You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

52 line
1.4 KiB

  1. #pragma once
  2. #include <cppargs/group/simple_group.h>
  3. namespace cppargs
  4. {
  5. template<typename T_arg>
  6. struct simple_verify_and_forward
  7. {
  8. template<typename T, typename T_enable = void>
  9. struct check
  10. {
  11. template<typename X>
  12. constexpr X&& operator()(X&& x) const
  13. { static_assert(sizeof(X) == -1, "invalid group or option type"); }
  14. };
  15. template<typename T>
  16. struct check<
  17. std::unique_ptr<T>,
  18. utl::mp::enable_if<utl::mp::is_base_of<simple_group, T>>>
  19. {
  20. template<typename X>
  21. constexpr X&& operator()(X&& x) const
  22. { return std::forward<X>(x); }
  23. };
  24. template<typename T>
  25. struct check<
  26. std::unique_ptr<T>,
  27. utl::mp::enable_if<utl::mp::is_base_of<simple_option, T>>>
  28. {
  29. template<typename X>
  30. constexpr X&& operator()(X&& x) const
  31. { return std::forward<X>(x); }
  32. };
  33. template<typename X>
  34. constexpr decltype(auto) operator()(X&& x) const
  35. { return check<T_arg> { } (std::forward<X>(x)); }
  36. };
  37. template<typename... T_args>
  38. simple_group::simple_group(
  39. const group_meta& p_meta,
  40. T_args&&... p_args)
  41. : group(p_meta, simple_verify_and_forward<T_args> { } (std::forward<T_args>(p_args))...)
  42. { }
  43. }