extracting-parameter-types0.cpp 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. #include <boost/parameter.hpp>
  2. BOOST_PARAMETER_NAME(name)
  3. BOOST_PARAMETER_NAME(index)
  4. template <typename T>
  5. #if defined(BOOST_PARAMETER_HAS_PERFECT_FORWARDING)
  6. void noop(T&&)
  7. #else
  8. void noop(T&)
  9. #endif
  10. {
  11. }
  12. #if defined(BOOST_PARAMETER_HAS_PERFECT_FORWARDING)
  13. #include <utility>
  14. #endif
  15. template <typename Name, typename Index>
  16. #if defined(BOOST_PARAMETER_HAS_PERFECT_FORWARDING)
  17. int deduce_arg_types_impl(Name&& name, Index&& index)
  18. {
  19. noop(std::forward<Name>(name));
  20. noop(std::forward<Index>(index));
  21. return index;
  22. }
  23. #else
  24. int deduce_arg_types_impl(Name& name, Index& index)
  25. {
  26. Name& n2 = name; // we know the types
  27. Index& i2 = index;
  28. noop(n2);
  29. noop(i2);
  30. return index;
  31. }
  32. #endif
  33. template <typename ArgumentPack>
  34. int deduce_arg_types(ArgumentPack const& args)
  35. {
  36. return deduce_arg_types_impl(args[_name], args[_index|42]);
  37. }
  38. #include <boost/core/lightweight_test.hpp>
  39. int main()
  40. {
  41. int a1 = deduce_arg_types((_name = "foo"));
  42. int a2 = deduce_arg_types((_name = "foo", _index = 3));
  43. BOOST_TEST_EQ(a1, 42);
  44. BOOST_TEST_EQ(a2, 3);
  45. return boost::report_errors();
  46. }