Passing/Moving parameters of a constructor in C++0x

You take each one by value, like this: struct foo { foo(std::string s, bar b, qux q) : mS(std::move(s)), mB(std::move(b)), mQ(std::move(q)) {} std::string mS; bar mB; qux mQ; }; The initialization of the function parameters by the argument will either be a copy-constructor or move-constructor. From there, you just move the function parameter values into … Read more

What is the correct way to initialize static data members in C++ (98, 11 and 14)

The rules have always been as follows: A const static data member (SDM) of integral or enumeration type can be initialised in class with a constant expression. A constexpr SDM must be initialised in class with a constant expression. C++17 no longer requires an initializer when the default constructor initialises every member. Also, constexpr SDMs … Read more

C++ ‘typedef’ vs. ‘using … = …’ [duplicate]

They are the same. To quote the C++11 standard (or the draft to be specific): A typedef-name can also be introduced by an alias-declaration. The identifier following the using keyword becomes a typedef-name and the optional attribute-specifier-seq following the identifier appertains to that typedef-name. It has the same semantics as if it were introduced by … Read more

How to store objects without copy or move constructor in std::vector?

For the start, std::mutex can not be copied or moved, therefore you are forced to use some kind of indirection. Since you want to store mutex in a vector, and not copy it, I would use std::unique_ptr. vector<unique_ptr<T>> does not allow certain vector operations (such as for_each) I am not sure I understand that sentence. … Read more

What does the .*& operator do? [duplicate]

typedef std::queue<int> Q; Q is a queue adapted container. typedef Q::container_type C; C is the underlying container of the Q — which is a deque<int>. C & get (Q &q) { get takes a queue and returns a deque. In fact it returns the deque that the queue wraps: by conventional means, this is not … Read more

Can you combine std::recursive_mutex with std::condition_variable?

You can, if you use std::condition_variable_any, which allows for any type of object that supports the Lockable concept. However, in the case of recursive mutex, you do have to ensure that the given thread has only locked the recursive mutex once, since the condition variable only will use the unlock method on the unique_lock once … Read more

Best way to seed mt19937_64 for Monte Carlo simulations

Use std::random_device to generate the seed. It’ll provide non-deterministic random numbers, provided your implementation supports it. Otherwise it’s allowed to use some other random number engine. std::mt19937_64 prng; seed = std::random_device{}(); prng.seed(seed); operator() of std::random_device returns an unsigned int, so if your platform has 32-bit ints, and you want a 64-bit seed, you’ll need to … Read more

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