How to write a std::string to a UTF-8 text file

The only way UTF-8 affects std::string is that size(), length(), and all the indices are measured in bytes, not characters. And, as sbi points out, incrementing the iterator provided by std::string will step forward by byte, not by character, so it can actually point into the middle of a multibyte UTF-8 codepoint. There’s no UTF-8-aware …

Read more

Is make_shared really more efficient than new?

As infrastructure I was using llvm/clang 3.0 along with the llvm std c++ library within XCode4. Well that appears to be your problem. The C++11 standard states the following requirements for make_shared<T> (and allocate_shared<T>), in section 20.7.2.2.6: Requires: The expression ::new (pv) T(std::forward(args)…), where pv has type void* and points to storage suitable to hold …

Read more

Why must I provide ‘operator ==’ when ‘operator ‘ is enough?

Why must I provide operator== when operator<=> is enough? Well, mainly because it’s not enough 🙂 Equality and ordering are different buckets when it comes time for C++ to rewrite your statements: Equality Ordering Primary == <=> Secondary != <, >, <=, >= Primary operators have the ability to be reversed, and secondary operators have …

Read more