我是Rust的初学者,在文档中找不到与此有关的任何内容。将不胜感激。C ++中的以下循环
for (const int i : {1,2,3,4,5})
cout << i;
Run Code Online (Sandbox Code Playgroud)
大致翻译成
for &i in &[1,2,3,4,5] {
println!("{}", i);
}
Run Code Online (Sandbox Code Playgroud)
有没有办法写相当于
for (int i : {1,2,3,4,5}) {
i += 1;
cout << i;
}
Run Code Online (Sandbox Code Playgroud)
简而言之在Rust中?也就是说,是否有一个快捷方式可以对要迭代的内容进行本地可变复制?
在“ 带有unordered_map的依赖类型 ”中,观察到在libstdc ++ 中
std::unordered_map<Key, Value>具有类型依赖关系Value(这是意外的),而Value在libc ++和MSVC中没有类型依赖关系。
通常,ISO C ++规范是否完全讨论了容器的类型依赖关系?如果可以,您能指出我相关的部分吗?
类型依赖:我不确定在ISO C ++规范中是否有类型依赖的正式定义,但是出于本文的目的,让我们说一个type A类型依赖于type BA是否不能使用B的前向声明进行编译单独。例:
struct Val; // forward declaration of Val
struct Container {
Val v;
}; // Compile error; Type Val is incomplete. Container has a type dependency on Val
Run Code Online (Sandbox Code Playgroud)
struct Val; // forward declaration of Val
struct Container2 {
Val *v;
}; // Compiles. Container2 does not have type dependency on Val
Run Code Online (Sandbox Code Playgroud)