diff --git a/include/boost/parameter/aux_/template_keyword.hpp b/include/boost/parameter/aux_/template_keyword.hpp index 5a02f008a..ce5b943c9 100644 --- a/include/boost/parameter/aux_/template_keyword.hpp +++ b/include/boost/parameter/aux_/template_keyword.hpp @@ -7,8 +7,17 @@ # include # include +# include # include -# include +# include +# include +# include + +# if defined(BOOST_NO_CXX11_HDR_FUNCTIONAL) +# include +# else +# include +# endif namespace boost { namespace parameter { @@ -25,7 +34,7 @@ namespace aux template struct is_template_keyword : mpl::and_< - mpl::not_ > + mpl::not_ > , is_pointer_convertible > {}; @@ -37,7 +46,19 @@ struct template_keyword : aux::template_keyword_tag { typedef Tag key_type; - typedef T value_type; + + // Wrap plain (non-UDT) function objects in either + // a boost::function or a std::function. -- Cromwell D. Enage + typedef typename ::boost::mpl::if_< + ::boost::is_function +#if defined(BOOST_NO_CXX11_HDR_FUNCTIONAL) + , ::boost::function +#else + , ::std::function +#endif + , T + >::type value_type; + typedef value_type reference; }; diff --git a/test/Jamfile.v2 b/test/Jamfile.v2 index 856559ca1..96606e756 100644 --- a/test/Jamfile.v2 +++ b/test/Jamfile.v2 @@ -20,6 +20,7 @@ test-suite "parameter" [ run tutorial.cpp ] [ run singular.cpp ] [ run mpl.cpp ] + [ run function_type_tpl_param.cpp ] [ run preprocessor.cpp ] [ run preprocessor_deduced.cpp ] [ run efficiency.cpp : : : : : release ] diff --git a/test/function_type_tpl_param.cpp b/test/function_type_tpl_param.cpp new file mode 100755 index 000000000..3b51650a8 --- /dev/null +++ b/test/function_type_tpl_param.cpp @@ -0,0 +1,70 @@ +// Copyright Frank Mori Hess 2009. +// Copyright Cromwell D. Enage 2017. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include +#include +#include +#include +#include +#include +#include + +#if defined(BOOST_NO_CXX11_HDR_FUNCTIONAL) +#include +#else +#include +#endif + +namespace test { + namespace keywords { + + BOOST_PARAMETER_TEMPLATE_KEYWORD(function_type) + } // namespace keywords + + template + struct X + : boost::parameter::value_type< + typename boost::parameter::parameters< + boost::parameter::required + >::BOOST_NESTED_TEMPLATE bind< + A + >::type + , K + > + { + }; + + template + struct Y + : boost::mpl::if_< + boost::is_same< +#if defined(BOOST_NO_CXX11_HDR_FUNCTIONAL) + boost::function +#else + std::function +#endif + , typename X< + test::keywords::tag::function_type + , test::keywords::function_type + >::type + > + , boost::mpl::true_ + , boost::mpl::false_ + >::type + { + }; +} // namespace test + +#include +#include + +MPL_TEST_CASE() +{ + BOOST_MPL_ASSERT((test::Y)); + BOOST_MPL_ASSERT_NOT((test::Y)); + BOOST_MPL_ASSERT((test::Y)); +} +