xref: /aosp_15_r20/external/google-fruit/include/fruit/impl/meta/algos.h (revision a65addddcf69f38db5b288d787b6b7571a57bb8f)
1*a65addddSAndroid Build Coastguard Worker /*
2*a65addddSAndroid Build Coastguard Worker  * Copyright 2014 Google Inc. All rights reserved.
3*a65addddSAndroid Build Coastguard Worker  *
4*a65addddSAndroid Build Coastguard Worker  * Licensed under the Apache License, Version 2.0 (the "License");
5*a65addddSAndroid Build Coastguard Worker  * you may not use this file except in compliance with the License.
6*a65addddSAndroid Build Coastguard Worker  * You may obtain a copy of the License at
7*a65addddSAndroid Build Coastguard Worker  *
8*a65addddSAndroid Build Coastguard Worker  *     http://www.apache.org/licenses/LICENSE-2.0
9*a65addddSAndroid Build Coastguard Worker  *
10*a65addddSAndroid Build Coastguard Worker  * Unless required by applicable law or agreed to in writing, software
11*a65addddSAndroid Build Coastguard Worker  * distributed under the License is distributed on an "AS IS" BASIS,
12*a65addddSAndroid Build Coastguard Worker  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13*a65addddSAndroid Build Coastguard Worker  * See the License for the specific language governing permissions and
14*a65addddSAndroid Build Coastguard Worker  * limitations under the License.
15*a65addddSAndroid Build Coastguard Worker  */
16*a65addddSAndroid Build Coastguard Worker 
17*a65addddSAndroid Build Coastguard Worker #ifndef FRUIT_META_ALGOS_H
18*a65addddSAndroid Build Coastguard Worker #define FRUIT_META_ALGOS_H
19*a65addddSAndroid Build Coastguard Worker 
20*a65addddSAndroid Build Coastguard Worker #include <fruit/impl/fruit-config.h>
21*a65addddSAndroid Build Coastguard Worker #include <fruit/impl/meta/immutable_map.h>
22*a65addddSAndroid Build Coastguard Worker 
23*a65addddSAndroid Build Coastguard Worker namespace fruit {
24*a65addddSAndroid Build Coastguard Worker namespace impl {
25*a65addddSAndroid Build Coastguard Worker namespace meta {
26*a65addddSAndroid Build Coastguard Worker 
27*a65addddSAndroid Build Coastguard Worker // We need a different (slower) implementation to workaround a Clang bug:
28*a65addddSAndroid Build Coastguard Worker // https://llvm.org/bugs/show_bug.cgi?id=25669
29*a65addddSAndroid Build Coastguard Worker // TODO: remove this once that bug is fixed (for the appropriate Clang versions).
30*a65addddSAndroid Build Coastguard Worker #if FRUIT_HAS_CLANG_ARBITRARY_OVERLOAD_RESOLUTION_BUG
31*a65addddSAndroid Build Coastguard Worker 
32*a65addddSAndroid Build Coastguard Worker struct HasDuplicatesHelper {
33*a65addddSAndroid Build Coastguard Worker   template <typename... Types>
34*a65addddSAndroid Build Coastguard Worker   struct apply {
35*a65addddSAndroid Build Coastguard Worker     using type = Bool<false>;
36*a65addddSAndroid Build Coastguard Worker   };
37*a65addddSAndroid Build Coastguard Worker 
38*a65addddSAndroid Build Coastguard Worker   template <typename Type, typename... Types>
39*a65addddSAndroid Build Coastguard Worker   struct apply<Type, Types...> {
40*a65addddSAndroid Build Coastguard Worker     using type = Or(StaticOr<std::is_same<Type, Types>::value...>, Id<HasDuplicatesHelper(Types...)>);
41*a65addddSAndroid Build Coastguard Worker   };
42*a65addddSAndroid Build Coastguard Worker };
43*a65addddSAndroid Build Coastguard Worker 
44*a65addddSAndroid Build Coastguard Worker struct HasDuplicates {
45*a65addddSAndroid Build Coastguard Worker   template <typename V>
46*a65addddSAndroid Build Coastguard Worker   struct apply;
47*a65addddSAndroid Build Coastguard Worker 
48*a65addddSAndroid Build Coastguard Worker   template <typename... Types>
49*a65addddSAndroid Build Coastguard Worker   struct apply<Vector<Types...>> {
50*a65addddSAndroid Build Coastguard Worker     using type = HasDuplicatesHelper(Types...);
51*a65addddSAndroid Build Coastguard Worker   };
52*a65addddSAndroid Build Coastguard Worker };
53*a65addddSAndroid Build Coastguard Worker 
54*a65addddSAndroid Build Coastguard Worker #else // !FRUIT_HAS_CLANG_ARBITRARY_OVERLOAD_RESOLUTION_BUG
55*a65addddSAndroid Build Coastguard Worker 
56*a65addddSAndroid Build Coastguard Worker // Checks if the given Vector has duplicated types.
57*a65addddSAndroid Build Coastguard Worker struct HasDuplicates {
58*a65addddSAndroid Build Coastguard Worker   template <typename V>
59*a65addddSAndroid Build Coastguard Worker   struct apply;
60*a65addddSAndroid Build Coastguard Worker 
61*a65addddSAndroid Build Coastguard Worker   template <typename... Types>
62*a65addddSAndroid Build Coastguard Worker   struct apply<Vector<Types...>> {
63*a65addddSAndroid Build Coastguard Worker     using M = VectorsToImmutableMap(Vector<Types...>, GenerateIntSequence(Int<sizeof...(Types)>));
64*a65addddSAndroid Build Coastguard Worker     using type = Not(StaticAnd<Eval<ImmutableMapContainsKey(M, Types)>::value...>);
65*a65addddSAndroid Build Coastguard Worker   };
66*a65addddSAndroid Build Coastguard Worker };
67*a65addddSAndroid Build Coastguard Worker 
68*a65addddSAndroid Build Coastguard Worker #endif // FRUIT_HAS_CLANG_ARBITRARY_OVERLOAD_RESOLUTION_BUG
69*a65addddSAndroid Build Coastguard Worker 
70*a65addddSAndroid Build Coastguard Worker } // namespace meta
71*a65addddSAndroid Build Coastguard Worker } // namespace impl
72*a65addddSAndroid Build Coastguard Worker } // namespace fruit
73*a65addddSAndroid Build Coastguard Worker 
74*a65addddSAndroid Build Coastguard Worker #endif // FRUIT_META_ALGOS_H
75