]> git.ipfire.org Git - thirdparty/gcc.git/blobdiff - libstdc++-v3/include/debug/array
Update copyright years.
[thirdparty/gcc.git] / libstdc++-v3 / include / debug / array
index 3ff786a1247161d76fc2ee03533e7a32ef1a5ace..3f87e98fe8d20c3d816b2ca7e480b7f75ab29877 100644 (file)
@@ -1,6 +1,6 @@
 // Debugging array implementation -*- C++ -*-
 
-// Copyright (C) 2012-2017 Free Software Foundation, Inc.
+// Copyright (C) 2012-2020 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
@@ -71,7 +71,7 @@ namespace __debug
       template<std::size_t _Size>
        struct _Array_check_nonempty
        {
-         bool empty() { return _Size == 0; }
+         _GLIBCXX_NODISCARD bool empty() { return _Size == 0; }
 
          _Array_check_nonempty()
          { __glibcxx_check_nonempty(); }
@@ -80,11 +80,11 @@ namespace __debug
       // No explicit construct/copy/destroy for aggregate type.
 
       // DR 776.
-      void
+      _GLIBCXX20_CONSTEXPR void
       fill(const value_type& __u)
       { std::fill_n(begin(), size(), __u); }
 
-      void
+      _GLIBCXX20_CONSTEXPR void
       swap(array& __other)
       noexcept(_AT_Type::_Is_nothrow_swappable::value)
       { std::swap_ranges(begin(), end(), __other.begin()); }
@@ -145,7 +145,7 @@ namespace __debug
       constexpr size_type
       max_size() const noexcept { return _Nm; }
 
-      constexpr bool
+      _GLIBCXX_NODISCARD constexpr bool
       empty() const noexcept { return size() == 0; }
 
       // Element access.
@@ -225,18 +225,28 @@ namespace __debug
       { return _AT_Type::_S_ptr(_M_elems); }
     };
 
+#if __cpp_deduction_guides >= 201606
+  template<typename _Tp, typename... _Up>
+    array(_Tp, _Up...)
+      -> array<std::enable_if_t<(std::is_same_v<_Tp, _Up> && ...), _Tp>,
+              1 + sizeof...(_Up)>;
+#endif
+
   // Array comparisons.
   template<typename _Tp, std::size_t _Nm>
+    _GLIBCXX20_CONSTEXPR
     inline bool
     operator==(const array<_Tp, _Nm>& __one, const array<_Tp, _Nm>& __two)
     { return std::equal(__one.begin(), __one.end(), __two.begin()); }
 
   template<typename _Tp, std::size_t _Nm>
+    _GLIBCXX20_CONSTEXPR
     inline bool
     operator!=(const array<_Tp, _Nm>& __one, const array<_Tp, _Nm>& __two)
     { return !(__one == __two); }
 
   template<typename _Tp, std::size_t _Nm>
+    _GLIBCXX20_CONSTEXPR
     inline bool
     operator<(const array<_Tp, _Nm>& __a, const array<_Tp, _Nm>& __b)
     {
@@ -245,16 +255,19 @@ namespace __debug
     }
 
   template<typename _Tp, std::size_t _Nm>
+    _GLIBCXX20_CONSTEXPR
     inline bool
     operator>(const array<_Tp, _Nm>& __one, const array<_Tp, _Nm>& __two)
     { return __two < __one; }
 
   template<typename _Tp, std::size_t _Nm>
+    _GLIBCXX20_CONSTEXPR
     inline bool
     operator<=(const array<_Tp, _Nm>& __one, const array<_Tp, _Nm>& __two)
     { return !(__one > __two); }
 
   template<typename _Tp, std::size_t _Nm>
+    _GLIBCXX20_CONSTEXPR
     inline bool
     operator>=(const array<_Tp, _Nm>& __one, const array<_Tp, _Nm>& __two)
     { return !(__one < __two); }
@@ -269,6 +282,7 @@ namespace __debug
 #endif
 
   template<typename _Tp, std::size_t _Nm>
+    _GLIBCXX20_CONSTEXPR
     inline void
     swap(array<_Tp, _Nm>& __one, array<_Tp, _Nm>& __two)
     noexcept(noexcept(__one.swap(__two)))
@@ -299,6 +313,53 @@ namespace __debug
       return _GLIBCXX_STD_C::__array_traits<_Tp, _Nm>::
        _S_ref(__arr._M_elems, _Int);
     }
+
+  template<std::size_t _Int, typename _Tp, std::size_t _Nm>
+    constexpr const _Tp&&
+    get(const array<_Tp, _Nm>&& __arr) noexcept
+    {
+      static_assert(_Int < _Nm, "index is out of bounds");
+      return std::move(__debug::get<_Int>(__arr));
+    }
+
+#if __cplusplus > 201703L
+#define __cpp_lib_to_array 201907L
+
+  template<bool _Move = false, typename _Tp, size_t... _Idx>
+    constexpr array<remove_cv_t<_Tp>, sizeof...(_Idx)>
+    __to_array(_Tp (&__a)[sizeof...(_Idx)], index_sequence<_Idx...>)
+    {
+      if constexpr (_Move)
+       return {{std::move(__a[_Idx])...}};
+      else
+       return {{__a[_Idx]...}};
+    }
+
+  template<typename _Tp, size_t _Nm>
+    constexpr array<remove_cv_t<_Tp>, _Nm>
+    to_array(_Tp (&__a)[_Nm])
+    noexcept(is_nothrow_constructible_v<_Tp, _Tp&>)
+    {
+      static_assert(!is_array_v<_Tp>);
+      static_assert(is_constructible_v<_Tp, _Tp&>);
+      if constexpr (is_constructible_v<_Tp, _Tp&>)
+       return __debug::__to_array(__a, make_index_sequence<_Nm>{});
+      __builtin_unreachable(); // FIXME: see PR c++/91388
+    }
+
+  template<typename _Tp, size_t _Nm>
+    constexpr array<remove_cv_t<_Tp>, _Nm>
+    to_array(_Tp (&&__a)[_Nm])
+    noexcept(is_nothrow_move_constructible_v<_Tp>)
+    {
+      static_assert(!is_array_v<_Tp>);
+      static_assert(is_move_constructible_v<_Tp>);
+      if constexpr (is_move_constructible_v<_Tp>)
+       return __debug::__to_array<1>(__a, make_index_sequence<_Nm>{});
+      __builtin_unreachable(); // FIXME: see PR c++/91388
+    }
+#endif // C++20
+
 } // namespace __debug
 
 _GLIBCXX_BEGIN_NAMESPACE_VERSION