mdds
Toggle main menu visibility
Loading...
Searching...
No Matches
include
mdds
multi_type_vector
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 <concepts>
10
#include <vector>
11
12
namespace
mdds {
namespace
mtv {
namespace
detail {
13
14
template
<
typename
T>
15
concept
has_capacity_method
=
requires
(
const
T& blk) {
16
{ blk.capacity() } -> std::same_as<typename T::size_type>;
17
};
18
19
template
<
typename
T>
20
std::size_t get_block_capacity(
const
T& blk)
21
{
22
if
constexpr
(
has_capacity_method<T>
)
23
return
blk.capacity();
24
else
25
return
0;
26
}
27
28
template
<
typename
T>
29
concept
has_reserve_method
=
requires
(T& blk,
typename
T::size_type size) {
30
{ blk.reserve(size) } -> std::same_as<void>;
31
};
32
33
template
<
typename
T>
34
void
reserve(T& blk,
typename
T::size_type size)
35
{
36
if
constexpr
(
has_reserve_method<T>
)
37
blk.reserve(size);
38
}
39
40
template
<
typename
T>
41
concept
has_shrink_to_fit_method
=
requires
(T& blk) {
42
{ blk.shrink_to_fit() } -> std::same_as<void>;
43
};
44
45
template
<
typename
T>
46
void
shrink_to_fit(T& blk)
47
{
48
if
constexpr
(
has_shrink_to_fit_method<T>
)
49
blk.shrink_to_fit();
50
}
51
52
template
<
typename
T>
53
struct
is_std_vector_bool_store
54
{
55
using
type = std::false_type;
56
};
57
58
template
<>
59
struct
is_std_vector_bool_store
<std::vector<bool>>
60
{
61
using
type = std::true_type;
62
};
63
64
template
<
typename
Blk>
65
struct
has_std_vector_bool_store
66
{
67
using
type =
typename
is_std_vector_bool_store<typename Blk::store_type>::type;
68
};
69
70
template
<
typename
T>
71
concept
has_exec_policy
=
requires
{
typename
T::exec_policy; };
72
73
}}}
// namespace mdds::mtv::detail
74
75
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
mdds::mtv::detail::has_capacity_method
Definition
types_util.hpp:15
mdds::mtv::detail::has_exec_policy
Definition
types_util.hpp:71
mdds::mtv::detail::has_reserve_method
Definition
types_util.hpp:29
mdds::mtv::detail::has_shrink_to_fit_method
Definition
types_util.hpp:41
mdds::mtv::detail::has_std_vector_bool_store
Definition
types_util.hpp:66
mdds::mtv::detail::is_std_vector_bool_store
Definition
types_util.hpp:54
Generated on
for mdds by
1.17.0