[container.adaptors.general]

# 23 Containers library [[containers]](./#containers)

## 23.6 Container adaptors [[container.adaptors]](container.adaptors#general)

### 23.6.1 General [container.adaptors.general]

[1](#1)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L15483)

The headers[<queue>](queue.syn#header:%3cqueue%3e "23.6.2 Header <queue> synopsis [queue.syn]"),[<stack>](stack.syn#header:%3cstack%3e "23.6.5 Header <stack> synopsis [stack.syn]"),[<flat_map>](flat.map.syn#header:%3cflat_map%3e "23.6.7 Header <flat_­map> synopsis [flat.map.syn]"),
and [<flat_set>](flat.set.syn#header:%3cflat_set%3e "23.6.10 Header <flat_­set> synopsis [flat.set.syn]") define the container adaptorsqueue and priority_queue,stack,flat_map and flat_multimap,
and flat_set and flat_multiset,
respectively[.](#1.sentence-1)

[2](#2)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L15496)

Each container adaptor takes
one or more template parameters
named Container, KeyContainer, or MappedContainer that denote the types of containers that the container adaptor adapts[.](#2.sentence-1)

Each container adaptor has at least one constructor
that takes a reference argument to one or more such template parameters[.](#2.sentence-2)

For each constructor reference argument to a container C,
the constructor copies the container into the container adaptor[.](#2.sentence-3)

If C takes an allocator, then a compatible allocator may be passed in
to the adaptor's constructor[.](#2.sentence-4)

Otherwise, normal copy or move construction is used for the container
argument[.](#2.sentence-5)

For the container adaptors
that take a single container template parameter Container,
the first template parameter T of the container adaptor
shall denote the same type as Container​::​value_type[.](#2.sentence-6)

[3](#3)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L15513)

For container adaptors, no swap function throws an exception unless that
exception is thrown by the swap of the adaptor'sContainer,KeyContainer,MappedContainer, orCompare object (if any)[.](#3.sentence-1)

[4](#4)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L15521)

A constructor template of a container adaptor
shall not participate in overload resolution
if it has an InputIterator template parameter and
a type that does not qualify as an input iterator is deduced for that parameter[.](#4.sentence-1)

[5](#5)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L15527)

For container adaptors that have them,
the insert, emplace, and erase members
affect the validity of iterators, references, and pointers
to the adaptor's container(s) in the same way that
the containers' respectiveinsert, emplace, and erase members do[.](#5.sentence-1)

[*Example [1](#example-1)*:

A call to flat_map<Key, T>​::​insert can invalidate all iterators to the flat_map[.](#5.sentence-2)

â *end example*]

[6](#6)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L15539)

A deduction guide for a container adaptor shall not participate in overload resolution if any of the following are true:

- [(6.1)](#6.1)

  It has an InputIterator template parameter and a type that does not qualify as an input iterator is deduced for that parameter[.](#6.1.sentence-1)

- [(6.2)](#6.2)

  It has a Compare template parameter and a type that qualifies as an allocator is deduced for that parameter[.](#6.2.sentence-1)

- [(6.3)](#6.3)

  It has a Container, KeyContainer, or MappedContainer template parameter and a type that qualifies as an allocator is deduced for that parameter[.](#6.3.sentence-1)

- [(6.4)](#6.4)

  It has no Container, KeyContainer, or MappedContainer template parameter, and it has an Allocator template parameter, and a type that does not qualify as an allocator is deduced for that parameter[.](#6.4.sentence-1)

- [(6.5)](#6.5)

  It has both Container and Allocator template parameters, and uses_allocator_v<Container, Allocator> is false[.](#6.5.sentence-1)

- [(6.6)](#6.6)

  It has both KeyContainer and Allocator template parameters, anduses_allocator_v<KeyContainer, Allocator> is false[.](#6.6.sentence-1)

- [(6.7)](#6.7)

  It has both KeyContainer and Compare template parameters, andis_invocable_v<const Compare&, const typename KeyContainer::value_type&, const typename KeyContainer::value_type&> is not a valid expression or is false[.](#6.7.sentence-1)

- [(6.8)](#6.8)

  It has both MappedContainer and Allocator template parameters, anduses_allocator_v<MappedContainer, Allocator> is false[.](#6.8.sentence-1)

[7](#7)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L15560)

The exposition-only alias template *iter-value-type* defined in [[sequences.general]](sequences.general "23.3.1 General") and
the exposition-only alias templates *iter-key-type*, *iter-mapped-type*,*range-key-type*, and *range-mapped-type* defined in [[associative.general]](associative.general "23.4.1 General") may appear in deduction guides for container adaptors[.](#7.sentence-1)

[8](#8)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/containers.tex#L15568)

The following exposition-only alias template
may appear in deduction guides for container adaptors:template<class Allocator, class T>using *alloc-rebind* = // *exposition only*typename allocator_traits<Allocator>::template rebind_alloc<T>;
