MSVC - How can I find out if a type needs to be moved?

I seem to have problems with a compiler / library error. When i try

#include <iostream>
#include <type_traits>
#include <memory>

int main() 
{
    typedef std::unique_ptr<int> T;

    std::cout << "is_copy_assignable: " 
              << std::is_copy_assignable<T>::value 
              << "\n"
              << "is_copy_constructible: " 
              << std::is_copy_constructible<T>::value << "\n";
}

with Visual Studio 2012 update 1 I get

is_copy_assignable: 1
is_copy_constructible: 1

instead

is_copy_assignable: 0
is_copy_constructible: 0

Is there an alternative solution?

+2
source share
2 answers

This is definitely a mistake. MS implementations of std::unique_ptr<>either type attributes. These character traits should work as you expect (see Live Example here ).

+3
source

If you look down at what happens, it checks if the assignment operator and ctor exist , . MSVC private std::unique_ptr . . MSVC = delete .., true.

- , , -, ctor:

#include <type_traits>
#include <memory>

template <typename T>
struct wrap
{
   T t;
};

template<typename T, typename = int>
struct is_copyable : std::false_type { };

template<typename T>
struct is_copyable<T, 
    decltype(wrap<T>(std::declval<const wrap<T>&>()), 0)> : std::true_type
{};

class X
{
   public:
   X(const X&) {}
};

class Y
{
   Y(const Y&){}
};

int main()
{
    static_assert(is_copyable<std::unique_ptr<int>>::value, "Error!");
    static_assert(is_copyable<X>::value, "Error!");
    static_assert(is_copyable<Y>::value, "Error!");
}

LWS.

ICE MSVC... .

+3

Source: https://habr.com/ru/post/1568747/


All Articles