Skip to content

Commit

Permalink
Merge pull request #145 from elbeno/ct-check-value
Browse files Browse the repository at this point in the history
🎨 Return a value from `ct_check::emit`
  • Loading branch information
lukevalenty authored Oct 1, 2024
2 parents 7976eaf + ab8519e commit 67120f7
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
8 changes: 6 additions & 2 deletions include/stdx/ct_string.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,14 +124,18 @@ template <ct_string S> CONSTEVAL auto operator""_cts() { return S; }
} // namespace ct_string_literals
} // namespace literals

struct ct_check_value {};

template <bool B> struct ct_check_t {
template <ct_string S> constexpr static bool diagnostic = false;
template <ct_string S>
constexpr static auto emit() -> void
constexpr static auto emit() -> ct_check_value
requires diagnostic<S>;
};
template <> struct ct_check_t<true> {
template <ct_string S> constexpr static auto emit() -> void {}
template <ct_string S> constexpr static auto emit() -> ct_check_value {
return {};
}
};
template <bool B> constexpr auto ct_check = ct_check_t<B>{};

Expand Down
2 changes: 1 addition & 1 deletion test/fail/ct_check.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ constexpr auto msg =
stdx::ct_string{"01234567890123456789012345678901234567890123456789"};

auto main() -> int {
stdx::ct_check<true>.emit<"not emitted">();
[[maybe_unused]] auto x = stdx::ct_check<true>.emit<"not emitted">();
stdx::ct_check<false>.emit<msg>();
}

0 comments on commit 67120f7

Please sign in to comment.