
2014-08-14 8:00 GMT+02:00 Robert Ramey
Niall Douglas wrote
So tl;dr; I am really saying the time for concepts - whatever they are to whoever's definition - isn't here yet.
I would disagree. The whole STL library is based on "concepts". That is, all template parameter have explicit requirements. This is true now and has always been so.
It's true that compiler support for verification of all the type requirements which someone might come up with falls short of perfection. But as a practical matter, most type requirements are pretty simple and easily supported with current type traits. For example, type requirements for
template<class T> quick_sort(iterator<T> begin, iterator<T> end)
are easily stated AND enforced: BOOST_CONCEPT_REQUIRES((Swappable<T>); BOOST_CONCEPT_REQUIRES((StrictWeakOrdering<T>));
This is useful right now. And few library authors even explicitly state their type requirements - much less include them in code.
This could change in a month - and it will if I have anything to say about it. There is absolutely no advantage to not doing this.
There appears to be a number of things where Robert and Niall would agree: 1. A library with templates in the interface should _document_ the requirements: in html or similar documentation 2. Unless there are reasons to do otherwise, such library should attempt to issue a diagnostic message during compilation that the requirements on types have not been satisfied. This doesn't need to be Boost.ConceptCheck (if no consensus can be reached on using it). Probably a static assert with a type trait should be enough: template<class T> quick_sort(iterator<T> begin, iterator<T> end) { static_assert(is_less_than_comparable<T>::value, "T is not LessThanComparable"); static_assert(is_swappable<T>::value, "T is not Swappable"); // do the work } Not an ideal, but perhaps less controversial. Regards, &rzej