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