Boost logo

Boost Users :

Subject: Re: [Boost-users] [array] range check (at compile time)
From: Joel Falcou (joel.falcou_at_[hidden])
Date: 2010-03-12 01:49:09


alfC wrote:
>> Hmm, shouldn't the adaptor for boost::array use the template parameter
>> of boost::array to define its extant?
>
> a small example on how to create such adaptor to boost::array will be
> greatly appreciated.
>
> thanks,
> Alfredo

Basically, if i am not mistaken on your intent, you need to change the
behavior of fusion::at_impl for array so it fires a static assert if the
index is greater than the array extent:

   template<> struct at_impl<array_tag>
   {
     template<typename Sequence, typename N>
     struct apply
     {
       typedef typename mpl::if_ < is_const<Sequence>
                                 , typename Sequence::const_reference
                                 , typename Sequence::reference>::type type;

           static type call(Sequence& seq)
          {
              BOOST_STATIC_ASSERT(N < Sequence::static_size);
              return seq[N::value];
           }
       };
   };


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net