Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/justasmasiulis/args

Header only library for binding, reordering and currying of function arguments without cost
https://github.com/justasmasiulis/args

bind binder cpp cpp14 currying easy-to-use fast functional functional-programming header-only modern modern-cpp monadic optimization reorder reordering simple small type-erasure

Last synced: 16 days ago
JSON representation

Header only library for binding, reordering and currying of function arguments without cost

Awesome Lists containing this project

README

        

# args
A header only functional programming support library without type erasure.

```cpp
void foo(int, float, const char*);

// all of the examples below call foo(1, 2.f, "3") and are optimized out in release builds

auto reordered = args::reorder<2, 0, 1>(foo);
reordered("3", 1, 2.f);

auto bound = args::bind<1>(foo, 2.f);
bound(1, "hello");

auto curried = args::curry<0, 2>(foo);
auto bound2 = curried(1, "3");
bound2(2.f);
```

## quick documentation
* Both functions and arguments are stored by value. Use std::ref to avoid copies.
* Chaining of the library functions is possible.
* Type erasure is not performed.

```cpp
template
constexpr /* callable object */ reorder(Fn&& function);

reorder<2, 0, 1>(void(int, float, const char*)) -> void(const char*, int, float)
```

```cpp
template
constexpr /* callable object */ bind(Fn&& function, Args&&... values_to_bind);

bind<1>(void(int, float, const char*), float) -> void(int, const char*)
```

```cpp
template
constexpr /* callable object */ curry(Fn&& function);

curry<2>(void(int, float, const char*)) -> (void(int, float))(const char*)
```