This is the mail archive of the libstdc++@gcc.gnu.org mailing list for the libstdc++ project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

index check in std::array


I am wondering why in g++ 4.7.2 (and possibly later versions) indexes
still are not checked in std::array operator[] when compiling in debug
mode, which is IMHO the biggest advantage std::array has over
C-arrays. boost::array has this feature.

The task can be accomplished quite easily - as shown in several forum
threads. E.g.

      // Element access.
      reference
      operator[](size_type __n)
      {
// added
#ifndef NDEBUG
        if (__n >= _Nm)
          std::__throw_out_of_range(__N("array::[]"));
#endif        
        return _M_instance[__n];
      }

      constexpr const_reference
      operator[](size_type __n) const noexcept
      {
// added
#ifndef NDEBUG
        if (__n >= _Nm)
          std::__throw_out_of_range(__N("array::[]"));
#endif        
        return _M_instance[__n];
      }

/MB


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]