Does class model a concept? (concept-to-trait, or vice versa)

103 views Asked by At

Apparently I'm missing something obvious, most likely with SFINAE - but for the life of me I just can't find what "it" is. I could blame my wisdom tooth, but it would sound weird because it's about wisdom...

In C++ when using Concepts (Boost, Lite or whatever) one uses something like REQUIRES(list_of_concepts) to enforce that eg.: a type in a function invocation follows a concept like "BidirectionalIteratorAccess". But what is the corresponding "query" component for this feature? Essentially, how do I ask if a class type T models BidirectionalIteratorAccess?

All I know is that I'm not looking for REQUIRES or BOOST_CONCEPT_ASSERT as they are true-or-compilation-error; I'm looking for something that is true-or-false, like the type_traits. The documentation of Boost.Concept Assert and others suggest that one would use a SFINAE check with something like not_satisfied<Concept> but if so I for some reason can't figure out which part goes where. I can only guess that a SFINAE test would end up like this:

template <typename T> struct models_MyConcept {
    template <typename C>
    static yes_t test (some_sort_of_argument_using_MyConcept);
    template <typename C>
    static no_t test (...);
    static const bool value = sizeof(something_calling_test_with_a_C_argument_somehow) == sizeof(yes_t);
};

…What kind of idiot named them wisdom teeth anyway? And why was I digressing?

1

There are 1 answers

0
Casey On

In Concepts Lite a constraint is a constexpr bool template function that returns true if and only if the template parameter(s) model the concept. So BidirectionalIteratorAccess<T>() would evaluate to true if and only T models BidirectionalIteratorAccess.

I understand this answer is likely not useful to you, but you did say "Boost, Lite, or whatever."