Skip to content

add a concept for contextual conversion to bool #1

@akrzemi1

Description

@akrzemi1

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions