Skip to content

generic programming utilitites for C++ 11; apply/map functions over tuples, etc.

License

Notifications You must be signed in to change notification settings

muellan/generic

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

55 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

AM generic

Header-only collection of generic programming tools for C++11.

Note: All classes and functions are work in progress. Interfaces are still likely to change over time and documentation is limited to some comments so far.

Quick Overview

Classes

integer_sequence

static integer sequence needed for variadic initialization/'exploding' something similar (and most likely better engineered) will be in the C++14 standard library

cached_function

std::function - like wrapper with return value cache

tuple_hash

xors std::hash values of tuple arguments together

Type Traits

all

maps logical AND over a variadic sequence of type traits modeled on std::integral_constant<bool,.>

any

maps logical OR over a variadic sequence of type traits modeled on std::integral_constant<bool,.>

Functions

make_function_composition

composes multiple function objects into one

make_application_chain

chains calls to 'apply(f_i, args...)' for multiple function objects

make_uniform

returns a copy of an object initialized with n times the same value

make_generate

returns a copy of an object initialized with n results obtained by n calls to a generator object

make_copy_elems

returns a copy of an object initialized with n values obtained from n subscript calls (with indices 0...n-1) to a source object

apply(function object, tuple<arguments...>)

explodes tuple arguments into function arguments

map(function object, tuple<arguments...>)

applies a function object to each argument of a tuple of arguments
returns a tuple of results
map(f, {x1,x2,...,xn}) -> {f(x1),f(x2),...,f(xn)}

map(tuple<function_objects...>, arguments...)

applies each function object in a tuple to a series of arguments
returns a tuple of results
map({f1,f2,...,fn}, x1,x2,...,xm) -> {f1(x1,...,xm),...,fn(x1,...,xm)}

zip_map(tuple<function_objects...>, tuple<arguments...>)

applies each function_object to each argument 1-by-1
returns a tuple of results
zip_map({f1,f2,...,fn}, {x1,x2,...,xn}) -> {f1(x1),f2(x2),...,fn(xn)}

for_each_arg(function_object, tuple<arguments...>)

applies a function object to each argument in a tuple of arguments
discards the results and returns void
for_each_arg(f, {x1,x2,...,xn}): {f(x1); f(x2); ...; f(xn);}

for_each_function(tuple<function...>, arguments...)

applies each function object to all arguments in turn
discards the results and returns void
for_each_function({f1,f2,...,fn}, x1,x2,...,xm): {f1(x1,...,xm); ...; fn(x1,...,xm);}

zip_for_each(tuple<function_objects...>, tuple<arguments...>)

applies each function object to each argument 1-by-1
discards the results and returns void
zip_for_each({f1,f2,...,fn}, {x1,x2,...,xn}) {f1(x1); f2(x2); ...; fn(xn);}

Requirements

  • variadic templates
  • template aliases
  • std::tuple
  • std::array
  • std::unordered_map
  • <chrono>
  • <type_traits>

tested with g++ {4.7.2, 5.4, 7.2}, clang++ 5.0.2

About

generic programming utilitites for C++ 11; apply/map functions over tuples, etc.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published