nngn
Loading...
Searching...
No Matches
utils.h File Reference
#include <bit>
#include <cassert>
#include <cstring>
#include <functional>
#include <span>
#include <string>
#include <string_view>
#include <type_traits>
#include <utility>
#include <vector>
#include "concepts.h"
#include "concepts/fundamental.h"
Include dependency graph for utils.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  nngn::detail::chain_cast< T >
 
struct  nngn::always_false< T >
 
struct  nngn::member_obj_type< O(T::*)>
 
struct  nngn::member_obj_type< R(T::*)(Args...)>
 
struct  nngn::mem_obj< p >
 
struct  nngn::member_less< p >
 

Namespaces

namespace  nngn
 
namespace  nngn::detail
 

Macros

#define FWD(...)   std::forward<decltype(__VA_ARGS__)>(__VA_ARGS__)
 
#define NNGN_DEFAULT_CONSTRUCT(x)
 
#define NNGN_VIRTUAL(x)
 
#define NNGN_PURE_VIRTUAL(x)
 
#define NNGN_NO_COPY(x)
 
#define NNGN_MOVE_ONLY(x)
 
#define NNGN_NO_MOVE(x)
 
#define NNGN_ANON_IMPL1(l)   nngn_anon_ ## l
 
#define NNGN_ANON_IMPL0(l)   NNGN_ANON_IMPL1(l)
 
#define NNGN_ANON()   NNGN_ANON_IMPL0(__LINE__)
 
#define NNGN_ANON_DECL(...)    [[maybe_unused]] const auto NNGN_ANON() = __VA_ARGS__;
 
#define NNGN_CONTAINER_OF(t, n, p)    (nngn::byte_cast<t*>(nngn::byte_cast<char*>(p) - offsetof(t, n)))
 
#define NNGN_BIND_MEM_FN(x, f)
 
#define NNGN_EXPOSE_ITERATOR(n, m)
 
#define NNGN_EXPOSE_ITERATOR0(n, m, i)
 

Typedefs

template<typename T >
using nngn::member_obj_type_t = typename member_obj_type<T>::type
 

Enumerations

enum class  nngn::empty
 

Functions

template<typename ... Ts>
constexpr nngn::chain_cast (auto &&x)
 Performs successive static_casts, right to left.
 
template<typename To , typename From >
To nngn::narrow (const From &x)
 Casts x to a narrower type, asserting that the value is preserved.
 
template<typename T , typename U >
constexpr nngn::cast (U &&x)
 Cast value to T with the strictest cast operator.
 
template<typename To , typename From >
requires byte_pointer<To> || byte_pointer<From>
constexpr To nngn::byte_cast (From p)
 reinterpret_cast restricted to conversions from/to char/uchar.
 
template<typename To , typename From >
requires byte_type<To> || char_type<To> || byte_type<From> || char_type<From>
std::span< To > nngn::byte_cast (std::span< From > s)
 Cast between spans where one is a byte type.
 
template<enum_ T>
constexpr auto nngn::to_underlying (T t)
 
constexpr auto nngn::ptr_diff (const auto *lhs, const auto *rhs)
 Signed distance in bytes between pointers.
 
constexpr bool nngn::ptr_cmp (const auto *p0, const auto *p1)
 Compares the address of two pointers.
 
template<standard_layout T>
std::size_t nngn::offsetof_ptr (auto T::*p)
 Similar to the stdlib's offsetof, but using member data pointers.
 
auto nngn::as_bytes (const void *p)
 
auto nngn::as_bytes (void *p)
 
std::span< const std::byte > nngn::as_byte_span (const auto *x)
 
std::span< std::byte > nngn::as_byte_span (auto *x)
 
constexpr bool nngn::str_less (const char *lhs, const char *rhs)
 
template<typename To , typename From >
requires ( sizeof(To) == sizeof(From) && std::is_trivially_copyable_v<To> && std::is_trivially_copyable_v<From>)
constexpr auto nngn::bit_cast (const From &from)
 
template<typename T >
constexpr auto nngn::set_bit (T t, T mask, bool value)
 
constexpr nngn::rptr (auto &&r)
 Allows passing an rvalue pointer to a function.
 
bool nngn::read_file (std::string_view filename, std::string *ret)
 
bool nngn::read_file (std::string_view filename, std::vector< std::byte > *ret)
 

Macro Definition Documentation

◆ FWD

#define FWD ( ...)    std::forward<decltype(__VA_ARGS__)>(__VA_ARGS__)

◆ NNGN_ANON

#define NNGN_ANON ( )    NNGN_ANON_IMPL0(__LINE__)

◆ NNGN_ANON_DECL

#define NNGN_ANON_DECL ( ...)     [[maybe_unused]] const auto NNGN_ANON() = __VA_ARGS__;

◆ NNGN_ANON_IMPL0

#define NNGN_ANON_IMPL0 ( l)    NNGN_ANON_IMPL1(l)

◆ NNGN_ANON_IMPL1

#define NNGN_ANON_IMPL1 ( l)    nngn_anon_ ## l

◆ NNGN_BIND_MEM_FN

#define NNGN_BIND_MEM_FN ( x,
f )
Value:
std::bind_front([] { \
constexpr auto nngn_ret = \
&std::remove_pointer_t<std::decay_t<decltype(x)>>::f; \
static_assert(std::is_member_function_pointer_v<decltype(nngn_ret)>); \
return nngn_ret; \
}(), (x))
local function f()) end

◆ NNGN_CONTAINER_OF

#define NNGN_CONTAINER_OF ( t,
n,
p )    (nngn::byte_cast<t*>(nngn::byte_cast<char*>(p) - offsetof(t, n)))

◆ NNGN_DEFAULT_CONSTRUCT

#define NNGN_DEFAULT_CONSTRUCT ( x)
Value:
x() = default; \
x(const x&) = default; \
x &operator=(const x&) = default; \
x(x&&) noexcept = default; \
x &operator=(x&&) noexcept = default; \

◆ NNGN_EXPOSE_ITERATOR

#define NNGN_EXPOSE_ITERATOR ( n,
m )
Value:
NNGN_EXPOSE_ITERATOR0(n, m, cend) \
NNGN_EXPOSE_ITERATOR0(n, m, begin) \
NNGN_EXPOSE_ITERATOR0(n, m, end)
function DEMO text end
Definition demo0.lua:6
local n
Definition dump_lights.lua:5
local m
Definition input.lua:28
#define NNGN_EXPOSE_ITERATOR0(n, m, i)
Definition utils.h:72

◆ NNGN_EXPOSE_ITERATOR0

#define NNGN_EXPOSE_ITERATOR0 ( n,
m,
i )
Value:
auto n##i(void) const { using std::i; return i(this->m); } \
auto n##i(void) { using std::i; return i(this->m); }
for i
Definition font.lua:5

◆ NNGN_MOVE_ONLY

#define NNGN_MOVE_ONLY ( x)
Value:
x(x&&) noexcept = default; \
x &operator=(x&&) noexcept = default;
#define NNGN_NO_COPY(x)
Definition utils.h:35

◆ NNGN_NO_COPY

#define NNGN_NO_COPY ( x)
Value:
x(const x&) = delete; \
x &operator=(const x&) = delete;

◆ NNGN_NO_MOVE

#define NNGN_NO_MOVE ( x)
Value:
x(const x&) = delete; \
x &operator=(const x&) = delete; \
x(x&&) noexcept = delete; \
x &operator=(x&&) noexcept = delete;

◆ NNGN_PURE_VIRTUAL

#define NNGN_PURE_VIRTUAL ( x)
Value:
virtual ~x() = 0;
#define NNGN_DEFAULT_CONSTRUCT(x)
Definition utils.h:20

◆ NNGN_VIRTUAL

#define NNGN_VIRTUAL ( x)
Value:
virtual ~x() = default;