Why is std::atomic much slower than volatile bool?

Code from “Olaf Dietsche” USE ATOMIC real 0m1.958s user 0m1.957s sys 0m0.000s USE VOLATILE real 0m1.966s user 0m1.953s sys 0m0.010s IF YOU ARE USING GCC SMALLER 4.7 http://gcc.gnu.org/gcc-4.7/changes.html Support for atomic operations specifying the C++11/C11 memory model has been added. These new __atomic routines replace the existing __sync built-in routines. Atomic support is also available … Read more

Deleted function unique_ptr

You aren’t explicitly following the “rule of three” (or is it five these days?). GCC will attempt to generate a copy constructor of UserQueues since you did not explicitly = delete; the copy constructor. When it does that, it will attempt to copy your std::vector<JobDeque>, but since that contains move-only std::unique_ptr‘s, it will fail to … Read more

Where to use the override keyword in C++

You can’t put an override specifier when defining the function outside the class’s member specification. The language doesn’t allow it, and a compiler will complain. So there’s really only one option. Beyond that, this option also makes more sense. When declaring the function you are expressing an intent to override it. So putting override there … Read more

How to handle constructors that must acquire multiple resources in an exception safe manner

Is there a better way? YES C++11 delivers a new feature called delegating constructors which deals with this situation very gracefully. But it is a bit subtle. The problem with throwing exceptions in constructors is to realize that the destructor of the object you’re constructing doesn’t run until the constructor is complete. Though the destructors … Read more

Unexpected behavior after assignment of function object to function wrapper

Object slicing happens here. The point is given f = *p;, p is of type std::shared_ptr<Foo>, then the type of *p is Foo& (instead of Bar&). Even the assignment operator of std::function takes argument by reference, but 4) Sets the target of *this to the callable f, as if by executing function(std::forward<F>(f)).swap(*this);. Note that the … Read more

Ad hoc polymorphism and heterogeneous containers with value semantics

Different alternatives It is possible. There are several alternative approaches to your problem. Each one has different advantages and drawbacks (I will explain each one): Create an interface and have a template class which implements this interface for different types. It should support cloning. Use boost::variant and visitation. Blending static and dynamic polymorphism For the … Read more

When Does Move Constructor get called?

A move constructor is called: when an object initializer is std::move(something) when an object initializer is std::forward<T>(something) and T is not an lvalue reference type (useful in template programming for “perfect forwarding”) when an object initializer is a temporary and the compiler doesn’t eliminate the copy/move entirely when returning a function-local class object by value … Read more

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