Skip to content

Commit 9d5f88e

Browse files
author
Cppshizoid
committed
in progress for add old stuff from archive
1 parent ee000c6 commit 9d5f88e

File tree

12 files changed

+3715
-19
lines changed

12 files changed

+3715
-19
lines changed

CMakeLists.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,13 @@ add_subdirectory(src)
5252
add_subdirectory(lib)
5353
# add tests
5454
set(BUILD_ALL_TESTS
55-
ON
55+
OFF
5656
CACHE BOOL "Build all tests" FORCE)
5757
message(
5858
STATUS "BUILD_ALL_TESTS value: ${BUILD_ALL_TESTS} (defined at ${CMAKE_CURRENT_LIST_FILE}:${CMAKE_CURRENT_LIST_LINE})")
5959
enable_testing()
60-
option(BUILD_ALL_TESTS "Build tests" ON)
61-
add_subdirectory(tests)
60+
option(BUILD_ALL_TESTS "Build tests" OFF)
61+
#add_subdirectory(tests)
6262

6363
include(cmake/BuildConfiguration.cmake)
6464

lib/CMakeLists.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@ add_subdirectory(library1)
33
add_subdirectory(library2)
44

55
# Настройка тестов
6-
option(BUILD_TESTS "Build tests" ON)
7-
option(BUILD_ALL_TESTS "Build all tests automatically" ON)
6+
option(BUILD_TESTS "Build tests" OFF)
7+
option(BUILD_ALL_TESTS "Build all tests automatically" OFF)
88

99
if(BUILD_TESTS)
10-
enable_testing()
11-
find_package(GTest REQUIRED)
10+
# enable_testing()
11+
# find_package(GTest REQUIRED)
1212

1313
if(BUILD_ALL_TESTS)
1414
# Добавляем тестовые поддиректории
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
/**
2+
* @file
3+
* @brief Meta-programming utilities for working with packs of types and values.
4+
*/
5+
6+
#pragma once
7+
8+
#include <type_traits>
9+
#include <utility>
10+
11+
namespace core::meta::utils {
12+
13+
/**
14+
* @brief A pack of auto (non-type) template parameters.
15+
* @tparam Args The non-type template parameters.
16+
*/
17+
template <auto... Args>
18+
struct auto_pack {
19+
using type = auto_pack<Args...>; ///< The type of this pack.
20+
21+
static constexpr size_t value =
22+
sizeof...(Args); ///< Number of elements in the pack.
23+
24+
/**
25+
* @brief Gets the number of elements in the pack.
26+
* @return The size of the pack.
27+
*/
28+
static constexpr size_t size() noexcept { return value; }
29+
};
30+
31+
/**
32+
* @brief A pack of type template parameters.
33+
* @tparam Args The type template parameters.
34+
*/
35+
template <typename... Args>
36+
struct type_pack {
37+
using type = type_pack<Args...>; ///< The type of this pack.
38+
39+
static constexpr size_t value =
40+
sizeof...(Args); ///< Number of elements in the pack.
41+
42+
/**
43+
* @brief Gets the number of elements in the pack.
44+
* @return The size of the pack.
45+
*/
46+
static constexpr size_t size() noexcept { return value; }
47+
};
48+
49+
/**
50+
* @brief A pack combining a type and auto template parameters.
51+
* @tparam T The leading type parameter.
52+
* @tparam Args The non-type template parameters.
53+
*/
54+
template <typename T, auto... Args>
55+
struct args_pack {
56+
using type = args_pack<T, Args...>; ///< The type of this pack.
57+
58+
static constexpr size_t value =
59+
sizeof...(Args); ///< Number of non-type elements in the pack.
60+
61+
/**
62+
* @brief Gets the number of non-type elements in the pack.
63+
* @return The size of the pack.
64+
*/
65+
static constexpr size_t size() noexcept { return value; }
66+
};
67+
68+
/**
69+
* @brief Primary template for getting the size of a pack.
70+
* @tparam T The pack type to examine.
71+
* @note The primary template has size 0.
72+
*/
73+
template <typename T>
74+
struct pack_size : std::integral_constant<size_t, 0> {};
75+
76+
/**
77+
* @brief Specialization for auto_pack-like types.
78+
* @tparam T The template template parameter.
79+
* @tparam U The non-type template parameters.
80+
*/
81+
template <template <auto...> typename T, auto... U>
82+
struct pack_size<T<U...>> : std::integral_constant<size_t, sizeof...(U)> {};
83+
84+
/**
85+
* @brief Specialization for type_pack-like types.
86+
* @tparam T The template template parameter.
87+
* @tparam U The type template parameters.
88+
*/
89+
template <template <typename...> typename T, typename... U>
90+
struct pack_size<T<U...>> : std::integral_constant<size_t, sizeof...(U)> {};
91+
92+
/**
93+
* @brief Specialization for args_pack-like types.
94+
* @tparam T The template template parameter.
95+
* @tparam U The leading type parameter.
96+
* @tparam V The non-type template parameters.
97+
*/
98+
template <template <typename, auto...> typename T, typename U, auto... V>
99+
struct pack_size<T<U, V...>> : std::integral_constant<size_t, sizeof...(V)> {};
100+
101+
/**
102+
* @brief Helper variable template for pack_size.
103+
* @tparam T The pack type to examine.
104+
*/
105+
template <typename T>
106+
inline constexpr auto pack_size_v = pack_size<T>::value;
107+
108+
} // namespace core::meta::utils
Lines changed: 145 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
1+
#pragma once
2+
3+
#include <type_traits>
4+
5+
#include "../meta_funcs/metafuncs_utility.hpp"
6+
#include "./sequence.hpp"
7+
#include "./tuple_utils.hpp"
8+
9+
namespace core::meta::utils {
10+
11+
/**
12+
* @brief Expands a template with index-based transformations
13+
*
14+
* @tparam F Template template parameter to apply
15+
* @tparam T Input type to transform
16+
* @tparam U Index sequence for expansion
17+
* @tparam values... Sequence of values
18+
* @tparam N Sequence of indices
19+
* @tparam V Offset value for indices
20+
*
21+
* Specialization for types with value parameters and true condition
22+
*/
23+
template <template <auto, typename> typename F,
24+
template <typename, auto...> typename T, typename U, auto... values,
25+
auto... N>
26+
struct expand<F, T<U, values...>, std::index_sequence<N...>, true> {
27+
using args = T<U, values...>; ///< Original argument type
28+
using type = tuple_t<c_<typev<F<N, args>>, U>...>; ///< Resulting tuple type
29+
};
30+
31+
/**
32+
* @brief Expands a template with index-based transformations
33+
*
34+
* Specialization for types with value parameters and false condition
35+
*/
36+
template <template <auto, typename> typename F,
37+
template <typename, auto...> typename T, typename U, auto... values,
38+
auto... N>
39+
struct expand<F, T<U, values...>, std::index_sequence<N...>, false> {
40+
using args = T<U, values...>; ///< Original argument type
41+
using type = tuple_t<
42+
index_type<N, c_<typev<F<N, args>>, U>>...>; ///< Resulting tuple type
43+
///< with indexed elements
44+
};
45+
46+
/**
47+
* @brief Empty expansion case for regular template types
48+
*
49+
* Specialization when index sequence is empty
50+
*/
51+
template <template <auto, typename> typename F,
52+
template <typename...> typename T, typename... Args, auto V>
53+
struct expand<F, T<Args...>, std::index_sequence<>, V> {
54+
using type = clear_t<T<Args...>>; ///< Cleared input type
55+
};
56+
57+
/**
58+
* @brief Empty expansion case for value-parameterized types
59+
*
60+
* Specialization when index sequence is empty
61+
*/
62+
template <template <auto, typename> typename F,
63+
template <typename, auto...> typename T, typename U, auto... values,
64+
auto V>
65+
struct expand<F, T<U, values...>, std::index_sequence<>, V> {
66+
using type = clear_t<T<U, values...>>; ///< Cleared input type
67+
};
68+
69+
/**
70+
* @brief General expansion implementation
71+
*
72+
* Handles both tuple-like and integer sequence outputs
73+
*/
74+
template <template <auto, typename> typename F, typename T, auto... N, auto V>
75+
struct expand<F, T, std::index_sequence<N...>, V> {
76+
/**
77+
* @brief Implementation for tuple-like output
78+
*/
79+
template <typename W, bool b>
80+
struct impl {
81+
using type =
82+
tuple_t<typeof_t<F<N + V, W>>...>; ///< Tuple of transformed types
83+
};
84+
85+
/**
86+
* @brief Implementation for integer sequence output
87+
*/
88+
template <typename W>
89+
struct impl<W, false> {
90+
using type = std::integer_sequence<
91+
W, typev<F<N + V, W>>...>; ///< Integer sequence of transformed values
92+
};
93+
94+
using head = typeof_t<
95+
F<head_v<std::index_sequence<N...>, V>, T>>; ///< First transformed type
96+
using type =
97+
typeof_t<impl<T, negav<has_value_type<head>>>>; ///< Select appropriate
98+
///< implementation
99+
};
100+
101+
/**
102+
* @brief Empty expansion case
103+
*/
104+
template <template <auto, typename> typename F, typename T, auto V>
105+
struct expand<F, T, std::index_sequence<>, V> {
106+
using type = tuple_t<>; ///< Empty tuple result
107+
};
108+
109+
/**
110+
* @brief Convenience alias for expand::type
111+
*/
112+
template <template <auto, typename> typename F, typename T,
113+
typename U = index_sequence_of_t<T>, auto V = 0>
114+
using expand_t = typeof_t<expand<F, T, U, V>>;
115+
116+
/**
117+
* @brief Conditional expansion
118+
*
119+
* Expands only if condition B is true, otherwise returns original type
120+
*/
121+
template <bool B, template <auto, typename> typename F, typename T,
122+
typename U = index_sequence_of_t<T>, auto V = 0>
123+
using expand_if =
124+
std::conditional_t<B, expand<F, T, U, V>, std::type_identity<T>>;
125+
126+
/**
127+
* @brief Convenience alias for expand_if::type
128+
*/
129+
template <bool B, template <auto, typename> typename F, typename T,
130+
typename U = index_sequence_of_t<T>, auto V = 0>
131+
using expand_if_t = typeof_t<expand_if<B, F, T, U, V>>;
132+
133+
/**
134+
* @brief Expansion using element extraction
135+
*/
136+
template <typename T, typename U = index_sequence_of_t<T>, auto V = 0>
137+
using expand_of = expand<element, T, U, V>;
138+
139+
/**
140+
* @brief Convenience alias for expand_of::type
141+
*/
142+
template <typename T, typename U = index_sequence_of_t<T>, auto V = 0>
143+
using expand_of_t = typeof_t<expand_of<T, U, V>>;
144+
145+
} // namespace core::meta::utils
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#pragma once
2+
3+
#include "./expand.hpp"
4+
5+
namespace core::meta::utils {
6+
7+
template <auto n, typename T>
8+
struct fill {
9+
template <auto N, typename U>
10+
struct impl : U {};
11+
12+
template <template <auto, typename> typename F>
13+
using call = expand<F, T, index_sequence_of_c<n>>;
14+
15+
using curr = type_if<!has_type_v<T> || !has_value_type_v<T>, call<identity>,
16+
call<impl>>;
17+
using type = rename_if_t<is_variadic_type_v<T>, curr, std::tuple<>>;
18+
};
19+
20+
template <auto n, typename T>
21+
using fill_t = typeof_t<fill<n, T>>;
22+
23+
template <auto n, auto v>
24+
using fill_c = typeof_t<fill<n, c_<v>>>;
25+
26+
template <typename T, typename U>
27+
struct assign : rename<fill_t<sizeof_t_v<T>, U>, clear_t<T>> {};
28+
29+
template <typename T, typename U>
30+
using assign_t = typeof_t<assign<T, U>>;
31+
32+
template <auto N, template <typename...> typename T>
33+
struct nest_fill : to_nest<fill_t<N, T<>>> {};
34+
35+
template <auto N, template <typename...> typename T>
36+
using nest_fill_t = typeof_t<nest_fill<N, T>>;
37+
} // namespace core::meta::utils

0 commit comments

Comments
 (0)