Last active
April 22, 2022 19:14
-
-
Save polymonster/68674ddcab96f8855a009fd9e48d8bb7 to your computer and use it in GitHub Desktop.
Vec<T, const N: usize>
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
pub struct Vec<T, const N: usize> { | |
v: [T; N] | |
} | |
impl<T, const N: usize> Vec<T, N> where T: std::ops::AddAssign + std::fmt::Display { | |
fn print(&self) { | |
for i in 0..N { | |
print!("{}, ", self.v[i]); | |
} | |
print!("\n"); | |
} | |
} | |
fn main() { | |
let v2 = Vec::<f32, 2> { | |
v: [6.0, 9.0] | |
}; | |
v2.print(); | |
let v3 = Vec::<f32, 3> { | |
v: [6.0, 9.0, 8.0] | |
}; | |
v3.print(); | |
let v4 = Vec::<f32, 4> { | |
v: [6.0, 9.0, 8.0, 4.0] | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment