cosmetics

This commit is contained in:
Frank B. Brokken 2020-11-20 21:05:08 +01:00
parent 88064f42d9
commit 22000e3955
3 changed files with 28 additions and 26 deletions

View file

@ -95,7 +95,7 @@ includefile(stl/comparisons)
subsect(The class `strong_equality')
includefile(stl/strongequal)
lsubsect(PARTIAL)(The class `partial_ordering')
lsubsect(PARTORD)(The class `partial_ordering')
includefile(stl/partialorder)
subsect(The class `weak_ordering')

View file

@ -56,7 +56,7 @@ int main(int argc, char **argv)
{
fun();
//stmnt
//stmnts
int one = 0;
int two = 0;

View file

@ -1,17 +1,18 @@
We already encountered em(structured bindings) in section
ref(STRUCTBIND). Structured bindings allow us to make the fields of structured
types (like tt(structs, std::pair) or (cf. section ref(TUPLES)) tt(tuples))
available as local variables inside functions. A basic example using
ref(STRUCTBIND). Structured bindings allow us to access the fields of
structured types (like tt(structs, std::pair) or (cf. section ref(TUPLES))
tt(tuples)) as local variables inside functions. A basic example using
structured bindings is shown in the following code snippet:
verbinsert(-s4 //binding examples/tie.cc)
Being able to use structured bindings is very useful in cases like those shown
in the above example. But what if we want to assign the fields of a struct to
variables that have already been defined or that were passed to a function via
its parameters? In those situations structured bindings offer no help. E.g.,
in the following code snippet a function tt(retrieve) is defined having an
tt(int &) parameter and an tt(int) local variable and we want to assign the
values returned by tt(factory) to those variables:
Being able to use structured bindings is very useful in cases like these.
But what if we want to assign the fields of a struct to variables that have
already been defined or that were passed to a function via its parameters? In
those situations structured bindings offer no help. E.g., in the following
code snippet a function tt(retrieve) is defined having an tt(int &) parameter
and an tt(int) local variable and we want to assign the values returned by
tt(factory) to those variables:
verb( void retrieve(int &one)
{
int two;
@ -26,9 +27,9 @@ tt(factory). These statements won't compile:
verb( pair<int &, int &> p{one, two} = factory();
pair<int &, int &>{one, two} = factory();)
Although it is possible to first define a tt(pair<int &, int &>) object and
then assign tt(factory's) return value to it, that solution also looks
somewhat clumsy compared to what's offered by structured bindings. E.g.:
While it is possible to first define a tt(pair<int &, int &>) object and then
assign tt(factory's) return value to it, that approach clearly is less elegant
than what's offered by structured bindings:
verb( pair<int &, int &> p{one, two};
p = factory();)
@ -48,15 +49,16 @@ the following output is obtained:
1 0)
In addition to the above the tt(std::tie) function also supports ordering and
(in)equality comparisons. The following tt(struct Data) defines three fields:
an tt(int), a tt(std::string) and a tt(double). Each of these fields support
ordering and (in)equality comparisons. In those cases, all comparison
operators can easily be implemented by implementing the spaceship operator
(cf. section ref(SPACESHIP)) in which tt(std::tie) is used:
verbinsert(-s4 //stmnts examples/tie.cc)
(in)equality comparisons. The tt(struct Data) in the next example defines
three fields: an tt(int), a tt(std::string) and a tt(double). Each of these
fields support ordering and (in)equality comparisons. In those cases, all
comparison operators can easily be implemented through the spaceship
operator (cf. section ref(SPACESHIP)) using tt(std::tie):
verbinsert(-s4 //spaceship examples/tie.cc)
Note that tt(struct Data's) spaceship operator returns a tt(partial_ordering)
value (cf. section ref(PARTIAL)): although tt(int) and tt(std::string) offer
tt(strong_ordering) spaceship operators tt(double) doesn't, and only provides
tt(partial_ordering) comparisons. Consequently, tt(struct Data's) spaceship
operator returns a tt(partial_ordering) value.
Note that tt(struct Data's) spaceship operator returns tt(partial_ordering)
values (cf. section ref(PARTORD)). Although tt(int) and tt(std::string's)
spaceship operators return tt(strong_ordering) values, tt(double's) spaceship
operator doesn't. Instead it returns tt(partial_ordering)
values. Consequently, tt(struct Data's) spaceship operator also returns
tt(partial_ordering) values.