mdds
types_util.hpp
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 
3 // SPDX-FileCopyrightText: 2022 - 2025 Kohei Yoshida
4 //
5 // SPDX-License-Identifier: MIT
6 
7 #pragma once
8 
9 #include <vector>
10 
11 namespace mdds { namespace mtv { namespace detail {
12 
13 template<typename T>
15 {
16  using yes_type = char;
17  using no_type = int;
18 
19  template<typename U, typename T::size_type (U::*)() const>
21  {
22  };
23 
24  template<typename U>
25  static yes_type test(test_has_method<U, &U::capacity>*);
26  template<typename U>
27  static no_type test(...);
28 
29  using type = std::conditional_t<sizeof(test<T>(0)) == sizeof(yes_type), std::true_type, std::false_type>;
30 };
31 
32 template<typename T>
33 std::size_t get_block_capacity(const T& blk, std::true_type)
34 {
35  return blk.capacity();
36 }
37 
38 template<typename T>
39 std::size_t get_block_capacity(const T&, std::false_type)
40 {
41  return 0;
42 }
43 
44 template<typename T>
45 std::size_t get_block_capacity(const T& blk)
46 {
47  typename has_capacity_method<T>::type v;
48  return get_block_capacity(blk, v);
49 }
50 
51 template<typename T>
53 {
54  using yes_type = char;
55  using no_type = int;
56 
57  template<typename U, void (U::*)(typename T::size_type)>
59  {
60  };
61 
62  template<typename U>
63  static yes_type test(test_has_method<U, &U::reserve>*);
64  template<typename U>
65  static no_type test(...);
66 
67  using type = std::conditional_t<sizeof(test<T>(0)) == sizeof(yes_type), std::true_type, std::false_type>;
68 };
69 
70 template<typename T>
71 void reserve(T& blk, typename T::size_type size, std::true_type)
72 {
73  return blk.reserve(size);
74 }
75 
76 template<typename T>
77 void reserve(T&, typename T::size_type, std::false_type)
78 {}
79 
80 template<typename T>
81 void reserve(T& blk, typename T::size_type size)
82 {
83  typename has_reserve_method<T>::type v;
84  reserve(blk, size, v);
85 }
86 
87 template<typename T>
89 {
90  using yes_type = char;
91  using no_type = int;
92 
93  template<typename U, void (U::*)()>
95  {
96  };
97 
98  template<typename U>
99  static yes_type test(test_has_method<U, &U::shrink_to_fit>*);
100  template<typename U>
101  static no_type test(...);
102 
103  using type = std::conditional_t<sizeof(test<T>(0)) == sizeof(yes_type), std::true_type, std::false_type>;
104 };
105 
106 template<typename T>
107 void shrink_to_fit(T& blk, std::true_type)
108 {
109  return blk.shrink_to_fit();
110 }
111 
112 template<typename T>
113 void shrink_to_fit(T&, std::false_type)
114 {}
115 
116 template<typename T>
117 void shrink_to_fit(T& blk)
118 {
119  typename has_shrink_to_fit_method<T>::type v;
120  shrink_to_fit(blk, v);
121 }
122 
123 template<typename T>
125 {
126  using type = std::false_type;
127 };
128 
129 template<>
130 struct is_std_vector_bool_store<std::vector<bool>>
131 {
132  using type = std::true_type;
133 };
134 
135 template<typename Blk>
137 {
138  using type = typename is_std_vector_bool_store<typename Blk::store_type>::type;
139 };
140 
141 template<typename T, typename = void>
142 struct has_exec_policy : std::false_type
143 {
144 };
145 
146 template<typename T>
147 struct has_exec_policy<T, std::void_t<typename T::exec_policy>> : std::true_type
148 {
149 };
150 
151 }}} // namespace mdds::mtv::detail
152 
153 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Definition: types_util.hpp:52
Definition: types_util.hpp:124
Definition: types_util.hpp:14
Definition: types_util.hpp:136
Definition: types_util.hpp:142
Definition: cref_wrapper.hpp:12
Definition: types_util.hpp:88