std::thread error (thread not member of std)

gcc does not fully support std::thread yet: http://gcc.gnu.org/projects/cxx0x.html http://gcc.gnu.org/onlinedocs/libstdc++/manual/status.html Use boost::thread in the meantime. Edit Although the following compiled and ran fine for me with gcc 4.4.3: #include <thread> #include <iostream> struct F { void operator() () const { std::cout<<“Printing from another thread”<<std::endl; } }; int main() { F f; std::thread t(f); t.join(); return 0; … Read more

What are the 15 classifications of types in C++?

I spoke with Walter directly, and it was simply a miscount. “Alas, I realized shortly thereafter that I’d miscounted and hence committed an off-by-one error during the talk: there are 14 (not 15) type classifications. See the list of primary type category predicates in clause [meta.unary.cat] in the C++ standard; these correspond to the classifications … Read more

Is writing to &str[0] buffer (of a std:string) well-defined behaviour in C++11?

Yes, the code is legal in C++11 because the storage for std::string is guaranteed to be contiguous and your code avoids overwriting the terminating NULL character (or value initialized CharT). From N3337, ยง21.4.5 [string.access] const_reference operator[](size_type pos) const; reference operator[](size_type pos); 1 Requires: pos <= size(). 2 Returns: *(begin() + pos) if pos < size(). … Read more

Should we use constexpr everywhere we can?

It won’t bother the compiler. The compiler will (or should anyway) give you a diagnostic when/if you use it on code that doesn’t fit the requirements of a constexpr. At the same time, I’d be a bit hesitant to just slap it on there because you could. Even though it doesn’t/won’t bother the compiler, your … Read more

Use cases for std::error_code

I was wondering about that a while back myself and found the answer here. Essentially, error_code is used to store and transport error codes, while error_condition is used to match error codes. void handle_error(error_code code) { if (code == error_condition1) do_something(); else if(code == error_condition2) do_something_else(); else do_yet_another_thing(); } Each error_condition is equivalent to a … Read more

error code vs error condition

From http://en.cppreference.com/w/cpp/error/error_condition std::error_condition is a platform-independent error code. Like std::error_code, it is uniquely identified by an integer value and a std::error_category, but unlike std::error_code, the value is not platform-dependent. So, the advantage is your error code isn’t specific to the platform you’re working on when using std::error_condition. With an std::error_code Each std::error_code object holds a … Read more

Why does C++ move semantics leave the source constructed?

In the “universe of move operations” there are four possibilities: target source is is left ———————————————————- constructed <– constructed // C++11 — move construction constructed <– destructed assigned <– constructed // C++11 — move assignment assigned <– destructed Each of these operations is useful! std::vector<T>::insert alone could make use of the first three. Though note: … Read more

Is std::any_of required to follow short circuit logic?

The standard itself doesn’t place any such hard requirement. But one may infer it is indirectly encouraged ([alg.any_of]): template <class InputIterator, class Predicate> bool any_of(InputIterator first, InputIterator last, Predicate pred); template <class ExecutionPolicy, class ForwardIterator, class Predicate> bool any_of(ExecutionPolicy&& exec, ForwardIterator first, ForwardIterator last, Predicate pred); Returns: false if [first, last) is empty or if … Read more

Difference between global non-throwing ::operator new and std::malloc

The main differences, aside from syntax and free vs. delete, are you can portably replace ::operator new; malloc comes with realloc, for which new has no equivalent; new has the concept of a new_handler, for which there is no malloc equivalent. (Replacing malloc opens up a can of worms. It can be done, but not … Read more

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