内容:
说明:
类模板多参数
示例代码:
// C++Variadics.cpp : 定义控制台应用程序的入口点。
//
#include "stdafx.h"
#include <iostream>
using namespace std;
template <bool a> int reversed_binary_value()
{
return a;
}
template <bool a, bool b, bool... d> int reversed_binary_value()
{
return ( reversed_binary_value<b, d...>() << 1 ) + a;
}
template <int n, bool...digits>
struct CheckValues
{
static void check( int x, int y )
{
CheckValues < n - 1, 0, digits... >::check( x, y );
CheckValues < n - 1, 1, digits... >::check( x, y );
}
};
template <bool...digits>
struct CheckValues<0, digits...>
{
static void check( int x, int y )
{
int z = reversed_binary_value<digits...>();
std::cout << ( z + 64 * y == x );
}
};
int main()
{
int t;
std::cin >> t;
for( int i = 0; i != t; ++i )
{
int x, y;
cin >> x >> y;
CheckValues<6>::check( x, y );
cout << "\n";
}
system("pause");
return 0;
}
知识点:
多参数的使用