OGLplus  (0.59.0) a C++ wrapper for rendering APIs

types.hpp
Go to the documentation of this file.
1 
9 #ifndef EAGINE_TYPES_HPP
10 #define EAGINE_TYPES_HPP
11 
12 #include "is_within_limits.hpp"
13 #include "type_identity.hpp"
14 #include "valid_if/nonnegative.hpp"
15 #include <cassert>
16 #include <cstdint>
17 #include <limits>
18 #include <type_traits>
19 
20 namespace eagine {
21 
24 using byte = unsigned char;
25 
28 using std_align_t = std::size_t;
29 
32 using std_size_t = std::size_t;
33 
36 using span_size_t = std::ptrdiff_t;
37 
41 
44 template <typename T, typename = std::enable_if_t<std::is_integral_v<T>>>
45 static constexpr auto std_align(T v) noexcept {
46  return limit_cast<std_align_t>(v);
47 }
48 
51 template <typename T, typename = std::enable_if_t<std::is_integral_v<T>>>
52 static constexpr auto std_size(T v) noexcept {
53  return limit_cast<std_size_t>(v);
54 }
55 
58 template <typename T, typename = std::enable_if_t<std::is_integral_v<T>>>
59 static constexpr auto span_size(T v) noexcept {
60  return limit_cast<span_size_t>(v);
61 }
62 
65 template <typename T>
66 static constexpr auto span_align_of(type_identity<T> = {}) noexcept {
67  return span_size(alignof(T));
68 }
69 
72 template <typename T>
73 static constexpr auto span_size_of(type_identity<T> = {}) noexcept {
74  return span_size(sizeof(T));
75 }
76 
79 template <typename T, typename S>
80 static constexpr auto span_size_of(S n, type_identity<T> = {}) noexcept {
81  return span_size(sizeof(T)) * span_size(n);
82 }
83 
84 } // namespace eagine
85 
86 #endif // EAGINE_TYPES_HPP
std::ptrdiff_t span_size_t
Signed span size type used by eagine.
Definition: types.hpp:36
static constexpr auto span_size(T v) noexcept
Converts argument to span size type.
Definition: types.hpp:59
Common code is placed in this namespace.
Definition: eagine.hpp:21
static constexpr auto std_align(T v) noexcept
Converts argument to std alignment type.
Definition: types.hpp:45
Primary template for conditionally valid values.
Definition: decl.hpp:49
std::size_t std_size_t
Size type used by std.
Definition: types.hpp:32
static constexpr auto std_size(T v) noexcept
Converts argument to std size type.
Definition: types.hpp:52
std::size_t std_align_t
Alignment type used by std.
Definition: types.hpp:28
static constexpr auto span_align_of(type_identity< T >={}) noexcept
Returns the byte alignment of type T as span_size_t.
Definition: types.hpp:66
static constexpr auto span_size_of(type_identity< T >={}) noexcept
Returns the byte size of type T as span_size_t.
Definition: types.hpp:73
Template type used mostly for function type-tag dispatching.
Definition: type_identity.hpp:19

Copyright © 2015-2021 Matúš Chochlík.
<chochlik -at -gmail.com>
Documentation generated on Tue Apr 13 2021 by Doxygen (version 1.8.17).