|
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-04-01 03:31:32
Jeffrey Hellrung wrote:
>> The templated constructor should be explicit, because otherwise
>> things like
>>
>> boost::initialized<std::vector<int> > v = 10;
>>
>> would compile. IMHO, it's okay if implicit
>> conversions that would normally work for
>> the contained type don't work, since this errs
>> on the side of safety, but it isn't okay to make
>> all conversions implicit.
>
> Agreed.
Leaving out the "explicit" keyword from the initialized(const T&)
constructor of initialized<T> won't make Steven's example compile (as I
wrote before).
In what particular situation would you need to use
boost::initialized<T>, including the new initialized(const T&)
constructor, instead of just the old value_initialized<T>?
I think /the/ motivating use case for boost::initialized<T> is about
member data initialization:
template <typename T> class foo
{
std::string m_name;
boost::initialized<T> m_data;
public:
foo();
foo(const foo&);
foo(const T&, std::string);
};
In this case, some of foo's constructors may want m_data to be
value-initialized, but others need to do direct-initialization.
Do you agree that its support for member data initialization would be
the main reason for having boost::initialized<T>?
> And I don't think the boost::direct_initialized tag is
> necessary,
> MSVC compiler bugs be damned.
Sorry, I'm not sure what you mean. It's certainly important to me to
have something that works on MSVC.
Kind regards,
Niels
-- 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