
Niels Dekker - address until 2010-10-10 wrote:
Do you agree that its support for member data initialization would be the main reason for having boost::initialized<T>?
Jeffrey Hellrung wrote:
Yes.
Within the context of member data initialization, the "explicit" keyword doesn't do anything. (For example, when the class has a data member of type boost::initialized<T>.) That's why I though the extra boost::direct_initialized_t tag parameter might be useful. Clearly so far I haven't convinced anyone. But I realize such a tag parameter will be less relevant when we're going to introduce a new initialized<T> template class, instead of modifying the interface of the old boost::value_initialized<T>. Fernando's boost::value_initialized<T> has been around for so long that I think backward-compatibility should be taken into account.
To me, the tag is a syntactic wart, but I understand your concerns, and you've clearly considered this problem more than I have... [...]
Honestly the MSVC bug just made me more aware that copy-constructors and non-copy-constructors can get confused, in a generic context. But the example I added to the ticket (#3472) would also be ambiguous on other compilers, when value_initialized(T const&) would be added:
class my_integer { value_initialized<int> m_data; public: operator value_initialized<int>() const; operator int() const; };
int main() { my_integer my; value_initialized<int> val(my); }
Point taken. See below.
Remaining question, triggered by the comments by Steven: should the new direct-initializing boost::initialized<T> constructor itself be a template? In that case, the "explicit" keyword certainly would make more sense to me:
// Note: untested! template<class T> class initialized { ... public: initialized();
template<class U> explicit initialized(U const&);
T const & data() const; T& data(); void swap(initialized &); operator T const &() const; operator T&(); };
What do you think?
What do you think about using the templated constructor *and* SFINAE out via enable_if the binding of U to initialized<T> (or, maybe, to any class derived from initialized<T>)? What problems does that have? - Jeff