views:

141

answers:

1

I have seen this in a few places, and to confirm I wasn't crazy, I looked for other examples. Apparently this can come in other flavors as well, eg operator+ <>.

However, nothing I have seen anywhere mentions what it is, so I thought I'd ask.

It's not the easiest thing to google operator<< <>( :-)

+9  A: 

<> after a function name (including an operator, like operator<<) in a declaration indicates that it is a function template specialization. For example, with an ordinary function template:

template <typename T>
void f(T x) { }

template<>
void f<>(int x) { } // specialization for T = int

(note that the angle brackets might have template arguments listed in them, depending on how the function template is specialized)

<> can also be used after a function name when calling a function to explicitly call a function template when there is a non-template function that would ordinarily be a better match in overload resolution:

template <typename T> 
void g(T x) { }   // (1)

void g(int x) { } // (2)

g(42);   // calls (2)
g<>(42); // calls (1)

So, operator<< <> isn't an operator.

James McNellis
James, there is no function template partial specialization, so, for function templates, those angle brackets will always be empty. Your last sentence is potentially confusing to people who keep saying "template function" when they ought to say "function template" and might benefit from a more thorough explanation. Your answer gets a +1 from me anyway, and I would give it a +10 if I could, because it taught me something new: I didn't know one can explicitly prefer a function template over an overloaded function that way.
sbi
@sbi: The angle brackets following the `template` keyword will always be empty. The angle brackets following the function template name may not be. For example, in the first example I give, the `int` could be explicitly stated (i.e., `template<> void f<int>(int x) { }` would yield the same result). If a template argument can't be deduced from the return type and parameter list of the specialization, then those arguments must be explicitly stated.
James McNellis
@James: You're right of course, regarding the angle brackets. Sorry for that brainfart.
sbi