Using a std::unordered_set of std::unique_ptr

You can also use a deleter that optionally doesn’t do anything. template<class T> struct maybe_deleter{ bool _delete; explicit maybe_deleter(bool doit = true) : _delete(doit){} void operator()(T* p) const{ if(_delete) delete p; } }; template<class T> using set_unique_ptr = std::unique_ptr<T, maybe_deleter<T>>; template<class T> set_unique_ptr<T> make_find_ptr(T* raw){ return set_unique_ptr<T>(raw, maybe_deleter<T>(false)); } // … int* raw = new … Read more

What is the difference between using explicit fences and std::atomic?

Although various answers cover bits and pieces of what the potential problem is and/or provide useful information, no answer correctly describes the potential issues for all three cases. In order to synchronize memory operations between threads, release and acquire barriers are used to specify ordering. In the diagram, memory operations A in thread 1 cannot … Read more

Implementation of addressof

First you have __r which is of type _Tp& It is reinterpret_cast‘ed to a char& in order to ensure being able to later take its address without fearing an overloaded operator& in the original type; actually it is cast to const volatile char& because reinterpret_cast can always legally add const and volatile qualifiers even if … Read more

Why is “error: invalid application of ‘sizeof’ to an incomplete type using unique_ptr” fixed by adding an empty destructor? [duplicate]

If we go to the cppreference document for std::unique_ptr: std::unique_ptr may be constructed for an incomplete type T, such as to facilitate the use as a handle in the Pimpl idiom. If the default deleter is used, T must be complete at the point in code where the deleter is invoked, which happens in the … Read more

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