LeechCraft  0.6.70-16373-g319c272718
Modular cross-platform feature rich live environment.
ctstringutils.h
Go to the documentation of this file.
1 /**********************************************************************
2  * LeechCraft - modular cross-platform feature rich internet client.
3  * Copyright (C) 2006-2014 Georg Rudoy
4  *
5  * Distributed under the Boost Software License, Version 1.0.
6  * (See accompanying file LICENSE or copy at https://www.boost.org/LICENSE_1_0.txt)
7  **********************************************************************/
8 
9 #pragma once
10 
11 #include "ctstring.h"
12 #include <QDebug>
13 
14 namespace LC::Util
15 {
16  constexpr auto Join (auto&&) noexcept
17  {
18  return ""_ct;
19  }
20 
21  constexpr auto Join (auto&& sep, auto&& first, auto&&... strings) noexcept
22  {
23  if constexpr (sizeof... (strings))
24  return first + ((sep + strings) + ...);
25  else
26  return first;
27  }
28 
29  constexpr auto JoinTup (auto&& stringsTuple, auto&& sep) noexcept
30  {
31  return std::apply ([&sep]<typename... Ts> (Ts&&... args) { return Join (sep, std::forward<Ts> (args)...); },
32  stringsTuple);
33  }
34 
35  template<typename Tup1, typename Tup2,
36  size_t Tup1Size = std::tuple_size_v<std::decay_t<Tup1>>,
37  size_t Tup2Size = std::tuple_size_v<std::decay_t<Tup2>>
38  >
39  requires (Tup1Size == Tup2Size)
40  constexpr auto ZipWith (Tup1&& tup1, auto&& sep, Tup2&& tup2) noexcept
41  {
42  return [&]<size_t... I> (std::index_sequence<I...>)
43  {
44  return std::tuple { (std::get<I> (tup1) + sep + std::get<I> (tup2))... };
45  } (std::make_index_sequence<Tup1Size> {});
46  }
47 
48  namespace detail
49  {
50  template<typename T1, typename T2>
51  consteval bool JMEq (const T1& v1, const T2& v2)
52  {
53  if constexpr (!std::is_same_v<T1, T2>)
54  return false;
55  else
56  return v1 == v2;
57  }
58  }
59 
60  template<const auto& F>
61  constexpr auto Nub ()
62  {
63  constexpr auto tup = F ();
64  constexpr auto indices = std::make_index_sequence<std::tuple_size_v<decltype (tup)>> {};
65 
66  return [&]<std::size_t... Ix> (std::index_sequence<Ix...>)
67  {
68  return std::tuple_cat ([&]
69  {
70  constexpr auto thisIndex = Ix;
71  constexpr auto item = std::get<thisIndex> (tup);
72 
73  constexpr auto itemResult = [&]<std::size_t... IxOther> (std::index_sequence<IxOther...>)
74  {
75  if constexpr (((detail::JMEq (item, std::get<IxOther> (tup)) && IxOther < thisIndex) || ...))
76  return std::tuple {};
77  else
78  return std::tuple { item };
79  } (indices);
80  return itemResult;
81  } ()...);
82  } (indices);
83  }
84 
85  template<size_t N, typename Char>
86  QDebug operator<< (QDebug dbg, const CtString<N, Char>& str)
87  {
88  QDebugStateSaver saver { dbg };
89  dbg.nospace () << "CtString[" << N << "] { ";
90  for (size_t i = 0; i < N; ++i)
91  dbg.nospace () << str.Data_ [i];
92  dbg.nospace () << " }";
93  return dbg;
94  }
95 }
auto && sep
Definition: ctstringutils.h:40
constexpr auto Join(auto &&) noexcept
Definition: ctstringutils.h:16
constexpr auto JoinTup(auto &&stringsTuple, auto &&sep) noexcept
Definition: ctstringutils.h:29
const std::tuple< Args... > & tup
Definition: oraltest.cpp:112
consteval bool JMEq(const T1 &v1, const T2 &v2)
Definition: ctstringutils.h:51
requires(Tup1Size==Tup2Size) const expr auto ZipWith(Tup1 &&tup1
auto Tup2 &&tup2 noexcept
Definition: ctstringutils.h:41
constexpr auto Nub()
Definition: ctstringutils.h:61
auto ZipWith(const Container< T1 > &c1, const Container< T2 > &c2, F f) -> WrapType_t< Container< std::decay_t< std::result_of_t< F(T1, T2)>>>>
Definition: prelude.h:37