Warning: This file is not a C or C++ file. It does not have highlighting.
| 1 | // -*- C++ -*- |
|---|---|
| 2 | //===----------------------------------------------------------------------===// |
| 3 | // |
| 4 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 5 | // See https://llvm.org/LICENSE.txt for license information. |
| 6 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | |
| 10 | #ifndef _LIBCPP___FLAT_SET_UTILS_H |
| 11 | #define _LIBCPP___FLAT_SET_UTILS_H |
| 12 | |
| 13 | #include <__config> |
| 14 | #include <__iterator/iterator_traits.h> |
| 15 | #include <__ranges/access.h> |
| 16 | #include <__ranges/concepts.h> |
| 17 | #include <__type_traits/container_traits.h> |
| 18 | #include <__type_traits/decay.h> |
| 19 | #include <__utility/exception_guard.h> |
| 20 | #include <__utility/forward.h> |
| 21 | #include <__utility/move.h> |
| 22 | |
| 23 | #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) |
| 24 | # pragma GCC system_header |
| 25 | #endif |
| 26 | |
| 27 | _LIBCPP_PUSH_MACROS |
| 28 | #include <__undef_macros> |
| 29 | |
| 30 | #if _LIBCPP_STD_VER >= 23 |
| 31 | |
| 32 | _LIBCPP_BEGIN_NAMESPACE_STD |
| 33 | |
| 34 | // These utilities are defined in a class instead of a namespace so that this class can be befriended more easily. |
| 35 | struct __flat_set_utils { |
| 36 | // Emplace a key into a flat_{multi}set, at the exact position that |
| 37 | // __it point to, assuming that the key is not already present in the set. |
| 38 | // When an exception is thrown during the emplacement, the function will clear the set if the container does not |
| 39 | // have strong exception safety guarantee on emplacement. |
| 40 | template <class _Set, class _Iter, class _KeyArg> |
| 41 | _LIBCPP_HIDE_FROM_ABI static auto __emplace_exact_pos(_Set& __set, _Iter&& __iter, _KeyArg&& __key) { |
| 42 | using _KeyContainer = typename decay_t<_Set>::container_type; |
| 43 | auto __on_failure = std::__make_exception_guard([&]() noexcept { |
| 44 | if constexpr (!__container_traits<_KeyContainer>::__emplacement_has_strong_exception_safety_guarantee) { |
| 45 | __set.clear() /* noexcept */; |
| 46 | } |
| 47 | }); |
| 48 | auto __key_it = __set.__keys_.emplace(__iter.__base(), std::forward<_KeyArg>(__key)); |
| 49 | __on_failure.__complete(); |
| 50 | return typename decay_t<_Set>::iterator(std::move(__key_it)); |
| 51 | } |
| 52 | |
| 53 | template <class _Set, class _InputIterator> |
| 54 | _LIBCPP_HIDE_FROM_ABI static void __append(_Set& __set, _InputIterator __first, _InputIterator __last) { |
| 55 | __set.__keys_.insert(__set.__keys_.end(), std::move(__first), std::move(__last)); |
| 56 | } |
| 57 | |
| 58 | template <class _Set, class _Range> |
| 59 | _LIBCPP_HIDE_FROM_ABI static void __append(_Set& __set, _Range&& __rng) { |
| 60 | if constexpr (requires { __set.__keys_.insert_range(__set.__keys_.end(), std::forward<_Range>(__rng)); }) { |
| 61 | // C++23 Sequence Container should have insert_range member function |
| 62 | // Note that not all Sequence Containers provide append_range. |
| 63 | __set.__keys_.insert_range(__set.__keys_.end(), std::forward<_Range>(__rng)); |
| 64 | } else if constexpr (ranges::common_range<_Range> && |
| 65 | __has_input_iterator_category<ranges::iterator_t<_Range>>::value) { |
| 66 | __set.__keys_.insert(__set.__keys_.end(), ranges::begin(__rng), ranges::end(__rng)); |
| 67 | } else { |
| 68 | for (auto&& __x : __rng) { |
| 69 | __set.__keys_.insert(__set.__keys_.end(), std::forward<decltype(__x)>(__x)); |
| 70 | } |
| 71 | } |
| 72 | } |
| 73 | }; |
| 74 | _LIBCPP_END_NAMESPACE_STD |
| 75 | |
| 76 | #endif // _LIBCPP_STD_VER >= 23 |
| 77 | |
| 78 | _LIBCPP_POP_MACROS |
| 79 | |
| 80 | #endif // #define _LIBCPP___FLAT_SET_UTILS_H |
| 81 |
Warning: This file is not a C or C++ file. It does not have highlighting.
