]> git.ipfire.org Git - thirdparty/gcc.git/blobdiff - libstdc++-v3/include/std/utility
Update copyright years in libstdc++-v3/
[thirdparty/gcc.git] / libstdc++-v3 / include / std / utility
index 245c41fa75dde001134aca4b8a2a7dc7526a5b58..4da92095f11956b5474df818e7ecbe96db79c6eb 100644 (file)
@@ -1,7 +1,6 @@
 // <utility> -*- C++ -*-
 
-// Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010
-// Free Software Foundation, Inc.
+// Copyright (C) 2001-2014 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
@@ -70,7 +69,7 @@
 #include <bits/stl_relops.h>
 #include <bits/stl_pair.h>
 
-#ifdef __GXX_EXPERIMENTAL_CXX0X__
+#if __cplusplus >= 201103L
 #include <bits/move.h>
 #include <initializer_list>
 
@@ -86,19 +85,15 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 
    // Various functions which give std::pair a tuple-like interface.
   template<class _Tp1, class _Tp2>
-    struct tuple_size<std::pair<_Tp1, _Tp2> >
-    { static const std::size_t value = 2; };
+    struct tuple_size<std::pair<_Tp1, _Tp2>>
+    : public integral_constant<std::size_t, 2> { };
 
   template<class _Tp1, class _Tp2>
-    const std::size_t
-    tuple_size<std::pair<_Tp1, _Tp2> >::value;
-
-  template<class _Tp1, class _Tp2>
-    struct tuple_element<0, std::pair<_Tp1, _Tp2> >
+    struct tuple_element<0, std::pair<_Tp1, _Tp2>>
     { typedef _Tp1 type; };
  
   template<class _Tp1, class _Tp2>
-    struct tuple_element<1, std::pair<_Tp1, _Tp2> >
+    struct tuple_element<1, std::pair<_Tp1, _Tp2>>
     { typedef _Tp2 type; };
 
   template<std::size_t _Int>
@@ -108,36 +103,158 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
     struct __pair_get<0>
     {
       template<typename _Tp1, typename _Tp2>
-      static _Tp1& __get(std::pair<_Tp1, _Tp2>& __pair)
-      { return __pair.first; }
+        static constexpr _Tp1&
+        __get(std::pair<_Tp1, _Tp2>& __pair) noexcept
+        { return __pair.first; }
 
       template<typename _Tp1, typename _Tp2>
-      static const _Tp1& __const_get(const std::pair<_Tp1, _Tp2>& __pair)
-      { return __pair.first; }
+        static constexpr _Tp1&&
+        __move_get(std::pair<_Tp1, _Tp2>&& __pair) noexcept
+        { return std::forward<_Tp1>(__pair.first); }
+
+      template<typename _Tp1, typename _Tp2>
+        static constexpr const _Tp1&
+        __const_get(const std::pair<_Tp1, _Tp2>& __pair) noexcept
+        { return __pair.first; }
     };
 
   template<>
     struct __pair_get<1>
     {
       template<typename _Tp1, typename _Tp2>
-      static _Tp2& __get(std::pair<_Tp1, _Tp2>& __pair)
-      { return __pair.second; }
+        static constexpr _Tp2&
+        __get(std::pair<_Tp1, _Tp2>& __pair) noexcept
+        { return __pair.second; }
+
+      template<typename _Tp1, typename _Tp2>
+        static constexpr _Tp2&&
+        __move_get(std::pair<_Tp1, _Tp2>&& __pair) noexcept
+        { return std::forward<_Tp2>(__pair.second); }
 
       template<typename _Tp1, typename _Tp2>
-      static const _Tp2& __const_get(const std::pair<_Tp1, _Tp2>& __pair)
-      { return __pair.second; }
+        static constexpr const _Tp2&
+        __const_get(const std::pair<_Tp1, _Tp2>& __pair) noexcept
+        { return __pair.second; }
     };
 
   template<std::size_t _Int, class _Tp1, class _Tp2>
-    inline typename tuple_element<_Int, std::pair<_Tp1, _Tp2> >::type&
-    get(std::pair<_Tp1, _Tp2>& __in)
+    constexpr typename tuple_element<_Int, std::pair<_Tp1, _Tp2>>::type&
+    get(std::pair<_Tp1, _Tp2>& __in) noexcept
     { return __pair_get<_Int>::__get(__in); }
 
   template<std::size_t _Int, class _Tp1, class _Tp2>
-    inline const typename tuple_element<_Int, std::pair<_Tp1, _Tp2> >::type&
-    get(const std::pair<_Tp1, _Tp2>& __in)
+    constexpr typename tuple_element<_Int, std::pair<_Tp1, _Tp2>>::type&&
+    get(std::pair<_Tp1, _Tp2>&& __in) noexcept
+    { return __pair_get<_Int>::__move_get(std::move(__in)); }
+
+  template<std::size_t _Int, class _Tp1, class _Tp2>
+    constexpr const typename tuple_element<_Int, std::pair<_Tp1, _Tp2>>::type&
+    get(const std::pair<_Tp1, _Tp2>& __in) noexcept
     { return __pair_get<_Int>::__const_get(__in); }
 
+#if __cplusplus > 201103L
+  template <typename _Tp, typename _Up>
+    constexpr _Tp&
+    get(pair<_Tp, _Up>& __p) noexcept
+    { return __p.first; }
+
+  template <typename _Tp, typename _Up>
+    constexpr const _Tp&
+    get(const pair<_Tp, _Up>& __p) noexcept
+    { return __p.first; }
+
+  template <typename _Tp, typename _Up>
+    constexpr _Tp&&
+    get(pair<_Tp, _Up>&& __p) noexcept
+    { return std::move(__p.first); }
+
+  template <typename _Tp, typename _Up>
+    constexpr _Tp&
+    get(pair<_Up, _Tp>& __p) noexcept
+    { return __p.second; }
+
+  template <typename _Tp, typename _Up>
+    constexpr const _Tp&
+    get(const pair<_Up, _Tp>& __p) noexcept
+    { return __p.second; }
+
+  template <typename _Tp, typename _Up>
+    constexpr _Tp&&
+    get(pair<_Up, _Tp>&& __p) noexcept
+    { return std::move(__p.second); }
+
+  /// Assign @p __new_val to @p __obj and return its previous value.
+  template <typename _Tp, typename _Up = _Tp>
+    inline _Tp
+    exchange(_Tp& __obj, _Up&& __new_val)
+    {
+      _Tp __old_val = std::move(__obj);
+      __obj = std::forward<_Up>(__new_val);
+      return __old_val;
+    }
+#endif
+
+  // Stores a tuple of indices.  Used by tuple and pair, and by bind() to
+  // extract the elements in a tuple.
+  template<size_t... _Indexes>
+    struct _Index_tuple
+    {
+      typedef _Index_tuple<_Indexes..., sizeof...(_Indexes)> __next;
+    };
+
+  // Builds an _Index_tuple<0, 1, 2, ..., _Num-1>.
+  template<size_t _Num>
+    struct _Build_index_tuple
+    {
+      typedef typename _Build_index_tuple<_Num - 1>::__type::__next __type;
+    };
+
+  template<>
+    struct _Build_index_tuple<0>
+    {
+      typedef _Index_tuple<> __type;
+    };
+
+#if __cplusplus > 201103L
+  /// Class template integer_sequence
+  template<typename _Tp, _Tp... _Idx>
+    struct integer_sequence
+    {
+      typedef _Tp value_type;
+      static constexpr size_t size() { return sizeof...(_Idx); }
+    };
+
+  template<typename _Tp, _Tp _Num,
+          typename _ISeq = typename _Build_index_tuple<_Num>::__type>
+    struct _Make_integer_sequence;
+
+  template<typename _Tp, _Tp _Num,  size_t... _Idx>
+    struct _Make_integer_sequence<_Tp, _Num, _Index_tuple<_Idx...>>
+    {
+      static_assert( _Num >= 0,
+                    "Cannot make integer sequence of negative length" );
+
+      typedef integer_sequence<_Tp, static_cast<_Tp>(_Idx)...> __type;
+    };
+
+  /// Alias template make_integer_sequence
+  template<typename _Tp, _Tp _Num>
+    using make_integer_sequence
+      = typename _Make_integer_sequence<_Tp, _Num>::__type;
+
+  /// Alias template index_sequence
+  template<size_t... _Idx>
+    using index_sequence = integer_sequence<size_t, _Idx...>;
+
+  /// Alias template make_index_sequence
+  template<size_t _Num>
+    using make_index_sequence = make_integer_sequence<size_t, _Num>;
+
+  /// Alias template index_sequence_for
+  template<typename... _Types>
+    using index_sequence_for = make_index_sequence<sizeof...(_Types)>;
+#endif
+
 _GLIBCXX_END_NAMESPACE_VERSION
 } // namespace