Guest User

Untitled

a guest
Feb 17th, 2019
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.66 KB | None | 0 0
  1. // Unreference tuple for raw memory copy.
  2. // Primary template for non referenced elements.
  3. template <class T, class = void>
  4. struct tuple_unref {
  5. tuple_unref(T& t) noexcept : value(t) { }
  6. T& value;
  7. };
  8.  
  9. // A specialization for tuple containing
  10. // at least one reference type.
  11. template <class... Ts>
  12. struct tuple_unref<std::tuple<Ts...>,
  13. std::enable_if_t<(std::is_reference_v<Ts> || ...)>> {
  14. private:
  15. using T = std::tuple<std::remove_reference_t<Ts>...>;
  16.  
  17. T value_;
  18. std::tuple<Ts...>& ref_;
  19.  
  20. public:
  21. tuple_unref(std::tuple<Ts...>& t) noexcept : ref_(t) { }
  22. ~tuple_unref() { ref_ = std::move(value_); }
  23.  
  24. T& value = value_;
  25. };
Add Comment
Please, Sign In to add comment