/* @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 #include using namespace boost::hana; struct LazyList; template struct lcons_type { X x; Xs xs; using hana_datatype = LazyList; }; auto lcons = [](auto x, auto xs) { return lcons_type{x, xs}; }; auto repeat = fix([](auto repeat, auto x) { return lcons(x, sandbox::lazy<>(repeat)(x)); }); namespace boost { namespace hana { template <> struct Iterable::instance : Iterable::mcd { template static constexpr auto head_impl(Xs lcons) { return lcons.x; } template static constexpr auto tail_impl(Xs lcons) { return lcons.xs.eval(); } template static constexpr auto is_empty_impl(Xs lcons) { return false_; } }; template <> constexpr bool foldable_from_iterable = true; template <> constexpr bool comparable_from_iterable = true; }} int main() { BOOST_HANA_STATIC_ASSERT(!is_empty(repeat(1))); BOOST_HANA_STATIC_ASSERT(head(repeat(1)) == 1); BOOST_HANA_STATIC_ASSERT(at(int_<10>, repeat(1)) == 1); }