ref in BlockBinaryOp
This commit is contained in:
parent
d8e62cc539
commit
776509e620
3 changed files with 17 additions and 15 deletions
|
@ -18,8 +18,10 @@ namespace MultiArrayHelper
|
|||
class BlockBinaryOp
|
||||
{
|
||||
public:
|
||||
BlockBinaryOp() = default;
|
||||
BlockResult<T> operator()(const BlockClass1& arg1, const BlockClass2& arg2);
|
||||
BlockBinaryOp(BlockResult<T>& mRes);
|
||||
void operator()(const BlockClass1& arg1, const BlockClass2& arg2);
|
||||
private:
|
||||
BlockResult<T>& mRes;
|
||||
};
|
||||
|
||||
template <typename T, class OpFunc, class BlockClass>
|
||||
|
@ -179,18 +181,18 @@ namespace MultiArrayHelper
|
|||
*********************/
|
||||
|
||||
template <typename T, class OpFunc, class BlockClass1, class BlockClass2>
|
||||
BlockResult<T>
|
||||
BlockBinaryOp<T,OpFunc,BlockClass1,BlockClass2>::operator()(const BlockClass1& arg1,
|
||||
const BlockClass2& arg2)
|
||||
BlockBinaryOp<T,OpFunc,BlockClass1,BlockClass2>::BlockBinaryOp(BlockResult<T>& res) : mRes(res) {}
|
||||
|
||||
template <typename T, class OpFunc, class BlockClass1, class BlockClass2>
|
||||
void BlockBinaryOp<T,OpFunc,BlockClass1,BlockClass2>::operator()(const BlockClass1& arg1,
|
||||
const BlockClass2& arg2)
|
||||
{
|
||||
static OpFunc f;
|
||||
BlockResult<T> res(arg1.size());
|
||||
assert(res.init() and arg1.init() and arg2.init());
|
||||
assert(mRes.init() and arg1.init() and arg2.init());
|
||||
assert(arg1.size() == arg2.size());
|
||||
for(size_t i = 0; i != arg1.size(); ++i){
|
||||
res[i] = f(arg1[i], arg2[i]);
|
||||
mRes[i] = f(arg1[i], arg2[i]);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
template <typename T, class OpFunc, class BlockClass>
|
||||
|
|
|
@ -472,7 +472,7 @@ namespace MultiArrayTools
|
|||
template <typename T, class OpFunction, class... Ops>
|
||||
const BlockResult<T>& Operation<T,OpFunction,Ops...>::get() const
|
||||
{
|
||||
mRes = std::move( PackNum<sizeof...(Ops)-1>::template unpackArgs<T,OpFunction>(mOps) );
|
||||
PackNum<sizeof...(Ops)-1>::template unpackArgs<T,OpFunction>(mRes, mOps);
|
||||
return mRes;
|
||||
}
|
||||
|
||||
|
|
|
@ -28,9 +28,9 @@ namespace MultiArrayHelper
|
|||
}
|
||||
|
||||
template <typename T, class Func, class ArgTuple, class... Args>
|
||||
static BlockResult<T> unpackArgs(const ArgTuple& tp, const Args&... args)
|
||||
static void unpackArgs(BlockResult<T>& res, const ArgTuple& tp, const Args&... args)
|
||||
{
|
||||
return PackNum<N-1>::template unpackArgs<T,Func>(tp, std::get<N>(tp).get(), args...);
|
||||
PackNum<N-1>::template unpackArgs<T,Func>(res, tp, std::get<N>(tp).get(), args...);
|
||||
}
|
||||
|
||||
template <typename... T>
|
||||
|
@ -46,12 +46,12 @@ namespace MultiArrayHelper
|
|||
{
|
||||
|
||||
template <typename T, class Func, class ArgTuple, class... Args>
|
||||
static BlockResult<T> unpackArgs(const ArgTuple& tp, const Args&... args)
|
||||
static void unpackArgs(BlockResult<T>& res, const ArgTuple& tp, const Args&... args)
|
||||
{
|
||||
static_assert(sizeof...(Args) == std::tuple_size<ArgTuple>::value-1,
|
||||
"inconsistent number of arguments");
|
||||
static BlockBinaryOp<T,Func,decltype(std::get<0>(tp).get()), decltype(args)...> f;
|
||||
return f(std::get<0>(tp).get(), args...);
|
||||
BlockBinaryOp<T,Func,decltype(std::get<0>(tp).get()), decltype(args)...> f(res);
|
||||
f(std::get<0>(tp).get(), args...);
|
||||
}
|
||||
|
||||
template <class... Ops>
|
||||
|
|
Loading…
Reference in a new issue