Modify

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

Attachments (0)

Change History (0)

Modify Ticket

Change Properties
Set your email in Preferences
Action
as new The owner will remain Steven Watanabe.

Add Comment


E-mail address and name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.