decimal_for_cpp icon indicating copy to clipboard operation
decimal_for_cpp copied to clipboard

Make it fully trivial

Open Frafjord opened this issue 4 years ago • 3 comments

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

Frafjord avatar Nov 25 '20 19:11 Frafjord

Hi, what is the benefit for end user? Could you provide any examples how it improves the library?

vpiotr avatar Nov 30 '20 21:11 vpiotr

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

Frafjord avatar Nov 30 '20 22:11 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).

vpiotr avatar Nov 30 '20 23:11 vpiotr