lazy-default-computation0.cpp 653 B

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