ORM C++
Loading...
Searching...
No Matches
utilities.cppm
Go to the documentation of this file.
1module;
2
3#include <cstddef>
4#include <string>
5#include <tuple>
6#include <type_traits>
7#include <utility>
8
9export module orm:foundation_utilities;
10
11// utils/ConstexprFor.hpp
12namespace orm::utils
13{
14export
15{
16
17 template <auto Start, auto End, auto Inc, class F, class... Args>
18 constexpr auto constexpr_for(F && f, Args... args) -> void
19 {
20 if constexpr (Start < End)
21 {
22 f(std::integral_constant<decltype(Start), Start>{}, std::forward<Args>(args)...);
23 constexpr_for<Start + Inc, End, Inc>(std::forward<F>(f), std::forward<Args>(args)...);
24 }
25 }
26
27 template <class Tuple, class F, class... Args>
28 constexpr auto constexpr_for_tuple(Tuple && t, F && f, Args... args) -> void
29 {
30 constexpr_for<std::size_t{0}, std::tuple_size_v<std::decay_t<Tuple>>, std::size_t{1}>(
31 [&t, &f, &args...](auto I) { f(I, std::get<I>(std::forward<Tuple>(t)), std::forward<Args>(args)...); });
32 }
33
34 template <class Tuple, class F, class... Args>
35 constexpr auto constexpr_for_tuple(F && f, Args... args) -> void
36 {
37 constexpr_for<std::size_t{0}, std::tuple_size_v<std::decay_t<Tuple>>, std::size_t{1}>(
38 [&f, &args...](auto I)
39 {
40 using field_t = std::tuple_element_t<I, std::decay_t<Tuple>>;
41 f(I, static_cast<field_t>(nullptr), std::forward<Args>(args)...);
42 });
43 }
44}
45} // namespace orm::utils
46
47// utils/StringUtils.hpp
48namespace orm::utils
49{
50export
51{
53 constexpr auto replaceAll(std::string & text, const std::string& toReplace, const std::string& replaceWith) -> void
54 {
55 if (toReplace.empty())
56 {
57 return;
58 }
59
60 size_t start_pos = 0;
61
62 while ((start_pos = text.find(toReplace, start_pos)) != std::string::npos)
63 {
64 text.replace(start_pos, toReplace.length(), replaceWith);
65 start_pos += replaceWith.length();
66 }
67 }
69 auto removeLastComma(std::string & text)->void;
70}
71}
auto removeLastComma(std::string &text) -> void
constexpr auto constexpr_for(F &&f, Args... args) -> void
constexpr auto constexpr_for_tuple(Tuple &&t, F &&f, Args... args) -> void
constexpr auto replaceAll(std::string &text, const std::string &toReplace, const std::string &replaceWith) -> void