string-view-lite | string_view lite - A C17-like string_view | File Utils library
kandi X-RAY | string-view-lite Summary
kandi X-RAY | string-view-lite Summary
string_view lite - A C++17-like string_view for C++98, C++11 and later in a single-file header-only library
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of string-view-lite
string-view-lite Key Features
string-view-lite Examples and Code Snippets
Community Discussions
Trending Discussions on string-view-lite
QUESTION
I have a codebase which makes extensive use of CUDA, which unfortunately only supports C++14 to date. However, I still want to use string_view, which is a C++17 feature. The implementation is relatively straight-forward, especially since I do not require the 'find' functionalities.
However, I do need hashing to work. The standard mandates that std::hash of a string_view must be the equal to the hash of a string constructed from the string_view (and I intend to rely on this guarantee). Is there a standard-conform way of getting the output from std::hash without having to temporarily construct a string object, which may come with an unoptimizable heap allocation (which is the route that string-view-lite went)? I would rather not rely on copying over the algorithm from the concrete stdlib implementation, since that might break in the future or already breaks compilation with older versions.
Alternatively, is there a way to let MSVC (EDIT: v14.16) use std::string_view in C++14-mode, which NVCC also recognizes? It would be great if Clang and GCC had a similar option as well, since the codebase might migrate away from MSVC one day.
...ANSWER
Answered 2019-Feb-09 at 14:05You are out of luck in my opinion since, also by assuming that you could mimic the internal structure and pass a tailored object to fulfill and look like a std::string
, that would surely be more fragile than just copying the implementation.
I see two choices, either:
you copy the
std::hash
specialization implementation and put some asserts with hardcoded cases which may warn you if anything changes or is different (rather a clumsy solution).you provide your own hash function which overrides
std::string
one and pass it as template argument so that you can enforce the constraint of them being equal when working with STL collections.
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install string-view-lite
Add nonstd-lite to the conan remotes: conan remote add nonstd-lite https://api.bintray.com/conan/martinmoene/nonstd-lite
Add a reference to string-view-lite to the requires section of your project's conanfile.txt file: [requires] string-view-lite/[~=1]@nonstd-lite/testing
Run conan's install command: conan install
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page