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

#include <StaticFactory.hpp>

Static Public Member Functions

template<class Val , template< class...> class Collection, template< class > class Allocator = std::allocator>
static auto makeCollection () -> decltype(templatious::adapters::CollectionMaker< Val, Collection, Allocator >().make())
 
template<class Val , template< class...> class Collection, template< class > class Allocator = std::allocator>
static auto makeCollection (long size) -> decltype(templatious::adapters::CollectionMaker< Val, Collection, Allocator >().make(size))
 
template<class T >
static auto seqL (const T &end) -> templatious::SeqL< T >
 
template<class T >
static auto seqL (const T &start, const T &end) -> templatious::SeqL< T >
 
template<class T >
static auto seqL (const T &start, const T &end, const T &step) -> templatious::SeqL< T >
 
template<class T >
static auto seqI (const T &end) -> templatious::SeqL< T >
 
template<class T >
static auto seqI (const T &start, const T &end) -> templatious::SeqL< T >
 
template<class T >
static auto seqI (const T &start, const T &end, const T &step) -> templatious::SeqL< T >
 
template<template< class > class StoragePolicy = templatious::util::DefaultStoragePolicy, class T >
static auto repA (long n, T &&c) -> detail::Repeater< false, StoragePolicy, decltype(std::forward< T >(c)) >
 
template<template< class > class StoragePolicy = templatious::util::DefaultStoragePolicy, class T >
static auto repM (long n, T &&c) -> detail::Repeater< true, StoragePolicy, decltype(std::forward< T >(c)) >
 
template<template< class > class StoragePolicy = templatious::util::DefaultStoragePolicy, class T >
static auto repS (long n, T &&t) -> detail::ItemRepeater< decltype(std::forward< T >(t)), StoragePolicy >
 
template<template< class > class StoragePolicy = templatious::util::DefaultStoragePolicy, class T >
static auto range (T &&t, typename adapters::CollectionAdapter< T >::Iterator b, typename adapters::CollectionAdapter< T >::Iterator e) -> templatious::Range< T, StoragePolicy >
 
template<template< class > class StoragePolicy = templatious::util::DefaultStoragePolicy, class T >
static auto range (T &&t, typename adapters::CollectionAdapter< T >::Iterator b) -> templatious::Range< decltype(std::forward< T >(t)), StoragePolicy >
 
template<template< class > class StoragePolicy = templatious::util::DefaultStoragePolicy, class T >
static auto range (T &&t, long b, long e) -> templatious::Range< decltype(std::forward< T >(t)), StoragePolicy >
 
template<template< class > class StoragePolicy = templatious::util::DefaultStoragePolicy, class T >
static auto range (T &&t, long b) -> Range< decltype(std::forward< T >(t)), StoragePolicy >
 
template<template< class...> class Collection = std::vector, template< class > class Allocator = std::allocator, class T , class... Args>
static auto rangeC (T &&t, Args &&...args) -> typename templatious::adapters::CollectionMaker< typename templatious::adapters::CollectionAdapter< T >::ValueType, Collection, Allocator >::Collection
 
template<template< class > class StoragePolicy = templatious::util::DefaultStoragePolicy, class T , class Fun >
static auto filter (T &&t, Fun &&f) -> Filter< decltype(std::forward< T >(t)), Fun, StoragePolicy >
 
template<template< class...> class Collection = std::vector, template< class > class Allocator = std::allocator, class T , class... Args>
static auto filterC (T &&t, Args &&...args) -> typename templatious::adapters::CollectionMaker< typename templatious::adapters::CollectionAdapter< T >::ValueType, Collection, Allocator >::Collection
 
template<template< class > class StoragePolicy = templatious::util::DefaultStoragePolicy, class T >
static auto skip (T &&t, long sz) -> Skipper< decltype(std::forward< T >(t)), StoragePolicy >
 
template<template< class...> class Collection = std::vector, template< class > class Allocator = std::allocator, class T , class... Args>
static auto skipC (T &&t, Args &&...args) -> typename templatious::adapters::CollectionMaker< typename templatious::adapters::CollectionAdapter< T >::ValueType, Collection, Allocator >::Collection
 
template<class ColType = void, template< class > class StoragePolicy = templatious::util::DefaultStoragePolicy, class T , class F >
static auto select (T &&t, F &&f) -> decltype(SelectCollectionMaker< std::is_same< ColType, void >::value, ColType, StoragePolicy >::Alg::make(std::forward< T >(t), std::forward< F >(f)))
 
template<class ColType = void, template< class...> class Collection = std::vector, template< class > class Allocator = std::allocator, template< class > class StoragePolicy = templatious::util::DefaultStoragePolicy, class T , class... Args>
static auto selectC (T &&t, Args &&...args) -> typename templatious::adapters::CollectionMaker< typename templatious::adapters::CollectionAdapter< decltype(StaticFactory::select< ColType >(std::forward< T >(t), std::forward< Args >(args)...)) >::ValueType, Collection, Allocator >::Collection
 
template<class T , template< class > class StoragePolicy = templatious::util::DefaultStoragePolicy>
static auto vcollection (T &&t) -> VCollection< typename adapters::CollectionAdapter< decltype(std::forward< T >(t)) >::ValueType >
 
template<class T , class Dtor , template< class > class StoragePolicy = templatious::util::DefaultStoragePolicy>
static auto vcollectionWDtor (T &&t, Dtor &&d) -> VCollection< typename adapters::CollectionAdapter< decltype(std::forward< T >(t)) >::ValueType >
 
template<templatious::AddablePolicy ap = templatious::AP_THROW, templatious::ClearablePolicy cp = templatious::CP_THROW, templatious::TraversablePolicy tp = templatious::TP_THROW, templatious::AccessPolicy acp = templatious::ACP_THROW, templatious::SizablePolicy sp = templatious::SP_THROW, template< class > class StoragePolicy = templatious::util::DefaultStoragePolicy, class T >
static auto vcollectionCustom (T &&t) -> VCollection< typename adapters::CollectionAdapter< T >::ValueType >
 
template<templatious::AddablePolicy ap = templatious::AP_THROW, templatious::ClearablePolicy cp = templatious::CP_THROW, templatious::TraversablePolicy tp = templatious::TP_THROW, templatious::AccessPolicy acp = templatious::ACP_THROW, templatious::SizablePolicy sp = templatious::SP_THROW, template< class > class StoragePolicy = templatious::util::DefaultStoragePolicy, class T , class Dtor >
static auto vcollectionCustomWDtor (T &&t, Dtor &&d) -> VCollection< typename adapters::CollectionAdapter< T >::ValueType >
 
template<int bitmask, template< class > class StoragePolicy = templatious::util::DefaultStoragePolicy, class T >
static auto prevent (T &&t) -> typename templatious::BitmaskVCollectionFactory< bitmask, false, decltype(std::forward< T >(t)), StoragePolicy >::Type
 
template<int bitmask, template< class > class StoragePolicy = templatious::util::DefaultStoragePolicy, class T >
static auto allow (T &&t) -> typename templatious::BitmaskVCollectionFactory< bitmask, true, decltype(std::forward< T >(t)), StoragePolicy >::Type
 
template<template< class > class StoragePolicy = DefaultPackStoragePolicy, class... T>
static auto pack (T &&...t) -> decltype(detail::PackAccess::packUp< StoragePolicy >(std::forward< T >(t)...))
 
template<template< class > class StoragePolicy = DefaultPackStoragePolicy, class P , class T >
static auto packInsert (P &&p, T &&t) -> decltype(detail::PackAccess::packInsert< StoragePolicy >(std::forward< P >(p), std::forward< T >(t)))
 
template<class P , class T >
static auto packInsertWithin (P &&p, T &&t) -> decltype(detail::PackAccess::packInsertWithin(std::forward< P >(p), std::forward< T >(t)))
 
template<class F , class P , class... T>
static auto packTransformWithin (F &&f, P &&p, T &&...t) -> decltype(detail::PackAccess::packTransformWithin(std::forward< F >(f), std::forward< P >(p), std::forward< T >(t)...))
 
template<int n, class... Args>
static auto packRepeat (Args &&...args) -> decltype(detail::PackAccess::packRepeat< n >(std::forward< Args >(args)...))
 
template<int n = 1>
static auto dummyVar () -> decltype(detail::PackAccess::packRepeat< n >(detail::dummyVar))
 
template<template< class > class StoragePolicy = ::templatious::util::DefaultStoragePolicy, class F , class... Args>
static auto packFunctor (F &&f, Args &&...args) -> detail::PackFunctor< StoragePolicy, decltype(std::forward< F >(f)), decltype(pack(std::forward< Args >(args)...)) >
 
template<class... T, class Func >
static auto matchTight (Func &&f) -> detail::Match< templatious::TypeList< T...>, Func, util::DefaultStoragePolicy, detail::TightRecursiveComparison, templatious::detail::TypelistsEqual >
 
template<template< class > class StoragePolicy, class... T, class Func >
static auto matchTight (Func &&f) -> detail::Match< templatious::TypeList< T...>, Func, StoragePolicy, detail::TightRecursiveComparison, templatious::detail::TypelistsEqual >
 
template<template< class, int > class MatchAlgorithm, template< class > class StoragePolicy = templatious::util::DefaultStoragePolicy, class Func >
static auto matchSpecial (Func &&f) -> detail::MatchSpecial< MatchAlgorithm, Func, StoragePolicy >
 
template<template< class > class MatchAlgorithm, template< class > class StoragePolicy = templatious::util::DefaultStoragePolicy, class Func >
static auto matchSpecialExt (Func &&f) -> detail::MatchSpecialExt< MatchAlgorithm, Func, StoragePolicy >
 
template<class... T, class Func >
static auto matchLoose (Func &&f) -> detail::Match< templatious::TypeList< T...>, Func, util::DefaultStoragePolicy, detail::LooseRecursiveComparison, templatious::detail::TypelistContains >
 
template<template< class > class StoragePolicy, class... T, class Func >
static auto matchLoose (Func &&f) -> detail::Match< templatious::TypeList< T...>, Func, StoragePolicy, detail::LooseRecursiveComparison, templatious::detail::TypelistContains >
 
template<template< class > class StoragePolicy = templatious::util::DefaultStoragePolicy, class Func >
static auto matchAny (Func &&f) -> detail::Match< templatious::TypeList< AnyType >, Func, StoragePolicy, detail::LooseRecursiveComparison, templatious::detail::TypelistContains >
 
static auto matchAnyDoNothing () -> detail::Match< templatious::TypeList< AnyType >, templatious::util::DoNothingFunctor, templatious::util::DefaultStoragePolicy, detail::LooseRecursiveComparison, templatious::detail::TypelistContains >
 
template<class T = void>
static auto matchAnyForward () -> detail::Match< templatious::TypeList< AnyType >, templatious::util::ForwardFunctor< T >, templatious::util::DefaultStoragePolicy, detail::LooseRecursiveComparison, templatious::detail::TypelistContains >
 
template<template< class > class StoragePolicy = templatious::util::DefaultStoragePolicy, class... T>
static auto matchFunctor (T &&...t) -> detail::MatchFunctor< StoragePolicy, T...>
 
template<template< class > class StoragePolicy = templatious::util::CopyOnlyStoragePolicy, class... T>
static auto virtualMatchFunctor (T &&...t) -> VirtualMatchFunctorImpl< StoragePolicy, decltype(std::forward< T >(t))... >
 
template<template< class > class StoragePolicy = templatious::util::CopyOnlyStoragePolicy, class... T>
static auto virtualMatchFunctorPtr (T &&...t) -> std::unique_ptr< VirtualMatchFunctor >
 
template<class... Args, class F >
static auto virtualMatch (F &&f) -> VirtualMatch< decltype(std::forward< F >(f)), false, templatious::util::CopyOnlyStoragePolicy, Args... >
 
template<template< class > class StoragePolicy, class... Args, class F >
static auto virtualMatch (F &&f) -> VirtualMatch< decltype(std::forward< F >(f)), false, StoragePolicy, Args... >
 
template<class... Args, class F >
static auto virtualTransparentMatch (F &&f) -> VirtualMatch< decltype(std::forward< F >(f)), true, templatious::util::CopyOnlyStoragePolicy, Args... >
 
template<template< class > class StoragePolicy, class... Args, class F >
static auto virtualTransparentMatch (F &&f) -> VirtualMatch< decltype(std::forward< F >(f)), true, StoragePolicy, Args... >
 
template<class... Signature, class... Init>
static auto vpack (Init &&...vars) -> templatious::VirtualPackImpl< DefVpackSettings, Signature... >
 
template<class... Signature, class... Init>
static auto vpackPtr (Init &&...vars) -> std::shared_ptr< VirtualPackImpl< DefVpackSettings, Signature... > >
 
template<class... Signature, class Function , class... Init>
static auto vpackPtrWCallback (Function &&f, Init &&...vars) -> std::shared_ptr< VirtualPackImpl< DefVpackSettings|VPACK_WCALLBACK, decltype(std::forward< Function >(f)), Signature... > >
 
template<int vpackFlags, class... Signature, class... Init>
static auto vpackPtrCustom (Init &&...vars) -> std::shared_ptr< VirtualPackImpl< vpackFlags, Signature... > >
 
template<int vpackFlags, class... Signature, class Function , class... Init>
static auto vpackPtrCustomWCallback (Function &&f, Init &&...vars) -> std::shared_ptr< VirtualPackImpl< vpackFlags|templatious::VPACK_WCALLBACK, decltype(std::forward< Function >(f)), Signature... > >
 
template<class T >
static auto streamOutFunctor (T &t) -> detail::CallEachStreamFunctor< T & >
 
template<template< class > class T, class Stor >
static auto storageFunctor (Stor &&s) -> T< decltype(std::forward< Stor >(s)) >
 
template<bool statefulDefault = false, template< class > class StoragePolicy = templatious::util::DefaultStoragePolicy, class... Args>
static auto chainFunctor (Args &&...args) -> decltype(detail::makeChainFunctor< statefulDefault, false, StoragePolicy >(detail::makeFunctorPair< StoragePolicy >(std::forward< Args >(args))...))
 
template<template< class > class StoragePolicy = templatious::util::DefaultStoragePolicy, class T , class U >
static auto functorPair (T &&t, U &&u) -> detail::FunctorPair< StoragePolicy, true, T, U >
 
template<class T >
static auto onceTraversable (T &&t) -> decltype(detail::makeOnceTraversable< templatious::util::DefaultStoragePolicy >(std::forward< T >(t)))
 

Static Public Attributes

static const int DefVpackSettings = VPACK_DEF_MASK
 

Detailed Description

A class which holds static methods that mainly have to do with object creation.

Member Function Documentation

template<int bitmask, template< class > class StoragePolicy = templatious::util::DefaultStoragePolicy, class T >
static auto templatious::StaticFactory::allow ( T &&  t) -> typename templatious::BitmaskVCollectionFactory< bitmask,true,decltype(std::forward<T>(t)),StoragePolicy >::Type
inlinestatic

Get handle to collection with selected permissions. Everything is disallowed unless specified otherwise. If action is disallowed on the handle code will not compile. Useful to assert that collection is operated only on the ways intended.

Parameters
[in]bitmaskBitmask which specifies compile time permissions for collection. Possible values:
// allow addition to collection
templatious::VCOL_ADD
// allow erase of elements in collection
templatious::VCOL_CLEAR
// allow traversal of collection
templatious::VCOL_TRAVERSE
// allow access of collection
templatious::VCOL_ACCESS
// allow size info of collection
templatious::VCOL_SIZE
[in]tCollection to get handle to.

Example:

std::vector<int> v;
// Allow addition and traversal of collection.
// Any other action fails static assert.
auto h = SF::allow<
templatious::VCOL_ADD | templatious::VCOL_TRAVERSE
>(v);
// ok
SA::add(h,1,2,3);
// ok
TEMPLATIOUS_FOREACH(auto i,h) {
}
// WRONG, access disabled, compile time error
//SA::getByIndex(h,0);
// WRONG, clear disabled, compile time error
//SA::clear(h);
// WRONG, size info disabled, compile time error
//long sz = SA::size(h);
template<bool statefulDefault = false, template< class > class StoragePolicy = templatious::util::DefaultStoragePolicy, class... Args>
static auto templatious::StaticFactory::chainFunctor ( Args &&...  args) -> decltype( detail::makeChainFunctor< statefulDefault, false, StoragePolicy >( detail::makeFunctorPair< StoragePolicy >( std::forward<Args>(args) )... ) )
inlinestatic

Chain functor encapsulates decorator design pattern. It saves functions to be called in a row (and in reverse if it is created using pairs) order.

Functional example:

int add(int n) { return n + 7; }
int mul(int n) { return n * 7; }
..
add,mul
);
// this
int res1 = cf(7);
// is same as
int res2 = mul(add(7));

Stateful example:

void add(int& n) { n += 7; }
void mul(int& n) { n *= 7; }
..
auto cf = StaticFactory::chainFunctor<true>(
add,mul
);
// this
int a = 7;
int res1 = cf(a);
// is same as
int b = 7;
add(b);
mul(b);
Parameters
[in]argsFunctions to encapsulate.
[in]statefulDefaultwhether to use stateful decorating (passing same exact arguments each iteration) or functional decorating (passing current function return value to the next function)
[in]StoragePolicyStorage policy to use. Defaults to templatious::util::DefaultStoragePolicy.
template<int n = 1>
static auto templatious::StaticFactory::dummyVar ( ) -> decltype( detail::PackAccess::packRepeat<n>( detail::dummyVar ) )
inlinestatic

Use packRepeat function with dummy variable. The variable returned is a pack full of dummy object that overloads = operator and can be assigned to from any class. It does nothing. This is useful with distribute function to skip iterators when assigning to this variable. Since = operator for this class does nothing it generates 0 instructions and only advances iterator.

Parameters
[in]nAmount of dummy variables to create.
template<template< class > class StoragePolicy = templatious::util::DefaultStoragePolicy, class T , class Fun >
static auto templatious::StaticFactory::filter ( T &&  t,
Fun &&  f 
) -> Filter<decltype(std::forward<T>(t)),Fun,StoragePolicy>
inlinestatic

Filter collection using predicate. Modifying underlying collection (adding or removing elements) and trying to use this one causes undefined behaviour.

Parameters
[in]tCollection to return range from.
[in]fPredicate function which decides what elements to expose in collection. Should take in one element of collection and return true if element should be kept in the filter, false if element should be ignored.
[in]StoragePolicyStorage policy to specify how to store the t collection in the filter. Defaults to templatious::util::DefaultStoragePolicy.

Example:

std::vector<int> v;
SA::add(v,SF::seqL(10));
// v contains {0,1,2,3,4,5,6,7,8,9}
auto r = SF::filter(v,[](int i) { return i >= 3 && i <= 7; });
TEMPLATIOUS_FOREACH(int i,r) {
std::cout << i << " ";
}
// prints out
// 3 4 5 6 7
template<template< class...> class Collection = std::vector, template< class > class Allocator = std::allocator, class T , class... Args>
static auto templatious::StaticFactory::filterC ( T &&  t,
Args &&...  args 
) -> typename templatious::adapters::CollectionMaker< typename templatious::adapters:: CollectionAdapter<T>::ValueType, Collection, Allocator >::Collection
inlinestatic

Copy filter collection using predicate.

Parameters
[in]tCollection to return range from.
[in]argsArguments which would be passed to normal filter function.
[in]CollectionCollection type to return. Defaults to std::vector.
[in]AllocatorCollection allocator. Defaults to std::allocator (is ignored if collection doesn't use allocators).

Example:

std::vector<int> v;
SA::add(v,SF::seqL(10));
// v contains {0,1,2,3,4,5,6,7,8,9}
// return type is std::vector<int>
std::vector<int> r = SF::filterC(v,[](int i) { return i >= 3 && i <= 7; });
TEMPLATIOUS_FOREACH(int i,r) {
std::cout << i << " ";
}
// prints out
// 3 4 5 6 7
template<template< class > class StoragePolicy = templatious::util::DefaultStoragePolicy, class T , class U >
static auto templatious::StaticFactory::functorPair ( T &&  t,
U &&  u 
) -> detail::FunctorPair< StoragePolicy, true, T, U >
inlinestatic

Create a functor pair consisting of do and undo action. Intented to be used with chainFunctor.

Parameters
[in]tDo action
[in]uUndo action
[in]StoragePolicyStorage policy to be used when saving actions.

Example:

int addNum(int n) { return n + 7; }
int subNum(int n) { return n - 7; }
int mulNum(int n) { return n * 7; }
int divNum(int n) { return n / 7; }
..
);
int res = cf(7); // res contains 98
int back = cf.doBwd(res); // back contains 7
// doBwd method is only applicable if
// *EVERY* argument passed to chainFunctor
// is functorPair with do and undo actions.
template<class Val , template< class...> class Collection, template< class > class Allocator = std::allocator>
static auto templatious::StaticFactory::makeCollection ( ) -> decltype(templatious::adapters::CollectionMaker< Val,Collection,Allocator>().make())
inlinestatic

Uniform function to make collection of any type.

Parameters
[in]ValValue type for collection.
[in]CollectionCollection template.
[in]Collectionallocator template, defaults to std::allocator (ignored if collection doesn't use allocators).

Example:

// makes std::vector<int>
auto v = SF::makeCollection<int,std::vector>();
template<class Val , template< class...> class Collection, template< class > class Allocator = std::allocator>
static auto templatious::StaticFactory::makeCollection ( long  size) -> decltype(templatious::adapters::CollectionMaker< Val,Collection,Allocator>().make(size))
inlinestatic

Uniform function to make collection of any type with size hint.

Parameters
[in]sizeSize hint for collection.
[in]ValValue type for collection.
[in]CollectionCollection template.
[in]Collectionallocator template, defaults to std::allocator (ignored if collection doesn't use allocators).

Example:

// makes std::vector<int> with capacity 64
auto v = SF::makeCollection<int,std::vector>(64);
template<template< class > class StoragePolicy = templatious::util::DefaultStoragePolicy, class Func >
static auto templatious::StaticFactory::matchAny ( Func &&  f) -> detail::Match< templatious::TypeList< AnyType >, Func, StoragePolicy, detail::LooseRecursiveComparison, templatious::detail::TypelistContains >
inlinestatic

Match anything. This is usually the last match in match functor.

Parameters
[in]fFunction to use when matched.
[in]StoragePolicyStorage policy. Defaults to templatious::util::DefaultStoragePolicy.

Example:

struct MatchStuff {
template <class... T>
std::string operator()(T&&... t) {
return "caught";
}
};
...
auto mf = SF::matchFunctor(
SF::matchAny(MatchStuff())
);
struct MyHipsterStruct {};
assert( mf(1) == "caught" );
assert( mf('1') == "caught" );
assert( mf("const char") == "caught" );
assert( mf(std::string("str")) == "caught" );
assert( mf(MyHipsterStruct()) == "caught" );
static auto templatious::StaticFactory::matchAnyDoNothing ( ) -> detail::Match< templatious::TypeList< AnyType >, templatious::util::DoNothingFunctor, templatious::util::DefaultStoragePolicy, detail::LooseRecursiveComparison, templatious::detail::TypelistContains >
inlinestatic

Match anything and do nothing. This is usually the last match in match functor. Anything after this match will never be reached.

Example:

int sum = 0;
auto wouldMatch = [&](int i) { sum += i; };
auto mf = SF::matchFunctor(
SF::matchAnyDoNothing(),
SF::matchLoose<int>(wouldMatch)
);
int someInt = 10;
mf(someInt);
mf(someInt);
mf(someInt);
assert( sum == 0 );
template<class T = void>
static auto templatious::StaticFactory::matchAnyForward ( ) -> detail::Match< templatious::TypeList< AnyType >, templatious::util::ForwardFunctor<T>, templatious::util::DefaultStoragePolicy, detail::LooseRecursiveComparison, templatious::detail::TypelistContains >
inlinestatic

Match anything and forward the argument. Usually the last match in the match functor.

Parameters
[in]TType to forward as. If void result forwarded will be returned as
return std::forward<T>(arg);

Example:

auto mf = SF::matchFunctor(
SF::matchLoose<int>([](int i) -> std::string { return "this is int"; }),
SF::matchAnyForward()
);
int i;
assert( mf(i) == "this is int" );
assert( mf('7') == '7' );
assert( mf("string") == std::string("string") );
assert( mf(std::string("string")) == "string" );
template<template< class > class StoragePolicy = templatious::util::DefaultStoragePolicy, class... T>
static auto templatious::StaticFactory::matchFunctor ( T &&...  t) -> detail::MatchFunctor<StoragePolicy,T...>
inlinestatic

Function to create match functor. Intended to be composed of match methods in StaticFactory which start as "match".

Parameters
[in]tMatch arguments to use.
[in]StoragePolicyStorage policy to store matches. Defaults to templatious::util::DefaultStoragePolicy.

Example:

auto toDoubleNum = SF::matchFunctor(
SF::matchLoose<int>([](int i) -> double {
return static_cast<double>(i);
}),
SF::matchLoose<char>([](char i) -> double {
return static_cast<double>(i);
})
);
auto toDoubleStr = SF::matchFunctor(
SF::matchLoose<const char*>([](const char* str) -> double {
return std::atof(str);
}),
SF::matchLoose<std::string>([](const std::string& str) -> double {
return std::atof(str.c_str());
})
);
auto toDouble = SF::matchFunctor(
toDoubleNum,toDoubleStr
);
assert( toDouble(7) == 7.0 );
assert( toDouble('7') == 55.0 );
assert( toDouble("7.7") == 7.7 );
assert( toDouble(std::string("7.77")) == 7.77 );
template<class... T, class Func >
static auto templatious::StaticFactory::matchLoose ( Func &&  f) -> detail::Match< templatious::TypeList<T...>, Func, util::DefaultStoragePolicy, detail::LooseRecursiveComparison, templatious::detail::TypelistContains >
inlinestatic

Loose match to be used in matchFunctor. This match applied std::decay on both types when comparing. Loose match matches

int& and int& // OK
const int& and int& // OK
const int& and const int& // OK
int& and int // OK

Loose match only matches at the start of arguments in typelist to match, therefore, it may match having less types in typelist than actual arguments. Loose match will always match templatious::AnyType.

Parameters
[in]fPredicate function to hold.
[in]T...Type arguments to match.

Example:

auto mf = SF::matchFunctor(
SF::matchLoose< int >(
[](int i) -> std::string { return "int"; }
),
SF::matchLoose< char >(
[](char c) -> int { return 7; }
)
);
int a;
char b;
auto retA = mf(a);
auto retB = mf(b);
// Compile time error: nothing to catch the match
// auto retC = mf(long(7));
// retA -> std::string
// retB -> int
assert( retA == "int" );
assert( retB == 7 );
template<template< class > class StoragePolicy, class... T, class Func >
static auto templatious::StaticFactory::matchLoose ( Func &&  f) -> detail::Match< templatious::TypeList<T...>, Func, StoragePolicy, detail::LooseRecursiveComparison, templatious::detail::TypelistContains >
inlinestatic

Same as loose match but with special storage policy.

Parameters
[in]fFunction to use.
[in]T...Typelist to match.
[in]StoragePolicyStorage policy used for saving function.

Example:

auto mf = SF::matchFunctor(
SF::matchLoose< int >(
[](int i) -> std::string { return "int"; }
),
SF::matchLoose< char >(
[](char c) -> int { return 7; }
)
);
int a;
char b;
auto retA = mf(a);
auto retB = mf(b);
// Compile time error: nothing to catch the match
// auto retC = mf(long(7));
// retA -> std::string
// retB -> int
assert( retA == "int" );
assert( retB == 7 );
template<template< class, int > class MatchAlgorithm, template< class > class StoragePolicy = templatious::util::DefaultStoragePolicy, class Func >
static auto templatious::StaticFactory::matchSpecial ( Func &&  f) -> detail::MatchSpecial< MatchAlgorithm, Func, StoragePolicy >
inlinestatic

Special match which uses user supplied template function to test whether this match succeeds.

Parameters
[in]fFunction to use.
[in]MatchAlgorithmUser supplied template function for matching.

Synposis:

// CurrentMatch - current argument type
// being matched.
// pos - current argument position,
// starting with 1
template <class CurrentMatch,int pos>
struct UserMatcher {
// does_match - result of this function.
// Must be true for all arguments to use
// this match.
static const bool does_match = true;
// num_args - the amount of arguments
// function should take. 0 for any amount
// of arguments.
static const int num_args = 0;
};
// If function f is called with arguments
// a,b,c like f(A a,B b,C c) UserMatcher will
// be called like:
// if (UserMatcher<A,1>::does_match &&
// UserMatcher<B,2>::does_match &&
// UserMatcher<C,3>::does_match) { MATCHED }

Example:

template <class CurrentMatch,int pos>
struct MatchSingleDouble {
typedef typename std::decay<CurrentMatch>::type DecType;
static const bool isDouble =
std::is_same<DecType,double>::value;
static const bool does_match = isDouble && pos == 1;
static const int num_args = 0;
};
struct AnyMatch {
template <class... T>
std::string operator()(T&&... args) {
return "no match";
}
};
...
auto mf = SF::matchFunctor(
SF::matchSpecial<MatchSingleDouble>(
[](double d) -> std::string {
return "caught double";
}),
SF::matchAny(AnyMatch())
);
assert( mf(7.7) == "caught double" );
assert( mf(7.7f) == "no match" );
assert( mf(7) == "no match" );
assert( mf('7') == "no match" );
assert( mf("string") == "no match" );
assert( mf(std::string("string")) == "no match" );
template<template< class > class MatchAlgorithm, template< class > class StoragePolicy = templatious::util::DefaultStoragePolicy, class Func >
static auto templatious::StaticFactory::matchSpecialExt ( Func &&  f) -> detail::MatchSpecialExt< MatchAlgorithm, Func, StoragePolicy >
inlinestatic

Special match extended which uses user supplied template function to test whether this match succeeds. TypeList is passed to user template.

Parameters
[in]fFunction to use.
[in]MatchAlgorithmUser supplied template function for matching.

Synopsis:

// TypeList - typelist which contains
// all the types current call has.
template <class TypeList>
struct UserMatcher {
// does_match - result. Did this
// TypeList satisfy user requirements?
static const bool does_match = ?;
};
// If function f is called with arguments
// a,b,c like f(A a,B b,C c) UserMatcher will
// be called like:
// if (UserMatcher< TypeList<A,B,C> >::does_match )
// { MATCHED }

Example:

template <class TypeList>
struct MatchSingleDouble {
typedef typename TypeList::template ByIndex<0>::type FirstType;
typedef typename std::decay<FirstType>::type DecType;
static const bool isDouble =
std::is_same<DecType,double>::value;
static const bool expectedNumOfArgs = TypeList::size == 1;
static const bool does_match = isDouble && expectedNumOfArgs;
};
struct AnyMatch {
template <class... T>
std::string operator()(T&&... args) {
return "no match";
}
};
...
auto mf = SF::matchFunctor(
SF::matchSpecialExt<MatchSingleDouble>(
[](double d) -> std::string {
return "caught double";
}),
SF::matchAny(AnyMatch())
);
assert( mf(7.7) == "caught double" );
assert( mf(7.7f) == "no match" );
assert( mf(7) == "no match" );
assert( mf('7') == "no match" );
assert( mf("string") == "no match" );
assert( mf(std::string("string")) == "no match" );
template<class... T, class Func >
static auto templatious::StaticFactory::matchTight ( Func &&  f) -> detail::Match< templatious::TypeList<T...>, Func, util::DefaultStoragePolicy, detail::TightRecursiveComparison, templatious::detail::TypelistsEqual >
inlinestatic

Tight match to be used in matchFunctor. Tight match matches

int& and int& // OK
const int& and int& // Doesn't match
const int& and const int& // OK
int& and int // Doesn't match

Tight match has to have exact number of arguments to match. Tight match will always match templatious::AnyType.

Parameters
[in]fPredicate function to hold.
[in]T...Type arguments to match.

Example:

auto mf = SF::matchFunctor(
SF::matchTight<int&>([](int& i) -> std::string {
return "tight";
}),
SF::matchLoose<int>([](const int& i) -> std::string {
return "loose";
})
);
int i;
assert( mf(i) == "tight" );
assert( mf(int(i)) == "loose" );
assert( mf(static_cast<const int&>(i)) == "loose" );
assert( mf(std::move(i)) == "loose" );
assert( mf(7) == "loose" );
template<template< class > class StoragePolicy, class... T, class Func >
static auto templatious::StaticFactory::matchTight ( Func &&  f) -> detail::Match< templatious::TypeList<T...>, Func, StoragePolicy, detail::TightRecursiveComparison, templatious::detail::TypelistsEqual >
inlinestatic

Same as tight match but with special storage policy.

Parameters
[in]fFunction to use.
[in]T...Typelist to match.
[in]StoragePolicyStorage policy used for saving function.

Example:

auto mf = SF::matchFunctor(
SF::matchTight<int&>([](int& i) -> std::string {
return "tight";
}),
SF::matchLoose<int>([](const int& i) -> std::string {
return "loose";
})
);
int i;
assert( mf(i) == "tight" );
assert( mf(int(i)) == "loose" );
assert( mf(static_cast<const int&>(i)) == "loose" );
assert( mf(std::move(i)) == "loose" );
assert( mf(7) == "loose" );
template<class T >
static auto templatious::StaticFactory::onceTraversable ( T &&  t) -> decltype( detail::makeOnceTraversable< templatious::util::DefaultStoragePolicy >(std::forward<T>(t)) )
inlinestatic

Create once traversable collection handle. Whenever begin iterator of this collection advances, begin iterator in handle is also advanced, therefore, "consuming" collection. Useful when distributing same collection over local arguments.

Example:

std::vector<int> v;
// v now contains 0,1,2,..,99
int a,b,c;
while (3 == StaticManipulator
::distribute(ot,a,b,c))
{
..
// will be executed 33 times
}
Parameters
[in]tCollection to create handle from.
template<template< class > class StoragePolicy = DefaultPackStoragePolicy, class... T>
static auto templatious::StaticFactory::pack ( T &&...  t) -> decltype( detail::PackAccess::packUp<StoragePolicy>( std::forward<T>(t)...) )
inlinestatic

Create a pack structure. Pack is like a tuple but with more features. By default pack stores references to objects if they are lvalues and copies objects using rvalue constructor if they are rvalues.

Parameters
[in]tVariables to save in pack. Can contain other packs.
[in]StoragePolicyPack storage policy for saving elements. Defaults to DefaultPackStoragePolicy.

Example:

int a,b,c;
a = 1;
b = 2;
c = 3;
auto p = SF::pack(a,b,c);
assert( p.get<0>() == 1 );
assert( p.get<1>() == 2 );
assert( p.get<2>() == 3 );
// since lvalues were passed in
// creation of the pack, original
// values can be mutated
p.get<0>() = 7;
assert( a == 7 );
template<template< class > class StoragePolicy = ::templatious::util::DefaultStoragePolicy, class F , class... Args>
static auto templatious::StaticFactory::packFunctor ( F &&  f,
Args &&...  args 
) -> detail::PackFunctor< StoragePolicy, decltype(std::forward<F>(f)), decltype(pack(std::forward<Args>(args)...)) >
inlinestatic

Pack passed variables to a pack to be used as arguments to a function. Does not have all the features of std::bind, but rather maps exact amount of variables contained in a pack to a function. Returns a functor.

Parameters
[in]fFunction to execute.
[in]argsarguments to pack.
[in]StoragePolicystorage policy to store arguments. Defaults to templatious::util::DefaultStoragePolicy.

Example:

int a = 1;
int b = 2;
auto p = SF::pack(a,b);
auto l = [](int& x,int& y) {
++x;
++y;
};
auto pf = SF::packFunctor(l,p);
pf();
assert( a == 2 && b == 3 );
pf();
assert( a == 3 && b == 4 );
template<template< class > class StoragePolicy = DefaultPackStoragePolicy, class P , class T >
static auto templatious::StaticFactory::packInsert ( P &&  p,
T &&  t 
) -> decltype(detail::PackAccess::packInsert<StoragePolicy>( std::forward<P>(p),std::forward<T>(t)))
inlinestatic

Create a new pack inserting passed element between elements of the pack. Does not insert into all packs contained within pack recursively. Returns new pack created. For instance, if pack contains elements

[7,'7',55]

and pack insert is called with ' ' (space symbol), then the created pack will contain

[7,' ','7',' ',55]

BUT NOT

[7,' ','7',' ',55,' ']

OR

[' ',7,' ','7',' ',55,' ']
Parameters
[in]pPack to use for creating new one.
[in]tElement to insert. Can be another pack.
template<class P , class T >
static auto templatious::StaticFactory::packInsertWithin ( P &&  p,
T &&  t 
) -> decltype(detail::PackAccess::packInsertWithin( std::forward<P>(p),std::forward<T>(t)))
inlinestatic

Create a new pack inserting element t into top level packs (if there are any). Returns new pack. For instance, if there is a pack of packs

[
['a','b'],
"some string",
['c','d']
]

And if ' ' (space) is inserted, then the resulting pack is

[
['a',' ','b'],
"some string",
['c',' ','d']
]

BUT NOT

[
['a',' ','b'],
' ',
"some string",
' ',
['c',' ','d']
]
Parameters
[in]pPack to use for creating new one.
[in]tElement to insert.
template<int n, class... Args>
static auto templatious::StaticFactory::packRepeat ( Args &&...  args) -> decltype( detail::PackAccess::packRepeat<n>( std::forward<Args>(args)...) )
inlinestatic

Make a pack of repeated element(s). For instance

auto p = StaticFactory::packRepeat<7>(55);

Will result into pack:

[55,55,55,55,55,55,55]

And

auto p = StaticFactory::packRepeat<3>(2,2);

Will result into:

[2,2,2,2,2,2]
Parameters
[in]argsArguments to make pack from
[in]nTimes to repeat pack.
template<class F , class P , class... T>
static auto templatious::StaticFactory::packTransformWithin ( F &&  f,
P &&  p,
T &&...  t 
) -> decltype( detail::PackAccess::packTransformWithin( std::forward<F>(f), std::forward<P>(p), std::forward<T>(t)...) )
inlinestatic

Transform pack with a predicate function (usually this is a match functor which selects appropriate types and forwards the rest). Returns the transformed pack. This is useful for breaking down POD types into smaller chunks, for instance, if there is a struct

struct Person {
std::string _firstName;
std::string _lastName;
};

And a pack

[
"Person is: ",
Person("Abraham","Isaac")
]

Pack transform function can be used to break this down to

[
"Person is: ",
[ // <- another pack created
"Abraham",
' ',
"Isaaac"
]
]

Thus eliminating the POD type.

Parameters
[in]pPack to transform
template<int bitmask, template< class > class StoragePolicy = templatious::util::DefaultStoragePolicy, class T >
static auto templatious::StaticFactory::prevent ( T &&  t) -> typename templatious::BitmaskVCollectionFactory< bitmask,false,decltype(std::forward<T>(t)),StoragePolicy >::Type
inlinestatic

Get handle to collection with selected permissions. Everything is allowed unless specified otherwise. If action is disallowed on the handle code will not compile. Useful to assert that collection is operated only on the ways intended.

Parameters
[in]bitmaskBitmask which specifies compile time permissions for collection. Possible values:
// prevent addition to collection
templatious::VCOL_ADD
// prevent erase of elements in collection
templatious::VCOL_CLEAR
// prevent traversal of collection
templatious::VCOL_TRAVERSE
// prevent access of collection
templatious::VCOL_ACCESS
// prevent size info of collection
templatious::VCOL_SIZE
[in]tCollection to get handle to.

Example:

std::vector<int> v;
// Prevent addition and traversal of collection.
// Any other action succeeds.
auto h = SF::prevent<
templatious::VCOL_ADD | templatious::VCOL_TRAVERSE
>(v);
// WRONG, addition prevented, compile time error
//SA::add(h,1,2,3);
// WRONG, traversal prevented, compile time error
//TEMPLATIOUS_FOREACH(auto i,h) {
//
//}
// ok
SA::getByIndex(h,0);
// ok
SA::clear(h);
// ok
long sz = SA::size(h);
template<template< class > class StoragePolicy = templatious::util::DefaultStoragePolicy, class T >
static auto templatious::StaticFactory::range ( T &&  t,
typename adapters::CollectionAdapter< T >::Iterator  b,
typename adapters::CollectionAdapter< T >::Iterator  e 
) -> templatious::Range<T,StoragePolicy>
inlinestatic

Return range from existing collection specifying begin and end iterators. Passing b iterator which is greater than e iterator causes undefined behaviour. Modifying underlying collection (adding or removing elements) and trying to use this one causes undefined behaviour.

Parameters
[in]tCollection to return range from.
[in]bCollection begin iterator.
[in]eCollection end iterator.
[in]StoragePolicyStorage policy to specify how to store t. Defaults to templatious::util::DefaultStoragePolicy.

Example:

std::vector<int> v;
SA::add(v,SF::seqL(10));
// v contains {0,1,2,3,4,5,6,7,8,9}
auto r = SF::range(v,SA::iterAt(v,2),SA::iterAt(v,5));
TEMPLATIOUS_FOREACH(int i,r) {
std::cout << i << " ";
}
// prints out
// 2 3 4
template<template< class > class StoragePolicy = templatious::util::DefaultStoragePolicy, class T >
static auto templatious::StaticFactory::range ( T &&  t,
typename adapters::CollectionAdapter< T >::Iterator  b 
) -> templatious::Range<decltype( std::forward<T>(t)),StoragePolicy>
inlinestatic

Return range from existing collection from begin to end only begin iterator. Modifying underlying collection (adding or removing elements) and trying to use this one causes undefined behaviour.

Parameters
[in]tCollection to return range from.
[in]bCollection begin iterator.
[in]StoragePolicyStorage policy to specify how to store t. Defaults to templatious::util::DefaultStoragePolicy.

Example:

std::vector<int> v;
SA::add(v,SF::seqL(10));
// v contains {0,1,2,3,4,5,6,7,8,9}
auto r = SF::range(v,SA::iterAt(v,2));
TEMPLATIOUS_FOREACH(int i,r) {
std::cout << i << " ";
}
// prints out
// 2 3 4 5 6 7 8 9
template<template< class > class StoragePolicy = templatious::util::DefaultStoragePolicy, class T >
static auto templatious::StaticFactory::range ( T &&  t,
long  b,
long  e 
) -> templatious::Range<decltype(std::forward<T>(t)),StoragePolicy>
inlinestatic

Return range from existing collection from begin index to end index. Modifying underlying collection (adding or removing elements) and trying to use this one causes undefined behaviour.

Parameters
[in]tCollection to return range from.
[in]bCollection begin index.
[in]eCollection end index.
[in]StoragePolicyStorage policy to specify how to store t. Defaults to templatious::util::DefaultStoragePolicy.

Example:

std::vector<int> v;
SA::add(v,SF::seqL(10));
// v contains {0,1,2,3,4,5,6,7,8,9}
auto r = SF::range(v,2,5);
TEMPLATIOUS_FOREACH(int i,r) {
std::cout << i << " ";
}
// prints out
// 2 3 4
template<template< class > class StoragePolicy = templatious::util::DefaultStoragePolicy, class T >
static auto templatious::StaticFactory::range ( T &&  t,
long  b 
) -> Range<decltype(std::forward<T>(t)),StoragePolicy>
inlinestatic

Return range from existing collection from begin index until end. Modifying underlying collection (adding or removing elements) and trying to use this one causes undefined behaviour.

Parameters
[in]tCollection to return range from.
[in]bCollection begin index.
[in]StoragePolicyStorage policy to specify how to store t. Defaults to templatious::util::DefaultStoragePolicy.

Example:

std::vector<int> v;
SA::add(v,SF::seqL(10));
// v contains {0,1,2,3,4,5,6,7,8,9}
auto r = SF::range(v,2);
TEMPLATIOUS_FOREACH(int i,r) {
std::cout << i << " ";
}
// prints out
// 2 3 4 5 6 7 8 9
template<template< class...> class Collection = std::vector, template< class > class Allocator = std::allocator, class T , class... Args>
static auto templatious::StaticFactory::rangeC ( T &&  t,
Args &&...  args 
) -> typename templatious::adapters::CollectionMaker< typename templatious::adapters:: CollectionAdapter<T>::ValueType, Collection, Allocator >::Collection
inlinestatic

Copy range from existing collection from begin iterator until end iterator.

Parameters
[in]tCollection to return range from.
[in]argsArguments which would be passed to simple range function (iterators or indexes).
[in]CollectionCollection type to return. Defaults to std::vector.
[in]AllocatorCollection allocator. Defaults to std::allocator (is ignored if collection doesn't use allocators).

Example:

std::vector<int> v;
SA::add(v,SF::seqL(10));
// v contains {0,1,2,3,4,5,6,7,8,9}
// return value is std::vector
std::vector<int> r = SF::rangeC(v,2);
TEMPLATIOUS_FOREACH(int i,r) {
std::cout << i << " ";
}
// prints out
// 2 3 4 5 6 7 8 9
template<template< class > class StoragePolicy = templatious::util::DefaultStoragePolicy, class T >
static auto templatious::StaticFactory::repA ( long  n,
T &&  c 
) -> detail::Repeater< false, StoragePolicy, decltype(std::forward<T>(c)) >
inlinestatic

Repeater Absolute. Returns reapeater to repeat collection specified amount of times using absolute repeating. For instance, if collection {1,2,3} is repeated 7 times result is collection {1,2,3,1,2,3,1}.

Parameters
[in]nTimes to repeat.
[in]cCollection to repeat.
[in]StoragePolicyStorage policy to specify how to store collection c in itself. Defaults to templatious::util::DefaultStoragePolicy.

Example:

auto s = SF::seqL(3);
auto r = SF::repA(5,s);
TEMPLATIOUS_FOREACH(int i,r) {
std::cout << i << " ";
}
// prints out
// 0 1 2 0 1
template<template< class > class StoragePolicy = templatious::util::DefaultStoragePolicy, class T >
static auto templatious::StaticFactory::repM ( long  n,
T &&  c 
) -> detail::Repeater< true, StoragePolicy, decltype(std::forward<T>(c)) >
inlinestatic

Repeater Multiply. Returns reapeater to repeat collection specified amount of times using multiple repeating. For instance, if collection {1,2} is repeated 3 times result is collection {1,2,1,2,1,2}.

Parameters
[in]nTimes to repeat.
[in]cCollection to repeat.
[in]StoragePolicyStorage policy to specify how to store collection c in itself. Defaults to templatious::util::DefaultStoragePolicy.

Example:

auto s = SF::seqL(3);
auto r = SF::repM(5,s);
TEMPLATIOUS_FOREACH(int i,r) {
std::cout << i << " ";
}
// prints out
// 0 1 2 0 1 2 0 1 2 0 1 2 0 1 2
template<template< class > class StoragePolicy = templatious::util::DefaultStoragePolicy, class T >
static auto templatious::StaticFactory::repS ( long  n,
T &&  t 
) -> detail::ItemRepeater< decltype(std::forward<T>(t)), StoragePolicy >
inlinestatic

Repeater Same. Collection which repeats same element specified amount of times. For instance, if element 55 is repeated 7 times result collection is {55,55,55,55,55,55,55}.

Parameters
[in]nTimes to repeat.
[in]tElement to repeat.
[in]StoragePolicyStorage policy to specify how to store element t in itself. Defaults to templatious::util::DefaultStoragePolicy.

Example:

auto r = SF::repS(3,2);
TEMPLATIOUS_FOREACH(int i,r) {
std::cout << i << " ";
}
// prints out
// 2 2 2
template<class ColType = void, template< class > class StoragePolicy = templatious::util::DefaultStoragePolicy, class T , class F >
static auto templatious::StaticFactory::select ( T &&  t,
F &&  f 
) -> decltype( SelectCollectionMaker< std::is_same<ColType,void>::value, ColType, StoragePolicy >::Alg::make(std::forward<T>(t),std::forward<F>(f)) )
inlinestatic

Select something from collection according to predicate function. Returns handle with elements selected.

Parameters
[in]tCollection to select from.
[in]fFunction to use on one collection element when selecting.
[in]ColTypeType of the resulting collection. If void it is inferred from predicate function passed. Defaults to void.

Example:

std::vector<int> v;
SA::add(v,SF::seqL(10));
// v contains {0,1,2,3,4,5,6,7,8,9}
auto r = SF::select(v,[](int i) { return 10 * i; });
TEMPLATIOUS_FOREACH(int i,r) {
std::cout << i << " ";
}
// prints out
// 0 10 20 30 40 50 60 70 80 90
template<class ColType = void, template< class...> class Collection = std::vector, template< class > class Allocator = std::allocator, template< class > class StoragePolicy = templatious::util::DefaultStoragePolicy, class T , class... Args>
static auto templatious::StaticFactory::selectC ( T &&  t,
Args &&...  args 
) -> typename templatious::adapters::CollectionMaker< typename templatious::adapters:: CollectionAdapter< decltype( StaticFactory::select<ColType>( std::forward<T>(t), std::forward<Args>(args)... ) ) >::ValueType, Collection, Allocator >::Collection
inlinestatic

Select something from collection according to predicate function. Returns copy of selected elements.

Parameters
[in]tCollection to select from.
[in]fFunction to use on one collection element when selecting.
[in]ColTypeType of the resulting collection. If void it is inferred from predicate function passed. Defaults to void.

Example:

std::vector<int> v;
SA::add(v,SF::seqL(10));
// v contains {0,1,2,3,4,5,6,7,8,9}
// return type is std::vector<int>
std::vector<int> r = SF::selectC(v,[](int i) { return 10 * i; });
TEMPLATIOUS_FOREACH(int i,r) {
std::cout << i << " ";
}
// prints out
// 0 10 20 30 40 50 60 70 80 90
template<class T >
static auto templatious::StaticFactory::seqI ( const T &  end) -> templatious::SeqL<T>
inlinestatic

Sequence Include. Create numeric sequence from 0 to end by step of 1.

Parameters
[in]startValue to specify start of collection.

Example:

auto s = SF::seqI(3);
TEMPLATIOUS_FOREACH(int i,s) {
std::cout << i << " ";
}
// prints out:
// 0 1 2 3
template<class T >
static auto templatious::StaticFactory::seqI ( const T &  start,
const T &  end 
) -> templatious::SeqL<T>
inlinestatic

Sequence Include. Create numeric sequence from start to end by step of 1.

Parameters
[in]startValue to specify start of collection.
[in]endValue to specify end of collection.

Example:

auto s = SF::seqI(2,5);
TEMPLATIOUS_FOREACH(int i,s) {
std::cout << i << " ";
}
// prints out:
// 2 3 4 5
template<class T >
static auto templatious::StaticFactory::seqI ( const T &  start,
const T &  end,
const T &  step 
) -> templatious::SeqL<T>
inlinestatic

Sequence Include. Create numeric sequence from start to end by step of step. Throws in case (end - start) % step != 0.

Parameters
[in]startValue to specify start of collection.
[in]endValue to specify end of collection.
[in]stepValue to specify step of collection. Has to be always positive, even if start > end.

Example:

auto s = SF::seqI(2,8,2);
TEMPLATIOUS_FOREACH(int i,s) {
std::cout << i << " ";
}
// prints out:
// 2 4 6 8
template<class T >
static auto templatious::StaticFactory::seqL ( const T &  end) -> templatious::SeqL<T>
inlinestatic

Sequence Less. Create numeric sequence from 0 until end by step of 1.

Parameters
[in]endValue to specify end of collection.

Example:

auto s = SF::seqL(3);
TEMPLATIOUS_FOREACH(int i,s) {
std::cout << i << " ";
}
// prints out:
// 0 1 2
template<class T >
static auto templatious::StaticFactory::seqL ( const T &  start,
const T &  end 
) -> templatious::SeqL<T>
inlinestatic

Sequence Less. Create numeric sequence from start until end by step of 1.

Parameters
[in]startValue to specify start of collection.
[in]endValue to specify end of collection.

Example:

auto s = SF::seqL(2,5);
TEMPLATIOUS_FOREACH(int i,s) {
std::cout << i << " ";
}
// prints out:
// 2 3 4
template<class T >
static auto templatious::StaticFactory::seqL ( const T &  start,
const T &  end,
const T &  step 
) -> templatious::SeqL<T>
inlinestatic

Sequence Less. Create numeric sequence from start until end by step of step.

Parameters
[in]startValue to specify start of collection.
[in]endValue to specify end of collection.
[in]stepValue to specify step of collection. Has to be always positive, even if start > end.

Example:

auto s = SF::seqL(2,7,2);
TEMPLATIOUS_FOREACH(int i,s) {
std::cout << i << " ";
}
// prints out:
// 2 4 6
template<template< class > class StoragePolicy = templatious::util::DefaultStoragePolicy, class T >
static auto templatious::StaticFactory::skip ( T &&  t,
long  sz 
) -> Skipper<decltype(std::forward<T>(t)),StoragePolicy>
inlinestatic

Skip collection each sz elements. Modifying underlying collection (adding or removing elements) and trying to use this one causes undefined behaviour.

Parameters
[in]tCollection to return range from.
[in]szSkip size.
[in]StoragePolicyStorage policy to specify how to store t. Defaults to templatious::util::DefaultStoragePolicy.

Example:

std::vector<int> v;
SA::add(v,SF::seqL(10));
// v contains {0,1,2,3,4,5,6,7,8,9}
auto r = SF::skip(v,2);
TEMPLATIOUS_FOREACH(int i,r) {
std::cout << i << " ";
}
// prints out
// 0 2 4 6 8
template<template< class...> class Collection = std::vector, template< class > class Allocator = std::allocator, class T , class... Args>
static auto templatious::StaticFactory::skipC ( T &&  t,
Args &&...  args 
) -> typename templatious::adapters::CollectionMaker< typename templatious::adapters:: CollectionAdapter<T>::ValueType, Collection, Allocator >::Collection
inlinestatic

Copy skip collection each sz elements.

Parameters
[in]tCollection to return range from.
[in]szSkip size.
[in]argsArguments which would be passed to simple range function (iterators or indexes).
[in]CollectionCollection type to return. Defaults to std::vector.
[in]AllocatorCollection allocator. Defaults to std::allocator (is ignored if collection doesn't use allocators).

Example:

std::vector<int> v;
SA::add(v,SF::seqL(10));
// v contains {0,1,2,3,4,5,6,7,8,9}
// return type is std::vector<int>
std::vector<int> r = SF::skipC(v,2);
TEMPLATIOUS_FOREACH(int i,r) {
std::cout << i << " ";
}
// prints out
// 0 2 4 6 8
template<template< class > class T, class Stor >
static auto templatious::StaticFactory::storageFunctor ( Stor &&  s) -> T< decltype(std::forward<Stor>(s)) >
inlinestatic

Storage functor to create from special clsses generated with TEMPLATIOUS_CALLEACH_FCTOR_WSTOR macro.

Parameters
[in]sObject to use.
[in]TTemplate to use.
template<class T >
static auto templatious::StaticFactory::streamOutFunctor ( T &  t) -> detail::CallEachStreamFunctor<T&>
inlinestatic

Create a stream functor out of object. For instance

auto sf = StaticFactory::streamOutFunctor(std::cout);
sf("ashes","to","ashes","dust","to","dust");
// upper expression is the same as:
std::cout << "ashes" << "to" << "ashes"
<< "dust" << "to" << "dust";
Parameters
[in]tObject to create stream functor from.
template<class T , template< class > class StoragePolicy = templatious::util::DefaultStoragePolicy>
static auto templatious::StaticFactory::vcollection ( T &&  t) -> VCollection< typename adapters::CollectionAdapter< decltype(std::forward<T>(t)) >::ValueType >
inlinestatic

Get virtual collection handle with all access to collection while hiding the original collection type. This is useful for exposing collection across translation units. Handle doesn't take ownership of it's collection (unless it is passed as rvalue reference) nor is responsible of freeing it. Handle assumes that collection is always valid and not freed.

Parameters
[in]tCollection to virtualize.

Example:

void printAnyCollection(templatious::VCollection<int>& vcol) {
auto b = SA::begin(vcol);
auto e = SA::end(vcol);
while ( b != e ) {
std::cout << *b << " ";
++b;
}
}
..
auto s = SF::seqL(10);
std::vector<int> v;
std::list<int> l;
SA::add(v,s);
SA::add(l,v);
// v and l both contain {0,1,2,3,4,5,6,7,8,9}
auto vl = SF::vcollection(l);
auto vv = SF::vcollection(v);
// function doesn't know any
// difference if it's using
// std::vector or templatious sequence.
printAnyCollection(vs);
printAnyCollection(vv);
template<templatious::AddablePolicy ap = templatious::AP_THROW, templatious::ClearablePolicy cp = templatious::CP_THROW, templatious::TraversablePolicy tp = templatious::TP_THROW, templatious::AccessPolicy acp = templatious::ACP_THROW, templatious::SizablePolicy sp = templatious::SP_THROW, template< class > class StoragePolicy = templatious::util::DefaultStoragePolicy, class T >
static auto templatious::StaticFactory::vcollectionCustom ( T &&  t) -> VCollection< typename adapters::CollectionAdapter<T>::ValueType >
inlinestatic

Make custom virtual collection with custom access to specific functions. Every policy value defaults to THROW. Handle doesn't take ownership of it's collection (unless it is passed as rvalue reference) nor is responsible of freeing it. Handle assumes that collection is always valid and not freed.

Parameters
[in]tCollection to virtualize.
[in]apAddition policy. Specifies whether user is allowed to add or insert elements in collection. Possible enums:
// Throw whenever function
// belonging to the addition section is called.
templatious::AP_THROW
// Fake addition (users
// may try to add elements but
// there would be no effect).
templatious::AP_FAKE
// Enable addition (what would normally happen)
templatious::AP_ENABLED
Functions that belong to this part of the interface:
CollectionAdapter::add
CollectionAdapter::insert
[in]cpClearable policy. Specifies how collection should react to attempts to erase elements. Possible enums:
// Throw whenever function
// belonging to the clear section is called.
templatious::CP_THROW
// Fake removal (users
// may try to erase elements but
// there would be no effect).
templatious::CP_FAKE
// Enable removal (what would normally happen)
templatious::CP_ENABLED
Functions that belong to this part of the interface:
CollectionAdapter::erase
CollectionAdapter::clear
[in]tpTraversible policy. Specifies how collection should react to traverse attempts. Possible enums:
// Throw whenever function
// belonging to the traversal section is called.
templatious::TP_THROW
// Fake traversal. Implemented by
// returning end iterator for both
// begin and end.
templatious::TP_FAKE
// Enable traversal (what would normally happen)
templatious::TP_ENABLED
Functions that belong to this part of the interface:
CollectionAdapter::begin
CollectionAdapter::end
CollectionAdapter::iterAt
CollectionAdapter::cbegin
CollectionAdapter::cend
CollectionAdapter::citerAt
[in]acpAccess policy. Specifies how collection should react to random element access. Possible enums:
// Throw whenever function
// belonging to the access section is called.
templatious::ACP_THROW
// Enable random access (what would normally happen)
templatious::ACP_ENABLED
Functions that belong to this part of the interface:
CollectionAdapter::first
CollectionAdapter::last
CollectionAdapter::getByIndex
CollectionAdapter::cfirst
CollectionAdapter::clast
CollectionAdapter::cgetByIndex
[in]spSizable policy. Specifies whether user is allowed to know collection size. Possible enums:
// Throw whenever user asks for
// collection size.
templatious::SP_THROW
// Fake size (always return 0 when asked)
templatious::SP_FAKE
// Enable size (what would normally happen)
templatious::SP_ENABLED
Functions that belong to this part of the interface:
CollectionAdapter::size
[in]StoragePolicyStorage policy to be used for storing collection. Defaults to templatious::util::DefaultStoragePolicy

Example:

std::vector<int> v;
SA::add(v,1,2,3,4,5,6,7);
auto vcol = SF::vcollectionCustom<
templatious::AP_THROW,
templatious::CP_FAKE,
templatious::TP_FAKE,
templatious::ACP_ENABLED,
templatious::SP_FAKE
>(v);
SA::add(vcol,7); // addition throws
SA::clear(vcol); // fakes clear (no effect)
int sum = 0;
TEMPLATIOUS_FOREACH(auto i,vcol) {
++sum;
}
// traversal faked
assert( sum == 0 );
// access enabled
assert( SA::getByIndex(vcol,6) == 7 );
// size faked
assert( SA::size(vcol) == 0 );
template<templatious::AddablePolicy ap = templatious::AP_THROW, templatious::ClearablePolicy cp = templatious::CP_THROW, templatious::TraversablePolicy tp = templatious::TP_THROW, templatious::AccessPolicy acp = templatious::ACP_THROW, templatious::SizablePolicy sp = templatious::SP_THROW, template< class > class StoragePolicy = templatious::util::DefaultStoragePolicy, class T , class Dtor >
static auto templatious::StaticFactory::vcollectionCustomWDtor ( T &&  t,
Dtor &&  d 
) -> VCollection< typename adapters::CollectionAdapter<T>::ValueType >
inlinestatic

Same as vcollectionCustom but user can specify destructor function when the handle (not the collection) is destroyed.

Parameters
[in]tCollection to virtualize
[in]dDestructor function. Should be callable as d() (without parameters).
[in]apSame as vcollectionCustom.
[in]cpSame as vcollectionCustom.
[in]tpSame as vcollectionCustom.
[in]acpSame as vcollectionCustom.
[in]spSame as vcollectionCustom.
[in]StoragePolicystorage policy for collection as well as function. Defaults to templatious::util::DefaultStoragePolicy.
template<class T , class Dtor , template< class > class StoragePolicy = templatious::util::DefaultStoragePolicy>
static auto templatious::StaticFactory::vcollectionWDtor ( T &&  t,
Dtor &&  d 
) -> VCollection< typename adapters::CollectionAdapter< decltype(std::forward<T>(t)) >::ValueType >
inlinestatic

Same as vcollection but user can specify destructor function when the handle (not the collection) is destroyed.

Parameters
[in]tCollection to virtualize
[in]dDestructor function. Should be callable as d() (without parameters).
[in]StoragePolicystorage policy for collection as well as function. Defaults to templatious::util::DefaultStoragePolicy.

Example:

std::vector<int> v;
bool destroyed = false;
{
auto vc = SF::vcollectionWDtor(v,[&]() {
destroyed = true;
});
}
assert( destroyed );
template<class... Args, class F >
static auto templatious::StaticFactory::virtualMatch ( F &&  f) -> VirtualMatch< decltype(std::forward<F>(f)), false, templatious::util::CopyOnlyStoragePolicy, Args... >
inlinestatic

Create virtual match with default storage policy. This match returns true if it matched, indicating that this match handled the object and stopping further object matching down the line.

Parameters
[in]fFunction to call when matched.
[in]ArgsVirtual pack signature.

Example:

auto p = SF::vpack<int>(7);
auto vmf = SF::virtualMatchFunctor(
SF::virtualMatch<int>(
[](int i) {
std::cout << "A MATCHED" << std::endl;
}
),
SF::virtualMatch<int>(
[](int i) {
std::cout << "NEVER REACHED" << std::endl;
}
)
);
bool matched = vmf.tryMatch(p);
// prints out:
// A MATCHED
assert( matched );
template<template< class > class StoragePolicy, class... Args, class F >
static auto templatious::StaticFactory::virtualMatch ( F &&  f) -> VirtualMatch< decltype(std::forward<F>(f)), false, StoragePolicy, Args... >
inlinestatic

Create virtual match with custom storage policy. This match returns true if it matched, indicating that this match handled the object and stopping further object matching down the line.

Parameters
[in]fFunction to call when matched.
[in]ArgsVirtual pack signature.

Example:

auto p = SF::vpack<int>(7);
auto vmf = SF::virtualMatchFunctor(
SF::virtualMatch<int>(
[](int i) {
std::cout << "A MATCHED" << std::endl;
}
),
SF::virtualMatch<int>(
[](int i) {
std::cout << "NEVER REACHED" << std::endl;
}
)
);
bool matched = vmf.tryMatch(p);
// prints out:
// A MATCHED
assert( matched );
template<template< class > class StoragePolicy = templatious::util::CopyOnlyStoragePolicy, class... T>
static auto templatious::StaticFactory::virtualMatchFunctor ( T &&...  t) -> VirtualMatchFunctorImpl< StoragePolicy, decltype(std::forward<T>(t))... >
inlinestatic

Create stack allocated virtual match functor. This match functor matches only one type of argument - templatious::VirtualPack. Can be used for convenient unpacking of virtual packs directly into function calls.

Virtual match functor can be composed out of virtual matches ( created with templatious::StaticFactory::virtualMatch or templatious::StaticFactory::virtualTransparentMatch ) or out of other virtual match functors.

Function to call for a specific virtual pack is resolved at runtime.

Parameters
[in]tArguments to compose virtual match functor from.

Example:

auto vmfA = SF::virtualMatchFunctor(
SF::virtualMatch<int>(
[](int i) {
std::cout << "MATCHED INT" << std::endl;
}
)
);
auto vmfB = SF::virtualMatchFunctor(
vmfA, // compose first into second
SF::virtualMatch<char>(
[](char i) {
std::cout << "MATCHED CHAR" << std::endl;
}
)
);
auto pInt = SF::vpack<int>(7);
auto pChar = SF::vpack<char>('7');
bool matchedInt = vmfB.tryMatch(pInt);
bool matchedChar = vmfB.tryMatch(pChar);
// prints out:
// MATCHED INT
// MATCHED CHAR
assert( matchedInt );
assert( matchedChar );
template<template< class > class StoragePolicy = templatious::util::CopyOnlyStoragePolicy, class... T>
static auto templatious::StaticFactory::virtualMatchFunctorPtr ( T &&...  t) -> std::unique_ptr< VirtualMatchFunctor >
inlinestatic

Create heap allocated virtual match functor wrapped inside std::unique_ptr. This match functor matches only one type of argument - templatious::VirtualPack. Can be used for convenient unpacking of virtual packs directly into function calls.

Virtual match functor can be composed out of virtual matches ( created with templatious::StaticFactory::virtualMatch or templatious::StaticFactory::virtualTransparentMatch ) or out of other virtual match functors.

Function to call for a specific virtual pack is resolved at runtime.

Parameters
[in]tArguments to compose virtual match functor from.

Example:

auto vmfA = SF::virtualMatchFunctor(
SF::virtualMatch<int>(
[](int i) {
std::cout << "MATCHED INT" << std::endl;
}
)
);
std::unique_ptr< templatious::VirtualMatchFunctor > vmfB =
SF::virtualMatchFunctorPtr(
vmfA, // compose first into second
SF::virtualMatch<char>(
[](char i) {
std::cout << "MATCHED CHAR" << std::endl;
}
)
);
auto pInt = SF::vpack<int>(7);
auto pChar = SF::vpack<char>('7');
bool matchedInt = vmfB->tryMatch(pInt);
bool matchedChar = vmfB->tryMatch(pChar);
// prints out:
// MATCHED INT
// MATCHED CHAR
assert( matchedInt );
assert( matchedChar );
template<class... Args, class F >
static auto templatious::StaticFactory::virtualTransparentMatch ( F &&  f) -> VirtualMatch< decltype(std::forward<F>(f)), true, templatious::util::CopyOnlyStoragePolicy, Args... >
inlinestatic

Create virtual transparent match with default strorage policy. This match returns false even if it matched, passing virtual pack to subsequent matches.

Parameters
[in]fFunction to call when matched.
[in]ArgsVirtual pack signature.

Example:

auto p = SF::vpack<int>(7);
auto vmf = SF::virtualMatchFunctor(
SF::virtualTransparentMatch<int>(
[](int i) {
std::cout << "A MATCHED" << std::endl;
}
),
SF::virtualTransparentMatch<int>(
[](int i) {
std::cout << "B MATCHED" << std::endl;
}
)
);
bool matched = vmf.tryMatch(p);
// prints out:
// A MATCHED
// B MATCHED
assert( !matched );
template<template< class > class StoragePolicy, class... Args, class F >
static auto templatious::StaticFactory::virtualTransparentMatch ( F &&  f) -> VirtualMatch< decltype(std::forward<F>(f)), true, StoragePolicy, Args... >
inlinestatic

Create virtual transparent match with custom strorage policy. This match returns false even if it matched, passing virtual pack to subsequent matches.

Parameters
[in]fFunction to call when matched.
[in]StoragePolicyStorage policy to use for storing function.
[in]ArgsVirtual pack signature.

Example:

auto p = SF::vpack<int>(7);
auto vmf = SF::virtualMatchFunctor(
SF::virtualTransparentMatch<int>(
[](int i) {
std::cout << "A MATCHED" << std::endl;
}
),
SF::virtualTransparentMatch<int>(
[](int i) {
std::cout << "B MATCHED" << std::endl;
}
)
);
bool matched = vmf.tryMatch(p);
// prints out:
// A MATCHED
// B MATCHED
assert( !matched );
template<class... Signature, class... Init>
static auto templatious::StaticFactory::vpack ( Init &&...  vars) -> templatious::VirtualPackImpl< DefVpackSettings, Signature... >
inlinestatic

Create virtual pack which resides on the stack.

Parameters
[in]SignatureSignature of the pack. Should only contain raw types without references. Const qualifiers allowed.
[in]varsVariables to use to initialize pack.
Note
Signature and var count must be the same.
Pointer to this function is a polymorphic pointer of base class templatious::VirtualPack.

Example:

auto p = SF::vpack<long,long>(1,2);
bool aSucc = p.tryCallFunction<long,long>(
[](long a,long b) {
std::cout << a << " " << b << std::endl;
}
);
bool bSucc = p.tryCallFunction<int,long>(
[](long a,long b) {
std::cout << a << " " << b << std::endl;
}
);
assert( aSucc );
assert( !bSucc );
template<class... Signature, class... Init>
static auto templatious::StaticFactory::vpackPtr ( Init &&...  vars) -> std::shared_ptr< VirtualPackImpl< DefVpackSettings,Signature... > >
inlinestatic

Create heap allocated virtual pack wrapped inside std::shared_ptr which could be shared among threads.

Parameters
[in]SignatureSignature of the pack. Should only contain raw types without references. Const qualifiers allowed.
[in]varsVariables to use to initialize pack.
Note
Signature and var count must be the same.
This function returns a polymorphic pointer of base class templatious::VirtualPack.

Example:

std::shared_Ptr< templatious::VirtualPack > p =
SF::vpackPtr<long,long>(1,2);
bool aSucc = p->tryCallFunction<long,long>(
[](long a,long b) {
std::cout << a << " " << b << std::endl;
}
);
bool bSucc = p->tryCallFunction<int,long>(
[](long a,long b) {
std::cout << a << " " << b << std::endl;
}
);
assert( aSucc );
assert( !bSucc );
template<int vpackFlags, class... Signature, class... Init>
static auto templatious::StaticFactory::vpackPtrCustom ( Init &&...  vars) -> std::shared_ptr< VirtualPackImpl< vpackFlags, Signature... > >
inlinestatic

Create heap allocated virtual pack with custom flags indicating the behaviour of the pack.

Parameters
[in]vpackFlagsBitmask of the configuration of the pack. Possible values
// does pack count ivocations?
templatious::VPACK_COUNT
// is pack eligible for waiting
// for the fisr invocation?
templatious::VPACK_WAIT
// is pack thread safe? (if yes, only
// one thread can invoke pack at a time)
templatious::VPACK_SYNCED
// does pack have callback?
// you never need to set this value,
// as this is determined by the function
// you call. If you call vpackPtrWCallback
// or vpackPtrCustomWCallback this is always true,
// if this flag is used on vpackPtrCustom
// static assertion is triggered.
templatious::VPACK_WCALLBACK
[in]SignatureSignature of the pack. Should only contain raw types without references. Const qualifiers allowed.
[in]varsVariables to use to initialize pack.
Note
Signature and var count must be the same.
This function returns a polymorphic pointer of base class templatious::VirtualPack.

Example (synchronization):

auto pack = SF::vpackPtrCustom<
templatious::VPACK_SYNCED,
int,int
>(1,2);
const int ROUNDS = 100000;
auto handleA = std::async(std::launch::async,
[=]() {
TEMPLATIOUS_REPEAT( ROUNDS ) {
pack->tryCallFunction<int,int>(
[](int& a,int& b) {
++a;
++b;
}
);
}
});
auto handleB = std::async(std::launch::async,
[=]() {
TEMPLATIOUS_REPEAT( ROUNDS ) {
pack->tryCallFunction<int,int>(
[](int& a,int& b) {
++a;
++b;
}
);
}
});
handleA.wait();
handleB.wait();
int outA = pack->fGet<0>();
int outB = pack->fGet<1>();
int expA = 1 + ROUNDS * 2;
int expB = 2 + ROUNDS * 2;
assert( outA == expA );
assert( outB == expB );

Example (waiting):

auto pack = SF::vpackPtrCustom<
tt::t::VPACK_WAIT,
int,int
>(1,2);
auto handle = std::async(std::launch::async,
[=]() {
std::this_thread::sleep_for(std::chrono::milliseconds(100));
pack->tryCallFunction<int,int>(
[](int& a,int& b) {
a *= 2;
b *= 2;
}
);
});
pack->wait();
int outA = pack->fGet<0>();
int outB = pack->fGet<1>();
assert( outA == 2 );
assert( outB == 4 );
template<int vpackFlags, class... Signature, class Function , class... Init>
static auto templatious::StaticFactory::vpackPtrCustomWCallback ( Function &&  f,
Init &&...  vars 
) -> std::shared_ptr< VirtualPackImpl< vpackFlags | templatious::VPACK_WCALLBACK, decltype(std::forward<Function>(f)), Signature... > >
inlinestatic

Create heap allocated virtual pack with callback and with custom flags indicating the behaviour of the pack.

Parameters
[in]vpackFlagsBitmask of the configuration of the pack. Possible values
// does pack count ivocations?
templatious::VPACK_COUNT
// is pack eligible for waiting
// for the fisr invocation?
templatious::VPACK_WAIT
// is pack thread safe? (if yes, only
// one thread can invoke pack at a time)
templatious::VPACK_SYNCED
// does pack have callback?
// you never need to set this value,
// as this is determined by the function
// you call. If you call vpackPtrWCallback
// or vpackPtrCustomWCallback this is always true,
// if this flag is used on vpackPtrCustom
// static assertion is triggered.
templatious::VPACK_WCALLBACK
[in]SignatureSignature of the pack. Should only contain raw types without references. Const qualifiers allowed.
[in]fFunction to be used as callback. Should take in const lvalue reference to templatious::VirtualPackCore with it's signature. Always stored as a copy.
[in]varsVariables to use to initialize pack.
Note
Signature and var count must be the same.
This function returns a polymorphic pointer of base class templatious::VirtualPack.

Example (synchronization with callback):

// increment this from threads
auto iPtr = std::make_shared< int >( 0 );
auto pack = SF::vpackPtrCustomWCallback<
templatious::VPACK_SYNCED,
int,int
>([=](const TEMPLATIOUS_VPCORE<int,int>& vp) {
*iPtr += vp.fGet<0>();
*iPtr += vp.fGet<1>();
},1,2);
const int ROUNDS = 100000;
// callbacks must also be synchronized
auto handleA = std::async(std::launch::async,
[=]() {
TEMPLATIOUS_REPEAT( ROUNDS ) {
pack->tryCallFunction<int,int>(
[](int& a,int& b) {}
);
}
});
auto handleB = std::async(std::launch::async,
[=]() {
TEMPLATIOUS_REPEAT( ROUNDS ) {
pack->tryCallFunction<int,int>(
[](int& a,int& b) {}
);
}
});
handleA.wait();
handleB.wait();
int outExpected = (ROUNDS * 2) * (1 + 2);
assert( *iPtr == outExpected );
template<class... Signature, class Function , class... Init>
static auto templatious::StaticFactory::vpackPtrWCallback ( Function &&  f,
Init &&...  vars 
) -> std::shared_ptr< VirtualPackImpl< DefVpackSettings | VPACK_WCALLBACK, decltype(std::forward<Function>(f)), Signature... > >
inlinestatic

Create heap allocated virtual pack with callback wrapped inside std::shared_ptr which could be shared among threads. Callback is called each time this pack is used (after the usage).

Parameters
[in]SignatureSignature of the pack. Should only contain raw types without references. Const qualifiers allowed.
[in]fFunction to be used as callback. Should take in const lvalue reference to templatious::VirtualPackCore with it's signature. Always stored as a copy.
[in]varsVariables to use to initialize pack.
Note
Signature and var count must be the same.
This function returns a polymorphic pointer of base class templatious::VirtualPack.

Example:

volatile long sum = 0;
auto p =
SF::vpackPtrWCallback<long,long>(
[&](const TEMPLATIOUS_VPCORE<long,long>& p) {
sum += p.fGet<0>();
sum += p.fGet<1>();
},
1,2);
bool aSucc = p->tryCallFunction<long,long>(
[](long& a,long& b) {
a *= 2;
b *= 2;
}
);
assert( aSucc );
assert( sum == 6 );

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