|
Boost : |
Subject: Re: [boost] [Concepts] Definition. Was [GSoC] [Boost.Hana] Formal review request
From: pfultz2 (pfultz2_at_[hidden])
Date: 2014-08-14 11:47:23
> 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.
If traits are going to be used, then `enable_if` should really be used
instead. This allows for better reusability. Say for instance I want a trait
that checks if the type is quick sortable:
template<class T>
struct holder { typedef void type; }
template<class T, class Enable=void>
struct is_quick_sortable
: std::false_type {};
template<class T>
struct is_quick_sortable<T, typename holder<
decltype(quick_sort(std::declval<T>(), std::declval<T>()))
>::type>
: std::true_type {};
It is better to check this way instead of checking for
`is_less_than_comparable`, and `is_swappable`, since those requirements
could
possibly change. However, if the requirements are checked with a
`static_assert` then it is impossible to check for `is_quick_sortable` this
way.
-- View this message in context: http://boost.2283326.n4.nabble.com/Concepts-Definition-Was-GSoC-Boost-Hana-Formal-review-request-tp4666011p4666362.html Sent from the Boost - Dev mailing list archive at Nabble.com.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk