diff --git a/include/boost/hana/comparable.hpp b/include/boost/hana/comparable.hpp index 2a9cbbb7d..832fbd56c 100644 --- a/include/boost/hana/comparable.hpp +++ b/include/boost/hana/comparable.hpp @@ -13,6 +13,7 @@ #define BOOST_HANA_COMPARABLE_HPP #include +#include namespace boost { namespace hana { @@ -20,17 +21,13 @@ namespace boost { namespace hana { template struct Comparable; - constexpr struct _equal { - template - constexpr auto operator()(T t, U u) const - { return Comparable::equal_impl(t, u); } - } equal{}; + BOOST_HANA_CONSTEXPR_LAMBDA auto equal = [](auto x, auto y) { + return Comparable::equal_impl(x, y); + }; - constexpr struct _not_equal { - template - constexpr auto operator()(T t, U u) const - { return Comparable::not_equal_impl(t, u); } - } not_equal{}; + BOOST_HANA_CONSTEXPR_LAMBDA auto not_equal = [](auto x, auto y) { + return Comparable::not_equal_impl(x, y); + }; template <> struct defaults { diff --git a/include/boost/hana/detail/constexpr.hpp b/include/boost/hana/detail/constexpr.hpp new file mode 100644 index 000000000..b485c5e19 --- /dev/null +++ b/include/boost/hana/detail/constexpr.hpp @@ -0,0 +1,22 @@ +/*! + * @file + * Defines the `BOOST_HANA_CONSTEXPR_LAMBDA` macro. + * + * + * @copyright Louis Dionne 2014 + * Distributed under the Boost Software License, Version 1.0. + * (See accompanying file LICENSE.md or copy at + * http://www.boost.org/LICENSE_1_0.txt) + */ + +#ifndef BOOST_HANA_DETAIL_CONSTEXPR_HPP +#define BOOST_HANA_DETAIL_CONSTEXPR_HPP + +/*! + * @ingroup details + * Expands to `constexpr` if constexpr lambdas are supported and + * to `const` otherwise. + */ +#define BOOST_HANA_CONSTEXPR_LAMBDA const + +#endif // !BOOST_HANA_DETAIL_CONSTEXPR_HPP \ No newline at end of file diff --git a/include/boost/hana/foldable.hpp b/include/boost/hana/foldable.hpp index dc535d5b9..3475ffbb5 100644 --- a/include/boost/hana/foldable.hpp +++ b/include/boost/hana/foldable.hpp @@ -13,6 +13,7 @@ #define BOOST_HANA_FOLDABLE_HPP #include +#include #include #include @@ -22,65 +23,47 @@ namespace boost { namespace hana { template struct Foldable; - constexpr struct _foldl { - template - constexpr auto operator()(F f, State s, Foldable_ foldable) const - { return Foldable::foldl_impl(f, s, foldable); } - } foldl{}; + BOOST_HANA_CONSTEXPR_LAMBDA auto foldl = [](auto f, auto state, auto foldable) { + return Foldable::foldl_impl(f, state, foldable); + }; - constexpr struct _foldr { - template - constexpr auto operator()(F f, State s, Foldable_ foldable) const - { return Foldable::foldr_impl(f, s, foldable); } - } foldr{}; + BOOST_HANA_CONSTEXPR_LAMBDA auto foldr = [](auto f, auto state, auto foldable) { + return Foldable::foldr_impl(f, state, foldable); + }; - constexpr struct _foldr1 { - template - constexpr auto operator()(F f, Foldable_ foldable) const - { return Foldable::foldr1_impl(f, foldable); } - } foldr1{}; + BOOST_HANA_CONSTEXPR_LAMBDA auto foldr1 = [](auto f, auto foldable) { + return Foldable::foldr1_impl(f, foldable); + }; - constexpr struct _foldl1 { - template - constexpr auto operator()(F f, Foldable_ foldable) const - { return Foldable::foldl1_impl(f, foldable); } - } foldl1{}; + BOOST_HANA_CONSTEXPR_LAMBDA auto foldl1 = [](auto f, auto foldable) { + return Foldable::foldl1_impl(f, foldable); + }; - constexpr struct _minimum { - template - constexpr auto operator()(Foldable_ foldable) const - { return Foldable::minimum_impl(foldable); } - } minimum{}; - constexpr struct _maximum { - template - constexpr auto operator()(Foldable_ foldable) const - { return Foldable::maximum_impl(foldable); } - } maximum{}; + BOOST_HANA_CONSTEXPR_LAMBDA auto minimum_by = [](auto pred, auto foldable) { + return Foldable::minimum_by_impl(pred, foldable); + }; - constexpr struct _maximum_by { - template - constexpr auto operator()(Pred pred, Foldable_ foldable) const - { return Foldable::maximum_by_impl(pred, foldable); } - } maximum_by{}; + BOOST_HANA_CONSTEXPR_LAMBDA auto minimum = [](auto foldable) { + return Foldable::minimum_impl(foldable); + }; - constexpr struct _minimum_by { - template - constexpr auto operator()(Pred pred, Foldable_ foldable) const - { return Foldable::minimum_by_impl(pred, foldable); } - } minimum_by{}; + BOOST_HANA_CONSTEXPR_LAMBDA auto maximum_by = [](auto pred, auto foldable) { + return Foldable::maximum_by_impl(pred, foldable); + }; - constexpr struct _sum { - template - constexpr auto operator()(Foldable_ foldable) const - { return Foldable::sum_impl(foldable); } - } sum{}; + BOOST_HANA_CONSTEXPR_LAMBDA auto maximum = [](auto foldable) { + return Foldable::maximum_impl(foldable); + }; + + BOOST_HANA_CONSTEXPR_LAMBDA auto sum = [](auto foldable) { + return Foldable::sum_impl(foldable); + }; + + BOOST_HANA_CONSTEXPR_LAMBDA auto product = [](auto foldable) { + return Foldable::product_impl(foldable); + }; - constexpr struct _product { - template - constexpr auto operator()(Foldable_ foldable) const - { return Foldable::product_impl(foldable); } - } product{}; template <> struct defaults { diff --git a/include/boost/hana/functional.hpp b/include/boost/hana/functional.hpp index df17da35c..4b56a3f94 100644 --- a/include/boost/hana/functional.hpp +++ b/include/boost/hana/functional.hpp @@ -12,6 +12,9 @@ #ifndef BOOST_HANA_FUNCTIONAL_HPP #define BOOST_HANA_FUNCTIONAL_HPP +#include + + namespace boost { namespace hana { template