I just finished an iteration on a library that I am writing. In order to isolate certain types, I originally put them into a namespace. Then, I realised that this namespace should actually be templated, so I turned it into a struct, ie:
namespace A
{
typedef _foo foo;
}
became
template <class T>
struct A
{
typedef _foo<T> foo;
};
This was more convenient to use in say, this situation:
template <class T>
class MyClass
{
public:
typedef A<T> nsA;
typedef typename nsA::foo foo_type;
};
Now, I'm using that library in another library, and there, I know that the template type T
will never change. So I would like to do something like:
namespace B
{
using namespace A<double>;
}
but obviously, this doesn't work. Of course, I could just stop being lazy, and typedef
manually each definition in A<double>
, but I like being lazy when I can. Any thoughts on how to do something equivalent to this last step?
Actually, I just found the answer. Sorry, if you think this question was useless, I'll delete it, just let me know in comment.
Since I used a struct as a namespace in the first place, the solution is to keep using a struct as a namespace (!):
struct B
: public A<double>
{};
Here is a demo.