Skip to content

Commit

Permalink
Removed legacy features.
Browse files Browse the repository at this point in the history
  • Loading branch information
Morwenn committed Jul 31, 2015
1 parent 151e0c8 commit 643c391
Show file tree
Hide file tree
Showing 3 changed files with 0 additions and 88 deletions.
23 changes: 0 additions & 23 deletions examples/functional.cpp
Expand Up @@ -64,27 +64,4 @@ int main()
<< memo_lambda(8.5, 44) << '\n'
<< memo_lambda(8.5, 42) << '\n';
}

////////////////////////////////////////////////////////////
// curried
{
auto curry_foo = curried(foo, 10.8);
std::cout << curry_foo(8) << '\n';

auto curry2 = curried(curry_foo, 5);
std::cout << curry2() << '\n';
}

////////////////////////////////////////////////////////////
// compose
{
auto add = [](int a, int b)
{
return a + b;
};
auto add5 = curried(add, 5);

auto composed = compose(add5, foo);
std::cout << composed(15, 5) << '\n';
}
}
52 changes: 0 additions & 52 deletions include/POLDER/details/functional.inl
Expand Up @@ -65,55 +65,3 @@ auto memoized(Function&& func)
using Indices = std::make_index_sequence<arity<Function>>;
return memoized_impl(std::forward<Function>(func), Indices{});
}

////////////////////////////////////////////////////////////
// curried
////////////////////////////////////////////////////////////

template<typename Function, typename First, std::size_t... Ind>
auto curried_impl(Function func, const First& first, std::index_sequence<Ind...>)
{
return [=](argument_type<Function, Ind>... args)
{
return func(first, args...);
};
}

template<typename Function, typename First>
auto curried(Function&& func, First&& first)
{
using FirstArg = argument_type<Function, 0u>;
static_assert(std::is_convertible<First, FirstArg>::value,
"the value to be tied should be convertible to the type of the function's first parameter");

using Indices = index_range<1, arity<Function>>;
return curried_impl(std::forward<Function>(func), std::forward<First>(first), Indices{});
}

////////////////////////////////////////////////////////////
// compose
////////////////////////////////////////////////////////////

template<typename First, typename Second, std::size_t... Ind>
auto compose_impl(First first, Second second, std::index_sequence<Ind...>)
{
return [=](argument_type<Second, Ind>... args)
{
return first(second(args...));
};
}

template<typename First, typename Second>
auto compose(First&& first, Second&& second)
{
static_assert(arity<First> == 1u,
"all the functions passed to compose, except the last one, must take exactly one parameter");

using Ret = result_type<Second>;
using FirstArg = argument_type<First, 0u>;
static_assert(std::is_convertible<Ret, FirstArg>::value,
"incompatible return types in compose");

using Indices = std::make_index_sequence<arity<Second>>;
return compose_impl(std::forward<First>(first), std::forward<Second>(second), Indices{});
}
13 changes: 0 additions & 13 deletions include/POLDER/functional.h
Expand Up @@ -180,19 +180,6 @@ namespace polder
auto memoized(Function&& func)
-> decltype(auto);

////////////////////////////////////////////////////////////
// curried

/**
* @brief Ties the first argument of a function to a value
*
* @param func Function to curry
* @param first Value to tie to \a func
* @return \a func curried with \a first
*/
template<typename Function, typename First>
auto curried(Function&& func, First&& first);

#include "details/functional.inl"
}

Expand Down

0 comments on commit 643c391

Please sign in to comment.