Why is “Init” in std::ios_base::Init uppercase? [closed]

In an early draft of the IOStream classes you can see that ios_base was originally not present, basic_ios was the base class and was responsible for Init and other members which were later separated into ios_base. basic_ios also had (and still has) an init function, and while the two names did not necessarily have to … Read more

Can I take the address of a function defined in standard library?

Short answer No. Explanation [namespace.std] says: Let F denote a standard library function ([global.functions]), a standard library static member function, or an instantiation of a standard library function template. Unless F is designated an addressable function, the behavior of a C++ program is unspecified (possibly ill-formed) if it explicitly or implicitly attempts to form a … Read more

std::atomic | compare_exchange_weak vs. compare_exchange_strong

The note gives a clue, referring to LL/SC architectures. From the Wikipedia article: If any updates have occurred, the store-conditional is guaranteed to fail, even if the value read by the load-link has since been restored. As such, an LL/SC pair is stronger than a read followed by a compare-and-swap (CAS), which will not detect … Read more

What STL algorithm can determine if exactly one item in a container satisfies a predicate?

Two things come to my mind: std::count_if and then compare the result to 1. To avoid traversing the whole container in case eg the first two elements already match the predicate I would use two calls looking for matching elements. Something along the line of auto it = std::find_if(begin,end,predicate); if (it == end) return false; … Read more

Android ndk std::to_string support

You can try LOCAL_CFLAGS := -std=c++11, but note that not all C++11 APIs are available with the NDK’s gnustl. Full C++14 support is available with libc++ (APP_STL := c++_shared). The alternative is to implement it yourself. #include <string> #include <sstream> template <typename T> std::string to_string(T value) { std::ostringstream os ; os << value ; return … Read more

Idiomatic use of std::rel_ops

The way operator overloads for user defined classes was meant to work is via argument dependent lookup. ADL allows programs and libraries to avoid cluttering up the global namespace with operator overloads, but still allow convenient use of the operators; That is, without explicit namespace qualification, which is not possible to do with the infix … Read more

Do std::min(0.0, 1.0) and std::max(0.0, 1.0) yield undefined behavior?

In the new [concepts.equality], in a slightly different context, we have: An expression is equality-preserving if, given equal inputs, the expression results in equal outputs. The inputs to an expression are the set of the expression’s operands. The output of an expression is the expression’s result and all operands modified by the expression. Not all … Read more

How to correctly use std::reference_wrappers

Class std::reference_wrapper<T> implements an implicit converting operator to T&: operator T& () const noexcept; and a more explicit getter: T& get() const noexcept; The implicit operator is called when a T (or T&) is required. For instance void f(some_type x); // … std::reference_wrapper<some_type> x; some_type y = x; // the implicit operator is called f(x); … Read more

Why is operator!= removed in C++20 for many standard library types?

In C++20 the way that the relational operators work was changed, notably with the introduction of the spaceship <=> operator. In particular, If you only provide operator==, then a != b is rewritten to !(a == b). From [over.match.oper]/3.4: The rewritten candidate set is determined as follows: For the relational ([expr.rel]) operators, the rewritten candidates … Read more

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