msvc is_copy_assignable always true?

后端 未结 2 577
南方客
南方客 2020-12-21 03:01
#include 

class Test
{
public:
    Test(const Test &) = delete;
    Test &operator=(const Test &) = delete;
};

void fn(Test &a,          


        
2条回答
  •  南方客
    南方客 (楼主)
    2020-12-21 03:08

    May be a bit too late, but I have a workaround here: define another copy-and-move assignment operator, also as a deleted one. The compiler gives a warning, complaining about multiple copy operators (C4522), so you have to disable it for the class:

    #pragma warning (disable: 4522)
    class A
    {
        A& operator=(const A&) = delete;
        A& operator=(A) = delete;
    };
    #pragma warning (default: 4522)
    

    Now std::is_copy_assignable::value is false.

提交回复
热议问题