It's been discussed, but there is still discussion on the best way to
achieve this.
At the moment, you should be able to get around it using Peano numbers [1]:
struct Zero;
struct Succ<T>;
struct Matrix<T, M, N> {
data: Vec<T>,
}
fn cofactor<T, M, N>(
m: Matrix<T, Succ<M>, Succ<N>>,
row: int,
col: int
) -> Matrix<T, M, N>
{
Matrix::<T, M, N>{ data: vec!() }
}
Of course, I would dread seeing the error message should you need more than
a couple rows/columns...
[1] http://www.haskell.org/haskellwiki/Peano_numbers
On Sun, May 25, 2014 at 7:25 PM, Isak Andersson <[email protected]>wrote:
> Hello!
>
> I was asking in IRC if something like this:
>
> fn cofactor(m: Matrix<T, R, C>, row, col: int) -> Matrix<T, R-1, C-1> {...}
>
> was possible. I quickly got the response that generics doesn't work with
> integers. So my question is, is there anyway to achieve something similar?
>
> Or would it be possible in the future to do generic instantiation based on
> more
> than just types.
>
> Thanks!
>
> _______________________________________________
> Rust-dev mailing list
> [email protected]
> https://mail.mozilla.org/listinfo/rust-dev
>
>
_______________________________________________
Rust-dev mailing list
[email protected]
https://mail.mozilla.org/listinfo/rust-dev