Transparent Operator Functors

The transparent operator functors proposal is there as a way to have generalised functors that are located in <functional>. I personally believe the proposal itself has a very good example that would help illustrate the need for it. However I’ll go ahead and try to explain it as well. Suppose you have a function, a … Read more

How undefined are __builtin_ctz(0) or __builtin_clz(0)?

Unfortunately, even x86-64 implementations can differ – from Intel’s instruction set reference,BSF and BSR, with a source operand value of (0), leaves the destination undefined, and sets the ZF (zero flag). So the behaviour may not be consistent between micro-architectures or, say, AMD and Intel. (I believe AMD leaves the destination unmodified.) The newer LZCNT … Read more

Overload resolution between value, rvalue reference, const lvalue reference

What are the rules here? As there is only one parameter, the rule is that one of the three viable parameter initializations of that parameter must be a better match than both the other two. When two initializations are compared, either one is better than the other, or neither is better (they are indistinguishable). Without … Read more

Can a shared lock on a std::shared_timed_mutex be upgraded to an exclusive lock?

No, it can not. That functionality was proposed to the committee under the name upgrade_mutex and upgrade_lock, but the committee chose to reject that portion of the proposal. There is currently no work under way to re-prepose that functionality. Edit In response to the “where to go from here” edit in user3761401’s question, I’ve created … Read more

What is the correct way to initialize static data members in C++ (98, 11 and 14)

The rules have always been as follows: A const static data member (SDM) of integral or enumeration type can be initialised in class with a constant expression. A constexpr SDM must be initialised in class with a constant expression. C++17 no longer requires an initializer when the default constructor initialises every member. Also, constexpr SDMs … Read more

C++ (14) and manual memory management

Caveat: I stand by this answer since I think it presents a best practice which will improve ~95% of C++ code – probably even more. That said, please read the full comments for a discussion of some important caveats. Since it was my comment, here’s my presentation explaining this. In a nutshell: [Raw] pointers must. not. … Read more

C++ Zero-Initialization

The following MyTest testObj = {}; is not zero-initialization for MyTest, but is simply calling its default constructor. The cppreference page explains why (emphasis mine): As part of value-initialization sequence for non-class types and for members of value-initialized class types that have no constructors, including value initialization of elements of aggregates for which no initializers … Read more

Get types of C++ function parameters

This syntax is slightly different. First, because types are easier to work with than packs, a type that holds a pack. The using type=types; just saves me work in the code that generates a types: template<class…>struct types{using type=types;}; Here is the workhorse. It takes a signature, and produces a types<?…> bundle containing the arguments for … Read more

Is there any way to enforce that instances are only ever on the stack?

Disclaimer: ‘stack’ is not part of the c++ standard to my knowledge, there we have ASDVs (automatic storage duration variables). ABI might define stack. Note that sometimes these are passed in registers, which I believe is OK in your case. Define a CPS (continuation-passing style) factory method: class A { public: template<typename F, typename… Args> … Read more

techhipbettruvabetnorabahisbahis forumueduseduseduedueduseduedueduseduedus