Is there any trait that specifies numeric functionality?

You can use num or num-traits crates and bound your generic function type with num::Float, num::Integer or whatever relevant trait: use num::Float; // 0.2.1 fn main() { let f1: f32 = 2.0; let f2: f64 = 3.0; let i1: i32 = 3; println!(“{:?}”, sqrt(f1)); println!(“{:?}”, sqrt(f2)); println!(“{:?}”, sqrt(i1)); // error } fn sqrt<T: Float>(input: T) … Read more

How do I build gcc with C++ concepts (“concepts lite”) support?

As of Fri, 7 Aug 2015 01:44:49 -0400 (05:44 +0000) concepts support has been merged into gcc’s trunk. Using a build from after that point, you can enable concepts support with the -std=c++1z flag. As of gcc 6.1 (27-04-2016), concepts are enabled by -fconcepts as they are unlikely to be included in C++17, so they … Read more

Tag dispatch versus static methods on partially specialised classes

I would like tag dispatch because: Easy to extend with new tags Easy to use inheritance (example) It is fairly common technique in generic programming It seems tricky to me to add third variant in second example. When you’ll want to add, for example non-POD-of-PODs type you’ll have to replace bool in template <typename T, … Read more

What is Haskell’s Data.Typeable?

Data.Typeable is an encoding of an well known approach (see e.g. Harper) to implementing delayed (dynamic) type checking in a statically typed language — using a universal type. Such a type wraps code for which type checking would not succeed until a later phase. Rather than reject the program as ill-typed, the compiler passes it … Read more