Introduction to some interesting operator overloads
operator""ms / operator""sv
In general occasions, we use std::chrono::milliseconds(1024) to indicate a duration about milliseconds. Actually, STL provides another convenient way to write it as well as other duration units.
After C++11 (_LIBCPP_STD_VER > 11), there is a set of operator overloads about chrono. e.g.
The operator overload operator""ms looks pretty awesome. Other durations have Similarly overloads such as hminsmsusns.
We can also write custom operator overloads like below. Note that the literal operator parameter type must be unsigned long long or long double, otherwise compiler will complain and throw errors even if it’s int or double. It seems like it’s specific form required by compiler.
Unfortunately, it can’t pass compiling because user-defined literal suffixes not starting with ‘_’ are reserved and no literal will invoke this operator. In order to achieve our purpose with user-defined literal suffixes, we can fix it like this:
A usage with overloaded operator -- and operator > that makes it like linked nodes in a line. This skill is implemented in the library workflow‘s data structure WFGraphNode.