C++ Logo

sg19

Advanced search

Requiring operator[] for random-access and bidirectional containers?

From: Phil Ratzloff <Phil.Ratzloff_at_[hidden]>
Date: Sun, 30 Oct 2022 16:57:28 +0000
operator[] makes coding much simpler and clearer when accessing elements in random_acess_ranges like vector and deque. It is also useful for the bidirectional_ranges like map and unordered_map. We could like to use operator[] in the graph algorithms and doing so would support writing more generic code, but the concepts for those ranges don't require operator[].

Is there a reason operator[] isn't a requirement for random_access_range? For bidirectional_range?

We would create a concept that would require operator[]. What caveats are there in doing that?


Received on 2022-10-30 16:57:36