0

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...
    };
Bill
  • 329
  • 1
  • 11
  • This is constructor inheritance, see the linked question for more information. The second `using` declaration is the constructor inheritance. The first one, labeled "using case 1", is just an alias, equivalent to a `typedef` that sets up the actual constructor inheritance, "using case 2", to make it cleaner. `_Base` is just an alias for the parent class. – Sam Varshavchik Feb 18 '19 at 02:14
  • Thanks much, Sam. Yes, it's the same question. The only different is that the base class is using an alias. I guess the both names (type and constructor), _Base::_Base, can use alias. – Bill Feb 18 '19 at 04:24

0 Answers0