@@ -46,6 +46,9 @@ namespace ondemand { |
46 | 46 |
|
47 | 47 | namespace key_selector_detail { |
48 | 48 |
|
| 49 | +// Since not constexpr, triggers compile-time error. |
| 50 | +inline void compile_time_error(const char* message) noexcept { (void)message; } |
| 51 | + |
49 | 52 | // ============================================================================ |
50 | 53 | // Compile-time perfect-hash generator. |
51 | 54 | // It scales to ~100 keys at compile time by determining association values one (position, character) |
@@ -265,7 +268,8 @@ consteval std::size_t select_positions( |
265 | 268 | if (positions_distinguish<N>(keys, positions.data(), num_pos, modulus)) { return num_pos; } |
266 | 269 | } |
267 | 270 |
|
268 | | - throw "Failed to find distinguishing positions for perfect hash"; |
| 271 | + compile_time_error("Failed to find distinguishing positions for perfect hash"); |
| 272 | + return 0; |
269 | 273 | } |
270 | 274 |
|
271 | 275 | // Result of PHF computation. A max-sized slot_to_key array lets the same struct |
@@ -614,7 +618,8 @@ consteval phf_result<N> compute_phf_hd_po2(const std::array<std::string_view, N> |
614 | 618 | if constexpr (NextM <= phf_result<N>::MAX_TABLE_SIZE) { |
615 | 619 | return compute_phf_hd_po2<N, NextM>(keys); |
616 | 620 | } else { |
617 | | - throw "Hash-and-Displace: failed to find valid table size"; |
| 621 | + compile_time_error("Hash-and-Displace: failed to find valid table size"); |
| 622 | + return result; |
618 | 623 | } |
619 | 624 | } |
620 | 625 |
|
@@ -661,15 +666,15 @@ template <std::size_t N, std::size_t TableSize, std::size_t MaxKeyLen> |
661 | 666 | consteval phf_data<N, TableSize, MaxKeyLen> |
662 | 667 | build_phf_data(const std::array<std::string_view, N>& keys, const phf_result<N>& result) { |
663 | 668 | for (std::size_t i = 0; i < N; ++i) { |
664 | | - if (keys[i].empty()) { throw "empty keys are not allowed in key_selector"; } |
665 | | - if (keys[i].size() > MaxKeyLen) { throw "key length exceeds MaxKeyLen"; } |
| 669 | + if (keys[i].empty()) { compile_time_error("empty keys are not allowed in key_selector"); } |
| 670 | + if (keys[i].size() > MaxKeyLen) { compile_time_error("key length exceeds MaxKeyLen"); } |
666 | 671 | for (char c : keys[i]) { |
667 | | - if (c == '\\') { throw "backslash not allowed in key_selector keys"; } |
668 | | - if (c == '"') { throw "quote not allowed in key_selector keys"; } |
669 | | - if (c == '\0') { throw "null byte not allowed in key_selector keys"; } |
| 672 | + if (c == '\\') { compile_time_error("backslash not allowed in key_selector keys"); } |
| 673 | + if (c == '"') { compile_time_error("quote not allowed in key_selector keys"); } |
| 674 | + if (c == '\0') { compile_time_error("null byte not allowed in key_selector keys"); } |
670 | 675 | } |
671 | 676 | for (std::size_t j = i + 1; j < N; ++j) { |
672 | | - if (keys[i] == keys[j]) { throw "duplicate keys in key_selector"; } |
| 677 | + if (keys[i] == keys[j]) { compile_time_error("duplicate keys in key_selector"); } |
673 | 678 | } |
674 | 679 | } |
675 | 680 |
|
|