unordered_map экземпляров класса-владельца
От: sergii.p  
Дата: 08.07.20 13:59
Оценка:
всем привет. Пишу так
struct B
{
   std::unordered_map<int, B> childs; 
};

не компилируется (/usr/include/c++/6/bits/stl_pair.h:211:11: error: ‘std::pair<_T1, _T2>::second’ has incomplete type)
переписываю на
struct B
{
   std::map<int, B> childs; 
};

всё нормально. Кто-то может объяснить почему?
microsoft компилирует оба варианта. Это gcc так выделывается.
Отредактировано 08.07.2020 14:41 sergii.p . Предыдущая версия .
Re: unordered_map экземпляров класса-владельца
От: _NN_ www.nemerleweb.com
Дата: 08.07.20 14:54
Оценка: 1 (1) +1
Здравствуйте, sergii.p, Вы писали:

SP>всё нормально. Кто-то может объяснить почему?

Потому что нет требования стандарта это компилировать.
Отдано на откуп реализации.

https://stackoverflow.com/a/13089641

17.6.4.8:

In certain cases (replacement functions, handler functions, operations on types used to instantiate standard library template components), the C++ standard library depends on components supplied by a C++ program. If these components do not meet their requirements, the Standard places no requirements on the implementation.

In particular, the effects are undefined in the following cases:

...

if an incomplete type is used as a template argument when instantiating a template component, unless specifically allowed for that component.


SP>microsoft компилирует оба варианта. Это gcc так выделывается.


Судя по всему GCC в обозримом будущем и не будет компилировать.
http://rsdn.nemerleweb.com
http://nemerleweb.com
 
Подождите ...
Wait...
Пока на собственное сообщение не было ответов, его можно удалить.