Creative operator overloading and proxy objects
As you know, C++ has the ability to overload operators that are usually utilized to make custom math objects that can be used with standard math operators, such as plus, minus, and so on, in order to make the code more readable. Another example is the stream operator, which in the standard library is overloaded in order to convert the objects to streams, as shown below:
std::cout << "iostream " << "uses " << "overloaded " << "operators.";
Some libraries, however, use the overloading in other contexts. The Range V3 library, as discussed earlier, uses overloading to compose views like this:
namespace rv = ranges::view; auto odd_positive_numbers = std::vector<int>{-5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5} | rv::filtered([](auto v){ return v > 0; } | rv::filtered([](auto v){ return (v % 2) == 1; } ;
Other libraries have used it to create an infix operator so that we can emulate the Python keyword, in
,...