|
Boost : |
From: Robert Ramey (ramey_at_[hidden])
Date: 2003-08-09 10:57:17
David B. Held" wrote
>"Jeremy Siek" <jsiek_at_[hidden]> wrote in message
>> [...]
>> However, did he want the exact interface as boost::array? If so, I'd
>> say we need a new class called ptr_array that adapts a pointer
>> and a size into an array.
>Or perhaps a policy-based smart pointer with an array-wrapping
>policy and boost::array-like interface? ;) If the OP is using gcc 3.3,
>I might be able to provide exactly such a beast.
>Dave
Dave Gomboc wrote:
>> const int array[] = {1, 2, 3, 4};
>> std::copy(array, array + 4, ...);
>>
Actually this suits my current need. It compiles in my environment.
Does this mean its universally OK?. I thought I had seen something
like this before but couldn't find it in any of my references so I had been
trying something variations on:
const int array[] = {1, 2, 3, 4};
std::copy(array.begin(), array.end(), ...);
without success - which of course makes sense.
which led me to boost::array. This I found unsuitable because
of the extra copy. I was also unenthusiastic about the intialization
syntax.
So now my immediate problem is addressed. However, now I've
got a couple of questions raised by the responses.
Presumably boost::array was motivated by the desire to make
an array look like a container - which is what I wanted. I found
it unsatisfactory because of the copying. Would it not be interesting
to make an equivalent that would take either an array reference
or a pointer and give it a ful container like interface so that one could
do something like:
const int array[] = {1, 2, 3, 4};
boost::container_facade<int> cfa(array);
std::copy(cfa.begin(), cfa.end(), ...);
so that an array or pointer could be used anywhere a container
can be used?
I think it would be a relative easy task given that boost::array
already provides the interface. In fact, just factoring boost::array
into two layers (one to provide the common interface) and one
to provide different constuctors an array or array reference member
might do the trick.
Just a suggestion.
Robert Ramey
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk