You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: book/chapters/options.md
+6-6Lines changed: 6 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -165,15 +165,15 @@ Windows style options do not allow combining short options or values not separat
165
165
166
166
## Parse configuration
167
167
168
-
How an option and its arguments are parsed depends on a set of controls that are part of the option structure. In most circumstances these controls are set automatically based on the function used to create the option and the type the arguments are parsed into. The variables define the size of the underlying type (essentially how many strings make up the type), the expected size (how many groups are expected) and a flag indicating if multiple groups are allowed with a single option. And these interact with the `multi_option_policy` when it comes time to parse.
168
+
How an option and its arguments are parsed depends on a set of controls that are part of the option structure. In most circumstances these controls are set automatically based on the function used to create the option and the type the arguments are parsed into. The variables define the size of the underlying type (essentially how many strings make up the type), the expected size (how many groups are expected) and a flag indicating if multiple groups are allowed with a single option. And these interact with the `multi_option_policy` when it comes time to parse.
169
169
170
170
### examples
171
171
How options manage this is best illustrated through some examples
172
172
```cpp
173
173
std::string val;
174
174
app.add_option("--opt",val,"description");
175
175
```
176
-
creates an option that assigns a value to a `std::string` When this option is constructed it sets a type_size of 1. meaning that the assignment uses a single string. The Expected size is also set to 1 by default, and `allow_extra_args` is set to false. meaning that each time this option is called 1 argument is expected. This would also be the case if val were a `double`, `int` or any other single argument types.
176
+
creates an option that assigns a value to a `std::string` When this option is constructed it sets a type_size of 1. meaning that the assignment uses a single string. The Expected size is also set to 1 by default, and `allow_extra_args` is set to false. meaning that each time this option is called 1 argument is expected. This would also be the case if val were a `double`, `int` or any other single argument types.
177
177
178
178
now for example
179
179
```cpp
@@ -188,20 +188,20 @@ std::vector<int> val;
188
188
app.add_option("--opt",val,"description");
189
189
```
190
190
191
-
detects a type size of 1, since the underlying element type is a single string, so the minimum number of strings is 1. But since it is a vector the expected number can be very big. The default for a vector is (1<<30), and the allow_extra_args is set to true. This means that at least 1 argument is expected to follow the option, but arbitrary numbers of arguments may follow. These are checked if they have the form of an option but if not they are added to the argument.
191
+
detects a type size of 1, since the underlying element type is a single string, so the minimum number of strings is 1. But since it is a vector the expected number can be very big. The default for a vector is (1<<30), and the allow_extra_args is set to true. This means that at least 1 argument is expected to follow the option, but arbitrary numbers of arguments may follow. These are checked if they have the form of an option but if not they are added to the argument.
gets into the complicated cases where the type size is now 3. and the expected max is set to a large number and `allow_extra_args` is set to true. In this case at least 3 arguments are required to follow the option, and subsequent groups must come in groups of three, otherwise an error will result.
197
+
gets into the complicated cases where the type size is now 3. and the expected max is set to a large number and `allow_extra_args` is set to true. In this case at least 3 arguments are required to follow the option, and subsequent groups must come in groups of three, otherwise an error will result.
198
198
199
199
```cpp
200
200
bool val;
201
201
app.add_flag("--opt",val,"description");
202
202
```
203
203
204
-
Using the add_flag methods for creating options creates an option with an expected size of 0, implying no arguments can be passed.
204
+
Using the add_flag methods for creating options creates an option with an expected size of 0, implying no arguments can be passed.
205
205
206
206
### Customization
207
207
@@ -212,7 +212,7 @@ std::string val;
212
212
auto opt=app.add_flag("--opt{vvv}",val,"description");
213
213
opt->expected(0,1);
214
214
```
215
-
will create a hybrid option, that can exist on its own in which case the value "vvv" is used or if a value is given that value will be used.
215
+
will create a hybrid option, that can exist on its own in which case the value "vvv" is used or if a value is given that value will be used.
216
216
217
217
[^1]: For example, enums are not printable to `std::cout`.
218
218
[^2]: There is a small difference. An combined unlimited option will not prioritize over a positional that could still accept values.
0 commit comments