@@ -142,10 +142,10 @@ class argument_parser {
142142 * \todo Check forbidden characters (after adding the assignment character).
143143 */
144144 template <detail::c_argument_value_type T = std::string>
145- argument::positional<T>& add_positional_argument (std::string_view primary_name) {
145+ argument::positional<T>& add_positional_argument (const std::string_view primary_name) {
146146 this ->_verify_arg_name_pattern (primary_name);
147147
148- const detail::argument_name arg_name (primary_name);
148+ const detail::argument_name arg_name (std::make_optional<std::string>( primary_name) );
149149 if (this ->_is_arg_name_used (arg_name))
150150 throw invalid_configuration::argument_name_used (arg_name);
151151
@@ -165,12 +165,15 @@ class argument_parser {
165165 */
166166 template <detail::c_argument_value_type T = std::string>
167167 argument::positional<T>& add_positional_argument (
168- std::string_view primary_name, std::string_view secondary_name
168+ const std::string_view primary_name, const std::string_view secondary_name
169169 ) {
170170 this ->_verify_arg_name_pattern (primary_name);
171171 this ->_verify_arg_name_pattern (secondary_name);
172172
173- const detail::argument_name arg_name (primary_name, secondary_name);
173+ const detail::argument_name arg_name{
174+ std::make_optional<std::string>(primary_name),
175+ std::make_optional<std::string>(secondary_name)
176+ };
174177 if (this ->_is_arg_name_used (arg_name))
175178 throw invalid_configuration::argument_name_used (arg_name);
176179
@@ -181,17 +184,27 @@ class argument_parser {
181184 /* *
182185 * @brief Adds a positional argument to the parser's configuration.
183186 * @tparam T Type of the argument value.
184- * @param primary_name The primary name of the argument.
187+ * @param name The name of the argument.
188+ * @param name_discr The discriminator value specifying whether the given name should be treated as primary or secondary.
185189 * @return Reference to the added optional argument.
186190 * @throws ap::invalid_configuration
187191 *
188192 * \todo Check forbidden characters (after adding the assignment character).
189193 */
190194 template <detail::c_argument_value_type T = std::string>
191- argument::optional<T>& add_optional_argument (std::string_view primary_name) {
192- this ->_verify_arg_name_pattern (primary_name);
193-
194- const detail::argument_name arg_name (primary_name, std::nullopt , this ->_flag_prefix_char );
195+ argument::optional<T>& add_optional_argument (
196+ const std::string_view name,
197+ const detail::argument_name_discriminator name_discr = n_primary
198+ ) {
199+ this ->_verify_arg_name_pattern (name);
200+
201+ const auto arg_name =
202+ name_discr == n_primary
203+ ? detail::
204+ argument_name{std::make_optional<std::string>(name), std::nullopt , this ->_flag_prefix_char }
205+ : detail::argument_name{
206+ std::nullopt , std::make_optional<std::string>(name), this ->_flag_prefix_char
207+ };
195208 if (this ->_is_arg_name_used (arg_name))
196209 throw invalid_configuration::argument_name_used (arg_name);
197210
@@ -211,12 +224,16 @@ class argument_parser {
211224 */
212225 template <detail::c_argument_value_type T = std::string>
213226 argument::optional<T>& add_optional_argument (
214- std::string_view primary_name, std::string_view secondary_name
227+ const std::string_view primary_name, const std::string_view secondary_name
215228 ) {
216229 this ->_verify_arg_name_pattern (primary_name);
217230 this ->_verify_arg_name_pattern (secondary_name);
218231
219- const detail::argument_name arg_name (primary_name, secondary_name, this ->_flag_prefix_char );
232+ const detail::argument_name arg_name (
233+ std::make_optional<std::string>(primary_name),
234+ std::make_optional<std::string>(secondary_name),
235+ this ->_flag_prefix_char
236+ );
220237 if (this ->_is_arg_name_used (arg_name))
221238 throw invalid_configuration::argument_name_used (arg_name);
222239
@@ -227,12 +244,16 @@ class argument_parser {
227244 /* *
228245 * @brief Adds a boolean flag argument (an optional argument with `value_type = bool`) to the parser's configuration.
229246 * @tparam StoreImplicitly A boolean value used as the `implicit_value` parameter of the argument.
230- * @param primary_name The primary name of the flag.
247+ * @param name The primary name of the flag.
248+ * @param name_discr The discriminator value specifying whether the given name should be treated as primary or secondary.
231249 * @return Reference to the added boolean flag argument.
232250 */
233251 template <bool StoreImplicitly = true >
234- argument::optional<bool >& add_flag (std::string_view primary_name) {
235- return this ->add_optional_argument <bool >(primary_name)
252+ argument::optional<bool >& add_flag (
253+ const std::string_view name,
254+ const detail::argument_name_discriminator name_discr = n_primary
255+ ) {
256+ return this ->add_optional_argument <bool >(name, name_discr)
236257 .default_value (not StoreImplicitly)
237258 .implicit_value (StoreImplicitly)
238259 .nargs (0ull );
@@ -247,7 +268,7 @@ class argument_parser {
247268 */
248269 template <bool StoreImplicitly = true >
249270 argument::optional<bool >& add_flag (
250- std::string_view primary_name, std::string_view secondary_name
271+ const std::string_view primary_name, const std::string_view secondary_name
251272 ) {
252273 return this ->add_optional_argument <bool >(primary_name, secondary_name)
253274 .default_value (not StoreImplicitly)
0 commit comments