mp11 icon indicating copy to clipboard operation
mp11 copied to clipboard

`make_mp_identity` function?

Open oliora opened this issue 6 years ago • 2 comments

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.

oliora avatar Jul 02 '18 17:07 oliora

Would you mind giving me an example of mp_make_identity being used?

pdimov avatar Jul 02 '18 21:07 pdimov

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); }

oliora avatar Jul 03 '18 15:07 oliora