Boost logo

Boost :

From: Valentin Bonnard (Bonnard.V_at_[hidden])
Date: 2000-08-01 11:15:14


Nicolai Josuttis wrote:

> Attached is the new version of array<> as complete file tree

Comments:

why don't you use the boost utilities in order
to implement !=, >=, <=, > ?

A looong time ago I implemented a container a bit like which supported
elements with no default ctor (like vector does). array<> does not.

To get such support you have to give-up the internal T array, so
it means direct "= { foo, bar }" style initialisation won't be
available anymore.

> Of course, it's still not perfect.
> But it should be good enough to put it on the web.
>
> Same urgent questions I have:
> - How to implement a template assignement operator that
> makes sure that the same number of elements are used?

This is too easy:

template <typename T2>
array<T,N>& operator= (const array<T2,N>& rhs)
{
  using std::copy;
  copy (rhs.begin (), rhs.end (), begin ());
  return *this;
}

> - Does anybody know whether using "{...}" instead of
> "{ { ... } }" for initialization is valid code???

> - assign()

Do you mean:

void assign (const T& elt)
{
  using std::fill_n;
  fill_n (begin (), size (), elt);
}

> - Jens Maurer <Jens.Maurer_at_[hidden]>:
> Do we want the "using std::swap;" trick so that Koenig lookup finds
> more global element swap() functions?
> What's that????

It probably means: Do not call std::swap directly.
Call the function (say do_swap) implemented as:

template <typename T>
void do_swap (T& lhs, T& rhs)
{
  using std::swap;
  swap (lhs, rhs);
}

This function should be in some boost header (if it isn't already).

-- 
Valentin Bonnard

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