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

Transform the Type in hana::type #326

Open
ricejasonf opened this issue Mar 11, 2017 · 3 comments
Open

Transform the Type in hana::type #326

ricejasonf opened this issue Mar 11, 2017 · 3 comments

Comments

@ricejasonf
Copy link
Collaborator

ricejasonf commented Mar 11, 2017

Consider a convenience function to perform operations modifying the contained type in a hana::type without unwrapping it and wrapping it again. Consider the following example:

// Current method
decltype(hana::typeid_(hana::back(std::declval<typename some_tuple_type::type>()))){};

// More expressive
type_transform(some_tuple_type{}, hana::back);

Note: It's important that it strips qualifiers since many functions possibly return references.

Possible Implementation (as discussed in Gitter):

template <typename T, typename F>
constexpr auto type_transform(hana::basic_type<T>, F f) {
  return decltype(hana::typeid_(f(std::declval<T>()))){};
}
@viboes
Copy link

viboes commented Jun 9, 2017

I don't understand what you are requesting.
Could you show a concrete example of what type_transform will do?

@ricejasonf
Copy link
Collaborator Author

Like hana::transform but for hana::type:

#include <boost/hana.hpp>

namespace hana = boost::hana;

template <typename T, typename F>
constexpr auto type_transform(hana::basic_type<T>, F f) {
    return decltype(hana::typeid_(f(std::declval<T>()))){};
}

int main() {
  constexpr auto foo = hana::type_c<hana::tuple<int, char, double>>;

  static_assert(type_transform(foo, hana::back) == hana::type_c<double>);
}

@ricejasonf
Copy link
Collaborator Author

I'd like to double-down and suggest that hana::type be a Functor.

This would not be unlike hana::experimental::types' implementation as a Functor.

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