/* * Copyright (c) 2021-2022 Huawei Device Co., Ltd. * 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 PANDA_LIBPANDABASE_CONCEPTS_H #define PANDA_LIBPANDABASE_CONCEPTS_H #include namespace panda { /// Iterable concept // NOLINTBEGIN(readability-identifier-naming) template struct is_iterable : public std::false_type { }; template struct is_iterable< T, std::void_t().begin()), decltype(std::declval().end())>> : public std::true_type { }; template // NOLINTNEXTLINE(misc-definitions-in-headers) constexpr bool is_iterable_v = is_iterable::value; /// Random access iterable concept template struct is_random_access_iterable : public std::bool_constant && std::is_same_v::iterator_category, std::random_access_iterator_tag>> { }; template // NOLINTNEXTLINE(misc-definitions-in-headers) constexpr bool is_random_access_iterable_v = is_random_access_iterable::value; /// Forward iterable concept template struct is_forward_iterable : public std::bool_constant && std::is_same_v::iterator_category, std::forward_iterator_tag>> { }; template // NOLINTNEXTLINE(misc-definitions-in-headers) constexpr bool is_forward_iterable_v = is_forward_iterable::value; /// Vectorable concept template struct is_vectorable : public std::false_type { }; template struct is_vectorable().size()), decltype(std::declval().data())>> : public std::bool_constant> { }; template // NOLINTNEXTLINE(misc-definitions-in-headers) constexpr bool is_vectorable_v = is_vectorable::value; /// Stringable concept template struct is_stringable : public std::false_type { }; template struct is_stringable().length()), decltype(std::declval().data())>> : public std::bool_constant> { }; template // NOLINTNEXTLINE(misc-definitions-in-headers) constexpr bool is_stringable_v = is_stringable::value; /// Hash mappable concept template struct is_hash_mappable : public std::false_type { }; template struct is_hash_mappable< HM, std::void_t().size())>> : public std::bool_constant> { }; template // NOLINTNEXTLINE(misc-definitions-in-headers) constexpr bool is_hash_mappable_v = is_hash_mappable::value; /** * Added in C++20 * Checks whether T is an array type of unknown bound */ template struct is_unbounded_array : public std::false_type { }; template // NOLINTNEXTLINE(modernize-avoid-c-arrays) struct is_unbounded_array : public std::true_type { }; template // NOLINTNEXTLINE(misc-definitions-in-headers) constexpr bool is_unbounded_array_v = is_unbounded_array::value; /// Checks whether T is an array type of known bound template struct is_bounded_array : public std::false_type { }; template // NOLINTNEXTLINE(modernize-avoid-c-arrays) struct is_bounded_array : public std::true_type { }; template // NOLINTNEXTLINE(misc-definitions-in-headers) constexpr bool is_bounded_array_v = is_bounded_array::value; } // namespace panda // NOLINTEND(readability-identifier-naming) #endif // PANDA_LIBPANDABASE_CONCEPTS_H