digitalmars.D.announce - concepts v0.0.6: use a run-time interface to specify a compile-time
- Atila Neves (35/35) May 10 2017 http://code.dlang.org/packages/concepts
- =?UTF-8?B?THXDrXM=?= Marques (2/5) May 10 2017 Awesome!
- Juanjo Alvarez (3/12) May 11 2017 Niiiiice, I love constraints but there error messages aren't the
http://code.dlang.org/packages/concepts concepts is a dub package and library that allows one to declare that a struct conforms to a "compile-time interface" such as `isInputRange`. The difference between this and a simple `static assert(isInputRange!MyType)` is that when the static assert fails you have no idea why not and half of the time it's because of a typo (e.g. `popFrnt`). With concepts you get an error message from the compiler, and you can still use your concepts in template constraints. It also has its own version of `isInputRange` et al that are drop-in replacements for the ones in Phobos, but you get compiler error messages instead of nothing. The new addition is ` implements`: interface IFoo { int foo(int i, string s) safe; double lefoo(string s) safe; } implements!(Foo, IFoo) struct Foo { int foo(int i, string s) safe { return 0; } double lefoo(string s) safe { return 0; } } // doesn't compile: Foo doesn't "implement" IFoo /* implements!(Oops, IFoo) struct Oops {} */ // also doesn't compile because foo is system: /* implements!(Nearly, IFoo) struct Nearly { int foo(int i, string s) system { return 0; } double lefoo(string s) safe { return 0; } } */
May 10 2017
On Wednesday, 10 May 2017 at 10:53:59 UTC, Atila Neves wrote:concepts is a dub package and library that allows one to declare that a struct conforms to a "compile-time interface" such as `isInputRange`.Awesome!
May 10 2017
On Wednesday, 10 May 2017 at 10:53:59 UTC, Atila Neves wrote:http://code.dlang.org/packages/concepts concepts is a dub package and library that allows one to declare that a struct conforms to a "compile-time interface" such as `isInputRange`. The difference between this and a simple `static assert(isInputRange!MyType)` is that when the static assert fails you have no idea why not and half of the time it's because of a typo (e.g. `popFrnt`). With concepts you get an error message from the compiler, and you can still use your concepts in template constraints.Niiiiice, I love constraints but there error messages aren't the best.
May 11 2017