1[/ 2Copyright 2018 Glen Joseph Fernandes 3(glenjofe@gmail.com) 4 5Distributed under the Boost Software License, Version 1.0. 6(http://www.boost.org/LICENSE_1_0.txt) 7] 8 9[section:exchange exchange] 10 11[simplesect Authors] 12 13* Glen Fernandes 14 15[endsimplesect] 16 17[section Overview] 18 19The header <boost/core/exchange.hpp> provides the function template 20`boost::exchange` which is an implementation of the `std::exchange` 21function introduced in C++14. `boost::exchange(o, v)` replaces the 22value of `o` with `v` and returns the old value of `o`. 23 24[endsect] 25 26[section Examples] 27 28The following example shows `boost::exchange` used to simplify the 29implementation of a move constructor. 30 31``` 32Node(Node&& other) 33 : head_(boost::exchange(other.head_, nullptr)) 34 , tail_(boost::exchange(other.tail_, nullptr)) { } 35``` 36 37[endsect] 38 39[section Reference] 40 41``` 42namespace boost { 43 template<class T, class U = T> 44 constexpr T exchange(T& t, U&& u); 45} 46``` 47[section Functions] 48 49[*`template<class T, class U = T> constexpr T exchange(T& t, U&& u);`] 50 51Equivalent to: 52 53``` 54T v = std::move(t); 55t = std::forward<U>(u); 56return v; 57``` 58 59[endsect] 60 61[endsect] 62 63[endsect] 64