What is the meaning of tokenizer<> tok(s)
line in code below? I know that <> is used while working with templates, but according to my understanding <> should not be empty- it should contain type definition.
using namespace std; using namespace boost; string s = "This is, a te\x1Dst"; cout<<s<<endl; tokenizer<> tok(s); for(tokenizer<>::iterator beg=tok.begin(); beg!=tok.end();++beg){ cout << *beg << "\n"; }
A template is a simple yet very powerful tool in C++. The simple idea is to pass data type as a parameter so that we don't need to write the same code for different data types. For example, a software company may need to sort() for different data types.
A template non-type parameter is a template parameter where the type of the parameter is predefined and is substituted for a constexpr value passed in as an argument. A non-type parameter can be any of the following types: An integral type. An enumeration type.
Why we use :: template-template parameter? Explanation: It is used to adapt a policy into binary ones.
It just means the template should use the default parameter(s). For example:
template <int N = 10> class X { }; X<> x; // this is an X<10>
Clearly, it's only possible when all the template parameters have defaults (or for variadic templates that have no mandatory parameters - see below)....
For boost::tokenizer
specifically, the template's:
template < class TokenizerFunc = char_delimiters_separator<char>, class Iterator = std::string::const_iterator, class Type = std::string > class tokenizer;
It's not relevant to the "meaning of tokenizer<> tok
" that the body of your question focuses on, but to address the more general question title "What is the meaning of empty “<>” in template usage?"...
As Shafik first mentioned, the my_template<>
form can also be used with variadic templates such as std::tuple
to specify an empty parameter pack:
// namespace std { template <class ...Args> class tuple; } std::tuple<> t; // this tuple can't store anything :-.
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