Why does not a template template parameter allow ‘typename’ after the parameter list

Short answer: because the Standard says so. Longer answer: prior to Standardization, C++ templates required the class keyword for all template parameters. However, to stress the fact that templates could also be of non-class (i.e. builtin) type, an alternative keyword typename was introduced. However, in C++98, template-template parameters could only be of class-type, and this … Read more

How do smart pointers choose between delete and delete[]?

Unfortunately, they don’t know what delete to use therefore they use delete. That’s why for each smart pointer we have a smart array counterpart. std::shared_ptr uses delete std::shared_array uses delete[] So, your line std :: unique_ptr <int> x (new int [2]); actually causes undefined behavior. Incidentally, if you write std :: unique_ptr<int[]> p(new int[2]); ^^ … Read more

std::shared_ptr Exception Safety

template<class Y> explicit shared_ptr(Y* p); [util.smartptr.shared.const]/6 Throws: bad_alloc, or an implementation-defined exception when a resource other than memory could not be obtained. [util.smartptr.shared.const]/7 Exception safety: If an exception is thrown, delete p is called. So no, no memory leak.

Is there a Boost.Bimap alternative in c++11?

Short answer: no. Long answer: nope. It should be noted that C++14‘s support for transparent comparators eliminates the need for Boost.Bimap 90% of the time*: when you need to key off of any given property of an object (stored or computed), often a simple, bitwise-comparable unique identifier inherent to/present in the object anyway. With transparent … Read more

When is a lambda trivial?

The standard does not specify whether a closure type (the type of a lambda expression) is trivial or not. It explicitly leaves this up to implementation, which makes it non-portable. I am afraid you cannot rely on your static_assert producing anything consistent. Quoting C++14 (N4140) 5.1.2/3: … An implementation may define the closure type differently … Read more

Can a lambda capturing nothing access global variables?

Yes, sure. Normal name lookup rules apply. [expr.prim.lambda]/7 … for purposes of name lookup … the compound-statement is considered in the context of the lambda-expression. Re: why local variables are treated differently from global ones. [expr.prim.lambda]/13 … If a lambda-expression or an instantiation of the function call operator template of a generic lambda odr-uses (3.2) … Read more

Can you implement a timer without a “sleep” in it using standard c++/c++11 only?

C++11 provides us with std::condition_variable. In your timer you can wait until your condition has been met: // Somewhere else, e.g. in a header: std::mutex mutex; bool condition_to_be_met{false}; std::condition_variable cv; // In your timer: // … std::unique_lock<std::mutex> lock{mutex}; if(!cv.wait_for(lock, std::chrono::milliseconds{timeout_ms}, [this]{return condition_to_be_met;})) std::cout << “timed out!” << std::endl; You can find more information here: https://en.cppreference.com/w/cpp/thread/condition_variable … Read more

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