based

Opinionated utility library
git clone git://git.dimitrijedobrota.com/based.git
Log | Files | Refs | README | LICENSE | HACKING | CONTRIBUTING | CODE_OF_CONDUCT | BUILDING

type.hpp (1025B)


0 #pragma once
2 #include <compare>
4 #include "based/integral/types.hpp"
6 namespace based
7 {
9 struct Character : public StrongType<char, Character>
10 {
11 using StrongType::StrongType;
12 using StrongType::operator=;
14 constexpr Character(char chr) // NOLINT(*explicit*)
15 : StrongType(chr)
16 {
17 }
19 explicit constexpr Character(U8 ord)
20 : StrongType(static_cast<char>(ord.value))
21 {
22 }
24 [[nodiscard]] char chr() const { return value; }
25 [[nodiscard]] U8 ord() const { return U8::underlying_cast(value); }
27 friend constexpr bool operator==(Character lhs, char rhs)
28 {
29 return lhs.value == rhs;
30 }
32 friend constexpr bool operator==(char lhs, Character rhs)
33 {
34 return lhs == rhs.value;
35 }
37 friend constexpr auto operator<=>(Character lhs, char rhs)
38 {
39 return lhs.value <=> rhs;
40 }
42 friend constexpr auto operator<=>(char lhs, Character rhs)
43 {
44 return lhs <=> rhs.value;
45 }
46 };
48 auto compare(Character, Character) -> bool;
49 auto order(Character, Character) -> bool;
51 } // namespace based