Templatious
 All Classes Functions Pages
Classes | Static Public Member Functions | Friends | List of all members
templatious::StaticManipulator Struct Reference

#include <StaticManipulator.hpp>

Static Public Member Functions

template<class T , bool passIndex = false, template< class...> class ResCollection = std::vector, template< class > class Allocator = std::allocator, class U , class... Args>
static auto map (U &&fn, Args &&...args) -> decltype(templatious::adapters::CollectionMaker< T, ResCollection, Allocator >::make(0))
 
template<bool passIndex = false, class U , class... Args>
static void traverse (U &&fn, Args &&...args)
 
template<bool passIndex = false, class U , class... Args>
static long quadro (U &&fn, Args &&...args)
 
template<class T , class V , class... Col>
static void set (T &&t, V &v, Col &...args)
 
template<class T , class V >
static void set (T &&t, V &col)
 
template<bool ignoreBooleanReturn = false, class T , class... V>
static long callEach (T &&f, V &&...args)
 
template<bool ignoreBooleanReturn = false, class T , class... V>
static long forEach (T &&f, V &&...args)
 
template<class RetVal = double, class... V>
static RetVal sum (V &&...args)
 
template<class RetVal = double, class Fn , class... V>
static RetVal sumS (Fn &&f, V &&...args)
 
template<class RetVal = double, class... V>
static RetVal avg (V &&...args)
 
template<class RetVal = double, class Fn , class... V>
static RetVal avgS (Fn &&f, V &&...args)
 
template<class RetVal = double, class... V>
static RetVal min (V &&...args)
 
template<class RetVal = double, class... V>
static RetVal max (V &&...args)
 
template<class RetVal = double, class CompFunc , class... V>
static RetVal maxS (CompFunc &&cf, V &&...args)
 
template<class T , class F , class... Args>
static T fold (T &&start, F &&f, Args &&...args)
 
template<class T , class... Args>
static long distribute (T &&t, Args &&...args)
 
template<class T , class... Args>
static long distributeR (T &&t, Args &&...args)
 
template<bool ignoreBooleanReturn = false, class Func , class T , class... Args>
static long distributeSpecial (Func &&f, T &&t, Args &&...args)
 
template<class F , class A , class B >
static bool areCollectionsEqualS (const F &f, const A &a, const B &b)
 
template<class F , class A , class B , class... Tail>
static bool areCollectionsEqualS (const F &f, const A &a, const B &b, const Tail &...tail)
 
template<class... Args>
static bool areCollectionsEqual (const Args &...args)
 
template<class F , class... Args>
static bool forAll (F &&f, Args &&...args)
 
template<class F , class... Args>
static bool forAllP (F &&f, Args &&...args)
 
template<class F , class... Args>
static bool exists (F &&f, Args &&...args)
 
template<class F , class... Args>
static bool existsP (F &&f, Args &&...args)
 
template<bool saveIdx = false, template< class...> class Collection = std::vector, template< class > class Alloc = std::allocator, class T >
static auto iterDump (T &&t) -> decltype(templatious::detail::CollectionIterDumper< decltype(std::forward< T >(t)), saveIdx, Collection, Alloc >::dumpIter(std::forward< T >(t)))
 
template<class T >
static void sort (T &&t)
 
template<class T , class Comparator >
static void sortS (T &&t, Comparator &&c)
 
template<class T , class Comparator >
static bool isSortedS (T &&t, Comparator &&c)
 
template<class T >
static bool isSorted (T &&t)
 

Friends

template<int var, template< class > class Decider>
struct detail::CallHandler
 

Detailed Description

A class which holds static methods that mainly have to do with element/collection manipulation.

Member Function Documentation

template<class... Args>
static bool templatious::StaticManipulator::areCollectionsEqual ( const Args &...  args)
inlinestatic

Check if passed collections contain identical elements using the default '==' operator.

Parameters
[in]argsArgument collections to check.

Example:

auto s1 = SF::seqL(3); // {0,1,2}
auto s2 = SF::seqI(1,3); // {1,2,3}
std::vector<int> v;
SA::add(v,1,2,3);
assert( !SM::areCollectionsEqual(s1,s2) );
assert( !SM::areCollectionsEqual(v ,s1) );
assert( SM::areCollectionsEqual(v ,s2) );
assert( SM::areCollectionsEqual(v ,s2,SF::seqI(1,3)) );
template<class F , class A , class B >
static bool templatious::StaticManipulator::areCollectionsEqualS ( const F &  f,
const A &  a,
const B &  b 
)
inlinestatic

Function that checks whether collections passed contain identical elements. Functor specifies the way of comparison and should return true when elements are equal. This is intended to use for collections only.

Parameters
[in]fFunction to be used when comparing.
[in]aFirst collection to compare.
[in]bSecond collection to compare.
Note
If collections are of different sizes they are always not equal, even if comparator always returns true.

Example:

std::vector<int> v;
SA::add(v,1,2,3);
auto nrm = [](int a,int b) { return a == b; };
auto alw = [](int a,int b) { return true; };
assert( SM::areCollectionsEqualS(nrm,v,SF::seqI(1,3)) );
assert( !SM::areCollectionsEqualS(nrm,v,SF::seqI(1,4)) );
assert( SM::areCollectionsEqualS(alw,v,SF::seqI(2,4)) );
assert( !SM::areCollectionsEqualS(alw,v,SF::seqI(2,5)) );
template<class F , class A , class B , class... Tail>
static bool templatious::StaticManipulator::areCollectionsEqualS ( const F &  f,
const A &  a,
const B &  b,
const Tail &...  tail 
)
inlinestatic

Same as the two element version but for more collections.

Parameters
[in]fFunction to be used when comparing.
[in]aFirst collection to compare.
[in]bSecond collection to compare.
Note
If collections are of different sizes they are always not equal, even if comparator always returns true.

Example:

std::vector<int> v;
SA::add(v,1,2,3);
auto nrm = [](int a,int b) { return a == b; };
auto alw = [](int a,int b) { return true; };
assert( SM::areCollectionsEqualS(nrm,v,SF::seqI(1,3)) );
assert( !SM::areCollectionsEqualS(nrm,v,SF::seqI(1,4)) );
assert( SM::areCollectionsEqualS(alw,v,SF::seqI(2,4)) );
assert( !SM::areCollectionsEqualS(alw,v,SF::seqI(2,5)) );
template<class RetVal = double, class... V>
static RetVal templatious::StaticManipulator::avg ( V &&...  args)
inlinestatic

Average of values. Returns numeric average of elements passed.

Parameters
[in]argsElements to sum. Can process packs, collections and single values.
[in]RetValReturn type. Defaults to double.

Example:

int a,b,c;
a = 1; b = 2; c = 3;
auto p = SF::pack(a,b,c);
std::vector<int> v;
SA::add(v,5,6,7);
double avg = SM::avg(p,4,v);
assert( avg == 4 );
template<class RetVal = double, class Fn , class... V>
static RetVal templatious::StaticManipulator::avgS ( Fn &&  f,
V &&...  args 
)
inlinestatic

Average of values using special function. Returns numeric average of elements passed.

Parameters
[in]fFunction to be used on every element before summing an element to the result.
[in]argsElements to sum. Can process packs, collections and single values.
[in]RetValReturn type. Defaults to double.

Example:

int a,b,c;
a = 1; b = 2; c = 3;
auto p = SF::pack(a,b,c);
std::vector<int> v;
SA::add(v,5,6,7);
auto trFunc = [](int i) { return 2*i; };
double avg = SM::avgS(trFunc,p,4,v);
assert( avg == 8 );
template<bool ignoreBooleanReturn = false, class T , class... V>
static long templatious::StaticManipulator::callEach ( T &&  f,
V &&...  args 
)
inlinestatic

Generic call each function for multiple elements (packs are considered composite)

Parameters
[in]fFunction to call on each argument. Function may return false to stop traversal (will work if ignoreBooleanReturn is set to false).
[in,out]argsArguments to call function on. Can be variables or packs. Packs are processed recursively calling function on each element of the pack.
[in]ignoreBooleanReturnValue which determines whether to interpret function return value (if it happens to be boolean) as a signal to stop traversal. If set to true boolean return value is ignored and traversal always iterates through every element.

Example:

auto p = SF::pack(1,2,3);
std::stringstream ss;
auto prnt = [&](int i) { ss << i; };
SM::callEach(prnt,7,p,7);
assert( ss.str() == "71237" );
std::vector<int> v(3);
// ILLEGAL, collections are not
// processed by callEach (see forEach)
//SM::callEach(prnt,v);
template<class T , class... Args>
static long templatious::StaticManipulator::distribute ( T &&  t,
Args &&...  args 
)
inlinestatic

Distribute function. Distributes from pack or collection over other collections/packs/variables in a linear fashion. Returns how many distributions were made.

Parameters
[in]tEntity to distribute from. Can be pack or collection.
[out]argsArguments to distribute over. Can be packs, collections or single variables.

Example:

int a,b,c;
int p1,p2,p3;
auto p = SF::pack(p1,p2,p3);
std::vector<int> v(3);
auto s = SF::seqL(12);
int count = SM::distribute(s,a,b,c,p,v);
assert( count == 9 );
assert( a == 0 );
assert( b == 1 );
assert( c == 2 );
assert( p1 == 3 );
assert( p2 == 4 );
assert( p3 == 5 );
assert( v[0] == 6 );
assert( v[1] == 7 );
assert( v[2] == 8 );
template<class T , class... Args>
static long templatious::StaticManipulator::distributeR ( T &&  t,
Args &&...  args 
)
inlinestatic

Reverse distribute function. Distributes over pack or collection from other collections/packs/variables in a linear fashion. Returns how many distributions were made.

Parameters
[out]tEntity to distribute to. Can be pack or collection.
[in]argsArguments to distribute from. Can be packs, collections or single variables.

Example:

std::vector<int> out(9);
int a,b,c;
a = 0; b = 1; c = 2;
auto p = SF::pack(3,4,5);
auto s = SF::seqI(6,8);
int count = SM::distributeR(out,a,b,c,p,s);
assert( count == 9 );
assert( out[0] == 0 );
assert( out[1] == 1 );
assert( out[2] == 2 );
assert( out[3] == 3 );
assert( out[4] == 4 );
assert( out[5] == 5 );
assert( out[6] == 6 );
assert( out[7] == 7 );
assert( out[8] == 8 );
template<bool ignoreBooleanReturn = false, class Func , class T , class... Args>
static long templatious::StaticManipulator::distributeSpecial ( Func &&  f,
T &&  t,
Args &&...  args 
)
inlinestatic

Distribute using special function. Returns how many distributions were made.

Parameters
[in]fFunction for use in distribution. should take two arguments. May return boolean value false to stop distribution at any time (ignoreBooleanReturn has to be set to false).
[in,out]tFirst part distribution entity, first argument for the function f. Can be pack or collection.
[in,out]argsSecond part of distribution entity. Second argument for the function f. Can be packs, collections or single variables.
[in]ignoreBooleanReturnValue to determine whether function return value (if it happens to be boolean) should stop traversal if it returns false. Defaults to false.

Example:

auto procFunc = [](int from,int& to)
{ to = 2*from; };
int a,b,c;
int count = SM::distributeSpecial(
procFunc,SF::seqI(77,100),a,b,c);
assert( count == 3 );
assert( a == 2*77 );
assert( b == 2*78 );
assert( c == 2*79 );
template<class F , class... Args>
static bool templatious::StaticManipulator::exists ( F &&  f,
Args &&...  args 
)
inlinestatic

Check if at least one element matches given predicate function. Works with collections or single variables. Collections are treated as composite.

Parameters
[in]fFunction that should return true if element satisfies condition.
[in]argsArgument collections/variables to check.

Example:

auto pred = [](int i) { return i > 5; };
std::vector<int> v;
SA::add(v,4,5);
assert( !SM::exists(pred,v) );
assert( SM::exists(pred,v,6) );
SA::add(v,6);
assert( SM::exists(pred,v) );
template<class F , class... Args>
static bool templatious::StaticManipulator::existsP ( F &&  f,
Args &&...  args 
)
inlinestatic

Check if at least one element matches given predicate function. Works with packs or single variables. Packs are treated as composite.

Parameters
[in]fFunction that should return true if element satisfies condition.
[in]argsArgument collections/variables to check.

Example:

auto pred = [](int i) { return i > 5; };
auto p = SF::pack(4,5);
assert( !SM::existsP(pred,p) );
assert( SM::existsP(pred,p,6) );
auto p2 = SF::pack(4,5,6);
assert( SM::existsP(pred,p2) );
template<class T , class F , class... Args>
static T templatious::StaticManipulator::fold ( T &&  start,
F &&  f,
Args &&...  args 
)
inlinestatic

Fold function. Folds multiple values to single.

Parameters
[in]startStarting value. Should be copy constructable.
[in]fFunction to apply in every iteration. Should take in two values as arguments, the accumulator value and the value processed through every iteration of a sequence. Should return newly calculated value.
[in]argsArguments to traverse. Can process packs, collections and single variables.

Example:

auto mulFunc = [](int curr,int next)
{ return curr * next; };
int res = SM::fold(1,mulFunc,2,3,4,5,6,7);
assert( res == 5040 );
template<class F , class... Args>
static bool templatious::StaticManipulator::forAll ( F &&  f,
Args &&...  args 
)
inlinestatic

Check if all elements match given predicate function. Works with collections or single variables. Collections are treated as composite.

Parameters
[in]fFunction that should return true if element satisfies condition.
[in]argsArgument collections/variables to check.

Example:

auto pred = [](int i) { return i > 5; };
std::vector<int> v;
SA::add(v,6,7);
assert( SM::forAll(pred,v) );
assert( !SM::forAll(pred,v,5) );
SA::add(v,5);
assert( !SM::forAll(pred,v) );
template<class F , class... Args>
static bool templatious::StaticManipulator::forAllP ( F &&  f,
Args &&...  args 
)
inlinestatic

Check if all elements match given predicate function. Works with packs or single variables. Packs are treated as composite.

Parameters
[in]fFunction that should return true if element satisfies condition.
[in]argsArgument collections/variables to check.

Example:

auto pred = [](int i) { return i > 5; };
auto p = SF::pack(6,7);
assert( SM::forAllP(pred,p) );
assert( !SM::forAllP(pred,p,5) );
auto p2 = SF::pack(6,7,5);
assert( !SM::forAllP(pred,p2) );
template<bool ignoreBooleanReturn = false, class T , class... V>
static long templatious::StaticManipulator::forEach ( T &&  f,
V &&...  args 
)
inlinestatic

Generic foreach function for multiple elements (collections are considered composite)

Parameters
[in]fFunction to call on each argument. Function may return false to stop traversal (will work if ignoreBooleanReturn is set to false).
[in,out]argsArguments to call function on. Can be variables or collections. Collections are processed element by element.
[in]ignoreBooleanReturnValue which determines whether to interpret function return value (if it happens to be boolean) as a signal to stop traversal. If set to true boolean return value is ignored and traversal always iterates through every element.

Example:

std::vector<int> v;
SA::add(v,1,2,3);
std::stringstream ss;
auto prnt = [&](int i) { ss << i; };
SM::forEach(prnt,7,v,7);
assert( ss.str() == "71237" );
auto p = SF::pack(1,2,3);
// ILLEGAL, packs are not
// processed by forEach (see callEach)
//SM::forEach(prnt,p);
template<class T >
static bool templatious::StaticManipulator::isSorted ( T &&  t)
inlinestatic

Check if collection is sorted using default comparator.

Parameters
[in]tCollection to check.

Example:

std::vector<int> sorted;
std::vector<int> notSorted;
SA::add(sorted,1,2,3);
SA::add(notSorted,1,3,2);
assert( SM::isSorted(sorted) );
assert( !SM::isSorted(notSorted) );
template<class T , class Comparator >
static bool templatious::StaticManipulator::isSortedS ( T &&  t,
Comparator &&  c 
)
inlinestatic

Check if collection is sorted using special comparator.

Parameters
[in]tCollection to check.
[in]cComparator to use. Function which returns true for f(a,b) if a < b.

Example:

auto revComp = [](int a,int b) { return a > b; };
std::vector<int> sortedRev;
std::vector<int> notSorted;
SA::add(sortedRev,3,2,1);
SA::add(notSorted,1,3,2);
assert( SM::isSortedS(sortedRev,revComp) );
assert( !SM::isSortedS(notSorted,revComp) );
template<bool saveIdx = false, template< class...> class Collection = std::vector, template< class > class Alloc = std::allocator, class T >
static auto templatious::StaticManipulator::iterDump ( T &&  t) -> decltype( templatious::detail::CollectionIterDumper< decltype(std::forward<T>(t)), saveIdx, Collection,Alloc >::dumpIter(std::forward<T>(t)) )
inlinestatic

Dump iterators of collection into one collection. Useful for operations like quick sorting of collections without random access iterators, like std::list.

Parameters
[in]tCollection to dump iterators from.

Example:

std::list<int> l;
SA::add(l,1,2,3);
auto d = SM::iterDump(l);
// Type of d: std::vector<
// templatious::VectoratorItem<
// std::vector<int>::iterator, false
// >
// >
SM::set(7,d);
// now all items of l have 3 for their value
assert( SA::getByIndex(l,0) == 7 );
assert( SA::getByIndex(l,1) == 7 );
assert( SA::getByIndex(l,2) == 7 );
template<class T , bool passIndex = false, template< class...> class ResCollection = std::vector, template< class > class Allocator = std::allocator, class U , class... Args>
static auto templatious::StaticManipulator::map ( U &&  fn,
Args &&...  args 
) -> decltype( templatious::adapters::CollectionMaker< T,ResCollection,Allocator>:: make(0) )
inlinestatic

Map function. Accepts function which takes n amount of args from n collections which are traversed linearly and new collection is made containing elements which are results of specified function.

Parameters
[in]fnFunction to use when mapping
[in]argsArguments, collections to traverse in linear way. Assertion is made that they all contain same amount of elements.
[out]Tthe collection element type to be returned. Inferred by default
[in]passIndexFlag wether to pass current iteration index while traversing. Index is passed first to function. Defaults to false.
[out]ResCollectionCollection type to return from this function. Defaults to std::vector. Needed amount of memory for collection is preallocated if applicable.
[out]AllocatorAllocator to use for new collection if applicable. Is ignored if collection is allocator indifferent.

Example:

auto s1 = SF::seqL(10); // {0..9}
auto s2 = SF::seqL(10,20); // {10..19}
auto func = [](int a,int b) { return a * b; };
auto out = SM::map<int>(func,s1,s2);
// type of out: std::vector<int>
// out contains:
// {0,11,24,39,56,75,96,119,144,171}

Example using prebuilt passIndex variable:

auto s = SF::seqL(10,20); // {10..19}
auto func = [](int i,int b) { return i * b; };
// passing only one sequence, first lambda
// argument is iteration number 0..n
auto out = SM::map<int,true>(func,s);
// type of out: std::vector<int>
// out contains:
// {0,11,24,39,56,75,96,119,144,171}
template<class RetVal = double, class... V>
static RetVal templatious::StaticManipulator::max ( V &&...  args)
inlinestatic

Maximum of values. Returns numeric maximum of elements passed.

Parameters
[in]argsElements to traverse. Can process packs, collections and single values.
[in]RetValReturn type. Defaults to double. May be specified to return references.

Example:

int a = 2;
int b = 3;
auto p = SF::pack(4,5,6);
auto s = SF::seqL(6,8);
int max = SM::max<int>(a,b,p,s,-1);
assert(max == 7);
template<class RetVal = double, class CompFunc , class... V>
static RetVal templatious::StaticManipulator::maxS ( CompFunc &&  cf,
V &&...  args 
)
inlinestatic

Maximum of values using a special function. Returns numeric user specified maximum according to the user specified comparison of elements passed.

Parameters
[in]cfFunction to be used for comparison. Should take two parameters for comparison. For instance, if maximum is wanted the function is called like cf(a,b) and it should return true if a > b.
[in]argsElements to traverse. Can process packs, collections and single values.
[in]RetValReturn type. Defaults to double. May be specified to return references.

Example:

struct MyPod {
MyPod(int a,int b) :
_a(a), _b(b) {}
int _a;
int _b;
};
MyPod a(7,8);
std::vector<MyPod> v;
SA::add(v,MyPod(1,2),MyPod(3,4),MyPod(5,6));
MyPod& mp = SM::maxS<MyPod&>(
[](const MyPod& a,const MyPod& b) {
return a._a * a._b > b._a * b._b;
},
v,a
);
assert(&a == &mp);
template<class RetVal = double, class... V>
static RetVal templatious::StaticManipulator::min ( V &&...  args)
inlinestatic

Minimum of values. Returns numeric minimum of elements passed.

Parameters
[in]argsElements to traverse. Can process packs, collections and single values.
[in]RetValReturn type. Defaults to double. May be specified to return references.

Example:

int a = 2;
int b = 3;
auto p = SF::pack(4,5,6);
auto s = SF::seqL(6,8);
int min = SM::min<int>(a,b,p,s,-1);
assert(min == -1);
template<bool passIndex = false, class U , class... Args>
static long templatious::StaticManipulator::quadro ( U &&  fn,
Args &&...  args 
)
inlinestatic

Quadratic traversal function. ***Removing or adding elements to traversed collections during traversal is undefined behaviour***. Example:

std::vector<int> v;
SA::add(v,1,2,3);
SM::quadro(
[](int i,int j,int k) {
std::cout << i << j << k << std::endl;
},
v,v,v
);
// Should output:
// 1,1,1
// 1,1,2
// 1,1,3
// 1,2,1
// 1,2,2
// 1,2,3
// ...
// 3,3,2
// 3,3,3
Parameters
[in]fnFunction to be used on each iteration. Should take in args collection value types.
[in]argsCollection arguments to be traversed in quadratic manner.
[in]passIndexSets whether to pass traversal index (starting with 0) to function. If passed it is passed first. Defaults to false.
template<class T , class V , class... Col>
static void templatious::StaticManipulator::set ( T &&  t,
V &  v,
Col &...  args 
)
inlinestatic

Variadic set function overload.

Parameters
[in]tValue used for setting.
[in,out]vOne entity to set. Can be collection, pack or a single variable.
[in,out]argsRest of the entities to use set function on.

Example:

int a,b,c;
std::vector<int> v(3);
int p1,p2,p3;
auto p = SF::pack(p1,p2,p3);
SM::set(7,a,b,c,v,p);
assert( a == 7 );
assert( b == 7 );
assert( c == 7 );
assert( v[0] == 7 );
assert( v[1] == 7 );
assert( v[2] == 7 );
assert( p1 == 7 );
assert( p2 == 7 );
assert( p3 == 7 );
template<class T , class V >
static void templatious::StaticManipulator::set ( T &&  t,
V &  col 
)
inlinestatic

Value set function.

Parameters
[in]tValue used for setting
[in,out]vEntity to set. Can be collection, pack or a single variable.

Example:

int a,b,c;
std::vector<int> v(3);
auto p = SF::pack(1,2,3);
SM::set(7,a,b,c,v,p);
// a,b,c = 7
// v[0],v[1],v[2] = 7
// p.get<0>(),p.get<1>().p.get<2>() = 7
template<class T >
static void templatious::StaticManipulator::sort ( T &&  t)
inlinestatic

Sort elements in the collection in ascending order. Collection has to be mutable. If collection iterator has random_access_iterator_tag then simply calls std::sort on collection. If iterator doesn't have random access iterator tag then all iterators are dumped to collection with random access iterator tag and are sorted then.

Parameters
[in]tCollection to be sorted.

Example:

std::list<int> l;
SA::add(l,7,6,5,4,3,2,1);
SM::sort(l);
std::vector<int> expected;
SA::add(expected,1,2,3,4,5,6,7);
assert( SM::areCollectionsEqual(l,expected) );
assert( SM::isSorted(l) );
template<class T , class Comparator >
static void templatious::StaticManipulator::sortS ( T &&  t,
Comparator &&  c 
)
inlinestatic

Sort elements in the collection using special comparator function which returns true for f(a,b) if a < b by default. Collection has to be mutable. If collection iterator has random_access_iterator_tag then simply calls std::sort on collection. If iterator doesn't have random access iterator tag then all iterators are dumped to collection with random access iterator tag and are sorted then.

Parameters
[in]tCollection to be sorted.
[in]cComparator function to be used. should take two parameters by default. If returns true on f(a,b) when a < b collection is sorted in ascending order.

Example:

std::list<int> l;
SA::add(l,1,2,3,4,5,6,7);
auto revComp = [](int a,int b) { return a > b; };
SM::sortS(l,revComp);
std::vector<int> expected;
SA::add(expected,7,6,5,4,3,2,1);
assert( SM::areCollectionsEqual(l,expected) );
assert( SM::isSortedS(l,revComp) );
template<class RetVal = double, class... V>
static RetVal templatious::StaticManipulator::sum ( V &&...  args)
inlinestatic

Sum utility function. Returns numeric sum of all elements. Example:

int a,b,c;
a = b = c = 7;
auto s = SF::seqL(3);
auto p = SF::pack(4,5,6);
int sum = SM::sum<int>(a,b,c,s,p);
// sum =
// 7 + 7 + 7 | a,b,c
// + 0 + 1 + 2 | s
// + 4 + 5 + 6 | p
// = 39
Parameters
[in]argsElements to sum. Can process packs, collections and single values.
[in]RetValReturn type. Defaults to double.
template<class RetVal = double, class Fn , class... V>
static RetVal templatious::StaticManipulator::sumS ( Fn &&  f,
V &&...  args 
)
inlinestatic

Sum using special function. Returns numeric sum of all elements.

Parameters
[in]fFunction to be used on every element before summing an element to the result.
[in]argsElements to sum. Can process packs, collections and single values.
[in]RetValReturn type. Defaults to double.

Example:

int a,b,c;
a = b = c = 7;
auto s = SF::seqL(3);
auto p = SF::pack(4,5,6);
int sum = SM::sumS<int>(
[](int i) { return 2*i; } // multiply each arg by 2
a,b,c,s,p);
// sum =
// 7*2 + 7*2 + 7*2 | a,b,c
// + 0*2 + 1*2 + 2*2 | s
// + 4*2 + 5*2 + 6*2 | p
// = 78
template<bool passIndex = false, class U , class... Args>
static void templatious::StaticManipulator::traverse ( U &&  fn,
Args &&...  args 
)
inlinestatic

Linear traversal function

Parameters
[in]fnFunction to be used on traversal. Should take arguments from args collection value types.
[in]argsCollection arguments to be traversed linearly. Must all have the same count of elements.
[in]passIndexBoolean value wether to pass index of current traversal (from 0) to a function. If passed, index is passed first. Defaults to false.

Example:

auto s1 = SF::seqL(10); // {0..9}
auto s2 = SF::seqL(10,20); // {10..19}
int sum = 0;
auto func = [&](int a,int b) { sum += a * b; };
SM::traverse(func,s1,s2);
assert( sum == 735 );

Example using prebuilt passIndex variable:

auto s = SF::seqL(10,20); // {10..19}
int sum = 0;
auto func = [&](int i,int b) { sum += i * b; };
// passing only one sequence, first lambda
// argument is iteration number 0..n
SM::traverse<true>(func,s);
assert( sum == 735 );

The documentation for this struct was generated from the following file: