How do I require and check that an argument is a certain concept in C++?
For example, the random_shuffle function in the algorithm header requires that its arguments are RandomAccessIterators:
template<typename _RandomAccessIterator>
inline void
random_shuffle(_RandomAccessIterator __first, _RandomAccessIterator __last)
{
// concept requirements
__glibcxx_function_requires(_Mutable_RandomAccessIteratorConcept<
_RandomAccessIterator>)
__glibcxx_requires_valid_range(__first, __last);
if (__first != __last)
for (_RandomAccessIterator __i = __first + 1; __i != __last; ++__i)
std::iter_swap(__i, __first + (std::rand() % ((__i - __first) + 1)));
}
I guess I can’t use these __glibcxx_function_requires etc. in my own code? How do they work? Do you check things like that in your code?
Boost has a library for this. It’s probably easier and more well documented than figuring out how to use the version your STL implementer has hacked together.
http://www.boost.org/doc/libs/1_40_0/libs/concept_check/concept_check.htm