HikoGUI
A low latency retained GUI
Loading...
Searching...
No Matches
iso_3166.hpp
1// Copyright Take Vos 2022.
2// Distributed under the Boost Software License, Version 1.0.
3// (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt)
4
5#pragma once
6
7#include <cctype>
8#include "../utility/module.hpp"
9#include "../strings.hpp"
10
11namespace hi::inline v1 {
12
15class iso_3166 {
16public:
17 constexpr iso_3166(iso_3166 const&) noexcept = default;
18 constexpr iso_3166(iso_3166&&) noexcept = default;
19 constexpr iso_3166& operator=(iso_3166 const&) noexcept = default;
20 constexpr iso_3166& operator=(iso_3166&&) noexcept = default;
21
22 constexpr iso_3166() noexcept : _v(999) {}
23
24 constexpr iso_3166(uint16_t number) : _v(number)
25 {
26 hi_check(number <= 999, "ISO-3166 number must be between 0 and 999, got {}", number);
27 }
28
29 iso_3166(std::string_view str);
30
31 [[nodiscard]] constexpr bool empty() const noexcept
32 {
33 return _v == 999;
34 }
35
36 constexpr explicit operator bool() const noexcept
37 {
38 return not empty();
39 }
40
41 [[nodiscard]] constexpr uint16_t number() const noexcept
42 {
43 return _v;
44 }
45
46 [[nodiscard]] std::string_view code2() const noexcept;
47 [[nodiscard]] std::string_view code3() const noexcept;
48
49 [[nodiscard]] constexpr friend bool operator==(iso_3166 const& lhs, iso_3166 const& rhs) noexcept = default;
50 [[nodiscard]] constexpr friend auto operator<=>(iso_3166 const& lhs, iso_3166 const& rhs) noexcept = default;
51
52private:
53 uint16_t _v;
54};
55
56} // namespace hi::inline v1
57
58template<>
59struct std::hash<hi::iso_3166> {
60 [[nodiscard]] size_t operator()(hi::iso_3166 const& rhs) const noexcept
61 {
62 return std::hash<uint16_t>{}(rhs.number());
63 }
64};
#define hi_check(expression, message,...)
Check if the expression is valid, or throw a parse_error.
Definition assert.hpp:95
DOXYGEN BUG.
Definition algorithm.hpp:13
geometry/margins.hpp
Definition cache.hpp:11
ISO-3166 country code.
Definition iso_3166.hpp:15
T operator()(T... args)