]> git.tdb.fi Git - ext/sigc++-2.0.git/blob - sigc++/reference_wrapper.h
Import libsigc++ 2.10.8 sources
[ext/sigc++-2.0.git] / sigc++ / reference_wrapper.h
1 /*
2  * Copyright 2002, The libsigc++ Development Team
3  *
4  *  This library is free software; you can redistribute it and/or
5  *  modify it under the terms of the GNU Lesser General Public
6  *  License as published by the Free Software Foundation; either
7  *  version 2.1 of the License, or (at your option) any later version.
8  *
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 GNU
12  *  Lesser General Public License for more details.
13  *
14  *  You should have received a copy of the GNU Lesser General Public
15  *  License along with this library; if not, write to the Free Software
16  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  *
18  */
19 #ifndef _SIGC_REFERENCE_WRAPPER_H_
20 #define _SIGC_REFERENCE_WRAPPER_H_
21
22 #include <functional> // For std::reference_wrapper.
23
24 namespace sigc {
25
26 #ifndef SIGCXX_DISABLE_DEPRECATED
27
28 /** Reference wrapper.
29  * Use sigc::ref() to create a reference wrapper.
30  *
31  * @deprecated Use std::ref() or std::cref() instead to create a std::reference_wrapper().
32  */
33 template <class T_type>
34 struct reference_wrapper
35 {
36   explicit reference_wrapper(T_type& v)
37     : value_(v)  {}
38
39   operator T_type& () const
40     { return value_; }
41
42   T_type& value_;
43 };
44
45 /** Const reference wrapper.
46  * Use sigc::ref() to create a const reference wrapper.
47  *
48  * @deprecated Use std::ref() or std::cref() instead to create a std::reference_wrapper().
49  */
50 template <class T_type>
51 struct const_reference_wrapper
52 {
53   explicit const_reference_wrapper(const T_type& v)
54     : value_(v)  {}
55
56   operator const T_type& () const
57     { return value_; }
58
59   const T_type& value_;
60 };
61
62 /** Creates a reference wrapper.
63  * Passing an object throught sigc::ref() makes libsigc++ adaptors
64  * like, e.g., sigc::bind store references to the object instead of copies.
65  * If the object type inherits from sigc::trackable this will ensure
66  * automatic invalidation of the adaptors when the object is deleted
67  * or overwritten.
68  *
69  * @param v Reference to store.
70  * @return A reference wrapper.
71  *
72  * @deprecated Use std::ref() or std::cref() instead.
73  */
74 template <class T_type>
75 reference_wrapper<T_type> ref(T_type& v)
76 { return reference_wrapper<T_type>(v); }
77
78 /** Creates a const reference wrapper.
79  * Passing an object throught sigc::ref() makes libsigc++ adaptors
80  * like, e.g., sigc::bind store references to the object instead of copies.
81  * If the object type inherits from sigc::trackable this will ensure
82  * automatic invalidation of the adaptors when the object is deleted
83  * or overwritten.
84  *
85  * @param v Reference to store.
86  * @return A reference wrapper.
87  *
88  * @deprecated Use std::ref() or std::cref() instead.
89  */
90 template <class T_type>
91 const_reference_wrapper<T_type> ref(const T_type& v)
92 { return const_reference_wrapper<T_type>(v); }
93
94 #endif // SIGCXX_DISABLE_DEPRECATED
95
96
97 template <class T_type>
98 struct unwrap_reference
99 {
100   typedef T_type type;
101 };
102
103
104 #ifndef SIGCXX_DISABLE_DEPRECATED
105
106 // Specializations for std::reference_wrapper and std::const_reference_wrapper:
107
108 template <class T_type>
109 struct unwrap_reference<reference_wrapper<T_type> >
110 {
111   typedef T_type& type;
112 };
113
114 template <class T_type>
115 struct unwrap_reference<const_reference_wrapper<T_type> >
116 {
117   typedef const T_type& type;
118 };
119
120 template <class T_type>
121 T_type& unwrap(const reference_wrapper<T_type>& v)
122 { return v; }
123
124 template <class T_type>
125 const T_type& unwrap(const const_reference_wrapper<T_type>& v)
126 { return v; }
127
128 #endif // SIGCXX_DISABLE_DEPRECATED
129
130 //Specializations for std::reference_wrapper:
131
132 template <class T_type>
133 struct unwrap_reference<std::reference_wrapper<T_type> >
134 {
135   typedef T_type& type;
136 };
137
138 template <class T_type>
139 T_type& unwrap(const std::reference_wrapper<T_type>& v)
140 { return v; }
141
142 } /* namespace sigc */
143
144 #endif /* _SIGC_REFERENCE_WRAPPER_H_ */