In my C++ program I've got these three user-defined literal operators:
constexpr Duration operator""_h(unsigned long long int count) { return {count / 1.f, true}; }
constexpr Duration operator""_m(unsigned long long int count) { return {count / 60.f, true}; }
constexpr Duration operator""_s(unsigned long long int count) { return {count / 3600.f, true}; }
Duration holds a number of hours (as a float) and a validity flag.
So I can say: Duration duration = 17_m;
And I can say: int m = 17; Duration duration = operator""_m(m);
But I can't say:
const char* m = "17_m"; Duration duration1 = operator""_(m);
const char* h = "17_h"; Duration duration2 = operator""_(h);
What I'm aiming for is something like that operator""_()
that I just invented up there, with the compiler picking at run-time the appropriate operator to call. I know I could write something like this myself (in fact I've already done it in this case), but I don't think anything like it is already in the language. I'm asking here to confirm that: Is it in the language?