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

unreachable_reference.hpp
Go to the documentation of this file.
1 
9 #ifndef EAGINE_UNREACHABLE_REFERENCE_HPP
10 #define EAGINE_UNREACHABLE_REFERENCE_HPP
11 
12 #include "assert.hpp"
13 #include "type_identity.hpp"
14 #include <type_traits>
15 
16 namespace eagine {
17 //------------------------------------------------------------------------------
18 template <std::size_t N>
19 static inline auto unreachable_storage() noexcept {
20  static std::aligned_storage_t<N> _storage{};
21  return static_cast<void*>(&_storage);
22 }
23 //------------------------------------------------------------------------------
24 template <typename T>
25 static inline auto unreachable_reference(type_identity<T>) noexcept -> T& {
26  EAGINE_UNREACHABLE();
27  return *static_cast<T*>(unreachable_storage<sizeof(T)>());
28 }
29 //------------------------------------------------------------------------------
30 } // namespace eagine
31 
32 #endif // EAGINE_UNREACHABLE_REFERENCE_HPP
Common code is placed in this namespace.
Definition: eagine.hpp:21

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