From 1429cbf34e02ff55f1419a44c1dd1d901454dea3 Mon Sep 17 00:00:00 2001 From: Ben Foppa Date: Tue, 6 Jan 2015 18:46:50 -0500 Subject: [PATCH] Remove obsolete closure syntax --- src/lib.rs | 7 ++++--- src/structs/dmat.rs | 2 +- src/structs/dvec.rs | 2 +- src/structs/dvec_macros.rs | 4 ++-- src/structs/spec/vec.rs | 20 ++++++++++---------- src/structs/spec/vec0.rs | 4 ++-- src/structs/vec_macros.rs | 4 ++-- src/traits/geometry.rs | 2 +- src/traits/structure.rs | 4 ++-- 9 files changed, 25 insertions(+), 24 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 544586b0..e24ca3a5 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -87,6 +87,7 @@ Feel free to add your project to this list if you happen to use **nalgebra**! #![feature(default_type_params)] #![feature(associated_types)] #![feature(old_orphan_check)] +#![feature(unboxed_closures)] #![doc(html_root_url = "http://nalgebra.org/doc")] extern crate "rustc-serialize" as rustc_serialize; @@ -749,7 +750,7 @@ pub fn from_homogeneous>(m: &M) -> Res { /// /// The number of sampling point is implementation-specific. It is always uniform. #[inline(always)] -pub fn sample_sphere(f: |V| -> ()) { +pub fn sample_sphere(f: F) { UniformSphereSample::sample(f) } @@ -865,13 +866,13 @@ pub fn new_identity(dim: uint) -> M { /// Computes the canonical basis for a given dimension. #[inline(always)] -pub fn canonical_basis(f: |V| -> bool) { +pub fn canonical_basis bool>(f: F) { Basis::canonical_basis(f) } /// Computes the basis of the orthonormal subspace of a given vector. #[inline(always)] -pub fn orthonormal_subspace_basis(v: &V, f: |V| -> bool) { +pub fn orthonormal_subspace_basis bool>(v: &V, f: F) { Basis::orthonormal_subspace_basis(v, f) } diff --git a/src/structs/dmat.rs b/src/structs/dmat.rs index 6649a526..496c88e1 100644 --- a/src/structs/dmat.rs +++ b/src/structs/dmat.rs @@ -127,7 +127,7 @@ impl DMat { impl DMat { /// Builds a matrix filled with a given constant. #[inline(always)] - pub fn from_fn(nrows: uint, ncols: uint, f: |uint, uint| -> N) -> DMat { + pub fn from_fn N>(nrows: uint, ncols: uint, f: F) -> DMat { DMat { nrows: nrows, ncols: ncols, diff --git a/src/structs/dvec.rs b/src/structs/dvec.rs index 1c54c026..f973af94 100644 --- a/src/structs/dvec.rs +++ b/src/structs/dvec.rs @@ -55,7 +55,7 @@ impl DVec { impl DVec { /// Builds a vector filled with the result of a function. #[inline(always)] - pub fn from_fn(dim: uint, f: |uint| -> N) -> DVec { + pub fn from_fn N>(dim: uint, f: F) -> DVec { DVec { at: range(0, dim).map(|i| f(i)).collect() } } diff --git a/src/structs/dvec_macros.rs b/src/structs/dvec_macros.rs index 6fd01ec0..5cdef332 100644 --- a/src/structs/dvec_macros.rs +++ b/src/structs/dvec_macros.rs @@ -108,7 +108,7 @@ macro_rules! dvec_impl( /// Builds a vector filled with random values. #[inline] pub fn new_random(dim: uint) -> $dvec { - $dvec::from_fn(dim, |_| rand::random()) + $dvec::from_fn(dim, |&: _| rand::random()) } } @@ -481,7 +481,7 @@ macro_rules! small_dvec_from_impl ( impl $dvec { /// Builds a vector filled with the result of a function. #[inline(always)] - pub fn from_fn(dim: uint, f: |uint| -> N) -> $dvec { + pub fn from_fn N>(dim: uint, f: F) -> $dvec { assert!(dim <= $dim); let mut at: [N; $dim] = [ $( $zeros, )* ]; diff --git a/src/structs/spec/vec.rs b/src/structs/spec/vec.rs index 41c775aa..2d07afab 100644 --- a/src/structs/spec/vec.rs +++ b/src/structs/spec/vec.rs @@ -74,12 +74,12 @@ impl Row> for Vec2 { impl Basis for Vec1 { #[inline(always)] - fn canonical_basis(f: |Vec1| -> bool) { + fn canonical_basis) -> bool>(f: F) { f(Vec1::new(::one())); } #[inline(always)] - fn orthonormal_subspace_basis(_: &Vec1, _: |Vec1| -> bool) { } + fn orthonormal_subspace_basis) -> bool>(_: &Vec1, _: F) { } #[inline] fn canonical_basis_element(i: uint) -> Option> { @@ -94,13 +94,13 @@ impl Basis for Vec1 { impl> Basis for Vec2 { #[inline(always)] - fn canonical_basis(f: |Vec2| -> bool) { + fn canonical_basis) -> bool>(f: F) { if !f(Vec2::new(::one(), ::zero())) { return }; f(Vec2::new(::zero(), ::one())); } #[inline] - fn orthonormal_subspace_basis(n: &Vec2, f: |Vec2| -> bool) { + fn orthonormal_subspace_basis) -> bool>(n: &Vec2, f: F) { f(Vec2::new(-n.y, n.x)); } @@ -120,14 +120,14 @@ impl> Basis for Vec2 { impl Basis for Vec3 { #[inline(always)] - fn canonical_basis(f: |Vec3| -> bool) { + fn canonical_basis) -> bool>(f: F) { if !f(Vec3::new(::one(), ::zero(), ::zero())) { return }; if !f(Vec3::new(::zero(), ::one(), ::zero())) { return }; f(Vec3::new(::zero(), ::zero(), ::one())); } #[inline(always)] - fn orthonormal_subspace_basis(n: &Vec3, f: |Vec3| -> bool) { + fn orthonormal_subspace_basis) -> bool>(n: &Vec3, f: F) { let a = if n.x.abs() > n.y.abs() { Norm::normalize_cpy(&Vec3::new(n.z, ::zero(), -n.x)) @@ -230,14 +230,14 @@ static SAMPLES_3_F64: [Vec3; 42] = [ impl UniformSphereSample for Vec1 { #[inline(always)] - fn sample(f: |Vec1| -> ()) { + fn sample)>(f: F) { f(::one()) } } impl + Copy> UniformSphereSample for Vec2 { #[inline(always)] - fn sample(f: |Vec2| -> ()) { + fn sample)>(f: F) { for sample in SAMPLES_2_F64.iter() { f(Cast::from(*sample)) } @@ -246,7 +246,7 @@ impl + Copy> UniformSphereSample for Vec2 { impl + Copy> UniformSphereSample for Vec3 { #[inline(always)] - fn sample(f: |Vec3| -> ()) { + fn sample)>(f: F) { for sample in SAMPLES_3_F64.iter() { f(Cast::from(*sample)) } @@ -255,7 +255,7 @@ impl + Copy> UniformSphereSample for Vec3 { impl + Copy> UniformSphereSample for Vec4 { #[inline(always)] - fn sample(_: |Vec4| -> ()) { + fn sample)>(_: F) { panic!("UniformSphereSample::>::sample : Not yet implemented.") // for sample in SAMPLES_3_F32.iter() { // f(Cast::from(*sample)) diff --git a/src/structs/spec/vec0.rs b/src/structs/spec/vec0.rs index dc291af0..db3a0c3f 100644 --- a/src/structs/spec/vec0.rs +++ b/src/structs/spec/vec0.rs @@ -92,10 +92,10 @@ impl Dim for vec::Vec0 { impl Basis for vec::Vec0 { #[inline(always)] - fn canonical_basis(_: |vec::Vec0| -> bool) { } + fn canonical_basis) -> bool>(_: F) { } #[inline(always)] - fn orthonormal_subspace_basis(_: &vec::Vec0, _: |vec::Vec0| -> bool) { } + fn orthonormal_subspace_basis) -> bool>(_: &vec::Vec0, _: F) { } #[inline(always)] fn canonical_basis_element(_: uint) -> Option> { diff --git a/src/structs/vec_macros.rs b/src/structs/vec_macros.rs index 9801ef95..aa2573f6 100644 --- a/src/structs/vec_macros.rs +++ b/src/structs/vec_macros.rs @@ -321,14 +321,14 @@ macro_rules! basis_impl( ($t: ident, $dim: expr) => ( impl> Basis for $t { #[inline] - fn canonical_basis(f: |$t| -> bool) { + fn canonical_basis) -> bool>(f: F) { for i in range(0u, $dim) { if !f(Basis::canonical_basis_element(i).unwrap()) { return } } } #[inline] - fn orthonormal_subspace_basis(n: &$t, f: |$t| -> bool) { + fn orthonormal_subspace_basis) -> bool>(n: &$t, f: F) { // compute the basis of the orthogonal subspace using Gram-Schmidt // orthogonalization algorithm let mut basis: Vec<$t> = Vec::new(); diff --git a/src/traits/geometry.rs b/src/traits/geometry.rs index 359718f7..eda796dc 100644 --- a/src/traits/geometry.rs +++ b/src/traits/geometry.rs @@ -266,7 +266,7 @@ pub trait FromHomogeneous { /// function. pub trait UniformSphereSample { /// Iterate through the samples. - fn sample(|Self| -> ()); + fn sample(F); } /// The zero element of a vector space, seen as an element of its embeding affine space. diff --git a/src/traits/structure.rs b/src/traits/structure.rs index ccb52816..5ffa712d 100644 --- a/src/traits/structure.rs +++ b/src/traits/structure.rs @@ -109,10 +109,10 @@ pub trait Bounded { /// Traits of objects which can form a basis (typically vectors). pub trait Basis { /// Iterates through the canonical basis of the space in which this object lives. - fn canonical_basis(|Self| -> bool); + fn canonical_basis bool>(F); /// Iterates through a basis of the subspace orthogonal to `self`. - fn orthonormal_subspace_basis(&Self, |Self| -> bool); + fn orthonormal_subspace_basis bool>(&Self, F); /// Gets the ith element of the canonical basis. fn canonical_basis_element(i: uint) -> Option;