[Boost-bugs] [Boost C++ Libraries] #7652: compile-time checked access

Subject: [Boost-bugs] [Boost C++ Libraries] #7652: compile-time checked access
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2012-11-06 06:56:56


#7652: compile-time checked access
------------------------------+---------------------------------------------
 Reporter: tobias.loew | Owner: marshall
     Type: Feature Requests | Status: new
Milestone: To Be Determined | Component: array
  Version: Boost 1.52.0 | Severity: Optimization
 Keywords: |
------------------------------+---------------------------------------------
 Since code like

 boost::array<int,2> test;
 test[2] = 1;
 test[-1] = 1;

 compiles correctly on some compilers (even without warnings). I suggest
 adding compile checked functions for static access to arrays like:
         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];
         }


 then code like:

 boost::array<int,2> test;
 test.at<2> = 1;
 test.at<-1> = 1;

 would result in the expected errors.

-- 
Ticket URL: <https://svn.boost.org/trac/boost/ticket/7652>
Boost C++ Libraries <http://www.boost.org/>
Boost provides free peer-reviewed portable C++ source libraries.

This archive was generated by hypermail 2.1.7 : 2017-02-16 18:50:11 UTC