Comments (9)
Although I suppose it would make sense to allow a user to select std::search
via a preprocessor macro (or vice-versa).
from string-view-lite.
Oh, actually, maybe it's a dupe of my other bug.
from string-view-lite.
You can try defining __OPTIMIZE__
before including string_view.hpp
or build with optimizations enabled.
string-view-lite/include/nonstd/string_view.hpp
Lines 554 to 576 in 5b1d95f
from string-view-lite.
The unconditional constexpr
in the non-optimize case of constexpr const CharT* search()
should perhaps be replaced with something like nssv_constexpr20_lib
.
I'd like nssv_HAVE_CONSTEXPR_20_LIB
to be not overly restrictive as it may be as show below. Suggestions are quite welcome.
// 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
from string-view-lite.
I think it makes sense to remove the branch on _OPTIMIZE_
. By removing the call to std::search
, this would allow use in constant expressions with debug builds.
from string-view-lite.
However, a possibly recursive search, possibly exhausting the stack doesn't look like the right thing to do at default.
from string-view-lite.
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();
}
from string-view-lite.
@oliverlee Thanks for your suggestions!
from string-view-lite.
Thanks for sharing your implementation of string view!
from string-view-lite.
Related Issues (20)
- [Readme] Add to_string(allocator) for <C++11 to table HOT 2
- `find_last_of` and `find_last_not_of` infinite loop
- Add cstring_view adapter HOT 2
- Literal string constructors should be marked noexcept HOT 5
- test on linux HOT 3
- nssv_CPP11 not defined HOT 1
- CMake Release? HOT 3
- Add badge to conan-center HOT 1
- Comparison to C string doesn't compile with VC 2010 HOT 3
- -Wshadow fails HOT 4
- Error with incomplete type when compiling using NEC compiler HOT 5
- template function length will occur with debug HOT 2
- Non constexpr operator== HOT 25
- Compile errors with clang on Windows HOT 2
- Wrong check for stream vs sentry HOT 3
- Prevent construction/conversion from nullptr HOT 1
- Make find() constexpr in C++11 HOT 7
- Another release please... HOT 8
- Change license to BSL
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from string-view-lite.