OSDN Git Service

2004-11-24 Benjamin Kosnik <bkoz@redhat.com>
[pf3gnuchains/gcc-fork.git] / libstdc++-v3 / include / tr1 / utility
1 // TR1 utility -*- C++ -*-
2
3 // Copyright (C) 2004 Free Software Foundation, Inc.
4 //
5 // This file is part of the GNU ISO C++ Library.  This library is free
6 // software; you can redistribute it and/or modify it under the
7 // terms of the GNU General Public License as published by the
8 // Free Software Foundation; either version 2, or (at your option)
9 // any later version.
10
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 // GNU General Public License for more details.
15
16 // You should have received a copy of the GNU General Public License along
17 // with this library; see the file COPYING.  If not, write to the Free
18 // Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
19 // USA.
20
21 /** @file 
22  *  This is a TR1 C++ Library header. 
23  */
24
25 #ifndef _TR1_UTILITY
26 #define _TR1_UTILITY 1
27
28 #include "../utility"
29
30 namespace std
31 {
32 namespace tr1
33 {
34   template<class _Tp> class tuple_size;
35   template<int _Int, class _Tp> class tuple_element;
36
37    // Various functions which give std::pair a tuple-like interface.
38   template<class _Tp1, class _Tp2>
39     struct tuple_size<std::pair<_Tp1, _Tp2> >
40     { static const int value = 2; };
41  
42   template<class _Tp1, class _Tp2>
43     struct tuple_element<0, std::pair<_Tp1, _Tp2> >
44     { typedef _Tp1 type; };
45  
46   template<class _Tp1, class _Tp2>
47     struct tuple_element<1, std::pair<_Tp1, _Tp2> >
48     { typedef _Tp2 type; };
49  
50
51   template<int _Int> struct __pair_get;
52
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
60       template<typename _Tp1, typename _Tp2>
61       static const _Tp1& __const_get(const std::pair<_Tp1, _Tp2>& __pair)
62       { return __pair.first; }
63     };
64
65   template<>
66     struct __pair_get<1>
67     {
68       template<typename _Tp1, typename _Tp2>
69       static _Tp1& __get(std::pair<_Tp1, _Tp2>& __pair)
70       { return __pair.second; }
71
72       template<typename _Tp1, typename _Tp2>
73       static const _Tp1& __const_get(const std::pair<_Tp1, _Tp2>& __pair)
74       { return __pair.second; }
75     };
76
77    template<int _I, class _Tp1, class _Tp2>
78      typename tuple_element<_I, std::pair<_Tp1, _Tp2> >::type&
79      get(pair<_Tp1, _Tp2>& __in)
80      { return __pair_get<_I>::__get(__in); }
81  
82    template<int _I, class _Tp1, class _Tp2>
83      const typename tuple_element<_I, std::pair<_Tp1, _Tp2> >::type&
84      get(const pair<_Tp1, _Tp2>& __in)
85      { return __pair_get<_I>::__const_get(__in); }
86 }
87
88
89 #endif