What is the cost of singleton tuple construction/access


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?


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.


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?


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


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