Opened 9 years ago

#9436 new Feature Requests

Add predefined concept for contextual conversion to bool

Reported by: akrzemi1@… Owned by: Steven Watanabe
Milestone: To Be Determined Component: type_erasure
Version: Boost 1.54.0 Severity: Not Applicable
Keywords: operator bool() Cc:

Description

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) {}
  return bool(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); }
};
}}

Change History (0)

Note: See TracTickets for help on using tickets.