1 /*
2  * Copyright 2016 Google Inc.
3  *
4  * Use of this source code is governed by a BSD-style license that can be
5  * found in the LICENSE file.
6  */
7 
8 #ifndef SkExchange_DEFINED
9 #define SkExchange_DEFINED
10 
11 #include <utility>
12 
13 namespace skstd {
14 
15 // std::exchange is in C++14
16 template<typename T, typename U = T>
exchange(T & obj,U && new_val)17 inline static T exchange(T& obj, U&& new_val) {
18     T old_val = std::move(obj);
19     obj = std::forward<U>(new_val);
20     return old_val;
21 }
22 
23 }
24 
25 #endif  // SkExchange_DEFINED
26