2014-08-24 星期日 20:47:29
traits简而言之就是型别+偏特化,以期提供统一的“traits”。
先给出只有型别的
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
|
#include <iostream>
#include <iterator>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>
using
namespace
std;
template
<
typename
T>
struct
is_void
{
static
const
bool
value =
false
;
};
template
<>
struct
is_void<
void
>
{
static
const
bool
value =
true
;
};
int
main(
int
argc,
char
* argv[])
{
std::cout<<is_void<
int
>::value<<std::endl;
std::cout<<is_void<
void
>::value<<std::endl;
return
0;
}
|