Eric Pearson

  Home  |   Contact  |   Syndication    |   Login
  11 Posts | 0 Stories | 6 Comments | 30 Trackbacks

News

Article Categories

Archives

Post Categories

I thought of a really cool use for generic-like syntax for parameterizing variable declaration beyond types.  It would be awesome if generics could be used to specify dimensions within a struct.

My case, I wanted to implement a Vector struct with a parametric dimension.  So if I was using a vector in R2, I could create the struct as Vector<2>.  If in R3, new Vector<3>, and so on.  If I was able to do that, my struct could have a stack-allocated array of floats.  Without this, my array is forced to live on the heap, and my struct doesn't really act like a struct.  true, I can just make it an object and do everything on the heap, but that departs from the behavior I wanted.

Oh well.... a guy can wish, right?

  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati
posted on Saturday, March 10, 2007 9:45 PM

Feedback

# re: A wish, generic syntax for parameterized structs. 3/10/2007 10:47 PM Mohamed Ahmed Meligy
generics are for parameterizing "types". This is different from constructor overloads. So, your example wouldn't just fit!

# re: A wish, generic syntax for parameterized structs. 3/10/2007 10:58 PM Eric
"generics are for parameterizing "types". This is different from constructor overloads. So, your example wouldn't just fit! "

right... which is why i'm talking about a generic-like syntax, not generics as they are. What I was talking about was being able to modify the variable allocation by the way it's declared (like generics do). So declaring "Vector<2> v2;" would put a different size structure on the stack than "Vector<3> v3;" would.

Post A Comment
Title:
Name:
Email:
Website:
Comment:
Verification: