diff --git a/test/preprocessor.cpp b/test/preprocessor.cpp index c0f8018..3ca752c 100755 --- a/test/preprocessor.cpp +++ b/test/preprocessor.cpp @@ -14,7 +14,7 @@ namespace test { -BOOST_PARAMETER_FUNCTION((int), f, tag, +BOOST_PARAMETER_BASIC_FUNCTION((int), f, tag, (required (tester, *) (name, *) @@ -40,7 +40,7 @@ BOOST_PARAMETER_FUNCTION((int), f, tag, return 1; } -BOOST_PARAMETER_FUNCTION((int), g, tag, +BOOST_PARAMETER_BASIC_FUNCTION((int), g, tag, (required (tester, *) (name, *) @@ -66,6 +66,52 @@ BOOST_PARAMETER_FUNCTION((int), g, tag, return 1; } +BOOST_PARAMETER_FUNCTION((int), h, tag, + (required + (tester, *) + (name, *) + ) + (optional + (value, *, 1.f) + (out(index), (int), 2) + ) +) +{ + BOOST_MPL_ASSERT((boost::is_same)); + + tester( + name + , value + , index + ); + + return 1; +} + +BOOST_PARAMETER_FUNCTION((int), h2, tag, + (required + (tester, *) + (name, *) + ) + (optional + (value, *, 1.f) + (out(index), (int), (int)value * 2) + ) +) +{ +# if !BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x564)) + BOOST_MPL_ASSERT((boost::is_same)); +# endif + + tester( + name + , value + , index + ); + + return 1; +} + struct base { template @@ -92,7 +138,7 @@ struct class_ : base ) ) - BOOST_PARAMETER_MEMBER_FUNCTION((int), f, tag, + BOOST_PARAMETER_BASIC_MEMBER_FUNCTION((int), f, tag, (required (tester, *) (name, *) @@ -112,7 +158,7 @@ struct class_ : base return 1; } - BOOST_PARAMETER_CONST_MEMBER_FUNCTION((int), f, tag, + BOOST_PARAMETER_BASIC_CONST_MEMBER_FUNCTION((int), f, tag, (required (tester, *) (name, *) @@ -131,6 +177,52 @@ struct class_ : base return 1; } + + BOOST_PARAMETER_MEMBER_FUNCTION((int), f2, tag, + (required + (tester, *) + (name, *) + ) + (optional + (value, *, 1.f) + (index, *, 2) + ) + ) + { + tester(name, value, index); + return 1; + } + + BOOST_PARAMETER_CONST_MEMBER_FUNCTION((int), f2, tag, + (required + (tester, *) + (name, *) + ) + (optional + (value, *, 1.f) + (index, *, 2) + ) + ) + { + tester(name, value, index); + return 1; + } + + + BOOST_PARAMETER_MEMBER_FUNCTION((int), static f_static, tag, + (required + (tester, *) + (name, *) + ) + (optional + (value, *, 1.f) + (index, *, 2) + ) + ) + { + tester(name, value, index); + return 1; + } }; BOOST_PARAMETER_FUNCTION( @@ -158,6 +250,31 @@ sfinae(A0 const& a0) } #endif +BOOST_PARAMETER_FUNCTION( + (int), sfinae1, tag, + (required + (name, *(boost::is_convertible)) + ) +) +{ + return 1; +} + +#ifndef BOOST_NO_SFINAE +// On compilers that actually support SFINAE, add another overload +// that is an equally good match and can only be in the overload set +// when the others are not. This tests that the SFINAE is actually +// working. On all other compilers we're just checking that +// everything about SFINAE-enabled code will work, except of course +// the SFINAE. +template +typename boost::enable_if, int>::type +sfinae1(A0 const& a0) +{ + return 0; +} +#endif + } int main() @@ -190,6 +307,19 @@ int main() , 2 ); + h( + tester = values(S("foo"), 1.f, 2) + , name = S("foo") + , 1.f + , 2 + ); + + h2( + tester = values(S("foo"), 1.f, 2) + , name = S("foo") + , 1.f + ); + class_ x( tester = values(S("foo"), 1.f, 2) , S("foo"), test::index = 2 @@ -205,6 +335,16 @@ int main() , name = S("foo") ); + x.f2( + tester = values(S("foo"), 1.f, 2) + , S("foo") + ); + + x.f2( + tester = values(S("foo"), 1.f, 2) + , name = S("foo") + ); + class_ const& x_const = x; x_const.f( @@ -216,10 +356,39 @@ int main() tester = values(S("foo"), 1.f, 2) , name = S("foo") ); - + + x_const.f2( + tester = values(S("foo"), 1.f, 2) + , S("foo") + ); + + x_const.f2( + tester = values(S("foo"), 1.f, 2) + , name = S("foo") + ); + + x_const.f2( + tester = values(S("foo"), 1.f, 2) + , name = S("foo") + ); + + class_::f_static( + tester = values(S("foo"), 1.f, 2) + , S("foo") + ); + + class_::f_static( + tester = values(S("foo"), 1.f, 2) + , name = S("foo") + ); + #ifndef BOOST_NO_SFINAE assert(sfinae("foo") == 1); assert(sfinae(1) == 0); + + assert(sfinae1("foo") == 1); + assert(sfinae1(1) == 0); #endif + return 0; } diff --git a/test/python.cpp b/test/python.cpp index 3d9b5b1..584469d 100755 --- a/test/python.cpp +++ b/test/python.cpp @@ -6,6 +6,7 @@ #include #include #include +#include namespace test { @@ -13,9 +14,32 @@ BOOST_PARAMETER_KEYWORD(tag, x) BOOST_PARAMETER_KEYWORD(tag, y) BOOST_PARAMETER_KEYWORD(tag, z) -struct X +struct Xbase { - BOOST_PARAMETER_MEMBER_FUNCTION((int), f, tag, + // We need the disable_if part for VC7.1/8.0. + template + Xbase( + Args const& args + , typename boost::disable_if< + boost::is_base_and_derived + >::type* = 0 + ) + : value(std::string(args[x | "foo"]) + args[y | "bar"]) + {} + + std::string value; +}; + +struct X : Xbase +{ + BOOST_PARAMETER_CONSTRUCTOR(X, (Xbase), tag, + (optional + (x, *) + (y, *) + ) + ) + + BOOST_PARAMETER_BASIC_MEMBER_FUNCTION((int), f, tag, (required (x, *) (y, *) @@ -28,7 +52,7 @@ struct X return args[x] + args[y] + args[z | 0]; } - BOOST_PARAMETER_MEMBER_FUNCTION((std::string), g, tag, + BOOST_PARAMETER_BASIC_MEMBER_FUNCTION((std::string), g, tag, (optional (x, *) (y, *) @@ -37,6 +61,19 @@ struct X { return std::string(args[x | "foo"]) + args[y | "bar"]; } + + BOOST_PARAMETER_MEMBER_FUNCTION((X&), h, tag, + (optional (x, *, "") (y, *, "")) + ) + { + return *this; + } + + template + X& operator()(A0 const& a0) + { + return *this; + } }; } // namespace test @@ -59,6 +96,15 @@ struct g_fwd } }; +struct h_fwd +{ + template + R operator()(boost::type, T& self, A0 const& a0, A1 const& a1) + { + return self.h(a0,a1); + } +}; + BOOST_PYTHON_MODULE(python_parameter) { namespace mpl = boost::mpl; @@ -66,21 +112,48 @@ BOOST_PYTHON_MODULE(python_parameter) using namespace boost::python; class_("X") + .def( + boost::parameter::python::init< + mpl::vector< + tag::x*(std::string), tag::y*(std::string) + > + >() + ) .def( "f" , boost::parameter::python::function< f_fwd - , mpl::vector3 - , mpl::vector4 + , mpl::vector< + int, tag::x(int), tag::y(int), tag::z*(int) + > >() ) .def( "g" , boost::parameter::python::function< g_fwd - , mpl::vector2 - , mpl::vector3 + , mpl::vector< + std::string, tag::x*(std::string), tag::y*(std::string) + > >() - ); + ) + .def( + "h" + , boost::parameter::python::function< + h_fwd + , mpl::vector< + X&, tag::x*(std::string), tag::y*(std::string) + > + >() + , return_arg<>() + ) + .def( + boost::parameter::python::call< + mpl::vector< + X&, tag::x(int) + > + >() [ return_arg<>() ] + ) + .def_readonly("value", &X::value); } diff --git a/test/python.py b/test/python.py index cd5540c..8bd2a56 100644 --- a/test/python.py +++ b/test/python.py @@ -1,6 +1,8 @@ ''' >>> from python_parameter import X ->>> x = X() +>>> x = X(y = 'baz') +>>> x.value +'foobaz' >>> x.f(1,2) 3 >>> x.f(1,2,3) @@ -17,6 +19,10 @@ 'bazbar' >>> x.g(y = "foo", x = "bar") 'barfoo' +>>> y = x.h(x = "bar", y = "foo") +>>> assert x == y +>>> y = x(0) +>>> assert x == y ''' def run(args = None):