Thread overview
Concepts lite, and tight error mesages
Feb 26, 2013
bearophile
Mar 01, 2013
bearophile
Mar 01, 2013
Andrea Fontana
February 26, 2013
The proposed (and already implemented) "Concepts lite" seem equal to D template constraint (but constexpr is worse than D CTFE):

http://isocpp.org/blog/2013/02/concepts-lite-constraining-templates-with-predicates-andrew-sutton-bjarne-s


In that page they show an example of error message:

template<Sortable Cont>
void sort(Cont& container);

and when you call it like this:

list<int> lst = ...;   // oops, bidirectional iterators
sort(lst);             // today, results in very long "template spew" error message

getting this short and non-cryptic error message:

error: no matching function for call to ‘sort(list<int>&)’
   sort(l);
         ^
note: candidate is:
note: template<Sortable T> void sort(T)
   void sort(T t) { }
        ^
note: template constraints not satisfied because
note:   'T' is not a/an 'Sortable' type [with T = list<int>] since
note:     'declval<T>()[n]' is not valid syntax


Currently D gives a worse error message, but when a D template constraint fails maybe it's possible to show a better error message that pinpoints what part of the condition has failed.

Bye,
bearophile
March 01, 2013
I have added one improvement request:

http://d.puremagic.com/issues/show_bug.cgi?id=9626

Bye,
bearophile
March 01, 2013
On Friday, 1 March 2013 at 20:37:21 UTC, bearophile wrote:
> I have added one improvement request:
>
> http://d.puremagic.com/issues/show_bug.cgi?id=9626
>
> Bye,
> bearophile

+1