parameter-enabled-constructors0.cpp 816 B

123456789101112131415161718192021222324252627282930313233343536
  1. #include <boost/parameter.hpp>
  2. #include <iostream>
  3. BOOST_PARAMETER_NAME(name)
  4. BOOST_PARAMETER_NAME(index)
  5. struct myclass_impl
  6. {
  7. template <typename ArgumentPack>
  8. myclass_impl(ArgumentPack const& args)
  9. {
  10. std::cout << "name = " << args[_name];
  11. std::cout << "; index = " << args[_index | 42];
  12. std::cout << std::endl;
  13. }
  14. };
  15. struct myclass : myclass_impl
  16. {
  17. BOOST_PARAMETER_CONSTRUCTOR(
  18. myclass, (myclass_impl), tag
  19. , (required (name,*)) (optional (index,*))
  20. ) // no semicolon
  21. };
  22. #include <boost/core/lightweight_test.hpp>
  23. int main()
  24. {
  25. myclass x("bob", 3); // positional
  26. myclass y(_index = 12, _name = "sally"); // named
  27. myclass z("june"); // positional/defaulted
  28. return boost::report_errors();
  29. }