]> git.proxmox.com Git - ceph.git/blame - ceph/src/boost/libs/hana/test/issues/github_31.cpp
update sources to v12.2.3
[ceph.git] / ceph / src / boost / libs / hana / test / issues / github_31.cpp
CommitLineData
b32b8144 1// Copyright Louis Dionne 2013-2017
7c673cae
FG
2// Distributed under the Boost Software License, Version 1.0.
3// (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt)
4
5#include <boost/hana/any_of.hpp>
6#include <boost/hana/assert.hpp>
7#include <boost/hana/bool.hpp>
8#include <boost/hana/equal.hpp>
9#include <boost/hana/find_if.hpp>
10#include <boost/hana/fwd/at.hpp>
11#include <boost/hana/fwd/drop_front.hpp>
12#include <boost/hana/fwd/is_empty.hpp>
13#include <boost/hana/integral_constant.hpp>
14#include <boost/hana/optional.hpp>
15namespace hana = boost::hana;
16
17
18// A simple infinite Iterable.
19template <int i>
20struct counter { };
21
22namespace boost { namespace hana {
23 template <int i>
24 struct at_impl<counter<i>> {
25 template <typename N>
26 static constexpr auto apply(counter<i>, N const&) {
27 return hana::int_c<i + N::value>;
28 }
29 };
30
31 template <int i>
32 struct drop_front_impl<counter<i>> {
33 template <typename N>
34 static constexpr auto apply(counter<i>, N) { return counter<i + N::value>{}; }
35 };
36
37 template <int i>
38 struct is_empty_impl<counter<i>> {
39 static constexpr auto apply(counter<i>) { return hana::false_c; }
40 };
41}}
42
43
44int main() {
45 // find_if and any_of should short-circuit and stop even though the
46 // Iterable is infinite.
47 BOOST_HANA_CONSTANT_CHECK(hana::any_of(counter<1>{}, hana::equal.to(hana::int_c<4>)));
48
49 BOOST_HANA_CONSTANT_CHECK(hana::equal(
50 hana::find_if(counter<1>{}, hana::equal.to(hana::int_c<4>)),
51 hana::just(hana::int_c<4>)
52 ));
53}