In the STL, "tag dispatch" is one of our oldest and most common metaprogramming techniques. When we need to construct temporary tags, we had to say _Meow() in C++98/03. Now, we prefer to say _Meow{}, because this avoids looking like a function call. We're trying to follow that style in new code, but there's lots of existing code that should be updated.
For example, the _Zero_then_variadic_args_t and _One_then_variadic_args_t tag types:
|
vector() noexcept(is_nothrow_default_constructible_v<_Alty>) : _Mypair(_Zero_then_variadic_args_t()) {
|
|
_Mypair._Myval2._Alloc_proxy(_GET_PROXY_ALLOCATOR(_Alty, _Getal()));
|
|
}
|
|
|
|
explicit vector(const _Alloc& _Al) noexcept : _Mypair(_One_then_variadic_args_t(), _Al) {
|
|
_Mypair._Myval2._Alloc_proxy(_GET_PROXY_ALLOCATOR(_Alty, _Getal()));
|
|
}
|
As I recall, the difference between T() and T{} can be detected by extremely unusual user code, so we shouldn't change how any user-defined types are constructed (e.g. comparison function objects). However, STL-internal tags can be freely changed.
Additionally, for STL-internal tag types, we should strongly consider giving them explicit default constructors, following modern practice in the Standard, which prevents unintentional misuse (e.g. passing {} where a tag is expected).
In the STL, "tag dispatch" is one of our oldest and most common metaprogramming techniques. When we need to construct temporary tags, we had to say
_Meow()in C++98/03. Now, we prefer to say_Meow{}, because this avoids looking like a function call. We're trying to follow that style in new code, but there's lots of existing code that should be updated.For example, the
_Zero_then_variadic_args_tand_One_then_variadic_args_ttag types:STL/stl/inc/vector
Lines 444 to 450 in fd04f77
As I recall, the difference between
T()andT{}can be detected by extremely unusual user code, so we shouldn't change how any user-defined types are constructed (e.g. comparison function objects). However, STL-internal tags can be freely changed.Additionally, for STL-internal tag types, we should strongly consider giving them
explicitdefault constructors, following modern practice in the Standard, which prevents unintentional misuse (e.g. passing{}where a tag is expected).