const int[2] 是微不足道的可复制的
Is const int[2] trivially copyable?
我有一个模板化的成员函数,它看起来有点像下面:
template <typename T>
int SendData( const T& tDataBuffer ) const
{
static_assert( std::is_trivially_copyable<T>::value, "The object type must be trivially copyable" );
// Send the data bitwise
...
}
然后,我以如下所示的方式调用此函数:
const int iArray[2] = {1, 2};
int iResult = pSocket->SendData( iArray );
当我使用 Visual Studio 2012 编译它时,我没有收到任何错误消息,并且程序的功能是我期望的(即数据按位发送),但是,当使用最新版本的编译器 Visual Studio 2013 进行编译时,静态断言失败,编译器向我发出语句:
1>c:...sockets.h(298): error C2338: The object type must be trivially copyable
1> c:...test.cpp(974) : see reference to function template instantiation 'int CBaseSocket::SendData<const int[2]>(T (&)) const' being compiled
1> with
1> [
1> T=const int [2]
1> ]
那么哪个版本的编译器符合标准,const int[2]
是否应该可以复制?
编辑:这是Visual Studio 2013的错误;这是Microsoft Connect报告。
3.9[basic.types]/9
说
标量类型、可平凡复制的类类型(条款 9)、此类类型的数组以及这些类型的 cv 限定版本(3.9.3)统称为平凡可复制类型
您的案例是标量类型的 cv 合格版本的数组。
是的。
平凡可复制对象的标量类型和数组是 也可以微不足道地复制。[1]
此外,gcc 将其报告为微不足道的可复制性。这似乎是VS2013中的一个错误。
相关文章:
- 简单可复制与可简单复制
- reinterpret_cast,只读访问,简单的可复制类型,会出什么问题?
- 对于参加可复制和可移动类的访问者来说,应该有多少过载?
- 可变参数宏:无法通过"..."传递非平凡可复制类型的对象
- 为什么 std::atomic<std::string> 会给出微不足道的可复制错误?
- 我可以隐式地创建一个琐碎的可复制类型吗
- 是std::memcpy在不同的可复制类型之间的未定义行为
- 为什么一对常量是微不足道的可复制的,而对不是?
- 在一个微不足道的可复制结构中,移动语义应该实现吗?
- 防止作用域枚举可复制/可移动
- C :对象上的可复制视图
- 防御性地应用 std::move 到平凡可复制的类型是否不可取
- 为什么 std::function 本身是可复制构造的类型?
- C++不可复制的 lambda 的行为是可复制的
- 错误:无法通过'...'传递非平凡可复制类型的对象'class boost::filesystem::path'
- 不能让类是微不足道的可复制的。我做错了什么?
- 使用临时存储区复制普通的可复制类型:允许吗
- 使用realloc可以安全地重新分配琐碎的可复制对象的存储吗
- 为什么Boost.Asio处理程序必须是可复制的
- const int[2] 是微不足道的可复制的