diff --git a/test/deduced.hpp b/test/deduced.hpp new file mode 100755 index 0000000..3e79996 --- /dev/null +++ b/test/deduced.hpp @@ -0,0 +1,77 @@ +// Copyright Daniel Wallin 2006. Use, modification and distribution is +// subject to 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) + +#ifndef BOOST_DEDUCED_060920_HPP +# define BOOST_DEDUCED_060920_HPP + +# include +# include "basics.hpp" + +struct not_present_tag {}; +not_present_tag not_present; + +template +struct assert_expected +{ + assert_expected(E const& e, ArgPack const& args) + : expected(e) + , args(args) + {} + + template + bool check_not_present(T const&) const + { + BOOST_MPL_ASSERT((boost::is_same)); + return true; + } + + template + bool check(K const& k, not_present_tag const&, long) const + { + return check_not_present(args[k | not_present]); + } + + template + bool check(K const& k, Expected const& expected, int) const + { + return test::equal(args[k], expected); + } + + template + void operator()(K) const + { + boost::parameter::keyword const& k = boost::parameter::keyword::get(); + assert(check(k, expected[k], 0L)); + } + + E const& expected; + ArgPack const& args; +}; + +template +void check0(E const& e, ArgPack const& args) +{ + boost::mpl::for_each(assert_expected(e, args)); +} + +template +void check(E const& e, A0 const& a0) +{ + check0(e, P()(a0)); +} + +template +void check(E const& e, A0 const& a0, A1 const& a1) +{ + check0(e, P()(a0,a1)); +} + +template +void check(E const& e, A0 const& a0, A1 const& a1, A2 const& a2) +{ + check0(e, P()(a0,a1,a2)); +} + +#endif // BOOST_DEDUCED_060920_HPP + diff --git a/test/deduced_dependent_predicate.cpp b/test/deduced_dependent_predicate.cpp new file mode 100755 index 0000000..c080b84 --- /dev/null +++ b/test/deduced_dependent_predicate.cpp @@ -0,0 +1,60 @@ +// Copyright Daniel Wallin 2006. Use, modification and distribution is +// subject to 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 "deduced.hpp" + +namespace parameter = boost::parameter; +namespace mpl = boost::mpl; + +BOOST_PARAMETER_NAME(x) +BOOST_PARAMETER_NAME(y) +BOOST_PARAMETER_NAME(z) + +int main() +{ + using namespace parameter; + using boost::is_same; + using boost::add_reference; + + check< + parameters< + tag::x + , optional< + deduced + , is_same< + add_reference + , binding + > + > + > + >( + (_x = 0, _y = 1) + , 0 + , 1 + ); + + check< + parameters< + tag::x + , optional< + deduced + , is_same< + add_reference + , binding + > + > + > + >( + (_x = 0U, _y = 1U) + , 0U + , 1U + ); + + return 0; +} + diff --git a/test/optional_deduced_sfinae.cpp b/test/optional_deduced_sfinae.cpp new file mode 100755 index 0000000..0ef31f7 --- /dev/null +++ b/test/optional_deduced_sfinae.cpp @@ -0,0 +1,50 @@ +// Copyright Daniel Wallin 2006. Use, modification and distribution is +// subject to 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 "basics.hpp" +#include + +namespace test { + +namespace mpl = boost::mpl; + +using mpl::_; +using boost::is_convertible; + +BOOST_PARAMETER_NAME(x) + +BOOST_PARAMETER_FUNCTION((int), sfinae, tag, + (deduced + (optional (x, *(is_convertible<_,char const*>), 0)) + ) +) +{ + return 1; +} + +template +typename boost::enable_if, int>::type +sfinae(A0 const& a0) +{ + return 0; +} + +} // namespace test + +int main() +{ + using namespace test; + + assert(sfinae() == 1); + assert(sfinae("foo") == 1); + assert(sfinae(1) == 0); + + return 0; +} +