mardi 15 décembre 2020

Why is std::is_move_constructible::value == false despite S move-constructing just fine? What is the correct behavior?

This following code move-constructs S via const &&.
Yet it returns 0, indicating S is not move-constructible!

  1. What is the correct behavior of each of the 2 marked constructions in main according to the standard?

  2. If returning 0 is the correct behavior, what is the rationale behind it?
    (Why shouldn't it reflect whether the type is, in fact, constructible via a move?)

#include <algorithm>

struct S
{
    S(          ) { }
    S(S        &) { }  // = delete; doesn't make any difference
    S(S const  &) { }  // = delete; doesn't make any difference
    S(S const &&) { }
    S(S       &&) = delete;
};

int main()
{
    S const s1;
    S s2(std::move(s1));  // OK for >= C++11
    S s3((S()));          // OK for >= C++17, error for <= C++14
    return std::is_move_constructible<S>::value;
}

Aucun commentaire:

Enregistrer un commentaire