Why is operator!= removed in C++20 for many standard library types?

In C++20 the way that the relational operators work was changed, notably with the introduction of the spaceship <=> operator. In particular, If you only provide operator==, then a != b is rewritten to !(a == b). From [over.match.oper]/3.4: The rewritten candidate set is determined as follows: For the relational ([expr.rel]) operators, the rewritten candidates … Read more

How can I use a std::valarray to store/manipulate a contiguous 2D array?

Off the top of my head: template <class element_type> class matrix { public: matrix(size_t width, size_t height): m_stride(width), m_height(height), m_storage(width*height) { } element_type &operator()(size_t row, size_t column) { // column major return m_storage[std::slice(column, m_height, m_stride)][row]; // row major return m_storage[std::slice(row, m_stride, m_height)][column]; } private: std::valarray<element_type> m_storage; size_t m_stride; size_t m_height; }; std::valarray provides many interesting … Read more

How similar are Boost.Filesystem and the C++ standard filesystem library?

There are a number of differences. Some were, I believe, Boost changes that were never propagated. For example, there is no path.filename_is_dot() query (as discussed below, it would be less useful in std::filesystem anyway). There was also a good bit of late-breaking news on this front: Support for non-POSIX-like filesystems: Specify whether a string is … 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

Why isn’t there int128_t?

I’ll refer to the C standard; I think the C++ standard inherits the rules for <stdint.h> / <cstdint> from C. I know that gcc implements 128-bit signed and unsigned integers, with the names __int128 and unsigned __int128 (__int128 is an implementation-defined keyword) on some platforms. Even for an implementation that provides a standard 128-bit type, … Read more