Hi.

Maybe you can use encapsulation instead of standalone function and generics.
Encapsulation is a fundamental principle in software engineering. It 
controls which parts of a package are visible from the outside and which 
are not.
It hides implementation details, allowing changes that do not affect 
dependent code.
Check it out: https://go.dev/play/p/xqwMPgB0IND

I really hope I can help you.

Cheers.
Cleberson


Em terça-feira, 15 de outubro de 2024 às 21:01:42 UTC-3, Robert Engels 
escreveu:

> Hi,
>
> Is there someway of doing this with Go generics? 
> https://github.com/robaho/cpp_fixed/blob/6770b217acd84e4b723449e4c4bb42c92e7f2af1/fixed.h#L18-L23
>
> I could make the type and interface and add a method for ‘decimal places’, 
> but I would like all of the constants to be resolved at compile time.
>
> Also, if I make it an interface, it is far less efficient than passing a 
> single int64 with generics and letting the compiler figure it out.
>
> I know constexpr is not available, but I would think that if I could do it 
> with methods the compiler would eventually inline the function calls anyway 
> - possibly as constants.
>
> I read through the docs, and it doesn’t seem possible.
>
> I got it kind of working here https://go.dev/play/p/5ztum5NAkUp but I 
> would really like it to be method based rather than standalone function 
> based, and the method based I would seemingly need to duplicate a lot of 
> code for every possible number of decimal places.
>
> What am I missing? Ideas?
>
> Thanks for the help.
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/fb1a8dd2-e1d6-499d-aabb-683afc8720a1n%40googlegroups.com.

Reply via email to