Reputation: 6637
struct foo{
template<typename T>
auto operator()(T arg) { return T{}; }
}
To use the operator()
, I would call it like: foo()(1)
, which T
would be deduced to int
.
However, if I want to specify T
as something else, like long
, the only way that seems to work is, which kind of defeats the reason of using operator()
:
foo().operator()<long>(1);
Is there a better option?
I'm thinking about letting foo
take a template parameter U
and defaults U
to void
; T
would defaults to U
if U
is not void
. However I'd prefer to only change the operator()
function. Maybe using a lambda instead?
Upvotes: 0
Views: 110
Reputation: 595782
You can use the L
or l
suffix to specify that the integer literal 1
should be treated as a long
instead of an int
, eg:
foo()(1L)
Upvotes: 3