3 ms·
That does not look like C++11. You don't use initializer lists. You don't use new-style for-loops. I'll give you that those don't add much to safety, though. A
by daivd 14y ago
That does not look like C++11. You don't use initializer lists. You don't use new-style for-loops. I'll give you that those don't add much to safety, though. A functional style with Boost ranges, adapters and algorithms do, however. I clearly write in the post that you shouldn't use for-loops. Use ranges and pipes.
- pcwalton 14y agoI don't see how Boost algorithms provide the aliasing guarantees you need to avoid invalidating iterators. It's a very difficult problem. Even if you use a library to pipe instances of your custom string class to cout and you trust that library, the method or function that sends your custom string class to cout could perform arbitrary mutations, which would invalidate the iterator. For example: #include <algorithm> #include <iostream> #include <iterator> #include <vector> class mystring { public: std::string m_s; mystring(const std::string &s) : m_s(s) {} }; std::vector<mystring> v; void operator<<(std::ostream &out, const mystring &ms) { v.clear(); out << ms.m_s; } int main() { v.push_back(mystring(std::string("Hello"))); v.push_back(mystring(std::string("world"))); std::copy(v.begin(), v.end(), std::ostream_iterator<mystring>(std::cout, "\n")); return 0; }