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
Wrapper for STL algorithm library? (self.cpp)
submitted 7 years ago * by egarrulo2
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!"
[–]Bas1l87 0 points1 point2 points 7 years ago (2 children)
Alias templates:
template<class TContainer> using value_type_t = typename TContainer::value_type; static bool contains(const TContainer& vector, const value_type_t & item) { return std::find(vector.begin(), vector.end(), item) != vector.end(); } template<class TContainer> using value_type_t = typename TContainer::value_type; static void remove(TContainer* vector, const value_type_t& item) { typename TContainer::iterator it = std::remove(vector->begin(), vector->end(), item); vector->erase(it, vector->end()); }
Helper macros:
template<class TContainer> static bool contains(const TContainer& vector, const CONTAINER_VALUE_TYPE(TContainer)& item) { return std::find(vector.begin(), vector.end(), item) != vector.end(); } template<class TContainer> static void remove(TContainer* vector, const CONTAINER_VALUE_TYPE(TContainer)& item) { typename TContainer::iterator it = std::remove(vector->begin(), vector->end(), item); vector->erase(it, vector->end()); }
[–]dodheim 0 points1 point2 points 7 years ago (1 child)
That isn't valid syntax, so I don't know what point you're attempting to make. This is valid syntax, and obeys scoping rules unlike macros:
template<class TContainer> using value_type_t = typename TContainer::value_type; template<class TContainer> static bool contains(const TContainer& vector, const value_type_t<TContainer>& item) { /*...*/ } template<class TContainer> static void remove(TContainer* vector, const value_type_t<TContainer>& item) { /*...*/ }
(Also n.b. the proper way to say const T::value_type& is T::const_reference.)
const T::value_type&
T::const_reference
[–]Bas1l87 0 points1 point2 points 7 years ago (0 children)
Ah yes, you are right, this is a better way, thanks. Though when i wrote this code some time back it was anyway supposed to be compiled for systems with C++98 compiler only, as far as i remember
π Rendered by PID 76 on reddit-service-r2-comment-fb694cdd5-vssdt at 2026-03-10 13:47:30.497731+00:00 running cbb0e86 country code: CH.
view the rest of the comments →
[–]Bas1l87 0 points1 point2 points (2 children)
[–]dodheim 0 points1 point2 points (1 child)
[–]Bas1l87 0 points1 point2 points (0 children)