SUNphi  1.0
UniversalReferences.hpp
Go to the documentation of this file.
1 #ifndef _UNIVERSALREFERENCE_HPP
2 #define _UNIVERSALREFERENCE_HPP
3 
4 /// \file UniversalReferences.hpp
5 ///
6 /// \brief Defines convenient macro and types for Universal References
7 ///
8 /// https://isocpp.org/blog/2012/11/universal-references-in-c11-scott-meyers
9 
10 #include <metaprogramming/TypeTraits.hpp>
11 
12 namespace SUNphi
13 {
14  /// See http://ericniebler.com/2013/08/07/universal-references-and-the-copy-constructo/
15 #define UNIVERSAL_REFERENCE_CONSTRUCTOR_OF_WRAPPER_DISABLE(T,WRAPPER)
16  typename=EnableIf<not isBaseOf<WRAPPER<T>,T>>
17 
18  /////////////////////////////////////////////////////////////////////
19 
20  /// Forward according to http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2009/n2951.html
21  template <class T,
22  class U,
23  class=EnableIf<(isLvalue<T> ?
24  isLvalue<U> :
25  true) and
26  std::is_convertible<RemRef<U>*,
27  RemRef<T>*>::value>>
28  constexpr T&& forw(U&& u) ///< Variable to forward
29  {
30  return static_cast<T&&>(u);
31  }
32 
33  /////////////////////////////////////////////////////////////////
34 
35  /// Short name for decltype(auto)
36 #define DECLAUTO decltype(auto)
37 }
38 
39 #endif