]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/range/include/boost/range/detail/default_constructible_unary_fn.hpp
bump version to 12.2.2-pve1
[ceph.git] / ceph / src / boost / libs / range / include / boost / range / detail / default_constructible_unary_fn.hpp
1 // Boost.Range library
2 //
3 // Copyright Neil Groves 2014. Use, modification and
4 // distribution is subject to the Boost Software License, Version
5 // 1.0. (See accompanying file LICENSE_1_0.txt or copy at
6 // http://www.boost.org/LICENSE_1_0.txt)
7 //
8 // For more information, see http://www.boost.org/libs/range/
9 //
10 #ifndef BOOST_RANGE_DETAIL_DEFAULT_CONSTRUCTIBLE_UNARY_FN_HPP_INCLUDED
11 #define BOOST_RANGE_DETAIL_DEFAULT_CONSTRUCTIBLE_UNARY_FN_HPP_INCLUDED
12
13 #include <boost/optional/optional.hpp>
14 #include <boost/mpl/if.hpp>
15 #include <boost/type_traits/has_trivial_constructor.hpp>
16
17 namespace boost
18 {
19 namespace range_detail
20 {
21
22 template<typename F, typename R>
23 class default_constructible_unary_fn_wrapper
24 {
25 public:
26 typedef R result_type;
27
28 default_constructible_unary_fn_wrapper()
29 {
30 }
31 default_constructible_unary_fn_wrapper(const F& source)
32 : m_impl(source)
33 {
34 }
35 template<typename Arg>
36 R operator()(const Arg& arg) const
37 {
38 BOOST_ASSERT(m_impl);
39 return (*m_impl)(arg);
40 }
41 template<typename Arg>
42 R operator()(Arg& arg) const
43 {
44 BOOST_ASSERT(m_impl);
45 return (*m_impl)(arg);
46 }
47 private:
48 boost::optional<F> m_impl;
49 };
50
51 template<typename F, typename R>
52 struct default_constructible_unary_fn_gen
53 {
54 typedef typename boost::mpl::if_<
55 boost::has_trivial_default_constructor<F>,
56 F,
57 default_constructible_unary_fn_wrapper<F,R>
58 >::type type;
59 };
60
61 } // namespace range_detail
62 } // namespace boost
63
64 #endif // include guard