Created
December 16, 2013 18:51
-
-
Save splinterofchaos/7992250 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/include/ftl/function.h b/include/ftl/function.h | |
index 1911efa..605db4f 100644 | |
--- a/include/ftl/function.h | |
+++ b/include/ftl/function.h | |
@@ -331,6 +331,7 @@ namespace ftl { | |
/* TODO: Make currying work even when we give N > 1, N < Nparams | |
* arguments to a function of Nparams parameters. | |
*/ | |
+ | |
template<typename...> | |
struct curried {}; | |
@@ -341,24 +342,17 @@ namespace ftl { | |
} | |
}; | |
- template<typename R, typename P> | |
- struct curried<R,P> { | |
- function<R()> operator()(P) const { | |
- throw(std::logic_error("Curried calling of parameterless function")); | |
- } | |
- }; | |
- | |
- template<typename R, typename P1, typename P2, typename...Ps> | |
- struct curried<R,P1,P2,Ps...> { | |
- | |
- function<R(P2,Ps...)> operator() (P1 p1) const { | |
- auto self = *reinterpret_cast<const function<R(P1,P2,Ps...)>*>(this); | |
- return [self,p1] (P2 p2, Ps...ps) { | |
- return self.operator()(p1, std::forward<P2>(p2), std::forward<Ps>(ps)...); | |
- }; | |
- } | |
- }; | |
- | |
+ template< typename R, typename P1, typename ...Ps > | |
+ struct curried<R,P1,Ps...> { | |
+ function<R(Ps...)> operator()(P1 p) const { | |
+ if( sizeof ...(Ps) == 0 ) | |
+ throw(std::logic_error("Curried calling of parameterless function")); | |
+ auto self = *reinterpret_cast<const function<R(P1,Ps...)>*>(this); | |
+ return [self,p] ( Ps...ps ) { | |
+ return self(p, std::forward<Ps>(ps)...); | |
+ }; | |
+ } | |
+ }; | |
} | |
/** |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment