File indexing completed on 2024-04-28 15:25:29

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 
0013 #pragma pack(push)
0014 #pragma pack(1)
0015 
0016 template<typename KeyType>
0017 struct MapEntry {
0018     KeyType key;
0019     uint16_t value;
0020 };
0021 
0022 template<typename KeyType>
0023 constexpr inline bool operator<(MapEntry<KeyType> lhs, MapEntry<KeyType> rhs)
0024 {
0025     return lhs.key < rhs.key;
0026 }
0027 
0028 template<typename KeyType>
0029 constexpr inline bool operator<(MapEntry<KeyType> lhs, KeyType rhs)
0030 {
0031     return lhs.key < rhs;
0032 }
0033 
0034 template<typename KeyType>
0035 constexpr inline bool operator<(KeyType lhs, MapEntry<KeyType> rhs)
0036 {
0037     return lhs < rhs.key;
0038 }
0039 
0040 template<typename MapEntry, std::size_t N>
0041 inline constexpr bool isSortedLookupTable(const MapEntry (&map)[N])
0042 {
0043 #if __cplusplus > 201703L
0044     return std::is_sorted(std::begin(map), std::end(map));
0045 #else
0046     (void)map;
0047     return true;
0048 #endif
0049 }
0050 
0051 #pragma pack(pop)
0052 
0053 #endif