40 #ifndef BINARYFUNCTION_HPP
41 #define BINARYFUNCTION_HPP 1
79 const VectorBase* vr);
184 template <
typename first_argument_type,
185 typename second_argument_type,
186 typename result_type,
189 :
public std::binary_function<first_argument_type,
190 second_argument_type,
221 const second_argument_type& right)
const
276 template <
typename first_argument_type,
277 typename second_argument_type,
278 typename result_type,
281 :
public std::binary_function<first_argument_type,
282 second_argument_type,
305 const second_argument_type& right)
const
363 template <
typename Functor,
364 class AttributeCopier = GeneralBinaryAttributeCopier,
365 template <
typename,
typename,
366 typename,
typename>
class FunctorWrapper
367 = BinaryNAPropagator>
404 template <
class Vout,
class Vl,
class Vr>
405 Vout*
apply(
const Vl* vl,
const Vr* vr)
const;
413 template <
int flag,
class Vout,
class Vl,
class Vr>
414 void mapElements(Vout* vout,
const Vl* vl,
const Vr* vr)
const;
444 template <
class AttributeCopier,
445 template <
typename,
typename,
446 typename,
typename>
class FunctorWrapper,
448 static BinaryFunction<Functor, AttributeCopier, FunctorWrapper>
449 makeBinaryFunction(Functor f)
451 return BinaryFunction<Functor, AttributeCopier, FunctorWrapper>(f);
476 template <
class AttributeCopier,
typename Functor>
477 static BinaryFunction<Functor, AttributeCopier>
478 makeBinaryFunction(Functor f)
480 return BinaryFunction<Functor, AttributeCopier>(f);
488 template <
typename Functor,
class AttributeCopier,
489 template <
typename,
typename,
490 typename,
typename>
class FunctorWrapper>
491 template <class Vout, class Vl, class Vr>
494 FunctorWrapper>::apply(
const Vl* vl,
498 std::size_t lsize = vl->size();
499 std::size_t rsize = vr->size();
501 if (lsize == 0 || rsize == 0) {
503 }
else if (lsize == rsize) {
505 mapElements<0>(ans.
get(), vl, vr);
506 }
else if (lsize > rsize) {
508 mapElements<1>(ans.
get(), vl, vr);
511 mapElements<-1>(ans.
get(), vl, vr);
513 AttributeCopier::copyAttributes(ans, vl, vr);
517 template <
typename Functor,
class AttributeCopier,
518 template <
typename,
typename,
519 typename,
typename>
class FunctorWrapper>
520 template <int flag, class Vout, class Vl, class Vr>
523 FunctorWrapper>::mapElements(Vout* vout,
527 typedef typename Vl::value_type Lelt;
528 typedef typename Vl::const_iterator Lit;
529 typedef typename Vr::value_type Relt;
530 typedef typename Vr::const_iterator Rit;
531 typedef typename Vout::value_type Oelt;
532 typedef typename Vout::iterator Oit;
533 FunctorWrapper<Lelt, Relt, Oelt, Functor> fwrapper(m_f);
534 Lit lit = vl->begin();
535 Lit lend = vl->end();
536 Rit rit = vr->begin();
537 Rit rend = vr->end();
538 Oit oend = vout->end();
539 for (Oit oit = vout->begin(); oit != oend; ++oit) {
540 *oit = fwrapper(*lit++, *rit++);
541 if (flag < 0 && lit == lend)
543 if (flag > 0 && rit == rend)
546 if ((flag < 0 && lit != vl->begin())
547 || (flag > 0 && rit != vr->begin()))
548 Rf_warning(_(
"longer object length is not"
549 " a multiple of shorter object length"));
553 #endif // BINARYFUNCTION_HPP