11#ifndef NDARRAY_DETAIL_BinaryOp_h_INCLUDED
12#define NDARRAY_DETAIL_BinaryOp_h_INCLUDED
22#include <boost/iterator/iterator_adaptor.hpp>
23#include <boost/iterator/zip_iterator.hpp>
24#include <boost/tuple/tuple.hpp>
36template <
typename Operand1,
typename Operand2,
typename BinaryFunction>
38 BinaryOpIterator<Operand1,Operand2,BinaryFunction>,
41 typename ExpressionTraits<Operand1>::Iterator,
42 typename ExpressionTraits<Operand2>::Iterator
45 typename ExpressionTraits< BinaryOpExpression<Operand1,Operand2,BinaryFunction> >::Value,
47 typename ExpressionTraits< BinaryOpExpression<Operand1,Operand2,BinaryFunction> >::Reference
59 BaseIterator1
const & baseIter1,
60 BaseIterator2
const & baseIter2,
61 BinaryFunction
const & functor
63 BinaryOpIterator::iterator_adaptor_(boost::make_tuple(baseIter1,baseIter2)),
67 BinaryOpIterator::iterator_adaptor_(other), _functor(other._functor) {}
70 friend class boost::iterator_core_access;
72 Reference dereference()
const {
75 this->base_reference()->
template get<0>(),
76 this->base_reference()->
template get<1>()
80 BinaryFunction _functor;
90template <
typename Operand1,
typename Operand2,
typename BinaryFunction,
int N>
102 Operand1
const & operand1,
103 Operand2
const & operand2,
104 BinaryFunction
const & functor
106 _operand1(operand1), _operand2(operand2), _functor(functor) {
107 NDARRAY_ASSERT(_operand1.getShape() == _operand2.getShape());
110 Reference operator[](Size n)
const {
111 return Reference(_operand1[n],_operand2[n],_functor);
114 Iterator begin()
const {
115 return Iterator(_operand1.begin(),_operand2.begin(),_functor);
118 Iterator end()
const {
119 return Iterator(_operand1.end(),_operand2.end(),_functor);
122 template <
int P> Size getSize()
const {
123 return _operand1.template getSize<P>();
126 Index getShape()
const {
127 return _operand1.getShape();
132 BinaryFunction _functor;
Definitions for ExpressionBase.
CRTP base class for all multidimensional expressions.
Definition ExpressionBase.h:40
boost::enable_if< typenameExpressionTraits< Scalar >::IsScalar, typenameUnaryFunction::result_type >::type vectorize(UnaryFunction const &functor, Scalar const &scalar)
Apply a non-mutating unary function object to a scalar.
Definition vectorize.h:73
Traits for expressions.
Definition ExpressionTraits.h:30
A fixed-size 1D array class.
Definition Vector.h:82
Code to apply arbitrary scalar functors to arrays.