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