/
find.hpp
74 lines (60 loc) · 2.8 KB
/
find.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
/*==================================================================================================
Copyright (c) 2015 Edouard Alligand and Joel Falcou
Distributed under the Boost Software License, Version 1.0.
(See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt)
=================================================================================================**/
#pragma once
#include <brigand/algorithms/detail/find.hpp>
#include <brigand/algorithms/detail/non_null.hpp>
#include <brigand/algorithms/reverse.hpp>
#include <brigand/sequences/list.hpp>
#include <brigand/sequences/size.hpp>
#include <brigand/types/bool.hpp>
namespace brigand
{
namespace lazy
{
// find uses Predicate, it's very effective
template <typename Sequence, typename Predicate = ::brigand::detail::non_null>
struct find;
template <template <typename...> class Sequence, typename... Ls, typename Pred>
struct find<Sequence<Ls...>, Pred>
: detail::finder<Sequence, detail::bound_apply, Pred>::template find<
false, false, void, void, void, void, void, void, void, void, Ls...>
{
};
template <template <typename...> class Sequence, typename... Ls, template <typename...> class F>
struct find<Sequence<Ls...>, bind<F, _1>>
: detail::finder<Sequence, F>::template find<false, false, void, void, void, void, void,
void, void, void, Ls...>
{
};
}
// find uses Predicate, it's very effective
template <typename Sequence, typename Predicate = brigand::detail::non_null>
using find = typename lazy::find<Sequence, Predicate>::type;
namespace lazy
{
// reverse_find uses reverse and find :o
template <typename Sequence, typename Predicate = detail::non_null>
using reverse_find =
::brigand::lazy::reverse< ::brigand::find<brigand::reverse<Sequence>, Predicate>>;
}
template <typename Sequence, typename Predicate = detail::non_null>
using reverse_find = typename ::brigand::lazy::reverse_find<Sequence, Predicate>::type;
namespace detail
{
template <typename Sequence, typename Predicate>
using find_size = size<brigand::find<Sequence, Predicate>>;
template <typename Sequence, typename Predicate>
using empty_find = bool_<find_size<Sequence, Predicate>::value == 0>;
template <typename Sequence, typename Predicate>
using non_empty_find = bool_<find_size<Sequence, Predicate>::value != 0>;
}
// Utility meta-function to check if nothing was found
template <typename Sequence, typename Predicate = detail::non_null>
using not_found = typename detail::empty_find<Sequence, Predicate>;
// Utility meta-function to check if something was found
template <typename Sequence, typename Predicate = detail::non_null>
using found = typename detail::non_empty_find<Sequence, Predicate>;
}