我期待在這個源代碼代碼我從來沒有在C++ 11
template<char... digits>
struct conv2bin;
template<char high, char... digits>
struct conv2bin<high, digits...> {
static_assert(high == '0' || high == '1', "no bin num!");
static int const value = (high - '0') * (1 << sizeof...(digits)) +
conv2bin<digits...>::value;
};
template<char high>
struct conv2bin<high> {
static_assert(high == '0' || high == '1', "no bin num!");
static int const value = (high - '0');
};
template<char... digits>
constexpr int operator "" _b() {
return conv2bin<digits...>::value;
}
int array[1010_b];
看到,我想知道這是否是有效的,即使C++。
template<char high, char... digits>
struct conv2bin<high, digits...> {
這是什麼?不專門化的模板專業化?
又爲何結構聲明其內部具有行代碼像
struct conv2bin<high> {
static_assert(high == '0' || high == '1', "no bin num!");
static int const value = (high - '0');
};
我很困惑..
是的,抱歉的錯誤 – Paul
看看這些鏈接。他們應該解釋一切。 - [Variadic模板](http://www.cplusplus.com/articles/EhvU7k9E/) - [用戶定義文字](http://en.cppreference.com/w/cpp/language/user_literal) - [Static斷言(http://en.cppreference.com/w/cpp/language/static_assert) –