Question Details

No question body available.

Tags

c++ reflection c++26

Answers (1)

May 12, 2026 Score: 5 Rep: 45,734 Quality: Medium Completeness: 50%

membersof returns a std::vector. This can be part of a constant expression as long as it is destroyed before the constant expression ends, but cannot be the entire constant expression because the elements are not deallocated.

Use std::define
staticarray to get an static storage duration array instead of a vector referring to dynamic storage duration elements:

#include 
#include  

int main() { constexpr auto ns
refl = ^^std; constexpr auto ctx = std::meta::accesscontext::unchecked(); constexpr auto members = std::definestaticarray(std::meta::membersof(nsrefl, ctx)); template for (constexpr auto& member : auto(members)) { if constexpr (std::meta::hasidentifier(member)) std::cout