Do expressions fun
and &fun
have the same type or not?
Consider the following code:
template <typename Check, typename T> void check(T) { static_assert(is_same<Check, T>::value); } void fun() {} check<void(*)()>(fun); check<void(*)()>(&fun); cout << typeid(fun).name() << endl; cout << typeid(&fun).name() << endl;
Both assertions succeed which suggests that both expressions have the same type. However, typeid
s return different results:
FvvE PFvvE
Why is that?
Funner and funnest have been in use as the comparative and superlative forms of the adjective fun for more than a century, though many people prefer to use more fun and most fun.
Fun commonly functions as an adjective ("I had a fun time") and as a noun ("Let's have some fun"), and somewhat less commonly as a verb ("I'm just funning you").
As a noun, fun means enjoyment. Fun is not universally accepted as an adjective. People who do accept it as an adjective seem to prefer more fun and most fun over funner and funnest.
But if you're thinking that that logic is downright silly, most dictionary establishments agree with you. And they also agree that…the answer to “is funner a word?” is yes. If you want to consider “fun,” as an adjective, a word, then “funner” is indeed a word, as is “funnest,” per normal rules of adjective formation.
Both assertions succeed because they are applied to the type T
deduced from function argument. In both cases it will be deduced as a pointer to function because functions decay to a pointer to function. However if you rewrite assertions to accept types directly then first one will fail:
static_assert(is_same<void(*)(), decltype(fun)>::value); static_assert(is_same<void(*)(), decltype(&fun)>::value);
online compiler
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With