std::map::reverse_iterator 与不完整类型一起使用时不适用于 C++20
std::map::reverse_iterator doesn't work with C++20 when used with incomplete type
我注意到以下示例中std::map::reverse_iterator
的使用不适用于C++20,但在所有编译器中都适用于C++17。
演示
演示MSVC
#include <map>
class C; //incomplete type
class Something
{
//THIS WORKS IN C++17 as well as C++20 in all compilers
std::map<int, C>::iterator obj1;
//THIS DOESN'T WORK in C++20 in all compilers but works in C++17 in all compilers
std::map<int, C>::reverse_iterator obj2;
};
int main()
{
Something s;
return 0;
}
我的问题是C++20
发生了什么变化,以至于所有C++20
编译器都停止使用std::map::reverse_iterator
。
它在C++20之前偶然工作,按照标准,在std容器中使用不完整类型是UB(自C++17以来,vector
、list
和forward_list
除外(。请参见此处。因此,它可能工作,也可能在任何时候停止工作,但基本上任何事情都可能发生,不应该依赖它
如果能够存储不完整的类型对于您的用例来说是一个硬性要求,那么您可能需要检查boost::container
。
相关文章:
- 为什么我不能将 rand() 与数组的大小一起使用?
- 不能将复制初始化与隐式转换的多个步骤一起使用
- spdlog标头仅与外部fmt一起使用.spdlog错误:'内部':不是'fmt'
- 为什么常量词在重载运算符中不与 ostream 对象一起使用<<?
- Python 3.8 不能与 Pybind11 一起导入 [Windows]
- Turbo C++ cin() 不能与 gets() 一起使用
- 如何将来自 Boost.Python 的map_indexing_suite与自定义而不是标准对象一起使用?
- OpenGL/Glew C++纹理不适用
- 为什么在template函数广播中把两个extensor表达式加在一起不正确
- 当我在 windows7 中安装程序时,我指定的字体大小不适用
- accelerator.cu(8): 错误:属性"managed"在这里不适用?
- typedef X=<T>T::UserType1,但如果不适用,typedef X<T>=UserType2
- 用C++编写一个程序,对一个简单的序列求和:1/N + 2/N-1 + 3/N-2+ ...不适用
- zmq呼吸机/工作人员/水槽模式与子流程一起不工作
- C++正则表达式与PCRE表达式一起不工作
- SFINAE在这里不适用吗?
- getline(cin,string)与cin.ignore()一起不工作
- 当是复制和交换习语不适用
- 为什么这两个构造函数一起不会产生歧义错误?
- 在函数实参中使用模板形参不适用gcc4.8