# std::mergeable

> C++ Atlas: `cppatlas.com/w/cpp/iterator/mergeable` | Source: https://en.cppreference.com/w/cpp/iterator/mergeable | Domain: Iterator | Standards: C++20

The mergeable concept specifies the requirements for algorithms that merge two input ranges into a single output range according to the strict weak ordering imposed by Comp.

## Official Specification Summary (cppreference)

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

template< class I1, class I2, class Out, class Comp = ranges::less,
          class Proj1 = std::identity, class Proj2 = std::identity >
concept mergeable =
    std::input_iterator<I1> &&
    std::input_iterator<I2> &&
    std::weakly_incrementable<Out> &&
    std::indirectly_copyable<I1, Out> &&
    std::indirectly_copyable<I2, Out> &&
    std::indirect_strict_weak_order<Comp,
                                    std::projected<I1, Proj1>,
                                    std::projected<I2, Proj2>>; // (since C++20)
```

The `mergeable` concept specifies the requirements for algorithms that merge two input ranges into a single output range according to the strict weak ordering imposed by `Comp`.

### Semantic requirements

`mergeable` is modeled only if all concepts it subsumes are modeled.

### See also

- [`ranges::merge`](https://en.cppreference.com/w/cpp/algorithm/ranges/merge) (C++20): merges two sorted ranges (algorithm function object)
- [`ranges::set_union`](https://en.cppreference.com/w/cpp/algorithm/ranges/set_union) (C++20): computes the union of two sets (algorithm function object)
- [`ranges::set_intersection`](https://en.cppreference.com/w/cpp/algorithm/ranges/set_intersection) (C++20): computes the intersection of two sets (algorithm function object)
- [`ranges::set_difference`](https://en.cppreference.com/w/cpp/algorithm/ranges/set_difference) (C++20): computes the difference between two sets (algorithm function object)
- [`ranges::set_symmetric_difference`](https://en.cppreference.com/w/cpp/algorithm/ranges/set_symmetric_difference) (C++20): computes the symmetric difference between two sets (algorithm function object)

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