maybe.cpp 1001 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. // Copyright Daniel Wallin 2006.
  2. // Distributed under the Boost Software License, Version 1.0.
  3. // (See accompanying file LICENSE_1_0.txt or copy at
  4. // http://www.boost.org/LICENSE_1_0.txt)
  5. #include <boost/parameter/name.hpp>
  6. namespace test {
  7. BOOST_PARAMETER_NAME(kw)
  8. BOOST_PARAMETER_NAME(unused)
  9. template <typename Args>
  10. int f(Args const& args)
  11. {
  12. return args[test::_kw | 1.f];
  13. }
  14. } // namespace test
  15. #include <boost/parameter/aux_/maybe.hpp>
  16. #include <boost/core/lightweight_test.hpp>
  17. int main()
  18. {
  19. BOOST_TEST_EQ(0, test::f((test::_kw = 0, test::_unused = 0)));
  20. BOOST_TEST_EQ(1, test::f(test::_unused = 0));
  21. BOOST_TEST_EQ(
  22. 1
  23. , test::f((
  24. test::_kw = boost::parameter::aux::maybe<int>()
  25. , test::_unused = 0
  26. ))
  27. );
  28. BOOST_TEST_EQ(
  29. 2
  30. , test::f((
  31. test::_kw = boost::parameter::aux::maybe<int>(2)
  32. , test::_unused = 0
  33. ))
  34. );
  35. return boost::report_errors();
  36. }