What is the cost of singleton tuple construction/access


#1

I have had to introduce some type wrappers to be able to redefine the + /- operators, and I am concerned about the cost. If I have a wrapper like this:

struct Wrapper<T>(T);

Will the construction and access get completely optimised away by the compiler?


#2

Ideally yes. There is no indirection (pointer) or memory overhead, but there are open bugs like #24963 that mean that there are situations where the wrapper does not optimize equivalently to the underlying type.


#3

Perhaps the best idea is to use a normal function for now, although it would be nice to use the common notation for add and subtract?


#4

Impossible to say without context, do you think it has any impact in your case?


#5

It’s a library, so its difficult to say how people will use it.