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

Proposal mp_eval_and? #33

Closed
HDembinski opened this issue May 13, 2019 · 6 comments
Closed

Proposal mp_eval_and? #33

HDembinski opened this issue May 13, 2019 · 6 comments

Comments

@HDembinski
Copy link

HDembinski commented May 13, 2019

This is a combination of mp_eval_if and mp_and. mp_and already shortcuts on the first substitution failure when mp_to_bool is applied to T or when the application yields mp_false. mp_eval_and would provide the same functionality for applications of meta functions F... on T.

template <class T, template<class>class F...> using mp_eval_and = ...

mp_eval_and<T, F0, F1, ...> is mp_false, if F0<T> is mp_false or a substitution failure. Otherwise it is mp_eval_and<T, F1, ...> and so on.

Example application for mp_eval_and

template <class T>
using is_unsigned_integral = mp_eval_and<T, std::is_integral, std::is_unsigned>;
@pdimov
Copy link
Member

pdimov commented May 13, 2019

Is this the one-liner

template<class T, template<class...> class... F> using mp_eval_and = mp_and<F<T>...>;

?

@HDembinski
Copy link
Author

I just tried it out, the one-liner seems to work, although I don't get why. I thought the right hand side mp_and<F<T>> would cause a substitution failure if F<T> is a substitution failure. mp_eval_and should never cause a substitution failure.

@HDembinski
Copy link
Author

I have an implementation here: https://github.com/HDembinski/mp11/tree/mp_eval_and, pieced together from looking at how you do things.

@pdimov
Copy link
Member

pdimov commented May 13, 2019

In your example, F0 is is_integral, and is_integral<T> is never a substitution failure, because it's a struct. F0<T>::value can be a substitution failure, but it's eaten by mp_and.

@HDembinski
Copy link
Author

Ok, then my example is just bad and my understanding of your one-liner was correct at least.

@HDembinski
Copy link
Author

I am closing this as it seems superfluous.

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