Is there a thin array wrapper/proxy lying around somewhere?

(Yes, I'm aware of boost.array, boost.multiarray, and std::vector.) Is there any thin but complete array wrapper/proxy lying around somewhere in boost? A class that if substituted for an array will behave just like the substituted array? Thanks, Mostafa

On Sunday 24 November 2013 23:42:15 Mostafa wrote:
(Yes, I'm aware of boost.array, boost.multiarray, and std::vector.) Is there any thin but complete array wrapper/proxy lying around somewhere in boost? A class that if substituted for an array will behave just like the substituted array?
Umm, could you explain why Boost.Array doesn't qualify?

On Mon, 25 Nov 2013 00:02:17 -0800, Andrey Semashev
On Sunday 24 November 2013 23:42:15 Mostafa wrote:
(Yes, I'm aware of boost.array, boost.multiarray, and std::vector.) Is there any thin but complete array wrapper/proxy lying around somewhere in boost? A class that if substituted for an array will behave just like the substituted array?
Umm, could you explain why Boost.Array doesn't qualify?
Because it does not meet the stated requirements. For one, it doesn't have operator+, two, it doesn't have the necessary implicit conversion-to-pointer operator, three regular arrays can't be assigned to, etc ... To be more clear, what is desired is a type that mimics all (well, I can live with almost all [1]) the functionality of a regular array, no more, no less. [1] Initialization with array initializor list might be impossible to do in C++03. Hope that clarifies, Mostafa

On Nov 25, 2013, at 4:22 AM, Mostafa
On Mon, 25 Nov 2013 00:02:17 -0800, Andrey Semashev
wrote: On Sunday 24 November 2013 23:42:15 Mostafa wrote:
(Yes, I'm aware of boost.array, boost.multiarray, and std::vector.) Is there any thin but complete array wrapper/proxy lying around somewhere in boost? A class that if substituted for an array will behave just like the substituted array?
Umm, could you explain why Boost.Array doesn't qualify?
Because it does not meet the stated requirements.
Your requirements statement left something to be desired.
For one, it doesn't have operator+, two, it doesn't have the necessary implicit conversion-to-pointer operator,
With the latter, there's no need for the former. However, the constructor overloads needed to achieve your desired initialization goals will likely cause problems with the conversion operator, though explicit may be sufficient.
three regular arrays can't be assigned to, etc ...
To be more clear, what is desired is a type that mimics all (well, I can live with almost all [1]) the functionality of a regular array, no more, no less.
[1] Initialization with array initializor list might be impossible to do in C++03.
I'm not aware of anything meeting your requirements. ___ Rob (Sent from my portable computation engine)

AMDG On 11/25/2013 01:22 AM, Mostafa wrote:
Because it does not meet the stated requirements. For one, it doesn't have operator+, two, it doesn't have the necessary implicit conversion-to-pointer operator, three regular arrays can't be assigned to, etc ...
To be more clear, what is desired is a type that mimics all (well, I can live with almost all [1]) the functionality of a regular array, no more, no less.
[1] Initialization with array initializor list might be impossible to do in C++03.
If you want something that behaves exactly like an array, why can't you use an array? In Christ, Steven Watanabe

On Mon, 25 Nov 2013 07:44:22 -0800, Steven Watanabe
AMDG
On 11/25/2013 01:22 AM, Mostafa wrote:
Because it does not meet the stated requirements. For one, it doesn't have operator+, two, it doesn't have the necessary implicit conversion-to-pointer operator, three regular arrays can't be assigned to, etc ...
To be more clear, what is desired is a type that mimics all (well, I can live with almost all [1]) the functionality of a regular array, no more, no less.
[1] Initialization with array initializor list might be impossible to do in C++03.
If you want something that behaves exactly like an array, why can't you use an array?
typedef int Arr3[3];
typedef tuple

On Mon, 25 Nov 2013 07:44:22 -0800, Steven Watanabe
AMDG
On 11/25/2013 01:22 AM, Mostafa wrote:
Because it does not meet the stated requirements. For one, it doesn't have operator+, two, it doesn't have the necessary implicit conversion-to-pointer operator, three regular arrays can't be assigned to, etc ...
To be more clear, what is desired is a type that mimics all (well, I can live with almost all [1]) the functionality of a regular array, no more, no less.
[1] Initialization with array initializor list might be impossible to do in C++03.
If you want something that behaves exactly like an array, why can't you use an array?
<The previous posting was sent in error.> typedef int Arr3[3]; struct Foo { Foo(int p1, Arr3 & p2, long p3) : m1(p1), m2(p2), m3(p3) {} int m1; Arr3 m2; long m3; }; 1) The ctor for Foo is auto-generated. 2) The member variables of Foo are user inputs to the codegen. 3) Obviously Foo's current ctor won't compile because arrays are not copy constructible. 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? Mostafa

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; }; Another option is just to provide a wrapper around std::array that offers the implicit conversion to pointer. 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.

Date: Mon, 25 Nov 2013 23:01:49 +0000 From: jwakely.boost@kayari.org
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.

On 29 November 2013 14:12, Daryle Walker wrote:
For C++11, array members can finally be put in member-initializers.
Array members were always allowed in member-initializers.
But brace- initialization must be used,
No, you can value-initialize them with () too.
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.)
That's why I omitted it :-)
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.
Yes, but that's what the OP specifically asked for.

On 11/25/13, Mostafa
(Yes, I'm aware of boost.array, boost.multiarray, and std::vector.) Is there any thin but complete array wrapper/proxy lying around somewhere in boost? A class that if substituted for an array will behave just like the substituted array?
This is not in Boost but it is in the review queue, https://github.com/BrianJSmith/Array Regards Brian -- www.maidsafe.net
participants (7)
-
Andrey Semashev
-
Brian Smith
-
Daryle Walker
-
Jonathan Wakely
-
Mostafa
-
Rob Stewart
-
Steven Watanabe