C++ & Boost: encode/decode UTF-8

Thanks everyone, but ultimately I resorted to http://utfcpp.sourceforge.net/ — it’s a header-only library that’s very lightweight and easy to use. I’m sharing a demo code here, should anyone find it useful: inline void decode_utf8(const std::string& bytes, std::wstring& wstr) { utf8::utf8to32(bytes.begin(), bytes.end(), std::back_inserter(wstr)); } inline void encode_utf8(const std::wstring& wstr, std::string& bytes) { utf8::utf32to8(wstr.begin(), wstr.end(), std::back_inserter(bytes)); } … Read more

how do you make a heterogeneous boost::map?

#include <map> #include <string> #include <iostream> #include <boost/any.hpp> int main() { try { std::map<std::string, boost::any> m; m[“a”] = 2; m[“b”] = static_cast<char const *>(“black sheep”); int i = boost::any_cast<int>(m[“a”]); std::cout << “I(” << i << “)\n”; int j = boost::any_cast<int>(m[“b”]); // throws exception std::cout << “J(” << j << “)\n”; } catch(…) { std::cout << … Read more

Copy a streambuf’s contents to a string

I don’t know whether it counts as “excessive copying“, but you can use a stringstream: std::ostringstream ss; ss << someStreamBuf; std::string s = ss.str(); Like, to read everything from stdin into a string, do std::ostringstream ss; ss << std::cin.rdbuf(); std::string s = ss.str(); Alternatively, you may also use a istreambuf_iterator. You will have to measure … Read more

C++ Boost: what’s the cause of this warning?

It is nothing to worry about. In the last few releases of MSVC, they’ve gone into full security-paranoia mode. std::copy issues this warning when it is used with raw pointers, because when used incorrectly, it can result in buffer overflows. Their iterator implementation performs bounds checking to ensure this doesn’t happen, at a significant performance … Read more

Official “Boost library” Support for Android and iOS? [closed]

Got reply from boost community Yes. These platforms are not officially supported because no one has volunteered to run regression tests regularly for them. It is not possible for a Boost developer to test on all platforms. So developers depend on the test results of regression tests run by volunteers. For example, see http://beta.boost.org/development/tests/trunk/developer/summary.html If … Read more