# std::ranges::random_access_range

> C++ Atlas: `cppatlas.com/w/cpp/ranges/random_access_range` | Source: https://en.cppreference.com/w/cpp/ranges/random_access_range | Domain: Ranges | Standards: C++20

The random_access_range concept is a refinement of range for which ranges::begin returns a model of random_access_iterator.

## Official Specification Summary (cppreference)

```cpp
// Defined in header <ranges>

template< class T >
concept random_access_range =
    ranges::bidirectional_range<T> && std::random_access_iterator<ranges::iterator_t<T>>; // (since C++20)
```

The `random_access_range` concept is a refinement of `range` for which `ranges::begin` returns a model of `random_access_iterator`.

### Example

```cpp
#include <array>
#include <deque>
#include <list>
#include <ranges>
#include <set>
#include <valarray>
#include <vector>

template<typename T> concept RAR = std::ranges::random_access_range<T>;

int main()
{
    int a[4];
    static_assert(
            RAR<std::vector<int>> and
            RAR<std::vector<bool>> and
            RAR<std::deque<int>> and
            RAR<std::valarray<int>> and
            RAR<decltype(a)> and
        not RAR<std::list<int>> and
        not RAR<std::set<int>> and
            RAR<std::array<std::list<int>,42>>
    );
}
```

### See also

- [`ranges::sized_range`](https://en.cppreference.com/w/cpp/ranges/sized_range) (C++20): specifies that a range knows its size in constant time (concept)
- [`ranges::contiguous_range`](https://en.cppreference.com/w/cpp/ranges/contiguous_range) (C++20): specifies a range whose iterator type satisfies `contiguous_iterator` (concept)

---
Attribution: content from https://en.cppreference.com/w/cpp/ranges/random_access_range (cppreference.com), licensed under CC-BY-SA 3.0 and GFDL. Modified: converted to markdown, study notes added. Offline snapshot of 9 February 2025.