Reputation: 3101
How can I test if a member type exists in a concept template argument, i.e. for typename Container
, test for Container::reverse_iterator
? What's the proper requires-clause ?
Upvotes: 8
Views: 1588
Reputation: 2137
If you just want the type to exist, follow answer of @StoryTeller above.
If you want the type to exist and fulfill a specific concept, then do the:
template<class Container>
concept has_reverse_iterator
= std::random_access_iterator<typename Container::reverse_iterator>;
Upvotes: 1
Reputation: 170064
We do this with the aptly named type requirement:
template<class Container>
concept has_reverse_iterator = requires {
typename Container::reverse_iterator;
};
Upvotes: 14