File indexing completed on 2024-04-21 03:54:30

0001 /*
0002     SPDX-FileCopyrightText: 2021 Volker Krause <vkrause@kde.org>
0003 
0004     SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 #ifndef MAPENTRY_P_H
0008 #define MAPENTRY_P_H
0009 
0010 #include <algorithm>
0011 #include <cstdint>
0012 #include <iterator>
0013 
0014 #pragma pack(push)
0015 #pragma pack(1)
0016 
0017 template<typename KeyType>
0018 struct MapEntry {
0019     KeyType key;
0020     uint16_t value;
0021 };
0022 
0023 template<typename KeyType>
0024 constexpr inline bool operator<(MapEntry<KeyType> lhs, MapEntry<KeyType> rhs)
0025 {
0026     return lhs.key < rhs.key;
0027 }
0028 
0029 template<typename KeyType>
0030 constexpr inline bool operator<(MapEntry<KeyType> lhs, KeyType rhs)
0031 {
0032     return lhs.key < rhs;
0033 }
0034 
0035 template<typename KeyType>
0036 constexpr inline bool operator<(KeyType lhs, MapEntry<KeyType> rhs)
0037 {
0038     return lhs < rhs.key;
0039 }
0040 
0041 template<typename MapEntry, std::size_t N>
0042 inline constexpr bool isSortedLookupTable(const MapEntry (&map)[N])
0043 {
0044 #if __cplusplus > 201703L && defined(__GNUC__) && !defined(__clang__)
0045     return std::is_sorted(std::begin(map), std::end(map));
0046 #else
0047     (void)map;
0048     return true;
0049 #endif
0050 }
0051 
0052 #pragma pack(pop)
0053 
0054 #endif