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: README.md
+14-14Lines changed: 14 additions & 14 deletions
Original file line number
Diff line number
Diff line change
@@ -55,7 +55,7 @@ Using this sample is only recommended if you are already somewhat familiar with
55
55
- Multiple short options may be grouped; `-alt` is equal to `-a -l -t`. This is only allowed if all options (including the last) don't require an argument.
56
56
-**Long options** (`--version`) consist of two leading hyphens followed by an identifier. The identifier may consist of alphanumeric ([`isalnum`](http://en.cppreference.com/w/cpp/string/byte/isalnum)) characters, hyphens, and underscores but must not start with a hyphen.<sup>1</sup>
57
57
- To pass an **argument** to the option, these syntaxes are allowed: `--optimization=3`, `--optimization 3`
58
-
-**Non-option arguments** (`file.txt`), also referred to as *operands* in POSIX lingo or *positional arguments*, are everything except options.
58
+
-**Non-option arguments** (`file.txt`), also referred to as *operands* in POSIX lingo or *positional arguments*, are everything except options and options' arguments.
59
59
-**Short options**, **long options** and **non-option arguments** can be interleaved at will. Their relative position is retained, i.e. *ProgramOptions.hxx* does not reorder them.
60
60
- A single hyphen `-` is parsed as a **non-option argument**.
61
61
- Two hyphens `--` terminate the option input. Any following arguments are treated as **non-option arguments**, even if they begin with a hyphen.
@@ -73,7 +73,7 @@ Don't forget to compile with C++11 enabled, i.e. with `-std=c++11`.
73
73
Using *ProgramOptions.hxx* is straightforward; we'll explain it by means of practical examples. All examples shown here and more can be found in the [/examples](examples) directory, all of which are well-documented.
74
74
75
75
### Example 1 (`abbreviation`, `u32`, `available`, `get`)
76
-
The following snippet is the complete source code for a simple program expecting an integer optimization level.
76
+
The following snippet is the complete source code of a simple program expecting an integer optimization level.
77
77
```cpp
78
78
#include<ProgramOptions.hxx>
79
79
#include<iostream>
@@ -109,7 +109,7 @@ Let's expand on the previous code. We want it to assume a certain value for the
109
109
110
110
Furthermore, we want to implement the option `-I` to let the user specify include paths. Paths should not be converted to any arithmetic type so we simply set the type to `po::string`.
111
111
112
-
By calling the method `.multi()` we're telling the library to store *all* values, not just the last one. The number of arguments can be retrieved by calling the `.size()` or the `.count()` method. The individual values may be read by means of the iterators returned by `.begin()` and `.end()`. Bear in mind that these iterators point to instances of `po::value`s, so you still need to refer to the member`.string`. One way of avoiding this is to directly use the iterators provided by `.begin<po::string>()` and `.end<po::string>()`. These random-access iterators behave as if they pointed to instances of `std::string`s. For more information, refer to [Example 4](#reading-multi-options).
112
+
By calling the method `.multi()` we're telling the library to store *all* values, not just the last one. The number of arguments can be retrieved by calling the `.size()` or the `.count()` method. The individual values may be read by means of the iterators returned by `.begin()` and `.end()`. Bear in mind that these iterators point to instances of `po::value`s so you still need to refer to the correct member, in this case `.string`. One way of avoiding this is to use the iterators returned by `.begin<po::string>()` and `.end<po::string>()` instead. These [random-access iterators](http://en.cppreference.com/w/cpp/concept/RandomAccessIterator) behave as if they pointed to instances of `std::string`s. For more information, refer to [Example 4](#reading-multi-options).
113
113
114
114
```cpp
115
115
#include <ProgramOptions.hxx>
@@ -134,9 +134,9 @@ int main( int argc, char** argv ) {
// Here, the non-template .begin() / .end() methods were used. Their value type is po::value,
139
+
// Here, the non-template .begin() / .end() methods are being used. Their value type is po::value,
140
140
// which is not a value in itself but contains the desired values as members, i.e. i.string.
141
141
for( auto&& i : I )
142
142
std::cout << '\t' << i.string << '\n';
@@ -156,7 +156,7 @@ Up until now, we were missing the infamous `--help` command. While *ProgramOptio
156
156
157
157
But how do we accomplish printing the options whenever there's a `--help` command? This is where callbacks come into play. Callbacks are functions that we supply to *ProgramOptions.hxx* to call. After we handed them over, we don't need to worry about invoking them as that's entirely *ProgramOptions.hxx*' job. In the code below, we pass a [lambda](http://en.cppreference.com/w/cpp/language/lambda) whose sole purpose is to print the options. Whenever the corresponding option occurs (`--help` in this case), the callback is invoked.
158
158
159
-
The *unnamed parameter*`""` is used to process *non-option arguments*. Consider the command line: `gcc -O2 a.c b.c` Here, unlike `-O2`, `a.c` and `b.c` do not belong to an option and neither do they start with a hyphen. They are non-option arguments but they are important nevertheless. In *ProgramOptions.hxx*, you treat the unnamed parameter like any other option. They only differ in their [default settings](#defaults).
159
+
The *unnamed parameter*`""` is used to process *non-option arguments*. Consider the command line: `gcc -O2 a.c b.c` Here, unlike `-O2`, `a.c` and `b.c` do not belong to an option and neither do they start with a hyphen. They are non-option arguments. In *ProgramOptions.hxx*, you treat the unnamed parameter like any other option. Options and the unnamed parameter only differ in their [default settings](#defaults).
160
160
161
161
Note that, in order to pass arguments starting with a hyphen to the unnamed parameter, you'll have to pass `--` first, signifying that all further arguments are non-option arguments and that they should be passed right to the unnamed parameter without attempting to interpret them.
162
162
```cpp
@@ -235,23 +235,23 @@ In this example, we will employ already known mechanics but lay the focus on the
235
235
236
236
#### Let's start with callbacks:
237
237
- Multiple callbacks are invoked in order of their addition.
238
-
- For an option of type `po::f64`, the possible parameters of a callback are: <*none*>, `std::string`, `po::f64_t`, or any type that is implicitly constructible from these.
239
-
- When using C++14, using `auto&&` as a callback's parameter is also possible.
238
+
- For an option of type `po::f64`, the possible parameter types of a callback are: <*none*>, `std::string`, `po::f64_t`, or any type that is implicitly constructible from these.
239
+
- When using C++14, `auto` and `auto&&` are also a valid callback parameter type.
240
240
241
241
#### About `.fallback(...)`:
242
-
- They can be provided in any form that would also suffice when parsed, e.g. as a `std::string`.
242
+
- Fallbacks can be provided in any form that would also suffice when parsed, i.e. also as a `std::string`.
243
243
- If `.multi()` is set, `.fallback(...)` can take an arbitrary number of values.
244
244
245
245
#### About `.type(...)`:
246
-
- `po::void_`: No value, the option either occurred or not
247
-
- `po::string`: Unaltered string
248
-
- `po::i32` / `po::i64`: Signed integer; supports hexadecimal (*0x*), binary (*0b*) and positive exponents (*e0*)
246
+
- `po::void_`: No value, the option has either occurred or not
247
+
- `po::string`: Stores the unaltered string
248
+
- `po::i32` / `po::i64`: Signed integer; supports decimal, hexadecimal (*0x*), binary (*0b*) and positive exponents (*e0*)
249
249
- `po::u32` / `po::u64`: Unsigned integer; same as with signed integers
250
250
- `po::f32` / `po::f64`: Floating point value; supports exponents (*e0*), infinities (*inf*) and NaNs (*nan*)
251
251
252
252
#### Reading `.multi()` options:
253
-
- `.begin()` and `.end()`: Iterators that point to `po::value`s; thus you have to choose the right member when dereferencing, e.g. `.begin()->i32`
254
-
- `.begin< po::i32 >()` and `.end< po::i32 >()`: Iterators that point to values of the specified type
253
+
- `.begin()` and `.end()`: Random-access iterators that point to `po::value`s; thus you have to choose the right member when dereferencing, e.g. `.begin()->i32`
254
+
- `.begin< po::i32 >()` and `.end< po::i32 >()`: Random-access iterators that point to values of the specified type
255
255
- `.get( i )` (and `.size()`): Reference to `po::value`; there's also a `.get_or( i, v )` method, returning the second parameter if the index is out of range
256
256
- `.to_vector< po::i32 >()`: Returns a `std::vector` with elements of the specified type
0 commit comments