mdds
Loading...
Searching...
No Matches
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
11namespace mdds { namespace mtv { namespace detail {
12
13template<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
32template<typename T>
33std::size_t get_block_capacity(const T& blk, std::true_type)
34{
35 return blk.capacity();
36}
37
38template<typename T>
39std::size_t get_block_capacity(const T&, std::false_type)
40{
41 return 0;
42}
43
44template<typename T>
45std::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
51template<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
70template<typename T>
71void reserve(T& blk, typename T::size_type size, std::true_type)
72{
73 return blk.reserve(size);
74}
75
76template<typename T>
77void reserve(T&, typename T::size_type, std::false_type)
78{}
79
80template<typename T>
81void reserve(T& blk, typename T::size_type size)
82{
83 typename has_reserve_method<T>::type v;
84 reserve(blk, size, v);
85}
86
87template<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
106template<typename T>
107void shrink_to_fit(T& blk, std::true_type)
108{
109 return blk.shrink_to_fit();
110}
111
112template<typename T>
113void shrink_to_fit(T&, std::false_type)
114{}
115
116template<typename T>
117void shrink_to_fit(T& blk)
118{
119 typename has_shrink_to_fit_method<T>::type v;
120 shrink_to_fit(blk, v);
121}
122
123template<typename T>
125{
126 using type = std::false_type;
127};
128
129template<>
130struct is_std_vector_bool_store<std::vector<bool>>
131{
132 using type = std::true_type;
133};
134
135template<typename Blk>
137{
138 using type = typename is_std_vector_bool_store<typename Blk::store_type>::type;
139};
140
141template<typename T, typename = void>
142struct has_exec_policy : std::false_type
143{
144};
145
146template<typename T>
147struct 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:15
Definition types_util.hpp:143
Definition types_util.hpp:53
Definition types_util.hpp:125