Boost logo

Boost :

Subject: Re: [boost] boost::mpl::for_each and value_initialized
From: Aleksey Gurtovoy (agurtovoy_at_[hidden])
Date: 2009-09-04 05:05:33


Hi Peter,

> what is the use of value_initialized in boost::mpl::for_each?
> It should be sufficient if the value is initialized by the constructor.

In theory, yes. In practice, at the time when the code was authored,
it wasn't -- see
http://www.boost.org/doc/libs/1_40_0/libs/utility/value_init.htm

> value_initialized() calls memset() in before calling the constructor.

Apparently this change was introduced in 1.35 release:

    "New versions of value_initialized (Boost release version 1.35 or
     higher) offer a workaround to these issues: value_initialized will
     now clear its internal data, prior to constructing the object that
     it contains."

The fact that it's done unconditionally (as opposite only for compilers
with the discussed issues) is IMHO a bug.

> This memset() is not being optimized away with gnu-c++ 4.4.1.

My preferred way of addressing this would be to fix value_initialized by
#ifdef-ing the memset to be present for the faulty compilers only.

Could you verify whether the gcc will optimize away the rest of the
value_initialized magic if the memset is out?

-- 
Aleksey Gurtovoy
MetaCommunications Engineering

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