Is possible, in C
, to overload the ""_something
operator for function identifiers or callables
in order to make it have custom behaviour?
I recently saw something similar in this cppcon video, where the presenter is exposing how to build a unit test framework using modules, zero macros... but I am not understanding well how the ""_test
is possible, or how C
understands that for that callable should perform such an action defined in the body of the operator overloading implementation.
template <typename T>
auto "some_name"_test(T a, T b);
Can someone explain the details behind this?
CodePudding user response:
The UDL operator ""
is just a function call. Functions can return anything. They can, for example, return an object type which has an overloaded operator()
, and is therefore callable. They can return an object type with an overloaded operator=
, and is therefore assignable. Etc.
It's not about how you overload the UDL operator; it's about what your overload returns.