I read some code from <any> in gcc 10.2.0 source
// Manage in-place contained object.
template<typename _Tp>
struct _Manager_internal
{
static void
_S_manage(_Op __which, const any* __anyp, _Arg* __arg);
template<typename _Up>
static void
_S_create(_Storage& __storage, _Up&& __value)
{
void* __addr = &__storage._M_buffer;
::new (__addr) _Tp(std::forward<_Up>(__value));
}
template<typename... _Args>
static void
_S_create(_Storage& __storage, _Args&&... __args)
{
void* __addr = &__storage._M_buffer;
::new (__addr) _Tp(std::forward<_Args>(__args)...);
}
};
And I can't understand why there are two _S_create
, the second is superset of the first, isn't it? Can we omit the first one?
typename _Up = initializer_list<int>
in order that the call_S_create(storage, {1,2,3})
is well formed. – Inkerman