Less repetitious way to do explicit template instantiation (ETIs)? (without macros)

Viewed 63

Small example problem:

// foo.h
template <typename S>
struct Foo
{
    template <typename T>
    void Bar ();
};

Both S and T can be either char or int. 'Seems like an easy list to maintain, but here's the code:

// foo.cpp
template <typename S>
template <typename T>
void Foo<S>::
    Bar ()
    {
        // uses S and T
    }

template class Foo<int>;
template class Foo<char>;
template void Foo<int>::Bar<int>();
template void Foo<int>::Bar<char>();
template void Foo<char>::Bar<int>();
template void Foo<char>::Bar<char>();

And just to make it a complete example:

// main.cpp
#include "foo.h"

int main ()
{
    // uses all the Foo/Bar permutations
}

In my real-world example I have 2 outer types and 5 inner types for 2 methods, resulting in 2 + 3 * 2 * 5 = 32 ETIs!

I understand that when using ETIs I need to maintain a list of used arguments, but do I really need to maintain all the permutations?

0 Answers
Related