ORNL / cpp-proposals-pub

Collaborating on papers for the ISO C++ committee - public repo
26 stars 26 forks source link

P0009: Add design justification for static->dynamic and dynamic->static mdspan assignment #165

Open mhoemmen opened 2 years ago

mhoemmen commented 2 years ago

should they allow static -> dynamic conversion (seems fine) should they allow dynamic -> static (note that this have UB)

Both of these cases are important. Static-to-dynamic conversion is "type erasure," for when an implementation doesn't want to specialize for compile-time extents. Dynamic-to-static conversion is "specialization" (the opposite of type erasure), for when an implementation is willing to pay the compile-time cost of specializing. A common use case for the latter is in applications that solve partial differential equations through a variety of different discretization methods. Many methods result in arrays with known fixed extents, but making all of them compile-time constants might cost too much compilation time, rather than just optimizing the most common methods.

mhoemmen commented 2 years ago

Also, span lets you assign static to dynamic.

mhoemmen commented 2 years ago

https://eel.is/c++draft/span.cons lets you assign both directions (static to dynamic, or dynamic to static)

mhoemmen commented 2 years ago

Tomasz Kamiński pointed out this issue

mhoemmen commented 2 years ago

span permits construction from dynamic to static, but not assignment: https://godbolt.org/z/4eEMWzYzW

mhoemmen commented 2 years ago

which is silly, because you can always construct an intermediate span, then assign