Skip to content

Commit 6c2f768

Browse files
committed
Don't define compile_signature if not supported by language features
1 parent b10f1b1 commit 6c2f768

2 files changed

Lines changed: 9 additions & 0 deletions

File tree

include/libhat/result.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,14 @@
66

77
#if __cpp_lib_expected >= 202202L
88
#define LIBHAT_CONSTEXPR_RESULT constexpr
9+
#define LIBHAT_HAS_CONSTEXPR_RESULT
910
#define LIBHAT_RESULT_EXPECTED
1011
#ifndef LIBHAT_MODULE
1112
#include <expected>
1213
#endif
1314
#elif __cpp_lib_variant >= 202106L
1415
#define LIBHAT_CONSTEXPR_RESULT constexpr
16+
#define LIBHAT_HAS_CONSTEXPR_RESULT
1517
#else
1618
#define LIBHAT_CONSTEXPR_RESULT inline
1719
#endif

include/libhat/signature.hpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,16 +220,19 @@ LIBHAT_EXPORT namespace hat {
220220

221221
namespace hat::detail {
222222

223+
#ifdef LIBHAT_HAS_CONSTEXPR_RESULT
223224
template<size_t N>
224225
[[nodiscard]] consteval std::pair<std::array<signature_element, N>, size_t> compile_signature_max_size(std::string_view str) {
225226
std::array<signature_element, N> array;
226227
auto size = parse_signature_to(array.begin(), str);
227228
return {array, size.value()};
228229
}
230+
#endif
229231
}
230232

231233
LIBHAT_EXPORT namespace hat {
232234

235+
#ifdef LIBHAT_HAS_CONSTEXPR_RESULT
233236
/// Parses a signature string at compile time and returns the result as a fixed_signature
234237
template<fixed_string str>
235238
[[nodiscard]] consteval auto compile_signature() {
@@ -241,6 +244,7 @@ LIBHAT_EXPORT namespace hat {
241244
std::move(pair.first.begin(), pair.first.begin() + pair.second, arr.begin());
242245
return arr;
243246
}
247+
#endif
244248

245249
[[nodiscard]] constexpr std::string to_string(const signature_view signature) {
246250
constexpr std::string_view hex{"0123456789ABCDEF"};
@@ -278,6 +282,7 @@ LIBHAT_EXPORT namespace hat {
278282

279283
LIBHAT_EXPORT namespace hat::inline literals::inline signature_literals {
280284

285+
#ifdef LIBHAT_HAS_CONSTEXPR_RESULT
281286
template<hat::fixed_string str>
282287
consteval auto operator""_sig() noexcept {
283288
return hat::compile_signature<str>();
@@ -290,4 +295,6 @@ LIBHAT_EXPORT namespace hat::inline literals::inline signature_literals {
290295
return hat::signature_view{sig};
291296
}
292297
#endif
298+
299+
#endif
293300
}

0 commit comments

Comments
 (0)