Topic: multi-dimensional array


Author: musabalbirair@gmail.com
Date: Fri, 25 Sep 2015 10:23:44 -0700 (PDT)
Raw View
------=_Part_2001_1780421541.1443201824803
Content-Type: multipart/alternative;
 boundary="----=_Part_2002_1316397900.1443201824804"

------=_Part_2002_1316397900.1443201824804
Content-Type: text/plain; charset=UTF-8

Hello everyone
I am thinking of adding a simple multi-dimensional array class to the
standard library. The proposed class can have the following interface:
template<class DataType,size_t first,size_t... rest>
class multiArray
{
private:
    multiArray<DataType,rest...> a[first];
public:
    using iterator = DataType*;
    using const_iterator = const DataType*;
    multiArray<DataType,rest...>& operator[](const size_t j)
    {
        return a[j];
    }
    const multiArray<DataType,rest...>& operator[](const size_t j)const
    {
        return a[j];
    }
    iterator begin()
    {
        return reinterpret_cast<iterator>(a);
    }
    const_iterator begin()const
    {
        return reinterpret_cast<const_iterator>(a);
    }
    iterator end()
    {
        return reinterpret_cast<iterator>(a) + size(*this);/*size(const
multiArray&) will be defined soon.*/
    }
    const_iterator end()const
    {
        return reinterpret_cast<const_iterator>(a) + size(*this);
    }
};
template<class DataType,size_t first>
class multiArray<DataType,first>
{
private:
    DataType a[first];
public:
    using iterator = DataType*;
    using const_iterator = const DataType*;
    DataType& operator[](const size_t j)
    {
        return a[j];
    }
    const DataType& operator[](const size_t j)const
    {
        return a[j];
    }
    iterator begin()
    {
        return a;
    }
    const_iterator begin()const
    {
        return a;
    }
    iterator end()
    {
        return a + first;
    }
    const_iterator end()const
    {
        return a + first;
    }
};
template<class T>
constexpr auto product(T&& first)
{
    return first;
}
template<class T,class... all>
constexpr auto product(T&& first,all&&... rest)
{
    return first * product(rest...);
}
template<class DataType,size_t first,size_t... rest>
constexpr size_t size(const multiArray<DataType,first,rest...>& a)
{
    return product(first,rest...);
}
/*zero-length arrays can be prevented like this:
template<class DataType>
class multiArray<DataType,0>;*/
This minimal design does not  sacrifice C-style array performance. It
provides capabilities like copying and moving arrays, thus it enables the
user to define generic functions which  take arrays as arguments or return
arrays despite their type or dimensions. However this comes at the price of
brace-initialized and constexpr arrays.

--

---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.

------=_Part_2002_1316397900.1443201824804
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><div>Hello everyone</div><div>I am thinking of adding a si=
mple multi-dimensional array class to the standard library. The proposed cl=
ass can have the following interface:</div><div><div>template&lt;class Data=
Type,size_t first,size_t... rest&gt;</div><div>class multiArray</div><div>{=
</div><div>private:</div><div>=C2=A0 =C2=A0 multiArray&lt;DataType,rest...&=
gt; a[first];</div><div>public:</div><div>=C2=A0 =C2=A0 using iterator =3D =
DataType*;</div><div>=C2=A0 =C2=A0 using const_iterator =3D const DataType*=
;</div><div>=C2=A0 =C2=A0 multiArray&lt;DataType,rest...&gt;&amp; operator[=
](const size_t j)</div><div>=C2=A0 =C2=A0 {</div><div>=C2=A0 =C2=A0 =C2=A0 =
=C2=A0 return a[j];</div><div>=C2=A0 =C2=A0 }</div><div>=C2=A0 =C2=A0 const=
 multiArray&lt;DataType,rest...&gt;&amp; operator[](const size_t j)const</d=
iv><div>=C2=A0 =C2=A0 {</div><div>=C2=A0 =C2=A0 =C2=A0 =C2=A0 return a[j];<=
/div><div>=C2=A0 =C2=A0 }</div><div>=C2=A0 =C2=A0 iterator begin()</div><di=
v>=C2=A0 =C2=A0 {</div><div>=C2=A0 =C2=A0 =C2=A0 =C2=A0 return reinterpret_=
cast&lt;iterator&gt;(a);</div><div>=C2=A0 =C2=A0 }</div><div>=C2=A0 =C2=A0 =
const_iterator begin()const</div><div>=C2=A0 =C2=A0 {</div><div>=C2=A0 =C2=
=A0 =C2=A0 =C2=A0 return reinterpret_cast&lt;const_iterator&gt;(a);</div><d=
iv>=C2=A0 =C2=A0 }</div><div>=C2=A0 =C2=A0 iterator end()</div><div>=C2=A0 =
=C2=A0 {</div><div>=C2=A0 =C2=A0 =C2=A0 =C2=A0 return reinterpret_cast&lt;i=
terator&gt;(a) + size(*this);/*size(const multiArray&amp;) will be defined =
soon.*/</div><div>=C2=A0 =C2=A0 }</div><div>=C2=A0 =C2=A0 const_iterator en=
d()const</div><div>=C2=A0 =C2=A0 {</div><div>=C2=A0 =C2=A0 =C2=A0 =C2=A0 re=
turn reinterpret_cast&lt;const_iterator&gt;(a) + size(*this);</div><div>=C2=
=A0 =C2=A0 }</div><div>};</div><div>template&lt;class DataType,size_t first=
&gt;</div><div>class multiArray&lt;DataType,first&gt;</div><div>{</div><div=
>private:</div><div>=C2=A0 =C2=A0 DataType a[first];</div><div>public:</div=
><div>=C2=A0 =C2=A0 using iterator =3D DataType*;</div><div>=C2=A0 =C2=A0 u=
sing const_iterator =3D const DataType*;</div><div>=C2=A0 =C2=A0 DataType&a=
mp; operator[](const size_t j)</div><div>=C2=A0 =C2=A0 {</div><div>=C2=A0 =
=C2=A0 =C2=A0 =C2=A0 return a[j];</div><div>=C2=A0 =C2=A0 }</div><div>=C2=
=A0 =C2=A0 const DataType&amp; operator[](const size_t j)const</div><div>=
=C2=A0 =C2=A0 {</div><div>=C2=A0 =C2=A0 =C2=A0 =C2=A0 return a[j];</div><di=
v>=C2=A0 =C2=A0 }</div><div>=C2=A0 =C2=A0 iterator begin()</div><div>=C2=A0=
 =C2=A0 {</div><div>=C2=A0 =C2=A0 =C2=A0 =C2=A0 return a;</div><div>=C2=A0 =
=C2=A0 }</div><div>=C2=A0 =C2=A0 const_iterator begin()const</div><div>=C2=
=A0 =C2=A0 {</div><div>=C2=A0 =C2=A0 =C2=A0 =C2=A0 return a;</div><div>=C2=
=A0 =C2=A0 }</div><div>=C2=A0 =C2=A0 iterator end()</div><div>=C2=A0 =C2=A0=
 {</div><div>=C2=A0 =C2=A0 =C2=A0 =C2=A0 return a + first;</div><div>=C2=A0=
 =C2=A0 }</div><div>=C2=A0 =C2=A0 const_iterator end()const</div><div>=C2=
=A0 =C2=A0 {</div><div>=C2=A0 =C2=A0 =C2=A0 =C2=A0 return a + first;</div><=
div>=C2=A0 =C2=A0 }</div><div>};</div><div>template&lt;class T&gt;</div><di=
v>constexpr auto product(T&amp;&amp; first)</div><div>{</div><div>=C2=A0 =
=C2=A0 return first;</div><div>}</div><div>template&lt;class T,class... all=
&gt;</div><div>constexpr auto product(T&amp;&amp; first,all&amp;&amp;... re=
st)</div><div>{</div><div>=C2=A0 =C2=A0 return first * product(rest...);</d=
iv><div>}</div><div>template&lt;class DataType,size_t first,size_t... rest&=
gt;</div><div>constexpr size_t size(const multiArray&lt;DataType,first,rest=
....&gt;&amp; a)</div><div>{</div><div>=C2=A0 =C2=A0 return product(first,re=
st...);</div><div>}</div><div>/*zero-length arrays can be prevented like th=
is:</div><div>template&lt;class DataType&gt;</div><div>class multiArray&lt;=
DataType,0&gt;;*/</div></div><div>This minimal design does not =C2=A0sacrif=
ice C-style array performance. It provides capabilities like copying and mo=
ving arrays, thus it enables the user to define generic functions which =C2=
=A0take arrays as arguments or return arrays despite their type or dimensio=
ns. However this comes at the price of brace-initialized and=C2=A0constexpr=
=C2=A0arrays.</div></div>

<p></p>

-- <br />
<br />
--- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals&quot; group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />

------=_Part_2002_1316397900.1443201824804--
------=_Part_2001_1780421541.1443201824803--

.


Author: Vitali Lovich <vlovich@gmail.com>
Date: Fri, 25 Sep 2015 12:53:59 -0700
Raw View
--Apple-Mail=_14158B6A-0758-4C45-AF03-E47F3558D1BF
Content-Transfer-Encoding: quoted-printable
Content-Type: text/plain; charset=UTF-8

There=E2=80=99s already a proposal for array_view.  You may want to start w=
ith reading those proposals.

Quick google search yields N3851 but unsure if that=E2=80=99s the most rece=
nt iteration.

-Vitali

> On Sep 25, 2015, at 10:23 AM, musabalbirair@gmail.com wrote:
>=20
> Hello everyone
> I am thinking of adding a simple multi-dimensional array class to the sta=
ndard library. The proposed class can have the following interface:
> template<class DataType,size_t first,size_t... rest>
> class multiArray
> {
> private:
>     multiArray<DataType,rest...> a[first];
> public:
>     using iterator =3D DataType*;
>     using const_iterator =3D const DataType*;
>     multiArray<DataType,rest...>& operator[](const size_t j)
>     {
>         return a[j];
>     }
>     const multiArray<DataType,rest...>& operator[](const size_t j)const
>     {
>         return a[j];
>     }
>     iterator begin()
>     {
>         return reinterpret_cast<iterator>(a);
>     }
>     const_iterator begin()const
>     {
>         return reinterpret_cast<const_iterator>(a);
>     }
>     iterator end()
>     {
>         return reinterpret_cast<iterator>(a) + size(*this);/*size(const m=
ultiArray&) will be defined soon.*/
>     }
>     const_iterator end()const
>     {
>         return reinterpret_cast<const_iterator>(a) + size(*this);
>     }
> };
> template<class DataType,size_t first>
> class multiArray<DataType,first>
> {
> private:
>     DataType a[first];
> public:
>     using iterator =3D DataType*;
>     using const_iterator =3D const DataType*;
>     DataType& operator[](const size_t j)
>     {
>         return a[j];
>     }
>     const DataType& operator[](const size_t j)const
>     {
>         return a[j];
>     }
>     iterator begin()
>     {
>         return a;
>     }
>     const_iterator begin()const
>     {
>         return a;
>     }
>     iterator end()
>     {
>         return a + first;
>     }
>     const_iterator end()const
>     {
>         return a + first;
>     }
> };
> template<class T>
> constexpr auto product(T&& first)
> {
>     return first;
> }
> template<class T,class... all>
> constexpr auto product(T&& first,all&&... rest)
> {
>     return first * product(rest...);
> }
> template<class DataType,size_t first,size_t... rest>
> constexpr size_t size(const multiArray<DataType,first,rest...>& a)
> {
>     return product(first,rest...);
> }
> /*zero-length arrays can be prevented like this:
> template<class DataType>
> class multiArray<DataType,0>;*/
> This minimal design does not  sacrifice C-style array performance. It pro=
vides capabilities like copying and moving arrays, thus it enables the user=
 to define generic functions which  take arrays as arguments or return arra=
ys despite their type or dimensions. However this comes at the price of bra=
ce-initialized and constexpr arrays.
>=20
> --=20
>=20
> ---=20
> You received this message because you are subscribed to the Google Groups=
 "ISO C++ Standard - Future Proposals" group.
> To unsubscribe from this group and stop receiving emails from it, send an=
 email to std-proposals+unsubscribe@isocpp.org <mailto:std-proposals+unsubs=
cribe@isocpp.org>.
> To post to this group, send email to std-proposals@isocpp.org <mailto:std=
-proposals@isocpp.org>.
> Visit this group at http://groups.google.com/a/isocpp.org/group/std-propo=
sals/ <http://groups.google.com/a/isocpp.org/group/std-proposals/>.

--=20

---=20
You received this message because you are subscribed to the Google Groups "=
ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposa=
ls/.

--Apple-Mail=_14158B6A-0758-4C45-AF03-E47F3558D1BF
Content-Transfer-Encoding: quoted-printable
Content-Type: text/html; charset=UTF-8

<html><head><meta http-equiv=3D"Content-Type" content=3D"text/html charset=
=3Dutf-8"></head><body style=3D"word-wrap: break-word; -webkit-nbsp-mode: s=
pace; -webkit-line-break: after-white-space;" class=3D"">There=E2=80=99s al=
ready a proposal for array_view. &nbsp;You may want to start with reading t=
hose proposals.<div class=3D""><br class=3D""></div><div class=3D"">Quick g=
oogle search yields&nbsp;N3851 but unsure if that=E2=80=99s the most recent=
 iteration.</div><div class=3D""><br class=3D""></div><div class=3D"">-Vita=
li<br class=3D""><div class=3D""><br class=3D""><div><blockquote type=3D"ci=
te" class=3D""><div class=3D"">On Sep 25, 2015, at 10:23 AM, <a href=3D"mai=
lto:musabalbirair@gmail.com" class=3D"">musabalbirair@gmail.com</a> wrote:<=
/div><br class=3D"Apple-interchange-newline"><div class=3D""><div dir=3D"lt=
r" class=3D""><div class=3D"">Hello everyone</div><div class=3D"">I am thin=
king of adding a simple multi-dimensional array class to the standard libra=
ry. The proposed class can have the following interface:</div><div class=3D=
""><div class=3D"">template&lt;class DataType,size_t first,size_t... rest&g=
t;</div><div class=3D"">class multiArray</div><div class=3D"">{</div><div c=
lass=3D"">private:</div><div class=3D"">&nbsp; &nbsp; multiArray&lt;DataTyp=
e,rest...&gt; a[first];</div><div class=3D"">public:</div><div class=3D"">&=
nbsp; &nbsp; using iterator =3D DataType*;</div><div class=3D"">&nbsp; &nbs=
p; using const_iterator =3D const DataType*;</div><div class=3D"">&nbsp; &n=
bsp; multiArray&lt;DataType,rest...&gt;&amp; operator[](const size_t j)</di=
v><div class=3D"">&nbsp; &nbsp; {</div><div class=3D"">&nbsp; &nbsp; &nbsp;=
 &nbsp; return a[j];</div><div class=3D"">&nbsp; &nbsp; }</div><div class=
=3D"">&nbsp; &nbsp; const multiArray&lt;DataType,rest...&gt;&amp; operator[=
](const size_t j)const</div><div class=3D"">&nbsp; &nbsp; {</div><div class=
=3D"">&nbsp; &nbsp; &nbsp; &nbsp; return a[j];</div><div class=3D"">&nbsp; =
&nbsp; }</div><div class=3D"">&nbsp; &nbsp; iterator begin()</div><div clas=
s=3D"">&nbsp; &nbsp; {</div><div class=3D"">&nbsp; &nbsp; &nbsp; &nbsp; ret=
urn reinterpret_cast&lt;iterator&gt;(a);</div><div class=3D"">&nbsp; &nbsp;=
 }</div><div class=3D"">&nbsp; &nbsp; const_iterator begin()const</div><div=
 class=3D"">&nbsp; &nbsp; {</div><div class=3D"">&nbsp; &nbsp; &nbsp; &nbsp=
; return reinterpret_cast&lt;const_iterator&gt;(a);</div><div class=3D"">&n=
bsp; &nbsp; }</div><div class=3D"">&nbsp; &nbsp; iterator end()</div><div c=
lass=3D"">&nbsp; &nbsp; {</div><div class=3D"">&nbsp; &nbsp; &nbsp; &nbsp; =
return reinterpret_cast&lt;iterator&gt;(a) + size(*this);/*size(const multi=
Array&amp;) will be defined soon.*/</div><div class=3D"">&nbsp; &nbsp; }</d=
iv><div class=3D"">&nbsp; &nbsp; const_iterator end()const</div><div class=
=3D"">&nbsp; &nbsp; {</div><div class=3D"">&nbsp; &nbsp; &nbsp; &nbsp; retu=
rn reinterpret_cast&lt;const_iterator&gt;(a) + size(*this);</div><div class=
=3D"">&nbsp; &nbsp; }</div><div class=3D"">};</div><div class=3D"">template=
&lt;class DataType,size_t first&gt;</div><div class=3D"">class multiArray&l=
t;DataType,first&gt;</div><div class=3D"">{</div><div class=3D"">private:</=
div><div class=3D"">&nbsp; &nbsp; DataType a[first];</div><div class=3D"">p=
ublic:</div><div class=3D"">&nbsp; &nbsp; using iterator =3D DataType*;</di=
v><div class=3D"">&nbsp; &nbsp; using const_iterator =3D const DataType*;</=
div><div class=3D"">&nbsp; &nbsp; DataType&amp; operator[](const size_t j)<=
/div><div class=3D"">&nbsp; &nbsp; {</div><div class=3D"">&nbsp; &nbsp; &nb=
sp; &nbsp; return a[j];</div><div class=3D"">&nbsp; &nbsp; }</div><div clas=
s=3D"">&nbsp; &nbsp; const DataType&amp; operator[](const size_t j)const</d=
iv><div class=3D"">&nbsp; &nbsp; {</div><div class=3D"">&nbsp; &nbsp; &nbsp=
; &nbsp; return a[j];</div><div class=3D"">&nbsp; &nbsp; }</div><div class=
=3D"">&nbsp; &nbsp; iterator begin()</div><div class=3D"">&nbsp; &nbsp; {</=
div><div class=3D"">&nbsp; &nbsp; &nbsp; &nbsp; return a;</div><div class=
=3D"">&nbsp; &nbsp; }</div><div class=3D"">&nbsp; &nbsp; const_iterator beg=
in()const</div><div class=3D"">&nbsp; &nbsp; {</div><div class=3D"">&nbsp; =
&nbsp; &nbsp; &nbsp; return a;</div><div class=3D"">&nbsp; &nbsp; }</div><d=
iv class=3D"">&nbsp; &nbsp; iterator end()</div><div class=3D"">&nbsp; &nbs=
p; {</div><div class=3D"">&nbsp; &nbsp; &nbsp; &nbsp; return a + first;</di=
v><div class=3D"">&nbsp; &nbsp; }</div><div class=3D"">&nbsp; &nbsp; const_=
iterator end()const</div><div class=3D"">&nbsp; &nbsp; {</div><div class=3D=
"">&nbsp; &nbsp; &nbsp; &nbsp; return a + first;</div><div class=3D"">&nbsp=
; &nbsp; }</div><div class=3D"">};</div><div class=3D"">template&lt;class T=
&gt;</div><div class=3D"">constexpr auto product(T&amp;&amp; first)</div><d=
iv class=3D"">{</div><div class=3D"">&nbsp; &nbsp; return first;</div><div =
class=3D"">}</div><div class=3D"">template&lt;class T,class... all&gt;</div=
><div class=3D"">constexpr auto product(T&amp;&amp; first,all&amp;&amp;... =
rest)</div><div class=3D"">{</div><div class=3D"">&nbsp; &nbsp; return firs=
t * product(rest...);</div><div class=3D"">}</div><div class=3D"">template&=
lt;class DataType,size_t first,size_t... rest&gt;</div><div class=3D"">cons=
texpr size_t size(const multiArray&lt;DataType,first,rest...&gt;&amp; a)</d=
iv><div class=3D"">{</div><div class=3D"">&nbsp; &nbsp; return product(firs=
t,rest...);</div><div class=3D"">}</div><div class=3D"">/*zero-length array=
s can be prevented like this:</div><div class=3D"">template&lt;class DataTy=
pe&gt;</div><div class=3D"">class multiArray&lt;DataType,0&gt;;*/</div></di=
v><div class=3D"">This minimal design does not &nbsp;sacrifice C-style arra=
y performance. It provides capabilities like copying and moving arrays, thu=
s it enables the user to define generic functions which &nbsp;take arrays a=
s arguments or return arrays despite their type or dimensions. However this=
 comes at the price of brace-initialized and&nbsp;constexpr&nbsp;arrays.</d=
iv></div><div class=3D""><br class=3D"webkit-block-placeholder"></div>

-- <br class=3D"">
<br class=3D"">
--- <br class=3D"">
You received this message because you are subscribed to the Google Groups "=
ISO C++ Standard - Future Proposals" group.<br class=3D"">
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org" class=3D"">=
std-proposals+unsubscribe@isocpp.org</a>.<br class=3D"">
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org" class=3D"">std-proposals@isocpp.org</a>.<br class=3D"">
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/" class=3D"">http://groups.google.com/a/isocpp.org/group/std-=
proposals/</a>.<br class=3D"">
</div></blockquote></div><br class=3D""></div></div></body></html>

<p></p>

-- <br />
<br />
--- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals&quot; group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />

--Apple-Mail=_14158B6A-0758-4C45-AF03-E47F3558D1BF--

.