Привет
https://godbolt.org/z/jhbda1j6d
#include <cstdint>
#include <deque>
using index_type = std::size_t;
inline constexpr const index_type invalid_index = (index_type)-1;
struct IndicesEntry
{
index_type i1;
index_type i2;
};
int main()
{
std::deque<IndicesEntry> que;
que.emplace_back(invalid_index, invalid_index);
//que.emplace_back(IndicesEntry{invalid_index, invalid_index});
}
Выдаёт:
Z:/compilers/msvc/14.41.33923-14.41.33923.0/include\xmemory(700): error C2661: 'IndicesEntry::IndicesEntry': no overloaded function takes 2 arguments
Z:/compilers/msvc/14.41.33923-14.41.33923.0/include\xmemory(700): note: while trying to match the argument list '(const index_type, const index_type)'
Z:/compilers/msvc/14.41.33923-14.41.33923.0/include\xmemory(700): note: the template instantiation context (the oldest one first) is
<source>(16): note: see reference to function template instantiation 'IndicesEntry &std::deque<IndicesEntry,std::allocator<IndicesEntry>>::emplace_back<const index_type&,const index_type&>(const index_type &,const index_type &)' being compiled
Z:/compilers/msvc/14.41.33923-14.41.33923.0/include\deque(1175): note: see reference to function template instantiation 'void std::deque<IndicesEntry,std::allocator<IndicesEntry>>::_Emplace_back_internal<const index_type&,const index_type&>(const index_type &,const index_type &)' being compiled
Z:/compilers/msvc/14.41.33923-14.41.33923.0/include\deque(1139): note: see reference to function template instantiation 'void std::_Default_allocator_traits<_Alloc>::construct<IndicesEntry,const index_type&,const index_type&>(_Alloc &,_Objty *const ,const index_type &,const index_type &)' being compiled
with
[
_Alloc=std::allocator<IndicesEntry>,
_Objty=IndicesEntry
]
Compiler returned: 2
Смущает
const index_type&,const index_type& в сообщении об ошибке. Зачем тут ссылки и почему из них оно не может инициализировать объект?
Вот раньше, в C++03 — было понятно — просто нельзя. Но можно было для статик мемберов структур/классов.
А теперь:
inline static const constexpr constinit index_type invalid_index = (index_type)-1;
Кто в теме, не разжуёте для дилетантов?