Skip to content

Commit fb88905

Browse files
committed
Upgrade BOOST_PARAMETER_TEMPLATE_KEYWORD
Keyword templates generated by BOOST_PARAMETER_TEMPLATE_KEYWORD can now accept function types.
1 parent 5d3e393 commit fb88905

File tree

3 files changed

+95
-3
lines changed

3 files changed

+95
-3
lines changed

include/boost/parameter/aux_/template_keyword.hpp

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,17 @@
77

88
# include <boost/mpl/and.hpp>
99
# include <boost/mpl/not.hpp>
10+
# include <boost/mpl/if.hpp>
1011
# include <boost/type_traits/is_convertible.hpp>
11-
# include <boost/type_traits/is_reference.hpp>
12+
# include <boost/type_traits/is_lvalue_reference.hpp>
13+
# include <boost/type_traits/is_function.hpp>
14+
# include <boost/config.hpp>
15+
16+
# if defined(BOOST_NO_CXX11_HDR_FUNCTIONAL)
17+
# include <boost/function.hpp>
18+
# else
19+
# include <functional>
20+
# endif
1221

1322
namespace boost { namespace parameter {
1423

@@ -25,7 +34,7 @@ namespace aux
2534
template <class T>
2635
struct is_template_keyword
2736
: mpl::and_<
28-
mpl::not_<is_reference<T> >
37+
mpl::not_<is_lvalue_reference<T> >
2938
, is_pointer_convertible<T, template_keyword_tag>
3039
>
3140
{};
@@ -37,7 +46,19 @@ struct template_keyword
3746
: aux::template_keyword_tag
3847
{
3948
typedef Tag key_type;
40-
typedef T value_type;
49+
50+
// Wrap plain (non-UDT) function objects in either
51+
// a boost::function or a std::function. -- Cromwell D. Enage
52+
typedef typename ::boost::mpl::if_<
53+
::boost::is_function<T>
54+
#if defined(BOOST_NO_CXX11_HDR_FUNCTIONAL)
55+
, ::boost::function<T>
56+
#else
57+
, ::std::function<T>
58+
#endif
59+
, T
60+
>::type value_type;
61+
4162
typedef value_type reference;
4263
};
4364

test/Jamfile.v2

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ test-suite "parameter"
2020
[ run tutorial.cpp ]
2121
[ run singular.cpp ]
2222
[ run mpl.cpp ]
23+
[ run function_type_tpl_param.cpp ]
2324
[ run preprocessor.cpp ]
2425
[ run preprocessor_deduced.cpp ]
2526
[ run efficiency.cpp : : : : : <variant>release ]

test/function_type_tpl_param.cpp

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
// Copyright Frank Mori Hess 2009.
2+
// Copyright Cromwell D. Enage 2017.
3+
// Distributed under the Boost Software License, Version 1.0.
4+
// (See accompanying file LICENSE_1_0.txt or copy at
5+
// http://www.boost.org/LICENSE_1_0.txt)
6+
7+
#include <boost/parameter/name.hpp>
8+
#include <boost/parameter/parameters.hpp>
9+
#include <boost/parameter/value_type.hpp>
10+
#include <boost/parameter/config.hpp>
11+
#include <boost/mpl/bool.hpp>
12+
#include <boost/mpl/if.hpp>
13+
#include <boost/type_traits/is_same.hpp>
14+
15+
#if defined(BOOST_NO_CXX11_HDR_FUNCTIONAL)
16+
#include <boost/function.hpp>
17+
#else
18+
#include <functional>
19+
#endif
20+
21+
namespace test {
22+
namespace keywords {
23+
24+
BOOST_PARAMETER_TEMPLATE_KEYWORD(function_type)
25+
} // namespace keywords
26+
27+
template <typename K, typename A>
28+
struct X
29+
: boost::parameter::value_type<
30+
typename boost::parameter::parameters<
31+
boost::parameter::required<K>
32+
>::BOOST_NESTED_TEMPLATE bind<
33+
A
34+
>::type
35+
, K
36+
>
37+
{
38+
};
39+
40+
template <typename T>
41+
struct Y
42+
: boost::mpl::if_<
43+
boost::is_same<
44+
#if defined(BOOST_NO_CXX11_HDR_FUNCTIONAL)
45+
boost::function<T>
46+
#else
47+
std::function<T>
48+
#endif
49+
, typename X<
50+
test::keywords::tag::function_type
51+
, test::keywords::function_type<T>
52+
>::type
53+
>
54+
, boost::mpl::true_
55+
, boost::mpl::false_
56+
>::type
57+
{
58+
};
59+
} // namespace test
60+
61+
#include <boost/mpl/assert.hpp>
62+
#include <boost/mpl/aux_/test.hpp>
63+
64+
MPL_TEST_CASE()
65+
{
66+
BOOST_MPL_ASSERT((test::Y<void()>));
67+
BOOST_MPL_ASSERT_NOT((test::Y<int>));
68+
BOOST_MPL_ASSERT((test::Y<double(double)>));
69+
}
70+

0 commit comments

Comments
 (0)