How to overload methods of generic structs to target particular types
Consider the snippet below:
I would like to add a get_decimal method which dispatches differently based on the type of T. For example if T is Int it should return False and True if T is a Float64
I have tried something like below and get a Compiler Error:
The Error:
Thanks in advance for the help
4 Replies
The only way I found currently is to pass an additional parameter and do a bitcast. See https://github.com/modularml/mojo/pull/3349 which does this
GitHub
[stdlib] Use memcpy in
List._realloc
for x13.2 speedups in some b...Currently, when re-allocating a list, elements are moved one by one. While it is correct, when one knows that T is a trivial type, we an use memcpy thus giving massive speedups in some benchmarks.
...
erm that seems like a too specific solution? Like what if I want to do it on other complex types I defined. Also, is this supposed to change because I think all of this can still be handled at the compile time itself?
that's the only solution I could find while we wait for a proper solution in the language
Thanks for sharing!