d03650ee052938f12240570bd0f848de5d309d5b
[libcds.git] / cds / ref.h
1 //$$CDS-header$$
2
3 #ifndef __CDS_REF_H
4 #define __CDS_REF_H
5
6 #include <cds/details/defs.h>
7 #include <boost/ref.hpp>
8
9 //@cond
10 namespace cds {
11
12     using boost::ref;
13
14     namespace details {
15         template <typename T>
16         struct unwrap_reference
17         {
18             typedef T type;
19             static T apply(T f)
20             {
21                 return f;
22             }
23         };
24
25         template <typename T>
26         struct unwrap_reference<T&>
27         {
28             typedef T& type;
29             static T& apply( T& f )
30             {
31                 return f;
32             }
33         };
34
35         template <typename T>
36         struct unwrap_reference<boost::reference_wrapper<T> >
37         {
38             typedef T& type;
39             static T& apply( boost::reference_wrapper<T> f )
40             {
41                 return f.get();
42             }
43         };
44     }
45
46     template <typename T>
47     static inline typename details::unwrap_reference<T>::type unref( T f )
48     {
49         return cds::details::unwrap_reference<T>::apply(f);
50     }
51 }
52 //@endcond
53
54 #endif // #ifndef __CDS_REF_H