[string.swap] # 27 Strings library [[strings]](./#strings) ## 27.4 String classes [[string.classes]](string.classes#string.swap) ### 27.4.3 Class template basic_string [[basic.string]](basic.string#string.swap) #### 27.4.3.7 Modifiers [[string.modifiers]](string.modifiers#string.swap) #### 27.4.3.7.8 basic_string​::​swap [string.swap] [🔗](#lib:swap,basic_string) `constexpr void swap(basic_string& s) noexcept(allocator_traits::propagate_on_container_swap::value || allocator_traits::is_always_equal::value); ` [1](#1) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/strings.tex#L4263) *Preconditions*: allocator_traits​::​propagate_on_container_swap​::​value is true orget_allocator() == s.get_allocator()[.](#1.sentence-1) [2](#2) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/strings.tex#L4269) *Postconditions*: *this contains the same sequence of characters that was in s,s contains the same sequence of characters that was in*this[.](#2.sentence-1) [3](#3) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/strings.tex#L4276) *Throws*: Nothing[.](#3.sentence-1) [4](#4) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/strings.tex#L4280) *Complexity*: Constant time[.](#4.sentence-1)