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

align.hpp
Go to the documentation of this file.
1 
9 #ifndef EAGINE_MEMORY_ALIGN_HPP
10 #define EAGINE_MEMORY_ALIGN_HPP
11 
12 #include "../type_identity.hpp"
13 #include "../types.hpp"
14 
15 namespace eagine::memory {
16 //------------------------------------------------------------------------------
19 static constexpr auto
20 misalignment(span_size_t addr, span_size_t alignment) noexcept -> span_size_t {
21  return addr % alignment;
22 }
23 //------------------------------------------------------------------------------
26 static constexpr auto misalignment(std::nullptr_t, span_size_t) noexcept
27  -> span_size_t {
28  return 0;
29 }
30 //------------------------------------------------------------------------------
33 static constexpr auto
34 is_aligned_to(span_size_t addr, span_size_t algn) noexcept {
35  return misalignment(addr, algn) == 0;
36 }
37 //------------------------------------------------------------------------------
40 static constexpr auto is_aligned_to(std::nullptr_t, span_size_t) noexcept {
41  return true;
42 }
43 //------------------------------------------------------------------------------
46 template <typename T>
47 static constexpr auto
49  return is_aligned_to(addr, span_align_of<T>());
50 }
51 //------------------------------------------------------------------------------
52 } // namespace eagine::memory
53 
54 #endif // EAGINE_MEMORY_ALIGN_HPP
std::ptrdiff_t span_size_t
Signed span size type used by eagine.
Definition: types.hpp:36
static constexpr auto misalignment(std::nullptr_t, span_size_t) noexcept -> span_size_t
Calculates basic numeric address misalignment.
Definition: align.hpp:26
static constexpr auto is_aligned_as(span_size_t addr, type_identity< T >={}) noexcept
Indicates if a basic numeric address is aligned to alignment of type T.
Definition: align.hpp:48
static constexpr auto is_aligned_to(std::nullptr_t, span_size_t) noexcept
Indicates if a basic numeric address is aligned.
Definition: align.hpp:40
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).