Re:Std::string half of all allocations in the Chrome browser...
by nightcracker on Friday December 05, 2014 @05:40PM
(#8707348)
#5 and many, many other reasons is why C++ desperately needs a standardized range type. Let's pray it comes in C++17.
Re:Std::string half of all allocations in the Chrome browser...
by pja on Saturday December 06, 2014 @05:12AM
(#8708868)
What would a range type offer over a pair of iterators?
Re:Std::string half of all allocations in the Chrome browser...
by humanrebar on Saturday December 06, 2014 @02:36PM
(#8709938)
cout << takeFirstN(sort(myVector), 10) << '\n';
...try that with iterators.
It's not their fault that C++ only really supports std::string out of the box. What are the alternatives?
1. const std::string & : what if I have a vector<char>?
2. const char * : what if it's not null terminated?
3. const char * and size_t : Better, but what if I have a deque<char>?
4. const char * start, const char * stop : Better because you can write algorithms around this, but still, doesn't help with deque<char>?
5. template on START_ITER and STOP_ITER : The best we have now if you need an extremely general solution. But I hope writing your implementation in headers is fine.
6. home grown type : a very popular choice, but http://xkcd.com/927/
7. boost::string_ref : maybe the best choice, as it can be created from 1-4 (and most 6's), but still doesn't work with deque<char>.
...so give the rookie a break. But I'll support any comment in a code review about not accepting std::string by reference or by value in an interface.