In function-oriented languages such as Haskell, you can overload function definitions with several axes of the parameter signature. C ++ supports the number and type of arguments. Other languages support argument values and even protective sentences (code that checks the arguments for conditions.) For example, factorial implementation in Haskell:
factorial :: (Integral a) => a -> a
factorial 0 = 1
factorial n = n * factorial (n - 1)
If the definition of factorial when the argument is 0 is different from the definition of factorial when the argument is any other integer.
I did not find this feature in C ++ and thought it would be difficult to implement in the language. Further reflection made me think that in fact it would be a fairly easy and enjoyable addition to the language, so I should miss it.
Is there a way to do this, either in my own syntax or in templates?
source
share