
On 05.04.2012, at 16:25, Dave Abrahams wrote:
on Wed Apr 04 2012, Sebastian Redl <sebastian.redl-AT-getdesigned.at> wrote:
I have used something like this to define a generic Set concept (bool contains(const Set& set, const Value& value)). Since in this concept, every normal value represents its own singleton set, I have used is_callable to separate out functions and function-like objects that return bool.
Hm. Can you describe this concept more fully, e.g. with a requirements table or ConceptGCC syntax?
concept Set<S, V> { bool contains(const S&, const V&); } template <typename V> concept_map Set<std::set<V>, V> { bool contains(const std::set<V>& s, const V& v) { return s.find(v) != s.end(); } } template <typename V> concept_map Set<bool, V> { bool contains(bool b, const V&) { return b; } } // various others, e.g. unordered_set. template <typename V, Callable<bool (V)> Fn> concept_map Set<Fn, V> { bool contains(Fn fn, const V& v) { return fn(v); } } template <EqualityComparable V> if no other concept_map matches concept_map Set<V, V> { bool contains(const V& s, const V& v) { return s == v; } } Specifically, I've used my is_callable to emulate the Callable concept in the enable_if of the contains() overload for functions, and the disable_if in the fallback version. Sebastian