Reputation: 1010
There are only 2 use cases known to me for empty angle brackets <>
in c++ templates, which are encountered:
1) During template full specialization e.g.
template<typename T>
class X
{};
template<>
class X<char>
{};
2) During the templated function call which argument type's can be deduced e.g.
template<typename T>
T add(T a, T b);
...
add<>(1, 2);
But this case is completely new to me, and I can't understand the meaning of such syntax (please have a look at rapidxml::xml_node<>*
):
class TestWidget : public GUI::Widget
{
public:
TestWidget(const std::string& name, rapidxml::xml_node<>* elem);
// ...
};
What semantics are given to the xml_node<>
type here in the constructor parameter ???
Upvotes: 6
Views: 1024
Reputation: 66220
Not this case (default template argument, as in the Jarod42's answer) but that syntax can also declare an object of a variadic template type with empty list of template arguments.
Or both.
#include <iostream>
// default value
template <typename = void>
struct foo
{ };
// variadic list
template <int ...>
struct bar
{ };
// both
template <int = 0, typename ...>
struct foobar
{ };
int main ()
{
foo<> f;
bar<> b;
foobar<> fb;
}
The funny part it that you can't distinguish the cases from variable declarations.
Upvotes: 8
Reputation: 217663
There is also with default template argument:
template<typename T = char>
class X
{};
so
X<> x; // X<char>
Upvotes: 8