0

Why did they choose to make the std::assignable_from concept behave so differently from its name-sharing type-trait std::is_assignable? (Opposed to some of the other name-sharing type-traits and concepts.)

static_assert(not std::is_convertible_v<char, std::string>); // ok
static_assert(not std::convertible_to<char, std::string>);   // ok

static_assert(not std::is_constructible_v<std::string, char>); // ok
static_assert(not std::constructible_from<std::string, char>); // ok

static_assert(std::is_assignable_v<std::string&, char>); // ok
static_assert(std::assignable_from<std::string&, char>); // fail

Live example

Why didn't they either change std::is_assignable to be more in line with std::assignable_from, or simply give a different name to std::assignable_from?

Please note that I'm not asking what explains the difference in behavior between the type-trait and related concept.

303
  • 2,417
  • 1
  • 11
  • 25
  • 2
    "*I'm not asking what explains the difference in behavior between the type-trait and related concept.*" Wouldn't that be a useful data point in trying to determine why they're not identical? – Nicol Bolas Mar 10 '23 at 23:44
  • @NicolBolas Yes, and by all means, feel free to use that to provide a good answer. I just wanted to emphasize that I'm not looking for an answer that boils down to highlighting the differences from the possible implementations that are available on [cppreference.com](https://www.cppreference.com/). – 303 Mar 11 '23 at 01:10
  • Does this answer your question? [The rationale behind std::assignable\_from possible implementation](https://stackoverflow.com/questions/60138440/the-rationale-behind-stdassignable-from-possible-implementation) – Rane Mar 11 '23 at 06:12
  • Furthermore, even if might not initially seem so, [this answer](https://stackoverflow.com/a/66938093/14462794) basically explains the crux behind all of this. The deviation of `std::assignable_from` has everything to do with `std::common_reference` and the semantic equality requirements of `std::assignable_from`. – Rane Mar 11 '23 at 06:20
  • @Rane I already read up on that question before asking this one. It doesn't answer the question I'm asking here. – 303 Mar 11 '23 at 08:59
  • @303 The `std::common_reference_with` requirement inherently explains why `std::assignable_from` gives different results compared to `std::is_assignable_v`. Moreover, `std::common_reference` is in the very root of the design of how [the original Concepts proposal defines equality](https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2012/n3351.pdf#subsection.3.3). Now, if you really want to ask why they designed it this way, I advice you to send an email to Stroustrup or Sutton (authors of the paper). – Rane Mar 11 '23 at 10:13

0 Answers0