Skip to content

Commit 943e967

Browse files
author
Fytch
committed
README: refine wording
1 parent c4cc137 commit 943e967

File tree

1 file changed

+14
-14
lines changed

1 file changed

+14
-14
lines changed

README.md

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ Using this sample is only recommended if you are already somewhat familiar with
5555
- 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.
5656
- **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>
5757
- 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.
5959
- **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.
6060
- A single hyphen `-` is parsed as a **non-option argument**.
6161
- 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`.
7373
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.
7474

7575
### 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.
7777
```cpp
7878
#include <ProgramOptions.hxx>
7979
#include <iostream>
@@ -109,7 +109,7 @@ Let's expand on the previous code. We want it to assume a certain value for the
109109
110110
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`.
111111
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).
113113
114114
```cpp
115115
#include <ProgramOptions.hxx>
@@ -134,9 +134,9 @@ int main( int argc, char** argv ) {
134134
std::cout << "optimization level (" << ( O.was_set() ? "manual" : "auto" ) << ") = " << O.get().u32 << '\n';
135135
136136
auto&& I = parser[ "include-path" ];
137-
// .size() and .count() return the number of given arguments. Without .multi(), their return value is always <= 1.
137+
// .size() and .count() return the number of arguments given. Without .multi(), their return value would always be <= 1.
138138
std::cout << "include paths (" << I.size() << "):\n";
139-
// 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,
140140
// which is not a value in itself but contains the desired values as members, i.e. i.string.
141141
for( auto&& i : I )
142142
std::cout << '\t' << i.string << '\n';
@@ -156,7 +156,7 @@ Up until now, we were missing the infamous `--help` command. While *ProgramOptio
156156

157157
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.
158158

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).
160160

161161
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.
162162
```cpp
@@ -235,23 +235,23 @@ In this example, we will employ already known mechanics but lay the focus on the
235235
236236
#### Let's start with callbacks:
237237
- 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.
240240
241241
#### 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`.
243243
- If `.multi()` is set, `.fallback(...)` can take an arbitrary number of values.
244244
245245
#### 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*)
249249
- `po::u32` / `po::u64`: Unsigned integer; same as with signed integers
250250
- `po::f32` / `po::f64`: Floating point value; supports exponents (*e0*), infinities (*inf*) and NaNs (*nan*)
251251
252252
#### 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
255255
- `.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
256256
- `.to_vector< po::i32 >()`: Returns a `std::vector` with elements of the specified type
257257

0 commit comments

Comments
 (0)