What type of containers does std::sort() work with?

QuestionsQuestions8 SkillsProUse STL Components in C++Nov, 02 2025
070

std::sort() works with random-access iterators, which means it can be used with containers that provide random access to their elements. The most common containers that std::sort() works with include:

  1. std::vector: A dynamic array that allows random access.
  2. std::deque: A double-ended queue that also supports random access.
  3. Arrays: Both built-in arrays and std::array.

It does not work with containers like std::list or std::forward_list, as they do not provide random access iterators.

0 Comments

no data
Be the first to share your comment!