Boost logo

Boost :

From: Mark Rodgers (mark.rodgers_at_[hidden])
Date: 2000-08-01 03:56:41


> Same urgent questions I have:
> - How to implement a template assignement operator that
> makes sure that the same number of elements are used?

Is there anything wrong with

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

This works for me. Of course, because rhs may be of a
different type, we can't easily check for self assignment,
but I don't think we need to.

I'd also like to see one or more assignment functions for
compatibility with vector. I think these should behave
like strncpy. If the range contains more than N elements,
assign the first N to the array. If the range contains
fewer than N, assign them to the array and "zero-fill"
(i.e. assign T() to) the remainder.

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

This is tricky. I don't see why not, but the standard is
less than clear. On the one hand I can't find anything in
the standard the explicitly allows it; on the other hand I
can't find anything that forbids it, it works with all the
compilers I've tested, and I think 8.5.1p11 is implying it
is allowed. So I think it is OK.

Mark


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