decimal_for_cpp
decimal_for_cpp copied to clipboard
Make it fully trivial
I would like the option of making the class fully trivial. This would be a breaking change, as an uninitialized object would have a random value (just like int).
The advantage of this is that it can easily be used by templates that require trivial objects.
I suggest using a new #define, but this will add to the complexity of the class.
#ifdef DEC_TRIVIAL
decimal() = default;
#else
decimal() noexcept : m_value(0) {}
#endif
Hi, what is the benefit for end user? Could you provide any examples how it improves the library?
Hi,
I don't really have a good example.
I got some problem when I tried to use decimal in a union, because of the non-trivial default constructor.
It is possible that some templates would expect trivial constructor, but I don't have an example of a template that would need this.
I do understand if you don't want to add this to the library, but I thought I would suggest it so you are aware of it.
Frode
On Mon, Nov 30, 2020 at 3:44 PM Piotr [email protected] wrote:
Hi, what is the benefit for end user? Could you provide any examples how it improves the library?
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/vpiotr/decimal_for_cpp/issues/38#issuecomment-736074462, or unsubscribe https://github.com/notifications/unsubscribe-auth/ADFLPWQUVZ54FBDC3IP2VK3SSQG3DANCNFSM4UCZVWGA .
-- Frode Frafjord
Uninitialized objects introduce some end-user risk which I would like to avoid. Anyway, if you want to work with internal decimal value, you can use "setUnbiased / getUnbiased" methods (if applicable).