// Copyright 2022 Huawei Cloud Computing Technology 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 INCLUDED_SRC_UTILS_CPP_CONCEPTS_HPP #define INCLUDED_SRC_UTILS_CPP_CONCEPTS_HPP #include #include #include // TODO(modernize): remove this once std::derived_from is shipped with libcxx template concept derived_from = std::is_base_of_v&& std::is_convertible_v; // TODO(modernize): remove this once std::same_as is shipped with libcxx template concept same_as = std::is_same_vand std::is_same_v; template concept ContainsString = requires { typename T::value_type; } and std::is_same_v; template concept HasSize = requires(T const c) { { c.size() } ->same_as; // TODO(modernize): replace by std::same_as }; template concept HasToString = requires(T const t) { { t.ToString() } ->same_as; // TODO(modernize): replace by std::same_as }; template concept InputIterableContainer = requires(T const c) { { c.begin() } ->same_as; // TODO(modernize): replace by // std::input_iterator { c.end() } ->same_as; // TODO(modernize): replace by // std::input_iterator }; template concept OutputIterableContainer = InputIterableContainerand requires(T c) { { std::inserter(c, c.begin()) } ->same_as>; // TODO(modernize): replace by // std::output_iterator }; template concept InputIterableStringContainer = InputIterableContainerand ContainsString; // TODO(modernize): remove this once we require clang version >= 14.0.0 template concept ClockHasFromSys = requires(std::chrono::time_point const tp) { T::from_sys(tp); }; // TODO(modernize): remove this once we require clang version >= 14.0.0 template concept ClockHasFromTime = requires(std::time_t const t) { T::from_time_t(t); }; template concept StrMapConstForwardIterator = requires(T const c) { { std::remove_reference_t { (*c).first } } ->same_as; }; #endif // INCLUDED_SRC_UTILS_CPP_CONCEPTS_HPP