must_init Class Template Reference
[Utility Library]

#include <stlsoft/util/must_init.hpp>

List of all members.


Detailed Description

template<typename T>
class stlsoft::must_init< T >

Wraps a variable and forces its explicit initialisation by the user.

Parameters:
T The base type, e.g. int, std::wstring
Problem:

  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_typeoperator= (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.

Member Typedef Documentation

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.


Constructor & Destructor Documentation

must_init ( t  )  [inline, explicit]

Constructor.


Member Function Documentation

operator value_type const & (  )  const [inline]

Implicit conversion to the wrapped type.

References must_init::value.

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]

Provides mutating access to the base type value.

References must_init::value.

const_reference get (  )  const [inline]

Provides non-mutating (const) access to the base type value.

References must_init::base_type_value().

reference get (  )  [inline]

Provides mutating access to the base type value.

References must_init::base_type_value().


Member Data Documentation

The underlying value.

Remarks:
Since the purpose of must_init is to guard against a forgotten initialisation in composition involving fundamental types, rather than encapsulation in any wider sense, the member value is public, to simplify manipulation of the actual value by its encapsulating class, thereby avoiding all the (compiler-dependent) hassles attendant with implicit conversion to reference types.

Referenced by must_init::base_type_value(), and must_init::operator value_type const &().


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

Generated on Thu Jun 10 08:59:02 2010 for STLSoft by  doxygen 1.5.6