Boost logo

Boost :

Subject: Re: [boost] [utility/value_init] boost::value_initialized<T> direct-initialized?
From: Niels Dekker - address until 2010-10-10 (niels_address_until_2010-10-10_at_[hidden])
Date: 2010-03-31 04:27:06

>> Can anybody please have a look at the following feature request by
>> Edward Diener? He
>> proposed to add an explicit constructor, value_initialized(T const&),
>> to boost::value_initialized<T>. This constructor would copy the value
>> of its argument to the object held by value_initialized<T>.
>> When such a constructor would be added, an object held by
>> value_initialized<T> might no longer be value-initialized. Instead it
>> might be direct-initialized. Does anybody have any moral (?)
>> objections against the idea that value_initialized<T> might hold a
>> non-value-initialized object?

Jeffrey Hellrung wrote:
> Is defining a new template class (e.g., value_or_direct_initialized<T>,
> or whatever) out of the question? Just a suggestion, and not confident
> it's a good one...

Thanks for the suggestion, Jeffrey! I like it, actually. :-) Maybe we
could simply call the new template class boost::initialized<T>.

I can think of two ways to implement boost::initialized<T> (and adapt
value_initialized<T> accordingly):

The implementation of boost::initialized could be simply copied from the
old value_initialized<T>, but having an extra constructor, initialized(T
const&). The new value_initialized<T> could then be implemented in
terms of boost::initialized<T>:

   template<class T>
   class value_initialized
     initialized<T> m_data;
     // Forwarding to m_data member functions:
     T const & data() const;
     T& data();
     void swap(value_initialized &);
     operator T const &() const;
     operator T&();

Or boost::initialized<T> could be derived from boost::value_initialized<T>:

   template<class T>
   class initialized: public value_initialized<T>
     initialized(T const& arg):
       value_initialized(arg) {}

     void swap(initialized &);

In that case, value_initialized<T> would still need the extra
constructor, value_initialized(T const&), but it could be declared

What do you think?

Kind regards,


Niels Dekker
Scientific programmer at LKEB, Leiden University Medical Center

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