Container
是模板参数,它定义了用于sorted_vector_map
存储键值对的容器,默认为std::vector
( std::vector<std::pair<Key, Value>, Allocator>>
)
value_type
is Container::value_type
( typedef typename Container::value_type value_type;
) which (对于默认模板参数) is std::pair<Key, Value>
(见std::vector 成员类型)
mapped_type
是Value
( typedef Value mapped_type;
) 所以存储在sorted_vector_map
什么是 value_type(key, mapped_type())?
什么是映射类型()?
它也是构造函数调用吗?
因此value_type(key, mapped_type())
创建了一个std::pair
with key
asfirst
和一个默认构造的Value
( mapped_type()
) as second
。
默认情况下它是对 std::pair 的构造函数调用吗?
是的
template <
class Key,
class Value, // <<===============
class Compare = std::less<Key>,
class Allocator = std::allocator<std::pair<Key, Value>>,
class GrowthPolicy = void,
class Container = std::vector<std::pair<Key, Value>, Allocator>> // <<===============
class sorted_vector_map : detail::growth_policy_wrapper<GrowthPolicy> {
detail::growth_policy_wrapper<GrowthPolicy>& get_growth_policy() {
return *this;
}
template <typename K, typename V, typename C = Compare>
using if_is_transparent =
_t<detail::sorted_vector_enable_if_is_transparent<void, C, K, V>>;
struct EBO;
public:
typedef Key key_type;
typedef Value mapped_type; // <<===============
typedef typename Container::value_type value_type; // <<===============
typedef Compare key_compare;
typedef Allocator allocator_type;
typedef Container container_type;