1 // Copyright Daniel Wallin 2006. Use, modification and distribution is
2 // subject to the Boost Software License, Version 1.0. (See accompanying
3 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6 // 2009.10.21 TDS remove depenency on boost::python::detail::referent_storage
8 #ifndef BOOST_PARAMETER_MAYBE_091021_HPP
9 # define BOOST_PARAMETER_MAYBE_091021_HPP
11 # include <boost/mpl/if.hpp>
12 # include <boost/mpl/identity.hpp>
13 # include <boost/type_traits/is_reference.hpp>
14 # include <boost/type_traits/add_reference.hpp>
15 # include <boost/optional.hpp>
16 # include <boost/aligned_storage.hpp>
17 # include <boost/type_traits/remove_cv.hpp>
18 # include <boost/type_traits/add_const.hpp>
19 # include <boost/parameter/aux_/is_maybe.hpp>
21 namespace boost
{ namespace parameter
{ namespace aux
{
23 template <class T
> struct referent_size
;
26 struct referent_size
<T
&>
28 BOOST_STATIC_CONSTANT(std::size_t, value
= sizeof(T
));
31 // A metafunction returning a POD type which can store U, where T ==
32 // U&. If T is not a reference type, returns a POD which can store T.
34 struct referent_storage
36 typedef typename
boost::aligned_storage
<
37 referent_size
<T
>::value
42 struct maybe
: maybe_base
44 typedef typename add_reference
<
45 # if BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x564))
48 typename add_const
<T
>::type
52 typedef typename remove_cv
<
53 BOOST_DEDUCED_TYPENAME remove_reference
<reference
>::type
56 explicit maybe(T value_
)
71 reference
construct(reference value_
) const
77 reference
construct2(U
const& value_
) const
79 new (m_storage
.address()) non_cv_value(value_
);
81 return *(non_cv_value
*)m_storage
.address();
85 reference
construct(U
const& value_
) const
87 return this->construct2(value_
);
92 ((non_cv_value
*)m_storage
.address())->~non_cv_value();
95 typedef reference(maybe
<T
>::*safe_bool
)() const;
97 operator safe_bool() const
99 return value
? &maybe
<T
>::get
: 0 ;
102 reference
get() const
108 boost::optional
<T
> value
;
109 mutable bool constructed
;
112 mutable typename referent_storage
<
117 }}} // namespace boost::parameter::aux
119 #endif // BOOST_PARAMETER_MAYBE_060211_HPP