I'm using Apple Clang and have the following code in C++:
struct Foo {
int x;
Foo& operator=(const Foo&) = default;
};
struct Bar {
double x;
Bar& operator=(const Foo& foo) {
this->x = static_cast<double>(foo.x);
return *this;
}
};
int main(int argc, const char * argv[]) {
static_assert(std::assignable_from<Bar&, const Foo&>, "fail");
return 0;
}
I have defined an assignment operator in Bar
to assign from Foo
. However, std::assignable_from<Bar&, const Foo&>
still returns false
, causing the static assertion to fail. My understanding is that std::assignable_from<Bar&, const Foo&>
should return true
since Bar
objects can be assigned from Foo
objects due to the custom assignment operator I defined in Bar
.
I'm compiling this with Apple Clang. Could this be a compiler issue or am I misunderstanding how std::assignable_from
works? Could someone explain why std::assignable_from<Bar&, const Foo&>
returns false
and how I could correct this?