123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272 |
- // <utility> -*- C++ -*-
- // Copyright (C) 2001-2015 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
- // terms of the GNU General Public License as published by the
- // Free Software Foundation; either version 3, or (at your option)
- // any later version.
- // This library is distributed in the hope that it will be useful,
- // but WITHOUT ANY WARRANTY; without even the implied warranty of
- // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- // GNU General Public License for more details.
- // Under Section 7 of GPL version 3, you are granted additional
- // permissions described in the GCC Runtime Library Exception, version
- // 3.1, as published by the Free Software Foundation.
- // You should have received a copy of the GNU General Public License and
- // a copy of the GCC Runtime Library Exception along with this program;
- // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
- // <http://www.gnu.org/licenses/>.
- /*
- *
- * Copyright (c) 1994
- * Hewlett-Packard Company
- *
- * Permission to use, copy, modify, distribute and sell this software
- * and its documentation for any purpose is hereby granted without fee,
- * provided that the above copyright notice appear in all copies and
- * that both that copyright notice and this permission notice appear
- * in supporting documentation. Hewlett-Packard Company makes no
- * representations about the suitability of this software for any
- * purpose. It is provided "as is" without express or implied warranty.
- *
- *
- * Copyright (c) 1996,1997
- * Silicon Graphics Computer Systems, Inc.
- *
- * Permission to use, copy, modify, distribute and sell this software
- * and its documentation for any purpose is hereby granted without fee,
- * provided that the above copyright notice appear in all copies and
- * that both that copyright notice and this permission notice appear
- * in supporting documentation. Silicon Graphics makes no
- * representations about the suitability of this software for any
- * purpose. It is provided "as is" without express or implied warranty.
- */
- /** @file include/utility
- * This is a Standard C++ Library header.
- */
- #ifndef _GLIBCXX_UTILITY
- #define _GLIBCXX_UTILITY 1
- #pragma GCC system_header
- /**
- * @defgroup utilities Utilities
- *
- * Components deemed generally useful. Includes pair, tuple,
- * forward/move helpers, ratio, function object, metaprogramming and
- * type traits, time, date, and memory functions.
- */
- #include <bits/c++config.h>
- #include <bits/stl_relops.h>
- #include <bits/stl_pair.h>
- #if __cplusplus >= 201103L
- #include <bits/move.h>
- #include <initializer_list>
- namespace std _GLIBCXX_VISIBILITY(default)
- {
- _GLIBCXX_BEGIN_NAMESPACE_VERSION
- template<class _Tp>
- class tuple_size;
- template<std::size_t _Int, class _Tp>
- class tuple_element;
- // Various functions which give std::pair a tuple-like interface.
- /// Partial specialization for std::pair
- template<class _Tp1, class _Tp2>
- struct tuple_size<std::pair<_Tp1, _Tp2>>
- : public integral_constant<std::size_t, 2> { };
- /// Partial specialization for std::pair
- template<class _Tp1, class _Tp2>
- struct tuple_element<0, std::pair<_Tp1, _Tp2>>
- { typedef _Tp1 type; };
-
- /// Partial specialization for std::pair
- template<class _Tp1, class _Tp2>
- struct tuple_element<1, std::pair<_Tp1, _Tp2>>
- { typedef _Tp2 type; };
- template<std::size_t _Int>
- struct __pair_get;
- template<>
- struct __pair_get<0>
- {
- template<typename _Tp1, typename _Tp2>
- static constexpr _Tp1&
- __get(std::pair<_Tp1, _Tp2>& __pair) noexcept
- { return __pair.first; }
- template<typename _Tp1, typename _Tp2>
- 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 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 constexpr const _Tp2&
- __const_get(const std::pair<_Tp1, _Tp2>& __pair) noexcept
- { return __pair.second; }
- };
- template<std::size_t _Int, class _Tp1, class _Tp2>
- 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>
- 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
- #define __cpp_lib_tuples_by_type 201304
- 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); }
- #define __cpp_lib_exchange_function 201304
- /// 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)
- { return std::__exchange(__obj, std::forward<_Up>(__new_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
- #define __cpp_lib_integer_sequence 201304
- /// 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
- #endif
- #endif /* _GLIBCXX_UTILITY */
|