utility 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. // TR1 utility -*- C++ -*-
  2. // Copyright (C) 2004-2022 Free Software Foundation, Inc.
  3. //
  4. // This file is part of the GNU ISO C++ Library. This library is free
  5. // software; you can redistribute it and/or modify it under the
  6. // terms of the GNU General Public License as published by the
  7. // Free Software Foundation; either version 3, or (at your option)
  8. // any later version.
  9. // This library is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU General Public License for more details.
  13. // Under Section 7 of GPL version 3, you are granted additional
  14. // permissions described in the GCC Runtime Library Exception, version
  15. // 3.1, as published by the Free Software Foundation.
  16. // You should have received a copy of the GNU General Public License and
  17. // a copy of the GCC Runtime Library Exception along with this program;
  18. // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
  19. // <http://www.gnu.org/licenses/>.
  20. /** @file tr1/utility
  21. * This is a TR1 C++ Library header.
  22. */
  23. #ifndef _GLIBCXX_TR1_UTILITY
  24. #define _GLIBCXX_TR1_UTILITY 1
  25. #pragma GCC system_header
  26. #include <bits/c++config.h>
  27. #include <bits/stl_relops.h>
  28. #include <bits/stl_pair.h>
  29. namespace std _GLIBCXX_VISIBILITY(default)
  30. {
  31. _GLIBCXX_BEGIN_NAMESPACE_VERSION
  32. namespace tr1
  33. {
  34. template<class _Tp>
  35. class tuple_size;
  36. template<int _Int, class _Tp>
  37. class tuple_element;
  38. // Various functions which give std::pair a tuple-like interface.
  39. template<class _Tp1, class _Tp2>
  40. struct tuple_size<std::pair<_Tp1, _Tp2> >
  41. { static const int value = 2; };
  42. template<class _Tp1, class _Tp2>
  43. const int
  44. tuple_size<std::pair<_Tp1, _Tp2> >::value;
  45. template<class _Tp1, class _Tp2>
  46. struct tuple_element<0, std::pair<_Tp1, _Tp2> >
  47. { typedef _Tp1 type; };
  48. template<class _Tp1, class _Tp2>
  49. struct tuple_element<1, std::pair<_Tp1, _Tp2> >
  50. { typedef _Tp2 type; };
  51. template<int _Int>
  52. struct __pair_get;
  53. template<>
  54. struct __pair_get<0>
  55. {
  56. template<typename _Tp1, typename _Tp2>
  57. static _Tp1& __get(std::pair<_Tp1, _Tp2>& __pair)
  58. { return __pair.first; }
  59. template<typename _Tp1, typename _Tp2>
  60. static const _Tp1& __const_get(const std::pair<_Tp1, _Tp2>& __pair)
  61. { return __pair.first; }
  62. };
  63. template<>
  64. struct __pair_get<1>
  65. {
  66. template<typename _Tp1, typename _Tp2>
  67. static _Tp2& __get(std::pair<_Tp1, _Tp2>& __pair)
  68. { return __pair.second; }
  69. template<typename _Tp1, typename _Tp2>
  70. static const _Tp2& __const_get(const std::pair<_Tp1, _Tp2>& __pair)
  71. { return __pair.second; }
  72. };
  73. template<int _Int, class _Tp1, class _Tp2>
  74. inline typename tuple_element<_Int, std::pair<_Tp1, _Tp2> >::type&
  75. get(std::pair<_Tp1, _Tp2>& __in)
  76. { return __pair_get<_Int>::__get(__in); }
  77. template<int _Int, class _Tp1, class _Tp2>
  78. inline const typename tuple_element<_Int, std::pair<_Tp1, _Tp2> >::type&
  79. get(const std::pair<_Tp1, _Tp2>& __in)
  80. { return __pair_get<_Int>::__const_get(__in); }
  81. }
  82. _GLIBCXX_END_NAMESPACE_VERSION
  83. }
  84. #endif // _GLIBCXX_TR1_UTILITY