The infix operator

First of all, adding an infix operator is both a hack and, more or less, an abuse of operator overloading. What you actually do is overload both the less than (operator<) and greater than (operator>) operators in order to make something that looks like an infix operator.

If nothing less, it can be used to show to your Python-fan friends, who praise the in keyword in Python, that you can implement something similar in C++.

Essentially, we want to see whether an object is contained in a list with the following syntax:

auto asia = std::vector<std::string>{"Korea","Philippines","Macau"}; auto africa = std::vector<std::string>{"Senegal","Botswana","Guinea"}; auto is_botswana_in_asia = "Botswana" <in> asia; auto is_botswana_in_africa ...

Get C++ High Performance now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.