OSDN Git Service

2012-03-22 Paolo Carlini <paolo.carlini@oracle.com>
[pf3gnuchains/gcc-fork.git] / libstdc++-v3 / include / std / array
index 474b884..8cd5388 100644 (file)
@@ -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
@@ -35,6 +36,7 @@
 # include <bits/c++0x_warning.h>
 #else
 
+#include <stdexcept>
 #include <bits/stl_algobase.h>
 #include <bits/range_access.h>
 
@@ -60,8 +62,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
     struct array
     {
       typedef _Tp                                    value_type;
-      typedef _Tp*                                    pointer;
-      typedef const _Tp*                              const_pointer;
+      typedef value_type*                            pointer;
+      typedef const value_type*                       const_pointer;
       typedef value_type&                            reference;
       typedef const value_type&                      const_reference;
       typedef value_type*                            iterator;
@@ -89,19 +91,19 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
       // Iterators.
       iterator
       begin() noexcept
-      { return iterator(std::__addressof(_M_instance[0])); }
+      { return iterator(data()); }
 
       const_iterator
       begin() const noexcept
-      { return const_iterator(std::__addressof(_M_instance[0])); }
+      { return const_iterator(data()); }
 
       iterator
       end() noexcept
-      { return iterator(std::__addressof(_M_instance[_Nm])); }
+      { return iterator(data() + _Nm); }
 
       const_iterator
       end() const noexcept
-      { return const_iterator(std::__addressof(_M_instance[_Nm])); }
+      { return const_iterator(data() + _Nm); }
 
       reverse_iterator 
       rbegin() noexcept
@@ -150,8 +152,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
       operator[](size_type __n)
       { return _M_instance[__n]; }
 
-      const_reference
-      operator[](size_type __n) const
+      constexpr const_reference
+      operator[](size_type __n) const noexcept
       { return _M_instance[__n]; }
 
       reference
@@ -162,6 +164,14 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
        return _M_instance[__n];
       }
 
+#ifdef __EXCEPTIONS
+      constexpr const_reference
+      at(size_type __n) const
+      {
+       return __n < _Nm ? 
+              _M_instance[__n] : throw out_of_range(__N("array::at"));
+      }
+#else
       const_reference
       at(size_type __n) const
       {
@@ -169,6 +179,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
          std::__throw_out_of_range(__N("array::at"));
        return _M_instance[__n];
       }
+#endif
 
       reference 
       front()
@@ -186,11 +197,11 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
       back() const
       { return _Nm ? *(end() - 1) : *end(); }
 
-      _Tp*
+      pointer
       data() noexcept
       { return std::__addressof(_M_instance[0]); }
 
-      const _Tp*
+      const_pointer
       data() const noexcept
       { return std::__addressof(_M_instance[0]); }
     };
@@ -255,19 +266,19 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
     { typedef _Tp type; };
 
   template<std::size_t _Int, typename _Tp, std::size_t _Nm>
-    inline _Tp&
+    constexpr _Tp&
     get(array<_Tp, _Nm>& __arr) noexcept
-    { return __arr[_Int]; }
+    { return __arr._M_instance[_Int]; }
 
   template<std::size_t _Int, typename _Tp, std::size_t _Nm>
-    inline _Tp&&
+    constexpr _Tp&&
     get(array<_Tp, _Nm>&& __arr) noexcept
     { return std::move(get<_Int>(__arr)); }
 
   template<std::size_t _Int, typename _Tp, std::size_t _Nm>
-    inline const _Tp&
+    constexpr const _Tp&
     get(const array<_Tp, _Nm>& __arr) noexcept
-    { return __arr[_Int]; }
+    { return __arr._M_instance[_Int]; }
 
 _GLIBCXX_END_NAMESPACE_VERSION
 } // namespace