copy_through_move.hpp 1.1 KB

12345678910111213141516171819202122232425262728293031323334
  1. // This file is part of OpenCV project.
  2. // It is subject to the license terms in the LICENSE file found in the top-level directory
  3. // of this distribution and at http://opencv.org/license.html.
  4. //
  5. // Copyright (C) 2020 Intel Corporation
  6. #ifndef OPENCV_GAPI_UTIL_COPY_THROUGH_MOVE_HPP
  7. #define OPENCV_GAPI_UTIL_COPY_THROUGH_MOVE_HPP
  8. #include <opencv2/gapi/util/type_traits.hpp> //decay_t
  9. namespace cv
  10. {
  11. namespace util
  12. {
  13. //This is a tool to move initialize captures of a lambda in C++11
  14. template<typename T>
  15. struct copy_through_move_t{
  16. T value;
  17. const T& get() const {return value;}
  18. T& get() {return value;}
  19. copy_through_move_t(T&& g) : value(std::move(g)) {}
  20. copy_through_move_t(copy_through_move_t&&) = default;
  21. copy_through_move_t(copy_through_move_t const& lhs) : copy_through_move_t(std::move(const_cast<copy_through_move_t&>(lhs))) {}
  22. };
  23. template<typename T>
  24. copy_through_move_t<util::decay_t<T>> copy_through_move(T&& t){
  25. return std::forward<T>(t);
  26. }
  27. } // namespace util
  28. } // namespace cv
  29. #endif /* OPENCV_GAPI_UTIL_COPY_THROUGH_MOVE_HPP */