2
我遇到了這個帖子: Convert a number to a string literal with constexpr如何解釋變量模板中的繼承?
答案是相當有趣:
namespace detail
{
template<unsigned... digits>
struct to_chars { static const char value[]; };
template<unsigned... digits>
const char to_chars<digits...>::value[] = {('0' + digits)..., 0};
template<unsigned rem, unsigned... digits>
struct explode : explode<rem/10, rem % 10, digits...> {};
template<unsigned... digits>
struct explode<0, digits...> : to_chars<digits...> {};
}
template<unsigned num>
struct num_to_string : detail::explode<num> {};
我的問題是:
「結構爆炸:爆炸」 宣佈爆炸的爆炸繼承;如何「結構爆炸< 0,數字...>:to_chars」?
'0'作爲第一個模板參數的函數是什麼?
謝謝!
非常有趣的是,它「繼續」通過variadiac模板擴展繼承而來,然後從最後一個不同的結構體繼承(base case)。謝謝! – Hei