AsmGrader 0.0.0
Loading...
Searching...
No Matches
static_size.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <range/v3/range/concepts.hpp>
4
5#include <concepts>
6#include <cstddef>
7#include <tuple>
8#include <type_traits>
9
10namespace asmgrader {
11
12template <typename Range>
13concept HasStaticSize = requires {
14 // have to use ::value here to force instantiation of tuple_size
15 { std::tuple_size<std::decay_t<Range>>::value } -> std::convertible_to<std::size_t>;
16};
17
18template <typename Range>
19consteval std::size_t get_static_size() {
20 using Type = std::remove_cvref_t<Range>;
21 if constexpr (std::is_array_v<Type>) {
22 return std::extent_v<Type, 0>;
23 } else {
24 return std::tuple_size_v<Type>;
25 }
26}
27
28template <typename Range>
29constexpr std::size_t get_static_size_or(std::size_t default_value) {
30 if constexpr (HasStaticSize<Range>) {
32 }
33
34 return default_value;
35}
36
37} // namespace asmgrader
Definition static_size.hpp:13
Definition asm_buffer.hpp:20
consteval std::size_t get_static_size()
Definition static_size.hpp:19
constexpr std::size_t get_static_size_or(std::size_t default_value)
Definition static_size.hpp:29