Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use "constexpr if" when possible #2270

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion include/rapidjson/pointer.h
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ class GenericPointer {
SizeType length = static_cast<SizeType>(end - buffer);
buffer[length] = '\0';

if (sizeof(Ch) == 1) {
RAPIDJSON_CONSTEXPR_IF (sizeof(Ch) == 1) {
Token token = { reinterpret_cast<Ch*>(buffer), length, index };
return Append(token, allocator);
}
Expand Down
6 changes: 6 additions & 0 deletions include/rapidjson/rapidjson.h
Original file line number Diff line number Diff line change
Expand Up @@ -663,6 +663,12 @@ RAPIDJSON_NAMESPACE_END
# define RAPIDJSON_DELIBERATE_FALLTHROUGH
#endif

#if RAPIDJSON_HAS_CXX17
# define RAPIDJSON_CONSTEXPR_IF if constexpr
#else
# define RAPIDJSON_CONSTEXPR_IF if
#endif

//!@endcond

//! Assertion (in non-throwing contexts).
Expand Down
2 changes: 1 addition & 1 deletion include/rapidjson/schema.h
Original file line number Diff line number Diff line change
Expand Up @@ -1762,7 +1762,7 @@ struct TokenHelper {
template <typename Stack>
struct TokenHelper<Stack, char> {
RAPIDJSON_FORCEINLINE static void AppendIndexToken(Stack& documentStack, SizeType index) {
if (sizeof(SizeType) == 4) {
RAPIDJSON_CONSTEXPR_IF (sizeof(SizeType) == 4) {
char *buffer = documentStack.template Push<char>(1 + 10); // '/' + uint
*buffer++ = '/';
const char* end = internal::u32toa(index, buffer);
Expand Down