forward.hpp 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. /*=============================================================================
  2. Copyright (c) 2014 Paul Fultz II
  3. forward.h
  4. Distributed under the Boost Software License, Version 1.0. (See accompanying
  5. file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  6. ==============================================================================*/
  7. #ifndef BOOST_HOF_GUARD_FORWARD_H
  8. #define BOOST_HOF_GUARD_FORWARD_H
  9. #include <utility>
  10. namespace boost { namespace hof {
  11. // contexpr-friendly forwarding
  12. template<typename T>
  13. constexpr T&& forward(typename std::remove_reference<T>::type& t) noexcept
  14. { return static_cast<T&&>(t); }
  15. template<typename T>
  16. constexpr T&& forward(typename std::remove_reference<T>::type&& t) noexcept
  17. {
  18. static_assert(!std::is_lvalue_reference<T>::value, "T must not be an lvalue reference type");
  19. return static_cast<T&&>(t);
  20. }
  21. #if (defined(__GNUC__) && !defined (__clang__) && __GNUC__ == 4 && __GNUC_MINOR__ < 7) || defined(_MSC_VER)
  22. #define BOOST_HOF_FORWARD(...) boost::hof::forward<__VA_ARGS__>
  23. #else
  24. #define BOOST_HOF_FORWARD(...) static_cast<__VA_ARGS__ &&>
  25. #endif
  26. }} // namespace boost::hof
  27. #endif