2 * Copyright 2002, The libsigc++ Development Team
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.
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.
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
19 #ifndef _SIGC_REFERENCE_WRAPPER_H_
20 #define _SIGC_REFERENCE_WRAPPER_H_
22 #include <functional> // For std::reference_wrapper.
26 #ifndef SIGCXX_DISABLE_DEPRECATED
28 /** Reference wrapper.
29 * Use sigc::ref() to create a reference wrapper.
31 * @deprecated Use std::ref() or std::cref() instead to create a std::reference_wrapper().
33 template <class T_type>
34 struct reference_wrapper
36 explicit reference_wrapper(T_type& v)
39 operator T_type& () const
45 /** Const reference wrapper.
46 * Use sigc::ref() to create a const reference wrapper.
48 * @deprecated Use std::ref() or std::cref() instead to create a std::reference_wrapper().
50 template <class T_type>
51 struct const_reference_wrapper
53 explicit const_reference_wrapper(const T_type& v)
56 operator const T_type& () const
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
69 * @param v Reference to store.
70 * @return A reference wrapper.
72 * @deprecated Use std::ref() or std::cref() instead.
74 template <class T_type>
75 reference_wrapper<T_type> ref(T_type& v)
76 { return reference_wrapper<T_type>(v); }
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
85 * @param v Reference to store.
86 * @return A reference wrapper.
88 * @deprecated Use std::ref() or std::cref() instead.
90 template <class T_type>
91 const_reference_wrapper<T_type> ref(const T_type& v)
92 { return const_reference_wrapper<T_type>(v); }
94 #endif // SIGCXX_DISABLE_DEPRECATED
97 template <class T_type>
98 struct unwrap_reference
104 #ifndef SIGCXX_DISABLE_DEPRECATED
106 // Specializations for std::reference_wrapper and std::const_reference_wrapper:
108 template <class T_type>
109 struct unwrap_reference<reference_wrapper<T_type> >
111 typedef T_type& type;
114 template <class T_type>
115 struct unwrap_reference<const_reference_wrapper<T_type> >
117 typedef const T_type& type;
120 template <class T_type>
121 T_type& unwrap(const reference_wrapper<T_type>& v)
124 template <class T_type>
125 const T_type& unwrap(const const_reference_wrapper<T_type>& v)
128 #endif // SIGCXX_DISABLE_DEPRECATED
130 //Specializations for std::reference_wrapper:
132 template <class T_type>
133 struct unwrap_reference<std::reference_wrapper<T_type> >
135 typedef T_type& type;
138 template <class T_type>
139 T_type& unwrap(const std::reference_wrapper<T_type>& v)
142 } /* namespace sigc */
144 #endif /* _SIGC_REFERENCE_WRAPPER_H_ */