Trick-17 / FMath

Math library for operations on fields
MIT License
3 stars 0 forks source link

Check if Field needs a move constructor #3

Closed GPMueller closed 5 years ago

GPMueller commented 6 years ago

If a function returns a field and there is no default move, the copy constructor will be used, leading to potentially significant inefficiencies.

NOhs commented 6 years ago

This is not entirely true. The compiler will still try to create the object in place where the function was called https://stackoverflow.com/q/12953127/2305545. Here you can read if or if not a move constructor is implocitly created https://stackoverflow.com/q/26227431/2305545

GPMueller commented 5 years ago

This blog post gives a nice overview of when which constructors are generated or not: https://foonathan.net/blog/2019/02/26/special-member-functions.html

GPMueller commented 5 years ago

As the Field and Expression classes only store references, until the layer where there is actual data inside the container, there is no need for a move constructor at all, since copying is cheap.