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-04-01 13:49:02


>> 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.

> Is that MSVC bug (the one referenced in the value_initialized
> ticket...no link handy at the moment) not "workaroundable" by
> explicitly defining the derived class' copy constructor?

MSVC bug (reported independently by both srconchiwa and Edward Diener):
http://connect.microsoft.com/VisualStudio/feedback/details/423737/default-copy-constructor-does-not-call-correct-base-constructor
http://connect.microsoft.com/VisualStudio/feedback/details/522094/warning-c4717-recursive-on-all-control-paths-error-erroneous

value_initialized ticket by Edward:
https://svn.boost.org/trac/boost/ticket/3472 (Yes, I added a reference to
our discussion!)

> And isn't it only a problem when the base class has a constructor other
> than the copy
> constructor that that a const derived& can bind to? Perhaps I need to
> go back and reread the Microsoft ticket...

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);
  }

See http://codepad.org/zukxSDbB

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?

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