VS 2015 Update 3 errors for the operator of copying deleted copies

The following code compiles well on clang-3.8 and gcc 4.9.3.

#include <vector>
#include <algorithm>
#include <iterator>

class foo 
{
};

class MyVec {
    public:
    MyVec() {}
};

class MyInsert :
    public std::iterator<std::output_iterator_tag, void, void, void, void>
{
  protected :
    MyVec &fV;

  public :
    explicit MyInsert (MyVec &v) : fV(v) {}

    MyInsert & operator= (void *value)
    {
        return *this;
    }

    MyInsert & operator* ()    { return *this; }
    MyInsert & operator++ ()   { return *this; }
    MyInsert & operator++(int) { return *this; }

};    

class test
{
    public:    
    void method()
    {
        MyVec retv;

        std::vector<const foo*> foovec;
        std::transform(foovec.begin(), foovec.end(),MyInsert(retv),[](const foo*)->void* { return nullptr;});
    }
};

int main(){
    return 0;
}

However, when compiling in VS 2015 Update 3, it crashes with the following error message.

c:\program files (x86)\microsoft visual studio 14.0\vc\include\xutility(458): error C2280: 'MyInsert &MyInsert::operator =(const MyInsert &)': attempting to reference a deleted function
test\mytests\main.cpp(33): note: compiler has generated 'MyInsert::operator =' here
c:\program files (x86)\microsoft visual studio 14.0\vc\include\algorithm(926): note: see reference to function template instantiation '_Iter &std::_Rechecked<_OutIt,_OutIt>(_Iter &,_UIter)' being compiled
        with
        [
            _Iter=MyInsert,
            _OutIt=MyInsert,
            _UIter=MyInsert
        ]
c:\program files (x86)\microsoft visual studio 14.0\vc\include\algorithm(950): note: see reference to function template instantiation '_OutIt std::_Transform_no_deprecate1<const foo**,_OutIt,_Fn1>(_InIt,_InIt,
_OutIt,_Fn1 &,std::input_iterator_tag,std::_Any_tag)' being compiled
        with
        [
            _OutIt=MyInsert,
            _Fn1=test::method::<lambda_45e8626339fc29aadca2bf2dd3420511>,
            _InIt=const foo **
        ]
c:\program files (x86)\microsoft visual studio 14.0\vc\include\algorithm(960): note: see reference to function template instantiation '_OutIt std::_Transform_no_deprecate<_InIt,_OutIt,_Fn1>(_InIt,_InIt,_OutIt,
_Fn1 &)' being compiled
        with
        [
            _OutIt=MyInsert,
            _InIt=std::_Vector_iterator<std::_Vector_val<std::_Simple_types<const foo *>>>,
            _Fn1=test::method::<lambda_45e8626339fc29aadca2bf2dd3420511>
        ]
test\mytests\main.cpp(45): note: see reference to function template instantiation '_OutIt std::transform<std::_Vector_iterator<std::_Vector_val<std::_Simple_types<const
foo *>>>,MyInsert,test::method::<lambda_45e8626339fc29aadca2bf2dd3420511>>(_InIt,_InIt,_OutIt,_Fn1)' being compiled
        with
        [
            _OutIt=MyInsert,
            _InIt=std::_Vector_iterator<std::_Vector_val<std::_Simple_types<const foo *>>>,
            _Fn1=test::method::<lambda_45e8626339fc29aadca2bf2dd3420511>
        ]
        ]

I cannot understand why it (VS Compiler) cannot find a copy assignment operator that accepts void *and returns MyInsert &when explicitly specified.

Digging more (following the error message trace)

c:\program files (x86)\microsoft visual studio14.0\vc\include\xutility

and

c:\program files (x86)\microsoft visual studio14.0\vc\include\algorithm

also made me realize that the actual function in which the algorithm std::transformationis called, the explicitly assigned copy destination is called, after which it enters the function _Recheckedand it goes to the header xutility.

, ( MyInsert& MyInsert&), , attempting to reference....

? , , ? , ?

P.S

, , MyInsert .

+4
1

, (VS Compiler) , void * MyInsert &, .

, void*, .

, . , .

OutputIterator, Iterator CopyAssignable, , . , MyInsert.

, ?

, , , .

, .

, ?

. VS, .

, , MyInsert .

, . . , , .

+5

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


All Articles