arg_router  1.4.0
C++ command line argument parsing and routing
forwarding_arg.hpp
1 // Copyright (C) 2023 by Camden Mannett.
2 // Distributed under the Boost Software License, Version 1.0.
3 // (See accompanying file LICENSE or copy at https://www.boost.org/LICENSE_1_0.txt)
4 
5 #pragma once
6 
7 #include "arg_router/multi_arg_base.hpp"
8 #include "arg_router/policy/description.hpp"
9 #include "arg_router/policy/none_name.hpp"
10 #include "arg_router/utility/string_to_policy.hpp"
11 
12 namespace arg_router
13 {
24 template <typename... Policies>
26  public multi_arg_base_t<vector<std::string_view>, 0, std::decay_t<Policies>...>
27 {
28  using parent_type = multi_arg_base_t<vector<std::string_view>, 0, std::decay_t<Policies>...>;
29 
30  static_assert(!traits::has_display_name_method_v<forwarding_arg_t> &&
31  !traits::has_long_name_method_v<forwarding_arg_t> &&
32  !traits::has_short_name_method_v<forwarding_arg_t>,
33  "Forwarding arg can only have a none name policy");
34 
35 public:
36  using typename parent_type::policies_type;
37 
40 
42  template <bool Flatten>
44  {
45  public:
46  using label = std::decay_t<decltype(
47  parent_type::template default_leaf_help_data_type<Flatten>::label_generator() +
48  AR_STRING(" "){} +
49  parent_type::template default_leaf_help_data_type<Flatten>::count_suffix())>;
50  using description =
51  typename parent_type::template default_leaf_help_data_type<Flatten>::description;
52  using children = std::tuple<>;
53  };
54 
59  constexpr explicit forwarding_arg_t(Policies... policies) noexcept :
60  parent_type{std::move(policies)...}
61  {
62  }
63 
64  template <typename Validator, bool HasTarget, typename... Parents>
65  [[nodiscard]] std::optional<parsing::parse_target> pre_parse(
66  parsing::pre_parse_data<Validator, HasTarget> pre_parse_data,
67  const Parents&... parents) const
68 
69  {
70  return parent_type::pre_parse(pre_parse_data, *this, parents...);
71  }
72 
73  template <typename... Parents>
74  value_type parse(parsing::parse_target&& target, const Parents&... parents) const
75  {
76  return parent_type::parse(target, *this, parents...);
77  }
78 
79 private:
80  static_assert(!parent_type::template any_phases_v<value_type, policy::has_routing_phase_method>,
81  "Forwarding arg does not support policies with routing phases "
82  "(e.g. router)");
83 };
84 
99 template <typename... Policies>
100 [[nodiscard]] constexpr auto forwarding_arg(Policies... policies) noexcept
101 {
102  return std::apply(
103  [](auto... converted_policies) {
104  return forwarding_arg_t<std::decay_t<decltype(converted_policies)>...>{
105  std::move(converted_policies)...};
106  },
110  std::move(policies)...));
111 }
112 } // namespace arg_router
typename parent_type::value_type value_type
constexpr forwarding_arg_t(Policies... policies) noexcept
value_type parse(parsing::parse_target target, const Parents &... parents) const
constexpr auto convert(Params &&... params) noexcept
constexpr auto forwarding_arg(Policies... policies) noexcept