Is it possible to declare the main function as follows:
template<typename T1, typename T2> int main(T1 argc, T2 *argv[]) { }
For the instance T1 = int and T2 = char we end the general signature.
Constraints for main mention nothing about templates:
No other function in the program can be called the main
main cannot be defined as inline or static.
C ++ main cannot be called from within a program.
C ++. The primary address cannot be completed.
C ++ The main function cannot be overloaded.
Apparently, there is no such syntax application, but
- Is there a compiler that implements it?
- Are there any logical barriers to implementing something like this?
EDIT
I was a little vague in my first attempt to ask above. There were (by right) some negative comments on this issue, so I have to formulate some arguments regarding the request for feedback on this topic :
C ++ is an evolving language, perhaps it should have been implemented, and someone knows about it
Someone can tell me about why main has limitations that it has
A language attorney may find a loophole in the Standard to allow such a declaration (the opposite happened well)
The evolution of the module system leads the language to the logic of separation of components (in terms of compilation units at the moment). Perhaps this will affect the way we create compiled units, maybe several main functions should be defined through submodules, in which case a more flexible main one will be needed.
Templatizing main example
If the Standard allowed something like this (in the future), we could write
template<typename... Args> int main(Args&& ...vs) { }
you go, the arguments of the arguments on the command line (did I invent the wheel or what?)
source share