TPIE

2362a60
tpie::maybe< T > Class Template Reference

Public Member Functions

 maybe ()
 Construct a new unconstructed maybe object. More...
 
 maybe (const maybe< T > &o)
 If o is constructed throw an exception otherwise do nothing. More...
 
 maybe (maybe< T > &&o)
 
maybeoperator= (const maybe< T > &o)
 If o is constructed throw an exception otherwise return *this. More...
 
maybeoperator== (maybe< T > &o)
 
bool is_constructed () const
 
template<typename... T_ARGS>
void construct (T_ARGS &&...t)
 Contains an element of the type given as template parameter and disallows copy constructing of the maybe class when the object is allocated. More...
 
T & operator* ()
 
const T & operator* () const
 
T * operator-> ()
 
const T * operator-> () const
 
void destruct ()
 Invokes the deconstructor on the object contained. More...
 
 ~maybe ()
 Calls the destruct method and destroys the instance. More...
 

Detailed Description

template<typename T>
class tpie::maybe< T >

Definition at line 34 of file maybe.h.

Constructor & Destructor Documentation

template<typename T>
tpie::maybe< T >::maybe ( )
inline

Construct a new unconstructed maybe object.

Definition at line 39 of file maybe.h.

39  : m_constructed(false) {
40  }
template<typename T>
tpie::maybe< T >::maybe ( const maybe< T > &  o)
inline

If o is constructed throw an exception otherwise do nothing.

Definition at line 45 of file maybe.h.

45  : m_constructed(false) {
46  o.assert_not_constructed();
47  }
template<typename T>
tpie::maybe< T >::~maybe ( )
inline

Calls the destruct method and destroys the instance.

Definition at line 147 of file maybe.h.

147  {
148  destruct();
149  }
void destruct()
Invokes the deconstructor on the object contained.
Definition: maybe.h:136

Member Function Documentation

template<typename T>
template<typename... T_ARGS>
void tpie::maybe< T >::construct ( T_ARGS &&...  t)
inline

Contains an element of the type given as template parameter and disallows copy constructing of the maybe class when the object is allocated.

The implementation of maybe either uses variadic templates (if supported by the compiler) or a bunch of overloads to support a variable number of constructor parameters.

Template Parameters
ArgsThe variadic number of types of constructor parameters.
Parameters
argsThe variadic number of arguments to pass to the constructor of

Definition at line 98 of file maybe.h.

98  {
99  assert_not_constructed();
100 
101  new(&object) T(std::forward<T_ARGS>(t)...);
102  m_constructed = true;
103  }
template<typename T>
void tpie::maybe< T >::destruct ( )
inline

Invokes the deconstructor on the object contained.

Definition at line 136 of file maybe.h.

Referenced by tpie::maybe< tpie::file_stream< item_type > >::~maybe().

136  {
137  if(!m_constructed)
138  return;
139 
140  object.~T();
141  m_constructed = false;
142  }
template<typename T>
bool tpie::maybe< T >::is_constructed ( ) const
inline
Returns
Whether the object contained is constructed or not.

Definition at line 80 of file maybe.h.

80  {
81  return m_constructed;
82  }
template<typename T>
T& tpie::maybe< T >::operator* ( )
inline
Returns
A reference to the object contained.

Definition at line 108 of file maybe.h.

108  {
109  return object;
110  }
template<typename T>
const T& tpie::maybe< T >::operator* ( ) const
inline
Returns
A const reference to the object contained.

Definition at line 115 of file maybe.h.

115  {
116  return object;
117  }
template<typename T>
T* tpie::maybe< T >::operator-> ( )
inline
Returns
A pointer to the object contained.

Definition at line 122 of file maybe.h.

122  {
123  return &object;
124  }
template<typename T>
const T* tpie::maybe< T >::operator-> ( ) const
inline
Returns
A const pointer to the object contained.

Definition at line 129 of file maybe.h.

129  {
130  return &object;
131  }
template<typename T>
maybe& tpie::maybe< T >::operator= ( const maybe< T > &  o)
inline

If o is constructed throw an exception otherwise return *this.

Definition at line 63 of file maybe.h.

63  {
64  o.assert_not_constructed();
65  assert_not_constructed();
66 
67  return *this;
68  }

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