c++ - What is an empty template argument <> while creating an object? -
here valid syntax:
std::uniform_real_distribution<> randomizer(0, 100); how work, automatically deduce object template? why necessary write <> @ end of type? can not remove <> , same?
typically can used , works when first , succeeding, or only, parameter has default template argument (type or value if integral). additional case when there template argument pack , empty.
the <> still needed identify template type.
template <class realtype = double> class uniform_real_distribution; hence default realtype template class uniform_real_distribution double. amounts std::uniform_real_distribution<double>.
with reference c++ wd n4527, §14.3/4 (template arguments)
when template argument packs or default template-arguments used, template-argument list can empty. in case empty
<>brackets shall still used template-argument-list. [ example:template<class t = char> class string; string<>* p; // ok: string<char> string* q; // syntax error template<class ... elements> class tuple; tuple<>* t; // ok: elements empty tuple* u; // syntax error- end example ]
Comments
Post a Comment