mp11
mp11 copied to clipboard
`make_mp_identity` function?
In my code when I glue together boost.hana and boost.mp11 kind of MPLs I use my own make_mp_identity
function defined as following:
template<class T>
inline constexpr mp_identity<T> make_mp_identity(T) noexcept { return {}; }
Would it be useful to add this function to mp11 library? Probably, the function should be named mp_make_identity
rather that make_mp_identity
.
I can make a pull request for it if needed.
Would you mind giving me an example of mp_make_identity
being used?
I have a type_variant
template class to transfer type information between components. One would be defined with C++17 as following (mine is a bit different because I don't have C++17 but the idea is the same):
template<class... T>
using type_variant = mp_transform<mp_identity, std::variant<T...>>;
If I need to set type_variant
in a generic lambda then my code looks like:
type_variant<...> var;
...
[&var](auto t) { var = mp_identity<decltype(t)>{}; }
In my opinion such a code will look cleaner with using of make_mp_identity
:
[&var](auto t) { var = make_mp_identity(t); }