1 /////////////////////////////////////////////////////////////////////////////
3 // (C) Copyright Joaquin M Lopez Munoz 2006-2013
4 // (C) Copyright Ion Gaztanaga 2014-2014
6 // Distributed under the Boost Software License, Version 1.0.
7 // (See accompanying file LICENSE_1_0.txt or copy at
8 // http://www.boost.org/LICENSE_1_0.txt)
10 // See http://www.boost.org/libs/intrusive for documentation.
12 /////////////////////////////////////////////////////////////////////////////
14 #ifndef BOOST_INTRUSIVE_DETAIL_EBO_HOLDER_HPP
15 #define BOOST_INTRUSIVE_DETAIL_EBO_HOLDER_HPP
17 #ifndef BOOST_CONFIG_HPP
18 # include <boost/config.hpp>
21 #if defined(BOOST_HAS_PRAGMA_ONCE)
25 #include <boost/intrusive/detail/workaround.hpp>
26 #include <boost/move/utility_core.hpp>
32 #if defined(BOOST_MSVC) || defined(__BORLANDC_)
33 #define BOOST_INTRUSIVE_TT_DECL __cdecl
35 #define BOOST_INTRUSIVE_TT_DECL
38 #if defined(_MSC_EXTENSIONS) && !defined(__BORLAND__) && !defined(_WIN64) && !defined(_M_ARM) && !defined(UNDER_CE)
39 #define BOOST_INTRUSIVE_TT_TEST_MSC_FUNC_SIGS
43 struct is_unary_or_binary_function_impl
44 { static const bool value = false; };
46 // see boost ticket #4094
47 // avoid duplicate definitions of is_unary_or_binary_function_impl
48 #ifndef BOOST_INTRUSIVE_TT_TEST_MSC_FUNC_SIGS
51 struct is_unary_or_binary_function_impl<R (*)()>
52 { static const bool value = true; };
55 struct is_unary_or_binary_function_impl<R (*)(...)>
56 { static const bool value = true; };
58 #else // BOOST_INTRUSIVE_TT_TEST_MSC_FUNC_SIGS
61 struct is_unary_or_binary_function_impl<R (__stdcall*)()>
62 { static const bool value = true; };
67 struct is_unary_or_binary_function_impl<R (__fastcall*)()>
68 { static const bool value = true; };
73 struct is_unary_or_binary_function_impl<R (__cdecl*)()>
74 { static const bool value = true; };
77 struct is_unary_or_binary_function_impl<R (__cdecl*)(...)>
78 { static const bool value = true; };
82 // see boost ticket #4094
83 // avoid duplicate definitions of is_unary_or_binary_function_impl
84 #ifndef BOOST_INTRUSIVE_TT_TEST_MSC_FUNC_SIGS
86 template <typename R, class T0>
87 struct is_unary_or_binary_function_impl<R (*)(T0)>
88 { static const bool value = true; };
90 template <typename R, class T0>
91 struct is_unary_or_binary_function_impl<R (*)(T0...)>
92 { static const bool value = true; };
94 #else // BOOST_INTRUSIVE_TT_TEST_MSC_FUNC_SIGS
96 template <typename R, class T0>
97 struct is_unary_or_binary_function_impl<R (__stdcall*)(T0)>
98 { static const bool value = true; };
102 template <typename R, class T0>
103 struct is_unary_or_binary_function_impl<R (__fastcall*)(T0)>
104 { static const bool value = true; };
108 template <typename R, class T0>
109 struct is_unary_or_binary_function_impl<R (__cdecl*)(T0)>
110 { static const bool value = true; };
112 template <typename R, class T0>
113 struct is_unary_or_binary_function_impl<R (__cdecl*)(T0...)>
114 { static const bool value = true; };
118 // see boost ticket #4094
119 // avoid duplicate definitions of is_unary_or_binary_function_impl
120 #ifndef BOOST_INTRUSIVE_TT_TEST_MSC_FUNC_SIGS
122 template <typename R, class T0, class T1>
123 struct is_unary_or_binary_function_impl<R (*)(T0, T1)>
124 { static const bool value = true; };
126 template <typename R, class T0, class T1>
127 struct is_unary_or_binary_function_impl<R (*)(T0, T1...)>
128 { static const bool value = true; };
130 #else // BOOST_INTRUSIVE_TT_TEST_MSC_FUNC_SIGS
132 template <typename R, class T0, class T1>
133 struct is_unary_or_binary_function_impl<R (__stdcall*)(T0, T1)>
134 { static const bool value = true; };
138 template <typename R, class T0, class T1>
139 struct is_unary_or_binary_function_impl<R (__fastcall*)(T0, T1)>
140 { static const bool value = true; };
144 template <typename R, class T0, class T1>
145 struct is_unary_or_binary_function_impl<R (__cdecl*)(T0, T1)>
146 { static const bool value = true; };
148 template <typename R, class T0, class T1>
149 struct is_unary_or_binary_function_impl<R (__cdecl*)(T0, T1...)>
150 { static const bool value = true; };
153 template <typename T>
154 struct is_unary_or_binary_function_impl<T&>
155 { static const bool value = false; };
158 struct is_unary_or_binary_function : is_unary_or_binary_function_impl<T>
161 template<typename T, bool = is_unary_or_binary_function<T>::value>
162 class ebo_functor_holder
164 BOOST_COPYABLE_AND_MOVABLE(ebo_functor_holder)
167 typedef T functor_type;
169 BOOST_INTRUSIVE_FORCEINLINE ebo_functor_holder()
173 BOOST_INTRUSIVE_FORCEINLINE explicit ebo_functor_holder(const T &t)
177 BOOST_INTRUSIVE_FORCEINLINE explicit ebo_functor_holder(BOOST_RV_REF(T) t)
178 : t_(::boost::move(t))
181 template<class Arg1, class Arg2>
182 BOOST_INTRUSIVE_FORCEINLINE ebo_functor_holder(BOOST_FWD_REF(Arg1) arg1, BOOST_FWD_REF(Arg2) arg2)
183 : t_(::boost::forward<Arg1>(arg1), ::boost::forward<Arg2>(arg2))
186 BOOST_INTRUSIVE_FORCEINLINE ebo_functor_holder(const ebo_functor_holder &x)
190 BOOST_INTRUSIVE_FORCEINLINE ebo_functor_holder(BOOST_RV_REF(ebo_functor_holder) x)
194 BOOST_INTRUSIVE_FORCEINLINE ebo_functor_holder& operator=(BOOST_COPY_ASSIGN_REF(ebo_functor_holder) x)
196 this->get() = x.get();
200 BOOST_INTRUSIVE_FORCEINLINE ebo_functor_holder& operator=(BOOST_RV_REF(ebo_functor_holder) x)
202 this->get() = ::boost::move(x.get());
206 BOOST_INTRUSIVE_FORCEINLINE ebo_functor_holder& operator=(const T &x)
212 BOOST_INTRUSIVE_FORCEINLINE ebo_functor_holder& operator=(BOOST_RV_REF(T) x)
214 this->get() = ::boost::move(x);
218 BOOST_INTRUSIVE_FORCEINLINE T& get(){return t_;}
219 BOOST_INTRUSIVE_FORCEINLINE const T& get()const{return t_;}
226 class ebo_functor_holder<T, false>
229 BOOST_COPYABLE_AND_MOVABLE(ebo_functor_holder)
232 typedef T functor_type;
234 BOOST_INTRUSIVE_FORCEINLINE ebo_functor_holder()
238 BOOST_INTRUSIVE_FORCEINLINE explicit ebo_functor_holder(const T &t)
242 BOOST_INTRUSIVE_FORCEINLINE explicit ebo_functor_holder(BOOST_RV_REF(T) t)
243 : T(::boost::move(t))
246 template<class Arg1, class Arg2>
247 BOOST_INTRUSIVE_FORCEINLINE ebo_functor_holder(BOOST_FWD_REF(Arg1) arg1, BOOST_FWD_REF(Arg2) arg2)
248 : T(::boost::forward<Arg1>(arg1), ::boost::forward<Arg2>(arg2))
251 BOOST_INTRUSIVE_FORCEINLINE ebo_functor_holder(const ebo_functor_holder &x)
252 : T(static_cast<const T&>(x))
255 BOOST_INTRUSIVE_FORCEINLINE ebo_functor_holder(BOOST_RV_REF(ebo_functor_holder) x)
256 : T(BOOST_MOVE_BASE(T, x))
259 BOOST_INTRUSIVE_FORCEINLINE ebo_functor_holder& operator=(BOOST_COPY_ASSIGN_REF(ebo_functor_holder) x)
261 const ebo_functor_holder&r = x;
266 BOOST_INTRUSIVE_FORCEINLINE ebo_functor_holder& operator=(BOOST_RV_REF(ebo_functor_holder) x)
268 this->get() = ::boost::move(x.get());
272 BOOST_INTRUSIVE_FORCEINLINE ebo_functor_holder& operator=(const T &x)
278 BOOST_INTRUSIVE_FORCEINLINE ebo_functor_holder& operator=(BOOST_RV_REF(T) x)
280 this->get() = ::boost::move(x);
284 BOOST_INTRUSIVE_FORCEINLINE T& get(){return *this;}
285 BOOST_INTRUSIVE_FORCEINLINE const T& get()const{return *this;}
288 } //namespace detail {
289 } //namespace intrusive {
290 } //namespace boost {
292 #endif //#ifndef BOOST_INTRUSIVE_DETAIL_EBO_HOLDER_HPP