This question already has an answer here:
- What is constructor inheritance? 1 answer
In libstdc++ variant implementation source, there is a use-case of C++ using-declaration, which is puzzling to me.
I simplified the relevant codes in bellow. The "using case 2", using _Base::_Base, appears to be a using-declaration inside a class, but the _Base doesn't have a member named _Base. What it mean here? Why need it?
template<bool __trivially_destructible, typename... _Types>
struct _Variant_storage;
template<typename... _Types>
struct _Variant_storage<false, _Types...> {
constexpr _Variant_storage() {}
//more...
};
template<typename... _Types>
struct _Variant_storage<true, _Types...> {
constexpr _Variant_storage() {}
//more...
};
template<typename... _Types>
bool _S_trivial_dtor = ( is_destructible_v<_Types> && ... );
template<typename... _Types>
using _Variant_storage_alias =
_Variant_storage<_S_trivial_dtor<_Types...>, _Types...>;
template<bool, typename... _Types>
struct _Copy_ctor_base : _Variant_storage_alias<_Types...>
{
using _Base = _Variant_storage_alias<_Types...>; // using case 1
using _Base::_Base; // using case 2
//more...
};
Aucun commentaire:
Enregistrer un commentaire