Are empty macro arguments legal in C++11?

If I understand correctly, empty macro argument is allowed since C99 and C++0x(11). C99 6.10.3/4 says: … the number of arguments (including those arguments consisting of no preprocessing tokens) shall equal the number of parameters … and C++ N3290 16.3/4 has the same statement, while C++03 16.3/10 mentions: … any argument consists of no preprocessing … Read more

Simultaneously iterating over and modifying an unordered_set?

Could you mess with max_load_factor somehow to prevent rehashing? Yes, you can set the max_load_factor() to infinity to ensure no rehashing occurs: #include <iostream> #include <limits> #include <unordered_set> int main() { // initialize std::unordered_set<int> S; for (int i = 0; i < 8; ++i) S.insert(i); std::cout << “buckets: ” << S.bucket_count() << std::endl; // infinite … Read more

Proper way of transferring ownership of a std::vector< std::unique_ptr< int> > to a class being constructed

std::unique_ptr<T> is a non-copyable but movable type. Having a move-only type in a std:vector<T> make the std::vector<T> move-only, too. To have the compiler automatically move objects, you need to have an r-value for move-construction or move-assignment. Within your constructor the object vecOfIntPtrsOwnedByCaller is an l-value, although one which, despite its name, already owns the pointed … Read more

Can a shared lock on a std::shared_timed_mutex be upgraded to an exclusive lock?

No, it can not. That functionality was proposed to the committee under the name upgrade_mutex and upgrade_lock, but the committee chose to reject that portion of the proposal. There is currently no work under way to re-prepose that functionality. Edit In response to the “where to go from here” edit in user3761401’s question, I’ve created … Read more

Using boost::future with “then” continuations

Boost.Thread comes in several versions of which you can choose via the BOOST_THREAD_VERSION macro. Currently, the default is 2. Up to version 2 of Boost.Thread, the name boost::unique_future was used for this class template (compare to boost::shared_future). Probably because of the standardization of std::future, more recent versions can use the name boost::future. Starting with version … 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

Enum to string in C++11

The longstanding and unnecessary lack of a generic enum-to-string feature in C++ (and C) is a painful one. C++11 didn’t address this, and as far as I know neither will C++14. Personally I’d solve this problem using code generation. The C preprocessor is one way–you can see some other answers linked in the comments here … Read more

C11 GCC threads.h not found?

The gcc document C11 status indicates that it does not support threading, it says: Threading [Optional] | Library issue (not implemented) As the document indicates this is not really a gcc or clang issue but glibc issue. As Zack pointed out it looks like there may be work under way soon to get support for … Read more

Why are override and final identifiers with special meaning instead of reserved keywords?

Adding new keywords is difficult because it takes away identifiers from the user. It ends up being a trade-off between choosing identifiers that potentially break old code currently using the identifier or choosing names that are highly unlikely to break old code but are ugly or not meaningful to the way they are being used. … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)