Boost logo

Boost :

Subject: Re: [boost] [array] compile-time checked access
From: Tobias Loew (Tobias.Loew_at_[hidden])
Date: 2012-11-05 09:57:23


Jeffrey Lee Hellrung, Jr.-2 wrote
> On Mon, Nov 5, 2012 at 6:02 AM, Tobias Loew <

> Tobias.Loew@

> > wrote:
>
>> I used the "raw"-tag to quote the code. Here is it again without the
>> tags:
>>
>> ...
>> So, code like
>>
>> boost::array<int,2> test;
>> test[2] = 1;
>> test[-1] = 1;
>>
>>
>> compiles without warnings or erros.
>> Now, adding the following functions to array
>>
>> template
> <size_type i>
>> reference at()
>> {
>> BOOST_STATIC_ASSERT( (i < N) );
>> return elems[i];
>> }
>>
>> template
> <size_type i>
>> const_reference at() const
>> {
>> BOOST_STATIC_ASSERT( (i < N) );
>> return elems[i];
>> }
>>
>>
>> would make it possible to write
>>
>> boost::array&lt;int,2&gt; test;
>> test.at<2> = 1;
>> test.at<-1> = 1;
>>
>>
>> which results in the expected error messages.
>>
>
> You can try to use boost::fusion::at_c
> <N>
> (test), but not sure if it
> actually has a static assertion. See
>
> http://www.boost.org/doc/libs/1_51_0/libs/fusion/doc/html/fusion/sequence/intrinsic/functions/at_c.html
> http://www.boost.org/doc/libs/1_51_0/libs/fusion/doc/html/fusion/adapted/boost__array.html
>
> - Jeff
>
> _______________________________________________
> Unsubscribe & other changes:
> http://lists.boost.org/mailman/listinfo.cgi/boost

I tried it, but it doesn't static assert. Shouldn't it ?

--
View this message in context: http://boost.2283326.n4.nabble.com/array-compile-time-checked-access-tp4638135p4638173.html
Sent from the Boost - Dev mailing list archive at Nabble.com.

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