// Copyright 2019 Google LLC // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // /////////////////////////////////////////////////////////////////////////////// #ifndef TINK_CORE_TEMPLATE_UTIL_H_ #define TINK_CORE_TEMPLATE_UTIL_H_ #include #include #include #include "absl/meta/type_traits.h" namespace crypto { namespace tink { // A list of types template struct List {}; namespace internal { // A helper class template which decides if the TestType occurs in the Tuple // For example, OccursInTuple>::value == false, // and OccursInTuple>::value == true. Not intended // to be used directly. // First declare the template which always takes two parameters. template class OccursInTuple; // In the special case where the tuple is empty, the result is false. template class OccursInTuple> : public std::false_type {}; // If the list is not empty, the result is true if TestType equals the first in // the list, or TestType occurs in the rest of the list. template class OccursInTuple> : public absl::disjunction< std::is_same, OccursInTuple>> {}; // The class HasDuplicates. Defines ::value as true in case the given list has // a duplicate, false otherwise. template class HasDuplicates; // Empty list has no duplicates. template <> class HasDuplicates<> : public std::false_type {}; // Non-empty list has a duplicate if the first appears in the rest, or if the // rest has a duplicate. template class HasDuplicates : public absl::disjunction< OccursInTuple>, HasDuplicates> {}; // The class IndexOf. Defines ::value as zero-based index of first element of // type T in the List. template struct IndexOf; template struct IndexOf> : public std::integral_constant {}; template struct IndexOf> : public std::integral_constant>::value> { }; } // namespace internal } // namespace tink } // namespace crypto #endif // TINK_CORE_TEMPLATE_UTIL_H_