jeudi 25 août 2016

Why is derived class move constructible when base class isn't?

Consider the following example:

#include <iostream>
#include <string>
#include <utility>

template <typename Base> struct Foo : public Base {
    using Base::Base;
};

struct Bar {
    Bar(const Bar&) { }
    Bar(Bar&&) = delete;
};

int main() {
    std::cout << std::is_move_constructible<Bar>::value << std::endl; // NO
    std::cout << std::is_move_constructible<Foo<Bar>>::value << std::endl; // YES. Why?!
}

Why does compiler generates move constructor despite base class being non-move-constructible?

Is that in the standard or it's a compiler bug? Is it possible to "perfectly propagate" move construction from base to derived class?

Aucun commentaire:

Enregistrer un commentaire