lazy-default-computation1.cpp 824 B

12345678910111213141516171819202122232425262728293031323334353637
  1. #include <boost/bind.hpp>
  2. #include <boost/ref.hpp>
  3. #include <boost/parameter.hpp>
  4. #include <string>
  5. #include <functional>
  6. BOOST_PARAMETER_NAME(s1)
  7. BOOST_PARAMETER_NAME(s2)
  8. BOOST_PARAMETER_NAME(s3)
  9. template <typename ArgumentPack>
  10. std::string f(ArgumentPack const& args)
  11. {
  12. std::string const& s1 = args[_s1];
  13. std::string const& s2 = args[_s2];
  14. typename boost::parameter::binding<
  15. ArgumentPack, tag::s3, std::string
  16. >::type s3 = args[
  17. _s3 || boost::bind(
  18. std::plus<std::string>()
  19. , boost::ref(s1)
  20. , boost::ref(s2)
  21. )
  22. ];
  23. return s3;
  24. }
  25. #include <boost/core/lightweight_test.hpp>
  26. int main()
  27. {
  28. std::string x = f((_s1="hello,", _s2=" world", _s3="hi world"));
  29. BOOST_TEST_EQ(x, std::string("hi world"));
  30. return boost::report_errors();
  31. }