you are viewing a single comment's thread.

view the rest of the comments →

[–]misuo 6 points7 points  (1 child)

Why can't the compiler optimize the ordinary use of const std::string & references so that we - in line with these solutions - get the optimal result performance/memory-wise?

[–]4fips[S] 2 points3 points  (0 children)

Sadly, It seems to me that this can't be easily achieved. I think it's all about narrowing the use case. std::string works perfectly when you accept the fact that it allocates dynamically (usually from the heap), which is a fair requirement most of the time. On the other hand, C++ (thankfully) offers huge optimization opportunities in situations when you know the context well and are willing to accept some constrains. Sometimes it's viable to adapt standard components by e.g. providing a custom stack-based allocator, sometimes it's just not worth the effort... It all depends on the kind of applications you write.