-
Notifications
You must be signed in to change notification settings - Fork 73
Add equality operator between string_view and char* #12
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
Conversation
inline | ||
bool operator == (const string_view lhs, const char* rhs) { | ||
return std::equal(lhs.begin(), lhs.end(), rhs) && !rhs[lhs.size() + 1]; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You really should be using strcmp here -- and I'm not sure if this is also something you want to add to the URI library.
I would suggest you bring this up with Boost.string_ref maintainers.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi
I didn't use strcmp because string_ref is not \0 termined. Is it ok to use it in this situation?
I didn't talk this on the boost mailing list because from what I understand string_ref it's a implementation of a future C++ spec proposal, and the string_ref proposal was replaced by string_view, and string_view will not even be part of C++14
So I was thinking "I can't talk this on boost because they must follow a now rejected ISO C++ proposal, and I'm only a student...I'm not sure about discussing of the string_view proposal in the ISO C++ mailing list. All I want is be able to compile netlib tip"
What do you think it's the correct way to fix it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know why you need this to make the code compile -- can you show me the sample code that you can't compile?
I would rather you bring this up with Boost (it doesn't matter really if you're still a student, everybody's welcome on the Boost mailing list as long as you don't troll and are agreeable in discussion). :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have pasted here what GCC 4.8 says: https://gist.github.com/nico159/5597288/raw/6cd9732b6155267bfaaeb9511ab261be45b3555b/gistfile1.txt
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interesting. Can you just change that part of cpp-netlib instead that doesn't build, use string_ref.compare(...)
, and send a PR to fix that case? I would suppose you still want to ask the Boost mailing list why string_ref doesn't have equality operator for const char*
when it really should have one.
Ok, you have a pull request for cpp-netlib As written in the commit using compare has some overhead, so I will post on the Boost mailing list for asking the inclusion of an equality operator between string_ref and char* |
The next version of Boost will have the string_ref operators that works with both string and const char* |
Sounds like this is something that has been resolved. |
Hi,
boost::string_ref don't have an equality operator between string_view and char*, so I added one
It first compare using std::equal and if it return true then search if we are at the end of the char*
I didn't search first for the possible \0 charter at size() + 1 because possible memory check made by OS/C++ runtime (or it's safe?)
I'm just started learning C++, so I don't know if this commit it's ok
The test suite for uri it's all green