diff options
Diffstat (limited to 'libstdc++-v3/include/std/array')
| -rw-r--r-- | libstdc++-v3/include/std/array | 25 |
1 files changed, 19 insertions, 6 deletions
diff --git a/libstdc++-v3/include/std/array b/libstdc++-v3/include/std/array index 3e177444083..e895dd7fc67 100644 --- a/libstdc++-v3/include/std/array +++ b/libstdc++-v3/include/std/array @@ -1,6 +1,7 @@ // <array> -*- C++ -*- -// Copyright (C) 2007, 2008, 2009, 2010, 2011 Free Software Foundation, Inc. +// Copyright (C) 2007, 2008, 2009, 2010, 2011, 2012 +// Free Software Foundation, Inc. // // This file is part of the GNU ISO C++ Library. This library is free // software; you can redistribute it and/or modify it under the @@ -261,23 +262,35 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION class tuple_element; template<std::size_t _Int, typename _Tp, std::size_t _Nm> - struct tuple_element<_Int, array<_Tp, _Nm> > - { typedef _Tp type; }; + struct tuple_element<_Int, array<_Tp, _Nm>> + { + static_assert(_Int < _Nm, "index is out of bounds"); + typedef _Tp type; + }; template<std::size_t _Int, typename _Tp, std::size_t _Nm> constexpr _Tp& get(array<_Tp, _Nm>& __arr) noexcept - { return __arr._M_instance[_Int]; } + { + static_assert(_Int < _Nm, "index is out of bounds"); + return __arr._M_instance[_Int]; + } template<std::size_t _Int, typename _Tp, std::size_t _Nm> constexpr _Tp&& get(array<_Tp, _Nm>&& __arr) noexcept - { return std::move(get<_Int>(__arr)); } + { + static_assert(_Int < _Nm, "index is out of bounds"); + return std::move(get<_Int>(__arr)); + } template<std::size_t _Int, typename _Tp, std::size_t _Nm> constexpr const _Tp& get(const array<_Tp, _Nm>& __arr) noexcept - { return __arr._M_instance[_Int]; } + { + static_assert(_Int < _Nm, "index is out of bounds"); + return __arr._M_instance[_Int]; + } _GLIBCXX_END_NAMESPACE_VERSION } // namespace |
