Last active
December 26, 2022 11:06
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 ) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Odin version