• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
8 #ifndef BOOST_HOF_GUARD_FORWARD_H
9 #define BOOST_HOF_GUARD_FORWARD_H
10 
11 #include <utility>
12 
13 namespace boost { namespace hof {
14 
15 // contexpr-friendly forwarding
16 
17 template<typename T>
forward(typename std::remove_reference<T>::type & t)18 constexpr T&& forward(typename std::remove_reference<T>::type& t) noexcept
19 { return static_cast<T&&>(t); }
20 
21 
22 template<typename T>
forward(typename std::remove_reference<T>::type && t)23 constexpr T&& forward(typename std::remove_reference<T>::type&& t) noexcept
24 {
25   static_assert(!std::is_lvalue_reference<T>::value, "T must not be an lvalue reference type");
26   return static_cast<T&&>(t);
27 }
28 
29 #if (defined(__GNUC__) && !defined (__clang__) && __GNUC__ == 4 && __GNUC_MINOR__ < 7) || defined(_MSC_VER)
30 #define BOOST_HOF_FORWARD(...) boost::hof::forward<__VA_ARGS__>
31 #else
32 #define BOOST_HOF_FORWARD(...) static_cast<__VA_ARGS__ &&>
33 #endif
34 
35 }} // namespace boost::hof
36 
37 #endif
38