From 95d227cd57893bbdd188408c7b2cf4dfebeff1cb Mon Sep 17 00:00:00 2001 From: Louis Dionne Date: Wed, 23 Jul 2014 20:43:34 -0400 Subject: [PATCH] Lazy: allow calls of the form lazy(f)(). --- include/boost/hana/lazy.hpp | 12 ++++++------ test/lazy/lazy.cpp | 2 ++ 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/include/boost/hana/lazy.hpp b/include/boost/hana/lazy.hpp index 8eb4d9e51..789747f05 100644 --- a/include/boost/hana/lazy.hpp +++ b/include/boost/hana/lazy.hpp @@ -36,10 +36,6 @@ namespace boost { namespace hana { //! functionality would require evaluating the lazy values in most cases. //! Since this raises some issues such as side effects and memoization, //! the data type is kept simple. - //! - //! @todo - //! Right now, we can't do `lazy(f)()` because `ap(f)` is invalid. How - //! should we fix this? struct Lazy { }; //! Evaluate a lazy value and return it. @@ -69,8 +65,12 @@ namespace boost { namespace hana { //! //! Additionally, `lazy(f)` is a function such that `lazy(f)(x1, ..., xN)` //! is equivalent to `ap(lazy(f), lift(x1), ..., lift(xN))`, - //! which is in turn equivalent to `lazy(f(x1, ..., xN))`, except for the - //! fact that the inner call to `f` is evaluated lazily. + //! which in turn is equivalent to `lazy(f(x1, ..., xN))`, except for the + //! fact that the inner call to `f` is evaluated lazily. Note that + //! `lazy(f)()` is equivalent to `lazy(f())`, with the inner call to + //! `f` being evaluated lazily. This is provided for convenience even + //! though `ap(lazy(f))` would be invalid because `ap` requires 2 + //! arguments or more. //! //! ### Example //! @snippet example/lazy/lazy.cpp main diff --git a/test/lazy/lazy.cpp b/test/lazy/lazy.cpp index 0fd4f5fe8..4b6537610 100644 --- a/test/lazy/lazy.cpp +++ b/test/lazy/lazy.cpp @@ -27,11 +27,13 @@ template constexpr auto x = detail::minimal::comparable<>(i); int main() { + BOOST_HANA_STATIC_ASSERT(lazy(f)() == lazy(f())); BOOST_HANA_STATIC_ASSERT(lazy(f)(x<0>) == lazy(f(x<0>))); BOOST_HANA_STATIC_ASSERT(lazy(f)(x<0>, x<1>) == lazy(f(x<0>, x<1>))); BOOST_HANA_STATIC_ASSERT(lazy(f)(x<0>, x<1>, x<2>) == lazy(f(x<0>, x<1>, x<2>))); // The function is not applied. + lazy(invalid)(); lazy(invalid)(x<0>); lazy(invalid)(x<0>, x<1>); lazy(invalid)(x<0>, x<1>, x<2>);