OSDN Git Service

2004-11-24 Benjamin Kosnik <bkoz@redhat.com>
[pf3gnuchains/gcc-fork.git] / libstdc++-v3 / include / tr1 / functional
1 // TR1 functional header -*- 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_FUNCTIONAL
26 #define _TR1_FUNCTIONAL 1
27
28 #include "../functional"
29
30 namespace std
31 {
32 namespace tr1
33 {
34   template<typename _Tp>
35     class reference_wrapper
36     {
37       _Tp* _M_data;
38     public:
39       typedef _Tp type;
40       explicit reference_wrapper(_Tp& __indata): _M_data(&__indata)
41       { }
42     
43       reference_wrapper(const reference_wrapper<_Tp>& __inref):
44       _M_data(__inref._M_data)
45       { }
46
47       reference_wrapper& 
48       operator=(const reference_wrapper<_Tp>& __inref)
49       {
50         _M_data = __inref._M_data;
51         return *this;
52       }
53       
54       operator _Tp&() const
55       { return this->get(); }
56     
57       _Tp&
58       get() const
59       { return *_M_data; }
60     };
61   
62   // Denotes a reference should be taken to a variable.
63   template<typename _Tp>
64     reference_wrapper<_Tp>
65     ref(_Tp& __t)
66     { return reference_wrapper<_Tp>(__t); }
67   
68   // Denotes a const reference should be taken to a variable.
69   template<typename _Tp>
70     reference_wrapper<const _Tp>
71     cref(const _Tp& __t)
72     { return reference_wrapper<const _Tp>(__t); }
73
74   template<typename _Tp>
75     reference_wrapper<_Tp> ref(reference_wrapper<_Tp> __t)
76     { return ref(__t.get()); }
77
78   template<typename _Tp>
79     reference_wrapper<const _Tp> cref(reference_wrapper<_Tp> __t)
80     { return cref(__t.get()); }
81 }
82 }
83
84 #endif
85