'C++: any way to avoid repeating a base class template argument twice?

Say I have a templated base class

template <typename T>
class Base;

and a derived class for which the above template argument is verbose to type out:

class Derived : Base<SomeVerboseType>;

Is there any way one can do something like:

class Derived : Base<T>
{
  using T = SomeVerboseType;
};

The above doesn't work because T is not declared before it is used. Is there any way around this?



Solution 1:[1]

Yes, place the typedef in the base class:

class SomeVerboseType {

};


template <typename T>
class Base {
public:
    using Ty = T;
};

class Derived : public Base<SomeVerboseType> {
    Ty foo;
};

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Ayxan Haqverdili