Skip to content

Commit

Permalink
Upgrade BOOST_PARAMETER_TEMPLATE_KEYWORD
Browse files Browse the repository at this point in the history
Keyword templates generated by BOOST_PARAMETER_TEMPLATE_KEYWORD can now accept function types.
  • Loading branch information
CromwellEnage committed Oct 16, 2018
1 parent 5d3e393 commit fb88905
Show file tree
Hide file tree
Showing 3 changed files with 95 additions and 3 deletions.
27 changes: 24 additions & 3 deletions include/boost/parameter/aux_/template_keyword.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,17 @@

# include <boost/mpl/and.hpp>
# include <boost/mpl/not.hpp>
# include <boost/mpl/if.hpp>
# include <boost/type_traits/is_convertible.hpp>
# include <boost/type_traits/is_reference.hpp>
# include <boost/type_traits/is_lvalue_reference.hpp>
# include <boost/type_traits/is_function.hpp>
# include <boost/config.hpp>

# if defined(BOOST_NO_CXX11_HDR_FUNCTIONAL)
# include <boost/function.hpp>
# else
# include <functional>
# endif

namespace boost { namespace parameter {

Expand All @@ -25,7 +34,7 @@ namespace aux
template <class T>
struct is_template_keyword
: mpl::and_<
mpl::not_<is_reference<T> >
mpl::not_<is_lvalue_reference<T> >
, is_pointer_convertible<T, template_keyword_tag>
>
{};
Expand All @@ -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<T>
#if defined(BOOST_NO_CXX11_HDR_FUNCTIONAL)
, ::boost::function<T>
#else
, ::std::function<T>
#endif
, T
>::type value_type;

typedef value_type reference;
};

Expand Down
1 change: 1 addition & 0 deletions test/Jamfile.v2
Original file line number Diff line number Diff line change
Expand Up @@ -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 : : : : : <variant>release ]
Expand Down
70 changes: 70 additions & 0 deletions test/function_type_tpl_param.cpp
Original file line number Diff line number Diff line change
@@ -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 <boost/parameter/name.hpp>
#include <boost/parameter/parameters.hpp>
#include <boost/parameter/value_type.hpp>
#include <boost/parameter/config.hpp>
#include <boost/mpl/bool.hpp>
#include <boost/mpl/if.hpp>
#include <boost/type_traits/is_same.hpp>

#if defined(BOOST_NO_CXX11_HDR_FUNCTIONAL)
#include <boost/function.hpp>
#else
#include <functional>
#endif

namespace test {
namespace keywords {

BOOST_PARAMETER_TEMPLATE_KEYWORD(function_type)
} // namespace keywords

template <typename K, typename A>
struct X
: boost::parameter::value_type<
typename boost::parameter::parameters<
boost::parameter::required<K>
>::BOOST_NESTED_TEMPLATE bind<
A
>::type
, K
>
{
};

template <typename T>
struct Y
: boost::mpl::if_<
boost::is_same<
#if defined(BOOST_NO_CXX11_HDR_FUNCTIONAL)
boost::function<T>
#else
std::function<T>
#endif
, typename X<
test::keywords::tag::function_type
, test::keywords::function_type<T>
>::type
>
, boost::mpl::true_
, boost::mpl::false_
>::type
{
};
} // namespace test

#include <boost/mpl/assert.hpp>
#include <boost/mpl/aux_/test.hpp>

MPL_TEST_CASE()
{
BOOST_MPL_ASSERT((test::Y<void()>));
BOOST_MPL_ASSERT_NOT((test::Y<int>));
BOOST_MPL_ASSERT((test::Y<double(double)>));
}

0 comments on commit fb88905

Please sign in to comment.