मैं इस स्रोत कोडकोड मैं में सी ++ 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 घोषणा
struct conv2bin<high> {
static_assert(high == '0' || high == '1', "no bin num!");
static int const value = (high - '0');
};
की तरह इसके अंदर कोड लाइनों है करता है ..
हां, गलती के लिए खेद है – Paul
इन लिंक पर एक नज़र डालें। उन्हें सबकुछ समझा जाना चाहिए। - [वैराडिक टेम्पलेट्स] (http://www.cplusplus.com/articles/EhvU7k9E/) - [उपयोगकर्ता-परिभाषित साहित्य] (http://en.cppreference.com/w/cpp/language/user_literal) - [स्टेटिक अभिकथन] (http://en.cppreference.com/w/cpp/language/static_assert) –