ARTICLE AD BOX
In a first attempt to use C++26 reflection, I am attempting to iterate over all available members of a namespace.
To do that I first get the members with std::meta::members_of.
GCC 16.1 is saying that my use of std::meta::members_of is not a constant expression. What am I doing wrong?
https://godbolt.org/z/sWP3h1nYo
#include <meta> int main() { constexpr auto ns_refl = ^^std; constexpr auto ctx = std::meta::access_context::unchecked(); constexpr auto members = std::meta::members_of(ns_refl, ctx); // Then I would like to do: //template for (constexpr auto &member : members) //{ // std::cout << std::meta::identifier_of(member) << '\n'; //} }Error from gcc:
<source>: In function 'int main()': <source>:6:64: error: 'std::meta::members_of(((std::meta::info)ns_refl), ctx)' is not a constant expression because it refers to a result of 'operator new' 6 | constexpr auto members = std::meta::members_of(ns_refl, ctx); | ^ In file included from /cefs/38/383ad2f84cbd57a52fd68bbe_consolidated/compilers_c++_x86_gcc_16.1.0/include/c++/16.1.0/string:46, from /cefs/38/383ad2f84cbd57a52fd68bbe_consolidated/compilers_c++_x86_gcc_16.1.0/include/c++/16.1.0/bits/stdexcept_throw.h:57, from /cefs/38/383ad2f84cbd57a52fd68bbe_consolidated/compilers_c++_x86_gcc_16.1.0/include/c++/16.1.0/array:44, from /cefs/38/383ad2f84cbd57a52fd68bbe_consolidated/compilers_c++_x86_gcc_16.1.0/include/c++/16.1.0/meta:42, from <source>:1: /cefs/38/383ad2f84cbd57a52fd68bbe_consolidated/compilers_c++_x86_gcc_16.1.0/include/c++/16.1.0/bits/allocator.h:203:52: note: allocated here 203 | return static_cast<_Tp*>(::operator new(__n)); | ~~~~~~~~~~~~~~^~~~~ ASM generation compiler returned: 1