How to alias a certain template function to make it called by using shorter syntax?
From ....
getSystem<SystemX>()-> //get semi-singleton instance of "SystemX"
... to something like this:-
getSystem<SystemX>-> or
getSystem(SystemX)-> or
{SystemX}-> or
SystemX=> (can I define new strange operator?)
At first, I don't think it is a problem at all, but after several months, I think there might be a more concise way (syntax) to call it. (I use it in 400+ location).
I believe it is possible by using the same trick as std::is_enable_t<T>
=std::is_enable<T>::value
. (?)
My poor workarounds
Besides making the name shorter e.g. getSystem<SystemA>()->
to ss<A>()->
, here are my workarounds.
Solution A
Instead of calling getSystem<SystemA>()->
, I would call SystemA::
instead.
Disadvantage:
Every function of system now become static function.
There can't be any 2 instance of the same system inside my program anymore.
Common disadvantage of singleton : Global variable, break single responsibility, etc.
Solution B
By using macro, the result is exactly what I want :-
#define S(param) getSystem<param>()
S(SystemA)->fa()
However, macro has some disadvantages.
I feel that this is not a place to use this type of hack.
Sorry, if it is too newbie, I am very new to C++.