How can a mixin see the template class it is wrapping was instantiated on?

I use the mixin pattern a lot in my C++ programming. I love this pattern as it has many of the advantages of the pipeline pattern but higher performance (I hope (let me know if anyone knows the internals of the optimizer to be sure)).
By “mixin” a mean a template class that inherits from one of its template arguments:
template<class BASE_CLASS>
class My_Mixin : public BASE_CLASS

I have been using this pattern for years without issue. Sometimes I have nested them 30 layers deep. It is nice because you can remove things for testing and build things up slowly etc, and not have to worry that performance will suck if you put it in a DSP or rendering loop.
Recently, I have had need to use, base classes which are templated container classes not other mixins and it has been desirable for the mixins to know the type that the base class is templatized on. I tried a bunch of things many of which did not compile as expected. This was the best I could do but it is kind of ugly.
I am running 14 until android studio NDK lets me move to something newer though I am still trying to master 11 completely. At the moment though I am developing on MS Visual Studio targeting windows 10 but with the goal that much of my code will be cross platform.
Often using auto has solved most problems but not in this case. So I have added this dummy static variable.
Does anyone know if there is a better way to do this?

template<class DATA>
class Base
{
public:
static DATA data_example;
private :
std::vector<DATA> x; // something I want to store but My_Mixin can’t get the type
// from with a decltype
};

template<class BASE_CLASS>
class My_Mixin: public BASE_CLASS
{
public:

private:

typedef decltype(BASE_CLASS::data_example) Data_Type;
Data_Type my_mixins_data; // I need to store something of the type that the base class was instantiated on

};

int main()
{
My_Mixin<Base<int>> obj;
}

I think I have dealt with this in the past like this
template<class BASE_CLASS, class DATA >
class My_Mixin: public BASE_CLASS

and then in main

My_Mixin<Base<int>, int> obj;


But the real code I am working on has about 6 mixins and 3 templated arguments for the base class.
Thanks for your ideas.
using is the 'modern' variant of typedef with some additional features...

See:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
template<class DATA>
class Base
{
public:
using data_example = DATA; // Note
private :
std::vector<DATA> x; // something I want to store but My_Mixin can’t get the type
// from with a decltype
};

template<class BASE_CLASS>
class My_Mixin: public BASE_CLASS
{
public:

private:
// Note:
typename BASE_CLASS::data_example my_mixins_data; // I need to store something of the type that the base class was instantiated on

};

int main()
{
My_Mixin<Base<int>> obj;
}
… a template class that inherits from one of its template arguments … Recently, I have had need to use, base classes which are templated container classes

There’s a specific syntax for that, described here:
https://en.cppreference.com/w/cpp/language/template_parameters
Please, see the chapter “Template template parameter”.

Example:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include <vector>

template <typename DATA> class Base {
public:
private:
    std::vector<DATA> v;
};


template <typename T,
          template <typename> class BASE_CLASS>
class My_Mixin: public BASE_CLASS<T> {
public:

private:
    T my_mixins_data;
};


int main()
{
    My_Mixin <int, Base> obj;
}

Topic archived. No new replies allowed.