Is a function object class used to perform comparisons. It is defined as a function object class for less than equality comparison that returns a Boolean value depending on the condition.
That is, just use the same example to order in ascending order:
2 4 8 9 11 12 13 17 52 79 89
Simple to understand, right?! That is, put in order of less than or equal.
std::variant is as its name assumes, the type can vary, it is not the same as using
auto(needs initialization and cannot change type). That is, with
std::variant you can say that the
var variable can be:
Std::visit is the way we will handle this data delivered by std::variant, that is, when you create a function it has a return type, so std::visit is almost the same idea directly linked to polymosphism. It is often used in conjunction with lambda expressions.
Example: Create a variable and pass its value to a function, in this case: lambda.
Some things to look at in the code above:
- Need to include variant lib:
- I chose 3 different types for my
- Scope resolution in std::visit can be optional: now I used:
std::visitand once only:
- And finally, you will only be able to compile this code with C++17.
That’s all for today, small daily doses that will always keep us in tune with C++!