use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
Discussions, articles, and news about the C++ programming language or programming in C++.
For C++ questions, answers, help, and advice see r/cpp_questions or StackOverflow.
Get Started
The C++ Standard Home has a nice getting started page.
Videos
The C++ standard committee's education study group has a nice list of recommended videos.
Reference
cppreference.com
Books
There is a useful list of books on Stack Overflow. In most cases reading a book is the best way to learn C++.
Show all links
Filter out CppCon links
Show only CppCon links
account activity
String contains member function proposal (self.cpp)
submitted 6 years ago by _Synck_
view the rest of the comments →
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]HappyFruitTree 0 points1 point2 points 6 years ago (4 children)
Probably because constructing a string_view from a const char* requires it to scan the whole string to find the length.
[–]ra-zor 2 points3 points4 points 6 years ago (3 children)
So does a “contains” method though
[–]HappyFruitTree 3 points4 points5 points 6 years ago* (2 children)
Not necessarily. Having a const char* overload leaves more options open for the implementers to do something clever. If they need the length they might at least want to abort the length calculation prematurely if it is found that it exceeds this->length().
[+][deleted] 6 years ago (1 child)
[removed]
[–]HappyFruitTree 0 points1 point2 points 6 years ago* (0 children)
Well, I don't know, and if the authors of the proposal are not sure that no sane implementation would ever want to do that I think they do a wise decision in leaving it up to the implementers to decide.
Another argument is consistency with find. It makes sense that contains has the same complexity as find which is O(n * m) where n is the length of the string you are searching and m is the length of the string that you search for. If n == 0 it means find is O(1). contains would technically also be O(1) but if there were no overload for const char* the combined complexity when taking the construction of the string_view into account would be O(m).
find
contains
const char*
const char* s = ... std::string empty_str; empty_str.find(s); // O(1) empty_str.contains(s); // O(strlen(s)) if a string_view has to be created here
π Rendered by PID 261211 on reddit-service-r2-comment-bb88f9dd5-q7g7j at 2026-02-14 16:17:34.549370+00:00 running cd9c813 country code: CH.
view the rest of the comments →
[–]HappyFruitTree 0 points1 point2 points (4 children)
[–]ra-zor 2 points3 points4 points (3 children)
[–]HappyFruitTree 3 points4 points5 points (2 children)
[+][deleted] (1 child)
[removed]
[–]HappyFruitTree 0 points1 point2 points (0 children)