Skip to content

Instantly share code, notes, and snippets.

@haller33
Last active December 26, 2022 11:06
Show Gist options
  • Save haller33/fc926609a47da737d85803143a125030 to your computer and use it in GitHub Desktop.
Save haller33/fc926609a47da737d85803143a125030 to your computer and use it in GitHub Desktop.
a 'Tuple' like struct that can handle a polymorphic type ( but not have imutability ) at least, is a way of store random types of data at once.
package tuples_like
import "core:fmt"
// Values :: union #no_nil {string, int, f32, bool} // for now, compile assertion error problem :: https://github.com/odin-lang/Odin/issues/1918
Poly :: struct {
data : union { string, int, bool, f32 },
}
Tuple :: struct {
ret : [dynamic]Poly,
}
main :: proc () {
{
a : Tuple
append( &(a.ret), Poly { data = 42 } )
append( &(a.ret), Poly { data = 93.93 } )
append( &(a.ret), Poly { data = "Hi 5" } )
append( &(a.ret), Poly { data = true } )
fmt.println ( a )
}
}
@haller33
Copy link
Author

haller33 commented Dec 26, 2022

Odin version

odin version dev-2022-12:521ed286

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment