userver
C++ Async Framework
Toggle main menu visibility
Loading...
Searching...
No Matches
constexpr_indices.hpp
Go to the documentation of this file.
1
#pragma once
2
5
6
#include <cstddef>
7
#include <type_traits>
8
#include <utility>
9
10
USERVER_NAMESPACE_BEGIN
11
12
namespace
utils
{
13
14
namespace
impl {
15
16
template
<std::size_t... Indices,
typename
Func>
17
void
DoForEachIndex(std::index_sequence<Indices...>, Func func) {
18
static_assert
(std::is_trivially_copyable_v<Func>);
19
(..., func(std::integral_constant<std::size_t, Indices>{}));
20
}
21
22
template
<std::size_t... Indices,
typename
Func>
23
void
DoWithConstexprIndex(std::index_sequence<Indices...>, std::size_t runtime_index, Func func) {
24
static_assert
(std::is_trivially_copyable_v<Func>);
25
(..., (runtime_index == Indices ? func(std::integral_constant<std::size_t, Indices>{}) : void()));
26
}
27
28
}
// namespace impl
29
32
template
<std::
size_t
Count,
typename
Func>
33
void
ForEachIndex
(Func func) {
34
impl::DoForEachIndex(std::make_index_sequence<Count>{}, func);
35
}
36
38
template
<std::
size_t
Count,
typename
Func>
39
void
WithConstexprIndex
(std::size_t runtime_index, Func func) {
40
impl::DoWithConstexprIndex(std::make_index_sequence<Count>{}, runtime_index, func);
41
}
42
43
}
// namespace utils
44
45
USERVER_NAMESPACE_END
userver
utils
constexpr_indices.hpp
Generated on
for userver by
Doxygen
1.17.0