Re: dynamic_*<T>

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Re: dynamic_*<T>

Boost - Dev mailing list
Alexander wrote:
> So if T[] and T[N] are valid, then T[N][M] should also be. This increases
the scope greatly but has an incredible difficult questions to answer: What
would operator[] return? I don't have a good answer...

Simple questions that already have an answer:
The same way shared_ptr<T[N][M]> works today. :)

Its operator[] returns element_type&

So:
     auto p = allocate_shared<int[5][1024]>(alloc);
     p[3][675] = 8;

     auto q = allocate_unique<double[][2][3][4]>(alloc, size);
     q[index][1][1][1] = 0.95;

Then:
    dynamic<int[5][1024], Allocator> a(alloc);
    a[3][675] = 8;

i.e. Making it work for T[N] also automatically makes it work for T[N][M].

Glen

_______________________________________________
Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
Reply | Threaded
Open this post in threaded view
|

Re: dynamic_*<T>

Boost - Dev mailing list
> Alexander wrote:

>> So if T[] and T[N] are valid, then T[N][M] should also be. This increases
> the scope greatly but has an incredible difficult questions to answer: What
> would operator[] return? I don't have a good answer...
>
> Simple questions that already have an answer:
> The same way shared_ptr<T[N][M]> works today. :)
>
> Its operator[] returns element_type&
>
> So:
>       auto p = allocate_shared<int[5][1024]>(alloc);
>       p[3][675] = 8;
>
>       auto q = allocate_unique<double[][2][3][4]>(alloc, size);
>       q[index][1][1][1] = 0.95;
>
> Then:
>      dynamic<int[5][1024], Allocator> a(alloc);
>      a[3][675] = 8;
>
> i.e. Making it work for T[N] also automatically makes it work for T[N][M].
Sure, but shouldn't `Foo<T[N][M]>[]` return `Foo<T[N]>` so you can pass
it down like that? Sure returning basically a raw array is possible and
easiest, but you (may) loose the goodies for type/range checking and you
can't get a lower-D type out of a high-D type for passing that down an
interface.




_______________________________________________
Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost

smime.p7s (6K) Download Attachment