#include <stlsoft/util/must_init.hpp>
T | The base type, e.g. int , std::wstring |
int i1; // Not initialised. Compiler doesn't care! int res = 2 * i1; // Result is undefined!
Solution:
must_init<int> i1; // Not initialised. Compiler error
The user is required to explicitly initialise i1
:
must_init<int> i1(0); // Initialised. Everybody's happy int res = 2 * i1.get(); // Result is defined
Public Types | |
Member Types | |
typedef T | value_type |
The wrapped type. | |
typedef must_init< T > | class_type |
The current instantiation of the type. | |
typedef T & | reference |
The reference type. | |
typedef T const & | const_reference |
The non-mutating (const) reference type. | |
Public Member Functions | |
Construction | |
must_init (T t) | |
Constructor. | |
operator value_type const & () const | |
Implicit conversion to the wrapped type. | |
class_type & | operator= (value_type const &rhs) |
Members | |
const_reference | base_type_value () const |
Provides non-mutating (const) access to the base type value. | |
reference | base_type_value () |
Provides mutating access to the base type value. | |
const_reference | get () const |
Provides non-mutating (const) access to the base type value. | |
reference | get () |
Provides mutating access to the base type value. | |
Public Attributes | |
Members | |
value_type | value |
The underlying value. |
typedef T value_type |
The wrapped type.
typedef must_init<T> class_type |
The current instantiation of the type.
typedef T& reference |
The reference type.
typedef T const& const_reference |
The non-mutating (const) reference type.
must_init | ( | T | t | ) | [inline, explicit] |
Constructor.
operator value_type const & | ( | ) | const [inline] |
const_reference base_type_value | ( | ) | const [inline] |
Provides non-mutating (const) access to the base type value.
References must_init::value.
Referenced by must_init::get().
reference base_type_value | ( | ) | [inline] |
const_reference get | ( | ) | const [inline] |
Provides non-mutating (const) access to the base type value.
References must_init::base_type_value().
reference get | ( | ) | [inline] |
The underlying value.
Referenced by must_init::base_type_value(), and must_init::operator value_type const &().