diff options
author | mikhnenko <mikhnenko@yandex-team.com> | 2023-11-04 00:34:43 +0300 |
---|---|---|
committer | mikhnenko <mikhnenko@yandex-team.com> | 2023-11-04 00:56:50 +0300 |
commit | 1b85f8248fcbe51733270e55a66115495f55e962 (patch) | |
tree | 5a15497b81da50ab1729df98ea80b44e6d17e8f2 /contrib | |
parent | 7f0f6f3bb94e4546f9c87b9ba3bed8721b1cd5de (diff) | |
download | ydb-1b85f8248fcbe51733270e55a66115495f55e962.tar.gz |
Use ym2 for sysincls generating
Diffstat (limited to 'contrib')
93 files changed, 17782 insertions, 0 deletions
diff --git a/contrib/libs/cxxsupp/libcxxmsvc/include/__charconv/from_chars_result.h b/contrib/libs/cxxsupp/libcxxmsvc/include/__charconv/from_chars_result.h new file mode 100644 index 0000000000..2cc3c11ef6 --- /dev/null +++ b/contrib/libs/cxxsupp/libcxxmsvc/include/__charconv/from_chars_result.h @@ -0,0 +1,37 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// 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 _LIBCPP___CHARCONV_FROM_CHARS_RESULT_H +#define _LIBCPP___CHARCONV_FROM_CHARS_RESULT_H + +#include <__config> +#include <__errc> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +# pragma GCC system_header +#endif + +_LIBCPP_BEGIN_NAMESPACE_STD + +#ifndef _LIBCPP_CXX03_LANG + +struct _LIBCPP_TYPE_VIS from_chars_result +{ + const char* ptr; + errc ec; +# if _LIBCPP_STD_VER > 17 + _LIBCPP_HIDE_FROM_ABI friend bool operator==(const from_chars_result&, const from_chars_result&) = default; +# endif +}; + +#endif // _LIBCPP_CXX03_LANG + +_LIBCPP_END_NAMESPACE_STD + +#endif // _LIBCPP___CHARCONV_FROM_CHARS_RESULT_H diff --git a/contrib/libs/cxxsupp/libcxxmsvc/include/__coroutine/coroutine_handle.h b/contrib/libs/cxxsupp/libcxxmsvc/include/__coroutine/coroutine_handle.h new file mode 100644 index 0000000000..4bf3237892 --- /dev/null +++ b/contrib/libs/cxxsupp/libcxxmsvc/include/__coroutine/coroutine_handle.h @@ -0,0 +1,202 @@ +//===----------------------------------------------------------------------===// +// +// 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 _LIBCPP___COROUTINE_COROUTINE_HANDLE_H +#define _LIBCPP___COROUTINE_COROUTINE_HANDLE_H + +#include <__assert> +#include <__config> +#include <__functional/hash.h> +#include <__memory/addressof.h> +#include <compare> +#include <type_traits> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +# pragma GCC system_header +#endif + +#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_CXX20_COROUTINES) + +_LIBCPP_BEGIN_NAMESPACE_STD + +// [coroutine.handle] +template <class _Promise = void> +struct _LIBCPP_TEMPLATE_VIS coroutine_handle; + +template <> +struct _LIBCPP_TEMPLATE_VIS coroutine_handle<void> { +public: + // [coroutine.handle.con], construct/reset + _LIBCPP_HIDE_FROM_ABI + constexpr coroutine_handle() noexcept = default; + + _LIBCPP_HIDE_FROM_ABI + constexpr coroutine_handle(nullptr_t) noexcept {} + + _LIBCPP_HIDE_FROM_ABI + coroutine_handle& operator=(nullptr_t) noexcept { + __handle_ = nullptr; + return *this; + } + + // [coroutine.handle.export.import], export/import + _LIBCPP_HIDE_FROM_ABI + constexpr void* address() const noexcept { return __handle_; } + + _LIBCPP_HIDE_FROM_ABI + static constexpr coroutine_handle from_address(void* __addr) noexcept { + coroutine_handle __tmp; + __tmp.__handle_ = __addr; + return __tmp; + } + + // [coroutine.handle.observers], observers + _LIBCPP_HIDE_FROM_ABI + constexpr explicit operator bool() const noexcept { + return __handle_ != nullptr; + } + + _LIBCPP_HIDE_FROM_ABI + bool done() const { + _LIBCPP_ASSERT(__is_suspended(), "done() can be called only on suspended coroutines"); + return __builtin_coro_done(__handle_); + } + + // [coroutine.handle.resumption], resumption + _LIBCPP_HIDE_FROM_ABI + void operator()() const { resume(); } + + _LIBCPP_HIDE_FROM_ABI + void resume() const { + _LIBCPP_ASSERT(__is_suspended(), "resume() can be called only on suspended coroutines"); + _LIBCPP_ASSERT(!done(), "resume() has undefined behavior when the coroutine is done"); + __builtin_coro_resume(__handle_); + } + + _LIBCPP_HIDE_FROM_ABI + void destroy() const { + _LIBCPP_ASSERT(__is_suspended(), "destroy() can be called only on suspended coroutines"); + __builtin_coro_destroy(__handle_); + } + +private: + bool __is_suspended() const { + // FIXME actually implement a check for if the coro is suspended. + return __handle_ != nullptr; + } + + void* __handle_ = nullptr; +}; + +// [coroutine.handle.compare] +inline _LIBCPP_HIDE_FROM_ABI +constexpr bool operator==(coroutine_handle<> __x, coroutine_handle<> __y) noexcept { + return __x.address() == __y.address(); +} +inline _LIBCPP_HIDE_FROM_ABI +constexpr strong_ordering operator<=>(coroutine_handle<> __x, coroutine_handle<> __y) noexcept { + return compare_three_way()(__x.address(), __y.address()); +} + +template <class _Promise> +struct _LIBCPP_TEMPLATE_VIS coroutine_handle { +public: + // [coroutine.handle.con], construct/reset + _LIBCPP_HIDE_FROM_ABI + constexpr coroutine_handle() noexcept = default; + + _LIBCPP_HIDE_FROM_ABI + constexpr coroutine_handle(nullptr_t) noexcept {} + + _LIBCPP_HIDE_FROM_ABI + static coroutine_handle from_promise(_Promise& __promise) { + using _RawPromise = typename remove_cv<_Promise>::type; + coroutine_handle __tmp; + __tmp.__handle_ = + __builtin_coro_promise(_VSTD::addressof(const_cast<_RawPromise&>(__promise)), alignof(_Promise), true); + return __tmp; + } + + _LIBCPP_HIDE_FROM_ABI + coroutine_handle& operator=(nullptr_t) noexcept { + __handle_ = nullptr; + return *this; + } + + // [coroutine.handle.export.import], export/import + _LIBCPP_HIDE_FROM_ABI + constexpr void* address() const noexcept { return __handle_; } + + _LIBCPP_HIDE_FROM_ABI + static constexpr coroutine_handle from_address(void* __addr) noexcept { + coroutine_handle __tmp; + __tmp.__handle_ = __addr; + return __tmp; + } + + // [coroutine.handle.conv], conversion + _LIBCPP_HIDE_FROM_ABI + constexpr operator coroutine_handle<>() const noexcept { + return coroutine_handle<>::from_address(address()); + } + + // [coroutine.handle.observers], observers + _LIBCPP_HIDE_FROM_ABI + constexpr explicit operator bool() const noexcept { + return __handle_ != nullptr; + } + + _LIBCPP_HIDE_FROM_ABI + bool done() const { + _LIBCPP_ASSERT(__is_suspended(), "done() can be called only on suspended coroutines"); + return __builtin_coro_done(__handle_); + } + + // [coroutine.handle.resumption], resumption + _LIBCPP_HIDE_FROM_ABI + void operator()() const { resume(); } + + _LIBCPP_HIDE_FROM_ABI + void resume() const { + _LIBCPP_ASSERT(__is_suspended(), "resume() can be called only on suspended coroutines"); + _LIBCPP_ASSERT(!done(), "resume() has undefined behavior when the coroutine is done"); + __builtin_coro_resume(__handle_); + } + + _LIBCPP_HIDE_FROM_ABI + void destroy() const { + _LIBCPP_ASSERT(__is_suspended(), "destroy() can be called only on suspended coroutines"); + __builtin_coro_destroy(__handle_); + } + + // [coroutine.handle.promise], promise access + _LIBCPP_HIDE_FROM_ABI + _Promise& promise() const { + return *static_cast<_Promise*>(__builtin_coro_promise(this->__handle_, alignof(_Promise), false)); + } + +private: + bool __is_suspended() const { + // FIXME actually implement a check for if the coro is suspended. + return __handle_ != nullptr; + } + void* __handle_ = nullptr; +}; + +// [coroutine.handle.hash] +template <class _Tp> +struct hash<coroutine_handle<_Tp>> { + _LIBCPP_HIDE_FROM_ABI + size_t operator()(const coroutine_handle<_Tp>& __v) const noexcept { return hash<void*>()(__v.address()); } +}; + +_LIBCPP_END_NAMESPACE_STD + +#endif // __LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_CXX20_COROUTINES) + +#endif // _LIBCPP___COROUTINE_COROUTINE_HANDLE_H diff --git a/contrib/libs/cxxsupp/libcxxmsvc/include/__coroutine/coroutine_traits.h b/contrib/libs/cxxsupp/libcxxmsvc/include/__coroutine/coroutine_traits.h new file mode 100644 index 0000000000..0a5229b459 --- /dev/null +++ b/contrib/libs/cxxsupp/libcxxmsvc/include/__coroutine/coroutine_traits.h @@ -0,0 +1,53 @@ +//===----------------------------------------------------------------------===// +// +// 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 _LIBCPP___COROUTINE_COROUTINE_TRAITS_H +#define _LIBCPP___COROUTINE_COROUTINE_TRAITS_H + +#include <__config> +#include <type_traits> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +# pragma GCC system_header +#endif + +#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_CXX20_COROUTINES) + +_LIBCPP_BEGIN_NAMESPACE_STD + +// [coroutine.traits] +// [coroutine.traits.primary] +// The header <coroutine> defined the primary template coroutine_traits such that +// if ArgTypes is a parameter pack of types and if the qualified-id R::promise_type +// is valid and denotes a type ([temp.deduct]), then coroutine_traits<R, ArgTypes...> +// has the following publicly accessible memebr: +// +// using promise_type = typename R::promise_type; +// +// Otherwise, coroutine_traits<R, ArgTypes...> has no members. +template <class _Tp, class = void> +struct __coroutine_traits_sfinae {}; + +template <class _Tp> +struct __coroutine_traits_sfinae< + _Tp, typename __void_t<typename _Tp::promise_type>::type> +{ + using promise_type = typename _Tp::promise_type; +}; + +template <class _Ret, class... _Args> +struct coroutine_traits + : public __coroutine_traits_sfinae<_Ret> +{ +}; + +_LIBCPP_END_NAMESPACE_STD + +#endif // __LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_CXX20_COROUTINES) + +#endif // _LIBCPP___COROUTINE_COROUTINE_TRAITS_H diff --git a/contrib/libs/cxxsupp/libcxxmsvc/include/__coroutine/noop_coroutine_handle.h b/contrib/libs/cxxsupp/libcxxmsvc/include/__coroutine/noop_coroutine_handle.h new file mode 100644 index 0000000000..7a2c672057 --- /dev/null +++ b/contrib/libs/cxxsupp/libcxxmsvc/include/__coroutine/noop_coroutine_handle.h @@ -0,0 +1,112 @@ +//===----------------------------------------------------------------------===// +// +// 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 _LIBCPP___COROUTINE_NOOP_COROUTINE_HANDLE_H +#define _LIBCPP___COROUTINE_NOOP_COROUTINE_HANDLE_H + +#include <__config> +#include <__coroutine/coroutine_handle.h> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +# pragma GCC system_header +#endif + +#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_CXX20_COROUTINES) + +_LIBCPP_BEGIN_NAMESPACE_STD + +#if __has_builtin(__builtin_coro_noop) || defined(_LIBCPP_COMPILER_GCC) + +// [coroutine.noop] +// [coroutine.promise.noop] +struct noop_coroutine_promise {}; + +// [coroutine.handle.noop] +template <> +struct _LIBCPP_TEMPLATE_VIS coroutine_handle<noop_coroutine_promise> { +public: + // [coroutine.handle.noop.conv], conversion + _LIBCPP_HIDE_FROM_ABI + constexpr operator coroutine_handle<>() const noexcept { + return coroutine_handle<>::from_address(address()); + } + + // [coroutine.handle.noop.observers], observers + _LIBCPP_HIDE_FROM_ABI + constexpr explicit operator bool() const noexcept { return true; } + _LIBCPP_HIDE_FROM_ABI + constexpr bool done() const noexcept { return false; } + + // [coroutine.handle.noop.resumption], resumption + _LIBCPP_HIDE_FROM_ABI + constexpr void operator()() const noexcept {} + _LIBCPP_HIDE_FROM_ABI + constexpr void resume() const noexcept {} + _LIBCPP_HIDE_FROM_ABI + constexpr void destroy() const noexcept {} + + // [coroutine.handle.noop.promise], promise access + _LIBCPP_HIDE_FROM_ABI + noop_coroutine_promise& promise() const noexcept { + return *static_cast<noop_coroutine_promise*>( + __builtin_coro_promise(this->__handle_, alignof(noop_coroutine_promise), false)); + } + + // [coroutine.handle.noop.address], address + _LIBCPP_HIDE_FROM_ABI + constexpr void* address() const noexcept { return __handle_; } + +private: + _LIBCPP_HIDE_FROM_ABI + friend coroutine_handle<noop_coroutine_promise> noop_coroutine() noexcept; + +#if __has_builtin(__builtin_coro_noop) + _LIBCPP_HIDE_FROM_ABI coroutine_handle() noexcept { + this->__handle_ = __builtin_coro_noop(); + } + + void* __handle_ = nullptr; + +#elif defined(_LIBCPP_COMPILER_GCC) + // GCC doesn't implement __builtin_coro_noop(). + // Construct the coroutine frame manually instead. + struct __noop_coroutine_frame_ty_ { + static void __dummy_resume_destroy_func() { } + + void (*__resume_)() = __dummy_resume_destroy_func; + void (*__destroy_)() = __dummy_resume_destroy_func; + struct noop_coroutine_promise __promise_; + }; + + static __noop_coroutine_frame_ty_ __noop_coroutine_frame_; + + void* __handle_ = &__noop_coroutine_frame_; + + _LIBCPP_HIDE_FROM_ABI coroutine_handle() noexcept = default; + +#endif // __has_builtin(__builtin_coro_noop) +}; + +using noop_coroutine_handle = coroutine_handle<noop_coroutine_promise>; + +#if defined(_LIBCPP_COMPILER_GCC) +inline noop_coroutine_handle::__noop_coroutine_frame_ty_ + noop_coroutine_handle::__noop_coroutine_frame_{}; +#endif + +// [coroutine.noop.coroutine] +inline _LIBCPP_HIDE_FROM_ABI +noop_coroutine_handle noop_coroutine() noexcept { return noop_coroutine_handle(); } + +#endif // __has_builtin(__builtin_coro_noop) || defined(_LIBCPP_COMPILER_GCC) + +_LIBCPP_END_NAMESPACE_STD + +#endif // __LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_CXX20_COROUTINES) + +#endif // _LIBCPP___COROUTINE_NOOP_COROUTINE_HANDLE_H diff --git a/contrib/libs/cxxsupp/libcxxmsvc/include/__coroutine/trivial_awaitables.h b/contrib/libs/cxxsupp/libcxxmsvc/include/__coroutine/trivial_awaitables.h new file mode 100644 index 0000000000..31399ab29a --- /dev/null +++ b/contrib/libs/cxxsupp/libcxxmsvc/include/__coroutine/trivial_awaitables.h @@ -0,0 +1,46 @@ +//===----------------------------------------------------------------------===// +// +// 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 __LIBCPP___COROUTINE_TRIVIAL_AWAITABLES_H +#define __LIBCPP___COROUTINE_TRIVIAL_AWAITABLES_H + +#include <__config> +#include <__coroutine/coroutine_handle.h> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +# pragma GCC system_header +#endif + +#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_CXX20_COROUTINES) + +_LIBCPP_BEGIN_NAMESPACE_STD + +// [coroutine.trivial.awaitables] +struct suspend_never { + _LIBCPP_HIDE_FROM_ABI + constexpr bool await_ready() const noexcept { return true; } + _LIBCPP_HIDE_FROM_ABI + constexpr void await_suspend(coroutine_handle<>) const noexcept {} + _LIBCPP_HIDE_FROM_ABI + constexpr void await_resume() const noexcept {} +}; + +struct suspend_always { + _LIBCPP_HIDE_FROM_ABI + constexpr bool await_ready() const noexcept { return false; } + _LIBCPP_HIDE_FROM_ABI + constexpr void await_suspend(coroutine_handle<>) const noexcept {} + _LIBCPP_HIDE_FROM_ABI + constexpr void await_resume() const noexcept {} +}; + +_LIBCPP_END_NAMESPACE_STD + +#endif // __LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_CXX20_COROUTINES) + +#endif // __LIBCPP___COROUTINE_TRIVIAL_AWAITABLES_H diff --git a/contrib/libs/cxxsupp/libcxxmsvc/include/__filesystem/copy_options.h b/contrib/libs/cxxsupp/libcxxmsvc/include/__filesystem/copy_options.h new file mode 100644 index 0000000000..2e037403f6 --- /dev/null +++ b/contrib/libs/cxxsupp/libcxxmsvc/include/__filesystem/copy_options.h @@ -0,0 +1,84 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// 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 _LIBCPP___FILESYSTEM_COPY_OPTIONS_H +#define _LIBCPP___FILESYSTEM_COPY_OPTIONS_H + +#include <__availability> +#include <__config> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +# pragma GCC system_header +#endif + +#ifndef _LIBCPP_CXX03_LANG + +_LIBCPP_BEGIN_NAMESPACE_FILESYSTEM + +_LIBCPP_AVAILABILITY_FILESYSTEM_PUSH + +enum class _LIBCPP_ENUM_VIS copy_options : unsigned short { + none = 0, + skip_existing = 1, + overwrite_existing = 2, + update_existing = 4, + recursive = 8, + copy_symlinks = 16, + skip_symlinks = 32, + directories_only = 64, + create_symlinks = 128, + create_hard_links = 256, + __in_recursive_copy = 512, +}; + +_LIBCPP_INLINE_VISIBILITY +inline constexpr copy_options operator&(copy_options _LHS, copy_options _RHS) { + return static_cast<copy_options>(static_cast<unsigned short>(_LHS) & + static_cast<unsigned short>(_RHS)); +} + +_LIBCPP_INLINE_VISIBILITY +inline constexpr copy_options operator|(copy_options _LHS, copy_options _RHS) { + return static_cast<copy_options>(static_cast<unsigned short>(_LHS) | + static_cast<unsigned short>(_RHS)); +} + +_LIBCPP_INLINE_VISIBILITY +inline constexpr copy_options operator^(copy_options _LHS, copy_options _RHS) { + return static_cast<copy_options>(static_cast<unsigned short>(_LHS) ^ + static_cast<unsigned short>(_RHS)); +} + +_LIBCPP_INLINE_VISIBILITY +inline constexpr copy_options operator~(copy_options _LHS) { + return static_cast<copy_options>(~static_cast<unsigned short>(_LHS)); +} + +_LIBCPP_INLINE_VISIBILITY +inline copy_options& operator&=(copy_options& _LHS, copy_options _RHS) { + return _LHS = _LHS & _RHS; +} + +_LIBCPP_INLINE_VISIBILITY +inline copy_options& operator|=(copy_options& _LHS, copy_options _RHS) { + return _LHS = _LHS | _RHS; +} + +_LIBCPP_INLINE_VISIBILITY +inline copy_options& operator^=(copy_options& _LHS, copy_options _RHS) { + return _LHS = _LHS ^ _RHS; +} + +_LIBCPP_AVAILABILITY_FILESYSTEM_POP + +_LIBCPP_END_NAMESPACE_FILESYSTEM + +#endif // _LIBCPP_CXX03_LANG + +#endif // _LIBCPP___FILESYSTEM_COPY_OPTIONS_H diff --git a/contrib/libs/cxxsupp/libcxxmsvc/include/__filesystem/directory_entry.h b/contrib/libs/cxxsupp/libcxxmsvc/include/__filesystem/directory_entry.h new file mode 100644 index 0000000000..a1f18add81 --- /dev/null +++ b/contrib/libs/cxxsupp/libcxxmsvc/include/__filesystem/directory_entry.h @@ -0,0 +1,516 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// 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 _LIBCPP___FILESYSTEM_DIRECTORY_ENTRY_H +#define _LIBCPP___FILESYSTEM_DIRECTORY_ENTRY_H + +#include <__availability> +#include <__config> +#include <__errc> +#include <__filesystem/file_status.h> +#include <__filesystem/file_time_type.h> +#include <__filesystem/file_type.h> +#include <__filesystem/filesystem_error.h> +#include <__filesystem/operations.h> +#include <__filesystem/path.h> +#include <__filesystem/perms.h> +#include <__utility/unreachable.h> +#include <chrono> +#include <cstdint> +#include <cstdlib> +#include <iosfwd> +#include <system_error> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +# pragma GCC system_header +#endif + +_LIBCPP_PUSH_MACROS +#include <__undef_macros> + +#ifndef _LIBCPP_CXX03_LANG + +_LIBCPP_BEGIN_NAMESPACE_FILESYSTEM + +_LIBCPP_AVAILABILITY_FILESYSTEM_PUSH + + +class directory_entry { + typedef _VSTD_FS::path _Path; + +public: + // constructors and destructors + directory_entry() noexcept = default; + directory_entry(directory_entry const&) = default; + directory_entry(directory_entry&&) noexcept = default; + + _LIBCPP_INLINE_VISIBILITY + explicit directory_entry(_Path const& __p) : __p_(__p) { + error_code __ec; + __refresh(&__ec); + } + + _LIBCPP_INLINE_VISIBILITY + directory_entry(_Path const& __p, error_code& __ec) : __p_(__p) { + __refresh(&__ec); + } + + ~directory_entry() {} + + directory_entry& operator=(directory_entry const&) = default; + directory_entry& operator=(directory_entry&&) noexcept = default; + + _LIBCPP_INLINE_VISIBILITY + void assign(_Path const& __p) { + __p_ = __p; + error_code __ec; + __refresh(&__ec); + } + + _LIBCPP_INLINE_VISIBILITY + void assign(_Path const& __p, error_code& __ec) { + __p_ = __p; + __refresh(&__ec); + } + + _LIBCPP_INLINE_VISIBILITY + void replace_filename(_Path const& __p) { + __p_.replace_filename(__p); + error_code __ec; + __refresh(&__ec); + } + + _LIBCPP_INLINE_VISIBILITY + void replace_filename(_Path const& __p, error_code& __ec) { + __p_ = __p_.parent_path() / __p; + __refresh(&__ec); + } + + _LIBCPP_INLINE_VISIBILITY + void refresh() { __refresh(); } + + _LIBCPP_INLINE_VISIBILITY + void refresh(error_code& __ec) noexcept { __refresh(&__ec); } + + _LIBCPP_INLINE_VISIBILITY + _Path const& path() const noexcept { return __p_; } + + _LIBCPP_INLINE_VISIBILITY + operator const _Path&() const noexcept { return __p_; } + + _LIBCPP_INLINE_VISIBILITY + bool exists() const { return _VSTD_FS::exists(file_status{__get_ft()}); } + + _LIBCPP_INLINE_VISIBILITY + bool exists(error_code& __ec) const noexcept { + return _VSTD_FS::exists(file_status{__get_ft(&__ec)}); + } + + _LIBCPP_INLINE_VISIBILITY + bool is_block_file() const { return __get_ft() == file_type::block; } + + _LIBCPP_INLINE_VISIBILITY + bool is_block_file(error_code& __ec) const noexcept { + return __get_ft(&__ec) == file_type::block; + } + + _LIBCPP_INLINE_VISIBILITY + bool is_character_file() const { return __get_ft() == file_type::character; } + + _LIBCPP_INLINE_VISIBILITY + bool is_character_file(error_code& __ec) const noexcept { + return __get_ft(&__ec) == file_type::character; + } + + _LIBCPP_INLINE_VISIBILITY + bool is_directory() const { return __get_ft() == file_type::directory; } + + _LIBCPP_INLINE_VISIBILITY + bool is_directory(error_code& __ec) const noexcept { + return __get_ft(&__ec) == file_type::directory; + } + + _LIBCPP_INLINE_VISIBILITY + bool is_fifo() const { return __get_ft() == file_type::fifo; } + + _LIBCPP_INLINE_VISIBILITY + bool is_fifo(error_code& __ec) const noexcept { + return __get_ft(&__ec) == file_type::fifo; + } + + _LIBCPP_INLINE_VISIBILITY + bool is_other() const { return _VSTD_FS::is_other(file_status{__get_ft()}); } + + _LIBCPP_INLINE_VISIBILITY + bool is_other(error_code& __ec) const noexcept { + return _VSTD_FS::is_other(file_status{__get_ft(&__ec)}); + } + + _LIBCPP_INLINE_VISIBILITY + bool is_regular_file() const { return __get_ft() == file_type::regular; } + + _LIBCPP_INLINE_VISIBILITY + bool is_regular_file(error_code& __ec) const noexcept { + return __get_ft(&__ec) == file_type::regular; + } + + _LIBCPP_INLINE_VISIBILITY + bool is_socket() const { return __get_ft() == file_type::socket; } + + _LIBCPP_INLINE_VISIBILITY + bool is_socket(error_code& __ec) const noexcept { + return __get_ft(&__ec) == file_type::socket; + } + + _LIBCPP_INLINE_VISIBILITY + bool is_symlink() const { return __get_sym_ft() == file_type::symlink; } + + _LIBCPP_INLINE_VISIBILITY + bool is_symlink(error_code& __ec) const noexcept { + return __get_sym_ft(&__ec) == file_type::symlink; + } + _LIBCPP_INLINE_VISIBILITY + uintmax_t file_size() const { return __get_size(); } + + _LIBCPP_INLINE_VISIBILITY + uintmax_t file_size(error_code& __ec) const noexcept { + return __get_size(&__ec); + } + + _LIBCPP_INLINE_VISIBILITY + uintmax_t hard_link_count() const { return __get_nlink(); } + + _LIBCPP_INLINE_VISIBILITY + uintmax_t hard_link_count(error_code& __ec) const noexcept { + return __get_nlink(&__ec); + } + + _LIBCPP_INLINE_VISIBILITY + file_time_type last_write_time() const { return __get_write_time(); } + + _LIBCPP_INLINE_VISIBILITY + file_time_type last_write_time(error_code& __ec) const noexcept { + return __get_write_time(&__ec); + } + + _LIBCPP_INLINE_VISIBILITY + file_status status() const { return __get_status(); } + + _LIBCPP_INLINE_VISIBILITY + file_status status(error_code& __ec) const noexcept { + return __get_status(&__ec); + } + + _LIBCPP_INLINE_VISIBILITY + file_status symlink_status() const { return __get_symlink_status(); } + + _LIBCPP_INLINE_VISIBILITY + file_status symlink_status(error_code& __ec) const noexcept { + return __get_symlink_status(&__ec); + } + + _LIBCPP_INLINE_VISIBILITY + bool operator<(directory_entry const& __rhs) const noexcept { + return __p_ < __rhs.__p_; + } + + _LIBCPP_INLINE_VISIBILITY + bool operator==(directory_entry const& __rhs) const noexcept { + return __p_ == __rhs.__p_; + } + + _LIBCPP_INLINE_VISIBILITY + bool operator!=(directory_entry const& __rhs) const noexcept { + return __p_ != __rhs.__p_; + } + + _LIBCPP_INLINE_VISIBILITY + bool operator<=(directory_entry const& __rhs) const noexcept { + return __p_ <= __rhs.__p_; + } + + _LIBCPP_INLINE_VISIBILITY + bool operator>(directory_entry const& __rhs) const noexcept { + return __p_ > __rhs.__p_; + } + + _LIBCPP_INLINE_VISIBILITY + bool operator>=(directory_entry const& __rhs) const noexcept { + return __p_ >= __rhs.__p_; + } + + template <class _CharT, class _Traits> + _LIBCPP_INLINE_VISIBILITY + friend basic_ostream<_CharT, _Traits>& operator<<(basic_ostream<_CharT, _Traits>& __os, const directory_entry& __d) { + return __os << __d.path(); + } + +private: + friend class directory_iterator; + friend class recursive_directory_iterator; + friend class __dir_stream; + + enum _CacheType : unsigned char { + _Empty, + _IterSymlink, + _IterNonSymlink, + _RefreshSymlink, + _RefreshSymlinkUnresolved, + _RefreshNonSymlink + }; + + struct __cached_data { + uintmax_t __size_; + uintmax_t __nlink_; + file_time_type __write_time_; + perms __sym_perms_; + perms __non_sym_perms_; + file_type __type_; + _CacheType __cache_type_; + + _LIBCPP_INLINE_VISIBILITY + __cached_data() noexcept { __reset(); } + + _LIBCPP_INLINE_VISIBILITY + void __reset() { + __cache_type_ = _Empty; + __type_ = file_type::none; + __sym_perms_ = __non_sym_perms_ = perms::unknown; + __size_ = __nlink_ = uintmax_t(-1); + __write_time_ = file_time_type::min(); + } + }; + + _LIBCPP_INLINE_VISIBILITY + static __cached_data __create_iter_result(file_type __ft) { + __cached_data __data; + __data.__type_ = __ft; + __data.__cache_type_ = [&]() { + switch (__ft) { + case file_type::none: + return _Empty; + case file_type::symlink: + return _IterSymlink; + default: + return _IterNonSymlink; + } + }(); + return __data; + } + + _LIBCPP_INLINE_VISIBILITY + void __assign_iter_entry(_Path&& __p, __cached_data __dt) { + __p_ = _VSTD::move(__p); + __data_ = __dt; + } + + _LIBCPP_FUNC_VIS + error_code __do_refresh() noexcept; + + _LIBCPP_INLINE_VISIBILITY + static bool __is_dne_error(error_code const& __ec) { + if (!__ec) + return true; + switch (static_cast<errc>(__ec.value())) { + case errc::no_such_file_or_directory: + case errc::not_a_directory: + return true; + default: + return false; + } + } + + _LIBCPP_INLINE_VISIBILITY + void __handle_error(const char* __msg, error_code* __dest_ec, + error_code const& __ec, bool __allow_dne = false) const { + if (__dest_ec) { + *__dest_ec = __ec; + return; + } + if (__ec && (!__allow_dne || !__is_dne_error(__ec))) + __throw_filesystem_error(__msg, __p_, __ec); + } + + _LIBCPP_INLINE_VISIBILITY + void __refresh(error_code* __ec = nullptr) { + __handle_error("in directory_entry::refresh", __ec, __do_refresh(), + /*allow_dne*/ true); + } + + _LIBCPP_INLINE_VISIBILITY + file_type __get_sym_ft(error_code* __ec = nullptr) const { + switch (__data_.__cache_type_) { + case _Empty: + return __symlink_status(__p_, __ec).type(); + case _IterSymlink: + case _RefreshSymlink: + case _RefreshSymlinkUnresolved: + if (__ec) + __ec->clear(); + return file_type::symlink; + case _IterNonSymlink: + case _RefreshNonSymlink: + file_status __st(__data_.__type_); + if (__ec && !_VSTD_FS::exists(__st)) + *__ec = make_error_code(errc::no_such_file_or_directory); + else if (__ec) + __ec->clear(); + return __data_.__type_; + } + __libcpp_unreachable(); + } + + _LIBCPP_INLINE_VISIBILITY + file_type __get_ft(error_code* __ec = nullptr) const { + switch (__data_.__cache_type_) { + case _Empty: + case _IterSymlink: + case _RefreshSymlinkUnresolved: + return __status(__p_, __ec).type(); + case _IterNonSymlink: + case _RefreshNonSymlink: + case _RefreshSymlink: { + file_status __st(__data_.__type_); + if (__ec && !_VSTD_FS::exists(__st)) + *__ec = make_error_code(errc::no_such_file_or_directory); + else if (__ec) + __ec->clear(); + return __data_.__type_; + } + } + __libcpp_unreachable(); + } + + _LIBCPP_INLINE_VISIBILITY + file_status __get_status(error_code* __ec = nullptr) const { + switch (__data_.__cache_type_) { + case _Empty: + case _IterNonSymlink: + case _IterSymlink: + case _RefreshSymlinkUnresolved: + return __status(__p_, __ec); + case _RefreshNonSymlink: + case _RefreshSymlink: + return file_status(__get_ft(__ec), __data_.__non_sym_perms_); + } + __libcpp_unreachable(); + } + + _LIBCPP_INLINE_VISIBILITY + file_status __get_symlink_status(error_code* __ec = nullptr) const { + switch (__data_.__cache_type_) { + case _Empty: + case _IterNonSymlink: + case _IterSymlink: + return __symlink_status(__p_, __ec); + case _RefreshNonSymlink: + return file_status(__get_sym_ft(__ec), __data_.__non_sym_perms_); + case _RefreshSymlink: + case _RefreshSymlinkUnresolved: + return file_status(__get_sym_ft(__ec), __data_.__sym_perms_); + } + __libcpp_unreachable(); + } + + _LIBCPP_INLINE_VISIBILITY + uintmax_t __get_size(error_code* __ec = nullptr) const { + switch (__data_.__cache_type_) { + case _Empty: + case _IterNonSymlink: + case _IterSymlink: + case _RefreshSymlinkUnresolved: + return _VSTD_FS::__file_size(__p_, __ec); + case _RefreshSymlink: + case _RefreshNonSymlink: { + error_code __m_ec; + file_status __st(__get_ft(&__m_ec)); + __handle_error("in directory_entry::file_size", __ec, __m_ec); + if (_VSTD_FS::exists(__st) && !_VSTD_FS::is_regular_file(__st)) { + errc __err_kind = _VSTD_FS::is_directory(__st) ? errc::is_a_directory + : errc::not_supported; + __handle_error("in directory_entry::file_size", __ec, + make_error_code(__err_kind)); + } + return __data_.__size_; + } + } + __libcpp_unreachable(); + } + + _LIBCPP_INLINE_VISIBILITY + uintmax_t __get_nlink(error_code* __ec = nullptr) const { + switch (__data_.__cache_type_) { + case _Empty: + case _IterNonSymlink: + case _IterSymlink: + case _RefreshSymlinkUnresolved: + return _VSTD_FS::__hard_link_count(__p_, __ec); + case _RefreshSymlink: + case _RefreshNonSymlink: { + error_code __m_ec; + (void)__get_ft(&__m_ec); + __handle_error("in directory_entry::hard_link_count", __ec, __m_ec); + return __data_.__nlink_; + } + } + __libcpp_unreachable(); + } + + _LIBCPP_INLINE_VISIBILITY + file_time_type __get_write_time(error_code* __ec = nullptr) const { + switch (__data_.__cache_type_) { + case _Empty: + case _IterNonSymlink: + case _IterSymlink: + case _RefreshSymlinkUnresolved: + return _VSTD_FS::__last_write_time(__p_, __ec); + case _RefreshSymlink: + case _RefreshNonSymlink: { + error_code __m_ec; + file_status __st(__get_ft(&__m_ec)); + __handle_error("in directory_entry::last_write_time", __ec, __m_ec); + if (_VSTD_FS::exists(__st) && + __data_.__write_time_ == file_time_type::min()) + __handle_error("in directory_entry::last_write_time", __ec, + make_error_code(errc::value_too_large)); + return __data_.__write_time_; + } + } + __libcpp_unreachable(); + } + +private: + _Path __p_; + __cached_data __data_; +}; + +class __dir_element_proxy { +public: + inline _LIBCPP_INLINE_VISIBILITY directory_entry operator*() { + return _VSTD::move(__elem_); + } + +private: + friend class directory_iterator; + friend class recursive_directory_iterator; + explicit __dir_element_proxy(directory_entry const& __e) : __elem_(__e) {} + __dir_element_proxy(__dir_element_proxy&& __o) + : __elem_(_VSTD::move(__o.__elem_)) {} + directory_entry __elem_; +}; + +_LIBCPP_AVAILABILITY_FILESYSTEM_POP + +_LIBCPP_END_NAMESPACE_FILESYSTEM + +#endif // _LIBCPP_CXX03_LANG + +_LIBCPP_POP_MACROS + +#endif // _LIBCPP___FILESYSTEM_DIRECTORY_ENTRY_H diff --git a/contrib/libs/cxxsupp/libcxxmsvc/include/__filesystem/directory_iterator.h b/contrib/libs/cxxsupp/libcxxmsvc/include/__filesystem/directory_iterator.h new file mode 100644 index 0000000000..87bbbfac71 --- /dev/null +++ b/contrib/libs/cxxsupp/libcxxmsvc/include/__filesystem/directory_iterator.h @@ -0,0 +1,154 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// 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 _LIBCPP___FILESYSTEM_DIRECTORY_ITERATOR_H +#define _LIBCPP___FILESYSTEM_DIRECTORY_ITERATOR_H + +#include <__assert> +#include <__availability> +#include <__config> +#include <__filesystem/directory_entry.h> +#include <__filesystem/directory_options.h> +#include <__filesystem/path.h> +#include <__iterator/iterator_traits.h> +#include <__memory/shared_ptr.h> +#include <__ranges/enable_borrowed_range.h> +#include <__ranges/enable_view.h> +#include <cstddef> +#include <system_error> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +# pragma GCC system_header +#endif + +#ifndef _LIBCPP_CXX03_LANG + +_LIBCPP_BEGIN_NAMESPACE_FILESYSTEM + +_LIBCPP_AVAILABILITY_FILESYSTEM_PUSH + +class _LIBCPP_HIDDEN __dir_stream; +class directory_iterator { +public: + typedef directory_entry value_type; + typedef ptrdiff_t difference_type; + typedef value_type const* pointer; + typedef value_type const& reference; + typedef input_iterator_tag iterator_category; + +public: + //ctor & dtor + directory_iterator() noexcept {} + + explicit directory_iterator(const path& __p) + : directory_iterator(__p, nullptr) {} + + directory_iterator(const path& __p, directory_options __opts) + : directory_iterator(__p, nullptr, __opts) {} + + directory_iterator(const path& __p, error_code& __ec) + : directory_iterator(__p, &__ec) {} + + directory_iterator(const path& __p, directory_options __opts, + error_code& __ec) + : directory_iterator(__p, &__ec, __opts) {} + + directory_iterator(const directory_iterator&) = default; + directory_iterator(directory_iterator&&) = default; + directory_iterator& operator=(const directory_iterator&) = default; + + directory_iterator& operator=(directory_iterator&& __o) noexcept { + // non-default implementation provided to support self-move assign. + if (this != &__o) { + __imp_ = _VSTD::move(__o.__imp_); + } + return *this; + } + + ~directory_iterator() = default; + + const directory_entry& operator*() const { + _LIBCPP_ASSERT(__imp_, "The end iterator cannot be dereferenced"); + return __dereference(); + } + + const directory_entry* operator->() const { return &**this; } + + directory_iterator& operator++() { return __increment(); } + + __dir_element_proxy operator++(int) { + __dir_element_proxy __p(**this); + __increment(); + return __p; + } + + directory_iterator& increment(error_code& __ec) { return __increment(&__ec); } + +private: + inline _LIBCPP_INLINE_VISIBILITY friend bool + operator==(const directory_iterator& __lhs, + const directory_iterator& __rhs) noexcept; + + // construct the dir_stream + _LIBCPP_FUNC_VIS + directory_iterator(const path&, error_code*, + directory_options = directory_options::none); + + _LIBCPP_FUNC_VIS + directory_iterator& __increment(error_code* __ec = nullptr); + + _LIBCPP_FUNC_VIS + const directory_entry& __dereference() const; + +private: + shared_ptr<__dir_stream> __imp_; +}; + +inline _LIBCPP_INLINE_VISIBILITY bool +operator==(const directory_iterator& __lhs, + const directory_iterator& __rhs) noexcept { + return __lhs.__imp_ == __rhs.__imp_; +} + +inline _LIBCPP_INLINE_VISIBILITY bool +operator!=(const directory_iterator& __lhs, + const directory_iterator& __rhs) noexcept { + return !(__lhs == __rhs); +} + +// enable directory_iterator range-based for statements +inline _LIBCPP_INLINE_VISIBILITY directory_iterator +begin(directory_iterator __iter) noexcept { + return __iter; +} + +inline _LIBCPP_INLINE_VISIBILITY directory_iterator +end(directory_iterator) noexcept { + return directory_iterator(); +} + +_LIBCPP_AVAILABILITY_FILESYSTEM_POP + +_LIBCPP_END_NAMESPACE_FILESYSTEM + +#if !defined(_LIBCPP_HAS_NO_CONCEPTS) + +template <> +_LIBCPP_AVAILABILITY_FILESYSTEM +inline constexpr bool _VSTD::ranges::enable_borrowed_range<_VSTD_FS::directory_iterator> = true; + +template <> +_LIBCPP_AVAILABILITY_FILESYSTEM +inline constexpr bool _VSTD::ranges::enable_view<_VSTD_FS::directory_iterator> = true; + +#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS) + +#endif // _LIBCPP_CXX03_LANG + +#endif // _LIBCPP___FILESYSTEM_DIRECTORY_ITERATOR_H diff --git a/contrib/libs/cxxsupp/libcxxmsvc/include/__filesystem/directory_options.h b/contrib/libs/cxxsupp/libcxxmsvc/include/__filesystem/directory_options.h new file mode 100644 index 0000000000..d3f8cc1deb --- /dev/null +++ b/contrib/libs/cxxsupp/libcxxmsvc/include/__filesystem/directory_options.h @@ -0,0 +1,82 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// 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 _LIBCPP___FILESYSTEM_DIRECTORY_OPTIONS_H +#define _LIBCPP___FILESYSTEM_DIRECTORY_OPTIONS_H + +#include <__availability> +#include <__config> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +# pragma GCC system_header +#endif + +#ifndef _LIBCPP_CXX03_LANG + +_LIBCPP_BEGIN_NAMESPACE_FILESYSTEM + +_LIBCPP_AVAILABILITY_FILESYSTEM_PUSH + +enum class _LIBCPP_ENUM_VIS directory_options : unsigned char { + none = 0, + follow_directory_symlink = 1, + skip_permission_denied = 2 +}; + +_LIBCPP_INLINE_VISIBILITY +inline constexpr directory_options operator&(directory_options _LHS, + directory_options _RHS) { + return static_cast<directory_options>(static_cast<unsigned char>(_LHS) & + static_cast<unsigned char>(_RHS)); +} + +_LIBCPP_INLINE_VISIBILITY +inline constexpr directory_options operator|(directory_options _LHS, + directory_options _RHS) { + return static_cast<directory_options>(static_cast<unsigned char>(_LHS) | + static_cast<unsigned char>(_RHS)); +} + +_LIBCPP_INLINE_VISIBILITY +inline constexpr directory_options operator^(directory_options _LHS, + directory_options _RHS) { + return static_cast<directory_options>(static_cast<unsigned char>(_LHS) ^ + static_cast<unsigned char>(_RHS)); +} + +_LIBCPP_INLINE_VISIBILITY +inline constexpr directory_options operator~(directory_options _LHS) { + return static_cast<directory_options>(~static_cast<unsigned char>(_LHS)); +} + +_LIBCPP_INLINE_VISIBILITY +inline directory_options& operator&=(directory_options& _LHS, + directory_options _RHS) { + return _LHS = _LHS & _RHS; +} + +_LIBCPP_INLINE_VISIBILITY +inline directory_options& operator|=(directory_options& _LHS, + directory_options _RHS) { + return _LHS = _LHS | _RHS; +} + +_LIBCPP_INLINE_VISIBILITY +inline directory_options& operator^=(directory_options& _LHS, + directory_options _RHS) { + return _LHS = _LHS ^ _RHS; +} + +_LIBCPP_AVAILABILITY_FILESYSTEM_POP + +_LIBCPP_END_NAMESPACE_FILESYSTEM + +#endif // _LIBCPP_CXX03_LANG + +#endif // _LIBCPP___FILESYSTEM_DIRECTORY_OPTIONS_H diff --git a/contrib/libs/cxxsupp/libcxxmsvc/include/__filesystem/file_status.h b/contrib/libs/cxxsupp/libcxxmsvc/include/__filesystem/file_status.h new file mode 100644 index 0000000000..ac3f6cbed9 --- /dev/null +++ b/contrib/libs/cxxsupp/libcxxmsvc/include/__filesystem/file_status.h @@ -0,0 +1,72 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// 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 _LIBCPP___FILESYSTEM_FILE_STATUS_H +#define _LIBCPP___FILESYSTEM_FILE_STATUS_H + +#include <__availability> +#include <__config> +#include <__filesystem/file_type.h> +#include <__filesystem/perms.h> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +# pragma GCC system_header +#endif + +#ifndef _LIBCPP_CXX03_LANG + +_LIBCPP_BEGIN_NAMESPACE_FILESYSTEM + +_LIBCPP_AVAILABILITY_FILESYSTEM_PUSH + +class _LIBCPP_TYPE_VIS file_status { +public: + // constructors + _LIBCPP_INLINE_VISIBILITY + file_status() noexcept : file_status(file_type::none) {} + _LIBCPP_INLINE_VISIBILITY + explicit file_status(file_type __ft, perms __prms = perms::unknown) noexcept + : __ft_(__ft), + __prms_(__prms) {} + + file_status(const file_status&) noexcept = default; + file_status(file_status&&) noexcept = default; + + _LIBCPP_INLINE_VISIBILITY + ~file_status() {} + + file_status& operator=(const file_status&) noexcept = default; + file_status& operator=(file_status&&) noexcept = default; + + // observers + _LIBCPP_INLINE_VISIBILITY + file_type type() const noexcept { return __ft_; } + + _LIBCPP_INLINE_VISIBILITY + perms permissions() const noexcept { return __prms_; } + + // modifiers + _LIBCPP_INLINE_VISIBILITY + void type(file_type __ft) noexcept { __ft_ = __ft; } + + _LIBCPP_INLINE_VISIBILITY + void permissions(perms __p) noexcept { __prms_ = __p; } + +private: + file_type __ft_; + perms __prms_; +}; + +_LIBCPP_AVAILABILITY_FILESYSTEM_POP + +_LIBCPP_END_NAMESPACE_FILESYSTEM + +#endif // _LIBCPP_CXX03_LANG + +#endif // _LIBCPP___FILESYSTEM_FILE_STATUS_H diff --git a/contrib/libs/cxxsupp/libcxxmsvc/include/__filesystem/file_type.h b/contrib/libs/cxxsupp/libcxxmsvc/include/__filesystem/file_type.h new file mode 100644 index 0000000000..c756a05c84 --- /dev/null +++ b/contrib/libs/cxxsupp/libcxxmsvc/include/__filesystem/file_type.h @@ -0,0 +1,43 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// 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 _LIBCPP___FILESYSTEM_FILE_TYPE_H +#define _LIBCPP___FILESYSTEM_FILE_TYPE_H + +#include <__availability> +#include <__config> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +# pragma GCC system_header +#endif + +#ifndef _LIBCPP_CXX03_LANG + +_LIBCPP_BEGIN_NAMESPACE_FILESYSTEM + +// On Windows, the library never identifies files as block, character, fifo +// or socket. +enum class _LIBCPP_ENUM_VIS file_type : signed char { + none = 0, + not_found = -1, + regular = 1, + directory = 2, + symlink = 3, + block = 4, + character = 5, + fifo = 6, + socket = 7, + unknown = 8 +}; + +_LIBCPP_END_NAMESPACE_FILESYSTEM + +#endif // _LIBCPP_CXX03_LANG + +#endif // _LIBCPP___FILESYSTEM_FILE_TYPE_H diff --git a/contrib/libs/cxxsupp/libcxxmsvc/include/__filesystem/filesystem_error.h b/contrib/libs/cxxsupp/libcxxmsvc/include/__filesystem/filesystem_error.h new file mode 100644 index 0000000000..e32b14c1b7 --- /dev/null +++ b/contrib/libs/cxxsupp/libcxxmsvc/include/__filesystem/filesystem_error.h @@ -0,0 +1,103 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// 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 _LIBCPP___FILESYSTEM_FILESYSTEM_ERROR_H +#define _LIBCPP___FILESYSTEM_FILESYSTEM_ERROR_H + +#include <__availability> +#include <__config> +#include <__filesystem/path.h> +#include <__memory/shared_ptr.h> +#include <iosfwd> +#include <new> +#include <system_error> +#include <type_traits> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +# pragma GCC system_header +#endif + +#ifndef _LIBCPP_CXX03_LANG + +_LIBCPP_BEGIN_NAMESPACE_FILESYSTEM + +class _LIBCPP_AVAILABILITY_FILESYSTEM _LIBCPP_EXCEPTION_ABI filesystem_error : public system_error { +public: + _LIBCPP_INLINE_VISIBILITY + filesystem_error(const string& __what, error_code __ec) + : system_error(__ec, __what), + __storage_(make_shared<_Storage>(path(), path())) { + __create_what(0); + } + + _LIBCPP_INLINE_VISIBILITY + filesystem_error(const string& __what, const path& __p1, error_code __ec) + : system_error(__ec, __what), + __storage_(make_shared<_Storage>(__p1, path())) { + __create_what(1); + } + + _LIBCPP_INLINE_VISIBILITY + filesystem_error(const string& __what, const path& __p1, const path& __p2, + error_code __ec) + : system_error(__ec, __what), + __storage_(make_shared<_Storage>(__p1, __p2)) { + __create_what(2); + } + + _LIBCPP_INLINE_VISIBILITY + const path& path1() const noexcept { return __storage_->__p1_; } + + _LIBCPP_INLINE_VISIBILITY + const path& path2() const noexcept { return __storage_->__p2_; } + + filesystem_error(const filesystem_error&) = default; + ~filesystem_error() override; // key function + + _LIBCPP_INLINE_VISIBILITY + const char* what() const noexcept override { + return __storage_->__what_.c_str(); + } + + void __create_what(int __num_paths); + +private: + struct _LIBCPP_HIDDEN _Storage { + _LIBCPP_INLINE_VISIBILITY + _Storage(const path& __p1, const path& __p2) : __p1_(__p1), __p2_(__p2) {} + + path __p1_; + path __p2_; + string __what_; + }; + shared_ptr<_Storage> __storage_; +}; + +// TODO(ldionne): We need to pop the pragma and push it again after +// filesystem_error to work around PR41078. +_LIBCPP_AVAILABILITY_FILESYSTEM_PUSH + +template <class... _Args> +_LIBCPP_NORETURN inline _LIBCPP_INLINE_VISIBILITY +#ifndef _LIBCPP_NO_EXCEPTIONS +void __throw_filesystem_error(_Args&&... __args) { + throw filesystem_error(_VSTD::forward<_Args>(__args)...); +} +#else +void __throw_filesystem_error(_Args&&...) { + _VSTD::abort(); +} +#endif +_LIBCPP_AVAILABILITY_FILESYSTEM_POP + +_LIBCPP_END_NAMESPACE_FILESYSTEM + +#endif // _LIBCPP_CXX03_LANG + +#endif // _LIBCPP___FILESYSTEM_FILESYSTEM_ERROR_H diff --git a/contrib/libs/cxxsupp/libcxxmsvc/include/__filesystem/operations.h b/contrib/libs/cxxsupp/libcxxmsvc/include/__filesystem/operations.h new file mode 100644 index 0000000000..894c501d4a --- /dev/null +++ b/contrib/libs/cxxsupp/libcxxmsvc/include/__filesystem/operations.h @@ -0,0 +1,201 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// 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 _LIBCPP___FILESYSTEM_OPERATIONS_H +#define _LIBCPP___FILESYSTEM_OPERATIONS_H + +#include <__availability> +#include <__config> +#include <__filesystem/copy_options.h> +#include <__filesystem/file_status.h> +#include <__filesystem/file_time_type.h> +#include <__filesystem/file_type.h> +#include <__filesystem/path.h> +#include <__filesystem/perm_options.h> +#include <__filesystem/perms.h> +#include <__filesystem/space_info.h> +#include <chrono> +#include <cstdint> +#include <system_error> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +# pragma GCC system_header +#endif + +#ifndef _LIBCPP_CXX03_LANG + +_LIBCPP_BEGIN_NAMESPACE_FILESYSTEM + +_LIBCPP_AVAILABILITY_FILESYSTEM_PUSH + +_LIBCPP_FUNC_VIS path __absolute(const path&, error_code* __ec = nullptr); +_LIBCPP_FUNC_VIS path __canonical(const path&, error_code* __ec = nullptr); +_LIBCPP_FUNC_VIS bool __copy_file(const path& __from, const path& __to, copy_options __opt, error_code* __ec = nullptr); +_LIBCPP_FUNC_VIS void __copy_symlink(const path& __existing_symlink, const path& __new_symlink, error_code* __ec = nullptr); +_LIBCPP_FUNC_VIS void __copy(const path& __from, const path& __to, copy_options __opt, error_code* __ec = nullptr); +_LIBCPP_FUNC_VIS bool __create_directories(const path& p, error_code* ec = nullptr); +_LIBCPP_FUNC_VIS void __create_directory_symlink(const path& __to, const path& __new_symlink, error_code* __ec = nullptr); +_LIBCPP_FUNC_VIS bool __create_directory(const path& p, error_code* ec = nullptr); +_LIBCPP_FUNC_VIS bool __create_directory(const path& p, const path& attributes, error_code* ec = nullptr); +_LIBCPP_FUNC_VIS void __create_hard_link(const path& __to, const path& __new_hard_link, error_code* __ec = nullptr); +_LIBCPP_FUNC_VIS void __create_symlink(const path& __to, const path& __new_symlink, error_code* __ec = nullptr); +_LIBCPP_FUNC_VIS path __current_path(error_code* __ec = nullptr); +_LIBCPP_FUNC_VIS void __current_path(const path&, error_code* __ec = nullptr); +_LIBCPP_FUNC_VIS bool __equivalent(const path&, const path&, error_code* __ec = nullptr); +_LIBCPP_FUNC_VIS file_status __status(const path&, error_code* __ec = nullptr); +_LIBCPP_FUNC_VIS uintmax_t __file_size(const path&, error_code* __ec = nullptr); +_LIBCPP_FUNC_VIS uintmax_t __hard_link_count(const path&, error_code* __ec = nullptr); +_LIBCPP_FUNC_VIS file_status __symlink_status(const path&, error_code* __ec = nullptr); +_LIBCPP_FUNC_VIS file_time_type __last_write_time(const path& p, error_code* ec = nullptr); +_LIBCPP_FUNC_VIS void __last_write_time(const path& p, file_time_type new_time, error_code* ec = nullptr); +_LIBCPP_FUNC_VIS path __weakly_canonical(path const& __p, error_code* __ec = nullptr); +_LIBCPP_FUNC_VIS path __read_symlink(const path& p, error_code* ec = nullptr); +_LIBCPP_FUNC_VIS uintmax_t __remove_all(const path& p, error_code* ec = nullptr); +_LIBCPP_FUNC_VIS bool __remove(const path& p, error_code* ec = nullptr); +_LIBCPP_FUNC_VIS void __rename(const path& from, const path& to, error_code* ec = nullptr); +_LIBCPP_FUNC_VIS void __resize_file(const path& p, uintmax_t size, error_code* ec = nullptr); +_LIBCPP_FUNC_VIS path __temp_directory_path(error_code* __ec = nullptr); + +inline _LIBCPP_HIDE_FROM_ABI path absolute(const path& __p) { return __absolute(__p); } +inline _LIBCPP_HIDE_FROM_ABI path absolute(const path& __p, error_code& __ec) { return __absolute(__p, &__ec); } +inline _LIBCPP_HIDE_FROM_ABI path canonical(const path& __p) { return __canonical(__p); } +inline _LIBCPP_HIDE_FROM_ABI path canonical(const path& __p, error_code& __ec) { return __canonical(__p, &__ec); } +inline _LIBCPP_HIDE_FROM_ABI bool copy_file(const path& __from, const path& __to) { return __copy_file(__from, __to, copy_options::none); } +inline _LIBCPP_HIDE_FROM_ABI bool copy_file(const path& __from, const path& __to, error_code& __ec) { return __copy_file(__from, __to, copy_options::none, &__ec); } +inline _LIBCPP_HIDE_FROM_ABI bool copy_file(const path& __from, const path& __to, copy_options __opt) { return __copy_file(__from, __to, __opt); } +inline _LIBCPP_HIDE_FROM_ABI bool copy_file(const path& __from, const path& __to, copy_options __opt, error_code& __ec) { return __copy_file(__from, __to, __opt, &__ec); } +inline _LIBCPP_HIDE_FROM_ABI void copy_symlink(const path& __from, const path& __to) { __copy_symlink(__from, __to); } +inline _LIBCPP_HIDE_FROM_ABI void copy_symlink(const path& __from, const path& __to, error_code& __ec) noexcept { __copy_symlink(__from, __to, &__ec); } +inline _LIBCPP_HIDE_FROM_ABI void copy(const path& __from, const path& __to) { __copy(__from, __to, copy_options::none); } +inline _LIBCPP_HIDE_FROM_ABI void copy(const path& __from, const path& __to, error_code& __ec) { __copy(__from, __to, copy_options::none, &__ec); } +inline _LIBCPP_HIDE_FROM_ABI void copy(const path& __from, const path& __to, copy_options __opt) { __copy(__from, __to, __opt); } +inline _LIBCPP_HIDE_FROM_ABI void copy(const path& __from, const path& __to, copy_options __opt, error_code& __ec) { __copy(__from, __to, __opt, &__ec); } +inline _LIBCPP_HIDE_FROM_ABI bool create_directories(const path& __p) { return __create_directories(__p); } +inline _LIBCPP_HIDE_FROM_ABI bool create_directories(const path& __p, error_code& __ec) { return __create_directories(__p, &__ec); } +inline _LIBCPP_HIDE_FROM_ABI void create_directory_symlink(const path& __target, const path& __link) { __create_directory_symlink(__target, __link); } +inline _LIBCPP_HIDE_FROM_ABI void create_directory_symlink(const path& __target, const path& __link, error_code& __ec) noexcept { __create_directory_symlink(__target, __link, &__ec); } +inline _LIBCPP_HIDE_FROM_ABI bool create_directory(const path& __p) { return __create_directory(__p); } +inline _LIBCPP_HIDE_FROM_ABI bool create_directory(const path& __p, error_code& __ec) noexcept { return __create_directory(__p, &__ec); } +inline _LIBCPP_HIDE_FROM_ABI bool create_directory(const path& __p, const path& __attrs) { return __create_directory(__p, __attrs); } +inline _LIBCPP_HIDE_FROM_ABI bool create_directory(const path& __p, const path& __attrs, error_code& __ec) noexcept { return __create_directory(__p, __attrs, &__ec); } +inline _LIBCPP_HIDE_FROM_ABI void create_hard_link(const path& __target, const path& __link) { __create_hard_link(__target, __link); } +inline _LIBCPP_HIDE_FROM_ABI void create_hard_link(const path& __target, const path& __link, error_code& __ec) noexcept { __create_hard_link(__target, __link, &__ec); } +inline _LIBCPP_HIDE_FROM_ABI void create_symlink(const path& __target, const path& __link) { __create_symlink(__target, __link); } +inline _LIBCPP_HIDE_FROM_ABI void create_symlink(const path& __target, const path& __link, error_code& __ec) noexcept { return __create_symlink(__target, __link, &__ec); } +inline _LIBCPP_HIDE_FROM_ABI path current_path() { return __current_path(); } +inline _LIBCPP_HIDE_FROM_ABI path current_path(error_code& __ec) { return __current_path(&__ec); } +inline _LIBCPP_HIDE_FROM_ABI void current_path(const path& __p) { __current_path(__p); } +inline _LIBCPP_HIDE_FROM_ABI void current_path(const path& __p, error_code& __ec) noexcept { __current_path(__p, &__ec); } +inline _LIBCPP_HIDE_FROM_ABI bool equivalent(const path& __p1, const path& __p2) { return __equivalent(__p1, __p2); } +inline _LIBCPP_HIDE_FROM_ABI bool equivalent(const path& __p1, const path& __p2, error_code& __ec) noexcept { return __equivalent(__p1, __p2, &__ec); } +inline _LIBCPP_HIDE_FROM_ABI bool status_known(file_status __s) noexcept { return __s.type() != file_type::none; } +inline _LIBCPP_HIDE_FROM_ABI bool exists(file_status __s) noexcept { return status_known(__s) && __s.type() != file_type::not_found; } +inline _LIBCPP_HIDE_FROM_ABI bool exists(const path& __p) { return exists(__status(__p)); } + +inline _LIBCPP_INLINE_VISIBILITY bool exists(const path& __p, error_code& __ec) noexcept { + auto __s = __status(__p, &__ec); + if (status_known(__s)) + __ec.clear(); + return exists(__s); +} + +inline _LIBCPP_HIDE_FROM_ABI uintmax_t file_size(const path& __p) { return __file_size(__p); } +inline _LIBCPP_HIDE_FROM_ABI uintmax_t file_size(const path& __p, error_code& __ec) noexcept { return __file_size(__p, &__ec); } +inline _LIBCPP_HIDE_FROM_ABI uintmax_t hard_link_count(const path& __p) { return __hard_link_count(__p); } +inline _LIBCPP_HIDE_FROM_ABI uintmax_t hard_link_count(const path& __p, error_code& __ec) noexcept { return __hard_link_count(__p, &__ec); } +inline _LIBCPP_HIDE_FROM_ABI bool is_block_file(file_status __s) noexcept { return __s.type() == file_type::block; } +inline _LIBCPP_HIDE_FROM_ABI bool is_block_file(const path& __p) { return is_block_file(__status(__p)); } +inline _LIBCPP_HIDE_FROM_ABI bool is_block_file(const path& __p, error_code& __ec) noexcept { return is_block_file(__status(__p, &__ec)); } +inline _LIBCPP_HIDE_FROM_ABI bool is_character_file(file_status __s) noexcept { return __s.type() == file_type::character; } +inline _LIBCPP_HIDE_FROM_ABI bool is_character_file(const path& __p) { return is_character_file(__status(__p)); } +inline _LIBCPP_HIDE_FROM_ABI bool is_character_file(const path& __p, error_code& __ec) noexcept { return is_character_file(__status(__p, &__ec)); } +inline _LIBCPP_HIDE_FROM_ABI bool is_directory(file_status __s) noexcept { return __s.type() == file_type::directory; } +inline _LIBCPP_HIDE_FROM_ABI bool is_directory(const path& __p) { return is_directory(__status(__p)); } +inline _LIBCPP_HIDE_FROM_ABI bool is_directory(const path& __p, error_code& __ec) noexcept { return is_directory(__status(__p, &__ec)); } +_LIBCPP_FUNC_VIS bool __fs_is_empty(const path& p, error_code* ec = nullptr); +inline _LIBCPP_HIDE_FROM_ABI bool is_empty(const path& __p) { return __fs_is_empty(__p); } +inline _LIBCPP_HIDE_FROM_ABI bool is_empty(const path& __p, error_code& __ec) { return __fs_is_empty(__p, &__ec); } +inline _LIBCPP_HIDE_FROM_ABI bool is_fifo(file_status __s) noexcept { return __s.type() == file_type::fifo; } +inline _LIBCPP_HIDE_FROM_ABI bool is_fifo(const path& __p) { return is_fifo(__status(__p)); } +inline _LIBCPP_HIDE_FROM_ABI bool is_fifo(const path& __p, error_code& __ec) noexcept { return is_fifo(__status(__p, &__ec)); } +inline _LIBCPP_HIDE_FROM_ABI bool is_regular_file(file_status __s) noexcept { return __s.type() == file_type::regular; } +inline _LIBCPP_HIDE_FROM_ABI bool is_regular_file(const path& __p) { return is_regular_file(__status(__p)); } +inline _LIBCPP_HIDE_FROM_ABI bool is_regular_file(const path& __p, error_code& __ec) noexcept { return is_regular_file(__status(__p, &__ec)); } +inline _LIBCPP_HIDE_FROM_ABI bool is_symlink(file_status __s) noexcept { return __s.type() == file_type::symlink; } +inline _LIBCPP_HIDE_FROM_ABI bool is_symlink(const path& __p) { return is_symlink(__symlink_status(__p)); } +inline _LIBCPP_HIDE_FROM_ABI bool is_symlink(const path& __p, error_code& __ec) noexcept { return is_symlink(__symlink_status(__p, &__ec)); } +inline _LIBCPP_HIDE_FROM_ABI bool is_other(file_status __s) noexcept { return exists(__s) && !is_regular_file(__s) && !is_directory(__s) && !is_symlink(__s); } +inline _LIBCPP_HIDE_FROM_ABI bool is_other(const path& __p) { return is_other(__status(__p)); } +inline _LIBCPP_HIDE_FROM_ABI bool is_other(const path& __p, error_code& __ec) noexcept { return is_other(__status(__p, &__ec)); } +inline _LIBCPP_HIDE_FROM_ABI bool is_socket(file_status __s) noexcept { return __s.type() == file_type::socket; } +inline _LIBCPP_HIDE_FROM_ABI bool is_socket(const path& __p) { return is_socket(__status(__p)); } +inline _LIBCPP_HIDE_FROM_ABI bool is_socket(const path& __p, error_code& __ec) noexcept { return is_socket(__status(__p, &__ec)); } +inline _LIBCPP_HIDE_FROM_ABI file_time_type last_write_time(const path& __p) { return __last_write_time(__p); } +inline _LIBCPP_HIDE_FROM_ABI file_time_type last_write_time(const path& __p, error_code& __ec) noexcept { return __last_write_time(__p, &__ec); } +inline _LIBCPP_HIDE_FROM_ABI void last_write_time(const path& __p, file_time_type __t) { __last_write_time(__p, __t); } +inline _LIBCPP_HIDE_FROM_ABI void last_write_time(const path& __p, file_time_type __t, error_code& __ec) noexcept { __last_write_time(__p, __t, &__ec); } +_LIBCPP_FUNC_VIS void __permissions(const path&, perms, perm_options, error_code* = nullptr); +inline _LIBCPP_HIDE_FROM_ABI void permissions(const path& __p, perms __prms, perm_options __opts = perm_options::replace) { __permissions(__p, __prms, __opts); } +inline _LIBCPP_HIDE_FROM_ABI void permissions(const path& __p, perms __prms, error_code& __ec) noexcept { __permissions(__p, __prms, perm_options::replace, &__ec); } +inline _LIBCPP_HIDE_FROM_ABI void permissions(const path& __p, perms __prms, perm_options __opts, error_code& __ec) { __permissions(__p, __prms, __opts, &__ec); } + +inline _LIBCPP_INLINE_VISIBILITY path proximate(const path& __p, const path& __base, error_code& __ec) { + path __tmp = __weakly_canonical(__p, &__ec); + if (__ec) + return {}; + path __tmp_base = __weakly_canonical(__base, &__ec); + if (__ec) + return {}; + return __tmp.lexically_proximate(__tmp_base); +} + +inline _LIBCPP_HIDE_FROM_ABI path proximate(const path& __p, error_code& __ec) { return proximate(__p, current_path(), __ec); } +inline _LIBCPP_HIDE_FROM_ABI path proximate(const path& __p, const path& __base = current_path()) { return __weakly_canonical(__p).lexically_proximate(__weakly_canonical(__base)); } +inline _LIBCPP_HIDE_FROM_ABI path read_symlink(const path& __p) { return __read_symlink(__p); } +inline _LIBCPP_HIDE_FROM_ABI path read_symlink(const path& __p, error_code& __ec) { return __read_symlink(__p, &__ec); } + +inline _LIBCPP_INLINE_VISIBILITY path relative(const path& __p, const path& __base, error_code& __ec) { + path __tmp = __weakly_canonical(__p, &__ec); + if (__ec) + return path(); + path __tmpbase = __weakly_canonical(__base, &__ec); + if (__ec) + return path(); + return __tmp.lexically_relative(__tmpbase); +} + +inline _LIBCPP_HIDE_FROM_ABI path relative(const path& __p, error_code& __ec) { return relative(__p, current_path(), __ec); } +inline _LIBCPP_HIDE_FROM_ABI path relative(const path& __p, const path& __base = current_path()) { return __weakly_canonical(__p).lexically_relative(__weakly_canonical(__base)); } +inline _LIBCPP_HIDE_FROM_ABI uintmax_t remove_all(const path& __p) { return __remove_all(__p); } +inline _LIBCPP_HIDE_FROM_ABI uintmax_t remove_all(const path& __p, error_code& __ec) { return __remove_all(__p, &__ec); } +inline _LIBCPP_HIDE_FROM_ABI bool remove(const path& __p) { return __remove(__p); } +inline _LIBCPP_HIDE_FROM_ABI bool remove(const path& __p, error_code& __ec) noexcept { return __remove(__p, &__ec); } +inline _LIBCPP_HIDE_FROM_ABI void rename(const path& __from, const path& __to) { return __rename(__from, __to); } +inline _LIBCPP_HIDE_FROM_ABI void rename(const path& __from, const path& __to, error_code& __ec) noexcept { return __rename(__from, __to, &__ec); } +inline _LIBCPP_HIDE_FROM_ABI void resize_file(const path& __p, uintmax_t __ns) { return __resize_file(__p, __ns); } +inline _LIBCPP_HIDE_FROM_ABI void resize_file(const path& __p, uintmax_t __ns, error_code& __ec) noexcept { return __resize_file(__p, __ns, &__ec); } +_LIBCPP_FUNC_VIS space_info __space(const path&, error_code* __ec = nullptr); +inline _LIBCPP_HIDE_FROM_ABI space_info space(const path& __p) { return __space(__p); } +inline _LIBCPP_HIDE_FROM_ABI space_info space(const path& __p, error_code& __ec) noexcept { return __space(__p, &__ec); } +inline _LIBCPP_HIDE_FROM_ABI file_status status(const path& __p) { return __status(__p); } +inline _LIBCPP_HIDE_FROM_ABI file_status status(const path& __p, error_code& __ec) noexcept { return __status(__p, &__ec); } +inline _LIBCPP_HIDE_FROM_ABI file_status symlink_status(const path& __p) { return __symlink_status(__p); } +inline _LIBCPP_HIDE_FROM_ABI file_status symlink_status(const path& __p, error_code& __ec) noexcept { return __symlink_status(__p, &__ec); } +inline _LIBCPP_HIDE_FROM_ABI path temp_directory_path() { return __temp_directory_path(); } +inline _LIBCPP_HIDE_FROM_ABI path temp_directory_path(error_code& __ec) { return __temp_directory_path(&__ec); } +inline _LIBCPP_HIDE_FROM_ABI path weakly_canonical(path const& __p) { return __weakly_canonical(__p); } +inline _LIBCPP_HIDE_FROM_ABI path weakly_canonical(path const& __p, error_code& __ec) { return __weakly_canonical(__p, &__ec); } + +_LIBCPP_AVAILABILITY_FILESYSTEM_POP + +_LIBCPP_END_NAMESPACE_FILESYSTEM + +#endif // _LIBCPP_CXX03_LANG + +#endif // _LIBCPP___FILESYSTEM_OPERATIONS_H diff --git a/contrib/libs/cxxsupp/libcxxmsvc/include/__filesystem/path.h b/contrib/libs/cxxsupp/libcxxmsvc/include/__filesystem/path.h new file mode 100644 index 0000000000..6b4b1ae9ba --- /dev/null +++ b/contrib/libs/cxxsupp/libcxxmsvc/include/__filesystem/path.h @@ -0,0 +1,1024 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// 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 _LIBCPP___FILESYSTEM_PATH_H +#define _LIBCPP___FILESYSTEM_PATH_H + +#include <__algorithm/replace.h> +#include <__algorithm/replace_copy.h> +#include <__availability> +#include <__config> +#include <__iterator/back_insert_iterator.h> +#include <__iterator/iterator_traits.h> +#include <cstddef> +#include <string> +#include <string_view> +#include <type_traits> + +#if !defined(_LIBCPP_HAS_NO_LOCALIZATION) +# include <iomanip> // for quoted +# include <locale> +#endif + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +# pragma GCC system_header +#endif + +#ifndef _LIBCPP_CXX03_LANG + +_LIBCPP_BEGIN_NAMESPACE_FILESYSTEM + +_LIBCPP_AVAILABILITY_FILESYSTEM_PUSH + +template <class _Tp> +struct __can_convert_char { + static const bool value = false; +}; +template <class _Tp> +struct __can_convert_char<const _Tp> : public __can_convert_char<_Tp> {}; +template <> +struct __can_convert_char<char> { + static const bool value = true; + using __char_type = char; +}; +template <> +struct __can_convert_char<wchar_t> { + static const bool value = true; + using __char_type = wchar_t; +}; +#ifndef _LIBCPP_HAS_NO_CHAR8_T +template <> +struct __can_convert_char<char8_t> { + static const bool value = true; + using __char_type = char8_t; +}; +#endif +template <> +struct __can_convert_char<char16_t> { + static const bool value = true; + using __char_type = char16_t; +}; +template <> +struct __can_convert_char<char32_t> { + static const bool value = true; + using __char_type = char32_t; +}; + +template <class _ECharT> +typename enable_if<__can_convert_char<_ECharT>::value, bool>::type +__is_separator(_ECharT __e) { +#if defined(_LIBCPP_WIN32API) + return __e == _ECharT('/') || __e == _ECharT('\\'); +#else + return __e == _ECharT('/'); +#endif +} + +#ifndef _LIBCPP_HAS_NO_CHAR8_T +typedef u8string __u8_string; +#else +typedef string __u8_string; +#endif + +struct _NullSentinel {}; + +template <class _Tp> +using _Void = void; + +template <class _Tp, class = void> +struct __is_pathable_string : public false_type {}; + +template <class _ECharT, class _Traits, class _Alloc> +struct __is_pathable_string< + basic_string<_ECharT, _Traits, _Alloc>, + _Void<typename __can_convert_char<_ECharT>::__char_type> > + : public __can_convert_char<_ECharT> { + using _Str = basic_string<_ECharT, _Traits, _Alloc>; + using _Base = __can_convert_char<_ECharT>; + static _ECharT const* __range_begin(_Str const& __s) { return __s.data(); } + static _ECharT const* __range_end(_Str const& __s) { + return __s.data() + __s.length(); + } + static _ECharT __first_or_null(_Str const& __s) { + return __s.empty() ? _ECharT{} : __s[0]; + } +}; + +template <class _ECharT, class _Traits> +struct __is_pathable_string< + basic_string_view<_ECharT, _Traits>, + _Void<typename __can_convert_char<_ECharT>::__char_type> > + : public __can_convert_char<_ECharT> { + using _Str = basic_string_view<_ECharT, _Traits>; + using _Base = __can_convert_char<_ECharT>; + static _ECharT const* __range_begin(_Str const& __s) { return __s.data(); } + static _ECharT const* __range_end(_Str const& __s) { + return __s.data() + __s.length(); + } + static _ECharT __first_or_null(_Str const& __s) { + return __s.empty() ? _ECharT{} : __s[0]; + } +}; + +template <class _Source, class _DS = typename decay<_Source>::type, + class _UnqualPtrType = + typename remove_const<typename remove_pointer<_DS>::type>::type, + bool _IsCharPtr = is_pointer<_DS>::value&& + __can_convert_char<_UnqualPtrType>::value> +struct __is_pathable_char_array : false_type {}; + +template <class _Source, class _ECharT, class _UPtr> +struct __is_pathable_char_array<_Source, _ECharT*, _UPtr, true> + : __can_convert_char<typename remove_const<_ECharT>::type> { + using _Base = __can_convert_char<typename remove_const<_ECharT>::type>; + + static _ECharT const* __range_begin(const _ECharT* __b) { return __b; } + static _ECharT const* __range_end(const _ECharT* __b) { + using _Iter = const _ECharT*; + const _ECharT __sentinel = _ECharT{}; + _Iter __e = __b; + for (; *__e != __sentinel; ++__e) + ; + return __e; + } + + static _ECharT __first_or_null(const _ECharT* __b) { return *__b; } +}; + +template <class _Iter, bool _IsIt = __is_cpp17_input_iterator<_Iter>::value, + class = void> +struct __is_pathable_iter : false_type {}; + +template <class _Iter> +struct __is_pathable_iter< + _Iter, true, + _Void<typename __can_convert_char< + typename iterator_traits<_Iter>::value_type>::__char_type> > + : __can_convert_char<typename iterator_traits<_Iter>::value_type> { + using _ECharT = typename iterator_traits<_Iter>::value_type; + using _Base = __can_convert_char<_ECharT>; + + static _Iter __range_begin(_Iter __b) { return __b; } + static _NullSentinel __range_end(_Iter) { return _NullSentinel{}; } + + static _ECharT __first_or_null(_Iter __b) { return *__b; } +}; + +template <class _Tp, bool _IsStringT = __is_pathable_string<_Tp>::value, + bool _IsCharIterT = __is_pathable_char_array<_Tp>::value, + bool _IsIterT = !_IsCharIterT && __is_pathable_iter<_Tp>::value> +struct __is_pathable : false_type { + static_assert(!_IsStringT && !_IsCharIterT && !_IsIterT, "Must all be false"); +}; + +template <class _Tp> +struct __is_pathable<_Tp, true, false, false> : __is_pathable_string<_Tp> {}; + +template <class _Tp> +struct __is_pathable<_Tp, false, true, false> : __is_pathable_char_array<_Tp> { +}; + +template <class _Tp> +struct __is_pathable<_Tp, false, false, true> : __is_pathable_iter<_Tp> {}; + +#if defined(_LIBCPP_WIN32API) +typedef wstring __path_string; +typedef wchar_t __path_value; +#else +typedef string __path_string; +typedef char __path_value; +#endif + +#if defined(_LIBCPP_WIN32API) +_LIBCPP_FUNC_VIS +size_t __wide_to_char(const wstring&, char*, size_t); +_LIBCPP_FUNC_VIS +size_t __char_to_wide(const string&, wchar_t*, size_t); +#endif + +template <class _ECharT> +struct _PathCVT; + +#if !defined(_LIBCPP_HAS_NO_LOCALIZATION) +template <class _ECharT> +struct _PathCVT { + static_assert(__can_convert_char<_ECharT>::value, + "Char type not convertible"); + + typedef __narrow_to_utf8<sizeof(_ECharT) * __CHAR_BIT__> _Narrower; +#if defined(_LIBCPP_WIN32API) + typedef __widen_from_utf8<sizeof(wchar_t) * __CHAR_BIT__> _Widener; +#endif + + static void __append_range(__path_string& __dest, _ECharT const* __b, + _ECharT const* __e) { +#if defined(_LIBCPP_WIN32API) + string __utf8; + _Narrower()(back_inserter(__utf8), __b, __e); + _Widener()(back_inserter(__dest), __utf8.data(), __utf8.data() + __utf8.size()); +#else + _Narrower()(back_inserter(__dest), __b, __e); +#endif + } + + template <class _Iter> + static void __append_range(__path_string& __dest, _Iter __b, _Iter __e) { + static_assert(!is_same<_Iter, _ECharT*>::value, "Call const overload"); + if (__b == __e) + return; + basic_string<_ECharT> __tmp(__b, __e); +#if defined(_LIBCPP_WIN32API) + string __utf8; + _Narrower()(back_inserter(__utf8), __tmp.data(), + __tmp.data() + __tmp.length()); + _Widener()(back_inserter(__dest), __utf8.data(), __utf8.data() + __utf8.size()); +#else + _Narrower()(back_inserter(__dest), __tmp.data(), + __tmp.data() + __tmp.length()); +#endif + } + + template <class _Iter> + static void __append_range(__path_string& __dest, _Iter __b, _NullSentinel) { + static_assert(!is_same<_Iter, _ECharT*>::value, "Call const overload"); + const _ECharT __sentinel = _ECharT{}; + if (*__b == __sentinel) + return; + basic_string<_ECharT> __tmp; + for (; *__b != __sentinel; ++__b) + __tmp.push_back(*__b); +#if defined(_LIBCPP_WIN32API) + string __utf8; + _Narrower()(back_inserter(__utf8), __tmp.data(), + __tmp.data() + __tmp.length()); + _Widener()(back_inserter(__dest), __utf8.data(), __utf8.data() + __utf8.size()); +#else + _Narrower()(back_inserter(__dest), __tmp.data(), + __tmp.data() + __tmp.length()); +#endif + } + + template <class _Source> + static void __append_source(__path_string& __dest, _Source const& __s) { + using _Traits = __is_pathable<_Source>; + __append_range(__dest, _Traits::__range_begin(__s), + _Traits::__range_end(__s)); + } +}; +#endif // !_LIBCPP_HAS_NO_LOCALIZATION + +template <> +struct _PathCVT<__path_value> { + + template <class _Iter> + static typename enable_if<__is_exactly_cpp17_input_iterator<_Iter>::value>::type + __append_range(__path_string& __dest, _Iter __b, _Iter __e) { + for (; __b != __e; ++__b) + __dest.push_back(*__b); + } + + template <class _Iter> + static typename enable_if<__is_cpp17_forward_iterator<_Iter>::value>::type + __append_range(__path_string& __dest, _Iter __b, _Iter __e) { + __dest.append(__b, __e); + } + + template <class _Iter> + static void __append_range(__path_string& __dest, _Iter __b, _NullSentinel) { + const char __sentinel = char{}; + for (; *__b != __sentinel; ++__b) + __dest.push_back(*__b); + } + + template <class _Source> + static void __append_source(__path_string& __dest, _Source const& __s) { + using _Traits = __is_pathable<_Source>; + __append_range(__dest, _Traits::__range_begin(__s), + _Traits::__range_end(__s)); + } +}; + +#if defined(_LIBCPP_WIN32API) +template <> +struct _PathCVT<char> { + + static void + __append_string(__path_string& __dest, const basic_string<char> &__str) { + size_t __size = __char_to_wide(__str, nullptr, 0); + size_t __pos = __dest.size(); + __dest.resize(__pos + __size); + __char_to_wide(__str, const_cast<__path_value*>(__dest.data()) + __pos, __size); + } + + template <class _Iter> + static typename enable_if<__is_exactly_cpp17_input_iterator<_Iter>::value>::type + __append_range(__path_string& __dest, _Iter __b, _Iter __e) { + basic_string<char> __tmp(__b, __e); + __append_string(__dest, __tmp); + } + + template <class _Iter> + static typename enable_if<__is_cpp17_forward_iterator<_Iter>::value>::type + __append_range(__path_string& __dest, _Iter __b, _Iter __e) { + basic_string<char> __tmp(__b, __e); + __append_string(__dest, __tmp); + } + + template <class _Iter> + static void __append_range(__path_string& __dest, _Iter __b, _NullSentinel) { + const char __sentinel = char{}; + basic_string<char> __tmp; + for (; *__b != __sentinel; ++__b) + __tmp.push_back(*__b); + __append_string(__dest, __tmp); + } + + template <class _Source> + static void __append_source(__path_string& __dest, _Source const& __s) { + using _Traits = __is_pathable<_Source>; + __append_range(__dest, _Traits::__range_begin(__s), + _Traits::__range_end(__s)); + } +}; + +template <class _ECharT> +struct _PathExport { + typedef __narrow_to_utf8<sizeof(wchar_t) * __CHAR_BIT__> _Narrower; + typedef __widen_from_utf8<sizeof(_ECharT) * __CHAR_BIT__> _Widener; + + template <class _Str> + static void __append(_Str& __dest, const __path_string& __src) { + string __utf8; + _Narrower()(back_inserter(__utf8), __src.data(), __src.data() + __src.size()); + _Widener()(back_inserter(__dest), __utf8.data(), __utf8.data() + __utf8.size()); + } +}; + +template <> +struct _PathExport<char> { + template <class _Str> + static void __append(_Str& __dest, const __path_string& __src) { + size_t __size = __wide_to_char(__src, nullptr, 0); + size_t __pos = __dest.size(); + __dest.resize(__size); + __wide_to_char(__src, const_cast<char*>(__dest.data()) + __pos, __size); + } +}; + +template <> +struct _PathExport<wchar_t> { + template <class _Str> + static void __append(_Str& __dest, const __path_string& __src) { + __dest.append(__src.begin(), __src.end()); + } +}; + +template <> +struct _PathExport<char16_t> { + template <class _Str> + static void __append(_Str& __dest, const __path_string& __src) { + __dest.append(__src.begin(), __src.end()); + } +}; + +#ifndef _LIBCPP_HAS_NO_CHAR8_T +template <> +struct _PathExport<char8_t> { + typedef __narrow_to_utf8<sizeof(wchar_t) * __CHAR_BIT__> _Narrower; + + template <class _Str> + static void __append(_Str& __dest, const __path_string& __src) { + _Narrower()(back_inserter(__dest), __src.data(), __src.data() + __src.size()); + } +}; +#endif /* !_LIBCPP_HAS_NO_CHAR8_T */ +#endif /* _LIBCPP_WIN32API */ + +class _LIBCPP_TYPE_VIS path { + template <class _SourceOrIter, class _Tp = path&> + using _EnableIfPathable = + typename enable_if<__is_pathable<_SourceOrIter>::value, _Tp>::type; + + template <class _Tp> + using _SourceChar = typename __is_pathable<_Tp>::__char_type; + + template <class _Tp> + using _SourceCVT = _PathCVT<_SourceChar<_Tp> >; + +public: +#if defined(_LIBCPP_WIN32API) + typedef wchar_t value_type; + static constexpr value_type preferred_separator = L'\\'; +#else + typedef char value_type; + static constexpr value_type preferred_separator = '/'; +#endif + typedef basic_string<value_type> string_type; + typedef basic_string_view<value_type> __string_view; + + enum _LIBCPP_ENUM_VIS format : unsigned char { + auto_format, + native_format, + generic_format + }; + + // constructors and destructor + _LIBCPP_INLINE_VISIBILITY path() noexcept {} + _LIBCPP_INLINE_VISIBILITY path(const path& __p) : __pn_(__p.__pn_) {} + _LIBCPP_INLINE_VISIBILITY path(path&& __p) noexcept + : __pn_(_VSTD::move(__p.__pn_)) {} + + _LIBCPP_INLINE_VISIBILITY + path(string_type&& __s, format = format::auto_format) noexcept + : __pn_(_VSTD::move(__s)) {} + + template <class _Source, class = _EnableIfPathable<_Source, void> > + path(const _Source& __src, format = format::auto_format) { + _SourceCVT<_Source>::__append_source(__pn_, __src); + } + + template <class _InputIt> + path(_InputIt __first, _InputIt __last, format = format::auto_format) { + typedef typename iterator_traits<_InputIt>::value_type _ItVal; + _PathCVT<_ItVal>::__append_range(__pn_, __first, __last); + } + +/* +#if !defined(_LIBCPP_HAS_NO_LOCALIZATION) + // TODO Implement locale conversions. + template <class _Source, class = _EnableIfPathable<_Source, void> > + path(const _Source& __src, const locale& __loc, format = format::auto_format); + template <class _InputIt> + path(_InputIt __first, _InputIt _last, const locale& __loc, + format = format::auto_format); +#endif +*/ + + _LIBCPP_INLINE_VISIBILITY + ~path() = default; + + // assignments + _LIBCPP_INLINE_VISIBILITY + path& operator=(const path& __p) { + __pn_ = __p.__pn_; + return *this; + } + + _LIBCPP_INLINE_VISIBILITY + path& operator=(path&& __p) noexcept { + __pn_ = _VSTD::move(__p.__pn_); + return *this; + } + + _LIBCPP_INLINE_VISIBILITY + path& operator=(string_type&& __s) noexcept { + __pn_ = _VSTD::move(__s); + return *this; + } + + _LIBCPP_INLINE_VISIBILITY + path& assign(string_type&& __s) noexcept { + __pn_ = _VSTD::move(__s); + return *this; + } + + template <class _Source> + _LIBCPP_INLINE_VISIBILITY _EnableIfPathable<_Source> + operator=(const _Source& __src) { + return this->assign(__src); + } + + template <class _Source> + _EnableIfPathable<_Source> assign(const _Source& __src) { + __pn_.clear(); + _SourceCVT<_Source>::__append_source(__pn_, __src); + return *this; + } + + template <class _InputIt> + path& assign(_InputIt __first, _InputIt __last) { + typedef typename iterator_traits<_InputIt>::value_type _ItVal; + __pn_.clear(); + _PathCVT<_ItVal>::__append_range(__pn_, __first, __last); + return *this; + } + +public: + // appends +#if defined(_LIBCPP_WIN32API) + path& operator/=(const path& __p) { + auto __p_root_name = __p.__root_name(); + auto __p_root_name_size = __p_root_name.size(); + if (__p.is_absolute() || + (!__p_root_name.empty() && __p_root_name != __string_view(root_name().__pn_))) { + __pn_ = __p.__pn_; + return *this; + } + if (__p.has_root_directory()) { + path __root_name_str = root_name(); + __pn_ = __root_name_str.native(); + __pn_ += __string_view(__p.__pn_).substr(__p_root_name_size); + return *this; + } + if (has_filename() || (!has_root_directory() && is_absolute())) + __pn_ += preferred_separator; + __pn_ += __string_view(__p.__pn_).substr(__p_root_name_size); + return *this; + } + template <class _Source> + _LIBCPP_INLINE_VISIBILITY _EnableIfPathable<_Source> + operator/=(const _Source& __src) { + return operator/=(path(__src)); + } + + template <class _Source> + _EnableIfPathable<_Source> append(const _Source& __src) { + return operator/=(path(__src)); + } + + template <class _InputIt> + path& append(_InputIt __first, _InputIt __last) { + return operator/=(path(__first, __last)); + } +#else + path& operator/=(const path& __p) { + if (__p.is_absolute()) { + __pn_ = __p.__pn_; + return *this; + } + if (has_filename()) + __pn_ += preferred_separator; + __pn_ += __p.native(); + return *this; + } + + // FIXME: Use _LIBCPP_DIAGNOSE_WARNING to produce a diagnostic when __src + // is known at compile time to be "/' since the user almost certainly intended + // to append a separator instead of overwriting the path with "/" + template <class _Source> + _LIBCPP_INLINE_VISIBILITY _EnableIfPathable<_Source> + operator/=(const _Source& __src) { + return this->append(__src); + } + + template <class _Source> + _EnableIfPathable<_Source> append(const _Source& __src) { + using _Traits = __is_pathable<_Source>; + using _CVT = _PathCVT<_SourceChar<_Source> >; + bool __source_is_absolute = __is_separator(_Traits::__first_or_null(__src)); + if (__source_is_absolute) + __pn_.clear(); + else if (has_filename()) + __pn_ += preferred_separator; + _CVT::__append_source(__pn_, __src); + return *this; + } + + template <class _InputIt> + path& append(_InputIt __first, _InputIt __last) { + typedef typename iterator_traits<_InputIt>::value_type _ItVal; + static_assert(__can_convert_char<_ItVal>::value, "Must convertible"); + using _CVT = _PathCVT<_ItVal>; + if (__first != __last && __is_separator(*__first)) + __pn_.clear(); + else if (has_filename()) + __pn_ += preferred_separator; + _CVT::__append_range(__pn_, __first, __last); + return *this; + } +#endif + + // concatenation + _LIBCPP_INLINE_VISIBILITY + path& operator+=(const path& __x) { + __pn_ += __x.__pn_; + return *this; + } + + _LIBCPP_INLINE_VISIBILITY + path& operator+=(const string_type& __x) { + __pn_ += __x; + return *this; + } + + _LIBCPP_INLINE_VISIBILITY + path& operator+=(__string_view __x) { + __pn_ += __x; + return *this; + } + + _LIBCPP_INLINE_VISIBILITY + path& operator+=(const value_type* __x) { + __pn_ += __x; + return *this; + } + + _LIBCPP_INLINE_VISIBILITY + path& operator+=(value_type __x) { + __pn_ += __x; + return *this; + } + + template <class _ECharT> + typename enable_if<__can_convert_char<_ECharT>::value, path&>::type + operator+=(_ECharT __x) { + _PathCVT<_ECharT>::__append_source(__pn_, + basic_string_view<_ECharT>(&__x, 1)); + return *this; + } + + template <class _Source> + _EnableIfPathable<_Source> operator+=(const _Source& __x) { + return this->concat(__x); + } + + template <class _Source> + _EnableIfPathable<_Source> concat(const _Source& __x) { + _SourceCVT<_Source>::__append_source(__pn_, __x); + return *this; + } + + template <class _InputIt> + path& concat(_InputIt __first, _InputIt __last) { + typedef typename iterator_traits<_InputIt>::value_type _ItVal; + _PathCVT<_ItVal>::__append_range(__pn_, __first, __last); + return *this; + } + + // modifiers + _LIBCPP_INLINE_VISIBILITY + void clear() noexcept { __pn_.clear(); } + + path& make_preferred() { +#if defined(_LIBCPP_WIN32API) + _VSTD::replace(__pn_.begin(), __pn_.end(), L'/', L'\\'); +#endif + return *this; + } + + _LIBCPP_INLINE_VISIBILITY + path& remove_filename() { + auto __fname = __filename(); + if (!__fname.empty()) + __pn_.erase(__fname.data() - __pn_.data()); + return *this; + } + + path& replace_filename(const path& __replacement) { + remove_filename(); + return (*this /= __replacement); + } + + path& replace_extension(const path& __replacement = path()); + + _LIBCPP_INLINE_VISIBILITY + void swap(path& __rhs) noexcept { __pn_.swap(__rhs.__pn_); } + + // private helper to allow reserving memory in the path + _LIBCPP_INLINE_VISIBILITY + void __reserve(size_t __s) { __pn_.reserve(__s); } + + // native format observers + _LIBCPP_INLINE_VISIBILITY + const string_type& native() const noexcept { return __pn_; } + + _LIBCPP_INLINE_VISIBILITY + const value_type* c_str() const noexcept { return __pn_.c_str(); } + + _LIBCPP_INLINE_VISIBILITY operator string_type() const { return __pn_; } + +#if defined(_LIBCPP_WIN32API) + _LIBCPP_INLINE_VISIBILITY _VSTD::wstring wstring() const { return __pn_; } + + _VSTD::wstring generic_wstring() const { + _VSTD::wstring __s; + __s.resize(__pn_.size()); + _VSTD::replace_copy(__pn_.begin(), __pn_.end(), __s.begin(), '\\', '/'); + return __s; + } + +#if !defined(_LIBCPP_HAS_NO_LOCALIZATION) + template <class _ECharT, class _Traits = char_traits<_ECharT>, + class _Allocator = allocator<_ECharT> > + basic_string<_ECharT, _Traits, _Allocator> + string(const _Allocator& __a = _Allocator()) const { + using _Str = basic_string<_ECharT, _Traits, _Allocator>; + _Str __s(__a); + __s.reserve(__pn_.size()); + _PathExport<_ECharT>::__append(__s, __pn_); + return __s; + } + + _LIBCPP_INLINE_VISIBILITY _VSTD::string string() const { + return string<char>(); + } + _LIBCPP_INLINE_VISIBILITY __u8_string u8string() const { + using _CVT = __narrow_to_utf8<sizeof(wchar_t) * __CHAR_BIT__>; + __u8_string __s; + __s.reserve(__pn_.size()); + _CVT()(back_inserter(__s), __pn_.data(), __pn_.data() + __pn_.size()); + return __s; + } + + _LIBCPP_INLINE_VISIBILITY _VSTD::u16string u16string() const { + return string<char16_t>(); + } + _LIBCPP_INLINE_VISIBILITY _VSTD::u32string u32string() const { + return string<char32_t>(); + } + + // generic format observers + template <class _ECharT, class _Traits = char_traits<_ECharT>, + class _Allocator = allocator<_ECharT> > + basic_string<_ECharT, _Traits, _Allocator> + generic_string(const _Allocator& __a = _Allocator()) const { + using _Str = basic_string<_ECharT, _Traits, _Allocator>; + _Str __s = string<_ECharT, _Traits, _Allocator>(__a); + // Note: This (and generic_u8string below) is slightly suboptimal as + // it iterates twice over the string; once to convert it to the right + // character type, and once to replace path delimiters. + _VSTD::replace(__s.begin(), __s.end(), + static_cast<_ECharT>('\\'), static_cast<_ECharT>('/')); + return __s; + } + + _VSTD::string generic_string() const { return generic_string<char>(); } + _VSTD::u16string generic_u16string() const { return generic_string<char16_t>(); } + _VSTD::u32string generic_u32string() const { return generic_string<char32_t>(); } + __u8_string generic_u8string() const { + __u8_string __s = u8string(); + _VSTD::replace(__s.begin(), __s.end(), '\\', '/'); + return __s; + } +#endif /* !_LIBCPP_HAS_NO_LOCALIZATION */ +#else /* _LIBCPP_WIN32API */ + + _LIBCPP_INLINE_VISIBILITY _VSTD::string string() const { return __pn_; } +#ifndef _LIBCPP_HAS_NO_CHAR8_T + _LIBCPP_INLINE_VISIBILITY _VSTD::u8string u8string() const { return _VSTD::u8string(__pn_.begin(), __pn_.end()); } +#else + _LIBCPP_INLINE_VISIBILITY _VSTD::string u8string() const { return __pn_; } +#endif + +#if !defined(_LIBCPP_HAS_NO_LOCALIZATION) + template <class _ECharT, class _Traits = char_traits<_ECharT>, + class _Allocator = allocator<_ECharT> > + basic_string<_ECharT, _Traits, _Allocator> + string(const _Allocator& __a = _Allocator()) const { + using _CVT = __widen_from_utf8<sizeof(_ECharT) * __CHAR_BIT__>; + using _Str = basic_string<_ECharT, _Traits, _Allocator>; + _Str __s(__a); + __s.reserve(__pn_.size()); + _CVT()(back_inserter(__s), __pn_.data(), __pn_.data() + __pn_.size()); + return __s; + } + +#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS + _LIBCPP_INLINE_VISIBILITY _VSTD::wstring wstring() const { + return string<wchar_t>(); + } +#endif + _LIBCPP_INLINE_VISIBILITY _VSTD::u16string u16string() const { + return string<char16_t>(); + } + _LIBCPP_INLINE_VISIBILITY _VSTD::u32string u32string() const { + return string<char32_t>(); + } +#endif /* !_LIBCPP_HAS_NO_LOCALIZATION */ + + // generic format observers + _VSTD::string generic_string() const { return __pn_; } +#ifndef _LIBCPP_HAS_NO_CHAR8_T + _VSTD::u8string generic_u8string() const { return _VSTD::u8string(__pn_.begin(), __pn_.end()); } +#else + _VSTD::string generic_u8string() const { return __pn_; } +#endif + +#if !defined(_LIBCPP_HAS_NO_LOCALIZATION) + template <class _ECharT, class _Traits = char_traits<_ECharT>, + class _Allocator = allocator<_ECharT> > + basic_string<_ECharT, _Traits, _Allocator> + generic_string(const _Allocator& __a = _Allocator()) const { + return string<_ECharT, _Traits, _Allocator>(__a); + } + +#ifndef _LIBCPP_HAS_NO_WIDE_CHARACTERS + _VSTD::wstring generic_wstring() const { return string<wchar_t>(); } +#endif + _VSTD::u16string generic_u16string() const { return string<char16_t>(); } + _VSTD::u32string generic_u32string() const { return string<char32_t>(); } +#endif /* !_LIBCPP_HAS_NO_LOCALIZATION */ +#endif /* !_LIBCPP_WIN32API */ + +private: + int __compare(__string_view) const; + __string_view __root_name() const; + __string_view __root_directory() const; + __string_view __root_path_raw() const; + __string_view __relative_path() const; + __string_view __parent_path() const; + __string_view __filename() const; + __string_view __stem() const; + __string_view __extension() const; + +public: + // compare + _LIBCPP_INLINE_VISIBILITY int compare(const path& __p) const noexcept { + return __compare(__p.__pn_); + } + _LIBCPP_INLINE_VISIBILITY int compare(const string_type& __s) const { + return __compare(__s); + } + _LIBCPP_INLINE_VISIBILITY int compare(__string_view __s) const { + return __compare(__s); + } + _LIBCPP_INLINE_VISIBILITY int compare(const value_type* __s) const { + return __compare(__s); + } + + // decomposition + _LIBCPP_INLINE_VISIBILITY path root_name() const { + return string_type(__root_name()); + } + _LIBCPP_INLINE_VISIBILITY path root_directory() const { + return string_type(__root_directory()); + } + _LIBCPP_INLINE_VISIBILITY path root_path() const { +#if defined(_LIBCPP_WIN32API) + return string_type(__root_path_raw()); +#else + return root_name().append(string_type(__root_directory())); +#endif + } + _LIBCPP_INLINE_VISIBILITY path relative_path() const { + return string_type(__relative_path()); + } + _LIBCPP_INLINE_VISIBILITY path parent_path() const { + return string_type(__parent_path()); + } + _LIBCPP_INLINE_VISIBILITY path filename() const { + return string_type(__filename()); + } + _LIBCPP_INLINE_VISIBILITY path stem() const { return string_type(__stem()); } + _LIBCPP_INLINE_VISIBILITY path extension() const { + return string_type(__extension()); + } + + // query + _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY bool + empty() const noexcept { + return __pn_.empty(); + } + + _LIBCPP_INLINE_VISIBILITY bool has_root_name() const { + return !__root_name().empty(); + } + _LIBCPP_INLINE_VISIBILITY bool has_root_directory() const { + return !__root_directory().empty(); + } + _LIBCPP_INLINE_VISIBILITY bool has_root_path() const { + return !__root_path_raw().empty(); + } + _LIBCPP_INLINE_VISIBILITY bool has_relative_path() const { + return !__relative_path().empty(); + } + _LIBCPP_INLINE_VISIBILITY bool has_parent_path() const { + return !__parent_path().empty(); + } + _LIBCPP_INLINE_VISIBILITY bool has_filename() const { + return !__filename().empty(); + } + _LIBCPP_INLINE_VISIBILITY bool has_stem() const { return !__stem().empty(); } + _LIBCPP_INLINE_VISIBILITY bool has_extension() const { + return !__extension().empty(); + } + + _LIBCPP_INLINE_VISIBILITY bool is_absolute() const { +#if defined(_LIBCPP_WIN32API) + __string_view __root_name_str = __root_name(); + __string_view __root_dir = __root_directory(); + if (__root_name_str.size() == 2 && __root_name_str[1] == ':') { + // A drive letter with no root directory is relative, e.g. x:example. + return !__root_dir.empty(); + } + // If no root name, it's relative, e.g. \example is relative to the current drive + if (__root_name_str.empty()) + return false; + if (__root_name_str.size() < 3) + return false; + // A server root name, like \\server, is always absolute + if (__root_name_str[0] != '/' && __root_name_str[0] != '\\') + return false; + if (__root_name_str[1] != '/' && __root_name_str[1] != '\\') + return false; + // Seems to be a server root name + return true; +#else + return has_root_directory(); +#endif + } + _LIBCPP_INLINE_VISIBILITY bool is_relative() const { return !is_absolute(); } + + // relative paths + path lexically_normal() const; + path lexically_relative(const path& __base) const; + + _LIBCPP_INLINE_VISIBILITY path lexically_proximate(const path& __base) const { + path __result = this->lexically_relative(__base); + if (__result.native().empty()) + return *this; + return __result; + } + + // iterators + class _LIBCPP_TYPE_VIS iterator; + typedef iterator const_iterator; + + iterator begin() const; + iterator end() const; + +#if !defined(_LIBCPP_HAS_NO_LOCALIZATION) + template <class _CharT, class _Traits> + _LIBCPP_INLINE_VISIBILITY friend + typename enable_if<is_same<_CharT, value_type>::value && + is_same<_Traits, char_traits<value_type> >::value, + basic_ostream<_CharT, _Traits>&>::type + operator<<(basic_ostream<_CharT, _Traits>& __os, const path& __p) { + __os << _VSTD::__quoted(__p.native()); + return __os; + } + + template <class _CharT, class _Traits> + _LIBCPP_INLINE_VISIBILITY friend + typename enable_if<!is_same<_CharT, value_type>::value || + !is_same<_Traits, char_traits<value_type> >::value, + basic_ostream<_CharT, _Traits>&>::type + operator<<(basic_ostream<_CharT, _Traits>& __os, const path& __p) { + __os << _VSTD::__quoted(__p.string<_CharT, _Traits>()); + return __os; + } + + template <class _CharT, class _Traits> + _LIBCPP_INLINE_VISIBILITY friend basic_istream<_CharT, _Traits>& + operator>>(basic_istream<_CharT, _Traits>& __is, path& __p) { + basic_string<_CharT, _Traits> __tmp; + __is >> __quoted(__tmp); + __p = __tmp; + return __is; + } +#endif // !_LIBCPP_HAS_NO_LOCALIZATION + + friend _LIBCPP_INLINE_VISIBILITY bool operator==(const path& __lhs, const path& __rhs) noexcept { + return __lhs.__compare(__rhs.__pn_) == 0; + } + friend _LIBCPP_INLINE_VISIBILITY bool operator!=(const path& __lhs, const path& __rhs) noexcept { + return __lhs.__compare(__rhs.__pn_) != 0; + } + friend _LIBCPP_INLINE_VISIBILITY bool operator<(const path& __lhs, const path& __rhs) noexcept { + return __lhs.__compare(__rhs.__pn_) < 0; + } + friend _LIBCPP_INLINE_VISIBILITY bool operator<=(const path& __lhs, const path& __rhs) noexcept { + return __lhs.__compare(__rhs.__pn_) <= 0; + } + friend _LIBCPP_INLINE_VISIBILITY bool operator>(const path& __lhs, const path& __rhs) noexcept { + return __lhs.__compare(__rhs.__pn_) > 0; + } + friend _LIBCPP_INLINE_VISIBILITY bool operator>=(const path& __lhs, const path& __rhs) noexcept { + return __lhs.__compare(__rhs.__pn_) >= 0; + } + + friend _LIBCPP_INLINE_VISIBILITY path operator/(const path& __lhs, + const path& __rhs) { + path __result(__lhs); + __result /= __rhs; + return __result; + } +private: + inline _LIBCPP_INLINE_VISIBILITY path& + __assign_view(__string_view const& __s) noexcept { + __pn_ = string_type(__s); + return *this; + } + string_type __pn_; +}; + +inline _LIBCPP_INLINE_VISIBILITY void swap(path& __lhs, path& __rhs) noexcept { + __lhs.swap(__rhs); +} + +_LIBCPP_FUNC_VIS +size_t hash_value(const path& __p) noexcept; + +_LIBCPP_AVAILABILITY_FILESYSTEM_POP + +_LIBCPP_END_NAMESPACE_FILESYSTEM + +#endif // _LIBCPP_CXX03_LANG + +#endif // _LIBCPP___FILESYSTEM_PATH_H diff --git a/contrib/libs/cxxsupp/libcxxmsvc/include/__filesystem/path_iterator.h b/contrib/libs/cxxsupp/libcxxmsvc/include/__filesystem/path_iterator.h new file mode 100644 index 0000000000..6f2baf8f7a --- /dev/null +++ b/contrib/libs/cxxsupp/libcxxmsvc/include/__filesystem/path_iterator.h @@ -0,0 +1,134 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// 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 _LIBCPP___FILESYSTEM_PATH_ITERATOR_H +#define _LIBCPP___FILESYSTEM_PATH_ITERATOR_H + +#include <__assert> +#include <__availability> +#include <__config> +#include <__filesystem/path.h> +#include <__iterator/iterator_traits.h> +#include <cstddef> +#include <string> +#include <string_view> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +# pragma GCC system_header +#endif + +#ifndef _LIBCPP_CXX03_LANG + +_LIBCPP_BEGIN_NAMESPACE_FILESYSTEM + +_LIBCPP_AVAILABILITY_FILESYSTEM_PUSH + +class _LIBCPP_TYPE_VIS path::iterator { +public: + enum _ParserState : unsigned char { + _Singular, + _BeforeBegin, + _InRootName, + _InRootDir, + _InFilenames, + _InTrailingSep, + _AtEnd + }; + +public: + typedef input_iterator_tag iterator_category; + typedef bidirectional_iterator_tag iterator_concept; + + typedef path value_type; + typedef ptrdiff_t difference_type; + typedef const path* pointer; + typedef path reference; + +public: + _LIBCPP_INLINE_VISIBILITY + iterator() + : __stashed_elem_(), __path_ptr_(nullptr), __entry_(), + __state_(_Singular) {} + + iterator(const iterator&) = default; + ~iterator() = default; + + iterator& operator=(const iterator&) = default; + + _LIBCPP_INLINE_VISIBILITY + reference operator*() const { return __stashed_elem_; } + + _LIBCPP_INLINE_VISIBILITY + pointer operator->() const { return &__stashed_elem_; } + + _LIBCPP_INLINE_VISIBILITY + iterator& operator++() { + _LIBCPP_ASSERT(__state_ != _Singular, + "attempting to increment a singular iterator"); + _LIBCPP_ASSERT(__state_ != _AtEnd, + "attempting to increment the end iterator"); + return __increment(); + } + + _LIBCPP_INLINE_VISIBILITY + iterator operator++(int) { + iterator __it(*this); + this->operator++(); + return __it; + } + + _LIBCPP_INLINE_VISIBILITY + iterator& operator--() { + _LIBCPP_ASSERT(__state_ != _Singular, + "attempting to decrement a singular iterator"); + _LIBCPP_ASSERT(__entry_.data() != __path_ptr_->native().data(), + "attempting to decrement the begin iterator"); + return __decrement(); + } + + _LIBCPP_INLINE_VISIBILITY + iterator operator--(int) { + iterator __it(*this); + this->operator--(); + return __it; + } + +private: + friend class path; + + inline _LIBCPP_INLINE_VISIBILITY friend bool operator==(const iterator&, + const iterator&); + + iterator& __increment(); + iterator& __decrement(); + + path __stashed_elem_; + const path* __path_ptr_; + path::__string_view __entry_; + _ParserState __state_; +}; + +inline _LIBCPP_INLINE_VISIBILITY bool operator==(const path::iterator& __lhs, + const path::iterator& __rhs) { + return __lhs.__path_ptr_ == __rhs.__path_ptr_ && + __lhs.__entry_.data() == __rhs.__entry_.data(); +} + +inline _LIBCPP_INLINE_VISIBILITY bool operator!=(const path::iterator& __lhs, + const path::iterator& __rhs) { + return !(__lhs == __rhs); +} + +_LIBCPP_AVAILABILITY_FILESYSTEM_POP + +_LIBCPP_END_NAMESPACE_FILESYSTEM + +#endif // _LIBCPP_CXX03_LANG + +#endif // _LIBCPP___FILESYSTEM_PATH_ITERATOR_H diff --git a/contrib/libs/cxxsupp/libcxxmsvc/include/__filesystem/perm_options.h b/contrib/libs/cxxsupp/libcxxmsvc/include/__filesystem/perm_options.h new file mode 100644 index 0000000000..f7580a2473 --- /dev/null +++ b/contrib/libs/cxxsupp/libcxxmsvc/include/__filesystem/perm_options.h @@ -0,0 +1,77 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// 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 _LIBCPP___FILESYSTEM_PERM_OPTIONS_H +#define _LIBCPP___FILESYSTEM_PERM_OPTIONS_H + +#include <__availability> +#include <__config> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +# pragma GCC system_header +#endif + +#ifndef _LIBCPP_CXX03_LANG + +_LIBCPP_BEGIN_NAMESPACE_FILESYSTEM + +_LIBCPP_AVAILABILITY_FILESYSTEM_PUSH + +enum class _LIBCPP_ENUM_VIS perm_options : unsigned char { + replace = 1, + add = 2, + remove = 4, + nofollow = 8 +}; + +_LIBCPP_INLINE_VISIBILITY +inline constexpr perm_options operator&(perm_options _LHS, perm_options _RHS) { + return static_cast<perm_options>(static_cast<unsigned>(_LHS) & + static_cast<unsigned>(_RHS)); +} + +_LIBCPP_INLINE_VISIBILITY +inline constexpr perm_options operator|(perm_options _LHS, perm_options _RHS) { + return static_cast<perm_options>(static_cast<unsigned>(_LHS) | + static_cast<unsigned>(_RHS)); +} + +_LIBCPP_INLINE_VISIBILITY +inline constexpr perm_options operator^(perm_options _LHS, perm_options _RHS) { + return static_cast<perm_options>(static_cast<unsigned>(_LHS) ^ + static_cast<unsigned>(_RHS)); +} + +_LIBCPP_INLINE_VISIBILITY +inline constexpr perm_options operator~(perm_options _LHS) { + return static_cast<perm_options>(~static_cast<unsigned>(_LHS)); +} + +_LIBCPP_INLINE_VISIBILITY +inline perm_options& operator&=(perm_options& _LHS, perm_options _RHS) { + return _LHS = _LHS & _RHS; +} + +_LIBCPP_INLINE_VISIBILITY +inline perm_options& operator|=(perm_options& _LHS, perm_options _RHS) { + return _LHS = _LHS | _RHS; +} + +_LIBCPP_INLINE_VISIBILITY +inline perm_options& operator^=(perm_options& _LHS, perm_options _RHS) { + return _LHS = _LHS ^ _RHS; +} + +_LIBCPP_AVAILABILITY_FILESYSTEM_POP + +_LIBCPP_END_NAMESPACE_FILESYSTEM + +#endif // _LIBCPP_CXX03_LANG + +#endif // _LIBCPP___FILESYSTEM_PERM_OPTIONS_H diff --git a/contrib/libs/cxxsupp/libcxxmsvc/include/__filesystem/perms.h b/contrib/libs/cxxsupp/libcxxmsvc/include/__filesystem/perms.h new file mode 100644 index 0000000000..0e5c7ed8d2 --- /dev/null +++ b/contrib/libs/cxxsupp/libcxxmsvc/include/__filesystem/perms.h @@ -0,0 +1,95 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// 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 _LIBCPP___FILESYSTEM_PERMS_H +#define _LIBCPP___FILESYSTEM_PERMS_H + +#include <__availability> +#include <__config> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +# pragma GCC system_header +#endif + +#ifndef _LIBCPP_CXX03_LANG + +_LIBCPP_BEGIN_NAMESPACE_FILESYSTEM + +_LIBCPP_AVAILABILITY_FILESYSTEM_PUSH + +// On Windows, these permission bits map to one single readonly flag per +// file, and the executable bit is always returned as set. When setting +// permissions, as long as the write bit is set for either owner, group or +// others, the readonly flag is cleared. +enum class _LIBCPP_ENUM_VIS perms : unsigned { + none = 0, + + owner_read = 0400, + owner_write = 0200, + owner_exec = 0100, + owner_all = 0700, + + group_read = 040, + group_write = 020, + group_exec = 010, + group_all = 070, + + others_read = 04, + others_write = 02, + others_exec = 01, + others_all = 07, + + all = 0777, + + set_uid = 04000, + set_gid = 02000, + sticky_bit = 01000, + mask = 07777, + unknown = 0xFFFF, +}; + +_LIBCPP_INLINE_VISIBILITY +inline constexpr perms operator&(perms _LHS, perms _RHS) { + return static_cast<perms>(static_cast<unsigned>(_LHS) & + static_cast<unsigned>(_RHS)); +} + +_LIBCPP_INLINE_VISIBILITY +inline constexpr perms operator|(perms _LHS, perms _RHS) { + return static_cast<perms>(static_cast<unsigned>(_LHS) | + static_cast<unsigned>(_RHS)); +} + +_LIBCPP_INLINE_VISIBILITY +inline constexpr perms operator^(perms _LHS, perms _RHS) { + return static_cast<perms>(static_cast<unsigned>(_LHS) ^ + static_cast<unsigned>(_RHS)); +} + +_LIBCPP_INLINE_VISIBILITY +inline constexpr perms operator~(perms _LHS) { + return static_cast<perms>(~static_cast<unsigned>(_LHS)); +} + +_LIBCPP_INLINE_VISIBILITY +inline perms& operator&=(perms& _LHS, perms _RHS) { return _LHS = _LHS & _RHS; } + +_LIBCPP_INLINE_VISIBILITY +inline perms& operator|=(perms& _LHS, perms _RHS) { return _LHS = _LHS | _RHS; } + +_LIBCPP_INLINE_VISIBILITY +inline perms& operator^=(perms& _LHS, perms _RHS) { return _LHS = _LHS ^ _RHS; } + +_LIBCPP_AVAILABILITY_FILESYSTEM_POP + +_LIBCPP_END_NAMESPACE_FILESYSTEM + +#endif // _LIBCPP_CXX03_LANG + +#endif // _LIBCPP___FILESYSTEM_PERMS_H diff --git a/contrib/libs/cxxsupp/libcxxmsvc/include/__filesystem/recursive_directory_iterator.h b/contrib/libs/cxxsupp/libcxxmsvc/include/__filesystem/recursive_directory_iterator.h new file mode 100644 index 0000000000..95360376fc --- /dev/null +++ b/contrib/libs/cxxsupp/libcxxmsvc/include/__filesystem/recursive_directory_iterator.h @@ -0,0 +1,185 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// 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 _LIBCPP___FILESYSTEM_RECURSIVE_DIRECTORY_ITERATOR_H +#define _LIBCPP___FILESYSTEM_RECURSIVE_DIRECTORY_ITERATOR_H + +#include <__availability> +#include <__config> +#include <__filesystem/directory_entry.h> +#include <__filesystem/directory_options.h> +#include <__filesystem/path.h> +#include <__iterator/iterator_traits.h> +#include <__memory/shared_ptr.h> +#include <__ranges/enable_borrowed_range.h> +#include <__ranges/enable_view.h> +#include <cstddef> +#include <system_error> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +# pragma GCC system_header +#endif + +#ifndef _LIBCPP_CXX03_LANG + +_LIBCPP_BEGIN_NAMESPACE_FILESYSTEM + +_LIBCPP_AVAILABILITY_FILESYSTEM_PUSH + +class recursive_directory_iterator { +public: + using value_type = directory_entry; + using difference_type = ptrdiff_t; + using pointer = directory_entry const*; + using reference = directory_entry const&; + using iterator_category = input_iterator_tag; + +public: + // constructors and destructor + _LIBCPP_INLINE_VISIBILITY + recursive_directory_iterator() noexcept : __rec_(false) {} + + _LIBCPP_INLINE_VISIBILITY + explicit recursive_directory_iterator( + const path& __p, directory_options __xoptions = directory_options::none) + : recursive_directory_iterator(__p, __xoptions, nullptr) {} + + _LIBCPP_INLINE_VISIBILITY + recursive_directory_iterator(const path& __p, directory_options __xoptions, + error_code& __ec) + : recursive_directory_iterator(__p, __xoptions, &__ec) {} + + _LIBCPP_INLINE_VISIBILITY + recursive_directory_iterator(const path& __p, error_code& __ec) + : recursive_directory_iterator(__p, directory_options::none, &__ec) {} + + recursive_directory_iterator(const recursive_directory_iterator&) = default; + recursive_directory_iterator(recursive_directory_iterator&&) = default; + + recursive_directory_iterator& + operator=(const recursive_directory_iterator&) = default; + + _LIBCPP_INLINE_VISIBILITY + recursive_directory_iterator& + operator=(recursive_directory_iterator&& __o) noexcept { + // non-default implementation provided to support self-move assign. + if (this != &__o) { + __imp_ = _VSTD::move(__o.__imp_); + __rec_ = __o.__rec_; + } + return *this; + } + + ~recursive_directory_iterator() = default; + + _LIBCPP_INLINE_VISIBILITY + const directory_entry& operator*() const { return __dereference(); } + + _LIBCPP_INLINE_VISIBILITY + const directory_entry* operator->() const { return &__dereference(); } + + recursive_directory_iterator& operator++() { return __increment(); } + + _LIBCPP_INLINE_VISIBILITY + __dir_element_proxy operator++(int) { + __dir_element_proxy __p(**this); + __increment(); + return __p; + } + + _LIBCPP_INLINE_VISIBILITY + recursive_directory_iterator& increment(error_code& __ec) { + return __increment(&__ec); + } + + _LIBCPP_FUNC_VIS directory_options options() const; + _LIBCPP_FUNC_VIS int depth() const; + + _LIBCPP_INLINE_VISIBILITY + void pop() { __pop(); } + + _LIBCPP_INLINE_VISIBILITY + void pop(error_code& __ec) { __pop(&__ec); } + + _LIBCPP_INLINE_VISIBILITY + bool recursion_pending() const { return __rec_; } + + _LIBCPP_INLINE_VISIBILITY + void disable_recursion_pending() { __rec_ = false; } + +private: + _LIBCPP_FUNC_VIS + recursive_directory_iterator(const path& __p, directory_options __opt, + error_code* __ec); + + _LIBCPP_FUNC_VIS + const directory_entry& __dereference() const; + + _LIBCPP_FUNC_VIS + bool __try_recursion(error_code* __ec); + + _LIBCPP_FUNC_VIS + void __advance(error_code* __ec = nullptr); + + _LIBCPP_FUNC_VIS + recursive_directory_iterator& __increment(error_code* __ec = nullptr); + + _LIBCPP_FUNC_VIS + void __pop(error_code* __ec = nullptr); + + inline _LIBCPP_INLINE_VISIBILITY friend bool + operator==(const recursive_directory_iterator&, + const recursive_directory_iterator&) noexcept; + + struct _LIBCPP_HIDDEN __shared_imp; + shared_ptr<__shared_imp> __imp_; + bool __rec_; +}; // class recursive_directory_iterator + +inline _LIBCPP_INLINE_VISIBILITY bool +operator==(const recursive_directory_iterator& __lhs, + const recursive_directory_iterator& __rhs) noexcept { + return __lhs.__imp_ == __rhs.__imp_; +} + +_LIBCPP_INLINE_VISIBILITY +inline bool operator!=(const recursive_directory_iterator& __lhs, + const recursive_directory_iterator& __rhs) noexcept { + return !(__lhs == __rhs); +} +// enable recursive_directory_iterator range-based for statements +inline _LIBCPP_INLINE_VISIBILITY recursive_directory_iterator +begin(recursive_directory_iterator __iter) noexcept { + return __iter; +} + +inline _LIBCPP_INLINE_VISIBILITY recursive_directory_iterator +end(recursive_directory_iterator) noexcept { + return recursive_directory_iterator(); +} + +_LIBCPP_AVAILABILITY_FILESYSTEM_POP + +_LIBCPP_END_NAMESPACE_FILESYSTEM + +#if !defined(_LIBCPP_HAS_NO_CONCEPTS) + +template <> +_LIBCPP_AVAILABILITY_FILESYSTEM +inline constexpr bool _VSTD::ranges::enable_borrowed_range<_VSTD_FS::recursive_directory_iterator> = true; + +template <> +_LIBCPP_AVAILABILITY_FILESYSTEM +inline constexpr bool _VSTD::ranges::enable_view<_VSTD_FS::recursive_directory_iterator> = true; + +#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS) + +#endif // _LIBCPP_CXX03_LANG + +#endif // _LIBCPP___FILESYSTEM_RECURSIVE_DIRECTORY_ITERATOR_H diff --git a/contrib/libs/cxxsupp/libcxxmsvc/include/__filesystem/space_info.h b/contrib/libs/cxxsupp/libcxxmsvc/include/__filesystem/space_info.h new file mode 100644 index 0000000000..d7dc03af75 --- /dev/null +++ b/contrib/libs/cxxsupp/libcxxmsvc/include/__filesystem/space_info.h @@ -0,0 +1,39 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// 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 _LIBCPP___FILESYSTEM_SPACE_INFO_H +#define _LIBCPP___FILESYSTEM_SPACE_INFO_H + +#include <__availability> +#include <__config> +#include <cstdint> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +# pragma GCC system_header +#endif + +#ifndef _LIBCPP_CXX03_LANG + +_LIBCPP_BEGIN_NAMESPACE_FILESYSTEM + +_LIBCPP_AVAILABILITY_FILESYSTEM_PUSH + +struct _LIBCPP_TYPE_VIS space_info { + uintmax_t capacity; + uintmax_t free; + uintmax_t available; +}; + +_LIBCPP_AVAILABILITY_FILESYSTEM_POP + +_LIBCPP_END_NAMESPACE_FILESYSTEM + +#endif // _LIBCPP_CXX03_LANG + +#endif // _LIBCPP___FILESYSTEM_SPACE_INFO_H diff --git a/contrib/libs/cxxsupp/libcxxmsvc/include/__filesystem/u8path.h b/contrib/libs/cxxsupp/libcxxmsvc/include/__filesystem/u8path.h new file mode 100644 index 0000000000..ee25521f28 --- /dev/null +++ b/contrib/libs/cxxsupp/libcxxmsvc/include/__filesystem/u8path.h @@ -0,0 +1,100 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// 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 _LIBCPP___FILESYSTEM_U8PATH_H +#define _LIBCPP___FILESYSTEM_U8PATH_H + +#include <__availability> +#include <__config> +#include <__filesystem/path.h> +#include <type_traits> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +# pragma GCC system_header +#endif + +#ifndef _LIBCPP_CXX03_LANG + +_LIBCPP_BEGIN_NAMESPACE_FILESYSTEM + +_LIBCPP_AVAILABILITY_FILESYSTEM_PUSH + +template <class _InputIt> +_LIBCPP_INLINE_VISIBILITY _LIBCPP_DEPRECATED_WITH_CHAR8_T + typename enable_if<__is_pathable<_InputIt>::value, path>::type + u8path(_InputIt __f, _InputIt __l) { + static_assert( +#ifndef _LIBCPP_HAS_NO_CHAR8_T + is_same<typename __is_pathable<_InputIt>::__char_type, char8_t>::value || +#endif + is_same<typename __is_pathable<_InputIt>::__char_type, char>::value, + "u8path(Iter, Iter) requires Iter have a value_type of type 'char'" + " or 'char8_t'"); +#if defined(_LIBCPP_WIN32API) + string __tmp(__f, __l); + using _CVT = __widen_from_utf8<sizeof(wchar_t) * __CHAR_BIT__>; + _VSTD::wstring __w; + __w.reserve(__tmp.size()); + _CVT()(back_inserter(__w), __tmp.data(), __tmp.data() + __tmp.size()); + return path(__w); +#else + return path(__f, __l); +#endif /* !_LIBCPP_WIN32API */ +} + +#if defined(_LIBCPP_WIN32API) +template <class _InputIt> +_LIBCPP_INLINE_VISIBILITY _LIBCPP_DEPRECATED_WITH_CHAR8_T + typename enable_if<__is_pathable<_InputIt>::value, path>::type + u8path(_InputIt __f, _NullSentinel) { + static_assert( +#ifndef _LIBCPP_HAS_NO_CHAR8_T + is_same<typename __is_pathable<_InputIt>::__char_type, char8_t>::value || +#endif + is_same<typename __is_pathable<_InputIt>::__char_type, char>::value, + "u8path(Iter, Iter) requires Iter have a value_type of type 'char'" + " or 'char8_t'"); + string __tmp; + const char __sentinel = char{}; + for (; *__f != __sentinel; ++__f) + __tmp.push_back(*__f); + using _CVT = __widen_from_utf8<sizeof(wchar_t) * __CHAR_BIT__>; + _VSTD::wstring __w; + __w.reserve(__tmp.size()); + _CVT()(back_inserter(__w), __tmp.data(), __tmp.data() + __tmp.size()); + return path(__w); +} +#endif /* _LIBCPP_WIN32API */ + +template <class _Source> +_LIBCPP_INLINE_VISIBILITY _LIBCPP_DEPRECATED_WITH_CHAR8_T + typename enable_if<__is_pathable<_Source>::value, path>::type + u8path(const _Source& __s) { + static_assert( +#ifndef _LIBCPP_HAS_NO_CHAR8_T + is_same<typename __is_pathable<_Source>::__char_type, char8_t>::value || +#endif + is_same<typename __is_pathable<_Source>::__char_type, char>::value, + "u8path(Source const&) requires Source have a character type of type " + "'char' or 'char8_t'"); +#if defined(_LIBCPP_WIN32API) + using _Traits = __is_pathable<_Source>; + return u8path(_VSTD::__unwrap_iter(_Traits::__range_begin(__s)), _VSTD::__unwrap_iter(_Traits::__range_end(__s))); +#else + return path(__s); +#endif +} + +_LIBCPP_AVAILABILITY_FILESYSTEM_POP + +_LIBCPP_END_NAMESPACE_FILESYSTEM + +#endif // _LIBCPP_CXX03_LANG + +#endif // _LIBCPP___FILESYSTEM_U8PATH_H diff --git a/contrib/libs/cxxsupp/libcxxmsvc/include/__functional/is_transparent.h b/contrib/libs/cxxsupp/libcxxmsvc/include/__functional/is_transparent.h new file mode 100644 index 0000000000..74326c76c1 --- /dev/null +++ b/contrib/libs/cxxsupp/libcxxmsvc/include/__functional/is_transparent.h @@ -0,0 +1,36 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// 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 _LIBCPP___FUNCTIONAL_IS_TRANSPARENT +#define _LIBCPP___FUNCTIONAL_IS_TRANSPARENT + +#include <__config> +#include <type_traits> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +# pragma GCC system_header +#endif + +_LIBCPP_BEGIN_NAMESPACE_STD + +#if _LIBCPP_STD_VER > 11 + +template <class _Tp, class, class = void> +struct __is_transparent : false_type {}; + +template <class _Tp, class _Up> +struct __is_transparent<_Tp, _Up, + typename __void_t<typename _Tp::is_transparent>::type> + : true_type {}; + +#endif + +_LIBCPP_END_NAMESPACE_STD + +#endif // _LIBCPP___FUNCTIONAL_IS_TRANSPARENT diff --git a/contrib/libs/cxxsupp/libcxxmsvc/include/__node_handle b/contrib/libs/cxxsupp/libcxxmsvc/include/__node_handle new file mode 100644 index 0000000000..71309be62f --- /dev/null +++ b/contrib/libs/cxxsupp/libcxxmsvc/include/__node_handle @@ -0,0 +1,253 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// 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 _LIBCPP___NODE_HANDLE +#define _LIBCPP___NODE_HANDLE + +/* + +template<unspecified> +class node-handle { +public: + using value_type = see below; // not present for map containers + using key_type = see below; // not present for set containers + using mapped_type = see below; // not present for set containers + using allocator_type = see below; + +private: + using container_node_type = unspecified; // exposition only + using ator_traits = allocator_traits<allocator_type>; // exposition only + + typename ator_traits::template + rebind_traits<container_node_type>::pointer ptr_; // exposition only + optional<allocator_type> alloc_; // exposition only + +public: + // [container.node.cons], constructors, copy, and assignment + constexpr node-handle() noexcept : ptr_(), alloc_() {} + node-handle(node-handle&&) noexcept; + node-handle& operator=(node-handle&&); + + // [container.node.dtor], destructor + ~node-handle(); + + // [container.node.observers], observers + value_type& value() const; // not present for map containers + key_type& key() const; // not present for set containers + mapped_type& mapped() const; // not present for set containers + + allocator_type get_allocator() const; + explicit operator bool() const noexcept; + [[nodiscard]] bool empty() const noexcept; // nodiscard since C++20 + + // [container.node.modifiers], modifiers + void swap(node-handle&) + noexcept(ator_traits::propagate_on_container_swap::value || + ator_traits::is_always_equal::value); + + friend void swap(node-handle& x, node-handle& y) noexcept(noexcept(x.swap(y))) { + x.swap(y); + } +}; + +*/ + +#include <__assert> +#include <__config> +#include <memory> +#include <optional> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +# pragma GCC system_header +#endif + +_LIBCPP_BEGIN_NAMESPACE_STD + +#if _LIBCPP_STD_VER > 14 + +// Specialized in __tree & __hash_table for their _NodeType. +template <class _NodeType, class _Alloc> +struct __generic_container_node_destructor; + +template <class _NodeType, class _Alloc, + template <class, class> class _MapOrSetSpecifics> +class _LIBCPP_TEMPLATE_VIS __basic_node_handle + : public _MapOrSetSpecifics< + _NodeType, + __basic_node_handle<_NodeType, _Alloc, _MapOrSetSpecifics>> +{ + template <class _Tp, class _Compare, class _Allocator> + friend class __tree; + template <class _Tp, class _Hash, class _Equal, class _Allocator> + friend class __hash_table; + friend struct _MapOrSetSpecifics< + _NodeType, __basic_node_handle<_NodeType, _Alloc, _MapOrSetSpecifics>>; + + typedef allocator_traits<_Alloc> __alloc_traits; + typedef typename __rebind_pointer<typename __alloc_traits::void_pointer, + _NodeType>::type + __node_pointer_type; + +public: + typedef _Alloc allocator_type; + +private: + __node_pointer_type __ptr_ = nullptr; + optional<allocator_type> __alloc_; + + _LIBCPP_INLINE_VISIBILITY + void __release_ptr() + { + __ptr_ = nullptr; + __alloc_ = _VSTD::nullopt; + } + + _LIBCPP_INLINE_VISIBILITY + void __destroy_node_pointer() + { + if (__ptr_ != nullptr) + { + typedef typename __allocator_traits_rebind< + allocator_type, _NodeType>::type __node_alloc_type; + __node_alloc_type __alloc(*__alloc_); + __generic_container_node_destructor<_NodeType, __node_alloc_type>( + __alloc, true)(__ptr_); + __ptr_ = nullptr; + } + } + + _LIBCPP_INLINE_VISIBILITY + __basic_node_handle(__node_pointer_type __ptr, + allocator_type const& __alloc) + : __ptr_(__ptr), __alloc_(__alloc) + { + } + +public: + _LIBCPP_INLINE_VISIBILITY + __basic_node_handle() = default; + + _LIBCPP_INLINE_VISIBILITY + __basic_node_handle(__basic_node_handle&& __other) noexcept + : __ptr_(__other.__ptr_), + __alloc_(_VSTD::move(__other.__alloc_)) + { + __other.__ptr_ = nullptr; + __other.__alloc_ = _VSTD::nullopt; + } + + _LIBCPP_INLINE_VISIBILITY + __basic_node_handle& operator=(__basic_node_handle&& __other) + { + _LIBCPP_ASSERT( + __alloc_ == _VSTD::nullopt || + __alloc_traits::propagate_on_container_move_assignment::value || + __alloc_ == __other.__alloc_, + "node_type with incompatible allocator passed to " + "node_type::operator=(node_type&&)"); + + __destroy_node_pointer(); + __ptr_ = __other.__ptr_; + + if (__alloc_traits::propagate_on_container_move_assignment::value || + __alloc_ == _VSTD::nullopt) + __alloc_ = _VSTD::move(__other.__alloc_); + + __other.__ptr_ = nullptr; + __other.__alloc_ = _VSTD::nullopt; + + return *this; + } + + _LIBCPP_INLINE_VISIBILITY + allocator_type get_allocator() const { return *__alloc_; } + + _LIBCPP_INLINE_VISIBILITY + explicit operator bool() const { return __ptr_ != nullptr; } + + _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY + bool empty() const { return __ptr_ == nullptr; } + + _LIBCPP_INLINE_VISIBILITY + void swap(__basic_node_handle& __other) noexcept( + __alloc_traits::propagate_on_container_swap::value || + __alloc_traits::is_always_equal::value) + { + using _VSTD::swap; + swap(__ptr_, __other.__ptr_); + if (__alloc_traits::propagate_on_container_swap::value || + __alloc_ == _VSTD::nullopt || __other.__alloc_ == _VSTD::nullopt) + swap(__alloc_, __other.__alloc_); + } + + _LIBCPP_INLINE_VISIBILITY + friend void swap(__basic_node_handle& __a, __basic_node_handle& __b) + noexcept(noexcept(__a.swap(__b))) { __a.swap(__b); } + + _LIBCPP_INLINE_VISIBILITY + ~__basic_node_handle() + { + __destroy_node_pointer(); + } +}; + +template <class _NodeType, class _Derived> +struct __set_node_handle_specifics +{ + typedef typename _NodeType::__node_value_type value_type; + + _LIBCPP_INLINE_VISIBILITY + value_type& value() const + { + return static_cast<_Derived const*>(this)->__ptr_->__value_; + } +}; + +template <class _NodeType, class _Derived> +struct __map_node_handle_specifics +{ + typedef typename _NodeType::__node_value_type::key_type key_type; + typedef typename _NodeType::__node_value_type::mapped_type mapped_type; + + _LIBCPP_INLINE_VISIBILITY + key_type& key() const + { + return static_cast<_Derived const*>(this)-> + __ptr_->__value_.__ref().first; + } + + _LIBCPP_INLINE_VISIBILITY + mapped_type& mapped() const + { + return static_cast<_Derived const*>(this)-> + __ptr_->__value_.__ref().second; + } +}; + +template <class _NodeType, class _Alloc> +using __set_node_handle = + __basic_node_handle< _NodeType, _Alloc, __set_node_handle_specifics>; + +template <class _NodeType, class _Alloc> +using __map_node_handle = + __basic_node_handle< _NodeType, _Alloc, __map_node_handle_specifics>; + +template <class _Iterator, class _NodeType> +struct _LIBCPP_TEMPLATE_VIS __insert_return_type +{ + _Iterator position; + bool inserted; + _NodeType node; +}; + +#endif // _LIBCPP_STD_VER > 14 + +_LIBCPP_END_NAMESPACE_STD + +#endif // _LIBCPP___NODE_HANDLE diff --git a/contrib/libs/cxxsupp/libcxxmsvc/include/__numeric/accumulate.h b/contrib/libs/cxxsupp/libcxxmsvc/include/__numeric/accumulate.h new file mode 100644 index 0000000000..fa759872ce --- /dev/null +++ b/contrib/libs/cxxsupp/libcxxmsvc/include/__numeric/accumulate.h @@ -0,0 +1,52 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// 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 _LIBCPP___NUMERIC_ACCUMULATE_H +#define _LIBCPP___NUMERIC_ACCUMULATE_H + +#include <__config> +#include <__utility/move.h> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +# pragma GCC system_header +#endif + +_LIBCPP_BEGIN_NAMESPACE_STD + +template <class _InputIterator, class _Tp> +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 +_Tp +accumulate(_InputIterator __first, _InputIterator __last, _Tp __init) +{ + for (; __first != __last; ++__first) +#if _LIBCPP_STD_VER > 17 + __init = _VSTD::move(__init) + *__first; +#else + __init = __init + *__first; +#endif + return __init; +} + +template <class _InputIterator, class _Tp, class _BinaryOperation> +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 +_Tp +accumulate(_InputIterator __first, _InputIterator __last, _Tp __init, _BinaryOperation __binary_op) +{ + for (; __first != __last; ++__first) +#if _LIBCPP_STD_VER > 17 + __init = __binary_op(_VSTD::move(__init), *__first); +#else + __init = __binary_op(__init, *__first); +#endif + return __init; +} + +_LIBCPP_END_NAMESPACE_STD + +#endif // _LIBCPP___NUMERIC_ACCUMULATE_H diff --git a/contrib/libs/cxxsupp/libcxxmsvc/include/__numeric/adjacent_difference.h b/contrib/libs/cxxsupp/libcxxmsvc/include/__numeric/adjacent_difference.h new file mode 100644 index 0000000000..5c712ecdf7 --- /dev/null +++ b/contrib/libs/cxxsupp/libcxxmsvc/include/__numeric/adjacent_difference.h @@ -0,0 +1,72 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// 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 _LIBCPP___NUMERIC_ADJACENT_DIFFERENCE_H +#define _LIBCPP___NUMERIC_ADJACENT_DIFFERENCE_H + +#include <__config> +#include <__iterator/iterator_traits.h> +#include <__utility/move.h> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +# pragma GCC system_header +#endif + +_LIBCPP_BEGIN_NAMESPACE_STD + +template <class _InputIterator, class _OutputIterator> +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 +_OutputIterator +adjacent_difference(_InputIterator __first, _InputIterator __last, _OutputIterator __result) +{ + if (__first != __last) + { + typename iterator_traits<_InputIterator>::value_type __acc(*__first); + *__result = __acc; + for (++__first, (void) ++__result; __first != __last; ++__first, (void) ++__result) + { + typename iterator_traits<_InputIterator>::value_type __val(*__first); +#if _LIBCPP_STD_VER > 17 + *__result = __val - _VSTD::move(__acc); +#else + *__result = __val - __acc; +#endif + __acc = _VSTD::move(__val); + } + } + return __result; +} + +template <class _InputIterator, class _OutputIterator, class _BinaryOperation> +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 +_OutputIterator +adjacent_difference(_InputIterator __first, _InputIterator __last, _OutputIterator __result, + _BinaryOperation __binary_op) +{ + if (__first != __last) + { + typename iterator_traits<_InputIterator>::value_type __acc(*__first); + *__result = __acc; + for (++__first, (void) ++__result; __first != __last; ++__first, (void) ++__result) + { + typename iterator_traits<_InputIterator>::value_type __val(*__first); +#if _LIBCPP_STD_VER > 17 + *__result = __binary_op(__val, _VSTD::move(__acc)); +#else + *__result = __binary_op(__val, __acc); +#endif + __acc = _VSTD::move(__val); + } + } + return __result; +} + +_LIBCPP_END_NAMESPACE_STD + +#endif // _LIBCPP___NUMERIC_ADJACENT_DIFFERENCE_H diff --git a/contrib/libs/cxxsupp/libcxxmsvc/include/__numeric/exclusive_scan.h b/contrib/libs/cxxsupp/libcxxmsvc/include/__numeric/exclusive_scan.h new file mode 100644 index 0000000000..c0c89b3880 --- /dev/null +++ b/contrib/libs/cxxsupp/libcxxmsvc/include/__numeric/exclusive_scan.h @@ -0,0 +1,53 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// 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 _LIBCPP___NUMERIC_EXCLUSIVE_SCAN_H +#define _LIBCPP___NUMERIC_EXCLUSIVE_SCAN_H + +#include <__config> +#include <__functional/operations.h> +#include <__utility/move.h> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +# pragma GCC system_header +#endif + +_LIBCPP_BEGIN_NAMESPACE_STD + +#if _LIBCPP_STD_VER > 14 + +template <class _InputIterator, class _OutputIterator, class _Tp, class _BinaryOp> +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 _OutputIterator +exclusive_scan(_InputIterator __first, _InputIterator __last, _OutputIterator __result, _Tp __init, _BinaryOp __b) { + if (__first != __last) { + _Tp __tmp(__b(__init, *__first)); + while (true) { + *__result = _VSTD::move(__init); + ++__result; + ++__first; + if (__first == __last) + break; + __init = _VSTD::move(__tmp); + __tmp = __b(__init, *__first); + } + } + return __result; +} + +template <class _InputIterator, class _OutputIterator, class _Tp> +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 _OutputIterator +exclusive_scan(_InputIterator __first, _InputIterator __last, _OutputIterator __result, _Tp __init) { + return _VSTD::exclusive_scan(__first, __last, __result, __init, _VSTD::plus<>()); +} + +#endif // _LIBCPP_STD_VER > 14 + +_LIBCPP_END_NAMESPACE_STD + +#endif // _LIBCPP___NUMERIC_EXCLUSIVE_SCAN_H diff --git a/contrib/libs/cxxsupp/libcxxmsvc/include/__numeric/gcd_lcm.h b/contrib/libs/cxxsupp/libcxxmsvc/include/__numeric/gcd_lcm.h new file mode 100644 index 0000000000..9a53a001f2 --- /dev/null +++ b/contrib/libs/cxxsupp/libcxxmsvc/include/__numeric/gcd_lcm.h @@ -0,0 +1,96 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// 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 _LIBCPP___NUMERIC_GCD_LCM_H +#define _LIBCPP___NUMERIC_GCD_LCM_H + +#include <__assert> +#include <__config> +#include <limits> +#include <type_traits> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +# pragma GCC system_header +#endif + +_LIBCPP_PUSH_MACROS +#include <__undef_macros> + +_LIBCPP_BEGIN_NAMESPACE_STD + +#if _LIBCPP_STD_VER > 14 + +template <typename _Result, typename _Source, bool _IsSigned = is_signed<_Source>::value> struct __ct_abs; + +template <typename _Result, typename _Source> +struct __ct_abs<_Result, _Source, true> { + _LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY + _Result operator()(_Source __t) const noexcept + { + if (__t >= 0) return __t; + if (__t == numeric_limits<_Source>::min()) return -static_cast<_Result>(__t); + return -__t; + } +}; + +template <typename _Result, typename _Source> +struct __ct_abs<_Result, _Source, false> { + _LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY + _Result operator()(_Source __t) const noexcept { return __t; } +}; + + +template<class _Tp> +_LIBCPP_CONSTEXPR _LIBCPP_HIDDEN +_Tp __gcd(_Tp __m, _Tp __n) +{ + static_assert((!is_signed<_Tp>::value), ""); + return __n == 0 ? __m : _VSTD::__gcd<_Tp>(__n, __m % __n); +} + +template<class _Tp, class _Up> +_LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY +common_type_t<_Tp,_Up> +gcd(_Tp __m, _Up __n) +{ + static_assert((is_integral<_Tp>::value && is_integral<_Up>::value), "Arguments to gcd must be integer types"); + static_assert((!is_same<typename remove_cv<_Tp>::type, bool>::value), "First argument to gcd cannot be bool" ); + static_assert((!is_same<typename remove_cv<_Up>::type, bool>::value), "Second argument to gcd cannot be bool" ); + using _Rp = common_type_t<_Tp,_Up>; + using _Wp = make_unsigned_t<_Rp>; + return static_cast<_Rp>(_VSTD::__gcd( + static_cast<_Wp>(__ct_abs<_Rp, _Tp>()(__m)), + static_cast<_Wp>(__ct_abs<_Rp, _Up>()(__n)))); +} + +template<class _Tp, class _Up> +_LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY +common_type_t<_Tp,_Up> +lcm(_Tp __m, _Up __n) +{ + static_assert((is_integral<_Tp>::value && is_integral<_Up>::value), "Arguments to lcm must be integer types"); + static_assert((!is_same<typename remove_cv<_Tp>::type, bool>::value), "First argument to lcm cannot be bool" ); + static_assert((!is_same<typename remove_cv<_Up>::type, bool>::value), "Second argument to lcm cannot be bool" ); + if (__m == 0 || __n == 0) + return 0; + + using _Rp = common_type_t<_Tp,_Up>; + _Rp __val1 = __ct_abs<_Rp, _Tp>()(__m) / _VSTD::gcd(__m, __n); + _Rp __val2 = __ct_abs<_Rp, _Up>()(__n); + _LIBCPP_ASSERT((numeric_limits<_Rp>::max() / __val1 > __val2), "Overflow in lcm"); + return __val1 * __val2; +} + +#endif // _LIBCPP_STD_VER + +_LIBCPP_END_NAMESPACE_STD + +_LIBCPP_POP_MACROS + +#endif // _LIBCPP___NUMERIC_GCD_LCM_H diff --git a/contrib/libs/cxxsupp/libcxxmsvc/include/__numeric/inclusive_scan.h b/contrib/libs/cxxsupp/libcxxmsvc/include/__numeric/inclusive_scan.h new file mode 100644 index 0000000000..a6b0050758 --- /dev/null +++ b/contrib/libs/cxxsupp/libcxxmsvc/include/__numeric/inclusive_scan.h @@ -0,0 +1,60 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// 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 _LIBCPP___NUMERIC_INCLUSIVE_SCAN_H +#define _LIBCPP___NUMERIC_INCLUSIVE_SCAN_H + +#include <__config> +#include <__functional/operations.h> +#include <__iterator/iterator_traits.h> +#include <__utility/move.h> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +# pragma GCC system_header +#endif + +_LIBCPP_BEGIN_NAMESPACE_STD + +#if _LIBCPP_STD_VER > 14 + +template <class _InputIterator, class _OutputIterator, class _Tp, class _BinaryOp> +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 _OutputIterator +inclusive_scan(_InputIterator __first, _InputIterator __last, _OutputIterator __result, _BinaryOp __b, _Tp __init) { + for (; __first != __last; ++__first, (void)++__result) { + __init = __b(__init, *__first); + *__result = __init; + } + return __result; +} + +template <class _InputIterator, class _OutputIterator, class _BinaryOp> +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 _OutputIterator +inclusive_scan(_InputIterator __first, _InputIterator __last, _OutputIterator __result, _BinaryOp __b) { + if (__first != __last) { + typename iterator_traits<_InputIterator>::value_type __init = *__first; + *__result++ = __init; + if (++__first != __last) + return _VSTD::inclusive_scan(__first, __last, __result, __b, __init); + } + + return __result; +} + +template <class _InputIterator, class _OutputIterator> +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 _OutputIterator inclusive_scan(_InputIterator __first, + _InputIterator __last, + _OutputIterator __result) { + return _VSTD::inclusive_scan(__first, __last, __result, _VSTD::plus<>()); +} + +#endif // _LIBCPP_STD_VER > 14 + +_LIBCPP_END_NAMESPACE_STD + +#endif // _LIBCPP___NUMERIC_INCLUSIVE_SCAN_H diff --git a/contrib/libs/cxxsupp/libcxxmsvc/include/__numeric/inner_product.h b/contrib/libs/cxxsupp/libcxxmsvc/include/__numeric/inner_product.h new file mode 100644 index 0000000000..6fe18bb2b1 --- /dev/null +++ b/contrib/libs/cxxsupp/libcxxmsvc/include/__numeric/inner_product.h @@ -0,0 +1,53 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// 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 _LIBCPP___NUMERIC_INNER_PRODUCT_H +#define _LIBCPP___NUMERIC_INNER_PRODUCT_H + +#include <__config> +#include <__utility/move.h> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +# pragma GCC system_header +#endif + +_LIBCPP_BEGIN_NAMESPACE_STD + +template <class _InputIterator1, class _InputIterator2, class _Tp> +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 +_Tp +inner_product(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2, _Tp __init) +{ + for (; __first1 != __last1; ++__first1, (void) ++__first2) +#if _LIBCPP_STD_VER > 17 + __init = _VSTD::move(__init) + *__first1 * *__first2; +#else + __init = __init + *__first1 * *__first2; +#endif + return __init; +} + +template <class _InputIterator1, class _InputIterator2, class _Tp, class _BinaryOperation1, class _BinaryOperation2> +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 +_Tp +inner_product(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2, + _Tp __init, _BinaryOperation1 __binary_op1, _BinaryOperation2 __binary_op2) +{ + for (; __first1 != __last1; ++__first1, (void) ++__first2) +#if _LIBCPP_STD_VER > 17 + __init = __binary_op1(_VSTD::move(__init), __binary_op2(*__first1, *__first2)); +#else + __init = __binary_op1(__init, __binary_op2(*__first1, *__first2)); +#endif + return __init; +} + +_LIBCPP_END_NAMESPACE_STD + +#endif // _LIBCPP___NUMERIC_INNER_PRODUCT_H diff --git a/contrib/libs/cxxsupp/libcxxmsvc/include/__numeric/iota.h b/contrib/libs/cxxsupp/libcxxmsvc/include/__numeric/iota.h new file mode 100644 index 0000000000..b30e0e0a54 --- /dev/null +++ b/contrib/libs/cxxsupp/libcxxmsvc/include/__numeric/iota.h @@ -0,0 +1,32 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// 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 _LIBCPP___NUMERIC_IOTA_H +#define _LIBCPP___NUMERIC_IOTA_H + +#include <__config> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +# pragma GCC system_header +#endif + +_LIBCPP_BEGIN_NAMESPACE_STD + +template <class _ForwardIterator, class _Tp> +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 +void +iota(_ForwardIterator __first, _ForwardIterator __last, _Tp __value_) +{ + for (; __first != __last; ++__first, (void) ++__value_) + *__first = __value_; +} + +_LIBCPP_END_NAMESPACE_STD + +#endif // _LIBCPP___NUMERIC_IOTA_H diff --git a/contrib/libs/cxxsupp/libcxxmsvc/include/__numeric/midpoint.h b/contrib/libs/cxxsupp/libcxxmsvc/include/__numeric/midpoint.h new file mode 100644 index 0000000000..668030c46b --- /dev/null +++ b/contrib/libs/cxxsupp/libcxxmsvc/include/__numeric/midpoint.h @@ -0,0 +1,85 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// 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 _LIBCPP___NUMERIC_MIDPOINT_H +#define _LIBCPP___NUMERIC_MIDPOINT_H + +#include <__config> +#include <limits> +#include <type_traits> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +# pragma GCC system_header +#endif + +_LIBCPP_PUSH_MACROS +#include <__undef_macros> + +_LIBCPP_BEGIN_NAMESPACE_STD + +#if _LIBCPP_STD_VER > 17 +template <class _Tp> +_LIBCPP_INLINE_VISIBILITY constexpr +enable_if_t<is_integral_v<_Tp> && !is_same_v<bool, _Tp> && !is_null_pointer_v<_Tp>, _Tp> +midpoint(_Tp __a, _Tp __b) noexcept +_LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK +{ + using _Up = make_unsigned_t<_Tp>; + constexpr _Up __bitshift = numeric_limits<_Up>::digits - 1; + + _Up __diff = _Up(__b) - _Up(__a); + _Up __sign_bit = __b < __a; + + _Up __half_diff = (__diff / 2) + (__sign_bit << __bitshift) + (__sign_bit & __diff); + + return __a + __half_diff; +} + + +template <class _TPtr> +_LIBCPP_INLINE_VISIBILITY constexpr +enable_if_t<is_pointer_v<_TPtr> + && is_object_v<remove_pointer_t<_TPtr>> + && ! is_void_v<remove_pointer_t<_TPtr>> + && (sizeof(remove_pointer_t<_TPtr>) > 0), _TPtr> +midpoint(_TPtr __a, _TPtr __b) noexcept +{ + return __a + _VSTD::midpoint(ptrdiff_t(0), __b - __a); +} + + +template <typename _Tp> +constexpr int __sign(_Tp __val) { + return (_Tp(0) < __val) - (__val < _Tp(0)); +} + +template <typename _Fp> +constexpr _Fp __fp_abs(_Fp __f) { return __f >= 0 ? __f : -__f; } + +template <class _Fp> +_LIBCPP_INLINE_VISIBILITY constexpr +enable_if_t<is_floating_point_v<_Fp>, _Fp> +midpoint(_Fp __a, _Fp __b) noexcept +{ + constexpr _Fp __lo = numeric_limits<_Fp>::min()*2; + constexpr _Fp __hi = numeric_limits<_Fp>::max()/2; + return __fp_abs(__a) <= __hi && __fp_abs(__b) <= __hi ? // typical case: overflow is impossible + (__a + __b)/2 : // always correctly rounded + __fp_abs(__a) < __lo ? __a + __b/2 : // not safe to halve a + __fp_abs(__b) < __lo ? __a/2 + __b : // not safe to halve b + __a/2 + __b/2; // otherwise correctly rounded +} + +#endif // _LIBCPP_STD_VER > 17 + +_LIBCPP_END_NAMESPACE_STD + +_LIBCPP_POP_MACROS + +#endif // _LIBCPP___NUMERIC_MIDPOINT_H diff --git a/contrib/libs/cxxsupp/libcxxmsvc/include/__numeric/partial_sum.h b/contrib/libs/cxxsupp/libcxxmsvc/include/__numeric/partial_sum.h new file mode 100644 index 0000000000..9acee3afc2 --- /dev/null +++ b/contrib/libs/cxxsupp/libcxxmsvc/include/__numeric/partial_sum.h @@ -0,0 +1,70 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// 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 _LIBCPP___NUMERIC_PARTIAL_SUM_H +#define _LIBCPP___NUMERIC_PARTIAL_SUM_H + +#include <__config> +#include <__iterator/iterator_traits.h> +#include <__utility/move.h> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +# pragma GCC system_header +#endif + +_LIBCPP_BEGIN_NAMESPACE_STD + +template <class _InputIterator, class _OutputIterator> +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 +_OutputIterator +partial_sum(_InputIterator __first, _InputIterator __last, _OutputIterator __result) +{ + if (__first != __last) + { + typename iterator_traits<_InputIterator>::value_type __t(*__first); + *__result = __t; + for (++__first, (void) ++__result; __first != __last; ++__first, (void) ++__result) + { +#if _LIBCPP_STD_VER > 17 + __t = _VSTD::move(__t) + *__first; +#else + __t = __t + *__first; +#endif + *__result = __t; + } + } + return __result; +} + +template <class _InputIterator, class _OutputIterator, class _BinaryOperation> +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 +_OutputIterator +partial_sum(_InputIterator __first, _InputIterator __last, _OutputIterator __result, + _BinaryOperation __binary_op) +{ + if (__first != __last) + { + typename iterator_traits<_InputIterator>::value_type __t(*__first); + *__result = __t; + for (++__first, (void) ++__result; __first != __last; ++__first, (void) ++__result) + { +#if _LIBCPP_STD_VER > 17 + __t = __binary_op(_VSTD::move(__t), *__first); +#else + __t = __binary_op(__t, *__first); +#endif + *__result = __t; + } + } + return __result; +} + +_LIBCPP_END_NAMESPACE_STD + +#endif // _LIBCPP___NUMERIC_PARTIAL_SUM_H diff --git a/contrib/libs/cxxsupp/libcxxmsvc/include/__numeric/reduce.h b/contrib/libs/cxxsupp/libcxxmsvc/include/__numeric/reduce.h new file mode 100644 index 0000000000..90e4d238d8 --- /dev/null +++ b/contrib/libs/cxxsupp/libcxxmsvc/include/__numeric/reduce.h @@ -0,0 +1,47 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// 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 _LIBCPP___NUMERIC_REDUCE_H +#define _LIBCPP___NUMERIC_REDUCE_H + +#include <__config> +#include <__functional/operations.h> +#include <__iterator/iterator_traits.h> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +# pragma GCC system_header +#endif + +_LIBCPP_BEGIN_NAMESPACE_STD + +#if _LIBCPP_STD_VER > 14 +template <class _InputIterator, class _Tp, class _BinaryOp> +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 _Tp reduce(_InputIterator __first, _InputIterator __last, + _Tp __init, _BinaryOp __b) { + for (; __first != __last; ++__first) + __init = __b(__init, *__first); + return __init; +} + +template <class _InputIterator, class _Tp> +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 _Tp reduce(_InputIterator __first, _InputIterator __last, + _Tp __init) { + return _VSTD::reduce(__first, __last, __init, _VSTD::plus<>()); +} + +template <class _InputIterator> +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 typename iterator_traits<_InputIterator>::value_type +reduce(_InputIterator __first, _InputIterator __last) { + return _VSTD::reduce(__first, __last, typename iterator_traits<_InputIterator>::value_type{}); +} +#endif + +_LIBCPP_END_NAMESPACE_STD + +#endif // _LIBCPP___NUMERIC_REDUCE_H diff --git a/contrib/libs/cxxsupp/libcxxmsvc/include/__numeric/transform_exclusive_scan.h b/contrib/libs/cxxsupp/libcxxmsvc/include/__numeric/transform_exclusive_scan.h new file mode 100644 index 0000000000..45b3077f66 --- /dev/null +++ b/contrib/libs/cxxsupp/libcxxmsvc/include/__numeric/transform_exclusive_scan.h @@ -0,0 +1,49 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// 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 _LIBCPP___NUMERIC_TRANSFORM_EXCLUSIVE_SCAN_H +#define _LIBCPP___NUMERIC_TRANSFORM_EXCLUSIVE_SCAN_H + +#include <__config> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +# pragma GCC system_header +#endif + +_LIBCPP_BEGIN_NAMESPACE_STD + +#if _LIBCPP_STD_VER > 14 + +template <class _InputIterator, class _OutputIterator, class _Tp, + class _BinaryOp, class _UnaryOp> +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 +_OutputIterator +transform_exclusive_scan(_InputIterator __first, _InputIterator __last, + _OutputIterator __result, _Tp __init, + _BinaryOp __b, _UnaryOp __u) +{ + if (__first != __last) + { + _Tp __saved = __init; + do + { + __init = __b(__init, __u(*__first)); + *__result = __saved; + __saved = __init; + ++__result; + } while (++__first != __last); + } + return __result; +} + +#endif // _LIBCPP_STD_VER > 14 + +_LIBCPP_END_NAMESPACE_STD + +#endif // _LIBCPP___NUMERIC_TRANSFORM_EXCLUSIVE_SCAN_H diff --git a/contrib/libs/cxxsupp/libcxxmsvc/include/__numeric/transform_inclusive_scan.h b/contrib/libs/cxxsupp/libcxxmsvc/include/__numeric/transform_inclusive_scan.h new file mode 100644 index 0000000000..b0d4ab5a88 --- /dev/null +++ b/contrib/libs/cxxsupp/libcxxmsvc/include/__numeric/transform_inclusive_scan.h @@ -0,0 +1,58 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// 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 _LIBCPP___NUMERIC_TRANSFORM_INCLUSIVE_SCAN_H +#define _LIBCPP___NUMERIC_TRANSFORM_INCLUSIVE_SCAN_H + +#include <__config> +#include <__iterator/iterator_traits.h> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +# pragma GCC system_header +#endif + +_LIBCPP_BEGIN_NAMESPACE_STD + +#if _LIBCPP_STD_VER > 14 + +template <class _InputIterator, class _OutputIterator, class _Tp, class _BinaryOp, class _UnaryOp> +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 +_OutputIterator +transform_inclusive_scan(_InputIterator __first, _InputIterator __last, + _OutputIterator __result, _BinaryOp __b, _UnaryOp __u, _Tp __init) +{ + for (; __first != __last; ++__first, (void) ++__result) { + __init = __b(__init, __u(*__first)); + *__result = __init; + } + + return __result; +} + +template <class _InputIterator, class _OutputIterator, class _BinaryOp, class _UnaryOp> +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 +_OutputIterator +transform_inclusive_scan(_InputIterator __first, _InputIterator __last, + _OutputIterator __result, _BinaryOp __b, _UnaryOp __u) +{ + if (__first != __last) { + typename iterator_traits<_InputIterator>::value_type __init = __u(*__first); + *__result++ = __init; + if (++__first != __last) + return _VSTD::transform_inclusive_scan(__first, __last, __result, __b, __u, __init); + } + + return __result; +} + +#endif // _LIBCPP_STD_VER > 14 + +_LIBCPP_END_NAMESPACE_STD + +#endif // _LIBCPP___NUMERIC_TRANSFORM_INCLUSIVE_SCAN_H diff --git a/contrib/libs/cxxsupp/libcxxmsvc/include/__numeric/transform_reduce.h b/contrib/libs/cxxsupp/libcxxmsvc/include/__numeric/transform_reduce.h new file mode 100644 index 0000000000..da5a77988c --- /dev/null +++ b/contrib/libs/cxxsupp/libcxxmsvc/include/__numeric/transform_reduce.h @@ -0,0 +1,54 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// 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 _LIBCPP___NUMERIC_TRANSFORM_REDUCE_H +#define _LIBCPP___NUMERIC_TRANSFORM_REDUCE_H + +#include <__config> +#include <__functional/operations.h> +#include <__utility/move.h> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +# pragma GCC system_header +#endif + +_LIBCPP_BEGIN_NAMESPACE_STD + +#if _LIBCPP_STD_VER > 14 +template <class _InputIterator, class _Tp, class _BinaryOp, class _UnaryOp> +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 _Tp transform_reduce(_InputIterator __first, + _InputIterator __last, _Tp __init, + _BinaryOp __b, _UnaryOp __u) { + for (; __first != __last; ++__first) + __init = __b(__init, __u(*__first)); + return __init; +} + +template <class _InputIterator1, class _InputIterator2, class _Tp, class _BinaryOp1, class _BinaryOp2> +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 _Tp transform_reduce(_InputIterator1 __first1, + _InputIterator1 __last1, + _InputIterator2 __first2, _Tp __init, + _BinaryOp1 __b1, _BinaryOp2 __b2) { + for (; __first1 != __last1; ++__first1, (void)++__first2) + __init = __b1(__init, __b2(*__first1, *__first2)); + return __init; +} + +template <class _InputIterator1, class _InputIterator2, class _Tp> +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 _Tp transform_reduce(_InputIterator1 __first1, + _InputIterator1 __last1, + _InputIterator2 __first2, _Tp __init) { + return _VSTD::transform_reduce(__first1, __last1, __first2, _VSTD::move(__init), _VSTD::plus<>(), + _VSTD::multiplies<>()); +} +#endif + +_LIBCPP_END_NAMESPACE_STD + +#endif // _LIBCPP___NUMERIC_TRANSFORM_REDUCE_H diff --git a/contrib/libs/cxxsupp/libcxxmsvc/include/__random/bernoulli_distribution.h b/contrib/libs/cxxsupp/libcxxmsvc/include/__random/bernoulli_distribution.h new file mode 100644 index 0000000000..cf019519ab --- /dev/null +++ b/contrib/libs/cxxsupp/libcxxmsvc/include/__random/bernoulli_distribution.h @@ -0,0 +1,143 @@ +//===----------------------------------------------------------------------===// +// +// 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 _LIBCPP___RANDOM_BERNOULLI_DISTRIBUTION_H +#define _LIBCPP___RANDOM_BERNOULLI_DISTRIBUTION_H + +#include <__config> +#include <__random/uniform_real_distribution.h> +#include <iosfwd> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +# pragma GCC system_header +#endif + +_LIBCPP_PUSH_MACROS +#include <__undef_macros> + +_LIBCPP_BEGIN_NAMESPACE_STD + +class _LIBCPP_TEMPLATE_VIS bernoulli_distribution +{ +public: + // types + typedef bool result_type; + + class _LIBCPP_TEMPLATE_VIS param_type + { + double __p_; + public: + typedef bernoulli_distribution distribution_type; + + _LIBCPP_INLINE_VISIBILITY + explicit param_type(double __p = 0.5) : __p_(__p) {} + + _LIBCPP_INLINE_VISIBILITY + double p() const {return __p_;} + + friend _LIBCPP_INLINE_VISIBILITY + bool operator==(const param_type& __x, const param_type& __y) + {return __x.__p_ == __y.__p_;} + friend _LIBCPP_INLINE_VISIBILITY + bool operator!=(const param_type& __x, const param_type& __y) + {return !(__x == __y);} + }; + +private: + param_type __p_; + +public: + // constructors and reset functions +#ifndef _LIBCPP_CXX03_LANG + _LIBCPP_INLINE_VISIBILITY + bernoulli_distribution() : bernoulli_distribution(0.5) {} + _LIBCPP_INLINE_VISIBILITY + explicit bernoulli_distribution(double __p) : __p_(param_type(__p)) {} +#else + _LIBCPP_INLINE_VISIBILITY + explicit bernoulli_distribution(double __p = 0.5) : __p_(param_type(__p)) {} +#endif + _LIBCPP_INLINE_VISIBILITY + explicit bernoulli_distribution(const param_type& __p) : __p_(__p) {} + _LIBCPP_INLINE_VISIBILITY + void reset() {} + + // generating functions + template<class _URNG> + _LIBCPP_INLINE_VISIBILITY + result_type operator()(_URNG& __g) + {return (*this)(__g, __p_);} + template<class _URNG> _LIBCPP_INLINE_VISIBILITY result_type operator()(_URNG& __g, const param_type& __p); + + // property functions + _LIBCPP_INLINE_VISIBILITY + double p() const {return __p_.p();} + + _LIBCPP_INLINE_VISIBILITY + param_type param() const {return __p_;} + _LIBCPP_INLINE_VISIBILITY + void param(const param_type& __p) {__p_ = __p;} + + _LIBCPP_INLINE_VISIBILITY + result_type min() const {return false;} + _LIBCPP_INLINE_VISIBILITY + result_type max() const {return true;} + + friend _LIBCPP_INLINE_VISIBILITY + bool operator==(const bernoulli_distribution& __x, + const bernoulli_distribution& __y) + {return __x.__p_ == __y.__p_;} + friend _LIBCPP_INLINE_VISIBILITY + bool operator!=(const bernoulli_distribution& __x, + const bernoulli_distribution& __y) + {return !(__x == __y);} +}; + +template<class _URNG> +inline +bernoulli_distribution::result_type +bernoulli_distribution::operator()(_URNG& __g, const param_type& __p) +{ + uniform_real_distribution<double> __gen; + return __gen(__g) < __p.p(); +} + +template <class _CharT, class _Traits> +basic_ostream<_CharT, _Traits>& +operator<<(basic_ostream<_CharT, _Traits>& __os, const bernoulli_distribution& __x) +{ + __save_flags<_CharT, _Traits> __lx(__os); + typedef basic_ostream<_CharT, _Traits> _OStream; + __os.flags(_OStream::dec | _OStream::left | _OStream::fixed | + _OStream::scientific); + _CharT __sp = __os.widen(' '); + __os.fill(__sp); + return __os << __x.p(); +} + +template <class _CharT, class _Traits> +basic_istream<_CharT, _Traits>& +operator>>(basic_istream<_CharT, _Traits>& __is, bernoulli_distribution& __x) +{ + typedef bernoulli_distribution _Eng; + typedef typename _Eng::param_type param_type; + __save_flags<_CharT, _Traits> __lx(__is); + typedef basic_istream<_CharT, _Traits> _Istream; + __is.flags(_Istream::dec | _Istream::skipws); + double __p; + __is >> __p; + if (!__is.fail()) + __x.param(param_type(__p)); + return __is; +} + +_LIBCPP_END_NAMESPACE_STD + +_LIBCPP_POP_MACROS + +#endif // _LIBCPP___RANDOM_BERNOULLI_DISTRIBUTION_H diff --git a/contrib/libs/cxxsupp/libcxxmsvc/include/__random/binomial_distribution.h b/contrib/libs/cxxsupp/libcxxmsvc/include/__random/binomial_distribution.h new file mode 100644 index 0000000000..77df98cba0 --- /dev/null +++ b/contrib/libs/cxxsupp/libcxxmsvc/include/__random/binomial_distribution.h @@ -0,0 +1,225 @@ +//===----------------------------------------------------------------------===// +// +// 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 _LIBCPP___RANDOM_BINOMIAL_DISTRIBUTION_H +#define _LIBCPP___RANDOM_BINOMIAL_DISTRIBUTION_H + +#include <__config> +#include <__random/uniform_real_distribution.h> +#include <cmath> +#include <iosfwd> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +# pragma GCC system_header +#endif + +_LIBCPP_PUSH_MACROS +#include <__undef_macros> + +_LIBCPP_BEGIN_NAMESPACE_STD + +template<class _IntType = int> +class _LIBCPP_TEMPLATE_VIS binomial_distribution +{ +public: + // types + typedef _IntType result_type; + + class _LIBCPP_TEMPLATE_VIS param_type + { + result_type __t_; + double __p_; + double __pr_; + double __odds_ratio_; + result_type __r0_; + public: + typedef binomial_distribution distribution_type; + + explicit param_type(result_type __t = 1, double __p = 0.5); + + _LIBCPP_INLINE_VISIBILITY + result_type t() const {return __t_;} + _LIBCPP_INLINE_VISIBILITY + double p() const {return __p_;} + + friend _LIBCPP_INLINE_VISIBILITY + bool operator==(const param_type& __x, const param_type& __y) + {return __x.__t_ == __y.__t_ && __x.__p_ == __y.__p_;} + friend _LIBCPP_INLINE_VISIBILITY + bool operator!=(const param_type& __x, const param_type& __y) + {return !(__x == __y);} + + friend class binomial_distribution; + }; + +private: + param_type __p_; + +public: + // constructors and reset functions +#ifndef _LIBCPP_CXX03_LANG + _LIBCPP_INLINE_VISIBILITY + binomial_distribution() : binomial_distribution(1) {} + _LIBCPP_INLINE_VISIBILITY + explicit binomial_distribution(result_type __t, double __p = 0.5) + : __p_(param_type(__t, __p)) {} +#else + _LIBCPP_INLINE_VISIBILITY + explicit binomial_distribution(result_type __t = 1, double __p = 0.5) + : __p_(param_type(__t, __p)) {} +#endif + _LIBCPP_INLINE_VISIBILITY + explicit binomial_distribution(const param_type& __p) : __p_(__p) {} + _LIBCPP_INLINE_VISIBILITY + void reset() {} + + // generating functions + template<class _URNG> + _LIBCPP_INLINE_VISIBILITY + result_type operator()(_URNG& __g) + {return (*this)(__g, __p_);} + template<class _URNG> result_type operator()(_URNG& __g, const param_type& __p); + + // property functions + _LIBCPP_INLINE_VISIBILITY + result_type t() const {return __p_.t();} + _LIBCPP_INLINE_VISIBILITY + double p() const {return __p_.p();} + + _LIBCPP_INLINE_VISIBILITY + param_type param() const {return __p_;} + _LIBCPP_INLINE_VISIBILITY + void param(const param_type& __p) {__p_ = __p;} + + _LIBCPP_INLINE_VISIBILITY + result_type min() const {return 0;} + _LIBCPP_INLINE_VISIBILITY + result_type max() const {return t();} + + friend _LIBCPP_INLINE_VISIBILITY + bool operator==(const binomial_distribution& __x, + const binomial_distribution& __y) + {return __x.__p_ == __y.__p_;} + friend _LIBCPP_INLINE_VISIBILITY + bool operator!=(const binomial_distribution& __x, + const binomial_distribution& __y) + {return !(__x == __y);} +}; + +#ifndef _LIBCPP_MSVCRT_LIKE +extern "C" double lgamma_r(double, int *); +#endif + +inline _LIBCPP_INLINE_VISIBILITY double __libcpp_lgamma(double __d) { +#if defined(_LIBCPP_MSVCRT_LIKE) + return lgamma(__d); +#else + int __sign; + return lgamma_r(__d, &__sign); +#endif +} + +template<class _IntType> +binomial_distribution<_IntType>::param_type::param_type(result_type __t, double __p) + : __t_(__t), __p_(__p) +{ + if (0 < __p_ && __p_ < 1) + { + __r0_ = static_cast<result_type>((__t_ + 1) * __p_); + __pr_ = _VSTD::exp(__libcpp_lgamma(__t_ + 1.) - + __libcpp_lgamma(__r0_ + 1.) - + __libcpp_lgamma(__t_ - __r0_ + 1.) + __r0_ * _VSTD::log(__p_) + + (__t_ - __r0_) * _VSTD::log(1 - __p_)); + __odds_ratio_ = __p_ / (1 - __p_); + } +} + +// Reference: Kemp, C.D. (1986). `A modal method for generating binomial +// variables', Commun. Statist. - Theor. Meth. 15(3), 805-813. +template<class _IntType> +template<class _URNG> +_IntType +binomial_distribution<_IntType>::operator()(_URNG& __g, const param_type& __pr) +{ + if (__pr.__t_ == 0 || __pr.__p_ == 0) + return 0; + if (__pr.__p_ == 1) + return __pr.__t_; + uniform_real_distribution<double> __gen; + double __u = __gen(__g) - __pr.__pr_; + if (__u < 0) + return __pr.__r0_; + double __pu = __pr.__pr_; + double __pd = __pu; + result_type __ru = __pr.__r0_; + result_type __rd = __ru; + while (true) + { + bool __break = true; + if (__rd >= 1) + { + __pd *= __rd / (__pr.__odds_ratio_ * (__pr.__t_ - __rd + 1)); + __u -= __pd; + __break = false; + if (__u < 0) + return __rd - 1; + } + if ( __rd != 0 ) + --__rd; + ++__ru; + if (__ru <= __pr.__t_) + { + __pu *= (__pr.__t_ - __ru + 1) * __pr.__odds_ratio_ / __ru; + __u -= __pu; + __break = false; + if (__u < 0) + return __ru; + } + if (__break) + return 0; + } +} + +template <class _CharT, class _Traits, class _IntType> +basic_ostream<_CharT, _Traits>& +operator<<(basic_ostream<_CharT, _Traits>& __os, + const binomial_distribution<_IntType>& __x) +{ + __save_flags<_CharT, _Traits> __lx(__os); + typedef basic_ostream<_CharT, _Traits> _OStream; + __os.flags(_OStream::dec | _OStream::left | _OStream::fixed | + _OStream::scientific); + _CharT __sp = __os.widen(' '); + __os.fill(__sp); + return __os << __x.t() << __sp << __x.p(); +} + +template <class _CharT, class _Traits, class _IntType> +basic_istream<_CharT, _Traits>& +operator>>(basic_istream<_CharT, _Traits>& __is, + binomial_distribution<_IntType>& __x) +{ + typedef binomial_distribution<_IntType> _Eng; + typedef typename _Eng::result_type result_type; + typedef typename _Eng::param_type param_type; + __save_flags<_CharT, _Traits> __lx(__is); + typedef basic_istream<_CharT, _Traits> _Istream; + __is.flags(_Istream::dec | _Istream::skipws); + result_type __t; + double __p; + __is >> __t >> __p; + if (!__is.fail()) + __x.param(param_type(__t, __p)); + return __is; +} + +_LIBCPP_END_NAMESPACE_STD + +_LIBCPP_POP_MACROS + +#endif // _LIBCPP___RANDOM_BINOMIAL_DISTRIBUTION_H diff --git a/contrib/libs/cxxsupp/libcxxmsvc/include/__random/cauchy_distribution.h b/contrib/libs/cxxsupp/libcxxmsvc/include/__random/cauchy_distribution.h new file mode 100644 index 0000000000..288118e1d2 --- /dev/null +++ b/contrib/libs/cxxsupp/libcxxmsvc/include/__random/cauchy_distribution.h @@ -0,0 +1,162 @@ +//===----------------------------------------------------------------------===// +// +// 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 _LIBCPP___RANDOM_CAUCHY_DISTRIBUTION_H +#define _LIBCPP___RANDOM_CAUCHY_DISTRIBUTION_H + +#include <__config> +#include <__random/uniform_real_distribution.h> +#include <cmath> +#include <iosfwd> +#include <limits> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +# pragma GCC system_header +#endif + +_LIBCPP_PUSH_MACROS +#include <__undef_macros> + +_LIBCPP_BEGIN_NAMESPACE_STD + +template<class _RealType = double> +class _LIBCPP_TEMPLATE_VIS cauchy_distribution +{ +public: + // types + typedef _RealType result_type; + + class _LIBCPP_TEMPLATE_VIS param_type + { + result_type __a_; + result_type __b_; + public: + typedef cauchy_distribution distribution_type; + + _LIBCPP_INLINE_VISIBILITY + explicit param_type(result_type __a = 0, result_type __b = 1) + : __a_(__a), __b_(__b) {} + + _LIBCPP_INLINE_VISIBILITY + result_type a() const {return __a_;} + _LIBCPP_INLINE_VISIBILITY + result_type b() const {return __b_;} + + friend _LIBCPP_INLINE_VISIBILITY + bool operator==(const param_type& __x, const param_type& __y) + {return __x.__a_ == __y.__a_ && __x.__b_ == __y.__b_;} + friend _LIBCPP_INLINE_VISIBILITY + bool operator!=(const param_type& __x, const param_type& __y) + {return !(__x == __y);} + }; + +private: + param_type __p_; + +public: + // constructor and reset functions +#ifndef _LIBCPP_CXX03_LANG + _LIBCPP_INLINE_VISIBILITY + cauchy_distribution() : cauchy_distribution(0) {} + _LIBCPP_INLINE_VISIBILITY + explicit cauchy_distribution(result_type __a, result_type __b = 1) + : __p_(param_type(__a, __b)) {} +#else + _LIBCPP_INLINE_VISIBILITY + explicit cauchy_distribution(result_type __a = 0, result_type __b = 1) + : __p_(param_type(__a, __b)) {} +#endif + _LIBCPP_INLINE_VISIBILITY + explicit cauchy_distribution(const param_type& __p) + : __p_(__p) {} + _LIBCPP_INLINE_VISIBILITY + void reset() {} + + // generating functions + template<class _URNG> + _LIBCPP_INLINE_VISIBILITY + result_type operator()(_URNG& __g) + {return (*this)(__g, __p_);} + template<class _URNG> _LIBCPP_INLINE_VISIBILITY result_type operator()(_URNG& __g, const param_type& __p); + + // property functions + _LIBCPP_INLINE_VISIBILITY + result_type a() const {return __p_.a();} + _LIBCPP_INLINE_VISIBILITY + result_type b() const {return __p_.b();} + + _LIBCPP_INLINE_VISIBILITY + param_type param() const {return __p_;} + _LIBCPP_INLINE_VISIBILITY + void param(const param_type& __p) {__p_ = __p;} + + _LIBCPP_INLINE_VISIBILITY + result_type min() const {return -numeric_limits<result_type>::infinity();} + _LIBCPP_INLINE_VISIBILITY + result_type max() const {return numeric_limits<result_type>::infinity();} + + friend _LIBCPP_INLINE_VISIBILITY + bool operator==(const cauchy_distribution& __x, + const cauchy_distribution& __y) + {return __x.__p_ == __y.__p_;} + friend _LIBCPP_INLINE_VISIBILITY + bool operator!=(const cauchy_distribution& __x, + const cauchy_distribution& __y) + {return !(__x == __y);} +}; + +template <class _RealType> +template<class _URNG> +inline +_RealType +cauchy_distribution<_RealType>::operator()(_URNG& __g, const param_type& __p) +{ + uniform_real_distribution<result_type> __gen; + // purposefully let tan arg get as close to pi/2 as it wants, tan will return a finite + return __p.a() + __p.b() * _VSTD::tan(3.1415926535897932384626433832795 * __gen(__g)); +} + +template <class _CharT, class _Traits, class _RT> +basic_ostream<_CharT, _Traits>& +operator<<(basic_ostream<_CharT, _Traits>& __os, + const cauchy_distribution<_RT>& __x) +{ + __save_flags<_CharT, _Traits> __lx(__os); + typedef basic_ostream<_CharT, _Traits> _OStream; + __os.flags(_OStream::dec | _OStream::left | _OStream::fixed | + _OStream::scientific); + _CharT __sp = __os.widen(' '); + __os.fill(__sp); + __os << __x.a() << __sp << __x.b(); + return __os; +} + +template <class _CharT, class _Traits, class _RT> +basic_istream<_CharT, _Traits>& +operator>>(basic_istream<_CharT, _Traits>& __is, + cauchy_distribution<_RT>& __x) +{ + typedef cauchy_distribution<_RT> _Eng; + typedef typename _Eng::result_type result_type; + typedef typename _Eng::param_type param_type; + __save_flags<_CharT, _Traits> __lx(__is); + typedef basic_istream<_CharT, _Traits> _Istream; + __is.flags(_Istream::dec | _Istream::skipws); + result_type __a; + result_type __b; + __is >> __a >> __b; + if (!__is.fail()) + __x.param(param_type(__a, __b)); + return __is; +} + +_LIBCPP_END_NAMESPACE_STD + +_LIBCPP_POP_MACROS + +#endif // _LIBCPP___RANDOM_CAUCHY_DISTRIBUTION_H diff --git a/contrib/libs/cxxsupp/libcxxmsvc/include/__random/chi_squared_distribution.h b/contrib/libs/cxxsupp/libcxxmsvc/include/__random/chi_squared_distribution.h new file mode 100644 index 0000000000..b98488c20d --- /dev/null +++ b/contrib/libs/cxxsupp/libcxxmsvc/include/__random/chi_squared_distribution.h @@ -0,0 +1,144 @@ +//===----------------------------------------------------------------------===// +// +// 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 _LIBCPP___RANDOM_CHI_SQUARED_DISTRIBUTION_H +#define _LIBCPP___RANDOM_CHI_SQUARED_DISTRIBUTION_H + +#include <__config> +#include <__random/gamma_distribution.h> +#include <iosfwd> +#include <limits> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +# pragma GCC system_header +#endif + +_LIBCPP_PUSH_MACROS +#include <__undef_macros> + +_LIBCPP_BEGIN_NAMESPACE_STD + +template<class _RealType = double> +class _LIBCPP_TEMPLATE_VIS chi_squared_distribution +{ +public: + // types + typedef _RealType result_type; + + class _LIBCPP_TEMPLATE_VIS param_type + { + result_type __n_; + public: + typedef chi_squared_distribution distribution_type; + + _LIBCPP_INLINE_VISIBILITY + explicit param_type(result_type __n = 1) : __n_(__n) {} + + _LIBCPP_INLINE_VISIBILITY + result_type n() const {return __n_;} + + friend _LIBCPP_INLINE_VISIBILITY + bool operator==(const param_type& __x, const param_type& __y) + {return __x.__n_ == __y.__n_;} + friend _LIBCPP_INLINE_VISIBILITY + bool operator!=(const param_type& __x, const param_type& __y) + {return !(__x == __y);} + }; + +private: + param_type __p_; + +public: + // constructor and reset functions +#ifndef _LIBCPP_CXX03_LANG + _LIBCPP_INLINE_VISIBILITY + chi_squared_distribution() : chi_squared_distribution(1) {} + _LIBCPP_INLINE_VISIBILITY + explicit chi_squared_distribution(result_type __n) + : __p_(param_type(__n)) {} +#else + _LIBCPP_INLINE_VISIBILITY + explicit chi_squared_distribution(result_type __n = 1) + : __p_(param_type(__n)) {} +#endif + _LIBCPP_INLINE_VISIBILITY + explicit chi_squared_distribution(const param_type& __p) + : __p_(__p) {} + _LIBCPP_INLINE_VISIBILITY + void reset() {} + + // generating functions + template<class _URNG> + _LIBCPP_INLINE_VISIBILITY + result_type operator()(_URNG& __g) + {return (*this)(__g, __p_);} + template<class _URNG> + _LIBCPP_INLINE_VISIBILITY + result_type operator()(_URNG& __g, const param_type& __p) + {return gamma_distribution<result_type>(__p.n() / 2, 2)(__g);} + + // property functions + _LIBCPP_INLINE_VISIBILITY + result_type n() const {return __p_.n();} + + _LIBCPP_INLINE_VISIBILITY + param_type param() const {return __p_;} + _LIBCPP_INLINE_VISIBILITY + void param(const param_type& __p) {__p_ = __p;} + + _LIBCPP_INLINE_VISIBILITY + result_type min() const {return 0;} + _LIBCPP_INLINE_VISIBILITY + result_type max() const {return numeric_limits<result_type>::infinity();} + + friend _LIBCPP_INLINE_VISIBILITY + bool operator==(const chi_squared_distribution& __x, + const chi_squared_distribution& __y) + {return __x.__p_ == __y.__p_;} + friend _LIBCPP_INLINE_VISIBILITY + bool operator!=(const chi_squared_distribution& __x, + const chi_squared_distribution& __y) + {return !(__x == __y);} +}; + +template <class _CharT, class _Traits, class _RT> +basic_ostream<_CharT, _Traits>& +operator<<(basic_ostream<_CharT, _Traits>& __os, + const chi_squared_distribution<_RT>& __x) +{ + __save_flags<_CharT, _Traits> __lx(__os); + typedef basic_ostream<_CharT, _Traits> _OStream; + __os.flags(_OStream::dec | _OStream::left | _OStream::fixed | + _OStream::scientific); + __os << __x.n(); + return __os; +} + +template <class _CharT, class _Traits, class _RT> +basic_istream<_CharT, _Traits>& +operator>>(basic_istream<_CharT, _Traits>& __is, + chi_squared_distribution<_RT>& __x) +{ + typedef chi_squared_distribution<_RT> _Eng; + typedef typename _Eng::result_type result_type; + typedef typename _Eng::param_type param_type; + __save_flags<_CharT, _Traits> __lx(__is); + typedef basic_istream<_CharT, _Traits> _Istream; + __is.flags(_Istream::dec | _Istream::skipws); + result_type __n; + __is >> __n; + if (!__is.fail()) + __x.param(param_type(__n)); + return __is; +} + +_LIBCPP_END_NAMESPACE_STD + +_LIBCPP_POP_MACROS + +#endif // _LIBCPP___RANDOM_CHI_SQUARED_DISTRIBUTION_H diff --git a/contrib/libs/cxxsupp/libcxxmsvc/include/__random/clamp_to_integral.h b/contrib/libs/cxxsupp/libcxxmsvc/include/__random/clamp_to_integral.h new file mode 100644 index 0000000000..7d44ff9cfc --- /dev/null +++ b/contrib/libs/cxxsupp/libcxxmsvc/include/__random/clamp_to_integral.h @@ -0,0 +1,60 @@ +//===----------------------------------------------------------------------===// +// +// 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 _LIBCPP___RANDOM_CLAMP_TO_INTEGRAL_H +#define _LIBCPP___RANDOM_CLAMP_TO_INTEGRAL_H + +#include <__config> +#include <cmath> +#include <limits> +#include <type_traits> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +# pragma GCC system_header +#endif + +_LIBCPP_PUSH_MACROS +#include <__undef_macros> + +_LIBCPP_BEGIN_NAMESPACE_STD + +template <class _IntT, class _FloatT, + bool _FloatBigger = (numeric_limits<_FloatT>::digits > numeric_limits<_IntT>::digits), + int _Bits = (numeric_limits<_IntT>::digits - numeric_limits<_FloatT>::digits)> +_LIBCPP_INLINE_VISIBILITY +_LIBCPP_CONSTEXPR _IntT __max_representable_int_for_float() _NOEXCEPT { + static_assert(is_floating_point<_FloatT>::value, "must be a floating point type"); + static_assert(is_integral<_IntT>::value, "must be an integral type"); + static_assert(numeric_limits<_FloatT>::radix == 2, "FloatT has incorrect radix"); + static_assert((_IsSame<_FloatT, float>::value || _IsSame<_FloatT, double>::value + || _IsSame<_FloatT,long double>::value), "unsupported floating point type"); + return _FloatBigger ? numeric_limits<_IntT>::max() : (numeric_limits<_IntT>::max() >> _Bits << _Bits); +} + +// Convert a floating point number to the specified integral type after +// clamping to the integral type's representable range. +// +// The behavior is undefined if `__r` is NaN. +template <class _IntT, class _RealT> +_LIBCPP_INLINE_VISIBILITY +_IntT __clamp_to_integral(_RealT __r) _NOEXCEPT { + using _Lim = numeric_limits<_IntT>; + const _IntT _MaxVal = __max_representable_int_for_float<_IntT, _RealT>(); + if (__r >= ::nextafter(static_cast<_RealT>(_MaxVal), INFINITY)) { + return _Lim::max(); + } else if (__r <= _Lim::lowest()) { + return _Lim::min(); + } + return static_cast<_IntT>(__r); +} + +_LIBCPP_END_NAMESPACE_STD + +_LIBCPP_POP_MACROS + +#endif // _LIBCPP___RANDOM_CLAMP_TO_INTEGRAL_H diff --git a/contrib/libs/cxxsupp/libcxxmsvc/include/__random/default_random_engine.h b/contrib/libs/cxxsupp/libcxxmsvc/include/__random/default_random_engine.h new file mode 100644 index 0000000000..89792f4f0d --- /dev/null +++ b/contrib/libs/cxxsupp/libcxxmsvc/include/__random/default_random_engine.h @@ -0,0 +1,25 @@ +//===----------------------------------------------------------------------===// +// +// 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 _LIBCPP___RANDOM_DEFAULT_RANDOM_ENGINE_H +#define _LIBCPP___RANDOM_DEFAULT_RANDOM_ENGINE_H + +#include <__config> +#include <__random/linear_congruential_engine.h> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +# pragma GCC system_header +#endif + +_LIBCPP_BEGIN_NAMESPACE_STD + +typedef minstd_rand default_random_engine; + +_LIBCPP_END_NAMESPACE_STD + +#endif // _LIBCPP___RANDOM_DEFAULT_RANDOM_ENGINE_H diff --git a/contrib/libs/cxxsupp/libcxxmsvc/include/__random/discard_block_engine.h b/contrib/libs/cxxsupp/libcxxmsvc/include/__random/discard_block_engine.h new file mode 100644 index 0000000000..c58d66b588 --- /dev/null +++ b/contrib/libs/cxxsupp/libcxxmsvc/include/__random/discard_block_engine.h @@ -0,0 +1,203 @@ +//===----------------------------------------------------------------------===// +// +// 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 _LIBCPP___RANDOM_DISCARD_BLOCK_ENGINE_H +#define _LIBCPP___RANDOM_DISCARD_BLOCK_ENGINE_H + +#include <__config> +#include <__random/is_seed_sequence.h> +#include <__utility/move.h> +#include <climits> +#include <iosfwd> +#include <type_traits> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +# pragma GCC system_header +#endif + +_LIBCPP_PUSH_MACROS +#include <__undef_macros> + +_LIBCPP_BEGIN_NAMESPACE_STD + +template<class _Engine, size_t __p, size_t __r> +class _LIBCPP_TEMPLATE_VIS discard_block_engine +{ + _Engine __e_; + int __n_; + + static_assert( 0 < __r, "discard_block_engine invalid parameters"); + static_assert(__r <= __p, "discard_block_engine invalid parameters"); + static_assert(__r <= INT_MAX, "discard_block_engine invalid parameters"); +public: + // types + typedef typename _Engine::result_type result_type; + + // engine characteristics + static _LIBCPP_CONSTEXPR const size_t block_size = __p; + static _LIBCPP_CONSTEXPR const size_t used_block = __r; + +#ifdef _LIBCPP_CXX03_LANG + static const result_type _Min = _Engine::_Min; + static const result_type _Max = _Engine::_Max; +#else + static _LIBCPP_CONSTEXPR const result_type _Min = _Engine::min(); + static _LIBCPP_CONSTEXPR const result_type _Max = _Engine::max(); +#endif + + _LIBCPP_INLINE_VISIBILITY + static _LIBCPP_CONSTEXPR result_type min() { return _Engine::min(); } + _LIBCPP_INLINE_VISIBILITY + static _LIBCPP_CONSTEXPR result_type max() { return _Engine::max(); } + + // constructors and seeding functions + _LIBCPP_INLINE_VISIBILITY + discard_block_engine() : __n_(0) {} + _LIBCPP_INLINE_VISIBILITY + explicit discard_block_engine(const _Engine& __e) + : __e_(__e), __n_(0) {} +#ifndef _LIBCPP_CXX03_LANG + _LIBCPP_INLINE_VISIBILITY + explicit discard_block_engine(_Engine&& __e) + : __e_(_VSTD::move(__e)), __n_(0) {} +#endif // _LIBCPP_CXX03_LANG + _LIBCPP_INLINE_VISIBILITY + explicit discard_block_engine(result_type __sd) : __e_(__sd), __n_(0) {} + template<class _Sseq> + _LIBCPP_INLINE_VISIBILITY + explicit discard_block_engine(_Sseq& __q, + typename enable_if<__is_seed_sequence<_Sseq, discard_block_engine>::value && + !is_convertible<_Sseq, _Engine>::value>::type* = 0) + : __e_(__q), __n_(0) {} + _LIBCPP_INLINE_VISIBILITY + void seed() {__e_.seed(); __n_ = 0;} + _LIBCPP_INLINE_VISIBILITY + void seed(result_type __sd) {__e_.seed(__sd); __n_ = 0;} + template<class _Sseq> + _LIBCPP_INLINE_VISIBILITY + typename enable_if + < + __is_seed_sequence<_Sseq, discard_block_engine>::value, + void + >::type + seed(_Sseq& __q) {__e_.seed(__q); __n_ = 0;} + + // generating functions + result_type operator()(); + _LIBCPP_INLINE_VISIBILITY + void discard(unsigned long long __z) {for (; __z; --__z) operator()();} + + // property functions + _LIBCPP_INLINE_VISIBILITY + const _Engine& base() const _NOEXCEPT {return __e_;} + + template<class _Eng, size_t _Pp, size_t _Rp> + friend + bool + operator==( + const discard_block_engine<_Eng, _Pp, _Rp>& __x, + const discard_block_engine<_Eng, _Pp, _Rp>& __y); + + template<class _Eng, size_t _Pp, size_t _Rp> + friend + bool + operator!=( + const discard_block_engine<_Eng, _Pp, _Rp>& __x, + const discard_block_engine<_Eng, _Pp, _Rp>& __y); + + template <class _CharT, class _Traits, + class _Eng, size_t _Pp, size_t _Rp> + friend + basic_ostream<_CharT, _Traits>& + operator<<(basic_ostream<_CharT, _Traits>& __os, + const discard_block_engine<_Eng, _Pp, _Rp>& __x); + + template <class _CharT, class _Traits, + class _Eng, size_t _Pp, size_t _Rp> + friend + basic_istream<_CharT, _Traits>& + operator>>(basic_istream<_CharT, _Traits>& __is, + discard_block_engine<_Eng, _Pp, _Rp>& __x); +}; + +template<class _Engine, size_t __p, size_t __r> + _LIBCPP_CONSTEXPR const size_t discard_block_engine<_Engine, __p, __r>::block_size; + +template<class _Engine, size_t __p, size_t __r> + _LIBCPP_CONSTEXPR const size_t discard_block_engine<_Engine, __p, __r>::used_block; + +template<class _Engine, size_t __p, size_t __r> +typename discard_block_engine<_Engine, __p, __r>::result_type +discard_block_engine<_Engine, __p, __r>::operator()() +{ + if (__n_ >= static_cast<int>(__r)) + { + __e_.discard(__p - __r); + __n_ = 0; + } + ++__n_; + return __e_(); +} + +template<class _Eng, size_t _Pp, size_t _Rp> +inline _LIBCPP_INLINE_VISIBILITY +bool +operator==(const discard_block_engine<_Eng, _Pp, _Rp>& __x, + const discard_block_engine<_Eng, _Pp, _Rp>& __y) +{ + return __x.__n_ == __y.__n_ && __x.__e_ == __y.__e_; +} + +template<class _Eng, size_t _Pp, size_t _Rp> +inline _LIBCPP_INLINE_VISIBILITY +bool +operator!=(const discard_block_engine<_Eng, _Pp, _Rp>& __x, + const discard_block_engine<_Eng, _Pp, _Rp>& __y) +{ + return !(__x == __y); +} + +template <class _CharT, class _Traits, + class _Eng, size_t _Pp, size_t _Rp> +basic_ostream<_CharT, _Traits>& +operator<<(basic_ostream<_CharT, _Traits>& __os, + const discard_block_engine<_Eng, _Pp, _Rp>& __x) +{ + __save_flags<_CharT, _Traits> __lx(__os); + typedef basic_ostream<_CharT, _Traits> _Ostream; + __os.flags(_Ostream::dec | _Ostream::left); + _CharT __sp = __os.widen(' '); + __os.fill(__sp); + return __os << __x.__e_ << __sp << __x.__n_; +} + +template <class _CharT, class _Traits, + class _Eng, size_t _Pp, size_t _Rp> +basic_istream<_CharT, _Traits>& +operator>>(basic_istream<_CharT, _Traits>& __is, + discard_block_engine<_Eng, _Pp, _Rp>& __x) +{ + __save_flags<_CharT, _Traits> __lx(__is); + typedef basic_istream<_CharT, _Traits> _Istream; + __is.flags(_Istream::dec | _Istream::skipws); + _Eng __e; + int __n; + __is >> __e >> __n; + if (!__is.fail()) + { + __x.__e_ = __e; + __x.__n_ = __n; + } + return __is; +} + +_LIBCPP_END_NAMESPACE_STD + +_LIBCPP_POP_MACROS + +#endif // _LIBCPP___RANDOM_DISCARD_BLOCK_ENGINE_H diff --git a/contrib/libs/cxxsupp/libcxxmsvc/include/__random/discrete_distribution.h b/contrib/libs/cxxsupp/libcxxmsvc/include/__random/discrete_distribution.h new file mode 100644 index 0000000000..fc19068eb0 --- /dev/null +++ b/contrib/libs/cxxsupp/libcxxmsvc/include/__random/discrete_distribution.h @@ -0,0 +1,260 @@ +//===----------------------------------------------------------------------===// +// +// 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 _LIBCPP___RANDOM_DISCRETE_DISTRIBUTION_H +#define _LIBCPP___RANDOM_DISCRETE_DISTRIBUTION_H + +#include <__algorithm/upper_bound.h> +#include <__config> +#include <__random/uniform_real_distribution.h> +#include <cstddef> +#include <iosfwd> +#include <numeric> +#include <vector> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +# pragma GCC system_header +#endif + +_LIBCPP_PUSH_MACROS +#include <__undef_macros> + +_LIBCPP_BEGIN_NAMESPACE_STD + +template<class _IntType = int> +class _LIBCPP_TEMPLATE_VIS discrete_distribution +{ +public: + // types + typedef _IntType result_type; + + class _LIBCPP_TEMPLATE_VIS param_type + { + vector<double> __p_; + public: + typedef discrete_distribution distribution_type; + + _LIBCPP_INLINE_VISIBILITY + param_type() {} + template<class _InputIterator> + _LIBCPP_INLINE_VISIBILITY + param_type(_InputIterator __f, _InputIterator __l) + : __p_(__f, __l) {__init();} +#ifndef _LIBCPP_CXX03_LANG + _LIBCPP_INLINE_VISIBILITY + param_type(initializer_list<double> __wl) + : __p_(__wl.begin(), __wl.end()) {__init();} +#endif // _LIBCPP_CXX03_LANG + template<class _UnaryOperation> + param_type(size_t __nw, double __xmin, double __xmax, + _UnaryOperation __fw); + + vector<double> probabilities() const; + + friend _LIBCPP_INLINE_VISIBILITY + bool operator==(const param_type& __x, const param_type& __y) + {return __x.__p_ == __y.__p_;} + friend _LIBCPP_INLINE_VISIBILITY + bool operator!=(const param_type& __x, const param_type& __y) + {return !(__x == __y);} + + private: + void __init(); + + friend class discrete_distribution; + + template <class _CharT, class _Traits, class _IT> + friend + basic_ostream<_CharT, _Traits>& + operator<<(basic_ostream<_CharT, _Traits>& __os, + const discrete_distribution<_IT>& __x); + + template <class _CharT, class _Traits, class _IT> + friend + basic_istream<_CharT, _Traits>& + operator>>(basic_istream<_CharT, _Traits>& __is, + discrete_distribution<_IT>& __x); + }; + +private: + param_type __p_; + +public: + // constructor and reset functions + _LIBCPP_INLINE_VISIBILITY + discrete_distribution() {} + template<class _InputIterator> + _LIBCPP_INLINE_VISIBILITY + discrete_distribution(_InputIterator __f, _InputIterator __l) + : __p_(__f, __l) {} +#ifndef _LIBCPP_CXX03_LANG + _LIBCPP_INLINE_VISIBILITY + discrete_distribution(initializer_list<double> __wl) + : __p_(__wl) {} +#endif // _LIBCPP_CXX03_LANG + template<class _UnaryOperation> + _LIBCPP_INLINE_VISIBILITY + discrete_distribution(size_t __nw, double __xmin, double __xmax, + _UnaryOperation __fw) + : __p_(__nw, __xmin, __xmax, __fw) {} + _LIBCPP_INLINE_VISIBILITY + explicit discrete_distribution(const param_type& __p) + : __p_(__p) {} + _LIBCPP_INLINE_VISIBILITY + void reset() {} + + // generating functions + template<class _URNG> + _LIBCPP_INLINE_VISIBILITY + result_type operator()(_URNG& __g) + {return (*this)(__g, __p_);} + template<class _URNG> result_type operator()(_URNG& __g, const param_type& __p); + + // property functions + _LIBCPP_INLINE_VISIBILITY + vector<double> probabilities() const {return __p_.probabilities();} + + _LIBCPP_INLINE_VISIBILITY + param_type param() const {return __p_;} + _LIBCPP_INLINE_VISIBILITY + void param(const param_type& __p) {__p_ = __p;} + + _LIBCPP_INLINE_VISIBILITY + result_type min() const {return 0;} + _LIBCPP_INLINE_VISIBILITY + result_type max() const {return __p_.__p_.size();} + + friend _LIBCPP_INLINE_VISIBILITY + bool operator==(const discrete_distribution& __x, + const discrete_distribution& __y) + {return __x.__p_ == __y.__p_;} + friend _LIBCPP_INLINE_VISIBILITY + bool operator!=(const discrete_distribution& __x, + const discrete_distribution& __y) + {return !(__x == __y);} + + template <class _CharT, class _Traits, class _IT> + friend + basic_ostream<_CharT, _Traits>& + operator<<(basic_ostream<_CharT, _Traits>& __os, + const discrete_distribution<_IT>& __x); + + template <class _CharT, class _Traits, class _IT> + friend + basic_istream<_CharT, _Traits>& + operator>>(basic_istream<_CharT, _Traits>& __is, + discrete_distribution<_IT>& __x); +}; + +template<class _IntType> +template<class _UnaryOperation> +discrete_distribution<_IntType>::param_type::param_type(size_t __nw, + double __xmin, + double __xmax, + _UnaryOperation __fw) +{ + if (__nw > 1) + { + __p_.reserve(__nw - 1); + double __d = (__xmax - __xmin) / __nw; + double __d2 = __d / 2; + for (size_t __k = 0; __k < __nw; ++__k) + __p_.push_back(__fw(__xmin + __k * __d + __d2)); + __init(); + } +} + +template<class _IntType> +void +discrete_distribution<_IntType>::param_type::__init() +{ + if (!__p_.empty()) + { + if (__p_.size() > 1) + { + double __s = _VSTD::accumulate(__p_.begin(), __p_.end(), 0.0); + for (vector<double>::iterator __i = __p_.begin(), __e = __p_.end(); __i < __e; ++__i) + *__i /= __s; + vector<double> __t(__p_.size() - 1); + _VSTD::partial_sum(__p_.begin(), __p_.end() - 1, __t.begin()); + swap(__p_, __t); + } + else + { + __p_.clear(); + __p_.shrink_to_fit(); + } + } +} + +template<class _IntType> +vector<double> +discrete_distribution<_IntType>::param_type::probabilities() const +{ + size_t __n = __p_.size(); + vector<double> __p(__n+1); + _VSTD::adjacent_difference(__p_.begin(), __p_.end(), __p.begin()); + if (__n > 0) + __p[__n] = 1 - __p_[__n-1]; + else + __p[0] = 1; + return __p; +} + +template<class _IntType> +template<class _URNG> +_IntType +discrete_distribution<_IntType>::operator()(_URNG& __g, const param_type& __p) +{ + uniform_real_distribution<double> __gen; + return static_cast<_IntType>( + _VSTD::upper_bound(__p.__p_.begin(), __p.__p_.end(), __gen(__g)) - + __p.__p_.begin()); +} + +template <class _CharT, class _Traits, class _IT> +basic_ostream<_CharT, _Traits>& +operator<<(basic_ostream<_CharT, _Traits>& __os, + const discrete_distribution<_IT>& __x) +{ + __save_flags<_CharT, _Traits> __lx(__os); + typedef basic_ostream<_CharT, _Traits> _OStream; + __os.flags(_OStream::dec | _OStream::left | _OStream::fixed | + _OStream::scientific); + _CharT __sp = __os.widen(' '); + __os.fill(__sp); + size_t __n = __x.__p_.__p_.size(); + __os << __n; + for (size_t __i = 0; __i < __n; ++__i) + __os << __sp << __x.__p_.__p_[__i]; + return __os; +} + +template <class _CharT, class _Traits, class _IT> +basic_istream<_CharT, _Traits>& +operator>>(basic_istream<_CharT, _Traits>& __is, + discrete_distribution<_IT>& __x) +{ + __save_flags<_CharT, _Traits> __lx(__is); + typedef basic_istream<_CharT, _Traits> _Istream; + __is.flags(_Istream::dec | _Istream::skipws); + size_t __n; + __is >> __n; + vector<double> __p(__n); + for (size_t __i = 0; __i < __n; ++__i) + __is >> __p[__i]; + if (!__is.fail()) + swap(__x.__p_.__p_, __p); + return __is; +} + +_LIBCPP_END_NAMESPACE_STD + +_LIBCPP_POP_MACROS + +#endif // _LIBCPP___RANDOM_DISCRETE_DISTRIBUTION_H diff --git a/contrib/libs/cxxsupp/libcxxmsvc/include/__random/exponential_distribution.h b/contrib/libs/cxxsupp/libcxxmsvc/include/__random/exponential_distribution.h new file mode 100644 index 0000000000..e51871dd53 --- /dev/null +++ b/contrib/libs/cxxsupp/libcxxmsvc/include/__random/exponential_distribution.h @@ -0,0 +1,155 @@ +//===----------------------------------------------------------------------===// +// +// 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 _LIBCPP___RANDOM_EXPONENTIAL_DISTRIBUTION_H +#define _LIBCPP___RANDOM_EXPONENTIAL_DISTRIBUTION_H + +#include <__config> +#include <__random/generate_canonical.h> +#include <__random/uniform_real_distribution.h> +#include <cmath> +#include <iosfwd> +#include <limits> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +# pragma GCC system_header +#endif + +_LIBCPP_PUSH_MACROS +#include <__undef_macros> + +_LIBCPP_BEGIN_NAMESPACE_STD + +template<class _RealType = double> +class _LIBCPP_TEMPLATE_VIS exponential_distribution +{ +public: + // types + typedef _RealType result_type; + + class _LIBCPP_TEMPLATE_VIS param_type + { + result_type __lambda_; + public: + typedef exponential_distribution distribution_type; + + _LIBCPP_INLINE_VISIBILITY + explicit param_type(result_type __lambda = 1) : __lambda_(__lambda) {} + + _LIBCPP_INLINE_VISIBILITY + result_type lambda() const {return __lambda_;} + + friend _LIBCPP_INLINE_VISIBILITY + bool operator==(const param_type& __x, const param_type& __y) + {return __x.__lambda_ == __y.__lambda_;} + friend _LIBCPP_INLINE_VISIBILITY + bool operator!=(const param_type& __x, const param_type& __y) + {return !(__x == __y);} + }; + +private: + param_type __p_; + +public: + // constructors and reset functions +#ifndef _LIBCPP_CXX03_LANG + _LIBCPP_INLINE_VISIBILITY + exponential_distribution() : exponential_distribution(1) {} + _LIBCPP_INLINE_VISIBILITY + explicit exponential_distribution(result_type __lambda) + : __p_(param_type(__lambda)) {} +#else + _LIBCPP_INLINE_VISIBILITY + explicit exponential_distribution(result_type __lambda = 1) + : __p_(param_type(__lambda)) {} +#endif + _LIBCPP_INLINE_VISIBILITY + explicit exponential_distribution(const param_type& __p) : __p_(__p) {} + _LIBCPP_INLINE_VISIBILITY + void reset() {} + + // generating functions + template<class _URNG> + _LIBCPP_INLINE_VISIBILITY + result_type operator()(_URNG& __g) + {return (*this)(__g, __p_);} + template<class _URNG> result_type operator()(_URNG& __g, const param_type& __p); + + // property functions + _LIBCPP_INLINE_VISIBILITY + result_type lambda() const {return __p_.lambda();} + + _LIBCPP_INLINE_VISIBILITY + param_type param() const {return __p_;} + _LIBCPP_INLINE_VISIBILITY + void param(const param_type& __p) {__p_ = __p;} + + _LIBCPP_INLINE_VISIBILITY + result_type min() const {return 0;} + _LIBCPP_INLINE_VISIBILITY + result_type max() const {return numeric_limits<result_type>::infinity();} + + friend _LIBCPP_INLINE_VISIBILITY + bool operator==(const exponential_distribution& __x, + const exponential_distribution& __y) + {return __x.__p_ == __y.__p_;} + friend _LIBCPP_INLINE_VISIBILITY + bool operator!=(const exponential_distribution& __x, + const exponential_distribution& __y) + {return !(__x == __y);} +}; + +template <class _RealType> +template<class _URNG> +_RealType +exponential_distribution<_RealType>::operator()(_URNG& __g, const param_type& __p) +{ + return -_VSTD::log + ( + result_type(1) - + _VSTD::generate_canonical<result_type, + numeric_limits<result_type>::digits>(__g) + ) + / __p.lambda(); +} + +template <class _CharT, class _Traits, class _RealType> +basic_ostream<_CharT, _Traits>& +operator<<(basic_ostream<_CharT, _Traits>& __os, + const exponential_distribution<_RealType>& __x) +{ + __save_flags<_CharT, _Traits> __lx(__os); + typedef basic_ostream<_CharT, _Traits> _OStream; + __os.flags(_OStream::dec | _OStream::left | _OStream::fixed | + _OStream::scientific); + return __os << __x.lambda(); +} + +template <class _CharT, class _Traits, class _RealType> +basic_istream<_CharT, _Traits>& +operator>>(basic_istream<_CharT, _Traits>& __is, + exponential_distribution<_RealType>& __x) +{ + typedef exponential_distribution<_RealType> _Eng; + typedef typename _Eng::result_type result_type; + typedef typename _Eng::param_type param_type; + __save_flags<_CharT, _Traits> __lx(__is); + typedef basic_istream<_CharT, _Traits> _Istream; + __is.flags(_Istream::dec | _Istream::skipws); + result_type __lambda; + __is >> __lambda; + if (!__is.fail()) + __x.param(param_type(__lambda)); + return __is; +} + +_LIBCPP_END_NAMESPACE_STD + +_LIBCPP_POP_MACROS + +#endif // _LIBCPP___RANDOM_EXPONENTIAL_DISTRIBUTION_H diff --git a/contrib/libs/cxxsupp/libcxxmsvc/include/__random/extreme_value_distribution.h b/contrib/libs/cxxsupp/libcxxmsvc/include/__random/extreme_value_distribution.h new file mode 100644 index 0000000000..15cebd8e95 --- /dev/null +++ b/contrib/libs/cxxsupp/libcxxmsvc/include/__random/extreme_value_distribution.h @@ -0,0 +1,161 @@ +//===----------------------------------------------------------------------===// +// +// 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 _LIBCPP___RANDOM_EXTREME_VALUE_DISTRIBUTION_H +#define _LIBCPP___RANDOM_EXTREME_VALUE_DISTRIBUTION_H + +#include <__config> +#include <__random/uniform_real_distribution.h> +#include <cmath> +#include <iosfwd> +#include <limits> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +# pragma GCC system_header +#endif + +_LIBCPP_PUSH_MACROS +#include <__undef_macros> + +_LIBCPP_BEGIN_NAMESPACE_STD + +template<class _RealType = double> +class _LIBCPP_TEMPLATE_VIS extreme_value_distribution +{ +public: + // types + typedef _RealType result_type; + + class _LIBCPP_TEMPLATE_VIS param_type + { + result_type __a_; + result_type __b_; + public: + typedef extreme_value_distribution distribution_type; + + _LIBCPP_INLINE_VISIBILITY + explicit param_type(result_type __a = 0, result_type __b = 1) + : __a_(__a), __b_(__b) {} + + _LIBCPP_INLINE_VISIBILITY + result_type a() const {return __a_;} + _LIBCPP_INLINE_VISIBILITY + result_type b() const {return __b_;} + + friend _LIBCPP_INLINE_VISIBILITY + bool operator==(const param_type& __x, const param_type& __y) + {return __x.__a_ == __y.__a_ && __x.__b_ == __y.__b_;} + friend _LIBCPP_INLINE_VISIBILITY + bool operator!=(const param_type& __x, const param_type& __y) + {return !(__x == __y);} + }; + +private: + param_type __p_; + +public: + // constructor and reset functions +#ifndef _LIBCPP_CXX03_LANG + _LIBCPP_INLINE_VISIBILITY + extreme_value_distribution() : extreme_value_distribution(0) {} + _LIBCPP_INLINE_VISIBILITY + explicit extreme_value_distribution(result_type __a, result_type __b = 1) + : __p_(param_type(__a, __b)) {} +#else + _LIBCPP_INLINE_VISIBILITY + explicit extreme_value_distribution(result_type __a = 0, + result_type __b = 1) + : __p_(param_type(__a, __b)) {} +#endif + _LIBCPP_INLINE_VISIBILITY + explicit extreme_value_distribution(const param_type& __p) + : __p_(__p) {} + _LIBCPP_INLINE_VISIBILITY + void reset() {} + + // generating functions + template<class _URNG> + _LIBCPP_INLINE_VISIBILITY + result_type operator()(_URNG& __g) + {return (*this)(__g, __p_);} + template<class _URNG> result_type operator()(_URNG& __g, const param_type& __p); + + // property functions + _LIBCPP_INLINE_VISIBILITY + result_type a() const {return __p_.a();} + _LIBCPP_INLINE_VISIBILITY + result_type b() const {return __p_.b();} + + _LIBCPP_INLINE_VISIBILITY + param_type param() const {return __p_;} + _LIBCPP_INLINE_VISIBILITY + void param(const param_type& __p) {__p_ = __p;} + + _LIBCPP_INLINE_VISIBILITY + result_type min() const {return -numeric_limits<result_type>::infinity();} + _LIBCPP_INLINE_VISIBILITY + result_type max() const {return numeric_limits<result_type>::infinity();} + + friend _LIBCPP_INLINE_VISIBILITY + bool operator==(const extreme_value_distribution& __x, + const extreme_value_distribution& __y) + {return __x.__p_ == __y.__p_;} + friend _LIBCPP_INLINE_VISIBILITY + bool operator!=(const extreme_value_distribution& __x, + const extreme_value_distribution& __y) + {return !(__x == __y);} +}; + +template<class _RealType> +template<class _URNG> +_RealType +extreme_value_distribution<_RealType>::operator()(_URNG& __g, const param_type& __p) +{ + return __p.a() - __p.b() * + _VSTD::log(-_VSTD::log(1-uniform_real_distribution<result_type>()(__g))); +} + +template <class _CharT, class _Traits, class _RT> +basic_ostream<_CharT, _Traits>& +operator<<(basic_ostream<_CharT, _Traits>& __os, + const extreme_value_distribution<_RT>& __x) +{ + __save_flags<_CharT, _Traits> __lx(__os); + typedef basic_ostream<_CharT, _Traits> _OStream; + __os.flags(_OStream::dec | _OStream::left | _OStream::fixed | + _OStream::scientific); + _CharT __sp = __os.widen(' '); + __os.fill(__sp); + __os << __x.a() << __sp << __x.b(); + return __os; +} + +template <class _CharT, class _Traits, class _RT> +basic_istream<_CharT, _Traits>& +operator>>(basic_istream<_CharT, _Traits>& __is, + extreme_value_distribution<_RT>& __x) +{ + typedef extreme_value_distribution<_RT> _Eng; + typedef typename _Eng::result_type result_type; + typedef typename _Eng::param_type param_type; + __save_flags<_CharT, _Traits> __lx(__is); + typedef basic_istream<_CharT, _Traits> _Istream; + __is.flags(_Istream::dec | _Istream::skipws); + result_type __a; + result_type __b; + __is >> __a >> __b; + if (!__is.fail()) + __x.param(param_type(__a, __b)); + return __is; +} + +_LIBCPP_END_NAMESPACE_STD + +_LIBCPP_POP_MACROS + +#endif // _LIBCPP___RANDOM_EXTREME_VALUE_DISTRIBUTION_H diff --git a/contrib/libs/cxxsupp/libcxxmsvc/include/__random/fisher_f_distribution.h b/contrib/libs/cxxsupp/libcxxmsvc/include/__random/fisher_f_distribution.h new file mode 100644 index 0000000000..72f1f40aaa --- /dev/null +++ b/contrib/libs/cxxsupp/libcxxmsvc/include/__random/fisher_f_distribution.h @@ -0,0 +1,160 @@ +//===----------------------------------------------------------------------===// +// +// 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 _LIBCPP___RANDOM_FISHER_F_DISTRIBUTION_H +#define _LIBCPP___RANDOM_FISHER_F_DISTRIBUTION_H + +#include <__config> +#include <__random/gamma_distribution.h> +#include <iosfwd> +#include <limits> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +# pragma GCC system_header +#endif + +_LIBCPP_PUSH_MACROS +#include <__undef_macros> + +_LIBCPP_BEGIN_NAMESPACE_STD + +template<class _RealType = double> +class _LIBCPP_TEMPLATE_VIS fisher_f_distribution +{ +public: + // types + typedef _RealType result_type; + + class _LIBCPP_TEMPLATE_VIS param_type + { + result_type __m_; + result_type __n_; + public: + typedef fisher_f_distribution distribution_type; + + _LIBCPP_INLINE_VISIBILITY + explicit param_type(result_type __m = 1, result_type __n = 1) + : __m_(__m), __n_(__n) {} + + _LIBCPP_INLINE_VISIBILITY + result_type m() const {return __m_;} + _LIBCPP_INLINE_VISIBILITY + result_type n() const {return __n_;} + + friend _LIBCPP_INLINE_VISIBILITY + bool operator==(const param_type& __x, const param_type& __y) + {return __x.__m_ == __y.__m_ && __x.__n_ == __y.__n_;} + friend _LIBCPP_INLINE_VISIBILITY + bool operator!=(const param_type& __x, const param_type& __y) + {return !(__x == __y);} + }; + +private: + param_type __p_; + +public: + // constructor and reset functions +#ifndef _LIBCPP_CXX03_LANG + _LIBCPP_INLINE_VISIBILITY + fisher_f_distribution() : fisher_f_distribution(1) {} + _LIBCPP_INLINE_VISIBILITY + explicit fisher_f_distribution(result_type __m, result_type __n = 1) + : __p_(param_type(__m, __n)) {} +#else + _LIBCPP_INLINE_VISIBILITY + explicit fisher_f_distribution(result_type __m = 1, result_type __n = 1) + : __p_(param_type(__m, __n)) {} +#endif + _LIBCPP_INLINE_VISIBILITY + explicit fisher_f_distribution(const param_type& __p) + : __p_(__p) {} + _LIBCPP_INLINE_VISIBILITY + void reset() {} + + // generating functions + template<class _URNG> + _LIBCPP_INLINE_VISIBILITY + result_type operator()(_URNG& __g) + {return (*this)(__g, __p_);} + template<class _URNG> result_type operator()(_URNG& __g, const param_type& __p); + + // property functions + _LIBCPP_INLINE_VISIBILITY + result_type m() const {return __p_.m();} + _LIBCPP_INLINE_VISIBILITY + result_type n() const {return __p_.n();} + + _LIBCPP_INLINE_VISIBILITY + param_type param() const {return __p_;} + _LIBCPP_INLINE_VISIBILITY + void param(const param_type& __p) {__p_ = __p;} + + _LIBCPP_INLINE_VISIBILITY + result_type min() const {return 0;} + _LIBCPP_INLINE_VISIBILITY + result_type max() const {return numeric_limits<result_type>::infinity();} + + friend _LIBCPP_INLINE_VISIBILITY + bool operator==(const fisher_f_distribution& __x, + const fisher_f_distribution& __y) + {return __x.__p_ == __y.__p_;} + friend _LIBCPP_INLINE_VISIBILITY + bool operator!=(const fisher_f_distribution& __x, + const fisher_f_distribution& __y) + {return !(__x == __y);} +}; + +template <class _RealType> +template<class _URNG> +_RealType +fisher_f_distribution<_RealType>::operator()(_URNG& __g, const param_type& __p) +{ + gamma_distribution<result_type> __gdm(__p.m() * result_type(.5)); + gamma_distribution<result_type> __gdn(__p.n() * result_type(.5)); + return __p.n() * __gdm(__g) / (__p.m() * __gdn(__g)); +} + +template <class _CharT, class _Traits, class _RT> +basic_ostream<_CharT, _Traits>& +operator<<(basic_ostream<_CharT, _Traits>& __os, + const fisher_f_distribution<_RT>& __x) +{ + __save_flags<_CharT, _Traits> __lx(__os); + typedef basic_ostream<_CharT, _Traits> _OStream; + __os.flags(_OStream::dec | _OStream::left | _OStream::fixed | + _OStream::scientific); + _CharT __sp = __os.widen(' '); + __os.fill(__sp); + __os << __x.m() << __sp << __x.n(); + return __os; +} + +template <class _CharT, class _Traits, class _RT> +basic_istream<_CharT, _Traits>& +operator>>(basic_istream<_CharT, _Traits>& __is, + fisher_f_distribution<_RT>& __x) +{ + typedef fisher_f_distribution<_RT> _Eng; + typedef typename _Eng::result_type result_type; + typedef typename _Eng::param_type param_type; + __save_flags<_CharT, _Traits> __lx(__is); + typedef basic_istream<_CharT, _Traits> _Istream; + __is.flags(_Istream::dec | _Istream::skipws); + result_type __m; + result_type __n; + __is >> __m >> __n; + if (!__is.fail()) + __x.param(param_type(__m, __n)); + return __is; +} + +_LIBCPP_END_NAMESPACE_STD + +_LIBCPP_POP_MACROS + +#endif // _LIBCPP___RANDOM_FISHER_F_DISTRIBUTION_H diff --git a/contrib/libs/cxxsupp/libcxxmsvc/include/__random/gamma_distribution.h b/contrib/libs/cxxsupp/libcxxmsvc/include/__random/gamma_distribution.h new file mode 100644 index 0000000000..a8504961b2 --- /dev/null +++ b/contrib/libs/cxxsupp/libcxxmsvc/include/__random/gamma_distribution.h @@ -0,0 +1,213 @@ +//===----------------------------------------------------------------------===// +// +// 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 _LIBCPP___RANDOM_GAMMA_DISTRIBUTION_H +#define _LIBCPP___RANDOM_GAMMA_DISTRIBUTION_H + +#include <__config> +#include <__random/exponential_distribution.h> +#include <__random/uniform_real_distribution.h> +#include <cmath> +#include <iosfwd> +#include <limits> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +# pragma GCC system_header +#endif + +_LIBCPP_PUSH_MACROS +#include <__undef_macros> + +_LIBCPP_BEGIN_NAMESPACE_STD + +template<class _RealType = double> +class _LIBCPP_TEMPLATE_VIS gamma_distribution +{ +public: + // types + typedef _RealType result_type; + + class _LIBCPP_TEMPLATE_VIS param_type + { + result_type __alpha_; + result_type __beta_; + public: + typedef gamma_distribution distribution_type; + + _LIBCPP_INLINE_VISIBILITY + explicit param_type(result_type __alpha = 1, result_type __beta = 1) + : __alpha_(__alpha), __beta_(__beta) {} + + _LIBCPP_INLINE_VISIBILITY + result_type alpha() const {return __alpha_;} + _LIBCPP_INLINE_VISIBILITY + result_type beta() const {return __beta_;} + + friend _LIBCPP_INLINE_VISIBILITY + bool operator==(const param_type& __x, const param_type& __y) + {return __x.__alpha_ == __y.__alpha_ && __x.__beta_ == __y.__beta_;} + friend _LIBCPP_INLINE_VISIBILITY + bool operator!=(const param_type& __x, const param_type& __y) + {return !(__x == __y);} + }; + +private: + param_type __p_; + +public: + // constructors and reset functions +#ifndef _LIBCPP_CXX03_LANG + _LIBCPP_INLINE_VISIBILITY + gamma_distribution() : gamma_distribution(1) {} + _LIBCPP_INLINE_VISIBILITY + explicit gamma_distribution(result_type __alpha, result_type __beta = 1) + : __p_(param_type(__alpha, __beta)) {} +#else + _LIBCPP_INLINE_VISIBILITY + explicit gamma_distribution(result_type __alpha = 1, + result_type __beta = 1) + : __p_(param_type(__alpha, __beta)) {} +#endif + _LIBCPP_INLINE_VISIBILITY + explicit gamma_distribution(const param_type& __p) + : __p_(__p) {} + _LIBCPP_INLINE_VISIBILITY + void reset() {} + + // generating functions + template<class _URNG> + _LIBCPP_INLINE_VISIBILITY + result_type operator()(_URNG& __g) + {return (*this)(__g, __p_);} + template<class _URNG> result_type operator()(_URNG& __g, const param_type& __p); + + // property functions + _LIBCPP_INLINE_VISIBILITY + result_type alpha() const {return __p_.alpha();} + _LIBCPP_INLINE_VISIBILITY + result_type beta() const {return __p_.beta();} + + _LIBCPP_INLINE_VISIBILITY + param_type param() const {return __p_;} + _LIBCPP_INLINE_VISIBILITY + void param(const param_type& __p) {__p_ = __p;} + + _LIBCPP_INLINE_VISIBILITY + result_type min() const {return 0;} + _LIBCPP_INLINE_VISIBILITY + result_type max() const {return numeric_limits<result_type>::infinity();} + + friend _LIBCPP_INLINE_VISIBILITY + bool operator==(const gamma_distribution& __x, + const gamma_distribution& __y) + {return __x.__p_ == __y.__p_;} + friend _LIBCPP_INLINE_VISIBILITY + bool operator!=(const gamma_distribution& __x, + const gamma_distribution& __y) + {return !(__x == __y);} +}; + +template <class _RealType> +template<class _URNG> +_RealType +gamma_distribution<_RealType>::operator()(_URNG& __g, const param_type& __p) +{ + result_type __a = __p.alpha(); + uniform_real_distribution<result_type> __gen(0, 1); + exponential_distribution<result_type> __egen; + result_type __x; + if (__a == 1) + __x = __egen(__g); + else if (__a > 1) + { + const result_type __b = __a - 1; + const result_type __c = 3 * __a - result_type(0.75); + while (true) + { + const result_type __u = __gen(__g); + const result_type __v = __gen(__g); + const result_type __w = __u * (1 - __u); + if (__w != 0) + { + const result_type __y = _VSTD::sqrt(__c / __w) * + (__u - result_type(0.5)); + __x = __b + __y; + if (__x >= 0) + { + const result_type __z = 64 * __w * __w * __w * __v * __v; + if (__z <= 1 - 2 * __y * __y / __x) + break; + if (_VSTD::log(__z) <= 2 * (__b * _VSTD::log(__x / __b) - __y)) + break; + } + } + } + } + else // __a < 1 + { + while (true) + { + const result_type __u = __gen(__g); + const result_type __es = __egen(__g); + if (__u <= 1 - __a) + { + __x = _VSTD::pow(__u, 1 / __a); + if (__x <= __es) + break; + } + else + { + const result_type __e = -_VSTD::log((1-__u)/__a); + __x = _VSTD::pow(1 - __a + __a * __e, 1 / __a); + if (__x <= __e + __es) + break; + } + } + } + return __x * __p.beta(); +} + +template <class _CharT, class _Traits, class _RT> +basic_ostream<_CharT, _Traits>& +operator<<(basic_ostream<_CharT, _Traits>& __os, + const gamma_distribution<_RT>& __x) +{ + __save_flags<_CharT, _Traits> __lx(__os); + typedef basic_ostream<_CharT, _Traits> _OStream; + __os.flags(_OStream::dec | _OStream::left | _OStream::fixed | + _OStream::scientific); + _CharT __sp = __os.widen(' '); + __os.fill(__sp); + __os << __x.alpha() << __sp << __x.beta(); + return __os; +} + +template <class _CharT, class _Traits, class _RT> +basic_istream<_CharT, _Traits>& +operator>>(basic_istream<_CharT, _Traits>& __is, + gamma_distribution<_RT>& __x) +{ + typedef gamma_distribution<_RT> _Eng; + typedef typename _Eng::result_type result_type; + typedef typename _Eng::param_type param_type; + __save_flags<_CharT, _Traits> __lx(__is); + typedef basic_istream<_CharT, _Traits> _Istream; + __is.flags(_Istream::dec | _Istream::skipws); + result_type __alpha; + result_type __beta; + __is >> __alpha >> __beta; + if (!__is.fail()) + __x.param(param_type(__alpha, __beta)); + return __is; +} + +_LIBCPP_END_NAMESPACE_STD + +_LIBCPP_POP_MACROS + +#endif // _LIBCPP___RANDOM_GAMMA_DISTRIBUTION_H diff --git a/contrib/libs/cxxsupp/libcxxmsvc/include/__random/generate_canonical.h b/contrib/libs/cxxsupp/libcxxmsvc/include/__random/generate_canonical.h new file mode 100644 index 0000000000..84efa7803c --- /dev/null +++ b/contrib/libs/cxxsupp/libcxxmsvc/include/__random/generate_canonical.h @@ -0,0 +1,53 @@ +//===----------------------------------------------------------------------===// +// +// 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 _LIBCPP___RANDOM_GENERATE_CANONICAL_H +#define _LIBCPP___RANDOM_GENERATE_CANONICAL_H + +#include <__config> +#include <__random/log2.h> +#include <cstdint> +#include <initializer_list> +#include <limits> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +# pragma GCC system_header +#endif + +_LIBCPP_PUSH_MACROS +#include <__undef_macros> + +_LIBCPP_BEGIN_NAMESPACE_STD + +// generate_canonical + +template<class _RealType, size_t __bits, class _URNG> +_RealType +generate_canonical(_URNG& __g) +{ + const size_t _Dt = numeric_limits<_RealType>::digits; + const size_t __b = _Dt < __bits ? _Dt : __bits; +#ifdef _LIBCPP_CXX03_LANG + const size_t __logR = __log2<uint64_t, _URNG::_Max - _URNG::_Min + uint64_t(1)>::value; +#else + const size_t __logR = __log2<uint64_t, _URNG::max() - _URNG::min() + uint64_t(1)>::value; +#endif + const size_t __k = __b / __logR + (__b % __logR != 0) + (__b == 0); + const _RealType _Rp = static_cast<_RealType>(_URNG::max() - _URNG::min()) + _RealType(1); + _RealType __base = _Rp; + _RealType _Sp = __g() - _URNG::min(); + for (size_t __i = 1; __i < __k; ++__i, __base *= _Rp) + _Sp += (__g() - _URNG::min()) * __base; + return _Sp / __base; +} + +_LIBCPP_END_NAMESPACE_STD + +_LIBCPP_POP_MACROS + +#endif // _LIBCPP___RANDOM_GENERATE_CANONICAL_H diff --git a/contrib/libs/cxxsupp/libcxxmsvc/include/__random/geometric_distribution.h b/contrib/libs/cxxsupp/libcxxmsvc/include/__random/geometric_distribution.h new file mode 100644 index 0000000000..b9cc151b34 --- /dev/null +++ b/contrib/libs/cxxsupp/libcxxmsvc/include/__random/geometric_distribution.h @@ -0,0 +1,141 @@ +//===----------------------------------------------------------------------===// +// +// 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 _LIBCPP___RANDOM_GEOMETRIC_DISTRIBUTION_H +#define _LIBCPP___RANDOM_GEOMETRIC_DISTRIBUTION_H + +#include <__config> +#include <__random/negative_binomial_distribution.h> +#include <iosfwd> +#include <limits> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +# pragma GCC system_header +#endif + +_LIBCPP_PUSH_MACROS +#include <__undef_macros> + +_LIBCPP_BEGIN_NAMESPACE_STD + +template<class _IntType = int> +class _LIBCPP_TEMPLATE_VIS geometric_distribution +{ +public: + // types + typedef _IntType result_type; + + class _LIBCPP_TEMPLATE_VIS param_type + { + double __p_; + public: + typedef geometric_distribution distribution_type; + + _LIBCPP_INLINE_VISIBILITY + explicit param_type(double __p = 0.5) : __p_(__p) {} + + _LIBCPP_INLINE_VISIBILITY + double p() const {return __p_;} + + friend _LIBCPP_INLINE_VISIBILITY + bool operator==(const param_type& __x, const param_type& __y) + {return __x.__p_ == __y.__p_;} + friend _LIBCPP_INLINE_VISIBILITY + bool operator!=(const param_type& __x, const param_type& __y) + {return !(__x == __y);} + }; + +private: + param_type __p_; + +public: + // constructors and reset functions +#ifndef _LIBCPP_CXX03_LANG + _LIBCPP_INLINE_VISIBILITY + geometric_distribution() : geometric_distribution(0.5) {} + _LIBCPP_INLINE_VISIBILITY + explicit geometric_distribution(double __p) + : __p_(__p) {} +#else + _LIBCPP_INLINE_VISIBILITY + explicit geometric_distribution(double __p = 0.5) + : __p_(__p) {} +#endif + _LIBCPP_INLINE_VISIBILITY + explicit geometric_distribution(const param_type& __p) : __p_(__p) {} + _LIBCPP_INLINE_VISIBILITY + void reset() {} + + // generating functions + template<class _URNG> + _LIBCPP_INLINE_VISIBILITY + result_type operator()(_URNG& __g) + {return (*this)(__g, __p_);} + template<class _URNG> + _LIBCPP_INLINE_VISIBILITY + result_type operator()(_URNG& __g, const param_type& __p) + {return negative_binomial_distribution<result_type>(1, __p.p())(__g);} + + // property functions + _LIBCPP_INLINE_VISIBILITY + double p() const {return __p_.p();} + + _LIBCPP_INLINE_VISIBILITY + param_type param() const {return __p_;} + _LIBCPP_INLINE_VISIBILITY + void param(const param_type& __p) {__p_ = __p;} + + _LIBCPP_INLINE_VISIBILITY + result_type min() const {return 0;} + _LIBCPP_INLINE_VISIBILITY + result_type max() const {return numeric_limits<result_type>::max();} + + friend _LIBCPP_INLINE_VISIBILITY + bool operator==(const geometric_distribution& __x, + const geometric_distribution& __y) + {return __x.__p_ == __y.__p_;} + friend _LIBCPP_INLINE_VISIBILITY + bool operator!=(const geometric_distribution& __x, + const geometric_distribution& __y) + {return !(__x == __y);} +}; + +template <class _CharT, class _Traits, class _IntType> +basic_ostream<_CharT, _Traits>& +operator<<(basic_ostream<_CharT, _Traits>& __os, + const geometric_distribution<_IntType>& __x) +{ + __save_flags<_CharT, _Traits> __lx(__os); + typedef basic_ostream<_CharT, _Traits> _OStream; + __os.flags(_OStream::dec | _OStream::left | _OStream::fixed | + _OStream::scientific); + return __os << __x.p(); +} + +template <class _CharT, class _Traits, class _IntType> +basic_istream<_CharT, _Traits>& +operator>>(basic_istream<_CharT, _Traits>& __is, + geometric_distribution<_IntType>& __x) +{ + typedef geometric_distribution<_IntType> _Eng; + typedef typename _Eng::param_type param_type; + __save_flags<_CharT, _Traits> __lx(__is); + typedef basic_istream<_CharT, _Traits> _Istream; + __is.flags(_Istream::dec | _Istream::skipws); + double __p; + __is >> __p; + if (!__is.fail()) + __x.param(param_type(__p)); + return __is; +} + +_LIBCPP_END_NAMESPACE_STD + +_LIBCPP_POP_MACROS + +#endif // _LIBCPP___RANDOM_GEOMETRIC_DISTRIBUTION_H diff --git a/contrib/libs/cxxsupp/libcxxmsvc/include/__random/independent_bits_engine.h b/contrib/libs/cxxsupp/libcxxmsvc/include/__random/independent_bits_engine.h new file mode 100644 index 0000000000..e80d6eec49 --- /dev/null +++ b/contrib/libs/cxxsupp/libcxxmsvc/include/__random/independent_bits_engine.h @@ -0,0 +1,271 @@ +//===----------------------------------------------------------------------===// +// +// 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 _LIBCPP___RANDOM_INDEPENDENT_BITS_ENGINE_H +#define _LIBCPP___RANDOM_INDEPENDENT_BITS_ENGINE_H + +#include <__config> +#include <__random/is_seed_sequence.h> +#include <__random/log2.h> +#include <__utility/move.h> +#include <iosfwd> +#include <limits> +#include <type_traits> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +# pragma GCC system_header +#endif + +_LIBCPP_PUSH_MACROS +#include <__undef_macros> + +_LIBCPP_BEGIN_NAMESPACE_STD + +template<class _Engine, size_t __w, class _UIntType> +class _LIBCPP_TEMPLATE_VIS independent_bits_engine +{ + template <class _UInt, _UInt _R0, size_t _Wp, size_t _Mp> + class __get_n + { + static _LIBCPP_CONSTEXPR const size_t _Dt = numeric_limits<_UInt>::digits; + static _LIBCPP_CONSTEXPR const size_t _Np = _Wp / _Mp + (_Wp % _Mp != 0); + static _LIBCPP_CONSTEXPR const size_t _W0 = _Wp / _Np; + static _LIBCPP_CONSTEXPR const _UInt _Y0 = _W0 >= _Dt ? 0 : (_R0 >> _W0) << _W0; + public: + static _LIBCPP_CONSTEXPR const size_t value = _R0 - _Y0 > _Y0 / _Np ? _Np + 1 : _Np; + }; +public: + // types + typedef _UIntType result_type; + +private: + _Engine __e_; + + static _LIBCPP_CONSTEXPR const result_type _Dt = numeric_limits<result_type>::digits; + static_assert( 0 < __w, "independent_bits_engine invalid parameters"); + static_assert(__w <= _Dt, "independent_bits_engine invalid parameters"); + + typedef typename _Engine::result_type _Engine_result_type; + typedef typename conditional + < + sizeof(_Engine_result_type) <= sizeof(result_type), + result_type, + _Engine_result_type + >::type _Working_result_type; +#ifdef _LIBCPP_CXX03_LANG + static const _Working_result_type _Rp = _Engine::_Max - _Engine::_Min + + _Working_result_type(1); +#else + static _LIBCPP_CONSTEXPR const _Working_result_type _Rp = _Engine::max() - _Engine::min() + + _Working_result_type(1); +#endif + static _LIBCPP_CONSTEXPR const size_t __m = __log2<_Working_result_type, _Rp>::value; + static _LIBCPP_CONSTEXPR const size_t __n = __get_n<_Working_result_type, _Rp, __w, __m>::value; + static _LIBCPP_CONSTEXPR const size_t __w0 = __w / __n; + static _LIBCPP_CONSTEXPR const size_t __n0 = __n - __w % __n; + static _LIBCPP_CONSTEXPR const size_t _WDt = numeric_limits<_Working_result_type>::digits; + static _LIBCPP_CONSTEXPR const size_t _EDt = numeric_limits<_Engine_result_type>::digits; + static _LIBCPP_CONSTEXPR const _Working_result_type __y0 = __w0 >= _WDt ? 0 : + (_Rp >> __w0) << __w0; + static _LIBCPP_CONSTEXPR const _Working_result_type __y1 = __w0 >= _WDt - 1 ? 0 : + (_Rp >> (__w0+1)) << (__w0+1); + static _LIBCPP_CONSTEXPR const _Engine_result_type __mask0 = __w0 > 0 ? + _Engine_result_type(~0) >> (_EDt - __w0) : + _Engine_result_type(0); + static _LIBCPP_CONSTEXPR const _Engine_result_type __mask1 = __w0 < _EDt - 1 ? + _Engine_result_type(~0) >> (_EDt - (__w0 + 1)) : + _Engine_result_type(~0); +public: + static _LIBCPP_CONSTEXPR const result_type _Min = 0; + static _LIBCPP_CONSTEXPR const result_type _Max = __w == _Dt ? result_type(~0) : + (result_type(1) << __w) - result_type(1); + static_assert(_Min < _Max, "independent_bits_engine invalid parameters"); + + // engine characteristics + _LIBCPP_INLINE_VISIBILITY + static _LIBCPP_CONSTEXPR result_type min() { return _Min; } + _LIBCPP_INLINE_VISIBILITY + static _LIBCPP_CONSTEXPR result_type max() { return _Max; } + + // constructors and seeding functions + _LIBCPP_INLINE_VISIBILITY + independent_bits_engine() {} + _LIBCPP_INLINE_VISIBILITY + explicit independent_bits_engine(const _Engine& __e) + : __e_(__e) {} +#ifndef _LIBCPP_CXX03_LANG + _LIBCPP_INLINE_VISIBILITY + explicit independent_bits_engine(_Engine&& __e) + : __e_(_VSTD::move(__e)) {} +#endif // _LIBCPP_CXX03_LANG + _LIBCPP_INLINE_VISIBILITY + explicit independent_bits_engine(result_type __sd) : __e_(__sd) {} + template<class _Sseq> + _LIBCPP_INLINE_VISIBILITY + explicit independent_bits_engine(_Sseq& __q, + typename enable_if<__is_seed_sequence<_Sseq, independent_bits_engine>::value && + !is_convertible<_Sseq, _Engine>::value>::type* = 0) + : __e_(__q) {} + _LIBCPP_INLINE_VISIBILITY + void seed() {__e_.seed();} + _LIBCPP_INLINE_VISIBILITY + void seed(result_type __sd) {__e_.seed(__sd);} + template<class _Sseq> + _LIBCPP_INLINE_VISIBILITY + typename enable_if + < + __is_seed_sequence<_Sseq, independent_bits_engine>::value, + void + >::type + seed(_Sseq& __q) {__e_.seed(__q);} + + // generating functions + _LIBCPP_INLINE_VISIBILITY + result_type operator()() {return __eval(integral_constant<bool, _Rp != 0>());} + _LIBCPP_INLINE_VISIBILITY + void discard(unsigned long long __z) {for (; __z; --__z) operator()();} + + // property functions + _LIBCPP_INLINE_VISIBILITY + const _Engine& base() const _NOEXCEPT {return __e_;} + + template<class _Eng, size_t _Wp, class _UInt> + friend + bool + operator==( + const independent_bits_engine<_Eng, _Wp, _UInt>& __x, + const independent_bits_engine<_Eng, _Wp, _UInt>& __y); + + template<class _Eng, size_t _Wp, class _UInt> + friend + bool + operator!=( + const independent_bits_engine<_Eng, _Wp, _UInt>& __x, + const independent_bits_engine<_Eng, _Wp, _UInt>& __y); + + template <class _CharT, class _Traits, + class _Eng, size_t _Wp, class _UInt> + friend + basic_ostream<_CharT, _Traits>& + operator<<(basic_ostream<_CharT, _Traits>& __os, + const independent_bits_engine<_Eng, _Wp, _UInt>& __x); + + template <class _CharT, class _Traits, + class _Eng, size_t _Wp, class _UInt> + friend + basic_istream<_CharT, _Traits>& + operator>>(basic_istream<_CharT, _Traits>& __is, + independent_bits_engine<_Eng, _Wp, _UInt>& __x); + +private: + _LIBCPP_INLINE_VISIBILITY + result_type __eval(false_type); + result_type __eval(true_type); + + template <size_t __count> + _LIBCPP_INLINE_VISIBILITY + static + typename enable_if + < + __count < _Dt, + result_type + >::type + __lshift(result_type __x) {return __x << __count;} + + template <size_t __count> + _LIBCPP_INLINE_VISIBILITY + static + typename enable_if + < + (__count >= _Dt), + result_type + >::type + __lshift(result_type) {return result_type(0);} +}; + +template<class _Engine, size_t __w, class _UIntType> +inline +_UIntType +independent_bits_engine<_Engine, __w, _UIntType>::__eval(false_type) +{ + return static_cast<result_type>(__e_() & __mask0); +} + +template<class _Engine, size_t __w, class _UIntType> +_UIntType +independent_bits_engine<_Engine, __w, _UIntType>::__eval(true_type) +{ + result_type _Sp = 0; + for (size_t __k = 0; __k < __n0; ++__k) + { + _Engine_result_type __u; + do + { + __u = __e_() - _Engine::min(); + } while (__u >= __y0); + _Sp = static_cast<result_type>(__lshift<__w0>(_Sp) + (__u & __mask0)); + } + for (size_t __k = __n0; __k < __n; ++__k) + { + _Engine_result_type __u; + do + { + __u = __e_() - _Engine::min(); + } while (__u >= __y1); + _Sp = static_cast<result_type>(__lshift<__w0+1>(_Sp) + (__u & __mask1)); + } + return _Sp; +} + +template<class _Eng, size_t _Wp, class _UInt> +inline _LIBCPP_INLINE_VISIBILITY +bool +operator==( + const independent_bits_engine<_Eng, _Wp, _UInt>& __x, + const independent_bits_engine<_Eng, _Wp, _UInt>& __y) +{ + return __x.base() == __y.base(); +} + +template<class _Eng, size_t _Wp, class _UInt> +inline _LIBCPP_INLINE_VISIBILITY +bool +operator!=( + const independent_bits_engine<_Eng, _Wp, _UInt>& __x, + const independent_bits_engine<_Eng, _Wp, _UInt>& __y) +{ + return !(__x == __y); +} + +template <class _CharT, class _Traits, + class _Eng, size_t _Wp, class _UInt> +basic_ostream<_CharT, _Traits>& +operator<<(basic_ostream<_CharT, _Traits>& __os, + const independent_bits_engine<_Eng, _Wp, _UInt>& __x) +{ + return __os << __x.base(); +} + +template <class _CharT, class _Traits, + class _Eng, size_t _Wp, class _UInt> +basic_istream<_CharT, _Traits>& +operator>>(basic_istream<_CharT, _Traits>& __is, + independent_bits_engine<_Eng, _Wp, _UInt>& __x) +{ + _Eng __e; + __is >> __e; + if (!__is.fail()) + __x.__e_ = __e; + return __is; +} + +_LIBCPP_END_NAMESPACE_STD + +_LIBCPP_POP_MACROS + +#endif // _LIBCPP___RANDOM_INDEPENDENT_BITS_ENGINE_H diff --git a/contrib/libs/cxxsupp/libcxxmsvc/include/__random/is_seed_sequence.h b/contrib/libs/cxxsupp/libcxxmsvc/include/__random/is_seed_sequence.h new file mode 100644 index 0000000000..a6832f51c1 --- /dev/null +++ b/contrib/libs/cxxsupp/libcxxmsvc/include/__random/is_seed_sequence.h @@ -0,0 +1,31 @@ +//===----------------------------------------------------------------------===// +// +// 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 _LIBCPP___RANDOM_IS_SEED_SEQUENCE_H +#define _LIBCPP___RANDOM_IS_SEED_SEQUENCE_H + +#include <__config> +#include <type_traits> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +# pragma GCC system_header +#endif + +_LIBCPP_BEGIN_NAMESPACE_STD + +template <class _Sseq, class _Engine> +struct __is_seed_sequence +{ + static _LIBCPP_CONSTEXPR const bool value = + !is_convertible<_Sseq, typename _Engine::result_type>::value && + !is_same<typename remove_cv<_Sseq>::type, _Engine>::value; +}; + +_LIBCPP_END_NAMESPACE_STD + +#endif // _LIBCPP___RANDOM_IS_SEED_SEQUENCE_H diff --git a/contrib/libs/cxxsupp/libcxxmsvc/include/__random/knuth_b.h b/contrib/libs/cxxsupp/libcxxmsvc/include/__random/knuth_b.h new file mode 100644 index 0000000000..f5b31cb64f --- /dev/null +++ b/contrib/libs/cxxsupp/libcxxmsvc/include/__random/knuth_b.h @@ -0,0 +1,26 @@ +//===----------------------------------------------------------------------===// +// +// 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 _LIBCPP___RANDOM_KNUTH_B_H +#define _LIBCPP___RANDOM_KNUTH_B_H + +#include <__config> +#include <__random/linear_congruential_engine.h> +#include <__random/shuffle_order_engine.h> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +# pragma GCC system_header +#endif + +_LIBCPP_BEGIN_NAMESPACE_STD + +typedef shuffle_order_engine<minstd_rand0, 256> knuth_b; + +_LIBCPP_END_NAMESPACE_STD + +#endif // _LIBCPP___RANDOM_KNUTH_B_H diff --git a/contrib/libs/cxxsupp/libcxxmsvc/include/__random/linear_congruential_engine.h b/contrib/libs/cxxsupp/libcxxmsvc/include/__random/linear_congruential_engine.h new file mode 100644 index 0000000000..f5aba75d57 --- /dev/null +++ b/contrib/libs/cxxsupp/libcxxmsvc/include/__random/linear_congruential_engine.h @@ -0,0 +1,398 @@ +//===----------------------------------------------------------------------===// +// +// 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 _LIBCPP___RANDOM_LINEAR_CONGRUENTIAL_ENGINE_H +#define _LIBCPP___RANDOM_LINEAR_CONGRUENTIAL_ENGINE_H + +#include <__config> +#include <__random/is_seed_sequence.h> +#include <cstdint> +#include <iosfwd> +#include <type_traits> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +# pragma GCC system_header +#endif + +_LIBCPP_PUSH_MACROS +#include <__undef_macros> + +_LIBCPP_BEGIN_NAMESPACE_STD + +template <unsigned long long __a, unsigned long long __c, + unsigned long long __m, unsigned long long _Mp, + bool _MightOverflow = (__a != 0 && __m != 0 && __m-1 > (_Mp-__c)/__a), + bool _OverflowOK = ((__m | (__m-1)) > __m), // m = 2^n + bool _SchrageOK = (__a != 0 && __m != 0 && __m % __a <= __m / __a)> // r <= q +struct __lce_alg_picker +{ + static_assert(__a != 0 || __m != 0 || !_MightOverflow || _OverflowOK || _SchrageOK, + "The current values of a, c, and m cannot generate a number " + "within bounds of linear_congruential_engine."); + + static _LIBCPP_CONSTEXPR const bool __use_schrage = _MightOverflow && + !_OverflowOK && + _SchrageOK; +}; + +template <unsigned long long __a, unsigned long long __c, + unsigned long long __m, unsigned long long _Mp, + bool _UseSchrage = __lce_alg_picker<__a, __c, __m, _Mp>::__use_schrage> +struct __lce_ta; + +// 64 + +template <unsigned long long __a, unsigned long long __c, unsigned long long __m> +struct __lce_ta<__a, __c, __m, (unsigned long long)(~0), true> +{ + typedef unsigned long long result_type; + _LIBCPP_INLINE_VISIBILITY + static result_type next(result_type __x) + { + // Schrage's algorithm + const result_type __q = __m / __a; + const result_type __r = __m % __a; + const result_type __t0 = __a * (__x % __q); + const result_type __t1 = __r * (__x / __q); + __x = __t0 + (__t0 < __t1) * __m - __t1; + __x += __c - (__x >= __m - __c) * __m; + return __x; + } +}; + +template <unsigned long long __a, unsigned long long __m> +struct __lce_ta<__a, 0, __m, (unsigned long long)(~0), true> +{ + typedef unsigned long long result_type; + _LIBCPP_INLINE_VISIBILITY + static result_type next(result_type __x) + { + // Schrage's algorithm + const result_type __q = __m / __a; + const result_type __r = __m % __a; + const result_type __t0 = __a * (__x % __q); + const result_type __t1 = __r * (__x / __q); + __x = __t0 + (__t0 < __t1) * __m - __t1; + return __x; + } +}; + +template <unsigned long long __a, unsigned long long __c, unsigned long long __m> +struct __lce_ta<__a, __c, __m, (unsigned long long)(~0), false> +{ + typedef unsigned long long result_type; + _LIBCPP_INLINE_VISIBILITY + static result_type next(result_type __x) + { + return (__a * __x + __c) % __m; + } +}; + +template <unsigned long long __a, unsigned long long __c> +struct __lce_ta<__a, __c, 0, (unsigned long long)(~0), false> +{ + typedef unsigned long long result_type; + _LIBCPP_INLINE_VISIBILITY + static result_type next(result_type __x) + { + return __a * __x + __c; + } +}; + +// 32 + +template <unsigned long long _Ap, unsigned long long _Cp, unsigned long long _Mp> +struct __lce_ta<_Ap, _Cp, _Mp, unsigned(~0), true> +{ + typedef unsigned result_type; + _LIBCPP_INLINE_VISIBILITY + static result_type next(result_type __x) + { + const result_type __a = static_cast<result_type>(_Ap); + const result_type __c = static_cast<result_type>(_Cp); + const result_type __m = static_cast<result_type>(_Mp); + // Schrage's algorithm + const result_type __q = __m / __a; + const result_type __r = __m % __a; + const result_type __t0 = __a * (__x % __q); + const result_type __t1 = __r * (__x / __q); + __x = __t0 + (__t0 < __t1) * __m - __t1; + __x += __c - (__x >= __m - __c) * __m; + return __x; + } +}; + +template <unsigned long long _Ap, unsigned long long _Mp> +struct __lce_ta<_Ap, 0, _Mp, unsigned(~0), true> +{ + typedef unsigned result_type; + _LIBCPP_INLINE_VISIBILITY + static result_type next(result_type __x) + { + const result_type __a = static_cast<result_type>(_Ap); + const result_type __m = static_cast<result_type>(_Mp); + // Schrage's algorithm + const result_type __q = __m / __a; + const result_type __r = __m % __a; + const result_type __t0 = __a * (__x % __q); + const result_type __t1 = __r * (__x / __q); + __x = __t0 + (__t0 < __t1) * __m - __t1; + return __x; + } +}; + +template <unsigned long long _Ap, unsigned long long _Cp, unsigned long long _Mp> +struct __lce_ta<_Ap, _Cp, _Mp, unsigned(~0), false> +{ + typedef unsigned result_type; + _LIBCPP_INLINE_VISIBILITY + static result_type next(result_type __x) + { + const result_type __a = static_cast<result_type>(_Ap); + const result_type __c = static_cast<result_type>(_Cp); + const result_type __m = static_cast<result_type>(_Mp); + return (__a * __x + __c) % __m; + } +}; + +template <unsigned long long _Ap, unsigned long long _Cp> +struct __lce_ta<_Ap, _Cp, 0, unsigned(~0), false> +{ + typedef unsigned result_type; + _LIBCPP_INLINE_VISIBILITY + static result_type next(result_type __x) + { + const result_type __a = static_cast<result_type>(_Ap); + const result_type __c = static_cast<result_type>(_Cp); + return __a * __x + __c; + } +}; + +// 16 + +template <unsigned long long __a, unsigned long long __c, unsigned long long __m, bool __b> +struct __lce_ta<__a, __c, __m, (unsigned short)(~0), __b> +{ + typedef unsigned short result_type; + _LIBCPP_INLINE_VISIBILITY + static result_type next(result_type __x) + { + return static_cast<result_type>(__lce_ta<__a, __c, __m, unsigned(~0)>::next(__x)); + } +}; + +template <class _UIntType, _UIntType __a, _UIntType __c, _UIntType __m> +class _LIBCPP_TEMPLATE_VIS linear_congruential_engine; + +template <class _CharT, class _Traits, + class _Up, _Up _Ap, _Up _Cp, _Up _Np> +_LIBCPP_INLINE_VISIBILITY +basic_ostream<_CharT, _Traits>& +operator<<(basic_ostream<_CharT, _Traits>& __os, + const linear_congruential_engine<_Up, _Ap, _Cp, _Np>&); + +template <class _CharT, class _Traits, + class _Up, _Up _Ap, _Up _Cp, _Up _Np> +basic_istream<_CharT, _Traits>& +operator>>(basic_istream<_CharT, _Traits>& __is, + linear_congruential_engine<_Up, _Ap, _Cp, _Np>& __x); + +template <class _UIntType, _UIntType __a, _UIntType __c, _UIntType __m> +class _LIBCPP_TEMPLATE_VIS linear_congruential_engine +{ +public: + // types + typedef _UIntType result_type; + +private: + result_type __x_; + + static _LIBCPP_CONSTEXPR const result_type _Mp = result_type(~0); + + static_assert(__m == 0 || __a < __m, "linear_congruential_engine invalid parameters"); + static_assert(__m == 0 || __c < __m, "linear_congruential_engine invalid parameters"); + static_assert(is_unsigned<_UIntType>::value, "_UIntType must be unsigned type"); +public: + static _LIBCPP_CONSTEXPR const result_type _Min = __c == 0u ? 1u: 0u; + static _LIBCPP_CONSTEXPR const result_type _Max = __m - 1u; + static_assert(_Min < _Max, "linear_congruential_engine invalid parameters"); + + // engine characteristics + static _LIBCPP_CONSTEXPR const result_type multiplier = __a; + static _LIBCPP_CONSTEXPR const result_type increment = __c; + static _LIBCPP_CONSTEXPR const result_type modulus = __m; + _LIBCPP_INLINE_VISIBILITY + static _LIBCPP_CONSTEXPR result_type min() {return _Min;} + _LIBCPP_INLINE_VISIBILITY + static _LIBCPP_CONSTEXPR result_type max() {return _Max;} + static _LIBCPP_CONSTEXPR const result_type default_seed = 1u; + + // constructors and seeding functions +#ifndef _LIBCPP_CXX03_LANG + _LIBCPP_INLINE_VISIBILITY + linear_congruential_engine() : linear_congruential_engine(default_seed) {} + _LIBCPP_INLINE_VISIBILITY + explicit linear_congruential_engine(result_type __s) { seed(__s); } +#else + _LIBCPP_INLINE_VISIBILITY + explicit linear_congruential_engine(result_type __s = default_seed) { + seed(__s); + } +#endif + template<class _Sseq> + _LIBCPP_INLINE_VISIBILITY + explicit linear_congruential_engine(_Sseq& __q, + typename enable_if<__is_seed_sequence<_Sseq, linear_congruential_engine>::value>::type* = 0) + {seed(__q);} + _LIBCPP_INLINE_VISIBILITY + void seed(result_type __s = default_seed) + {seed(integral_constant<bool, __m == 0>(), + integral_constant<bool, __c == 0>(), __s);} + template<class _Sseq> + _LIBCPP_INLINE_VISIBILITY + typename enable_if + < + __is_seed_sequence<_Sseq, linear_congruential_engine>::value, + void + >::type + seed(_Sseq& __q) + {__seed(__q, integral_constant<unsigned, + 1 + (__m == 0 ? (sizeof(result_type) * __CHAR_BIT__ - 1)/32 + : (__m > 0x100000000ull))>());} + + // generating functions + _LIBCPP_INLINE_VISIBILITY + result_type operator()() + {return __x_ = static_cast<result_type>(__lce_ta<__a, __c, __m, _Mp>::next(__x_));} + _LIBCPP_INLINE_VISIBILITY + void discard(unsigned long long __z) {for (; __z; --__z) operator()();} + + friend _LIBCPP_INLINE_VISIBILITY + bool operator==(const linear_congruential_engine& __x, + const linear_congruential_engine& __y) + {return __x.__x_ == __y.__x_;} + friend _LIBCPP_INLINE_VISIBILITY + bool operator!=(const linear_congruential_engine& __x, + const linear_congruential_engine& __y) + {return !(__x == __y);} + +private: + + _LIBCPP_INLINE_VISIBILITY + void seed(true_type, true_type, result_type __s) {__x_ = __s == 0 ? 1 : __s;} + _LIBCPP_INLINE_VISIBILITY + void seed(true_type, false_type, result_type __s) {__x_ = __s;} + _LIBCPP_INLINE_VISIBILITY + void seed(false_type, true_type, result_type __s) {__x_ = __s % __m == 0 ? + 1 : __s % __m;} + _LIBCPP_INLINE_VISIBILITY + void seed(false_type, false_type, result_type __s) {__x_ = __s % __m;} + + template<class _Sseq> + void __seed(_Sseq& __q, integral_constant<unsigned, 1>); + template<class _Sseq> + void __seed(_Sseq& __q, integral_constant<unsigned, 2>); + + template <class _CharT, class _Traits, + class _Up, _Up _Ap, _Up _Cp, _Up _Np> + friend + basic_ostream<_CharT, _Traits>& + operator<<(basic_ostream<_CharT, _Traits>& __os, + const linear_congruential_engine<_Up, _Ap, _Cp, _Np>&); + + template <class _CharT, class _Traits, + class _Up, _Up _Ap, _Up _Cp, _Up _Np> + friend + basic_istream<_CharT, _Traits>& + operator>>(basic_istream<_CharT, _Traits>& __is, + linear_congruential_engine<_Up, _Ap, _Cp, _Np>& __x); +}; + +template <class _UIntType, _UIntType __a, _UIntType __c, _UIntType __m> + _LIBCPP_CONSTEXPR const typename linear_congruential_engine<_UIntType, __a, __c, __m>::result_type + linear_congruential_engine<_UIntType, __a, __c, __m>::multiplier; + +template <class _UIntType, _UIntType __a, _UIntType __c, _UIntType __m> + _LIBCPP_CONSTEXPR const typename linear_congruential_engine<_UIntType, __a, __c, __m>::result_type + linear_congruential_engine<_UIntType, __a, __c, __m>::increment; + +template <class _UIntType, _UIntType __a, _UIntType __c, _UIntType __m> + _LIBCPP_CONSTEXPR const typename linear_congruential_engine<_UIntType, __a, __c, __m>::result_type + linear_congruential_engine<_UIntType, __a, __c, __m>::modulus; + +template <class _UIntType, _UIntType __a, _UIntType __c, _UIntType __m> + _LIBCPP_CONSTEXPR const typename linear_congruential_engine<_UIntType, __a, __c, __m>::result_type + linear_congruential_engine<_UIntType, __a, __c, __m>::default_seed; + +template <class _UIntType, _UIntType __a, _UIntType __c, _UIntType __m> +template<class _Sseq> +void +linear_congruential_engine<_UIntType, __a, __c, __m>::__seed(_Sseq& __q, + integral_constant<unsigned, 1>) +{ + const unsigned __k = 1; + uint32_t __ar[__k+3]; + __q.generate(__ar, __ar + __k + 3); + result_type __s = static_cast<result_type>(__ar[3] % __m); + __x_ = __c == 0 && __s == 0 ? result_type(1) : __s; +} + +template <class _UIntType, _UIntType __a, _UIntType __c, _UIntType __m> +template<class _Sseq> +void +linear_congruential_engine<_UIntType, __a, __c, __m>::__seed(_Sseq& __q, + integral_constant<unsigned, 2>) +{ + const unsigned __k = 2; + uint32_t __ar[__k+3]; + __q.generate(__ar, __ar + __k + 3); + result_type __s = static_cast<result_type>((__ar[3] + + ((uint64_t)__ar[4] << 32)) % __m); + __x_ = __c == 0 && __s == 0 ? result_type(1) : __s; +} + +template <class _CharT, class _Traits, + class _UIntType, _UIntType __a, _UIntType __c, _UIntType __m> +inline _LIBCPP_INLINE_VISIBILITY +basic_ostream<_CharT, _Traits>& +operator<<(basic_ostream<_CharT, _Traits>& __os, + const linear_congruential_engine<_UIntType, __a, __c, __m>& __x) +{ + __save_flags<_CharT, _Traits> __lx(__os); + typedef basic_ostream<_CharT, _Traits> _Ostream; + __os.flags(_Ostream::dec | _Ostream::left); + __os.fill(__os.widen(' ')); + return __os << __x.__x_; +} + +template <class _CharT, class _Traits, + class _UIntType, _UIntType __a, _UIntType __c, _UIntType __m> +basic_istream<_CharT, _Traits>& +operator>>(basic_istream<_CharT, _Traits>& __is, + linear_congruential_engine<_UIntType, __a, __c, __m>& __x) +{ + __save_flags<_CharT, _Traits> __lx(__is); + typedef basic_istream<_CharT, _Traits> _Istream; + __is.flags(_Istream::dec | _Istream::skipws); + _UIntType __t; + __is >> __t; + if (!__is.fail()) + __x.__x_ = __t; + return __is; +} + +typedef linear_congruential_engine<uint_fast32_t, 16807, 0, 2147483647> + minstd_rand0; +typedef linear_congruential_engine<uint_fast32_t, 48271, 0, 2147483647> + minstd_rand; + +_LIBCPP_END_NAMESPACE_STD + +_LIBCPP_POP_MACROS + +#endif // _LIBCPP___RANDOM_LINEAR_CONGRUENTIAL_ENGINE_H diff --git a/contrib/libs/cxxsupp/libcxxmsvc/include/__random/lognormal_distribution.h b/contrib/libs/cxxsupp/libcxxmsvc/include/__random/lognormal_distribution.h new file mode 100644 index 0000000000..048d7dade9 --- /dev/null +++ b/contrib/libs/cxxsupp/libcxxmsvc/include/__random/lognormal_distribution.h @@ -0,0 +1,299 @@ +//===----------------------------------------------------------------------===// +// +// 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 _LIBCPP___RANDOM_LOGNORMAL_DISTRIBUTION_H +#define _LIBCPP___RANDOM_LOGNORMAL_DISTRIBUTION_H + +#include <__config> +#include <__random/normal_distribution.h> +#include <cmath> +#include <iosfwd> +#include <limits> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +# pragma GCC system_header +#endif + +_LIBCPP_PUSH_MACROS +#include <__undef_macros> + +_LIBCPP_BEGIN_NAMESPACE_STD + +#ifdef _LIBCPP_ABI_OLD_LOGNORMAL_DISTRIBUTION + +template<class _RealType = double> +class _LIBCPP_TEMPLATE_VIS lognormal_distribution +{ +public: + // types + typedef _RealType result_type; + + class _LIBCPP_TEMPLATE_VIS param_type + { + normal_distribution<result_type> __nd_; + public: + typedef lognormal_distribution distribution_type; + + _LIBCPP_INLINE_VISIBILITY + explicit param_type(result_type __m = 0, result_type __s = 1) + : __nd_(__m, __s) {} + + _LIBCPP_INLINE_VISIBILITY + result_type m() const {return __nd_.mean();} + _LIBCPP_INLINE_VISIBILITY + result_type s() const {return __nd_.stddev();} + + friend _LIBCPP_INLINE_VISIBILITY + bool operator==(const param_type& __x, const param_type& __y) + {return __x.__nd_ == __y.__nd_;} + friend _LIBCPP_INLINE_VISIBILITY + bool operator!=(const param_type& __x, const param_type& __y) + {return !(__x == __y);} + friend class lognormal_distribution; + + template <class _CharT, class _Traits, class _RT> + friend + basic_ostream<_CharT, _Traits>& + operator<<(basic_ostream<_CharT, _Traits>& __os, + const lognormal_distribution<_RT>& __x); + + template <class _CharT, class _Traits, class _RT> + friend + basic_istream<_CharT, _Traits>& + operator>>(basic_istream<_CharT, _Traits>& __is, + lognormal_distribution<_RT>& __x); + }; + +private: + param_type __p_; + +public: + // constructor and reset functions +#ifndef _LIBCPP_CXX03_LANG + _LIBCPP_INLINE_VISIBILITY + lognormal_distribution() : lognormal_distribution(0) {} + _LIBCPP_INLINE_VISIBILITY + explicit lognormal_distribution(result_type __m, result_type __s = 1) + : __p_(param_type(__m, __s)) {} +#else + _LIBCPP_INLINE_VISIBILITY + explicit lognormal_distribution(result_type __m = 0, + result_type __s = 1) + : __p_(param_type(__m, __s)) {} +#endif + _LIBCPP_INLINE_VISIBILITY + explicit lognormal_distribution(const param_type& __p) + : __p_(__p) {} + _LIBCPP_INLINE_VISIBILITY + void reset() {__p_.__nd_.reset();} + + // generating functions + template<class _URNG> + _LIBCPP_INLINE_VISIBILITY + result_type operator()(_URNG& __g) + {return (*this)(__g, __p_);} + template<class _URNG> + _LIBCPP_INLINE_VISIBILITY + result_type operator()(_URNG& __g, const param_type& __p) + {return _VSTD::exp(const_cast<normal_distribution<result_type>&>(__p.__nd_)(__g));} + + // property functions + _LIBCPP_INLINE_VISIBILITY + result_type m() const {return __p_.m();} + _LIBCPP_INLINE_VISIBILITY + result_type s() const {return __p_.s();} + + _LIBCPP_INLINE_VISIBILITY + param_type param() const {return __p_;} + _LIBCPP_INLINE_VISIBILITY + void param(const param_type& __p) {__p_ = __p;} + + _LIBCPP_INLINE_VISIBILITY + result_type min() const {return 0;} + _LIBCPP_INLINE_VISIBILITY + result_type max() const {return numeric_limits<result_type>::infinity();} + + friend _LIBCPP_INLINE_VISIBILITY + bool operator==(const lognormal_distribution& __x, + const lognormal_distribution& __y) + {return __x.__p_ == __y.__p_;} + friend _LIBCPP_INLINE_VISIBILITY + bool operator!=(const lognormal_distribution& __x, + const lognormal_distribution& __y) + {return !(__x == __y);} + + template <class _CharT, class _Traits, class _RT> + friend + basic_ostream<_CharT, _Traits>& + operator<<(basic_ostream<_CharT, _Traits>& __os, + const lognormal_distribution<_RT>& __x); + + template <class _CharT, class _Traits, class _RT> + friend + basic_istream<_CharT, _Traits>& + operator>>(basic_istream<_CharT, _Traits>& __is, + lognormal_distribution<_RT>& __x); +}; + +template <class _CharT, class _Traits, class _RT> +inline _LIBCPP_INLINE_VISIBILITY +basic_ostream<_CharT, _Traits>& +operator<<(basic_ostream<_CharT, _Traits>& __os, + const lognormal_distribution<_RT>& __x) +{ + return __os << __x.__p_.__nd_; +} + +template <class _CharT, class _Traits, class _RT> +inline _LIBCPP_INLINE_VISIBILITY +basic_istream<_CharT, _Traits>& +operator>>(basic_istream<_CharT, _Traits>& __is, + lognormal_distribution<_RT>& __x) +{ + return __is >> __x.__p_.__nd_; +} + +#else // _LIBCPP_ABI_OLD_LOGNORMAL_DISTRIBUTION + +template<class _RealType = double> +class _LIBCPP_TEMPLATE_VIS lognormal_distribution +{ +public: + // types + typedef _RealType result_type; + + class _LIBCPP_TEMPLATE_VIS param_type + { + result_type __m_; + result_type __s_; + public: + typedef lognormal_distribution distribution_type; + + _LIBCPP_INLINE_VISIBILITY + explicit param_type(result_type __m = 0, result_type __s = 1) + : __m_(__m), __s_(__s) {} + + _LIBCPP_INLINE_VISIBILITY + result_type m() const {return __m_;} + _LIBCPP_INLINE_VISIBILITY + result_type s() const {return __s_;} + + friend _LIBCPP_INLINE_VISIBILITY + bool operator==(const param_type& __x, const param_type& __y) + {return __x.__m_ == __y.__m_ && __x.__s_ == __y.__s_;} + friend _LIBCPP_INLINE_VISIBILITY + bool operator!=(const param_type& __x, const param_type& __y) + {return !(__x == __y);} + }; + +private: + normal_distribution<result_type> __nd_; + +public: + // constructor and reset functions +#ifndef _LIBCPP_CXX03_LANG + _LIBCPP_INLINE_VISIBILITY + lognormal_distribution() : lognormal_distribution(0) {} + _LIBCPP_INLINE_VISIBILITY + explicit lognormal_distribution(result_type __m, result_type __s = 1) + : __nd_(__m, __s) {} +#else + _LIBCPP_INLINE_VISIBILITY + explicit lognormal_distribution(result_type __m = 0, + result_type __s = 1) + : __nd_(__m, __s) {} +#endif + _LIBCPP_INLINE_VISIBILITY + explicit lognormal_distribution(const param_type& __p) + : __nd_(__p.m(), __p.s()) {} + _LIBCPP_INLINE_VISIBILITY + void reset() {__nd_.reset();} + + // generating functions + template<class _URNG> + _LIBCPP_INLINE_VISIBILITY + result_type operator()(_URNG& __g) + { + return _VSTD::exp(__nd_(__g)); + } + + template<class _URNG> + _LIBCPP_INLINE_VISIBILITY + result_type operator()(_URNG& __g, const param_type& __p) + { + typename normal_distribution<result_type>::param_type __pn(__p.m(), __p.s()); + return _VSTD::exp(__nd_(__g, __pn)); + } + + // property functions + _LIBCPP_INLINE_VISIBILITY + result_type m() const {return __nd_.mean();} + _LIBCPP_INLINE_VISIBILITY + result_type s() const {return __nd_.stddev();} + + _LIBCPP_INLINE_VISIBILITY + param_type param() const {return param_type(__nd_.mean(), __nd_.stddev());} + _LIBCPP_INLINE_VISIBILITY + void param(const param_type& __p) + { + typename normal_distribution<result_type>::param_type __pn(__p.m(), __p.s()); + __nd_.param(__pn); + } + + _LIBCPP_INLINE_VISIBILITY + result_type min() const {return 0;} + _LIBCPP_INLINE_VISIBILITY + result_type max() const {return numeric_limits<result_type>::infinity();} + + friend _LIBCPP_INLINE_VISIBILITY + bool operator==(const lognormal_distribution& __x, + const lognormal_distribution& __y) + {return __x.__nd_ == __y.__nd_;} + friend _LIBCPP_INLINE_VISIBILITY + bool operator!=(const lognormal_distribution& __x, + const lognormal_distribution& __y) + {return !(__x == __y);} + + template <class _CharT, class _Traits, class _RT> + friend + basic_ostream<_CharT, _Traits>& + operator<<(basic_ostream<_CharT, _Traits>& __os, + const lognormal_distribution<_RT>& __x); + + template <class _CharT, class _Traits, class _RT> + friend + basic_istream<_CharT, _Traits>& + operator>>(basic_istream<_CharT, _Traits>& __is, + lognormal_distribution<_RT>& __x); +}; + +template <class _CharT, class _Traits, class _RT> +inline _LIBCPP_INLINE_VISIBILITY +basic_ostream<_CharT, _Traits>& +operator<<(basic_ostream<_CharT, _Traits>& __os, + const lognormal_distribution<_RT>& __x) +{ + return __os << __x.__nd_; +} + +template <class _CharT, class _Traits, class _RT> +inline _LIBCPP_INLINE_VISIBILITY +basic_istream<_CharT, _Traits>& +operator>>(basic_istream<_CharT, _Traits>& __is, + lognormal_distribution<_RT>& __x) +{ + return __is >> __x.__nd_; +} + +#endif // _LIBCPP_ABI_OLD_LOGNORMAL_DISTRIBUTION + +_LIBCPP_END_NAMESPACE_STD + +_LIBCPP_POP_MACROS + +#endif // _LIBCPP___RANDOM_LOGNORMAL_DISTRIBUTION_H diff --git a/contrib/libs/cxxsupp/libcxxmsvc/include/__random/mersenne_twister_engine.h b/contrib/libs/cxxsupp/libcxxmsvc/include/__random/mersenne_twister_engine.h new file mode 100644 index 0000000000..8bceac05dc --- /dev/null +++ b/contrib/libs/cxxsupp/libcxxmsvc/include/__random/mersenne_twister_engine.h @@ -0,0 +1,534 @@ +//===----------------------------------------------------------------------===// +// +// 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 _LIBCPP___RANDOM_MERSENNE_TWISTER_ENGINE_H +#define _LIBCPP___RANDOM_MERSENNE_TWISTER_ENGINE_H + +#include <__algorithm/equal.h> +#include <__algorithm/min.h> +#include <__config> +#include <__random/is_seed_sequence.h> +#include <cstddef> +#include <cstdint> +#include <iosfwd> +#include <limits> +#include <type_traits> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +# pragma GCC system_header +#endif + +_LIBCPP_PUSH_MACROS +#include <__undef_macros> + +_LIBCPP_BEGIN_NAMESPACE_STD + +template <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r, + _UIntType __a, size_t __u, _UIntType __d, size_t __s, + _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f> +class _LIBCPP_TEMPLATE_VIS mersenne_twister_engine; + +template <class _UInt, size_t _Wp, size_t _Np, size_t _Mp, size_t _Rp, + _UInt _Ap, size_t _Up, _UInt _Dp, size_t _Sp, + _UInt _Bp, size_t _Tp, _UInt _Cp, size_t _Lp, _UInt _Fp> +bool +operator==(const mersenne_twister_engine<_UInt, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp, + _Bp, _Tp, _Cp, _Lp, _Fp>& __x, + const mersenne_twister_engine<_UInt, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp, + _Bp, _Tp, _Cp, _Lp, _Fp>& __y); + +template <class _UInt, size_t _Wp, size_t _Np, size_t _Mp, size_t _Rp, + _UInt _Ap, size_t _Up, _UInt _Dp, size_t _Sp, + _UInt _Bp, size_t _Tp, _UInt _Cp, size_t _Lp, _UInt _Fp> +_LIBCPP_INLINE_VISIBILITY +bool +operator!=(const mersenne_twister_engine<_UInt, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp, + _Bp, _Tp, _Cp, _Lp, _Fp>& __x, + const mersenne_twister_engine<_UInt, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp, + _Bp, _Tp, _Cp, _Lp, _Fp>& __y); + +template <class _CharT, class _Traits, + class _UInt, size_t _Wp, size_t _Np, size_t _Mp, size_t _Rp, + _UInt _Ap, size_t _Up, _UInt _Dp, size_t _Sp, + _UInt _Bp, size_t _Tp, _UInt _Cp, size_t _Lp, _UInt _Fp> +basic_ostream<_CharT, _Traits>& +operator<<(basic_ostream<_CharT, _Traits>& __os, + const mersenne_twister_engine<_UInt, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp, + _Bp, _Tp, _Cp, _Lp, _Fp>& __x); + +template <class _CharT, class _Traits, + class _UInt, size_t _Wp, size_t _Np, size_t _Mp, size_t _Rp, + _UInt _Ap, size_t _Up, _UInt _Dp, size_t _Sp, + _UInt _Bp, size_t _Tp, _UInt _Cp, size_t _Lp, _UInt _Fp> +basic_istream<_CharT, _Traits>& +operator>>(basic_istream<_CharT, _Traits>& __is, + mersenne_twister_engine<_UInt, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp, + _Bp, _Tp, _Cp, _Lp, _Fp>& __x); + +template <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r, + _UIntType __a, size_t __u, _UIntType __d, size_t __s, + _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f> +class _LIBCPP_TEMPLATE_VIS mersenne_twister_engine +{ +public: + // types + typedef _UIntType result_type; + +private: + result_type __x_[__n]; + size_t __i_; + + static_assert( 0 < __m, "mersenne_twister_engine invalid parameters"); + static_assert(__m <= __n, "mersenne_twister_engine invalid parameters"); + static _LIBCPP_CONSTEXPR const result_type _Dt = numeric_limits<result_type>::digits; + static_assert(__w <= _Dt, "mersenne_twister_engine invalid parameters"); + static_assert( 2 <= __w, "mersenne_twister_engine invalid parameters"); + static_assert(__r <= __w, "mersenne_twister_engine invalid parameters"); + static_assert(__u <= __w, "mersenne_twister_engine invalid parameters"); + static_assert(__s <= __w, "mersenne_twister_engine invalid parameters"); + static_assert(__t <= __w, "mersenne_twister_engine invalid parameters"); + static_assert(__l <= __w, "mersenne_twister_engine invalid parameters"); +public: + static _LIBCPP_CONSTEXPR const result_type _Min = 0; + static _LIBCPP_CONSTEXPR const result_type _Max = __w == _Dt ? result_type(~0) : + (result_type(1) << __w) - result_type(1); + static_assert(_Min < _Max, "mersenne_twister_engine invalid parameters"); + static_assert(__a <= _Max, "mersenne_twister_engine invalid parameters"); + static_assert(__b <= _Max, "mersenne_twister_engine invalid parameters"); + static_assert(__c <= _Max, "mersenne_twister_engine invalid parameters"); + static_assert(__d <= _Max, "mersenne_twister_engine invalid parameters"); + static_assert(__f <= _Max, "mersenne_twister_engine invalid parameters"); + + // engine characteristics + static _LIBCPP_CONSTEXPR const size_t word_size = __w; + static _LIBCPP_CONSTEXPR const size_t state_size = __n; + static _LIBCPP_CONSTEXPR const size_t shift_size = __m; + static _LIBCPP_CONSTEXPR const size_t mask_bits = __r; + static _LIBCPP_CONSTEXPR const result_type xor_mask = __a; + static _LIBCPP_CONSTEXPR const size_t tempering_u = __u; + static _LIBCPP_CONSTEXPR const result_type tempering_d = __d; + static _LIBCPP_CONSTEXPR const size_t tempering_s = __s; + static _LIBCPP_CONSTEXPR const result_type tempering_b = __b; + static _LIBCPP_CONSTEXPR const size_t tempering_t = __t; + static _LIBCPP_CONSTEXPR const result_type tempering_c = __c; + static _LIBCPP_CONSTEXPR const size_t tempering_l = __l; + static _LIBCPP_CONSTEXPR const result_type initialization_multiplier = __f; + _LIBCPP_INLINE_VISIBILITY + static _LIBCPP_CONSTEXPR result_type min() { return _Min; } + _LIBCPP_INLINE_VISIBILITY + static _LIBCPP_CONSTEXPR result_type max() { return _Max; } + static _LIBCPP_CONSTEXPR const result_type default_seed = 5489u; + + // constructors and seeding functions +#ifndef _LIBCPP_CXX03_LANG + _LIBCPP_INLINE_VISIBILITY + mersenne_twister_engine() : mersenne_twister_engine(default_seed) {} + _LIBCPP_INLINE_VISIBILITY + explicit mersenne_twister_engine(result_type __sd) { seed(__sd); } +#else + _LIBCPP_INLINE_VISIBILITY + explicit mersenne_twister_engine(result_type __sd = default_seed) { + seed(__sd); + } +#endif + template<class _Sseq> + _LIBCPP_INLINE_VISIBILITY + explicit mersenne_twister_engine(_Sseq& __q, + typename enable_if<__is_seed_sequence<_Sseq, mersenne_twister_engine>::value>::type* = 0) + {seed(__q);} + void seed(result_type __sd = default_seed); + template<class _Sseq> + _LIBCPP_INLINE_VISIBILITY + typename enable_if + < + __is_seed_sequence<_Sseq, mersenne_twister_engine>::value, + void + >::type + seed(_Sseq& __q) + {__seed(__q, integral_constant<unsigned, 1 + (__w - 1) / 32>());} + + // generating functions + result_type operator()(); + _LIBCPP_INLINE_VISIBILITY + void discard(unsigned long long __z) {for (; __z; --__z) operator()();} + + template <class _UInt, size_t _Wp, size_t _Np, size_t _Mp, size_t _Rp, + _UInt _Ap, size_t _Up, _UInt _Dp, size_t _Sp, + _UInt _Bp, size_t _Tp, _UInt _Cp, size_t _Lp, _UInt _Fp> + friend + bool + operator==(const mersenne_twister_engine<_UInt, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp, + _Bp, _Tp, _Cp, _Lp, _Fp>& __x, + const mersenne_twister_engine<_UInt, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp, + _Bp, _Tp, _Cp, _Lp, _Fp>& __y); + + template <class _UInt, size_t _Wp, size_t _Np, size_t _Mp, size_t _Rp, + _UInt _Ap, size_t _Up, _UInt _Dp, size_t _Sp, + _UInt _Bp, size_t _Tp, _UInt _Cp, size_t _Lp, _UInt _Fp> + friend + bool + operator!=(const mersenne_twister_engine<_UInt, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp, + _Bp, _Tp, _Cp, _Lp, _Fp>& __x, + const mersenne_twister_engine<_UInt, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp, + _Bp, _Tp, _Cp, _Lp, _Fp>& __y); + + template <class _CharT, class _Traits, + class _UInt, size_t _Wp, size_t _Np, size_t _Mp, size_t _Rp, + _UInt _Ap, size_t _Up, _UInt _Dp, size_t _Sp, + _UInt _Bp, size_t _Tp, _UInt _Cp, size_t _Lp, _UInt _Fp> + friend + basic_ostream<_CharT, _Traits>& + operator<<(basic_ostream<_CharT, _Traits>& __os, + const mersenne_twister_engine<_UInt, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp, + _Bp, _Tp, _Cp, _Lp, _Fp>& __x); + + template <class _CharT, class _Traits, + class _UInt, size_t _Wp, size_t _Np, size_t _Mp, size_t _Rp, + _UInt _Ap, size_t _Up, _UInt _Dp, size_t _Sp, + _UInt _Bp, size_t _Tp, _UInt _Cp, size_t _Lp, _UInt _Fp> + friend + basic_istream<_CharT, _Traits>& + operator>>(basic_istream<_CharT, _Traits>& __is, + mersenne_twister_engine<_UInt, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp, + _Bp, _Tp, _Cp, _Lp, _Fp>& __x); +private: + + template<class _Sseq> + void __seed(_Sseq& __q, integral_constant<unsigned, 1>); + template<class _Sseq> + void __seed(_Sseq& __q, integral_constant<unsigned, 2>); + + template <size_t __count> + _LIBCPP_INLINE_VISIBILITY + static + typename enable_if + < + __count < __w, + result_type + >::type + __lshift(result_type __x) {return (__x << __count) & _Max;} + + template <size_t __count> + _LIBCPP_INLINE_VISIBILITY + static + typename enable_if + < + (__count >= __w), + result_type + >::type + __lshift(result_type) {return result_type(0);} + + template <size_t __count> + _LIBCPP_INLINE_VISIBILITY + static + typename enable_if + < + __count < _Dt, + result_type + >::type + __rshift(result_type __x) {return __x >> __count;} + + template <size_t __count> + _LIBCPP_INLINE_VISIBILITY + static + typename enable_if + < + (__count >= _Dt), + result_type + >::type + __rshift(result_type) {return result_type(0);} +}; + +template <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r, + _UIntType __a, size_t __u, _UIntType __d, size_t __s, + _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f> + _LIBCPP_CONSTEXPR const size_t + mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::word_size; + +template <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r, + _UIntType __a, size_t __u, _UIntType __d, size_t __s, + _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f> + _LIBCPP_CONSTEXPR const size_t + mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::state_size; + +template <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r, + _UIntType __a, size_t __u, _UIntType __d, size_t __s, + _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f> + _LIBCPP_CONSTEXPR const size_t + mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::shift_size; + +template <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r, + _UIntType __a, size_t __u, _UIntType __d, size_t __s, + _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f> + _LIBCPP_CONSTEXPR const size_t + mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::mask_bits; + +template <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r, + _UIntType __a, size_t __u, _UIntType __d, size_t __s, + _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f> + _LIBCPP_CONSTEXPR const typename mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::result_type + mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::xor_mask; + +template <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r, + _UIntType __a, size_t __u, _UIntType __d, size_t __s, + _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f> + _LIBCPP_CONSTEXPR const size_t + mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::tempering_u; + +template <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r, + _UIntType __a, size_t __u, _UIntType __d, size_t __s, + _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f> + _LIBCPP_CONSTEXPR const typename mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::result_type + mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::tempering_d; + +template <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r, + _UIntType __a, size_t __u, _UIntType __d, size_t __s, + _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f> + _LIBCPP_CONSTEXPR const size_t + mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::tempering_s; + +template <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r, + _UIntType __a, size_t __u, _UIntType __d, size_t __s, + _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f> + _LIBCPP_CONSTEXPR const typename mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::result_type + mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::tempering_b; + +template <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r, + _UIntType __a, size_t __u, _UIntType __d, size_t __s, + _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f> + _LIBCPP_CONSTEXPR const size_t + mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::tempering_t; + +template <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r, + _UIntType __a, size_t __u, _UIntType __d, size_t __s, + _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f> + _LIBCPP_CONSTEXPR const typename mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::result_type + mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::tempering_c; + +template <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r, + _UIntType __a, size_t __u, _UIntType __d, size_t __s, + _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f> + _LIBCPP_CONSTEXPR const size_t + mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::tempering_l; + +template <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r, + _UIntType __a, size_t __u, _UIntType __d, size_t __s, + _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f> + _LIBCPP_CONSTEXPR const typename mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::result_type + mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::initialization_multiplier; + +template <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r, + _UIntType __a, size_t __u, _UIntType __d, size_t __s, + _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f> + _LIBCPP_CONSTEXPR const typename mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::result_type + mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, __t, __c, __l, __f>::default_seed; + +template <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r, + _UIntType __a, size_t __u, _UIntType __d, size_t __s, + _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f> +void +mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, + __t, __c, __l, __f>::seed(result_type __sd) + _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK +{ // __w >= 2 + __x_[0] = __sd & _Max; + for (size_t __i = 1; __i < __n; ++__i) + __x_[__i] = (__f * (__x_[__i-1] ^ __rshift<__w - 2>(__x_[__i-1])) + __i) & _Max; + __i_ = 0; +} + +template <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r, + _UIntType __a, size_t __u, _UIntType __d, size_t __s, + _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f> +template<class _Sseq> +void +mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, + __t, __c, __l, __f>::__seed(_Sseq& __q, integral_constant<unsigned, 1>) +{ + const unsigned __k = 1; + uint32_t __ar[__n * __k]; + __q.generate(__ar, __ar + __n * __k); + for (size_t __i = 0; __i < __n; ++__i) + __x_[__i] = static_cast<result_type>(__ar[__i] & _Max); + const result_type __mask = __r == _Dt ? result_type(~0) : + (result_type(1) << __r) - result_type(1); + __i_ = 0; + if ((__x_[0] & ~__mask) == 0) + { + for (size_t __i = 1; __i < __n; ++__i) + if (__x_[__i] != 0) + return; + __x_[0] = result_type(1) << (__w - 1); + } +} + +template <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r, + _UIntType __a, size_t __u, _UIntType __d, size_t __s, + _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f> +template<class _Sseq> +void +mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, + __t, __c, __l, __f>::__seed(_Sseq& __q, integral_constant<unsigned, 2>) +{ + const unsigned __k = 2; + uint32_t __ar[__n * __k]; + __q.generate(__ar, __ar + __n * __k); + for (size_t __i = 0; __i < __n; ++__i) + __x_[__i] = static_cast<result_type>( + (__ar[2 * __i] + ((uint64_t)__ar[2 * __i + 1] << 32)) & _Max); + const result_type __mask = __r == _Dt ? result_type(~0) : + (result_type(1) << __r) - result_type(1); + __i_ = 0; + if ((__x_[0] & ~__mask) == 0) + { + for (size_t __i = 1; __i < __n; ++__i) + if (__x_[__i] != 0) + return; + __x_[0] = result_type(1) << (__w - 1); + } +} + +template <class _UIntType, size_t __w, size_t __n, size_t __m, size_t __r, + _UIntType __a, size_t __u, _UIntType __d, size_t __s, + _UIntType __b, size_t __t, _UIntType __c, size_t __l, _UIntType __f> +_UIntType +mersenne_twister_engine<_UIntType, __w, __n, __m, __r, __a, __u, __d, __s, __b, + __t, __c, __l, __f>::operator()() +{ + const size_t __j = (__i_ + 1) % __n; + const result_type __mask = __r == _Dt ? result_type(~0) : + (result_type(1) << __r) - result_type(1); + const result_type _Yp = (__x_[__i_] & ~__mask) | (__x_[__j] & __mask); + const size_t __k = (__i_ + __m) % __n; + __x_[__i_] = __x_[__k] ^ __rshift<1>(_Yp) ^ (__a * (_Yp & 1)); + result_type __z = __x_[__i_] ^ (__rshift<__u>(__x_[__i_]) & __d); + __i_ = __j; + __z ^= __lshift<__s>(__z) & __b; + __z ^= __lshift<__t>(__z) & __c; + return __z ^ __rshift<__l>(__z); +} + +template <class _UInt, size_t _Wp, size_t _Np, size_t _Mp, size_t _Rp, + _UInt _Ap, size_t _Up, _UInt _Dp, size_t _Sp, + _UInt _Bp, size_t _Tp, _UInt _Cp, size_t _Lp, _UInt _Fp> +bool +operator==(const mersenne_twister_engine<_UInt, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp, + _Bp, _Tp, _Cp, _Lp, _Fp>& __x, + const mersenne_twister_engine<_UInt, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp, + _Bp, _Tp, _Cp, _Lp, _Fp>& __y) +{ + if (__x.__i_ == __y.__i_) + return _VSTD::equal(__x.__x_, __x.__x_ + _Np, __y.__x_); + if (__x.__i_ == 0 || __y.__i_ == 0) + { + size_t __j = _VSTD::min(_Np - __x.__i_, _Np - __y.__i_); + if (!_VSTD::equal(__x.__x_ + __x.__i_, __x.__x_ + __x.__i_ + __j, + __y.__x_ + __y.__i_)) + return false; + if (__x.__i_ == 0) + return _VSTD::equal(__x.__x_ + __j, __x.__x_ + _Np, __y.__x_); + return _VSTD::equal(__x.__x_, __x.__x_ + (_Np - __j), __y.__x_ + __j); + } + if (__x.__i_ < __y.__i_) + { + size_t __j = _Np - __y.__i_; + if (!_VSTD::equal(__x.__x_ + __x.__i_, __x.__x_ + (__x.__i_ + __j), + __y.__x_ + __y.__i_)) + return false; + if (!_VSTD::equal(__x.__x_ + (__x.__i_ + __j), __x.__x_ + _Np, + __y.__x_)) + return false; + return _VSTD::equal(__x.__x_, __x.__x_ + __x.__i_, + __y.__x_ + (_Np - (__x.__i_ + __j))); + } + size_t __j = _Np - __x.__i_; + if (!_VSTD::equal(__y.__x_ + __y.__i_, __y.__x_ + (__y.__i_ + __j), + __x.__x_ + __x.__i_)) + return false; + if (!_VSTD::equal(__y.__x_ + (__y.__i_ + __j), __y.__x_ + _Np, + __x.__x_)) + return false; + return _VSTD::equal(__y.__x_, __y.__x_ + __y.__i_, + __x.__x_ + (_Np - (__y.__i_ + __j))); +} + +template <class _UInt, size_t _Wp, size_t _Np, size_t _Mp, size_t _Rp, + _UInt _Ap, size_t _Up, _UInt _Dp, size_t _Sp, + _UInt _Bp, size_t _Tp, _UInt _Cp, size_t _Lp, _UInt _Fp> +inline _LIBCPP_INLINE_VISIBILITY +bool +operator!=(const mersenne_twister_engine<_UInt, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp, + _Bp, _Tp, _Cp, _Lp, _Fp>& __x, + const mersenne_twister_engine<_UInt, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp, + _Bp, _Tp, _Cp, _Lp, _Fp>& __y) +{ + return !(__x == __y); +} + +template <class _CharT, class _Traits, + class _UInt, size_t _Wp, size_t _Np, size_t _Mp, size_t _Rp, + _UInt _Ap, size_t _Up, _UInt _Dp, size_t _Sp, + _UInt _Bp, size_t _Tp, _UInt _Cp, size_t _Lp, _UInt _Fp> +basic_ostream<_CharT, _Traits>& +operator<<(basic_ostream<_CharT, _Traits>& __os, + const mersenne_twister_engine<_UInt, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp, + _Bp, _Tp, _Cp, _Lp, _Fp>& __x) +{ + __save_flags<_CharT, _Traits> __lx(__os); + typedef basic_ostream<_CharT, _Traits> _Ostream; + __os.flags(_Ostream::dec | _Ostream::left); + _CharT __sp = __os.widen(' '); + __os.fill(__sp); + __os << __x.__x_[__x.__i_]; + for (size_t __j = __x.__i_ + 1; __j < _Np; ++__j) + __os << __sp << __x.__x_[__j]; + for (size_t __j = 0; __j < __x.__i_; ++__j) + __os << __sp << __x.__x_[__j]; + return __os; +} + +template <class _CharT, class _Traits, + class _UInt, size_t _Wp, size_t _Np, size_t _Mp, size_t _Rp, + _UInt _Ap, size_t _Up, _UInt _Dp, size_t _Sp, + _UInt _Bp, size_t _Tp, _UInt _Cp, size_t _Lp, _UInt _Fp> +basic_istream<_CharT, _Traits>& +operator>>(basic_istream<_CharT, _Traits>& __is, + mersenne_twister_engine<_UInt, _Wp, _Np, _Mp, _Rp, _Ap, _Up, _Dp, _Sp, + _Bp, _Tp, _Cp, _Lp, _Fp>& __x) +{ + __save_flags<_CharT, _Traits> __lx(__is); + typedef basic_istream<_CharT, _Traits> _Istream; + __is.flags(_Istream::dec | _Istream::skipws); + _UInt __t[_Np]; + for (size_t __i = 0; __i < _Np; ++__i) + __is >> __t[__i]; + if (!__is.fail()) + { + for (size_t __i = 0; __i < _Np; ++__i) + __x.__x_[__i] = __t[__i]; + __x.__i_ = 0; + } + return __is; +} + +typedef mersenne_twister_engine<uint_fast32_t, 32, 624, 397, 31, + 0x9908b0df, 11, 0xffffffff, + 7, 0x9d2c5680, + 15, 0xefc60000, + 18, 1812433253> mt19937; +typedef mersenne_twister_engine<uint_fast64_t, 64, 312, 156, 31, + 0xb5026f5aa96619e9ULL, 29, 0x5555555555555555ULL, + 17, 0x71d67fffeda60000ULL, + 37, 0xfff7eee000000000ULL, + 43, 6364136223846793005ULL> mt19937_64; + +_LIBCPP_END_NAMESPACE_STD + +_LIBCPP_POP_MACROS + +#endif // _LIBCPP___RANDOM_MERSENNE_TWISTER_ENGINE_H diff --git a/contrib/libs/cxxsupp/libcxxmsvc/include/__random/negative_binomial_distribution.h b/contrib/libs/cxxsupp/libcxxmsvc/include/__random/negative_binomial_distribution.h new file mode 100644 index 0000000000..01e9c303a7 --- /dev/null +++ b/contrib/libs/cxxsupp/libcxxmsvc/include/__random/negative_binomial_distribution.h @@ -0,0 +1,176 @@ +//===----------------------------------------------------------------------===// +// +// 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 _LIBCPP___RANDOM_NEGATIVE_BINOMIAL_DISTRIBUTION_H +#define _LIBCPP___RANDOM_NEGATIVE_BINOMIAL_DISTRIBUTION_H + +#include <__config> +#include <__random/bernoulli_distribution.h> +#include <__random/gamma_distribution.h> +#include <__random/poisson_distribution.h> +#include <iosfwd> +#include <limits> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +# pragma GCC system_header +#endif + +_LIBCPP_PUSH_MACROS +#include <__undef_macros> + +_LIBCPP_BEGIN_NAMESPACE_STD + +template<class _IntType = int> +class _LIBCPP_TEMPLATE_VIS negative_binomial_distribution +{ +public: + // types + typedef _IntType result_type; + + class _LIBCPP_TEMPLATE_VIS param_type + { + result_type __k_; + double __p_; + public: + typedef negative_binomial_distribution distribution_type; + + _LIBCPP_INLINE_VISIBILITY + explicit param_type(result_type __k = 1, double __p = 0.5) + : __k_(__k), __p_(__p) {} + + _LIBCPP_INLINE_VISIBILITY + result_type k() const {return __k_;} + _LIBCPP_INLINE_VISIBILITY + double p() const {return __p_;} + + friend _LIBCPP_INLINE_VISIBILITY + bool operator==(const param_type& __x, const param_type& __y) + {return __x.__k_ == __y.__k_ && __x.__p_ == __y.__p_;} + friend _LIBCPP_INLINE_VISIBILITY + bool operator!=(const param_type& __x, const param_type& __y) + {return !(__x == __y);} + }; + +private: + param_type __p_; + +public: + // constructor and reset functions +#ifndef _LIBCPP_CXX03_LANG + _LIBCPP_INLINE_VISIBILITY + negative_binomial_distribution() : negative_binomial_distribution(1) {} + _LIBCPP_INLINE_VISIBILITY + explicit negative_binomial_distribution(result_type __k, double __p = 0.5) + : __p_(__k, __p) {} +#else + _LIBCPP_INLINE_VISIBILITY + explicit negative_binomial_distribution(result_type __k = 1, + double __p = 0.5) + : __p_(__k, __p) {} +#endif + _LIBCPP_INLINE_VISIBILITY + explicit negative_binomial_distribution(const param_type& __p) : __p_(__p) {} + _LIBCPP_INLINE_VISIBILITY + void reset() {} + + // generating functions + template<class _URNG> + _LIBCPP_INLINE_VISIBILITY + result_type operator()(_URNG& __g) + {return (*this)(__g, __p_);} + template<class _URNG> result_type operator()(_URNG& __g, const param_type& __p); + + // property functions + _LIBCPP_INLINE_VISIBILITY + result_type k() const {return __p_.k();} + _LIBCPP_INLINE_VISIBILITY + double p() const {return __p_.p();} + + _LIBCPP_INLINE_VISIBILITY + param_type param() const {return __p_;} + _LIBCPP_INLINE_VISIBILITY + void param(const param_type& __p) {__p_ = __p;} + + _LIBCPP_INLINE_VISIBILITY + result_type min() const {return 0;} + _LIBCPP_INLINE_VISIBILITY + result_type max() const {return numeric_limits<result_type>::max();} + + friend _LIBCPP_INLINE_VISIBILITY + bool operator==(const negative_binomial_distribution& __x, + const negative_binomial_distribution& __y) + {return __x.__p_ == __y.__p_;} + friend _LIBCPP_INLINE_VISIBILITY + bool operator!=(const negative_binomial_distribution& __x, + const negative_binomial_distribution& __y) + {return !(__x == __y);} +}; + +template <class _IntType> +template<class _URNG> +_IntType +negative_binomial_distribution<_IntType>::operator()(_URNG& __urng, const param_type& __pr) +{ + result_type __k = __pr.k(); + double __p = __pr.p(); + if (__k <= 21 * __p) + { + bernoulli_distribution __gen(__p); + result_type __f = 0; + result_type __s = 0; + while (__s < __k) + { + if (__gen(__urng)) + ++__s; + else + ++__f; + } + return __f; + } + return poisson_distribution<result_type>(gamma_distribution<double> + (__k, (1-__p)/__p)(__urng))(__urng); +} + +template <class _CharT, class _Traits, class _IntType> +basic_ostream<_CharT, _Traits>& +operator<<(basic_ostream<_CharT, _Traits>& __os, + const negative_binomial_distribution<_IntType>& __x) +{ + __save_flags<_CharT, _Traits> __lx(__os); + typedef basic_ostream<_CharT, _Traits> _OStream; + __os.flags(_OStream::dec | _OStream::left | _OStream::fixed | + _OStream::scientific); + _CharT __sp = __os.widen(' '); + __os.fill(__sp); + return __os << __x.k() << __sp << __x.p(); +} + +template <class _CharT, class _Traits, class _IntType> +basic_istream<_CharT, _Traits>& +operator>>(basic_istream<_CharT, _Traits>& __is, + negative_binomial_distribution<_IntType>& __x) +{ + typedef negative_binomial_distribution<_IntType> _Eng; + typedef typename _Eng::result_type result_type; + typedef typename _Eng::param_type param_type; + __save_flags<_CharT, _Traits> __lx(__is); + typedef basic_istream<_CharT, _Traits> _Istream; + __is.flags(_Istream::dec | _Istream::skipws); + result_type __k; + double __p; + __is >> __k >> __p; + if (!__is.fail()) + __x.param(param_type(__k, __p)); + return __is; +} + +_LIBCPP_END_NAMESPACE_STD + +_LIBCPP_POP_MACROS + +#endif // _LIBCPP___RANDOM_NEGATIVE_BINOMIAL_DISTRIBUTION_H diff --git a/contrib/libs/cxxsupp/libcxxmsvc/include/__random/normal_distribution.h b/contrib/libs/cxxsupp/libcxxmsvc/include/__random/normal_distribution.h new file mode 100644 index 0000000000..dc4de78e92 --- /dev/null +++ b/contrib/libs/cxxsupp/libcxxmsvc/include/__random/normal_distribution.h @@ -0,0 +1,208 @@ +//===----------------------------------------------------------------------===// +// +// 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 _LIBCPP___RANDOM_NORMAL_DISTRIBUTION_H +#define _LIBCPP___RANDOM_NORMAL_DISTRIBUTION_H + +#include <__config> +#include <__random/uniform_real_distribution.h> +#include <cmath> +#include <iosfwd> +#include <limits> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +# pragma GCC system_header +#endif + +_LIBCPP_PUSH_MACROS +#include <__undef_macros> + +_LIBCPP_BEGIN_NAMESPACE_STD + +template<class _RealType = double> +class _LIBCPP_TEMPLATE_VIS normal_distribution +{ +public: + // types + typedef _RealType result_type; + + class _LIBCPP_TEMPLATE_VIS param_type + { + result_type __mean_; + result_type __stddev_; + public: + typedef normal_distribution distribution_type; + + _LIBCPP_INLINE_VISIBILITY + explicit param_type(result_type __mean = 0, result_type __stddev = 1) + : __mean_(__mean), __stddev_(__stddev) {} + + _LIBCPP_INLINE_VISIBILITY + result_type mean() const {return __mean_;} + _LIBCPP_INLINE_VISIBILITY + result_type stddev() const {return __stddev_;} + + friend _LIBCPP_INLINE_VISIBILITY + bool operator==(const param_type& __x, const param_type& __y) + {return __x.__mean_ == __y.__mean_ && __x.__stddev_ == __y.__stddev_;} + friend _LIBCPP_INLINE_VISIBILITY + bool operator!=(const param_type& __x, const param_type& __y) + {return !(__x == __y);} + }; + +private: + param_type __p_; + result_type _V_; + bool _V_hot_; + +public: + // constructors and reset functions +#ifndef _LIBCPP_CXX03_LANG + _LIBCPP_INLINE_VISIBILITY + normal_distribution() : normal_distribution(0) {} + _LIBCPP_INLINE_VISIBILITY + explicit normal_distribution(result_type __mean, result_type __stddev = 1) + : __p_(param_type(__mean, __stddev)), _V_hot_(false) {} +#else + _LIBCPP_INLINE_VISIBILITY + explicit normal_distribution(result_type __mean = 0, + result_type __stddev = 1) + : __p_(param_type(__mean, __stddev)), _V_hot_(false) {} +#endif + _LIBCPP_INLINE_VISIBILITY + explicit normal_distribution(const param_type& __p) + : __p_(__p), _V_hot_(false) {} + _LIBCPP_INLINE_VISIBILITY + void reset() {_V_hot_ = false;} + + // generating functions + template<class _URNG> + _LIBCPP_INLINE_VISIBILITY + result_type operator()(_URNG& __g) + {return (*this)(__g, __p_);} + template<class _URNG> result_type operator()(_URNG& __g, const param_type& __p); + + // property functions + _LIBCPP_INLINE_VISIBILITY + result_type mean() const {return __p_.mean();} + _LIBCPP_INLINE_VISIBILITY + result_type stddev() const {return __p_.stddev();} + + _LIBCPP_INLINE_VISIBILITY + param_type param() const {return __p_;} + _LIBCPP_INLINE_VISIBILITY + void param(const param_type& __p) {__p_ = __p;} + + _LIBCPP_INLINE_VISIBILITY + result_type min() const {return -numeric_limits<result_type>::infinity();} + _LIBCPP_INLINE_VISIBILITY + result_type max() const {return numeric_limits<result_type>::infinity();} + + friend _LIBCPP_INLINE_VISIBILITY + bool operator==(const normal_distribution& __x, + const normal_distribution& __y) + {return __x.__p_ == __y.__p_ && __x._V_hot_ == __y._V_hot_ && + (!__x._V_hot_ || __x._V_ == __y._V_);} + friend _LIBCPP_INLINE_VISIBILITY + bool operator!=(const normal_distribution& __x, + const normal_distribution& __y) + {return !(__x == __y);} + + template <class _CharT, class _Traits, class _RT> + friend + basic_ostream<_CharT, _Traits>& + operator<<(basic_ostream<_CharT, _Traits>& __os, + const normal_distribution<_RT>& __x); + + template <class _CharT, class _Traits, class _RT> + friend + basic_istream<_CharT, _Traits>& + operator>>(basic_istream<_CharT, _Traits>& __is, + normal_distribution<_RT>& __x); +}; + +template <class _RealType> +template<class _URNG> +_RealType +normal_distribution<_RealType>::operator()(_URNG& __g, const param_type& __p) +{ + result_type _Up; + if (_V_hot_) + { + _V_hot_ = false; + _Up = _V_; + } + else + { + uniform_real_distribution<result_type> _Uni(-1, 1); + result_type __u; + result_type __v; + result_type __s; + do + { + __u = _Uni(__g); + __v = _Uni(__g); + __s = __u * __u + __v * __v; + } while (__s > 1 || __s == 0); + result_type _Fp = _VSTD::sqrt(-2 * _VSTD::log(__s) / __s); + _V_ = __v * _Fp; + _V_hot_ = true; + _Up = __u * _Fp; + } + return _Up * __p.stddev() + __p.mean(); +} + +template <class _CharT, class _Traits, class _RT> +basic_ostream<_CharT, _Traits>& +operator<<(basic_ostream<_CharT, _Traits>& __os, + const normal_distribution<_RT>& __x) +{ + __save_flags<_CharT, _Traits> __lx(__os); + typedef basic_ostream<_CharT, _Traits> _OStream; + __os.flags(_OStream::dec | _OStream::left | _OStream::fixed | + _OStream::scientific); + _CharT __sp = __os.widen(' '); + __os.fill(__sp); + __os << __x.mean() << __sp << __x.stddev() << __sp << __x._V_hot_; + if (__x._V_hot_) + __os << __sp << __x._V_; + return __os; +} + +template <class _CharT, class _Traits, class _RT> +basic_istream<_CharT, _Traits>& +operator>>(basic_istream<_CharT, _Traits>& __is, + normal_distribution<_RT>& __x) +{ + typedef normal_distribution<_RT> _Eng; + typedef typename _Eng::result_type result_type; + typedef typename _Eng::param_type param_type; + __save_flags<_CharT, _Traits> __lx(__is); + typedef basic_istream<_CharT, _Traits> _Istream; + __is.flags(_Istream::dec | _Istream::skipws); + result_type __mean; + result_type __stddev; + result_type _Vp = 0; + bool _V_hot = false; + __is >> __mean >> __stddev >> _V_hot; + if (_V_hot) + __is >> _Vp; + if (!__is.fail()) + { + __x.param(param_type(__mean, __stddev)); + __x._V_hot_ = _V_hot; + __x._V_ = _Vp; + } + return __is; +} + +_LIBCPP_END_NAMESPACE_STD + +_LIBCPP_POP_MACROS + +#endif // _LIBCPP___RANDOM_NORMAL_DISTRIBUTION_H diff --git a/contrib/libs/cxxsupp/libcxxmsvc/include/__random/piecewise_constant_distribution.h b/contrib/libs/cxxsupp/libcxxmsvc/include/__random/piecewise_constant_distribution.h new file mode 100644 index 0000000000..eec9b7540a --- /dev/null +++ b/contrib/libs/cxxsupp/libcxxmsvc/include/__random/piecewise_constant_distribution.h @@ -0,0 +1,356 @@ +//===----------------------------------------------------------------------===// +// +// 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 _LIBCPP___RANDOM_PIECEWISE_CONSTANT_DISTRIBUTION_H +#define _LIBCPP___RANDOM_PIECEWISE_CONSTANT_DISTRIBUTION_H + +#include <__algorithm/upper_bound.h> +#include <__config> +#include <__random/uniform_real_distribution.h> +#include <iosfwd> +#include <numeric> +#include <vector> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +# pragma GCC system_header +#endif + +_LIBCPP_PUSH_MACROS +#include <__undef_macros> + +_LIBCPP_BEGIN_NAMESPACE_STD + +template<class _RealType = double> +class _LIBCPP_TEMPLATE_VIS piecewise_constant_distribution +{ +public: + // types + typedef _RealType result_type; + + class _LIBCPP_TEMPLATE_VIS param_type + { + vector<result_type> __b_; + vector<result_type> __densities_; + vector<result_type> __areas_; + public: + typedef piecewise_constant_distribution distribution_type; + + param_type(); + template<class _InputIteratorB, class _InputIteratorW> + param_type(_InputIteratorB __fB, _InputIteratorB __lB, + _InputIteratorW __fW); +#ifndef _LIBCPP_CXX03_LANG + template<class _UnaryOperation> + param_type(initializer_list<result_type> __bl, _UnaryOperation __fw); +#endif // _LIBCPP_CXX03_LANG + template<class _UnaryOperation> + param_type(size_t __nw, result_type __xmin, result_type __xmax, + _UnaryOperation __fw); + param_type(param_type const&) = default; + param_type & operator=(const param_type& __rhs); + + _LIBCPP_INLINE_VISIBILITY + vector<result_type> intervals() const {return __b_;} + _LIBCPP_INLINE_VISIBILITY + vector<result_type> densities() const {return __densities_;} + + friend _LIBCPP_INLINE_VISIBILITY + bool operator==(const param_type& __x, const param_type& __y) + {return __x.__densities_ == __y.__densities_ && __x.__b_ == __y.__b_;} + friend _LIBCPP_INLINE_VISIBILITY + bool operator!=(const param_type& __x, const param_type& __y) + {return !(__x == __y);} + + private: + void __init(); + + friend class piecewise_constant_distribution; + + template <class _CharT, class _Traits, class _RT> + friend + basic_ostream<_CharT, _Traits>& + operator<<(basic_ostream<_CharT, _Traits>& __os, + const piecewise_constant_distribution<_RT>& __x); + + template <class _CharT, class _Traits, class _RT> + friend + basic_istream<_CharT, _Traits>& + operator>>(basic_istream<_CharT, _Traits>& __is, + piecewise_constant_distribution<_RT>& __x); + }; + +private: + param_type __p_; + +public: + // constructor and reset functions + _LIBCPP_INLINE_VISIBILITY + piecewise_constant_distribution() {} + template<class _InputIteratorB, class _InputIteratorW> + _LIBCPP_INLINE_VISIBILITY + piecewise_constant_distribution(_InputIteratorB __fB, + _InputIteratorB __lB, + _InputIteratorW __fW) + : __p_(__fB, __lB, __fW) {} + +#ifndef _LIBCPP_CXX03_LANG + template<class _UnaryOperation> + _LIBCPP_INLINE_VISIBILITY + piecewise_constant_distribution(initializer_list<result_type> __bl, + _UnaryOperation __fw) + : __p_(__bl, __fw) {} +#endif // _LIBCPP_CXX03_LANG + + template<class _UnaryOperation> + _LIBCPP_INLINE_VISIBILITY + piecewise_constant_distribution(size_t __nw, result_type __xmin, + result_type __xmax, _UnaryOperation __fw) + : __p_(__nw, __xmin, __xmax, __fw) {} + + _LIBCPP_INLINE_VISIBILITY + explicit piecewise_constant_distribution(const param_type& __p) + : __p_(__p) {} + + _LIBCPP_INLINE_VISIBILITY + void reset() {} + + // generating functions + template<class _URNG> + _LIBCPP_INLINE_VISIBILITY + result_type operator()(_URNG& __g) + {return (*this)(__g, __p_);} + template<class _URNG> result_type operator()(_URNG& __g, const param_type& __p); + + // property functions + _LIBCPP_INLINE_VISIBILITY + vector<result_type> intervals() const {return __p_.intervals();} + _LIBCPP_INLINE_VISIBILITY + vector<result_type> densities() const {return __p_.densities();} + + _LIBCPP_INLINE_VISIBILITY + param_type param() const {return __p_;} + _LIBCPP_INLINE_VISIBILITY + void param(const param_type& __p) {__p_ = __p;} + + _LIBCPP_INLINE_VISIBILITY + result_type min() const {return __p_.__b_.front();} + _LIBCPP_INLINE_VISIBILITY + result_type max() const {return __p_.__b_.back();} + + friend _LIBCPP_INLINE_VISIBILITY + bool operator==(const piecewise_constant_distribution& __x, + const piecewise_constant_distribution& __y) + {return __x.__p_ == __y.__p_;} + friend _LIBCPP_INLINE_VISIBILITY + bool operator!=(const piecewise_constant_distribution& __x, + const piecewise_constant_distribution& __y) + {return !(__x == __y);} + + template <class _CharT, class _Traits, class _RT> + friend + basic_ostream<_CharT, _Traits>& + operator<<(basic_ostream<_CharT, _Traits>& __os, + const piecewise_constant_distribution<_RT>& __x); + + template <class _CharT, class _Traits, class _RT> + friend + basic_istream<_CharT, _Traits>& + operator>>(basic_istream<_CharT, _Traits>& __is, + piecewise_constant_distribution<_RT>& __x); +}; + +template<class _RealType> +typename piecewise_constant_distribution<_RealType>::param_type & +piecewise_constant_distribution<_RealType>::param_type::operator= + (const param_type& __rhs) +{ +// These can throw + __b_.reserve (__rhs.__b_.size ()); + __densities_.reserve(__rhs.__densities_.size()); + __areas_.reserve (__rhs.__areas_.size()); + +// These can not throw + __b_ = __rhs.__b_; + __densities_ = __rhs.__densities_; + __areas_ = __rhs.__areas_; + return *this; +} + +template<class _RealType> +void +piecewise_constant_distribution<_RealType>::param_type::__init() +{ + // __densities_ contains non-normalized areas + result_type __total_area = _VSTD::accumulate(__densities_.begin(), + __densities_.end(), + result_type()); + for (size_t __i = 0; __i < __densities_.size(); ++__i) + __densities_[__i] /= __total_area; + // __densities_ contains normalized areas + __areas_.assign(__densities_.size(), result_type()); + _VSTD::partial_sum(__densities_.begin(), __densities_.end() - 1, + __areas_.begin() + 1); + // __areas_ contains partial sums of normalized areas: [0, __densities_ - 1] + __densities_.back() = 1 - __areas_.back(); // correct round off error + for (size_t __i = 0; __i < __densities_.size(); ++__i) + __densities_[__i] /= (__b_[__i+1] - __b_[__i]); + // __densities_ now contains __densities_ +} + +template<class _RealType> +piecewise_constant_distribution<_RealType>::param_type::param_type() + : __b_(2), + __densities_(1, 1.0), + __areas_(1, 0.0) +{ + __b_[1] = 1; +} + +template<class _RealType> +template<class _InputIteratorB, class _InputIteratorW> +piecewise_constant_distribution<_RealType>::param_type::param_type( + _InputIteratorB __fB, _InputIteratorB __lB, _InputIteratorW __fW) + : __b_(__fB, __lB) +{ + if (__b_.size() < 2) + { + __b_.resize(2); + __b_[0] = 0; + __b_[1] = 1; + __densities_.assign(1, 1.0); + __areas_.assign(1, 0.0); + } + else + { + __densities_.reserve(__b_.size() - 1); + for (size_t __i = 0; __i < __b_.size() - 1; ++__i, ++__fW) + __densities_.push_back(*__fW); + __init(); + } +} + +#ifndef _LIBCPP_CXX03_LANG + +template<class _RealType> +template<class _UnaryOperation> +piecewise_constant_distribution<_RealType>::param_type::param_type( + initializer_list<result_type> __bl, _UnaryOperation __fw) + : __b_(__bl.begin(), __bl.end()) +{ + if (__b_.size() < 2) + { + __b_.resize(2); + __b_[0] = 0; + __b_[1] = 1; + __densities_.assign(1, 1.0); + __areas_.assign(1, 0.0); + } + else + { + __densities_.reserve(__b_.size() - 1); + for (size_t __i = 0; __i < __b_.size() - 1; ++__i) + __densities_.push_back(__fw((__b_[__i+1] + __b_[__i])*.5)); + __init(); + } +} + +#endif // _LIBCPP_CXX03_LANG + +template<class _RealType> +template<class _UnaryOperation> +piecewise_constant_distribution<_RealType>::param_type::param_type( + size_t __nw, result_type __xmin, result_type __xmax, _UnaryOperation __fw) + : __b_(__nw == 0 ? 2 : __nw + 1) +{ + size_t __n = __b_.size() - 1; + result_type __d = (__xmax - __xmin) / __n; + __densities_.reserve(__n); + for (size_t __i = 0; __i < __n; ++__i) + { + __b_[__i] = __xmin + __i * __d; + __densities_.push_back(__fw(__b_[__i] + __d*.5)); + } + __b_[__n] = __xmax; + __init(); +} + +template<class _RealType> +template<class _URNG> +_RealType +piecewise_constant_distribution<_RealType>::operator()(_URNG& __g, const param_type& __p) +{ + typedef uniform_real_distribution<result_type> _Gen; + result_type __u = _Gen()(__g); + ptrdiff_t __k = _VSTD::upper_bound(__p.__areas_.begin(), __p.__areas_.end(), + __u) - __p.__areas_.begin() - 1; + return (__u - __p.__areas_[__k]) / __p.__densities_[__k] + __p.__b_[__k]; +} + +template <class _CharT, class _Traits, class _RT> +basic_ostream<_CharT, _Traits>& +operator<<(basic_ostream<_CharT, _Traits>& __os, + const piecewise_constant_distribution<_RT>& __x) +{ + __save_flags<_CharT, _Traits> __lx(__os); + typedef basic_ostream<_CharT, _Traits> _OStream; + __os.flags(_OStream::dec | _OStream::left | _OStream::fixed | + _OStream::scientific); + _CharT __sp = __os.widen(' '); + __os.fill(__sp); + size_t __n = __x.__p_.__b_.size(); + __os << __n; + for (size_t __i = 0; __i < __n; ++__i) + __os << __sp << __x.__p_.__b_[__i]; + __n = __x.__p_.__densities_.size(); + __os << __sp << __n; + for (size_t __i = 0; __i < __n; ++__i) + __os << __sp << __x.__p_.__densities_[__i]; + __n = __x.__p_.__areas_.size(); + __os << __sp << __n; + for (size_t __i = 0; __i < __n; ++__i) + __os << __sp << __x.__p_.__areas_[__i]; + return __os; +} + +template <class _CharT, class _Traits, class _RT> +basic_istream<_CharT, _Traits>& +operator>>(basic_istream<_CharT, _Traits>& __is, + piecewise_constant_distribution<_RT>& __x) +{ + typedef piecewise_constant_distribution<_RT> _Eng; + typedef typename _Eng::result_type result_type; + __save_flags<_CharT, _Traits> __lx(__is); + typedef basic_istream<_CharT, _Traits> _Istream; + __is.flags(_Istream::dec | _Istream::skipws); + size_t __n; + __is >> __n; + vector<result_type> __b(__n); + for (size_t __i = 0; __i < __n; ++__i) + __is >> __b[__i]; + __is >> __n; + vector<result_type> __densities(__n); + for (size_t __i = 0; __i < __n; ++__i) + __is >> __densities[__i]; + __is >> __n; + vector<result_type> __areas(__n); + for (size_t __i = 0; __i < __n; ++__i) + __is >> __areas[__i]; + if (!__is.fail()) + { + swap(__x.__p_.__b_, __b); + swap(__x.__p_.__densities_, __densities); + swap(__x.__p_.__areas_, __areas); + } + return __is; +} + +_LIBCPP_END_NAMESPACE_STD + +_LIBCPP_POP_MACROS + +#endif // _LIBCPP___RANDOM_PIECEWISE_CONSTANT_DISTRIBUTION_H diff --git a/contrib/libs/cxxsupp/libcxxmsvc/include/__random/piecewise_linear_distribution.h b/contrib/libs/cxxsupp/libcxxmsvc/include/__random/piecewise_linear_distribution.h new file mode 100644 index 0000000000..0d7591af10 --- /dev/null +++ b/contrib/libs/cxxsupp/libcxxmsvc/include/__random/piecewise_linear_distribution.h @@ -0,0 +1,372 @@ +//===----------------------------------------------------------------------===// +// +// 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 _LIBCPP___RANDOM_PIECEWISE_LINEAR_DISTRIBUTION_H +#define _LIBCPP___RANDOM_PIECEWISE_LINEAR_DISTRIBUTION_H + +#include <__algorithm/upper_bound.h> +#include <__config> +#include <__random/uniform_real_distribution.h> +#include <iosfwd> +#include <numeric> +#include <vector> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +# pragma GCC system_header +#endif + +_LIBCPP_PUSH_MACROS +#include <__undef_macros> + +_LIBCPP_BEGIN_NAMESPACE_STD + +template<class _RealType = double> +class _LIBCPP_TEMPLATE_VIS piecewise_linear_distribution +{ +public: + // types + typedef _RealType result_type; + + class _LIBCPP_TEMPLATE_VIS param_type + { + vector<result_type> __b_; + vector<result_type> __densities_; + vector<result_type> __areas_; + public: + typedef piecewise_linear_distribution distribution_type; + + param_type(); + template<class _InputIteratorB, class _InputIteratorW> + param_type(_InputIteratorB __fB, _InputIteratorB __lB, + _InputIteratorW __fW); +#ifndef _LIBCPP_CXX03_LANG + template<class _UnaryOperation> + param_type(initializer_list<result_type> __bl, _UnaryOperation __fw); +#endif // _LIBCPP_CXX03_LANG + template<class _UnaryOperation> + param_type(size_t __nw, result_type __xmin, result_type __xmax, + _UnaryOperation __fw); + param_type(param_type const&) = default; + param_type & operator=(const param_type& __rhs); + + _LIBCPP_INLINE_VISIBILITY + vector<result_type> intervals() const {return __b_;} + _LIBCPP_INLINE_VISIBILITY + vector<result_type> densities() const {return __densities_;} + + friend _LIBCPP_INLINE_VISIBILITY + bool operator==(const param_type& __x, const param_type& __y) + {return __x.__densities_ == __y.__densities_ && __x.__b_ == __y.__b_;} + friend _LIBCPP_INLINE_VISIBILITY + bool operator!=(const param_type& __x, const param_type& __y) + {return !(__x == __y);} + + private: + void __init(); + + friend class piecewise_linear_distribution; + + template <class _CharT, class _Traits, class _RT> + friend + basic_ostream<_CharT, _Traits>& + operator<<(basic_ostream<_CharT, _Traits>& __os, + const piecewise_linear_distribution<_RT>& __x); + + template <class _CharT, class _Traits, class _RT> + friend + basic_istream<_CharT, _Traits>& + operator>>(basic_istream<_CharT, _Traits>& __is, + piecewise_linear_distribution<_RT>& __x); + }; + +private: + param_type __p_; + +public: + // constructor and reset functions + _LIBCPP_INLINE_VISIBILITY + piecewise_linear_distribution() {} + template<class _InputIteratorB, class _InputIteratorW> + _LIBCPP_INLINE_VISIBILITY + piecewise_linear_distribution(_InputIteratorB __fB, + _InputIteratorB __lB, + _InputIteratorW __fW) + : __p_(__fB, __lB, __fW) {} + +#ifndef _LIBCPP_CXX03_LANG + template<class _UnaryOperation> + _LIBCPP_INLINE_VISIBILITY + piecewise_linear_distribution(initializer_list<result_type> __bl, + _UnaryOperation __fw) + : __p_(__bl, __fw) {} +#endif // _LIBCPP_CXX03_LANG + + template<class _UnaryOperation> + _LIBCPP_INLINE_VISIBILITY + piecewise_linear_distribution(size_t __nw, result_type __xmin, + result_type __xmax, _UnaryOperation __fw) + : __p_(__nw, __xmin, __xmax, __fw) {} + + _LIBCPP_INLINE_VISIBILITY + explicit piecewise_linear_distribution(const param_type& __p) + : __p_(__p) {} + + _LIBCPP_INLINE_VISIBILITY + void reset() {} + + // generating functions + template<class _URNG> + _LIBCPP_INLINE_VISIBILITY + result_type operator()(_URNG& __g) + {return (*this)(__g, __p_);} + template<class _URNG> result_type operator()(_URNG& __g, const param_type& __p); + + // property functions + _LIBCPP_INLINE_VISIBILITY + vector<result_type> intervals() const {return __p_.intervals();} + _LIBCPP_INLINE_VISIBILITY + vector<result_type> densities() const {return __p_.densities();} + + _LIBCPP_INLINE_VISIBILITY + param_type param() const {return __p_;} + _LIBCPP_INLINE_VISIBILITY + void param(const param_type& __p) {__p_ = __p;} + + _LIBCPP_INLINE_VISIBILITY + result_type min() const {return __p_.__b_.front();} + _LIBCPP_INLINE_VISIBILITY + result_type max() const {return __p_.__b_.back();} + + friend _LIBCPP_INLINE_VISIBILITY + bool operator==(const piecewise_linear_distribution& __x, + const piecewise_linear_distribution& __y) + {return __x.__p_ == __y.__p_;} + friend _LIBCPP_INLINE_VISIBILITY + bool operator!=(const piecewise_linear_distribution& __x, + const piecewise_linear_distribution& __y) + {return !(__x == __y);} + + template <class _CharT, class _Traits, class _RT> + friend + basic_ostream<_CharT, _Traits>& + operator<<(basic_ostream<_CharT, _Traits>& __os, + const piecewise_linear_distribution<_RT>& __x); + + template <class _CharT, class _Traits, class _RT> + friend + basic_istream<_CharT, _Traits>& + operator>>(basic_istream<_CharT, _Traits>& __is, + piecewise_linear_distribution<_RT>& __x); +}; + +template<class _RealType> +typename piecewise_linear_distribution<_RealType>::param_type & +piecewise_linear_distribution<_RealType>::param_type::operator= + (const param_type& __rhs) +{ +// These can throw + __b_.reserve (__rhs.__b_.size ()); + __densities_.reserve(__rhs.__densities_.size()); + __areas_.reserve (__rhs.__areas_.size()); + +// These can not throw + __b_ = __rhs.__b_; + __densities_ = __rhs.__densities_; + __areas_ = __rhs.__areas_; + return *this; +} + + +template<class _RealType> +void +piecewise_linear_distribution<_RealType>::param_type::__init() +{ + __areas_.assign(__densities_.size() - 1, result_type()); + result_type _Sp = 0; + for (size_t __i = 0; __i < __areas_.size(); ++__i) + { + __areas_[__i] = (__densities_[__i+1] + __densities_[__i]) * + (__b_[__i+1] - __b_[__i]) * .5; + _Sp += __areas_[__i]; + } + for (size_t __i = __areas_.size(); __i > 1;) + { + --__i; + __areas_[__i] = __areas_[__i-1] / _Sp; + } + __areas_[0] = 0; + for (size_t __i = 1; __i < __areas_.size(); ++__i) + __areas_[__i] += __areas_[__i-1]; + for (size_t __i = 0; __i < __densities_.size(); ++__i) + __densities_[__i] /= _Sp; +} + +template<class _RealType> +piecewise_linear_distribution<_RealType>::param_type::param_type() + : __b_(2), + __densities_(2, 1.0), + __areas_(1, 0.0) +{ + __b_[1] = 1; +} + +template<class _RealType> +template<class _InputIteratorB, class _InputIteratorW> +piecewise_linear_distribution<_RealType>::param_type::param_type( + _InputIteratorB __fB, _InputIteratorB __lB, _InputIteratorW __fW) + : __b_(__fB, __lB) +{ + if (__b_.size() < 2) + { + __b_.resize(2); + __b_[0] = 0; + __b_[1] = 1; + __densities_.assign(2, 1.0); + __areas_.assign(1, 0.0); + } + else + { + __densities_.reserve(__b_.size()); + for (size_t __i = 0; __i < __b_.size(); ++__i, ++__fW) + __densities_.push_back(*__fW); + __init(); + } +} + +#ifndef _LIBCPP_CXX03_LANG + +template<class _RealType> +template<class _UnaryOperation> +piecewise_linear_distribution<_RealType>::param_type::param_type( + initializer_list<result_type> __bl, _UnaryOperation __fw) + : __b_(__bl.begin(), __bl.end()) +{ + if (__b_.size() < 2) + { + __b_.resize(2); + __b_[0] = 0; + __b_[1] = 1; + __densities_.assign(2, 1.0); + __areas_.assign(1, 0.0); + } + else + { + __densities_.reserve(__b_.size()); + for (size_t __i = 0; __i < __b_.size(); ++__i) + __densities_.push_back(__fw(__b_[__i])); + __init(); + } +} + +#endif // _LIBCPP_CXX03_LANG + +template<class _RealType> +template<class _UnaryOperation> +piecewise_linear_distribution<_RealType>::param_type::param_type( + size_t __nw, result_type __xmin, result_type __xmax, _UnaryOperation __fw) + : __b_(__nw == 0 ? 2 : __nw + 1) +{ + size_t __n = __b_.size() - 1; + result_type __d = (__xmax - __xmin) / __n; + __densities_.reserve(__b_.size()); + for (size_t __i = 0; __i < __n; ++__i) + { + __b_[__i] = __xmin + __i * __d; + __densities_.push_back(__fw(__b_[__i])); + } + __b_[__n] = __xmax; + __densities_.push_back(__fw(__b_[__n])); + __init(); +} + +template<class _RealType> +template<class _URNG> +_RealType +piecewise_linear_distribution<_RealType>::operator()(_URNG& __g, const param_type& __p) +{ + typedef uniform_real_distribution<result_type> _Gen; + result_type __u = _Gen()(__g); + ptrdiff_t __k = _VSTD::upper_bound(__p.__areas_.begin(), __p.__areas_.end(), + __u) - __p.__areas_.begin() - 1; + __u -= __p.__areas_[__k]; + const result_type __dk = __p.__densities_[__k]; + const result_type __dk1 = __p.__densities_[__k+1]; + const result_type __deltad = __dk1 - __dk; + const result_type __bk = __p.__b_[__k]; + if (__deltad == 0) + return __u / __dk + __bk; + const result_type __bk1 = __p.__b_[__k+1]; + const result_type __deltab = __bk1 - __bk; + return (__bk * __dk1 - __bk1 * __dk + + _VSTD::sqrt(__deltab * (__deltab * __dk * __dk + 2 * __deltad * __u))) / + __deltad; +} + +template <class _CharT, class _Traits, class _RT> +basic_ostream<_CharT, _Traits>& +operator<<(basic_ostream<_CharT, _Traits>& __os, + const piecewise_linear_distribution<_RT>& __x) +{ + __save_flags<_CharT, _Traits> __lx(__os); + typedef basic_ostream<_CharT, _Traits> _OStream; + __os.flags(_OStream::dec | _OStream::left | _OStream::fixed | + _OStream::scientific); + _CharT __sp = __os.widen(' '); + __os.fill(__sp); + size_t __n = __x.__p_.__b_.size(); + __os << __n; + for (size_t __i = 0; __i < __n; ++__i) + __os << __sp << __x.__p_.__b_[__i]; + __n = __x.__p_.__densities_.size(); + __os << __sp << __n; + for (size_t __i = 0; __i < __n; ++__i) + __os << __sp << __x.__p_.__densities_[__i]; + __n = __x.__p_.__areas_.size(); + __os << __sp << __n; + for (size_t __i = 0; __i < __n; ++__i) + __os << __sp << __x.__p_.__areas_[__i]; + return __os; +} + +template <class _CharT, class _Traits, class _RT> +basic_istream<_CharT, _Traits>& +operator>>(basic_istream<_CharT, _Traits>& __is, + piecewise_linear_distribution<_RT>& __x) +{ + typedef piecewise_linear_distribution<_RT> _Eng; + typedef typename _Eng::result_type result_type; + __save_flags<_CharT, _Traits> __lx(__is); + typedef basic_istream<_CharT, _Traits> _Istream; + __is.flags(_Istream::dec | _Istream::skipws); + size_t __n; + __is >> __n; + vector<result_type> __b(__n); + for (size_t __i = 0; __i < __n; ++__i) + __is >> __b[__i]; + __is >> __n; + vector<result_type> __densities(__n); + for (size_t __i = 0; __i < __n; ++__i) + __is >> __densities[__i]; + __is >> __n; + vector<result_type> __areas(__n); + for (size_t __i = 0; __i < __n; ++__i) + __is >> __areas[__i]; + if (!__is.fail()) + { + swap(__x.__p_.__b_, __b); + swap(__x.__p_.__densities_, __densities); + swap(__x.__p_.__areas_, __areas); + } + return __is; +} + +_LIBCPP_END_NAMESPACE_STD + +_LIBCPP_POP_MACROS + +#endif // _LIBCPP___RANDOM_PIECEWISE_LINEAR_DISTRIBUTION_H diff --git a/contrib/libs/cxxsupp/libcxxmsvc/include/__random/poisson_distribution.h b/contrib/libs/cxxsupp/libcxxmsvc/include/__random/poisson_distribution.h new file mode 100644 index 0000000000..c54d783b7c --- /dev/null +++ b/contrib/libs/cxxsupp/libcxxmsvc/include/__random/poisson_distribution.h @@ -0,0 +1,277 @@ +//===----------------------------------------------------------------------===// +// +// 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 _LIBCPP___RANDOM_POISSON_DISTRIBUTION_H +#define _LIBCPP___RANDOM_POISSON_DISTRIBUTION_H + +#include <__config> +#include <__random/clamp_to_integral.h> +#include <__random/exponential_distribution.h> +#include <__random/normal_distribution.h> +#include <__random/uniform_real_distribution.h> +#include <cmath> +#include <iosfwd> +#include <limits> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +# pragma GCC system_header +#endif + +_LIBCPP_PUSH_MACROS +#include <__undef_macros> + +_LIBCPP_BEGIN_NAMESPACE_STD + +template<class _IntType = int> +class _LIBCPP_TEMPLATE_VIS poisson_distribution +{ +public: + // types + typedef _IntType result_type; + + class _LIBCPP_TEMPLATE_VIS param_type + { + double __mean_; + double __s_; + double __d_; + double __l_; + double __omega_; + double __c0_; + double __c1_; + double __c2_; + double __c3_; + double __c_; + + public: + typedef poisson_distribution distribution_type; + + explicit param_type(double __mean = 1.0); + + _LIBCPP_INLINE_VISIBILITY + double mean() const {return __mean_;} + + friend _LIBCPP_INLINE_VISIBILITY + bool operator==(const param_type& __x, const param_type& __y) + {return __x.__mean_ == __y.__mean_;} + friend _LIBCPP_INLINE_VISIBILITY + bool operator!=(const param_type& __x, const param_type& __y) + {return !(__x == __y);} + + friend class poisson_distribution; + }; + +private: + param_type __p_; + +public: + // constructors and reset functions +#ifndef _LIBCPP_CXX03_LANG + _LIBCPP_INLINE_VISIBILITY + poisson_distribution() : poisson_distribution(1.0) {} + _LIBCPP_INLINE_VISIBILITY + explicit poisson_distribution(double __mean) + : __p_(__mean) {} +#else + _LIBCPP_INLINE_VISIBILITY + explicit poisson_distribution(double __mean = 1.0) + : __p_(__mean) {} +#endif + _LIBCPP_INLINE_VISIBILITY + explicit poisson_distribution(const param_type& __p) : __p_(__p) {} + _LIBCPP_INLINE_VISIBILITY + void reset() {} + + // generating functions + template<class _URNG> + _LIBCPP_INLINE_VISIBILITY + result_type operator()(_URNG& __g) + {return (*this)(__g, __p_);} + template<class _URNG> result_type operator()(_URNG& __g, const param_type& __p); + + // property functions + _LIBCPP_INLINE_VISIBILITY + double mean() const {return __p_.mean();} + + _LIBCPP_INLINE_VISIBILITY + param_type param() const {return __p_;} + _LIBCPP_INLINE_VISIBILITY + void param(const param_type& __p) {__p_ = __p;} + + _LIBCPP_INLINE_VISIBILITY + result_type min() const {return 0;} + _LIBCPP_INLINE_VISIBILITY + result_type max() const {return numeric_limits<result_type>::max();} + + friend _LIBCPP_INLINE_VISIBILITY + bool operator==(const poisson_distribution& __x, + const poisson_distribution& __y) + {return __x.__p_ == __y.__p_;} + friend _LIBCPP_INLINE_VISIBILITY + bool operator!=(const poisson_distribution& __x, + const poisson_distribution& __y) + {return !(__x == __y);} +}; + +template<class _IntType> +poisson_distribution<_IntType>::param_type::param_type(double __mean) + // According to the standard `inf` is a valid input, but it causes the + // distribution to hang, so we replace it with the maximum representable + // mean. + : __mean_(isinf(__mean) ? numeric_limits<double>::max() : __mean) +{ + if (__mean_ < 10) + { + __s_ = 0; + __d_ = 0; + __l_ = _VSTD::exp(-__mean_); + __omega_ = 0; + __c3_ = 0; + __c2_ = 0; + __c1_ = 0; + __c0_ = 0; + __c_ = 0; + } + else + { + __s_ = _VSTD::sqrt(__mean_); + __d_ = 6 * __mean_ * __mean_; + __l_ = _VSTD::trunc(__mean_ - 1.1484); + __omega_ = .3989423 / __s_; + double __b1_ = .4166667E-1 / __mean_; + double __b2_ = .3 * __b1_ * __b1_; + __c3_ = .1428571 * __b1_ * __b2_; + __c2_ = __b2_ - 15. * __c3_; + __c1_ = __b1_ - 6. * __b2_ + 45. * __c3_; + __c0_ = 1. - __b1_ + 3. * __b2_ - 15. * __c3_; + __c_ = .1069 / __mean_; + } +} + +template <class _IntType> +template<class _URNG> +_IntType +poisson_distribution<_IntType>::operator()(_URNG& __urng, const param_type& __pr) +{ + double __tx; + uniform_real_distribution<double> __urd; + if (__pr.__mean_ < 10) + { + __tx = 0; + for (double __p = __urd(__urng); __p > __pr.__l_; ++__tx) + __p *= __urd(__urng); + } + else + { + double __difmuk; + double __g = __pr.__mean_ + __pr.__s_ * normal_distribution<double>()(__urng); + double __u; + if (__g > 0) + { + __tx = _VSTD::trunc(__g); + if (__tx >= __pr.__l_) + return _VSTD::__clamp_to_integral<result_type>(__tx); + __difmuk = __pr.__mean_ - __tx; + __u = __urd(__urng); + if (__pr.__d_ * __u >= __difmuk * __difmuk * __difmuk) + return _VSTD::__clamp_to_integral<result_type>(__tx); + } + exponential_distribution<double> __edist; + for (bool __using_exp_dist = false; true; __using_exp_dist = true) + { + double __e; + if (__using_exp_dist || __g <= 0) + { + double __t; + do + { + __e = __edist(__urng); + __u = __urd(__urng); + __u += __u - 1; + __t = 1.8 + (__u < 0 ? -__e : __e); + } while (__t <= -.6744); + __tx = _VSTD::trunc(__pr.__mean_ + __pr.__s_ * __t); + __difmuk = __pr.__mean_ - __tx; + __using_exp_dist = true; + } + double __px; + double __py; + if (__tx < 10 && __tx >= 0) + { + const double __fac[] = {1, 1, 2, 6, 24, 120, 720, 5040, + 40320, 362880}; + __px = -__pr.__mean_; + __py = _VSTD::pow(__pr.__mean_, (double)__tx) / __fac[static_cast<int>(__tx)]; + } + else + { + double __del = .8333333E-1 / __tx; + __del -= 4.8 * __del * __del * __del; + double __v = __difmuk / __tx; + if (_VSTD::abs(__v) > 0.25) + __px = __tx * _VSTD::log(1 + __v) - __difmuk - __del; + else + __px = __tx * __v * __v * (((((((.1250060 * __v + -.1384794) * + __v + .1421878) * __v + -.1661269) * __v + .2000118) * + __v + -.2500068) * __v + .3333333) * __v + -.5) - __del; + __py = .3989423 / _VSTD::sqrt(__tx); + } + double __r = (0.5 - __difmuk) / __pr.__s_; + double __r2 = __r * __r; + double __fx = -0.5 * __r2; + double __fy = __pr.__omega_ * (((__pr.__c3_ * __r2 + __pr.__c2_) * + __r2 + __pr.__c1_) * __r2 + __pr.__c0_); + if (__using_exp_dist) + { + if (__pr.__c_ * _VSTD::abs(__u) <= __py * _VSTD::exp(__px + __e) - + __fy * _VSTD::exp(__fx + __e)) + break; + } + else + { + if (__fy - __u * __fy <= __py * _VSTD::exp(__px - __fx)) + break; + } + } + } + return _VSTD::__clamp_to_integral<result_type>(__tx); +} + +template <class _CharT, class _Traits, class _IntType> +basic_ostream<_CharT, _Traits>& +operator<<(basic_ostream<_CharT, _Traits>& __os, + const poisson_distribution<_IntType>& __x) +{ + __save_flags<_CharT, _Traits> __lx(__os); + typedef basic_ostream<_CharT, _Traits> _OStream; + __os.flags(_OStream::dec | _OStream::left | _OStream::fixed | + _OStream::scientific); + return __os << __x.mean(); +} + +template <class _CharT, class _Traits, class _IntType> +basic_istream<_CharT, _Traits>& +operator>>(basic_istream<_CharT, _Traits>& __is, + poisson_distribution<_IntType>& __x) +{ + typedef poisson_distribution<_IntType> _Eng; + typedef typename _Eng::param_type param_type; + __save_flags<_CharT, _Traits> __lx(__is); + typedef basic_istream<_CharT, _Traits> _Istream; + __is.flags(_Istream::dec | _Istream::skipws); + double __mean; + __is >> __mean; + if (!__is.fail()) + __x.param(param_type(__mean)); + return __is; +} + +_LIBCPP_END_NAMESPACE_STD + +_LIBCPP_POP_MACROS + +#endif // _LIBCPP___RANDOM_POISSON_DISTRIBUTION_H diff --git a/contrib/libs/cxxsupp/libcxxmsvc/include/__random/random_device.h b/contrib/libs/cxxsupp/libcxxmsvc/include/__random/random_device.h new file mode 100644 index 0000000000..e82b437a3b --- /dev/null +++ b/contrib/libs/cxxsupp/libcxxmsvc/include/__random/random_device.h @@ -0,0 +1,84 @@ +//===----------------------------------------------------------------------===// +// +// 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 _LIBCPP___RANDOM_RANDOM_DEVICE_H +#define _LIBCPP___RANDOM_RANDOM_DEVICE_H + +#include <__config> +#include <string> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +# pragma GCC system_header +#endif + +_LIBCPP_PUSH_MACROS +#include <__undef_macros> + +_LIBCPP_BEGIN_NAMESPACE_STD + +#if !defined(_LIBCPP_HAS_NO_RANDOM_DEVICE) + +class _LIBCPP_TYPE_VIS random_device +{ +#ifdef _LIBCPP_USING_DEV_RANDOM + int __f_; +#elif !defined(_LIBCPP_ABI_NO_RANDOM_DEVICE_COMPATIBILITY_LAYOUT) + _LIBCPP_DIAGNOSTIC_PUSH + _LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Wunused-private-field") + + // Apple platforms used to use the `_LIBCPP_USING_DEV_RANDOM` code path, and now + // use `arc4random()` as of this comment. In order to avoid breaking the ABI, we + // retain the same layout as before. +# if defined(__APPLE__) + int __padding_; // padding to fake the `__f_` field above +# endif + + // ... vendors can add workarounds here if they switch to a different representation ... + + _LIBCPP_DIAGNOSTIC_POP +#endif + +public: + // types + typedef unsigned result_type; + + // generator characteristics + static _LIBCPP_CONSTEXPR const result_type _Min = 0; + static _LIBCPP_CONSTEXPR const result_type _Max = 0xFFFFFFFFu; + + _LIBCPP_INLINE_VISIBILITY + static _LIBCPP_CONSTEXPR result_type min() { return _Min;} + _LIBCPP_INLINE_VISIBILITY + static _LIBCPP_CONSTEXPR result_type max() { return _Max;} + + // constructors +#ifndef _LIBCPP_CXX03_LANG + random_device() : random_device("/dev/urandom") {} + explicit random_device(const string& __token); +#else + explicit random_device(const string& __token = "/dev/urandom"); +#endif + ~random_device(); + + // generating functions + result_type operator()(); + + // property functions + double entropy() const _NOEXCEPT; + + random_device(const random_device&) = delete; + void operator=(const random_device&) = delete; +}; + +#endif // !_LIBCPP_HAS_NO_RANDOM_DEVICE + +_LIBCPP_END_NAMESPACE_STD + +_LIBCPP_POP_MACROS + +#endif // _LIBCPP___RANDOM_RANDOM_DEVICE_H diff --git a/contrib/libs/cxxsupp/libcxxmsvc/include/__random/ranlux.h b/contrib/libs/cxxsupp/libcxxmsvc/include/__random/ranlux.h new file mode 100644 index 0000000000..e44cece39d --- /dev/null +++ b/contrib/libs/cxxsupp/libcxxmsvc/include/__random/ranlux.h @@ -0,0 +1,31 @@ +//===----------------------------------------------------------------------===// +// +// 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 _LIBCPP___RANDOM_RANLUX_H +#define _LIBCPP___RANDOM_RANLUX_H + +#include <__config> +#include <__random/discard_block_engine.h> +#include <__random/subtract_with_carry_engine.h> +#include <cstdint> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +# pragma GCC system_header +#endif + +_LIBCPP_BEGIN_NAMESPACE_STD + +typedef subtract_with_carry_engine<uint_fast32_t, 24, 10, 24> ranlux24_base; +typedef subtract_with_carry_engine<uint_fast64_t, 48, 5, 12> ranlux48_base; + +typedef discard_block_engine<ranlux24_base, 223, 23> ranlux24; +typedef discard_block_engine<ranlux48_base, 389, 11> ranlux48; + +_LIBCPP_END_NAMESPACE_STD + +#endif // _LIBCPP___RANDOM_RANLUX_H diff --git a/contrib/libs/cxxsupp/libcxxmsvc/include/__random/seed_seq.h b/contrib/libs/cxxsupp/libcxxmsvc/include/__random/seed_seq.h new file mode 100644 index 0000000000..8640cd1b4e --- /dev/null +++ b/contrib/libs/cxxsupp/libcxxmsvc/include/__random/seed_seq.h @@ -0,0 +1,153 @@ +//===----------------------------------------------------------------------===// +// +// 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 _LIBCPP___RANDOM_SEED_SEQ_H +#define _LIBCPP___RANDOM_SEED_SEQ_H + +#include <__algorithm/copy.h> +#include <__algorithm/fill.h> +#include <__algorithm/max.h> +#include <__config> +#include <initializer_list> +#include <vector> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +# pragma GCC system_header +#endif + +_LIBCPP_PUSH_MACROS +#include <__undef_macros> + +_LIBCPP_BEGIN_NAMESPACE_STD + +class _LIBCPP_TEMPLATE_VIS seed_seq +{ +public: + // types + typedef uint32_t result_type; + + // constructors + _LIBCPP_INLINE_VISIBILITY + seed_seq() _NOEXCEPT {} +#ifndef _LIBCPP_CXX03_LANG + template<class _Tp, __enable_if_t<is_integral<_Tp>::value>* = nullptr> + _LIBCPP_INLINE_VISIBILITY + seed_seq(initializer_list<_Tp> __il) { + __init(__il.begin(), __il.end()); + } +#endif // _LIBCPP_CXX03_LANG + + template<class _InputIterator> + _LIBCPP_INLINE_VISIBILITY + seed_seq(_InputIterator __first, _InputIterator __last) { + static_assert(is_integral<typename iterator_traits<_InputIterator>::value_type>::value, + "Mandates: iterator_traits<InputIterator>::value_type is an integer type"); + __init(__first, __last); + } + + // generating functions + template<class _RandomAccessIterator> + void generate(_RandomAccessIterator __first, _RandomAccessIterator __last); + + // property functions + _LIBCPP_INLINE_VISIBILITY + size_t size() const _NOEXCEPT {return __v_.size();} + template<class _OutputIterator> + _LIBCPP_INLINE_VISIBILITY + void param(_OutputIterator __dest) const + {_VSTD::copy(__v_.begin(), __v_.end(), __dest);} + + seed_seq(const seed_seq&) = delete; + void operator=(const seed_seq&) = delete; + + _LIBCPP_INLINE_VISIBILITY + static result_type _Tp(result_type __x) {return __x ^ (__x >> 27);} + +private: + template<class _InputIterator> + void __init(_InputIterator __first, _InputIterator __last); + + vector<result_type> __v_; +}; + +template<class _InputIterator> +void +seed_seq::__init(_InputIterator __first, _InputIterator __last) +{ + for (_InputIterator __s = __first; __s != __last; ++__s) + __v_.push_back(*__s & 0xFFFFFFFF); +} + +template<class _RandomAccessIterator> +void +seed_seq::generate(_RandomAccessIterator __first, _RandomAccessIterator __last) +{ + if (__first != __last) + { + _VSTD::fill(__first, __last, 0x8b8b8b8b); + const size_t __n = static_cast<size_t>(__last - __first); + const size_t __s = __v_.size(); + const size_t __t = (__n >= 623) ? 11 + : (__n >= 68) ? 7 + : (__n >= 39) ? 5 + : (__n >= 7) ? 3 + : (__n - 1) / 2; + const size_t __p = (__n - __t) / 2; + const size_t __q = __p + __t; + const size_t __m = _VSTD::max(__s + 1, __n); + // __k = 0; + { + result_type __r = 1664525 * _Tp(__first[0] ^ __first[__p] + ^ __first[__n - 1]); + __first[__p] += __r; + __r += __s; + __first[__q] += __r; + __first[0] = __r; + } + for (size_t __k = 1; __k <= __s; ++__k) + { + const size_t __kmodn = __k % __n; + const size_t __kpmodn = (__k + __p) % __n; + result_type __r = 1664525 * _Tp(__first[__kmodn] ^ __first[__kpmodn] + ^ __first[(__k - 1) % __n]); + __first[__kpmodn] += __r; + __r += __kmodn + __v_[__k-1]; + __first[(__k + __q) % __n] += __r; + __first[__kmodn] = __r; + } + for (size_t __k = __s + 1; __k < __m; ++__k) + { + const size_t __kmodn = __k % __n; + const size_t __kpmodn = (__k + __p) % __n; + result_type __r = 1664525 * _Tp(__first[__kmodn] ^ __first[__kpmodn] + ^ __first[(__k - 1) % __n]); + __first[__kpmodn] += __r; + __r += __kmodn; + __first[(__k + __q) % __n] += __r; + __first[__kmodn] = __r; + } + for (size_t __k = __m; __k < __m + __n; ++__k) + { + const size_t __kmodn = __k % __n; + const size_t __kpmodn = (__k + __p) % __n; + result_type __r = 1566083941 * _Tp(__first[__kmodn] + + __first[__kpmodn] + + __first[(__k - 1) % __n]); + __first[__kpmodn] ^= __r; + __r -= __kmodn; + __first[(__k + __q) % __n] ^= __r; + __first[__kmodn] = __r; + } + } +} + +_LIBCPP_END_NAMESPACE_STD + +_LIBCPP_POP_MACROS + +#endif // _LIBCPP___RANDOM_SEED_SEQ_H diff --git a/contrib/libs/cxxsupp/libcxxmsvc/include/__random/shuffle_order_engine.h b/contrib/libs/cxxsupp/libcxxmsvc/include/__random/shuffle_order_engine.h new file mode 100644 index 0000000000..c2f76f609a --- /dev/null +++ b/contrib/libs/cxxsupp/libcxxmsvc/include/__random/shuffle_order_engine.h @@ -0,0 +1,283 @@ +//===----------------------------------------------------------------------===// +// +// 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 _LIBCPP___RANDOM_SHUFFLE_ORDER_ENGINE_H +#define _LIBCPP___RANDOM_SHUFFLE_ORDER_ENGINE_H + +#include <__algorithm/equal.h> +#include <__config> +#include <__random/is_seed_sequence.h> +#include <__utility/move.h> +#include <cstdint> +#include <iosfwd> +#include <type_traits> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +# pragma GCC system_header +#endif + +_LIBCPP_PUSH_MACROS +#include <__undef_macros> + +_LIBCPP_BEGIN_NAMESPACE_STD + +template <uint64_t _Xp, uint64_t _Yp> +struct __ugcd +{ + static _LIBCPP_CONSTEXPR const uint64_t value = __ugcd<_Yp, _Xp % _Yp>::value; +}; + +template <uint64_t _Xp> +struct __ugcd<_Xp, 0> +{ + static _LIBCPP_CONSTEXPR const uint64_t value = _Xp; +}; + +template <uint64_t _Np, uint64_t _Dp> +class __uratio +{ + static_assert(_Dp != 0, "__uratio divide by 0"); + static _LIBCPP_CONSTEXPR const uint64_t __gcd = __ugcd<_Np, _Dp>::value; +public: + static _LIBCPP_CONSTEXPR const uint64_t num = _Np / __gcd; + static _LIBCPP_CONSTEXPR const uint64_t den = _Dp / __gcd; + + typedef __uratio<num, den> type; +}; + +template<class _Engine, size_t __k> +class _LIBCPP_TEMPLATE_VIS shuffle_order_engine +{ + static_assert(0 < __k, "shuffle_order_engine invalid parameters"); +public: + // types + typedef typename _Engine::result_type result_type; + +private: + _Engine __e_; + result_type _V_[__k]; + result_type _Y_; + +public: + // engine characteristics + static _LIBCPP_CONSTEXPR const size_t table_size = __k; + +#ifdef _LIBCPP_CXX03_LANG + static const result_type _Min = _Engine::_Min; + static const result_type _Max = _Engine::_Max; +#else + static _LIBCPP_CONSTEXPR const result_type _Min = _Engine::min(); + static _LIBCPP_CONSTEXPR const result_type _Max = _Engine::max(); +#endif + static_assert(_Min < _Max, "shuffle_order_engine invalid parameters"); + _LIBCPP_INLINE_VISIBILITY + static _LIBCPP_CONSTEXPR result_type min() { return _Min; } + _LIBCPP_INLINE_VISIBILITY + static _LIBCPP_CONSTEXPR result_type max() { return _Max; } + + static _LIBCPP_CONSTEXPR const unsigned long long _Rp = _Max - _Min + 1ull; + + // constructors and seeding functions + _LIBCPP_INLINE_VISIBILITY + shuffle_order_engine() {__init();} + _LIBCPP_INLINE_VISIBILITY + explicit shuffle_order_engine(const _Engine& __e) + : __e_(__e) {__init();} +#ifndef _LIBCPP_CXX03_LANG + _LIBCPP_INLINE_VISIBILITY + explicit shuffle_order_engine(_Engine&& __e) + : __e_(_VSTD::move(__e)) {__init();} +#endif // _LIBCPP_CXX03_LANG + _LIBCPP_INLINE_VISIBILITY + explicit shuffle_order_engine(result_type __sd) : __e_(__sd) {__init();} + template<class _Sseq> + _LIBCPP_INLINE_VISIBILITY + explicit shuffle_order_engine(_Sseq& __q, + typename enable_if<__is_seed_sequence<_Sseq, shuffle_order_engine>::value && + !is_convertible<_Sseq, _Engine>::value>::type* = 0) + : __e_(__q) {__init();} + _LIBCPP_INLINE_VISIBILITY + void seed() {__e_.seed(); __init();} + _LIBCPP_INLINE_VISIBILITY + void seed(result_type __sd) {__e_.seed(__sd); __init();} + template<class _Sseq> + _LIBCPP_INLINE_VISIBILITY + typename enable_if + < + __is_seed_sequence<_Sseq, shuffle_order_engine>::value, + void + >::type + seed(_Sseq& __q) {__e_.seed(__q); __init();} + + // generating functions + _LIBCPP_INLINE_VISIBILITY + result_type operator()() {return __eval(integral_constant<bool, _Rp != 0>());} + _LIBCPP_INLINE_VISIBILITY + void discard(unsigned long long __z) {for (; __z; --__z) operator()();} + + // property functions + _LIBCPP_INLINE_VISIBILITY + const _Engine& base() const _NOEXCEPT {return __e_;} + +private: + template<class _Eng, size_t _Kp> + friend + bool + operator==( + const shuffle_order_engine<_Eng, _Kp>& __x, + const shuffle_order_engine<_Eng, _Kp>& __y); + + template<class _Eng, size_t _Kp> + friend + bool + operator!=( + const shuffle_order_engine<_Eng, _Kp>& __x, + const shuffle_order_engine<_Eng, _Kp>& __y); + + template <class _CharT, class _Traits, + class _Eng, size_t _Kp> + friend + basic_ostream<_CharT, _Traits>& + operator<<(basic_ostream<_CharT, _Traits>& __os, + const shuffle_order_engine<_Eng, _Kp>& __x); + + template <class _CharT, class _Traits, + class _Eng, size_t _Kp> + friend + basic_istream<_CharT, _Traits>& + operator>>(basic_istream<_CharT, _Traits>& __is, + shuffle_order_engine<_Eng, _Kp>& __x); + + _LIBCPP_INLINE_VISIBILITY + void __init() + { + for (size_t __i = 0; __i < __k; ++__i) + _V_[__i] = __e_(); + _Y_ = __e_(); + } + + _LIBCPP_INLINE_VISIBILITY + result_type __eval(false_type) {return __eval2(integral_constant<bool, __k & 1>());} + _LIBCPP_INLINE_VISIBILITY + result_type __eval(true_type) {return __eval(__uratio<__k, _Rp>());} + + _LIBCPP_INLINE_VISIBILITY + result_type __eval2(false_type) {return __eval(__uratio<__k/2, 0x8000000000000000ull>());} + _LIBCPP_INLINE_VISIBILITY + result_type __eval2(true_type) {return __evalf<__k, 0>();} + + template <uint64_t _Np, uint64_t _Dp> + _LIBCPP_INLINE_VISIBILITY + typename enable_if + < + (__uratio<_Np, _Dp>::num > 0xFFFFFFFFFFFFFFFFull / (_Max - _Min)), + result_type + >::type + __eval(__uratio<_Np, _Dp>) + {return __evalf<__uratio<_Np, _Dp>::num, __uratio<_Np, _Dp>::den>();} + + template <uint64_t _Np, uint64_t _Dp> + _LIBCPP_INLINE_VISIBILITY + typename enable_if + < + __uratio<_Np, _Dp>::num <= 0xFFFFFFFFFFFFFFFFull / (_Max - _Min), + result_type + >::type + __eval(__uratio<_Np, _Dp>) + { + const size_t __j = static_cast<size_t>(__uratio<_Np, _Dp>::num * (_Y_ - _Min) + / __uratio<_Np, _Dp>::den); + _Y_ = _V_[__j]; + _V_[__j] = __e_(); + return _Y_; + } + + template <uint64_t __n, uint64_t __d> + _LIBCPP_INLINE_VISIBILITY + result_type __evalf() + { + const double _Fp = __d == 0 ? + __n / (2. * 0x8000000000000000ull) : + __n / (double)__d; + const size_t __j = static_cast<size_t>(_Fp * (_Y_ - _Min)); + _Y_ = _V_[__j]; + _V_[__j] = __e_(); + return _Y_; + } +}; + +template<class _Engine, size_t __k> + _LIBCPP_CONSTEXPR const size_t shuffle_order_engine<_Engine, __k>::table_size; + +template<class _Eng, size_t _Kp> +bool +operator==( + const shuffle_order_engine<_Eng, _Kp>& __x, + const shuffle_order_engine<_Eng, _Kp>& __y) +{ + return __x._Y_ == __y._Y_ && _VSTD::equal(__x._V_, __x._V_ + _Kp, __y._V_) && + __x.__e_ == __y.__e_; +} + +template<class _Eng, size_t _Kp> +inline _LIBCPP_INLINE_VISIBILITY +bool +operator!=( + const shuffle_order_engine<_Eng, _Kp>& __x, + const shuffle_order_engine<_Eng, _Kp>& __y) +{ + return !(__x == __y); +} + +template <class _CharT, class _Traits, + class _Eng, size_t _Kp> +basic_ostream<_CharT, _Traits>& +operator<<(basic_ostream<_CharT, _Traits>& __os, + const shuffle_order_engine<_Eng, _Kp>& __x) +{ + __save_flags<_CharT, _Traits> __lx(__os); + typedef basic_ostream<_CharT, _Traits> _Ostream; + __os.flags(_Ostream::dec | _Ostream::left); + _CharT __sp = __os.widen(' '); + __os.fill(__sp); + __os << __x.__e_ << __sp << __x._V_[0]; + for (size_t __i = 1; __i < _Kp; ++__i) + __os << __sp << __x._V_[__i]; + return __os << __sp << __x._Y_; +} + +template <class _CharT, class _Traits, + class _Eng, size_t _Kp> +basic_istream<_CharT, _Traits>& +operator>>(basic_istream<_CharT, _Traits>& __is, + shuffle_order_engine<_Eng, _Kp>& __x) +{ + typedef typename shuffle_order_engine<_Eng, _Kp>::result_type result_type; + __save_flags<_CharT, _Traits> __lx(__is); + typedef basic_istream<_CharT, _Traits> _Istream; + __is.flags(_Istream::dec | _Istream::skipws); + _Eng __e; + result_type _Vp[_Kp+1]; + __is >> __e; + for (size_t __i = 0; __i < _Kp+1; ++__i) + __is >> _Vp[__i]; + if (!__is.fail()) + { + __x.__e_ = __e; + for (size_t __i = 0; __i < _Kp; ++__i) + __x._V_[__i] = _Vp[__i]; + __x._Y_ = _Vp[_Kp]; + } + return __is; +} + +_LIBCPP_END_NAMESPACE_STD + +_LIBCPP_POP_MACROS + +#endif // _LIBCPP___RANDOM_SHUFFLE_ORDER_ENGINE_H diff --git a/contrib/libs/cxxsupp/libcxxmsvc/include/__random/student_t_distribution.h b/contrib/libs/cxxsupp/libcxxmsvc/include/__random/student_t_distribution.h new file mode 100644 index 0000000000..dc38a8b3d2 --- /dev/null +++ b/contrib/libs/cxxsupp/libcxxmsvc/include/__random/student_t_distribution.h @@ -0,0 +1,153 @@ +//===----------------------------------------------------------------------===// +// +// 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 _LIBCPP___RANDOM_STUDENT_T_DISTRIBUTION_H +#define _LIBCPP___RANDOM_STUDENT_T_DISTRIBUTION_H + +#include <__config> +#include <__random/gamma_distribution.h> +#include <__random/normal_distribution.h> +#include <cmath> +#include <iosfwd> +#include <limits> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +# pragma GCC system_header +#endif + +_LIBCPP_PUSH_MACROS +#include <__undef_macros> + +_LIBCPP_BEGIN_NAMESPACE_STD + +template<class _RealType = double> +class _LIBCPP_TEMPLATE_VIS student_t_distribution +{ +public: + // types + typedef _RealType result_type; + + class _LIBCPP_TEMPLATE_VIS param_type + { + result_type __n_; + public: + typedef student_t_distribution distribution_type; + + _LIBCPP_INLINE_VISIBILITY + explicit param_type(result_type __n = 1) : __n_(__n) {} + + _LIBCPP_INLINE_VISIBILITY + result_type n() const {return __n_;} + + friend _LIBCPP_INLINE_VISIBILITY + bool operator==(const param_type& __x, const param_type& __y) + {return __x.__n_ == __y.__n_;} + friend _LIBCPP_INLINE_VISIBILITY + bool operator!=(const param_type& __x, const param_type& __y) + {return !(__x == __y);} + }; + +private: + param_type __p_; + normal_distribution<result_type> __nd_; + +public: + // constructor and reset functions +#ifndef _LIBCPP_CXX03_LANG + _LIBCPP_INLINE_VISIBILITY + student_t_distribution() : student_t_distribution(1) {} + _LIBCPP_INLINE_VISIBILITY + explicit student_t_distribution(result_type __n) + : __p_(param_type(__n)) {} +#else + _LIBCPP_INLINE_VISIBILITY + explicit student_t_distribution(result_type __n = 1) + : __p_(param_type(__n)) {} +#endif + _LIBCPP_INLINE_VISIBILITY + explicit student_t_distribution(const param_type& __p) + : __p_(__p) {} + _LIBCPP_INLINE_VISIBILITY + void reset() {__nd_.reset();} + + // generating functions + template<class _URNG> + _LIBCPP_INLINE_VISIBILITY + result_type operator()(_URNG& __g) + {return (*this)(__g, __p_);} + template<class _URNG> result_type operator()(_URNG& __g, const param_type& __p); + + // property functions + _LIBCPP_INLINE_VISIBILITY + result_type n() const {return __p_.n();} + + _LIBCPP_INLINE_VISIBILITY + param_type param() const {return __p_;} + _LIBCPP_INLINE_VISIBILITY + void param(const param_type& __p) {__p_ = __p;} + + _LIBCPP_INLINE_VISIBILITY + result_type min() const {return -numeric_limits<result_type>::infinity();} + _LIBCPP_INLINE_VISIBILITY + result_type max() const {return numeric_limits<result_type>::infinity();} + + friend _LIBCPP_INLINE_VISIBILITY + bool operator==(const student_t_distribution& __x, + const student_t_distribution& __y) + {return __x.__p_ == __y.__p_;} + friend _LIBCPP_INLINE_VISIBILITY + bool operator!=(const student_t_distribution& __x, + const student_t_distribution& __y) + {return !(__x == __y);} +}; + +template <class _RealType> +template<class _URNG> +_RealType +student_t_distribution<_RealType>::operator()(_URNG& __g, const param_type& __p) +{ + gamma_distribution<result_type> __gd(__p.n() * .5, 2); + return __nd_(__g) * _VSTD::sqrt(__p.n()/__gd(__g)); +} + +template <class _CharT, class _Traits, class _RT> +basic_ostream<_CharT, _Traits>& +operator<<(basic_ostream<_CharT, _Traits>& __os, + const student_t_distribution<_RT>& __x) +{ + __save_flags<_CharT, _Traits> __lx(__os); + typedef basic_ostream<_CharT, _Traits> _OStream; + __os.flags(_OStream::dec | _OStream::left | _OStream::fixed | + _OStream::scientific); + __os << __x.n(); + return __os; +} + +template <class _CharT, class _Traits, class _RT> +basic_istream<_CharT, _Traits>& +operator>>(basic_istream<_CharT, _Traits>& __is, + student_t_distribution<_RT>& __x) +{ + typedef student_t_distribution<_RT> _Eng; + typedef typename _Eng::result_type result_type; + typedef typename _Eng::param_type param_type; + __save_flags<_CharT, _Traits> __lx(__is); + typedef basic_istream<_CharT, _Traits> _Istream; + __is.flags(_Istream::dec | _Istream::skipws); + result_type __n; + __is >> __n; + if (!__is.fail()) + __x.param(param_type(__n)); + return __is; +} + +_LIBCPP_END_NAMESPACE_STD + +_LIBCPP_POP_MACROS + +#endif // _LIBCPP___RANDOM_STUDENT_T_DISTRIBUTION_H diff --git a/contrib/libs/cxxsupp/libcxxmsvc/include/__random/subtract_with_carry_engine.h b/contrib/libs/cxxsupp/libcxxmsvc/include/__random/subtract_with_carry_engine.h new file mode 100644 index 0000000000..fdbe2d2e9b --- /dev/null +++ b/contrib/libs/cxxsupp/libcxxmsvc/include/__random/subtract_with_carry_engine.h @@ -0,0 +1,352 @@ +//===----------------------------------------------------------------------===// +// +// 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 _LIBCPP___RANDOM_SUBTRACT_WITH_CARRY_ENGINE_H +#define _LIBCPP___RANDOM_SUBTRACT_WITH_CARRY_ENGINE_H + +#include <__algorithm/equal.h> +#include <__algorithm/min.h> +#include <__config> +#include <__random/is_seed_sequence.h> +#include <__random/linear_congruential_engine.h> +#include <cstddef> +#include <cstdint> +#include <iosfwd> +#include <limits> +#include <type_traits> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +# pragma GCC system_header +#endif + +_LIBCPP_PUSH_MACROS +#include <__undef_macros> + +_LIBCPP_BEGIN_NAMESPACE_STD + +template<class _UIntType, size_t __w, size_t __s, size_t __r> +class _LIBCPP_TEMPLATE_VIS subtract_with_carry_engine; + +template<class _UInt, size_t _Wp, size_t _Sp, size_t _Rp> +bool +operator==( + const subtract_with_carry_engine<_UInt, _Wp, _Sp, _Rp>& __x, + const subtract_with_carry_engine<_UInt, _Wp, _Sp, _Rp>& __y); + +template<class _UInt, size_t _Wp, size_t _Sp, size_t _Rp> +_LIBCPP_INLINE_VISIBILITY +bool +operator!=( + const subtract_with_carry_engine<_UInt, _Wp, _Sp, _Rp>& __x, + const subtract_with_carry_engine<_UInt, _Wp, _Sp, _Rp>& __y); + +template <class _CharT, class _Traits, + class _UInt, size_t _Wp, size_t _Sp, size_t _Rp> +basic_ostream<_CharT, _Traits>& +operator<<(basic_ostream<_CharT, _Traits>& __os, + const subtract_with_carry_engine<_UInt, _Wp, _Sp, _Rp>& __x); + +template <class _CharT, class _Traits, + class _UInt, size_t _Wp, size_t _Sp, size_t _Rp> +basic_istream<_CharT, _Traits>& +operator>>(basic_istream<_CharT, _Traits>& __is, + subtract_with_carry_engine<_UInt, _Wp, _Sp, _Rp>& __x); + +template<class _UIntType, size_t __w, size_t __s, size_t __r> +class _LIBCPP_TEMPLATE_VIS subtract_with_carry_engine +{ +public: + // types + typedef _UIntType result_type; + +private: + result_type __x_[__r]; + result_type __c_; + size_t __i_; + + static _LIBCPP_CONSTEXPR const result_type _Dt = numeric_limits<result_type>::digits; + static_assert( 0 < __w, "subtract_with_carry_engine invalid parameters"); + static_assert(__w <= _Dt, "subtract_with_carry_engine invalid parameters"); + static_assert( 0 < __s, "subtract_with_carry_engine invalid parameters"); + static_assert(__s < __r, "subtract_with_carry_engine invalid parameters"); +public: + static _LIBCPP_CONSTEXPR const result_type _Min = 0; + static _LIBCPP_CONSTEXPR const result_type _Max = __w == _Dt ? result_type(~0) : + (result_type(1) << __w) - result_type(1); + static_assert(_Min < _Max, "subtract_with_carry_engine invalid parameters"); + + // engine characteristics + static _LIBCPP_CONSTEXPR const size_t word_size = __w; + static _LIBCPP_CONSTEXPR const size_t short_lag = __s; + static _LIBCPP_CONSTEXPR const size_t long_lag = __r; + _LIBCPP_INLINE_VISIBILITY + static _LIBCPP_CONSTEXPR result_type min() { return _Min; } + _LIBCPP_INLINE_VISIBILITY + static _LIBCPP_CONSTEXPR result_type max() { return _Max; } + static _LIBCPP_CONSTEXPR const result_type default_seed = 19780503u; + + // constructors and seeding functions +#ifndef _LIBCPP_CXX03_LANG + _LIBCPP_INLINE_VISIBILITY + subtract_with_carry_engine() : subtract_with_carry_engine(default_seed) {} + _LIBCPP_INLINE_VISIBILITY + explicit subtract_with_carry_engine(result_type __sd) { seed(__sd); } +#else + _LIBCPP_INLINE_VISIBILITY + explicit subtract_with_carry_engine(result_type __sd = default_seed) { + seed(__sd); + } +#endif + template<class _Sseq> + _LIBCPP_INLINE_VISIBILITY + explicit subtract_with_carry_engine(_Sseq& __q, + typename enable_if<__is_seed_sequence<_Sseq, subtract_with_carry_engine>::value>::type* = 0) + {seed(__q);} + _LIBCPP_INLINE_VISIBILITY + void seed(result_type __sd = default_seed) + {seed(__sd, integral_constant<unsigned, 1 + (__w - 1) / 32>());} + template<class _Sseq> + _LIBCPP_INLINE_VISIBILITY + typename enable_if + < + __is_seed_sequence<_Sseq, subtract_with_carry_engine>::value, + void + >::type + seed(_Sseq& __q) + {__seed(__q, integral_constant<unsigned, 1 + (__w - 1) / 32>());} + + // generating functions + result_type operator()(); + _LIBCPP_INLINE_VISIBILITY + void discard(unsigned long long __z) {for (; __z; --__z) operator()();} + + template<class _UInt, size_t _Wp, size_t _Sp, size_t _Rp> + friend + bool + operator==( + const subtract_with_carry_engine<_UInt, _Wp, _Sp, _Rp>& __x, + const subtract_with_carry_engine<_UInt, _Wp, _Sp, _Rp>& __y); + + template<class _UInt, size_t _Wp, size_t _Sp, size_t _Rp> + friend + bool + operator!=( + const subtract_with_carry_engine<_UInt, _Wp, _Sp, _Rp>& __x, + const subtract_with_carry_engine<_UInt, _Wp, _Sp, _Rp>& __y); + + template <class _CharT, class _Traits, + class _UInt, size_t _Wp, size_t _Sp, size_t _Rp> + friend + basic_ostream<_CharT, _Traits>& + operator<<(basic_ostream<_CharT, _Traits>& __os, + const subtract_with_carry_engine<_UInt, _Wp, _Sp, _Rp>& __x); + + template <class _CharT, class _Traits, + class _UInt, size_t _Wp, size_t _Sp, size_t _Rp> + friend + basic_istream<_CharT, _Traits>& + operator>>(basic_istream<_CharT, _Traits>& __is, + subtract_with_carry_engine<_UInt, _Wp, _Sp, _Rp>& __x); + +private: + + void seed(result_type __sd, integral_constant<unsigned, 1>); + void seed(result_type __sd, integral_constant<unsigned, 2>); + template<class _Sseq> + void __seed(_Sseq& __q, integral_constant<unsigned, 1>); + template<class _Sseq> + void __seed(_Sseq& __q, integral_constant<unsigned, 2>); +}; + +template<class _UIntType, size_t __w, size_t __s, size_t __r> + _LIBCPP_CONSTEXPR const size_t subtract_with_carry_engine<_UIntType, __w, __s, __r>::word_size; + +template<class _UIntType, size_t __w, size_t __s, size_t __r> + _LIBCPP_CONSTEXPR const size_t subtract_with_carry_engine<_UIntType, __w, __s, __r>::short_lag; + +template<class _UIntType, size_t __w, size_t __s, size_t __r> + _LIBCPP_CONSTEXPR const size_t subtract_with_carry_engine<_UIntType, __w, __s, __r>::long_lag; + +template<class _UIntType, size_t __w, size_t __s, size_t __r> + _LIBCPP_CONSTEXPR const typename subtract_with_carry_engine<_UIntType, __w, __s, __r>::result_type + subtract_with_carry_engine<_UIntType, __w, __s, __r>::default_seed; + +template<class _UIntType, size_t __w, size_t __s, size_t __r> +void +subtract_with_carry_engine<_UIntType, __w, __s, __r>::seed(result_type __sd, + integral_constant<unsigned, 1>) +{ + linear_congruential_engine<result_type, 40014u, 0u, 2147483563u> + __e(__sd == 0u ? default_seed : __sd); + for (size_t __i = 0; __i < __r; ++__i) + __x_[__i] = static_cast<result_type>(__e() & _Max); + __c_ = __x_[__r-1] == 0; + __i_ = 0; +} + +template<class _UIntType, size_t __w, size_t __s, size_t __r> +void +subtract_with_carry_engine<_UIntType, __w, __s, __r>::seed(result_type __sd, + integral_constant<unsigned, 2>) +{ + linear_congruential_engine<result_type, 40014u, 0u, 2147483563u> + __e(__sd == 0u ? default_seed : __sd); + for (size_t __i = 0; __i < __r; ++__i) + { + result_type __e0 = __e(); + __x_[__i] = static_cast<result_type>( + (__e0 + ((uint64_t)__e() << 32)) & _Max); + } + __c_ = __x_[__r-1] == 0; + __i_ = 0; +} + +template<class _UIntType, size_t __w, size_t __s, size_t __r> +template<class _Sseq> +void +subtract_with_carry_engine<_UIntType, __w, __s, __r>::__seed(_Sseq& __q, + integral_constant<unsigned, 1>) +{ + const unsigned __k = 1; + uint32_t __ar[__r * __k]; + __q.generate(__ar, __ar + __r * __k); + for (size_t __i = 0; __i < __r; ++__i) + __x_[__i] = static_cast<result_type>(__ar[__i] & _Max); + __c_ = __x_[__r-1] == 0; + __i_ = 0; +} + +template<class _UIntType, size_t __w, size_t __s, size_t __r> +template<class _Sseq> +void +subtract_with_carry_engine<_UIntType, __w, __s, __r>::__seed(_Sseq& __q, + integral_constant<unsigned, 2>) +{ + const unsigned __k = 2; + uint32_t __ar[__r * __k]; + __q.generate(__ar, __ar + __r * __k); + for (size_t __i = 0; __i < __r; ++__i) + __x_[__i] = static_cast<result_type>( + (__ar[2 * __i] + ((uint64_t)__ar[2 * __i + 1] << 32)) & _Max); + __c_ = __x_[__r-1] == 0; + __i_ = 0; +} + +template<class _UIntType, size_t __w, size_t __s, size_t __r> +_UIntType +subtract_with_carry_engine<_UIntType, __w, __s, __r>::operator()() +{ + const result_type& __xs = __x_[(__i_ + (__r - __s)) % __r]; + result_type& __xr = __x_[__i_]; + result_type __new_c = __c_ == 0 ? __xs < __xr : __xs != 0 ? __xs <= __xr : 1; + __xr = (__xs - __xr - __c_) & _Max; + __c_ = __new_c; + __i_ = (__i_ + 1) % __r; + return __xr; +} + +template<class _UInt, size_t _Wp, size_t _Sp, size_t _Rp> +bool +operator==( + const subtract_with_carry_engine<_UInt, _Wp, _Sp, _Rp>& __x, + const subtract_with_carry_engine<_UInt, _Wp, _Sp, _Rp>& __y) +{ + if (__x.__c_ != __y.__c_) + return false; + if (__x.__i_ == __y.__i_) + return _VSTD::equal(__x.__x_, __x.__x_ + _Rp, __y.__x_); + if (__x.__i_ == 0 || __y.__i_ == 0) + { + size_t __j = _VSTD::min(_Rp - __x.__i_, _Rp - __y.__i_); + if (!_VSTD::equal(__x.__x_ + __x.__i_, __x.__x_ + __x.__i_ + __j, + __y.__x_ + __y.__i_)) + return false; + if (__x.__i_ == 0) + return _VSTD::equal(__x.__x_ + __j, __x.__x_ + _Rp, __y.__x_); + return _VSTD::equal(__x.__x_, __x.__x_ + (_Rp - __j), __y.__x_ + __j); + } + if (__x.__i_ < __y.__i_) + { + size_t __j = _Rp - __y.__i_; + if (!_VSTD::equal(__x.__x_ + __x.__i_, __x.__x_ + (__x.__i_ + __j), + __y.__x_ + __y.__i_)) + return false; + if (!_VSTD::equal(__x.__x_ + (__x.__i_ + __j), __x.__x_ + _Rp, + __y.__x_)) + return false; + return _VSTD::equal(__x.__x_, __x.__x_ + __x.__i_, + __y.__x_ + (_Rp - (__x.__i_ + __j))); + } + size_t __j = _Rp - __x.__i_; + if (!_VSTD::equal(__y.__x_ + __y.__i_, __y.__x_ + (__y.__i_ + __j), + __x.__x_ + __x.__i_)) + return false; + if (!_VSTD::equal(__y.__x_ + (__y.__i_ + __j), __y.__x_ + _Rp, + __x.__x_)) + return false; + return _VSTD::equal(__y.__x_, __y.__x_ + __y.__i_, + __x.__x_ + (_Rp - (__y.__i_ + __j))); +} + +template<class _UInt, size_t _Wp, size_t _Sp, size_t _Rp> +inline _LIBCPP_INLINE_VISIBILITY +bool +operator!=( + const subtract_with_carry_engine<_UInt, _Wp, _Sp, _Rp>& __x, + const subtract_with_carry_engine<_UInt, _Wp, _Sp, _Rp>& __y) +{ + return !(__x == __y); +} + +template <class _CharT, class _Traits, + class _UInt, size_t _Wp, size_t _Sp, size_t _Rp> +basic_ostream<_CharT, _Traits>& +operator<<(basic_ostream<_CharT, _Traits>& __os, + const subtract_with_carry_engine<_UInt, _Wp, _Sp, _Rp>& __x) +{ + __save_flags<_CharT, _Traits> __lx(__os); + typedef basic_ostream<_CharT, _Traits> _Ostream; + __os.flags(_Ostream::dec | _Ostream::left); + _CharT __sp = __os.widen(' '); + __os.fill(__sp); + __os << __x.__x_[__x.__i_]; + for (size_t __j = __x.__i_ + 1; __j < _Rp; ++__j) + __os << __sp << __x.__x_[__j]; + for (size_t __j = 0; __j < __x.__i_; ++__j) + __os << __sp << __x.__x_[__j]; + __os << __sp << __x.__c_; + return __os; +} + +template <class _CharT, class _Traits, + class _UInt, size_t _Wp, size_t _Sp, size_t _Rp> +basic_istream<_CharT, _Traits>& +operator>>(basic_istream<_CharT, _Traits>& __is, + subtract_with_carry_engine<_UInt, _Wp, _Sp, _Rp>& __x) +{ + __save_flags<_CharT, _Traits> __lx(__is); + typedef basic_istream<_CharT, _Traits> _Istream; + __is.flags(_Istream::dec | _Istream::skipws); + _UInt __t[_Rp+1]; + for (size_t __i = 0; __i < _Rp+1; ++__i) + __is >> __t[__i]; + if (!__is.fail()) + { + for (size_t __i = 0; __i < _Rp; ++__i) + __x.__x_[__i] = __t[__i]; + __x.__c_ = __t[_Rp]; + __x.__i_ = 0; + } + return __is; +} + +_LIBCPP_END_NAMESPACE_STD + +_LIBCPP_POP_MACROS + +#endif // _LIBCPP___RANDOM_SUBTRACT_WITH_CARRY_ENGINE_H diff --git a/contrib/libs/cxxsupp/libcxxmsvc/include/__random/uniform_random_bit_generator.h b/contrib/libs/cxxsupp/libcxxmsvc/include/__random/uniform_random_bit_generator.h new file mode 100644 index 0000000000..99f2e6bc30 --- /dev/null +++ b/contrib/libs/cxxsupp/libcxxmsvc/include/__random/uniform_random_bit_generator.h @@ -0,0 +1,45 @@ +//===----------------------------------------------------------------------===// +// +// 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 _LIBCPP___RANDOM_UNIFORM_RANDOM_BIT_GENERATOR_H +#define _LIBCPP___RANDOM_UNIFORM_RANDOM_BIT_GENERATOR_H + +#include <__concepts/arithmetic.h> +#include <__concepts/invocable.h> +#include <__concepts/same_as.h> +#include <__config> +#include <type_traits> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +# pragma GCC system_header +#endif + +_LIBCPP_PUSH_MACROS +#include <__undef_macros> + +_LIBCPP_BEGIN_NAMESPACE_STD + +#if !defined(_LIBCPP_HAS_NO_CONCEPTS) + +// [rand.req.urng] +template<class _Gen> +concept uniform_random_bit_generator = + invocable<_Gen&> && unsigned_integral<invoke_result_t<_Gen&>> && + requires { + { _Gen::min() } -> same_as<invoke_result_t<_Gen&>>; + { _Gen::max() } -> same_as<invoke_result_t<_Gen&>>; + requires bool_constant<(_Gen::min() < _Gen::max())>::value; + }; + +#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS) + +_LIBCPP_END_NAMESPACE_STD + +_LIBCPP_POP_MACROS + +#endif // _LIBCPP___RANDOM_UNIFORM_RANDOM_BIT_GENERATOR_H diff --git a/contrib/libs/cxxsupp/libcxxmsvc/include/__random/uniform_real_distribution.h b/contrib/libs/cxxsupp/libcxxmsvc/include/__random/uniform_real_distribution.h new file mode 100644 index 0000000000..e11222540b --- /dev/null +++ b/contrib/libs/cxxsupp/libcxxmsvc/include/__random/uniform_real_distribution.h @@ -0,0 +1,160 @@ +//===----------------------------------------------------------------------===// +// +// 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 _LIBCPP___RANDOM_UNIFORM_REAL_DISTRIBUTION_H +#define _LIBCPP___RANDOM_UNIFORM_REAL_DISTRIBUTION_H + +#include <__config> +#include <__random/generate_canonical.h> +#include <iosfwd> +#include <limits> +#include <type_traits> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +# pragma GCC system_header +#endif + +_LIBCPP_PUSH_MACROS +#include <__undef_macros> + +_LIBCPP_BEGIN_NAMESPACE_STD + +template<class _RealType = double> +class _LIBCPP_TEMPLATE_VIS uniform_real_distribution +{ +public: + // types + typedef _RealType result_type; + + class _LIBCPP_TEMPLATE_VIS param_type + { + result_type __a_; + result_type __b_; + public: + typedef uniform_real_distribution distribution_type; + + _LIBCPP_INLINE_VISIBILITY + explicit param_type(result_type __a = 0, + result_type __b = 1) + : __a_(__a), __b_(__b) {} + + _LIBCPP_INLINE_VISIBILITY + result_type a() const {return __a_;} + _LIBCPP_INLINE_VISIBILITY + result_type b() const {return __b_;} + + friend _LIBCPP_INLINE_VISIBILITY + bool operator==(const param_type& __x, const param_type& __y) + {return __x.__a_ == __y.__a_ && __x.__b_ == __y.__b_;} + friend _LIBCPP_INLINE_VISIBILITY + bool operator!=(const param_type& __x, const param_type& __y) + {return !(__x == __y);} + }; + +private: + param_type __p_; + +public: + // constructors and reset functions +#ifndef _LIBCPP_CXX03_LANG + _LIBCPP_INLINE_VISIBILITY + uniform_real_distribution() : uniform_real_distribution(0) {} + explicit uniform_real_distribution(result_type __a, result_type __b = 1) + : __p_(param_type(__a, __b)) {} +#else + _LIBCPP_INLINE_VISIBILITY + explicit uniform_real_distribution(result_type __a = 0, result_type __b = 1) + : __p_(param_type(__a, __b)) {} +#endif + _LIBCPP_INLINE_VISIBILITY + explicit uniform_real_distribution(const param_type& __p) : __p_(__p) {} + _LIBCPP_INLINE_VISIBILITY + void reset() {} + + // generating functions + template<class _URNG> + _LIBCPP_INLINE_VISIBILITY + result_type operator()(_URNG& __g) + {return (*this)(__g, __p_);} + template<class _URNG> _LIBCPP_INLINE_VISIBILITY result_type operator()(_URNG& __g, const param_type& __p); + + // property functions + _LIBCPP_INLINE_VISIBILITY + result_type a() const {return __p_.a();} + _LIBCPP_INLINE_VISIBILITY + result_type b() const {return __p_.b();} + + _LIBCPP_INLINE_VISIBILITY + param_type param() const {return __p_;} + _LIBCPP_INLINE_VISIBILITY + void param(const param_type& __p) {__p_ = __p;} + + _LIBCPP_INLINE_VISIBILITY + result_type min() const {return a();} + _LIBCPP_INLINE_VISIBILITY + result_type max() const {return b();} + + friend _LIBCPP_INLINE_VISIBILITY + bool operator==(const uniform_real_distribution& __x, + const uniform_real_distribution& __y) + {return __x.__p_ == __y.__p_;} + friend _LIBCPP_INLINE_VISIBILITY + bool operator!=(const uniform_real_distribution& __x, + const uniform_real_distribution& __y) + {return !(__x == __y);} +}; + +template<class _RealType> +template<class _URNG> +inline +typename uniform_real_distribution<_RealType>::result_type +uniform_real_distribution<_RealType>::operator()(_URNG& __g, const param_type& __p) +{ + return (__p.b() - __p.a()) + * _VSTD::generate_canonical<_RealType, numeric_limits<_RealType>::digits>(__g) + + __p.a(); +} + +template <class _CharT, class _Traits, class _RT> +basic_ostream<_CharT, _Traits>& +operator<<(basic_ostream<_CharT, _Traits>& __os, + const uniform_real_distribution<_RT>& __x) +{ + __save_flags<_CharT, _Traits> __lx(__os); + typedef basic_ostream<_CharT, _Traits> _OStream; + __os.flags(_OStream::dec | _OStream::left | _OStream::fixed | + _OStream::scientific); + _CharT __sp = __os.widen(' '); + __os.fill(__sp); + return __os << __x.a() << __sp << __x.b(); +} + +template <class _CharT, class _Traits, class _RT> +basic_istream<_CharT, _Traits>& +operator>>(basic_istream<_CharT, _Traits>& __is, + uniform_real_distribution<_RT>& __x) +{ + typedef uniform_real_distribution<_RT> _Eng; + typedef typename _Eng::result_type result_type; + typedef typename _Eng::param_type param_type; + __save_flags<_CharT, _Traits> __lx(__is); + typedef basic_istream<_CharT, _Traits> _Istream; + __is.flags(_Istream::dec | _Istream::skipws); + result_type __a; + result_type __b; + __is >> __a >> __b; + if (!__is.fail()) + __x.param(param_type(__a, __b)); + return __is; +} + +_LIBCPP_END_NAMESPACE_STD + +_LIBCPP_POP_MACROS + +#endif // _LIBCPP___RANDOM_UNIFORM_REAL_DISTRIBUTION_H diff --git a/contrib/libs/cxxsupp/libcxxmsvc/include/__random/weibull_distribution.h b/contrib/libs/cxxsupp/libcxxmsvc/include/__random/weibull_distribution.h new file mode 100644 index 0000000000..85bae65096 --- /dev/null +++ b/contrib/libs/cxxsupp/libcxxmsvc/include/__random/weibull_distribution.h @@ -0,0 +1,155 @@ +//===----------------------------------------------------------------------===// +// +// 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 _LIBCPP___RANDOM_WEIBULL_DISTRIBUTION_H +#define _LIBCPP___RANDOM_WEIBULL_DISTRIBUTION_H + +#include <__config> +#include <__random/exponential_distribution.h> +#include <cmath> +#include <iosfwd> +#include <limits> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +# pragma GCC system_header +#endif + +_LIBCPP_PUSH_MACROS +#include <__undef_macros> + +_LIBCPP_BEGIN_NAMESPACE_STD + +template<class _RealType = double> +class _LIBCPP_TEMPLATE_VIS weibull_distribution +{ +public: + // types + typedef _RealType result_type; + + class _LIBCPP_TEMPLATE_VIS param_type + { + result_type __a_; + result_type __b_; + public: + typedef weibull_distribution distribution_type; + + _LIBCPP_INLINE_VISIBILITY + explicit param_type(result_type __a = 1, result_type __b = 1) + : __a_(__a), __b_(__b) {} + + _LIBCPP_INLINE_VISIBILITY + result_type a() const {return __a_;} + _LIBCPP_INLINE_VISIBILITY + result_type b() const {return __b_;} + + friend _LIBCPP_INLINE_VISIBILITY + bool operator==(const param_type& __x, const param_type& __y) + {return __x.__a_ == __y.__a_ && __x.__b_ == __y.__b_;} + friend _LIBCPP_INLINE_VISIBILITY + bool operator!=(const param_type& __x, const param_type& __y) + {return !(__x == __y);} + }; + +private: + param_type __p_; + +public: + // constructor and reset functions +#ifndef _LIBCPP_CXX03_LANG + _LIBCPP_INLINE_VISIBILITY + weibull_distribution() : weibull_distribution(1) {} + _LIBCPP_INLINE_VISIBILITY + explicit weibull_distribution(result_type __a, result_type __b = 1) + : __p_(param_type(__a, __b)) {} +#else + _LIBCPP_INLINE_VISIBILITY + explicit weibull_distribution(result_type __a = 1, result_type __b = 1) + : __p_(param_type(__a, __b)) {} +#endif + _LIBCPP_INLINE_VISIBILITY + explicit weibull_distribution(const param_type& __p) + : __p_(__p) {} + _LIBCPP_INLINE_VISIBILITY + void reset() {} + + // generating functions + template<class _URNG> + _LIBCPP_INLINE_VISIBILITY + result_type operator()(_URNG& __g) + {return (*this)(__g, __p_);} + template<class _URNG> + _LIBCPP_INLINE_VISIBILITY + result_type operator()(_URNG& __g, const param_type& __p) + {return __p.b() * + _VSTD::pow(exponential_distribution<result_type>()(__g), 1/__p.a());} + + // property functions + _LIBCPP_INLINE_VISIBILITY + result_type a() const {return __p_.a();} + _LIBCPP_INLINE_VISIBILITY + result_type b() const {return __p_.b();} + + _LIBCPP_INLINE_VISIBILITY + param_type param() const {return __p_;} + _LIBCPP_INLINE_VISIBILITY + void param(const param_type& __p) {__p_ = __p;} + + _LIBCPP_INLINE_VISIBILITY + result_type min() const {return 0;} + _LIBCPP_INLINE_VISIBILITY + result_type max() const {return numeric_limits<result_type>::infinity();} + + friend _LIBCPP_INLINE_VISIBILITY + bool operator==(const weibull_distribution& __x, + const weibull_distribution& __y) + {return __x.__p_ == __y.__p_;} + friend _LIBCPP_INLINE_VISIBILITY + bool operator!=(const weibull_distribution& __x, + const weibull_distribution& __y) + {return !(__x == __y);} +}; + +template <class _CharT, class _Traits, class _RT> +basic_ostream<_CharT, _Traits>& +operator<<(basic_ostream<_CharT, _Traits>& __os, + const weibull_distribution<_RT>& __x) +{ + __save_flags<_CharT, _Traits> __lx(__os); + typedef basic_ostream<_CharT, _Traits> _OStream; + __os.flags(_OStream::dec | _OStream::left | _OStream::fixed | + _OStream::scientific); + _CharT __sp = __os.widen(' '); + __os.fill(__sp); + __os << __x.a() << __sp << __x.b(); + return __os; +} + +template <class _CharT, class _Traits, class _RT> +basic_istream<_CharT, _Traits>& +operator>>(basic_istream<_CharT, _Traits>& __is, + weibull_distribution<_RT>& __x) +{ + typedef weibull_distribution<_RT> _Eng; + typedef typename _Eng::result_type result_type; + typedef typename _Eng::param_type param_type; + __save_flags<_CharT, _Traits> __lx(__is); + typedef basic_istream<_CharT, _Traits> _Istream; + __is.flags(_Istream::dec | _Istream::skipws); + result_type __a; + result_type __b; + __is >> __a >> __b; + if (!__is.fail()) + __x.param(param_type(__a, __b)); + return __is; +} + +_LIBCPP_END_NAMESPACE_STD + +_LIBCPP_POP_MACROS + +#endif // _LIBCPP___RANDOM_WEIBULL_DISTRIBUTION_H diff --git a/contrib/libs/cxxsupp/libcxxmsvc/include/__ranges/all.h b/contrib/libs/cxxsupp/libcxxmsvc/include/__ranges/all.h new file mode 100644 index 0000000000..77396222d6 --- /dev/null +++ b/contrib/libs/cxxsupp/libcxxmsvc/include/__ranges/all.h @@ -0,0 +1,82 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// 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 _LIBCPP___RANGES_ALL_H +#define _LIBCPP___RANGES_ALL_H + +#include <__config> +#include <__iterator/concepts.h> +#include <__iterator/iterator_traits.h> +#include <__ranges/access.h> +#include <__ranges/concepts.h> +#include <__ranges/owning_view.h> +#include <__ranges/range_adaptor.h> +#include <__ranges/ref_view.h> +#include <__utility/auto_cast.h> +#include <__utility/declval.h> +#include <__utility/forward.h> +#include <type_traits> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +# pragma GCC system_header +#endif + +_LIBCPP_BEGIN_NAMESPACE_STD + +#if !defined(_LIBCPP_HAS_NO_CONCEPTS) && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES) + +namespace ranges::views { + +namespace __all { + struct __fn : __range_adaptor_closure<__fn> { + template<class _Tp> + requires ranges::view<decay_t<_Tp>> + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI + constexpr auto operator()(_Tp&& __t) const + noexcept(noexcept(_LIBCPP_AUTO_CAST(std::forward<_Tp>(__t)))) + { + return _LIBCPP_AUTO_CAST(std::forward<_Tp>(__t)); + } + + template<class _Tp> + requires (!ranges::view<decay_t<_Tp>>) && + requires (_Tp&& __t) { ranges::ref_view{std::forward<_Tp>(__t)}; } + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI + constexpr auto operator()(_Tp&& __t) const + noexcept(noexcept(ranges::ref_view{std::forward<_Tp>(__t)})) + { + return ranges::ref_view{std::forward<_Tp>(__t)}; + } + + template<class _Tp> + requires (!ranges::view<decay_t<_Tp>> && + !requires (_Tp&& __t) { ranges::ref_view{std::forward<_Tp>(__t)}; } && + requires (_Tp&& __t) { ranges::owning_view{std::forward<_Tp>(__t)}; }) + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI + constexpr auto operator()(_Tp&& __t) const + noexcept(noexcept(ranges::owning_view{std::forward<_Tp>(__t)})) + { + return ranges::owning_view{std::forward<_Tp>(__t)}; + } + }; +} // namespace __all + +inline namespace __cpo { + inline constexpr auto all = __all::__fn{}; +} // namespace __cpo + +template<ranges::viewable_range _Range> +using all_t = decltype(views::all(declval<_Range>())); + +} // namespace ranges::views + +#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS) && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES) + +_LIBCPP_END_NAMESPACE_STD + +#endif // _LIBCPP___RANGES_ALL_H diff --git a/contrib/libs/cxxsupp/libcxxmsvc/include/__ranges/common_view.h b/contrib/libs/cxxsupp/libcxxmsvc/include/__ranges/common_view.h new file mode 100644 index 0000000000..78911284bb --- /dev/null +++ b/contrib/libs/cxxsupp/libcxxmsvc/include/__ranges/common_view.h @@ -0,0 +1,135 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// 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 _LIBCPP___RANGES_COMMON_VIEW_H +#define _LIBCPP___RANGES_COMMON_VIEW_H + +#include <__config> +#include <__iterator/common_iterator.h> +#include <__iterator/iterator_traits.h> +#include <__ranges/access.h> +#include <__ranges/all.h> +#include <__ranges/concepts.h> +#include <__ranges/enable_borrowed_range.h> +#include <__ranges/range_adaptor.h> +#include <__ranges/size.h> +#include <__ranges/view_interface.h> +#include <__utility/forward.h> +#include <__utility/move.h> +#include <concepts> +#include <type_traits> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +# pragma GCC system_header +#endif + +_LIBCPP_BEGIN_NAMESPACE_STD + +#if !defined(_LIBCPP_HAS_NO_CONCEPTS) && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES) + +namespace ranges { + +template<view _View> + requires (!common_range<_View> && copyable<iterator_t<_View>>) +class common_view : public view_interface<common_view<_View>> { + _View __base_ = _View(); + +public: + _LIBCPP_HIDE_FROM_ABI + common_view() requires default_initializable<_View> = default; + + _LIBCPP_HIDE_FROM_ABI + constexpr explicit common_view(_View __v) : __base_(std::move(__v)) { } + + _LIBCPP_HIDE_FROM_ABI + constexpr _View base() const& requires copy_constructible<_View> { return __base_; } + + _LIBCPP_HIDE_FROM_ABI + constexpr _View base() && { return std::move(__base_); } + + _LIBCPP_HIDE_FROM_ABI + constexpr auto begin() { + if constexpr (random_access_range<_View> && sized_range<_View>) + return ranges::begin(__base_); + else + return common_iterator<iterator_t<_View>, sentinel_t<_View>>(ranges::begin(__base_)); + } + + _LIBCPP_HIDE_FROM_ABI + constexpr auto begin() const requires range<const _View> { + if constexpr (random_access_range<const _View> && sized_range<const _View>) + return ranges::begin(__base_); + else + return common_iterator<iterator_t<const _View>, sentinel_t<const _View>>(ranges::begin(__base_)); + } + + _LIBCPP_HIDE_FROM_ABI + constexpr auto end() { + if constexpr (random_access_range<_View> && sized_range<_View>) + return ranges::begin(__base_) + ranges::size(__base_); + else + return common_iterator<iterator_t<_View>, sentinel_t<_View>>(ranges::end(__base_)); + } + + _LIBCPP_HIDE_FROM_ABI + constexpr auto end() const requires range<const _View> { + if constexpr (random_access_range<const _View> && sized_range<const _View>) + return ranges::begin(__base_) + ranges::size(__base_); + else + return common_iterator<iterator_t<const _View>, sentinel_t<const _View>>(ranges::end(__base_)); + } + + _LIBCPP_HIDE_FROM_ABI + constexpr auto size() requires sized_range<_View> { + return ranges::size(__base_); + } + + _LIBCPP_HIDE_FROM_ABI + constexpr auto size() const requires sized_range<const _View> { + return ranges::size(__base_); + } +}; + +template<class _Range> +common_view(_Range&&) + -> common_view<views::all_t<_Range>>; + +template<class _View> +inline constexpr bool enable_borrowed_range<common_view<_View>> = enable_borrowed_range<_View>; + +namespace views { +namespace __common { + struct __fn : __range_adaptor_closure<__fn> { + template<class _Range> + requires common_range<_Range> + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI + constexpr auto operator()(_Range&& __range) const + noexcept(noexcept(views::all(std::forward<_Range>(__range)))) + -> decltype( views::all(std::forward<_Range>(__range))) + { return views::all(std::forward<_Range>(__range)); } + + template<class _Range> + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI + constexpr auto operator()(_Range&& __range) const + noexcept(noexcept(common_view{std::forward<_Range>(__range)})) + -> decltype( common_view{std::forward<_Range>(__range)}) + { return common_view{std::forward<_Range>(__range)}; } + }; +} // namespace __common + +inline namespace __cpo { + inline constexpr auto common = __common::__fn{}; +} // namespace __cpo +} // namespace views +} // namespace ranges + +#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS) && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES) + +_LIBCPP_END_NAMESPACE_STD + +#endif // _LIBCPP___RANGES_COMMON_VIEW_H diff --git a/contrib/libs/cxxsupp/libcxxmsvc/include/__ranges/copyable_box.h b/contrib/libs/cxxsupp/libcxxmsvc/include/__ranges/copyable_box.h new file mode 100644 index 0000000000..e1c08a7ea1 --- /dev/null +++ b/contrib/libs/cxxsupp/libcxxmsvc/include/__ranges/copyable_box.h @@ -0,0 +1,178 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// 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 _LIBCPP___RANGES_COPYABLE_BOX_H +#define _LIBCPP___RANGES_COPYABLE_BOX_H + +#include <__config> +#include <__memory/addressof.h> +#include <__memory/construct_at.h> +#include <__utility/move.h> +#include <concepts> +#include <optional> +#include <type_traits> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +# pragma GCC system_header +#endif + +_LIBCPP_BEGIN_NAMESPACE_STD + +#if !defined(_LIBCPP_HAS_NO_CONCEPTS) && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES) + +// __copyable_box allows turning a type that is copy-constructible (but maybe not copy-assignable) into +// a type that is both copy-constructible and copy-assignable. It does that by introducing an empty state +// and basically doing destroy-then-copy-construct in the assignment operator. The empty state is necessary +// to handle the case where the copy construction fails after destroying the object. +// +// In some cases, we can completely avoid the use of an empty state; we provide a specialization of +// __copyable_box that does this, see below for the details. + +template<class _Tp> +concept __copy_constructible_object = copy_constructible<_Tp> && is_object_v<_Tp>; + +namespace ranges { + // Primary template - uses std::optional and introduces an empty state in case assignment fails. + template<__copy_constructible_object _Tp> + class __copyable_box { + _LIBCPP_NO_UNIQUE_ADDRESS optional<_Tp> __val_; + + public: + template<class ..._Args> + requires is_constructible_v<_Tp, _Args...> + _LIBCPP_HIDE_FROM_ABI + constexpr explicit __copyable_box(in_place_t, _Args&& ...__args) + noexcept(is_nothrow_constructible_v<_Tp, _Args...>) + : __val_(in_place, std::forward<_Args>(__args)...) + { } + + _LIBCPP_HIDE_FROM_ABI + constexpr __copyable_box() noexcept(is_nothrow_default_constructible_v<_Tp>) + requires default_initializable<_Tp> + : __val_(in_place) + { } + + _LIBCPP_HIDE_FROM_ABI __copyable_box(__copyable_box const&) = default; + _LIBCPP_HIDE_FROM_ABI __copyable_box(__copyable_box&&) = default; + + _LIBCPP_HIDE_FROM_ABI + constexpr __copyable_box& operator=(__copyable_box const& __other) + noexcept(is_nothrow_copy_constructible_v<_Tp>) + { + if (this != std::addressof(__other)) { + if (__other.__has_value()) __val_.emplace(*__other); + else __val_.reset(); + } + return *this; + } + + _LIBCPP_HIDE_FROM_ABI + __copyable_box& operator=(__copyable_box&&) requires movable<_Tp> = default; + + _LIBCPP_HIDE_FROM_ABI + constexpr __copyable_box& operator=(__copyable_box&& __other) + noexcept(is_nothrow_move_constructible_v<_Tp>) + { + if (this != std::addressof(__other)) { + if (__other.__has_value()) __val_.emplace(std::move(*__other)); + else __val_.reset(); + } + return *this; + } + + _LIBCPP_HIDE_FROM_ABI constexpr _Tp const& operator*() const noexcept { return *__val_; } + _LIBCPP_HIDE_FROM_ABI constexpr _Tp& operator*() noexcept { return *__val_; } + + _LIBCPP_HIDE_FROM_ABI constexpr const _Tp *operator->() const noexcept { return __val_.operator->(); } + _LIBCPP_HIDE_FROM_ABI constexpr _Tp *operator->() noexcept { return __val_.operator->(); } + + _LIBCPP_HIDE_FROM_ABI constexpr bool __has_value() const noexcept { return __val_.has_value(); } + }; + + // This partial specialization implements an optimization for when we know we don't need to store + // an empty state to represent failure to perform an assignment. For copy-assignment, this happens: + // + // 1. If the type is copyable (which includes copy-assignment), we can use the type's own assignment operator + // directly and avoid using std::optional. + // 2. If the type is not copyable, but it is nothrow-copy-constructible, then we can implement assignment as + // destroy-and-then-construct and we know it will never fail, so we don't need an empty state. + // + // The exact same reasoning can be applied for move-assignment, with copyable replaced by movable and + // nothrow-copy-constructible replaced by nothrow-move-constructible. This specialization is enabled + // whenever we can apply any of these optimizations for both the copy assignment and the move assignment + // operator. + template<class _Tp> + concept __doesnt_need_empty_state_for_copy = copyable<_Tp> || is_nothrow_copy_constructible_v<_Tp>; + + template<class _Tp> + concept __doesnt_need_empty_state_for_move = movable<_Tp> || is_nothrow_move_constructible_v<_Tp>; + + template<__copy_constructible_object _Tp> + requires __doesnt_need_empty_state_for_copy<_Tp> && __doesnt_need_empty_state_for_move<_Tp> + class __copyable_box<_Tp> { + _LIBCPP_NO_UNIQUE_ADDRESS _Tp __val_; + + public: + template<class ..._Args> + requires is_constructible_v<_Tp, _Args...> + _LIBCPP_HIDE_FROM_ABI + constexpr explicit __copyable_box(in_place_t, _Args&& ...__args) + noexcept(is_nothrow_constructible_v<_Tp, _Args...>) + : __val_(std::forward<_Args>(__args)...) + { } + + _LIBCPP_HIDE_FROM_ABI + constexpr __copyable_box() noexcept(is_nothrow_default_constructible_v<_Tp>) + requires default_initializable<_Tp> + : __val_() + { } + + _LIBCPP_HIDE_FROM_ABI __copyable_box(__copyable_box const&) = default; + _LIBCPP_HIDE_FROM_ABI __copyable_box(__copyable_box&&) = default; + + // Implementation of assignment operators in case we perform optimization (1) + _LIBCPP_HIDE_FROM_ABI __copyable_box& operator=(__copyable_box const&) requires copyable<_Tp> = default; + _LIBCPP_HIDE_FROM_ABI __copyable_box& operator=(__copyable_box&&) requires movable<_Tp> = default; + + // Implementation of assignment operators in case we perform optimization (2) + _LIBCPP_HIDE_FROM_ABI + constexpr __copyable_box& operator=(__copyable_box const& __other) noexcept { + static_assert(is_nothrow_copy_constructible_v<_Tp>); + if (this != std::addressof(__other)) { + std::destroy_at(std::addressof(__val_)); + std::construct_at(std::addressof(__val_), __other.__val_); + } + return *this; + } + + _LIBCPP_HIDE_FROM_ABI + constexpr __copyable_box& operator=(__copyable_box&& __other) noexcept { + static_assert(is_nothrow_move_constructible_v<_Tp>); + if (this != std::addressof(__other)) { + std::destroy_at(std::addressof(__val_)); + std::construct_at(std::addressof(__val_), std::move(__other.__val_)); + } + return *this; + } + + _LIBCPP_HIDE_FROM_ABI constexpr _Tp const& operator*() const noexcept { return __val_; } + _LIBCPP_HIDE_FROM_ABI constexpr _Tp& operator*() noexcept { return __val_; } + + _LIBCPP_HIDE_FROM_ABI constexpr const _Tp *operator->() const noexcept { return std::addressof(__val_); } + _LIBCPP_HIDE_FROM_ABI constexpr _Tp *operator->() noexcept { return std::addressof(__val_); } + + _LIBCPP_HIDE_FROM_ABI constexpr bool __has_value() const noexcept { return true; } + }; +} // namespace ranges + +#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS) && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES) + +_LIBCPP_END_NAMESPACE_STD + +#endif // _LIBCPP___RANGES_COPYABLE_BOX_H diff --git a/contrib/libs/cxxsupp/libcxxmsvc/include/__ranges/counted.h b/contrib/libs/cxxsupp/libcxxmsvc/include/__ranges/counted.h new file mode 100644 index 0000000000..0a2d828578 --- /dev/null +++ b/contrib/libs/cxxsupp/libcxxmsvc/include/__ranges/counted.h @@ -0,0 +1,81 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// 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 _LIBCPP___RANGES_COUNTED_H +#define _LIBCPP___RANGES_COUNTED_H + +#include <__concepts/convertible_to.h> +#include <__config> +#include <__iterator/concepts.h> +#include <__iterator/counted_iterator.h> +#include <__iterator/default_sentinel.h> +#include <__iterator/incrementable_traits.h> +#include <__iterator/iterator_traits.h> +#include <__memory/pointer_traits.h> +#include <__ranges/subrange.h> +#include <__utility/forward.h> +#include <__utility/move.h> +#include <span> +#include <type_traits> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +# pragma GCC system_header +#endif + +_LIBCPP_BEGIN_NAMESPACE_STD + +#if !defined(_LIBCPP_HAS_NO_CONCEPTS) && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES) + +namespace ranges::views { + +namespace __counted { + + struct __fn { + template<contiguous_iterator _It> + _LIBCPP_HIDE_FROM_ABI + static constexpr auto __go(_It __it, iter_difference_t<_It> __count) + noexcept(noexcept(span(std::to_address(__it), static_cast<size_t>(__count)))) + // Deliberately omit return-type SFINAE, because to_address is not SFINAE-friendly + { return span(std::to_address(__it), static_cast<size_t>(__count)); } + + template<random_access_iterator _It> + _LIBCPP_HIDE_FROM_ABI + static constexpr auto __go(_It __it, iter_difference_t<_It> __count) + noexcept(noexcept(subrange(__it, __it + __count))) + -> decltype( subrange(__it, __it + __count)) + { return subrange(__it, __it + __count); } + + template<class _It> + _LIBCPP_HIDE_FROM_ABI + static constexpr auto __go(_It __it, iter_difference_t<_It> __count) + noexcept(noexcept(subrange(counted_iterator(std::move(__it), __count), default_sentinel))) + -> decltype( subrange(counted_iterator(std::move(__it), __count), default_sentinel)) + { return subrange(counted_iterator(std::move(__it), __count), default_sentinel); } + + template<class _It, convertible_to<iter_difference_t<_It>> _Diff> + requires input_or_output_iterator<decay_t<_It>> + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI + constexpr auto operator()(_It&& __it, _Diff&& __count) const + noexcept(noexcept(__go(std::forward<_It>(__it), std::forward<_Diff>(__count)))) + -> decltype( __go(std::forward<_It>(__it), std::forward<_Diff>(__count))) + { return __go(std::forward<_It>(__it), std::forward<_Diff>(__count)); } + }; + +} // namespace __counted + +inline namespace __cpo { + inline constexpr auto counted = __counted::__fn{}; +} // namespace __cpo + +} // namespace ranges::views + +#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS) && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES) + +_LIBCPP_END_NAMESPACE_STD + +#endif // _LIBCPP___RANGES_COUNTED_H diff --git a/contrib/libs/cxxsupp/libcxxmsvc/include/__ranges/drop_view.h b/contrib/libs/cxxsupp/libcxxmsvc/include/__ranges/drop_view.h new file mode 100644 index 0000000000..079a74d4b8 --- /dev/null +++ b/contrib/libs/cxxsupp/libcxxmsvc/include/__ranges/drop_view.h @@ -0,0 +1,127 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// 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 _LIBCPP___RANGES_DROP_VIEW_H +#define _LIBCPP___RANGES_DROP_VIEW_H + +#include <__assert> +#include <__config> +#include <__iterator/concepts.h> +#include <__iterator/iterator_traits.h> +#include <__iterator/next.h> +#include <__ranges/access.h> +#include <__ranges/all.h> +#include <__ranges/concepts.h> +#include <__ranges/enable_borrowed_range.h> +#include <__ranges/non_propagating_cache.h> +#include <__ranges/size.h> +#include <__ranges/view_interface.h> +#include <__utility/move.h> +#include <concepts> +#include <type_traits> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +# pragma GCC system_header +#endif + +_LIBCPP_BEGIN_NAMESPACE_STD + +#if !defined(_LIBCPP_HAS_NO_CONCEPTS) && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES) + +namespace ranges { + template<view _View> + class drop_view + : public view_interface<drop_view<_View>> + { + // We cache begin() whenever ranges::next is not guaranteed O(1) to provide an + // amortized O(1) begin() method. If this is an input_range, then we cannot cache + // begin because begin is not equality preserving. + // Note: drop_view<input-range>::begin() is still trivially amortized O(1) because + // one can't call begin() on it more than once. + static constexpr bool _UseCache = forward_range<_View> && !(random_access_range<_View> && sized_range<_View>); + using _Cache = _If<_UseCache, __non_propagating_cache<iterator_t<_View>>, __empty_cache>; + _LIBCPP_NO_UNIQUE_ADDRESS _Cache __cached_begin_ = _Cache(); + range_difference_t<_View> __count_ = 0; + _View __base_ = _View(); + +public: + drop_view() requires default_initializable<_View> = default; + + _LIBCPP_HIDE_FROM_ABI + constexpr drop_view(_View __base, range_difference_t<_View> __count) + : __count_(__count) + , __base_(std::move(__base)) + { + _LIBCPP_ASSERT(__count_ >= 0, "count must be greater than or equal to zero."); + } + + _LIBCPP_HIDE_FROM_ABI constexpr _View base() const& requires copy_constructible<_View> { return __base_; } + _LIBCPP_HIDE_FROM_ABI constexpr _View base() && { return std::move(__base_); } + + _LIBCPP_HIDE_FROM_ABI + constexpr auto begin() + requires (!(__simple_view<_View> && + random_access_range<const _View> && sized_range<const _View>)) + { + if constexpr (_UseCache) + if (__cached_begin_.__has_value()) + return *__cached_begin_; + + auto __tmp = ranges::next(ranges::begin(__base_), __count_, ranges::end(__base_)); + if constexpr (_UseCache) + __cached_begin_.__emplace(__tmp); + return __tmp; + } + + _LIBCPP_HIDE_FROM_ABI + constexpr auto begin() const + requires random_access_range<const _View> && sized_range<const _View> + { + return ranges::next(ranges::begin(__base_), __count_, ranges::end(__base_)); + } + + _LIBCPP_HIDE_FROM_ABI + constexpr auto end() + requires (!__simple_view<_View>) + { return ranges::end(__base_); } + + _LIBCPP_HIDE_FROM_ABI + constexpr auto end() const + requires range<const _View> + { return ranges::end(__base_); } + + _LIBCPP_HIDE_FROM_ABI + static constexpr auto __size(auto& __self) { + const auto __s = ranges::size(__self.__base_); + const auto __c = static_cast<decltype(__s)>(__self.__count_); + return __s < __c ? 0 : __s - __c; + } + + _LIBCPP_HIDE_FROM_ABI + constexpr auto size() + requires sized_range<_View> + { return __size(*this); } + + _LIBCPP_HIDE_FROM_ABI + constexpr auto size() const + requires sized_range<const _View> + { return __size(*this); } + }; + + template<class _Range> + drop_view(_Range&&, range_difference_t<_Range>) -> drop_view<views::all_t<_Range>>; + + template<class _Tp> + inline constexpr bool enable_borrowed_range<drop_view<_Tp>> = enable_borrowed_range<_Tp>; +} // namespace ranges + +#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS) && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES) + +_LIBCPP_END_NAMESPACE_STD + +#endif // _LIBCPP___RANGES_DROP_VIEW_H diff --git a/contrib/libs/cxxsupp/libcxxmsvc/include/__ranges/empty.h b/contrib/libs/cxxsupp/libcxxmsvc/include/__ranges/empty.h new file mode 100644 index 0000000000..c0b55b221a --- /dev/null +++ b/contrib/libs/cxxsupp/libcxxmsvc/include/__ranges/empty.h @@ -0,0 +1,82 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// 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 _LIBCPP___RANGES_EMPTY_H +#define _LIBCPP___RANGES_EMPTY_H + +#include <__concepts/class_or_enum.h> +#include <__config> +#include <__iterator/concepts.h> +#include <__ranges/access.h> +#include <__ranges/size.h> +#include <type_traits> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +# pragma GCC system_header +#endif + +_LIBCPP_BEGIN_NAMESPACE_STD + +#if !defined(_LIBCPP_HAS_NO_CONCEPTS) && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES) + +// [range.prim.empty] + +namespace ranges { +namespace __empty { + template <class _Tp> + concept __member_empty = + __workaround_52970<_Tp> && + requires(_Tp&& __t) { + bool(__t.empty()); + }; + + template<class _Tp> + concept __can_invoke_size = + !__member_empty<_Tp> && + requires(_Tp&& __t) { ranges::size(__t); }; + + template <class _Tp> + concept __can_compare_begin_end = + !__member_empty<_Tp> && + !__can_invoke_size<_Tp> && + requires(_Tp&& __t) { + bool(ranges::begin(__t) == ranges::end(__t)); + { ranges::begin(__t) } -> forward_iterator; + }; + + struct __fn { + template <__member_empty _Tp> + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr bool operator()(_Tp&& __t) const + noexcept(noexcept(bool(__t.empty()))) { + return bool(__t.empty()); + } + + template <__can_invoke_size _Tp> + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr bool operator()(_Tp&& __t) const + noexcept(noexcept(ranges::size(__t))) { + return ranges::size(__t) == 0; + } + + template<__can_compare_begin_end _Tp> + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr bool operator()(_Tp&& __t) const + noexcept(noexcept(bool(ranges::begin(__t) == ranges::end(__t)))) { + return ranges::begin(__t) == ranges::end(__t); + } + }; +} // namespace __empty + +inline namespace __cpo { + inline constexpr auto empty = __empty::__fn{}; +} // namespace __cpo +} // namespace ranges + +#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS) && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES) + +_LIBCPP_END_NAMESPACE_STD + +#endif // _LIBCPP___RANGES_EMPTY_H diff --git a/contrib/libs/cxxsupp/libcxxmsvc/include/__ranges/empty_view.h b/contrib/libs/cxxsupp/libcxxmsvc/include/__ranges/empty_view.h new file mode 100644 index 0000000000..6a08727678 --- /dev/null +++ b/contrib/libs/cxxsupp/libcxxmsvc/include/__ranges/empty_view.h @@ -0,0 +1,45 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// 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 _LIBCPP___RANGES_EMPTY_VIEW_H +#define _LIBCPP___RANGES_EMPTY_VIEW_H + +#include <__config> +#include <__ranges/enable_borrowed_range.h> +#include <__ranges/view_interface.h> +#include <type_traits> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +# pragma GCC system_header +#endif + +_LIBCPP_BEGIN_NAMESPACE_STD + +#if !defined(_LIBCPP_HAS_NO_CONCEPTS) && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES) + +namespace ranges { + template<class _Tp> + requires is_object_v<_Tp> + class empty_view : public view_interface<empty_view<_Tp>> { + public: + _LIBCPP_HIDE_FROM_ABI static constexpr _Tp* begin() noexcept { return nullptr; } + _LIBCPP_HIDE_FROM_ABI static constexpr _Tp* end() noexcept { return nullptr; } + _LIBCPP_HIDE_FROM_ABI static constexpr _Tp* data() noexcept { return nullptr; } + _LIBCPP_HIDE_FROM_ABI static constexpr size_t size() noexcept { return 0; } + _LIBCPP_HIDE_FROM_ABI static constexpr bool empty() noexcept { return true; } + }; + + template<class _Tp> + inline constexpr bool enable_borrowed_range<empty_view<_Tp>> = true; +} // namespace ranges + +#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS) && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES) + +_LIBCPP_END_NAMESPACE_STD + +#endif // _LIBCPP___RANGES_EMPTY_VIEW_H diff --git a/contrib/libs/cxxsupp/libcxxmsvc/include/__ranges/iota_view.h b/contrib/libs/cxxsupp/libcxxmsvc/include/__ranges/iota_view.h new file mode 100644 index 0000000000..b7c099e049 --- /dev/null +++ b/contrib/libs/cxxsupp/libcxxmsvc/include/__ranges/iota_view.h @@ -0,0 +1,408 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// 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 _LIBCPP___RANGES_IOTA_VIEW_H +#define _LIBCPP___RANGES_IOTA_VIEW_H + +#include <__assert> +#include <__compare/three_way_comparable.h> +#include <__concepts/arithmetic.h> +#include <__concepts/constructible.h> +#include <__concepts/convertible_to.h> +#include <__concepts/copyable.h> +#include <__concepts/equality_comparable.h> +#include <__concepts/invocable.h> +#include <__concepts/same_as.h> +#include <__concepts/semiregular.h> +#include <__concepts/totally_ordered.h> +#include <__config> +#include <__functional/ranges_operations.h> +#include <__iterator/concepts.h> +#include <__iterator/incrementable_traits.h> +#include <__iterator/iterator_traits.h> +#include <__iterator/unreachable_sentinel.h> +#include <__ranges/copyable_box.h> +#include <__ranges/enable_borrowed_range.h> +#include <__ranges/view_interface.h> +#include <__utility/forward.h> +#include <__utility/move.h> +#include <type_traits> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +# pragma GCC system_header +#endif + +_LIBCPP_BEGIN_NAMESPACE_STD + +#if !defined(_LIBCPP_HAS_NO_CONCEPTS) && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES) + +namespace ranges { + template<class _Int> + struct __get_wider_signed { + static auto __call() { + if constexpr (sizeof(_Int) < sizeof(short)) return type_identity<short>{}; + else if constexpr (sizeof(_Int) < sizeof(int)) return type_identity<int>{}; + else if constexpr (sizeof(_Int) < sizeof(long)) return type_identity<long>{}; + else return type_identity<long long>{}; + + static_assert(sizeof(_Int) <= sizeof(long long), + "Found integer-like type that is bigger than largest integer like type."); + } + + using type = typename decltype(__call())::type; + }; + + template<class _Start> + using _IotaDiffT = typename _If< + (!integral<_Start> || sizeof(iter_difference_t<_Start>) > sizeof(_Start)), + type_identity<iter_difference_t<_Start>>, + __get_wider_signed<_Start> + >::type; + + template<class _Iter> + concept __decrementable = incrementable<_Iter> && requires(_Iter __i) { + { --__i } -> same_as<_Iter&>; + { __i-- } -> same_as<_Iter>; + }; + + template<class _Iter> + concept __advanceable = + __decrementable<_Iter> && totally_ordered<_Iter> && + requires(_Iter __i, const _Iter __j, const _IotaDiffT<_Iter> __n) { + { __i += __n } -> same_as<_Iter&>; + { __i -= __n } -> same_as<_Iter&>; + _Iter(__j + __n); + _Iter(__n + __j); + _Iter(__j - __n); + { __j - __j } -> convertible_to<_IotaDiffT<_Iter>>; + }; + + template<class> + struct __iota_iterator_category {}; + + template<incrementable _Tp> + struct __iota_iterator_category<_Tp> { + using iterator_category = input_iterator_tag; + }; + + template<weakly_incrementable _Start, semiregular _Bound = unreachable_sentinel_t> + requires __weakly_equality_comparable_with<_Start, _Bound> && copyable<_Start> + class iota_view : public view_interface<iota_view<_Start, _Bound>> { + struct __iterator : public __iota_iterator_category<_Start> { + friend class iota_view; + + using iterator_concept = + _If<__advanceable<_Start>, random_access_iterator_tag, + _If<__decrementable<_Start>, bidirectional_iterator_tag, + _If<incrementable<_Start>, forward_iterator_tag, + /*Else*/ input_iterator_tag>>>; + + using value_type = _Start; + using difference_type = _IotaDiffT<_Start>; + + _Start __value_ = _Start(); + + _LIBCPP_HIDE_FROM_ABI + __iterator() requires default_initializable<_Start> = default; + + _LIBCPP_HIDE_FROM_ABI + constexpr explicit __iterator(_Start __value) : __value_(std::move(__value)) {} + + _LIBCPP_HIDE_FROM_ABI + constexpr _Start operator*() const noexcept(is_nothrow_copy_constructible_v<_Start>) { + return __value_; + } + + _LIBCPP_HIDE_FROM_ABI + constexpr __iterator& operator++() { + ++__value_; + return *this; + } + + _LIBCPP_HIDE_FROM_ABI + constexpr void operator++(int) { ++*this; } + + _LIBCPP_HIDE_FROM_ABI + constexpr __iterator operator++(int) requires incrementable<_Start> { + auto __tmp = *this; + ++*this; + return __tmp; + } + + _LIBCPP_HIDE_FROM_ABI + constexpr __iterator& operator--() requires __decrementable<_Start> { + --__value_; + return *this; + } + + _LIBCPP_HIDE_FROM_ABI + constexpr __iterator operator--(int) requires __decrementable<_Start> { + auto __tmp = *this; + --*this; + return __tmp; + } + + _LIBCPP_HIDE_FROM_ABI + constexpr __iterator& operator+=(difference_type __n) + requires __advanceable<_Start> + { + if constexpr (__integer_like<_Start> && !__signed_integer_like<_Start>) { + if (__n >= difference_type(0)) { + __value_ += static_cast<_Start>(__n); + } else { + __value_ -= static_cast<_Start>(-__n); + } + } else { + __value_ += __n; + } + return *this; + } + + _LIBCPP_HIDE_FROM_ABI + constexpr __iterator& operator-=(difference_type __n) + requires __advanceable<_Start> + { + if constexpr (__integer_like<_Start> && !__signed_integer_like<_Start>) { + if (__n >= difference_type(0)) { + __value_ -= static_cast<_Start>(__n); + } else { + __value_ += static_cast<_Start>(-__n); + } + } else { + __value_ -= __n; + } + return *this; + } + + _LIBCPP_HIDE_FROM_ABI + constexpr _Start operator[](difference_type __n) const + requires __advanceable<_Start> + { + return _Start(__value_ + __n); + } + + _LIBCPP_HIDE_FROM_ABI + friend constexpr bool operator==(const __iterator& __x, const __iterator& __y) + requires equality_comparable<_Start> + { + return __x.__value_ == __y.__value_; + } + + _LIBCPP_HIDE_FROM_ABI + friend constexpr bool operator<(const __iterator& __x, const __iterator& __y) + requires totally_ordered<_Start> + { + return __x.__value_ < __y.__value_; + } + + _LIBCPP_HIDE_FROM_ABI + friend constexpr bool operator>(const __iterator& __x, const __iterator& __y) + requires totally_ordered<_Start> + { + return __y < __x; + } + + _LIBCPP_HIDE_FROM_ABI + friend constexpr bool operator<=(const __iterator& __x, const __iterator& __y) + requires totally_ordered<_Start> + { + return !(__y < __x); + } + + _LIBCPP_HIDE_FROM_ABI + friend constexpr bool operator>=(const __iterator& __x, const __iterator& __y) + requires totally_ordered<_Start> + { + return !(__x < __y); + } + + friend constexpr auto operator<=>(const __iterator& __x, const __iterator& __y) + requires totally_ordered<_Start> && three_way_comparable<_Start> + { + return __x.__value_ <=> __y.__value_; + } + + _LIBCPP_HIDE_FROM_ABI + friend constexpr __iterator operator+(__iterator __i, difference_type __n) + requires __advanceable<_Start> + { + __i += __n; + return __i; + } + + _LIBCPP_HIDE_FROM_ABI + friend constexpr __iterator operator+(difference_type __n, __iterator __i) + requires __advanceable<_Start> + { + return __i + __n; + } + + _LIBCPP_HIDE_FROM_ABI + friend constexpr __iterator operator-(__iterator __i, difference_type __n) + requires __advanceable<_Start> + { + __i -= __n; + return __i; + } + + _LIBCPP_HIDE_FROM_ABI + friend constexpr difference_type operator-(const __iterator& __x, const __iterator& __y) + requires __advanceable<_Start> + { + if constexpr (__integer_like<_Start>) { + if constexpr (__signed_integer_like<_Start>) { + return difference_type(difference_type(__x.__value_) - difference_type(__y.__value_)); + } + if (__y.__value_ > __x.__value_) { + return difference_type(-difference_type(__y.__value_ - __x.__value_)); + } + return difference_type(__x.__value_ - __y.__value_); + } + return __x.__value_ - __y.__value_; + } + }; + + struct __sentinel { + friend class iota_view; + + private: + _Bound __bound_ = _Bound(); + + public: + _LIBCPP_HIDE_FROM_ABI + __sentinel() = default; + constexpr explicit __sentinel(_Bound __bound) : __bound_(std::move(__bound)) {} + + _LIBCPP_HIDE_FROM_ABI + friend constexpr bool operator==(const __iterator& __x, const __sentinel& __y) { + return __x.__value_ == __y.__bound_; + } + + _LIBCPP_HIDE_FROM_ABI + friend constexpr iter_difference_t<_Start> operator-(const __iterator& __x, const __sentinel& __y) + requires sized_sentinel_for<_Bound, _Start> + { + return __x.__value_ - __y.__bound_; + } + + _LIBCPP_HIDE_FROM_ABI + friend constexpr iter_difference_t<_Start> operator-(const __sentinel& __x, const __iterator& __y) + requires sized_sentinel_for<_Bound, _Start> + { + return -(__y - __x); + } + }; + + _Start __value_ = _Start(); + _Bound __bound_ = _Bound(); + + public: + _LIBCPP_HIDE_FROM_ABI + iota_view() requires default_initializable<_Start> = default; + + _LIBCPP_HIDE_FROM_ABI + constexpr explicit iota_view(_Start __value) : __value_(std::move(__value)) { } + + _LIBCPP_HIDE_FROM_ABI + constexpr iota_view(type_identity_t<_Start> __value, type_identity_t<_Bound> __bound) + : __value_(std::move(__value)), __bound_(std::move(__bound)) { + // Validate the precondition if possible. + if constexpr (totally_ordered_with<_Start, _Bound>) { + _LIBCPP_ASSERT(ranges::less_equal()(__value_, __bound_), + "Precondition violated: value is greater than bound."); + } + } + + _LIBCPP_HIDE_FROM_ABI + constexpr iota_view(__iterator __first, __iterator __last) + requires same_as<_Start, _Bound> + : iota_view(std::move(__first.__value_), std::move(__last.__value_)) {} + + _LIBCPP_HIDE_FROM_ABI + constexpr iota_view(__iterator __first, _Bound __last) + requires same_as<_Bound, unreachable_sentinel_t> + : iota_view(std::move(__first.__value_), std::move(__last)) {} + + _LIBCPP_HIDE_FROM_ABI + constexpr iota_view(__iterator __first, __sentinel __last) + requires (!same_as<_Start, _Bound> && !same_as<_Start, unreachable_sentinel_t>) + : iota_view(std::move(__first.__value_), std::move(__last.__bound_)) {} + + _LIBCPP_HIDE_FROM_ABI + constexpr __iterator begin() const { return __iterator{__value_}; } + + _LIBCPP_HIDE_FROM_ABI + constexpr auto end() const { + if constexpr (same_as<_Bound, unreachable_sentinel_t>) + return unreachable_sentinel; + else + return __sentinel{__bound_}; + } + + _LIBCPP_HIDE_FROM_ABI + constexpr __iterator end() const requires same_as<_Start, _Bound> { + return __iterator{__bound_}; + } + + _LIBCPP_HIDE_FROM_ABI + constexpr auto size() const + requires (same_as<_Start, _Bound> && __advanceable<_Start>) || + (integral<_Start> && integral<_Bound>) || + sized_sentinel_for<_Bound, _Start> + { + if constexpr (__integer_like<_Start> && __integer_like<_Bound>) { + if (__value_ < 0) { + if (__bound_ < 0) { + return std::__to_unsigned_like(-__value_) - std::__to_unsigned_like(-__bound_); + } + return std::__to_unsigned_like(__bound_) + std::__to_unsigned_like(-__value_); + } + return std::__to_unsigned_like(__bound_) - std::__to_unsigned_like(__value_); + } + return std::__to_unsigned_like(__bound_ - __value_); + } + }; + + template<class _Start, class _Bound> + requires (!__integer_like<_Start> || !__integer_like<_Bound> || + (__signed_integer_like<_Start> == __signed_integer_like<_Bound>)) + iota_view(_Start, _Bound) -> iota_view<_Start, _Bound>; + + template<class _Start, class _Bound> + inline constexpr bool enable_borrowed_range<iota_view<_Start, _Bound>> = true; + +namespace views { +namespace __iota { + struct __fn { + template<class _Start> + _LIBCPP_HIDE_FROM_ABI + constexpr auto operator()(_Start&& __start) const + noexcept(noexcept(ranges::iota_view(std::forward<_Start>(__start)))) + -> decltype( ranges::iota_view(std::forward<_Start>(__start))) + { return ranges::iota_view(std::forward<_Start>(__start)); } + + template<class _Start, class _Bound> + _LIBCPP_HIDE_FROM_ABI + constexpr auto operator()(_Start&& __start, _Bound&& __bound) const + noexcept(noexcept(ranges::iota_view(std::forward<_Start>(__start), std::forward<_Bound>(__bound)))) + -> decltype( ranges::iota_view(std::forward<_Start>(__start), std::forward<_Bound>(__bound))) + { return ranges::iota_view(std::forward<_Start>(__start), std::forward<_Bound>(__bound)); } + }; +} // namespace __iota + +inline namespace __cpo { + inline constexpr auto iota = __iota::__fn{}; +} // namespace __cpo +} // namespace views +} // namespace ranges + +#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS) && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES) + +_LIBCPP_END_NAMESPACE_STD + +#endif // _LIBCPP___RANGES_IOTA_VIEW_H diff --git a/contrib/libs/cxxsupp/libcxxmsvc/include/__ranges/join_view.h b/contrib/libs/cxxsupp/libcxxmsvc/include/__ranges/join_view.h new file mode 100644 index 0000000000..395e5c7ece --- /dev/null +++ b/contrib/libs/cxxsupp/libcxxmsvc/include/__ranges/join_view.h @@ -0,0 +1,350 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// 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 _LIBCPP___RANGES_JOIN_VIEW_H +#define _LIBCPP___RANGES_JOIN_VIEW_H + +#include <__config> +#include <__iterator/concepts.h> +#include <__iterator/iterator_traits.h> +#include <__ranges/access.h> +#include <__ranges/all.h> +#include <__ranges/concepts.h> +#include <__ranges/non_propagating_cache.h> +#include <__ranges/ref_view.h> +#include <__ranges/subrange.h> +#include <__ranges/view_interface.h> +#include <__utility/declval.h> +#include <__utility/forward.h> +#include <optional> +#include <type_traits> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +# pragma GCC system_header +#endif + +_LIBCPP_BEGIN_NAMESPACE_STD + +#if !defined(_LIBCPP_HAS_NO_CONCEPTS) && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES) + +namespace ranges { + template<class> + struct __join_view_iterator_category {}; + + template<class _View> + requires is_reference_v<range_reference_t<_View>> && + forward_range<_View> && + forward_range<range_reference_t<_View>> + struct __join_view_iterator_category<_View> { + using _OuterC = typename iterator_traits<iterator_t<_View>>::iterator_category; + using _InnerC = typename iterator_traits<iterator_t<range_reference_t<_View>>>::iterator_category; + + using iterator_category = _If< + derived_from<_OuterC, bidirectional_iterator_tag> && derived_from<_InnerC, bidirectional_iterator_tag>, + bidirectional_iterator_tag, + _If< + derived_from<_OuterC, forward_iterator_tag> && derived_from<_InnerC, forward_iterator_tag>, + forward_iterator_tag, + input_iterator_tag + > + >; + }; + + template<input_range _View> + requires view<_View> && input_range<range_reference_t<_View>> + class join_view + : public view_interface<join_view<_View>> { + private: + using _InnerRange = range_reference_t<_View>; + + template<bool> struct __iterator; + template<bool> struct __sentinel; + + static constexpr bool _UseCache = !is_reference_v<_InnerRange>; + using _Cache = _If<_UseCache, __non_propagating_cache<remove_cvref_t<_InnerRange>>, __empty_cache>; + _LIBCPP_NO_UNIQUE_ADDRESS _Cache __cache_; + _LIBCPP_NO_UNIQUE_ADDRESS _View __base_ = _View(); + + public: + _LIBCPP_HIDE_FROM_ABI + join_view() requires default_initializable<_View> = default; + + _LIBCPP_HIDE_FROM_ABI + constexpr explicit join_view(_View __base) + : __base_(std::move(__base)) {} + + _LIBCPP_HIDE_FROM_ABI + constexpr _View base() const& requires copy_constructible<_View> { return __base_; } + + _LIBCPP_HIDE_FROM_ABI + constexpr _View base() && { return std::move(__base_); } + + _LIBCPP_HIDE_FROM_ABI + constexpr auto begin() { + constexpr bool __use_const = __simple_view<_View> && + is_reference_v<range_reference_t<_View>>; + return __iterator<__use_const>{*this, ranges::begin(__base_)}; + } + + template<class _V2 = _View> + _LIBCPP_HIDE_FROM_ABI + constexpr auto begin() const + requires input_range<const _V2> && + is_reference_v<range_reference_t<const _V2>> + { + return __iterator<true>{*this, ranges::begin(__base_)}; + } + + _LIBCPP_HIDE_FROM_ABI + constexpr auto end() { + if constexpr (forward_range<_View> && + is_reference_v<_InnerRange> && + forward_range<_InnerRange> && + common_range<_View> && + common_range<_InnerRange>) + return __iterator<__simple_view<_View>>{*this, ranges::end(__base_)}; + else + return __sentinel<__simple_view<_View>>{*this}; + } + + template<class _V2 = _View> + _LIBCPP_HIDE_FROM_ABI + constexpr auto end() const + requires input_range<const _V2> && + is_reference_v<range_reference_t<const _V2>> + { + using _ConstInnerRange = range_reference_t<const _View>; + if constexpr (forward_range<const _View> && + is_reference_v<_ConstInnerRange> && + forward_range<_ConstInnerRange> && + common_range<const _View> && + common_range<_ConstInnerRange>) { + return __iterator<true>{*this, ranges::end(__base_)}; + } else { + return __sentinel<true>{*this}; + } + } + }; + + template<input_range _View> + requires view<_View> && input_range<range_reference_t<_View>> + template<bool _Const> struct join_view<_View>::__sentinel { + template<bool> friend struct __sentinel; + + private: + using _Parent = __maybe_const<_Const, join_view>; + using _Base = __maybe_const<_Const, _View>; + sentinel_t<_Base> __end_ = sentinel_t<_Base>(); + + public: + _LIBCPP_HIDE_FROM_ABI + __sentinel() = default; + + _LIBCPP_HIDE_FROM_ABI + constexpr explicit __sentinel(_Parent& __parent) + : __end_(ranges::end(__parent.__base_)) {} + + _LIBCPP_HIDE_FROM_ABI + constexpr __sentinel(__sentinel<!_Const> __s) + requires _Const && convertible_to<sentinel_t<_View>, sentinel_t<_Base>> + : __end_(std::move(__s.__end_)) {} + + template<bool _OtherConst> + requires sentinel_for<sentinel_t<_Base>, iterator_t<__maybe_const<_OtherConst, _View>>> + _LIBCPP_HIDE_FROM_ABI + friend constexpr bool operator==(const __iterator<_OtherConst>& __x, const __sentinel& __y) { + return __x.__outer_ == __y.__end_; + } + }; + + template<input_range _View> + requires view<_View> && input_range<range_reference_t<_View>> + template<bool _Const> struct join_view<_View>::__iterator + : public __join_view_iterator_category<__maybe_const<_Const, _View>> { + + template<bool> friend struct __iterator; + + private: + using _Parent = __maybe_const<_Const, join_view>; + using _Base = __maybe_const<_Const, _View>; + using _Outer = iterator_t<_Base>; + using _Inner = iterator_t<range_reference_t<_Base>>; + + static constexpr bool __ref_is_glvalue = is_reference_v<range_reference_t<_Base>>; + + public: + _Outer __outer_ = _Outer(); + + private: + optional<_Inner> __inner_; + _Parent *__parent_ = nullptr; + + _LIBCPP_HIDE_FROM_ABI + constexpr void __satisfy() { + for (; __outer_ != ranges::end(__parent_->__base_); ++__outer_) { + auto&& __inner = [&]() -> auto&& { + if constexpr (__ref_is_glvalue) + return *__outer_; + else + return __parent_->__cache_.__emplace_from([&]() -> decltype(auto) { return *__outer_; }); + }(); + __inner_ = ranges::begin(__inner); + if (*__inner_ != ranges::end(__inner)) + return; + } + + if constexpr (__ref_is_glvalue) + __inner_.reset(); + } + + public: + using iterator_concept = _If< + __ref_is_glvalue && bidirectional_range<_Base> && bidirectional_range<range_reference_t<_Base>>, + bidirectional_iterator_tag, + _If< + __ref_is_glvalue && forward_range<_Base> && forward_range<range_reference_t<_Base>>, + forward_iterator_tag, + input_iterator_tag + > + >; + + using value_type = range_value_t<range_reference_t<_Base>>; + + using difference_type = common_type_t< + range_difference_t<_Base>, range_difference_t<range_reference_t<_Base>>>; + + _LIBCPP_HIDE_FROM_ABI + __iterator() requires default_initializable<_Outer> = default; + + _LIBCPP_HIDE_FROM_ABI + constexpr __iterator(_Parent& __parent, _Outer __outer) + : __outer_(std::move(__outer)) + , __parent_(std::addressof(__parent)) { + __satisfy(); + } + + _LIBCPP_HIDE_FROM_ABI + constexpr __iterator(__iterator<!_Const> __i) + requires _Const && + convertible_to<iterator_t<_View>, _Outer> && + convertible_to<iterator_t<_InnerRange>, _Inner> + : __outer_(std::move(__i.__outer_)) + , __inner_(std::move(__i.__inner_)) + , __parent_(__i.__parent_) {} + + _LIBCPP_HIDE_FROM_ABI + constexpr decltype(auto) operator*() const { + return **__inner_; + } + + _LIBCPP_HIDE_FROM_ABI + constexpr _Inner operator->() const + requires __has_arrow<_Inner> && copyable<_Inner> + { + return *__inner_; + } + + _LIBCPP_HIDE_FROM_ABI + constexpr __iterator& operator++() { + auto&& __inner = [&]() -> auto&& { + if constexpr (__ref_is_glvalue) + return *__outer_; + else + return *__parent_->__cache_; + }(); + if (++*__inner_ == ranges::end(__inner)) { + ++__outer_; + __satisfy(); + } + return *this; + } + + _LIBCPP_HIDE_FROM_ABI + constexpr void operator++(int) { + ++*this; + } + + _LIBCPP_HIDE_FROM_ABI + constexpr __iterator operator++(int) + requires __ref_is_glvalue && + forward_range<_Base> && + forward_range<range_reference_t<_Base>> + { + auto __tmp = *this; + ++*this; + return __tmp; + } + + _LIBCPP_HIDE_FROM_ABI + constexpr __iterator& operator--() + requires __ref_is_glvalue && + bidirectional_range<_Base> && + bidirectional_range<range_reference_t<_Base>> && + common_range<range_reference_t<_Base>> + { + if (__outer_ == ranges::end(__parent_->__base_)) + __inner_ = ranges::end(*--__outer_); + + // Skip empty inner ranges when going backwards. + while (*__inner_ == ranges::begin(*__outer_)) { + __inner_ = ranges::end(*--__outer_); + } + + --*__inner_; + return *this; + } + + _LIBCPP_HIDE_FROM_ABI + constexpr __iterator operator--(int) + requires __ref_is_glvalue && + bidirectional_range<_Base> && + bidirectional_range<range_reference_t<_Base>> && + common_range<range_reference_t<_Base>> + { + auto __tmp = *this; + --*this; + return __tmp; + } + + _LIBCPP_HIDE_FROM_ABI + friend constexpr bool operator==(const __iterator& __x, const __iterator& __y) + requires __ref_is_glvalue && + equality_comparable<iterator_t<_Base>> && + equality_comparable<iterator_t<range_reference_t<_Base>>> + { + return __x.__outer_ == __y.__outer_ && __x.__inner_ == __y.__inner_; + } + + _LIBCPP_HIDE_FROM_ABI + friend constexpr decltype(auto) iter_move(const __iterator& __i) + noexcept(noexcept(ranges::iter_move(*__i.__inner_))) + { + return ranges::iter_move(*__i.__inner_); + } + + _LIBCPP_HIDE_FROM_ABI + friend constexpr void iter_swap(const __iterator& __x, const __iterator& __y) + noexcept(noexcept(ranges::iter_swap(*__x.__inner_, *__y.__inner_))) + requires indirectly_swappable<_Inner> + { + return ranges::iter_swap(*__x.__inner_, *__y.__inner_); + } + }; + + template<class _Range> + explicit join_view(_Range&&) -> join_view<views::all_t<_Range>>; + +} // namespace ranges + +#undef _CONSTEXPR_TERNARY + +#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS) && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES) + +_LIBCPP_END_NAMESPACE_STD + +#endif // _LIBCPP___RANGES_JOIN_VIEW_H diff --git a/contrib/libs/cxxsupp/libcxxmsvc/include/__ranges/non_propagating_cache.h b/contrib/libs/cxxsupp/libcxxmsvc/include/__ranges/non_propagating_cache.h new file mode 100644 index 0000000000..d9589ae46c --- /dev/null +++ b/contrib/libs/cxxsupp/libcxxmsvc/include/__ranges/non_propagating_cache.h @@ -0,0 +1,114 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// 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 _LIBCPP___RANGES_NON_PROPAGATING_CACHE_H +#define _LIBCPP___RANGES_NON_PROPAGATING_CACHE_H + +#include <__config> +#include <__iterator/concepts.h> // indirectly_readable +#include <__iterator/iterator_traits.h> // iter_reference_t +#include <__memory/addressof.h> +#include <__utility/forward.h> +#include <concepts> // constructible_from +#include <optional> +#include <type_traits> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +# pragma GCC system_header +#endif + +_LIBCPP_BEGIN_NAMESPACE_STD + +#if !defined(_LIBCPP_HAS_NO_CONCEPTS) && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES) + +namespace ranges { + // __non_propagating_cache is a helper type that allows storing an optional value in it, + // but which does not copy the source's value when it is copy constructed/assigned to, + // and which resets the source's value when it is moved-from. + // + // This type is used as an implementation detail of some views that need to cache the + // result of `begin()` in order to provide an amortized O(1) begin() method. Typically, + // we don't want to propagate the value of the cache upon copy because the cached iterator + // may refer to internal details of the source view. + template<class _Tp> + requires is_object_v<_Tp> + class _LIBCPP_TEMPLATE_VIS __non_propagating_cache { + struct __from_tag { }; + struct __forward_tag { }; + + // This helper class is needed to perform copy and move elision when + // constructing the contained type from an iterator. + struct __wrapper { + template<class ..._Args> + constexpr explicit __wrapper(__forward_tag, _Args&& ...__args) : __t_(std::forward<_Args>(__args)...) { } + template<class _Fn> + constexpr explicit __wrapper(__from_tag, _Fn const& __f) : __t_(__f()) { } + _Tp __t_; + }; + + optional<__wrapper> __value_ = nullopt; + + public: + _LIBCPP_HIDE_FROM_ABI __non_propagating_cache() = default; + + _LIBCPP_HIDE_FROM_ABI + constexpr __non_propagating_cache(__non_propagating_cache const&) noexcept + : __value_(nullopt) + { } + + _LIBCPP_HIDE_FROM_ABI + constexpr __non_propagating_cache(__non_propagating_cache&& __other) noexcept + : __value_(nullopt) + { + __other.__value_.reset(); + } + + _LIBCPP_HIDE_FROM_ABI + constexpr __non_propagating_cache& operator=(__non_propagating_cache const& __other) noexcept { + if (this != std::addressof(__other)) { + __value_.reset(); + } + return *this; + } + + _LIBCPP_HIDE_FROM_ABI + constexpr __non_propagating_cache& operator=(__non_propagating_cache&& __other) noexcept { + __value_.reset(); + __other.__value_.reset(); + return *this; + } + + _LIBCPP_HIDE_FROM_ABI + constexpr _Tp& operator*() { return __value_->__t_; } + _LIBCPP_HIDE_FROM_ABI + constexpr _Tp const& operator*() const { return __value_->__t_; } + + _LIBCPP_HIDE_FROM_ABI + constexpr bool __has_value() const { return __value_.has_value(); } + + template<class _Fn> + _LIBCPP_HIDE_FROM_ABI + constexpr _Tp& __emplace_from(_Fn const& __f) { + return __value_.emplace(__from_tag{}, __f).__t_; + } + + template<class ..._Args> + _LIBCPP_HIDE_FROM_ABI + constexpr _Tp& __emplace(_Args&& ...__args) { + return __value_.emplace(__forward_tag{}, std::forward<_Args>(__args)...).__t_; + } + }; + + struct __empty_cache { }; +} // namespace ranges + +#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS) && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES) + +_LIBCPP_END_NAMESPACE_STD + +#endif // _LIBCPP___RANGES_NON_PROPAGATING_CACHE_H diff --git a/contrib/libs/cxxsupp/libcxxmsvc/include/__ranges/owning_view.h b/contrib/libs/cxxsupp/libcxxmsvc/include/__ranges/owning_view.h new file mode 100644 index 0000000000..7987c60751 --- /dev/null +++ b/contrib/libs/cxxsupp/libcxxmsvc/include/__ranges/owning_view.h @@ -0,0 +1,81 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// 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 _LIBCPP___RANGES_OWNING_VIEW_H +#define _LIBCPP___RANGES_OWNING_VIEW_H + +#include <__concepts/constructible.h> +#include <__concepts/movable.h> +#include <__config> +#include <__ranges/access.h> +#include <__ranges/concepts.h> +#include <__ranges/data.h> +#include <__ranges/empty.h> +#include <__ranges/enable_borrowed_range.h> +#include <__ranges/size.h> +#include <__ranges/view_interface.h> +#include <__utility/move.h> +#include <type_traits> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +# pragma GCC system_header +#endif + +_LIBCPP_BEGIN_NAMESPACE_STD + +#if !defined(_LIBCPP_HAS_NO_CONCEPTS) && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES) + +namespace ranges { + template<range _Rp> + requires movable<_Rp> && (!__is_std_initializer_list<remove_cvref_t<_Rp>>) + class owning_view : public view_interface<owning_view<_Rp>> { + _Rp __r_ = _Rp(); + +public: + owning_view() requires default_initializable<_Rp> = default; + _LIBCPP_HIDE_FROM_ABI constexpr owning_view(_Rp&& __r) : __r_(std::move(__r)) {} + + owning_view(owning_view&&) = default; + owning_view& operator=(owning_view&&) = default; + + _LIBCPP_HIDE_FROM_ABI constexpr _Rp& base() & noexcept { return __r_; } + _LIBCPP_HIDE_FROM_ABI constexpr const _Rp& base() const& noexcept { return __r_; } + _LIBCPP_HIDE_FROM_ABI constexpr _Rp&& base() && noexcept { return std::move(__r_); } + _LIBCPP_HIDE_FROM_ABI constexpr const _Rp&& base() const&& noexcept { return std::move(__r_); } + + _LIBCPP_HIDE_FROM_ABI constexpr iterator_t<_Rp> begin() { return ranges::begin(__r_); } + _LIBCPP_HIDE_FROM_ABI constexpr sentinel_t<_Rp> end() { return ranges::end(__r_); } + _LIBCPP_HIDE_FROM_ABI constexpr auto begin() const requires range<const _Rp> { return ranges::begin(__r_); } + _LIBCPP_HIDE_FROM_ABI constexpr auto end() const requires range<const _Rp> { return ranges::end(__r_); } + + _LIBCPP_HIDE_FROM_ABI constexpr bool empty() requires requires { ranges::empty(__r_); } + { return ranges::empty(__r_); } + _LIBCPP_HIDE_FROM_ABI constexpr bool empty() const requires requires { ranges::empty(__r_); } + { return ranges::empty(__r_); } + + _LIBCPP_HIDE_FROM_ABI constexpr auto size() requires sized_range<_Rp> + { return ranges::size(__r_); } + _LIBCPP_HIDE_FROM_ABI constexpr auto size() const requires sized_range<const _Rp> + { return ranges::size(__r_); } + + _LIBCPP_HIDE_FROM_ABI constexpr auto data() requires contiguous_range<_Rp> + { return ranges::data(__r_); } + _LIBCPP_HIDE_FROM_ABI constexpr auto data() const requires contiguous_range<const _Rp> + { return ranges::data(__r_); } + }; + + template<class _Tp> + inline constexpr bool enable_borrowed_range<owning_view<_Tp>> = enable_borrowed_range<_Tp>; + +} // namespace ranges + +#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS) && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES) + +_LIBCPP_END_NAMESPACE_STD + +#endif // _LIBCPP___RANGES_OWNING_VIEW_H diff --git a/contrib/libs/cxxsupp/libcxxmsvc/include/__ranges/range_adaptor.h b/contrib/libs/cxxsupp/libcxxmsvc/include/__ranges/range_adaptor.h new file mode 100644 index 0000000000..9c53488ba6 --- /dev/null +++ b/contrib/libs/cxxsupp/libcxxmsvc/include/__ranges/range_adaptor.h @@ -0,0 +1,73 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// 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 _LIBCPP___RANGES_RANGE_ADAPTOR_H +#define _LIBCPP___RANGES_RANGE_ADAPTOR_H + +#include <__config> +#include <__functional/compose.h> +#include <__functional/invoke.h> +#include <__ranges/concepts.h> +#include <__utility/forward.h> +#include <__utility/move.h> +#include <concepts> +#include <type_traits> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +# pragma GCC system_header +#endif + +_LIBCPP_BEGIN_NAMESPACE_STD + +#if !defined(_LIBCPP_HAS_NO_CONCEPTS) && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES) + +// CRTP base that one can derive from in order to be considered a range adaptor closure +// by the library. When deriving from this class, a pipe operator will be provided to +// make the following hold: +// - `x | f` is equivalent to `f(x)` +// - `f1 | f2` is an adaptor closure `g` such that `g(x)` is equivalent to `f2(f1(x))` +template <class _Tp> +struct __range_adaptor_closure; + +// Type that wraps an arbitrary function object and makes it into a range adaptor closure, +// i.e. something that can be called via the `x | f` notation. +template <class _Fn> +struct __range_adaptor_closure_t : _Fn, __range_adaptor_closure<__range_adaptor_closure_t<_Fn>> { + constexpr explicit __range_adaptor_closure_t(_Fn&& __f) : _Fn(std::move(__f)) { } +}; + +template <class _Tp> +concept _RangeAdaptorClosure = derived_from<remove_cvref_t<_Tp>, __range_adaptor_closure<remove_cvref_t<_Tp>>>; + +template <class _Tp> +struct __range_adaptor_closure { + template <ranges::viewable_range _View, _RangeAdaptorClosure _Closure> + requires same_as<_Tp, remove_cvref_t<_Closure>> && + invocable<_Closure, _View> + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI + friend constexpr decltype(auto) operator|(_View&& __view, _Closure&& __closure) + noexcept(is_nothrow_invocable_v<_Closure, _View>) + { return std::invoke(std::forward<_Closure>(__closure), std::forward<_View>(__view)); } + + template <_RangeAdaptorClosure _Closure, _RangeAdaptorClosure _OtherClosure> + requires same_as<_Tp, remove_cvref_t<_Closure>> && + constructible_from<decay_t<_Closure>, _Closure> && + constructible_from<decay_t<_OtherClosure>, _OtherClosure> + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI + friend constexpr auto operator|(_Closure&& __c1, _OtherClosure&& __c2) + noexcept(is_nothrow_constructible_v<decay_t<_Closure>, _Closure> && + is_nothrow_constructible_v<decay_t<_OtherClosure>, _OtherClosure>) + { return __range_adaptor_closure_t(std::__compose(std::forward<_OtherClosure>(__c2), std::forward<_Closure>(__c1))); } +}; + +#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS) && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES) + +_LIBCPP_END_NAMESPACE_STD + +#endif // _LIBCPP___RANGES_RANGE_ADAPTOR_H diff --git a/contrib/libs/cxxsupp/libcxxmsvc/include/__ranges/rbegin.h b/contrib/libs/cxxsupp/libcxxmsvc/include/__ranges/rbegin.h new file mode 100644 index 0000000000..20f5489c50 --- /dev/null +++ b/contrib/libs/cxxsupp/libcxxmsvc/include/__ranges/rbegin.h @@ -0,0 +1,130 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// 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 _LIBCPP___RANGES_RBEGIN_H +#define _LIBCPP___RANGES_RBEGIN_H + +#include <__concepts/class_or_enum.h> +#include <__concepts/same_as.h> +#include <__config> +#include <__iterator/concepts.h> +#include <__iterator/readable_traits.h> +#include <__iterator/reverse_iterator.h> +#include <__ranges/access.h> +#include <__utility/auto_cast.h> +#include <type_traits> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +# pragma GCC system_header +#endif + +_LIBCPP_BEGIN_NAMESPACE_STD + +#if !defined(_LIBCPP_HAS_NO_CONCEPTS) && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES) + +// [ranges.access.rbegin] + +namespace ranges { +namespace __rbegin { +template <class _Tp> +concept __member_rbegin = + __can_borrow<_Tp> && + __workaround_52970<_Tp> && + requires(_Tp&& __t) { + { _LIBCPP_AUTO_CAST(__t.rbegin()) } -> input_or_output_iterator; + }; + +void rbegin(auto&) = delete; +void rbegin(const auto&) = delete; + +template <class _Tp> +concept __unqualified_rbegin = + !__member_rbegin<_Tp> && + __can_borrow<_Tp> && + __class_or_enum<remove_cvref_t<_Tp>> && + requires(_Tp&& __t) { + { _LIBCPP_AUTO_CAST(rbegin(__t)) } -> input_or_output_iterator; + }; + +template <class _Tp> +concept __can_reverse = + __can_borrow<_Tp> && + !__member_rbegin<_Tp> && + !__unqualified_rbegin<_Tp> && + requires(_Tp&& __t) { + { ranges::begin(__t) } -> same_as<decltype(ranges::end(__t))>; + { ranges::begin(__t) } -> bidirectional_iterator; + }; + +struct __fn { + template <class _Tp> + requires __member_rbegin<_Tp> + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr auto operator()(_Tp&& __t) const + noexcept(noexcept(_LIBCPP_AUTO_CAST(__t.rbegin()))) + { + return _LIBCPP_AUTO_CAST(__t.rbegin()); + } + + template <class _Tp> + requires __unqualified_rbegin<_Tp> + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr auto operator()(_Tp&& __t) const + noexcept(noexcept(_LIBCPP_AUTO_CAST(rbegin(__t)))) + { + return _LIBCPP_AUTO_CAST(rbegin(__t)); + } + + template <class _Tp> + requires __can_reverse<_Tp> + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr auto operator()(_Tp&& __t) const + noexcept(noexcept(ranges::end(__t))) + { + return std::make_reverse_iterator(ranges::end(__t)); + } + + void operator()(auto&&) const = delete; +}; +} // namespace __rbegin + +inline namespace __cpo { + inline constexpr auto rbegin = __rbegin::__fn{}; +} // namespace __cpo +} // namespace ranges + +// [range.access.crbegin] + +namespace ranges { +namespace __crbegin { +struct __fn { + template <class _Tp> + requires is_lvalue_reference_v<_Tp&&> + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI + constexpr auto operator()(_Tp&& __t) const + noexcept(noexcept(ranges::rbegin(static_cast<const remove_reference_t<_Tp>&>(__t)))) + -> decltype( ranges::rbegin(static_cast<const remove_reference_t<_Tp>&>(__t))) + { return ranges::rbegin(static_cast<const remove_reference_t<_Tp>&>(__t)); } + + template <class _Tp> + requires is_rvalue_reference_v<_Tp&&> + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI + constexpr auto operator()(_Tp&& __t) const + noexcept(noexcept(ranges::rbegin(static_cast<const _Tp&&>(__t)))) + -> decltype( ranges::rbegin(static_cast<const _Tp&&>(__t))) + { return ranges::rbegin(static_cast<const _Tp&&>(__t)); } +}; +} // namespace __crbegin + +inline namespace __cpo { + inline constexpr auto crbegin = __crbegin::__fn{}; +} // namespace __cpo +} // namespace ranges + +#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS) && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES) + +_LIBCPP_END_NAMESPACE_STD + +#endif // _LIBCPP___RANGES_RBEGIN_H diff --git a/contrib/libs/cxxsupp/libcxxmsvc/include/__ranges/ref_view.h b/contrib/libs/cxxsupp/libcxxmsvc/include/__ranges/ref_view.h new file mode 100644 index 0000000000..255a468606 --- /dev/null +++ b/contrib/libs/cxxsupp/libcxxmsvc/include/__ranges/ref_view.h @@ -0,0 +1,86 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// 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 _LIBCPP___RANGES_REF_VIEW_H +#define _LIBCPP___RANGES_REF_VIEW_H + +#include <__config> +#include <__iterator/concepts.h> +#include <__iterator/incrementable_traits.h> +#include <__iterator/iterator_traits.h> +#include <__memory/addressof.h> +#include <__ranges/access.h> +#include <__ranges/concepts.h> +#include <__ranges/data.h> +#include <__ranges/empty.h> +#include <__ranges/enable_borrowed_range.h> +#include <__ranges/size.h> +#include <__ranges/view_interface.h> +#include <__utility/forward.h> +#include <concepts> +#include <type_traits> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +# pragma GCC system_header +#endif + +_LIBCPP_BEGIN_NAMESPACE_STD + +#if !defined(_LIBCPP_HAS_NO_CONCEPTS) && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES) + +namespace ranges { + template<range _Range> + requires is_object_v<_Range> + class ref_view : public view_interface<ref_view<_Range>> { + _Range *__range_; + + static void __fun(_Range&); + static void __fun(_Range&&) = delete; + +public: + template<class _Tp> + requires __different_from<_Tp, ref_view> && + convertible_to<_Tp, _Range&> && requires { __fun(declval<_Tp>()); } + _LIBCPP_HIDE_FROM_ABI + constexpr ref_view(_Tp&& __t) + : __range_(std::addressof(static_cast<_Range&>(std::forward<_Tp>(__t)))) + {} + + _LIBCPP_HIDE_FROM_ABI constexpr _Range& base() const { return *__range_; } + + _LIBCPP_HIDE_FROM_ABI constexpr iterator_t<_Range> begin() const { return ranges::begin(*__range_); } + _LIBCPP_HIDE_FROM_ABI constexpr sentinel_t<_Range> end() const { return ranges::end(*__range_); } + + _LIBCPP_HIDE_FROM_ABI + constexpr bool empty() const + requires requires { ranges::empty(*__range_); } + { return ranges::empty(*__range_); } + + _LIBCPP_HIDE_FROM_ABI + constexpr auto size() const + requires sized_range<_Range> + { return ranges::size(*__range_); } + + _LIBCPP_HIDE_FROM_ABI + constexpr auto data() const + requires contiguous_range<_Range> + { return ranges::data(*__range_); } + }; + + template<class _Range> + ref_view(_Range&) -> ref_view<_Range>; + + template<class _Tp> + inline constexpr bool enable_borrowed_range<ref_view<_Tp>> = true; +} // namespace ranges + +#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS) && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES) + +_LIBCPP_END_NAMESPACE_STD + +#endif // _LIBCPP___RANGES_REF_VIEW_H diff --git a/contrib/libs/cxxsupp/libcxxmsvc/include/__ranges/rend.h b/contrib/libs/cxxsupp/libcxxmsvc/include/__ranges/rend.h new file mode 100644 index 0000000000..4f1597e073 --- /dev/null +++ b/contrib/libs/cxxsupp/libcxxmsvc/include/__ranges/rend.h @@ -0,0 +1,134 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// 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 _LIBCPP___RANGES_REND_H +#define _LIBCPP___RANGES_REND_H + +#include <__concepts/class_or_enum.h> +#include <__concepts/same_as.h> +#include <__config> +#include <__iterator/concepts.h> +#include <__iterator/readable_traits.h> +#include <__iterator/reverse_iterator.h> +#include <__ranges/access.h> +#include <__ranges/rbegin.h> +#include <__utility/auto_cast.h> +#include <type_traits> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +# pragma GCC system_header +#endif + +_LIBCPP_BEGIN_NAMESPACE_STD + +#if !defined(_LIBCPP_HAS_NO_CONCEPTS) && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES) + +// [range.access.rend] + +namespace ranges { +namespace __rend { +template <class _Tp> +concept __member_rend = + __can_borrow<_Tp> && + __workaround_52970<_Tp> && + requires(_Tp&& __t) { + ranges::rbegin(__t); + { _LIBCPP_AUTO_CAST(__t.rend()) } -> sentinel_for<decltype(ranges::rbegin(__t))>; + }; + +void rend(auto&) = delete; +void rend(const auto&) = delete; + +template <class _Tp> +concept __unqualified_rend = + !__member_rend<_Tp> && + __can_borrow<_Tp> && + __class_or_enum<remove_cvref_t<_Tp>> && + requires(_Tp&& __t) { + ranges::rbegin(__t); + { _LIBCPP_AUTO_CAST(rend(__t)) } -> sentinel_for<decltype(ranges::rbegin(__t))>; + }; + +template <class _Tp> +concept __can_reverse = + __can_borrow<_Tp> && + !__member_rend<_Tp> && + !__unqualified_rend<_Tp> && + requires(_Tp&& __t) { + { ranges::begin(__t) } -> same_as<decltype(ranges::end(__t))>; + { ranges::begin(__t) } -> bidirectional_iterator; + }; + +class __fn { +public: + template <class _Tp> + requires __member_rend<_Tp> + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr auto operator()(_Tp&& __t) const + noexcept(noexcept(_LIBCPP_AUTO_CAST(__t.rend()))) + { + return _LIBCPP_AUTO_CAST(__t.rend()); + } + + template <class _Tp> + requires __unqualified_rend<_Tp> + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr auto operator()(_Tp&& __t) const + noexcept(noexcept(_LIBCPP_AUTO_CAST(rend(__t)))) + { + return _LIBCPP_AUTO_CAST(rend(__t)); + } + + template <class _Tp> + requires __can_reverse<_Tp> + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr auto operator()(_Tp&& __t) const + noexcept(noexcept(ranges::begin(__t))) + { + return std::make_reverse_iterator(ranges::begin(__t)); + } + + void operator()(auto&&) const = delete; +}; +} // namespace __rend + +inline namespace __cpo { + inline constexpr auto rend = __rend::__fn{}; +} // namespace __cpo +} // namespace ranges + +// [range.access.crend] + +namespace ranges { +namespace __crend { +struct __fn { + template <class _Tp> + requires is_lvalue_reference_v<_Tp&&> + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI + constexpr auto operator()(_Tp&& __t) const + noexcept(noexcept(ranges::rend(static_cast<const remove_reference_t<_Tp>&>(__t)))) + -> decltype( ranges::rend(static_cast<const remove_reference_t<_Tp>&>(__t))) + { return ranges::rend(static_cast<const remove_reference_t<_Tp>&>(__t)); } + + template <class _Tp> + requires is_rvalue_reference_v<_Tp&&> + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI + constexpr auto operator()(_Tp&& __t) const + noexcept(noexcept(ranges::rend(static_cast<const _Tp&&>(__t)))) + -> decltype( ranges::rend(static_cast<const _Tp&&>(__t))) + { return ranges::rend(static_cast<const _Tp&&>(__t)); } +}; +} // namespace __crend + +inline namespace __cpo { + inline constexpr auto crend = __crend::__fn{}; +} // namespace __cpo +} // namespace ranges + +#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS) && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES) + +_LIBCPP_END_NAMESPACE_STD + +#endif // _LIBCPP___RANGES_REND_H diff --git a/contrib/libs/cxxsupp/libcxxmsvc/include/__ranges/reverse_view.h b/contrib/libs/cxxsupp/libcxxmsvc/include/__ranges/reverse_view.h new file mode 100644 index 0000000000..c3ab6261f0 --- /dev/null +++ b/contrib/libs/cxxsupp/libcxxmsvc/include/__ranges/reverse_view.h @@ -0,0 +1,190 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// 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 _LIBCPP___RANGES_REVERSE_VIEW_H +#define _LIBCPP___RANGES_REVERSE_VIEW_H + +#include <__concepts/constructible.h> +#include <__config> +#include <__iterator/concepts.h> +#include <__iterator/next.h> +#include <__iterator/reverse_iterator.h> +#include <__ranges/access.h> +#include <__ranges/all.h> +#include <__ranges/concepts.h> +#include <__ranges/enable_borrowed_range.h> +#include <__ranges/non_propagating_cache.h> +#include <__ranges/range_adaptor.h> +#include <__ranges/size.h> +#include <__ranges/subrange.h> +#include <__ranges/view_interface.h> +#include <__utility/forward.h> +#include <__utility/move.h> +#include <type_traits> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +# pragma GCC system_header +#endif + +_LIBCPP_BEGIN_NAMESPACE_STD + +#if !defined(_LIBCPP_HAS_NO_CONCEPTS) && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES) + +namespace ranges { + template<view _View> + requires bidirectional_range<_View> + class reverse_view : public view_interface<reverse_view<_View>> { + // We cache begin() whenever ranges::next is not guaranteed O(1) to provide an + // amortized O(1) begin() method. + static constexpr bool _UseCache = !random_access_range<_View> && !common_range<_View>; + using _Cache = _If<_UseCache, __non_propagating_cache<reverse_iterator<iterator_t<_View>>>, __empty_cache>; + _LIBCPP_NO_UNIQUE_ADDRESS _Cache __cached_begin_ = _Cache(); + _LIBCPP_NO_UNIQUE_ADDRESS _View __base_ = _View(); + + public: + _LIBCPP_HIDE_FROM_ABI + reverse_view() requires default_initializable<_View> = default; + + _LIBCPP_HIDE_FROM_ABI + constexpr explicit reverse_view(_View __view) : __base_(std::move(__view)) {} + + _LIBCPP_HIDE_FROM_ABI + constexpr _View base() const& requires copy_constructible<_View> { return __base_; } + + _LIBCPP_HIDE_FROM_ABI + constexpr _View base() && { return std::move(__base_); } + + _LIBCPP_HIDE_FROM_ABI + constexpr reverse_iterator<iterator_t<_View>> begin() { + if constexpr (_UseCache) + if (__cached_begin_.__has_value()) + return *__cached_begin_; + + auto __tmp = std::make_reverse_iterator(ranges::next(ranges::begin(__base_), ranges::end(__base_))); + if constexpr (_UseCache) + __cached_begin_.__emplace(__tmp); + return __tmp; + } + + _LIBCPP_HIDE_FROM_ABI + constexpr reverse_iterator<iterator_t<_View>> begin() requires common_range<_View> { + return std::make_reverse_iterator(ranges::end(__base_)); + } + + _LIBCPP_HIDE_FROM_ABI + constexpr auto begin() const requires common_range<const _View> { + return std::make_reverse_iterator(ranges::end(__base_)); + } + + _LIBCPP_HIDE_FROM_ABI + constexpr reverse_iterator<iterator_t<_View>> end() { + return std::make_reverse_iterator(ranges::begin(__base_)); + } + + _LIBCPP_HIDE_FROM_ABI + constexpr auto end() const requires common_range<const _View> { + return std::make_reverse_iterator(ranges::begin(__base_)); + } + + _LIBCPP_HIDE_FROM_ABI + constexpr auto size() requires sized_range<_View> { + return ranges::size(__base_); + } + + _LIBCPP_HIDE_FROM_ABI + constexpr auto size() const requires sized_range<const _View> { + return ranges::size(__base_); + } + }; + + template<class _Range> + reverse_view(_Range&&) -> reverse_view<views::all_t<_Range>>; + + template<class _Tp> + inline constexpr bool enable_borrowed_range<reverse_view<_Tp>> = enable_borrowed_range<_Tp>; + + namespace views { + namespace __reverse { + template<class _Tp> + constexpr bool __is_reverse_view = false; + + template<class _Tp> + constexpr bool __is_reverse_view<reverse_view<_Tp>> = true; + + template<class _Tp> + constexpr bool __is_sized_reverse_subrange = false; + + template<class _Iter> + constexpr bool __is_sized_reverse_subrange<subrange<reverse_iterator<_Iter>, reverse_iterator<_Iter>, subrange_kind::sized>> = true; + + template<class _Tp> + constexpr bool __is_unsized_reverse_subrange = false; + + template<class _Iter, subrange_kind _Kind> + constexpr bool __is_unsized_reverse_subrange<subrange<reverse_iterator<_Iter>, reverse_iterator<_Iter>, _Kind>> = _Kind == subrange_kind::unsized; + + template<class _Tp> + struct __unwrapped_reverse_subrange { + using type = void; // avoid SFINAE-ing out the overload below -- let the concept requirements do it for better diagnostics + }; + + template<class _Iter, subrange_kind _Kind> + struct __unwrapped_reverse_subrange<subrange<reverse_iterator<_Iter>, reverse_iterator<_Iter>, _Kind>> { + using type = subrange<_Iter, _Iter, _Kind>; + }; + + struct __fn : __range_adaptor_closure<__fn> { + template<class _Range> + requires __is_reverse_view<remove_cvref_t<_Range>> + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI + constexpr auto operator()(_Range&& __range) const + noexcept(noexcept(std::forward<_Range>(__range).base())) + -> decltype( std::forward<_Range>(__range).base()) + { return std::forward<_Range>(__range).base(); } + + template<class _Range, + class _UnwrappedSubrange = typename __unwrapped_reverse_subrange<remove_cvref_t<_Range>>::type> + requires __is_sized_reverse_subrange<remove_cvref_t<_Range>> + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI + constexpr auto operator()(_Range&& __range) const + noexcept(noexcept(_UnwrappedSubrange(__range.end().base(), __range.begin().base(), __range.size()))) + -> decltype( _UnwrappedSubrange(__range.end().base(), __range.begin().base(), __range.size())) + { return _UnwrappedSubrange(__range.end().base(), __range.begin().base(), __range.size()); } + + template<class _Range, + class _UnwrappedSubrange = typename __unwrapped_reverse_subrange<remove_cvref_t<_Range>>::type> + requires __is_unsized_reverse_subrange<remove_cvref_t<_Range>> + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI + constexpr auto operator()(_Range&& __range) const + noexcept(noexcept(_UnwrappedSubrange(__range.end().base(), __range.begin().base()))) + -> decltype( _UnwrappedSubrange(__range.end().base(), __range.begin().base())) + { return _UnwrappedSubrange(__range.end().base(), __range.begin().base()); } + + template<class _Range> + requires (!__is_reverse_view<remove_cvref_t<_Range>> && + !__is_sized_reverse_subrange<remove_cvref_t<_Range>> && + !__is_unsized_reverse_subrange<remove_cvref_t<_Range>>) + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI + constexpr auto operator()(_Range&& __range) const + noexcept(noexcept(reverse_view{std::forward<_Range>(__range)})) + -> decltype( reverse_view{std::forward<_Range>(__range)}) + { return reverse_view{std::forward<_Range>(__range)}; } + }; + } // namespace __reverse + + inline namespace __cpo { + inline constexpr auto reverse = __reverse::__fn{}; + } // namespace __cpo + } // namespace views +} // namespace ranges + +#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS) && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES) + +_LIBCPP_END_NAMESPACE_STD + +#endif // _LIBCPP___RANGES_REVERSE_VIEW_H diff --git a/contrib/libs/cxxsupp/libcxxmsvc/include/__ranges/single_view.h b/contrib/libs/cxxsupp/libcxxmsvc/include/__ranges/single_view.h new file mode 100644 index 0000000000..e0fd4849f4 --- /dev/null +++ b/contrib/libs/cxxsupp/libcxxmsvc/include/__ranges/single_view.h @@ -0,0 +1,81 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// 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 _LIBCPP___RANGES_SINGLE_VIEW_H +#define _LIBCPP___RANGES_SINGLE_VIEW_H + +#include <__config> +#include <__ranges/copyable_box.h> +#include <__ranges/view_interface.h> +#include <__utility/forward.h> +#include <__utility/in_place.h> +#include <__utility/move.h> +#include <concepts> +#include <type_traits> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +# pragma GCC system_header +#endif + +_LIBCPP_BEGIN_NAMESPACE_STD + +#if !defined(_LIBCPP_HAS_NO_CONCEPTS) && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES) + +namespace ranges { + template<copy_constructible _Tp> + requires is_object_v<_Tp> + class single_view : public view_interface<single_view<_Tp>> { + __copyable_box<_Tp> __value_; + + public: + _LIBCPP_HIDE_FROM_ABI + single_view() requires default_initializable<_Tp> = default; + + _LIBCPP_HIDE_FROM_ABI + constexpr explicit single_view(const _Tp& __t) : __value_(in_place, __t) {} + + _LIBCPP_HIDE_FROM_ABI + constexpr explicit single_view(_Tp&& __t) : __value_(in_place, std::move(__t)) {} + + template<class... _Args> + requires constructible_from<_Tp, _Args...> + _LIBCPP_HIDE_FROM_ABI + constexpr explicit single_view(in_place_t, _Args&&... __args) + : __value_{in_place, std::forward<_Args>(__args)...} {} + + _LIBCPP_HIDE_FROM_ABI + constexpr _Tp* begin() noexcept { return data(); } + + _LIBCPP_HIDE_FROM_ABI + constexpr const _Tp* begin() const noexcept { return data(); } + + _LIBCPP_HIDE_FROM_ABI + constexpr _Tp* end() noexcept { return data() + 1; } + + _LIBCPP_HIDE_FROM_ABI + constexpr const _Tp* end() const noexcept { return data() + 1; } + + _LIBCPP_HIDE_FROM_ABI + static constexpr size_t size() noexcept { return 1; } + + _LIBCPP_HIDE_FROM_ABI + constexpr _Tp* data() noexcept { return __value_.operator->(); } + + _LIBCPP_HIDE_FROM_ABI + constexpr const _Tp* data() const noexcept { return __value_.operator->(); } + }; + + template<class _Tp> + single_view(_Tp) -> single_view<_Tp>; +} // namespace ranges + +#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS) && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES) + +_LIBCPP_END_NAMESPACE_STD + +#endif // _LIBCPP___RANGES_SINGLE_VIEW_H diff --git a/contrib/libs/cxxsupp/libcxxmsvc/include/__ranges/subrange.h b/contrib/libs/cxxsupp/libcxxmsvc/include/__ranges/subrange.h new file mode 100644 index 0000000000..c54f7710fc --- /dev/null +++ b/contrib/libs/cxxsupp/libcxxmsvc/include/__ranges/subrange.h @@ -0,0 +1,289 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// 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 _LIBCPP___RANGES_SUBRANGE_H +#define _LIBCPP___RANGES_SUBRANGE_H + +#include <__assert> +#include <__concepts/constructible.h> +#include <__concepts/convertible_to.h> +#include <__concepts/copyable.h> +#include <__concepts/derived_from.h> +#include <__concepts/different_from.h> +#include <__config> +#include <__iterator/advance.h> +#include <__iterator/concepts.h> +#include <__iterator/incrementable_traits.h> +#include <__iterator/iterator_traits.h> +#include <__ranges/access.h> +#include <__ranges/concepts.h> +#include <__ranges/dangling.h> +#include <__ranges/enable_borrowed_range.h> +#include <__ranges/size.h> +#include <__ranges/view_interface.h> +#include <__tuple> +#include <__utility/move.h> +#include <type_traits> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +# pragma GCC system_header +#endif + +_LIBCPP_BEGIN_NAMESPACE_STD + +#if !defined(_LIBCPP_HAS_NO_CONCEPTS) && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES) + +namespace ranges { + template<class _From, class _To> + concept __uses_nonqualification_pointer_conversion = + is_pointer_v<_From> && is_pointer_v<_To> && + !convertible_to<remove_pointer_t<_From>(*)[], remove_pointer_t<_To>(*)[]>; + + template<class _From, class _To> + concept __convertible_to_non_slicing = + convertible_to<_From, _To> && + !__uses_nonqualification_pointer_conversion<decay_t<_From>, decay_t<_To>>; + + template<class _Tp> + concept __pair_like = + !is_reference_v<_Tp> && requires(_Tp __t) { + typename tuple_size<_Tp>::type; // Ensures `tuple_size<T>` is complete. + requires derived_from<tuple_size<_Tp>, integral_constant<size_t, 2>>; + typename tuple_element_t<0, remove_const_t<_Tp>>; + typename tuple_element_t<1, remove_const_t<_Tp>>; + { std::get<0>(__t) } -> convertible_to<const tuple_element_t<0, _Tp>&>; + { std::get<1>(__t) } -> convertible_to<const tuple_element_t<1, _Tp>&>; + }; + + template<class _Pair, class _Iter, class _Sent> + concept __pair_like_convertible_from = + !range<_Pair> && __pair_like<_Pair> && + constructible_from<_Pair, _Iter, _Sent> && + __convertible_to_non_slicing<_Iter, tuple_element_t<0, _Pair>> && + convertible_to<_Sent, tuple_element_t<1, _Pair>>; + + enum class _LIBCPP_ENUM_VIS subrange_kind : bool { unsized, sized }; + + template<input_or_output_iterator _Iter, sentinel_for<_Iter> _Sent = _Iter, + subrange_kind _Kind = sized_sentinel_for<_Sent, _Iter> + ? subrange_kind::sized + : subrange_kind::unsized> + requires (_Kind == subrange_kind::sized || !sized_sentinel_for<_Sent, _Iter>) + class _LIBCPP_TEMPLATE_VIS subrange + : public view_interface<subrange<_Iter, _Sent, _Kind>> + { + private: + static constexpr bool _StoreSize = (_Kind == subrange_kind::sized && !sized_sentinel_for<_Sent, _Iter>); + static constexpr bool _MustProvideSizeAtConstruction = !_StoreSize; // just to improve compiler diagnostics + struct _Empty { constexpr _Empty(auto) noexcept { } }; + using _Size = conditional_t<_StoreSize, make_unsigned_t<iter_difference_t<_Iter>>, _Empty>; + _LIBCPP_NO_UNIQUE_ADDRESS _Iter __begin_ = _Iter(); + _LIBCPP_NO_UNIQUE_ADDRESS _Sent __end_ = _Sent(); + _LIBCPP_NO_UNIQUE_ADDRESS _Size __size_ = 0; + + public: + _LIBCPP_HIDE_FROM_ABI + subrange() requires default_initializable<_Iter> = default; + + _LIBCPP_HIDE_FROM_ABI + constexpr subrange(__convertible_to_non_slicing<_Iter> auto __iter, _Sent __sent) + requires _MustProvideSizeAtConstruction + : __begin_(std::move(__iter)), __end_(std::move(__sent)) + { } + + _LIBCPP_HIDE_FROM_ABI + constexpr subrange(__convertible_to_non_slicing<_Iter> auto __iter, _Sent __sent, + make_unsigned_t<iter_difference_t<_Iter>> __n) + requires (_Kind == subrange_kind::sized) + : __begin_(std::move(__iter)), __end_(std::move(__sent)), __size_(__n) + { + if constexpr (sized_sentinel_for<_Sent, _Iter>) + _LIBCPP_ASSERT((__end_ - __begin_) == static_cast<iter_difference_t<_Iter>>(__n), + "std::ranges::subrange was passed an invalid size hint"); + } + + template<__different_from<subrange> _Range> + requires borrowed_range<_Range> && + __convertible_to_non_slicing<iterator_t<_Range>, _Iter> && + convertible_to<sentinel_t<_Range>, _Sent> + _LIBCPP_HIDE_FROM_ABI + constexpr subrange(_Range&& __range) + requires (!_StoreSize) + : subrange(ranges::begin(__range), ranges::end(__range)) + { } + + template<__different_from<subrange> _Range> + requires borrowed_range<_Range> && + __convertible_to_non_slicing<iterator_t<_Range>, _Iter> && + convertible_to<sentinel_t<_Range>, _Sent> + _LIBCPP_HIDE_FROM_ABI + constexpr subrange(_Range&& __range) + requires _StoreSize && sized_range<_Range> + : subrange(__range, ranges::size(__range)) + { } + + template<borrowed_range _Range> + requires __convertible_to_non_slicing<iterator_t<_Range>, _Iter> && + convertible_to<sentinel_t<_Range>, _Sent> + _LIBCPP_HIDE_FROM_ABI + constexpr subrange(_Range&& __range, make_unsigned_t<iter_difference_t<_Iter>> __n) + requires (_Kind == subrange_kind::sized) + : subrange(ranges::begin(__range), ranges::end(__range), __n) + { } + + template<__different_from<subrange> _Pair> + requires __pair_like_convertible_from<_Pair, const _Iter&, const _Sent&> + _LIBCPP_HIDE_FROM_ABI + constexpr operator _Pair() const { + return _Pair(__begin_, __end_); + } + + _LIBCPP_HIDE_FROM_ABI + constexpr _Iter begin() const requires copyable<_Iter> { + return __begin_; + } + + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr _Iter begin() requires (!copyable<_Iter>) { + return std::move(__begin_); + } + + _LIBCPP_HIDE_FROM_ABI + constexpr _Sent end() const { + return __end_; + } + + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr bool empty() const { + return __begin_ == __end_; + } + + _LIBCPP_HIDE_FROM_ABI + constexpr make_unsigned_t<iter_difference_t<_Iter>> size() const + requires (_Kind == subrange_kind::sized) + { + if constexpr (_StoreSize) + return __size_; + else + return std::__to_unsigned_like(__end_ - __begin_); + } + + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr subrange next(iter_difference_t<_Iter> __n = 1) const& + requires forward_iterator<_Iter> + { + auto __tmp = *this; + __tmp.advance(__n); + return __tmp; + } + + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr subrange next(iter_difference_t<_Iter> __n = 1) && { + advance(__n); + return std::move(*this); + } + + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr subrange prev(iter_difference_t<_Iter> __n = 1) const + requires bidirectional_iterator<_Iter> + { + auto __tmp = *this; + __tmp.advance(-__n); + return __tmp; + } + + _LIBCPP_HIDE_FROM_ABI + constexpr subrange& advance(iter_difference_t<_Iter> __n) { + if constexpr (bidirectional_iterator<_Iter>) { + if (__n < 0) { + ranges::advance(__begin_, __n); + if constexpr (_StoreSize) + __size_ += std::__to_unsigned_like(-__n); + return *this; + } + } + + auto __d = __n - ranges::advance(__begin_, __n, __end_); + if constexpr (_StoreSize) + __size_ -= std::__to_unsigned_like(__d); + return *this; + } + }; + + template<input_or_output_iterator _Iter, sentinel_for<_Iter> _Sent> + subrange(_Iter, _Sent) -> subrange<_Iter, _Sent>; + + template<input_or_output_iterator _Iter, sentinel_for<_Iter> _Sent> + subrange(_Iter, _Sent, make_unsigned_t<iter_difference_t<_Iter>>) + -> subrange<_Iter, _Sent, subrange_kind::sized>; + + template<borrowed_range _Range> + subrange(_Range&&) -> subrange<iterator_t<_Range>, sentinel_t<_Range>, + (sized_range<_Range> || sized_sentinel_for<sentinel_t<_Range>, iterator_t<_Range>>) + ? subrange_kind::sized : subrange_kind::unsized>; + + template<borrowed_range _Range> + subrange(_Range&&, make_unsigned_t<range_difference_t<_Range>>) + -> subrange<iterator_t<_Range>, sentinel_t<_Range>, subrange_kind::sized>; + + template<size_t _Index, class _Iter, class _Sent, subrange_kind _Kind> + requires ((_Index == 0 && copyable<_Iter>) || _Index == 1) + _LIBCPP_HIDE_FROM_ABI + constexpr auto get(const subrange<_Iter, _Sent, _Kind>& __subrange) { + if constexpr (_Index == 0) + return __subrange.begin(); + else + return __subrange.end(); + } + + template<size_t _Index, class _Iter, class _Sent, subrange_kind _Kind> + requires (_Index < 2) + _LIBCPP_HIDE_FROM_ABI + constexpr auto get(subrange<_Iter, _Sent, _Kind>&& __subrange) { + if constexpr (_Index == 0) + return __subrange.begin(); + else + return __subrange.end(); + } + + template<class _Ip, class _Sp, subrange_kind _Kp> + inline constexpr bool enable_borrowed_range<subrange<_Ip, _Sp, _Kp>> = true; + + template<range _Rp> + using borrowed_subrange_t = _If<borrowed_range<_Rp>, subrange<iterator_t<_Rp>>, dangling>; +} // namespace ranges + +// [range.subrange.general] + +using ranges::get; + +// [ranges.syn] + +template<class _Ip, class _Sp, ranges::subrange_kind _Kp> +struct tuple_size<ranges::subrange<_Ip, _Sp, _Kp>> : integral_constant<size_t, 2> {}; + +template<class _Ip, class _Sp, ranges::subrange_kind _Kp> +struct tuple_element<0, ranges::subrange<_Ip, _Sp, _Kp>> { + using type = _Ip; +}; + +template<class _Ip, class _Sp, ranges::subrange_kind _Kp> +struct tuple_element<1, ranges::subrange<_Ip, _Sp, _Kp>> { + using type = _Sp; +}; + +template<class _Ip, class _Sp, ranges::subrange_kind _Kp> +struct tuple_element<0, const ranges::subrange<_Ip, _Sp, _Kp>> { + using type = _Ip; +}; + +template<class _Ip, class _Sp, ranges::subrange_kind _Kp> +struct tuple_element<1, const ranges::subrange<_Ip, _Sp, _Kp>> { + using type = _Sp; +}; + +#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS) && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES) + +_LIBCPP_END_NAMESPACE_STD + +#endif // _LIBCPP___RANGES_SUBRANGE_H diff --git a/contrib/libs/cxxsupp/libcxxmsvc/include/__ranges/take_view.h b/contrib/libs/cxxsupp/libcxxmsvc/include/__ranges/take_view.h new file mode 100644 index 0000000000..b5f194f9a0 --- /dev/null +++ b/contrib/libs/cxxsupp/libcxxmsvc/include/__ranges/take_view.h @@ -0,0 +1,185 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// 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 _LIBCPP___RANGES_TAKE_VIEW_H +#define _LIBCPP___RANGES_TAKE_VIEW_H + +#include <__algorithm/min.h> +#include <__config> +#include <__iterator/concepts.h> +#include <__iterator/counted_iterator.h> +#include <__iterator/default_sentinel.h> +#include <__iterator/iterator_traits.h> +#include <__ranges/access.h> +#include <__ranges/all.h> +#include <__ranges/concepts.h> +#include <__ranges/enable_borrowed_range.h> +#include <__ranges/size.h> +#include <__ranges/view_interface.h> +#include <__utility/move.h> +#include <concepts> +#include <type_traits> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +# pragma GCC system_header +#endif + +_LIBCPP_PUSH_MACROS +#include <__undef_macros> + +_LIBCPP_BEGIN_NAMESPACE_STD + +#if !defined(_LIBCPP_HAS_NO_CONCEPTS) && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES) + +namespace ranges { + template<view _View> + class take_view : public view_interface<take_view<_View>> { + _LIBCPP_NO_UNIQUE_ADDRESS _View __base_ = _View(); + range_difference_t<_View> __count_ = 0; + + template<bool> class __sentinel; + + public: + _LIBCPP_HIDE_FROM_ABI + take_view() requires default_initializable<_View> = default; + + _LIBCPP_HIDE_FROM_ABI + constexpr take_view(_View __base, range_difference_t<_View> __count) + : __base_(std::move(__base)), __count_(__count) {} + + _LIBCPP_HIDE_FROM_ABI + constexpr _View base() const& requires copy_constructible<_View> { return __base_; } + + _LIBCPP_HIDE_FROM_ABI + constexpr _View base() && { return std::move(__base_); } + + _LIBCPP_HIDE_FROM_ABI + constexpr auto begin() requires (!__simple_view<_View>) { + if constexpr (sized_range<_View>) { + if constexpr (random_access_range<_View>) { + return ranges::begin(__base_); + } else { + using _DifferenceT = range_difference_t<_View>; + auto __size = size(); + return counted_iterator(ranges::begin(__base_), static_cast<_DifferenceT>(__size)); + } + } else { + return counted_iterator(ranges::begin(__base_), __count_); + } + } + + _LIBCPP_HIDE_FROM_ABI + constexpr auto begin() const requires range<const _View> { + if constexpr (sized_range<const _View>) { + if constexpr (random_access_range<const _View>) { + return ranges::begin(__base_); + } else { + using _DifferenceT = range_difference_t<const _View>; + auto __size = size(); + return counted_iterator(ranges::begin(__base_), static_cast<_DifferenceT>(__size)); + } + } else { + return counted_iterator(ranges::begin(__base_), __count_); + } + } + + _LIBCPP_HIDE_FROM_ABI + constexpr auto end() requires (!__simple_view<_View>) { + if constexpr (sized_range<_View>) { + if constexpr (random_access_range<_View>) { + return ranges::begin(__base_) + size(); + } else { + return default_sentinel; + } + } else { + return __sentinel<false>{ranges::end(__base_)}; + } + } + + _LIBCPP_HIDE_FROM_ABI + constexpr auto end() const requires range<const _View> { + if constexpr (sized_range<const _View>) { + if constexpr (random_access_range<const _View>) { + return ranges::begin(__base_) + size(); + } else { + return default_sentinel; + } + } else { + return __sentinel<true>{ranges::end(__base_)}; + } + } + + + _LIBCPP_HIDE_FROM_ABI + constexpr auto size() requires sized_range<_View> { + auto __n = ranges::size(__base_); + // TODO: use ranges::min here. + return std::min(__n, static_cast<decltype(__n)>(__count_)); + } + + _LIBCPP_HIDE_FROM_ABI + constexpr auto size() const requires sized_range<const _View> { + auto __n = ranges::size(__base_); + // TODO: use ranges::min here. + return std::min(__n, static_cast<decltype(__n)>(__count_)); + } + }; + + template<view _View> + template<bool _Const> + class take_view<_View>::__sentinel { + using _Base = __maybe_const<_Const, _View>; + template<bool _OtherConst> + using _Iter = counted_iterator<iterator_t<__maybe_const<_OtherConst, _View>>>; + _LIBCPP_NO_UNIQUE_ADDRESS sentinel_t<_Base> __end_ = sentinel_t<_Base>(); + + template<bool> + friend class take_view<_View>::__sentinel; + +public: + _LIBCPP_HIDE_FROM_ABI + __sentinel() = default; + + _LIBCPP_HIDE_FROM_ABI + constexpr explicit __sentinel(sentinel_t<_Base> __end) : __end_(std::move(__end)) {} + + _LIBCPP_HIDE_FROM_ABI + constexpr __sentinel(__sentinel<!_Const> __s) + requires _Const && convertible_to<sentinel_t<_View>, sentinel_t<_Base>> + : __end_(std::move(__s.__end_)) {} + + _LIBCPP_HIDE_FROM_ABI + constexpr sentinel_t<_Base> base() const { return __end_; } + + _LIBCPP_HIDE_FROM_ABI + friend constexpr bool operator==(const _Iter<_Const>& __lhs, const __sentinel& __rhs) { + return __lhs.count() == 0 || __lhs.base() == __rhs.__end_; + } + + template<bool _OtherConst = !_Const> + requires sentinel_for<sentinel_t<_Base>, iterator_t<__maybe_const<_OtherConst, _View>>> + _LIBCPP_HIDE_FROM_ABI + friend constexpr bool operator==(const _Iter<_Const>& __lhs, const __sentinel& __rhs) { + return __lhs.count() == 0 || __lhs.base() == __rhs.__end_; + } + }; + + template<class _Range> + take_view(_Range&&, range_difference_t<_Range>) -> take_view<views::all_t<_Range>>; + + template<class _Tp> + inline constexpr bool enable_borrowed_range<take_view<_Tp>> = enable_borrowed_range<_Tp>; +} // namespace ranges + +#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS) && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES) + +_LIBCPP_END_NAMESPACE_STD + +_LIBCPP_POP_MACROS + +#endif // _LIBCPP___RANGES_TAKE_VIEW_H diff --git a/contrib/libs/cxxsupp/libcxxmsvc/include/__ranges/transform_view.h b/contrib/libs/cxxsupp/libcxxmsvc/include/__ranges/transform_view.h new file mode 100644 index 0000000000..4cc582faeb --- /dev/null +++ b/contrib/libs/cxxsupp/libcxxmsvc/include/__ranges/transform_view.h @@ -0,0 +1,440 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// 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 _LIBCPP___RANGES_TRANSFORM_VIEW_H +#define _LIBCPP___RANGES_TRANSFORM_VIEW_H + +#include <__compare/three_way_comparable.h> +#include <__concepts/constructible.h> +#include <__concepts/convertible_to.h> +#include <__concepts/copyable.h> +#include <__concepts/derived_from.h> +#include <__concepts/equality_comparable.h> +#include <__concepts/invocable.h> +#include <__config> +#include <__functional/bind_back.h> +#include <__functional/invoke.h> +#include <__iterator/concepts.h> +#include <__iterator/iterator_traits.h> +#include <__memory/addressof.h> +#include <__ranges/access.h> +#include <__ranges/all.h> +#include <__ranges/concepts.h> +#include <__ranges/copyable_box.h> +#include <__ranges/empty.h> +#include <__ranges/range_adaptor.h> +#include <__ranges/size.h> +#include <__ranges/view_interface.h> +#include <__utility/forward.h> +#include <__utility/in_place.h> +#include <__utility/move.h> +#include <type_traits> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +# pragma GCC system_header +#endif + +_LIBCPP_BEGIN_NAMESPACE_STD + +#if !defined(_LIBCPP_HAS_NO_CONCEPTS) && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES) + +namespace ranges { + +template<class _Fn, class _View> +concept __regular_invocable_with_range_ref = + regular_invocable<_Fn, range_reference_t<_View>>; + +template<class _View, class _Fn> +concept __transform_view_constraints = + view<_View> && is_object_v<_Fn> && + regular_invocable<_Fn&, range_reference_t<_View>> && + __can_reference<invoke_result_t<_Fn&, range_reference_t<_View>>>; + +template<input_range _View, copy_constructible _Fn> + requires __transform_view_constraints<_View, _Fn> +class transform_view : public view_interface<transform_view<_View, _Fn>> { + template<bool> class __iterator; + template<bool> class __sentinel; + + _LIBCPP_NO_UNIQUE_ADDRESS __copyable_box<_Fn> __func_; + _LIBCPP_NO_UNIQUE_ADDRESS _View __base_ = _View(); + +public: + _LIBCPP_HIDE_FROM_ABI + transform_view() + requires default_initializable<_View> && default_initializable<_Fn> = default; + + _LIBCPP_HIDE_FROM_ABI + constexpr transform_view(_View __base, _Fn __func) + : __func_(std::in_place, std::move(__func)), __base_(std::move(__base)) {} + + _LIBCPP_HIDE_FROM_ABI + constexpr _View base() const& requires copy_constructible<_View> { return __base_; } + _LIBCPP_HIDE_FROM_ABI + constexpr _View base() && { return std::move(__base_); } + + _LIBCPP_HIDE_FROM_ABI + constexpr __iterator<false> begin() { + return __iterator<false>{*this, ranges::begin(__base_)}; + } + _LIBCPP_HIDE_FROM_ABI + constexpr __iterator<true> begin() const + requires range<const _View> && + __regular_invocable_with_range_ref<const _Fn&, const _View> + { + return __iterator<true>(*this, ranges::begin(__base_)); + } + + _LIBCPP_HIDE_FROM_ABI + constexpr __sentinel<false> end() { + return __sentinel<false>(ranges::end(__base_)); + } + _LIBCPP_HIDE_FROM_ABI + constexpr __iterator<false> end() + requires common_range<_View> + { + return __iterator<false>(*this, ranges::end(__base_)); + } + _LIBCPP_HIDE_FROM_ABI + constexpr __sentinel<true> end() const + requires range<const _View> && + __regular_invocable_with_range_ref<const _Fn&, const _View> + { + return __sentinel<true>(ranges::end(__base_)); + } + _LIBCPP_HIDE_FROM_ABI + constexpr __iterator<true> end() const + requires common_range<const _View> && + __regular_invocable_with_range_ref<const _Fn&, const _View> + { + return __iterator<true>(*this, ranges::end(__base_)); + } + + _LIBCPP_HIDE_FROM_ABI + constexpr auto size() requires sized_range<_View> { return ranges::size(__base_); } + _LIBCPP_HIDE_FROM_ABI + constexpr auto size() const requires sized_range<const _View> { return ranges::size(__base_); } +}; + +template<class _Range, class _Fn> +transform_view(_Range&&, _Fn) -> transform_view<views::all_t<_Range>, _Fn>; + +template<class _View> +struct __transform_view_iterator_concept { using type = input_iterator_tag; }; + +template<random_access_range _View> +struct __transform_view_iterator_concept<_View> { using type = random_access_iterator_tag; }; + +template<bidirectional_range _View> +struct __transform_view_iterator_concept<_View> { using type = bidirectional_iterator_tag; }; + +template<forward_range _View> +struct __transform_view_iterator_concept<_View> { using type = forward_iterator_tag; }; + +template<class, class> +struct __transform_view_iterator_category_base {}; + +template<forward_range _View, class _Fn> +struct __transform_view_iterator_category_base<_View, _Fn> { + using _Cat = typename iterator_traits<iterator_t<_View>>::iterator_category; + + using iterator_category = conditional_t< + is_lvalue_reference_v<invoke_result_t<_Fn&, range_reference_t<_View>>>, + conditional_t< + derived_from<_Cat, contiguous_iterator_tag>, + random_access_iterator_tag, + _Cat + >, + input_iterator_tag + >; +}; + +template<input_range _View, copy_constructible _Fn> + requires __transform_view_constraints<_View, _Fn> +template<bool _Const> +class transform_view<_View, _Fn>::__iterator + : public __transform_view_iterator_category_base<_View, _Fn> { + + using _Parent = __maybe_const<_Const, transform_view>; + using _Base = __maybe_const<_Const, _View>; + + _Parent *__parent_ = nullptr; + + template<bool> + friend class transform_view<_View, _Fn>::__iterator; + + template<bool> + friend class transform_view<_View, _Fn>::__sentinel; + +public: + iterator_t<_Base> __current_ = iterator_t<_Base>(); + + using iterator_concept = typename __transform_view_iterator_concept<_View>::type; + using value_type = remove_cvref_t<invoke_result_t<_Fn&, range_reference_t<_Base>>>; + using difference_type = range_difference_t<_Base>; + + _LIBCPP_HIDE_FROM_ABI + __iterator() requires default_initializable<iterator_t<_Base>> = default; + + _LIBCPP_HIDE_FROM_ABI + constexpr __iterator(_Parent& __parent, iterator_t<_Base> __current) + : __parent_(std::addressof(__parent)), __current_(std::move(__current)) {} + + // Note: `__i` should always be `__iterator<false>`, but directly using + // `__iterator<false>` is ill-formed when `_Const` is false + // (see http://wg21.link/class.copy.ctor#5). + _LIBCPP_HIDE_FROM_ABI + constexpr __iterator(__iterator<!_Const> __i) + requires _Const && convertible_to<iterator_t<_View>, iterator_t<_Base>> + : __parent_(__i.__parent_), __current_(std::move(__i.__current_)) {} + + _LIBCPP_HIDE_FROM_ABI + constexpr const iterator_t<_Base>& base() const& noexcept { + return __current_; + } + + _LIBCPP_HIDE_FROM_ABI + constexpr iterator_t<_Base> base() && { + return std::move(__current_); + } + + _LIBCPP_HIDE_FROM_ABI + constexpr decltype(auto) operator*() const + noexcept(noexcept(std::invoke(*__parent_->__func_, *__current_))) + { + return std::invoke(*__parent_->__func_, *__current_); + } + + _LIBCPP_HIDE_FROM_ABI + constexpr __iterator& operator++() { + ++__current_; + return *this; + } + + _LIBCPP_HIDE_FROM_ABI + constexpr void operator++(int) { ++__current_; } + + _LIBCPP_HIDE_FROM_ABI + constexpr __iterator operator++(int) + requires forward_range<_Base> + { + auto __tmp = *this; + ++*this; + return __tmp; + } + + _LIBCPP_HIDE_FROM_ABI + constexpr __iterator& operator--() + requires bidirectional_range<_Base> + { + --__current_; + return *this; + } + + _LIBCPP_HIDE_FROM_ABI + constexpr __iterator operator--(int) + requires bidirectional_range<_Base> + { + auto __tmp = *this; + --*this; + return __tmp; + } + + _LIBCPP_HIDE_FROM_ABI + constexpr __iterator& operator+=(difference_type __n) + requires random_access_range<_Base> + { + __current_ += __n; + return *this; + } + + _LIBCPP_HIDE_FROM_ABI + constexpr __iterator& operator-=(difference_type __n) + requires random_access_range<_Base> + { + __current_ -= __n; + return *this; + } + + _LIBCPP_HIDE_FROM_ABI + constexpr decltype(auto) operator[](difference_type __n) const + noexcept(noexcept(std::invoke(*__parent_->__func_, __current_[__n]))) + requires random_access_range<_Base> + { + return std::invoke(*__parent_->__func_, __current_[__n]); + } + + _LIBCPP_HIDE_FROM_ABI + friend constexpr bool operator==(const __iterator& __x, const __iterator& __y) + requires equality_comparable<iterator_t<_Base>> + { + return __x.__current_ == __y.__current_; + } + + _LIBCPP_HIDE_FROM_ABI + friend constexpr bool operator<(const __iterator& __x, const __iterator& __y) + requires random_access_range<_Base> + { + return __x.__current_ < __y.__current_; + } + + _LIBCPP_HIDE_FROM_ABI + friend constexpr bool operator>(const __iterator& __x, const __iterator& __y) + requires random_access_range<_Base> + { + return __x.__current_ > __y.__current_; + } + + _LIBCPP_HIDE_FROM_ABI + friend constexpr bool operator<=(const __iterator& __x, const __iterator& __y) + requires random_access_range<_Base> + { + return __x.__current_ <= __y.__current_; + } + + _LIBCPP_HIDE_FROM_ABI + friend constexpr bool operator>=(const __iterator& __x, const __iterator& __y) + requires random_access_range<_Base> + { + return __x.__current_ >= __y.__current_; + } + + _LIBCPP_HIDE_FROM_ABI + friend constexpr auto operator<=>(const __iterator& __x, const __iterator& __y) + requires random_access_range<_Base> && three_way_comparable<iterator_t<_Base>> + { + return __x.__current_ <=> __y.__current_; + } + + _LIBCPP_HIDE_FROM_ABI + friend constexpr __iterator operator+(__iterator __i, difference_type __n) + requires random_access_range<_Base> + { + return __iterator{*__i.__parent_, __i.__current_ + __n}; + } + + _LIBCPP_HIDE_FROM_ABI + friend constexpr __iterator operator+(difference_type __n, __iterator __i) + requires random_access_range<_Base> + { + return __iterator{*__i.__parent_, __i.__current_ + __n}; + } + + _LIBCPP_HIDE_FROM_ABI + friend constexpr __iterator operator-(__iterator __i, difference_type __n) + requires random_access_range<_Base> + { + return __iterator{*__i.__parent_, __i.__current_ - __n}; + } + + _LIBCPP_HIDE_FROM_ABI + friend constexpr difference_type operator-(const __iterator& __x, const __iterator& __y) + requires sized_sentinel_for<iterator_t<_Base>, iterator_t<_Base>> + { + return __x.__current_ - __y.__current_; + } + + _LIBCPP_HIDE_FROM_ABI + friend constexpr decltype(auto) iter_move(const __iterator& __i) + noexcept(noexcept(*__i)) + { + if constexpr (is_lvalue_reference_v<decltype(*__i)>) + return std::move(*__i); + else + return *__i; + } +}; + +template<input_range _View, copy_constructible _Fn> + requires __transform_view_constraints<_View, _Fn> +template<bool _Const> +class transform_view<_View, _Fn>::__sentinel { + using _Parent = __maybe_const<_Const, transform_view>; + using _Base = __maybe_const<_Const, _View>; + + sentinel_t<_Base> __end_ = sentinel_t<_Base>(); + + template<bool> + friend class transform_view<_View, _Fn>::__iterator; + + template<bool> + friend class transform_view<_View, _Fn>::__sentinel; + +public: + _LIBCPP_HIDE_FROM_ABI + __sentinel() = default; + + _LIBCPP_HIDE_FROM_ABI + constexpr explicit __sentinel(sentinel_t<_Base> __end) : __end_(__end) {} + + // Note: `__i` should always be `__sentinel<false>`, but directly using + // `__sentinel<false>` is ill-formed when `_Const` is false + // (see http://wg21.link/class.copy.ctor#5). + _LIBCPP_HIDE_FROM_ABI + constexpr __sentinel(__sentinel<!_Const> __i) + requires _Const && convertible_to<sentinel_t<_View>, sentinel_t<_Base>> + : __end_(std::move(__i.__end_)) {} + + _LIBCPP_HIDE_FROM_ABI + constexpr sentinel_t<_Base> base() const { return __end_; } + + template<bool _OtherConst> + requires sentinel_for<sentinel_t<_Base>, iterator_t<__maybe_const<_OtherConst, _View>>> + _LIBCPP_HIDE_FROM_ABI + friend constexpr bool operator==(const __iterator<_OtherConst>& __x, const __sentinel& __y) { + return __x.__current_ == __y.__end_; + } + + template<bool _OtherConst> + requires sized_sentinel_for<sentinel_t<_Base>, iterator_t<__maybe_const<_OtherConst, _View>>> + _LIBCPP_HIDE_FROM_ABI + friend constexpr range_difference_t<__maybe_const<_OtherConst, _View>> + operator-(const __iterator<_OtherConst>& __x, const __sentinel& __y) { + return __x.__current_ - __y.__end_; + } + + template<bool _OtherConst> + requires sized_sentinel_for<sentinel_t<_Base>, iterator_t<__maybe_const<_OtherConst, _View>>> + _LIBCPP_HIDE_FROM_ABI + friend constexpr range_difference_t<__maybe_const<_OtherConst, _View>> + operator-(const __sentinel& __x, const __iterator<_OtherConst>& __y) { + return __x.__end_ - __y.__current_; + } +}; + +namespace views { +namespace __transform { + struct __fn { + template<class _Range, class _Fn> + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI + constexpr auto operator()(_Range&& __range, _Fn&& __f) const + noexcept(noexcept(transform_view(std::forward<_Range>(__range), std::forward<_Fn>(__f)))) + -> decltype( transform_view(std::forward<_Range>(__range), std::forward<_Fn>(__f))) + { return transform_view(std::forward<_Range>(__range), std::forward<_Fn>(__f)); } + + template<class _Fn> + requires constructible_from<decay_t<_Fn>, _Fn> + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI + constexpr auto operator()(_Fn&& __f) const + noexcept(is_nothrow_constructible_v<decay_t<_Fn>, _Fn>) + { return __range_adaptor_closure_t(std::__bind_back(*this, std::forward<_Fn>(__f))); } + }; +} // namespace __transform + +inline namespace __cpo { + inline constexpr auto transform = __transform::__fn{}; +} // namespace __cpo +} // namespace views + +} // namespace ranges + +#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS) && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES) + +_LIBCPP_END_NAMESPACE_STD + +#endif // _LIBCPP___RANGES_TRANSFORM_VIEW_H diff --git a/contrib/libs/cxxsupp/libcxxmsvc/include/__ranges/view_interface.h b/contrib/libs/cxxsupp/libcxxmsvc/include/__ranges/view_interface.h new file mode 100644 index 0000000000..eecc475111 --- /dev/null +++ b/contrib/libs/cxxsupp/libcxxmsvc/include/__ranges/view_interface.h @@ -0,0 +1,174 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// 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 _LIBCPP___RANGES_VIEW_INTERFACE_H +#define _LIBCPP___RANGES_VIEW_INTERFACE_H + +#include <__assert> +#include <__concepts/derived_from.h> +#include <__concepts/same_as.h> +#include <__config> +#include <__iterator/concepts.h> +#include <__iterator/iterator_traits.h> +#include <__iterator/prev.h> +#include <__memory/pointer_traits.h> +#include <__ranges/access.h> +#include <__ranges/concepts.h> +#include <__ranges/empty.h> +#include <type_traits> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +# pragma GCC system_header +#endif + +_LIBCPP_BEGIN_NAMESPACE_STD + +#if !defined(_LIBCPP_HAS_NO_CONCEPTS) && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES) + +namespace ranges { + +template<class _Derived> + requires is_class_v<_Derived> && same_as<_Derived, remove_cv_t<_Derived>> +class view_interface { + _LIBCPP_HIDE_FROM_ABI + constexpr _Derived& __derived() noexcept { + static_assert(sizeof(_Derived) && derived_from<_Derived, view_interface> && view<_Derived>); + return static_cast<_Derived&>(*this); + } + + _LIBCPP_HIDE_FROM_ABI + constexpr _Derived const& __derived() const noexcept { + static_assert(sizeof(_Derived) && derived_from<_Derived, view_interface> && view<_Derived>); + return static_cast<_Derived const&>(*this); + } + +public: + template<class _D2 = _Derived> + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr bool empty() + requires forward_range<_D2> + { + return ranges::begin(__derived()) == ranges::end(__derived()); + } + + template<class _D2 = _Derived> + [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr bool empty() const + requires forward_range<const _D2> + { + return ranges::begin(__derived()) == ranges::end(__derived()); + } + + template<class _D2 = _Derived> + _LIBCPP_HIDE_FROM_ABI + constexpr explicit operator bool() + requires requires (_D2& __t) { ranges::empty(__t); } + { + return !ranges::empty(__derived()); + } + + template<class _D2 = _Derived> + _LIBCPP_HIDE_FROM_ABI + constexpr explicit operator bool() const + requires requires (const _D2& __t) { ranges::empty(__t); } + { + return !ranges::empty(__derived()); + } + + template<class _D2 = _Derived> + _LIBCPP_HIDE_FROM_ABI + constexpr auto data() + requires contiguous_iterator<iterator_t<_D2>> + { + return std::to_address(ranges::begin(__derived())); + } + + template<class _D2 = _Derived> + _LIBCPP_HIDE_FROM_ABI + constexpr auto data() const + requires range<const _D2> && contiguous_iterator<iterator_t<const _D2>> + { + return std::to_address(ranges::begin(__derived())); + } + + template<class _D2 = _Derived> + _LIBCPP_HIDE_FROM_ABI + constexpr auto size() + requires forward_range<_D2> && sized_sentinel_for<sentinel_t<_D2>, iterator_t<_D2>> + { + return ranges::end(__derived()) - ranges::begin(__derived()); + } + + template<class _D2 = _Derived> + _LIBCPP_HIDE_FROM_ABI + constexpr auto size() const + requires forward_range<const _D2> && sized_sentinel_for<sentinel_t<const _D2>, iterator_t<const _D2>> + { + return ranges::end(__derived()) - ranges::begin(__derived()); + } + + template<class _D2 = _Derived> + _LIBCPP_HIDE_FROM_ABI + constexpr decltype(auto) front() + requires forward_range<_D2> + { + _LIBCPP_ASSERT(!empty(), + "Precondition `!empty()` not satisfied. `.front()` called on an empty view."); + return *ranges::begin(__derived()); + } + + template<class _D2 = _Derived> + _LIBCPP_HIDE_FROM_ABI + constexpr decltype(auto) front() const + requires forward_range<const _D2> + { + _LIBCPP_ASSERT(!empty(), + "Precondition `!empty()` not satisfied. `.front()` called on an empty view."); + return *ranges::begin(__derived()); + } + + template<class _D2 = _Derived> + _LIBCPP_HIDE_FROM_ABI + constexpr decltype(auto) back() + requires bidirectional_range<_D2> && common_range<_D2> + { + _LIBCPP_ASSERT(!empty(), + "Precondition `!empty()` not satisfied. `.back()` called on an empty view."); + return *ranges::prev(ranges::end(__derived())); + } + + template<class _D2 = _Derived> + _LIBCPP_HIDE_FROM_ABI + constexpr decltype(auto) back() const + requires bidirectional_range<const _D2> && common_range<const _D2> + { + _LIBCPP_ASSERT(!empty(), + "Precondition `!empty()` not satisfied. `.back()` called on an empty view."); + return *ranges::prev(ranges::end(__derived())); + } + + template<random_access_range _RARange = _Derived> + _LIBCPP_HIDE_FROM_ABI + constexpr decltype(auto) operator[](range_difference_t<_RARange> __index) + { + return ranges::begin(__derived())[__index]; + } + + template<random_access_range _RARange = const _Derived> + _LIBCPP_HIDE_FROM_ABI + constexpr decltype(auto) operator[](range_difference_t<_RARange> __index) const + { + return ranges::begin(__derived())[__index]; + } +}; + +} // namespace ranges + +#endif // !defined(_LIBCPP_HAS_NO_CONCEPTS) && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES) + +_LIBCPP_END_NAMESPACE_STD + +#endif // _LIBCPP___RANGES_VIEW_INTERFACE_H diff --git a/contrib/libs/cxxsupp/libcxxmsvc/include/__ranges/views.h b/contrib/libs/cxxsupp/libcxxmsvc/include/__ranges/views.h new file mode 100644 index 0000000000..8cc5ba3d2a --- /dev/null +++ b/contrib/libs/cxxsupp/libcxxmsvc/include/__ranges/views.h @@ -0,0 +1,35 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// 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 _LIBCPP___RANGES_VIEWS +#define _LIBCPP___RANGES_VIEWS + +#include <__config> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +# pragma GCC system_header +#endif + +_LIBCPP_BEGIN_NAMESPACE_STD + +#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES) + +namespace ranges { + +namespace views { } + +} // namespace ranges + +namespace views = ranges::views; + +#endif // _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES) + +_LIBCPP_END_NAMESPACE_STD + +#endif // _LIBCPP___RANGES_VIEWS diff --git a/contrib/libs/cxxsupp/libcxxmsvc/include/__split_buffer b/contrib/libs/cxxsupp/libcxxmsvc/include/__split_buffer new file mode 100644 index 0000000000..dd789e8e9d --- /dev/null +++ b/contrib/libs/cxxsupp/libcxxmsvc/include/__split_buffer @@ -0,0 +1,636 @@ +// -*- C++ -*- +#ifndef _LIBCPP_SPLIT_BUFFER +#define _LIBCPP_SPLIT_BUFFER + +#include <__algorithm/max.h> +#include <__algorithm/move.h> +#include <__algorithm/move_backward.h> +#include <__config> +#include <__iterator/distance.h> +#include <__iterator/iterator_traits.h> +#include <__iterator/move_iterator.h> +#include <__memory/allocator.h> +#include <__memory/compressed_pair.h> +#include <__utility/forward.h> +#include <memory> +#include <type_traits> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +# pragma GCC system_header +#endif + +_LIBCPP_PUSH_MACROS +#include <__undef_macros> + + +_LIBCPP_BEGIN_NAMESPACE_STD + +template <class _Tp, class _Allocator = allocator<_Tp> > +struct __split_buffer +{ +private: + __split_buffer(const __split_buffer&); + __split_buffer& operator=(const __split_buffer&); +public: + typedef _Tp value_type; + typedef _Allocator allocator_type; + typedef typename remove_reference<allocator_type>::type __alloc_rr; + typedef allocator_traits<__alloc_rr> __alloc_traits; + typedef value_type& reference; + typedef const value_type& const_reference; + typedef typename __alloc_traits::size_type size_type; + typedef typename __alloc_traits::difference_type difference_type; + typedef typename __alloc_traits::pointer pointer; + typedef typename __alloc_traits::const_pointer const_pointer; + typedef pointer iterator; + typedef const_pointer const_iterator; + + pointer __first_; + pointer __begin_; + pointer __end_; + __compressed_pair<pointer, allocator_type> __end_cap_; + + typedef typename add_lvalue_reference<allocator_type>::type __alloc_ref; + typedef typename add_lvalue_reference<allocator_type>::type __alloc_const_ref; + + _LIBCPP_INLINE_VISIBILITY __alloc_rr& __alloc() _NOEXCEPT {return __end_cap_.second();} + _LIBCPP_INLINE_VISIBILITY const __alloc_rr& __alloc() const _NOEXCEPT {return __end_cap_.second();} + _LIBCPP_INLINE_VISIBILITY pointer& __end_cap() _NOEXCEPT {return __end_cap_.first();} + _LIBCPP_INLINE_VISIBILITY const pointer& __end_cap() const _NOEXCEPT {return __end_cap_.first();} + + _LIBCPP_INLINE_VISIBILITY + __split_buffer() + _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value); + _LIBCPP_INLINE_VISIBILITY + explicit __split_buffer(__alloc_rr& __a); + _LIBCPP_INLINE_VISIBILITY + explicit __split_buffer(const __alloc_rr& __a); + __split_buffer(size_type __cap, size_type __start, __alloc_rr& __a); + ~__split_buffer(); + + __split_buffer(__split_buffer&& __c) + _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value); + __split_buffer(__split_buffer&& __c, const __alloc_rr& __a); + __split_buffer& operator=(__split_buffer&& __c) + _NOEXCEPT_((__alloc_traits::propagate_on_container_move_assignment::value && + is_nothrow_move_assignable<allocator_type>::value) || + !__alloc_traits::propagate_on_container_move_assignment::value); + + _LIBCPP_INLINE_VISIBILITY iterator begin() _NOEXCEPT {return __begin_;} + _LIBCPP_INLINE_VISIBILITY const_iterator begin() const _NOEXCEPT {return __begin_;} + _LIBCPP_INLINE_VISIBILITY iterator end() _NOEXCEPT {return __end_;} + _LIBCPP_INLINE_VISIBILITY const_iterator end() const _NOEXCEPT {return __end_;} + + _LIBCPP_INLINE_VISIBILITY + void clear() _NOEXCEPT + {__destruct_at_end(__begin_);} + _LIBCPP_INLINE_VISIBILITY size_type size() const {return static_cast<size_type>(__end_ - __begin_);} + _LIBCPP_INLINE_VISIBILITY bool empty() const {return __end_ == __begin_;} + _LIBCPP_INLINE_VISIBILITY size_type capacity() const {return static_cast<size_type>(__end_cap() - __first_);} + _LIBCPP_INLINE_VISIBILITY size_type __front_spare() const {return static_cast<size_type>(__begin_ - __first_);} + _LIBCPP_INLINE_VISIBILITY size_type __back_spare() const {return static_cast<size_type>(__end_cap() - __end_);} + + _LIBCPP_INLINE_VISIBILITY reference front() {return *__begin_;} + _LIBCPP_INLINE_VISIBILITY const_reference front() const {return *__begin_;} + _LIBCPP_INLINE_VISIBILITY reference back() {return *(__end_ - 1);} + _LIBCPP_INLINE_VISIBILITY const_reference back() const {return *(__end_ - 1);} + + void reserve(size_type __n); + void shrink_to_fit() _NOEXCEPT; + void push_front(const_reference __x); + _LIBCPP_INLINE_VISIBILITY void push_back(const_reference __x); + void push_front(value_type&& __x); + void push_back(value_type&& __x); + template <class... _Args> + void emplace_back(_Args&&... __args); + + _LIBCPP_INLINE_VISIBILITY void pop_front() {__destruct_at_begin(__begin_+1);} + _LIBCPP_INLINE_VISIBILITY void pop_back() {__destruct_at_end(__end_-1);} + + void __uninitialized_at_end(size_type __n); + void __construct_at_end(size_type __n); + void __construct_at_end(size_type __n, const_reference __x); + template <class _InputIter> + typename enable_if + < + __is_cpp17_input_iterator<_InputIter>::value && + !__is_cpp17_forward_iterator<_InputIter>::value, + void + >::type + __construct_at_end(_InputIter __first, _InputIter __last); + template <class _ForwardIterator> + typename enable_if + < + __is_cpp17_forward_iterator<_ForwardIterator>::value, + void + >::type + __construct_at_end(_ForwardIterator __first, _ForwardIterator __last); + + _LIBCPP_INLINE_VISIBILITY void __destruct_at_begin(pointer __new_begin) + {__destruct_at_begin(__new_begin, is_trivially_destructible<value_type>());} + _LIBCPP_INLINE_VISIBILITY + void __destruct_at_begin(pointer __new_begin, false_type); + _LIBCPP_INLINE_VISIBILITY + void __destruct_at_begin(pointer __new_begin, true_type); + + _LIBCPP_INLINE_VISIBILITY + void __destruct_at_end(pointer __new_last) _NOEXCEPT + {__destruct_at_end(__new_last, false_type());} + _LIBCPP_INLINE_VISIBILITY + void __destruct_at_end(pointer __new_last, false_type) _NOEXCEPT; + _LIBCPP_INLINE_VISIBILITY + void __destruct_at_end(pointer __new_last, true_type) _NOEXCEPT; + + void swap(__split_buffer& __x) + _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value|| + __is_nothrow_swappable<__alloc_rr>::value); + + bool __invariants() const; + +private: + _LIBCPP_INLINE_VISIBILITY + void __move_assign_alloc(__split_buffer& __c, true_type) + _NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value) + { + __alloc() = _VSTD::move(__c.__alloc()); + } + + _LIBCPP_INLINE_VISIBILITY + void __move_assign_alloc(__split_buffer&, false_type) _NOEXCEPT + {} + + struct _ConstructTransaction { + explicit _ConstructTransaction(pointer* __p, size_type __n) _NOEXCEPT + : __pos_(*__p), __end_(*__p + __n), __dest_(__p) { + } + ~_ConstructTransaction() { + *__dest_ = __pos_; + } + pointer __pos_; + const pointer __end_; + private: + pointer *__dest_; + }; +}; + +template <class _Tp, class _Allocator> +bool +__split_buffer<_Tp, _Allocator>::__invariants() const +{ + if (__first_ == nullptr) + { + if (__begin_ != nullptr) + return false; + if (__end_ != nullptr) + return false; + if (__end_cap() != nullptr) + return false; + } + else + { + if (__begin_ < __first_) + return false; + if (__end_ < __begin_) + return false; + if (__end_cap() < __end_) + return false; + } + return true; +} + +template <class _Tp, class _Allocator> +void +__split_buffer<_Tp, _Allocator>::__uninitialized_at_end(size_type __n) +{ + this->__end_ += __n; +} + +// Default constructs __n objects starting at __end_ +// throws if construction throws +// Precondition: __n > 0 +// Precondition: size() + __n <= capacity() +// Postcondition: size() == size() + __n +template <class _Tp, class _Allocator> +void +__split_buffer<_Tp, _Allocator>::__construct_at_end(size_type __n) +{ + _ConstructTransaction __tx(&this->__end_, __n); + for (; __tx.__pos_ != __tx.__end_; ++__tx.__pos_) { + __alloc_traits::construct(this->__alloc(), _VSTD::__to_address(__tx.__pos_)); + } +} + +// Copy constructs __n objects starting at __end_ from __x +// throws if construction throws +// Precondition: __n > 0 +// Precondition: size() + __n <= capacity() +// Postcondition: size() == old size() + __n +// Postcondition: [i] == __x for all i in [size() - __n, __n) +template <class _Tp, class _Allocator> +void +__split_buffer<_Tp, _Allocator>::__construct_at_end(size_type __n, const_reference __x) +{ + _ConstructTransaction __tx(&this->__end_, __n); + for (; __tx.__pos_ != __tx.__end_; ++__tx.__pos_) { + __alloc_traits::construct(this->__alloc(), + _VSTD::__to_address(__tx.__pos_), __x); + } +} + +template <class _Tp, class _Allocator> +template <class _InputIter> +typename enable_if +< + __is_cpp17_input_iterator<_InputIter>::value && + !__is_cpp17_forward_iterator<_InputIter>::value, + void +>::type +__split_buffer<_Tp, _Allocator>::__construct_at_end(_InputIter __first, _InputIter __last) +{ + __alloc_rr& __a = this->__alloc(); + for (; __first != __last; ++__first) + { + if (__end_ == __end_cap()) + { + size_type __old_cap = __end_cap() - __first_; + size_type __new_cap = _VSTD::max<size_type>(2 * __old_cap, 8); + __split_buffer __buf(__new_cap, 0, __a); + for (pointer __p = __begin_; __p != __end_; ++__p, (void) ++__buf.__end_) + __alloc_traits::construct(__buf.__alloc(), + _VSTD::__to_address(__buf.__end_), _VSTD::move(*__p)); + swap(__buf); + } + __alloc_traits::construct(__a, _VSTD::__to_address(this->__end_), *__first); + ++this->__end_; + } +} + +template <class _Tp, class _Allocator> +template <class _ForwardIterator> +typename enable_if +< + __is_cpp17_forward_iterator<_ForwardIterator>::value, + void +>::type +__split_buffer<_Tp, _Allocator>::__construct_at_end(_ForwardIterator __first, _ForwardIterator __last) +{ + _ConstructTransaction __tx(&this->__end_, _VSTD::distance(__first, __last)); + for (; __tx.__pos_ != __tx.__end_; ++__tx.__pos_, (void) ++__first) { + __alloc_traits::construct(this->__alloc(), + _VSTD::__to_address(__tx.__pos_), *__first); + } +} + +template <class _Tp, class _Allocator> +inline +void +__split_buffer<_Tp, _Allocator>::__destruct_at_begin(pointer __new_begin, false_type) +{ + while (__begin_ != __new_begin) + __alloc_traits::destroy(__alloc(), _VSTD::__to_address(__begin_++)); +} + +template <class _Tp, class _Allocator> +inline +void +__split_buffer<_Tp, _Allocator>::__destruct_at_begin(pointer __new_begin, true_type) +{ + __begin_ = __new_begin; +} + +template <class _Tp, class _Allocator> +inline _LIBCPP_INLINE_VISIBILITY +void +__split_buffer<_Tp, _Allocator>::__destruct_at_end(pointer __new_last, false_type) _NOEXCEPT +{ + while (__new_last != __end_) + __alloc_traits::destroy(__alloc(), _VSTD::__to_address(--__end_)); +} + +template <class _Tp, class _Allocator> +inline _LIBCPP_INLINE_VISIBILITY +void +__split_buffer<_Tp, _Allocator>::__destruct_at_end(pointer __new_last, true_type) _NOEXCEPT +{ + __end_ = __new_last; +} + +template <class _Tp, class _Allocator> +__split_buffer<_Tp, _Allocator>::__split_buffer(size_type __cap, size_type __start, __alloc_rr& __a) + : __end_cap_(nullptr, __a) +{ + __first_ = __cap != 0 ? __alloc_traits::allocate(__alloc(), __cap) : nullptr; + __begin_ = __end_ = __first_ + __start; + __end_cap() = __first_ + __cap; +} + +template <class _Tp, class _Allocator> +inline +__split_buffer<_Tp, _Allocator>::__split_buffer() + _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value) + : __first_(nullptr), __begin_(nullptr), __end_(nullptr), __end_cap_(nullptr, __default_init_tag()) +{ +} + +template <class _Tp, class _Allocator> +inline +__split_buffer<_Tp, _Allocator>::__split_buffer(__alloc_rr& __a) + : __first_(nullptr), __begin_(nullptr), __end_(nullptr), __end_cap_(nullptr, __a) +{ +} + +template <class _Tp, class _Allocator> +inline +__split_buffer<_Tp, _Allocator>::__split_buffer(const __alloc_rr& __a) + : __first_(nullptr), __begin_(nullptr), __end_(nullptr), __end_cap_(nullptr, __a) +{ +} + +template <class _Tp, class _Allocator> +__split_buffer<_Tp, _Allocator>::~__split_buffer() +{ + clear(); + if (__first_) + __alloc_traits::deallocate(__alloc(), __first_, capacity()); +} + +template <class _Tp, class _Allocator> +__split_buffer<_Tp, _Allocator>::__split_buffer(__split_buffer&& __c) + _NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value) + : __first_(_VSTD::move(__c.__first_)), + __begin_(_VSTD::move(__c.__begin_)), + __end_(_VSTD::move(__c.__end_)), + __end_cap_(_VSTD::move(__c.__end_cap_)) +{ + __c.__first_ = nullptr; + __c.__begin_ = nullptr; + __c.__end_ = nullptr; + __c.__end_cap() = nullptr; +} + +template <class _Tp, class _Allocator> +__split_buffer<_Tp, _Allocator>::__split_buffer(__split_buffer&& __c, const __alloc_rr& __a) + : __end_cap_(nullptr, __a) +{ + if (__a == __c.__alloc()) + { + __first_ = __c.__first_; + __begin_ = __c.__begin_; + __end_ = __c.__end_; + __end_cap() = __c.__end_cap(); + __c.__first_ = nullptr; + __c.__begin_ = nullptr; + __c.__end_ = nullptr; + __c.__end_cap() = nullptr; + } + else + { + size_type __cap = __c.size(); + __first_ = __alloc_traits::allocate(__alloc(), __cap); + __begin_ = __end_ = __first_; + __end_cap() = __first_ + __cap; + typedef move_iterator<iterator> _Ip; + __construct_at_end(_Ip(__c.begin()), _Ip(__c.end())); + } +} + +template <class _Tp, class _Allocator> +__split_buffer<_Tp, _Allocator>& +__split_buffer<_Tp, _Allocator>::operator=(__split_buffer&& __c) + _NOEXCEPT_((__alloc_traits::propagate_on_container_move_assignment::value && + is_nothrow_move_assignable<allocator_type>::value) || + !__alloc_traits::propagate_on_container_move_assignment::value) +{ + clear(); + shrink_to_fit(); + __first_ = __c.__first_; + __begin_ = __c.__begin_; + __end_ = __c.__end_; + __end_cap() = __c.__end_cap(); + __move_assign_alloc(__c, + integral_constant<bool, + __alloc_traits::propagate_on_container_move_assignment::value>()); + __c.__first_ = __c.__begin_ = __c.__end_ = __c.__end_cap() = nullptr; + return *this; +} + +template <class _Tp, class _Allocator> +void +__split_buffer<_Tp, _Allocator>::swap(__split_buffer& __x) + _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value|| + __is_nothrow_swappable<__alloc_rr>::value) +{ + _VSTD::swap(__first_, __x.__first_); + _VSTD::swap(__begin_, __x.__begin_); + _VSTD::swap(__end_, __x.__end_); + _VSTD::swap(__end_cap(), __x.__end_cap()); + _VSTD::__swap_allocator(__alloc(), __x.__alloc()); +} + +template <class _Tp, class _Allocator> +void +__split_buffer<_Tp, _Allocator>::reserve(size_type __n) +{ + if (__n < capacity()) + { + __split_buffer<value_type, __alloc_rr&> __t(__n, 0, __alloc()); + __t.__construct_at_end(move_iterator<pointer>(__begin_), + move_iterator<pointer>(__end_)); + _VSTD::swap(__first_, __t.__first_); + _VSTD::swap(__begin_, __t.__begin_); + _VSTD::swap(__end_, __t.__end_); + _VSTD::swap(__end_cap(), __t.__end_cap()); + } +} + +template <class _Tp, class _Allocator> +void +__split_buffer<_Tp, _Allocator>::shrink_to_fit() _NOEXCEPT +{ + if (capacity() > size()) + { +#ifndef _LIBCPP_NO_EXCEPTIONS + try + { +#endif // _LIBCPP_NO_EXCEPTIONS + __split_buffer<value_type, __alloc_rr&> __t(size(), 0, __alloc()); + __t.__construct_at_end(move_iterator<pointer>(__begin_), + move_iterator<pointer>(__end_)); + __t.__end_ = __t.__begin_ + (__end_ - __begin_); + _VSTD::swap(__first_, __t.__first_); + _VSTD::swap(__begin_, __t.__begin_); + _VSTD::swap(__end_, __t.__end_); + _VSTD::swap(__end_cap(), __t.__end_cap()); +#ifndef _LIBCPP_NO_EXCEPTIONS + } + catch (...) + { + } +#endif // _LIBCPP_NO_EXCEPTIONS + } +} + +template <class _Tp, class _Allocator> +void +__split_buffer<_Tp, _Allocator>::push_front(const_reference __x) +{ + if (__begin_ == __first_) + { + if (__end_ < __end_cap()) + { + difference_type __d = __end_cap() - __end_; + __d = (__d + 1) / 2; + __begin_ = _VSTD::move_backward(__begin_, __end_, __end_ + __d); + __end_ += __d; + } + else + { + size_type __c = max<size_type>(2 * static_cast<size_t>(__end_cap() - __first_), 1); + __split_buffer<value_type, __alloc_rr&> __t(__c, (__c + 3) / 4, __alloc()); + __t.__construct_at_end(move_iterator<pointer>(__begin_), + move_iterator<pointer>(__end_)); + _VSTD::swap(__first_, __t.__first_); + _VSTD::swap(__begin_, __t.__begin_); + _VSTD::swap(__end_, __t.__end_); + _VSTD::swap(__end_cap(), __t.__end_cap()); + } + } + __alloc_traits::construct(__alloc(), _VSTD::__to_address(__begin_-1), __x); + --__begin_; +} + +template <class _Tp, class _Allocator> +void +__split_buffer<_Tp, _Allocator>::push_front(value_type&& __x) +{ + if (__begin_ == __first_) + { + if (__end_ < __end_cap()) + { + difference_type __d = __end_cap() - __end_; + __d = (__d + 1) / 2; + __begin_ = _VSTD::move_backward(__begin_, __end_, __end_ + __d); + __end_ += __d; + } + else + { + size_type __c = max<size_type>(2 * static_cast<size_t>(__end_cap() - __first_), 1); + __split_buffer<value_type, __alloc_rr&> __t(__c, (__c + 3) / 4, __alloc()); + __t.__construct_at_end(move_iterator<pointer>(__begin_), + move_iterator<pointer>(__end_)); + _VSTD::swap(__first_, __t.__first_); + _VSTD::swap(__begin_, __t.__begin_); + _VSTD::swap(__end_, __t.__end_); + _VSTD::swap(__end_cap(), __t.__end_cap()); + } + } + __alloc_traits::construct(__alloc(), _VSTD::__to_address(__begin_-1), + _VSTD::move(__x)); + --__begin_; +} + +template <class _Tp, class _Allocator> +inline _LIBCPP_INLINE_VISIBILITY +void +__split_buffer<_Tp, _Allocator>::push_back(const_reference __x) +{ + if (__end_ == __end_cap()) + { + if (__begin_ > __first_) + { + difference_type __d = __begin_ - __first_; + __d = (__d + 1) / 2; + __end_ = _VSTD::move(__begin_, __end_, __begin_ - __d); + __begin_ -= __d; + } + else + { + size_type __c = max<size_type>(2 * static_cast<size_t>(__end_cap() - __first_), 1); + __split_buffer<value_type, __alloc_rr&> __t(__c, __c / 4, __alloc()); + __t.__construct_at_end(move_iterator<pointer>(__begin_), + move_iterator<pointer>(__end_)); + _VSTD::swap(__first_, __t.__first_); + _VSTD::swap(__begin_, __t.__begin_); + _VSTD::swap(__end_, __t.__end_); + _VSTD::swap(__end_cap(), __t.__end_cap()); + } + } + __alloc_traits::construct(__alloc(), _VSTD::__to_address(__end_), __x); + ++__end_; +} + +template <class _Tp, class _Allocator> +void +__split_buffer<_Tp, _Allocator>::push_back(value_type&& __x) +{ + if (__end_ == __end_cap()) + { + if (__begin_ > __first_) + { + difference_type __d = __begin_ - __first_; + __d = (__d + 1) / 2; + __end_ = _VSTD::move(__begin_, __end_, __begin_ - __d); + __begin_ -= __d; + } + else + { + size_type __c = max<size_type>(2 * static_cast<size_t>(__end_cap() - __first_), 1); + __split_buffer<value_type, __alloc_rr&> __t(__c, __c / 4, __alloc()); + __t.__construct_at_end(move_iterator<pointer>(__begin_), + move_iterator<pointer>(__end_)); + _VSTD::swap(__first_, __t.__first_); + _VSTD::swap(__begin_, __t.__begin_); + _VSTD::swap(__end_, __t.__end_); + _VSTD::swap(__end_cap(), __t.__end_cap()); + } + } + __alloc_traits::construct(__alloc(), _VSTD::__to_address(__end_), + _VSTD::move(__x)); + ++__end_; +} + +template <class _Tp, class _Allocator> +template <class... _Args> +void +__split_buffer<_Tp, _Allocator>::emplace_back(_Args&&... __args) +{ + if (__end_ == __end_cap()) + { + if (__begin_ > __first_) + { + difference_type __d = __begin_ - __first_; + __d = (__d + 1) / 2; + __end_ = _VSTD::move(__begin_, __end_, __begin_ - __d); + __begin_ -= __d; + } + else + { + size_type __c = max<size_type>(2 * static_cast<size_t>(__end_cap() - __first_), 1); + __split_buffer<value_type, __alloc_rr&> __t(__c, __c / 4, __alloc()); + __t.__construct_at_end(move_iterator<pointer>(__begin_), + move_iterator<pointer>(__end_)); + _VSTD::swap(__first_, __t.__first_); + _VSTD::swap(__begin_, __t.__begin_); + _VSTD::swap(__end_, __t.__end_); + _VSTD::swap(__end_cap(), __t.__end_cap()); + } + } + __alloc_traits::construct(__alloc(), _VSTD::__to_address(__end_), + _VSTD::forward<_Args>(__args)...); + ++__end_; +} + +template <class _Tp, class _Allocator> +inline _LIBCPP_INLINE_VISIBILITY +void +swap(__split_buffer<_Tp, _Allocator>& __x, __split_buffer<_Tp, _Allocator>& __y) + _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y))) +{ + __x.swap(__y); +} + +_LIBCPP_END_NAMESPACE_STD + +_LIBCPP_POP_MACROS + +#endif // _LIBCPP_SPLIT_BUFFER diff --git a/contrib/libs/cxxsupp/libcxxmsvc/include/__tree b/contrib/libs/cxxsupp/libcxxmsvc/include/__tree new file mode 100644 index 0000000000..384d383504 --- /dev/null +++ b/contrib/libs/cxxsupp/libcxxmsvc/include/__tree @@ -0,0 +1,2748 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// 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 _LIBCPP___TREE +#define _LIBCPP___TREE + +#include <__algorithm/min.h> +#include <__config> +#include <__utility/forward.h> +#include <iterator> +#include <limits> +#include <memory> +#include <stdexcept> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +# pragma GCC system_header +#endif + +_LIBCPP_PUSH_MACROS +#include <__undef_macros> + + +_LIBCPP_BEGIN_NAMESPACE_STD + +#if defined(__GNUC__) && !defined(__clang__) // gcc.gnu.org/PR37804 +template <class, class, class, class> class _LIBCPP_TEMPLATE_VIS map; +template <class, class, class, class> class _LIBCPP_TEMPLATE_VIS multimap; +template <class, class, class> class _LIBCPP_TEMPLATE_VIS set; +template <class, class, class> class _LIBCPP_TEMPLATE_VIS multiset; +#endif + +template <class _Tp, class _Compare, class _Allocator> class __tree; +template <class _Tp, class _NodePtr, class _DiffType> + class _LIBCPP_TEMPLATE_VIS __tree_iterator; +template <class _Tp, class _ConstNodePtr, class _DiffType> + class _LIBCPP_TEMPLATE_VIS __tree_const_iterator; + +template <class _Pointer> class __tree_end_node; +template <class _VoidPtr> class __tree_node_base; +template <class _Tp, class _VoidPtr> class __tree_node; + +template <class _Key, class _Value> +struct __value_type; + +template <class _Allocator> class __map_node_destructor; +template <class _TreeIterator> class _LIBCPP_TEMPLATE_VIS __map_iterator; +template <class _TreeIterator> class _LIBCPP_TEMPLATE_VIS __map_const_iterator; + +/* + +_NodePtr algorithms + +The algorithms taking _NodePtr are red black tree algorithms. Those +algorithms taking a parameter named __root should assume that __root +points to a proper red black tree (unless otherwise specified). + +Each algorithm herein assumes that __root->__parent_ points to a non-null +structure which has a member __left_ which points back to __root. No other +member is read or written to at __root->__parent_. + +__root->__parent_ will be referred to below (in comments only) as end_node. +end_node->__left_ is an externably accessible lvalue for __root, and can be +changed by node insertion and removal (without explicit reference to end_node). + +All nodes (with the exception of end_node), even the node referred to as +__root, have a non-null __parent_ field. + +*/ + +// Returns: true if __x is a left child of its parent, else false +// Precondition: __x != nullptr. +template <class _NodePtr> +inline _LIBCPP_INLINE_VISIBILITY +bool +__tree_is_left_child(_NodePtr __x) _NOEXCEPT +{ + return __x == __x->__parent_->__left_; +} + +// Determines if the subtree rooted at __x is a proper red black subtree. If +// __x is a proper subtree, returns the black height (null counts as 1). If +// __x is an improper subtree, returns 0. +template <class _NodePtr> +unsigned +__tree_sub_invariant(_NodePtr __x) +{ + if (__x == nullptr) + return 1; + // parent consistency checked by caller + // check __x->__left_ consistency + if (__x->__left_ != nullptr && __x->__left_->__parent_ != __x) + return 0; + // check __x->__right_ consistency + if (__x->__right_ != nullptr && __x->__right_->__parent_ != __x) + return 0; + // check __x->__left_ != __x->__right_ unless both are nullptr + if (__x->__left_ == __x->__right_ && __x->__left_ != nullptr) + return 0; + // If this is red, neither child can be red + if (!__x->__is_black_) + { + if (__x->__left_ && !__x->__left_->__is_black_) + return 0; + if (__x->__right_ && !__x->__right_->__is_black_) + return 0; + } + unsigned __h = _VSTD::__tree_sub_invariant(__x->__left_); + if (__h == 0) + return 0; // invalid left subtree + if (__h != _VSTD::__tree_sub_invariant(__x->__right_)) + return 0; // invalid or different height right subtree + return __h + __x->__is_black_; // return black height of this node +} + +// Determines if the red black tree rooted at __root is a proper red black tree. +// __root == nullptr is a proper tree. Returns true is __root is a proper +// red black tree, else returns false. +template <class _NodePtr> +bool +__tree_invariant(_NodePtr __root) +{ + if (__root == nullptr) + return true; + // check __x->__parent_ consistency + if (__root->__parent_ == nullptr) + return false; + if (!_VSTD::__tree_is_left_child(__root)) + return false; + // root must be black + if (!__root->__is_black_) + return false; + // do normal node checks + return _VSTD::__tree_sub_invariant(__root) != 0; +} + +// Returns: pointer to the left-most node under __x. +// Precondition: __x != nullptr. +template <class _NodePtr> +inline _LIBCPP_INLINE_VISIBILITY +_NodePtr +__tree_min(_NodePtr __x) _NOEXCEPT +{ + while (__x->__left_ != nullptr) + __x = __x->__left_; + return __x; +} + +// Returns: pointer to the right-most node under __x. +// Precondition: __x != nullptr. +template <class _NodePtr> +inline _LIBCPP_INLINE_VISIBILITY +_NodePtr +__tree_max(_NodePtr __x) _NOEXCEPT +{ + while (__x->__right_ != nullptr) + __x = __x->__right_; + return __x; +} + +// Returns: pointer to the next in-order node after __x. +// Precondition: __x != nullptr. +template <class _NodePtr> +_NodePtr +__tree_next(_NodePtr __x) _NOEXCEPT +{ + if (__x->__right_ != nullptr) + return _VSTD::__tree_min(__x->__right_); + while (!_VSTD::__tree_is_left_child(__x)) + __x = __x->__parent_unsafe(); + return __x->__parent_unsafe(); +} + +template <class _EndNodePtr, class _NodePtr> +inline _LIBCPP_INLINE_VISIBILITY +_EndNodePtr +__tree_next_iter(_NodePtr __x) _NOEXCEPT +{ + if (__x->__right_ != nullptr) + return static_cast<_EndNodePtr>(_VSTD::__tree_min(__x->__right_)); + while (!_VSTD::__tree_is_left_child(__x)) + __x = __x->__parent_unsafe(); + return static_cast<_EndNodePtr>(__x->__parent_); +} + +// Returns: pointer to the previous in-order node before __x. +// Precondition: __x != nullptr. +// Note: __x may be the end node. +template <class _NodePtr, class _EndNodePtr> +inline _LIBCPP_INLINE_VISIBILITY +_NodePtr +__tree_prev_iter(_EndNodePtr __x) _NOEXCEPT +{ + if (__x->__left_ != nullptr) + return _VSTD::__tree_max(__x->__left_); + _NodePtr __xx = static_cast<_NodePtr>(__x); + while (_VSTD::__tree_is_left_child(__xx)) + __xx = __xx->__parent_unsafe(); + return __xx->__parent_unsafe(); +} + +// Returns: pointer to a node which has no children +// Precondition: __x != nullptr. +template <class _NodePtr> +_NodePtr +__tree_leaf(_NodePtr __x) _NOEXCEPT +{ + while (true) + { + if (__x->__left_ != nullptr) + { + __x = __x->__left_; + continue; + } + if (__x->__right_ != nullptr) + { + __x = __x->__right_; + continue; + } + break; + } + return __x; +} + +// Effects: Makes __x->__right_ the subtree root with __x as its left child +// while preserving in-order order. +// Precondition: __x->__right_ != nullptr +template <class _NodePtr> +void +__tree_left_rotate(_NodePtr __x) _NOEXCEPT +{ + _NodePtr __y = __x->__right_; + __x->__right_ = __y->__left_; + if (__x->__right_ != nullptr) + __x->__right_->__set_parent(__x); + __y->__parent_ = __x->__parent_; + if (_VSTD::__tree_is_left_child(__x)) + __x->__parent_->__left_ = __y; + else + __x->__parent_unsafe()->__right_ = __y; + __y->__left_ = __x; + __x->__set_parent(__y); +} + +// Effects: Makes __x->__left_ the subtree root with __x as its right child +// while preserving in-order order. +// Precondition: __x->__left_ != nullptr +template <class _NodePtr> +void +__tree_right_rotate(_NodePtr __x) _NOEXCEPT +{ + _NodePtr __y = __x->__left_; + __x->__left_ = __y->__right_; + if (__x->__left_ != nullptr) + __x->__left_->__set_parent(__x); + __y->__parent_ = __x->__parent_; + if (_VSTD::__tree_is_left_child(__x)) + __x->__parent_->__left_ = __y; + else + __x->__parent_unsafe()->__right_ = __y; + __y->__right_ = __x; + __x->__set_parent(__y); +} + +// Effects: Rebalances __root after attaching __x to a leaf. +// Precondition: __root != nulptr && __x != nullptr. +// __x has no children. +// __x == __root or == a direct or indirect child of __root. +// If __x were to be unlinked from __root (setting __root to +// nullptr if __root == __x), __tree_invariant(__root) == true. +// Postcondition: __tree_invariant(end_node->__left_) == true. end_node->__left_ +// may be different than the value passed in as __root. +template <class _NodePtr> +void +__tree_balance_after_insert(_NodePtr __root, _NodePtr __x) _NOEXCEPT +{ + __x->__is_black_ = __x == __root; + while (__x != __root && !__x->__parent_unsafe()->__is_black_) + { + // __x->__parent_ != __root because __x->__parent_->__is_black == false + if (_VSTD::__tree_is_left_child(__x->__parent_unsafe())) + { + _NodePtr __y = __x->__parent_unsafe()->__parent_unsafe()->__right_; + if (__y != nullptr && !__y->__is_black_) + { + __x = __x->__parent_unsafe(); + __x->__is_black_ = true; + __x = __x->__parent_unsafe(); + __x->__is_black_ = __x == __root; + __y->__is_black_ = true; + } + else + { + if (!_VSTD::__tree_is_left_child(__x)) + { + __x = __x->__parent_unsafe(); + _VSTD::__tree_left_rotate(__x); + } + __x = __x->__parent_unsafe(); + __x->__is_black_ = true; + __x = __x->__parent_unsafe(); + __x->__is_black_ = false; + _VSTD::__tree_right_rotate(__x); + break; + } + } + else + { + _NodePtr __y = __x->__parent_unsafe()->__parent_->__left_; + if (__y != nullptr && !__y->__is_black_) + { + __x = __x->__parent_unsafe(); + __x->__is_black_ = true; + __x = __x->__parent_unsafe(); + __x->__is_black_ = __x == __root; + __y->__is_black_ = true; + } + else + { + if (_VSTD::__tree_is_left_child(__x)) + { + __x = __x->__parent_unsafe(); + _VSTD::__tree_right_rotate(__x); + } + __x = __x->__parent_unsafe(); + __x->__is_black_ = true; + __x = __x->__parent_unsafe(); + __x->__is_black_ = false; + _VSTD::__tree_left_rotate(__x); + break; + } + } + } +} + +// Precondition: __root != nullptr && __z != nullptr. +// __tree_invariant(__root) == true. +// __z == __root or == a direct or indirect child of __root. +// Effects: unlinks __z from the tree rooted at __root, rebalancing as needed. +// Postcondition: __tree_invariant(end_node->__left_) == true && end_node->__left_ +// nor any of its children refer to __z. end_node->__left_ +// may be different than the value passed in as __root. +template <class _NodePtr> +void +__tree_remove(_NodePtr __root, _NodePtr __z) _NOEXCEPT +{ + // __z will be removed from the tree. Client still needs to destruct/deallocate it + // __y is either __z, or if __z has two children, __tree_next(__z). + // __y will have at most one child. + // __y will be the initial hole in the tree (make the hole at a leaf) + _NodePtr __y = (__z->__left_ == nullptr || __z->__right_ == nullptr) ? + __z : _VSTD::__tree_next(__z); + // __x is __y's possibly null single child + _NodePtr __x = __y->__left_ != nullptr ? __y->__left_ : __y->__right_; + // __w is __x's possibly null uncle (will become __x's sibling) + _NodePtr __w = nullptr; + // link __x to __y's parent, and find __w + if (__x != nullptr) + __x->__parent_ = __y->__parent_; + if (_VSTD::__tree_is_left_child(__y)) + { + __y->__parent_->__left_ = __x; + if (__y != __root) + __w = __y->__parent_unsafe()->__right_; + else + __root = __x; // __w == nullptr + } + else + { + __y->__parent_unsafe()->__right_ = __x; + // __y can't be root if it is a right child + __w = __y->__parent_->__left_; + } + bool __removed_black = __y->__is_black_; + // If we didn't remove __z, do so now by splicing in __y for __z, + // but copy __z's color. This does not impact __x or __w. + if (__y != __z) + { + // __z->__left_ != nulptr but __z->__right_ might == __x == nullptr + __y->__parent_ = __z->__parent_; + if (_VSTD::__tree_is_left_child(__z)) + __y->__parent_->__left_ = __y; + else + __y->__parent_unsafe()->__right_ = __y; + __y->__left_ = __z->__left_; + __y->__left_->__set_parent(__y); + __y->__right_ = __z->__right_; + if (__y->__right_ != nullptr) + __y->__right_->__set_parent(__y); + __y->__is_black_ = __z->__is_black_; + if (__root == __z) + __root = __y; + } + // There is no need to rebalance if we removed a red, or if we removed + // the last node. + if (__removed_black && __root != nullptr) + { + // Rebalance: + // __x has an implicit black color (transferred from the removed __y) + // associated with it, no matter what its color is. + // If __x is __root (in which case it can't be null), it is supposed + // to be black anyway, and if it is doubly black, then the double + // can just be ignored. + // If __x is red (in which case it can't be null), then it can absorb + // the implicit black just by setting its color to black. + // Since __y was black and only had one child (which __x points to), __x + // is either red with no children, else null, otherwise __y would have + // different black heights under left and right pointers. + // if (__x == __root || __x != nullptr && !__x->__is_black_) + if (__x != nullptr) + __x->__is_black_ = true; + else + { + // Else __x isn't root, and is "doubly black", even though it may + // be null. __w can not be null here, else the parent would + // see a black height >= 2 on the __x side and a black height + // of 1 on the __w side (__w must be a non-null black or a red + // with a non-null black child). + while (true) + { + if (!_VSTD::__tree_is_left_child(__w)) // if x is left child + { + if (!__w->__is_black_) + { + __w->__is_black_ = true; + __w->__parent_unsafe()->__is_black_ = false; + _VSTD::__tree_left_rotate(__w->__parent_unsafe()); + // __x is still valid + // reset __root only if necessary + if (__root == __w->__left_) + __root = __w; + // reset sibling, and it still can't be null + __w = __w->__left_->__right_; + } + // __w->__is_black_ is now true, __w may have null children + if ((__w->__left_ == nullptr || __w->__left_->__is_black_) && + (__w->__right_ == nullptr || __w->__right_->__is_black_)) + { + __w->__is_black_ = false; + __x = __w->__parent_unsafe(); + // __x can no longer be null + if (__x == __root || !__x->__is_black_) + { + __x->__is_black_ = true; + break; + } + // reset sibling, and it still can't be null + __w = _VSTD::__tree_is_left_child(__x) ? + __x->__parent_unsafe()->__right_ : + __x->__parent_->__left_; + // continue; + } + else // __w has a red child + { + if (__w->__right_ == nullptr || __w->__right_->__is_black_) + { + // __w left child is non-null and red + __w->__left_->__is_black_ = true; + __w->__is_black_ = false; + _VSTD::__tree_right_rotate(__w); + // __w is known not to be root, so root hasn't changed + // reset sibling, and it still can't be null + __w = __w->__parent_unsafe(); + } + // __w has a right red child, left child may be null + __w->__is_black_ = __w->__parent_unsafe()->__is_black_; + __w->__parent_unsafe()->__is_black_ = true; + __w->__right_->__is_black_ = true; + _VSTD::__tree_left_rotate(__w->__parent_unsafe()); + break; + } + } + else + { + if (!__w->__is_black_) + { + __w->__is_black_ = true; + __w->__parent_unsafe()->__is_black_ = false; + _VSTD::__tree_right_rotate(__w->__parent_unsafe()); + // __x is still valid + // reset __root only if necessary + if (__root == __w->__right_) + __root = __w; + // reset sibling, and it still can't be null + __w = __w->__right_->__left_; + } + // __w->__is_black_ is now true, __w may have null children + if ((__w->__left_ == nullptr || __w->__left_->__is_black_) && + (__w->__right_ == nullptr || __w->__right_->__is_black_)) + { + __w->__is_black_ = false; + __x = __w->__parent_unsafe(); + // __x can no longer be null + if (!__x->__is_black_ || __x == __root) + { + __x->__is_black_ = true; + break; + } + // reset sibling, and it still can't be null + __w = _VSTD::__tree_is_left_child(__x) ? + __x->__parent_unsafe()->__right_ : + __x->__parent_->__left_; + // continue; + } + else // __w has a red child + { + if (__w->__left_ == nullptr || __w->__left_->__is_black_) + { + // __w right child is non-null and red + __w->__right_->__is_black_ = true; + __w->__is_black_ = false; + _VSTD::__tree_left_rotate(__w); + // __w is known not to be root, so root hasn't changed + // reset sibling, and it still can't be null + __w = __w->__parent_unsafe(); + } + // __w has a left red child, right child may be null + __w->__is_black_ = __w->__parent_unsafe()->__is_black_; + __w->__parent_unsafe()->__is_black_ = true; + __w->__left_->__is_black_ = true; + _VSTD::__tree_right_rotate(__w->__parent_unsafe()); + break; + } + } + } + } + } +} + +// node traits + + +template <class _Tp> +struct __is_tree_value_type_imp : false_type {}; + +template <class _Key, class _Value> +struct __is_tree_value_type_imp<__value_type<_Key, _Value> > : true_type {}; + +template <class ..._Args> +struct __is_tree_value_type : false_type {}; + +template <class _One> +struct __is_tree_value_type<_One> : __is_tree_value_type_imp<__uncvref_t<_One> > {}; + +template <class _Tp> +struct __tree_key_value_types { + typedef _Tp key_type; + typedef _Tp __node_value_type; + typedef _Tp __container_value_type; + static const bool __is_map = false; + + _LIBCPP_INLINE_VISIBILITY + static key_type const& __get_key(_Tp const& __v) { + return __v; + } + _LIBCPP_INLINE_VISIBILITY + static __container_value_type const& __get_value(__node_value_type const& __v) { + return __v; + } + _LIBCPP_INLINE_VISIBILITY + static __container_value_type* __get_ptr(__node_value_type& __n) { + return _VSTD::addressof(__n); + } + _LIBCPP_INLINE_VISIBILITY + static __container_value_type&& __move(__node_value_type& __v) { + return _VSTD::move(__v); + } +}; + +template <class _Key, class _Tp> +struct __tree_key_value_types<__value_type<_Key, _Tp> > { + typedef _Key key_type; + typedef _Tp mapped_type; + typedef __value_type<_Key, _Tp> __node_value_type; + typedef pair<const _Key, _Tp> __container_value_type; + typedef __container_value_type __map_value_type; + static const bool __is_map = true; + + _LIBCPP_INLINE_VISIBILITY + static key_type const& + __get_key(__node_value_type const& __t) { + return __t.__get_value().first; + } + + template <class _Up> + _LIBCPP_INLINE_VISIBILITY + static typename enable_if<__is_same_uncvref<_Up, __container_value_type>::value, + key_type const&>::type + __get_key(_Up& __t) { + return __t.first; + } + + _LIBCPP_INLINE_VISIBILITY + static __container_value_type const& + __get_value(__node_value_type const& __t) { + return __t.__get_value(); + } + + template <class _Up> + _LIBCPP_INLINE_VISIBILITY + static typename enable_if<__is_same_uncvref<_Up, __container_value_type>::value, + __container_value_type const&>::type + __get_value(_Up& __t) { + return __t; + } + + _LIBCPP_INLINE_VISIBILITY + static __container_value_type* __get_ptr(__node_value_type& __n) { + return _VSTD::addressof(__n.__get_value()); + } + + _LIBCPP_INLINE_VISIBILITY + static pair<key_type&&, mapped_type&&> __move(__node_value_type& __v) { + return __v.__move(); + } +}; + +template <class _VoidPtr> +struct __tree_node_base_types { + typedef _VoidPtr __void_pointer; + + typedef __tree_node_base<__void_pointer> __node_base_type; + typedef typename __rebind_pointer<_VoidPtr, __node_base_type>::type + __node_base_pointer; + + typedef __tree_end_node<__node_base_pointer> __end_node_type; + typedef typename __rebind_pointer<_VoidPtr, __end_node_type>::type + __end_node_pointer; +#if defined(_LIBCPP_ABI_TREE_REMOVE_NODE_POINTER_UB) + typedef __end_node_pointer __parent_pointer; +#else + typedef typename conditional< + is_pointer<__end_node_pointer>::value, + __end_node_pointer, + __node_base_pointer>::type __parent_pointer; +#endif + +private: + static_assert((is_same<typename pointer_traits<_VoidPtr>::element_type, void>::value), + "_VoidPtr does not point to unqualified void type"); +}; + +template <class _Tp, class _AllocPtr, class _KVTypes = __tree_key_value_types<_Tp>, + bool = _KVTypes::__is_map> +struct __tree_map_pointer_types {}; + +template <class _Tp, class _AllocPtr, class _KVTypes> +struct __tree_map_pointer_types<_Tp, _AllocPtr, _KVTypes, true> { + typedef typename _KVTypes::__map_value_type _Mv; + typedef typename __rebind_pointer<_AllocPtr, _Mv>::type + __map_value_type_pointer; + typedef typename __rebind_pointer<_AllocPtr, const _Mv>::type + __const_map_value_type_pointer; +}; + +template <class _NodePtr, class _NodeT = typename pointer_traits<_NodePtr>::element_type> +struct __tree_node_types; + +template <class _NodePtr, class _Tp, class _VoidPtr> +struct __tree_node_types<_NodePtr, __tree_node<_Tp, _VoidPtr> > + : public __tree_node_base_types<_VoidPtr>, + __tree_key_value_types<_Tp>, + __tree_map_pointer_types<_Tp, _VoidPtr> +{ + typedef __tree_node_base_types<_VoidPtr> __base; + typedef __tree_key_value_types<_Tp> __key_base; + typedef __tree_map_pointer_types<_Tp, _VoidPtr> __map_pointer_base; +public: + + typedef typename pointer_traits<_NodePtr>::element_type __node_type; + typedef _NodePtr __node_pointer; + + typedef _Tp __node_value_type; + typedef typename __rebind_pointer<_VoidPtr, __node_value_type>::type + __node_value_type_pointer; + typedef typename __rebind_pointer<_VoidPtr, const __node_value_type>::type + __const_node_value_type_pointer; +#if defined(_LIBCPP_ABI_TREE_REMOVE_NODE_POINTER_UB) + typedef typename __base::__end_node_pointer __iter_pointer; +#else + typedef typename conditional< + is_pointer<__node_pointer>::value, + typename __base::__end_node_pointer, + __node_pointer>::type __iter_pointer; +#endif +private: + static_assert(!is_const<__node_type>::value, + "_NodePtr should never be a pointer to const"); + static_assert((is_same<typename __rebind_pointer<_VoidPtr, __node_type>::type, + _NodePtr>::value), "_VoidPtr does not rebind to _NodePtr."); +}; + +template <class _ValueTp, class _VoidPtr> +struct __make_tree_node_types { + typedef typename __rebind_pointer<_VoidPtr, __tree_node<_ValueTp, _VoidPtr> >::type + _NodePtr; + typedef __tree_node_types<_NodePtr> type; +}; + +// node + +template <class _Pointer> +class __tree_end_node +{ +public: + typedef _Pointer pointer; + pointer __left_; + + _LIBCPP_INLINE_VISIBILITY + __tree_end_node() _NOEXCEPT : __left_() {} +}; + +template <class _VoidPtr> +class _LIBCPP_STANDALONE_DEBUG __tree_node_base + : public __tree_node_base_types<_VoidPtr>::__end_node_type +{ + typedef __tree_node_base_types<_VoidPtr> _NodeBaseTypes; + +public: + typedef typename _NodeBaseTypes::__node_base_pointer pointer; + typedef typename _NodeBaseTypes::__parent_pointer __parent_pointer; + + pointer __right_; + __parent_pointer __parent_; + bool __is_black_; + + _LIBCPP_INLINE_VISIBILITY + pointer __parent_unsafe() const { return static_cast<pointer>(__parent_);} + + _LIBCPP_INLINE_VISIBILITY + void __set_parent(pointer __p) { + __parent_ = static_cast<__parent_pointer>(__p); + } + +private: + ~__tree_node_base() = delete; + __tree_node_base(__tree_node_base const&) = delete; + __tree_node_base& operator=(__tree_node_base const&) = delete; +}; + +template <class _Tp, class _VoidPtr> +class _LIBCPP_STANDALONE_DEBUG __tree_node + : public __tree_node_base<_VoidPtr> +{ +public: + typedef _Tp __node_value_type; + + __node_value_type __value_; + +private: + ~__tree_node() = delete; + __tree_node(__tree_node const&) = delete; + __tree_node& operator=(__tree_node const&) = delete; +}; + + +template <class _Allocator> +class __tree_node_destructor +{ + typedef _Allocator allocator_type; + typedef allocator_traits<allocator_type> __alloc_traits; + +public: + typedef typename __alloc_traits::pointer pointer; +private: + typedef __tree_node_types<pointer> _NodeTypes; + allocator_type& __na_; + + +public: + bool __value_constructed; + + + __tree_node_destructor(const __tree_node_destructor &) = default; + __tree_node_destructor& operator=(const __tree_node_destructor&) = delete; + + _LIBCPP_INLINE_VISIBILITY + explicit __tree_node_destructor(allocator_type& __na, bool __val = false) _NOEXCEPT + : __na_(__na), + __value_constructed(__val) + {} + + _LIBCPP_INLINE_VISIBILITY + void operator()(pointer __p) _NOEXCEPT + { + if (__value_constructed) + __alloc_traits::destroy(__na_, _NodeTypes::__get_ptr(__p->__value_)); + if (__p) + __alloc_traits::deallocate(__na_, __p, 1); + } + + template <class> friend class __map_node_destructor; +}; + +#if _LIBCPP_STD_VER > 14 +template <class _NodeType, class _Alloc> +struct __generic_container_node_destructor; +template <class _Tp, class _VoidPtr, class _Alloc> +struct __generic_container_node_destructor<__tree_node<_Tp, _VoidPtr>, _Alloc> + : __tree_node_destructor<_Alloc> +{ + using __tree_node_destructor<_Alloc>::__tree_node_destructor; +}; +#endif + +template <class _Tp, class _NodePtr, class _DiffType> +class _LIBCPP_TEMPLATE_VIS __tree_iterator +{ + typedef __tree_node_types<_NodePtr> _NodeTypes; + typedef _NodePtr __node_pointer; + typedef typename _NodeTypes::__node_base_pointer __node_base_pointer; + typedef typename _NodeTypes::__end_node_pointer __end_node_pointer; + typedef typename _NodeTypes::__iter_pointer __iter_pointer; + typedef pointer_traits<__node_pointer> __pointer_traits; + + __iter_pointer __ptr_; + +public: + typedef bidirectional_iterator_tag iterator_category; + typedef _Tp value_type; + typedef _DiffType difference_type; + typedef value_type& reference; + typedef typename _NodeTypes::__node_value_type_pointer pointer; + + _LIBCPP_INLINE_VISIBILITY __tree_iterator() _NOEXCEPT +#if _LIBCPP_STD_VER > 11 + : __ptr_(nullptr) +#endif + {} + + _LIBCPP_INLINE_VISIBILITY reference operator*() const + {return __get_np()->__value_;} + _LIBCPP_INLINE_VISIBILITY pointer operator->() const + {return pointer_traits<pointer>::pointer_to(__get_np()->__value_);} + + _LIBCPP_INLINE_VISIBILITY + __tree_iterator& operator++() { + __ptr_ = static_cast<__iter_pointer>( + _VSTD::__tree_next_iter<__end_node_pointer>(static_cast<__node_base_pointer>(__ptr_))); + return *this; + } + _LIBCPP_INLINE_VISIBILITY + __tree_iterator operator++(int) + {__tree_iterator __t(*this); ++(*this); return __t;} + + _LIBCPP_INLINE_VISIBILITY + __tree_iterator& operator--() { + __ptr_ = static_cast<__iter_pointer>(_VSTD::__tree_prev_iter<__node_base_pointer>( + static_cast<__end_node_pointer>(__ptr_))); + return *this; + } + _LIBCPP_INLINE_VISIBILITY + __tree_iterator operator--(int) + {__tree_iterator __t(*this); --(*this); return __t;} + + friend _LIBCPP_INLINE_VISIBILITY + bool operator==(const __tree_iterator& __x, const __tree_iterator& __y) + {return __x.__ptr_ == __y.__ptr_;} + friend _LIBCPP_INLINE_VISIBILITY + bool operator!=(const __tree_iterator& __x, const __tree_iterator& __y) + {return !(__x == __y);} + +private: + _LIBCPP_INLINE_VISIBILITY + explicit __tree_iterator(__node_pointer __p) _NOEXCEPT : __ptr_(__p) {} + _LIBCPP_INLINE_VISIBILITY + explicit __tree_iterator(__end_node_pointer __p) _NOEXCEPT : __ptr_(__p) {} + _LIBCPP_INLINE_VISIBILITY + __node_pointer __get_np() const { return static_cast<__node_pointer>(__ptr_); } + template <class, class, class> friend class __tree; + template <class, class, class> friend class _LIBCPP_TEMPLATE_VIS __tree_const_iterator; + template <class> friend class _LIBCPP_TEMPLATE_VIS __map_iterator; + template <class, class, class, class> friend class _LIBCPP_TEMPLATE_VIS map; + template <class, class, class, class> friend class _LIBCPP_TEMPLATE_VIS multimap; + template <class, class, class> friend class _LIBCPP_TEMPLATE_VIS set; + template <class, class, class> friend class _LIBCPP_TEMPLATE_VIS multiset; +}; + +template <class _Tp, class _NodePtr, class _DiffType> +class _LIBCPP_TEMPLATE_VIS __tree_const_iterator +{ + typedef __tree_node_types<_NodePtr> _NodeTypes; + typedef typename _NodeTypes::__node_pointer __node_pointer; + typedef typename _NodeTypes::__node_base_pointer __node_base_pointer; + typedef typename _NodeTypes::__end_node_pointer __end_node_pointer; + typedef typename _NodeTypes::__iter_pointer __iter_pointer; + typedef pointer_traits<__node_pointer> __pointer_traits; + + __iter_pointer __ptr_; + +public: + typedef bidirectional_iterator_tag iterator_category; + typedef _Tp value_type; + typedef _DiffType difference_type; + typedef const value_type& reference; + typedef typename _NodeTypes::__const_node_value_type_pointer pointer; + + _LIBCPP_INLINE_VISIBILITY __tree_const_iterator() _NOEXCEPT +#if _LIBCPP_STD_VER > 11 + : __ptr_(nullptr) +#endif + {} + +private: + typedef __tree_iterator<value_type, __node_pointer, difference_type> + __non_const_iterator; +public: + _LIBCPP_INLINE_VISIBILITY + __tree_const_iterator(__non_const_iterator __p) _NOEXCEPT + : __ptr_(__p.__ptr_) {} + + _LIBCPP_INLINE_VISIBILITY reference operator*() const + {return __get_np()->__value_;} + _LIBCPP_INLINE_VISIBILITY pointer operator->() const + {return pointer_traits<pointer>::pointer_to(__get_np()->__value_);} + + _LIBCPP_INLINE_VISIBILITY + __tree_const_iterator& operator++() { + __ptr_ = static_cast<__iter_pointer>( + _VSTD::__tree_next_iter<__end_node_pointer>(static_cast<__node_base_pointer>(__ptr_))); + return *this; + } + + _LIBCPP_INLINE_VISIBILITY + __tree_const_iterator operator++(int) + {__tree_const_iterator __t(*this); ++(*this); return __t;} + + _LIBCPP_INLINE_VISIBILITY + __tree_const_iterator& operator--() { + __ptr_ = static_cast<__iter_pointer>(_VSTD::__tree_prev_iter<__node_base_pointer>( + static_cast<__end_node_pointer>(__ptr_))); + return *this; + } + + _LIBCPP_INLINE_VISIBILITY + __tree_const_iterator operator--(int) + {__tree_const_iterator __t(*this); --(*this); return __t;} + + friend _LIBCPP_INLINE_VISIBILITY + bool operator==(const __tree_const_iterator& __x, const __tree_const_iterator& __y) + {return __x.__ptr_ == __y.__ptr_;} + friend _LIBCPP_INLINE_VISIBILITY + bool operator!=(const __tree_const_iterator& __x, const __tree_const_iterator& __y) + {return !(__x == __y);} + +private: + _LIBCPP_INLINE_VISIBILITY + explicit __tree_const_iterator(__node_pointer __p) _NOEXCEPT + : __ptr_(__p) {} + _LIBCPP_INLINE_VISIBILITY + explicit __tree_const_iterator(__end_node_pointer __p) _NOEXCEPT + : __ptr_(__p) {} + _LIBCPP_INLINE_VISIBILITY + __node_pointer __get_np() const { return static_cast<__node_pointer>(__ptr_); } + + template <class, class, class> friend class __tree; + template <class, class, class, class> friend class _LIBCPP_TEMPLATE_VIS map; + template <class, class, class, class> friend class _LIBCPP_TEMPLATE_VIS multimap; + template <class, class, class> friend class _LIBCPP_TEMPLATE_VIS set; + template <class, class, class> friend class _LIBCPP_TEMPLATE_VIS multiset; + template <class> friend class _LIBCPP_TEMPLATE_VIS __map_const_iterator; + +}; + +template<class _Tp, class _Compare> +#ifndef _LIBCPP_CXX03_LANG + _LIBCPP_DIAGNOSE_WARNING(!__invokable<_Compare const&, _Tp const&, _Tp const&>::value, + "the specified comparator type does not provide a viable const call operator") +#endif +int __diagnose_non_const_comparator(); + +template <class _Tp, class _Compare, class _Allocator> +class __tree +{ +public: + typedef _Tp value_type; + typedef _Compare value_compare; + typedef _Allocator allocator_type; + +private: + typedef allocator_traits<allocator_type> __alloc_traits; + typedef typename __make_tree_node_types<value_type, + typename __alloc_traits::void_pointer>::type + _NodeTypes; + typedef typename _NodeTypes::key_type key_type; +public: + typedef typename _NodeTypes::__node_value_type __node_value_type; + typedef typename _NodeTypes::__container_value_type __container_value_type; + + typedef typename __alloc_traits::pointer pointer; + typedef typename __alloc_traits::const_pointer const_pointer; + typedef typename __alloc_traits::size_type size_type; + typedef typename __alloc_traits::difference_type difference_type; + +public: + typedef typename _NodeTypes::__void_pointer __void_pointer; + + typedef typename _NodeTypes::__node_type __node; + typedef typename _NodeTypes::__node_pointer __node_pointer; + + typedef typename _NodeTypes::__node_base_type __node_base; + typedef typename _NodeTypes::__node_base_pointer __node_base_pointer; + + typedef typename _NodeTypes::__end_node_type __end_node_t; + typedef typename _NodeTypes::__end_node_pointer __end_node_ptr; + + typedef typename _NodeTypes::__parent_pointer __parent_pointer; + typedef typename _NodeTypes::__iter_pointer __iter_pointer; + + typedef typename __rebind_alloc_helper<__alloc_traits, __node>::type __node_allocator; + typedef allocator_traits<__node_allocator> __node_traits; + +private: + // check for sane allocator pointer rebinding semantics. Rebinding the + // allocator for a new pointer type should be exactly the same as rebinding + // the pointer using 'pointer_traits'. + static_assert((is_same<__node_pointer, typename __node_traits::pointer>::value), + "Allocator does not rebind pointers in a sane manner."); + typedef typename __rebind_alloc_helper<__node_traits, __node_base>::type + __node_base_allocator; + typedef allocator_traits<__node_base_allocator> __node_base_traits; + static_assert((is_same<__node_base_pointer, typename __node_base_traits::pointer>::value), + "Allocator does not rebind pointers in a sane manner."); + +private: + __iter_pointer __begin_node_; + __compressed_pair<__end_node_t, __node_allocator> __pair1_; + __compressed_pair<size_type, value_compare> __pair3_; + +public: + _LIBCPP_INLINE_VISIBILITY + __iter_pointer __end_node() _NOEXCEPT + { + return static_cast<__iter_pointer>( + pointer_traits<__end_node_ptr>::pointer_to(__pair1_.first()) + ); + } + _LIBCPP_INLINE_VISIBILITY + __iter_pointer __end_node() const _NOEXCEPT + { + return static_cast<__iter_pointer>( + pointer_traits<__end_node_ptr>::pointer_to( + const_cast<__end_node_t&>(__pair1_.first()) + ) + ); + } + _LIBCPP_INLINE_VISIBILITY + __node_allocator& __node_alloc() _NOEXCEPT {return __pair1_.second();} +private: + _LIBCPP_INLINE_VISIBILITY + const __node_allocator& __node_alloc() const _NOEXCEPT + {return __pair1_.second();} + _LIBCPP_INLINE_VISIBILITY + __iter_pointer& __begin_node() _NOEXCEPT {return __begin_node_;} + _LIBCPP_INLINE_VISIBILITY + const __iter_pointer& __begin_node() const _NOEXCEPT {return __begin_node_;} +public: + _LIBCPP_INLINE_VISIBILITY + allocator_type __alloc() const _NOEXCEPT + {return allocator_type(__node_alloc());} +private: + _LIBCPP_INLINE_VISIBILITY + size_type& size() _NOEXCEPT {return __pair3_.first();} +public: + _LIBCPP_INLINE_VISIBILITY + const size_type& size() const _NOEXCEPT {return __pair3_.first();} + _LIBCPP_INLINE_VISIBILITY + value_compare& value_comp() _NOEXCEPT {return __pair3_.second();} + _LIBCPP_INLINE_VISIBILITY + const value_compare& value_comp() const _NOEXCEPT + {return __pair3_.second();} +public: + + _LIBCPP_INLINE_VISIBILITY + __node_pointer __root() const _NOEXCEPT + {return static_cast<__node_pointer>(__end_node()->__left_);} + + __node_base_pointer* __root_ptr() const _NOEXCEPT { + return _VSTD::addressof(__end_node()->__left_); + } + + typedef __tree_iterator<value_type, __node_pointer, difference_type> iterator; + typedef __tree_const_iterator<value_type, __node_pointer, difference_type> const_iterator; + + explicit __tree(const value_compare& __comp) + _NOEXCEPT_( + is_nothrow_default_constructible<__node_allocator>::value && + is_nothrow_copy_constructible<value_compare>::value); + explicit __tree(const allocator_type& __a); + __tree(const value_compare& __comp, const allocator_type& __a); + __tree(const __tree& __t); + __tree& operator=(const __tree& __t); + template <class _ForwardIterator> + void __assign_unique(_ForwardIterator __first, _ForwardIterator __last); + template <class _InputIterator> + void __assign_multi(_InputIterator __first, _InputIterator __last); + __tree(__tree&& __t) + _NOEXCEPT_( + is_nothrow_move_constructible<__node_allocator>::value && + is_nothrow_move_constructible<value_compare>::value); + __tree(__tree&& __t, const allocator_type& __a); + __tree& operator=(__tree&& __t) + _NOEXCEPT_( + __node_traits::propagate_on_container_move_assignment::value && + is_nothrow_move_assignable<value_compare>::value && + is_nothrow_move_assignable<__node_allocator>::value); + ~__tree(); + + _LIBCPP_INLINE_VISIBILITY + iterator begin() _NOEXCEPT {return iterator(__begin_node());} + _LIBCPP_INLINE_VISIBILITY + const_iterator begin() const _NOEXCEPT {return const_iterator(__begin_node());} + _LIBCPP_INLINE_VISIBILITY + iterator end() _NOEXCEPT {return iterator(__end_node());} + _LIBCPP_INLINE_VISIBILITY + const_iterator end() const _NOEXCEPT {return const_iterator(__end_node());} + + _LIBCPP_INLINE_VISIBILITY + size_type max_size() const _NOEXCEPT + {return _VSTD::min<size_type>( + __node_traits::max_size(__node_alloc()), + numeric_limits<difference_type >::max());} + + void clear() _NOEXCEPT; + + void swap(__tree& __t) +#if _LIBCPP_STD_VER <= 11 + _NOEXCEPT_( + __is_nothrow_swappable<value_compare>::value + && (!__node_traits::propagate_on_container_swap::value || + __is_nothrow_swappable<__node_allocator>::value) + ); +#else + _NOEXCEPT_(__is_nothrow_swappable<value_compare>::value); +#endif + + template <class _Key, class ..._Args> + pair<iterator, bool> + __emplace_unique_key_args(_Key const&, _Args&&... __args); + template <class _Key, class ..._Args> + pair<iterator, bool> + __emplace_hint_unique_key_args(const_iterator, _Key const&, _Args&&...); + + template <class... _Args> + pair<iterator, bool> __emplace_unique_impl(_Args&&... __args); + + template <class... _Args> + iterator __emplace_hint_unique_impl(const_iterator __p, _Args&&... __args); + + template <class... _Args> + iterator __emplace_multi(_Args&&... __args); + + template <class... _Args> + iterator __emplace_hint_multi(const_iterator __p, _Args&&... __args); + + template <class _Pp> + _LIBCPP_INLINE_VISIBILITY + pair<iterator, bool> __emplace_unique(_Pp&& __x) { + return __emplace_unique_extract_key(_VSTD::forward<_Pp>(__x), + __can_extract_key<_Pp, key_type>()); + } + + template <class _First, class _Second> + _LIBCPP_INLINE_VISIBILITY + typename enable_if< + __can_extract_map_key<_First, key_type, __container_value_type>::value, + pair<iterator, bool> + >::type __emplace_unique(_First&& __f, _Second&& __s) { + return __emplace_unique_key_args(__f, _VSTD::forward<_First>(__f), + _VSTD::forward<_Second>(__s)); + } + + template <class... _Args> + _LIBCPP_INLINE_VISIBILITY + pair<iterator, bool> __emplace_unique(_Args&&... __args) { + return __emplace_unique_impl(_VSTD::forward<_Args>(__args)...); + } + + template <class _Pp> + _LIBCPP_INLINE_VISIBILITY + pair<iterator, bool> + __emplace_unique_extract_key(_Pp&& __x, __extract_key_fail_tag) { + return __emplace_unique_impl(_VSTD::forward<_Pp>(__x)); + } + + template <class _Pp> + _LIBCPP_INLINE_VISIBILITY + pair<iterator, bool> + __emplace_unique_extract_key(_Pp&& __x, __extract_key_self_tag) { + return __emplace_unique_key_args(__x, _VSTD::forward<_Pp>(__x)); + } + + template <class _Pp> + _LIBCPP_INLINE_VISIBILITY + pair<iterator, bool> + __emplace_unique_extract_key(_Pp&& __x, __extract_key_first_tag) { + return __emplace_unique_key_args(__x.first, _VSTD::forward<_Pp>(__x)); + } + + template <class _Pp> + _LIBCPP_INLINE_VISIBILITY + iterator __emplace_hint_unique(const_iterator __p, _Pp&& __x) { + return __emplace_hint_unique_extract_key(__p, _VSTD::forward<_Pp>(__x), + __can_extract_key<_Pp, key_type>()); + } + + template <class _First, class _Second> + _LIBCPP_INLINE_VISIBILITY + typename enable_if< + __can_extract_map_key<_First, key_type, __container_value_type>::value, + iterator + >::type __emplace_hint_unique(const_iterator __p, _First&& __f, _Second&& __s) { + return __emplace_hint_unique_key_args(__p, __f, + _VSTD::forward<_First>(__f), + _VSTD::forward<_Second>(__s)).first; + } + + template <class... _Args> + _LIBCPP_INLINE_VISIBILITY + iterator __emplace_hint_unique(const_iterator __p, _Args&&... __args) { + return __emplace_hint_unique_impl(__p, _VSTD::forward<_Args>(__args)...); + } + + template <class _Pp> + _LIBCPP_INLINE_VISIBILITY + iterator + __emplace_hint_unique_extract_key(const_iterator __p, _Pp&& __x, __extract_key_fail_tag) { + return __emplace_hint_unique_impl(__p, _VSTD::forward<_Pp>(__x)); + } + + template <class _Pp> + _LIBCPP_INLINE_VISIBILITY + iterator + __emplace_hint_unique_extract_key(const_iterator __p, _Pp&& __x, __extract_key_self_tag) { + return __emplace_hint_unique_key_args(__p, __x, _VSTD::forward<_Pp>(__x)).first; + } + + template <class _Pp> + _LIBCPP_INLINE_VISIBILITY + iterator + __emplace_hint_unique_extract_key(const_iterator __p, _Pp&& __x, __extract_key_first_tag) { + return __emplace_hint_unique_key_args(__p, __x.first, _VSTD::forward<_Pp>(__x)).first; + } + + _LIBCPP_INLINE_VISIBILITY + pair<iterator, bool> __insert_unique(const __container_value_type& __v) { + return __emplace_unique_key_args(_NodeTypes::__get_key(__v), __v); + } + + _LIBCPP_INLINE_VISIBILITY + iterator __insert_unique(const_iterator __p, const __container_value_type& __v) { + return __emplace_hint_unique_key_args(__p, _NodeTypes::__get_key(__v), __v).first; + } + + _LIBCPP_INLINE_VISIBILITY + pair<iterator, bool> __insert_unique(__container_value_type&& __v) { + return __emplace_unique_key_args(_NodeTypes::__get_key(__v), _VSTD::move(__v)); + } + + _LIBCPP_INLINE_VISIBILITY + iterator __insert_unique(const_iterator __p, __container_value_type&& __v) { + return __emplace_hint_unique_key_args(__p, _NodeTypes::__get_key(__v), _VSTD::move(__v)).first; + } + + template <class _Vp, class = typename enable_if< + !is_same<typename __unconstref<_Vp>::type, + __container_value_type + >::value + >::type> + _LIBCPP_INLINE_VISIBILITY + pair<iterator, bool> __insert_unique(_Vp&& __v) { + return __emplace_unique(_VSTD::forward<_Vp>(__v)); + } + + template <class _Vp, class = typename enable_if< + !is_same<typename __unconstref<_Vp>::type, + __container_value_type + >::value + >::type> + _LIBCPP_INLINE_VISIBILITY + iterator __insert_unique(const_iterator __p, _Vp&& __v) { + return __emplace_hint_unique(__p, _VSTD::forward<_Vp>(__v)); + } + + _LIBCPP_INLINE_VISIBILITY + iterator __insert_multi(__container_value_type&& __v) { + return __emplace_multi(_VSTD::move(__v)); + } + + _LIBCPP_INLINE_VISIBILITY + iterator __insert_multi(const_iterator __p, __container_value_type&& __v) { + return __emplace_hint_multi(__p, _VSTD::move(__v)); + } + + template <class _Vp> + _LIBCPP_INLINE_VISIBILITY + iterator __insert_multi(_Vp&& __v) { + return __emplace_multi(_VSTD::forward<_Vp>(__v)); + } + + template <class _Vp> + _LIBCPP_INLINE_VISIBILITY + iterator __insert_multi(const_iterator __p, _Vp&& __v) { + return __emplace_hint_multi(__p, _VSTD::forward<_Vp>(__v)); + } + + _LIBCPP_INLINE_VISIBILITY + pair<iterator, bool> __node_assign_unique(const __container_value_type& __v, __node_pointer __dest); + + _LIBCPP_INLINE_VISIBILITY + iterator __node_insert_multi(__node_pointer __nd); + _LIBCPP_INLINE_VISIBILITY + iterator __node_insert_multi(const_iterator __p, __node_pointer __nd); + + + _LIBCPP_INLINE_VISIBILITY iterator + __remove_node_pointer(__node_pointer) _NOEXCEPT; + +#if _LIBCPP_STD_VER > 14 + template <class _NodeHandle, class _InsertReturnType> + _LIBCPP_INLINE_VISIBILITY + _InsertReturnType __node_handle_insert_unique(_NodeHandle&&); + template <class _NodeHandle> + _LIBCPP_INLINE_VISIBILITY + iterator __node_handle_insert_unique(const_iterator, _NodeHandle&&); + template <class _Tree> + _LIBCPP_INLINE_VISIBILITY + void __node_handle_merge_unique(_Tree& __source); + + template <class _NodeHandle> + _LIBCPP_INLINE_VISIBILITY + iterator __node_handle_insert_multi(_NodeHandle&&); + template <class _NodeHandle> + _LIBCPP_INLINE_VISIBILITY + iterator __node_handle_insert_multi(const_iterator, _NodeHandle&&); + template <class _Tree> + _LIBCPP_INLINE_VISIBILITY + void __node_handle_merge_multi(_Tree& __source); + + + template <class _NodeHandle> + _LIBCPP_INLINE_VISIBILITY + _NodeHandle __node_handle_extract(key_type const&); + template <class _NodeHandle> + _LIBCPP_INLINE_VISIBILITY + _NodeHandle __node_handle_extract(const_iterator); +#endif + + iterator erase(const_iterator __p); + iterator erase(const_iterator __f, const_iterator __l); + template <class _Key> + size_type __erase_unique(const _Key& __k); + template <class _Key> + size_type __erase_multi(const _Key& __k); + + void __insert_node_at(__parent_pointer __parent, + __node_base_pointer& __child, + __node_base_pointer __new_node) _NOEXCEPT; + + template <class _Key> + iterator find(const _Key& __v); + template <class _Key> + const_iterator find(const _Key& __v) const; + + template <class _Key> + size_type __count_unique(const _Key& __k) const; + template <class _Key> + size_type __count_multi(const _Key& __k) const; + + template <class _Key> + _LIBCPP_INLINE_VISIBILITY + iterator lower_bound(const _Key& __v) + {return __lower_bound(__v, __root(), __end_node());} + template <class _Key> + iterator __lower_bound(const _Key& __v, + __node_pointer __root, + __iter_pointer __result); + template <class _Key> + _LIBCPP_INLINE_VISIBILITY + const_iterator lower_bound(const _Key& __v) const + {return __lower_bound(__v, __root(), __end_node());} + template <class _Key> + const_iterator __lower_bound(const _Key& __v, + __node_pointer __root, + __iter_pointer __result) const; + template <class _Key> + _LIBCPP_INLINE_VISIBILITY + iterator upper_bound(const _Key& __v) + {return __upper_bound(__v, __root(), __end_node());} + template <class _Key> + iterator __upper_bound(const _Key& __v, + __node_pointer __root, + __iter_pointer __result); + template <class _Key> + _LIBCPP_INLINE_VISIBILITY + const_iterator upper_bound(const _Key& __v) const + {return __upper_bound(__v, __root(), __end_node());} + template <class _Key> + const_iterator __upper_bound(const _Key& __v, + __node_pointer __root, + __iter_pointer __result) const; + template <class _Key> + pair<iterator, iterator> + __equal_range_unique(const _Key& __k); + template <class _Key> + pair<const_iterator, const_iterator> + __equal_range_unique(const _Key& __k) const; + + template <class _Key> + pair<iterator, iterator> + __equal_range_multi(const _Key& __k); + template <class _Key> + pair<const_iterator, const_iterator> + __equal_range_multi(const _Key& __k) const; + + typedef __tree_node_destructor<__node_allocator> _Dp; + typedef unique_ptr<__node, _Dp> __node_holder; + + __node_holder remove(const_iterator __p) _NOEXCEPT; +private: + __node_base_pointer& + __find_leaf_low(__parent_pointer& __parent, const key_type& __v); + __node_base_pointer& + __find_leaf_high(__parent_pointer& __parent, const key_type& __v); + __node_base_pointer& + __find_leaf(const_iterator __hint, + __parent_pointer& __parent, const key_type& __v); + // FIXME: Make this function const qualified. Unfortunately doing so + // breaks existing code which uses non-const callable comparators. + template <class _Key> + __node_base_pointer& + __find_equal(__parent_pointer& __parent, const _Key& __v); + template <class _Key> + _LIBCPP_INLINE_VISIBILITY __node_base_pointer& + __find_equal(__parent_pointer& __parent, const _Key& __v) const { + return const_cast<__tree*>(this)->__find_equal(__parent, __v); + } + template <class _Key> + __node_base_pointer& + __find_equal(const_iterator __hint, __parent_pointer& __parent, + __node_base_pointer& __dummy, + const _Key& __v); + + template <class ..._Args> + __node_holder __construct_node(_Args&& ...__args); + + void destroy(__node_pointer __nd) _NOEXCEPT; + + _LIBCPP_INLINE_VISIBILITY + void __copy_assign_alloc(const __tree& __t) + {__copy_assign_alloc(__t, integral_constant<bool, + __node_traits::propagate_on_container_copy_assignment::value>());} + + _LIBCPP_INLINE_VISIBILITY + void __copy_assign_alloc(const __tree& __t, true_type) + { + if (__node_alloc() != __t.__node_alloc()) + clear(); + __node_alloc() = __t.__node_alloc(); + } + _LIBCPP_INLINE_VISIBILITY + void __copy_assign_alloc(const __tree&, false_type) {} + + void __move_assign(__tree& __t, false_type); + void __move_assign(__tree& __t, true_type) + _NOEXCEPT_(is_nothrow_move_assignable<value_compare>::value && + is_nothrow_move_assignable<__node_allocator>::value); + + _LIBCPP_INLINE_VISIBILITY + void __move_assign_alloc(__tree& __t) + _NOEXCEPT_( + !__node_traits::propagate_on_container_move_assignment::value || + is_nothrow_move_assignable<__node_allocator>::value) + {__move_assign_alloc(__t, integral_constant<bool, + __node_traits::propagate_on_container_move_assignment::value>());} + + _LIBCPP_INLINE_VISIBILITY + void __move_assign_alloc(__tree& __t, true_type) + _NOEXCEPT_(is_nothrow_move_assignable<__node_allocator>::value) + {__node_alloc() = _VSTD::move(__t.__node_alloc());} + _LIBCPP_INLINE_VISIBILITY + void __move_assign_alloc(__tree&, false_type) _NOEXCEPT {} + + struct _DetachedTreeCache { + _LIBCPP_INLINE_VISIBILITY + explicit _DetachedTreeCache(__tree *__t) _NOEXCEPT : __t_(__t), + __cache_root_(__detach_from_tree(__t)) { + __advance(); + } + + _LIBCPP_INLINE_VISIBILITY + __node_pointer __get() const _NOEXCEPT { + return __cache_elem_; + } + + _LIBCPP_INLINE_VISIBILITY + void __advance() _NOEXCEPT { + __cache_elem_ = __cache_root_; + if (__cache_root_) { + __cache_root_ = __detach_next(__cache_root_); + } + } + + _LIBCPP_INLINE_VISIBILITY + ~_DetachedTreeCache() { + __t_->destroy(__cache_elem_); + if (__cache_root_) { + while (__cache_root_->__parent_ != nullptr) + __cache_root_ = static_cast<__node_pointer>(__cache_root_->__parent_); + __t_->destroy(__cache_root_); + } + } + + _DetachedTreeCache(_DetachedTreeCache const&) = delete; + _DetachedTreeCache& operator=(_DetachedTreeCache const&) = delete; + + private: + _LIBCPP_INLINE_VISIBILITY + static __node_pointer __detach_from_tree(__tree *__t) _NOEXCEPT; + _LIBCPP_INLINE_VISIBILITY + static __node_pointer __detach_next(__node_pointer) _NOEXCEPT; + + __tree *__t_; + __node_pointer __cache_root_; + __node_pointer __cache_elem_; + }; + + + template <class, class, class, class> friend class _LIBCPP_TEMPLATE_VIS map; + template <class, class, class, class> friend class _LIBCPP_TEMPLATE_VIS multimap; +}; + +template <class _Tp, class _Compare, class _Allocator> +__tree<_Tp, _Compare, _Allocator>::__tree(const value_compare& __comp) + _NOEXCEPT_( + is_nothrow_default_constructible<__node_allocator>::value && + is_nothrow_copy_constructible<value_compare>::value) + : __pair3_(0, __comp) +{ + __begin_node() = __end_node(); +} + +template <class _Tp, class _Compare, class _Allocator> +__tree<_Tp, _Compare, _Allocator>::__tree(const allocator_type& __a) + : __begin_node_(__iter_pointer()), + __pair1_(__default_init_tag(), __node_allocator(__a)), + __pair3_(0, __default_init_tag()) +{ + __begin_node() = __end_node(); +} + +template <class _Tp, class _Compare, class _Allocator> +__tree<_Tp, _Compare, _Allocator>::__tree(const value_compare& __comp, + const allocator_type& __a) + : __begin_node_(__iter_pointer()), + __pair1_(__default_init_tag(), __node_allocator(__a)), + __pair3_(0, __comp) +{ + __begin_node() = __end_node(); +} + +// Precondition: size() != 0 +template <class _Tp, class _Compare, class _Allocator> +typename __tree<_Tp, _Compare, _Allocator>::__node_pointer +__tree<_Tp, _Compare, _Allocator>::_DetachedTreeCache::__detach_from_tree(__tree *__t) _NOEXCEPT +{ + __node_pointer __cache = static_cast<__node_pointer>(__t->__begin_node()); + __t->__begin_node() = __t->__end_node(); + __t->__end_node()->__left_->__parent_ = nullptr; + __t->__end_node()->__left_ = nullptr; + __t->size() = 0; + // __cache->__left_ == nullptr + if (__cache->__right_ != nullptr) + __cache = static_cast<__node_pointer>(__cache->__right_); + // __cache->__left_ == nullptr + // __cache->__right_ == nullptr + return __cache; +} + +// Precondition: __cache != nullptr +// __cache->left_ == nullptr +// __cache->right_ == nullptr +// This is no longer a red-black tree +template <class _Tp, class _Compare, class _Allocator> +typename __tree<_Tp, _Compare, _Allocator>::__node_pointer +__tree<_Tp, _Compare, _Allocator>::_DetachedTreeCache::__detach_next(__node_pointer __cache) _NOEXCEPT +{ + if (__cache->__parent_ == nullptr) + return nullptr; + if (_VSTD::__tree_is_left_child(static_cast<__node_base_pointer>(__cache))) + { + __cache->__parent_->__left_ = nullptr; + __cache = static_cast<__node_pointer>(__cache->__parent_); + if (__cache->__right_ == nullptr) + return __cache; + return static_cast<__node_pointer>(_VSTD::__tree_leaf(__cache->__right_)); + } + // __cache is right child + __cache->__parent_unsafe()->__right_ = nullptr; + __cache = static_cast<__node_pointer>(__cache->__parent_); + if (__cache->__left_ == nullptr) + return __cache; + return static_cast<__node_pointer>(_VSTD::__tree_leaf(__cache->__left_)); +} + +template <class _Tp, class _Compare, class _Allocator> +__tree<_Tp, _Compare, _Allocator>& +__tree<_Tp, _Compare, _Allocator>::operator=(const __tree& __t) +{ + if (this != _VSTD::addressof(__t)) + { + value_comp() = __t.value_comp(); + __copy_assign_alloc(__t); + __assign_multi(__t.begin(), __t.end()); + } + return *this; +} + +template <class _Tp, class _Compare, class _Allocator> +template <class _ForwardIterator> +void +__tree<_Tp, _Compare, _Allocator>::__assign_unique(_ForwardIterator __first, _ForwardIterator __last) +{ + typedef iterator_traits<_ForwardIterator> _ITraits; + typedef typename _ITraits::value_type _ItValueType; + static_assert((is_same<_ItValueType, __container_value_type>::value), + "__assign_unique may only be called with the containers value type"); + static_assert(__is_cpp17_forward_iterator<_ForwardIterator>::value, + "__assign_unique requires a forward iterator"); + if (size() != 0) + { + _DetachedTreeCache __cache(this); + for (; __cache.__get() != nullptr && __first != __last; ++__first) { + if (__node_assign_unique(*__first, __cache.__get()).second) + __cache.__advance(); + } + } + for (; __first != __last; ++__first) + __insert_unique(*__first); +} + +template <class _Tp, class _Compare, class _Allocator> +template <class _InputIterator> +void +__tree<_Tp, _Compare, _Allocator>::__assign_multi(_InputIterator __first, _InputIterator __last) +{ + typedef iterator_traits<_InputIterator> _ITraits; + typedef typename _ITraits::value_type _ItValueType; + static_assert((is_same<_ItValueType, __container_value_type>::value || + is_same<_ItValueType, __node_value_type>::value), + "__assign_multi may only be called with the containers value type" + " or the nodes value type"); + if (size() != 0) + { + _DetachedTreeCache __cache(this); + for (; __cache.__get() && __first != __last; ++__first) { + __cache.__get()->__value_ = *__first; + __node_insert_multi(__cache.__get()); + __cache.__advance(); + } + } + for (; __first != __last; ++__first) + __insert_multi(_NodeTypes::__get_value(*__first)); +} + +template <class _Tp, class _Compare, class _Allocator> +__tree<_Tp, _Compare, _Allocator>::__tree(const __tree& __t) + : __begin_node_(__iter_pointer()), + __pair1_(__default_init_tag(), __node_traits::select_on_container_copy_construction(__t.__node_alloc())), + __pair3_(0, __t.value_comp()) +{ + __begin_node() = __end_node(); +} + +template <class _Tp, class _Compare, class _Allocator> +__tree<_Tp, _Compare, _Allocator>::__tree(__tree&& __t) + _NOEXCEPT_( + is_nothrow_move_constructible<__node_allocator>::value && + is_nothrow_move_constructible<value_compare>::value) + : __begin_node_(_VSTD::move(__t.__begin_node_)), + __pair1_(_VSTD::move(__t.__pair1_)), + __pair3_(_VSTD::move(__t.__pair3_)) +{ + if (size() == 0) + __begin_node() = __end_node(); + else + { + __end_node()->__left_->__parent_ = static_cast<__parent_pointer>(__end_node()); + __t.__begin_node() = __t.__end_node(); + __t.__end_node()->__left_ = nullptr; + __t.size() = 0; + } +} + +template <class _Tp, class _Compare, class _Allocator> +__tree<_Tp, _Compare, _Allocator>::__tree(__tree&& __t, const allocator_type& __a) + : __pair1_(__default_init_tag(), __node_allocator(__a)), + __pair3_(0, _VSTD::move(__t.value_comp())) +{ + if (__a == __t.__alloc()) + { + if (__t.size() == 0) + __begin_node() = __end_node(); + else + { + __begin_node() = __t.__begin_node(); + __end_node()->__left_ = __t.__end_node()->__left_; + __end_node()->__left_->__parent_ = static_cast<__parent_pointer>(__end_node()); + size() = __t.size(); + __t.__begin_node() = __t.__end_node(); + __t.__end_node()->__left_ = nullptr; + __t.size() = 0; + } + } + else + { + __begin_node() = __end_node(); + } +} + +template <class _Tp, class _Compare, class _Allocator> +void +__tree<_Tp, _Compare, _Allocator>::__move_assign(__tree& __t, true_type) + _NOEXCEPT_(is_nothrow_move_assignable<value_compare>::value && + is_nothrow_move_assignable<__node_allocator>::value) +{ + destroy(static_cast<__node_pointer>(__end_node()->__left_)); + __begin_node_ = __t.__begin_node_; + __pair1_.first() = __t.__pair1_.first(); + __move_assign_alloc(__t); + __pair3_ = _VSTD::move(__t.__pair3_); + if (size() == 0) + __begin_node() = __end_node(); + else + { + __end_node()->__left_->__parent_ = static_cast<__parent_pointer>(__end_node()); + __t.__begin_node() = __t.__end_node(); + __t.__end_node()->__left_ = nullptr; + __t.size() = 0; + } +} + +template <class _Tp, class _Compare, class _Allocator> +void +__tree<_Tp, _Compare, _Allocator>::__move_assign(__tree& __t, false_type) +{ + if (__node_alloc() == __t.__node_alloc()) + __move_assign(__t, true_type()); + else + { + value_comp() = _VSTD::move(__t.value_comp()); + const_iterator __e = end(); + if (size() != 0) + { + _DetachedTreeCache __cache(this); + while (__cache.__get() != nullptr && __t.size() != 0) { + __cache.__get()->__value_ = _VSTD::move(__t.remove(__t.begin())->__value_); + __node_insert_multi(__cache.__get()); + __cache.__advance(); + } + } + while (__t.size() != 0) + __insert_multi(__e, _NodeTypes::__move(__t.remove(__t.begin())->__value_)); + } +} + +template <class _Tp, class _Compare, class _Allocator> +__tree<_Tp, _Compare, _Allocator>& +__tree<_Tp, _Compare, _Allocator>::operator=(__tree&& __t) + _NOEXCEPT_( + __node_traits::propagate_on_container_move_assignment::value && + is_nothrow_move_assignable<value_compare>::value && + is_nothrow_move_assignable<__node_allocator>::value) + +{ + __move_assign(__t, integral_constant<bool, + __node_traits::propagate_on_container_move_assignment::value>()); + return *this; +} + +template <class _Tp, class _Compare, class _Allocator> +__tree<_Tp, _Compare, _Allocator>::~__tree() +{ + static_assert((is_copy_constructible<value_compare>::value), + "Comparator must be copy-constructible."); + destroy(__root()); +} + +template <class _Tp, class _Compare, class _Allocator> +void +__tree<_Tp, _Compare, _Allocator>::destroy(__node_pointer __nd) _NOEXCEPT +{ + if (__nd != nullptr) + { + destroy(static_cast<__node_pointer>(__nd->__left_)); + destroy(static_cast<__node_pointer>(__nd->__right_)); + __node_allocator& __na = __node_alloc(); + __node_traits::destroy(__na, _NodeTypes::__get_ptr(__nd->__value_)); + __node_traits::deallocate(__na, __nd, 1); + } +} + +template <class _Tp, class _Compare, class _Allocator> +void +__tree<_Tp, _Compare, _Allocator>::swap(__tree& __t) +#if _LIBCPP_STD_VER <= 11 + _NOEXCEPT_( + __is_nothrow_swappable<value_compare>::value + && (!__node_traits::propagate_on_container_swap::value || + __is_nothrow_swappable<__node_allocator>::value) + ) +#else + _NOEXCEPT_(__is_nothrow_swappable<value_compare>::value) +#endif +{ + using _VSTD::swap; + swap(__begin_node_, __t.__begin_node_); + swap(__pair1_.first(), __t.__pair1_.first()); + _VSTD::__swap_allocator(__node_alloc(), __t.__node_alloc()); + __pair3_.swap(__t.__pair3_); + if (size() == 0) + __begin_node() = __end_node(); + else + __end_node()->__left_->__parent_ = static_cast<__parent_pointer>(__end_node()); + if (__t.size() == 0) + __t.__begin_node() = __t.__end_node(); + else + __t.__end_node()->__left_->__parent_ = static_cast<__parent_pointer>(__t.__end_node()); +} + +template <class _Tp, class _Compare, class _Allocator> +void +__tree<_Tp, _Compare, _Allocator>::clear() _NOEXCEPT +{ + destroy(__root()); + size() = 0; + __begin_node() = __end_node(); + __end_node()->__left_ = nullptr; +} + +// Find lower_bound place to insert +// Set __parent to parent of null leaf +// Return reference to null leaf +template <class _Tp, class _Compare, class _Allocator> +typename __tree<_Tp, _Compare, _Allocator>::__node_base_pointer& +__tree<_Tp, _Compare, _Allocator>::__find_leaf_low(__parent_pointer& __parent, + const key_type& __v) +{ + __node_pointer __nd = __root(); + if (__nd != nullptr) + { + while (true) + { + if (value_comp()(__nd->__value_, __v)) + { + if (__nd->__right_ != nullptr) + __nd = static_cast<__node_pointer>(__nd->__right_); + else + { + __parent = static_cast<__parent_pointer>(__nd); + return __nd->__right_; + } + } + else + { + if (__nd->__left_ != nullptr) + __nd = static_cast<__node_pointer>(__nd->__left_); + else + { + __parent = static_cast<__parent_pointer>(__nd); + return __parent->__left_; + } + } + } + } + __parent = static_cast<__parent_pointer>(__end_node()); + return __parent->__left_; +} + +// Find upper_bound place to insert +// Set __parent to parent of null leaf +// Return reference to null leaf +template <class _Tp, class _Compare, class _Allocator> +typename __tree<_Tp, _Compare, _Allocator>::__node_base_pointer& +__tree<_Tp, _Compare, _Allocator>::__find_leaf_high(__parent_pointer& __parent, + const key_type& __v) +{ + __node_pointer __nd = __root(); + if (__nd != nullptr) + { + while (true) + { + if (value_comp()(__v, __nd->__value_)) + { + if (__nd->__left_ != nullptr) + __nd = static_cast<__node_pointer>(__nd->__left_); + else + { + __parent = static_cast<__parent_pointer>(__nd); + return __parent->__left_; + } + } + else + { + if (__nd->__right_ != nullptr) + __nd = static_cast<__node_pointer>(__nd->__right_); + else + { + __parent = static_cast<__parent_pointer>(__nd); + return __nd->__right_; + } + } + } + } + __parent = static_cast<__parent_pointer>(__end_node()); + return __parent->__left_; +} + +// Find leaf place to insert closest to __hint +// First check prior to __hint. +// Next check after __hint. +// Next do O(log N) search. +// Set __parent to parent of null leaf +// Return reference to null leaf +template <class _Tp, class _Compare, class _Allocator> +typename __tree<_Tp, _Compare, _Allocator>::__node_base_pointer& +__tree<_Tp, _Compare, _Allocator>::__find_leaf(const_iterator __hint, + __parent_pointer& __parent, + const key_type& __v) +{ + if (__hint == end() || !value_comp()(*__hint, __v)) // check before + { + // __v <= *__hint + const_iterator __prior = __hint; + if (__prior == begin() || !value_comp()(__v, *--__prior)) + { + // *prev(__hint) <= __v <= *__hint + if (__hint.__ptr_->__left_ == nullptr) + { + __parent = static_cast<__parent_pointer>(__hint.__ptr_); + return __parent->__left_; + } + else + { + __parent = static_cast<__parent_pointer>(__prior.__ptr_); + return static_cast<__node_base_pointer>(__prior.__ptr_)->__right_; + } + } + // __v < *prev(__hint) + return __find_leaf_high(__parent, __v); + } + // else __v > *__hint + return __find_leaf_low(__parent, __v); +} + +// Find place to insert if __v doesn't exist +// Set __parent to parent of null leaf +// Return reference to null leaf +// If __v exists, set parent to node of __v and return reference to node of __v +template <class _Tp, class _Compare, class _Allocator> +template <class _Key> +typename __tree<_Tp, _Compare, _Allocator>::__node_base_pointer& +__tree<_Tp, _Compare, _Allocator>::__find_equal(__parent_pointer& __parent, + const _Key& __v) +{ + __node_pointer __nd = __root(); + __node_base_pointer* __nd_ptr = __root_ptr(); + if (__nd != nullptr) + { + while (true) + { + if (value_comp()(__v, __nd->__value_)) + { + if (__nd->__left_ != nullptr) { + __nd_ptr = _VSTD::addressof(__nd->__left_); + __nd = static_cast<__node_pointer>(__nd->__left_); + } else { + __parent = static_cast<__parent_pointer>(__nd); + return __parent->__left_; + } + } + else if (value_comp()(__nd->__value_, __v)) + { + if (__nd->__right_ != nullptr) { + __nd_ptr = _VSTD::addressof(__nd->__right_); + __nd = static_cast<__node_pointer>(__nd->__right_); + } else { + __parent = static_cast<__parent_pointer>(__nd); + return __nd->__right_; + } + } + else + { + __parent = static_cast<__parent_pointer>(__nd); + return *__nd_ptr; + } + } + } + __parent = static_cast<__parent_pointer>(__end_node()); + return __parent->__left_; +} + +// Find place to insert if __v doesn't exist +// First check prior to __hint. +// Next check after __hint. +// Next do O(log N) search. +// Set __parent to parent of null leaf +// Return reference to null leaf +// If __v exists, set parent to node of __v and return reference to node of __v +template <class _Tp, class _Compare, class _Allocator> +template <class _Key> +typename __tree<_Tp, _Compare, _Allocator>::__node_base_pointer& +__tree<_Tp, _Compare, _Allocator>::__find_equal(const_iterator __hint, + __parent_pointer& __parent, + __node_base_pointer& __dummy, + const _Key& __v) +{ + if (__hint == end() || value_comp()(__v, *__hint)) // check before + { + // __v < *__hint + const_iterator __prior = __hint; + if (__prior == begin() || value_comp()(*--__prior, __v)) + { + // *prev(__hint) < __v < *__hint + if (__hint.__ptr_->__left_ == nullptr) + { + __parent = static_cast<__parent_pointer>(__hint.__ptr_); + return __parent->__left_; + } + else + { + __parent = static_cast<__parent_pointer>(__prior.__ptr_); + return static_cast<__node_base_pointer>(__prior.__ptr_)->__right_; + } + } + // __v <= *prev(__hint) + return __find_equal(__parent, __v); + } + else if (value_comp()(*__hint, __v)) // check after + { + // *__hint < __v + const_iterator __next = _VSTD::next(__hint); + if (__next == end() || value_comp()(__v, *__next)) + { + // *__hint < __v < *_VSTD::next(__hint) + if (__hint.__get_np()->__right_ == nullptr) + { + __parent = static_cast<__parent_pointer>(__hint.__ptr_); + return static_cast<__node_base_pointer>(__hint.__ptr_)->__right_; + } + else + { + __parent = static_cast<__parent_pointer>(__next.__ptr_); + return __parent->__left_; + } + } + // *next(__hint) <= __v + return __find_equal(__parent, __v); + } + // else __v == *__hint + __parent = static_cast<__parent_pointer>(__hint.__ptr_); + __dummy = static_cast<__node_base_pointer>(__hint.__ptr_); + return __dummy; +} + +template <class _Tp, class _Compare, class _Allocator> +void __tree<_Tp, _Compare, _Allocator>::__insert_node_at( + __parent_pointer __parent, __node_base_pointer& __child, + __node_base_pointer __new_node) _NOEXCEPT +{ + __new_node->__left_ = nullptr; + __new_node->__right_ = nullptr; + __new_node->__parent_ = __parent; + // __new_node->__is_black_ is initialized in __tree_balance_after_insert + __child = __new_node; + if (__begin_node()->__left_ != nullptr) + __begin_node() = static_cast<__iter_pointer>(__begin_node()->__left_); + _VSTD::__tree_balance_after_insert(__end_node()->__left_, __child); + ++size(); +} + +template <class _Tp, class _Compare, class _Allocator> +template <class _Key, class... _Args> +pair<typename __tree<_Tp, _Compare, _Allocator>::iterator, bool> +__tree<_Tp, _Compare, _Allocator>::__emplace_unique_key_args(_Key const& __k, _Args&&... __args) +{ + __parent_pointer __parent; + __node_base_pointer& __child = __find_equal(__parent, __k); + __node_pointer __r = static_cast<__node_pointer>(__child); + bool __inserted = false; + if (__child == nullptr) + { + __node_holder __h = __construct_node(_VSTD::forward<_Args>(__args)...); + __insert_node_at(__parent, __child, static_cast<__node_base_pointer>(__h.get())); + __r = __h.release(); + __inserted = true; + } + return pair<iterator, bool>(iterator(__r), __inserted); +} + +template <class _Tp, class _Compare, class _Allocator> +template <class _Key, class... _Args> +pair<typename __tree<_Tp, _Compare, _Allocator>::iterator, bool> +__tree<_Tp, _Compare, _Allocator>::__emplace_hint_unique_key_args( + const_iterator __p, _Key const& __k, _Args&&... __args) +{ + __parent_pointer __parent; + __node_base_pointer __dummy; + __node_base_pointer& __child = __find_equal(__p, __parent, __dummy, __k); + __node_pointer __r = static_cast<__node_pointer>(__child); + bool __inserted = false; + if (__child == nullptr) + { + __node_holder __h = __construct_node(_VSTD::forward<_Args>(__args)...); + __insert_node_at(__parent, __child, static_cast<__node_base_pointer>(__h.get())); + __r = __h.release(); + __inserted = true; + } + return pair<iterator, bool>(iterator(__r), __inserted); +} + +template <class _Tp, class _Compare, class _Allocator> +template <class ..._Args> +typename __tree<_Tp, _Compare, _Allocator>::__node_holder +__tree<_Tp, _Compare, _Allocator>::__construct_node(_Args&& ...__args) +{ + static_assert(!__is_tree_value_type<_Args...>::value, + "Cannot construct from __value_type"); + __node_allocator& __na = __node_alloc(); + __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na)); + __node_traits::construct(__na, _NodeTypes::__get_ptr(__h->__value_), _VSTD::forward<_Args>(__args)...); + __h.get_deleter().__value_constructed = true; + return __h; +} + + +template <class _Tp, class _Compare, class _Allocator> +template <class... _Args> +pair<typename __tree<_Tp, _Compare, _Allocator>::iterator, bool> +__tree<_Tp, _Compare, _Allocator>::__emplace_unique_impl(_Args&&... __args) +{ + __node_holder __h = __construct_node(_VSTD::forward<_Args>(__args)...); + __parent_pointer __parent; + __node_base_pointer& __child = __find_equal(__parent, __h->__value_); + __node_pointer __r = static_cast<__node_pointer>(__child); + bool __inserted = false; + if (__child == nullptr) + { + __insert_node_at(__parent, __child, static_cast<__node_base_pointer>(__h.get())); + __r = __h.release(); + __inserted = true; + } + return pair<iterator, bool>(iterator(__r), __inserted); +} + +template <class _Tp, class _Compare, class _Allocator> +template <class... _Args> +typename __tree<_Tp, _Compare, _Allocator>::iterator +__tree<_Tp, _Compare, _Allocator>::__emplace_hint_unique_impl(const_iterator __p, _Args&&... __args) +{ + __node_holder __h = __construct_node(_VSTD::forward<_Args>(__args)...); + __parent_pointer __parent; + __node_base_pointer __dummy; + __node_base_pointer& __child = __find_equal(__p, __parent, __dummy, __h->__value_); + __node_pointer __r = static_cast<__node_pointer>(__child); + if (__child == nullptr) + { + __insert_node_at(__parent, __child, static_cast<__node_base_pointer>(__h.get())); + __r = __h.release(); + } + return iterator(__r); +} + +template <class _Tp, class _Compare, class _Allocator> +template <class... _Args> +typename __tree<_Tp, _Compare, _Allocator>::iterator +__tree<_Tp, _Compare, _Allocator>::__emplace_multi(_Args&&... __args) +{ + __node_holder __h = __construct_node(_VSTD::forward<_Args>(__args)...); + __parent_pointer __parent; + __node_base_pointer& __child = __find_leaf_high(__parent, _NodeTypes::__get_key(__h->__value_)); + __insert_node_at(__parent, __child, static_cast<__node_base_pointer>(__h.get())); + return iterator(static_cast<__node_pointer>(__h.release())); +} + +template <class _Tp, class _Compare, class _Allocator> +template <class... _Args> +typename __tree<_Tp, _Compare, _Allocator>::iterator +__tree<_Tp, _Compare, _Allocator>::__emplace_hint_multi(const_iterator __p, + _Args&&... __args) +{ + __node_holder __h = __construct_node(_VSTD::forward<_Args>(__args)...); + __parent_pointer __parent; + __node_base_pointer& __child = __find_leaf(__p, __parent, _NodeTypes::__get_key(__h->__value_)); + __insert_node_at(__parent, __child, static_cast<__node_base_pointer>(__h.get())); + return iterator(static_cast<__node_pointer>(__h.release())); +} + +template <class _Tp, class _Compare, class _Allocator> +pair<typename __tree<_Tp, _Compare, _Allocator>::iterator, bool> +__tree<_Tp, _Compare, _Allocator>::__node_assign_unique(const __container_value_type& __v, __node_pointer __nd) +{ + __parent_pointer __parent; + __node_base_pointer& __child = __find_equal(__parent, _NodeTypes::__get_key(__v)); + __node_pointer __r = static_cast<__node_pointer>(__child); + bool __inserted = false; + if (__child == nullptr) + { + __nd->__value_ = __v; + __insert_node_at(__parent, __child, static_cast<__node_base_pointer>(__nd)); + __r = __nd; + __inserted = true; + } + return pair<iterator, bool>(iterator(__r), __inserted); +} + + +template <class _Tp, class _Compare, class _Allocator> +typename __tree<_Tp, _Compare, _Allocator>::iterator +__tree<_Tp, _Compare, _Allocator>::__node_insert_multi(__node_pointer __nd) +{ + __parent_pointer __parent; + __node_base_pointer& __child = __find_leaf_high(__parent, _NodeTypes::__get_key(__nd->__value_)); + __insert_node_at(__parent, __child, static_cast<__node_base_pointer>(__nd)); + return iterator(__nd); +} + +template <class _Tp, class _Compare, class _Allocator> +typename __tree<_Tp, _Compare, _Allocator>::iterator +__tree<_Tp, _Compare, _Allocator>::__node_insert_multi(const_iterator __p, + __node_pointer __nd) +{ + __parent_pointer __parent; + __node_base_pointer& __child = __find_leaf(__p, __parent, _NodeTypes::__get_key(__nd->__value_)); + __insert_node_at(__parent, __child, static_cast<__node_base_pointer>(__nd)); + return iterator(__nd); +} + +template <class _Tp, class _Compare, class _Allocator> +typename __tree<_Tp, _Compare, _Allocator>::iterator +__tree<_Tp, _Compare, _Allocator>::__remove_node_pointer(__node_pointer __ptr) _NOEXCEPT +{ + iterator __r(__ptr); + ++__r; + if (__begin_node() == __ptr) + __begin_node() = __r.__ptr_; + --size(); + _VSTD::__tree_remove(__end_node()->__left_, + static_cast<__node_base_pointer>(__ptr)); + return __r; +} + +#if _LIBCPP_STD_VER > 14 +template <class _Tp, class _Compare, class _Allocator> +template <class _NodeHandle, class _InsertReturnType> +_LIBCPP_INLINE_VISIBILITY +_InsertReturnType +__tree<_Tp, _Compare, _Allocator>::__node_handle_insert_unique( + _NodeHandle&& __nh) +{ + if (__nh.empty()) + return _InsertReturnType{end(), false, _NodeHandle()}; + + __node_pointer __ptr = __nh.__ptr_; + __parent_pointer __parent; + __node_base_pointer& __child = __find_equal(__parent, + __ptr->__value_); + if (__child != nullptr) + return _InsertReturnType{ + iterator(static_cast<__node_pointer>(__child)), + false, _VSTD::move(__nh)}; + + __insert_node_at(__parent, __child, + static_cast<__node_base_pointer>(__ptr)); + __nh.__release_ptr(); + return _InsertReturnType{iterator(__ptr), true, _NodeHandle()}; +} + +template <class _Tp, class _Compare, class _Allocator> +template <class _NodeHandle> +_LIBCPP_INLINE_VISIBILITY +typename __tree<_Tp, _Compare, _Allocator>::iterator +__tree<_Tp, _Compare, _Allocator>::__node_handle_insert_unique( + const_iterator __hint, _NodeHandle&& __nh) +{ + if (__nh.empty()) + return end(); + + __node_pointer __ptr = __nh.__ptr_; + __parent_pointer __parent; + __node_base_pointer __dummy; + __node_base_pointer& __child = __find_equal(__hint, __parent, __dummy, + __ptr->__value_); + __node_pointer __r = static_cast<__node_pointer>(__child); + if (__child == nullptr) + { + __insert_node_at(__parent, __child, + static_cast<__node_base_pointer>(__ptr)); + __r = __ptr; + __nh.__release_ptr(); + } + return iterator(__r); +} + +template <class _Tp, class _Compare, class _Allocator> +template <class _NodeHandle> +_LIBCPP_INLINE_VISIBILITY +_NodeHandle +__tree<_Tp, _Compare, _Allocator>::__node_handle_extract(key_type const& __key) +{ + iterator __it = find(__key); + if (__it == end()) + return _NodeHandle(); + return __node_handle_extract<_NodeHandle>(__it); +} + +template <class _Tp, class _Compare, class _Allocator> +template <class _NodeHandle> +_LIBCPP_INLINE_VISIBILITY +_NodeHandle +__tree<_Tp, _Compare, _Allocator>::__node_handle_extract(const_iterator __p) +{ + __node_pointer __np = __p.__get_np(); + __remove_node_pointer(__np); + return _NodeHandle(__np, __alloc()); +} + +template <class _Tp, class _Compare, class _Allocator> +template <class _Tree> +_LIBCPP_INLINE_VISIBILITY +void +__tree<_Tp, _Compare, _Allocator>::__node_handle_merge_unique(_Tree& __source) +{ + static_assert(is_same<typename _Tree::__node_pointer, __node_pointer>::value, ""); + + for (typename _Tree::iterator __i = __source.begin(); + __i != __source.end();) + { + __node_pointer __src_ptr = __i.__get_np(); + __parent_pointer __parent; + __node_base_pointer& __child = + __find_equal(__parent, _NodeTypes::__get_key(__src_ptr->__value_)); + ++__i; + if (__child != nullptr) + continue; + __source.__remove_node_pointer(__src_ptr); + __insert_node_at(__parent, __child, + static_cast<__node_base_pointer>(__src_ptr)); + } +} + +template <class _Tp, class _Compare, class _Allocator> +template <class _NodeHandle> +_LIBCPP_INLINE_VISIBILITY +typename __tree<_Tp, _Compare, _Allocator>::iterator +__tree<_Tp, _Compare, _Allocator>::__node_handle_insert_multi(_NodeHandle&& __nh) +{ + if (__nh.empty()) + return end(); + __node_pointer __ptr = __nh.__ptr_; + __parent_pointer __parent; + __node_base_pointer& __child = __find_leaf_high( + __parent, _NodeTypes::__get_key(__ptr->__value_)); + __insert_node_at(__parent, __child, static_cast<__node_base_pointer>(__ptr)); + __nh.__release_ptr(); + return iterator(__ptr); +} + +template <class _Tp, class _Compare, class _Allocator> +template <class _NodeHandle> +_LIBCPP_INLINE_VISIBILITY +typename __tree<_Tp, _Compare, _Allocator>::iterator +__tree<_Tp, _Compare, _Allocator>::__node_handle_insert_multi( + const_iterator __hint, _NodeHandle&& __nh) +{ + if (__nh.empty()) + return end(); + + __node_pointer __ptr = __nh.__ptr_; + __parent_pointer __parent; + __node_base_pointer& __child = __find_leaf(__hint, __parent, + _NodeTypes::__get_key(__ptr->__value_)); + __insert_node_at(__parent, __child, static_cast<__node_base_pointer>(__ptr)); + __nh.__release_ptr(); + return iterator(__ptr); +} + +template <class _Tp, class _Compare, class _Allocator> +template <class _Tree> +_LIBCPP_INLINE_VISIBILITY +void +__tree<_Tp, _Compare, _Allocator>::__node_handle_merge_multi(_Tree& __source) +{ + static_assert(is_same<typename _Tree::__node_pointer, __node_pointer>::value, ""); + + for (typename _Tree::iterator __i = __source.begin(); + __i != __source.end();) + { + __node_pointer __src_ptr = __i.__get_np(); + __parent_pointer __parent; + __node_base_pointer& __child = __find_leaf_high( + __parent, _NodeTypes::__get_key(__src_ptr->__value_)); + ++__i; + __source.__remove_node_pointer(__src_ptr); + __insert_node_at(__parent, __child, + static_cast<__node_base_pointer>(__src_ptr)); + } +} + +#endif // _LIBCPP_STD_VER > 14 + +template <class _Tp, class _Compare, class _Allocator> +typename __tree<_Tp, _Compare, _Allocator>::iterator +__tree<_Tp, _Compare, _Allocator>::erase(const_iterator __p) +{ + __node_pointer __np = __p.__get_np(); + iterator __r = __remove_node_pointer(__np); + __node_allocator& __na = __node_alloc(); + __node_traits::destroy(__na, _NodeTypes::__get_ptr( + const_cast<__node_value_type&>(*__p))); + __node_traits::deallocate(__na, __np, 1); + return __r; +} + +template <class _Tp, class _Compare, class _Allocator> +typename __tree<_Tp, _Compare, _Allocator>::iterator +__tree<_Tp, _Compare, _Allocator>::erase(const_iterator __f, const_iterator __l) +{ + while (__f != __l) + __f = erase(__f); + return iterator(__l.__ptr_); +} + +template <class _Tp, class _Compare, class _Allocator> +template <class _Key> +typename __tree<_Tp, _Compare, _Allocator>::size_type +__tree<_Tp, _Compare, _Allocator>::__erase_unique(const _Key& __k) +{ + iterator __i = find(__k); + if (__i == end()) + return 0; + erase(__i); + return 1; +} + +template <class _Tp, class _Compare, class _Allocator> +template <class _Key> +typename __tree<_Tp, _Compare, _Allocator>::size_type +__tree<_Tp, _Compare, _Allocator>::__erase_multi(const _Key& __k) +{ + pair<iterator, iterator> __p = __equal_range_multi(__k); + size_type __r = 0; + for (; __p.first != __p.second; ++__r) + __p.first = erase(__p.first); + return __r; +} + +template <class _Tp, class _Compare, class _Allocator> +template <class _Key> +typename __tree<_Tp, _Compare, _Allocator>::iterator +__tree<_Tp, _Compare, _Allocator>::find(const _Key& __v) +{ + iterator __p = __lower_bound(__v, __root(), __end_node()); + if (__p != end() && !value_comp()(__v, *__p)) + return __p; + return end(); +} + +template <class _Tp, class _Compare, class _Allocator> +template <class _Key> +typename __tree<_Tp, _Compare, _Allocator>::const_iterator +__tree<_Tp, _Compare, _Allocator>::find(const _Key& __v) const +{ + const_iterator __p = __lower_bound(__v, __root(), __end_node()); + if (__p != end() && !value_comp()(__v, *__p)) + return __p; + return end(); +} + +template <class _Tp, class _Compare, class _Allocator> +template <class _Key> +typename __tree<_Tp, _Compare, _Allocator>::size_type +__tree<_Tp, _Compare, _Allocator>::__count_unique(const _Key& __k) const +{ + __node_pointer __rt = __root(); + while (__rt != nullptr) + { + if (value_comp()(__k, __rt->__value_)) + { + __rt = static_cast<__node_pointer>(__rt->__left_); + } + else if (value_comp()(__rt->__value_, __k)) + __rt = static_cast<__node_pointer>(__rt->__right_); + else + return 1; + } + return 0; +} + +template <class _Tp, class _Compare, class _Allocator> +template <class _Key> +typename __tree<_Tp, _Compare, _Allocator>::size_type +__tree<_Tp, _Compare, _Allocator>::__count_multi(const _Key& __k) const +{ + __iter_pointer __result = __end_node(); + __node_pointer __rt = __root(); + while (__rt != nullptr) + { + if (value_comp()(__k, __rt->__value_)) + { + __result = static_cast<__iter_pointer>(__rt); + __rt = static_cast<__node_pointer>(__rt->__left_); + } + else if (value_comp()(__rt->__value_, __k)) + __rt = static_cast<__node_pointer>(__rt->__right_); + else + return _VSTD::distance( + __lower_bound(__k, static_cast<__node_pointer>(__rt->__left_), static_cast<__iter_pointer>(__rt)), + __upper_bound(__k, static_cast<__node_pointer>(__rt->__right_), __result) + ); + } + return 0; +} + +template <class _Tp, class _Compare, class _Allocator> +template <class _Key> +typename __tree<_Tp, _Compare, _Allocator>::iterator +__tree<_Tp, _Compare, _Allocator>::__lower_bound(const _Key& __v, + __node_pointer __root, + __iter_pointer __result) +{ + while (__root != nullptr) + { + if (!value_comp()(__root->__value_, __v)) + { + __result = static_cast<__iter_pointer>(__root); + __root = static_cast<__node_pointer>(__root->__left_); + } + else + __root = static_cast<__node_pointer>(__root->__right_); + } + return iterator(__result); +} + +template <class _Tp, class _Compare, class _Allocator> +template <class _Key> +typename __tree<_Tp, _Compare, _Allocator>::const_iterator +__tree<_Tp, _Compare, _Allocator>::__lower_bound(const _Key& __v, + __node_pointer __root, + __iter_pointer __result) const +{ + while (__root != nullptr) + { + if (!value_comp()(__root->__value_, __v)) + { + __result = static_cast<__iter_pointer>(__root); + __root = static_cast<__node_pointer>(__root->__left_); + } + else + __root = static_cast<__node_pointer>(__root->__right_); + } + return const_iterator(__result); +} + +template <class _Tp, class _Compare, class _Allocator> +template <class _Key> +typename __tree<_Tp, _Compare, _Allocator>::iterator +__tree<_Tp, _Compare, _Allocator>::__upper_bound(const _Key& __v, + __node_pointer __root, + __iter_pointer __result) +{ + while (__root != nullptr) + { + if (value_comp()(__v, __root->__value_)) + { + __result = static_cast<__iter_pointer>(__root); + __root = static_cast<__node_pointer>(__root->__left_); + } + else + __root = static_cast<__node_pointer>(__root->__right_); + } + return iterator(__result); +} + +template <class _Tp, class _Compare, class _Allocator> +template <class _Key> +typename __tree<_Tp, _Compare, _Allocator>::const_iterator +__tree<_Tp, _Compare, _Allocator>::__upper_bound(const _Key& __v, + __node_pointer __root, + __iter_pointer __result) const +{ + while (__root != nullptr) + { + if (value_comp()(__v, __root->__value_)) + { + __result = static_cast<__iter_pointer>(__root); + __root = static_cast<__node_pointer>(__root->__left_); + } + else + __root = static_cast<__node_pointer>(__root->__right_); + } + return const_iterator(__result); +} + +template <class _Tp, class _Compare, class _Allocator> +template <class _Key> +pair<typename __tree<_Tp, _Compare, _Allocator>::iterator, + typename __tree<_Tp, _Compare, _Allocator>::iterator> +__tree<_Tp, _Compare, _Allocator>::__equal_range_unique(const _Key& __k) +{ + typedef pair<iterator, iterator> _Pp; + __iter_pointer __result = __end_node(); + __node_pointer __rt = __root(); + while (__rt != nullptr) + { + if (value_comp()(__k, __rt->__value_)) + { + __result = static_cast<__iter_pointer>(__rt); + __rt = static_cast<__node_pointer>(__rt->__left_); + } + else if (value_comp()(__rt->__value_, __k)) + __rt = static_cast<__node_pointer>(__rt->__right_); + else + return _Pp(iterator(__rt), + iterator( + __rt->__right_ != nullptr ? + static_cast<__iter_pointer>(_VSTD::__tree_min(__rt->__right_)) + : __result)); + } + return _Pp(iterator(__result), iterator(__result)); +} + +template <class _Tp, class _Compare, class _Allocator> +template <class _Key> +pair<typename __tree<_Tp, _Compare, _Allocator>::const_iterator, + typename __tree<_Tp, _Compare, _Allocator>::const_iterator> +__tree<_Tp, _Compare, _Allocator>::__equal_range_unique(const _Key& __k) const +{ + typedef pair<const_iterator, const_iterator> _Pp; + __iter_pointer __result = __end_node(); + __node_pointer __rt = __root(); + while (__rt != nullptr) + { + if (value_comp()(__k, __rt->__value_)) + { + __result = static_cast<__iter_pointer>(__rt); + __rt = static_cast<__node_pointer>(__rt->__left_); + } + else if (value_comp()(__rt->__value_, __k)) + __rt = static_cast<__node_pointer>(__rt->__right_); + else + return _Pp(const_iterator(__rt), + const_iterator( + __rt->__right_ != nullptr ? + static_cast<__iter_pointer>(_VSTD::__tree_min(__rt->__right_)) + : __result)); + } + return _Pp(const_iterator(__result), const_iterator(__result)); +} + +template <class _Tp, class _Compare, class _Allocator> +template <class _Key> +pair<typename __tree<_Tp, _Compare, _Allocator>::iterator, + typename __tree<_Tp, _Compare, _Allocator>::iterator> +__tree<_Tp, _Compare, _Allocator>::__equal_range_multi(const _Key& __k) +{ + typedef pair<iterator, iterator> _Pp; + __iter_pointer __result = __end_node(); + __node_pointer __rt = __root(); + while (__rt != nullptr) + { + if (value_comp()(__k, __rt->__value_)) + { + __result = static_cast<__iter_pointer>(__rt); + __rt = static_cast<__node_pointer>(__rt->__left_); + } + else if (value_comp()(__rt->__value_, __k)) + __rt = static_cast<__node_pointer>(__rt->__right_); + else + return _Pp(__lower_bound(__k, static_cast<__node_pointer>(__rt->__left_), static_cast<__iter_pointer>(__rt)), + __upper_bound(__k, static_cast<__node_pointer>(__rt->__right_), __result)); + } + return _Pp(iterator(__result), iterator(__result)); +} + +template <class _Tp, class _Compare, class _Allocator> +template <class _Key> +pair<typename __tree<_Tp, _Compare, _Allocator>::const_iterator, + typename __tree<_Tp, _Compare, _Allocator>::const_iterator> +__tree<_Tp, _Compare, _Allocator>::__equal_range_multi(const _Key& __k) const +{ + typedef pair<const_iterator, const_iterator> _Pp; + __iter_pointer __result = __end_node(); + __node_pointer __rt = __root(); + while (__rt != nullptr) + { + if (value_comp()(__k, __rt->__value_)) + { + __result = static_cast<__iter_pointer>(__rt); + __rt = static_cast<__node_pointer>(__rt->__left_); + } + else if (value_comp()(__rt->__value_, __k)) + __rt = static_cast<__node_pointer>(__rt->__right_); + else + return _Pp(__lower_bound(__k, static_cast<__node_pointer>(__rt->__left_), static_cast<__iter_pointer>(__rt)), + __upper_bound(__k, static_cast<__node_pointer>(__rt->__right_), __result)); + } + return _Pp(const_iterator(__result), const_iterator(__result)); +} + +template <class _Tp, class _Compare, class _Allocator> +typename __tree<_Tp, _Compare, _Allocator>::__node_holder +__tree<_Tp, _Compare, _Allocator>::remove(const_iterator __p) _NOEXCEPT +{ + __node_pointer __np = __p.__get_np(); + if (__begin_node() == __p.__ptr_) + { + if (__np->__right_ != nullptr) + __begin_node() = static_cast<__iter_pointer>(__np->__right_); + else + __begin_node() = static_cast<__iter_pointer>(__np->__parent_); + } + --size(); + _VSTD::__tree_remove(__end_node()->__left_, + static_cast<__node_base_pointer>(__np)); + return __node_holder(__np, _Dp(__node_alloc(), true)); +} + +template <class _Tp, class _Compare, class _Allocator> +inline _LIBCPP_INLINE_VISIBILITY +void +swap(__tree<_Tp, _Compare, _Allocator>& __x, + __tree<_Tp, _Compare, _Allocator>& __y) + _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y))) +{ + __x.swap(__y); +} + +_LIBCPP_END_NAMESPACE_STD + +_LIBCPP_POP_MACROS + +#endif // _LIBCPP___TREE |