]> git.lyx.org Git - lyx.git/blob - boost/boost/ref.hpp
complie fix
[lyx.git] / boost / boost / ref.hpp
1 #ifndef BOOST_REF_HPP_INCLUDED
2 # define BOOST_REF_HPP_INCLUDED
3
4 # if _MSC_VER+0 >= 1020
5 #  pragma once
6 # endif
7
8 # include <boost/config.hpp>
9 # include <boost/utility/addressof.hpp>
10
11 //
12 //  ref.hpp - ref/cref, useful helper functions
13 //
14 //  Copyright (C) 1999, 2000 Jaakko Järvi (jaakko.jarvi@cs.utu.fi)
15 //  Copyright (C) 2001, 2002 Peter Dimov
16 //  Copyright (C) 2002 David Abrahams
17 //
18 //  Permission to copy, use, modify, sell and distribute this software
19 //  is granted provided this copyright notice appears in all copies.
20 //  This software is provided "as is" without express or implied
21 //  warranty, and with no claim as to its suitability for any purpose.
22 //
23 //  See http://www.boost.org/libs/bind/ref.html for documentation.
24 //
25
26 namespace boost
27 {
28
29 template<class T> class reference_wrapper
30
31 public:
32     typedef T type;
33
34 #if defined(BOOST_MSVC) && (BOOST_MSVC < 1300)
35
36     explicit reference_wrapper(T& t): t_(&t) {}
37
38 #else
39
40     explicit reference_wrapper(T& t): t_(addressof(t)) {}
41
42 #endif
43
44     operator T& () const { return *t_; }
45
46     T& get() const { return *t_; }
47
48     T* get_pointer() const { return t_; }
49
50 private:
51
52     T* t_;
53 };
54
55 # if defined(__BORLANDC__) && (__BORLANDC__ <= 0x570)
56 #  define BOOST_REF_CONST
57 # else
58 #  define BOOST_REF_CONST const
59 # endif
60
61 template<class T> inline reference_wrapper<T> BOOST_REF_CONST ref(T & t)
62
63     return reference_wrapper<T>(t);
64 }
65
66 template<class T> inline reference_wrapper<T const> BOOST_REF_CONST cref(T const & t)
67 {
68     return reference_wrapper<T const>(t);
69 }
70
71 # undef BOOST_REF_CONST
72
73 # ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
74 template<typename T>
75 class is_reference_wrapper
76 {
77  public:
78     BOOST_STATIC_CONSTANT(bool, value = false); 
79 };
80
81 template<typename T>
82 class is_reference_wrapper<reference_wrapper<T> >
83 {
84  public:
85     BOOST_STATIC_CONSTANT(bool, value = true);
86 };
87
88 template<typename T>
89 class unwrap_reference
90 {
91  public:
92     typedef T type;
93 };
94
95 template<typename T>
96 class unwrap_reference<reference_wrapper<T> >
97 {
98  public:
99     typedef T type;
100 };
101 # else // no partial specialization
102
103 } // namespace boost
104
105 #include <boost/type.hpp>
106
107 namespace boost
108 {
109
110 namespace detail
111 {
112   typedef char (&yes_reference_wrapper_t)[1];
113   typedef char (&no_reference_wrapper_t)[2];
114       
115   no_reference_wrapper_t is_reference_wrapper_test(...);
116
117   template<typename T>
118   yes_reference_wrapper_t is_reference_wrapper_test(type< reference_wrapper<T> >);
119
120   template<bool wrapped>
121   struct reference_unwrapper
122   {
123       template <class T>
124       struct apply
125       {
126           typedef T type;
127       };
128   };
129
130   template<>
131   struct reference_unwrapper<true>
132   {
133       template <class T>
134       struct apply
135       {
136           typedef typename T::type type;
137       };
138   };
139 }
140
141 template<typename T>
142 class is_reference_wrapper
143 {
144  public:
145     BOOST_STATIC_CONSTANT(
146         bool, value = (
147             sizeof(detail::is_reference_wrapper_test(type<T>()))
148             == sizeof(detail::yes_reference_wrapper_t)));
149 };
150
151 template <typename T>
152 class unwrap_reference
153     : public detail::reference_unwrapper<
154         is_reference_wrapper<T>::value
155       >::template apply<T>
156 {};
157
158 # endif // BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
159
160 } // namespace boost
161
162 #endif // #ifndef BOOST_REF_HPP_INCLUDED