Into

Modules

Documentation

classPiiArithmeticBase

#include <PiiArithmeticBase.h>

A template that adds support for arithmetic operators for any data structure that can be iterated over.

Inherited by PiiVector< double, 3 >

Description

This class is intended to be used with the CRTP (curiously recurring template pattern). The derived class must have have stl-style begin() and end() functions for iterators. Information about the element type itself is provided through the helper type Traits. The required type definitions are shown in the example below.

 // Forward declaration for the rebinder in MyTraits.
 template <class T> class MyClass;

 template <class T> struct MyTraits
 {
   // The element type
   typedef T Type;
   // Iterator type
   typedef T* Iterator;
   // Const iterator type
   typedef const T* ConstIterator;
   // Rebinder creates a MyClass types with varying content types.
   template <class U> struct Rebind { typedef MyClass<U> Type; };
 };

 template <class T> class MyClass : public PiiArithmeticBase<MyClass<T>, MyTraits<T> >
 {
 public:
   typedef PiiArithmeticBase<MyClass<T>, MyTraits<T> > BaseType;

   // Required iterator functions
   typename BaseType::ConstIterator begin() const { return _pData; }   // const iterator to the beginning
   typename BaseType::Iterator begin() { return _pData; }              // iterator to the beginning
   typename BaseType::ConstIterator end() const { return _pData + 5; } // const iterator to the end
   typename BaseType::Iterator end() { return _pData + 5; }            // const iterator to the end

   // The following aren't necessarily required if your class is a POD type

   // Standard onstructors (implementations may vary)
   MyClass() { BaseType::operator=(0); }
   MyClass(const MyClass& other) { *this = other; }

   // Copy assignment isn't inherited...
   MyClass& operator= (const MyClass& other) { return BaseType::operator=(other); }

 private:
   T _pData[5];
 };

 // Now, you can do this:
 MyClass a, b;
 MyClass c = a + b;

The length of the vector/array is assumed to be fixed. That is, all instances of the derived class should hold the same amount of elements. If this is not the case, your program will (in the best case) crash.

Public types

typedef Traits::ConstIterator

Stl-style const iterator.

typedef Traits::ConstIterator

Qt-style const iterator.

typedef Traits::Iterator

Stl-style iterator.

typedef Traits::Iterator

Qt-style iterator.

typedef Traits::Type

A shorthand for the content type of the derived class.

typedef Traits

A typedef for the traits template parameter.

Public member functions

template<class Operation>
Traits::template Rebind< typename Operation::result_type >::Type
(
  • Operation op
  • const typename Traits::template Rebind< typename Operation::second_argument_type >::Type & other
)

Apply a binary function to all elements using the corresponding elements in this and other as function parameters.

template<class Operation>
void
(
  • Operation op
  • const typename Traits::template Rebind< typename Operation::second_argument_type >::Type & other
)

Apply a binary function to all elements using the corresponding elements in this and other as function parameters.

template<class Operation>
Traits::template Rebind< typename Operation::result_type >::Type
(
  • Operation op
  • typename Operation::second_argument_type value
)

Apply a binary function to all elements using value as the second function parameter.

template<class Operation>
void
(
  • Operation op
  • typename Operation::second_argument_type value
)

Apply a binary function to all elements using value as the second function parameter.

Returns an stl-style const iterator to the beginning of data.

Returns an stl-style const iterator to the end of data.

bool
(
  • const Derived & other
)

Returns false if all elements in this and other are equal, true otherwise.

Derived
(
  • const Derived & other
)

Multiply corresponding elements by each other.

Derived
(
  • T value
)

Multiply all elements by value.

void
(
  • T value
)

Multiply all elements by value.

void
(
  • const Derived & other
)

Multiply corresponding elements in this by other.

Derived
(
  • T value
)

Add value to all elements.

Derived
(
  • const Derived & other
)

Sum corresponding elements.

void
(
  • const Derived & other
)

Add corresponding elements in other to this.

void
(
  • T value
)

Add value to all elements.

Derived
(
  • const Derived & other
)

Subtract corresponding elements from each other.

Derived

Create a negation of all elements.

Derived
(
  • T value
)

Subtract value from all elements.

void
(
  • const Derived & other
)

Subtract corresponding elements in other from this.

void
(
  • T value
)

Subtract value from all elements.

Derived
(
  • const Derived & other
)

Divide corresponding elements by each other.

Derived
(
  • T value
)

Divide all elements by value.

void
(
  • const Derived & other
)

Divide corresponding elements in this by other.

void
(
  • T value
)

Divide all elements by value.

Derived &
(
  • const Derived & other
)

Assign the values in other to this.

Derived &
(
  • T value
)

Set all elements to value.

bool
(
  • const Derived & other
)

Returns true if all elements in this and other are equal, false otherwise.

template<class Operation>
Traits::template Rebind< typename Operation::result_type >::Type
(
  • Operation op
)

Apply a unary function to all elements.

template<class Operation>
void
(
  • Operation op
)

Apply a unary function to all elements.

Function details

  • template<class Operation>

    Traits::template Rebind< typename Operation::result_type >::Type binaryOp

    (
    • Operation op
    • const typename Traits::template Rebind< typename Operation::second_argument_type >::Type & other
    )
    [inline]

    Apply a binary function to all elements using the corresponding elements in this and other as function parameters.

    Return a new object.

  • template<class Operation>

    void binaryOp

    (
    • Operation op
    • const typename Traits::template Rebind< typename Operation::second_argument_type >::Type & other
    )
    [inline]

    Apply a binary function to all elements using the corresponding elements in this and other as function parameters.

    Modify elements in place.

  • template<class Operation>

    Traits::template Rebind< typename Operation::result_type >::Type binaryOp

    (
    • Operation op
    • typename Operation::second_argument_type value
    )
    [inline]

    Apply a binary function to all elements using value as the second function parameter.

    Return a new object.

  • template<class Operation>

    void binaryOp

    (
    • Operation op
    • typename Operation::second_argument_type value
    )
    [inline]

    Apply a binary function to all elements using value as the second function parameter.

    Modify elements in place.

  • const_iterator constBegin

    ()
    [inline]

    Returns an stl-style const iterator to the beginning of data.

  • const_iterator constEnd

    ()
    [inline]

    Returns an stl-style const iterator to the end of data.

  • bool operator!=

    (
    • const Derived & other
    )
    [inline]

    Returns false if all elements in this and other are equal, true otherwise.

  • Derived operator*

    (
    • const Derived & other
    )
    [inline]

    Multiply corresponding elements by each other.

  • Derived operator*

    (
    • T value
    )
    [inline]

    Multiply all elements by value.

  • void operator*=

    (
    • T value
    )
    [inline]

    Multiply all elements by value.

  • void operator*=

    (
    • const Derived & other
    )
    [inline]

    Multiply corresponding elements in this by other.

  • Derived operator+

    (
    • T value
    )
    [inline]

    Add value to all elements.

  • Derived operator+

    (
    • const Derived & other
    )
    [inline]

    Sum corresponding elements.

  • void operator+=

    (
    • const Derived & other
    )
    [inline]

    Add corresponding elements in other to this.

  • void operator+=

    (
    • T value
    )
    [inline]

    Add value to all elements.

  • Derived operator-

    (
    • const Derived & other
    )
    [inline]

    Subtract corresponding elements from each other.

  • Derived operator-

    ()
    [inline]

    Create a negation of all elements.

  • Derived operator-

    (
    • T value
    )
    [inline]

    Subtract value from all elements.

  • void operator-=

    (
    • const Derived & other
    )
    [inline]

    Subtract corresponding elements in other from this.

  • void operator-=

    (
    • T value
    )
    [inline]

    Subtract value from all elements.

  • Derived operator/

    (
    • const Derived & other
    )
    [inline]

    Divide corresponding elements by each other.

  • Derived operator/

    (
    • T value
    )
    [inline]

    Divide all elements by value.

  • void operator/=

    (
    • const Derived & other
    )
    [inline]

    Divide corresponding elements in this by other.

  • void operator/=

    (
    • T value
    )
    [inline]

    Divide all elements by value.

  • Derived & operator=

    (
    • const Derived & other
    )
    [inline]

    Assign the values in other to this.

  • Derived & operator=

    (
    • T value
    )
    [inline]

    Set all elements to value.

  • bool operator==

    (
    • const Derived & other
    )
    [inline]

    Returns true if all elements in this and other are equal, false otherwise.

  • template<class Operation>

    Traits::template Rebind< typename Operation::result_type >::Type unaryOp

    (
    • Operation op
    )
    [inline]

    Apply a unary function to all elements.

    Return a new object.

  • template<class Operation>

    void unaryOp

    (
    • Operation op
    )
    [inline]

    Apply a unary function to all elements.

    Modify the elements in place.

Notes (0)

Add a note

Not a single note added yet. Be the first, add yours.