/* @copyright Louis Dionne 2014 Distributed under the Boost Software License, Version 1.0. (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) */ #include #include #include #include namespace hana = boost::hana; template struct Incrementable; BOOST_HANA_CONSTEXPR_LAMBDA auto next = [](auto x) { return Incrementable>::next_impl(x); }; BOOST_HANA_CONSTEXPR_LAMBDA auto next_n = [](auto x, unsigned int n) { return Incrementable>::next_n_impl(x, n); }; namespace boost { namespace hana { template <> struct instance { template struct with { }; }; template <> struct defaults { template struct with : defaults<> { template static constexpr auto next_n_impl(X x, unsigned int n) { if (n == 0) return x; else return next_n_impl(next(x), n - 1); } template static constexpr auto next_impl(X x) { return next_n(x, 1); } }; }; }} template struct Incrementable : hana::instance::template with { }; template <> struct Incrementable : hana::defaults::with { static constexpr auto next_impl(int x) { return x + 1; } }; template <> struct Incrementable : hana::defaults::with { static constexpr auto next_n_impl(long x, unsigned int n) { return x + n; } }; int main() { BOOST_HANA_STATIC_ASSERT(next(1) == 2); BOOST_HANA_STATIC_ASSERT(next_n(1, 3) == 4); // default implementation BOOST_HANA_STATIC_ASSERT(next(1l) == 2l); // default implementation BOOST_HANA_STATIC_ASSERT(next_n(1l, 3) == 4l); }