Skip to content

Commit

Permalink
std::equal is not necessarily constexpr in C++17 (only C++20) (#37)
Browse files Browse the repository at this point in the history
* std::equal is not necessarily constexpr in C++17 (only C++20) which means that
PR #35 broke idna technically.

* clang-format
  • Loading branch information
lemire authored Sep 19, 2023
1 parent 6313d3a commit 3c8be01
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 9 deletions.
4 changes: 1 addition & 3 deletions benchmarks/performancecounters/apple_arm_events.h
Original file line number Diff line number Diff line change
Expand Up @@ -615,9 +615,7 @@ typedef struct {

#define lib_nelems(x) (sizeof(x) / sizeof((x)[0]))
#define lib_symbol_def(name) \
{ \
#name, (void **)&name \
}
{ #name, (void **)&name }

static const lib_symbol lib_symbols_kperf[] = {
lib_symbol_def(kpc_pmu_version),
Expand Down
5 changes: 2 additions & 3 deletions include/ada/idna/to_ascii.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,8 @@ std::string to_ascii(std::string_view ut8_string);
// https://url.spec.whatwg.org/#forbidden-domain-code-point
bool contains_forbidden_domain_code_point(std::string_view ascii_string);

bool constexpr begins_with(std::u32string_view view,
std::u32string_view prefix);
bool constexpr begins_with(std::string_view view, std::string_view prefix);
bool begins_with(std::u32string_view view, std::u32string_view prefix);
bool begins_with(std::string_view view, std::string_view prefix);

bool constexpr is_ascii(std::u32string_view view);
bool constexpr is_ascii(std::string_view view);
Expand Down
7 changes: 4 additions & 3 deletions src/to_ascii.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,19 @@

namespace ada::idna {

bool constexpr begins_with(std::u32string_view view,
std::u32string_view prefix) {
bool begins_with(std::u32string_view view, std::u32string_view prefix) {
if (view.size() < prefix.size()) {
return false;
}
// constexpr as of C++20
return std::equal(prefix.begin(), prefix.end(), view.begin());
}

bool constexpr begins_with(std::string_view view, std::string_view prefix) {
bool begins_with(std::string_view view, std::string_view prefix) {
if (view.size() < prefix.size()) {
return false;
}
// constexpr as of C++20
return std::equal(prefix.begin(), prefix.end(), view.begin());
}

Expand Down

0 comments on commit 3c8be01

Please sign in to comment.