Suppose file like this:
my_code.h:
namespace my {
namespace _details{
int ActionNoPrecision(int a);
float ActionSinglePrecision(float a);
double ActionDoublePrecision(double a);
}
auto& Action = my::_details::ActionSinglePrecision;
}
my_code.cpp - implements these functions
So Action is the function alias, that is meant to be called from user code. From my side I want to control meaning of this alias, without touching user's source code (i.e. users still call Action, but Action = ActionDoublePrecision). But with current code I cannot include this header file, because function reference will be defined multiple times.
How to deal with it? I came up with idea of creating static class with these aliases inside, but I've never seen this approach in any library (so do they have just one hardcoded function name?).
Also I have a deeper question. Do aliases cure a need of recompiling user code, if alias meaning changed (i.e. function aliases, type aliases and other)? I suppose no, because location of truly called function is changed, so relinkage is necessary
You are almost there. Just use this:
constexpr auto* Action = my::_details::ActionSinglePrecision;
This could be included into multiple translation units with no problem.