[libcxx-commits] [libcxx] 0161874 - [libc++] NFC: Inline array<T, N>::at methods inside the class

Louis Dionne via libcxx-commits libcxx-commits at lists.llvm.org
Fri May 22 06:25:37 PDT 2020


Author: Louis Dionne
Date: 2020-05-22T09:24:07-04:00
New Revision: 0161874c04645cbcb8c69af38a571b9fba84cd48

URL: https://github.com/llvm/llvm-project/commit/0161874c04645cbcb8c69af38a571b9fba84cd48
DIFF: https://github.com/llvm/llvm-project/commit/0161874c04645cbcb8c69af38a571b9fba84cd48.diff

LOG: [libc++] NFC: Inline array<T,N>::at methods inside the class

All other methods are defined in the class, so this increases consistency.

Added: 
    

Modified: 
    libcxx/include/array

Removed: 
    


################################################################################
diff  --git a/libcxx/include/array b/libcxx/include/array
index 81685bf06040..7ffa825a9652 100644
--- a/libcxx/include/array
+++ b/libcxx/include/array
@@ -194,8 +194,19 @@ struct _LIBCPP_TEMPLATE_VIS array
     _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
     const_reference operator[](size_type __n) const _NOEXCEPT {return __elems_[__n];}
 
-    _LIBCPP_CONSTEXPR_AFTER_CXX14       reference at(size_type __n);
-    _LIBCPP_CONSTEXPR_AFTER_CXX11 const_reference at(size_type __n) const;
+    _LIBCPP_CONSTEXPR_AFTER_CXX14 reference at(size_type __n)
+    {
+        if (__n >= _Size)
+            __throw_out_of_range("array::at");
+        return __elems_[__n];
+    }
+
+    _LIBCPP_CONSTEXPR_AFTER_CXX11 const_reference at(size_type __n) const
+    {
+        if (__n >= _Size)
+            __throw_out_of_range("array::at");
+        return __elems_[__n];
+    }
 
     _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 reference front()             _NOEXCEPT {return __elems_[0];}
     _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 const_reference front() const _NOEXCEPT {return __elems_[0];}
@@ -208,28 +219,6 @@ struct _LIBCPP_TEMPLATE_VIS array
     const value_type* data() const _NOEXCEPT {return __elems_;}
 };
 
-
-template <class _Tp, size_t _Size>
-_LIBCPP_CONSTEXPR_AFTER_CXX14
-typename array<_Tp, _Size>::reference
-array<_Tp, _Size>::at(size_type __n)
-{
-    if (__n >= _Size)
-        __throw_out_of_range("array::at");
-
-    return __elems_[__n];
-}
-
-template <class _Tp, size_t _Size>
-_LIBCPP_CONSTEXPR_AFTER_CXX11
-typename array<_Tp, _Size>::const_reference
-array<_Tp, _Size>::at(size_type __n) const
-{
-    if (__n >= _Size)
-        __throw_out_of_range("array::at");
-    return __elems_[__n];
-}
-
 template <class _Tp>
 struct _LIBCPP_TEMPLATE_VIS array<_Tp, 0>
 {


        


More information about the libcxx-commits mailing list