1
Vote

unique requires iterator::value_type to be CopyAssignable

description

unique requires the value_type to be MoveAssignable, while unique_copy has a stricter requirement for it to be CopyConstructible and CopyAssignable.

The current implementation of unique defers to _Unique_copy_impl_helper which utilizes the stricter requirement and tries to copy the object (unique.h:30), causing a failure when a movable-only value_type is used.

Repro:
#include <experimental/algorithm>

struct non_copyable
{
    non_copyable(){}
    non_copyable(const non_copyable&) = delete;
    non_copyable(non_copyable&&){}
    non_copyable& operator=(const non_copyable&) = delete;
    non_copyable& operator=(non_copyable&&){ return *this; }
    bool operator==(const non_copyable&) { return true; }
};

void foo()
{
    non_copyable nc[1];
    unique(std::experimental::parallel::par, std::begin(nc), std::end(nc));
}
Expected: Compilation success.
Actual:
unique.h(30) : error C2280: 'non_copyable &non_copyable::operator =(const non_copyable &)' : attempting to reference a deleted function

comments