Home | History | Annotate | Download | only in rpc
      1 #ifndef ANDROID_PDX_RPC_COPY_CV_REFERENCE_H_
      2 #define ANDROID_PDX_RPC_COPY_CV_REFERENCE_H_
      3 
      4 #include <type_traits>
      5 
      6 namespace android {
      7 namespace pdx {
      8 namespace rpc {
      9 
     10 // Copies const, void, and reference qualifiers from type T to type U, such that
     11 // the new type U' carries the same cv-reference qualifiers as T, with the same
     12 // underlying type as U.
     13 template <typename T, typename U>
     14 class CopyCVReference {
     15  private:
     16   using R = typename std::remove_reference<T>::type;
     17   using U1 =
     18       typename std::conditional<std::is_const<R>::value,
     19                                 typename std::add_const<U>::type, U>::type;
     20   using U2 =
     21       typename std::conditional<std::is_volatile<R>::value,
     22                                 typename std::add_volatile<U1>::type, U1>::type;
     23   using U3 =
     24       typename std::conditional<std::is_lvalue_reference<T>::value,
     25                                 typename std::add_lvalue_reference<U2>::type,
     26                                 U2>::type;
     27   using U4 =
     28       typename std::conditional<std::is_rvalue_reference<T>::value,
     29                                 typename std::add_rvalue_reference<U3>::type,
     30                                 U3>::type;
     31 
     32  public:
     33   using Type = U4;
     34 };
     35 
     36 template <typename T, typename U>
     37 using CopyCVReferenceType = typename CopyCVReference<T, U>::Type;
     38 
     39 }  // namespace rpc
     40 }  // namespace pdx
     41 }  // namespace android
     42 
     43 #endif  //  ANDROID_PDX_RPC_COPY_CV_REFERENCE_H_
     44