msvc is_copy_assignable always true?(msvc is_copy_assignable 始终为真?)
问题描述
#include <type_traits>
class Test
{
public:
Test(const Test &) = delete;
Test &operator=(const Test &) = delete;
};
void fn(Test &a, const Test &b) { a = b; }
static_assert(!std::is_copy_assignable<Test>::value, "Test shouldn't be assignable");
在 MSVC 2013 Update 3 下编译它意外地使 static_assert 失败,并且函数 fn 无法编译(如预期).这是矛盾的,对吧?
Compiling this under MSVC 2013 Update 3 unexpectedly fails the static_assert, and the function fn fails to compile (as expected.) This is contradictory, right?
我是否滥用了is_copy_assignable?有没有其他方法可以测试这种情况?
Am I misusing is_copy_assignable? Is there another way to test for this condition?
推荐答案
您说得对,这是一个错误:https://connect.microsoft.com/VisualStudio/feedback/details/819202/std-is-assignable-and-std-is-constructible-give-wrong-value-for-deleted-members
You are correct this is a bug: https://connect.microsoft.com/VisualStudio/feedback/details/819202/std-is-assignable-and-std-is-constructible-give-wrong-value-for-deleted-members
我拿了 cplusplus.com 的 is_copy_assignable 代码:
I took cplusplus.com's is_copy_assignable code:
#include <iostream>
#include <type_traits>
struct A { };
struct B { B& operator= (const B&) = delete; };
int main() {
std::cout << std::boolalpha;
std::cout << "is_copy_assignable:" << std::endl;
std::cout << "int: " << std::is_copy_assignable<int>::value << std::endl;
std::cout << "A: " << std::is_copy_assignable<A>::value << std::endl;
std::cout << "B: " << std::is_copy_assignable<B>::value << std::endl;
return 0;
}
并在 Visual Studio 2013 上对其进行测试并得到:
And tested it on Visual Studio 2013 and got:
is_copy_assignable:
整数:真
答:是的
乙:真的
is_copy_assignable:
int: true
A: true
B: true
在 gcc 4.8.1 上,我得到了:
is_copy_assignable:
整数:真
答:是的
乙:假
is_copy_assignable:
int: true
A: true
B: false
特别是在 Visual Studio 2015 Beta 上,此问题已修复.我得到:
Notably on the Visual Studio 2015 Beta this is fixed. I get:
is_copy_assignable:
整数:真
答:是的
乙:假
is_copy_assignable:
int: true
A: true
B: false
你对测试版的感觉如何;)
How do you feel about betas ;)
这篇关于msvc is_copy_assignable 始终为真?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:msvc is_copy_assignable 始终为真?
基础教程推荐
- 常量变量在标题中不起作用 2021-01-01
- 在 C++ 中计算滚动/移动平均值 2021-01-01
- 如何在 C++ 中初始化静态常量成员? 2022-01-01
- 静态库、静态链接动态库和动态链接动态库的 .lib 文件里面是什么? 2021-01-01
- 这个宏可以转换成函数吗? 2022-01-01
- 如何将 std::pair 的排序 std::list 转换为 std::map 2022-01-01
- 如何检查GTK+3.0中的小部件类型? 2022-11-30
- 我有静态或动态 boost 库吗? 2021-01-01
- C++结构和函数声明。为什么它不能编译? 2022-11-07
- 如何通过C程序打开命令提示符Cmd 2022-12-09
