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
|
class BlockBinaryOp
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
BlockBinaryOp() = default;
|
BlockBinaryOp(BlockResult<T>& mRes);
|
||||||
BlockResult<T> operator()(const BlockClass1& arg1, const BlockClass2& arg2);
|
void operator()(const BlockClass1& arg1, const BlockClass2& arg2);
|
||||||
|
private:
|
||||||
|
BlockResult<T>& mRes;
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename T, class OpFunc, class BlockClass>
|
template <typename T, class OpFunc, class BlockClass>
|
||||||
|
@ -179,18 +181,18 @@ namespace MultiArrayHelper
|
||||||
*********************/
|
*********************/
|
||||||
|
|
||||||
template <typename T, class OpFunc, class BlockClass1, class BlockClass2>
|
template <typename T, class OpFunc, class BlockClass1, class BlockClass2>
|
||||||
BlockResult<T>
|
BlockBinaryOp<T,OpFunc,BlockClass1,BlockClass2>::BlockBinaryOp(BlockResult<T>& res) : mRes(res) {}
|
||||||
BlockBinaryOp<T,OpFunc,BlockClass1,BlockClass2>::operator()(const BlockClass1& arg1,
|
|
||||||
const BlockClass2& arg2)
|
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;
|
static OpFunc f;
|
||||||
BlockResult<T> res(arg1.size());
|
assert(mRes.init() and arg1.init() and arg2.init());
|
||||||
assert(res.init() and arg1.init() and arg2.init());
|
|
||||||
assert(arg1.size() == arg2.size());
|
assert(arg1.size() == arg2.size());
|
||||||
for(size_t i = 0; i != arg1.size(); ++i){
|
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>
|
template <typename T, class OpFunc, class BlockClass>
|
||||||
|
|
|
@ -472,7 +472,7 @@ namespace MultiArrayTools
|
||||||
template <typename T, class OpFunction, class... Ops>
|
template <typename T, class OpFunction, class... Ops>
|
||||||
const BlockResult<T>& Operation<T,OpFunction,Ops...>::get() const
|
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;
|
return mRes;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -28,9 +28,9 @@ namespace MultiArrayHelper
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T, class Func, class ArgTuple, class... Args>
|
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>
|
template <typename... T>
|
||||||
|
@ -46,12 +46,12 @@ namespace MultiArrayHelper
|
||||||
{
|
{
|
||||||
|
|
||||||
template <typename T, class Func, class ArgTuple, class... Args>
|
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,
|
static_assert(sizeof...(Args) == std::tuple_size<ArgTuple>::value-1,
|
||||||
"inconsistent number of arguments");
|
"inconsistent number of arguments");
|
||||||
static BlockBinaryOp<T,Func,decltype(std::get<0>(tp).get()), decltype(args)...> f;
|
BlockBinaryOp<T,Func,decltype(std::get<0>(tp).get()), decltype(args)...> f(res);
|
||||||
return f(std::get<0>(tp).get(), args...);
|
f(std::get<0>(tp).get(), args...);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class... Ops>
|
template <class... Ops>
|
||||||
|
|
Loading…
Reference in a new issue