Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:51:16

0001 // Boost.Range library
0002 //
0003 //  Copyright Neil Groves 2014. Use, modification and
0004 //  distribution is subject to the Boost Software License, Version
0005 //  1.0. (See accompanying file LICENSE_1_0.txt or copy at
0006 //  http://www.boost.org/LICENSE_1_0.txt)
0007 //
0008 // For more information, see http://www.boost.org/libs/range/
0009 //
0010 #ifndef BOOST_RANGE_DETAIL_DEFAULT_CONSTRUCTIBLE_UNARY_FN_HPP_INCLUDED
0011 #define BOOST_RANGE_DETAIL_DEFAULT_CONSTRUCTIBLE_UNARY_FN_HPP_INCLUDED
0012 
0013 #include <boost/optional/optional.hpp>
0014 #include <boost/mpl/if.hpp>
0015 #include <boost/type_traits/has_trivial_constructor.hpp>
0016 
0017 namespace boost
0018 {
0019     namespace range_detail
0020     {
0021 
0022 template<typename F, typename R>
0023 class default_constructible_unary_fn_wrapper
0024 {
0025 public:
0026     typedef R result_type;
0027 
0028     default_constructible_unary_fn_wrapper()
0029     {
0030     }
0031     default_constructible_unary_fn_wrapper(const F& source)
0032         : m_impl(source)
0033     {
0034     }
0035     default_constructible_unary_fn_wrapper(const default_constructible_unary_fn_wrapper& source)
0036         : m_impl(source.m_impl)
0037     {
0038     }
0039     default_constructible_unary_fn_wrapper& operator=(const default_constructible_unary_fn_wrapper& source)
0040     {
0041         if (source.m_impl)
0042         {
0043             // Lambda are not copy/move assignable.
0044             m_impl.emplace(*source.m_impl);
0045         }
0046         else
0047         {
0048             m_impl.reset();
0049         }
0050         return *this;
0051     }
0052     template<typename Arg>
0053     R operator()(const Arg& arg) const
0054     {
0055         BOOST_ASSERT(m_impl);
0056         return (*m_impl)(arg);
0057     }
0058     template<typename Arg>
0059     R operator()(Arg& arg) const
0060     {
0061         BOOST_ASSERT(m_impl);
0062         return (*m_impl)(arg);
0063     }
0064 private:
0065     boost::optional<F> m_impl;
0066 };
0067 
0068 template<typename F, typename R>
0069 struct default_constructible_unary_fn_gen
0070 {
0071     typedef typename boost::mpl::if_<
0072         boost::has_trivial_default_constructor<F>,
0073         F,
0074         default_constructible_unary_fn_wrapper<F,R>
0075     >::type type;
0076 };
0077 
0078     } // namespace range_detail
0079 } // namespace boost
0080 
0081 #endif // include guard