是const int [2]平凡可复制吗? [英] Is const int[2] trivially copyable?

查看:320
本文介绍了是const int [2]平凡可复制吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个模板成员函数,看起来有点像下面:

I have a templated member function which looks somewhat like the following:

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
    ...
}

然后,我以如下方式调用此函数:

I then call this function in a manner like the following:

const int iArray[2] = {1, 2};
int iResult = pSocket->SendData( iArray );

当我使用Visual Studio 2012编译时,我没有收到错误信息,程序的功能我将期望(即数据是按位发送),但是,当编译与最新版本的编译器,Visual Studio 2013,静态assert失败,编译器发出我的语句:

When I compile this with Visual Studio 2012, I get no error message and the functionality of the program is how I would expect (i.e. the data is sent bitwise), however, when compiling with the newest version of the compiler, Visual Studio 2013, the static assert fails, the compiler issuing me the statement:

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] 是否可以轻易复制?

So which version of the compiler is standards-conformant, should const int[2] be trivially copyable or not?

编辑: Studio 2013;这里是 Microsoft Connect报告

This is a bug with Visual Studio 2013; here is the Microsoft Connect report

推荐答案

3.9 [basic.types] / 9


标量类型,简单可复制类类型(第9条)这些类型的数组和这些类型的cv限定版本(3.9.3)统称为可复制类型

Scalar types, trivially copyable class types (Clause 9), arrays of such types, and cv-qualified versions of these types (3.9.3) are collectively called trivially copyable types

数组的cv限定版本的标量类型。

Your case is array of cv-qualified version of a scalar type.

这篇关于是const int [2]平凡可复制吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆