header_utils
Loading...
Searching...
No Matches
named.h
1#pragma once
2
3#include <type_traits>
4#include <utility>
5
6namespace ghassanpl
7{
8 template <typename T, typename TYPE_TAG>
9 struct named
10 {
11 using base_type = T;
12 using self_type = named<T, TYPE_TAG>;
13
14 T value{};
15
16 template <typename... ARGS, typename = typename std::enable_if<std::is_constructible<T, ARGS...>::value>::type>
17 constexpr explicit named(ARGS&&... args) noexcept(std::is_nothrow_constructible<T, ARGS...>::value) : value(std::forward<ARGS>(args)...) {}
18
19 constexpr named() noexcept(std::is_nothrow_default_constructible<T>::value) = default;
20 constexpr named(named const&) noexcept(std::is_nothrow_copy_constructible<T>::value) = default;
21 constexpr named(named&&) noexcept(std::is_nothrow_move_constructible<T>::value) = default;
22 named& operator=(named const&) noexcept(std::is_nothrow_copy_assignable<T>::value) = default;
23 named& operator=(named&&) noexcept(std::is_nothrow_move_assignable<T>::value) = default;
24
25 T* operator->() noexcept { return &value; }
26 T const* operator->() const noexcept { return &value; }
27
28 T const& get() const& { return value; }
29 T get()&& { return std::move(value); }
30
31 template <typename U>
32 constexpr U as() const noexcept { return static_cast<U>(value); }
33
34 constexpr T drop() const noexcept(std::is_nothrow_move_constructible<T>::value) { return std::move(value); }
35
36 constexpr explicit operator bool() const noexcept { return value; }
37 constexpr explicit operator base_type() const noexcept { return value; }
38
39 constexpr bool operator <(named const& other) const { return value < other.value; }
40 constexpr bool operator <=(named const& other) const { return value <= other.value; }
41 constexpr bool operator >(named const& other) const { return value > other.value; }
42 constexpr bool operator >=(named const& other) const { return value >= other.value; }
43 constexpr bool operator ==(named const& other) const { return value == other.value; }
44 constexpr bool operator !=(named const& other) const { return value != other.value; }
45
46 friend constexpr bool operator <(T const& value, named const& other) { return value < other.value; }
47 friend constexpr bool operator <=(T const& value, named const& other) { return value <= other.value; }
48 friend constexpr bool operator >(T const& value, named const& other) { return value > other.value; }
49 friend constexpr bool operator >=(T const& value, named const& other) { return value >= other.value; }
50 friend constexpr bool operator ==(T const& value, named const& other) { return value == other.value; }
51 friend constexpr bool operator !=(T const& value, named const& other) { return value != other.value; }
52 };
53
54}
constexpr auto bit_count
Equal to the number of bits in the type.
Definition bits.h:33
nlohmann::json const & get(nlohmann::json const &g, std::string_view key, jtype type=jtype::discarded)
Gets the item in the json object g with the key key, or an empty json object if none found.
Primary namespace for everything in this library.
Definition align+rec2.h:10