-
Notifications
You must be signed in to change notification settings - Fork 0
/
search_view.hpp
118 lines (108 loc) · 2.61 KB
/
search_view.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
#pragma once
#include "concepts.hpp"
namespace
{
namespace O1
{
// seacrh view template
template<std::input_or_output_iterator It>
struct seacrh_view
{
// type definitions
using T = std::iter_value_t<It>;
using reference_type = std::reference_wrapper<T>;
// data members
It observable_begin_iterator, observable_end_iterator;
std::unordered_multiset<reference_type, reference::hash<reference_type>,
reference::equal_to<reference_type>, std::allocator<reference_type>> configuration;
// ctors/dtor
seacrh_view()
:observable_begin_iterator{},
observable_end_iterator{},
configuration{}
{
}
seacrh_view(It begin, It end)
:observable_begin_iterator{ begin },
observable_end_iterator{ end },
configuration{}
{
update();
}
virtual ~seacrh_view() = default;
// observable iterators setter
auto set_observable_iterators(It begin, It end) -> void
{
observable_begin_iterator = begin;
observable_end_iterator = end;
}
// update method
constexpr auto update() -> void
{
configuration.clear();
std::ranges::for_each(
observable_begin_iterator,
observable_end_iterator,
[this](auto& value)
{
configuration.emplace(std::ref(value));
}
);
}
// display method
auto show(std::ostream& os) -> void
{
std::ranges::for_each(
configuration,
[&os](auto& e)
{
os << e.get() << '\t' << reinterpret_cast<uintptr_t>(&(e.get())) << '\n';
}
);
}
auto show(std::ofstream& os) -> void
{
std::ranges::for_each(
configuration,
[&os](auto& e)
{
os << e.get() << '\t' << reinterpret_cast<uintptr_t>(&(e.get())) << '\n';
}
);
}
auto show(std::wostream& os) -> void
{
std::ranges::for_each(
configuration,
[&os](auto& e)
{
os << e.get() << '\t' << reinterpret_cast<uintptr_t>(&(e.get())) << '\n';
}
);
}
auto show(std::wofstream& os) -> void
{
std::ranges::for_each(
configuration,
[&os](auto& e)
{
os << e.get() << '\t' << reinterpret_cast<uintptr_t>(&(e.get())) << '\n';
}
);
}
// find methods
constexpr decltype(auto) find(std::iter_value_t<It> value)
{
return configuration.find(std::ref(value));
}
constexpr decltype(auto) find(reference_type value_ref)
{
return configuration.find(value_ref);
}
// size method
constexpr auto size() const->size_t { return configuration.size(); }
// size of data in bytes
constexpr auto size_of_data_in_bytes() const->size_t { return size_of::data_in_bytes(configuration); }
};
}
}