-
Notifications
You must be signed in to change notification settings - Fork 45
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
std::search called in search() when compiling with C++14 #50
Comments
Oh, actually, maybe it's a dupe of my other bug. |
You can try defining string-view-lite/include/nonstd/string_view.hpp Lines 554 to 576 in 5b1d95f
|
The unconditional I'd like // Presence of C++20 library features:
#define nssv_HAVE_CONSTEXPR_20_LIB nssv_CPP20_000
// ...
#if nssv_HAVE_CONSTEXPR_20_LIB
# define nssv_constexpr20_lib constexpr
#else
# define nssv_constexpr20_lib /*constexpr*/
#endif
// ...
#else // OPTIMIZE
// non-recursive:
template< class CharT, class Traits = std::char_traits<CharT> >
nssv_constexpr20_lib const CharT* search( basic_string_view<CharT, Traits> haystack, basic_string_view<CharT, Traits> needle )
{
return std::search( haystack.begin(), haystack.end(), needle.begin(), needle.end() );
}
#endif // OPTIMIZE |
I think it makes sense to remove the branch on |
However, a possibly recursive search, possibly exhausting the stack doesn't look like the right thing to do at default. |
Ah right. In that case, what about replacing the second implementation with something like: template< class CharT, class Traits = std::char_traits<CharT> >
nssv_constexpr14 const CharT* search( basic_string_view<CharT, Traits> haystack, basic_string_view<CharT, Traits> needle )
{
while (needle.size() <= haystack.size()) {
if (haystack.starts_with(needle)) {
return haystack.cbegin();
}
haystack = basic_string_view<CharT, Traits>{ haystack.begin() + 1, haystack.size() - 1U };
}
return haystack.cend();
} |
Although I suppose it would make sense to allow a user to select |
@oliverlee Thanks for your suggestions! |
Thanks for sharing your implementation of string view! |
@oliverlee) Allow to avoid constexpr with std::search() and select a local implementation for it for C++14 constexpr.
I'm trying to compile one of the examples of my cuda-api-wrappers library, which uses string-view-lite, using C++14 instead of C++11 like I was compiling it so far. I get:
and, indead, std::search is not constexpr before C++20.
The text was updated successfully, but these errors were encountered: