Std :: couple complaining about incomplete type

How to compile the following code?

#include <type_traits>
#include <utility>

struct A;

template<typename T>
struct B{
    T* p;

    B& operator=(B&&);
    B& operator=(T&&);
};

int main(){
    //typedef B<A> type;// fine
    typedef B<std::pair<A, A>> type;// error

    noexcept(std::declval<type&>() = std::declval<type>());

    return 0;
}

PS: Type B mimics boost :: recursive_wrapper, which cannot compile for the same reason.

+4
source share
2 answers

Typedef itself is not a problem. It is perfectly legal to write struct foo; typedef std::pair<foo, foo> bar;. The problem is

noexcept(std::declval<type&>() = std::declval<type>());

This requires the compiler to perform overload resolution for operator=. As part of overload resolution, he must look for possible conversions from B&&to std::pair<A, A>&&, and this requires the creation of an instance std::pair<A,A>(Β§14.7.1 [temp.inst] / p6):

, , . [: , , . , , , . -end note]

... Β§ 17.6.4.8 [res.on.functions]/p2 undefined.

std::pair<A, A> , (Β§14.7.1 [temp.inst]/p7):

, , .

+7

A , . .

+2

All Articles