Reputation: 33
I found some similar topics, but none seem to give straight answer about my particular problem.
I have a class (let's call it Foo) within some library that we are using across few modules. Now I need to transform this class to be a variadic template(so now I have: template<class... T> Foo() {}
), as some new uses need exactly the same general mechanics, but need to accept additional parameters inside. Old implementations already in use do not need this.
So I transformed this into variadic template stored in one *.h file, but now wherever we already use this class I would need to change every occurrence of Foo()
to Foo<>()
, in order for existing code to work as it did.
Now, I am not sure if there are some modules that I am not even aware of that would use this library, so I thought of a flexible solution like alias to Foo<>, that would not require those other modules to be updated after this change in library.
Is it possible in this particular example to use something like: using Foo = Foo<>
, so that all occurrences of Foo
that already exist in the code will automatically be treated as Foo<>
without need of any changes in source code?
Would it be possible to have such alias defined in the same file as template definition/declaration, even though it would have exactly the same name as the class itself?
Upvotes: 3
Views: 93
Reputation: 4046
If you rename the templatized definition of Foo
to some other name FooExtended
, then you can typedef
the empty template to Foo
//old
class Foo;
//new
template<class... Args>
class FooExtended;
using Foo = FooExtended<>;
Upvotes: 3