The classic example of compile time recursion is std::tuple, which you
might find instructive to have a look at. tuples are normally
implemented using recursive inheritance, something like:
template <class Head, class... Tail>
class Tuple<Head, Tail...>: private Tuple<Tail...> {
Head elt;
public:
...
};
with a specialization:
template <> struct Tuple<> { ... };
which ends recursion. I think most people go through the business of
writing their own tuple implementation at some point in their lives for
pedagogical purposes (and to learn how variadic templates work).
This is of course doing different things from your RecursiveClass.
A tuple keeps values via this recursive inheritance which can be
accessed individually by a get function such as std::get(), which would
traverse the inheritance graph. Yours provides an accessor which sums
all the values.
You are right that at compile time the size of the tuple and the types
for which it is instantiated must be known. It is part of the
tuple's type.
As regards your non-templated RecursiveClass, your use of
std::unique_ptr looks OK. If your compiler supports C++17, as an
alternative you could try std::optional, which I have never used. If
this implementation is a toy for fun, then it looks OK but in practice
to keep a collection of unsigned ints of a size determined at run time I
would use std::vector, which would be much more flexible because it
would not restrict you to summing the elements - std::accumulate can
fold over the container to do whatever you want. std::forward_list
would be a more exact container replacement for your implementation, but
be much less efficient for keeping unsigned ints.
Chris