Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make_mp_identity function? #24

Open
oliora opened this issue Jul 2, 2018 · 2 comments
Open

make_mp_identity function? #24

oliora opened this issue Jul 2, 2018 · 2 comments

Comments

@oliora
Copy link

oliora commented Jul 2, 2018

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.

@pdimov
Copy link
Member

pdimov commented Jul 2, 2018

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

@oliora
Copy link
Author

oliora commented Jul 3, 2018

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants