std::remove_const with const references

std::remove_const removes top level const-qualifications. In const T&, which is equivalent to T const&, the qualification is not top-level: in fact, it does not apply to the reference itself (that would be meaningless, because references are immutable by definition), but to the referenced type. Table 52 in Paragraph 20.9.7.1 of the C++11 Standard specifies, regarding … Read more

std::thread error (thread not member of std)

gcc does not fully support std::thread yet: http://gcc.gnu.org/projects/cxx0x.html http://gcc.gnu.org/onlinedocs/libstdc++/manual/status.html Use boost::thread in the meantime. Edit Although the following compiled and ran fine for me with gcc 4.4.3: #include <thread> #include <iostream> struct F { void operator() () const { std::cout<<“Printing from another thread”<<std::endl; } }; int main() { F f; std::thread t(f); t.join(); return 0; … Read more

std::vector resize downward

Calling resize() with a smaller size has no effect on the capacity of a vector. It will not free memory. The standard idiom for freeing memory from a vector is to swap() it with an empty temporary vector: std::vector<T>().swap(vec);. If you want to resize downwards you’d need to copy from your original vector into a … Read more

Android ndk std::to_string support

You can try LOCAL_CFLAGS := -std=c++11, but note that not all C++11 APIs are available with the NDK’s gnustl. Full C++14 support is available with libc++ (APP_STL := c++_shared). The alternative is to implement it yourself. #include <string> #include <sstream> template <typename T> std::string to_string(T value) { std::ostringstream os ; os << value ; return … Read more

std::lexical_cast – is there such a thing?

Only partially. C++11 <string> has std::to_string for the built-in types: [n3290: 21.5/7]: string to_string(int val); string to_string(unsigned val); string to_string(long val); string to_string(unsigned long val); string to_string(long long val); string to_string(unsigned long long val); string to_string(float val); string to_string(double val); string to_string(long double val); Returns: Each function returns a string object holding the character representation … Read more