The decorate function adaptor helps create simple function decorators.

A function adaptor takes a function and returns a new functions whereas a decorator takes some parameters and returns a function adaptor. The decorate function adaptor will return a decorator that returns a function adaptor. Eventually, it will invoke the function with the user- provided parameter and function.


template<class F>
constexpr decorate_adaptor<F> decorate(F f);


assert(decorate(f)(x)(g)(xs...) == f(x, g, xs...));


F must be:


#include <fit.hpp>
#include <cassert>
#include <iostream>
#include <string>
using namespace fit;

struct logger_f
    template<class F, class... Ts>
    auto operator()(const std::string& message, F&& f, Ts&&... xs) const 
        -> decltype(f(std::forward<Ts>(xs)...))
        // Message to print out when the function is called
        std::cout << message << std::endl;
        // Call the function
        return f(std::forward<Ts>(xs)...);
// The logger decorator
FIT_STATIC_FUNCTION(logger) = fit::decorate(logger_f());

struct sum_f
    template<class T, class U>
    T operator()(T x, U y) const
        return x+y;

FIT_STATIC_FUNCTION(sum) = sum_f();
int main() {
    // Use the logger decorator to print "Calling sum" when the function is called
    assert(3 == logger("Calling sum")(sum)(1, 2));