c++ - template argument deduction - boost::unordered_map -
when reading boost::unordered_map source code, i'was confused definition of class, below:
template <class k, class t, class h, class p, class a> class unordered_map { public: typedef k key_type; typedef std::pair<const k, t> value_type; typedef t mapped_type; typedef h hasher; typedef p key_equal; typedef allocator_type; private: typedef boost::unordered::detail::map<a, k, t, h, p> types; typedef typename types::traits allocator_traits; typedef typename types::table table; ... private: table table_; public: // constructors explicit unordered_map( size_type = boost::unordered::detail::default_bucket_count, const hasher& = hasher(), const key_equal& = key_equal(), const allocator_type& = allocator_type()); ... }; there's no default value class h, class p , class a, why user can declare map instance boost::unordered_map<key, value> map? didn't find guide. help? detailed document/link best.
if start looking @ first header file, 1 #include, going find declaration template, specifies defaults template parameters. (that declaration may not in actual header file, in internal header file being #included there).
the declaration gets compiled first, , declares defaults, , you're seeing here actual template definition.
the initial template declaration specifies defaults template parameters, , not need specified in template definition (and, in fact, compilation error if did).
a brief example:
// initial declaration template<typename t=int> class foo; // definition template<typename t> class foo {}; // usage foo<> bar; the actual boost header files quite complex in structure, declaration , definition of templates spread across separate files, various sundry reasons, assembled in right order actual header file #include in code.
Comments
Post a Comment