Seastar
High performance C++ framework for concurrent servers
Public Member Functions | Static Public Attributes | List of all members
seastar::bool_class< Tag > Class Template Reference

Detailed Description

template<typename Tag>
class seastar::bool_class< Tag >

Type-safe boolean.

bool_class objects are type-safe boolean values that cannot be implicitly casted to untyped bools, integers or different bool_class types while still provides all relevant logical and comparison operators.

bool_class template parameter is a tag type that is going to be used to distinguish booleans of different types.

Usage examples:

struct foo_tag { };
using foo = bool_class<foo_tag>;
struct bar_tag { };
using bar = bool_class<bar_tag>;
foo v1 = foo::yes; // OK
bar v2 = foo::yes; // ERROR, no implicit cast
foo v4 = v1 || foo::no; // OK
bar v5 = bar::yes && bar(true); // OK
bool v6 = v5; // ERROR, no implicit cast
Template Parameters
Tagtype used as a tag

#include <seastar/util/bool_class.hh>

Public Member Functions

constexpr bool_class () noexcept
 Constructs a bool_class object initialised to false.
 
constexpr bool_class (bool v) noexcept
 Constructs a bool_class object initialised to v.
 
 operator bool () const noexcept
 Casts a bool_class object to an untyped bool.
 

Static Public Attributes

static const bool_class yes { true }
 
static const bool_class no { false }
 

The documentation for this class was generated from the following file: