HikoGUI
A low latency retained GUI
Loading...
Searching...
No Matches
iso_3166.hpp
1// Copyright Take Vos 2021.
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 "../assert.hpp"
9#include "../check.hpp"
10#include "../strings.hpp"
11
12namespace hi::inline v1 {
13
16class iso_3166 {
17public:
18 constexpr iso_3166(iso_3166 const&) noexcept = default;
19 constexpr iso_3166(iso_3166&&) noexcept = default;
20 constexpr iso_3166& operator=(iso_3166 const&) noexcept = default;
21 constexpr iso_3166& operator=(iso_3166&&) noexcept = default;
22
23 constexpr iso_3166() noexcept : _v(999) {}
24
25 constexpr iso_3166(uint16_t number) : _v(number)
26 {
27 hi_parse_check(number <= 999, "ISO-3166 number must be between 0 and 999, got {}", number);
28 }
29
30 iso_3166(std::string_view str);
31
32 [[nodiscard]] constexpr bool empty() const noexcept
33 {
34 return _v == 999;
35 }
36
37 constexpr explicit operator bool() const noexcept
38 {
39 return not empty();
40 }
41
42 [[nodiscard]] constexpr uint16_t number() const noexcept
43 {
44 return _v;
45 }
46
47 [[nodiscard]] std::string_view code2() const noexcept;
48 [[nodiscard]] std::string_view code3() const noexcept;
49
50 [[nodiscard]] constexpr friend bool operator==(iso_3166 const& lhs, iso_3166 const& rhs) noexcept = default;
51 [[nodiscard]] constexpr friend auto operator<=>(iso_3166 const& lhs, iso_3166 const& rhs) noexcept = default;
52
53private:
54 uint16_t _v;
55};
56
57} // namespace hi::inline v1
58
59template<>
60struct std::hash<hi::iso_3166> {
61 [[nodiscard]] size_t operator()(hi::iso_3166 const& rhs) const noexcept
62 {
63 return std::hash<uint16_t>{}(rhs.number());
64 }
65};
ISO-3166 country code.
Definition iso_3166.hpp:16
T operator()(T... args)
Definition datum.hpp:2458