Boost logo

Boost :

From: Niels Dekker - mail address until 2008-12-31 (nd_mail_address_valid_until_2008-12-31_at_[hidden])
Date: 2008-06-18 04:40:56

FYI, I just merged value_init from the trunk to the release branch:

It now has a little const object, boost::initialized_value, that has a
generic conversion operator, so that one can initialize any
CopyConstructible, DefaultConstructible type of object as follows:

  T obj = boost::initialized_value;

boost::initialized_value provides a workaround to compilers that haven't
yet fully implemented value-initialization. Including compiler versions
from MSVC, Borland, Sun, and GCC:
For example, suppose your class Foo has all its data stored in a simple
aggregate struct, called Bar:

  class Foo {
    Bar m_bar;

  struct Bar {
    std::string s;
    int i;

The default constructor of Foo would typically want to value-initialize
its data:

  Foo::Foo() :
  m_bar() // Value-initialization.

This may not work properly, because of those aforementioned compiler
issues. (Bar::i may be left uninitialized!) So instead,
boost::initialized_value could be of help:

  Foo::Foo() :
  m_bar( boost::initialized_value ) // Works fine :-)

boost::initialized_value is in fact just an extra convenience feature of
the template boost::value_initialized<T>, by Fernando Cacciola. So
Fernando and I agreed to add initialized_value to

Kind regards,

Niels Dekker
Scientific programmer at LKEB, Leiden University Medical Center

Boost list run by bdawes at, gregod at, cpdaniel at, john at