brevzin / cpp_proposals

My WG21 proposals
40 stars 22 forks source link

P2996 - type_of and std::meta::info #165

Open krzysztof-jusiak opened 4 months ago

krzysztof-jusiak commented 4 months ago

It's sometimes the case that whilst manipulating std::meta::info with ranges that the underlying type of the std::meta::info is required, for example: to do some transformations on the underlying type.

It seems that type_of should be the right tool for the job, but that's not the case and instead substantial effort is required. The following is an example of how to lifting to type from std::meta::info can be achieved.

template <class R>
consteval auto invoke(auto fn, std::meta::info m) {
  return value_of<R>(reflect_invoke(^fn, {substitute(^meta, {reflect_value(m)})}));
}

Simple example of filter with test_test or, more generic, conversion to type:

Maybe there is a better way or maybe type_of should be made to work in such case or maybe there should be some utility such as invoke to make that simpler? Not sure, just wanted to raise it here as it's not trivial and/or clear, at least for me, what's the canonical way to do it?