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

add a concept for contextual conversion to bool #1

Open
akrzemi1 opened this issue Jul 25, 2014 · 0 comments
Open

add a concept for contextual conversion to bool #1

akrzemi1 opened this issue Jul 25, 2014 · 0 comments

Comments

@akrzemi1
Copy link
Member

One concept that is often useful in many types is a contextual conversion to bool. The following expressions should be valid with the concept:

if (o) {}
if (!o) {}
template <typename O>
bool test(O&& o)  { return o; }

Add a predefined concept that catches these requirement. A possible implementation:

namespace boost { namespace type_erasure {

template<class T>
struct testable
{
  static bool apply(const T& arg)
  { return bool(arg); }
};

template<class T, class Base>
struct concept_interface<testable<T>, Base, T> : Base
{
  explicit operator bool () const
  { return call(testable<T>(), *this); }
};
}}
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

1 participant