How to turn a class into a template class without breaking existing client code (pre c++17)?

Viewed 99

Can I turn a class into a template class without breaking user code? I am trying to change a class to accept template parameters, but at the same time, I would like to avoid breaking existing client code. In more detail, the existing codebase was

class A{ // some code };

I turned this into the following:

template <type T = defaultType>
class A{ // some code };

The non-templatized code was effectively written for defaultType. Can I do anything so that existing code does not break when the code is compiled without c++17 (or greater) support? For example, the following should be valid:

A a{}; //existing code; works under c++17 with CTAD. How to use in c++14?
A<typeFoo> b{} //new code, if users decide to use a different template argument;

I am grateful for any hints or suggestions!

1 Answers

You can do what std::string does:

template <typename T>
class basic_A{ ... };

using A = basic_A<defaultType>;
Related