//===----------------------------------------------------------------------===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// #ifndef SUPPORT_INSERT_RANGE_HELPERS_H #define SUPPORT_INSERT_RANGE_HELPERS_H #include #include #include #include #include #include #include #include #include #include #include #include "from_range_helpers.h" #include "min_allocator.h" #include "test_allocator.h" #include "test_iterators.h" #include "test_macros.h" #include "type_algorithms.h" // A simple literal-type container. It can be used as a `constexpr` global variable (which isn't supported by // `std::vector`). template class Buffer { public: constexpr Buffer() = default; constexpr Buffer(std::initializer_list input) { assert(input.size() <= N); std::ranges::copy(input, data_); size_ = input.size(); } // Makes initializing `Buffer` nicer -- allows writing `buf = "abc"` instead of `buf = {'a', 'b', 'c'}`. // To make the two forms equivalent, omits the terminating null. template constexpr Buffer(const char (&input) [N2]) requires std::same_as { static_assert(N2 <= N); std::ranges::copy(input, data_); // Omit the terminating null. size_ = input[N2 - 1] == '\0' ? N2 - 1 : N2; } constexpr const T* begin() const { return data_; } constexpr const T* end() const { return data_ + size_; } constexpr std::size_t size() const { return size_; } private: std::size_t size_ = 0; T data_[N] = {}; }; template struct TestCase { Buffer initial; std::size_t index = 0; Buffer input; Buffer expected; }; template constexpr void for_all_iterators_and_allocators(Func f) { using Iterators = types::type_list< cpp20_input_iterator, forward_iterator, bidirectional_iterator, random_access_iterator, contiguous_iterator, PtrT >; types::for_each(Iterators{}, [=]() { f.template operator(), std::allocator>(); f.template operator(), test_allocator>(); f.template operator(), min_allocator>(); f.template operator(), safe_allocator>(); if constexpr (std::sentinel_for) { f.template operator()>(); f.template operator()>(); f.template operator()>(); f.template operator()>(); } }); } // Uses a shorter list of iterator types for use in `constexpr` mode for cases when running the full set in would take // too long. template constexpr void for_all_iterators_and_allocators_constexpr(Func f) { using Iterators = types::type_list< cpp20_input_iterator, forward_iterator, PtrT >; types::for_each(Iterators{}, [=]() { f.template operator(), std::allocator>(); f.template operator(), test_allocator>(); f.template operator(), min_allocator>(); f.template operator(), safe_allocator>(); if constexpr (std::sentinel_for) { f.template operator()>(); f.template operator()>(); f.template operator()>(); f.template operator()>(); } }); } #endif // SUPPORT_INSERT_RANGE_HELPERS_H