Skip to content

Instantly share code, notes, and snippets.

@SiegeLord
Created August 18, 2014 17:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SiegeLord/bfee058170eb846b1e83 to your computer and use it in GitHub Desktop.
Save SiegeLord/bfee058170eb846b1e83 to your computer and use it in GitHub Desktop.
Operator overloads
#![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);
}
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