[Cs3] recognizing that the template type parameter is indeed a container

Mikhail Nesterenko mikhail at cs.kent.edu
Thu Mar 10 14:59:21 EST 2022


CS3 students,

There was a question as to how to recognize the type in a
template. In this example that we studied in class:

  http://www.cs.kent.edu/~mikhail/classes/cs3/Examples/STLAlgorithms/Iterators/advance.cpp

There is a function is_same where you can check for specific
container, but it gets cumbersome quickly

   https://en.cppreference.com/w/cpp/types/is_same

However, there is this elegant solution proposed in stackoverflow that
checks if the template-parameter has begin() and end() and an iterator
defined:

   https://stackoverflow.com/questions/9407367/determine-if-a-type-is-an-stl-container-at-compile-time

Thanks,
-- 
Mikhail


More information about the cs3 mailing list