#include template Iterator LinearSearch(const T&value, Iterator first, Iterator last) { for (Iterator x = first; x != last; x++) { if (value == *x) { return x; } } return last; } template auto FindImplemented(T value, It begin_it, It end_it, std::random_access_iterator_tag) { auto it = std::lower_bound(begin_it, end_it, value); if (*it == value) return it; else return end_it; } template auto FindImplemented(T value, It begin_it, It end_it, IteratorTag) { return LinearSearch(value, begin_it, end_it); } template auto Find(T value, It begin_it, It end_it) { typedef typename std::iterator_traits::iterator_category category; return FindImplemented(value, begin_it, end_it, category()); }