Created
August 18, 2014 17:38
-
-
Save SiegeLord/bfee058170eb846b1e83 to your computer and use it in GitHub Desktop.
Operator overloads
This file contains hidden or 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
#![feature(globs, phase, macro_rules)] | |
extern crate algebloat; | |
#[phase(plugin)] | |
extern crate algebloat_macros; | |
use algebloat::*; | |
fn add< | |
T: MatrixRawGet + SameShape + MatrixShape + Clone + | |
Add<T, MatrixBinOp<T, T, OpAdd>> + | |
Add<U, MatrixBinOp<T, U, OpAdd>> | |
, | |
U: MatrixRawGet + SameShape + MatrixShape + Clone + | |
Add<U, MatrixBinOp<U, U, OpAdd>> + | |
Add<T, MatrixBinOp<U, T, OpAdd>> | |
>(a: T, b: U) | |
{ | |
let e = a + a; | |
let e = b + b; | |
let e = a + b; | |
} | |
fn mat_mul< | |
T: MatrixRawGet + SameShape + MatrixShape + Clone, | |
U: MatrixRawGet + SameShape + MatrixShape + Clone | |
>(a: T, b: U) | |
{ | |
macro_rules! c{ ($e: expr) => { $e.clone() } } | |
let e = c!(a).mat_mul_lazy(c!(a)); | |
let e = c!(b).mat_mul_lazy(c!(b)); | |
let e = c!(a).mat_mul_lazy(c!(b)); | |
let e = c!(b).mat_mul_lazy(c!(a)); | |
} | |
fn main() | |
{ | |
let a = &mat![1u, 2u; 3u, 4u]; | |
let b = a + a; | |
add(a, b); | |
mat_mul(a, b); | |
println!("{}", b); | |
} |
This file contains hidden or 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
test.rs:21:14: 21:15 error: mismatched types: expected `T` but found `U` (expected type parameter but found type parameter) | |
test.rs:21 let e = a + b; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment