Command设计模式3
来源:互联网 发布:启航考研网络视频 编辑:程序博客网 时间:2024/06/08 00:42
2014-11-18 星期一 20:44:45
接下来对struct TestFunctor的泛化,主要是对返回值的返回。分void和非void
1、TestFunctorImpl
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
template
<
typename
R>
struct
Rtraits
{
enum
{isvoid =
false
};
typedef
R reltype;
};
template
<>
struct
Rtraits<
void
>
{
enum
{isvoid =
true
};
typedef
void
reltype;
};
template
<
typename
R,
class
TList>
struct
TestFunctorImpl
{
typedef
R ResultType;
typedef
typename
TypeAtNonStrict<TList, 0, NullType>::Result Parm1;
typedef
typename
TypeAtNonStrict<TList, 1, NullType>::Result Parm2;
typedef
typename
Rtraits<R>::reltype reltype;
ResultType operator()(Parm1 p1, Parm2 p2)
{
if
(Rtraits<R>::isvoid)
{
printf
(
"TestFunctorImpl::operator(%d, %f) called, return void\n"
, p1, p2);
return
operator_(p1, p2);
}
else
{
printf
(
"TestFunctorImpl::operator(%d, %f) called, return void not\n"
, p1, p2);
return
operator_(p1, p2, 1);
}
}
ResultType operator_(Parm1 p1, Parm2 p2)
{
printf
(
"TestFunctorImpl::operator1(%d, %f) called, return void\n"
, p1, p2);
}
ResultType operator_(Parm1 p1, Parm2 p2,
int
)
{
printf
(
"TestFunctorImpl::operator1(%d, %f) called, return void not\n"
, p1, p2);
}
};
2、main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
int
main(
int
argc,
char
* argv[])
{
TestFunctorImpl<
void
, TYPELIST_2(
int
,
double
)> fImpl;
Functor<
void
, TYPELIST_2(
int
,
double
) > cmdImpl(fImpl);
cmdImpl(5, 5.5);
printf
(
"\n######\n"
);
TestFunctorImpl<
int
, TYPELIST_2(
int
,
double
)> fImpl_1;
Functor<
int
, TYPELIST_2(
int
,
double
) > cmdImpl_1(fTmpl_1);
cmdImpl_1(5, 5.5);
return
0;
}
0 0
- Command设计模式3
- 设计模式 command模式
- 设计模式----Command模式
- 设计模式:Command模式
- 【设计模式】Command模式
- 设计模式--Command 模式
- 设计模式-----COMMAND模式
- 设计模式之Command
- 设计模式之Command
- 设计模式之Command
- 设计模式之Command
- Command设计模式
- 设计模式之Command
- 设计模式之Command
- Command设计模式
- 设计模式之 Command
- 设计模式之Command
- 设计模式之Command
- 设计模式笔记-观察者模式
- opencv中的svm实现细节[官方论坛]
- 【C语言疯狂讲义】(十一)C语言动态内存及结构体
- 20070420ser-0.9.6 patch
- LSM树由来、设计思想以及应用到HBase的索引
- Command设计模式3
- 百度地图API实例教程
- C++全局变量的声明和定义
- 解释器模式
- OTL使用string和自定义class读取和写入数据库示例
- Linux学习(二) wget命令的使用
- CF#277.5div2
- 第12周项目2-求N组数的最大公约数
- SQLite 的学习