c++ 17 incomplete type works in map but not unordered_map. Are both undefined behavior?

Viewed 141

It seems like I can use an incomplete type for map but not unordered_map. Are they both actually undefined behavior in c++ 17? For example:

// this compiles
class Foo {
public:
  map<string, Foo> mymap;
};

// this does not compile
class Foo {
public:
  unordered_map<string, Foo> mymap;
};

It also appears like vector compiles as well.

// this also compiles
class Foo {
public:
  vector<Foo> myvec;
};

I guess my question is can I use vector and map for incomplete types?

0 Answers
Related