In the following MCVE, std::assignable_from reports that A<double>& can't be assigned to from A<double> -- when it clearly can.
#include <iostream>
template <typename T>
class A
{
public:
const A& operator= (const A& other) { return *this; }
};
int main ()
{
A<double> d1, d2; d1 = d2; //this works fine
std::cout << std::boolalpha
<< "Is double assignable? " << std::assignable_from<double&, double> << '\n' //Says true, as it should
<< "Is A<double> assignable? " << std::assignable_from<A<double>&, A<double>> << '\n'; //Says false
return 0;
}
I know why. assignable_from expects operator= to have a return type of A&, not const A&.
template <class _LTy, class _RTy>
concept assignable_from = is_lvalue_reference_v<_LTy>
&& common_reference_with<const remove_reference_t<_LTy>&, const remove_reference_t<_RTy>&>
&& requires(_LTy _Left, _RTy&& _Right) {
{ _Left = static_cast<_RTy&&>(_Right) } -> same_as<_LTy>;
};
Is there an alternative, short of writing my own concept for assignability? I've always had = return const &, because I thought it was dumb to say (A=B)=C.