简体   繁体   English

C ++标准是否指定了标准容器的类型依赖性?

[英]Does the C++ standard specify the type dependencies of standard containers?

In " Codependent types with unordered_map " it was observed that std::unordered_map<Key, Value> has a type dependency on Value in libstdc++ (which is unexpected) and has no type dependency on Value in libc++ and MSVC. 在“ 具有unordered_map的Codependent类型 ”中,观察到std::unordered_map<Key, Value>在libstdc ++中具有类型依赖于Value (这是意外的)并且在libc ++和MSVC中没有类型依赖于Value

In general, does the ISO C++ specification talk about the type dependencies of containers at all? 一般来说,ISO C ++规范是否谈论容器的类型依赖性? If so could you point me to relevant parts? 如果是这样,你能指点我相关的部分吗?

Type dependency: I'm not sure if there is a formal definition of type dependency in the ISO C++ spec, but for the purposes of this post, let us say a type A has type dependency on type B if A cannot be compiled with the forward declaration of B alone. 类型依赖:我不确定ISO C ++规范中是否存在类型依赖的正式定义,但是为了本文的目的,让我们假设type Atype B具有类型依赖性,如果A无法使用仅B的前瞻声明。 Example: 例:

struct Val; // forward declaration of Val
struct Container {
  Val v;
}; // Compile error; Type Val is incomplete. Container has a type dependency on Val
struct Val; // forward declaration of Val
struct Container2 {
  Val *v;
}; // Compiles. Container2 does not have type dependency on Val

You might be looking for this: 你可能正在寻找这个:

[res.on.functions]/2 In particular, the effects are undefined in the following cases: [res.on.functions] / 2特别是,在下列情况下效果未定义:

... ...

(2.5) — if an incomplete type (6.9) is used as a template argument when instantiating a template component, unless specifically allowed for that component. (2.5) - 如果在实例化模板组件时使用不完整类型(6.9)作为模板参数,除非特别允许该组件。


Of various standard containers, [containers] section specifies that std::forward_list , std::list and std::vector can be instantiated with incomplete types. 在各种标准容器中, [containers]部分指定可以使用不完整类型实例化std::forward_liststd::liststd::vector Eg 例如

[vector.overview]/3 An incomplete type T may be used when instantiating vector if the allocator satisfies the allocator completeness requirements (20.5.3.5.1). [vector.overview] / 3如果分配器满足分配器完整性要求(20.5.3.5.1),则在实例化vector时可以使用不完整类型T T shall be complete before any member of the resulting specialization of vector is referenced. 在引用vector任何成员之前, T应该是完整的。

There's similar wording for forward_list and list . 对于forward_listlist有类似的措辞。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM