MCPcopy Create free account
hub / github.com/Neargye/magic_enum / has_duplicate

Function has_duplicate

include/magic_enum/magic_enum.hpp:1090–1110  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1088
1089template <auto* Arr, typename Hash>
1090constexpr bool has_duplicate() noexcept {
1091 using value_t = std::decay_t<decltype((*Arr)[0])>;
1092 using hash_value_t = std::invoke_result_t<Hash, value_t>;
1093 std::array<hash_value_t, Arr->size()> hashes{};
1094 std::size_t size = 0;
1095 for (auto elem : *Arr) {
1096 hashes[size] = hash_v<Hash>(elem);
1097 for (auto i = size++; i > 0; --i) {
1098 if (hashes[i] < hashes[i - 1]) {
1099 auto tmp = hashes[i];
1100 hashes[i] = hashes[i - 1];
1101 hashes[i - 1] = tmp;
1102 } else if (hashes[i] == hashes[i - 1]) {
1103 return false;
1104 } else {
1105 break;
1106 }
1107 }
1108 }
1109 return true;
1110}
1111
1112#define MAGIC_ENUM_CASE(val) \
1113 case cases[val]: \

Callers

nothing calls this directly

Calls 1

sizeMethod · 0.45

Tested by

no test coverage detected