Drake
Bool< T > Class Template Reference

Class representing a boolean value independent of the underlying scalar type T: More...

#include <drake/common/drake_bool.h>

Public Types

using value_type = decltype(T()< T())
 

Public Member Functions

 Bool (const value_type &value)
 Constructs with value. More...
 
template<typename = std::enable_if<!std::is_same<value_type, bool>::value>>
 Bool (bool b)
 Constructs with a Boolean b. More...
 
value_type value () const
 Returns a copy of its value. More...
 
Implements CopyConstructible, CopyAssignable, MoveConstructible, MoveAssignable
 Bool (const Bool &)=default
 
Booloperator= (const Bool &)=default
 
 Bool (Bool &&)=default
 
Booloperator= (Bool &&)=default
 

Static Public Member Functions

static Bool< T > True ()
 Returns the true value. More...
 
static Bool< T > False ()
 Returns the false value. More...
 

Friends

Bool< T > operator&& (const Bool< T > &b1, const Bool< T > &b2)
 Provides logical AND operator (&&). More...
 
Bool< T > operator|| (const Bool< T > &b1, const Bool< T > &b2)
 Provides logical OR operator (||). More...
 

Detailed Description

template<typename T>
class drake::Bool< T >

Class representing a boolean value independent of the underlying scalar type T:

A value of this class is not contextually convertible to bool. To convert a value to bool, one needs to explicitly call ExtractBoolOrThrow defined below in this file. Here is an example use-case:

const Bool<double> b{3.0 < 4.0};
...
}

In contrast, the following code does not compile:

const Bool<double> b{3.0 < 4.0};
if (b) {
...
}

Member Typedef Documentation

using value_type = decltype(T() < T())

Constructor & Destructor Documentation

Bool ( const Bool< T > &  )
default
Bool ( Bool< T > &&  )
default
Bool ( const value_type value)
inline

Constructs with value.

Bool ( bool  b)
inline

Constructs with a Boolean b.

Note
This constructor is only enabled if value_type is not bool in which case the above constructor, Bool(const value_type& value), is used instead.

Member Function Documentation

static Bool<T> False ( )
inlinestatic

Returns the false value.

Here is the caller graph for this function:

Bool& operator= ( Bool< T > &&  )
default
Bool& operator= ( const Bool< T > &  )
default
static Bool<T> True ( )
inlinestatic

Returns the true value.

Here is the caller graph for this function:

value_type value ( ) const
inline

Returns a copy of its value.

Here is the caller graph for this function:

Friends And Related Function Documentation

Bool<T> operator&& ( const Bool< T > &  b1,
const Bool< T > &  b2 
)
friend

Provides logical AND operator (&&).

Note
We define this operator in the class as a friend function so that implicit conversion works as expected (i.e. Bool<T> && Bool<T>::value_type). See item 46 of Effective C++ (3rd ed.) for more information.
Bool<T> operator|| ( const Bool< T > &  b1,
const Bool< T > &  b2 
)
friend

Provides logical OR operator (||).


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