1 #ifndef ANDROID_PDX_RPC_FIND_REPLACE_H_
2 #define ANDROID_PDX_RPC_FIND_REPLACE_H_
3 
4 #include <type_traits>
5 
6 #include <pdx/rpc/copy_cv_reference.h>
7 
8 namespace android {
9 namespace pdx {
10 namespace rpc {
11 
12 // Utility class to capture types to find and replace.
13 template <typename Find, typename Replace>
14 struct FindReplace;
15 
16 template <typename T, typename U>
17 using IsSameBaseType = typename std::is_same<typename std::decay<T>::type,
18                                              typename std::decay<U>::type>;
19 
20 // Replaces the type Subject with type Replace if type Subject is the same type
21 // as type Find, excluding cv-reference qualifiers in the match.
22 template <typename Find, typename Replace, typename Subject>
23 using ReplaceType =
24     typename std::conditional<IsSameBaseType<Find, Subject>::value,
25                               CopyCVReferenceType<Subject, Replace>,
26                               Subject>::type;
27 
28 // Determines whether the type Find (excluding cv-reference qualifiers) is in
29 // the given parameter pack.
30 template <typename Find, typename... Types>
31 struct ContainsType : std::true_type {};
32 
33 template <typename Find, typename First, typename... Rest>
34 struct ContainsType<Find, First, Rest...>
35     : std::conditional<IsSameBaseType<Find, First>::value, std::true_type,
36                        ContainsType<Find, Rest...>>::type {};
37 
38 template <typename Find>
39 struct ContainsType<Find> : std::false_type {};
40 
41 }  // namespace rpc
42 }  // namespace pdx
43 }  // namespace android
44 
45 #endif  //  ANDROID_PDX_RPC_FIND_REPLACE_H_
46