SkExchange.h 477 B

12345678910111213141516171819202122232425
  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. #ifndef SkExchange_DEFINED
  8. #define SkExchange_DEFINED
  9. #include <utility>
  10. namespace skstd {
  11. // std::exchange is in C++14
  12. template<typename T, typename U = T>
  13. inline static T exchange(T& obj, U&& new_val) {
  14. T old_val = std::move(obj);
  15. obj = std::forward<U>(new_val);
  16. return old_val;
  17. }
  18. }
  19. #endif // SkExchange_DEFINED