Boost logo

Boost :

From: rwgk (rwgk_at_[hidden])
Date: 2002-03-06 14:31:44


In light of the upcoming Curacao meeting David Abrahams and
myself are discussion a proposal for the revision of
std::complex. Attached is one facet from our discussion. We
would like to hear comments if there are different
opinions.

David Abrahams wrote:
> I need you to explain why we need a complex<> with a
> predictable POD-like layout and a way to avoid
> initializing the members (anything else important about
> complex<>?)

Regarding David's last point:

It seems to me that this is more a question of how
containers work rather than one of the design of
std::complex<T>.

E.g.:

  std::vector<T>(1000000); // elements are default constructed -> T()

B. Stroustrup writes (section 6.2.8 of The C++ Prog. Lang.):

"The value of an explicit use of the constructor for a
built-in type is 0 converted to that type."

Do we want std::complex<T> to behave differently than
built-in types?

Here is a more general solution that will work for any type
that has a trivial destructor:

From files misc.h and shared_plain.h at:
http://cvs.sourceforge.net/cgi-
bin/viewcvs.cgi/cctbx/cctbx/cctbx/array_family/?
only_with_tag=array_family_integration

  struct no_initialization_flag {};

  template <typename ElementType>
  class shared_plain {
      // ...
      shared_plain(const size_type& sz, no_initialization_flag)
        : m_is_weak_ref(false),
          m_handle(new handle_type(sz * element_size()))
      {
        CCTBX_ARRAY_FAMILY_STATIC_ASSERT_HAS_TRIVIAL_DESTRUCTOR
        m_handle->size = m_handle->capacity;
      }
      // ...
  };

IMO both std::vector and std::valarray should have a
similar additional constructor.
This suggestion requires that type traits are part of the
standard. Is this likely to happen any time soon?

Thanks,
        Ralf


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