-
Notifications
You must be signed in to change notification settings - Fork 0
/
string_manip.hpp
77 lines (62 loc) · 1.92 KB
/
string_manip.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
#pragma once
#include <algorithm>
#include <cstddef>
#include <tuple>
#include <utility>
#include"get_nth_element.hpp"
namespace mlib
{
template <std::size_t i>
struct fixed_string_ {
constexpr fixed_string_(const char(&arr)[i + 1]) {
std::copy_n(arr, i + 1, data);
}
constexpr fixed_string_(char(&arr)[i + 1])
{
std::copy_n(arr, i + 1, data);
}
constexpr auto size() const { return i; }
auto operator<=>(const fixed_string_&) const = default;
template<auto J>
constexpr auto nth_element() const { return data[J]; }
auto data_()
{
return data;
}
char data[i + 1] = {};
};
template <std::size_t i>
fixed_string_(const char(&arr)[i])->fixed_string_<i - 1>;
template <std::size_t i>
fixed_string_(char(&arr)[i])->fixed_string_<i - 1>;
template <fixed_string_ s>
struct manipulate_str {
constexpr auto operator()()
{
}
template <auto T>
constexpr auto on_all()
{
return[]<std::size_t... indexes>(std::index_sequence<indexes...>)
{
char arr[] = { T(s.template nth_element<indexes>())... };
return fixed_string_{ arr };
}(std::make_index_sequence<s.size()>{});
}
template<auto I>
constexpr auto get_until()
{
return[]<std::size_t... indexes>(std::index_sequence<indexes...>) {
char arr[I + 1] = { s.template nth_element<indexes>()... };
arr[I] = 0;
return fixed_string_{ arr };
}(std::make_index_sequence<I>{});
}
template<std::size_t... indexes>
constexpr auto select()
{
char arr[sizeof...(indexes)] = {s.template nth_element<indexes>()...};
return fixed_string_{arr};
}
};
} // namespace mlib