Can C++ array end at memory boundary?

An implementation must allow a pointer to one past the end to exist. How it does this is its business. On many machines, you can safely put any value into a pointer, without risk (unless you dereference it); on such systems, the one past the end pointer may point to unmapped memory—I’ve actually encountered a … Read more

Use of enable_shared_from_this with multiple inheritance

Indeed you are doing it wrong. If you have simple inheritance, just inherit from enable_shared_from this in the base class, and derived class get it for free. (of course you’ll need to downcast the result) If you have multiple inheritance (like it seems), you must use the trick described here and also here : /* … Read more

Performance of resizing std::vector

The claim that unique_ptr performs as well as a raw pointer after optimization mostly applies only to the basic operations on a single pointer, such as creation, dereferencing, assignment of a single pointer and deletion. Those operations are defined simply enough that an optimizing compiler can usually make the required transformations such that the resulting … Read more

capture by value class members

No, data members cannot be captured by value. A lambda can capture only two kinds of things: the this pointer, and nonstatic local variables (that is, variables with automatic storage duration). As has been noted by ildjarn in the comments, you can create a local variable with a copy of the value of the data … Read more

Timeout for thread.join()

There is no timeout for std::thread::join(). However you can view std::thread::join() as merely a convenience function. Using condition_variables you can create very rich communication and cooperation between your threads, including timed waits. For example: #include <chrono> #include <thread> #include <iostream> int thread_count = 0; bool time_to_quit = false; std::mutex m; std::condition_variable cv; void f(int id) … Read more

Should I use C++11 emplace_back with pointers containers?

Don’t use raw pointers, use std::unique_ptr like this: std::vector<std::unique_ptr<Fruit>> m_fruits; And as you can’t copy construct a std::unique_ptr you must use emplace_back (although you can use push_back with std::move). m_fruits.emplace_back(new Pear()); m_fruits.emplace_back(new Tomato()); Edit: As it appears that using std::vector<std::unique_ptr<T>>::emplace_back and new can leak if the std::vector needs and fails to reallocate memory, my recommended … Read more

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