How to construct expression templates from operations on fundamental data types?

107 views Asked by At

I'm trying to build expression templates from maths operations in order to correctly sequence unsequenced operations (such as opertor+).

The reason is because operator co_await with operator+ appears to be unsequenced (resulting in incorrect results from generators/yielding tasks). See here C++20 Coroutines, Unexpected reordering of await_resume, return_value and yield_value.

If I can use expression templates on primitive data types I can manually sequence the execution using expression templates. This is mainly an excercise to determine whether its possible (not whether its a good idea) to detemine whether a possible work around for the issue exists.

If its not possible to get global operators overloaded for primative types then does anybody have any ideas how to inject expression templates into existing operator based maths code.


Ongoing Research


Operators require atleast 1 class type for overloads:

why C++ operator overloading requires "having at least one parameter of class type"?

So, I cannot do it for fundamental data types. So it transforms this questions focus to be around other ways to transform fundamental data type expressions into expression templates.


As per comment below from Peter. As the arguments of operator+(a,b) are unsequenced this approach will not work :(


0

There are 0 answers