This thing about a std::string or std::vector only being able to hold contents at compile time as a temporary or within a consteval function is frustrating. As far as I can tell it means you cannot directly get its size and then still access its content.

So far the only way I've seen that would work is converting it to an array, but to do that you need to pre-allocate one to some maximum size. In order to parameterize this you also have to shove the generator in a lambda.

#cpp

@crazyeddie the most easy way at the moment is probably `std::define_static_array` and `std::define_static_string`

@deezo I'm just about done coding an attempt to try that out when realizing it's also not going to work. It'll work for string and stuff but it's not going to help bring a compile time vector into a place that can be used as a constexpr. The reason being is that all it does is wrap its parameter into a span. Span defers to the owner, which is an object that used new. The span thus isn't a valid constexpr either.

Thanks though. I had recently learned there were such and was going to find.

@crazyeddie `std::span` returned by `std::define_static_array` doesn't refer to the original vector. You can pass almost arbitrary range into it, and you still get a span.
The retuned span is a span over static array (just as the title suggests 😂). The main limitation is that the element type must be something that can be used as constant template parameter.
You might benefit from watching some practical examples (https://youtu.be/ZX_z6wzEOG0?si=YlWb7RCh0UCrjKLA this is a cppcon talk by Barry Revzin)
Practical Reflection With C++26 - Barry Revzin - CppCon 2025

YouTube
@crazyeddie you might still need to extract the function that creates the span to use it it a constexpr context, but the need for constexpr variables is significantly reduced by `meta::substitute` and `meta::extract`.
In my personal experience, it takes some time to get used to the new ways, even if you have a significant experience in the pre-C++26 metaprogramming.

@deezo I should have kept going!

What I'm doing is clearly not the way to go here but it can be done. I just wanted a loop in main that would println the members of a class.

Yeah, the conversion has to happen in a separate, consteval function because the vector can't be used elsewhere. Then the constexpr value you keep of the array has to be made static. Then you can template for that array in main and println each member.

There are a couple pretty big changes I had to learn here, yep.

@crazyeddie keep going, C++26 is awesome 😎