Boost logo

Boost :

Subject: Re: [boost] Is there a thin array wrapper/proxy lying around somewhere?
From: Daryle Walker (darylew_at_[hidden])
Date: 2013-11-29 09:12:17


> Date: Mon, 25 Nov 2013 23:01:49 +0000
> From: jwakely.boost_at_[hidden]
>
> On 25 November 2013 21:47, Mostafa wrote:
>>
>> I can't think of any TMP trick that would work around the array
>> initialization issue. So the next best thing is to fake an array type. I
>> think this is achievable. Do you see any alternatives?
>
> So you want something that behaves exactly like an array except when
> it doesn't. You're going to have to be a bit more precise about what
> exactly you want.
>
> In C++11 you can do this:
>
> typedef int Arr3[3];
>
> struct Foo
> {
> Foo(int p1, std::initializer_list<int> p2, long p3) : m1(p1), m3(p3)
> { std::copy(p2.begin(), p2.end(), m2); }
>
> int m1;
> Arr3 m2;
> long m3;
> };

For C++11, array members can finally be put in member-initializers. But brace-
initialization must be used, and they're still not Assignable:

    Foo( int p1, Arr3 const &p2, long p3 ) : m1( p1 ), m2{}, m3{ p3 }
    { std::copy(std::begin(p2), std::end(p2), std::begin(m2)); }

(The "m2" member initialization could have been omitted since the body completely
paves those values over.)

>
> Another option is just to provide a wrapper around std::array that
> offers the implicit conversion to pointer.

The aggressive array-to-pointer decay makes arrays 2nd-class types in the C family
of languages and is our (not so) secret shame. A design that needs to emulate
this decay is probably broken.

>
> If these aren't suitable then again, you need to be more precise about
> what exactly you want, so far you're expecting answers to quite vague
> questions.

Daryle W.


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