l*****y 发帖数: 58 | 1 会自动聚合的操作符重载或宏
我们通常会有一些数据有比较复杂的结构.
data A,B,C,D,R ;
它们之间的运算仅仅是遍历所有数据成员,对每个数据成员进行运算。 那这种操作符
重载后的运算
R = A + B
实质上是
for_all_units {
R(id) = A(id) + B(id)
}
而 R = A + B - C
实质上是
for_all_units {
tmp(id) = A(id) + B(id)
}
for_all_units {
R(id) = tmp(id) - C(id)
}
当多个这样的运算符联立时,即使是用 -O2 之类的优化编译,遍历所有单元的操作会
重复多次。 有没有什么成熟的design pattern 或 可以自动合并的宏定义之类, 可以
自动实现将
R = A + B - C - D
编译成
for_all_units {
R(id) = A(id) + B(id) - C(id) - D(id)
}
谢谢 |
l******t 发帖数: 55733 | |
l*****y 发帖数: 58 | 3 谢谢,我本能的反应也是用 functional programming 来实现比较自然。
我对C++ 和functional programming 都了解不深。 那请问有没有现成的Monad in c++
之类的库可推荐呢?
如果没有,那用boost之类的functional programming功能来实现一个Monand有没有可
能?
【在 l******t 的大作中提到】 : Monad
|
p***o 发帖数: 1252 | 4 It's called expression template in C++. Boost has a lot of support or you
can use Eigen directly.
++
【在 l*****y 的大作中提到】 : 谢谢,我本能的反应也是用 functional programming 来实现比较自然。 : 我对C++ 和functional programming 都了解不深。 那请问有没有现成的Monad in c++ : 之类的库可推荐呢? : 如果没有,那用boost之类的functional programming功能来实现一个Monand有没有可 : 能?
|
d****i 发帖数: 4809 | 5 高手,第一次听说这个C++的feature
【在 p***o 的大作中提到】 : It's called expression template in C++. Boost has a lot of support or you : can use Eigen directly. : : ++
|
l*****y 发帖数: 58 | 6 啊,太感谢了。 看了一下你推荐的两个东西,感觉很合用。
【在 p***o 的大作中提到】 : It's called expression template in C++. Boost has a lot of support or you : can use Eigen directly. : : ++
|
b*******s 发帖数: 5216 | |
l*********s 发帖数: 5409 | |
b*******s 发帖数: 5216 | 9 check out Dr Dobb's to get these kinda topics
【在 l*********s 的大作中提到】 : 太谢谢了,第一次听说这个特性!
|
x****k 发帖数: 2932 | 10 学习了,多谢:-)
【在 p***o 的大作中提到】 : It's called expression template in C++. Boost has a lot of support or you : can use Eigen directly. : : ++
|
l*********s 发帖数: 5409 | 11 多谢!
【在 b*******s 的大作中提到】 : check out Dr Dobb's to get these kinda topics
|