I am really struggling to understand the "build_string" example. Here's my attempt to pick it apart.
template<std::size_t count , typename STRING>
struct build_string_impl;
I think the above is a template that resolves to a forward declaration of a struct type called build_string_impl. It says, give me a size and a type STRING, and I give you a struct type. template<std::size_t count , char... Cs>
struct build_string_impl<count,string<Cs...>>
{
using result = typename build_string_impl<count-1,string<c+count,Cs...>>::result;
};
I think the above is a partial specialization of the above forward declaration. In this specialization, the typename STRING is not a string, but instead a variadic char-thingy. So the 'typename STRING' is misleading. This partial specialization creates a struct type that contains a member type 'result' that aliases the 'result' type member of a recursive template instantiation. template<char... Cs>
struct build_string_impl<0,string<Cs...>>
{
using result = string<c,Cs...>;
};
This is a partial specialization that represents the base case. It declares a template that creates a struct type build_string_impl that contains a member type 'result' that aliases the 'result' of a string type.Where I get lost is here:
build_string_impl<count-1,string<c+count,Cs...>>
This attempts to instantiate the build_string_impl template with a size_t and a string. But there is no implementation of the template with these types - only for size_t and variadic char. So how does this get instantiated?