Functional

Flex Functions

Warning

doxygenfile: Cannot find file “tools/flex_function.hpp

Function Sets

Setup a collection of functions, all with the same signature, that can be run as a group.

Note

This file is part of Empirical, https://github.com/devosoft/Empirical

Copyright

Copyright (C) Michigan State University, MIT Software license; see doc/LICENSE.md

Date

2016-2017

Note

Status: BETA

namespace emp

If we are in emscripten, make sure to include the header.

template<typename T>
class FunctionSet
template<typename RETURN_T, typename ...ARGS>
class FunctionSet<RETURN_T(ARGS...)> : public emp::vector<std::function<RETURN_T(ARGS...)>>
#include <FunctionSet.hpp>

A vector of functions that can all be triggered at onece; results can either be returned in a vector or post-processed in a function (such as max, min, etc.) Derived from emp::vector, hence with all of the same methods as vector.

Public Types

using base_t = emp::vector<std::function<RETURN_T(ARGS...)>>
using value_type = typename base_t::value_type
using return_t = RETURN_T

Public Functions

FunctionSet()
~FunctionSet()
size_t GetSize() const

How many functions are in this FunctionSet?

void Add(const value_type &in_fun)

Add a new funtion to this FunctionSet.

void Remove(size_t pos)

Remove the function at a specified position.

const emp::vector<RETURN_T> &Run(ARGS... args) const

Run all functions and return a vector of all results.

RETURN_T Run(ARGS... args, std::function<RETURN_T(RETURN_T, RETURN_T)> comp_fun, RETURN_T default_val = 0, ) const

If you want to provide a filter function, you can retrieve a specific return value. The filter should take in two return values and indicate which is “better”.

RETURN_T FindMax(ARGS... args, RETURN_T default_val = 0) const

Run all functions and return the highest value.

RETURN_T FindMin(ARGS... args, RETURN_T default_val = 0) const

Run all functions and return the lowest value.

RETURN_T FindSum(ARGS... args, RETURN_T default_val = 0) const

Run all functions and return the total value.

RETURN_T FindProduct(ARGS... args, RETURN_T default_val = 1) const

Run all functions and return a product of all values.

Protected Attributes

emp::vector<RETURN_T> return_vals
template<typename ...ARGS>
class FunctionSet<void(ARGS...)> : public emp::vector<std::function<void(ARGS...)>>
#include <FunctionSet.hpp>

A specialized version of FunctionSet for void functions.

Public Types

using base_t = emp::vector<std::function<void(ARGS...)>>
using value_type = typename base_t::value_type
using return_t = void

Public Functions

FunctionSet()
~FunctionSet()
size_t GetSize() const

How many functions are in this FunctionSet?

void Add(const std::function<void(ARGS...)> &in_fun)

Add a new function to this FunctionSet.

void Remove(size_t pos)

Remove the function at the designated position from this FunctionSet.

void Run(ARGS... args) const

Run all functions in the FunctionSet.

Generic Functions

Warning

doxygenfile: Cannot find file “emp/functional/GenericFunctions.hpp

Memoized Functions

Warning

doxygenfile: Cannot find file “emp/functional/memo_functions.hpp