Concepts lite, and tight error mesages
bearophile
bearophileHUGS at lycos.com
Tue Feb 26 10:32:09 PST 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
More information about the Digitalmars-d
mailing list