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:
http://svn.boost.org/trac/boost/changeset/46464

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:
http://svn.boost.org/trac/boost/browser/branches/release/libs/utility/value_init.htm?format=raw#compiler_issues
For example, suppose your class Foo has all its data stored in a simple
aggregate struct, called Bar:

  class Foo {
    Bar m_bar;
  public:
    Foo();
  };

  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
<utility/value_init.hpp>

Kind regards,

-- 
Niels Dekker
http://www.xs4all.nl/~nd/dekkerware
Scientific programmer at LKEB, Leiden University Medical Center

Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk