veselink1 / refl-cpp

Static reflection for C++17 (compile-time enumeration, attributes, proxies, overloads, template functions, metaprogramming).
https://veselink1.github.io/refl-cpp/md__introduction.html
MIT License
1.06k stars 77 forks source link

constexpr if not a constant expression when using filter functions with const_string<N> #21

Closed veselink1 closed 4 years ago

veselink1 commented 4 years ago
constexpr auto contains(type_list<Ts...> list, const const_string<N>& name);
constexpr auto find_one(type_list<Ts...> list, const const_string<N>& name);

The overloads taking a const_string<N> do not work reliably. These functions currently wrap the passed in string in a lambda, which is later called in a constexpr context in filter(...). This does not work, as the captured variables by the lambda do not form a constant expression. The workaround is to pass in a lambda doing the comparison explicitly:

find_one(member_list<T>{}, [](auto member) { return member.name == "mymethod"; });

Some further investigation is required, but these will most likely end up being removed in the next release.