Chris@102: // Boost.Range library Chris@102: // Chris@102: // Copyright Neil Groves 2014. Use, modification and Chris@102: // distribution is subject to the Boost Software License, Version Chris@102: // 1.0. (See accompanying file LICENSE_1_0.txt or copy at Chris@102: // http://www.boost.org/LICENSE_1_0.txt) Chris@102: // Chris@102: // For more information, see http://www.boost.org/libs/range/ Chris@102: // Chris@102: #ifndef BOOST_RANGE_DETAIL_DEFAULT_CONSTRUCTIBLE_UNARY_FN_HPP_INCLUDED Chris@102: #define BOOST_RANGE_DETAIL_DEFAULT_CONSTRUCTIBLE_UNARY_FN_HPP_INCLUDED Chris@102: Chris@102: #include Chris@102: #include Chris@102: #include Chris@102: Chris@102: namespace boost Chris@102: { Chris@102: namespace range_detail Chris@102: { Chris@102: Chris@102: template Chris@102: class default_constructible_unary_fn_wrapper Chris@102: { Chris@102: public: Chris@102: typedef R result_type; Chris@102: Chris@102: default_constructible_unary_fn_wrapper() Chris@102: { Chris@102: } Chris@102: default_constructible_unary_fn_wrapper(const F& source) Chris@102: : m_impl(source) Chris@102: { Chris@102: } Chris@102: template Chris@102: R operator()(const Arg& arg) const Chris@102: { Chris@102: BOOST_ASSERT(m_impl); Chris@102: return (*m_impl)(arg); Chris@102: } Chris@102: template Chris@102: R operator()(Arg& arg) const Chris@102: { Chris@102: BOOST_ASSERT(m_impl); Chris@102: return (*m_impl)(arg); Chris@102: } Chris@102: private: Chris@102: boost::optional m_impl; Chris@102: }; Chris@102: Chris@102: template Chris@102: struct default_constructible_unary_fn_gen Chris@102: { Chris@102: typedef typename boost::mpl::if_< Chris@102: boost::has_trivial_default_constructor, Chris@102: F, Chris@102: default_constructible_unary_fn_wrapper Chris@102: >::type type; Chris@102: }; Chris@102: Chris@102: } // namespace range_detail Chris@102: } // namespace boost Chris@102: Chris@102: #endif // include guard