3 ms·
> I believe (correct me if I'm wrong) that they will make compiler errors for templated code much more straightforward Oh yes, that would really be awesome if
by dgellow 6y ago
> I believe (correct me if I'm wrong) that they will make compiler errors for templated code much more straightforward
Oh yes, that would really be awesome if that's the case. Wikipedia has a section regarding "Compiler diagnostics" when Concepts are used, the precision of the error message demonstrated is SO MUCH better than what you get with templates!
https://en.wikipedia.org/wiki/Concepts_(C%2B%2B)#Compiler_diagnostics https://en.wikipedia.org/wiki/Concepts_(C%2B%2B)#Compiler_di...
Code example:
std::list<int> l = {2, 1, 3};
std::sort(l.begin(), l.end());
Example with templates:
In instantiation of 'void
std::__sort(_RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = std::_List_iterator<int>; _Compare = __gnu_cxx::__ops::_Iter_less_iter]':
error: no match for 'operator-' (operand types are 'std::_List_iterator<int>' and 'std::_List_iterator<int>')
std::__lg(__last - __first) * 2,
...
... // continues for 50+ lines
Example with concepts:
error: cannot call function 'void std::sort(_RAIter, _RAIter) [with _RAIter = std::_List_iterator<int>]'
note: concept 'RandomAccessIterator()' was not satisfied