You cannot make templates instantiate at runtime, you can however ditch templates altogether and use c++11 constexpr
, which was added to the language exactly for this purpose:
struct AnyTime
{
int value;
constexpr AnyTime(int mValue) : value{mValue} { }
constexpr int duplicate() const { return value * 2; }
};
int main()
{
constexpr int compileTime = AnyTime{2}.duplicate();
int value; std::cin >> value;
int runTime = AnyTime{value}.duplicate();
}