path
stringlengths 14
112
| content
stringlengths 0
6.32M
| size
int64 0
6.32M
| max_lines
int64 1
100k
| repo_name
stringclasses 2
values | autogenerated
bool 1
class |
---|---|---|---|---|---|
cosmopolitan/third_party/libcxx/condition_variable.cc | // clang-format off
//===-------------------- condition_variable.cpp --------------------------===//
//
// 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
//
//===----------------------------------------------------------------------===//
#include "third_party/libcxx/__config"
#ifndef _LIBCPP_HAS_NO_THREADS
#include "third_party/libcxx/condition_variable"
#include "third_party/libcxx/thread"
#include "third_party/libcxx/system_error"
#include "third_party/libcxx/__undef_macros"
_LIBCPP_BEGIN_NAMESPACE_STD
// ~condition_variable is defined elsewhere.
void
condition_variable::notify_one() _NOEXCEPT
{
__libcpp_condvar_signal(&__cv_);
}
void
condition_variable::notify_all() _NOEXCEPT
{
__libcpp_condvar_broadcast(&__cv_);
}
void
condition_variable::wait(unique_lock<mutex>& lk) _NOEXCEPT
{
if (!lk.owns_lock())
__throw_system_error(EPERM,
"condition_variable::wait: mutex not locked");
int ec = __libcpp_condvar_wait(&__cv_, lk.mutex()->native_handle());
if (ec)
__throw_system_error(ec, "condition_variable wait failed");
}
void
condition_variable::__do_timed_wait(unique_lock<mutex>& lk,
chrono::time_point<chrono::system_clock, chrono::nanoseconds> tp) _NOEXCEPT
{
using namespace chrono;
if (!lk.owns_lock())
__throw_system_error(EPERM,
"condition_variable::timed wait: mutex not locked");
nanoseconds d = tp.time_since_epoch();
if (d > nanoseconds(0x59682F000000E941))
d = nanoseconds(0x59682F000000E941);
__libcpp_timespec_t ts;
seconds s = duration_cast<seconds>(d);
typedef decltype(ts.tv_sec) ts_sec;
_LIBCPP_CONSTEXPR ts_sec ts_sec_max = numeric_limits<ts_sec>::max();
if (s.count() < ts_sec_max)
{
ts.tv_sec = static_cast<ts_sec>(s.count());
ts.tv_nsec = static_cast<decltype(ts.tv_nsec)>((d - s).count());
}
else
{
ts.tv_sec = ts_sec_max;
ts.tv_nsec = giga::num - 1;
}
int ec = __libcpp_condvar_timedwait(&__cv_, lk.mutex()->native_handle(), &ts);
if (ec != 0 && ec != ETIMEDOUT)
__throw_system_error(ec, "condition_variable timed_wait failed");
}
void
notify_all_at_thread_exit(condition_variable& cond, unique_lock<mutex> lk)
{
auto& tl_ptr = __thread_local_data();
// If this thread was not created using std::thread then it will not have
// previously allocated.
if (tl_ptr.get() == nullptr) {
tl_ptr.set_pointer(new __thread_struct);
}
__thread_local_data()->notify_all_at_thread_exit(&cond, lk.release());
}
_LIBCPP_END_NAMESPACE_STD
#endif // !_LIBCPP_HAS_NO_THREADS
| 2,808 | 91 | jart/cosmopolitan | false |
cosmopolitan/third_party/libcxx/mutex.cc | // clang-format off
//===------------------------- mutex.cpp ----------------------------------===//
//
// 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
//
//===----------------------------------------------------------------------===//
#include "third_party/libcxx/mutex"
#include "third_party/libcxx/limits"
#include "third_party/libcxx/system_error"
#include "third_party/libcxx/include/atomic_support.hh"
#include "third_party/libcxx/__undef_macros"
#ifndef _LIBCPP_HAS_NO_THREADS
#if defined(__unix__) && !defined(__ANDROID__) && defined(__ELF__) && defined(_LIBCPP_HAS_COMMENT_LIB_PRAGMA)
#pragma comment(lib, "pthread")
#endif
#endif
_LIBCPP_BEGIN_NAMESPACE_STD
#ifndef _LIBCPP_HAS_NO_THREADS
// TODO(jart): why do we need to comment these out?
// const defer_lock_t defer_lock{};
// const try_to_lock_t try_to_lock{};
// const adopt_lock_t adopt_lock{};
// ~mutex is defined elsewhere
void
mutex::lock()
{
int ec = __libcpp_mutex_lock(&__m_);
if (ec)
__throw_system_error(ec, "mutex lock failed");
}
bool
mutex::try_lock() _NOEXCEPT
{
return __libcpp_mutex_trylock(&__m_);
}
void
mutex::unlock() _NOEXCEPT
{
int ec = __libcpp_mutex_unlock(&__m_);
(void)ec;
_LIBCPP_ASSERT(ec == 0, "call to mutex::unlock failed");
}
// recursive_mutex
recursive_mutex::recursive_mutex()
{
int ec = __libcpp_recursive_mutex_init(&__m_);
if (ec)
__throw_system_error(ec, "recursive_mutex constructor failed");
}
recursive_mutex::~recursive_mutex()
{
int e = __libcpp_recursive_mutex_destroy(&__m_);
(void)e;
_LIBCPP_ASSERT(e == 0, "call to ~recursive_mutex() failed");
}
void
recursive_mutex::lock()
{
int ec = __libcpp_recursive_mutex_lock(&__m_);
if (ec)
__throw_system_error(ec, "recursive_mutex lock failed");
}
void
recursive_mutex::unlock() _NOEXCEPT
{
int e = __libcpp_recursive_mutex_unlock(&__m_);
(void)e;
_LIBCPP_ASSERT(e == 0, "call to recursive_mutex::unlock() failed");
}
bool
recursive_mutex::try_lock() _NOEXCEPT
{
return __libcpp_recursive_mutex_trylock(&__m_);
}
// timed_mutex
timed_mutex::timed_mutex()
: __locked_(false)
{
}
timed_mutex::~timed_mutex()
{
lock_guard<mutex> _(__m_);
}
void
timed_mutex::lock()
{
unique_lock<mutex> lk(__m_);
while (__locked_)
__cv_.wait(lk);
__locked_ = true;
}
bool
timed_mutex::try_lock() _NOEXCEPT
{
unique_lock<mutex> lk(__m_, try_to_lock);
if (lk.owns_lock() && !__locked_)
{
__locked_ = true;
return true;
}
return false;
}
void
timed_mutex::unlock() _NOEXCEPT
{
lock_guard<mutex> _(__m_);
__locked_ = false;
__cv_.notify_one();
}
// recursive_timed_mutex
recursive_timed_mutex::recursive_timed_mutex()
: __count_(0),
__id_{}
{
}
recursive_timed_mutex::~recursive_timed_mutex()
{
lock_guard<mutex> _(__m_);
}
void
recursive_timed_mutex::lock()
{
__thread_id id = this_thread::get_id();
unique_lock<mutex> lk(__m_);
if (id ==__id_)
{
if (__count_ == numeric_limits<size_t>::max())
__throw_system_error(EAGAIN, "recursive_timed_mutex lock limit reached");
++__count_;
return;
}
while (__count_ != 0)
__cv_.wait(lk);
__count_ = 1;
__id_ = id;
}
bool
recursive_timed_mutex::try_lock() _NOEXCEPT
{
__thread_id id = this_thread::get_id();
unique_lock<mutex> lk(__m_, try_to_lock);
if (lk.owns_lock() && (__count_ == 0 || id == __id_))
{
if (__count_ == numeric_limits<size_t>::max())
return false;
++__count_;
__id_ = id;
return true;
}
return false;
}
void
recursive_timed_mutex::unlock() _NOEXCEPT
{
unique_lock<mutex> lk(__m_);
if (--__count_ == 0)
{
__id_.__reset();
lk.unlock();
__cv_.notify_one();
}
}
#endif // !_LIBCPP_HAS_NO_THREADS
// If dispatch_once_f ever handles C++ exceptions, and if one can get to it
// without illegal macros (unexpected macros not beginning with _UpperCase or
// __lowercase), and if it stops spinning waiting threads, then call_once should
// call into dispatch_once_f instead of here. Relevant radar this code needs to
// keep in sync with: 7741191.
#ifndef _LIBCPP_HAS_NO_THREADS
_LIBCPP_SAFE_STATIC static __libcpp_mutex_t mut = _LIBCPP_MUTEX_INITIALIZER;
_LIBCPP_SAFE_STATIC static __libcpp_condvar_t cv = _LIBCPP_CONDVAR_INITIALIZER;
#endif
void __call_once(volatile once_flag::_State_type& flag, void* arg,
void (*func)(void*))
{
#if defined(_LIBCPP_HAS_NO_THREADS)
if (flag == 0)
{
#ifndef _LIBCPP_NO_EXCEPTIONS
try
{
#endif // _LIBCPP_NO_EXCEPTIONS
flag = 1;
func(arg);
flag = ~once_flag::_State_type(0);
#ifndef _LIBCPP_NO_EXCEPTIONS
}
catch (...)
{
flag = 0;
throw;
}
#endif // _LIBCPP_NO_EXCEPTIONS
}
#else // !_LIBCPP_HAS_NO_THREADS
__libcpp_mutex_lock(&mut);
while (flag == 1)
__libcpp_condvar_wait(&cv, &mut);
if (flag == 0)
{
#ifndef _LIBCPP_NO_EXCEPTIONS
try
{
#endif // _LIBCPP_NO_EXCEPTIONS
__libcpp_relaxed_store(&flag, once_flag::_State_type(1));
__libcpp_mutex_unlock(&mut);
func(arg);
__libcpp_mutex_lock(&mut);
__libcpp_atomic_store(&flag, ~once_flag::_State_type(0),
_AO_Release);
__libcpp_mutex_unlock(&mut);
__libcpp_condvar_broadcast(&cv);
#ifndef _LIBCPP_NO_EXCEPTIONS
}
catch (...)
{
__libcpp_mutex_lock(&mut);
__libcpp_relaxed_store(&flag, once_flag::_State_type(0));
__libcpp_mutex_unlock(&mut);
__libcpp_condvar_broadcast(&cv);
throw;
}
#endif // _LIBCPP_NO_EXCEPTIONS
}
else
__libcpp_mutex_unlock(&mut);
#endif // !_LIBCPP_HAS_NO_THREADS
}
_LIBCPP_END_NAMESPACE_STD
| 6,137 | 263 | jart/cosmopolitan | false |
cosmopolitan/third_party/libcxx/locale.h | // -*- C++ -*-
//===---------------------------- locale.h --------------------------------===//
//
// 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_LOCALE_H
#define _LIBCPP_LOCALE_H
/*
locale.h synopsis
Macros:
LC_ALL
LC_COLLATE
LC_CTYPE
LC_MONETARY
LC_NUMERIC
LC_TIME
Types:
lconv
Functions:
setlocale
localeconv
*/
#include "third_party/libcxx/__config"
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
#pragma GCC system_header
#endif
#include "libc/isystem/locale.h"
#endif // _LIBCPP_LOCALE_H
| 802 | 45 | jart/cosmopolitan | false |
cosmopolitan/third_party/libcxx/memory.cc | // clang-format off
//===------------------------ memory.cpp ----------------------------------===//
//
// 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
//
//===----------------------------------------------------------------------===//
#include "third_party/libcxx/memory"
#ifndef _LIBCPP_HAS_NO_THREADS
#include "third_party/libcxx/mutex"
#include "third_party/libcxx/thread"
#if defined(__unix__) && !defined(__ANDROID__) && defined(__ELF__) && defined(_LIBCPP_HAS_COMMENT_LIB_PRAGMA)
#pragma comment(lib, "pthread")
#endif
#endif
#include "third_party/libcxx/include/atomic_support.hh"
_LIBCPP_BEGIN_NAMESPACE_STD
// TODO(jart): why does this need to be commented?
// const allocator_arg_t allocator_arg = allocator_arg_t();
bad_weak_ptr::~bad_weak_ptr() _NOEXCEPT {}
const char*
bad_weak_ptr::what() const _NOEXCEPT
{
return "bad_weak_ptr";
}
__shared_count::~__shared_count()
{
}
__shared_weak_count::~__shared_weak_count()
{
}
#if defined(_LIBCPP_DEPRECATED_ABI_LEGACY_LIBRARY_DEFINITIONS_FOR_INLINE_FUNCTIONS)
void
__shared_count::__add_shared() _NOEXCEPT
{
__libcpp_atomic_refcount_increment(__shared_owners_);
}
bool
__shared_count::__release_shared() _NOEXCEPT
{
if (__libcpp_atomic_refcount_decrement(__shared_owners_) == -1)
{
__on_zero_shared();
return true;
}
return false;
}
void
__shared_weak_count::__add_shared() _NOEXCEPT
{
__shared_count::__add_shared();
}
void
__shared_weak_count::__add_weak() _NOEXCEPT
{
__libcpp_atomic_refcount_increment(__shared_weak_owners_);
}
void
__shared_weak_count::__release_shared() _NOEXCEPT
{
if (__shared_count::__release_shared())
__release_weak();
}
#endif // _LIBCPP_DEPRECATED_ABI_LEGACY_LIBRARY_DEFINITIONS_FOR_INLINE_FUNCTIONS
void
__shared_weak_count::__release_weak() _NOEXCEPT
{
// NOTE: The acquire load here is an optimization of the very
// common case where a shared pointer is being destructed while
// having no other contended references.
//
// BENEFIT: We avoid expensive atomic stores like XADD and STREX
// in a common case. Those instructions are slow and do nasty
// things to caches.
//
// IS THIS SAFE? Yes. During weak destruction, if we see that we
// are the last reference, we know that no-one else is accessing
// us. If someone were accessing us, then they would be doing so
// while the last shared / weak_ptr was being destructed, and
// that's undefined anyway.
//
// If we see anything other than a 0, then we have possible
// contention, and need to use an atomicrmw primitive.
// The same arguments don't apply for increment, where it is legal
// (though inadvisable) to share shared_ptr references between
// threads, and have them all get copied at once. The argument
// also doesn't apply for __release_shared, because an outstanding
// weak_ptr::lock() could read / modify the shared count.
if (__libcpp_atomic_load(&__shared_weak_owners_, _AO_Acquire) == 0)
{
// no need to do this store, because we are about
// to destroy everything.
//__libcpp_atomic_store(&__shared_weak_owners_, -1, _AO_Release);
__on_zero_shared_weak();
}
else if (__libcpp_atomic_refcount_decrement(__shared_weak_owners_) == -1)
__on_zero_shared_weak();
}
__shared_weak_count*
__shared_weak_count::lock() _NOEXCEPT
{
long object_owners = __libcpp_atomic_load(&__shared_owners_);
while (object_owners != -1)
{
if (__libcpp_atomic_compare_exchange(&__shared_owners_,
&object_owners,
object_owners+1))
return this;
}
return nullptr;
}
#if !defined(_LIBCPP_NO_RTTI) || !defined(_LIBCPP_BUILD_STATIC)
const void*
__shared_weak_count::__get_deleter(const type_info&) const _NOEXCEPT
{
return nullptr;
}
#endif // _LIBCPP_NO_RTTI
#if !defined(_LIBCPP_HAS_NO_ATOMIC_HEADER)
_LIBCPP_SAFE_STATIC static const std::size_t __sp_mut_count = 16;
_LIBCPP_SAFE_STATIC static __libcpp_mutex_t mut_back[__sp_mut_count] =
{
_LIBCPP_MUTEX_INITIALIZER, _LIBCPP_MUTEX_INITIALIZER, _LIBCPP_MUTEX_INITIALIZER, _LIBCPP_MUTEX_INITIALIZER,
_LIBCPP_MUTEX_INITIALIZER, _LIBCPP_MUTEX_INITIALIZER, _LIBCPP_MUTEX_INITIALIZER, _LIBCPP_MUTEX_INITIALIZER,
_LIBCPP_MUTEX_INITIALIZER, _LIBCPP_MUTEX_INITIALIZER, _LIBCPP_MUTEX_INITIALIZER, _LIBCPP_MUTEX_INITIALIZER,
_LIBCPP_MUTEX_INITIALIZER, _LIBCPP_MUTEX_INITIALIZER, _LIBCPP_MUTEX_INITIALIZER, _LIBCPP_MUTEX_INITIALIZER
};
_LIBCPP_CONSTEXPR __sp_mut::__sp_mut(void* p) _NOEXCEPT
: __lx(p)
{
}
void
__sp_mut::lock() _NOEXCEPT
{
auto m = static_cast<__libcpp_mutex_t*>(__lx);
unsigned count = 0;
while (!__libcpp_mutex_trylock(m))
{
if (++count > 16)
{
__libcpp_mutex_lock(m);
break;
}
this_thread::yield();
}
}
void
__sp_mut::unlock() _NOEXCEPT
{
__libcpp_mutex_unlock(static_cast<__libcpp_mutex_t*>(__lx));
}
__sp_mut&
__get_sp_mut(const void* p)
{
static __sp_mut muts[__sp_mut_count]
{
&mut_back[ 0], &mut_back[ 1], &mut_back[ 2], &mut_back[ 3],
&mut_back[ 4], &mut_back[ 5], &mut_back[ 6], &mut_back[ 7],
&mut_back[ 8], &mut_back[ 9], &mut_back[10], &mut_back[11],
&mut_back[12], &mut_back[13], &mut_back[14], &mut_back[15]
};
return muts[hash<const void*>()(p) & (__sp_mut_count-1)];
}
#endif // !defined(_LIBCPP_HAS_NO_ATOMIC_HEADER)
void
declare_reachable(void*)
{
}
void
declare_no_pointers(char*, size_t)
{
}
void
undeclare_no_pointers(char*, size_t)
{
}
#if !defined(_LIBCPP_ABI_POINTER_SAFETY_ENUM_TYPE)
pointer_safety get_pointer_safety() _NOEXCEPT
{
return pointer_safety::relaxed;
}
#endif
void*
__undeclare_reachable(void* p)
{
return p;
}
void*
align(size_t alignment, size_t size, void*& ptr, size_t& space)
{
void* r = nullptr;
if (size <= space)
{
char* p1 = static_cast<char*>(ptr);
char* p2 = reinterpret_cast<char*>(reinterpret_cast<size_t>(p1 + (alignment - 1)) & -alignment);
size_t d = static_cast<size_t>(p2 - p1);
if (d <= space - size)
{
r = p2;
ptr = r;
space -= d;
}
}
return r;
}
_LIBCPP_END_NAMESPACE_STD
| 6,503 | 240 | jart/cosmopolitan | false |
cosmopolitan/third_party/libcxx/version | // -*- C++ -*-
//===--------------------------- version ----------------------------------===//
//
// 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_VERSIONH
#define _LIBCPP_VERSIONH
#include "third_party/libcxx/__config"
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
#pragma GCC system_header
#endif
/*
version synopsis
Macro name Value Headers
__cpp_lib_addressof_constexpr 201603L <memory>
__cpp_lib_allocator_traits_is_always_equal 201411L <memory> <scoped_allocator> <string>
<deque> <forward_list> <list>
<vector> <map> <set>
<unordered_map> <unordered_set>
__cpp_lib_any 201606L <any>
__cpp_lib_apply 201603L <tuple>
__cpp_lib_array_constexpr 201603L <iterator> <array>
__cpp_lib_as_const 201510L <utility>
__cpp_lib_atomic_is_always_lock_free 201603L <atomic>
__cpp_lib_atomic_ref 201806L <atomic>
__cpp_lib_bind_front 201811L <functional>
__cpp_lib_bit_cast 201806L <bit>
__cpp_lib_bool_constant 201505L <type_traits>
__cpp_lib_boyer_moore_searcher 201603L <functional>
__cpp_lib_byte 201603L <cstddef>
__cpp_lib_char8_t 201811L <atomic> <filesystem> <istream>
<limits> <locale> <ostream>
<string> <string_view>
__cpp_lib_chrono 201611L <chrono>
__cpp_lib_chrono_udls 201304L <chrono>
__cpp_lib_clamp 201603L <algorithm>
__cpp_lib_complex_udls 201309L <complex>
__cpp_lib_concepts 201806L <concepts>
__cpp_lib_constexpr_misc 201811L <array> <functional> <iterator>
<string_view> <tuple> <utility>
__cpp_lib_constexpr_swap_algorithms 201806L <algorithm>
__cpp_lib_destroying_delete 201806L <new>
__cpp_lib_enable_shared_from_this 201603L <memory>
__cpp_lib_erase_if 201811L <string> <deque> <forward_list>
<list> <vector> <map>
<set> <unordered_map> <unordered_set>
__cpp_lib_exchange_function 201304L <utility>
__cpp_lib_execution 201603L <execution>
__cpp_lib_filesystem 201703L <filesystem>
__cpp_lib_gcd_lcm 201606L <numeric>
__cpp_lib_generic_associative_lookup 201304L <map> <set>
__cpp_lib_generic_unordered_lookup 201811L <unordered_map> <unordered_set>
__cpp_lib_hardware_interference_size 201703L <new>
__cpp_lib_has_unique_object_representations 201606L <type_traits>
__cpp_lib_hypot 201603L <cmath>
__cpp_lib_incomplete_container_elements 201505L <forward_list> <list> <vector>
__cpp_lib_integer_sequence 201304L <utility>
__cpp_lib_integral_constant_callable 201304L <type_traits>
__cpp_lib_interpolate 201902L <numeric>
__cpp_lib_invoke 201411L <functional>
__cpp_lib_is_aggregate 201703L <type_traits>
__cpp_lib_is_constant_evaluated 201811L <type_traits>
__cpp_lib_is_final 201402L <type_traits>
__cpp_lib_is_invocable 201703L <type_traits>
__cpp_lib_is_null_pointer 201309L <type_traits>
__cpp_lib_is_swappable 201603L <type_traits>
__cpp_lib_launder 201606L <new>
__cpp_lib_list_remove_return_type 201806L <forward_list> <list>
__cpp_lib_logical_traits 201510L <type_traits>
__cpp_lib_make_from_tuple 201606L <tuple>
__cpp_lib_make_reverse_iterator 201402L <iterator>
__cpp_lib_make_unique 201304L <memory>
__cpp_lib_map_try_emplace 201411L <map>
__cpp_lib_math_special_functions 201603L <cmath>
__cpp_lib_memory_resource 201603L <memory_resource>
__cpp_lib_node_extract 201606L <map> <set> <unordered_map>
<unordered_set>
__cpp_lib_nonmember_container_access 201411L <iterator> <array> <deque>
<forward_list> <list> <map>
<regex> <set> <string>
<unordered_map> <unordered_set> <vector>
__cpp_lib_not_fn 201603L <functional>
__cpp_lib_null_iterators 201304L <iterator>
__cpp_lib_optional 201606L <optional>
__cpp_lib_parallel_algorithm 201603L <algorithm> <numeric>
__cpp_lib_quoted_string_io 201304L <iomanip>
__cpp_lib_ranges 201811L <algorithm> <functional> <iterator>
<memory> <ranges>
__cpp_lib_raw_memory_algorithms 201606L <memory>
__cpp_lib_result_of_sfinae 201210L <functional> <type_traits>
__cpp_lib_robust_nonmodifying_seq_ops 201304L <algorithm>
__cpp_lib_sample 201603L <algorithm>
__cpp_lib_scoped_lock 201703L <mutex>
__cpp_lib_shared_mutex 201505L <shared_mutex>
__cpp_lib_shared_ptr_arrays 201611L <memory>
__cpp_lib_shared_ptr_weak_type 201606L <memory>
__cpp_lib_shared_timed_mutex 201402L <shared_mutex>
__cpp_lib_string_udls 201304L <string>
__cpp_lib_string_view 201606L <string> <string_view>
__cpp_lib_three_way_comparison 201711L <compare>
__cpp_lib_to_chars 201611L <utility>
__cpp_lib_transformation_trait_aliases 201304L <type_traits>
__cpp_lib_transparent_operators 201510L <functional>
201210L // C++14
__cpp_lib_tuple_element_t 201402L <tuple>
__cpp_lib_tuples_by_type 201304L <utility> <tuple>
__cpp_lib_type_trait_variable_templates 201510L <type_traits>
__cpp_lib_uncaught_exceptions 201411L <exception>
__cpp_lib_unordered_map_try_emplace 201411L <unordered_map>
__cpp_lib_variant 201606L <variant>
__cpp_lib_void_t 201411L <type_traits>
*/
#if _LIBCPP_STD_VER > 11
# define __cpp_lib_chrono_udls 201304L
# define __cpp_lib_complex_udls 201309L
# define __cpp_lib_exchange_function 201304L
# define __cpp_lib_generic_associative_lookup 201304L
# define __cpp_lib_integer_sequence 201304L
# define __cpp_lib_integral_constant_callable 201304L
# define __cpp_lib_is_final 201402L
# define __cpp_lib_is_null_pointer 201309L
# define __cpp_lib_make_reverse_iterator 201402L
# define __cpp_lib_make_unique 201304L
# define __cpp_lib_null_iterators 201304L
# define __cpp_lib_quoted_string_io 201304L
# define __cpp_lib_result_of_sfinae 201210L
# define __cpp_lib_robust_nonmodifying_seq_ops 201304L
# if !defined(_LIBCPP_HAS_NO_THREADS)
# define __cpp_lib_shared_timed_mutex 201402L
# endif
# define __cpp_lib_string_udls 201304L
# define __cpp_lib_transformation_trait_aliases 201304L
# define __cpp_lib_transparent_operators 201210L
# define __cpp_lib_tuple_element_t 201402L
# define __cpp_lib_tuples_by_type 201304L
#endif
#if _LIBCPP_STD_VER > 14
# if !defined(_LIBCPP_HAS_NO_BUILTIN_ADDRESSOF)
# define __cpp_lib_addressof_constexpr 201603L
# endif
# define __cpp_lib_allocator_traits_is_always_equal 201411L
# define __cpp_lib_any 201606L
# define __cpp_lib_apply 201603L
# define __cpp_lib_array_constexpr 201603L
# define __cpp_lib_as_const 201510L
# if !defined(_LIBCPP_HAS_NO_THREADS)
# define __cpp_lib_atomic_is_always_lock_free 201603L
# endif
# define __cpp_lib_bool_constant 201505L
// # define __cpp_lib_boyer_moore_searcher 201603L
# define __cpp_lib_byte 201603L
# define __cpp_lib_chrono 201611L
# define __cpp_lib_clamp 201603L
# define __cpp_lib_enable_shared_from_this 201603L
// # define __cpp_lib_execution 201603L
# define __cpp_lib_filesystem 201703L
# define __cpp_lib_gcd_lcm 201606L
# define __cpp_lib_hardware_interference_size 201703L
# if defined(_LIBCPP_HAS_UNIQUE_OBJECT_REPRESENTATIONS)
# define __cpp_lib_has_unique_object_representations 201606L
# endif
# define __cpp_lib_hypot 201603L
# define __cpp_lib_incomplete_container_elements 201505L
# define __cpp_lib_invoke 201411L
# if !defined(_LIBCPP_HAS_NO_IS_AGGREGATE)
# define __cpp_lib_is_aggregate 201703L
# endif
# define __cpp_lib_is_invocable 201703L
# define __cpp_lib_is_swappable 201603L
# define __cpp_lib_launder 201606L
# define __cpp_lib_logical_traits 201510L
# define __cpp_lib_make_from_tuple 201606L
# define __cpp_lib_map_try_emplace 201411L
// # define __cpp_lib_math_special_functions 201603L
// # define __cpp_lib_memory_resource 201603L
# define __cpp_lib_node_extract 201606L
# define __cpp_lib_nonmember_container_access 201411L
# define __cpp_lib_not_fn 201603L
# define __cpp_lib_optional 201606L
// # define __cpp_lib_parallel_algorithm 201603L
# define __cpp_lib_raw_memory_algorithms 201606L
# define __cpp_lib_sample 201603L
# define __cpp_lib_scoped_lock 201703L
# if !defined(_LIBCPP_HAS_NO_THREADS)
# define __cpp_lib_shared_mutex 201505L
# endif
// # define __cpp_lib_shared_ptr_arrays 201611L
# define __cpp_lib_shared_ptr_weak_type 201606L
# define __cpp_lib_string_view 201606L
// # define __cpp_lib_to_chars 201611L
# undef __cpp_lib_transparent_operators
# define __cpp_lib_transparent_operators 201510L
# define __cpp_lib_type_trait_variable_templates 201510L
# define __cpp_lib_uncaught_exceptions 201411L
# define __cpp_lib_unordered_map_try_emplace 201411L
# define __cpp_lib_variant 201606L
# define __cpp_lib_void_t 201411L
#endif
#if _LIBCPP_STD_VER > 17
# if !defined(_LIBCPP_HAS_NO_THREADS)
// # define __cpp_lib_atomic_ref 201806L
# endif
// # define __cpp_lib_bind_front 201811L
// # define __cpp_lib_bit_cast 201806L
# if !defined(_LIBCPP_NO_HAS_CHAR8_T)
# define __cpp_lib_char8_t 201811L
# endif
// # define __cpp_lib_concepts 201806L
// # define __cpp_lib_constexpr_misc 201811L
// # define __cpp_lib_constexpr_swap_algorithms 201806L
# if _LIBCPP_STD_VER > 17 && defined(__cpp_impl_destroying_delete) && __cpp_impl_destroying_delete >= 201806L
# define __cpp_lib_destroying_delete 201806L
# endif
# define __cpp_lib_erase_if 201811L
// # define __cpp_lib_generic_unordered_lookup 201811L
# define __cpp_lib_interpolate 201902L
# if !defined(_LIBCPP_HAS_NO_BUILTIN_IS_CONSTANT_EVALUATED)
# define __cpp_lib_is_constant_evaluated 201811L
# endif
// # define __cpp_lib_list_remove_return_type 201806L
// # define __cpp_lib_ranges 201811L
// # define __cpp_lib_three_way_comparison 201711L
#endif
#endif // _LIBCPP_VERSIONH
| 14,573 | 238 | jart/cosmopolitan | false |
cosmopolitan/third_party/libcxx/vector | // -*- C++ -*-
//===------------------------------ vector --------------------------------===//
//
// 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_VECTOR
#define _LIBCPP_VECTOR
#include "third_party/libcxx/__config"
#include "third_party/libcxx/iosfwd" // for forward declaration of vector
#include "third_party/libcxx/__bit_reference"
#include "third_party/libcxx/type_traits"
#include "third_party/libcxx/climits"
#include "third_party/libcxx/limits"
#include "third_party/libcxx/initializer_list"
#include "third_party/libcxx/memory"
#include "third_party/libcxx/stdexcept"
#include "third_party/libcxx/algorithm"
#include "third_party/libcxx/cstring"
#include "third_party/libcxx/version"
#include "third_party/libcxx/__split_buffer"
#include "third_party/libcxx/__functional_base"
#include "third_party/libcxx/__debug"
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
#pragma GCC system_header
#endif
_LIBCPP_PUSH_MACROS
#include "third_party/libcxx/__undef_macros"
_LIBCPP_BEGIN_NAMESPACE_STD
/*
vector synopsis
namespace std
{
template <class T, class Allocator = allocator<T> >
class vector
{
public:
typedef T value_type;
typedef Allocator allocator_type;
typedef typename allocator_type::reference reference;
typedef typename allocator_type::const_reference const_reference;
typedef implementation-defined iterator;
typedef implementation-defined const_iterator;
typedef typename allocator_type::size_type size_type;
typedef typename allocator_type::difference_type difference_type;
typedef typename allocator_type::pointer pointer;
typedef typename allocator_type::const_pointer const_pointer;
typedef std::reverse_iterator<iterator> reverse_iterator;
typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
vector()
noexcept(is_nothrow_default_constructible<allocator_type>::value);
explicit vector(const allocator_type&);
explicit vector(size_type n);
explicit vector(size_type n, const allocator_type&); // C++14
vector(size_type n, const value_type& value, const allocator_type& = allocator_type());
template <class InputIterator>
vector(InputIterator first, InputIterator last, const allocator_type& = allocator_type());
vector(const vector& x);
vector(vector&& x)
noexcept(is_nothrow_move_constructible<allocator_type>::value);
vector(initializer_list<value_type> il);
vector(initializer_list<value_type> il, const allocator_type& a);
~vector();
vector& operator=(const vector& x);
vector& operator=(vector&& x)
noexcept(
allocator_type::propagate_on_container_move_assignment::value ||
allocator_type::is_always_equal::value); // C++17
vector& operator=(initializer_list<value_type> il);
template <class InputIterator>
void assign(InputIterator first, InputIterator last);
void assign(size_type n, const value_type& u);
void assign(initializer_list<value_type> il);
allocator_type get_allocator() const noexcept;
iterator begin() noexcept;
const_iterator begin() const noexcept;
iterator end() noexcept;
const_iterator end() const noexcept;
reverse_iterator rbegin() noexcept;
const_reverse_iterator rbegin() const noexcept;
reverse_iterator rend() noexcept;
const_reverse_iterator rend() const noexcept;
const_iterator cbegin() const noexcept;
const_iterator cend() const noexcept;
const_reverse_iterator crbegin() const noexcept;
const_reverse_iterator crend() const noexcept;
size_type size() const noexcept;
size_type max_size() const noexcept;
size_type capacity() const noexcept;
bool empty() const noexcept;
void reserve(size_type n);
void shrink_to_fit() noexcept;
reference operator[](size_type n);
const_reference operator[](size_type n) const;
reference at(size_type n);
const_reference at(size_type n) const;
reference front();
const_reference front() const;
reference back();
const_reference back() const;
value_type* data() noexcept;
const value_type* data() const noexcept;
void push_back(const value_type& x);
void push_back(value_type&& x);
template <class... Args>
reference emplace_back(Args&&... args); // reference in C++17
void pop_back();
template <class... Args> iterator emplace(const_iterator position, Args&&... args);
iterator insert(const_iterator position, const value_type& x);
iterator insert(const_iterator position, value_type&& x);
iterator insert(const_iterator position, size_type n, const value_type& x);
template <class InputIterator>
iterator insert(const_iterator position, InputIterator first, InputIterator last);
iterator insert(const_iterator position, initializer_list<value_type> il);
iterator erase(const_iterator position);
iterator erase(const_iterator first, const_iterator last);
void clear() noexcept;
void resize(size_type sz);
void resize(size_type sz, const value_type& c);
void swap(vector&)
noexcept(allocator_traits<allocator_type>::propagate_on_container_swap::value ||
allocator_traits<allocator_type>::is_always_equal::value); // C++17
bool __invariants() const;
};
template <class Allocator = allocator<T> >
class vector<bool, Allocator>
{
public:
typedef bool value_type;
typedef Allocator allocator_type;
typedef implementation-defined iterator;
typedef implementation-defined const_iterator;
typedef typename allocator_type::size_type size_type;
typedef typename allocator_type::difference_type difference_type;
typedef iterator pointer;
typedef const_iterator const_pointer;
typedef std::reverse_iterator<iterator> reverse_iterator;
typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
class reference
{
public:
reference(const reference&) noexcept;
operator bool() const noexcept;
reference& operator=(const bool x) noexcept;
reference& operator=(const reference& x) noexcept;
iterator operator&() const noexcept;
void flip() noexcept;
};
class const_reference
{
public:
const_reference(const reference&) noexcept;
operator bool() const noexcept;
const_iterator operator&() const noexcept;
};
vector()
noexcept(is_nothrow_default_constructible<allocator_type>::value);
explicit vector(const allocator_type&);
explicit vector(size_type n, const allocator_type& a = allocator_type()); // C++14
vector(size_type n, const value_type& value, const allocator_type& = allocator_type());
template <class InputIterator>
vector(InputIterator first, InputIterator last, const allocator_type& = allocator_type());
vector(const vector& x);
vector(vector&& x)
noexcept(is_nothrow_move_constructible<allocator_type>::value);
vector(initializer_list<value_type> il);
vector(initializer_list<value_type> il, const allocator_type& a);
~vector();
vector& operator=(const vector& x);
vector& operator=(vector&& x)
noexcept(
allocator_type::propagate_on_container_move_assignment::value ||
allocator_type::is_always_equal::value); // C++17
vector& operator=(initializer_list<value_type> il);
template <class InputIterator>
void assign(InputIterator first, InputIterator last);
void assign(size_type n, const value_type& u);
void assign(initializer_list<value_type> il);
allocator_type get_allocator() const noexcept;
iterator begin() noexcept;
const_iterator begin() const noexcept;
iterator end() noexcept;
const_iterator end() const noexcept;
reverse_iterator rbegin() noexcept;
const_reverse_iterator rbegin() const noexcept;
reverse_iterator rend() noexcept;
const_reverse_iterator rend() const noexcept;
const_iterator cbegin() const noexcept;
const_iterator cend() const noexcept;
const_reverse_iterator crbegin() const noexcept;
const_reverse_iterator crend() const noexcept;
size_type size() const noexcept;
size_type max_size() const noexcept;
size_type capacity() const noexcept;
bool empty() const noexcept;
void reserve(size_type n);
void shrink_to_fit() noexcept;
reference operator[](size_type n);
const_reference operator[](size_type n) const;
reference at(size_type n);
const_reference at(size_type n) const;
reference front();
const_reference front() const;
reference back();
const_reference back() const;
void push_back(const value_type& x);
template <class... Args> reference emplace_back(Args&&... args); // C++14; reference in C++17
void pop_back();
template <class... Args> iterator emplace(const_iterator position, Args&&... args); // C++14
iterator insert(const_iterator position, const value_type& x);
iterator insert(const_iterator position, size_type n, const value_type& x);
template <class InputIterator>
iterator insert(const_iterator position, InputIterator first, InputIterator last);
iterator insert(const_iterator position, initializer_list<value_type> il);
iterator erase(const_iterator position);
iterator erase(const_iterator first, const_iterator last);
void clear() noexcept;
void resize(size_type sz);
void resize(size_type sz, value_type x);
void swap(vector&)
noexcept(allocator_traits<allocator_type>::propagate_on_container_swap::value ||
allocator_traits<allocator_type>::is_always_equal::value); // C++17
void flip() noexcept;
bool __invariants() const;
};
template <class InputIterator, class Allocator = allocator<typename iterator_traits<InputIterator>::value_type>>
vector(InputIterator, InputIterator, Allocator = Allocator())
-> vector<typename iterator_traits<InputIterator>::value_type, Allocator>;
template <class Allocator> struct hash<std::vector<bool, Allocator>>;
template <class T, class Allocator> bool operator==(const vector<T,Allocator>& x, const vector<T,Allocator>& y);
template <class T, class Allocator> bool operator< (const vector<T,Allocator>& x, const vector<T,Allocator>& y);
template <class T, class Allocator> bool operator!=(const vector<T,Allocator>& x, const vector<T,Allocator>& y);
template <class T, class Allocator> bool operator> (const vector<T,Allocator>& x, const vector<T,Allocator>& y);
template <class T, class Allocator> bool operator>=(const vector<T,Allocator>& x, const vector<T,Allocator>& y);
template <class T, class Allocator> bool operator<=(const vector<T,Allocator>& x, const vector<T,Allocator>& y);
template <class T, class Allocator>
void swap(vector<T,Allocator>& x, vector<T,Allocator>& y)
noexcept(noexcept(x.swap(y)));
template <class T, class Allocator, class U>
void erase(vector<T, Allocator>& c, const U& value); // C++20
template <class T, class Allocator, class Predicate>
void erase_if(vector<T, Allocator>& c, Predicate pred); // C++20
} // std
*/
template <bool>
class _LIBCPP_TEMPLATE_VIS __vector_base_common
{
protected:
_LIBCPP_INLINE_VISIBILITY __vector_base_common() {}
_LIBCPP_NORETURN void __throw_length_error() const;
_LIBCPP_NORETURN void __throw_out_of_range() const;
};
template <bool __b>
void
__vector_base_common<__b>::__throw_length_error() const
{
_VSTD::__throw_length_error("vector");
}
template <bool __b>
void
__vector_base_common<__b>::__throw_out_of_range() const
{
_VSTD::__throw_out_of_range("vector");
}
_LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS __vector_base_common<true>)
template <class _Tp, class _Allocator>
class __vector_base
: protected __vector_base_common<true>
{
public:
typedef _Allocator allocator_type;
typedef allocator_traits<allocator_type> __alloc_traits;
typedef typename __alloc_traits::size_type size_type;
protected:
typedef _Tp value_type;
typedef value_type& reference;
typedef const value_type& const_reference;
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 __begin_;
pointer __end_;
__compressed_pair<pointer, allocator_type> __end_cap_;
_LIBCPP_INLINE_VISIBILITY
allocator_type& __alloc() _NOEXCEPT
{return __end_cap_.second();}
_LIBCPP_INLINE_VISIBILITY
const allocator_type& __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
__vector_base()
_NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value);
_LIBCPP_INLINE_VISIBILITY __vector_base(const allocator_type& __a);
#ifndef _LIBCPP_CXX03_LANG
_LIBCPP_INLINE_VISIBILITY __vector_base(allocator_type&& __a) _NOEXCEPT;
#endif
~__vector_base();
_LIBCPP_INLINE_VISIBILITY
void clear() _NOEXCEPT {__destruct_at_end(__begin_);}
_LIBCPP_INLINE_VISIBILITY
size_type capacity() const _NOEXCEPT
{return static_cast<size_type>(__end_cap() - __begin_);}
_LIBCPP_INLINE_VISIBILITY
void __destruct_at_end(pointer __new_last) _NOEXCEPT;
_LIBCPP_INLINE_VISIBILITY
void __copy_assign_alloc(const __vector_base& __c)
{__copy_assign_alloc(__c, integral_constant<bool,
__alloc_traits::propagate_on_container_copy_assignment::value>());}
_LIBCPP_INLINE_VISIBILITY
void __move_assign_alloc(__vector_base& __c)
_NOEXCEPT_(
!__alloc_traits::propagate_on_container_move_assignment::value ||
is_nothrow_move_assignable<allocator_type>::value)
{__move_assign_alloc(__c, integral_constant<bool,
__alloc_traits::propagate_on_container_move_assignment::value>());}
private:
_LIBCPP_INLINE_VISIBILITY
void __copy_assign_alloc(const __vector_base& __c, true_type)
{
if (__alloc() != __c.__alloc())
{
clear();
__alloc_traits::deallocate(__alloc(), __begin_, capacity());
__begin_ = __end_ = __end_cap() = nullptr;
}
__alloc() = __c.__alloc();
}
_LIBCPP_INLINE_VISIBILITY
void __copy_assign_alloc(const __vector_base&, false_type)
{}
_LIBCPP_INLINE_VISIBILITY
void __move_assign_alloc(__vector_base& __c, true_type)
_NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value)
{
__alloc() = _VSTD::move(__c.__alloc());
}
_LIBCPP_INLINE_VISIBILITY
void __move_assign_alloc(__vector_base&, false_type)
_NOEXCEPT
{}
};
template <class _Tp, class _Allocator>
inline _LIBCPP_INLINE_VISIBILITY
void
__vector_base<_Tp, _Allocator>::__destruct_at_end(pointer __new_last) _NOEXCEPT
{
pointer __soon_to_be_end = __end_;
while (__new_last != __soon_to_be_end)
__alloc_traits::destroy(__alloc(), _VSTD::__to_raw_pointer(--__soon_to_be_end));
__end_ = __new_last;
}
template <class _Tp, class _Allocator>
inline _LIBCPP_INLINE_VISIBILITY
__vector_base<_Tp, _Allocator>::__vector_base()
_NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value)
: __begin_(nullptr),
__end_(nullptr),
__end_cap_(nullptr)
{
}
template <class _Tp, class _Allocator>
inline _LIBCPP_INLINE_VISIBILITY
__vector_base<_Tp, _Allocator>::__vector_base(const allocator_type& __a)
: __begin_(nullptr),
__end_(nullptr),
__end_cap_(nullptr, __a)
{
}
#ifndef _LIBCPP_CXX03_LANG
template <class _Tp, class _Allocator>
inline _LIBCPP_INLINE_VISIBILITY
__vector_base<_Tp, _Allocator>::__vector_base(allocator_type&& __a) _NOEXCEPT
: __begin_(nullptr),
__end_(nullptr),
__end_cap_(nullptr, std::move(__a)) {}
#endif
template <class _Tp, class _Allocator>
__vector_base<_Tp, _Allocator>::~__vector_base()
{
if (__begin_ != nullptr)
{
clear();
__alloc_traits::deallocate(__alloc(), __begin_, capacity());
}
}
template <class _Tp, class _Allocator /* = allocator<_Tp> */>
class _LIBCPP_TEMPLATE_VIS vector
: private __vector_base<_Tp, _Allocator>
{
private:
typedef __vector_base<_Tp, _Allocator> __base;
typedef allocator<_Tp> __default_allocator_type;
public:
typedef vector __self;
typedef _Tp value_type;
typedef _Allocator allocator_type;
typedef typename __base::__alloc_traits __alloc_traits;
typedef typename __base::reference reference;
typedef typename __base::const_reference const_reference;
typedef typename __base::size_type size_type;
typedef typename __base::difference_type difference_type;
typedef typename __base::pointer pointer;
typedef typename __base::const_pointer const_pointer;
typedef __wrap_iter<pointer> iterator;
typedef __wrap_iter<const_pointer> const_iterator;
typedef _VSTD::reverse_iterator<iterator> reverse_iterator;
typedef _VSTD::reverse_iterator<const_iterator> const_reverse_iterator;
static_assert((is_same<typename allocator_type::value_type, value_type>::value),
"Allocator::value_type must be same type as value_type");
_LIBCPP_INLINE_VISIBILITY
vector() _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value)
{
#if _LIBCPP_DEBUG_LEVEL >= 2
__get_db()->__insert_c(this);
#endif
}
_LIBCPP_INLINE_VISIBILITY explicit vector(const allocator_type& __a)
#if _LIBCPP_STD_VER <= 14
_NOEXCEPT_(is_nothrow_copy_constructible<allocator_type>::value)
#else
_NOEXCEPT
#endif
: __base(__a)
{
#if _LIBCPP_DEBUG_LEVEL >= 2
__get_db()->__insert_c(this);
#endif
}
explicit vector(size_type __n);
#if _LIBCPP_STD_VER > 11
explicit vector(size_type __n, const allocator_type& __a);
#endif
vector(size_type __n, const value_type& __x);
vector(size_type __n, const value_type& __x, const allocator_type& __a);
template <class _InputIterator>
vector(_InputIterator __first,
typename enable_if<__is_input_iterator <_InputIterator>::value &&
!__is_forward_iterator<_InputIterator>::value &&
is_constructible<
value_type,
typename iterator_traits<_InputIterator>::reference>::value,
_InputIterator>::type __last);
template <class _InputIterator>
vector(_InputIterator __first, _InputIterator __last, const allocator_type& __a,
typename enable_if<__is_input_iterator <_InputIterator>::value &&
!__is_forward_iterator<_InputIterator>::value &&
is_constructible<
value_type,
typename iterator_traits<_InputIterator>::reference>::value>::type* = 0);
template <class _ForwardIterator>
vector(_ForwardIterator __first,
typename enable_if<__is_forward_iterator<_ForwardIterator>::value &&
is_constructible<
value_type,
typename iterator_traits<_ForwardIterator>::reference>::value,
_ForwardIterator>::type __last);
template <class _ForwardIterator>
vector(_ForwardIterator __first, _ForwardIterator __last, const allocator_type& __a,
typename enable_if<__is_forward_iterator<_ForwardIterator>::value &&
is_constructible<
value_type,
typename iterator_traits<_ForwardIterator>::reference>::value>::type* = 0);
_LIBCPP_INLINE_VISIBILITY
~vector()
{
__annotate_delete();
#if _LIBCPP_DEBUG_LEVEL >= 2
__get_db()->__erase_c(this);
#endif
}
vector(const vector& __x);
vector(const vector& __x, const allocator_type& __a);
_LIBCPP_INLINE_VISIBILITY
vector& operator=(const vector& __x);
#ifndef _LIBCPP_CXX03_LANG
_LIBCPP_INLINE_VISIBILITY
vector(initializer_list<value_type> __il);
_LIBCPP_INLINE_VISIBILITY
vector(initializer_list<value_type> __il, const allocator_type& __a);
_LIBCPP_INLINE_VISIBILITY
vector(vector&& __x)
#if _LIBCPP_STD_VER > 14
_NOEXCEPT;
#else
_NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value);
#endif
_LIBCPP_INLINE_VISIBILITY
vector(vector&& __x, const allocator_type& __a);
_LIBCPP_INLINE_VISIBILITY
vector& operator=(vector&& __x)
_NOEXCEPT_((__noexcept_move_assign_container<_Allocator, __alloc_traits>::value));
_LIBCPP_INLINE_VISIBILITY
vector& operator=(initializer_list<value_type> __il)
{assign(__il.begin(), __il.end()); return *this;}
#endif // !_LIBCPP_CXX03_LANG
template <class _InputIterator>
typename enable_if
<
__is_input_iterator <_InputIterator>::value &&
!__is_forward_iterator<_InputIterator>::value &&
is_constructible<
value_type,
typename iterator_traits<_InputIterator>::reference>::value,
void
>::type
assign(_InputIterator __first, _InputIterator __last);
template <class _ForwardIterator>
typename enable_if
<
__is_forward_iterator<_ForwardIterator>::value &&
is_constructible<
value_type,
typename iterator_traits<_ForwardIterator>::reference>::value,
void
>::type
assign(_ForwardIterator __first, _ForwardIterator __last);
void assign(size_type __n, const_reference __u);
#ifndef _LIBCPP_CXX03_LANG
_LIBCPP_INLINE_VISIBILITY
void assign(initializer_list<value_type> __il)
{assign(__il.begin(), __il.end());}
#endif
_LIBCPP_INLINE_VISIBILITY
allocator_type get_allocator() const _NOEXCEPT
{return this->__alloc();}
_LIBCPP_INLINE_VISIBILITY iterator begin() _NOEXCEPT;
_LIBCPP_INLINE_VISIBILITY const_iterator begin() const _NOEXCEPT;
_LIBCPP_INLINE_VISIBILITY iterator end() _NOEXCEPT;
_LIBCPP_INLINE_VISIBILITY const_iterator end() const _NOEXCEPT;
_LIBCPP_INLINE_VISIBILITY
reverse_iterator rbegin() _NOEXCEPT
{return reverse_iterator(end());}
_LIBCPP_INLINE_VISIBILITY
const_reverse_iterator rbegin() const _NOEXCEPT
{return const_reverse_iterator(end());}
_LIBCPP_INLINE_VISIBILITY
reverse_iterator rend() _NOEXCEPT
{return reverse_iterator(begin());}
_LIBCPP_INLINE_VISIBILITY
const_reverse_iterator rend() const _NOEXCEPT
{return const_reverse_iterator(begin());}
_LIBCPP_INLINE_VISIBILITY
const_iterator cbegin() const _NOEXCEPT
{return begin();}
_LIBCPP_INLINE_VISIBILITY
const_iterator cend() const _NOEXCEPT
{return end();}
_LIBCPP_INLINE_VISIBILITY
const_reverse_iterator crbegin() const _NOEXCEPT
{return rbegin();}
_LIBCPP_INLINE_VISIBILITY
const_reverse_iterator crend() const _NOEXCEPT
{return rend();}
_LIBCPP_INLINE_VISIBILITY
size_type size() const _NOEXCEPT
{return static_cast<size_type>(this->__end_ - this->__begin_);}
_LIBCPP_INLINE_VISIBILITY
size_type capacity() const _NOEXCEPT
{return __base::capacity();}
_LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
bool empty() const _NOEXCEPT
{return this->__begin_ == this->__end_;}
size_type max_size() const _NOEXCEPT;
void reserve(size_type __n);
void shrink_to_fit() _NOEXCEPT;
_LIBCPP_INLINE_VISIBILITY reference operator[](size_type __n) _NOEXCEPT;
_LIBCPP_INLINE_VISIBILITY const_reference operator[](size_type __n) const _NOEXCEPT;
reference at(size_type __n);
const_reference at(size_type __n) const;
_LIBCPP_INLINE_VISIBILITY reference front() _NOEXCEPT
{
_LIBCPP_ASSERT(!empty(), "front() called for empty vector");
return *this->__begin_;
}
_LIBCPP_INLINE_VISIBILITY const_reference front() const _NOEXCEPT
{
_LIBCPP_ASSERT(!empty(), "front() called for empty vector");
return *this->__begin_;
}
_LIBCPP_INLINE_VISIBILITY reference back() _NOEXCEPT
{
_LIBCPP_ASSERT(!empty(), "back() called for empty vector");
return *(this->__end_ - 1);
}
_LIBCPP_INLINE_VISIBILITY const_reference back() const _NOEXCEPT
{
_LIBCPP_ASSERT(!empty(), "back() called for empty vector");
return *(this->__end_ - 1);
}
_LIBCPP_INLINE_VISIBILITY
value_type* data() _NOEXCEPT
{return _VSTD::__to_raw_pointer(this->__begin_);}
_LIBCPP_INLINE_VISIBILITY
const value_type* data() const _NOEXCEPT
{return _VSTD::__to_raw_pointer(this->__begin_);}
#ifdef _LIBCPP_CXX03_LANG
_LIBCPP_INLINE_VISIBILITY
void __emplace_back(const value_type& __x) { push_back(__x); }
#else
template <class _Arg>
_LIBCPP_INLINE_VISIBILITY
void __emplace_back(_Arg&& __arg) {
emplace_back(_VSTD::forward<_Arg>(__arg));
}
#endif
_LIBCPP_INLINE_VISIBILITY void push_back(const_reference __x);
#ifndef _LIBCPP_CXX03_LANG
_LIBCPP_INLINE_VISIBILITY void push_back(value_type&& __x);
template <class... _Args>
_LIBCPP_INLINE_VISIBILITY
#if _LIBCPP_STD_VER > 14
reference emplace_back(_Args&&... __args);
#else
void emplace_back(_Args&&... __args);
#endif
#endif // !_LIBCPP_CXX03_LANG
_LIBCPP_INLINE_VISIBILITY
void pop_back();
iterator insert(const_iterator __position, const_reference __x);
#ifndef _LIBCPP_CXX03_LANG
iterator insert(const_iterator __position, value_type&& __x);
template <class... _Args>
iterator emplace(const_iterator __position, _Args&&... __args);
#endif // !_LIBCPP_CXX03_LANG
iterator insert(const_iterator __position, size_type __n, const_reference __x);
template <class _InputIterator>
typename enable_if
<
__is_input_iterator <_InputIterator>::value &&
!__is_forward_iterator<_InputIterator>::value &&
is_constructible<
value_type,
typename iterator_traits<_InputIterator>::reference>::value,
iterator
>::type
insert(const_iterator __position, _InputIterator __first, _InputIterator __last);
template <class _ForwardIterator>
typename enable_if
<
__is_forward_iterator<_ForwardIterator>::value &&
is_constructible<
value_type,
typename iterator_traits<_ForwardIterator>::reference>::value,
iterator
>::type
insert(const_iterator __position, _ForwardIterator __first, _ForwardIterator __last);
#ifndef _LIBCPP_CXX03_LANG
_LIBCPP_INLINE_VISIBILITY
iterator insert(const_iterator __position, initializer_list<value_type> __il)
{return insert(__position, __il.begin(), __il.end());}
#endif
_LIBCPP_INLINE_VISIBILITY iterator erase(const_iterator __position);
iterator erase(const_iterator __first, const_iterator __last);
_LIBCPP_INLINE_VISIBILITY
void clear() _NOEXCEPT
{
size_type __old_size = size();
__base::clear();
__annotate_shrink(__old_size);
__invalidate_all_iterators();
}
void resize(size_type __sz);
void resize(size_type __sz, const_reference __x);
void swap(vector&)
#if _LIBCPP_STD_VER >= 14
_NOEXCEPT;
#else
_NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value ||
__is_nothrow_swappable<allocator_type>::value);
#endif
bool __invariants() const;
#if _LIBCPP_DEBUG_LEVEL >= 2
bool __dereferenceable(const const_iterator* __i) const;
bool __decrementable(const const_iterator* __i) const;
bool __addable(const const_iterator* __i, ptrdiff_t __n) const;
bool __subscriptable(const const_iterator* __i, ptrdiff_t __n) const;
#endif // _LIBCPP_DEBUG_LEVEL >= 2
private:
_LIBCPP_INLINE_VISIBILITY void __invalidate_all_iterators();
_LIBCPP_INLINE_VISIBILITY void __invalidate_iterators_past(pointer __new_last);
void __vallocate(size_type __n);
void __vdeallocate() _NOEXCEPT;
_LIBCPP_INLINE_VISIBILITY size_type __recommend(size_type __new_size) const;
void __construct_at_end(size_type __n);
_LIBCPP_INLINE_VISIBILITY
void __construct_at_end(size_type __n, const_reference __x);
template <class _ForwardIterator>
typename enable_if
<
__is_forward_iterator<_ForwardIterator>::value,
void
>::type
__construct_at_end(_ForwardIterator __first, _ForwardIterator __last, size_type __n);
void __append(size_type __n);
void __append(size_type __n, const_reference __x);
_LIBCPP_INLINE_VISIBILITY
iterator __make_iter(pointer __p) _NOEXCEPT;
_LIBCPP_INLINE_VISIBILITY
const_iterator __make_iter(const_pointer __p) const _NOEXCEPT;
void __swap_out_circular_buffer(__split_buffer<value_type, allocator_type&>& __v);
pointer __swap_out_circular_buffer(__split_buffer<value_type, allocator_type&>& __v, pointer __p);
void __move_range(pointer __from_s, pointer __from_e, pointer __to);
void __move_assign(vector& __c, true_type)
_NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value);
void __move_assign(vector& __c, false_type)
_NOEXCEPT_(__alloc_traits::is_always_equal::value);
_LIBCPP_INLINE_VISIBILITY
void __destruct_at_end(pointer __new_last) _NOEXCEPT
{
__invalidate_iterators_past(__new_last);
size_type __old_size = size();
__base::__destruct_at_end(__new_last);
__annotate_shrink(__old_size);
}
#ifndef _LIBCPP_CXX03_LANG
template <class _Up>
_LIBCPP_INLINE_VISIBILITY
inline void __push_back_slow_path(_Up&& __x);
template <class... _Args>
_LIBCPP_INLINE_VISIBILITY
inline void __emplace_back_slow_path(_Args&&... __args);
#else
template <class _Up>
_LIBCPP_INLINE_VISIBILITY
inline void __push_back_slow_path(_Up& __x);
#endif
// The following functions are no-ops outside of AddressSanitizer mode.
// We call annotatations only for the default Allocator because other allocators
// may not meet the AddressSanitizer alignment constraints.
// See the documentation for __sanitizer_annotate_contiguous_container for more details.
#ifndef _LIBCPP_HAS_NO_ASAN
void __annotate_contiguous_container(const void *__beg, const void *__end,
const void *__old_mid,
const void *__new_mid) const
{
if (__beg && is_same<allocator_type, __default_allocator_type>::value)
__sanitizer_annotate_contiguous_container(__beg, __end, __old_mid, __new_mid);
}
#else
_LIBCPP_INLINE_VISIBILITY
void __annotate_contiguous_container(const void*, const void*, const void*,
const void*) const _NOEXCEPT {}
#endif
_LIBCPP_INLINE_VISIBILITY
void __annotate_new(size_type __current_size) const _NOEXCEPT {
__annotate_contiguous_container(data(), data() + capacity(),
data() + capacity(), data() + __current_size);
}
_LIBCPP_INLINE_VISIBILITY
void __annotate_delete() const _NOEXCEPT {
__annotate_contiguous_container(data(), data() + capacity(),
data() + size(), data() + capacity());
}
_LIBCPP_INLINE_VISIBILITY
void __annotate_increase(size_type __n) const _NOEXCEPT
{
__annotate_contiguous_container(data(), data() + capacity(),
data() + size(), data() + size() + __n);
}
_LIBCPP_INLINE_VISIBILITY
void __annotate_shrink(size_type __old_size) const _NOEXCEPT
{
__annotate_contiguous_container(data(), data() + capacity(),
data() + __old_size, data() + size());
}
struct _ConstructTransaction {
explicit _ConstructTransaction(vector &__v, size_type __n)
: __v_(__v), __pos_(__v.__end_), __new_end_(__v.__end_ + __n) {
#ifndef _LIBCPP_HAS_NO_ASAN
__v_.__annotate_increase(__n);
#endif
}
~_ConstructTransaction() {
__v_.__end_ = __pos_;
#ifndef _LIBCPP_HAS_NO_ASAN
if (__pos_ != __new_end_) {
__v_.__annotate_shrink(__new_end_ - __v_.__begin_);
}
#endif
}
vector &__v_;
pointer __pos_;
const_pointer const __new_end_;
private:
_ConstructTransaction(_ConstructTransaction const&) = delete;
_ConstructTransaction& operator=(_ConstructTransaction const&) = delete;
};
template <class ..._Args>
_LIBCPP_INLINE_VISIBILITY
void __construct_one_at_end(_Args&& ...__args) {
_ConstructTransaction __tx(*this, 1);
__alloc_traits::construct(this->__alloc(), _VSTD::__to_raw_pointer(__tx.__pos_),
_VSTD::forward<_Args>(__args)...);
++__tx.__pos_;
}
};
#ifndef _LIBCPP_HAS_NO_DEDUCTION_GUIDES
template<class _InputIterator,
class _Alloc = typename std::allocator<typename iterator_traits<_InputIterator>::value_type>,
class = typename enable_if<__is_allocator<_Alloc>::value, void>::type
>
vector(_InputIterator, _InputIterator)
-> vector<typename iterator_traits<_InputIterator>::value_type, _Alloc>;
template<class _InputIterator,
class _Alloc,
class = typename enable_if<__is_allocator<_Alloc>::value, void>::type
>
vector(_InputIterator, _InputIterator, _Alloc)
-> vector<typename iterator_traits<_InputIterator>::value_type, _Alloc>;
#endif
template <class _Tp, class _Allocator>
void
vector<_Tp, _Allocator>::__swap_out_circular_buffer(__split_buffer<value_type, allocator_type&>& __v)
{
__annotate_delete();
__alloc_traits::__construct_backward_with_exception_guarantees(
this->__alloc(), this->__begin_, this->__end_, __v.__begin_);
_VSTD::swap(this->__begin_, __v.__begin_);
_VSTD::swap(this->__end_, __v.__end_);
_VSTD::swap(this->__end_cap(), __v.__end_cap());
__v.__first_ = __v.__begin_;
__annotate_new(size());
__invalidate_all_iterators();
}
template <class _Tp, class _Allocator>
typename vector<_Tp, _Allocator>::pointer
vector<_Tp, _Allocator>::__swap_out_circular_buffer(__split_buffer<value_type, allocator_type&>& __v, pointer __p)
{
__annotate_delete();
pointer __r = __v.__begin_;
__alloc_traits::__construct_backward_with_exception_guarantees(
this->__alloc(), this->__begin_, __p, __v.__begin_);
__alloc_traits::__construct_forward_with_exception_guarantees(
this->__alloc(), __p, this->__end_, __v.__end_);
_VSTD::swap(this->__begin_, __v.__begin_);
_VSTD::swap(this->__end_, __v.__end_);
_VSTD::swap(this->__end_cap(), __v.__end_cap());
__v.__first_ = __v.__begin_;
__annotate_new(size());
__invalidate_all_iterators();
return __r;
}
// Allocate space for __n objects
// throws length_error if __n > max_size()
// throws (probably bad_alloc) if memory run out
// Precondition: __begin_ == __end_ == __end_cap() == 0
// Precondition: __n > 0
// Postcondition: capacity() == __n
// Postcondition: size() == 0
template <class _Tp, class _Allocator>
void
vector<_Tp, _Allocator>::__vallocate(size_type __n)
{
if (__n > max_size())
this->__throw_length_error();
this->__begin_ = this->__end_ = __alloc_traits::allocate(this->__alloc(), __n);
this->__end_cap() = this->__begin_ + __n;
__annotate_new(0);
}
template <class _Tp, class _Allocator>
void
vector<_Tp, _Allocator>::__vdeallocate() _NOEXCEPT
{
if (this->__begin_ != nullptr)
{
clear();
__alloc_traits::deallocate(this->__alloc(), this->__begin_, capacity());
this->__begin_ = this->__end_ = this->__end_cap() = nullptr;
}
}
template <class _Tp, class _Allocator>
typename vector<_Tp, _Allocator>::size_type
vector<_Tp, _Allocator>::max_size() const _NOEXCEPT
{
return _VSTD::min<size_type>(__alloc_traits::max_size(this->__alloc()),
numeric_limits<difference_type>::max());
}
// Precondition: __new_size > capacity()
template <class _Tp, class _Allocator>
inline _LIBCPP_INLINE_VISIBILITY
typename vector<_Tp, _Allocator>::size_type
vector<_Tp, _Allocator>::__recommend(size_type __new_size) const
{
const size_type __ms = max_size();
if (__new_size > __ms)
this->__throw_length_error();
const size_type __cap = capacity();
if (__cap >= __ms / 2)
return __ms;
return _VSTD::max<size_type>(2*__cap, __new_size);
}
// 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
vector<_Tp, _Allocator>::__construct_at_end(size_type __n)
{
_ConstructTransaction __tx(*this, __n);
for (; __tx.__pos_ != __tx.__new_end_; ++__tx.__pos_) {
__alloc_traits::construct(this->__alloc(), _VSTD::__to_raw_pointer(__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>
inline
void
vector<_Tp, _Allocator>::__construct_at_end(size_type __n, const_reference __x)
{
_ConstructTransaction __tx(*this, __n);
for (; __tx.__pos_ != __tx.__new_end_; ++__tx.__pos_) {
__alloc_traits::construct(this->__alloc(), _VSTD::__to_raw_pointer(__tx.__pos_), __x);
}
}
template <class _Tp, class _Allocator>
template <class _ForwardIterator>
typename enable_if
<
__is_forward_iterator<_ForwardIterator>::value,
void
>::type
vector<_Tp, _Allocator>::__construct_at_end(_ForwardIterator __first, _ForwardIterator __last, size_type __n)
{
_ConstructTransaction __tx(*this, __n);
__alloc_traits::__construct_range_forward(this->__alloc(), __first, __last, __tx.__pos_);
}
// Default constructs __n objects starting at __end_
// throws if construction throws
// Postcondition: size() == size() + __n
// Exception safety: strong.
template <class _Tp, class _Allocator>
void
vector<_Tp, _Allocator>::__append(size_type __n)
{
if (static_cast<size_type>(this->__end_cap() - this->__end_) >= __n)
this->__construct_at_end(__n);
else
{
allocator_type& __a = this->__alloc();
__split_buffer<value_type, allocator_type&> __v(__recommend(size() + __n), size(), __a);
__v.__construct_at_end(__n);
__swap_out_circular_buffer(__v);
}
}
// Default constructs __n objects starting at __end_
// throws if construction throws
// Postcondition: size() == size() + __n
// Exception safety: strong.
template <class _Tp, class _Allocator>
void
vector<_Tp, _Allocator>::__append(size_type __n, const_reference __x)
{
if (static_cast<size_type>(this->__end_cap() - this->__end_) >= __n)
this->__construct_at_end(__n, __x);
else
{
allocator_type& __a = this->__alloc();
__split_buffer<value_type, allocator_type&> __v(__recommend(size() + __n), size(), __a);
__v.__construct_at_end(__n, __x);
__swap_out_circular_buffer(__v);
}
}
template <class _Tp, class _Allocator>
vector<_Tp, _Allocator>::vector(size_type __n)
{
#if _LIBCPP_DEBUG_LEVEL >= 2
__get_db()->__insert_c(this);
#endif
if (__n > 0)
{
__vallocate(__n);
__construct_at_end(__n);
}
}
#if _LIBCPP_STD_VER > 11
template <class _Tp, class _Allocator>
vector<_Tp, _Allocator>::vector(size_type __n, const allocator_type& __a)
: __base(__a)
{
#if _LIBCPP_DEBUG_LEVEL >= 2
__get_db()->__insert_c(this);
#endif
if (__n > 0)
{
__vallocate(__n);
__construct_at_end(__n);
}
}
#endif
template <class _Tp, class _Allocator>
vector<_Tp, _Allocator>::vector(size_type __n, const value_type& __x)
{
#if _LIBCPP_DEBUG_LEVEL >= 2
__get_db()->__insert_c(this);
#endif
if (__n > 0)
{
__vallocate(__n);
__construct_at_end(__n, __x);
}
}
template <class _Tp, class _Allocator>
vector<_Tp, _Allocator>::vector(size_type __n, const value_type& __x, const allocator_type& __a)
: __base(__a)
{
#if _LIBCPP_DEBUG_LEVEL >= 2
__get_db()->__insert_c(this);
#endif
if (__n > 0)
{
__vallocate(__n);
__construct_at_end(__n, __x);
}
}
template <class _Tp, class _Allocator>
template <class _InputIterator>
vector<_Tp, _Allocator>::vector(_InputIterator __first,
typename enable_if<__is_input_iterator <_InputIterator>::value &&
!__is_forward_iterator<_InputIterator>::value &&
is_constructible<
value_type,
typename iterator_traits<_InputIterator>::reference>::value,
_InputIterator>::type __last)
{
#if _LIBCPP_DEBUG_LEVEL >= 2
__get_db()->__insert_c(this);
#endif
for (; __first != __last; ++__first)
__emplace_back(*__first);
}
template <class _Tp, class _Allocator>
template <class _InputIterator>
vector<_Tp, _Allocator>::vector(_InputIterator __first, _InputIterator __last, const allocator_type& __a,
typename enable_if<__is_input_iterator <_InputIterator>::value &&
!__is_forward_iterator<_InputIterator>::value &&
is_constructible<
value_type,
typename iterator_traits<_InputIterator>::reference>::value>::type*)
: __base(__a)
{
#if _LIBCPP_DEBUG_LEVEL >= 2
__get_db()->__insert_c(this);
#endif
for (; __first != __last; ++__first)
__emplace_back(*__first);
}
template <class _Tp, class _Allocator>
template <class _ForwardIterator>
vector<_Tp, _Allocator>::vector(_ForwardIterator __first,
typename enable_if<__is_forward_iterator<_ForwardIterator>::value &&
is_constructible<
value_type,
typename iterator_traits<_ForwardIterator>::reference>::value,
_ForwardIterator>::type __last)
{
#if _LIBCPP_DEBUG_LEVEL >= 2
__get_db()->__insert_c(this);
#endif
size_type __n = static_cast<size_type>(_VSTD::distance(__first, __last));
if (__n > 0)
{
__vallocate(__n);
__construct_at_end(__first, __last, __n);
}
}
template <class _Tp, class _Allocator>
template <class _ForwardIterator>
vector<_Tp, _Allocator>::vector(_ForwardIterator __first, _ForwardIterator __last, const allocator_type& __a,
typename enable_if<__is_forward_iterator<_ForwardIterator>::value &&
is_constructible<
value_type,
typename iterator_traits<_ForwardIterator>::reference>::value>::type*)
: __base(__a)
{
#if _LIBCPP_DEBUG_LEVEL >= 2
__get_db()->__insert_c(this);
#endif
size_type __n = static_cast<size_type>(_VSTD::distance(__first, __last));
if (__n > 0)
{
__vallocate(__n);
__construct_at_end(__first, __last, __n);
}
}
template <class _Tp, class _Allocator>
vector<_Tp, _Allocator>::vector(const vector& __x)
: __base(__alloc_traits::select_on_container_copy_construction(__x.__alloc()))
{
#if _LIBCPP_DEBUG_LEVEL >= 2
__get_db()->__insert_c(this);
#endif
size_type __n = __x.size();
if (__n > 0)
{
__vallocate(__n);
__construct_at_end(__x.__begin_, __x.__end_, __n);
}
}
template <class _Tp, class _Allocator>
vector<_Tp, _Allocator>::vector(const vector& __x, const allocator_type& __a)
: __base(__a)
{
#if _LIBCPP_DEBUG_LEVEL >= 2
__get_db()->__insert_c(this);
#endif
size_type __n = __x.size();
if (__n > 0)
{
__vallocate(__n);
__construct_at_end(__x.__begin_, __x.__end_, __n);
}
}
#ifndef _LIBCPP_CXX03_LANG
template <class _Tp, class _Allocator>
inline _LIBCPP_INLINE_VISIBILITY
vector<_Tp, _Allocator>::vector(vector&& __x)
#if _LIBCPP_STD_VER > 14
_NOEXCEPT
#else
_NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value)
#endif
: __base(_VSTD::move(__x.__alloc()))
{
#if _LIBCPP_DEBUG_LEVEL >= 2
__get_db()->__insert_c(this);
__get_db()->swap(this, &__x);
#endif
this->__begin_ = __x.__begin_;
this->__end_ = __x.__end_;
this->__end_cap() = __x.__end_cap();
__x.__begin_ = __x.__end_ = __x.__end_cap() = nullptr;
}
template <class _Tp, class _Allocator>
inline _LIBCPP_INLINE_VISIBILITY
vector<_Tp, _Allocator>::vector(vector&& __x, const allocator_type& __a)
: __base(__a)
{
#if _LIBCPP_DEBUG_LEVEL >= 2
__get_db()->__insert_c(this);
#endif
if (__a == __x.__alloc())
{
this->__begin_ = __x.__begin_;
this->__end_ = __x.__end_;
this->__end_cap() = __x.__end_cap();
__x.__begin_ = __x.__end_ = __x.__end_cap() = nullptr;
#if _LIBCPP_DEBUG_LEVEL >= 2
__get_db()->swap(this, &__x);
#endif
}
else
{
typedef move_iterator<iterator> _Ip;
assign(_Ip(__x.begin()), _Ip(__x.end()));
}
}
template <class _Tp, class _Allocator>
inline _LIBCPP_INLINE_VISIBILITY
vector<_Tp, _Allocator>::vector(initializer_list<value_type> __il)
{
#if _LIBCPP_DEBUG_LEVEL >= 2
__get_db()->__insert_c(this);
#endif
if (__il.size() > 0)
{
__vallocate(__il.size());
__construct_at_end(__il.begin(), __il.end(), __il.size());
}
}
template <class _Tp, class _Allocator>
inline _LIBCPP_INLINE_VISIBILITY
vector<_Tp, _Allocator>::vector(initializer_list<value_type> __il, const allocator_type& __a)
: __base(__a)
{
#if _LIBCPP_DEBUG_LEVEL >= 2
__get_db()->__insert_c(this);
#endif
if (__il.size() > 0)
{
__vallocate(__il.size());
__construct_at_end(__il.begin(), __il.end(), __il.size());
}
}
template <class _Tp, class _Allocator>
inline _LIBCPP_INLINE_VISIBILITY
vector<_Tp, _Allocator>&
vector<_Tp, _Allocator>::operator=(vector&& __x)
_NOEXCEPT_((__noexcept_move_assign_container<_Allocator, __alloc_traits>::value))
{
__move_assign(__x, integral_constant<bool,
__alloc_traits::propagate_on_container_move_assignment::value>());
return *this;
}
template <class _Tp, class _Allocator>
void
vector<_Tp, _Allocator>::__move_assign(vector& __c, false_type)
_NOEXCEPT_(__alloc_traits::is_always_equal::value)
{
if (__base::__alloc() != __c.__alloc())
{
typedef move_iterator<iterator> _Ip;
assign(_Ip(__c.begin()), _Ip(__c.end()));
}
else
__move_assign(__c, true_type());
}
template <class _Tp, class _Allocator>
void
vector<_Tp, _Allocator>::__move_assign(vector& __c, true_type)
_NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value)
{
__vdeallocate();
__base::__move_assign_alloc(__c); // this can throw
this->__begin_ = __c.__begin_;
this->__end_ = __c.__end_;
this->__end_cap() = __c.__end_cap();
__c.__begin_ = __c.__end_ = __c.__end_cap() = nullptr;
#if _LIBCPP_DEBUG_LEVEL >= 2
__get_db()->swap(this, &__c);
#endif
}
#endif // !_LIBCPP_CXX03_LANG
template <class _Tp, class _Allocator>
inline _LIBCPP_INLINE_VISIBILITY
vector<_Tp, _Allocator>&
vector<_Tp, _Allocator>::operator=(const vector& __x)
{
if (this != &__x)
{
__base::__copy_assign_alloc(__x);
assign(__x.__begin_, __x.__end_);
}
return *this;
}
template <class _Tp, class _Allocator>
template <class _InputIterator>
typename enable_if
<
__is_input_iterator <_InputIterator>::value &&
!__is_forward_iterator<_InputIterator>::value &&
is_constructible<
_Tp,
typename iterator_traits<_InputIterator>::reference>::value,
void
>::type
vector<_Tp, _Allocator>::assign(_InputIterator __first, _InputIterator __last)
{
clear();
for (; __first != __last; ++__first)
__emplace_back(*__first);
}
template <class _Tp, class _Allocator>
template <class _ForwardIterator>
typename enable_if
<
__is_forward_iterator<_ForwardIterator>::value &&
is_constructible<
_Tp,
typename iterator_traits<_ForwardIterator>::reference>::value,
void
>::type
vector<_Tp, _Allocator>::assign(_ForwardIterator __first, _ForwardIterator __last)
{
size_type __new_size = static_cast<size_type>(_VSTD::distance(__first, __last));
if (__new_size <= capacity())
{
_ForwardIterator __mid = __last;
bool __growing = false;
if (__new_size > size())
{
__growing = true;
__mid = __first;
_VSTD::advance(__mid, size());
}
pointer __m = _VSTD::copy(__first, __mid, this->__begin_);
if (__growing)
__construct_at_end(__mid, __last, __new_size - size());
else
this->__destruct_at_end(__m);
}
else
{
__vdeallocate();
__vallocate(__recommend(__new_size));
__construct_at_end(__first, __last, __new_size);
}
__invalidate_all_iterators();
}
template <class _Tp, class _Allocator>
void
vector<_Tp, _Allocator>::assign(size_type __n, const_reference __u)
{
if (__n <= capacity())
{
size_type __s = size();
_VSTD::fill_n(this->__begin_, _VSTD::min(__n, __s), __u);
if (__n > __s)
__construct_at_end(__n - __s, __u);
else
this->__destruct_at_end(this->__begin_ + __n);
}
else
{
__vdeallocate();
__vallocate(__recommend(static_cast<size_type>(__n)));
__construct_at_end(__n, __u);
}
__invalidate_all_iterators();
}
template <class _Tp, class _Allocator>
inline _LIBCPP_INLINE_VISIBILITY
typename vector<_Tp, _Allocator>::iterator
vector<_Tp, _Allocator>::__make_iter(pointer __p) _NOEXCEPT
{
#if _LIBCPP_DEBUG_LEVEL >= 2
return iterator(this, __p);
#else
return iterator(__p);
#endif
}
template <class _Tp, class _Allocator>
inline _LIBCPP_INLINE_VISIBILITY
typename vector<_Tp, _Allocator>::const_iterator
vector<_Tp, _Allocator>::__make_iter(const_pointer __p) const _NOEXCEPT
{
#if _LIBCPP_DEBUG_LEVEL >= 2
return const_iterator(this, __p);
#else
return const_iterator(__p);
#endif
}
template <class _Tp, class _Allocator>
inline _LIBCPP_INLINE_VISIBILITY
typename vector<_Tp, _Allocator>::iterator
vector<_Tp, _Allocator>::begin() _NOEXCEPT
{
return __make_iter(this->__begin_);
}
template <class _Tp, class _Allocator>
inline _LIBCPP_INLINE_VISIBILITY
typename vector<_Tp, _Allocator>::const_iterator
vector<_Tp, _Allocator>::begin() const _NOEXCEPT
{
return __make_iter(this->__begin_);
}
template <class _Tp, class _Allocator>
inline _LIBCPP_INLINE_VISIBILITY
typename vector<_Tp, _Allocator>::iterator
vector<_Tp, _Allocator>::end() _NOEXCEPT
{
return __make_iter(this->__end_);
}
template <class _Tp, class _Allocator>
inline _LIBCPP_INLINE_VISIBILITY
typename vector<_Tp, _Allocator>::const_iterator
vector<_Tp, _Allocator>::end() const _NOEXCEPT
{
return __make_iter(this->__end_);
}
template <class _Tp, class _Allocator>
inline _LIBCPP_INLINE_VISIBILITY
typename vector<_Tp, _Allocator>::reference
vector<_Tp, _Allocator>::operator[](size_type __n) _NOEXCEPT
{
_LIBCPP_ASSERT(__n < size(), "vector[] index out of bounds");
return this->__begin_[__n];
}
template <class _Tp, class _Allocator>
inline _LIBCPP_INLINE_VISIBILITY
typename vector<_Tp, _Allocator>::const_reference
vector<_Tp, _Allocator>::operator[](size_type __n) const _NOEXCEPT
{
_LIBCPP_ASSERT(__n < size(), "vector[] index out of bounds");
return this->__begin_[__n];
}
template <class _Tp, class _Allocator>
typename vector<_Tp, _Allocator>::reference
vector<_Tp, _Allocator>::at(size_type __n)
{
if (__n >= size())
this->__throw_out_of_range();
return this->__begin_[__n];
}
template <class _Tp, class _Allocator>
typename vector<_Tp, _Allocator>::const_reference
vector<_Tp, _Allocator>::at(size_type __n) const
{
if (__n >= size())
this->__throw_out_of_range();
return this->__begin_[__n];
}
template <class _Tp, class _Allocator>
void
vector<_Tp, _Allocator>::reserve(size_type __n)
{
if (__n > capacity())
{
allocator_type& __a = this->__alloc();
__split_buffer<value_type, allocator_type&> __v(__n, size(), __a);
__swap_out_circular_buffer(__v);
}
}
template <class _Tp, class _Allocator>
void
vector<_Tp, _Allocator>::shrink_to_fit() _NOEXCEPT
{
if (capacity() > size())
{
#ifndef _LIBCPP_NO_EXCEPTIONS
try
{
#endif // _LIBCPP_NO_EXCEPTIONS
allocator_type& __a = this->__alloc();
__split_buffer<value_type, allocator_type&> __v(size(), size(), __a);
__swap_out_circular_buffer(__v);
#ifndef _LIBCPP_NO_EXCEPTIONS
}
catch (...)
{
}
#endif // _LIBCPP_NO_EXCEPTIONS
}
}
template <class _Tp, class _Allocator>
template <class _Up>
void
#ifndef _LIBCPP_CXX03_LANG
vector<_Tp, _Allocator>::__push_back_slow_path(_Up&& __x)
#else
vector<_Tp, _Allocator>::__push_back_slow_path(_Up& __x)
#endif
{
allocator_type& __a = this->__alloc();
__split_buffer<value_type, allocator_type&> __v(__recommend(size() + 1), size(), __a);
// __v.push_back(_VSTD::forward<_Up>(__x));
__alloc_traits::construct(__a, _VSTD::__to_raw_pointer(__v.__end_), _VSTD::forward<_Up>(__x));
__v.__end_++;
__swap_out_circular_buffer(__v);
}
template <class _Tp, class _Allocator>
inline _LIBCPP_INLINE_VISIBILITY
void
vector<_Tp, _Allocator>::push_back(const_reference __x)
{
if (this->__end_ != this->__end_cap())
{
__construct_one_at_end(__x);
}
else
__push_back_slow_path(__x);
}
#ifndef _LIBCPP_CXX03_LANG
template <class _Tp, class _Allocator>
inline _LIBCPP_INLINE_VISIBILITY
void
vector<_Tp, _Allocator>::push_back(value_type&& __x)
{
if (this->__end_ < this->__end_cap())
{
__construct_one_at_end(_VSTD::move(__x));
}
else
__push_back_slow_path(_VSTD::move(__x));
}
template <class _Tp, class _Allocator>
template <class... _Args>
void
vector<_Tp, _Allocator>::__emplace_back_slow_path(_Args&&... __args)
{
allocator_type& __a = this->__alloc();
__split_buffer<value_type, allocator_type&> __v(__recommend(size() + 1), size(), __a);
// __v.emplace_back(_VSTD::forward<_Args>(__args)...);
__alloc_traits::construct(__a, _VSTD::__to_raw_pointer(__v.__end_), _VSTD::forward<_Args>(__args)...);
__v.__end_++;
__swap_out_circular_buffer(__v);
}
template <class _Tp, class _Allocator>
template <class... _Args>
inline
#if _LIBCPP_STD_VER > 14
typename vector<_Tp, _Allocator>::reference
#else
void
#endif
vector<_Tp, _Allocator>::emplace_back(_Args&&... __args)
{
if (this->__end_ < this->__end_cap())
{
__construct_one_at_end(_VSTD::forward<_Args>(__args)...);
}
else
__emplace_back_slow_path(_VSTD::forward<_Args>(__args)...);
#if _LIBCPP_STD_VER > 14
return this->back();
#endif
}
#endif // !_LIBCPP_CXX03_LANG
template <class _Tp, class _Allocator>
inline
void
vector<_Tp, _Allocator>::pop_back()
{
_LIBCPP_ASSERT(!empty(), "vector::pop_back called for empty vector");
this->__destruct_at_end(this->__end_ - 1);
}
template <class _Tp, class _Allocator>
inline _LIBCPP_INLINE_VISIBILITY
typename vector<_Tp, _Allocator>::iterator
vector<_Tp, _Allocator>::erase(const_iterator __position)
{
#if _LIBCPP_DEBUG_LEVEL >= 2
_LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__position) == this,
"vector::erase(iterator) called with an iterator not"
" referring to this vector");
#endif
_LIBCPP_ASSERT(__position != end(),
"vector::erase(iterator) called with a non-dereferenceable iterator");
difference_type __ps = __position - cbegin();
pointer __p = this->__begin_ + __ps;
this->__destruct_at_end(_VSTD::move(__p + 1, this->__end_, __p));
this->__invalidate_iterators_past(__p-1);
iterator __r = __make_iter(__p);
return __r;
}
template <class _Tp, class _Allocator>
typename vector<_Tp, _Allocator>::iterator
vector<_Tp, _Allocator>::erase(const_iterator __first, const_iterator __last)
{
#if _LIBCPP_DEBUG_LEVEL >= 2
_LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__first) == this,
"vector::erase(iterator, iterator) called with an iterator not"
" referring to this vector");
_LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__last) == this,
"vector::erase(iterator, iterator) called with an iterator not"
" referring to this vector");
#endif
_LIBCPP_ASSERT(__first <= __last, "vector::erase(first, last) called with invalid range");
pointer __p = this->__begin_ + (__first - begin());
if (__first != __last) {
this->__destruct_at_end(_VSTD::move(__p + (__last - __first), this->__end_, __p));
this->__invalidate_iterators_past(__p - 1);
}
iterator __r = __make_iter(__p);
return __r;
}
template <class _Tp, class _Allocator>
void
vector<_Tp, _Allocator>::__move_range(pointer __from_s, pointer __from_e, pointer __to)
{
pointer __old_last = this->__end_;
difference_type __n = __old_last - __to;
{
pointer __i = __from_s + __n;
_ConstructTransaction __tx(*this, __from_e - __i);
for (; __i < __from_e; ++__i, ++__tx.__pos_) {
__alloc_traits::construct(this->__alloc(),
_VSTD::__to_raw_pointer(__tx.__pos_),
_VSTD::move(*__i));
}
}
_VSTD::move_backward(__from_s, __from_s + __n, __old_last);
}
template <class _Tp, class _Allocator>
typename vector<_Tp, _Allocator>::iterator
vector<_Tp, _Allocator>::insert(const_iterator __position, const_reference __x)
{
#if _LIBCPP_DEBUG_LEVEL >= 2
_LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__position) == this,
"vector::insert(iterator, x) called with an iterator not"
" referring to this vector");
#endif
pointer __p = this->__begin_ + (__position - begin());
if (this->__end_ < this->__end_cap())
{
if (__p == this->__end_)
{
__construct_one_at_end(__x);
}
else
{
__move_range(__p, this->__end_, __p + 1);
const_pointer __xr = pointer_traits<const_pointer>::pointer_to(__x);
if (__p <= __xr && __xr < this->__end_)
++__xr;
*__p = *__xr;
}
}
else
{
allocator_type& __a = this->__alloc();
__split_buffer<value_type, allocator_type&> __v(__recommend(size() + 1), __p - this->__begin_, __a);
__v.push_back(__x);
__p = __swap_out_circular_buffer(__v, __p);
}
return __make_iter(__p);
}
#ifndef _LIBCPP_CXX03_LANG
template <class _Tp, class _Allocator>
typename vector<_Tp, _Allocator>::iterator
vector<_Tp, _Allocator>::insert(const_iterator __position, value_type&& __x)
{
#if _LIBCPP_DEBUG_LEVEL >= 2
_LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__position) == this,
"vector::insert(iterator, x) called with an iterator not"
" referring to this vector");
#endif
pointer __p = this->__begin_ + (__position - begin());
if (this->__end_ < this->__end_cap())
{
if (__p == this->__end_)
{
__construct_one_at_end(_VSTD::move(__x));
}
else
{
__move_range(__p, this->__end_, __p + 1);
*__p = _VSTD::move(__x);
}
}
else
{
allocator_type& __a = this->__alloc();
__split_buffer<value_type, allocator_type&> __v(__recommend(size() + 1), __p - this->__begin_, __a);
__v.push_back(_VSTD::move(__x));
__p = __swap_out_circular_buffer(__v, __p);
}
return __make_iter(__p);
}
template <class _Tp, class _Allocator>
template <class... _Args>
typename vector<_Tp, _Allocator>::iterator
vector<_Tp, _Allocator>::emplace(const_iterator __position, _Args&&... __args)
{
#if _LIBCPP_DEBUG_LEVEL >= 2
_LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__position) == this,
"vector::emplace(iterator, x) called with an iterator not"
" referring to this vector");
#endif
pointer __p = this->__begin_ + (__position - begin());
if (this->__end_ < this->__end_cap())
{
if (__p == this->__end_)
{
__construct_one_at_end(_VSTD::forward<_Args>(__args)...);
}
else
{
__temp_value<value_type, _Allocator> __tmp(this->__alloc(), _VSTD::forward<_Args>(__args)...);
__move_range(__p, this->__end_, __p + 1);
*__p = _VSTD::move(__tmp.get());
}
}
else
{
allocator_type& __a = this->__alloc();
__split_buffer<value_type, allocator_type&> __v(__recommend(size() + 1), __p - this->__begin_, __a);
__v.emplace_back(_VSTD::forward<_Args>(__args)...);
__p = __swap_out_circular_buffer(__v, __p);
}
return __make_iter(__p);
}
#endif // !_LIBCPP_CXX03_LANG
template <class _Tp, class _Allocator>
typename vector<_Tp, _Allocator>::iterator
vector<_Tp, _Allocator>::insert(const_iterator __position, size_type __n, const_reference __x)
{
#if _LIBCPP_DEBUG_LEVEL >= 2
_LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__position) == this,
"vector::insert(iterator, n, x) called with an iterator not"
" referring to this vector");
#endif
pointer __p = this->__begin_ + (__position - begin());
if (__n > 0)
{
if (__n <= static_cast<size_type>(this->__end_cap() - this->__end_))
{
size_type __old_n = __n;
pointer __old_last = this->__end_;
if (__n > static_cast<size_type>(this->__end_ - __p))
{
size_type __cx = __n - (this->__end_ - __p);
__construct_at_end(__cx, __x);
__n -= __cx;
}
if (__n > 0)
{
__move_range(__p, __old_last, __p + __old_n);
const_pointer __xr = pointer_traits<const_pointer>::pointer_to(__x);
if (__p <= __xr && __xr < this->__end_)
__xr += __old_n;
_VSTD::fill_n(__p, __n, *__xr);
}
}
else
{
allocator_type& __a = this->__alloc();
__split_buffer<value_type, allocator_type&> __v(__recommend(size() + __n), __p - this->__begin_, __a);
__v.__construct_at_end(__n, __x);
__p = __swap_out_circular_buffer(__v, __p);
}
}
return __make_iter(__p);
}
template <class _Tp, class _Allocator>
template <class _InputIterator>
typename enable_if
<
__is_input_iterator <_InputIterator>::value &&
!__is_forward_iterator<_InputIterator>::value &&
is_constructible<
_Tp,
typename iterator_traits<_InputIterator>::reference>::value,
typename vector<_Tp, _Allocator>::iterator
>::type
vector<_Tp, _Allocator>::insert(const_iterator __position, _InputIterator __first, _InputIterator __last)
{
#if _LIBCPP_DEBUG_LEVEL >= 2
_LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__position) == this,
"vector::insert(iterator, range) called with an iterator not"
" referring to this vector");
#endif
difference_type __off = __position - begin();
pointer __p = this->__begin_ + __off;
allocator_type& __a = this->__alloc();
pointer __old_last = this->__end_;
for (; this->__end_ != this->__end_cap() && __first != __last; ++__first)
{
__construct_one_at_end(*__first);
}
__split_buffer<value_type, allocator_type&> __v(__a);
if (__first != __last)
{
#ifndef _LIBCPP_NO_EXCEPTIONS
try
{
#endif // _LIBCPP_NO_EXCEPTIONS
__v.__construct_at_end(__first, __last);
difference_type __old_size = __old_last - this->__begin_;
difference_type __old_p = __p - this->__begin_;
reserve(__recommend(size() + __v.size()));
__p = this->__begin_ + __old_p;
__old_last = this->__begin_ + __old_size;
#ifndef _LIBCPP_NO_EXCEPTIONS
}
catch (...)
{
erase(__make_iter(__old_last), end());
throw;
}
#endif // _LIBCPP_NO_EXCEPTIONS
}
__p = _VSTD::rotate(__p, __old_last, this->__end_);
insert(__make_iter(__p), make_move_iterator(__v.begin()),
make_move_iterator(__v.end()));
return begin() + __off;
}
template <class _Tp, class _Allocator>
template <class _ForwardIterator>
typename enable_if
<
__is_forward_iterator<_ForwardIterator>::value &&
is_constructible<
_Tp,
typename iterator_traits<_ForwardIterator>::reference>::value,
typename vector<_Tp, _Allocator>::iterator
>::type
vector<_Tp, _Allocator>::insert(const_iterator __position, _ForwardIterator __first, _ForwardIterator __last)
{
#if _LIBCPP_DEBUG_LEVEL >= 2
_LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__position) == this,
"vector::insert(iterator, range) called with an iterator not"
" referring to this vector");
#endif
pointer __p = this->__begin_ + (__position - begin());
difference_type __n = _VSTD::distance(__first, __last);
if (__n > 0)
{
if (__n <= this->__end_cap() - this->__end_)
{
size_type __old_n = __n;
pointer __old_last = this->__end_;
_ForwardIterator __m = __last;
difference_type __dx = this->__end_ - __p;
if (__n > __dx)
{
__m = __first;
difference_type __diff = this->__end_ - __p;
_VSTD::advance(__m, __diff);
__construct_at_end(__m, __last, __n - __diff);
__n = __dx;
}
if (__n > 0)
{
__move_range(__p, __old_last, __p + __old_n);
_VSTD::copy(__first, __m, __p);
}
}
else
{
allocator_type& __a = this->__alloc();
__split_buffer<value_type, allocator_type&> __v(__recommend(size() + __n), __p - this->__begin_, __a);
__v.__construct_at_end(__first, __last);
__p = __swap_out_circular_buffer(__v, __p);
}
}
return __make_iter(__p);
}
template <class _Tp, class _Allocator>
void
vector<_Tp, _Allocator>::resize(size_type __sz)
{
size_type __cs = size();
if (__cs < __sz)
this->__append(__sz - __cs);
else if (__cs > __sz)
this->__destruct_at_end(this->__begin_ + __sz);
}
template <class _Tp, class _Allocator>
void
vector<_Tp, _Allocator>::resize(size_type __sz, const_reference __x)
{
size_type __cs = size();
if (__cs < __sz)
this->__append(__sz - __cs, __x);
else if (__cs > __sz)
this->__destruct_at_end(this->__begin_ + __sz);
}
template <class _Tp, class _Allocator>
void
vector<_Tp, _Allocator>::swap(vector& __x)
#if _LIBCPP_STD_VER >= 14
_NOEXCEPT
#else
_NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value ||
__is_nothrow_swappable<allocator_type>::value)
#endif
{
_LIBCPP_ASSERT(__alloc_traits::propagate_on_container_swap::value ||
this->__alloc() == __x.__alloc(),
"vector::swap: Either propagate_on_container_swap must be true"
" or the allocators must compare equal");
_VSTD::swap(this->__begin_, __x.__begin_);
_VSTD::swap(this->__end_, __x.__end_);
_VSTD::swap(this->__end_cap(), __x.__end_cap());
__swap_allocator(this->__alloc(), __x.__alloc(),
integral_constant<bool,__alloc_traits::propagate_on_container_swap::value>());
#if _LIBCPP_DEBUG_LEVEL >= 2
__get_db()->swap(this, &__x);
#endif // _LIBCPP_DEBUG_LEVEL >= 2
}
template <class _Tp, class _Allocator>
bool
vector<_Tp, _Allocator>::__invariants() const
{
if (this->__begin_ == nullptr)
{
if (this->__end_ != nullptr || this->__end_cap() != nullptr)
return false;
}
else
{
if (this->__begin_ > this->__end_)
return false;
if (this->__begin_ == this->__end_cap())
return false;
if (this->__end_ > this->__end_cap())
return false;
}
return true;
}
#if _LIBCPP_DEBUG_LEVEL >= 2
template <class _Tp, class _Allocator>
bool
vector<_Tp, _Allocator>::__dereferenceable(const const_iterator* __i) const
{
return this->__begin_ <= __i->base() && __i->base() < this->__end_;
}
template <class _Tp, class _Allocator>
bool
vector<_Tp, _Allocator>::__decrementable(const const_iterator* __i) const
{
return this->__begin_ < __i->base() && __i->base() <= this->__end_;
}
template <class _Tp, class _Allocator>
bool
vector<_Tp, _Allocator>::__addable(const const_iterator* __i, ptrdiff_t __n) const
{
const_pointer __p = __i->base() + __n;
return this->__begin_ <= __p && __p <= this->__end_;
}
template <class _Tp, class _Allocator>
bool
vector<_Tp, _Allocator>::__subscriptable(const const_iterator* __i, ptrdiff_t __n) const
{
const_pointer __p = __i->base() + __n;
return this->__begin_ <= __p && __p < this->__end_;
}
#endif // _LIBCPP_DEBUG_LEVEL >= 2
template <class _Tp, class _Allocator>
inline _LIBCPP_INLINE_VISIBILITY
void
vector<_Tp, _Allocator>::__invalidate_all_iterators()
{
#if _LIBCPP_DEBUG_LEVEL >= 2
__get_db()->__invalidate_all(this);
#endif // _LIBCPP_DEBUG_LEVEL >= 2
}
template <class _Tp, class _Allocator>
inline _LIBCPP_INLINE_VISIBILITY
void
vector<_Tp, _Allocator>::__invalidate_iterators_past(pointer __new_last) {
#if _LIBCPP_DEBUG_LEVEL >= 2
__c_node* __c = __get_db()->__find_c_and_lock(this);
for (__i_node** __p = __c->end_; __p != __c->beg_; ) {
--__p;
const_iterator* __i = static_cast<const_iterator*>((*__p)->__i_);
if (__i->base() > __new_last) {
(*__p)->__c_ = nullptr;
if (--__c->end_ != __p)
memmove(__p, __p+1, (__c->end_ - __p)*sizeof(__i_node*));
}
}
__get_db()->unlock();
#else
((void)__new_last);
#endif
}
// vector<bool>
template <class _Allocator> class vector<bool, _Allocator>;
template <class _Allocator> struct hash<vector<bool, _Allocator> >;
template <class _Allocator>
struct __has_storage_type<vector<bool, _Allocator> >
{
static const bool value = true;
};
template <class _Allocator>
class _LIBCPP_TEMPLATE_VIS vector<bool, _Allocator>
: private __vector_base_common<true>
{
public:
typedef vector __self;
typedef bool value_type;
typedef _Allocator allocator_type;
typedef allocator_traits<allocator_type> __alloc_traits;
typedef typename __alloc_traits::size_type size_type;
typedef typename __alloc_traits::difference_type difference_type;
typedef size_type __storage_type;
typedef __bit_iterator<vector, false> pointer;
typedef __bit_iterator<vector, true> const_pointer;
typedef pointer iterator;
typedef const_pointer const_iterator;
typedef _VSTD::reverse_iterator<iterator> reverse_iterator;
typedef _VSTD::reverse_iterator<const_iterator> const_reverse_iterator;
private:
typedef typename __rebind_alloc_helper<__alloc_traits, __storage_type>::type __storage_allocator;
typedef allocator_traits<__storage_allocator> __storage_traits;
typedef typename __storage_traits::pointer __storage_pointer;
typedef typename __storage_traits::const_pointer __const_storage_pointer;
__storage_pointer __begin_;
size_type __size_;
__compressed_pair<size_type, __storage_allocator> __cap_alloc_;
public:
typedef __bit_reference<vector> reference;
typedef __bit_const_reference<vector> const_reference;
private:
_LIBCPP_INLINE_VISIBILITY
size_type& __cap() _NOEXCEPT
{return __cap_alloc_.first();}
_LIBCPP_INLINE_VISIBILITY
const size_type& __cap() const _NOEXCEPT
{return __cap_alloc_.first();}
_LIBCPP_INLINE_VISIBILITY
__storage_allocator& __alloc() _NOEXCEPT
{return __cap_alloc_.second();}
_LIBCPP_INLINE_VISIBILITY
const __storage_allocator& __alloc() const _NOEXCEPT
{return __cap_alloc_.second();}
static const unsigned __bits_per_word = static_cast<unsigned>(sizeof(__storage_type) * CHAR_BIT);
_LIBCPP_INLINE_VISIBILITY
static size_type __internal_cap_to_external(size_type __n) _NOEXCEPT
{return __n * __bits_per_word;}
_LIBCPP_INLINE_VISIBILITY
static size_type __external_cap_to_internal(size_type __n) _NOEXCEPT
{return (__n - 1) / __bits_per_word + 1;}
public:
_LIBCPP_INLINE_VISIBILITY
vector() _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value);
_LIBCPP_INLINE_VISIBILITY explicit vector(const allocator_type& __a)
#if _LIBCPP_STD_VER <= 14
_NOEXCEPT_(is_nothrow_copy_constructible<allocator_type>::value);
#else
_NOEXCEPT;
#endif
~vector();
explicit vector(size_type __n);
#if _LIBCPP_STD_VER > 11
explicit vector(size_type __n, const allocator_type& __a);
#endif
vector(size_type __n, const value_type& __v);
vector(size_type __n, const value_type& __v, const allocator_type& __a);
template <class _InputIterator>
vector(_InputIterator __first, _InputIterator __last,
typename enable_if<__is_input_iterator <_InputIterator>::value &&
!__is_forward_iterator<_InputIterator>::value>::type* = 0);
template <class _InputIterator>
vector(_InputIterator __first, _InputIterator __last, const allocator_type& __a,
typename enable_if<__is_input_iterator <_InputIterator>::value &&
!__is_forward_iterator<_InputIterator>::value>::type* = 0);
template <class _ForwardIterator>
vector(_ForwardIterator __first, _ForwardIterator __last,
typename enable_if<__is_forward_iterator<_ForwardIterator>::value>::type* = 0);
template <class _ForwardIterator>
vector(_ForwardIterator __first, _ForwardIterator __last, const allocator_type& __a,
typename enable_if<__is_forward_iterator<_ForwardIterator>::value>::type* = 0);
vector(const vector& __v);
vector(const vector& __v, const allocator_type& __a);
vector& operator=(const vector& __v);
#ifndef _LIBCPP_CXX03_LANG
vector(initializer_list<value_type> __il);
vector(initializer_list<value_type> __il, const allocator_type& __a);
_LIBCPP_INLINE_VISIBILITY
vector(vector&& __v)
#if _LIBCPP_STD_VER > 14
_NOEXCEPT;
#else
_NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value);
#endif
vector(vector&& __v, const allocator_type& __a);
_LIBCPP_INLINE_VISIBILITY
vector& operator=(vector&& __v)
_NOEXCEPT_((__noexcept_move_assign_container<_Allocator, __alloc_traits>::value));
_LIBCPP_INLINE_VISIBILITY
vector& operator=(initializer_list<value_type> __il)
{assign(__il.begin(), __il.end()); return *this;}
#endif // !_LIBCPP_CXX03_LANG
template <class _InputIterator>
typename enable_if
<
__is_input_iterator<_InputIterator>::value &&
!__is_forward_iterator<_InputIterator>::value,
void
>::type
assign(_InputIterator __first, _InputIterator __last);
template <class _ForwardIterator>
typename enable_if
<
__is_forward_iterator<_ForwardIterator>::value,
void
>::type
assign(_ForwardIterator __first, _ForwardIterator __last);
void assign(size_type __n, const value_type& __x);
#ifndef _LIBCPP_CXX03_LANG
_LIBCPP_INLINE_VISIBILITY
void assign(initializer_list<value_type> __il)
{assign(__il.begin(), __il.end());}
#endif
_LIBCPP_INLINE_VISIBILITY allocator_type get_allocator() const _NOEXCEPT
{return allocator_type(this->__alloc());}
size_type max_size() const _NOEXCEPT;
_LIBCPP_INLINE_VISIBILITY
size_type capacity() const _NOEXCEPT
{return __internal_cap_to_external(__cap());}
_LIBCPP_INLINE_VISIBILITY
size_type size() const _NOEXCEPT
{return __size_;}
_LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
bool empty() const _NOEXCEPT
{return __size_ == 0;}
void reserve(size_type __n);
void shrink_to_fit() _NOEXCEPT;
_LIBCPP_INLINE_VISIBILITY
iterator begin() _NOEXCEPT
{return __make_iter(0);}
_LIBCPP_INLINE_VISIBILITY
const_iterator begin() const _NOEXCEPT
{return __make_iter(0);}
_LIBCPP_INLINE_VISIBILITY
iterator end() _NOEXCEPT
{return __make_iter(__size_);}
_LIBCPP_INLINE_VISIBILITY
const_iterator end() const _NOEXCEPT
{return __make_iter(__size_);}
_LIBCPP_INLINE_VISIBILITY
reverse_iterator rbegin() _NOEXCEPT
{return reverse_iterator(end());}
_LIBCPP_INLINE_VISIBILITY
const_reverse_iterator rbegin() const _NOEXCEPT
{return const_reverse_iterator(end());}
_LIBCPP_INLINE_VISIBILITY
reverse_iterator rend() _NOEXCEPT
{return reverse_iterator(begin());}
_LIBCPP_INLINE_VISIBILITY
const_reverse_iterator rend() const _NOEXCEPT
{return const_reverse_iterator(begin());}
_LIBCPP_INLINE_VISIBILITY
const_iterator cbegin() const _NOEXCEPT
{return __make_iter(0);}
_LIBCPP_INLINE_VISIBILITY
const_iterator cend() const _NOEXCEPT
{return __make_iter(__size_);}
_LIBCPP_INLINE_VISIBILITY
const_reverse_iterator crbegin() const _NOEXCEPT
{return rbegin();}
_LIBCPP_INLINE_VISIBILITY
const_reverse_iterator crend() const _NOEXCEPT
{return rend();}
_LIBCPP_INLINE_VISIBILITY reference operator[](size_type __n) {return __make_ref(__n);}
_LIBCPP_INLINE_VISIBILITY const_reference operator[](size_type __n) const {return __make_ref(__n);}
reference at(size_type __n);
const_reference at(size_type __n) const;
_LIBCPP_INLINE_VISIBILITY reference front() {return __make_ref(0);}
_LIBCPP_INLINE_VISIBILITY const_reference front() const {return __make_ref(0);}
_LIBCPP_INLINE_VISIBILITY reference back() {return __make_ref(__size_ - 1);}
_LIBCPP_INLINE_VISIBILITY const_reference back() const {return __make_ref(__size_ - 1);}
void push_back(const value_type& __x);
#if _LIBCPP_STD_VER > 11
template <class... _Args>
#if _LIBCPP_STD_VER > 14
_LIBCPP_INLINE_VISIBILITY reference emplace_back(_Args&&... __args)
#else
_LIBCPP_INLINE_VISIBILITY void emplace_back(_Args&&... __args)
#endif
{
push_back ( value_type ( _VSTD::forward<_Args>(__args)... ));
#if _LIBCPP_STD_VER > 14
return this->back();
#endif
}
#endif
_LIBCPP_INLINE_VISIBILITY void pop_back() {--__size_;}
#if _LIBCPP_STD_VER > 11
template <class... _Args>
_LIBCPP_INLINE_VISIBILITY iterator emplace(const_iterator position, _Args&&... __args)
{ return insert ( position, value_type ( _VSTD::forward<_Args>(__args)... )); }
#endif
iterator insert(const_iterator __position, const value_type& __x);
iterator insert(const_iterator __position, size_type __n, const value_type& __x);
iterator insert(const_iterator __position, size_type __n, const_reference __x);
template <class _InputIterator>
typename enable_if
<
__is_input_iterator <_InputIterator>::value &&
!__is_forward_iterator<_InputIterator>::value,
iterator
>::type
insert(const_iterator __position, _InputIterator __first, _InputIterator __last);
template <class _ForwardIterator>
typename enable_if
<
__is_forward_iterator<_ForwardIterator>::value,
iterator
>::type
insert(const_iterator __position, _ForwardIterator __first, _ForwardIterator __last);
#ifndef _LIBCPP_CXX03_LANG
_LIBCPP_INLINE_VISIBILITY
iterator insert(const_iterator __position, initializer_list<value_type> __il)
{return insert(__position, __il.begin(), __il.end());}
#endif
_LIBCPP_INLINE_VISIBILITY iterator erase(const_iterator __position);
iterator erase(const_iterator __first, const_iterator __last);
_LIBCPP_INLINE_VISIBILITY
void clear() _NOEXCEPT {__size_ = 0;}
void swap(vector&)
#if _LIBCPP_STD_VER >= 14
_NOEXCEPT;
#else
_NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value ||
__is_nothrow_swappable<allocator_type>::value);
#endif
static void swap(reference __x, reference __y) _NOEXCEPT { _VSTD::swap(__x, __y); }
void resize(size_type __sz, value_type __x = false);
void flip() _NOEXCEPT;
bool __invariants() const;
private:
_LIBCPP_INLINE_VISIBILITY void __invalidate_all_iterators();
void __vallocate(size_type __n);
void __vdeallocate() _NOEXCEPT;
_LIBCPP_INLINE_VISIBILITY
static size_type __align_it(size_type __new_size) _NOEXCEPT
{return __new_size + (__bits_per_word-1) & ~((size_type)__bits_per_word-1);}
_LIBCPP_INLINE_VISIBILITY size_type __recommend(size_type __new_size) const;
_LIBCPP_INLINE_VISIBILITY void __construct_at_end(size_type __n, bool __x);
template <class _ForwardIterator>
typename enable_if
<
__is_forward_iterator<_ForwardIterator>::value,
void
>::type
__construct_at_end(_ForwardIterator __first, _ForwardIterator __last);
void __append(size_type __n, const_reference __x);
_LIBCPP_INLINE_VISIBILITY
reference __make_ref(size_type __pos) _NOEXCEPT
{return reference(__begin_ + __pos / __bits_per_word, __storage_type(1) << __pos % __bits_per_word);}
_LIBCPP_INLINE_VISIBILITY
const_reference __make_ref(size_type __pos) const _NOEXCEPT
{return const_reference(__begin_ + __pos / __bits_per_word, __storage_type(1) << __pos % __bits_per_word);}
_LIBCPP_INLINE_VISIBILITY
iterator __make_iter(size_type __pos) _NOEXCEPT
{return iterator(__begin_ + __pos / __bits_per_word, static_cast<unsigned>(__pos % __bits_per_word));}
_LIBCPP_INLINE_VISIBILITY
const_iterator __make_iter(size_type __pos) const _NOEXCEPT
{return const_iterator(__begin_ + __pos / __bits_per_word, static_cast<unsigned>(__pos % __bits_per_word));}
_LIBCPP_INLINE_VISIBILITY
iterator __const_iterator_cast(const_iterator __p) _NOEXCEPT
{return begin() + (__p - cbegin());}
_LIBCPP_INLINE_VISIBILITY
void __copy_assign_alloc(const vector& __v)
{__copy_assign_alloc(__v, integral_constant<bool,
__storage_traits::propagate_on_container_copy_assignment::value>());}
_LIBCPP_INLINE_VISIBILITY
void __copy_assign_alloc(const vector& __c, true_type)
{
if (__alloc() != __c.__alloc())
__vdeallocate();
__alloc() = __c.__alloc();
}
_LIBCPP_INLINE_VISIBILITY
void __copy_assign_alloc(const vector&, false_type)
{}
void __move_assign(vector& __c, false_type);
void __move_assign(vector& __c, true_type)
_NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value);
_LIBCPP_INLINE_VISIBILITY
void __move_assign_alloc(vector& __c)
_NOEXCEPT_(
!__storage_traits::propagate_on_container_move_assignment::value ||
is_nothrow_move_assignable<allocator_type>::value)
{__move_assign_alloc(__c, integral_constant<bool,
__storage_traits::propagate_on_container_move_assignment::value>());}
_LIBCPP_INLINE_VISIBILITY
void __move_assign_alloc(vector& __c, true_type)
_NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value)
{
__alloc() = _VSTD::move(__c.__alloc());
}
_LIBCPP_INLINE_VISIBILITY
void __move_assign_alloc(vector&, false_type)
_NOEXCEPT
{}
size_t __hash_code() const _NOEXCEPT;
friend class __bit_reference<vector>;
friend class __bit_const_reference<vector>;
friend class __bit_iterator<vector, false>;
friend class __bit_iterator<vector, true>;
friend struct __bit_array<vector>;
friend struct _LIBCPP_TEMPLATE_VIS hash<vector>;
};
template <class _Allocator>
inline _LIBCPP_INLINE_VISIBILITY
void
vector<bool, _Allocator>::__invalidate_all_iterators()
{
}
// Allocate space for __n objects
// throws length_error if __n > max_size()
// throws (probably bad_alloc) if memory run out
// Precondition: __begin_ == __end_ == __cap() == 0
// Precondition: __n > 0
// Postcondition: capacity() == __n
// Postcondition: size() == 0
template <class _Allocator>
void
vector<bool, _Allocator>::__vallocate(size_type __n)
{
if (__n > max_size())
this->__throw_length_error();
__n = __external_cap_to_internal(__n);
this->__begin_ = __storage_traits::allocate(this->__alloc(), __n);
this->__size_ = 0;
this->__cap() = __n;
}
template <class _Allocator>
void
vector<bool, _Allocator>::__vdeallocate() _NOEXCEPT
{
if (this->__begin_ != nullptr)
{
__storage_traits::deallocate(this->__alloc(), this->__begin_, __cap());
__invalidate_all_iterators();
this->__begin_ = nullptr;
this->__size_ = this->__cap() = 0;
}
}
template <class _Allocator>
typename vector<bool, _Allocator>::size_type
vector<bool, _Allocator>::max_size() const _NOEXCEPT
{
size_type __amax = __storage_traits::max_size(__alloc());
size_type __nmax = numeric_limits<size_type>::max() / 2; // end() >= begin(), always
if (__nmax / __bits_per_word <= __amax)
return __nmax;
return __internal_cap_to_external(__amax);
}
// Precondition: __new_size > capacity()
template <class _Allocator>
inline _LIBCPP_INLINE_VISIBILITY
typename vector<bool, _Allocator>::size_type
vector<bool, _Allocator>::__recommend(size_type __new_size) const
{
const size_type __ms = max_size();
if (__new_size > __ms)
this->__throw_length_error();
const size_type __cap = capacity();
if (__cap >= __ms / 2)
return __ms;
return _VSTD::max(2*__cap, __align_it(__new_size));
}
// Default constructs __n objects starting at __end_
// Precondition: __n > 0
// Precondition: size() + __n <= capacity()
// Postcondition: size() == size() + __n
template <class _Allocator>
inline _LIBCPP_INLINE_VISIBILITY
void
vector<bool, _Allocator>::__construct_at_end(size_type __n, bool __x)
{
size_type __old_size = this->__size_;
this->__size_ += __n;
if (__old_size == 0 || ((__old_size - 1) / __bits_per_word) != ((this->__size_ - 1) / __bits_per_word))
{
if (this->__size_ <= __bits_per_word)
this->__begin_[0] = __storage_type(0);
else
this->__begin_[(this->__size_ - 1) / __bits_per_word] = __storage_type(0);
}
_VSTD::fill_n(__make_iter(__old_size), __n, __x);
}
template <class _Allocator>
template <class _ForwardIterator>
typename enable_if
<
__is_forward_iterator<_ForwardIterator>::value,
void
>::type
vector<bool, _Allocator>::__construct_at_end(_ForwardIterator __first, _ForwardIterator __last)
{
size_type __old_size = this->__size_;
this->__size_ += _VSTD::distance(__first, __last);
if (__old_size == 0 || ((__old_size - 1) / __bits_per_word) != ((this->__size_ - 1) / __bits_per_word))
{
if (this->__size_ <= __bits_per_word)
this->__begin_[0] = __storage_type(0);
else
this->__begin_[(this->__size_ - 1) / __bits_per_word] = __storage_type(0);
}
_VSTD::copy(__first, __last, __make_iter(__old_size));
}
template <class _Allocator>
inline _LIBCPP_INLINE_VISIBILITY
vector<bool, _Allocator>::vector()
_NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value)
: __begin_(nullptr),
__size_(0),
__cap_alloc_(0)
{
}
template <class _Allocator>
inline _LIBCPP_INLINE_VISIBILITY
vector<bool, _Allocator>::vector(const allocator_type& __a)
#if _LIBCPP_STD_VER <= 14
_NOEXCEPT_(is_nothrow_copy_constructible<allocator_type>::value)
#else
_NOEXCEPT
#endif
: __begin_(nullptr),
__size_(0),
__cap_alloc_(0, static_cast<__storage_allocator>(__a))
{
}
template <class _Allocator>
vector<bool, _Allocator>::vector(size_type __n)
: __begin_(nullptr),
__size_(0),
__cap_alloc_(0)
{
if (__n > 0)
{
__vallocate(__n);
__construct_at_end(__n, false);
}
}
#if _LIBCPP_STD_VER > 11
template <class _Allocator>
vector<bool, _Allocator>::vector(size_type __n, const allocator_type& __a)
: __begin_(nullptr),
__size_(0),
__cap_alloc_(0, static_cast<__storage_allocator>(__a))
{
if (__n > 0)
{
__vallocate(__n);
__construct_at_end(__n, false);
}
}
#endif
template <class _Allocator>
vector<bool, _Allocator>::vector(size_type __n, const value_type& __x)
: __begin_(nullptr),
__size_(0),
__cap_alloc_(0)
{
if (__n > 0)
{
__vallocate(__n);
__construct_at_end(__n, __x);
}
}
template <class _Allocator>
vector<bool, _Allocator>::vector(size_type __n, const value_type& __x, const allocator_type& __a)
: __begin_(nullptr),
__size_(0),
__cap_alloc_(0, static_cast<__storage_allocator>(__a))
{
if (__n > 0)
{
__vallocate(__n);
__construct_at_end(__n, __x);
}
}
template <class _Allocator>
template <class _InputIterator>
vector<bool, _Allocator>::vector(_InputIterator __first, _InputIterator __last,
typename enable_if<__is_input_iterator <_InputIterator>::value &&
!__is_forward_iterator<_InputIterator>::value>::type*)
: __begin_(nullptr),
__size_(0),
__cap_alloc_(0)
{
#ifndef _LIBCPP_NO_EXCEPTIONS
try
{
#endif // _LIBCPP_NO_EXCEPTIONS
for (; __first != __last; ++__first)
push_back(*__first);
#ifndef _LIBCPP_NO_EXCEPTIONS
}
catch (...)
{
if (__begin_ != nullptr)
__storage_traits::deallocate(__alloc(), __begin_, __cap());
__invalidate_all_iterators();
throw;
}
#endif // _LIBCPP_NO_EXCEPTIONS
}
template <class _Allocator>
template <class _InputIterator>
vector<bool, _Allocator>::vector(_InputIterator __first, _InputIterator __last, const allocator_type& __a,
typename enable_if<__is_input_iterator <_InputIterator>::value &&
!__is_forward_iterator<_InputIterator>::value>::type*)
: __begin_(nullptr),
__size_(0),
__cap_alloc_(0, static_cast<__storage_allocator>(__a))
{
#ifndef _LIBCPP_NO_EXCEPTIONS
try
{
#endif // _LIBCPP_NO_EXCEPTIONS
for (; __first != __last; ++__first)
push_back(*__first);
#ifndef _LIBCPP_NO_EXCEPTIONS
}
catch (...)
{
if (__begin_ != nullptr)
__storage_traits::deallocate(__alloc(), __begin_, __cap());
__invalidate_all_iterators();
throw;
}
#endif // _LIBCPP_NO_EXCEPTIONS
}
template <class _Allocator>
template <class _ForwardIterator>
vector<bool, _Allocator>::vector(_ForwardIterator __first, _ForwardIterator __last,
typename enable_if<__is_forward_iterator<_ForwardIterator>::value>::type*)
: __begin_(nullptr),
__size_(0),
__cap_alloc_(0)
{
size_type __n = static_cast<size_type>(_VSTD::distance(__first, __last));
if (__n > 0)
{
__vallocate(__n);
__construct_at_end(__first, __last);
}
}
template <class _Allocator>
template <class _ForwardIterator>
vector<bool, _Allocator>::vector(_ForwardIterator __first, _ForwardIterator __last, const allocator_type& __a,
typename enable_if<__is_forward_iterator<_ForwardIterator>::value>::type*)
: __begin_(nullptr),
__size_(0),
__cap_alloc_(0, static_cast<__storage_allocator>(__a))
{
size_type __n = static_cast<size_type>(_VSTD::distance(__first, __last));
if (__n > 0)
{
__vallocate(__n);
__construct_at_end(__first, __last);
}
}
#ifndef _LIBCPP_CXX03_LANG
template <class _Allocator>
vector<bool, _Allocator>::vector(initializer_list<value_type> __il)
: __begin_(nullptr),
__size_(0),
__cap_alloc_(0)
{
size_type __n = static_cast<size_type>(__il.size());
if (__n > 0)
{
__vallocate(__n);
__construct_at_end(__il.begin(), __il.end());
}
}
template <class _Allocator>
vector<bool, _Allocator>::vector(initializer_list<value_type> __il, const allocator_type& __a)
: __begin_(nullptr),
__size_(0),
__cap_alloc_(0, static_cast<__storage_allocator>(__a))
{
size_type __n = static_cast<size_type>(__il.size());
if (__n > 0)
{
__vallocate(__n);
__construct_at_end(__il.begin(), __il.end());
}
}
#endif // _LIBCPP_CXX03_LANG
template <class _Allocator>
vector<bool, _Allocator>::~vector()
{
if (__begin_ != nullptr)
__storage_traits::deallocate(__alloc(), __begin_, __cap());
__invalidate_all_iterators();
}
template <class _Allocator>
vector<bool, _Allocator>::vector(const vector& __v)
: __begin_(nullptr),
__size_(0),
__cap_alloc_(0, __storage_traits::select_on_container_copy_construction(__v.__alloc()))
{
if (__v.size() > 0)
{
__vallocate(__v.size());
__construct_at_end(__v.begin(), __v.end());
}
}
template <class _Allocator>
vector<bool, _Allocator>::vector(const vector& __v, const allocator_type& __a)
: __begin_(nullptr),
__size_(0),
__cap_alloc_(0, __a)
{
if (__v.size() > 0)
{
__vallocate(__v.size());
__construct_at_end(__v.begin(), __v.end());
}
}
template <class _Allocator>
vector<bool, _Allocator>&
vector<bool, _Allocator>::operator=(const vector& __v)
{
if (this != &__v)
{
__copy_assign_alloc(__v);
if (__v.__size_)
{
if (__v.__size_ > capacity())
{
__vdeallocate();
__vallocate(__v.__size_);
}
_VSTD::copy(__v.__begin_, __v.__begin_ + __external_cap_to_internal(__v.__size_), __begin_);
}
__size_ = __v.__size_;
}
return *this;
}
#ifndef _LIBCPP_CXX03_LANG
template <class _Allocator>
inline _LIBCPP_INLINE_VISIBILITY vector<bool, _Allocator>::vector(vector&& __v)
#if _LIBCPP_STD_VER > 14
_NOEXCEPT
#else
_NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value)
#endif
: __begin_(__v.__begin_),
__size_(__v.__size_),
__cap_alloc_(std::move(__v.__cap_alloc_)) {
__v.__begin_ = nullptr;
__v.__size_ = 0;
__v.__cap() = 0;
}
template <class _Allocator>
vector<bool, _Allocator>::vector(vector&& __v, const allocator_type& __a)
: __begin_(nullptr),
__size_(0),
__cap_alloc_(0, __a)
{
if (__a == allocator_type(__v.__alloc()))
{
this->__begin_ = __v.__begin_;
this->__size_ = __v.__size_;
this->__cap() = __v.__cap();
__v.__begin_ = nullptr;
__v.__cap() = __v.__size_ = 0;
}
else if (__v.size() > 0)
{
__vallocate(__v.size());
__construct_at_end(__v.begin(), __v.end());
}
}
template <class _Allocator>
inline _LIBCPP_INLINE_VISIBILITY
vector<bool, _Allocator>&
vector<bool, _Allocator>::operator=(vector&& __v)
_NOEXCEPT_((__noexcept_move_assign_container<_Allocator, __alloc_traits>::value))
{
__move_assign(__v, integral_constant<bool,
__storage_traits::propagate_on_container_move_assignment::value>());
return *this;
}
template <class _Allocator>
void
vector<bool, _Allocator>::__move_assign(vector& __c, false_type)
{
if (__alloc() != __c.__alloc())
assign(__c.begin(), __c.end());
else
__move_assign(__c, true_type());
}
template <class _Allocator>
void
vector<bool, _Allocator>::__move_assign(vector& __c, true_type)
_NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value)
{
__vdeallocate();
__move_assign_alloc(__c);
this->__begin_ = __c.__begin_;
this->__size_ = __c.__size_;
this->__cap() = __c.__cap();
__c.__begin_ = nullptr;
__c.__cap() = __c.__size_ = 0;
}
#endif // !_LIBCPP_CXX03_LANG
template <class _Allocator>
void
vector<bool, _Allocator>::assign(size_type __n, const value_type& __x)
{
__size_ = 0;
if (__n > 0)
{
size_type __c = capacity();
if (__n <= __c)
__size_ = __n;
else
{
vector __v(__alloc());
__v.reserve(__recommend(__n));
__v.__size_ = __n;
swap(__v);
}
_VSTD::fill_n(begin(), __n, __x);
}
__invalidate_all_iterators();
}
template <class _Allocator>
template <class _InputIterator>
typename enable_if
<
__is_input_iterator<_InputIterator>::value &&
!__is_forward_iterator<_InputIterator>::value,
void
>::type
vector<bool, _Allocator>::assign(_InputIterator __first, _InputIterator __last)
{
clear();
for (; __first != __last; ++__first)
push_back(*__first);
}
template <class _Allocator>
template <class _ForwardIterator>
typename enable_if
<
__is_forward_iterator<_ForwardIterator>::value,
void
>::type
vector<bool, _Allocator>::assign(_ForwardIterator __first, _ForwardIterator __last)
{
clear();
difference_type __ns = _VSTD::distance(__first, __last);
_LIBCPP_ASSERT(__ns >= 0, "invalid range specified");
const size_t __n = static_cast<size_type>(__ns);
if (__n)
{
if (__n > capacity())
{
__vdeallocate();
__vallocate(__n);
}
__construct_at_end(__first, __last);
}
}
template <class _Allocator>
void
vector<bool, _Allocator>::reserve(size_type __n)
{
if (__n > capacity())
{
vector __v(this->__alloc());
__v.__vallocate(__n);
__v.__construct_at_end(this->begin(), this->end());
swap(__v);
__invalidate_all_iterators();
}
}
template <class _Allocator>
void
vector<bool, _Allocator>::shrink_to_fit() _NOEXCEPT
{
if (__external_cap_to_internal(size()) > __cap())
{
#ifndef _LIBCPP_NO_EXCEPTIONS
try
{
#endif // _LIBCPP_NO_EXCEPTIONS
vector(*this, allocator_type(__alloc())).swap(*this);
#ifndef _LIBCPP_NO_EXCEPTIONS
}
catch (...)
{
}
#endif // _LIBCPP_NO_EXCEPTIONS
}
}
template <class _Allocator>
typename vector<bool, _Allocator>::reference
vector<bool, _Allocator>::at(size_type __n)
{
if (__n >= size())
this->__throw_out_of_range();
return (*this)[__n];
}
template <class _Allocator>
typename vector<bool, _Allocator>::const_reference
vector<bool, _Allocator>::at(size_type __n) const
{
if (__n >= size())
this->__throw_out_of_range();
return (*this)[__n];
}
template <class _Allocator>
void
vector<bool, _Allocator>::push_back(const value_type& __x)
{
if (this->__size_ == this->capacity())
reserve(__recommend(this->__size_ + 1));
++this->__size_;
back() = __x;
}
template <class _Allocator>
typename vector<bool, _Allocator>::iterator
vector<bool, _Allocator>::insert(const_iterator __position, const value_type& __x)
{
iterator __r;
if (size() < capacity())
{
const_iterator __old_end = end();
++__size_;
_VSTD::copy_backward(__position, __old_end, end());
__r = __const_iterator_cast(__position);
}
else
{
vector __v(__alloc());
__v.reserve(__recommend(__size_ + 1));
__v.__size_ = __size_ + 1;
__r = _VSTD::copy(cbegin(), __position, __v.begin());
_VSTD::copy_backward(__position, cend(), __v.end());
swap(__v);
}
*__r = __x;
return __r;
}
template <class _Allocator>
typename vector<bool, _Allocator>::iterator
vector<bool, _Allocator>::insert(const_iterator __position, size_type __n, const value_type& __x)
{
iterator __r;
size_type __c = capacity();
if (__n <= __c && size() <= __c - __n)
{
const_iterator __old_end = end();
__size_ += __n;
_VSTD::copy_backward(__position, __old_end, end());
__r = __const_iterator_cast(__position);
}
else
{
vector __v(__alloc());
__v.reserve(__recommend(__size_ + __n));
__v.__size_ = __size_ + __n;
__r = _VSTD::copy(cbegin(), __position, __v.begin());
_VSTD::copy_backward(__position, cend(), __v.end());
swap(__v);
}
_VSTD::fill_n(__r, __n, __x);
return __r;
}
template <class _Allocator>
template <class _InputIterator>
typename enable_if
<
__is_input_iterator <_InputIterator>::value &&
!__is_forward_iterator<_InputIterator>::value,
typename vector<bool, _Allocator>::iterator
>::type
vector<bool, _Allocator>::insert(const_iterator __position, _InputIterator __first, _InputIterator __last)
{
difference_type __off = __position - begin();
iterator __p = __const_iterator_cast(__position);
iterator __old_end = end();
for (; size() != capacity() && __first != __last; ++__first)
{
++this->__size_;
back() = *__first;
}
vector __v(__alloc());
if (__first != __last)
{
#ifndef _LIBCPP_NO_EXCEPTIONS
try
{
#endif // _LIBCPP_NO_EXCEPTIONS
__v.assign(__first, __last);
difference_type __old_size = static_cast<difference_type>(__old_end - begin());
difference_type __old_p = __p - begin();
reserve(__recommend(size() + __v.size()));
__p = begin() + __old_p;
__old_end = begin() + __old_size;
#ifndef _LIBCPP_NO_EXCEPTIONS
}
catch (...)
{
erase(__old_end, end());
throw;
}
#endif // _LIBCPP_NO_EXCEPTIONS
}
__p = _VSTD::rotate(__p, __old_end, end());
insert(__p, __v.begin(), __v.end());
return begin() + __off;
}
template <class _Allocator>
template <class _ForwardIterator>
typename enable_if
<
__is_forward_iterator<_ForwardIterator>::value,
typename vector<bool, _Allocator>::iterator
>::type
vector<bool, _Allocator>::insert(const_iterator __position, _ForwardIterator __first, _ForwardIterator __last)
{
const difference_type __n_signed = _VSTD::distance(__first, __last);
_LIBCPP_ASSERT(__n_signed >= 0, "invalid range specified");
const size_type __n = static_cast<size_type>(__n_signed);
iterator __r;
size_type __c = capacity();
if (__n <= __c && size() <= __c - __n)
{
const_iterator __old_end = end();
__size_ += __n;
_VSTD::copy_backward(__position, __old_end, end());
__r = __const_iterator_cast(__position);
}
else
{
vector __v(__alloc());
__v.reserve(__recommend(__size_ + __n));
__v.__size_ = __size_ + __n;
__r = _VSTD::copy(cbegin(), __position, __v.begin());
_VSTD::copy_backward(__position, cend(), __v.end());
swap(__v);
}
_VSTD::copy(__first, __last, __r);
return __r;
}
template <class _Allocator>
inline _LIBCPP_INLINE_VISIBILITY
typename vector<bool, _Allocator>::iterator
vector<bool, _Allocator>::erase(const_iterator __position)
{
iterator __r = __const_iterator_cast(__position);
_VSTD::copy(__position + 1, this->cend(), __r);
--__size_;
return __r;
}
template <class _Allocator>
typename vector<bool, _Allocator>::iterator
vector<bool, _Allocator>::erase(const_iterator __first, const_iterator __last)
{
iterator __r = __const_iterator_cast(__first);
difference_type __d = __last - __first;
_VSTD::copy(__last, this->cend(), __r);
__size_ -= __d;
return __r;
}
template <class _Allocator>
void
vector<bool, _Allocator>::swap(vector& __x)
#if _LIBCPP_STD_VER >= 14
_NOEXCEPT
#else
_NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value ||
__is_nothrow_swappable<allocator_type>::value)
#endif
{
_VSTD::swap(this->__begin_, __x.__begin_);
_VSTD::swap(this->__size_, __x.__size_);
_VSTD::swap(this->__cap(), __x.__cap());
__swap_allocator(this->__alloc(), __x.__alloc(),
integral_constant<bool, __alloc_traits::propagate_on_container_swap::value>());
}
template <class _Allocator>
void
vector<bool, _Allocator>::resize(size_type __sz, value_type __x)
{
size_type __cs = size();
if (__cs < __sz)
{
iterator __r;
size_type __c = capacity();
size_type __n = __sz - __cs;
if (__n <= __c && __cs <= __c - __n)
{
__r = end();
__size_ += __n;
}
else
{
vector __v(__alloc());
__v.reserve(__recommend(__size_ + __n));
__v.__size_ = __size_ + __n;
__r = _VSTD::copy(cbegin(), cend(), __v.begin());
swap(__v);
}
_VSTD::fill_n(__r, __n, __x);
}
else
__size_ = __sz;
}
template <class _Allocator>
void
vector<bool, _Allocator>::flip() _NOEXCEPT
{
// do middle whole words
size_type __n = __size_;
__storage_pointer __p = __begin_;
for (; __n >= __bits_per_word; ++__p, __n -= __bits_per_word)
*__p = ~*__p;
// do last partial word
if (__n > 0)
{
__storage_type __m = ~__storage_type(0) >> (__bits_per_word - __n);
__storage_type __b = *__p & __m;
*__p &= ~__m;
*__p |= ~__b & __m;
}
}
template <class _Allocator>
bool
vector<bool, _Allocator>::__invariants() const
{
if (this->__begin_ == nullptr)
{
if (this->__size_ != 0 || this->__cap() != 0)
return false;
}
else
{
if (this->__cap() == 0)
return false;
if (this->__size_ > this->capacity())
return false;
}
return true;
}
template <class _Allocator>
size_t
vector<bool, _Allocator>::__hash_code() const _NOEXCEPT
{
size_t __h = 0;
// do middle whole words
size_type __n = __size_;
__storage_pointer __p = __begin_;
for (; __n >= __bits_per_word; ++__p, __n -= __bits_per_word)
__h ^= *__p;
// do last partial word
if (__n > 0)
{
const __storage_type __m = ~__storage_type(0) >> (__bits_per_word - __n);
__h ^= *__p & __m;
}
return __h;
}
template <class _Allocator>
struct _LIBCPP_TEMPLATE_VIS hash<vector<bool, _Allocator> >
: public unary_function<vector<bool, _Allocator>, size_t>
{
_LIBCPP_INLINE_VISIBILITY
size_t operator()(const vector<bool, _Allocator>& __vec) const _NOEXCEPT
{return __vec.__hash_code();}
};
template <class _Tp, class _Allocator>
inline _LIBCPP_INLINE_VISIBILITY
bool
operator==(const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __y)
{
const typename vector<_Tp, _Allocator>::size_type __sz = __x.size();
return __sz == __y.size() && _VSTD::equal(__x.begin(), __x.end(), __y.begin());
}
template <class _Tp, class _Allocator>
inline _LIBCPP_INLINE_VISIBILITY
bool
operator!=(const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __y)
{
return !(__x == __y);
}
template <class _Tp, class _Allocator>
inline _LIBCPP_INLINE_VISIBILITY
bool
operator< (const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __y)
{
return _VSTD::lexicographical_compare(__x.begin(), __x.end(), __y.begin(), __y.end());
}
template <class _Tp, class _Allocator>
inline _LIBCPP_INLINE_VISIBILITY
bool
operator> (const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __y)
{
return __y < __x;
}
template <class _Tp, class _Allocator>
inline _LIBCPP_INLINE_VISIBILITY
bool
operator>=(const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __y)
{
return !(__x < __y);
}
template <class _Tp, class _Allocator>
inline _LIBCPP_INLINE_VISIBILITY
bool
operator<=(const vector<_Tp, _Allocator>& __x, const vector<_Tp, _Allocator>& __y)
{
return !(__y < __x);
}
template <class _Tp, class _Allocator>
inline _LIBCPP_INLINE_VISIBILITY
void
swap(vector<_Tp, _Allocator>& __x, vector<_Tp, _Allocator>& __y)
_NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
{
__x.swap(__y);
}
#if _LIBCPP_STD_VER > 17
template <class _Tp, class _Allocator, class _Up>
inline _LIBCPP_INLINE_VISIBILITY
void erase(vector<_Tp, _Allocator>& __c, const _Up& __v)
{ __c.erase(_VSTD::remove(__c.begin(), __c.end(), __v), __c.end()); }
template <class _Tp, class _Allocator, class _Predicate>
inline _LIBCPP_INLINE_VISIBILITY
void erase_if(vector<_Tp, _Allocator>& __c, _Predicate __pred)
{ __c.erase(_VSTD::remove_if(__c.begin(), __c.end(), __pred), __c.end()); }
#endif
_LIBCPP_END_NAMESPACE_STD
_LIBCPP_POP_MACROS
#endif // _LIBCPP_VECTOR
| 111,451 | 3,407 | jart/cosmopolitan | false |
cosmopolitan/third_party/libcxx/ctype.h | // -*- C++ -*-
//===---------------------------- ctype.h ---------------------------------===//
//
// 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_CTYPE_H
#define _LIBCPP_CTYPE_H
/*
ctype.h synopsis
int isalnum(int c);
int isalpha(int c);
int isblank(int c); // C99
int iscntrl(int c);
int isdigit(int c);
int isgraph(int c);
int islower(int c);
int isprint(int c);
int ispunct(int c);
int isspace(int c);
int isupper(int c);
int isxdigit(int c);
int tolower(int c);
int toupper(int c);
*/
#include "third_party/libcxx/__config"
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
#pragma GCC system_header
#endif
#include "libc/isystem/ctype.h"
#ifdef __cplusplus
#undef isalnum
#undef isalpha
#undef isblank
#undef iscntrl
#undef isdigit
#undef isgraph
#undef islower
#undef isprint
#undef ispunct
#undef isspace
#undef isupper
#undef isxdigit
#undef tolower
#undef toupper
#endif
#endif // _LIBCPP_CTYPE_H
| 1,175 | 60 | jart/cosmopolitan | false |
cosmopolitan/third_party/libcxx/__undef_macros | // -*- C++ -*-
//===------------------------ __undef_macros ------------------------------===//
//
// 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
//
//===----------------------------------------------------------------------===//
#ifdef min
#if !defined(_LIBCPP_DISABLE_MACRO_CONFLICT_WARNINGS)
#if defined(_LIBCPP_WARNING)
_LIBCPP_WARNING("macro min is incompatible with C++. Try #define NOMINMAX "
"before any Windows header. #undefing min")
#else
#warning: macro min is incompatible with C++. #undefing min
#endif
#endif
#undef min
#endif
#ifdef max
#if !defined(_LIBCPP_DISABLE_MACRO_CONFLICT_WARNINGS)
#if defined(_LIBCPP_WARNING)
_LIBCPP_WARNING("macro max is incompatible with C++. Try #define NOMINMAX "
"before any Windows header. #undefing max")
#else
#warning: macro max is incompatible with C++. #undefing max
#endif
#endif
#undef max
#endif
| 1,047 | 34 | jart/cosmopolitan | false |
cosmopolitan/third_party/libcxx/string | // -*- C++ -*-
//===--------------------------- string -----------------------------------===//
//
// 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_STRING
#define _LIBCPP_STRING
#include "third_party/libcxx/__config"
#include "third_party/libcxx/string_view"
#include "third_party/libcxx/iosfwd"
#include "third_party/libcxx/cstring"
#include "third_party/libcxx/cstdio" // For EOF.
#include "third_party/libcxx/cwchar"
#include "third_party/libcxx/algorithm"
#include "third_party/libcxx/iterator"
#include "third_party/libcxx/utility"
#include "third_party/libcxx/memory"
#include "third_party/libcxx/stdexcept"
#include "third_party/libcxx/type_traits"
#include "third_party/libcxx/initializer_list"
#include "third_party/libcxx/__functional_base"
#include "third_party/libcxx/version"
#ifndef _LIBCPP_HAS_NO_UNICODE_CHARS
#include "third_party/libcxx/cstdint"
#endif
#include "third_party/libcxx/__debug"
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
#pragma GCC system_header
#endif
_LIBCPP_PUSH_MACROS
#include "third_party/libcxx/__undef_macros"
_LIBCPP_BEGIN_NAMESPACE_STD
/*
string synopsis
namespace std
{
template <class stateT>
class fpos
{
private:
stateT st;
public:
fpos(streamoff = streamoff());
operator streamoff() const;
stateT state() const;
void state(stateT);
fpos& operator+=(streamoff);
fpos operator+ (streamoff) const;
fpos& operator-=(streamoff);
fpos operator- (streamoff) const;
};
template <class stateT> streamoff operator-(const fpos<stateT>& x, const fpos<stateT>& y);
template <class stateT> bool operator==(const fpos<stateT>& x, const fpos<stateT>& y);
template <class stateT> bool operator!=(const fpos<stateT>& x, const fpos<stateT>& y);
template <class charT>
struct char_traits
{
typedef charT char_type;
typedef ... int_type;
typedef streamoff off_type;
typedef streampos pos_type;
typedef mbstate_t state_type;
static void assign(char_type& c1, const char_type& c2) noexcept;
static constexpr bool eq(char_type c1, char_type c2) noexcept;
static constexpr bool lt(char_type c1, char_type c2) noexcept;
static int compare(const char_type* s1, const char_type* s2, size_t n);
static size_t length(const char_type* s);
static const char_type* find(const char_type* s, size_t n, const char_type& a);
static char_type* move(char_type* s1, const char_type* s2, size_t n);
static char_type* copy(char_type* s1, const char_type* s2, size_t n);
static char_type* assign(char_type* s, size_t n, char_type a);
static constexpr int_type not_eof(int_type c) noexcept;
static constexpr char_type to_char_type(int_type c) noexcept;
static constexpr int_type to_int_type(char_type c) noexcept;
static constexpr bool eq_int_type(int_type c1, int_type c2) noexcept;
static constexpr int_type eof() noexcept;
};
template <> struct char_traits<char>;
template <> struct char_traits<wchar_t>;
template<class charT, class traits = char_traits<charT>, class Allocator = allocator<charT> >
class basic_string
{
public:
// types:
typedef traits traits_type;
typedef typename traits_type::char_type value_type;
typedef Allocator allocator_type;
typedef typename allocator_type::size_type size_type;
typedef typename allocator_type::difference_type difference_type;
typedef typename allocator_type::reference reference;
typedef typename allocator_type::const_reference const_reference;
typedef typename allocator_type::pointer pointer;
typedef typename allocator_type::const_pointer const_pointer;
typedef implementation-defined iterator;
typedef implementation-defined const_iterator;
typedef std::reverse_iterator<iterator> reverse_iterator;
typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
static const size_type npos = -1;
basic_string()
noexcept(is_nothrow_default_constructible<allocator_type>::value);
explicit basic_string(const allocator_type& a);
basic_string(const basic_string& str);
basic_string(basic_string&& str)
noexcept(is_nothrow_move_constructible<allocator_type>::value);
basic_string(const basic_string& str, size_type pos,
const allocator_type& a = allocator_type());
basic_string(const basic_string& str, size_type pos, size_type n,
const Allocator& a = Allocator());
template<class T>
basic_string(const T& t, size_type pos, size_type n, const Allocator& a = Allocator()); // C++17
template <class T>
explicit basic_string(const T& t, const Allocator& a = Allocator()); // C++17
basic_string(const value_type* s, const allocator_type& a = allocator_type());
basic_string(const value_type* s, size_type n, const allocator_type& a = allocator_type());
basic_string(size_type n, value_type c, const allocator_type& a = allocator_type());
template<class InputIterator>
basic_string(InputIterator begin, InputIterator end,
const allocator_type& a = allocator_type());
basic_string(initializer_list<value_type>, const Allocator& = Allocator());
basic_string(const basic_string&, const Allocator&);
basic_string(basic_string&&, const Allocator&);
~basic_string();
operator basic_string_view<charT, traits>() const noexcept;
basic_string& operator=(const basic_string& str);
template <class T>
basic_string& operator=(const T& t); // C++17
basic_string& operator=(basic_string&& str)
noexcept(
allocator_type::propagate_on_container_move_assignment::value ||
allocator_type::is_always_equal::value ); // C++17
basic_string& operator=(const value_type* s);
basic_string& operator=(value_type c);
basic_string& operator=(initializer_list<value_type>);
iterator begin() noexcept;
const_iterator begin() const noexcept;
iterator end() noexcept;
const_iterator end() const noexcept;
reverse_iterator rbegin() noexcept;
const_reverse_iterator rbegin() const noexcept;
reverse_iterator rend() noexcept;
const_reverse_iterator rend() const noexcept;
const_iterator cbegin() const noexcept;
const_iterator cend() const noexcept;
const_reverse_iterator crbegin() const noexcept;
const_reverse_iterator crend() const noexcept;
size_type size() const noexcept;
size_type length() const noexcept;
size_type max_size() const noexcept;
size_type capacity() const noexcept;
void resize(size_type n, value_type c);
void resize(size_type n);
void reserve(size_type res_arg = 0);
void shrink_to_fit();
void clear() noexcept;
bool empty() const noexcept;
const_reference operator[](size_type pos) const;
reference operator[](size_type pos);
const_reference at(size_type n) const;
reference at(size_type n);
basic_string& operator+=(const basic_string& str);
template <class T>
basic_string& operator+=(const T& t); // C++17
basic_string& operator+=(const value_type* s);
basic_string& operator+=(value_type c);
basic_string& operator+=(initializer_list<value_type>);
basic_string& append(const basic_string& str);
template <class T>
basic_string& append(const T& t); // C++17
basic_string& append(const basic_string& str, size_type pos, size_type n=npos); //C++14
template <class T>
basic_string& append(const T& t, size_type pos, size_type n=npos); // C++17
basic_string& append(const value_type* s, size_type n);
basic_string& append(const value_type* s);
basic_string& append(size_type n, value_type c);
template<class InputIterator>
basic_string& append(InputIterator first, InputIterator last);
basic_string& append(initializer_list<value_type>);
void push_back(value_type c);
void pop_back();
reference front();
const_reference front() const;
reference back();
const_reference back() const;
basic_string& assign(const basic_string& str);
template <class T>
basic_string& assign(const T& t); // C++17
basic_string& assign(basic_string&& str);
basic_string& assign(const basic_string& str, size_type pos, size_type n=npos); // C++14
template <class T>
basic_string& assign(const T& t, size_type pos, size_type n=npos); // C++17
basic_string& assign(const value_type* s, size_type n);
basic_string& assign(const value_type* s);
basic_string& assign(size_type n, value_type c);
template<class InputIterator>
basic_string& assign(InputIterator first, InputIterator last);
basic_string& assign(initializer_list<value_type>);
basic_string& insert(size_type pos1, const basic_string& str);
template <class T>
basic_string& insert(size_type pos1, const T& t);
basic_string& insert(size_type pos1, const basic_string& str,
size_type pos2, size_type n);
template <class T>
basic_string& insert(size_type pos1, const T& t, size_type pos2, size_type n); // C++17
basic_string& insert(size_type pos, const value_type* s, size_type n=npos); //C++14
basic_string& insert(size_type pos, const value_type* s);
basic_string& insert(size_type pos, size_type n, value_type c);
iterator insert(const_iterator p, value_type c);
iterator insert(const_iterator p, size_type n, value_type c);
template<class InputIterator>
iterator insert(const_iterator p, InputIterator first, InputIterator last);
iterator insert(const_iterator p, initializer_list<value_type>);
basic_string& erase(size_type pos = 0, size_type n = npos);
iterator erase(const_iterator position);
iterator erase(const_iterator first, const_iterator last);
basic_string& replace(size_type pos1, size_type n1, const basic_string& str);
template <class T>
basic_string& replace(size_type pos1, size_type n1, const T& t); // C++17
basic_string& replace(size_type pos1, size_type n1, const basic_string& str,
size_type pos2, size_type n2=npos); // C++14
template <class T>
basic_string& replace(size_type pos1, size_type n1, const T& t,
size_type pos2, size_type n); // C++17
basic_string& replace(size_type pos, size_type n1, const value_type* s, size_type n2);
basic_string& replace(size_type pos, size_type n1, const value_type* s);
basic_string& replace(size_type pos, size_type n1, size_type n2, value_type c);
basic_string& replace(const_iterator i1, const_iterator i2, const basic_string& str);
template <class T>
basic_string& replace(const_iterator i1, const_iterator i2, const T& t); // C++17
basic_string& replace(const_iterator i1, const_iterator i2, const value_type* s, size_type n);
basic_string& replace(const_iterator i1, const_iterator i2, const value_type* s);
basic_string& replace(const_iterator i1, const_iterator i2, size_type n, value_type c);
template<class InputIterator>
basic_string& replace(const_iterator i1, const_iterator i2, InputIterator j1, InputIterator j2);
basic_string& replace(const_iterator i1, const_iterator i2, initializer_list<value_type>);
size_type copy(value_type* s, size_type n, size_type pos = 0) const;
basic_string substr(size_type pos = 0, size_type n = npos) const;
void swap(basic_string& str)
noexcept(allocator_traits<allocator_type>::propagate_on_container_swap::value ||
allocator_traits<allocator_type>::is_always_equal::value); // C++17
const value_type* c_str() const noexcept;
const value_type* data() const noexcept;
value_type* data() noexcept; // C++17
allocator_type get_allocator() const noexcept;
size_type find(const basic_string& str, size_type pos = 0) const noexcept;
template <class T>
size_type find(const T& t, size_type pos = 0) const; // C++17
size_type find(const value_type* s, size_type pos, size_type n) const noexcept;
size_type find(const value_type* s, size_type pos = 0) const noexcept;
size_type find(value_type c, size_type pos = 0) const noexcept;
size_type rfind(const basic_string& str, size_type pos = npos) const noexcept;
template <class T>
size_type rfind(const T& t, size_type pos = npos) const; // C++17
size_type rfind(const value_type* s, size_type pos, size_type n) const noexcept;
size_type rfind(const value_type* s, size_type pos = npos) const noexcept;
size_type rfind(value_type c, size_type pos = npos) const noexcept;
size_type find_first_of(const basic_string& str, size_type pos = 0) const noexcept;
template <class T>
size_type find_first_of(const T& t, size_type pos = 0) const; // C++17
size_type find_first_of(const value_type* s, size_type pos, size_type n) const noexcept;
size_type find_first_of(const value_type* s, size_type pos = 0) const noexcept;
size_type find_first_of(value_type c, size_type pos = 0) const noexcept;
size_type find_last_of(const basic_string& str, size_type pos = npos) const noexcept;
template <class T>
size_type find_last_of(const T& t, size_type pos = npos) const noexcept; // C++17
size_type find_last_of(const value_type* s, size_type pos, size_type n) const noexcept;
size_type find_last_of(const value_type* s, size_type pos = npos) const noexcept;
size_type find_last_of(value_type c, size_type pos = npos) const noexcept;
size_type find_first_not_of(const basic_string& str, size_type pos = 0) const noexcept;
template <class T>
size_type find_first_not_of(const T& t, size_type pos = 0) const; // C++17
size_type find_first_not_of(const value_type* s, size_type pos, size_type n) const noexcept;
size_type find_first_not_of(const value_type* s, size_type pos = 0) const noexcept;
size_type find_first_not_of(value_type c, size_type pos = 0) const noexcept;
size_type find_last_not_of(const basic_string& str, size_type pos = npos) const noexcept;
template <class T>
size_type find_last_not_of(const T& t, size_type pos = npos) const; // C++17
size_type find_last_not_of(const value_type* s, size_type pos, size_type n) const noexcept;
size_type find_last_not_of(const value_type* s, size_type pos = npos) const noexcept;
size_type find_last_not_of(value_type c, size_type pos = npos) const noexcept;
int compare(const basic_string& str) const noexcept;
template <class T>
int compare(const T& t) const noexcept; // C++17
int compare(size_type pos1, size_type n1, const basic_string& str) const;
template <class T>
int compare(size_type pos1, size_type n1, const T& t) const; // C++17
int compare(size_type pos1, size_type n1, const basic_string& str,
size_type pos2, size_type n2=npos) const; // C++14
template <class T>
int compare(size_type pos1, size_type n1, const T& t,
size_type pos2, size_type n2=npos) const; // C++17
int compare(const value_type* s) const noexcept;
int compare(size_type pos1, size_type n1, const value_type* s) const;
int compare(size_type pos1, size_type n1, const value_type* s, size_type n2) const;
bool starts_with(basic_string_view<charT, traits> sv) const noexcept; // C++2a
bool starts_with(charT c) const noexcept; // C++2a
bool starts_with(const charT* s) const; // C++2a
bool ends_with(basic_string_view<charT, traits> sv) const noexcept; // C++2a
bool ends_with(charT c) const noexcept; // C++2a
bool ends_with(const charT* s) const; // C++2a
bool __invariants() const;
};
template<class InputIterator,
class Allocator = allocator<typename iterator_traits<InputIterator>::value_type>>
basic_string(InputIterator, InputIterator, Allocator = Allocator())
-> basic_string<typename iterator_traits<InputIterator>::value_type,
char_traits<typename iterator_traits<InputIterator>::value_type>,
Allocator>; // C++17
template<class charT, class traits, class Allocator>
basic_string<charT, traits, Allocator>
operator+(const basic_string<charT, traits, Allocator>& lhs,
const basic_string<charT, traits, Allocator>& rhs);
template<class charT, class traits, class Allocator>
basic_string<charT, traits, Allocator>
operator+(const charT* lhs , const basic_string<charT,traits,Allocator>&rhs);
template<class charT, class traits, class Allocator>
basic_string<charT, traits, Allocator>
operator+(charT lhs, const basic_string<charT,traits,Allocator>& rhs);
template<class charT, class traits, class Allocator>
basic_string<charT, traits, Allocator>
operator+(const basic_string<charT, traits, Allocator>& lhs, const charT* rhs);
template<class charT, class traits, class Allocator>
basic_string<charT, traits, Allocator>
operator+(const basic_string<charT, traits, Allocator>& lhs, charT rhs);
template<class charT, class traits, class Allocator>
bool operator==(const basic_string<charT, traits, Allocator>& lhs,
const basic_string<charT, traits, Allocator>& rhs) noexcept;
template<class charT, class traits, class Allocator>
bool operator==(const charT* lhs, const basic_string<charT, traits, Allocator>& rhs) noexcept;
template<class charT, class traits, class Allocator>
bool operator==(const basic_string<charT,traits,Allocator>& lhs, const charT* rhs) noexcept;
template<class charT, class traits, class Allocator>
bool operator!=(const basic_string<charT,traits,Allocator>& lhs,
const basic_string<charT, traits, Allocator>& rhs) noexcept;
template<class charT, class traits, class Allocator>
bool operator!=(const charT* lhs, const basic_string<charT, traits, Allocator>& rhs) noexcept;
template<class charT, class traits, class Allocator>
bool operator!=(const basic_string<charT, traits, Allocator>& lhs, const charT* rhs) noexcept;
template<class charT, class traits, class Allocator>
bool operator< (const basic_string<charT, traits, Allocator>& lhs,
const basic_string<charT, traits, Allocator>& rhs) noexcept;
template<class charT, class traits, class Allocator>
bool operator< (const basic_string<charT, traits, Allocator>& lhs, const charT* rhs) noexcept;
template<class charT, class traits, class Allocator>
bool operator< (const charT* lhs, const basic_string<charT, traits, Allocator>& rhs) noexcept;
template<class charT, class traits, class Allocator>
bool operator> (const basic_string<charT, traits, Allocator>& lhs,
const basic_string<charT, traits, Allocator>& rhs) noexcept;
template<class charT, class traits, class Allocator>
bool operator> (const basic_string<charT, traits, Allocator>& lhs, const charT* rhs) noexcept;
template<class charT, class traits, class Allocator>
bool operator> (const charT* lhs, const basic_string<charT, traits, Allocator>& rhs) noexcept;
template<class charT, class traits, class Allocator>
bool operator<=(const basic_string<charT, traits, Allocator>& lhs,
const basic_string<charT, traits, Allocator>& rhs) noexcept;
template<class charT, class traits, class Allocator>
bool operator<=(const basic_string<charT, traits, Allocator>& lhs, const charT* rhs) noexcept;
template<class charT, class traits, class Allocator>
bool operator<=(const charT* lhs, const basic_string<charT, traits, Allocator>& rhs) noexcept;
template<class charT, class traits, class Allocator>
bool operator>=(const basic_string<charT, traits, Allocator>& lhs,
const basic_string<charT, traits, Allocator>& rhs) noexcept;
template<class charT, class traits, class Allocator>
bool operator>=(const basic_string<charT, traits, Allocator>& lhs, const charT* rhs) noexcept;
template<class charT, class traits, class Allocator>
bool operator>=(const charT* lhs, const basic_string<charT, traits, Allocator>& rhs) noexcept;
template<class charT, class traits, class Allocator>
void swap(basic_string<charT, traits, Allocator>& lhs,
basic_string<charT, traits, Allocator>& rhs)
noexcept(noexcept(lhs.swap(rhs)));
template<class charT, class traits, class Allocator>
basic_istream<charT, traits>&
operator>>(basic_istream<charT, traits>& is, basic_string<charT, traits, Allocator>& str);
template<class charT, class traits, class Allocator>
basic_ostream<charT, traits>&
operator<<(basic_ostream<charT, traits>& os, const basic_string<charT, traits, Allocator>& str);
template<class charT, class traits, class Allocator>
basic_istream<charT, traits>&
getline(basic_istream<charT, traits>& is, basic_string<charT, traits, Allocator>& str,
charT delim);
template<class charT, class traits, class Allocator>
basic_istream<charT, traits>&
getline(basic_istream<charT, traits>& is, basic_string<charT, traits, Allocator>& str);
template<class charT, class traits, class Allocator, class U>
void erase(basic_string<charT, traits, Allocator>& c, const U& value); // C++20
template<class charT, class traits, class Allocator, class Predicate>
void erase_if(basic_string<charT, traits, Allocator>& c, Predicate pred); // C++20
typedef basic_string<char> string;
typedef basic_string<wchar_t> wstring;
typedef basic_string<char16_t> u16string;
typedef basic_string<char32_t> u32string;
int stoi (const string& str, size_t* idx = 0, int base = 10);
long stol (const string& str, size_t* idx = 0, int base = 10);
unsigned long stoul (const string& str, size_t* idx = 0, int base = 10);
long long stoll (const string& str, size_t* idx = 0, int base = 10);
unsigned long long stoull(const string& str, size_t* idx = 0, int base = 10);
float stof (const string& str, size_t* idx = 0);
double stod (const string& str, size_t* idx = 0);
long double stold(const string& str, size_t* idx = 0);
string to_string(int val);
string to_string(unsigned val);
string to_string(long val);
string to_string(unsigned long val);
string to_string(long long val);
string to_string(unsigned long long val);
string to_string(float val);
string to_string(double val);
string to_string(long double val);
int stoi (const wstring& str, size_t* idx = 0, int base = 10);
long stol (const wstring& str, size_t* idx = 0, int base = 10);
unsigned long stoul (const wstring& str, size_t* idx = 0, int base = 10);
long long stoll (const wstring& str, size_t* idx = 0, int base = 10);
unsigned long long stoull(const wstring& str, size_t* idx = 0, int base = 10);
float stof (const wstring& str, size_t* idx = 0);
double stod (const wstring& str, size_t* idx = 0);
long double stold(const wstring& str, size_t* idx = 0);
wstring to_wstring(int val);
wstring to_wstring(unsigned val);
wstring to_wstring(long val);
wstring to_wstring(unsigned long val);
wstring to_wstring(long long val);
wstring to_wstring(unsigned long long val);
wstring to_wstring(float val);
wstring to_wstring(double val);
wstring to_wstring(long double val);
template <> struct hash<string>;
template <> struct hash<u16string>;
template <> struct hash<u32string>;
template <> struct hash<wstring>;
basic_string<char> operator "" s( const char *str, size_t len ); // C++14
basic_string<wchar_t> operator "" s( const wchar_t *str, size_t len ); // C++14
basic_string<char16_t> operator "" s( const char16_t *str, size_t len ); // C++14
basic_string<char32_t> operator "" s( const char32_t *str, size_t len ); // C++14
} // std
*/
// fpos
template <class _StateT>
class _LIBCPP_TEMPLATE_VIS fpos
{
private:
_StateT __st_;
streamoff __off_;
public:
_LIBCPP_INLINE_VISIBILITY fpos(streamoff __off = streamoff()) : __st_(), __off_(__off) {}
_LIBCPP_INLINE_VISIBILITY operator streamoff() const {return __off_;}
_LIBCPP_INLINE_VISIBILITY _StateT state() const {return __st_;}
_LIBCPP_INLINE_VISIBILITY void state(_StateT __st) {__st_ = __st;}
_LIBCPP_INLINE_VISIBILITY fpos& operator+=(streamoff __off) {__off_ += __off; return *this;}
_LIBCPP_INLINE_VISIBILITY fpos operator+ (streamoff __off) const {fpos __t(*this); __t += __off; return __t;}
_LIBCPP_INLINE_VISIBILITY fpos& operator-=(streamoff __off) {__off_ -= __off; return *this;}
_LIBCPP_INLINE_VISIBILITY fpos operator- (streamoff __off) const {fpos __t(*this); __t -= __off; return __t;}
};
template <class _StateT>
inline _LIBCPP_INLINE_VISIBILITY
streamoff operator-(const fpos<_StateT>& __x, const fpos<_StateT>& __y)
{return streamoff(__x) - streamoff(__y);}
template <class _StateT>
inline _LIBCPP_INLINE_VISIBILITY
bool operator==(const fpos<_StateT>& __x, const fpos<_StateT>& __y)
{return streamoff(__x) == streamoff(__y);}
template <class _StateT>
inline _LIBCPP_INLINE_VISIBILITY
bool operator!=(const fpos<_StateT>& __x, const fpos<_StateT>& __y)
{return streamoff(__x) != streamoff(__y);}
// basic_string
template<class _CharT, class _Traits, class _Allocator>
basic_string<_CharT, _Traits, _Allocator>
operator+(const basic_string<_CharT, _Traits, _Allocator>& __x,
const basic_string<_CharT, _Traits, _Allocator>& __y);
template<class _CharT, class _Traits, class _Allocator>
basic_string<_CharT, _Traits, _Allocator>
operator+(const _CharT* __x, const basic_string<_CharT,_Traits,_Allocator>& __y);
template<class _CharT, class _Traits, class _Allocator>
basic_string<_CharT, _Traits, _Allocator>
operator+(_CharT __x, const basic_string<_CharT,_Traits,_Allocator>& __y);
template<class _CharT, class _Traits, class _Allocator>
inline _LIBCPP_INLINE_VISIBILITY
basic_string<_CharT, _Traits, _Allocator>
operator+(const basic_string<_CharT, _Traits, _Allocator>& __x, const _CharT* __y);
template<class _CharT, class _Traits, class _Allocator>
basic_string<_CharT, _Traits, _Allocator>
operator+(const basic_string<_CharT, _Traits, _Allocator>& __x, _CharT __y);
_LIBCPP_EXTERN_TEMPLATE(_LIBCPP_FUNC_VIS string operator+<char, char_traits<char>, allocator<char> >(char const*, string const&))
template <bool>
class _LIBCPP_TEMPLATE_VIS __basic_string_common
{
protected:
_LIBCPP_NORETURN void __throw_length_error() const;
_LIBCPP_NORETURN void __throw_out_of_range() const;
};
template <bool __b>
void
__basic_string_common<__b>::__throw_length_error() const
{
_VSTD::__throw_length_error("basic_string");
}
template <bool __b>
void
__basic_string_common<__b>::__throw_out_of_range() const
{
_VSTD::__throw_out_of_range("basic_string");
}
_LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS __basic_string_common<true>)
#ifdef _LIBCPP_NO_EXCEPTIONS
template <class _Iter>
struct __libcpp_string_gets_noexcept_iterator_impl : public true_type {};
#elif defined(_LIBCPP_HAS_NO_NOEXCEPT)
template <class _Iter>
struct __libcpp_string_gets_noexcept_iterator_impl : public false_type {};
#else
template <class _Iter, bool = __is_forward_iterator<_Iter>::value>
struct __libcpp_string_gets_noexcept_iterator_impl : public _LIBCPP_BOOL_CONSTANT((
noexcept(++(declval<_Iter&>())) &&
is_nothrow_assignable<_Iter&, _Iter>::value &&
noexcept(declval<_Iter>() == declval<_Iter>()) &&
noexcept(*declval<_Iter>())
)) {};
template <class _Iter>
struct __libcpp_string_gets_noexcept_iterator_impl<_Iter, false> : public false_type {};
#endif
template <class _Iter>
struct __libcpp_string_gets_noexcept_iterator
: public _LIBCPP_BOOL_CONSTANT(__libcpp_is_trivial_iterator<_Iter>::value || __libcpp_string_gets_noexcept_iterator_impl<_Iter>::value) {};
template <class _CharT, class _Traits, class _Tp>
struct __can_be_converted_to_string_view : public _LIBCPP_BOOL_CONSTANT(
( is_convertible<const _Tp&, basic_string_view<_CharT, _Traits> >::value &&
!is_convertible<const _Tp&, const _CharT*>::value)) {};
#ifdef _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
template <class _CharT, size_t = sizeof(_CharT)>
struct __padding
{
unsigned char __xx[sizeof(_CharT)-1];
};
template <class _CharT>
struct __padding<_CharT, 1>
{
};
#endif // _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
template<class _CharT, class _Traits, class _Allocator>
class _LIBCPP_TEMPLATE_VIS basic_string
: private __basic_string_common<true>
{
public:
typedef basic_string __self;
typedef basic_string_view<_CharT, _Traits> __self_view;
typedef _Traits traits_type;
typedef _CharT value_type;
typedef _Allocator allocator_type;
typedef allocator_traits<allocator_type> __alloc_traits;
typedef typename __alloc_traits::size_type size_type;
typedef typename __alloc_traits::difference_type difference_type;
typedef value_type& reference;
typedef const value_type& const_reference;
typedef typename __alloc_traits::pointer pointer;
typedef typename __alloc_traits::const_pointer const_pointer;
static_assert((!is_array<value_type>::value), "Character type of basic_string must not be an array");
static_assert(( is_standard_layout<value_type>::value), "Character type of basic_string must be standard-layout");
static_assert(( is_trivial<value_type>::value), "Character type of basic_string must be trivial");
static_assert(( is_same<_CharT, typename traits_type::char_type>::value),
"traits_type::char_type must be the same type as CharT");
static_assert(( is_same<typename allocator_type::value_type, value_type>::value),
"Allocator::value_type must be same type as value_type");
#if defined(_LIBCPP_RAW_ITERATORS)
typedef pointer iterator;
typedef const_pointer const_iterator;
#else // defined(_LIBCPP_RAW_ITERATORS)
typedef __wrap_iter<pointer> iterator;
typedef __wrap_iter<const_pointer> const_iterator;
#endif // defined(_LIBCPP_RAW_ITERATORS)
typedef _VSTD::reverse_iterator<iterator> reverse_iterator;
typedef _VSTD::reverse_iterator<const_iterator> const_reverse_iterator;
private:
#ifdef _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
struct __long
{
pointer __data_;
size_type __size_;
size_type __cap_;
};
#ifdef _LIBCPP_BIG_ENDIAN
static const size_type __short_mask = 0x01;
static const size_type __long_mask = 0x1ul;
#else // _LIBCPP_BIG_ENDIAN
static const size_type __short_mask = 0x80;
static const size_type __long_mask = ~(size_type(~0) >> 1);
#endif // _LIBCPP_BIG_ENDIAN
enum {__min_cap = (sizeof(__long) - 1)/sizeof(value_type) > 2 ?
(sizeof(__long) - 1)/sizeof(value_type) : 2};
struct __short
{
value_type __data_[__min_cap];
struct
: __padding<value_type>
{
unsigned char __size_;
};
};
#else
struct __long
{
size_type __cap_;
size_type __size_;
pointer __data_;
};
#ifdef _LIBCPP_BIG_ENDIAN
static const size_type __short_mask = 0x80;
static const size_type __long_mask = ~(size_type(~0) >> 1);
#else // _LIBCPP_BIG_ENDIAN
static const size_type __short_mask = 0x01;
static const size_type __long_mask = 0x1ul;
#endif // _LIBCPP_BIG_ENDIAN
enum {__min_cap = (sizeof(__long) - 1)/sizeof(value_type) > 2 ?
(sizeof(__long) - 1)/sizeof(value_type) : 2};
struct __short
{
union
{
unsigned char __size_;
value_type __lx;
};
value_type __data_[__min_cap];
};
#endif // _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
union __ulx{__long __lx; __short __lxx;};
enum {__n_words = sizeof(__ulx) / sizeof(size_type)};
struct __raw
{
size_type __words[__n_words];
};
struct __rep
{
union
{
__long __l;
__short __s;
__raw __r;
};
};
__compressed_pair<__rep, allocator_type> __r_;
public:
static const size_type npos = -1;
_LIBCPP_INLINE_VISIBILITY basic_string()
_NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value);
_LIBCPP_INLINE_VISIBILITY explicit basic_string(const allocator_type& __a)
#if _LIBCPP_STD_VER <= 14
_NOEXCEPT_(is_nothrow_copy_constructible<allocator_type>::value);
#else
_NOEXCEPT;
#endif
basic_string(const basic_string& __str);
basic_string(const basic_string& __str, const allocator_type& __a);
#ifndef _LIBCPP_CXX03_LANG
_LIBCPP_INLINE_VISIBILITY
basic_string(basic_string&& __str)
#if _LIBCPP_STD_VER <= 14
_NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value);
#else
_NOEXCEPT;
#endif
_LIBCPP_INLINE_VISIBILITY
basic_string(basic_string&& __str, const allocator_type& __a);
#endif // _LIBCPP_CXX03_LANG
template <class = typename enable_if<__is_allocator<_Allocator>::value, nullptr_t>::type>
_LIBCPP_INLINE_VISIBILITY
basic_string(const _CharT* __s) {
_LIBCPP_ASSERT(__s != nullptr, "basic_string(const char*) detected nullptr");
__init(__s, traits_type::length(__s));
# if _LIBCPP_DEBUG_LEVEL >= 2
__get_db()->__insert_c(this);
# endif
}
template <class = typename enable_if<__is_allocator<_Allocator>::value, nullptr_t>::type>
_LIBCPP_INLINE_VISIBILITY
basic_string(const _CharT* __s, const _Allocator& __a);
_LIBCPP_INLINE_VISIBILITY
basic_string(const _CharT* __s, size_type __n);
_LIBCPP_INLINE_VISIBILITY
basic_string(const _CharT* __s, size_type __n, const _Allocator& __a);
_LIBCPP_INLINE_VISIBILITY
basic_string(size_type __n, _CharT __c);
template <class = typename enable_if<__is_allocator<_Allocator>::value, nullptr_t>::type>
_LIBCPP_INLINE_VISIBILITY
basic_string(size_type __n, _CharT __c, const _Allocator& __a);
basic_string(const basic_string& __str, size_type __pos, size_type __n,
const _Allocator& __a = _Allocator());
_LIBCPP_INLINE_VISIBILITY
basic_string(const basic_string& __str, size_type __pos,
const _Allocator& __a = _Allocator());
template<class _Tp, class = typename enable_if<__can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value, void>::type>
_LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
basic_string(const _Tp& __t, size_type __pos, size_type __n,
const allocator_type& __a = allocator_type());
template<class _Tp, class = typename enable_if<__can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value, void>::type>
_LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
explicit basic_string(const _Tp& __t);
template<class _Tp, class = typename enable_if<__can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value, void>::type>
_LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
explicit basic_string(const _Tp& __t, const allocator_type& __a);
template<class _InputIterator, class = typename enable_if<__is_input_iterator<_InputIterator>::value>::type>
_LIBCPP_INLINE_VISIBILITY
basic_string(_InputIterator __first, _InputIterator __last);
template<class _InputIterator, class = typename enable_if<__is_input_iterator<_InputIterator>::value>::type>
_LIBCPP_INLINE_VISIBILITY
basic_string(_InputIterator __first, _InputIterator __last, const allocator_type& __a);
#ifndef _LIBCPP_CXX03_LANG
_LIBCPP_INLINE_VISIBILITY
basic_string(initializer_list<_CharT> __il);
_LIBCPP_INLINE_VISIBILITY
basic_string(initializer_list<_CharT> __il, const _Allocator& __a);
#endif // _LIBCPP_CXX03_LANG
inline ~basic_string();
_LIBCPP_INLINE_VISIBILITY
operator __self_view() const _NOEXCEPT { return __self_view(data(), size()); }
basic_string& operator=(const basic_string& __str);
template <class _Tp, class = typename enable_if<__can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value, void>::type>
basic_string& operator=(const _Tp& __t)
{__self_view __sv = __t; return assign(__sv);}
#ifndef _LIBCPP_CXX03_LANG
_LIBCPP_INLINE_VISIBILITY
basic_string& operator=(basic_string&& __str)
_NOEXCEPT_((__noexcept_move_assign_container<_Allocator, __alloc_traits>::value));
_LIBCPP_INLINE_VISIBILITY
basic_string& operator=(initializer_list<value_type> __il) {return assign(__il.begin(), __il.size());}
#endif
_LIBCPP_INLINE_VISIBILITY basic_string& operator=(const value_type* __s) {return assign(__s);}
basic_string& operator=(value_type __c);
#if _LIBCPP_DEBUG_LEVEL >= 2
_LIBCPP_INLINE_VISIBILITY
iterator begin() _NOEXCEPT
{return iterator(this, __get_pointer());}
_LIBCPP_INLINE_VISIBILITY
const_iterator begin() const _NOEXCEPT
{return const_iterator(this, __get_pointer());}
_LIBCPP_INLINE_VISIBILITY
iterator end() _NOEXCEPT
{return iterator(this, __get_pointer() + size());}
_LIBCPP_INLINE_VISIBILITY
const_iterator end() const _NOEXCEPT
{return const_iterator(this, __get_pointer() + size());}
#else
_LIBCPP_INLINE_VISIBILITY
iterator begin() _NOEXCEPT
{return iterator(__get_pointer());}
_LIBCPP_INLINE_VISIBILITY
const_iterator begin() const _NOEXCEPT
{return const_iterator(__get_pointer());}
_LIBCPP_INLINE_VISIBILITY
iterator end() _NOEXCEPT
{return iterator(__get_pointer() + size());}
_LIBCPP_INLINE_VISIBILITY
const_iterator end() const _NOEXCEPT
{return const_iterator(__get_pointer() + size());}
#endif // _LIBCPP_DEBUG_LEVEL >= 2
_LIBCPP_INLINE_VISIBILITY
reverse_iterator rbegin() _NOEXCEPT
{return reverse_iterator(end());}
_LIBCPP_INLINE_VISIBILITY
const_reverse_iterator rbegin() const _NOEXCEPT
{return const_reverse_iterator(end());}
_LIBCPP_INLINE_VISIBILITY
reverse_iterator rend() _NOEXCEPT
{return reverse_iterator(begin());}
_LIBCPP_INLINE_VISIBILITY
const_reverse_iterator rend() const _NOEXCEPT
{return const_reverse_iterator(begin());}
_LIBCPP_INLINE_VISIBILITY
const_iterator cbegin() const _NOEXCEPT
{return begin();}
_LIBCPP_INLINE_VISIBILITY
const_iterator cend() const _NOEXCEPT
{return end();}
_LIBCPP_INLINE_VISIBILITY
const_reverse_iterator crbegin() const _NOEXCEPT
{return rbegin();}
_LIBCPP_INLINE_VISIBILITY
const_reverse_iterator crend() const _NOEXCEPT
{return rend();}
_LIBCPP_INLINE_VISIBILITY size_type size() const _NOEXCEPT
{return __is_long() ? __get_long_size() : __get_short_size();}
_LIBCPP_INLINE_VISIBILITY size_type length() const _NOEXCEPT {return size();}
_LIBCPP_INLINE_VISIBILITY size_type max_size() const _NOEXCEPT;
_LIBCPP_INLINE_VISIBILITY size_type capacity() const _NOEXCEPT
{return (__is_long() ? __get_long_cap()
: static_cast<size_type>(__min_cap)) - 1;}
void resize(size_type __n, value_type __c);
_LIBCPP_INLINE_VISIBILITY void resize(size_type __n) {resize(__n, value_type());}
void reserve(size_type __res_arg);
_LIBCPP_INLINE_VISIBILITY void __resize_default_init(size_type __n);
_LIBCPP_INLINE_VISIBILITY
void reserve() _NOEXCEPT {reserve(0);}
_LIBCPP_INLINE_VISIBILITY
void shrink_to_fit() _NOEXCEPT {reserve();}
_LIBCPP_INLINE_VISIBILITY
void clear() _NOEXCEPT;
_LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
bool empty() const _NOEXCEPT {return size() == 0;}
_LIBCPP_INLINE_VISIBILITY const_reference operator[](size_type __pos) const _NOEXCEPT;
_LIBCPP_INLINE_VISIBILITY reference operator[](size_type __pos) _NOEXCEPT;
const_reference at(size_type __n) const;
reference at(size_type __n);
_LIBCPP_INLINE_VISIBILITY basic_string& operator+=(const basic_string& __str) {return append(__str);}
template <class _Tp>
_LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
typename enable_if
<
__can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
basic_string&
>::type
operator+=(const _Tp& __t) {__self_view __sv = __t; return append(__sv);}
_LIBCPP_INLINE_VISIBILITY basic_string& operator+=(const value_type* __s) {return append(__s);}
_LIBCPP_INLINE_VISIBILITY basic_string& operator+=(value_type __c) {push_back(__c); return *this;}
#ifndef _LIBCPP_CXX03_LANG
_LIBCPP_INLINE_VISIBILITY basic_string& operator+=(initializer_list<value_type> __il) {return append(__il);}
#endif // _LIBCPP_CXX03_LANG
_LIBCPP_INLINE_VISIBILITY
basic_string& append(const basic_string& __str);
template <class _Tp>
_LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
typename enable_if
<
__can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
basic_string&
>::type
append(const _Tp& __t) { __self_view __sv = __t; return append(__sv.data(), __sv.size()); }
basic_string& append(const basic_string& __str, size_type __pos, size_type __n=npos);
template <class _Tp>
_LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
typename enable_if
<
__can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
basic_string&
>::type
append(const _Tp& __t, size_type __pos, size_type __n=npos);
basic_string& append(const value_type* __s, size_type __n);
basic_string& append(const value_type* __s);
basic_string& append(size_type __n, value_type __c);
_LIBCPP_INLINE_VISIBILITY
void __append_default_init(size_type __n);
template <class _ForwardIterator>
_LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
basic_string& __append_forward_unsafe(_ForwardIterator, _ForwardIterator);
template<class _InputIterator>
_LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
typename enable_if
<
__is_exactly_input_iterator<_InputIterator>::value
|| !__libcpp_string_gets_noexcept_iterator<_InputIterator>::value,
basic_string&
>::type
_LIBCPP_INLINE_VISIBILITY
append(_InputIterator __first, _InputIterator __last) {
const basic_string __temp (__first, __last, __alloc());
append(__temp.data(), __temp.size());
return *this;
}
template<class _ForwardIterator>
_LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
typename enable_if
<
__is_forward_iterator<_ForwardIterator>::value
&& __libcpp_string_gets_noexcept_iterator<_ForwardIterator>::value,
basic_string&
>::type
_LIBCPP_INLINE_VISIBILITY
append(_ForwardIterator __first, _ForwardIterator __last) {
return __append_forward_unsafe(__first, __last);
}
#ifndef _LIBCPP_CXX03_LANG
_LIBCPP_INLINE_VISIBILITY
basic_string& append(initializer_list<value_type> __il) {return append(__il.begin(), __il.size());}
#endif // _LIBCPP_CXX03_LANG
void push_back(value_type __c);
_LIBCPP_INLINE_VISIBILITY
void pop_back();
_LIBCPP_INLINE_VISIBILITY reference front() _NOEXCEPT;
_LIBCPP_INLINE_VISIBILITY const_reference front() const _NOEXCEPT;
_LIBCPP_INLINE_VISIBILITY reference back() _NOEXCEPT;
_LIBCPP_INLINE_VISIBILITY const_reference back() const _NOEXCEPT;
template <class _Tp>
_LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
typename enable_if
<
__can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
basic_string&
>::type
assign(const _Tp & __t) { __self_view __sv = __t; return assign(__sv.data(), __sv.size()); }
_LIBCPP_INLINE_VISIBILITY
basic_string& assign(const basic_string& __str) { return *this = __str; }
#ifndef _LIBCPP_CXX03_LANG
_LIBCPP_INLINE_VISIBILITY
basic_string& assign(basic_string&& __str)
_NOEXCEPT_((__noexcept_move_assign_container<_Allocator, __alloc_traits>::value))
{*this = _VSTD::move(__str); return *this;}
#endif
basic_string& assign(const basic_string& __str, size_type __pos, size_type __n=npos);
template <class _Tp>
_LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
typename enable_if
<
__can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
basic_string&
>::type
assign(const _Tp & __t, size_type __pos, size_type __n=npos);
basic_string& assign(const value_type* __s, size_type __n);
basic_string& assign(const value_type* __s);
basic_string& assign(size_type __n, value_type __c);
template<class _InputIterator>
_LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
typename enable_if
<
__is_exactly_input_iterator<_InputIterator>::value
|| !__libcpp_string_gets_noexcept_iterator<_InputIterator>::value,
basic_string&
>::type
assign(_InputIterator __first, _InputIterator __last);
template<class _ForwardIterator>
_LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
typename enable_if
<
__is_forward_iterator<_ForwardIterator>::value
&& __libcpp_string_gets_noexcept_iterator<_ForwardIterator>::value,
basic_string&
>::type
assign(_ForwardIterator __first, _ForwardIterator __last);
#ifndef _LIBCPP_CXX03_LANG
_LIBCPP_INLINE_VISIBILITY
basic_string& assign(initializer_list<value_type> __il) {return assign(__il.begin(), __il.size());}
#endif // _LIBCPP_CXX03_LANG
_LIBCPP_INLINE_VISIBILITY
basic_string& insert(size_type __pos1, const basic_string& __str);
template <class _Tp>
_LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
typename enable_if
<
__can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
basic_string&
>::type
insert(size_type __pos1, const _Tp& __t)
{ __self_view __sv = __t; return insert(__pos1, __sv.data(), __sv.size()); }
template <class _Tp>
_LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
typename enable_if
<
__can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
basic_string&
>::type
insert(size_type __pos1, const _Tp& __t, size_type __pos2, size_type __n=npos);
basic_string& insert(size_type __pos1, const basic_string& __str, size_type __pos2, size_type __n=npos);
basic_string& insert(size_type __pos, const value_type* __s, size_type __n);
basic_string& insert(size_type __pos, const value_type* __s);
basic_string& insert(size_type __pos, size_type __n, value_type __c);
iterator insert(const_iterator __pos, value_type __c);
_LIBCPP_INLINE_VISIBILITY
iterator insert(const_iterator __pos, size_type __n, value_type __c);
template<class _InputIterator>
_LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
typename enable_if
<
__is_exactly_input_iterator<_InputIterator>::value
|| !__libcpp_string_gets_noexcept_iterator<_InputIterator>::value,
iterator
>::type
insert(const_iterator __pos, _InputIterator __first, _InputIterator __last);
template<class _ForwardIterator>
_LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
typename enable_if
<
__is_forward_iterator<_ForwardIterator>::value
&& __libcpp_string_gets_noexcept_iterator<_ForwardIterator>::value,
iterator
>::type
insert(const_iterator __pos, _ForwardIterator __first, _ForwardIterator __last);
#ifndef _LIBCPP_CXX03_LANG
_LIBCPP_INLINE_VISIBILITY
iterator insert(const_iterator __pos, initializer_list<value_type> __il)
{return insert(__pos, __il.begin(), __il.end());}
#endif // _LIBCPP_CXX03_LANG
basic_string& erase(size_type __pos = 0, size_type __n = npos);
_LIBCPP_INLINE_VISIBILITY
iterator erase(const_iterator __pos);
_LIBCPP_INLINE_VISIBILITY
iterator erase(const_iterator __first, const_iterator __last);
_LIBCPP_INLINE_VISIBILITY
basic_string& replace(size_type __pos1, size_type __n1, const basic_string& __str);
template <class _Tp>
_LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
typename enable_if
<
__can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
basic_string&
>::type
replace(size_type __pos1, size_type __n1, const _Tp& __t) { __self_view __sv = __t; return replace(__pos1, __n1, __sv.data(), __sv.size()); }
basic_string& replace(size_type __pos1, size_type __n1, const basic_string& __str, size_type __pos2, size_type __n2=npos);
template <class _Tp>
_LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
typename enable_if
<
__can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
basic_string&
>::type
replace(size_type __pos1, size_type __n1, const _Tp& __t, size_type __pos2, size_type __n2=npos);
basic_string& replace(size_type __pos, size_type __n1, const value_type* __s, size_type __n2);
basic_string& replace(size_type __pos, size_type __n1, const value_type* __s);
basic_string& replace(size_type __pos, size_type __n1, size_type __n2, value_type __c);
_LIBCPP_INLINE_VISIBILITY
basic_string& replace(const_iterator __i1, const_iterator __i2, const basic_string& __str);
template <class _Tp>
_LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
typename enable_if
<
__can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
basic_string&
>::type
replace(const_iterator __i1, const_iterator __i2, const _Tp& __t) { __self_view __sv = __t; return replace(__i1 - begin(), __i2 - __i1, __sv); }
_LIBCPP_INLINE_VISIBILITY
basic_string& replace(const_iterator __i1, const_iterator __i2, const value_type* __s, size_type __n);
_LIBCPP_INLINE_VISIBILITY
basic_string& replace(const_iterator __i1, const_iterator __i2, const value_type* __s);
_LIBCPP_INLINE_VISIBILITY
basic_string& replace(const_iterator __i1, const_iterator __i2, size_type __n, value_type __c);
template<class _InputIterator>
_LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
typename enable_if
<
__is_input_iterator<_InputIterator>::value,
basic_string&
>::type
replace(const_iterator __i1, const_iterator __i2, _InputIterator __j1, _InputIterator __j2);
#ifndef _LIBCPP_CXX03_LANG
_LIBCPP_INLINE_VISIBILITY
basic_string& replace(const_iterator __i1, const_iterator __i2, initializer_list<value_type> __il)
{return replace(__i1, __i2, __il.begin(), __il.end());}
#endif // _LIBCPP_CXX03_LANG
size_type copy(value_type* __s, size_type __n, size_type __pos = 0) const;
_LIBCPP_INLINE_VISIBILITY
basic_string substr(size_type __pos = 0, size_type __n = npos) const;
_LIBCPP_INLINE_VISIBILITY
void swap(basic_string& __str)
#if _LIBCPP_STD_VER >= 14
_NOEXCEPT;
#else
_NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value ||
__is_nothrow_swappable<allocator_type>::value);
#endif
_LIBCPP_INLINE_VISIBILITY
const value_type* c_str() const _NOEXCEPT {return data();}
_LIBCPP_INLINE_VISIBILITY
const value_type* data() const _NOEXCEPT {return _VSTD::__to_raw_pointer(__get_pointer());}
#if _LIBCPP_STD_VER > 14 || defined(_LIBCPP_BUILDING_LIBRARY)
_LIBCPP_INLINE_VISIBILITY
value_type* data() _NOEXCEPT {return _VSTD::__to_raw_pointer(__get_pointer());}
#endif
_LIBCPP_INLINE_VISIBILITY
allocator_type get_allocator() const _NOEXCEPT {return __alloc();}
_LIBCPP_INLINE_VISIBILITY
size_type find(const basic_string& __str, size_type __pos = 0) const _NOEXCEPT;
template <class _Tp>
_LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
typename enable_if
<
__can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
size_type
>::type
find(const _Tp& __t, size_type __pos = 0) const;
size_type find(const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPT;
_LIBCPP_INLINE_VISIBILITY
size_type find(const value_type* __s, size_type __pos = 0) const _NOEXCEPT;
size_type find(value_type __c, size_type __pos = 0) const _NOEXCEPT;
_LIBCPP_INLINE_VISIBILITY
size_type rfind(const basic_string& __str, size_type __pos = npos) const _NOEXCEPT;
template <class _Tp>
_LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
typename enable_if
<
__can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
size_type
>::type
rfind(const _Tp& __t, size_type __pos = npos) const;
size_type rfind(const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPT;
_LIBCPP_INLINE_VISIBILITY
size_type rfind(const value_type* __s, size_type __pos = npos) const _NOEXCEPT;
size_type rfind(value_type __c, size_type __pos = npos) const _NOEXCEPT;
_LIBCPP_INLINE_VISIBILITY
size_type find_first_of(const basic_string& __str, size_type __pos = 0) const _NOEXCEPT;
template <class _Tp>
_LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
typename enable_if
<
__can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
size_type
>::type
find_first_of(const _Tp& __t, size_type __pos = 0) const;
size_type find_first_of(const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPT;
_LIBCPP_INLINE_VISIBILITY
size_type find_first_of(const value_type* __s, size_type __pos = 0) const _NOEXCEPT;
_LIBCPP_INLINE_VISIBILITY
size_type find_first_of(value_type __c, size_type __pos = 0) const _NOEXCEPT;
_LIBCPP_INLINE_VISIBILITY
size_type find_last_of(const basic_string& __str, size_type __pos = npos) const _NOEXCEPT;
template <class _Tp>
_LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
typename enable_if
<
__can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
size_type
>::type
find_last_of(const _Tp& __t, size_type __pos = npos) const;
size_type find_last_of(const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPT;
_LIBCPP_INLINE_VISIBILITY
size_type find_last_of(const value_type* __s, size_type __pos = npos) const _NOEXCEPT;
_LIBCPP_INLINE_VISIBILITY
size_type find_last_of(value_type __c, size_type __pos = npos) const _NOEXCEPT;
_LIBCPP_INLINE_VISIBILITY
size_type find_first_not_of(const basic_string& __str, size_type __pos = 0) const _NOEXCEPT;
template <class _Tp>
_LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
typename enable_if
<
__can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
size_type
>::type
find_first_not_of(const _Tp &__t, size_type __pos = 0) const;
size_type find_first_not_of(const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPT;
_LIBCPP_INLINE_VISIBILITY
size_type find_first_not_of(const value_type* __s, size_type __pos = 0) const _NOEXCEPT;
_LIBCPP_INLINE_VISIBILITY
size_type find_first_not_of(value_type __c, size_type __pos = 0) const _NOEXCEPT;
_LIBCPP_INLINE_VISIBILITY
size_type find_last_not_of(const basic_string& __str, size_type __pos = npos) const _NOEXCEPT;
template <class _Tp>
_LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
typename enable_if
<
__can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
size_type
>::type
find_last_not_of(const _Tp& __t, size_type __pos = npos) const;
size_type find_last_not_of(const value_type* __s, size_type __pos, size_type __n) const _NOEXCEPT;
_LIBCPP_INLINE_VISIBILITY
size_type find_last_not_of(const value_type* __s, size_type __pos = npos) const _NOEXCEPT;
_LIBCPP_INLINE_VISIBILITY
size_type find_last_not_of(value_type __c, size_type __pos = npos) const _NOEXCEPT;
_LIBCPP_INLINE_VISIBILITY
int compare(const basic_string& __str) const _NOEXCEPT;
template <class _Tp>
_LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
typename enable_if
<
__can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
int
>::type
compare(const _Tp &__t) const;
template <class _Tp>
_LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
typename enable_if
<
__can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
int
>::type
compare(size_type __pos1, size_type __n1, const _Tp& __t) const;
_LIBCPP_INLINE_VISIBILITY
int compare(size_type __pos1, size_type __n1, const basic_string& __str) const;
int compare(size_type __pos1, size_type __n1, const basic_string& __str, size_type __pos2, size_type __n2=npos) const;
template <class _Tp>
inline _LIBCPP_INLINE_VISIBILITY
typename enable_if
<
__can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
int
>::type
compare(size_type __pos1, size_type __n1, const _Tp& __t, size_type __pos2, size_type __n2=npos) const;
int compare(const value_type* __s) const _NOEXCEPT;
int compare(size_type __pos1, size_type __n1, const value_type* __s) const;
int compare(size_type __pos1, size_type __n1, const value_type* __s, size_type __n2) const;
#if _LIBCPP_STD_VER > 17
_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
bool starts_with(__self_view __sv) const _NOEXCEPT
{ return __self_view(data(), size()).starts_with(__sv); }
_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
bool starts_with(value_type __c) const _NOEXCEPT
{ return !empty() && _Traits::eq(front(), __c); }
_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
bool starts_with(const value_type* __s) const _NOEXCEPT
{ return starts_with(__self_view(__s)); }
_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
bool ends_with(__self_view __sv) const _NOEXCEPT
{ return __self_view(data(), size()).ends_with( __sv); }
_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
bool ends_with(value_type __c) const _NOEXCEPT
{ return !empty() && _Traits::eq(back(), __c); }
_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
bool ends_with(const value_type* __s) const _NOEXCEPT
{ return ends_with(__self_view(__s)); }
#endif
_LIBCPP_INLINE_VISIBILITY bool __invariants() const;
_LIBCPP_INLINE_VISIBILITY void __clear_and_shrink() _NOEXCEPT;
_LIBCPP_INLINE_VISIBILITY
bool __is_long() const _NOEXCEPT
{return bool(__r_.first().__s.__size_ & __short_mask);}
#if _LIBCPP_DEBUG_LEVEL >= 2
bool __dereferenceable(const const_iterator* __i) const;
bool __decrementable(const const_iterator* __i) const;
bool __addable(const const_iterator* __i, ptrdiff_t __n) const;
bool __subscriptable(const const_iterator* __i, ptrdiff_t __n) const;
#endif // _LIBCPP_DEBUG_LEVEL >= 2
private:
_LIBCPP_INLINE_VISIBILITY
allocator_type& __alloc() _NOEXCEPT
{return __r_.second();}
_LIBCPP_INLINE_VISIBILITY
const allocator_type& __alloc() const _NOEXCEPT
{return __r_.second();}
#ifdef _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
_LIBCPP_INLINE_VISIBILITY
void __set_short_size(size_type __s) _NOEXCEPT
# ifdef _LIBCPP_BIG_ENDIAN
{__r_.first().__s.__size_ = (unsigned char)(__s << 1);}
# else
{__r_.first().__s.__size_ = (unsigned char)(__s);}
# endif
_LIBCPP_INLINE_VISIBILITY
size_type __get_short_size() const _NOEXCEPT
# ifdef _LIBCPP_BIG_ENDIAN
{return __r_.first().__s.__size_ >> 1;}
# else
{return __r_.first().__s.__size_;}
# endif
#else // _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
_LIBCPP_INLINE_VISIBILITY
void __set_short_size(size_type __s) _NOEXCEPT
# ifdef _LIBCPP_BIG_ENDIAN
{__r_.first().__s.__size_ = (unsigned char)(__s);}
# else
{__r_.first().__s.__size_ = (unsigned char)(__s << 1);}
# endif
_LIBCPP_INLINE_VISIBILITY
size_type __get_short_size() const _NOEXCEPT
# ifdef _LIBCPP_BIG_ENDIAN
{return __r_.first().__s.__size_;}
# else
{return __r_.first().__s.__size_ >> 1;}
# endif
#endif // _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
_LIBCPP_INLINE_VISIBILITY
void __set_long_size(size_type __s) _NOEXCEPT
{__r_.first().__l.__size_ = __s;}
_LIBCPP_INLINE_VISIBILITY
size_type __get_long_size() const _NOEXCEPT
{return __r_.first().__l.__size_;}
_LIBCPP_INLINE_VISIBILITY
void __set_size(size_type __s) _NOEXCEPT
{if (__is_long()) __set_long_size(__s); else __set_short_size(__s);}
_LIBCPP_INLINE_VISIBILITY
void __set_long_cap(size_type __s) _NOEXCEPT
{__r_.first().__l.__cap_ = __long_mask | __s;}
_LIBCPP_INLINE_VISIBILITY
size_type __get_long_cap() const _NOEXCEPT
{return __r_.first().__l.__cap_ & size_type(~__long_mask);}
_LIBCPP_INLINE_VISIBILITY
void __set_long_pointer(pointer __p) _NOEXCEPT
{__r_.first().__l.__data_ = __p;}
_LIBCPP_INLINE_VISIBILITY
pointer __get_long_pointer() _NOEXCEPT
{return __r_.first().__l.__data_;}
_LIBCPP_INLINE_VISIBILITY
const_pointer __get_long_pointer() const _NOEXCEPT
{return __r_.first().__l.__data_;}
_LIBCPP_INLINE_VISIBILITY
pointer __get_short_pointer() _NOEXCEPT
{return pointer_traits<pointer>::pointer_to(__r_.first().__s.__data_[0]);}
_LIBCPP_INLINE_VISIBILITY
const_pointer __get_short_pointer() const _NOEXCEPT
{return pointer_traits<const_pointer>::pointer_to(__r_.first().__s.__data_[0]);}
_LIBCPP_INLINE_VISIBILITY
pointer __get_pointer() _NOEXCEPT
{return __is_long() ? __get_long_pointer() : __get_short_pointer();}
_LIBCPP_INLINE_VISIBILITY
const_pointer __get_pointer() const _NOEXCEPT
{return __is_long() ? __get_long_pointer() : __get_short_pointer();}
_LIBCPP_INLINE_VISIBILITY
void __zero() _NOEXCEPT
{
size_type (&__a)[__n_words] = __r_.first().__r.__words;
for (unsigned __i = 0; __i < __n_words; ++__i)
__a[__i] = 0;
}
template <size_type __a> static
_LIBCPP_INLINE_VISIBILITY
size_type __align_it(size_type __s) _NOEXCEPT
{return (__s + (__a-1)) & ~(__a-1);}
enum {__alignment = 16};
static _LIBCPP_INLINE_VISIBILITY
size_type __recommend(size_type __s) _NOEXCEPT
{
if (__s < __min_cap) return static_cast<size_type>(__min_cap) - 1;
size_type __guess = __align_it<sizeof(value_type) < __alignment ?
__alignment/sizeof(value_type) : 1 > (__s+1) - 1;
if (__guess == __min_cap) ++__guess;
return __guess;
}
inline
void __init(const value_type* __s, size_type __sz, size_type __reserve);
inline
void __init(const value_type* __s, size_type __sz);
inline
void __init(size_type __n, value_type __c);
template <class _InputIterator>
inline
typename enable_if
<
__is_exactly_input_iterator<_InputIterator>::value,
void
>::type
__init(_InputIterator __first, _InputIterator __last);
template <class _ForwardIterator>
inline
typename enable_if
<
__is_forward_iterator<_ForwardIterator>::value,
void
>::type
__init(_ForwardIterator __first, _ForwardIterator __last);
void __grow_by(size_type __old_cap, size_type __delta_cap, size_type __old_sz,
size_type __n_copy, size_type __n_del, size_type __n_add = 0);
void __grow_by_and_replace(size_type __old_cap, size_type __delta_cap, size_type __old_sz,
size_type __n_copy, size_type __n_del,
size_type __n_add, const value_type* __p_new_stuff);
_LIBCPP_INLINE_VISIBILITY
void __erase_to_end(size_type __pos);
_LIBCPP_INLINE_VISIBILITY
void __copy_assign_alloc(const basic_string& __str)
{__copy_assign_alloc(__str, integral_constant<bool,
__alloc_traits::propagate_on_container_copy_assignment::value>());}
_LIBCPP_INLINE_VISIBILITY
void __copy_assign_alloc(const basic_string& __str, true_type)
{
if (__alloc() == __str.__alloc())
__alloc() = __str.__alloc();
else
{
if (!__str.__is_long())
{
__clear_and_shrink();
__alloc() = __str.__alloc();
}
else
{
allocator_type __a = __str.__alloc();
pointer __p = __alloc_traits::allocate(__a, __str.__get_long_cap());
__clear_and_shrink();
__alloc() = _VSTD::move(__a);
__set_long_pointer(__p);
__set_long_cap(__str.__get_long_cap());
__set_long_size(__str.size());
}
}
}
_LIBCPP_INLINE_VISIBILITY
void __copy_assign_alloc(const basic_string&, false_type) _NOEXCEPT
{}
#ifndef _LIBCPP_CXX03_LANG
_LIBCPP_INLINE_VISIBILITY
void __move_assign(basic_string& __str, false_type)
_NOEXCEPT_(__alloc_traits::is_always_equal::value);
_LIBCPP_INLINE_VISIBILITY
void __move_assign(basic_string& __str, true_type)
#if _LIBCPP_STD_VER > 14
_NOEXCEPT;
#else
_NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value);
#endif
#endif
_LIBCPP_INLINE_VISIBILITY
void
__move_assign_alloc(basic_string& __str)
_NOEXCEPT_(
!__alloc_traits::propagate_on_container_move_assignment::value ||
is_nothrow_move_assignable<allocator_type>::value)
{__move_assign_alloc(__str, integral_constant<bool,
__alloc_traits::propagate_on_container_move_assignment::value>());}
_LIBCPP_INLINE_VISIBILITY
void __move_assign_alloc(basic_string& __c, true_type)
_NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value)
{
__alloc() = _VSTD::move(__c.__alloc());
}
_LIBCPP_INLINE_VISIBILITY
void __move_assign_alloc(basic_string&, false_type)
_NOEXCEPT
{}
_LIBCPP_INLINE_VISIBILITY void __invalidate_all_iterators();
_LIBCPP_INLINE_VISIBILITY void __invalidate_iterators_past(size_type);
friend basic_string operator+<>(const basic_string&, const basic_string&);
friend basic_string operator+<>(const value_type*, const basic_string&);
friend basic_string operator+<>(value_type, const basic_string&);
friend basic_string operator+<>(const basic_string&, const value_type*);
friend basic_string operator+<>(const basic_string&, value_type);
};
#ifndef _LIBCPP_HAS_NO_DEDUCTION_GUIDES
template<class _InputIterator,
class _CharT = typename iterator_traits<_InputIterator>::value_type,
class _Allocator = allocator<_CharT>,
class = typename enable_if<__is_input_iterator<_InputIterator>::value, void>::type,
class = typename enable_if<__is_allocator<_Allocator>::value, void>::type
>
basic_string(_InputIterator, _InputIterator, _Allocator = _Allocator())
-> basic_string<_CharT, char_traits<_CharT>, _Allocator>;
template<class _CharT,
class _Traits,
class _Allocator = allocator<_CharT>,
class = typename enable_if<__is_allocator<_Allocator>::value, void>::type
>
explicit basic_string(basic_string_view<_CharT, _Traits>, const _Allocator& = _Allocator())
-> basic_string<_CharT, _Traits, _Allocator>;
template<class _CharT,
class _Traits,
class _Allocator = allocator<_CharT>,
class = typename enable_if<__is_allocator<_Allocator>::value, void>::type,
class _Sz = typename allocator_traits<_Allocator>::size_type
>
basic_string(basic_string_view<_CharT, _Traits>, _Sz, _Sz, const _Allocator& = _Allocator())
-> basic_string<_CharT, _Traits, _Allocator>;
#endif
template <class _CharT, class _Traits, class _Allocator>
inline
void
basic_string<_CharT, _Traits, _Allocator>::__invalidate_all_iterators()
{
#if _LIBCPP_DEBUG_LEVEL >= 2
__get_db()->__invalidate_all(this);
#endif // _LIBCPP_DEBUG_LEVEL >= 2
}
template <class _CharT, class _Traits, class _Allocator>
inline
void
basic_string<_CharT, _Traits, _Allocator>::__invalidate_iterators_past(size_type
#if _LIBCPP_DEBUG_LEVEL >= 2
__pos
#endif
)
{
#if _LIBCPP_DEBUG_LEVEL >= 2
__c_node* __c = __get_db()->__find_c_and_lock(this);
if (__c)
{
const_pointer __new_last = __get_pointer() + __pos;
for (__i_node** __p = __c->end_; __p != __c->beg_; )
{
--__p;
const_iterator* __i = static_cast<const_iterator*>((*__p)->__i_);
if (__i->base() > __new_last)
{
(*__p)->__c_ = nullptr;
if (--__c->end_ != __p)
memmove(__p, __p+1, (__c->end_ - __p)*sizeof(__i_node*));
}
}
__get_db()->unlock();
}
#endif // _LIBCPP_DEBUG_LEVEL >= 2
}
template <class _CharT, class _Traits, class _Allocator>
inline
basic_string<_CharT, _Traits, _Allocator>::basic_string()
_NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value)
{
#if _LIBCPP_DEBUG_LEVEL >= 2
__get_db()->__insert_c(this);
#endif
__zero();
}
template <class _CharT, class _Traits, class _Allocator>
inline
basic_string<_CharT, _Traits, _Allocator>::basic_string(const allocator_type& __a)
#if _LIBCPP_STD_VER <= 14
_NOEXCEPT_(is_nothrow_copy_constructible<allocator_type>::value)
#else
_NOEXCEPT
#endif
: __r_(__second_tag(), __a)
{
#if _LIBCPP_DEBUG_LEVEL >= 2
__get_db()->__insert_c(this);
#endif
__zero();
}
template <class _CharT, class _Traits, class _Allocator>
void basic_string<_CharT, _Traits, _Allocator>::__init(const value_type* __s,
size_type __sz,
size_type __reserve)
{
if (__reserve > max_size())
this->__throw_length_error();
pointer __p;
if (__reserve < __min_cap)
{
__set_short_size(__sz);
__p = __get_short_pointer();
}
else
{
size_type __cap = __recommend(__reserve);
__p = __alloc_traits::allocate(__alloc(), __cap+1);
__set_long_pointer(__p);
__set_long_cap(__cap+1);
__set_long_size(__sz);
}
traits_type::copy(_VSTD::__to_raw_pointer(__p), __s, __sz);
traits_type::assign(__p[__sz], value_type());
}
template <class _CharT, class _Traits, class _Allocator>
void
basic_string<_CharT, _Traits, _Allocator>::__init(const value_type* __s, size_type __sz)
{
if (__sz > max_size())
this->__throw_length_error();
pointer __p;
if (__sz < __min_cap)
{
__set_short_size(__sz);
__p = __get_short_pointer();
}
else
{
size_type __cap = __recommend(__sz);
__p = __alloc_traits::allocate(__alloc(), __cap+1);
__set_long_pointer(__p);
__set_long_cap(__cap+1);
__set_long_size(__sz);
}
traits_type::copy(_VSTD::__to_raw_pointer(__p), __s, __sz);
traits_type::assign(__p[__sz], value_type());
}
template <class _CharT, class _Traits, class _Allocator>
template <class>
basic_string<_CharT, _Traits, _Allocator>::basic_string(const _CharT* __s, const _Allocator& __a)
: __r_(__second_tag(), __a)
{
_LIBCPP_ASSERT(__s != nullptr, "basic_string(const char*, allocator) detected nullptr");
__init(__s, traits_type::length(__s));
#if _LIBCPP_DEBUG_LEVEL >= 2
__get_db()->__insert_c(this);
#endif
}
template <class _CharT, class _Traits, class _Allocator>
inline
basic_string<_CharT, _Traits, _Allocator>::basic_string(const _CharT* __s, size_type __n)
{
_LIBCPP_ASSERT(__n == 0 || __s != nullptr, "basic_string(const char*, n) detected nullptr");
__init(__s, __n);
#if _LIBCPP_DEBUG_LEVEL >= 2
__get_db()->__insert_c(this);
#endif
}
template <class _CharT, class _Traits, class _Allocator>
inline
basic_string<_CharT, _Traits, _Allocator>::basic_string(const _CharT* __s, size_type __n, const _Allocator& __a)
: __r_(__second_tag(), __a)
{
_LIBCPP_ASSERT(__n == 0 || __s != nullptr, "basic_string(const char*, n, allocator) detected nullptr");
__init(__s, __n);
#if _LIBCPP_DEBUG_LEVEL >= 2
__get_db()->__insert_c(this);
#endif
}
template <class _CharT, class _Traits, class _Allocator>
basic_string<_CharT, _Traits, _Allocator>::basic_string(const basic_string& __str)
: __r_(__second_tag(), __alloc_traits::select_on_container_copy_construction(__str.__alloc()))
{
if (!__str.__is_long())
__r_.first().__r = __str.__r_.first().__r;
else
__init(_VSTD::__to_raw_pointer(__str.__get_long_pointer()), __str.__get_long_size());
#if _LIBCPP_DEBUG_LEVEL >= 2
__get_db()->__insert_c(this);
#endif
}
template <class _CharT, class _Traits, class _Allocator>
basic_string<_CharT, _Traits, _Allocator>::basic_string(
const basic_string& __str, const allocator_type& __a)
: __r_(__second_tag(), __a)
{
if (!__str.__is_long())
__r_.first().__r = __str.__r_.first().__r;
else
__init(_VSTD::__to_raw_pointer(__str.__get_long_pointer()), __str.__get_long_size());
#if _LIBCPP_DEBUG_LEVEL >= 2
__get_db()->__insert_c(this);
#endif
}
#ifndef _LIBCPP_CXX03_LANG
template <class _CharT, class _Traits, class _Allocator>
inline
basic_string<_CharT, _Traits, _Allocator>::basic_string(basic_string&& __str)
#if _LIBCPP_STD_VER <= 14
_NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value)
#else
_NOEXCEPT
#endif
: __r_(_VSTD::move(__str.__r_))
{
__str.__zero();
#if _LIBCPP_DEBUG_LEVEL >= 2
__get_db()->__insert_c(this);
if (__is_long())
__get_db()->swap(this, &__str);
#endif
}
template <class _CharT, class _Traits, class _Allocator>
inline
basic_string<_CharT, _Traits, _Allocator>::basic_string(basic_string&& __str, const allocator_type& __a)
: __r_(__second_tag(), __a)
{
if (__str.__is_long() && __a != __str.__alloc()) // copy, not move
__init(_VSTD::__to_raw_pointer(__str.__get_long_pointer()), __str.__get_long_size());
else
{
__r_.first().__r = __str.__r_.first().__r;
__str.__zero();
}
#if _LIBCPP_DEBUG_LEVEL >= 2
__get_db()->__insert_c(this);
if (__is_long())
__get_db()->swap(this, &__str);
#endif
}
#endif // _LIBCPP_CXX03_LANG
template <class _CharT, class _Traits, class _Allocator>
void
basic_string<_CharT, _Traits, _Allocator>::__init(size_type __n, value_type __c)
{
if (__n > max_size())
this->__throw_length_error();
pointer __p;
if (__n < __min_cap)
{
__set_short_size(__n);
__p = __get_short_pointer();
}
else
{
size_type __cap = __recommend(__n);
__p = __alloc_traits::allocate(__alloc(), __cap+1);
__set_long_pointer(__p);
__set_long_cap(__cap+1);
__set_long_size(__n);
}
traits_type::assign(_VSTD::__to_raw_pointer(__p), __n, __c);
traits_type::assign(__p[__n], value_type());
}
template <class _CharT, class _Traits, class _Allocator>
inline
basic_string<_CharT, _Traits, _Allocator>::basic_string(size_type __n, _CharT __c)
{
__init(__n, __c);
#if _LIBCPP_DEBUG_LEVEL >= 2
__get_db()->__insert_c(this);
#endif
}
template <class _CharT, class _Traits, class _Allocator>
template <class>
basic_string<_CharT, _Traits, _Allocator>::basic_string(size_type __n, _CharT __c, const _Allocator& __a)
: __r_(__second_tag(), __a)
{
__init(__n, __c);
#if _LIBCPP_DEBUG_LEVEL >= 2
__get_db()->__insert_c(this);
#endif
}
template <class _CharT, class _Traits, class _Allocator>
basic_string<_CharT, _Traits, _Allocator>::basic_string(const basic_string& __str,
size_type __pos, size_type __n,
const _Allocator& __a)
: __r_(__second_tag(), __a)
{
size_type __str_sz = __str.size();
if (__pos > __str_sz)
this->__throw_out_of_range();
__init(__str.data() + __pos, _VSTD::min(__n, __str_sz - __pos));
#if _LIBCPP_DEBUG_LEVEL >= 2
__get_db()->__insert_c(this);
#endif
}
template <class _CharT, class _Traits, class _Allocator>
inline
basic_string<_CharT, _Traits, _Allocator>::basic_string(const basic_string& __str, size_type __pos,
const _Allocator& __a)
: __r_(__second_tag(), __a)
{
size_type __str_sz = __str.size();
if (__pos > __str_sz)
this->__throw_out_of_range();
__init(__str.data() + __pos, __str_sz - __pos);
#if _LIBCPP_DEBUG_LEVEL >= 2
__get_db()->__insert_c(this);
#endif
}
template <class _CharT, class _Traits, class _Allocator>
template <class _Tp, class>
basic_string<_CharT, _Traits, _Allocator>::basic_string(
const _Tp& __t, size_type __pos, size_type __n, const allocator_type& __a)
: __r_(__second_tag(), __a)
{
__self_view __sv0 = __t;
__self_view __sv = __sv0.substr(__pos, __n);
__init(__sv.data(), __sv.size());
#if _LIBCPP_DEBUG_LEVEL >= 2
__get_db()->__insert_c(this);
#endif
}
template <class _CharT, class _Traits, class _Allocator>
template <class _Tp, class>
basic_string<_CharT, _Traits, _Allocator>::basic_string(const _Tp & __t)
{
__self_view __sv = __t;
__init(__sv.data(), __sv.size());
#if _LIBCPP_DEBUG_LEVEL >= 2
__get_db()->__insert_c(this);
#endif
}
template <class _CharT, class _Traits, class _Allocator>
template <class _Tp, class>
basic_string<_CharT, _Traits, _Allocator>::basic_string(const _Tp & __t, const _Allocator& __a)
: __r_(__second_tag(), __a)
{
__self_view __sv = __t;
__init(__sv.data(), __sv.size());
#if _LIBCPP_DEBUG_LEVEL >= 2
__get_db()->__insert_c(this);
#endif
}
template <class _CharT, class _Traits, class _Allocator>
template <class _InputIterator>
typename enable_if
<
__is_exactly_input_iterator<_InputIterator>::value,
void
>::type
basic_string<_CharT, _Traits, _Allocator>::__init(_InputIterator __first, _InputIterator __last)
{
__zero();
#ifndef _LIBCPP_NO_EXCEPTIONS
try
{
#endif // _LIBCPP_NO_EXCEPTIONS
for (; __first != __last; ++__first)
push_back(*__first);
#ifndef _LIBCPP_NO_EXCEPTIONS
}
catch (...)
{
if (__is_long())
__alloc_traits::deallocate(__alloc(), __get_long_pointer(), __get_long_cap());
throw;
}
#endif // _LIBCPP_NO_EXCEPTIONS
}
template <class _CharT, class _Traits, class _Allocator>
template <class _ForwardIterator>
typename enable_if
<
__is_forward_iterator<_ForwardIterator>::value,
void
>::type
basic_string<_CharT, _Traits, _Allocator>::__init(_ForwardIterator __first, _ForwardIterator __last)
{
size_type __sz = static_cast<size_type>(_VSTD::distance(__first, __last));
if (__sz > max_size())
this->__throw_length_error();
pointer __p;
if (__sz < __min_cap)
{
__set_short_size(__sz);
__p = __get_short_pointer();
}
else
{
size_type __cap = __recommend(__sz);
__p = __alloc_traits::allocate(__alloc(), __cap+1);
__set_long_pointer(__p);
__set_long_cap(__cap+1);
__set_long_size(__sz);
}
for (; __first != __last; ++__first, (void) ++__p)
traits_type::assign(*__p, *__first);
traits_type::assign(*__p, value_type());
}
template <class _CharT, class _Traits, class _Allocator>
template<class _InputIterator, class>
inline
basic_string<_CharT, _Traits, _Allocator>::basic_string(_InputIterator __first, _InputIterator __last)
{
__init(__first, __last);
#if _LIBCPP_DEBUG_LEVEL >= 2
__get_db()->__insert_c(this);
#endif
}
template <class _CharT, class _Traits, class _Allocator>
template<class _InputIterator, class>
inline
basic_string<_CharT, _Traits, _Allocator>::basic_string(_InputIterator __first, _InputIterator __last,
const allocator_type& __a)
: __r_(__second_tag(), __a)
{
__init(__first, __last);
#if _LIBCPP_DEBUG_LEVEL >= 2
__get_db()->__insert_c(this);
#endif
}
#ifndef _LIBCPP_CXX03_LANG
template <class _CharT, class _Traits, class _Allocator>
inline
basic_string<_CharT, _Traits, _Allocator>::basic_string(
initializer_list<_CharT> __il)
{
__init(__il.begin(), __il.end());
#if _LIBCPP_DEBUG_LEVEL >= 2
__get_db()->__insert_c(this);
#endif
}
template <class _CharT, class _Traits, class _Allocator>
inline
basic_string<_CharT, _Traits, _Allocator>::basic_string(
initializer_list<_CharT> __il, const _Allocator& __a)
: __r_(__second_tag(), __a)
{
__init(__il.begin(), __il.end());
#if _LIBCPP_DEBUG_LEVEL >= 2
__get_db()->__insert_c(this);
#endif
}
#endif // _LIBCPP_CXX03_LANG
template <class _CharT, class _Traits, class _Allocator>
basic_string<_CharT, _Traits, _Allocator>::~basic_string()
{
#if _LIBCPP_DEBUG_LEVEL >= 2
__get_db()->__erase_c(this);
#endif
if (__is_long())
__alloc_traits::deallocate(__alloc(), __get_long_pointer(), __get_long_cap());
}
template <class _CharT, class _Traits, class _Allocator>
void
basic_string<_CharT, _Traits, _Allocator>::__grow_by_and_replace
(size_type __old_cap, size_type __delta_cap, size_type __old_sz,
size_type __n_copy, size_type __n_del, size_type __n_add, const value_type* __p_new_stuff)
{
size_type __ms = max_size();
if (__delta_cap > __ms - __old_cap - 1)
this->__throw_length_error();
pointer __old_p = __get_pointer();
size_type __cap = __old_cap < __ms / 2 - __alignment ?
__recommend(_VSTD::max(__old_cap + __delta_cap, 2 * __old_cap)) :
__ms - 1;
pointer __p = __alloc_traits::allocate(__alloc(), __cap+1);
__invalidate_all_iterators();
if (__n_copy != 0)
traits_type::copy(_VSTD::__to_raw_pointer(__p),
_VSTD::__to_raw_pointer(__old_p), __n_copy);
if (__n_add != 0)
traits_type::copy(_VSTD::__to_raw_pointer(__p) + __n_copy, __p_new_stuff, __n_add);
size_type __sec_cp_sz = __old_sz - __n_del - __n_copy;
if (__sec_cp_sz != 0)
traits_type::copy(_VSTD::__to_raw_pointer(__p) + __n_copy + __n_add,
_VSTD::__to_raw_pointer(__old_p) + __n_copy + __n_del, __sec_cp_sz);
if (__old_cap+1 != __min_cap)
__alloc_traits::deallocate(__alloc(), __old_p, __old_cap+1);
__set_long_pointer(__p);
__set_long_cap(__cap+1);
__old_sz = __n_copy + __n_add + __sec_cp_sz;
__set_long_size(__old_sz);
traits_type::assign(__p[__old_sz], value_type());
}
template <class _CharT, class _Traits, class _Allocator>
void
basic_string<_CharT, _Traits, _Allocator>::__grow_by(size_type __old_cap, size_type __delta_cap, size_type __old_sz,
size_type __n_copy, size_type __n_del, size_type __n_add)
{
size_type __ms = max_size();
if (__delta_cap > __ms - __old_cap)
this->__throw_length_error();
pointer __old_p = __get_pointer();
size_type __cap = __old_cap < __ms / 2 - __alignment ?
__recommend(_VSTD::max(__old_cap + __delta_cap, 2 * __old_cap)) :
__ms - 1;
pointer __p = __alloc_traits::allocate(__alloc(), __cap+1);
__invalidate_all_iterators();
if (__n_copy != 0)
traits_type::copy(_VSTD::__to_raw_pointer(__p),
_VSTD::__to_raw_pointer(__old_p), __n_copy);
size_type __sec_cp_sz = __old_sz - __n_del - __n_copy;
if (__sec_cp_sz != 0)
traits_type::copy(_VSTD::__to_raw_pointer(__p) + __n_copy + __n_add,
_VSTD::__to_raw_pointer(__old_p) + __n_copy + __n_del,
__sec_cp_sz);
if (__old_cap+1 != __min_cap)
__alloc_traits::deallocate(__alloc(), __old_p, __old_cap+1);
__set_long_pointer(__p);
__set_long_cap(__cap+1);
}
// assign
template <class _CharT, class _Traits, class _Allocator>
basic_string<_CharT, _Traits, _Allocator>&
basic_string<_CharT, _Traits, _Allocator>::assign(const value_type* __s, size_type __n)
{
_LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::assign received nullptr");
size_type __cap = capacity();
if (__cap >= __n)
{
value_type* __p = _VSTD::__to_raw_pointer(__get_pointer());
traits_type::move(__p, __s, __n);
traits_type::assign(__p[__n], value_type());
__set_size(__n);
__invalidate_iterators_past(__n);
}
else
{
size_type __sz = size();
__grow_by_and_replace(__cap, __n - __cap, __sz, 0, __sz, __n, __s);
}
return *this;
}
template <class _CharT, class _Traits, class _Allocator>
basic_string<_CharT, _Traits, _Allocator>&
basic_string<_CharT, _Traits, _Allocator>::assign(size_type __n, value_type __c)
{
size_type __cap = capacity();
if (__cap < __n)
{
size_type __sz = size();
__grow_by(__cap, __n - __cap, __sz, 0, __sz);
}
else
__invalidate_iterators_past(__n);
value_type* __p = _VSTD::__to_raw_pointer(__get_pointer());
traits_type::assign(__p, __n, __c);
traits_type::assign(__p[__n], value_type());
__set_size(__n);
return *this;
}
template <class _CharT, class _Traits, class _Allocator>
basic_string<_CharT, _Traits, _Allocator>&
basic_string<_CharT, _Traits, _Allocator>::operator=(value_type __c)
{
pointer __p;
if (__is_long())
{
__p = __get_long_pointer();
__set_long_size(1);
}
else
{
__p = __get_short_pointer();
__set_short_size(1);
}
traits_type::assign(*__p, __c);
traits_type::assign(*++__p, value_type());
__invalidate_iterators_past(1);
return *this;
}
template <class _CharT, class _Traits, class _Allocator>
basic_string<_CharT, _Traits, _Allocator>&
basic_string<_CharT, _Traits, _Allocator>::operator=(const basic_string& __str)
{
if (this != &__str)
{
__copy_assign_alloc(__str);
return assign(__str.data(), __str.size());
}
return *this;
}
#ifndef _LIBCPP_CXX03_LANG
template <class _CharT, class _Traits, class _Allocator>
inline
void
basic_string<_CharT, _Traits, _Allocator>::__move_assign(basic_string& __str, false_type)
_NOEXCEPT_(__alloc_traits::is_always_equal::value)
{
if (__alloc() != __str.__alloc())
assign(__str);
else
__move_assign(__str, true_type());
}
template <class _CharT, class _Traits, class _Allocator>
inline
void
basic_string<_CharT, _Traits, _Allocator>::__move_assign(basic_string& __str, true_type)
#if _LIBCPP_STD_VER > 14
_NOEXCEPT
#else
_NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value)
#endif
{
__clear_and_shrink();
__r_.first() = __str.__r_.first();
__move_assign_alloc(__str);
__str.__zero();
}
template <class _CharT, class _Traits, class _Allocator>
inline
basic_string<_CharT, _Traits, _Allocator>&
basic_string<_CharT, _Traits, _Allocator>::operator=(basic_string&& __str)
_NOEXCEPT_((__noexcept_move_assign_container<_Allocator, __alloc_traits>::value))
{
__move_assign(__str, integral_constant<bool,
__alloc_traits::propagate_on_container_move_assignment::value>());
return *this;
}
#endif
template <class _CharT, class _Traits, class _Allocator>
template<class _InputIterator>
typename enable_if
<
__is_exactly_input_iterator <_InputIterator>::value
|| !__libcpp_string_gets_noexcept_iterator<_InputIterator>::value,
basic_string<_CharT, _Traits, _Allocator>&
>::type
basic_string<_CharT, _Traits, _Allocator>::assign(_InputIterator __first, _InputIterator __last)
{
const basic_string __temp(__first, __last, __alloc());
assign(__temp.data(), __temp.size());
return *this;
}
template <class _CharT, class _Traits, class _Allocator>
template<class _ForwardIterator>
typename enable_if
<
__is_forward_iterator<_ForwardIterator>::value
&& __libcpp_string_gets_noexcept_iterator<_ForwardIterator>::value,
basic_string<_CharT, _Traits, _Allocator>&
>::type
basic_string<_CharT, _Traits, _Allocator>::assign(_ForwardIterator __first, _ForwardIterator __last)
{
size_type __n = static_cast<size_type>(_VSTD::distance(__first, __last));
size_type __cap = capacity();
if (__cap < __n)
{
size_type __sz = size();
__grow_by(__cap, __n - __cap, __sz, 0, __sz);
}
else
__invalidate_iterators_past(__n);
pointer __p = __get_pointer();
for (; __first != __last; ++__first, ++__p)
traits_type::assign(*__p, *__first);
traits_type::assign(*__p, value_type());
__set_size(__n);
return *this;
}
template <class _CharT, class _Traits, class _Allocator>
basic_string<_CharT, _Traits, _Allocator>&
basic_string<_CharT, _Traits, _Allocator>::assign(const basic_string& __str, size_type __pos, size_type __n)
{
size_type __sz = __str.size();
if (__pos > __sz)
this->__throw_out_of_range();
return assign(__str.data() + __pos, _VSTD::min(__n, __sz - __pos));
}
template <class _CharT, class _Traits, class _Allocator>
template <class _Tp>
typename enable_if
<
__can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
basic_string<_CharT, _Traits, _Allocator>&
>::type
basic_string<_CharT, _Traits, _Allocator>::assign(const _Tp & __t, size_type __pos, size_type __n)
{
__self_view __sv = __t;
size_type __sz = __sv.size();
if (__pos > __sz)
this->__throw_out_of_range();
return assign(__sv.data() + __pos, _VSTD::min(__n, __sz - __pos));
}
template <class _CharT, class _Traits, class _Allocator>
basic_string<_CharT, _Traits, _Allocator>&
basic_string<_CharT, _Traits, _Allocator>::assign(const value_type* __s)
{
_LIBCPP_ASSERT(__s != nullptr, "string::assign received nullptr");
return assign(__s, traits_type::length(__s));
}
// append
template <class _CharT, class _Traits, class _Allocator>
basic_string<_CharT, _Traits, _Allocator>&
basic_string<_CharT, _Traits, _Allocator>::append(const value_type* __s, size_type __n)
{
_LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::append received nullptr");
size_type __cap = capacity();
size_type __sz = size();
if (__cap - __sz >= __n)
{
if (__n)
{
value_type* __p = _VSTD::__to_raw_pointer(__get_pointer());
traits_type::copy(__p + __sz, __s, __n);
__sz += __n;
__set_size(__sz);
traits_type::assign(__p[__sz], value_type());
}
}
else
__grow_by_and_replace(__cap, __sz + __n - __cap, __sz, __sz, 0, __n, __s);
return *this;
}
template <class _CharT, class _Traits, class _Allocator>
basic_string<_CharT, _Traits, _Allocator>&
basic_string<_CharT, _Traits, _Allocator>::append(size_type __n, value_type __c)
{
if (__n)
{
size_type __cap = capacity();
size_type __sz = size();
if (__cap - __sz < __n)
__grow_by(__cap, __sz + __n - __cap, __sz, __sz, 0);
pointer __p = __get_pointer();
traits_type::assign(_VSTD::__to_raw_pointer(__p) + __sz, __n, __c);
__sz += __n;
__set_size(__sz);
traits_type::assign(__p[__sz], value_type());
}
return *this;
}
template <class _CharT, class _Traits, class _Allocator>
inline void
basic_string<_CharT, _Traits, _Allocator>::__append_default_init(size_type __n)
{
if (__n)
{
size_type __cap = capacity();
size_type __sz = size();
if (__cap - __sz < __n)
__grow_by(__cap, __sz + __n - __cap, __sz, __sz, 0);
pointer __p = __get_pointer();
__sz += __n;
__set_size(__sz);
traits_type::assign(__p[__sz], value_type());
}
}
template <class _CharT, class _Traits, class _Allocator>
void
basic_string<_CharT, _Traits, _Allocator>::push_back(value_type __c)
{
bool __is_short = !__is_long();
size_type __cap;
size_type __sz;
if (__is_short)
{
__cap = __min_cap - 1;
__sz = __get_short_size();
}
else
{
__cap = __get_long_cap() - 1;
__sz = __get_long_size();
}
if (__sz == __cap)
{
__grow_by(__cap, 1, __sz, __sz, 0);
__is_short = !__is_long();
}
pointer __p;
if (__is_short)
{
__p = __get_short_pointer() + __sz;
__set_short_size(__sz+1);
}
else
{
__p = __get_long_pointer() + __sz;
__set_long_size(__sz+1);
}
traits_type::assign(*__p, __c);
traits_type::assign(*++__p, value_type());
}
template <class _Tp>
bool __ptr_in_range (const _Tp* __p, const _Tp* __first, const _Tp* __last)
{
return __first <= __p && __p < __last;
}
template <class _Tp1, class _Tp2>
bool __ptr_in_range (const _Tp1*, const _Tp2*, const _Tp2*)
{
return false;
}
template <class _CharT, class _Traits, class _Allocator>
template<class _ForwardIterator>
basic_string<_CharT, _Traits, _Allocator>&
basic_string<_CharT, _Traits, _Allocator>::__append_forward_unsafe(
_ForwardIterator __first, _ForwardIterator __last)
{
static_assert(__is_forward_iterator<_ForwardIterator>::value,
"function requires a ForwardIterator");
size_type __sz = size();
size_type __cap = capacity();
size_type __n = static_cast<size_type>(_VSTD::distance(__first, __last));
if (__n)
{
typedef typename iterator_traits<_ForwardIterator>::reference _CharRef;
_CharRef __tmp_ref = *__first;
if (__ptr_in_range(_VSTD::addressof(__tmp_ref), data(), data() + size()))
{
const basic_string __temp (__first, __last, __alloc());
append(__temp.data(), __temp.size());
}
else
{
if (__cap - __sz < __n)
__grow_by(__cap, __sz + __n - __cap, __sz, __sz, 0);
pointer __p = __get_pointer() + __sz;
for (; __first != __last; ++__p, ++__first)
traits_type::assign(*__p, *__first);
traits_type::assign(*__p, value_type());
__set_size(__sz + __n);
}
}
return *this;
}
template <class _CharT, class _Traits, class _Allocator>
inline
basic_string<_CharT, _Traits, _Allocator>&
basic_string<_CharT, _Traits, _Allocator>::append(const basic_string& __str)
{
return append(__str.data(), __str.size());
}
template <class _CharT, class _Traits, class _Allocator>
basic_string<_CharT, _Traits, _Allocator>&
basic_string<_CharT, _Traits, _Allocator>::append(const basic_string& __str, size_type __pos, size_type __n)
{
size_type __sz = __str.size();
if (__pos > __sz)
this->__throw_out_of_range();
return append(__str.data() + __pos, _VSTD::min(__n, __sz - __pos));
}
template <class _CharT, class _Traits, class _Allocator>
template <class _Tp>
typename enable_if
<
__can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
basic_string<_CharT, _Traits, _Allocator>&
>::type
basic_string<_CharT, _Traits, _Allocator>::append(const _Tp & __t, size_type __pos, size_type __n)
{
__self_view __sv = __t;
size_type __sz = __sv.size();
if (__pos > __sz)
this->__throw_out_of_range();
return append(__sv.data() + __pos, _VSTD::min(__n, __sz - __pos));
}
template <class _CharT, class _Traits, class _Allocator>
basic_string<_CharT, _Traits, _Allocator>&
basic_string<_CharT, _Traits, _Allocator>::append(const value_type* __s)
{
_LIBCPP_ASSERT(__s != nullptr, "string::append received nullptr");
return append(__s, traits_type::length(__s));
}
// insert
template <class _CharT, class _Traits, class _Allocator>
basic_string<_CharT, _Traits, _Allocator>&
basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos, const value_type* __s, size_type __n)
{
_LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::insert received nullptr");
size_type __sz = size();
if (__pos > __sz)
this->__throw_out_of_range();
size_type __cap = capacity();
if (__cap - __sz >= __n)
{
if (__n)
{
value_type* __p = _VSTD::__to_raw_pointer(__get_pointer());
size_type __n_move = __sz - __pos;
if (__n_move != 0)
{
if (__p + __pos <= __s && __s < __p + __sz)
__s += __n;
traits_type::move(__p + __pos + __n, __p + __pos, __n_move);
}
traits_type::move(__p + __pos, __s, __n);
__sz += __n;
__set_size(__sz);
traits_type::assign(__p[__sz], value_type());
}
}
else
__grow_by_and_replace(__cap, __sz + __n - __cap, __sz, __pos, 0, __n, __s);
return *this;
}
template <class _CharT, class _Traits, class _Allocator>
basic_string<_CharT, _Traits, _Allocator>&
basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos, size_type __n, value_type __c)
{
size_type __sz = size();
if (__pos > __sz)
this->__throw_out_of_range();
if (__n)
{
size_type __cap = capacity();
value_type* __p;
if (__cap - __sz >= __n)
{
__p = _VSTD::__to_raw_pointer(__get_pointer());
size_type __n_move = __sz - __pos;
if (__n_move != 0)
traits_type::move(__p + __pos + __n, __p + __pos, __n_move);
}
else
{
__grow_by(__cap, __sz + __n - __cap, __sz, __pos, 0, __n);
__p = _VSTD::__to_raw_pointer(__get_long_pointer());
}
traits_type::assign(__p + __pos, __n, __c);
__sz += __n;
__set_size(__sz);
traits_type::assign(__p[__sz], value_type());
}
return *this;
}
template <class _CharT, class _Traits, class _Allocator>
template<class _InputIterator>
typename enable_if
<
__is_exactly_input_iterator<_InputIterator>::value
|| !__libcpp_string_gets_noexcept_iterator<_InputIterator>::value,
typename basic_string<_CharT, _Traits, _Allocator>::iterator
>::type
basic_string<_CharT, _Traits, _Allocator>::insert(const_iterator __pos, _InputIterator __first, _InputIterator __last)
{
#if _LIBCPP_DEBUG_LEVEL >= 2
_LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__pos) == this,
"string::insert(iterator, range) called with an iterator not"
" referring to this string");
#endif
const basic_string __temp(__first, __last, __alloc());
return insert(__pos, __temp.data(), __temp.data() + __temp.size());
}
template <class _CharT, class _Traits, class _Allocator>
template<class _ForwardIterator>
typename enable_if
<
__is_forward_iterator<_ForwardIterator>::value
&& __libcpp_string_gets_noexcept_iterator<_ForwardIterator>::value,
typename basic_string<_CharT, _Traits, _Allocator>::iterator
>::type
basic_string<_CharT, _Traits, _Allocator>::insert(const_iterator __pos, _ForwardIterator __first, _ForwardIterator __last)
{
#if _LIBCPP_DEBUG_LEVEL >= 2
_LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__pos) == this,
"string::insert(iterator, range) called with an iterator not"
" referring to this string");
#endif
size_type __ip = static_cast<size_type>(__pos - begin());
size_type __n = static_cast<size_type>(_VSTD::distance(__first, __last));
if (__n)
{
typedef typename iterator_traits<_ForwardIterator>::reference _CharRef;
_CharRef __tmp_char = *__first;
if (__ptr_in_range(_VSTD::addressof(__tmp_char), data(), data() + size()))
{
const basic_string __temp(__first, __last, __alloc());
return insert(__pos, __temp.data(), __temp.data() + __temp.size());
}
size_type __sz = size();
size_type __cap = capacity();
value_type* __p;
if (__cap - __sz >= __n)
{
__p = _VSTD::__to_raw_pointer(__get_pointer());
size_type __n_move = __sz - __ip;
if (__n_move != 0)
traits_type::move(__p + __ip + __n, __p + __ip, __n_move);
}
else
{
__grow_by(__cap, __sz + __n - __cap, __sz, __ip, 0, __n);
__p = _VSTD::__to_raw_pointer(__get_long_pointer());
}
__sz += __n;
__set_size(__sz);
traits_type::assign(__p[__sz], value_type());
for (__p += __ip; __first != __last; ++__p, ++__first)
traits_type::assign(*__p, *__first);
}
return begin() + __ip;
}
template <class _CharT, class _Traits, class _Allocator>
inline
basic_string<_CharT, _Traits, _Allocator>&
basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos1, const basic_string& __str)
{
return insert(__pos1, __str.data(), __str.size());
}
template <class _CharT, class _Traits, class _Allocator>
basic_string<_CharT, _Traits, _Allocator>&
basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos1, const basic_string& __str,
size_type __pos2, size_type __n)
{
size_type __str_sz = __str.size();
if (__pos2 > __str_sz)
this->__throw_out_of_range();
return insert(__pos1, __str.data() + __pos2, _VSTD::min(__n, __str_sz - __pos2));
}
template <class _CharT, class _Traits, class _Allocator>
template <class _Tp>
typename enable_if
<
__can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
basic_string<_CharT, _Traits, _Allocator>&
>::type
basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos1, const _Tp& __t,
size_type __pos2, size_type __n)
{
__self_view __sv = __t;
size_type __str_sz = __sv.size();
if (__pos2 > __str_sz)
this->__throw_out_of_range();
return insert(__pos1, __sv.data() + __pos2, _VSTD::min(__n, __str_sz - __pos2));
}
template <class _CharT, class _Traits, class _Allocator>
basic_string<_CharT, _Traits, _Allocator>&
basic_string<_CharT, _Traits, _Allocator>::insert(size_type __pos, const value_type* __s)
{
_LIBCPP_ASSERT(__s != nullptr, "string::insert received nullptr");
return insert(__pos, __s, traits_type::length(__s));
}
template <class _CharT, class _Traits, class _Allocator>
typename basic_string<_CharT, _Traits, _Allocator>::iterator
basic_string<_CharT, _Traits, _Allocator>::insert(const_iterator __pos, value_type __c)
{
size_type __ip = static_cast<size_type>(__pos - begin());
size_type __sz = size();
size_type __cap = capacity();
value_type* __p;
if (__cap == __sz)
{
__grow_by(__cap, 1, __sz, __ip, 0, 1);
__p = _VSTD::__to_raw_pointer(__get_long_pointer());
}
else
{
__p = _VSTD::__to_raw_pointer(__get_pointer());
size_type __n_move = __sz - __ip;
if (__n_move != 0)
traits_type::move(__p + __ip + 1, __p + __ip, __n_move);
}
traits_type::assign(__p[__ip], __c);
traits_type::assign(__p[++__sz], value_type());
__set_size(__sz);
return begin() + static_cast<difference_type>(__ip);
}
template <class _CharT, class _Traits, class _Allocator>
inline
typename basic_string<_CharT, _Traits, _Allocator>::iterator
basic_string<_CharT, _Traits, _Allocator>::insert(const_iterator __pos, size_type __n, value_type __c)
{
#if _LIBCPP_DEBUG_LEVEL >= 2
_LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__pos) == this,
"string::insert(iterator, n, value) called with an iterator not"
" referring to this string");
#endif
difference_type __p = __pos - begin();
insert(static_cast<size_type>(__p), __n, __c);
return begin() + __p;
}
// replace
template <class _CharT, class _Traits, class _Allocator>
basic_string<_CharT, _Traits, _Allocator>&
basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos, size_type __n1, const value_type* __s, size_type __n2)
_LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK
{
_LIBCPP_ASSERT(__n2 == 0 || __s != nullptr, "string::replace received nullptr");
size_type __sz = size();
if (__pos > __sz)
this->__throw_out_of_range();
__n1 = _VSTD::min(__n1, __sz - __pos);
size_type __cap = capacity();
if (__cap - __sz + __n1 >= __n2)
{
value_type* __p = _VSTD::__to_raw_pointer(__get_pointer());
if (__n1 != __n2)
{
size_type __n_move = __sz - __pos - __n1;
if (__n_move != 0)
{
if (__n1 > __n2)
{
traits_type::move(__p + __pos, __s, __n2);
traits_type::move(__p + __pos + __n2, __p + __pos + __n1, __n_move);
goto __finish;
}
if (__p + __pos < __s && __s < __p + __sz)
{
if (__p + __pos + __n1 <= __s)
__s += __n2 - __n1;
else // __p + __pos < __s < __p + __pos + __n1
{
traits_type::move(__p + __pos, __s, __n1);
__pos += __n1;
__s += __n2;
__n2 -= __n1;
__n1 = 0;
}
}
traits_type::move(__p + __pos + __n2, __p + __pos + __n1, __n_move);
}
}
traits_type::move(__p + __pos, __s, __n2);
__finish:
// __sz += __n2 - __n1; in this and the below function below can cause unsigned integer overflow,
// but this is a safe operation, so we disable the check.
__sz += __n2 - __n1;
__set_size(__sz);
__invalidate_iterators_past(__sz);
traits_type::assign(__p[__sz], value_type());
}
else
__grow_by_and_replace(__cap, __sz - __n1 + __n2 - __cap, __sz, __pos, __n1, __n2, __s);
return *this;
}
template <class _CharT, class _Traits, class _Allocator>
basic_string<_CharT, _Traits, _Allocator>&
basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos, size_type __n1, size_type __n2, value_type __c)
_LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK
{
size_type __sz = size();
if (__pos > __sz)
this->__throw_out_of_range();
__n1 = _VSTD::min(__n1, __sz - __pos);
size_type __cap = capacity();
value_type* __p;
if (__cap - __sz + __n1 >= __n2)
{
__p = _VSTD::__to_raw_pointer(__get_pointer());
if (__n1 != __n2)
{
size_type __n_move = __sz - __pos - __n1;
if (__n_move != 0)
traits_type::move(__p + __pos + __n2, __p + __pos + __n1, __n_move);
}
}
else
{
__grow_by(__cap, __sz - __n1 + __n2 - __cap, __sz, __pos, __n1, __n2);
__p = _VSTD::__to_raw_pointer(__get_long_pointer());
}
traits_type::assign(__p + __pos, __n2, __c);
__sz += __n2 - __n1;
__set_size(__sz);
__invalidate_iterators_past(__sz);
traits_type::assign(__p[__sz], value_type());
return *this;
}
template <class _CharT, class _Traits, class _Allocator>
template<class _InputIterator>
typename enable_if
<
__is_input_iterator<_InputIterator>::value,
basic_string<_CharT, _Traits, _Allocator>&
>::type
basic_string<_CharT, _Traits, _Allocator>::replace(const_iterator __i1, const_iterator __i2,
_InputIterator __j1, _InputIterator __j2)
{
const basic_string __temp(__j1, __j2, __alloc());
return this->replace(__i1, __i2, __temp);
}
template <class _CharT, class _Traits, class _Allocator>
inline
basic_string<_CharT, _Traits, _Allocator>&
basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos1, size_type __n1, const basic_string& __str)
{
return replace(__pos1, __n1, __str.data(), __str.size());
}
template <class _CharT, class _Traits, class _Allocator>
basic_string<_CharT, _Traits, _Allocator>&
basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos1, size_type __n1, const basic_string& __str,
size_type __pos2, size_type __n2)
{
size_type __str_sz = __str.size();
if (__pos2 > __str_sz)
this->__throw_out_of_range();
return replace(__pos1, __n1, __str.data() + __pos2, _VSTD::min(__n2, __str_sz - __pos2));
}
template <class _CharT, class _Traits, class _Allocator>
template <class _Tp>
typename enable_if
<
__can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
basic_string<_CharT, _Traits, _Allocator>&
>::type
basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos1, size_type __n1, const _Tp& __t,
size_type __pos2, size_type __n2)
{
__self_view __sv = __t;
size_type __str_sz = __sv.size();
if (__pos2 > __str_sz)
this->__throw_out_of_range();
return replace(__pos1, __n1, __sv.data() + __pos2, _VSTD::min(__n2, __str_sz - __pos2));
}
template <class _CharT, class _Traits, class _Allocator>
basic_string<_CharT, _Traits, _Allocator>&
basic_string<_CharT, _Traits, _Allocator>::replace(size_type __pos, size_type __n1, const value_type* __s)
{
_LIBCPP_ASSERT(__s != nullptr, "string::replace received nullptr");
return replace(__pos, __n1, __s, traits_type::length(__s));
}
template <class _CharT, class _Traits, class _Allocator>
inline
basic_string<_CharT, _Traits, _Allocator>&
basic_string<_CharT, _Traits, _Allocator>::replace(const_iterator __i1, const_iterator __i2, const basic_string& __str)
{
return replace(static_cast<size_type>(__i1 - begin()), static_cast<size_type>(__i2 - __i1),
__str.data(), __str.size());
}
template <class _CharT, class _Traits, class _Allocator>
inline
basic_string<_CharT, _Traits, _Allocator>&
basic_string<_CharT, _Traits, _Allocator>::replace(const_iterator __i1, const_iterator __i2, const value_type* __s, size_type __n)
{
return replace(static_cast<size_type>(__i1 - begin()), static_cast<size_type>(__i2 - __i1), __s, __n);
}
template <class _CharT, class _Traits, class _Allocator>
inline
basic_string<_CharT, _Traits, _Allocator>&
basic_string<_CharT, _Traits, _Allocator>::replace(const_iterator __i1, const_iterator __i2, const value_type* __s)
{
return replace(static_cast<size_type>(__i1 - begin()), static_cast<size_type>(__i2 - __i1), __s);
}
template <class _CharT, class _Traits, class _Allocator>
inline
basic_string<_CharT, _Traits, _Allocator>&
basic_string<_CharT, _Traits, _Allocator>::replace(const_iterator __i1, const_iterator __i2, size_type __n, value_type __c)
{
return replace(static_cast<size_type>(__i1 - begin()), static_cast<size_type>(__i2 - __i1), __n, __c);
}
// erase
template <class _CharT, class _Traits, class _Allocator>
basic_string<_CharT, _Traits, _Allocator>&
basic_string<_CharT, _Traits, _Allocator>::erase(size_type __pos, size_type __n)
{
size_type __sz = size();
if (__pos > __sz)
this->__throw_out_of_range();
if (__n)
{
value_type* __p = _VSTD::__to_raw_pointer(__get_pointer());
__n = _VSTD::min(__n, __sz - __pos);
size_type __n_move = __sz - __pos - __n;
if (__n_move != 0)
traits_type::move(__p + __pos, __p + __pos + __n, __n_move);
__sz -= __n;
__set_size(__sz);
__invalidate_iterators_past(__sz);
traits_type::assign(__p[__sz], value_type());
}
return *this;
}
template <class _CharT, class _Traits, class _Allocator>
inline
typename basic_string<_CharT, _Traits, _Allocator>::iterator
basic_string<_CharT, _Traits, _Allocator>::erase(const_iterator __pos)
{
#if _LIBCPP_DEBUG_LEVEL >= 2
_LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__pos) == this,
"string::erase(iterator) called with an iterator not"
" referring to this string");
#endif
_LIBCPP_ASSERT(__pos != end(),
"string::erase(iterator) called with a non-dereferenceable iterator");
iterator __b = begin();
size_type __r = static_cast<size_type>(__pos - __b);
erase(__r, 1);
return __b + static_cast<difference_type>(__r);
}
template <class _CharT, class _Traits, class _Allocator>
inline
typename basic_string<_CharT, _Traits, _Allocator>::iterator
basic_string<_CharT, _Traits, _Allocator>::erase(const_iterator __first, const_iterator __last)
{
#if _LIBCPP_DEBUG_LEVEL >= 2
_LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__first) == this,
"string::erase(iterator, iterator) called with an iterator not"
" referring to this string");
#endif
_LIBCPP_ASSERT(__first <= __last, "string::erase(first, last) called with invalid range");
iterator __b = begin();
size_type __r = static_cast<size_type>(__first - __b);
erase(__r, static_cast<size_type>(__last - __first));
return __b + static_cast<difference_type>(__r);
}
template <class _CharT, class _Traits, class _Allocator>
inline
void
basic_string<_CharT, _Traits, _Allocator>::pop_back()
{
_LIBCPP_ASSERT(!empty(), "string::pop_back(): string is already empty");
size_type __sz;
if (__is_long())
{
__sz = __get_long_size() - 1;
__set_long_size(__sz);
traits_type::assign(*(__get_long_pointer() + __sz), value_type());
}
else
{
__sz = __get_short_size() - 1;
__set_short_size(__sz);
traits_type::assign(*(__get_short_pointer() + __sz), value_type());
}
__invalidate_iterators_past(__sz);
}
template <class _CharT, class _Traits, class _Allocator>
inline
void
basic_string<_CharT, _Traits, _Allocator>::clear() _NOEXCEPT
{
__invalidate_all_iterators();
if (__is_long())
{
traits_type::assign(*__get_long_pointer(), value_type());
__set_long_size(0);
}
else
{
traits_type::assign(*__get_short_pointer(), value_type());
__set_short_size(0);
}
}
template <class _CharT, class _Traits, class _Allocator>
inline
void
basic_string<_CharT, _Traits, _Allocator>::__erase_to_end(size_type __pos)
{
if (__is_long())
{
traits_type::assign(*(__get_long_pointer() + __pos), value_type());
__set_long_size(__pos);
}
else
{
traits_type::assign(*(__get_short_pointer() + __pos), value_type());
__set_short_size(__pos);
}
__invalidate_iterators_past(__pos);
}
template <class _CharT, class _Traits, class _Allocator>
void
basic_string<_CharT, _Traits, _Allocator>::resize(size_type __n, value_type __c)
{
size_type __sz = size();
if (__n > __sz)
append(__n - __sz, __c);
else
__erase_to_end(__n);
}
template <class _CharT, class _Traits, class _Allocator>
inline void
basic_string<_CharT, _Traits, _Allocator>::__resize_default_init(size_type __n)
{
size_type __sz = size();
if (__n > __sz) {
__append_default_init(__n - __sz);
} else
__erase_to_end(__n);
}
template <class _CharT, class _Traits, class _Allocator>
inline
typename basic_string<_CharT, _Traits, _Allocator>::size_type
basic_string<_CharT, _Traits, _Allocator>::max_size() const _NOEXCEPT
{
size_type __m = __alloc_traits::max_size(__alloc());
#ifdef _LIBCPP_BIG_ENDIAN
return (__m <= ~__long_mask ? __m : __m/2) - __alignment;
#else
return __m - __alignment;
#endif
}
template <class _CharT, class _Traits, class _Allocator>
void
basic_string<_CharT, _Traits, _Allocator>::reserve(size_type __res_arg)
{
if (__res_arg > max_size())
this->__throw_length_error();
size_type __cap = capacity();
size_type __sz = size();
__res_arg = _VSTD::max(__res_arg, __sz);
__res_arg = __recommend(__res_arg);
if (__res_arg != __cap)
{
pointer __new_data, __p;
bool __was_long, __now_long;
if (__res_arg == __min_cap - 1)
{
__was_long = true;
__now_long = false;
__new_data = __get_short_pointer();
__p = __get_long_pointer();
}
else
{
if (__res_arg > __cap)
__new_data = __alloc_traits::allocate(__alloc(), __res_arg+1);
else
{
#ifndef _LIBCPP_NO_EXCEPTIONS
try
{
#endif // _LIBCPP_NO_EXCEPTIONS
__new_data = __alloc_traits::allocate(__alloc(), __res_arg+1);
#ifndef _LIBCPP_NO_EXCEPTIONS
}
catch (...)
{
return;
}
#else // _LIBCPP_NO_EXCEPTIONS
if (__new_data == nullptr)
return;
#endif // _LIBCPP_NO_EXCEPTIONS
}
__now_long = true;
__was_long = __is_long();
__p = __get_pointer();
}
traits_type::copy(_VSTD::__to_raw_pointer(__new_data),
_VSTD::__to_raw_pointer(__p), size()+1);
if (__was_long)
__alloc_traits::deallocate(__alloc(), __p, __cap+1);
if (__now_long)
{
__set_long_cap(__res_arg+1);
__set_long_size(__sz);
__set_long_pointer(__new_data);
}
else
__set_short_size(__sz);
__invalidate_all_iterators();
}
}
template <class _CharT, class _Traits, class _Allocator>
inline
typename basic_string<_CharT, _Traits, _Allocator>::const_reference
basic_string<_CharT, _Traits, _Allocator>::operator[](size_type __pos) const _NOEXCEPT
{
_LIBCPP_ASSERT(__pos <= size(), "string index out of bounds");
return *(data() + __pos);
}
template <class _CharT, class _Traits, class _Allocator>
inline
typename basic_string<_CharT, _Traits, _Allocator>::reference
basic_string<_CharT, _Traits, _Allocator>::operator[](size_type __pos) _NOEXCEPT
{
_LIBCPP_ASSERT(__pos <= size(), "string index out of bounds");
return *(__get_pointer() + __pos);
}
template <class _CharT, class _Traits, class _Allocator>
typename basic_string<_CharT, _Traits, _Allocator>::const_reference
basic_string<_CharT, _Traits, _Allocator>::at(size_type __n) const
{
if (__n >= size())
this->__throw_out_of_range();
return (*this)[__n];
}
template <class _CharT, class _Traits, class _Allocator>
typename basic_string<_CharT, _Traits, _Allocator>::reference
basic_string<_CharT, _Traits, _Allocator>::at(size_type __n)
{
if (__n >= size())
this->__throw_out_of_range();
return (*this)[__n];
}
template <class _CharT, class _Traits, class _Allocator>
inline
typename basic_string<_CharT, _Traits, _Allocator>::reference
basic_string<_CharT, _Traits, _Allocator>::front() _NOEXCEPT
{
_LIBCPP_ASSERT(!empty(), "string::front(): string is empty");
return *__get_pointer();
}
template <class _CharT, class _Traits, class _Allocator>
inline
typename basic_string<_CharT, _Traits, _Allocator>::const_reference
basic_string<_CharT, _Traits, _Allocator>::front() const _NOEXCEPT
{
_LIBCPP_ASSERT(!empty(), "string::front(): string is empty");
return *data();
}
template <class _CharT, class _Traits, class _Allocator>
inline
typename basic_string<_CharT, _Traits, _Allocator>::reference
basic_string<_CharT, _Traits, _Allocator>::back() _NOEXCEPT
{
_LIBCPP_ASSERT(!empty(), "string::back(): string is empty");
return *(__get_pointer() + size() - 1);
}
template <class _CharT, class _Traits, class _Allocator>
inline
typename basic_string<_CharT, _Traits, _Allocator>::const_reference
basic_string<_CharT, _Traits, _Allocator>::back() const _NOEXCEPT
{
_LIBCPP_ASSERT(!empty(), "string::back(): string is empty");
return *(data() + size() - 1);
}
template <class _CharT, class _Traits, class _Allocator>
typename basic_string<_CharT, _Traits, _Allocator>::size_type
basic_string<_CharT, _Traits, _Allocator>::copy(value_type* __s, size_type __n, size_type __pos) const
{
size_type __sz = size();
if (__pos > __sz)
this->__throw_out_of_range();
size_type __rlen = _VSTD::min(__n, __sz - __pos);
traits_type::copy(__s, data() + __pos, __rlen);
return __rlen;
}
template <class _CharT, class _Traits, class _Allocator>
inline
basic_string<_CharT, _Traits, _Allocator>
basic_string<_CharT, _Traits, _Allocator>::substr(size_type __pos, size_type __n) const
{
return basic_string(*this, __pos, __n, __alloc());
}
template <class _CharT, class _Traits, class _Allocator>
inline
void
basic_string<_CharT, _Traits, _Allocator>::swap(basic_string& __str)
#if _LIBCPP_STD_VER >= 14
_NOEXCEPT
#else
_NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value ||
__is_nothrow_swappable<allocator_type>::value)
#endif
{
#if _LIBCPP_DEBUG_LEVEL >= 2
if (!__is_long())
__get_db()->__invalidate_all(this);
if (!__str.__is_long())
__get_db()->__invalidate_all(&__str);
__get_db()->swap(this, &__str);
#endif
_LIBCPP_ASSERT(
__alloc_traits::propagate_on_container_swap::value ||
__alloc_traits::is_always_equal::value ||
__alloc() == __str.__alloc(), "swapping non-equal allocators");
_VSTD::swap(__r_.first(), __str.__r_.first());
__swap_allocator(__alloc(), __str.__alloc());
}
// find
template <class _Traits>
struct _LIBCPP_HIDDEN __traits_eq
{
typedef typename _Traits::char_type char_type;
_LIBCPP_INLINE_VISIBILITY
bool operator()(const char_type& __x, const char_type& __y) _NOEXCEPT
{return _Traits::eq(__x, __y);}
};
template<class _CharT, class _Traits, class _Allocator>
typename basic_string<_CharT, _Traits, _Allocator>::size_type
basic_string<_CharT, _Traits, _Allocator>::find(const value_type* __s,
size_type __pos,
size_type __n) const _NOEXCEPT
{
_LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::find(): received nullptr");
return __str_find<value_type, size_type, traits_type, npos>
(data(), size(), __s, __pos, __n);
}
template<class _CharT, class _Traits, class _Allocator>
inline
typename basic_string<_CharT, _Traits, _Allocator>::size_type
basic_string<_CharT, _Traits, _Allocator>::find(const basic_string& __str,
size_type __pos) const _NOEXCEPT
{
return __str_find<value_type, size_type, traits_type, npos>
(data(), size(), __str.data(), __pos, __str.size());
}
template<class _CharT, class _Traits, class _Allocator>
template <class _Tp>
typename enable_if
<
__can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
typename basic_string<_CharT, _Traits, _Allocator>::size_type
>::type
basic_string<_CharT, _Traits, _Allocator>::find(const _Tp &__t,
size_type __pos) const
{
__self_view __sv = __t;
return __str_find<value_type, size_type, traits_type, npos>
(data(), size(), __sv.data(), __pos, __sv.size());
}
template<class _CharT, class _Traits, class _Allocator>
inline
typename basic_string<_CharT, _Traits, _Allocator>::size_type
basic_string<_CharT, _Traits, _Allocator>::find(const value_type* __s,
size_type __pos) const _NOEXCEPT
{
_LIBCPP_ASSERT(__s != nullptr, "string::find(): received nullptr");
return __str_find<value_type, size_type, traits_type, npos>
(data(), size(), __s, __pos, traits_type::length(__s));
}
template<class _CharT, class _Traits, class _Allocator>
typename basic_string<_CharT, _Traits, _Allocator>::size_type
basic_string<_CharT, _Traits, _Allocator>::find(value_type __c,
size_type __pos) const _NOEXCEPT
{
return __str_find<value_type, size_type, traits_type, npos>
(data(), size(), __c, __pos);
}
// rfind
template<class _CharT, class _Traits, class _Allocator>
typename basic_string<_CharT, _Traits, _Allocator>::size_type
basic_string<_CharT, _Traits, _Allocator>::rfind(const value_type* __s,
size_type __pos,
size_type __n) const _NOEXCEPT
{
_LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::rfind(): received nullptr");
return __str_rfind<value_type, size_type, traits_type, npos>
(data(), size(), __s, __pos, __n);
}
template<class _CharT, class _Traits, class _Allocator>
inline
typename basic_string<_CharT, _Traits, _Allocator>::size_type
basic_string<_CharT, _Traits, _Allocator>::rfind(const basic_string& __str,
size_type __pos) const _NOEXCEPT
{
return __str_rfind<value_type, size_type, traits_type, npos>
(data(), size(), __str.data(), __pos, __str.size());
}
template<class _CharT, class _Traits, class _Allocator>
template <class _Tp>
typename enable_if
<
__can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
typename basic_string<_CharT, _Traits, _Allocator>::size_type
>::type
basic_string<_CharT, _Traits, _Allocator>::rfind(const _Tp& __t,
size_type __pos) const
{
__self_view __sv = __t;
return __str_rfind<value_type, size_type, traits_type, npos>
(data(), size(), __sv.data(), __pos, __sv.size());
}
template<class _CharT, class _Traits, class _Allocator>
inline
typename basic_string<_CharT, _Traits, _Allocator>::size_type
basic_string<_CharT, _Traits, _Allocator>::rfind(const value_type* __s,
size_type __pos) const _NOEXCEPT
{
_LIBCPP_ASSERT(__s != nullptr, "string::rfind(): received nullptr");
return __str_rfind<value_type, size_type, traits_type, npos>
(data(), size(), __s, __pos, traits_type::length(__s));
}
template<class _CharT, class _Traits, class _Allocator>
typename basic_string<_CharT, _Traits, _Allocator>::size_type
basic_string<_CharT, _Traits, _Allocator>::rfind(value_type __c,
size_type __pos) const _NOEXCEPT
{
return __str_rfind<value_type, size_type, traits_type, npos>
(data(), size(), __c, __pos);
}
// find_first_of
template<class _CharT, class _Traits, class _Allocator>
typename basic_string<_CharT, _Traits, _Allocator>::size_type
basic_string<_CharT, _Traits, _Allocator>::find_first_of(const value_type* __s,
size_type __pos,
size_type __n) const _NOEXCEPT
{
_LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::find_first_of(): received nullptr");
return __str_find_first_of<value_type, size_type, traits_type, npos>
(data(), size(), __s, __pos, __n);
}
template<class _CharT, class _Traits, class _Allocator>
inline
typename basic_string<_CharT, _Traits, _Allocator>::size_type
basic_string<_CharT, _Traits, _Allocator>::find_first_of(const basic_string& __str,
size_type __pos) const _NOEXCEPT
{
return __str_find_first_of<value_type, size_type, traits_type, npos>
(data(), size(), __str.data(), __pos, __str.size());
}
template<class _CharT, class _Traits, class _Allocator>
template <class _Tp>
typename enable_if
<
__can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
typename basic_string<_CharT, _Traits, _Allocator>::size_type
>::type
basic_string<_CharT, _Traits, _Allocator>::find_first_of(const _Tp& __t,
size_type __pos) const
{
__self_view __sv = __t;
return __str_find_first_of<value_type, size_type, traits_type, npos>
(data(), size(), __sv.data(), __pos, __sv.size());
}
template<class _CharT, class _Traits, class _Allocator>
inline
typename basic_string<_CharT, _Traits, _Allocator>::size_type
basic_string<_CharT, _Traits, _Allocator>::find_first_of(const value_type* __s,
size_type __pos) const _NOEXCEPT
{
_LIBCPP_ASSERT(__s != nullptr, "string::find_first_of(): received nullptr");
return __str_find_first_of<value_type, size_type, traits_type, npos>
(data(), size(), __s, __pos, traits_type::length(__s));
}
template<class _CharT, class _Traits, class _Allocator>
inline
typename basic_string<_CharT, _Traits, _Allocator>::size_type
basic_string<_CharT, _Traits, _Allocator>::find_first_of(value_type __c,
size_type __pos) const _NOEXCEPT
{
return find(__c, __pos);
}
// find_last_of
template<class _CharT, class _Traits, class _Allocator>
typename basic_string<_CharT, _Traits, _Allocator>::size_type
basic_string<_CharT, _Traits, _Allocator>::find_last_of(const value_type* __s,
size_type __pos,
size_type __n) const _NOEXCEPT
{
_LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::find_last_of(): received nullptr");
return __str_find_last_of<value_type, size_type, traits_type, npos>
(data(), size(), __s, __pos, __n);
}
template<class _CharT, class _Traits, class _Allocator>
inline
typename basic_string<_CharT, _Traits, _Allocator>::size_type
basic_string<_CharT, _Traits, _Allocator>::find_last_of(const basic_string& __str,
size_type __pos) const _NOEXCEPT
{
return __str_find_last_of<value_type, size_type, traits_type, npos>
(data(), size(), __str.data(), __pos, __str.size());
}
template<class _CharT, class _Traits, class _Allocator>
template <class _Tp>
typename enable_if
<
__can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
typename basic_string<_CharT, _Traits, _Allocator>::size_type
>::type
basic_string<_CharT, _Traits, _Allocator>::find_last_of(const _Tp& __t,
size_type __pos) const
{
__self_view __sv = __t;
return __str_find_last_of<value_type, size_type, traits_type, npos>
(data(), size(), __sv.data(), __pos, __sv.size());
}
template<class _CharT, class _Traits, class _Allocator>
inline
typename basic_string<_CharT, _Traits, _Allocator>::size_type
basic_string<_CharT, _Traits, _Allocator>::find_last_of(const value_type* __s,
size_type __pos) const _NOEXCEPT
{
_LIBCPP_ASSERT(__s != nullptr, "string::find_last_of(): received nullptr");
return __str_find_last_of<value_type, size_type, traits_type, npos>
(data(), size(), __s, __pos, traits_type::length(__s));
}
template<class _CharT, class _Traits, class _Allocator>
inline
typename basic_string<_CharT, _Traits, _Allocator>::size_type
basic_string<_CharT, _Traits, _Allocator>::find_last_of(value_type __c,
size_type __pos) const _NOEXCEPT
{
return rfind(__c, __pos);
}
// find_first_not_of
template<class _CharT, class _Traits, class _Allocator>
typename basic_string<_CharT, _Traits, _Allocator>::size_type
basic_string<_CharT, _Traits, _Allocator>::find_first_not_of(const value_type* __s,
size_type __pos,
size_type __n) const _NOEXCEPT
{
_LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::find_first_not_of(): received nullptr");
return __str_find_first_not_of<value_type, size_type, traits_type, npos>
(data(), size(), __s, __pos, __n);
}
template<class _CharT, class _Traits, class _Allocator>
inline
typename basic_string<_CharT, _Traits, _Allocator>::size_type
basic_string<_CharT, _Traits, _Allocator>::find_first_not_of(const basic_string& __str,
size_type __pos) const _NOEXCEPT
{
return __str_find_first_not_of<value_type, size_type, traits_type, npos>
(data(), size(), __str.data(), __pos, __str.size());
}
template<class _CharT, class _Traits, class _Allocator>
template <class _Tp>
typename enable_if
<
__can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
typename basic_string<_CharT, _Traits, _Allocator>::size_type
>::type
basic_string<_CharT, _Traits, _Allocator>::find_first_not_of(const _Tp& __t,
size_type __pos) const
{
__self_view __sv = __t;
return __str_find_first_not_of<value_type, size_type, traits_type, npos>
(data(), size(), __sv.data(), __pos, __sv.size());
}
template<class _CharT, class _Traits, class _Allocator>
inline
typename basic_string<_CharT, _Traits, _Allocator>::size_type
basic_string<_CharT, _Traits, _Allocator>::find_first_not_of(const value_type* __s,
size_type __pos) const _NOEXCEPT
{
_LIBCPP_ASSERT(__s != nullptr, "string::find_first_not_of(): received nullptr");
return __str_find_first_not_of<value_type, size_type, traits_type, npos>
(data(), size(), __s, __pos, traits_type::length(__s));
}
template<class _CharT, class _Traits, class _Allocator>
inline
typename basic_string<_CharT, _Traits, _Allocator>::size_type
basic_string<_CharT, _Traits, _Allocator>::find_first_not_of(value_type __c,
size_type __pos) const _NOEXCEPT
{
return __str_find_first_not_of<value_type, size_type, traits_type, npos>
(data(), size(), __c, __pos);
}
// find_last_not_of
template<class _CharT, class _Traits, class _Allocator>
typename basic_string<_CharT, _Traits, _Allocator>::size_type
basic_string<_CharT, _Traits, _Allocator>::find_last_not_of(const value_type* __s,
size_type __pos,
size_type __n) const _NOEXCEPT
{
_LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string::find_last_not_of(): received nullptr");
return __str_find_last_not_of<value_type, size_type, traits_type, npos>
(data(), size(), __s, __pos, __n);
}
template<class _CharT, class _Traits, class _Allocator>
inline
typename basic_string<_CharT, _Traits, _Allocator>::size_type
basic_string<_CharT, _Traits, _Allocator>::find_last_not_of(const basic_string& __str,
size_type __pos) const _NOEXCEPT
{
return __str_find_last_not_of<value_type, size_type, traits_type, npos>
(data(), size(), __str.data(), __pos, __str.size());
}
template<class _CharT, class _Traits, class _Allocator>
template <class _Tp>
typename enable_if
<
__can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
typename basic_string<_CharT, _Traits, _Allocator>::size_type
>::type
basic_string<_CharT, _Traits, _Allocator>::find_last_not_of(const _Tp& __t,
size_type __pos) const
{
__self_view __sv = __t;
return __str_find_last_not_of<value_type, size_type, traits_type, npos>
(data(), size(), __sv.data(), __pos, __sv.size());
}
template<class _CharT, class _Traits, class _Allocator>
inline
typename basic_string<_CharT, _Traits, _Allocator>::size_type
basic_string<_CharT, _Traits, _Allocator>::find_last_not_of(const value_type* __s,
size_type __pos) const _NOEXCEPT
{
_LIBCPP_ASSERT(__s != nullptr, "string::find_last_not_of(): received nullptr");
return __str_find_last_not_of<value_type, size_type, traits_type, npos>
(data(), size(), __s, __pos, traits_type::length(__s));
}
template<class _CharT, class _Traits, class _Allocator>
inline
typename basic_string<_CharT, _Traits, _Allocator>::size_type
basic_string<_CharT, _Traits, _Allocator>::find_last_not_of(value_type __c,
size_type __pos) const _NOEXCEPT
{
return __str_find_last_not_of<value_type, size_type, traits_type, npos>
(data(), size(), __c, __pos);
}
// compare
template <class _CharT, class _Traits, class _Allocator>
template <class _Tp>
typename enable_if
<
__can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
int
>::type
basic_string<_CharT, _Traits, _Allocator>::compare(const _Tp& __t) const
{
__self_view __sv = __t;
size_t __lhs_sz = size();
size_t __rhs_sz = __sv.size();
int __result = traits_type::compare(data(), __sv.data(),
_VSTD::min(__lhs_sz, __rhs_sz));
if (__result != 0)
return __result;
if (__lhs_sz < __rhs_sz)
return -1;
if (__lhs_sz > __rhs_sz)
return 1;
return 0;
}
template <class _CharT, class _Traits, class _Allocator>
inline
int
basic_string<_CharT, _Traits, _Allocator>::compare(const basic_string& __str) const _NOEXCEPT
{
return compare(__self_view(__str));
}
template <class _CharT, class _Traits, class _Allocator>
int
basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1,
size_type __n1,
const value_type* __s,
size_type __n2) const
{
_LIBCPP_ASSERT(__n2 == 0 || __s != nullptr, "string::compare(): received nullptr");
size_type __sz = size();
if (__pos1 > __sz || __n2 == npos)
this->__throw_out_of_range();
size_type __rlen = _VSTD::min(__n1, __sz - __pos1);
int __r = traits_type::compare(data() + __pos1, __s, _VSTD::min(__rlen, __n2));
if (__r == 0)
{
if (__rlen < __n2)
__r = -1;
else if (__rlen > __n2)
__r = 1;
}
return __r;
}
template <class _CharT, class _Traits, class _Allocator>
template <class _Tp>
typename enable_if
<
__can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
int
>::type
basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1,
size_type __n1,
const _Tp& __t) const
{
__self_view __sv = __t;
return compare(__pos1, __n1, __sv.data(), __sv.size());
}
template <class _CharT, class _Traits, class _Allocator>
inline
int
basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1,
size_type __n1,
const basic_string& __str) const
{
return compare(__pos1, __n1, __str.data(), __str.size());
}
template <class _CharT, class _Traits, class _Allocator>
template <class _Tp>
typename enable_if
<
__can_be_converted_to_string_view<_CharT, _Traits, _Tp>::value,
int
>::type
basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1,
size_type __n1,
const _Tp& __t,
size_type __pos2,
size_type __n2) const
{
__self_view __sv = __t;
return __self_view(*this).substr(__pos1, __n1).compare(__sv.substr(__pos2, __n2));
}
template <class _CharT, class _Traits, class _Allocator>
int
basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1,
size_type __n1,
const basic_string& __str,
size_type __pos2,
size_type __n2) const
{
return compare(__pos1, __n1, __self_view(__str), __pos2, __n2);
}
template <class _CharT, class _Traits, class _Allocator>
int
basic_string<_CharT, _Traits, _Allocator>::compare(const value_type* __s) const _NOEXCEPT
{
_LIBCPP_ASSERT(__s != nullptr, "string::compare(): received nullptr");
return compare(0, npos, __s, traits_type::length(__s));
}
template <class _CharT, class _Traits, class _Allocator>
int
basic_string<_CharT, _Traits, _Allocator>::compare(size_type __pos1,
size_type __n1,
const value_type* __s) const
{
_LIBCPP_ASSERT(__s != nullptr, "string::compare(): received nullptr");
return compare(__pos1, __n1, __s, traits_type::length(__s));
}
// __invariants
template<class _CharT, class _Traits, class _Allocator>
inline
bool
basic_string<_CharT, _Traits, _Allocator>::__invariants() const
{
if (size() > capacity())
return false;
if (capacity() < __min_cap - 1)
return false;
if (data() == 0)
return false;
if (data()[size()] != value_type(0))
return false;
return true;
}
// __clear_and_shrink
template<class _CharT, class _Traits, class _Allocator>
inline
void
basic_string<_CharT, _Traits, _Allocator>::__clear_and_shrink() _NOEXCEPT
{
clear();
if(__is_long())
{
__alloc_traits::deallocate(__alloc(), __get_long_pointer(), capacity() + 1);
__set_long_cap(0);
__set_short_size(0);
}
}
// operator==
template<class _CharT, class _Traits, class _Allocator>
inline _LIBCPP_INLINE_VISIBILITY
bool
operator==(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
{
size_t __lhs_sz = __lhs.size();
return __lhs_sz == __rhs.size() && _Traits::compare(__lhs.data(),
__rhs.data(),
__lhs_sz) == 0;
}
template<class _Allocator>
inline _LIBCPP_INLINE_VISIBILITY
bool
operator==(const basic_string<char, char_traits<char>, _Allocator>& __lhs,
const basic_string<char, char_traits<char>, _Allocator>& __rhs) _NOEXCEPT
{
size_t __lhs_sz = __lhs.size();
if (__lhs_sz != __rhs.size())
return false;
const char* __lp = __lhs.data();
const char* __rp = __rhs.data();
if (__lhs.__is_long())
return char_traits<char>::compare(__lp, __rp, __lhs_sz) == 0;
for (; __lhs_sz != 0; --__lhs_sz, ++__lp, ++__rp)
if (*__lp != *__rp)
return false;
return true;
}
template<class _CharT, class _Traits, class _Allocator>
inline _LIBCPP_INLINE_VISIBILITY
bool
operator==(const _CharT* __lhs,
const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
{
typedef basic_string<_CharT, _Traits, _Allocator> _String;
_LIBCPP_ASSERT(__lhs != nullptr, "operator==(char*, basic_string): received nullptr");
size_t __lhs_len = _Traits::length(__lhs);
if (__lhs_len != __rhs.size()) return false;
return __rhs.compare(0, _String::npos, __lhs, __lhs_len) == 0;
}
template<class _CharT, class _Traits, class _Allocator>
inline _LIBCPP_INLINE_VISIBILITY
bool
operator==(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
const _CharT* __rhs) _NOEXCEPT
{
typedef basic_string<_CharT, _Traits, _Allocator> _String;
_LIBCPP_ASSERT(__rhs != nullptr, "operator==(basic_string, char*): received nullptr");
size_t __rhs_len = _Traits::length(__rhs);
if (__rhs_len != __lhs.size()) return false;
return __lhs.compare(0, _String::npos, __rhs, __rhs_len) == 0;
}
template<class _CharT, class _Traits, class _Allocator>
inline _LIBCPP_INLINE_VISIBILITY
bool
operator!=(const basic_string<_CharT,_Traits,_Allocator>& __lhs,
const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
{
return !(__lhs == __rhs);
}
template<class _CharT, class _Traits, class _Allocator>
inline _LIBCPP_INLINE_VISIBILITY
bool
operator!=(const _CharT* __lhs,
const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
{
return !(__lhs == __rhs);
}
template<class _CharT, class _Traits, class _Allocator>
inline _LIBCPP_INLINE_VISIBILITY
bool
operator!=(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
const _CharT* __rhs) _NOEXCEPT
{
return !(__lhs == __rhs);
}
// operator<
template<class _CharT, class _Traits, class _Allocator>
inline _LIBCPP_INLINE_VISIBILITY
bool
operator< (const basic_string<_CharT, _Traits, _Allocator>& __lhs,
const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
{
return __lhs.compare(__rhs) < 0;
}
template<class _CharT, class _Traits, class _Allocator>
inline _LIBCPP_INLINE_VISIBILITY
bool
operator< (const basic_string<_CharT, _Traits, _Allocator>& __lhs,
const _CharT* __rhs) _NOEXCEPT
{
return __lhs.compare(__rhs) < 0;
}
template<class _CharT, class _Traits, class _Allocator>
inline _LIBCPP_INLINE_VISIBILITY
bool
operator< (const _CharT* __lhs,
const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
{
return __rhs.compare(__lhs) > 0;
}
// operator>
template<class _CharT, class _Traits, class _Allocator>
inline _LIBCPP_INLINE_VISIBILITY
bool
operator> (const basic_string<_CharT, _Traits, _Allocator>& __lhs,
const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
{
return __rhs < __lhs;
}
template<class _CharT, class _Traits, class _Allocator>
inline _LIBCPP_INLINE_VISIBILITY
bool
operator> (const basic_string<_CharT, _Traits, _Allocator>& __lhs,
const _CharT* __rhs) _NOEXCEPT
{
return __rhs < __lhs;
}
template<class _CharT, class _Traits, class _Allocator>
inline _LIBCPP_INLINE_VISIBILITY
bool
operator> (const _CharT* __lhs,
const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
{
return __rhs < __lhs;
}
// operator<=
template<class _CharT, class _Traits, class _Allocator>
inline _LIBCPP_INLINE_VISIBILITY
bool
operator<=(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
{
return !(__rhs < __lhs);
}
template<class _CharT, class _Traits, class _Allocator>
inline _LIBCPP_INLINE_VISIBILITY
bool
operator<=(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
const _CharT* __rhs) _NOEXCEPT
{
return !(__rhs < __lhs);
}
template<class _CharT, class _Traits, class _Allocator>
inline _LIBCPP_INLINE_VISIBILITY
bool
operator<=(const _CharT* __lhs,
const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
{
return !(__rhs < __lhs);
}
// operator>=
template<class _CharT, class _Traits, class _Allocator>
inline _LIBCPP_INLINE_VISIBILITY
bool
operator>=(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
{
return !(__lhs < __rhs);
}
template<class _CharT, class _Traits, class _Allocator>
inline _LIBCPP_INLINE_VISIBILITY
bool
operator>=(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
const _CharT* __rhs) _NOEXCEPT
{
return !(__lhs < __rhs);
}
template<class _CharT, class _Traits, class _Allocator>
inline _LIBCPP_INLINE_VISIBILITY
bool
operator>=(const _CharT* __lhs,
const basic_string<_CharT, _Traits, _Allocator>& __rhs) _NOEXCEPT
{
return !(__lhs < __rhs);
}
// operator +
template<class _CharT, class _Traits, class _Allocator>
basic_string<_CharT, _Traits, _Allocator>
operator+(const basic_string<_CharT, _Traits, _Allocator>& __lhs,
const basic_string<_CharT, _Traits, _Allocator>& __rhs)
{
basic_string<_CharT, _Traits, _Allocator> __r(__lhs.get_allocator());
typename basic_string<_CharT, _Traits, _Allocator>::size_type __lhs_sz = __lhs.size();
typename basic_string<_CharT, _Traits, _Allocator>::size_type __rhs_sz = __rhs.size();
__r.__init(__lhs.data(), __lhs_sz, __lhs_sz + __rhs_sz);
__r.append(__rhs.data(), __rhs_sz);
return __r;
}
template<class _CharT, class _Traits, class _Allocator>
basic_string<_CharT, _Traits, _Allocator>
operator+(const _CharT* __lhs , const basic_string<_CharT,_Traits,_Allocator>& __rhs)
{
basic_string<_CharT, _Traits, _Allocator> __r(__rhs.get_allocator());
typename basic_string<_CharT, _Traits, _Allocator>::size_type __lhs_sz = _Traits::length(__lhs);
typename basic_string<_CharT, _Traits, _Allocator>::size_type __rhs_sz = __rhs.size();
__r.__init(__lhs, __lhs_sz, __lhs_sz + __rhs_sz);
__r.append(__rhs.data(), __rhs_sz);
return __r;
}
template<class _CharT, class _Traits, class _Allocator>
basic_string<_CharT, _Traits, _Allocator>
operator+(_CharT __lhs, const basic_string<_CharT,_Traits,_Allocator>& __rhs)
{
basic_string<_CharT, _Traits, _Allocator> __r(__rhs.get_allocator());
typename basic_string<_CharT, _Traits, _Allocator>::size_type __rhs_sz = __rhs.size();
__r.__init(&__lhs, 1, 1 + __rhs_sz);
__r.append(__rhs.data(), __rhs_sz);
return __r;
}
template<class _CharT, class _Traits, class _Allocator>
inline
basic_string<_CharT, _Traits, _Allocator>
operator+(const basic_string<_CharT, _Traits, _Allocator>& __lhs, const _CharT* __rhs)
{
basic_string<_CharT, _Traits, _Allocator> __r(__lhs.get_allocator());
typename basic_string<_CharT, _Traits, _Allocator>::size_type __lhs_sz = __lhs.size();
typename basic_string<_CharT, _Traits, _Allocator>::size_type __rhs_sz = _Traits::length(__rhs);
__r.__init(__lhs.data(), __lhs_sz, __lhs_sz + __rhs_sz);
__r.append(__rhs, __rhs_sz);
return __r;
}
template<class _CharT, class _Traits, class _Allocator>
basic_string<_CharT, _Traits, _Allocator>
operator+(const basic_string<_CharT, _Traits, _Allocator>& __lhs, _CharT __rhs)
{
basic_string<_CharT, _Traits, _Allocator> __r(__lhs.get_allocator());
typename basic_string<_CharT, _Traits, _Allocator>::size_type __lhs_sz = __lhs.size();
__r.__init(__lhs.data(), __lhs_sz, __lhs_sz + 1);
__r.push_back(__rhs);
return __r;
}
#ifndef _LIBCPP_CXX03_LANG
template<class _CharT, class _Traits, class _Allocator>
inline _LIBCPP_INLINE_VISIBILITY
basic_string<_CharT, _Traits, _Allocator>
operator+(basic_string<_CharT, _Traits, _Allocator>&& __lhs, const basic_string<_CharT, _Traits, _Allocator>& __rhs)
{
return _VSTD::move(__lhs.append(__rhs));
}
template<class _CharT, class _Traits, class _Allocator>
inline _LIBCPP_INLINE_VISIBILITY
basic_string<_CharT, _Traits, _Allocator>
operator+(const basic_string<_CharT, _Traits, _Allocator>& __lhs, basic_string<_CharT, _Traits, _Allocator>&& __rhs)
{
return _VSTD::move(__rhs.insert(0, __lhs));
}
template<class _CharT, class _Traits, class _Allocator>
inline _LIBCPP_INLINE_VISIBILITY
basic_string<_CharT, _Traits, _Allocator>
operator+(basic_string<_CharT, _Traits, _Allocator>&& __lhs, basic_string<_CharT, _Traits, _Allocator>&& __rhs)
{
return _VSTD::move(__lhs.append(__rhs));
}
template<class _CharT, class _Traits, class _Allocator>
inline _LIBCPP_INLINE_VISIBILITY
basic_string<_CharT, _Traits, _Allocator>
operator+(const _CharT* __lhs , basic_string<_CharT,_Traits,_Allocator>&& __rhs)
{
return _VSTD::move(__rhs.insert(0, __lhs));
}
template<class _CharT, class _Traits, class _Allocator>
inline _LIBCPP_INLINE_VISIBILITY
basic_string<_CharT, _Traits, _Allocator>
operator+(_CharT __lhs, basic_string<_CharT,_Traits,_Allocator>&& __rhs)
{
__rhs.insert(__rhs.begin(), __lhs);
return _VSTD::move(__rhs);
}
template<class _CharT, class _Traits, class _Allocator>
inline _LIBCPP_INLINE_VISIBILITY
basic_string<_CharT, _Traits, _Allocator>
operator+(basic_string<_CharT, _Traits, _Allocator>&& __lhs, const _CharT* __rhs)
{
return _VSTD::move(__lhs.append(__rhs));
}
template<class _CharT, class _Traits, class _Allocator>
inline _LIBCPP_INLINE_VISIBILITY
basic_string<_CharT, _Traits, _Allocator>
operator+(basic_string<_CharT, _Traits, _Allocator>&& __lhs, _CharT __rhs)
{
__lhs.push_back(__rhs);
return _VSTD::move(__lhs);
}
#endif // _LIBCPP_CXX03_LANG
// swap
template<class _CharT, class _Traits, class _Allocator>
inline _LIBCPP_INLINE_VISIBILITY
void
swap(basic_string<_CharT, _Traits, _Allocator>& __lhs,
basic_string<_CharT, _Traits, _Allocator>& __rhs)
_NOEXCEPT_(_NOEXCEPT_(__lhs.swap(__rhs)))
{
__lhs.swap(__rhs);
}
#ifndef _LIBCPP_NO_HAS_CHAR8_T
typedef basic_string<char8_t> u8string;
#endif
#ifndef _LIBCPP_HAS_NO_UNICODE_CHARS
typedef basic_string<char16_t> u16string;
typedef basic_string<char32_t> u32string;
#endif // _LIBCPP_HAS_NO_UNICODE_CHARS
_LIBCPP_FUNC_VIS int stoi (const string& __str, size_t* __idx = 0, int __base = 10);
_LIBCPP_FUNC_VIS long stol (const string& __str, size_t* __idx = 0, int __base = 10);
_LIBCPP_FUNC_VIS unsigned long stoul (const string& __str, size_t* __idx = 0, int __base = 10);
_LIBCPP_FUNC_VIS long long stoll (const string& __str, size_t* __idx = 0, int __base = 10);
_LIBCPP_FUNC_VIS unsigned long long stoull(const string& __str, size_t* __idx = 0, int __base = 10);
_LIBCPP_FUNC_VIS float stof (const string& __str, size_t* __idx = 0);
_LIBCPP_FUNC_VIS double stod (const string& __str, size_t* __idx = 0);
_LIBCPP_FUNC_VIS long double stold(const string& __str, size_t* __idx = 0);
_LIBCPP_FUNC_VIS string to_string(int __val);
_LIBCPP_FUNC_VIS string to_string(unsigned __val);
_LIBCPP_FUNC_VIS string to_string(long __val);
_LIBCPP_FUNC_VIS string to_string(unsigned long __val);
_LIBCPP_FUNC_VIS string to_string(long long __val);
_LIBCPP_FUNC_VIS string to_string(unsigned long long __val);
_LIBCPP_FUNC_VIS string to_string(float __val);
_LIBCPP_FUNC_VIS string to_string(double __val);
_LIBCPP_FUNC_VIS string to_string(long double __val);
_LIBCPP_FUNC_VIS int stoi (const wstring& __str, size_t* __idx = 0, int __base = 10);
_LIBCPP_FUNC_VIS long stol (const wstring& __str, size_t* __idx = 0, int __base = 10);
_LIBCPP_FUNC_VIS unsigned long stoul (const wstring& __str, size_t* __idx = 0, int __base = 10);
_LIBCPP_FUNC_VIS long long stoll (const wstring& __str, size_t* __idx = 0, int __base = 10);
_LIBCPP_FUNC_VIS unsigned long long stoull(const wstring& __str, size_t* __idx = 0, int __base = 10);
_LIBCPP_FUNC_VIS float stof (const wstring& __str, size_t* __idx = 0);
_LIBCPP_FUNC_VIS double stod (const wstring& __str, size_t* __idx = 0);
_LIBCPP_FUNC_VIS long double stold(const wstring& __str, size_t* __idx = 0);
_LIBCPP_FUNC_VIS wstring to_wstring(int __val);
_LIBCPP_FUNC_VIS wstring to_wstring(unsigned __val);
_LIBCPP_FUNC_VIS wstring to_wstring(long __val);
_LIBCPP_FUNC_VIS wstring to_wstring(unsigned long __val);
_LIBCPP_FUNC_VIS wstring to_wstring(long long __val);
_LIBCPP_FUNC_VIS wstring to_wstring(unsigned long long __val);
_LIBCPP_FUNC_VIS wstring to_wstring(float __val);
_LIBCPP_FUNC_VIS wstring to_wstring(double __val);
_LIBCPP_FUNC_VIS wstring to_wstring(long double __val);
template<class _CharT, class _Traits, class _Allocator>
const typename basic_string<_CharT, _Traits, _Allocator>::size_type
basic_string<_CharT, _Traits, _Allocator>::npos;
template <class _CharT, class _Allocator>
struct _LIBCPP_TEMPLATE_VIS
hash<basic_string<_CharT, char_traits<_CharT>, _Allocator> >
: public unary_function<
basic_string<_CharT, char_traits<_CharT>, _Allocator>, size_t>
{
size_t
operator()(const basic_string<_CharT, char_traits<_CharT>, _Allocator>& __val) const _NOEXCEPT
{ return __do_string_hash(__val.data(), __val.data() + __val.size()); }
};
template<class _CharT, class _Traits, class _Allocator>
basic_ostream<_CharT, _Traits>&
operator<<(basic_ostream<_CharT, _Traits>& __os,
const basic_string<_CharT, _Traits, _Allocator>& __str);
template<class _CharT, class _Traits, class _Allocator>
basic_istream<_CharT, _Traits>&
operator>>(basic_istream<_CharT, _Traits>& __is,
basic_string<_CharT, _Traits, _Allocator>& __str);
template<class _CharT, class _Traits, class _Allocator>
basic_istream<_CharT, _Traits>&
getline(basic_istream<_CharT, _Traits>& __is,
basic_string<_CharT, _Traits, _Allocator>& __str, _CharT __dlm);
template<class _CharT, class _Traits, class _Allocator>
inline _LIBCPP_INLINE_VISIBILITY
basic_istream<_CharT, _Traits>&
getline(basic_istream<_CharT, _Traits>& __is,
basic_string<_CharT, _Traits, _Allocator>& __str);
#ifndef _LIBCPP_CXX03_LANG
template<class _CharT, class _Traits, class _Allocator>
inline _LIBCPP_INLINE_VISIBILITY
basic_istream<_CharT, _Traits>&
getline(basic_istream<_CharT, _Traits>&& __is,
basic_string<_CharT, _Traits, _Allocator>& __str, _CharT __dlm);
template<class _CharT, class _Traits, class _Allocator>
inline _LIBCPP_INLINE_VISIBILITY
basic_istream<_CharT, _Traits>&
getline(basic_istream<_CharT, _Traits>&& __is,
basic_string<_CharT, _Traits, _Allocator>& __str);
#endif // _LIBCPP_CXX03_LANG
#if _LIBCPP_STD_VER > 17
template<class _CharT, class _Traits, class _Allocator, class _Up>
inline _LIBCPP_INLINE_VISIBILITY
void erase(basic_string<_CharT, _Traits, _Allocator>& __str, const _Up& __v)
{ __str.erase(_VSTD::remove(__str.begin(), __str.end(), __v), __str.end()); }
template<class _CharT, class _Traits, class _Allocator, class _Predicate>
inline _LIBCPP_INLINE_VISIBILITY
void erase_if(basic_string<_CharT, _Traits, _Allocator>& __str, _Predicate __pred)
{ __str.erase(_VSTD::remove_if(__str.begin(), __str.end(), __pred), __str.end()); }
#endif
#if _LIBCPP_DEBUG_LEVEL >= 2
template<class _CharT, class _Traits, class _Allocator>
bool
basic_string<_CharT, _Traits, _Allocator>::__dereferenceable(const const_iterator* __i) const
{
return this->data() <= _VSTD::__to_raw_pointer(__i->base()) &&
_VSTD::__to_raw_pointer(__i->base()) < this->data() + this->size();
}
template<class _CharT, class _Traits, class _Allocator>
bool
basic_string<_CharT, _Traits, _Allocator>::__decrementable(const const_iterator* __i) const
{
return this->data() < _VSTD::__to_raw_pointer(__i->base()) &&
_VSTD::__to_raw_pointer(__i->base()) <= this->data() + this->size();
}
template<class _CharT, class _Traits, class _Allocator>
bool
basic_string<_CharT, _Traits, _Allocator>::__addable(const const_iterator* __i, ptrdiff_t __n) const
{
const value_type* __p = _VSTD::__to_raw_pointer(__i->base()) + __n;
return this->data() <= __p && __p <= this->data() + this->size();
}
template<class _CharT, class _Traits, class _Allocator>
bool
basic_string<_CharT, _Traits, _Allocator>::__subscriptable(const const_iterator* __i, ptrdiff_t __n) const
{
const value_type* __p = _VSTD::__to_raw_pointer(__i->base()) + __n;
return this->data() <= __p && __p < this->data() + this->size();
}
#endif // _LIBCPP_DEBUG_LEVEL >= 2
_LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_string<char>)
_LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_string<wchar_t>)
#if _LIBCPP_STD_VER > 11
// Literal suffixes for basic_string [basic.string.literals]
inline namespace literals
{
inline namespace string_literals
{
inline _LIBCPP_INLINE_VISIBILITY
basic_string<char> operator "" s( const char *__str, size_t __len )
{
return basic_string<char> (__str, __len);
}
inline _LIBCPP_INLINE_VISIBILITY
basic_string<wchar_t> operator "" s( const wchar_t *__str, size_t __len )
{
return basic_string<wchar_t> (__str, __len);
}
#ifndef _LIBCPP_NO_HAS_CHAR8_T
inline _LIBCPP_INLINE_VISIBILITY
basic_string<char8_t> operator "" s(const char8_t *__str, size_t __len) _NOEXCEPT
{
return basic_string<char8_t> (__str, __len);
}
#endif
inline _LIBCPP_INLINE_VISIBILITY
basic_string<char16_t> operator "" s( const char16_t *__str, size_t __len )
{
return basic_string<char16_t> (__str, __len);
}
inline _LIBCPP_INLINE_VISIBILITY
basic_string<char32_t> operator "" s( const char32_t *__str, size_t __len )
{
return basic_string<char32_t> (__str, __len);
}
}
}
#endif
_LIBCPP_END_NAMESPACE_STD
_LIBCPP_POP_MACROS
#endif // _LIBCPP_STRING
| 161,597 | 4,366 | jart/cosmopolitan | false |
cosmopolitan/third_party/libcxx/__threading_support | // -*- 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_THREADING_SUPPORT
#define _LIBCPP_THREADING_SUPPORT
#include "third_party/libcxx/__config"
#include "third_party/libcxx/chrono"
#include "third_party/libcxx/iosfwd"
#include "libc/thread/thread2.h"
#include "third_party/libcxx/errno.h"
#ifndef _LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER
#pragma GCC system_header
#endif
#if defined(_LIBCPP_HAS_THREAD_API_EXTERNAL)
# include "third_party/libcxx/__external_threading"
#elif !defined(_LIBCPP_HAS_NO_THREADS)
#if defined(_LIBCPP_HAS_THREAD_API_PTHREAD)
#include "libc/thread/thread.h"
#include "libc/calls/calls.h"
#include "libc/calls/struct/sched_param.h"
#include "libc/sysv/consts/sched.h"
#endif
#if defined(_LIBCPP_HAS_THREAD_LIBRARY_EXTERNAL) || \
defined(_LIBCPP_BUILDING_THREAD_LIBRARY_EXTERNAL) || \
defined(_LIBCPP_HAS_THREAD_API_WIN32)
#define _LIBCPP_THREAD_ABI_VISIBILITY _LIBCPP_FUNC_VIS
#else
#define _LIBCPP_THREAD_ABI_VISIBILITY inline _LIBCPP_INLINE_VISIBILITY
#endif
#if defined(__FreeBSD__) && defined(__clang__) && __has_attribute(no_thread_safety_analysis)
#define _LIBCPP_NO_THREAD_SAFETY_ANALYSIS __attribute__((no_thread_safety_analysis))
#else
#define _LIBCPP_NO_THREAD_SAFETY_ANALYSIS
#endif
typedef ::timespec __libcpp_timespec_t;
#endif // !defined(_LIBCPP_HAS_NO_THREADS)
_LIBCPP_PUSH_MACROS
#include "third_party/libcxx/__undef_macros"
_LIBCPP_BEGIN_NAMESPACE_STD
#if !defined(_LIBCPP_HAS_NO_THREADS)
#if defined(_LIBCPP_HAS_THREAD_API_PTHREAD)
// Mutex
typedef pthread_mutex_t __libcpp_mutex_t;
#define _LIBCPP_MUTEX_INITIALIZER PTHREAD_MUTEX_INITIALIZER
typedef pthread_mutex_t __libcpp_recursive_mutex_t;
// Condition Variable
typedef pthread_cond_t __libcpp_condvar_t;
#define _LIBCPP_CONDVAR_INITIALIZER PTHREAD_COND_INITIALIZER
// Execute once
typedef pthread_once_t __libcpp_exec_once_flag;
#define _LIBCPP_EXEC_ONCE_INITIALIZER PTHREAD_ONCE_INIT
// Thread id
typedef pthread_t __libcpp_thread_id;
// Thread
#define _LIBCPP_NULL_THREAD 0U
typedef pthread_t __libcpp_thread_t;
// Thread Local Storage
typedef pthread_key_t __libcpp_tls_key;
#define _LIBCPP_TLS_DESTRUCTOR_CC
#elif !defined(_LIBCPP_HAS_THREAD_API_EXTERNAL)
// Mutex
typedef void* __libcpp_mutex_t;
#define _LIBCPP_MUTEX_INITIALIZER 0
#if defined(_M_IX86) || defined(__i386__) || defined(_M_ARM) || defined(__arm__)
typedef void* __libcpp_recursive_mutex_t[6];
#elif defined(_M_AMD64) || defined(__x86_64__) || defined(_M_ARM64) || defined(__aarch64__)
typedef void* __libcpp_recursive_mutex_t[5];
#else
# error Unsupported architecture
#endif
// Condition Variable
typedef void* __libcpp_condvar_t;
#define _LIBCPP_CONDVAR_INITIALIZER 0
// Execute Once
typedef void* __libcpp_exec_once_flag;
#define _LIBCPP_EXEC_ONCE_INITIALIZER 0
// Thread ID
typedef long __libcpp_thread_id;
// Thread
#define _LIBCPP_NULL_THREAD 0U
typedef void* __libcpp_thread_t;
// Thread Local Storage
typedef long __libcpp_tls_key;
#define _LIBCPP_TLS_DESTRUCTOR_CC __stdcall
#endif // !defined(_LIBCPP_HAS_THREAD_API_PTHREAD) && !defined(_LIBCPP_HAS_THREAD_API_EXTERNAL)
#if !defined(_LIBCPP_HAS_THREAD_API_EXTERNAL)
// Mutex
_LIBCPP_THREAD_ABI_VISIBILITY
int __libcpp_recursive_mutex_init(__libcpp_recursive_mutex_t *__m);
_LIBCPP_THREAD_ABI_VISIBILITY _LIBCPP_NO_THREAD_SAFETY_ANALYSIS
int __libcpp_recursive_mutex_lock(__libcpp_recursive_mutex_t *__m);
_LIBCPP_THREAD_ABI_VISIBILITY _LIBCPP_NO_THREAD_SAFETY_ANALYSIS
bool __libcpp_recursive_mutex_trylock(__libcpp_recursive_mutex_t *__m);
_LIBCPP_THREAD_ABI_VISIBILITY _LIBCPP_NO_THREAD_SAFETY_ANALYSIS
int __libcpp_recursive_mutex_unlock(__libcpp_recursive_mutex_t *__m);
_LIBCPP_THREAD_ABI_VISIBILITY
int __libcpp_recursive_mutex_destroy(__libcpp_recursive_mutex_t *__m);
_LIBCPP_THREAD_ABI_VISIBILITY _LIBCPP_NO_THREAD_SAFETY_ANALYSIS
int __libcpp_mutex_lock(__libcpp_mutex_t *__m);
_LIBCPP_THREAD_ABI_VISIBILITY _LIBCPP_NO_THREAD_SAFETY_ANALYSIS
bool __libcpp_mutex_trylock(__libcpp_mutex_t *__m);
_LIBCPP_THREAD_ABI_VISIBILITY _LIBCPP_NO_THREAD_SAFETY_ANALYSIS
int __libcpp_mutex_unlock(__libcpp_mutex_t *__m);
_LIBCPP_THREAD_ABI_VISIBILITY
int __libcpp_mutex_destroy(__libcpp_mutex_t *__m);
// Condition variable
_LIBCPP_THREAD_ABI_VISIBILITY
int __libcpp_condvar_signal(__libcpp_condvar_t* __cv);
_LIBCPP_THREAD_ABI_VISIBILITY
int __libcpp_condvar_broadcast(__libcpp_condvar_t* __cv);
_LIBCPP_THREAD_ABI_VISIBILITY _LIBCPP_NO_THREAD_SAFETY_ANALYSIS
int __libcpp_condvar_wait(__libcpp_condvar_t* __cv, __libcpp_mutex_t* __m);
_LIBCPP_THREAD_ABI_VISIBILITY _LIBCPP_NO_THREAD_SAFETY_ANALYSIS
int __libcpp_condvar_timedwait(__libcpp_condvar_t *__cv, __libcpp_mutex_t *__m,
__libcpp_timespec_t *__ts);
_LIBCPP_THREAD_ABI_VISIBILITY
int __libcpp_condvar_destroy(__libcpp_condvar_t* __cv);
// Execute once
_LIBCPP_THREAD_ABI_VISIBILITY
int __libcpp_execute_once(__libcpp_exec_once_flag *flag,
void (*init_routine)());
// Thread id
_LIBCPP_THREAD_ABI_VISIBILITY
bool __libcpp_thread_id_equal(__libcpp_thread_id t1, __libcpp_thread_id t2);
_LIBCPP_THREAD_ABI_VISIBILITY
bool __libcpp_thread_id_less(__libcpp_thread_id t1, __libcpp_thread_id t2);
// Thread
_LIBCPP_THREAD_ABI_VISIBILITY
bool __libcpp_thread_isnull(const __libcpp_thread_t *__t);
_LIBCPP_THREAD_ABI_VISIBILITY
int __libcpp_thread_create(__libcpp_thread_t *__t, void *(*__func)(void *),
void *__arg);
_LIBCPP_THREAD_ABI_VISIBILITY
__libcpp_thread_id __libcpp_thread_get_current_id();
_LIBCPP_THREAD_ABI_VISIBILITY
__libcpp_thread_id __libcpp_thread_get_id(const __libcpp_thread_t *__t);
_LIBCPP_THREAD_ABI_VISIBILITY
int __libcpp_thread_join(__libcpp_thread_t *__t);
_LIBCPP_THREAD_ABI_VISIBILITY
int __libcpp_thread_detach(__libcpp_thread_t *__t);
_LIBCPP_THREAD_ABI_VISIBILITY
void __libcpp_thread_yield();
_LIBCPP_THREAD_ABI_VISIBILITY
void __libcpp_thread_sleep_for(const chrono::nanoseconds& __ns);
// Thread local storage
_LIBCPP_THREAD_ABI_VISIBILITY
int __libcpp_tls_create(__libcpp_tls_key* __key,
void(_LIBCPP_TLS_DESTRUCTOR_CC* __at_exit)(void*));
_LIBCPP_THREAD_ABI_VISIBILITY
void *__libcpp_tls_get(__libcpp_tls_key __key);
_LIBCPP_THREAD_ABI_VISIBILITY
int __libcpp_tls_set(__libcpp_tls_key __key, void *__p);
#endif // !defined(_LIBCPP_HAS_THREAD_API_EXTERNAL)
#if (!defined(_LIBCPP_HAS_THREAD_LIBRARY_EXTERNAL) || \
defined(_LIBCPP_BUILDING_THREAD_LIBRARY_EXTERNAL)) && \
defined(_LIBCPP_HAS_THREAD_API_PTHREAD)
int __libcpp_recursive_mutex_init(__libcpp_recursive_mutex_t *__m)
{
pthread_mutexattr_t attr;
int __ec = pthread_mutexattr_init(&attr);
if (__ec)
return __ec;
__ec = pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE);
if (__ec) {
pthread_mutexattr_destroy(&attr);
return __ec;
}
__ec = pthread_mutex_init(__m, &attr);
if (__ec) {
pthread_mutexattr_destroy(&attr);
return __ec;
}
__ec = pthread_mutexattr_destroy(&attr);
if (__ec) {
pthread_mutex_destroy(__m);
return __ec;
}
return 0;
}
int __libcpp_recursive_mutex_lock(__libcpp_recursive_mutex_t *__m)
{
return pthread_mutex_lock(__m);
}
bool __libcpp_recursive_mutex_trylock(__libcpp_recursive_mutex_t *__m)
{
return pthread_mutex_trylock(__m) == 0;
}
int __libcpp_recursive_mutex_unlock(__libcpp_mutex_t *__m)
{
return pthread_mutex_unlock(__m);
}
int __libcpp_recursive_mutex_destroy(__libcpp_recursive_mutex_t *__m)
{
return pthread_mutex_destroy(__m);
}
int __libcpp_mutex_lock(__libcpp_mutex_t *__m)
{
return pthread_mutex_lock(__m);
}
bool __libcpp_mutex_trylock(__libcpp_mutex_t *__m)
{
return pthread_mutex_trylock(__m) == 0;
}
int __libcpp_mutex_unlock(__libcpp_mutex_t *__m)
{
return pthread_mutex_unlock(__m);
}
int __libcpp_mutex_destroy(__libcpp_mutex_t *__m)
{
return pthread_mutex_destroy(__m);
}
// Condition Variable
int __libcpp_condvar_signal(__libcpp_condvar_t *__cv)
{
return pthread_cond_signal(__cv);
}
int __libcpp_condvar_broadcast(__libcpp_condvar_t *__cv)
{
return pthread_cond_broadcast(__cv);
}
int __libcpp_condvar_wait(__libcpp_condvar_t *__cv, __libcpp_mutex_t *__m)
{
return pthread_cond_wait(__cv, __m);
}
int __libcpp_condvar_timedwait(__libcpp_condvar_t *__cv, __libcpp_mutex_t *__m,
__libcpp_timespec_t *__ts)
{
return pthread_cond_timedwait(__cv, __m, __ts);
}
int __libcpp_condvar_destroy(__libcpp_condvar_t *__cv)
{
return pthread_cond_destroy(__cv);
}
// Execute once
int __libcpp_execute_once(__libcpp_exec_once_flag *flag,
void (*init_routine)()) {
return pthread_once(flag, init_routine);
}
// Thread id
// Returns non-zero if the thread ids are equal, otherwise 0
bool __libcpp_thread_id_equal(__libcpp_thread_id t1, __libcpp_thread_id t2)
{
return pthread_equal(t1, t2) != 0;
}
// Returns non-zero if t1 < t2, otherwise 0
bool __libcpp_thread_id_less(__libcpp_thread_id t1, __libcpp_thread_id t2)
{
return t1 < t2;
}
// Thread
bool __libcpp_thread_isnull(const __libcpp_thread_t *__t) {
return *__t == 0;
}
int __libcpp_thread_create(__libcpp_thread_t *__t, void *(*__func)(void *),
void *__arg)
{
return pthread_create(__t, 0, __func, __arg);
}
__libcpp_thread_id __libcpp_thread_get_current_id()
{
return pthread_self();
}
__libcpp_thread_id __libcpp_thread_get_id(const __libcpp_thread_t *__t)
{
return *__t;
}
int __libcpp_thread_join(__libcpp_thread_t *__t)
{
return pthread_join(*__t, 0);
}
int __libcpp_thread_detach(__libcpp_thread_t *__t)
{
return pthread_detach(*__t);
}
void __libcpp_thread_yield()
{
sched_yield();
}
void __libcpp_thread_sleep_for(const chrono::nanoseconds& __ns)
{
using namespace chrono;
seconds __s = duration_cast<seconds>(__ns);
__libcpp_timespec_t __ts;
typedef decltype(__ts.tv_sec) ts_sec;
_LIBCPP_CONSTEXPR ts_sec __ts_sec_max = numeric_limits<ts_sec>::max();
if (__s.count() < __ts_sec_max)
{
__ts.tv_sec = static_cast<ts_sec>(__s.count());
__ts.tv_nsec = static_cast<decltype(__ts.tv_nsec)>((__ns - __s).count());
}
else
{
__ts.tv_sec = __ts_sec_max;
__ts.tv_nsec = 999999999; // (10^9 - 1)
}
while (nanosleep(&__ts, &__ts) == -1 && errno == EINTR);
}
// Thread local storage
int __libcpp_tls_create(__libcpp_tls_key *__key, void (*__at_exit)(void *))
{
return pthread_key_create(__key, __at_exit);
}
void *__libcpp_tls_get(__libcpp_tls_key __key)
{
return pthread_getspecific(__key);
}
int __libcpp_tls_set(__libcpp_tls_key __key, void *__p)
{
return pthread_setspecific(__key, __p);
}
#endif // !_LIBCPP_HAS_THREAD_LIBRARY_EXTERNAL || _LIBCPP_BUILDING_THREAD_LIBRARY_EXTERNAL
class _LIBCPP_TYPE_VIS thread;
class _LIBCPP_TYPE_VIS __thread_id;
namespace this_thread
{
_LIBCPP_INLINE_VISIBILITY __thread_id get_id() _NOEXCEPT;
} // this_thread
template<> struct hash<__thread_id>;
class _LIBCPP_TEMPLATE_VIS __thread_id
{
// FIXME: pthread_t is a pointer on Darwin but a long on Linux.
// NULL is the no-thread value on Darwin. Someone needs to check
// on other platforms. We assume 0 works everywhere for now.
__libcpp_thread_id __id_;
public:
_LIBCPP_INLINE_VISIBILITY
__thread_id() _NOEXCEPT : __id_(0) {}
friend _LIBCPP_INLINE_VISIBILITY
bool operator==(__thread_id __x, __thread_id __y) _NOEXCEPT
{ // don't pass id==0 to underlying routines
if (__x.__id_ == 0) return __y.__id_ == 0;
if (__y.__id_ == 0) return false;
return __libcpp_thread_id_equal(__x.__id_, __y.__id_);
}
friend _LIBCPP_INLINE_VISIBILITY
bool operator!=(__thread_id __x, __thread_id __y) _NOEXCEPT
{return !(__x == __y);}
friend _LIBCPP_INLINE_VISIBILITY
bool operator< (__thread_id __x, __thread_id __y) _NOEXCEPT
{ // id==0 is always less than any other thread_id
if (__x.__id_ == 0) return __y.__id_ != 0;
if (__y.__id_ == 0) return false;
return __libcpp_thread_id_less(__x.__id_, __y.__id_);
}
friend _LIBCPP_INLINE_VISIBILITY
bool operator<=(__thread_id __x, __thread_id __y) _NOEXCEPT
{return !(__y < __x);}
friend _LIBCPP_INLINE_VISIBILITY
bool operator> (__thread_id __x, __thread_id __y) _NOEXCEPT
{return __y < __x ;}
friend _LIBCPP_INLINE_VISIBILITY
bool operator>=(__thread_id __x, __thread_id __y) _NOEXCEPT
{return !(__x < __y);}
_LIBCPP_INLINE_VISIBILITY
void __reset() { __id_ = 0; }
template<class _CharT, class _Traits>
friend
_LIBCPP_INLINE_VISIBILITY
basic_ostream<_CharT, _Traits>&
operator<<(basic_ostream<_CharT, _Traits>& __os, __thread_id __id);
private:
_LIBCPP_INLINE_VISIBILITY
__thread_id(__libcpp_thread_id __id) : __id_(__id) {}
friend __thread_id this_thread::get_id() _NOEXCEPT;
friend class _LIBCPP_TYPE_VIS thread;
friend struct _LIBCPP_TEMPLATE_VIS hash<__thread_id>;
};
namespace this_thread
{
inline _LIBCPP_INLINE_VISIBILITY
__thread_id
get_id() _NOEXCEPT
{
return __libcpp_thread_get_current_id();
}
} // this_thread
#endif // !_LIBCPP_HAS_NO_THREADS
_LIBCPP_END_NAMESPACE_STD
_LIBCPP_POP_MACROS
#endif // _LIBCPP_THREADING_SUPPORT
| 13,612 | 494 | jart/cosmopolitan | false |
cosmopolitan/third_party/libcxx/ctgmath | // -*- C++ -*-
// clang-format off
//===-------------------------- ctgmath -----------------------------------===//
//
// 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_CTGMATH
#define _LIBCPP_CTGMATH
/*
ctgmath synopsis
#include "third_party/libcxx/ccomplex"
#include "third_party/libcxx/cmath"
*/
#include "third_party/libcxx/ccomplex"
#include "third_party/libcxx/cmath"
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
#pragma GCC system_header
#endif
#endif // _LIBCPP_CTGMATH
| 746 | 30 | jart/cosmopolitan | false |
cosmopolitan/third_party/libcxx/valarray | // -*- C++ -*-
// clang-format off
//===-------------------------- valarray ----------------------------------===//
//
// 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_VALARRAY
#define _LIBCPP_VALARRAY
/*
valarray synopsis
namespace std
{
template<class T>
class valarray
{
public:
typedef T value_type;
// construct/destroy:
valarray();
explicit valarray(size_t n);
valarray(const value_type& x, size_t n);
valarray(const value_type* px, size_t n);
valarray(const valarray& v);
valarray(valarray&& v) noexcept;
valarray(const slice_array<value_type>& sa);
valarray(const gslice_array<value_type>& ga);
valarray(const mask_array<value_type>& ma);
valarray(const indirect_array<value_type>& ia);
valarray(initializer_list<value_type> il);
~valarray();
// assignment:
valarray& operator=(const valarray& v);
valarray& operator=(valarray&& v) noexcept;
valarray& operator=(initializer_list<value_type> il);
valarray& operator=(const value_type& x);
valarray& operator=(const slice_array<value_type>& sa);
valarray& operator=(const gslice_array<value_type>& ga);
valarray& operator=(const mask_array<value_type>& ma);
valarray& operator=(const indirect_array<value_type>& ia);
// element access:
const value_type& operator[](size_t i) const;
value_type& operator[](size_t i);
// subset operations:
valarray operator[](slice s) const;
slice_array<value_type> operator[](slice s);
valarray operator[](const gslice& gs) const;
gslice_array<value_type> operator[](const gslice& gs);
valarray operator[](const valarray<bool>& vb) const;
mask_array<value_type> operator[](const valarray<bool>& vb);
valarray operator[](const valarray<size_t>& vs) const;
indirect_array<value_type> operator[](const valarray<size_t>& vs);
// unary operators:
valarray operator+() const;
valarray operator-() const;
valarray operator~() const;
valarray<bool> operator!() const;
// computed assignment:
valarray& operator*= (const value_type& x);
valarray& operator/= (const value_type& x);
valarray& operator%= (const value_type& x);
valarray& operator+= (const value_type& x);
valarray& operator-= (const value_type& x);
valarray& operator^= (const value_type& x);
valarray& operator&= (const value_type& x);
valarray& operator|= (const value_type& x);
valarray& operator<<=(const value_type& x);
valarray& operator>>=(const value_type& x);
valarray& operator*= (const valarray& v);
valarray& operator/= (const valarray& v);
valarray& operator%= (const valarray& v);
valarray& operator+= (const valarray& v);
valarray& operator-= (const valarray& v);
valarray& operator^= (const valarray& v);
valarray& operator|= (const valarray& v);
valarray& operator&= (const valarray& v);
valarray& operator<<=(const valarray& v);
valarray& operator>>=(const valarray& v);
// member functions:
void swap(valarray& v) noexcept;
size_t size() const;
value_type sum() const;
value_type min() const;
value_type max() const;
valarray shift (int i) const;
valarray cshift(int i) const;
valarray apply(value_type f(value_type)) const;
valarray apply(value_type f(const value_type&)) const;
void resize(size_t n, value_type x = value_type());
};
class slice
{
public:
slice();
slice(size_t start, size_t size, size_t stride);
size_t start() const;
size_t size() const;
size_t stride() const;
};
template <class T>
class slice_array
{
public:
typedef T value_type;
const slice_array& operator=(const slice_array& sa) const;
void operator= (const valarray<value_type>& v) const;
void operator*= (const valarray<value_type>& v) const;
void operator/= (const valarray<value_type>& v) const;
void operator%= (const valarray<value_type>& v) const;
void operator+= (const valarray<value_type>& v) const;
void operator-= (const valarray<value_type>& v) const;
void operator^= (const valarray<value_type>& v) const;
void operator&= (const valarray<value_type>& v) const;
void operator|= (const valarray<value_type>& v) const;
void operator<<=(const valarray<value_type>& v) const;
void operator>>=(const valarray<value_type>& v) const;
void operator=(const value_type& x) const;
slice_array() = delete;
};
class gslice
{
public:
gslice();
gslice(size_t start, const valarray<size_t>& size,
const valarray<size_t>& stride);
size_t start() const;
valarray<size_t> size() const;
valarray<size_t> stride() const;
};
template <class T>
class gslice_array
{
public:
typedef T value_type;
void operator= (const valarray<value_type>& v) const;
void operator*= (const valarray<value_type>& v) const;
void operator/= (const valarray<value_type>& v) const;
void operator%= (const valarray<value_type>& v) const;
void operator+= (const valarray<value_type>& v) const;
void operator-= (const valarray<value_type>& v) const;
void operator^= (const valarray<value_type>& v) const;
void operator&= (const valarray<value_type>& v) const;
void operator|= (const valarray<value_type>& v) const;
void operator<<=(const valarray<value_type>& v) const;
void operator>>=(const valarray<value_type>& v) const;
gslice_array(const gslice_array& ga);
~gslice_array();
const gslice_array& operator=(const gslice_array& ga) const;
void operator=(const value_type& x) const;
gslice_array() = delete;
};
template <class T>
class mask_array
{
public:
typedef T value_type;
void operator= (const valarray<value_type>& v) const;
void operator*= (const valarray<value_type>& v) const;
void operator/= (const valarray<value_type>& v) const;
void operator%= (const valarray<value_type>& v) const;
void operator+= (const valarray<value_type>& v) const;
void operator-= (const valarray<value_type>& v) const;
void operator^= (const valarray<value_type>& v) const;
void operator&= (const valarray<value_type>& v) const;
void operator|= (const valarray<value_type>& v) const;
void operator<<=(const valarray<value_type>& v) const;
void operator>>=(const valarray<value_type>& v) const;
mask_array(const mask_array& ma);
~mask_array();
const mask_array& operator=(const mask_array& ma) const;
void operator=(const value_type& x) const;
mask_array() = delete;
};
template <class T>
class indirect_array
{
public:
typedef T value_type;
void operator= (const valarray<value_type>& v) const;
void operator*= (const valarray<value_type>& v) const;
void operator/= (const valarray<value_type>& v) const;
void operator%= (const valarray<value_type>& v) const;
void operator+= (const valarray<value_type>& v) const;
void operator-= (const valarray<value_type>& v) const;
void operator^= (const valarray<value_type>& v) const;
void operator&= (const valarray<value_type>& v) const;
void operator|= (const valarray<value_type>& v) const;
void operator<<=(const valarray<value_type>& v) const;
void operator>>=(const valarray<value_type>& v) const;
indirect_array(const indirect_array& ia);
~indirect_array();
const indirect_array& operator=(const indirect_array& ia) const;
void operator=(const value_type& x) const;
indirect_array() = delete;
};
template<class T> void swap(valarray<T>& x, valarray<T>& y) noexcept;
template<class T> valarray<T> operator* (const valarray<T>& x, const valarray<T>& y);
template<class T> valarray<T> operator* (const valarray<T>& x, const T& y);
template<class T> valarray<T> operator* (const T& x, const valarray<T>& y);
template<class T> valarray<T> operator/ (const valarray<T>& x, const valarray<T>& y);
template<class T> valarray<T> operator/ (const valarray<T>& x, const T& y);
template<class T> valarray<T> operator/ (const T& x, const valarray<T>& y);
template<class T> valarray<T> operator% (const valarray<T>& x, const valarray<T>& y);
template<class T> valarray<T> operator% (const valarray<T>& x, const T& y);
template<class T> valarray<T> operator% (const T& x, const valarray<T>& y);
template<class T> valarray<T> operator+ (const valarray<T>& x, const valarray<T>& y);
template<class T> valarray<T> operator+ (const valarray<T>& x, const T& y);
template<class T> valarray<T> operator+ (const T& x, const valarray<T>& y);
template<class T> valarray<T> operator- (const valarray<T>& x, const valarray<T>& y);
template<class T> valarray<T> operator- (const valarray<T>& x, const T& y);
template<class T> valarray<T> operator- (const T& x, const valarray<T>& y);
template<class T> valarray<T> operator^ (const valarray<T>& x, const valarray<T>& y);
template<class T> valarray<T> operator^ (const valarray<T>& x, const T& y);
template<class T> valarray<T> operator^ (const T& x, const valarray<T>& y);
template<class T> valarray<T> operator& (const valarray<T>& x, const valarray<T>& y);
template<class T> valarray<T> operator& (const valarray<T>& x, const T& y);
template<class T> valarray<T> operator& (const T& x, const valarray<T>& y);
template<class T> valarray<T> operator| (const valarray<T>& x, const valarray<T>& y);
template<class T> valarray<T> operator| (const valarray<T>& x, const T& y);
template<class T> valarray<T> operator| (const T& x, const valarray<T>& y);
template<class T> valarray<T> operator<<(const valarray<T>& x, const valarray<T>& y);
template<class T> valarray<T> operator<<(const valarray<T>& x, const T& y);
template<class T> valarray<T> operator<<(const T& x, const valarray<T>& y);
template<class T> valarray<T> operator>>(const valarray<T>& x, const valarray<T>& y);
template<class T> valarray<T> operator>>(const valarray<T>& x, const T& y);
template<class T> valarray<T> operator>>(const T& x, const valarray<T>& y);
template<class T> valarray<bool> operator&&(const valarray<T>& x, const valarray<T>& y);
template<class T> valarray<bool> operator&&(const valarray<T>& x, const T& y);
template<class T> valarray<bool> operator&&(const T& x, const valarray<T>& y);
template<class T> valarray<bool> operator||(const valarray<T>& x, const valarray<T>& y);
template<class T> valarray<bool> operator||(const valarray<T>& x, const T& y);
template<class T> valarray<bool> operator||(const T& x, const valarray<T>& y);
template<class T> valarray<bool> operator==(const valarray<T>& x, const valarray<T>& y);
template<class T> valarray<bool> operator==(const valarray<T>& x, const T& y);
template<class T> valarray<bool> operator==(const T& x, const valarray<T>& y);
template<class T> valarray<bool> operator!=(const valarray<T>& x, const valarray<T>& y);
template<class T> valarray<bool> operator!=(const valarray<T>& x, const T& y);
template<class T> valarray<bool> operator!=(const T& x, const valarray<T>& y);
template<class T> valarray<bool> operator< (const valarray<T>& x, const valarray<T>& y);
template<class T> valarray<bool> operator< (const valarray<T>& x, const T& y);
template<class T> valarray<bool> operator< (const T& x, const valarray<T>& y);
template<class T> valarray<bool> operator> (const valarray<T>& x, const valarray<T>& y);
template<class T> valarray<bool> operator> (const valarray<T>& x, const T& y);
template<class T> valarray<bool> operator> (const T& x, const valarray<T>& y);
template<class T> valarray<bool> operator<=(const valarray<T>& x, const valarray<T>& y);
template<class T> valarray<bool> operator<=(const valarray<T>& x, const T& y);
template<class T> valarray<bool> operator<=(const T& x, const valarray<T>& y);
template<class T> valarray<bool> operator>=(const valarray<T>& x, const valarray<T>& y);
template<class T> valarray<bool> operator>=(const valarray<T>& x, const T& y);
template<class T> valarray<bool> operator>=(const T& x, const valarray<T>& y);
template<class T> valarray<T> abs (const valarray<T>& x);
template<class T> valarray<T> acos (const valarray<T>& x);
template<class T> valarray<T> asin (const valarray<T>& x);
template<class T> valarray<T> atan (const valarray<T>& x);
template<class T> valarray<T> atan2(const valarray<T>& x, const valarray<T>& y);
template<class T> valarray<T> atan2(const valarray<T>& x, const T& y);
template<class T> valarray<T> atan2(const T& x, const valarray<T>& y);
template<class T> valarray<T> cos (const valarray<T>& x);
template<class T> valarray<T> cosh (const valarray<T>& x);
template<class T> valarray<T> exp (const valarray<T>& x);
template<class T> valarray<T> log (const valarray<T>& x);
template<class T> valarray<T> log10(const valarray<T>& x);
template<class T> valarray<T> pow(const valarray<T>& x, const valarray<T>& y);
template<class T> valarray<T> pow(const valarray<T>& x, const T& y);
template<class T> valarray<T> pow(const T& x, const valarray<T>& y);
template<class T> valarray<T> sin (const valarray<T>& x);
template<class T> valarray<T> sinh (const valarray<T>& x);
template<class T> valarray<T> sqrt (const valarray<T>& x);
template<class T> valarray<T> tan (const valarray<T>& x);
template<class T> valarray<T> tanh (const valarray<T>& x);
template <class T> unspecified1 begin(valarray<T>& v);
template <class T> unspecified2 begin(const valarray<T>& v);
template <class T> unspecified1 end(valarray<T>& v);
template <class T> unspecified2 end(const valarray<T>& v);
} // std
*/
#include "third_party/libcxx/__config"
#include "third_party/libcxx/cstddef"
#include "third_party/libcxx/cmath"
#include "third_party/libcxx/initializer_list"
#include "third_party/libcxx/algorithm"
#include "third_party/libcxx/functional"
#include "third_party/libcxx/new"
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
#pragma GCC system_header
#endif
_LIBCPP_PUSH_MACROS
// MISSING #include <__undef_macros>
_LIBCPP_BEGIN_NAMESPACE_STD
template<class _Tp> class _LIBCPP_TEMPLATE_VIS valarray;
class _LIBCPP_TEMPLATE_VIS slice
{
size_t __start_;
size_t __size_;
size_t __stride_;
public:
_LIBCPP_INLINE_VISIBILITY
slice()
: __start_(0),
__size_(0),
__stride_(0)
{}
_LIBCPP_INLINE_VISIBILITY
slice(size_t __start, size_t __size, size_t __stride)
: __start_(__start),
__size_(__size),
__stride_(__stride)
{}
_LIBCPP_INLINE_VISIBILITY size_t start() const {return __start_;}
_LIBCPP_INLINE_VISIBILITY size_t size() const {return __size_;}
_LIBCPP_INLINE_VISIBILITY size_t stride() const {return __stride_;}
};
template <class _Tp> class _LIBCPP_TEMPLATE_VIS slice_array;
class _LIBCPP_TYPE_VIS gslice;
template <class _Tp> class _LIBCPP_TEMPLATE_VIS gslice_array;
template <class _Tp> class _LIBCPP_TEMPLATE_VIS mask_array;
template <class _Tp> class _LIBCPP_TEMPLATE_VIS indirect_array;
template <class _Tp>
_LIBCPP_INLINE_VISIBILITY
_Tp*
begin(valarray<_Tp>& __v);
template <class _Tp>
_LIBCPP_INLINE_VISIBILITY
const _Tp*
begin(const valarray<_Tp>& __v);
template <class _Tp>
_LIBCPP_INLINE_VISIBILITY
_Tp*
end(valarray<_Tp>& __v);
template <class _Tp>
_LIBCPP_INLINE_VISIBILITY
const _Tp*
end(const valarray<_Tp>& __v);
template <class _Op, class _A0>
struct _UnaryOp
{
typedef typename _Op::result_type result_type;
typedef typename _A0::value_type value_type;
_Op __op_;
_A0 __a0_;
_LIBCPP_INLINE_VISIBILITY
_UnaryOp(const _Op& __op, const _A0& __a0) : __op_(__op), __a0_(__a0) {}
_LIBCPP_INLINE_VISIBILITY
result_type operator[](size_t __i) const {return __op_(__a0_[__i]);}
_LIBCPP_INLINE_VISIBILITY
size_t size() const {return __a0_.size();}
};
template <class _Op, class _A0, class _A1>
struct _BinaryOp
{
typedef typename _Op::result_type result_type;
typedef typename _A0::value_type value_type;
_Op __op_;
_A0 __a0_;
_A1 __a1_;
_LIBCPP_INLINE_VISIBILITY
_BinaryOp(const _Op& __op, const _A0& __a0, const _A1& __a1)
: __op_(__op), __a0_(__a0), __a1_(__a1) {}
_LIBCPP_INLINE_VISIBILITY
value_type operator[](size_t __i) const {return __op_(__a0_[__i], __a1_[__i]);}
_LIBCPP_INLINE_VISIBILITY
size_t size() const {return __a0_.size();}
};
template <class _Tp>
class __scalar_expr
{
public:
typedef _Tp value_type;
typedef const _Tp& result_type;
private:
const value_type& __t_;
size_t __s_;
public:
_LIBCPP_INLINE_VISIBILITY
explicit __scalar_expr(const value_type& __t, size_t __s) : __t_(__t), __s_(__s) {}
_LIBCPP_INLINE_VISIBILITY
result_type operator[](size_t) const {return __t_;}
_LIBCPP_INLINE_VISIBILITY
size_t size() const {return __s_;}
};
template <class _Tp>
struct __unary_plus : unary_function<_Tp, _Tp>
{
_LIBCPP_INLINE_VISIBILITY
_Tp operator()(const _Tp& __x) const
{return +__x;}
};
template <class _Tp>
struct __bit_not : unary_function<_Tp, _Tp>
{
_LIBCPP_INLINE_VISIBILITY
_Tp operator()(const _Tp& __x) const
{return ~__x;}
};
template <class _Tp>
struct __bit_shift_left : binary_function<_Tp, _Tp, _Tp>
{
_LIBCPP_INLINE_VISIBILITY
_Tp operator()(const _Tp& __x, const _Tp& __y) const
{return __x << __y;}
};
template <class _Tp>
struct __bit_shift_right : binary_function<_Tp, _Tp, _Tp>
{
_LIBCPP_INLINE_VISIBILITY
_Tp operator()(const _Tp& __x, const _Tp& __y) const
{return __x >> __y;}
};
template <class _Tp, class _Fp>
struct __apply_expr : unary_function<_Tp, _Tp>
{
private:
_Fp __f_;
public:
_LIBCPP_INLINE_VISIBILITY
explicit __apply_expr(_Fp __f) : __f_(__f) {}
_LIBCPP_INLINE_VISIBILITY
_Tp operator()(const _Tp& __x) const
{return __f_(__x);}
};
template <class _Tp>
struct __abs_expr : unary_function<_Tp, _Tp>
{
_LIBCPP_INLINE_VISIBILITY
_Tp operator()(const _Tp& __x) const
{return abs(__x);}
};
template <class _Tp>
struct __acos_expr : unary_function<_Tp, _Tp>
{
_LIBCPP_INLINE_VISIBILITY
_Tp operator()(const _Tp& __x) const
{return acos(__x);}
};
template <class _Tp>
struct __asin_expr : unary_function<_Tp, _Tp>
{
_LIBCPP_INLINE_VISIBILITY
_Tp operator()(const _Tp& __x) const
{return asin(__x);}
};
template <class _Tp>
struct __atan_expr : unary_function<_Tp, _Tp>
{
_LIBCPP_INLINE_VISIBILITY
_Tp operator()(const _Tp& __x) const
{return atan(__x);}
};
template <class _Tp>
struct __atan2_expr : binary_function<_Tp, _Tp, _Tp>
{
_LIBCPP_INLINE_VISIBILITY
_Tp operator()(const _Tp& __x, const _Tp& __y) const
{return atan2(__x, __y);}
};
template <class _Tp>
struct __cos_expr : unary_function<_Tp, _Tp>
{
_LIBCPP_INLINE_VISIBILITY
_Tp operator()(const _Tp& __x) const
{return cos(__x);}
};
template <class _Tp>
struct __cosh_expr : unary_function<_Tp, _Tp>
{
_LIBCPP_INLINE_VISIBILITY
_Tp operator()(const _Tp& __x) const
{return cosh(__x);}
};
template <class _Tp>
struct __exp_expr : unary_function<_Tp, _Tp>
{
_LIBCPP_INLINE_VISIBILITY
_Tp operator()(const _Tp& __x) const
{return exp(__x);}
};
template <class _Tp>
struct __log_expr : unary_function<_Tp, _Tp>
{
_LIBCPP_INLINE_VISIBILITY
_Tp operator()(const _Tp& __x) const
{return log(__x);}
};
template <class _Tp>
struct __log10_expr : unary_function<_Tp, _Tp>
{
_LIBCPP_INLINE_VISIBILITY
_Tp operator()(const _Tp& __x) const
{return log10(__x);}
};
template <class _Tp>
struct __pow_expr : binary_function<_Tp, _Tp, _Tp>
{
_LIBCPP_INLINE_VISIBILITY
_Tp operator()(const _Tp& __x, const _Tp& __y) const
{return pow(__x, __y);}
};
template <class _Tp>
struct __sin_expr : unary_function<_Tp, _Tp>
{
_LIBCPP_INLINE_VISIBILITY
_Tp operator()(const _Tp& __x) const
{return sin(__x);}
};
template <class _Tp>
struct __sinh_expr : unary_function<_Tp, _Tp>
{
_LIBCPP_INLINE_VISIBILITY
_Tp operator()(const _Tp& __x) const
{return sinh(__x);}
};
template <class _Tp>
struct __sqrt_expr : unary_function<_Tp, _Tp>
{
_LIBCPP_INLINE_VISIBILITY
_Tp operator()(const _Tp& __x) const
{return sqrt(__x);}
};
template <class _Tp>
struct __tan_expr : unary_function<_Tp, _Tp>
{
_LIBCPP_INLINE_VISIBILITY
_Tp operator()(const _Tp& __x) const
{return tan(__x);}
};
template <class _Tp>
struct __tanh_expr : unary_function<_Tp, _Tp>
{
_LIBCPP_INLINE_VISIBILITY
_Tp operator()(const _Tp& __x) const
{return tanh(__x);}
};
template <class _ValExpr>
class __slice_expr
{
typedef typename remove_reference<_ValExpr>::type _RmExpr;
public:
typedef typename _RmExpr::value_type value_type;
typedef value_type result_type;
private:
_ValExpr __expr_;
size_t __start_;
size_t __size_;
size_t __stride_;
_LIBCPP_INLINE_VISIBILITY
__slice_expr(const slice& __sl, const _RmExpr& __e)
: __expr_(__e),
__start_(__sl.start()),
__size_(__sl.size()),
__stride_(__sl.stride())
{}
public:
_LIBCPP_INLINE_VISIBILITY
result_type operator[](size_t __i) const
{return __expr_[__start_ + __i * __stride_];}
_LIBCPP_INLINE_VISIBILITY
size_t size() const {return __size_;}
template <class> friend class __val_expr;
template <class> friend class _LIBCPP_TEMPLATE_VIS valarray;
};
template <class _ValExpr>
class __mask_expr;
template <class _ValExpr>
class __indirect_expr;
template <class _ValExpr>
class __shift_expr
{
typedef typename remove_reference<_ValExpr>::type _RmExpr;
public:
typedef typename _RmExpr::value_type value_type;
typedef value_type result_type;
private:
_ValExpr __expr_;
size_t __size_;
ptrdiff_t __ul_;
ptrdiff_t __sn_;
ptrdiff_t __n_;
static const ptrdiff_t _Np = static_cast<ptrdiff_t>(
sizeof(ptrdiff_t) * __CHAR_BIT__ - 1);
_LIBCPP_INLINE_VISIBILITY
__shift_expr(int __n, const _RmExpr& __e)
: __expr_(__e),
__size_(__e.size()),
__n_(__n)
{
ptrdiff_t __neg_n = static_cast<ptrdiff_t>(__n_ >> _Np);
__sn_ = __neg_n | static_cast<ptrdiff_t>(static_cast<size_t>(-__n_) >> _Np);
__ul_ = ((__size_ - __n_) & ~__neg_n) | ((__n_ + 1) & __neg_n);
}
public:
_LIBCPP_INLINE_VISIBILITY
result_type operator[](size_t __j) const
{
ptrdiff_t __i = static_cast<ptrdiff_t>(__j);
ptrdiff_t __m = (__sn_ * __i - __ul_) >> _Np;
return (__expr_[(__i + __n_) & __m] & __m) | (value_type() & ~__m);
}
_LIBCPP_INLINE_VISIBILITY
size_t size() const {return __size_;}
template <class> friend class __val_expr;
};
template <class _ValExpr>
class __cshift_expr
{
typedef typename remove_reference<_ValExpr>::type _RmExpr;
public:
typedef typename _RmExpr::value_type value_type;
typedef value_type result_type;
private:
_ValExpr __expr_;
size_t __size_;
size_t __m_;
size_t __o1_;
size_t __o2_;
_LIBCPP_INLINE_VISIBILITY
__cshift_expr(int __n, const _RmExpr& __e)
: __expr_(__e),
__size_(__e.size())
{
__n %= static_cast<int>(__size_);
if (__n >= 0)
{
__m_ = __size_ - __n;
__o1_ = __n;
__o2_ = __n - __size_;
}
else
{
__m_ = -__n;
__o1_ = __n + __size_;
__o2_ = __n;
}
}
public:
_LIBCPP_INLINE_VISIBILITY
result_type operator[](size_t __i) const
{
if (__i < __m_)
return __expr_[__i + __o1_];
return __expr_[__i + __o2_];
}
_LIBCPP_INLINE_VISIBILITY
size_t size() const {return __size_;}
template <class> friend class __val_expr;
};
template<class _ValExpr>
class __val_expr;
template<class _ValExpr>
struct __is_val_expr : false_type {};
template<class _ValExpr>
struct __is_val_expr<__val_expr<_ValExpr> > : true_type {};
template<class _Tp>
struct __is_val_expr<valarray<_Tp> > : true_type {};
template<class _Tp>
class _LIBCPP_TEMPLATE_VIS valarray
{
public:
typedef _Tp value_type;
typedef _Tp result_type;
private:
value_type* __begin_;
value_type* __end_;
public:
// construct/destroy:
_LIBCPP_INLINE_VISIBILITY
valarray() : __begin_(0), __end_(0) {}
inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1
explicit valarray(size_t __n);
_LIBCPP_INLINE_VISIBILITY
valarray(const value_type& __x, size_t __n);
valarray(const value_type* __p, size_t __n);
valarray(const valarray& __v);
#ifndef _LIBCPP_CXX03_LANG
_LIBCPP_INLINE_VISIBILITY
valarray(valarray&& __v) _NOEXCEPT;
valarray(initializer_list<value_type> __il);
#endif // _LIBCPP_CXX03_LANG
valarray(const slice_array<value_type>& __sa);
valarray(const gslice_array<value_type>& __ga);
valarray(const mask_array<value_type>& __ma);
valarray(const indirect_array<value_type>& __ia);
inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1
~valarray();
// assignment:
valarray& operator=(const valarray& __v);
#ifndef _LIBCPP_CXX03_LANG
_LIBCPP_INLINE_VISIBILITY
valarray& operator=(valarray&& __v) _NOEXCEPT;
_LIBCPP_INLINE_VISIBILITY
valarray& operator=(initializer_list<value_type>);
#endif // _LIBCPP_CXX03_LANG
_LIBCPP_INLINE_VISIBILITY
valarray& operator=(const value_type& __x);
_LIBCPP_INLINE_VISIBILITY
valarray& operator=(const slice_array<value_type>& __sa);
_LIBCPP_INLINE_VISIBILITY
valarray& operator=(const gslice_array<value_type>& __ga);
_LIBCPP_INLINE_VISIBILITY
valarray& operator=(const mask_array<value_type>& __ma);
_LIBCPP_INLINE_VISIBILITY
valarray& operator=(const indirect_array<value_type>& __ia);
template <class _ValExpr>
_LIBCPP_INLINE_VISIBILITY
valarray& operator=(const __val_expr<_ValExpr>& __v);
// element access:
_LIBCPP_INLINE_VISIBILITY
const value_type& operator[](size_t __i) const {return __begin_[__i];}
_LIBCPP_INLINE_VISIBILITY
value_type& operator[](size_t __i) {return __begin_[__i];}
// subset operations:
_LIBCPP_INLINE_VISIBILITY
__val_expr<__slice_expr<const valarray&> > operator[](slice __s) const;
_LIBCPP_INLINE_VISIBILITY
slice_array<value_type> operator[](slice __s);
_LIBCPP_INLINE_VISIBILITY
__val_expr<__indirect_expr<const valarray&> > operator[](const gslice& __gs) const;
_LIBCPP_INLINE_VISIBILITY
gslice_array<value_type> operator[](const gslice& __gs);
#ifndef _LIBCPP_CXX03_LANG
_LIBCPP_INLINE_VISIBILITY
__val_expr<__indirect_expr<const valarray&> > operator[](gslice&& __gs) const;
_LIBCPP_INLINE_VISIBILITY
gslice_array<value_type> operator[](gslice&& __gs);
#endif // _LIBCPP_CXX03_LANG
_LIBCPP_INLINE_VISIBILITY
__val_expr<__mask_expr<const valarray&> > operator[](const valarray<bool>& __vb) const;
_LIBCPP_INLINE_VISIBILITY
mask_array<value_type> operator[](const valarray<bool>& __vb);
#ifndef _LIBCPP_CXX03_LANG
_LIBCPP_INLINE_VISIBILITY
__val_expr<__mask_expr<const valarray&> > operator[](valarray<bool>&& __vb) const;
_LIBCPP_INLINE_VISIBILITY
mask_array<value_type> operator[](valarray<bool>&& __vb);
#endif // _LIBCPP_CXX03_LANG
_LIBCPP_INLINE_VISIBILITY
__val_expr<__indirect_expr<const valarray&> > operator[](const valarray<size_t>& __vs) const;
_LIBCPP_INLINE_VISIBILITY
indirect_array<value_type> operator[](const valarray<size_t>& __vs);
#ifndef _LIBCPP_CXX03_LANG
_LIBCPP_INLINE_VISIBILITY
__val_expr<__indirect_expr<const valarray&> > operator[](valarray<size_t>&& __vs) const;
_LIBCPP_INLINE_VISIBILITY
indirect_array<value_type> operator[](valarray<size_t>&& __vs);
#endif // _LIBCPP_CXX03_LANG
// unary operators:
valarray operator+() const;
valarray operator-() const;
valarray operator~() const;
valarray<bool> operator!() const;
// computed assignment:
_LIBCPP_INLINE_VISIBILITY
valarray& operator*= (const value_type& __x);
_LIBCPP_INLINE_VISIBILITY
valarray& operator/= (const value_type& __x);
_LIBCPP_INLINE_VISIBILITY
valarray& operator%= (const value_type& __x);
_LIBCPP_INLINE_VISIBILITY
valarray& operator+= (const value_type& __x);
_LIBCPP_INLINE_VISIBILITY
valarray& operator-= (const value_type& __x);
_LIBCPP_INLINE_VISIBILITY
valarray& operator^= (const value_type& __x);
_LIBCPP_INLINE_VISIBILITY
valarray& operator&= (const value_type& __x);
_LIBCPP_INLINE_VISIBILITY
valarray& operator|= (const value_type& __x);
_LIBCPP_INLINE_VISIBILITY
valarray& operator<<=(const value_type& __x);
_LIBCPP_INLINE_VISIBILITY
valarray& operator>>=(const value_type& __x);
template <class _Expr>
typename enable_if
<
__is_val_expr<_Expr>::value,
valarray&
>::type
_LIBCPP_INLINE_VISIBILITY
operator*= (const _Expr& __v);
template <class _Expr>
typename enable_if
<
__is_val_expr<_Expr>::value,
valarray&
>::type
_LIBCPP_INLINE_VISIBILITY
operator/= (const _Expr& __v);
template <class _Expr>
typename enable_if
<
__is_val_expr<_Expr>::value,
valarray&
>::type
_LIBCPP_INLINE_VISIBILITY
operator%= (const _Expr& __v);
template <class _Expr>
typename enable_if
<
__is_val_expr<_Expr>::value,
valarray&
>::type
_LIBCPP_INLINE_VISIBILITY
operator+= (const _Expr& __v);
template <class _Expr>
typename enable_if
<
__is_val_expr<_Expr>::value,
valarray&
>::type
_LIBCPP_INLINE_VISIBILITY
operator-= (const _Expr& __v);
template <class _Expr>
typename enable_if
<
__is_val_expr<_Expr>::value,
valarray&
>::type
_LIBCPP_INLINE_VISIBILITY
operator^= (const _Expr& __v);
template <class _Expr>
typename enable_if
<
__is_val_expr<_Expr>::value,
valarray&
>::type
_LIBCPP_INLINE_VISIBILITY
operator|= (const _Expr& __v);
template <class _Expr>
typename enable_if
<
__is_val_expr<_Expr>::value,
valarray&
>::type
_LIBCPP_INLINE_VISIBILITY
operator&= (const _Expr& __v);
template <class _Expr>
typename enable_if
<
__is_val_expr<_Expr>::value,
valarray&
>::type
_LIBCPP_INLINE_VISIBILITY
operator<<= (const _Expr& __v);
template <class _Expr>
typename enable_if
<
__is_val_expr<_Expr>::value,
valarray&
>::type
_LIBCPP_INLINE_VISIBILITY
operator>>= (const _Expr& __v);
// member functions:
_LIBCPP_INLINE_VISIBILITY
void swap(valarray& __v) _NOEXCEPT;
_LIBCPP_INLINE_VISIBILITY
size_t size() const {return static_cast<size_t>(__end_ - __begin_);}
_LIBCPP_INLINE_VISIBILITY
value_type sum() const;
_LIBCPP_INLINE_VISIBILITY
value_type min() const;
_LIBCPP_INLINE_VISIBILITY
value_type max() const;
valarray shift (int __i) const;
valarray cshift(int __i) const;
valarray apply(value_type __f(value_type)) const;
valarray apply(value_type __f(const value_type&)) const;
void resize(size_t __n, value_type __x = value_type());
private:
template <class> friend class _LIBCPP_TEMPLATE_VIS valarray;
template <class> friend class _LIBCPP_TEMPLATE_VIS slice_array;
template <class> friend class _LIBCPP_TEMPLATE_VIS gslice_array;
template <class> friend class _LIBCPP_TEMPLATE_VIS mask_array;
template <class> friend class __mask_expr;
template <class> friend class _LIBCPP_TEMPLATE_VIS indirect_array;
template <class> friend class __indirect_expr;
template <class> friend class __val_expr;
template <class _Up>
friend
_Up*
begin(valarray<_Up>& __v);
template <class _Up>
friend
const _Up*
begin(const valarray<_Up>& __v);
template <class _Up>
friend
_Up*
end(valarray<_Up>& __v);
template <class _Up>
friend
const _Up*
end(const valarray<_Up>& __v);
_LIBCPP_INLINE_VISIBILITY
void __clear(size_t __capacity);
valarray& __assign_range(const value_type* __f, const value_type* __l);
};
_LIBCPP_EXTERN_TEMPLATE(_LIBCPP_FUNC_VIS void valarray<size_t>::resize(size_t, size_t))
template <class _Op, class _Tp>
struct _UnaryOp<_Op, valarray<_Tp> >
{
typedef typename _Op::result_type result_type;
typedef _Tp value_type;
_Op __op_;
const valarray<_Tp>& __a0_;
_LIBCPP_INLINE_VISIBILITY
_UnaryOp(const _Op& __op, const valarray<_Tp>& __a0) : __op_(__op), __a0_(__a0) {}
_LIBCPP_INLINE_VISIBILITY
result_type operator[](size_t __i) const {return __op_(__a0_[__i]);}
_LIBCPP_INLINE_VISIBILITY
size_t size() const {return __a0_.size();}
};
template <class _Op, class _Tp, class _A1>
struct _BinaryOp<_Op, valarray<_Tp>, _A1>
{
typedef typename _Op::result_type result_type;
typedef _Tp value_type;
_Op __op_;
const valarray<_Tp>& __a0_;
_A1 __a1_;
_LIBCPP_INLINE_VISIBILITY
_BinaryOp(const _Op& __op, const valarray<_Tp>& __a0, const _A1& __a1)
: __op_(__op), __a0_(__a0), __a1_(__a1) {}
_LIBCPP_INLINE_VISIBILITY
value_type operator[](size_t __i) const {return __op_(__a0_[__i], __a1_[__i]);}
_LIBCPP_INLINE_VISIBILITY
size_t size() const {return __a0_.size();}
};
template <class _Op, class _A0, class _Tp>
struct _BinaryOp<_Op, _A0, valarray<_Tp> >
{
typedef typename _Op::result_type result_type;
typedef _Tp value_type;
_Op __op_;
_A0 __a0_;
const valarray<_Tp>& __a1_;
_LIBCPP_INLINE_VISIBILITY
_BinaryOp(const _Op& __op, const _A0& __a0, const valarray<_Tp>& __a1)
: __op_(__op), __a0_(__a0), __a1_(__a1) {}
_LIBCPP_INLINE_VISIBILITY
value_type operator[](size_t __i) const {return __op_(__a0_[__i], __a1_[__i]);}
_LIBCPP_INLINE_VISIBILITY
size_t size() const {return __a0_.size();}
};
template <class _Op, class _Tp>
struct _BinaryOp<_Op, valarray<_Tp>, valarray<_Tp> >
{
typedef typename _Op::result_type result_type;
typedef _Tp value_type;
_Op __op_;
const valarray<_Tp>& __a0_;
const valarray<_Tp>& __a1_;
_LIBCPP_INLINE_VISIBILITY
_BinaryOp(const _Op& __op, const valarray<_Tp>& __a0, const valarray<_Tp>& __a1)
: __op_(__op), __a0_(__a0), __a1_(__a1) {}
_LIBCPP_INLINE_VISIBILITY
value_type operator[](size_t __i) const {return __op_(__a0_[__i], __a1_[__i]);}
_LIBCPP_INLINE_VISIBILITY
size_t size() const {return __a0_.size();}
};
// slice_array
template <class _Tp>
class _LIBCPP_TEMPLATE_VIS slice_array
{
public:
typedef _Tp value_type;
private:
value_type* __vp_;
size_t __size_;
size_t __stride_;
public:
template <class _Expr>
typename enable_if
<
__is_val_expr<_Expr>::value,
void
>::type
_LIBCPP_INLINE_VISIBILITY
operator=(const _Expr& __v) const;
template <class _Expr>
typename enable_if
<
__is_val_expr<_Expr>::value,
void
>::type
_LIBCPP_INLINE_VISIBILITY
operator*=(const _Expr& __v) const;
template <class _Expr>
typename enable_if
<
__is_val_expr<_Expr>::value,
void
>::type
_LIBCPP_INLINE_VISIBILITY
operator/=(const _Expr& __v) const;
template <class _Expr>
typename enable_if
<
__is_val_expr<_Expr>::value,
void
>::type
_LIBCPP_INLINE_VISIBILITY
operator%=(const _Expr& __v) const;
template <class _Expr>
typename enable_if
<
__is_val_expr<_Expr>::value,
void
>::type
_LIBCPP_INLINE_VISIBILITY
operator+=(const _Expr& __v) const;
template <class _Expr>
typename enable_if
<
__is_val_expr<_Expr>::value,
void
>::type
_LIBCPP_INLINE_VISIBILITY
operator-=(const _Expr& __v) const;
template <class _Expr>
typename enable_if
<
__is_val_expr<_Expr>::value,
void
>::type
_LIBCPP_INLINE_VISIBILITY
operator^=(const _Expr& __v) const;
template <class _Expr>
typename enable_if
<
__is_val_expr<_Expr>::value,
void
>::type
_LIBCPP_INLINE_VISIBILITY
operator&=(const _Expr& __v) const;
template <class _Expr>
typename enable_if
<
__is_val_expr<_Expr>::value,
void
>::type
_LIBCPP_INLINE_VISIBILITY
operator|=(const _Expr& __v) const;
template <class _Expr>
typename enable_if
<
__is_val_expr<_Expr>::value,
void
>::type
_LIBCPP_INLINE_VISIBILITY
operator<<=(const _Expr& __v) const;
template <class _Expr>
typename enable_if
<
__is_val_expr<_Expr>::value,
void
>::type
_LIBCPP_INLINE_VISIBILITY
operator>>=(const _Expr& __v) const;
_LIBCPP_INLINE_VISIBILITY
const slice_array& operator=(const slice_array& __sa) const;
_LIBCPP_INLINE_VISIBILITY
void operator=(const value_type& __x) const;
private:
_LIBCPP_INLINE_VISIBILITY
slice_array(const slice& __sl, const valarray<value_type>& __v)
: __vp_(const_cast<value_type*>(__v.__begin_ + __sl.start())),
__size_(__sl.size()),
__stride_(__sl.stride())
{}
template <class> friend class valarray;
template <class> friend class sliceExpr;
};
template <class _Tp>
inline
const slice_array<_Tp>&
slice_array<_Tp>::operator=(const slice_array& __sa) const
{
value_type* __t = __vp_;
const value_type* __s = __sa.__vp_;
for (size_t __n = __size_; __n; --__n, __t += __stride_, __s += __sa.__stride_)
*__t = *__s;
return *this;
}
template <class _Tp>
template <class _Expr>
inline
typename enable_if
<
__is_val_expr<_Expr>::value,
void
>::type
slice_array<_Tp>::operator=(const _Expr& __v) const
{
value_type* __t = __vp_;
for (size_t __i = 0; __i < __size_; ++__i, __t += __stride_)
*__t = __v[__i];
}
template <class _Tp>
template <class _Expr>
inline
typename enable_if
<
__is_val_expr<_Expr>::value,
void
>::type
slice_array<_Tp>::operator*=(const _Expr& __v) const
{
value_type* __t = __vp_;
for (size_t __i = 0; __i < __size_; ++__i, __t += __stride_)
*__t *= __v[__i];
}
template <class _Tp>
template <class _Expr>
inline
typename enable_if
<
__is_val_expr<_Expr>::value,
void
>::type
slice_array<_Tp>::operator/=(const _Expr& __v) const
{
value_type* __t = __vp_;
for (size_t __i = 0; __i < __size_; ++__i, __t += __stride_)
*__t /= __v[__i];
}
template <class _Tp>
template <class _Expr>
inline
typename enable_if
<
__is_val_expr<_Expr>::value,
void
>::type
slice_array<_Tp>::operator%=(const _Expr& __v) const
{
value_type* __t = __vp_;
for (size_t __i = 0; __i < __size_; ++__i, __t += __stride_)
*__t %= __v[__i];
}
template <class _Tp>
template <class _Expr>
inline
typename enable_if
<
__is_val_expr<_Expr>::value,
void
>::type
slice_array<_Tp>::operator+=(const _Expr& __v) const
{
value_type* __t = __vp_;
for (size_t __i = 0; __i < __size_; ++__i, __t += __stride_)
*__t += __v[__i];
}
template <class _Tp>
template <class _Expr>
inline
typename enable_if
<
__is_val_expr<_Expr>::value,
void
>::type
slice_array<_Tp>::operator-=(const _Expr& __v) const
{
value_type* __t = __vp_;
for (size_t __i = 0; __i < __size_; ++__i, __t += __stride_)
*__t -= __v[__i];
}
template <class _Tp>
template <class _Expr>
inline
typename enable_if
<
__is_val_expr<_Expr>::value,
void
>::type
slice_array<_Tp>::operator^=(const _Expr& __v) const
{
value_type* __t = __vp_;
for (size_t __i = 0; __i < __size_; ++__i, __t += __stride_)
*__t ^= __v[__i];
}
template <class _Tp>
template <class _Expr>
inline
typename enable_if
<
__is_val_expr<_Expr>::value,
void
>::type
slice_array<_Tp>::operator&=(const _Expr& __v) const
{
value_type* __t = __vp_;
for (size_t __i = 0; __i < __size_; ++__i, __t += __stride_)
*__t &= __v[__i];
}
template <class _Tp>
template <class _Expr>
inline
typename enable_if
<
__is_val_expr<_Expr>::value,
void
>::type
slice_array<_Tp>::operator|=(const _Expr& __v) const
{
value_type* __t = __vp_;
for (size_t __i = 0; __i < __size_; ++__i, __t += __stride_)
*__t |= __v[__i];
}
template <class _Tp>
template <class _Expr>
inline
typename enable_if
<
__is_val_expr<_Expr>::value,
void
>::type
slice_array<_Tp>::operator<<=(const _Expr& __v) const
{
value_type* __t = __vp_;
for (size_t __i = 0; __i < __size_; ++__i, __t += __stride_)
*__t <<= __v[__i];
}
template <class _Tp>
template <class _Expr>
inline
typename enable_if
<
__is_val_expr<_Expr>::value,
void
>::type
slice_array<_Tp>::operator>>=(const _Expr& __v) const
{
value_type* __t = __vp_;
for (size_t __i = 0; __i < __size_; ++__i, __t += __stride_)
*__t >>= __v[__i];
}
template <class _Tp>
inline
void
slice_array<_Tp>::operator=(const value_type& __x) const
{
value_type* __t = __vp_;
for (size_t __n = __size_; __n; --__n, __t += __stride_)
*__t = __x;
}
// gslice
class _LIBCPP_TYPE_VIS gslice
{
valarray<size_t> __size_;
valarray<size_t> __stride_;
valarray<size_t> __1d_;
public:
_LIBCPP_INLINE_VISIBILITY
gslice() {}
_LIBCPP_INLINE_VISIBILITY
gslice(size_t __start, const valarray<size_t>& __size,
const valarray<size_t>& __stride)
: __size_(__size),
__stride_(__stride)
{__init(__start);}
#ifndef _LIBCPP_CXX03_LANG
_LIBCPP_INLINE_VISIBILITY
gslice(size_t __start, const valarray<size_t>& __size,
valarray<size_t>&& __stride)
: __size_(__size),
__stride_(move(__stride))
{__init(__start);}
_LIBCPP_INLINE_VISIBILITY
gslice(size_t __start, valarray<size_t>&& __size,
const valarray<size_t>& __stride)
: __size_(move(__size)),
__stride_(__stride)
{__init(__start);}
_LIBCPP_INLINE_VISIBILITY
gslice(size_t __start, valarray<size_t>&& __size,
valarray<size_t>&& __stride)
: __size_(move(__size)),
__stride_(move(__stride))
{__init(__start);}
#endif // _LIBCPP_CXX03_LANG
// gslice(const gslice&) = default;
// gslice(gslice&&) = default;
// gslice& operator=(const gslice&) = default;
// gslice& operator=(gslice&&) = default;
_LIBCPP_INLINE_VISIBILITY
size_t start() const {return __1d_.size() ? __1d_[0] : 0;}
_LIBCPP_INLINE_VISIBILITY
valarray<size_t> size() const {return __size_;}
_LIBCPP_INLINE_VISIBILITY
valarray<size_t> stride() const {return __stride_;}
private:
void __init(size_t __start);
template <class> friend class gslice_array;
template <class> friend class valarray;
template <class> friend class __val_expr;
};
// gslice_array
template <class _Tp>
class _LIBCPP_TEMPLATE_VIS gslice_array
{
public:
typedef _Tp value_type;
private:
value_type* __vp_;
valarray<size_t> __1d_;
public:
template <class _Expr>
typename enable_if
<
__is_val_expr<_Expr>::value,
void
>::type
_LIBCPP_INLINE_VISIBILITY
operator=(const _Expr& __v) const;
template <class _Expr>
typename enable_if
<
__is_val_expr<_Expr>::value,
void
>::type
_LIBCPP_INLINE_VISIBILITY
operator*=(const _Expr& __v) const;
template <class _Expr>
typename enable_if
<
__is_val_expr<_Expr>::value,
void
>::type
_LIBCPP_INLINE_VISIBILITY
operator/=(const _Expr& __v) const;
template <class _Expr>
typename enable_if
<
__is_val_expr<_Expr>::value,
void
>::type
_LIBCPP_INLINE_VISIBILITY
operator%=(const _Expr& __v) const;
template <class _Expr>
typename enable_if
<
__is_val_expr<_Expr>::value,
void
>::type
_LIBCPP_INLINE_VISIBILITY
operator+=(const _Expr& __v) const;
template <class _Expr>
typename enable_if
<
__is_val_expr<_Expr>::value,
void
>::type
_LIBCPP_INLINE_VISIBILITY
operator-=(const _Expr& __v) const;
template <class _Expr>
typename enable_if
<
__is_val_expr<_Expr>::value,
void
>::type
_LIBCPP_INLINE_VISIBILITY
operator^=(const _Expr& __v) const;
template <class _Expr>
typename enable_if
<
__is_val_expr<_Expr>::value,
void
>::type
_LIBCPP_INLINE_VISIBILITY
operator&=(const _Expr& __v) const;
template <class _Expr>
typename enable_if
<
__is_val_expr<_Expr>::value,
void
>::type
_LIBCPP_INLINE_VISIBILITY
operator|=(const _Expr& __v) const;
template <class _Expr>
typename enable_if
<
__is_val_expr<_Expr>::value,
void
>::type
_LIBCPP_INLINE_VISIBILITY
operator<<=(const _Expr& __v) const;
template <class _Expr>
typename enable_if
<
__is_val_expr<_Expr>::value,
void
>::type
_LIBCPP_INLINE_VISIBILITY
operator>>=(const _Expr& __v) const;
_LIBCPP_INLINE_VISIBILITY
const gslice_array& operator=(const gslice_array& __ga) const;
_LIBCPP_INLINE_VISIBILITY
void operator=(const value_type& __x) const;
// gslice_array(const gslice_array&) = default;
// gslice_array(gslice_array&&) = default;
// gslice_array& operator=(const gslice_array&) = default;
// gslice_array& operator=(gslice_array&&) = default;
private:
gslice_array(const gslice& __gs, const valarray<value_type>& __v)
: __vp_(const_cast<value_type*>(__v.__begin_)),
__1d_(__gs.__1d_)
{}
#ifndef _LIBCPP_CXX03_LANG
gslice_array(gslice&& __gs, const valarray<value_type>& __v)
: __vp_(const_cast<value_type*>(__v.__begin_)),
__1d_(move(__gs.__1d_))
{}
#endif // _LIBCPP_CXX03_LANG
template <class> friend class valarray;
};
template <class _Tp>
template <class _Expr>
inline
typename enable_if
<
__is_val_expr<_Expr>::value,
void
>::type
gslice_array<_Tp>::operator=(const _Expr& __v) const
{
typedef const size_t* _Ip;
size_t __j = 0;
for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i, ++__j)
__vp_[*__i] = __v[__j];
}
template <class _Tp>
template <class _Expr>
inline
typename enable_if
<
__is_val_expr<_Expr>::value,
void
>::type
gslice_array<_Tp>::operator*=(const _Expr& __v) const
{
typedef const size_t* _Ip;
size_t __j = 0;
for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i, ++__j)
__vp_[*__i] *= __v[__j];
}
template <class _Tp>
template <class _Expr>
inline
typename enable_if
<
__is_val_expr<_Expr>::value,
void
>::type
gslice_array<_Tp>::operator/=(const _Expr& __v) const
{
typedef const size_t* _Ip;
size_t __j = 0;
for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i, ++__j)
__vp_[*__i] /= __v[__j];
}
template <class _Tp>
template <class _Expr>
inline
typename enable_if
<
__is_val_expr<_Expr>::value,
void
>::type
gslice_array<_Tp>::operator%=(const _Expr& __v) const
{
typedef const size_t* _Ip;
size_t __j = 0;
for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i, ++__j)
__vp_[*__i] %= __v[__j];
}
template <class _Tp>
template <class _Expr>
inline
typename enable_if
<
__is_val_expr<_Expr>::value,
void
>::type
gslice_array<_Tp>::operator+=(const _Expr& __v) const
{
typedef const size_t* _Ip;
size_t __j = 0;
for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i, ++__j)
__vp_[*__i] += __v[__j];
}
template <class _Tp>
template <class _Expr>
inline
typename enable_if
<
__is_val_expr<_Expr>::value,
void
>::type
gslice_array<_Tp>::operator-=(const _Expr& __v) const
{
typedef const size_t* _Ip;
size_t __j = 0;
for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i, ++__j)
__vp_[*__i] -= __v[__j];
}
template <class _Tp>
template <class _Expr>
inline
typename enable_if
<
__is_val_expr<_Expr>::value,
void
>::type
gslice_array<_Tp>::operator^=(const _Expr& __v) const
{
typedef const size_t* _Ip;
size_t __j = 0;
for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i, ++__j)
__vp_[*__i] ^= __v[__j];
}
template <class _Tp>
template <class _Expr>
inline
typename enable_if
<
__is_val_expr<_Expr>::value,
void
>::type
gslice_array<_Tp>::operator&=(const _Expr& __v) const
{
typedef const size_t* _Ip;
size_t __j = 0;
for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i, ++__j)
__vp_[*__i] &= __v[__j];
}
template <class _Tp>
template <class _Expr>
inline
typename enable_if
<
__is_val_expr<_Expr>::value,
void
>::type
gslice_array<_Tp>::operator|=(const _Expr& __v) const
{
typedef const size_t* _Ip;
size_t __j = 0;
for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i, ++__j)
__vp_[*__i] |= __v[__j];
}
template <class _Tp>
template <class _Expr>
inline
typename enable_if
<
__is_val_expr<_Expr>::value,
void
>::type
gslice_array<_Tp>::operator<<=(const _Expr& __v) const
{
typedef const size_t* _Ip;
size_t __j = 0;
for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i, ++__j)
__vp_[*__i] <<= __v[__j];
}
template <class _Tp>
template <class _Expr>
inline
typename enable_if
<
__is_val_expr<_Expr>::value,
void
>::type
gslice_array<_Tp>::operator>>=(const _Expr& __v) const
{
typedef const size_t* _Ip;
size_t __j = 0;
for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i, ++__j)
__vp_[*__i] >>= __v[__j];
}
template <class _Tp>
inline
const gslice_array<_Tp>&
gslice_array<_Tp>::operator=(const gslice_array& __ga) const
{
typedef const size_t* _Ip;
const value_type* __s = __ga.__vp_;
for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_, __j = __ga.__1d_.__begin_;
__i != __e; ++__i, ++__j)
__vp_[*__i] = __s[*__j];
return *this;
}
template <class _Tp>
inline
void
gslice_array<_Tp>::operator=(const value_type& __x) const
{
typedef const size_t* _Ip;
for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i)
__vp_[*__i] = __x;
}
// mask_array
template <class _Tp>
class _LIBCPP_TEMPLATE_VIS mask_array
{
public:
typedef _Tp value_type;
private:
value_type* __vp_;
valarray<size_t> __1d_;
public:
template <class _Expr>
typename enable_if
<
__is_val_expr<_Expr>::value,
void
>::type
_LIBCPP_INLINE_VISIBILITY
operator=(const _Expr& __v) const;
template <class _Expr>
typename enable_if
<
__is_val_expr<_Expr>::value,
void
>::type
_LIBCPP_INLINE_VISIBILITY
operator*=(const _Expr& __v) const;
template <class _Expr>
typename enable_if
<
__is_val_expr<_Expr>::value,
void
>::type
_LIBCPP_INLINE_VISIBILITY
operator/=(const _Expr& __v) const;
template <class _Expr>
typename enable_if
<
__is_val_expr<_Expr>::value,
void
>::type
_LIBCPP_INLINE_VISIBILITY
operator%=(const _Expr& __v) const;
template <class _Expr>
typename enable_if
<
__is_val_expr<_Expr>::value,
void
>::type
_LIBCPP_INLINE_VISIBILITY
operator+=(const _Expr& __v) const;
template <class _Expr>
typename enable_if
<
__is_val_expr<_Expr>::value,
void
>::type
_LIBCPP_INLINE_VISIBILITY
operator-=(const _Expr& __v) const;
template <class _Expr>
typename enable_if
<
__is_val_expr<_Expr>::value,
void
>::type
_LIBCPP_INLINE_VISIBILITY
operator^=(const _Expr& __v) const;
template <class _Expr>
typename enable_if
<
__is_val_expr<_Expr>::value,
void
>::type
_LIBCPP_INLINE_VISIBILITY
operator&=(const _Expr& __v) const;
template <class _Expr>
typename enable_if
<
__is_val_expr<_Expr>::value,
void
>::type
_LIBCPP_INLINE_VISIBILITY
operator|=(const _Expr& __v) const;
template <class _Expr>
typename enable_if
<
__is_val_expr<_Expr>::value,
void
>::type
_LIBCPP_INLINE_VISIBILITY
operator<<=(const _Expr& __v) const;
template <class _Expr>
typename enable_if
<
__is_val_expr<_Expr>::value,
void
>::type
_LIBCPP_INLINE_VISIBILITY
operator>>=(const _Expr& __v) const;
_LIBCPP_INLINE_VISIBILITY
const mask_array& operator=(const mask_array& __ma) const;
_LIBCPP_INLINE_VISIBILITY
void operator=(const value_type& __x) const;
// mask_array(const mask_array&) = default;
// mask_array(mask_array&&) = default;
// mask_array& operator=(const mask_array&) = default;
// mask_array& operator=(mask_array&&) = default;
private:
_LIBCPP_INLINE_VISIBILITY
mask_array(const valarray<bool>& __vb, const valarray<value_type>& __v)
: __vp_(const_cast<value_type*>(__v.__begin_)),
__1d_(static_cast<size_t>(count(__vb.__begin_, __vb.__end_, true)))
{
size_t __j = 0;
for (size_t __i = 0; __i < __vb.size(); ++__i)
if (__vb[__i])
__1d_[__j++] = __i;
}
template <class> friend class valarray;
};
template <class _Tp>
template <class _Expr>
inline
typename enable_if
<
__is_val_expr<_Expr>::value,
void
>::type
mask_array<_Tp>::operator=(const _Expr& __v) const
{
size_t __n = __1d_.size();
for (size_t __i = 0; __i < __n; ++__i)
__vp_[__1d_[__i]] = __v[__i];
}
template <class _Tp>
template <class _Expr>
inline
typename enable_if
<
__is_val_expr<_Expr>::value,
void
>::type
mask_array<_Tp>::operator*=(const _Expr& __v) const
{
size_t __n = __1d_.size();
for (size_t __i = 0; __i < __n; ++__i)
__vp_[__1d_[__i]] *= __v[__i];
}
template <class _Tp>
template <class _Expr>
inline
typename enable_if
<
__is_val_expr<_Expr>::value,
void
>::type
mask_array<_Tp>::operator/=(const _Expr& __v) const
{
size_t __n = __1d_.size();
for (size_t __i = 0; __i < __n; ++__i)
__vp_[__1d_[__i]] /= __v[__i];
}
template <class _Tp>
template <class _Expr>
inline
typename enable_if
<
__is_val_expr<_Expr>::value,
void
>::type
mask_array<_Tp>::operator%=(const _Expr& __v) const
{
size_t __n = __1d_.size();
for (size_t __i = 0; __i < __n; ++__i)
__vp_[__1d_[__i]] %= __v[__i];
}
template <class _Tp>
template <class _Expr>
inline
typename enable_if
<
__is_val_expr<_Expr>::value,
void
>::type
mask_array<_Tp>::operator+=(const _Expr& __v) const
{
size_t __n = __1d_.size();
for (size_t __i = 0; __i < __n; ++__i)
__vp_[__1d_[__i]] += __v[__i];
}
template <class _Tp>
template <class _Expr>
inline
typename enable_if
<
__is_val_expr<_Expr>::value,
void
>::type
mask_array<_Tp>::operator-=(const _Expr& __v) const
{
size_t __n = __1d_.size();
for (size_t __i = 0; __i < __n; ++__i)
__vp_[__1d_[__i]] -= __v[__i];
}
template <class _Tp>
template <class _Expr>
inline
typename enable_if
<
__is_val_expr<_Expr>::value,
void
>::type
mask_array<_Tp>::operator^=(const _Expr& __v) const
{
size_t __n = __1d_.size();
for (size_t __i = 0; __i < __n; ++__i)
__vp_[__1d_[__i]] ^= __v[__i];
}
template <class _Tp>
template <class _Expr>
inline
typename enable_if
<
__is_val_expr<_Expr>::value,
void
>::type
mask_array<_Tp>::operator&=(const _Expr& __v) const
{
size_t __n = __1d_.size();
for (size_t __i = 0; __i < __n; ++__i)
__vp_[__1d_[__i]] &= __v[__i];
}
template <class _Tp>
template <class _Expr>
inline
typename enable_if
<
__is_val_expr<_Expr>::value,
void
>::type
mask_array<_Tp>::operator|=(const _Expr& __v) const
{
size_t __n = __1d_.size();
for (size_t __i = 0; __i < __n; ++__i)
__vp_[__1d_[__i]] |= __v[__i];
}
template <class _Tp>
template <class _Expr>
inline
typename enable_if
<
__is_val_expr<_Expr>::value,
void
>::type
mask_array<_Tp>::operator<<=(const _Expr& __v) const
{
size_t __n = __1d_.size();
for (size_t __i = 0; __i < __n; ++__i)
__vp_[__1d_[__i]] <<= __v[__i];
}
template <class _Tp>
template <class _Expr>
inline
typename enable_if
<
__is_val_expr<_Expr>::value,
void
>::type
mask_array<_Tp>::operator>>=(const _Expr& __v) const
{
size_t __n = __1d_.size();
for (size_t __i = 0; __i < __n; ++__i)
__vp_[__1d_[__i]] >>= __v[__i];
}
template <class _Tp>
inline
const mask_array<_Tp>&
mask_array<_Tp>::operator=(const mask_array& __ma) const
{
size_t __n = __1d_.size();
for (size_t __i = 0; __i < __n; ++__i)
__vp_[__1d_[__i]] = __ma.__vp_[__1d_[__i]];
return *this;
}
template <class _Tp>
inline
void
mask_array<_Tp>::operator=(const value_type& __x) const
{
size_t __n = __1d_.size();
for (size_t __i = 0; __i < __n; ++__i)
__vp_[__1d_[__i]] = __x;
}
template <class _ValExpr>
class __mask_expr
{
typedef typename remove_reference<_ValExpr>::type _RmExpr;
public:
typedef typename _RmExpr::value_type value_type;
typedef value_type result_type;
private:
_ValExpr __expr_;
valarray<size_t> __1d_;
_LIBCPP_INLINE_VISIBILITY
__mask_expr(const valarray<bool>& __vb, const _RmExpr& __e)
: __expr_(__e),
__1d_(static_cast<size_t>(count(__vb.__begin_, __vb.__end_, true)))
{
size_t __j = 0;
for (size_t __i = 0; __i < __vb.size(); ++__i)
if (__vb[__i])
__1d_[__j++] = __i;
}
public:
_LIBCPP_INLINE_VISIBILITY
result_type operator[](size_t __i) const
{return __expr_[__1d_[__i]];}
_LIBCPP_INLINE_VISIBILITY
size_t size() const {return __1d_.size();}
template <class> friend class __val_expr;
template <class> friend class valarray;
};
// indirect_array
template <class _Tp>
class _LIBCPP_TEMPLATE_VIS indirect_array
{
public:
typedef _Tp value_type;
private:
value_type* __vp_;
valarray<size_t> __1d_;
public:
template <class _Expr>
typename enable_if
<
__is_val_expr<_Expr>::value,
void
>::type
_LIBCPP_INLINE_VISIBILITY
operator=(const _Expr& __v) const;
template <class _Expr>
typename enable_if
<
__is_val_expr<_Expr>::value,
void
>::type
_LIBCPP_INLINE_VISIBILITY
operator*=(const _Expr& __v) const;
template <class _Expr>
typename enable_if
<
__is_val_expr<_Expr>::value,
void
>::type
_LIBCPP_INLINE_VISIBILITY
operator/=(const _Expr& __v) const;
template <class _Expr>
typename enable_if
<
__is_val_expr<_Expr>::value,
void
>::type
_LIBCPP_INLINE_VISIBILITY
operator%=(const _Expr& __v) const;
template <class _Expr>
typename enable_if
<
__is_val_expr<_Expr>::value,
void
>::type
_LIBCPP_INLINE_VISIBILITY
operator+=(const _Expr& __v) const;
template <class _Expr>
typename enable_if
<
__is_val_expr<_Expr>::value,
void
>::type
_LIBCPP_INLINE_VISIBILITY
operator-=(const _Expr& __v) const;
template <class _Expr>
typename enable_if
<
__is_val_expr<_Expr>::value,
void
>::type
_LIBCPP_INLINE_VISIBILITY
operator^=(const _Expr& __v) const;
template <class _Expr>
typename enable_if
<
__is_val_expr<_Expr>::value,
void
>::type
_LIBCPP_INLINE_VISIBILITY
operator&=(const _Expr& __v) const;
template <class _Expr>
typename enable_if
<
__is_val_expr<_Expr>::value,
void
>::type
_LIBCPP_INLINE_VISIBILITY
operator|=(const _Expr& __v) const;
template <class _Expr>
typename enable_if
<
__is_val_expr<_Expr>::value,
void
>::type
_LIBCPP_INLINE_VISIBILITY
operator<<=(const _Expr& __v) const;
template <class _Expr>
typename enable_if
<
__is_val_expr<_Expr>::value,
void
>::type
_LIBCPP_INLINE_VISIBILITY
operator>>=(const _Expr& __v) const;
_LIBCPP_INLINE_VISIBILITY
const indirect_array& operator=(const indirect_array& __ia) const;
_LIBCPP_INLINE_VISIBILITY
void operator=(const value_type& __x) const;
// indirect_array(const indirect_array&) = default;
// indirect_array(indirect_array&&) = default;
// indirect_array& operator=(const indirect_array&) = default;
// indirect_array& operator=(indirect_array&&) = default;
private:
_LIBCPP_INLINE_VISIBILITY
indirect_array(const valarray<size_t>& __ia, const valarray<value_type>& __v)
: __vp_(const_cast<value_type*>(__v.__begin_)),
__1d_(__ia)
{}
#ifndef _LIBCPP_CXX03_LANG
_LIBCPP_INLINE_VISIBILITY
indirect_array(valarray<size_t>&& __ia, const valarray<value_type>& __v)
: __vp_(const_cast<value_type*>(__v.__begin_)),
__1d_(move(__ia))
{}
#endif // _LIBCPP_CXX03_LANG
template <class> friend class valarray;
};
template <class _Tp>
template <class _Expr>
inline
typename enable_if
<
__is_val_expr<_Expr>::value,
void
>::type
indirect_array<_Tp>::operator=(const _Expr& __v) const
{
size_t __n = __1d_.size();
for (size_t __i = 0; __i < __n; ++__i)
__vp_[__1d_[__i]] = __v[__i];
}
template <class _Tp>
template <class _Expr>
inline
typename enable_if
<
__is_val_expr<_Expr>::value,
void
>::type
indirect_array<_Tp>::operator*=(const _Expr& __v) const
{
size_t __n = __1d_.size();
for (size_t __i = 0; __i < __n; ++__i)
__vp_[__1d_[__i]] *= __v[__i];
}
template <class _Tp>
template <class _Expr>
inline
typename enable_if
<
__is_val_expr<_Expr>::value,
void
>::type
indirect_array<_Tp>::operator/=(const _Expr& __v) const
{
size_t __n = __1d_.size();
for (size_t __i = 0; __i < __n; ++__i)
__vp_[__1d_[__i]] /= __v[__i];
}
template <class _Tp>
template <class _Expr>
inline
typename enable_if
<
__is_val_expr<_Expr>::value,
void
>::type
indirect_array<_Tp>::operator%=(const _Expr& __v) const
{
size_t __n = __1d_.size();
for (size_t __i = 0; __i < __n; ++__i)
__vp_[__1d_[__i]] %= __v[__i];
}
template <class _Tp>
template <class _Expr>
inline
typename enable_if
<
__is_val_expr<_Expr>::value,
void
>::type
indirect_array<_Tp>::operator+=(const _Expr& __v) const
{
size_t __n = __1d_.size();
for (size_t __i = 0; __i < __n; ++__i)
__vp_[__1d_[__i]] += __v[__i];
}
template <class _Tp>
template <class _Expr>
inline
typename enable_if
<
__is_val_expr<_Expr>::value,
void
>::type
indirect_array<_Tp>::operator-=(const _Expr& __v) const
{
size_t __n = __1d_.size();
for (size_t __i = 0; __i < __n; ++__i)
__vp_[__1d_[__i]] -= __v[__i];
}
template <class _Tp>
template <class _Expr>
inline
typename enable_if
<
__is_val_expr<_Expr>::value,
void
>::type
indirect_array<_Tp>::operator^=(const _Expr& __v) const
{
size_t __n = __1d_.size();
for (size_t __i = 0; __i < __n; ++__i)
__vp_[__1d_[__i]] ^= __v[__i];
}
template <class _Tp>
template <class _Expr>
inline
typename enable_if
<
__is_val_expr<_Expr>::value,
void
>::type
indirect_array<_Tp>::operator&=(const _Expr& __v) const
{
size_t __n = __1d_.size();
for (size_t __i = 0; __i < __n; ++__i)
__vp_[__1d_[__i]] &= __v[__i];
}
template <class _Tp>
template <class _Expr>
inline
typename enable_if
<
__is_val_expr<_Expr>::value,
void
>::type
indirect_array<_Tp>::operator|=(const _Expr& __v) const
{
size_t __n = __1d_.size();
for (size_t __i = 0; __i < __n; ++__i)
__vp_[__1d_[__i]] |= __v[__i];
}
template <class _Tp>
template <class _Expr>
inline
typename enable_if
<
__is_val_expr<_Expr>::value,
void
>::type
indirect_array<_Tp>::operator<<=(const _Expr& __v) const
{
size_t __n = __1d_.size();
for (size_t __i = 0; __i < __n; ++__i)
__vp_[__1d_[__i]] <<= __v[__i];
}
template <class _Tp>
template <class _Expr>
inline
typename enable_if
<
__is_val_expr<_Expr>::value,
void
>::type
indirect_array<_Tp>::operator>>=(const _Expr& __v) const
{
size_t __n = __1d_.size();
for (size_t __i = 0; __i < __n; ++__i)
__vp_[__1d_[__i]] >>= __v[__i];
}
template <class _Tp>
inline
const indirect_array<_Tp>&
indirect_array<_Tp>::operator=(const indirect_array& __ia) const
{
typedef const size_t* _Ip;
const value_type* __s = __ia.__vp_;
for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_, __j = __ia.__1d_.__begin_;
__i != __e; ++__i, ++__j)
__vp_[*__i] = __s[*__j];
return *this;
}
template <class _Tp>
inline
void
indirect_array<_Tp>::operator=(const value_type& __x) const
{
typedef const size_t* _Ip;
for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i)
__vp_[*__i] = __x;
}
template <class _ValExpr>
class __indirect_expr
{
typedef typename remove_reference<_ValExpr>::type _RmExpr;
public:
typedef typename _RmExpr::value_type value_type;
typedef value_type result_type;
private:
_ValExpr __expr_;
valarray<size_t> __1d_;
_LIBCPP_INLINE_VISIBILITY
__indirect_expr(const valarray<size_t>& __ia, const _RmExpr& __e)
: __expr_(__e),
__1d_(__ia)
{}
#ifndef _LIBCPP_CXX03_LANG
_LIBCPP_INLINE_VISIBILITY
__indirect_expr(valarray<size_t>&& __ia, const _RmExpr& __e)
: __expr_(__e),
__1d_(move(__ia))
{}
#endif // _LIBCPP_CXX03_LANG
public:
_LIBCPP_INLINE_VISIBILITY
result_type operator[](size_t __i) const
{return __expr_[__1d_[__i]];}
_LIBCPP_INLINE_VISIBILITY
size_t size() const {return __1d_.size();}
template <class> friend class __val_expr;
template <class> friend class _LIBCPP_TEMPLATE_VIS valarray;
};
template<class _ValExpr>
class __val_expr
{
typedef typename remove_reference<_ValExpr>::type _RmExpr;
_ValExpr __expr_;
public:
typedef typename _RmExpr::value_type value_type;
typedef typename _RmExpr::result_type result_type;
_LIBCPP_INLINE_VISIBILITY
explicit __val_expr(const _RmExpr& __e) : __expr_(__e) {}
_LIBCPP_INLINE_VISIBILITY
result_type operator[](size_t __i) const
{return __expr_[__i];}
_LIBCPP_INLINE_VISIBILITY
__val_expr<__slice_expr<_ValExpr> > operator[](slice __s) const
{
typedef __slice_expr<_ValExpr> _NewExpr;
return __val_expr< _NewExpr >(_NewExpr(__s, __expr_));
}
_LIBCPP_INLINE_VISIBILITY
__val_expr<__indirect_expr<_ValExpr> > operator[](const gslice& __gs) const
{
typedef __indirect_expr<_ValExpr> _NewExpr;
return __val_expr<_NewExpr >(_NewExpr(__gs.__1d_, __expr_));
}
_LIBCPP_INLINE_VISIBILITY
__val_expr<__mask_expr<_ValExpr> > operator[](const valarray<bool>& __vb) const
{
typedef __mask_expr<_ValExpr> _NewExpr;
return __val_expr< _NewExpr >( _NewExpr(__vb, __expr_));
}
_LIBCPP_INLINE_VISIBILITY
__val_expr<__indirect_expr<_ValExpr> > operator[](const valarray<size_t>& __vs) const
{
typedef __indirect_expr<_ValExpr> _NewExpr;
return __val_expr< _NewExpr >(_NewExpr(__vs, __expr_));
}
_LIBCPP_INLINE_VISIBILITY
__val_expr<_UnaryOp<__unary_plus<value_type>, _ValExpr> >
operator+() const
{
typedef _UnaryOp<__unary_plus<value_type>, _ValExpr> _NewExpr;
return __val_expr<_NewExpr>(_NewExpr(__unary_plus<value_type>(), __expr_));
}
_LIBCPP_INLINE_VISIBILITY
__val_expr<_UnaryOp<negate<value_type>, _ValExpr> >
operator-() const
{
typedef _UnaryOp<negate<value_type>, _ValExpr> _NewExpr;
return __val_expr<_NewExpr>(_NewExpr(negate<value_type>(), __expr_));
}
_LIBCPP_INLINE_VISIBILITY
__val_expr<_UnaryOp<__bit_not<value_type>, _ValExpr> >
operator~() const
{
typedef _UnaryOp<__bit_not<value_type>, _ValExpr> _NewExpr;
return __val_expr<_NewExpr>(_NewExpr(__bit_not<value_type>(), __expr_));
}
_LIBCPP_INLINE_VISIBILITY
__val_expr<_UnaryOp<logical_not<value_type>, _ValExpr> >
operator!() const
{
typedef _UnaryOp<logical_not<value_type>, _ValExpr> _NewExpr;
return __val_expr<_NewExpr>(_NewExpr(logical_not<value_type>(), __expr_));
}
operator valarray<result_type>() const;
_LIBCPP_INLINE_VISIBILITY
size_t size() const {return __expr_.size();}
_LIBCPP_INLINE_VISIBILITY
result_type sum() const
{
size_t __n = __expr_.size();
result_type __r = __n ? __expr_[0] : result_type();
for (size_t __i = 1; __i < __n; ++__i)
__r += __expr_[__i];
return __r;
}
_LIBCPP_INLINE_VISIBILITY
result_type min() const
{
size_t __n = size();
result_type __r = __n ? (*this)[0] : result_type();
for (size_t __i = 1; __i < __n; ++__i)
{
result_type __x = __expr_[__i];
if (__x < __r)
__r = __x;
}
return __r;
}
_LIBCPP_INLINE_VISIBILITY
result_type max() const
{
size_t __n = size();
result_type __r = __n ? (*this)[0] : result_type();
for (size_t __i = 1; __i < __n; ++__i)
{
result_type __x = __expr_[__i];
if (__r < __x)
__r = __x;
}
return __r;
}
_LIBCPP_INLINE_VISIBILITY
__val_expr<__shift_expr<_ValExpr> > shift (int __i) const
{return __val_expr<__shift_expr<_ValExpr> >(__shift_expr<_ValExpr>(__i, __expr_));}
_LIBCPP_INLINE_VISIBILITY
__val_expr<__cshift_expr<_ValExpr> > cshift(int __i) const
{return __val_expr<__cshift_expr<_ValExpr> >(__cshift_expr<_ValExpr>(__i, __expr_));}
_LIBCPP_INLINE_VISIBILITY
__val_expr<_UnaryOp<__apply_expr<value_type, value_type(*)(value_type)>, _ValExpr> >
apply(value_type __f(value_type)) const
{
typedef __apply_expr<value_type, value_type(*)(value_type)> _Op;
typedef _UnaryOp<_Op, _ValExpr> _NewExpr;
return __val_expr<_NewExpr>(_NewExpr(_Op(__f), __expr_));
}
_LIBCPP_INLINE_VISIBILITY
__val_expr<_UnaryOp<__apply_expr<value_type, value_type(*)(const value_type&)>, _ValExpr> >
apply(value_type __f(const value_type&)) const
{
typedef __apply_expr<value_type, value_type(*)(const value_type&)> _Op;
typedef _UnaryOp<_Op, _ValExpr> _NewExpr;
return __val_expr<_NewExpr>(_NewExpr(_Op(__f), __expr_));
}
};
template<class _ValExpr>
__val_expr<_ValExpr>::operator valarray<__val_expr::result_type>() const
{
valarray<result_type> __r;
size_t __n = __expr_.size();
if (__n)
{
__r.__begin_ =
__r.__end_ =
static_cast<result_type*>(
_VSTD::__libcpp_allocate(__n * sizeof(result_type), _LIBCPP_ALIGNOF(result_type)));
for (size_t __i = 0; __i != __n; ++__r.__end_, ++__i)
::new (__r.__end_) result_type(__expr_[__i]);
}
return __r;
}
// valarray
template <class _Tp>
inline
valarray<_Tp>::valarray(size_t __n)
: __begin_(0),
__end_(0)
{
if (__n)
{
__begin_ = __end_ = static_cast<value_type*>(
_VSTD::__libcpp_allocate(__n * sizeof(value_type), _LIBCPP_ALIGNOF(value_type)));
#ifndef _LIBCPP_NO_EXCEPTIONS
try
{
#endif // _LIBCPP_NO_EXCEPTIONS
for (size_t __n_left = __n; __n_left; --__n_left, ++__end_)
::new (__end_) value_type();
#ifndef _LIBCPP_NO_EXCEPTIONS
}
catch (...)
{
__clear(__n);
throw;
}
#endif // _LIBCPP_NO_EXCEPTIONS
}
}
template <class _Tp>
inline
valarray<_Tp>::valarray(const value_type& __x, size_t __n)
: __begin_(0),
__end_(0)
{
resize(__n, __x);
}
template <class _Tp>
valarray<_Tp>::valarray(const value_type* __p, size_t __n)
: __begin_(0),
__end_(0)
{
if (__n)
{
__begin_ = __end_ = static_cast<value_type*>(
_VSTD::__libcpp_allocate(__n * sizeof(value_type), _LIBCPP_ALIGNOF(value_type)));
#ifndef _LIBCPP_NO_EXCEPTIONS
try
{
#endif // _LIBCPP_NO_EXCEPTIONS
for (size_t __n_left = __n; __n_left; ++__end_, ++__p, --__n_left)
::new (__end_) value_type(*__p);
#ifndef _LIBCPP_NO_EXCEPTIONS
}
catch (...)
{
__clear(__n);
throw;
}
#endif // _LIBCPP_NO_EXCEPTIONS
}
}
template <class _Tp>
valarray<_Tp>::valarray(const valarray& __v)
: __begin_(0),
__end_(0)
{
if (__v.size())
{
__begin_ = __end_ = static_cast<value_type*>(
_VSTD::__libcpp_allocate(__v.size() * sizeof(value_type), _LIBCPP_ALIGNOF(value_type)));
#ifndef _LIBCPP_NO_EXCEPTIONS
try
{
#endif // _LIBCPP_NO_EXCEPTIONS
for (value_type* __p = __v.__begin_; __p != __v.__end_; ++__end_, ++__p)
::new (__end_) value_type(*__p);
#ifndef _LIBCPP_NO_EXCEPTIONS
}
catch (...)
{
__clear(__v.size());
throw;
}
#endif // _LIBCPP_NO_EXCEPTIONS
}
}
#ifndef _LIBCPP_CXX03_LANG
template <class _Tp>
inline
valarray<_Tp>::valarray(valarray&& __v) _NOEXCEPT
: __begin_(__v.__begin_),
__end_(__v.__end_)
{
__v.__begin_ = __v.__end_ = nullptr;
}
template <class _Tp>
valarray<_Tp>::valarray(initializer_list<value_type> __il)
: __begin_(0),
__end_(0)
{
const size_t __n = __il.size();
if (__n)
{
__begin_ = __end_ = static_cast<value_type*>(
_VSTD::__libcpp_allocate(__n * sizeof(value_type), _LIBCPP_ALIGNOF(value_type)));
#ifndef _LIBCPP_NO_EXCEPTIONS
try
{
#endif // _LIBCPP_NO_EXCEPTIONS
size_t __n_left = __n;
for (const value_type* __p = __il.begin(); __n_left; ++__end_, ++__p, --__n_left)
::new (__end_) value_type(*__p);
#ifndef _LIBCPP_NO_EXCEPTIONS
}
catch (...)
{
__clear(__n);
throw;
}
#endif // _LIBCPP_NO_EXCEPTIONS
}
}
#endif // _LIBCPP_CXX03_LANG
template <class _Tp>
valarray<_Tp>::valarray(const slice_array<value_type>& __sa)
: __begin_(0),
__end_(0)
{
const size_t __n = __sa.__size_;
if (__n)
{
__begin_ = __end_ = static_cast<value_type*>(
_VSTD::__libcpp_allocate(__n * sizeof(value_type), _LIBCPP_ALIGNOF(value_type)));
#ifndef _LIBCPP_NO_EXCEPTIONS
try
{
#endif // _LIBCPP_NO_EXCEPTIONS
size_t __n_left = __n;
for (const value_type* __p = __sa.__vp_; __n_left; ++__end_, __p += __sa.__stride_, --__n_left)
::new (__end_) value_type(*__p);
#ifndef _LIBCPP_NO_EXCEPTIONS
}
catch (...)
{
__clear(__n);
throw;
}
#endif // _LIBCPP_NO_EXCEPTIONS
}
}
template <class _Tp>
valarray<_Tp>::valarray(const gslice_array<value_type>& __ga)
: __begin_(0),
__end_(0)
{
const size_t __n = __ga.__1d_.size();
if (__n)
{
__begin_ = __end_ = static_cast<value_type*>(
_VSTD::__libcpp_allocate(__n * sizeof(value_type), _LIBCPP_ALIGNOF(value_type)));
#ifndef _LIBCPP_NO_EXCEPTIONS
try
{
#endif // _LIBCPP_NO_EXCEPTIONS
typedef const size_t* _Ip;
const value_type* __s = __ga.__vp_;
for (_Ip __i = __ga.__1d_.__begin_, __e = __ga.__1d_.__end_;
__i != __e; ++__i, ++__end_)
::new (__end_) value_type(__s[*__i]);
#ifndef _LIBCPP_NO_EXCEPTIONS
}
catch (...)
{
__clear(__n);
throw;
}
#endif // _LIBCPP_NO_EXCEPTIONS
}
}
template <class _Tp>
valarray<_Tp>::valarray(const mask_array<value_type>& __ma)
: __begin_(0),
__end_(0)
{
const size_t __n = __ma.__1d_.size();
if (__n)
{
__begin_ = __end_ = static_cast<value_type*>(
_VSTD::__libcpp_allocate(__n * sizeof(value_type), _LIBCPP_ALIGNOF(value_type)));
#ifndef _LIBCPP_NO_EXCEPTIONS
try
{
#endif // _LIBCPP_NO_EXCEPTIONS
typedef const size_t* _Ip;
const value_type* __s = __ma.__vp_;
for (_Ip __i = __ma.__1d_.__begin_, __e = __ma.__1d_.__end_;
__i != __e; ++__i, ++__end_)
::new (__end_) value_type(__s[*__i]);
#ifndef _LIBCPP_NO_EXCEPTIONS
}
catch (...)
{
__clear(__n);
throw;
}
#endif // _LIBCPP_NO_EXCEPTIONS
}
}
template <class _Tp>
valarray<_Tp>::valarray(const indirect_array<value_type>& __ia)
: __begin_(0),
__end_(0)
{
const size_t __n = __ia.__1d_.size();
if (__n)
{
__begin_ = __end_ = static_cast<value_type*>(
_VSTD::__libcpp_allocate(__n * sizeof(value_type), _LIBCPP_ALIGNOF(value_type)));
#ifndef _LIBCPP_NO_EXCEPTIONS
try
{
#endif // _LIBCPP_NO_EXCEPTIONS
typedef const size_t* _Ip;
const value_type* __s = __ia.__vp_;
for (_Ip __i = __ia.__1d_.__begin_, __e = __ia.__1d_.__end_;
__i != __e; ++__i, ++__end_)
::new (__end_) value_type(__s[*__i]);
#ifndef _LIBCPP_NO_EXCEPTIONS
}
catch (...)
{
__clear(__n);
throw;
}
#endif // _LIBCPP_NO_EXCEPTIONS
}
}
template <class _Tp>
inline
valarray<_Tp>::~valarray()
{
__clear(size());
}
template <class _Tp>
valarray<_Tp>&
valarray<_Tp>::__assign_range(const value_type* __f, const value_type* __l)
{
size_t __n = __l - __f;
if (size() != __n)
{
__clear(size());
__begin_ = static_cast<value_type*>(
_VSTD::__libcpp_allocate(__n * sizeof(value_type), _LIBCPP_ALIGNOF(value_type)));
__end_ = __begin_ + __n;
_VSTD::uninitialized_copy(__f, __l, __begin_);
} else {
_VSTD::copy(__f, __l, __begin_);
}
return *this;
}
template <class _Tp>
valarray<_Tp>&
valarray<_Tp>::operator=(const valarray& __v)
{
if (this != &__v)
return __assign_range(__v.__begin_, __v.__end_);
return *this;
}
#ifndef _LIBCPP_CXX03_LANG
template <class _Tp>
inline
valarray<_Tp>&
valarray<_Tp>::operator=(valarray&& __v) _NOEXCEPT
{
__clear(size());
__begin_ = __v.__begin_;
__end_ = __v.__end_;
__v.__begin_ = nullptr;
__v.__end_ = nullptr;
return *this;
}
template <class _Tp>
inline
valarray<_Tp>&
valarray<_Tp>::operator=(initializer_list<value_type> __il)
{
return __assign_range(__il.begin(), __il.end());
}
#endif // _LIBCPP_CXX03_LANG
template <class _Tp>
inline
valarray<_Tp>&
valarray<_Tp>::operator=(const value_type& __x)
{
_VSTD::fill(__begin_, __end_, __x);
return *this;
}
template <class _Tp>
inline
valarray<_Tp>&
valarray<_Tp>::operator=(const slice_array<value_type>& __sa)
{
value_type* __t = __begin_;
const value_type* __s = __sa.__vp_;
for (size_t __n = __sa.__size_; __n; --__n, __s += __sa.__stride_, ++__t)
*__t = *__s;
return *this;
}
template <class _Tp>
inline
valarray<_Tp>&
valarray<_Tp>::operator=(const gslice_array<value_type>& __ga)
{
typedef const size_t* _Ip;
value_type* __t = __begin_;
const value_type* __s = __ga.__vp_;
for (_Ip __i = __ga.__1d_.__begin_, __e = __ga.__1d_.__end_;
__i != __e; ++__i, ++__t)
*__t = __s[*__i];
return *this;
}
template <class _Tp>
inline
valarray<_Tp>&
valarray<_Tp>::operator=(const mask_array<value_type>& __ma)
{
typedef const size_t* _Ip;
value_type* __t = __begin_;
const value_type* __s = __ma.__vp_;
for (_Ip __i = __ma.__1d_.__begin_, __e = __ma.__1d_.__end_;
__i != __e; ++__i, ++__t)
*__t = __s[*__i];
return *this;
}
template <class _Tp>
inline
valarray<_Tp>&
valarray<_Tp>::operator=(const indirect_array<value_type>& __ia)
{
typedef const size_t* _Ip;
value_type* __t = __begin_;
const value_type* __s = __ia.__vp_;
for (_Ip __i = __ia.__1d_.__begin_, __e = __ia.__1d_.__end_;
__i != __e; ++__i, ++__t)
*__t = __s[*__i];
return *this;
}
template <class _Tp>
template <class _ValExpr>
inline
valarray<_Tp>&
valarray<_Tp>::operator=(const __val_expr<_ValExpr>& __v)
{
size_t __n = __v.size();
if (size() != __n)
resize(__n);
value_type* __t = __begin_;
for (size_t __i = 0; __i != __n; ++__t, ++__i)
*__t = result_type(__v[__i]);
return *this;
}
template <class _Tp>
inline
__val_expr<__slice_expr<const valarray<_Tp>&> >
valarray<_Tp>::operator[](slice __s) const
{
return __val_expr<__slice_expr<const valarray&> >(__slice_expr<const valarray&>(__s, *this));
}
template <class _Tp>
inline
slice_array<_Tp>
valarray<_Tp>::operator[](slice __s)
{
return slice_array<value_type>(__s, *this);
}
template <class _Tp>
inline
__val_expr<__indirect_expr<const valarray<_Tp>&> >
valarray<_Tp>::operator[](const gslice& __gs) const
{
return __val_expr<__indirect_expr<const valarray&> >(__indirect_expr<const valarray&>(__gs.__1d_, *this));
}
template <class _Tp>
inline
gslice_array<_Tp>
valarray<_Tp>::operator[](const gslice& __gs)
{
return gslice_array<value_type>(__gs, *this);
}
#ifndef _LIBCPP_CXX03_LANG
template <class _Tp>
inline
__val_expr<__indirect_expr<const valarray<_Tp>&> >
valarray<_Tp>::operator[](gslice&& __gs) const
{
return __val_expr<__indirect_expr<const valarray&> >(__indirect_expr<const valarray&>(move(__gs.__1d_), *this));
}
template <class _Tp>
inline
gslice_array<_Tp>
valarray<_Tp>::operator[](gslice&& __gs)
{
return gslice_array<value_type>(move(__gs), *this);
}
#endif // _LIBCPP_CXX03_LANG
template <class _Tp>
inline
__val_expr<__mask_expr<const valarray<_Tp>&> >
valarray<_Tp>::operator[](const valarray<bool>& __vb) const
{
return __val_expr<__mask_expr<const valarray&> >(__mask_expr<const valarray&>(__vb, *this));
}
template <class _Tp>
inline
mask_array<_Tp>
valarray<_Tp>::operator[](const valarray<bool>& __vb)
{
return mask_array<value_type>(__vb, *this);
}
#ifndef _LIBCPP_CXX03_LANG
template <class _Tp>
inline
__val_expr<__mask_expr<const valarray<_Tp>&> >
valarray<_Tp>::operator[](valarray<bool>&& __vb) const
{
return __val_expr<__mask_expr<const valarray&> >(__mask_expr<const valarray&>(move(__vb), *this));
}
template <class _Tp>
inline
mask_array<_Tp>
valarray<_Tp>::operator[](valarray<bool>&& __vb)
{
return mask_array<value_type>(move(__vb), *this);
}
#endif // _LIBCPP_CXX03_LANG
template <class _Tp>
inline
__val_expr<__indirect_expr<const valarray<_Tp>&> >
valarray<_Tp>::operator[](const valarray<size_t>& __vs) const
{
return __val_expr<__indirect_expr<const valarray&> >(__indirect_expr<const valarray&>(__vs, *this));
}
template <class _Tp>
inline
indirect_array<_Tp>
valarray<_Tp>::operator[](const valarray<size_t>& __vs)
{
return indirect_array<value_type>(__vs, *this);
}
#ifndef _LIBCPP_CXX03_LANG
template <class _Tp>
inline
__val_expr<__indirect_expr<const valarray<_Tp>&> >
valarray<_Tp>::operator[](valarray<size_t>&& __vs) const
{
return __val_expr<__indirect_expr<const valarray&> >(__indirect_expr<const valarray&>(move(__vs), *this));
}
template <class _Tp>
inline
indirect_array<_Tp>
valarray<_Tp>::operator[](valarray<size_t>&& __vs)
{
return indirect_array<value_type>(move(__vs), *this);
}
#endif // _LIBCPP_CXX03_LANG
template <class _Tp>
valarray<_Tp>
valarray<_Tp>::operator+() const
{
valarray<value_type> __r;
size_t __n = size();
if (__n)
{
__r.__begin_ =
__r.__end_ =
static_cast<value_type*>(
_VSTD::__libcpp_allocate(__n * sizeof(value_type), _LIBCPP_ALIGNOF(value_type)));
for (const value_type* __p = __begin_; __n; ++__r.__end_, ++__p, --__n)
::new (__r.__end_) value_type(+*__p);
}
return __r;
}
template <class _Tp>
valarray<_Tp>
valarray<_Tp>::operator-() const
{
valarray<value_type> __r;
size_t __n = size();
if (__n)
{
__r.__begin_ =
__r.__end_ =
static_cast<value_type*>(
_VSTD::__libcpp_allocate(__n * sizeof(value_type), _LIBCPP_ALIGNOF(value_type)));
for (const value_type* __p = __begin_; __n; ++__r.__end_, ++__p, --__n)
::new (__r.__end_) value_type(-*__p);
}
return __r;
}
template <class _Tp>
valarray<_Tp>
valarray<_Tp>::operator~() const
{
valarray<value_type> __r;
size_t __n = size();
if (__n)
{
__r.__begin_ =
__r.__end_ =
static_cast<value_type*>(
_VSTD::__libcpp_allocate(__n * sizeof(value_type), _LIBCPP_ALIGNOF(value_type)));
for (const value_type* __p = __begin_; __n; ++__r.__end_, ++__p, --__n)
::new (__r.__end_) value_type(~*__p);
}
return __r;
}
template <class _Tp>
valarray<bool>
valarray<_Tp>::operator!() const
{
valarray<bool> __r;
size_t __n = size();
if (__n)
{
__r.__begin_ =
__r.__end_ =
static_cast<bool*>(_VSTD::__libcpp_allocate(__n * sizeof(bool), _LIBCPP_ALIGNOF(bool)));
for (const value_type* __p = __begin_; __n; ++__r.__end_, ++__p, --__n)
::new (__r.__end_) bool(!*__p);
}
return __r;
}
template <class _Tp>
inline
valarray<_Tp>&
valarray<_Tp>::operator*=(const value_type& __x)
{
for (value_type* __p = __begin_; __p != __end_; ++__p)
*__p *= __x;
return *this;
}
template <class _Tp>
inline
valarray<_Tp>&
valarray<_Tp>::operator/=(const value_type& __x)
{
for (value_type* __p = __begin_; __p != __end_; ++__p)
*__p /= __x;
return *this;
}
template <class _Tp>
inline
valarray<_Tp>&
valarray<_Tp>::operator%=(const value_type& __x)
{
for (value_type* __p = __begin_; __p != __end_; ++__p)
*__p %= __x;
return *this;
}
template <class _Tp>
inline
valarray<_Tp>&
valarray<_Tp>::operator+=(const value_type& __x)
{
for (value_type* __p = __begin_; __p != __end_; ++__p)
*__p += __x;
return *this;
}
template <class _Tp>
inline
valarray<_Tp>&
valarray<_Tp>::operator-=(const value_type& __x)
{
for (value_type* __p = __begin_; __p != __end_; ++__p)
*__p -= __x;
return *this;
}
template <class _Tp>
inline
valarray<_Tp>&
valarray<_Tp>::operator^=(const value_type& __x)
{
for (value_type* __p = __begin_; __p != __end_; ++__p)
*__p ^= __x;
return *this;
}
template <class _Tp>
inline
valarray<_Tp>&
valarray<_Tp>::operator&=(const value_type& __x)
{
for (value_type* __p = __begin_; __p != __end_; ++__p)
*__p &= __x;
return *this;
}
template <class _Tp>
inline
valarray<_Tp>&
valarray<_Tp>::operator|=(const value_type& __x)
{
for (value_type* __p = __begin_; __p != __end_; ++__p)
*__p |= __x;
return *this;
}
template <class _Tp>
inline
valarray<_Tp>&
valarray<_Tp>::operator<<=(const value_type& __x)
{
for (value_type* __p = __begin_; __p != __end_; ++__p)
*__p <<= __x;
return *this;
}
template <class _Tp>
inline
valarray<_Tp>&
valarray<_Tp>::operator>>=(const value_type& __x)
{
for (value_type* __p = __begin_; __p != __end_; ++__p)
*__p >>= __x;
return *this;
}
template <class _Tp>
template <class _Expr>
inline
typename enable_if
<
__is_val_expr<_Expr>::value,
valarray<_Tp>&
>::type
valarray<_Tp>::operator*=(const _Expr& __v)
{
size_t __i = 0;
for (value_type* __t = __begin_; __t != __end_ ; ++__t, ++__i)
*__t *= __v[__i];
return *this;
}
template <class _Tp>
template <class _Expr>
inline
typename enable_if
<
__is_val_expr<_Expr>::value,
valarray<_Tp>&
>::type
valarray<_Tp>::operator/=(const _Expr& __v)
{
size_t __i = 0;
for (value_type* __t = __begin_; __t != __end_ ; ++__t, ++__i)
*__t /= __v[__i];
return *this;
}
template <class _Tp>
template <class _Expr>
inline
typename enable_if
<
__is_val_expr<_Expr>::value,
valarray<_Tp>&
>::type
valarray<_Tp>::operator%=(const _Expr& __v)
{
size_t __i = 0;
for (value_type* __t = __begin_; __t != __end_ ; ++__t, ++__i)
*__t %= __v[__i];
return *this;
}
template <class _Tp>
template <class _Expr>
inline
typename enable_if
<
__is_val_expr<_Expr>::value,
valarray<_Tp>&
>::type
valarray<_Tp>::operator+=(const _Expr& __v)
{
size_t __i = 0;
for (value_type* __t = __begin_; __t != __end_ ; ++__t, ++__i)
*__t += __v[__i];
return *this;
}
template <class _Tp>
template <class _Expr>
inline
typename enable_if
<
__is_val_expr<_Expr>::value,
valarray<_Tp>&
>::type
valarray<_Tp>::operator-=(const _Expr& __v)
{
size_t __i = 0;
for (value_type* __t = __begin_; __t != __end_ ; ++__t, ++__i)
*__t -= __v[__i];
return *this;
}
template <class _Tp>
template <class _Expr>
inline
typename enable_if
<
__is_val_expr<_Expr>::value,
valarray<_Tp>&
>::type
valarray<_Tp>::operator^=(const _Expr& __v)
{
size_t __i = 0;
for (value_type* __t = __begin_; __t != __end_ ; ++__t, ++__i)
*__t ^= __v[__i];
return *this;
}
template <class _Tp>
template <class _Expr>
inline
typename enable_if
<
__is_val_expr<_Expr>::value,
valarray<_Tp>&
>::type
valarray<_Tp>::operator|=(const _Expr& __v)
{
size_t __i = 0;
for (value_type* __t = __begin_; __t != __end_ ; ++__t, ++__i)
*__t |= __v[__i];
return *this;
}
template <class _Tp>
template <class _Expr>
inline
typename enable_if
<
__is_val_expr<_Expr>::value,
valarray<_Tp>&
>::type
valarray<_Tp>::operator&=(const _Expr& __v)
{
size_t __i = 0;
for (value_type* __t = __begin_; __t != __end_ ; ++__t, ++__i)
*__t &= __v[__i];
return *this;
}
template <class _Tp>
template <class _Expr>
inline
typename enable_if
<
__is_val_expr<_Expr>::value,
valarray<_Tp>&
>::type
valarray<_Tp>::operator<<=(const _Expr& __v)
{
size_t __i = 0;
for (value_type* __t = __begin_; __t != __end_ ; ++__t, ++__i)
*__t <<= __v[__i];
return *this;
}
template <class _Tp>
template <class _Expr>
inline
typename enable_if
<
__is_val_expr<_Expr>::value,
valarray<_Tp>&
>::type
valarray<_Tp>::operator>>=(const _Expr& __v)
{
size_t __i = 0;
for (value_type* __t = __begin_; __t != __end_ ; ++__t, ++__i)
*__t >>= __v[__i];
return *this;
}
template <class _Tp>
inline
void
valarray<_Tp>::swap(valarray& __v) _NOEXCEPT
{
_VSTD::swap(__begin_, __v.__begin_);
_VSTD::swap(__end_, __v.__end_);
}
template <class _Tp>
inline
_Tp
valarray<_Tp>::sum() const
{
if (__begin_ == __end_)
return value_type();
const value_type* __p = __begin_;
_Tp __r = *__p;
for (++__p; __p != __end_; ++__p)
__r += *__p;
return __r;
}
template <class _Tp>
inline
_Tp
valarray<_Tp>::min() const
{
if (__begin_ == __end_)
return value_type();
return *_VSTD::min_element(__begin_, __end_);
}
template <class _Tp>
inline
_Tp
valarray<_Tp>::max() const
{
if (__begin_ == __end_)
return value_type();
return *_VSTD::max_element(__begin_, __end_);
}
template <class _Tp>
valarray<_Tp>
valarray<_Tp>::shift(int __i) const
{
valarray<value_type> __r;
size_t __n = size();
if (__n)
{
__r.__begin_ =
__r.__end_ =
static_cast<value_type*>(
_VSTD::__libcpp_allocate(__n * sizeof(value_type), _LIBCPP_ALIGNOF(value_type)));
const value_type* __sb;
value_type* __tb;
value_type* __te;
if (__i >= 0)
{
__i = _VSTD::min(__i, static_cast<int>(__n));
__sb = __begin_ + __i;
__tb = __r.__begin_;
__te = __r.__begin_ + (__n - __i);
}
else
{
__i = _VSTD::min(-__i, static_cast<int>(__n));
__sb = __begin_;
__tb = __r.__begin_ + __i;
__te = __r.__begin_ + __n;
}
for (; __r.__end_ != __tb; ++__r.__end_)
::new (__r.__end_) value_type();
for (; __r.__end_ != __te; ++__r.__end_, ++__sb)
::new (__r.__end_) value_type(*__sb);
for (__te = __r.__begin_ + __n; __r.__end_ != __te; ++__r.__end_)
::new (__r.__end_) value_type();
}
return __r;
}
template <class _Tp>
valarray<_Tp>
valarray<_Tp>::cshift(int __i) const
{
valarray<value_type> __r;
size_t __n = size();
if (__n)
{
__r.__begin_ =
__r.__end_ =
static_cast<value_type*>(
_VSTD::__libcpp_allocate(__n * sizeof(value_type), _LIBCPP_ALIGNOF(value_type)));
__i %= static_cast<int>(__n);
const value_type* __m = __i >= 0 ? __begin_ + __i : __end_ + __i;
for (const value_type* __s = __m; __s != __end_; ++__r.__end_, ++__s)
::new (__r.__end_) value_type(*__s);
for (const value_type* __s = __begin_; __s != __m; ++__r.__end_, ++__s)
::new (__r.__end_) value_type(*__s);
}
return __r;
}
template <class _Tp>
valarray<_Tp>
valarray<_Tp>::apply(value_type __f(value_type)) const
{
valarray<value_type> __r;
size_t __n = size();
if (__n)
{
__r.__begin_ =
__r.__end_ =
static_cast<value_type*>(
_VSTD::__libcpp_allocate(__n * sizeof(value_type), _LIBCPP_ALIGNOF(value_type)));
for (const value_type* __p = __begin_; __n; ++__r.__end_, ++__p, --__n)
::new (__r.__end_) value_type(__f(*__p));
}
return __r;
}
template <class _Tp>
valarray<_Tp>
valarray<_Tp>::apply(value_type __f(const value_type&)) const
{
valarray<value_type> __r;
size_t __n = size();
if (__n)
{
__r.__begin_ =
__r.__end_ =
static_cast<value_type*>(
_VSTD::__libcpp_allocate(__n * sizeof(value_type), _LIBCPP_ALIGNOF(value_type)));
for (const value_type* __p = __begin_; __n; ++__r.__end_, ++__p, --__n)
::new (__r.__end_) value_type(__f(*__p));
}
return __r;
}
template <class _Tp>
inline
void valarray<_Tp>::__clear(size_t __capacity)
{
if (__begin_ != nullptr)
{
while (__end_ != __begin_)
(--__end_)->~value_type();
_VSTD::__libcpp_deallocate(__begin_, __capacity * sizeof(value_type), _LIBCPP_ALIGNOF(value_type));
__begin_ = __end_ = nullptr;
}
}
template <class _Tp>
void
valarray<_Tp>::resize(size_t __n, value_type __x)
{
__clear(size());
if (__n)
{
__begin_ = __end_ = static_cast<value_type*>(
_VSTD::__libcpp_allocate(__n * sizeof(value_type), _LIBCPP_ALIGNOF(value_type)));
#ifndef _LIBCPP_NO_EXCEPTIONS
try
{
#endif // _LIBCPP_NO_EXCEPTIONS
for (size_t __n_left = __n; __n_left; --__n_left, ++__end_)
::new (__end_) value_type(__x);
#ifndef _LIBCPP_NO_EXCEPTIONS
}
catch (...)
{
__clear(__n);
throw;
}
#endif // _LIBCPP_NO_EXCEPTIONS
}
}
template<class _Tp>
inline _LIBCPP_INLINE_VISIBILITY
void
swap(valarray<_Tp>& __x, valarray<_Tp>& __y) _NOEXCEPT
{
__x.swap(__y);
}
template<class _Expr1, class _Expr2>
inline _LIBCPP_INLINE_VISIBILITY
typename enable_if
<
__is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
__val_expr<_BinaryOp<multiplies<typename _Expr1::value_type>, _Expr1, _Expr2> >
>::type
operator*(const _Expr1& __x, const _Expr2& __y)
{
typedef typename _Expr1::value_type value_type;
typedef _BinaryOp<multiplies<value_type>, _Expr1, _Expr2> _Op;
return __val_expr<_Op>(_Op(multiplies<value_type>(), __x, __y));
}
template<class _Expr>
inline _LIBCPP_INLINE_VISIBILITY
typename enable_if
<
__is_val_expr<_Expr>::value,
__val_expr<_BinaryOp<multiplies<typename _Expr::value_type>,
_Expr, __scalar_expr<typename _Expr::value_type> > >
>::type
operator*(const _Expr& __x, const typename _Expr::value_type& __y)
{
typedef typename _Expr::value_type value_type;
typedef _BinaryOp<multiplies<value_type>, _Expr, __scalar_expr<value_type> > _Op;
return __val_expr<_Op>(_Op(multiplies<value_type>(),
__x, __scalar_expr<value_type>(__y, __x.size())));
}
template<class _Expr>
inline _LIBCPP_INLINE_VISIBILITY
typename enable_if
<
__is_val_expr<_Expr>::value,
__val_expr<_BinaryOp<multiplies<typename _Expr::value_type>,
__scalar_expr<typename _Expr::value_type>, _Expr> >
>::type
operator*(const typename _Expr::value_type& __x, const _Expr& __y)
{
typedef typename _Expr::value_type value_type;
typedef _BinaryOp<multiplies<value_type>, __scalar_expr<value_type>, _Expr> _Op;
return __val_expr<_Op>(_Op(multiplies<value_type>(),
__scalar_expr<value_type>(__x, __y.size()), __y));
}
template<class _Expr1, class _Expr2>
inline _LIBCPP_INLINE_VISIBILITY
typename enable_if
<
__is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
__val_expr<_BinaryOp<divides<typename _Expr1::value_type>, _Expr1, _Expr2> >
>::type
operator/(const _Expr1& __x, const _Expr2& __y)
{
typedef typename _Expr1::value_type value_type;
typedef _BinaryOp<divides<value_type>, _Expr1, _Expr2> _Op;
return __val_expr<_Op>(_Op(divides<value_type>(), __x, __y));
}
template<class _Expr>
inline _LIBCPP_INLINE_VISIBILITY
typename enable_if
<
__is_val_expr<_Expr>::value,
__val_expr<_BinaryOp<divides<typename _Expr::value_type>,
_Expr, __scalar_expr<typename _Expr::value_type> > >
>::type
operator/(const _Expr& __x, const typename _Expr::value_type& __y)
{
typedef typename _Expr::value_type value_type;
typedef _BinaryOp<divides<value_type>, _Expr, __scalar_expr<value_type> > _Op;
return __val_expr<_Op>(_Op(divides<value_type>(),
__x, __scalar_expr<value_type>(__y, __x.size())));
}
template<class _Expr>
inline _LIBCPP_INLINE_VISIBILITY
typename enable_if
<
__is_val_expr<_Expr>::value,
__val_expr<_BinaryOp<divides<typename _Expr::value_type>,
__scalar_expr<typename _Expr::value_type>, _Expr> >
>::type
operator/(const typename _Expr::value_type& __x, const _Expr& __y)
{
typedef typename _Expr::value_type value_type;
typedef _BinaryOp<divides<value_type>, __scalar_expr<value_type>, _Expr> _Op;
return __val_expr<_Op>(_Op(divides<value_type>(),
__scalar_expr<value_type>(__x, __y.size()), __y));
}
template<class _Expr1, class _Expr2>
inline _LIBCPP_INLINE_VISIBILITY
typename enable_if
<
__is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
__val_expr<_BinaryOp<modulus<typename _Expr1::value_type>, _Expr1, _Expr2> >
>::type
operator%(const _Expr1& __x, const _Expr2& __y)
{
typedef typename _Expr1::value_type value_type;
typedef _BinaryOp<modulus<value_type>, _Expr1, _Expr2> _Op;
return __val_expr<_Op>(_Op(modulus<value_type>(), __x, __y));
}
template<class _Expr>
inline _LIBCPP_INLINE_VISIBILITY
typename enable_if
<
__is_val_expr<_Expr>::value,
__val_expr<_BinaryOp<modulus<typename _Expr::value_type>,
_Expr, __scalar_expr<typename _Expr::value_type> > >
>::type
operator%(const _Expr& __x, const typename _Expr::value_type& __y)
{
typedef typename _Expr::value_type value_type;
typedef _BinaryOp<modulus<value_type>, _Expr, __scalar_expr<value_type> > _Op;
return __val_expr<_Op>(_Op(modulus<value_type>(),
__x, __scalar_expr<value_type>(__y, __x.size())));
}
template<class _Expr>
inline _LIBCPP_INLINE_VISIBILITY
typename enable_if
<
__is_val_expr<_Expr>::value,
__val_expr<_BinaryOp<modulus<typename _Expr::value_type>,
__scalar_expr<typename _Expr::value_type>, _Expr> >
>::type
operator%(const typename _Expr::value_type& __x, const _Expr& __y)
{
typedef typename _Expr::value_type value_type;
typedef _BinaryOp<modulus<value_type>, __scalar_expr<value_type>, _Expr> _Op;
return __val_expr<_Op>(_Op(modulus<value_type>(),
__scalar_expr<value_type>(__x, __y.size()), __y));
}
template<class _Expr1, class _Expr2>
inline _LIBCPP_INLINE_VISIBILITY
typename enable_if
<
__is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
__val_expr<_BinaryOp<plus<typename _Expr1::value_type>, _Expr1, _Expr2> >
>::type
operator+(const _Expr1& __x, const _Expr2& __y)
{
typedef typename _Expr1::value_type value_type;
typedef _BinaryOp<plus<value_type>, _Expr1, _Expr2> _Op;
return __val_expr<_Op>(_Op(plus<value_type>(), __x, __y));
}
template<class _Expr>
inline _LIBCPP_INLINE_VISIBILITY
typename enable_if
<
__is_val_expr<_Expr>::value,
__val_expr<_BinaryOp<plus<typename _Expr::value_type>,
_Expr, __scalar_expr<typename _Expr::value_type> > >
>::type
operator+(const _Expr& __x, const typename _Expr::value_type& __y)
{
typedef typename _Expr::value_type value_type;
typedef _BinaryOp<plus<value_type>, _Expr, __scalar_expr<value_type> > _Op;
return __val_expr<_Op>(_Op(plus<value_type>(),
__x, __scalar_expr<value_type>(__y, __x.size())));
}
template<class _Expr>
inline _LIBCPP_INLINE_VISIBILITY
typename enable_if
<
__is_val_expr<_Expr>::value,
__val_expr<_BinaryOp<plus<typename _Expr::value_type>,
__scalar_expr<typename _Expr::value_type>, _Expr> >
>::type
operator+(const typename _Expr::value_type& __x, const _Expr& __y)
{
typedef typename _Expr::value_type value_type;
typedef _BinaryOp<plus<value_type>, __scalar_expr<value_type>, _Expr> _Op;
return __val_expr<_Op>(_Op(plus<value_type>(),
__scalar_expr<value_type>(__x, __y.size()), __y));
}
template<class _Expr1, class _Expr2>
inline _LIBCPP_INLINE_VISIBILITY
typename enable_if
<
__is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
__val_expr<_BinaryOp<minus<typename _Expr1::value_type>, _Expr1, _Expr2> >
>::type
operator-(const _Expr1& __x, const _Expr2& __y)
{
typedef typename _Expr1::value_type value_type;
typedef _BinaryOp<minus<value_type>, _Expr1, _Expr2> _Op;
return __val_expr<_Op>(_Op(minus<value_type>(), __x, __y));
}
template<class _Expr>
inline _LIBCPP_INLINE_VISIBILITY
typename enable_if
<
__is_val_expr<_Expr>::value,
__val_expr<_BinaryOp<minus<typename _Expr::value_type>,
_Expr, __scalar_expr<typename _Expr::value_type> > >
>::type
operator-(const _Expr& __x, const typename _Expr::value_type& __y)
{
typedef typename _Expr::value_type value_type;
typedef _BinaryOp<minus<value_type>, _Expr, __scalar_expr<value_type> > _Op;
return __val_expr<_Op>(_Op(minus<value_type>(),
__x, __scalar_expr<value_type>(__y, __x.size())));
}
template<class _Expr>
inline _LIBCPP_INLINE_VISIBILITY
typename enable_if
<
__is_val_expr<_Expr>::value,
__val_expr<_BinaryOp<minus<typename _Expr::value_type>,
__scalar_expr<typename _Expr::value_type>, _Expr> >
>::type
operator-(const typename _Expr::value_type& __x, const _Expr& __y)
{
typedef typename _Expr::value_type value_type;
typedef _BinaryOp<minus<value_type>, __scalar_expr<value_type>, _Expr> _Op;
return __val_expr<_Op>(_Op(minus<value_type>(),
__scalar_expr<value_type>(__x, __y.size()), __y));
}
template<class _Expr1, class _Expr2>
inline _LIBCPP_INLINE_VISIBILITY
typename enable_if
<
__is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
__val_expr<_BinaryOp<bit_xor<typename _Expr1::value_type>, _Expr1, _Expr2> >
>::type
operator^(const _Expr1& __x, const _Expr2& __y)
{
typedef typename _Expr1::value_type value_type;
typedef _BinaryOp<bit_xor<value_type>, _Expr1, _Expr2> _Op;
return __val_expr<_Op>(_Op(bit_xor<value_type>(), __x, __y));
}
template<class _Expr>
inline _LIBCPP_INLINE_VISIBILITY
typename enable_if
<
__is_val_expr<_Expr>::value,
__val_expr<_BinaryOp<bit_xor<typename _Expr::value_type>,
_Expr, __scalar_expr<typename _Expr::value_type> > >
>::type
operator^(const _Expr& __x, const typename _Expr::value_type& __y)
{
typedef typename _Expr::value_type value_type;
typedef _BinaryOp<bit_xor<value_type>, _Expr, __scalar_expr<value_type> > _Op;
return __val_expr<_Op>(_Op(bit_xor<value_type>(),
__x, __scalar_expr<value_type>(__y, __x.size())));
}
template<class _Expr>
inline _LIBCPP_INLINE_VISIBILITY
typename enable_if
<
__is_val_expr<_Expr>::value,
__val_expr<_BinaryOp<bit_xor<typename _Expr::value_type>,
__scalar_expr<typename _Expr::value_type>, _Expr> >
>::type
operator^(const typename _Expr::value_type& __x, const _Expr& __y)
{
typedef typename _Expr::value_type value_type;
typedef _BinaryOp<bit_xor<value_type>, __scalar_expr<value_type>, _Expr> _Op;
return __val_expr<_Op>(_Op(bit_xor<value_type>(),
__scalar_expr<value_type>(__x, __y.size()), __y));
}
template<class _Expr1, class _Expr2>
inline _LIBCPP_INLINE_VISIBILITY
typename enable_if
<
__is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
__val_expr<_BinaryOp<bit_and<typename _Expr1::value_type>, _Expr1, _Expr2> >
>::type
operator&(const _Expr1& __x, const _Expr2& __y)
{
typedef typename _Expr1::value_type value_type;
typedef _BinaryOp<bit_and<value_type>, _Expr1, _Expr2> _Op;
return __val_expr<_Op>(_Op(bit_and<value_type>(), __x, __y));
}
template<class _Expr>
inline _LIBCPP_INLINE_VISIBILITY
typename enable_if
<
__is_val_expr<_Expr>::value,
__val_expr<_BinaryOp<bit_and<typename _Expr::value_type>,
_Expr, __scalar_expr<typename _Expr::value_type> > >
>::type
operator&(const _Expr& __x, const typename _Expr::value_type& __y)
{
typedef typename _Expr::value_type value_type;
typedef _BinaryOp<bit_and<value_type>, _Expr, __scalar_expr<value_type> > _Op;
return __val_expr<_Op>(_Op(bit_and<value_type>(),
__x, __scalar_expr<value_type>(__y, __x.size())));
}
template<class _Expr>
inline _LIBCPP_INLINE_VISIBILITY
typename enable_if
<
__is_val_expr<_Expr>::value,
__val_expr<_BinaryOp<bit_and<typename _Expr::value_type>,
__scalar_expr<typename _Expr::value_type>, _Expr> >
>::type
operator&(const typename _Expr::value_type& __x, const _Expr& __y)
{
typedef typename _Expr::value_type value_type;
typedef _BinaryOp<bit_and<value_type>, __scalar_expr<value_type>, _Expr> _Op;
return __val_expr<_Op>(_Op(bit_and<value_type>(),
__scalar_expr<value_type>(__x, __y.size()), __y));
}
template<class _Expr1, class _Expr2>
inline _LIBCPP_INLINE_VISIBILITY
typename enable_if
<
__is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
__val_expr<_BinaryOp<bit_or<typename _Expr1::value_type>, _Expr1, _Expr2> >
>::type
operator|(const _Expr1& __x, const _Expr2& __y)
{
typedef typename _Expr1::value_type value_type;
typedef _BinaryOp<bit_or<value_type>, _Expr1, _Expr2> _Op;
return __val_expr<_Op>(_Op(bit_or<value_type>(), __x, __y));
}
template<class _Expr>
inline _LIBCPP_INLINE_VISIBILITY
typename enable_if
<
__is_val_expr<_Expr>::value,
__val_expr<_BinaryOp<bit_or<typename _Expr::value_type>,
_Expr, __scalar_expr<typename _Expr::value_type> > >
>::type
operator|(const _Expr& __x, const typename _Expr::value_type& __y)
{
typedef typename _Expr::value_type value_type;
typedef _BinaryOp<bit_or<value_type>, _Expr, __scalar_expr<value_type> > _Op;
return __val_expr<_Op>(_Op(bit_or<value_type>(),
__x, __scalar_expr<value_type>(__y, __x.size())));
}
template<class _Expr>
inline _LIBCPP_INLINE_VISIBILITY
typename enable_if
<
__is_val_expr<_Expr>::value,
__val_expr<_BinaryOp<bit_or<typename _Expr::value_type>,
__scalar_expr<typename _Expr::value_type>, _Expr> >
>::type
operator|(const typename _Expr::value_type& __x, const _Expr& __y)
{
typedef typename _Expr::value_type value_type;
typedef _BinaryOp<bit_or<value_type>, __scalar_expr<value_type>, _Expr> _Op;
return __val_expr<_Op>(_Op(bit_or<value_type>(),
__scalar_expr<value_type>(__x, __y.size()), __y));
}
template<class _Expr1, class _Expr2>
inline _LIBCPP_INLINE_VISIBILITY
typename enable_if
<
__is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
__val_expr<_BinaryOp<__bit_shift_left<typename _Expr1::value_type>, _Expr1, _Expr2> >
>::type
operator<<(const _Expr1& __x, const _Expr2& __y)
{
typedef typename _Expr1::value_type value_type;
typedef _BinaryOp<__bit_shift_left<value_type>, _Expr1, _Expr2> _Op;
return __val_expr<_Op>(_Op(__bit_shift_left<value_type>(), __x, __y));
}
template<class _Expr>
inline _LIBCPP_INLINE_VISIBILITY
typename enable_if
<
__is_val_expr<_Expr>::value,
__val_expr<_BinaryOp<__bit_shift_left<typename _Expr::value_type>,
_Expr, __scalar_expr<typename _Expr::value_type> > >
>::type
operator<<(const _Expr& __x, const typename _Expr::value_type& __y)
{
typedef typename _Expr::value_type value_type;
typedef _BinaryOp<__bit_shift_left<value_type>, _Expr, __scalar_expr<value_type> > _Op;
return __val_expr<_Op>(_Op(__bit_shift_left<value_type>(),
__x, __scalar_expr<value_type>(__y, __x.size())));
}
template<class _Expr>
inline _LIBCPP_INLINE_VISIBILITY
typename enable_if
<
__is_val_expr<_Expr>::value,
__val_expr<_BinaryOp<__bit_shift_left<typename _Expr::value_type>,
__scalar_expr<typename _Expr::value_type>, _Expr> >
>::type
operator<<(const typename _Expr::value_type& __x, const _Expr& __y)
{
typedef typename _Expr::value_type value_type;
typedef _BinaryOp<__bit_shift_left<value_type>, __scalar_expr<value_type>, _Expr> _Op;
return __val_expr<_Op>(_Op(__bit_shift_left<value_type>(),
__scalar_expr<value_type>(__x, __y.size()), __y));
}
template<class _Expr1, class _Expr2>
inline _LIBCPP_INLINE_VISIBILITY
typename enable_if
<
__is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
__val_expr<_BinaryOp<__bit_shift_right<typename _Expr1::value_type>, _Expr1, _Expr2> >
>::type
operator>>(const _Expr1& __x, const _Expr2& __y)
{
typedef typename _Expr1::value_type value_type;
typedef _BinaryOp<__bit_shift_right<value_type>, _Expr1, _Expr2> _Op;
return __val_expr<_Op>(_Op(__bit_shift_right<value_type>(), __x, __y));
}
template<class _Expr>
inline _LIBCPP_INLINE_VISIBILITY
typename enable_if
<
__is_val_expr<_Expr>::value,
__val_expr<_BinaryOp<__bit_shift_right<typename _Expr::value_type>,
_Expr, __scalar_expr<typename _Expr::value_type> > >
>::type
operator>>(const _Expr& __x, const typename _Expr::value_type& __y)
{
typedef typename _Expr::value_type value_type;
typedef _BinaryOp<__bit_shift_right<value_type>, _Expr, __scalar_expr<value_type> > _Op;
return __val_expr<_Op>(_Op(__bit_shift_right<value_type>(),
__x, __scalar_expr<value_type>(__y, __x.size())));
}
template<class _Expr>
inline _LIBCPP_INLINE_VISIBILITY
typename enable_if
<
__is_val_expr<_Expr>::value,
__val_expr<_BinaryOp<__bit_shift_right<typename _Expr::value_type>,
__scalar_expr<typename _Expr::value_type>, _Expr> >
>::type
operator>>(const typename _Expr::value_type& __x, const _Expr& __y)
{
typedef typename _Expr::value_type value_type;
typedef _BinaryOp<__bit_shift_right<value_type>, __scalar_expr<value_type>, _Expr> _Op;
return __val_expr<_Op>(_Op(__bit_shift_right<value_type>(),
__scalar_expr<value_type>(__x, __y.size()), __y));
}
template<class _Expr1, class _Expr2>
inline _LIBCPP_INLINE_VISIBILITY
typename enable_if
<
__is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
__val_expr<_BinaryOp<logical_and<typename _Expr1::value_type>, _Expr1, _Expr2> >
>::type
operator&&(const _Expr1& __x, const _Expr2& __y)
{
typedef typename _Expr1::value_type value_type;
typedef _BinaryOp<logical_and<value_type>, _Expr1, _Expr2> _Op;
return __val_expr<_Op>(_Op(logical_and<value_type>(), __x, __y));
}
template<class _Expr>
inline _LIBCPP_INLINE_VISIBILITY
typename enable_if
<
__is_val_expr<_Expr>::value,
__val_expr<_BinaryOp<logical_and<typename _Expr::value_type>,
_Expr, __scalar_expr<typename _Expr::value_type> > >
>::type
operator&&(const _Expr& __x, const typename _Expr::value_type& __y)
{
typedef typename _Expr::value_type value_type;
typedef _BinaryOp<logical_and<value_type>, _Expr, __scalar_expr<value_type> > _Op;
return __val_expr<_Op>(_Op(logical_and<value_type>(),
__x, __scalar_expr<value_type>(__y, __x.size())));
}
template<class _Expr>
inline _LIBCPP_INLINE_VISIBILITY
typename enable_if
<
__is_val_expr<_Expr>::value,
__val_expr<_BinaryOp<logical_and<typename _Expr::value_type>,
__scalar_expr<typename _Expr::value_type>, _Expr> >
>::type
operator&&(const typename _Expr::value_type& __x, const _Expr& __y)
{
typedef typename _Expr::value_type value_type;
typedef _BinaryOp<logical_and<value_type>, __scalar_expr<value_type>, _Expr> _Op;
return __val_expr<_Op>(_Op(logical_and<value_type>(),
__scalar_expr<value_type>(__x, __y.size()), __y));
}
template<class _Expr1, class _Expr2>
inline _LIBCPP_INLINE_VISIBILITY
typename enable_if
<
__is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
__val_expr<_BinaryOp<logical_or<typename _Expr1::value_type>, _Expr1, _Expr2> >
>::type
operator||(const _Expr1& __x, const _Expr2& __y)
{
typedef typename _Expr1::value_type value_type;
typedef _BinaryOp<logical_or<value_type>, _Expr1, _Expr2> _Op;
return __val_expr<_Op>(_Op(logical_or<value_type>(), __x, __y));
}
template<class _Expr>
inline _LIBCPP_INLINE_VISIBILITY
typename enable_if
<
__is_val_expr<_Expr>::value,
__val_expr<_BinaryOp<logical_or<typename _Expr::value_type>,
_Expr, __scalar_expr<typename _Expr::value_type> > >
>::type
operator||(const _Expr& __x, const typename _Expr::value_type& __y)
{
typedef typename _Expr::value_type value_type;
typedef _BinaryOp<logical_or<value_type>, _Expr, __scalar_expr<value_type> > _Op;
return __val_expr<_Op>(_Op(logical_or<value_type>(),
__x, __scalar_expr<value_type>(__y, __x.size())));
}
template<class _Expr>
inline _LIBCPP_INLINE_VISIBILITY
typename enable_if
<
__is_val_expr<_Expr>::value,
__val_expr<_BinaryOp<logical_or<typename _Expr::value_type>,
__scalar_expr<typename _Expr::value_type>, _Expr> >
>::type
operator||(const typename _Expr::value_type& __x, const _Expr& __y)
{
typedef typename _Expr::value_type value_type;
typedef _BinaryOp<logical_or<value_type>, __scalar_expr<value_type>, _Expr> _Op;
return __val_expr<_Op>(_Op(logical_or<value_type>(),
__scalar_expr<value_type>(__x, __y.size()), __y));
}
template<class _Expr1, class _Expr2>
inline _LIBCPP_INLINE_VISIBILITY
typename enable_if
<
__is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
__val_expr<_BinaryOp<equal_to<typename _Expr1::value_type>, _Expr1, _Expr2> >
>::type
operator==(const _Expr1& __x, const _Expr2& __y)
{
typedef typename _Expr1::value_type value_type;
typedef _BinaryOp<equal_to<value_type>, _Expr1, _Expr2> _Op;
return __val_expr<_Op>(_Op(equal_to<value_type>(), __x, __y));
}
template<class _Expr>
inline _LIBCPP_INLINE_VISIBILITY
typename enable_if
<
__is_val_expr<_Expr>::value,
__val_expr<_BinaryOp<equal_to<typename _Expr::value_type>,
_Expr, __scalar_expr<typename _Expr::value_type> > >
>::type
operator==(const _Expr& __x, const typename _Expr::value_type& __y)
{
typedef typename _Expr::value_type value_type;
typedef _BinaryOp<equal_to<value_type>, _Expr, __scalar_expr<value_type> > _Op;
return __val_expr<_Op>(_Op(equal_to<value_type>(),
__x, __scalar_expr<value_type>(__y, __x.size())));
}
template<class _Expr>
inline _LIBCPP_INLINE_VISIBILITY
typename enable_if
<
__is_val_expr<_Expr>::value,
__val_expr<_BinaryOp<equal_to<typename _Expr::value_type>,
__scalar_expr<typename _Expr::value_type>, _Expr> >
>::type
operator==(const typename _Expr::value_type& __x, const _Expr& __y)
{
typedef typename _Expr::value_type value_type;
typedef _BinaryOp<equal_to<value_type>, __scalar_expr<value_type>, _Expr> _Op;
return __val_expr<_Op>(_Op(equal_to<value_type>(),
__scalar_expr<value_type>(__x, __y.size()), __y));
}
template<class _Expr1, class _Expr2>
inline _LIBCPP_INLINE_VISIBILITY
typename enable_if
<
__is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
__val_expr<_BinaryOp<not_equal_to<typename _Expr1::value_type>, _Expr1, _Expr2> >
>::type
operator!=(const _Expr1& __x, const _Expr2& __y)
{
typedef typename _Expr1::value_type value_type;
typedef _BinaryOp<not_equal_to<value_type>, _Expr1, _Expr2> _Op;
return __val_expr<_Op>(_Op(not_equal_to<value_type>(), __x, __y));
}
template<class _Expr>
inline _LIBCPP_INLINE_VISIBILITY
typename enable_if
<
__is_val_expr<_Expr>::value,
__val_expr<_BinaryOp<not_equal_to<typename _Expr::value_type>,
_Expr, __scalar_expr<typename _Expr::value_type> > >
>::type
operator!=(const _Expr& __x, const typename _Expr::value_type& __y)
{
typedef typename _Expr::value_type value_type;
typedef _BinaryOp<not_equal_to<value_type>, _Expr, __scalar_expr<value_type> > _Op;
return __val_expr<_Op>(_Op(not_equal_to<value_type>(),
__x, __scalar_expr<value_type>(__y, __x.size())));
}
template<class _Expr>
inline _LIBCPP_INLINE_VISIBILITY
typename enable_if
<
__is_val_expr<_Expr>::value,
__val_expr<_BinaryOp<not_equal_to<typename _Expr::value_type>,
__scalar_expr<typename _Expr::value_type>, _Expr> >
>::type
operator!=(const typename _Expr::value_type& __x, const _Expr& __y)
{
typedef typename _Expr::value_type value_type;
typedef _BinaryOp<not_equal_to<value_type>, __scalar_expr<value_type>, _Expr> _Op;
return __val_expr<_Op>(_Op(not_equal_to<value_type>(),
__scalar_expr<value_type>(__x, __y.size()), __y));
}
template<class _Expr1, class _Expr2>
inline _LIBCPP_INLINE_VISIBILITY
typename enable_if
<
__is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
__val_expr<_BinaryOp<less<typename _Expr1::value_type>, _Expr1, _Expr2> >
>::type
operator<(const _Expr1& __x, const _Expr2& __y)
{
typedef typename _Expr1::value_type value_type;
typedef _BinaryOp<less<value_type>, _Expr1, _Expr2> _Op;
return __val_expr<_Op>(_Op(less<value_type>(), __x, __y));
}
template<class _Expr>
inline _LIBCPP_INLINE_VISIBILITY
typename enable_if
<
__is_val_expr<_Expr>::value,
__val_expr<_BinaryOp<less<typename _Expr::value_type>,
_Expr, __scalar_expr<typename _Expr::value_type> > >
>::type
operator<(const _Expr& __x, const typename _Expr::value_type& __y)
{
typedef typename _Expr::value_type value_type;
typedef _BinaryOp<less<value_type>, _Expr, __scalar_expr<value_type> > _Op;
return __val_expr<_Op>(_Op(less<value_type>(),
__x, __scalar_expr<value_type>(__y, __x.size())));
}
template<class _Expr>
inline _LIBCPP_INLINE_VISIBILITY
typename enable_if
<
__is_val_expr<_Expr>::value,
__val_expr<_BinaryOp<less<typename _Expr::value_type>,
__scalar_expr<typename _Expr::value_type>, _Expr> >
>::type
operator<(const typename _Expr::value_type& __x, const _Expr& __y)
{
typedef typename _Expr::value_type value_type;
typedef _BinaryOp<less<value_type>, __scalar_expr<value_type>, _Expr> _Op;
return __val_expr<_Op>(_Op(less<value_type>(),
__scalar_expr<value_type>(__x, __y.size()), __y));
}
template<class _Expr1, class _Expr2>
inline _LIBCPP_INLINE_VISIBILITY
typename enable_if
<
__is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
__val_expr<_BinaryOp<greater<typename _Expr1::value_type>, _Expr1, _Expr2> >
>::type
operator>(const _Expr1& __x, const _Expr2& __y)
{
typedef typename _Expr1::value_type value_type;
typedef _BinaryOp<greater<value_type>, _Expr1, _Expr2> _Op;
return __val_expr<_Op>(_Op(greater<value_type>(), __x, __y));
}
template<class _Expr>
inline _LIBCPP_INLINE_VISIBILITY
typename enable_if
<
__is_val_expr<_Expr>::value,
__val_expr<_BinaryOp<greater<typename _Expr::value_type>,
_Expr, __scalar_expr<typename _Expr::value_type> > >
>::type
operator>(const _Expr& __x, const typename _Expr::value_type& __y)
{
typedef typename _Expr::value_type value_type;
typedef _BinaryOp<greater<value_type>, _Expr, __scalar_expr<value_type> > _Op;
return __val_expr<_Op>(_Op(greater<value_type>(),
__x, __scalar_expr<value_type>(__y, __x.size())));
}
template<class _Expr>
inline _LIBCPP_INLINE_VISIBILITY
typename enable_if
<
__is_val_expr<_Expr>::value,
__val_expr<_BinaryOp<greater<typename _Expr::value_type>,
__scalar_expr<typename _Expr::value_type>, _Expr> >
>::type
operator>(const typename _Expr::value_type& __x, const _Expr& __y)
{
typedef typename _Expr::value_type value_type;
typedef _BinaryOp<greater<value_type>, __scalar_expr<value_type>, _Expr> _Op;
return __val_expr<_Op>(_Op(greater<value_type>(),
__scalar_expr<value_type>(__x, __y.size()), __y));
}
template<class _Expr1, class _Expr2>
inline _LIBCPP_INLINE_VISIBILITY
typename enable_if
<
__is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
__val_expr<_BinaryOp<less_equal<typename _Expr1::value_type>, _Expr1, _Expr2> >
>::type
operator<=(const _Expr1& __x, const _Expr2& __y)
{
typedef typename _Expr1::value_type value_type;
typedef _BinaryOp<less_equal<value_type>, _Expr1, _Expr2> _Op;
return __val_expr<_Op>(_Op(less_equal<value_type>(), __x, __y));
}
template<class _Expr>
inline _LIBCPP_INLINE_VISIBILITY
typename enable_if
<
__is_val_expr<_Expr>::value,
__val_expr<_BinaryOp<less_equal<typename _Expr::value_type>,
_Expr, __scalar_expr<typename _Expr::value_type> > >
>::type
operator<=(const _Expr& __x, const typename _Expr::value_type& __y)
{
typedef typename _Expr::value_type value_type;
typedef _BinaryOp<less_equal<value_type>, _Expr, __scalar_expr<value_type> > _Op;
return __val_expr<_Op>(_Op(less_equal<value_type>(),
__x, __scalar_expr<value_type>(__y, __x.size())));
}
template<class _Expr>
inline _LIBCPP_INLINE_VISIBILITY
typename enable_if
<
__is_val_expr<_Expr>::value,
__val_expr<_BinaryOp<less_equal<typename _Expr::value_type>,
__scalar_expr<typename _Expr::value_type>, _Expr> >
>::type
operator<=(const typename _Expr::value_type& __x, const _Expr& __y)
{
typedef typename _Expr::value_type value_type;
typedef _BinaryOp<less_equal<value_type>, __scalar_expr<value_type>, _Expr> _Op;
return __val_expr<_Op>(_Op(less_equal<value_type>(),
__scalar_expr<value_type>(__x, __y.size()), __y));
}
template<class _Expr1, class _Expr2>
inline _LIBCPP_INLINE_VISIBILITY
typename enable_if
<
__is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
__val_expr<_BinaryOp<greater_equal<typename _Expr1::value_type>, _Expr1, _Expr2> >
>::type
operator>=(const _Expr1& __x, const _Expr2& __y)
{
typedef typename _Expr1::value_type value_type;
typedef _BinaryOp<greater_equal<value_type>, _Expr1, _Expr2> _Op;
return __val_expr<_Op>(_Op(greater_equal<value_type>(), __x, __y));
}
template<class _Expr>
inline _LIBCPP_INLINE_VISIBILITY
typename enable_if
<
__is_val_expr<_Expr>::value,
__val_expr<_BinaryOp<greater_equal<typename _Expr::value_type>,
_Expr, __scalar_expr<typename _Expr::value_type> > >
>::type
operator>=(const _Expr& __x, const typename _Expr::value_type& __y)
{
typedef typename _Expr::value_type value_type;
typedef _BinaryOp<greater_equal<value_type>, _Expr, __scalar_expr<value_type> > _Op;
return __val_expr<_Op>(_Op(greater_equal<value_type>(),
__x, __scalar_expr<value_type>(__y, __x.size())));
}
template<class _Expr>
inline _LIBCPP_INLINE_VISIBILITY
typename enable_if
<
__is_val_expr<_Expr>::value,
__val_expr<_BinaryOp<greater_equal<typename _Expr::value_type>,
__scalar_expr<typename _Expr::value_type>, _Expr> >
>::type
operator>=(const typename _Expr::value_type& __x, const _Expr& __y)
{
typedef typename _Expr::value_type value_type;
typedef _BinaryOp<greater_equal<value_type>, __scalar_expr<value_type>, _Expr> _Op;
return __val_expr<_Op>(_Op(greater_equal<value_type>(),
__scalar_expr<value_type>(__x, __y.size()), __y));
}
template<class _Expr>
inline _LIBCPP_INLINE_VISIBILITY
typename enable_if
<
__is_val_expr<_Expr>::value,
__val_expr<_UnaryOp<__abs_expr<typename _Expr::value_type>, _Expr> >
>::type
abs(const _Expr& __x)
{
typedef typename _Expr::value_type value_type;
typedef _UnaryOp<__abs_expr<value_type>, _Expr> _Op;
return __val_expr<_Op>(_Op(__abs_expr<value_type>(), __x));
}
template<class _Expr>
inline _LIBCPP_INLINE_VISIBILITY
typename enable_if
<
__is_val_expr<_Expr>::value,
__val_expr<_UnaryOp<__acos_expr<typename _Expr::value_type>, _Expr> >
>::type
acos(const _Expr& __x)
{
typedef typename _Expr::value_type value_type;
typedef _UnaryOp<__acos_expr<value_type>, _Expr> _Op;
return __val_expr<_Op>(_Op(__acos_expr<value_type>(), __x));
}
template<class _Expr>
inline _LIBCPP_INLINE_VISIBILITY
typename enable_if
<
__is_val_expr<_Expr>::value,
__val_expr<_UnaryOp<__asin_expr<typename _Expr::value_type>, _Expr> >
>::type
asin(const _Expr& __x)
{
typedef typename _Expr::value_type value_type;
typedef _UnaryOp<__asin_expr<value_type>, _Expr> _Op;
return __val_expr<_Op>(_Op(__asin_expr<value_type>(), __x));
}
template<class _Expr>
inline _LIBCPP_INLINE_VISIBILITY
typename enable_if
<
__is_val_expr<_Expr>::value,
__val_expr<_UnaryOp<__atan_expr<typename _Expr::value_type>, _Expr> >
>::type
atan(const _Expr& __x)
{
typedef typename _Expr::value_type value_type;
typedef _UnaryOp<__atan_expr<value_type>, _Expr> _Op;
return __val_expr<_Op>(_Op(__atan_expr<value_type>(), __x));
}
template<class _Expr1, class _Expr2>
inline _LIBCPP_INLINE_VISIBILITY
typename enable_if
<
__is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
__val_expr<_BinaryOp<__atan2_expr<typename _Expr1::value_type>, _Expr1, _Expr2> >
>::type
atan2(const _Expr1& __x, const _Expr2& __y)
{
typedef typename _Expr1::value_type value_type;
typedef _BinaryOp<__atan2_expr<value_type>, _Expr1, _Expr2> _Op;
return __val_expr<_Op>(_Op(__atan2_expr<value_type>(), __x, __y));
}
template<class _Expr>
inline _LIBCPP_INLINE_VISIBILITY
typename enable_if
<
__is_val_expr<_Expr>::value,
__val_expr<_BinaryOp<__atan2_expr<typename _Expr::value_type>,
_Expr, __scalar_expr<typename _Expr::value_type> > >
>::type
atan2(const _Expr& __x, const typename _Expr::value_type& __y)
{
typedef typename _Expr::value_type value_type;
typedef _BinaryOp<__atan2_expr<value_type>, _Expr, __scalar_expr<value_type> > _Op;
return __val_expr<_Op>(_Op(__atan2_expr<value_type>(),
__x, __scalar_expr<value_type>(__y, __x.size())));
}
template<class _Expr>
inline _LIBCPP_INLINE_VISIBILITY
typename enable_if
<
__is_val_expr<_Expr>::value,
__val_expr<_BinaryOp<__atan2_expr<typename _Expr::value_type>,
__scalar_expr<typename _Expr::value_type>, _Expr> >
>::type
atan2(const typename _Expr::value_type& __x, const _Expr& __y)
{
typedef typename _Expr::value_type value_type;
typedef _BinaryOp<__atan2_expr<value_type>, __scalar_expr<value_type>, _Expr> _Op;
return __val_expr<_Op>(_Op(__atan2_expr<value_type>(),
__scalar_expr<value_type>(__x, __y.size()), __y));
}
template<class _Expr>
inline _LIBCPP_INLINE_VISIBILITY
typename enable_if
<
__is_val_expr<_Expr>::value,
__val_expr<_UnaryOp<__cos_expr<typename _Expr::value_type>, _Expr> >
>::type
cos(const _Expr& __x)
{
typedef typename _Expr::value_type value_type;
typedef _UnaryOp<__cos_expr<value_type>, _Expr> _Op;
return __val_expr<_Op>(_Op(__cos_expr<value_type>(), __x));
}
template<class _Expr>
inline _LIBCPP_INLINE_VISIBILITY
typename enable_if
<
__is_val_expr<_Expr>::value,
__val_expr<_UnaryOp<__cosh_expr<typename _Expr::value_type>, _Expr> >
>::type
cosh(const _Expr& __x)
{
typedef typename _Expr::value_type value_type;
typedef _UnaryOp<__cosh_expr<value_type>, _Expr> _Op;
return __val_expr<_Op>(_Op(__cosh_expr<value_type>(), __x));
}
template<class _Expr>
inline _LIBCPP_INLINE_VISIBILITY
typename enable_if
<
__is_val_expr<_Expr>::value,
__val_expr<_UnaryOp<__exp_expr<typename _Expr::value_type>, _Expr> >
>::type
exp(const _Expr& __x)
{
typedef typename _Expr::value_type value_type;
typedef _UnaryOp<__exp_expr<value_type>, _Expr> _Op;
return __val_expr<_Op>(_Op(__exp_expr<value_type>(), __x));
}
template<class _Expr>
inline _LIBCPP_INLINE_VISIBILITY
typename enable_if
<
__is_val_expr<_Expr>::value,
__val_expr<_UnaryOp<__log_expr<typename _Expr::value_type>, _Expr> >
>::type
log(const _Expr& __x)
{
typedef typename _Expr::value_type value_type;
typedef _UnaryOp<__log_expr<value_type>, _Expr> _Op;
return __val_expr<_Op>(_Op(__log_expr<value_type>(), __x));
}
template<class _Expr>
inline _LIBCPP_INLINE_VISIBILITY
typename enable_if
<
__is_val_expr<_Expr>::value,
__val_expr<_UnaryOp<__log10_expr<typename _Expr::value_type>, _Expr> >
>::type
log10(const _Expr& __x)
{
typedef typename _Expr::value_type value_type;
typedef _UnaryOp<__log10_expr<value_type>, _Expr> _Op;
return __val_expr<_Op>(_Op(__log10_expr<value_type>(), __x));
}
template<class _Expr1, class _Expr2>
inline _LIBCPP_INLINE_VISIBILITY
typename enable_if
<
__is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value,
__val_expr<_BinaryOp<__pow_expr<typename _Expr1::value_type>, _Expr1, _Expr2> >
>::type
pow(const _Expr1& __x, const _Expr2& __y)
{
typedef typename _Expr1::value_type value_type;
typedef _BinaryOp<__pow_expr<value_type>, _Expr1, _Expr2> _Op;
return __val_expr<_Op>(_Op(__pow_expr<value_type>(), __x, __y));
}
template<class _Expr>
inline _LIBCPP_INLINE_VISIBILITY
typename enable_if
<
__is_val_expr<_Expr>::value,
__val_expr<_BinaryOp<__pow_expr<typename _Expr::value_type>,
_Expr, __scalar_expr<typename _Expr::value_type> > >
>::type
pow(const _Expr& __x, const typename _Expr::value_type& __y)
{
typedef typename _Expr::value_type value_type;
typedef _BinaryOp<__pow_expr<value_type>, _Expr, __scalar_expr<value_type> > _Op;
return __val_expr<_Op>(_Op(__pow_expr<value_type>(),
__x, __scalar_expr<value_type>(__y, __x.size())));
}
template<class _Expr>
inline _LIBCPP_INLINE_VISIBILITY
typename enable_if
<
__is_val_expr<_Expr>::value,
__val_expr<_BinaryOp<__pow_expr<typename _Expr::value_type>,
__scalar_expr<typename _Expr::value_type>, _Expr> >
>::type
pow(const typename _Expr::value_type& __x, const _Expr& __y)
{
typedef typename _Expr::value_type value_type;
typedef _BinaryOp<__pow_expr<value_type>, __scalar_expr<value_type>, _Expr> _Op;
return __val_expr<_Op>(_Op(__pow_expr<value_type>(),
__scalar_expr<value_type>(__x, __y.size()), __y));
}
template<class _Expr>
inline _LIBCPP_INLINE_VISIBILITY
typename enable_if
<
__is_val_expr<_Expr>::value,
__val_expr<_UnaryOp<__sin_expr<typename _Expr::value_type>, _Expr> >
>::type
sin(const _Expr& __x)
{
typedef typename _Expr::value_type value_type;
typedef _UnaryOp<__sin_expr<value_type>, _Expr> _Op;
return __val_expr<_Op>(_Op(__sin_expr<value_type>(), __x));
}
template<class _Expr>
inline _LIBCPP_INLINE_VISIBILITY
typename enable_if
<
__is_val_expr<_Expr>::value,
__val_expr<_UnaryOp<__sinh_expr<typename _Expr::value_type>, _Expr> >
>::type
sinh(const _Expr& __x)
{
typedef typename _Expr::value_type value_type;
typedef _UnaryOp<__sinh_expr<value_type>, _Expr> _Op;
return __val_expr<_Op>(_Op(__sinh_expr<value_type>(), __x));
}
template<class _Expr>
inline _LIBCPP_INLINE_VISIBILITY
typename enable_if
<
__is_val_expr<_Expr>::value,
__val_expr<_UnaryOp<__sqrt_expr<typename _Expr::value_type>, _Expr> >
>::type
sqrt(const _Expr& __x)
{
typedef typename _Expr::value_type value_type;
typedef _UnaryOp<__sqrt_expr<value_type>, _Expr> _Op;
return __val_expr<_Op>(_Op(__sqrt_expr<value_type>(), __x));
}
template<class _Expr>
inline _LIBCPP_INLINE_VISIBILITY
typename enable_if
<
__is_val_expr<_Expr>::value,
__val_expr<_UnaryOp<__tan_expr<typename _Expr::value_type>, _Expr> >
>::type
tan(const _Expr& __x)
{
typedef typename _Expr::value_type value_type;
typedef _UnaryOp<__tan_expr<value_type>, _Expr> _Op;
return __val_expr<_Op>(_Op(__tan_expr<value_type>(), __x));
}
template<class _Expr>
inline _LIBCPP_INLINE_VISIBILITY
typename enable_if
<
__is_val_expr<_Expr>::value,
__val_expr<_UnaryOp<__tanh_expr<typename _Expr::value_type>, _Expr> >
>::type
tanh(const _Expr& __x)
{
typedef typename _Expr::value_type value_type;
typedef _UnaryOp<__tanh_expr<value_type>, _Expr> _Op;
return __val_expr<_Op>(_Op(__tanh_expr<value_type>(), __x));
}
template <class _Tp>
inline _LIBCPP_INLINE_VISIBILITY
_Tp*
begin(valarray<_Tp>& __v)
{
return __v.__begin_;
}
template <class _Tp>
inline _LIBCPP_INLINE_VISIBILITY
const _Tp*
begin(const valarray<_Tp>& __v)
{
return __v.__begin_;
}
template <class _Tp>
inline _LIBCPP_INLINE_VISIBILITY
_Tp*
end(valarray<_Tp>& __v)
{
return __v.__end_;
}
template <class _Tp>
inline _LIBCPP_INLINE_VISIBILITY
const _Tp*
end(const valarray<_Tp>& __v)
{
return __v.__end_;
}
_LIBCPP_END_NAMESPACE_STD
_LIBCPP_POP_MACROS
#endif // _LIBCPP_VALARRAY
| 136,004 | 4,944 | jart/cosmopolitan | false |
cosmopolitan/third_party/libcxx/map | // -*- C++ -*-
//===----------------------------- map ------------------------------------===//
//
// 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_MAP
#define _LIBCPP_MAP
#include "third_party/libcxx/__config"
#include "third_party/libcxx/__tree"
#include "third_party/libcxx/__node_handle"
#include "third_party/libcxx/iterator"
#include "third_party/libcxx/memory"
#include "third_party/libcxx/utility"
#include "third_party/libcxx/functional"
#include "third_party/libcxx/initializer_list"
#include "third_party/libcxx/type_traits"
#include "third_party/libcxx/version"
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
#pragma GCC system_header
#endif
_LIBCPP_BEGIN_NAMESPACE_STD
/*
map synopsis
namespace std
{
template <class Key, class T, class Compare = less<Key>,
class Allocator = allocator<pair<const Key, T>>>
class map
{
public:
// types:
typedef Key key_type;
typedef T mapped_type;
typedef pair<const key_type, mapped_type> value_type;
typedef Compare key_compare;
typedef Allocator allocator_type;
typedef typename allocator_type::reference reference;
typedef typename allocator_type::const_reference const_reference;
typedef typename allocator_type::pointer pointer;
typedef typename allocator_type::const_pointer const_pointer;
typedef typename allocator_type::size_type size_type;
typedef typename allocator_type::difference_type difference_type;
typedef implementation-defined iterator;
typedef implementation-defined const_iterator;
typedef std::reverse_iterator<iterator> reverse_iterator;
typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
typedef unspecified node_type; // C++17
typedef INSERT_RETURN_TYPE<iterator, node_type> insert_return_type; // C++17
class value_compare
: public binary_function<value_type, value_type, bool>
{
friend class map;
protected:
key_compare comp;
value_compare(key_compare c);
public:
bool operator()(const value_type& x, const value_type& y) const;
};
// construct/copy/destroy:
map()
noexcept(
is_nothrow_default_constructible<allocator_type>::value &&
is_nothrow_default_constructible<key_compare>::value &&
is_nothrow_copy_constructible<key_compare>::value);
explicit map(const key_compare& comp);
map(const key_compare& comp, const allocator_type& a);
template <class InputIterator>
map(InputIterator first, InputIterator last,
const key_compare& comp = key_compare());
template <class InputIterator>
map(InputIterator first, InputIterator last,
const key_compare& comp, const allocator_type& a);
map(const map& m);
map(map&& m)
noexcept(
is_nothrow_move_constructible<allocator_type>::value &&
is_nothrow_move_constructible<key_compare>::value);
explicit map(const allocator_type& a);
map(const map& m, const allocator_type& a);
map(map&& m, const allocator_type& a);
map(initializer_list<value_type> il, const key_compare& comp = key_compare());
map(initializer_list<value_type> il, const key_compare& comp, const allocator_type& a);
template <class InputIterator>
map(InputIterator first, InputIterator last, const allocator_type& a)
: map(first, last, Compare(), a) {} // C++14
map(initializer_list<value_type> il, const allocator_type& a)
: map(il, Compare(), a) {} // C++14
~map();
map& operator=(const map& m);
map& operator=(map&& m)
noexcept(
allocator_type::propagate_on_container_move_assignment::value &&
is_nothrow_move_assignable<allocator_type>::value &&
is_nothrow_move_assignable<key_compare>::value);
map& operator=(initializer_list<value_type> il);
// iterators:
iterator begin() noexcept;
const_iterator begin() const noexcept;
iterator end() noexcept;
const_iterator end() const noexcept;
reverse_iterator rbegin() noexcept;
const_reverse_iterator rbegin() const noexcept;
reverse_iterator rend() noexcept;
const_reverse_iterator rend() const noexcept;
const_iterator cbegin() const noexcept;
const_iterator cend() const noexcept;
const_reverse_iterator crbegin() const noexcept;
const_reverse_iterator crend() const noexcept;
// capacity:
bool empty() const noexcept;
size_type size() const noexcept;
size_type max_size() const noexcept;
// element access:
mapped_type& operator[](const key_type& k);
mapped_type& operator[](key_type&& k);
mapped_type& at(const key_type& k);
const mapped_type& at(const key_type& k) const;
// modifiers:
template <class... Args>
pair<iterator, bool> emplace(Args&&... args);
template <class... Args>
iterator emplace_hint(const_iterator position, Args&&... args);
pair<iterator, bool> insert(const value_type& v);
pair<iterator, bool> insert( value_type&& v); // C++17
template <class P>
pair<iterator, bool> insert(P&& p);
iterator insert(const_iterator position, const value_type& v);
iterator insert(const_iterator position, value_type&& v); // C++17
template <class P>
iterator insert(const_iterator position, P&& p);
template <class InputIterator>
void insert(InputIterator first, InputIterator last);
void insert(initializer_list<value_type> il);
node_type extract(const_iterator position); // C++17
node_type extract(const key_type& x); // C++17
insert_return_type insert(node_type&& nh); // C++17
iterator insert(const_iterator hint, node_type&& nh); // C++17
template <class... Args>
pair<iterator, bool> try_emplace(const key_type& k, Args&&... args); // C++17
template <class... Args>
pair<iterator, bool> try_emplace(key_type&& k, Args&&... args); // C++17
template <class... Args>
iterator try_emplace(const_iterator hint, const key_type& k, Args&&... args); // C++17
template <class... Args>
iterator try_emplace(const_iterator hint, key_type&& k, Args&&... args); // C++17
template <class M>
pair<iterator, bool> insert_or_assign(const key_type& k, M&& obj); // C++17
template <class M>
pair<iterator, bool> insert_or_assign(key_type&& k, M&& obj); // C++17
template <class M>
iterator insert_or_assign(const_iterator hint, const key_type& k, M&& obj); // C++17
template <class M>
iterator insert_or_assign(const_iterator hint, key_type&& k, M&& obj); // C++17
iterator erase(const_iterator position);
iterator erase(iterator position); // C++14
size_type erase(const key_type& k);
iterator erase(const_iterator first, const_iterator last);
void clear() noexcept;
template<class C2>
void merge(map<Key, T, C2, Allocator>& source); // C++17
template<class C2>
void merge(map<Key, T, C2, Allocator>&& source); // C++17
template<class C2>
void merge(multimap<Key, T, C2, Allocator>& source); // C++17
template<class C2>
void merge(multimap<Key, T, C2, Allocator>&& source); // C++17
void swap(map& m)
noexcept(allocator_traits<allocator_type>::is_always_equal::value &&
is_nothrow_swappable<key_compare>::value); // C++17
// observers:
allocator_type get_allocator() const noexcept;
key_compare key_comp() const;
value_compare value_comp() const;
// map operations:
iterator find(const key_type& k);
const_iterator find(const key_type& k) const;
template<typename K>
iterator find(const K& x); // C++14
template<typename K>
const_iterator find(const K& x) const; // C++14
template<typename K>
size_type count(const K& x) const; // C++14
size_type count(const key_type& k) const;
bool contains(const key_type& x) const; // C++20
iterator lower_bound(const key_type& k);
const_iterator lower_bound(const key_type& k) const;
template<typename K>
iterator lower_bound(const K& x); // C++14
template<typename K>
const_iterator lower_bound(const K& x) const; // C++14
iterator upper_bound(const key_type& k);
const_iterator upper_bound(const key_type& k) const;
template<typename K>
iterator upper_bound(const K& x); // C++14
template<typename K>
const_iterator upper_bound(const K& x) const; // C++14
pair<iterator,iterator> equal_range(const key_type& k);
pair<const_iterator,const_iterator> equal_range(const key_type& k) const;
template<typename K>
pair<iterator,iterator> equal_range(const K& x); // C++14
template<typename K>
pair<const_iterator,const_iterator> equal_range(const K& x) const; // C++14
};
template <class Key, class T, class Compare, class Allocator>
bool
operator==(const map<Key, T, Compare, Allocator>& x,
const map<Key, T, Compare, Allocator>& y);
template <class Key, class T, class Compare, class Allocator>
bool
operator< (const map<Key, T, Compare, Allocator>& x,
const map<Key, T, Compare, Allocator>& y);
template <class Key, class T, class Compare, class Allocator>
bool
operator!=(const map<Key, T, Compare, Allocator>& x,
const map<Key, T, Compare, Allocator>& y);
template <class Key, class T, class Compare, class Allocator>
bool
operator> (const map<Key, T, Compare, Allocator>& x,
const map<Key, T, Compare, Allocator>& y);
template <class Key, class T, class Compare, class Allocator>
bool
operator>=(const map<Key, T, Compare, Allocator>& x,
const map<Key, T, Compare, Allocator>& y);
template <class Key, class T, class Compare, class Allocator>
bool
operator<=(const map<Key, T, Compare, Allocator>& x,
const map<Key, T, Compare, Allocator>& y);
// specialized algorithms:
template <class Key, class T, class Compare, class Allocator>
void
swap(map<Key, T, Compare, Allocator>& x, map<Key, T, Compare, Allocator>& y)
noexcept(noexcept(x.swap(y)));
template <class Key, class T, class Compare, class Allocator, class Predicate>
void erase_if(map<Key, T, Compare, Allocator>& c, Predicate pred); // C++20
template <class Key, class T, class Compare = less<Key>,
class Allocator = allocator<pair<const Key, T>>>
class multimap
{
public:
// types:
typedef Key key_type;
typedef T mapped_type;
typedef pair<const key_type,mapped_type> value_type;
typedef Compare key_compare;
typedef Allocator allocator_type;
typedef typename allocator_type::reference reference;
typedef typename allocator_type::const_reference const_reference;
typedef typename allocator_type::size_type size_type;
typedef typename allocator_type::difference_type difference_type;
typedef typename allocator_type::pointer pointer;
typedef typename allocator_type::const_pointer const_pointer;
typedef implementation-defined iterator;
typedef implementation-defined const_iterator;
typedef std::reverse_iterator<iterator> reverse_iterator;
typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
typedef unspecified node_type; // C++17
class value_compare
: public binary_function<value_type,value_type,bool>
{
friend class multimap;
protected:
key_compare comp;
value_compare(key_compare c);
public:
bool operator()(const value_type& x, const value_type& y) const;
};
// construct/copy/destroy:
multimap()
noexcept(
is_nothrow_default_constructible<allocator_type>::value &&
is_nothrow_default_constructible<key_compare>::value &&
is_nothrow_copy_constructible<key_compare>::value);
explicit multimap(const key_compare& comp);
multimap(const key_compare& comp, const allocator_type& a);
template <class InputIterator>
multimap(InputIterator first, InputIterator last, const key_compare& comp);
template <class InputIterator>
multimap(InputIterator first, InputIterator last, const key_compare& comp,
const allocator_type& a);
multimap(const multimap& m);
multimap(multimap&& m)
noexcept(
is_nothrow_move_constructible<allocator_type>::value &&
is_nothrow_move_constructible<key_compare>::value);
explicit multimap(const allocator_type& a);
multimap(const multimap& m, const allocator_type& a);
multimap(multimap&& m, const allocator_type& a);
multimap(initializer_list<value_type> il, const key_compare& comp = key_compare());
multimap(initializer_list<value_type> il, const key_compare& comp,
const allocator_type& a);
template <class InputIterator>
multimap(InputIterator first, InputIterator last, const allocator_type& a)
: multimap(first, last, Compare(), a) {} // C++14
multimap(initializer_list<value_type> il, const allocator_type& a)
: multimap(il, Compare(), a) {} // C++14
~multimap();
multimap& operator=(const multimap& m);
multimap& operator=(multimap&& m)
noexcept(
allocator_type::propagate_on_container_move_assignment::value &&
is_nothrow_move_assignable<allocator_type>::value &&
is_nothrow_move_assignable<key_compare>::value);
multimap& operator=(initializer_list<value_type> il);
// iterators:
iterator begin() noexcept;
const_iterator begin() const noexcept;
iterator end() noexcept;
const_iterator end() const noexcept;
reverse_iterator rbegin() noexcept;
const_reverse_iterator rbegin() const noexcept;
reverse_iterator rend() noexcept;
const_reverse_iterator rend() const noexcept;
const_iterator cbegin() const noexcept;
const_iterator cend() const noexcept;
const_reverse_iterator crbegin() const noexcept;
const_reverse_iterator crend() const noexcept;
// capacity:
bool empty() const noexcept;
size_type size() const noexcept;
size_type max_size() const noexcept;
// modifiers:
template <class... Args>
iterator emplace(Args&&... args);
template <class... Args>
iterator emplace_hint(const_iterator position, Args&&... args);
iterator insert(const value_type& v);
iterator insert( value_type&& v); // C++17
template <class P>
iterator insert(P&& p);
iterator insert(const_iterator position, const value_type& v);
iterator insert(const_iterator position, value_type&& v); // C++17
template <class P>
iterator insert(const_iterator position, P&& p);
template <class InputIterator>
void insert(InputIterator first, InputIterator last);
void insert(initializer_list<value_type> il);
node_type extract(const_iterator position); // C++17
node_type extract(const key_type& x); // C++17
iterator insert(node_type&& nh); // C++17
iterator insert(const_iterator hint, node_type&& nh); // C++17
iterator erase(const_iterator position);
iterator erase(iterator position); // C++14
size_type erase(const key_type& k);
iterator erase(const_iterator first, const_iterator last);
void clear() noexcept;
template<class C2>
void merge(multimap<Key, T, C2, Allocator>& source); // C++17
template<class C2>
void merge(multimap<Key, T, C2, Allocator>&& source); // C++17
template<class C2>
void merge(map<Key, T, C2, Allocator>& source); // C++17
template<class C2>
void merge(map<Key, T, C2, Allocator>&& source); // C++17
void swap(multimap& m)
noexcept(allocator_traits<allocator_type>::is_always_equal::value &&
is_nothrow_swappable<key_compare>::value); // C++17
// observers:
allocator_type get_allocator() const noexcept;
key_compare key_comp() const;
value_compare value_comp() const;
// map operations:
iterator find(const key_type& k);
const_iterator find(const key_type& k) const;
template<typename K>
iterator find(const K& x); // C++14
template<typename K>
const_iterator find(const K& x) const; // C++14
template<typename K>
size_type count(const K& x) const; // C++14
size_type count(const key_type& k) const;
bool contains(const key_type& x) const; // C++20
iterator lower_bound(const key_type& k);
const_iterator lower_bound(const key_type& k) const;
template<typename K>
iterator lower_bound(const K& x); // C++14
template<typename K>
const_iterator lower_bound(const K& x) const; // C++14
iterator upper_bound(const key_type& k);
const_iterator upper_bound(const key_type& k) const;
template<typename K>
iterator upper_bound(const K& x); // C++14
template<typename K>
const_iterator upper_bound(const K& x) const; // C++14
pair<iterator,iterator> equal_range(const key_type& k);
pair<const_iterator,const_iterator> equal_range(const key_type& k) const;
template<typename K>
pair<iterator,iterator> equal_range(const K& x); // C++14
template<typename K>
pair<const_iterator,const_iterator> equal_range(const K& x) const; // C++14
};
template <class Key, class T, class Compare, class Allocator>
bool
operator==(const multimap<Key, T, Compare, Allocator>& x,
const multimap<Key, T, Compare, Allocator>& y);
template <class Key, class T, class Compare, class Allocator>
bool
operator< (const multimap<Key, T, Compare, Allocator>& x,
const multimap<Key, T, Compare, Allocator>& y);
template <class Key, class T, class Compare, class Allocator>
bool
operator!=(const multimap<Key, T, Compare, Allocator>& x,
const multimap<Key, T, Compare, Allocator>& y);
template <class Key, class T, class Compare, class Allocator>
bool
operator> (const multimap<Key, T, Compare, Allocator>& x,
const multimap<Key, T, Compare, Allocator>& y);
template <class Key, class T, class Compare, class Allocator>
bool
operator>=(const multimap<Key, T, Compare, Allocator>& x,
const multimap<Key, T, Compare, Allocator>& y);
template <class Key, class T, class Compare, class Allocator>
bool
operator<=(const multimap<Key, T, Compare, Allocator>& x,
const multimap<Key, T, Compare, Allocator>& y);
// specialized algorithms:
template <class Key, class T, class Compare, class Allocator>
void
swap(multimap<Key, T, Compare, Allocator>& x,
multimap<Key, T, Compare, Allocator>& y)
noexcept(noexcept(x.swap(y)));
template <class Key, class T, class Compare, class Allocator, class Predicate>
void erase_if(multimap<Key, T, Compare, Allocator>& c, Predicate pred); // C++20
} // std
*/
template <class _Key, class _CP, class _Compare,
bool = is_empty<_Compare>::value && !__libcpp_is_final<_Compare>::value>
class __map_value_compare
: private _Compare
{
public:
_LIBCPP_INLINE_VISIBILITY
__map_value_compare()
_NOEXCEPT_(is_nothrow_default_constructible<_Compare>::value)
: _Compare() {}
_LIBCPP_INLINE_VISIBILITY
__map_value_compare(_Compare c)
_NOEXCEPT_(is_nothrow_copy_constructible<_Compare>::value)
: _Compare(c) {}
_LIBCPP_INLINE_VISIBILITY
const _Compare& key_comp() const _NOEXCEPT {return *this;}
_LIBCPP_INLINE_VISIBILITY
bool operator()(const _CP& __x, const _CP& __y) const
{return static_cast<const _Compare&>(*this)(__x.__get_value().first, __y.__get_value().first);}
_LIBCPP_INLINE_VISIBILITY
bool operator()(const _CP& __x, const _Key& __y) const
{return static_cast<const _Compare&>(*this)(__x.__get_value().first, __y);}
_LIBCPP_INLINE_VISIBILITY
bool operator()(const _Key& __x, const _CP& __y) const
{return static_cast<const _Compare&>(*this)(__x, __y.__get_value().first);}
void swap(__map_value_compare&__y)
_NOEXCEPT_(__is_nothrow_swappable<_Compare>::value)
{
using _VSTD::swap;
swap(static_cast<_Compare&>(*this), static_cast<_Compare&>(__y));
}
#if _LIBCPP_STD_VER > 11
template <typename _K2>
_LIBCPP_INLINE_VISIBILITY
typename enable_if<__is_transparent<_Compare, _K2>::value, bool>::type
operator () ( const _K2& __x, const _CP& __y ) const
{return static_cast<const _Compare&>(*this) (__x, __y.__get_value().first);}
template <typename _K2>
_LIBCPP_INLINE_VISIBILITY
typename enable_if<__is_transparent<_Compare, _K2>::value, bool>::type
operator () (const _CP& __x, const _K2& __y) const
{return static_cast<const _Compare&>(*this) (__x.__get_value().first, __y);}
#endif
};
template <class _Key, class _CP, class _Compare>
class __map_value_compare<_Key, _CP, _Compare, false>
{
_Compare comp;
public:
_LIBCPP_INLINE_VISIBILITY
__map_value_compare()
_NOEXCEPT_(is_nothrow_default_constructible<_Compare>::value)
: comp() {}
_LIBCPP_INLINE_VISIBILITY
__map_value_compare(_Compare c)
_NOEXCEPT_(is_nothrow_copy_constructible<_Compare>::value)
: comp(c) {}
_LIBCPP_INLINE_VISIBILITY
const _Compare& key_comp() const _NOEXCEPT {return comp;}
_LIBCPP_INLINE_VISIBILITY
bool operator()(const _CP& __x, const _CP& __y) const
{return comp(__x.__get_value().first, __y.__get_value().first);}
_LIBCPP_INLINE_VISIBILITY
bool operator()(const _CP& __x, const _Key& __y) const
{return comp(__x.__get_value().first, __y);}
_LIBCPP_INLINE_VISIBILITY
bool operator()(const _Key& __x, const _CP& __y) const
{return comp(__x, __y.__get_value().first);}
void swap(__map_value_compare&__y)
_NOEXCEPT_(__is_nothrow_swappable<_Compare>::value)
{
using _VSTD::swap;
swap(comp, __y.comp);
}
#if _LIBCPP_STD_VER > 11
template <typename _K2>
_LIBCPP_INLINE_VISIBILITY
typename enable_if<__is_transparent<_Compare, _K2>::value, bool>::type
operator () ( const _K2& __x, const _CP& __y ) const
{return comp (__x, __y.__get_value().first);}
template <typename _K2>
_LIBCPP_INLINE_VISIBILITY
typename enable_if<__is_transparent<_Compare, _K2>::value, bool>::type
operator () (const _CP& __x, const _K2& __y) const
{return comp (__x.__get_value().first, __y);}
#endif
};
template <class _Key, class _CP, class _Compare, bool __b>
inline _LIBCPP_INLINE_VISIBILITY
void
swap(__map_value_compare<_Key, _CP, _Compare, __b>& __x,
__map_value_compare<_Key, _CP, _Compare, __b>& __y)
_NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
{
__x.swap(__y);
}
template <class _Allocator>
class __map_node_destructor
{
typedef _Allocator allocator_type;
typedef allocator_traits<allocator_type> __alloc_traits;
public:
typedef typename __alloc_traits::pointer pointer;
private:
allocator_type& __na_;
__map_node_destructor& operator=(const __map_node_destructor&);
public:
bool __first_constructed;
bool __second_constructed;
_LIBCPP_INLINE_VISIBILITY
explicit __map_node_destructor(allocator_type& __na) _NOEXCEPT
: __na_(__na),
__first_constructed(false),
__second_constructed(false)
{}
#ifndef _LIBCPP_CXX03_LANG
_LIBCPP_INLINE_VISIBILITY
__map_node_destructor(__tree_node_destructor<allocator_type>&& __x) _NOEXCEPT
: __na_(__x.__na_),
__first_constructed(__x.__value_constructed),
__second_constructed(__x.__value_constructed)
{
__x.__value_constructed = false;
}
#endif // _LIBCPP_CXX03_LANG
_LIBCPP_INLINE_VISIBILITY
void operator()(pointer __p) _NOEXCEPT
{
if (__second_constructed)
__alloc_traits::destroy(__na_, _VSTD::addressof(__p->__value_.__get_value().second));
if (__first_constructed)
__alloc_traits::destroy(__na_, _VSTD::addressof(__p->__value_.__get_value().first));
if (__p)
__alloc_traits::deallocate(__na_, __p, 1);
}
};
template <class _Key, class _Tp, class _Compare, class _Allocator>
class map;
template <class _Key, class _Tp, class _Compare, class _Allocator>
class multimap;
template <class _TreeIterator> class __map_const_iterator;
#ifndef _LIBCPP_CXX03_LANG
template <class _Key, class _Tp>
struct __value_type
{
typedef _Key key_type;
typedef _Tp mapped_type;
typedef pair<const key_type, mapped_type> value_type;
typedef pair<key_type&, mapped_type&> __nc_ref_pair_type;
typedef pair<key_type&&, mapped_type&&> __nc_rref_pair_type;
private:
value_type __cc;
public:
_LIBCPP_INLINE_VISIBILITY
value_type& __get_value()
{
#if _LIBCPP_STD_VER > 14
return *_VSTD::launder(_VSTD::addressof(__cc));
#else
return __cc;
#endif
}
_LIBCPP_INLINE_VISIBILITY
const value_type& __get_value() const
{
#if _LIBCPP_STD_VER > 14
return *_VSTD::launder(_VSTD::addressof(__cc));
#else
return __cc;
#endif
}
_LIBCPP_INLINE_VISIBILITY
__nc_ref_pair_type __ref()
{
value_type& __v = __get_value();
return __nc_ref_pair_type(const_cast<key_type&>(__v.first), __v.second);
}
_LIBCPP_INLINE_VISIBILITY
__nc_rref_pair_type __move()
{
value_type& __v = __get_value();
return __nc_rref_pair_type(
_VSTD::move(const_cast<key_type&>(__v.first)),
_VSTD::move(__v.second));
}
_LIBCPP_INLINE_VISIBILITY
__value_type& operator=(const __value_type& __v)
{
__ref() = __v.__get_value();
return *this;
}
_LIBCPP_INLINE_VISIBILITY
__value_type& operator=(__value_type&& __v)
{
__ref() = __v.__move();
return *this;
}
template <class _ValueTp,
class = typename enable_if<
__is_same_uncvref<_ValueTp, value_type>::value
>::type
>
_LIBCPP_INLINE_VISIBILITY
__value_type& operator=(_ValueTp&& __v)
{
__ref() = _VSTD::forward<_ValueTp>(__v);
return *this;
}
private:
__value_type() _LIBCPP_EQUAL_DELETE;
~__value_type() _LIBCPP_EQUAL_DELETE;
__value_type(const __value_type& __v) _LIBCPP_EQUAL_DELETE;
__value_type(__value_type&& __v) _LIBCPP_EQUAL_DELETE;
};
#else
template <class _Key, class _Tp>
struct __value_type
{
typedef _Key key_type;
typedef _Tp mapped_type;
typedef pair<const key_type, mapped_type> value_type;
private:
value_type __cc;
public:
_LIBCPP_INLINE_VISIBILITY
value_type& __get_value() { return __cc; }
_LIBCPP_INLINE_VISIBILITY
const value_type& __get_value() const { return __cc; }
private:
__value_type();
__value_type(__value_type const&);
__value_type& operator=(__value_type const&);
~__value_type();
};
#endif // _LIBCPP_CXX03_LANG
template <class _Tp>
struct __extract_key_value_types;
template <class _Key, class _Tp>
struct __extract_key_value_types<__value_type<_Key, _Tp> >
{
typedef _Key const __key_type;
typedef _Tp __mapped_type;
};
template <class _TreeIterator>
class _LIBCPP_TEMPLATE_VIS __map_iterator
{
typedef typename _TreeIterator::_NodeTypes _NodeTypes;
typedef typename _TreeIterator::__pointer_traits __pointer_traits;
_TreeIterator __i_;
public:
typedef bidirectional_iterator_tag iterator_category;
typedef typename _NodeTypes::__map_value_type value_type;
typedef typename _TreeIterator::difference_type difference_type;
typedef value_type& reference;
typedef typename _NodeTypes::__map_value_type_pointer pointer;
_LIBCPP_INLINE_VISIBILITY
__map_iterator() _NOEXCEPT {}
_LIBCPP_INLINE_VISIBILITY
__map_iterator(_TreeIterator __i) _NOEXCEPT : __i_(__i) {}
_LIBCPP_INLINE_VISIBILITY
reference operator*() const {return __i_->__get_value();}
_LIBCPP_INLINE_VISIBILITY
pointer operator->() const {return pointer_traits<pointer>::pointer_to(__i_->__get_value());}
_LIBCPP_INLINE_VISIBILITY
__map_iterator& operator++() {++__i_; return *this;}
_LIBCPP_INLINE_VISIBILITY
__map_iterator operator++(int)
{
__map_iterator __t(*this);
++(*this);
return __t;
}
_LIBCPP_INLINE_VISIBILITY
__map_iterator& operator--() {--__i_; return *this;}
_LIBCPP_INLINE_VISIBILITY
__map_iterator operator--(int)
{
__map_iterator __t(*this);
--(*this);
return __t;
}
friend _LIBCPP_INLINE_VISIBILITY
bool operator==(const __map_iterator& __x, const __map_iterator& __y)
{return __x.__i_ == __y.__i_;}
friend
_LIBCPP_INLINE_VISIBILITY
bool operator!=(const __map_iterator& __x, const __map_iterator& __y)
{return __x.__i_ != __y.__i_;}
template <class, class, class, class> friend class _LIBCPP_TEMPLATE_VIS map;
template <class, class, class, class> friend class _LIBCPP_TEMPLATE_VIS multimap;
template <class> friend class _LIBCPP_TEMPLATE_VIS __map_const_iterator;
};
template <class _TreeIterator>
class _LIBCPP_TEMPLATE_VIS __map_const_iterator
{
typedef typename _TreeIterator::_NodeTypes _NodeTypes;
typedef typename _TreeIterator::__pointer_traits __pointer_traits;
_TreeIterator __i_;
public:
typedef bidirectional_iterator_tag iterator_category;
typedef typename _NodeTypes::__map_value_type value_type;
typedef typename _TreeIterator::difference_type difference_type;
typedef const value_type& reference;
typedef typename _NodeTypes::__const_map_value_type_pointer pointer;
_LIBCPP_INLINE_VISIBILITY
__map_const_iterator() _NOEXCEPT {}
_LIBCPP_INLINE_VISIBILITY
__map_const_iterator(_TreeIterator __i) _NOEXCEPT : __i_(__i) {}
_LIBCPP_INLINE_VISIBILITY
__map_const_iterator(__map_iterator<
typename _TreeIterator::__non_const_iterator> __i) _NOEXCEPT
: __i_(__i.__i_) {}
_LIBCPP_INLINE_VISIBILITY
reference operator*() const {return __i_->__get_value();}
_LIBCPP_INLINE_VISIBILITY
pointer operator->() const {return pointer_traits<pointer>::pointer_to(__i_->__get_value());}
_LIBCPP_INLINE_VISIBILITY
__map_const_iterator& operator++() {++__i_; return *this;}
_LIBCPP_INLINE_VISIBILITY
__map_const_iterator operator++(int)
{
__map_const_iterator __t(*this);
++(*this);
return __t;
}
_LIBCPP_INLINE_VISIBILITY
__map_const_iterator& operator--() {--__i_; return *this;}
_LIBCPP_INLINE_VISIBILITY
__map_const_iterator operator--(int)
{
__map_const_iterator __t(*this);
--(*this);
return __t;
}
friend _LIBCPP_INLINE_VISIBILITY
bool operator==(const __map_const_iterator& __x, const __map_const_iterator& __y)
{return __x.__i_ == __y.__i_;}
friend _LIBCPP_INLINE_VISIBILITY
bool operator!=(const __map_const_iterator& __x, const __map_const_iterator& __y)
{return __x.__i_ != __y.__i_;}
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 __tree_const_iterator;
};
template <class _Key, class _Tp, class _Compare = less<_Key>,
class _Allocator = allocator<pair<const _Key, _Tp> > >
class _LIBCPP_TEMPLATE_VIS map
{
public:
// types:
typedef _Key key_type;
typedef _Tp mapped_type;
typedef pair<const key_type, mapped_type> value_type;
typedef typename __identity<_Compare>::type key_compare;
typedef typename __identity<_Allocator>::type allocator_type;
typedef value_type& reference;
typedef const value_type& const_reference;
static_assert((is_same<typename allocator_type::value_type, value_type>::value),
"Allocator::value_type must be same type as value_type");
class _LIBCPP_TEMPLATE_VIS value_compare
: public binary_function<value_type, value_type, bool>
{
friend class map;
protected:
key_compare comp;
_LIBCPP_INLINE_VISIBILITY value_compare(key_compare c) : comp(c) {}
public:
_LIBCPP_INLINE_VISIBILITY
bool operator()(const value_type& __x, const value_type& __y) const
{return comp(__x.first, __y.first);}
};
private:
typedef _VSTD::__value_type<key_type, mapped_type> __value_type;
typedef __map_value_compare<key_type, __value_type, key_compare> __vc;
typedef typename __rebind_alloc_helper<allocator_traits<allocator_type>,
__value_type>::type __allocator_type;
typedef __tree<__value_type, __vc, __allocator_type> __base;
typedef typename __base::__node_traits __node_traits;
typedef allocator_traits<allocator_type> __alloc_traits;
__base __tree_;
public:
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;
typedef __map_iterator<typename __base::iterator> iterator;
typedef __map_const_iterator<typename __base::const_iterator> const_iterator;
typedef _VSTD::reverse_iterator<iterator> reverse_iterator;
typedef _VSTD::reverse_iterator<const_iterator> const_reverse_iterator;
#if _LIBCPP_STD_VER > 14
typedef __map_node_handle<typename __base::__node, allocator_type> node_type;
typedef __insert_return_type<iterator, node_type> insert_return_type;
#endif
template <class _Key2, class _Value2, class _Comp2, class _Alloc2>
friend class _LIBCPP_TEMPLATE_VIS map;
template <class _Key2, class _Value2, class _Comp2, class _Alloc2>
friend class _LIBCPP_TEMPLATE_VIS multimap;
_LIBCPP_INLINE_VISIBILITY
map()
_NOEXCEPT_(
is_nothrow_default_constructible<allocator_type>::value &&
is_nothrow_default_constructible<key_compare>::value &&
is_nothrow_copy_constructible<key_compare>::value)
: __tree_(__vc(key_compare())) {}
_LIBCPP_INLINE_VISIBILITY
explicit map(const key_compare& __comp)
_NOEXCEPT_(
is_nothrow_default_constructible<allocator_type>::value &&
is_nothrow_copy_constructible<key_compare>::value)
: __tree_(__vc(__comp)) {}
_LIBCPP_INLINE_VISIBILITY
explicit map(const key_compare& __comp, const allocator_type& __a)
: __tree_(__vc(__comp), typename __base::allocator_type(__a)) {}
template <class _InputIterator>
_LIBCPP_INLINE_VISIBILITY
map(_InputIterator __f, _InputIterator __l,
const key_compare& __comp = key_compare())
: __tree_(__vc(__comp))
{
insert(__f, __l);
}
template <class _InputIterator>
_LIBCPP_INLINE_VISIBILITY
map(_InputIterator __f, _InputIterator __l,
const key_compare& __comp, const allocator_type& __a)
: __tree_(__vc(__comp), typename __base::allocator_type(__a))
{
insert(__f, __l);
}
#if _LIBCPP_STD_VER > 11
template <class _InputIterator>
_LIBCPP_INLINE_VISIBILITY
map(_InputIterator __f, _InputIterator __l, const allocator_type& __a)
: map(__f, __l, key_compare(), __a) {}
#endif
_LIBCPP_INLINE_VISIBILITY
map(const map& __m)
: __tree_(__m.__tree_)
{
insert(__m.begin(), __m.end());
}
_LIBCPP_INLINE_VISIBILITY
map& operator=(const map& __m)
{
#ifndef _LIBCPP_CXX03_LANG
__tree_ = __m.__tree_;
#else
if (this != &__m) {
__tree_.clear();
__tree_.value_comp() = __m.__tree_.value_comp();
__tree_.__copy_assign_alloc(__m.__tree_);
insert(__m.begin(), __m.end());
}
#endif
return *this;
}
#ifndef _LIBCPP_CXX03_LANG
_LIBCPP_INLINE_VISIBILITY
map(map&& __m)
_NOEXCEPT_(is_nothrow_move_constructible<__base>::value)
: __tree_(_VSTD::move(__m.__tree_))
{
}
map(map&& __m, const allocator_type& __a);
_LIBCPP_INLINE_VISIBILITY
map& operator=(map&& __m)
_NOEXCEPT_(is_nothrow_move_assignable<__base>::value)
{
__tree_ = _VSTD::move(__m.__tree_);
return *this;
}
_LIBCPP_INLINE_VISIBILITY
map(initializer_list<value_type> __il, const key_compare& __comp = key_compare())
: __tree_(__vc(__comp))
{
insert(__il.begin(), __il.end());
}
_LIBCPP_INLINE_VISIBILITY
map(initializer_list<value_type> __il, const key_compare& __comp, const allocator_type& __a)
: __tree_(__vc(__comp), typename __base::allocator_type(__a))
{
insert(__il.begin(), __il.end());
}
#if _LIBCPP_STD_VER > 11
_LIBCPP_INLINE_VISIBILITY
map(initializer_list<value_type> __il, const allocator_type& __a)
: map(__il, key_compare(), __a) {}
#endif
_LIBCPP_INLINE_VISIBILITY
map& operator=(initializer_list<value_type> __il)
{
__tree_.__assign_unique(__il.begin(), __il.end());
return *this;
}
#endif // _LIBCPP_CXX03_LANG
_LIBCPP_INLINE_VISIBILITY
explicit map(const allocator_type& __a)
: __tree_(typename __base::allocator_type(__a))
{
}
_LIBCPP_INLINE_VISIBILITY
map(const map& __m, const allocator_type& __a)
: __tree_(__m.__tree_.value_comp(), typename __base::allocator_type(__a))
{
insert(__m.begin(), __m.end());
}
_LIBCPP_INLINE_VISIBILITY
~map() {
static_assert(sizeof(__diagnose_non_const_comparator<_Key, _Compare>()), "");
}
_LIBCPP_INLINE_VISIBILITY
iterator begin() _NOEXCEPT {return __tree_.begin();}
_LIBCPP_INLINE_VISIBILITY
const_iterator begin() const _NOEXCEPT {return __tree_.begin();}
_LIBCPP_INLINE_VISIBILITY
iterator end() _NOEXCEPT {return __tree_.end();}
_LIBCPP_INLINE_VISIBILITY
const_iterator end() const _NOEXCEPT {return __tree_.end();}
_LIBCPP_INLINE_VISIBILITY
reverse_iterator rbegin() _NOEXCEPT {return reverse_iterator(end());}
_LIBCPP_INLINE_VISIBILITY
const_reverse_iterator rbegin() const _NOEXCEPT
{return const_reverse_iterator(end());}
_LIBCPP_INLINE_VISIBILITY
reverse_iterator rend() _NOEXCEPT
{return reverse_iterator(begin());}
_LIBCPP_INLINE_VISIBILITY
const_reverse_iterator rend() const _NOEXCEPT
{return const_reverse_iterator(begin());}
_LIBCPP_INLINE_VISIBILITY
const_iterator cbegin() const _NOEXCEPT {return begin();}
_LIBCPP_INLINE_VISIBILITY
const_iterator cend() const _NOEXCEPT {return end();}
_LIBCPP_INLINE_VISIBILITY
const_reverse_iterator crbegin() const _NOEXCEPT {return rbegin();}
_LIBCPP_INLINE_VISIBILITY
const_reverse_iterator crend() const _NOEXCEPT {return rend();}
_LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
bool empty() const _NOEXCEPT {return __tree_.size() == 0;}
_LIBCPP_INLINE_VISIBILITY
size_type size() const _NOEXCEPT {return __tree_.size();}
_LIBCPP_INLINE_VISIBILITY
size_type max_size() const _NOEXCEPT {return __tree_.max_size();}
mapped_type& operator[](const key_type& __k);
#ifndef _LIBCPP_CXX03_LANG
mapped_type& operator[](key_type&& __k);
#endif
mapped_type& at(const key_type& __k);
const mapped_type& at(const key_type& __k) const;
_LIBCPP_INLINE_VISIBILITY
allocator_type get_allocator() const _NOEXCEPT {return allocator_type(__tree_.__alloc());}
_LIBCPP_INLINE_VISIBILITY
key_compare key_comp() const {return __tree_.value_comp().key_comp();}
_LIBCPP_INLINE_VISIBILITY
value_compare value_comp() const {return value_compare(__tree_.value_comp().key_comp());}
#ifndef _LIBCPP_CXX03_LANG
template <class ..._Args>
_LIBCPP_INLINE_VISIBILITY
pair<iterator, bool> emplace(_Args&& ...__args) {
return __tree_.__emplace_unique(_VSTD::forward<_Args>(__args)...);
}
template <class ..._Args>
_LIBCPP_INLINE_VISIBILITY
iterator emplace_hint(const_iterator __p, _Args&& ...__args) {
return __tree_.__emplace_hint_unique(__p.__i_, _VSTD::forward<_Args>(__args)...);
}
template <class _Pp,
class = typename enable_if<is_constructible<value_type, _Pp>::value>::type>
_LIBCPP_INLINE_VISIBILITY
pair<iterator, bool> insert(_Pp&& __p)
{return __tree_.__insert_unique(_VSTD::forward<_Pp>(__p));}
template <class _Pp,
class = typename enable_if<is_constructible<value_type, _Pp>::value>::type>
_LIBCPP_INLINE_VISIBILITY
iterator insert(const_iterator __pos, _Pp&& __p)
{return __tree_.__insert_unique(__pos.__i_, _VSTD::forward<_Pp>(__p));}
#endif // _LIBCPP_CXX03_LANG
_LIBCPP_INLINE_VISIBILITY
pair<iterator, bool>
insert(const value_type& __v) {return __tree_.__insert_unique(__v);}
_LIBCPP_INLINE_VISIBILITY
iterator
insert(const_iterator __p, const value_type& __v)
{return __tree_.__insert_unique(__p.__i_, __v);}
#ifndef _LIBCPP_CXX03_LANG
_LIBCPP_INLINE_VISIBILITY
pair<iterator, bool>
insert(value_type&& __v) {return __tree_.__insert_unique(_VSTD::move(__v));}
_LIBCPP_INLINE_VISIBILITY
iterator insert(const_iterator __p, value_type&& __v)
{return __tree_.__insert_unique(__p.__i_, _VSTD::move(__v));}
_LIBCPP_INLINE_VISIBILITY
void insert(initializer_list<value_type> __il)
{insert(__il.begin(), __il.end());}
#endif
template <class _InputIterator>
_LIBCPP_INLINE_VISIBILITY
void insert(_InputIterator __f, _InputIterator __l)
{
for (const_iterator __e = cend(); __f != __l; ++__f)
insert(__e.__i_, *__f);
}
#if _LIBCPP_STD_VER > 14
template <class... _Args>
_LIBCPP_INLINE_VISIBILITY
pair<iterator, bool> try_emplace(const key_type& __k, _Args&&... __args)
{
return __tree_.__emplace_unique_key_args(__k,
_VSTD::piecewise_construct,
_VSTD::forward_as_tuple(__k),
_VSTD::forward_as_tuple(_VSTD::forward<_Args>(__args)...));
}
template <class... _Args>
_LIBCPP_INLINE_VISIBILITY
pair<iterator, bool> try_emplace(key_type&& __k, _Args&&... __args)
{
return __tree_.__emplace_unique_key_args(__k,
_VSTD::piecewise_construct,
_VSTD::forward_as_tuple(_VSTD::move(__k)),
_VSTD::forward_as_tuple(_VSTD::forward<_Args>(__args)...));
}
template <class... _Args>
_LIBCPP_INLINE_VISIBILITY
iterator try_emplace(const_iterator __h, const key_type& __k, _Args&&... __args)
{
return __tree_.__emplace_hint_unique_key_args(__h.__i_, __k,
_VSTD::piecewise_construct,
_VSTD::forward_as_tuple(__k),
_VSTD::forward_as_tuple(_VSTD::forward<_Args>(__args)...));
}
template <class... _Args>
_LIBCPP_INLINE_VISIBILITY
iterator try_emplace(const_iterator __h, key_type&& __k, _Args&&... __args)
{
return __tree_.__emplace_hint_unique_key_args(__h.__i_, __k,
_VSTD::piecewise_construct,
_VSTD::forward_as_tuple(_VSTD::move(__k)),
_VSTD::forward_as_tuple(_VSTD::forward<_Args>(__args)...));
}
template <class _Vp>
_LIBCPP_INLINE_VISIBILITY
pair<iterator, bool> insert_or_assign(const key_type& __k, _Vp&& __v)
{
iterator __p = lower_bound(__k);
if ( __p != end() && !key_comp()(__k, __p->first))
{
__p->second = _VSTD::forward<_Vp>(__v);
return _VSTD::make_pair(__p, false);
}
return _VSTD::make_pair(emplace_hint(__p, __k, _VSTD::forward<_Vp>(__v)), true);
}
template <class _Vp>
_LIBCPP_INLINE_VISIBILITY
pair<iterator, bool> insert_or_assign(key_type&& __k, _Vp&& __v)
{
iterator __p = lower_bound(__k);
if ( __p != end() && !key_comp()(__k, __p->first))
{
__p->second = _VSTD::forward<_Vp>(__v);
return _VSTD::make_pair(__p, false);
}
return _VSTD::make_pair(emplace_hint(__p, _VSTD::move(__k), _VSTD::forward<_Vp>(__v)), true);
}
template <class _Vp>
_LIBCPP_INLINE_VISIBILITY
iterator insert_or_assign(const_iterator __h, const key_type& __k, _Vp&& __v)
{
iterator __p = lower_bound(__k);
if ( __p != end() && !key_comp()(__k, __p->first))
{
__p->second = _VSTD::forward<_Vp>(__v);
return __p;
}
return emplace_hint(__h, __k, _VSTD::forward<_Vp>(__v));
}
template <class _Vp>
_LIBCPP_INLINE_VISIBILITY
iterator insert_or_assign(const_iterator __h, key_type&& __k, _Vp&& __v)
{
iterator __p = lower_bound(__k);
if ( __p != end() && !key_comp()(__k, __p->first))
{
__p->second = _VSTD::forward<_Vp>(__v);
return __p;
}
return emplace_hint(__h, _VSTD::move(__k), _VSTD::forward<_Vp>(__v));
}
#endif // _LIBCPP_STD_VER > 14
_LIBCPP_INLINE_VISIBILITY
iterator erase(const_iterator __p) {return __tree_.erase(__p.__i_);}
_LIBCPP_INLINE_VISIBILITY
iterator erase(iterator __p) {return __tree_.erase(__p.__i_);}
_LIBCPP_INLINE_VISIBILITY
size_type erase(const key_type& __k)
{return __tree_.__erase_unique(__k);}
_LIBCPP_INLINE_VISIBILITY
iterator erase(const_iterator __f, const_iterator __l)
{return __tree_.erase(__f.__i_, __l.__i_);}
_LIBCPP_INLINE_VISIBILITY
void clear() _NOEXCEPT {__tree_.clear();}
#if _LIBCPP_STD_VER > 14
_LIBCPP_INLINE_VISIBILITY
insert_return_type insert(node_type&& __nh)
{
_LIBCPP_ASSERT(__nh.empty() || __nh.get_allocator() == get_allocator(),
"node_type with incompatible allocator passed to map::insert()");
return __tree_.template __node_handle_insert_unique<
node_type, insert_return_type>(_VSTD::move(__nh));
}
_LIBCPP_INLINE_VISIBILITY
iterator insert(const_iterator __hint, node_type&& __nh)
{
_LIBCPP_ASSERT(__nh.empty() || __nh.get_allocator() == get_allocator(),
"node_type with incompatible allocator passed to map::insert()");
return __tree_.template __node_handle_insert_unique<node_type>(
__hint.__i_, _VSTD::move(__nh));
}
_LIBCPP_INLINE_VISIBILITY
node_type extract(key_type const& __key)
{
return __tree_.template __node_handle_extract<node_type>(__key);
}
_LIBCPP_INLINE_VISIBILITY
node_type extract(const_iterator __it)
{
return __tree_.template __node_handle_extract<node_type>(__it.__i_);
}
template <class _Compare2>
_LIBCPP_INLINE_VISIBILITY
void merge(map<key_type, mapped_type, _Compare2, allocator_type>& __source)
{
_LIBCPP_ASSERT(__source.get_allocator() == get_allocator(),
"merging container with incompatible allocator");
__tree_.__node_handle_merge_unique(__source.__tree_);
}
template <class _Compare2>
_LIBCPP_INLINE_VISIBILITY
void merge(map<key_type, mapped_type, _Compare2, allocator_type>&& __source)
{
_LIBCPP_ASSERT(__source.get_allocator() == get_allocator(),
"merging container with incompatible allocator");
__tree_.__node_handle_merge_unique(__source.__tree_);
}
template <class _Compare2>
_LIBCPP_INLINE_VISIBILITY
void merge(multimap<key_type, mapped_type, _Compare2, allocator_type>& __source)
{
_LIBCPP_ASSERT(__source.get_allocator() == get_allocator(),
"merging container with incompatible allocator");
__tree_.__node_handle_merge_unique(__source.__tree_);
}
template <class _Compare2>
_LIBCPP_INLINE_VISIBILITY
void merge(multimap<key_type, mapped_type, _Compare2, allocator_type>&& __source)
{
_LIBCPP_ASSERT(__source.get_allocator() == get_allocator(),
"merging container with incompatible allocator");
__tree_.__node_handle_merge_unique(__source.__tree_);
}
#endif
_LIBCPP_INLINE_VISIBILITY
void swap(map& __m)
_NOEXCEPT_(__is_nothrow_swappable<__base>::value)
{__tree_.swap(__m.__tree_);}
_LIBCPP_INLINE_VISIBILITY
iterator find(const key_type& __k) {return __tree_.find(__k);}
_LIBCPP_INLINE_VISIBILITY
const_iterator find(const key_type& __k) const {return __tree_.find(__k);}
#if _LIBCPP_STD_VER > 11
template <typename _K2>
_LIBCPP_INLINE_VISIBILITY
typename enable_if<__is_transparent<_Compare, _K2>::value,iterator>::type
find(const _K2& __k) {return __tree_.find(__k);}
template <typename _K2>
_LIBCPP_INLINE_VISIBILITY
typename enable_if<__is_transparent<_Compare, _K2>::value,const_iterator>::type
find(const _K2& __k) const {return __tree_.find(__k);}
#endif
_LIBCPP_INLINE_VISIBILITY
size_type count(const key_type& __k) const
{return __tree_.__count_unique(__k);}
#if _LIBCPP_STD_VER > 11
template <typename _K2>
_LIBCPP_INLINE_VISIBILITY
typename enable_if<__is_transparent<_Compare, _K2>::value,size_type>::type
count(const _K2& __k) const {return __tree_.__count_multi(__k);}
#endif
#if _LIBCPP_STD_VER > 17
_LIBCPP_INLINE_VISIBILITY
bool contains(const key_type& __k) const {return find(__k) != end();}
#endif // _LIBCPP_STD_VER > 17
_LIBCPP_INLINE_VISIBILITY
iterator lower_bound(const key_type& __k)
{return __tree_.lower_bound(__k);}
_LIBCPP_INLINE_VISIBILITY
const_iterator lower_bound(const key_type& __k) const
{return __tree_.lower_bound(__k);}
#if _LIBCPP_STD_VER > 11
template <typename _K2>
_LIBCPP_INLINE_VISIBILITY
typename enable_if<__is_transparent<_Compare, _K2>::value,iterator>::type
lower_bound(const _K2& __k) {return __tree_.lower_bound(__k);}
template <typename _K2>
_LIBCPP_INLINE_VISIBILITY
typename enable_if<__is_transparent<_Compare, _K2>::value,const_iterator>::type
lower_bound(const _K2& __k) const {return __tree_.lower_bound(__k);}
#endif
_LIBCPP_INLINE_VISIBILITY
iterator upper_bound(const key_type& __k)
{return __tree_.upper_bound(__k);}
_LIBCPP_INLINE_VISIBILITY
const_iterator upper_bound(const key_type& __k) const
{return __tree_.upper_bound(__k);}
#if _LIBCPP_STD_VER > 11
template <typename _K2>
_LIBCPP_INLINE_VISIBILITY
typename enable_if<__is_transparent<_Compare, _K2>::value,iterator>::type
upper_bound(const _K2& __k) {return __tree_.upper_bound(__k);}
template <typename _K2>
_LIBCPP_INLINE_VISIBILITY
typename enable_if<__is_transparent<_Compare, _K2>::value,const_iterator>::type
upper_bound(const _K2& __k) const {return __tree_.upper_bound(__k);}
#endif
_LIBCPP_INLINE_VISIBILITY
pair<iterator,iterator> equal_range(const key_type& __k)
{return __tree_.__equal_range_unique(__k);}
_LIBCPP_INLINE_VISIBILITY
pair<const_iterator,const_iterator> equal_range(const key_type& __k) const
{return __tree_.__equal_range_unique(__k);}
#if _LIBCPP_STD_VER > 11
template <typename _K2>
_LIBCPP_INLINE_VISIBILITY
typename enable_if<__is_transparent<_Compare, _K2>::value,pair<iterator,iterator>>::type
equal_range(const _K2& __k) {return __tree_.__equal_range_multi(__k);}
template <typename _K2>
_LIBCPP_INLINE_VISIBILITY
typename enable_if<__is_transparent<_Compare, _K2>::value,pair<const_iterator,const_iterator>>::type
equal_range(const _K2& __k) const {return __tree_.__equal_range_multi(__k);}
#endif
private:
typedef typename __base::__node __node;
typedef typename __base::__node_allocator __node_allocator;
typedef typename __base::__node_pointer __node_pointer;
typedef typename __base::__node_base_pointer __node_base_pointer;
typedef typename __base::__parent_pointer __parent_pointer;
typedef __map_node_destructor<__node_allocator> _Dp;
typedef unique_ptr<__node, _Dp> __node_holder;
#ifdef _LIBCPP_CXX03_LANG
__node_holder __construct_node_with_key(const key_type& __k);
#endif
};
#ifndef _LIBCPP_HAS_NO_DEDUCTION_GUIDES
template<class _InputIterator, class _Compare = less<__iter_key_type<_InputIterator>>,
class _Allocator = allocator<__iter_to_alloc_type<_InputIterator>>,
class = _EnableIf<!__is_allocator<_Compare>::value, void>,
class = _EnableIf<__is_allocator<_Allocator>::value, void>>
map(_InputIterator, _InputIterator, _Compare = _Compare(), _Allocator = _Allocator())
-> map<__iter_key_type<_InputIterator>, __iter_mapped_type<_InputIterator>, _Compare, _Allocator>;
template<class _Key, class _Tp, class _Compare = less<remove_const_t<_Key>>,
class _Allocator = allocator<pair<const _Key, _Tp>>,
class = _EnableIf<!__is_allocator<_Compare>::value, void>,
class = _EnableIf<__is_allocator<_Allocator>::value, void>>
map(initializer_list<pair<_Key, _Tp>>, _Compare = _Compare(), _Allocator = _Allocator())
-> map<remove_const_t<_Key>, _Tp, _Compare, _Allocator>;
template<class _InputIterator, class _Allocator,
class = _EnableIf<__is_allocator<_Allocator>::value, void>>
map(_InputIterator, _InputIterator, _Allocator)
-> map<__iter_key_type<_InputIterator>, __iter_mapped_type<_InputIterator>,
less<__iter_key_type<_InputIterator>>, _Allocator>;
template<class _Key, class _Tp, class _Allocator,
class = _EnableIf<__is_allocator<_Allocator>::value, void>>
map(initializer_list<pair<_Key, _Tp>>, _Allocator)
-> map<remove_const_t<_Key>, _Tp, less<remove_const_t<_Key>>, _Allocator>;
#endif
#ifndef _LIBCPP_CXX03_LANG
template <class _Key, class _Tp, class _Compare, class _Allocator>
map<_Key, _Tp, _Compare, _Allocator>::map(map&& __m, const allocator_type& __a)
: __tree_(_VSTD::move(__m.__tree_), typename __base::allocator_type(__a))
{
if (__a != __m.get_allocator())
{
const_iterator __e = cend();
while (!__m.empty())
__tree_.__insert_unique(__e.__i_,
__m.__tree_.remove(__m.begin().__i_)->__value_.__move());
}
}
template <class _Key, class _Tp, class _Compare, class _Allocator>
_Tp&
map<_Key, _Tp, _Compare, _Allocator>::operator[](const key_type& __k)
{
return __tree_.__emplace_unique_key_args(__k,
_VSTD::piecewise_construct,
_VSTD::forward_as_tuple(__k),
_VSTD::forward_as_tuple()).first->__get_value().second;
}
template <class _Key, class _Tp, class _Compare, class _Allocator>
_Tp&
map<_Key, _Tp, _Compare, _Allocator>::operator[](key_type&& __k)
{
return __tree_.__emplace_unique_key_args(__k,
_VSTD::piecewise_construct,
_VSTD::forward_as_tuple(_VSTD::move(__k)),
_VSTD::forward_as_tuple()).first->__get_value().second;
}
#else // _LIBCPP_CXX03_LANG
template <class _Key, class _Tp, class _Compare, class _Allocator>
typename map<_Key, _Tp, _Compare, _Allocator>::__node_holder
map<_Key, _Tp, _Compare, _Allocator>::__construct_node_with_key(const key_type& __k)
{
__node_allocator& __na = __tree_.__node_alloc();
__node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na));
__node_traits::construct(__na, _VSTD::addressof(__h->__value_.__get_value().first), __k);
__h.get_deleter().__first_constructed = true;
__node_traits::construct(__na, _VSTD::addressof(__h->__value_.__get_value().second));
__h.get_deleter().__second_constructed = true;
return _LIBCPP_EXPLICIT_MOVE(__h); // explicitly moved for C++03
}
template <class _Key, class _Tp, class _Compare, class _Allocator>
_Tp&
map<_Key, _Tp, _Compare, _Allocator>::operator[](const key_type& __k)
{
__parent_pointer __parent;
__node_base_pointer& __child = __tree_.__find_equal(__parent, __k);
__node_pointer __r = static_cast<__node_pointer>(__child);
if (__child == nullptr)
{
__node_holder __h = __construct_node_with_key(__k);
__tree_.__insert_node_at(__parent, __child, static_cast<__node_base_pointer>(__h.get()));
__r = __h.release();
}
return __r->__value_.__get_value().second;
}
#endif // _LIBCPP_CXX03_LANG
template <class _Key, class _Tp, class _Compare, class _Allocator>
_Tp&
map<_Key, _Tp, _Compare, _Allocator>::at(const key_type& __k)
{
__parent_pointer __parent;
__node_base_pointer& __child = __tree_.__find_equal(__parent, __k);
if (__child == nullptr)
__throw_out_of_range("map::at: key not found");
return static_cast<__node_pointer>(__child)->__value_.__get_value().second;
}
template <class _Key, class _Tp, class _Compare, class _Allocator>
const _Tp&
map<_Key, _Tp, _Compare, _Allocator>::at(const key_type& __k) const
{
__parent_pointer __parent;
__node_base_pointer __child = __tree_.__find_equal(__parent, __k);
if (__child == nullptr)
__throw_out_of_range("map::at: key not found");
return static_cast<__node_pointer>(__child)->__value_.__get_value().second;
}
template <class _Key, class _Tp, class _Compare, class _Allocator>
inline _LIBCPP_INLINE_VISIBILITY
bool
operator==(const map<_Key, _Tp, _Compare, _Allocator>& __x,
const map<_Key, _Tp, _Compare, _Allocator>& __y)
{
return __x.size() == __y.size() && _VSTD::equal(__x.begin(), __x.end(), __y.begin());
}
template <class _Key, class _Tp, class _Compare, class _Allocator>
inline _LIBCPP_INLINE_VISIBILITY
bool
operator< (const map<_Key, _Tp, _Compare, _Allocator>& __x,
const map<_Key, _Tp, _Compare, _Allocator>& __y)
{
return _VSTD::lexicographical_compare(__x.begin(), __x.end(), __y.begin(), __y.end());
}
template <class _Key, class _Tp, class _Compare, class _Allocator>
inline _LIBCPP_INLINE_VISIBILITY
bool
operator!=(const map<_Key, _Tp, _Compare, _Allocator>& __x,
const map<_Key, _Tp, _Compare, _Allocator>& __y)
{
return !(__x == __y);
}
template <class _Key, class _Tp, class _Compare, class _Allocator>
inline _LIBCPP_INLINE_VISIBILITY
bool
operator> (const map<_Key, _Tp, _Compare, _Allocator>& __x,
const map<_Key, _Tp, _Compare, _Allocator>& __y)
{
return __y < __x;
}
template <class _Key, class _Tp, class _Compare, class _Allocator>
inline _LIBCPP_INLINE_VISIBILITY
bool
operator>=(const map<_Key, _Tp, _Compare, _Allocator>& __x,
const map<_Key, _Tp, _Compare, _Allocator>& __y)
{
return !(__x < __y);
}
template <class _Key, class _Tp, class _Compare, class _Allocator>
inline _LIBCPP_INLINE_VISIBILITY
bool
operator<=(const map<_Key, _Tp, _Compare, _Allocator>& __x,
const map<_Key, _Tp, _Compare, _Allocator>& __y)
{
return !(__y < __x);
}
template <class _Key, class _Tp, class _Compare, class _Allocator>
inline _LIBCPP_INLINE_VISIBILITY
void
swap(map<_Key, _Tp, _Compare, _Allocator>& __x,
map<_Key, _Tp, _Compare, _Allocator>& __y)
_NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
{
__x.swap(__y);
}
#if _LIBCPP_STD_VER > 17
template <class _Key, class _Tp, class _Compare, class _Allocator, class _Predicate>
inline _LIBCPP_INLINE_VISIBILITY
void erase_if(map<_Key, _Tp, _Compare, _Allocator>& __c, _Predicate __pred)
{ __libcpp_erase_if_container(__c, __pred); }
#endif
template <class _Key, class _Tp, class _Compare = less<_Key>,
class _Allocator = allocator<pair<const _Key, _Tp> > >
class _LIBCPP_TEMPLATE_VIS multimap
{
public:
// types:
typedef _Key key_type;
typedef _Tp mapped_type;
typedef pair<const key_type, mapped_type> value_type;
typedef typename __identity<_Compare>::type key_compare;
typedef typename __identity<_Allocator>::type allocator_type;
typedef value_type& reference;
typedef const value_type& const_reference;
static_assert((is_same<typename allocator_type::value_type, value_type>::value),
"Allocator::value_type must be same type as value_type");
class _LIBCPP_TEMPLATE_VIS value_compare
: public binary_function<value_type, value_type, bool>
{
friend class multimap;
protected:
key_compare comp;
_LIBCPP_INLINE_VISIBILITY
value_compare(key_compare c) : comp(c) {}
public:
_LIBCPP_INLINE_VISIBILITY
bool operator()(const value_type& __x, const value_type& __y) const
{return comp(__x.first, __y.first);}
};
private:
typedef _VSTD::__value_type<key_type, mapped_type> __value_type;
typedef __map_value_compare<key_type, __value_type, key_compare> __vc;
typedef typename __rebind_alloc_helper<allocator_traits<allocator_type>,
__value_type>::type __allocator_type;
typedef __tree<__value_type, __vc, __allocator_type> __base;
typedef typename __base::__node_traits __node_traits;
typedef allocator_traits<allocator_type> __alloc_traits;
__base __tree_;
public:
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;
typedef __map_iterator<typename __base::iterator> iterator;
typedef __map_const_iterator<typename __base::const_iterator> const_iterator;
typedef _VSTD::reverse_iterator<iterator> reverse_iterator;
typedef _VSTD::reverse_iterator<const_iterator> const_reverse_iterator;
#if _LIBCPP_STD_VER > 14
typedef __map_node_handle<typename __base::__node, allocator_type> node_type;
#endif
template <class _Key2, class _Value2, class _Comp2, class _Alloc2>
friend class _LIBCPP_TEMPLATE_VIS map;
template <class _Key2, class _Value2, class _Comp2, class _Alloc2>
friend class _LIBCPP_TEMPLATE_VIS multimap;
_LIBCPP_INLINE_VISIBILITY
multimap()
_NOEXCEPT_(
is_nothrow_default_constructible<allocator_type>::value &&
is_nothrow_default_constructible<key_compare>::value &&
is_nothrow_copy_constructible<key_compare>::value)
: __tree_(__vc(key_compare())) {}
_LIBCPP_INLINE_VISIBILITY
explicit multimap(const key_compare& __comp)
_NOEXCEPT_(
is_nothrow_default_constructible<allocator_type>::value &&
is_nothrow_copy_constructible<key_compare>::value)
: __tree_(__vc(__comp)) {}
_LIBCPP_INLINE_VISIBILITY
explicit multimap(const key_compare& __comp, const allocator_type& __a)
: __tree_(__vc(__comp), typename __base::allocator_type(__a)) {}
template <class _InputIterator>
_LIBCPP_INLINE_VISIBILITY
multimap(_InputIterator __f, _InputIterator __l,
const key_compare& __comp = key_compare())
: __tree_(__vc(__comp))
{
insert(__f, __l);
}
template <class _InputIterator>
_LIBCPP_INLINE_VISIBILITY
multimap(_InputIterator __f, _InputIterator __l,
const key_compare& __comp, const allocator_type& __a)
: __tree_(__vc(__comp), typename __base::allocator_type(__a))
{
insert(__f, __l);
}
#if _LIBCPP_STD_VER > 11
template <class _InputIterator>
_LIBCPP_INLINE_VISIBILITY
multimap(_InputIterator __f, _InputIterator __l, const allocator_type& __a)
: multimap(__f, __l, key_compare(), __a) {}
#endif
_LIBCPP_INLINE_VISIBILITY
multimap(const multimap& __m)
: __tree_(__m.__tree_.value_comp(),
__alloc_traits::select_on_container_copy_construction(__m.__tree_.__alloc()))
{
insert(__m.begin(), __m.end());
}
_LIBCPP_INLINE_VISIBILITY
multimap& operator=(const multimap& __m)
{
#ifndef _LIBCPP_CXX03_LANG
__tree_ = __m.__tree_;
#else
if (this != &__m) {
__tree_.clear();
__tree_.value_comp() = __m.__tree_.value_comp();
__tree_.__copy_assign_alloc(__m.__tree_);
insert(__m.begin(), __m.end());
}
#endif
return *this;
}
#ifndef _LIBCPP_CXX03_LANG
_LIBCPP_INLINE_VISIBILITY
multimap(multimap&& __m)
_NOEXCEPT_(is_nothrow_move_constructible<__base>::value)
: __tree_(_VSTD::move(__m.__tree_))
{
}
multimap(multimap&& __m, const allocator_type& __a);
_LIBCPP_INLINE_VISIBILITY
multimap& operator=(multimap&& __m)
_NOEXCEPT_(is_nothrow_move_assignable<__base>::value)
{
__tree_ = _VSTD::move(__m.__tree_);
return *this;
}
_LIBCPP_INLINE_VISIBILITY
multimap(initializer_list<value_type> __il, const key_compare& __comp = key_compare())
: __tree_(__vc(__comp))
{
insert(__il.begin(), __il.end());
}
_LIBCPP_INLINE_VISIBILITY
multimap(initializer_list<value_type> __il, const key_compare& __comp, const allocator_type& __a)
: __tree_(__vc(__comp), typename __base::allocator_type(__a))
{
insert(__il.begin(), __il.end());
}
#if _LIBCPP_STD_VER > 11
_LIBCPP_INLINE_VISIBILITY
multimap(initializer_list<value_type> __il, const allocator_type& __a)
: multimap(__il, key_compare(), __a) {}
#endif
_LIBCPP_INLINE_VISIBILITY
multimap& operator=(initializer_list<value_type> __il)
{
__tree_.__assign_multi(__il.begin(), __il.end());
return *this;
}
#endif // _LIBCPP_CXX03_LANG
_LIBCPP_INLINE_VISIBILITY
explicit multimap(const allocator_type& __a)
: __tree_(typename __base::allocator_type(__a))
{
}
_LIBCPP_INLINE_VISIBILITY
multimap(const multimap& __m, const allocator_type& __a)
: __tree_(__m.__tree_.value_comp(), typename __base::allocator_type(__a))
{
insert(__m.begin(), __m.end());
}
_LIBCPP_INLINE_VISIBILITY
~multimap() {
static_assert(sizeof(__diagnose_non_const_comparator<_Key, _Compare>()), "");
}
_LIBCPP_INLINE_VISIBILITY
iterator begin() _NOEXCEPT {return __tree_.begin();}
_LIBCPP_INLINE_VISIBILITY
const_iterator begin() const _NOEXCEPT {return __tree_.begin();}
_LIBCPP_INLINE_VISIBILITY
iterator end() _NOEXCEPT {return __tree_.end();}
_LIBCPP_INLINE_VISIBILITY
const_iterator end() const _NOEXCEPT {return __tree_.end();}
_LIBCPP_INLINE_VISIBILITY
reverse_iterator rbegin() _NOEXCEPT {return reverse_iterator(end());}
_LIBCPP_INLINE_VISIBILITY
const_reverse_iterator rbegin() const _NOEXCEPT
{return const_reverse_iterator(end());}
_LIBCPP_INLINE_VISIBILITY
reverse_iterator rend() _NOEXCEPT {return reverse_iterator(begin());}
_LIBCPP_INLINE_VISIBILITY
const_reverse_iterator rend() const _NOEXCEPT
{return const_reverse_iterator(begin());}
_LIBCPP_INLINE_VISIBILITY
const_iterator cbegin() const _NOEXCEPT {return begin();}
_LIBCPP_INLINE_VISIBILITY
const_iterator cend() const _NOEXCEPT {return end();}
_LIBCPP_INLINE_VISIBILITY
const_reverse_iterator crbegin() const _NOEXCEPT {return rbegin();}
_LIBCPP_INLINE_VISIBILITY
const_reverse_iterator crend() const _NOEXCEPT {return rend();}
_LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
bool empty() const _NOEXCEPT {return __tree_.size() == 0;}
_LIBCPP_INLINE_VISIBILITY
size_type size() const _NOEXCEPT {return __tree_.size();}
_LIBCPP_INLINE_VISIBILITY
size_type max_size() const _NOEXCEPT {return __tree_.max_size();}
_LIBCPP_INLINE_VISIBILITY
allocator_type get_allocator() const _NOEXCEPT {return allocator_type(__tree_.__alloc());}
_LIBCPP_INLINE_VISIBILITY
key_compare key_comp() const {return __tree_.value_comp().key_comp();}
_LIBCPP_INLINE_VISIBILITY
value_compare value_comp() const
{return value_compare(__tree_.value_comp().key_comp());}
#ifndef _LIBCPP_CXX03_LANG
template <class ..._Args>
_LIBCPP_INLINE_VISIBILITY
iterator emplace(_Args&& ...__args) {
return __tree_.__emplace_multi(_VSTD::forward<_Args>(__args)...);
}
template <class ..._Args>
_LIBCPP_INLINE_VISIBILITY
iterator emplace_hint(const_iterator __p, _Args&& ...__args) {
return __tree_.__emplace_hint_multi(__p.__i_, _VSTD::forward<_Args>(__args)...);
}
template <class _Pp,
class = typename enable_if<is_constructible<value_type, _Pp>::value>::type>
_LIBCPP_INLINE_VISIBILITY
iterator insert(_Pp&& __p)
{return __tree_.__insert_multi(_VSTD::forward<_Pp>(__p));}
template <class _Pp,
class = typename enable_if<is_constructible<value_type, _Pp>::value>::type>
_LIBCPP_INLINE_VISIBILITY
iterator insert(const_iterator __pos, _Pp&& __p)
{return __tree_.__insert_multi(__pos.__i_, _VSTD::forward<_Pp>(__p));}
_LIBCPP_INLINE_VISIBILITY
iterator insert(value_type&& __v)
{return __tree_.__insert_multi(_VSTD::move(__v));}
_LIBCPP_INLINE_VISIBILITY
iterator insert(const_iterator __p, value_type&& __v)
{return __tree_.__insert_multi(__p.__i_, _VSTD::move(__v));}
_LIBCPP_INLINE_VISIBILITY
void insert(initializer_list<value_type> __il)
{insert(__il.begin(), __il.end());}
#endif // _LIBCPP_CXX03_LANG
_LIBCPP_INLINE_VISIBILITY
iterator insert(const value_type& __v) {return __tree_.__insert_multi(__v);}
_LIBCPP_INLINE_VISIBILITY
iterator insert(const_iterator __p, const value_type& __v)
{return __tree_.__insert_multi(__p.__i_, __v);}
template <class _InputIterator>
_LIBCPP_INLINE_VISIBILITY
void insert(_InputIterator __f, _InputIterator __l)
{
for (const_iterator __e = cend(); __f != __l; ++__f)
__tree_.__insert_multi(__e.__i_, *__f);
}
_LIBCPP_INLINE_VISIBILITY
iterator erase(const_iterator __p) {return __tree_.erase(__p.__i_);}
_LIBCPP_INLINE_VISIBILITY
iterator erase(iterator __p) {return __tree_.erase(__p.__i_);}
_LIBCPP_INLINE_VISIBILITY
size_type erase(const key_type& __k) {return __tree_.__erase_multi(__k);}
_LIBCPP_INLINE_VISIBILITY
iterator erase(const_iterator __f, const_iterator __l)
{return __tree_.erase(__f.__i_, __l.__i_);}
#if _LIBCPP_STD_VER > 14
_LIBCPP_INLINE_VISIBILITY
iterator insert(node_type&& __nh)
{
_LIBCPP_ASSERT(__nh.empty() || __nh.get_allocator() == get_allocator(),
"node_type with incompatible allocator passed to multimap::insert()");
return __tree_.template __node_handle_insert_multi<node_type>(
_VSTD::move(__nh));
}
_LIBCPP_INLINE_VISIBILITY
iterator insert(const_iterator __hint, node_type&& __nh)
{
_LIBCPP_ASSERT(__nh.empty() || __nh.get_allocator() == get_allocator(),
"node_type with incompatible allocator passed to multimap::insert()");
return __tree_.template __node_handle_insert_multi<node_type>(
__hint.__i_, _VSTD::move(__nh));
}
_LIBCPP_INLINE_VISIBILITY
node_type extract(key_type const& __key)
{
return __tree_.template __node_handle_extract<node_type>(__key);
}
_LIBCPP_INLINE_VISIBILITY
node_type extract(const_iterator __it)
{
return __tree_.template __node_handle_extract<node_type>(
__it.__i_);
}
template <class _Compare2>
_LIBCPP_INLINE_VISIBILITY
void merge(multimap<key_type, mapped_type, _Compare2, allocator_type>& __source)
{
_LIBCPP_ASSERT(__source.get_allocator() == get_allocator(),
"merging container with incompatible allocator");
return __tree_.__node_handle_merge_multi(__source.__tree_);
}
template <class _Compare2>
_LIBCPP_INLINE_VISIBILITY
void merge(multimap<key_type, mapped_type, _Compare2, allocator_type>&& __source)
{
_LIBCPP_ASSERT(__source.get_allocator() == get_allocator(),
"merging container with incompatible allocator");
return __tree_.__node_handle_merge_multi(__source.__tree_);
}
template <class _Compare2>
_LIBCPP_INLINE_VISIBILITY
void merge(map<key_type, mapped_type, _Compare2, allocator_type>& __source)
{
_LIBCPP_ASSERT(__source.get_allocator() == get_allocator(),
"merging container with incompatible allocator");
return __tree_.__node_handle_merge_multi(__source.__tree_);
}
template <class _Compare2>
_LIBCPP_INLINE_VISIBILITY
void merge(map<key_type, mapped_type, _Compare2, allocator_type>&& __source)
{
_LIBCPP_ASSERT(__source.get_allocator() == get_allocator(),
"merging container with incompatible allocator");
return __tree_.__node_handle_merge_multi(__source.__tree_);
}
#endif
_LIBCPP_INLINE_VISIBILITY
void clear() _NOEXCEPT {__tree_.clear();}
_LIBCPP_INLINE_VISIBILITY
void swap(multimap& __m)
_NOEXCEPT_(__is_nothrow_swappable<__base>::value)
{__tree_.swap(__m.__tree_);}
_LIBCPP_INLINE_VISIBILITY
iterator find(const key_type& __k) {return __tree_.find(__k);}
_LIBCPP_INLINE_VISIBILITY
const_iterator find(const key_type& __k) const {return __tree_.find(__k);}
#if _LIBCPP_STD_VER > 11
template <typename _K2>
_LIBCPP_INLINE_VISIBILITY
typename enable_if<__is_transparent<_Compare, _K2>::value,iterator>::type
find(const _K2& __k) {return __tree_.find(__k);}
template <typename _K2>
_LIBCPP_INLINE_VISIBILITY
typename enable_if<__is_transparent<_Compare, _K2>::value,const_iterator>::type
find(const _K2& __k) const {return __tree_.find(__k);}
#endif
_LIBCPP_INLINE_VISIBILITY
size_type count(const key_type& __k) const
{return __tree_.__count_multi(__k);}
#if _LIBCPP_STD_VER > 11
template <typename _K2>
_LIBCPP_INLINE_VISIBILITY
typename enable_if<__is_transparent<_Compare, _K2>::value,size_type>::type
count(const _K2& __k) const {return __tree_.__count_multi(__k);}
#endif
#if _LIBCPP_STD_VER > 17
_LIBCPP_INLINE_VISIBILITY
bool contains(const key_type& __k) const {return find(__k) != end();}
#endif // _LIBCPP_STD_VER > 17
_LIBCPP_INLINE_VISIBILITY
iterator lower_bound(const key_type& __k)
{return __tree_.lower_bound(__k);}
_LIBCPP_INLINE_VISIBILITY
const_iterator lower_bound(const key_type& __k) const
{return __tree_.lower_bound(__k);}
#if _LIBCPP_STD_VER > 11
template <typename _K2>
_LIBCPP_INLINE_VISIBILITY
typename enable_if<__is_transparent<_Compare, _K2>::value,iterator>::type
lower_bound(const _K2& __k) {return __tree_.lower_bound(__k);}
template <typename _K2>
_LIBCPP_INLINE_VISIBILITY
typename enable_if<__is_transparent<_Compare, _K2>::value,const_iterator>::type
lower_bound(const _K2& __k) const {return __tree_.lower_bound(__k);}
#endif
_LIBCPP_INLINE_VISIBILITY
iterator upper_bound(const key_type& __k)
{return __tree_.upper_bound(__k);}
_LIBCPP_INLINE_VISIBILITY
const_iterator upper_bound(const key_type& __k) const
{return __tree_.upper_bound(__k);}
#if _LIBCPP_STD_VER > 11
template <typename _K2>
_LIBCPP_INLINE_VISIBILITY
typename enable_if<__is_transparent<_Compare, _K2>::value,iterator>::type
upper_bound(const _K2& __k) {return __tree_.upper_bound(__k);}
template <typename _K2>
_LIBCPP_INLINE_VISIBILITY
typename enable_if<__is_transparent<_Compare, _K2>::value,const_iterator>::type
upper_bound(const _K2& __k) const {return __tree_.upper_bound(__k);}
#endif
_LIBCPP_INLINE_VISIBILITY
pair<iterator,iterator> equal_range(const key_type& __k)
{return __tree_.__equal_range_multi(__k);}
_LIBCPP_INLINE_VISIBILITY
pair<const_iterator,const_iterator> equal_range(const key_type& __k) const
{return __tree_.__equal_range_multi(__k);}
#if _LIBCPP_STD_VER > 11
template <typename _K2>
_LIBCPP_INLINE_VISIBILITY
typename enable_if<__is_transparent<_Compare, _K2>::value,pair<iterator,iterator>>::type
equal_range(const _K2& __k) {return __tree_.__equal_range_multi(__k);}
template <typename _K2>
_LIBCPP_INLINE_VISIBILITY
typename enable_if<__is_transparent<_Compare, _K2>::value,pair<const_iterator,const_iterator>>::type
equal_range(const _K2& __k) const {return __tree_.__equal_range_multi(__k);}
#endif
private:
typedef typename __base::__node __node;
typedef typename __base::__node_allocator __node_allocator;
typedef typename __base::__node_pointer __node_pointer;
typedef __map_node_destructor<__node_allocator> _Dp;
typedef unique_ptr<__node, _Dp> __node_holder;
};
#ifndef _LIBCPP_HAS_NO_DEDUCTION_GUIDES
template<class _InputIterator, class _Compare = less<__iter_key_type<_InputIterator>>,
class _Allocator = allocator<__iter_to_alloc_type<_InputIterator>>,
class = _EnableIf<!__is_allocator<_Compare>::value, void>,
class = _EnableIf<__is_allocator<_Allocator>::value, void>>
multimap(_InputIterator, _InputIterator, _Compare = _Compare(), _Allocator = _Allocator())
-> multimap<__iter_key_type<_InputIterator>, __iter_mapped_type<_InputIterator>, _Compare, _Allocator>;
template<class _Key, class _Tp, class _Compare = less<remove_const_t<_Key>>,
class _Allocator = allocator<pair<const _Key, _Tp>>,
class = _EnableIf<!__is_allocator<_Compare>::value, void>,
class = _EnableIf<__is_allocator<_Allocator>::value, void>>
multimap(initializer_list<pair<_Key, _Tp>>, _Compare = _Compare(), _Allocator = _Allocator())
-> multimap<remove_const_t<_Key>, _Tp, _Compare, _Allocator>;
template<class _InputIterator, class _Allocator,
class = _EnableIf<__is_allocator<_Allocator>::value, void>>
multimap(_InputIterator, _InputIterator, _Allocator)
-> multimap<__iter_key_type<_InputIterator>, __iter_mapped_type<_InputIterator>,
less<__iter_key_type<_InputIterator>>, _Allocator>;
template<class _Key, class _Tp, class _Allocator,
class = _EnableIf<__is_allocator<_Allocator>::value, void>>
multimap(initializer_list<pair<_Key, _Tp>>, _Allocator)
-> multimap<remove_const_t<_Key>, _Tp, less<remove_const_t<_Key>>, _Allocator>;
#endif
#ifndef _LIBCPP_CXX03_LANG
template <class _Key, class _Tp, class _Compare, class _Allocator>
multimap<_Key, _Tp, _Compare, _Allocator>::multimap(multimap&& __m, const allocator_type& __a)
: __tree_(_VSTD::move(__m.__tree_), typename __base::allocator_type(__a))
{
if (__a != __m.get_allocator())
{
const_iterator __e = cend();
while (!__m.empty())
__tree_.__insert_multi(__e.__i_,
_VSTD::move(__m.__tree_.remove(__m.begin().__i_)->__value_.__move()));
}
}
#endif
template <class _Key, class _Tp, class _Compare, class _Allocator>
inline _LIBCPP_INLINE_VISIBILITY
bool
operator==(const multimap<_Key, _Tp, _Compare, _Allocator>& __x,
const multimap<_Key, _Tp, _Compare, _Allocator>& __y)
{
return __x.size() == __y.size() && _VSTD::equal(__x.begin(), __x.end(), __y.begin());
}
template <class _Key, class _Tp, class _Compare, class _Allocator>
inline _LIBCPP_INLINE_VISIBILITY
bool
operator< (const multimap<_Key, _Tp, _Compare, _Allocator>& __x,
const multimap<_Key, _Tp, _Compare, _Allocator>& __y)
{
return _VSTD::lexicographical_compare(__x.begin(), __x.end(), __y.begin(), __y.end());
}
template <class _Key, class _Tp, class _Compare, class _Allocator>
inline _LIBCPP_INLINE_VISIBILITY
bool
operator!=(const multimap<_Key, _Tp, _Compare, _Allocator>& __x,
const multimap<_Key, _Tp, _Compare, _Allocator>& __y)
{
return !(__x == __y);
}
template <class _Key, class _Tp, class _Compare, class _Allocator>
inline _LIBCPP_INLINE_VISIBILITY
bool
operator> (const multimap<_Key, _Tp, _Compare, _Allocator>& __x,
const multimap<_Key, _Tp, _Compare, _Allocator>& __y)
{
return __y < __x;
}
template <class _Key, class _Tp, class _Compare, class _Allocator>
inline _LIBCPP_INLINE_VISIBILITY
bool
operator>=(const multimap<_Key, _Tp, _Compare, _Allocator>& __x,
const multimap<_Key, _Tp, _Compare, _Allocator>& __y)
{
return !(__x < __y);
}
template <class _Key, class _Tp, class _Compare, class _Allocator>
inline _LIBCPP_INLINE_VISIBILITY
bool
operator<=(const multimap<_Key, _Tp, _Compare, _Allocator>& __x,
const multimap<_Key, _Tp, _Compare, _Allocator>& __y)
{
return !(__y < __x);
}
template <class _Key, class _Tp, class _Compare, class _Allocator>
inline _LIBCPP_INLINE_VISIBILITY
void
swap(multimap<_Key, _Tp, _Compare, _Allocator>& __x,
multimap<_Key, _Tp, _Compare, _Allocator>& __y)
_NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
{
__x.swap(__y);
}
#if _LIBCPP_STD_VER > 17
template <class _Key, class _Tp, class _Compare, class _Allocator, class _Predicate>
inline _LIBCPP_INLINE_VISIBILITY
void erase_if(multimap<_Key, _Tp, _Compare, _Allocator>& __c, _Predicate __pred)
{ __libcpp_erase_if_container(__c, __pred); }
#endif
_LIBCPP_END_NAMESPACE_STD
#endif // _LIBCPP_MAP
| 84,490 | 2,247 | jart/cosmopolitan | false |
cosmopolitan/third_party/libcxx/exception.cc | //===------------------------ exception.cpp -------------------------------===//
//
// 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
//
//===----------------------------------------------------------------------===//
#include "third_party/libcxx/__config"
#include "third_party/libcxx/exception"
#include "third_party/libcxx/new"
#include "third_party/libcxx/typeinfo"
#include "third_party/libcxx/atomic_support.hh"
#include "third_party/libcxx/exception_fallback.hh"
#include "third_party/libcxx/exception_pointer_unimplemented.hh"
| 688 | 17 | jart/cosmopolitan | false |
cosmopolitan/third_party/libcxx/random | // -*- C++ -*-
//===--------------------------- random -----------------------------------===//
//
// 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
#define _LIBCPP_RANDOM
#include "third_party/libcxx/__config"
#include "third_party/libcxx/cstddef"
#include "third_party/libcxx/cstdint"
#include "third_party/libcxx/cmath"
#include "third_party/libcxx/type_traits"
#include "third_party/libcxx/initializer_list"
#include "third_party/libcxx/limits"
#include "third_party/libcxx/algorithm"
#include "third_party/libcxx/numeric"
#include "third_party/libcxx/vector"
#include "third_party/libcxx/string"
#include "third_party/libcxx/istream"
#include "third_party/libcxx/ostream"
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
#pragma GCC system_header
#endif
_LIBCPP_PUSH_MACROS
#include "third_party/libcxx/__undef_macros"
_LIBCPP_BEGIN_NAMESPACE_STD
/*
random synopsis
#include "third_party/libcxx/initializer_list"
namespace std
{
// Engines
template <class UIntType, UIntType a, UIntType c, UIntType m>
class linear_congruential_engine
{
public:
// types
typedef UIntType result_type;
// engine characteristics
static constexpr result_type multiplier = a;
static constexpr result_type increment = c;
static constexpr result_type modulus = m;
static constexpr result_type min() { return c == 0u ? 1u: 0u;}
static constexpr result_type max() { return m - 1u;}
static constexpr result_type default_seed = 1u;
// constructors and seeding functions
explicit linear_congruential_engine(result_type s = default_seed);
template<class Sseq> explicit linear_congruential_engine(Sseq& q);
void seed(result_type s = default_seed);
template<class Sseq> void seed(Sseq& q);
// generating functions
result_type operator()();
void discard(unsigned long long z);
};
template <class UIntType, UIntType a, UIntType c, UIntType m>
bool
operator==(const linear_congruential_engine<UIntType, a, c, m>& x,
const linear_congruential_engine<UIntType, a, c, m>& y);
template <class UIntType, UIntType a, UIntType c, UIntType m>
bool
operator!=(const linear_congruential_engine<UIntType, a, c, m>& x,
const linear_congruential_engine<UIntType, a, c, m>& y);
template <class charT, class traits,
class UIntType, UIntType a, UIntType c, UIntType m>
basic_ostream<charT, traits>&
operator<<(basic_ostream<charT, traits>& os,
const linear_congruential_engine<UIntType, a, c, m>& 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);
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 mersenne_twister_engine
{
public:
// types
typedef UIntType result_type;
// engine characteristics
static constexpr size_t word_size = w;
static constexpr size_t state_size = n;
static constexpr size_t shift_size = m;
static constexpr size_t mask_bits = r;
static constexpr result_type xor_mask = a;
static constexpr size_t tempering_u = u;
static constexpr result_type tempering_d = d;
static constexpr size_t tempering_s = s;
static constexpr result_type tempering_b = b;
static constexpr size_t tempering_t = t;
static constexpr result_type tempering_c = c;
static constexpr size_t tempering_l = l;
static constexpr result_type initialization_multiplier = f;
static constexpr result_type min () { return 0; }
static constexpr result_type max() { return 2^w - 1; }
static constexpr result_type default_seed = 5489u;
// constructors and seeding functions
explicit mersenne_twister_engine(result_type value = default_seed);
template<class Sseq> explicit mersenne_twister_engine(Sseq& q);
void seed(result_type value = default_seed);
template<class Sseq> void seed(Sseq& q);
// generating functions
result_type operator()();
void discard(unsigned long long z);
};
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>
bool
operator==(
const mersenne_twister_engine<UIntType, w, n, m, r, a, u, d, s, b, t, c, l, f>& x,
const mersenne_twister_engine<UIntType, w, n, m, r, a, u, d, s, b, t, c, l, f>& y);
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>
bool
operator!=(
const mersenne_twister_engine<UIntType, w, n, m, r, a, u, d, s, b, t, c, l, f>& x,
const mersenne_twister_engine<UIntType, w, n, m, r, a, u, d, s, b, t, c, l, f>& y);
template <class charT, class traits,
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>
basic_ostream<charT, traits>&
operator<<(basic_ostream<charT, traits>& os,
const mersenne_twister_engine<UIntType, w, n, m, r, a, u, d, s, b, t, c, l, f>& x);
template <class charT, class traits,
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>
basic_istream<charT, traits>&
operator>>(basic_istream<charT, traits>& is,
mersenne_twister_engine<UIntType, w, n, m, r, a, u, d, s, b, t, c, l, f>& x);
template<class UIntType, size_t w, size_t s, size_t r>
class subtract_with_carry_engine
{
public:
// types
typedef UIntType result_type;
// engine characteristics
static constexpr size_t word_size = w;
static constexpr size_t short_lag = s;
static constexpr size_t long_lag = r;
static constexpr result_type min() { return 0; }
static constexpr result_type max() { return m-1; }
static constexpr result_type default_seed = 19780503u;
// constructors and seeding functions
explicit subtract_with_carry_engine(result_type value = default_seed);
template<class Sseq> explicit subtract_with_carry_engine(Sseq& q);
void seed(result_type value = default_seed);
template<class Sseq> void seed(Sseq& q);
// generating functions
result_type operator()();
void discard(unsigned long long z);
};
template<class UIntType, size_t w, size_t s, size_t r>
bool
operator==(
const subtract_with_carry_engine<UIntType, w, s, r>& x,
const subtract_with_carry_engine<UIntType, w, s, r>& y);
template<class UIntType, size_t w, size_t s, size_t r>
bool
operator!=(
const subtract_with_carry_engine<UIntType, w, s, r>& x,
const subtract_with_carry_engine<UIntType, w, s, r>& y);
template <class charT, class traits,
class UIntType, size_t w, size_t s, size_t r>
basic_ostream<charT, traits>&
operator<<(basic_ostream<charT, traits>& os,
const subtract_with_carry_engine<UIntType, w, s, r>& x);
template <class charT, class traits,
class UIntType, size_t w, size_t s, size_t r>
basic_istream<charT, traits>&
operator>>(basic_istream<charT, traits>& is,
subtract_with_carry_engine<UIntType, w, s, r>& x);
template<class Engine, size_t p, size_t r>
class discard_block_engine
{
public:
// types
typedef typename Engine::result_type result_type;
// engine characteristics
static constexpr size_t block_size = p;
static constexpr size_t used_block = r;
static constexpr result_type min() { return Engine::min(); }
static constexpr result_type max() { return Engine::max(); }
// constructors and seeding functions
discard_block_engine();
explicit discard_block_engine(const Engine& e);
explicit discard_block_engine(Engine&& e);
explicit discard_block_engine(result_type s);
template<class Sseq> explicit discard_block_engine(Sseq& q);
void seed();
void seed(result_type s);
template<class Sseq> void seed(Sseq& q);
// generating functions
result_type operator()();
void discard(unsigned long long z);
// property functions
const Engine& base() const noexcept;
};
template<class Engine, size_t p, size_t r>
bool
operator==(
const discard_block_engine<Engine, p, r>& x,
const discard_block_engine<Engine, p, r>& y);
template<class Engine, size_t p, size_t r>
bool
operator!=(
const discard_block_engine<Engine, p, r>& x,
const discard_block_engine<Engine, p, r>& y);
template <class charT, class traits,
class Engine, size_t p, size_t r>
basic_ostream<charT, traits>&
operator<<(basic_ostream<charT, traits>& os,
const discard_block_engine<Engine, p, r>& x);
template <class charT, class traits,
class Engine, size_t p, size_t r>
basic_istream<charT, traits>&
operator>>(basic_istream<charT, traits>& is,
discard_block_engine<Engine, p, r>& x);
template<class Engine, size_t w, class UIntType>
class independent_bits_engine
{
public:
// types
typedef UIntType result_type;
// engine characteristics
static constexpr result_type min() { return 0; }
static constexpr result_type max() { return 2^w - 1; }
// constructors and seeding functions
independent_bits_engine();
explicit independent_bits_engine(const Engine& e);
explicit independent_bits_engine(Engine&& e);
explicit independent_bits_engine(result_type s);
template<class Sseq> explicit independent_bits_engine(Sseq& q);
void seed();
void seed(result_type s);
template<class Sseq> void seed(Sseq& q);
// generating functions
result_type operator()(); void discard(unsigned long long z);
// property functions
const Engine& base() const noexcept;
};
template<class Engine, size_t w, class UIntType>
bool
operator==(
const independent_bits_engine<Engine, w, UIntType>& x,
const independent_bits_engine<Engine, w, UIntType>& y);
template<class Engine, size_t w, class UIntType>
bool
operator!=(
const independent_bits_engine<Engine, w, UIntType>& x,
const independent_bits_engine<Engine, w, UIntType>& y);
template <class charT, class traits,
class Engine, size_t w, class UIntType>
basic_ostream<charT, traits>&
operator<<(basic_ostream<charT, traits>& os,
const independent_bits_engine<Engine, w, UIntType>& x);
template <class charT, class traits,
class Engine, size_t w, class UIntType>
basic_istream<charT, traits>&
operator>>(basic_istream<charT, traits>& is,
independent_bits_engine<Engine, w, UIntType>& x);
template<class Engine, size_t k>
class shuffle_order_engine
{
public:
// types
typedef typename Engine::result_type result_type;
// engine characteristics
static constexpr size_t table_size = k;
static constexpr result_type min() { return Engine::min; }
static constexpr result_type max() { return Engine::max; }
// constructors and seeding functions
shuffle_order_engine();
explicit shuffle_order_engine(const Engine& e);
explicit shuffle_order_engine(Engine&& e);
explicit shuffle_order_engine(result_type s);
template<class Sseq> explicit shuffle_order_engine(Sseq& q);
void seed();
void seed(result_type s);
template<class Sseq> void seed(Sseq& q);
// generating functions
result_type operator()();
void discard(unsigned long long z);
// property functions
const Engine& base() const noexcept;
};
template<class Engine, size_t k>
bool
operator==(
const shuffle_order_engine<Engine, k>& x,
const shuffle_order_engine<Engine, k>& y);
template<class Engine, size_t k>
bool
operator!=(
const shuffle_order_engine<Engine, k>& x,
const shuffle_order_engine<Engine, k>& y);
template <class charT, class traits,
class Engine, size_t k>
basic_ostream<charT, traits>&
operator<<(basic_ostream<charT, traits>& os,
const shuffle_order_engine<Engine, k>& x);
template <class charT, class traits,
class Engine, size_t k>
basic_istream<charT, traits>&
operator>>(basic_istream<charT, traits>& is,
shuffle_order_engine<Engine, k>& x);
typedef linear_congruential_engine<uint_fast32_t, 16807, 0, 2147483647>
minstd_rand0;
typedef linear_congruential_engine<uint_fast32_t, 48271, 0, 2147483647>
minstd_rand;
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,
0xb5026f5aa96619e9,
29, 0x5555555555555555,
17, 0x71d67fffeda60000,
37, 0xfff7eee000000000,
43, 6364136223846793005> mt19937_64;
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;
typedef shuffle_order_engine<minstd_rand0, 256> knuth_b;
typedef minstd_rand default_random_engine;
// Generators
class random_device
{
public:
// types
typedef unsigned int result_type;
// generator characteristics
static constexpr result_type min() { return numeric_limits<result_type>::min(); }
static constexpr result_type max() { return numeric_limits<result_type>::max(); }
// constructors
explicit random_device(const string& token = "/dev/urandom");
// generating functions
result_type operator()();
// property functions
double entropy() const noexcept;
// no copy functions
random_device(const random_device& ) = delete;
void operator=(const random_device& ) = delete;
};
// Utilities
class seed_seq
{
public:
// types
typedef uint_least32_t result_type;
// constructors
seed_seq();
template<class T>
seed_seq(initializer_list<T> il);
template<class InputIterator>
seed_seq(InputIterator begin, InputIterator end);
// generating functions
template<class RandomAccessIterator>
void generate(RandomAccessIterator begin, RandomAccessIterator end);
// property functions
size_t size() const;
template<class OutputIterator>
void param(OutputIterator dest) const;
// no copy functions
seed_seq(const seed_seq&) = delete;
void operator=(const seed_seq& ) = delete;
};
template<class RealType, size_t bits, class URNG>
RealType generate_canonical(URNG& g);
// Distributions
template<class IntType = int>
class uniform_int_distribution
{
public:
// types
typedef IntType result_type;
class param_type
{
public:
typedef uniform_int_distribution distribution_type;
explicit param_type(IntType a = 0,
IntType b = numeric_limits<IntType>::max());
result_type a() const;
result_type b() const;
friend bool operator==(const param_type& x, const param_type& y);
friend bool operator!=(const param_type& x, const param_type& y);
};
// constructors and reset functions
explicit uniform_int_distribution(IntType a = 0,
IntType b = numeric_limits<IntType>::max());
explicit uniform_int_distribution(const param_type& parm);
void reset();
// generating functions
template<class URNG> result_type operator()(URNG& g);
template<class URNG> result_type operator()(URNG& g, const param_type& parm);
// property functions
result_type a() const;
result_type b() const;
param_type param() const;
void param(const param_type& parm);
result_type min() const;
result_type max() const;
friend bool operator==(const uniform_int_distribution& x,
const uniform_int_distribution& y);
friend bool operator!=(const uniform_int_distribution& x,
const uniform_int_distribution& y);
template <class charT, class traits>
friend
basic_ostream<charT, traits>&
operator<<(basic_ostream<charT, traits>& os,
const uniform_int_distribution& x);
template <class charT, class traits>
friend
basic_istream<charT, traits>&
operator>>(basic_istream<charT, traits>& is,
uniform_int_distribution& x);
};
template<class RealType = double>
class uniform_real_distribution
{
public:
// types
typedef RealType result_type;
class param_type
{
public:
typedef uniform_real_distribution distribution_type;
explicit param_type(RealType a = 0,
RealType b = 1);
result_type a() const;
result_type b() const;
friend bool operator==(const param_type& x, const param_type& y);
friend bool operator!=(const param_type& x, const param_type& y);
};
// constructors and reset functions
explicit uniform_real_distribution(RealType a = 0.0, RealType b = 1.0);
explicit uniform_real_distribution(const param_type& parm);
void reset();
// generating functions
template<class URNG> result_type operator()(URNG& g);
template<class URNG> result_type operator()(URNG& g, const param_type& parm);
// property functions
result_type a() const;
result_type b() const;
param_type param() const;
void param(const param_type& parm);
result_type min() const;
result_type max() const;
friend bool operator==(const uniform_real_distribution& x,
const uniform_real_distribution& y);
friend bool operator!=(const uniform_real_distribution& x,
const uniform_real_distribution& y);
template <class charT, class traits>
friend
basic_ostream<charT, traits>&
operator<<(basic_ostream<charT, traits>& os,
const uniform_real_distribution& x);
template <class charT, class traits>
friend
basic_istream<charT, traits>&
operator>>(basic_istream<charT, traits>& is,
uniform_real_distribution& x);
};
class bernoulli_distribution
{
public:
// types
typedef bool result_type;
class param_type
{
public:
typedef bernoulli_distribution distribution_type;
explicit param_type(double p = 0.5);
double p() const;
friend bool operator==(const param_type& x, const param_type& y);
friend bool operator!=(const param_type& x, const param_type& y);
};
// constructors and reset functions
explicit bernoulli_distribution(double p = 0.5);
explicit bernoulli_distribution(const param_type& parm);
void reset();
// generating functions
template<class URNG> result_type operator()(URNG& g);
template<class URNG> result_type operator()(URNG& g, const param_type& parm);
// property functions
double p() const;
param_type param() const;
void param(const param_type& parm);
result_type min() const;
result_type max() const;
friend bool operator==(const bernoulli_distribution& x,
const bernoulli_distribution& y);
friend bool operator!=(const bernoulli_distribution& x,
const bernoulli_distribution& y);
template <class charT, class traits>
friend
basic_ostream<charT, traits>&
operator<<(basic_ostream<charT, traits>& os,
const bernoulli_distribution& x);
template <class charT, class traits>
friend
basic_istream<charT, traits>&
operator>>(basic_istream<charT, traits>& is,
bernoulli_distribution& x);
};
template<class IntType = int>
class binomial_distribution
{
public:
// types
typedef IntType result_type;
class param_type
{
public:
typedef binomial_distribution distribution_type;
explicit param_type(IntType t = 1, double p = 0.5);
IntType t() const;
double p() const;
friend bool operator==(const param_type& x, const param_type& y);
friend bool operator!=(const param_type& x, const param_type& y);
};
// constructors and reset functions
explicit binomial_distribution(IntType t = 1, double p = 0.5);
explicit binomial_distribution(const param_type& parm);
void reset();
// generating functions
template<class URNG> result_type operator()(URNG& g);
template<class URNG> result_type operator()(URNG& g, const param_type& parm);
// property functions
IntType t() const;
double p() const;
param_type param() const;
void param(const param_type& parm);
result_type min() const;
result_type max() const;
friend bool operator==(const binomial_distribution& x,
const binomial_distribution& y);
friend bool operator!=(const binomial_distribution& x,
const binomial_distribution& y);
template <class charT, class traits>
friend
basic_ostream<charT, traits>&
operator<<(basic_ostream<charT, traits>& os,
const binomial_distribution& x);
template <class charT, class traits>
friend
basic_istream<charT, traits>&
operator>>(basic_istream<charT, traits>& is,
binomial_distribution& x);
};
template<class IntType = int>
class geometric_distribution
{
public:
// types
typedef IntType result_type;
class param_type
{
public:
typedef geometric_distribution distribution_type;
explicit param_type(double p = 0.5);
double p() const;
friend bool operator==(const param_type& x, const param_type& y);
friend bool operator!=(const param_type& x, const param_type& y);
};
// constructors and reset functions
explicit geometric_distribution(double p = 0.5);
explicit geometric_distribution(const param_type& parm);
void reset();
// generating functions
template<class URNG> result_type operator()(URNG& g);
template<class URNG> result_type operator()(URNG& g, const param_type& parm);
// property functions
double p() const;
param_type param() const;
void param(const param_type& parm);
result_type min() const;
result_type max() const;
friend bool operator==(const geometric_distribution& x,
const geometric_distribution& y);
friend bool operator!=(const geometric_distribution& x,
const geometric_distribution& y);
template <class charT, class traits>
friend
basic_ostream<charT, traits>&
operator<<(basic_ostream<charT, traits>& os,
const geometric_distribution& x);
template <class charT, class traits>
friend
basic_istream<charT, traits>&
operator>>(basic_istream<charT, traits>& is,
geometric_distribution& x);
};
template<class IntType = int>
class negative_binomial_distribution
{
public:
// types
typedef IntType result_type;
class param_type
{
public:
typedef negative_binomial_distribution distribution_type;
explicit param_type(result_type k = 1, double p = 0.5);
result_type k() const;
double p() const;
friend bool operator==(const param_type& x, const param_type& y);
friend bool operator!=(const param_type& x, const param_type& y);
};
// constructor and reset functions
explicit negative_binomial_distribution(result_type k = 1, double p = 0.5);
explicit negative_binomial_distribution(const param_type& parm);
void reset();
// generating functions
template<class URNG> result_type operator()(URNG& g);
template<class URNG> result_type operator()(URNG& g, const param_type& parm);
// property functions
result_type k() const;
double p() const;
param_type param() const;
void param(const param_type& parm);
result_type min() const;
result_type max() const;
friend bool operator==(const negative_binomial_distribution& x,
const negative_binomial_distribution& y);
friend bool operator!=(const negative_binomial_distribution& x,
const negative_binomial_distribution& y);
template <class charT, class traits>
friend
basic_ostream<charT, traits>&
operator<<(basic_ostream<charT, traits>& os,
const negative_binomial_distribution& x);
template <class charT, class traits>
friend
basic_istream<charT, traits>&
operator>>(basic_istream<charT, traits>& is,
negative_binomial_distribution& x);
};
template<class IntType = int>
class poisson_distribution
{
public:
// types
typedef IntType result_type;
class param_type
{
public:
typedef poisson_distribution distribution_type;
explicit param_type(double mean = 1.0);
double mean() const;
friend bool operator==(const param_type& x, const param_type& y);
friend bool operator!=(const param_type& x, const param_type& y);
};
// constructors and reset functions
explicit poisson_distribution(double mean = 1.0);
explicit poisson_distribution(const param_type& parm);
void reset();
// generating functions
template<class URNG> result_type operator()(URNG& g);
template<class URNG> result_type operator()(URNG& g, const param_type& parm);
// property functions
double mean() const;
param_type param() const;
void param(const param_type& parm);
result_type min() const;
result_type max() const;
friend bool operator==(const poisson_distribution& x,
const poisson_distribution& y);
friend bool operator!=(const poisson_distribution& x,
const poisson_distribution& y);
template <class charT, class traits>
friend
basic_ostream<charT, traits>&
operator<<(basic_ostream<charT, traits>& os,
const poisson_distribution& x);
template <class charT, class traits>
friend
basic_istream<charT, traits>&
operator>>(basic_istream<charT, traits>& is,
poisson_distribution& x);
};
template<class RealType = double>
class exponential_distribution
{
public:
// types
typedef RealType result_type;
class param_type
{
public:
typedef exponential_distribution distribution_type;
explicit param_type(result_type lambda = 1.0);
result_type lambda() const;
friend bool operator==(const param_type& x, const param_type& y);
friend bool operator!=(const param_type& x, const param_type& y);
};
// constructors and reset functions
explicit exponential_distribution(result_type lambda = 1.0);
explicit exponential_distribution(const param_type& parm);
void reset();
// generating functions
template<class URNG> result_type operator()(URNG& g);
template<class URNG> result_type operator()(URNG& g, const param_type& parm);
// property functions
result_type lambda() const;
param_type param() const;
void param(const param_type& parm);
result_type min() const;
result_type max() const;
friend bool operator==(const exponential_distribution& x,
const exponential_distribution& y);
friend bool operator!=(const exponential_distribution& x,
const exponential_distribution& y);
template <class charT, class traits>
friend
basic_ostream<charT, traits>&
operator<<(basic_ostream<charT, traits>& os,
const exponential_distribution& x);
template <class charT, class traits>
friend
basic_istream<charT, traits>&
operator>>(basic_istream<charT, traits>& is,
exponential_distribution& x);
};
template<class RealType = double>
class gamma_distribution
{
public:
// types
typedef RealType result_type;
class param_type
{
public:
typedef gamma_distribution distribution_type;
explicit param_type(result_type alpha = 1, result_type beta = 1);
result_type alpha() const;
result_type beta() const;
friend bool operator==(const param_type& x, const param_type& y);
friend bool operator!=(const param_type& x, const param_type& y);
};
// constructors and reset functions
explicit gamma_distribution(result_type alpha = 1, result_type beta = 1);
explicit gamma_distribution(const param_type& parm);
void reset();
// generating functions
template<class URNG> result_type operator()(URNG& g);
template<class URNG> result_type operator()(URNG& g, const param_type& parm);
// property functions
result_type alpha() const;
result_type beta() const;
param_type param() const;
void param(const param_type& parm);
result_type min() const;
result_type max() const;
friend bool operator==(const gamma_distribution& x,
const gamma_distribution& y);
friend bool operator!=(const gamma_distribution& x,
const gamma_distribution& y);
template <class charT, class traits>
friend
basic_ostream<charT, traits>&
operator<<(basic_ostream<charT, traits>& os,
const gamma_distribution& x);
template <class charT, class traits>
friend
basic_istream<charT, traits>&
operator>>(basic_istream<charT, traits>& is,
gamma_distribution& x);
};
template<class RealType = double>
class weibull_distribution
{
public:
// types
typedef RealType result_type;
class param_type
{
public:
typedef weibull_distribution distribution_type;
explicit param_type(result_type alpha = 1, result_type beta = 1);
result_type a() const;
result_type b() const;
friend bool operator==(const param_type& x, const param_type& y);
friend bool operator!=(const param_type& x, const param_type& y);
};
// constructor and reset functions
explicit weibull_distribution(result_type a = 1, result_type b = 1);
explicit weibull_distribution(const param_type& parm);
void reset();
// generating functions
template<class URNG> result_type operator()(URNG& g);
template<class URNG> result_type operator()(URNG& g, const param_type& parm);
// property functions
result_type a() const;
result_type b() const;
param_type param() const;
void param(const param_type& parm);
result_type min() const;
result_type max() const;
friend bool operator==(const weibull_distribution& x,
const weibull_distribution& y);
friend bool operator!=(const weibull_distribution& x,
const weibull_distribution& y);
template <class charT, class traits>
friend
basic_ostream<charT, traits>&
operator<<(basic_ostream<charT, traits>& os,
const weibull_distribution& x);
template <class charT, class traits>
friend
basic_istream<charT, traits>&
operator>>(basic_istream<charT, traits>& is,
weibull_distribution& x);
};
template<class RealType = double>
class extreme_value_distribution
{
public:
// types
typedef RealType result_type;
class param_type
{
public:
typedef extreme_value_distribution distribution_type;
explicit param_type(result_type a = 0, result_type b = 1);
result_type a() const;
result_type b() const;
friend bool operator==(const param_type& x, const param_type& y);
friend bool operator!=(const param_type& x, const param_type& y);
};
// constructor and reset functions
explicit extreme_value_distribution(result_type a = 0, result_type b = 1);
explicit extreme_value_distribution(const param_type& parm);
void reset();
// generating functions
template<class URNG> result_type operator()(URNG& g);
template<class URNG> result_type operator()(URNG& g, const param_type& parm);
// property functions
result_type a() const;
result_type b() const;
param_type param() const;
void param(const param_type& parm);
result_type min() const;
result_type max() const;
friend bool operator==(const extreme_value_distribution& x,
const extreme_value_distribution& y);
friend bool operator!=(const extreme_value_distribution& x,
const extreme_value_distribution& y);
template <class charT, class traits>
friend
basic_ostream<charT, traits>&
operator<<(basic_ostream<charT, traits>& os,
const extreme_value_distribution& x);
template <class charT, class traits>
friend
basic_istream<charT, traits>&
operator>>(basic_istream<charT, traits>& is,
extreme_value_distribution& x);
};
template<class RealType = double>
class normal_distribution
{
public:
// types
typedef RealType result_type;
class param_type
{
public:
typedef normal_distribution distribution_type;
explicit param_type(result_type mean = 0, result_type stddev = 1);
result_type mean() const;
result_type stddev() const;
friend bool operator==(const param_type& x, const param_type& y);
friend bool operator!=(const param_type& x, const param_type& y);
};
// constructors and reset functions
explicit normal_distribution(result_type mean = 0, result_type stddev = 1);
explicit normal_distribution(const param_type& parm);
void reset();
// generating functions
template<class URNG> result_type operator()(URNG& g);
template<class URNG> result_type operator()(URNG& g, const param_type& parm);
// property functions
result_type mean() const;
result_type stddev() const;
param_type param() const;
void param(const param_type& parm);
result_type min() const;
result_type max() const;
friend bool operator==(const normal_distribution& x,
const normal_distribution& y);
friend bool operator!=(const normal_distribution& x,
const normal_distribution& y);
template <class charT, class traits>
friend
basic_ostream<charT, traits>&
operator<<(basic_ostream<charT, traits>& os,
const normal_distribution& x);
template <class charT, class traits>
friend
basic_istream<charT, traits>&
operator>>(basic_istream<charT, traits>& is,
normal_distribution& x);
};
template<class RealType = double>
class lognormal_distribution
{
public:
// types
typedef RealType result_type;
class param_type
{
public:
typedef lognormal_distribution distribution_type;
explicit param_type(result_type m = 0, result_type s = 1);
result_type m() const;
result_type s() const;
friend bool operator==(const param_type& x, const param_type& y);
friend bool operator!=(const param_type& x, const param_type& y);
};
// constructor and reset functions
explicit lognormal_distribution(result_type m = 0, result_type s = 1);
explicit lognormal_distribution(const param_type& parm);
void reset();
// generating functions
template<class URNG> result_type operator()(URNG& g);
template<class URNG> result_type operator()(URNG& g, const param_type& parm);
// property functions
result_type m() const;
result_type s() const;
param_type param() const;
void param(const param_type& parm);
result_type min() const;
result_type max() const;
friend bool operator==(const lognormal_distribution& x,
const lognormal_distribution& y);
friend bool operator!=(const lognormal_distribution& x,
const lognormal_distribution& y);
template <class charT, class traits>
friend
basic_ostream<charT, traits>&
operator<<(basic_ostream<charT, traits>& os,
const lognormal_distribution& x);
template <class charT, class traits>
friend
basic_istream<charT, traits>&
operator>>(basic_istream<charT, traits>& is,
lognormal_distribution& x);
};
template<class RealType = double>
class chi_squared_distribution
{
public:
// types
typedef RealType result_type;
class param_type
{
public:
typedef chi_squared_distribution distribution_type;
explicit param_type(result_type n = 1);
result_type n() const;
friend bool operator==(const param_type& x, const param_type& y);
friend bool operator!=(const param_type& x, const param_type& y);
};
// constructor and reset functions
explicit chi_squared_distribution(result_type n = 1);
explicit chi_squared_distribution(const param_type& parm);
void reset();
// generating functions
template<class URNG> result_type operator()(URNG& g);
template<class URNG> result_type operator()(URNG& g, const param_type& parm);
// property functions
result_type n() const;
param_type param() const;
void param(const param_type& parm);
result_type min() const;
result_type max() const;
friend bool operator==(const chi_squared_distribution& x,
const chi_squared_distribution& y);
friend bool operator!=(const chi_squared_distribution& x,
const chi_squared_distribution& y);
template <class charT, class traits>
friend
basic_ostream<charT, traits>&
operator<<(basic_ostream<charT, traits>& os,
const chi_squared_distribution& x);
template <class charT, class traits>
friend
basic_istream<charT, traits>&
operator>>(basic_istream<charT, traits>& is,
chi_squared_distribution& x);
};
template<class RealType = double>
class cauchy_distribution
{
public:
// types
typedef RealType result_type;
class param_type
{
public:
typedef cauchy_distribution distribution_type;
explicit param_type(result_type a = 0, result_type b = 1);
result_type a() const;
result_type b() const;
friend bool operator==(const param_type& x, const param_type& y);
friend bool operator!=(const param_type& x, const param_type& y);
};
// constructor and reset functions
explicit cauchy_distribution(result_type a = 0, result_type b = 1);
explicit cauchy_distribution(const param_type& parm);
void reset();
// generating functions
template<class URNG> result_type operator()(URNG& g);
template<class URNG> result_type operator()(URNG& g, const param_type& parm);
// property functions
result_type a() const;
result_type b() const;
param_type param() const;
void param(const param_type& parm);
result_type min() const;
result_type max() const;
friend bool operator==(const cauchy_distribution& x,
const cauchy_distribution& y);
friend bool operator!=(const cauchy_distribution& x,
const cauchy_distribution& y);
template <class charT, class traits>
friend
basic_ostream<charT, traits>&
operator<<(basic_ostream<charT, traits>& os,
const cauchy_distribution& x);
template <class charT, class traits>
friend
basic_istream<charT, traits>&
operator>>(basic_istream<charT, traits>& is,
cauchy_distribution& x);
};
template<class RealType = double>
class fisher_f_distribution
{
public:
// types
typedef RealType result_type;
class param_type
{
public:
typedef fisher_f_distribution distribution_type;
explicit param_type(result_type m = 1, result_type n = 1);
result_type m() const;
result_type n() const;
friend bool operator==(const param_type& x, const param_type& y);
friend bool operator!=(const param_type& x, const param_type& y);
};
// constructor and reset functions
explicit fisher_f_distribution(result_type m = 1, result_type n = 1);
explicit fisher_f_distribution(const param_type& parm);
void reset();
// generating functions
template<class URNG> result_type operator()(URNG& g);
template<class URNG> result_type operator()(URNG& g, const param_type& parm);
// property functions
result_type m() const;
result_type n() const;
param_type param() const;
void param(const param_type& parm);
result_type min() const;
result_type max() const;
friend bool operator==(const fisher_f_distribution& x,
const fisher_f_distribution& y);
friend bool operator!=(const fisher_f_distribution& x,
const fisher_f_distribution& y);
template <class charT, class traits>
friend
basic_ostream<charT, traits>&
operator<<(basic_ostream<charT, traits>& os,
const fisher_f_distribution& x);
template <class charT, class traits>
friend
basic_istream<charT, traits>&
operator>>(basic_istream<charT, traits>& is,
fisher_f_distribution& x);
};
template<class RealType = double>
class student_t_distribution
{
public:
// types
typedef RealType result_type;
class param_type
{
public:
typedef student_t_distribution distribution_type;
explicit param_type(result_type n = 1);
result_type n() const;
friend bool operator==(const param_type& x, const param_type& y);
friend bool operator!=(const param_type& x, const param_type& y);
};
// constructor and reset functions
explicit student_t_distribution(result_type n = 1);
explicit student_t_distribution(const param_type& parm);
void reset();
// generating functions
template<class URNG> result_type operator()(URNG& g);
template<class URNG> result_type operator()(URNG& g, const param_type& parm);
// property functions
result_type n() const;
param_type param() const;
void param(const param_type& parm);
result_type min() const;
result_type max() const;
friend bool operator==(const student_t_distribution& x,
const student_t_distribution& y);
friend bool operator!=(const student_t_distribution& x,
const student_t_distribution& y);
template <class charT, class traits>
friend
basic_ostream<charT, traits>&
operator<<(basic_ostream<charT, traits>& os,
const student_t_distribution& x);
template <class charT, class traits>
friend
basic_istream<charT, traits>&
operator>>(basic_istream<charT, traits>& is,
student_t_distribution& x);
};
template<class IntType = int>
class discrete_distribution
{
public:
// types
typedef IntType result_type;
class param_type
{
public:
typedef discrete_distribution distribution_type;
param_type();
template<class InputIterator>
param_type(InputIterator firstW, InputIterator lastW);
param_type(initializer_list<double> wl);
template<class UnaryOperation>
param_type(size_t nw, double xmin, double xmax, UnaryOperation fw);
vector<double> probabilities() const;
friend bool operator==(const param_type& x, const param_type& y);
friend bool operator!=(const param_type& x, const param_type& y);
};
// constructor and reset functions
discrete_distribution();
template<class InputIterator>
discrete_distribution(InputIterator firstW, InputIterator lastW);
discrete_distribution(initializer_list<double> wl);
template<class UnaryOperation>
discrete_distribution(size_t nw, double xmin, double xmax,
UnaryOperation fw);
explicit discrete_distribution(const param_type& parm);
void reset();
// generating functions
template<class URNG> result_type operator()(URNG& g);
template<class URNG> result_type operator()(URNG& g, const param_type& parm);
// property functions
vector<double> probabilities() const;
param_type param() const;
void param(const param_type& parm);
result_type min() const;
result_type max() const;
friend bool operator==(const discrete_distribution& x,
const discrete_distribution& y);
friend bool operator!=(const discrete_distribution& x,
const discrete_distribution& y);
template <class charT, class traits>
friend
basic_ostream<charT, traits>&
operator<<(basic_ostream<charT, traits>& os,
const discrete_distribution& x);
template <class charT, class traits>
friend
basic_istream<charT, traits>&
operator>>(basic_istream<charT, traits>& is,
discrete_distribution& x);
};
template<class RealType = double>
class piecewise_constant_distribution
{
// types
typedef RealType result_type;
class param_type
{
public:
typedef piecewise_constant_distribution distribution_type;
param_type();
template<class InputIteratorB, class InputIteratorW>
param_type(InputIteratorB firstB, InputIteratorB lastB,
InputIteratorW firstW);
template<class UnaryOperation>
param_type(initializer_list<result_type> bl, UnaryOperation fw);
template<class UnaryOperation>
param_type(size_t nw, result_type xmin, result_type xmax,
UnaryOperation fw);
vector<result_type> intervals() const;
vector<result_type> densities() const;
friend bool operator==(const param_type& x, const param_type& y);
friend bool operator!=(const param_type& x, const param_type& y);
};
// constructor and reset functions
piecewise_constant_distribution();
template<class InputIteratorB, class InputIteratorW>
piecewise_constant_distribution(InputIteratorB firstB,
InputIteratorB lastB,
InputIteratorW firstW);
template<class UnaryOperation>
piecewise_constant_distribution(initializer_list<result_type> bl,
UnaryOperation fw);
template<class UnaryOperation>
piecewise_constant_distribution(size_t nw, result_type xmin,
result_type xmax, UnaryOperation fw);
explicit piecewise_constant_distribution(const param_type& parm);
void reset();
// generating functions
template<class URNG> result_type operator()(URNG& g);
template<class URNG> result_type operator()(URNG& g, const param_type& parm);
// property functions
vector<result_type> intervals() const;
vector<result_type> densities() const;
param_type param() const;
void param(const param_type& parm);
result_type min() const;
result_type max() const;
friend bool operator==(const piecewise_constant_distribution& x,
const piecewise_constant_distribution& y);
friend bool operator!=(const piecewise_constant_distribution& x,
const piecewise_constant_distribution& y);
template <class charT, class traits>
friend
basic_ostream<charT, traits>&
operator<<(basic_ostream<charT, traits>& os,
const piecewise_constant_distribution& x);
template <class charT, class traits>
friend
basic_istream<charT, traits>&
operator>>(basic_istream<charT, traits>& is,
piecewise_constant_distribution& x);
};
template<class RealType = double>
class piecewise_linear_distribution
{
// types
typedef RealType result_type;
class param_type
{
public:
typedef piecewise_linear_distribution distribution_type;
param_type();
template<class InputIteratorB, class InputIteratorW>
param_type(InputIteratorB firstB, InputIteratorB lastB,
InputIteratorW firstW);
template<class UnaryOperation>
param_type(initializer_list<result_type> bl, UnaryOperation fw);
template<class UnaryOperation>
param_type(size_t nw, result_type xmin, result_type xmax,
UnaryOperation fw);
vector<result_type> intervals() const;
vector<result_type> densities() const;
friend bool operator==(const param_type& x, const param_type& y);
friend bool operator!=(const param_type& x, const param_type& y);
};
// constructor and reset functions
piecewise_linear_distribution();
template<class InputIteratorB, class InputIteratorW>
piecewise_linear_distribution(InputIteratorB firstB,
InputIteratorB lastB,
InputIteratorW firstW);
template<class UnaryOperation>
piecewise_linear_distribution(initializer_list<result_type> bl,
UnaryOperation fw);
template<class UnaryOperation>
piecewise_linear_distribution(size_t nw, result_type xmin,
result_type xmax, UnaryOperation fw);
explicit piecewise_linear_distribution(const param_type& parm);
void reset();
// generating functions
template<class URNG> result_type operator()(URNG& g);
template<class URNG> result_type operator()(URNG& g, const param_type& parm);
// property functions
vector<result_type> intervals() const;
vector<result_type> densities() const;
param_type param() const;
void param(const param_type& parm);
result_type min() const;
result_type max() const;
friend bool operator==(const piecewise_linear_distribution& x,
const piecewise_linear_distribution& y);
friend bool operator!=(const piecewise_linear_distribution& x,
const piecewise_linear_distribution& y);
template <class charT, class traits>
friend
basic_ostream<charT, traits>&
operator<<(basic_ostream<charT, traits>& os,
const piecewise_linear_distribution& x);
template <class charT, class traits>
friend
basic_istream<charT, traits>&
operator>>(basic_istream<charT, traits>& is,
piecewise_linear_distribution& x);
};
} // std
*/
// __is_seed_sequence
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;
};
// linear_congruential_engine
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)>
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");
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
_LIBCPP_INLINE_VISIBILITY
explicit linear_congruential_engine(result_type __s = default_seed)
{seed(__s);}
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);
__os.flags(ios_base::dec | ios_base::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);
__is.flags(ios_base::dec | ios_base::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;
typedef minstd_rand default_random_engine;
// mersenne_twister_engine
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
_LIBCPP_INLINE_VISIBILITY
explicit mersenne_twister_engine(result_type __sd = default_seed)
{seed(__sd);}
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);
__os.flags(ios_base::dec | ios_base::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);
__is.flags(ios_base::dec | ios_base::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;
// subtract_with_carry_engine
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
_LIBCPP_INLINE_VISIBILITY
explicit subtract_with_carry_engine(result_type __sd = default_seed)
{seed(__sd);}
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);
__os.flags(ios_base::dec | ios_base::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);
__is.flags(ios_base::dec | ios_base::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;
}
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;
// discard_block_engine
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);
__os.flags(ios_base::dec | ios_base::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);
__is.flags(ios_base::dec | ios_base::skipws);
_Eng __e;
int __n;
__is >> __e >> __n;
if (!__is.fail())
{
__x.__e_ = __e;
__x.__n_ = __n;
}
return __is;
}
typedef discard_block_engine<ranlux24_base, 223, 23> ranlux24;
typedef discard_block_engine<ranlux48_base, 389, 11> ranlux48;
// independent_bits_engine
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;
}
// shuffle_order_engine
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);
__os.flags(ios_base::dec | ios_base::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);
__is.flags(ios_base::dec | ios_base::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;
}
typedef shuffle_order_engine<minstd_rand0, 256> knuth_b;
// random_device
class _LIBCPP_TYPE_VIS random_device
{
#ifdef _LIBCPP_USING_DEV_RANDOM
int __f_;
#endif // defined(_LIBCPP_USING_DEV_RANDOM)
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
explicit random_device(const string& __token = "/dev/urandom");
~random_device();
// generating functions
result_type operator()();
// property functions
double entropy() const _NOEXCEPT;
private:
// no copy functions
random_device(const random_device&); // = delete;
random_device& operator=(const random_device&); // = delete;
};
// seed_seq
class _LIBCPP_TEMPLATE_VIS seed_seq
{
public:
// types
typedef uint32_t result_type;
private:
vector<result_type> __v_;
template<class _InputIterator>
void init(_InputIterator __first, _InputIterator __last);
public:
// constructors
_LIBCPP_INLINE_VISIBILITY
seed_seq() _NOEXCEPT {}
#ifndef _LIBCPP_CXX03_LANG
template<class _Tp>
_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)
{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);}
private:
// no copy functions
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);}
};
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;
}
}
}
// 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;
}
// uniform_int_distribution
// in <algorithm>
template <class _CharT, class _Traits, class _IT>
basic_ostream<_CharT, _Traits>&
operator<<(basic_ostream<_CharT, _Traits>& __os,
const uniform_int_distribution<_IT>& __x)
{
__save_flags<_CharT, _Traits> __lx(__os);
__os.flags(ios_base::dec | ios_base::left);
_CharT __sp = __os.widen(' ');
__os.fill(__sp);
return __os << __x.a() << __sp << __x.b();
}
template <class _CharT, class _Traits, class _IT>
basic_istream<_CharT, _Traits>&
operator>>(basic_istream<_CharT, _Traits>& __is,
uniform_int_distribution<_IT>& __x)
{
typedef uniform_int_distribution<_IT> _Eng;
typedef typename _Eng::result_type result_type;
typedef typename _Eng::param_type param_type;
__save_flags<_CharT, _Traits> __lx(__is);
__is.flags(ios_base::dec | ios_base::skipws);
result_type __a;
result_type __b;
__is >> __a >> __b;
if (!__is.fail())
__x.param(param_type(__a, __b));
return __is;
}
// uniform_real_distribution
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
_LIBCPP_INLINE_VISIBILITY
explicit uniform_real_distribution(result_type __a = 0, result_type __b = 1)
: __p_(param_type(__a, __b)) {}
_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);
__os.flags(ios_base::dec | ios_base::left | ios_base::fixed |
ios_base::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);
__is.flags(ios_base::dec | ios_base::skipws);
result_type __a;
result_type __b;
__is >> __a >> __b;
if (!__is.fail())
__x.param(param_type(__a, __b));
return __is;
}
// bernoulli_distribution
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
_LIBCPP_INLINE_VISIBILITY
explicit bernoulli_distribution(double __p = 0.5)
: __p_(param_type(__p)) {}
_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);
__os.flags(ios_base::dec | ios_base::left | ios_base::fixed |
ios_base::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);
__is.flags(ios_base::dec | ios_base::skipws);
double __p;
__is >> __p;
if (!__is.fail())
__x.param(param_type(__p));
return __is;
}
// binomial_distribution
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
_LIBCPP_INLINE_VISIBILITY
explicit binomial_distribution(result_type __t = 1, double __p = 0.5)
: __p_(param_type(__t, __p)) {}
_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
extern "C" double lgamma_r(double, int *);
#endif
inline _LIBCPP_INLINE_VISIBILITY double __libcpp_lgamma(double __d) {
#if defined(_LIBCPP_MSVCRT)
return lgamma(__d);
#else
int __sign;
return lgamma_r(__d, &__sign);
#endif
}
template<class _IntType>
binomial_distribution<_IntType>::param_type::param_type(const result_type __t, const 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)
{
if (__rd >= 1)
{
__pd *= __rd / (__pr.__odds_ratio_ * (__pr.__t_ - __rd + 1));
__u -= __pd;
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;
if (__u < 0)
return __ru;
}
}
}
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);
__os.flags(ios_base::dec | ios_base::left | ios_base::fixed |
ios_base::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);
__is.flags(ios_base::dec | ios_base::skipws);
result_type __t;
double __p;
__is >> __t >> __p;
if (!__is.fail())
__x.param(param_type(__t, __p));
return __is;
}
// exponential_distribution
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
_LIBCPP_INLINE_VISIBILITY
explicit exponential_distribution(result_type __lambda = 1)
: __p_(param_type(__lambda)) {}
_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);
__os.flags(ios_base::dec | ios_base::left | ios_base::fixed |
ios_base::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);
__is.flags(ios_base::dec | ios_base::skipws);
result_type __lambda;
__is >> __lambda;
if (!__is.fail())
__x.param(param_type(__lambda));
return __is;
}
// normal_distribution
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
_LIBCPP_INLINE_VISIBILITY
explicit normal_distribution(result_type __mean = 0, result_type __stddev = 1)
: __p_(param_type(__mean, __stddev)), _V_hot_(false) {}
_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);
__os.flags(ios_base::dec | ios_base::left | ios_base::fixed |
ios_base::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);
__is.flags(ios_base::dec | ios_base::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;
}
// 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
_LIBCPP_INLINE_VISIBILITY
explicit lognormal_distribution(result_type __m = 0, result_type __s = 1)
: __p_(param_type(__m, __s)) {}
_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_;
}
// poisson_distribution
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
_LIBCPP_INLINE_VISIBILITY
explicit poisson_distribution(double __mean = 1.0) : __p_(__mean) {}
_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)
: __mean_(__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_ = static_cast<result_type>(__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)
{
result_type __x;
uniform_real_distribution<double> __urd;
if (__pr.__mean_ < 10)
{
__x = 0;
for (double __p = __urd(__urng); __p > __pr.__l_; ++__x)
__p *= __urd(__urng);
}
else
{
double __difmuk;
double __g = __pr.__mean_ + __pr.__s_ * normal_distribution<double>()(__urng);
double __u;
if (__g > 0)
{
__x = static_cast<result_type>(__g);
if (__x >= __pr.__l_)
return __x;
__difmuk = __pr.__mean_ - __x;
__u = __urd(__urng);
if (__pr.__d_ * __u >= __difmuk * __difmuk * __difmuk)
return __x;
}
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);
__x = __pr.__mean_ + __pr.__s_ * __t;
__difmuk = __pr.__mean_ - __x;
__using_exp_dist = true;
}
double __px;
double __py;
if (__x < 10)
{
const double __fac[] = {1, 1, 2, 6, 24, 120, 720, 5040,
40320, 362880};
__px = -__pr.__mean_;
__py = _VSTD::pow(__pr.__mean_, (double)__x) / __fac[__x];
}
else
{
double __del = .8333333E-1 / __x;
__del -= 4.8 * __del * __del * __del;
double __v = __difmuk / __x;
if (_VSTD::abs(__v) > 0.25)
__px = __x * _VSTD::log(1 + __v) - __difmuk - __del;
else
__px = __x * __v * __v * (((((((.1250060 * __v + -.1384794) *
__v + .1421878) * __v + -.1661269) * __v + .2000118) *
__v + -.2500068) * __v + .3333333) * __v + -.5) - __del;
__py = .3989423 / _VSTD::sqrt(__x);
}
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 __x;
}
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);
__os.flags(ios_base::dec | ios_base::left | ios_base::fixed |
ios_base::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);
__is.flags(ios_base::dec | ios_base::skipws);
double __mean;
__is >> __mean;
if (!__is.fail())
__x.param(param_type(__mean));
return __is;
}
// weibull_distribution
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
_LIBCPP_INLINE_VISIBILITY
explicit weibull_distribution(result_type __a = 1, result_type __b = 1)
: __p_(param_type(__a, __b)) {}
_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);
__os.flags(ios_base::dec | ios_base::left | ios_base::fixed |
ios_base::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);
__is.flags(ios_base::dec | ios_base::skipws);
result_type __a;
result_type __b;
__is >> __a >> __b;
if (!__is.fail())
__x.param(param_type(__a, __b));
return __is;
}
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
_LIBCPP_INLINE_VISIBILITY
explicit extreme_value_distribution(result_type __a = 0, result_type __b = 1)
: __p_(param_type(__a, __b)) {}
_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);
__os.flags(ios_base::dec | ios_base::left | ios_base::fixed |
ios_base::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);
__is.flags(ios_base::dec | ios_base::skipws);
result_type __a;
result_type __b;
__is >> __a >> __b;
if (!__is.fail())
__x.param(param_type(__a, __b));
return __is;
}
// gamma_distribution
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
_LIBCPP_INLINE_VISIBILITY
explicit gamma_distribution(result_type __alpha = 1, result_type __beta = 1)
: __p_(param_type(__alpha, __beta)) {}
_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);
__os.flags(ios_base::dec | ios_base::left | ios_base::fixed |
ios_base::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);
__is.flags(ios_base::dec | ios_base::skipws);
result_type __alpha;
result_type __beta;
__is >> __alpha >> __beta;
if (!__is.fail())
__x.param(param_type(__alpha, __beta));
return __is;
}
// negative_binomial_distribution
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
_LIBCPP_INLINE_VISIBILITY
explicit negative_binomial_distribution(result_type __k = 1, double __p = 0.5)
: __p_(__k, __p) {}
_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);
__os.flags(ios_base::dec | ios_base::left | ios_base::fixed |
ios_base::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);
__is.flags(ios_base::dec | ios_base::skipws);
result_type __k;
double __p;
__is >> __k >> __p;
if (!__is.fail())
__x.param(param_type(__k, __p));
return __is;
}
// geometric_distribution
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
_LIBCPP_INLINE_VISIBILITY
explicit geometric_distribution(double __p = 0.5) : __p_(__p) {}
_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);
__os.flags(ios_base::dec | ios_base::left | ios_base::fixed |
ios_base::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);
__is.flags(ios_base::dec | ios_base::skipws);
double __p;
__is >> __p;
if (!__is.fail())
__x.param(param_type(__p));
return __is;
}
// chi_squared_distribution
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
_LIBCPP_INLINE_VISIBILITY
explicit chi_squared_distribution(result_type __n = 1)
: __p_(param_type(__n)) {}
_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);
__os.flags(ios_base::dec | ios_base::left | ios_base::fixed |
ios_base::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);
__is.flags(ios_base::dec | ios_base::skipws);
result_type __n;
__is >> __n;
if (!__is.fail())
__x.param(param_type(__n));
return __is;
}
// cauchy_distribution
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
_LIBCPP_INLINE_VISIBILITY
explicit cauchy_distribution(result_type __a = 0, result_type __b = 1)
: __p_(param_type(__a, __b)) {}
_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);
__os.flags(ios_base::dec | ios_base::left | ios_base::fixed |
ios_base::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);
__is.flags(ios_base::dec | ios_base::skipws);
result_type __a;
result_type __b;
__is >> __a >> __b;
if (!__is.fail())
__x.param(param_type(__a, __b));
return __is;
}
// fisher_f_distribution
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
_LIBCPP_INLINE_VISIBILITY
explicit fisher_f_distribution(result_type __m = 1, result_type __n = 1)
: __p_(param_type(__m, __n)) {}
_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);
__os.flags(ios_base::dec | ios_base::left | ios_base::fixed |
ios_base::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);
__is.flags(ios_base::dec | ios_base::skipws);
result_type __m;
result_type __n;
__is >> __m >> __n;
if (!__is.fail())
__x.param(param_type(__m, __n));
return __is;
}
// student_t_distribution
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
_LIBCPP_INLINE_VISIBILITY
explicit student_t_distribution(result_type __n = 1)
: __p_(param_type(__n)) {}
_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);
__os.flags(ios_base::dec | ios_base::left | ios_base::fixed |
ios_base::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);
__is.flags(ios_base::dec | ios_base::skipws);
result_type __n;
__is >> __n;
if (!__is.fail())
__x.param(param_type(__n));
return __is;
}
// discrete_distribution
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 (_VSTD::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();
_VSTD::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);
__os.flags(ios_base::dec | ios_base::left | ios_base::fixed |
ios_base::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);
__is.flags(ios_base::dec | ios_base::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;
}
// piecewise_constant_distribution
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 & 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);
__os.flags(ios_base::dec | ios_base::left | ios_base::fixed |
ios_base::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);
__is.flags(ios_base::dec | ios_base::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;
}
// piecewise_linear_distribution
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 & 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);
__os.flags(ios_base::dec | ios_base::left | ios_base::fixed |
ios_base::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);
__is.flags(ios_base::dec | ios_base::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
| 226,303 | 6,744 | jart/cosmopolitan | false |
cosmopolitan/third_party/libcxx/iostream.cc | // clang-format off
//===------------------------ iostream.cpp --------------------------------===//
//
// 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
//
//===----------------------------------------------------------------------===//
#include "third_party/libcxx/__std_stream"
#include "third_party/libcxx/__locale"
#include "third_party/libcxx/string"
#include "third_party/libcxx/new"
#define _str(s) #s
#define str(s) _str(s)
#define _LIBCPP_ABI_NAMESPACE_STR str(_LIBCPP_ABI_NAMESPACE)
_LIBCPP_BEGIN_NAMESPACE_STD
#ifndef _LIBCPP_HAS_NO_STDIN
_ALIGNAS_TYPE (istream) _LIBCPP_FUNC_VIS char cin[sizeof(istream)]
#if defined(_LIBCPP_ABI_MICROSOFT) && defined(__clang__)
__asm__("?cin@" _LIBCPP_ABI_NAMESPACE_STR "@std@@3V?$basic_istream@DU?$char_traits@D@" _LIBCPP_ABI_NAMESPACE_STR "@std@@@12@A")
#endif
;
_ALIGNAS_TYPE (__stdinbuf<char> ) static char __cin[sizeof(__stdinbuf <char>)];
static mbstate_t mb_cin;
_ALIGNAS_TYPE (wistream) _LIBCPP_FUNC_VIS char wcin[sizeof(wistream)]
#if defined(_LIBCPP_ABI_MICROSOFT) && defined(__clang__)
__asm__("?wcin@" _LIBCPP_ABI_NAMESPACE_STR "@std@@3V?$basic_istream@_WU?$char_traits@_W@" _LIBCPP_ABI_NAMESPACE_STR "@std@@@12@A")
#endif
;
_ALIGNAS_TYPE (__stdinbuf<wchar_t> ) static char __wcin[sizeof(__stdinbuf <wchar_t>)];
static mbstate_t mb_wcin;
#endif
#ifndef _LIBCPP_HAS_NO_STDOUT
_ALIGNAS_TYPE (ostream) _LIBCPP_FUNC_VIS char cout[sizeof(ostream)]
#if defined(_LIBCPP_ABI_MICROSOFT) && defined(__clang__)
__asm__("?cout@" _LIBCPP_ABI_NAMESPACE_STR "@std@@3V?$basic_ostream@DU?$char_traits@D@" _LIBCPP_ABI_NAMESPACE_STR "@std@@@12@A")
#endif
;
_ALIGNAS_TYPE (__stdoutbuf<char>) static char __cout[sizeof(__stdoutbuf<char>)];
static mbstate_t mb_cout;
_ALIGNAS_TYPE (wostream) _LIBCPP_FUNC_VIS char wcout[sizeof(wostream)]
#if defined(_LIBCPP_ABI_MICROSOFT) && defined(__clang__)
__asm__("?wcout@" _LIBCPP_ABI_NAMESPACE_STR "@std@@3V?$basic_ostream@_WU?$char_traits@_W@" _LIBCPP_ABI_NAMESPACE_STR "@std@@@12@A")
#endif
;
_ALIGNAS_TYPE (__stdoutbuf<wchar_t>) static char __wcout[sizeof(__stdoutbuf<wchar_t>)];
static mbstate_t mb_wcout;
#endif
_ALIGNAS_TYPE (ostream) _LIBCPP_FUNC_VIS char cerr[sizeof(ostream)]
#if defined(_LIBCPP_ABI_MICROSOFT) && defined(__clang__)
__asm__("?cerr@" _LIBCPP_ABI_NAMESPACE_STR "@std@@3V?$basic_ostream@DU?$char_traits@D@" _LIBCPP_ABI_NAMESPACE_STR "@std@@@12@A")
#endif
;
_ALIGNAS_TYPE (__stdoutbuf<char>) static char __cerr[sizeof(__stdoutbuf<char>)];
static mbstate_t mb_cerr;
_ALIGNAS_TYPE (wostream) _LIBCPP_FUNC_VIS char wcerr[sizeof(wostream)]
#if defined(_LIBCPP_ABI_MICROSOFT) && defined(__clang__)
__asm__("?wcerr@" _LIBCPP_ABI_NAMESPACE_STR "@std@@3V?$basic_ostream@_WU?$char_traits@_W@" _LIBCPP_ABI_NAMESPACE_STR "@std@@@12@A")
#endif
;
_ALIGNAS_TYPE (__stdoutbuf<wchar_t>) static char __wcerr[sizeof(__stdoutbuf<wchar_t>)];
static mbstate_t mb_wcerr;
_ALIGNAS_TYPE (ostream) _LIBCPP_FUNC_VIS char clog[sizeof(ostream)]
#if defined(_LIBCPP_ABI_MICROSOFT) && defined(__clang__)
__asm__("?clog@" _LIBCPP_ABI_NAMESPACE_STR "@std@@3V?$basic_ostream@DU?$char_traits@D@" _LIBCPP_ABI_NAMESPACE_STR "@std@@@12@A")
#endif
;
_ALIGNAS_TYPE (wostream) _LIBCPP_FUNC_VIS char wclog[sizeof(wostream)]
#if defined(_LIBCPP_ABI_MICROSOFT) && defined(__clang__)
__asm__("?wclog@" _LIBCPP_ABI_NAMESPACE_STR "@std@@3V?$basic_ostream@_WU?$char_traits@_W@" _LIBCPP_ABI_NAMESPACE_STR "@std@@@12@A")
#endif
;
_LIBCPP_HIDDEN ios_base::Init __start_std_streams;
// On Windows the TLS storage for locales needs to be initialized before we create
// the standard streams, otherwise it may not be alive during program termination
// when we flush the streams.
static void force_locale_initialization() {
#if defined(_LIBCPP_MSVCRT_LIKE)
static bool once = []() {
auto loc = newlocale(LC_ALL_MASK, "C", 0);
{
__libcpp_locale_guard g(loc); // forces initialization of locale TLS
((void)g);
}
freelocale(loc);
return true;
}();
((void)once);
#endif
}
class DoIOSInit {
public:
DoIOSInit();
~DoIOSInit();
};
DoIOSInit::DoIOSInit()
{
force_locale_initialization();
#ifndef _LIBCPP_HAS_NO_STDIN
istream* cin_ptr = ::new(cin) istream(::new(__cin) __stdinbuf <char>(stdin, &mb_cin));
wistream* wcin_ptr = ::new(wcin) wistream(::new(__wcin) __stdinbuf <wchar_t>(stdin, &mb_wcin));
#endif
#ifndef _LIBCPP_HAS_NO_STDOUT
ostream* cout_ptr = ::new(cout) ostream(::new(__cout) __stdoutbuf<char>(stdout, &mb_cout));
wostream* wcout_ptr = ::new(wcout) wostream(::new(__wcout) __stdoutbuf<wchar_t>(stdout, &mb_wcout));
#endif
ostream* cerr_ptr = ::new(cerr) ostream(::new(__cerr) __stdoutbuf<char>(stderr, &mb_cerr));
::new(clog) ostream(cerr_ptr->rdbuf());
wostream* wcerr_ptr = ::new(wcerr) wostream(::new(__wcerr) __stdoutbuf<wchar_t>(stderr, &mb_wcerr));
::new(wclog) wostream(wcerr_ptr->rdbuf());
#if !defined(_LIBCPP_HAS_NO_STDIN) && !defined(_LIBCPP_HAS_NO_STDOUT)
cin_ptr->tie(cout_ptr);
wcin_ptr->tie(wcout_ptr);
#endif
_VSTD::unitbuf(*cerr_ptr);
_VSTD::unitbuf(*wcerr_ptr);
#ifndef _LIBCPP_HAS_NO_STDOUT
cerr_ptr->tie(cout_ptr);
wcerr_ptr->tie(wcout_ptr);
#endif
}
DoIOSInit::~DoIOSInit()
{
#ifndef _LIBCPP_HAS_NO_STDOUT
ostream* cout_ptr = reinterpret_cast<ostream*>(cout);
wostream* wcout_ptr = reinterpret_cast<wostream*>(wcout);
cout_ptr->flush();
wcout_ptr->flush();
#endif
ostream* clog_ptr = reinterpret_cast<ostream*>(clog);
wostream* wclog_ptr = reinterpret_cast<wostream*>(wclog);
clog_ptr->flush();
wclog_ptr->flush();
}
ios_base::Init::Init()
{
static DoIOSInit init_the_streams; // gets initialized once
}
ios_base::Init::~Init()
{
}
_LIBCPP_END_NAMESPACE_STD
| 5,890 | 161 | jart/cosmopolitan | false |
cosmopolitan/third_party/libcxx/thread | // -*- C++ -*-
// clang-format off
//===--------------------------- thread -----------------------------------===//
//
// 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_THREAD
#define _LIBCPP_THREAD
#include "third_party/libcxx/__config"
#include "third_party/libcxx/iosfwd"
#include "third_party/libcxx/__functional_base"
#include "third_party/libcxx/type_traits"
#include "third_party/libcxx/cstddef"
#include "third_party/libcxx/functional"
#include "third_party/libcxx/memory"
#include "third_party/libcxx/system_error"
#include "third_party/libcxx/chrono"
#include "third_party/libcxx/__mutex_base"
#ifndef _LIBCPP_CXX03_LANG
#include "third_party/libcxx/tuple"
#endif
#include "third_party/libcxx/__threading_support"
#include "third_party/libcxx/__debug"
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
#pragma GCC system_header
#endif
_LIBCPP_PUSH_MACROS
#include "third_party/libcxx/__undef_macros"
#ifndef _LIBCPP_HAS_NO_THREADS
_LIBCPP_BEGIN_NAMESPACE_STD
/*
thread synopsis
namespace std
{
class thread
{
public:
class id;
typedef pthread_t native_handle_type;
thread() noexcept;
template <class F, class ...Args> explicit thread(F&& f, Args&&... args);
~thread();
thread(const thread&) = delete;
thread(thread&& t) noexcept;
thread& operator=(const thread&) = delete;
thread& operator=(thread&& t) noexcept;
void swap(thread& t) noexcept;
bool joinable() const noexcept;
void join();
void detach();
id get_id() const noexcept;
native_handle_type native_handle();
static unsigned hardware_concurrency() noexcept;
};
void swap(thread& x, thread& y) noexcept;
class thread::id
{
public:
id() noexcept;
};
bool operator==(thread::id x, thread::id y) noexcept;
bool operator!=(thread::id x, thread::id y) noexcept;
bool operator< (thread::id x, thread::id y) noexcept;
bool operator<=(thread::id x, thread::id y) noexcept;
bool operator> (thread::id x, thread::id y) noexcept;
bool operator>=(thread::id x, thread::id y) noexcept;
template<class charT, class traits>
basic_ostream<charT, traits>&
operator<<(basic_ostream<charT, traits>& out, thread::id id);
namespace this_thread
{
thread::id get_id() noexcept;
void yield() noexcept;
template <class Clock, class Duration>
void sleep_until(const chrono::time_point<Clock, Duration>& abs_time);
template <class Rep, class Period>
void sleep_for(const chrono::duration<Rep, Period>& rel_time);
} // this_thread
} // std
*/
template <class _Tp> class __thread_specific_ptr;
class _LIBCPP_TYPE_VIS __thread_struct;
class _LIBCPP_HIDDEN __thread_struct_imp;
class __assoc_sub_state;
_LIBCPP_FUNC_VIS __thread_specific_ptr<__thread_struct>& __thread_local_data();
class _LIBCPP_TYPE_VIS __thread_struct
{
__thread_struct_imp* __p_;
__thread_struct(const __thread_struct&);
__thread_struct& operator=(const __thread_struct&);
public:
__thread_struct();
~__thread_struct();
void notify_all_at_thread_exit(condition_variable*, mutex*);
void __make_ready_at_thread_exit(__assoc_sub_state*);
};
template <class _Tp>
class __thread_specific_ptr
{
__libcpp_tls_key __key_;
// Only __thread_local_data() may construct a __thread_specific_ptr
// and only with _Tp == __thread_struct.
static_assert((is_same<_Tp, __thread_struct>::value), "");
__thread_specific_ptr();
friend _LIBCPP_FUNC_VIS __thread_specific_ptr<__thread_struct>& __thread_local_data();
__thread_specific_ptr(const __thread_specific_ptr&);
__thread_specific_ptr& operator=(const __thread_specific_ptr&);
_LIBCPP_HIDDEN static void _LIBCPP_TLS_DESTRUCTOR_CC __at_thread_exit(void*);
public:
typedef _Tp* pointer;
~__thread_specific_ptr();
_LIBCPP_INLINE_VISIBILITY
pointer get() const {return static_cast<_Tp*>(__libcpp_tls_get(__key_));}
_LIBCPP_INLINE_VISIBILITY
pointer operator*() const {return *get();}
_LIBCPP_INLINE_VISIBILITY
pointer operator->() const {return get();}
void set_pointer(pointer __p);
};
template <class _Tp>
void _LIBCPP_TLS_DESTRUCTOR_CC
__thread_specific_ptr<_Tp>::__at_thread_exit(void* __p)
{
delete static_cast<pointer>(__p);
}
template <class _Tp>
__thread_specific_ptr<_Tp>::__thread_specific_ptr()
{
int __ec =
__libcpp_tls_create(&__key_, &__thread_specific_ptr::__at_thread_exit);
if (__ec)
__throw_system_error(__ec, "__thread_specific_ptr construction failed");
}
template <class _Tp>
__thread_specific_ptr<_Tp>::~__thread_specific_ptr()
{
// __thread_specific_ptr is only created with a static storage duration
// so this destructor is only invoked during program termination. Invoking
// pthread_key_delete(__key_) may prevent other threads from deleting their
// thread local data. For this reason we leak the key.
}
template <class _Tp>
void
__thread_specific_ptr<_Tp>::set_pointer(pointer __p)
{
_LIBCPP_ASSERT(get() == nullptr,
"Attempting to overwrite thread local data");
__libcpp_tls_set(__key_, __p);
}
template<>
struct _LIBCPP_TEMPLATE_VIS hash<__thread_id>
: public unary_function<__thread_id, size_t>
{
_LIBCPP_INLINE_VISIBILITY
size_t operator()(__thread_id __v) const _NOEXCEPT
{
return hash<__libcpp_thread_id>()(__v.__id_);
}
};
template<class _CharT, class _Traits>
_LIBCPP_INLINE_VISIBILITY
basic_ostream<_CharT, _Traits>&
operator<<(basic_ostream<_CharT, _Traits>& __os, __thread_id __id)
{return __os << __id.__id_;}
class _LIBCPP_TYPE_VIS thread
{
__libcpp_thread_t __t_;
thread(const thread&);
thread& operator=(const thread&);
public:
typedef __thread_id id;
typedef __libcpp_thread_t native_handle_type;
_LIBCPP_INLINE_VISIBILITY
thread() _NOEXCEPT : __t_(_LIBCPP_NULL_THREAD) {}
#ifndef _LIBCPP_CXX03_LANG
template <class _Fp, class ..._Args,
class = typename enable_if
<
!is_same<typename __uncvref<_Fp>::type, thread>::value
>::type
>
_LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
explicit thread(_Fp&& __f, _Args&&... __args);
#else // _LIBCPP_CXX03_LANG
template <class _Fp>
_LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
explicit thread(_Fp __f);
#endif
~thread();
#ifndef _LIBCPP_CXX03_LANG
_LIBCPP_INLINE_VISIBILITY
thread(thread&& __t) _NOEXCEPT : __t_(__t.__t_) {__t.__t_ = _LIBCPP_NULL_THREAD;}
_LIBCPP_INLINE_VISIBILITY
thread& operator=(thread&& __t) _NOEXCEPT;
#endif // _LIBCPP_CXX03_LANG
_LIBCPP_INLINE_VISIBILITY
void swap(thread& __t) _NOEXCEPT {_VSTD::swap(__t_, __t.__t_);}
_LIBCPP_INLINE_VISIBILITY
bool joinable() const _NOEXCEPT {return !__libcpp_thread_isnull(&__t_);}
void join();
void detach();
_LIBCPP_INLINE_VISIBILITY
id get_id() const _NOEXCEPT {return __libcpp_thread_get_id(&__t_);}
_LIBCPP_INLINE_VISIBILITY
native_handle_type native_handle() _NOEXCEPT {return __t_;}
static unsigned hardware_concurrency() _NOEXCEPT;
};
#ifndef _LIBCPP_CXX03_LANG
template <class _TSp, class _Fp, class ..._Args, size_t ..._Indices>
inline _LIBCPP_INLINE_VISIBILITY
void
__thread_execute(tuple<_TSp, _Fp, _Args...>& __t, __tuple_indices<_Indices...>)
{
__invoke(_VSTD::move(_VSTD::get<1>(__t)), _VSTD::move(_VSTD::get<_Indices>(__t))...);
}
template <class _Fp>
void* __thread_proxy(void* __vp)
{
// _Fp = std::tuple< unique_ptr<__thread_struct>, Functor, Args...>
std::unique_ptr<_Fp> __p(static_cast<_Fp*>(__vp));
__thread_local_data().set_pointer(_VSTD::get<0>(*__p).release());
typedef typename __make_tuple_indices<tuple_size<_Fp>::value, 2>::type _Index;
__thread_execute(*__p, _Index());
return nullptr;
}
template <class _Fp, class ..._Args,
class
>
thread::thread(_Fp&& __f, _Args&&... __args)
{
typedef unique_ptr<__thread_struct> _TSPtr;
_TSPtr __tsp(new __thread_struct);
typedef tuple<_TSPtr, typename decay<_Fp>::type, typename decay<_Args>::type...> _Gp;
_VSTD::unique_ptr<_Gp> __p(
new _Gp(std::move(__tsp),
__decay_copy(_VSTD::forward<_Fp>(__f)),
__decay_copy(_VSTD::forward<_Args>(__args))...));
int __ec = __libcpp_thread_create(&__t_, &__thread_proxy<_Gp>, __p.get());
if (__ec == 0)
__p.release();
else
__throw_system_error(__ec, "thread constructor failed");
}
inline
thread&
thread::operator=(thread&& __t) _NOEXCEPT
{
if (!__libcpp_thread_isnull(&__t_))
terminate();
__t_ = __t.__t_;
__t.__t_ = _LIBCPP_NULL_THREAD;
return *this;
}
#else // _LIBCPP_CXX03_LANG
template <class _Fp>
struct __thread_invoke_pair {
// This type is used to pass memory for thread local storage and a functor
// to a newly created thread because std::pair doesn't work with
// std::unique_ptr in C++03.
__thread_invoke_pair(_Fp& __f) : __tsp_(new __thread_struct), __fn_(__f) {}
unique_ptr<__thread_struct> __tsp_;
_Fp __fn_;
};
template <class _Fp>
void* __thread_proxy_cxx03(void* __vp)
{
std::unique_ptr<_Fp> __p(static_cast<_Fp*>(__vp));
__thread_local_data().set_pointer(__p->__tsp_.release());
(__p->__fn_)();
return nullptr;
}
template <class _Fp>
thread::thread(_Fp __f)
{
typedef __thread_invoke_pair<_Fp> _InvokePair;
typedef std::unique_ptr<_InvokePair> _PairPtr;
_PairPtr __pp(new _InvokePair(__f));
int __ec = __libcpp_thread_create(&__t_, &__thread_proxy_cxx03<_InvokePair>, __pp.get());
if (__ec == 0)
__pp.release();
else
__throw_system_error(__ec, "thread constructor failed");
}
#endif // _LIBCPP_CXX03_LANG
inline _LIBCPP_INLINE_VISIBILITY
void swap(thread& __x, thread& __y) _NOEXCEPT {__x.swap(__y);}
namespace this_thread
{
_LIBCPP_FUNC_VIS void sleep_for(const chrono::nanoseconds& __ns);
template <class _Rep, class _Period>
void
sleep_for(const chrono::duration<_Rep, _Period>& __d)
{
using namespace chrono;
if (__d > duration<_Rep, _Period>::zero())
{
#if defined(_LIBCPP_COMPILER_GCC) && (__powerpc__ || __POWERPC__)
// GCC's long double const folding is incomplete for IBM128 long doubles.
_LIBCPP_CONSTEXPR duration<long double> _Max = nanoseconds::max();
#else
_LIBCPP_CONSTEXPR duration<long double> _Max = duration<long double>(ULLONG_MAX/1000000000ULL) ;
#endif
nanoseconds __ns;
if (__d < _Max)
{
__ns = duration_cast<nanoseconds>(__d);
if (__ns < __d)
++__ns;
}
else
__ns = nanoseconds::max();
sleep_for(__ns);
}
}
template <class _Clock, class _Duration>
void
sleep_until(const chrono::time_point<_Clock, _Duration>& __t)
{
using namespace chrono;
mutex __mut;
condition_variable __cv;
unique_lock<mutex> __lk(__mut);
while (_Clock::now() < __t)
__cv.wait_until(__lk, __t);
}
template <class _Duration>
inline _LIBCPP_INLINE_VISIBILITY
void
sleep_until(const chrono::time_point<chrono::steady_clock, _Duration>& __t)
{
using namespace chrono;
sleep_for(__t - steady_clock::now());
}
inline _LIBCPP_INLINE_VISIBILITY
void yield() _NOEXCEPT {__libcpp_thread_yield();}
} // this_thread
_LIBCPP_END_NAMESPACE_STD
#endif // !_LIBCPP_HAS_NO_THREADS
_LIBCPP_POP_MACROS
#endif // _LIBCPP_THREAD
| 11,643 | 420 | jart/cosmopolitan | false |
cosmopolitan/third_party/libcxx/new | // -*- C++ -*-
//===----------------------------- new ------------------------------------===//
//
// 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_NEW
#define _LIBCPP_NEW
#include "third_party/libcxx/__config"
#include "third_party/libcxx/exception"
#include "third_party/libcxx/type_traits"
#include "third_party/libcxx/cstddef"
#include "third_party/libcxx/version"
#ifdef _LIBCPP_NO_EXCEPTIONS
#include "third_party/libcxx/cstdlib"
#endif
/*
new synopsis
namespace std
{
class bad_alloc
: public exception
{
public:
bad_alloc() noexcept;
bad_alloc(const bad_alloc&) noexcept;
bad_alloc& operator=(const bad_alloc&) noexcept;
virtual const char* what() const noexcept;
};
class bad_array_new_length : public bad_alloc // C++14
{
public:
bad_array_new_length() noexcept;
};
enum class align_val_t : size_t {}; // C++17
struct destroying_delete_t { // C++20
explicit destroying_delete_t() = default;
};
inline constexpr destroying_delete_t destroying_delete{}; // C++20
struct nothrow_t { explicit nothrow_t() = default; };
extern const nothrow_t nothrow;
typedef void (*new_handler)();
new_handler set_new_handler(new_handler new_p) noexcept;
new_handler get_new_handler() noexcept;
// 21.6.4, pointer optimization barrier
template <class T> constexpr T* launder(T* p) noexcept; // C++17
} // std
void* operator new(std::size_t size); // replaceable, nodiscard in C++2a
void* operator new(std::size_t size, std::align_val_t alignment); // replaceable, C++17, nodiscard in C++2a
void* operator new(std::size_t size, const std::nothrow_t&) noexcept; // replaceable, nodiscard in C++2a
void* operator new(std::size_t size, std::align_val_t alignment,
const std::nothrow_t&) noexcept; // replaceable, C++17, nodiscard in C++2a
void operator delete(void* ptr) noexcept; // replaceable
void operator delete(void* ptr, std::size_t size) noexcept; // replaceable, C++14
void operator delete(void* ptr, std::align_val_t alignment) noexcept; // replaceable, C++17
void operator delete(void* ptr, std::size_t size,
std::align_val_t alignment) noexcept; // replaceable, C++17
void operator delete(void* ptr, const std::nothrow_t&) noexcept; // replaceable
void operator delete(void* ptr, std:align_val_t alignment,
const std::nothrow_t&) noexcept; // replaceable, C++17
void* operator new[](std::size_t size); // replaceable, nodiscard in C++2a
void* operator new[](std::size_t size,
std::align_val_t alignment) noexcept; // replaceable, C++17, nodiscard in C++2a
void* operator new[](std::size_t size, const std::nothrow_t&) noexcept; // replaceable, nodiscard in C++2a
void* operator new[](std::size_t size, std::align_val_t alignment,
const std::nothrow_t&) noexcept; // replaceable, C++17, nodiscard in C++2a
void operator delete[](void* ptr) noexcept; // replaceable
void operator delete[](void* ptr, std::size_t size) noexcept; // replaceable, C++14
void operator delete[](void* ptr,
std::align_val_t alignment) noexcept; // replaceable, C++17
void operator delete[](void* ptr, std::size_t size,
std::align_val_t alignment) noexcept; // replaceable, C++17
void operator delete[](void* ptr, const std::nothrow_t&) noexcept; // replaceable
void operator delete[](void* ptr, std::align_val_t alignment,
const std::nothrow_t&) noexcept; // replaceable, C++17
void* operator new (std::size_t size, void* ptr) noexcept; // nodiscard in C++2a
void* operator new[](std::size_t size, void* ptr) noexcept; // nodiscard in C++2a
void operator delete (void* ptr, void*) noexcept;
void operator delete[](void* ptr, void*) noexcept;
*/
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
#pragma GCC system_header
#endif
#if !defined(__cpp_sized_deallocation) || __cpp_sized_deallocation < 201309L
#define _LIBCPP_HAS_NO_LANGUAGE_SIZED_DEALLOCATION
#endif
#if !defined(_LIBCPP_BUILDING_LIBRARY) && _LIBCPP_STD_VER < 14 && \
defined(_LIBCPP_HAS_NO_LANGUAGE_SIZED_DEALLOCATION)
# define _LIBCPP_HAS_NO_LIBRARY_SIZED_DEALLOCATION
#endif
#if defined(_LIBCPP_HAS_NO_LIBRARY_SIZED_DEALLOCATION) || \
defined(_LIBCPP_HAS_NO_LANGUAGE_SIZED_DEALLOCATION)
# define _LIBCPP_HAS_NO_SIZED_DEALLOCATION
#endif
#if !__has_builtin(__builtin_operator_new) || \
__has_builtin(__builtin_operator_new) < 201802L
#define _LIBCPP_HAS_NO_BUILTIN_OVERLOADED_OPERATOR_NEW_DELETE
#endif
namespace std // purposefully not using versioning namespace
{
#if !defined(_LIBCPP_ABI_VCRUNTIME)
struct _LIBCPP_TYPE_VIS nothrow_t { explicit nothrow_t() = default; };
extern _LIBCPP_FUNC_VIS const nothrow_t nothrow;
class _LIBCPP_EXCEPTION_ABI bad_alloc
: public exception
{
public:
bad_alloc() _NOEXCEPT;
virtual ~bad_alloc() _NOEXCEPT;
virtual const char* what() const _NOEXCEPT;
};
class _LIBCPP_EXCEPTION_ABI bad_array_new_length
: public bad_alloc
{
public:
bad_array_new_length() _NOEXCEPT;
virtual ~bad_array_new_length() _NOEXCEPT;
virtual const char* what() const _NOEXCEPT;
};
typedef void (*new_handler)();
_LIBCPP_FUNC_VIS new_handler set_new_handler(new_handler) _NOEXCEPT;
_LIBCPP_FUNC_VIS new_handler get_new_handler() _NOEXCEPT;
#endif // !_LIBCPP_ABI_VCRUNTIME
_LIBCPP_NORETURN _LIBCPP_FUNC_VIS void __throw_bad_alloc(); // not in C++ spec
#if !defined(_LIBCPP_HAS_NO_LIBRARY_ALIGNED_ALLOCATION) && \
!defined(_LIBCPP_ABI_VCRUNTIME)
#ifndef _LIBCPP_CXX03_LANG
enum class _LIBCPP_ENUM_VIS align_val_t : size_t { };
#else
enum align_val_t { __zero = 0, __max = (size_t)-1 };
#endif
#endif
#if _LIBCPP_STD_VER > 17
// Enable the declaration even if the compiler doesn't support the language
// feature.
struct destroying_delete_t {
explicit destroying_delete_t() = default;
};
_LIBCPP_INLINE_VAR constexpr destroying_delete_t destroying_delete{};
#endif // _LIBCPP_STD_VER > 17
} // std
#if defined(_LIBCPP_CXX03_LANG)
#define _THROW_BAD_ALLOC throw(std::bad_alloc)
#else
#define _THROW_BAD_ALLOC
#endif
#if !defined(_LIBCPP_ABI_VCRUNTIME)
_LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_OVERRIDABLE_FUNC_VIS void* operator new(std::size_t __sz) _THROW_BAD_ALLOC;
_LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_OVERRIDABLE_FUNC_VIS void* operator new(std::size_t __sz, const std::nothrow_t&) _NOEXCEPT _LIBCPP_NOALIAS;
_LIBCPP_OVERRIDABLE_FUNC_VIS void operator delete(void* __p) _NOEXCEPT;
_LIBCPP_OVERRIDABLE_FUNC_VIS void operator delete(void* __p, const std::nothrow_t&) _NOEXCEPT;
#ifndef _LIBCPP_HAS_NO_LIBRARY_SIZED_DEALLOCATION
_LIBCPP_OVERRIDABLE_FUNC_VIS _LIBCPP_AVAILABILITY_SIZED_NEW_DELETE void operator delete(void* __p, std::size_t __sz) _NOEXCEPT;
#endif
_LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_OVERRIDABLE_FUNC_VIS void* operator new[](std::size_t __sz) _THROW_BAD_ALLOC;
_LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_OVERRIDABLE_FUNC_VIS void* operator new[](std::size_t __sz, const std::nothrow_t&) _NOEXCEPT _LIBCPP_NOALIAS;
_LIBCPP_OVERRIDABLE_FUNC_VIS void operator delete[](void* __p) _NOEXCEPT;
_LIBCPP_OVERRIDABLE_FUNC_VIS void operator delete[](void* __p, const std::nothrow_t&) _NOEXCEPT;
#ifndef _LIBCPP_HAS_NO_LIBRARY_SIZED_DEALLOCATION
_LIBCPP_OVERRIDABLE_FUNC_VIS _LIBCPP_AVAILABILITY_SIZED_NEW_DELETE void operator delete[](void* __p, std::size_t __sz) _NOEXCEPT;
#endif
#ifndef _LIBCPP_HAS_NO_LIBRARY_ALIGNED_ALLOCATION
_LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_OVERRIDABLE_FUNC_VIS void* operator new(std::size_t __sz, std::align_val_t) _THROW_BAD_ALLOC;
_LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_OVERRIDABLE_FUNC_VIS void* operator new(std::size_t __sz, std::align_val_t, const std::nothrow_t&) _NOEXCEPT _LIBCPP_NOALIAS;
_LIBCPP_OVERRIDABLE_FUNC_VIS void operator delete(void* __p, std::align_val_t) _NOEXCEPT;
_LIBCPP_OVERRIDABLE_FUNC_VIS void operator delete(void* __p, std::align_val_t, const std::nothrow_t&) _NOEXCEPT;
#ifndef _LIBCPP_HAS_NO_LIBRARY_SIZED_DEALLOCATION
_LIBCPP_OVERRIDABLE_FUNC_VIS _LIBCPP_AVAILABILITY_SIZED_NEW_DELETE void operator delete(void* __p, std::size_t __sz, std::align_val_t) _NOEXCEPT;
#endif
_LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_OVERRIDABLE_FUNC_VIS void* operator new[](std::size_t __sz, std::align_val_t) _THROW_BAD_ALLOC;
_LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_OVERRIDABLE_FUNC_VIS void* operator new[](std::size_t __sz, std::align_val_t, const std::nothrow_t&) _NOEXCEPT _LIBCPP_NOALIAS;
_LIBCPP_OVERRIDABLE_FUNC_VIS void operator delete[](void* __p, std::align_val_t) _NOEXCEPT;
_LIBCPP_OVERRIDABLE_FUNC_VIS void operator delete[](void* __p, std::align_val_t, const std::nothrow_t&) _NOEXCEPT;
#ifndef _LIBCPP_HAS_NO_LIBRARY_SIZED_DEALLOCATION
_LIBCPP_OVERRIDABLE_FUNC_VIS _LIBCPP_AVAILABILITY_SIZED_NEW_DELETE void operator delete[](void* __p, std::size_t __sz, std::align_val_t) _NOEXCEPT;
#endif
#endif
_LIBCPP_NODISCARD_AFTER_CXX17 inline _LIBCPP_INLINE_VISIBILITY void* operator new (std::size_t, void* __p) _NOEXCEPT {return __p;}
_LIBCPP_NODISCARD_AFTER_CXX17 inline _LIBCPP_INLINE_VISIBILITY void* operator new[](std::size_t, void* __p) _NOEXCEPT {return __p;}
inline _LIBCPP_INLINE_VISIBILITY void operator delete (void*, void*) _NOEXCEPT {}
inline _LIBCPP_INLINE_VISIBILITY void operator delete[](void*, void*) _NOEXCEPT {}
#endif // !_LIBCPP_ABI_VCRUNTIME
_LIBCPP_BEGIN_NAMESPACE_STD
_LIBCPP_CONSTEXPR inline _LIBCPP_INLINE_VISIBILITY bool __is_overaligned_for_new(size_t __align) _NOEXCEPT {
#ifdef __STDCPP_DEFAULT_NEW_ALIGNMENT__
return __align > __STDCPP_DEFAULT_NEW_ALIGNMENT__;
#else
return __align > alignment_of<max_align_t>::value;
#endif
}
inline _LIBCPP_INLINE_VISIBILITY void *__libcpp_allocate(size_t __size, size_t __align) {
#ifndef _LIBCPP_HAS_NO_ALIGNED_ALLOCATION
if (__is_overaligned_for_new(__align)) {
const align_val_t __align_val = static_cast<align_val_t>(__align);
# ifdef _LIBCPP_HAS_NO_BUILTIN_OVERLOADED_OPERATOR_NEW_DELETE
return ::operator new(__size, __align_val);
# else
return __builtin_operator_new(__size, __align_val);
# endif
}
#else
((void)__align);
#endif
#ifdef _LIBCPP_HAS_NO_BUILTIN_OPERATOR_NEW_DELETE
return ::operator new(__size);
#else
return __builtin_operator_new(__size);
#endif
}
struct _DeallocateCaller {
static inline _LIBCPP_INLINE_VISIBILITY
void __do_deallocate_handle_size_align(void *__ptr, size_t __size, size_t __align) {
#if defined(_LIBCPP_HAS_NO_ALIGNED_ALLOCATION)
((void)__align);
return __do_deallocate_handle_size(__ptr, __size);
#else
if (__is_overaligned_for_new(__align)) {
const align_val_t __align_val = static_cast<align_val_t>(__align);
return __do_deallocate_handle_size(__ptr, __size, __align_val);
} else {
return __do_deallocate_handle_size(__ptr, __size);
}
#endif
}
static inline _LIBCPP_INLINE_VISIBILITY
void __do_deallocate_handle_align(void *__ptr, size_t __align) {
#if defined(_LIBCPP_HAS_NO_ALIGNED_ALLOCATION)
((void)__align);
return __do_call(__ptr);
#else
if (__is_overaligned_for_new(__align)) {
const align_val_t __align_val = static_cast<align_val_t>(__align);
return __do_call(__ptr, __align_val);
} else {
return __do_call(__ptr);
}
#endif
}
private:
static inline void __do_deallocate_handle_size(void *__ptr, size_t __size) {
#ifdef _LIBCPP_HAS_NO_SIZED_DEALLOCATION
((void)__size);
return __do_call(__ptr);
#else
return __do_call(__ptr, __size);
#endif
}
#ifndef _LIBCPP_HAS_NO_ALIGNED_ALLOCATION
static inline void __do_deallocate_handle_size(void *__ptr, size_t __size, align_val_t __align) {
#ifdef _LIBCPP_HAS_NO_SIZED_DEALLOCATION
((void)__size);
return __do_call(__ptr, __align);
#else
return __do_call(__ptr, __size, __align);
#endif
}
#endif
private:
template <class _A1, class _A2>
static inline void __do_call(void *__ptr, _A1 __a1, _A2 __a2) {
#if defined(_LIBCPP_HAS_NO_BUILTIN_OPERATOR_NEW_DELETE) || \
defined(_LIBCPP_HAS_NO_BUILTIN_OVERLOADED_OPERATOR_NEW_DELETE)
return ::operator delete(__ptr, __a1, __a2);
#else
return __builtin_operator_delete(__ptr, __a1, __a2);
#endif
}
template <class _A1>
static inline void __do_call(void *__ptr, _A1 __a1) {
#if defined(_LIBCPP_HAS_NO_BUILTIN_OPERATOR_NEW_DELETE) || \
defined(_LIBCPP_HAS_NO_BUILTIN_OVERLOADED_OPERATOR_NEW_DELETE)
return ::operator delete(__ptr, __a1);
#else
return __builtin_operator_delete(__ptr, __a1);
#endif
}
static inline void __do_call(void *__ptr) {
#ifdef _LIBCPP_HAS_NO_BUILTIN_OPERATOR_NEW_DELETE
return ::operator delete(__ptr);
#else
return __builtin_operator_delete(__ptr);
#endif
}
};
inline _LIBCPP_INLINE_VISIBILITY void __libcpp_deallocate(void* __ptr, size_t __size, size_t __align) {
_DeallocateCaller::__do_deallocate_handle_size_align(__ptr, __size, __align);
}
inline _LIBCPP_INLINE_VISIBILITY void __libcpp_deallocate_unsized(void* __ptr, size_t __align) {
_DeallocateCaller::__do_deallocate_handle_align(__ptr, __align);
}
template <class _Tp>
_LIBCPP_NODISCARD_AFTER_CXX17 inline
_LIBCPP_CONSTEXPR _Tp* __launder(_Tp* __p) _NOEXCEPT
{
static_assert (!(is_function<_Tp>::value), "can't launder functions" );
static_assert (!(is_same<void, typename remove_cv<_Tp>::type>::value), "can't launder cv-void" );
#ifdef _LIBCPP_COMPILER_HAS_BUILTIN_LAUNDER
return __builtin_launder(__p);
#else
return __p;
#endif
}
#if _LIBCPP_STD_VER > 14
template <class _Tp>
_LIBCPP_NODISCARD_AFTER_CXX17 inline _LIBCPP_INLINE_VISIBILITY
constexpr _Tp* launder(_Tp* __p) noexcept
{
return _VSTD::__launder(__p);
}
#endif
_LIBCPP_END_NAMESPACE_STD
#endif // _LIBCPP_NEW
| 14,176 | 369 | jart/cosmopolitan | false |
cosmopolitan/third_party/libcxx/new_handler_fallback.hh | // -*- 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
//
//===----------------------------------------------------------------------===//
#include "third_party/libcxx/__config"
#include "third_party/libcxx/new"
#include "third_party/libcxx/atomic_support.hh"
namespace std {
_LIBCPP_SAFE_STATIC static std::new_handler __new_handler;
new_handler set_new_handler(new_handler handler) _NOEXCEPT {
return __libcpp_atomic_exchange(&__new_handler, handler);
}
new_handler get_new_handler() _NOEXCEPT {
return __libcpp_atomic_load(&__new_handler);
}
} // namespace std
| 819 | 27 | jart/cosmopolitan | false |
cosmopolitan/third_party/libcxx/__string | // -*- C++ -*-
//===-------------------------- __string ----------------------------------===//
//
// 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___STRING
#define _LIBCPP___STRING
#include "third_party/libcxx/__config"
#include "third_party/libcxx/algorithm" // for search and min
#include "third_party/libcxx/cstdio" // For EOF.
#include "third_party/libcxx/memory" // for __murmur2_or_cityhash
#include "third_party/libcxx/__debug"
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
#pragma GCC system_header
#endif
_LIBCPP_PUSH_MACROS
#include "third_party/libcxx/__undef_macros"
_LIBCPP_BEGIN_NAMESPACE_STD
/*
string synopsis
namespace std
{
template <class charT>
struct char_traits
{
typedef charT char_type;
typedef ... int_type;
typedef streamoff off_type;
typedef streampos pos_type;
typedef mbstate_t state_type;
static constexpr void assign(char_type& c1, const char_type& c2) noexcept;
static constexpr bool eq(char_type c1, char_type c2) noexcept;
static constexpr bool lt(char_type c1, char_type c2) noexcept;
static constexpr int compare(const char_type* s1, const char_type* s2, size_t n);
static constexpr size_t length(const char_type* s);
static constexpr const char_type*
find(const char_type* s, size_t n, const char_type& a);
static char_type* move(char_type* s1, const char_type* s2, size_t n);
static char_type* copy(char_type* s1, const char_type* s2, size_t n);
static char_type* assign(char_type* s, size_t n, char_type a);
static constexpr int_type not_eof(int_type c) noexcept;
static constexpr char_type to_char_type(int_type c) noexcept;
static constexpr int_type to_int_type(char_type c) noexcept;
static constexpr bool eq_int_type(int_type c1, int_type c2) noexcept;
static constexpr int_type eof() noexcept;
};
template <> struct char_traits<char>;
template <> struct char_traits<wchar_t>;
template <> struct char_traits<char8_t>; // c++20
} // std
*/
// char_traits
template <class _CharT>
struct _LIBCPP_TEMPLATE_VIS char_traits
{
typedef _CharT char_type;
typedef int int_type;
typedef streamoff off_type;
typedef streampos pos_type;
typedef mbstate_t state_type;
static inline void _LIBCPP_CONSTEXPR_AFTER_CXX14
assign(char_type& __c1, const char_type& __c2) _NOEXCEPT {__c1 = __c2;}
static inline _LIBCPP_CONSTEXPR bool eq(char_type __c1, char_type __c2) _NOEXCEPT
{return __c1 == __c2;}
static inline _LIBCPP_CONSTEXPR bool lt(char_type __c1, char_type __c2) _NOEXCEPT
{return __c1 < __c2;}
static _LIBCPP_CONSTEXPR_AFTER_CXX14
int compare(const char_type* __s1, const char_type* __s2, size_t __n);
_LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR_AFTER_CXX14
size_t length(const char_type* __s);
_LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR_AFTER_CXX14
const char_type* find(const char_type* __s, size_t __n, const char_type& __a);
static char_type* move(char_type* __s1, const char_type* __s2, size_t __n);
_LIBCPP_INLINE_VISIBILITY
static char_type* copy(char_type* __s1, const char_type* __s2, size_t __n);
_LIBCPP_INLINE_VISIBILITY
static char_type* assign(char_type* __s, size_t __n, char_type __a);
static inline _LIBCPP_CONSTEXPR int_type not_eof(int_type __c) _NOEXCEPT
{return eq_int_type(__c, eof()) ? ~eof() : __c;}
static inline _LIBCPP_CONSTEXPR char_type to_char_type(int_type __c) _NOEXCEPT
{return char_type(__c);}
static inline _LIBCPP_CONSTEXPR int_type to_int_type(char_type __c) _NOEXCEPT
{return int_type(__c);}
static inline _LIBCPP_CONSTEXPR bool eq_int_type(int_type __c1, int_type __c2) _NOEXCEPT
{return __c1 == __c2;}
static inline _LIBCPP_CONSTEXPR int_type eof() _NOEXCEPT
{return int_type(EOF);}
};
template <class _CharT>
_LIBCPP_CONSTEXPR_AFTER_CXX14 int
char_traits<_CharT>::compare(const char_type* __s1, const char_type* __s2, size_t __n)
{
for (; __n; --__n, ++__s1, ++__s2)
{
if (lt(*__s1, *__s2))
return -1;
if (lt(*__s2, *__s1))
return 1;
}
return 0;
}
template <class _CharT>
inline
_LIBCPP_CONSTEXPR_AFTER_CXX14 size_t
char_traits<_CharT>::length(const char_type* __s)
{
size_t __len = 0;
for (; !eq(*__s, char_type(0)); ++__s)
++__len;
return __len;
}
template <class _CharT>
inline
_LIBCPP_CONSTEXPR_AFTER_CXX14 const _CharT*
char_traits<_CharT>::find(const char_type* __s, size_t __n, const char_type& __a)
{
for (; __n; --__n)
{
if (eq(*__s, __a))
return __s;
++__s;
}
return 0;
}
template <class _CharT>
_CharT*
char_traits<_CharT>::move(char_type* __s1, const char_type* __s2, size_t __n)
{
char_type* __r = __s1;
if (__s1 < __s2)
{
for (; __n; --__n, ++__s1, ++__s2)
assign(*__s1, *__s2);
}
else if (__s2 < __s1)
{
__s1 += __n;
__s2 += __n;
for (; __n; --__n)
assign(*--__s1, *--__s2);
}
return __r;
}
template <class _CharT>
inline
_CharT*
char_traits<_CharT>::copy(char_type* __s1, const char_type* __s2, size_t __n)
{
_LIBCPP_ASSERT(__s2 < __s1 || __s2 >= __s1+__n, "char_traits::copy overlapped range");
char_type* __r = __s1;
for (; __n; --__n, ++__s1, ++__s2)
assign(*__s1, *__s2);
return __r;
}
template <class _CharT>
inline
_CharT*
char_traits<_CharT>::assign(char_type* __s, size_t __n, char_type __a)
{
char_type* __r = __s;
for (; __n; --__n, ++__s)
assign(*__s, __a);
return __r;
}
// char_traits<char>
template <>
struct _LIBCPP_TEMPLATE_VIS char_traits<char>
{
typedef char char_type;
typedef int int_type;
typedef streamoff off_type;
typedef streampos pos_type;
typedef mbstate_t state_type;
static inline _LIBCPP_CONSTEXPR_AFTER_CXX14
void assign(char_type& __c1, const char_type& __c2) _NOEXCEPT {__c1 = __c2;}
static inline _LIBCPP_CONSTEXPR bool eq(char_type __c1, char_type __c2) _NOEXCEPT
{return __c1 == __c2;}
static inline _LIBCPP_CONSTEXPR bool lt(char_type __c1, char_type __c2) _NOEXCEPT
{return (unsigned char)__c1 < (unsigned char)__c2;}
static _LIBCPP_CONSTEXPR_AFTER_CXX14
int compare(const char_type* __s1, const char_type* __s2, size_t __n) _NOEXCEPT;
static inline size_t _LIBCPP_CONSTEXPR_AFTER_CXX14
length(const char_type* __s) _NOEXCEPT {return __builtin_strlen(__s);}
static _LIBCPP_CONSTEXPR_AFTER_CXX14
const char_type* find(const char_type* __s, size_t __n, const char_type& __a) _NOEXCEPT;
static inline char_type* move(char_type* __s1, const char_type* __s2, size_t __n) _NOEXCEPT
{return __n == 0 ? __s1 : (char_type*) memmove(__s1, __s2, __n);}
static inline char_type* copy(char_type* __s1, const char_type* __s2, size_t __n) _NOEXCEPT
{
_LIBCPP_ASSERT(__s2 < __s1 || __s2 >= __s1+__n, "char_traits::copy overlapped range");
return __n == 0 ? __s1 : (char_type*)memcpy(__s1, __s2, __n);
}
static inline char_type* assign(char_type* __s, size_t __n, char_type __a) _NOEXCEPT
{return __n == 0 ? __s : (char_type*)memset(__s, to_int_type(__a), __n);}
static inline _LIBCPP_CONSTEXPR int_type not_eof(int_type __c) _NOEXCEPT
{return eq_int_type(__c, eof()) ? ~eof() : __c;}
static inline _LIBCPP_CONSTEXPR char_type to_char_type(int_type __c) _NOEXCEPT
{return char_type(__c);}
static inline _LIBCPP_CONSTEXPR int_type to_int_type(char_type __c) _NOEXCEPT
{return int_type((unsigned char)__c);}
static inline _LIBCPP_CONSTEXPR bool eq_int_type(int_type __c1, int_type __c2) _NOEXCEPT
{return __c1 == __c2;}
static inline _LIBCPP_CONSTEXPR int_type eof() _NOEXCEPT
{return int_type(EOF);}
};
inline _LIBCPP_CONSTEXPR_AFTER_CXX14
int
char_traits<char>::compare(const char_type* __s1, const char_type* __s2, size_t __n) _NOEXCEPT
{
if (__n == 0)
return 0;
#if __has_feature(cxx_constexpr_string_builtins)
return __builtin_memcmp(__s1, __s2, __n);
#elif _LIBCPP_STD_VER <= 14
return memcmp(__s1, __s2, __n);
#else
for (; __n; --__n, ++__s1, ++__s2)
{
if (lt(*__s1, *__s2))
return -1;
if (lt(*__s2, *__s1))
return 1;
}
return 0;
#endif
}
inline _LIBCPP_CONSTEXPR_AFTER_CXX14
const char*
char_traits<char>::find(const char_type* __s, size_t __n, const char_type& __a) _NOEXCEPT
{
if (__n == 0)
return nullptr;
#if __has_feature(cxx_constexpr_string_builtins)
return __builtin_char_memchr(__s, to_int_type(__a), __n);
#elif _LIBCPP_STD_VER <= 14
return (const char_type*) memchr(__s, to_int_type(__a), __n);
#else
for (; __n; --__n)
{
if (eq(*__s, __a))
return __s;
++__s;
}
return nullptr;
#endif
}
// char_traits<wchar_t>
template <>
struct _LIBCPP_TEMPLATE_VIS char_traits<wchar_t>
{
typedef wchar_t char_type;
typedef wint_t int_type;
typedef streamoff off_type;
typedef streampos pos_type;
typedef mbstate_t state_type;
static inline _LIBCPP_CONSTEXPR_AFTER_CXX14
void assign(char_type& __c1, const char_type& __c2) _NOEXCEPT {__c1 = __c2;}
static inline _LIBCPP_CONSTEXPR bool eq(char_type __c1, char_type __c2) _NOEXCEPT
{return __c1 == __c2;}
static inline _LIBCPP_CONSTEXPR bool lt(char_type __c1, char_type __c2) _NOEXCEPT
{return __c1 < __c2;}
static _LIBCPP_CONSTEXPR_AFTER_CXX14
int compare(const char_type* __s1, const char_type* __s2, size_t __n) _NOEXCEPT;
static _LIBCPP_CONSTEXPR_AFTER_CXX14
size_t length(const char_type* __s) _NOEXCEPT;
static _LIBCPP_CONSTEXPR_AFTER_CXX14
const char_type* find(const char_type* __s, size_t __n, const char_type& __a) _NOEXCEPT;
static inline char_type* move(char_type* __s1, const char_type* __s2, size_t __n) _NOEXCEPT
{return __n == 0 ? __s1 : (char_type*)wmemmove(__s1, __s2, __n);}
static inline char_type* copy(char_type* __s1, const char_type* __s2, size_t __n) _NOEXCEPT
{
_LIBCPP_ASSERT(__s2 < __s1 || __s2 >= __s1+__n, "char_traits::copy overlapped range");
return __n == 0 ? __s1 : (char_type*)wmemcpy(__s1, __s2, __n);
}
static inline char_type* assign(char_type* __s, size_t __n, char_type __a) _NOEXCEPT
{return __n == 0 ? __s : (char_type*)wmemset(__s, __a, __n);}
static inline _LIBCPP_CONSTEXPR int_type not_eof(int_type __c) _NOEXCEPT
{return eq_int_type(__c, eof()) ? ~eof() : __c;}
static inline _LIBCPP_CONSTEXPR char_type to_char_type(int_type __c) _NOEXCEPT
{return char_type(__c);}
static inline _LIBCPP_CONSTEXPR int_type to_int_type(char_type __c) _NOEXCEPT
{return int_type(__c);}
static inline _LIBCPP_CONSTEXPR bool eq_int_type(int_type __c1, int_type __c2) _NOEXCEPT
{return __c1 == __c2;}
static inline _LIBCPP_CONSTEXPR int_type eof() _NOEXCEPT
{return int_type(WEOF);}
};
inline _LIBCPP_CONSTEXPR_AFTER_CXX14
int
char_traits<wchar_t>::compare(const char_type* __s1, const char_type* __s2, size_t __n) _NOEXCEPT
{
if (__n == 0)
return 0;
#if __has_feature(cxx_constexpr_string_builtins)
return __builtin_wmemcmp(__s1, __s2, __n);
#elif _LIBCPP_STD_VER <= 14
return wmemcmp(__s1, __s2, __n);
#else
for (; __n; --__n, ++__s1, ++__s2)
{
if (lt(*__s1, *__s2))
return -1;
if (lt(*__s2, *__s1))
return 1;
}
return 0;
#endif
}
template <class _Traits>
_LIBCPP_INLINE_VISIBILITY
_LIBCPP_CONSTEXPR
inline size_t __char_traits_length_checked(const typename _Traits::char_type* __s) _NOEXCEPT {
#if _LIBCPP_DEBUG_LEVEL >= 1
return __s ? _Traits::length(__s) : (_VSTD::__libcpp_debug_function(_VSTD::__libcpp_debug_info(__FILE__, __LINE__, "p == nullptr", "null pointer pass to non-null argument of char_traits<...>::length")), 0);
#else
return _Traits::length(__s);
#endif
}
inline _LIBCPP_CONSTEXPR_AFTER_CXX14
size_t
char_traits<wchar_t>::length(const char_type* __s) _NOEXCEPT
{
#if __has_feature(cxx_constexpr_string_builtins)
return __builtin_wcslen(__s);
#elif _LIBCPP_STD_VER <= 14
return wcslen(__s);
#else
size_t __len = 0;
for (; !eq(*__s, char_type(0)); ++__s)
++__len;
return __len;
#endif
}
inline _LIBCPP_CONSTEXPR_AFTER_CXX14
const wchar_t*
char_traits<wchar_t>::find(const char_type* __s, size_t __n, const char_type& __a) _NOEXCEPT
{
if (__n == 0)
return nullptr;
#if __has_feature(cxx_constexpr_string_builtins)
return __builtin_wmemchr(__s, __a, __n);
#elif _LIBCPP_STD_VER <= 14
return wmemchr(__s, __a, __n);
#else
for (; __n; --__n)
{
if (eq(*__s, __a))
return __s;
++__s;
}
return nullptr;
#endif
}
#ifndef _LIBCPP_NO_HAS_CHAR8_T
template <>
struct _LIBCPP_TEMPLATE_VIS char_traits<char8_t>
{
typedef char8_t char_type;
typedef unsigned int int_type;
typedef streamoff off_type;
typedef u8streampos pos_type;
typedef mbstate_t state_type;
static inline constexpr void assign(char_type& __c1, const char_type& __c2) noexcept
{__c1 = __c2;}
static inline constexpr bool eq(char_type __c1, char_type __c2) noexcept
{return __c1 == __c2;}
static inline constexpr bool lt(char_type __c1, char_type __c2) noexcept
{return __c1 < __c2;}
static constexpr
int compare(const char_type* __s1, const char_type* __s2, size_t __n) _NOEXCEPT;
static constexpr
size_t length(const char_type* __s) _NOEXCEPT;
_LIBCPP_INLINE_VISIBILITY static constexpr
const char_type* find(const char_type* __s, size_t __n, const char_type& __a) _NOEXCEPT;
static char_type* move(char_type* __s1, const char_type* __s2, size_t __n) _NOEXCEPT
{return __n == 0 ? __s1 : (char_type*) memmove(__s1, __s2, __n);}
static char_type* copy(char_type* __s1, const char_type* __s2, size_t __n) _NOEXCEPT
{
_LIBCPP_ASSERT(__s2 < __s1 || __s2 >= __s1+__n, "char_traits::copy overlapped range");
return __n == 0 ? __s1 : (char_type*)memcpy(__s1, __s2, __n);
}
static char_type* assign(char_type* __s, size_t __n, char_type __a) _NOEXCEPT
{return __n == 0 ? __s : (char_type*)memset(__s, to_int_type(__a), __n);}
static inline constexpr int_type not_eof(int_type __c) noexcept
{return eq_int_type(__c, eof()) ? ~eof() : __c;}
static inline constexpr char_type to_char_type(int_type __c) noexcept
{return char_type(__c);}
static inline constexpr int_type to_int_type(char_type __c) noexcept
{return int_type(__c);}
static inline constexpr bool eq_int_type(int_type __c1, int_type __c2) noexcept
{return __c1 == __c2;}
static inline constexpr int_type eof() noexcept
{return int_type(EOF);}
};
// TODO use '__builtin_strlen' if it ever supports char8_t ??
inline constexpr
size_t
char_traits<char8_t>::length(const char_type* __s) _NOEXCEPT
{
size_t __len = 0;
for (; !eq(*__s, char_type(0)); ++__s)
++__len;
return __len;
}
inline constexpr
int
char_traits<char8_t>::compare(const char_type* __s1, const char_type* __s2, size_t __n) _NOEXCEPT
{
#if __has_feature(cxx_constexpr_string_builtins)
return __builtin_memcmp(__s1, __s2, __n);
#else
for (; __n; --__n, ++__s1, ++__s2)
{
if (lt(*__s1, *__s2))
return -1;
if (lt(*__s2, *__s1))
return 1;
}
return 0;
#endif
}
// TODO use '__builtin_char_memchr' if it ever supports char8_t ??
inline constexpr
const char8_t*
char_traits<char8_t>::find(const char_type* __s, size_t __n, const char_type& __a) _NOEXCEPT
{
for (; __n; --__n)
{
if (eq(*__s, __a))
return __s;
++__s;
}
return 0;
}
#endif // #_LIBCPP_NO_HAS_CHAR8_T
#ifndef _LIBCPP_HAS_NO_UNICODE_CHARS
template <>
struct _LIBCPP_TEMPLATE_VIS char_traits<char16_t>
{
typedef char16_t char_type;
typedef uint_least16_t int_type;
typedef streamoff off_type;
typedef u16streampos pos_type;
typedef mbstate_t state_type;
static inline _LIBCPP_CONSTEXPR_AFTER_CXX14
void assign(char_type& __c1, const char_type& __c2) _NOEXCEPT {__c1 = __c2;}
static inline _LIBCPP_CONSTEXPR bool eq(char_type __c1, char_type __c2) _NOEXCEPT
{return __c1 == __c2;}
static inline _LIBCPP_CONSTEXPR bool lt(char_type __c1, char_type __c2) _NOEXCEPT
{return __c1 < __c2;}
_LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR_AFTER_CXX14
int compare(const char_type* __s1, const char_type* __s2, size_t __n) _NOEXCEPT;
_LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR_AFTER_CXX14
size_t length(const char_type* __s) _NOEXCEPT;
_LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR_AFTER_CXX14
const char_type* find(const char_type* __s, size_t __n, const char_type& __a) _NOEXCEPT;
_LIBCPP_INLINE_VISIBILITY
static char_type* move(char_type* __s1, const char_type* __s2, size_t __n) _NOEXCEPT;
_LIBCPP_INLINE_VISIBILITY
static char_type* copy(char_type* __s1, const char_type* __s2, size_t __n) _NOEXCEPT;
_LIBCPP_INLINE_VISIBILITY
static char_type* assign(char_type* __s, size_t __n, char_type __a) _NOEXCEPT;
static inline _LIBCPP_CONSTEXPR int_type not_eof(int_type __c) _NOEXCEPT
{return eq_int_type(__c, eof()) ? ~eof() : __c;}
static inline _LIBCPP_CONSTEXPR char_type to_char_type(int_type __c) _NOEXCEPT
{return char_type(__c);}
static inline _LIBCPP_CONSTEXPR int_type to_int_type(char_type __c) _NOEXCEPT
{return int_type(__c);}
static inline _LIBCPP_CONSTEXPR bool eq_int_type(int_type __c1, int_type __c2) _NOEXCEPT
{return __c1 == __c2;}
static inline _LIBCPP_CONSTEXPR int_type eof() _NOEXCEPT
{return int_type(0xFFFF);}
};
inline _LIBCPP_CONSTEXPR_AFTER_CXX14
int
char_traits<char16_t>::compare(const char_type* __s1, const char_type* __s2, size_t __n) _NOEXCEPT
{
for (; __n; --__n, ++__s1, ++__s2)
{
if (lt(*__s1, *__s2))
return -1;
if (lt(*__s2, *__s1))
return 1;
}
return 0;
}
inline _LIBCPP_CONSTEXPR_AFTER_CXX14
size_t
char_traits<char16_t>::length(const char_type* __s) _NOEXCEPT
{
size_t __len = 0;
for (; !eq(*__s, char_type(0)); ++__s)
++__len;
return __len;
}
inline _LIBCPP_CONSTEXPR_AFTER_CXX14
const char16_t*
char_traits<char16_t>::find(const char_type* __s, size_t __n, const char_type& __a) _NOEXCEPT
{
for (; __n; --__n)
{
if (eq(*__s, __a))
return __s;
++__s;
}
return 0;
}
inline
char16_t*
char_traits<char16_t>::move(char_type* __s1, const char_type* __s2, size_t __n) _NOEXCEPT
{
char_type* __r = __s1;
if (__s1 < __s2)
{
for (; __n; --__n, ++__s1, ++__s2)
assign(*__s1, *__s2);
}
else if (__s2 < __s1)
{
__s1 += __n;
__s2 += __n;
for (; __n; --__n)
assign(*--__s1, *--__s2);
}
return __r;
}
inline
char16_t*
char_traits<char16_t>::copy(char_type* __s1, const char_type* __s2, size_t __n) _NOEXCEPT
{
_LIBCPP_ASSERT(__s2 < __s1 || __s2 >= __s1+__n, "char_traits::copy overlapped range");
char_type* __r = __s1;
for (; __n; --__n, ++__s1, ++__s2)
assign(*__s1, *__s2);
return __r;
}
inline
char16_t*
char_traits<char16_t>::assign(char_type* __s, size_t __n, char_type __a) _NOEXCEPT
{
char_type* __r = __s;
for (; __n; --__n, ++__s)
assign(*__s, __a);
return __r;
}
template <>
struct _LIBCPP_TEMPLATE_VIS char_traits<char32_t>
{
typedef char32_t char_type;
typedef uint_least32_t int_type;
typedef streamoff off_type;
typedef u32streampos pos_type;
typedef mbstate_t state_type;
static inline _LIBCPP_CONSTEXPR_AFTER_CXX14
void assign(char_type& __c1, const char_type& __c2) _NOEXCEPT {__c1 = __c2;}
static inline _LIBCPP_CONSTEXPR bool eq(char_type __c1, char_type __c2) _NOEXCEPT
{return __c1 == __c2;}
static inline _LIBCPP_CONSTEXPR bool lt(char_type __c1, char_type __c2) _NOEXCEPT
{return __c1 < __c2;}
_LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR_AFTER_CXX14
int compare(const char_type* __s1, const char_type* __s2, size_t __n) _NOEXCEPT;
_LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR_AFTER_CXX14
size_t length(const char_type* __s) _NOEXCEPT;
_LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR_AFTER_CXX14
const char_type* find(const char_type* __s, size_t __n, const char_type& __a) _NOEXCEPT;
_LIBCPP_INLINE_VISIBILITY
static char_type* move(char_type* __s1, const char_type* __s2, size_t __n) _NOEXCEPT;
_LIBCPP_INLINE_VISIBILITY
static char_type* copy(char_type* __s1, const char_type* __s2, size_t __n) _NOEXCEPT;
_LIBCPP_INLINE_VISIBILITY
static char_type* assign(char_type* __s, size_t __n, char_type __a) _NOEXCEPT;
static inline _LIBCPP_CONSTEXPR int_type not_eof(int_type __c) _NOEXCEPT
{return eq_int_type(__c, eof()) ? ~eof() : __c;}
static inline _LIBCPP_CONSTEXPR char_type to_char_type(int_type __c) _NOEXCEPT
{return char_type(__c);}
static inline _LIBCPP_CONSTEXPR int_type to_int_type(char_type __c) _NOEXCEPT
{return int_type(__c);}
static inline _LIBCPP_CONSTEXPR bool eq_int_type(int_type __c1, int_type __c2) _NOEXCEPT
{return __c1 == __c2;}
static inline _LIBCPP_CONSTEXPR int_type eof() _NOEXCEPT
{return int_type(0xFFFFFFFF);}
};
inline _LIBCPP_CONSTEXPR_AFTER_CXX14
int
char_traits<char32_t>::compare(const char_type* __s1, const char_type* __s2, size_t __n) _NOEXCEPT
{
for (; __n; --__n, ++__s1, ++__s2)
{
if (lt(*__s1, *__s2))
return -1;
if (lt(*__s2, *__s1))
return 1;
}
return 0;
}
inline _LIBCPP_CONSTEXPR_AFTER_CXX14
size_t
char_traits<char32_t>::length(const char_type* __s) _NOEXCEPT
{
size_t __len = 0;
for (; !eq(*__s, char_type(0)); ++__s)
++__len;
return __len;
}
inline _LIBCPP_CONSTEXPR_AFTER_CXX14
const char32_t*
char_traits<char32_t>::find(const char_type* __s, size_t __n, const char_type& __a) _NOEXCEPT
{
for (; __n; --__n)
{
if (eq(*__s, __a))
return __s;
++__s;
}
return 0;
}
inline
char32_t*
char_traits<char32_t>::move(char_type* __s1, const char_type* __s2, size_t __n) _NOEXCEPT
{
char_type* __r = __s1;
if (__s1 < __s2)
{
for (; __n; --__n, ++__s1, ++__s2)
assign(*__s1, *__s2);
}
else if (__s2 < __s1)
{
__s1 += __n;
__s2 += __n;
for (; __n; --__n)
assign(*--__s1, *--__s2);
}
return __r;
}
inline
char32_t*
char_traits<char32_t>::copy(char_type* __s1, const char_type* __s2, size_t __n) _NOEXCEPT
{
_LIBCPP_ASSERT(__s2 < __s1 || __s2 >= __s1+__n, "char_traits::copy overlapped range");
char_type* __r = __s1;
for (; __n; --__n, ++__s1, ++__s2)
assign(*__s1, *__s2);
return __r;
}
inline
char32_t*
char_traits<char32_t>::assign(char_type* __s, size_t __n, char_type __a) _NOEXCEPT
{
char_type* __r = __s;
for (; __n; --__n, ++__s)
assign(*__s, __a);
return __r;
}
#endif // _LIBCPP_HAS_NO_UNICODE_CHARS
// helper fns for basic_string and string_view
// __str_find
template<class _CharT, class _SizeT, class _Traits, _SizeT __npos>
inline _SizeT _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
__str_find(const _CharT *__p, _SizeT __sz,
_CharT __c, _SizeT __pos) _NOEXCEPT
{
if (__pos >= __sz)
return __npos;
const _CharT* __r = _Traits::find(__p + __pos, __sz - __pos, __c);
if (__r == 0)
return __npos;
return static_cast<_SizeT>(__r - __p);
}
template <class _CharT, class _Traits>
inline _LIBCPP_CONSTEXPR_AFTER_CXX11 const _CharT *
__search_substring(const _CharT *__first1, const _CharT *__last1,
const _CharT *__first2, const _CharT *__last2) {
// Take advantage of knowing source and pattern lengths.
// Stop short when source is smaller than pattern.
const ptrdiff_t __len2 = __last2 - __first2;
if (__len2 == 0)
return __first1;
ptrdiff_t __len1 = __last1 - __first1;
if (__len1 < __len2)
return __last1;
// First element of __first2 is loop invariant.
_CharT __f2 = *__first2;
while (true) {
__len1 = __last1 - __first1;
// Check whether __first1 still has at least __len2 bytes.
if (__len1 < __len2)
return __last1;
// Find __f2 the first byte matching in __first1.
__first1 = _Traits::find(__first1, __len1 - __len2 + 1, __f2);
if (__first1 == 0)
return __last1;
// It is faster to compare from the first byte of __first1 even if we
// already know that it matches the first byte of __first2: this is because
// __first2 is most likely aligned, as it is user's "pattern" string, and
// __first1 + 1 is most likely not aligned, as the match is in the middle of
// the string.
if (_Traits::compare(__first1, __first2, __len2) == 0)
return __first1;
++__first1;
}
}
template<class _CharT, class _SizeT, class _Traits, _SizeT __npos>
inline _SizeT _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
__str_find(const _CharT *__p, _SizeT __sz,
const _CharT* __s, _SizeT __pos, _SizeT __n) _NOEXCEPT
{
if (__pos > __sz)
return __npos;
if (__n == 0) // There is nothing to search, just return __pos.
return __pos;
const _CharT *__r = __search_substring<_CharT, _Traits>(
__p + __pos, __p + __sz, __s, __s + __n);
if (__r == __p + __sz)
return __npos;
return static_cast<_SizeT>(__r - __p);
}
// __str_rfind
template<class _CharT, class _SizeT, class _Traits, _SizeT __npos>
inline _SizeT _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
__str_rfind(const _CharT *__p, _SizeT __sz,
_CharT __c, _SizeT __pos) _NOEXCEPT
{
if (__sz < 1)
return __npos;
if (__pos < __sz)
++__pos;
else
__pos = __sz;
for (const _CharT* __ps = __p + __pos; __ps != __p;)
{
if (_Traits::eq(*--__ps, __c))
return static_cast<_SizeT>(__ps - __p);
}
return __npos;
}
template<class _CharT, class _SizeT, class _Traits, _SizeT __npos>
inline _SizeT _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
__str_rfind(const _CharT *__p, _SizeT __sz,
const _CharT* __s, _SizeT __pos, _SizeT __n) _NOEXCEPT
{
__pos = _VSTD::min(__pos, __sz);
if (__n < __sz - __pos)
__pos += __n;
else
__pos = __sz;
const _CharT* __r = _VSTD::__find_end(
__p, __p + __pos, __s, __s + __n, _Traits::eq,
random_access_iterator_tag(), random_access_iterator_tag());
if (__n > 0 && __r == __p + __pos)
return __npos;
return static_cast<_SizeT>(__r - __p);
}
// __str_find_first_of
template<class _CharT, class _SizeT, class _Traits, _SizeT __npos>
inline _SizeT _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
__str_find_first_of(const _CharT *__p, _SizeT __sz,
const _CharT* __s, _SizeT __pos, _SizeT __n) _NOEXCEPT
{
if (__pos >= __sz || __n == 0)
return __npos;
const _CharT* __r = _VSTD::__find_first_of_ce
(__p + __pos, __p + __sz, __s, __s + __n, _Traits::eq );
if (__r == __p + __sz)
return __npos;
return static_cast<_SizeT>(__r - __p);
}
// __str_find_last_of
template<class _CharT, class _SizeT, class _Traits, _SizeT __npos>
inline _SizeT _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
__str_find_last_of(const _CharT *__p, _SizeT __sz,
const _CharT* __s, _SizeT __pos, _SizeT __n) _NOEXCEPT
{
if (__n != 0)
{
if (__pos < __sz)
++__pos;
else
__pos = __sz;
for (const _CharT* __ps = __p + __pos; __ps != __p;)
{
const _CharT* __r = _Traits::find(__s, __n, *--__ps);
if (__r)
return static_cast<_SizeT>(__ps - __p);
}
}
return __npos;
}
// __str_find_first_not_of
template<class _CharT, class _SizeT, class _Traits, _SizeT __npos>
inline _SizeT _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
__str_find_first_not_of(const _CharT *__p, _SizeT __sz,
const _CharT* __s, _SizeT __pos, _SizeT __n) _NOEXCEPT
{
if (__pos < __sz)
{
const _CharT* __pe = __p + __sz;
for (const _CharT* __ps = __p + __pos; __ps != __pe; ++__ps)
if (_Traits::find(__s, __n, *__ps) == 0)
return static_cast<_SizeT>(__ps - __p);
}
return __npos;
}
template<class _CharT, class _SizeT, class _Traits, _SizeT __npos>
inline _SizeT _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
__str_find_first_not_of(const _CharT *__p, _SizeT __sz,
_CharT __c, _SizeT __pos) _NOEXCEPT
{
if (__pos < __sz)
{
const _CharT* __pe = __p + __sz;
for (const _CharT* __ps = __p + __pos; __ps != __pe; ++__ps)
if (!_Traits::eq(*__ps, __c))
return static_cast<_SizeT>(__ps - __p);
}
return __npos;
}
// __str_find_last_not_of
template<class _CharT, class _SizeT, class _Traits, _SizeT __npos>
inline _SizeT _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
__str_find_last_not_of(const _CharT *__p, _SizeT __sz,
const _CharT* __s, _SizeT __pos, _SizeT __n) _NOEXCEPT
{
if (__pos < __sz)
++__pos;
else
__pos = __sz;
for (const _CharT* __ps = __p + __pos; __ps != __p;)
if (_Traits::find(__s, __n, *--__ps) == 0)
return static_cast<_SizeT>(__ps - __p);
return __npos;
}
template<class _CharT, class _SizeT, class _Traits, _SizeT __npos>
inline _SizeT _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
__str_find_last_not_of(const _CharT *__p, _SizeT __sz,
_CharT __c, _SizeT __pos) _NOEXCEPT
{
if (__pos < __sz)
++__pos;
else
__pos = __sz;
for (const _CharT* __ps = __p + __pos; __ps != __p;)
if (!_Traits::eq(*--__ps, __c))
return static_cast<_SizeT>(__ps - __p);
return __npos;
}
template<class _Ptr>
inline _LIBCPP_INLINE_VISIBILITY
size_t __do_string_hash(_Ptr __p, _Ptr __e)
{
typedef typename iterator_traits<_Ptr>::value_type value_type;
return __murmur2_or_cityhash<size_t>()(__p, (__e-__p)*sizeof(value_type));
}
template <class _CharT, class _Iter, class _Traits=char_traits<_CharT> >
struct __quoted_output_proxy
{
_Iter __first;
_Iter __last;
_CharT __delim;
_CharT __escape;
__quoted_output_proxy(_Iter __f, _Iter __l, _CharT __d, _CharT __e)
: __first(__f), __last(__l), __delim(__d), __escape(__e) {}
// This would be a nice place for a string_ref
};
_LIBCPP_END_NAMESPACE_STD
_LIBCPP_POP_MACROS
#endif // _LIBCPP___STRING
| 31,696 | 986 | jart/cosmopolitan | false |
cosmopolitan/third_party/libcxx/charconv | // -*- C++ -*-
//===------------------------------ charconv ------------------------------===//
//
// 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
#define _LIBCPP_CHARCONV
#include "third_party/libcxx/__errc"
#include "third_party/libcxx/type_traits"
#include "third_party/libcxx/limits"
#include "third_party/libcxx/string.h"
#include "libc/literal.h"
#include "third_party/libcxx/math.h"
#include "third_party/libcxx/__debug"
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
#pragma GCC system_header
#endif
_LIBCPP_PUSH_MACROS
#include "third_party/libcxx/__undef_macros"
_LIBCPP_BEGIN_NAMESPACE_STD
/*
charconv synopsis
namespace std {
// floating-point format for primitive numerical conversion
enum class chars_format {
scientific = unspecified,
fixed = unspecified,
hex = unspecified,
general = fixed | scientific
};
// 23.20.2, primitive numerical output conversion
struct to_chars_result {
char* ptr;
errc ec;
};
to_chars_result to_chars(char* first, char* last, see below value,
int base = 10);
to_chars_result to_chars(char* first, char* last, float value);
to_chars_result to_chars(char* first, char* last, double value);
to_chars_result to_chars(char* first, char* last, long double value);
to_chars_result to_chars(char* first, char* last, float value,
chars_format fmt);
to_chars_result to_chars(char* first, char* last, double value,
chars_format fmt);
to_chars_result to_chars(char* first, char* last, long double value,
chars_format fmt);
to_chars_result to_chars(char* first, char* last, float value,
chars_format fmt, int precision);
to_chars_result to_chars(char* first, char* last, double value,
chars_format fmt, int precision);
to_chars_result to_chars(char* first, char* last, long double value,
chars_format fmt, int precision);
// 23.20.3, primitive numerical input conversion
struct from_chars_result {
const char* ptr;
errc ec;
};
from_chars_result from_chars(const char* first, const char* last,
see below& value, int base = 10);
from_chars_result from_chars(const char* first, const char* last,
float& value,
chars_format fmt = chars_format::general);
from_chars_result from_chars(const char* first, const char* last,
double& value,
chars_format fmt = chars_format::general);
from_chars_result from_chars(const char* first, const char* last,
long double& value,
chars_format fmt = chars_format::general);
} // namespace std
*/
namespace __itoa {
_LIBCPP_FUNC_VIS char* __u64toa(uint64_t __value, char* __buffer);
_LIBCPP_FUNC_VIS char* __u32toa(uint32_t __value, char* __buffer);
}
#ifndef _LIBCPP_CXX03_LANG
enum class _LIBCPP_ENUM_VIS chars_format
{
scientific = 0x1,
fixed = 0x2,
hex = 0x4,
general = fixed | scientific
};
struct _LIBCPP_TYPE_VIS to_chars_result
{
char* ptr;
errc ec;
};
struct _LIBCPP_TYPE_VIS from_chars_result
{
const char* ptr;
errc ec;
};
void to_chars(char*, char*, bool, int = 10) = delete;
void from_chars(const char*, const char*, bool, int = 10) = delete;
namespace __itoa
{
static _LIBCPP_CONSTEXPR uint64_t __pow10_64[] = {
UINT64_C(0),
UINT64_C(10),
UINT64_C(100),
UINT64_C(1000),
UINT64_C(10000),
UINT64_C(100000),
UINT64_C(1000000),
UINT64_C(10000000),
UINT64_C(100000000),
UINT64_C(1000000000),
UINT64_C(10000000000),
UINT64_C(100000000000),
UINT64_C(1000000000000),
UINT64_C(10000000000000),
UINT64_C(100000000000000),
UINT64_C(1000000000000000),
UINT64_C(10000000000000000),
UINT64_C(100000000000000000),
UINT64_C(1000000000000000000),
UINT64_C(10000000000000000000),
};
static _LIBCPP_CONSTEXPR uint32_t __pow10_32[] = {
UINT32_C(0), UINT32_C(10), UINT32_C(100),
UINT32_C(1000), UINT32_C(10000), UINT32_C(100000),
UINT32_C(1000000), UINT32_C(10000000), UINT32_C(100000000),
UINT32_C(1000000000),
};
template <typename _Tp, typename = void>
struct _LIBCPP_HIDDEN __traits_base
{
using type = uint64_t;
#if !defined(_LIBCPP_COMPILER_MSVC)
static _LIBCPP_INLINE_VISIBILITY int __width(_Tp __v)
{
auto __t = (64 - __builtin_clzll(__v | 1)) * 1233 >> 12;
return __t - (__v < __pow10_64[__t]) + 1;
}
#endif
static _LIBCPP_INLINE_VISIBILITY char* __convert(_Tp __v, char* __p)
{
return __u64toa(__v, __p);
}
static _LIBCPP_INLINE_VISIBILITY decltype(__pow10_64)& __pow() { return __pow10_64; }
};
template <typename _Tp>
struct _LIBCPP_HIDDEN
__traits_base<_Tp, decltype(void(uint32_t{declval<_Tp>()}))>
{
using type = uint32_t;
#if !defined(_LIBCPP_COMPILER_MSVC)
static _LIBCPP_INLINE_VISIBILITY int __width(_Tp __v)
{
auto __t = (32 - __builtin_clz(__v | 1)) * 1233 >> 12;
return __t - (__v < __pow10_32[__t]) + 1;
}
#endif
static _LIBCPP_INLINE_VISIBILITY char* __convert(_Tp __v, char* __p)
{
return __u32toa(__v, __p);
}
static _LIBCPP_INLINE_VISIBILITY decltype(__pow10_32)& __pow() { return __pow10_32; }
};
template <typename _Tp>
inline _LIBCPP_INLINE_VISIBILITY bool
__mul_overflowed(unsigned char __a, _Tp __b, unsigned char& __r)
{
auto __c = __a * __b;
__r = __c;
return __c > (numeric_limits<unsigned char>::max)();
}
template <typename _Tp>
inline _LIBCPP_INLINE_VISIBILITY bool
__mul_overflowed(unsigned short __a, _Tp __b, unsigned short& __r)
{
auto __c = __a * __b;
__r = __c;
return __c > (numeric_limits<unsigned short>::max)();
}
template <typename _Tp>
inline _LIBCPP_INLINE_VISIBILITY bool
__mul_overflowed(_Tp __a, _Tp __b, _Tp& __r)
{
static_assert(is_unsigned<_Tp>::value, "");
#if !defined(_LIBCPP_COMPILER_MSVC)
return __builtin_mul_overflow(__a, __b, &__r);
#else
bool __did = __b && ((numeric_limits<_Tp>::max)() / __b) < __a;
__r = __a * __b;
return __did;
#endif
}
template <typename _Tp, typename _Up>
inline _LIBCPP_INLINE_VISIBILITY bool
__mul_overflowed(_Tp __a, _Up __b, _Tp& __r)
{
return __mul_overflowed(__a, static_cast<_Tp>(__b), __r);
}
template <typename _Tp>
struct _LIBCPP_HIDDEN __traits : __traits_base<_Tp>
{
static _LIBCPP_CONSTEXPR int digits = numeric_limits<_Tp>::digits10 + 1;
using __traits_base<_Tp>::__pow;
using typename __traits_base<_Tp>::type;
// precondition: at least one non-zero character available
static _LIBCPP_INLINE_VISIBILITY char const*
__read(char const* __p, char const* __ep, type& __a, type& __b)
{
type __cprod[digits];
int __j = digits - 1;
int __i = digits;
do
{
if (!('0' <= *__p && *__p <= '9'))
break;
__cprod[--__i] = *__p++ - '0';
} while (__p != __ep && __i != 0);
__a = __inner_product(__cprod + __i + 1, __cprod + __j, __pow() + 1,
__cprod[__i]);
if (__mul_overflowed(__cprod[__j], __pow()[__j - __i], __b))
--__p;
return __p;
}
template <typename _It1, typename _It2, class _Up>
static _LIBCPP_INLINE_VISIBILITY _Up
__inner_product(_It1 __first1, _It1 __last1, _It2 __first2, _Up __init)
{
for (; __first1 < __last1; ++__first1, ++__first2)
__init = __init + *__first1 * *__first2;
return __init;
}
};
} // namespace __itoa
template <typename _Tp>
inline _LIBCPP_INLINE_VISIBILITY _Tp
__complement(_Tp __x)
{
static_assert(is_unsigned<_Tp>::value, "cast to unsigned first");
return _Tp(~__x + 1);
}
template <typename _Tp>
inline _LIBCPP_INLINE_VISIBILITY typename make_unsigned<_Tp>::type
__to_unsigned(_Tp __x)
{
return static_cast<typename make_unsigned<_Tp>::type>(__x);
}
template <typename _Tp>
inline _LIBCPP_INLINE_VISIBILITY to_chars_result
__to_chars_itoa(char* __first, char* __last, _Tp __value, true_type)
{
auto __x = __to_unsigned(__value);
if (__value < 0 && __first != __last)
{
*__first++ = '-';
__x = __complement(__x);
}
return __to_chars_itoa(__first, __last, __x, false_type());
}
template <typename _Tp>
inline _LIBCPP_INLINE_VISIBILITY to_chars_result
__to_chars_itoa(char* __first, char* __last, _Tp __value, false_type)
{
using __tx = __itoa::__traits<_Tp>;
auto __diff = __last - __first;
#if !defined(_LIBCPP_COMPILER_MSVC)
if (__tx::digits <= __diff || __tx::__width(__value) <= __diff)
return {__tx::__convert(__value, __first), errc(0)};
else
return {__last, errc::value_too_large};
#else
if (__tx::digits <= __diff)
return {__tx::__convert(__value, __first), {}};
else
{
char __buf[__tx::digits];
auto __p = __tx::__convert(__value, __buf);
auto __len = __p - __buf;
if (__len <= __diff)
{
memcpy(__first, __buf, __len);
return {__first + __len, {}};
}
else
return {__last, errc::value_too_large};
}
#endif
}
template <typename _Tp>
inline _LIBCPP_INLINE_VISIBILITY to_chars_result
__to_chars_integral(char* __first, char* __last, _Tp __value, int __base,
true_type)
{
auto __x = __to_unsigned(__value);
if (__value < 0 && __first != __last)
{
*__first++ = '-';
__x = __complement(__x);
}
return __to_chars_integral(__first, __last, __x, __base, false_type());
}
template <typename _Tp>
inline _LIBCPP_INLINE_VISIBILITY to_chars_result
__to_chars_integral(char* __first, char* __last, _Tp __value, int __base,
false_type)
{
if (__base == 10)
return __to_chars_itoa(__first, __last, __value, false_type());
auto __p = __last;
while (__p != __first)
{
auto __c = __value % __base;
__value /= __base;
*--__p = "0123456789abcdefghijklmnopqrstuvwxyz"[__c];
if (__value == 0)
break;
}
auto __len = __last - __p;
if (__value != 0 || !__len)
return {__last, errc::value_too_large};
else
{
memmove(__first, __p, __len);
return {__first + __len, {}};
}
}
template <typename _Tp, typename enable_if<is_integral<_Tp>::value, int>::type = 0>
inline _LIBCPP_INLINE_VISIBILITY to_chars_result
to_chars(char* __first, char* __last, _Tp __value)
{
return __to_chars_itoa(__first, __last, __value, is_signed<_Tp>());
}
template <typename _Tp, typename enable_if<is_integral<_Tp>::value, int>::type = 0>
inline _LIBCPP_INLINE_VISIBILITY to_chars_result
to_chars(char* __first, char* __last, _Tp __value, int __base)
{
_LIBCPP_ASSERT(2 <= __base && __base <= 36, "base not in [2, 36]");
return __to_chars_integral(__first, __last, __value, __base,
is_signed<_Tp>());
}
template <typename _It, typename _Tp, typename _Fn, typename... _Ts>
inline _LIBCPP_INLINE_VISIBILITY from_chars_result
__sign_combinator(_It __first, _It __last, _Tp& __value, _Fn __f, _Ts... __args)
{
using __tl = numeric_limits<_Tp>;
decltype(__to_unsigned(__value)) __x;
bool __neg = (__first != __last && *__first == '-');
auto __r = __f(__neg ? __first + 1 : __first, __last, __x, __args...);
switch (__r.ec)
{
case errc::invalid_argument:
return {__first, __r.ec};
case errc::result_out_of_range:
return __r;
default:
break;
}
if (__neg)
{
if (__x <= __complement(__to_unsigned(__tl::min())))
{
__x = __complement(__x);
memcpy(&__value, &__x, sizeof(__x));
return __r;
}
}
else
{
if (__x <= (__tl::max)())
{
__value = __x;
return __r;
}
}
return {__r.ptr, errc::result_out_of_range};
}
template <typename _Tp>
inline _LIBCPP_INLINE_VISIBILITY bool
__in_pattern(_Tp __c)
{
return '0' <= __c && __c <= '9';
}
struct _LIBCPP_HIDDEN __in_pattern_result
{
bool __ok;
int __val;
explicit _LIBCPP_INLINE_VISIBILITY operator bool() const { return __ok; }
};
template <typename _Tp>
inline _LIBCPP_INLINE_VISIBILITY __in_pattern_result
__in_pattern(_Tp __c, int __base)
{
if (__base <= 10)
return {'0' <= __c && __c < '0' + __base, __c - '0'};
else if (__in_pattern(__c))
return {true, __c - '0'};
else if ('a' <= __c && __c < 'a' + __base - 10)
return {true, __c - 'a' + 10};
else
return {'A' <= __c && __c < 'A' + __base - 10, __c - 'A' + 10};
}
template <typename _It, typename _Tp, typename _Fn, typename... _Ts>
inline _LIBCPP_INLINE_VISIBILITY from_chars_result
__subject_seq_combinator(_It __first, _It __last, _Tp& __value, _Fn __f,
_Ts... __args)
{
auto __find_non_zero = [](_It __first, _It __last) {
for (; __first != __last; ++__first)
if (*__first != '0')
break;
return __first;
};
auto __p = __find_non_zero(__first, __last);
if (__p == __last || !__in_pattern(*__p, __args...))
{
if (__p == __first)
return {__first, errc::invalid_argument};
else
{
__value = 0;
return {__p, {}};
}
}
auto __r = __f(__p, __last, __value, __args...);
if (__r.ec == errc::result_out_of_range)
{
for (; __r.ptr != __last; ++__r.ptr)
{
if (!__in_pattern(*__r.ptr, __args...))
break;
}
}
return __r;
}
template <typename _Tp, typename enable_if<is_unsigned<_Tp>::value, int>::type = 0>
inline _LIBCPP_INLINE_VISIBILITY from_chars_result
__from_chars_atoi(const char* __first, const char* __last, _Tp& __value)
{
using __tx = __itoa::__traits<_Tp>;
using __output_type = typename __tx::type;
return __subject_seq_combinator(
__first, __last, __value,
[](const char* __first, const char* __last,
_Tp& __value) -> from_chars_result {
__output_type __a, __b;
auto __p = __tx::__read(__first, __last, __a, __b);
if (__p == __last || !__in_pattern(*__p))
{
__output_type __m = (numeric_limits<_Tp>::max)();
if (__m >= __a && __m - __a >= __b)
{
__value = __a + __b;
return {__p, {}};
}
}
return {__p, errc::result_out_of_range};
});
}
template <typename _Tp, typename enable_if<is_signed<_Tp>::value, int>::type = 0>
inline _LIBCPP_INLINE_VISIBILITY from_chars_result
__from_chars_atoi(const char* __first, const char* __last, _Tp& __value)
{
using __t = decltype(__to_unsigned(__value));
return __sign_combinator(__first, __last, __value, __from_chars_atoi<__t>);
}
template <typename _Tp, typename enable_if<is_unsigned<_Tp>::value, int>::type = 0>
inline _LIBCPP_INLINE_VISIBILITY from_chars_result
__from_chars_integral(const char* __first, const char* __last, _Tp& __value,
int __base)
{
if (__base == 10)
return __from_chars_atoi(__first, __last, __value);
return __subject_seq_combinator(
__first, __last, __value,
[](const char* __p, const char* __last, _Tp& __value,
int __base) -> from_chars_result {
using __tl = numeric_limits<_Tp>;
auto __digits = __tl::digits / log2f(float(__base));
_Tp __a = __in_pattern(*__p++, __base).__val, __b = 0;
for (int __i = 1; __p != __last; ++__i, ++__p)
{
if (auto __c = __in_pattern(*__p, __base))
{
if (__i < __digits - 1)
__a = __a * __base + __c.__val;
else
{
if (!__itoa::__mul_overflowed(__a, __base, __a))
++__p;
__b = __c.__val;
break;
}
}
else
break;
}
if (__p == __last || !__in_pattern(*__p, __base))
{
if ((__tl::max)() - __a >= __b)
{
__value = __a + __b;
return {__p, {}};
}
}
return {__p, errc::result_out_of_range};
},
__base);
}
template <typename _Tp, typename enable_if<is_signed<_Tp>::value, int>::type = 0>
inline _LIBCPP_INLINE_VISIBILITY from_chars_result
__from_chars_integral(const char* __first, const char* __last, _Tp& __value,
int __base)
{
using __t = decltype(__to_unsigned(__value));
return __sign_combinator(__first, __last, __value,
__from_chars_integral<__t>, __base);
}
template <typename _Tp, typename enable_if<is_integral<_Tp>::value, int>::type = 0>
inline _LIBCPP_INLINE_VISIBILITY from_chars_result
from_chars(const char* __first, const char* __last, _Tp& __value)
{
return __from_chars_atoi(__first, __last, __value);
}
template <typename _Tp, typename enable_if<is_integral<_Tp>::value, int>::type = 0>
inline _LIBCPP_INLINE_VISIBILITY from_chars_result
from_chars(const char* __first, const char* __last, _Tp& __value, int __base)
{
_LIBCPP_ASSERT(2 <= __base && __base <= 36, "base not in [2, 36]");
return __from_chars_integral(__first, __last, __value, __base);
}
#endif // _LIBCPP_CXX03_LANG
_LIBCPP_END_NAMESPACE_STD
_LIBCPP_POP_MACROS
#endif // _LIBCPP_CHARCONV
| 18,176 | 617 | jart/cosmopolitan | false |
cosmopolitan/third_party/libcxx/filesystem | // -*- C++ -*-
// clang-format off
//===--------------------------- filesystem -------------------------------===//
//
// 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
#define _LIBCPP_FILESYSTEM
/*
filesystem synopsis
namespace std { namespace filesystem {
class path;
void swap(path& lhs, path& rhs) noexcept;
size_t hash_value(const path& p) noexcept;
bool operator==(const path& lhs, const path& rhs) noexcept;
bool operator!=(const path& lhs, const path& rhs) noexcept;
bool operator< (const path& lhs, const path& rhs) noexcept;
bool operator<=(const path& lhs, const path& rhs) noexcept;
bool operator> (const path& lhs, const path& rhs) noexcept;
bool operator>=(const path& lhs, const path& rhs) noexcept;
path operator/ (const path& lhs, const path& rhs);
// fs.path.io operators are friends of path.
template <class charT, class traits>
friend basic_ostream<charT, traits>&
operator<<(basic_ostream<charT, traits>& os, const path& p);
template <class charT, class traits>
friend basic_istream<charT, traits>&
operator>>(basic_istream<charT, traits>& is, path& p);
template <class Source>
path u8path(const Source& source);
template <class InputIterator>
path u8path(InputIterator first, InputIterator last);
class filesystem_error;
class directory_entry;
class directory_iterator;
// enable directory_iterator range-based for statements
directory_iterator begin(directory_iterator iter) noexcept;
directory_iterator end(const directory_iterator&) noexcept;
class recursive_directory_iterator;
// enable recursive_directory_iterator range-based for statements
recursive_directory_iterator begin(recursive_directory_iterator iter) noexcept;
recursive_directory_iterator end(const recursive_directory_iterator&) noexcept;
class file_status;
struct space_info
{
uintmax_t capacity;
uintmax_t free;
uintmax_t available;
};
enum class file_type;
enum class perms;
enum class perm_options;
enum class copy_options;
enum class directory_options;
typedef chrono::time_point<trivial-clock> file_time_type;
// operational functions
path absolute(const path& p);
path absolute(const path& p, error_code &ec);
path canonical(const path& p);
path canonical(const path& p, error_code& ec);
void copy(const path& from, const path& to);
void copy(const path& from, const path& to, error_code& ec);
void copy(const path& from, const path& to, copy_options options);
void copy(const path& from, const path& to, copy_options options,
error_code& ec);
bool copy_file(const path& from, const path& to);
bool copy_file(const path& from, const path& to, error_code& ec);
bool copy_file(const path& from, const path& to, copy_options option);
bool copy_file(const path& from, const path& to, copy_options option,
error_code& ec);
void copy_symlink(const path& existing_symlink, const path& new_symlink);
void copy_symlink(const path& existing_symlink, const path& new_symlink,
error_code& ec) noexcept;
bool create_directories(const path& p);
bool create_directories(const path& p, error_code& ec);
bool create_directory(const path& p);
bool create_directory(const path& p, error_code& ec) noexcept;
bool create_directory(const path& p, const path& attributes);
bool create_directory(const path& p, const path& attributes,
error_code& ec) noexcept;
void create_directory_symlink(const path& to, const path& new_symlink);
void create_directory_symlink(const path& to, const path& new_symlink,
error_code& ec) noexcept;
void create_hard_link(const path& to, const path& new_hard_link);
void create_hard_link(const path& to, const path& new_hard_link,
error_code& ec) noexcept;
void create_symlink(const path& to, const path& new_symlink);
void create_symlink(const path& to, const path& new_symlink,
error_code& ec) noexcept;
path current_path();
path current_path(error_code& ec);
void current_path(const path& p);
void current_path(const path& p, error_code& ec) noexcept;
bool exists(file_status s) noexcept;
bool exists(const path& p);
bool exists(const path& p, error_code& ec) noexcept;
bool equivalent(const path& p1, const path& p2);
bool equivalent(const path& p1, const path& p2, error_code& ec) noexcept;
uintmax_t file_size(const path& p);
uintmax_t file_size(const path& p, error_code& ec) noexcept;
uintmax_t hard_link_count(const path& p);
uintmax_t hard_link_count(const path& p, error_code& ec) noexcept;
bool is_block_file(file_status s) noexcept;
bool is_block_file(const path& p);
bool is_block_file(const path& p, error_code& ec) noexcept;
bool is_character_file(file_status s) noexcept;
bool is_character_file(const path& p);
bool is_character_file(const path& p, error_code& ec) noexcept;
bool is_directory(file_status s) noexcept;
bool is_directory(const path& p);
bool is_directory(const path& p, error_code& ec) noexcept;
bool is_empty(const path& p);
bool is_empty(const path& p, error_code& ec) noexcept;
bool is_fifo(file_status s) noexcept;
bool is_fifo(const path& p);
bool is_fifo(const path& p, error_code& ec) noexcept;
bool is_other(file_status s) noexcept;
bool is_other(const path& p);
bool is_other(const path& p, error_code& ec) noexcept;
bool is_regular_file(file_status s) noexcept;
bool is_regular_file(const path& p);
bool is_regular_file(const path& p, error_code& ec) noexcept;
bool is_socket(file_status s) noexcept;
bool is_socket(const path& p);
bool is_socket(const path& p, error_code& ec) noexcept;
bool is_symlink(file_status s) noexcept;
bool is_symlink(const path& p);
bool is_symlink(const path& p, error_code& ec) noexcept;
file_time_type last_write_time(const path& p);
file_time_type last_write_time(const path& p, error_code& ec) noexcept;
void last_write_time(const path& p, file_time_type new_time);
void last_write_time(const path& p, file_time_type new_time,
error_code& ec) noexcept;
void permissions(const path& p, perms prms,
perm_options opts=perm_options::replace);
void permissions(const path& p, perms prms, error_code& ec) noexcept;
void permissions(const path& p, perms prms, perm_options opts,
error_code& ec);
path proximate(const path& p, error_code& ec);
path proximate(const path& p, const path& base = current_path());
path proximate(const path& p, const path& base, error_code &ec);
path read_symlink(const path& p);
path read_symlink(const path& p, error_code& ec);
path relative(const path& p, error_code& ec);
path relative(const path& p, const path& base=current_path());
path relative(const path& p, const path& base, error_code& ec);
bool remove(const path& p);
bool remove(const path& p, error_code& ec) noexcept;
uintmax_t remove_all(const path& p);
uintmax_t remove_all(const path& p, error_code& ec);
void rename(const path& from, const path& to);
void rename(const path& from, const path& to, error_code& ec) noexcept;
void resize_file(const path& p, uintmax_t size);
void resize_file(const path& p, uintmax_t size, error_code& ec) noexcept;
space_info space(const path& p);
space_info space(const path& p, error_code& ec) noexcept;
file_status status(const path& p);
file_status status(const path& p, error_code& ec) noexcept;
bool status_known(file_status s) noexcept;
file_status symlink_status(const path& p);
file_status symlink_status(const path& p, error_code& ec) noexcept;
path temp_directory_path();
path temp_directory_path(error_code& ec);
path weakly_canonical(path const& p);
path weakly_canonical(path const& p, error_code& ec);
} } // namespaces std::filesystem
*/
#include "third_party/libcxx/__config"
#include "third_party/libcxx/cstddef"
#include "third_party/libcxx/cstdlib"
#include "third_party/libcxx/chrono"
#include "third_party/libcxx/iterator"
#include "third_party/libcxx/iosfwd"
#include "third_party/libcxx/locale"
#include "third_party/libcxx/memory"
#include "third_party/libcxx/stack"
#include "third_party/libcxx/string"
#include "third_party/libcxx/system_error"
#include "third_party/libcxx/utility"
#include "third_party/libcxx/iomanip" // for quoted
#include "third_party/libcxx/string_view"
#include "third_party/libcxx/version"
#include "third_party/libcxx/__debug"
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
#pragma GCC system_header
#endif
_LIBCPP_PUSH_MACROS
#include "third_party/libcxx/__undef_macros"
#ifndef _LIBCPP_CXX03_LANG
_LIBCPP_BEGIN_NAMESPACE_FILESYSTEM
_LIBCPP_AVAILABILITY_FILESYSTEM_PUSH
typedef chrono::time_point<_FilesystemClock> file_time_type;
struct _LIBCPP_TYPE_VIS space_info {
uintmax_t capacity;
uintmax_t free;
uintmax_t available;
};
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
};
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; }
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;
}
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;
}
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;
}
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_;
};
class _LIBCPP_TYPE_VIS directory_entry;
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;
};
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) {
return __e == _ECharT('/');
}
struct _NullSentinal {};
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 __sentinal = _ECharT{};
_Iter __e = __b;
for (; *__e != __sentinal; ++__e)
;
return __e;
}
static _ECharT __first_or_null(const _ECharT* __b) { return *__b; }
};
template <class _Iter, bool _IsIt = __is_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 _NullSentinal __range_end(_Iter) { return _NullSentinal{}; }
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> {};
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;
static void __append_range(string& __dest, _ECharT const* __b,
_ECharT const* __e) {
_Narrower()(back_inserter(__dest), __b, __e);
}
template <class _Iter>
static void __append_range(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);
_Narrower()(back_inserter(__dest), __tmp.data(),
__tmp.data() + __tmp.length());
}
template <class _Iter>
static void __append_range(string& __dest, _Iter __b, _NullSentinal) {
static_assert(!is_same<_Iter, _ECharT*>::value, "Call const overload");
const _ECharT __sentinal = _ECharT{};
if (*__b == __sentinal)
return;
basic_string<_ECharT> __tmp;
for (; *__b != __sentinal; ++__b)
__tmp.push_back(*__b);
_Narrower()(back_inserter(__dest), __tmp.data(),
__tmp.data() + __tmp.length());
}
template <class _Source>
static void __append_source(string& __dest, _Source const& __s) {
using _Traits = __is_pathable<_Source>;
__append_range(__dest, _Traits::__range_begin(__s),
_Traits::__range_end(__s));
}
};
template <>
struct _PathCVT<char> {
template <class _Iter>
static typename enable_if<__is_exactly_input_iterator<_Iter>::value>::type
__append_range(string& __dest, _Iter __b, _Iter __e) {
for (; __b != __e; ++__b)
__dest.push_back(*__b);
}
template <class _Iter>
static typename enable_if<__is_forward_iterator<_Iter>::value>::type
__append_range(string& __dest, _Iter __b, _Iter __e) {
__dest.__append_forward_unsafe(__b, __e);
}
template <class _Iter>
static void __append_range(string& __dest, _Iter __b, _NullSentinal) {
const char __sentinal = char{};
for (; *__b != __sentinal; ++__b)
__dest.push_back(*__b);
}
template <class _Source>
static void __append_source(string& __dest, _Source const& __s) {
using _Traits = __is_pathable<_Source>;
__append_range(__dest, _Traits::__range_begin(__s),
_Traits::__range_end(__s));
}
};
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:
typedef char value_type;
typedef basic_string<value_type> string_type;
typedef _VSTD::string_view __string_view;
static constexpr value_type preferred_separator = '/';
enum class _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);
}
// 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);
_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;
}
template <class = void>
_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;
}
private:
template <class _ECharT>
static bool __source_is_absolute(_ECharT __first_or_null) {
return __is_separator(__first_or_null);
}
public:
// appends
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> >;
if (__source_is_absolute(_Traits::__first_or_null(__src)))
__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 && __source_is_absolute(*__first))
__pn_.clear();
else if (has_filename())
__pn_ += preferred_separator;
_CVT::__append_range(__pn_, __first, __last);
return *this;
}
// 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) {
basic_string<_ECharT> __tmp;
__tmp += __x;
_PathCVT<_ECharT>::__append_source(__pn_, __tmp);
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() { 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_; }
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;
}
_LIBCPP_INLINE_VISIBILITY std::string string() const { return __pn_; }
_LIBCPP_INLINE_VISIBILITY std::wstring wstring() const {
return string<wchar_t>();
}
_LIBCPP_INLINE_VISIBILITY std::string u8string() const { return __pn_; }
_LIBCPP_INLINE_VISIBILITY std::u16string u16string() const {
return string<char16_t>();
}
_LIBCPP_INLINE_VISIBILITY std::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 {
return string<_ECharT, _Traits, _Allocator>(__a);
}
std::string generic_string() const { return __pn_; }
std::wstring generic_wstring() const { return string<wchar_t>(); }
std::string generic_u8string() const { return __pn_; }
std::u16string generic_u16string() const { return string<char16_t>(); }
std::u32string generic_u32string() const { return string<char32_t>(); }
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 {
return root_name().append(string_type(__root_directory()));
}
_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 {
return has_root_directory();
}
_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;
template <class _CharT, class _Traits>
_LIBCPP_INLINE_VISIBILITY friend
typename enable_if<is_same<_CharT, char>::value &&
is_same<_Traits, char_traits<char> >::value,
basic_ostream<_CharT, _Traits>&>::type
operator<<(basic_ostream<_CharT, _Traits>& __os, const path& __p) {
__os << std::__quoted(__p.native());
return __os;
}
template <class _CharT, class _Traits>
_LIBCPP_INLINE_VISIBILITY friend
typename enable_if<!is_same<_CharT, char>::value ||
!is_same<_Traits, char_traits<char> >::value,
basic_ostream<_CharT, _Traits>&>::type
operator<<(basic_ostream<_CharT, _Traits>& __os, const path& __p) {
__os << std::__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;
}
friend _LIBCPP_INLINE_VISIBILITY bool operator==(const path& __lhs, const path& __rhs) noexcept {
return __lhs.compare(__rhs) == 0;
}
friend _LIBCPP_INLINE_VISIBILITY bool operator!=(const path& __lhs, const path& __rhs) noexcept {
return __lhs.compare(__rhs) != 0;
}
friend _LIBCPP_INLINE_VISIBILITY bool operator<(const path& __lhs, const path& __rhs) noexcept {
return __lhs.compare(__rhs) < 0;
}
friend _LIBCPP_INLINE_VISIBILITY bool operator<=(const path& __lhs, const path& __rhs) noexcept {
return __lhs.compare(__rhs) <= 0;
}
friend _LIBCPP_INLINE_VISIBILITY bool operator>(const path& __lhs, const path& __rhs) noexcept {
return __lhs.compare(__rhs) > 0;
}
friend _LIBCPP_INLINE_VISIBILITY bool operator>=(const path& __lhs, const path& __rhs) noexcept {
return __lhs.compare(__rhs) >= 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;
template <class _Source>
_LIBCPP_INLINE_VISIBILITY
typename enable_if<__is_pathable<_Source>::value, path>::type
u8path(const _Source& __s) {
static_assert(
is_same<typename __is_pathable<_Source>::__char_type, char>::value,
"u8path(Source const&) requires Source have a character type of type "
"'char'");
return path(__s);
}
template <class _InputIt>
_LIBCPP_INLINE_VISIBILITY
typename enable_if<__is_pathable<_InputIt>::value, path>::type
u8path(_InputIt __f, _InputIt __l) {
static_assert(
is_same<typename __is_pathable<_InputIt>::__char_type, char>::value,
"u8path(Iter, Iter) requires Iter have a value_type of type 'char'");
return path(__f, __l);
}
class _LIBCPP_TYPE_VIS path::iterator {
public:
enum _ParserState : unsigned char {
_Singular,
_BeforeBegin,
_InRootName,
_InRootDir,
_InFilenames,
_InTrailingSep,
_AtEnd
};
public:
typedef bidirectional_iterator_tag iterator_category;
typedef path value_type;
typedef std::ptrdiff_t difference_type;
typedef const path* pointer;
typedef const path& reference;
typedef void
__stashing_iterator_tag; // See reverse_iterator and __is_stashing_iterator
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);
}
// TODO(ldionne): We need to pop the pragma and push it again after
// filesystem_error to work around PR41078.
_LIBCPP_AVAILABILITY_FILESYSTEM_POP
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() 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_;
};
_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(std::forward<_Args>(__args)...);
}
#else
void __throw_filesystem_error(_Args&&...) {
_VSTD::abort();
}
#endif
// operational functions
_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
void __copy(const path& __from, const path& __to, copy_options __opt,
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
bool __create_directories(const path& p, 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_directory_symlink(const path& __to, const path& __new_symlink,
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
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
bool __fs_is_empty(const path& p, 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
void __permissions(const path&, perms, perm_options, error_code* = nullptr);
_LIBCPP_FUNC_VIS
path __read_symlink(const path& p, error_code* ec = nullptr);
_LIBCPP_FUNC_VIS
bool __remove(const path& p, error_code* ec = nullptr);
_LIBCPP_FUNC_VIS
uintmax_t __remove_all(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
space_info __space(const path&, error_code* __ec = nullptr);
_LIBCPP_FUNC_VIS
file_status __status(const path&, error_code* __ec = nullptr);
_LIBCPP_FUNC_VIS
file_status __symlink_status(const path&, error_code* __ec = nullptr);
_LIBCPP_FUNC_VIS
path __system_complete(const path&, error_code* __ec = nullptr);
_LIBCPP_FUNC_VIS
path __temp_directory_path(error_code* __ec = nullptr);
_LIBCPP_FUNC_VIS
path __weakly_canonical(path const& __p, error_code* __ec = nullptr);
inline _LIBCPP_INLINE_VISIBILITY path current_path() {
return __current_path();
}
inline _LIBCPP_INLINE_VISIBILITY path current_path(error_code& __ec) {
return __current_path(&__ec);
}
inline _LIBCPP_INLINE_VISIBILITY void current_path(const path& __p) {
__current_path(__p);
}
inline _LIBCPP_INLINE_VISIBILITY void current_path(const path& __p,
error_code& __ec) noexcept {
__current_path(__p, &__ec);
}
inline _LIBCPP_INLINE_VISIBILITY path absolute(const path& __p) {
return __absolute(__p);
}
inline _LIBCPP_INLINE_VISIBILITY path absolute(const path& __p,
error_code& __ec) {
return __absolute(__p, &__ec);
}
inline _LIBCPP_INLINE_VISIBILITY path canonical(const path& __p) {
return __canonical(__p);
}
inline _LIBCPP_INLINE_VISIBILITY path canonical(const path& __p,
error_code& __ec) {
return __canonical(__p, &__ec);
}
inline _LIBCPP_INLINE_VISIBILITY void copy(const path& __from,
const path& __to) {
__copy(__from, __to, copy_options::none);
}
inline _LIBCPP_INLINE_VISIBILITY void copy(const path& __from, const path& __to,
error_code& __ec) {
__copy(__from, __to, copy_options::none, &__ec);
}
inline _LIBCPP_INLINE_VISIBILITY void copy(const path& __from, const path& __to,
copy_options __opt) {
__copy(__from, __to, __opt);
}
inline _LIBCPP_INLINE_VISIBILITY void copy(const path& __from, const path& __to,
copy_options __opt,
error_code& __ec) {
__copy(__from, __to, __opt, &__ec);
}
inline _LIBCPP_INLINE_VISIBILITY bool copy_file(const path& __from,
const path& __to) {
return __copy_file(__from, __to, copy_options::none);
}
inline _LIBCPP_INLINE_VISIBILITY bool
copy_file(const path& __from, const path& __to, error_code& __ec) {
return __copy_file(__from, __to, copy_options::none, &__ec);
}
inline _LIBCPP_INLINE_VISIBILITY bool
copy_file(const path& __from, const path& __to, copy_options __opt) {
return __copy_file(__from, __to, __opt);
}
inline _LIBCPP_INLINE_VISIBILITY bool copy_file(const path& __from,
const path& __to,
copy_options __opt,
error_code& __ec) {
return __copy_file(__from, __to, __opt, &__ec);
}
inline _LIBCPP_INLINE_VISIBILITY void copy_symlink(const path& __existing,
const path& __new) {
__copy_symlink(__existing, __new);
}
inline _LIBCPP_INLINE_VISIBILITY void
copy_symlink(const path& __ext, const path& __new, error_code& __ec) noexcept {
__copy_symlink(__ext, __new, &__ec);
}
inline _LIBCPP_INLINE_VISIBILITY bool create_directories(const path& __p) {
return __create_directories(__p);
}
inline _LIBCPP_INLINE_VISIBILITY bool create_directories(const path& __p,
error_code& __ec) {
return __create_directories(__p, &__ec);
}
inline _LIBCPP_INLINE_VISIBILITY bool create_directory(const path& __p) {
return __create_directory(__p);
}
inline _LIBCPP_INLINE_VISIBILITY bool
create_directory(const path& __p, error_code& __ec) noexcept {
return __create_directory(__p, &__ec);
}
inline _LIBCPP_INLINE_VISIBILITY bool create_directory(const path& __p,
const path& __attrs) {
return __create_directory(__p, __attrs);
}
inline _LIBCPP_INLINE_VISIBILITY bool
create_directory(const path& __p, const path& __attrs,
error_code& __ec) noexcept {
return __create_directory(__p, __attrs, &__ec);
}
inline _LIBCPP_INLINE_VISIBILITY void
create_directory_symlink(const path& __to, const path& __new) {
__create_directory_symlink(__to, __new);
}
inline _LIBCPP_INLINE_VISIBILITY void
create_directory_symlink(const path& __to, const path& __new,
error_code& __ec) noexcept {
__create_directory_symlink(__to, __new, &__ec);
}
inline _LIBCPP_INLINE_VISIBILITY void create_hard_link(const path& __to,
const path& __new) {
__create_hard_link(__to, __new);
}
inline _LIBCPP_INLINE_VISIBILITY void
create_hard_link(const path& __to, const path& __new,
error_code& __ec) noexcept {
__create_hard_link(__to, __new, &__ec);
}
inline _LIBCPP_INLINE_VISIBILITY void create_symlink(const path& __to,
const path& __new) {
__create_symlink(__to, __new);
}
inline _LIBCPP_INLINE_VISIBILITY void
create_symlink(const path& __to, const path& __new, error_code& __ec) noexcept {
return __create_symlink(__to, __new, &__ec);
}
inline _LIBCPP_INLINE_VISIBILITY bool status_known(file_status __s) noexcept {
return __s.type() != file_type::none;
}
inline _LIBCPP_INLINE_VISIBILITY bool exists(file_status __s) noexcept {
return status_known(__s) && __s.type() != file_type::not_found;
}
inline _LIBCPP_INLINE_VISIBILITY 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_INLINE_VISIBILITY bool equivalent(const path& __p1,
const path& __p2) {
return __equivalent(__p1, __p2);
}
inline _LIBCPP_INLINE_VISIBILITY bool
equivalent(const path& __p1, const path& __p2, error_code& __ec) noexcept {
return __equivalent(__p1, __p2, &__ec);
}
inline _LIBCPP_INLINE_VISIBILITY uintmax_t file_size(const path& __p) {
return __file_size(__p);
}
inline _LIBCPP_INLINE_VISIBILITY uintmax_t
file_size(const path& __p, error_code& __ec) noexcept {
return __file_size(__p, &__ec);
}
inline _LIBCPP_INLINE_VISIBILITY uintmax_t hard_link_count(const path& __p) {
return __hard_link_count(__p);
}
inline _LIBCPP_INLINE_VISIBILITY uintmax_t
hard_link_count(const path& __p, error_code& __ec) noexcept {
return __hard_link_count(__p, &__ec);
}
inline _LIBCPP_INLINE_VISIBILITY bool is_block_file(file_status __s) noexcept {
return __s.type() == file_type::block;
}
inline _LIBCPP_INLINE_VISIBILITY bool is_block_file(const path& __p) {
return is_block_file(__status(__p));
}
inline _LIBCPP_INLINE_VISIBILITY bool is_block_file(const path& __p,
error_code& __ec) noexcept {
return is_block_file(__status(__p, &__ec));
}
inline _LIBCPP_INLINE_VISIBILITY bool
is_character_file(file_status __s) noexcept {
return __s.type() == file_type::character;
}
inline _LIBCPP_INLINE_VISIBILITY bool is_character_file(const path& __p) {
return is_character_file(__status(__p));
}
inline _LIBCPP_INLINE_VISIBILITY bool
is_character_file(const path& __p, error_code& __ec) noexcept {
return is_character_file(__status(__p, &__ec));
}
inline _LIBCPP_INLINE_VISIBILITY bool is_directory(file_status __s) noexcept {
return __s.type() == file_type::directory;
}
inline _LIBCPP_INLINE_VISIBILITY bool is_directory(const path& __p) {
return is_directory(__status(__p));
}
inline _LIBCPP_INLINE_VISIBILITY bool is_directory(const path& __p,
error_code& __ec) noexcept {
return is_directory(__status(__p, &__ec));
}
inline _LIBCPP_INLINE_VISIBILITY bool is_empty(const path& __p) {
return __fs_is_empty(__p);
}
inline _LIBCPP_INLINE_VISIBILITY bool is_empty(const path& __p,
error_code& __ec) {
return __fs_is_empty(__p, &__ec);
}
inline _LIBCPP_INLINE_VISIBILITY bool is_fifo(file_status __s) noexcept {
return __s.type() == file_type::fifo;
}
inline _LIBCPP_INLINE_VISIBILITY bool is_fifo(const path& __p) {
return is_fifo(__status(__p));
}
inline _LIBCPP_INLINE_VISIBILITY bool is_fifo(const path& __p,
error_code& __ec) noexcept {
return is_fifo(__status(__p, &__ec));
}
inline _LIBCPP_INLINE_VISIBILITY bool
is_regular_file(file_status __s) noexcept {
return __s.type() == file_type::regular;
}
inline _LIBCPP_INLINE_VISIBILITY bool is_regular_file(const path& __p) {
return is_regular_file(__status(__p));
}
inline _LIBCPP_INLINE_VISIBILITY bool
is_regular_file(const path& __p, error_code& __ec) noexcept {
return is_regular_file(__status(__p, &__ec));
}
inline _LIBCPP_INLINE_VISIBILITY bool is_socket(file_status __s) noexcept {
return __s.type() == file_type::socket;
}
inline _LIBCPP_INLINE_VISIBILITY bool is_socket(const path& __p) {
return is_socket(__status(__p));
}
inline _LIBCPP_INLINE_VISIBILITY bool is_socket(const path& __p,
error_code& __ec) noexcept {
return is_socket(__status(__p, &__ec));
}
inline _LIBCPP_INLINE_VISIBILITY bool is_symlink(file_status __s) noexcept {
return __s.type() == file_type::symlink;
}
inline _LIBCPP_INLINE_VISIBILITY bool is_symlink(const path& __p) {
return is_symlink(__symlink_status(__p));
}
inline _LIBCPP_INLINE_VISIBILITY bool is_symlink(const path& __p,
error_code& __ec) noexcept {
return is_symlink(__symlink_status(__p, &__ec));
}
inline _LIBCPP_INLINE_VISIBILITY bool is_other(file_status __s) noexcept {
return exists(__s) && !is_regular_file(__s) && !is_directory(__s) &&
!is_symlink(__s);
}
inline _LIBCPP_INLINE_VISIBILITY bool is_other(const path& __p) {
return is_other(__status(__p));
}
inline _LIBCPP_INLINE_VISIBILITY bool is_other(const path& __p,
error_code& __ec) noexcept {
return is_other(__status(__p, &__ec));
}
inline _LIBCPP_INLINE_VISIBILITY file_time_type
last_write_time(const path& __p) {
return __last_write_time(__p);
}
inline _LIBCPP_INLINE_VISIBILITY file_time_type
last_write_time(const path& __p, error_code& __ec) noexcept {
return __last_write_time(__p, &__ec);
}
inline _LIBCPP_INLINE_VISIBILITY void last_write_time(const path& __p,
file_time_type __t) {
__last_write_time(__p, __t);
}
inline _LIBCPP_INLINE_VISIBILITY void
last_write_time(const path& __p, file_time_type __t,
error_code& __ec) noexcept {
__last_write_time(__p, __t, &__ec);
}
inline _LIBCPP_INLINE_VISIBILITY void
permissions(const path& __p, perms __prms,
perm_options __opts = perm_options::replace) {
__permissions(__p, __prms, __opts);
}
inline _LIBCPP_INLINE_VISIBILITY void permissions(const path& __p, perms __prms,
error_code& __ec) noexcept {
__permissions(__p, __prms, perm_options::replace, &__ec);
}
inline _LIBCPP_INLINE_VISIBILITY 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_INLINE_VISIBILITY path proximate(const path& __p,
error_code& __ec) {
return proximate(__p, current_path(), __ec);
}
inline _LIBCPP_INLINE_VISIBILITY path
proximate(const path& __p, const path& __base = current_path()) {
return __weakly_canonical(__p).lexically_proximate(
__weakly_canonical(__base));
}
inline _LIBCPP_INLINE_VISIBILITY path read_symlink(const path& __p) {
return __read_symlink(__p);
}
inline _LIBCPP_INLINE_VISIBILITY 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_INLINE_VISIBILITY path relative(const path& __p,
error_code& __ec) {
return relative(__p, current_path(), __ec);
}
inline _LIBCPP_INLINE_VISIBILITY path
relative(const path& __p, const path& __base = current_path()) {
return __weakly_canonical(__p).lexically_relative(__weakly_canonical(__base));
}
inline _LIBCPP_INLINE_VISIBILITY bool remove(const path& __p) {
return __remove(__p);
}
inline _LIBCPP_INLINE_VISIBILITY bool remove(const path& __p,
error_code& __ec) noexcept {
return __remove(__p, &__ec);
}
inline _LIBCPP_INLINE_VISIBILITY uintmax_t remove_all(const path& __p) {
return __remove_all(__p);
}
inline _LIBCPP_INLINE_VISIBILITY uintmax_t remove_all(const path& __p,
error_code& __ec) {
return __remove_all(__p, &__ec);
}
inline _LIBCPP_INLINE_VISIBILITY void rename(const path& __from,
const path& __to) {
return __rename(__from, __to);
}
inline _LIBCPP_INLINE_VISIBILITY void
rename(const path& __from, const path& __to, error_code& __ec) noexcept {
return __rename(__from, __to, &__ec);
}
inline _LIBCPP_INLINE_VISIBILITY void resize_file(const path& __p,
uintmax_t __ns) {
return __resize_file(__p, __ns);
}
inline _LIBCPP_INLINE_VISIBILITY void
resize_file(const path& __p, uintmax_t __ns, error_code& __ec) noexcept {
return __resize_file(__p, __ns, &__ec);
}
inline _LIBCPP_INLINE_VISIBILITY space_info space(const path& __p) {
return __space(__p);
}
inline _LIBCPP_INLINE_VISIBILITY space_info space(const path& __p,
error_code& __ec) noexcept {
return __space(__p, &__ec);
}
inline _LIBCPP_INLINE_VISIBILITY file_status status(const path& __p) {
return __status(__p);
}
inline _LIBCPP_INLINE_VISIBILITY file_status status(const path& __p,
error_code& __ec) noexcept {
return __status(__p, &__ec);
}
inline _LIBCPP_INLINE_VISIBILITY file_status symlink_status(const path& __p) {
return __symlink_status(__p);
}
inline _LIBCPP_INLINE_VISIBILITY file_status
symlink_status(const path& __p, error_code& __ec) noexcept {
return __symlink_status(__p, &__ec);
}
inline _LIBCPP_INLINE_VISIBILITY path temp_directory_path() {
return __temp_directory_path();
}
inline _LIBCPP_INLINE_VISIBILITY path temp_directory_path(error_code& __ec) {
return __temp_directory_path(&__ec);
}
inline _LIBCPP_INLINE_VISIBILITY path weakly_canonical(path const& __p) {
return __weakly_canonical(__p);
}
inline _LIBCPP_INLINE_VISIBILITY path weakly_canonical(path const& __p,
error_code& __ec) {
return __weakly_canonical(__p, &__ec);
}
class directory_iterator;
class recursive_directory_iterator;
class _LIBCPP_HIDDEN __dir_stream;
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_;
}
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_ = std::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_;
};
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(const directory_iterator&) noexcept {
return directory_iterator();
}
class recursive_directory_iterator {
public:
using value_type = directory_entry;
using difference_type = std::ptrdiff_t;
using pointer = directory_entry const*;
using reference = directory_entry const&;
using iterator_category = std::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(const recursive_directory_iterator&) noexcept {
return recursive_directory_iterator();
}
_LIBCPP_AVAILABILITY_FILESYSTEM_POP
_LIBCPP_END_NAMESPACE_FILESYSTEM
#endif // !_LIBCPP_CXX03_LANG
_LIBCPP_POP_MACROS
#endif // _LIBCPP_FILESYSTEM
| 82,369 | 2,646 | jart/cosmopolitan | false |
cosmopolitan/third_party/libcxx/__locale | // -*- 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___LOCALE
#define _LIBCPP___LOCALE
#include "third_party/libcxx/__config"
#include "third_party/libcxx/string"
#include "third_party/libcxx/memory"
#include "third_party/libcxx/utility"
#include "third_party/libcxx/mutex"
#include "third_party/libcxx/cstdint"
#include "third_party/libcxx/cctype"
#include "third_party/libcxx/locale.h"
#if defined(_LIBCPP_MSVCRT_LIKE)
# include "third_party/libcxx/cstring"
# include "third_party/libcxx/support/win32/locale_win32.h"
#elif defined(_AIX)
# include "third_party/libcxx/support/ibm/xlocale.h"
#elif defined(__ANDROID__)
# include "third_party/libcxx/support/android/locale_bionic.h"
#elif defined(__sun__)
# include "third_party/libcxx/xlocale.h"
# include "third_party/libcxx/support/solaris/xlocale.h"
#elif defined(_NEWLIB_VERSION)
# include "third_party/libcxx/support/newlib/xlocale.h"
#elif (defined(__APPLE__) || defined(__FreeBSD__) \
|| defined(__EMSCRIPTEN__) || defined(__IBMCPP__))
# include "third_party/libcxx/xlocale.h"
#elif defined(__Fuchsia__)
# include "third_party/libcxx/support/fuchsia/xlocale.h"
#elif defined(__wasi__)
// WASI libc uses musl's locales support.
# include "third_party/libcxx/support/musl/xlocale.h"
#elif defined(_LIBCPP_HAS_MUSL_LIBC)
# include "third_party/libcxx/support/musl/xlocale.h"
#endif
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
#pragma GCC system_header
#endif
_LIBCPP_BEGIN_NAMESPACE_STD
#if !defined(_LIBCPP_LOCALE__L_EXTENSIONS)
struct __libcpp_locale_guard {
_LIBCPP_INLINE_VISIBILITY
__libcpp_locale_guard(locale_t& __loc) : __old_loc_(uselocale(__loc)) {}
_LIBCPP_INLINE_VISIBILITY
~__libcpp_locale_guard() {
if (__old_loc_)
uselocale(__old_loc_);
}
locale_t __old_loc_;
private:
__libcpp_locale_guard(__libcpp_locale_guard const&);
__libcpp_locale_guard& operator=(__libcpp_locale_guard const&);
};
#elif defined(_LIBCPP_MSVCRT_LIKE)
struct __libcpp_locale_guard {
__libcpp_locale_guard(locale_t __l) :
__status(_configthreadlocale(_ENABLE_PER_THREAD_LOCALE)) {
// Setting the locale can be expensive even when the locale given is
// already the current locale, so do an explicit check to see if the
// current locale is already the one we want.
const char* __lc = __setlocale(nullptr);
// If every category is the same, the locale string will simply be the
// locale name, otherwise it will be a semicolon-separated string listing
// each category. In the second case, we know at least one category won't
// be what we want, so we only have to check the first case.
if (strcmp(__l.__get_locale(), __lc) != 0) {
__locale_all = _strdup(__lc);
if (__locale_all == nullptr)
__throw_bad_alloc();
__setlocale(__l.__get_locale());
}
}
~__libcpp_locale_guard() {
// The CRT documentation doesn't explicitly say, but setlocale() does the
// right thing when given a semicolon-separated list of locale settings
// for the different categories in the same format as returned by
// setlocale(LC_ALL, nullptr).
if (__locale_all != nullptr) {
__setlocale(__locale_all);
free(__locale_all);
}
_configthreadlocale(__status);
}
static const char* __setlocale(const char* __locale) {
const char* __new_locale = setlocale(LC_ALL, __locale);
if (__new_locale == nullptr)
__throw_bad_alloc();
return __new_locale;
}
int __status;
char* __locale_all = nullptr;
};
#endif
class _LIBCPP_TYPE_VIS locale;
template <class _Facet>
_LIBCPP_INLINE_VISIBILITY
bool
has_facet(const locale&) _NOEXCEPT;
template <class _Facet>
_LIBCPP_INLINE_VISIBILITY
const _Facet&
use_facet(const locale&);
class _LIBCPP_TYPE_VIS locale
{
public:
// types:
class _LIBCPP_TYPE_VIS facet;
class _LIBCPP_TYPE_VIS id;
typedef int category;
_LIBCPP_AVAILABILITY_LOCALE_CATEGORY
static const category // values assigned here are for exposition only
none = 0,
collate = LC_COLLATE_MASK,
ctype = LC_CTYPE_MASK,
monetary = LC_MONETARY_MASK,
numeric = LC_NUMERIC_MASK,
time = LC_TIME_MASK,
messages = LC_MESSAGES_MASK,
all = collate | ctype | monetary | numeric | time | messages;
// construct/copy/destroy:
locale() _NOEXCEPT;
locale(const locale&) _NOEXCEPT;
explicit locale(const char*);
explicit locale(const string&);
locale(const locale&, const char*, category);
locale(const locale&, const string&, category);
template <class _Facet>
_LIBCPP_INLINE_VISIBILITY locale(const locale&, _Facet*);
locale(const locale&, const locale&, category);
~locale();
const locale& operator=(const locale&) _NOEXCEPT;
template <class _Facet>
_LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
locale combine(const locale&) const;
// locale operations:
string name() const;
bool operator==(const locale&) const;
bool operator!=(const locale& __y) const {return !(*this == __y);}
template <class _CharT, class _Traits, class _Allocator>
_LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
bool operator()(const basic_string<_CharT, _Traits, _Allocator>&,
const basic_string<_CharT, _Traits, _Allocator>&) const;
// global locale objects:
static locale global(const locale&);
static const locale& classic();
private:
class __imp;
__imp* __locale_;
void __install_ctor(const locale&, facet*, long);
static locale& __global();
bool has_facet(id&) const;
const facet* use_facet(id&) const;
template <class _Facet> friend bool has_facet(const locale&) _NOEXCEPT;
template <class _Facet> friend const _Facet& use_facet(const locale&);
};
class _LIBCPP_TYPE_VIS locale::facet
: public __shared_count
{
protected:
_LIBCPP_INLINE_VISIBILITY
explicit facet(size_t __refs = 0)
: __shared_count(static_cast<long>(__refs)-1) {}
virtual ~facet();
// facet(const facet&) = delete; // effectively done in __shared_count
// void operator=(const facet&) = delete;
private:
virtual void __on_zero_shared() _NOEXCEPT;
};
class _LIBCPP_TYPE_VIS locale::id
{
once_flag __flag_;
int32_t __id_;
static int32_t __next_id;
public:
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR id() :__id_(0) {}
private:
void __init();
void operator=(const id&); // = delete;
id(const id&); // = delete;
public: // only needed for tests
long __get();
friend class locale;
friend class locale::__imp;
};
template <class _Facet>
inline _LIBCPP_INLINE_VISIBILITY
locale::locale(const locale& __other, _Facet* __f)
{
__install_ctor(__other, __f, __f ? __f->id.__get() : 0);
}
template <class _Facet>
locale
locale::combine(const locale& __other) const
{
if (!_VSTD::has_facet<_Facet>(__other))
__throw_runtime_error("locale::combine: locale missing facet");
return locale(*this, &const_cast<_Facet&>(_VSTD::use_facet<_Facet>(__other)));
}
template <class _Facet>
inline _LIBCPP_INLINE_VISIBILITY
bool
has_facet(const locale& __l) _NOEXCEPT
{
return __l.has_facet(_Facet::id);
}
template <class _Facet>
inline _LIBCPP_INLINE_VISIBILITY
const _Facet&
use_facet(const locale& __l)
{
return static_cast<const _Facet&>(*__l.use_facet(_Facet::id));
}
// template <class _CharT> class collate;
template <class _CharT>
class _LIBCPP_TEMPLATE_VIS collate
: public locale::facet
{
public:
typedef _CharT char_type;
typedef basic_string<char_type> string_type;
_LIBCPP_INLINE_VISIBILITY
explicit collate(size_t __refs = 0)
: locale::facet(__refs) {}
_LIBCPP_INLINE_VISIBILITY
int compare(const char_type* __lo1, const char_type* __hi1,
const char_type* __lo2, const char_type* __hi2) const
{
return do_compare(__lo1, __hi1, __lo2, __hi2);
}
// FIXME(EricWF): The _LIBCPP_ALWAYS_INLINE is needed on Windows to work
// around a dllimport bug that expects an external instantiation.
_LIBCPP_INLINE_VISIBILITY
_LIBCPP_ALWAYS_INLINE
string_type transform(const char_type* __lo, const char_type* __hi) const
{
return do_transform(__lo, __hi);
}
_LIBCPP_INLINE_VISIBILITY
long hash(const char_type* __lo, const char_type* __hi) const
{
return do_hash(__lo, __hi);
}
static locale::id id;
protected:
~collate();
virtual int do_compare(const char_type* __lo1, const char_type* __hi1,
const char_type* __lo2, const char_type* __hi2) const;
virtual string_type do_transform(const char_type* __lo, const char_type* __hi) const
{return string_type(__lo, __hi);}
virtual long do_hash(const char_type* __lo, const char_type* __hi) const;
};
template <class _CharT> locale::id collate<_CharT>::id;
template <class _CharT>
collate<_CharT>::~collate()
{
}
template <class _CharT>
int
collate<_CharT>::do_compare(const char_type* __lo1, const char_type* __hi1,
const char_type* __lo2, const char_type* __hi2) const
{
for (; __lo2 != __hi2; ++__lo1, ++__lo2)
{
if (__lo1 == __hi1 || *__lo1 < *__lo2)
return -1;
if (*__lo2 < *__lo1)
return 1;
}
return __lo1 != __hi1;
}
template <class _CharT>
long
collate<_CharT>::do_hash(const char_type* __lo, const char_type* __hi) const
{
size_t __h = 0;
const size_t __sr = __CHAR_BIT__ * sizeof(size_t) - 8;
const size_t __mask = size_t(0xF) << (__sr + 4);
for(const char_type* __p = __lo; __p != __hi; ++__p)
{
__h = (__h << 4) + static_cast<size_t>(*__p);
size_t __g = __h & __mask;
__h ^= __g | (__g >> __sr);
}
return static_cast<long>(__h);
}
_LIBCPP_EXTERN_TEMPLATE2(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS collate<char>)
_LIBCPP_EXTERN_TEMPLATE2(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS collate<wchar_t>)
// template <class CharT> class collate_byname;
template <class _CharT> class _LIBCPP_TEMPLATE_VIS collate_byname;
template <>
class _LIBCPP_TYPE_VIS collate_byname<char>
: public collate<char>
{
locale_t __l;
public:
typedef char char_type;
typedef basic_string<char_type> string_type;
explicit collate_byname(const char* __n, size_t __refs = 0);
explicit collate_byname(const string& __n, size_t __refs = 0);
protected:
~collate_byname();
virtual int do_compare(const char_type* __lo1, const char_type* __hi1,
const char_type* __lo2, const char_type* __hi2) const;
virtual string_type do_transform(const char_type* __lo, const char_type* __hi) const;
};
template <>
class _LIBCPP_TYPE_VIS collate_byname<wchar_t>
: public collate<wchar_t>
{
locale_t __l;
public:
typedef wchar_t char_type;
typedef basic_string<char_type> string_type;
explicit collate_byname(const char* __n, size_t __refs = 0);
explicit collate_byname(const string& __n, size_t __refs = 0);
protected:
~collate_byname();
virtual int do_compare(const char_type* __lo1, const char_type* __hi1,
const char_type* __lo2, const char_type* __hi2) const;
virtual string_type do_transform(const char_type* __lo, const char_type* __hi) const;
};
template <class _CharT, class _Traits, class _Allocator>
bool
locale::operator()(const basic_string<_CharT, _Traits, _Allocator>& __x,
const basic_string<_CharT, _Traits, _Allocator>& __y) const
{
return _VSTD::use_facet<_VSTD::collate<_CharT> >(*this).compare(
__x.data(), __x.data() + __x.size(),
__y.data(), __y.data() + __y.size()) < 0;
}
// template <class charT> class ctype
class _LIBCPP_TYPE_VIS ctype_base
{
public:
#if defined(__GLIBC__)
typedef unsigned short mask;
static const mask space = _ISspace;
static const mask print = _ISprint;
static const mask cntrl = _IScntrl;
static const mask upper = _ISupper;
static const mask lower = _ISlower;
static const mask alpha = _ISalpha;
static const mask digit = _ISdigit;
static const mask punct = _ISpunct;
static const mask xdigit = _ISxdigit;
static const mask blank = _ISblank;
#if defined(__mips__)
static const mask __regex_word = static_cast<mask>(_ISbit(15));
#else
static const mask __regex_word = 0x80;
#endif
#elif defined(_LIBCPP_MSVCRT_LIKE)
typedef unsigned short mask;
static const mask space = _SPACE;
static const mask print = _BLANK|_PUNCT|_ALPHA|_DIGIT;
static const mask cntrl = _CONTROL;
static const mask upper = _UPPER;
static const mask lower = _LOWER;
static const mask alpha = _ALPHA;
static const mask digit = _DIGIT;
static const mask punct = _PUNCT;
static const mask xdigit = _HEX;
static const mask blank = _BLANK;
static const mask __regex_word = 0x80;
# define _LIBCPP_CTYPE_MASK_IS_COMPOSITE_PRINT
#elif defined(__APPLE__) || defined(__FreeBSD__) || defined(__EMSCRIPTEN__) || defined(__NetBSD__)
# ifdef __APPLE__
typedef __uint32_t mask;
# elif defined(__FreeBSD__)
typedef unsigned long mask;
# elif defined(__EMSCRIPTEN__) || defined(__NetBSD__)
typedef unsigned short mask;
# endif
static const mask space = _CTYPE_S;
static const mask print = _CTYPE_R;
static const mask cntrl = _CTYPE_C;
static const mask upper = _CTYPE_U;
static const mask lower = _CTYPE_L;
static const mask alpha = _CTYPE_A;
static const mask digit = _CTYPE_D;
static const mask punct = _CTYPE_P;
static const mask xdigit = _CTYPE_X;
# if defined(__NetBSD__)
static const mask blank = _CTYPE_BL;
// NetBSD defines classes up to 0x2000
// see sys/ctype_bits.h, _CTYPE_Q
static const mask __regex_word = 0x8000;
# else
static const mask blank = _CTYPE_B;
static const mask __regex_word = 0x80;
# endif
#elif defined(__sun__) || defined(_AIX)
typedef unsigned int mask;
static const mask space = _ISSPACE;
static const mask print = _ISPRINT;
static const mask cntrl = _ISCNTRL;
static const mask upper = _ISUPPER;
static const mask lower = _ISLOWER;
static const mask alpha = _ISALPHA;
static const mask digit = _ISDIGIT;
static const mask punct = _ISPUNCT;
static const mask xdigit = _ISXDIGIT;
static const mask blank = _ISBLANK;
static const mask __regex_word = 0x80;
#elif defined(_NEWLIB_VERSION)
// Same type as Newlib's _ctype_ array in newlib/libc/include/ctype.h.
typedef char mask;
static const mask space = _S;
static const mask print = _P | _U | _L | _N | _B;
static const mask cntrl = _C;
static const mask upper = _U;
static const mask lower = _L;
static const mask alpha = _U | _L;
static const mask digit = _N;
static const mask punct = _P;
static const mask xdigit = _X | _N;
static const mask blank = _B;
static const mask __regex_word = 0x80;
# define _LIBCPP_CTYPE_MASK_IS_COMPOSITE_PRINT
# define _LIBCPP_CTYPE_MASK_IS_COMPOSITE_ALPHA
# define _LIBCPP_CTYPE_MASK_IS_COMPOSITE_XDIGIT
#else
typedef unsigned long mask;
static const mask space = 1<<0;
static const mask print = 1<<1;
static const mask cntrl = 1<<2;
static const mask upper = 1<<3;
static const mask lower = 1<<4;
static const mask alpha = 1<<5;
static const mask digit = 1<<6;
static const mask punct = 1<<7;
static const mask xdigit = 1<<8;
static const mask blank = 1<<9;
static const mask __regex_word = 1<<10;
#endif
static const mask alnum = alpha | digit;
static const mask graph = alnum | punct;
_LIBCPP_INLINE_VISIBILITY ctype_base() {}
};
template <class _CharT> class _LIBCPP_TEMPLATE_VIS ctype;
template <>
class _LIBCPP_TYPE_VIS ctype<wchar_t>
: public locale::facet,
public ctype_base
{
public:
typedef wchar_t char_type;
_LIBCPP_INLINE_VISIBILITY
explicit ctype(size_t __refs = 0)
: locale::facet(__refs) {}
_LIBCPP_INLINE_VISIBILITY
bool is(mask __m, char_type __c) const
{
return do_is(__m, __c);
}
_LIBCPP_INLINE_VISIBILITY
const char_type* is(const char_type* __low, const char_type* __high, mask* __vec) const
{
return do_is(__low, __high, __vec);
}
_LIBCPP_INLINE_VISIBILITY
const char_type* scan_is(mask __m, const char_type* __low, const char_type* __high) const
{
return do_scan_is(__m, __low, __high);
}
_LIBCPP_INLINE_VISIBILITY
const char_type* scan_not(mask __m, const char_type* __low, const char_type* __high) const
{
return do_scan_not(__m, __low, __high);
}
_LIBCPP_INLINE_VISIBILITY
char_type toupper(char_type __c) const
{
return do_toupper(__c);
}
_LIBCPP_INLINE_VISIBILITY
const char_type* toupper(char_type* __low, const char_type* __high) const
{
return do_toupper(__low, __high);
}
_LIBCPP_INLINE_VISIBILITY
char_type tolower(char_type __c) const
{
return do_tolower(__c);
}
_LIBCPP_INLINE_VISIBILITY
const char_type* tolower(char_type* __low, const char_type* __high) const
{
return do_tolower(__low, __high);
}
_LIBCPP_INLINE_VISIBILITY
char_type widen(char __c) const
{
return do_widen(__c);
}
_LIBCPP_INLINE_VISIBILITY
const char* widen(const char* __low, const char* __high, char_type* __to) const
{
return do_widen(__low, __high, __to);
}
_LIBCPP_INLINE_VISIBILITY
char narrow(char_type __c, char __dfault) const
{
return do_narrow(__c, __dfault);
}
_LIBCPP_INLINE_VISIBILITY
const char_type* narrow(const char_type* __low, const char_type* __high, char __dfault, char* __to) const
{
return do_narrow(__low, __high, __dfault, __to);
}
static locale::id id;
protected:
~ctype();
virtual bool do_is(mask __m, char_type __c) const;
virtual const char_type* do_is(const char_type* __low, const char_type* __high, mask* __vec) const;
virtual const char_type* do_scan_is(mask __m, const char_type* __low, const char_type* __high) const;
virtual const char_type* do_scan_not(mask __m, const char_type* __low, const char_type* __high) const;
virtual char_type do_toupper(char_type) const;
virtual const char_type* do_toupper(char_type* __low, const char_type* __high) const;
virtual char_type do_tolower(char_type) const;
virtual const char_type* do_tolower(char_type* __low, const char_type* __high) const;
virtual char_type do_widen(char) const;
virtual const char* do_widen(const char* __low, const char* __high, char_type* __dest) const;
virtual char do_narrow(char_type, char __dfault) const;
virtual const char_type* do_narrow(const char_type* __low, const char_type* __high, char __dfault, char* __dest) const;
};
template <>
class _LIBCPP_TYPE_VIS ctype<char>
: public locale::facet, public ctype_base
{
const mask* __tab_;
bool __del_;
public:
typedef char char_type;
explicit ctype(const mask* __tab = 0, bool __del = false, size_t __refs = 0);
_LIBCPP_INLINE_VISIBILITY
bool is(mask __m, char_type __c) const
{
return isascii(__c) ? (__tab_[static_cast<int>(__c)] & __m) !=0 : false;
}
_LIBCPP_INLINE_VISIBILITY
const char_type* is(const char_type* __low, const char_type* __high, mask* __vec) const
{
for (; __low != __high; ++__low, ++__vec)
*__vec = isascii(*__low) ? __tab_[static_cast<int>(*__low)] : 0;
return __low;
}
_LIBCPP_INLINE_VISIBILITY
const char_type* scan_is (mask __m, const char_type* __low, const char_type* __high) const
{
for (; __low != __high; ++__low)
if (isascii(*__low) && (__tab_[static_cast<int>(*__low)] & __m))
break;
return __low;
}
_LIBCPP_INLINE_VISIBILITY
const char_type* scan_not(mask __m, const char_type* __low, const char_type* __high) const
{
for (; __low != __high; ++__low)
if (!(isascii(*__low) && (__tab_[static_cast<int>(*__low)] & __m)))
break;
return __low;
}
_LIBCPP_INLINE_VISIBILITY
char_type toupper(char_type __c) const
{
return do_toupper(__c);
}
_LIBCPP_INLINE_VISIBILITY
const char_type* toupper(char_type* __low, const char_type* __high) const
{
return do_toupper(__low, __high);
}
_LIBCPP_INLINE_VISIBILITY
char_type tolower(char_type __c) const
{
return do_tolower(__c);
}
_LIBCPP_INLINE_VISIBILITY
const char_type* tolower(char_type* __low, const char_type* __high) const
{
return do_tolower(__low, __high);
}
_LIBCPP_INLINE_VISIBILITY
char_type widen(char __c) const
{
return do_widen(__c);
}
_LIBCPP_INLINE_VISIBILITY
const char* widen(const char* __low, const char* __high, char_type* __to) const
{
return do_widen(__low, __high, __to);
}
_LIBCPP_INLINE_VISIBILITY
char narrow(char_type __c, char __dfault) const
{
return do_narrow(__c, __dfault);
}
_LIBCPP_INLINE_VISIBILITY
const char* narrow(const char_type* __low, const char_type* __high, char __dfault, char* __to) const
{
return do_narrow(__low, __high, __dfault, __to);
}
static locale::id id;
#ifdef _CACHED_RUNES
static const size_t table_size = _CACHED_RUNES;
#else
static const size_t table_size = 256; // FIXME: Don't hardcode this.
#endif
_LIBCPP_INLINE_VISIBILITY const mask* table() const _NOEXCEPT {return __tab_;}
static const mask* classic_table() _NOEXCEPT;
#if defined(__GLIBC__) || defined(__EMSCRIPTEN__)
static const int* __classic_upper_table() _NOEXCEPT;
static const int* __classic_lower_table() _NOEXCEPT;
#endif
#if defined(__NetBSD__)
static const short* __classic_upper_table() _NOEXCEPT;
static const short* __classic_lower_table() _NOEXCEPT;
#endif
protected:
~ctype();
virtual char_type do_toupper(char_type __c) const;
virtual const char_type* do_toupper(char_type* __low, const char_type* __high) const;
virtual char_type do_tolower(char_type __c) const;
virtual const char_type* do_tolower(char_type* __low, const char_type* __high) const;
virtual char_type do_widen(char __c) const;
virtual const char* do_widen(const char* __low, const char* __high, char_type* __to) const;
virtual char do_narrow(char_type __c, char __dfault) const;
virtual const char* do_narrow(const char_type* __low, const char_type* __high, char __dfault, char* __to) const;
};
// template <class CharT> class ctype_byname;
template <class _CharT> class _LIBCPP_TEMPLATE_VIS ctype_byname;
template <>
class _LIBCPP_TYPE_VIS ctype_byname<char>
: public ctype<char>
{
locale_t __l;
public:
explicit ctype_byname(const char*, size_t = 0);
explicit ctype_byname(const string&, size_t = 0);
protected:
~ctype_byname();
virtual char_type do_toupper(char_type) const;
virtual const char_type* do_toupper(char_type* __low, const char_type* __high) const;
virtual char_type do_tolower(char_type) const;
virtual const char_type* do_tolower(char_type* __low, const char_type* __high) const;
};
template <>
class _LIBCPP_TYPE_VIS ctype_byname<wchar_t>
: public ctype<wchar_t>
{
locale_t __l;
public:
explicit ctype_byname(const char*, size_t = 0);
explicit ctype_byname(const string&, size_t = 0);
protected:
~ctype_byname();
virtual bool do_is(mask __m, char_type __c) const;
virtual const char_type* do_is(const char_type* __low, const char_type* __high, mask* __vec) const;
virtual const char_type* do_scan_is(mask __m, const char_type* __low, const char_type* __high) const;
virtual const char_type* do_scan_not(mask __m, const char_type* __low, const char_type* __high) const;
virtual char_type do_toupper(char_type) const;
virtual const char_type* do_toupper(char_type* __low, const char_type* __high) const;
virtual char_type do_tolower(char_type) const;
virtual const char_type* do_tolower(char_type* __low, const char_type* __high) const;
virtual char_type do_widen(char) const;
virtual const char* do_widen(const char* __low, const char* __high, char_type* __dest) const;
virtual char do_narrow(char_type, char __dfault) const;
virtual const char_type* do_narrow(const char_type* __low, const char_type* __high, char __dfault, char* __dest) const;
};
template <class _CharT>
inline _LIBCPP_INLINE_VISIBILITY
bool
isspace(_CharT __c, const locale& __loc)
{
return use_facet<ctype<_CharT> >(__loc).is(ctype_base::space, __c);
}
template <class _CharT>
inline _LIBCPP_INLINE_VISIBILITY
bool
isprint(_CharT __c, const locale& __loc)
{
return use_facet<ctype<_CharT> >(__loc).is(ctype_base::print, __c);
}
template <class _CharT>
inline _LIBCPP_INLINE_VISIBILITY
bool
iscntrl(_CharT __c, const locale& __loc)
{
return use_facet<ctype<_CharT> >(__loc).is(ctype_base::cntrl, __c);
}
template <class _CharT>
inline _LIBCPP_INLINE_VISIBILITY
bool
isupper(_CharT __c, const locale& __loc)
{
return use_facet<ctype<_CharT> >(__loc).is(ctype_base::upper, __c);
}
template <class _CharT>
inline _LIBCPP_INLINE_VISIBILITY
bool
islower(_CharT __c, const locale& __loc)
{
return use_facet<ctype<_CharT> >(__loc).is(ctype_base::lower, __c);
}
template <class _CharT>
inline _LIBCPP_INLINE_VISIBILITY
bool
isalpha(_CharT __c, const locale& __loc)
{
return use_facet<ctype<_CharT> >(__loc).is(ctype_base::alpha, __c);
}
template <class _CharT>
inline _LIBCPP_INLINE_VISIBILITY
bool
isdigit(_CharT __c, const locale& __loc)
{
return use_facet<ctype<_CharT> >(__loc).is(ctype_base::digit, __c);
}
template <class _CharT>
inline _LIBCPP_INLINE_VISIBILITY
bool
ispunct(_CharT __c, const locale& __loc)
{
return use_facet<ctype<_CharT> >(__loc).is(ctype_base::punct, __c);
}
template <class _CharT>
inline _LIBCPP_INLINE_VISIBILITY
bool
isxdigit(_CharT __c, const locale& __loc)
{
return use_facet<ctype<_CharT> >(__loc).is(ctype_base::xdigit, __c);
}
template <class _CharT>
inline _LIBCPP_INLINE_VISIBILITY
bool
isalnum(_CharT __c, const locale& __loc)
{
return use_facet<ctype<_CharT> >(__loc).is(ctype_base::alnum, __c);
}
template <class _CharT>
inline _LIBCPP_INLINE_VISIBILITY
bool
isgraph(_CharT __c, const locale& __loc)
{
return use_facet<ctype<_CharT> >(__loc).is(ctype_base::graph, __c);
}
template <class _CharT>
inline _LIBCPP_INLINE_VISIBILITY
_CharT
toupper(_CharT __c, const locale& __loc)
{
return use_facet<ctype<_CharT> >(__loc).toupper(__c);
}
template <class _CharT>
inline _LIBCPP_INLINE_VISIBILITY
_CharT
tolower(_CharT __c, const locale& __loc)
{
return use_facet<ctype<_CharT> >(__loc).tolower(__c);
}
// codecvt_base
class _LIBCPP_TYPE_VIS codecvt_base
{
public:
_LIBCPP_INLINE_VISIBILITY codecvt_base() {}
enum result {ok, partial, error, noconv};
};
// template <class internT, class externT, class stateT> class codecvt;
template <class _InternT, class _ExternT, class _StateT> class _LIBCPP_TEMPLATE_VIS codecvt;
// template <> class codecvt<char, char, mbstate_t>
template <>
class _LIBCPP_TYPE_VIS codecvt<char, char, mbstate_t>
: public locale::facet,
public codecvt_base
{
public:
typedef char intern_type;
typedef char extern_type;
typedef mbstate_t state_type;
_LIBCPP_INLINE_VISIBILITY
explicit codecvt(size_t __refs = 0)
: locale::facet(__refs) {}
_LIBCPP_INLINE_VISIBILITY
result out(state_type& __st,
const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt,
extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const
{
return do_out(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt);
}
_LIBCPP_INLINE_VISIBILITY
result unshift(state_type& __st,
extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const
{
return do_unshift(__st, __to, __to_end, __to_nxt);
}
_LIBCPP_INLINE_VISIBILITY
result in(state_type& __st,
const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt,
intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const
{
return do_in(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt);
}
_LIBCPP_INLINE_VISIBILITY
int encoding() const _NOEXCEPT
{
return do_encoding();
}
_LIBCPP_INLINE_VISIBILITY
bool always_noconv() const _NOEXCEPT
{
return do_always_noconv();
}
_LIBCPP_INLINE_VISIBILITY
int length(state_type& __st, const extern_type* __frm, const extern_type* __end, size_t __mx) const
{
return do_length(__st, __frm, __end, __mx);
}
_LIBCPP_INLINE_VISIBILITY
int max_length() const _NOEXCEPT
{
return do_max_length();
}
static locale::id id;
protected:
_LIBCPP_INLINE_VISIBILITY
explicit codecvt(const char*, size_t __refs = 0)
: locale::facet(__refs) {}
~codecvt();
virtual result do_out(state_type& __st,
const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt,
extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
virtual result do_in(state_type& __st,
const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt,
intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const;
virtual result do_unshift(state_type& __st,
extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
virtual int do_encoding() const _NOEXCEPT;
virtual bool do_always_noconv() const _NOEXCEPT;
virtual int do_length(state_type& __st, const extern_type* __frm, const extern_type* __end, size_t __mx) const;
virtual int do_max_length() const _NOEXCEPT;
};
// template <> class codecvt<wchar_t, char, mbstate_t>
template <>
class _LIBCPP_TYPE_VIS codecvt<wchar_t, char, mbstate_t>
: public locale::facet,
public codecvt_base
{
locale_t __l;
public:
typedef wchar_t intern_type;
typedef char extern_type;
typedef mbstate_t state_type;
explicit codecvt(size_t __refs = 0);
_LIBCPP_INLINE_VISIBILITY
result out(state_type& __st,
const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt,
extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const
{
return do_out(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt);
}
_LIBCPP_INLINE_VISIBILITY
result unshift(state_type& __st,
extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const
{
return do_unshift(__st, __to, __to_end, __to_nxt);
}
_LIBCPP_INLINE_VISIBILITY
result in(state_type& __st,
const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt,
intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const
{
return do_in(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt);
}
_LIBCPP_INLINE_VISIBILITY
int encoding() const _NOEXCEPT
{
return do_encoding();
}
_LIBCPP_INLINE_VISIBILITY
bool always_noconv() const _NOEXCEPT
{
return do_always_noconv();
}
_LIBCPP_INLINE_VISIBILITY
int length(state_type& __st, const extern_type* __frm, const extern_type* __end, size_t __mx) const
{
return do_length(__st, __frm, __end, __mx);
}
_LIBCPP_INLINE_VISIBILITY
int max_length() const _NOEXCEPT
{
return do_max_length();
}
static locale::id id;
protected:
explicit codecvt(const char*, size_t __refs = 0);
~codecvt();
virtual result do_out(state_type& __st,
const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt,
extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
virtual result do_in(state_type& __st,
const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt,
intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const;
virtual result do_unshift(state_type& __st,
extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
virtual int do_encoding() const _NOEXCEPT;
virtual bool do_always_noconv() const _NOEXCEPT;
virtual int do_length(state_type&, const extern_type* __frm, const extern_type* __end, size_t __mx) const;
virtual int do_max_length() const _NOEXCEPT;
};
// template <> class codecvt<char16_t, char, mbstate_t>
template <>
class _LIBCPP_TYPE_VIS codecvt<char16_t, char, mbstate_t>
: public locale::facet,
public codecvt_base
{
public:
typedef char16_t intern_type;
typedef char extern_type;
typedef mbstate_t state_type;
_LIBCPP_INLINE_VISIBILITY
explicit codecvt(size_t __refs = 0)
: locale::facet(__refs) {}
_LIBCPP_INLINE_VISIBILITY
result out(state_type& __st,
const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt,
extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const
{
return do_out(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt);
}
_LIBCPP_INLINE_VISIBILITY
result unshift(state_type& __st,
extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const
{
return do_unshift(__st, __to, __to_end, __to_nxt);
}
_LIBCPP_INLINE_VISIBILITY
result in(state_type& __st,
const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt,
intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const
{
return do_in(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt);
}
_LIBCPP_INLINE_VISIBILITY
int encoding() const _NOEXCEPT
{
return do_encoding();
}
_LIBCPP_INLINE_VISIBILITY
bool always_noconv() const _NOEXCEPT
{
return do_always_noconv();
}
_LIBCPP_INLINE_VISIBILITY
int length(state_type& __st, const extern_type* __frm, const extern_type* __end, size_t __mx) const
{
return do_length(__st, __frm, __end, __mx);
}
_LIBCPP_INLINE_VISIBILITY
int max_length() const _NOEXCEPT
{
return do_max_length();
}
static locale::id id;
protected:
_LIBCPP_INLINE_VISIBILITY
explicit codecvt(const char*, size_t __refs = 0)
: locale::facet(__refs) {}
~codecvt();
virtual result do_out(state_type& __st,
const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt,
extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
virtual result do_in(state_type& __st,
const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt,
intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const;
virtual result do_unshift(state_type& __st,
extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
virtual int do_encoding() const _NOEXCEPT;
virtual bool do_always_noconv() const _NOEXCEPT;
virtual int do_length(state_type&, const extern_type* __frm, const extern_type* __end, size_t __mx) const;
virtual int do_max_length() const _NOEXCEPT;
};
// template <> class codecvt<char32_t, char, mbstate_t>
template <>
class _LIBCPP_TYPE_VIS codecvt<char32_t, char, mbstate_t>
: public locale::facet,
public codecvt_base
{
public:
typedef char32_t intern_type;
typedef char extern_type;
typedef mbstate_t state_type;
_LIBCPP_INLINE_VISIBILITY
explicit codecvt(size_t __refs = 0)
: locale::facet(__refs) {}
_LIBCPP_INLINE_VISIBILITY
result out(state_type& __st,
const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt,
extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const
{
return do_out(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt);
}
_LIBCPP_INLINE_VISIBILITY
result unshift(state_type& __st,
extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const
{
return do_unshift(__st, __to, __to_end, __to_nxt);
}
_LIBCPP_INLINE_VISIBILITY
result in(state_type& __st,
const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt,
intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const
{
return do_in(__st, __frm, __frm_end, __frm_nxt, __to, __to_end, __to_nxt);
}
_LIBCPP_INLINE_VISIBILITY
int encoding() const _NOEXCEPT
{
return do_encoding();
}
_LIBCPP_INLINE_VISIBILITY
bool always_noconv() const _NOEXCEPT
{
return do_always_noconv();
}
_LIBCPP_INLINE_VISIBILITY
int length(state_type& __st, const extern_type* __frm, const extern_type* __end, size_t __mx) const
{
return do_length(__st, __frm, __end, __mx);
}
_LIBCPP_INLINE_VISIBILITY
int max_length() const _NOEXCEPT
{
return do_max_length();
}
static locale::id id;
protected:
_LIBCPP_INLINE_VISIBILITY
explicit codecvt(const char*, size_t __refs = 0)
: locale::facet(__refs) {}
~codecvt();
virtual result do_out(state_type& __st,
const intern_type* __frm, const intern_type* __frm_end, const intern_type*& __frm_nxt,
extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
virtual result do_in(state_type& __st,
const extern_type* __frm, const extern_type* __frm_end, const extern_type*& __frm_nxt,
intern_type* __to, intern_type* __to_end, intern_type*& __to_nxt) const;
virtual result do_unshift(state_type& __st,
extern_type* __to, extern_type* __to_end, extern_type*& __to_nxt) const;
virtual int do_encoding() const _NOEXCEPT;
virtual bool do_always_noconv() const _NOEXCEPT;
virtual int do_length(state_type&, const extern_type* __frm, const extern_type* __end, size_t __mx) const;
virtual int do_max_length() const _NOEXCEPT;
};
// template <class _InternT, class _ExternT, class _StateT> class codecvt_byname
template <class _InternT, class _ExternT, class _StateT>
class _LIBCPP_TEMPLATE_VIS codecvt_byname
: public codecvt<_InternT, _ExternT, _StateT>
{
public:
_LIBCPP_INLINE_VISIBILITY
explicit codecvt_byname(const char* __nm, size_t __refs = 0)
: codecvt<_InternT, _ExternT, _StateT>(__nm, __refs) {}
_LIBCPP_INLINE_VISIBILITY
explicit codecvt_byname(const string& __nm, size_t __refs = 0)
: codecvt<_InternT, _ExternT, _StateT>(__nm.c_str(), __refs) {}
protected:
~codecvt_byname();
};
template <class _InternT, class _ExternT, class _StateT>
codecvt_byname<_InternT, _ExternT, _StateT>::~codecvt_byname()
{
}
_LIBCPP_EXTERN_TEMPLATE2(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS codecvt_byname<char, char, mbstate_t>)
_LIBCPP_EXTERN_TEMPLATE2(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS codecvt_byname<wchar_t, char, mbstate_t>)
_LIBCPP_EXTERN_TEMPLATE2(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS codecvt_byname<char16_t, char, mbstate_t>)
_LIBCPP_EXTERN_TEMPLATE2(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS codecvt_byname<char32_t, char, mbstate_t>)
template <size_t _Np>
struct __narrow_to_utf8
{
template <class _OutputIterator, class _CharT>
_OutputIterator
operator()(_OutputIterator __s, const _CharT* __wb, const _CharT* __we) const;
};
template <>
struct __narrow_to_utf8<8>
{
template <class _OutputIterator, class _CharT>
_LIBCPP_INLINE_VISIBILITY
_OutputIterator
operator()(_OutputIterator __s, const _CharT* __wb, const _CharT* __we) const
{
for (; __wb < __we; ++__wb, ++__s)
*__s = *__wb;
return __s;
}
};
template <>
struct _LIBCPP_TEMPLATE_VIS __narrow_to_utf8<16>
: public codecvt<char16_t, char, mbstate_t>
{
_LIBCPP_INLINE_VISIBILITY
__narrow_to_utf8() : codecvt<char16_t, char, mbstate_t>(1) {}
_LIBCPP_EXPORTED_FROM_ABI ~__narrow_to_utf8();
template <class _OutputIterator, class _CharT>
_LIBCPP_INLINE_VISIBILITY
_OutputIterator
operator()(_OutputIterator __s, const _CharT* __wb, const _CharT* __we) const
{
result __r = ok;
mbstate_t __mb;
while (__wb < __we && __r != error)
{
const int __sz = 32;
char __buf[__sz];
char* __bn;
const char16_t* __wn = (const char16_t*)__wb;
__r = do_out(__mb, (const char16_t*)__wb, (const char16_t*)__we, __wn,
__buf, __buf+__sz, __bn);
if (__r == codecvt_base::error || __wn == (const char16_t*)__wb)
__throw_runtime_error("locale not supported");
for (const char* __p = __buf; __p < __bn; ++__p, ++__s)
*__s = *__p;
__wb = (const _CharT*)__wn;
}
return __s;
}
};
template <>
struct _LIBCPP_TEMPLATE_VIS __narrow_to_utf8<32>
: public codecvt<char32_t, char, mbstate_t>
{
_LIBCPP_INLINE_VISIBILITY
__narrow_to_utf8() : codecvt<char32_t, char, mbstate_t>(1) {}
_LIBCPP_EXPORTED_FROM_ABI ~__narrow_to_utf8();
template <class _OutputIterator, class _CharT>
_LIBCPP_INLINE_VISIBILITY
_OutputIterator
operator()(_OutputIterator __s, const _CharT* __wb, const _CharT* __we) const
{
result __r = ok;
mbstate_t __mb;
while (__wb < __we && __r != error)
{
const int __sz = 32;
char __buf[__sz];
char* __bn;
const char32_t* __wn = (const char32_t*)__wb;
__r = do_out(__mb, (const char32_t*)__wb, (const char32_t*)__we, __wn,
__buf, __buf+__sz, __bn);
if (__r == codecvt_base::error || __wn == (const char32_t*)__wb)
__throw_runtime_error("locale not supported");
for (const char* __p = __buf; __p < __bn; ++__p, ++__s)
*__s = *__p;
__wb = (const _CharT*)__wn;
}
return __s;
}
};
template <size_t _Np>
struct __widen_from_utf8
{
template <class _OutputIterator>
_OutputIterator
operator()(_OutputIterator __s, const char* __nb, const char* __ne) const;
};
template <>
struct __widen_from_utf8<8>
{
template <class _OutputIterator>
_LIBCPP_INLINE_VISIBILITY
_OutputIterator
operator()(_OutputIterator __s, const char* __nb, const char* __ne) const
{
for (; __nb < __ne; ++__nb, ++__s)
*__s = *__nb;
return __s;
}
};
template <>
struct _LIBCPP_TEMPLATE_VIS __widen_from_utf8<16>
: public codecvt<char16_t, char, mbstate_t>
{
_LIBCPP_INLINE_VISIBILITY
__widen_from_utf8() : codecvt<char16_t, char, mbstate_t>(1) {}
_LIBCPP_EXPORTED_FROM_ABI ~__widen_from_utf8();
template <class _OutputIterator>
_LIBCPP_INLINE_VISIBILITY
_OutputIterator
operator()(_OutputIterator __s, const char* __nb, const char* __ne) const
{
result __r = ok;
mbstate_t __mb;
while (__nb < __ne && __r != error)
{
const int __sz = 32;
char16_t __buf[__sz];
char16_t* __bn;
const char* __nn = __nb;
__r = do_in(__mb, __nb, __ne - __nb > __sz ? __nb+__sz : __ne, __nn,
__buf, __buf+__sz, __bn);
if (__r == codecvt_base::error || __nn == __nb)
__throw_runtime_error("locale not supported");
for (const char16_t* __p = __buf; __p < __bn; ++__p, ++__s)
*__s = (wchar_t)*__p;
__nb = __nn;
}
return __s;
}
};
template <>
struct _LIBCPP_TEMPLATE_VIS __widen_from_utf8<32>
: public codecvt<char32_t, char, mbstate_t>
{
_LIBCPP_INLINE_VISIBILITY
__widen_from_utf8() : codecvt<char32_t, char, mbstate_t>(1) {}
_LIBCPP_EXPORTED_FROM_ABI ~__widen_from_utf8();
template <class _OutputIterator>
_LIBCPP_INLINE_VISIBILITY
_OutputIterator
operator()(_OutputIterator __s, const char* __nb, const char* __ne) const
{
result __r = ok;
mbstate_t __mb;
while (__nb < __ne && __r != error)
{
const int __sz = 32;
char32_t __buf[__sz];
char32_t* __bn;
const char* __nn = __nb;
__r = do_in(__mb, __nb, __ne - __nb > __sz ? __nb+__sz : __ne, __nn,
__buf, __buf+__sz, __bn);
if (__r == codecvt_base::error || __nn == __nb)
__throw_runtime_error("locale not supported");
for (const char32_t* __p = __buf; __p < __bn; ++__p, ++__s)
*__s = (wchar_t)*__p;
__nb = __nn;
}
return __s;
}
};
// template <class charT> class numpunct
template <class _CharT> class _LIBCPP_TEMPLATE_VIS numpunct;
template <>
class _LIBCPP_TYPE_VIS numpunct<char>
: public locale::facet
{
public:
typedef char char_type;
typedef basic_string<char_type> string_type;
explicit numpunct(size_t __refs = 0);
_LIBCPP_INLINE_VISIBILITY char_type decimal_point() const {return do_decimal_point();}
_LIBCPP_INLINE_VISIBILITY char_type thousands_sep() const {return do_thousands_sep();}
_LIBCPP_INLINE_VISIBILITY string grouping() const {return do_grouping();}
_LIBCPP_INLINE_VISIBILITY string_type truename() const {return do_truename();}
_LIBCPP_INLINE_VISIBILITY string_type falsename() const {return do_falsename();}
static locale::id id;
protected:
~numpunct();
virtual char_type do_decimal_point() const;
virtual char_type do_thousands_sep() const;
virtual string do_grouping() const;
virtual string_type do_truename() const;
virtual string_type do_falsename() const;
char_type __decimal_point_;
char_type __thousands_sep_;
string __grouping_;
};
template <>
class _LIBCPP_TYPE_VIS numpunct<wchar_t>
: public locale::facet
{
public:
typedef wchar_t char_type;
typedef basic_string<char_type> string_type;
explicit numpunct(size_t __refs = 0);
_LIBCPP_INLINE_VISIBILITY char_type decimal_point() const {return do_decimal_point();}
_LIBCPP_INLINE_VISIBILITY char_type thousands_sep() const {return do_thousands_sep();}
_LIBCPP_INLINE_VISIBILITY string grouping() const {return do_grouping();}
_LIBCPP_INLINE_VISIBILITY string_type truename() const {return do_truename();}
_LIBCPP_INLINE_VISIBILITY string_type falsename() const {return do_falsename();}
static locale::id id;
protected:
~numpunct();
virtual char_type do_decimal_point() const;
virtual char_type do_thousands_sep() const;
virtual string do_grouping() const;
virtual string_type do_truename() const;
virtual string_type do_falsename() const;
char_type __decimal_point_;
char_type __thousands_sep_;
string __grouping_;
};
// template <class charT> class numpunct_byname
template <class _CharT> class _LIBCPP_TEMPLATE_VIS numpunct_byname;
template <>
class _LIBCPP_TYPE_VIS numpunct_byname<char>
: public numpunct<char>
{
public:
typedef char char_type;
typedef basic_string<char_type> string_type;
explicit numpunct_byname(const char* __nm, size_t __refs = 0);
explicit numpunct_byname(const string& __nm, size_t __refs = 0);
protected:
~numpunct_byname();
private:
void __init(const char*);
};
template <>
class _LIBCPP_TYPE_VIS numpunct_byname<wchar_t>
: public numpunct<wchar_t>
{
public:
typedef wchar_t char_type;
typedef basic_string<char_type> string_type;
explicit numpunct_byname(const char* __nm, size_t __refs = 0);
explicit numpunct_byname(const string& __nm, size_t __refs = 0);
protected:
~numpunct_byname();
private:
void __init(const char*);
};
_LIBCPP_END_NAMESPACE_STD
#endif // _LIBCPP___LOCALE
| 49,333 | 1,554 | jart/cosmopolitan | false |
cosmopolitan/third_party/libcxx/strstream | // -*- C++ -*-
// clang-format off
//===--------------------------- strstream --------------------------------===//
//
// 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_STRSTREAM
#define _LIBCPP_STRSTREAM
/*
strstream synopsis
class strstreambuf
: public basic_streambuf<char>
{
public:
explicit strstreambuf(streamsize alsize_arg = 0);
strstreambuf(void* (*palloc_arg)(size_t), void (*pfree_arg)(void*));
strstreambuf(char* gnext_arg, streamsize n, char* pbeg_arg = 0);
strstreambuf(const char* gnext_arg, streamsize n);
strstreambuf(signed char* gnext_arg, streamsize n, signed char* pbeg_arg = 0);
strstreambuf(const signed char* gnext_arg, streamsize n);
strstreambuf(unsigned char* gnext_arg, streamsize n, unsigned char* pbeg_arg = 0);
strstreambuf(const unsigned char* gnext_arg, streamsize n);
strstreambuf(strstreambuf&& rhs);
strstreambuf& operator=(strstreambuf&& rhs);
virtual ~strstreambuf();
void swap(strstreambuf& rhs);
void freeze(bool freezefl = true);
char* str();
int pcount() const;
protected:
virtual int_type overflow (int_type c = EOF);
virtual int_type pbackfail(int_type c = EOF);
virtual int_type underflow();
virtual pos_type seekoff(off_type off, ios_base::seekdir way,
ios_base::openmode which = ios_base::in | ios_base::out);
virtual pos_type seekpos(pos_type sp,
ios_base::openmode which = ios_base::in | ios_base::out);
virtual streambuf* setbuf(char* s, streamsize n);
private:
typedef T1 strstate; // exposition only
static const strstate allocated; // exposition only
static const strstate constant; // exposition only
static const strstate dynamic; // exposition only
static const strstate frozen; // exposition only
strstate strmode; // exposition only
streamsize alsize; // exposition only
void* (*palloc)(size_t); // exposition only
void (*pfree)(void*); // exposition only
};
class istrstream
: public basic_istream<char>
{
public:
explicit istrstream(const char* s);
explicit istrstream(char* s);
istrstream(const char* s, streamsize n);
istrstream(char* s, streamsize n);
virtual ~istrstream();
strstreambuf* rdbuf() const;
char *str();
private:
strstreambuf sb; // exposition only
};
class ostrstream
: public basic_ostream<char>
{
public:
ostrstream();
ostrstream(char* s, int n, ios_base::openmode mode = ios_base::out);
virtual ~ostrstream();
strstreambuf* rdbuf() const;
void freeze(bool freezefl = true);
char* str();
int pcount() const;
private:
strstreambuf sb; // exposition only
};
class strstream
: public basic_iostream<char>
{
public:
// Types
typedef char char_type;
typedef char_traits<char>::int_type int_type;
typedef char_traits<char>::pos_type pos_type;
typedef char_traits<char>::off_type off_type;
// constructors/destructor
strstream();
strstream(char* s, int n, ios_base::openmode mode = ios_base::in | ios_base::out);
virtual ~strstream();
// Members:
strstreambuf* rdbuf() const;
void freeze(bool freezefl = true);
int pcount() const;
char* str();
private:
strstreambuf sb; // exposition only
};
} // std
*/
#include "third_party/libcxx/__config"
#include "third_party/libcxx/ostream"
#include "third_party/libcxx/istream"
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
#pragma GCC system_header
#endif
_LIBCPP_BEGIN_NAMESPACE_STD
class _LIBCPP_TYPE_VIS strstreambuf
: public streambuf
{
public:
explicit strstreambuf(streamsize __alsize = 0);
strstreambuf(void* (*__palloc)(size_t), void (*__pfree)(void*));
strstreambuf(char* __gnext, streamsize __n, char* __pbeg = 0);
strstreambuf(const char* __gnext, streamsize __n);
strstreambuf(signed char* __gnext, streamsize __n, signed char* __pbeg = 0);
strstreambuf(const signed char* __gnext, streamsize __n);
strstreambuf(unsigned char* __gnext, streamsize __n, unsigned char* __pbeg = 0);
strstreambuf(const unsigned char* __gnext, streamsize __n);
#ifndef _LIBCPP_CXX03_LANG
_LIBCPP_INLINE_VISIBILITY
strstreambuf(strstreambuf&& __rhs);
_LIBCPP_INLINE_VISIBILITY
strstreambuf& operator=(strstreambuf&& __rhs);
#endif // _LIBCPP_CXX03_LANG
virtual ~strstreambuf();
void swap(strstreambuf& __rhs);
void freeze(bool __freezefl = true);
char* str();
int pcount() const;
protected:
virtual int_type overflow (int_type __c = EOF);
virtual int_type pbackfail(int_type __c = EOF);
virtual int_type underflow();
virtual pos_type seekoff(off_type __off, ios_base::seekdir __way,
ios_base::openmode __which = ios_base::in | ios_base::out);
virtual pos_type seekpos(pos_type __sp,
ios_base::openmode __which = ios_base::in | ios_base::out);
private:
typedef unsigned __mode_type;
static const __mode_type __allocated = 0x01;
static const __mode_type __constant = 0x02;
static const __mode_type __dynamic = 0x04;
static const __mode_type __frozen = 0x08;
static const streamsize __default_alsize = 4096;
__mode_type __strmode_;
streamsize __alsize_;
void* (*__palloc_)(size_t);
void (*__pfree_)(void*);
void __init(char* __gnext, streamsize __n, char* __pbeg);
};
#ifndef _LIBCPP_CXX03_LANG
inline _LIBCPP_INLINE_VISIBILITY
strstreambuf::strstreambuf(strstreambuf&& __rhs)
: streambuf(__rhs),
__strmode_(__rhs.__strmode_),
__alsize_(__rhs.__alsize_),
__palloc_(__rhs.__palloc_),
__pfree_(__rhs.__pfree_)
{
__rhs.setg(nullptr, nullptr, nullptr);
__rhs.setp(nullptr, nullptr);
}
inline _LIBCPP_INLINE_VISIBILITY
strstreambuf&
strstreambuf::operator=(strstreambuf&& __rhs)
{
if (eback() && (__strmode_ & __allocated) != 0 && (__strmode_ & __frozen) == 0)
{
if (__pfree_)
__pfree_(eback());
else
delete [] eback();
}
streambuf::operator=(__rhs);
__strmode_ = __rhs.__strmode_;
__alsize_ = __rhs.__alsize_;
__palloc_ = __rhs.__palloc_;
__pfree_ = __rhs.__pfree_;
__rhs.setg(nullptr, nullptr, nullptr);
__rhs.setp(nullptr, nullptr);
return *this;
}
#endif // _LIBCPP_CXX03_LANG
class _LIBCPP_TYPE_VIS istrstream
: public istream
{
public:
_LIBCPP_INLINE_VISIBILITY
explicit istrstream(const char* __s)
: istream(&__sb_), __sb_(__s, 0) {}
_LIBCPP_INLINE_VISIBILITY
explicit istrstream(char* __s)
: istream(&__sb_), __sb_(__s, 0) {}
_LIBCPP_INLINE_VISIBILITY
istrstream(const char* __s, streamsize __n)
: istream(&__sb_), __sb_(__s, __n) {}
_LIBCPP_INLINE_VISIBILITY
istrstream(char* __s, streamsize __n)
: istream(&__sb_), __sb_(__s, __n) {}
#ifndef _LIBCPP_CXX03_LANG
_LIBCPP_INLINE_VISIBILITY
istrstream(istrstream&& __rhs)
: istream(_VSTD::move(__rhs)),
__sb_(_VSTD::move(__rhs.__sb_))
{
istream::set_rdbuf(&__sb_);
}
_LIBCPP_INLINE_VISIBILITY
istrstream& operator=(istrstream&& __rhs)
{
istream::operator=(_VSTD::move(__rhs));
__sb_ = _VSTD::move(__rhs.__sb_);
return *this;
}
#endif // _LIBCPP_CXX03_LANG
virtual ~istrstream();
_LIBCPP_INLINE_VISIBILITY
void swap(istrstream& __rhs)
{
istream::swap(__rhs);
__sb_.swap(__rhs.__sb_);
}
_LIBCPP_INLINE_VISIBILITY
strstreambuf* rdbuf() const {return const_cast<strstreambuf*>(&__sb_);}
_LIBCPP_INLINE_VISIBILITY
char *str() {return __sb_.str();}
private:
strstreambuf __sb_;
};
class _LIBCPP_TYPE_VIS ostrstream
: public ostream
{
public:
_LIBCPP_INLINE_VISIBILITY
ostrstream()
: ostream(&__sb_) {}
_LIBCPP_INLINE_VISIBILITY
ostrstream(char* __s, int __n, ios_base::openmode __mode = ios_base::out)
: ostream(&__sb_),
__sb_(__s, __n, __s + (__mode & ios::app ? strlen(__s) : 0))
{}
#ifndef _LIBCPP_CXX03_LANG
_LIBCPP_INLINE_VISIBILITY
ostrstream(ostrstream&& __rhs)
: ostream(_VSTD::move(__rhs)),
__sb_(_VSTD::move(__rhs.__sb_))
{
ostream::set_rdbuf(&__sb_);
}
_LIBCPP_INLINE_VISIBILITY
ostrstream& operator=(ostrstream&& __rhs)
{
ostream::operator=(_VSTD::move(__rhs));
__sb_ = _VSTD::move(__rhs.__sb_);
return *this;
}
#endif // _LIBCPP_CXX03_LANG
virtual ~ostrstream();
_LIBCPP_INLINE_VISIBILITY
void swap(ostrstream& __rhs)
{
ostream::swap(__rhs);
__sb_.swap(__rhs.__sb_);
}
_LIBCPP_INLINE_VISIBILITY
strstreambuf* rdbuf() const {return const_cast<strstreambuf*>(&__sb_);}
_LIBCPP_INLINE_VISIBILITY
void freeze(bool __freezefl = true) {__sb_.freeze(__freezefl);}
_LIBCPP_INLINE_VISIBILITY
char* str() {return __sb_.str();}
_LIBCPP_INLINE_VISIBILITY
int pcount() const {return __sb_.pcount();}
private:
strstreambuf __sb_; // exposition only
};
class _LIBCPP_TYPE_VIS strstream
: public iostream
{
public:
// Types
typedef char char_type;
typedef char_traits<char>::int_type int_type;
typedef char_traits<char>::pos_type pos_type;
typedef char_traits<char>::off_type off_type;
// constructors/destructor
_LIBCPP_INLINE_VISIBILITY
strstream()
: iostream(&__sb_) {}
_LIBCPP_INLINE_VISIBILITY
strstream(char* __s, int __n, ios_base::openmode __mode = ios_base::in | ios_base::out)
: iostream(&__sb_),
__sb_(__s, __n, __s + (__mode & ios::app ? strlen(__s) : 0))
{}
#ifndef _LIBCPP_CXX03_LANG
_LIBCPP_INLINE_VISIBILITY
strstream(strstream&& __rhs)
: iostream(_VSTD::move(__rhs)),
__sb_(_VSTD::move(__rhs.__sb_))
{
iostream::set_rdbuf(&__sb_);
}
_LIBCPP_INLINE_VISIBILITY
strstream& operator=(strstream&& __rhs)
{
iostream::operator=(_VSTD::move(__rhs));
__sb_ = _VSTD::move(__rhs.__sb_);
return *this;
}
#endif // _LIBCPP_CXX03_LANG
virtual ~strstream();
_LIBCPP_INLINE_VISIBILITY
void swap(strstream& __rhs)
{
iostream::swap(__rhs);
__sb_.swap(__rhs.__sb_);
}
// Members:
_LIBCPP_INLINE_VISIBILITY
strstreambuf* rdbuf() const {return const_cast<strstreambuf*>(&__sb_);}
_LIBCPP_INLINE_VISIBILITY
void freeze(bool __freezefl = true) {__sb_.freeze(__freezefl);}
_LIBCPP_INLINE_VISIBILITY
int pcount() const {return __sb_.pcount();}
_LIBCPP_INLINE_VISIBILITY
char* str() {return __sb_.str();}
private:
strstreambuf __sb_; // exposition only
};
_LIBCPP_END_NAMESPACE_STD
#endif // _LIBCPP_STRSTREAM
| 11,222 | 401 | jart/cosmopolitan | false |
cosmopolitan/third_party/libcxx/.clang-format | BasedOnStyle: LLVM
---
Language: Cpp
Standard: Cpp03
AlwaysBreakTemplateDeclarations: true
PointerAlignment: Left
# Disable formatting options which may break tests.
SortIncludes: false
ReflowComments: false
---
| 215 | 14 | jart/cosmopolitan | false |
cosmopolitan/third_party/libcxx/cstdbool | // -*- C++ -*-
// clang-format off
//===--------------------------- cstdbool ---------------------------------===//
//
// 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_CSTDBOOL
#define _LIBCPP_CSTDBOOL
/*
cstdbool synopsis
Macros:
__bool_true_false_are_defined
*/
#include "third_party/libcxx/__config"
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
#pragma GCC system_header
#endif
#undef __bool_true_false_are_defined
#define __bool_true_false_are_defined 1
#endif // _LIBCPP_CSTDBOOL
| 760 | 33 | jart/cosmopolitan | false |
cosmopolitan/third_party/libcxx/stdlib.h | // -*- C++ -*-
//===--------------------------- stdlib.h ---------------------------------===//
//
// 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
//
//===----------------------------------------------------------------------===//
#if defined(__need_malloc_and_calloc) || defined(_LIBCPP_STDLIB_INCLUDE_NEXT)
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
#pragma GCC system_header
#endif
#if defined(_LIBCPP_STDLIB_INCLUDE_NEXT)
#undef _LIBCPP_STDLIB_INCLUDE_NEXT
#endif
#include "libc/isystem/stdlib.h"
#elif !defined(_LIBCPP_STDLIB_H)
#define _LIBCPP_STDLIB_H
#include "third_party/libcxx/__config"
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
#pragma GCC system_header
#endif
#include "libc/isystem/stdlib.h"
#ifdef __cplusplus
#include "third_party/libcxx/math.h"
#endif // __cplusplus
/*
stdlib.h synopsis
Macros:
EXIT_FAILURE
EXIT_SUCCESS
MB_CUR_MAX
NULL
RAND_MAX
Types:
size_t
div_t
ldiv_t
lldiv_t // C99
double atof (const char* nptr);
int atoi (const char* nptr);
long atol (const char* nptr);
long long atoll(const char* nptr); // C99
double strtod (const char* restrict nptr, char** restrict endptr);
float strtof (const char* restrict nptr, char** restrict endptr); // C99
long double strtold (const char* restrict nptr, char** restrict endptr); // C99
long strtol (const char* restrict nptr, char** restrict endptr, int base);
long long strtoll (const char* restrict nptr, char** restrict endptr, int base); // C99
unsigned long strtoul (const char* restrict nptr, char** restrict endptr, int base);
unsigned long long strtoull(const char* restrict nptr, char** restrict endptr, int base); // C99
int rand(void);
void srand(unsigned int seed);
void* calloc(size_t nmemb, size_t size);
void free(void* ptr);
void* malloc(size_t size);
void* realloc(void* ptr, size_t size);
void abort(void);
int atexit(void (*func)(void));
void exit(int status);
void _Exit(int status);
char* getenv(const char* name);
int system(const char* string);
void* bsearch(const void* key, const void* base, size_t nmemb, size_t size,
int (*compar)(const void *, const void *));
void qsort(void* base, size_t nmemb, size_t size,
int (*compar)(const void *, const void *));
int abs( int j);
long abs( long j);
long long abs(long long j); // C++0X
long labs( long j);
long long llabs(long long j); // C99
div_t div( int numer, int denom);
ldiv_t div( long numer, long denom);
lldiv_t div(long long numer, long long denom); // C++0X
ldiv_t ldiv( long numer, long denom);
lldiv_t lldiv(long long numer, long long denom); // C99
int mblen(const char* s, size_t n);
int mbtowc(wchar_t* restrict pwc, const char* restrict s, size_t n);
int wctomb(char* s, wchar_t wchar);
size_t mbstowcs(wchar_t* restrict pwcs, const char* restrict s, size_t n);
size_t wcstombs(char* restrict s, const wchar_t* restrict pwcs, size_t n);
int at_quick_exit(void (*func)(void)) // C++11
void quick_exit(int status); // C++11
void *aligned_alloc(size_t alignment, size_t size); // C11
*/
#endif // _LIBCPP_STDLIB_H
| 3,716 | 104 | jart/cosmopolitan | false |
cosmopolitan/third_party/libcxx/cstdio | // -*- C++ -*-
//===---------------------------- cstdio ----------------------------------===//
//
// 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_CSTDIO
#define _LIBCPP_CSTDIO
#include "third_party/libcxx/__config"
#include "third_party/libcxx/stdio.h"
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
#pragma GCC system_header
#endif
_LIBCPP_BEGIN_NAMESPACE_STD
/*
cstdio synopsis
Macros:
BUFSIZ
EOF
FILENAME_MAX
FOPEN_MAX
L_tmpnam
NULL
SEEK_CUR
SEEK_END
SEEK_SET
TMP_MAX
_IOFBF
_IOLBF
_IONBF
stderr
stdin
stdout
namespace std
{
Types:
FILE
fpos_t
size_t
int remove(const char* filename);
int rename(const char* old, const char* new);
FILE* tmpfile(void);
char* tmpnam(char* s);
int fclose(FILE* stream);
int fflush(FILE* stream);
FILE* fopen(const char* restrict filename, const char* restrict mode);
FILE* freopen(const char* restrict filename, const char * restrict mode,
FILE * restrict stream);
void setbuf(FILE* restrict stream, char* restrict buf);
int setvbuf(FILE* restrict stream, char* restrict buf, int mode, size_t size);
int fprintf(FILE* restrict stream, const char* restrict format, ...);
int fscanf(FILE* restrict stream, const char * restrict format, ...);
int printf(const char* restrict format, ...);
int scanf(const char* restrict format, ...);
int snprintf(char* restrict s, size_t n, const char* restrict format, ...); // C99
int sprintf(char* restrict s, const char* restrict format, ...);
int sscanf(const char* restrict s, const char* restrict format, ...);
int vfprintf(FILE* restrict stream, const char* restrict format, va_list arg);
int vfscanf(FILE* restrict stream, const char* restrict format, va_list arg); // C99
int vprintf(const char* restrict format, va_list arg);
int vscanf(const char* restrict format, va_list arg); // C99
int vsnprintf(char* restrict s, size_t n, const char* restrict format, // C99
va_list arg);
int vsprintf(char* restrict s, const char* restrict format, va_list arg);
int vsscanf(const char* restrict s, const char* restrict format, va_list arg); // C99
int fgetc(FILE* stream);
char* fgets(char* restrict s, int n, FILE* restrict stream);
int fputc(int c, FILE* stream);
int fputs(const char* restrict s, FILE* restrict stream);
int getc(FILE* stream);
int getchar(void);
char* gets(char* s); // removed in C++14
int putc(int c, FILE* stream);
int putchar(int c);
int puts(const char* s);
int ungetc(int c, FILE* stream);
size_t fread(void* restrict ptr, size_t size, size_t nmemb,
FILE* restrict stream);
size_t fwrite(const void* restrict ptr, size_t size, size_t nmemb,
FILE* restrict stream);
int fgetpos(FILE* restrict stream, fpos_t* restrict pos);
int fseek(FILE* stream, long offset, int whence);
int fsetpos(FILE*stream, const fpos_t* pos);
long ftell(FILE* stream);
void rewind(FILE* stream);
void clearerr(FILE* stream);
int feof(FILE* stream);
int ferror(FILE* stream);
void perror(const char* s);
} // std
*/
using ::FILE;
using ::fpos_t;
using ::size_t;
using ::fclose;
using ::fflush;
using ::setbuf;
using ::setvbuf;
using ::fprintf;
using ::fscanf;
using ::snprintf;
using ::sprintf;
using ::sscanf;
using ::vfprintf;
using ::vfscanf;
using ::vsscanf;
using ::vsnprintf;
using ::vsprintf;
using ::fgetc;
using ::fgets;
using ::fputc;
using ::fputs;
using ::getc;
using ::putc;
using ::ungetc;
using ::fread;
using ::fwrite;
using ::fgetpos;
using ::fseek;
using ::fsetpos;
using ::ftell;
using ::rewind;
using ::clearerr;
using ::feof;
using ::ferror;
using ::perror;
#ifndef _LIBCPP_HAS_NO_GLOBAL_FILESYSTEM_NAMESPACE
using ::fopen;
using ::freopen;
using ::remove;
using ::rename;
using ::tmpfile;
using ::tmpnam;
#endif
#ifndef _LIBCPP_HAS_NO_STDIN
using ::getchar;
#if _LIBCPP_STD_VER <= 11 && !defined(_LIBCPP_C_HAS_NO_GETS)
using ::gets;
#endif
using ::scanf;
using ::vscanf;
#endif
#ifndef _LIBCPP_HAS_NO_STDOUT
using ::printf;
using ::putchar;
using ::puts;
using ::vprintf;
#endif
_LIBCPP_END_NAMESPACE_STD
#endif // _LIBCPP_CSTDIO
| 4,359 | 172 | jart/cosmopolitan | false |
cosmopolitan/third_party/libcxx/bitset | // -*- C++ -*-
//===---------------------------- bitset ----------------------------------===//
//
// 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_BITSET
#define _LIBCPP_BITSET
#include "third_party/libcxx/__config"
#include "third_party/libcxx/__bit_reference"
#include "third_party/libcxx/cstddef"
#include "third_party/libcxx/climits"
#include "third_party/libcxx/string"
#include "third_party/libcxx/stdexcept"
#include "third_party/libcxx/iosfwd"
#include "third_party/libcxx/__functional_base"
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
#pragma GCC system_header
#endif
_LIBCPP_PUSH_MACROS
#include "third_party/libcxx/__undef_macros"
_LIBCPP_BEGIN_NAMESPACE_STD
/*
bitset synopsis
namespace std
{
namespace std {
template <size_t N>
class bitset
{
public:
// bit reference:
class reference
{
friend class bitset;
reference() noexcept;
public:
~reference() noexcept;
reference& operator=(bool x) noexcept; // for b[i] = x;
reference& operator=(const reference&) noexcept; // for b[i] = b[j];
bool operator~() const noexcept; // flips the bit
operator bool() const noexcept; // for x = b[i];
reference& flip() noexcept; // for b[i].flip();
};
// 23.3.5.1 constructors:
constexpr bitset() noexcept;
constexpr bitset(unsigned long long val) noexcept;
template <class charT>
explicit bitset(const charT* str,
typename basic_string<charT>::size_type n = basic_string<charT>::npos,
charT zero = charT('0'), charT one = charT('1'));
template<class charT, class traits, class Allocator>
explicit bitset(const basic_string<charT,traits,Allocator>& str,
typename basic_string<charT,traits,Allocator>::size_type pos = 0,
typename basic_string<charT,traits,Allocator>::size_type n =
basic_string<charT,traits,Allocator>::npos,
charT zero = charT('0'), charT one = charT('1'));
// 23.3.5.2 bitset operations:
bitset& operator&=(const bitset& rhs) noexcept;
bitset& operator|=(const bitset& rhs) noexcept;
bitset& operator^=(const bitset& rhs) noexcept;
bitset& operator<<=(size_t pos) noexcept;
bitset& operator>>=(size_t pos) noexcept;
bitset& set() noexcept;
bitset& set(size_t pos, bool val = true);
bitset& reset() noexcept;
bitset& reset(size_t pos);
bitset operator~() const noexcept;
bitset& flip() noexcept;
bitset& flip(size_t pos);
// element access:
constexpr bool operator[](size_t pos) const; // for b[i];
reference operator[](size_t pos); // for b[i];
unsigned long to_ulong() const;
unsigned long long to_ullong() const;
template <class charT, class traits, class Allocator>
basic_string<charT, traits, Allocator> to_string(charT zero = charT('0'), charT one = charT('1')) const;
template <class charT, class traits>
basic_string<charT, traits, allocator<charT> > to_string(charT zero = charT('0'), charT one = charT('1')) const;
template <class charT>
basic_string<charT, char_traits<charT>, allocator<charT> > to_string(charT zero = charT('0'), charT one = charT('1')) const;
basic_string<char, char_traits<char>, allocator<char> > to_string(char zero = '0', char one = '1') const;
size_t count() const noexcept;
constexpr size_t size() const noexcept;
bool operator==(const bitset& rhs) const noexcept;
bool operator!=(const bitset& rhs) const noexcept;
bool test(size_t pos) const;
bool all() const noexcept;
bool any() const noexcept;
bool none() const noexcept;
bitset operator<<(size_t pos) const noexcept;
bitset operator>>(size_t pos) const noexcept;
};
// 23.3.5.3 bitset operators:
template <size_t N>
bitset<N> operator&(const bitset<N>&, const bitset<N>&) noexcept;
template <size_t N>
bitset<N> operator|(const bitset<N>&, const bitset<N>&) noexcept;
template <size_t N>
bitset<N> operator^(const bitset<N>&, const bitset<N>&) noexcept;
template <class charT, class traits, size_t N>
basic_istream<charT, traits>&
operator>>(basic_istream<charT, traits>& is, bitset<N>& x);
template <class charT, class traits, size_t N>
basic_ostream<charT, traits>&
operator<<(basic_ostream<charT, traits>& os, const bitset<N>& x);
template <size_t N> struct hash<std::bitset<N>>;
} // std
*/
template <size_t _N_words, size_t _Size>
class __bitset;
template <size_t _N_words, size_t _Size>
struct __has_storage_type<__bitset<_N_words, _Size> >
{
static const bool value = true;
};
template <size_t _N_words, size_t _Size>
class __bitset
{
public:
typedef ptrdiff_t difference_type;
typedef size_t size_type;
typedef size_type __storage_type;
protected:
typedef __bitset __self;
typedef __storage_type* __storage_pointer;
typedef const __storage_type* __const_storage_pointer;
static const unsigned __bits_per_word = static_cast<unsigned>(sizeof(__storage_type) * CHAR_BIT);
friend class __bit_reference<__bitset>;
friend class __bit_const_reference<__bitset>;
friend class __bit_iterator<__bitset, false>;
friend class __bit_iterator<__bitset, true>;
friend struct __bit_array<__bitset>;
__storage_type __first_[_N_words];
typedef __bit_reference<__bitset> reference;
typedef __bit_const_reference<__bitset> const_reference;
typedef __bit_iterator<__bitset, false> iterator;
typedef __bit_iterator<__bitset, true> const_iterator;
_LIBCPP_INLINE_VISIBILITY
_LIBCPP_CONSTEXPR __bitset() _NOEXCEPT;
_LIBCPP_INLINE_VISIBILITY
explicit _LIBCPP_CONSTEXPR __bitset(unsigned long long __v) _NOEXCEPT;
_LIBCPP_INLINE_VISIBILITY reference __make_ref(size_t __pos) _NOEXCEPT
{return reference(__first_ + __pos / __bits_per_word, __storage_type(1) << __pos % __bits_per_word);}
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR const_reference __make_ref(size_t __pos) const _NOEXCEPT
{return const_reference(__first_ + __pos / __bits_per_word, __storage_type(1) << __pos % __bits_per_word);}
_LIBCPP_INLINE_VISIBILITY iterator __make_iter(size_t __pos) _NOEXCEPT
{return iterator(__first_ + __pos / __bits_per_word, __pos % __bits_per_word);}
_LIBCPP_INLINE_VISIBILITY const_iterator __make_iter(size_t __pos) const _NOEXCEPT
{return const_iterator(__first_ + __pos / __bits_per_word, __pos % __bits_per_word);}
_LIBCPP_INLINE_VISIBILITY
void operator&=(const __bitset& __v) _NOEXCEPT;
_LIBCPP_INLINE_VISIBILITY
void operator|=(const __bitset& __v) _NOEXCEPT;
_LIBCPP_INLINE_VISIBILITY
void operator^=(const __bitset& __v) _NOEXCEPT;
void flip() _NOEXCEPT;
_LIBCPP_INLINE_VISIBILITY unsigned long to_ulong() const
{return to_ulong(integral_constant<bool, _Size < sizeof(unsigned long) * CHAR_BIT>());}
_LIBCPP_INLINE_VISIBILITY unsigned long long to_ullong() const
{return to_ullong(integral_constant<bool, _Size < sizeof(unsigned long long) * CHAR_BIT>());}
bool all() const _NOEXCEPT;
bool any() const _NOEXCEPT;
_LIBCPP_INLINE_VISIBILITY
size_t __hash_code() const _NOEXCEPT;
private:
#ifdef _LIBCPP_CXX03_LANG
void __init(unsigned long long __v, false_type) _NOEXCEPT;
_LIBCPP_INLINE_VISIBILITY
void __init(unsigned long long __v, true_type) _NOEXCEPT;
#endif // _LIBCPP_CXX03_LANG
unsigned long to_ulong(false_type) const;
_LIBCPP_INLINE_VISIBILITY
unsigned long to_ulong(true_type) const;
unsigned long long to_ullong(false_type) const;
_LIBCPP_INLINE_VISIBILITY
unsigned long long to_ullong(true_type) const;
_LIBCPP_INLINE_VISIBILITY
unsigned long long to_ullong(true_type, false_type) const;
unsigned long long to_ullong(true_type, true_type) const;
};
template <size_t _N_words, size_t _Size>
inline
_LIBCPP_CONSTEXPR
__bitset<_N_words, _Size>::__bitset() _NOEXCEPT
#ifndef _LIBCPP_CXX03_LANG
: __first_{0}
#endif
{
#ifdef _LIBCPP_CXX03_LANG
_VSTD::fill_n(__first_, _N_words, __storage_type(0));
#endif
}
#ifdef _LIBCPP_CXX03_LANG
template <size_t _N_words, size_t _Size>
void
__bitset<_N_words, _Size>::__init(unsigned long long __v, false_type) _NOEXCEPT
{
__storage_type __t[sizeof(unsigned long long) / sizeof(__storage_type)];
size_t __sz = _Size;
for (size_t __i = 0; __i < sizeof(__t)/sizeof(__t[0]); ++__i, __v >>= __bits_per_word, __sz -= __bits_per_word )
if ( __sz < __bits_per_word)
__t[__i] = static_cast<__storage_type>(__v) & ( 1ULL << __sz ) - 1;
else
__t[__i] = static_cast<__storage_type>(__v);
_VSTD::copy(__t, __t + sizeof(__t)/sizeof(__t[0]), __first_);
_VSTD::fill(__first_ + sizeof(__t)/sizeof(__t[0]), __first_ + sizeof(__first_)/sizeof(__first_[0]),
__storage_type(0));
}
template <size_t _N_words, size_t _Size>
inline _LIBCPP_INLINE_VISIBILITY
void
__bitset<_N_words, _Size>::__init(unsigned long long __v, true_type) _NOEXCEPT
{
__first_[0] = __v;
if (_Size < __bits_per_word)
__first_[0] &= ( 1ULL << _Size ) - 1;
_VSTD::fill(__first_ + 1, __first_ + sizeof(__first_)/sizeof(__first_[0]), __storage_type(0));
}
#endif // _LIBCPP_CXX03_LANG
template <size_t _N_words, size_t _Size>
inline
_LIBCPP_CONSTEXPR
__bitset<_N_words, _Size>::__bitset(unsigned long long __v) _NOEXCEPT
#ifndef _LIBCPP_CXX03_LANG
#if __SIZEOF_SIZE_T__ == 8
: __first_{__v}
#elif __SIZEOF_SIZE_T__ == 4
: __first_{static_cast<__storage_type>(__v),
_Size >= 2 * __bits_per_word ? static_cast<__storage_type>(__v >> __bits_per_word)
: static_cast<__storage_type>((__v >> __bits_per_word) & (__storage_type(1) << (_Size - __bits_per_word)) - 1)}
#else
#error This constructor has not been ported to this platform
#endif
#endif
{
#ifdef _LIBCPP_CXX03_LANG
__init(__v, integral_constant<bool, sizeof(unsigned long long) == sizeof(__storage_type)>());
#endif
}
template <size_t _N_words, size_t _Size>
inline
void
__bitset<_N_words, _Size>::operator&=(const __bitset& __v) _NOEXCEPT
{
for (size_type __i = 0; __i < _N_words; ++__i)
__first_[__i] &= __v.__first_[__i];
}
template <size_t _N_words, size_t _Size>
inline
void
__bitset<_N_words, _Size>::operator|=(const __bitset& __v) _NOEXCEPT
{
for (size_type __i = 0; __i < _N_words; ++__i)
__first_[__i] |= __v.__first_[__i];
}
template <size_t _N_words, size_t _Size>
inline
void
__bitset<_N_words, _Size>::operator^=(const __bitset& __v) _NOEXCEPT
{
for (size_type __i = 0; __i < _N_words; ++__i)
__first_[__i] ^= __v.__first_[__i];
}
template <size_t _N_words, size_t _Size>
void
__bitset<_N_words, _Size>::flip() _NOEXCEPT
{
// do middle whole words
size_type __n = _Size;
__storage_pointer __p = __first_;
for (; __n >= __bits_per_word; ++__p, __n -= __bits_per_word)
*__p = ~*__p;
// do last partial word
if (__n > 0)
{
__storage_type __m = ~__storage_type(0) >> (__bits_per_word - __n);
__storage_type __b = *__p & __m;
*__p &= ~__m;
*__p |= ~__b & __m;
}
}
template <size_t _N_words, size_t _Size>
unsigned long
__bitset<_N_words, _Size>::to_ulong(false_type) const
{
const_iterator __e = __make_iter(_Size);
const_iterator __i = _VSTD::find(__make_iter(sizeof(unsigned long) * CHAR_BIT), __e, true);
if (__i != __e)
__throw_overflow_error("bitset to_ulong overflow error");
return __first_[0];
}
template <size_t _N_words, size_t _Size>
inline
unsigned long
__bitset<_N_words, _Size>::to_ulong(true_type) const
{
return __first_[0];
}
template <size_t _N_words, size_t _Size>
unsigned long long
__bitset<_N_words, _Size>::to_ullong(false_type) const
{
const_iterator __e = __make_iter(_Size);
const_iterator __i = _VSTD::find(__make_iter(sizeof(unsigned long long) * CHAR_BIT), __e, true);
if (__i != __e)
__throw_overflow_error("bitset to_ullong overflow error");
return to_ullong(true_type());
}
template <size_t _N_words, size_t _Size>
inline
unsigned long long
__bitset<_N_words, _Size>::to_ullong(true_type) const
{
return to_ullong(true_type(), integral_constant<bool, sizeof(__storage_type) < sizeof(unsigned long long)>());
}
template <size_t _N_words, size_t _Size>
inline
unsigned long long
__bitset<_N_words, _Size>::to_ullong(true_type, false_type) const
{
return __first_[0];
}
template <size_t _N_words, size_t _Size>
unsigned long long
__bitset<_N_words, _Size>::to_ullong(true_type, true_type) const
{
unsigned long long __r = __first_[0];
for (std::size_t __i = 1; __i < sizeof(unsigned long long) / sizeof(__storage_type); ++__i)
__r |= static_cast<unsigned long long>(__first_[__i]) << (sizeof(__storage_type) * CHAR_BIT);
return __r;
}
template <size_t _N_words, size_t _Size>
bool
__bitset<_N_words, _Size>::all() const _NOEXCEPT
{
// do middle whole words
size_type __n = _Size;
__const_storage_pointer __p = __first_;
for (; __n >= __bits_per_word; ++__p, __n -= __bits_per_word)
if (~*__p)
return false;
// do last partial word
if (__n > 0)
{
__storage_type __m = ~__storage_type(0) >> (__bits_per_word - __n);
if (~*__p & __m)
return false;
}
return true;
}
template <size_t _N_words, size_t _Size>
bool
__bitset<_N_words, _Size>::any() const _NOEXCEPT
{
// do middle whole words
size_type __n = _Size;
__const_storage_pointer __p = __first_;
for (; __n >= __bits_per_word; ++__p, __n -= __bits_per_word)
if (*__p)
return true;
// do last partial word
if (__n > 0)
{
__storage_type __m = ~__storage_type(0) >> (__bits_per_word - __n);
if (*__p & __m)
return true;
}
return false;
}
template <size_t _N_words, size_t _Size>
inline
size_t
__bitset<_N_words, _Size>::__hash_code() const _NOEXCEPT
{
size_t __h = 0;
for (size_type __i = 0; __i < _N_words; ++__i)
__h ^= __first_[__i];
return __h;
}
template <size_t _Size>
class __bitset<1, _Size>
{
public:
typedef ptrdiff_t difference_type;
typedef size_t size_type;
typedef size_type __storage_type;
protected:
typedef __bitset __self;
typedef __storage_type* __storage_pointer;
typedef const __storage_type* __const_storage_pointer;
static const unsigned __bits_per_word = static_cast<unsigned>(sizeof(__storage_type) * CHAR_BIT);
friend class __bit_reference<__bitset>;
friend class __bit_const_reference<__bitset>;
friend class __bit_iterator<__bitset, false>;
friend class __bit_iterator<__bitset, true>;
friend struct __bit_array<__bitset>;
__storage_type __first_;
typedef __bit_reference<__bitset> reference;
typedef __bit_const_reference<__bitset> const_reference;
typedef __bit_iterator<__bitset, false> iterator;
typedef __bit_iterator<__bitset, true> const_iterator;
_LIBCPP_INLINE_VISIBILITY
_LIBCPP_CONSTEXPR __bitset() _NOEXCEPT;
_LIBCPP_INLINE_VISIBILITY
explicit _LIBCPP_CONSTEXPR __bitset(unsigned long long __v) _NOEXCEPT;
_LIBCPP_INLINE_VISIBILITY reference __make_ref(size_t __pos) _NOEXCEPT
{return reference(&__first_, __storage_type(1) << __pos);}
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR const_reference __make_ref(size_t __pos) const _NOEXCEPT
{return const_reference(&__first_, __storage_type(1) << __pos);}
_LIBCPP_INLINE_VISIBILITY iterator __make_iter(size_t __pos) _NOEXCEPT
{return iterator(&__first_ + __pos / __bits_per_word, __pos % __bits_per_word);}
_LIBCPP_INLINE_VISIBILITY const_iterator __make_iter(size_t __pos) const _NOEXCEPT
{return const_iterator(&__first_ + __pos / __bits_per_word, __pos % __bits_per_word);}
_LIBCPP_INLINE_VISIBILITY
void operator&=(const __bitset& __v) _NOEXCEPT;
_LIBCPP_INLINE_VISIBILITY
void operator|=(const __bitset& __v) _NOEXCEPT;
_LIBCPP_INLINE_VISIBILITY
void operator^=(const __bitset& __v) _NOEXCEPT;
_LIBCPP_INLINE_VISIBILITY
void flip() _NOEXCEPT;
_LIBCPP_INLINE_VISIBILITY
unsigned long to_ulong() const;
_LIBCPP_INLINE_VISIBILITY
unsigned long long to_ullong() const;
_LIBCPP_INLINE_VISIBILITY
bool all() const _NOEXCEPT;
_LIBCPP_INLINE_VISIBILITY
bool any() const _NOEXCEPT;
_LIBCPP_INLINE_VISIBILITY
size_t __hash_code() const _NOEXCEPT;
};
template <size_t _Size>
inline
_LIBCPP_CONSTEXPR
__bitset<1, _Size>::__bitset() _NOEXCEPT
: __first_(0)
{
}
template <size_t _Size>
inline
_LIBCPP_CONSTEXPR
__bitset<1, _Size>::__bitset(unsigned long long __v) _NOEXCEPT
: __first_(
_Size == __bits_per_word ? static_cast<__storage_type>(__v)
: static_cast<__storage_type>(__v) & ((__storage_type(1) << _Size) - 1)
)
{
}
template <size_t _Size>
inline
void
__bitset<1, _Size>::operator&=(const __bitset& __v) _NOEXCEPT
{
__first_ &= __v.__first_;
}
template <size_t _Size>
inline
void
__bitset<1, _Size>::operator|=(const __bitset& __v) _NOEXCEPT
{
__first_ |= __v.__first_;
}
template <size_t _Size>
inline
void
__bitset<1, _Size>::operator^=(const __bitset& __v) _NOEXCEPT
{
__first_ ^= __v.__first_;
}
template <size_t _Size>
inline
void
__bitset<1, _Size>::flip() _NOEXCEPT
{
__storage_type __m = ~__storage_type(0) >> (__bits_per_word - _Size);
__first_ = ~__first_;
__first_ &= __m;
}
template <size_t _Size>
inline
unsigned long
__bitset<1, _Size>::to_ulong() const
{
return __first_;
}
template <size_t _Size>
inline
unsigned long long
__bitset<1, _Size>::to_ullong() const
{
return __first_;
}
template <size_t _Size>
inline
bool
__bitset<1, _Size>::all() const _NOEXCEPT
{
__storage_type __m = ~__storage_type(0) >> (__bits_per_word - _Size);
return !(~__first_ & __m);
}
template <size_t _Size>
inline
bool
__bitset<1, _Size>::any() const _NOEXCEPT
{
__storage_type __m = ~__storage_type(0) >> (__bits_per_word - _Size);
return __first_ & __m;
}
template <size_t _Size>
inline
size_t
__bitset<1, _Size>::__hash_code() const _NOEXCEPT
{
return __first_;
}
template <>
class __bitset<0, 0>
{
public:
typedef ptrdiff_t difference_type;
typedef size_t size_type;
typedef size_type __storage_type;
protected:
typedef __bitset __self;
typedef __storage_type* __storage_pointer;
typedef const __storage_type* __const_storage_pointer;
static const unsigned __bits_per_word = static_cast<unsigned>(sizeof(__storage_type) * CHAR_BIT);
friend class __bit_reference<__bitset>;
friend class __bit_const_reference<__bitset>;
friend class __bit_iterator<__bitset, false>;
friend class __bit_iterator<__bitset, true>;
friend struct __bit_array<__bitset>;
typedef __bit_reference<__bitset> reference;
typedef __bit_const_reference<__bitset> const_reference;
typedef __bit_iterator<__bitset, false> iterator;
typedef __bit_iterator<__bitset, true> const_iterator;
_LIBCPP_INLINE_VISIBILITY
_LIBCPP_CONSTEXPR __bitset() _NOEXCEPT;
_LIBCPP_INLINE_VISIBILITY
explicit _LIBCPP_CONSTEXPR __bitset(unsigned long long) _NOEXCEPT;
_LIBCPP_INLINE_VISIBILITY reference __make_ref(size_t) _NOEXCEPT
{return reference(0, 1);}
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR const_reference __make_ref(size_t) const _NOEXCEPT
{return const_reference(0, 1);}
_LIBCPP_INLINE_VISIBILITY iterator __make_iter(size_t) _NOEXCEPT
{return iterator(0, 0);}
_LIBCPP_INLINE_VISIBILITY const_iterator __make_iter(size_t) const _NOEXCEPT
{return const_iterator(0, 0);}
_LIBCPP_INLINE_VISIBILITY void operator&=(const __bitset&) _NOEXCEPT {}
_LIBCPP_INLINE_VISIBILITY void operator|=(const __bitset&) _NOEXCEPT {}
_LIBCPP_INLINE_VISIBILITY void operator^=(const __bitset&) _NOEXCEPT {}
_LIBCPP_INLINE_VISIBILITY void flip() _NOEXCEPT {}
_LIBCPP_INLINE_VISIBILITY unsigned long to_ulong() const {return 0;}
_LIBCPP_INLINE_VISIBILITY unsigned long long to_ullong() const {return 0;}
_LIBCPP_INLINE_VISIBILITY bool all() const _NOEXCEPT {return true;}
_LIBCPP_INLINE_VISIBILITY bool any() const _NOEXCEPT {return false;}
_LIBCPP_INLINE_VISIBILITY size_t __hash_code() const _NOEXCEPT {return 0;}
};
inline
_LIBCPP_CONSTEXPR
__bitset<0, 0>::__bitset() _NOEXCEPT
{
}
inline
_LIBCPP_CONSTEXPR
__bitset<0, 0>::__bitset(unsigned long long) _NOEXCEPT
{
}
template <size_t _Size> class _LIBCPP_TEMPLATE_VIS bitset;
template <size_t _Size> struct hash<bitset<_Size> >;
template <size_t _Size>
class _LIBCPP_TEMPLATE_VIS bitset
: private __bitset<_Size == 0 ? 0 : (_Size - 1) / (sizeof(size_t) * CHAR_BIT) + 1, _Size>
{
public:
static const unsigned __n_words = _Size == 0 ? 0 : (_Size - 1) / (sizeof(size_t) * CHAR_BIT) + 1;
typedef __bitset<__n_words, _Size> base;
public:
typedef typename base::reference reference;
typedef typename base::const_reference const_reference;
// 23.3.5.1 constructors:
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR bitset() _NOEXCEPT {}
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
bitset(unsigned long long __v) _NOEXCEPT : base(__v) {}
template<class _CharT, class = _EnableIf<_IsCharLikeType<_CharT>::value> >
explicit bitset(const _CharT* __str,
typename basic_string<_CharT>::size_type __n = basic_string<_CharT>::npos,
_CharT __zero = _CharT('0'), _CharT __one = _CharT('1'));
template<class _CharT, class _Traits, class _Allocator>
explicit bitset(const basic_string<_CharT,_Traits,_Allocator>& __str,
typename basic_string<_CharT,_Traits,_Allocator>::size_type __pos = 0,
typename basic_string<_CharT,_Traits,_Allocator>::size_type __n =
(basic_string<_CharT,_Traits,_Allocator>::npos),
_CharT __zero = _CharT('0'), _CharT __one = _CharT('1'));
// 23.3.5.2 bitset operations:
_LIBCPP_INLINE_VISIBILITY
bitset& operator&=(const bitset& __rhs) _NOEXCEPT;
_LIBCPP_INLINE_VISIBILITY
bitset& operator|=(const bitset& __rhs) _NOEXCEPT;
_LIBCPP_INLINE_VISIBILITY
bitset& operator^=(const bitset& __rhs) _NOEXCEPT;
bitset& operator<<=(size_t __pos) _NOEXCEPT;
bitset& operator>>=(size_t __pos) _NOEXCEPT;
_LIBCPP_INLINE_VISIBILITY
bitset& set() _NOEXCEPT;
bitset& set(size_t __pos, bool __val = true);
_LIBCPP_INLINE_VISIBILITY
bitset& reset() _NOEXCEPT;
bitset& reset(size_t __pos);
_LIBCPP_INLINE_VISIBILITY
bitset operator~() const _NOEXCEPT;
_LIBCPP_INLINE_VISIBILITY
bitset& flip() _NOEXCEPT;
bitset& flip(size_t __pos);
// element access:
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
const_reference operator[](size_t __p) const {return base::__make_ref(__p);}
_LIBCPP_INLINE_VISIBILITY reference operator[](size_t __p) {return base::__make_ref(__p);}
_LIBCPP_INLINE_VISIBILITY
unsigned long to_ulong() const;
_LIBCPP_INLINE_VISIBILITY
unsigned long long to_ullong() const;
template <class _CharT, class _Traits, class _Allocator>
basic_string<_CharT, _Traits, _Allocator> to_string(_CharT __zero = _CharT('0'),
_CharT __one = _CharT('1')) const;
template <class _CharT, class _Traits>
_LIBCPP_INLINE_VISIBILITY
basic_string<_CharT, _Traits, allocator<_CharT> > to_string(_CharT __zero = _CharT('0'),
_CharT __one = _CharT('1')) const;
template <class _CharT>
_LIBCPP_INLINE_VISIBILITY
basic_string<_CharT, char_traits<_CharT>, allocator<_CharT> > to_string(_CharT __zero = _CharT('0'),
_CharT __one = _CharT('1')) const;
_LIBCPP_INLINE_VISIBILITY
basic_string<char, char_traits<char>, allocator<char> > to_string(char __zero = '0',
char __one = '1') const;
_LIBCPP_INLINE_VISIBILITY
size_t count() const _NOEXCEPT;
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR size_t size() const _NOEXCEPT {return _Size;}
_LIBCPP_INLINE_VISIBILITY
bool operator==(const bitset& __rhs) const _NOEXCEPT;
_LIBCPP_INLINE_VISIBILITY
bool operator!=(const bitset& __rhs) const _NOEXCEPT;
bool test(size_t __pos) const;
_LIBCPP_INLINE_VISIBILITY
bool all() const _NOEXCEPT;
_LIBCPP_INLINE_VISIBILITY
bool any() const _NOEXCEPT;
_LIBCPP_INLINE_VISIBILITY bool none() const _NOEXCEPT {return !any();}
_LIBCPP_INLINE_VISIBILITY
bitset operator<<(size_t __pos) const _NOEXCEPT;
_LIBCPP_INLINE_VISIBILITY
bitset operator>>(size_t __pos) const _NOEXCEPT;
private:
_LIBCPP_INLINE_VISIBILITY
size_t __hash_code() const _NOEXCEPT {return base::__hash_code();}
friend struct hash<bitset>;
};
template <size_t _Size>
template<class _CharT, class>
bitset<_Size>::bitset(const _CharT* __str,
typename basic_string<_CharT>::size_type __n,
_CharT __zero, _CharT __one)
{
size_t __rlen = _VSTD::min(__n, char_traits<_CharT>::length(__str));
for (size_t __i = 0; __i < __rlen; ++__i)
if (__str[__i] != __zero && __str[__i] != __one)
__throw_invalid_argument("bitset string ctor has invalid argument");
size_t _Mp = _VSTD::min(__rlen, _Size);
size_t __i = 0;
for (; __i < _Mp; ++__i)
{
_CharT __c = __str[_Mp - 1 - __i];
if (__c == __zero)
(*this)[__i] = false;
else
(*this)[__i] = true;
}
_VSTD::fill(base::__make_iter(__i), base::__make_iter(_Size), false);
}
template <size_t _Size>
template<class _CharT, class _Traits, class _Allocator>
bitset<_Size>::bitset(const basic_string<_CharT,_Traits,_Allocator>& __str,
typename basic_string<_CharT,_Traits,_Allocator>::size_type __pos,
typename basic_string<_CharT,_Traits,_Allocator>::size_type __n,
_CharT __zero, _CharT __one)
{
if (__pos > __str.size())
__throw_out_of_range("bitset string pos out of range");
size_t __rlen = _VSTD::min(__n, __str.size() - __pos);
for (size_t __i = __pos; __i < __pos + __rlen; ++__i)
if (!_Traits::eq(__str[__i], __zero) && !_Traits::eq(__str[__i], __one))
__throw_invalid_argument("bitset string ctor has invalid argument");
size_t _Mp = _VSTD::min(__rlen, _Size);
size_t __i = 0;
for (; __i < _Mp; ++__i)
{
_CharT __c = __str[__pos + _Mp - 1 - __i];
if (_Traits::eq(__c, __zero))
(*this)[__i] = false;
else
(*this)[__i] = true;
}
_VSTD::fill(base::__make_iter(__i), base::__make_iter(_Size), false);
}
template <size_t _Size>
inline
bitset<_Size>&
bitset<_Size>::operator&=(const bitset& __rhs) _NOEXCEPT
{
base::operator&=(__rhs);
return *this;
}
template <size_t _Size>
inline
bitset<_Size>&
bitset<_Size>::operator|=(const bitset& __rhs) _NOEXCEPT
{
base::operator|=(__rhs);
return *this;
}
template <size_t _Size>
inline
bitset<_Size>&
bitset<_Size>::operator^=(const bitset& __rhs) _NOEXCEPT
{
base::operator^=(__rhs);
return *this;
}
template <size_t _Size>
bitset<_Size>&
bitset<_Size>::operator<<=(size_t __pos) _NOEXCEPT
{
__pos = _VSTD::min(__pos, _Size);
_VSTD::copy_backward(base::__make_iter(0), base::__make_iter(_Size - __pos), base::__make_iter(_Size));
_VSTD::fill_n(base::__make_iter(0), __pos, false);
return *this;
}
template <size_t _Size>
bitset<_Size>&
bitset<_Size>::operator>>=(size_t __pos) _NOEXCEPT
{
__pos = _VSTD::min(__pos, _Size);
_VSTD::copy(base::__make_iter(__pos), base::__make_iter(_Size), base::__make_iter(0));
_VSTD::fill_n(base::__make_iter(_Size - __pos), __pos, false);
return *this;
}
template <size_t _Size>
inline
bitset<_Size>&
bitset<_Size>::set() _NOEXCEPT
{
_VSTD::fill_n(base::__make_iter(0), _Size, true);
return *this;
}
template <size_t _Size>
bitset<_Size>&
bitset<_Size>::set(size_t __pos, bool __val)
{
if (__pos >= _Size)
__throw_out_of_range("bitset set argument out of range");
(*this)[__pos] = __val;
return *this;
}
template <size_t _Size>
inline
bitset<_Size>&
bitset<_Size>::reset() _NOEXCEPT
{
_VSTD::fill_n(base::__make_iter(0), _Size, false);
return *this;
}
template <size_t _Size>
bitset<_Size>&
bitset<_Size>::reset(size_t __pos)
{
if (__pos >= _Size)
__throw_out_of_range("bitset reset argument out of range");
(*this)[__pos] = false;
return *this;
}
template <size_t _Size>
inline
bitset<_Size>
bitset<_Size>::operator~() const _NOEXCEPT
{
bitset __x(*this);
__x.flip();
return __x;
}
template <size_t _Size>
inline
bitset<_Size>&
bitset<_Size>::flip() _NOEXCEPT
{
base::flip();
return *this;
}
template <size_t _Size>
bitset<_Size>&
bitset<_Size>::flip(size_t __pos)
{
if (__pos >= _Size)
__throw_out_of_range("bitset flip argument out of range");
reference r = base::__make_ref(__pos);
r = ~r;
return *this;
}
template <size_t _Size>
inline
unsigned long
bitset<_Size>::to_ulong() const
{
return base::to_ulong();
}
template <size_t _Size>
inline
unsigned long long
bitset<_Size>::to_ullong() const
{
return base::to_ullong();
}
template <size_t _Size>
template <class _CharT, class _Traits, class _Allocator>
basic_string<_CharT, _Traits, _Allocator>
bitset<_Size>::to_string(_CharT __zero, _CharT __one) const
{
basic_string<_CharT, _Traits, _Allocator> __r(_Size, __zero);
for (size_t __i = 0; __i < _Size; ++__i)
{
if ((*this)[__i])
__r[_Size - 1 - __i] = __one;
}
return __r;
}
template <size_t _Size>
template <class _CharT, class _Traits>
inline
basic_string<_CharT, _Traits, allocator<_CharT> >
bitset<_Size>::to_string(_CharT __zero, _CharT __one) const
{
return to_string<_CharT, _Traits, allocator<_CharT> >(__zero, __one);
}
template <size_t _Size>
template <class _CharT>
inline
basic_string<_CharT, char_traits<_CharT>, allocator<_CharT> >
bitset<_Size>::to_string(_CharT __zero, _CharT __one) const
{
return to_string<_CharT, char_traits<_CharT>, allocator<_CharT> >(__zero, __one);
}
template <size_t _Size>
inline
basic_string<char, char_traits<char>, allocator<char> >
bitset<_Size>::to_string(char __zero, char __one) const
{
return to_string<char, char_traits<char>, allocator<char> >(__zero, __one);
}
template <size_t _Size>
inline
size_t
bitset<_Size>::count() const _NOEXCEPT
{
return static_cast<size_t>(__count_bool_true(base::__make_iter(0), _Size));
}
template <size_t _Size>
inline
bool
bitset<_Size>::operator==(const bitset& __rhs) const _NOEXCEPT
{
return _VSTD::equal(base::__make_iter(0), base::__make_iter(_Size), __rhs.__make_iter(0));
}
template <size_t _Size>
inline
bool
bitset<_Size>::operator!=(const bitset& __rhs) const _NOEXCEPT
{
return !(*this == __rhs);
}
template <size_t _Size>
bool
bitset<_Size>::test(size_t __pos) const
{
if (__pos >= _Size)
__throw_out_of_range("bitset test argument out of range");
return (*this)[__pos];
}
template <size_t _Size>
inline
bool
bitset<_Size>::all() const _NOEXCEPT
{
return base::all();
}
template <size_t _Size>
inline
bool
bitset<_Size>::any() const _NOEXCEPT
{
return base::any();
}
template <size_t _Size>
inline
bitset<_Size>
bitset<_Size>::operator<<(size_t __pos) const _NOEXCEPT
{
bitset __r = *this;
__r <<= __pos;
return __r;
}
template <size_t _Size>
inline
bitset<_Size>
bitset<_Size>::operator>>(size_t __pos) const _NOEXCEPT
{
bitset __r = *this;
__r >>= __pos;
return __r;
}
template <size_t _Size>
inline _LIBCPP_INLINE_VISIBILITY
bitset<_Size>
operator&(const bitset<_Size>& __x, const bitset<_Size>& __y) _NOEXCEPT
{
bitset<_Size> __r = __x;
__r &= __y;
return __r;
}
template <size_t _Size>
inline _LIBCPP_INLINE_VISIBILITY
bitset<_Size>
operator|(const bitset<_Size>& __x, const bitset<_Size>& __y) _NOEXCEPT
{
bitset<_Size> __r = __x;
__r |= __y;
return __r;
}
template <size_t _Size>
inline _LIBCPP_INLINE_VISIBILITY
bitset<_Size>
operator^(const bitset<_Size>& __x, const bitset<_Size>& __y) _NOEXCEPT
{
bitset<_Size> __r = __x;
__r ^= __y;
return __r;
}
template <size_t _Size>
struct _LIBCPP_TEMPLATE_VIS hash<bitset<_Size> >
: public unary_function<bitset<_Size>, size_t>
{
_LIBCPP_INLINE_VISIBILITY
size_t operator()(const bitset<_Size>& __bs) const _NOEXCEPT
{return __bs.__hash_code();}
};
template <class _CharT, class _Traits, size_t _Size>
basic_istream<_CharT, _Traits>&
operator>>(basic_istream<_CharT, _Traits>& __is, bitset<_Size>& __x);
template <class _CharT, class _Traits, size_t _Size>
basic_ostream<_CharT, _Traits>&
operator<<(basic_ostream<_CharT, _Traits>& __os, const bitset<_Size>& __x);
_LIBCPP_END_NAMESPACE_STD
_LIBCPP_POP_MACROS
#endif // _LIBCPP_BITSET
| 33,965 | 1,110 | jart/cosmopolitan | false |
cosmopolitan/third_party/libcxx/locale2.cc | // clang-format off
//===------------------------- locale.cpp ---------------------------------===//
//
// 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
//
//===----------------------------------------------------------------------===//
#include "third_party/libcxx/string"
#include "third_party/libcxx/locale"
#include "third_party/libcxx/codecvt"
#include "third_party/libcxx/vector"
#include "third_party/libcxx/algorithm"
#include "third_party/libcxx/typeinfo"
#ifndef _LIBCPP_NO_EXCEPTIONS
#include "third_party/libcxx/type_traits"
#endif
#include "third_party/libcxx/clocale"
#include "third_party/libcxx/cstring"
#include "third_party/libcxx/cwctype"
#include "third_party/libcxx/__sso_allocator"
#include "third_party/libcxx/include/atomic_support.hh"
#include "libc/str/locale.h"
#include "third_party/libcxx/countof.internal.hh"
#include "third_party/libcxx/__undef_macros"
// On Linux, wint_t and wchar_t have different signed-ness, and this causes
// lots of noise in the build log, but no bugs that I know of.
#if defined(__clang__)
#pragma clang diagnostic ignored "-Wsign-conversion"
#endif
_LIBCPP_BEGIN_NAMESPACE_STD
namespace {
_LIBCPP_NORETURN static void __throw_runtime_error(const string &msg)
{
#ifndef _LIBCPP_NO_EXCEPTIONS
throw runtime_error(msg);
#else
(void)msg;
_VSTD::abort();
#endif
}
} // namespace
struct __libcpp_unique_locale {
__libcpp_unique_locale(const char* nm) : __loc_(newlocale(LC_ALL_MASK, nm, 0)) {}
~__libcpp_unique_locale() {
if (__loc_)
freelocale(__loc_);
}
explicit operator bool() const { return __loc_; }
locale_t& get() { return __loc_; }
locale_t __loc_;
private:
__libcpp_unique_locale(__libcpp_unique_locale const&);
__libcpp_unique_locale& operator=(__libcpp_unique_locale const&);
};
// Valid UTF ranges
// UTF-32 UTF-16 UTF-8 # of code points
// first second first second third fourth
// 000000 - 00007F 0000 - 007F 00 - 7F 127
// 000080 - 0007FF 0080 - 07FF C2 - DF, 80 - BF 1920
// 000800 - 000FFF 0800 - 0FFF E0 - E0, A0 - BF, 80 - BF 2048
// 001000 - 00CFFF 1000 - CFFF E1 - EC, 80 - BF, 80 - BF 49152
// 00D000 - 00D7FF D000 - D7FF ED - ED, 80 - 9F, 80 - BF 2048
// 00D800 - 00DFFF invalid
// 00E000 - 00FFFF E000 - FFFF EE - EF, 80 - BF, 80 - BF 8192
// 010000 - 03FFFF D800 - D8BF, DC00 - DFFF F0 - F0, 90 - BF, 80 - BF, 80 - BF 196608
// 040000 - 0FFFFF D8C0 - DBBF, DC00 - DFFF F1 - F3, 80 - BF, 80 - BF, 80 - BF 786432
// 100000 - 10FFFF DBC0 - DBFF, DC00 - DFFF F4 - F4, 80 - 8F, 80 - BF, 80 - BF 65536
static
codecvt_base::result
utf16_to_utf8(const uint16_t* frm, const uint16_t* frm_end, const uint16_t*& frm_nxt,
uint8_t* to, uint8_t* to_end, uint8_t*& to_nxt,
unsigned long Maxcode = 0x10FFFF, codecvt_mode mode = codecvt_mode(0))
{
frm_nxt = frm;
to_nxt = to;
if (mode & generate_header)
{
if (to_end-to_nxt < 3)
return codecvt_base::partial;
*to_nxt++ = static_cast<uint8_t>(0xEF);
*to_nxt++ = static_cast<uint8_t>(0xBB);
*to_nxt++ = static_cast<uint8_t>(0xBF);
}
for (; frm_nxt < frm_end; ++frm_nxt)
{
uint16_t wc1 = *frm_nxt;
if (wc1 > Maxcode)
return codecvt_base::error;
if (wc1 < 0x0080)
{
if (to_end-to_nxt < 1)
return codecvt_base::partial;
*to_nxt++ = static_cast<uint8_t>(wc1);
}
else if (wc1 < 0x0800)
{
if (to_end-to_nxt < 2)
return codecvt_base::partial;
*to_nxt++ = static_cast<uint8_t>(0xC0 | (wc1 >> 6));
*to_nxt++ = static_cast<uint8_t>(0x80 | (wc1 & 0x03F));
}
else if (wc1 < 0xD800)
{
if (to_end-to_nxt < 3)
return codecvt_base::partial;
*to_nxt++ = static_cast<uint8_t>(0xE0 | (wc1 >> 12));
*to_nxt++ = static_cast<uint8_t>(0x80 | ((wc1 & 0x0FC0) >> 6));
*to_nxt++ = static_cast<uint8_t>(0x80 | (wc1 & 0x003F));
}
else if (wc1 < 0xDC00)
{
if (frm_end-frm_nxt < 2)
return codecvt_base::partial;
uint16_t wc2 = frm_nxt[1];
if ((wc2 & 0xFC00) != 0xDC00)
return codecvt_base::error;
if (to_end-to_nxt < 4)
return codecvt_base::partial;
if (((((wc1 & 0x03C0UL) >> 6) + 1) << 16) +
((wc1 & 0x003FUL) << 10) + (wc2 & 0x03FF) > Maxcode)
return codecvt_base::error;
++frm_nxt;
uint8_t z = ((wc1 & 0x03C0) >> 6) + 1;
*to_nxt++ = static_cast<uint8_t>(0xF0 | (z >> 2));
*to_nxt++ = static_cast<uint8_t>(0x80 | ((z & 0x03) << 4) | ((wc1 & 0x003C) >> 2));
*to_nxt++ = static_cast<uint8_t>(0x80 | ((wc1 & 0x0003) << 4) | ((wc2 & 0x03C0) >> 6));
*to_nxt++ = static_cast<uint8_t>(0x80 | (wc2 & 0x003F));
}
else if (wc1 < 0xE000)
{
return codecvt_base::error;
}
else
{
if (to_end-to_nxt < 3)
return codecvt_base::partial;
*to_nxt++ = static_cast<uint8_t>(0xE0 | (wc1 >> 12));
*to_nxt++ = static_cast<uint8_t>(0x80 | ((wc1 & 0x0FC0) >> 6));
*to_nxt++ = static_cast<uint8_t>(0x80 | (wc1 & 0x003F));
}
}
return codecvt_base::ok;
}
static
codecvt_base::result
utf16_to_utf8(const uint32_t* frm, const uint32_t* frm_end, const uint32_t*& frm_nxt,
uint8_t* to, uint8_t* to_end, uint8_t*& to_nxt,
unsigned long Maxcode = 0x10FFFF, codecvt_mode mode = codecvt_mode(0))
{
frm_nxt = frm;
to_nxt = to;
if (mode & generate_header)
{
if (to_end-to_nxt < 3)
return codecvt_base::partial;
*to_nxt++ = static_cast<uint8_t>(0xEF);
*to_nxt++ = static_cast<uint8_t>(0xBB);
*to_nxt++ = static_cast<uint8_t>(0xBF);
}
for (; frm_nxt < frm_end; ++frm_nxt)
{
uint16_t wc1 = static_cast<uint16_t>(*frm_nxt);
if (wc1 > Maxcode)
return codecvt_base::error;
if (wc1 < 0x0080)
{
if (to_end-to_nxt < 1)
return codecvt_base::partial;
*to_nxt++ = static_cast<uint8_t>(wc1);
}
else if (wc1 < 0x0800)
{
if (to_end-to_nxt < 2)
return codecvt_base::partial;
*to_nxt++ = static_cast<uint8_t>(0xC0 | (wc1 >> 6));
*to_nxt++ = static_cast<uint8_t>(0x80 | (wc1 & 0x03F));
}
else if (wc1 < 0xD800)
{
if (to_end-to_nxt < 3)
return codecvt_base::partial;
*to_nxt++ = static_cast<uint8_t>(0xE0 | (wc1 >> 12));
*to_nxt++ = static_cast<uint8_t>(0x80 | ((wc1 & 0x0FC0) >> 6));
*to_nxt++ = static_cast<uint8_t>(0x80 | (wc1 & 0x003F));
}
else if (wc1 < 0xDC00)
{
if (frm_end-frm_nxt < 2)
return codecvt_base::partial;
uint16_t wc2 = static_cast<uint16_t>(frm_nxt[1]);
if ((wc2 & 0xFC00) != 0xDC00)
return codecvt_base::error;
if (to_end-to_nxt < 4)
return codecvt_base::partial;
if (((((wc1 & 0x03C0UL) >> 6) + 1) << 16) +
((wc1 & 0x003FUL) << 10) + (wc2 & 0x03FF) > Maxcode)
return codecvt_base::error;
++frm_nxt;
uint8_t z = ((wc1 & 0x03C0) >> 6) + 1;
*to_nxt++ = static_cast<uint8_t>(0xF0 | (z >> 2));
*to_nxt++ = static_cast<uint8_t>(0x80 | ((z & 0x03) << 4) | ((wc1 & 0x003C) >> 2));
*to_nxt++ = static_cast<uint8_t>(0x80 | ((wc1 & 0x0003) << 4) | ((wc2 & 0x03C0) >> 6));
*to_nxt++ = static_cast<uint8_t>(0x80 | (wc2 & 0x003F));
}
else if (wc1 < 0xE000)
{
return codecvt_base::error;
}
else
{
if (to_end-to_nxt < 3)
return codecvt_base::partial;
*to_nxt++ = static_cast<uint8_t>(0xE0 | (wc1 >> 12));
*to_nxt++ = static_cast<uint8_t>(0x80 | ((wc1 & 0x0FC0) >> 6));
*to_nxt++ = static_cast<uint8_t>(0x80 | (wc1 & 0x003F));
}
}
return codecvt_base::ok;
}
static
codecvt_base::result
utf8_to_utf16(const uint8_t* frm, const uint8_t* frm_end, const uint8_t*& frm_nxt,
uint16_t* to, uint16_t* to_end, uint16_t*& to_nxt,
unsigned long Maxcode = 0x10FFFF, codecvt_mode mode = codecvt_mode(0))
{
frm_nxt = frm;
to_nxt = to;
if (mode & consume_header)
{
if (frm_end-frm_nxt >= 3 && frm_nxt[0] == 0xEF && frm_nxt[1] == 0xBB &&
frm_nxt[2] == 0xBF)
frm_nxt += 3;
}
for (; frm_nxt < frm_end && to_nxt < to_end; ++to_nxt)
{
uint8_t c1 = *frm_nxt;
if (c1 > Maxcode)
return codecvt_base::error;
if (c1 < 0x80)
{
*to_nxt = static_cast<uint16_t>(c1);
++frm_nxt;
}
else if (c1 < 0xC2)
{
return codecvt_base::error;
}
else if (c1 < 0xE0)
{
if (frm_end-frm_nxt < 2)
return codecvt_base::partial;
uint8_t c2 = frm_nxt[1];
if ((c2 & 0xC0) != 0x80)
return codecvt_base::error;
uint16_t t = static_cast<uint16_t>(((c1 & 0x1F) << 6) | (c2 & 0x3F));
if (t > Maxcode)
return codecvt_base::error;
*to_nxt = t;
frm_nxt += 2;
}
else if (c1 < 0xF0)
{
if (frm_end-frm_nxt < 3)
return codecvt_base::partial;
uint8_t c2 = frm_nxt[1];
uint8_t c3 = frm_nxt[2];
switch (c1)
{
case 0xE0:
if ((c2 & 0xE0) != 0xA0)
return codecvt_base::error;
break;
case 0xED:
if ((c2 & 0xE0) != 0x80)
return codecvt_base::error;
break;
default:
if ((c2 & 0xC0) != 0x80)
return codecvt_base::error;
break;
}
if ((c3 & 0xC0) != 0x80)
return codecvt_base::error;
uint16_t t = static_cast<uint16_t>(((c1 & 0x0F) << 12)
| ((c2 & 0x3F) << 6)
| (c3 & 0x3F));
if (t > Maxcode)
return codecvt_base::error;
*to_nxt = t;
frm_nxt += 3;
}
else if (c1 < 0xF5)
{
if (frm_end-frm_nxt < 4)
return codecvt_base::partial;
uint8_t c2 = frm_nxt[1];
uint8_t c3 = frm_nxt[2];
uint8_t c4 = frm_nxt[3];
switch (c1)
{
case 0xF0:
if (!(0x90 <= c2 && c2 <= 0xBF))
return codecvt_base::error;
break;
case 0xF4:
if ((c2 & 0xF0) != 0x80)
return codecvt_base::error;
break;
default:
if ((c2 & 0xC0) != 0x80)
return codecvt_base::error;
break;
}
if ((c3 & 0xC0) != 0x80 || (c4 & 0xC0) != 0x80)
return codecvt_base::error;
if (to_end-to_nxt < 2)
return codecvt_base::partial;
if ((((c1 & 7UL) << 18) +
((c2 & 0x3FUL) << 12) +
((c3 & 0x3FUL) << 6) + (c4 & 0x3F)) > Maxcode)
return codecvt_base::error;
*to_nxt = static_cast<uint16_t>(
0xD800
| (((((c1 & 0x07) << 2) | ((c2 & 0x30) >> 4)) - 1) << 6)
| ((c2 & 0x0F) << 2)
| ((c3 & 0x30) >> 4));
*++to_nxt = static_cast<uint16_t>(
0xDC00
| ((c3 & 0x0F) << 6)
| (c4 & 0x3F));
frm_nxt += 4;
}
else
{
return codecvt_base::error;
}
}
return frm_nxt < frm_end ? codecvt_base::partial : codecvt_base::ok;
}
static
codecvt_base::result
utf8_to_utf16(const uint8_t* frm, const uint8_t* frm_end, const uint8_t*& frm_nxt,
uint32_t* to, uint32_t* to_end, uint32_t*& to_nxt,
unsigned long Maxcode = 0x10FFFF, codecvt_mode mode = codecvt_mode(0))
{
frm_nxt = frm;
to_nxt = to;
if (mode & consume_header)
{
if (frm_end-frm_nxt >= 3 && frm_nxt[0] == 0xEF && frm_nxt[1] == 0xBB &&
frm_nxt[2] == 0xBF)
frm_nxt += 3;
}
for (; frm_nxt < frm_end && to_nxt < to_end; ++to_nxt)
{
uint8_t c1 = *frm_nxt;
if (c1 > Maxcode)
return codecvt_base::error;
if (c1 < 0x80)
{
*to_nxt = static_cast<uint32_t>(c1);
++frm_nxt;
}
else if (c1 < 0xC2)
{
return codecvt_base::error;
}
else if (c1 < 0xE0)
{
if (frm_end-frm_nxt < 2)
return codecvt_base::partial;
uint8_t c2 = frm_nxt[1];
if ((c2 & 0xC0) != 0x80)
return codecvt_base::error;
uint16_t t = static_cast<uint16_t>(((c1 & 0x1F) << 6) | (c2 & 0x3F));
if (t > Maxcode)
return codecvt_base::error;
*to_nxt = static_cast<uint32_t>(t);
frm_nxt += 2;
}
else if (c1 < 0xF0)
{
if (frm_end-frm_nxt < 3)
return codecvt_base::partial;
uint8_t c2 = frm_nxt[1];
uint8_t c3 = frm_nxt[2];
switch (c1)
{
case 0xE0:
if ((c2 & 0xE0) != 0xA0)
return codecvt_base::error;
break;
case 0xED:
if ((c2 & 0xE0) != 0x80)
return codecvt_base::error;
break;
default:
if ((c2 & 0xC0) != 0x80)
return codecvt_base::error;
break;
}
if ((c3 & 0xC0) != 0x80)
return codecvt_base::error;
uint16_t t = static_cast<uint16_t>(((c1 & 0x0F) << 12)
| ((c2 & 0x3F) << 6)
| (c3 & 0x3F));
if (t > Maxcode)
return codecvt_base::error;
*to_nxt = static_cast<uint32_t>(t);
frm_nxt += 3;
}
else if (c1 < 0xF5)
{
if (frm_end-frm_nxt < 4)
return codecvt_base::partial;
uint8_t c2 = frm_nxt[1];
uint8_t c3 = frm_nxt[2];
uint8_t c4 = frm_nxt[3];
switch (c1)
{
case 0xF0:
if (!(0x90 <= c2 && c2 <= 0xBF))
return codecvt_base::error;
break;
case 0xF4:
if ((c2 & 0xF0) != 0x80)
return codecvt_base::error;
break;
default:
if ((c2 & 0xC0) != 0x80)
return codecvt_base::error;
break;
}
if ((c3 & 0xC0) != 0x80 || (c4 & 0xC0) != 0x80)
return codecvt_base::error;
if (to_end-to_nxt < 2)
return codecvt_base::partial;
if ((((c1 & 7UL) << 18) +
((c2 & 0x3FUL) << 12) +
((c3 & 0x3FUL) << 6) + (c4 & 0x3F)) > Maxcode)
return codecvt_base::error;
*to_nxt = static_cast<uint32_t>(
0xD800
| (((((c1 & 0x07) << 2) | ((c2 & 0x30) >> 4)) - 1) << 6)
| ((c2 & 0x0F) << 2)
| ((c3 & 0x30) >> 4));
*++to_nxt = static_cast<uint32_t>(
0xDC00
| ((c3 & 0x0F) << 6)
| (c4 & 0x3F));
frm_nxt += 4;
}
else
{
return codecvt_base::error;
}
}
return frm_nxt < frm_end ? codecvt_base::partial : codecvt_base::ok;
}
static
int
utf8_to_utf16_length(const uint8_t* frm, const uint8_t* frm_end,
size_t mx, unsigned long Maxcode = 0x10FFFF,
codecvt_mode mode = codecvt_mode(0))
{
const uint8_t* frm_nxt = frm;
if (mode & consume_header)
{
if (frm_end-frm_nxt >= 3 && frm_nxt[0] == 0xEF && frm_nxt[1] == 0xBB &&
frm_nxt[2] == 0xBF)
frm_nxt += 3;
}
for (size_t nchar16_t = 0; frm_nxt < frm_end && nchar16_t < mx; ++nchar16_t)
{
uint8_t c1 = *frm_nxt;
if (c1 > Maxcode)
break;
if (c1 < 0x80)
{
++frm_nxt;
}
else if (c1 < 0xC2)
{
break;
}
else if (c1 < 0xE0)
{
if ((frm_end-frm_nxt < 2) || (frm_nxt[1] & 0xC0) != 0x80)
break;
uint16_t t = static_cast<uint16_t>(((c1 & 0x1F) << 6) | (frm_nxt[1] & 0x3F));
if (t > Maxcode)
break;
frm_nxt += 2;
}
else if (c1 < 0xF0)
{
if (frm_end-frm_nxt < 3)
break;
uint8_t c2 = frm_nxt[1];
uint8_t c3 = frm_nxt[2];
switch (c1)
{
case 0xE0:
if ((c2 & 0xE0) != 0xA0)
return static_cast<int>(frm_nxt - frm);
break;
case 0xED:
if ((c2 & 0xE0) != 0x80)
return static_cast<int>(frm_nxt - frm);
break;
default:
if ((c2 & 0xC0) != 0x80)
return static_cast<int>(frm_nxt - frm);
break;
}
if ((c3 & 0xC0) != 0x80)
break;
if ((((c1 & 0x0Fu) << 12) | ((c2 & 0x3Fu) << 6) | (c3 & 0x3Fu)) > Maxcode)
break;
frm_nxt += 3;
}
else if (c1 < 0xF5)
{
if (frm_end-frm_nxt < 4 || mx-nchar16_t < 2)
break;
uint8_t c2 = frm_nxt[1];
uint8_t c3 = frm_nxt[2];
uint8_t c4 = frm_nxt[3];
switch (c1)
{
case 0xF0:
if (!(0x90 <= c2 && c2 <= 0xBF))
return static_cast<int>(frm_nxt - frm);
break;
case 0xF4:
if ((c2 & 0xF0) != 0x80)
return static_cast<int>(frm_nxt - frm);
break;
default:
if ((c2 & 0xC0) != 0x80)
return static_cast<int>(frm_nxt - frm);
break;
}
if ((c3 & 0xC0) != 0x80 || (c4 & 0xC0) != 0x80)
break;
if ((((c1 & 7UL) << 18) +
((c2 & 0x3FUL) << 12) +
((c3 & 0x3FUL) << 6) + (c4 & 0x3F)) > Maxcode)
break;
++nchar16_t;
frm_nxt += 4;
}
else
{
break;
}
}
return static_cast<int>(frm_nxt - frm);
}
static
codecvt_base::result
ucs4_to_utf8(const uint32_t* frm, const uint32_t* frm_end, const uint32_t*& frm_nxt,
uint8_t* to, uint8_t* to_end, uint8_t*& to_nxt,
unsigned long Maxcode = 0x10FFFF, codecvt_mode mode = codecvt_mode(0))
{
frm_nxt = frm;
to_nxt = to;
if (mode & generate_header)
{
if (to_end-to_nxt < 3)
return codecvt_base::partial;
*to_nxt++ = static_cast<uint8_t>(0xEF);
*to_nxt++ = static_cast<uint8_t>(0xBB);
*to_nxt++ = static_cast<uint8_t>(0xBF);
}
for (; frm_nxt < frm_end; ++frm_nxt)
{
uint32_t wc = *frm_nxt;
if ((wc & 0xFFFFF800) == 0x00D800 || wc > Maxcode)
return codecvt_base::error;
if (wc < 0x000080)
{
if (to_end-to_nxt < 1)
return codecvt_base::partial;
*to_nxt++ = static_cast<uint8_t>(wc);
}
else if (wc < 0x000800)
{
if (to_end-to_nxt < 2)
return codecvt_base::partial;
*to_nxt++ = static_cast<uint8_t>(0xC0 | (wc >> 6));
*to_nxt++ = static_cast<uint8_t>(0x80 | (wc & 0x03F));
}
else if (wc < 0x010000)
{
if (to_end-to_nxt < 3)
return codecvt_base::partial;
*to_nxt++ = static_cast<uint8_t>(0xE0 | (wc >> 12));
*to_nxt++ = static_cast<uint8_t>(0x80 | ((wc & 0x0FC0) >> 6));
*to_nxt++ = static_cast<uint8_t>(0x80 | (wc & 0x003F));
}
else // if (wc < 0x110000)
{
if (to_end-to_nxt < 4)
return codecvt_base::partial;
*to_nxt++ = static_cast<uint8_t>(0xF0 | (wc >> 18));
*to_nxt++ = static_cast<uint8_t>(0x80 | ((wc & 0x03F000) >> 12));
*to_nxt++ = static_cast<uint8_t>(0x80 | ((wc & 0x000FC0) >> 6));
*to_nxt++ = static_cast<uint8_t>(0x80 | (wc & 0x00003F));
}
}
return codecvt_base::ok;
}
static
codecvt_base::result
utf8_to_ucs4(const uint8_t* frm, const uint8_t* frm_end, const uint8_t*& frm_nxt,
uint32_t* to, uint32_t* to_end, uint32_t*& to_nxt,
unsigned long Maxcode = 0x10FFFF, codecvt_mode mode = codecvt_mode(0))
{
frm_nxt = frm;
to_nxt = to;
if (mode & consume_header)
{
if (frm_end-frm_nxt >= 3 && frm_nxt[0] == 0xEF && frm_nxt[1] == 0xBB &&
frm_nxt[2] == 0xBF)
frm_nxt += 3;
}
for (; frm_nxt < frm_end && to_nxt < to_end; ++to_nxt)
{
uint8_t c1 = static_cast<uint8_t>(*frm_nxt);
if (c1 < 0x80)
{
if (c1 > Maxcode)
return codecvt_base::error;
*to_nxt = static_cast<uint32_t>(c1);
++frm_nxt;
}
else if (c1 < 0xC2)
{
return codecvt_base::error;
}
else if (c1 < 0xE0)
{
if (frm_end-frm_nxt < 2)
return codecvt_base::partial;
uint8_t c2 = frm_nxt[1];
if ((c2 & 0xC0) != 0x80)
return codecvt_base::error;
uint32_t t = static_cast<uint32_t>(((c1 & 0x1F) << 6)
| (c2 & 0x3F));
if (t > Maxcode)
return codecvt_base::error;
*to_nxt = t;
frm_nxt += 2;
}
else if (c1 < 0xF0)
{
if (frm_end-frm_nxt < 3)
return codecvt_base::partial;
uint8_t c2 = frm_nxt[1];
uint8_t c3 = frm_nxt[2];
switch (c1)
{
case 0xE0:
if ((c2 & 0xE0) != 0xA0)
return codecvt_base::error;
break;
case 0xED:
if ((c2 & 0xE0) != 0x80)
return codecvt_base::error;
break;
default:
if ((c2 & 0xC0) != 0x80)
return codecvt_base::error;
break;
}
if ((c3 & 0xC0) != 0x80)
return codecvt_base::error;
uint32_t t = static_cast<uint32_t>(((c1 & 0x0F) << 12)
| ((c2 & 0x3F) << 6)
| (c3 & 0x3F));
if (t > Maxcode)
return codecvt_base::error;
*to_nxt = t;
frm_nxt += 3;
}
else if (c1 < 0xF5)
{
if (frm_end-frm_nxt < 4)
return codecvt_base::partial;
uint8_t c2 = frm_nxt[1];
uint8_t c3 = frm_nxt[2];
uint8_t c4 = frm_nxt[3];
switch (c1)
{
case 0xF0:
if (!(0x90 <= c2 && c2 <= 0xBF))
return codecvt_base::error;
break;
case 0xF4:
if ((c2 & 0xF0) != 0x80)
return codecvt_base::error;
break;
default:
if ((c2 & 0xC0) != 0x80)
return codecvt_base::error;
break;
}
if ((c3 & 0xC0) != 0x80 || (c4 & 0xC0) != 0x80)
return codecvt_base::error;
uint32_t t = static_cast<uint32_t>(((c1 & 0x07) << 18)
| ((c2 & 0x3F) << 12)
| ((c3 & 0x3F) << 6)
| (c4 & 0x3F));
if (t > Maxcode)
return codecvt_base::error;
*to_nxt = t;
frm_nxt += 4;
}
else
{
return codecvt_base::error;
}
}
return frm_nxt < frm_end ? codecvt_base::partial : codecvt_base::ok;
}
static
int
utf8_to_ucs4_length(const uint8_t* frm, const uint8_t* frm_end,
size_t mx, unsigned long Maxcode = 0x10FFFF,
codecvt_mode mode = codecvt_mode(0))
{
const uint8_t* frm_nxt = frm;
if (mode & consume_header)
{
if (frm_end-frm_nxt >= 3 && frm_nxt[0] == 0xEF && frm_nxt[1] == 0xBB &&
frm_nxt[2] == 0xBF)
frm_nxt += 3;
}
for (size_t nchar32_t = 0; frm_nxt < frm_end && nchar32_t < mx; ++nchar32_t)
{
uint8_t c1 = static_cast<uint8_t>(*frm_nxt);
if (c1 < 0x80)
{
if (c1 > Maxcode)
break;
++frm_nxt;
}
else if (c1 < 0xC2)
{
break;
}
else if (c1 < 0xE0)
{
if ((frm_end-frm_nxt < 2) || ((frm_nxt[1] & 0xC0) != 0x80))
break;
if ((((c1 & 0x1Fu) << 6) | (frm_nxt[1] & 0x3Fu)) > Maxcode)
break;
frm_nxt += 2;
}
else if (c1 < 0xF0)
{
if (frm_end-frm_nxt < 3)
break;
uint8_t c2 = frm_nxt[1];
uint8_t c3 = frm_nxt[2];
switch (c1)
{
case 0xE0:
if ((c2 & 0xE0) != 0xA0)
return static_cast<int>(frm_nxt - frm);
break;
case 0xED:
if ((c2 & 0xE0) != 0x80)
return static_cast<int>(frm_nxt - frm);
break;
default:
if ((c2 & 0xC0) != 0x80)
return static_cast<int>(frm_nxt - frm);
break;
}
if ((c3 & 0xC0) != 0x80)
break;
if ((((c1 & 0x0Fu) << 12) | ((c2 & 0x3Fu) << 6) | (c3 & 0x3Fu)) > Maxcode)
break;
frm_nxt += 3;
}
else if (c1 < 0xF5)
{
if (frm_end-frm_nxt < 4)
break;
uint8_t c2 = frm_nxt[1];
uint8_t c3 = frm_nxt[2];
uint8_t c4 = frm_nxt[3];
switch (c1)
{
case 0xF0:
if (!(0x90 <= c2 && c2 <= 0xBF))
return static_cast<int>(frm_nxt - frm);
break;
case 0xF4:
if ((c2 & 0xF0) != 0x80)
return static_cast<int>(frm_nxt - frm);
break;
default:
if ((c2 & 0xC0) != 0x80)
return static_cast<int>(frm_nxt - frm);
break;
}
if ((c3 & 0xC0) != 0x80 || (c4 & 0xC0) != 0x80)
break;
if ((((c1 & 0x07u) << 18) | ((c2 & 0x3Fu) << 12) |
((c3 & 0x3Fu) << 6) | (c4 & 0x3Fu)) > Maxcode)
break;
frm_nxt += 4;
}
else
{
break;
}
}
return static_cast<int>(frm_nxt - frm);
}
static
codecvt_base::result
ucs2_to_utf8(const uint16_t* frm, const uint16_t* frm_end, const uint16_t*& frm_nxt,
uint8_t* to, uint8_t* to_end, uint8_t*& to_nxt,
unsigned long Maxcode = 0x10FFFF, codecvt_mode mode = codecvt_mode(0))
{
frm_nxt = frm;
to_nxt = to;
if (mode & generate_header)
{
if (to_end-to_nxt < 3)
return codecvt_base::partial;
*to_nxt++ = static_cast<uint8_t>(0xEF);
*to_nxt++ = static_cast<uint8_t>(0xBB);
*to_nxt++ = static_cast<uint8_t>(0xBF);
}
for (; frm_nxt < frm_end; ++frm_nxt)
{
uint16_t wc = *frm_nxt;
if ((wc & 0xF800) == 0xD800 || wc > Maxcode)
return codecvt_base::error;
if (wc < 0x0080)
{
if (to_end-to_nxt < 1)
return codecvt_base::partial;
*to_nxt++ = static_cast<uint8_t>(wc);
}
else if (wc < 0x0800)
{
if (to_end-to_nxt < 2)
return codecvt_base::partial;
*to_nxt++ = static_cast<uint8_t>(0xC0 | (wc >> 6));
*to_nxt++ = static_cast<uint8_t>(0x80 | (wc & 0x03F));
}
else // if (wc <= 0xFFFF)
{
if (to_end-to_nxt < 3)
return codecvt_base::partial;
*to_nxt++ = static_cast<uint8_t>(0xE0 | (wc >> 12));
*to_nxt++ = static_cast<uint8_t>(0x80 | ((wc & 0x0FC0) >> 6));
*to_nxt++ = static_cast<uint8_t>(0x80 | (wc & 0x003F));
}
}
return codecvt_base::ok;
}
static
codecvt_base::result
utf8_to_ucs2(const uint8_t* frm, const uint8_t* frm_end, const uint8_t*& frm_nxt,
uint16_t* to, uint16_t* to_end, uint16_t*& to_nxt,
unsigned long Maxcode = 0x10FFFF, codecvt_mode mode = codecvt_mode(0))
{
frm_nxt = frm;
to_nxt = to;
if (mode & consume_header)
{
if (frm_end-frm_nxt >= 3 && frm_nxt[0] == 0xEF && frm_nxt[1] == 0xBB &&
frm_nxt[2] == 0xBF)
frm_nxt += 3;
}
for (; frm_nxt < frm_end && to_nxt < to_end; ++to_nxt)
{
uint8_t c1 = static_cast<uint8_t>(*frm_nxt);
if (c1 < 0x80)
{
if (c1 > Maxcode)
return codecvt_base::error;
*to_nxt = static_cast<uint16_t>(c1);
++frm_nxt;
}
else if (c1 < 0xC2)
{
return codecvt_base::error;
}
else if (c1 < 0xE0)
{
if (frm_end-frm_nxt < 2)
return codecvt_base::partial;
uint8_t c2 = frm_nxt[1];
if ((c2 & 0xC0) != 0x80)
return codecvt_base::error;
uint16_t t = static_cast<uint16_t>(((c1 & 0x1F) << 6)
| (c2 & 0x3F));
if (t > Maxcode)
return codecvt_base::error;
*to_nxt = t;
frm_nxt += 2;
}
else if (c1 < 0xF0)
{
if (frm_end-frm_nxt < 3)
return codecvt_base::partial;
uint8_t c2 = frm_nxt[1];
uint8_t c3 = frm_nxt[2];
switch (c1)
{
case 0xE0:
if ((c2 & 0xE0) != 0xA0)
return codecvt_base::error;
break;
case 0xED:
if ((c2 & 0xE0) != 0x80)
return codecvt_base::error;
break;
default:
if ((c2 & 0xC0) != 0x80)
return codecvt_base::error;
break;
}
if ((c3 & 0xC0) != 0x80)
return codecvt_base::error;
uint16_t t = static_cast<uint16_t>(((c1 & 0x0F) << 12)
| ((c2 & 0x3F) << 6)
| (c3 & 0x3F));
if (t > Maxcode)
return codecvt_base::error;
*to_nxt = t;
frm_nxt += 3;
}
else
{
return codecvt_base::error;
}
}
return frm_nxt < frm_end ? codecvt_base::partial : codecvt_base::ok;
}
static
int
utf8_to_ucs2_length(const uint8_t* frm, const uint8_t* frm_end,
size_t mx, unsigned long Maxcode = 0x10FFFF,
codecvt_mode mode = codecvt_mode(0))
{
const uint8_t* frm_nxt = frm;
if (mode & consume_header)
{
if (frm_end-frm_nxt >= 3 && frm_nxt[0] == 0xEF && frm_nxt[1] == 0xBB &&
frm_nxt[2] == 0xBF)
frm_nxt += 3;
}
for (size_t nchar32_t = 0; frm_nxt < frm_end && nchar32_t < mx; ++nchar32_t)
{
uint8_t c1 = static_cast<uint8_t>(*frm_nxt);
if (c1 < 0x80)
{
if (c1 > Maxcode)
break;
++frm_nxt;
}
else if (c1 < 0xC2)
{
break;
}
else if (c1 < 0xE0)
{
if ((frm_end-frm_nxt < 2) || ((frm_nxt[1] & 0xC0) != 0x80))
break;
if ((((c1 & 0x1Fu) << 6) | (frm_nxt[1] & 0x3Fu)) > Maxcode)
break;
frm_nxt += 2;
}
else if (c1 < 0xF0)
{
if (frm_end-frm_nxt < 3)
break;
uint8_t c2 = frm_nxt[1];
uint8_t c3 = frm_nxt[2];
switch (c1)
{
case 0xE0:
if ((c2 & 0xE0) != 0xA0)
return static_cast<int>(frm_nxt - frm);
break;
case 0xED:
if ((c2 & 0xE0) != 0x80)
return static_cast<int>(frm_nxt - frm);
break;
default:
if ((c2 & 0xC0) != 0x80)
return static_cast<int>(frm_nxt - frm);
break;
}
if ((c3 & 0xC0) != 0x80)
break;
if ((((c1 & 0x0Fu) << 12) | ((c2 & 0x3Fu) << 6) | (c3 & 0x3Fu)) > Maxcode)
break;
frm_nxt += 3;
}
else
{
break;
}
}
return static_cast<int>(frm_nxt - frm);
}
static
codecvt_base::result
ucs4_to_utf16be(const uint32_t* frm, const uint32_t* frm_end, const uint32_t*& frm_nxt,
uint8_t* to, uint8_t* to_end, uint8_t*& to_nxt,
unsigned long Maxcode = 0x10FFFF, codecvt_mode mode = codecvt_mode(0))
{
frm_nxt = frm;
to_nxt = to;
if (mode & generate_header)
{
if (to_end-to_nxt < 2)
return codecvt_base::partial;
*to_nxt++ = static_cast<uint8_t>(0xFE);
*to_nxt++ = static_cast<uint8_t>(0xFF);
}
for (; frm_nxt < frm_end; ++frm_nxt)
{
uint32_t wc = *frm_nxt;
if ((wc & 0xFFFFF800) == 0x00D800 || wc > Maxcode)
return codecvt_base::error;
if (wc < 0x010000)
{
if (to_end-to_nxt < 2)
return codecvt_base::partial;
*to_nxt++ = static_cast<uint8_t>(wc >> 8);
*to_nxt++ = static_cast<uint8_t>(wc);
}
else
{
if (to_end-to_nxt < 4)
return codecvt_base::partial;
uint16_t t = static_cast<uint16_t>(
0xD800
| ((((wc & 0x1F0000) >> 16) - 1) << 6)
| ((wc & 0x00FC00) >> 10));
*to_nxt++ = static_cast<uint8_t>(t >> 8);
*to_nxt++ = static_cast<uint8_t>(t);
t = static_cast<uint16_t>(0xDC00 | (wc & 0x03FF));
*to_nxt++ = static_cast<uint8_t>(t >> 8);
*to_nxt++ = static_cast<uint8_t>(t);
}
}
return codecvt_base::ok;
}
static
codecvt_base::result
utf16be_to_ucs4(const uint8_t* frm, const uint8_t* frm_end, const uint8_t*& frm_nxt,
uint32_t* to, uint32_t* to_end, uint32_t*& to_nxt,
unsigned long Maxcode = 0x10FFFF, codecvt_mode mode = codecvt_mode(0))
{
frm_nxt = frm;
to_nxt = to;
if (mode & consume_header)
{
if (frm_end-frm_nxt >= 2 && frm_nxt[0] == 0xFE && frm_nxt[1] == 0xFF)
frm_nxt += 2;
}
for (; frm_nxt < frm_end - 1 && to_nxt < to_end; ++to_nxt)
{
uint16_t c1 = static_cast<uint16_t>(frm_nxt[0] << 8 | frm_nxt[1]);
if ((c1 & 0xFC00) == 0xDC00)
return codecvt_base::error;
if ((c1 & 0xFC00) != 0xD800)
{
if (c1 > Maxcode)
return codecvt_base::error;
*to_nxt = static_cast<uint32_t>(c1);
frm_nxt += 2;
}
else
{
if (frm_end-frm_nxt < 4)
return codecvt_base::partial;
uint16_t c2 = static_cast<uint16_t>(frm_nxt[2] << 8 | frm_nxt[3]);
if ((c2 & 0xFC00) != 0xDC00)
return codecvt_base::error;
uint32_t t = static_cast<uint32_t>(
((((c1 & 0x03C0) >> 6) + 1) << 16)
| ((c1 & 0x003F) << 10)
| (c2 & 0x03FF));
if (t > Maxcode)
return codecvt_base::error;
*to_nxt = t;
frm_nxt += 4;
}
}
return frm_nxt < frm_end ? codecvt_base::partial : codecvt_base::ok;
}
static
int
utf16be_to_ucs4_length(const uint8_t* frm, const uint8_t* frm_end,
size_t mx, unsigned long Maxcode = 0x10FFFF,
codecvt_mode mode = codecvt_mode(0))
{
const uint8_t* frm_nxt = frm;
if (mode & consume_header)
{
if (frm_end-frm_nxt >= 2 && frm_nxt[0] == 0xFE && frm_nxt[1] == 0xFF)
frm_nxt += 2;
}
for (size_t nchar32_t = 0; frm_nxt < frm_end - 1 && nchar32_t < mx; ++nchar32_t)
{
uint16_t c1 = static_cast<uint16_t>(frm_nxt[0] << 8 | frm_nxt[1]);
if ((c1 & 0xFC00) == 0xDC00)
break;
if ((c1 & 0xFC00) != 0xD800)
{
if (c1 > Maxcode)
break;
frm_nxt += 2;
}
else
{
if (frm_end-frm_nxt < 4)
break;
uint16_t c2 = static_cast<uint16_t>(frm_nxt[2] << 8 | frm_nxt[3]);
if ((c2 & 0xFC00) != 0xDC00)
break;
uint32_t t = static_cast<uint32_t>(
((((c1 & 0x03C0) >> 6) + 1) << 16)
| ((c1 & 0x003F) << 10)
| (c2 & 0x03FF));
if (t > Maxcode)
break;
frm_nxt += 4;
}
}
return static_cast<int>(frm_nxt - frm);
}
static
codecvt_base::result
ucs4_to_utf16le(const uint32_t* frm, const uint32_t* frm_end, const uint32_t*& frm_nxt,
uint8_t* to, uint8_t* to_end, uint8_t*& to_nxt,
unsigned long Maxcode = 0x10FFFF, codecvt_mode mode = codecvt_mode(0))
{
frm_nxt = frm;
to_nxt = to;
if (mode & generate_header)
{
if (to_end - to_nxt < 2)
return codecvt_base::partial;
*to_nxt++ = static_cast<uint8_t>(0xFF);
*to_nxt++ = static_cast<uint8_t>(0xFE);
}
for (; frm_nxt < frm_end; ++frm_nxt)
{
uint32_t wc = *frm_nxt;
if ((wc & 0xFFFFF800) == 0x00D800 || wc > Maxcode)
return codecvt_base::error;
if (wc < 0x010000)
{
if (to_end-to_nxt < 2)
return codecvt_base::partial;
*to_nxt++ = static_cast<uint8_t>(wc);
*to_nxt++ = static_cast<uint8_t>(wc >> 8);
}
else
{
if (to_end-to_nxt < 4)
return codecvt_base::partial;
uint16_t t = static_cast<uint16_t>(
0xD800
| ((((wc & 0x1F0000) >> 16) - 1) << 6)
| ((wc & 0x00FC00) >> 10));
*to_nxt++ = static_cast<uint8_t>(t);
*to_nxt++ = static_cast<uint8_t>(t >> 8);
t = static_cast<uint16_t>(0xDC00 | (wc & 0x03FF));
*to_nxt++ = static_cast<uint8_t>(t);
*to_nxt++ = static_cast<uint8_t>(t >> 8);
}
}
return codecvt_base::ok;
}
static
codecvt_base::result
utf16le_to_ucs4(const uint8_t* frm, const uint8_t* frm_end, const uint8_t*& frm_nxt,
uint32_t* to, uint32_t* to_end, uint32_t*& to_nxt,
unsigned long Maxcode = 0x10FFFF, codecvt_mode mode = codecvt_mode(0))
{
frm_nxt = frm;
to_nxt = to;
if (mode & consume_header)
{
if (frm_end-frm_nxt >= 2 && frm_nxt[0] == 0xFF && frm_nxt[1] == 0xFE)
frm_nxt += 2;
}
for (; frm_nxt < frm_end - 1 && to_nxt < to_end; ++to_nxt)
{
uint16_t c1 = static_cast<uint16_t>(frm_nxt[1] << 8 | frm_nxt[0]);
if ((c1 & 0xFC00) == 0xDC00)
return codecvt_base::error;
if ((c1 & 0xFC00) != 0xD800)
{
if (c1 > Maxcode)
return codecvt_base::error;
*to_nxt = static_cast<uint32_t>(c1);
frm_nxt += 2;
}
else
{
if (frm_end-frm_nxt < 4)
return codecvt_base::partial;
uint16_t c2 = static_cast<uint16_t>(frm_nxt[3] << 8 | frm_nxt[2]);
if ((c2 & 0xFC00) != 0xDC00)
return codecvt_base::error;
uint32_t t = static_cast<uint32_t>(
((((c1 & 0x03C0) >> 6) + 1) << 16)
| ((c1 & 0x003F) << 10)
| (c2 & 0x03FF));
if (t > Maxcode)
return codecvt_base::error;
*to_nxt = t;
frm_nxt += 4;
}
}
return frm_nxt < frm_end ? codecvt_base::partial : codecvt_base::ok;
}
static
int
utf16le_to_ucs4_length(const uint8_t* frm, const uint8_t* frm_end,
size_t mx, unsigned long Maxcode = 0x10FFFF,
codecvt_mode mode = codecvt_mode(0))
{
const uint8_t* frm_nxt = frm;
if (mode & consume_header)
{
if (frm_end-frm_nxt >= 2 && frm_nxt[0] == 0xFF && frm_nxt[1] == 0xFE)
frm_nxt += 2;
}
for (size_t nchar32_t = 0; frm_nxt < frm_end - 1 && nchar32_t < mx; ++nchar32_t)
{
uint16_t c1 = static_cast<uint16_t>(frm_nxt[1] << 8 | frm_nxt[0]);
if ((c1 & 0xFC00) == 0xDC00)
break;
if ((c1 & 0xFC00) != 0xD800)
{
if (c1 > Maxcode)
break;
frm_nxt += 2;
}
else
{
if (frm_end-frm_nxt < 4)
break;
uint16_t c2 = static_cast<uint16_t>(frm_nxt[3] << 8 | frm_nxt[2]);
if ((c2 & 0xFC00) != 0xDC00)
break;
uint32_t t = static_cast<uint32_t>(
((((c1 & 0x03C0) >> 6) + 1) << 16)
| ((c1 & 0x003F) << 10)
| (c2 & 0x03FF));
if (t > Maxcode)
break;
frm_nxt += 4;
}
}
return static_cast<int>(frm_nxt - frm);
}
static
codecvt_base::result
ucs2_to_utf16be(const uint16_t* frm, const uint16_t* frm_end, const uint16_t*& frm_nxt,
uint8_t* to, uint8_t* to_end, uint8_t*& to_nxt,
unsigned long Maxcode = 0x10FFFF, codecvt_mode mode = codecvt_mode(0))
{
frm_nxt = frm;
to_nxt = to;
if (mode & generate_header)
{
if (to_end-to_nxt < 2)
return codecvt_base::partial;
*to_nxt++ = static_cast<uint8_t>(0xFE);
*to_nxt++ = static_cast<uint8_t>(0xFF);
}
for (; frm_nxt < frm_end; ++frm_nxt)
{
uint16_t wc = *frm_nxt;
if ((wc & 0xF800) == 0xD800 || wc > Maxcode)
return codecvt_base::error;
if (to_end-to_nxt < 2)
return codecvt_base::partial;
*to_nxt++ = static_cast<uint8_t>(wc >> 8);
*to_nxt++ = static_cast<uint8_t>(wc);
}
return codecvt_base::ok;
}
static
codecvt_base::result
utf16be_to_ucs2(const uint8_t* frm, const uint8_t* frm_end, const uint8_t*& frm_nxt,
uint16_t* to, uint16_t* to_end, uint16_t*& to_nxt,
unsigned long Maxcode = 0x10FFFF, codecvt_mode mode = codecvt_mode(0))
{
frm_nxt = frm;
to_nxt = to;
if (mode & consume_header)
{
if (frm_end-frm_nxt >= 2 && frm_nxt[0] == 0xFE && frm_nxt[1] == 0xFF)
frm_nxt += 2;
}
for (; frm_nxt < frm_end - 1 && to_nxt < to_end; ++to_nxt)
{
uint16_t c1 = static_cast<uint16_t>(frm_nxt[0] << 8 | frm_nxt[1]);
if ((c1 & 0xF800) == 0xD800 || c1 > Maxcode)
return codecvt_base::error;
*to_nxt = c1;
frm_nxt += 2;
}
return frm_nxt < frm_end ? codecvt_base::partial : codecvt_base::ok;
}
static
int
utf16be_to_ucs2_length(const uint8_t* frm, const uint8_t* frm_end,
size_t mx, unsigned long Maxcode = 0x10FFFF,
codecvt_mode mode = codecvt_mode(0))
{
const uint8_t* frm_nxt = frm;
if (mode & consume_header)
{
if (frm_end-frm_nxt >= 2 && frm_nxt[0] == 0xFE && frm_nxt[1] == 0xFF)
frm_nxt += 2;
}
for (size_t nchar16_t = 0; frm_nxt < frm_end - 1 && nchar16_t < mx; ++nchar16_t)
{
uint16_t c1 = static_cast<uint16_t>(frm_nxt[0] << 8 | frm_nxt[1]);
if ((c1 & 0xF800) == 0xD800 || c1 > Maxcode)
break;
frm_nxt += 2;
}
return static_cast<int>(frm_nxt - frm);
}
static
codecvt_base::result
ucs2_to_utf16le(const uint16_t* frm, const uint16_t* frm_end, const uint16_t*& frm_nxt,
uint8_t* to, uint8_t* to_end, uint8_t*& to_nxt,
unsigned long Maxcode = 0x10FFFF, codecvt_mode mode = codecvt_mode(0))
{
frm_nxt = frm;
to_nxt = to;
if (mode & generate_header)
{
if (to_end-to_nxt < 2)
return codecvt_base::partial;
*to_nxt++ = static_cast<uint8_t>(0xFF);
*to_nxt++ = static_cast<uint8_t>(0xFE);
}
for (; frm_nxt < frm_end; ++frm_nxt)
{
uint16_t wc = *frm_nxt;
if ((wc & 0xF800) == 0xD800 || wc > Maxcode)
return codecvt_base::error;
if (to_end-to_nxt < 2)
return codecvt_base::partial;
*to_nxt++ = static_cast<uint8_t>(wc);
*to_nxt++ = static_cast<uint8_t>(wc >> 8);
}
return codecvt_base::ok;
}
static
codecvt_base::result
utf16le_to_ucs2(const uint8_t* frm, const uint8_t* frm_end, const uint8_t*& frm_nxt,
uint16_t* to, uint16_t* to_end, uint16_t*& to_nxt,
unsigned long Maxcode = 0x10FFFF, codecvt_mode mode = codecvt_mode(0))
{
frm_nxt = frm;
to_nxt = to;
if (mode & consume_header)
{
if (frm_end-frm_nxt >= 2 && frm_nxt[0] == 0xFF && frm_nxt[1] == 0xFE)
frm_nxt += 2;
}
for (; frm_nxt < frm_end - 1 && to_nxt < to_end; ++to_nxt)
{
uint16_t c1 = static_cast<uint16_t>(frm_nxt[1] << 8 | frm_nxt[0]);
if ((c1 & 0xF800) == 0xD800 || c1 > Maxcode)
return codecvt_base::error;
*to_nxt = c1;
frm_nxt += 2;
}
return frm_nxt < frm_end ? codecvt_base::partial : codecvt_base::ok;
}
static
int
utf16le_to_ucs2_length(const uint8_t* frm, const uint8_t* frm_end,
size_t mx, unsigned long Maxcode = 0x10FFFF,
codecvt_mode mode = codecvt_mode(0))
{
const uint8_t* frm_nxt = frm;
frm_nxt = frm;
if (mode & consume_header)
{
if (frm_end-frm_nxt >= 2 && frm_nxt[0] == 0xFF && frm_nxt[1] == 0xFE)
frm_nxt += 2;
}
for (size_t nchar16_t = 0; frm_nxt < frm_end - 1 && nchar16_t < mx; ++nchar16_t)
{
uint16_t c1 = static_cast<uint16_t>(frm_nxt[1] << 8 | frm_nxt[0]);
if ((c1 & 0xF800) == 0xD800 || c1 > Maxcode)
break;
frm_nxt += 2;
}
return static_cast<int>(frm_nxt - frm);
}
// template <> class codecvt<char16_t, char, mbstate_t>
locale::id codecvt<char16_t, char, mbstate_t>::id;
codecvt<char16_t, char, mbstate_t>::~codecvt()
{
}
codecvt<char16_t, char, mbstate_t>::result
codecvt<char16_t, char, mbstate_t>::do_out(state_type&,
const intern_type* frm, const intern_type* frm_end, const intern_type*& frm_nxt,
extern_type* to, extern_type* to_end, extern_type*& to_nxt) const
{
const uint16_t* _frm = reinterpret_cast<const uint16_t*>(frm);
const uint16_t* _frm_end = reinterpret_cast<const uint16_t*>(frm_end);
const uint16_t* _frm_nxt = _frm;
uint8_t* _to = reinterpret_cast<uint8_t*>(to);
uint8_t* _to_end = reinterpret_cast<uint8_t*>(to_end);
uint8_t* _to_nxt = _to;
result r = utf16_to_utf8(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt);
frm_nxt = frm + (_frm_nxt - _frm);
to_nxt = to + (_to_nxt - _to);
return r;
}
codecvt<char16_t, char, mbstate_t>::result
codecvt<char16_t, char, mbstate_t>::do_in(state_type&,
const extern_type* frm, const extern_type* frm_end, const extern_type*& frm_nxt,
intern_type* to, intern_type* to_end, intern_type*& to_nxt) const
{
const uint8_t* _frm = reinterpret_cast<const uint8_t*>(frm);
const uint8_t* _frm_end = reinterpret_cast<const uint8_t*>(frm_end);
const uint8_t* _frm_nxt = _frm;
uint16_t* _to = reinterpret_cast<uint16_t*>(to);
uint16_t* _to_end = reinterpret_cast<uint16_t*>(to_end);
uint16_t* _to_nxt = _to;
result r = utf8_to_utf16(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt);
frm_nxt = frm + (_frm_nxt - _frm);
to_nxt = to + (_to_nxt - _to);
return r;
}
codecvt<char16_t, char, mbstate_t>::result
codecvt<char16_t, char, mbstate_t>::do_unshift(state_type&,
extern_type* to, extern_type*, extern_type*& to_nxt) const
{
to_nxt = to;
return noconv;
}
int
codecvt<char16_t, char, mbstate_t>::do_encoding() const _NOEXCEPT
{
return 0;
}
bool
codecvt<char16_t, char, mbstate_t>::do_always_noconv() const _NOEXCEPT
{
return false;
}
int
codecvt<char16_t, char, mbstate_t>::do_length(state_type&,
const extern_type* frm, const extern_type* frm_end, size_t mx) const
{
const uint8_t* _frm = reinterpret_cast<const uint8_t*>(frm);
const uint8_t* _frm_end = reinterpret_cast<const uint8_t*>(frm_end);
return utf8_to_utf16_length(_frm, _frm_end, mx);
}
int
codecvt<char16_t, char, mbstate_t>::do_max_length() const _NOEXCEPT
{
return 4;
}
// template <> class codecvt<char32_t, char, mbstate_t>
locale::id codecvt<char32_t, char, mbstate_t>::id;
codecvt<char32_t, char, mbstate_t>::~codecvt()
{
}
codecvt<char32_t, char, mbstate_t>::result
codecvt<char32_t, char, mbstate_t>::do_out(state_type&,
const intern_type* frm, const intern_type* frm_end, const intern_type*& frm_nxt,
extern_type* to, extern_type* to_end, extern_type*& to_nxt) const
{
const uint32_t* _frm = reinterpret_cast<const uint32_t*>(frm);
const uint32_t* _frm_end = reinterpret_cast<const uint32_t*>(frm_end);
const uint32_t* _frm_nxt = _frm;
uint8_t* _to = reinterpret_cast<uint8_t*>(to);
uint8_t* _to_end = reinterpret_cast<uint8_t*>(to_end);
uint8_t* _to_nxt = _to;
result r = ucs4_to_utf8(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt);
frm_nxt = frm + (_frm_nxt - _frm);
to_nxt = to + (_to_nxt - _to);
return r;
}
codecvt<char32_t, char, mbstate_t>::result
codecvt<char32_t, char, mbstate_t>::do_in(state_type&,
const extern_type* frm, const extern_type* frm_end, const extern_type*& frm_nxt,
intern_type* to, intern_type* to_end, intern_type*& to_nxt) const
{
const uint8_t* _frm = reinterpret_cast<const uint8_t*>(frm);
const uint8_t* _frm_end = reinterpret_cast<const uint8_t*>(frm_end);
const uint8_t* _frm_nxt = _frm;
uint32_t* _to = reinterpret_cast<uint32_t*>(to);
uint32_t* _to_end = reinterpret_cast<uint32_t*>(to_end);
uint32_t* _to_nxt = _to;
result r = utf8_to_ucs4(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt);
frm_nxt = frm + (_frm_nxt - _frm);
to_nxt = to + (_to_nxt - _to);
return r;
}
codecvt<char32_t, char, mbstate_t>::result
codecvt<char32_t, char, mbstate_t>::do_unshift(state_type&,
extern_type* to, extern_type*, extern_type*& to_nxt) const
{
to_nxt = to;
return noconv;
}
int
codecvt<char32_t, char, mbstate_t>::do_encoding() const _NOEXCEPT
{
return 0;
}
bool
codecvt<char32_t, char, mbstate_t>::do_always_noconv() const _NOEXCEPT
{
return false;
}
int
codecvt<char32_t, char, mbstate_t>::do_length(state_type&,
const extern_type* frm, const extern_type* frm_end, size_t mx) const
{
const uint8_t* _frm = reinterpret_cast<const uint8_t*>(frm);
const uint8_t* _frm_end = reinterpret_cast<const uint8_t*>(frm_end);
return utf8_to_ucs4_length(_frm, _frm_end, mx);
}
int
codecvt<char32_t, char, mbstate_t>::do_max_length() const _NOEXCEPT
{
return 4;
}
// __codecvt_utf8<wchar_t>
__codecvt_utf8<wchar_t>::result
__codecvt_utf8<wchar_t>::do_out(state_type&,
const intern_type* frm, const intern_type* frm_end, const intern_type*& frm_nxt,
extern_type* to, extern_type* to_end, extern_type*& to_nxt) const
{
#if defined(_LIBCPP_SHORT_WCHAR)
const uint16_t* _frm = reinterpret_cast<const uint16_t*>(frm);
const uint16_t* _frm_end = reinterpret_cast<const uint16_t*>(frm_end);
const uint16_t* _frm_nxt = _frm;
#else
const uint32_t* _frm = reinterpret_cast<const uint32_t*>(frm);
const uint32_t* _frm_end = reinterpret_cast<const uint32_t*>(frm_end);
const uint32_t* _frm_nxt = _frm;
#endif
uint8_t* _to = reinterpret_cast<uint8_t*>(to);
uint8_t* _to_end = reinterpret_cast<uint8_t*>(to_end);
uint8_t* _to_nxt = _to;
#if defined(_LIBCPP_SHORT_WCHAR)
result r = ucs2_to_utf8(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt,
_Maxcode_, _Mode_);
#else
result r = ucs4_to_utf8(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt,
_Maxcode_, _Mode_);
#endif
frm_nxt = frm + (_frm_nxt - _frm);
to_nxt = to + (_to_nxt - _to);
return r;
}
__codecvt_utf8<wchar_t>::result
__codecvt_utf8<wchar_t>::do_in(state_type&,
const extern_type* frm, const extern_type* frm_end, const extern_type*& frm_nxt,
intern_type* to, intern_type* to_end, intern_type*& to_nxt) const
{
const uint8_t* _frm = reinterpret_cast<const uint8_t*>(frm);
const uint8_t* _frm_end = reinterpret_cast<const uint8_t*>(frm_end);
const uint8_t* _frm_nxt = _frm;
#if defined(_LIBCPP_SHORT_WCHAR)
uint16_t* _to = reinterpret_cast<uint16_t*>(to);
uint16_t* _to_end = reinterpret_cast<uint16_t*>(to_end);
uint16_t* _to_nxt = _to;
result r = utf8_to_ucs2(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt,
_Maxcode_, _Mode_);
#else
uint32_t* _to = reinterpret_cast<uint32_t*>(to);
uint32_t* _to_end = reinterpret_cast<uint32_t*>(to_end);
uint32_t* _to_nxt = _to;
result r = utf8_to_ucs4(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt,
_Maxcode_, _Mode_);
#endif
frm_nxt = frm + (_frm_nxt - _frm);
to_nxt = to + (_to_nxt - _to);
return r;
}
__codecvt_utf8<wchar_t>::result
__codecvt_utf8<wchar_t>::do_unshift(state_type&,
extern_type* to, extern_type*, extern_type*& to_nxt) const
{
to_nxt = to;
return noconv;
}
int
__codecvt_utf8<wchar_t>::do_encoding() const _NOEXCEPT
{
return 0;
}
bool
__codecvt_utf8<wchar_t>::do_always_noconv() const _NOEXCEPT
{
return false;
}
int
__codecvt_utf8<wchar_t>::do_length(state_type&,
const extern_type* frm, const extern_type* frm_end, size_t mx) const
{
const uint8_t* _frm = reinterpret_cast<const uint8_t*>(frm);
const uint8_t* _frm_end = reinterpret_cast<const uint8_t*>(frm_end);
return utf8_to_ucs4_length(_frm, _frm_end, mx, _Maxcode_, _Mode_);
}
int
__codecvt_utf8<wchar_t>::do_max_length() const _NOEXCEPT
{
if (_Mode_ & consume_header)
return 7;
return 4;
}
// __codecvt_utf8<char16_t>
__codecvt_utf8<char16_t>::result
__codecvt_utf8<char16_t>::do_out(state_type&,
const intern_type* frm, const intern_type* frm_end, const intern_type*& frm_nxt,
extern_type* to, extern_type* to_end, extern_type*& to_nxt) const
{
const uint16_t* _frm = reinterpret_cast<const uint16_t*>(frm);
const uint16_t* _frm_end = reinterpret_cast<const uint16_t*>(frm_end);
const uint16_t* _frm_nxt = _frm;
uint8_t* _to = reinterpret_cast<uint8_t*>(to);
uint8_t* _to_end = reinterpret_cast<uint8_t*>(to_end);
uint8_t* _to_nxt = _to;
result r = ucs2_to_utf8(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt,
_Maxcode_, _Mode_);
frm_nxt = frm + (_frm_nxt - _frm);
to_nxt = to + (_to_nxt - _to);
return r;
}
__codecvt_utf8<char16_t>::result
__codecvt_utf8<char16_t>::do_in(state_type&,
const extern_type* frm, const extern_type* frm_end, const extern_type*& frm_nxt,
intern_type* to, intern_type* to_end, intern_type*& to_nxt) const
{
const uint8_t* _frm = reinterpret_cast<const uint8_t*>(frm);
const uint8_t* _frm_end = reinterpret_cast<const uint8_t*>(frm_end);
const uint8_t* _frm_nxt = _frm;
uint16_t* _to = reinterpret_cast<uint16_t*>(to);
uint16_t* _to_end = reinterpret_cast<uint16_t*>(to_end);
uint16_t* _to_nxt = _to;
result r = utf8_to_ucs2(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt,
_Maxcode_, _Mode_);
frm_nxt = frm + (_frm_nxt - _frm);
to_nxt = to + (_to_nxt - _to);
return r;
}
__codecvt_utf8<char16_t>::result
__codecvt_utf8<char16_t>::do_unshift(state_type&,
extern_type* to, extern_type*, extern_type*& to_nxt) const
{
to_nxt = to;
return noconv;
}
int
__codecvt_utf8<char16_t>::do_encoding() const _NOEXCEPT
{
return 0;
}
bool
__codecvt_utf8<char16_t>::do_always_noconv() const _NOEXCEPT
{
return false;
}
int
__codecvt_utf8<char16_t>::do_length(state_type&,
const extern_type* frm, const extern_type* frm_end, size_t mx) const
{
const uint8_t* _frm = reinterpret_cast<const uint8_t*>(frm);
const uint8_t* _frm_end = reinterpret_cast<const uint8_t*>(frm_end);
return utf8_to_ucs2_length(_frm, _frm_end, mx, _Maxcode_, _Mode_);
}
int
__codecvt_utf8<char16_t>::do_max_length() const _NOEXCEPT
{
if (_Mode_ & consume_header)
return 6;
return 3;
}
// __codecvt_utf8<char32_t>
__codecvt_utf8<char32_t>::result
__codecvt_utf8<char32_t>::do_out(state_type&,
const intern_type* frm, const intern_type* frm_end, const intern_type*& frm_nxt,
extern_type* to, extern_type* to_end, extern_type*& to_nxt) const
{
const uint32_t* _frm = reinterpret_cast<const uint32_t*>(frm);
const uint32_t* _frm_end = reinterpret_cast<const uint32_t*>(frm_end);
const uint32_t* _frm_nxt = _frm;
uint8_t* _to = reinterpret_cast<uint8_t*>(to);
uint8_t* _to_end = reinterpret_cast<uint8_t*>(to_end);
uint8_t* _to_nxt = _to;
result r = ucs4_to_utf8(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt,
_Maxcode_, _Mode_);
frm_nxt = frm + (_frm_nxt - _frm);
to_nxt = to + (_to_nxt - _to);
return r;
}
__codecvt_utf8<char32_t>::result
__codecvt_utf8<char32_t>::do_in(state_type&,
const extern_type* frm, const extern_type* frm_end, const extern_type*& frm_nxt,
intern_type* to, intern_type* to_end, intern_type*& to_nxt) const
{
const uint8_t* _frm = reinterpret_cast<const uint8_t*>(frm);
const uint8_t* _frm_end = reinterpret_cast<const uint8_t*>(frm_end);
const uint8_t* _frm_nxt = _frm;
uint32_t* _to = reinterpret_cast<uint32_t*>(to);
uint32_t* _to_end = reinterpret_cast<uint32_t*>(to_end);
uint32_t* _to_nxt = _to;
result r = utf8_to_ucs4(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt,
_Maxcode_, _Mode_);
frm_nxt = frm + (_frm_nxt - _frm);
to_nxt = to + (_to_nxt - _to);
return r;
}
__codecvt_utf8<char32_t>::result
__codecvt_utf8<char32_t>::do_unshift(state_type&,
extern_type* to, extern_type*, extern_type*& to_nxt) const
{
to_nxt = to;
return noconv;
}
int
__codecvt_utf8<char32_t>::do_encoding() const _NOEXCEPT
{
return 0;
}
bool
__codecvt_utf8<char32_t>::do_always_noconv() const _NOEXCEPT
{
return false;
}
int
__codecvt_utf8<char32_t>::do_length(state_type&,
const extern_type* frm, const extern_type* frm_end, size_t mx) const
{
const uint8_t* _frm = reinterpret_cast<const uint8_t*>(frm);
const uint8_t* _frm_end = reinterpret_cast<const uint8_t*>(frm_end);
return utf8_to_ucs4_length(_frm, _frm_end, mx, _Maxcode_, _Mode_);
}
int
__codecvt_utf8<char32_t>::do_max_length() const _NOEXCEPT
{
if (_Mode_ & consume_header)
return 7;
return 4;
}
// __codecvt_utf16<wchar_t, false>
__codecvt_utf16<wchar_t, false>::result
__codecvt_utf16<wchar_t, false>::do_out(state_type&,
const intern_type* frm, const intern_type* frm_end, const intern_type*& frm_nxt,
extern_type* to, extern_type* to_end, extern_type*& to_nxt) const
{
const uint32_t* _frm = reinterpret_cast<const uint32_t*>(frm);
const uint32_t* _frm_end = reinterpret_cast<const uint32_t*>(frm_end);
const uint32_t* _frm_nxt = _frm;
uint8_t* _to = reinterpret_cast<uint8_t*>(to);
uint8_t* _to_end = reinterpret_cast<uint8_t*>(to_end);
uint8_t* _to_nxt = _to;
result r = ucs4_to_utf16be(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt,
_Maxcode_, _Mode_);
frm_nxt = frm + (_frm_nxt - _frm);
to_nxt = to + (_to_nxt - _to);
return r;
}
__codecvt_utf16<wchar_t, false>::result
__codecvt_utf16<wchar_t, false>::do_in(state_type&,
const extern_type* frm, const extern_type* frm_end, const extern_type*& frm_nxt,
intern_type* to, intern_type* to_end, intern_type*& to_nxt) const
{
const uint8_t* _frm = reinterpret_cast<const uint8_t*>(frm);
const uint8_t* _frm_end = reinterpret_cast<const uint8_t*>(frm_end);
const uint8_t* _frm_nxt = _frm;
uint32_t* _to = reinterpret_cast<uint32_t*>(to);
uint32_t* _to_end = reinterpret_cast<uint32_t*>(to_end);
uint32_t* _to_nxt = _to;
result r = utf16be_to_ucs4(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt,
_Maxcode_, _Mode_);
frm_nxt = frm + (_frm_nxt - _frm);
to_nxt = to + (_to_nxt - _to);
return r;
}
__codecvt_utf16<wchar_t, false>::result
__codecvt_utf16<wchar_t, false>::do_unshift(state_type&,
extern_type* to, extern_type*, extern_type*& to_nxt) const
{
to_nxt = to;
return noconv;
}
int
__codecvt_utf16<wchar_t, false>::do_encoding() const _NOEXCEPT
{
return 0;
}
bool
__codecvt_utf16<wchar_t, false>::do_always_noconv() const _NOEXCEPT
{
return false;
}
int
__codecvt_utf16<wchar_t, false>::do_length(state_type&,
const extern_type* frm, const extern_type* frm_end, size_t mx) const
{
const uint8_t* _frm = reinterpret_cast<const uint8_t*>(frm);
const uint8_t* _frm_end = reinterpret_cast<const uint8_t*>(frm_end);
return utf16be_to_ucs4_length(_frm, _frm_end, mx, _Maxcode_, _Mode_);
}
int
__codecvt_utf16<wchar_t, false>::do_max_length() const _NOEXCEPT
{
if (_Mode_ & consume_header)
return 6;
return 4;
}
// __codecvt_utf16<wchar_t, true>
__codecvt_utf16<wchar_t, true>::result
__codecvt_utf16<wchar_t, true>::do_out(state_type&,
const intern_type* frm, const intern_type* frm_end, const intern_type*& frm_nxt,
extern_type* to, extern_type* to_end, extern_type*& to_nxt) const
{
const uint32_t* _frm = reinterpret_cast<const uint32_t*>(frm);
const uint32_t* _frm_end = reinterpret_cast<const uint32_t*>(frm_end);
const uint32_t* _frm_nxt = _frm;
uint8_t* _to = reinterpret_cast<uint8_t*>(to);
uint8_t* _to_end = reinterpret_cast<uint8_t*>(to_end);
uint8_t* _to_nxt = _to;
result r = ucs4_to_utf16le(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt,
_Maxcode_, _Mode_);
frm_nxt = frm + (_frm_nxt - _frm);
to_nxt = to + (_to_nxt - _to);
return r;
}
__codecvt_utf16<wchar_t, true>::result
__codecvt_utf16<wchar_t, true>::do_in(state_type&,
const extern_type* frm, const extern_type* frm_end, const extern_type*& frm_nxt,
intern_type* to, intern_type* to_end, intern_type*& to_nxt) const
{
const uint8_t* _frm = reinterpret_cast<const uint8_t*>(frm);
const uint8_t* _frm_end = reinterpret_cast<const uint8_t*>(frm_end);
const uint8_t* _frm_nxt = _frm;
uint32_t* _to = reinterpret_cast<uint32_t*>(to);
uint32_t* _to_end = reinterpret_cast<uint32_t*>(to_end);
uint32_t* _to_nxt = _to;
result r = utf16le_to_ucs4(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt,
_Maxcode_, _Mode_);
frm_nxt = frm + (_frm_nxt - _frm);
to_nxt = to + (_to_nxt - _to);
return r;
}
__codecvt_utf16<wchar_t, true>::result
__codecvt_utf16<wchar_t, true>::do_unshift(state_type&,
extern_type* to, extern_type*, extern_type*& to_nxt) const
{
to_nxt = to;
return noconv;
}
int
__codecvt_utf16<wchar_t, true>::do_encoding() const _NOEXCEPT
{
return 0;
}
bool
__codecvt_utf16<wchar_t, true>::do_always_noconv() const _NOEXCEPT
{
return false;
}
int
__codecvt_utf16<wchar_t, true>::do_length(state_type&,
const extern_type* frm, const extern_type* frm_end, size_t mx) const
{
const uint8_t* _frm = reinterpret_cast<const uint8_t*>(frm);
const uint8_t* _frm_end = reinterpret_cast<const uint8_t*>(frm_end);
return utf16le_to_ucs4_length(_frm, _frm_end, mx, _Maxcode_, _Mode_);
}
int
__codecvt_utf16<wchar_t, true>::do_max_length() const _NOEXCEPT
{
if (_Mode_ & consume_header)
return 6;
return 4;
}
// __codecvt_utf16<char16_t, false>
__codecvt_utf16<char16_t, false>::result
__codecvt_utf16<char16_t, false>::do_out(state_type&,
const intern_type* frm, const intern_type* frm_end, const intern_type*& frm_nxt,
extern_type* to, extern_type* to_end, extern_type*& to_nxt) const
{
const uint16_t* _frm = reinterpret_cast<const uint16_t*>(frm);
const uint16_t* _frm_end = reinterpret_cast<const uint16_t*>(frm_end);
const uint16_t* _frm_nxt = _frm;
uint8_t* _to = reinterpret_cast<uint8_t*>(to);
uint8_t* _to_end = reinterpret_cast<uint8_t*>(to_end);
uint8_t* _to_nxt = _to;
result r = ucs2_to_utf16be(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt,
_Maxcode_, _Mode_);
frm_nxt = frm + (_frm_nxt - _frm);
to_nxt = to + (_to_nxt - _to);
return r;
}
__codecvt_utf16<char16_t, false>::result
__codecvt_utf16<char16_t, false>::do_in(state_type&,
const extern_type* frm, const extern_type* frm_end, const extern_type*& frm_nxt,
intern_type* to, intern_type* to_end, intern_type*& to_nxt) const
{
const uint8_t* _frm = reinterpret_cast<const uint8_t*>(frm);
const uint8_t* _frm_end = reinterpret_cast<const uint8_t*>(frm_end);
const uint8_t* _frm_nxt = _frm;
uint16_t* _to = reinterpret_cast<uint16_t*>(to);
uint16_t* _to_end = reinterpret_cast<uint16_t*>(to_end);
uint16_t* _to_nxt = _to;
result r = utf16be_to_ucs2(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt,
_Maxcode_, _Mode_);
frm_nxt = frm + (_frm_nxt - _frm);
to_nxt = to + (_to_nxt - _to);
return r;
}
__codecvt_utf16<char16_t, false>::result
__codecvt_utf16<char16_t, false>::do_unshift(state_type&,
extern_type* to, extern_type*, extern_type*& to_nxt) const
{
to_nxt = to;
return noconv;
}
int
__codecvt_utf16<char16_t, false>::do_encoding() const _NOEXCEPT
{
return 0;
}
bool
__codecvt_utf16<char16_t, false>::do_always_noconv() const _NOEXCEPT
{
return false;
}
int
__codecvt_utf16<char16_t, false>::do_length(state_type&,
const extern_type* frm, const extern_type* frm_end, size_t mx) const
{
const uint8_t* _frm = reinterpret_cast<const uint8_t*>(frm);
const uint8_t* _frm_end = reinterpret_cast<const uint8_t*>(frm_end);
return utf16be_to_ucs2_length(_frm, _frm_end, mx, _Maxcode_, _Mode_);
}
int
__codecvt_utf16<char16_t, false>::do_max_length() const _NOEXCEPT
{
if (_Mode_ & consume_header)
return 4;
return 2;
}
// __codecvt_utf16<char16_t, true>
__codecvt_utf16<char16_t, true>::result
__codecvt_utf16<char16_t, true>::do_out(state_type&,
const intern_type* frm, const intern_type* frm_end, const intern_type*& frm_nxt,
extern_type* to, extern_type* to_end, extern_type*& to_nxt) const
{
const uint16_t* _frm = reinterpret_cast<const uint16_t*>(frm);
const uint16_t* _frm_end = reinterpret_cast<const uint16_t*>(frm_end);
const uint16_t* _frm_nxt = _frm;
uint8_t* _to = reinterpret_cast<uint8_t*>(to);
uint8_t* _to_end = reinterpret_cast<uint8_t*>(to_end);
uint8_t* _to_nxt = _to;
result r = ucs2_to_utf16le(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt,
_Maxcode_, _Mode_);
frm_nxt = frm + (_frm_nxt - _frm);
to_nxt = to + (_to_nxt - _to);
return r;
}
__codecvt_utf16<char16_t, true>::result
__codecvt_utf16<char16_t, true>::do_in(state_type&,
const extern_type* frm, const extern_type* frm_end, const extern_type*& frm_nxt,
intern_type* to, intern_type* to_end, intern_type*& to_nxt) const
{
const uint8_t* _frm = reinterpret_cast<const uint8_t*>(frm);
const uint8_t* _frm_end = reinterpret_cast<const uint8_t*>(frm_end);
const uint8_t* _frm_nxt = _frm;
uint16_t* _to = reinterpret_cast<uint16_t*>(to);
uint16_t* _to_end = reinterpret_cast<uint16_t*>(to_end);
uint16_t* _to_nxt = _to;
result r = utf16le_to_ucs2(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt,
_Maxcode_, _Mode_);
frm_nxt = frm + (_frm_nxt - _frm);
to_nxt = to + (_to_nxt - _to);
return r;
}
__codecvt_utf16<char16_t, true>::result
__codecvt_utf16<char16_t, true>::do_unshift(state_type&,
extern_type* to, extern_type*, extern_type*& to_nxt) const
{
to_nxt = to;
return noconv;
}
int
__codecvt_utf16<char16_t, true>::do_encoding() const _NOEXCEPT
{
return 0;
}
bool
__codecvt_utf16<char16_t, true>::do_always_noconv() const _NOEXCEPT
{
return false;
}
int
__codecvt_utf16<char16_t, true>::do_length(state_type&,
const extern_type* frm, const extern_type* frm_end, size_t mx) const
{
const uint8_t* _frm = reinterpret_cast<const uint8_t*>(frm);
const uint8_t* _frm_end = reinterpret_cast<const uint8_t*>(frm_end);
return utf16le_to_ucs2_length(_frm, _frm_end, mx, _Maxcode_, _Mode_);
}
int
__codecvt_utf16<char16_t, true>::do_max_length() const _NOEXCEPT
{
if (_Mode_ & consume_header)
return 4;
return 2;
}
// __codecvt_utf16<char32_t, false>
__codecvt_utf16<char32_t, false>::result
__codecvt_utf16<char32_t, false>::do_out(state_type&,
const intern_type* frm, const intern_type* frm_end, const intern_type*& frm_nxt,
extern_type* to, extern_type* to_end, extern_type*& to_nxt) const
{
const uint32_t* _frm = reinterpret_cast<const uint32_t*>(frm);
const uint32_t* _frm_end = reinterpret_cast<const uint32_t*>(frm_end);
const uint32_t* _frm_nxt = _frm;
uint8_t* _to = reinterpret_cast<uint8_t*>(to);
uint8_t* _to_end = reinterpret_cast<uint8_t*>(to_end);
uint8_t* _to_nxt = _to;
result r = ucs4_to_utf16be(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt,
_Maxcode_, _Mode_);
frm_nxt = frm + (_frm_nxt - _frm);
to_nxt = to + (_to_nxt - _to);
return r;
}
__codecvt_utf16<char32_t, false>::result
__codecvt_utf16<char32_t, false>::do_in(state_type&,
const extern_type* frm, const extern_type* frm_end, const extern_type*& frm_nxt,
intern_type* to, intern_type* to_end, intern_type*& to_nxt) const
{
const uint8_t* _frm = reinterpret_cast<const uint8_t*>(frm);
const uint8_t* _frm_end = reinterpret_cast<const uint8_t*>(frm_end);
const uint8_t* _frm_nxt = _frm;
uint32_t* _to = reinterpret_cast<uint32_t*>(to);
uint32_t* _to_end = reinterpret_cast<uint32_t*>(to_end);
uint32_t* _to_nxt = _to;
result r = utf16be_to_ucs4(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt,
_Maxcode_, _Mode_);
frm_nxt = frm + (_frm_nxt - _frm);
to_nxt = to + (_to_nxt - _to);
return r;
}
__codecvt_utf16<char32_t, false>::result
__codecvt_utf16<char32_t, false>::do_unshift(state_type&,
extern_type* to, extern_type*, extern_type*& to_nxt) const
{
to_nxt = to;
return noconv;
}
int
__codecvt_utf16<char32_t, false>::do_encoding() const _NOEXCEPT
{
return 0;
}
bool
__codecvt_utf16<char32_t, false>::do_always_noconv() const _NOEXCEPT
{
return false;
}
int
__codecvt_utf16<char32_t, false>::do_length(state_type&,
const extern_type* frm, const extern_type* frm_end, size_t mx) const
{
const uint8_t* _frm = reinterpret_cast<const uint8_t*>(frm);
const uint8_t* _frm_end = reinterpret_cast<const uint8_t*>(frm_end);
return utf16be_to_ucs4_length(_frm, _frm_end, mx, _Maxcode_, _Mode_);
}
int
__codecvt_utf16<char32_t, false>::do_max_length() const _NOEXCEPT
{
if (_Mode_ & consume_header)
return 6;
return 4;
}
// __codecvt_utf16<char32_t, true>
__codecvt_utf16<char32_t, true>::result
__codecvt_utf16<char32_t, true>::do_out(state_type&,
const intern_type* frm, const intern_type* frm_end, const intern_type*& frm_nxt,
extern_type* to, extern_type* to_end, extern_type*& to_nxt) const
{
const uint32_t* _frm = reinterpret_cast<const uint32_t*>(frm);
const uint32_t* _frm_end = reinterpret_cast<const uint32_t*>(frm_end);
const uint32_t* _frm_nxt = _frm;
uint8_t* _to = reinterpret_cast<uint8_t*>(to);
uint8_t* _to_end = reinterpret_cast<uint8_t*>(to_end);
uint8_t* _to_nxt = _to;
result r = ucs4_to_utf16le(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt,
_Maxcode_, _Mode_);
frm_nxt = frm + (_frm_nxt - _frm);
to_nxt = to + (_to_nxt - _to);
return r;
}
__codecvt_utf16<char32_t, true>::result
__codecvt_utf16<char32_t, true>::do_in(state_type&,
const extern_type* frm, const extern_type* frm_end, const extern_type*& frm_nxt,
intern_type* to, intern_type* to_end, intern_type*& to_nxt) const
{
const uint8_t* _frm = reinterpret_cast<const uint8_t*>(frm);
const uint8_t* _frm_end = reinterpret_cast<const uint8_t*>(frm_end);
const uint8_t* _frm_nxt = _frm;
uint32_t* _to = reinterpret_cast<uint32_t*>(to);
uint32_t* _to_end = reinterpret_cast<uint32_t*>(to_end);
uint32_t* _to_nxt = _to;
result r = utf16le_to_ucs4(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt,
_Maxcode_, _Mode_);
frm_nxt = frm + (_frm_nxt - _frm);
to_nxt = to + (_to_nxt - _to);
return r;
}
__codecvt_utf16<char32_t, true>::result
__codecvt_utf16<char32_t, true>::do_unshift(state_type&,
extern_type* to, extern_type*, extern_type*& to_nxt) const
{
to_nxt = to;
return noconv;
}
int
__codecvt_utf16<char32_t, true>::do_encoding() const _NOEXCEPT
{
return 0;
}
bool
__codecvt_utf16<char32_t, true>::do_always_noconv() const _NOEXCEPT
{
return false;
}
int
__codecvt_utf16<char32_t, true>::do_length(state_type&,
const extern_type* frm, const extern_type* frm_end, size_t mx) const
{
const uint8_t* _frm = reinterpret_cast<const uint8_t*>(frm);
const uint8_t* _frm_end = reinterpret_cast<const uint8_t*>(frm_end);
return utf16le_to_ucs4_length(_frm, _frm_end, mx, _Maxcode_, _Mode_);
}
int
__codecvt_utf16<char32_t, true>::do_max_length() const _NOEXCEPT
{
if (_Mode_ & consume_header)
return 6;
return 4;
}
// __codecvt_utf8_utf16<wchar_t>
__codecvt_utf8_utf16<wchar_t>::result
__codecvt_utf8_utf16<wchar_t>::do_out(state_type&,
const intern_type* frm, const intern_type* frm_end, const intern_type*& frm_nxt,
extern_type* to, extern_type* to_end, extern_type*& to_nxt) const
{
const uint32_t* _frm = reinterpret_cast<const uint32_t*>(frm);
const uint32_t* _frm_end = reinterpret_cast<const uint32_t*>(frm_end);
const uint32_t* _frm_nxt = _frm;
uint8_t* _to = reinterpret_cast<uint8_t*>(to);
uint8_t* _to_end = reinterpret_cast<uint8_t*>(to_end);
uint8_t* _to_nxt = _to;
result r = utf16_to_utf8(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt,
_Maxcode_, _Mode_);
frm_nxt = frm + (_frm_nxt - _frm);
to_nxt = to + (_to_nxt - _to);
return r;
}
__codecvt_utf8_utf16<wchar_t>::result
__codecvt_utf8_utf16<wchar_t>::do_in(state_type&,
const extern_type* frm, const extern_type* frm_end, const extern_type*& frm_nxt,
intern_type* to, intern_type* to_end, intern_type*& to_nxt) const
{
const uint8_t* _frm = reinterpret_cast<const uint8_t*>(frm);
const uint8_t* _frm_end = reinterpret_cast<const uint8_t*>(frm_end);
const uint8_t* _frm_nxt = _frm;
uint32_t* _to = reinterpret_cast<uint32_t*>(to);
uint32_t* _to_end = reinterpret_cast<uint32_t*>(to_end);
uint32_t* _to_nxt = _to;
result r = utf8_to_utf16(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt,
_Maxcode_, _Mode_);
frm_nxt = frm + (_frm_nxt - _frm);
to_nxt = to + (_to_nxt - _to);
return r;
}
__codecvt_utf8_utf16<wchar_t>::result
__codecvt_utf8_utf16<wchar_t>::do_unshift(state_type&,
extern_type* to, extern_type*, extern_type*& to_nxt) const
{
to_nxt = to;
return noconv;
}
int
__codecvt_utf8_utf16<wchar_t>::do_encoding() const _NOEXCEPT
{
return 0;
}
bool
__codecvt_utf8_utf16<wchar_t>::do_always_noconv() const _NOEXCEPT
{
return false;
}
int
__codecvt_utf8_utf16<wchar_t>::do_length(state_type&,
const extern_type* frm, const extern_type* frm_end, size_t mx) const
{
const uint8_t* _frm = reinterpret_cast<const uint8_t*>(frm);
const uint8_t* _frm_end = reinterpret_cast<const uint8_t*>(frm_end);
return utf8_to_utf16_length(_frm, _frm_end, mx, _Maxcode_, _Mode_);
}
int
__codecvt_utf8_utf16<wchar_t>::do_max_length() const _NOEXCEPT
{
if (_Mode_ & consume_header)
return 7;
return 4;
}
// __codecvt_utf8_utf16<char16_t>
__codecvt_utf8_utf16<char16_t>::result
__codecvt_utf8_utf16<char16_t>::do_out(state_type&,
const intern_type* frm, const intern_type* frm_end, const intern_type*& frm_nxt,
extern_type* to, extern_type* to_end, extern_type*& to_nxt) const
{
const uint16_t* _frm = reinterpret_cast<const uint16_t*>(frm);
const uint16_t* _frm_end = reinterpret_cast<const uint16_t*>(frm_end);
const uint16_t* _frm_nxt = _frm;
uint8_t* _to = reinterpret_cast<uint8_t*>(to);
uint8_t* _to_end = reinterpret_cast<uint8_t*>(to_end);
uint8_t* _to_nxt = _to;
result r = utf16_to_utf8(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt,
_Maxcode_, _Mode_);
frm_nxt = frm + (_frm_nxt - _frm);
to_nxt = to + (_to_nxt - _to);
return r;
}
__codecvt_utf8_utf16<char16_t>::result
__codecvt_utf8_utf16<char16_t>::do_in(state_type&,
const extern_type* frm, const extern_type* frm_end, const extern_type*& frm_nxt,
intern_type* to, intern_type* to_end, intern_type*& to_nxt) const
{
const uint8_t* _frm = reinterpret_cast<const uint8_t*>(frm);
const uint8_t* _frm_end = reinterpret_cast<const uint8_t*>(frm_end);
const uint8_t* _frm_nxt = _frm;
uint16_t* _to = reinterpret_cast<uint16_t*>(to);
uint16_t* _to_end = reinterpret_cast<uint16_t*>(to_end);
uint16_t* _to_nxt = _to;
result r = utf8_to_utf16(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt,
_Maxcode_, _Mode_);
frm_nxt = frm + (_frm_nxt - _frm);
to_nxt = to + (_to_nxt - _to);
return r;
}
__codecvt_utf8_utf16<char16_t>::result
__codecvt_utf8_utf16<char16_t>::do_unshift(state_type&,
extern_type* to, extern_type*, extern_type*& to_nxt) const
{
to_nxt = to;
return noconv;
}
int
__codecvt_utf8_utf16<char16_t>::do_encoding() const _NOEXCEPT
{
return 0;
}
bool
__codecvt_utf8_utf16<char16_t>::do_always_noconv() const _NOEXCEPT
{
return false;
}
int
__codecvt_utf8_utf16<char16_t>::do_length(state_type&,
const extern_type* frm, const extern_type* frm_end, size_t mx) const
{
const uint8_t* _frm = reinterpret_cast<const uint8_t*>(frm);
const uint8_t* _frm_end = reinterpret_cast<const uint8_t*>(frm_end);
return utf8_to_utf16_length(_frm, _frm_end, mx, _Maxcode_, _Mode_);
}
int
__codecvt_utf8_utf16<char16_t>::do_max_length() const _NOEXCEPT
{
if (_Mode_ & consume_header)
return 7;
return 4;
}
// __codecvt_utf8_utf16<char32_t>
__codecvt_utf8_utf16<char32_t>::result
__codecvt_utf8_utf16<char32_t>::do_out(state_type&,
const intern_type* frm, const intern_type* frm_end, const intern_type*& frm_nxt,
extern_type* to, extern_type* to_end, extern_type*& to_nxt) const
{
const uint32_t* _frm = reinterpret_cast<const uint32_t*>(frm);
const uint32_t* _frm_end = reinterpret_cast<const uint32_t*>(frm_end);
const uint32_t* _frm_nxt = _frm;
uint8_t* _to = reinterpret_cast<uint8_t*>(to);
uint8_t* _to_end = reinterpret_cast<uint8_t*>(to_end);
uint8_t* _to_nxt = _to;
result r = utf16_to_utf8(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt,
_Maxcode_, _Mode_);
frm_nxt = frm + (_frm_nxt - _frm);
to_nxt = to + (_to_nxt - _to);
return r;
}
__codecvt_utf8_utf16<char32_t>::result
__codecvt_utf8_utf16<char32_t>::do_in(state_type&,
const extern_type* frm, const extern_type* frm_end, const extern_type*& frm_nxt,
intern_type* to, intern_type* to_end, intern_type*& to_nxt) const
{
const uint8_t* _frm = reinterpret_cast<const uint8_t*>(frm);
const uint8_t* _frm_end = reinterpret_cast<const uint8_t*>(frm_end);
const uint8_t* _frm_nxt = _frm;
uint32_t* _to = reinterpret_cast<uint32_t*>(to);
uint32_t* _to_end = reinterpret_cast<uint32_t*>(to_end);
uint32_t* _to_nxt = _to;
result r = utf8_to_utf16(_frm, _frm_end, _frm_nxt, _to, _to_end, _to_nxt,
_Maxcode_, _Mode_);
frm_nxt = frm + (_frm_nxt - _frm);
to_nxt = to + (_to_nxt - _to);
return r;
}
__codecvt_utf8_utf16<char32_t>::result
__codecvt_utf8_utf16<char32_t>::do_unshift(state_type&,
extern_type* to, extern_type*, extern_type*& to_nxt) const
{
to_nxt = to;
return noconv;
}
int
__codecvt_utf8_utf16<char32_t>::do_encoding() const _NOEXCEPT
{
return 0;
}
bool
__codecvt_utf8_utf16<char32_t>::do_always_noconv() const _NOEXCEPT
{
return false;
}
int
__codecvt_utf8_utf16<char32_t>::do_length(state_type&,
const extern_type* frm, const extern_type* frm_end, size_t mx) const
{
const uint8_t* _frm = reinterpret_cast<const uint8_t*>(frm);
const uint8_t* _frm_end = reinterpret_cast<const uint8_t*>(frm_end);
return utf8_to_utf16_length(_frm, _frm_end, mx, _Maxcode_, _Mode_);
}
int
__codecvt_utf8_utf16<char32_t>::do_max_length() const _NOEXCEPT
{
if (_Mode_ & consume_header)
return 7;
return 4;
}
// __narrow_to_utf8<16>
__narrow_to_utf8<16>::~__narrow_to_utf8()
{
}
// __narrow_to_utf8<32>
__narrow_to_utf8<32>::~__narrow_to_utf8()
{
}
// __widen_from_utf8<16>
__widen_from_utf8<16>::~__widen_from_utf8()
{
}
// __widen_from_utf8<32>
__widen_from_utf8<32>::~__widen_from_utf8()
{
}
bool __checked_string_to_wchar_convert(wchar_t& dest,
const char* ptr,
locale_t loc) {
if (*ptr == '\0')
return false;
mbstate_t mb = {};
wchar_t out;
size_t ret = __libcpp_mbrtowc_l(&out, ptr, strlen(ptr), &mb, loc);
if (ret == static_cast<size_t>(-1) || ret == static_cast<size_t>(-2)) {
return false;
}
dest = out;
return true;
}
bool __checked_string_to_char_convert(char& dest,
const char* ptr,
locale_t __loc) {
if (*ptr == '\0')
return false;
if (!ptr[1]) {
dest = *ptr;
return true;
}
// First convert the MBS into a wide char then attempt to narrow it using
// wctob_l.
wchar_t wout;
if (!__checked_string_to_wchar_convert(wout, ptr, __loc))
return false;
int res;
if ((res = __libcpp_wctob_l(wout, __loc)) != char_traits<char>::eof()) {
dest = res;
return true;
}
// FIXME: Work around specific multibyte sequences that we can reasonable
// translate into a different single byte.
switch (wout) {
case L'\u202F': // narrow non-breaking space
case L'\u00A0': // non-breaking space
dest = ' ';
return true;
default:
return false;
}
_LIBCPP_UNREACHABLE();
}
// numpunct<char> && numpunct<wchar_t>
locale::id numpunct< char >::id;
locale::id numpunct<wchar_t>::id;
numpunct<char>::numpunct(size_t refs)
: locale::facet(refs),
__decimal_point_('.'),
__thousands_sep_(',')
{
}
numpunct<wchar_t>::numpunct(size_t refs)
: locale::facet(refs),
__decimal_point_(L'.'),
__thousands_sep_(L',')
{
}
numpunct<char>::~numpunct()
{
}
numpunct<wchar_t>::~numpunct()
{
}
char numpunct< char >::do_decimal_point() const {return __decimal_point_;}
wchar_t numpunct<wchar_t>::do_decimal_point() const {return __decimal_point_;}
char numpunct< char >::do_thousands_sep() const {return __thousands_sep_;}
wchar_t numpunct<wchar_t>::do_thousands_sep() const {return __thousands_sep_;}
string numpunct< char >::do_grouping() const {return __grouping_;}
string numpunct<wchar_t>::do_grouping() const {return __grouping_;}
string numpunct< char >::do_truename() const {return "true";}
wstring numpunct<wchar_t>::do_truename() const {return L"true";}
string numpunct< char >::do_falsename() const {return "false";}
wstring numpunct<wchar_t>::do_falsename() const {return L"false";}
// numpunct_byname<char>
numpunct_byname<char>::numpunct_byname(const char* nm, size_t refs)
: numpunct<char>(refs)
{
__init(nm);
}
numpunct_byname<char>::numpunct_byname(const string& nm, size_t refs)
: numpunct<char>(refs)
{
__init(nm.c_str());
}
numpunct_byname<char>::~numpunct_byname()
{
}
void
numpunct_byname<char>::__init(const char* nm)
{
if (strcmp(nm, "C") != 0)
{
__libcpp_unique_locale loc(nm);
if (!loc)
__throw_runtime_error("numpunct_byname<char>::numpunct_byname"
" failed to construct for " + string(nm));
lconv* lc = __libcpp_localeconv_l(loc.get());
__checked_string_to_char_convert(__decimal_point_, lc->decimal_point,
loc.get());
__checked_string_to_char_convert(__thousands_sep_, lc->thousands_sep,
loc.get());
__grouping_ = lc->grouping;
// localization for truename and falsename is not available
}
}
// numpunct_byname<wchar_t>
numpunct_byname<wchar_t>::numpunct_byname(const char* nm, size_t refs)
: numpunct<wchar_t>(refs)
{
__init(nm);
}
numpunct_byname<wchar_t>::numpunct_byname(const string& nm, size_t refs)
: numpunct<wchar_t>(refs)
{
__init(nm.c_str());
}
numpunct_byname<wchar_t>::~numpunct_byname()
{
}
void
numpunct_byname<wchar_t>::__init(const char* nm)
{
if (strcmp(nm, "C") != 0)
{
__libcpp_unique_locale loc(nm);
if (!loc)
__throw_runtime_error("numpunct_byname<wchar_t>::numpunct_byname"
" failed to construct for " + string(nm));
lconv* lc = __libcpp_localeconv_l(loc.get());
__checked_string_to_wchar_convert(__decimal_point_, lc->decimal_point,
loc.get());
__checked_string_to_wchar_convert(__thousands_sep_, lc->thousands_sep,
loc.get());
__grouping_ = lc->grouping;
// localization for truename and falsename is not available
}
}
// num_get helpers
int
__num_get_base::__get_base(ios_base& iob)
{
ios_base::fmtflags __basefield = iob.flags() & ios_base::basefield;
if (__basefield == ios_base::oct)
return 8;
else if (__basefield == ios_base::hex)
return 16;
else if (__basefield == 0)
return 0;
return 10;
}
const char __num_get_base::__src[33] = "0123456789abcdefABCDEFxX+-pPiInN";
void
__check_grouping(const string& __grouping, unsigned* __g, unsigned* __g_end,
ios_base::iostate& __err)
{
// if the grouping pattern is empty _or_ there are no grouping bits, then do nothing
// we always have at least a single entry in [__g, __g_end); the end of the input sequence
if (__grouping.size() != 0 && __g_end - __g > 1)
{
reverse(__g, __g_end);
const char* __ig = __grouping.data();
const char* __eg = __ig + __grouping.size();
for (unsigned* __r = __g; __r < __g_end-1; ++__r)
{
if (0 < *__ig && *__ig < numeric_limits<char>::max())
{
if (static_cast<unsigned>(*__ig) != *__r)
{
__err = ios_base::failbit;
return;
}
}
if (__eg - __ig > 1)
++__ig;
}
if (0 < *__ig && *__ig < numeric_limits<char>::max())
{
if (static_cast<unsigned>(*__ig) < __g_end[-1] || __g_end[-1] == 0)
__err = ios_base::failbit;
}
}
}
void
__num_put_base::__format_int(char* __fmtp, const char* __len, bool __signd,
ios_base::fmtflags __flags)
{
if (__flags & ios_base::showpos)
*__fmtp++ = '+';
if (__flags & ios_base::showbase)
*__fmtp++ = '#';
while(*__len)
*__fmtp++ = *__len++;
if ((__flags & ios_base::basefield) == ios_base::oct)
*__fmtp = 'o';
else if ((__flags & ios_base::basefield) == ios_base::hex)
{
if (__flags & ios_base::uppercase)
*__fmtp = 'X';
else
*__fmtp = 'x';
}
else if (__signd)
*__fmtp = 'd';
else
*__fmtp = 'u';
}
bool
__num_put_base::__format_float(char* __fmtp, const char* __len,
ios_base::fmtflags __flags)
{
bool specify_precision = true;
if (__flags & ios_base::showpos)
*__fmtp++ = '+';
if (__flags & ios_base::showpoint)
*__fmtp++ = '#';
ios_base::fmtflags floatfield = __flags & ios_base::floatfield;
bool uppercase = (__flags & ios_base::uppercase) != 0;
if (floatfield == (ios_base::fixed | ios_base::scientific))
specify_precision = false;
else
{
*__fmtp++ = '.';
*__fmtp++ = '*';
}
while(*__len)
*__fmtp++ = *__len++;
if (floatfield == ios_base::fixed)
{
if (uppercase)
*__fmtp = 'F';
else
*__fmtp = 'f';
}
else if (floatfield == ios_base::scientific)
{
if (uppercase)
*__fmtp = 'E';
else
*__fmtp = 'e';
}
else if (floatfield == (ios_base::fixed | ios_base::scientific))
{
if (uppercase)
*__fmtp = 'A';
else
*__fmtp = 'a';
}
else
{
if (uppercase)
*__fmtp = 'G';
else
*__fmtp = 'g';
}
return specify_precision;
}
char*
__num_put_base::__identify_padding(char* __nb, char* __ne,
const ios_base& __iob)
{
switch (__iob.flags() & ios_base::adjustfield)
{
case ios_base::internal:
if (__nb[0] == '-' || __nb[0] == '+')
return __nb+1;
if (__ne - __nb >= 2 && __nb[0] == '0'
&& (__nb[1] == 'x' || __nb[1] == 'X'))
return __nb+2;
break;
case ios_base::left:
return __ne;
case ios_base::right:
default:
break;
}
return __nb;
}
void __do_nothing(void*) {}
void __throw_runtime_error(const char* msg)
{
#ifndef _LIBCPP_NO_EXCEPTIONS
throw runtime_error(msg);
#else
(void)msg;
_VSTD::abort();
#endif
}
template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS collate<char>;
template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS collate<wchar_t>;
template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS num_get<char>;
template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS num_get<wchar_t>;
template struct _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS __num_get<char>;
template struct _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS __num_get<wchar_t>;
template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS num_put<char>;
template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS num_put<wchar_t>;
template struct _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS __num_put<char>;
template struct _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS __num_put<wchar_t>;
template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS messages<char>;
template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS messages<wchar_t>;
template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS messages_byname<char>;
template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS messages_byname<wchar_t>;
template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS codecvt_byname<char, char, mbstate_t>;
template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS codecvt_byname<wchar_t, char, mbstate_t>;
template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS codecvt_byname<char16_t, char, mbstate_t>;
template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS codecvt_byname<char32_t, char, mbstate_t>;
_LIBCPP_END_NAMESPACE_STD
| 94,337 | 2,905 | jart/cosmopolitan | false |
cosmopolitan/third_party/libcxx/random.cc | //===-------------------------- random.cpp --------------------------------===//
//
// 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
//
//===----------------------------------------------------------------------===//
#include "libc/stdio/rand.h"
#include "third_party/libcxx/__config"
#include "third_party/libcxx/random"
#include "third_party/libcxx/system_error"
#include "third_party/libcxx/errno.h"
#include "third_party/libcxx/stdio.h"
#include "third_party/libcxx/stdlib.h"
_LIBCPP_BEGIN_NAMESPACE_STD
#if defined(_LIBCPP_USING_GETENTROPY)
random_device::random_device(const string& __token) {
if (__token != "/dev/urandom")
__throw_system_error(ENOENT,
("random device not supported " + __token).c_str());
}
random_device::~random_device() {}
unsigned random_device::operator()() {
unsigned r;
size_t n = sizeof(r);
int err = getentropy(&r, n);
if (err)
__throw_system_error(errno, "random_device getentropy failed");
return r;
}
#elif defined(_LIBCPP_USING_ARC4_RANDOM)
random_device::random_device(const string& __token) {
if (__token != "/dev/urandom")
__throw_system_error(ENOENT,
("random device not supported " + __token).c_str());
}
random_device::~random_device() {}
unsigned random_device::operator()() { return arc4random(); }
#elif defined(_LIBCPP_USING_DEV_RANDOM)
random_device::random_device(const string& __token)
: __f_(open(__token.c_str(), O_RDONLY)) {
if (__f_ < 0)
__throw_system_error(errno,
("random_device failed to open " + __token).c_str());
}
random_device::~random_device() { close(__f_); }
unsigned random_device::operator()() {
unsigned r;
size_t n = sizeof(r);
char* p = reinterpret_cast<char*>(&r);
while (n > 0) {
ssize_t s = read(__f_, p, n);
if (s == 0)
__throw_system_error(ENODATA, "random_device got EOF");
if (s == -1) {
if (errno != EINTR)
__throw_system_error(errno, "random_device got an unexpected error");
continue;
}
n -= static_cast<size_t>(s);
p += static_cast<size_t>(s);
}
return r;
}
#elif defined(_LIBCPP_USING_NACL_RANDOM)
random_device::random_device(const string& __token) {
if (__token != "/dev/urandom")
__throw_system_error(ENOENT,
("random device not supported " + __token).c_str());
int error = nacl_secure_random_init();
if (error)
__throw_system_error(error,
("random device failed to open " + __token).c_str());
}
random_device::~random_device() {}
unsigned random_device::operator()() {
unsigned r;
size_t n = sizeof(r);
size_t bytes_written;
int error = nacl_secure_random(&r, n, &bytes_written);
if (error != 0)
__throw_system_error(error, "random_device failed getting bytes");
else if (bytes_written != n)
__throw_runtime_error("random_device failed to obtain enough bytes");
return r;
}
#elif defined(_LIBCPP_USING_WIN32_RANDOM)
random_device::random_device(const string& __token) {
if (__token != "/dev/urandom")
__throw_system_error(ENOENT,
("random device not supported " + __token).c_str());
}
random_device::~random_device() {}
unsigned random_device::operator()() {
unsigned r;
errno_t err = rand_s(&r);
if (err)
__throw_system_error(err, "random_device rand_s failed.");
return r;
}
#else
#error "Random device not implemented for this architecture"
#endif
double random_device::entropy() const _NOEXCEPT { return 0; }
_LIBCPP_END_NAMESPACE_STD
| 3,705 | 131 | jart/cosmopolitan | false |
cosmopolitan/third_party/libcxx/sstream | // -*- C++ -*-
//===--------------------------- sstream ----------------------------------===//
//
// 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_SSTREAM
#define _LIBCPP_SSTREAM
#include "third_party/libcxx/__config"
#include "third_party/libcxx/ostream"
#include "third_party/libcxx/istream"
#include "third_party/libcxx/string"
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
#pragma GCC system_header
#endif
_LIBCPP_PUSH_MACROS
#include "third_party/libcxx/__undef_macros"
_LIBCPP_BEGIN_NAMESPACE_STD
/*
sstream synopsis
template <class charT, class traits = char_traits<charT>, class Allocator = allocator<charT> >
class basic_stringbuf
: public basic_streambuf<charT, traits>
{
public:
typedef charT char_type;
typedef traits traits_type;
typedef typename traits_type::int_type int_type;
typedef typename traits_type::pos_type pos_type;
typedef typename traits_type::off_type off_type;
typedef Allocator allocator_type;
// 27.8.1.1 Constructors:
explicit basic_stringbuf(ios_base::openmode which = ios_base::in | ios_base::out);
explicit basic_stringbuf(const basic_string<char_type, traits_type, allocator_type>& str,
ios_base::openmode which = ios_base::in | ios_base::out);
basic_stringbuf(basic_stringbuf&& rhs);
// 27.8.1.2 Assign and swap:
basic_stringbuf& operator=(basic_stringbuf&& rhs);
void swap(basic_stringbuf& rhs);
// 27.8.1.3 Get and set:
basic_string<char_type, traits_type, allocator_type> str() const;
void str(const basic_string<char_type, traits_type, allocator_type>& s);
protected:
// 27.8.1.4 Overridden virtual functions:
virtual int_type underflow();
virtual int_type pbackfail(int_type c = traits_type::eof());
virtual int_type overflow (int_type c = traits_type::eof());
virtual basic_streambuf<char_type, traits_type>* setbuf(char_type*, streamsize);
virtual pos_type seekoff(off_type off, ios_base::seekdir way,
ios_base::openmode which = ios_base::in | ios_base::out);
virtual pos_type seekpos(pos_type sp,
ios_base::openmode which = ios_base::in | ios_base::out);
};
template <class charT, class traits, class Allocator>
void swap(basic_stringbuf<charT, traits, Allocator>& x,
basic_stringbuf<charT, traits, Allocator>& y);
typedef basic_stringbuf<char> stringbuf;
typedef basic_stringbuf<wchar_t> wstringbuf;
template <class charT, class traits = char_traits<charT>, class Allocator = allocator<charT> >
class basic_istringstream
: public basic_istream<charT, traits>
{
public:
typedef charT char_type;
typedef traits traits_type;
typedef typename traits_type::int_type int_type;
typedef typename traits_type::pos_type pos_type;
typedef typename traits_type::off_type off_type;
typedef Allocator allocator_type;
// 27.8.2.1 Constructors:
explicit basic_istringstream(ios_base::openmode which = ios_base::in);
explicit basic_istringstream(const basic_string<char_type, traits_type,allocator_type>& str,
ios_base::openmode which = ios_base::in);
basic_istringstream(basic_istringstream&& rhs);
// 27.8.2.2 Assign and swap:
basic_istringstream& operator=(basic_istringstream&& rhs);
void swap(basic_istringstream& rhs);
// 27.8.2.3 Members:
basic_stringbuf<char_type, traits_type, allocator_type>* rdbuf() const;
basic_string<char_type, traits_type, allocator_type> str() const;
void str(const basic_string<char_type, traits_type, allocator_type>& s);
};
template <class charT, class traits, class Allocator>
void swap(basic_istringstream<charT, traits, Allocator>& x,
basic_istringstream<charT, traits, Allocator>& y);
typedef basic_istringstream<char> istringstream;
typedef basic_istringstream<wchar_t> wistringstream;
template <class charT, class traits = char_traits<charT>, class Allocator = allocator<charT> >
class basic_ostringstream
: public basic_ostream<charT, traits>
{
public:
// types:
typedef charT char_type;
typedef traits traits_type;
typedef typename traits_type::int_type int_type;
typedef typename traits_type::pos_type pos_type;
typedef typename traits_type::off_type off_type;
typedef Allocator allocator_type;
// 27.8.3.1 Constructors/destructor:
explicit basic_ostringstream(ios_base::openmode which = ios_base::out);
explicit basic_ostringstream(const basic_string<char_type, traits_type, allocator_type>& str,
ios_base::openmode which = ios_base::out);
basic_ostringstream(basic_ostringstream&& rhs);
// 27.8.3.2 Assign/swap:
basic_ostringstream& operator=(basic_ostringstream&& rhs);
void swap(basic_ostringstream& rhs);
// 27.8.3.3 Members:
basic_stringbuf<char_type, traits_type, allocator_type>* rdbuf() const;
basic_string<char_type, traits_type, allocator_type> str() const;
void str(const basic_string<char_type, traits_type, allocator_type>& s);
};
template <class charT, class traits, class Allocator>
void swap(basic_ostringstream<charT, traits, Allocator>& x,
basic_ostringstream<charT, traits, Allocator>& y);
typedef basic_ostringstream<char> ostringstream;
typedef basic_ostringstream<wchar_t> wostringstream;
template <class charT, class traits = char_traits<charT>, class Allocator = allocator<charT> >
class basic_stringstream
: public basic_iostream<charT, traits>
{
public:
// types:
typedef charT char_type;
typedef traits traits_type;
typedef typename traits_type::int_type int_type;
typedef typename traits_type::pos_type pos_type;
typedef typename traits_type::off_type off_type;
typedef Allocator allocator_type;
// constructors/destructor
explicit basic_stringstream(ios_base::openmode which = ios_base::out|ios_base::in);
explicit basic_stringstream(const basic_string<char_type, traits_type, allocator_type>& str,
ios_base::openmode which = ios_base::out|ios_base::in);
basic_stringstream(basic_stringstream&& rhs);
// 27.8.5.1 Assign/swap:
basic_stringstream& operator=(basic_stringstream&& rhs);
void swap(basic_stringstream& rhs);
// Members:
basic_stringbuf<char_type, traits_type, allocator_type>* rdbuf() const;
basic_string<char_type, traits_type, allocator_type> str() const;
void str(const basic_string<char_type, traits_type, allocator_type>& str);
};
template <class charT, class traits, class Allocator>
void swap(basic_stringstream<charT, traits, Allocator>& x,
basic_stringstream<charT, traits, Allocator>& y);
typedef basic_stringstream<char> stringstream;
typedef basic_stringstream<wchar_t> wstringstream;
} // std
*/
// basic_stringbuf
template <class _CharT, class _Traits, class _Allocator>
class _LIBCPP_TEMPLATE_VIS basic_stringbuf
: public basic_streambuf<_CharT, _Traits>
{
public:
typedef _CharT char_type;
typedef _Traits traits_type;
typedef typename traits_type::int_type int_type;
typedef typename traits_type::pos_type pos_type;
typedef typename traits_type::off_type off_type;
typedef _Allocator allocator_type;
typedef basic_string<char_type, traits_type, allocator_type> string_type;
private:
string_type __str_;
mutable char_type* __hm_;
ios_base::openmode __mode_;
public:
// 27.8.1.1 Constructors:
inline _LIBCPP_INLINE_VISIBILITY
explicit basic_stringbuf(ios_base::openmode __wch = ios_base::in | ios_base::out);
inline _LIBCPP_INLINE_VISIBILITY
explicit basic_stringbuf(const string_type& __s,
ios_base::openmode __wch = ios_base::in | ios_base::out);
#ifndef _LIBCPP_CXX03_LANG
basic_stringbuf(basic_stringbuf&& __rhs);
// 27.8.1.2 Assign and swap:
basic_stringbuf& operator=(basic_stringbuf&& __rhs);
#endif
void swap(basic_stringbuf& __rhs);
// 27.8.1.3 Get and set:
string_type str() const;
void str(const string_type& __s);
protected:
// 27.8.1.4 Overridden virtual functions:
virtual int_type underflow();
virtual int_type pbackfail(int_type __c = traits_type::eof());
virtual int_type overflow (int_type __c = traits_type::eof());
virtual pos_type seekoff(off_type __off, ios_base::seekdir __way,
ios_base::openmode __wch = ios_base::in | ios_base::out);
inline _LIBCPP_INLINE_VISIBILITY
virtual pos_type seekpos(pos_type __sp,
ios_base::openmode __wch = ios_base::in | ios_base::out);
};
template <class _CharT, class _Traits, class _Allocator>
basic_stringbuf<_CharT, _Traits, _Allocator>::basic_stringbuf(ios_base::openmode __wch)
: __hm_(0),
__mode_(__wch)
{
}
template <class _CharT, class _Traits, class _Allocator>
basic_stringbuf<_CharT, _Traits, _Allocator>::basic_stringbuf(const string_type& __s,
ios_base::openmode __wch)
: __str_(__s.get_allocator()),
__hm_(0),
__mode_(__wch)
{
str(__s);
}
#ifndef _LIBCPP_CXX03_LANG
template <class _CharT, class _Traits, class _Allocator>
basic_stringbuf<_CharT, _Traits, _Allocator>::basic_stringbuf(basic_stringbuf&& __rhs)
: __mode_(__rhs.__mode_)
{
char_type* __p = const_cast<char_type*>(__rhs.__str_.data());
ptrdiff_t __binp = -1;
ptrdiff_t __ninp = -1;
ptrdiff_t __einp = -1;
if (__rhs.eback() != nullptr)
{
__binp = __rhs.eback() - __p;
__ninp = __rhs.gptr() - __p;
__einp = __rhs.egptr() - __p;
}
ptrdiff_t __bout = -1;
ptrdiff_t __nout = -1;
ptrdiff_t __eout = -1;
if (__rhs.pbase() != nullptr)
{
__bout = __rhs.pbase() - __p;
__nout = __rhs.pptr() - __p;
__eout = __rhs.epptr() - __p;
}
ptrdiff_t __hm = __rhs.__hm_ == nullptr ? -1 : __rhs.__hm_ - __p;
__str_ = _VSTD::move(__rhs.__str_);
__p = const_cast<char_type*>(__str_.data());
if (__binp != -1)
this->setg(__p + __binp, __p + __ninp, __p + __einp);
if (__bout != -1)
{
this->setp(__p + __bout, __p + __eout);
this->__pbump(__nout);
}
__hm_ = __hm == -1 ? nullptr : __p + __hm;
__p = const_cast<char_type*>(__rhs.__str_.data());
__rhs.setg(__p, __p, __p);
__rhs.setp(__p, __p);
__rhs.__hm_ = __p;
this->pubimbue(__rhs.getloc());
}
template <class _CharT, class _Traits, class _Allocator>
basic_stringbuf<_CharT, _Traits, _Allocator>&
basic_stringbuf<_CharT, _Traits, _Allocator>::operator=(basic_stringbuf&& __rhs)
{
char_type* __p = const_cast<char_type*>(__rhs.__str_.data());
ptrdiff_t __binp = -1;
ptrdiff_t __ninp = -1;
ptrdiff_t __einp = -1;
if (__rhs.eback() != nullptr)
{
__binp = __rhs.eback() - __p;
__ninp = __rhs.gptr() - __p;
__einp = __rhs.egptr() - __p;
}
ptrdiff_t __bout = -1;
ptrdiff_t __nout = -1;
ptrdiff_t __eout = -1;
if (__rhs.pbase() != nullptr)
{
__bout = __rhs.pbase() - __p;
__nout = __rhs.pptr() - __p;
__eout = __rhs.epptr() - __p;
}
ptrdiff_t __hm = __rhs.__hm_ == nullptr ? -1 : __rhs.__hm_ - __p;
__str_ = _VSTD::move(__rhs.__str_);
__p = const_cast<char_type*>(__str_.data());
if (__binp != -1)
this->setg(__p + __binp, __p + __ninp, __p + __einp);
else
this->setg(nullptr, nullptr, nullptr);
if (__bout != -1)
{
this->setp(__p + __bout, __p + __eout);
this->__pbump(__nout);
}
else
this->setp(nullptr, nullptr);
__hm_ = __hm == -1 ? nullptr : __p + __hm;
__mode_ = __rhs.__mode_;
__p = const_cast<char_type*>(__rhs.__str_.data());
__rhs.setg(__p, __p, __p);
__rhs.setp(__p, __p);
__rhs.__hm_ = __p;
this->pubimbue(__rhs.getloc());
return *this;
}
#endif // _LIBCPP_CXX03_LANG
template <class _CharT, class _Traits, class _Allocator>
void
basic_stringbuf<_CharT, _Traits, _Allocator>::swap(basic_stringbuf& __rhs)
{
char_type* __p = const_cast<char_type*>(__rhs.__str_.data());
ptrdiff_t __rbinp = -1;
ptrdiff_t __rninp = -1;
ptrdiff_t __reinp = -1;
if (__rhs.eback() != nullptr)
{
__rbinp = __rhs.eback() - __p;
__rninp = __rhs.gptr() - __p;
__reinp = __rhs.egptr() - __p;
}
ptrdiff_t __rbout = -1;
ptrdiff_t __rnout = -1;
ptrdiff_t __reout = -1;
if (__rhs.pbase() != nullptr)
{
__rbout = __rhs.pbase() - __p;
__rnout = __rhs.pptr() - __p;
__reout = __rhs.epptr() - __p;
}
ptrdiff_t __rhm = __rhs.__hm_ == nullptr ? -1 : __rhs.__hm_ - __p;
__p = const_cast<char_type*>(__str_.data());
ptrdiff_t __lbinp = -1;
ptrdiff_t __lninp = -1;
ptrdiff_t __leinp = -1;
if (this->eback() != nullptr)
{
__lbinp = this->eback() - __p;
__lninp = this->gptr() - __p;
__leinp = this->egptr() - __p;
}
ptrdiff_t __lbout = -1;
ptrdiff_t __lnout = -1;
ptrdiff_t __leout = -1;
if (this->pbase() != nullptr)
{
__lbout = this->pbase() - __p;
__lnout = this->pptr() - __p;
__leout = this->epptr() - __p;
}
ptrdiff_t __lhm = __hm_ == nullptr ? -1 : __hm_ - __p;
_VSTD::swap(__mode_, __rhs.__mode_);
__str_.swap(__rhs.__str_);
__p = const_cast<char_type*>(__str_.data());
if (__rbinp != -1)
this->setg(__p + __rbinp, __p + __rninp, __p + __reinp);
else
this->setg(nullptr, nullptr, nullptr);
if (__rbout != -1)
{
this->setp(__p + __rbout, __p + __reout);
this->__pbump(__rnout);
}
else
this->setp(nullptr, nullptr);
__hm_ = __rhm == -1 ? nullptr : __p + __rhm;
__p = const_cast<char_type*>(__rhs.__str_.data());
if (__lbinp != -1)
__rhs.setg(__p + __lbinp, __p + __lninp, __p + __leinp);
else
__rhs.setg(nullptr, nullptr, nullptr);
if (__lbout != -1)
{
__rhs.setp(__p + __lbout, __p + __leout);
__rhs.__pbump(__lnout);
}
else
__rhs.setp(nullptr, nullptr);
__rhs.__hm_ = __lhm == -1 ? nullptr : __p + __lhm;
locale __tl = __rhs.getloc();
__rhs.pubimbue(this->getloc());
this->pubimbue(__tl);
}
template <class _CharT, class _Traits, class _Allocator>
inline _LIBCPP_INLINE_VISIBILITY
void
swap(basic_stringbuf<_CharT, _Traits, _Allocator>& __x,
basic_stringbuf<_CharT, _Traits, _Allocator>& __y)
{
__x.swap(__y);
}
template <class _CharT, class _Traits, class _Allocator>
basic_string<_CharT, _Traits, _Allocator>
basic_stringbuf<_CharT, _Traits, _Allocator>::str() const
{
if (__mode_ & ios_base::out)
{
if (__hm_ < this->pptr())
__hm_ = this->pptr();
return string_type(this->pbase(), __hm_, __str_.get_allocator());
}
else if (__mode_ & ios_base::in)
return string_type(this->eback(), this->egptr(), __str_.get_allocator());
return string_type(__str_.get_allocator());
}
template <class _CharT, class _Traits, class _Allocator>
void
basic_stringbuf<_CharT, _Traits, _Allocator>::str(const string_type& __s)
{
__str_ = __s;
__hm_ = 0;
if (__mode_ & ios_base::in)
{
__hm_ = const_cast<char_type*>(__str_.data()) + __str_.size();
this->setg(const_cast<char_type*>(__str_.data()),
const_cast<char_type*>(__str_.data()),
__hm_);
}
if (__mode_ & ios_base::out)
{
typename string_type::size_type __sz = __str_.size();
__hm_ = const_cast<char_type*>(__str_.data()) + __sz;
__str_.resize(__str_.capacity());
this->setp(const_cast<char_type*>(__str_.data()),
const_cast<char_type*>(__str_.data()) + __str_.size());
if (__mode_ & (ios_base::app | ios_base::ate))
{
while (__sz > INT_MAX)
{
this->pbump(INT_MAX);
__sz -= INT_MAX;
}
if (__sz > 0)
this->pbump(__sz);
}
}
}
template <class _CharT, class _Traits, class _Allocator>
typename basic_stringbuf<_CharT, _Traits, _Allocator>::int_type
basic_stringbuf<_CharT, _Traits, _Allocator>::underflow()
{
if (__hm_ < this->pptr())
__hm_ = this->pptr();
if (__mode_ & ios_base::in)
{
if (this->egptr() < __hm_)
this->setg(this->eback(), this->gptr(), __hm_);
if (this->gptr() < this->egptr())
return traits_type::to_int_type(*this->gptr());
}
return traits_type::eof();
}
template <class _CharT, class _Traits, class _Allocator>
typename basic_stringbuf<_CharT, _Traits, _Allocator>::int_type
basic_stringbuf<_CharT, _Traits, _Allocator>::pbackfail(int_type __c)
{
if (__hm_ < this->pptr())
__hm_ = this->pptr();
if (this->eback() < this->gptr())
{
if (traits_type::eq_int_type(__c, traits_type::eof()))
{
this->setg(this->eback(), this->gptr()-1, __hm_);
return traits_type::not_eof(__c);
}
if ((__mode_ & ios_base::out) ||
traits_type::eq(traits_type::to_char_type(__c), this->gptr()[-1]))
{
this->setg(this->eback(), this->gptr()-1, __hm_);
*this->gptr() = traits_type::to_char_type(__c);
return __c;
}
}
return traits_type::eof();
}
template <class _CharT, class _Traits, class _Allocator>
typename basic_stringbuf<_CharT, _Traits, _Allocator>::int_type
basic_stringbuf<_CharT, _Traits, _Allocator>::overflow(int_type __c)
{
if (!traits_type::eq_int_type(__c, traits_type::eof()))
{
ptrdiff_t __ninp = this->gptr() - this->eback();
if (this->pptr() == this->epptr())
{
if (!(__mode_ & ios_base::out))
return traits_type::eof();
#ifndef _LIBCPP_NO_EXCEPTIONS
try
{
#endif // _LIBCPP_NO_EXCEPTIONS
ptrdiff_t __nout = this->pptr() - this->pbase();
ptrdiff_t __hm = __hm_ - this->pbase();
__str_.push_back(char_type());
__str_.resize(__str_.capacity());
char_type* __p = const_cast<char_type*>(__str_.data());
this->setp(__p, __p + __str_.size());
this->__pbump(__nout);
__hm_ = this->pbase() + __hm;
#ifndef _LIBCPP_NO_EXCEPTIONS
}
catch (...)
{
return traits_type::eof();
}
#endif // _LIBCPP_NO_EXCEPTIONS
}
__hm_ = _VSTD::max(this->pptr() + 1, __hm_);
if (__mode_ & ios_base::in)
{
char_type* __p = const_cast<char_type*>(__str_.data());
this->setg(__p, __p + __ninp, __hm_);
}
return this->sputc(traits_type::to_char_type(__c));
}
return traits_type::not_eof(__c);
}
template <class _CharT, class _Traits, class _Allocator>
typename basic_stringbuf<_CharT, _Traits, _Allocator>::pos_type
basic_stringbuf<_CharT, _Traits, _Allocator>::seekoff(off_type __off,
ios_base::seekdir __way,
ios_base::openmode __wch)
{
if (__hm_ < this->pptr())
__hm_ = this->pptr();
if ((__wch & (ios_base::in | ios_base::out)) == 0)
return pos_type(-1);
if ((__wch & (ios_base::in | ios_base::out)) == (ios_base::in | ios_base::out)
&& __way == ios_base::cur)
return pos_type(-1);
const ptrdiff_t __hm = __hm_ == nullptr ? 0 : __hm_ - __str_.data();
off_type __noff;
switch (__way)
{
case ios_base::beg:
__noff = 0;
break;
case ios_base::cur:
if (__wch & ios_base::in)
__noff = this->gptr() - this->eback();
else
__noff = this->pptr() - this->pbase();
break;
case ios_base::end:
__noff = __hm;
break;
default:
return pos_type(-1);
}
__noff += __off;
if (__noff < 0 || __hm < __noff)
return pos_type(-1);
if (__noff != 0)
{
if ((__wch & ios_base::in) && this->gptr() == 0)
return pos_type(-1);
if ((__wch & ios_base::out) && this->pptr() == 0)
return pos_type(-1);
}
if (__wch & ios_base::in)
this->setg(this->eback(), this->eback() + __noff, __hm_);
if (__wch & ios_base::out)
{
this->setp(this->pbase(), this->epptr());
this->pbump(__noff);
}
return pos_type(__noff);
}
template <class _CharT, class _Traits, class _Allocator>
typename basic_stringbuf<_CharT, _Traits, _Allocator>::pos_type
basic_stringbuf<_CharT, _Traits, _Allocator>::seekpos(pos_type __sp,
ios_base::openmode __wch)
{
return seekoff(__sp, ios_base::beg, __wch);
}
// basic_istringstream
template <class _CharT, class _Traits, class _Allocator>
class _LIBCPP_TEMPLATE_VIS basic_istringstream
: public basic_istream<_CharT, _Traits>
{
public:
typedef _CharT char_type;
typedef _Traits traits_type;
typedef typename traits_type::int_type int_type;
typedef typename traits_type::pos_type pos_type;
typedef typename traits_type::off_type off_type;
typedef _Allocator allocator_type;
typedef basic_string<char_type, traits_type, allocator_type> string_type;
private:
basic_stringbuf<char_type, traits_type, allocator_type> __sb_;
public:
// 27.8.2.1 Constructors:
inline _LIBCPP_INLINE_VISIBILITY
explicit basic_istringstream(ios_base::openmode __wch = ios_base::in);
inline _LIBCPP_INLINE_VISIBILITY
explicit basic_istringstream(const string_type& __s,
ios_base::openmode __wch = ios_base::in);
#ifndef _LIBCPP_CXX03_LANG
inline _LIBCPP_INLINE_VISIBILITY
basic_istringstream(basic_istringstream&& __rhs);
// 27.8.2.2 Assign and swap:
basic_istringstream& operator=(basic_istringstream&& __rhs);
#endif // _LIBCPP_CXX03_LANG
inline _LIBCPP_INLINE_VISIBILITY
void swap(basic_istringstream& __rhs);
// 27.8.2.3 Members:
inline _LIBCPP_INLINE_VISIBILITY
basic_stringbuf<char_type, traits_type, allocator_type>* rdbuf() const;
inline _LIBCPP_INLINE_VISIBILITY
string_type str() const;
inline _LIBCPP_INLINE_VISIBILITY
void str(const string_type& __s);
};
template <class _CharT, class _Traits, class _Allocator>
basic_istringstream<_CharT, _Traits, _Allocator>::basic_istringstream(ios_base::openmode __wch)
: basic_istream<_CharT, _Traits>(&__sb_),
__sb_(__wch | ios_base::in)
{
}
template <class _CharT, class _Traits, class _Allocator>
basic_istringstream<_CharT, _Traits, _Allocator>::basic_istringstream(const string_type& __s,
ios_base::openmode __wch)
: basic_istream<_CharT, _Traits>(&__sb_),
__sb_(__s, __wch | ios_base::in)
{
}
#ifndef _LIBCPP_CXX03_LANG
template <class _CharT, class _Traits, class _Allocator>
basic_istringstream<_CharT, _Traits, _Allocator>::basic_istringstream(basic_istringstream&& __rhs)
: basic_istream<_CharT, _Traits>(_VSTD::move(__rhs)),
__sb_(_VSTD::move(__rhs.__sb_))
{
basic_istream<_CharT, _Traits>::set_rdbuf(&__sb_);
}
template <class _CharT, class _Traits, class _Allocator>
basic_istringstream<_CharT, _Traits, _Allocator>&
basic_istringstream<_CharT, _Traits, _Allocator>::operator=(basic_istringstream&& __rhs)
{
basic_istream<char_type, traits_type>::operator=(_VSTD::move(__rhs));
__sb_ = _VSTD::move(__rhs.__sb_);
return *this;
}
#endif // _LIBCPP_CXX03_LANG
template <class _CharT, class _Traits, class _Allocator>
void basic_istringstream<_CharT, _Traits, _Allocator>::swap(basic_istringstream& __rhs)
{
basic_istream<char_type, traits_type>::swap(__rhs);
__sb_.swap(__rhs.__sb_);
}
template <class _CharT, class _Traits, class _Allocator>
inline _LIBCPP_INLINE_VISIBILITY
void
swap(basic_istringstream<_CharT, _Traits, _Allocator>& __x,
basic_istringstream<_CharT, _Traits, _Allocator>& __y)
{
__x.swap(__y);
}
template <class _CharT, class _Traits, class _Allocator>
basic_stringbuf<_CharT, _Traits, _Allocator>*
basic_istringstream<_CharT, _Traits, _Allocator>::rdbuf() const
{
return const_cast<basic_stringbuf<char_type, traits_type, allocator_type>*>(&__sb_);
}
template <class _CharT, class _Traits, class _Allocator>
basic_string<_CharT, _Traits, _Allocator>
basic_istringstream<_CharT, _Traits, _Allocator>::str() const
{
return __sb_.str();
}
template <class _CharT, class _Traits, class _Allocator>
void basic_istringstream<_CharT, _Traits, _Allocator>::str(const string_type& __s)
{
__sb_.str(__s);
}
// basic_ostringstream
template <class _CharT, class _Traits, class _Allocator>
class _LIBCPP_TEMPLATE_VIS basic_ostringstream
: public basic_ostream<_CharT, _Traits>
{
public:
typedef _CharT char_type;
typedef _Traits traits_type;
typedef typename traits_type::int_type int_type;
typedef typename traits_type::pos_type pos_type;
typedef typename traits_type::off_type off_type;
typedef _Allocator allocator_type;
typedef basic_string<char_type, traits_type, allocator_type> string_type;
private:
basic_stringbuf<char_type, traits_type, allocator_type> __sb_;
public:
// 27.8.2.1 Constructors:
inline _LIBCPP_INLINE_VISIBILITY
explicit basic_ostringstream(ios_base::openmode __wch = ios_base::out);
inline _LIBCPP_INLINE_VISIBILITY
explicit basic_ostringstream(const string_type& __s,
ios_base::openmode __wch = ios_base::out);
#ifndef _LIBCPP_CXX03_LANG
inline _LIBCPP_INLINE_VISIBILITY
basic_ostringstream(basic_ostringstream&& __rhs);
// 27.8.2.2 Assign and swap:
basic_ostringstream& operator=(basic_ostringstream&& __rhs);
#endif // _LIBCPP_CXX03_LANG
inline _LIBCPP_INLINE_VISIBILITY
void swap(basic_ostringstream& __rhs);
// 27.8.2.3 Members:
inline _LIBCPP_INLINE_VISIBILITY
basic_stringbuf<char_type, traits_type, allocator_type>* rdbuf() const;
inline _LIBCPP_INLINE_VISIBILITY
string_type str() const;
inline _LIBCPP_INLINE_VISIBILITY
void str(const string_type& __s);
};
template <class _CharT, class _Traits, class _Allocator>
basic_ostringstream<_CharT, _Traits, _Allocator>::basic_ostringstream(ios_base::openmode __wch)
: basic_ostream<_CharT, _Traits>(&__sb_),
__sb_(__wch | ios_base::out)
{
}
template <class _CharT, class _Traits, class _Allocator>
basic_ostringstream<_CharT, _Traits, _Allocator>::basic_ostringstream(const string_type& __s,
ios_base::openmode __wch)
: basic_ostream<_CharT, _Traits>(&__sb_),
__sb_(__s, __wch | ios_base::out)
{
}
#ifndef _LIBCPP_CXX03_LANG
template <class _CharT, class _Traits, class _Allocator>
basic_ostringstream<_CharT, _Traits, _Allocator>::basic_ostringstream(basic_ostringstream&& __rhs)
: basic_ostream<_CharT, _Traits>(_VSTD::move(__rhs)),
__sb_(_VSTD::move(__rhs.__sb_))
{
basic_ostream<_CharT, _Traits>::set_rdbuf(&__sb_);
}
template <class _CharT, class _Traits, class _Allocator>
basic_ostringstream<_CharT, _Traits, _Allocator>&
basic_ostringstream<_CharT, _Traits, _Allocator>::operator=(basic_ostringstream&& __rhs)
{
basic_ostream<char_type, traits_type>::operator=(_VSTD::move(__rhs));
__sb_ = _VSTD::move(__rhs.__sb_);
return *this;
}
#endif // _LIBCPP_CXX03_LANG
template <class _CharT, class _Traits, class _Allocator>
void
basic_ostringstream<_CharT, _Traits, _Allocator>::swap(basic_ostringstream& __rhs)
{
basic_ostream<char_type, traits_type>::swap(__rhs);
__sb_.swap(__rhs.__sb_);
}
template <class _CharT, class _Traits, class _Allocator>
inline _LIBCPP_INLINE_VISIBILITY
void
swap(basic_ostringstream<_CharT, _Traits, _Allocator>& __x,
basic_ostringstream<_CharT, _Traits, _Allocator>& __y)
{
__x.swap(__y);
}
template <class _CharT, class _Traits, class _Allocator>
basic_stringbuf<_CharT, _Traits, _Allocator>*
basic_ostringstream<_CharT, _Traits, _Allocator>::rdbuf() const
{
return const_cast<basic_stringbuf<char_type, traits_type, allocator_type>*>(&__sb_);
}
template <class _CharT, class _Traits, class _Allocator>
basic_string<_CharT, _Traits, _Allocator>
basic_ostringstream<_CharT, _Traits, _Allocator>::str() const
{
return __sb_.str();
}
template <class _CharT, class _Traits, class _Allocator>
void
basic_ostringstream<_CharT, _Traits, _Allocator>::str(const string_type& __s)
{
__sb_.str(__s);
}
// basic_stringstream
template <class _CharT, class _Traits, class _Allocator>
class _LIBCPP_TEMPLATE_VIS basic_stringstream
: public basic_iostream<_CharT, _Traits>
{
public:
typedef _CharT char_type;
typedef _Traits traits_type;
typedef typename traits_type::int_type int_type;
typedef typename traits_type::pos_type pos_type;
typedef typename traits_type::off_type off_type;
typedef _Allocator allocator_type;
typedef basic_string<char_type, traits_type, allocator_type> string_type;
private:
basic_stringbuf<char_type, traits_type, allocator_type> __sb_;
public:
// 27.8.2.1 Constructors:
inline _LIBCPP_INLINE_VISIBILITY
explicit basic_stringstream(ios_base::openmode __wch = ios_base::in | ios_base::out);
inline _LIBCPP_INLINE_VISIBILITY
explicit basic_stringstream(const string_type& __s,
ios_base::openmode __wch = ios_base::in | ios_base::out);
#ifndef _LIBCPP_CXX03_LANG
inline _LIBCPP_INLINE_VISIBILITY
basic_stringstream(basic_stringstream&& __rhs);
// 27.8.2.2 Assign and swap:
basic_stringstream& operator=(basic_stringstream&& __rhs);
#endif // _LIBCPP_CXX03_LANG
inline _LIBCPP_INLINE_VISIBILITY
void swap(basic_stringstream& __rhs);
// 27.8.2.3 Members:
inline _LIBCPP_INLINE_VISIBILITY
basic_stringbuf<char_type, traits_type, allocator_type>* rdbuf() const;
inline _LIBCPP_INLINE_VISIBILITY
string_type str() const;
inline _LIBCPP_INLINE_VISIBILITY
void str(const string_type& __s);
};
template <class _CharT, class _Traits, class _Allocator>
basic_stringstream<_CharT, _Traits, _Allocator>::basic_stringstream(ios_base::openmode __wch)
: basic_iostream<_CharT, _Traits>(&__sb_),
__sb_(__wch)
{
}
template <class _CharT, class _Traits, class _Allocator>
basic_stringstream<_CharT, _Traits, _Allocator>::basic_stringstream(const string_type& __s,
ios_base::openmode __wch)
: basic_iostream<_CharT, _Traits>(&__sb_),
__sb_(__s, __wch)
{
}
#ifndef _LIBCPP_CXX03_LANG
template <class _CharT, class _Traits, class _Allocator>
basic_stringstream<_CharT, _Traits, _Allocator>::basic_stringstream(basic_stringstream&& __rhs)
: basic_iostream<_CharT, _Traits>(_VSTD::move(__rhs)),
__sb_(_VSTD::move(__rhs.__sb_))
{
basic_istream<_CharT, _Traits>::set_rdbuf(&__sb_);
}
template <class _CharT, class _Traits, class _Allocator>
basic_stringstream<_CharT, _Traits, _Allocator>&
basic_stringstream<_CharT, _Traits, _Allocator>::operator=(basic_stringstream&& __rhs)
{
basic_iostream<char_type, traits_type>::operator=(_VSTD::move(__rhs));
__sb_ = _VSTD::move(__rhs.__sb_);
return *this;
}
#endif // _LIBCPP_CXX03_LANG
template <class _CharT, class _Traits, class _Allocator>
void
basic_stringstream<_CharT, _Traits, _Allocator>::swap(basic_stringstream& __rhs)
{
basic_iostream<char_type, traits_type>::swap(__rhs);
__sb_.swap(__rhs.__sb_);
}
template <class _CharT, class _Traits, class _Allocator>
inline _LIBCPP_INLINE_VISIBILITY
void
swap(basic_stringstream<_CharT, _Traits, _Allocator>& __x,
basic_stringstream<_CharT, _Traits, _Allocator>& __y)
{
__x.swap(__y);
}
template <class _CharT, class _Traits, class _Allocator>
basic_stringbuf<_CharT, _Traits, _Allocator>*
basic_stringstream<_CharT, _Traits, _Allocator>::rdbuf() const
{
return const_cast<basic_stringbuf<char_type, traits_type, allocator_type>*>(&__sb_);
}
template <class _CharT, class _Traits, class _Allocator>
basic_string<_CharT, _Traits, _Allocator>
basic_stringstream<_CharT, _Traits, _Allocator>::str() const
{
return __sb_.str();
}
template <class _CharT, class _Traits, class _Allocator>
void
basic_stringstream<_CharT, _Traits, _Allocator>::str(const string_type& __s)
{
__sb_.str(__s);
}
_LIBCPP_END_NAMESPACE_STD
_LIBCPP_POP_MACROS
#endif // _LIBCPP_SSTREAM
| 33,472 | 986 | jart/cosmopolitan | false |
cosmopolitan/third_party/libcxx/climits | // -*- C++ -*-
//===--------------------------- climits ----------------------------------===//
//
// 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_CLIMITS
#define _LIBCPP_CLIMITS
/*
climits synopsis
Macros:
CHAR_BIT
SCHAR_MIN
SCHAR_MAX
UCHAR_MAX
CHAR_MIN
CHAR_MAX
MB_LEN_MAX
SHRT_MIN
SHRT_MAX
USHRT_MAX
INT_MIN
INT_MAX
UINT_MAX
LONG_MIN
LONG_MAX
ULONG_MAX
LLONG_MIN // C99
LLONG_MAX // C99
ULLONG_MAX // C99
*/
#include "third_party/libcxx/__config"
#include "third_party/libcxx/limits.h"
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
#pragma GCC system_header
#endif
#endif // _LIBCPP_CLIMITS
| 945 | 48 | jart/cosmopolitan | false |
cosmopolitan/third_party/libcxx/exception | // -*- C++ -*-
//===-------------------------- exception ---------------------------------===//
//
// 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_EXCEPTION
#define _LIBCPP_EXCEPTION
#include "third_party/libcxx/__config"
#include "third_party/libcxx/cstddef"
#include "third_party/libcxx/cstdlib"
#include "third_party/libcxx/type_traits"
#include "third_party/libcxx/version"
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
#pragma GCC system_header
#endif
/*
exception synopsis
namespace std
{
class exception
{
public:
exception() noexcept;
exception(const exception&) noexcept;
exception& operator=(const exception&) noexcept;
virtual ~exception() noexcept;
virtual const char* what() const noexcept;
};
class bad_exception
: public exception
{
public:
bad_exception() noexcept;
bad_exception(const bad_exception&) noexcept;
bad_exception& operator=(const bad_exception&) noexcept;
virtual ~bad_exception() noexcept;
virtual const char* what() const noexcept;
};
typedef void (*unexpected_handler)();
unexpected_handler set_unexpected(unexpected_handler f ) noexcept;
unexpected_handler get_unexpected() noexcept;
[[noreturn]] void unexpected();
typedef void (*terminate_handler)();
terminate_handler set_terminate(terminate_handler f ) noexcept;
terminate_handler get_terminate() noexcept;
[[noreturn]] void terminate() noexcept;
bool uncaught_exception() noexcept;
int uncaught_exceptions() noexcept; // C++17
typedef unspecified exception_ptr;
exception_ptr current_exception() noexcept;
void rethrow_exception [[noreturn]] (exception_ptr p);
template<class E> exception_ptr make_exception_ptr(E e) noexcept;
class nested_exception
{
public:
nested_exception() noexcept;
nested_exception(const nested_exception&) noexcept = default;
nested_exception& operator=(const nested_exception&) noexcept = default;
virtual ~nested_exception() = default;
// access functions
[[noreturn]] void rethrow_nested() const;
exception_ptr nested_ptr() const noexcept;
};
template <class T> [[noreturn]] void throw_with_nested(T&& t);
template <class E> void rethrow_if_nested(const E& e);
} // std
*/
namespace std // purposefully not using versioning namespace
{
#if !defined(_LIBCPP_ABI_VCRUNTIME)
class _LIBCPP_EXCEPTION_ABI exception
{
public:
_LIBCPP_INLINE_VISIBILITY exception() _NOEXCEPT {}
virtual ~exception() _NOEXCEPT;
virtual const char* what() const _NOEXCEPT;
};
class _LIBCPP_EXCEPTION_ABI bad_exception
: public exception
{
public:
_LIBCPP_INLINE_VISIBILITY bad_exception() _NOEXCEPT {}
virtual ~bad_exception() _NOEXCEPT;
virtual const char* what() const _NOEXCEPT;
};
#endif // !_LIBCPP_ABI_VCRUNTIME
#if _LIBCPP_STD_VER <= 14 \
|| defined(_LIBCPP_ENABLE_CXX17_REMOVED_UNEXPECTED_FUNCTIONS) \
|| defined(_LIBCPP_BUILDING_LIBRARY)
typedef void (*unexpected_handler)();
_LIBCPP_FUNC_VIS unexpected_handler set_unexpected(unexpected_handler) _NOEXCEPT;
_LIBCPP_FUNC_VIS unexpected_handler get_unexpected() _NOEXCEPT;
_LIBCPP_NORETURN _LIBCPP_FUNC_VIS void unexpected();
#endif
typedef void (*terminate_handler)();
_LIBCPP_FUNC_VIS terminate_handler set_terminate(terminate_handler) _NOEXCEPT;
_LIBCPP_FUNC_VIS terminate_handler get_terminate() _NOEXCEPT;
_LIBCPP_NORETURN _LIBCPP_FUNC_VIS void terminate() _NOEXCEPT;
_LIBCPP_FUNC_VIS bool uncaught_exception() _NOEXCEPT;
_LIBCPP_FUNC_VIS _LIBCPP_AVAILABILITY_UNCAUGHT_EXCEPTIONS int uncaught_exceptions() _NOEXCEPT;
class _LIBCPP_TYPE_VIS exception_ptr;
_LIBCPP_FUNC_VIS exception_ptr current_exception() _NOEXCEPT;
_LIBCPP_NORETURN _LIBCPP_FUNC_VIS void rethrow_exception(exception_ptr);
#ifndef _LIBCPP_ABI_MICROSOFT
class _LIBCPP_TYPE_VIS exception_ptr
{
void* __ptr_;
public:
_LIBCPP_INLINE_VISIBILITY exception_ptr() _NOEXCEPT : __ptr_() {}
_LIBCPP_INLINE_VISIBILITY exception_ptr(nullptr_t) _NOEXCEPT : __ptr_() {}
exception_ptr(const exception_ptr&) _NOEXCEPT;
exception_ptr& operator=(const exception_ptr&) _NOEXCEPT;
~exception_ptr() _NOEXCEPT;
_LIBCPP_INLINE_VISIBILITY _LIBCPP_EXPLICIT operator bool() const _NOEXCEPT
{return __ptr_ != nullptr;}
friend _LIBCPP_INLINE_VISIBILITY
bool operator==(const exception_ptr& __x, const exception_ptr& __y) _NOEXCEPT
{return __x.__ptr_ == __y.__ptr_;}
friend _LIBCPP_INLINE_VISIBILITY
bool operator!=(const exception_ptr& __x, const exception_ptr& __y) _NOEXCEPT
{return !(__x == __y);}
friend _LIBCPP_FUNC_VIS exception_ptr current_exception() _NOEXCEPT;
friend _LIBCPP_FUNC_VIS void rethrow_exception(exception_ptr);
};
template<class _Ep>
_LIBCPP_INLINE_VISIBILITY exception_ptr
make_exception_ptr(_Ep __e) _NOEXCEPT
{
#ifndef _LIBCPP_NO_EXCEPTIONS
try
{
throw __e;
}
catch (...)
{
return current_exception();
}
#else
((void)__e);
_VSTD::abort();
#endif
}
#else // _LIBCPP_ABI_MICROSOFT
class _LIBCPP_TYPE_VIS exception_ptr
{
#if defined(__clang__)
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wunused-private-field"
#endif
void* __ptr1_;
void* __ptr2_;
#if defined(__clang__)
#pragma clang diagnostic pop
#endif
public:
exception_ptr() _NOEXCEPT;
exception_ptr(nullptr_t) _NOEXCEPT;
exception_ptr(const exception_ptr& __other) _NOEXCEPT;
exception_ptr& operator=(const exception_ptr& __other) _NOEXCEPT;
exception_ptr& operator=(nullptr_t) _NOEXCEPT;
~exception_ptr() _NOEXCEPT;
_LIBCPP_EXPLICIT operator bool() const _NOEXCEPT;
};
_LIBCPP_FUNC_VIS
bool operator==(const exception_ptr& __x, const exception_ptr& __y) _NOEXCEPT;
inline _LIBCPP_INLINE_VISIBILITY
bool operator!=(const exception_ptr& __x, const exception_ptr& __y) _NOEXCEPT
{return !(__x == __y);}
_LIBCPP_FUNC_VIS void swap(exception_ptr&, exception_ptr&) _NOEXCEPT;
_LIBCPP_FUNC_VIS exception_ptr __copy_exception_ptr(void *__except, const void* __ptr);
_LIBCPP_FUNC_VIS exception_ptr current_exception() _NOEXCEPT;
_LIBCPP_NORETURN _LIBCPP_FUNC_VIS void rethrow_exception(exception_ptr p);
// This is a built-in template function which automagically extracts the required
// information.
template <class _E> void *__GetExceptionInfo(_E);
template<class _Ep>
_LIBCPP_INLINE_VISIBILITY exception_ptr
make_exception_ptr(_Ep __e) _NOEXCEPT
{
return __copy_exception_ptr(_VSTD::addressof(__e), __GetExceptionInfo(__e));
}
#endif // _LIBCPP_ABI_MICROSOFT
// nested_exception
class _LIBCPP_EXCEPTION_ABI nested_exception
{
exception_ptr __ptr_;
public:
nested_exception() _NOEXCEPT;
// nested_exception(const nested_exception&) noexcept = default;
// nested_exception& operator=(const nested_exception&) noexcept = default;
virtual ~nested_exception() _NOEXCEPT;
// access functions
_LIBCPP_NORETURN void rethrow_nested() const;
_LIBCPP_INLINE_VISIBILITY exception_ptr nested_ptr() const _NOEXCEPT {return __ptr_;}
};
template <class _Tp>
struct __nested
: public _Tp,
public nested_exception
{
_LIBCPP_INLINE_VISIBILITY explicit __nested(const _Tp& __t) : _Tp(__t) {}
};
#ifndef _LIBCPP_NO_EXCEPTIONS
template <class _Tp, class _Up, bool>
struct __throw_with_nested;
template <class _Tp, class _Up>
struct __throw_with_nested<_Tp, _Up, true> {
_LIBCPP_NORETURN static inline _LIBCPP_INLINE_VISIBILITY void
__do_throw(_Tp&& __t)
{
throw __nested<_Up>(_VSTD::forward<_Tp>(__t));
}
};
template <class _Tp, class _Up>
struct __throw_with_nested<_Tp, _Up, false> {
_LIBCPP_NORETURN static inline _LIBCPP_INLINE_VISIBILITY void
#ifndef _LIBCPP_CXX03_LANG
__do_throw(_Tp&& __t)
#else
__do_throw (_Tp& __t)
#endif // _LIBCPP_CXX03_LANG
{
throw _VSTD::forward<_Tp>(__t);
}
};
#endif
template <class _Tp>
_LIBCPP_NORETURN
void
throw_with_nested(_Tp&& __t)
{
#ifndef _LIBCPP_NO_EXCEPTIONS
typedef typename decay<_Tp>::type _Up;
static_assert( is_copy_constructible<_Up>::value, "type thrown must be CopyConstructible");
__throw_with_nested<_Tp, _Up,
is_class<_Up>::value &&
!is_base_of<nested_exception, _Up>::value &&
!__libcpp_is_final<_Up>::value>::
__do_throw(_VSTD::forward<_Tp>(__t));
#else
((void)__t);
// FIXME: Make this abort
#endif
}
template <class _From, class _To>
struct __can_dynamic_cast : public _LIBCPP_BOOL_CONSTANT(
is_polymorphic<_From>::value &&
(!is_base_of<_To, _From>::value ||
is_convertible<const _From*, const _To*>::value)) {};
template <class _Ep>
inline _LIBCPP_INLINE_VISIBILITY
void
rethrow_if_nested(const _Ep& __e,
typename enable_if< __can_dynamic_cast<_Ep, nested_exception>::value>::type* = 0)
{
const nested_exception* __nep = dynamic_cast<const nested_exception*>(_VSTD::addressof(__e));
if (__nep)
__nep->rethrow_nested();
}
template <class _Ep>
inline _LIBCPP_INLINE_VISIBILITY
void
rethrow_if_nested(const _Ep&,
typename enable_if<!__can_dynamic_cast<_Ep, nested_exception>::value>::type* = 0)
{
}
} // std
#endif // _LIBCPP_EXCEPTION
| 9,410 | 326 | jart/cosmopolitan | false |
cosmopolitan/third_party/libcxx/vector.cc | //===------------------------- vector.cpp ---------------------------------===//
//
// 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
//
//===----------------------------------------------------------------------===//
#include "third_party/libcxx/vector"
_LIBCPP_BEGIN_NAMESPACE_STD
template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS
__vector_base_common<true>;
_LIBCPP_END_NAMESPACE_STD
| 552 | 17 | jart/cosmopolitan | false |
cosmopolitan/third_party/libcxx/exception_pointer_unimplemented.hh | // -*- 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
//
//===----------------------------------------------------------------------===//
#include "third_party/libcxx/stdio.h"
#include "third_party/libcxx/stdlib.h"
#include "third_party/libcxx/exception"
namespace std {
exception_ptr::~exception_ptr() _NOEXCEPT {
// #warning exception_ptr not yet implemented
fprintf(stderr, "exception_ptr not yet implemented\n");
::abort();
}
exception_ptr::exception_ptr(const exception_ptr& other) _NOEXCEPT
: __ptr_(other.__ptr_) {
// #warning exception_ptr not yet implemented
fprintf(stderr, "exception_ptr not yet implemented\n");
::abort();
}
exception_ptr& exception_ptr::operator=(const exception_ptr& other) _NOEXCEPT {
// #warning exception_ptr not yet implemented
fprintf(stderr, "exception_ptr not yet implemented\n");
::abort();
}
nested_exception::nested_exception() _NOEXCEPT : __ptr_(current_exception()) {}
#if !defined(__GLIBCXX__)
nested_exception::~nested_exception() _NOEXCEPT {}
#endif
_LIBCPP_NORETURN
void nested_exception::rethrow_nested() const {
// #warning exception_ptr not yet implemented
fprintf(stderr, "exception_ptr not yet implemented\n");
::abort();
#if 0
if (__ptr_ == nullptr)
terminate();
rethrow_exception(__ptr_);
#endif // FIXME
}
exception_ptr current_exception() _NOEXCEPT {
// #warning exception_ptr not yet implemented
fprintf(stderr, "exception_ptr not yet implemented\n");
::abort();
}
_LIBCPP_NORETURN
void rethrow_exception(exception_ptr p) {
// #warning exception_ptr not yet implemented
fprintf(stderr, "exception_ptr not yet implemented\n");
::abort();
}
} // namespace std
| 1,924 | 69 | jart/cosmopolitan | false |
cosmopolitan/third_party/libcxx/locale1.cc | // clang-format off
//===------------------------- locale.cpp ---------------------------------===//
//
// 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
//
//===----------------------------------------------------------------------===//
#include "third_party/libcxx/string"
#include "third_party/libcxx/locale"
#include "third_party/libcxx/codecvt"
#include "third_party/libcxx/vector"
#include "third_party/libcxx/algorithm"
#include "third_party/libcxx/typeinfo"
#ifndef _LIBCPP_NO_EXCEPTIONS
#include "third_party/libcxx/type_traits"
#endif
#include "third_party/libcxx/clocale"
#include "third_party/libcxx/cstring"
#include "third_party/libcxx/cwctype"
#include "third_party/libcxx/__sso_allocator"
#include "third_party/libcxx/include/atomic_support.hh"
#include "libc/str/locale.h"
#include "third_party/libcxx/__undef_macros"
// On Linux, wint_t and wchar_t have different signed-ness, and this causes
// lots of noise in the build log, but no bugs that I know of.
#if defined(__clang__)
#pragma clang diagnostic ignored "-Wsign-conversion"
#endif
_LIBCPP_BEGIN_NAMESPACE_STD
#ifdef __cloc_defined
locale_t __cloc() {
// In theory this could create a race condition. In practice
// the race condition is non-fatal since it will just create
// a little resource leak. Better approach would be appreciated.
static locale_t result = newlocale(LC_ALL_MASK, "C", 0);
return result;
}
#endif // __cloc_defined
namespace {
struct release
{
void operator()(locale::facet* p) {p->__release_shared();}
};
template <class T, class A0>
inline
T&
make(A0 a0)
{
static typename aligned_storage<sizeof(T)>::type buf;
auto *obj = ::new (&buf) T(a0);
return *obj;
}
template <class T, class A0, class A1>
inline
T&
make(A0 a0, A1 a1)
{
static typename aligned_storage<sizeof(T)>::type buf;
::new (&buf) T(a0, a1);
return *reinterpret_cast<T*>(&buf);
}
template <class T, class A0, class A1, class A2>
inline
T&
make(A0 a0, A1 a1, A2 a2)
{
static typename aligned_storage<sizeof(T)>::type buf;
auto *obj = ::new (&buf) T(a0, a1, a2);
return *obj;
}
_LIBCPP_NORETURN static void __throw_runtime_error(const string &msg)
{
#ifndef _LIBCPP_NO_EXCEPTIONS
throw runtime_error(msg);
#else
(void)msg;
_VSTD::abort();
#endif
}
}
#if defined(_AIX)
// Set priority to INT_MIN + 256 + 150
# pragma priority ( -2147483242 )
#endif
const locale::category locale::none;
const locale::category locale::collate;
const locale::category locale::ctype;
const locale::category locale::monetary;
const locale::category locale::numeric;
const locale::category locale::time;
const locale::category locale::messages;
const locale::category locale::all;
class _LIBCPP_HIDDEN locale::__imp
: public facet
{
enum {N = 28};
#if defined(_LIBCPP_COMPILER_MSVC)
// FIXME: MSVC doesn't support aligned parameters by value.
// I can't get the __sso_allocator to work here
// for MSVC I think for this reason.
vector<facet*> facets_;
#else
vector<facet*, __sso_allocator<facet*, N> > facets_;
#endif
string name_;
public:
explicit __imp(size_t refs = 0);
explicit __imp(const string& name, size_t refs = 0);
__imp(const __imp&);
__imp(const __imp&, const string&, locale::category c);
__imp(const __imp& other, const __imp& one, locale::category c);
__imp(const __imp&, facet* f, long id);
~__imp();
const string& name() const {return name_;}
bool has_facet(long id) const
{return static_cast<size_t>(id) < facets_.size() && facets_[static_cast<size_t>(id)];}
const locale::facet* use_facet(long id) const;
static const locale& make_classic();
static locale& make_global();
private:
void install(facet* f, long id);
template <class F> void install(F* f) {install(f, f->id.__get());}
template <class F> void install_from(const __imp& other);
};
locale::__imp::__imp(size_t refs)
: facet(refs),
facets_(N),
name_("C")
{
facets_.clear();
install(&make<_VSTD::collate<char> >(1u));
install(&make<_VSTD::collate<wchar_t> >(1u));
install(&make<_VSTD::ctype<char> >(nullptr, false, 1u));
install(&make<_VSTD::ctype<wchar_t> >(1u));
install(&make<codecvt<char, char, mbstate_t> >(1u));
install(&make<codecvt<wchar_t, char, mbstate_t> >(1u));
install(&make<codecvt<char16_t, char, mbstate_t> >(1u));
install(&make<codecvt<char32_t, char, mbstate_t> >(1u));
install(&make<numpunct<char> >(1u));
install(&make<numpunct<wchar_t> >(1u));
install(&make<num_get<char> >(1u));
install(&make<num_get<wchar_t> >(1u));
install(&make<num_put<char> >(1u));
install(&make<num_put<wchar_t> >(1u));
install(&make<moneypunct<char, false> >(1u));
install(&make<moneypunct<char, true> >(1u));
install(&make<moneypunct<wchar_t, false> >(1u));
install(&make<moneypunct<wchar_t, true> >(1u));
install(&make<money_get<char> >(1u));
install(&make<money_get<wchar_t> >(1u));
install(&make<money_put<char> >(1u));
install(&make<money_put<wchar_t> >(1u));
install(&make<time_get<char> >(1u));
install(&make<time_get<wchar_t> >(1u));
install(&make<time_put<char> >(1u));
install(&make<time_put<wchar_t> >(1u));
install(&make<_VSTD::messages<char> >(1u));
install(&make<_VSTD::messages<wchar_t> >(1u));
}
locale::__imp::__imp(const string& name, size_t refs)
: facet(refs),
facets_(N),
name_(name)
{
#ifndef _LIBCPP_NO_EXCEPTIONS
try
{
#endif // _LIBCPP_NO_EXCEPTIONS
facets_ = locale::classic().__locale_->facets_;
for (unsigned i = 0; i < facets_.size(); ++i)
if (facets_[i])
facets_[i]->__add_shared();
install(new collate_byname<char>(name_));
install(new collate_byname<wchar_t>(name_));
install(new ctype_byname<char>(name_));
install(new ctype_byname<wchar_t>(name_));
install(new codecvt_byname<char, char, mbstate_t>(name_));
install(new codecvt_byname<wchar_t, char, mbstate_t>(name_));
install(new codecvt_byname<char16_t, char, mbstate_t>(name_));
install(new codecvt_byname<char32_t, char, mbstate_t>(name_));
install(new numpunct_byname<char>(name_));
install(new numpunct_byname<wchar_t>(name_));
install(new moneypunct_byname<char, false>(name_));
install(new moneypunct_byname<char, true>(name_));
install(new moneypunct_byname<wchar_t, false>(name_));
install(new moneypunct_byname<wchar_t, true>(name_));
install(new time_get_byname<char>(name_));
install(new time_get_byname<wchar_t>(name_));
install(new time_put_byname<char>(name_));
install(new time_put_byname<wchar_t>(name_));
install(new messages_byname<char>(name_));
install(new messages_byname<wchar_t>(name_));
#ifndef _LIBCPP_NO_EXCEPTIONS
}
catch (...)
{
for (unsigned i = 0; i < facets_.size(); ++i)
if (facets_[i])
facets_[i]->__release_shared();
throw;
}
#endif // _LIBCPP_NO_EXCEPTIONS
}
// NOTE avoid the `base class should be explicitly initialized in the
// copy constructor` warning emitted by GCC
#if defined(__clang__) || _GNUC_VER >= 406
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wextra"
#endif
locale::__imp::__imp(const __imp& other)
: facets_(max<size_t>(N, other.facets_.size())),
name_(other.name_)
{
facets_ = other.facets_;
for (unsigned i = 0; i < facets_.size(); ++i)
if (facets_[i])
facets_[i]->__add_shared();
}
#if defined(__clang__) || _GNUC_VER >= 406
#pragma GCC diagnostic pop
#endif
locale::__imp::__imp(const __imp& other, const string& name, locale::category c)
: facets_(N),
name_("*")
{
facets_ = other.facets_;
for (unsigned i = 0; i < facets_.size(); ++i)
if (facets_[i])
facets_[i]->__add_shared();
#ifndef _LIBCPP_NO_EXCEPTIONS
try
{
#endif // _LIBCPP_NO_EXCEPTIONS
if (c & locale::collate)
{
install(new collate_byname<char>(name));
install(new collate_byname<wchar_t>(name));
}
if (c & locale::ctype)
{
install(new ctype_byname<char>(name));
install(new ctype_byname<wchar_t>(name));
install(new codecvt_byname<char, char, mbstate_t>(name));
install(new codecvt_byname<wchar_t, char, mbstate_t>(name));
install(new codecvt_byname<char16_t, char, mbstate_t>(name));
install(new codecvt_byname<char32_t, char, mbstate_t>(name));
}
if (c & locale::monetary)
{
install(new moneypunct_byname<char, false>(name));
install(new moneypunct_byname<char, true>(name));
install(new moneypunct_byname<wchar_t, false>(name));
install(new moneypunct_byname<wchar_t, true>(name));
}
if (c & locale::numeric)
{
install(new numpunct_byname<char>(name));
install(new numpunct_byname<wchar_t>(name));
}
if (c & locale::time)
{
install(new time_get_byname<char>(name));
install(new time_get_byname<wchar_t>(name));
install(new time_put_byname<char>(name));
install(new time_put_byname<wchar_t>(name));
}
if (c & locale::messages)
{
install(new messages_byname<char>(name));
install(new messages_byname<wchar_t>(name));
}
#ifndef _LIBCPP_NO_EXCEPTIONS
}
catch (...)
{
for (unsigned i = 0; i < facets_.size(); ++i)
if (facets_[i])
facets_[i]->__release_shared();
throw;
}
#endif // _LIBCPP_NO_EXCEPTIONS
}
template<class F>
inline
void
locale::__imp::install_from(const locale::__imp& one)
{
long id = F::id.__get();
install(const_cast<F*>(static_cast<const F*>(one.use_facet(id))), id);
}
locale::__imp::__imp(const __imp& other, const __imp& one, locale::category c)
: facets_(N),
name_("*")
{
facets_ = other.facets_;
for (unsigned i = 0; i < facets_.size(); ++i)
if (facets_[i])
facets_[i]->__add_shared();
#ifndef _LIBCPP_NO_EXCEPTIONS
try
{
#endif // _LIBCPP_NO_EXCEPTIONS
if (c & locale::collate)
{
install_from<_VSTD::collate<char> >(one);
install_from<_VSTD::collate<wchar_t> >(one);
}
if (c & locale::ctype)
{
install_from<_VSTD::ctype<char> >(one);
install_from<_VSTD::ctype<wchar_t> >(one);
install_from<_VSTD::codecvt<char, char, mbstate_t> >(one);
install_from<_VSTD::codecvt<char16_t, char, mbstate_t> >(one);
install_from<_VSTD::codecvt<char32_t, char, mbstate_t> >(one);
install_from<_VSTD::codecvt<wchar_t, char, mbstate_t> >(one);
}
if (c & locale::monetary)
{
install_from<moneypunct<char, false> >(one);
install_from<moneypunct<char, true> >(one);
install_from<moneypunct<wchar_t, false> >(one);
install_from<moneypunct<wchar_t, true> >(one);
install_from<money_get<char> >(one);
install_from<money_get<wchar_t> >(one);
install_from<money_put<char> >(one);
install_from<money_put<wchar_t> >(one);
}
if (c & locale::numeric)
{
install_from<numpunct<char> >(one);
install_from<numpunct<wchar_t> >(one);
install_from<num_get<char> >(one);
install_from<num_get<wchar_t> >(one);
install_from<num_put<char> >(one);
install_from<num_put<wchar_t> >(one);
}
if (c & locale::time)
{
install_from<time_get<char> >(one);
install_from<time_get<wchar_t> >(one);
install_from<time_put<char> >(one);
install_from<time_put<wchar_t> >(one);
}
if (c & locale::messages)
{
install_from<_VSTD::messages<char> >(one);
install_from<_VSTD::messages<wchar_t> >(one);
}
#ifndef _LIBCPP_NO_EXCEPTIONS
}
catch (...)
{
for (unsigned i = 0; i < facets_.size(); ++i)
if (facets_[i])
facets_[i]->__release_shared();
throw;
}
#endif // _LIBCPP_NO_EXCEPTIONS
}
locale::__imp::__imp(const __imp& other, facet* f, long id)
: facets_(max<size_t>(N, other.facets_.size()+1)),
name_("*")
{
f->__add_shared();
unique_ptr<facet, release> hold(f);
facets_ = other.facets_;
for (unsigned i = 0; i < other.facets_.size(); ++i)
if (facets_[i])
facets_[i]->__add_shared();
install(hold.get(), id);
}
locale::__imp::~__imp()
{
for (unsigned i = 0; i < facets_.size(); ++i)
if (facets_[i])
facets_[i]->__release_shared();
}
void
locale::__imp::install(facet* f, long id)
{
f->__add_shared();
unique_ptr<facet, release> hold(f);
if (static_cast<size_t>(id) >= facets_.size())
facets_.resize(static_cast<size_t>(id+1));
if (facets_[static_cast<size_t>(id)])
facets_[static_cast<size_t>(id)]->__release_shared();
facets_[static_cast<size_t>(id)] = hold.release();
}
const locale::facet*
locale::__imp::use_facet(long id) const
{
if (!has_facet(id))
__throw_bad_cast();
return facets_[static_cast<size_t>(id)];
}
// locale
const locale&
locale::__imp::make_classic()
{
// only one thread can get in here and it only gets in once
static aligned_storage<sizeof(locale)>::type buf;
locale* c = reinterpret_cast<locale*>(&buf);
c->__locale_ = &make<__imp>(1u);
return *c;
}
const locale&
locale::classic()
{
static const locale& c = __imp::make_classic();
return c;
}
locale&
locale::__imp::make_global()
{
// only one thread can get in here and it only gets in once
static aligned_storage<sizeof(locale)>::type buf;
auto *obj = ::new (&buf) locale(locale::classic());
return *obj;
}
locale&
locale::__global()
{
static locale& g = __imp::make_global();
return g;
}
locale::locale() _NOEXCEPT
: __locale_(__global().__locale_)
{
__locale_->__add_shared();
}
locale::locale(const locale& l) _NOEXCEPT
: __locale_(l.__locale_)
{
__locale_->__add_shared();
}
locale::~locale()
{
__locale_->__release_shared();
}
const locale&
locale::operator=(const locale& other) _NOEXCEPT
{
other.__locale_->__add_shared();
__locale_->__release_shared();
__locale_ = other.__locale_;
return *this;
}
locale::locale(const char* name)
: __locale_(name ? new __imp(name)
: (__throw_runtime_error("locale constructed with null"), (__imp*)0))
{
__locale_->__add_shared();
}
locale::locale(const string& name)
: __locale_(new __imp(name))
{
__locale_->__add_shared();
}
locale::locale(const locale& other, const char* name, category c)
: __locale_(name ? new __imp(*other.__locale_, name, c)
: (__throw_runtime_error("locale constructed with null"), (__imp*)0))
{
__locale_->__add_shared();
}
locale::locale(const locale& other, const string& name, category c)
: __locale_(new __imp(*other.__locale_, name, c))
{
__locale_->__add_shared();
}
locale::locale(const locale& other, const locale& one, category c)
: __locale_(new __imp(*other.__locale_, *one.__locale_, c))
{
__locale_->__add_shared();
}
string
locale::name() const
{
return __locale_->name();
}
void
locale::__install_ctor(const locale& other, facet* f, long id)
{
if (f)
__locale_ = new __imp(*other.__locale_, f, id);
else
__locale_ = other.__locale_;
__locale_->__add_shared();
}
locale
locale::global(const locale& loc)
{
locale& g = __global();
locale r = g;
g = loc;
if (g.name() != "*")
setlocale(LC_ALL, g.name().c_str());
return r;
}
bool
locale::has_facet(id& x) const
{
return __locale_->has_facet(x.__get());
}
const locale::facet*
locale::use_facet(id& x) const
{
return __locale_->use_facet(x.__get());
}
bool
locale::operator==(const locale& y) const
{
return (__locale_ == y.__locale_)
|| (__locale_->name() != "*" && __locale_->name() == y.__locale_->name());
}
// locale::facet
locale::facet::~facet()
{
}
void
locale::facet::__on_zero_shared() _NOEXCEPT
{
delete this;
}
// locale::id
int32_t locale::id::__next_id = 0;
namespace
{
class __fake_bind
{
locale::id* id_;
void (locale::id::* pmf_)();
public:
__fake_bind(void (locale::id::* pmf)(), locale::id* id)
: id_(id), pmf_(pmf) {}
void operator()() const
{
(id_->*pmf_)();
}
};
}
long
locale::id::__get()
{
call_once(__flag_, __fake_bind(&locale::id::__init, this));
return __id_ - 1;
}
void
locale::id::__init()
{
__id_ = __libcpp_atomic_add(&__next_id, 1);
}
// template <> class collate_byname<char>
collate_byname<char>::collate_byname(const char* n, size_t refs)
: collate<char>(refs),
__l(newlocale(LC_ALL_MASK, n, 0))
{
if (__l == 0)
__throw_runtime_error("collate_byname<char>::collate_byname"
" failed to construct for " + string(n));
}
collate_byname<char>::collate_byname(const string& name, size_t refs)
: collate<char>(refs),
__l(newlocale(LC_ALL_MASK, name.c_str(), 0))
{
if (__l == 0)
__throw_runtime_error("collate_byname<char>::collate_byname"
" failed to construct for " + name);
}
collate_byname<char>::~collate_byname()
{
freelocale(__l);
}
int
collate_byname<char>::do_compare(const char_type* __lo1, const char_type* __hi1,
const char_type* __lo2, const char_type* __hi2) const
{
string_type lhs(__lo1, __hi1);
string_type rhs(__lo2, __hi2);
int r = strcoll_l(lhs.c_str(), rhs.c_str(), __l);
if (r < 0)
return -1;
if (r > 0)
return 1;
return r;
}
collate_byname<char>::string_type
collate_byname<char>::do_transform(const char_type* lo, const char_type* hi) const
{
const string_type in(lo, hi);
string_type out(strxfrm_l(0, in.c_str(), 0, __l), char());
strxfrm_l(const_cast<char*>(out.c_str()), in.c_str(), out.size()+1, __l);
return out;
}
// template <> class collate_byname<wchar_t>
collate_byname<wchar_t>::collate_byname(const char* n, size_t refs)
: collate<wchar_t>(refs),
__l(newlocale(LC_ALL_MASK, n, 0))
{
if (__l == 0)
__throw_runtime_error("collate_byname<wchar_t>::collate_byname(size_t refs)"
" failed to construct for " + string(n));
}
collate_byname<wchar_t>::collate_byname(const string& name, size_t refs)
: collate<wchar_t>(refs),
__l(newlocale(LC_ALL_MASK, name.c_str(), 0))
{
if (__l == 0)
__throw_runtime_error("collate_byname<wchar_t>::collate_byname(size_t refs)"
" failed to construct for " + name);
}
collate_byname<wchar_t>::~collate_byname()
{
freelocale(__l);
}
int
collate_byname<wchar_t>::do_compare(const char_type* __lo1, const char_type* __hi1,
const char_type* __lo2, const char_type* __hi2) const
{
string_type lhs(__lo1, __hi1);
string_type rhs(__lo2, __hi2);
int r = wcscoll_l(lhs.c_str(), rhs.c_str(), __l);
if (r < 0)
return -1;
if (r > 0)
return 1;
return r;
}
collate_byname<wchar_t>::string_type
collate_byname<wchar_t>::do_transform(const char_type* lo, const char_type* hi) const
{
const string_type in(lo, hi);
string_type out(wcsxfrm_l(0, in.c_str(), 0, __l), wchar_t());
wcsxfrm_l(const_cast<wchar_t*>(out.c_str()), in.c_str(), out.size()+1, __l);
return out;
}
// template <> class ctype<wchar_t>;
const ctype_base::mask ctype_base::space;
const ctype_base::mask ctype_base::print;
const ctype_base::mask ctype_base::cntrl;
const ctype_base::mask ctype_base::upper;
const ctype_base::mask ctype_base::lower;
const ctype_base::mask ctype_base::alpha;
const ctype_base::mask ctype_base::digit;
const ctype_base::mask ctype_base::punct;
const ctype_base::mask ctype_base::xdigit;
const ctype_base::mask ctype_base::blank;
const ctype_base::mask ctype_base::alnum;
const ctype_base::mask ctype_base::graph;
locale::id ctype<wchar_t>::id;
ctype<wchar_t>::~ctype()
{
}
bool
ctype<wchar_t>::do_is(mask m, char_type c) const
{
return isascii(c) ? (ctype<char>::classic_table()[c] & m) != 0 : false;
}
const wchar_t*
ctype<wchar_t>::do_is(const char_type* low, const char_type* high, mask* vec) const
{
for (; low != high; ++low, ++vec)
*vec = static_cast<mask>(isascii(*low) ?
ctype<char>::classic_table()[*low] : 0);
return low;
}
const wchar_t*
ctype<wchar_t>::do_scan_is(mask m, const char_type* low, const char_type* high) const
{
for (; low != high; ++low)
if (isascii(*low) && (ctype<char>::classic_table()[*low] & m))
break;
return low;
}
const wchar_t*
ctype<wchar_t>::do_scan_not(mask m, const char_type* low, const char_type* high) const
{
for (; low != high; ++low)
if (!(isascii(*low) && (ctype<char>::classic_table()[*low] & m)))
break;
return low;
}
wchar_t
ctype<wchar_t>::do_toupper(char_type c) const
{
#ifdef _LIBCPP_HAS_DEFAULTRUNELOCALE
return isascii(c) ? _DefaultRuneLocale.__mapupper[c] : c;
#elif defined(__GLIBC__) || defined(__EMSCRIPTEN__) || \
defined(__NetBSD__)
return isascii(c) ? ctype<char>::__classic_upper_table()[c] : c;
#else
return (isascii(c) && iswlower_l(c, _LIBCPP_GET_C_LOCALE)) ? c-L'a'+L'A' : c;
#endif
}
const wchar_t*
ctype<wchar_t>::do_toupper(char_type* low, const char_type* high) const
{
for (; low != high; ++low)
#ifdef _LIBCPP_HAS_DEFAULTRUNELOCALE
*low = isascii(*low) ? _DefaultRuneLocale.__mapupper[*low] : *low;
#elif defined(__GLIBC__) || defined(__EMSCRIPTEN__) || \
defined(__NetBSD__)
*low = isascii(*low) ? ctype<char>::__classic_upper_table()[*low]
: *low;
#else
*low = (isascii(*low) && islower_l(*low, _LIBCPP_GET_C_LOCALE)) ? (*low-L'a'+L'A') : *low;
#endif
return low;
}
wchar_t
ctype<wchar_t>::do_tolower(char_type c) const
{
#ifdef _LIBCPP_HAS_DEFAULTRUNELOCALE
return isascii(c) ? _DefaultRuneLocale.__maplower[c] : c;
#elif defined(__GLIBC__) || defined(__EMSCRIPTEN__) || \
defined(__NetBSD__)
return isascii(c) ? ctype<char>::__classic_lower_table()[c] : c;
#else
return (isascii(c) && isupper_l(c, _LIBCPP_GET_C_LOCALE)) ? c-L'A'+'a' : c;
#endif
}
const wchar_t*
ctype<wchar_t>::do_tolower(char_type* low, const char_type* high) const
{
for (; low != high; ++low)
#ifdef _LIBCPP_HAS_DEFAULTRUNELOCALE
*low = isascii(*low) ? _DefaultRuneLocale.__maplower[*low] : *low;
#elif defined(__GLIBC__) || defined(__EMSCRIPTEN__) || \
defined(__NetBSD__)
*low = isascii(*low) ? ctype<char>::__classic_lower_table()[*low]
: *low;
#else
*low = (isascii(*low) && isupper_l(*low, _LIBCPP_GET_C_LOCALE)) ? *low-L'A'+L'a' : *low;
#endif
return low;
}
wchar_t
ctype<wchar_t>::do_widen(char c) const
{
return c;
}
const char*
ctype<wchar_t>::do_widen(const char* low, const char* high, char_type* dest) const
{
for (; low != high; ++low, ++dest)
*dest = *low;
return low;
}
char
ctype<wchar_t>::do_narrow(char_type c, char dfault) const
{
if (isascii(c))
return static_cast<char>(c);
return dfault;
}
const wchar_t*
ctype<wchar_t>::do_narrow(const char_type* low, const char_type* high, char dfault, char* dest) const
{
for (; low != high; ++low, ++dest)
if (isascii(*low))
*dest = static_cast<char>(*low);
else
*dest = dfault;
return low;
}
// template <> class ctype<char>;
locale::id ctype<char>::id;
ctype<char>::ctype(const mask* tab, bool del, size_t refs)
: locale::facet(refs),
__tab_(tab),
__del_(del)
{
if (__tab_ == 0)
__tab_ = classic_table();
}
ctype<char>::~ctype()
{
if (__tab_ && __del_)
delete [] __tab_;
}
char
ctype<char>::do_toupper(char_type c) const
{
#ifdef _LIBCPP_HAS_DEFAULTRUNELOCALE
return isascii(c) ?
static_cast<char>(_DefaultRuneLocale.__mapupper[static_cast<ptrdiff_t>(c)]) : c;
#elif defined(__NetBSD__)
return static_cast<char>(__classic_upper_table()[static_cast<unsigned char>(c)]);
#elif defined(__GLIBC__) || defined(__EMSCRIPTEN__)
return isascii(c) ?
static_cast<char>(__classic_upper_table()[static_cast<unsigned char>(c)]) : c;
#else
return (isascii(c) && islower_l(c, _LIBCPP_GET_C_LOCALE)) ? c-'a'+'A' : c;
#endif
}
const char*
ctype<char>::do_toupper(char_type* low, const char_type* high) const
{
for (; low != high; ++low)
#ifdef _LIBCPP_HAS_DEFAULTRUNELOCALE
*low = isascii(*low) ?
static_cast<char>(_DefaultRuneLocale.__mapupper[static_cast<ptrdiff_t>(*low)]) : *low;
#elif defined(__NetBSD__)
*low = static_cast<char>(__classic_upper_table()[static_cast<unsigned char>(*low)]);
#elif defined(__GLIBC__) || defined(__EMSCRIPTEN__)
*low = isascii(*low) ?
static_cast<char>(__classic_upper_table()[static_cast<size_t>(*low)]) : *low;
#else
*low = (isascii(*low) && islower_l(*low, _LIBCPP_GET_C_LOCALE)) ? *low-'a'+'A' : *low;
#endif
return low;
}
char
ctype<char>::do_tolower(char_type c) const
{
#ifdef _LIBCPP_HAS_DEFAULTRUNELOCALE
return isascii(c) ?
static_cast<char>(_DefaultRuneLocale.__maplower[static_cast<ptrdiff_t>(c)]) : c;
#elif defined(__NetBSD__)
return static_cast<char>(__classic_lower_table()[static_cast<unsigned char>(c)]);
#elif defined(__GLIBC__) || defined(__EMSCRIPTEN__)
return isascii(c) ?
static_cast<char>(__classic_lower_table()[static_cast<size_t>(c)]) : c;
#else
return (isascii(c) && isupper_l(c, _LIBCPP_GET_C_LOCALE)) ? c-'A'+'a' : c;
#endif
}
const char*
ctype<char>::do_tolower(char_type* low, const char_type* high) const
{
for (; low != high; ++low)
#ifdef _LIBCPP_HAS_DEFAULTRUNELOCALE
*low = isascii(*low) ? static_cast<char>(_DefaultRuneLocale.__maplower[static_cast<ptrdiff_t>(*low)]) : *low;
#elif defined(__NetBSD__)
*low = static_cast<char>(__classic_lower_table()[static_cast<unsigned char>(*low)]);
#elif defined(__GLIBC__) || defined(__EMSCRIPTEN__)
*low = isascii(*low) ? static_cast<char>(__classic_lower_table()[static_cast<size_t>(*low)]) : *low;
#else
*low = (isascii(*low) && isupper_l(*low, _LIBCPP_GET_C_LOCALE)) ? *low-'A'+'a' : *low;
#endif
return low;
}
char
ctype<char>::do_widen(char c) const
{
return c;
}
const char*
ctype<char>::do_widen(const char* low, const char* high, char_type* dest) const
{
for (; low != high; ++low, ++dest)
*dest = *low;
return low;
}
char
ctype<char>::do_narrow(char_type c, char dfault) const
{
if (isascii(c))
return static_cast<char>(c);
return dfault;
}
const char*
ctype<char>::do_narrow(const char_type* low, const char_type* high, char dfault, char* dest) const
{
for (; low != high; ++low, ++dest)
if (isascii(*low))
*dest = *low;
else
*dest = dfault;
return low;
}
#if defined(__EMSCRIPTEN__)
extern "C" const unsigned short ** __ctype_b_loc();
extern "C" const int ** __ctype_tolower_loc();
extern "C" const int ** __ctype_toupper_loc();
#endif
#ifdef _LIBCPP_PROVIDES_DEFAULT_RUNE_TABLE
const ctype<char>::mask*
ctype<char>::classic_table() _NOEXCEPT
{
static _LIBCPP_CONSTEXPR const ctype<char>::mask builtin_table[table_size] = {
cntrl, cntrl,
cntrl, cntrl,
cntrl, cntrl,
cntrl, cntrl,
cntrl, cntrl | space | blank,
cntrl | space, cntrl | space,
cntrl | space, cntrl | space,
cntrl, cntrl,
cntrl, cntrl,
cntrl, cntrl,
cntrl, cntrl,
cntrl, cntrl,
cntrl, cntrl,
cntrl, cntrl,
cntrl, cntrl,
cntrl, cntrl,
space | blank | print, punct | print,
punct | print, punct | print,
punct | print, punct | print,
punct | print, punct | print,
punct | print, punct | print,
punct | print, punct | print,
punct | print, punct | print,
punct | print, punct | print,
digit | print | xdigit, digit | print | xdigit,
digit | print | xdigit, digit | print | xdigit,
digit | print | xdigit, digit | print | xdigit,
digit | print | xdigit, digit | print | xdigit,
digit | print | xdigit, digit | print | xdigit,
punct | print, punct | print,
punct | print, punct | print,
punct | print, punct | print,
punct | print, upper | xdigit | print | alpha,
upper | xdigit | print | alpha, upper | xdigit | print | alpha,
upper | xdigit | print | alpha, upper | xdigit | print | alpha,
upper | xdigit | print | alpha, upper | print | alpha,
upper | print | alpha, upper | print | alpha,
upper | print | alpha, upper | print | alpha,
upper | print | alpha, upper | print | alpha,
upper | print | alpha, upper | print | alpha,
upper | print | alpha, upper | print | alpha,
upper | print | alpha, upper | print | alpha,
upper | print | alpha, upper | print | alpha,
upper | print | alpha, upper | print | alpha,
upper | print | alpha, upper | print | alpha,
upper | print | alpha, punct | print,
punct | print, punct | print,
punct | print, punct | print,
punct | print, lower | xdigit | print | alpha,
lower | xdigit | print | alpha, lower | xdigit | print | alpha,
lower | xdigit | print | alpha, lower | xdigit | print | alpha,
lower | xdigit | print | alpha, lower | print | alpha,
lower | print | alpha, lower | print | alpha,
lower | print | alpha, lower | print | alpha,
lower | print | alpha, lower | print | alpha,
lower | print | alpha, lower | print | alpha,
lower | print | alpha, lower | print | alpha,
lower | print | alpha, lower | print | alpha,
lower | print | alpha, lower | print | alpha,
lower | print | alpha, lower | print | alpha,
lower | print | alpha, lower | print | alpha,
lower | print | alpha, punct | print,
punct | print, punct | print,
punct | print, cntrl,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
};
return builtin_table;
}
#else
const ctype<char>::mask*
ctype<char>::classic_table() _NOEXCEPT
{
#if defined(__APPLE__) || defined(__FreeBSD__)
return _DefaultRuneLocale.__runetype;
#elif defined(__NetBSD__)
return _C_ctype_tab_ + 1;
#elif defined(__GLIBC__)
return _LIBCPP_GET_C_LOCALE->__ctype_b;
#elif __sun__
return __ctype_mask;
#elif defined(_LIBCPP_MSVCRT) || defined(__MINGW32__)
return __pctype_func();
#elif defined(__EMSCRIPTEN__)
return *__ctype_b_loc();
#elif defined(_NEWLIB_VERSION)
// Newlib has a 257-entry table in ctype_.c, where (char)0 starts at [1].
return _ctype_ + 1;
#elif defined(_AIX)
return (const unsigned int *)__lc_ctype_ptr->obj->mask;
#else
// Platform not supported: abort so the person doing the port knows what to
// fix
# warning ctype<char>::classic_table() is not implemented
printf("ctype<char>::classic_table() is not implemented\n");
abort();
return NULL;
#endif
}
#endif
#if defined(__GLIBC__)
const int*
ctype<char>::__classic_lower_table() _NOEXCEPT
{
return _LIBCPP_GET_C_LOCALE->__ctype_tolower;
}
const int*
ctype<char>::__classic_upper_table() _NOEXCEPT
{
return _LIBCPP_GET_C_LOCALE->__ctype_toupper;
}
#elif __NetBSD__
const short*
ctype<char>::__classic_lower_table() _NOEXCEPT
{
return _C_tolower_tab_ + 1;
}
const short*
ctype<char>::__classic_upper_table() _NOEXCEPT
{
return _C_toupper_tab_ + 1;
}
#elif defined(__EMSCRIPTEN__)
const int*
ctype<char>::__classic_lower_table() _NOEXCEPT
{
return *__ctype_tolower_loc();
}
const int*
ctype<char>::__classic_upper_table() _NOEXCEPT
{
return *__ctype_toupper_loc();
}
#endif // __GLIBC__ || __NETBSD__ || __EMSCRIPTEN__
// template <> class ctype_byname<char>
ctype_byname<char>::ctype_byname(const char* name, size_t refs)
: ctype<char>(0, false, refs),
__l(newlocale(LC_ALL_MASK, name, 0))
{
if (__l == 0)
__throw_runtime_error("ctype_byname<char>::ctype_byname"
" failed to construct for " + string(name));
}
ctype_byname<char>::ctype_byname(const string& name, size_t refs)
: ctype<char>(0, false, refs),
__l(newlocale(LC_ALL_MASK, name.c_str(), 0))
{
if (__l == 0)
__throw_runtime_error("ctype_byname<char>::ctype_byname"
" failed to construct for " + name);
}
ctype_byname<char>::~ctype_byname()
{
freelocale(__l);
}
char
ctype_byname<char>::do_toupper(char_type c) const
{
return static_cast<char>(toupper_l(static_cast<unsigned char>(c), __l));
}
const char*
ctype_byname<char>::do_toupper(char_type* low, const char_type* high) const
{
for (; low != high; ++low)
*low = static_cast<char>(toupper_l(static_cast<unsigned char>(*low), __l));
return low;
}
char
ctype_byname<char>::do_tolower(char_type c) const
{
return static_cast<char>(tolower_l(static_cast<unsigned char>(c), __l));
}
const char*
ctype_byname<char>::do_tolower(char_type* low, const char_type* high) const
{
for (; low != high; ++low)
*low = static_cast<char>(tolower_l(static_cast<unsigned char>(*low), __l));
return low;
}
// template <> class ctype_byname<wchar_t>
ctype_byname<wchar_t>::ctype_byname(const char* name, size_t refs)
: ctype<wchar_t>(refs),
__l(newlocale(LC_ALL_MASK, name, 0))
{
if (__l == 0)
__throw_runtime_error("ctype_byname<wchar_t>::ctype_byname"
" failed to construct for " + string(name));
}
ctype_byname<wchar_t>::ctype_byname(const string& name, size_t refs)
: ctype<wchar_t>(refs),
__l(newlocale(LC_ALL_MASK, name.c_str(), 0))
{
if (__l == 0)
__throw_runtime_error("ctype_byname<wchar_t>::ctype_byname"
" failed to construct for " + name);
}
ctype_byname<wchar_t>::~ctype_byname()
{
freelocale(__l);
}
bool
ctype_byname<wchar_t>::do_is(mask m, char_type c) const
{
#ifdef _LIBCPP_WCTYPE_IS_MASK
return static_cast<bool>(iswctype_l(c, m, __l));
#else
bool result = false;
wint_t ch = static_cast<wint_t>(c);
if ((m & space) == space) result |= (iswspace_l(ch, __l) != 0);
if ((m & print) == print) result |= (iswprint_l(ch, __l) != 0);
if ((m & cntrl) == cntrl) result |= (iswcntrl_l(ch, __l) != 0);
if ((m & upper) == upper) result |= (iswupper_l(ch, __l) != 0);
if ((m & lower) == lower) result |= (iswlower_l(ch, __l) != 0);
if ((m & alpha) == alpha) result |= (iswalpha_l(ch, __l) != 0);
if ((m & digit) == digit) result |= (iswdigit_l(ch, __l) != 0);
if ((m & punct) == punct) result |= (iswpunct_l(ch, __l) != 0);
if ((m & xdigit) == xdigit) result |= (iswxdigit_l(ch, __l) != 0);
if ((m & blank) == blank) result |= (iswblank_l(ch, __l) != 0);
return result;
#endif
}
const wchar_t*
ctype_byname<wchar_t>::do_is(const char_type* low, const char_type* high, mask* vec) const
{
for (; low != high; ++low, ++vec)
{
if (isascii(*low))
*vec = static_cast<mask>(ctype<char>::classic_table()[*low]);
else
{
*vec = 0;
wint_t ch = static_cast<wint_t>(*low);
if (iswspace_l(ch, __l))
*vec |= space;
#ifndef _LIBCPP_CTYPE_MASK_IS_COMPOSITE_PRINT
if (iswprint_l(ch, __l))
*vec |= print;
#endif
if (iswcntrl_l(ch, __l))
*vec |= cntrl;
if (iswupper_l(ch, __l))
*vec |= upper;
if (iswlower_l(ch, __l))
*vec |= lower;
#ifndef _LIBCPP_CTYPE_MASK_IS_COMPOSITE_ALPHA
if (iswalpha_l(ch, __l))
*vec |= alpha;
#endif
if (iswdigit_l(ch, __l))
*vec |= digit;
if (iswpunct_l(ch, __l))
*vec |= punct;
#ifndef _LIBCPP_CTYPE_MASK_IS_COMPOSITE_XDIGIT
if (iswxdigit_l(ch, __l))
*vec |= xdigit;
#endif
#if !defined(__sun__)
if (iswblank_l(ch, __l))
*vec |= blank;
#endif
}
}
return low;
}
const wchar_t*
ctype_byname<wchar_t>::do_scan_is(mask m, const char_type* low, const char_type* high) const
{
for (; low != high; ++low)
{
#ifdef _LIBCPP_WCTYPE_IS_MASK
if (iswctype_l(*low, m, __l))
break;
#else
wint_t ch = static_cast<wint_t>(*low);
if ((m & space) == space && iswspace_l(ch, __l)) break;
if ((m & print) == print && iswprint_l(ch, __l)) break;
if ((m & cntrl) == cntrl && iswcntrl_l(ch, __l)) break;
if ((m & upper) == upper && iswupper_l(ch, __l)) break;
if ((m & lower) == lower && iswlower_l(ch, __l)) break;
if ((m & alpha) == alpha && iswalpha_l(ch, __l)) break;
if ((m & digit) == digit && iswdigit_l(ch, __l)) break;
if ((m & punct) == punct && iswpunct_l(ch, __l)) break;
if ((m & xdigit) == xdigit && iswxdigit_l(ch, __l)) break;
if ((m & blank) == blank && iswblank_l(ch, __l)) break;
#endif
}
return low;
}
const wchar_t*
ctype_byname<wchar_t>::do_scan_not(mask m, const char_type* low, const char_type* high) const
{
for (; low != high; ++low)
{
#ifdef _LIBCPP_WCTYPE_IS_MASK
if (!iswctype_l(*low, m, __l))
break;
#else
wint_t ch = static_cast<wint_t>(*low);
if ((m & space) == space && iswspace_l(ch, __l)) continue;
if ((m & print) == print && iswprint_l(ch, __l)) continue;
if ((m & cntrl) == cntrl && iswcntrl_l(ch, __l)) continue;
if ((m & upper) == upper && iswupper_l(ch, __l)) continue;
if ((m & lower) == lower && iswlower_l(ch, __l)) continue;
if ((m & alpha) == alpha && iswalpha_l(ch, __l)) continue;
if ((m & digit) == digit && iswdigit_l(ch, __l)) continue;
if ((m & punct) == punct && iswpunct_l(ch, __l)) continue;
if ((m & xdigit) == xdigit && iswxdigit_l(ch, __l)) continue;
if ((m & blank) == blank && iswblank_l(ch, __l)) continue;
break;
#endif
}
return low;
}
wchar_t
ctype_byname<wchar_t>::do_toupper(char_type c) const
{
return towupper_l(c, __l);
}
const wchar_t*
ctype_byname<wchar_t>::do_toupper(char_type* low, const char_type* high) const
{
for (; low != high; ++low)
*low = towupper_l(*low, __l);
return low;
}
wchar_t
ctype_byname<wchar_t>::do_tolower(char_type c) const
{
return towlower_l(c, __l);
}
const wchar_t*
ctype_byname<wchar_t>::do_tolower(char_type* low, const char_type* high) const
{
for (; low != high; ++low)
*low = towlower_l(*low, __l);
return low;
}
wchar_t
ctype_byname<wchar_t>::do_widen(char c) const
{
return __libcpp_btowc_l(c, __l);
}
const char*
ctype_byname<wchar_t>::do_widen(const char* low, const char* high, char_type* dest) const
{
for (; low != high; ++low, ++dest)
*dest = __libcpp_btowc_l(*low, __l);
return low;
}
char
ctype_byname<wchar_t>::do_narrow(char_type c, char dfault) const
{
int r = __libcpp_wctob_l(c, __l);
return r != static_cast<int>(WEOF) ? static_cast<char>(r) : dfault;
}
const wchar_t*
ctype_byname<wchar_t>::do_narrow(const char_type* low, const char_type* high, char dfault, char* dest) const
{
for (; low != high; ++low, ++dest)
{
int r = __libcpp_wctob_l(*low, __l);
*dest = r != static_cast<int>(WEOF) ? static_cast<char>(r) : dfault;
}
return low;
}
// template <> class codecvt<char, char, mbstate_t>
locale::id codecvt<char, char, mbstate_t>::id;
codecvt<char, char, mbstate_t>::~codecvt()
{
}
codecvt<char, char, mbstate_t>::result
codecvt<char, char, mbstate_t>::do_out(state_type&,
const intern_type* frm, const intern_type*, const intern_type*& frm_nxt,
extern_type* to, extern_type*, extern_type*& to_nxt) const
{
frm_nxt = frm;
to_nxt = to;
return noconv;
}
codecvt<char, char, mbstate_t>::result
codecvt<char, char, mbstate_t>::do_in(state_type&,
const extern_type* frm, const extern_type*, const extern_type*& frm_nxt,
intern_type* to, intern_type*, intern_type*& to_nxt) const
{
frm_nxt = frm;
to_nxt = to;
return noconv;
}
codecvt<char, char, mbstate_t>::result
codecvt<char, char, mbstate_t>::do_unshift(state_type&,
extern_type* to, extern_type*, extern_type*& to_nxt) const
{
to_nxt = to;
return noconv;
}
int
codecvt<char, char, mbstate_t>::do_encoding() const _NOEXCEPT
{
return 1;
}
bool
codecvt<char, char, mbstate_t>::do_always_noconv() const _NOEXCEPT
{
return true;
}
int
codecvt<char, char, mbstate_t>::do_length(state_type&,
const extern_type* frm, const extern_type* end, size_t mx) const
{
return static_cast<int>(min<size_t>(mx, static_cast<size_t>(end-frm)));
}
int
codecvt<char, char, mbstate_t>::do_max_length() const _NOEXCEPT
{
return 1;
}
// template <> class codecvt<wchar_t, char, mbstate_t>
locale::id codecvt<wchar_t, char, mbstate_t>::id;
codecvt<wchar_t, char, mbstate_t>::codecvt(size_t refs)
: locale::facet(refs),
__l(_LIBCPP_GET_C_LOCALE)
{
}
codecvt<wchar_t, char, mbstate_t>::codecvt(const char* nm, size_t refs)
: locale::facet(refs),
__l(newlocale(LC_ALL_MASK, nm, 0))
{
if (__l == 0)
__throw_runtime_error("codecvt_byname<wchar_t, char, mbstate_t>::codecvt_byname"
" failed to construct for " + string(nm));
}
codecvt<wchar_t, char, mbstate_t>::~codecvt()
{
if (__l != _LIBCPP_GET_C_LOCALE)
freelocale(__l);
}
codecvt<wchar_t, char, mbstate_t>::result
codecvt<wchar_t, char, mbstate_t>::do_out(state_type& st,
const intern_type* frm, const intern_type* frm_end, const intern_type*& frm_nxt,
extern_type* to, extern_type* to_end, extern_type*& to_nxt) const
{
// look for first internal null in frm
const intern_type* fend = frm;
for (; fend != frm_end; ++fend)
if (*fend == 0)
break;
// loop over all null-terminated sequences in frm
to_nxt = to;
for (frm_nxt = frm; frm != frm_end && to != to_end; frm = frm_nxt, to = to_nxt)
{
// save state in case it is needed to recover to_nxt on error
mbstate_t save_state = st;
size_t n = __libcpp_wcsnrtombs_l(to, &frm_nxt, static_cast<size_t>(fend-frm),
static_cast<size_t>(to_end-to), &st, __l);
if (n == size_t(-1))
{
// need to recover to_nxt
for (to_nxt = to; frm != frm_nxt; ++frm)
{
n = __libcpp_wcrtomb_l(to_nxt, *frm, &save_state, __l);
if (n == size_t(-1))
break;
to_nxt += n;
}
frm_nxt = frm;
return error;
}
if (n == 0)
return partial;
to_nxt += n;
if (to_nxt == to_end)
break;
if (fend != frm_end) // set up next null terminated sequence
{
// Try to write the terminating null
extern_type tmp[MB_LEN_MAX];
n = __libcpp_wcrtomb_l(tmp, intern_type(), &st, __l);
if (n == size_t(-1)) // on error
return error;
if (n > static_cast<size_t>(to_end-to_nxt)) // is there room?
return partial;
for (extern_type* p = tmp; n; --n) // write it
*to_nxt++ = *p++;
++frm_nxt;
// look for next null in frm
for (fend = frm_nxt; fend != frm_end; ++fend)
if (*fend == 0)
break;
}
}
return frm_nxt == frm_end ? ok : partial;
}
codecvt<wchar_t, char, mbstate_t>::result
codecvt<wchar_t, char, mbstate_t>::do_in(state_type& st,
const extern_type* frm, const extern_type* frm_end, const extern_type*& frm_nxt,
intern_type* to, intern_type* to_end, intern_type*& to_nxt) const
{
// look for first internal null in frm
const extern_type* fend = frm;
for (; fend != frm_end; ++fend)
if (*fend == 0)
break;
// loop over all null-terminated sequences in frm
to_nxt = to;
for (frm_nxt = frm; frm != frm_end && to != to_end; frm = frm_nxt, to = to_nxt)
{
// save state in case it is needed to recover to_nxt on error
mbstate_t save_state = st;
size_t n = __libcpp_mbsnrtowcs_l(to, &frm_nxt, static_cast<size_t>(fend-frm),
static_cast<size_t>(to_end-to), &st, __l);
if (n == size_t(-1))
{
// need to recover to_nxt
for (to_nxt = to; frm != frm_nxt; ++to_nxt)
{
n = __libcpp_mbrtowc_l(to_nxt, frm, static_cast<size_t>(fend-frm),
&save_state, __l);
switch (n)
{
case 0:
++frm;
break;
case size_t(-1):
frm_nxt = frm;
return error;
case size_t(-2):
frm_nxt = frm;
return partial;
default:
frm += n;
break;
}
}
frm_nxt = frm;
return frm_nxt == frm_end ? ok : partial;
}
if (n == size_t(-1))
return error;
to_nxt += n;
if (to_nxt == to_end)
break;
if (fend != frm_end) // set up next null terminated sequence
{
// Try to write the terminating null
n = __libcpp_mbrtowc_l(to_nxt, frm_nxt, 1, &st, __l);
if (n != 0) // on error
return error;
++to_nxt;
++frm_nxt;
// look for next null in frm
for (fend = frm_nxt; fend != frm_end; ++fend)
if (*fend == 0)
break;
}
}
return frm_nxt == frm_end ? ok : partial;
}
codecvt<wchar_t, char, mbstate_t>::result
codecvt<wchar_t, char, mbstate_t>::do_unshift(state_type& st,
extern_type* to, extern_type* to_end, extern_type*& to_nxt) const
{
to_nxt = to;
extern_type tmp[MB_LEN_MAX];
size_t n = __libcpp_wcrtomb_l(tmp, intern_type(), &st, __l);
if (n == size_t(-1) || n == 0) // on error
return error;
--n;
if (n > static_cast<size_t>(to_end-to_nxt)) // is there room?
return partial;
for (extern_type* p = tmp; n; --n) // write it
*to_nxt++ = *p++;
return ok;
}
int
codecvt<wchar_t, char, mbstate_t>::do_encoding() const _NOEXCEPT
{
if (__libcpp_mbtowc_l(nullptr, nullptr, MB_LEN_MAX, __l) != 0)
return -1;
// stateless encoding
if (__l == 0 || __libcpp_mb_cur_max_l(__l) == 1) // there are no known constant length encodings
return 1; // which take more than 1 char to form a wchar_t
return 0;
}
bool
codecvt<wchar_t, char, mbstate_t>::do_always_noconv() const _NOEXCEPT
{
return false;
}
int
codecvt<wchar_t, char, mbstate_t>::do_length(state_type& st,
const extern_type* frm, const extern_type* frm_end, size_t mx) const
{
int nbytes = 0;
for (size_t nwchar_t = 0; nwchar_t < mx && frm != frm_end; ++nwchar_t)
{
size_t n = __libcpp_mbrlen_l(frm, static_cast<size_t>(frm_end-frm), &st, __l);
switch (n)
{
case 0:
++nbytes;
++frm;
break;
case size_t(-1):
case size_t(-2):
return nbytes;
default:
nbytes += n;
frm += n;
break;
}
}
return nbytes;
}
int
codecvt<wchar_t, char, mbstate_t>::do_max_length() const _NOEXCEPT
{
return __l == 0 ? 1 : static_cast<int>(__libcpp_mb_cur_max_l(__l));
}
_LIBCPP_END_NAMESPACE_STD
| 49,861 | 1,661 | jart/cosmopolitan | false |
cosmopolitan/third_party/libcxx/string_view | // -*- C++ -*-
//===------------------------ string_view ---------------------------------===//
//
// 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_STRING_VIEW
#define _LIBCPP_STRING_VIEW
#include "third_party/libcxx/__config"
#include "third_party/libcxx/__string"
#include "third_party/libcxx/iosfwd"
#include "third_party/libcxx/algorithm"
#include "third_party/libcxx/iterator"
#include "third_party/libcxx/limits"
#include "third_party/libcxx/stdexcept"
#include "third_party/libcxx/version"
#include "third_party/libcxx/__debug"
#pragma GCC diagnostic ignored "-Wliteral-suffix"
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
#pragma GCC system_header
#endif
_LIBCPP_PUSH_MACROS
#include "third_party/libcxx/__undef_macros"
_LIBCPP_BEGIN_NAMESPACE_STD
/*
string_view synopsis
namespace std {
// 7.2, Class template basic_string_view
template<class charT, class traits = char_traits<charT>>
class basic_string_view;
// 7.9, basic_string_view non-member comparison functions
template<class charT, class traits>
constexpr bool operator==(basic_string_view<charT, traits> x,
basic_string_view<charT, traits> y) noexcept;
template<class charT, class traits>
constexpr bool operator!=(basic_string_view<charT, traits> x,
basic_string_view<charT, traits> y) noexcept;
template<class charT, class traits>
constexpr bool operator< (basic_string_view<charT, traits> x,
basic_string_view<charT, traits> y) noexcept;
template<class charT, class traits>
constexpr bool operator> (basic_string_view<charT, traits> x,
basic_string_view<charT, traits> y) noexcept;
template<class charT, class traits>
constexpr bool operator<=(basic_string_view<charT, traits> x,
basic_string_view<charT, traits> y) noexcept;
template<class charT, class traits>
constexpr bool operator>=(basic_string_view<charT, traits> x,
basic_string_view<charT, traits> y) noexcept;
// see below, sufficient additional overloads of comparison functions
// 7.10, Inserters and extractors
template<class charT, class traits>
basic_ostream<charT, traits>&
operator<<(basic_ostream<charT, traits>& os,
basic_string_view<charT, traits> str);
// basic_string_view typedef names
typedef basic_string_view<char> string_view;
typedef basic_string_view<char16_t> u16string_view;
typedef basic_string_view<char32_t> u32string_view;
typedef basic_string_view<wchar_t> wstring_view;
template<class charT, class traits = char_traits<charT>>
class basic_string_view {
public:
// types
typedef traits traits_type;
typedef charT value_type;
typedef charT* pointer;
typedef const charT* const_pointer;
typedef charT& reference;
typedef const charT& const_reference;
typedef implementation-defined const_iterator;
typedef const_iterator iterator;
typedef reverse_iterator<const_iterator> const_reverse_iterator;
typedef const_reverse_iterator reverse_iterator;
typedef size_t size_type;
typedef ptrdiff_t difference_type;
static constexpr size_type npos = size_type(-1);
// 7.3, basic_string_view constructors and assignment operators
constexpr basic_string_view() noexcept;
constexpr basic_string_view(const basic_string_view&) noexcept = default;
basic_string_view& operator=(const basic_string_view&) noexcept = default;
template<class Allocator>
constexpr basic_string_view(const charT* str);
constexpr basic_string_view(const charT* str, size_type len);
// 7.4, basic_string_view iterator support
constexpr const_iterator begin() const noexcept;
constexpr const_iterator end() const noexcept;
constexpr const_iterator cbegin() const noexcept;
constexpr const_iterator cend() const noexcept;
const_reverse_iterator rbegin() const noexcept;
const_reverse_iterator rend() const noexcept;
const_reverse_iterator crbegin() const noexcept;
const_reverse_iterator crend() const noexcept;
// 7.5, basic_string_view capacity
constexpr size_type size() const noexcept;
constexpr size_type length() const noexcept;
constexpr size_type max_size() const noexcept;
constexpr bool empty() const noexcept;
// 7.6, basic_string_view element access
constexpr const_reference operator[](size_type pos) const;
constexpr const_reference at(size_type pos) const;
constexpr const_reference front() const;
constexpr const_reference back() const;
constexpr const_pointer data() const noexcept;
// 7.7, basic_string_view modifiers
constexpr void remove_prefix(size_type n);
constexpr void remove_suffix(size_type n);
constexpr void swap(basic_string_view& s) noexcept;
size_type copy(charT* s, size_type n, size_type pos = 0) const;
constexpr basic_string_view substr(size_type pos = 0, size_type n = npos) const;
constexpr int compare(basic_string_view s) const noexcept;
constexpr int compare(size_type pos1, size_type n1, basic_string_view s) const;
constexpr int compare(size_type pos1, size_type n1,
basic_string_view s, size_type pos2, size_type n2) const;
constexpr int compare(const charT* s) const;
constexpr int compare(size_type pos1, size_type n1, const charT* s) const;
constexpr int compare(size_type pos1, size_type n1,
const charT* s, size_type n2) const;
constexpr size_type find(basic_string_view s, size_type pos = 0) const noexcept;
constexpr size_type find(charT c, size_type pos = 0) const noexcept;
constexpr size_type find(const charT* s, size_type pos, size_type n) const;
constexpr size_type find(const charT* s, size_type pos = 0) const;
constexpr size_type rfind(basic_string_view s, size_type pos = npos) const noexcept;
constexpr size_type rfind(charT c, size_type pos = npos) const noexcept;
constexpr size_type rfind(const charT* s, size_type pos, size_type n) const;
constexpr size_type rfind(const charT* s, size_type pos = npos) const;
constexpr size_type find_first_of(basic_string_view s, size_type pos = 0) const noexcept;
constexpr size_type find_first_of(charT c, size_type pos = 0) const noexcept;
constexpr size_type find_first_of(const charT* s, size_type pos, size_type n) const;
constexpr size_type find_first_of(const charT* s, size_type pos = 0) const;
constexpr size_type find_last_of(basic_string_view s, size_type pos = npos) const noexcept;
constexpr size_type find_last_of(charT c, size_type pos = npos) const noexcept;
constexpr size_type find_last_of(const charT* s, size_type pos, size_type n) const;
constexpr size_type find_last_of(const charT* s, size_type pos = npos) const;
constexpr size_type find_first_not_of(basic_string_view s, size_type pos = 0) const noexcept;
constexpr size_type find_first_not_of(charT c, size_type pos = 0) const noexcept;
constexpr size_type find_first_not_of(const charT* s, size_type pos, size_type n) const;
constexpr size_type find_first_not_of(const charT* s, size_type pos = 0) const;
constexpr size_type find_last_not_of(basic_string_view s, size_type pos = npos) const noexcept;
constexpr size_type find_last_not_of(charT c, size_type pos = npos) const noexcept;
constexpr size_type find_last_not_of(const charT* s, size_type pos, size_type n) const;
constexpr size_type find_last_not_of(const charT* s, size_type pos = npos) const;
constexpr bool starts_with(basic_string_view s) const noexcept; // C++2a
constexpr bool starts_with(charT c) const noexcept; // C++2a
constexpr bool starts_with(const charT* s) const; // C++2a
constexpr bool ends_with(basic_string_view s) const noexcept; // C++2a
constexpr bool ends_with(charT c) const noexcept; // C++2a
constexpr bool ends_with(const charT* s) const; // C++2a
private:
const_pointer data_; // exposition only
size_type size_; // exposition only
};
// 7.11, Hash support
template <class T> struct hash;
template <> struct hash<string_view>;
template <> struct hash<u16string_view>;
template <> struct hash<u32string_view>;
template <> struct hash<wstring_view>;
constexpr basic_string_view<char> operator "" sv( const char *str, size_t len ) noexcept;
constexpr basic_string_view<wchar_t> operator "" sv( const wchar_t *str, size_t len ) noexcept;
constexpr basic_string_view<char16_t> operator "" sv( const char16_t *str, size_t len ) noexcept;
constexpr basic_string_view<char32_t> operator "" sv( const char32_t *str, size_t len ) noexcept;
} // namespace std
*/
template<class _CharT, class _Traits = char_traits<_CharT> >
class _LIBCPP_TEMPLATE_VIS basic_string_view {
public:
// types
typedef _Traits traits_type;
typedef _CharT value_type;
typedef _CharT* pointer;
typedef const _CharT* const_pointer;
typedef _CharT& reference;
typedef const _CharT& const_reference;
typedef const_pointer const_iterator; // See [string.view.iterators]
typedef const_iterator iterator;
typedef _VSTD::reverse_iterator<const_iterator> const_reverse_iterator;
typedef const_reverse_iterator reverse_iterator;
typedef size_t size_type;
typedef ptrdiff_t difference_type;
static _LIBCPP_CONSTEXPR const size_type npos = -1; // size_type(-1);
static_assert((!is_array<value_type>::value), "Character type of basic_string_view must not be an array");
static_assert(( is_standard_layout<value_type>::value), "Character type of basic_string_view must be standard-layout");
static_assert(( is_trivial<value_type>::value), "Character type of basic_string_view must be trivial");
static_assert((is_same<_CharT, typename traits_type::char_type>::value),
"traits_type::char_type must be the same type as CharT");
// [string.view.cons], construct/copy
_LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY
basic_string_view() _NOEXCEPT : __data (nullptr), __size(0) {}
_LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY
basic_string_view(const basic_string_view&) _NOEXCEPT = default;
_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
basic_string_view& operator=(const basic_string_view&) _NOEXCEPT = default;
_LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY
basic_string_view(const _CharT* __s, size_type __len) _NOEXCEPT
: __data(__s), __size(__len)
{
#if _LIBCPP_STD_VER > 11
_LIBCPP_ASSERT(__len == 0 || __s != nullptr, "string_view::string_view(_CharT *, size_t): received nullptr");
#endif
}
_LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY
basic_string_view(const _CharT* __s)
: __data(__s), __size(std::__char_traits_length_checked<_Traits>(__s)) {}
// [string.view.iterators], iterators
_LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY
const_iterator begin() const _NOEXCEPT { return cbegin(); }
_LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY
const_iterator end() const _NOEXCEPT { return cend(); }
_LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY
const_iterator cbegin() const _NOEXCEPT { return __data; }
_LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY
const_iterator cend() const _NOEXCEPT { return __data + __size; }
_LIBCPP_CONSTEXPR_AFTER_CXX14 _LIBCPP_INLINE_VISIBILITY
const_reverse_iterator rbegin() const _NOEXCEPT { return const_reverse_iterator(cend()); }
_LIBCPP_CONSTEXPR_AFTER_CXX14 _LIBCPP_INLINE_VISIBILITY
const_reverse_iterator rend() const _NOEXCEPT { return const_reverse_iterator(cbegin()); }
_LIBCPP_CONSTEXPR_AFTER_CXX14 _LIBCPP_INLINE_VISIBILITY
const_reverse_iterator crbegin() const _NOEXCEPT { return const_reverse_iterator(cend()); }
_LIBCPP_CONSTEXPR_AFTER_CXX14 _LIBCPP_INLINE_VISIBILITY
const_reverse_iterator crend() const _NOEXCEPT { return const_reverse_iterator(cbegin()); }
// [string.view.capacity], capacity
_LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY
size_type size() const _NOEXCEPT { return __size; }
_LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY
size_type length() const _NOEXCEPT { return __size; }
_LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY
size_type max_size() const _NOEXCEPT { return numeric_limits<size_type>::max(); }
_LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
bool empty() const _NOEXCEPT { return __size == 0; }
// [string.view.access], element access
_LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY
const_reference operator[](size_type __pos) const _NOEXCEPT { return __data[__pos]; }
_LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY
const_reference at(size_type __pos) const
{
return __pos >= size()
? (__throw_out_of_range("string_view::at"), __data[0])
: __data[__pos];
}
_LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY
const_reference front() const _NOEXCEPT
{
return _LIBCPP_ASSERT(!empty(), "string_view::front(): string is empty"), __data[0];
}
_LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY
const_reference back() const _NOEXCEPT
{
return _LIBCPP_ASSERT(!empty(), "string_view::back(): string is empty"), __data[__size-1];
}
_LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY
const_pointer data() const _NOEXCEPT { return __data; }
// [string.view.modifiers], modifiers:
_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
void remove_prefix(size_type __n) _NOEXCEPT
{
_LIBCPP_ASSERT(__n <= size(), "remove_prefix() can't remove more than size()");
__data += __n;
__size -= __n;
}
_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
void remove_suffix(size_type __n) _NOEXCEPT
{
_LIBCPP_ASSERT(__n <= size(), "remove_suffix() can't remove more than size()");
__size -= __n;
}
_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
void swap(basic_string_view& __other) _NOEXCEPT
{
const value_type *__p = __data;
__data = __other.__data;
__other.__data = __p;
size_type __sz = __size;
__size = __other.__size;
__other.__size = __sz;
}
_LIBCPP_INLINE_VISIBILITY
size_type copy(_CharT* __s, size_type __n, size_type __pos = 0) const
{
if (__pos > size())
__throw_out_of_range("string_view::copy");
size_type __rlen = _VSTD::min(__n, size() - __pos);
_Traits::copy(__s, data() + __pos, __rlen);
return __rlen;
}
_LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY
basic_string_view substr(size_type __pos = 0, size_type __n = npos) const
{
return __pos > size()
? (__throw_out_of_range("string_view::substr"), basic_string_view())
: basic_string_view(data() + __pos, _VSTD::min(__n, size() - __pos));
}
_LIBCPP_CONSTEXPR_AFTER_CXX11 int compare(basic_string_view __sv) const _NOEXCEPT
{
size_type __rlen = _VSTD::min( size(), __sv.size());
int __retval = _Traits::compare(data(), __sv.data(), __rlen);
if ( __retval == 0 ) // first __rlen chars matched
__retval = size() == __sv.size() ? 0 : ( size() < __sv.size() ? -1 : 1 );
return __retval;
}
_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
int compare(size_type __pos1, size_type __n1, basic_string_view __sv) const
{
return substr(__pos1, __n1).compare(__sv);
}
_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
int compare( size_type __pos1, size_type __n1,
basic_string_view __sv, size_type __pos2, size_type __n2) const
{
return substr(__pos1, __n1).compare(__sv.substr(__pos2, __n2));
}
_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
int compare(const _CharT* __s) const _NOEXCEPT
{
return compare(basic_string_view(__s));
}
_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
int compare(size_type __pos1, size_type __n1, const _CharT* __s) const
{
return substr(__pos1, __n1).compare(basic_string_view(__s));
}
_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
int compare(size_type __pos1, size_type __n1, const _CharT* __s, size_type __n2) const
{
return substr(__pos1, __n1).compare(basic_string_view(__s, __n2));
}
// find
_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
size_type find(basic_string_view __s, size_type __pos = 0) const _NOEXCEPT
{
_LIBCPP_ASSERT(__s.size() == 0 || __s.data() != nullptr, "string_view::find(): received nullptr");
return __str_find<value_type, size_type, traits_type, npos>
(data(), size(), __s.data(), __pos, __s.size());
}
_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
size_type find(_CharT __c, size_type __pos = 0) const _NOEXCEPT
{
return __str_find<value_type, size_type, traits_type, npos>
(data(), size(), __c, __pos);
}
_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
size_type find(const _CharT* __s, size_type __pos, size_type __n) const
{
_LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string_view::find(): received nullptr");
return __str_find<value_type, size_type, traits_type, npos>
(data(), size(), __s, __pos, __n);
}
_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
size_type find(const _CharT* __s, size_type __pos = 0) const
{
_LIBCPP_ASSERT(__s != nullptr, "string_view::find(): received nullptr");
return __str_find<value_type, size_type, traits_type, npos>
(data(), size(), __s, __pos, traits_type::length(__s));
}
// rfind
_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
size_type rfind(basic_string_view __s, size_type __pos = npos) const _NOEXCEPT
{
_LIBCPP_ASSERT(__s.size() == 0 || __s.data() != nullptr, "string_view::find(): received nullptr");
return __str_rfind<value_type, size_type, traits_type, npos>
(data(), size(), __s.data(), __pos, __s.size());
}
_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
size_type rfind(_CharT __c, size_type __pos = npos) const _NOEXCEPT
{
return __str_rfind<value_type, size_type, traits_type, npos>
(data(), size(), __c, __pos);
}
_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
size_type rfind(const _CharT* __s, size_type __pos, size_type __n) const
{
_LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string_view::rfind(): received nullptr");
return __str_rfind<value_type, size_type, traits_type, npos>
(data(), size(), __s, __pos, __n);
}
_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
size_type rfind(const _CharT* __s, size_type __pos=npos) const
{
_LIBCPP_ASSERT(__s != nullptr, "string_view::rfind(): received nullptr");
return __str_rfind<value_type, size_type, traits_type, npos>
(data(), size(), __s, __pos, traits_type::length(__s));
}
// find_first_of
_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
size_type find_first_of(basic_string_view __s, size_type __pos = 0) const _NOEXCEPT
{
_LIBCPP_ASSERT(__s.size() == 0 || __s.data() != nullptr, "string_view::find_first_of(): received nullptr");
return __str_find_first_of<value_type, size_type, traits_type, npos>
(data(), size(), __s.data(), __pos, __s.size());
}
_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
size_type find_first_of(_CharT __c, size_type __pos = 0) const _NOEXCEPT
{ return find(__c, __pos); }
_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
size_type find_first_of(const _CharT* __s, size_type __pos, size_type __n) const
{
_LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string_view::find_first_of(): received nullptr");
return __str_find_first_of<value_type, size_type, traits_type, npos>
(data(), size(), __s, __pos, __n);
}
_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
size_type find_first_of(const _CharT* __s, size_type __pos=0) const
{
_LIBCPP_ASSERT(__s != nullptr, "string_view::find_first_of(): received nullptr");
return __str_find_first_of<value_type, size_type, traits_type, npos>
(data(), size(), __s, __pos, traits_type::length(__s));
}
// find_last_of
_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
size_type find_last_of(basic_string_view __s, size_type __pos=npos) const _NOEXCEPT
{
_LIBCPP_ASSERT(__s.size() == 0 || __s.data() != nullptr, "string_view::find_last_of(): received nullptr");
return __str_find_last_of<value_type, size_type, traits_type, npos>
(data(), size(), __s.data(), __pos, __s.size());
}
_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
size_type find_last_of(_CharT __c, size_type __pos = npos) const _NOEXCEPT
{ return rfind(__c, __pos); }
_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
size_type find_last_of(const _CharT* __s, size_type __pos, size_type __n) const
{
_LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string_view::find_last_of(): received nullptr");
return __str_find_last_of<value_type, size_type, traits_type, npos>
(data(), size(), __s, __pos, __n);
}
_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
size_type find_last_of(const _CharT* __s, size_type __pos=npos) const
{
_LIBCPP_ASSERT(__s != nullptr, "string_view::find_last_of(): received nullptr");
return __str_find_last_of<value_type, size_type, traits_type, npos>
(data(), size(), __s, __pos, traits_type::length(__s));
}
// find_first_not_of
_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
size_type find_first_not_of(basic_string_view __s, size_type __pos=0) const _NOEXCEPT
{
_LIBCPP_ASSERT(__s.size() == 0 || __s.data() != nullptr, "string_view::find_first_not_of(): received nullptr");
return __str_find_first_not_of<value_type, size_type, traits_type, npos>
(data(), size(), __s.data(), __pos, __s.size());
}
_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
size_type find_first_not_of(_CharT __c, size_type __pos=0) const _NOEXCEPT
{
return __str_find_first_not_of<value_type, size_type, traits_type, npos>
(data(), size(), __c, __pos);
}
_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
size_type find_first_not_of(const _CharT* __s, size_type __pos, size_type __n) const
{
_LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string_view::find_first_not_of(): received nullptr");
return __str_find_first_not_of<value_type, size_type, traits_type, npos>
(data(), size(), __s, __pos, __n);
}
_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
size_type find_first_not_of(const _CharT* __s, size_type __pos=0) const
{
_LIBCPP_ASSERT(__s != nullptr, "string_view::find_first_not_of(): received nullptr");
return __str_find_first_not_of<value_type, size_type, traits_type, npos>
(data(), size(), __s, __pos, traits_type::length(__s));
}
// find_last_not_of
_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
size_type find_last_not_of(basic_string_view __s, size_type __pos=npos) const _NOEXCEPT
{
_LIBCPP_ASSERT(__s.size() == 0 || __s.data() != nullptr, "string_view::find_last_not_of(): received nullptr");
return __str_find_last_not_of<value_type, size_type, traits_type, npos>
(data(), size(), __s.data(), __pos, __s.size());
}
_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
size_type find_last_not_of(_CharT __c, size_type __pos=npos) const _NOEXCEPT
{
return __str_find_last_not_of<value_type, size_type, traits_type, npos>
(data(), size(), __c, __pos);
}
_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
size_type find_last_not_of(const _CharT* __s, size_type __pos, size_type __n) const
{
_LIBCPP_ASSERT(__n == 0 || __s != nullptr, "string_view::find_last_not_of(): received nullptr");
return __str_find_last_not_of<value_type, size_type, traits_type, npos>
(data(), size(), __s, __pos, __n);
}
_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
size_type find_last_not_of(const _CharT* __s, size_type __pos=npos) const
{
_LIBCPP_ASSERT(__s != nullptr, "string_view::find_last_not_of(): received nullptr");
return __str_find_last_not_of<value_type, size_type, traits_type, npos>
(data(), size(), __s, __pos, traits_type::length(__s));
}
#if _LIBCPP_STD_VER > 17
_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
bool starts_with(basic_string_view __s) const _NOEXCEPT
{ return size() >= __s.size() && compare(0, __s.size(), __s) == 0; }
_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
bool starts_with(value_type __c) const _NOEXCEPT
{ return !empty() && _Traits::eq(front(), __c); }
_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
bool starts_with(const value_type* __s) const _NOEXCEPT
{ return starts_with(basic_string_view(__s)); }
_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
bool ends_with(basic_string_view __s) const _NOEXCEPT
{ return size() >= __s.size() && compare(size() - __s.size(), npos, __s) == 0; }
_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
bool ends_with(value_type __c) const _NOEXCEPT
{ return !empty() && _Traits::eq(back(), __c); }
_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
bool ends_with(const value_type* __s) const _NOEXCEPT
{ return ends_with(basic_string_view(__s)); }
#endif
private:
const value_type* __data;
size_type __size;
};
// [string.view.comparison]
// operator ==
template<class _CharT, class _Traits>
_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
bool operator==(basic_string_view<_CharT, _Traits> __lhs,
basic_string_view<_CharT, _Traits> __rhs) _NOEXCEPT
{
if ( __lhs.size() != __rhs.size()) return false;
return __lhs.compare(__rhs) == 0;
}
template<class _CharT, class _Traits>
_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
bool operator==(basic_string_view<_CharT, _Traits> __lhs,
typename common_type<basic_string_view<_CharT, _Traits> >::type __rhs) _NOEXCEPT
{
if ( __lhs.size() != __rhs.size()) return false;
return __lhs.compare(__rhs) == 0;
}
template<class _CharT, class _Traits>
_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
bool operator==(typename common_type<basic_string_view<_CharT, _Traits> >::type __lhs,
basic_string_view<_CharT, _Traits> __rhs) _NOEXCEPT
{
if ( __lhs.size() != __rhs.size()) return false;
return __lhs.compare(__rhs) == 0;
}
// operator !=
template<class _CharT, class _Traits>
_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
bool operator!=(basic_string_view<_CharT, _Traits> __lhs, basic_string_view<_CharT, _Traits> __rhs) _NOEXCEPT
{
if ( __lhs.size() != __rhs.size())
return true;
return __lhs.compare(__rhs) != 0;
}
template<class _CharT, class _Traits>
_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
bool operator!=(basic_string_view<_CharT, _Traits> __lhs,
typename common_type<basic_string_view<_CharT, _Traits> >::type __rhs) _NOEXCEPT
{
if ( __lhs.size() != __rhs.size())
return true;
return __lhs.compare(__rhs) != 0;
}
template<class _CharT, class _Traits>
_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
bool operator!=(typename common_type<basic_string_view<_CharT, _Traits> >::type __lhs,
basic_string_view<_CharT, _Traits> __rhs) _NOEXCEPT
{
if ( __lhs.size() != __rhs.size())
return true;
return __lhs.compare(__rhs) != 0;
}
// operator <
template<class _CharT, class _Traits>
_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
bool operator<(basic_string_view<_CharT, _Traits> __lhs, basic_string_view<_CharT, _Traits> __rhs) _NOEXCEPT
{
return __lhs.compare(__rhs) < 0;
}
template<class _CharT, class _Traits>
_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
bool operator<(basic_string_view<_CharT, _Traits> __lhs,
typename common_type<basic_string_view<_CharT, _Traits> >::type __rhs) _NOEXCEPT
{
return __lhs.compare(__rhs) < 0;
}
template<class _CharT, class _Traits>
_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
bool operator<(typename common_type<basic_string_view<_CharT, _Traits> >::type __lhs,
basic_string_view<_CharT, _Traits> __rhs) _NOEXCEPT
{
return __lhs.compare(__rhs) < 0;
}
// operator >
template<class _CharT, class _Traits>
_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
bool operator> (basic_string_view<_CharT, _Traits> __lhs, basic_string_view<_CharT, _Traits> __rhs) _NOEXCEPT
{
return __lhs.compare(__rhs) > 0;
}
template<class _CharT, class _Traits>
_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
bool operator>(basic_string_view<_CharT, _Traits> __lhs,
typename common_type<basic_string_view<_CharT, _Traits> >::type __rhs) _NOEXCEPT
{
return __lhs.compare(__rhs) > 0;
}
template<class _CharT, class _Traits>
_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
bool operator>(typename common_type<basic_string_view<_CharT, _Traits> >::type __lhs,
basic_string_view<_CharT, _Traits> __rhs) _NOEXCEPT
{
return __lhs.compare(__rhs) > 0;
}
// operator <=
template<class _CharT, class _Traits>
_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
bool operator<=(basic_string_view<_CharT, _Traits> __lhs, basic_string_view<_CharT, _Traits> __rhs) _NOEXCEPT
{
return __lhs.compare(__rhs) <= 0;
}
template<class _CharT, class _Traits>
_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
bool operator<=(basic_string_view<_CharT, _Traits> __lhs,
typename common_type<basic_string_view<_CharT, _Traits> >::type __rhs) _NOEXCEPT
{
return __lhs.compare(__rhs) <= 0;
}
template<class _CharT, class _Traits>
_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
bool operator<=(typename common_type<basic_string_view<_CharT, _Traits> >::type __lhs,
basic_string_view<_CharT, _Traits> __rhs) _NOEXCEPT
{
return __lhs.compare(__rhs) <= 0;
}
// operator >=
template<class _CharT, class _Traits>
_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
bool operator>=(basic_string_view<_CharT, _Traits> __lhs, basic_string_view<_CharT, _Traits> __rhs) _NOEXCEPT
{
return __lhs.compare(__rhs) >= 0;
}
template<class _CharT, class _Traits>
_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
bool operator>=(basic_string_view<_CharT, _Traits> __lhs,
typename common_type<basic_string_view<_CharT, _Traits> >::type __rhs) _NOEXCEPT
{
return __lhs.compare(__rhs) >= 0;
}
template<class _CharT, class _Traits>
_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
bool operator>=(typename common_type<basic_string_view<_CharT, _Traits> >::type __lhs,
basic_string_view<_CharT, _Traits> __rhs) _NOEXCEPT
{
return __lhs.compare(__rhs) >= 0;
}
template<class _CharT, class _Traits>
basic_ostream<_CharT, _Traits>&
operator<<(basic_ostream<_CharT, _Traits>& __os,
basic_string_view<_CharT, _Traits> __str);
typedef basic_string_view<char> string_view;
#ifndef _LIBCPP_NO_HAS_CHAR8_T
typedef basic_string_view<char8_t> u8string_view;
#endif
typedef basic_string_view<char16_t> u16string_view;
typedef basic_string_view<char32_t> u32string_view;
typedef basic_string_view<wchar_t> wstring_view;
// [string.view.hash]
template<class _CharT>
struct _LIBCPP_TEMPLATE_VIS hash<basic_string_view<_CharT, char_traits<_CharT> > >
: public unary_function<basic_string_view<_CharT, char_traits<_CharT> >, size_t>
{
_LIBCPP_INLINE_VISIBILITY
size_t operator()(const basic_string_view<_CharT, char_traits<_CharT> > __val) const _NOEXCEPT {
return __do_string_hash(__val.data(), __val.data() + __val.size());
}
};
#if _LIBCPP_STD_VER > 11
inline namespace literals
{
inline namespace string_view_literals
{
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
basic_string_view<char> operator "" sv(const char *__str, size_t __len) _NOEXCEPT
{
return basic_string_view<char> (__str, __len);
}
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
basic_string_view<wchar_t> operator "" sv(const wchar_t *__str, size_t __len) _NOEXCEPT
{
return basic_string_view<wchar_t> (__str, __len);
}
#ifndef _LIBCPP_NO_HAS_CHAR8_T
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
basic_string_view<char8_t> operator "" sv(const char8_t *__str, size_t __len) _NOEXCEPT
{
return basic_string_view<char8_t> (__str, __len);
}
#endif
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
basic_string_view<char16_t> operator "" sv(const char16_t *__str, size_t __len) _NOEXCEPT
{
return basic_string_view<char16_t> (__str, __len);
}
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
basic_string_view<char32_t> operator "" sv(const char32_t *__str, size_t __len) _NOEXCEPT
{
return basic_string_view<char32_t> (__str, __len);
}
}
}
#endif
_LIBCPP_END_NAMESPACE_STD
_LIBCPP_POP_MACROS
#endif // _LIBCPP_STRING_VIEW
| 34,794 | 843 | jart/cosmopolitan | false |
cosmopolitan/third_party/libcxx/cwchar | // -*- C++ -*-
//===--------------------------- cwchar -----------------------------------===//
//
// 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_CWCHAR
#define _LIBCPP_CWCHAR
#include "third_party/libcxx/__config"
#include "third_party/libcxx/cwctype"
#include "third_party/libcxx/wchar.h"
#include "libc/stdio/stdio.h"
#include "libc/str/str.h"
#include "libc/time/struct/tm.h"
#include "libc/stdio/stdio.h"
#include "libc/stdio/stdio.h"
#include "libc/fmt/conv.h"
#include "third_party/gdtoa/gdtoa.h"
#include "libc/time/struct/tm.h"
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
#pragma GCC system_header
#endif
_LIBCPP_BEGIN_NAMESPACE_STD
/*
cwchar synopsis
Macros:
NULL
WCHAR_MAX
WCHAR_MIN
WEOF
namespace std
{
Types:
mbstate_t
size_t
tm
wint_t
int fwprintf(FILE* restrict stream, const wchar_t* restrict format, ...);
int fwscanf(FILE* restrict stream, const wchar_t* restrict format, ...);
int swprintf(wchar_t* restrict s, size_t n, const wchar_t* restrict format, ...);
int swscanf(const wchar_t* restrict s, const wchar_t* restrict format, ...);
int vfwprintf(FILE* restrict stream, const wchar_t* restrict format, va_list arg);
int vfwscanf(FILE* restrict stream, const wchar_t* restrict format, va_list arg); // C99
int vswprintf(wchar_t* restrict s, size_t n, const wchar_t* restrict format, va_list arg);
int vswscanf(const wchar_t* restrict s, const wchar_t* restrict format, va_list arg); // C99
int vwprintf(const wchar_t* restrict format, va_list arg);
int vwscanf(const wchar_t* restrict format, va_list arg); // C99
int wprintf(const wchar_t* restrict format, ...);
int wscanf(const wchar_t* restrict format, ...);
wint_t fgetwc(FILE* stream);
wchar_t* fgetws(wchar_t* restrict s, int n, FILE* restrict stream);
wint_t fputwc(wchar_t c, FILE* stream);
int fputws(const wchar_t* restrict s, FILE* restrict stream);
int fwide(FILE* stream, int mode);
wint_t getwc(FILE* stream);
wint_t getwchar();
wint_t putwc(wchar_t c, FILE* stream);
wint_t putwchar(wchar_t c);
wint_t ungetwc(wint_t c, FILE* stream);
double wcstod(const wchar_t* restrict nptr, wchar_t** restrict endptr);
float wcstof(const wchar_t* restrict nptr, wchar_t** restrict endptr); // C99
long double wcstold(const wchar_t* restrict nptr, wchar_t** restrict endptr); // C99
long wcstol(const wchar_t* restrict nptr, wchar_t** restrict endptr, int base);
long long wcstoll(const wchar_t* restrict nptr, wchar_t** restrict endptr, int base); // C99
unsigned long wcstoul(const wchar_t* restrict nptr, wchar_t** restrict endptr, int base);
unsigned long long wcstoull(const wchar_t* restrict nptr, wchar_t** restrict endptr, int base); // C99
wchar_t* wcscpy(wchar_t* restrict s1, const wchar_t* restrict s2);
wchar_t* wcsncpy(wchar_t* restrict s1, const wchar_t* restrict s2, size_t n);
wchar_t* wcscat(wchar_t* restrict s1, const wchar_t* restrict s2);
wchar_t* wcsncat(wchar_t* restrict s1, const wchar_t* restrict s2, size_t n);
int wcscmp(const wchar_t* s1, const wchar_t* s2);
int wcscoll(const wchar_t* s1, const wchar_t* s2);
int wcsncmp(const wchar_t* s1, const wchar_t* s2, size_t n);
size_t wcsxfrm(wchar_t* restrict s1, const wchar_t* restrict s2, size_t n);
const wchar_t* wcschr(const wchar_t* s, wchar_t c);
wchar_t* wcschr( wchar_t* s, wchar_t c);
size_t wcscspn(const wchar_t* s1, const wchar_t* s2);
size_t wcslen(const wchar_t* s);
const wchar_t* wcspbrk(const wchar_t* s1, const wchar_t* s2);
wchar_t* wcspbrk( wchar_t* s1, const wchar_t* s2);
const wchar_t* wcsrchr(const wchar_t* s, wchar_t c);
wchar_t* wcsrchr( wchar_t* s, wchar_t c);
size_t wcsspn(const wchar_t* s1, const wchar_t* s2);
const wchar_t* wcsstr(const wchar_t* s1, const wchar_t* s2);
wchar_t* wcsstr( wchar_t* s1, const wchar_t* s2);
wchar_t* wcstok(wchar_t* restrict s1, const wchar_t* restrict s2, wchar_t** restrict ptr);
const wchar_t* wmemchr(const wchar_t* s, wchar_t c, size_t n);
wchar_t* wmemchr( wchar_t* s, wchar_t c, size_t n);
int wmemcmp(wchar_t* restrict s1, const wchar_t* restrict s2, size_t n);
wchar_t* wmemcpy(wchar_t* restrict s1, const wchar_t* restrict s2, size_t n);
wchar_t* wmemmove(wchar_t* s1, const wchar_t* s2, size_t n);
wchar_t* wmemset(wchar_t* s, wchar_t c, size_t n);
size_t wcsftime(wchar_t* restrict s, size_t maxsize, const wchar_t* restrict format,
const tm* restrict timeptr);
wint_t btowc(int c);
int wctob(wint_t c);
int mbsinit(const mbstate_t* ps);
size_t mbrlen(const char* restrict s, size_t n, mbstate_t* restrict ps);
size_t mbrtowc(wchar_t* restrict pwc, const char* restrict s, size_t n, mbstate_t* restrict ps);
size_t wcrtomb(char* restrict s, wchar_t wc, mbstate_t* restrict ps);
size_t mbsrtowcs(wchar_t* restrict dst, const char** restrict src, size_t len,
mbstate_t* restrict ps);
size_t wcsrtombs(char* restrict dst, const wchar_t** restrict src, size_t len,
mbstate_t* restrict ps);
} // std
*/
using ::mbstate_t;
using ::size_t;
using ::tm;
using ::wint_t;
using ::FILE;
using ::fwprintf;
using ::fwscanf;
using ::swprintf;
using ::vfwprintf;
using ::vswprintf;
using ::swscanf;
using ::vfwscanf;
using ::vswscanf;
using ::fgetwc;
using ::fgetws;
using ::fputwc;
using ::fputws;
using ::fwide;
using ::getwc;
using ::putwc;
using ::ungetwc;
using ::wcstod;
using ::wcstof;
using ::wcstold;
using ::wcstol;
#ifndef _LIBCPP_HAS_NO_LONG_LONG
using ::wcstoll;
#endif // _LIBCPP_HAS_NO_LONG_LONG
using ::wcstoul;
#ifndef _LIBCPP_HAS_NO_LONG_LONG
using ::wcstoull;
#endif // _LIBCPP_HAS_NO_LONG_LONG
using ::wcscpy;
using ::wcsncpy;
using ::wcscat;
using ::wcsncat;
using ::wcscmp;
using ::wcscoll;
using ::wcsncmp;
using ::wcsxfrm;
using ::wcschr;
using ::wcspbrk;
using ::wcsrchr;
using ::wcsstr;
using ::wmemchr;
using ::wcscspn;
using ::wcslen;
using ::wcsspn;
using ::wcstok;
using ::wmemcmp;
using ::wmemcpy;
using ::wmemmove;
using ::wmemset;
using ::wcsftime;
using ::btowc;
using ::wctob;
using ::mbsinit;
using ::mbrlen;
using ::mbrtowc;
using ::wcrtomb;
using ::mbsrtowcs;
using ::wcsrtombs;
#ifndef _LIBCPP_HAS_NO_STDIN
using ::getwchar;
using ::vwscanf;
using ::wscanf;
#endif
#ifndef _LIBCPP_HAS_NO_STDOUT
using ::putwchar;
using ::vwprintf;
using ::wprintf;
#endif
_LIBCPP_END_NAMESPACE_STD
#endif // _LIBCPP_CWCHAR
| 6,588 | 201 | jart/cosmopolitan | false |
cosmopolitan/third_party/libcxx/array | // -*- C++ -*-
//===---------------------------- array -----------------------------------===//
//
// 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_ARRAY
#define _LIBCPP_ARRAY
#include "third_party/libcxx/__config"
#include "third_party/libcxx/__tuple"
#include "third_party/libcxx/type_traits"
#include "third_party/libcxx/utility"
#include "third_party/libcxx/iterator"
#include "third_party/libcxx/algorithm"
#include "third_party/libcxx/stdexcept"
#include "third_party/libcxx/cstdlib" // for _LIBCPP_UNREACHABLE
#include "third_party/libcxx/version"
#include "third_party/libcxx/__debug"
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
#pragma GCC system_header
#endif
_LIBCPP_BEGIN_NAMESPACE_STD
/*
array synopsis
namespace std
{
template <class T, size_t N >
struct array
{
// types:
typedef T & reference;
typedef const T & const_reference;
typedef implementation defined iterator;
typedef implementation defined const_iterator;
typedef size_t size_type;
typedef ptrdiff_t difference_type;
typedef T value_type;
typedef T* pointer;
typedef const T* const_pointer;
typedef std::reverse_iterator<iterator> reverse_iterator;
typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
// No explicit construct/copy/destroy for aggregate type
void fill(const T& u);
void swap(array& a) noexcept(is_nothrow_swappable_v<T>);
// iterators:
iterator begin() noexcept;
const_iterator begin() const noexcept;
iterator end() noexcept;
const_iterator end() const noexcept;
reverse_iterator rbegin() noexcept;
const_reverse_iterator rbegin() const noexcept;
reverse_iterator rend() noexcept;
const_reverse_iterator rend() const noexcept;
const_iterator cbegin() const noexcept;
const_iterator cend() const noexcept;
const_reverse_iterator crbegin() const noexcept;
const_reverse_iterator crend() const noexcept;
// capacity:
constexpr size_type size() const noexcept;
constexpr size_type max_size() const noexcept;
constexpr bool empty() const noexcept;
// element access:
reference operator[](size_type n);
const_reference operator[](size_type n) const; // constexpr in C++14
const_reference at(size_type n) const; // constexpr in C++14
reference at(size_type n);
reference front();
const_reference front() const; // constexpr in C++14
reference back();
const_reference back() const; // constexpr in C++14
T* data() noexcept;
const T* data() const noexcept;
};
template <class T, class... U>
array(T, U...) -> array<T, 1 + sizeof...(U)>;
template <class T, size_t N>
bool operator==(const array<T,N>& x, const array<T,N>& y);
template <class T, size_t N>
bool operator!=(const array<T,N>& x, const array<T,N>& y);
template <class T, size_t N>
bool operator<(const array<T,N>& x, const array<T,N>& y);
template <class T, size_t N>
bool operator>(const array<T,N>& x, const array<T,N>& y);
template <class T, size_t N>
bool operator<=(const array<T,N>& x, const array<T,N>& y);
template <class T, size_t N>
bool operator>=(const array<T,N>& x, const array<T,N>& y);
template <class T, size_t N >
void swap(array<T,N>& x, array<T,N>& y) noexcept(noexcept(x.swap(y))); // C++17
template <class T> struct tuple_size;
template <size_t I, class T> struct tuple_element;
template <class T, size_t N> struct tuple_size<array<T, N>>;
template <size_t I, class T, size_t N> struct tuple_element<I, array<T, N>>;
template <size_t I, class T, size_t N> T& get(array<T, N>&) noexcept; // constexpr in C++14
template <size_t I, class T, size_t N> const T& get(const array<T, N>&) noexcept; // constexpr in C++14
template <size_t I, class T, size_t N> T&& get(array<T, N>&&) noexcept; // constexpr in C++14
template <size_t I, class T, size_t N> const T&& get(const array<T, N>&&) noexcept; // constexpr in C++14
} // std
*/
template <class _Tp, size_t _Size>
struct _LIBCPP_TEMPLATE_VIS array
{
// types:
typedef array __self;
typedef _Tp value_type;
typedef value_type& reference;
typedef const value_type& const_reference;
typedef value_type* iterator;
typedef const value_type* const_iterator;
typedef value_type* pointer;
typedef const value_type* const_pointer;
typedef size_t size_type;
typedef ptrdiff_t difference_type;
typedef std::reverse_iterator<iterator> reverse_iterator;
typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
_Tp __elems_[_Size];
// No explicit construct/copy/destroy for aggregate type
_LIBCPP_INLINE_VISIBILITY void fill(const value_type& __u) {
_VSTD::fill_n(__elems_, _Size, __u);
}
_LIBCPP_INLINE_VISIBILITY
void swap(array& __a) _NOEXCEPT_(__is_nothrow_swappable<_Tp>::value) {
std::swap_ranges(__elems_, __elems_ + _Size, __a.__elems_);
}
// iterators:
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
iterator begin() _NOEXCEPT {return iterator(data());}
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
const_iterator begin() const _NOEXCEPT {return const_iterator(data());}
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
iterator end() _NOEXCEPT {return iterator(data() + _Size);}
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
const_iterator end() const _NOEXCEPT {return const_iterator(data() + _Size);}
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
reverse_iterator rbegin() _NOEXCEPT {return reverse_iterator(end());}
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
const_reverse_iterator rbegin() const _NOEXCEPT {return const_reverse_iterator(end());}
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
reverse_iterator rend() _NOEXCEPT {return reverse_iterator(begin());}
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
const_reverse_iterator rend() const _NOEXCEPT {return const_reverse_iterator(begin());}
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
const_iterator cbegin() const _NOEXCEPT {return begin();}
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
const_iterator cend() const _NOEXCEPT {return end();}
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
const_reverse_iterator crbegin() const _NOEXCEPT {return rbegin();}
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
const_reverse_iterator crend() const _NOEXCEPT {return rend();}
// capacity:
_LIBCPP_INLINE_VISIBILITY
_LIBCPP_CONSTEXPR size_type size() const _NOEXCEPT {return _Size;}
_LIBCPP_INLINE_VISIBILITY
_LIBCPP_CONSTEXPR size_type max_size() const _NOEXCEPT {return _Size;}
_LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
_LIBCPP_CONSTEXPR bool empty() const _NOEXCEPT {return false; }
// element access:
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
reference operator[](size_type __n) _NOEXCEPT {return __elems_[__n];}
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
const_reference operator[](size_type __n) const _NOEXCEPT {return __elems_[__n];}
_LIBCPP_CONSTEXPR_AFTER_CXX14 reference at(size_type __n);
_LIBCPP_CONSTEXPR_AFTER_CXX11 const_reference at(size_type __n) const;
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 reference front() _NOEXCEPT {return __elems_[0];}
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 const_reference front() const _NOEXCEPT {return __elems_[0];}
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 reference back() _NOEXCEPT {return __elems_[_Size - 1];}
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 const_reference back() const _NOEXCEPT {return __elems_[_Size - 1];}
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
value_type* data() _NOEXCEPT {return __elems_;}
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
const value_type* data() const _NOEXCEPT {return __elems_;}
};
template <class _Tp, size_t _Size>
_LIBCPP_CONSTEXPR_AFTER_CXX14
typename array<_Tp, _Size>::reference
array<_Tp, _Size>::at(size_type __n)
{
if (__n >= _Size)
__throw_out_of_range("array::at");
return __elems_[__n];
}
template <class _Tp, size_t _Size>
_LIBCPP_CONSTEXPR_AFTER_CXX11
typename array<_Tp, _Size>::const_reference
array<_Tp, _Size>::at(size_type __n) const
{
if (__n >= _Size)
__throw_out_of_range("array::at");
return __elems_[__n];
}
template <class _Tp>
struct _LIBCPP_TEMPLATE_VIS array<_Tp, 0>
{
// types:
typedef array __self;
typedef _Tp value_type;
typedef value_type& reference;
typedef const value_type& const_reference;
typedef value_type* iterator;
typedef const value_type* const_iterator;
typedef value_type* pointer;
typedef const value_type* const_pointer;
typedef size_t size_type;
typedef ptrdiff_t difference_type;
typedef std::reverse_iterator<iterator> reverse_iterator;
typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
typedef typename conditional<is_const<_Tp>::value, const char,
char>::type _CharType;
struct _ArrayInStructT { _Tp __data_[1]; };
_ALIGNAS_TYPE(_ArrayInStructT) _CharType __elems_[sizeof(_ArrayInStructT)];
// No explicit construct/copy/destroy for aggregate type
_LIBCPP_INLINE_VISIBILITY void fill(const value_type&) {
static_assert(!is_const<_Tp>::value,
"cannot fill zero-sized array of type 'const T'");
}
_LIBCPP_INLINE_VISIBILITY
void swap(array&) _NOEXCEPT {
static_assert(!is_const<_Tp>::value,
"cannot swap zero-sized array of type 'const T'");
}
// iterators:
_LIBCPP_INLINE_VISIBILITY
iterator begin() _NOEXCEPT {return iterator(data());}
_LIBCPP_INLINE_VISIBILITY
const_iterator begin() const _NOEXCEPT {return const_iterator(data());}
_LIBCPP_INLINE_VISIBILITY
iterator end() _NOEXCEPT {return iterator(data());}
_LIBCPP_INLINE_VISIBILITY
const_iterator end() const _NOEXCEPT {return const_iterator(data());}
_LIBCPP_INLINE_VISIBILITY
reverse_iterator rbegin() _NOEXCEPT {return reverse_iterator(end());}
_LIBCPP_INLINE_VISIBILITY
const_reverse_iterator rbegin() const _NOEXCEPT {return const_reverse_iterator(end());}
_LIBCPP_INLINE_VISIBILITY
reverse_iterator rend() _NOEXCEPT {return reverse_iterator(begin());}
_LIBCPP_INLINE_VISIBILITY
const_reverse_iterator rend() const _NOEXCEPT {return const_reverse_iterator(begin());}
_LIBCPP_INLINE_VISIBILITY
const_iterator cbegin() const _NOEXCEPT {return begin();}
_LIBCPP_INLINE_VISIBILITY
const_iterator cend() const _NOEXCEPT {return end();}
_LIBCPP_INLINE_VISIBILITY
const_reverse_iterator crbegin() const _NOEXCEPT {return rbegin();}
_LIBCPP_INLINE_VISIBILITY
const_reverse_iterator crend() const _NOEXCEPT {return rend();}
// capacity:
_LIBCPP_INLINE_VISIBILITY
_LIBCPP_CONSTEXPR size_type size() const _NOEXCEPT {return 0; }
_LIBCPP_INLINE_VISIBILITY
_LIBCPP_CONSTEXPR size_type max_size() const _NOEXCEPT {return 0;}
_LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
_LIBCPP_CONSTEXPR bool empty() const _NOEXCEPT {return true;}
// element access:
_LIBCPP_INLINE_VISIBILITY
reference operator[](size_type) _NOEXCEPT {
_LIBCPP_ASSERT(false, "cannot call array<T, 0>::operator[] on a zero-sized array");
_LIBCPP_UNREACHABLE();
}
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
const_reference operator[](size_type) const _NOEXCEPT {
_LIBCPP_ASSERT(false, "cannot call array<T, 0>::operator[] on a zero-sized array");
_LIBCPP_UNREACHABLE();
}
_LIBCPP_INLINE_VISIBILITY
reference at(size_type) {
__throw_out_of_range("array<T, 0>::at");
_LIBCPP_UNREACHABLE();
}
_LIBCPP_INLINE_VISIBILITY
const_reference at(size_type) const {
__throw_out_of_range("array<T, 0>::at");
_LIBCPP_UNREACHABLE();
}
_LIBCPP_INLINE_VISIBILITY
reference front() _NOEXCEPT {
_LIBCPP_ASSERT(false, "cannot call array<T, 0>::front() on a zero-sized array");
_LIBCPP_UNREACHABLE();
}
_LIBCPP_INLINE_VISIBILITY
const_reference front() const _NOEXCEPT {
_LIBCPP_ASSERT(false, "cannot call array<T, 0>::front() on a zero-sized array");
_LIBCPP_UNREACHABLE();
}
_LIBCPP_INLINE_VISIBILITY
reference back() _NOEXCEPT {
_LIBCPP_ASSERT(false, "cannot call array<T, 0>::back() on a zero-sized array");
_LIBCPP_UNREACHABLE();
}
_LIBCPP_INLINE_VISIBILITY
const_reference back() const _NOEXCEPT {
_LIBCPP_ASSERT(false, "cannot call array<T, 0>::back() on a zero-sized array");
_LIBCPP_UNREACHABLE();
}
_LIBCPP_INLINE_VISIBILITY
value_type* data() _NOEXCEPT {return reinterpret_cast<value_type*>(__elems_);}
_LIBCPP_INLINE_VISIBILITY
const value_type* data() const _NOEXCEPT {return reinterpret_cast<const value_type*>(__elems_);}
};
#ifndef _LIBCPP_HAS_NO_DEDUCTION_GUIDES
template<class _Tp, class... _Args,
class = typename enable_if<(is_same_v<_Tp, _Args> && ...), void>::type
>
array(_Tp, _Args...)
-> array<_Tp, 1 + sizeof...(_Args)>;
#endif
template <class _Tp, size_t _Size>
inline _LIBCPP_INLINE_VISIBILITY
_LIBCPP_CONSTEXPR_AFTER_CXX17 bool
operator==(const array<_Tp, _Size>& __x, const array<_Tp, _Size>& __y)
{
return _VSTD::equal(__x.begin(), __x.end(), __y.begin());
}
template <class _Tp, size_t _Size>
inline _LIBCPP_INLINE_VISIBILITY
_LIBCPP_CONSTEXPR_AFTER_CXX17 bool
operator!=(const array<_Tp, _Size>& __x, const array<_Tp, _Size>& __y)
{
return !(__x == __y);
}
template <class _Tp, size_t _Size>
inline _LIBCPP_INLINE_VISIBILITY
_LIBCPP_CONSTEXPR_AFTER_CXX17 bool
operator<(const array<_Tp, _Size>& __x, const array<_Tp, _Size>& __y)
{
return _VSTD::lexicographical_compare(__x.begin(), __x.end(),
__y.begin(), __y.end());
}
template <class _Tp, size_t _Size>
inline _LIBCPP_INLINE_VISIBILITY
_LIBCPP_CONSTEXPR_AFTER_CXX17 bool
operator>(const array<_Tp, _Size>& __x, const array<_Tp, _Size>& __y)
{
return __y < __x;
}
template <class _Tp, size_t _Size>
inline _LIBCPP_INLINE_VISIBILITY
_LIBCPP_CONSTEXPR_AFTER_CXX17 bool
operator<=(const array<_Tp, _Size>& __x, const array<_Tp, _Size>& __y)
{
return !(__y < __x);
}
template <class _Tp, size_t _Size>
inline _LIBCPP_INLINE_VISIBILITY
_LIBCPP_CONSTEXPR_AFTER_CXX17 bool
operator>=(const array<_Tp, _Size>& __x, const array<_Tp, _Size>& __y)
{
return !(__x < __y);
}
template <class _Tp, size_t _Size>
inline _LIBCPP_INLINE_VISIBILITY
typename enable_if
<
_Size == 0 ||
__is_swappable<_Tp>::value,
void
>::type
swap(array<_Tp, _Size>& __x, array<_Tp, _Size>& __y)
_NOEXCEPT_(noexcept(__x.swap(__y)))
{
__x.swap(__y);
}
template <class _Tp, size_t _Size>
struct _LIBCPP_TEMPLATE_VIS tuple_size<array<_Tp, _Size> >
: public integral_constant<size_t, _Size> {};
template <size_t _Ip, class _Tp, size_t _Size>
struct _LIBCPP_TEMPLATE_VIS tuple_element<_Ip, array<_Tp, _Size> >
{
static_assert(_Ip < _Size, "Index out of bounds in std::tuple_element<> (std::array)");
typedef _Tp type;
};
template <size_t _Ip, class _Tp, size_t _Size>
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
_Tp&
get(array<_Tp, _Size>& __a) _NOEXCEPT
{
static_assert(_Ip < _Size, "Index out of bounds in std::get<> (std::array)");
return __a.__elems_[_Ip];
}
template <size_t _Ip, class _Tp, size_t _Size>
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
const _Tp&
get(const array<_Tp, _Size>& __a) _NOEXCEPT
{
static_assert(_Ip < _Size, "Index out of bounds in std::get<> (const std::array)");
return __a.__elems_[_Ip];
}
#ifndef _LIBCPP_CXX03_LANG
template <size_t _Ip, class _Tp, size_t _Size>
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
_Tp&&
get(array<_Tp, _Size>&& __a) _NOEXCEPT
{
static_assert(_Ip < _Size, "Index out of bounds in std::get<> (std::array &&)");
return _VSTD::move(__a.__elems_[_Ip]);
}
template <size_t _Ip, class _Tp, size_t _Size>
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
const _Tp&&
get(const array<_Tp, _Size>&& __a) _NOEXCEPT
{
static_assert(_Ip < _Size, "Index out of bounds in std::get<> (const std::array &&)");
return _VSTD::move(__a.__elems_[_Ip]);
}
#endif // !_LIBCPP_CXX03_LANG
_LIBCPP_END_NAMESPACE_STD
#endif // _LIBCPP_ARRAY
| 17,458 | 483 | jart/cosmopolitan | false |
cosmopolitan/third_party/libcxx/iomanip | // -*- C++ -*-
// clang-format off
//===--------------------------- iomanip ----------------------------------===//
//
// 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_IOMANIP
#define _LIBCPP_IOMANIP
/*
iomanip synopsis
namespace std {
// types T1, T2, ... are unspecified implementation types
T1 resetiosflags(ios_base::fmtflags mask);
T2 setiosflags (ios_base::fmtflags mask);
T3 setbase(int base);
template<charT> T4 setfill(charT c);
T5 setprecision(int n);
T6 setw(int n);
template <class moneyT> T7 get_money(moneyT& mon, bool intl = false);
template <class charT, class moneyT> T8 put_money(const moneyT& mon, bool intl = false);
template <class charT> T9 get_time(struct tm* tmb, const charT* fmt);
template <class charT> T10 put_time(const struct tm* tmb, const charT* fmt);
template <class charT>
T11 quoted(const charT* s, charT delim=charT('"'), charT escape=charT('\\')); // C++14
template <class charT, class traits, class Allocator>
T12 quoted(const basic_string<charT, traits, Allocator>& s,
charT delim=charT('"'), charT escape=charT('\\')); // C++14
template <class charT, class traits, class Allocator>
T13 quoted(basic_string<charT, traits, Allocator>& s,
charT delim=charT('"'), charT escape=charT('\\')); // C++14
} // std
*/
#include "third_party/libcxx/__config"
#include "third_party/libcxx/__string"
#include "third_party/libcxx/istream"
#include "third_party/libcxx/version"
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
#pragma GCC system_header
#endif
_LIBCPP_BEGIN_NAMESPACE_STD
// resetiosflags
class __iom_t1
{
ios_base::fmtflags __mask_;
public:
_LIBCPP_INLINE_VISIBILITY
explicit __iom_t1(ios_base::fmtflags __m) : __mask_(__m) {}
template <class _CharT, class _Traits>
friend
_LIBCPP_INLINE_VISIBILITY
basic_istream<_CharT, _Traits>&
operator>>(basic_istream<_CharT, _Traits>& __is, const __iom_t1& __x)
{
__is.unsetf(__x.__mask_);
return __is;
}
template <class _CharT, class _Traits>
friend
_LIBCPP_INLINE_VISIBILITY
basic_ostream<_CharT, _Traits>&
operator<<(basic_ostream<_CharT, _Traits>& __os, const __iom_t1& __x)
{
__os.unsetf(__x.__mask_);
return __os;
}
};
inline _LIBCPP_INLINE_VISIBILITY
__iom_t1
resetiosflags(ios_base::fmtflags __mask)
{
return __iom_t1(__mask);
}
// setiosflags
class __iom_t2
{
ios_base::fmtflags __mask_;
public:
_LIBCPP_INLINE_VISIBILITY
explicit __iom_t2(ios_base::fmtflags __m) : __mask_(__m) {}
template <class _CharT, class _Traits>
friend
_LIBCPP_INLINE_VISIBILITY
basic_istream<_CharT, _Traits>&
operator>>(basic_istream<_CharT, _Traits>& __is, const __iom_t2& __x)
{
__is.setf(__x.__mask_);
return __is;
}
template <class _CharT, class _Traits>
friend
_LIBCPP_INLINE_VISIBILITY
basic_ostream<_CharT, _Traits>&
operator<<(basic_ostream<_CharT, _Traits>& __os, const __iom_t2& __x)
{
__os.setf(__x.__mask_);
return __os;
}
};
inline _LIBCPP_INLINE_VISIBILITY
__iom_t2
setiosflags(ios_base::fmtflags __mask)
{
return __iom_t2(__mask);
}
// setbase
class __iom_t3
{
int __base_;
public:
_LIBCPP_INLINE_VISIBILITY
explicit __iom_t3(int __b) : __base_(__b) {}
template <class _CharT, class _Traits>
friend
_LIBCPP_INLINE_VISIBILITY
basic_istream<_CharT, _Traits>&
operator>>(basic_istream<_CharT, _Traits>& __is, const __iom_t3& __x)
{
__is.setf(__x.__base_ == 8 ? ios_base::oct :
__x.__base_ == 10 ? ios_base::dec :
__x.__base_ == 16 ? ios_base::hex :
ios_base::fmtflags(0), ios_base::basefield);
return __is;
}
template <class _CharT, class _Traits>
friend
_LIBCPP_INLINE_VISIBILITY
basic_ostream<_CharT, _Traits>&
operator<<(basic_ostream<_CharT, _Traits>& __os, const __iom_t3& __x)
{
__os.setf(__x.__base_ == 8 ? ios_base::oct :
__x.__base_ == 10 ? ios_base::dec :
__x.__base_ == 16 ? ios_base::hex :
ios_base::fmtflags(0), ios_base::basefield);
return __os;
}
};
inline _LIBCPP_INLINE_VISIBILITY
__iom_t3
setbase(int __base)
{
return __iom_t3(__base);
}
// setfill
template<class _CharT>
class __iom_t4
{
_CharT __fill_;
public:
_LIBCPP_INLINE_VISIBILITY
explicit __iom_t4(_CharT __c) : __fill_(__c) {}
template <class _Traits>
friend
_LIBCPP_INLINE_VISIBILITY
basic_ostream<_CharT, _Traits>&
operator<<(basic_ostream<_CharT, _Traits>& __os, const __iom_t4& __x)
{
__os.fill(__x.__fill_);
return __os;
}
};
template<class _CharT>
inline _LIBCPP_INLINE_VISIBILITY
__iom_t4<_CharT>
setfill(_CharT __c)
{
return __iom_t4<_CharT>(__c);
}
// setprecision
class __iom_t5
{
int __n_;
public:
_LIBCPP_INLINE_VISIBILITY
explicit __iom_t5(int __n) : __n_(__n) {}
template <class _CharT, class _Traits>
friend
_LIBCPP_INLINE_VISIBILITY
basic_istream<_CharT, _Traits>&
operator>>(basic_istream<_CharT, _Traits>& __is, const __iom_t5& __x)
{
__is.precision(__x.__n_);
return __is;
}
template <class _CharT, class _Traits>
friend
_LIBCPP_INLINE_VISIBILITY
basic_ostream<_CharT, _Traits>&
operator<<(basic_ostream<_CharT, _Traits>& __os, const __iom_t5& __x)
{
__os.precision(__x.__n_);
return __os;
}
};
inline _LIBCPP_INLINE_VISIBILITY
__iom_t5
setprecision(int __n)
{
return __iom_t5(__n);
}
// setw
class __iom_t6
{
int __n_;
public:
_LIBCPP_INLINE_VISIBILITY
explicit __iom_t6(int __n) : __n_(__n) {}
template <class _CharT, class _Traits>
friend
_LIBCPP_INLINE_VISIBILITY
basic_istream<_CharT, _Traits>&
operator>>(basic_istream<_CharT, _Traits>& __is, const __iom_t6& __x)
{
__is.width(__x.__n_);
return __is;
}
template <class _CharT, class _Traits>
friend
_LIBCPP_INLINE_VISIBILITY
basic_ostream<_CharT, _Traits>&
operator<<(basic_ostream<_CharT, _Traits>& __os, const __iom_t6& __x)
{
__os.width(__x.__n_);
return __os;
}
};
inline _LIBCPP_INLINE_VISIBILITY
__iom_t6
setw(int __n)
{
return __iom_t6(__n);
}
// get_money
template <class _MoneyT> class __iom_t7;
template <class _CharT, class _Traits, class _MoneyT>
basic_istream<_CharT, _Traits>&
operator>>(basic_istream<_CharT, _Traits>& __is, const __iom_t7<_MoneyT>& __x);
template <class _MoneyT>
class __iom_t7
{
_MoneyT& __mon_;
bool __intl_;
public:
_LIBCPP_INLINE_VISIBILITY
__iom_t7(_MoneyT& __mon, bool __intl)
: __mon_(__mon), __intl_(__intl) {}
template <class _CharT, class _Traits, class _Mp>
friend
basic_istream<_CharT, _Traits>&
operator>>(basic_istream<_CharT, _Traits>& __is, const __iom_t7<_Mp>& __x);
};
template <class _CharT, class _Traits, class _MoneyT>
basic_istream<_CharT, _Traits>&
operator>>(basic_istream<_CharT, _Traits>& __is, const __iom_t7<_MoneyT>& __x)
{
#ifndef _LIBCPP_NO_EXCEPTIONS
try
{
#endif // _LIBCPP_NO_EXCEPTIONS
typename basic_istream<_CharT, _Traits>::sentry __s(__is);
if (__s)
{
typedef istreambuf_iterator<_CharT, _Traits> _Ip;
typedef money_get<_CharT, _Ip> _Fp;
ios_base::iostate __err = ios_base::goodbit;
const _Fp& __mf = use_facet<_Fp>(__is.getloc());
__mf.get(_Ip(__is), _Ip(), __x.__intl_, __is, __err, __x.__mon_);
__is.setstate(__err);
}
#ifndef _LIBCPP_NO_EXCEPTIONS
}
catch (...)
{
__is.__set_badbit_and_consider_rethrow();
}
#endif // _LIBCPP_NO_EXCEPTIONS
return __is;
}
template <class _MoneyT>
inline _LIBCPP_INLINE_VISIBILITY
__iom_t7<_MoneyT>
get_money(_MoneyT& __mon, bool __intl = false)
{
return __iom_t7<_MoneyT>(__mon, __intl);
}
// put_money
template <class _MoneyT> class __iom_t8;
template <class _CharT, class _Traits, class _MoneyT>
basic_ostream<_CharT, _Traits>&
operator<<(basic_ostream<_CharT, _Traits>& __os, const __iom_t8<_MoneyT>& __x);
template <class _MoneyT>
class __iom_t8
{
const _MoneyT& __mon_;
bool __intl_;
public:
_LIBCPP_INLINE_VISIBILITY
__iom_t8(const _MoneyT& __mon, bool __intl)
: __mon_(__mon), __intl_(__intl) {}
template <class _CharT, class _Traits, class _Mp>
friend
basic_ostream<_CharT, _Traits>&
operator<<(basic_ostream<_CharT, _Traits>& __os, const __iom_t8<_Mp>& __x);
};
template <class _CharT, class _Traits, class _MoneyT>
basic_ostream<_CharT, _Traits>&
operator<<(basic_ostream<_CharT, _Traits>& __os, const __iom_t8<_MoneyT>& __x)
{
#ifndef _LIBCPP_NO_EXCEPTIONS
try
{
#endif // _LIBCPP_NO_EXCEPTIONS
typename basic_ostream<_CharT, _Traits>::sentry __s(__os);
if (__s)
{
typedef ostreambuf_iterator<_CharT, _Traits> _Op;
typedef money_put<_CharT, _Op> _Fp;
const _Fp& __mf = use_facet<_Fp>(__os.getloc());
if (__mf.put(_Op(__os), __x.__intl_, __os, __os.fill(), __x.__mon_).failed())
__os.setstate(ios_base::badbit);
}
#ifndef _LIBCPP_NO_EXCEPTIONS
}
catch (...)
{
__os.__set_badbit_and_consider_rethrow();
}
#endif // _LIBCPP_NO_EXCEPTIONS
return __os;
}
template <class _MoneyT>
inline _LIBCPP_INLINE_VISIBILITY
__iom_t8<_MoneyT>
put_money(const _MoneyT& __mon, bool __intl = false)
{
return __iom_t8<_MoneyT>(__mon, __intl);
}
// get_time
template <class _CharT> class __iom_t9;
template <class _CharT, class _Traits>
basic_istream<_CharT, _Traits>&
operator>>(basic_istream<_CharT, _Traits>& __is, const __iom_t9<_CharT>& __x);
template <class _CharT>
class __iom_t9
{
tm* __tm_;
const _CharT* __fmt_;
public:
_LIBCPP_INLINE_VISIBILITY
__iom_t9(tm* __tm, const _CharT* __fmt)
: __tm_(__tm), __fmt_(__fmt) {}
template <class _Cp, class _Traits>
friend
basic_istream<_Cp, _Traits>&
operator>>(basic_istream<_Cp, _Traits>& __is, const __iom_t9<_Cp>& __x);
};
template <class _CharT, class _Traits>
basic_istream<_CharT, _Traits>&
operator>>(basic_istream<_CharT, _Traits>& __is, const __iom_t9<_CharT>& __x)
{
#ifndef _LIBCPP_NO_EXCEPTIONS
try
{
#endif // _LIBCPP_NO_EXCEPTIONS
typename basic_istream<_CharT, _Traits>::sentry __s(__is);
if (__s)
{
typedef istreambuf_iterator<_CharT, _Traits> _Ip;
typedef time_get<_CharT, _Ip> _Fp;
ios_base::iostate __err = ios_base::goodbit;
const _Fp& __tf = use_facet<_Fp>(__is.getloc());
__tf.get(_Ip(__is), _Ip(), __is, __err, __x.__tm_,
__x.__fmt_, __x.__fmt_ + _Traits::length(__x.__fmt_));
__is.setstate(__err);
}
#ifndef _LIBCPP_NO_EXCEPTIONS
}
catch (...)
{
__is.__set_badbit_and_consider_rethrow();
}
#endif // _LIBCPP_NO_EXCEPTIONS
return __is;
}
template <class _CharT>
inline _LIBCPP_INLINE_VISIBILITY
__iom_t9<_CharT>
get_time(tm* __tm, const _CharT* __fmt)
{
return __iom_t9<_CharT>(__tm, __fmt);
}
// put_time
template <class _CharT> class __iom_t10;
template <class _CharT, class _Traits>
basic_ostream<_CharT, _Traits>&
operator<<(basic_ostream<_CharT, _Traits>& __os, const __iom_t10<_CharT>& __x);
template <class _CharT>
class __iom_t10
{
const tm* __tm_;
const _CharT* __fmt_;
public:
_LIBCPP_INLINE_VISIBILITY
__iom_t10(const tm* __tm, const _CharT* __fmt)
: __tm_(__tm), __fmt_(__fmt) {}
template <class _Cp, class _Traits>
friend
basic_ostream<_Cp, _Traits>&
operator<<(basic_ostream<_Cp, _Traits>& __os, const __iom_t10<_Cp>& __x);
};
template <class _CharT, class _Traits>
basic_ostream<_CharT, _Traits>&
operator<<(basic_ostream<_CharT, _Traits>& __os, const __iom_t10<_CharT>& __x)
{
#ifndef _LIBCPP_NO_EXCEPTIONS
try
{
#endif // _LIBCPP_NO_EXCEPTIONS
typename basic_ostream<_CharT, _Traits>::sentry __s(__os);
if (__s)
{
typedef ostreambuf_iterator<_CharT, _Traits> _Op;
typedef time_put<_CharT, _Op> _Fp;
const _Fp& __tf = use_facet<_Fp>(__os.getloc());
if (__tf.put(_Op(__os), __os, __os.fill(), __x.__tm_,
__x.__fmt_, __x.__fmt_ + _Traits::length(__x.__fmt_)).failed())
__os.setstate(ios_base::badbit);
}
#ifndef _LIBCPP_NO_EXCEPTIONS
}
catch (...)
{
__os.__set_badbit_and_consider_rethrow();
}
#endif // _LIBCPP_NO_EXCEPTIONS
return __os;
}
template <class _CharT>
inline _LIBCPP_INLINE_VISIBILITY
__iom_t10<_CharT>
put_time(const tm* __tm, const _CharT* __fmt)
{
return __iom_t10<_CharT>(__tm, __fmt);
}
template <class _CharT, class _Traits, class _ForwardIterator>
std::basic_ostream<_CharT, _Traits> &
__quoted_output ( basic_ostream<_CharT, _Traits> &__os,
_ForwardIterator __first, _ForwardIterator __last, _CharT __delim, _CharT __escape )
{
_VSTD::basic_string<_CharT, _Traits> __str;
__str.push_back(__delim);
for ( ; __first != __last; ++ __first )
{
if (_Traits::eq (*__first, __escape) || _Traits::eq (*__first, __delim))
__str.push_back(__escape);
__str.push_back(*__first);
}
__str.push_back(__delim);
return __put_character_sequence(__os, __str.data(), __str.size());
}
template <class _CharT, class _Traits, class _String>
basic_istream<_CharT, _Traits> &
__quoted_input ( basic_istream<_CharT, _Traits> &__is, _String & __string, _CharT __delim, _CharT __escape )
{
__string.clear ();
_CharT __c;
__is >> __c;
if ( __is.fail ())
return __is;
if (!_Traits::eq (__c, __delim)) // no delimiter, read the whole string
{
__is.unget ();
__is >> __string;
return __is;
}
__save_flags<_CharT, _Traits> sf(__is);
noskipws (__is);
while (true)
{
__is >> __c;
if ( __is.fail ())
break;
if (_Traits::eq (__c, __escape))
{
__is >> __c;
if ( __is.fail ())
break;
}
else if (_Traits::eq (__c, __delim))
break;
__string.push_back ( __c );
}
return __is;
}
template <class _CharT, class _Traits, class _Iter>
basic_ostream<_CharT, _Traits>& operator<<(
basic_ostream<_CharT, _Traits>& __os,
const __quoted_output_proxy<_CharT, _Iter, _Traits> & __proxy)
{
return __quoted_output (__os, __proxy.__first, __proxy.__last, __proxy.__delim, __proxy.__escape);
}
template <class _CharT, class _Traits, class _Allocator>
struct __quoted_proxy
{
basic_string<_CharT, _Traits, _Allocator> &__string;
_CharT __delim;
_CharT __escape;
__quoted_proxy(basic_string<_CharT, _Traits, _Allocator> &__s, _CharT __d, _CharT __e)
: __string(__s), __delim(__d), __escape(__e) {}
};
template <class _CharT, class _Traits, class _Allocator>
_LIBCPP_INLINE_VISIBILITY
basic_ostream<_CharT, _Traits>& operator<<(
basic_ostream<_CharT, _Traits>& __os,
const __quoted_proxy<_CharT, _Traits, _Allocator> & __proxy)
{
return __quoted_output (__os, __proxy.__string.cbegin (), __proxy.__string.cend (), __proxy.__delim, __proxy.__escape);
}
// extractor for non-const basic_string& proxies
template <class _CharT, class _Traits, class _Allocator>
_LIBCPP_INLINE_VISIBILITY
basic_istream<_CharT, _Traits>& operator>>(
basic_istream<_CharT, _Traits>& __is,
const __quoted_proxy<_CharT, _Traits, _Allocator> & __proxy)
{
return __quoted_input ( __is, __proxy.__string, __proxy.__delim, __proxy.__escape );
}
template <class _CharT>
_LIBCPP_INLINE_VISIBILITY
__quoted_output_proxy<_CharT, const _CharT *>
quoted ( const _CharT *__s, _CharT __delim = _CharT('"'), _CharT __escape =_CharT('\\'))
{
const _CharT *__end = __s;
while ( *__end ) ++__end;
return __quoted_output_proxy<_CharT, const _CharT *> ( __s, __end, __delim, __escape );
}
template <class _CharT, class _Traits, class _Allocator>
_LIBCPP_INLINE_VISIBILITY
__quoted_output_proxy<_CharT, typename basic_string <_CharT, _Traits, _Allocator>::const_iterator>
__quoted ( const basic_string <_CharT, _Traits, _Allocator> &__s, _CharT __delim = _CharT('"'), _CharT __escape=_CharT('\\'))
{
return __quoted_output_proxy<_CharT,
typename basic_string <_CharT, _Traits, _Allocator>::const_iterator>
( __s.cbegin(), __s.cend (), __delim, __escape );
}
template <class _CharT, class _Traits, class _Allocator>
_LIBCPP_INLINE_VISIBILITY
__quoted_proxy<_CharT, _Traits, _Allocator>
__quoted ( basic_string <_CharT, _Traits, _Allocator> &__s, _CharT __delim = _CharT('"'), _CharT __escape=_CharT('\\'))
{
return __quoted_proxy<_CharT, _Traits, _Allocator>( __s, __delim, __escape );
}
#if _LIBCPP_STD_VER > 11
template <class _CharT, class _Traits, class _Allocator>
_LIBCPP_INLINE_VISIBILITY
__quoted_output_proxy<_CharT, typename basic_string <_CharT, _Traits, _Allocator>::const_iterator>
quoted ( const basic_string <_CharT, _Traits, _Allocator> &__s, _CharT __delim = _CharT('"'), _CharT __escape=_CharT('\\'))
{
return __quoted(__s, __delim, __escape);
}
template <class _CharT, class _Traits, class _Allocator>
_LIBCPP_INLINE_VISIBILITY
__quoted_proxy<_CharT, _Traits, _Allocator>
quoted ( basic_string <_CharT, _Traits, _Allocator> &__s, _CharT __delim = _CharT('"'), _CharT __escape=_CharT('\\'))
{
return __quoted(__s, __delim, __escape);
}
template <class _CharT, class _Traits>
__quoted_output_proxy<_CharT, const _CharT *, _Traits>
quoted (basic_string_view <_CharT, _Traits> __sv,
_CharT __delim = _CharT('"'), _CharT __escape=_CharT('\\'))
{
return __quoted_output_proxy<_CharT, const _CharT *, _Traits>
( __sv.data(), __sv.data() + __sv.size(), __delim, __escape );
}
#endif
_LIBCPP_END_NAMESPACE_STD
#endif // _LIBCPP_IOMANIP
| 18,374 | 672 | jart/cosmopolitan | false |
cosmopolitan/third_party/libcxx/string.cc | // clang-format off
//===------------------------- string.cpp ---------------------------------===//
//
// 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
//
//===----------------------------------------------------------------------===//
#include "third_party/libcxx/string"
#include "third_party/libcxx/charconv"
#include "third_party/libcxx/cstdlib"
#include "third_party/libcxx/cwchar"
#include "third_party/libcxx/cerrno"
#include "third_party/libcxx/limits"
#include "third_party/libcxx/stdexcept"
#include "third_party/libcxx/stdio.h"
#include "third_party/libcxx/__debug"
_LIBCPP_BEGIN_NAMESPACE_STD
template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS __basic_string_common<true>;
template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS basic_string<char>;
template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS basic_string<wchar_t>;
template
string
operator+<char, char_traits<char>, allocator<char> >(char const*, string const&);
namespace
{
template<typename T>
inline
void throw_helper( const string& msg )
{
#ifndef _LIBCPP_NO_EXCEPTIONS
throw T( msg );
#else
fprintf(stderr, "%s\n", msg.c_str());
_VSTD::abort();
#endif
}
inline
void throw_from_string_out_of_range( const string& func )
{
throw_helper<out_of_range>(func + ": out of range");
}
inline
void throw_from_string_invalid_arg( const string& func )
{
throw_helper<invalid_argument>(func + ": no conversion");
}
// as_integer
template<typename V, typename S, typename F>
inline
V
as_integer_helper(const string& func, const S& str, size_t* idx, int base, F f)
{
typename S::value_type* ptr = nullptr;
const typename S::value_type* const p = str.c_str();
typename remove_reference<decltype(errno)>::type errno_save = errno;
errno = 0;
V r = f(p, &ptr, base);
swap(errno, errno_save);
if (errno_save == ERANGE)
throw_from_string_out_of_range(func);
if (ptr == p)
throw_from_string_invalid_arg(func);
if (idx)
*idx = static_cast<size_t>(ptr - p);
return r;
}
template<typename V, typename S>
inline
V
as_integer(const string& func, const S& s, size_t* idx, int base);
// string
template<>
inline
int
as_integer(const string& func, const string& s, size_t* idx, int base )
{
// Use long as no Standard string to integer exists.
long r = as_integer_helper<long>( func, s, idx, base, strtol );
if (r < numeric_limits<int>::min() || numeric_limits<int>::max() < r)
throw_from_string_out_of_range(func);
return static_cast<int>(r);
}
template<>
inline
long
as_integer(const string& func, const string& s, size_t* idx, int base )
{
return as_integer_helper<long>( func, s, idx, base, strtol );
}
template<>
inline
unsigned long
as_integer( const string& func, const string& s, size_t* idx, int base )
{
return as_integer_helper<unsigned long>( func, s, idx, base, strtoul );
}
template<>
inline
long long
as_integer( const string& func, const string& s, size_t* idx, int base )
{
return as_integer_helper<long long>( func, s, idx, base, strtoll );
}
template<>
inline
unsigned long long
as_integer( const string& func, const string& s, size_t* idx, int base )
{
return as_integer_helper<unsigned long long>( func, s, idx, base, strtoull );
}
// wstring
template<>
inline
int
as_integer( const string& func, const wstring& s, size_t* idx, int base )
{
// Use long as no Stantard string to integer exists.
long r = as_integer_helper<long>( func, s, idx, base, wcstol );
if (r < numeric_limits<int>::min() || numeric_limits<int>::max() < r)
throw_from_string_out_of_range(func);
return static_cast<int>(r);
}
template<>
inline
long
as_integer( const string& func, const wstring& s, size_t* idx, int base )
{
return as_integer_helper<long>( func, s, idx, base, wcstol );
}
template<>
inline
unsigned long
as_integer( const string& func, const wstring& s, size_t* idx, int base )
{
return as_integer_helper<unsigned long>( func, s, idx, base, wcstoul );
}
template<>
inline
long long
as_integer( const string& func, const wstring& s, size_t* idx, int base )
{
return as_integer_helper<long long>( func, s, idx, base, wcstoll );
}
template<>
inline
unsigned long long
as_integer( const string& func, const wstring& s, size_t* idx, int base )
{
return as_integer_helper<unsigned long long>( func, s, idx, base, wcstoull );
}
// as_float
template<typename V, typename S, typename F>
inline
V
as_float_helper(const string& func, const S& str, size_t* idx, F f )
{
typename S::value_type* ptr = nullptr;
const typename S::value_type* const p = str.c_str();
typename remove_reference<decltype(errno)>::type errno_save = errno;
errno = 0;
V r = f(p, &ptr);
swap(errno, errno_save);
if (errno_save == ERANGE)
throw_from_string_out_of_range(func);
if (ptr == p)
throw_from_string_invalid_arg(func);
if (idx)
*idx = static_cast<size_t>(ptr - p);
return r;
}
template<typename V, typename S>
inline
V as_float( const string& func, const S& s, size_t* idx = nullptr );
template<>
inline
float
as_float( const string& func, const string& s, size_t* idx )
{
return as_float_helper<float>( func, s, idx, strtof );
}
template<>
inline
double
as_float(const string& func, const string& s, size_t* idx )
{
return as_float_helper<double>( func, s, idx, strtod );
}
template<>
inline
long double
as_float( const string& func, const string& s, size_t* idx )
{
return as_float_helper<long double>( func, s, idx, strtold );
}
template<>
inline
float
as_float( const string& func, const wstring& s, size_t* idx )
{
return as_float_helper<float>( func, s, idx, wcstof );
}
template<>
inline
double
as_float( const string& func, const wstring& s, size_t* idx )
{
return as_float_helper<double>( func, s, idx, wcstod );
}
template<>
inline
long double
as_float( const string& func, const wstring& s, size_t* idx )
{
return as_float_helper<long double>( func, s, idx, wcstold );
}
} // unnamed namespace
int
stoi(const string& str, size_t* idx, int base)
{
return as_integer<int>( "stoi", str, idx, base );
}
int
stoi(const wstring& str, size_t* idx, int base)
{
return as_integer<int>( "stoi", str, idx, base );
}
long
stol(const string& str, size_t* idx, int base)
{
return as_integer<long>( "stol", str, idx, base );
}
long
stol(const wstring& str, size_t* idx, int base)
{
return as_integer<long>( "stol", str, idx, base );
}
unsigned long
stoul(const string& str, size_t* idx, int base)
{
return as_integer<unsigned long>( "stoul", str, idx, base );
}
unsigned long
stoul(const wstring& str, size_t* idx, int base)
{
return as_integer<unsigned long>( "stoul", str, idx, base );
}
long long
stoll(const string& str, size_t* idx, int base)
{
return as_integer<long long>( "stoll", str, idx, base );
}
long long
stoll(const wstring& str, size_t* idx, int base)
{
return as_integer<long long>( "stoll", str, idx, base );
}
unsigned long long
stoull(const string& str, size_t* idx, int base)
{
return as_integer<unsigned long long>( "stoull", str, idx, base );
}
unsigned long long
stoull(const wstring& str, size_t* idx, int base)
{
return as_integer<unsigned long long>( "stoull", str, idx, base );
}
float
stof(const string& str, size_t* idx)
{
return as_float<float>( "stof", str, idx );
}
float
stof(const wstring& str, size_t* idx)
{
return as_float<float>( "stof", str, idx );
}
double
stod(const string& str, size_t* idx)
{
return as_float<double>( "stod", str, idx );
}
double
stod(const wstring& str, size_t* idx)
{
return as_float<double>( "stod", str, idx );
}
long double
stold(const string& str, size_t* idx)
{
return as_float<long double>( "stold", str, idx );
}
long double
stold(const wstring& str, size_t* idx)
{
return as_float<long double>( "stold", str, idx );
}
// to_string
namespace
{
// as_string
template<typename S, typename P, typename V >
inline
S
as_string(P sprintf_like, S s, const typename S::value_type* fmt, V a)
{
typedef typename S::size_type size_type;
size_type available = s.size();
while (true)
{
int status = sprintf_like(&s[0], available + 1, fmt, a);
if ( status >= 0 )
{
size_type used = static_cast<size_type>(status);
if ( used <= available )
{
s.resize( used );
break;
}
available = used; // Assume this is advice of how much space we need.
}
else
available = available * 2 + 1;
s.resize(available);
}
return s;
}
template <class S>
struct initial_string;
template <>
struct initial_string<string>
{
string
operator()() const
{
string s;
s.resize(s.capacity());
return s;
}
};
template <>
struct initial_string<wstring>
{
wstring
operator()() const
{
wstring s(20, wchar_t());
s.resize(s.capacity());
return s;
}
};
typedef int (*wide_printf)(wchar_t* __restrict, size_t, const wchar_t*__restrict, ...);
inline
wide_printf
get_swprintf()
{
#ifndef _LIBCPP_MSVCRT
return swprintf;
#else
return static_cast<int (__cdecl*)(wchar_t* __restrict, size_t, const wchar_t*__restrict, ...)>(_snwprintf);
#endif
}
template <typename S, typename V>
S i_to_string(const V v)
{
// numeric_limits::digits10 returns value less on 1 than desired for unsigned numbers.
// For example, for 1-byte unsigned value digits10 is 2 (999 can not be represented),
// so we need +1 here.
constexpr size_t bufsize = numeric_limits<V>::digits10 + 2; // +1 for minus, +1 for digits10
char buf[bufsize];
const auto res = to_chars(buf, buf + bufsize, v);
_LIBCPP_ASSERT(res.ec == errc(), "bufsize must be large enough to accomodate the value");
return S(buf, res.ptr);
}
} // unnamed namespace
string to_string (int val) { return i_to_string< string>(val); }
string to_string (long val) { return i_to_string< string>(val); }
string to_string (long long val) { return i_to_string< string>(val); }
string to_string (unsigned val) { return i_to_string< string>(val); }
string to_string (unsigned long val) { return i_to_string< string>(val); }
string to_string (unsigned long long val) { return i_to_string< string>(val); }
wstring to_wstring(int val) { return i_to_string<wstring>(val); }
wstring to_wstring(long val) { return i_to_string<wstring>(val); }
wstring to_wstring(long long val) { return i_to_string<wstring>(val); }
wstring to_wstring(unsigned val) { return i_to_string<wstring>(val); }
wstring to_wstring(unsigned long val) { return i_to_string<wstring>(val); }
wstring to_wstring(unsigned long long val) { return i_to_string<wstring>(val); }
string to_string (float val) { return as_string(snprintf, initial_string< string>()(), "%f", val); }
string to_string (double val) { return as_string(snprintf, initial_string< string>()(), "%f", val); }
string to_string (long double val) { return as_string(snprintf, initial_string< string>()(), "%Lf", val); }
wstring to_wstring(float val) { return as_string(get_swprintf(), initial_string<wstring>()(), L"%f", val); }
wstring to_wstring(double val) { return as_string(get_swprintf(), initial_string<wstring>()(), L"%f", val); }
wstring to_wstring(long double val) { return as_string(get_swprintf(), initial_string<wstring>()(), L"%Lf", val); }
_LIBCPP_END_NAMESPACE_STD
| 11,768 | 460 | jart/cosmopolitan | false |
cosmopolitan/third_party/libcxx/__mutex_base | // -*- 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___MUTEX_BASE
#define _LIBCPP___MUTEX_BASE
#include "third_party/libcxx/__config"
#include "third_party/libcxx/chrono"
#include "third_party/libcxx/system_error"
#include "third_party/libcxx/__threading_support"
#include "libc/sysv/consts/sched.h"
#include "libc/time/struct/tm.h"
#include "libc/time/time.h"
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
#pragma GCC system_header
#endif
_LIBCPP_PUSH_MACROS
#include "third_party/libcxx/__undef_macros"
_LIBCPP_BEGIN_NAMESPACE_STD
#ifndef _LIBCPP_HAS_NO_THREADS
#ifndef _LIBCPP_THREAD_SAFETY_ANNOTATION
# ifdef _LIBCPP_HAS_THREAD_SAFETY_ANNOTATIONS
# define _LIBCPP_THREAD_SAFETY_ANNOTATION(x) __attribute__((x))
# else
# define _LIBCPP_THREAD_SAFETY_ANNOTATION(x)
# endif
#endif // _LIBCPP_THREAD_SAFETY_ANNOTATION
class _LIBCPP_TYPE_VIS _LIBCPP_THREAD_SAFETY_ANNOTATION(capability("mutex")) mutex
{
__libcpp_mutex_t __m_ = _LIBCPP_MUTEX_INITIALIZER;
public:
_LIBCPP_INLINE_VISIBILITY
_LIBCPP_CONSTEXPR mutex() = default;
mutex(const mutex&) = delete;
mutex& operator=(const mutex&) = delete;
#if defined(_LIBCPP_HAS_TRIVIAL_MUTEX_DESTRUCTION)
~mutex() = default;
#else
~mutex() _NOEXCEPT;
#endif
void lock() _LIBCPP_THREAD_SAFETY_ANNOTATION(acquire_capability());
bool try_lock() _NOEXCEPT _LIBCPP_THREAD_SAFETY_ANNOTATION(try_acquire_capability(true));
void unlock() _NOEXCEPT _LIBCPP_THREAD_SAFETY_ANNOTATION(release_capability());
typedef __libcpp_mutex_t* native_handle_type;
_LIBCPP_INLINE_VISIBILITY native_handle_type native_handle() {return &__m_;}
};
static_assert(is_nothrow_default_constructible<mutex>::value,
"the default constructor for std::mutex must be nothrow");
struct _LIBCPP_TYPE_VIS defer_lock_t { explicit defer_lock_t() = default; };
struct _LIBCPP_TYPE_VIS try_to_lock_t { explicit try_to_lock_t() = default; };
struct _LIBCPP_TYPE_VIS adopt_lock_t { explicit adopt_lock_t() = default; };
#if defined(_LIBCPP_CXX03_LANG) || defined(_LIBCPP_BUILDING_LIBRARY)
extern _LIBCPP_EXPORTED_FROM_ABI const defer_lock_t defer_lock;
extern _LIBCPP_EXPORTED_FROM_ABI const try_to_lock_t try_to_lock;
extern _LIBCPP_EXPORTED_FROM_ABI const adopt_lock_t adopt_lock;
#else
/* _LIBCPP_INLINE_VAR */ constexpr defer_lock_t defer_lock = defer_lock_t();
/* _LIBCPP_INLINE_VAR */ constexpr try_to_lock_t try_to_lock = try_to_lock_t();
/* _LIBCPP_INLINE_VAR */ constexpr adopt_lock_t adopt_lock = adopt_lock_t();
#endif
template <class _Mutex>
class _LIBCPP_TEMPLATE_VIS _LIBCPP_THREAD_SAFETY_ANNOTATION(scoped_lockable)
lock_guard
{
public:
typedef _Mutex mutex_type;
private:
mutex_type& __m_;
public:
_LIBCPP_NODISCARD_EXT _LIBCPP_INLINE_VISIBILITY
explicit lock_guard(mutex_type& __m) _LIBCPP_THREAD_SAFETY_ANNOTATION(acquire_capability(__m))
: __m_(__m) {__m_.lock();}
_LIBCPP_NODISCARD_EXT _LIBCPP_INLINE_VISIBILITY
lock_guard(mutex_type& __m, adopt_lock_t) _LIBCPP_THREAD_SAFETY_ANNOTATION(requires_capability(__m))
: __m_(__m) {}
_LIBCPP_INLINE_VISIBILITY
~lock_guard() _LIBCPP_THREAD_SAFETY_ANNOTATION(release_capability()) {__m_.unlock();}
private:
lock_guard(lock_guard const&) _LIBCPP_EQUAL_DELETE;
lock_guard& operator=(lock_guard const&) _LIBCPP_EQUAL_DELETE;
};
template <class _Mutex>
class _LIBCPP_TEMPLATE_VIS unique_lock
{
public:
typedef _Mutex mutex_type;
private:
mutex_type* __m_;
bool __owns_;
public:
_LIBCPP_INLINE_VISIBILITY
unique_lock() _NOEXCEPT : __m_(nullptr), __owns_(false) {}
_LIBCPP_INLINE_VISIBILITY
explicit unique_lock(mutex_type& __m)
: __m_(_VSTD::addressof(__m)), __owns_(true) {__m_->lock();}
_LIBCPP_INLINE_VISIBILITY
unique_lock(mutex_type& __m, defer_lock_t) _NOEXCEPT
: __m_(_VSTD::addressof(__m)), __owns_(false) {}
_LIBCPP_INLINE_VISIBILITY
unique_lock(mutex_type& __m, try_to_lock_t)
: __m_(_VSTD::addressof(__m)), __owns_(__m.try_lock()) {}
_LIBCPP_INLINE_VISIBILITY
unique_lock(mutex_type& __m, adopt_lock_t)
: __m_(_VSTD::addressof(__m)), __owns_(true) {}
template <class _Clock, class _Duration>
_LIBCPP_INLINE_VISIBILITY
unique_lock(mutex_type& __m, const chrono::time_point<_Clock, _Duration>& __t)
: __m_(_VSTD::addressof(__m)), __owns_(__m.try_lock_until(__t)) {}
template <class _Rep, class _Period>
_LIBCPP_INLINE_VISIBILITY
unique_lock(mutex_type& __m, const chrono::duration<_Rep, _Period>& __d)
: __m_(_VSTD::addressof(__m)), __owns_(__m.try_lock_for(__d)) {}
_LIBCPP_INLINE_VISIBILITY
~unique_lock()
{
if (__owns_)
__m_->unlock();
}
private:
unique_lock(unique_lock const&); // = delete;
unique_lock& operator=(unique_lock const&); // = delete;
public:
#ifndef _LIBCPP_CXX03_LANG
_LIBCPP_INLINE_VISIBILITY
unique_lock(unique_lock&& __u) _NOEXCEPT
: __m_(__u.__m_), __owns_(__u.__owns_)
{__u.__m_ = nullptr; __u.__owns_ = false;}
_LIBCPP_INLINE_VISIBILITY
unique_lock& operator=(unique_lock&& __u) _NOEXCEPT
{
if (__owns_)
__m_->unlock();
__m_ = __u.__m_;
__owns_ = __u.__owns_;
__u.__m_ = nullptr;
__u.__owns_ = false;
return *this;
}
#endif // _LIBCPP_CXX03_LANG
void lock();
bool try_lock();
template <class _Rep, class _Period>
bool try_lock_for(const chrono::duration<_Rep, _Period>& __d);
template <class _Clock, class _Duration>
bool try_lock_until(const chrono::time_point<_Clock, _Duration>& __t);
void unlock();
_LIBCPP_INLINE_VISIBILITY
void swap(unique_lock& __u) _NOEXCEPT
{
_VSTD::swap(__m_, __u.__m_);
_VSTD::swap(__owns_, __u.__owns_);
}
_LIBCPP_INLINE_VISIBILITY
mutex_type* release() _NOEXCEPT
{
mutex_type* __m = __m_;
__m_ = nullptr;
__owns_ = false;
return __m;
}
_LIBCPP_INLINE_VISIBILITY
bool owns_lock() const _NOEXCEPT {return __owns_;}
_LIBCPP_INLINE_VISIBILITY
_LIBCPP_EXPLICIT
operator bool () const _NOEXCEPT {return __owns_;}
_LIBCPP_INLINE_VISIBILITY
mutex_type* mutex() const _NOEXCEPT {return __m_;}
};
template <class _Mutex>
void
unique_lock<_Mutex>::lock()
{
if (__m_ == nullptr)
__throw_system_error(EPERM, "unique_lock::lock: references null mutex");
if (__owns_)
__throw_system_error(EDEADLK, "unique_lock::lock: already locked");
__m_->lock();
__owns_ = true;
}
template <class _Mutex>
bool
unique_lock<_Mutex>::try_lock()
{
if (__m_ == nullptr)
__throw_system_error(EPERM, "unique_lock::try_lock: references null mutex");
if (__owns_)
__throw_system_error(EDEADLK, "unique_lock::try_lock: already locked");
__owns_ = __m_->try_lock();
return __owns_;
}
template <class _Mutex>
template <class _Rep, class _Period>
bool
unique_lock<_Mutex>::try_lock_for(const chrono::duration<_Rep, _Period>& __d)
{
if (__m_ == nullptr)
__throw_system_error(EPERM, "unique_lock::try_lock_for: references null mutex");
if (__owns_)
__throw_system_error(EDEADLK, "unique_lock::try_lock_for: already locked");
__owns_ = __m_->try_lock_for(__d);
return __owns_;
}
template <class _Mutex>
template <class _Clock, class _Duration>
bool
unique_lock<_Mutex>::try_lock_until(const chrono::time_point<_Clock, _Duration>& __t)
{
if (__m_ == nullptr)
__throw_system_error(EPERM, "unique_lock::try_lock_until: references null mutex");
if (__owns_)
__throw_system_error(EDEADLK, "unique_lock::try_lock_until: already locked");
__owns_ = __m_->try_lock_until(__t);
return __owns_;
}
template <class _Mutex>
void
unique_lock<_Mutex>::unlock()
{
if (!__owns_)
__throw_system_error(EPERM, "unique_lock::unlock: not locked");
__m_->unlock();
__owns_ = false;
}
template <class _Mutex>
inline _LIBCPP_INLINE_VISIBILITY
void
swap(unique_lock<_Mutex>& __x, unique_lock<_Mutex>& __y) _NOEXCEPT
{__x.swap(__y);}
//enum class cv_status
_LIBCPP_DECLARE_STRONG_ENUM(cv_status)
{
no_timeout,
timeout
};
_LIBCPP_DECLARE_STRONG_ENUM_EPILOG(cv_status)
class _LIBCPP_TYPE_VIS condition_variable
{
__libcpp_condvar_t __cv_ = _LIBCPP_CONDVAR_INITIALIZER;
public:
_LIBCPP_INLINE_VISIBILITY
_LIBCPP_CONSTEXPR condition_variable() _NOEXCEPT = default;
#ifdef _LIBCPP_HAS_TRIVIAL_CONDVAR_DESTRUCTION
~condition_variable() = default;
#else
~condition_variable();
#endif
condition_variable(const condition_variable&) = delete;
condition_variable& operator=(const condition_variable&) = delete;
void notify_one() _NOEXCEPT;
void notify_all() _NOEXCEPT;
void wait(unique_lock<mutex>& __lk) _NOEXCEPT;
template <class _Predicate>
_LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
void wait(unique_lock<mutex>& __lk, _Predicate __pred);
template <class _Clock, class _Duration>
_LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
cv_status
wait_until(unique_lock<mutex>& __lk,
const chrono::time_point<_Clock, _Duration>& __t);
template <class _Clock, class _Duration, class _Predicate>
_LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
bool
wait_until(unique_lock<mutex>& __lk,
const chrono::time_point<_Clock, _Duration>& __t,
_Predicate __pred);
template <class _Rep, class _Period>
_LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
cv_status
wait_for(unique_lock<mutex>& __lk,
const chrono::duration<_Rep, _Period>& __d);
template <class _Rep, class _Period, class _Predicate>
bool
_LIBCPP_INLINE_VISIBILITY
wait_for(unique_lock<mutex>& __lk,
const chrono::duration<_Rep, _Period>& __d,
_Predicate __pred);
typedef __libcpp_condvar_t* native_handle_type;
_LIBCPP_INLINE_VISIBILITY native_handle_type native_handle() {return &__cv_;}
private:
void __do_timed_wait(unique_lock<mutex>& __lk,
chrono::time_point<chrono::system_clock, chrono::nanoseconds>) _NOEXCEPT;
#if defined(_LIBCPP_HAS_COND_CLOCKWAIT)
void __do_timed_wait(unique_lock<mutex>& __lk,
chrono::time_point<chrono::steady_clock, chrono::nanoseconds>) _NOEXCEPT;
#endif
template <class _Clock>
void __do_timed_wait(unique_lock<mutex>& __lk,
chrono::time_point<_Clock, chrono::nanoseconds>) _NOEXCEPT;
};
#endif // !_LIBCPP_HAS_NO_THREADS
template <class _Rep, class _Period>
inline _LIBCPP_INLINE_VISIBILITY
typename enable_if
<
is_floating_point<_Rep>::value,
chrono::nanoseconds
>::type
__safe_nanosecond_cast(chrono::duration<_Rep, _Period> __d)
{
using namespace chrono;
using __ratio = ratio_divide<_Period, nano>;
using __ns_rep = nanoseconds::rep;
_Rep __result_float = __d.count() * __ratio::num / __ratio::den;
_Rep __result_max = numeric_limits<__ns_rep>::max();
if (__result_float >= __result_max) {
return nanoseconds::max();
}
_Rep __result_min = numeric_limits<__ns_rep>::min();
if (__result_float <= __result_min) {
return nanoseconds::min();
}
return nanoseconds(static_cast<__ns_rep>(__result_float));
}
template <class _Rep, class _Period>
inline _LIBCPP_INLINE_VISIBILITY
typename enable_if
<
!is_floating_point<_Rep>::value,
chrono::nanoseconds
>::type
__safe_nanosecond_cast(chrono::duration<_Rep, _Period> __d)
{
using namespace chrono;
if (__d.count() == 0) {
return nanoseconds(0);
}
using __ratio = ratio_divide<_Period, nano>;
using __ns_rep = nanoseconds::rep;
__ns_rep __result_max = std::numeric_limits<__ns_rep>::max();
if (__d.count() > 0 && __d.count() > __result_max / __ratio::num) {
return nanoseconds::max();
}
__ns_rep __result_min = std::numeric_limits<__ns_rep>::min();
if (__d.count() < 0 && __d.count() < __result_min / __ratio::num) {
return nanoseconds::min();
}
__ns_rep __result = __d.count() * __ratio::num / __ratio::den;
if (__result == 0) {
return nanoseconds(1);
}
return nanoseconds(__result);
}
#ifndef _LIBCPP_HAS_NO_THREADS
template <class _Predicate>
void
condition_variable::wait(unique_lock<mutex>& __lk, _Predicate __pred)
{
while (!__pred())
wait(__lk);
}
template <class _Clock, class _Duration>
cv_status
condition_variable::wait_until(unique_lock<mutex>& __lk,
const chrono::time_point<_Clock, _Duration>& __t)
{
using namespace chrono;
using __clock_tp_ns = time_point<_Clock, nanoseconds>;
typename _Clock::time_point __now = _Clock::now();
if (__t <= __now)
return cv_status::timeout;
__clock_tp_ns __t_ns = __clock_tp_ns(__safe_nanosecond_cast(__t.time_since_epoch()));
__do_timed_wait(__lk, __t_ns);
return _Clock::now() < __t ? cv_status::no_timeout : cv_status::timeout;
}
template <class _Clock, class _Duration, class _Predicate>
bool
condition_variable::wait_until(unique_lock<mutex>& __lk,
const chrono::time_point<_Clock, _Duration>& __t,
_Predicate __pred)
{
while (!__pred())
{
if (wait_until(__lk, __t) == cv_status::timeout)
return __pred();
}
return true;
}
template <class _Rep, class _Period>
cv_status
condition_variable::wait_for(unique_lock<mutex>& __lk,
const chrono::duration<_Rep, _Period>& __d)
{
using namespace chrono;
if (__d <= __d.zero())
return cv_status::timeout;
using __ns_rep = nanoseconds::rep;
steady_clock::time_point __c_now = steady_clock::now();
#if defined(_LIBCPP_HAS_COND_CLOCKWAIT)
using __clock_tp_ns = time_point<steady_clock, nanoseconds>;
__ns_rep __now_count_ns = __safe_nanosecond_cast(__c_now.time_since_epoch()).count();
#else
using __clock_tp_ns = time_point<system_clock, nanoseconds>;
__ns_rep __now_count_ns = __safe_nanosecond_cast(system_clock::now().time_since_epoch()).count();
#endif
__ns_rep __d_ns_count = __safe_nanosecond_cast(__d).count();
if (__now_count_ns > numeric_limits<__ns_rep>::max() - __d_ns_count) {
__do_timed_wait(__lk, __clock_tp_ns::max());
} else {
__do_timed_wait(__lk, __clock_tp_ns(nanoseconds(__now_count_ns + __d_ns_count)));
}
return steady_clock::now() - __c_now < __d ? cv_status::no_timeout :
cv_status::timeout;
}
template <class _Rep, class _Period, class _Predicate>
inline
bool
condition_variable::wait_for(unique_lock<mutex>& __lk,
const chrono::duration<_Rep, _Period>& __d,
_Predicate __pred)
{
return wait_until(__lk, chrono::steady_clock::now() + __d,
_VSTD::move(__pred));
}
#if defined(_LIBCPP_HAS_COND_CLOCKWAIT)
inline
void
condition_variable::__do_timed_wait(unique_lock<mutex>& __lk,
chrono::time_point<chrono::steady_clock, chrono::nanoseconds> __tp) _NOEXCEPT
{
using namespace chrono;
if (!__lk.owns_lock())
__throw_system_error(EPERM,
"condition_variable::timed wait: mutex not locked");
nanoseconds __d = __tp.time_since_epoch();
timespec __ts;
seconds __s = duration_cast<seconds>(__d);
using __ts_sec = decltype(__ts.tv_sec);
const __ts_sec __ts_sec_max = numeric_limits<__ts_sec>::max();
if (__s.count() < __ts_sec_max)
{
__ts.tv_sec = static_cast<__ts_sec>(__s.count());
__ts.tv_nsec = (__d - __s).count();
}
else
{
__ts.tv_sec = __ts_sec_max;
__ts.tv_nsec = giga::num - 1;
}
int __ec = pthread_cond_clockwait(&__cv_, __lk.mutex()->native_handle(), CLOCK_MONOTONIC, &__ts);
if (__ec != 0 && __ec != ETIMEDOUT)
__throw_system_error(__ec, "condition_variable timed_wait failed");
}
#endif // _LIBCPP_HAS_COND_CLOCKWAIT
template <class _Clock>
inline
void
condition_variable::__do_timed_wait(unique_lock<mutex>& __lk,
chrono::time_point<_Clock, chrono::nanoseconds> __tp) _NOEXCEPT
{
wait_for(__lk, __tp - _Clock::now());
}
#endif // !_LIBCPP_HAS_NO_THREADS
_LIBCPP_END_NAMESPACE_STD
_LIBCPP_POP_MACROS
#endif // _LIBCPP___MUTEX_BASE
| 16,861 | 544 | jart/cosmopolitan | false |
cosmopolitan/third_party/libcxx/libcxx.mk | #-*-mode:makefile-gmake;indent-tabs-mode:t;tab-width:8;coding:utf-8-*-â
#âââvi: set et ft=make ts=8 tw=8 fenc=utf-8 :viââââââââââââââââââââââââ
PKGS += THIRD_PARTY_LIBCXX
THIRD_PARTY_LIBCXX_ARTIFACTS += THIRD_PARTY_LIBCXX_A
THIRD_PARTY_LIBCXX = $(THIRD_PARTY_LIBCXX_A_DEPS) $(THIRD_PARTY_LIBCXX_A)
THIRD_PARTY_LIBCXX_A = o/$(MODE)/third_party/libcxx/libcxx.a
THIRD_PARTY_LIBCXX_A_HDRS = \
third_party/libcxx/__bit_reference \
third_party/libcxx/__bsd_locale_fallbacks.h \
third_party/libcxx/__config \
third_party/libcxx/__debug \
third_party/libcxx/__errc \
third_party/libcxx/__functional_base \
third_party/libcxx/__hash_table \
third_party/libcxx/__locale \
third_party/libcxx/__mutex_base \
third_party/libcxx/__node_handle \
third_party/libcxx/__nullptr \
third_party/libcxx/__split_buffer \
third_party/libcxx/__sso_allocator \
third_party/libcxx/__std_stream \
third_party/libcxx/__string \
third_party/libcxx/__threading_support \
third_party/libcxx/__tree \
third_party/libcxx/__tuple \
third_party/libcxx/__undef_macros \
third_party/libcxx/algorithm \
third_party/libcxx/any \
third_party/libcxx/array \
third_party/libcxx/atomic \
third_party/libcxx/atomic_support.hh \
third_party/libcxx/bit \
third_party/libcxx/bitset \
third_party/libcxx/cassert \
third_party/libcxx/ccomplex \
third_party/libcxx/cctype \
third_party/libcxx/cerrno \
third_party/libcxx/cfenv \
third_party/libcxx/cfloat \
third_party/libcxx/charconv \
third_party/libcxx/chrono \
third_party/libcxx/cinttypes \
third_party/libcxx/ciso646 \
third_party/libcxx/climits \
third_party/libcxx/clocale \
third_party/libcxx/cmath \
third_party/libcxx/codecvt \
third_party/libcxx/compare \
third_party/libcxx/complex \
third_party/libcxx/condition_variable \
third_party/libcxx/config_elast.h \
third_party/libcxx/countof.internal.hh \
third_party/libcxx/csetjmp \
third_party/libcxx/csignal \
third_party/libcxx/cstdarg \
third_party/libcxx/cstdbool \
third_party/libcxx/cstddef \
third_party/libcxx/cstdint \
third_party/libcxx/cstdio \
third_party/libcxx/cstdlib \
third_party/libcxx/cstring \
third_party/libcxx/ctgmath \
third_party/libcxx/ctime \
third_party/libcxx/ctype.h \
third_party/libcxx/cwchar \
third_party/libcxx/cwctype \
third_party/libcxx/deque \
third_party/libcxx/errno.h \
third_party/libcxx/exception \
third_party/libcxx/exception_fallback.hh \
third_party/libcxx/exception_pointer_unimplemented.hh \
third_party/libcxx/execution \
third_party/libcxx/experimental/__config \
third_party/libcxx/filesystem \
third_party/libcxx/forward_list \
third_party/libcxx/fstream \
third_party/libcxx/functional \
third_party/libcxx/future \
third_party/libcxx/include/atomic_support.hh \
third_party/libcxx/include/config_elast.hh \
third_party/libcxx/initializer_list \
third_party/libcxx/iomanip \
third_party/libcxx/ios \
third_party/libcxx/iosfwd \
third_party/libcxx/iostream \
third_party/libcxx/istream \
third_party/libcxx/iterator \
third_party/libcxx/limits \
third_party/libcxx/limits.h \
third_party/libcxx/list \
third_party/libcxx/locale \
third_party/libcxx/locale.h \
third_party/libcxx/map \
third_party/libcxx/math.h \
third_party/libcxx/memory \
third_party/libcxx/mutex \
third_party/libcxx/new \
third_party/libcxx/new_handler_fallback.hh \
third_party/libcxx/numeric \
third_party/libcxx/optional \
third_party/libcxx/ostream \
third_party/libcxx/queue \
third_party/libcxx/queue \
third_party/libcxx/random \
third_party/libcxx/ratio \
third_party/libcxx/refstring.hh \
third_party/libcxx/regex \
third_party/libcxx/scoped_allocator \
third_party/libcxx/set \
third_party/libcxx/sstream \
third_party/libcxx/stack \
third_party/libcxx/stdexcept \
third_party/libcxx/stdexcept_default.hh \
third_party/libcxx/stdio.h \
third_party/libcxx/stdlib.h \
third_party/libcxx/streambuf \
third_party/libcxx/string \
third_party/libcxx/string.h \
third_party/libcxx/string_view \
third_party/libcxx/strstream \
third_party/libcxx/system_error \
third_party/libcxx/thread \
third_party/libcxx/tuple \
third_party/libcxx/type_traits \
third_party/libcxx/typeindex \
third_party/libcxx/typeinfo \
third_party/libcxx/unordered_map \
third_party/libcxx/unordered_set \
third_party/libcxx/utility \
third_party/libcxx/valarray \
third_party/libcxx/variant \
third_party/libcxx/vector \
third_party/libcxx/version \
third_party/libcxx/wchar.h \
third_party/libcxx/wctype.h
THIRD_PARTY_LIBCXX_A_SRCS_CC = \
third_party/libcxx/algorithm.cc \
third_party/libcxx/charconv.cc \
third_party/libcxx/chrono.cc \
third_party/libcxx/condition_variable.cc \
third_party/libcxx/condition_variable_destructor.cc \
third_party/libcxx/exception.cc \
third_party/libcxx/functional.cc \
third_party/libcxx/future.cc \
third_party/libcxx/hash.cc \
third_party/libcxx/ios.cc \
third_party/libcxx/iostream.cc \
third_party/libcxx/locale1.cc \
third_party/libcxx/locale2.cc \
third_party/libcxx/locale3.cc \
third_party/libcxx/locale4.cc \
third_party/libcxx/memory.cc \
third_party/libcxx/mutex.cc \
third_party/libcxx/new.cc \
third_party/libcxx/optional.cc \
third_party/libcxx/random.cc \
third_party/libcxx/regex.cc \
third_party/libcxx/stdexcept.cc \
third_party/libcxx/string.cc \
third_party/libcxx/strstream.cc \
third_party/libcxx/system_error.cc \
third_party/libcxx/thread.cc \
third_party/libcxx/valarray.cc \
third_party/libcxx/vector.cc
THIRD_PARTY_LIBCXX_A_SRCS = \
$(THIRD_PARTY_LIBCXX_A_SRCS_S) \
$(THIRD_PARTY_LIBCXX_A_SRCS_CC)
THIRD_PARTY_LIBCXX_A_OBJS = \
$(THIRD_PARTY_LIBCXX_A_SRCS_S:%.S=o/$(MODE)/%.o) \
$(THIRD_PARTY_LIBCXX_A_SRCS_C:%.c=o/$(MODE)/%.o) \
$(THIRD_PARTY_LIBCXX_A_SRCS_CC:%.cc=o/$(MODE)/%.o)
THIRD_PARTY_LIBCXX_A_CHECKS = \
$(THIRD_PARTY_LIBCXX_A).pkg \
$(THIRD_PARTY_LIBCXX_A_HDRS:%=o/$(MODE)/%.okk)
THIRD_PARTY_LIBCXX_A_DIRECTDEPS = \
LIBC_CALLS \
LIBC_FMT \
LIBC_INTRIN \
LIBC_MEM \
LIBC_NEXGEN32E \
LIBC_RUNTIME \
LIBC_STDIO \
LIBC_STR \
LIBC_STUBS \
LIBC_SYSV \
LIBC_TIME \
LIBC_THREAD \
LIBC_TINYMATH \
THIRD_PARTY_GDTOA
THIRD_PARTY_LIBCXX_A_DEPS := \
$(call uniq,$(foreach x,$(THIRD_PARTY_LIBCXX_A_DIRECTDEPS),$($(x))))
$(THIRD_PARTY_LIBCXX_A): \
third_party/libcxx/ \
$(THIRD_PARTY_LIBCXX_A).pkg \
$(THIRD_PARTY_LIBCXX_A_OBJS)
$(THIRD_PARTY_LIBCXX_A).pkg: \
$(THIRD_PARTY_LIBCXX_A_OBJS) \
$(foreach x,$(THIRD_PARTY_LIBCXX_A_DIRECTDEPS),$($(x)_A).pkg)
$(THIRD_PARTY_LIBCXX_A_OBJS): private \
OVERRIDE_CXXFLAGS += \
-ffunction-sections \
-fdata-sections
THIRD_PARTY_LIBCXX_LIBS = $(foreach x,$(THIRD_PARTY_LIBCXX_ARTIFACTS),$($(x)))
THIRD_PARTY_LIBCXX_SRCS = $(foreach x,$(THIRD_PARTY_LIBCXX_ARTIFACTS),$($(x)_SRCS))
THIRD_PARTY_LIBCXX_HDRS = $(foreach x,$(THIRD_PARTY_LIBCXX_ARTIFACTS),$($(x)_HDRS))
THIRD_PARTY_LIBCXX_INCS = $(foreach x,$(THIRD_PARTY_LIBCXX_ARTIFACTS),$($(x)_INCS))
THIRD_PARTY_LIBCXX_CHECKS = $(foreach x,$(THIRD_PARTY_LIBCXX_ARTIFACTS),$($(x)_CHECKS))
THIRD_PARTY_LIBCXX_OBJS = $(foreach x,$(THIRD_PARTY_LIBCXX_ARTIFACTS),$($(x)_OBJS))
.PHONY: o/$(MODE)/third_party/libcxx
o/$(MODE)/third_party/libcxx: \
$(THIRD_PARTY_LIBCXX_CHECKS) \
$(THIRD_PARTY_LIBCXX_A)
| 7,821 | 228 | jart/cosmopolitan | false |
cosmopolitan/third_party/libcxx/__errc | // -*- C++ -*-
//===---------------------------- __errc ----------------------------------===//
//
// 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___ERRC
#define _LIBCPP___ERRC
#include "third_party/libcxx/__config"
#include "third_party/libcxx/cerrno"
/*
system_error synopsis
namespace std
{
enum class errc
{
address_family_not_supported, // EAFNOSUPPORT
address_in_use, // EADDRINUSE
address_not_available, // EADDRNOTAVAIL
already_connected, // EISCONN
argument_list_too_long, // E2BIG
argument_out_of_domain, // EDOM
bad_address, // EFAULT
bad_file_descriptor, // EBADF
bad_message, // EBADMSG
broken_pipe, // EPIPE
connection_aborted, // ECONNABORTED
connection_already_in_progress, // EALREADY
connection_refused, // ECONNREFUSED
connection_reset, // ECONNRESET
cross_device_link, // EXDEV
destination_address_required, // EDESTADDRREQ
device_or_resource_busy, // EBUSY
directory_not_empty, // ENOTEMPTY
executable_format_error, // ENOEXEC
file_exists, // EEXIST
file_too_large, // EFBIG
filename_too_long, // ENAMETOOLONG
function_not_supported, // ENOSYS
host_unreachable, // EHOSTUNREACH
identifier_removed, // EIDRM
illegal_byte_sequence, // EILSEQ
inappropriate_io_control_operation, // ENOTTY
interrupted, // EINTR
invalid_argument, // EINVAL
invalid_seek, // ESPIPE
io_error, // EIO
is_a_directory, // EISDIR
message_size, // EMSGSIZE
network_down, // ENETDOWN
network_reset, // ENETRESET
network_unreachable, // ENETUNREACH
no_buffer_space, // ENOBUFS
no_child_process, // ECHILD
no_link, // ENOLINK
no_lock_available, // ENOLCK
no_message_available, // ENODATA
no_message, // ENOMSG
no_protocol_option, // ENOPROTOOPT
no_space_on_device, // ENOSPC
no_stream_resources, // ENOSR
no_such_device_or_address, // ENXIO
no_such_device, // ENODEV
no_such_file_or_directory, // ENOENT
no_such_process, // ESRCH
not_a_directory, // ENOTDIR
not_a_socket, // ENOTSOCK
not_a_stream, // ENOSTR
not_connected, // ENOTCONN
not_enough_memory, // ENOMEM
not_supported, // ENOTSUP
operation_canceled, // ECANCELED
operation_in_progress, // EINPROGRESS
operation_not_permitted, // EPERM
operation_not_supported, // EOPNOTSUPP
operation_would_block, // EWOULDBLOCK
owner_dead, // EOWNERDEAD
permission_denied, // EACCES
protocol_error, // EPROTO
protocol_not_supported, // EPROTONOSUPPORT
read_only_file_system, // EROFS
resource_deadlock_would_occur, // EDEADLK
resource_unavailable_try_again, // EAGAIN
result_out_of_range, // ERANGE
state_not_recoverable, // ENOTRECOVERABLE
stream_timeout, // ETIME
text_file_busy, // ETXTBSY
timed_out, // ETIMEDOUT
too_many_files_open_in_system, // ENFILE
too_many_files_open, // EMFILE
too_many_links, // EMLINK
too_many_symbolic_link_levels, // ELOOP
value_too_large, // EOVERFLOW
wrong_protocol_type // EPROTOTYPE
};
*/
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
#pragma GCC system_header
#endif
_LIBCPP_BEGIN_NAMESPACE_STD
// Some error codes are not present on all platforms, so we provide equivalents
// for them:
//enum class errc
_LIBCPP_DECLARE_STRONG_ENUM(errc)
{
address_family_not_supported,
address_in_use,
address_not_available,
already_connected,
argument_list_too_long,
argument_out_of_domain,
bad_address,
bad_file_descriptor,
bad_message,
broken_pipe,
connection_aborted,
connection_already_in_progress,
connection_refused,
connection_reset,
cross_device_link,
destination_address_required,
device_or_resource_busy,
directory_not_empty,
executable_format_error,
file_exists,
file_too_large,
filename_too_long,
function_not_supported,
host_unreachable,
identifier_removed,
illegal_byte_sequence,
inappropriate_io_control_operation,
interrupted,
invalid_argument,
invalid_seek,
io_error,
is_a_directory,
message_size,
network_down,
network_reset,
network_unreachable,
no_buffer_space,
no_child_process,
no_link,
no_lock_available,
#ifdef ENODATA
no_message_available,
#else
no_message_available,
#endif
no_message,
no_protocol_option,
no_space_on_device,
#ifdef ENOSR
no_stream_resources,
#else
no_stream_resources,
#endif
no_such_device_or_address,
no_such_device,
no_such_file_or_directory,
no_such_process,
not_a_directory,
not_a_socket,
#ifdef ENOSTR
not_a_stream,
#else
not_a_stream,
#endif
not_connected,
not_enough_memory,
not_supported,
operation_canceled,
operation_in_progress,
operation_not_permitted,
operation_not_supported,
operation_would_block,
owner_dead,
permission_denied,
protocol_error,
protocol_not_supported,
read_only_file_system,
resource_deadlock_would_occur,
resource_unavailable_try_again,
result_out_of_range,
state_not_recoverable,
#ifdef ETIME
stream_timeout,
#else
stream_timeout,
#endif
text_file_busy,
timed_out,
too_many_files_open_in_system,
too_many_files_open,
too_many_links,
too_many_symbolic_link_levels,
value_too_large,
wrong_protocol_type
};
_LIBCPP_DECLARE_STRONG_ENUM_EPILOG(errc)
_LIBCPP_END_NAMESPACE_STD
#endif // _LIBCPP___ERRC
| 7,010 | 218 | jart/cosmopolitan | false |
cosmopolitan/third_party/libcxx/cstdlib | // -*- C++ -*-
//===--------------------------- cstdlib ----------------------------------===//
//
// 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_CSTDLIB
#define _LIBCPP_CSTDLIB
#include "third_party/libcxx/__config"
#include "libc/str/str.h"
#include "third_party/libcxx/stdlib.h"
/*
cstdlib synopsis
Macros:
EXIT_FAILURE
EXIT_SUCCESS
MB_CUR_MAX
NULL
RAND_MAX
namespace std
{
Types:
size_t
div_t
ldiv_t
lldiv_t // C99
double atof (const char* nptr);
int atoi (const char* nptr);
long atol (const char* nptr);
long long atoll(const char* nptr); // C99
double strtod (const char* restrict nptr, char** restrict endptr);
float strtof (const char* restrict nptr, char** restrict endptr); // C99
long double strtold (const char* restrict nptr, char** restrict endptr); // C99
long strtol (const char* restrict nptr, char** restrict endptr, int base);
long long strtoll (const char* restrict nptr, char** restrict endptr, int base); // C99
unsigned long strtoul (const char* restrict nptr, char** restrict endptr, int base);
unsigned long long strtoull(const char* restrict nptr, char** restrict endptr, int base); // C99
int rand(void);
void srand(unsigned int seed);
void* calloc(size_t nmemb, size_t size);
void free(void* ptr);
void* malloc(size_t size);
void* realloc(void* ptr, size_t size);
void abort(void);
int atexit(void (*func)(void));
void exit(int status);
void _Exit(int status);
char* getenv(const char* name);
int system(const char* string);
void* bsearch(const void* key, const void* base, size_t nmemb, size_t size,
int (*compar)(const void *, const void *));
void qsort(void* base, size_t nmemb, size_t size,
int (*compar)(const void *, const void *));
int abs( int j);
long abs( long j);
long long abs(long long j); // C++0X
long labs( long j);
long long llabs(long long j); // C99
div_t div( int numer, int denom);
ldiv_t div( long numer, long denom);
lldiv_t div(long long numer, long long denom); // C++0X
ldiv_t ldiv( long numer, long denom);
lldiv_t lldiv(long long numer, long long denom); // C99
int mblen(const char* s, size_t n);
int mbtowc(wchar_t* restrict pwc, const char* restrict s, size_t n);
int wctomb(char* s, wchar_t wchar);
size_t mbstowcs(wchar_t* restrict pwcs, const char* restrict s, size_t n);
size_t wcstombs(char* restrict s, const wchar_t* restrict pwcs, size_t n);
int at_quick_exit(void (*func)(void)) // C++11
void quick_exit(int status); // C++11
void *aligned_alloc(size_t alignment, size_t size); // C11
} // std
*/
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
#pragma GCC system_header
#endif
#ifdef __GNUC__
#define _LIBCPP_UNREACHABLE() __builtin_unreachable()
#else
#define _LIBCPP_UNREACHABLE() _VSTD::abort()
#endif
_LIBCPP_BEGIN_NAMESPACE_STD
using ::size_t;
using ::div_t;
using ::ldiv_t;
#ifndef _LIBCPP_HAS_NO_LONG_LONG
using ::lldiv_t;
#endif // _LIBCPP_HAS_NO_LONG_LONG
using ::atof;
using ::atoi;
using ::atol;
#ifndef _LIBCPP_HAS_NO_LONG_LONG
using ::atoll;
#endif // _LIBCPP_HAS_NO_LONG_LONG
using ::strtod;
using ::strtof;
using ::strtold;
using ::strtol;
#ifndef _LIBCPP_HAS_NO_LONG_LONG
using ::strtoll;
#endif // _LIBCPP_HAS_NO_LONG_LONG
using ::strtoul;
#ifndef _LIBCPP_HAS_NO_LONG_LONG
using ::strtoull;
#endif // _LIBCPP_HAS_NO_LONG_LONG
using ::rand;
using ::srand;
using ::calloc;
using ::free;
using ::malloc;
using ::realloc;
using ::abort;
using ::atexit;
using ::exit;
using ::_Exit;
#ifndef _LIBCPP_WINDOWS_STORE_APP
using ::getenv;
using ::system;
#endif
using ::bsearch;
using ::qsort;
using ::abs;
using ::labs;
#ifndef _LIBCPP_HAS_NO_LONG_LONG
using ::llabs;
#endif // _LIBCPP_HAS_NO_LONG_LONG
using ::div;
using ::ldiv;
#ifndef _LIBCPP_HAS_NO_LONG_LONG
using ::lldiv;
#endif // _LIBCPP_HAS_NO_LONG_LONG
using ::mblen;
using ::mbtowc;
using ::wctomb;
using ::mbstowcs;
using ::wcstombs;
#if !defined(_LIBCPP_CXX03_LANG) && defined(_LIBCPP_HAS_QUICK_EXIT)
using ::at_quick_exit;
using ::quick_exit;
#endif
#if _LIBCPP_STD_VER > 14 && defined(_LIBCPP_HAS_C11_FEATURES)
using ::aligned_alloc;
#endif
_LIBCPP_END_NAMESPACE_STD
#endif // _LIBCPP_CSTDLIB
| 4,870 | 165 | jart/cosmopolitan | false |
cosmopolitan/third_party/libcxx/unordered_set | // -*- C++ -*-
//===-------------------------- unordered_set -----------------------------===//
//
// 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_UNORDERED_SET
#define _LIBCPP_UNORDERED_SET
#include "third_party/libcxx/__config"
#include "third_party/libcxx/__hash_table"
#include "third_party/libcxx/__node_handle"
#include "third_party/libcxx/functional"
#include "third_party/libcxx/version"
#include "third_party/libcxx/__debug"
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
#pragma GCC system_header
#endif
_LIBCPP_BEGIN_NAMESPACE_STD
/*
unordered_set synopsis
#include "third_party/libcxx/initializer_list"
namespace std
{
template <class Value, class Hash = hash<Value>, class Pred = equal_to<Value>,
class Alloc = allocator<Value>>
class unordered_set
{
public:
// types
typedef Value key_type;
typedef key_type value_type;
typedef Hash hasher;
typedef Pred key_equal;
typedef Alloc allocator_type;
typedef value_type& reference;
typedef const value_type& const_reference;
typedef typename allocator_traits<allocator_type>::pointer pointer;
typedef typename allocator_traits<allocator_type>::const_pointer const_pointer;
typedef typename allocator_traits<allocator_type>::size_type size_type;
typedef typename allocator_traits<allocator_type>::difference_type difference_type;
typedef /unspecified/ iterator;
typedef /unspecified/ const_iterator;
typedef /unspecified/ local_iterator;
typedef /unspecified/ const_local_iterator;
typedef unspecified node_type unspecified; // C++17
typedef INSERT_RETURN_TYPE<iterator, node_type> insert_return_type; // C++17
unordered_set()
noexcept(
is_nothrow_default_constructible<hasher>::value &&
is_nothrow_default_constructible<key_equal>::value &&
is_nothrow_default_constructible<allocator_type>::value);
explicit unordered_set(size_type n, const hasher& hf = hasher(),
const key_equal& eql = key_equal(),
const allocator_type& a = allocator_type());
template <class InputIterator>
unordered_set(InputIterator f, InputIterator l,
size_type n = 0, const hasher& hf = hasher(),
const key_equal& eql = key_equal(),
const allocator_type& a = allocator_type());
explicit unordered_set(const allocator_type&);
unordered_set(const unordered_set&);
unordered_set(const unordered_set&, const Allocator&);
unordered_set(unordered_set&&)
noexcept(
is_nothrow_move_constructible<hasher>::value &&
is_nothrow_move_constructible<key_equal>::value &&
is_nothrow_move_constructible<allocator_type>::value);
unordered_set(unordered_set&&, const Allocator&);
unordered_set(initializer_list<value_type>, size_type n = 0,
const hasher& hf = hasher(), const key_equal& eql = key_equal(),
const allocator_type& a = allocator_type());
unordered_set(size_type n, const allocator_type& a); // C++14
unordered_set(size_type n, const hasher& hf, const allocator_type& a); // C++14
template <class InputIterator>
unordered_set(InputIterator f, InputIterator l, size_type n, const allocator_type& a); // C++14
template <class InputIterator>
unordered_set(InputIterator f, InputIterator l, size_type n,
const hasher& hf, const allocator_type& a); // C++14
unordered_set(initializer_list<value_type> il, size_type n, const allocator_type& a); // C++14
unordered_set(initializer_list<value_type> il, size_type n,
const hasher& hf, const allocator_type& a); // C++14
~unordered_set();
unordered_set& operator=(const unordered_set&);
unordered_set& operator=(unordered_set&&)
noexcept(
allocator_type::propagate_on_container_move_assignment::value &&
is_nothrow_move_assignable<allocator_type>::value &&
is_nothrow_move_assignable<hasher>::value &&
is_nothrow_move_assignable<key_equal>::value);
unordered_set& operator=(initializer_list<value_type>);
allocator_type get_allocator() const noexcept;
bool empty() const noexcept;
size_type size() const noexcept;
size_type max_size() const noexcept;
iterator begin() noexcept;
iterator end() noexcept;
const_iterator begin() const noexcept;
const_iterator end() const noexcept;
const_iterator cbegin() const noexcept;
const_iterator cend() const noexcept;
template <class... Args>
pair<iterator, bool> emplace(Args&&... args);
template <class... Args>
iterator emplace_hint(const_iterator position, Args&&... args);
pair<iterator, bool> insert(const value_type& obj);
pair<iterator, bool> insert(value_type&& obj);
iterator insert(const_iterator hint, const value_type& obj);
iterator insert(const_iterator hint, value_type&& obj);
template <class InputIterator>
void insert(InputIterator first, InputIterator last);
void insert(initializer_list<value_type>);
node_type extract(const_iterator position); // C++17
node_type extract(const key_type& x); // C++17
insert_return_type insert(node_type&& nh); // C++17
iterator insert(const_iterator hint, node_type&& nh); // C++17
iterator erase(const_iterator position);
iterator erase(iterator position); // C++14
size_type erase(const key_type& k);
iterator erase(const_iterator first, const_iterator last);
void clear() noexcept;
template<class H2, class P2>
void merge(unordered_set<Key, H2, P2, Allocator>& source); // C++17
template<class H2, class P2>
void merge(unordered_set<Key, H2, P2, Allocator>&& source); // C++17
template<class H2, class P2>
void merge(unordered_multiset<Key, H2, P2, Allocator>& source); // C++17
template<class H2, class P2>
void merge(unordered_multiset<Key, H2, P2, Allocator>&& source); // C++17
void swap(unordered_set&)
noexcept(allocator_traits<Allocator>::is_always_equal::value &&
noexcept(swap(declval<hasher&>(), declval<hasher&>())) &&
noexcept(swap(declval<key_equal&>(), declval<key_equal&>()))); // C++17
hasher hash_function() const;
key_equal key_eq() const;
iterator find(const key_type& k);
const_iterator find(const key_type& k) const;
size_type count(const key_type& k) const;
bool contains(const key_type& k) const; // C++20
pair<iterator, iterator> equal_range(const key_type& k);
pair<const_iterator, const_iterator> equal_range(const key_type& k) const;
size_type bucket_count() const noexcept;
size_type max_bucket_count() const noexcept;
size_type bucket_size(size_type n) const;
size_type bucket(const key_type& k) const;
local_iterator begin(size_type n);
local_iterator end(size_type n);
const_local_iterator begin(size_type n) const;
const_local_iterator end(size_type n) const;
const_local_iterator cbegin(size_type n) const;
const_local_iterator cend(size_type n) const;
float load_factor() const noexcept;
float max_load_factor() const noexcept;
void max_load_factor(float z);
void rehash(size_type n);
void reserve(size_type n);
};
template <class Value, class Hash, class Pred, class Alloc>
void swap(unordered_set<Value, Hash, Pred, Alloc>& x,
unordered_set<Value, Hash, Pred, Alloc>& y)
noexcept(noexcept(x.swap(y)));
template <class Value, class Hash, class Pred, class Alloc>
bool
operator==(const unordered_set<Value, Hash, Pred, Alloc>& x,
const unordered_set<Value, Hash, Pred, Alloc>& y);
template <class Value, class Hash, class Pred, class Alloc>
bool
operator!=(const unordered_set<Value, Hash, Pred, Alloc>& x,
const unordered_set<Value, Hash, Pred, Alloc>& y);
template <class Value, class Hash = hash<Value>, class Pred = equal_to<Value>,
class Alloc = allocator<Value>>
class unordered_multiset
{
public:
// types
typedef Value key_type;
typedef key_type value_type;
typedef Hash hasher;
typedef Pred key_equal;
typedef Alloc allocator_type;
typedef value_type& reference;
typedef const value_type& const_reference;
typedef typename allocator_traits<allocator_type>::pointer pointer;
typedef typename allocator_traits<allocator_type>::const_pointer const_pointer;
typedef typename allocator_traits<allocator_type>::size_type size_type;
typedef typename allocator_traits<allocator_type>::difference_type difference_type;
typedef /unspecified/ iterator;
typedef /unspecified/ const_iterator;
typedef /unspecified/ local_iterator;
typedef /unspecified/ const_local_iterator;
typedef unspecified node_type unspecified; // C++17
unordered_multiset()
noexcept(
is_nothrow_default_constructible<hasher>::value &&
is_nothrow_default_constructible<key_equal>::value &&
is_nothrow_default_constructible<allocator_type>::value);
explicit unordered_multiset(size_type n, const hasher& hf = hasher(),
const key_equal& eql = key_equal(),
const allocator_type& a = allocator_type());
template <class InputIterator>
unordered_multiset(InputIterator f, InputIterator l,
size_type n = 0, const hasher& hf = hasher(),
const key_equal& eql = key_equal(),
const allocator_type& a = allocator_type());
explicit unordered_multiset(const allocator_type&);
unordered_multiset(const unordered_multiset&);
unordered_multiset(const unordered_multiset&, const Allocator&);
unordered_multiset(unordered_multiset&&)
noexcept(
is_nothrow_move_constructible<hasher>::value &&
is_nothrow_move_constructible<key_equal>::value &&
is_nothrow_move_constructible<allocator_type>::value);
unordered_multiset(unordered_multiset&&, const Allocator&);
unordered_multiset(initializer_list<value_type>, size_type n = /see below/,
const hasher& hf = hasher(), const key_equal& eql = key_equal(),
const allocator_type& a = allocator_type());
unordered_multiset(size_type n, const allocator_type& a); // C++14
unordered_multiset(size_type n, const hasher& hf, const allocator_type& a); // C++14
template <class InputIterator>
unordered_multiset(InputIterator f, InputIterator l, size_type n, const allocator_type& a); // C++14
template <class InputIterator>
unordered_multiset(InputIterator f, InputIterator l, size_type n,
const hasher& hf, const allocator_type& a); // C++14
unordered_multiset(initializer_list<value_type> il, size_type n, const allocator_type& a); // C++14
unordered_multiset(initializer_list<value_type> il, size_type n,
const hasher& hf, const allocator_type& a); // C++14
~unordered_multiset();
unordered_multiset& operator=(const unordered_multiset&);
unordered_multiset& operator=(unordered_multiset&&)
noexcept(
allocator_type::propagate_on_container_move_assignment::value &&
is_nothrow_move_assignable<allocator_type>::value &&
is_nothrow_move_assignable<hasher>::value &&
is_nothrow_move_assignable<key_equal>::value);
unordered_multiset& operator=(initializer_list<value_type>);
allocator_type get_allocator() const noexcept;
bool empty() const noexcept;
size_type size() const noexcept;
size_type max_size() const noexcept;
iterator begin() noexcept;
iterator end() noexcept;
const_iterator begin() const noexcept;
const_iterator end() const noexcept;
const_iterator cbegin() const noexcept;
const_iterator cend() const noexcept;
template <class... Args>
iterator emplace(Args&&... args);
template <class... Args>
iterator emplace_hint(const_iterator position, Args&&... args);
iterator insert(const value_type& obj);
iterator insert(value_type&& obj);
iterator insert(const_iterator hint, const value_type& obj);
iterator insert(const_iterator hint, value_type&& obj);
template <class InputIterator>
void insert(InputIterator first, InputIterator last);
void insert(initializer_list<value_type>);
node_type extract(const_iterator position); // C++17
node_type extract(const key_type& x); // C++17
iterator insert(node_type&& nh); // C++17
iterator insert(const_iterator hint, node_type&& nh); // C++17
iterator erase(const_iterator position);
iterator erase(iterator position); // C++14
size_type erase(const key_type& k);
iterator erase(const_iterator first, const_iterator last);
void clear() noexcept;
template<class H2, class P2>
void merge(unordered_multiset<Key, H2, P2, Allocator>& source); // C++17
template<class H2, class P2>
void merge(unordered_multiset<Key, H2, P2, Allocator>&& source); // C++17
template<class H2, class P2>
void merge(unordered_set<Key, H2, P2, Allocator>& source); // C++17
template<class H2, class P2>
void merge(unordered_set<Key, H2, P2, Allocator>&& source); // C++17
void swap(unordered_multiset&)
noexcept(allocator_traits<Allocator>::is_always_equal::value &&
noexcept(swap(declval<hasher&>(), declval<hasher&>())) &&
noexcept(swap(declval<key_equal&>(), declval<key_equal&>()))); // C++17
hasher hash_function() const;
key_equal key_eq() const;
iterator find(const key_type& k);
const_iterator find(const key_type& k) const;
size_type count(const key_type& k) const;
bool contains(const key_type& k) const; // C++20
pair<iterator, iterator> equal_range(const key_type& k);
pair<const_iterator, const_iterator> equal_range(const key_type& k) const;
size_type bucket_count() const noexcept;
size_type max_bucket_count() const noexcept;
size_type bucket_size(size_type n) const;
size_type bucket(const key_type& k) const;
local_iterator begin(size_type n);
local_iterator end(size_type n);
const_local_iterator begin(size_type n) const;
const_local_iterator end(size_type n) const;
const_local_iterator cbegin(size_type n) const;
const_local_iterator cend(size_type n) const;
float load_factor() const noexcept;
float max_load_factor() const noexcept;
void max_load_factor(float z);
void rehash(size_type n);
void reserve(size_type n);
};
template <class Value, class Hash, class Pred, class Alloc>
void swap(unordered_multiset<Value, Hash, Pred, Alloc>& x,
unordered_multiset<Value, Hash, Pred, Alloc>& y)
noexcept(noexcept(x.swap(y)));
template <class K, class T, class H, class P, class A, class Predicate>
void erase_if(unordered_set<K, T, H, P, A>& c, Predicate pred); // C++20
template <class K, class T, class H, class P, class A, class Predicate>
void erase_if(unordered_multiset<K, T, H, P, A>& c, Predicate pred); // C++20
template <class Value, class Hash, class Pred, class Alloc>
bool
operator==(const unordered_multiset<Value, Hash, Pred, Alloc>& x,
const unordered_multiset<Value, Hash, Pred, Alloc>& y);
template <class Value, class Hash, class Pred, class Alloc>
bool
operator!=(const unordered_multiset<Value, Hash, Pred, Alloc>& x,
const unordered_multiset<Value, Hash, Pred, Alloc>& y);
} // std
*/
template <class _Value, class _Hash, class _Pred, class _Alloc>
class unordered_multiset;
template <class _Value, class _Hash = hash<_Value>, class _Pred = equal_to<_Value>,
class _Alloc = allocator<_Value> >
class _LIBCPP_TEMPLATE_VIS unordered_set
{
public:
// types
typedef _Value key_type;
typedef key_type value_type;
typedef typename __identity<_Hash>::type hasher;
typedef typename __identity<_Pred>::type key_equal;
typedef typename __identity<_Alloc>::type allocator_type;
typedef value_type& reference;
typedef const value_type& const_reference;
static_assert((is_same<value_type, typename allocator_type::value_type>::value),
"Invalid allocator::value_type");
private:
typedef __hash_table<value_type, hasher, key_equal, allocator_type> __table;
__table __table_;
public:
typedef typename __table::pointer pointer;
typedef typename __table::const_pointer const_pointer;
typedef typename __table::size_type size_type;
typedef typename __table::difference_type difference_type;
typedef typename __table::const_iterator iterator;
typedef typename __table::const_iterator const_iterator;
typedef typename __table::const_local_iterator local_iterator;
typedef typename __table::const_local_iterator const_local_iterator;
#if _LIBCPP_STD_VER > 14
typedef __set_node_handle<typename __table::__node, allocator_type> node_type;
typedef __insert_return_type<iterator, node_type> insert_return_type;
#endif
template <class _Value2, class _Hash2, class _Pred2, class _Alloc2>
friend class _LIBCPP_TEMPLATE_VIS unordered_set;
template <class _Value2, class _Hash2, class _Pred2, class _Alloc2>
friend class _LIBCPP_TEMPLATE_VIS unordered_multiset;
_LIBCPP_INLINE_VISIBILITY
unordered_set()
_NOEXCEPT_(is_nothrow_default_constructible<__table>::value)
{
#if _LIBCPP_DEBUG_LEVEL >= 2
__get_db()->__insert_c(this);
#endif
}
explicit unordered_set(size_type __n, const hasher& __hf = hasher(),
const key_equal& __eql = key_equal());
#if _LIBCPP_STD_VER > 11
inline _LIBCPP_INLINE_VISIBILITY
unordered_set(size_type __n, const allocator_type& __a)
: unordered_set(__n, hasher(), key_equal(), __a) {}
inline _LIBCPP_INLINE_VISIBILITY
unordered_set(size_type __n, const hasher& __hf, const allocator_type& __a)
: unordered_set(__n, __hf, key_equal(), __a) {}
#endif
unordered_set(size_type __n, const hasher& __hf, const key_equal& __eql,
const allocator_type& __a);
template <class _InputIterator>
unordered_set(_InputIterator __first, _InputIterator __last);
template <class _InputIterator>
unordered_set(_InputIterator __first, _InputIterator __last,
size_type __n, const hasher& __hf = hasher(),
const key_equal& __eql = key_equal());
template <class _InputIterator>
unordered_set(_InputIterator __first, _InputIterator __last,
size_type __n, const hasher& __hf, const key_equal& __eql,
const allocator_type& __a);
#if _LIBCPP_STD_VER > 11
template <class _InputIterator>
inline _LIBCPP_INLINE_VISIBILITY
unordered_set(_InputIterator __first, _InputIterator __last,
size_type __n, const allocator_type& __a)
: unordered_set(__first, __last, __n, hasher(), key_equal(), __a) {}
template <class _InputIterator>
unordered_set(_InputIterator __first, _InputIterator __last,
size_type __n, const hasher& __hf, const allocator_type& __a)
: unordered_set(__first, __last, __n, __hf, key_equal(), __a) {}
#endif
_LIBCPP_INLINE_VISIBILITY
explicit unordered_set(const allocator_type& __a);
unordered_set(const unordered_set& __u);
unordered_set(const unordered_set& __u, const allocator_type& __a);
#ifndef _LIBCPP_CXX03_LANG
_LIBCPP_INLINE_VISIBILITY
unordered_set(unordered_set&& __u)
_NOEXCEPT_(is_nothrow_move_constructible<__table>::value);
unordered_set(unordered_set&& __u, const allocator_type& __a);
unordered_set(initializer_list<value_type> __il);
unordered_set(initializer_list<value_type> __il, size_type __n,
const hasher& __hf = hasher(),
const key_equal& __eql = key_equal());
unordered_set(initializer_list<value_type> __il, size_type __n,
const hasher& __hf, const key_equal& __eql,
const allocator_type& __a);
#if _LIBCPP_STD_VER > 11
inline _LIBCPP_INLINE_VISIBILITY
unordered_set(initializer_list<value_type> __il, size_type __n,
const allocator_type& __a)
: unordered_set(__il, __n, hasher(), key_equal(), __a) {}
inline _LIBCPP_INLINE_VISIBILITY
unordered_set(initializer_list<value_type> __il, size_type __n,
const hasher& __hf, const allocator_type& __a)
: unordered_set(__il, __n, __hf, key_equal(), __a) {}
#endif
#endif // _LIBCPP_CXX03_LANG
_LIBCPP_INLINE_VISIBILITY
~unordered_set() {
static_assert(sizeof(__diagnose_unordered_container_requirements<_Value, _Hash, _Pred>(0)), "");
}
_LIBCPP_INLINE_VISIBILITY
unordered_set& operator=(const unordered_set& __u)
{
__table_ = __u.__table_;
return *this;
}
#ifndef _LIBCPP_CXX03_LANG
_LIBCPP_INLINE_VISIBILITY
unordered_set& operator=(unordered_set&& __u)
_NOEXCEPT_(is_nothrow_move_assignable<__table>::value);
_LIBCPP_INLINE_VISIBILITY
unordered_set& operator=(initializer_list<value_type> __il);
#endif // _LIBCPP_CXX03_LANG
_LIBCPP_INLINE_VISIBILITY
allocator_type get_allocator() const _NOEXCEPT
{return allocator_type(__table_.__node_alloc());}
_LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
bool empty() const _NOEXCEPT {return __table_.size() == 0;}
_LIBCPP_INLINE_VISIBILITY
size_type size() const _NOEXCEPT {return __table_.size();}
_LIBCPP_INLINE_VISIBILITY
size_type max_size() const _NOEXCEPT {return __table_.max_size();}
_LIBCPP_INLINE_VISIBILITY
iterator begin() _NOEXCEPT {return __table_.begin();}
_LIBCPP_INLINE_VISIBILITY
iterator end() _NOEXCEPT {return __table_.end();}
_LIBCPP_INLINE_VISIBILITY
const_iterator begin() const _NOEXCEPT {return __table_.begin();}
_LIBCPP_INLINE_VISIBILITY
const_iterator end() const _NOEXCEPT {return __table_.end();}
_LIBCPP_INLINE_VISIBILITY
const_iterator cbegin() const _NOEXCEPT {return __table_.begin();}
_LIBCPP_INLINE_VISIBILITY
const_iterator cend() const _NOEXCEPT {return __table_.end();}
#ifndef _LIBCPP_CXX03_LANG
template <class... _Args>
_LIBCPP_INLINE_VISIBILITY
pair<iterator, bool> emplace(_Args&&... __args)
{return __table_.__emplace_unique(_VSTD::forward<_Args>(__args)...);}
template <class... _Args>
_LIBCPP_INLINE_VISIBILITY
#if _LIBCPP_DEBUG_LEVEL >= 2
iterator emplace_hint(const_iterator __p, _Args&&... __args)
{
_LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this,
"unordered_set::emplace_hint(const_iterator, args...) called with an iterator not"
" referring to this unordered_set");
return __table_.__emplace_unique(_VSTD::forward<_Args>(__args)...).first;
}
#else
iterator emplace_hint(const_iterator, _Args&&... __args)
{return __table_.__emplace_unique(_VSTD::forward<_Args>(__args)...).first;}
#endif
_LIBCPP_INLINE_VISIBILITY
pair<iterator, bool> insert(value_type&& __x)
{return __table_.__insert_unique(_VSTD::move(__x));}
_LIBCPP_INLINE_VISIBILITY
#if _LIBCPP_DEBUG_LEVEL >= 2
iterator insert(const_iterator __p, value_type&& __x)
{
_LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this,
"unordered_set::insert(const_iterator, value_type&&) called with an iterator not"
" referring to this unordered_set");
return insert(_VSTD::move(__x)).first;
}
#else
iterator insert(const_iterator, value_type&& __x)
{return insert(_VSTD::move(__x)).first;}
#endif
_LIBCPP_INLINE_VISIBILITY
void insert(initializer_list<value_type> __il)
{insert(__il.begin(), __il.end());}
#endif // _LIBCPP_CXX03_LANG
_LIBCPP_INLINE_VISIBILITY
pair<iterator, bool> insert(const value_type& __x)
{return __table_.__insert_unique(__x);}
_LIBCPP_INLINE_VISIBILITY
#if _LIBCPP_DEBUG_LEVEL >= 2
iterator insert(const_iterator __p, const value_type& __x)
{
_LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this,
"unordered_set::insert(const_iterator, const value_type&) called with an iterator not"
" referring to this unordered_set");
return insert(__x).first;
}
#else
iterator insert(const_iterator, const value_type& __x)
{return insert(__x).first;}
#endif
template <class _InputIterator>
_LIBCPP_INLINE_VISIBILITY
void insert(_InputIterator __first, _InputIterator __last);
_LIBCPP_INLINE_VISIBILITY
iterator erase(const_iterator __p) {return __table_.erase(__p);}
_LIBCPP_INLINE_VISIBILITY
size_type erase(const key_type& __k) {return __table_.__erase_unique(__k);}
_LIBCPP_INLINE_VISIBILITY
iterator erase(const_iterator __first, const_iterator __last)
{return __table_.erase(__first, __last);}
_LIBCPP_INLINE_VISIBILITY
void clear() _NOEXCEPT {__table_.clear();}
#if _LIBCPP_STD_VER > 14
_LIBCPP_INLINE_VISIBILITY
insert_return_type insert(node_type&& __nh)
{
_LIBCPP_ASSERT(__nh.empty() || __nh.get_allocator() == get_allocator(),
"node_type with incompatible allocator passed to unordered_set::insert()");
return __table_.template __node_handle_insert_unique<
node_type, insert_return_type>(_VSTD::move(__nh));
}
_LIBCPP_INLINE_VISIBILITY
iterator insert(const_iterator __h, node_type&& __nh)
{
_LIBCPP_ASSERT(__nh.empty() || __nh.get_allocator() == get_allocator(),
"node_type with incompatible allocator passed to unordered_set::insert()");
return __table_.template __node_handle_insert_unique<node_type>(
__h, _VSTD::move(__nh));
}
_LIBCPP_INLINE_VISIBILITY
node_type extract(key_type const& __key)
{
return __table_.template __node_handle_extract<node_type>(__key);
}
_LIBCPP_INLINE_VISIBILITY
node_type extract(const_iterator __it)
{
return __table_.template __node_handle_extract<node_type>(__it);
}
template<class _H2, class _P2>
_LIBCPP_INLINE_VISIBILITY
void merge(unordered_set<key_type, _H2, _P2, allocator_type>& __source)
{
_LIBCPP_ASSERT(__source.get_allocator() == get_allocator(),
"merging container with incompatible allocator");
__table_.__node_handle_merge_unique(__source.__table_);
}
template<class _H2, class _P2>
_LIBCPP_INLINE_VISIBILITY
void merge(unordered_set<key_type, _H2, _P2, allocator_type>&& __source)
{
_LIBCPP_ASSERT(__source.get_allocator() == get_allocator(),
"merging container with incompatible allocator");
__table_.__node_handle_merge_unique(__source.__table_);
}
template<class _H2, class _P2>
_LIBCPP_INLINE_VISIBILITY
void merge(unordered_multiset<key_type, _H2, _P2, allocator_type>& __source)
{
_LIBCPP_ASSERT(__source.get_allocator() == get_allocator(),
"merging container with incompatible allocator");
__table_.__node_handle_merge_unique(__source.__table_);
}
template<class _H2, class _P2>
_LIBCPP_INLINE_VISIBILITY
void merge(unordered_multiset<key_type, _H2, _P2, allocator_type>&& __source)
{
_LIBCPP_ASSERT(__source.get_allocator() == get_allocator(),
"merging container with incompatible allocator");
__table_.__node_handle_merge_unique(__source.__table_);
}
#endif
_LIBCPP_INLINE_VISIBILITY
void swap(unordered_set& __u)
_NOEXCEPT_(__is_nothrow_swappable<__table>::value)
{__table_.swap(__u.__table_);}
_LIBCPP_INLINE_VISIBILITY
hasher hash_function() const {return __table_.hash_function();}
_LIBCPP_INLINE_VISIBILITY
key_equal key_eq() const {return __table_.key_eq();}
_LIBCPP_INLINE_VISIBILITY
iterator find(const key_type& __k) {return __table_.find(__k);}
_LIBCPP_INLINE_VISIBILITY
const_iterator find(const key_type& __k) const {return __table_.find(__k);}
_LIBCPP_INLINE_VISIBILITY
size_type count(const key_type& __k) const {return __table_.__count_unique(__k);}
#if _LIBCPP_STD_VER > 17
_LIBCPP_INLINE_VISIBILITY
bool contains(const key_type& __k) const {return find(__k) != end();}
#endif // _LIBCPP_STD_VER > 17
_LIBCPP_INLINE_VISIBILITY
pair<iterator, iterator> equal_range(const key_type& __k)
{return __table_.__equal_range_unique(__k);}
_LIBCPP_INLINE_VISIBILITY
pair<const_iterator, const_iterator> equal_range(const key_type& __k) const
{return __table_.__equal_range_unique(__k);}
_LIBCPP_INLINE_VISIBILITY
size_type bucket_count() const _NOEXCEPT {return __table_.bucket_count();}
_LIBCPP_INLINE_VISIBILITY
size_type max_bucket_count() const _NOEXCEPT {return __table_.max_bucket_count();}
_LIBCPP_INLINE_VISIBILITY
size_type bucket_size(size_type __n) const {return __table_.bucket_size(__n);}
_LIBCPP_INLINE_VISIBILITY
size_type bucket(const key_type& __k) const {return __table_.bucket(__k);}
_LIBCPP_INLINE_VISIBILITY
local_iterator begin(size_type __n) {return __table_.begin(__n);}
_LIBCPP_INLINE_VISIBILITY
local_iterator end(size_type __n) {return __table_.end(__n);}
_LIBCPP_INLINE_VISIBILITY
const_local_iterator begin(size_type __n) const {return __table_.cbegin(__n);}
_LIBCPP_INLINE_VISIBILITY
const_local_iterator end(size_type __n) const {return __table_.cend(__n);}
_LIBCPP_INLINE_VISIBILITY
const_local_iterator cbegin(size_type __n) const {return __table_.cbegin(__n);}
_LIBCPP_INLINE_VISIBILITY
const_local_iterator cend(size_type __n) const {return __table_.cend(__n);}
_LIBCPP_INLINE_VISIBILITY
float load_factor() const _NOEXCEPT {return __table_.load_factor();}
_LIBCPP_INLINE_VISIBILITY
float max_load_factor() const _NOEXCEPT {return __table_.max_load_factor();}
_LIBCPP_INLINE_VISIBILITY
void max_load_factor(float __mlf) {__table_.max_load_factor(__mlf);}
_LIBCPP_INLINE_VISIBILITY
void rehash(size_type __n) {__table_.rehash(__n);}
_LIBCPP_INLINE_VISIBILITY
void reserve(size_type __n) {__table_.reserve(__n);}
#if _LIBCPP_DEBUG_LEVEL >= 2
bool __dereferenceable(const const_iterator* __i) const
{return __table_.__dereferenceable(__i);}
bool __decrementable(const const_iterator* __i) const
{return __table_.__decrementable(__i);}
bool __addable(const const_iterator* __i, ptrdiff_t __n) const
{return __table_.__addable(__i, __n);}
bool __subscriptable(const const_iterator* __i, ptrdiff_t __n) const
{return __table_.__addable(__i, __n);}
#endif // _LIBCPP_DEBUG_LEVEL >= 2
};
#ifndef _LIBCPP_HAS_NO_DEDUCTION_GUIDES
template<class _InputIterator,
class _Hash = hash<__iter_value_type<_InputIterator>>,
class _Pred = equal_to<__iter_value_type<_InputIterator>>,
class _Allocator = allocator<__iter_value_type<_InputIterator>>,
class = _EnableIf<!__is_allocator<_Hash>::value>,
class = _EnableIf<!is_integral<_Hash>::value>,
class = _EnableIf<!__is_allocator<_Pred>::value>,
class = _EnableIf<__is_allocator<_Allocator>::value>>
unordered_set(_InputIterator, _InputIterator, typename allocator_traits<_Allocator>::size_type = 0,
_Hash = _Hash(), _Pred = _Pred(), _Allocator = _Allocator())
-> unordered_set<__iter_value_type<_InputIterator>, _Hash, _Pred, _Allocator>;
template<class _Tp, class _Hash = hash<_Tp>,
class _Pred = equal_to<_Tp>,
class _Allocator = allocator<_Tp>,
class = _EnableIf<!__is_allocator<_Hash>::value>,
class = _EnableIf<!is_integral<_Hash>::value>,
class = _EnableIf<!__is_allocator<_Pred>::value>,
class = _EnableIf<__is_allocator<_Allocator>::value>>
unordered_set(initializer_list<_Tp>, typename allocator_traits<_Allocator>::size_type = 0,
_Hash = _Hash(), _Pred = _Pred(), _Allocator = _Allocator())
-> unordered_set<_Tp, _Hash, _Pred, _Allocator>;
template<class _InputIterator, class _Allocator,
class = _EnableIf<__is_allocator<_Allocator>::value>>
unordered_set(_InputIterator, _InputIterator,
typename allocator_traits<_Allocator>::size_type, _Allocator)
-> unordered_set<__iter_value_type<_InputIterator>,
hash<__iter_value_type<_InputIterator>>,
equal_to<__iter_value_type<_InputIterator>>,
_Allocator>;
template<class _InputIterator, class _Hash, class _Allocator,
class = _EnableIf<!__is_allocator<_Hash>::value>,
class = _EnableIf<!is_integral<_Hash>::value>,
class = _EnableIf<__is_allocator<_Allocator>::value>>
unordered_set(_InputIterator, _InputIterator,
typename allocator_traits<_Allocator>::size_type, _Hash, _Allocator)
-> unordered_set<__iter_value_type<_InputIterator>, _Hash,
equal_to<__iter_value_type<_InputIterator>>,
_Allocator>;
template<class _Tp, class _Allocator,
class = _EnableIf<__is_allocator<_Allocator>::value>>
unordered_set(initializer_list<_Tp>, typename allocator_traits<_Allocator>::size_type, _Allocator)
-> unordered_set<_Tp, hash<_Tp>, equal_to<_Tp>, _Allocator>;
template<class _Tp, class _Hash, class _Allocator,
class = _EnableIf<!__is_allocator<_Hash>::value>,
class = _EnableIf<!is_integral<_Hash>::value>,
class = _EnableIf<__is_allocator<_Allocator>::value>>
unordered_set(initializer_list<_Tp>, typename allocator_traits<_Allocator>::size_type, _Hash, _Allocator)
-> unordered_set<_Tp, _Hash, equal_to<_Tp>, _Allocator>;
#endif
template <class _Value, class _Hash, class _Pred, class _Alloc>
unordered_set<_Value, _Hash, _Pred, _Alloc>::unordered_set(size_type __n,
const hasher& __hf, const key_equal& __eql)
: __table_(__hf, __eql)
{
#if _LIBCPP_DEBUG_LEVEL >= 2
__get_db()->__insert_c(this);
#endif
__table_.rehash(__n);
}
template <class _Value, class _Hash, class _Pred, class _Alloc>
unordered_set<_Value, _Hash, _Pred, _Alloc>::unordered_set(size_type __n,
const hasher& __hf, const key_equal& __eql, const allocator_type& __a)
: __table_(__hf, __eql, __a)
{
#if _LIBCPP_DEBUG_LEVEL >= 2
__get_db()->__insert_c(this);
#endif
__table_.rehash(__n);
}
template <class _Value, class _Hash, class _Pred, class _Alloc>
template <class _InputIterator>
unordered_set<_Value, _Hash, _Pred, _Alloc>::unordered_set(
_InputIterator __first, _InputIterator __last)
{
#if _LIBCPP_DEBUG_LEVEL >= 2
__get_db()->__insert_c(this);
#endif
insert(__first, __last);
}
template <class _Value, class _Hash, class _Pred, class _Alloc>
template <class _InputIterator>
unordered_set<_Value, _Hash, _Pred, _Alloc>::unordered_set(
_InputIterator __first, _InputIterator __last, size_type __n,
const hasher& __hf, const key_equal& __eql)
: __table_(__hf, __eql)
{
#if _LIBCPP_DEBUG_LEVEL >= 2
__get_db()->__insert_c(this);
#endif
__table_.rehash(__n);
insert(__first, __last);
}
template <class _Value, class _Hash, class _Pred, class _Alloc>
template <class _InputIterator>
unordered_set<_Value, _Hash, _Pred, _Alloc>::unordered_set(
_InputIterator __first, _InputIterator __last, size_type __n,
const hasher& __hf, const key_equal& __eql, const allocator_type& __a)
: __table_(__hf, __eql, __a)
{
#if _LIBCPP_DEBUG_LEVEL >= 2
__get_db()->__insert_c(this);
#endif
__table_.rehash(__n);
insert(__first, __last);
}
template <class _Value, class _Hash, class _Pred, class _Alloc>
inline
unordered_set<_Value, _Hash, _Pred, _Alloc>::unordered_set(
const allocator_type& __a)
: __table_(__a)
{
#if _LIBCPP_DEBUG_LEVEL >= 2
__get_db()->__insert_c(this);
#endif
}
template <class _Value, class _Hash, class _Pred, class _Alloc>
unordered_set<_Value, _Hash, _Pred, _Alloc>::unordered_set(
const unordered_set& __u)
: __table_(__u.__table_)
{
#if _LIBCPP_DEBUG_LEVEL >= 2
__get_db()->__insert_c(this);
#endif
__table_.rehash(__u.bucket_count());
insert(__u.begin(), __u.end());
}
template <class _Value, class _Hash, class _Pred, class _Alloc>
unordered_set<_Value, _Hash, _Pred, _Alloc>::unordered_set(
const unordered_set& __u, const allocator_type& __a)
: __table_(__u.__table_, __a)
{
#if _LIBCPP_DEBUG_LEVEL >= 2
__get_db()->__insert_c(this);
#endif
__table_.rehash(__u.bucket_count());
insert(__u.begin(), __u.end());
}
#ifndef _LIBCPP_CXX03_LANG
template <class _Value, class _Hash, class _Pred, class _Alloc>
inline
unordered_set<_Value, _Hash, _Pred, _Alloc>::unordered_set(
unordered_set&& __u)
_NOEXCEPT_(is_nothrow_move_constructible<__table>::value)
: __table_(_VSTD::move(__u.__table_))
{
#if _LIBCPP_DEBUG_LEVEL >= 2
__get_db()->__insert_c(this);
__get_db()->swap(this, &__u);
#endif
}
template <class _Value, class _Hash, class _Pred, class _Alloc>
unordered_set<_Value, _Hash, _Pred, _Alloc>::unordered_set(
unordered_set&& __u, const allocator_type& __a)
: __table_(_VSTD::move(__u.__table_), __a)
{
#if _LIBCPP_DEBUG_LEVEL >= 2
__get_db()->__insert_c(this);
#endif
if (__a != __u.get_allocator())
{
iterator __i = __u.begin();
while (__u.size() != 0)
__table_.__insert_unique(_VSTD::move(__u.__table_.remove(__i++)->__value_));
}
#if _LIBCPP_DEBUG_LEVEL >= 2
else
__get_db()->swap(this, &__u);
#endif
}
template <class _Value, class _Hash, class _Pred, class _Alloc>
unordered_set<_Value, _Hash, _Pred, _Alloc>::unordered_set(
initializer_list<value_type> __il)
{
#if _LIBCPP_DEBUG_LEVEL >= 2
__get_db()->__insert_c(this);
#endif
insert(__il.begin(), __il.end());
}
template <class _Value, class _Hash, class _Pred, class _Alloc>
unordered_set<_Value, _Hash, _Pred, _Alloc>::unordered_set(
initializer_list<value_type> __il, size_type __n, const hasher& __hf,
const key_equal& __eql)
: __table_(__hf, __eql)
{
#if _LIBCPP_DEBUG_LEVEL >= 2
__get_db()->__insert_c(this);
#endif
__table_.rehash(__n);
insert(__il.begin(), __il.end());
}
template <class _Value, class _Hash, class _Pred, class _Alloc>
unordered_set<_Value, _Hash, _Pred, _Alloc>::unordered_set(
initializer_list<value_type> __il, size_type __n, const hasher& __hf,
const key_equal& __eql, const allocator_type& __a)
: __table_(__hf, __eql, __a)
{
#if _LIBCPP_DEBUG_LEVEL >= 2
__get_db()->__insert_c(this);
#endif
__table_.rehash(__n);
insert(__il.begin(), __il.end());
}
template <class _Value, class _Hash, class _Pred, class _Alloc>
inline
unordered_set<_Value, _Hash, _Pred, _Alloc>&
unordered_set<_Value, _Hash, _Pred, _Alloc>::operator=(unordered_set&& __u)
_NOEXCEPT_(is_nothrow_move_assignable<__table>::value)
{
__table_ = _VSTD::move(__u.__table_);
return *this;
}
template <class _Value, class _Hash, class _Pred, class _Alloc>
inline
unordered_set<_Value, _Hash, _Pred, _Alloc>&
unordered_set<_Value, _Hash, _Pred, _Alloc>::operator=(
initializer_list<value_type> __il)
{
__table_.__assign_unique(__il.begin(), __il.end());
return *this;
}
#endif // _LIBCPP_CXX03_LANG
template <class _Value, class _Hash, class _Pred, class _Alloc>
template <class _InputIterator>
inline
void
unordered_set<_Value, _Hash, _Pred, _Alloc>::insert(_InputIterator __first,
_InputIterator __last)
{
for (; __first != __last; ++__first)
__table_.__insert_unique(*__first);
}
template <class _Value, class _Hash, class _Pred, class _Alloc>
inline _LIBCPP_INLINE_VISIBILITY
void
swap(unordered_set<_Value, _Hash, _Pred, _Alloc>& __x,
unordered_set<_Value, _Hash, _Pred, _Alloc>& __y)
_NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
{
__x.swap(__y);
}
#if _LIBCPP_STD_VER > 17
template <class _Value, class _Hash, class _Pred, class _Alloc, class _Predicate>
inline _LIBCPP_INLINE_VISIBILITY
void erase_if(unordered_set<_Value, _Hash, _Pred, _Alloc>& __c, _Predicate __pred)
{ __libcpp_erase_if_container(__c, __pred); }
#endif
template <class _Value, class _Hash, class _Pred, class _Alloc>
bool
operator==(const unordered_set<_Value, _Hash, _Pred, _Alloc>& __x,
const unordered_set<_Value, _Hash, _Pred, _Alloc>& __y)
{
if (__x.size() != __y.size())
return false;
typedef typename unordered_set<_Value, _Hash, _Pred, _Alloc>::const_iterator
const_iterator;
for (const_iterator __i = __x.begin(), __ex = __x.end(), __ey = __y.end();
__i != __ex; ++__i)
{
const_iterator __j = __y.find(*__i);
if (__j == __ey || !(*__i == *__j))
return false;
}
return true;
}
template <class _Value, class _Hash, class _Pred, class _Alloc>
inline _LIBCPP_INLINE_VISIBILITY
bool
operator!=(const unordered_set<_Value, _Hash, _Pred, _Alloc>& __x,
const unordered_set<_Value, _Hash, _Pred, _Alloc>& __y)
{
return !(__x == __y);
}
template <class _Value, class _Hash = hash<_Value>, class _Pred = equal_to<_Value>,
class _Alloc = allocator<_Value> >
class _LIBCPP_TEMPLATE_VIS unordered_multiset
{
public:
// types
typedef _Value key_type;
typedef key_type value_type;
typedef typename __identity<_Hash>::type hasher;
typedef typename __identity<_Pred>::type key_equal;
typedef typename __identity<_Alloc>::type allocator_type;
typedef value_type& reference;
typedef const value_type& const_reference;
static_assert((is_same<value_type, typename allocator_type::value_type>::value),
"Invalid allocator::value_type");
private:
typedef __hash_table<value_type, hasher, key_equal, allocator_type> __table;
__table __table_;
public:
typedef typename __table::pointer pointer;
typedef typename __table::const_pointer const_pointer;
typedef typename __table::size_type size_type;
typedef typename __table::difference_type difference_type;
typedef typename __table::const_iterator iterator;
typedef typename __table::const_iterator const_iterator;
typedef typename __table::const_local_iterator local_iterator;
typedef typename __table::const_local_iterator const_local_iterator;
#if _LIBCPP_STD_VER > 14
typedef __set_node_handle<typename __table::__node, allocator_type> node_type;
#endif
template <class _Value2, class _Hash2, class _Pred2, class _Alloc2>
friend class _LIBCPP_TEMPLATE_VIS unordered_set;
template <class _Value2, class _Hash2, class _Pred2, class _Alloc2>
friend class _LIBCPP_TEMPLATE_VIS unordered_multiset;
_LIBCPP_INLINE_VISIBILITY
unordered_multiset()
_NOEXCEPT_(is_nothrow_default_constructible<__table>::value)
{
#if _LIBCPP_DEBUG_LEVEL >= 2
__get_db()->__insert_c(this);
#endif
}
explicit unordered_multiset(size_type __n, const hasher& __hf = hasher(),
const key_equal& __eql = key_equal());
unordered_multiset(size_type __n, const hasher& __hf,
const key_equal& __eql, const allocator_type& __a);
#if _LIBCPP_STD_VER > 11
inline _LIBCPP_INLINE_VISIBILITY
unordered_multiset(size_type __n, const allocator_type& __a)
: unordered_multiset(__n, hasher(), key_equal(), __a) {}
inline _LIBCPP_INLINE_VISIBILITY
unordered_multiset(size_type __n, const hasher& __hf, const allocator_type& __a)
: unordered_multiset(__n, __hf, key_equal(), __a) {}
#endif
template <class _InputIterator>
unordered_multiset(_InputIterator __first, _InputIterator __last);
template <class _InputIterator>
unordered_multiset(_InputIterator __first, _InputIterator __last,
size_type __n, const hasher& __hf = hasher(),
const key_equal& __eql = key_equal());
template <class _InputIterator>
unordered_multiset(_InputIterator __first, _InputIterator __last,
size_type __n , const hasher& __hf,
const key_equal& __eql, const allocator_type& __a);
#if _LIBCPP_STD_VER > 11
template <class _InputIterator>
inline _LIBCPP_INLINE_VISIBILITY
unordered_multiset(_InputIterator __first, _InputIterator __last,
size_type __n, const allocator_type& __a)
: unordered_multiset(__first, __last, __n, hasher(), key_equal(), __a) {}
template <class _InputIterator>
inline _LIBCPP_INLINE_VISIBILITY
unordered_multiset(_InputIterator __first, _InputIterator __last,
size_type __n, const hasher& __hf, const allocator_type& __a)
: unordered_multiset(__first, __last, __n, __hf, key_equal(), __a) {}
#endif
_LIBCPP_INLINE_VISIBILITY
explicit unordered_multiset(const allocator_type& __a);
unordered_multiset(const unordered_multiset& __u);
unordered_multiset(const unordered_multiset& __u, const allocator_type& __a);
#ifndef _LIBCPP_CXX03_LANG
_LIBCPP_INLINE_VISIBILITY
unordered_multiset(unordered_multiset&& __u)
_NOEXCEPT_(is_nothrow_move_constructible<__table>::value);
unordered_multiset(unordered_multiset&& __u, const allocator_type& __a);
unordered_multiset(initializer_list<value_type> __il);
unordered_multiset(initializer_list<value_type> __il, size_type __n,
const hasher& __hf = hasher(),
const key_equal& __eql = key_equal());
unordered_multiset(initializer_list<value_type> __il, size_type __n,
const hasher& __hf, const key_equal& __eql,
const allocator_type& __a);
#if _LIBCPP_STD_VER > 11
inline _LIBCPP_INLINE_VISIBILITY
unordered_multiset(initializer_list<value_type> __il, size_type __n, const allocator_type& __a)
: unordered_multiset(__il, __n, hasher(), key_equal(), __a) {}
inline _LIBCPP_INLINE_VISIBILITY
unordered_multiset(initializer_list<value_type> __il, size_type __n, const hasher& __hf, const allocator_type& __a)
: unordered_multiset(__il, __n, __hf, key_equal(), __a) {}
#endif
#endif // _LIBCPP_CXX03_LANG
_LIBCPP_INLINE_VISIBILITY
~unordered_multiset() {
static_assert(sizeof(__diagnose_unordered_container_requirements<_Value, _Hash, _Pred>(0)), "");
}
_LIBCPP_INLINE_VISIBILITY
unordered_multiset& operator=(const unordered_multiset& __u)
{
__table_ = __u.__table_;
return *this;
}
#ifndef _LIBCPP_CXX03_LANG
_LIBCPP_INLINE_VISIBILITY
unordered_multiset& operator=(unordered_multiset&& __u)
_NOEXCEPT_(is_nothrow_move_assignable<__table>::value);
unordered_multiset& operator=(initializer_list<value_type> __il);
#endif // _LIBCPP_CXX03_LANG
_LIBCPP_INLINE_VISIBILITY
allocator_type get_allocator() const _NOEXCEPT
{return allocator_type(__table_.__node_alloc());}
_LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
bool empty() const _NOEXCEPT {return __table_.size() == 0;}
_LIBCPP_INLINE_VISIBILITY
size_type size() const _NOEXCEPT {return __table_.size();}
_LIBCPP_INLINE_VISIBILITY
size_type max_size() const _NOEXCEPT {return __table_.max_size();}
_LIBCPP_INLINE_VISIBILITY
iterator begin() _NOEXCEPT {return __table_.begin();}
_LIBCPP_INLINE_VISIBILITY
iterator end() _NOEXCEPT {return __table_.end();}
_LIBCPP_INLINE_VISIBILITY
const_iterator begin() const _NOEXCEPT {return __table_.begin();}
_LIBCPP_INLINE_VISIBILITY
const_iterator end() const _NOEXCEPT {return __table_.end();}
_LIBCPP_INLINE_VISIBILITY
const_iterator cbegin() const _NOEXCEPT {return __table_.begin();}
_LIBCPP_INLINE_VISIBILITY
const_iterator cend() const _NOEXCEPT {return __table_.end();}
#ifndef _LIBCPP_CXX03_LANG
template <class... _Args>
_LIBCPP_INLINE_VISIBILITY
iterator emplace(_Args&&... __args)
{return __table_.__emplace_multi(_VSTD::forward<_Args>(__args)...);}
template <class... _Args>
_LIBCPP_INLINE_VISIBILITY
iterator emplace_hint(const_iterator __p, _Args&&... __args)
{return __table_.__emplace_hint_multi(__p, _VSTD::forward<_Args>(__args)...);}
_LIBCPP_INLINE_VISIBILITY
iterator insert(value_type&& __x) {return __table_.__insert_multi(_VSTD::move(__x));}
_LIBCPP_INLINE_VISIBILITY
iterator insert(const_iterator __p, value_type&& __x)
{return __table_.__insert_multi(__p, _VSTD::move(__x));}
_LIBCPP_INLINE_VISIBILITY
void insert(initializer_list<value_type> __il)
{insert(__il.begin(), __il.end());}
#endif // _LIBCPP_CXX03_LANG
_LIBCPP_INLINE_VISIBILITY
iterator insert(const value_type& __x) {return __table_.__insert_multi(__x);}
_LIBCPP_INLINE_VISIBILITY
iterator insert(const_iterator __p, const value_type& __x)
{return __table_.__insert_multi(__p, __x);}
template <class _InputIterator>
_LIBCPP_INLINE_VISIBILITY
void insert(_InputIterator __first, _InputIterator __last);
#if _LIBCPP_STD_VER > 14
_LIBCPP_INLINE_VISIBILITY
iterator insert(node_type&& __nh)
{
_LIBCPP_ASSERT(__nh.empty() || __nh.get_allocator() == get_allocator(),
"node_type with incompatible allocator passed to unordered_multiset::insert()");
return __table_.template __node_handle_insert_multi<node_type>(
_VSTD::move(__nh));
}
_LIBCPP_INLINE_VISIBILITY
iterator insert(const_iterator __hint, node_type&& __nh)
{
_LIBCPP_ASSERT(__nh.empty() || __nh.get_allocator() == get_allocator(),
"node_type with incompatible allocator passed to unordered_multiset::insert()");
return __table_.template __node_handle_insert_multi<node_type>(
__hint, _VSTD::move(__nh));
}
_LIBCPP_INLINE_VISIBILITY
node_type extract(const_iterator __position)
{
return __table_.template __node_handle_extract<node_type>(
__position);
}
_LIBCPP_INLINE_VISIBILITY
node_type extract(key_type const& __key)
{
return __table_.template __node_handle_extract<node_type>(__key);
}
template <class _H2, class _P2>
_LIBCPP_INLINE_VISIBILITY
void merge(unordered_multiset<key_type, _H2, _P2, allocator_type>& __source)
{
_LIBCPP_ASSERT(__source.get_allocator() == get_allocator(),
"merging container with incompatible allocator");
return __table_.__node_handle_merge_multi(__source.__table_);
}
template <class _H2, class _P2>
_LIBCPP_INLINE_VISIBILITY
void merge(unordered_multiset<key_type, _H2, _P2, allocator_type>&& __source)
{
_LIBCPP_ASSERT(__source.get_allocator() == get_allocator(),
"merging container with incompatible allocator");
return __table_.__node_handle_merge_multi(__source.__table_);
}
template <class _H2, class _P2>
_LIBCPP_INLINE_VISIBILITY
void merge(unordered_set<key_type, _H2, _P2, allocator_type>& __source)
{
_LIBCPP_ASSERT(__source.get_allocator() == get_allocator(),
"merging container with incompatible allocator");
return __table_.__node_handle_merge_multi(__source.__table_);
}
template <class _H2, class _P2>
_LIBCPP_INLINE_VISIBILITY
void merge(unordered_set<key_type, _H2, _P2, allocator_type>&& __source)
{
_LIBCPP_ASSERT(__source.get_allocator() == get_allocator(),
"merging container with incompatible allocator");
return __table_.__node_handle_merge_multi(__source.__table_);
}
#endif
_LIBCPP_INLINE_VISIBILITY
iterator erase(const_iterator __p) {return __table_.erase(__p);}
_LIBCPP_INLINE_VISIBILITY
size_type erase(const key_type& __k) {return __table_.__erase_multi(__k);}
_LIBCPP_INLINE_VISIBILITY
iterator erase(const_iterator __first, const_iterator __last)
{return __table_.erase(__first, __last);}
_LIBCPP_INLINE_VISIBILITY
void clear() _NOEXCEPT {__table_.clear();}
_LIBCPP_INLINE_VISIBILITY
void swap(unordered_multiset& __u)
_NOEXCEPT_(__is_nothrow_swappable<__table>::value)
{__table_.swap(__u.__table_);}
_LIBCPP_INLINE_VISIBILITY
hasher hash_function() const {return __table_.hash_function();}
_LIBCPP_INLINE_VISIBILITY
key_equal key_eq() const {return __table_.key_eq();}
_LIBCPP_INLINE_VISIBILITY
iterator find(const key_type& __k) {return __table_.find(__k);}
_LIBCPP_INLINE_VISIBILITY
const_iterator find(const key_type& __k) const {return __table_.find(__k);}
_LIBCPP_INLINE_VISIBILITY
size_type count(const key_type& __k) const {return __table_.__count_multi(__k);}
#if _LIBCPP_STD_VER > 17
_LIBCPP_INLINE_VISIBILITY
bool contains(const key_type& __k) const {return find(__k) != end();}
#endif // _LIBCPP_STD_VER > 17
_LIBCPP_INLINE_VISIBILITY
pair<iterator, iterator> equal_range(const key_type& __k)
{return __table_.__equal_range_multi(__k);}
_LIBCPP_INLINE_VISIBILITY
pair<const_iterator, const_iterator> equal_range(const key_type& __k) const
{return __table_.__equal_range_multi(__k);}
_LIBCPP_INLINE_VISIBILITY
size_type bucket_count() const _NOEXCEPT {return __table_.bucket_count();}
_LIBCPP_INLINE_VISIBILITY
size_type max_bucket_count() const _NOEXCEPT {return __table_.max_bucket_count();}
_LIBCPP_INLINE_VISIBILITY
size_type bucket_size(size_type __n) const {return __table_.bucket_size(__n);}
_LIBCPP_INLINE_VISIBILITY
size_type bucket(const key_type& __k) const {return __table_.bucket(__k);}
_LIBCPP_INLINE_VISIBILITY
local_iterator begin(size_type __n) {return __table_.begin(__n);}
_LIBCPP_INLINE_VISIBILITY
local_iterator end(size_type __n) {return __table_.end(__n);}
_LIBCPP_INLINE_VISIBILITY
const_local_iterator begin(size_type __n) const {return __table_.cbegin(__n);}
_LIBCPP_INLINE_VISIBILITY
const_local_iterator end(size_type __n) const {return __table_.cend(__n);}
_LIBCPP_INLINE_VISIBILITY
const_local_iterator cbegin(size_type __n) const {return __table_.cbegin(__n);}
_LIBCPP_INLINE_VISIBILITY
const_local_iterator cend(size_type __n) const {return __table_.cend(__n);}
_LIBCPP_INLINE_VISIBILITY
float load_factor() const _NOEXCEPT {return __table_.load_factor();}
_LIBCPP_INLINE_VISIBILITY
float max_load_factor() const _NOEXCEPT {return __table_.max_load_factor();}
_LIBCPP_INLINE_VISIBILITY
void max_load_factor(float __mlf) {__table_.max_load_factor(__mlf);}
_LIBCPP_INLINE_VISIBILITY
void rehash(size_type __n) {__table_.rehash(__n);}
_LIBCPP_INLINE_VISIBILITY
void reserve(size_type __n) {__table_.reserve(__n);}
#if _LIBCPP_DEBUG_LEVEL >= 2
bool __dereferenceable(const const_iterator* __i) const
{return __table_.__dereferenceable(__i);}
bool __decrementable(const const_iterator* __i) const
{return __table_.__decrementable(__i);}
bool __addable(const const_iterator* __i, ptrdiff_t __n) const
{return __table_.__addable(__i, __n);}
bool __subscriptable(const const_iterator* __i, ptrdiff_t __n) const
{return __table_.__addable(__i, __n);}
#endif // _LIBCPP_DEBUG_LEVEL >= 2
};
#ifndef _LIBCPP_HAS_NO_DEDUCTION_GUIDES
template<class _InputIterator,
class _Hash = hash<__iter_value_type<_InputIterator>>,
class _Pred = equal_to<__iter_value_type<_InputIterator>>,
class _Allocator = allocator<__iter_value_type<_InputIterator>>,
class = _EnableIf<!__is_allocator<_Hash>::value>,
class = _EnableIf<!is_integral<_Hash>::value>,
class = _EnableIf<!__is_allocator<_Pred>::value>,
class = _EnableIf<__is_allocator<_Allocator>::value>>
unordered_multiset(_InputIterator, _InputIterator, typename allocator_traits<_Allocator>::size_type = 0,
_Hash = _Hash(), _Pred = _Pred(), _Allocator = _Allocator())
-> unordered_multiset<__iter_value_type<_InputIterator>, _Hash, _Pred, _Allocator>;
template<class _Tp, class _Hash = hash<_Tp>,
class _Pred = equal_to<_Tp>, class _Allocator = allocator<_Tp>,
class = _EnableIf<!__is_allocator<_Hash>::value>,
class = _EnableIf<!is_integral<_Hash>::value>,
class = _EnableIf<!__is_allocator<_Pred>::value>,
class = _EnableIf<__is_allocator<_Allocator>::value>>
unordered_multiset(initializer_list<_Tp>, typename allocator_traits<_Allocator>::size_type = 0,
_Hash = _Hash(), _Pred = _Pred(), _Allocator = _Allocator())
-> unordered_multiset<_Tp, _Hash, _Pred, _Allocator>;
template<class _InputIterator, class _Allocator,
class = _EnableIf<__is_allocator<_Allocator>::value>>
unordered_multiset(_InputIterator, _InputIterator, typename allocator_traits<_Allocator>::size_type, _Allocator)
-> unordered_multiset<__iter_value_type<_InputIterator>,
hash<__iter_value_type<_InputIterator>>,
equal_to<__iter_value_type<_InputIterator>>,
_Allocator>;
template<class _InputIterator, class _Hash, class _Allocator,
class = _EnableIf<!__is_allocator<_Hash>::value>,
class = _EnableIf<!is_integral<_Hash>::value>,
class = _EnableIf<__is_allocator<_Allocator>::value>>
unordered_multiset(_InputIterator, _InputIterator, typename allocator_traits<_Allocator>::size_type,
_Hash, _Allocator)
-> unordered_multiset<__iter_value_type<_InputIterator>, _Hash,
equal_to<__iter_value_type<_InputIterator>>,
_Allocator>;
template<class _Tp, class _Allocator,
class = _EnableIf<__is_allocator<_Allocator>::value>>
unordered_multiset(initializer_list<_Tp>, typename allocator_traits<_Allocator>::size_type, _Allocator)
-> unordered_multiset<_Tp, hash<_Tp>, equal_to<_Tp>, _Allocator>;
template<class _Tp, class _Hash, class _Allocator,
class = _EnableIf<!__is_allocator<_Hash>::value>,
class = _EnableIf<!is_integral<_Hash>::value>,
class = _EnableIf<__is_allocator<_Allocator>::value>>
unordered_multiset(initializer_list<_Tp>, typename allocator_traits<_Allocator>::size_type, _Hash, _Allocator)
-> unordered_multiset<_Tp, _Hash, equal_to<_Tp>, _Allocator>;
#endif
template <class _Value, class _Hash, class _Pred, class _Alloc>
unordered_multiset<_Value, _Hash, _Pred, _Alloc>::unordered_multiset(
size_type __n, const hasher& __hf, const key_equal& __eql)
: __table_(__hf, __eql)
{
#if _LIBCPP_DEBUG_LEVEL >= 2
__get_db()->__insert_c(this);
#endif
__table_.rehash(__n);
}
template <class _Value, class _Hash, class _Pred, class _Alloc>
unordered_multiset<_Value, _Hash, _Pred, _Alloc>::unordered_multiset(
size_type __n, const hasher& __hf, const key_equal& __eql,
const allocator_type& __a)
: __table_(__hf, __eql, __a)
{
#if _LIBCPP_DEBUG_LEVEL >= 2
__get_db()->__insert_c(this);
#endif
__table_.rehash(__n);
}
template <class _Value, class _Hash, class _Pred, class _Alloc>
template <class _InputIterator>
unordered_multiset<_Value, _Hash, _Pred, _Alloc>::unordered_multiset(
_InputIterator __first, _InputIterator __last)
{
#if _LIBCPP_DEBUG_LEVEL >= 2
__get_db()->__insert_c(this);
#endif
insert(__first, __last);
}
template <class _Value, class _Hash, class _Pred, class _Alloc>
template <class _InputIterator>
unordered_multiset<_Value, _Hash, _Pred, _Alloc>::unordered_multiset(
_InputIterator __first, _InputIterator __last, size_type __n,
const hasher& __hf, const key_equal& __eql)
: __table_(__hf, __eql)
{
#if _LIBCPP_DEBUG_LEVEL >= 2
__get_db()->__insert_c(this);
#endif
__table_.rehash(__n);
insert(__first, __last);
}
template <class _Value, class _Hash, class _Pred, class _Alloc>
template <class _InputIterator>
unordered_multiset<_Value, _Hash, _Pred, _Alloc>::unordered_multiset(
_InputIterator __first, _InputIterator __last, size_type __n,
const hasher& __hf, const key_equal& __eql, const allocator_type& __a)
: __table_(__hf, __eql, __a)
{
#if _LIBCPP_DEBUG_LEVEL >= 2
__get_db()->__insert_c(this);
#endif
__table_.rehash(__n);
insert(__first, __last);
}
template <class _Value, class _Hash, class _Pred, class _Alloc>
inline
unordered_multiset<_Value, _Hash, _Pred, _Alloc>::unordered_multiset(
const allocator_type& __a)
: __table_(__a)
{
#if _LIBCPP_DEBUG_LEVEL >= 2
__get_db()->__insert_c(this);
#endif
}
template <class _Value, class _Hash, class _Pred, class _Alloc>
unordered_multiset<_Value, _Hash, _Pred, _Alloc>::unordered_multiset(
const unordered_multiset& __u)
: __table_(__u.__table_)
{
#if _LIBCPP_DEBUG_LEVEL >= 2
__get_db()->__insert_c(this);
#endif
__table_.rehash(__u.bucket_count());
insert(__u.begin(), __u.end());
}
template <class _Value, class _Hash, class _Pred, class _Alloc>
unordered_multiset<_Value, _Hash, _Pred, _Alloc>::unordered_multiset(
const unordered_multiset& __u, const allocator_type& __a)
: __table_(__u.__table_, __a)
{
#if _LIBCPP_DEBUG_LEVEL >= 2
__get_db()->__insert_c(this);
#endif
__table_.rehash(__u.bucket_count());
insert(__u.begin(), __u.end());
}
#ifndef _LIBCPP_CXX03_LANG
template <class _Value, class _Hash, class _Pred, class _Alloc>
inline
unordered_multiset<_Value, _Hash, _Pred, _Alloc>::unordered_multiset(
unordered_multiset&& __u)
_NOEXCEPT_(is_nothrow_move_constructible<__table>::value)
: __table_(_VSTD::move(__u.__table_))
{
#if _LIBCPP_DEBUG_LEVEL >= 2
__get_db()->__insert_c(this);
__get_db()->swap(this, &__u);
#endif
}
template <class _Value, class _Hash, class _Pred, class _Alloc>
unordered_multiset<_Value, _Hash, _Pred, _Alloc>::unordered_multiset(
unordered_multiset&& __u, const allocator_type& __a)
: __table_(_VSTD::move(__u.__table_), __a)
{
#if _LIBCPP_DEBUG_LEVEL >= 2
__get_db()->__insert_c(this);
#endif
if (__a != __u.get_allocator())
{
iterator __i = __u.begin();
while (__u.size() != 0)
__table_.__insert_multi(_VSTD::move(__u.__table_.remove(__i++)->__value_));
}
#if _LIBCPP_DEBUG_LEVEL >= 2
else
__get_db()->swap(this, &__u);
#endif
}
template <class _Value, class _Hash, class _Pred, class _Alloc>
unordered_multiset<_Value, _Hash, _Pred, _Alloc>::unordered_multiset(
initializer_list<value_type> __il)
{
#if _LIBCPP_DEBUG_LEVEL >= 2
__get_db()->__insert_c(this);
#endif
insert(__il.begin(), __il.end());
}
template <class _Value, class _Hash, class _Pred, class _Alloc>
unordered_multiset<_Value, _Hash, _Pred, _Alloc>::unordered_multiset(
initializer_list<value_type> __il, size_type __n, const hasher& __hf,
const key_equal& __eql)
: __table_(__hf, __eql)
{
#if _LIBCPP_DEBUG_LEVEL >= 2
__get_db()->__insert_c(this);
#endif
__table_.rehash(__n);
insert(__il.begin(), __il.end());
}
template <class _Value, class _Hash, class _Pred, class _Alloc>
unordered_multiset<_Value, _Hash, _Pred, _Alloc>::unordered_multiset(
initializer_list<value_type> __il, size_type __n, const hasher& __hf,
const key_equal& __eql, const allocator_type& __a)
: __table_(__hf, __eql, __a)
{
#if _LIBCPP_DEBUG_LEVEL >= 2
__get_db()->__insert_c(this);
#endif
__table_.rehash(__n);
insert(__il.begin(), __il.end());
}
template <class _Value, class _Hash, class _Pred, class _Alloc>
inline
unordered_multiset<_Value, _Hash, _Pred, _Alloc>&
unordered_multiset<_Value, _Hash, _Pred, _Alloc>::operator=(
unordered_multiset&& __u)
_NOEXCEPT_(is_nothrow_move_assignable<__table>::value)
{
__table_ = _VSTD::move(__u.__table_);
return *this;
}
template <class _Value, class _Hash, class _Pred, class _Alloc>
inline
unordered_multiset<_Value, _Hash, _Pred, _Alloc>&
unordered_multiset<_Value, _Hash, _Pred, _Alloc>::operator=(
initializer_list<value_type> __il)
{
__table_.__assign_multi(__il.begin(), __il.end());
return *this;
}
#endif // _LIBCPP_CXX03_LANG
template <class _Value, class _Hash, class _Pred, class _Alloc>
template <class _InputIterator>
inline
void
unordered_multiset<_Value, _Hash, _Pred, _Alloc>::insert(_InputIterator __first,
_InputIterator __last)
{
for (; __first != __last; ++__first)
__table_.__insert_multi(*__first);
}
template <class _Value, class _Hash, class _Pred, class _Alloc>
inline _LIBCPP_INLINE_VISIBILITY
void
swap(unordered_multiset<_Value, _Hash, _Pred, _Alloc>& __x,
unordered_multiset<_Value, _Hash, _Pred, _Alloc>& __y)
_NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
{
__x.swap(__y);
}
#if _LIBCPP_STD_VER > 17
template <class _Value, class _Hash, class _Pred, class _Alloc, class _Predicate>
inline _LIBCPP_INLINE_VISIBILITY
void erase_if(unordered_multiset<_Value, _Hash, _Pred, _Alloc>& __c, _Predicate __pred)
{ __libcpp_erase_if_container(__c, __pred); }
#endif
template <class _Value, class _Hash, class _Pred, class _Alloc>
bool
operator==(const unordered_multiset<_Value, _Hash, _Pred, _Alloc>& __x,
const unordered_multiset<_Value, _Hash, _Pred, _Alloc>& __y)
{
if (__x.size() != __y.size())
return false;
typedef typename unordered_multiset<_Value, _Hash, _Pred, _Alloc>::const_iterator
const_iterator;
typedef pair<const_iterator, const_iterator> _EqRng;
for (const_iterator __i = __x.begin(), __ex = __x.end(); __i != __ex;)
{
_EqRng __xeq = __x.equal_range(*__i);
_EqRng __yeq = __y.equal_range(*__i);
if (_VSTD::distance(__xeq.first, __xeq.second) !=
_VSTD::distance(__yeq.first, __yeq.second) ||
!_VSTD::is_permutation(__xeq.first, __xeq.second, __yeq.first))
return false;
__i = __xeq.second;
}
return true;
}
template <class _Value, class _Hash, class _Pred, class _Alloc>
inline _LIBCPP_INLINE_VISIBILITY
bool
operator!=(const unordered_multiset<_Value, _Hash, _Pred, _Alloc>& __x,
const unordered_multiset<_Value, _Hash, _Pred, _Alloc>& __y)
{
return !(__x == __y);
}
_LIBCPP_END_NAMESPACE_STD
#endif // _LIBCPP_UNORDERED_SET
| 69,248 | 1,681 | jart/cosmopolitan | false |
cosmopolitan/third_party/libcxx/stdexcept_default.hh | //===--------------------- stdexcept_default.ipp --------------------------===//
//
// 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
//
//===----------------------------------------------------------------------===//
#include "third_party/libcxx/refstring.hh"
#include "third_party/libcxx/string"
static_assert(sizeof(std::__libcpp_refstring) == sizeof(const char*), "");
namespace std // purposefully not using versioning namespace
{
logic_error::logic_error(const string& msg) : __imp_(msg.c_str()) {}
logic_error::logic_error(const char* msg) : __imp_(msg) {}
logic_error::logic_error(const logic_error& le) _NOEXCEPT : __imp_(le.__imp_) {}
logic_error& logic_error::operator=(const logic_error& le) _NOEXCEPT {
__imp_ = le.__imp_;
return *this;
}
runtime_error::runtime_error(const string& msg) : __imp_(msg.c_str()) {}
runtime_error::runtime_error(const char* msg) : __imp_(msg) {}
runtime_error::runtime_error(const runtime_error& re) _NOEXCEPT
: __imp_(re.__imp_) {}
runtime_error& runtime_error::operator=(const runtime_error& re) _NOEXCEPT {
__imp_ = re.__imp_;
return *this;
}
#if !defined(_LIBCPPABI_VERSION) && !defined(LIBSTDCXX)
const char* logic_error::what() const _NOEXCEPT { return __imp_.c_str(); }
const char* runtime_error::what() const _NOEXCEPT { return __imp_.c_str(); }
logic_error::~logic_error() _NOEXCEPT {}
domain_error::~domain_error() _NOEXCEPT {}
invalid_argument::~invalid_argument() _NOEXCEPT {}
length_error::~length_error() _NOEXCEPT {}
out_of_range::~out_of_range() _NOEXCEPT {}
runtime_error::~runtime_error() _NOEXCEPT {}
range_error::~range_error() _NOEXCEPT {}
overflow_error::~overflow_error() _NOEXCEPT {}
underflow_error::~underflow_error() _NOEXCEPT {}
#endif
} // namespace std
| 1,906 | 60 | jart/cosmopolitan | false |
cosmopolitan/third_party/libcxx/future | // -*- C++ -*-
// clang-format off
//===--------------------------- future -----------------------------------===//
//
// 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_FUTURE
#define _LIBCPP_FUTURE
/*
future synopsis
namespace std
{
enum class future_errc
{
future_already_retrieved = 1,
promise_already_satisfied,
no_state,
broken_promise
};
enum class launch
{
async = 1,
deferred = 2,
any = async | deferred
};
enum class future_status
{
ready,
timeout,
deferred
};
template <> struct is_error_code_enum<future_errc> : public true_type { };
error_code make_error_code(future_errc e) noexcept;
error_condition make_error_condition(future_errc e) noexcept;
const error_category& future_category() noexcept;
class future_error
: public logic_error
{
public:
future_error(error_code ec); // exposition only
explicit future_error(future_errc); // C++17
const error_code& code() const noexcept;
const char* what() const noexcept;
};
template <class R>
class promise
{
public:
promise();
template <class Allocator>
promise(allocator_arg_t, const Allocator& a);
promise(promise&& rhs) noexcept;
promise(const promise& rhs) = delete;
~promise();
// assignment
promise& operator=(promise&& rhs) noexcept;
promise& operator=(const promise& rhs) = delete;
void swap(promise& other) noexcept;
// retrieving the result
future<R> get_future();
// setting the result
void set_value(const R& r);
void set_value(R&& r);
void set_exception(exception_ptr p);
// setting the result with deferred notification
void set_value_at_thread_exit(const R& r);
void set_value_at_thread_exit(R&& r);
void set_exception_at_thread_exit(exception_ptr p);
};
template <class R>
class promise<R&>
{
public:
promise();
template <class Allocator>
promise(allocator_arg_t, const Allocator& a);
promise(promise&& rhs) noexcept;
promise(const promise& rhs) = delete;
~promise();
// assignment
promise& operator=(promise&& rhs) noexcept;
promise& operator=(const promise& rhs) = delete;
void swap(promise& other) noexcept;
// retrieving the result
future<R&> get_future();
// setting the result
void set_value(R& r);
void set_exception(exception_ptr p);
// setting the result with deferred notification
void set_value_at_thread_exit(R&);
void set_exception_at_thread_exit(exception_ptr p);
};
template <>
class promise<void>
{
public:
promise();
template <class Allocator>
promise(allocator_arg_t, const Allocator& a);
promise(promise&& rhs) noexcept;
promise(const promise& rhs) = delete;
~promise();
// assignment
promise& operator=(promise&& rhs) noexcept;
promise& operator=(const promise& rhs) = delete;
void swap(promise& other) noexcept;
// retrieving the result
future<void> get_future();
// setting the result
void set_value();
void set_exception(exception_ptr p);
// setting the result with deferred notification
void set_value_at_thread_exit();
void set_exception_at_thread_exit(exception_ptr p);
};
template <class R> void swap(promise<R>& x, promise<R>& y) noexcept;
template <class R, class Alloc>
struct uses_allocator<promise<R>, Alloc> : public true_type {};
template <class R>
class future
{
public:
future() noexcept;
future(future&&) noexcept;
future(const future& rhs) = delete;
~future();
future& operator=(const future& rhs) = delete;
future& operator=(future&&) noexcept;
shared_future<R> share() noexcept;
// retrieving the value
R get();
// functions to check state
bool valid() const noexcept;
void wait() const;
template <class Rep, class Period>
future_status
wait_for(const chrono::duration<Rep, Period>& rel_time) const;
template <class Clock, class Duration>
future_status
wait_until(const chrono::time_point<Clock, Duration>& abs_time) const;
};
template <class R>
class future<R&>
{
public:
future() noexcept;
future(future&&) noexcept;
future(const future& rhs) = delete;
~future();
future& operator=(const future& rhs) = delete;
future& operator=(future&&) noexcept;
shared_future<R&> share() noexcept;
// retrieving the value
R& get();
// functions to check state
bool valid() const noexcept;
void wait() const;
template <class Rep, class Period>
future_status
wait_for(const chrono::duration<Rep, Period>& rel_time) const;
template <class Clock, class Duration>
future_status
wait_until(const chrono::time_point<Clock, Duration>& abs_time) const;
};
template <>
class future<void>
{
public:
future() noexcept;
future(future&&) noexcept;
future(const future& rhs) = delete;
~future();
future& operator=(const future& rhs) = delete;
future& operator=(future&&) noexcept;
shared_future<void> share() noexcept;
// retrieving the value
void get();
// functions to check state
bool valid() const noexcept;
void wait() const;
template <class Rep, class Period>
future_status
wait_for(const chrono::duration<Rep, Period>& rel_time) const;
template <class Clock, class Duration>
future_status
wait_until(const chrono::time_point<Clock, Duration>& abs_time) const;
};
template <class R>
class shared_future
{
public:
shared_future() noexcept;
shared_future(const shared_future& rhs);
shared_future(future<R>&&) noexcept;
shared_future(shared_future&& rhs) noexcept;
~shared_future();
shared_future& operator=(const shared_future& rhs);
shared_future& operator=(shared_future&& rhs) noexcept;
// retrieving the value
const R& get() const;
// functions to check state
bool valid() const noexcept;
void wait() const;
template <class Rep, class Period>
future_status
wait_for(const chrono::duration<Rep, Period>& rel_time) const;
template <class Clock, class Duration>
future_status
wait_until(const chrono::time_point<Clock, Duration>& abs_time) const;
};
template <class R>
class shared_future<R&>
{
public:
shared_future() noexcept;
shared_future(const shared_future& rhs);
shared_future(future<R&>&&) noexcept;
shared_future(shared_future&& rhs) noexcept;
~shared_future();
shared_future& operator=(const shared_future& rhs);
shared_future& operator=(shared_future&& rhs) noexcept;
// retrieving the value
R& get() const;
// functions to check state
bool valid() const noexcept;
void wait() const;
template <class Rep, class Period>
future_status
wait_for(const chrono::duration<Rep, Period>& rel_time) const;
template <class Clock, class Duration>
future_status
wait_until(const chrono::time_point<Clock, Duration>& abs_time) const;
};
template <>
class shared_future<void>
{
public:
shared_future() noexcept;
shared_future(const shared_future& rhs);
shared_future(future<void>&&) noexcept;
shared_future(shared_future&& rhs) noexcept;
~shared_future();
shared_future& operator=(const shared_future& rhs);
shared_future& operator=(shared_future&& rhs) noexcept;
// retrieving the value
void get() const;
// functions to check state
bool valid() const noexcept;
void wait() const;
template <class Rep, class Period>
future_status
wait_for(const chrono::duration<Rep, Period>& rel_time) const;
template <class Clock, class Duration>
future_status
wait_until(const chrono::time_point<Clock, Duration>& abs_time) const;
};
template <class F, class... Args>
future<typename result_of<typename decay<F>::type(typename decay<Args>::type...)>::type>
async(F&& f, Args&&... args);
template <class F, class... Args>
future<typename result_of<typename decay<F>::type(typename decay<Args>::type...)>::type>
async(launch policy, F&& f, Args&&... args);
template <class> class packaged_task; // undefined
template <class R, class... ArgTypes>
class packaged_task<R(ArgTypes...)>
{
public:
typedef R result_type; // extension
// construction and destruction
packaged_task() noexcept;
template <class F>
explicit packaged_task(F&& f);
template <class F, class Allocator>
packaged_task(allocator_arg_t, const Allocator& a, F&& f);
~packaged_task();
// no copy
packaged_task(const packaged_task&) = delete;
packaged_task& operator=(const packaged_task&) = delete;
// move support
packaged_task(packaged_task&& other) noexcept;
packaged_task& operator=(packaged_task&& other) noexcept;
void swap(packaged_task& other) noexcept;
bool valid() const noexcept;
// result retrieval
future<R> get_future();
// execution
void operator()(ArgTypes... );
void make_ready_at_thread_exit(ArgTypes...);
void reset();
};
template <class R>
void swap(packaged_task<R(ArgTypes...)&, packaged_task<R(ArgTypes...)>&) noexcept;
template <class R, class Alloc> struct uses_allocator<packaged_task<R>, Alloc>;
} // std
*/
#include "third_party/libcxx/__config"
#include "third_party/libcxx/system_error"
#include "third_party/libcxx/memory"
#include "third_party/libcxx/chrono"
#include "third_party/libcxx/exception"
#include "third_party/libcxx/mutex"
#include "third_party/libcxx/thread"
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
#pragma GCC system_header
#endif
#ifdef _LIBCPP_HAS_NO_THREADS
#error <future> is not supported on this single threaded system
#else // !_LIBCPP_HAS_NO_THREADS
_LIBCPP_BEGIN_NAMESPACE_STD
//enum class future_errc
_LIBCPP_DECLARE_STRONG_ENUM(future_errc)
{
future_already_retrieved = 1,
promise_already_satisfied,
no_state,
broken_promise
};
_LIBCPP_DECLARE_STRONG_ENUM_EPILOG(future_errc)
template <>
struct _LIBCPP_TEMPLATE_VIS is_error_code_enum<future_errc> : public true_type {};
#ifdef _LIBCPP_HAS_NO_STRONG_ENUMS
template <>
struct _LIBCPP_TEMPLATE_VIS is_error_code_enum<future_errc::__lx> : public true_type { };
#endif
//enum class launch
_LIBCPP_DECLARE_STRONG_ENUM(launch)
{
async = 1,
deferred = 2,
any = async | deferred
};
_LIBCPP_DECLARE_STRONG_ENUM_EPILOG(launch)
#ifndef _LIBCPP_HAS_NO_STRONG_ENUMS
typedef underlying_type<launch>::type __launch_underlying_type;
inline _LIBCPP_INLINE_VISIBILITY
_LIBCPP_CONSTEXPR
launch
operator&(launch __x, launch __y)
{
return static_cast<launch>(static_cast<__launch_underlying_type>(__x) &
static_cast<__launch_underlying_type>(__y));
}
inline _LIBCPP_INLINE_VISIBILITY
_LIBCPP_CONSTEXPR
launch
operator|(launch __x, launch __y)
{
return static_cast<launch>(static_cast<__launch_underlying_type>(__x) |
static_cast<__launch_underlying_type>(__y));
}
inline _LIBCPP_INLINE_VISIBILITY
_LIBCPP_CONSTEXPR
launch
operator^(launch __x, launch __y)
{
return static_cast<launch>(static_cast<__launch_underlying_type>(__x) ^
static_cast<__launch_underlying_type>(__y));
}
inline _LIBCPP_INLINE_VISIBILITY
_LIBCPP_CONSTEXPR
launch
operator~(launch __x)
{
return static_cast<launch>(~static_cast<__launch_underlying_type>(__x) & 3);
}
inline _LIBCPP_INLINE_VISIBILITY
launch&
operator&=(launch& __x, launch __y)
{
__x = __x & __y; return __x;
}
inline _LIBCPP_INLINE_VISIBILITY
launch&
operator|=(launch& __x, launch __y)
{
__x = __x | __y; return __x;
}
inline _LIBCPP_INLINE_VISIBILITY
launch&
operator^=(launch& __x, launch __y)
{
__x = __x ^ __y; return __x;
}
#endif // !_LIBCPP_HAS_NO_STRONG_ENUMS
//enum class future_status
_LIBCPP_DECLARE_STRONG_ENUM(future_status)
{
ready,
timeout,
deferred
};
_LIBCPP_DECLARE_STRONG_ENUM_EPILOG(future_status)
_LIBCPP_FUNC_VIS
const error_category& future_category() _NOEXCEPT;
inline _LIBCPP_INLINE_VISIBILITY
error_code
make_error_code(future_errc __e) _NOEXCEPT
{
return error_code(static_cast<int>(__e), future_category());
}
inline _LIBCPP_INLINE_VISIBILITY
error_condition
make_error_condition(future_errc __e) _NOEXCEPT
{
return error_condition(static_cast<int>(__e), future_category());
}
class _LIBCPP_EXCEPTION_ABI _LIBCPP_AVAILABILITY_FUTURE_ERROR future_error
: public logic_error
{
error_code __ec_;
public:
future_error(error_code __ec);
#if _LIBCPP_STD_VERS > 14
explicit future_error(future_errc _Ev) : logic_error(), __ec_(make_error_code(_Ev)) {}
#endif
_LIBCPP_INLINE_VISIBILITY
const error_code& code() const _NOEXCEPT {return __ec_;}
virtual ~future_error() _NOEXCEPT;
};
_LIBCPP_NORETURN inline _LIBCPP_INLINE_VISIBILITY
#ifndef _LIBCPP_NO_EXCEPTIONS
_LIBCPP_AVAILABILITY_FUTURE_ERROR
#endif
void __throw_future_error(future_errc _Ev)
{
#ifndef _LIBCPP_NO_EXCEPTIONS
throw future_error(make_error_code(_Ev));
#else
((void)_Ev);
_VSTD::abort();
#endif
}
class _LIBCPP_TYPE_VIS _LIBCPP_AVAILABILITY_FUTURE __assoc_sub_state
: public __shared_count
{
protected:
exception_ptr __exception_;
mutable mutex __mut_;
mutable condition_variable __cv_;
unsigned __state_;
virtual void __on_zero_shared() _NOEXCEPT;
void __sub_wait(unique_lock<mutex>& __lk);
public:
enum
{
__constructed = 1,
__future_attached = 2,
ready = 4,
deferred = 8
};
_LIBCPP_INLINE_VISIBILITY
__assoc_sub_state() : __state_(0) {}
_LIBCPP_INLINE_VISIBILITY
bool __has_value() const
{return (__state_ & __constructed) || (__exception_ != nullptr);}
_LIBCPP_INLINE_VISIBILITY
void __attach_future() {
lock_guard<mutex> __lk(__mut_);
bool __has_future_attached = (__state_ & __future_attached) != 0;
if (__has_future_attached)
__throw_future_error(future_errc::future_already_retrieved);
this->__add_shared();
__state_ |= __future_attached;
}
_LIBCPP_INLINE_VISIBILITY
void __set_deferred() {__state_ |= deferred;}
void __make_ready();
_LIBCPP_INLINE_VISIBILITY
bool __is_ready() const {return (__state_ & ready) != 0;}
void set_value();
void set_value_at_thread_exit();
void set_exception(exception_ptr __p);
void set_exception_at_thread_exit(exception_ptr __p);
void copy();
void wait();
template <class _Rep, class _Period>
future_status
_LIBCPP_INLINE_VISIBILITY
wait_for(const chrono::duration<_Rep, _Period>& __rel_time) const;
template <class _Clock, class _Duration>
_LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
future_status
wait_until(const chrono::time_point<_Clock, _Duration>& __abs_time) const;
virtual void __execute();
};
template <class _Clock, class _Duration>
future_status
__assoc_sub_state::wait_until(const chrono::time_point<_Clock, _Duration>& __abs_time) const
{
unique_lock<mutex> __lk(__mut_);
if (__state_ & deferred)
return future_status::deferred;
while (!(__state_ & ready) && _Clock::now() < __abs_time)
__cv_.wait_until(__lk, __abs_time);
if (__state_ & ready)
return future_status::ready;
return future_status::timeout;
}
template <class _Rep, class _Period>
inline
future_status
__assoc_sub_state::wait_for(const chrono::duration<_Rep, _Period>& __rel_time) const
{
return wait_until(chrono::steady_clock::now() + __rel_time);
}
template <class _Rp>
class _LIBCPP_AVAILABILITY_FUTURE __assoc_state
: public __assoc_sub_state
{
typedef __assoc_sub_state base;
typedef typename aligned_storage<sizeof(_Rp), alignment_of<_Rp>::value>::type _Up;
protected:
_Up __value_;
virtual void __on_zero_shared() _NOEXCEPT;
public:
template <class _Arg>
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
void set_value(_Arg&& __arg);
#else
void set_value(_Arg& __arg);
#endif
template <class _Arg>
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
void set_value_at_thread_exit(_Arg&& __arg);
#else
void set_value_at_thread_exit(_Arg& __arg);
#endif
_Rp move();
typename add_lvalue_reference<_Rp>::type copy();
};
template <class _Rp>
void
__assoc_state<_Rp>::__on_zero_shared() _NOEXCEPT
{
if (this->__state_ & base::__constructed)
reinterpret_cast<_Rp*>(&__value_)->~_Rp();
delete this;
}
template <class _Rp>
template <class _Arg>
_LIBCPP_AVAILABILITY_FUTURE
void
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
__assoc_state<_Rp>::set_value(_Arg&& __arg)
#else
__assoc_state<_Rp>::set_value(_Arg& __arg)
#endif
{
unique_lock<mutex> __lk(this->__mut_);
if (this->__has_value())
__throw_future_error(future_errc::promise_already_satisfied);
::new(&__value_) _Rp(_VSTD::forward<_Arg>(__arg));
this->__state_ |= base::__constructed | base::ready;
__cv_.notify_all();
}
template <class _Rp>
template <class _Arg>
void
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
__assoc_state<_Rp>::set_value_at_thread_exit(_Arg&& __arg)
#else
__assoc_state<_Rp>::set_value_at_thread_exit(_Arg& __arg)
#endif
{
unique_lock<mutex> __lk(this->__mut_);
if (this->__has_value())
__throw_future_error(future_errc::promise_already_satisfied);
::new(&__value_) _Rp(_VSTD::forward<_Arg>(__arg));
this->__state_ |= base::__constructed;
__thread_local_data()->__make_ready_at_thread_exit(this);
}
template <class _Rp>
_Rp
__assoc_state<_Rp>::move()
{
unique_lock<mutex> __lk(this->__mut_);
this->__sub_wait(__lk);
if (this->__exception_ != nullptr)
rethrow_exception(this->__exception_);
return _VSTD::move(*reinterpret_cast<_Rp*>(&__value_));
}
template <class _Rp>
typename add_lvalue_reference<_Rp>::type
__assoc_state<_Rp>::copy()
{
unique_lock<mutex> __lk(this->__mut_);
this->__sub_wait(__lk);
if (this->__exception_ != nullptr)
rethrow_exception(this->__exception_);
return *reinterpret_cast<_Rp*>(&__value_);
}
template <class _Rp>
class _LIBCPP_AVAILABILITY_FUTURE __assoc_state<_Rp&>
: public __assoc_sub_state
{
typedef __assoc_sub_state base;
typedef _Rp* _Up;
protected:
_Up __value_;
virtual void __on_zero_shared() _NOEXCEPT;
public:
void set_value(_Rp& __arg);
void set_value_at_thread_exit(_Rp& __arg);
_Rp& copy();
};
template <class _Rp>
void
__assoc_state<_Rp&>::__on_zero_shared() _NOEXCEPT
{
delete this;
}
template <class _Rp>
void
__assoc_state<_Rp&>::set_value(_Rp& __arg)
{
unique_lock<mutex> __lk(this->__mut_);
if (this->__has_value())
__throw_future_error(future_errc::promise_already_satisfied);
__value_ = _VSTD::addressof(__arg);
this->__state_ |= base::__constructed | base::ready;
__cv_.notify_all();
}
template <class _Rp>
void
__assoc_state<_Rp&>::set_value_at_thread_exit(_Rp& __arg)
{
unique_lock<mutex> __lk(this->__mut_);
if (this->__has_value())
__throw_future_error(future_errc::promise_already_satisfied);
__value_ = _VSTD::addressof(__arg);
this->__state_ |= base::__constructed;
__thread_local_data()->__make_ready_at_thread_exit(this);
}
template <class _Rp>
_Rp&
__assoc_state<_Rp&>::copy()
{
unique_lock<mutex> __lk(this->__mut_);
this->__sub_wait(__lk);
if (this->__exception_ != nullptr)
rethrow_exception(this->__exception_);
return *__value_;
}
template <class _Rp, class _Alloc>
class _LIBCPP_AVAILABILITY_FUTURE __assoc_state_alloc
: public __assoc_state<_Rp>
{
typedef __assoc_state<_Rp> base;
_Alloc __alloc_;
virtual void __on_zero_shared() _NOEXCEPT;
public:
_LIBCPP_INLINE_VISIBILITY
explicit __assoc_state_alloc(const _Alloc& __a)
: __alloc_(__a) {}
};
template <class _Rp, class _Alloc>
void
__assoc_state_alloc<_Rp, _Alloc>::__on_zero_shared() _NOEXCEPT
{
if (this->__state_ & base::__constructed)
reinterpret_cast<_Rp*>(_VSTD::addressof(this->__value_))->~_Rp();
typedef typename __allocator_traits_rebind<_Alloc, __assoc_state_alloc>::type _Al;
typedef allocator_traits<_Al> _ATraits;
typedef pointer_traits<typename _ATraits::pointer> _PTraits;
_Al __a(__alloc_);
this->~__assoc_state_alloc();
__a.deallocate(_PTraits::pointer_to(*this), 1);
}
template <class _Rp, class _Alloc>
class _LIBCPP_AVAILABILITY_FUTURE __assoc_state_alloc<_Rp&, _Alloc>
: public __assoc_state<_Rp&>
{
typedef __assoc_state<_Rp&> base;
_Alloc __alloc_;
virtual void __on_zero_shared() _NOEXCEPT;
public:
_LIBCPP_INLINE_VISIBILITY
explicit __assoc_state_alloc(const _Alloc& __a)
: __alloc_(__a) {}
};
template <class _Rp, class _Alloc>
void
__assoc_state_alloc<_Rp&, _Alloc>::__on_zero_shared() _NOEXCEPT
{
typedef typename __allocator_traits_rebind<_Alloc, __assoc_state_alloc>::type _Al;
typedef allocator_traits<_Al> _ATraits;
typedef pointer_traits<typename _ATraits::pointer> _PTraits;
_Al __a(__alloc_);
this->~__assoc_state_alloc();
__a.deallocate(_PTraits::pointer_to(*this), 1);
}
template <class _Alloc>
class _LIBCPP_AVAILABILITY_FUTURE __assoc_sub_state_alloc
: public __assoc_sub_state
{
typedef __assoc_sub_state base;
_Alloc __alloc_;
virtual void __on_zero_shared() _NOEXCEPT;
public:
_LIBCPP_INLINE_VISIBILITY
explicit __assoc_sub_state_alloc(const _Alloc& __a)
: __alloc_(__a) {}
};
template <class _Alloc>
void
__assoc_sub_state_alloc<_Alloc>::__on_zero_shared() _NOEXCEPT
{
typedef typename __allocator_traits_rebind<_Alloc, __assoc_sub_state_alloc>::type _Al;
typedef allocator_traits<_Al> _ATraits;
typedef pointer_traits<typename _ATraits::pointer> _PTraits;
_Al __a(__alloc_);
this->~__assoc_sub_state_alloc();
__a.deallocate(_PTraits::pointer_to(*this), 1);
}
template <class _Rp, class _Fp>
class _LIBCPP_AVAILABILITY_FUTURE __deferred_assoc_state
: public __assoc_state<_Rp>
{
typedef __assoc_state<_Rp> base;
_Fp __func_;
public:
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
_LIBCPP_INLINE_VISIBILITY
explicit __deferred_assoc_state(_Fp&& __f);
#endif
virtual void __execute();
};
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
template <class _Rp, class _Fp>
inline
__deferred_assoc_state<_Rp, _Fp>::__deferred_assoc_state(_Fp&& __f)
: __func_(_VSTD::forward<_Fp>(__f))
{
this->__set_deferred();
}
#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
template <class _Rp, class _Fp>
void
__deferred_assoc_state<_Rp, _Fp>::__execute()
{
#ifndef _LIBCPP_NO_EXCEPTIONS
try
{
#endif // _LIBCPP_NO_EXCEPTIONS
this->set_value(__func_());
#ifndef _LIBCPP_NO_EXCEPTIONS
}
catch (...)
{
this->set_exception(current_exception());
}
#endif // _LIBCPP_NO_EXCEPTIONS
}
template <class _Fp>
class _LIBCPP_AVAILABILITY_FUTURE __deferred_assoc_state<void, _Fp>
: public __assoc_sub_state
{
typedef __assoc_sub_state base;
_Fp __func_;
public:
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
_LIBCPP_INLINE_VISIBILITY
explicit __deferred_assoc_state(_Fp&& __f);
#endif
virtual void __execute();
};
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
template <class _Fp>
inline
__deferred_assoc_state<void, _Fp>::__deferred_assoc_state(_Fp&& __f)
: __func_(_VSTD::forward<_Fp>(__f))
{
this->__set_deferred();
}
#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
template <class _Fp>
void
__deferred_assoc_state<void, _Fp>::__execute()
{
#ifndef _LIBCPP_NO_EXCEPTIONS
try
{
#endif // _LIBCPP_NO_EXCEPTIONS
__func_();
this->set_value();
#ifndef _LIBCPP_NO_EXCEPTIONS
}
catch (...)
{
this->set_exception(current_exception());
}
#endif // _LIBCPP_NO_EXCEPTIONS
}
template <class _Rp, class _Fp>
class _LIBCPP_AVAILABILITY_FUTURE __async_assoc_state
: public __assoc_state<_Rp>
{
typedef __assoc_state<_Rp> base;
_Fp __func_;
virtual void __on_zero_shared() _NOEXCEPT;
public:
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
_LIBCPP_INLINE_VISIBILITY
explicit __async_assoc_state(_Fp&& __f);
#endif
virtual void __execute();
};
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
template <class _Rp, class _Fp>
inline
__async_assoc_state<_Rp, _Fp>::__async_assoc_state(_Fp&& __f)
: __func_(_VSTD::forward<_Fp>(__f))
{
}
#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
template <class _Rp, class _Fp>
void
__async_assoc_state<_Rp, _Fp>::__execute()
{
#ifndef _LIBCPP_NO_EXCEPTIONS
try
{
#endif // _LIBCPP_NO_EXCEPTIONS
this->set_value(__func_());
#ifndef _LIBCPP_NO_EXCEPTIONS
}
catch (...)
{
this->set_exception(current_exception());
}
#endif // _LIBCPP_NO_EXCEPTIONS
}
template <class _Rp, class _Fp>
void
__async_assoc_state<_Rp, _Fp>::__on_zero_shared() _NOEXCEPT
{
this->wait();
base::__on_zero_shared();
}
template <class _Fp>
class _LIBCPP_AVAILABILITY_FUTURE __async_assoc_state<void, _Fp>
: public __assoc_sub_state
{
typedef __assoc_sub_state base;
_Fp __func_;
virtual void __on_zero_shared() _NOEXCEPT;
public:
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
_LIBCPP_INLINE_VISIBILITY
explicit __async_assoc_state(_Fp&& __f);
#endif
virtual void __execute();
};
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
template <class _Fp>
inline
__async_assoc_state<void, _Fp>::__async_assoc_state(_Fp&& __f)
: __func_(_VSTD::forward<_Fp>(__f))
{
}
#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
template <class _Fp>
void
__async_assoc_state<void, _Fp>::__execute()
{
#ifndef _LIBCPP_NO_EXCEPTIONS
try
{
#endif // _LIBCPP_NO_EXCEPTIONS
__func_();
this->set_value();
#ifndef _LIBCPP_NO_EXCEPTIONS
}
catch (...)
{
this->set_exception(current_exception());
}
#endif // _LIBCPP_NO_EXCEPTIONS
}
template <class _Fp>
void
__async_assoc_state<void, _Fp>::__on_zero_shared() _NOEXCEPT
{
this->wait();
base::__on_zero_shared();
}
template <class _Rp> class _LIBCPP_TEMPLATE_VIS promise;
template <class _Rp> class _LIBCPP_TEMPLATE_VIS shared_future;
// future
template <class _Rp> class _LIBCPP_TEMPLATE_VIS future;
template <class _Rp, class _Fp>
future<_Rp>
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
__make_deferred_assoc_state(_Fp&& __f);
#else
__make_deferred_assoc_state(_Fp __f);
#endif
template <class _Rp, class _Fp>
future<_Rp>
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
__make_async_assoc_state(_Fp&& __f);
#else
__make_async_assoc_state(_Fp __f);
#endif
template <class _Rp>
class _LIBCPP_TEMPLATE_VIS _LIBCPP_AVAILABILITY_FUTURE future
{
__assoc_state<_Rp>* __state_;
explicit future(__assoc_state<_Rp>* __state);
template <class> friend class promise;
template <class> friend class shared_future;
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
template <class _R1, class _Fp>
friend future<_R1> __make_deferred_assoc_state(_Fp&& __f);
template <class _R1, class _Fp>
friend future<_R1> __make_async_assoc_state(_Fp&& __f);
#else
template <class _R1, class _Fp>
friend future<_R1> __make_deferred_assoc_state(_Fp __f);
template <class _R1, class _Fp>
friend future<_R1> __make_async_assoc_state(_Fp __f);
#endif
public:
_LIBCPP_INLINE_VISIBILITY
future() _NOEXCEPT : __state_(nullptr) {}
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
_LIBCPP_INLINE_VISIBILITY
future(future&& __rhs) _NOEXCEPT
: __state_(__rhs.__state_) {__rhs.__state_ = nullptr;}
future(const future&) = delete;
future& operator=(const future&) = delete;
_LIBCPP_INLINE_VISIBILITY
future& operator=(future&& __rhs) _NOEXCEPT
{
future(std::move(__rhs)).swap(*this);
return *this;
}
#else // _LIBCPP_HAS_NO_RVALUE_REFERENCES
private:
future(const future&);
future& operator=(const future&);
public:
#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
~future();
_LIBCPP_INLINE_VISIBILITY
shared_future<_Rp> share() _NOEXCEPT;
// retrieving the value
_Rp get();
_LIBCPP_INLINE_VISIBILITY
void swap(future& __rhs) _NOEXCEPT {_VSTD::swap(__state_, __rhs.__state_);}
// functions to check state
_LIBCPP_INLINE_VISIBILITY
bool valid() const _NOEXCEPT {return __state_ != nullptr;}
_LIBCPP_INLINE_VISIBILITY
void wait() const {__state_->wait();}
template <class _Rep, class _Period>
_LIBCPP_INLINE_VISIBILITY
future_status
wait_for(const chrono::duration<_Rep, _Period>& __rel_time) const
{return __state_->wait_for(__rel_time);}
template <class _Clock, class _Duration>
_LIBCPP_INLINE_VISIBILITY
future_status
wait_until(const chrono::time_point<_Clock, _Duration>& __abs_time) const
{return __state_->wait_until(__abs_time);}
};
template <class _Rp>
future<_Rp>::future(__assoc_state<_Rp>* __state)
: __state_(__state)
{
__state_->__attach_future();
}
struct __release_shared_count
{
void operator()(__shared_count* p) {p->__release_shared();}
};
template <class _Rp>
future<_Rp>::~future()
{
if (__state_)
__state_->__release_shared();
}
template <class _Rp>
_Rp
future<_Rp>::get()
{
unique_ptr<__shared_count, __release_shared_count> __(__state_);
__assoc_state<_Rp>* __s = __state_;
__state_ = nullptr;
return __s->move();
}
template <class _Rp>
class _LIBCPP_TEMPLATE_VIS _LIBCPP_AVAILABILITY_FUTURE future<_Rp&>
{
__assoc_state<_Rp&>* __state_;
explicit future(__assoc_state<_Rp&>* __state);
template <class> friend class promise;
template <class> friend class shared_future;
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
template <class _R1, class _Fp>
friend future<_R1> __make_deferred_assoc_state(_Fp&& __f);
template <class _R1, class _Fp>
friend future<_R1> __make_async_assoc_state(_Fp&& __f);
#else
template <class _R1, class _Fp>
friend future<_R1> __make_deferred_assoc_state(_Fp __f);
template <class _R1, class _Fp>
friend future<_R1> __make_async_assoc_state(_Fp __f);
#endif
public:
_LIBCPP_INLINE_VISIBILITY
future() _NOEXCEPT : __state_(nullptr) {}
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
_LIBCPP_INLINE_VISIBILITY
future(future&& __rhs) _NOEXCEPT
: __state_(__rhs.__state_) {__rhs.__state_ = nullptr;}
future(const future&) = delete;
future& operator=(const future&) = delete;
_LIBCPP_INLINE_VISIBILITY
future& operator=(future&& __rhs) _NOEXCEPT
{
future(std::move(__rhs)).swap(*this);
return *this;
}
#else // _LIBCPP_HAS_NO_RVALUE_REFERENCES
private:
future(const future&);
future& operator=(const future&);
public:
#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
~future();
_LIBCPP_INLINE_VISIBILITY
shared_future<_Rp&> share() _NOEXCEPT;
// retrieving the value
_Rp& get();
_LIBCPP_INLINE_VISIBILITY
void swap(future& __rhs) _NOEXCEPT {_VSTD::swap(__state_, __rhs.__state_);}
// functions to check state
_LIBCPP_INLINE_VISIBILITY
bool valid() const _NOEXCEPT {return __state_ != nullptr;}
_LIBCPP_INLINE_VISIBILITY
void wait() const {__state_->wait();}
template <class _Rep, class _Period>
_LIBCPP_INLINE_VISIBILITY
future_status
wait_for(const chrono::duration<_Rep, _Period>& __rel_time) const
{return __state_->wait_for(__rel_time);}
template <class _Clock, class _Duration>
_LIBCPP_INLINE_VISIBILITY
future_status
wait_until(const chrono::time_point<_Clock, _Duration>& __abs_time) const
{return __state_->wait_until(__abs_time);}
};
template <class _Rp>
future<_Rp&>::future(__assoc_state<_Rp&>* __state)
: __state_(__state)
{
__state_->__attach_future();
}
template <class _Rp>
future<_Rp&>::~future()
{
if (__state_)
__state_->__release_shared();
}
template <class _Rp>
_Rp&
future<_Rp&>::get()
{
unique_ptr<__shared_count, __release_shared_count> __(__state_);
__assoc_state<_Rp&>* __s = __state_;
__state_ = nullptr;
return __s->copy();
}
template <>
class _LIBCPP_TYPE_VIS _LIBCPP_AVAILABILITY_FUTURE future<void>
{
__assoc_sub_state* __state_;
explicit future(__assoc_sub_state* __state);
template <class> friend class promise;
template <class> friend class shared_future;
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
template <class _R1, class _Fp>
friend future<_R1> __make_deferred_assoc_state(_Fp&& __f);
template <class _R1, class _Fp>
friend future<_R1> __make_async_assoc_state(_Fp&& __f);
#else
template <class _R1, class _Fp>
friend future<_R1> __make_deferred_assoc_state(_Fp __f);
template <class _R1, class _Fp>
friend future<_R1> __make_async_assoc_state(_Fp __f);
#endif
public:
_LIBCPP_INLINE_VISIBILITY
future() _NOEXCEPT : __state_(nullptr) {}
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
_LIBCPP_INLINE_VISIBILITY
future(future&& __rhs) _NOEXCEPT
: __state_(__rhs.__state_) {__rhs.__state_ = nullptr;}
future(const future&) = delete;
future& operator=(const future&) = delete;
_LIBCPP_INLINE_VISIBILITY
future& operator=(future&& __rhs) _NOEXCEPT
{
future(std::move(__rhs)).swap(*this);
return *this;
}
#else // _LIBCPP_HAS_NO_RVALUE_REFERENCES
private:
future(const future&);
future& operator=(const future&);
public:
#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
~future();
_LIBCPP_INLINE_VISIBILITY
shared_future<void> share() _NOEXCEPT;
// retrieving the value
void get();
_LIBCPP_INLINE_VISIBILITY
void swap(future& __rhs) _NOEXCEPT {_VSTD::swap(__state_, __rhs.__state_);}
// functions to check state
_LIBCPP_INLINE_VISIBILITY
bool valid() const _NOEXCEPT {return __state_ != nullptr;}
_LIBCPP_INLINE_VISIBILITY
void wait() const {__state_->wait();}
template <class _Rep, class _Period>
_LIBCPP_INLINE_VISIBILITY
future_status
wait_for(const chrono::duration<_Rep, _Period>& __rel_time) const
{return __state_->wait_for(__rel_time);}
template <class _Clock, class _Duration>
_LIBCPP_INLINE_VISIBILITY
future_status
wait_until(const chrono::time_point<_Clock, _Duration>& __abs_time) const
{return __state_->wait_until(__abs_time);}
};
template <class _Rp>
inline _LIBCPP_INLINE_VISIBILITY
void
swap(future<_Rp>& __x, future<_Rp>& __y) _NOEXCEPT
{
__x.swap(__y);
}
// promise<R>
template <class _Callable> class packaged_task;
template <class _Rp>
class _LIBCPP_TEMPLATE_VIS _LIBCPP_AVAILABILITY_FUTURE promise
{
__assoc_state<_Rp>* __state_;
_LIBCPP_INLINE_VISIBILITY
explicit promise(nullptr_t) _NOEXCEPT : __state_(nullptr) {}
template <class> friend class packaged_task;
public:
promise();
template <class _Alloc>
promise(allocator_arg_t, const _Alloc& __a);
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
_LIBCPP_INLINE_VISIBILITY
promise(promise&& __rhs) _NOEXCEPT
: __state_(__rhs.__state_) {__rhs.__state_ = nullptr;}
promise(const promise& __rhs) = delete;
#else // _LIBCPP_HAS_NO_RVALUE_REFERENCES
private:
promise(const promise& __rhs);
public:
#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
~promise();
// assignment
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
_LIBCPP_INLINE_VISIBILITY
promise& operator=(promise&& __rhs) _NOEXCEPT
{
promise(std::move(__rhs)).swap(*this);
return *this;
}
promise& operator=(const promise& __rhs) = delete;
#else // _LIBCPP_HAS_NO_RVALUE_REFERENCES
private:
promise& operator=(const promise& __rhs);
public:
#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
_LIBCPP_INLINE_VISIBILITY
void swap(promise& __rhs) _NOEXCEPT {_VSTD::swap(__state_, __rhs.__state_);}
// retrieving the result
future<_Rp> get_future();
// setting the result
void set_value(const _Rp& __r);
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
void set_value(_Rp&& __r);
#endif
void set_exception(exception_ptr __p);
// setting the result with deferred notification
void set_value_at_thread_exit(const _Rp& __r);
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
void set_value_at_thread_exit(_Rp&& __r);
#endif
void set_exception_at_thread_exit(exception_ptr __p);
};
template <class _Rp>
promise<_Rp>::promise()
: __state_(new __assoc_state<_Rp>)
{
}
template <class _Rp>
template <class _Alloc>
promise<_Rp>::promise(allocator_arg_t, const _Alloc& __a0)
{
typedef __assoc_state_alloc<_Rp, _Alloc> _State;
typedef typename __allocator_traits_rebind<_Alloc, _State>::type _A2;
typedef __allocator_destructor<_A2> _D2;
_A2 __a(__a0);
unique_ptr<_State, _D2> __hold(__a.allocate(1), _D2(__a, 1));
::new(static_cast<void*>(_VSTD::addressof(*__hold.get()))) _State(__a0);
__state_ = _VSTD::addressof(*__hold.release());
}
template <class _Rp>
promise<_Rp>::~promise()
{
if (__state_)
{
if (!__state_->__has_value() && __state_->use_count() > 1)
__state_->set_exception(make_exception_ptr(
future_error(make_error_code(future_errc::broken_promise))
));
__state_->__release_shared();
}
}
template <class _Rp>
future<_Rp>
promise<_Rp>::get_future()
{
if (__state_ == nullptr)
__throw_future_error(future_errc::no_state);
return future<_Rp>(__state_);
}
template <class _Rp>
void
promise<_Rp>::set_value(const _Rp& __r)
{
if (__state_ == nullptr)
__throw_future_error(future_errc::no_state);
__state_->set_value(__r);
}
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
template <class _Rp>
void
promise<_Rp>::set_value(_Rp&& __r)
{
if (__state_ == nullptr)
__throw_future_error(future_errc::no_state);
__state_->set_value(_VSTD::move(__r));
}
#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
template <class _Rp>
void
promise<_Rp>::set_exception(exception_ptr __p)
{
_LIBCPP_ASSERT( __p != nullptr, "promise::set_exception: received nullptr" );
if (__state_ == nullptr)
__throw_future_error(future_errc::no_state);
__state_->set_exception(__p);
}
template <class _Rp>
void
promise<_Rp>::set_value_at_thread_exit(const _Rp& __r)
{
if (__state_ == nullptr)
__throw_future_error(future_errc::no_state);
__state_->set_value_at_thread_exit(__r);
}
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
template <class _Rp>
void
promise<_Rp>::set_value_at_thread_exit(_Rp&& __r)
{
if (__state_ == nullptr)
__throw_future_error(future_errc::no_state);
__state_->set_value_at_thread_exit(_VSTD::move(__r));
}
#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
template <class _Rp>
void
promise<_Rp>::set_exception_at_thread_exit(exception_ptr __p)
{
_LIBCPP_ASSERT( __p != nullptr, "promise::set_exception_at_thread_exit: received nullptr" );
if (__state_ == nullptr)
__throw_future_error(future_errc::no_state);
__state_->set_exception_at_thread_exit(__p);
}
// promise<R&>
template <class _Rp>
class _LIBCPP_TEMPLATE_VIS _LIBCPP_AVAILABILITY_FUTURE promise<_Rp&>
{
__assoc_state<_Rp&>* __state_;
_LIBCPP_INLINE_VISIBILITY
explicit promise(nullptr_t) _NOEXCEPT : __state_(nullptr) {}
template <class> friend class packaged_task;
public:
promise();
template <class _Allocator>
promise(allocator_arg_t, const _Allocator& __a);
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
_LIBCPP_INLINE_VISIBILITY
promise(promise&& __rhs) _NOEXCEPT
: __state_(__rhs.__state_) {__rhs.__state_ = nullptr;}
promise(const promise& __rhs) = delete;
#else // _LIBCPP_HAS_NO_RVALUE_REFERENCES
private:
promise(const promise& __rhs);
public:
#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
~promise();
// assignment
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
_LIBCPP_INLINE_VISIBILITY
promise& operator=(promise&& __rhs) _NOEXCEPT
{
promise(std::move(__rhs)).swap(*this);
return *this;
}
promise& operator=(const promise& __rhs) = delete;
#else // _LIBCPP_HAS_NO_RVALUE_REFERENCES
private:
promise& operator=(const promise& __rhs);
public:
#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
_LIBCPP_INLINE_VISIBILITY
void swap(promise& __rhs) _NOEXCEPT {_VSTD::swap(__state_, __rhs.__state_);}
// retrieving the result
future<_Rp&> get_future();
// setting the result
void set_value(_Rp& __r);
void set_exception(exception_ptr __p);
// setting the result with deferred notification
void set_value_at_thread_exit(_Rp&);
void set_exception_at_thread_exit(exception_ptr __p);
};
template <class _Rp>
promise<_Rp&>::promise()
: __state_(new __assoc_state<_Rp&>)
{
}
template <class _Rp>
template <class _Alloc>
promise<_Rp&>::promise(allocator_arg_t, const _Alloc& __a0)
{
typedef __assoc_state_alloc<_Rp&, _Alloc> _State;
typedef typename __allocator_traits_rebind<_Alloc, _State>::type _A2;
typedef __allocator_destructor<_A2> _D2;
_A2 __a(__a0);
unique_ptr<_State, _D2> __hold(__a.allocate(1), _D2(__a, 1));
::new(static_cast<void*>(_VSTD::addressof(*__hold.get()))) _State(__a0);
__state_ = _VSTD::addressof(*__hold.release());
}
template <class _Rp>
promise<_Rp&>::~promise()
{
if (__state_)
{
if (!__state_->__has_value() && __state_->use_count() > 1)
__state_->set_exception(make_exception_ptr(
future_error(make_error_code(future_errc::broken_promise))
));
__state_->__release_shared();
}
}
template <class _Rp>
future<_Rp&>
promise<_Rp&>::get_future()
{
if (__state_ == nullptr)
__throw_future_error(future_errc::no_state);
return future<_Rp&>(__state_);
}
template <class _Rp>
void
promise<_Rp&>::set_value(_Rp& __r)
{
if (__state_ == nullptr)
__throw_future_error(future_errc::no_state);
__state_->set_value(__r);
}
template <class _Rp>
void
promise<_Rp&>::set_exception(exception_ptr __p)
{
_LIBCPP_ASSERT( __p != nullptr, "promise::set_exception: received nullptr" );
if (__state_ == nullptr)
__throw_future_error(future_errc::no_state);
__state_->set_exception(__p);
}
template <class _Rp>
void
promise<_Rp&>::set_value_at_thread_exit(_Rp& __r)
{
if (__state_ == nullptr)
__throw_future_error(future_errc::no_state);
__state_->set_value_at_thread_exit(__r);
}
template <class _Rp>
void
promise<_Rp&>::set_exception_at_thread_exit(exception_ptr __p)
{
_LIBCPP_ASSERT( __p != nullptr, "promise::set_exception_at_thread_exit: received nullptr" );
if (__state_ == nullptr)
__throw_future_error(future_errc::no_state);
__state_->set_exception_at_thread_exit(__p);
}
// promise<void>
template <>
class _LIBCPP_TYPE_VIS _LIBCPP_AVAILABILITY_FUTURE promise<void>
{
__assoc_sub_state* __state_;
_LIBCPP_INLINE_VISIBILITY
explicit promise(nullptr_t) _NOEXCEPT : __state_(nullptr) {}
template <class> friend class packaged_task;
public:
promise();
template <class _Allocator>
_LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
promise(allocator_arg_t, const _Allocator& __a);
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
_LIBCPP_INLINE_VISIBILITY
promise(promise&& __rhs) _NOEXCEPT
: __state_(__rhs.__state_) {__rhs.__state_ = nullptr;}
promise(const promise& __rhs) = delete;
#else // _LIBCPP_HAS_NO_RVALUE_REFERENCES
private:
promise(const promise& __rhs);
public:
#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
~promise();
// assignment
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
_LIBCPP_INLINE_VISIBILITY
promise& operator=(promise&& __rhs) _NOEXCEPT
{
promise(std::move(__rhs)).swap(*this);
return *this;
}
promise& operator=(const promise& __rhs) = delete;
#else // _LIBCPP_HAS_NO_RVALUE_REFERENCES
private:
promise& operator=(const promise& __rhs);
public:
#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
_LIBCPP_INLINE_VISIBILITY
void swap(promise& __rhs) _NOEXCEPT {_VSTD::swap(__state_, __rhs.__state_);}
// retrieving the result
future<void> get_future();
// setting the result
void set_value();
void set_exception(exception_ptr __p);
// setting the result with deferred notification
void set_value_at_thread_exit();
void set_exception_at_thread_exit(exception_ptr __p);
};
template <class _Alloc>
promise<void>::promise(allocator_arg_t, const _Alloc& __a0)
{
typedef __assoc_sub_state_alloc<_Alloc> _State;
typedef typename __allocator_traits_rebind<_Alloc, _State>::type _A2;
typedef __allocator_destructor<_A2> _D2;
_A2 __a(__a0);
unique_ptr<_State, _D2> __hold(__a.allocate(1), _D2(__a, 1));
::new(static_cast<void*>(_VSTD::addressof(*__hold.get()))) _State(__a0);
__state_ = _VSTD::addressof(*__hold.release());
}
template <class _Rp>
inline _LIBCPP_INLINE_VISIBILITY
void
swap(promise<_Rp>& __x, promise<_Rp>& __y) _NOEXCEPT
{
__x.swap(__y);
}
template <class _Rp, class _Alloc>
struct _LIBCPP_TEMPLATE_VIS uses_allocator<promise<_Rp>, _Alloc>
: public true_type {};
#ifndef _LIBCPP_HAS_NO_VARIADICS
// packaged_task
template<class _Fp> class __packaged_task_base;
template<class _Rp, class ..._ArgTypes>
class _LIBCPP_AVAILABILITY_FUTURE __packaged_task_base<_Rp(_ArgTypes...)>
{
__packaged_task_base(const __packaged_task_base&);
__packaged_task_base& operator=(const __packaged_task_base&);
public:
_LIBCPP_INLINE_VISIBILITY
__packaged_task_base() {}
_LIBCPP_INLINE_VISIBILITY
virtual ~__packaged_task_base() {}
virtual void __move_to(__packaged_task_base*) _NOEXCEPT = 0;
virtual void destroy() = 0;
virtual void destroy_deallocate() = 0;
virtual _Rp operator()(_ArgTypes&& ...) = 0;
};
template<class _FD, class _Alloc, class _FB> class __packaged_task_func;
template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes>
class _LIBCPP_AVAILABILITY_FUTURE __packaged_task_func<_Fp, _Alloc, _Rp(_ArgTypes...)>
: public __packaged_task_base<_Rp(_ArgTypes...)>
{
__compressed_pair<_Fp, _Alloc> __f_;
public:
_LIBCPP_INLINE_VISIBILITY
explicit __packaged_task_func(const _Fp& __f) : __f_(__f) {}
_LIBCPP_INLINE_VISIBILITY
explicit __packaged_task_func(_Fp&& __f) : __f_(_VSTD::move(__f)) {}
_LIBCPP_INLINE_VISIBILITY
__packaged_task_func(const _Fp& __f, const _Alloc& __a)
: __f_(__f, __a) {}
_LIBCPP_INLINE_VISIBILITY
__packaged_task_func(_Fp&& __f, const _Alloc& __a)
: __f_(_VSTD::move(__f), __a) {}
virtual void __move_to(__packaged_task_base<_Rp(_ArgTypes...)>*) _NOEXCEPT;
virtual void destroy();
virtual void destroy_deallocate();
virtual _Rp operator()(_ArgTypes&& ... __args);
};
template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes>
void
__packaged_task_func<_Fp, _Alloc, _Rp(_ArgTypes...)>::__move_to(
__packaged_task_base<_Rp(_ArgTypes...)>* __p) _NOEXCEPT
{
::new (__p) __packaged_task_func(_VSTD::move(__f_.first()), _VSTD::move(__f_.second()));
}
template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes>
void
__packaged_task_func<_Fp, _Alloc, _Rp(_ArgTypes...)>::destroy()
{
__f_.~__compressed_pair<_Fp, _Alloc>();
}
template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes>
void
__packaged_task_func<_Fp, _Alloc, _Rp(_ArgTypes...)>::destroy_deallocate()
{
typedef typename __allocator_traits_rebind<_Alloc, __packaged_task_func>::type _Ap;
typedef allocator_traits<_Ap> _ATraits;
typedef pointer_traits<typename _ATraits::pointer> _PTraits;
_Ap __a(__f_.second());
__f_.~__compressed_pair<_Fp, _Alloc>();
__a.deallocate(_PTraits::pointer_to(*this), 1);
}
template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes>
_Rp
__packaged_task_func<_Fp, _Alloc, _Rp(_ArgTypes...)>::operator()(_ArgTypes&& ... __arg)
{
return __invoke(__f_.first(), _VSTD::forward<_ArgTypes>(__arg)...);
}
template <class _Callable> class __packaged_task_function;
template<class _Rp, class ..._ArgTypes>
class _LIBCPP_AVAILABILITY_FUTURE __packaged_task_function<_Rp(_ArgTypes...)>
{
typedef __packaged_task_base<_Rp(_ArgTypes...)> __base;
typename aligned_storage<3*sizeof(void*)>::type __buf_;
__base* __f_;
public:
typedef _Rp result_type;
// construct/copy/destroy:
_LIBCPP_INLINE_VISIBILITY
__packaged_task_function() _NOEXCEPT : __f_(nullptr) {}
template<class _Fp>
__packaged_task_function(_Fp&& __f);
template<class _Fp, class _Alloc>
__packaged_task_function(allocator_arg_t, const _Alloc& __a, _Fp&& __f);
__packaged_task_function(__packaged_task_function&&) _NOEXCEPT;
__packaged_task_function& operator=(__packaged_task_function&&) _NOEXCEPT;
__packaged_task_function(const __packaged_task_function&) = delete;
__packaged_task_function& operator=(const __packaged_task_function&) = delete;
~__packaged_task_function();
void swap(__packaged_task_function&) _NOEXCEPT;
_LIBCPP_INLINE_VISIBILITY
_Rp operator()(_ArgTypes...) const;
};
template<class _Rp, class ..._ArgTypes>
__packaged_task_function<_Rp(_ArgTypes...)>::__packaged_task_function(__packaged_task_function&& __f) _NOEXCEPT
{
if (__f.__f_ == nullptr)
__f_ = nullptr;
else if (__f.__f_ == (__base*)&__f.__buf_)
{
__f_ = (__base*)&__buf_;
__f.__f_->__move_to(__f_);
}
else
{
__f_ = __f.__f_;
__f.__f_ = nullptr;
}
}
template<class _Rp, class ..._ArgTypes>
template <class _Fp>
__packaged_task_function<_Rp(_ArgTypes...)>::__packaged_task_function(_Fp&& __f)
: __f_(nullptr)
{
typedef typename remove_reference<typename decay<_Fp>::type>::type _FR;
typedef __packaged_task_func<_FR, allocator<_FR>, _Rp(_ArgTypes...)> _FF;
if (sizeof(_FF) <= sizeof(__buf_))
{
__f_ = (__base*)&__buf_;
::new (__f_) _FF(_VSTD::forward<_Fp>(__f));
}
else
{
typedef allocator<_FF> _Ap;
_Ap __a;
typedef __allocator_destructor<_Ap> _Dp;
unique_ptr<__base, _Dp> __hold(__a.allocate(1), _Dp(__a, 1));
::new (__hold.get()) _FF(_VSTD::forward<_Fp>(__f), allocator<_FR>(__a));
__f_ = __hold.release();
}
}
template<class _Rp, class ..._ArgTypes>
template <class _Fp, class _Alloc>
__packaged_task_function<_Rp(_ArgTypes...)>::__packaged_task_function(
allocator_arg_t, const _Alloc& __a0, _Fp&& __f)
: __f_(nullptr)
{
typedef typename remove_reference<typename decay<_Fp>::type>::type _FR;
typedef __packaged_task_func<_FR, _Alloc, _Rp(_ArgTypes...)> _FF;
if (sizeof(_FF) <= sizeof(__buf_))
{
__f_ = (__base*)&__buf_;
::new (__f_) _FF(_VSTD::forward<_Fp>(__f));
}
else
{
typedef typename __allocator_traits_rebind<_Alloc, _FF>::type _Ap;
_Ap __a(__a0);
typedef __allocator_destructor<_Ap> _Dp;
unique_ptr<__base, _Dp> __hold(__a.allocate(1), _Dp(__a, 1));
::new (static_cast<void*>(_VSTD::addressof(*__hold.get())))
_FF(_VSTD::forward<_Fp>(__f), _Alloc(__a));
__f_ = _VSTD::addressof(*__hold.release());
}
}
template<class _Rp, class ..._ArgTypes>
__packaged_task_function<_Rp(_ArgTypes...)>&
__packaged_task_function<_Rp(_ArgTypes...)>::operator=(__packaged_task_function&& __f) _NOEXCEPT
{
if (__f_ == (__base*)&__buf_)
__f_->destroy();
else if (__f_)
__f_->destroy_deallocate();
__f_ = nullptr;
if (__f.__f_ == nullptr)
__f_ = nullptr;
else if (__f.__f_ == (__base*)&__f.__buf_)
{
__f_ = (__base*)&__buf_;
__f.__f_->__move_to(__f_);
}
else
{
__f_ = __f.__f_;
__f.__f_ = nullptr;
}
return *this;
}
template<class _Rp, class ..._ArgTypes>
__packaged_task_function<_Rp(_ArgTypes...)>::~__packaged_task_function()
{
if (__f_ == (__base*)&__buf_)
__f_->destroy();
else if (__f_)
__f_->destroy_deallocate();
}
template<class _Rp, class ..._ArgTypes>
void
__packaged_task_function<_Rp(_ArgTypes...)>::swap(__packaged_task_function& __f) _NOEXCEPT
{
if (__f_ == (__base*)&__buf_ && __f.__f_ == (__base*)&__f.__buf_)
{
typename aligned_storage<sizeof(__buf_)>::type __tempbuf;
__base* __t = (__base*)&__tempbuf;
__f_->__move_to(__t);
__f_->destroy();
__f_ = nullptr;
__f.__f_->__move_to((__base*)&__buf_);
__f.__f_->destroy();
__f.__f_ = nullptr;
__f_ = (__base*)&__buf_;
__t->__move_to((__base*)&__f.__buf_);
__t->destroy();
__f.__f_ = (__base*)&__f.__buf_;
}
else if (__f_ == (__base*)&__buf_)
{
__f_->__move_to((__base*)&__f.__buf_);
__f_->destroy();
__f_ = __f.__f_;
__f.__f_ = (__base*)&__f.__buf_;
}
else if (__f.__f_ == (__base*)&__f.__buf_)
{
__f.__f_->__move_to((__base*)&__buf_);
__f.__f_->destroy();
__f.__f_ = __f_;
__f_ = (__base*)&__buf_;
}
else
_VSTD::swap(__f_, __f.__f_);
}
template<class _Rp, class ..._ArgTypes>
inline
_Rp
__packaged_task_function<_Rp(_ArgTypes...)>::operator()(_ArgTypes... __arg) const
{
return (*__f_)(_VSTD::forward<_ArgTypes>(__arg)...);
}
template<class _Rp, class ..._ArgTypes>
class _LIBCPP_TEMPLATE_VIS _LIBCPP_AVAILABILITY_FUTURE packaged_task<_Rp(_ArgTypes...)>
{
public:
typedef _Rp result_type; // extension
private:
__packaged_task_function<result_type(_ArgTypes...)> __f_;
promise<result_type> __p_;
public:
// construction and destruction
_LIBCPP_INLINE_VISIBILITY
packaged_task() _NOEXCEPT : __p_(nullptr) {}
template <class _Fp,
class = typename enable_if
<
!is_same<
typename __uncvref<_Fp>::type,
packaged_task
>::value
>::type
>
_LIBCPP_INLINE_VISIBILITY
explicit packaged_task(_Fp&& __f) : __f_(_VSTD::forward<_Fp>(__f)) {}
template <class _Fp, class _Allocator,
class = typename enable_if
<
!is_same<
typename __uncvref<_Fp>::type,
packaged_task
>::value
>::type
>
_LIBCPP_INLINE_VISIBILITY
packaged_task(allocator_arg_t, const _Allocator& __a, _Fp&& __f)
: __f_(allocator_arg, __a, _VSTD::forward<_Fp>(__f)),
__p_(allocator_arg, __a) {}
// ~packaged_task() = default;
// no copy
packaged_task(const packaged_task&) = delete;
packaged_task& operator=(const packaged_task&) = delete;
// move support
_LIBCPP_INLINE_VISIBILITY
packaged_task(packaged_task&& __other) _NOEXCEPT
: __f_(_VSTD::move(__other.__f_)), __p_(_VSTD::move(__other.__p_)) {}
_LIBCPP_INLINE_VISIBILITY
packaged_task& operator=(packaged_task&& __other) _NOEXCEPT
{
__f_ = _VSTD::move(__other.__f_);
__p_ = _VSTD::move(__other.__p_);
return *this;
}
_LIBCPP_INLINE_VISIBILITY
void swap(packaged_task& __other) _NOEXCEPT
{
__f_.swap(__other.__f_);
__p_.swap(__other.__p_);
}
_LIBCPP_INLINE_VISIBILITY
bool valid() const _NOEXCEPT {return __p_.__state_ != nullptr;}
// result retrieval
_LIBCPP_INLINE_VISIBILITY
future<result_type> get_future() {return __p_.get_future();}
// execution
void operator()(_ArgTypes... __args);
void make_ready_at_thread_exit(_ArgTypes... __args);
void reset();
};
template<class _Rp, class ..._ArgTypes>
void
packaged_task<_Rp(_ArgTypes...)>::operator()(_ArgTypes... __args)
{
if (__p_.__state_ == nullptr)
__throw_future_error(future_errc::no_state);
if (__p_.__state_->__has_value())
__throw_future_error(future_errc::promise_already_satisfied);
#ifndef _LIBCPP_NO_EXCEPTIONS
try
{
#endif // _LIBCPP_NO_EXCEPTIONS
__p_.set_value(__f_(_VSTD::forward<_ArgTypes>(__args)...));
#ifndef _LIBCPP_NO_EXCEPTIONS
}
catch (...)
{
__p_.set_exception(current_exception());
}
#endif // _LIBCPP_NO_EXCEPTIONS
}
template<class _Rp, class ..._ArgTypes>
void
packaged_task<_Rp(_ArgTypes...)>::make_ready_at_thread_exit(_ArgTypes... __args)
{
if (__p_.__state_ == nullptr)
__throw_future_error(future_errc::no_state);
if (__p_.__state_->__has_value())
__throw_future_error(future_errc::promise_already_satisfied);
#ifndef _LIBCPP_NO_EXCEPTIONS
try
{
#endif // _LIBCPP_NO_EXCEPTIONS
__p_.set_value_at_thread_exit(__f_(_VSTD::forward<_ArgTypes>(__args)...));
#ifndef _LIBCPP_NO_EXCEPTIONS
}
catch (...)
{
__p_.set_exception_at_thread_exit(current_exception());
}
#endif // _LIBCPP_NO_EXCEPTIONS
}
template<class _Rp, class ..._ArgTypes>
void
packaged_task<_Rp(_ArgTypes...)>::reset()
{
if (!valid())
__throw_future_error(future_errc::no_state);
__p_ = promise<result_type>();
}
template<class ..._ArgTypes>
class _LIBCPP_TEMPLATE_VIS _LIBCPP_AVAILABILITY_FUTURE packaged_task<void(_ArgTypes...)>
{
public:
typedef void result_type; // extension
private:
__packaged_task_function<result_type(_ArgTypes...)> __f_;
promise<result_type> __p_;
public:
// construction and destruction
_LIBCPP_INLINE_VISIBILITY
packaged_task() _NOEXCEPT : __p_(nullptr) {}
template <class _Fp,
class = typename enable_if
<
!is_same<
typename __uncvref<_Fp>::type,
packaged_task
>::value
>::type
>
_LIBCPP_INLINE_VISIBILITY
explicit packaged_task(_Fp&& __f) : __f_(_VSTD::forward<_Fp>(__f)) {}
template <class _Fp, class _Allocator,
class = typename enable_if
<
!is_same<
typename __uncvref<_Fp>::type,
packaged_task
>::value
>::type
>
_LIBCPP_INLINE_VISIBILITY
packaged_task(allocator_arg_t, const _Allocator& __a, _Fp&& __f)
: __f_(allocator_arg, __a, _VSTD::forward<_Fp>(__f)),
__p_(allocator_arg, __a) {}
// ~packaged_task() = default;
// no copy
packaged_task(const packaged_task&) = delete;
packaged_task& operator=(const packaged_task&) = delete;
// move support
_LIBCPP_INLINE_VISIBILITY
packaged_task(packaged_task&& __other) _NOEXCEPT
: __f_(_VSTD::move(__other.__f_)), __p_(_VSTD::move(__other.__p_)) {}
_LIBCPP_INLINE_VISIBILITY
packaged_task& operator=(packaged_task&& __other) _NOEXCEPT
{
__f_ = _VSTD::move(__other.__f_);
__p_ = _VSTD::move(__other.__p_);
return *this;
}
_LIBCPP_INLINE_VISIBILITY
void swap(packaged_task& __other) _NOEXCEPT
{
__f_.swap(__other.__f_);
__p_.swap(__other.__p_);
}
_LIBCPP_INLINE_VISIBILITY
bool valid() const _NOEXCEPT {return __p_.__state_ != nullptr;}
// result retrieval
_LIBCPP_INLINE_VISIBILITY
future<result_type> get_future() {return __p_.get_future();}
// execution
void operator()(_ArgTypes... __args);
void make_ready_at_thread_exit(_ArgTypes... __args);
void reset();
};
template<class ..._ArgTypes>
void
packaged_task<void(_ArgTypes...)>::operator()(_ArgTypes... __args)
{
if (__p_.__state_ == nullptr)
__throw_future_error(future_errc::no_state);
if (__p_.__state_->__has_value())
__throw_future_error(future_errc::promise_already_satisfied);
#ifndef _LIBCPP_NO_EXCEPTIONS
try
{
#endif // _LIBCPP_NO_EXCEPTIONS
__f_(_VSTD::forward<_ArgTypes>(__args)...);
__p_.set_value();
#ifndef _LIBCPP_NO_EXCEPTIONS
}
catch (...)
{
__p_.set_exception(current_exception());
}
#endif // _LIBCPP_NO_EXCEPTIONS
}
template<class ..._ArgTypes>
void
packaged_task<void(_ArgTypes...)>::make_ready_at_thread_exit(_ArgTypes... __args)
{
if (__p_.__state_ == nullptr)
__throw_future_error(future_errc::no_state);
if (__p_.__state_->__has_value())
__throw_future_error(future_errc::promise_already_satisfied);
#ifndef _LIBCPP_NO_EXCEPTIONS
try
{
#endif // _LIBCPP_NO_EXCEPTIONS
__f_(_VSTD::forward<_ArgTypes>(__args)...);
__p_.set_value_at_thread_exit();
#ifndef _LIBCPP_NO_EXCEPTIONS
}
catch (...)
{
__p_.set_exception_at_thread_exit(current_exception());
}
#endif // _LIBCPP_NO_EXCEPTIONS
}
template<class ..._ArgTypes>
void
packaged_task<void(_ArgTypes...)>::reset()
{
if (!valid())
__throw_future_error(future_errc::no_state);
__p_ = promise<result_type>();
}
template <class _Callable>
inline _LIBCPP_INLINE_VISIBILITY
void
swap(packaged_task<_Callable>& __x, packaged_task<_Callable>& __y) _NOEXCEPT
{
__x.swap(__y);
}
template <class _Callable, class _Alloc>
struct _LIBCPP_TEMPLATE_VIS uses_allocator<packaged_task<_Callable>, _Alloc>
: public true_type {};
template <class _Rp, class _Fp>
future<_Rp>
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
__make_deferred_assoc_state(_Fp&& __f)
#else
__make_deferred_assoc_state(_Fp __f)
#endif
{
unique_ptr<__deferred_assoc_state<_Rp, _Fp>, __release_shared_count>
__h(new __deferred_assoc_state<_Rp, _Fp>(_VSTD::forward<_Fp>(__f)));
return future<_Rp>(__h.get());
}
template <class _Rp, class _Fp>
future<_Rp>
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
__make_async_assoc_state(_Fp&& __f)
#else
__make_async_assoc_state(_Fp __f)
#endif
{
unique_ptr<__async_assoc_state<_Rp, _Fp>, __release_shared_count>
__h(new __async_assoc_state<_Rp, _Fp>(_VSTD::forward<_Fp>(__f)));
_VSTD::thread(&__async_assoc_state<_Rp, _Fp>::__execute, __h.get()).detach();
return future<_Rp>(__h.get());
}
template <class _Fp, class... _Args>
class __async_func
{
tuple<_Fp, _Args...> __f_;
public:
typedef typename __invoke_of<_Fp, _Args...>::type _Rp;
_LIBCPP_INLINE_VISIBILITY
explicit __async_func(_Fp&& __f, _Args&&... __args)
: __f_(_VSTD::move(__f), _VSTD::move(__args)...) {}
_LIBCPP_INLINE_VISIBILITY
__async_func(__async_func&& __f) : __f_(_VSTD::move(__f.__f_)) {}
_Rp operator()()
{
typedef typename __make_tuple_indices<1+sizeof...(_Args), 1>::type _Index;
return __execute(_Index());
}
private:
template <size_t ..._Indices>
_Rp
__execute(__tuple_indices<_Indices...>)
{
return __invoke(_VSTD::move(_VSTD::get<0>(__f_)), _VSTD::move(_VSTD::get<_Indices>(__f_))...);
}
};
inline _LIBCPP_INLINE_VISIBILITY bool __does_policy_contain(launch __policy, launch __value )
{ return (int(__policy) & int(__value)) != 0; }
template <class _Fp, class... _Args>
_LIBCPP_NODISCARD_AFTER_CXX17
future<typename __invoke_of<typename decay<_Fp>::type, typename decay<_Args>::type...>::type>
async(launch __policy, _Fp&& __f, _Args&&... __args)
{
typedef __async_func<typename decay<_Fp>::type, typename decay<_Args>::type...> _BF;
typedef typename _BF::_Rp _Rp;
#ifndef _LIBCPP_NO_EXCEPTIONS
try
{
#endif
if (__does_policy_contain(__policy, launch::async))
return _VSTD::__make_async_assoc_state<_Rp>(_BF(__decay_copy(_VSTD::forward<_Fp>(__f)),
__decay_copy(_VSTD::forward<_Args>(__args))...));
#ifndef _LIBCPP_NO_EXCEPTIONS
}
catch ( ... ) { if (__policy == launch::async) throw ; }
#endif
if (__does_policy_contain(__policy, launch::deferred))
return _VSTD::__make_deferred_assoc_state<_Rp>(_BF(__decay_copy(_VSTD::forward<_Fp>(__f)),
__decay_copy(_VSTD::forward<_Args>(__args))...));
return future<_Rp>{};
}
template <class _Fp, class... _Args>
_LIBCPP_NODISCARD_AFTER_CXX17 inline _LIBCPP_INLINE_VISIBILITY
future<typename __invoke_of<typename decay<_Fp>::type, typename decay<_Args>::type...>::type>
async(_Fp&& __f, _Args&&... __args)
{
return _VSTD::async(launch::any, _VSTD::forward<_Fp>(__f),
_VSTD::forward<_Args>(__args)...);
}
#endif // _LIBCPP_HAS_NO_VARIADICS
// shared_future
template <class _Rp>
class _LIBCPP_TEMPLATE_VIS shared_future
{
__assoc_state<_Rp>* __state_;
public:
_LIBCPP_INLINE_VISIBILITY
shared_future() _NOEXCEPT : __state_(nullptr) {}
_LIBCPP_INLINE_VISIBILITY
shared_future(const shared_future& __rhs) _NOEXCEPT : __state_(__rhs.__state_)
{if (__state_) __state_->__add_shared();}
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
_LIBCPP_INLINE_VISIBILITY
shared_future(future<_Rp>&& __f) _NOEXCEPT : __state_(__f.__state_)
{__f.__state_ = nullptr;}
_LIBCPP_INLINE_VISIBILITY
shared_future(shared_future&& __rhs) _NOEXCEPT : __state_(__rhs.__state_)
{__rhs.__state_ = nullptr;}
#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
~shared_future();
shared_future& operator=(const shared_future& __rhs) _NOEXCEPT;
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
_LIBCPP_INLINE_VISIBILITY
shared_future& operator=(shared_future&& __rhs) _NOEXCEPT
{
shared_future(std::move(__rhs)).swap(*this);
return *this;
}
#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
// retrieving the value
_LIBCPP_INLINE_VISIBILITY
const _Rp& get() const {return __state_->copy();}
_LIBCPP_INLINE_VISIBILITY
void swap(shared_future& __rhs) _NOEXCEPT {_VSTD::swap(__state_, __rhs.__state_);}
// functions to check state
_LIBCPP_INLINE_VISIBILITY
bool valid() const _NOEXCEPT {return __state_ != nullptr;}
_LIBCPP_INLINE_VISIBILITY
void wait() const {__state_->wait();}
template <class _Rep, class _Period>
_LIBCPP_INLINE_VISIBILITY
future_status
wait_for(const chrono::duration<_Rep, _Period>& __rel_time) const
{return __state_->wait_for(__rel_time);}
template <class _Clock, class _Duration>
_LIBCPP_INLINE_VISIBILITY
future_status
wait_until(const chrono::time_point<_Clock, _Duration>& __abs_time) const
{return __state_->wait_until(__abs_time);}
};
template <class _Rp>
shared_future<_Rp>::~shared_future()
{
if (__state_)
__state_->__release_shared();
}
template <class _Rp>
shared_future<_Rp>&
shared_future<_Rp>::operator=(const shared_future& __rhs) _NOEXCEPT
{
if (__rhs.__state_)
__rhs.__state_->__add_shared();
if (__state_)
__state_->__release_shared();
__state_ = __rhs.__state_;
return *this;
}
template <class _Rp>
class _LIBCPP_TEMPLATE_VIS shared_future<_Rp&>
{
__assoc_state<_Rp&>* __state_;
public:
_LIBCPP_INLINE_VISIBILITY
shared_future() _NOEXCEPT : __state_(nullptr) {}
_LIBCPP_INLINE_VISIBILITY
shared_future(const shared_future& __rhs) : __state_(__rhs.__state_)
{if (__state_) __state_->__add_shared();}
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
_LIBCPP_INLINE_VISIBILITY
shared_future(future<_Rp&>&& __f) _NOEXCEPT : __state_(__f.__state_)
{__f.__state_ = nullptr;}
_LIBCPP_INLINE_VISIBILITY
shared_future(shared_future&& __rhs) _NOEXCEPT : __state_(__rhs.__state_)
{__rhs.__state_ = nullptr;}
#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
~shared_future();
shared_future& operator=(const shared_future& __rhs);
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
_LIBCPP_INLINE_VISIBILITY
shared_future& operator=(shared_future&& __rhs) _NOEXCEPT
{
shared_future(std::move(__rhs)).swap(*this);
return *this;
}
#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
// retrieving the value
_LIBCPP_INLINE_VISIBILITY
_Rp& get() const {return __state_->copy();}
_LIBCPP_INLINE_VISIBILITY
void swap(shared_future& __rhs) _NOEXCEPT {_VSTD::swap(__state_, __rhs.__state_);}
// functions to check state
_LIBCPP_INLINE_VISIBILITY
bool valid() const _NOEXCEPT {return __state_ != nullptr;}
_LIBCPP_INLINE_VISIBILITY
void wait() const {__state_->wait();}
template <class _Rep, class _Period>
_LIBCPP_INLINE_VISIBILITY
future_status
wait_for(const chrono::duration<_Rep, _Period>& __rel_time) const
{return __state_->wait_for(__rel_time);}
template <class _Clock, class _Duration>
_LIBCPP_INLINE_VISIBILITY
future_status
wait_until(const chrono::time_point<_Clock, _Duration>& __abs_time) const
{return __state_->wait_until(__abs_time);}
};
template <class _Rp>
shared_future<_Rp&>::~shared_future()
{
if (__state_)
__state_->__release_shared();
}
template <class _Rp>
shared_future<_Rp&>&
shared_future<_Rp&>::operator=(const shared_future& __rhs)
{
if (__rhs.__state_)
__rhs.__state_->__add_shared();
if (__state_)
__state_->__release_shared();
__state_ = __rhs.__state_;
return *this;
}
template <>
class _LIBCPP_TYPE_VIS _LIBCPP_AVAILABILITY_FUTURE shared_future<void>
{
__assoc_sub_state* __state_;
public:
_LIBCPP_INLINE_VISIBILITY
shared_future() _NOEXCEPT : __state_(nullptr) {}
_LIBCPP_INLINE_VISIBILITY
shared_future(const shared_future& __rhs) : __state_(__rhs.__state_)
{if (__state_) __state_->__add_shared();}
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
_LIBCPP_INLINE_VISIBILITY
shared_future(future<void>&& __f) _NOEXCEPT : __state_(__f.__state_)
{__f.__state_ = nullptr;}
_LIBCPP_INLINE_VISIBILITY
shared_future(shared_future&& __rhs) _NOEXCEPT : __state_(__rhs.__state_)
{__rhs.__state_ = nullptr;}
#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
~shared_future();
shared_future& operator=(const shared_future& __rhs);
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
_LIBCPP_INLINE_VISIBILITY
shared_future& operator=(shared_future&& __rhs) _NOEXCEPT
{
shared_future(std::move(__rhs)).swap(*this);
return *this;
}
#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
// retrieving the value
_LIBCPP_INLINE_VISIBILITY
void get() const {__state_->copy();}
_LIBCPP_INLINE_VISIBILITY
void swap(shared_future& __rhs) _NOEXCEPT {_VSTD::swap(__state_, __rhs.__state_);}
// functions to check state
_LIBCPP_INLINE_VISIBILITY
bool valid() const _NOEXCEPT {return __state_ != nullptr;}
_LIBCPP_INLINE_VISIBILITY
void wait() const {__state_->wait();}
template <class _Rep, class _Period>
_LIBCPP_INLINE_VISIBILITY
future_status
wait_for(const chrono::duration<_Rep, _Period>& __rel_time) const
{return __state_->wait_for(__rel_time);}
template <class _Clock, class _Duration>
_LIBCPP_INLINE_VISIBILITY
future_status
wait_until(const chrono::time_point<_Clock, _Duration>& __abs_time) const
{return __state_->wait_until(__abs_time);}
};
template <class _Rp>
inline _LIBCPP_INLINE_VISIBILITY
void
swap(shared_future<_Rp>& __x, shared_future<_Rp>& __y) _NOEXCEPT
{
__x.swap(__y);
}
template <class _Rp>
inline
shared_future<_Rp>
future<_Rp>::share() _NOEXCEPT
{
return shared_future<_Rp>(_VSTD::move(*this));
}
template <class _Rp>
inline
shared_future<_Rp&>
future<_Rp&>::share() _NOEXCEPT
{
return shared_future<_Rp&>(_VSTD::move(*this));
}
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
inline
shared_future<void>
future<void>::share() _NOEXCEPT
{
return shared_future<void>(_VSTD::move(*this));
}
#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
_LIBCPP_END_NAMESPACE_STD
#endif // !_LIBCPP_HAS_NO_THREADS
#endif // _LIBCPP_FUTURE
| 72,527 | 2,610 | jart/cosmopolitan | false |
cosmopolitan/third_party/libcxx/ratio | // -*- C++ -*-
//===---------------------------- ratio -----------------------------------===//
//
// 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_RATIO
#define _LIBCPP_RATIO
#include "third_party/libcxx/__config"
#include "third_party/libcxx/cstdint"
#include "third_party/libcxx/climits"
#include "third_party/libcxx/type_traits"
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
#pragma GCC system_header
#endif
_LIBCPP_PUSH_MACROS
#include "third_party/libcxx/__undef_macros"
_LIBCPP_BEGIN_NAMESPACE_STD
/*
ratio synopsis
namespace std
{
template <intmax_t N, intmax_t D = 1>
class ratio
{
public:
static constexpr intmax_t num;
static constexpr intmax_t den;
typedef ratio<num, den> type;
};
// ratio arithmetic
template <class R1, class R2> using ratio_add = ...;
template <class R1, class R2> using ratio_subtract = ...;
template <class R1, class R2> using ratio_multiply = ...;
template <class R1, class R2> using ratio_divide = ...;
// ratio comparison
template <class R1, class R2> struct ratio_equal;
template <class R1, class R2> struct ratio_not_equal;
template <class R1, class R2> struct ratio_less;
template <class R1, class R2> struct ratio_less_equal;
template <class R1, class R2> struct ratio_greater;
template <class R1, class R2> struct ratio_greater_equal;
// convenience SI typedefs
typedef ratio<1, 1000000000000000000000000> yocto; // not supported
typedef ratio<1, 1000000000000000000000> zepto; // not supported
typedef ratio<1, 1000000000000000000> atto;
typedef ratio<1, 1000000000000000> femto;
typedef ratio<1, 1000000000000> pico;
typedef ratio<1, 1000000000> nano;
typedef ratio<1, 1000000> micro;
typedef ratio<1, 1000> milli;
typedef ratio<1, 100> centi;
typedef ratio<1, 10> deci;
typedef ratio< 10, 1> deca;
typedef ratio< 100, 1> hecto;
typedef ratio< 1000, 1> kilo;
typedef ratio< 1000000, 1> mega;
typedef ratio< 1000000000, 1> giga;
typedef ratio< 1000000000000, 1> tera;
typedef ratio< 1000000000000000, 1> peta;
typedef ratio< 1000000000000000000, 1> exa;
typedef ratio< 1000000000000000000000, 1> zetta; // not supported
typedef ratio<1000000000000000000000000, 1> yotta; // not supported
// 20.11.5, ratio comparison
template <class R1, class R2> inline constexpr bool ratio_equal_v
= ratio_equal<R1, R2>::value; // C++17
template <class R1, class R2> inline constexpr bool ratio_not_equal_v
= ratio_not_equal<R1, R2>::value; // C++17
template <class R1, class R2> inline constexpr bool ratio_less_v
= ratio_less<R1, R2>::value; // C++17
template <class R1, class R2> inline constexpr bool ratio_less_equal_v
= ratio_less_equal<R1, R2>::value; // C++17
template <class R1, class R2> inline constexpr bool ratio_greater_v
= ratio_greater<R1, R2>::value; // C++17
template <class R1, class R2> inline constexpr bool ratio_greater_equal_v
= ratio_greater_equal<R1, R2>::value; // C++17
}
*/
// __static_gcd
template <intmax_t _Xp, intmax_t _Yp>
struct __static_gcd
{
static const intmax_t value = __static_gcd<_Yp, _Xp % _Yp>::value;
};
template <intmax_t _Xp>
struct __static_gcd<_Xp, 0>
{
static const intmax_t value = _Xp;
};
template <>
struct __static_gcd<0, 0>
{
static const intmax_t value = 1;
};
// __static_lcm
template <intmax_t _Xp, intmax_t _Yp>
struct __static_lcm
{
static const intmax_t value = _Xp / __static_gcd<_Xp, _Yp>::value * _Yp;
};
template <intmax_t _Xp>
struct __static_abs
{
static const intmax_t value = _Xp < 0 ? -_Xp : _Xp;
};
template <intmax_t _Xp>
struct __static_sign
{
static const intmax_t value = _Xp == 0 ? 0 : (_Xp < 0 ? -1 : 1);
};
template <intmax_t _Xp, intmax_t _Yp, intmax_t = __static_sign<_Yp>::value>
class __ll_add;
template <intmax_t _Xp, intmax_t _Yp>
class __ll_add<_Xp, _Yp, 1>
{
static const intmax_t min = (1LL << (sizeof(intmax_t) * CHAR_BIT - 1)) + 1;
static const intmax_t max = -min;
static_assert(_Xp <= max - _Yp, "overflow in __ll_add");
public:
static const intmax_t value = _Xp + _Yp;
};
template <intmax_t _Xp, intmax_t _Yp>
class __ll_add<_Xp, _Yp, 0>
{
public:
static const intmax_t value = _Xp;
};
template <intmax_t _Xp, intmax_t _Yp>
class __ll_add<_Xp, _Yp, -1>
{
static const intmax_t min = (1LL << (sizeof(intmax_t) * CHAR_BIT - 1)) + 1;
static const intmax_t max = -min;
static_assert(min - _Yp <= _Xp, "overflow in __ll_add");
public:
static const intmax_t value = _Xp + _Yp;
};
template <intmax_t _Xp, intmax_t _Yp, intmax_t = __static_sign<_Yp>::value>
class __ll_sub;
template <intmax_t _Xp, intmax_t _Yp>
class __ll_sub<_Xp, _Yp, 1>
{
static const intmax_t min = (1LL << (sizeof(intmax_t) * CHAR_BIT - 1)) + 1;
static const intmax_t max = -min;
static_assert(min + _Yp <= _Xp, "overflow in __ll_sub");
public:
static const intmax_t value = _Xp - _Yp;
};
template <intmax_t _Xp, intmax_t _Yp>
class __ll_sub<_Xp, _Yp, 0>
{
public:
static const intmax_t value = _Xp;
};
template <intmax_t _Xp, intmax_t _Yp>
class __ll_sub<_Xp, _Yp, -1>
{
static const intmax_t min = (1LL << (sizeof(intmax_t) * CHAR_BIT - 1)) + 1;
static const intmax_t max = -min;
static_assert(_Xp <= max + _Yp, "overflow in __ll_sub");
public:
static const intmax_t value = _Xp - _Yp;
};
template <intmax_t _Xp, intmax_t _Yp>
class __ll_mul
{
static const intmax_t nan = (1LL << (sizeof(intmax_t) * CHAR_BIT - 1));
static const intmax_t min = nan + 1;
static const intmax_t max = -min;
static const intmax_t __a_x = __static_abs<_Xp>::value;
static const intmax_t __a_y = __static_abs<_Yp>::value;
static_assert(_Xp != nan && _Yp != nan && __a_x <= max / __a_y, "overflow in __ll_mul");
public:
static const intmax_t value = _Xp * _Yp;
};
template <intmax_t _Yp>
class __ll_mul<0, _Yp>
{
public:
static const intmax_t value = 0;
};
template <intmax_t _Xp>
class __ll_mul<_Xp, 0>
{
public:
static const intmax_t value = 0;
};
template <>
class __ll_mul<0, 0>
{
public:
static const intmax_t value = 0;
};
// Not actually used but left here in case needed in future maintenance
template <intmax_t _Xp, intmax_t _Yp>
class __ll_div
{
static const intmax_t nan = (1LL << (sizeof(intmax_t) * CHAR_BIT - 1));
static const intmax_t min = nan + 1;
static const intmax_t max = -min;
static_assert(_Xp != nan && _Yp != nan && _Yp != 0, "overflow in __ll_div");
public:
static const intmax_t value = _Xp / _Yp;
};
template <intmax_t _Num, intmax_t _Den = 1>
class _LIBCPP_TEMPLATE_VIS ratio
{
static_assert(__static_abs<_Num>::value >= 0, "ratio numerator is out of range");
static_assert(_Den != 0, "ratio divide by 0");
static_assert(__static_abs<_Den>::value > 0, "ratio denominator is out of range");
static _LIBCPP_CONSTEXPR const intmax_t __na = __static_abs<_Num>::value;
static _LIBCPP_CONSTEXPR const intmax_t __da = __static_abs<_Den>::value;
static _LIBCPP_CONSTEXPR const intmax_t __s = __static_sign<_Num>::value * __static_sign<_Den>::value;
static _LIBCPP_CONSTEXPR const intmax_t __gcd = __static_gcd<__na, __da>::value;
public:
static _LIBCPP_CONSTEXPR const intmax_t num = __s * __na / __gcd;
static _LIBCPP_CONSTEXPR const intmax_t den = __da / __gcd;
typedef ratio<num, den> type;
};
template <intmax_t _Num, intmax_t _Den>
_LIBCPP_CONSTEXPR const intmax_t ratio<_Num, _Den>::num;
template <intmax_t _Num, intmax_t _Den>
_LIBCPP_CONSTEXPR const intmax_t ratio<_Num, _Den>::den;
template <class _Tp> struct __is_ratio : false_type {};
template <intmax_t _Num, intmax_t _Den> struct __is_ratio<ratio<_Num, _Den> > : true_type {};
typedef ratio<1LL, 1000000000000000000LL> atto;
typedef ratio<1LL, 1000000000000000LL> femto;
typedef ratio<1LL, 1000000000000LL> pico;
typedef ratio<1LL, 1000000000LL> nano;
typedef ratio<1LL, 1000000LL> micro;
typedef ratio<1LL, 1000LL> milli;
typedef ratio<1LL, 100LL> centi;
typedef ratio<1LL, 10LL> deci;
typedef ratio< 10LL, 1LL> deca;
typedef ratio< 100LL, 1LL> hecto;
typedef ratio< 1000LL, 1LL> kilo;
typedef ratio< 1000000LL, 1LL> mega;
typedef ratio< 1000000000LL, 1LL> giga;
typedef ratio< 1000000000000LL, 1LL> tera;
typedef ratio< 1000000000000000LL, 1LL> peta;
typedef ratio<1000000000000000000LL, 1LL> exa;
template <class _R1, class _R2>
struct __ratio_multiply
{
private:
static const intmax_t __gcd_n1_d2 = __static_gcd<_R1::num, _R2::den>::value;
static const intmax_t __gcd_d1_n2 = __static_gcd<_R1::den, _R2::num>::value;
public:
typedef typename ratio
<
__ll_mul<_R1::num / __gcd_n1_d2, _R2::num / __gcd_d1_n2>::value,
__ll_mul<_R2::den / __gcd_n1_d2, _R1::den / __gcd_d1_n2>::value
>::type type;
};
#ifndef _LIBCPP_CXX03_LANG
template <class _R1, class _R2> using ratio_multiply
= typename __ratio_multiply<_R1, _R2>::type;
#else // _LIBCPP_CXX03_LANG
template <class _R1, class _R2>
struct _LIBCPP_TEMPLATE_VIS ratio_multiply
: public __ratio_multiply<_R1, _R2>::type {};
#endif // _LIBCPP_CXX03_LANG
template <class _R1, class _R2>
struct __ratio_divide
{
private:
static const intmax_t __gcd_n1_n2 = __static_gcd<_R1::num, _R2::num>::value;
static const intmax_t __gcd_d1_d2 = __static_gcd<_R1::den, _R2::den>::value;
public:
typedef typename ratio
<
__ll_mul<_R1::num / __gcd_n1_n2, _R2::den / __gcd_d1_d2>::value,
__ll_mul<_R2::num / __gcd_n1_n2, _R1::den / __gcd_d1_d2>::value
>::type type;
};
#ifndef _LIBCPP_CXX03_LANG
template <class _R1, class _R2> using ratio_divide
= typename __ratio_divide<_R1, _R2>::type;
#else // _LIBCPP_CXX03_LANG
template <class _R1, class _R2>
struct _LIBCPP_TEMPLATE_VIS ratio_divide
: public __ratio_divide<_R1, _R2>::type {};
#endif // _LIBCPP_CXX03_LANG
template <class _R1, class _R2>
struct __ratio_add
{
private:
static const intmax_t __gcd_n1_n2 = __static_gcd<_R1::num, _R2::num>::value;
static const intmax_t __gcd_d1_d2 = __static_gcd<_R1::den, _R2::den>::value;
public:
typedef typename ratio_multiply
<
ratio<__gcd_n1_n2, _R1::den / __gcd_d1_d2>,
ratio
<
__ll_add
<
__ll_mul<_R1::num / __gcd_n1_n2, _R2::den / __gcd_d1_d2>::value,
__ll_mul<_R2::num / __gcd_n1_n2, _R1::den / __gcd_d1_d2>::value
>::value,
_R2::den
>
>::type type;
};
#ifndef _LIBCPP_CXX03_LANG
template <class _R1, class _R2> using ratio_add
= typename __ratio_add<_R1, _R2>::type;
#else // _LIBCPP_CXX03_LANG
template <class _R1, class _R2>
struct _LIBCPP_TEMPLATE_VIS ratio_add
: public __ratio_add<_R1, _R2>::type {};
#endif // _LIBCPP_CXX03_LANG
template <class _R1, class _R2>
struct __ratio_subtract
{
private:
static const intmax_t __gcd_n1_n2 = __static_gcd<_R1::num, _R2::num>::value;
static const intmax_t __gcd_d1_d2 = __static_gcd<_R1::den, _R2::den>::value;
public:
typedef typename ratio_multiply
<
ratio<__gcd_n1_n2, _R1::den / __gcd_d1_d2>,
ratio
<
__ll_sub
<
__ll_mul<_R1::num / __gcd_n1_n2, _R2::den / __gcd_d1_d2>::value,
__ll_mul<_R2::num / __gcd_n1_n2, _R1::den / __gcd_d1_d2>::value
>::value,
_R2::den
>
>::type type;
};
#ifndef _LIBCPP_CXX03_LANG
template <class _R1, class _R2> using ratio_subtract
= typename __ratio_subtract<_R1, _R2>::type;
#else // _LIBCPP_CXX03_LANG
template <class _R1, class _R2>
struct _LIBCPP_TEMPLATE_VIS ratio_subtract
: public __ratio_subtract<_R1, _R2>::type {};
#endif // _LIBCPP_CXX03_LANG
// ratio_equal
template <class _R1, class _R2>
struct _LIBCPP_TEMPLATE_VIS ratio_equal
: public _LIBCPP_BOOL_CONSTANT((_R1::num == _R2::num && _R1::den == _R2::den)) {};
template <class _R1, class _R2>
struct _LIBCPP_TEMPLATE_VIS ratio_not_equal
: public _LIBCPP_BOOL_CONSTANT((!ratio_equal<_R1, _R2>::value)) {};
// ratio_less
template <class _R1, class _R2, bool _Odd = false,
intmax_t _Q1 = _R1::num / _R1::den, intmax_t _M1 = _R1::num % _R1::den,
intmax_t _Q2 = _R2::num / _R2::den, intmax_t _M2 = _R2::num % _R2::den>
struct __ratio_less1
{
static const bool value = _Odd ? _Q2 < _Q1 : _Q1 < _Q2;
};
template <class _R1, class _R2, bool _Odd, intmax_t _Qp>
struct __ratio_less1<_R1, _R2, _Odd, _Qp, 0, _Qp, 0>
{
static const bool value = false;
};
template <class _R1, class _R2, bool _Odd, intmax_t _Qp, intmax_t _M2>
struct __ratio_less1<_R1, _R2, _Odd, _Qp, 0, _Qp, _M2>
{
static const bool value = !_Odd;
};
template <class _R1, class _R2, bool _Odd, intmax_t _Qp, intmax_t _M1>
struct __ratio_less1<_R1, _R2, _Odd, _Qp, _M1, _Qp, 0>
{
static const bool value = _Odd;
};
template <class _R1, class _R2, bool _Odd, intmax_t _Qp, intmax_t _M1,
intmax_t _M2>
struct __ratio_less1<_R1, _R2, _Odd, _Qp, _M1, _Qp, _M2>
{
static const bool value = __ratio_less1<ratio<_R1::den, _M1>,
ratio<_R2::den, _M2>, !_Odd>::value;
};
template <class _R1, class _R2, intmax_t _S1 = __static_sign<_R1::num>::value,
intmax_t _S2 = __static_sign<_R2::num>::value>
struct __ratio_less
{
static const bool value = _S1 < _S2;
};
template <class _R1, class _R2>
struct __ratio_less<_R1, _R2, 1LL, 1LL>
{
static const bool value = __ratio_less1<_R1, _R2>::value;
};
template <class _R1, class _R2>
struct __ratio_less<_R1, _R2, -1LL, -1LL>
{
static const bool value = __ratio_less1<ratio<-_R2::num, _R2::den>, ratio<-_R1::num, _R1::den> >::value;
};
template <class _R1, class _R2>
struct _LIBCPP_TEMPLATE_VIS ratio_less
: public _LIBCPP_BOOL_CONSTANT((__ratio_less<_R1, _R2>::value)) {};
template <class _R1, class _R2>
struct _LIBCPP_TEMPLATE_VIS ratio_less_equal
: public _LIBCPP_BOOL_CONSTANT((!ratio_less<_R2, _R1>::value)) {};
template <class _R1, class _R2>
struct _LIBCPP_TEMPLATE_VIS ratio_greater
: public _LIBCPP_BOOL_CONSTANT((ratio_less<_R2, _R1>::value)) {};
template <class _R1, class _R2>
struct _LIBCPP_TEMPLATE_VIS ratio_greater_equal
: public _LIBCPP_BOOL_CONSTANT((!ratio_less<_R1, _R2>::value)) {};
template <class _R1, class _R2>
struct __ratio_gcd
{
typedef ratio<__static_gcd<_R1::num, _R2::num>::value,
__static_lcm<_R1::den, _R2::den>::value> type;
};
#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
template <class _R1, class _R2>
_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool ratio_equal_v
= ratio_equal<_R1, _R2>::value;
template <class _R1, class _R2>
_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool ratio_not_equal_v
= ratio_not_equal<_R1, _R2>::value;
template <class _R1, class _R2>
_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool ratio_less_v
= ratio_less<_R1, _R2>::value;
template <class _R1, class _R2>
_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool ratio_less_equal_v
= ratio_less_equal<_R1, _R2>::value;
template <class _R1, class _R2>
_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool ratio_greater_v
= ratio_greater<_R1, _R2>::value;
template <class _R1, class _R2>
_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool ratio_greater_equal_v
= ratio_greater_equal<_R1, _R2>::value;
#endif
_LIBCPP_END_NAMESPACE_STD
_LIBCPP_POP_MACROS
#endif // _LIBCPP_RATIO
| 16,524 | 533 | jart/cosmopolitan | false |
cosmopolitan/third_party/libcxx/__tree | // -*- 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 "third_party/libcxx/__config"
#include "third_party/libcxx/iterator"
#include "third_party/libcxx/memory"
#include "third_party/libcxx/stdexcept"
#include "third_party/libcxx/algorithm"
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
#pragma GCC system_header
#endif
_LIBCPP_PUSH_MACROS
#include "third_party/libcxx/__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 = __tree_sub_invariant(__x->__left_);
if (__h == 0)
return 0; // invalid left subtree
if (__h != __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 (!__tree_is_left_child(__root))
return false;
// root must be black
if (!__root->__is_black_)
return false;
// do normal node checks
return __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 __tree_min(__x->__right_);
while (!__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>(__tree_min(__x->__right_));
while (!__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 __tree_max(__x->__left_);
_NodePtr __xx = static_cast<_NodePtr>(__x);
while (__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 (__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 (__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 (__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 (!__tree_is_left_child(__x))
{
__x = __x->__parent_unsafe();
__tree_left_rotate(__x);
}
__x = __x->__parent_unsafe();
__x->__is_black_ = true;
__x = __x->__parent_unsafe();
__x->__is_black_ = false;
__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 (__tree_is_left_child(__x))
{
__x = __x->__parent_unsafe();
__tree_right_rotate(__x);
}
__x = __x->__parent_unsafe();
__x->__is_black_ = true;
__x = __x->__parent_unsafe();
__x->__is_black_ = false;
__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 : __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 (__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 (__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 (!__tree_is_left_child(__w)) // if x is left child
{
if (!__w->__is_black_)
{
__w->__is_black_ = true;
__w->__parent_unsafe()->__is_black_ = false;
__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 = __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;
__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;
__tree_left_rotate(__w->__parent_unsafe());
break;
}
}
else
{
if (!__w->__is_black_)
{
__w->__is_black_ = true;
__w->__parent_unsafe()->__is_black_ = false;
__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 = __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;
__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;
__tree_right_rotate(__w->__parent_unsafe());
break;
}
}
}
}
}
}
// node traits
#ifndef _LIBCPP_CXX03_LANG
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<typename __uncvref<_One>::type> {};
#endif
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);
}
#ifndef _LIBCPP_CXX03_LANG
_LIBCPP_INLINE_VISIBILITY
static __container_value_type&& __move(__node_value_type& __v) {
return _VSTD::move(__v);
}
#endif
};
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());
}
#ifndef _LIBCPP_CXX03_LANG
_LIBCPP_INLINE_VISIBILITY
static pair<key_type&&, mapped_type&&> __move(__node_value_type& __v) {
return __v.__move();
}
#endif
};
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 __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() _LIBCPP_EQUAL_DELETE;
__tree_node_base(__tree_node_base const&) _LIBCPP_EQUAL_DELETE;
__tree_node_base& operator=(__tree_node_base const&) _LIBCPP_EQUAL_DELETE;
};
template <class _Tp, class _VoidPtr>
class __tree_node
: public __tree_node_base<_VoidPtr>
{
public:
typedef _Tp __node_value_type;
__node_value_type __value_;
private:
~__tree_node() _LIBCPP_EQUAL_DELETE;
__tree_node(__tree_node const&) _LIBCPP_EQUAL_DELETE;
__tree_node& operator=(__tree_node const&) _LIBCPP_EQUAL_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_;
__tree_node_destructor& operator=(const __tree_node_destructor&);
public:
bool __value_constructed;
_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>(
__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>(__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>(
__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>(__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(!std::__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);
#ifndef _LIBCPP_CXX03_LANG
__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);
#endif // _LIBCPP_CXX03_LANG
~__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 std::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
#ifndef _LIBCPP_CXX03_LANG
template <class _Key, class ..._Args>
pair<iterator, bool>
__emplace_unique_key_args(_Key const&, _Args&&... __args);
template <class _Key, class ..._Args>
iterator
__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));
}
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));
}
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));
}
#else
template <class _Key, class _Args>
_LIBCPP_INLINE_VISIBILITY
pair<iterator, bool> __emplace_unique_key_args(_Key const&, _Args& __args);
template <class _Key, class _Args>
_LIBCPP_INLINE_VISIBILITY
iterator __emplace_hint_unique_key_args(const_iterator, _Key const&, _Args&);
#endif
_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);
}
#ifdef _LIBCPP_CXX03_LANG
_LIBCPP_INLINE_VISIBILITY
iterator __insert_multi(const __container_value_type& __v);
_LIBCPP_INLINE_VISIBILITY
iterator __insert_multi(const_iterator __p, const __container_value_type& __v);
#else
_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));
}
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));
}
#endif // !_LIBCPP_CXX03_LANG
_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. Unfortunetly 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);
#ifndef _LIBCPP_CXX03_LANG
template <class ..._Args>
__node_holder __construct_node(_Args&& ...__args);
#else
__node_holder __construct_node(const __container_value_type& __v);
#endif
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_(__second_tag(), __node_allocator(__a)),
__pair3_(0)
{
__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_(__second_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 (__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>(__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>(__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 != &__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_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_(__second_tag(), __node_traits::select_on_container_copy_construction(__t.__node_alloc())),
__pair3_(0, __t.value_comp())
{
__begin_node() = __end_node();
}
#ifndef _LIBCPP_CXX03_LANG
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_(__second_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;
}
#endif // _LIBCPP_CXX03_LANG
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());
__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_);
__tree_balance_after_insert(__end_node()->__left_, __child);
++size();
}
#ifndef _LIBCPP_CXX03_LANG
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)
#else
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)
#endif
{
__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)
{
#ifndef _LIBCPP_CXX03_LANG
__node_holder __h = __construct_node(_VSTD::forward<_Args>(__args)...);
#else
__node_holder __h = __construct_node(__args);
#endif
__insert_node_at(__parent, __child, static_cast<__node_base_pointer>(__h.get()));
__r = __h.release();
__inserted = true;
}
return pair<iterator, bool>(iterator(__r), __inserted);
}
#ifndef _LIBCPP_CXX03_LANG
template <class _Tp, class _Compare, class _Allocator>
template <class _Key, class... _Args>
typename __tree<_Tp, _Compare, _Allocator>::iterator
__tree<_Tp, _Compare, _Allocator>::__emplace_hint_unique_key_args(
const_iterator __p, _Key const& __k, _Args&&... __args)
#else
template <class _Tp, class _Compare, class _Allocator>
template <class _Key, class _Args>
typename __tree<_Tp, _Compare, _Allocator>::iterator
__tree<_Tp, _Compare, _Allocator>::__emplace_hint_unique_key_args(
const_iterator __p, _Key const& __k, _Args& __args)
#endif
{
__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);
if (__child == nullptr)
{
#ifndef _LIBCPP_CXX03_LANG
__node_holder __h = __construct_node(_VSTD::forward<_Args>(__args)...);
#else
__node_holder __h = __construct_node(__args);
#endif
__insert_node_at(__parent, __child, static_cast<__node_base_pointer>(__h.get()));
__r = __h.release();
}
return iterator(__r);
}
#ifndef _LIBCPP_CXX03_LANG
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()));
}
#else // _LIBCPP_CXX03_LANG
template <class _Tp, class _Compare, class _Allocator>
typename __tree<_Tp, _Compare, _Allocator>::__node_holder
__tree<_Tp, _Compare, _Allocator>::__construct_node(const __container_value_type& __v)
{
__node_allocator& __na = __node_alloc();
__node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na));
__node_traits::construct(__na, _NodeTypes::__get_ptr(__h->__value_), __v);
__h.get_deleter().__value_constructed = true;
return _LIBCPP_EXPLICIT_MOVE(__h); // explicitly moved for C++03
}
#endif // _LIBCPP_CXX03_LANG
#ifdef _LIBCPP_CXX03_LANG
template <class _Tp, class _Compare, class _Allocator>
typename __tree<_Tp, _Compare, _Allocator>::iterator
__tree<_Tp, _Compare, _Allocator>::__insert_multi(const __container_value_type& __v)
{
__parent_pointer __parent;
__node_base_pointer& __child = __find_leaf_high(__parent, _NodeTypes::__get_key(__v));
__node_holder __h = __construct_node(__v);
__insert_node_at(__parent, __child, static_cast<__node_base_pointer>(__h.get()));
return iterator(__h.release());
}
template <class _Tp, class _Compare, class _Allocator>
typename __tree<_Tp, _Compare, _Allocator>::iterator
__tree<_Tp, _Compare, _Allocator>::__insert_multi(const_iterator __p, const __container_value_type& __v)
{
__parent_pointer __parent;
__node_base_pointer& __child = __find_leaf(__p, __parent, _NodeTypes::__get_key(__v));
__node_holder __h = __construct_node(__v);
__insert_node_at(__parent, __child, static_cast<__node_base_pointer>(__h.get()));
return iterator(__h.release());
}
#endif
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();
__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>(__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>(__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();
__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
| 104,818 | 2,844 | jart/cosmopolitan | false |
cosmopolitan/third_party/libcxx/bit | // -*- C++ -*-
//===------------------------------ bit ----------------------------------===//
//
// 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_BIT
#define _LIBCPP_BIT
#include "third_party/libcxx/__config"
#include "third_party/libcxx/limits"
#include "third_party/libcxx/type_traits"
#include "third_party/libcxx/version"
#include "third_party/libcxx/__debug"
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
#pragma GCC system_header
#endif
_LIBCPP_PUSH_MACROS
#include "third_party/libcxx/__undef_macros"
_LIBCPP_BEGIN_NAMESPACE_STD
/*
bit synopsis
namespace std {
template <class T>
constexpr bool ispow2(T x) noexcept; // C++20
template <class T>
constexpr T ceil2(T x); // C++20
template <class T>
constexpr T floor2(T x) noexcept; // C++20
template <class T>
constexpr T log2p1(T x) noexcept; // C++20
// 23.20.2, rotating
template<class T>
constexpr T rotl(T x, unsigned int s) noexcept; // C++20
template<class T>
constexpr T rotr(T x, unsigned int s) noexcept; // C++20
// 23.20.3, counting
template<class T>
constexpr int countl_zero(T x) noexcept; // C++20
template<class T>
constexpr int countl_one(T x) noexcept; // C++20
template<class T>
constexpr int countr_zero(T x) noexcept; // C++20
template<class T>
constexpr int countr_one(T x) noexcept; // C++20
template<class T>
constexpr int popcount(T x) noexcept; // C++20
// 20.15.9, endian
enum class endian {
little = see below, // C++20
big = see below, // C++20
native = see below // C++20
};
} // namespace std
*/
#ifndef _LIBCPP_COMPILER_MSVC
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
int __libcpp_ctz(unsigned __x) _NOEXCEPT { return __builtin_ctz(__x); }
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
int __libcpp_ctz(unsigned long __x) _NOEXCEPT { return __builtin_ctzl(__x); }
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
int __libcpp_ctz(unsigned long long __x) _NOEXCEPT { return __builtin_ctzll(__x); }
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
int __libcpp_clz(unsigned __x) _NOEXCEPT { return __builtin_clz(__x); }
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
int __libcpp_clz(unsigned long __x) _NOEXCEPT { return __builtin_clzl(__x); }
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
int __libcpp_clz(unsigned long long __x) _NOEXCEPT { return __builtin_clzll(__x); }
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
int __libcpp_popcount(unsigned __x) _NOEXCEPT { return __builtin_popcount(__x); }
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
int __libcpp_popcount(unsigned long __x) _NOEXCEPT { return __builtin_popcountl(__x); }
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
int __libcpp_popcount(unsigned long long __x) _NOEXCEPT { return __builtin_popcountll(__x); }
#else // _LIBCPP_COMPILER_MSVC
// Precondition: __x != 0
inline _LIBCPP_INLINE_VISIBILITY
int __libcpp_ctz(unsigned __x) {
static_assert(sizeof(unsigned) == sizeof(unsigned long), "");
static_assert(sizeof(unsigned long) == 4, "");
unsigned long __where;
if (_BitScanForward(&__where, __x))
return static_cast<int>(__where);
return 32;
}
inline _LIBCPP_INLINE_VISIBILITY
int __libcpp_ctz(unsigned long __x) {
static_assert(sizeof(unsigned long) == sizeof(unsigned), "");
return __ctz(static_cast<unsigned>(__x));
}
inline _LIBCPP_INLINE_VISIBILITY
int __libcpp_ctz(unsigned long long __x) {
unsigned long __where;
#if defined(_LIBCPP_HAS_BITSCAN64)
(defined(_M_AMD64) || defined(__x86_64__))
if (_BitScanForward64(&__where, __x))
return static_cast<int>(__where);
#else
// Win32 doesn't have _BitScanForward64 so emulate it with two 32 bit calls.
if (_BitScanForward(&__where, static_cast<unsigned long>(__x)))
return static_cast<int>(__where);
if (_BitScanForward(&__where, static_cast<unsigned long>(__x >> 32)))
return static_cast<int>(__where + 32);
#endif
return 64;
}
// Precondition: __x != 0
inline _LIBCPP_INLINE_VISIBILITY
int __libcpp_clz(unsigned __x) {
static_assert(sizeof(unsigned) == sizeof(unsigned long), "");
static_assert(sizeof(unsigned long) == 4, "");
unsigned long __where;
if (_BitScanReverse(&__where, __x))
return static_cast<int>(31 - __where);
return 32; // Undefined Behavior.
}
inline _LIBCPP_INLINE_VISIBILITY
int __libcpp_clz(unsigned long __x) {
static_assert(sizeof(unsigned) == sizeof(unsigned long), "");
return __libcpp_clz(static_cast<unsigned>(__x));
}
inline _LIBCPP_INLINE_VISIBILITY
int __libcpp_clz(unsigned long long __x) {
unsigned long __where;
#if defined(_LIBCPP_HAS_BITSCAN64)
if (_BitScanReverse64(&__where, __x))
return static_cast<int>(63 - __where);
#else
// Win32 doesn't have _BitScanReverse64 so emulate it with two 32 bit calls.
if (_BitScanReverse(&__where, static_cast<unsigned long>(__x >> 32)))
return static_cast<int>(63 - (__where + 32));
if (_BitScanReverse(&__where, static_cast<unsigned long>(__x)))
return static_cast<int>(63 - __where);
#endif
return 64; // Undefined Behavior.
}
inline _LIBCPP_INLINE_VISIBILITY int __libcpp_popcount(unsigned __x) {
static_assert(sizeof(unsigned) == 4, "");
return __popcnt(__x);
}
inline _LIBCPP_INLINE_VISIBILITY int __libcpp_popcount(unsigned long __x) {
static_assert(sizeof(unsigned long) == 4, "");
return __popcnt(__x);
}
inline _LIBCPP_INLINE_VISIBILITY int __libcpp_popcount(unsigned long long __x) {
static_assert(sizeof(unsigned long long) == 8, "");
return __popcnt64(__x);
}
#endif // _LIBCPP_COMPILER_MSVC
template <class _Tp>
using __bitop_unsigned_integer _LIBCPP_NODEBUG_TYPE = integral_constant<bool,
is_integral<_Tp>::value &&
is_unsigned<_Tp>::value &&
_IsNotSame<typename remove_cv<_Tp>::type, bool>::value &&
_IsNotSame<typename remove_cv<_Tp>::type, signed char>::value &&
_IsNotSame<typename remove_cv<_Tp>::type, wchar_t>::value &&
_IsNotSame<typename remove_cv<_Tp>::type, char16_t>::value &&
_IsNotSame<typename remove_cv<_Tp>::type, char32_t>::value
>;
template<class _Tp>
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
_Tp __rotl(_Tp __t, unsigned int __cnt) _NOEXCEPT
{
static_assert(__bitop_unsigned_integer<_Tp>::value, "__rotl requires unsigned");
const unsigned int __dig = numeric_limits<_Tp>::digits;
if ((__cnt % __dig) == 0)
return __t;
return (__t << (__cnt % __dig)) | (__t >> (__dig - (__cnt % __dig)));
}
template<class _Tp>
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
_Tp __rotr(_Tp __t, unsigned int __cnt) _NOEXCEPT
{
static_assert(__bitop_unsigned_integer<_Tp>::value, "__rotr requires unsigned");
const unsigned int __dig = numeric_limits<_Tp>::digits;
if ((__cnt % __dig) == 0)
return __t;
return (__t >> (__cnt % __dig)) | (__t << (__dig - (__cnt % __dig)));
}
template<class _Tp>
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
int __countr_zero(_Tp __t) _NOEXCEPT
{
static_assert(__bitop_unsigned_integer<_Tp>::value, "__countr_zero requires unsigned");
if (__t == 0)
return numeric_limits<_Tp>::digits;
if (sizeof(_Tp) <= sizeof(unsigned int))
return __libcpp_ctz(static_cast<unsigned int>(__t));
else if (sizeof(_Tp) <= sizeof(unsigned long))
return __libcpp_ctz(static_cast<unsigned long>(__t));
else if (sizeof(_Tp) <= sizeof(unsigned long long))
return __libcpp_ctz(static_cast<unsigned long long>(__t));
else
{
int __ret = 0;
int __iter = 0;
const unsigned int __ulldigits = numeric_limits<unsigned long long>::digits;
while ((__iter = __libcpp_ctz(static_cast<unsigned long long>(__t))) == __ulldigits)
{
__ret += __iter;
__t >>= __ulldigits;
}
return __ret + __iter;
}
}
template<class _Tp>
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
int __countl_zero(_Tp __t) _NOEXCEPT
{
static_assert(__bitop_unsigned_integer<_Tp>::value, "__countl_zero requires unsigned");
if (__t == 0)
return numeric_limits<_Tp>::digits;
if (sizeof(_Tp) <= sizeof(unsigned int))
return __libcpp_clz(static_cast<unsigned int>(__t))
- (numeric_limits<unsigned int>::digits - numeric_limits<_Tp>::digits);
else if (sizeof(_Tp) <= sizeof(unsigned long))
return __libcpp_clz(static_cast<unsigned long>(__t))
- (numeric_limits<unsigned long>::digits - numeric_limits<_Tp>::digits);
else if (sizeof(_Tp) <= sizeof(unsigned long long))
return __libcpp_clz(static_cast<unsigned long long>(__t))
- (numeric_limits<unsigned long long>::digits - numeric_limits<_Tp>::digits);
else
{
int __ret = 0;
int __iter = 0;
const unsigned int __ulldigits = numeric_limits<unsigned long long>::digits;
while (true) {
__t = __rotr(__t, __ulldigits);
if ((__iter = __countl_zero(static_cast<unsigned long long>(__t))) != __ulldigits)
break;
__ret += __iter;
}
return __ret + __iter;
}
}
template<class _Tp>
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
int __countl_one(_Tp __t) _NOEXCEPT
{
static_assert(__bitop_unsigned_integer<_Tp>::value, "__countl_one requires unsigned");
return __t != numeric_limits<_Tp>::max()
? __countl_zero(static_cast<_Tp>(~__t))
: numeric_limits<_Tp>::digits;
}
template<class _Tp>
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
int __countr_one(_Tp __t) _NOEXCEPT
{
static_assert(__bitop_unsigned_integer<_Tp>::value, "__countr_one requires unsigned");
return __t != numeric_limits<_Tp>::max()
? __countr_zero(static_cast<_Tp>(~__t))
: numeric_limits<_Tp>::digits;
}
template<class _Tp>
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
int
__popcount(_Tp __t) _NOEXCEPT
{
static_assert(__bitop_unsigned_integer<_Tp>::value, "__libcpp_popcount requires unsigned");
if (sizeof(_Tp) <= sizeof(unsigned int))
return __libcpp_popcount(static_cast<unsigned int>(__t));
else if (sizeof(_Tp) <= sizeof(unsigned long))
return __libcpp_popcount(static_cast<unsigned long>(__t));
else if (sizeof(_Tp) <= sizeof(unsigned long long))
return __libcpp_popcount(static_cast<unsigned long long>(__t));
else
{
int __ret = 0;
while (__t != 0)
{
__ret += __libcpp_popcount(static_cast<unsigned long long>(__t));
__t >>= numeric_limits<unsigned long long>::digits;
}
return __ret;
}
}
// integral log base 2
template<class _Tp>
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
unsigned __bit_log2(_Tp __t) _NOEXCEPT
{
static_assert(__bitop_unsigned_integer<_Tp>::value, "__bit_log2 requires unsigned");
return std::numeric_limits<_Tp>::digits - 1 - __countl_zero(__t);
}
template <class _Tp>
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
bool __ispow2(_Tp __t) _NOEXCEPT
{
static_assert(__bitop_unsigned_integer<_Tp>::value, "__ispow2 requires unsigned");
return __t != 0 && (((__t & (__t - 1)) == 0));
}
#if _LIBCPP_STD_VER > 17
template<class _Tp>
_LIBCPP_INLINE_VISIBILITY constexpr
enable_if_t<__bitop_unsigned_integer<_Tp>::value, _Tp>
rotl(_Tp __t, unsigned int __cnt) noexcept
{
return __rotl(__t, __cnt);
}
// rotr
template<class _Tp>
_LIBCPP_INLINE_VISIBILITY constexpr
enable_if_t<__bitop_unsigned_integer<_Tp>::value, _Tp>
rotr(_Tp __t, unsigned int __cnt) noexcept
{
return __rotr(__t, __cnt);
}
template<class _Tp>
_LIBCPP_INLINE_VISIBILITY constexpr
enable_if_t<__bitop_unsigned_integer<_Tp>::value, int>
countl_zero(_Tp __t) noexcept
{
return __countl_zero(__t);
}
template<class _Tp>
_LIBCPP_INLINE_VISIBILITY constexpr
enable_if_t<__bitop_unsigned_integer<_Tp>::value, int>
countl_one(_Tp __t) noexcept
{
return __countl_one(__t);
}
template<class _Tp>
_LIBCPP_INLINE_VISIBILITY constexpr
enable_if_t<__bitop_unsigned_integer<_Tp>::value, int>
countr_zero(_Tp __t) noexcept
{
return __countr_zero(__t);
}
template<class _Tp>
_LIBCPP_INLINE_VISIBILITY constexpr
enable_if_t<__bitop_unsigned_integer<_Tp>::value, int>
countr_one(_Tp __t) noexcept
{
return __countr_one(__t);
}
template<class _Tp>
_LIBCPP_INLINE_VISIBILITY constexpr
enable_if_t<__bitop_unsigned_integer<_Tp>::value, int>
popcount(_Tp __t) noexcept
{
return __popcount(__t);
}
template <class _Tp>
_LIBCPP_INLINE_VISIBILITY constexpr
enable_if_t<__bitop_unsigned_integer<_Tp>::value, bool>
ispow2(_Tp __t) noexcept
{
return __ispow2(__t);
}
template <class _Tp>
_LIBCPP_INLINE_VISIBILITY constexpr
enable_if_t<__bitop_unsigned_integer<_Tp>::value, _Tp>
floor2(_Tp __t) noexcept
{
return __t == 0 ? 0 : _Tp{1} << __bit_log2(__t);
}
template <class _Tp>
_LIBCPP_INLINE_VISIBILITY constexpr
enable_if_t<__bitop_unsigned_integer<_Tp>::value, _Tp>
ceil2(_Tp __t) noexcept
{
if (__t < 2) return 1;
const unsigned __n = numeric_limits<_Tp>::digits - countl_zero((_Tp)(__t - 1u));
_LIBCPP_DEBUG_ASSERT(__libcpp_is_constant_evaluated() || __n != numeric_limits<_Tp>::digits, "Bad input to ceil2");
if constexpr (sizeof(_Tp) >= sizeof(unsigned))
return _Tp{1} << __n;
else
{
const unsigned __extra = numeric_limits<unsigned>::digits - numeric_limits<_Tp>::digits;
const unsigned __retVal = 1u << (__n + __extra);
return (_Tp) (__retVal >> __extra);
}
}
template <class _Tp>
_LIBCPP_INLINE_VISIBILITY constexpr
enable_if_t<__bitop_unsigned_integer<_Tp>::value, _Tp>
log2p1(_Tp __t) noexcept
{
return __t == 0 ? 0 : __bit_log2(__t) + 1;
}
enum class endian
{
little = 0xDEAD,
big = 0xFACE,
#if defined(_LIBCPP_LITTLE_ENDIAN)
native = little
#elif defined(_LIBCPP_BIG_ENDIAN)
native = big
#else
native = 0xCAFE
#endif
};
#endif // _LIBCPP_STD_VER > 17
_LIBCPP_END_NAMESPACE_STD
_LIBCPP_POP_MACROS
#endif // _LIBCPP_BIT
| 14,404 | 480 | jart/cosmopolitan | false |
cosmopolitan/third_party/libcxx/execution | // -*- C++ -*-
// clang-format off
//===------------------------- execution ---------------------------------===//
//
// 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_EXECUTION
#define _LIBCPP_EXECUTION
#include "third_party/libcxx/__config"
#if defined(_LIBCPP_HAS_PARALLEL_ALGORITHMS) && _LIBCPP_STD_VER >= 17
# include "third_party/libcxx/__pstl_execution"
#endif
#endif // _LIBCPP_EXECUTION
| 651 | 21 | jart/cosmopolitan | false |
cosmopolitan/third_party/libcxx/__sso_allocator | // -*- C++ -*-
// clang-format off
//===----------------------------------------------------------------------===//
//
// 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___SSO_ALLOCATOR
#define _LIBCPP___SSO_ALLOCATOR
#include "third_party/libcxx/__config"
#include "third_party/libcxx/type_traits"
#include "third_party/libcxx/new"
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
#pragma GCC system_header
#endif
_LIBCPP_BEGIN_NAMESPACE_STD
template <class _Tp, size_t _Np> class _LIBCPP_HIDDEN __sso_allocator;
template <size_t _Np>
class _LIBCPP_HIDDEN __sso_allocator<void, _Np>
{
public:
typedef const void* const_pointer;
typedef void value_type;
};
template <class _Tp, size_t _Np>
class _LIBCPP_HIDDEN __sso_allocator
{
typename aligned_storage<sizeof(_Tp) * _Np>::type buf_;
bool __allocated_;
public:
typedef size_t size_type;
typedef _Tp* pointer;
typedef _Tp value_type;
_LIBCPP_INLINE_VISIBILITY __sso_allocator() throw() : __allocated_(false) {}
_LIBCPP_INLINE_VISIBILITY __sso_allocator(const __sso_allocator&) throw() : __allocated_(false) {}
template <class _Up> _LIBCPP_INLINE_VISIBILITY __sso_allocator(const __sso_allocator<_Up, _Np>&) throw()
: __allocated_(false) {}
private:
__sso_allocator& operator=(const __sso_allocator&);
public:
_LIBCPP_INLINE_VISIBILITY pointer allocate(size_type __n, typename __sso_allocator<void, _Np>::const_pointer = 0)
{
if (!__allocated_ && __n <= _Np)
{
__allocated_ = true;
return (pointer)&buf_;
}
return static_cast<pointer>(_VSTD::__libcpp_allocate(__n * sizeof(_Tp), _LIBCPP_ALIGNOF(_Tp)));
}
_LIBCPP_INLINE_VISIBILITY void deallocate(pointer __p, size_type __n)
{
if (__p == (pointer)&buf_)
__allocated_ = false;
else
_VSTD::__libcpp_deallocate(__p, __n * sizeof(_Tp), _LIBCPP_ALIGNOF(_Tp));
}
_LIBCPP_INLINE_VISIBILITY size_type max_size() const throw() {return size_type(~0) / sizeof(_Tp);}
_LIBCPP_INLINE_VISIBILITY
bool operator==(__sso_allocator& __a) const {return &buf_ == &__a.buf_;}
_LIBCPP_INLINE_VISIBILITY
bool operator!=(__sso_allocator& __a) const {return &buf_ != &__a.buf_;}
};
_LIBCPP_END_NAMESPACE_STD
#endif // _LIBCPP___SSO_ALLOCATOR
| 2,629 | 78 | jart/cosmopolitan | false |
cosmopolitan/third_party/libcxx/wctype.h | // -*- C++ -*-
//===--------------------------- wctype.h ---------------------------------===//
//
// 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_WCTYPE_H
#define _LIBCPP_WCTYPE_H
/*
wctype.h synopsis
Macros:
WEOF
Types:
wint_t
wctrans_t
wctype_t
int iswalnum(wint_t wc);
int iswalpha(wint_t wc);
int iswblank(wint_t wc); // C99
int iswcntrl(wint_t wc);
int iswdigit(wint_t wc);
int iswgraph(wint_t wc);
int iswlower(wint_t wc);
int iswprint(wint_t wc);
int iswpunct(wint_t wc);
int iswspace(wint_t wc);
int iswupper(wint_t wc);
int iswxdigit(wint_t wc);
int iswctype(wint_t wc, wctype_t desc);
wctype_t wctype(const char* property);
wint_t towlower(wint_t wc);
wint_t towupper(wint_t wc);
wint_t towctrans(wint_t wc, wctrans_t desc);
wctrans_t wctrans(const char* property);
*/
#include "third_party/libcxx/__config"
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
#pragma GCC system_header
#endif
#include "libc/str/str.h"
#include "libc/time/time.h"
#ifdef __cplusplus
#undef iswalnum
#undef iswalpha
#undef iswblank
#undef iswcntrl
#undef iswdigit
#undef iswgraph
#undef iswlower
#undef iswprint
#undef iswpunct
#undef iswspace
#undef iswupper
#undef iswxdigit
#undef iswctype
#undef wctype
#undef towlower
#undef towupper
#undef towctrans
#undef wctrans
#endif // __cplusplus
#endif // _LIBCPP_WCTYPE_H
| 1,600 | 80 | jart/cosmopolitan | false |
cosmopolitan/third_party/libcxx/cstdarg | // -*- C++ -*-
//===--------------------------- cstdarg ----------------------------------===//
//
// 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_CSTDARG
#define _LIBCPP_CSTDARG
#include "third_party/libcxx/__config"
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
#pragma GCC system_header
#endif
_LIBCPP_BEGIN_NAMESPACE_STD
/*
cstdarg synopsis
Macros:
type va_arg(va_list ap, type);
void va_copy(va_list dest, va_list src); // C99
void va_end(va_list ap);
void va_start(va_list ap, parmN);
namespace std
{
Types:
va_list
} // std
*/
using ::va_list;
_LIBCPP_END_NAMESPACE_STD
#endif // _LIBCPP_CSTDARG
| 902 | 47 | jart/cosmopolitan | false |
cosmopolitan/third_party/libcxx/variant | // -*- C++ -*-
// clang-format off
//===------------------------------ variant -------------------------------===//
//
// 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_VARIANT
#define _LIBCPP_VARIANT
#include "third_party/libcxx/__config"
#include "third_party/libcxx/__tuple"
#include "third_party/libcxx/array"
#include "third_party/libcxx/exception"
#include "third_party/libcxx/functional"
#include "third_party/libcxx/initializer_list"
#include "third_party/libcxx/new"
#include "third_party/libcxx/tuple"
#include "third_party/libcxx/type_traits"
#include "third_party/libcxx/utility"
#include "third_party/libcxx/limits"
#include "third_party/libcxx/version"
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
#pragma GCC system_header
#endif
_LIBCPP_PUSH_MACROS
#include "third_party/libcxx/__undef_macros"
/*
variant synopsis
namespace std {
// 20.7.2, class template variant
template <class... Types>
class variant {
public:
// 20.7.2.1, constructors
constexpr variant() noexcept(see below);
variant(const variant&); // constexpr in C++20
variant(variant&&) noexcept(see below); // constexpr in C++20
template <class T> constexpr variant(T&&) noexcept(see below);
template <class T, class... Args>
constexpr explicit variant(in_place_type_t<T>, Args&&...);
template <class T, class U, class... Args>
constexpr explicit variant(
in_place_type_t<T>, initializer_list<U>, Args&&...);
template <size_t I, class... Args>
constexpr explicit variant(in_place_index_t<I>, Args&&...);
template <size_t I, class U, class... Args>
constexpr explicit variant(
in_place_index_t<I>, initializer_list<U>, Args&&...);
// 20.7.2.2, destructor
~variant();
// 20.7.2.3, assignment
variant& operator=(const variant&); // constexpr in C++20
variant& operator=(variant&&) noexcept(see below); // constexpr in C++20
template <class T> variant& operator=(T&&) noexcept(see below);
// 20.7.2.4, modifiers
template <class T, class... Args>
T& emplace(Args&&...);
template <class T, class U, class... Args>
T& emplace(initializer_list<U>, Args&&...);
template <size_t I, class... Args>
variant_alternative_t<I, variant>& emplace(Args&&...);
template <size_t I, class U, class... Args>
variant_alternative_t<I, variant>& emplace(initializer_list<U>, Args&&...);
// 20.7.2.5, value status
constexpr bool valueless_by_exception() const noexcept;
constexpr size_t index() const noexcept;
// 20.7.2.6, swap
void swap(variant&) noexcept(see below);
};
// 20.7.3, variant helper classes
template <class T> struct variant_size; // undefined
template <class T>
inline constexpr size_t variant_size_v = variant_size<T>::value;
template <class T> struct variant_size<const T>;
template <class T> struct variant_size<volatile T>;
template <class T> struct variant_size<const volatile T>;
template <class... Types>
struct variant_size<variant<Types...>>;
template <size_t I, class T> struct variant_alternative; // undefined
template <size_t I, class T>
using variant_alternative_t = typename variant_alternative<I, T>::type;
template <size_t I, class T> struct variant_alternative<I, const T>;
template <size_t I, class T> struct variant_alternative<I, volatile T>;
template <size_t I, class T> struct variant_alternative<I, const volatile T>;
template <size_t I, class... Types>
struct variant_alternative<I, variant<Types...>>;
inline constexpr size_t variant_npos = -1;
// 20.7.4, value access
template <class T, class... Types>
constexpr bool holds_alternative(const variant<Types...>&) noexcept;
template <size_t I, class... Types>
constexpr variant_alternative_t<I, variant<Types...>>&
get(variant<Types...>&);
template <size_t I, class... Types>
constexpr variant_alternative_t<I, variant<Types...>>&&
get(variant<Types...>&&);
template <size_t I, class... Types>
constexpr variant_alternative_t<I, variant<Types...>> const&
get(const variant<Types...>&);
template <size_t I, class... Types>
constexpr variant_alternative_t<I, variant<Types...>> const&&
get(const variant<Types...>&&);
template <class T, class... Types>
constexpr T& get(variant<Types...>&);
template <class T, class... Types>
constexpr T&& get(variant<Types...>&&);
template <class T, class... Types>
constexpr const T& get(const variant<Types...>&);
template <class T, class... Types>
constexpr const T&& get(const variant<Types...>&&);
template <size_t I, class... Types>
constexpr add_pointer_t<variant_alternative_t<I, variant<Types...>>>
get_if(variant<Types...>*) noexcept;
template <size_t I, class... Types>
constexpr add_pointer_t<const variant_alternative_t<I, variant<Types...>>>
get_if(const variant<Types...>*) noexcept;
template <class T, class... Types>
constexpr add_pointer_t<T>
get_if(variant<Types...>*) noexcept;
template <class T, class... Types>
constexpr add_pointer_t<const T>
get_if(const variant<Types...>*) noexcept;
// 20.7.5, relational operators
template <class... Types>
constexpr bool operator==(const variant<Types...>&, const variant<Types...>&);
template <class... Types>
constexpr bool operator!=(const variant<Types...>&, const variant<Types...>&);
template <class... Types>
constexpr bool operator<(const variant<Types...>&, const variant<Types...>&);
template <class... Types>
constexpr bool operator>(const variant<Types...>&, const variant<Types...>&);
template <class... Types>
constexpr bool operator<=(const variant<Types...>&, const variant<Types...>&);
template <class... Types>
constexpr bool operator>=(const variant<Types...>&, const variant<Types...>&);
// 20.7.6, visitation
template <class Visitor, class... Variants>
constexpr see below visit(Visitor&&, Variants&&...);
// 20.7.7, class monostate
struct monostate;
// 20.7.8, monostate relational operators
constexpr bool operator<(monostate, monostate) noexcept;
constexpr bool operator>(monostate, monostate) noexcept;
constexpr bool operator<=(monostate, monostate) noexcept;
constexpr bool operator>=(monostate, monostate) noexcept;
constexpr bool operator==(monostate, monostate) noexcept;
constexpr bool operator!=(monostate, monostate) noexcept;
// 20.7.9, specialized algorithms
template <class... Types>
void swap(variant<Types...>&, variant<Types...>&) noexcept(see below);
// 20.7.10, class bad_variant_access
class bad_variant_access;
// 20.7.11, hash support
template <class T> struct hash;
template <class... Types> struct hash<variant<Types...>>;
template <> struct hash<monostate>;
} // namespace std
*/
namespace std { // explicitly not using versioning namespace
class _LIBCPP_EXCEPTION_ABI _LIBCPP_AVAILABILITY_BAD_VARIANT_ACCESS bad_variant_access : public exception {
public:
virtual const char* what() const _NOEXCEPT;
};
} // namespace std
_LIBCPP_BEGIN_NAMESPACE_STD
#if _LIBCPP_STD_VER > 14
_LIBCPP_NORETURN
inline _LIBCPP_INLINE_VISIBILITY
_LIBCPP_AVAILABILITY_THROW_BAD_VARIANT_ACCESS
void __throw_bad_variant_access() {
#ifndef _LIBCPP_NO_EXCEPTIONS
throw bad_variant_access();
#else
_VSTD::abort();
#endif
}
template <class... _Types>
class _LIBCPP_TEMPLATE_VIS variant;
template <class _Tp>
struct _LIBCPP_TEMPLATE_VIS variant_size;
template <class _Tp>
_LIBCPP_INLINE_VAR constexpr size_t variant_size_v = variant_size<_Tp>::value;
template <class _Tp>
struct _LIBCPP_TEMPLATE_VIS variant_size<const _Tp> : variant_size<_Tp> {};
template <class _Tp>
struct _LIBCPP_TEMPLATE_VIS variant_size<volatile _Tp> : variant_size<_Tp> {};
template <class _Tp>
struct _LIBCPP_TEMPLATE_VIS variant_size<const volatile _Tp>
: variant_size<_Tp> {};
template <class... _Types>
struct _LIBCPP_TEMPLATE_VIS variant_size<variant<_Types...>>
: integral_constant<size_t, sizeof...(_Types)> {};
template <size_t _Ip, class _Tp>
struct _LIBCPP_TEMPLATE_VIS variant_alternative;
template <size_t _Ip, class _Tp>
using variant_alternative_t = typename variant_alternative<_Ip, _Tp>::type;
template <size_t _Ip, class _Tp>
struct _LIBCPP_TEMPLATE_VIS variant_alternative<_Ip, const _Tp>
: add_const<variant_alternative_t<_Ip, _Tp>> {};
template <size_t _Ip, class _Tp>
struct _LIBCPP_TEMPLATE_VIS variant_alternative<_Ip, volatile _Tp>
: add_volatile<variant_alternative_t<_Ip, _Tp>> {};
template <size_t _Ip, class _Tp>
struct _LIBCPP_TEMPLATE_VIS variant_alternative<_Ip, const volatile _Tp>
: add_cv<variant_alternative_t<_Ip, _Tp>> {};
template <size_t _Ip, class... _Types>
struct _LIBCPP_TEMPLATE_VIS variant_alternative<_Ip, variant<_Types...>> {
static_assert(_Ip < sizeof...(_Types), "Index out of bounds in std::variant_alternative<>");
using type = __type_pack_element<_Ip, _Types...>;
};
_LIBCPP_INLINE_VAR constexpr size_t variant_npos = static_cast<size_t>(-1);
constexpr int __choose_index_type(unsigned int __num_elem) {
if (__num_elem < std::numeric_limits<unsigned char>::max())
return 0;
if (__num_elem < std::numeric_limits<unsigned short>::max())
return 1;
return 2;
}
template <size_t _NumAlts>
using __variant_index_t =
#ifndef _LIBCPP_ABI_VARIANT_INDEX_TYPE_OPTIMIZATION
unsigned int;
#else
std::tuple_element_t<
__choose_index_type(_NumAlts),
std::tuple<unsigned char, unsigned short, unsigned int>
>;
#endif
template <class _IndexType>
constexpr _IndexType __variant_npos = static_cast<_IndexType>(-1);
namespace __find_detail {
template <class _Tp, class... _Types>
inline _LIBCPP_INLINE_VISIBILITY
constexpr size_t __find_index() {
constexpr bool __matches[] = {is_same_v<_Tp, _Types>...};
size_t __result = __not_found;
for (size_t __i = 0; __i < sizeof...(_Types); ++__i) {
if (__matches[__i]) {
if (__result != __not_found) {
return __ambiguous;
}
__result = __i;
}
}
return __result;
}
template <size_t _Index>
struct __find_unambiguous_index_sfinae_impl
: integral_constant<size_t, _Index> {};
template <>
struct __find_unambiguous_index_sfinae_impl<__not_found> {};
template <>
struct __find_unambiguous_index_sfinae_impl<__ambiguous> {};
template <class _Tp, class... _Types>
struct __find_unambiguous_index_sfinae
: __find_unambiguous_index_sfinae_impl<__find_index<_Tp, _Types...>()> {};
} // namespace __find_detail
namespace __variant_detail {
struct __valueless_t {};
enum class _Trait { _TriviallyAvailable, _Available, _Unavailable };
template <typename _Tp,
template <typename> class _IsTriviallyAvailable,
template <typename> class _IsAvailable>
constexpr _Trait __trait =
_IsTriviallyAvailable<_Tp>::value
? _Trait::_TriviallyAvailable
: _IsAvailable<_Tp>::value ? _Trait::_Available : _Trait::_Unavailable;
inline _LIBCPP_INLINE_VISIBILITY
constexpr _Trait __common_trait(initializer_list<_Trait> __traits) {
_Trait __result = _Trait::_TriviallyAvailable;
for (_Trait __t : __traits) {
if (static_cast<int>(__t) > static_cast<int>(__result)) {
__result = __t;
}
}
return __result;
}
template <typename... _Types>
struct __traits {
static constexpr _Trait __copy_constructible_trait =
__common_trait({__trait<_Types,
is_trivially_copy_constructible,
is_copy_constructible>...});
static constexpr _Trait __move_constructible_trait =
__common_trait({__trait<_Types,
is_trivially_move_constructible,
is_move_constructible>...});
static constexpr _Trait __copy_assignable_trait = __common_trait(
{__copy_constructible_trait,
__trait<_Types, is_trivially_copy_assignable, is_copy_assignable>...});
static constexpr _Trait __move_assignable_trait = __common_trait(
{__move_constructible_trait,
__trait<_Types, is_trivially_move_assignable, is_move_assignable>...});
static constexpr _Trait __destructible_trait = __common_trait(
{__trait<_Types, is_trivially_destructible, is_destructible>...});
};
namespace __access {
struct __union {
template <class _Vp>
inline _LIBCPP_INLINE_VISIBILITY
static constexpr auto&& __get_alt(_Vp&& __v, in_place_index_t<0>) {
return _VSTD::forward<_Vp>(__v).__head;
}
template <class _Vp, size_t _Ip>
inline _LIBCPP_INLINE_VISIBILITY
static constexpr auto&& __get_alt(_Vp&& __v, in_place_index_t<_Ip>) {
return __get_alt(_VSTD::forward<_Vp>(__v).__tail, in_place_index<_Ip - 1>);
}
};
struct __base {
template <size_t _Ip, class _Vp>
inline _LIBCPP_INLINE_VISIBILITY
static constexpr auto&& __get_alt(_Vp&& __v) {
return __union::__get_alt(_VSTD::forward<_Vp>(__v).__data,
in_place_index<_Ip>);
}
};
struct __variant {
template <size_t _Ip, class _Vp>
inline _LIBCPP_INLINE_VISIBILITY
static constexpr auto&& __get_alt(_Vp&& __v) {
return __base::__get_alt<_Ip>(_VSTD::forward<_Vp>(__v).__impl);
}
};
} // namespace __access
namespace __visitation {
struct __base {
template <class _Visitor, class... _Vs>
inline _LIBCPP_INLINE_VISIBILITY
static constexpr decltype(auto)
__visit_alt_at(size_t __index, _Visitor&& __visitor, _Vs&&... __vs) {
constexpr auto __fdiagonal =
__make_fdiagonal<_Visitor&&,
decltype(_VSTD::forward<_Vs>(__vs).__as_base())...>();
return __fdiagonal[__index](_VSTD::forward<_Visitor>(__visitor),
_VSTD::forward<_Vs>(__vs).__as_base()...);
}
template <class _Visitor, class... _Vs>
inline _LIBCPP_INLINE_VISIBILITY
static constexpr decltype(auto) __visit_alt(_Visitor&& __visitor,
_Vs&&... __vs) {
constexpr auto __fmatrix =
__make_fmatrix<_Visitor&&,
decltype(_VSTD::forward<_Vs>(__vs).__as_base())...>();
return __at(__fmatrix, __vs.index()...)(
_VSTD::forward<_Visitor>(__visitor),
_VSTD::forward<_Vs>(__vs).__as_base()...);
}
private:
template <class _Tp>
inline _LIBCPP_INLINE_VISIBILITY
static constexpr const _Tp& __at(const _Tp& __elem) { return __elem; }
template <class _Tp, size_t _Np, typename... _Indices>
inline _LIBCPP_INLINE_VISIBILITY
static constexpr auto&& __at(const array<_Tp, _Np>& __elems,
size_t __index, _Indices... __indices) {
return __at(__elems[__index], __indices...);
}
template <class _Fp, class... _Fs>
static constexpr void __std_visit_visitor_return_type_check() {
static_assert(
__all<is_same_v<_Fp, _Fs>...>::value,
"`std::visit` requires the visitor to have a single return type.");
}
template <class... _Fs>
inline _LIBCPP_INLINE_VISIBILITY
static constexpr auto __make_farray(_Fs&&... __fs) {
__std_visit_visitor_return_type_check<__uncvref_t<_Fs>...>();
using __result = array<common_type_t<__uncvref_t<_Fs>...>, sizeof...(_Fs)>;
return __result{{_VSTD::forward<_Fs>(__fs)...}};
}
template <std::size_t... _Is>
struct __dispatcher {
template <class _Fp, class... _Vs>
inline _LIBCPP_INLINE_VISIBILITY
static constexpr decltype(auto) __dispatch(_Fp __f, _Vs... __vs) {
return __invoke_constexpr(
static_cast<_Fp>(__f),
__access::__base::__get_alt<_Is>(static_cast<_Vs>(__vs))...);
}
};
template <class _Fp, class... _Vs, size_t... _Is>
inline _LIBCPP_INLINE_VISIBILITY
static constexpr auto __make_dispatch(index_sequence<_Is...>) {
return __dispatcher<_Is...>::template __dispatch<_Fp, _Vs...>;
}
template <size_t _Ip, class _Fp, class... _Vs>
inline _LIBCPP_INLINE_VISIBILITY
static constexpr auto __make_fdiagonal_impl() {
return __make_dispatch<_Fp, _Vs...>(
index_sequence<(__identity<_Vs>{}, _Ip)...>{});
}
template <class _Fp, class... _Vs, size_t... _Is>
inline _LIBCPP_INLINE_VISIBILITY
static constexpr auto __make_fdiagonal_impl(index_sequence<_Is...>) {
return __base::__make_farray(__make_fdiagonal_impl<_Is, _Fp, _Vs...>()...);
}
template <class _Fp, class _Vp, class... _Vs>
inline _LIBCPP_INLINE_VISIBILITY
static constexpr auto __make_fdiagonal() {
constexpr size_t _Np = __uncvref_t<_Vp>::__size();
static_assert(__all<(_Np == __uncvref_t<_Vs>::__size())...>::value);
return __make_fdiagonal_impl<_Fp, _Vp, _Vs...>(make_index_sequence<_Np>{});
}
template <class _Fp, class... _Vs, size_t... _Is>
inline _LIBCPP_INLINE_VISIBILITY
static constexpr auto __make_fmatrix_impl(index_sequence<_Is...> __is) {
return __make_dispatch<_Fp, _Vs...>(__is);
}
template <class _Fp, class... _Vs, size_t... _Is, size_t... _Js, class... _Ls>
inline _LIBCPP_INLINE_VISIBILITY
static constexpr auto __make_fmatrix_impl(index_sequence<_Is...>,
index_sequence<_Js...>,
_Ls... __ls) {
return __base::__make_farray(__make_fmatrix_impl<_Fp, _Vs...>(
index_sequence<_Is..., _Js>{}, __ls...)...);
}
template <class _Fp, class... _Vs>
inline _LIBCPP_INLINE_VISIBILITY
static constexpr auto __make_fmatrix() {
return __make_fmatrix_impl<_Fp, _Vs...>(
index_sequence<>{}, make_index_sequence<__uncvref_t<_Vs>::__size()>{}...);
}
};
struct __variant {
template <class _Visitor, class... _Vs>
inline _LIBCPP_INLINE_VISIBILITY
static constexpr decltype(auto)
__visit_alt_at(size_t __index, _Visitor&& __visitor, _Vs&&... __vs) {
return __base::__visit_alt_at(__index,
_VSTD::forward<_Visitor>(__visitor),
_VSTD::forward<_Vs>(__vs).__impl...);
}
template <class _Visitor, class... _Vs>
inline _LIBCPP_INLINE_VISIBILITY
static constexpr decltype(auto) __visit_alt(_Visitor&& __visitor,
_Vs&&... __vs) {
return __base::__visit_alt(_VSTD::forward<_Visitor>(__visitor),
_VSTD::forward<_Vs>(__vs).__impl...);
}
template <class _Visitor, class... _Vs>
inline _LIBCPP_INLINE_VISIBILITY
static constexpr decltype(auto)
__visit_value_at(size_t __index, _Visitor&& __visitor, _Vs&&... __vs) {
return __visit_alt_at(
__index,
__make_value_visitor(_VSTD::forward<_Visitor>(__visitor)),
_VSTD::forward<_Vs>(__vs)...);
}
template <class _Visitor, class... _Vs>
inline _LIBCPP_INLINE_VISIBILITY
static constexpr decltype(auto) __visit_value(_Visitor&& __visitor,
_Vs&&... __vs) {
return __visit_alt(
__make_value_visitor(_VSTD::forward<_Visitor>(__visitor)),
_VSTD::forward<_Vs>(__vs)...);
}
private:
template <class _Visitor, class... _Values>
static constexpr void __std_visit_exhaustive_visitor_check() {
static_assert(is_invocable_v<_Visitor, _Values...>,
"`std::visit` requires the visitor to be exhaustive.");
}
template <class _Visitor>
struct __value_visitor {
template <class... _Alts>
inline _LIBCPP_INLINE_VISIBILITY
constexpr decltype(auto) operator()(_Alts&&... __alts) const {
__std_visit_exhaustive_visitor_check<
_Visitor,
decltype((_VSTD::forward<_Alts>(__alts).__value))...>();
return __invoke_constexpr(_VSTD::forward<_Visitor>(__visitor),
_VSTD::forward<_Alts>(__alts).__value...);
}
_Visitor&& __visitor;
};
template <class _Visitor>
inline _LIBCPP_INLINE_VISIBILITY
static constexpr auto __make_value_visitor(_Visitor&& __visitor) {
return __value_visitor<_Visitor>{_VSTD::forward<_Visitor>(__visitor)};
}
};
} // namespace __visitation
template <size_t _Index, class _Tp>
struct _LIBCPP_TEMPLATE_VIS __alt {
using __value_type = _Tp;
template <class... _Args>
inline _LIBCPP_INLINE_VISIBILITY
explicit constexpr __alt(in_place_t, _Args&&... __args)
: __value(_VSTD::forward<_Args>(__args)...) {}
__value_type __value;
};
template <_Trait _DestructibleTrait, size_t _Index, class... _Types>
union _LIBCPP_TEMPLATE_VIS __union;
template <_Trait _DestructibleTrait, size_t _Index>
union _LIBCPP_TEMPLATE_VIS __union<_DestructibleTrait, _Index> {};
#define _LIBCPP_VARIANT_UNION(destructible_trait, destructor) \
template <size_t _Index, class _Tp, class... _Types> \
union _LIBCPP_TEMPLATE_VIS __union<destructible_trait, \
_Index, \
_Tp, \
_Types...> { \
public: \
inline _LIBCPP_INLINE_VISIBILITY \
explicit constexpr __union(__valueless_t) noexcept : __dummy{} {} \
\
template <class... _Args> \
inline _LIBCPP_INLINE_VISIBILITY \
explicit constexpr __union(in_place_index_t<0>, _Args&&... __args) \
: __head(in_place, _VSTD::forward<_Args>(__args)...) {} \
\
template <size_t _Ip, class... _Args> \
inline _LIBCPP_INLINE_VISIBILITY \
explicit constexpr __union(in_place_index_t<_Ip>, _Args&&... __args) \
: __tail(in_place_index<_Ip - 1>, _VSTD::forward<_Args>(__args)...) {} \
\
__union(const __union&) = default; \
__union(__union&&) = default; \
\
destructor \
\
__union& operator=(const __union&) = default; \
__union& operator=(__union&&) = default; \
\
private: \
char __dummy; \
__alt<_Index, _Tp> __head; \
__union<destructible_trait, _Index + 1, _Types...> __tail; \
\
friend struct __access::__union; \
}
_LIBCPP_VARIANT_UNION(_Trait::_TriviallyAvailable, ~__union() = default;);
_LIBCPP_VARIANT_UNION(_Trait::_Available, ~__union() {});
_LIBCPP_VARIANT_UNION(_Trait::_Unavailable, ~__union() = delete;);
#undef _LIBCPP_VARIANT_UNION
template <_Trait _DestructibleTrait, class... _Types>
class _LIBCPP_TEMPLATE_VIS __base {
public:
using __index_t = __variant_index_t<sizeof...(_Types)>;
inline _LIBCPP_INLINE_VISIBILITY
explicit constexpr __base(__valueless_t tag) noexcept
: __data(tag), __index(__variant_npos<__index_t>) {}
template <size_t _Ip, class... _Args>
inline _LIBCPP_INLINE_VISIBILITY
explicit constexpr __base(in_place_index_t<_Ip>, _Args&&... __args)
:
__data(in_place_index<_Ip>, _VSTD::forward<_Args>(__args)...),
__index(_Ip) {}
inline _LIBCPP_INLINE_VISIBILITY
constexpr bool valueless_by_exception() const noexcept {
return index() == variant_npos;
}
inline _LIBCPP_INLINE_VISIBILITY
constexpr size_t index() const noexcept {
return __index == __variant_npos<__index_t> ? variant_npos : __index;
}
protected:
inline _LIBCPP_INLINE_VISIBILITY
constexpr auto&& __as_base() & { return *this; }
inline _LIBCPP_INLINE_VISIBILITY
constexpr auto&& __as_base() && { return _VSTD::move(*this); }
inline _LIBCPP_INLINE_VISIBILITY
constexpr auto&& __as_base() const & { return *this; }
inline _LIBCPP_INLINE_VISIBILITY
constexpr auto&& __as_base() const && { return _VSTD::move(*this); }
inline _LIBCPP_INLINE_VISIBILITY
static constexpr size_t __size() { return sizeof...(_Types); }
__union<_DestructibleTrait, 0, _Types...> __data;
__index_t __index;
friend struct __access::__base;
friend struct __visitation::__base;
};
template <class _Traits, _Trait = _Traits::__destructible_trait>
class _LIBCPP_TEMPLATE_VIS __destructor;
#define _LIBCPP_VARIANT_DESTRUCTOR(destructible_trait, destructor, destroy) \
template <class... _Types> \
class _LIBCPP_TEMPLATE_VIS __destructor<__traits<_Types...>, \
destructible_trait> \
: public __base<destructible_trait, _Types...> { \
using __base_type = __base<destructible_trait, _Types...>; \
using __index_t = typename __base_type::__index_t; \
\
public: \
using __base_type::__base_type; \
using __base_type::operator=; \
\
__destructor(const __destructor&) = default; \
__destructor(__destructor&&) = default; \
destructor \
__destructor& operator=(const __destructor&) = default; \
__destructor& operator=(__destructor&&) = default; \
\
protected: \
inline _LIBCPP_INLINE_VISIBILITY \
destroy \
}
_LIBCPP_VARIANT_DESTRUCTOR(
_Trait::_TriviallyAvailable,
~__destructor() = default;,
void __destroy() noexcept { this->__index = __variant_npos<__index_t>; });
_LIBCPP_VARIANT_DESTRUCTOR(
_Trait::_Available,
~__destructor() { __destroy(); },
void __destroy() noexcept {
if (!this->valueless_by_exception()) {
__visitation::__base::__visit_alt(
[](auto& __alt) noexcept {
using __alt_type = __uncvref_t<decltype(__alt)>;
__alt.~__alt_type();
},
*this);
}
this->__index = __variant_npos<__index_t>;
});
_LIBCPP_VARIANT_DESTRUCTOR(
_Trait::_Unavailable,
~__destructor() = delete;,
void __destroy() noexcept = delete;);
#undef _LIBCPP_VARIANT_DESTRUCTOR
template <class _Traits>
class _LIBCPP_TEMPLATE_VIS __constructor : public __destructor<_Traits> {
using __base_type = __destructor<_Traits>;
public:
using __base_type::__base_type;
using __base_type::operator=;
protected:
template <size_t _Ip, class _Tp, class... _Args>
inline _LIBCPP_INLINE_VISIBILITY
static _Tp& __construct_alt(__alt<_Ip, _Tp>& __a, _Args&&... __args) {
::new ((void*)_VSTD::addressof(__a))
__alt<_Ip, _Tp>(in_place, _VSTD::forward<_Args>(__args)...);
return __a.__value;
}
template <class _Rhs>
inline _LIBCPP_INLINE_VISIBILITY
static void __generic_construct(__constructor& __lhs, _Rhs&& __rhs) {
__lhs.__destroy();
if (!__rhs.valueless_by_exception()) {
__visitation::__base::__visit_alt_at(
__rhs.index(),
[](auto& __lhs_alt, auto&& __rhs_alt) {
__construct_alt(
__lhs_alt,
_VSTD::forward<decltype(__rhs_alt)>(__rhs_alt).__value);
},
__lhs, _VSTD::forward<_Rhs>(__rhs));
__lhs.__index = __rhs.index();
}
}
};
template <class _Traits, _Trait = _Traits::__move_constructible_trait>
class _LIBCPP_TEMPLATE_VIS __move_constructor;
#define _LIBCPP_VARIANT_MOVE_CONSTRUCTOR(move_constructible_trait, \
move_constructor) \
template <class... _Types> \
class _LIBCPP_TEMPLATE_VIS __move_constructor<__traits<_Types...>, \
move_constructible_trait> \
: public __constructor<__traits<_Types...>> { \
using __base_type = __constructor<__traits<_Types...>>; \
\
public: \
using __base_type::__base_type; \
using __base_type::operator=; \
\
__move_constructor(const __move_constructor&) = default; \
move_constructor \
~__move_constructor() = default; \
__move_constructor& operator=(const __move_constructor&) = default; \
__move_constructor& operator=(__move_constructor&&) = default; \
}
_LIBCPP_VARIANT_MOVE_CONSTRUCTOR(
_Trait::_TriviallyAvailable,
__move_constructor(__move_constructor&& __that) = default;);
_LIBCPP_VARIANT_MOVE_CONSTRUCTOR(
_Trait::_Available,
__move_constructor(__move_constructor&& __that) noexcept(
__all<is_nothrow_move_constructible_v<_Types>...>::value)
: __move_constructor(__valueless_t{}) {
this->__generic_construct(*this, _VSTD::move(__that));
});
_LIBCPP_VARIANT_MOVE_CONSTRUCTOR(
_Trait::_Unavailable,
__move_constructor(__move_constructor&&) = delete;);
#undef _LIBCPP_VARIANT_MOVE_CONSTRUCTOR
template <class _Traits, _Trait = _Traits::__copy_constructible_trait>
class _LIBCPP_TEMPLATE_VIS __copy_constructor;
#define _LIBCPP_VARIANT_COPY_CONSTRUCTOR(copy_constructible_trait, \
copy_constructor) \
template <class... _Types> \
class _LIBCPP_TEMPLATE_VIS __copy_constructor<__traits<_Types...>, \
copy_constructible_trait> \
: public __move_constructor<__traits<_Types...>> { \
using __base_type = __move_constructor<__traits<_Types...>>; \
\
public: \
using __base_type::__base_type; \
using __base_type::operator=; \
\
copy_constructor \
__copy_constructor(__copy_constructor&&) = default; \
~__copy_constructor() = default; \
__copy_constructor& operator=(const __copy_constructor&) = default; \
__copy_constructor& operator=(__copy_constructor&&) = default; \
}
_LIBCPP_VARIANT_COPY_CONSTRUCTOR(
_Trait::_TriviallyAvailable,
__copy_constructor(const __copy_constructor& __that) = default;);
_LIBCPP_VARIANT_COPY_CONSTRUCTOR(
_Trait::_Available,
__copy_constructor(const __copy_constructor& __that)
: __copy_constructor(__valueless_t{}) {
this->__generic_construct(*this, __that);
});
_LIBCPP_VARIANT_COPY_CONSTRUCTOR(
_Trait::_Unavailable,
__copy_constructor(const __copy_constructor&) = delete;);
#undef _LIBCPP_VARIANT_COPY_CONSTRUCTOR
template <class _Traits>
class _LIBCPP_TEMPLATE_VIS __assignment : public __copy_constructor<_Traits> {
using __base_type = __copy_constructor<_Traits>;
public:
using __base_type::__base_type;
using __base_type::operator=;
template <size_t _Ip, class... _Args>
inline _LIBCPP_INLINE_VISIBILITY
auto& __emplace(_Args&&... __args) {
this->__destroy();
auto& __res = this->__construct_alt(__access::__base::__get_alt<_Ip>(*this),
_VSTD::forward<_Args>(__args)...);
this->__index = _Ip;
return __res;
}
protected:
template <size_t _Ip, class _Tp, class _Arg>
inline _LIBCPP_INLINE_VISIBILITY
void __assign_alt(__alt<_Ip, _Tp>& __a, _Arg&& __arg) {
if (this->index() == _Ip) {
__a.__value = _VSTD::forward<_Arg>(__arg);
} else {
struct {
void operator()(true_type) const {
__this->__emplace<_Ip>(_VSTD::forward<_Arg>(__arg));
}
void operator()(false_type) const {
__this->__emplace<_Ip>(_Tp(_VSTD::forward<_Arg>(__arg)));
}
__assignment* __this;
_Arg&& __arg;
} __impl{this, _VSTD::forward<_Arg>(__arg)};
__impl(bool_constant<is_nothrow_constructible_v<_Tp, _Arg> ||
!is_nothrow_move_constructible_v<_Tp>>{});
}
}
template <class _That>
inline _LIBCPP_INLINE_VISIBILITY
void __generic_assign(_That&& __that) {
if (this->valueless_by_exception() && __that.valueless_by_exception()) {
// do nothing.
} else if (__that.valueless_by_exception()) {
this->__destroy();
} else {
__visitation::__base::__visit_alt_at(
__that.index(),
[this](auto& __this_alt, auto&& __that_alt) {
this->__assign_alt(
__this_alt,
_VSTD::forward<decltype(__that_alt)>(__that_alt).__value);
},
*this, _VSTD::forward<_That>(__that));
}
}
};
template <class _Traits, _Trait = _Traits::__move_assignable_trait>
class _LIBCPP_TEMPLATE_VIS __move_assignment;
#define _LIBCPP_VARIANT_MOVE_ASSIGNMENT(move_assignable_trait, \
move_assignment) \
template <class... _Types> \
class _LIBCPP_TEMPLATE_VIS __move_assignment<__traits<_Types...>, \
move_assignable_trait> \
: public __assignment<__traits<_Types...>> { \
using __base_type = __assignment<__traits<_Types...>>; \
\
public: \
using __base_type::__base_type; \
using __base_type::operator=; \
\
__move_assignment(const __move_assignment&) = default; \
__move_assignment(__move_assignment&&) = default; \
~__move_assignment() = default; \
__move_assignment& operator=(const __move_assignment&) = default; \
move_assignment \
}
_LIBCPP_VARIANT_MOVE_ASSIGNMENT(
_Trait::_TriviallyAvailable,
__move_assignment& operator=(__move_assignment&& __that) = default;);
_LIBCPP_VARIANT_MOVE_ASSIGNMENT(
_Trait::_Available,
__move_assignment& operator=(__move_assignment&& __that) noexcept(
__all<(is_nothrow_move_constructible_v<_Types> &&
is_nothrow_move_assignable_v<_Types>)...>::value) {
this->__generic_assign(_VSTD::move(__that));
return *this;
});
_LIBCPP_VARIANT_MOVE_ASSIGNMENT(
_Trait::_Unavailable,
__move_assignment& operator=(__move_assignment&&) = delete;);
#undef _LIBCPP_VARIANT_MOVE_ASSIGNMENT
template <class _Traits, _Trait = _Traits::__copy_assignable_trait>
class _LIBCPP_TEMPLATE_VIS __copy_assignment;
#define _LIBCPP_VARIANT_COPY_ASSIGNMENT(copy_assignable_trait, \
copy_assignment) \
template <class... _Types> \
class _LIBCPP_TEMPLATE_VIS __copy_assignment<__traits<_Types...>, \
copy_assignable_trait> \
: public __move_assignment<__traits<_Types...>> { \
using __base_type = __move_assignment<__traits<_Types...>>; \
\
public: \
using __base_type::__base_type; \
using __base_type::operator=; \
\
__copy_assignment(const __copy_assignment&) = default; \
__copy_assignment(__copy_assignment&&) = default; \
~__copy_assignment() = default; \
copy_assignment \
__copy_assignment& operator=(__copy_assignment&&) = default; \
}
_LIBCPP_VARIANT_COPY_ASSIGNMENT(
_Trait::_TriviallyAvailable,
__copy_assignment& operator=(const __copy_assignment& __that) = default;);
_LIBCPP_VARIANT_COPY_ASSIGNMENT(
_Trait::_Available,
__copy_assignment& operator=(const __copy_assignment& __that) {
this->__generic_assign(__that);
return *this;
});
_LIBCPP_VARIANT_COPY_ASSIGNMENT(
_Trait::_Unavailable,
__copy_assignment& operator=(const __copy_assignment&) = delete;);
#undef _LIBCPP_VARIANT_COPY_ASSIGNMENT
template <class... _Types>
class _LIBCPP_TEMPLATE_VIS __impl
: public __copy_assignment<__traits<_Types...>> {
using __base_type = __copy_assignment<__traits<_Types...>>;
public:
using __base_type::__base_type;
using __base_type::operator=;
template <size_t _Ip, class _Arg>
inline _LIBCPP_INLINE_VISIBILITY
void __assign(_Arg&& __arg) {
this->__assign_alt(__access::__base::__get_alt<_Ip>(*this),
_VSTD::forward<_Arg>(__arg));
}
inline _LIBCPP_INLINE_VISIBILITY
void __swap(__impl& __that) {
if (this->valueless_by_exception() && __that.valueless_by_exception()) {
// do nothing.
} else if (this->index() == __that.index()) {
__visitation::__base::__visit_alt_at(
this->index(),
[](auto& __this_alt, auto& __that_alt) {
using _VSTD::swap;
swap(__this_alt.__value, __that_alt.__value);
},
*this,
__that);
} else {
__impl* __lhs = this;
__impl* __rhs = _VSTD::addressof(__that);
if (__lhs->__move_nothrow() && !__rhs->__move_nothrow()) {
_VSTD::swap(__lhs, __rhs);
}
__impl __tmp(_VSTD::move(*__rhs));
#ifndef _LIBCPP_NO_EXCEPTIONS
// EXTENSION: When the move construction of `__lhs` into `__rhs` throws
// and `__tmp` is nothrow move constructible then we move `__tmp` back
// into `__rhs` and provide the strong exception safety guarantee.
try {
this->__generic_construct(*__rhs, _VSTD::move(*__lhs));
} catch (...) {
if (__tmp.__move_nothrow()) {
this->__generic_construct(*__rhs, _VSTD::move(__tmp));
}
throw;
}
#else
this->__generic_construct(*__rhs, _VSTD::move(*__lhs));
#endif
this->__generic_construct(*__lhs, _VSTD::move(__tmp));
}
}
private:
inline _LIBCPP_INLINE_VISIBILITY
bool __move_nothrow() const {
constexpr bool __results[] = {is_nothrow_move_constructible_v<_Types>...};
return this->valueless_by_exception() || __results[this->index()];
}
};
struct __no_narrowing_check {
template <class _Dest, class _Source>
using _Apply = __identity<_Dest>;
};
struct __narrowing_check {
template <class _Dest>
static auto __test_impl(_Dest (&&)[1]) -> __identity<_Dest>;
template <class _Dest, class _Source>
using _Apply _LIBCPP_NODEBUG_TYPE = decltype(__test_impl<_Dest>({std::declval<_Source>()}));
};
template <class _Dest, class _Source>
using __check_for_narrowing _LIBCPP_NODEBUG_TYPE =
typename _If<
#ifdef _LIBCPP_ENABLE_NARROWING_CONVERSIONS_IN_VARIANT
false &&
#endif
is_arithmetic<_Dest>::value,
__narrowing_check,
__no_narrowing_check
>::template _Apply<_Dest, _Source>;
template <class _Tp, size_t _Idx>
struct __overload {
template <class _Up>
auto operator()(_Tp, _Up&&) const -> __check_for_narrowing<_Tp, _Up>;
};
template <class _Tp, size_t>
struct __overload_bool {
template <class _Up, class _Ap = __uncvref_t<_Up>>
auto operator()(bool, _Up&&) const
-> enable_if_t<is_same_v<_Ap, bool>, __identity<_Tp>>;
};
template <size_t _Idx>
struct __overload<bool, _Idx> : __overload_bool<bool, _Idx> {};
template <size_t _Idx>
struct __overload<bool const, _Idx> : __overload_bool<bool const, _Idx> {};
template <size_t _Idx>
struct __overload<bool volatile, _Idx> : __overload_bool<bool volatile, _Idx> {};
template <size_t _Idx>
struct __overload<bool const volatile, _Idx> : __overload_bool<bool const volatile, _Idx> {};
template <class ..._Bases>
struct __all_overloads : _Bases... {
void operator()() const;
using _Bases::operator()...;
};
template <class IdxSeq>
struct __make_overloads_imp;
template <size_t ..._Idx>
struct __make_overloads_imp<__tuple_indices<_Idx...> > {
template <class ..._Types>
using _Apply _LIBCPP_NODEBUG_TYPE = __all_overloads<__overload<_Types, _Idx>...>;
};
template <class ..._Types>
using _MakeOverloads _LIBCPP_NODEBUG_TYPE = typename __make_overloads_imp<
__make_indices_imp<sizeof...(_Types), 0> >::template _Apply<_Types...>;
template <class _Tp, class... _Types>
using __best_match_t =
typename invoke_result_t<_MakeOverloads<_Types...>, _Tp, _Tp>::type;
} // __variant_detail
template <class... _Types>
class _LIBCPP_TEMPLATE_VIS variant
: private __sfinae_ctor_base<
__all<is_copy_constructible_v<_Types>...>::value,
__all<is_move_constructible_v<_Types>...>::value>,
private __sfinae_assign_base<
__all<(is_copy_constructible_v<_Types> &&
is_copy_assignable_v<_Types>)...>::value,
__all<(is_move_constructible_v<_Types> &&
is_move_assignable_v<_Types>)...>::value> {
static_assert(0 < sizeof...(_Types),
"variant must consist of at least one alternative.");
static_assert(__all<!is_array_v<_Types>...>::value,
"variant can not have an array type as an alternative.");
static_assert(__all<!is_reference_v<_Types>...>::value,
"variant can not have a reference type as an alternative.");
static_assert(__all<!is_void_v<_Types>...>::value,
"variant can not have a void type as an alternative.");
using __first_type = variant_alternative_t<0, variant>;
public:
template <bool _Dummy = true,
enable_if_t<__dependent_type<is_default_constructible<__first_type>,
_Dummy>::value,
int> = 0>
inline _LIBCPP_INLINE_VISIBILITY
constexpr variant() noexcept(is_nothrow_default_constructible_v<__first_type>)
: __impl(in_place_index<0>) {}
variant(const variant&) = default;
variant(variant&&) = default;
template <
class _Arg,
enable_if_t<!is_same_v<__uncvref_t<_Arg>, variant>, int> = 0,
enable_if_t<!__is_inplace_type<__uncvref_t<_Arg>>::value, int> = 0,
enable_if_t<!__is_inplace_index<__uncvref_t<_Arg>>::value, int> = 0,
class _Tp = __variant_detail::__best_match_t<_Arg, _Types...>,
size_t _Ip =
__find_detail::__find_unambiguous_index_sfinae<_Tp, _Types...>::value,
enable_if_t<is_constructible_v<_Tp, _Arg>, int> = 0>
inline _LIBCPP_INLINE_VISIBILITY
constexpr variant(_Arg&& __arg) noexcept(
is_nothrow_constructible_v<_Tp, _Arg>)
: __impl(in_place_index<_Ip>, _VSTD::forward<_Arg>(__arg)) {}
template <size_t _Ip, class... _Args,
class = enable_if_t<(_Ip < sizeof...(_Types)), int>,
class _Tp = variant_alternative_t<_Ip, variant<_Types...>>,
enable_if_t<is_constructible_v<_Tp, _Args...>, int> = 0>
inline _LIBCPP_INLINE_VISIBILITY
explicit constexpr variant(
in_place_index_t<_Ip>,
_Args&&... __args) noexcept(is_nothrow_constructible_v<_Tp, _Args...>)
: __impl(in_place_index<_Ip>, _VSTD::forward<_Args>(__args)...) {}
template <
size_t _Ip,
class _Up,
class... _Args,
enable_if_t<(_Ip < sizeof...(_Types)), int> = 0,
class _Tp = variant_alternative_t<_Ip, variant<_Types...>>,
enable_if_t<is_constructible_v<_Tp, initializer_list<_Up>&, _Args...>,
int> = 0>
inline _LIBCPP_INLINE_VISIBILITY
explicit constexpr variant(
in_place_index_t<_Ip>,
initializer_list<_Up> __il,
_Args&&... __args) noexcept(
is_nothrow_constructible_v<_Tp, initializer_list<_Up>&, _Args...>)
: __impl(in_place_index<_Ip>, __il, _VSTD::forward<_Args>(__args)...) {}
template <
class _Tp,
class... _Args,
size_t _Ip =
__find_detail::__find_unambiguous_index_sfinae<_Tp, _Types...>::value,
enable_if_t<is_constructible_v<_Tp, _Args...>, int> = 0>
inline _LIBCPP_INLINE_VISIBILITY
explicit constexpr variant(in_place_type_t<_Tp>, _Args&&... __args) noexcept(
is_nothrow_constructible_v<_Tp, _Args...>)
: __impl(in_place_index<_Ip>, _VSTD::forward<_Args>(__args)...) {}
template <
class _Tp,
class _Up,
class... _Args,
size_t _Ip =
__find_detail::__find_unambiguous_index_sfinae<_Tp, _Types...>::value,
enable_if_t<is_constructible_v<_Tp, initializer_list<_Up>&, _Args...>,
int> = 0>
inline _LIBCPP_INLINE_VISIBILITY
explicit constexpr variant(
in_place_type_t<_Tp>,
initializer_list<_Up> __il,
_Args&&... __args) noexcept(
is_nothrow_constructible_v<_Tp, initializer_list< _Up>&, _Args...>)
: __impl(in_place_index<_Ip>, __il, _VSTD::forward<_Args>(__args)...) {}
~variant() = default;
variant& operator=(const variant&) = default;
variant& operator=(variant&&) = default;
template <
class _Arg,
enable_if_t<!is_same_v<__uncvref_t<_Arg>, variant>, int> = 0,
class _Tp = __variant_detail::__best_match_t<_Arg, _Types...>,
size_t _Ip =
__find_detail::__find_unambiguous_index_sfinae<_Tp, _Types...>::value,
enable_if_t<is_assignable_v<_Tp&, _Arg> && is_constructible_v<_Tp, _Arg>,
int> = 0>
inline _LIBCPP_INLINE_VISIBILITY
variant& operator=(_Arg&& __arg) noexcept(
is_nothrow_assignable_v<_Tp&, _Arg> &&
is_nothrow_constructible_v<_Tp, _Arg>) {
__impl.template __assign<_Ip>(_VSTD::forward<_Arg>(__arg));
return *this;
}
template <
size_t _Ip,
class... _Args,
enable_if_t<(_Ip < sizeof...(_Types)), int> = 0,
class _Tp = variant_alternative_t<_Ip, variant<_Types...>>,
enable_if_t<is_constructible_v<_Tp, _Args...>, int> = 0>
inline _LIBCPP_INLINE_VISIBILITY
_Tp& emplace(_Args&&... __args) {
return __impl.template __emplace<_Ip>(_VSTD::forward<_Args>(__args)...);
}
template <
size_t _Ip,
class _Up,
class... _Args,
enable_if_t<(_Ip < sizeof...(_Types)), int> = 0,
class _Tp = variant_alternative_t<_Ip, variant<_Types...>>,
enable_if_t<is_constructible_v<_Tp, initializer_list<_Up>&, _Args...>,
int> = 0>
inline _LIBCPP_INLINE_VISIBILITY
_Tp& emplace(initializer_list<_Up> __il, _Args&&... __args) {
return __impl.template __emplace<_Ip>(__il, _VSTD::forward<_Args>(__args)...);
}
template <
class _Tp,
class... _Args,
size_t _Ip =
__find_detail::__find_unambiguous_index_sfinae<_Tp, _Types...>::value,
enable_if_t<is_constructible_v<_Tp, _Args...>, int> = 0>
inline _LIBCPP_INLINE_VISIBILITY
_Tp& emplace(_Args&&... __args) {
return __impl.template __emplace<_Ip>(_VSTD::forward<_Args>(__args)...);
}
template <
class _Tp,
class _Up,
class... _Args,
size_t _Ip =
__find_detail::__find_unambiguous_index_sfinae<_Tp, _Types...>::value,
enable_if_t<is_constructible_v<_Tp, initializer_list<_Up>&, _Args...>,
int> = 0>
inline _LIBCPP_INLINE_VISIBILITY
_Tp& emplace(initializer_list<_Up> __il, _Args&&... __args) {
return __impl.template __emplace<_Ip>(__il, _VSTD::forward<_Args>(__args)...);
}
inline _LIBCPP_INLINE_VISIBILITY
constexpr bool valueless_by_exception() const noexcept {
return __impl.valueless_by_exception();
}
inline _LIBCPP_INLINE_VISIBILITY
constexpr size_t index() const noexcept { return __impl.index(); }
template <
bool _Dummy = true,
enable_if_t<
__all<(
__dependent_type<is_move_constructible<_Types>, _Dummy>::value &&
__dependent_type<is_swappable<_Types>, _Dummy>::value)...>::value,
int> = 0>
inline _LIBCPP_INLINE_VISIBILITY
void swap(variant& __that) noexcept(
__all<(is_nothrow_move_constructible_v<_Types> &&
is_nothrow_swappable_v<_Types>)...>::value) {
__impl.__swap(__that.__impl);
}
private:
__variant_detail::__impl<_Types...> __impl;
friend struct __variant_detail::__access::__variant;
friend struct __variant_detail::__visitation::__variant;
};
template <size_t _Ip, class... _Types>
inline _LIBCPP_INLINE_VISIBILITY
constexpr bool __holds_alternative(const variant<_Types...>& __v) noexcept {
return __v.index() == _Ip;
}
template <class _Tp, class... _Types>
inline _LIBCPP_INLINE_VISIBILITY
constexpr bool holds_alternative(const variant<_Types...>& __v) noexcept {
return __holds_alternative<__find_exactly_one_t<_Tp, _Types...>::value>(__v);
}
template <size_t _Ip, class _Vp>
inline _LIBCPP_INLINE_VISIBILITY
_LIBCPP_AVAILABILITY_THROW_BAD_VARIANT_ACCESS
constexpr auto&& __generic_get(_Vp&& __v) {
using __variant_detail::__access::__variant;
if (!__holds_alternative<_Ip>(__v)) {
__throw_bad_variant_access();
}
return __variant::__get_alt<_Ip>(_VSTD::forward<_Vp>(__v)).__value;
}
template <size_t _Ip, class... _Types>
inline _LIBCPP_INLINE_VISIBILITY
_LIBCPP_AVAILABILITY_THROW_BAD_VARIANT_ACCESS
constexpr variant_alternative_t<_Ip, variant<_Types...>>& get(
variant<_Types...>& __v) {
static_assert(_Ip < sizeof...(_Types));
static_assert(!is_void_v<variant_alternative_t<_Ip, variant<_Types...>>>);
return __generic_get<_Ip>(__v);
}
template <size_t _Ip, class... _Types>
inline _LIBCPP_INLINE_VISIBILITY
_LIBCPP_AVAILABILITY_THROW_BAD_VARIANT_ACCESS
constexpr variant_alternative_t<_Ip, variant<_Types...>>&& get(
variant<_Types...>&& __v) {
static_assert(_Ip < sizeof...(_Types));
static_assert(!is_void_v<variant_alternative_t<_Ip, variant<_Types...>>>);
return __generic_get<_Ip>(_VSTD::move(__v));
}
template <size_t _Ip, class... _Types>
inline _LIBCPP_INLINE_VISIBILITY
_LIBCPP_AVAILABILITY_THROW_BAD_VARIANT_ACCESS
constexpr const variant_alternative_t<_Ip, variant<_Types...>>& get(
const variant<_Types...>& __v) {
static_assert(_Ip < sizeof...(_Types));
static_assert(!is_void_v<variant_alternative_t<_Ip, variant<_Types...>>>);
return __generic_get<_Ip>(__v);
}
template <size_t _Ip, class... _Types>
inline _LIBCPP_INLINE_VISIBILITY
_LIBCPP_AVAILABILITY_THROW_BAD_VARIANT_ACCESS
constexpr const variant_alternative_t<_Ip, variant<_Types...>>&& get(
const variant<_Types...>&& __v) {
static_assert(_Ip < sizeof...(_Types));
static_assert(!is_void_v<variant_alternative_t<_Ip, variant<_Types...>>>);
return __generic_get<_Ip>(_VSTD::move(__v));
}
template <class _Tp, class... _Types>
inline _LIBCPP_INLINE_VISIBILITY
_LIBCPP_AVAILABILITY_THROW_BAD_VARIANT_ACCESS
constexpr _Tp& get(variant<_Types...>& __v) {
static_assert(!is_void_v<_Tp>);
return _VSTD::get<__find_exactly_one_t<_Tp, _Types...>::value>(__v);
}
template <class _Tp, class... _Types>
inline _LIBCPP_INLINE_VISIBILITY
_LIBCPP_AVAILABILITY_THROW_BAD_VARIANT_ACCESS
constexpr _Tp&& get(variant<_Types...>&& __v) {
static_assert(!is_void_v<_Tp>);
return _VSTD::get<__find_exactly_one_t<_Tp, _Types...>::value>(
_VSTD::move(__v));
}
template <class _Tp, class... _Types>
inline _LIBCPP_INLINE_VISIBILITY
_LIBCPP_AVAILABILITY_THROW_BAD_VARIANT_ACCESS
constexpr const _Tp& get(const variant<_Types...>& __v) {
static_assert(!is_void_v<_Tp>);
return _VSTD::get<__find_exactly_one_t<_Tp, _Types...>::value>(__v);
}
template <class _Tp, class... _Types>
inline _LIBCPP_INLINE_VISIBILITY
_LIBCPP_AVAILABILITY_THROW_BAD_VARIANT_ACCESS
constexpr const _Tp&& get(const variant<_Types...>&& __v) {
static_assert(!is_void_v<_Tp>);
return _VSTD::get<__find_exactly_one_t<_Tp, _Types...>::value>(
_VSTD::move(__v));
}
template <size_t _Ip, class _Vp>
inline _LIBCPP_INLINE_VISIBILITY
constexpr auto* __generic_get_if(_Vp* __v) noexcept {
using __variant_detail::__access::__variant;
return __v && __holds_alternative<_Ip>(*__v)
? _VSTD::addressof(__variant::__get_alt<_Ip>(*__v).__value)
: nullptr;
}
template <size_t _Ip, class... _Types>
inline _LIBCPP_INLINE_VISIBILITY
constexpr add_pointer_t<variant_alternative_t<_Ip, variant<_Types...>>>
get_if(variant<_Types...>* __v) noexcept {
static_assert(_Ip < sizeof...(_Types));
static_assert(!is_void_v<variant_alternative_t<_Ip, variant<_Types...>>>);
return __generic_get_if<_Ip>(__v);
}
template <size_t _Ip, class... _Types>
inline _LIBCPP_INLINE_VISIBILITY
constexpr add_pointer_t<const variant_alternative_t<_Ip, variant<_Types...>>>
get_if(const variant<_Types...>* __v) noexcept {
static_assert(_Ip < sizeof...(_Types));
static_assert(!is_void_v<variant_alternative_t<_Ip, variant<_Types...>>>);
return __generic_get_if<_Ip>(__v);
}
template <class _Tp, class... _Types>
inline _LIBCPP_INLINE_VISIBILITY
constexpr add_pointer_t<_Tp>
get_if(variant<_Types...>* __v) noexcept {
static_assert(!is_void_v<_Tp>);
return _VSTD::get_if<__find_exactly_one_t<_Tp, _Types...>::value>(__v);
}
template <class _Tp, class... _Types>
inline _LIBCPP_INLINE_VISIBILITY
constexpr add_pointer_t<const _Tp>
get_if(const variant<_Types...>* __v) noexcept {
static_assert(!is_void_v<_Tp>);
return _VSTD::get_if<__find_exactly_one_t<_Tp, _Types...>::value>(__v);
}
template <class _Operator>
struct __convert_to_bool {
template <class _T1, class _T2>
_LIBCPP_INLINE_VISIBILITY constexpr bool operator()(_T1 && __t1, _T2&& __t2) const {
static_assert(std::is_convertible<decltype(_Operator{}(_VSTD::forward<_T1>(__t1), _VSTD::forward<_T2>(__t2))), bool>::value,
"the relational operator does not return a type which is implicitly convertible to bool");
return _Operator{}(_VSTD::forward<_T1>(__t1), _VSTD::forward<_T2>(__t2));
}
};
template <class... _Types>
inline _LIBCPP_INLINE_VISIBILITY
constexpr bool operator==(const variant<_Types...>& __lhs,
const variant<_Types...>& __rhs) {
using __variant_detail::__visitation::__variant;
if (__lhs.index() != __rhs.index()) return false;
if (__lhs.valueless_by_exception()) return true;
return __variant::__visit_value_at(__lhs.index(), __convert_to_bool<equal_to<>>{}, __lhs, __rhs);
}
template <class... _Types>
inline _LIBCPP_INLINE_VISIBILITY
constexpr bool operator!=(const variant<_Types...>& __lhs,
const variant<_Types...>& __rhs) {
using __variant_detail::__visitation::__variant;
if (__lhs.index() != __rhs.index()) return true;
if (__lhs.valueless_by_exception()) return false;
return __variant::__visit_value_at(
__lhs.index(), __convert_to_bool<not_equal_to<>>{}, __lhs, __rhs);
}
template <class... _Types>
inline _LIBCPP_INLINE_VISIBILITY
constexpr bool operator<(const variant<_Types...>& __lhs,
const variant<_Types...>& __rhs) {
using __variant_detail::__visitation::__variant;
if (__rhs.valueless_by_exception()) return false;
if (__lhs.valueless_by_exception()) return true;
if (__lhs.index() < __rhs.index()) return true;
if (__lhs.index() > __rhs.index()) return false;
return __variant::__visit_value_at(__lhs.index(), __convert_to_bool<less<>>{}, __lhs, __rhs);
}
template <class... _Types>
inline _LIBCPP_INLINE_VISIBILITY
constexpr bool operator>(const variant<_Types...>& __lhs,
const variant<_Types...>& __rhs) {
using __variant_detail::__visitation::__variant;
if (__lhs.valueless_by_exception()) return false;
if (__rhs.valueless_by_exception()) return true;
if (__lhs.index() > __rhs.index()) return true;
if (__lhs.index() < __rhs.index()) return false;
return __variant::__visit_value_at(__lhs.index(), __convert_to_bool<greater<>>{}, __lhs, __rhs);
}
template <class... _Types>
inline _LIBCPP_INLINE_VISIBILITY
constexpr bool operator<=(const variant<_Types...>& __lhs,
const variant<_Types...>& __rhs) {
using __variant_detail::__visitation::__variant;
if (__lhs.valueless_by_exception()) return true;
if (__rhs.valueless_by_exception()) return false;
if (__lhs.index() < __rhs.index()) return true;
if (__lhs.index() > __rhs.index()) return false;
return __variant::__visit_value_at(
__lhs.index(), __convert_to_bool<less_equal<>>{}, __lhs, __rhs);
}
template <class... _Types>
inline _LIBCPP_INLINE_VISIBILITY
constexpr bool operator>=(const variant<_Types...>& __lhs,
const variant<_Types...>& __rhs) {
using __variant_detail::__visitation::__variant;
if (__rhs.valueless_by_exception()) return true;
if (__lhs.valueless_by_exception()) return false;
if (__lhs.index() > __rhs.index()) return true;
if (__lhs.index() < __rhs.index()) return false;
return __variant::__visit_value_at(
__lhs.index(), __convert_to_bool<greater_equal<>>{}, __lhs, __rhs);
}
template <class _Visitor, class... _Vs>
inline _LIBCPP_INLINE_VISIBILITY
_LIBCPP_AVAILABILITY_THROW_BAD_VARIANT_ACCESS
constexpr decltype(auto) visit(_Visitor&& __visitor, _Vs&&... __vs) {
using __variant_detail::__visitation::__variant;
bool __results[] = {__vs.valueless_by_exception()...};
for (bool __result : __results) {
if (__result) {
__throw_bad_variant_access();
}
}
return __variant::__visit_value(_VSTD::forward<_Visitor>(__visitor),
_VSTD::forward<_Vs>(__vs)...);
}
struct _LIBCPP_TEMPLATE_VIS monostate {};
inline _LIBCPP_INLINE_VISIBILITY
constexpr bool operator<(monostate, monostate) noexcept { return false; }
inline _LIBCPP_INLINE_VISIBILITY
constexpr bool operator>(monostate, monostate) noexcept { return false; }
inline _LIBCPP_INLINE_VISIBILITY
constexpr bool operator<=(monostate, monostate) noexcept { return true; }
inline _LIBCPP_INLINE_VISIBILITY
constexpr bool operator>=(monostate, monostate) noexcept { return true; }
inline _LIBCPP_INLINE_VISIBILITY
constexpr bool operator==(monostate, monostate) noexcept { return true; }
inline _LIBCPP_INLINE_VISIBILITY
constexpr bool operator!=(monostate, monostate) noexcept { return false; }
template <class... _Types>
inline _LIBCPP_INLINE_VISIBILITY
auto swap(variant<_Types...>& __lhs,
variant<_Types...>& __rhs) noexcept(noexcept(__lhs.swap(__rhs)))
-> decltype(__lhs.swap(__rhs)) {
__lhs.swap(__rhs);
}
template <class... _Types>
struct _LIBCPP_TEMPLATE_VIS hash<
__enable_hash_helper<variant<_Types...>, remove_const_t<_Types>...>> {
using argument_type = variant<_Types...>;
using result_type = size_t;
inline _LIBCPP_INLINE_VISIBILITY
result_type operator()(const argument_type& __v) const {
using __variant_detail::__visitation::__variant;
size_t __res =
__v.valueless_by_exception()
? 299792458 // Random value chosen by the universe upon creation
: __variant::__visit_alt(
[](const auto& __alt) {
using __alt_type = __uncvref_t<decltype(__alt)>;
using __value_type = remove_const_t<
typename __alt_type::__value_type>;
return hash<__value_type>{}(__alt.__value);
},
__v);
return __hash_combine(__res, hash<size_t>{}(__v.index()));
}
};
template <>
struct _LIBCPP_TEMPLATE_VIS hash<monostate> {
using argument_type = monostate;
using result_type = size_t;
inline _LIBCPP_INLINE_VISIBILITY
result_type operator()(const argument_type&) const _NOEXCEPT {
return 66740831; // return a fundamentally attractive random value.
}
};
#endif // _LIBCPP_STD_VER > 14
_LIBCPP_END_NAMESPACE_STD
_LIBCPP_POP_MACROS
#endif // _LIBCPP_VARIANT
| 62,277 | 1,670 | jart/cosmopolitan | false |
cosmopolitan/third_party/libcxx/__hash_table | // -*- 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__HASH_TABLE
#define _LIBCPP__HASH_TABLE
#include "third_party/libcxx/__config"
#include "third_party/libcxx/initializer_list"
#include "third_party/libcxx/memory"
#include "third_party/libcxx/iterator"
#include "third_party/libcxx/algorithm"
#include "third_party/libcxx/cmath"
#include "third_party/libcxx/utility"
#include "third_party/libcxx/type_traits"
#include "third_party/libcxx/__debug"
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
#pragma GCC system_header
#endif
_LIBCPP_PUSH_MACROS
#include "third_party/libcxx/__undef_macros"
_LIBCPP_BEGIN_NAMESPACE_STD
template <class _Key, class _Tp>
struct __hash_value_type;
#ifndef _LIBCPP_CXX03_LANG
template <class _Tp>
struct __is_hash_value_type_imp : false_type {};
template <class _Key, class _Value>
struct __is_hash_value_type_imp<__hash_value_type<_Key, _Value>> : true_type {};
template <class ..._Args>
struct __is_hash_value_type : false_type {};
template <class _One>
struct __is_hash_value_type<_One> : __is_hash_value_type_imp<typename __uncvref<_One>::type> {};
#endif
_LIBCPP_FUNC_VIS
size_t __next_prime(size_t __n);
template <class _NodePtr>
struct __hash_node_base
{
typedef typename pointer_traits<_NodePtr>::element_type __node_type;
typedef __hash_node_base __first_node;
typedef typename __rebind_pointer<_NodePtr, __first_node>::type __node_base_pointer;
typedef _NodePtr __node_pointer;
#if defined(_LIBCPP_ABI_FIX_UNORDERED_NODE_POINTER_UB)
typedef __node_base_pointer __next_pointer;
#else
typedef typename conditional<
is_pointer<__node_pointer>::value,
__node_base_pointer,
__node_pointer>::type __next_pointer;
#endif
__next_pointer __next_;
_LIBCPP_INLINE_VISIBILITY
__next_pointer __ptr() _NOEXCEPT {
return static_cast<__next_pointer>(
pointer_traits<__node_base_pointer>::pointer_to(*this));
}
_LIBCPP_INLINE_VISIBILITY
__node_pointer __upcast() _NOEXCEPT {
return static_cast<__node_pointer>(
pointer_traits<__node_base_pointer>::pointer_to(*this));
}
_LIBCPP_INLINE_VISIBILITY
size_t __hash() const _NOEXCEPT {
return static_cast<__node_type const&>(*this).__hash_;
}
_LIBCPP_INLINE_VISIBILITY __hash_node_base() _NOEXCEPT : __next_(nullptr) {}
};
template <class _Tp, class _VoidPtr>
struct __hash_node
: public __hash_node_base
<
typename __rebind_pointer<_VoidPtr, __hash_node<_Tp, _VoidPtr> >::type
>
{
typedef _Tp __node_value_type;
size_t __hash_;
__node_value_type __value_;
};
inline _LIBCPP_INLINE_VISIBILITY
bool
__is_hash_power2(size_t __bc)
{
return __bc > 2 && !(__bc & (__bc - 1));
}
inline _LIBCPP_INLINE_VISIBILITY
size_t
__constrain_hash(size_t __h, size_t __bc)
{
return !(__bc & (__bc - 1)) ? __h & (__bc - 1) :
(__h < __bc ? __h : __h % __bc);
}
inline _LIBCPP_INLINE_VISIBILITY
size_t
__next_hash_pow2(size_t __n)
{
return __n < 2 ? __n : (size_t(1) << (std::numeric_limits<size_t>::digits - __libcpp_clz(__n-1)));
}
template <class _Tp, class _Hash, class _Equal, class _Alloc> class __hash_table;
template <class _NodePtr> class _LIBCPP_TEMPLATE_VIS __hash_iterator;
template <class _ConstNodePtr> class _LIBCPP_TEMPLATE_VIS __hash_const_iterator;
template <class _NodePtr> class _LIBCPP_TEMPLATE_VIS __hash_local_iterator;
template <class _ConstNodePtr> class _LIBCPP_TEMPLATE_VIS __hash_const_local_iterator;
template <class _HashIterator> class _LIBCPP_TEMPLATE_VIS __hash_map_iterator;
template <class _HashIterator> class _LIBCPP_TEMPLATE_VIS __hash_map_const_iterator;
template <class _Tp>
struct __hash_key_value_types {
static_assert(!is_reference<_Tp>::value && !is_const<_Tp>::value, "");
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);
}
#ifndef _LIBCPP_CXX03_LANG
_LIBCPP_INLINE_VISIBILITY
static __container_value_type&& __move(__node_value_type& __v) {
return _VSTD::move(__v);
}
#endif
};
template <class _Key, class _Tp>
struct __hash_key_value_types<__hash_value_type<_Key, _Tp> > {
typedef _Key key_type;
typedef _Tp mapped_type;
typedef __hash_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(__container_value_type const& __v) {
return __v.first;
}
template <class _Up>
_LIBCPP_INLINE_VISIBILITY
static typename enable_if<__is_same_uncvref<_Up, __node_value_type>::value,
__container_value_type const&>::type
__get_value(_Up& __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());
}
#ifndef _LIBCPP_CXX03_LANG
_LIBCPP_INLINE_VISIBILITY
static pair<key_type&&, mapped_type&&> __move(__node_value_type& __v) {
return __v.__move();
}
#endif
};
template <class _Tp, class _AllocPtr, class _KVTypes = __hash_key_value_types<_Tp>,
bool = _KVTypes::__is_map>
struct __hash_map_pointer_types {};
template <class _Tp, class _AllocPtr, class _KVTypes>
struct __hash_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 __hash_node_types;
template <class _NodePtr, class _Tp, class _VoidPtr>
struct __hash_node_types<_NodePtr, __hash_node<_Tp, _VoidPtr> >
: public __hash_key_value_types<_Tp>, __hash_map_pointer_types<_Tp, _VoidPtr>
{
typedef __hash_key_value_types<_Tp> __base;
public:
typedef ptrdiff_t difference_type;
typedef size_t size_type;
typedef typename __rebind_pointer<_NodePtr, void>::type __void_pointer;
typedef typename pointer_traits<_NodePtr>::element_type __node_type;
typedef _NodePtr __node_pointer;
typedef __hash_node_base<__node_pointer> __node_base_type;
typedef typename __rebind_pointer<_NodePtr, __node_base_type>::type
__node_base_pointer;
typedef typename __node_base_type::__next_pointer __next_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;
private:
static_assert(!is_const<__node_type>::value,
"_NodePtr should never be a pointer to const");
static_assert((is_same<typename pointer_traits<_VoidPtr>::element_type, void>::value),
"_VoidPtr does not point to unqualified void type");
static_assert((is_same<typename __rebind_pointer<_VoidPtr, __node_type>::type,
_NodePtr>::value), "_VoidPtr does not rebind to _NodePtr.");
};
template <class _HashIterator>
struct __hash_node_types_from_iterator;
template <class _NodePtr>
struct __hash_node_types_from_iterator<__hash_iterator<_NodePtr> > : __hash_node_types<_NodePtr> {};
template <class _NodePtr>
struct __hash_node_types_from_iterator<__hash_const_iterator<_NodePtr> > : __hash_node_types<_NodePtr> {};
template <class _NodePtr>
struct __hash_node_types_from_iterator<__hash_local_iterator<_NodePtr> > : __hash_node_types<_NodePtr> {};
template <class _NodePtr>
struct __hash_node_types_from_iterator<__hash_const_local_iterator<_NodePtr> > : __hash_node_types<_NodePtr> {};
template <class _NodeValueTp, class _VoidPtr>
struct __make_hash_node_types {
typedef __hash_node<_NodeValueTp, _VoidPtr> _NodeTp;
typedef typename __rebind_pointer<_VoidPtr, _NodeTp>::type _NodePtr;
typedef __hash_node_types<_NodePtr> type;
};
template <class _NodePtr>
class _LIBCPP_TEMPLATE_VIS __hash_iterator
{
typedef __hash_node_types<_NodePtr> _NodeTypes;
typedef _NodePtr __node_pointer;
typedef typename _NodeTypes::__next_pointer __next_pointer;
__next_pointer __node_;
public:
typedef forward_iterator_tag iterator_category;
typedef typename _NodeTypes::__node_value_type value_type;
typedef typename _NodeTypes::difference_type difference_type;
typedef value_type& reference;
typedef typename _NodeTypes::__node_value_type_pointer pointer;
_LIBCPP_INLINE_VISIBILITY __hash_iterator() _NOEXCEPT : __node_(nullptr) {
_LIBCPP_DEBUG_MODE(__get_db()->__insert_i(this));
}
#if _LIBCPP_DEBUG_LEVEL >= 2
_LIBCPP_INLINE_VISIBILITY
__hash_iterator(const __hash_iterator& __i)
: __node_(__i.__node_)
{
__get_db()->__iterator_copy(this, &__i);
}
_LIBCPP_INLINE_VISIBILITY
~__hash_iterator()
{
__get_db()->__erase_i(this);
}
_LIBCPP_INLINE_VISIBILITY
__hash_iterator& operator=(const __hash_iterator& __i)
{
if (this != &__i)
{
__get_db()->__iterator_copy(this, &__i);
__node_ = __i.__node_;
}
return *this;
}
#endif // _LIBCPP_DEBUG_LEVEL >= 2
_LIBCPP_INLINE_VISIBILITY
reference operator*() const {
_LIBCPP_DEBUG_ASSERT(__get_const_db()->__dereferenceable(this),
"Attempted to dereference a non-dereferenceable unordered container iterator");
return __node_->__upcast()->__value_;
}
_LIBCPP_INLINE_VISIBILITY
pointer operator->() const {
_LIBCPP_DEBUG_ASSERT(__get_const_db()->__dereferenceable(this),
"Attempted to dereference a non-dereferenceable unordered container iterator");
return pointer_traits<pointer>::pointer_to(__node_->__upcast()->__value_);
}
_LIBCPP_INLINE_VISIBILITY
__hash_iterator& operator++() {
_LIBCPP_DEBUG_ASSERT(__get_const_db()->__dereferenceable(this),
"Attempted to increment non-incrementable unordered container iterator");
__node_ = __node_->__next_;
return *this;
}
_LIBCPP_INLINE_VISIBILITY
__hash_iterator operator++(int)
{
__hash_iterator __t(*this);
++(*this);
return __t;
}
friend _LIBCPP_INLINE_VISIBILITY
bool operator==(const __hash_iterator& __x, const __hash_iterator& __y)
{
return __x.__node_ == __y.__node_;
}
friend _LIBCPP_INLINE_VISIBILITY
bool operator!=(const __hash_iterator& __x, const __hash_iterator& __y)
{return !(__x == __y);}
private:
#if _LIBCPP_DEBUG_LEVEL >= 2
_LIBCPP_INLINE_VISIBILITY
__hash_iterator(__next_pointer __node, const void* __c) _NOEXCEPT
: __node_(__node)
{
__get_db()->__insert_ic(this, __c);
}
#else
_LIBCPP_INLINE_VISIBILITY
__hash_iterator(__next_pointer __node) _NOEXCEPT
: __node_(__node)
{}
#endif
template <class, class, class, class> friend class __hash_table;
template <class> friend class _LIBCPP_TEMPLATE_VIS __hash_const_iterator;
template <class> friend class _LIBCPP_TEMPLATE_VIS __hash_map_iterator;
template <class, class, class, class, class> friend class _LIBCPP_TEMPLATE_VIS unordered_map;
template <class, class, class, class, class> friend class _LIBCPP_TEMPLATE_VIS unordered_multimap;
};
template <class _NodePtr>
class _LIBCPP_TEMPLATE_VIS __hash_const_iterator
{
static_assert(!is_const<typename pointer_traits<_NodePtr>::element_type>::value, "");
typedef __hash_node_types<_NodePtr> _NodeTypes;
typedef _NodePtr __node_pointer;
typedef typename _NodeTypes::__next_pointer __next_pointer;
__next_pointer __node_;
public:
typedef __hash_iterator<_NodePtr> __non_const_iterator;
typedef forward_iterator_tag iterator_category;
typedef typename _NodeTypes::__node_value_type value_type;
typedef typename _NodeTypes::difference_type difference_type;
typedef const value_type& reference;
typedef typename _NodeTypes::__const_node_value_type_pointer pointer;
_LIBCPP_INLINE_VISIBILITY __hash_const_iterator() _NOEXCEPT : __node_(nullptr) {
_LIBCPP_DEBUG_MODE(__get_db()->__insert_i(this));
}
_LIBCPP_INLINE_VISIBILITY
__hash_const_iterator(const __non_const_iterator& __x) _NOEXCEPT
: __node_(__x.__node_)
{
_LIBCPP_DEBUG_MODE(__get_db()->__iterator_copy(this, &__x));
}
#if _LIBCPP_DEBUG_LEVEL >= 2
_LIBCPP_INLINE_VISIBILITY
__hash_const_iterator(const __hash_const_iterator& __i)
: __node_(__i.__node_)
{
__get_db()->__iterator_copy(this, &__i);
}
_LIBCPP_INLINE_VISIBILITY
~__hash_const_iterator()
{
__get_db()->__erase_i(this);
}
_LIBCPP_INLINE_VISIBILITY
__hash_const_iterator& operator=(const __hash_const_iterator& __i)
{
if (this != &__i)
{
__get_db()->__iterator_copy(this, &__i);
__node_ = __i.__node_;
}
return *this;
}
#endif // _LIBCPP_DEBUG_LEVEL >= 2
_LIBCPP_INLINE_VISIBILITY
reference operator*() const {
_LIBCPP_DEBUG_ASSERT(__get_const_db()->__dereferenceable(this),
"Attempted to dereference a non-dereferenceable unordered container const_iterator");
return __node_->__upcast()->__value_;
}
_LIBCPP_INLINE_VISIBILITY
pointer operator->() const {
_LIBCPP_DEBUG_ASSERT(__get_const_db()->__dereferenceable(this),
"Attempted to dereference a non-dereferenceable unordered container const_iterator");
return pointer_traits<pointer>::pointer_to(__node_->__upcast()->__value_);
}
_LIBCPP_INLINE_VISIBILITY
__hash_const_iterator& operator++() {
_LIBCPP_DEBUG_ASSERT(__get_const_db()->__dereferenceable(this),
"Attempted to increment non-incrementable unordered container const_iterator");
__node_ = __node_->__next_;
return *this;
}
_LIBCPP_INLINE_VISIBILITY
__hash_const_iterator operator++(int)
{
__hash_const_iterator __t(*this);
++(*this);
return __t;
}
friend _LIBCPP_INLINE_VISIBILITY
bool operator==(const __hash_const_iterator& __x, const __hash_const_iterator& __y)
{
return __x.__node_ == __y.__node_;
}
friend _LIBCPP_INLINE_VISIBILITY
bool operator!=(const __hash_const_iterator& __x, const __hash_const_iterator& __y)
{return !(__x == __y);}
private:
#if _LIBCPP_DEBUG_LEVEL >= 2
_LIBCPP_INLINE_VISIBILITY
__hash_const_iterator(__next_pointer __node, const void* __c) _NOEXCEPT
: __node_(__node)
{
__get_db()->__insert_ic(this, __c);
}
#else
_LIBCPP_INLINE_VISIBILITY
__hash_const_iterator(__next_pointer __node) _NOEXCEPT
: __node_(__node)
{}
#endif
template <class, class, class, class> friend class __hash_table;
template <class> friend class _LIBCPP_TEMPLATE_VIS __hash_map_const_iterator;
template <class, class, class, class, class> friend class _LIBCPP_TEMPLATE_VIS unordered_map;
template <class, class, class, class, class> friend class _LIBCPP_TEMPLATE_VIS unordered_multimap;
};
template <class _NodePtr>
class _LIBCPP_TEMPLATE_VIS __hash_local_iterator
{
typedef __hash_node_types<_NodePtr> _NodeTypes;
typedef _NodePtr __node_pointer;
typedef typename _NodeTypes::__next_pointer __next_pointer;
__next_pointer __node_;
size_t __bucket_;
size_t __bucket_count_;
public:
typedef forward_iterator_tag iterator_category;
typedef typename _NodeTypes::__node_value_type value_type;
typedef typename _NodeTypes::difference_type difference_type;
typedef value_type& reference;
typedef typename _NodeTypes::__node_value_type_pointer pointer;
_LIBCPP_INLINE_VISIBILITY __hash_local_iterator() _NOEXCEPT : __node_(nullptr) {
_LIBCPP_DEBUG_MODE(__get_db()->__insert_i(this));
}
#if _LIBCPP_DEBUG_LEVEL >= 2
_LIBCPP_INLINE_VISIBILITY
__hash_local_iterator(const __hash_local_iterator& __i)
: __node_(__i.__node_),
__bucket_(__i.__bucket_),
__bucket_count_(__i.__bucket_count_)
{
__get_db()->__iterator_copy(this, &__i);
}
_LIBCPP_INLINE_VISIBILITY
~__hash_local_iterator()
{
__get_db()->__erase_i(this);
}
_LIBCPP_INLINE_VISIBILITY
__hash_local_iterator& operator=(const __hash_local_iterator& __i)
{
if (this != &__i)
{
__get_db()->__iterator_copy(this, &__i);
__node_ = __i.__node_;
__bucket_ = __i.__bucket_;
__bucket_count_ = __i.__bucket_count_;
}
return *this;
}
#endif // _LIBCPP_DEBUG_LEVEL >= 2
_LIBCPP_INLINE_VISIBILITY
reference operator*() const {
_LIBCPP_DEBUG_ASSERT(__get_const_db()->__dereferenceable(this),
"Attempted to dereference a non-dereferenceable unordered container local_iterator");
return __node_->__upcast()->__value_;
}
_LIBCPP_INLINE_VISIBILITY
pointer operator->() const {
_LIBCPP_DEBUG_ASSERT(__get_const_db()->__dereferenceable(this),
"Attempted to dereference a non-dereferenceable unordered container local_iterator");
return pointer_traits<pointer>::pointer_to(__node_->__upcast()->__value_);
}
_LIBCPP_INLINE_VISIBILITY
__hash_local_iterator& operator++() {
_LIBCPP_DEBUG_ASSERT(__get_const_db()->__dereferenceable(this),
"Attempted to increment non-incrementable unordered container local_iterator");
__node_ = __node_->__next_;
if (__node_ != nullptr && __constrain_hash(__node_->__hash(), __bucket_count_) != __bucket_)
__node_ = nullptr;
return *this;
}
_LIBCPP_INLINE_VISIBILITY
__hash_local_iterator operator++(int)
{
__hash_local_iterator __t(*this);
++(*this);
return __t;
}
friend _LIBCPP_INLINE_VISIBILITY
bool operator==(const __hash_local_iterator& __x, const __hash_local_iterator& __y)
{
return __x.__node_ == __y.__node_;
}
friend _LIBCPP_INLINE_VISIBILITY
bool operator!=(const __hash_local_iterator& __x, const __hash_local_iterator& __y)
{return !(__x == __y);}
private:
#if _LIBCPP_DEBUG_LEVEL >= 2
_LIBCPP_INLINE_VISIBILITY
__hash_local_iterator(__next_pointer __node, size_t __bucket,
size_t __bucket_count, const void* __c) _NOEXCEPT
: __node_(__node),
__bucket_(__bucket),
__bucket_count_(__bucket_count)
{
__get_db()->__insert_ic(this, __c);
if (__node_ != nullptr)
__node_ = __node_->__next_;
}
#else
_LIBCPP_INLINE_VISIBILITY
__hash_local_iterator(__next_pointer __node, size_t __bucket,
size_t __bucket_count) _NOEXCEPT
: __node_(__node),
__bucket_(__bucket),
__bucket_count_(__bucket_count)
{
if (__node_ != nullptr)
__node_ = __node_->__next_;
}
#endif
template <class, class, class, class> friend class __hash_table;
template <class> friend class _LIBCPP_TEMPLATE_VIS __hash_const_local_iterator;
template <class> friend class _LIBCPP_TEMPLATE_VIS __hash_map_iterator;
};
template <class _ConstNodePtr>
class _LIBCPP_TEMPLATE_VIS __hash_const_local_iterator
{
typedef __hash_node_types<_ConstNodePtr> _NodeTypes;
typedef _ConstNodePtr __node_pointer;
typedef typename _NodeTypes::__next_pointer __next_pointer;
__next_pointer __node_;
size_t __bucket_;
size_t __bucket_count_;
typedef pointer_traits<__node_pointer> __pointer_traits;
typedef typename __pointer_traits::element_type __node;
typedef typename remove_const<__node>::type __non_const_node;
typedef typename __rebind_pointer<__node_pointer, __non_const_node>::type
__non_const_node_pointer;
public:
typedef __hash_local_iterator<__non_const_node_pointer>
__non_const_iterator;
typedef forward_iterator_tag iterator_category;
typedef typename _NodeTypes::__node_value_type value_type;
typedef typename _NodeTypes::difference_type difference_type;
typedef const value_type& reference;
typedef typename _NodeTypes::__const_node_value_type_pointer pointer;
_LIBCPP_INLINE_VISIBILITY __hash_const_local_iterator() _NOEXCEPT : __node_(nullptr) {
_LIBCPP_DEBUG_MODE(__get_db()->__insert_i(this));
}
_LIBCPP_INLINE_VISIBILITY
__hash_const_local_iterator(const __non_const_iterator& __x) _NOEXCEPT
: __node_(__x.__node_),
__bucket_(__x.__bucket_),
__bucket_count_(__x.__bucket_count_)
{
_LIBCPP_DEBUG_MODE(__get_db()->__iterator_copy(this, &__x));
}
#if _LIBCPP_DEBUG_LEVEL >= 2
_LIBCPP_INLINE_VISIBILITY
__hash_const_local_iterator(const __hash_const_local_iterator& __i)
: __node_(__i.__node_),
__bucket_(__i.__bucket_),
__bucket_count_(__i.__bucket_count_)
{
__get_db()->__iterator_copy(this, &__i);
}
_LIBCPP_INLINE_VISIBILITY
~__hash_const_local_iterator()
{
__get_db()->__erase_i(this);
}
_LIBCPP_INLINE_VISIBILITY
__hash_const_local_iterator& operator=(const __hash_const_local_iterator& __i)
{
if (this != &__i)
{
__get_db()->__iterator_copy(this, &__i);
__node_ = __i.__node_;
__bucket_ = __i.__bucket_;
__bucket_count_ = __i.__bucket_count_;
}
return *this;
}
#endif // _LIBCPP_DEBUG_LEVEL >= 2
_LIBCPP_INLINE_VISIBILITY
reference operator*() const {
_LIBCPP_DEBUG_ASSERT(__get_const_db()->__dereferenceable(this),
"Attempted to dereference a non-dereferenceable unordered container const_local_iterator");
return __node_->__upcast()->__value_;
}
_LIBCPP_INLINE_VISIBILITY
pointer operator->() const {
_LIBCPP_DEBUG_ASSERT(__get_const_db()->__dereferenceable(this),
"Attempted to dereference a non-dereferenceable unordered container const_local_iterator");
return pointer_traits<pointer>::pointer_to(__node_->__upcast()->__value_);
}
_LIBCPP_INLINE_VISIBILITY
__hash_const_local_iterator& operator++() {
_LIBCPP_DEBUG_ASSERT(__get_const_db()->__dereferenceable(this),
"Attempted to increment non-incrementable unordered container const_local_iterator");
__node_ = __node_->__next_;
if (__node_ != nullptr && __constrain_hash(__node_->__hash(), __bucket_count_) != __bucket_)
__node_ = nullptr;
return *this;
}
_LIBCPP_INLINE_VISIBILITY
__hash_const_local_iterator operator++(int)
{
__hash_const_local_iterator __t(*this);
++(*this);
return __t;
}
friend _LIBCPP_INLINE_VISIBILITY
bool operator==(const __hash_const_local_iterator& __x, const __hash_const_local_iterator& __y)
{
return __x.__node_ == __y.__node_;
}
friend _LIBCPP_INLINE_VISIBILITY
bool operator!=(const __hash_const_local_iterator& __x, const __hash_const_local_iterator& __y)
{return !(__x == __y);}
private:
#if _LIBCPP_DEBUG_LEVEL >= 2
_LIBCPP_INLINE_VISIBILITY
__hash_const_local_iterator(__next_pointer __node, size_t __bucket,
size_t __bucket_count, const void* __c) _NOEXCEPT
: __node_(__node),
__bucket_(__bucket),
__bucket_count_(__bucket_count)
{
__get_db()->__insert_ic(this, __c);
if (__node_ != nullptr)
__node_ = __node_->__next_;
}
#else
_LIBCPP_INLINE_VISIBILITY
__hash_const_local_iterator(__next_pointer __node, size_t __bucket,
size_t __bucket_count) _NOEXCEPT
: __node_(__node),
__bucket_(__bucket),
__bucket_count_(__bucket_count)
{
if (__node_ != nullptr)
__node_ = __node_->__next_;
}
#endif
template <class, class, class, class> friend class __hash_table;
template <class> friend class _LIBCPP_TEMPLATE_VIS __hash_map_const_iterator;
};
template <class _Alloc>
class __bucket_list_deallocator
{
typedef _Alloc allocator_type;
typedef allocator_traits<allocator_type> __alloc_traits;
typedef typename __alloc_traits::size_type size_type;
__compressed_pair<size_type, allocator_type> __data_;
public:
typedef typename __alloc_traits::pointer pointer;
_LIBCPP_INLINE_VISIBILITY
__bucket_list_deallocator()
_NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value)
: __data_(0) {}
_LIBCPP_INLINE_VISIBILITY
__bucket_list_deallocator(const allocator_type& __a, size_type __size)
_NOEXCEPT_(is_nothrow_copy_constructible<allocator_type>::value)
: __data_(__size, __a) {}
#ifndef _LIBCPP_CXX03_LANG
_LIBCPP_INLINE_VISIBILITY
__bucket_list_deallocator(__bucket_list_deallocator&& __x)
_NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value)
: __data_(_VSTD::move(__x.__data_))
{
__x.size() = 0;
}
#endif
_LIBCPP_INLINE_VISIBILITY
size_type& size() _NOEXCEPT {return __data_.first();}
_LIBCPP_INLINE_VISIBILITY
size_type size() const _NOEXCEPT {return __data_.first();}
_LIBCPP_INLINE_VISIBILITY
allocator_type& __alloc() _NOEXCEPT {return __data_.second();}
_LIBCPP_INLINE_VISIBILITY
const allocator_type& __alloc() const _NOEXCEPT {return __data_.second();}
_LIBCPP_INLINE_VISIBILITY
void operator()(pointer __p) _NOEXCEPT
{
__alloc_traits::deallocate(__alloc(), __p, size());
}
};
template <class _Alloc> class __hash_map_node_destructor;
template <class _Alloc>
class __hash_node_destructor
{
typedef _Alloc allocator_type;
typedef allocator_traits<allocator_type> __alloc_traits;
public:
typedef typename __alloc_traits::pointer pointer;
private:
typedef __hash_node_types<pointer> _NodeTypes;
allocator_type& __na_;
__hash_node_destructor& operator=(const __hash_node_destructor&);
public:
bool __value_constructed;
_LIBCPP_INLINE_VISIBILITY
explicit __hash_node_destructor(allocator_type& __na,
bool __constructed = false) _NOEXCEPT
: __na_(__na),
__value_constructed(__constructed)
{}
_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 __hash_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<__hash_node<_Tp, _VoidPtr>, _Alloc>
: __hash_node_destructor<_Alloc>
{
using __hash_node_destructor<_Alloc>::__hash_node_destructor;
};
#endif
template <class _Key, class _Hash, class _Equal>
struct __enforce_unordered_container_requirements {
#ifndef _LIBCPP_CXX03_LANG
static_assert(__check_hash_requirements<_Key, _Hash>::value,
"the specified hash does not meet the Hash requirements");
static_assert(is_copy_constructible<_Equal>::value,
"the specified comparator is required to be copy constructible");
#endif
typedef int type;
};
template <class _Key, class _Hash, class _Equal>
#ifndef _LIBCPP_CXX03_LANG
_LIBCPP_DIAGNOSE_WARNING(!__invokable<_Equal const&, _Key const&, _Key const&>::value,
"the specified comparator type does not provide a viable const call operator")
_LIBCPP_DIAGNOSE_WARNING(!__invokable<_Hash const&, _Key const&>::value,
"the specified hash functor does not provide a viable const call operator")
#endif
typename __enforce_unordered_container_requirements<_Key, _Hash, _Equal>::type
__diagnose_unordered_container_requirements(int);
// This dummy overload is used so that the compiler won't emit a spurious
// "no matching function for call to __diagnose_unordered_xxx" diagnostic
// when the overload above causes a hard error.
template <class _Key, class _Hash, class _Equal>
int __diagnose_unordered_container_requirements(void*);
template <class _Tp, class _Hash, class _Equal, class _Alloc>
class __hash_table
{
public:
typedef _Tp value_type;
typedef _Hash hasher;
typedef _Equal key_equal;
typedef _Alloc allocator_type;
private:
typedef allocator_traits<allocator_type> __alloc_traits;
typedef typename
__make_hash_node_types<value_type, typename __alloc_traits::void_pointer>::type
_NodeTypes;
public:
typedef typename _NodeTypes::__node_value_type __node_value_type;
typedef typename _NodeTypes::__container_value_type __container_value_type;
typedef typename _NodeTypes::key_type key_type;
typedef value_type& reference;
typedef const value_type& const_reference;
typedef typename __alloc_traits::pointer pointer;
typedef typename __alloc_traits::const_pointer const_pointer;
#ifndef _LIBCPP_ABI_FIX_UNORDERED_CONTAINER_SIZE_TYPE
typedef typename __alloc_traits::size_type size_type;
#else
typedef typename _NodeTypes::size_type size_type;
#endif
typedef typename _NodeTypes::difference_type difference_type;
public:
// Create __node
typedef typename _NodeTypes::__node_type __node;
typedef typename __rebind_alloc_helper<__alloc_traits, __node>::type __node_allocator;
typedef allocator_traits<__node_allocator> __node_traits;
typedef typename _NodeTypes::__void_pointer __void_pointer;
typedef typename _NodeTypes::__node_pointer __node_pointer;
typedef typename _NodeTypes::__node_pointer __node_const_pointer;
typedef typename _NodeTypes::__node_base_type __first_node;
typedef typename _NodeTypes::__node_base_pointer __node_base_pointer;
typedef typename _NodeTypes::__next_pointer __next_pointer;
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, __first_node>::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:
typedef typename __rebind_alloc_helper<__node_traits, __next_pointer>::type __pointer_allocator;
typedef __bucket_list_deallocator<__pointer_allocator> __bucket_list_deleter;
typedef unique_ptr<__next_pointer[], __bucket_list_deleter> __bucket_list;
typedef allocator_traits<__pointer_allocator> __pointer_alloc_traits;
typedef typename __bucket_list_deleter::pointer __node_pointer_pointer;
// --- Member data begin ---
__bucket_list __bucket_list_;
__compressed_pair<__first_node, __node_allocator> __p1_;
__compressed_pair<size_type, hasher> __p2_;
__compressed_pair<float, key_equal> __p3_;
// --- Member data end ---
_LIBCPP_INLINE_VISIBILITY
size_type& size() _NOEXCEPT {return __p2_.first();}
public:
_LIBCPP_INLINE_VISIBILITY
size_type size() const _NOEXCEPT {return __p2_.first();}
_LIBCPP_INLINE_VISIBILITY
hasher& hash_function() _NOEXCEPT {return __p2_.second();}
_LIBCPP_INLINE_VISIBILITY
const hasher& hash_function() const _NOEXCEPT {return __p2_.second();}
_LIBCPP_INLINE_VISIBILITY
float& max_load_factor() _NOEXCEPT {return __p3_.first();}
_LIBCPP_INLINE_VISIBILITY
float max_load_factor() const _NOEXCEPT {return __p3_.first();}
_LIBCPP_INLINE_VISIBILITY
key_equal& key_eq() _NOEXCEPT {return __p3_.second();}
_LIBCPP_INLINE_VISIBILITY
const key_equal& key_eq() const _NOEXCEPT {return __p3_.second();}
_LIBCPP_INLINE_VISIBILITY
__node_allocator& __node_alloc() _NOEXCEPT {return __p1_.second();}
_LIBCPP_INLINE_VISIBILITY
const __node_allocator& __node_alloc() const _NOEXCEPT
{return __p1_.second();}
public:
typedef __hash_iterator<__node_pointer> iterator;
typedef __hash_const_iterator<__node_pointer> const_iterator;
typedef __hash_local_iterator<__node_pointer> local_iterator;
typedef __hash_const_local_iterator<__node_pointer> const_local_iterator;
_LIBCPP_INLINE_VISIBILITY
__hash_table()
_NOEXCEPT_(
is_nothrow_default_constructible<__bucket_list>::value &&
is_nothrow_default_constructible<__first_node>::value &&
is_nothrow_default_constructible<__node_allocator>::value &&
is_nothrow_default_constructible<hasher>::value &&
is_nothrow_default_constructible<key_equal>::value);
_LIBCPP_INLINE_VISIBILITY
__hash_table(const hasher& __hf, const key_equal& __eql);
__hash_table(const hasher& __hf, const key_equal& __eql,
const allocator_type& __a);
explicit __hash_table(const allocator_type& __a);
__hash_table(const __hash_table& __u);
__hash_table(const __hash_table& __u, const allocator_type& __a);
#ifndef _LIBCPP_CXX03_LANG
__hash_table(__hash_table&& __u)
_NOEXCEPT_(
is_nothrow_move_constructible<__bucket_list>::value &&
is_nothrow_move_constructible<__first_node>::value &&
is_nothrow_move_constructible<__node_allocator>::value &&
is_nothrow_move_constructible<hasher>::value &&
is_nothrow_move_constructible<key_equal>::value);
__hash_table(__hash_table&& __u, const allocator_type& __a);
#endif // _LIBCPP_CXX03_LANG
~__hash_table();
__hash_table& operator=(const __hash_table& __u);
#ifndef _LIBCPP_CXX03_LANG
_LIBCPP_INLINE_VISIBILITY
__hash_table& operator=(__hash_table&& __u)
_NOEXCEPT_(
__node_traits::propagate_on_container_move_assignment::value &&
is_nothrow_move_assignable<__node_allocator>::value &&
is_nothrow_move_assignable<hasher>::value &&
is_nothrow_move_assignable<key_equal>::value);
#endif
template <class _InputIterator>
void __assign_unique(_InputIterator __first, _InputIterator __last);
template <class _InputIterator>
void __assign_multi(_InputIterator __first, _InputIterator __last);
_LIBCPP_INLINE_VISIBILITY
size_type max_size() const _NOEXCEPT
{
return std::min<size_type>(
__node_traits::max_size(__node_alloc()),
numeric_limits<difference_type >::max()
);
}
private:
_LIBCPP_INLINE_VISIBILITY
__next_pointer __node_insert_multi_prepare(size_t __cp_hash,
value_type& __cp_val);
_LIBCPP_INLINE_VISIBILITY
void __node_insert_multi_perform(__node_pointer __cp,
__next_pointer __pn) _NOEXCEPT;
_LIBCPP_INLINE_VISIBILITY
__next_pointer __node_insert_unique_prepare(size_t __nd_hash,
value_type& __nd_val);
_LIBCPP_INLINE_VISIBILITY
void __node_insert_unique_perform(__node_pointer __ptr) _NOEXCEPT;
public:
_LIBCPP_INLINE_VISIBILITY
pair<iterator, bool> __node_insert_unique(__node_pointer __nd);
_LIBCPP_INLINE_VISIBILITY
iterator __node_insert_multi(__node_pointer __nd);
_LIBCPP_INLINE_VISIBILITY
iterator __node_insert_multi(const_iterator __p,
__node_pointer __nd);
#ifndef _LIBCPP_CXX03_LANG
template <class _Key, class ..._Args>
inline _LIBCPP_INLINE_VISIBILITY
pair<iterator, bool> __emplace_unique_key_args(_Key const& __k, _Args&&... __args);
template <class... _Args>
_LIBCPP_INLINE_VISIBILITY
pair<iterator, bool> __emplace_unique_impl(_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... _Args>
_LIBCPP_INLINE_VISIBILITY
iterator __emplace_multi(_Args&&... __args);
template <class... _Args>
_LIBCPP_INLINE_VISIBILITY
iterator __emplace_hint_multi(const_iterator __p, _Args&&... __args);
_LIBCPP_INLINE_VISIBILITY
pair<iterator, bool>
__insert_unique(__container_value_type&& __x) {
return __emplace_unique_key_args(_NodeTypes::__get_key(__x), _VSTD::move(__x));
}
template <class _Pp, class = typename enable_if<
!__is_same_uncvref<_Pp, __container_value_type>::value
>::type>
_LIBCPP_INLINE_VISIBILITY
pair<iterator, bool> __insert_unique(_Pp&& __x) {
return __emplace_unique(_VSTD::forward<_Pp>(__x));
}
template <class _Pp>
_LIBCPP_INLINE_VISIBILITY
iterator __insert_multi(_Pp&& __x) {
return __emplace_multi(_VSTD::forward<_Pp>(__x));
}
template <class _Pp>
_LIBCPP_INLINE_VISIBILITY
iterator __insert_multi(const_iterator __p, _Pp&& __x) {
return __emplace_hint_multi(__p, _VSTD::forward<_Pp>(__x));
}
#else // !defined(_LIBCPP_CXX03_LANG)
template <class _Key, class _Args>
_LIBCPP_INLINE_VISIBILITY
pair<iterator, bool> __emplace_unique_key_args(_Key const&, _Args& __args);
iterator __insert_multi(const __container_value_type& __x);
iterator __insert_multi(const_iterator __p, const __container_value_type& __x);
#endif
_LIBCPP_INLINE_VISIBILITY
pair<iterator, bool> __insert_unique(const __container_value_type& __x) {
return __emplace_unique_key_args(_NodeTypes::__get_key(__x), __x);
}
#if _LIBCPP_STD_VER > 14
template <class _NodeHandle, class _InsertReturnType>
_LIBCPP_INLINE_VISIBILITY
_InsertReturnType __node_handle_insert_unique(_NodeHandle&& __nh);
template <class _NodeHandle>
_LIBCPP_INLINE_VISIBILITY
iterator __node_handle_insert_unique(const_iterator __hint,
_NodeHandle&& __nh);
template <class _Table>
_LIBCPP_INLINE_VISIBILITY
void __node_handle_merge_unique(_Table& __source);
template <class _NodeHandle>
_LIBCPP_INLINE_VISIBILITY
iterator __node_handle_insert_multi(_NodeHandle&& __nh);
template <class _NodeHandle>
_LIBCPP_INLINE_VISIBILITY
iterator __node_handle_insert_multi(const_iterator __hint, _NodeHandle&& __nh);
template <class _Table>
_LIBCPP_INLINE_VISIBILITY
void __node_handle_merge_multi(_Table& __source);
template <class _NodeHandle>
_LIBCPP_INLINE_VISIBILITY
_NodeHandle __node_handle_extract(key_type const& __key);
template <class _NodeHandle>
_LIBCPP_INLINE_VISIBILITY
_NodeHandle __node_handle_extract(const_iterator __it);
#endif
void clear() _NOEXCEPT;
void rehash(size_type __n);
_LIBCPP_INLINE_VISIBILITY void reserve(size_type __n)
{rehash(static_cast<size_type>(ceil(__n / max_load_factor())));}
_LIBCPP_INLINE_VISIBILITY
size_type bucket_count() const _NOEXCEPT
{
return __bucket_list_.get_deleter().size();
}
_LIBCPP_INLINE_VISIBILITY
iterator begin() _NOEXCEPT;
_LIBCPP_INLINE_VISIBILITY
iterator end() _NOEXCEPT;
_LIBCPP_INLINE_VISIBILITY
const_iterator begin() const _NOEXCEPT;
_LIBCPP_INLINE_VISIBILITY
const_iterator end() const _NOEXCEPT;
template <class _Key>
_LIBCPP_INLINE_VISIBILITY
size_type bucket(const _Key& __k) const
{
_LIBCPP_ASSERT(bucket_count() > 0,
"unordered container::bucket(key) called when bucket_count() == 0");
return __constrain_hash(hash_function()(__k), bucket_count());
}
template <class _Key>
iterator find(const _Key& __x);
template <class _Key>
const_iterator find(const _Key& __x) const;
typedef __hash_node_destructor<__node_allocator> _Dp;
typedef unique_ptr<__node, _Dp> __node_holder;
iterator erase(const_iterator __p);
iterator erase(const_iterator __first, const_iterator __last);
template <class _Key>
size_type __erase_unique(const _Key& __k);
template <class _Key>
size_type __erase_multi(const _Key& __k);
__node_holder remove(const_iterator __p) _NOEXCEPT;
template <class _Key>
_LIBCPP_INLINE_VISIBILITY
size_type __count_unique(const _Key& __k) const;
template <class _Key>
size_type __count_multi(const _Key& __k) 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;
void swap(__hash_table& __u)
#if _LIBCPP_STD_VER <= 11
_NOEXCEPT_(
__is_nothrow_swappable<hasher>::value && __is_nothrow_swappable<key_equal>::value
&& (!allocator_traits<__pointer_allocator>::propagate_on_container_swap::value
|| __is_nothrow_swappable<__pointer_allocator>::value)
&& (!__node_traits::propagate_on_container_swap::value
|| __is_nothrow_swappable<__node_allocator>::value)
);
#else
_NOEXCEPT_(__is_nothrow_swappable<hasher>::value && __is_nothrow_swappable<key_equal>::value);
#endif
_LIBCPP_INLINE_VISIBILITY
size_type max_bucket_count() const _NOEXCEPT
{return max_size(); }
size_type bucket_size(size_type __n) const;
_LIBCPP_INLINE_VISIBILITY float load_factor() const _NOEXCEPT
{
size_type __bc = bucket_count();
return __bc != 0 ? (float)size() / __bc : 0.f;
}
_LIBCPP_INLINE_VISIBILITY void max_load_factor(float __mlf) _NOEXCEPT
{
_LIBCPP_ASSERT(__mlf > 0,
"unordered container::max_load_factor(lf) called with lf <= 0");
max_load_factor() = _VSTD::max(__mlf, load_factor());
}
_LIBCPP_INLINE_VISIBILITY
local_iterator
begin(size_type __n)
{
_LIBCPP_ASSERT(__n < bucket_count(),
"unordered container::begin(n) called with n >= bucket_count()");
#if _LIBCPP_DEBUG_LEVEL >= 2
return local_iterator(__bucket_list_[__n], __n, bucket_count(), this);
#else
return local_iterator(__bucket_list_[__n], __n, bucket_count());
#endif
}
_LIBCPP_INLINE_VISIBILITY
local_iterator
end(size_type __n)
{
_LIBCPP_ASSERT(__n < bucket_count(),
"unordered container::end(n) called with n >= bucket_count()");
#if _LIBCPP_DEBUG_LEVEL >= 2
return local_iterator(nullptr, __n, bucket_count(), this);
#else
return local_iterator(nullptr, __n, bucket_count());
#endif
}
_LIBCPP_INLINE_VISIBILITY
const_local_iterator
cbegin(size_type __n) const
{
_LIBCPP_ASSERT(__n < bucket_count(),
"unordered container::cbegin(n) called with n >= bucket_count()");
#if _LIBCPP_DEBUG_LEVEL >= 2
return const_local_iterator(__bucket_list_[__n], __n, bucket_count(), this);
#else
return const_local_iterator(__bucket_list_[__n], __n, bucket_count());
#endif
}
_LIBCPP_INLINE_VISIBILITY
const_local_iterator
cend(size_type __n) const
{
_LIBCPP_ASSERT(__n < bucket_count(),
"unordered container::cend(n) called with n >= bucket_count()");
#if _LIBCPP_DEBUG_LEVEL >= 2
return const_local_iterator(nullptr, __n, bucket_count(), this);
#else
return const_local_iterator(nullptr, __n, bucket_count());
#endif
}
#if _LIBCPP_DEBUG_LEVEL >= 2
bool __dereferenceable(const const_iterator* __i) const;
bool __decrementable(const const_iterator* __i) const;
bool __addable(const const_iterator* __i, ptrdiff_t __n) const;
bool __subscriptable(const const_iterator* __i, ptrdiff_t __n) const;
#endif // _LIBCPP_DEBUG_LEVEL >= 2
private:
void __rehash(size_type __n);
#ifndef _LIBCPP_CXX03_LANG
template <class ..._Args>
__node_holder __construct_node(_Args&& ...__args);
template <class _First, class ..._Rest>
__node_holder __construct_node_hash(size_t __hash, _First&& __f, _Rest&&... __rest);
#else // _LIBCPP_CXX03_LANG
__node_holder __construct_node(const __container_value_type& __v);
__node_holder __construct_node_hash(size_t __hash, const __container_value_type& __v);
#endif
_LIBCPP_INLINE_VISIBILITY
void __copy_assign_alloc(const __hash_table& __u)
{__copy_assign_alloc(__u, integral_constant<bool,
__node_traits::propagate_on_container_copy_assignment::value>());}
void __copy_assign_alloc(const __hash_table& __u, true_type);
_LIBCPP_INLINE_VISIBILITY
void __copy_assign_alloc(const __hash_table&, false_type) {}
#ifndef _LIBCPP_CXX03_LANG
void __move_assign(__hash_table& __u, false_type);
void __move_assign(__hash_table& __u, true_type)
_NOEXCEPT_(
is_nothrow_move_assignable<__node_allocator>::value &&
is_nothrow_move_assignable<hasher>::value &&
is_nothrow_move_assignable<key_equal>::value);
_LIBCPP_INLINE_VISIBILITY
void __move_assign_alloc(__hash_table& __u)
_NOEXCEPT_(
!__node_traits::propagate_on_container_move_assignment::value ||
(is_nothrow_move_assignable<__pointer_allocator>::value &&
is_nothrow_move_assignable<__node_allocator>::value))
{__move_assign_alloc(__u, integral_constant<bool,
__node_traits::propagate_on_container_move_assignment::value>());}
_LIBCPP_INLINE_VISIBILITY
void __move_assign_alloc(__hash_table& __u, true_type)
_NOEXCEPT_(
is_nothrow_move_assignable<__pointer_allocator>::value &&
is_nothrow_move_assignable<__node_allocator>::value)
{
__bucket_list_.get_deleter().__alloc() =
_VSTD::move(__u.__bucket_list_.get_deleter().__alloc());
__node_alloc() = _VSTD::move(__u.__node_alloc());
}
_LIBCPP_INLINE_VISIBILITY
void __move_assign_alloc(__hash_table&, false_type) _NOEXCEPT {}
#endif // _LIBCPP_CXX03_LANG
void __deallocate_node(__next_pointer __np) _NOEXCEPT;
__next_pointer __detach() _NOEXCEPT;
template <class, class, class, class, class> friend class _LIBCPP_TEMPLATE_VIS unordered_map;
template <class, class, class, class, class> friend class _LIBCPP_TEMPLATE_VIS unordered_multimap;
};
template <class _Tp, class _Hash, class _Equal, class _Alloc>
inline
__hash_table<_Tp, _Hash, _Equal, _Alloc>::__hash_table()
_NOEXCEPT_(
is_nothrow_default_constructible<__bucket_list>::value &&
is_nothrow_default_constructible<__first_node>::value &&
is_nothrow_default_constructible<__node_allocator>::value &&
is_nothrow_default_constructible<hasher>::value &&
is_nothrow_default_constructible<key_equal>::value)
: __p2_(0),
__p3_(1.0f)
{
}
template <class _Tp, class _Hash, class _Equal, class _Alloc>
inline
__hash_table<_Tp, _Hash, _Equal, _Alloc>::__hash_table(const hasher& __hf,
const key_equal& __eql)
: __bucket_list_(nullptr, __bucket_list_deleter()),
__p1_(),
__p2_(0, __hf),
__p3_(1.0f, __eql)
{
}
template <class _Tp, class _Hash, class _Equal, class _Alloc>
__hash_table<_Tp, _Hash, _Equal, _Alloc>::__hash_table(const hasher& __hf,
const key_equal& __eql,
const allocator_type& __a)
: __bucket_list_(nullptr, __bucket_list_deleter(__pointer_allocator(__a), 0)),
__p1_(__second_tag(), __node_allocator(__a)),
__p2_(0, __hf),
__p3_(1.0f, __eql)
{
}
template <class _Tp, class _Hash, class _Equal, class _Alloc>
__hash_table<_Tp, _Hash, _Equal, _Alloc>::__hash_table(const allocator_type& __a)
: __bucket_list_(nullptr, __bucket_list_deleter(__pointer_allocator(__a), 0)),
__p1_(__second_tag(), __node_allocator(__a)),
__p2_(0),
__p3_(1.0f)
{
}
template <class _Tp, class _Hash, class _Equal, class _Alloc>
__hash_table<_Tp, _Hash, _Equal, _Alloc>::__hash_table(const __hash_table& __u)
: __bucket_list_(nullptr,
__bucket_list_deleter(allocator_traits<__pointer_allocator>::
select_on_container_copy_construction(
__u.__bucket_list_.get_deleter().__alloc()), 0)),
__p1_(__second_tag(), allocator_traits<__node_allocator>::
select_on_container_copy_construction(__u.__node_alloc())),
__p2_(0, __u.hash_function()),
__p3_(__u.__p3_)
{
}
template <class _Tp, class _Hash, class _Equal, class _Alloc>
__hash_table<_Tp, _Hash, _Equal, _Alloc>::__hash_table(const __hash_table& __u,
const allocator_type& __a)
: __bucket_list_(nullptr, __bucket_list_deleter(__pointer_allocator(__a), 0)),
__p1_(__second_tag(), __node_allocator(__a)),
__p2_(0, __u.hash_function()),
__p3_(__u.__p3_)
{
}
#ifndef _LIBCPP_CXX03_LANG
template <class _Tp, class _Hash, class _Equal, class _Alloc>
__hash_table<_Tp, _Hash, _Equal, _Alloc>::__hash_table(__hash_table&& __u)
_NOEXCEPT_(
is_nothrow_move_constructible<__bucket_list>::value &&
is_nothrow_move_constructible<__first_node>::value &&
is_nothrow_move_constructible<__node_allocator>::value &&
is_nothrow_move_constructible<hasher>::value &&
is_nothrow_move_constructible<key_equal>::value)
: __bucket_list_(_VSTD::move(__u.__bucket_list_)),
__p1_(_VSTD::move(__u.__p1_)),
__p2_(_VSTD::move(__u.__p2_)),
__p3_(_VSTD::move(__u.__p3_))
{
if (size() > 0)
{
__bucket_list_[__constrain_hash(__p1_.first().__next_->__hash(), bucket_count())] =
__p1_.first().__ptr();
__u.__p1_.first().__next_ = nullptr;
__u.size() = 0;
}
}
template <class _Tp, class _Hash, class _Equal, class _Alloc>
__hash_table<_Tp, _Hash, _Equal, _Alloc>::__hash_table(__hash_table&& __u,
const allocator_type& __a)
: __bucket_list_(nullptr, __bucket_list_deleter(__pointer_allocator(__a), 0)),
__p1_(__second_tag(), __node_allocator(__a)),
__p2_(0, _VSTD::move(__u.hash_function())),
__p3_(_VSTD::move(__u.__p3_))
{
if (__a == allocator_type(__u.__node_alloc()))
{
__bucket_list_.reset(__u.__bucket_list_.release());
__bucket_list_.get_deleter().size() = __u.__bucket_list_.get_deleter().size();
__u.__bucket_list_.get_deleter().size() = 0;
if (__u.size() > 0)
{
__p1_.first().__next_ = __u.__p1_.first().__next_;
__u.__p1_.first().__next_ = nullptr;
__bucket_list_[__constrain_hash(__p1_.first().__next_->__hash(), bucket_count())] =
__p1_.first().__ptr();
size() = __u.size();
__u.size() = 0;
}
}
}
#endif // _LIBCPP_CXX03_LANG
template <class _Tp, class _Hash, class _Equal, class _Alloc>
__hash_table<_Tp, _Hash, _Equal, _Alloc>::~__hash_table()
{
#if defined(_LIBCPP_CXX03_LANG)
static_assert((is_copy_constructible<key_equal>::value),
"Predicate must be copy-constructible.");
static_assert((is_copy_constructible<hasher>::value),
"Hasher must be copy-constructible.");
#endif
__deallocate_node(__p1_.first().__next_);
#if _LIBCPP_DEBUG_LEVEL >= 2
__get_db()->__erase_c(this);
#endif
}
template <class _Tp, class _Hash, class _Equal, class _Alloc>
void
__hash_table<_Tp, _Hash, _Equal, _Alloc>::__copy_assign_alloc(
const __hash_table& __u, true_type)
{
if (__node_alloc() != __u.__node_alloc())
{
clear();
__bucket_list_.reset();
__bucket_list_.get_deleter().size() = 0;
}
__bucket_list_.get_deleter().__alloc() = __u.__bucket_list_.get_deleter().__alloc();
__node_alloc() = __u.__node_alloc();
}
template <class _Tp, class _Hash, class _Equal, class _Alloc>
__hash_table<_Tp, _Hash, _Equal, _Alloc>&
__hash_table<_Tp, _Hash, _Equal, _Alloc>::operator=(const __hash_table& __u)
{
if (this != &__u)
{
__copy_assign_alloc(__u);
hash_function() = __u.hash_function();
key_eq() = __u.key_eq();
max_load_factor() = __u.max_load_factor();
__assign_multi(__u.begin(), __u.end());
}
return *this;
}
template <class _Tp, class _Hash, class _Equal, class _Alloc>
void
__hash_table<_Tp, _Hash, _Equal, _Alloc>::__deallocate_node(__next_pointer __np)
_NOEXCEPT
{
__node_allocator& __na = __node_alloc();
while (__np != nullptr)
{
__next_pointer __next = __np->__next_;
#if _LIBCPP_DEBUG_LEVEL >= 2
__c_node* __c = __get_db()->__find_c_and_lock(this);
for (__i_node** __p = __c->end_; __p != __c->beg_; )
{
--__p;
iterator* __i = static_cast<iterator*>((*__p)->__i_);
if (__i->__node_ == __np)
{
(*__p)->__c_ = nullptr;
if (--__c->end_ != __p)
memmove(__p, __p+1, (__c->end_ - __p)*sizeof(__i_node*));
}
}
__get_db()->unlock();
#endif
__node_pointer __real_np = __np->__upcast();
__node_traits::destroy(__na, _NodeTypes::__get_ptr(__real_np->__value_));
__node_traits::deallocate(__na, __real_np, 1);
__np = __next;
}
}
template <class _Tp, class _Hash, class _Equal, class _Alloc>
typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::__next_pointer
__hash_table<_Tp, _Hash, _Equal, _Alloc>::__detach() _NOEXCEPT
{
size_type __bc = bucket_count();
for (size_type __i = 0; __i < __bc; ++__i)
__bucket_list_[__i] = nullptr;
size() = 0;
__next_pointer __cache = __p1_.first().__next_;
__p1_.first().__next_ = nullptr;
return __cache;
}
#ifndef _LIBCPP_CXX03_LANG
template <class _Tp, class _Hash, class _Equal, class _Alloc>
void
__hash_table<_Tp, _Hash, _Equal, _Alloc>::__move_assign(
__hash_table& __u, true_type)
_NOEXCEPT_(
is_nothrow_move_assignable<__node_allocator>::value &&
is_nothrow_move_assignable<hasher>::value &&
is_nothrow_move_assignable<key_equal>::value)
{
clear();
__bucket_list_.reset(__u.__bucket_list_.release());
__bucket_list_.get_deleter().size() = __u.__bucket_list_.get_deleter().size();
__u.__bucket_list_.get_deleter().size() = 0;
__move_assign_alloc(__u);
size() = __u.size();
hash_function() = _VSTD::move(__u.hash_function());
max_load_factor() = __u.max_load_factor();
key_eq() = _VSTD::move(__u.key_eq());
__p1_.first().__next_ = __u.__p1_.first().__next_;
if (size() > 0)
{
__bucket_list_[__constrain_hash(__p1_.first().__next_->__hash(), bucket_count())] =
__p1_.first().__ptr();
__u.__p1_.first().__next_ = nullptr;
__u.size() = 0;
}
#if _LIBCPP_DEBUG_LEVEL >= 2
__get_db()->swap(this, &__u);
#endif
}
template <class _Tp, class _Hash, class _Equal, class _Alloc>
void
__hash_table<_Tp, _Hash, _Equal, _Alloc>::__move_assign(
__hash_table& __u, false_type)
{
if (__node_alloc() == __u.__node_alloc())
__move_assign(__u, true_type());
else
{
hash_function() = _VSTD::move(__u.hash_function());
key_eq() = _VSTD::move(__u.key_eq());
max_load_factor() = __u.max_load_factor();
if (bucket_count() != 0)
{
__next_pointer __cache = __detach();
#ifndef _LIBCPP_NO_EXCEPTIONS
try
{
#endif // _LIBCPP_NO_EXCEPTIONS
const_iterator __i = __u.begin();
while (__cache != nullptr && __u.size() != 0)
{
__cache->__upcast()->__value_ =
_VSTD::move(__u.remove(__i++)->__value_);
__next_pointer __next = __cache->__next_;
__node_insert_multi(__cache->__upcast());
__cache = __next;
}
#ifndef _LIBCPP_NO_EXCEPTIONS
}
catch (...)
{
__deallocate_node(__cache);
throw;
}
#endif // _LIBCPP_NO_EXCEPTIONS
__deallocate_node(__cache);
}
const_iterator __i = __u.begin();
while (__u.size() != 0)
{
__node_holder __h = __construct_node(_NodeTypes::__move(__u.remove(__i++)->__value_));
__node_insert_multi(__h.get());
__h.release();
}
}
}
template <class _Tp, class _Hash, class _Equal, class _Alloc>
inline
__hash_table<_Tp, _Hash, _Equal, _Alloc>&
__hash_table<_Tp, _Hash, _Equal, _Alloc>::operator=(__hash_table&& __u)
_NOEXCEPT_(
__node_traits::propagate_on_container_move_assignment::value &&
is_nothrow_move_assignable<__node_allocator>::value &&
is_nothrow_move_assignable<hasher>::value &&
is_nothrow_move_assignable<key_equal>::value)
{
__move_assign(__u, integral_constant<bool,
__node_traits::propagate_on_container_move_assignment::value>());
return *this;
}
#endif // _LIBCPP_CXX03_LANG
template <class _Tp, class _Hash, class _Equal, class _Alloc>
template <class _InputIterator>
void
__hash_table<_Tp, _Hash, _Equal, _Alloc>::__assign_unique(_InputIterator __first,
_InputIterator __last)
{
typedef iterator_traits<_InputIterator> _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");
if (bucket_count() != 0)
{
__next_pointer __cache = __detach();
#ifndef _LIBCPP_NO_EXCEPTIONS
try
{
#endif // _LIBCPP_NO_EXCEPTIONS
for (; __cache != nullptr && __first != __last; ++__first)
{
__cache->__upcast()->__value_ = *__first;
__next_pointer __next = __cache->__next_;
__node_insert_unique(__cache->__upcast());
__cache = __next;
}
#ifndef _LIBCPP_NO_EXCEPTIONS
}
catch (...)
{
__deallocate_node(__cache);
throw;
}
#endif // _LIBCPP_NO_EXCEPTIONS
__deallocate_node(__cache);
}
for (; __first != __last; ++__first)
__insert_unique(*__first);
}
template <class _Tp, class _Hash, class _Equal, class _Alloc>
template <class _InputIterator>
void
__hash_table<_Tp, _Hash, _Equal, _Alloc>::__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 (bucket_count() != 0)
{
__next_pointer __cache = __detach();
#ifndef _LIBCPP_NO_EXCEPTIONS
try
{
#endif // _LIBCPP_NO_EXCEPTIONS
for (; __cache != nullptr && __first != __last; ++__first)
{
__cache->__upcast()->__value_ = *__first;
__next_pointer __next = __cache->__next_;
__node_insert_multi(__cache->__upcast());
__cache = __next;
}
#ifndef _LIBCPP_NO_EXCEPTIONS
}
catch (...)
{
__deallocate_node(__cache);
throw;
}
#endif // _LIBCPP_NO_EXCEPTIONS
__deallocate_node(__cache);
}
for (; __first != __last; ++__first)
__insert_multi(_NodeTypes::__get_value(*__first));
}
template <class _Tp, class _Hash, class _Equal, class _Alloc>
inline
typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator
__hash_table<_Tp, _Hash, _Equal, _Alloc>::begin() _NOEXCEPT
{
#if _LIBCPP_DEBUG_LEVEL >= 2
return iterator(__p1_.first().__next_, this);
#else
return iterator(__p1_.first().__next_);
#endif
}
template <class _Tp, class _Hash, class _Equal, class _Alloc>
inline
typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator
__hash_table<_Tp, _Hash, _Equal, _Alloc>::end() _NOEXCEPT
{
#if _LIBCPP_DEBUG_LEVEL >= 2
return iterator(nullptr, this);
#else
return iterator(nullptr);
#endif
}
template <class _Tp, class _Hash, class _Equal, class _Alloc>
inline
typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::const_iterator
__hash_table<_Tp, _Hash, _Equal, _Alloc>::begin() const _NOEXCEPT
{
#if _LIBCPP_DEBUG_LEVEL >= 2
return const_iterator(__p1_.first().__next_, this);
#else
return const_iterator(__p1_.first().__next_);
#endif
}
template <class _Tp, class _Hash, class _Equal, class _Alloc>
inline
typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::const_iterator
__hash_table<_Tp, _Hash, _Equal, _Alloc>::end() const _NOEXCEPT
{
#if _LIBCPP_DEBUG_LEVEL >= 2
return const_iterator(nullptr, this);
#else
return const_iterator(nullptr);
#endif
}
template <class _Tp, class _Hash, class _Equal, class _Alloc>
void
__hash_table<_Tp, _Hash, _Equal, _Alloc>::clear() _NOEXCEPT
{
if (size() > 0)
{
__deallocate_node(__p1_.first().__next_);
__p1_.first().__next_ = nullptr;
size_type __bc = bucket_count();
for (size_type __i = 0; __i < __bc; ++__i)
__bucket_list_[__i] = nullptr;
size() = 0;
}
}
// Prepare the container for an insertion of the value __value with the hash
// __hash. This does a lookup into the container to see if __value is already
// present, and performs a rehash if necessary. Returns a pointer to the
// existing element if it exists, otherwise nullptr.
//
// Note that this function does forward exceptions if key_eq() throws, and never
// mutates __value or actually inserts into the map.
template <class _Tp, class _Hash, class _Equal, class _Alloc>
_LIBCPP_INLINE_VISIBILITY
typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::__next_pointer
__hash_table<_Tp, _Hash, _Equal, _Alloc>::__node_insert_unique_prepare(
size_t __hash, value_type& __value)
{
size_type __bc = bucket_count();
if (__bc != 0)
{
size_t __chash = __constrain_hash(__hash, __bc);
__next_pointer __ndptr = __bucket_list_[__chash];
if (__ndptr != nullptr)
{
for (__ndptr = __ndptr->__next_; __ndptr != nullptr &&
__constrain_hash(__ndptr->__hash(), __bc) == __chash;
__ndptr = __ndptr->__next_)
{
if (key_eq()(__ndptr->__upcast()->__value_, __value))
return __ndptr;
}
}
}
if (size()+1 > __bc * max_load_factor() || __bc == 0)
{
rehash(_VSTD::max<size_type>(2 * __bc + !__is_hash_power2(__bc),
size_type(ceil(float(size() + 1) / max_load_factor()))));
}
return nullptr;
}
// Insert the node __nd into the container by pushing it into the right bucket,
// and updating size(). Assumes that __nd->__hash is up-to-date, and that
// rehashing has already occurred and that no element with the same key exists
// in the map.
template <class _Tp, class _Hash, class _Equal, class _Alloc>
_LIBCPP_INLINE_VISIBILITY
void
__hash_table<_Tp, _Hash, _Equal, _Alloc>::__node_insert_unique_perform(
__node_pointer __nd) _NOEXCEPT
{
size_type __bc = bucket_count();
size_t __chash = __constrain_hash(__nd->__hash(), __bc);
// insert_after __bucket_list_[__chash], or __first_node if bucket is null
__next_pointer __pn = __bucket_list_[__chash];
if (__pn == nullptr)
{
__pn =__p1_.first().__ptr();
__nd->__next_ = __pn->__next_;
__pn->__next_ = __nd->__ptr();
// fix up __bucket_list_
__bucket_list_[__chash] = __pn;
if (__nd->__next_ != nullptr)
__bucket_list_[__constrain_hash(__nd->__next_->__hash(), __bc)] = __nd->__ptr();
}
else
{
__nd->__next_ = __pn->__next_;
__pn->__next_ = __nd->__ptr();
}
++size();
}
template <class _Tp, class _Hash, class _Equal, class _Alloc>
pair<typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator, bool>
__hash_table<_Tp, _Hash, _Equal, _Alloc>::__node_insert_unique(__node_pointer __nd)
{
__nd->__hash_ = hash_function()(__nd->__value_);
__next_pointer __existing_node =
__node_insert_unique_prepare(__nd->__hash(), __nd->__value_);
// Insert the node, unless it already exists in the container.
bool __inserted = false;
if (__existing_node == nullptr)
{
__node_insert_unique_perform(__nd);
__existing_node = __nd->__ptr();
__inserted = true;
}
#if _LIBCPP_DEBUG_LEVEL >= 2
return pair<iterator, bool>(iterator(__existing_node, this), __inserted);
#else
return pair<iterator, bool>(iterator(__existing_node), __inserted);
#endif
}
// Prepare the container for an insertion of the value __cp_val with the hash
// __cp_hash. This does a lookup into the container to see if __cp_value is
// already present, and performs a rehash if necessary. Returns a pointer to the
// last occurance of __cp_val in the map.
//
// Note that this function does forward exceptions if key_eq() throws, and never
// mutates __value or actually inserts into the map.
template <class _Tp, class _Hash, class _Equal, class _Alloc>
typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::__next_pointer
__hash_table<_Tp, _Hash, _Equal, _Alloc>::__node_insert_multi_prepare(
size_t __cp_hash, value_type& __cp_val)
{
size_type __bc = bucket_count();
if (size()+1 > __bc * max_load_factor() || __bc == 0)
{
rehash(_VSTD::max<size_type>(2 * __bc + !__is_hash_power2(__bc),
size_type(ceil(float(size() + 1) / max_load_factor()))));
__bc = bucket_count();
}
size_t __chash = __constrain_hash(__cp_hash, __bc);
__next_pointer __pn = __bucket_list_[__chash];
if (__pn != nullptr)
{
for (bool __found = false; __pn->__next_ != nullptr &&
__constrain_hash(__pn->__next_->__hash(), __bc) == __chash;
__pn = __pn->__next_)
{
// __found key_eq() action
// false false loop
// true true loop
// false true set __found to true
// true false break
if (__found != (__pn->__next_->__hash() == __cp_hash &&
key_eq()(__pn->__next_->__upcast()->__value_, __cp_val)))
{
if (!__found)
__found = true;
else
break;
}
}
}
return __pn;
}
// Insert the node __cp into the container after __pn (which is the last node in
// the bucket that compares equal to __cp). Rehashing, and checking for
// uniqueness has already been performed (in __node_insert_multi_prepare), so
// all we need to do is update the bucket and size(). Assumes that __cp->__hash
// is up-to-date.
template <class _Tp, class _Hash, class _Equal, class _Alloc>
void
__hash_table<_Tp, _Hash, _Equal, _Alloc>::__node_insert_multi_perform(
__node_pointer __cp, __next_pointer __pn) _NOEXCEPT
{
size_type __bc = bucket_count();
size_t __chash = __constrain_hash(__cp->__hash_, __bc);
if (__pn == nullptr)
{
__pn =__p1_.first().__ptr();
__cp->__next_ = __pn->__next_;
__pn->__next_ = __cp->__ptr();
// fix up __bucket_list_
__bucket_list_[__chash] = __pn;
if (__cp->__next_ != nullptr)
__bucket_list_[__constrain_hash(__cp->__next_->__hash(), __bc)]
= __cp->__ptr();
}
else
{
__cp->__next_ = __pn->__next_;
__pn->__next_ = __cp->__ptr();
if (__cp->__next_ != nullptr)
{
size_t __nhash = __constrain_hash(__cp->__next_->__hash(), __bc);
if (__nhash != __chash)
__bucket_list_[__nhash] = __cp->__ptr();
}
}
++size();
}
template <class _Tp, class _Hash, class _Equal, class _Alloc>
typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator
__hash_table<_Tp, _Hash, _Equal, _Alloc>::__node_insert_multi(__node_pointer __cp)
{
__cp->__hash_ = hash_function()(__cp->__value_);
__next_pointer __pn = __node_insert_multi_prepare(__cp->__hash(), __cp->__value_);
__node_insert_multi_perform(__cp, __pn);
#if _LIBCPP_DEBUG_LEVEL >= 2
return iterator(__cp->__ptr(), this);
#else
return iterator(__cp->__ptr());
#endif
}
template <class _Tp, class _Hash, class _Equal, class _Alloc>
typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator
__hash_table<_Tp, _Hash, _Equal, _Alloc>::__node_insert_multi(
const_iterator __p, __node_pointer __cp)
{
#if _LIBCPP_DEBUG_LEVEL >= 2
_LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this,
"unordered container::emplace_hint(const_iterator, args...) called with an iterator not"
" referring to this unordered container");
#endif
if (__p != end() && key_eq()(*__p, __cp->__value_))
{
__next_pointer __np = __p.__node_;
__cp->__hash_ = __np->__hash();
size_type __bc = bucket_count();
if (size()+1 > __bc * max_load_factor() || __bc == 0)
{
rehash(_VSTD::max<size_type>(2 * __bc + !__is_hash_power2(__bc),
size_type(ceil(float(size() + 1) / max_load_factor()))));
__bc = bucket_count();
}
size_t __chash = __constrain_hash(__cp->__hash_, __bc);
__next_pointer __pp = __bucket_list_[__chash];
while (__pp->__next_ != __np)
__pp = __pp->__next_;
__cp->__next_ = __np;
__pp->__next_ = static_cast<__next_pointer>(__cp);
++size();
#if _LIBCPP_DEBUG_LEVEL >= 2
return iterator(static_cast<__next_pointer>(__cp), this);
#else
return iterator(static_cast<__next_pointer>(__cp));
#endif
}
return __node_insert_multi(__cp);
}
#ifndef _LIBCPP_CXX03_LANG
template <class _Tp, class _Hash, class _Equal, class _Alloc>
template <class _Key, class ..._Args>
pair<typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator, bool>
__hash_table<_Tp, _Hash, _Equal, _Alloc>::__emplace_unique_key_args(_Key const& __k, _Args&&... __args)
#else
template <class _Tp, class _Hash, class _Equal, class _Alloc>
template <class _Key, class _Args>
pair<typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator, bool>
__hash_table<_Tp, _Hash, _Equal, _Alloc>::__emplace_unique_key_args(_Key const& __k, _Args& __args)
#endif
{
size_t __hash = hash_function()(__k);
size_type __bc = bucket_count();
bool __inserted = false;
__next_pointer __nd;
size_t __chash = 0;
if (__bc != 0)
{
__chash = __constrain_hash(__hash, __bc);
__nd = __bucket_list_[__chash];
if (__nd != nullptr)
{
for (__nd = __nd->__next_; __nd != nullptr &&
(__nd->__hash() == __hash || __constrain_hash(__nd->__hash(), __bc) == __chash);
__nd = __nd->__next_)
{
if (key_eq()(__nd->__upcast()->__value_, __k))
goto __done;
}
}
}
{
#ifndef _LIBCPP_CXX03_LANG
__node_holder __h = __construct_node_hash(__hash, _VSTD::forward<_Args>(__args)...);
#else
__node_holder __h = __construct_node_hash(__hash, __args);
#endif
if (size()+1 > __bc * max_load_factor() || __bc == 0)
{
rehash(_VSTD::max<size_type>(2 * __bc + !__is_hash_power2(__bc),
size_type(ceil(float(size() + 1) / max_load_factor()))));
__bc = bucket_count();
__chash = __constrain_hash(__hash, __bc);
}
// insert_after __bucket_list_[__chash], or __first_node if bucket is null
__next_pointer __pn = __bucket_list_[__chash];
if (__pn == nullptr)
{
__pn = __p1_.first().__ptr();
__h->__next_ = __pn->__next_;
__pn->__next_ = __h.get()->__ptr();
// fix up __bucket_list_
__bucket_list_[__chash] = __pn;
if (__h->__next_ != nullptr)
__bucket_list_[__constrain_hash(__h->__next_->__hash(), __bc)]
= __h.get()->__ptr();
}
else
{
__h->__next_ = __pn->__next_;
__pn->__next_ = static_cast<__next_pointer>(__h.get());
}
__nd = static_cast<__next_pointer>(__h.release());
// increment size
++size();
__inserted = true;
}
__done:
#if _LIBCPP_DEBUG_LEVEL >= 2
return pair<iterator, bool>(iterator(__nd, this), __inserted);
#else
return pair<iterator, bool>(iterator(__nd), __inserted);
#endif
}
#ifndef _LIBCPP_CXX03_LANG
template <class _Tp, class _Hash, class _Equal, class _Alloc>
template <class... _Args>
pair<typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator, bool>
__hash_table<_Tp, _Hash, _Equal, _Alloc>::__emplace_unique_impl(_Args&&... __args)
{
__node_holder __h = __construct_node(_VSTD::forward<_Args>(__args)...);
pair<iterator, bool> __r = __node_insert_unique(__h.get());
if (__r.second)
__h.release();
return __r;
}
template <class _Tp, class _Hash, class _Equal, class _Alloc>
template <class... _Args>
typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator
__hash_table<_Tp, _Hash, _Equal, _Alloc>::__emplace_multi(_Args&&... __args)
{
__node_holder __h = __construct_node(_VSTD::forward<_Args>(__args)...);
iterator __r = __node_insert_multi(__h.get());
__h.release();
return __r;
}
template <class _Tp, class _Hash, class _Equal, class _Alloc>
template <class... _Args>
typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator
__hash_table<_Tp, _Hash, _Equal, _Alloc>::__emplace_hint_multi(
const_iterator __p, _Args&&... __args)
{
#if _LIBCPP_DEBUG_LEVEL >= 2
_LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this,
"unordered container::emplace_hint(const_iterator, args...) called with an iterator not"
" referring to this unordered container");
#endif
__node_holder __h = __construct_node(_VSTD::forward<_Args>(__args)...);
iterator __r = __node_insert_multi(__p, __h.get());
__h.release();
return __r;
}
#else // _LIBCPP_CXX03_LANG
template <class _Tp, class _Hash, class _Equal, class _Alloc>
typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator
__hash_table<_Tp, _Hash, _Equal, _Alloc>::__insert_multi(const __container_value_type& __x)
{
__node_holder __h = __construct_node(__x);
iterator __r = __node_insert_multi(__h.get());
__h.release();
return __r;
}
template <class _Tp, class _Hash, class _Equal, class _Alloc>
typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator
__hash_table<_Tp, _Hash, _Equal, _Alloc>::__insert_multi(const_iterator __p,
const __container_value_type& __x)
{
#if _LIBCPP_DEBUG_LEVEL >= 2
_LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this,
"unordered container::insert(const_iterator, lvalue) called with an iterator not"
" referring to this unordered container");
#endif
__node_holder __h = __construct_node(__x);
iterator __r = __node_insert_multi(__p, __h.get());
__h.release();
return __r;
}
#endif // _LIBCPP_CXX03_LANG
#if _LIBCPP_STD_VER > 14
template <class _Tp, class _Hash, class _Equal, class _Alloc>
template <class _NodeHandle, class _InsertReturnType>
_LIBCPP_INLINE_VISIBILITY
_InsertReturnType
__hash_table<_Tp, _Hash, _Equal, _Alloc>::__node_handle_insert_unique(
_NodeHandle&& __nh)
{
if (__nh.empty())
return _InsertReturnType{end(), false, _NodeHandle()};
pair<iterator, bool> __result = __node_insert_unique(__nh.__ptr_);
if (__result.second)
__nh.__release_ptr();
return _InsertReturnType{__result.first, __result.second, _VSTD::move(__nh)};
}
template <class _Tp, class _Hash, class _Equal, class _Alloc>
template <class _NodeHandle>
_LIBCPP_INLINE_VISIBILITY
typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator
__hash_table<_Tp, _Hash, _Equal, _Alloc>::__node_handle_insert_unique(
const_iterator, _NodeHandle&& __nh)
{
if (__nh.empty())
return end();
pair<iterator, bool> __result = __node_insert_unique(__nh.__ptr_);
if (__result.second)
__nh.__release_ptr();
return __result.first;
}
template <class _Tp, class _Hash, class _Equal, class _Alloc>
template <class _NodeHandle>
_LIBCPP_INLINE_VISIBILITY
_NodeHandle
__hash_table<_Tp, _Hash, _Equal, _Alloc>::__node_handle_extract(
key_type const& __key)
{
iterator __i = find(__key);
if (__i == end())
return _NodeHandle();
return __node_handle_extract<_NodeHandle>(__i);
}
template <class _Tp, class _Hash, class _Equal, class _Alloc>
template <class _NodeHandle>
_LIBCPP_INLINE_VISIBILITY
_NodeHandle
__hash_table<_Tp, _Hash, _Equal, _Alloc>::__node_handle_extract(
const_iterator __p)
{
allocator_type __alloc(__node_alloc());
return _NodeHandle(remove(__p).release(), __alloc);
}
template <class _Tp, class _Hash, class _Equal, class _Alloc>
template <class _Table>
_LIBCPP_INLINE_VISIBILITY
void
__hash_table<_Tp, _Hash, _Equal, _Alloc>::__node_handle_merge_unique(
_Table& __source)
{
static_assert(is_same<__node, typename _Table::__node>::value, "");
for (typename _Table::iterator __it = __source.begin();
__it != __source.end();)
{
__node_pointer __src_ptr = __it.__node_->__upcast();
size_t __hash = hash_function()(__src_ptr->__value_);
__next_pointer __existing_node =
__node_insert_unique_prepare(__hash, __src_ptr->__value_);
auto __prev_iter = __it++;
if (__existing_node == nullptr)
{
(void)__source.remove(__prev_iter).release();
__src_ptr->__hash_ = __hash;
__node_insert_unique_perform(__src_ptr);
}
}
}
template <class _Tp, class _Hash, class _Equal, class _Alloc>
template <class _NodeHandle>
_LIBCPP_INLINE_VISIBILITY
typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator
__hash_table<_Tp, _Hash, _Equal, _Alloc>::__node_handle_insert_multi(
_NodeHandle&& __nh)
{
if (__nh.empty())
return end();
iterator __result = __node_insert_multi(__nh.__ptr_);
__nh.__release_ptr();
return __result;
}
template <class _Tp, class _Hash, class _Equal, class _Alloc>
template <class _NodeHandle>
_LIBCPP_INLINE_VISIBILITY
typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator
__hash_table<_Tp, _Hash, _Equal, _Alloc>::__node_handle_insert_multi(
const_iterator __hint, _NodeHandle&& __nh)
{
if (__nh.empty())
return end();
iterator __result = __node_insert_multi(__hint, __nh.__ptr_);
__nh.__release_ptr();
return __result;
}
template <class _Tp, class _Hash, class _Equal, class _Alloc>
template <class _Table>
_LIBCPP_INLINE_VISIBILITY
void
__hash_table<_Tp, _Hash, _Equal, _Alloc>::__node_handle_merge_multi(
_Table& __source)
{
static_assert(is_same<typename _Table::__node, __node>::value, "");
for (typename _Table::iterator __it = __source.begin();
__it != __source.end();)
{
__node_pointer __src_ptr = __it.__node_->__upcast();
size_t __src_hash = hash_function()(__src_ptr->__value_);
__next_pointer __pn =
__node_insert_multi_prepare(__src_hash, __src_ptr->__value_);
(void)__source.remove(__it++).release();
__src_ptr->__hash_ = __src_hash;
__node_insert_multi_perform(__src_ptr, __pn);
}
}
#endif // _LIBCPP_STD_VER > 14
template <class _Tp, class _Hash, class _Equal, class _Alloc>
void
__hash_table<_Tp, _Hash, _Equal, _Alloc>::rehash(size_type __n)
_LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK
{
if (__n == 1)
__n = 2;
else if (__n & (__n - 1))
__n = __next_prime(__n);
size_type __bc = bucket_count();
if (__n > __bc)
__rehash(__n);
else if (__n < __bc)
{
__n = _VSTD::max<size_type>
(
__n,
__is_hash_power2(__bc) ? __next_hash_pow2(size_t(ceil(float(size()) / max_load_factor()))) :
__next_prime(size_t(ceil(float(size()) / max_load_factor())))
);
if (__n < __bc)
__rehash(__n);
}
}
template <class _Tp, class _Hash, class _Equal, class _Alloc>
void
__hash_table<_Tp, _Hash, _Equal, _Alloc>::__rehash(size_type __nbc)
{
#if _LIBCPP_DEBUG_LEVEL >= 2
__get_db()->__invalidate_all(this);
#endif // _LIBCPP_DEBUG_LEVEL >= 2
__pointer_allocator& __npa = __bucket_list_.get_deleter().__alloc();
__bucket_list_.reset(__nbc > 0 ?
__pointer_alloc_traits::allocate(__npa, __nbc) : nullptr);
__bucket_list_.get_deleter().size() = __nbc;
if (__nbc > 0)
{
for (size_type __i = 0; __i < __nbc; ++__i)
__bucket_list_[__i] = nullptr;
__next_pointer __pp = __p1_.first().__ptr();
__next_pointer __cp = __pp->__next_;
if (__cp != nullptr)
{
size_type __chash = __constrain_hash(__cp->__hash(), __nbc);
__bucket_list_[__chash] = __pp;
size_type __phash = __chash;
for (__pp = __cp, __cp = __cp->__next_; __cp != nullptr;
__cp = __pp->__next_)
{
__chash = __constrain_hash(__cp->__hash(), __nbc);
if (__chash == __phash)
__pp = __cp;
else
{
if (__bucket_list_[__chash] == nullptr)
{
__bucket_list_[__chash] = __pp;
__pp = __cp;
__phash = __chash;
}
else
{
__next_pointer __np = __cp;
for (; __np->__next_ != nullptr &&
key_eq()(__cp->__upcast()->__value_,
__np->__next_->__upcast()->__value_);
__np = __np->__next_)
;
__pp->__next_ = __np->__next_;
__np->__next_ = __bucket_list_[__chash]->__next_;
__bucket_list_[__chash]->__next_ = __cp;
}
}
}
}
}
}
template <class _Tp, class _Hash, class _Equal, class _Alloc>
template <class _Key>
typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator
__hash_table<_Tp, _Hash, _Equal, _Alloc>::find(const _Key& __k)
{
size_t __hash = hash_function()(__k);
size_type __bc = bucket_count();
if (__bc != 0)
{
size_t __chash = __constrain_hash(__hash, __bc);
__next_pointer __nd = __bucket_list_[__chash];
if (__nd != nullptr)
{
for (__nd = __nd->__next_; __nd != nullptr &&
(__nd->__hash() == __hash
|| __constrain_hash(__nd->__hash(), __bc) == __chash);
__nd = __nd->__next_)
{
if ((__nd->__hash() == __hash)
&& key_eq()(__nd->__upcast()->__value_, __k))
#if _LIBCPP_DEBUG_LEVEL >= 2
return iterator(__nd, this);
#else
return iterator(__nd);
#endif
}
}
}
return end();
}
template <class _Tp, class _Hash, class _Equal, class _Alloc>
template <class _Key>
typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::const_iterator
__hash_table<_Tp, _Hash, _Equal, _Alloc>::find(const _Key& __k) const
{
size_t __hash = hash_function()(__k);
size_type __bc = bucket_count();
if (__bc != 0)
{
size_t __chash = __constrain_hash(__hash, __bc);
__next_pointer __nd = __bucket_list_[__chash];
if (__nd != nullptr)
{
for (__nd = __nd->__next_; __nd != nullptr &&
(__hash == __nd->__hash()
|| __constrain_hash(__nd->__hash(), __bc) == __chash);
__nd = __nd->__next_)
{
if ((__nd->__hash() == __hash)
&& key_eq()(__nd->__upcast()->__value_, __k))
#if _LIBCPP_DEBUG_LEVEL >= 2
return const_iterator(__nd, this);
#else
return const_iterator(__nd);
#endif
}
}
}
return end();
}
#ifndef _LIBCPP_CXX03_LANG
template <class _Tp, class _Hash, class _Equal, class _Alloc>
template <class ..._Args>
typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::__node_holder
__hash_table<_Tp, _Hash, _Equal, _Alloc>::__construct_node(_Args&& ...__args)
{
static_assert(!__is_hash_value_type<_Args...>::value,
"Construct cannot be called with a hash 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;
__h->__hash_ = hash_function()(__h->__value_);
__h->__next_ = nullptr;
return __h;
}
template <class _Tp, class _Hash, class _Equal, class _Alloc>
template <class _First, class ..._Rest>
typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::__node_holder
__hash_table<_Tp, _Hash, _Equal, _Alloc>::__construct_node_hash(
size_t __hash, _First&& __f, _Rest&& ...__rest)
{
static_assert(!__is_hash_value_type<_First, _Rest...>::value,
"Construct cannot be called with a hash 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<_First>(__f),
_VSTD::forward<_Rest>(__rest)...);
__h.get_deleter().__value_constructed = true;
__h->__hash_ = __hash;
__h->__next_ = nullptr;
return __h;
}
#else // _LIBCPP_CXX03_LANG
template <class _Tp, class _Hash, class _Equal, class _Alloc>
typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::__node_holder
__hash_table<_Tp, _Hash, _Equal, _Alloc>::__construct_node(const __container_value_type& __v)
{
__node_allocator& __na = __node_alloc();
__node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na));
__node_traits::construct(__na, _NodeTypes::__get_ptr(__h->__value_), __v);
__h.get_deleter().__value_constructed = true;
__h->__hash_ = hash_function()(__h->__value_);
__h->__next_ = nullptr;
return _LIBCPP_EXPLICIT_MOVE(__h); // explicitly moved for C++03
}
template <class _Tp, class _Hash, class _Equal, class _Alloc>
typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::__node_holder
__hash_table<_Tp, _Hash, _Equal, _Alloc>::__construct_node_hash(size_t __hash,
const __container_value_type& __v)
{
__node_allocator& __na = __node_alloc();
__node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na));
__node_traits::construct(__na, _NodeTypes::__get_ptr(__h->__value_), __v);
__h.get_deleter().__value_constructed = true;
__h->__hash_ = __hash;
__h->__next_ = nullptr;
return _LIBCPP_EXPLICIT_MOVE(__h); // explicitly moved for C++03
}
#endif // _LIBCPP_CXX03_LANG
template <class _Tp, class _Hash, class _Equal, class _Alloc>
typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator
__hash_table<_Tp, _Hash, _Equal, _Alloc>::erase(const_iterator __p)
{
__next_pointer __np = __p.__node_;
#if _LIBCPP_DEBUG_LEVEL >= 2
_LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this,
"unordered container erase(iterator) called with an iterator not"
" referring to this container");
_LIBCPP_ASSERT(__p != end(),
"unordered container erase(iterator) called with a non-dereferenceable iterator");
iterator __r(__np, this);
#else
iterator __r(__np);
#endif
++__r;
remove(__p);
return __r;
}
template <class _Tp, class _Hash, class _Equal, class _Alloc>
typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator
__hash_table<_Tp, _Hash, _Equal, _Alloc>::erase(const_iterator __first,
const_iterator __last)
{
#if _LIBCPP_DEBUG_LEVEL >= 2
_LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__first) == this,
"unodered container::erase(iterator, iterator) called with an iterator not"
" referring to this unodered container");
_LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__last) == this,
"unodered container::erase(iterator, iterator) called with an iterator not"
" referring to this unodered container");
#endif
for (const_iterator __p = __first; __first != __last; __p = __first)
{
++__first;
erase(__p);
}
__next_pointer __np = __last.__node_;
#if _LIBCPP_DEBUG_LEVEL >= 2
return iterator (__np, this);
#else
return iterator (__np);
#endif
}
template <class _Tp, class _Hash, class _Equal, class _Alloc>
template <class _Key>
typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::size_type
__hash_table<_Tp, _Hash, _Equal, _Alloc>::__erase_unique(const _Key& __k)
{
iterator __i = find(__k);
if (__i == end())
return 0;
erase(__i);
return 1;
}
template <class _Tp, class _Hash, class _Equal, class _Alloc>
template <class _Key>
typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::size_type
__hash_table<_Tp, _Hash, _Equal, _Alloc>::__erase_multi(const _Key& __k)
{
size_type __r = 0;
iterator __i = find(__k);
if (__i != end())
{
iterator __e = end();
do
{
erase(__i++);
++__r;
} while (__i != __e && key_eq()(*__i, __k));
}
return __r;
}
template <class _Tp, class _Hash, class _Equal, class _Alloc>
typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::__node_holder
__hash_table<_Tp, _Hash, _Equal, _Alloc>::remove(const_iterator __p) _NOEXCEPT
{
// current node
__next_pointer __cn = __p.__node_;
size_type __bc = bucket_count();
size_t __chash = __constrain_hash(__cn->__hash(), __bc);
// find previous node
__next_pointer __pn = __bucket_list_[__chash];
for (; __pn->__next_ != __cn; __pn = __pn->__next_)
;
// Fix up __bucket_list_
// if __pn is not in same bucket (before begin is not in same bucket) &&
// if __cn->__next_ is not in same bucket (nullptr is not in same bucket)
if (__pn == __p1_.first().__ptr()
|| __constrain_hash(__pn->__hash(), __bc) != __chash)
{
if (__cn->__next_ == nullptr
|| __constrain_hash(__cn->__next_->__hash(), __bc) != __chash)
__bucket_list_[__chash] = nullptr;
}
// if __cn->__next_ is not in same bucket (nullptr is in same bucket)
if (__cn->__next_ != nullptr)
{
size_t __nhash = __constrain_hash(__cn->__next_->__hash(), __bc);
if (__nhash != __chash)
__bucket_list_[__nhash] = __pn;
}
// remove __cn
__pn->__next_ = __cn->__next_;
__cn->__next_ = nullptr;
--size();
#if _LIBCPP_DEBUG_LEVEL >= 2
__c_node* __c = __get_db()->__find_c_and_lock(this);
for (__i_node** __dp = __c->end_; __dp != __c->beg_; )
{
--__dp;
iterator* __i = static_cast<iterator*>((*__dp)->__i_);
if (__i->__node_ == __cn)
{
(*__dp)->__c_ = nullptr;
if (--__c->end_ != __dp)
memmove(__dp, __dp+1, (__c->end_ - __dp)*sizeof(__i_node*));
}
}
__get_db()->unlock();
#endif
return __node_holder(__cn->__upcast(), _Dp(__node_alloc(), true));
}
template <class _Tp, class _Hash, class _Equal, class _Alloc>
template <class _Key>
inline
typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::size_type
__hash_table<_Tp, _Hash, _Equal, _Alloc>::__count_unique(const _Key& __k) const
{
return static_cast<size_type>(find(__k) != end());
}
template <class _Tp, class _Hash, class _Equal, class _Alloc>
template <class _Key>
typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::size_type
__hash_table<_Tp, _Hash, _Equal, _Alloc>::__count_multi(const _Key& __k) const
{
size_type __r = 0;
const_iterator __i = find(__k);
if (__i != end())
{
const_iterator __e = end();
do
{
++__i;
++__r;
} while (__i != __e && key_eq()(*__i, __k));
}
return __r;
}
template <class _Tp, class _Hash, class _Equal, class _Alloc>
template <class _Key>
pair<typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator,
typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator>
__hash_table<_Tp, _Hash, _Equal, _Alloc>::__equal_range_unique(
const _Key& __k)
{
iterator __i = find(__k);
iterator __j = __i;
if (__i != end())
++__j;
return pair<iterator, iterator>(__i, __j);
}
template <class _Tp, class _Hash, class _Equal, class _Alloc>
template <class _Key>
pair<typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::const_iterator,
typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::const_iterator>
__hash_table<_Tp, _Hash, _Equal, _Alloc>::__equal_range_unique(
const _Key& __k) const
{
const_iterator __i = find(__k);
const_iterator __j = __i;
if (__i != end())
++__j;
return pair<const_iterator, const_iterator>(__i, __j);
}
template <class _Tp, class _Hash, class _Equal, class _Alloc>
template <class _Key>
pair<typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator,
typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator>
__hash_table<_Tp, _Hash, _Equal, _Alloc>::__equal_range_multi(
const _Key& __k)
{
iterator __i = find(__k);
iterator __j = __i;
if (__i != end())
{
iterator __e = end();
do
{
++__j;
} while (__j != __e && key_eq()(*__j, __k));
}
return pair<iterator, iterator>(__i, __j);
}
template <class _Tp, class _Hash, class _Equal, class _Alloc>
template <class _Key>
pair<typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::const_iterator,
typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::const_iterator>
__hash_table<_Tp, _Hash, _Equal, _Alloc>::__equal_range_multi(
const _Key& __k) const
{
const_iterator __i = find(__k);
const_iterator __j = __i;
if (__i != end())
{
const_iterator __e = end();
do
{
++__j;
} while (__j != __e && key_eq()(*__j, __k));
}
return pair<const_iterator, const_iterator>(__i, __j);
}
template <class _Tp, class _Hash, class _Equal, class _Alloc>
void
__hash_table<_Tp, _Hash, _Equal, _Alloc>::swap(__hash_table& __u)
#if _LIBCPP_STD_VER <= 11
_NOEXCEPT_(
__is_nothrow_swappable<hasher>::value && __is_nothrow_swappable<key_equal>::value
&& (!allocator_traits<__pointer_allocator>::propagate_on_container_swap::value
|| __is_nothrow_swappable<__pointer_allocator>::value)
&& (!__node_traits::propagate_on_container_swap::value
|| __is_nothrow_swappable<__node_allocator>::value)
)
#else
_NOEXCEPT_(__is_nothrow_swappable<hasher>::value && __is_nothrow_swappable<key_equal>::value)
#endif
{
_LIBCPP_ASSERT(__node_traits::propagate_on_container_swap::value ||
this->__node_alloc() == __u.__node_alloc(),
"list::swap: Either propagate_on_container_swap must be true"
" or the allocators must compare equal");
{
__node_pointer_pointer __npp = __bucket_list_.release();
__bucket_list_.reset(__u.__bucket_list_.release());
__u.__bucket_list_.reset(__npp);
}
_VSTD::swap(__bucket_list_.get_deleter().size(), __u.__bucket_list_.get_deleter().size());
__swap_allocator(__bucket_list_.get_deleter().__alloc(),
__u.__bucket_list_.get_deleter().__alloc());
__swap_allocator(__node_alloc(), __u.__node_alloc());
_VSTD::swap(__p1_.first().__next_, __u.__p1_.first().__next_);
__p2_.swap(__u.__p2_);
__p3_.swap(__u.__p3_);
if (size() > 0)
__bucket_list_[__constrain_hash(__p1_.first().__next_->__hash(), bucket_count())] =
__p1_.first().__ptr();
if (__u.size() > 0)
__u.__bucket_list_[__constrain_hash(__u.__p1_.first().__next_->__hash(), __u.bucket_count())] =
__u.__p1_.first().__ptr();
#if _LIBCPP_DEBUG_LEVEL >= 2
__get_db()->swap(this, &__u);
#endif
}
template <class _Tp, class _Hash, class _Equal, class _Alloc>
typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::size_type
__hash_table<_Tp, _Hash, _Equal, _Alloc>::bucket_size(size_type __n) const
{
_LIBCPP_ASSERT(__n < bucket_count(),
"unordered container::bucket_size(n) called with n >= bucket_count()");
__next_pointer __np = __bucket_list_[__n];
size_type __bc = bucket_count();
size_type __r = 0;
if (__np != nullptr)
{
for (__np = __np->__next_; __np != nullptr &&
__constrain_hash(__np->__hash(), __bc) == __n;
__np = __np->__next_, ++__r)
;
}
return __r;
}
template <class _Tp, class _Hash, class _Equal, class _Alloc>
inline _LIBCPP_INLINE_VISIBILITY
void
swap(__hash_table<_Tp, _Hash, _Equal, _Alloc>& __x,
__hash_table<_Tp, _Hash, _Equal, _Alloc>& __y)
_NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
{
__x.swap(__y);
}
#if _LIBCPP_DEBUG_LEVEL >= 2
template <class _Tp, class _Hash, class _Equal, class _Alloc>
bool
__hash_table<_Tp, _Hash, _Equal, _Alloc>::__dereferenceable(const const_iterator* __i) const
{
return __i->__node_ != nullptr;
}
template <class _Tp, class _Hash, class _Equal, class _Alloc>
bool
__hash_table<_Tp, _Hash, _Equal, _Alloc>::__decrementable(const const_iterator*) const
{
return false;
}
template <class _Tp, class _Hash, class _Equal, class _Alloc>
bool
__hash_table<_Tp, _Hash, _Equal, _Alloc>::__addable(const const_iterator*, ptrdiff_t) const
{
return false;
}
template <class _Tp, class _Hash, class _Equal, class _Alloc>
bool
__hash_table<_Tp, _Hash, _Equal, _Alloc>::__subscriptable(const const_iterator*, ptrdiff_t) const
{
return false;
}
#endif // _LIBCPP_DEBUG_LEVEL >= 2
_LIBCPP_END_NAMESPACE_STD
_LIBCPP_POP_MACROS
#endif // _LIBCPP__HASH_TABLE
| 104,406 | 2,914 | jart/cosmopolitan | false |
cosmopolitan/third_party/libcxx/clocale | // -*- C++ -*-
// clang-format off
//===--------------------------- clocale ----------------------------------===//
//
// 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_CLOCALE
#define _LIBCPP_CLOCALE
/*
clocale synopsis
Macros:
LC_ALL
LC_COLLATE
LC_CTYPE
LC_MONETARY
LC_NUMERIC
LC_TIME
NULL
namespace std
{
struct lconv;
char* setlocale(int category, const char* locale);
lconv* localeconv();
} // std
*/
#include "third_party/libcxx/__config"
#include "libc/str/unicode.h"
#include "libc/str/locale.h"
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
#pragma GCC system_header
#endif
_LIBCPP_BEGIN_NAMESPACE_STD
using ::lconv;
#ifndef _LIBCPP_HAS_NO_THREAD_UNSAFE_C_FUNCTIONS
using ::setlocale;
#endif
using ::localeconv;
_LIBCPP_END_NAMESPACE_STD
#endif // _LIBCPP_CLOCALE
| 1,076 | 57 | jart/cosmopolitan | false |
cosmopolitan/third_party/libcxx/ctime | // -*- C++ -*-
//===---------------------------- ctime -----------------------------------===//
//
// 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_CTIME
#define _LIBCPP_CTIME
#include "third_party/libcxx/__config"
#include "libc/calls/weirdtypes.h"
#include "libc/isystem/time.h"
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
#pragma GCC system_header
#endif
_LIBCPP_BEGIN_NAMESPACE_STD
/*
ctime synopsis
Macros:
NULL
CLOCKS_PER_SEC
TIME_UTC // C++17
namespace std
{
Types:
clock_t
size_t
time_t
tm
timespec // C++17
clock_t clock();
double difftime(time_t time1, time_t time0);
time_t mktime(tm* timeptr);
time_t time(time_t* timer);
char* asctime(const tm* timeptr);
char* ctime(const time_t* timer);
tm* gmtime(const time_t* timer);
tm* localtime(const time_t* timer);
size_t strftime(char* restrict s, size_t maxsize, const char* restrict format,
const tm* restrict timeptr);
int timespec_get( struct timespec *ts, int base); // C++17
} // std
*/
using ::clock_t;
using ::size_t;
using ::time_t;
using ::tm;
#if _LIBCPP_STD_VER > 14 && defined(_LIBCPP_HAS_C11_FEATURES)
using ::timespec;
#endif
using ::clock;
using ::difftime;
using ::mktime;
using ::time;
#ifndef _LIBCPP_HAS_NO_THREAD_UNSAFE_C_FUNCTIONS
using ::asctime;
using ::ctime;
using ::gmtime;
using ::localtime;
#endif
using ::strftime;
#if _LIBCPP_STD_VER > 14 && defined(_LIBCPP_HAS_TIMESPEC_GET)
using ::timespec_get;
#endif
_LIBCPP_END_NAMESPACE_STD
#endif // _LIBCPP_CTIME
| 1,781 | 83 | jart/cosmopolitan | false |
cosmopolitan/third_party/libcxx/locale | // -*- C++ -*-
//===-------------------------- locale ------------------------------------===//
//
// 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_LOCALE
#define _LIBCPP_LOCALE
#include "third_party/libcxx/__config"
#include "third_party/libcxx/__locale"
#include "third_party/libcxx/__debug"
#include "third_party/libcxx/algorithm"
#include "third_party/libcxx/memory"
#include "third_party/libcxx/ios"
#include "third_party/libcxx/streambuf"
#include "third_party/libcxx/iterator"
#include "third_party/libcxx/limits"
#include "third_party/libcxx/version"
#include "third_party/libcxx/cstdarg"
#include "third_party/libcxx/cstdlib"
#include "third_party/libcxx/ctime"
#include "third_party/libcxx/cstdio"
#ifdef _LIBCPP_HAS_CATOPEN
# include "libc/str/locale.h"
# include "third_party/libcxx/nl_types.h"
#endif
#ifdef _LIBCPP_LOCALE__L_EXTENSIONS
# include "third_party/libcxx/__bsd_locale_defaults.h"
#else
#include "third_party/libcxx/__bsd_locale_fallbacks.h"
#endif
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
#pragma GCC system_header
#endif
_LIBCPP_PUSH_MACROS
#include "third_party/libcxx/__undef_macros"
_LIBCPP_BEGIN_NAMESPACE_STD
/*
locale synopsis
namespace std
{
class locale
{
public:
// types:
class facet;
class id;
typedef int category;
static const category // values assigned here are for exposition only
none = 0x000,
collate = 0x010,
ctype = 0x020,
monetary = 0x040,
numeric = 0x080,
time = 0x100,
messages = 0x200,
all = collate | ctype | monetary | numeric | time | messages;
// construct/copy/destroy:
locale() noexcept;
locale(const locale& other) noexcept;
explicit locale(const char* std_name);
explicit locale(const string& std_name);
locale(const locale& other, const char* std_name, category);
locale(const locale& other, const string& std_name, category);
template <class Facet> locale(const locale& other, Facet* f);
locale(const locale& other, const locale& one, category);
~locale(); // not virtual
const locale& operator=(const locale& other) noexcept;
template <class Facet> locale combine(const locale& other) const;
// locale operations:
basic_string<char> name() const;
bool operator==(const locale& other) const;
bool operator!=(const locale& other) const;
template <class charT, class Traits, class Allocator>
bool operator()(const basic_string<charT,Traits,Allocator>& s1,
const basic_string<charT,Traits,Allocator>& s2) const;
// global locale objects:
static locale global(const locale&);
static const locale& classic();
};
template <class Facet> const Facet& use_facet(const locale&);
template <class Facet> bool has_facet(const locale&) noexcept;
// 22.3.3, convenience interfaces:
template <class charT> bool isspace (charT c, const locale& loc);
template <class charT> bool isprint (charT c, const locale& loc);
template <class charT> bool iscntrl (charT c, const locale& loc);
template <class charT> bool isupper (charT c, const locale& loc);
template <class charT> bool islower (charT c, const locale& loc);
template <class charT> bool isalpha (charT c, const locale& loc);
template <class charT> bool isdigit (charT c, const locale& loc);
template <class charT> bool ispunct (charT c, const locale& loc);
template <class charT> bool isxdigit(charT c, const locale& loc);
template <class charT> bool isalnum (charT c, const locale& loc);
template <class charT> bool isgraph (charT c, const locale& loc);
template <class charT> charT toupper(charT c, const locale& loc);
template <class charT> charT tolower(charT c, const locale& loc);
template<class Codecvt, class Elem = wchar_t,
class Wide_alloc = allocator<Elem>,
class Byte_alloc = allocator<char>>
class wstring_convert
{
public:
typedef basic_string<char, char_traits<char>, Byte_alloc> byte_string;
typedef basic_string<Elem, char_traits<Elem>, Wide_alloc> wide_string;
typedef typename Codecvt::state_type state_type;
typedef typename wide_string::traits_type::int_type int_type;
explicit wstring_convert(Codecvt* pcvt = new Codecvt); // explicit in C++14
wstring_convert(Codecvt* pcvt, state_type state);
explicit wstring_convert(const byte_string& byte_err, // explicit in C++14
const wide_string& wide_err = wide_string());
wstring_convert(const wstring_convert&) = delete; // C++14
wstring_convert & operator=(const wstring_convert &) = delete; // C++14
~wstring_convert();
wide_string from_bytes(char byte);
wide_string from_bytes(const char* ptr);
wide_string from_bytes(const byte_string& str);
wide_string from_bytes(const char* first, const char* last);
byte_string to_bytes(Elem wchar);
byte_string to_bytes(const Elem* wptr);
byte_string to_bytes(const wide_string& wstr);
byte_string to_bytes(const Elem* first, const Elem* last);
size_t converted() const; // noexcept in C++14
state_type state() const;
};
template <class Codecvt, class Elem = wchar_t, class Tr = char_traits<Elem>>
class wbuffer_convert
: public basic_streambuf<Elem, Tr>
{
public:
typedef typename Tr::state_type state_type;
explicit wbuffer_convert(streambuf* bytebuf = 0, Codecvt* pcvt = new Codecvt,
state_type state = state_type()); // explicit in C++14
wbuffer_convert(const wbuffer_convert&) = delete; // C++14
wbuffer_convert & operator=(const wbuffer_convert &) = delete; // C++14
~wbuffer_convert(); // C++14
streambuf* rdbuf() const;
streambuf* rdbuf(streambuf* bytebuf);
state_type state() const;
};
// 22.4.1 and 22.4.1.3, ctype:
class ctype_base;
template <class charT> class ctype;
template <> class ctype<char>; // specialization
template <class charT> class ctype_byname;
template <> class ctype_byname<char>; // specialization
class codecvt_base;
template <class internT, class externT, class stateT> class codecvt;
template <class internT, class externT, class stateT> class codecvt_byname;
// 22.4.2 and 22.4.3, numeric:
template <class charT, class InputIterator> class num_get;
template <class charT, class OutputIterator> class num_put;
template <class charT> class numpunct;
template <class charT> class numpunct_byname;
// 22.4.4, col lation:
template <class charT> class collate;
template <class charT> class collate_byname;
// 22.4.5, date and time:
class time_base;
template <class charT, class InputIterator> class time_get;
template <class charT, class InputIterator> class time_get_byname;
template <class charT, class OutputIterator> class time_put;
template <class charT, class OutputIterator> class time_put_byname;
// 22.4.6, money:
class money_base;
template <class charT, class InputIterator> class money_get;
template <class charT, class OutputIterator> class money_put;
template <class charT, bool Intl> class moneypunct;
template <class charT, bool Intl> class moneypunct_byname;
// 22.4.7, message retrieval:
class messages_base;
template <class charT> class messages;
template <class charT> class messages_byname;
} // std
*/
#if defined(__APPLE__) || defined(__FreeBSD__) || defined(__COSMOPOLITAN__)
# define _LIBCPP_GET_C_LOCALE 0
#elif defined(__CloudABI__) || defined(__NetBSD__)
# define _LIBCPP_GET_C_LOCALE LC_C_LOCALE
#else
# define _LIBCPP_GET_C_LOCALE __cloc()
// Get the C locale object
_LIBCPP_FUNC_VIS locale_t __cloc();
#define __cloc_defined
#endif
// __scan_keyword
// Scans [__b, __e) until a match is found in the basic_strings range
// [__kb, __ke) or until it can be shown that there is no match in [__kb, __ke).
// __b will be incremented (visibly), consuming CharT until a match is found
// or proved to not exist. A keyword may be "", in which will match anything.
// If one keyword is a prefix of another, and the next CharT in the input
// might match another keyword, the algorithm will attempt to find the longest
// matching keyword. If the longer matching keyword ends up not matching, then
// no keyword match is found. If no keyword match is found, __ke is returned
// and failbit is set in __err.
// Else an iterator pointing to the matching keyword is found. If more than
// one keyword matches, an iterator to the first matching keyword is returned.
// If on exit __b == __e, eofbit is set in __err. If __case_sensitive is false,
// __ct is used to force to lower case before comparing characters.
// Examples:
// Keywords: "a", "abb"
// If the input is "a", the first keyword matches and eofbit is set.
// If the input is "abc", no match is found and "ab" are consumed.
template <class _InputIterator, class _ForwardIterator, class _Ctype>
_LIBCPP_HIDDEN
_ForwardIterator
__scan_keyword(_InputIterator& __b, _InputIterator __e,
_ForwardIterator __kb, _ForwardIterator __ke,
const _Ctype& __ct, ios_base::iostate& __err,
bool __case_sensitive = true)
{
typedef typename iterator_traits<_InputIterator>::value_type _CharT;
size_t __nkw = static_cast<size_t>(_VSTD::distance(__kb, __ke));
const unsigned char __doesnt_match = '\0';
const unsigned char __might_match = '\1';
const unsigned char __does_match = '\2';
unsigned char __statbuf[100];
unsigned char* __status = __statbuf;
unique_ptr<unsigned char, void(*)(void*)> __stat_hold(0, free);
if (__nkw > sizeof(__statbuf))
{
__status = (unsigned char*)malloc(__nkw);
if (__status == 0)
__throw_bad_alloc();
__stat_hold.reset(__status);
}
size_t __n_might_match = __nkw; // At this point, any keyword might match
size_t __n_does_match = 0; // but none of them definitely do
// Initialize all statuses to __might_match, except for "" keywords are __does_match
unsigned char* __st = __status;
for (_ForwardIterator __ky = __kb; __ky != __ke; ++__ky, (void) ++__st)
{
if (!__ky->empty())
*__st = __might_match;
else
{
*__st = __does_match;
--__n_might_match;
++__n_does_match;
}
}
// While there might be a match, test keywords against the next CharT
for (size_t __indx = 0; __b != __e && __n_might_match > 0; ++__indx)
{
// Peek at the next CharT but don't consume it
_CharT __c = *__b;
if (!__case_sensitive)
__c = __ct.toupper(__c);
bool __consume = false;
// For each keyword which might match, see if the __indx character is __c
// If a match if found, consume __c
// If a match is found, and that is the last character in the keyword,
// then that keyword matches.
// If the keyword doesn't match this character, then change the keyword
// to doesn't match
__st = __status;
for (_ForwardIterator __ky = __kb; __ky != __ke; ++__ky, (void) ++__st)
{
if (*__st == __might_match)
{
_CharT __kc = (*__ky)[__indx];
if (!__case_sensitive)
__kc = __ct.toupper(__kc);
if (__c == __kc)
{
__consume = true;
if (__ky->size() == __indx+1)
{
*__st = __does_match;
--__n_might_match;
++__n_does_match;
}
}
else
{
*__st = __doesnt_match;
--__n_might_match;
}
}
}
// consume if we matched a character
if (__consume)
{
++__b;
// If we consumed a character and there might be a matched keyword that
// was marked matched on a previous iteration, then such keywords
// which are now marked as not matching.
if (__n_might_match + __n_does_match > 1)
{
__st = __status;
for (_ForwardIterator __ky = __kb; __ky != __ke; ++__ky, (void) ++__st)
{
if (*__st == __does_match && __ky->size() != __indx+1)
{
*__st = __doesnt_match;
--__n_does_match;
}
}
}
}
}
// We've exited the loop because we hit eof and/or we have no more "might matches".
if (__b == __e)
__err |= ios_base::eofbit;
// Return the first matching result
for (__st = __status; __kb != __ke; ++__kb, (void) ++__st)
if (*__st == __does_match)
break;
if (__kb == __ke)
__err |= ios_base::failbit;
return __kb;
}
struct _LIBCPP_TYPE_VIS __num_get_base
{
static const int __num_get_buf_sz = 40;
static int __get_base(ios_base&);
static const char __src[33];
};
_LIBCPP_FUNC_VIS
void __check_grouping(const string& __grouping, unsigned* __g, unsigned* __g_end,
ios_base::iostate& __err);
template <class _CharT>
struct __num_get
: protected __num_get_base
{
static string __stage2_float_prep(ios_base& __iob, _CharT* __atoms, _CharT& __decimal_point,
_CharT& __thousands_sep);
static int __stage2_float_loop(_CharT __ct, bool& __in_units, char& __exp,
char* __a, char*& __a_end,
_CharT __decimal_point, _CharT __thousands_sep,
const string& __grouping, unsigned* __g,
unsigned*& __g_end, unsigned& __dc, _CharT* __atoms);
#ifndef _LIBCPP_ABI_OPTIMIZED_LOCALE_NUM_GET
static string __stage2_int_prep(ios_base& __iob, _CharT* __atoms, _CharT& __thousands_sep);
static int __stage2_int_loop(_CharT __ct, int __base, char* __a, char*& __a_end,
unsigned& __dc, _CharT __thousands_sep, const string& __grouping,
unsigned* __g, unsigned*& __g_end, _CharT* __atoms);
#else
static string __stage2_int_prep(ios_base& __iob, _CharT& __thousands_sep)
{
locale __loc = __iob.getloc();
const numpunct<_CharT>& __np = use_facet<numpunct<_CharT> >(__loc);
__thousands_sep = __np.thousands_sep();
return __np.grouping();
}
const _CharT* __do_widen(ios_base& __iob, _CharT* __atoms) const
{
return __do_widen_p(__iob, __atoms);
}
static int __stage2_int_loop(_CharT __ct, int __base, char* __a, char*& __a_end,
unsigned& __dc, _CharT __thousands_sep, const string& __grouping,
unsigned* __g, unsigned*& __g_end, const _CharT* __atoms);
private:
template<typename T>
const T* __do_widen_p(ios_base& __iob, T* __atoms) const
{
locale __loc = __iob.getloc();
use_facet<ctype<T> >(__loc).widen(__src, __src + 26, __atoms);
return __atoms;
}
const char* __do_widen_p(ios_base& __iob, char* __atoms) const
{
(void)__iob;
(void)__atoms;
return __src;
}
#endif
};
#ifndef _LIBCPP_ABI_OPTIMIZED_LOCALE_NUM_GET
template <class _CharT>
string
__num_get<_CharT>::__stage2_int_prep(ios_base& __iob, _CharT* __atoms, _CharT& __thousands_sep)
{
locale __loc = __iob.getloc();
use_facet<ctype<_CharT> >(__loc).widen(__src, __src + 26, __atoms);
const numpunct<_CharT>& __np = use_facet<numpunct<_CharT> >(__loc);
__thousands_sep = __np.thousands_sep();
return __np.grouping();
}
#endif
template <class _CharT>
string
__num_get<_CharT>::__stage2_float_prep(ios_base& __iob, _CharT* __atoms, _CharT& __decimal_point,
_CharT& __thousands_sep)
{
locale __loc = __iob.getloc();
use_facet<ctype<_CharT> >(__loc).widen(__src, __src + 32, __atoms);
const numpunct<_CharT>& __np = use_facet<numpunct<_CharT> >(__loc);
__decimal_point = __np.decimal_point();
__thousands_sep = __np.thousands_sep();
return __np.grouping();
}
template <class _CharT>
int
#ifndef _LIBCPP_ABI_OPTIMIZED_LOCALE_NUM_GET
__num_get<_CharT>::__stage2_int_loop(_CharT __ct, int __base, char* __a, char*& __a_end,
unsigned& __dc, _CharT __thousands_sep, const string& __grouping,
unsigned* __g, unsigned*& __g_end, _CharT* __atoms)
#else
__num_get<_CharT>::__stage2_int_loop(_CharT __ct, int __base, char* __a, char*& __a_end,
unsigned& __dc, _CharT __thousands_sep, const string& __grouping,
unsigned* __g, unsigned*& __g_end, const _CharT* __atoms)
#endif
{
if (__a_end == __a && (__ct == __atoms[24] || __ct == __atoms[25]))
{
*__a_end++ = __ct == __atoms[24] ? '+' : '-';
__dc = 0;
return 0;
}
if (__grouping.size() != 0 && __ct == __thousands_sep)
{
if (__g_end-__g < __num_get_buf_sz)
{
*__g_end++ = __dc;
__dc = 0;
}
return 0;
}
ptrdiff_t __f = find(__atoms, __atoms + 26, __ct) - __atoms;
if (__f >= 24)
return -1;
switch (__base)
{
case 8:
case 10:
if (__f >= __base)
return -1;
break;
case 16:
if (__f < 22)
break;
if (__a_end != __a && __a_end - __a <= 2 && __a_end[-1] == '0')
{
__dc = 0;
*__a_end++ = __src[__f];
return 0;
}
return -1;
}
*__a_end++ = __src[__f];
++__dc;
return 0;
}
template <class _CharT>
int
__num_get<_CharT>::__stage2_float_loop(_CharT __ct, bool& __in_units, char& __exp, char* __a, char*& __a_end,
_CharT __decimal_point, _CharT __thousands_sep, const string& __grouping,
unsigned* __g, unsigned*& __g_end, unsigned& __dc, _CharT* __atoms)
{
if (__ct == __decimal_point)
{
if (!__in_units)
return -1;
__in_units = false;
*__a_end++ = '.';
if (__grouping.size() != 0 && __g_end-__g < __num_get_buf_sz)
*__g_end++ = __dc;
return 0;
}
if (__ct == __thousands_sep && __grouping.size() != 0)
{
if (!__in_units)
return -1;
if (__g_end-__g < __num_get_buf_sz)
{
*__g_end++ = __dc;
__dc = 0;
}
return 0;
}
ptrdiff_t __f = find(__atoms, __atoms + 32, __ct) - __atoms;
if (__f >= 32)
return -1;
char __x = __src[__f];
if (__x == '-' || __x == '+')
{
if (__a_end == __a || (__a_end[-1] & 0x5F) == (__exp & 0x7F))
{
*__a_end++ = __x;
return 0;
}
return -1;
}
if (__x == 'x' || __x == 'X')
__exp = 'P';
else if ((__x & 0x5F) == __exp)
{
__exp |= (char) 0x80;
if (__in_units)
{
__in_units = false;
if (__grouping.size() != 0 && __g_end-__g < __num_get_buf_sz)
*__g_end++ = __dc;
}
}
*__a_end++ = __x;
if (__f >= 22)
return 0;
++__dc;
return 0;
}
_LIBCPP_EXTERN_TEMPLATE2(struct _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS __num_get<char>)
_LIBCPP_EXTERN_TEMPLATE2(struct _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS __num_get<wchar_t>)
template <class _CharT, class _InputIterator = istreambuf_iterator<_CharT> >
class _LIBCPP_TEMPLATE_VIS num_get
: public locale::facet,
private __num_get<_CharT>
{
public:
typedef _CharT char_type;
typedef _InputIterator iter_type;
_LIBCPP_INLINE_VISIBILITY
explicit num_get(size_t __refs = 0)
: locale::facet(__refs) {}
_LIBCPP_INLINE_VISIBILITY
iter_type get(iter_type __b, iter_type __e, ios_base& __iob,
ios_base::iostate& __err, bool& __v) const
{
return do_get(__b, __e, __iob, __err, __v);
}
_LIBCPP_INLINE_VISIBILITY
iter_type get(iter_type __b, iter_type __e, ios_base& __iob,
ios_base::iostate& __err, long& __v) const
{
return do_get(__b, __e, __iob, __err, __v);
}
_LIBCPP_INLINE_VISIBILITY
iter_type get(iter_type __b, iter_type __e, ios_base& __iob,
ios_base::iostate& __err, long long& __v) const
{
return do_get(__b, __e, __iob, __err, __v);
}
_LIBCPP_INLINE_VISIBILITY
iter_type get(iter_type __b, iter_type __e, ios_base& __iob,
ios_base::iostate& __err, unsigned short& __v) const
{
return do_get(__b, __e, __iob, __err, __v);
}
_LIBCPP_INLINE_VISIBILITY
iter_type get(iter_type __b, iter_type __e, ios_base& __iob,
ios_base::iostate& __err, unsigned int& __v) const
{
return do_get(__b, __e, __iob, __err, __v);
}
_LIBCPP_INLINE_VISIBILITY
iter_type get(iter_type __b, iter_type __e, ios_base& __iob,
ios_base::iostate& __err, unsigned long& __v) const
{
return do_get(__b, __e, __iob, __err, __v);
}
_LIBCPP_INLINE_VISIBILITY
iter_type get(iter_type __b, iter_type __e, ios_base& __iob,
ios_base::iostate& __err, unsigned long long& __v) const
{
return do_get(__b, __e, __iob, __err, __v);
}
_LIBCPP_INLINE_VISIBILITY
iter_type get(iter_type __b, iter_type __e, ios_base& __iob,
ios_base::iostate& __err, float& __v) const
{
return do_get(__b, __e, __iob, __err, __v);
}
_LIBCPP_INLINE_VISIBILITY
iter_type get(iter_type __b, iter_type __e, ios_base& __iob,
ios_base::iostate& __err, double& __v) const
{
return do_get(__b, __e, __iob, __err, __v);
}
_LIBCPP_INLINE_VISIBILITY
iter_type get(iter_type __b, iter_type __e, ios_base& __iob,
ios_base::iostate& __err, long double& __v) const
{
return do_get(__b, __e, __iob, __err, __v);
}
_LIBCPP_INLINE_VISIBILITY
iter_type get(iter_type __b, iter_type __e, ios_base& __iob,
ios_base::iostate& __err, void*& __v) const
{
return do_get(__b, __e, __iob, __err, __v);
}
static locale::id id;
protected:
_LIBCPP_INLINE_VISIBILITY
~num_get() {}
template <class _Fp>
_LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
iter_type __do_get_floating_point
(iter_type __b, iter_type __e, ios_base& __iob,
ios_base::iostate& __err, _Fp& __v) const;
template <class _Signed>
_LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
iter_type __do_get_signed
(iter_type __b, iter_type __e, ios_base& __iob,
ios_base::iostate& __err, _Signed& __v) const;
template <class _Unsigned>
_LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
iter_type __do_get_unsigned
(iter_type __b, iter_type __e, ios_base& __iob,
ios_base::iostate& __err, _Unsigned& __v) const;
virtual iter_type do_get(iter_type __b, iter_type __e, ios_base& __iob,
ios_base::iostate& __err, bool& __v) const;
virtual iter_type do_get(iter_type __b, iter_type __e, ios_base& __iob,
ios_base::iostate& __err, long& __v) const
{ return this->__do_get_signed ( __b, __e, __iob, __err, __v ); }
virtual iter_type do_get(iter_type __b, iter_type __e, ios_base& __iob,
ios_base::iostate& __err, long long& __v) const
{ return this->__do_get_signed ( __b, __e, __iob, __err, __v ); }
virtual iter_type do_get(iter_type __b, iter_type __e, ios_base& __iob,
ios_base::iostate& __err, unsigned short& __v) const
{ return this->__do_get_unsigned ( __b, __e, __iob, __err, __v ); }
virtual iter_type do_get(iter_type __b, iter_type __e, ios_base& __iob,
ios_base::iostate& __err, unsigned int& __v) const
{ return this->__do_get_unsigned ( __b, __e, __iob, __err, __v ); }
virtual iter_type do_get(iter_type __b, iter_type __e, ios_base& __iob,
ios_base::iostate& __err, unsigned long& __v) const
{ return this->__do_get_unsigned ( __b, __e, __iob, __err, __v ); }
virtual iter_type do_get(iter_type __b, iter_type __e, ios_base& __iob,
ios_base::iostate& __err, unsigned long long& __v) const
{ return this->__do_get_unsigned ( __b, __e, __iob, __err, __v ); }
virtual iter_type do_get(iter_type __b, iter_type __e, ios_base& __iob,
ios_base::iostate& __err, float& __v) const
{ return this->__do_get_floating_point ( __b, __e, __iob, __err, __v ); }
virtual iter_type do_get(iter_type __b, iter_type __e, ios_base& __iob,
ios_base::iostate& __err, double& __v) const
{ return this->__do_get_floating_point ( __b, __e, __iob, __err, __v ); }
virtual iter_type do_get(iter_type __b, iter_type __e, ios_base& __iob,
ios_base::iostate& __err, long double& __v) const
{ return this->__do_get_floating_point ( __b, __e, __iob, __err, __v ); }
virtual iter_type do_get(iter_type __b, iter_type __e, ios_base& __iob,
ios_base::iostate& __err, void*& __v) const;
};
template <class _CharT, class _InputIterator>
locale::id
num_get<_CharT, _InputIterator>::id;
template <class _Tp>
_LIBCPP_HIDDEN _Tp
__num_get_signed_integral(const char* __a, const char* __a_end,
ios_base::iostate& __err, int __base)
{
if (__a != __a_end)
{
typename remove_reference<decltype(errno)>::type __save_errno = errno;
errno = 0;
char *__p2;
long long __ll = strtoll_l(__a, &__p2, __base, _LIBCPP_GET_C_LOCALE);
typename remove_reference<decltype(errno)>::type __current_errno = errno;
if (__current_errno == 0)
errno = __save_errno;
if (__p2 != __a_end)
{
__err = ios_base::failbit;
return 0;
}
else if (__current_errno == ERANGE ||
__ll < numeric_limits<_Tp>::min() ||
numeric_limits<_Tp>::max() < __ll)
{
__err = ios_base::failbit;
if (__ll > 0)
return numeric_limits<_Tp>::max();
else
return numeric_limits<_Tp>::min();
}
return static_cast<_Tp>(__ll);
}
__err = ios_base::failbit;
return 0;
}
template <class _Tp>
_LIBCPP_HIDDEN _Tp
__num_get_unsigned_integral(const char* __a, const char* __a_end,
ios_base::iostate& __err, int __base)
{
if (__a != __a_end)
{
const bool __negate = *__a == '-';
if (__negate && ++__a == __a_end) {
__err = ios_base::failbit;
return 0;
}
typename remove_reference<decltype(errno)>::type __save_errno = errno;
errno = 0;
char *__p2;
unsigned long long __ll = strtoull_l(__a, &__p2, __base, _LIBCPP_GET_C_LOCALE);
typename remove_reference<decltype(errno)>::type __current_errno = errno;
if (__current_errno == 0)
errno = __save_errno;
if (__p2 != __a_end)
{
__err = ios_base::failbit;
return 0;
}
else if (__current_errno == ERANGE || numeric_limits<_Tp>::max() < __ll)
{
__err = ios_base::failbit;
return numeric_limits<_Tp>::max();
}
_Tp __res = static_cast<_Tp>(__ll);
if (__negate) __res = -__res;
return __res;
}
__err = ios_base::failbit;
return 0;
}
template <class _Tp>
_LIBCPP_INLINE_VISIBILITY
_Tp __do_strtod(const char* __a, char** __p2);
template <>
inline _LIBCPP_INLINE_VISIBILITY
float __do_strtod<float>(const char* __a, char** __p2) {
return strtof_l(__a, __p2, _LIBCPP_GET_C_LOCALE);
}
template <>
inline _LIBCPP_INLINE_VISIBILITY
double __do_strtod<double>(const char* __a, char** __p2) {
return strtod_l(__a, __p2, _LIBCPP_GET_C_LOCALE);
}
template <>
inline _LIBCPP_INLINE_VISIBILITY
long double __do_strtod<long double>(const char* __a, char** __p2) {
return strtold_l(__a, __p2, _LIBCPP_GET_C_LOCALE);
}
template <class _Tp>
_LIBCPP_HIDDEN
_Tp
__num_get_float(const char* __a, const char* __a_end, ios_base::iostate& __err)
{
if (__a != __a_end)
{
typename remove_reference<decltype(errno)>::type __save_errno = errno;
errno = 0;
char *__p2;
_Tp __ld = __do_strtod<_Tp>(__a, &__p2);
typename remove_reference<decltype(errno)>::type __current_errno = errno;
if (__current_errno == 0)
errno = __save_errno;
if (__p2 != __a_end)
{
__err = ios_base::failbit;
return 0;
}
else if (__current_errno == ERANGE)
__err = ios_base::failbit;
return __ld;
}
__err = ios_base::failbit;
return 0;
}
template <class _CharT, class _InputIterator>
_InputIterator
num_get<_CharT, _InputIterator>::do_get(iter_type __b, iter_type __e,
ios_base& __iob,
ios_base::iostate& __err,
bool& __v) const
{
if ((__iob.flags() & ios_base::boolalpha) == 0)
{
long __lv = -1;
__b = do_get(__b, __e, __iob, __err, __lv);
switch (__lv)
{
case 0:
__v = false;
break;
case 1:
__v = true;
break;
default:
__v = true;
__err = ios_base::failbit;
break;
}
return __b;
}
const ctype<_CharT>& __ct = use_facet<ctype<_CharT> >(__iob.getloc());
const numpunct<_CharT>& __np = use_facet<numpunct<_CharT> >(__iob.getloc());
typedef typename numpunct<_CharT>::string_type string_type;
const string_type __names[2] = {__np.truename(), __np.falsename()};
const string_type* __i = __scan_keyword(__b, __e, __names, __names+2,
__ct, __err);
__v = __i == __names;
return __b;
}
// signed
template <class _CharT, class _InputIterator>
template <class _Signed>
_InputIterator
num_get<_CharT, _InputIterator>::__do_get_signed(iter_type __b, iter_type __e,
ios_base& __iob,
ios_base::iostate& __err,
_Signed& __v) const
{
// Stage 1
int __base = this->__get_base(__iob);
// Stage 2
char_type __thousands_sep;
const int __atoms_size = 26;
#ifdef _LIBCPP_ABI_OPTIMIZED_LOCALE_NUM_GET
char_type __atoms1[__atoms_size];
const char_type *__atoms = this->__do_widen(__iob, __atoms1);
string __grouping = this->__stage2_int_prep(__iob, __thousands_sep);
#else
char_type __atoms[__atoms_size];
string __grouping = this->__stage2_int_prep(__iob, __atoms, __thousands_sep);
#endif
string __buf;
__buf.resize(__buf.capacity());
char* __a = &__buf[0];
char* __a_end = __a;
unsigned __g[__num_get_base::__num_get_buf_sz];
unsigned* __g_end = __g;
unsigned __dc = 0;
for (; __b != __e; ++__b)
{
if (__a_end == __a + __buf.size())
{
size_t __tmp = __buf.size();
__buf.resize(2*__buf.size());
__buf.resize(__buf.capacity());
__a = &__buf[0];
__a_end = __a + __tmp;
}
if (this->__stage2_int_loop(*__b, __base, __a, __a_end, __dc,
__thousands_sep, __grouping, __g, __g_end,
__atoms))
break;
}
if (__grouping.size() != 0 && __g_end-__g < __num_get_base::__num_get_buf_sz)
*__g_end++ = __dc;
// Stage 3
__v = __num_get_signed_integral<_Signed>(__a, __a_end, __err, __base);
// Digit grouping checked
__check_grouping(__grouping, __g, __g_end, __err);
// EOF checked
if (__b == __e)
__err |= ios_base::eofbit;
return __b;
}
// unsigned
template <class _CharT, class _InputIterator>
template <class _Unsigned>
_InputIterator
num_get<_CharT, _InputIterator>::__do_get_unsigned(iter_type __b, iter_type __e,
ios_base& __iob,
ios_base::iostate& __err,
_Unsigned& __v) const
{
// Stage 1
int __base = this->__get_base(__iob);
// Stage 2
char_type __thousands_sep;
const int __atoms_size = 26;
#ifdef _LIBCPP_ABI_OPTIMIZED_LOCALE_NUM_GET
char_type __atoms1[__atoms_size];
const char_type *__atoms = this->__do_widen(__iob, __atoms1);
string __grouping = this->__stage2_int_prep(__iob, __thousands_sep);
#else
char_type __atoms[__atoms_size];
string __grouping = this->__stage2_int_prep(__iob, __atoms, __thousands_sep);
#endif
string __buf;
__buf.resize(__buf.capacity());
char* __a = &__buf[0];
char* __a_end = __a;
unsigned __g[__num_get_base::__num_get_buf_sz];
unsigned* __g_end = __g;
unsigned __dc = 0;
for (; __b != __e; ++__b)
{
if (__a_end == __a + __buf.size())
{
size_t __tmp = __buf.size();
__buf.resize(2*__buf.size());
__buf.resize(__buf.capacity());
__a = &__buf[0];
__a_end = __a + __tmp;
}
if (this->__stage2_int_loop(*__b, __base, __a, __a_end, __dc,
__thousands_sep, __grouping, __g, __g_end,
__atoms))
break;
}
if (__grouping.size() != 0 && __g_end-__g < __num_get_base::__num_get_buf_sz)
*__g_end++ = __dc;
// Stage 3
__v = __num_get_unsigned_integral<_Unsigned>(__a, __a_end, __err, __base);
// Digit grouping checked
__check_grouping(__grouping, __g, __g_end, __err);
// EOF checked
if (__b == __e)
__err |= ios_base::eofbit;
return __b;
}
// floating point
template <class _CharT, class _InputIterator>
template <class _Fp>
_InputIterator
num_get<_CharT, _InputIterator>::__do_get_floating_point(iter_type __b, iter_type __e,
ios_base& __iob,
ios_base::iostate& __err,
_Fp& __v) const
{
// Stage 1, nothing to do
// Stage 2
char_type __atoms[32];
char_type __decimal_point;
char_type __thousands_sep;
string __grouping = this->__stage2_float_prep(__iob, __atoms,
__decimal_point,
__thousands_sep);
string __buf;
__buf.resize(__buf.capacity());
char* __a = &__buf[0];
char* __a_end = __a;
unsigned __g[__num_get_base::__num_get_buf_sz];
unsigned* __g_end = __g;
unsigned __dc = 0;
bool __in_units = true;
char __exp = 'E';
for (; __b != __e; ++__b)
{
if (__a_end == __a + __buf.size())
{
size_t __tmp = __buf.size();
__buf.resize(2*__buf.size());
__buf.resize(__buf.capacity());
__a = &__buf[0];
__a_end = __a + __tmp;
}
if (this->__stage2_float_loop(*__b, __in_units, __exp, __a, __a_end,
__decimal_point, __thousands_sep,
__grouping, __g, __g_end,
__dc, __atoms))
break;
}
if (__grouping.size() != 0 && __in_units && __g_end-__g < __num_get_base::__num_get_buf_sz)
*__g_end++ = __dc;
// Stage 3
__v = __num_get_float<_Fp>(__a, __a_end, __err);
// Digit grouping checked
__check_grouping(__grouping, __g, __g_end, __err);
// EOF checked
if (__b == __e)
__err |= ios_base::eofbit;
return __b;
}
template <class _CharT, class _InputIterator>
_InputIterator
num_get<_CharT, _InputIterator>::do_get(iter_type __b, iter_type __e,
ios_base& __iob,
ios_base::iostate& __err,
void*& __v) const
{
// Stage 1
int __base = 16;
// Stage 2
char_type __atoms[26];
char_type __thousands_sep = 0;
string __grouping;
use_facet<ctype<_CharT> >(__iob.getloc()).widen(__num_get_base::__src,
__num_get_base::__src + 26, __atoms);
string __buf;
__buf.resize(__buf.capacity());
char* __a = &__buf[0];
char* __a_end = __a;
unsigned __g[__num_get_base::__num_get_buf_sz];
unsigned* __g_end = __g;
unsigned __dc = 0;
for (; __b != __e; ++__b)
{
if (__a_end == __a + __buf.size())
{
size_t __tmp = __buf.size();
__buf.resize(2*__buf.size());
__buf.resize(__buf.capacity());
__a = &__buf[0];
__a_end = __a + __tmp;
}
if (this->__stage2_int_loop(*__b, __base, __a, __a_end, __dc,
__thousands_sep, __grouping,
__g, __g_end, __atoms))
break;
}
// Stage 3
__buf.resize(__a_end - __a);
if (__libcpp_sscanf_l(__buf.c_str(), _LIBCPP_GET_C_LOCALE, "%p", &__v) != 1)
__err = ios_base::failbit;
// EOF checked
if (__b == __e)
__err |= ios_base::eofbit;
return __b;
}
_LIBCPP_EXTERN_TEMPLATE2(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS num_get<char>)
_LIBCPP_EXTERN_TEMPLATE2(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS num_get<wchar_t>)
struct _LIBCPP_TYPE_VIS __num_put_base
{
protected:
static void __format_int(char* __fmt, const char* __len, bool __signd,
ios_base::fmtflags __flags);
static bool __format_float(char* __fmt, const char* __len,
ios_base::fmtflags __flags);
static char* __identify_padding(char* __nb, char* __ne,
const ios_base& __iob);
};
template <class _CharT>
struct __num_put
: protected __num_put_base
{
static void __widen_and_group_int(char* __nb, char* __np, char* __ne,
_CharT* __ob, _CharT*& __op, _CharT*& __oe,
const locale& __loc);
static void __widen_and_group_float(char* __nb, char* __np, char* __ne,
_CharT* __ob, _CharT*& __op, _CharT*& __oe,
const locale& __loc);
};
template <class _CharT>
void
__num_put<_CharT>::__widen_and_group_int(char* __nb, char* __np, char* __ne,
_CharT* __ob, _CharT*& __op, _CharT*& __oe,
const locale& __loc)
{
const ctype<_CharT>& __ct = use_facet<ctype<_CharT> > (__loc);
const numpunct<_CharT>& __npt = use_facet<numpunct<_CharT> >(__loc);
string __grouping = __npt.grouping();
if (__grouping.empty())
{
__ct.widen(__nb, __ne, __ob);
__oe = __ob + (__ne - __nb);
}
else
{
__oe = __ob;
char* __nf = __nb;
if (*__nf == '-' || *__nf == '+')
*__oe++ = __ct.widen(*__nf++);
if (__ne - __nf >= 2 && __nf[0] == '0' && (__nf[1] == 'x' ||
__nf[1] == 'X'))
{
*__oe++ = __ct.widen(*__nf++);
*__oe++ = __ct.widen(*__nf++);
}
reverse(__nf, __ne);
_CharT __thousands_sep = __npt.thousands_sep();
unsigned __dc = 0;
unsigned __dg = 0;
for (char* __p = __nf; __p < __ne; ++__p)
{
if (static_cast<unsigned>(__grouping[__dg]) > 0 &&
__dc == static_cast<unsigned>(__grouping[__dg]))
{
*__oe++ = __thousands_sep;
__dc = 0;
if (__dg < __grouping.size()-1)
++__dg;
}
*__oe++ = __ct.widen(*__p);
++__dc;
}
reverse(__ob + (__nf - __nb), __oe);
}
if (__np == __ne)
__op = __oe;
else
__op = __ob + (__np - __nb);
}
template <class _CharT>
void
__num_put<_CharT>::__widen_and_group_float(char* __nb, char* __np, char* __ne,
_CharT* __ob, _CharT*& __op, _CharT*& __oe,
const locale& __loc)
{
const ctype<_CharT>& __ct = use_facet<ctype<_CharT> > (__loc);
const numpunct<_CharT>& __npt = use_facet<numpunct<_CharT> >(__loc);
string __grouping = __npt.grouping();
__oe = __ob;
char* __nf = __nb;
if (*__nf == '-' || *__nf == '+')
*__oe++ = __ct.widen(*__nf++);
char* __ns;
if (__ne - __nf >= 2 && __nf[0] == '0' && (__nf[1] == 'x' ||
__nf[1] == 'X'))
{
*__oe++ = __ct.widen(*__nf++);
*__oe++ = __ct.widen(*__nf++);
for (__ns = __nf; __ns < __ne; ++__ns)
if (!isxdigit_l(*__ns, _LIBCPP_GET_C_LOCALE))
break;
}
else
{
for (__ns = __nf; __ns < __ne; ++__ns)
if (!isdigit_l(*__ns, _LIBCPP_GET_C_LOCALE))
break;
}
if (__grouping.empty())
{
__ct.widen(__nf, __ns, __oe);
__oe += __ns - __nf;
}
else
{
reverse(__nf, __ns);
_CharT __thousands_sep = __npt.thousands_sep();
unsigned __dc = 0;
unsigned __dg = 0;
for (char* __p = __nf; __p < __ns; ++__p)
{
if (__grouping[__dg] > 0 && __dc == static_cast<unsigned>(__grouping[__dg]))
{
*__oe++ = __thousands_sep;
__dc = 0;
if (__dg < __grouping.size()-1)
++__dg;
}
*__oe++ = __ct.widen(*__p);
++__dc;
}
reverse(__ob + (__nf - __nb), __oe);
}
for (__nf = __ns; __nf < __ne; ++__nf)
{
if (*__nf == '.')
{
*__oe++ = __npt.decimal_point();
++__nf;
break;
}
else
*__oe++ = __ct.widen(*__nf);
}
__ct.widen(__nf, __ne, __oe);
__oe += __ne - __nf;
if (__np == __ne)
__op = __oe;
else
__op = __ob + (__np - __nb);
}
_LIBCPP_EXTERN_TEMPLATE2(struct _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS __num_put<char>)
_LIBCPP_EXTERN_TEMPLATE2(struct _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS __num_put<wchar_t>)
template <class _CharT, class _OutputIterator = ostreambuf_iterator<_CharT> >
class _LIBCPP_TEMPLATE_VIS num_put
: public locale::facet,
private __num_put<_CharT>
{
public:
typedef _CharT char_type;
typedef _OutputIterator iter_type;
_LIBCPP_INLINE_VISIBILITY
explicit num_put(size_t __refs = 0)
: locale::facet(__refs) {}
_LIBCPP_INLINE_VISIBILITY
iter_type put(iter_type __s, ios_base& __iob, char_type __fl,
bool __v) const
{
return do_put(__s, __iob, __fl, __v);
}
_LIBCPP_INLINE_VISIBILITY
iter_type put(iter_type __s, ios_base& __iob, char_type __fl,
long __v) const
{
return do_put(__s, __iob, __fl, __v);
}
_LIBCPP_INLINE_VISIBILITY
iter_type put(iter_type __s, ios_base& __iob, char_type __fl,
long long __v) const
{
return do_put(__s, __iob, __fl, __v);
}
_LIBCPP_INLINE_VISIBILITY
iter_type put(iter_type __s, ios_base& __iob, char_type __fl,
unsigned long __v) const
{
return do_put(__s, __iob, __fl, __v);
}
_LIBCPP_INLINE_VISIBILITY
iter_type put(iter_type __s, ios_base& __iob, char_type __fl,
unsigned long long __v) const
{
return do_put(__s, __iob, __fl, __v);
}
_LIBCPP_INLINE_VISIBILITY
iter_type put(iter_type __s, ios_base& __iob, char_type __fl,
double __v) const
{
return do_put(__s, __iob, __fl, __v);
}
_LIBCPP_INLINE_VISIBILITY
iter_type put(iter_type __s, ios_base& __iob, char_type __fl,
long double __v) const
{
return do_put(__s, __iob, __fl, __v);
}
_LIBCPP_INLINE_VISIBILITY
iter_type put(iter_type __s, ios_base& __iob, char_type __fl,
const void* __v) const
{
return do_put(__s, __iob, __fl, __v);
}
static locale::id id;
protected:
_LIBCPP_INLINE_VISIBILITY
~num_put() {}
virtual iter_type do_put(iter_type __s, ios_base& __iob, char_type __fl,
bool __v) const;
virtual iter_type do_put(iter_type __s, ios_base& __iob, char_type __fl,
long __v) const;
virtual iter_type do_put(iter_type __s, ios_base& __iob, char_type __fl,
long long __v) const;
virtual iter_type do_put(iter_type __s, ios_base& __iob, char_type __fl,
unsigned long) const;
virtual iter_type do_put(iter_type __s, ios_base& __iob, char_type __fl,
unsigned long long) const;
virtual iter_type do_put(iter_type __s, ios_base& __iob, char_type __fl,
double __v) const;
virtual iter_type do_put(iter_type __s, ios_base& __iob, char_type __fl,
long double __v) const;
virtual iter_type do_put(iter_type __s, ios_base& __iob, char_type __fl,
const void* __v) const;
};
template <class _CharT, class _OutputIterator>
locale::id
num_put<_CharT, _OutputIterator>::id;
template <class _CharT, class _OutputIterator>
_LIBCPP_HIDDEN
_OutputIterator
__pad_and_output(_OutputIterator __s,
const _CharT* __ob, const _CharT* __op, const _CharT* __oe,
ios_base& __iob, _CharT __fl)
{
streamsize __sz = __oe - __ob;
streamsize __ns = __iob.width();
if (__ns > __sz)
__ns -= __sz;
else
__ns = 0;
for (;__ob < __op; ++__ob, ++__s)
*__s = *__ob;
for (; __ns; --__ns, ++__s)
*__s = __fl;
for (; __ob < __oe; ++__ob, ++__s)
*__s = *__ob;
__iob.width(0);
return __s;
}
template <class _CharT, class _Traits>
_LIBCPP_HIDDEN
ostreambuf_iterator<_CharT, _Traits>
__pad_and_output(ostreambuf_iterator<_CharT, _Traits> __s,
const _CharT* __ob, const _CharT* __op, const _CharT* __oe,
ios_base& __iob, _CharT __fl)
{
if (__s.__sbuf_ == nullptr)
return __s;
streamsize __sz = __oe - __ob;
streamsize __ns = __iob.width();
if (__ns > __sz)
__ns -= __sz;
else
__ns = 0;
streamsize __np = __op - __ob;
if (__np > 0)
{
if (__s.__sbuf_->sputn(__ob, __np) != __np)
{
__s.__sbuf_ = nullptr;
return __s;
}
}
if (__ns > 0)
{
basic_string<_CharT, _Traits> __sp(__ns, __fl);
if (__s.__sbuf_->sputn(__sp.data(), __ns) != __ns)
{
__s.__sbuf_ = nullptr;
return __s;
}
}
__np = __oe - __op;
if (__np > 0)
{
if (__s.__sbuf_->sputn(__op, __np) != __np)
{
__s.__sbuf_ = nullptr;
return __s;
}
}
__iob.width(0);
return __s;
}
template <class _CharT, class _OutputIterator>
_OutputIterator
num_put<_CharT, _OutputIterator>::do_put(iter_type __s, ios_base& __iob,
char_type __fl, bool __v) const
{
if ((__iob.flags() & ios_base::boolalpha) == 0)
return do_put(__s, __iob, __fl, (unsigned long)__v);
const numpunct<char_type>& __np = use_facet<numpunct<char_type> >(__iob.getloc());
typedef typename numpunct<char_type>::string_type string_type;
#if _LIBCPP_DEBUG_LEVEL >= 2
string_type __tmp(__v ? __np.truename() : __np.falsename());
string_type __nm = _VSTD::move(__tmp);
#else
string_type __nm = __v ? __np.truename() : __np.falsename();
#endif
for (typename string_type::iterator __i = __nm.begin(); __i != __nm.end(); ++__i, ++__s)
*__s = *__i;
return __s;
}
template <class _CharT, class _OutputIterator>
_OutputIterator
num_put<_CharT, _OutputIterator>::do_put(iter_type __s, ios_base& __iob,
char_type __fl, long __v) const
{
// Stage 1 - Get number in narrow char
char __fmt[6] = {'%', 0};
const char* __len = "l";
this->__format_int(__fmt+1, __len, true, __iob.flags());
const unsigned __nbuf = (numeric_limits<long>::digits / 3)
+ ((numeric_limits<long>::digits % 3) != 0)
+ ((__iob.flags() & ios_base::showbase) != 0)
+ 2;
char __nar[__nbuf];
int __nc = __libcpp_snprintf_l(__nar, sizeof(__nar), _LIBCPP_GET_C_LOCALE, __fmt, __v);
char* __ne = __nar + __nc;
char* __np = this->__identify_padding(__nar, __ne, __iob);
// Stage 2 - Widen __nar while adding thousands separators
char_type __o[2*(__nbuf-1) - 1];
char_type* __op; // pad here
char_type* __oe; // end of output
this->__widen_and_group_int(__nar, __np, __ne, __o, __op, __oe, __iob.getloc());
// [__o, __oe) contains thousands_sep'd wide number
// Stage 3 & 4
return __pad_and_output(__s, __o, __op, __oe, __iob, __fl);
}
template <class _CharT, class _OutputIterator>
_OutputIterator
num_put<_CharT, _OutputIterator>::do_put(iter_type __s, ios_base& __iob,
char_type __fl, long long __v) const
{
// Stage 1 - Get number in narrow char
char __fmt[8] = {'%', 0};
const char* __len = "ll";
this->__format_int(__fmt+1, __len, true, __iob.flags());
const unsigned __nbuf = (numeric_limits<long long>::digits / 3)
+ ((numeric_limits<long long>::digits % 3) != 0)
+ ((__iob.flags() & ios_base::showbase) != 0)
+ 2;
char __nar[__nbuf];
int __nc = __libcpp_snprintf_l(__nar, sizeof(__nar), _LIBCPP_GET_C_LOCALE, __fmt, __v);
char* __ne = __nar + __nc;
char* __np = this->__identify_padding(__nar, __ne, __iob);
// Stage 2 - Widen __nar while adding thousands separators
char_type __o[2*(__nbuf-1) - 1];
char_type* __op; // pad here
char_type* __oe; // end of output
this->__widen_and_group_int(__nar, __np, __ne, __o, __op, __oe, __iob.getloc());
// [__o, __oe) contains thousands_sep'd wide number
// Stage 3 & 4
return __pad_and_output(__s, __o, __op, __oe, __iob, __fl);
}
template <class _CharT, class _OutputIterator>
_OutputIterator
num_put<_CharT, _OutputIterator>::do_put(iter_type __s, ios_base& __iob,
char_type __fl, unsigned long __v) const
{
// Stage 1 - Get number in narrow char
char __fmt[6] = {'%', 0};
const char* __len = "l";
this->__format_int(__fmt+1, __len, false, __iob.flags());
const unsigned __nbuf = (numeric_limits<unsigned long>::digits / 3)
+ ((numeric_limits<unsigned long>::digits % 3) != 0)
+ ((__iob.flags() & ios_base::showbase) != 0)
+ 1;
char __nar[__nbuf];
int __nc = __libcpp_snprintf_l(__nar, sizeof(__nar), _LIBCPP_GET_C_LOCALE, __fmt, __v);
char* __ne = __nar + __nc;
char* __np = this->__identify_padding(__nar, __ne, __iob);
// Stage 2 - Widen __nar while adding thousands separators
char_type __o[2*(__nbuf-1) - 1];
char_type* __op; // pad here
char_type* __oe; // end of output
this->__widen_and_group_int(__nar, __np, __ne, __o, __op, __oe, __iob.getloc());
// [__o, __oe) contains thousands_sep'd wide number
// Stage 3 & 4
return __pad_and_output(__s, __o, __op, __oe, __iob, __fl);
}
template <class _CharT, class _OutputIterator>
_OutputIterator
num_put<_CharT, _OutputIterator>::do_put(iter_type __s, ios_base& __iob,
char_type __fl, unsigned long long __v) const
{
// Stage 1 - Get number in narrow char
char __fmt[8] = {'%', 0};
const char* __len = "ll";
this->__format_int(__fmt+1, __len, false, __iob.flags());
const unsigned __nbuf = (numeric_limits<unsigned long long>::digits / 3)
+ ((numeric_limits<unsigned long long>::digits % 3) != 0)
+ ((__iob.flags() & ios_base::showbase) != 0)
+ 1;
char __nar[__nbuf];
int __nc = __libcpp_snprintf_l(__nar, sizeof(__nar), _LIBCPP_GET_C_LOCALE, __fmt, __v);
char* __ne = __nar + __nc;
char* __np = this->__identify_padding(__nar, __ne, __iob);
// Stage 2 - Widen __nar while adding thousands separators
char_type __o[2*(__nbuf-1) - 1];
char_type* __op; // pad here
char_type* __oe; // end of output
this->__widen_and_group_int(__nar, __np, __ne, __o, __op, __oe, __iob.getloc());
// [__o, __oe) contains thousands_sep'd wide number
// Stage 3 & 4
return __pad_and_output(__s, __o, __op, __oe, __iob, __fl);
}
template <class _CharT, class _OutputIterator>
_OutputIterator
num_put<_CharT, _OutputIterator>::do_put(iter_type __s, ios_base& __iob,
char_type __fl, double __v) const
{
// Stage 1 - Get number in narrow char
char __fmt[8] = {'%', 0};
const char* __len = "";
bool __specify_precision = this->__format_float(__fmt+1, __len, __iob.flags());
const unsigned __nbuf = 30;
char __nar[__nbuf];
char* __nb = __nar;
int __nc;
if (__specify_precision)
__nc = __libcpp_snprintf_l(__nb, __nbuf, _LIBCPP_GET_C_LOCALE, __fmt,
(int)__iob.precision(), __v);
else
__nc = __libcpp_snprintf_l(__nb, __nbuf, _LIBCPP_GET_C_LOCALE, __fmt, __v);
unique_ptr<char, void(*)(void*)> __nbh(0, free);
if (__nc > static_cast<int>(__nbuf-1))
{
if (__specify_precision)
__nc = __libcpp_asprintf_l(&__nb, _LIBCPP_GET_C_LOCALE, __fmt, (int)__iob.precision(), __v);
else
__nc = __libcpp_asprintf_l(&__nb, _LIBCPP_GET_C_LOCALE, __fmt, __v);
if (__nb == 0)
__throw_bad_alloc();
__nbh.reset(__nb);
}
char* __ne = __nb + __nc;
char* __np = this->__identify_padding(__nb, __ne, __iob);
// Stage 2 - Widen __nar while adding thousands separators
char_type __o[2*(__nbuf-1) - 1];
char_type* __ob = __o;
unique_ptr<char_type, void(*)(void*)> __obh(0, free);
if (__nb != __nar)
{
__ob = (char_type*)malloc(2*static_cast<size_t>(__nc)*sizeof(char_type));
if (__ob == 0)
__throw_bad_alloc();
__obh.reset(__ob);
}
char_type* __op; // pad here
char_type* __oe; // end of output
this->__widen_and_group_float(__nb, __np, __ne, __ob, __op, __oe, __iob.getloc());
// [__o, __oe) contains thousands_sep'd wide number
// Stage 3 & 4
__s = __pad_and_output(__s, __ob, __op, __oe, __iob, __fl);
return __s;
}
template <class _CharT, class _OutputIterator>
_OutputIterator
num_put<_CharT, _OutputIterator>::do_put(iter_type __s, ios_base& __iob,
char_type __fl, long double __v) const
{
// Stage 1 - Get number in narrow char
char __fmt[8] = {'%', 0};
const char* __len = "L";
bool __specify_precision = this->__format_float(__fmt+1, __len, __iob.flags());
const unsigned __nbuf = 30;
char __nar[__nbuf];
char* __nb = __nar;
int __nc;
if (__specify_precision)
__nc = __libcpp_snprintf_l(__nb, __nbuf, _LIBCPP_GET_C_LOCALE, __fmt,
(int)__iob.precision(), __v);
else
__nc = __libcpp_snprintf_l(__nb, __nbuf, _LIBCPP_GET_C_LOCALE, __fmt, __v);
unique_ptr<char, void(*)(void*)> __nbh(0, free);
if (__nc > static_cast<int>(__nbuf-1))
{
if (__specify_precision)
__nc = __libcpp_asprintf_l(&__nb, _LIBCPP_GET_C_LOCALE, __fmt, (int)__iob.precision(), __v);
else
__nc = __libcpp_asprintf_l(&__nb, _LIBCPP_GET_C_LOCALE, __fmt, __v);
if (__nb == 0)
__throw_bad_alloc();
__nbh.reset(__nb);
}
char* __ne = __nb + __nc;
char* __np = this->__identify_padding(__nb, __ne, __iob);
// Stage 2 - Widen __nar while adding thousands separators
char_type __o[2*(__nbuf-1) - 1];
char_type* __ob = __o;
unique_ptr<char_type, void(*)(void*)> __obh(0, free);
if (__nb != __nar)
{
__ob = (char_type*)malloc(2*static_cast<size_t>(__nc)*sizeof(char_type));
if (__ob == 0)
__throw_bad_alloc();
__obh.reset(__ob);
}
char_type* __op; // pad here
char_type* __oe; // end of output
this->__widen_and_group_float(__nb, __np, __ne, __ob, __op, __oe, __iob.getloc());
// [__o, __oe) contains thousands_sep'd wide number
// Stage 3 & 4
__s = __pad_and_output(__s, __ob, __op, __oe, __iob, __fl);
return __s;
}
template <class _CharT, class _OutputIterator>
_OutputIterator
num_put<_CharT, _OutputIterator>::do_put(iter_type __s, ios_base& __iob,
char_type __fl, const void* __v) const
{
// Stage 1 - Get pointer in narrow char
char __fmt[6] = "%p";
const unsigned __nbuf = 20;
char __nar[__nbuf];
int __nc = __libcpp_snprintf_l(__nar, sizeof(__nar), _LIBCPP_GET_C_LOCALE, __fmt, __v);
char* __ne = __nar + __nc;
char* __np = this->__identify_padding(__nar, __ne, __iob);
// Stage 2 - Widen __nar
char_type __o[2*(__nbuf-1) - 1];
char_type* __op; // pad here
char_type* __oe; // end of output
const ctype<char_type>& __ct = use_facet<ctype<char_type> >(__iob.getloc());
__ct.widen(__nar, __ne, __o);
__oe = __o + (__ne - __nar);
if (__np == __ne)
__op = __oe;
else
__op = __o + (__np - __nar);
// [__o, __oe) contains wide number
// Stage 3 & 4
return __pad_and_output(__s, __o, __op, __oe, __iob, __fl);
}
_LIBCPP_EXTERN_TEMPLATE2(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS num_put<char>)
_LIBCPP_EXTERN_TEMPLATE2(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS num_put<wchar_t>)
template <class _CharT, class _InputIterator>
_LIBCPP_HIDDEN
int
__get_up_to_n_digits(_InputIterator& __b, _InputIterator __e,
ios_base::iostate& __err, const ctype<_CharT>& __ct, int __n)
{
// Precondition: __n >= 1
if (__b == __e)
{
__err |= ios_base::eofbit | ios_base::failbit;
return 0;
}
// get first digit
_CharT __c = *__b;
if (!__ct.is(ctype_base::digit, __c))
{
__err |= ios_base::failbit;
return 0;
}
int __r = __ct.narrow(__c, 0) - '0';
for (++__b, (void) --__n; __b != __e && __n > 0; ++__b, (void) --__n)
{
// get next digit
__c = *__b;
if (!__ct.is(ctype_base::digit, __c))
return __r;
__r = __r * 10 + __ct.narrow(__c, 0) - '0';
}
if (__b == __e)
__err |= ios_base::eofbit;
return __r;
}
class _LIBCPP_TYPE_VIS time_base
{
public:
enum dateorder {no_order, dmy, mdy, ymd, ydm};
};
template <class _CharT>
class _LIBCPP_TEMPLATE_VIS __time_get_c_storage
{
protected:
typedef basic_string<_CharT> string_type;
virtual const string_type* __weeks() const;
virtual const string_type* __months() const;
virtual const string_type* __am_pm() const;
virtual const string_type& __c() const;
virtual const string_type& __r() const;
virtual const string_type& __x() const;
virtual const string_type& __X() const;
_LIBCPP_INLINE_VISIBILITY
~__time_get_c_storage() {}
};
template <> _LIBCPP_FUNC_VIS const string* __time_get_c_storage<char>::__weeks() const;
template <> _LIBCPP_FUNC_VIS const string* __time_get_c_storage<char>::__months() const;
template <> _LIBCPP_FUNC_VIS const string* __time_get_c_storage<char>::__am_pm() const;
template <> _LIBCPP_FUNC_VIS const string& __time_get_c_storage<char>::__c() const;
template <> _LIBCPP_FUNC_VIS const string& __time_get_c_storage<char>::__r() const;
template <> _LIBCPP_FUNC_VIS const string& __time_get_c_storage<char>::__x() const;
template <> _LIBCPP_FUNC_VIS const string& __time_get_c_storage<char>::__X() const;
template <> _LIBCPP_FUNC_VIS const wstring* __time_get_c_storage<wchar_t>::__weeks() const;
template <> _LIBCPP_FUNC_VIS const wstring* __time_get_c_storage<wchar_t>::__months() const;
template <> _LIBCPP_FUNC_VIS const wstring* __time_get_c_storage<wchar_t>::__am_pm() const;
template <> _LIBCPP_FUNC_VIS const wstring& __time_get_c_storage<wchar_t>::__c() const;
template <> _LIBCPP_FUNC_VIS const wstring& __time_get_c_storage<wchar_t>::__r() const;
template <> _LIBCPP_FUNC_VIS const wstring& __time_get_c_storage<wchar_t>::__x() const;
template <> _LIBCPP_FUNC_VIS const wstring& __time_get_c_storage<wchar_t>::__X() const;
template <class _CharT, class _InputIterator = istreambuf_iterator<_CharT> >
class _LIBCPP_TEMPLATE_VIS time_get
: public locale::facet,
public time_base,
private __time_get_c_storage<_CharT>
{
public:
typedef _CharT char_type;
typedef _InputIterator iter_type;
typedef time_base::dateorder dateorder;
typedef basic_string<char_type> string_type;
_LIBCPP_INLINE_VISIBILITY
explicit time_get(size_t __refs = 0)
: locale::facet(__refs) {}
_LIBCPP_INLINE_VISIBILITY
dateorder date_order() const
{
return this->do_date_order();
}
_LIBCPP_INLINE_VISIBILITY
iter_type get_time(iter_type __b, iter_type __e, ios_base& __iob,
ios_base::iostate& __err, tm* __tm) const
{
return do_get_time(__b, __e, __iob, __err, __tm);
}
_LIBCPP_INLINE_VISIBILITY
iter_type get_date(iter_type __b, iter_type __e, ios_base& __iob,
ios_base::iostate& __err, tm* __tm) const
{
return do_get_date(__b, __e, __iob, __err, __tm);
}
_LIBCPP_INLINE_VISIBILITY
iter_type get_weekday(iter_type __b, iter_type __e, ios_base& __iob,
ios_base::iostate& __err, tm* __tm) const
{
return do_get_weekday(__b, __e, __iob, __err, __tm);
}
_LIBCPP_INLINE_VISIBILITY
iter_type get_monthname(iter_type __b, iter_type __e, ios_base& __iob,
ios_base::iostate& __err, tm* __tm) const
{
return do_get_monthname(__b, __e, __iob, __err, __tm);
}
_LIBCPP_INLINE_VISIBILITY
iter_type get_year(iter_type __b, iter_type __e, ios_base& __iob,
ios_base::iostate& __err, tm* __tm) const
{
return do_get_year(__b, __e, __iob, __err, __tm);
}
_LIBCPP_INLINE_VISIBILITY
iter_type get(iter_type __b, iter_type __e, ios_base& __iob,
ios_base::iostate& __err, tm *__tm,
char __fmt, char __mod = 0) const
{
return do_get(__b, __e, __iob, __err, __tm, __fmt, __mod);
}
iter_type get(iter_type __b, iter_type __e, ios_base& __iob,
ios_base::iostate& __err, tm* __tm,
const char_type* __fmtb, const char_type* __fmte) const;
static locale::id id;
protected:
_LIBCPP_INLINE_VISIBILITY
~time_get() {}
virtual dateorder do_date_order() const;
virtual iter_type do_get_time(iter_type __b, iter_type __e, ios_base& __iob,
ios_base::iostate& __err, tm* __tm) const;
virtual iter_type do_get_date(iter_type __b, iter_type __e, ios_base& __iob,
ios_base::iostate& __err, tm* __tm) const;
virtual iter_type do_get_weekday(iter_type __b, iter_type __e, ios_base& __iob,
ios_base::iostate& __err, tm* __tm) const;
virtual iter_type do_get_monthname(iter_type __b, iter_type __e, ios_base& __iob,
ios_base::iostate& __err, tm* __tm) const;
virtual iter_type do_get_year(iter_type __b, iter_type __e, ios_base& __iob,
ios_base::iostate& __err, tm* __tm) const;
virtual iter_type do_get(iter_type __b, iter_type __e, ios_base& __iob,
ios_base::iostate& __err, tm* __tm,
char __fmt, char __mod) const;
private:
void __get_white_space(iter_type& __b, iter_type __e,
ios_base::iostate& __err, const ctype<char_type>& __ct) const;
void __get_percent(iter_type& __b, iter_type __e, ios_base::iostate& __err,
const ctype<char_type>& __ct) const;
void __get_weekdayname(int& __m,
iter_type& __b, iter_type __e,
ios_base::iostate& __err,
const ctype<char_type>& __ct) const;
void __get_monthname(int& __m,
iter_type& __b, iter_type __e,
ios_base::iostate& __err,
const ctype<char_type>& __ct) const;
void __get_day(int& __d,
iter_type& __b, iter_type __e,
ios_base::iostate& __err,
const ctype<char_type>& __ct) const;
void __get_month(int& __m,
iter_type& __b, iter_type __e,
ios_base::iostate& __err,
const ctype<char_type>& __ct) const;
void __get_year(int& __y,
iter_type& __b, iter_type __e,
ios_base::iostate& __err,
const ctype<char_type>& __ct) const;
void __get_year4(int& __y,
iter_type& __b, iter_type __e,
ios_base::iostate& __err,
const ctype<char_type>& __ct) const;
void __get_hour(int& __d,
iter_type& __b, iter_type __e,
ios_base::iostate& __err,
const ctype<char_type>& __ct) const;
void __get_12_hour(int& __h,
iter_type& __b, iter_type __e,
ios_base::iostate& __err,
const ctype<char_type>& __ct) const;
void __get_am_pm(int& __h,
iter_type& __b, iter_type __e,
ios_base::iostate& __err,
const ctype<char_type>& __ct) const;
void __get_minute(int& __m,
iter_type& __b, iter_type __e,
ios_base::iostate& __err,
const ctype<char_type>& __ct) const;
void __get_second(int& __s,
iter_type& __b, iter_type __e,
ios_base::iostate& __err,
const ctype<char_type>& __ct) const;
void __get_weekday(int& __w,
iter_type& __b, iter_type __e,
ios_base::iostate& __err,
const ctype<char_type>& __ct) const;
void __get_day_year_num(int& __w,
iter_type& __b, iter_type __e,
ios_base::iostate& __err,
const ctype<char_type>& __ct) const;
};
template <class _CharT, class _InputIterator>
locale::id
time_get<_CharT, _InputIterator>::id;
// time_get primitives
template <class _CharT, class _InputIterator>
void
time_get<_CharT, _InputIterator>::__get_weekdayname(int& __w,
iter_type& __b, iter_type __e,
ios_base::iostate& __err,
const ctype<char_type>& __ct) const
{
// Note: ignoring case comes from the POSIX strptime spec
const string_type* __wk = this->__weeks();
ptrdiff_t __i = __scan_keyword(__b, __e, __wk, __wk+14, __ct, __err, false) - __wk;
if (__i < 14)
__w = __i % 7;
}
template <class _CharT, class _InputIterator>
void
time_get<_CharT, _InputIterator>::__get_monthname(int& __m,
iter_type& __b, iter_type __e,
ios_base::iostate& __err,
const ctype<char_type>& __ct) const
{
// Note: ignoring case comes from the POSIX strptime spec
const string_type* __month = this->__months();
ptrdiff_t __i = __scan_keyword(__b, __e, __month, __month+24, __ct, __err, false) - __month;
if (__i < 24)
__m = __i % 12;
}
template <class _CharT, class _InputIterator>
void
time_get<_CharT, _InputIterator>::__get_day(int& __d,
iter_type& __b, iter_type __e,
ios_base::iostate& __err,
const ctype<char_type>& __ct) const
{
int __t = __get_up_to_n_digits(__b, __e, __err, __ct, 2);
if (!(__err & ios_base::failbit) && 1 <= __t && __t <= 31)
__d = __t;
else
__err |= ios_base::failbit;
}
template <class _CharT, class _InputIterator>
void
time_get<_CharT, _InputIterator>::__get_month(int& __m,
iter_type& __b, iter_type __e,
ios_base::iostate& __err,
const ctype<char_type>& __ct) const
{
int __t = __get_up_to_n_digits(__b, __e, __err, __ct, 2) - 1;
if (!(__err & ios_base::failbit) && __t <= 11)
__m = __t;
else
__err |= ios_base::failbit;
}
template <class _CharT, class _InputIterator>
void
time_get<_CharT, _InputIterator>::__get_year(int& __y,
iter_type& __b, iter_type __e,
ios_base::iostate& __err,
const ctype<char_type>& __ct) const
{
int __t = __get_up_to_n_digits(__b, __e, __err, __ct, 4);
if (!(__err & ios_base::failbit))
{
if (__t < 69)
__t += 2000;
else if (69 <= __t && __t <= 99)
__t += 1900;
__y = __t - 1900;
}
}
template <class _CharT, class _InputIterator>
void
time_get<_CharT, _InputIterator>::__get_year4(int& __y,
iter_type& __b, iter_type __e,
ios_base::iostate& __err,
const ctype<char_type>& __ct) const
{
int __t = __get_up_to_n_digits(__b, __e, __err, __ct, 4);
if (!(__err & ios_base::failbit))
__y = __t - 1900;
}
template <class _CharT, class _InputIterator>
void
time_get<_CharT, _InputIterator>::__get_hour(int& __h,
iter_type& __b, iter_type __e,
ios_base::iostate& __err,
const ctype<char_type>& __ct) const
{
int __t = __get_up_to_n_digits(__b, __e, __err, __ct, 2);
if (!(__err & ios_base::failbit) && __t <= 23)
__h = __t;
else
__err |= ios_base::failbit;
}
template <class _CharT, class _InputIterator>
void
time_get<_CharT, _InputIterator>::__get_12_hour(int& __h,
iter_type& __b, iter_type __e,
ios_base::iostate& __err,
const ctype<char_type>& __ct) const
{
int __t = __get_up_to_n_digits(__b, __e, __err, __ct, 2);
if (!(__err & ios_base::failbit) && 1 <= __t && __t <= 12)
__h = __t;
else
__err |= ios_base::failbit;
}
template <class _CharT, class _InputIterator>
void
time_get<_CharT, _InputIterator>::__get_minute(int& __m,
iter_type& __b, iter_type __e,
ios_base::iostate& __err,
const ctype<char_type>& __ct) const
{
int __t = __get_up_to_n_digits(__b, __e, __err, __ct, 2);
if (!(__err & ios_base::failbit) && __t <= 59)
__m = __t;
else
__err |= ios_base::failbit;
}
template <class _CharT, class _InputIterator>
void
time_get<_CharT, _InputIterator>::__get_second(int& __s,
iter_type& __b, iter_type __e,
ios_base::iostate& __err,
const ctype<char_type>& __ct) const
{
int __t = __get_up_to_n_digits(__b, __e, __err, __ct, 2);
if (!(__err & ios_base::failbit) && __t <= 60)
__s = __t;
else
__err |= ios_base::failbit;
}
template <class _CharT, class _InputIterator>
void
time_get<_CharT, _InputIterator>::__get_weekday(int& __w,
iter_type& __b, iter_type __e,
ios_base::iostate& __err,
const ctype<char_type>& __ct) const
{
int __t = __get_up_to_n_digits(__b, __e, __err, __ct, 1);
if (!(__err & ios_base::failbit) && __t <= 6)
__w = __t;
else
__err |= ios_base::failbit;
}
template <class _CharT, class _InputIterator>
void
time_get<_CharT, _InputIterator>::__get_day_year_num(int& __d,
iter_type& __b, iter_type __e,
ios_base::iostate& __err,
const ctype<char_type>& __ct) const
{
int __t = __get_up_to_n_digits(__b, __e, __err, __ct, 3);
if (!(__err & ios_base::failbit) && __t <= 365)
__d = __t;
else
__err |= ios_base::failbit;
}
template <class _CharT, class _InputIterator>
void
time_get<_CharT, _InputIterator>::__get_white_space(iter_type& __b, iter_type __e,
ios_base::iostate& __err,
const ctype<char_type>& __ct) const
{
for (; __b != __e && __ct.is(ctype_base::space, *__b); ++__b)
;
if (__b == __e)
__err |= ios_base::eofbit;
}
template <class _CharT, class _InputIterator>
void
time_get<_CharT, _InputIterator>::__get_am_pm(int& __h,
iter_type& __b, iter_type __e,
ios_base::iostate& __err,
const ctype<char_type>& __ct) const
{
const string_type* __ap = this->__am_pm();
if (__ap[0].size() + __ap[1].size() == 0)
{
__err |= ios_base::failbit;
return;
}
ptrdiff_t __i = __scan_keyword(__b, __e, __ap, __ap+2, __ct, __err, false) - __ap;
if (__i == 0 && __h == 12)
__h = 0;
else if (__i == 1 && __h < 12)
__h += 12;
}
template <class _CharT, class _InputIterator>
void
time_get<_CharT, _InputIterator>::__get_percent(iter_type& __b, iter_type __e,
ios_base::iostate& __err,
const ctype<char_type>& __ct) const
{
if (__b == __e)
{
__err |= ios_base::eofbit | ios_base::failbit;
return;
}
if (__ct.narrow(*__b, 0) != '%')
__err |= ios_base::failbit;
else if(++__b == __e)
__err |= ios_base::eofbit;
}
// time_get end primitives
template <class _CharT, class _InputIterator>
_InputIterator
time_get<_CharT, _InputIterator>::get(iter_type __b, iter_type __e,
ios_base& __iob,
ios_base::iostate& __err, tm* __tm,
const char_type* __fmtb, const char_type* __fmte) const
{
const ctype<char_type>& __ct = use_facet<ctype<char_type> >(__iob.getloc());
__err = ios_base::goodbit;
while (__fmtb != __fmte && __err == ios_base::goodbit)
{
if (__b == __e)
{
__err = ios_base::failbit;
break;
}
if (__ct.narrow(*__fmtb, 0) == '%')
{
if (++__fmtb == __fmte)
{
__err = ios_base::failbit;
break;
}
char __cmd = __ct.narrow(*__fmtb, 0);
char __opt = '\0';
if (__cmd == 'E' || __cmd == '0')
{
if (++__fmtb == __fmte)
{
__err = ios_base::failbit;
break;
}
__opt = __cmd;
__cmd = __ct.narrow(*__fmtb, 0);
}
__b = do_get(__b, __e, __iob, __err, __tm, __cmd, __opt);
++__fmtb;
}
else if (__ct.is(ctype_base::space, *__fmtb))
{
for (++__fmtb; __fmtb != __fmte && __ct.is(ctype_base::space, *__fmtb); ++__fmtb)
;
for ( ; __b != __e && __ct.is(ctype_base::space, *__b); ++__b)
;
}
else if (__ct.toupper(*__b) == __ct.toupper(*__fmtb))
{
++__b;
++__fmtb;
}
else
__err = ios_base::failbit;
}
if (__b == __e)
__err |= ios_base::eofbit;
return __b;
}
template <class _CharT, class _InputIterator>
typename time_get<_CharT, _InputIterator>::dateorder
time_get<_CharT, _InputIterator>::do_date_order() const
{
return mdy;
}
template <class _CharT, class _InputIterator>
_InputIterator
time_get<_CharT, _InputIterator>::do_get_time(iter_type __b, iter_type __e,
ios_base& __iob,
ios_base::iostate& __err,
tm* __tm) const
{
const char_type __fmt[] = {'%', 'H', ':', '%', 'M', ':', '%', 'S'};
return get(__b, __e, __iob, __err, __tm, __fmt, __fmt + sizeof(__fmt)/sizeof(__fmt[0]));
}
template <class _CharT, class _InputIterator>
_InputIterator
time_get<_CharT, _InputIterator>::do_get_date(iter_type __b, iter_type __e,
ios_base& __iob,
ios_base::iostate& __err,
tm* __tm) const
{
const string_type& __fmt = this->__x();
return get(__b, __e, __iob, __err, __tm, __fmt.data(), __fmt.data() + __fmt.size());
}
template <class _CharT, class _InputIterator>
_InputIterator
time_get<_CharT, _InputIterator>::do_get_weekday(iter_type __b, iter_type __e,
ios_base& __iob,
ios_base::iostate& __err,
tm* __tm) const
{
const ctype<char_type>& __ct = use_facet<ctype<char_type> >(__iob.getloc());
__get_weekdayname(__tm->tm_wday, __b, __e, __err, __ct);
return __b;
}
template <class _CharT, class _InputIterator>
_InputIterator
time_get<_CharT, _InputIterator>::do_get_monthname(iter_type __b, iter_type __e,
ios_base& __iob,
ios_base::iostate& __err,
tm* __tm) const
{
const ctype<char_type>& __ct = use_facet<ctype<char_type> >(__iob.getloc());
__get_monthname(__tm->tm_mon, __b, __e, __err, __ct);
return __b;
}
template <class _CharT, class _InputIterator>
_InputIterator
time_get<_CharT, _InputIterator>::do_get_year(iter_type __b, iter_type __e,
ios_base& __iob,
ios_base::iostate& __err,
tm* __tm) const
{
const ctype<char_type>& __ct = use_facet<ctype<char_type> >(__iob.getloc());
__get_year(__tm->tm_year, __b, __e, __err, __ct);
return __b;
}
template <class _CharT, class _InputIterator>
_InputIterator
time_get<_CharT, _InputIterator>::do_get(iter_type __b, iter_type __e,
ios_base& __iob,
ios_base::iostate& __err, tm* __tm,
char __fmt, char) const
{
__err = ios_base::goodbit;
const ctype<char_type>& __ct = use_facet<ctype<char_type> >(__iob.getloc());
switch (__fmt)
{
case 'a':
case 'A':
__get_weekdayname(__tm->tm_wday, __b, __e, __err, __ct);
break;
case 'b':
case 'B':
case 'h':
__get_monthname(__tm->tm_mon, __b, __e, __err, __ct);
break;
case 'c':
{
const string_type& __fm = this->__c();
__b = get(__b, __e, __iob, __err, __tm, __fm.data(), __fm.data() + __fm.size());
}
break;
case 'd':
case 'e':
__get_day(__tm->tm_mday, __b, __e, __err, __ct);
break;
case 'D':
{
const char_type __fm[] = {'%', 'm', '/', '%', 'd', '/', '%', 'y'};
__b = get(__b, __e, __iob, __err, __tm, __fm, __fm + sizeof(__fm)/sizeof(__fm[0]));
}
break;
case 'F':
{
const char_type __fm[] = {'%', 'Y', '-', '%', 'm', '-', '%', 'd'};
__b = get(__b, __e, __iob, __err, __tm, __fm, __fm + sizeof(__fm)/sizeof(__fm[0]));
}
break;
case 'H':
__get_hour(__tm->tm_hour, __b, __e, __err, __ct);
break;
case 'I':
__get_12_hour(__tm->tm_hour, __b, __e, __err, __ct);
break;
case 'j':
__get_day_year_num(__tm->tm_yday, __b, __e, __err, __ct);
break;
case 'm':
__get_month(__tm->tm_mon, __b, __e, __err, __ct);
break;
case 'M':
__get_minute(__tm->tm_min, __b, __e, __err, __ct);
break;
case 'n':
case 't':
__get_white_space(__b, __e, __err, __ct);
break;
case 'p':
__get_am_pm(__tm->tm_hour, __b, __e, __err, __ct);
break;
case 'r':
{
const char_type __fm[] = {'%', 'I', ':', '%', 'M', ':', '%', 'S', ' ', '%', 'p'};
__b = get(__b, __e, __iob, __err, __tm, __fm, __fm + sizeof(__fm)/sizeof(__fm[0]));
}
break;
case 'R':
{
const char_type __fm[] = {'%', 'H', ':', '%', 'M'};
__b = get(__b, __e, __iob, __err, __tm, __fm, __fm + sizeof(__fm)/sizeof(__fm[0]));
}
break;
case 'S':
__get_second(__tm->tm_sec, __b, __e, __err, __ct);
break;
case 'T':
{
const char_type __fm[] = {'%', 'H', ':', '%', 'M', ':', '%', 'S'};
__b = get(__b, __e, __iob, __err, __tm, __fm, __fm + sizeof(__fm)/sizeof(__fm[0]));
}
break;
case 'w':
__get_weekday(__tm->tm_wday, __b, __e, __err, __ct);
break;
case 'x':
return do_get_date(__b, __e, __iob, __err, __tm);
case 'X':
{
const string_type& __fm = this->__X();
__b = get(__b, __e, __iob, __err, __tm, __fm.data(), __fm.data() + __fm.size());
}
break;
case 'y':
__get_year(__tm->tm_year, __b, __e, __err, __ct);
break;
case 'Y':
__get_year4(__tm->tm_year, __b, __e, __err, __ct);
break;
case '%':
__get_percent(__b, __e, __err, __ct);
break;
default:
__err |= ios_base::failbit;
}
return __b;
}
_LIBCPP_EXTERN_TEMPLATE2(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS time_get<char>)
_LIBCPP_EXTERN_TEMPLATE2(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS time_get<wchar_t>)
class _LIBCPP_TYPE_VIS __time_get
{
protected:
locale_t __loc_;
__time_get(const char* __nm);
__time_get(const string& __nm);
~__time_get();
};
template <class _CharT>
class _LIBCPP_TEMPLATE_VIS __time_get_storage
: public __time_get
{
protected:
typedef basic_string<_CharT> string_type;
string_type __weeks_[14];
string_type __months_[24];
string_type __am_pm_[2];
string_type __c_;
string_type __r_;
string_type __x_;
string_type __X_;
explicit __time_get_storage(const char* __nm);
explicit __time_get_storage(const string& __nm);
_LIBCPP_INLINE_VISIBILITY ~__time_get_storage() {}
time_base::dateorder __do_date_order() const;
private:
void init(const ctype<_CharT>&);
string_type __analyze(char __fmt, const ctype<_CharT>&);
};
#define _LIBCPP_TIME_GET_STORAGE_EXPLICIT_INSTANTIATION(_CharT) \
template <> _LIBCPP_FUNC_VIS time_base::dateorder __time_get_storage<_CharT>::__do_date_order() const; \
template <> _LIBCPP_FUNC_VIS __time_get_storage<_CharT>::__time_get_storage(const char*); \
template <> _LIBCPP_FUNC_VIS __time_get_storage<_CharT>::__time_get_storage(const string&); \
template <> _LIBCPP_FUNC_VIS void __time_get_storage<_CharT>::init(const ctype<_CharT>&); \
template <> _LIBCPP_FUNC_VIS __time_get_storage<_CharT>::string_type __time_get_storage<_CharT>::__analyze(char, const ctype<_CharT>&); \
extern template _LIBCPP_FUNC_VIS time_base::dateorder __time_get_storage<_CharT>::__do_date_order() const; \
extern template _LIBCPP_FUNC_VIS __time_get_storage<_CharT>::__time_get_storage(const char*); \
extern template _LIBCPP_FUNC_VIS __time_get_storage<_CharT>::__time_get_storage(const string&); \
extern template _LIBCPP_FUNC_VIS void __time_get_storage<_CharT>::init(const ctype<_CharT>&); \
extern template _LIBCPP_FUNC_VIS __time_get_storage<_CharT>::string_type __time_get_storage<_CharT>::__analyze(char, const ctype<_CharT>&); \
/**/
_LIBCPP_TIME_GET_STORAGE_EXPLICIT_INSTANTIATION(char)
_LIBCPP_TIME_GET_STORAGE_EXPLICIT_INSTANTIATION(wchar_t)
#undef _LIBCPP_TIME_GET_STORAGE_EXPLICIT_INSTANTIATION
template <class _CharT, class _InputIterator = istreambuf_iterator<_CharT> >
class _LIBCPP_TEMPLATE_VIS time_get_byname
: public time_get<_CharT, _InputIterator>,
private __time_get_storage<_CharT>
{
public:
typedef time_base::dateorder dateorder;
typedef _InputIterator iter_type;
typedef _CharT char_type;
typedef basic_string<char_type> string_type;
_LIBCPP_INLINE_VISIBILITY
explicit time_get_byname(const char* __nm, size_t __refs = 0)
: time_get<_CharT, _InputIterator>(__refs),
__time_get_storage<_CharT>(__nm) {}
_LIBCPP_INLINE_VISIBILITY
explicit time_get_byname(const string& __nm, size_t __refs = 0)
: time_get<_CharT, _InputIterator>(__refs),
__time_get_storage<_CharT>(__nm) {}
protected:
_LIBCPP_INLINE_VISIBILITY
~time_get_byname() {}
_LIBCPP_INLINE_VISIBILITY
virtual dateorder do_date_order() const {return this->__do_date_order();}
private:
_LIBCPP_INLINE_VISIBILITY
virtual const string_type* __weeks() const {return this->__weeks_;}
_LIBCPP_INLINE_VISIBILITY
virtual const string_type* __months() const {return this->__months_;}
_LIBCPP_INLINE_VISIBILITY
virtual const string_type* __am_pm() const {return this->__am_pm_;}
_LIBCPP_INLINE_VISIBILITY
virtual const string_type& __c() const {return this->__c_;}
_LIBCPP_INLINE_VISIBILITY
virtual const string_type& __r() const {return this->__r_;}
_LIBCPP_INLINE_VISIBILITY
virtual const string_type& __x() const {return this->__x_;}
_LIBCPP_INLINE_VISIBILITY
virtual const string_type& __X() const {return this->__X_;}
};
_LIBCPP_EXTERN_TEMPLATE2(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS time_get_byname<char>)
_LIBCPP_EXTERN_TEMPLATE2(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS time_get_byname<wchar_t>)
class _LIBCPP_TYPE_VIS __time_put
{
locale_t __loc_;
protected:
_LIBCPP_INLINE_VISIBILITY __time_put() : __loc_(_LIBCPP_GET_C_LOCALE) {}
__time_put(const char* __nm);
__time_put(const string& __nm);
~__time_put();
void __do_put(char* __nb, char*& __ne, const tm* __tm,
char __fmt, char __mod) const;
void __do_put(wchar_t* __wb, wchar_t*& __we, const tm* __tm,
char __fmt, char __mod) const;
};
template <class _CharT, class _OutputIterator = ostreambuf_iterator<_CharT> >
class _LIBCPP_TEMPLATE_VIS time_put
: public locale::facet,
private __time_put
{
public:
typedef _CharT char_type;
typedef _OutputIterator iter_type;
_LIBCPP_INLINE_VISIBILITY
explicit time_put(size_t __refs = 0)
: locale::facet(__refs) {}
iter_type put(iter_type __s, ios_base& __iob, char_type __fl, const tm* __tm,
const char_type* __pb, const char_type* __pe) const;
_LIBCPP_INLINE_VISIBILITY
iter_type put(iter_type __s, ios_base& __iob, char_type __fl,
const tm* __tm, char __fmt, char __mod = 0) const
{
return do_put(__s, __iob, __fl, __tm, __fmt, __mod);
}
static locale::id id;
protected:
_LIBCPP_INLINE_VISIBILITY
~time_put() {}
virtual iter_type do_put(iter_type __s, ios_base&, char_type, const tm* __tm,
char __fmt, char __mod) const;
_LIBCPP_INLINE_VISIBILITY
explicit time_put(const char* __nm, size_t __refs)
: locale::facet(__refs),
__time_put(__nm) {}
_LIBCPP_INLINE_VISIBILITY
explicit time_put(const string& __nm, size_t __refs)
: locale::facet(__refs),
__time_put(__nm) {}
};
template <class _CharT, class _OutputIterator>
locale::id
time_put<_CharT, _OutputIterator>::id;
template <class _CharT, class _OutputIterator>
_OutputIterator
time_put<_CharT, _OutputIterator>::put(iter_type __s, ios_base& __iob,
char_type __fl, const tm* __tm,
const char_type* __pb,
const char_type* __pe) const
{
const ctype<char_type>& __ct = use_facet<ctype<char_type> >(__iob.getloc());
for (; __pb != __pe; ++__pb)
{
if (__ct.narrow(*__pb, 0) == '%')
{
if (++__pb == __pe)
{
*__s++ = __pb[-1];
break;
}
char __mod = 0;
char __fmt = __ct.narrow(*__pb, 0);
if (__fmt == 'E' || __fmt == 'O')
{
if (++__pb == __pe)
{
*__s++ = __pb[-2];
*__s++ = __pb[-1];
break;
}
__mod = __fmt;
__fmt = __ct.narrow(*__pb, 0);
}
__s = do_put(__s, __iob, __fl, __tm, __fmt, __mod);
}
else
*__s++ = *__pb;
}
return __s;
}
template <class _CharT, class _OutputIterator>
_OutputIterator
time_put<_CharT, _OutputIterator>::do_put(iter_type __s, ios_base&,
char_type, const tm* __tm,
char __fmt, char __mod) const
{
char_type __nar[100];
char_type* __nb = __nar;
char_type* __ne = __nb + 100;
__do_put(__nb, __ne, __tm, __fmt, __mod);
return _VSTD::copy(__nb, __ne, __s);
}
_LIBCPP_EXTERN_TEMPLATE2(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS time_put<char>)
_LIBCPP_EXTERN_TEMPLATE2(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS time_put<wchar_t>)
template <class _CharT, class _OutputIterator = ostreambuf_iterator<_CharT> >
class _LIBCPP_TEMPLATE_VIS time_put_byname
: public time_put<_CharT, _OutputIterator>
{
public:
_LIBCPP_INLINE_VISIBILITY
explicit time_put_byname(const char* __nm, size_t __refs = 0)
: time_put<_CharT, _OutputIterator>(__nm, __refs) {}
_LIBCPP_INLINE_VISIBILITY
explicit time_put_byname(const string& __nm, size_t __refs = 0)
: time_put<_CharT, _OutputIterator>(__nm, __refs) {}
protected:
_LIBCPP_INLINE_VISIBILITY
~time_put_byname() {}
};
_LIBCPP_EXTERN_TEMPLATE2(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS time_put_byname<char>)
_LIBCPP_EXTERN_TEMPLATE2(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS time_put_byname<wchar_t>)
// money_base
class _LIBCPP_TYPE_VIS money_base
{
public:
enum part {none, space, symbol, sign, value};
struct pattern {char field[4];};
_LIBCPP_INLINE_VISIBILITY money_base() {}
};
// moneypunct
template <class _CharT, bool _International = false>
class _LIBCPP_TEMPLATE_VIS moneypunct
: public locale::facet,
public money_base
{
public:
typedef _CharT char_type;
typedef basic_string<char_type> string_type;
_LIBCPP_INLINE_VISIBILITY
explicit moneypunct(size_t __refs = 0)
: locale::facet(__refs) {}
_LIBCPP_INLINE_VISIBILITY char_type decimal_point() const {return do_decimal_point();}
_LIBCPP_INLINE_VISIBILITY char_type thousands_sep() const {return do_thousands_sep();}
_LIBCPP_INLINE_VISIBILITY string grouping() const {return do_grouping();}
_LIBCPP_INLINE_VISIBILITY string_type curr_symbol() const {return do_curr_symbol();}
_LIBCPP_INLINE_VISIBILITY string_type positive_sign() const {return do_positive_sign();}
_LIBCPP_INLINE_VISIBILITY string_type negative_sign() const {return do_negative_sign();}
_LIBCPP_INLINE_VISIBILITY int frac_digits() const {return do_frac_digits();}
_LIBCPP_INLINE_VISIBILITY pattern pos_format() const {return do_pos_format();}
_LIBCPP_INLINE_VISIBILITY pattern neg_format() const {return do_neg_format();}
static locale::id id;
static const bool intl = _International;
protected:
_LIBCPP_INLINE_VISIBILITY
~moneypunct() {}
virtual char_type do_decimal_point() const {return numeric_limits<char_type>::max();}
virtual char_type do_thousands_sep() const {return numeric_limits<char_type>::max();}
virtual string do_grouping() const {return string();}
virtual string_type do_curr_symbol() const {return string_type();}
virtual string_type do_positive_sign() const {return string_type();}
virtual string_type do_negative_sign() const {return string_type(1, '-');}
virtual int do_frac_digits() const {return 0;}
virtual pattern do_pos_format() const
{pattern __p = {{symbol, sign, none, value}}; return __p;}
virtual pattern do_neg_format() const
{pattern __p = {{symbol, sign, none, value}}; return __p;}
};
template <class _CharT, bool _International>
locale::id
moneypunct<_CharT, _International>::id;
template <class _CharT, bool _International>
const bool
moneypunct<_CharT, _International>::intl;
_LIBCPP_EXTERN_TEMPLATE2(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS moneypunct<char, false>)
_LIBCPP_EXTERN_TEMPLATE2(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS moneypunct<char, true>)
_LIBCPP_EXTERN_TEMPLATE2(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS moneypunct<wchar_t, false>)
_LIBCPP_EXTERN_TEMPLATE2(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS moneypunct<wchar_t, true>)
// moneypunct_byname
template <class _CharT, bool _International = false>
class _LIBCPP_TEMPLATE_VIS moneypunct_byname
: public moneypunct<_CharT, _International>
{
public:
typedef money_base::pattern pattern;
typedef _CharT char_type;
typedef basic_string<char_type> string_type;
_LIBCPP_INLINE_VISIBILITY
explicit moneypunct_byname(const char* __nm, size_t __refs = 0)
: moneypunct<_CharT, _International>(__refs) {init(__nm);}
_LIBCPP_INLINE_VISIBILITY
explicit moneypunct_byname(const string& __nm, size_t __refs = 0)
: moneypunct<_CharT, _International>(__refs) {init(__nm.c_str());}
protected:
_LIBCPP_INLINE_VISIBILITY
~moneypunct_byname() {}
virtual char_type do_decimal_point() const {return __decimal_point_;}
virtual char_type do_thousands_sep() const {return __thousands_sep_;}
virtual string do_grouping() const {return __grouping_;}
virtual string_type do_curr_symbol() const {return __curr_symbol_;}
virtual string_type do_positive_sign() const {return __positive_sign_;}
virtual string_type do_negative_sign() const {return __negative_sign_;}
virtual int do_frac_digits() const {return __frac_digits_;}
virtual pattern do_pos_format() const {return __pos_format_;}
virtual pattern do_neg_format() const {return __neg_format_;}
private:
char_type __decimal_point_;
char_type __thousands_sep_;
string __grouping_;
string_type __curr_symbol_;
string_type __positive_sign_;
string_type __negative_sign_;
int __frac_digits_;
pattern __pos_format_;
pattern __neg_format_;
void init(const char*);
};
template<> _LIBCPP_FUNC_VIS void moneypunct_byname<char, false>::init(const char*);
template<> _LIBCPP_FUNC_VIS void moneypunct_byname<char, true>::init(const char*);
template<> _LIBCPP_FUNC_VIS void moneypunct_byname<wchar_t, false>::init(const char*);
template<> _LIBCPP_FUNC_VIS void moneypunct_byname<wchar_t, true>::init(const char*);
_LIBCPP_EXTERN_TEMPLATE2(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS moneypunct_byname<char, false>)
_LIBCPP_EXTERN_TEMPLATE2(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS moneypunct_byname<char, true>)
_LIBCPP_EXTERN_TEMPLATE2(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS moneypunct_byname<wchar_t, false>)
_LIBCPP_EXTERN_TEMPLATE2(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS moneypunct_byname<wchar_t, true>)
// money_get
template <class _CharT>
class __money_get
{
protected:
typedef _CharT char_type;
typedef basic_string<char_type> string_type;
_LIBCPP_INLINE_VISIBILITY __money_get() {}
static void __gather_info(bool __intl, const locale& __loc,
money_base::pattern& __pat, char_type& __dp,
char_type& __ts, string& __grp,
string_type& __sym, string_type& __psn,
string_type& __nsn, int& __fd);
};
template <class _CharT>
void
__money_get<_CharT>::__gather_info(bool __intl, const locale& __loc,
money_base::pattern& __pat, char_type& __dp,
char_type& __ts, string& __grp,
string_type& __sym, string_type& __psn,
string_type& __nsn, int& __fd)
{
if (__intl)
{
const moneypunct<char_type, true>& __mp =
use_facet<moneypunct<char_type, true> >(__loc);
__pat = __mp.neg_format();
__nsn = __mp.negative_sign();
__psn = __mp.positive_sign();
__dp = __mp.decimal_point();
__ts = __mp.thousands_sep();
__grp = __mp.grouping();
__sym = __mp.curr_symbol();
__fd = __mp.frac_digits();
}
else
{
const moneypunct<char_type, false>& __mp =
use_facet<moneypunct<char_type, false> >(__loc);
__pat = __mp.neg_format();
__nsn = __mp.negative_sign();
__psn = __mp.positive_sign();
__dp = __mp.decimal_point();
__ts = __mp.thousands_sep();
__grp = __mp.grouping();
__sym = __mp.curr_symbol();
__fd = __mp.frac_digits();
}
}
_LIBCPP_EXTERN_TEMPLATE2(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS __money_get<char>)
_LIBCPP_EXTERN_TEMPLATE2(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS __money_get<wchar_t>)
template <class _CharT, class _InputIterator = istreambuf_iterator<_CharT> >
class _LIBCPP_TEMPLATE_VIS money_get
: public locale::facet,
private __money_get<_CharT>
{
public:
typedef _CharT char_type;
typedef _InputIterator iter_type;
typedef basic_string<char_type> string_type;
_LIBCPP_INLINE_VISIBILITY
explicit money_get(size_t __refs = 0)
: locale::facet(__refs) {}
_LIBCPP_INLINE_VISIBILITY
iter_type get(iter_type __b, iter_type __e, bool __intl, ios_base& __iob,
ios_base::iostate& __err, long double& __v) const
{
return do_get(__b, __e, __intl, __iob, __err, __v);
}
_LIBCPP_INLINE_VISIBILITY
iter_type get(iter_type __b, iter_type __e, bool __intl, ios_base& __iob,
ios_base::iostate& __err, string_type& __v) const
{
return do_get(__b, __e, __intl, __iob, __err, __v);
}
static locale::id id;
protected:
_LIBCPP_INLINE_VISIBILITY
~money_get() {}
virtual iter_type do_get(iter_type __b, iter_type __e, bool __intl,
ios_base& __iob, ios_base::iostate& __err,
long double& __v) const;
virtual iter_type do_get(iter_type __b, iter_type __e, bool __intl,
ios_base& __iob, ios_base::iostate& __err,
string_type& __v) const;
private:
static bool __do_get(iter_type& __b, iter_type __e,
bool __intl, const locale& __loc,
ios_base::fmtflags __flags, ios_base::iostate& __err,
bool& __neg, const ctype<char_type>& __ct,
unique_ptr<char_type, void(*)(void*)>& __wb,
char_type*& __wn, char_type* __we);
};
template <class _CharT, class _InputIterator>
locale::id
money_get<_CharT, _InputIterator>::id;
_LIBCPP_FUNC_VIS void __do_nothing(void*);
template <class _Tp>
_LIBCPP_HIDDEN
void
__double_or_nothing(unique_ptr<_Tp, void(*)(void*)>& __b, _Tp*& __n, _Tp*& __e)
{
bool __owns = __b.get_deleter() != __do_nothing;
size_t __cur_cap = static_cast<size_t>(__e-__b.get()) * sizeof(_Tp);
size_t __new_cap = __cur_cap < numeric_limits<size_t>::max() / 2 ?
2 * __cur_cap : numeric_limits<size_t>::max();
if (__new_cap == 0)
__new_cap = sizeof(_Tp);
size_t __n_off = static_cast<size_t>(__n - __b.get());
_Tp* __t = (_Tp*)realloc(__owns ? __b.get() : 0, __new_cap);
if (__t == 0)
__throw_bad_alloc();
if (__owns)
__b.release();
__b = unique_ptr<_Tp, void(*)(void*)>(__t, free);
__new_cap /= sizeof(_Tp);
__n = __b.get() + __n_off;
__e = __b.get() + __new_cap;
}
// true == success
template <class _CharT, class _InputIterator>
bool
money_get<_CharT, _InputIterator>::__do_get(iter_type& __b, iter_type __e,
bool __intl, const locale& __loc,
ios_base::fmtflags __flags,
ios_base::iostate& __err,
bool& __neg,
const ctype<char_type>& __ct,
unique_ptr<char_type, void(*)(void*)>& __wb,
char_type*& __wn, char_type* __we)
{
const unsigned __bz = 100;
unsigned __gbuf[__bz];
unique_ptr<unsigned, void(*)(void*)> __gb(__gbuf, __do_nothing);
unsigned* __gn = __gb.get();
unsigned* __ge = __gn + __bz;
money_base::pattern __pat;
char_type __dp;
char_type __ts;
string __grp;
string_type __sym;
string_type __psn;
string_type __nsn;
// Capture the spaces read into money_base::{space,none} so they
// can be compared to initial spaces in __sym.
string_type __spaces;
int __fd;
__money_get<_CharT>::__gather_info(__intl, __loc, __pat, __dp, __ts, __grp,
__sym, __psn, __nsn, __fd);
const string_type* __trailing_sign = 0;
__wn = __wb.get();
for (unsigned __p = 0; __p < 4 && __b != __e; ++__p)
{
switch (__pat.field[__p])
{
case money_base::space:
if (__p != 3)
{
if (__ct.is(ctype_base::space, *__b))
__spaces.push_back(*__b++);
else
{
__err |= ios_base::failbit;
return false;
}
}
_LIBCPP_FALLTHROUGH();
case money_base::none:
if (__p != 3)
{
while (__b != __e && __ct.is(ctype_base::space, *__b))
__spaces.push_back(*__b++);
}
break;
case money_base::sign:
if (__psn.size() + __nsn.size() > 0)
{
if (__psn.size() == 0 || __nsn.size() == 0)
{ // sign is optional
if (__psn.size() > 0)
{ // __nsn.size() == 0
if (*__b == __psn[0])
{
++__b;
if (__psn.size() > 1)
__trailing_sign = &__psn;
}
else
__neg = true;
}
else if (*__b == __nsn[0]) // __nsn.size() > 0 && __psn.size() == 0
{
++__b;
__neg = true;
if (__nsn.size() > 1)
__trailing_sign = &__nsn;
}
}
else // sign is required
{
if (*__b == __psn[0])
{
++__b;
if (__psn.size() > 1)
__trailing_sign = &__psn;
}
else if (*__b == __nsn[0])
{
++__b;
__neg = true;
if (__nsn.size() > 1)
__trailing_sign = &__nsn;
}
else
{
__err |= ios_base::failbit;
return false;
}
}
}
break;
case money_base::symbol:
{
bool __more_needed = __trailing_sign ||
(__p < 2) ||
(__p == 2 && __pat.field[3] != static_cast<char>(money_base::none));
bool __sb = (__flags & ios_base::showbase) != 0;
if (__sb || __more_needed)
{
typename string_type::const_iterator __sym_space_end = __sym.begin();
if (__p > 0 && (__pat.field[__p - 1] == money_base::none ||
__pat.field[__p - 1] == money_base::space)) {
// Match spaces we've already read against spaces at
// the beginning of __sym.
while (__sym_space_end != __sym.end() &&
__ct.is(ctype_base::space, *__sym_space_end))
++__sym_space_end;
const size_t __num_spaces = __sym_space_end - __sym.begin();
if (__num_spaces > __spaces.size() ||
!equal(__spaces.end() - __num_spaces, __spaces.end(),
__sym.begin())) {
// No match. Put __sym_space_end back at the
// beginning of __sym, which will prevent a
// match in the next loop.
__sym_space_end = __sym.begin();
}
}
typename string_type::const_iterator __sym_curr_char = __sym_space_end;
while (__sym_curr_char != __sym.end() && __b != __e &&
*__b == *__sym_curr_char) {
++__b;
++__sym_curr_char;
}
if (__sb && __sym_curr_char != __sym.end())
{
__err |= ios_base::failbit;
return false;
}
}
}
break;
case money_base::value:
{
unsigned __ng = 0;
for (; __b != __e; ++__b)
{
char_type __c = *__b;
if (__ct.is(ctype_base::digit, __c))
{
if (__wn == __we)
__double_or_nothing(__wb, __wn, __we);
*__wn++ = __c;
++__ng;
}
else if (__grp.size() > 0 && __ng > 0 && __c == __ts)
{
if (__gn == __ge)
__double_or_nothing(__gb, __gn, __ge);
*__gn++ = __ng;
__ng = 0;
}
else
break;
}
if (__gb.get() != __gn && __ng > 0)
{
if (__gn == __ge)
__double_or_nothing(__gb, __gn, __ge);
*__gn++ = __ng;
}
if (__fd > 0)
{
if (__b == __e || *__b != __dp)
{
__err |= ios_base::failbit;
return false;
}
for (++__b; __fd > 0; --__fd, ++__b)
{
if (__b == __e || !__ct.is(ctype_base::digit, *__b))
{
__err |= ios_base::failbit;
return false;
}
if (__wn == __we)
__double_or_nothing(__wb, __wn, __we);
*__wn++ = *__b;
}
}
if (__wn == __wb.get())
{
__err |= ios_base::failbit;
return false;
}
}
break;
}
}
if (__trailing_sign)
{
for (unsigned __i = 1; __i < __trailing_sign->size(); ++__i, ++__b)
{
if (__b == __e || *__b != (*__trailing_sign)[__i])
{
__err |= ios_base::failbit;
return false;
}
}
}
if (__gb.get() != __gn)
{
ios_base::iostate __et = ios_base::goodbit;
__check_grouping(__grp, __gb.get(), __gn, __et);
if (__et)
{
__err |= ios_base::failbit;
return false;
}
}
return true;
}
template <class _CharT, class _InputIterator>
_InputIterator
money_get<_CharT, _InputIterator>::do_get(iter_type __b, iter_type __e,
bool __intl, ios_base& __iob,
ios_base::iostate& __err,
long double& __v) const
{
const int __bz = 100;
char_type __wbuf[__bz];
unique_ptr<char_type, void(*)(void*)> __wb(__wbuf, __do_nothing);
char_type* __wn;
char_type* __we = __wbuf + __bz;
locale __loc = __iob.getloc();
const ctype<char_type>& __ct = use_facet<ctype<char_type> >(__loc);
bool __neg = false;
if (__do_get(__b, __e, __intl, __loc, __iob.flags(), __err, __neg, __ct,
__wb, __wn, __we))
{
const char __src[] = "0123456789";
char_type __atoms[sizeof(__src)-1];
__ct.widen(__src, __src + (sizeof(__src)-1), __atoms);
char __nbuf[__bz];
char* __nc = __nbuf;
unique_ptr<char, void(*)(void*)> __h(0, free);
if (__wn - __wb.get() > __bz-2)
{
__h.reset((char*)malloc(static_cast<size_t>(__wn - __wb.get() + 2)));
if (__h.get() == 0)
__throw_bad_alloc();
__nc = __h.get();
}
if (__neg)
*__nc++ = '-';
for (const char_type* __w = __wb.get(); __w < __wn; ++__w, ++__nc)
*__nc = __src[find(__atoms, _VSTD::end(__atoms), *__w) - __atoms];
*__nc = char();
if (sscanf(__nbuf, "%Lf", &__v) != 1)
__throw_runtime_error("money_get error");
}
if (__b == __e)
__err |= ios_base::eofbit;
return __b;
}
template <class _CharT, class _InputIterator>
_InputIterator
money_get<_CharT, _InputIterator>::do_get(iter_type __b, iter_type __e,
bool __intl, ios_base& __iob,
ios_base::iostate& __err,
string_type& __v) const
{
const int __bz = 100;
char_type __wbuf[__bz];
unique_ptr<char_type, void(*)(void*)> __wb(__wbuf, __do_nothing);
char_type* __wn;
char_type* __we = __wbuf + __bz;
locale __loc = __iob.getloc();
const ctype<char_type>& __ct = use_facet<ctype<char_type> >(__loc);
bool __neg = false;
if (__do_get(__b, __e, __intl, __loc, __iob.flags(), __err, __neg, __ct,
__wb, __wn, __we))
{
__v.clear();
if (__neg)
__v.push_back(__ct.widen('-'));
char_type __z = __ct.widen('0');
char_type* __w;
for (__w = __wb.get(); __w < __wn-1; ++__w)
if (*__w != __z)
break;
__v.append(__w, __wn);
}
if (__b == __e)
__err |= ios_base::eofbit;
return __b;
}
_LIBCPP_EXTERN_TEMPLATE2(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS money_get<char>)
_LIBCPP_EXTERN_TEMPLATE2(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS money_get<wchar_t>)
// money_put
template <class _CharT>
class __money_put
{
protected:
typedef _CharT char_type;
typedef basic_string<char_type> string_type;
_LIBCPP_INLINE_VISIBILITY __money_put() {}
static void __gather_info(bool __intl, bool __neg, const locale& __loc,
money_base::pattern& __pat, char_type& __dp,
char_type& __ts, string& __grp,
string_type& __sym, string_type& __sn,
int& __fd);
static void __format(char_type* __mb, char_type*& __mi, char_type*& __me,
ios_base::fmtflags __flags,
const char_type* __db, const char_type* __de,
const ctype<char_type>& __ct, bool __neg,
const money_base::pattern& __pat, char_type __dp,
char_type __ts, const string& __grp,
const string_type& __sym, const string_type& __sn,
int __fd);
};
template <class _CharT>
void
__money_put<_CharT>::__gather_info(bool __intl, bool __neg, const locale& __loc,
money_base::pattern& __pat, char_type& __dp,
char_type& __ts, string& __grp,
string_type& __sym, string_type& __sn,
int& __fd)
{
if (__intl)
{
const moneypunct<char_type, true>& __mp =
use_facet<moneypunct<char_type, true> >(__loc);
if (__neg)
{
__pat = __mp.neg_format();
__sn = __mp.negative_sign();
}
else
{
__pat = __mp.pos_format();
__sn = __mp.positive_sign();
}
__dp = __mp.decimal_point();
__ts = __mp.thousands_sep();
__grp = __mp.grouping();
__sym = __mp.curr_symbol();
__fd = __mp.frac_digits();
}
else
{
const moneypunct<char_type, false>& __mp =
use_facet<moneypunct<char_type, false> >(__loc);
if (__neg)
{
__pat = __mp.neg_format();
__sn = __mp.negative_sign();
}
else
{
__pat = __mp.pos_format();
__sn = __mp.positive_sign();
}
__dp = __mp.decimal_point();
__ts = __mp.thousands_sep();
__grp = __mp.grouping();
__sym = __mp.curr_symbol();
__fd = __mp.frac_digits();
}
}
template <class _CharT>
void
__money_put<_CharT>::__format(char_type* __mb, char_type*& __mi, char_type*& __me,
ios_base::fmtflags __flags,
const char_type* __db, const char_type* __de,
const ctype<char_type>& __ct, bool __neg,
const money_base::pattern& __pat, char_type __dp,
char_type __ts, const string& __grp,
const string_type& __sym, const string_type& __sn,
int __fd)
{
__me = __mb;
for (unsigned __p = 0; __p < 4; ++__p)
{
switch (__pat.field[__p])
{
case money_base::none:
__mi = __me;
break;
case money_base::space:
__mi = __me;
*__me++ = __ct.widen(' ');
break;
case money_base::sign:
if (!__sn.empty())
*__me++ = __sn[0];
break;
case money_base::symbol:
if (!__sym.empty() && (__flags & ios_base::showbase))
__me = _VSTD::copy(__sym.begin(), __sym.end(), __me);
break;
case money_base::value:
{
// remember start of value so we can reverse it
char_type* __t = __me;
// find beginning of digits
if (__neg)
++__db;
// find end of digits
const char_type* __d;
for (__d = __db; __d < __de; ++__d)
if (!__ct.is(ctype_base::digit, *__d))
break;
// print fractional part
if (__fd > 0)
{
int __f;
for (__f = __fd; __d > __db && __f > 0; --__f)
*__me++ = *--__d;
char_type __z = __f > 0 ? __ct.widen('0') : char_type();
for (; __f > 0; --__f)
*__me++ = __z;
*__me++ = __dp;
}
// print units part
if (__d == __db)
{
*__me++ = __ct.widen('0');
}
else
{
unsigned __ng = 0;
unsigned __ig = 0;
unsigned __gl = __grp.empty() ? numeric_limits<unsigned>::max()
: static_cast<unsigned>(__grp[__ig]);
while (__d != __db)
{
if (__ng == __gl)
{
*__me++ = __ts;
__ng = 0;
if (++__ig < __grp.size())
__gl = __grp[__ig] == numeric_limits<char>::max() ?
numeric_limits<unsigned>::max() :
static_cast<unsigned>(__grp[__ig]);
}
*__me++ = *--__d;
++__ng;
}
}
// reverse it
reverse(__t, __me);
}
break;
}
}
// print rest of sign, if any
if (__sn.size() > 1)
__me = _VSTD::copy(__sn.begin()+1, __sn.end(), __me);
// set alignment
if ((__flags & ios_base::adjustfield) == ios_base::left)
__mi = __me;
else if ((__flags & ios_base::adjustfield) != ios_base::internal)
__mi = __mb;
}
_LIBCPP_EXTERN_TEMPLATE2(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS __money_put<char>)
_LIBCPP_EXTERN_TEMPLATE2(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS __money_put<wchar_t>)
template <class _CharT, class _OutputIterator = ostreambuf_iterator<_CharT> >
class _LIBCPP_TEMPLATE_VIS money_put
: public locale::facet,
private __money_put<_CharT>
{
public:
typedef _CharT char_type;
typedef _OutputIterator iter_type;
typedef basic_string<char_type> string_type;
_LIBCPP_INLINE_VISIBILITY
explicit money_put(size_t __refs = 0)
: locale::facet(__refs) {}
_LIBCPP_INLINE_VISIBILITY
iter_type put(iter_type __s, bool __intl, ios_base& __iob, char_type __fl,
long double __units) const
{
return do_put(__s, __intl, __iob, __fl, __units);
}
_LIBCPP_INLINE_VISIBILITY
iter_type put(iter_type __s, bool __intl, ios_base& __iob, char_type __fl,
const string_type& __digits) const
{
return do_put(__s, __intl, __iob, __fl, __digits);
}
static locale::id id;
protected:
_LIBCPP_INLINE_VISIBILITY
~money_put() {}
virtual iter_type do_put(iter_type __s, bool __intl, ios_base& __iob,
char_type __fl, long double __units) const;
virtual iter_type do_put(iter_type __s, bool __intl, ios_base& __iob,
char_type __fl, const string_type& __digits) const;
};
template <class _CharT, class _OutputIterator>
locale::id
money_put<_CharT, _OutputIterator>::id;
template <class _CharT, class _OutputIterator>
_OutputIterator
money_put<_CharT, _OutputIterator>::do_put(iter_type __s, bool __intl,
ios_base& __iob, char_type __fl,
long double __units) const
{
// convert to char
const size_t __bs = 100;
char __buf[__bs];
char* __bb = __buf;
char_type __digits[__bs];
char_type* __db = __digits;
size_t __n = static_cast<size_t>(snprintf(__bb, __bs, "%.0Lf", __units));
unique_ptr<char, void(*)(void*)> __hn(0, free);
unique_ptr<char_type, void(*)(void*)> __hd(0, free);
// secure memory for digit storage
if (__n > __bs-1)
{
__n = static_cast<size_t>(__libcpp_asprintf_l(&__bb, _LIBCPP_GET_C_LOCALE, "%.0Lf", __units));
if (__bb == 0)
__throw_bad_alloc();
__hn.reset(__bb);
__hd.reset((char_type*)malloc(__n * sizeof(char_type)));
if (__hd == nullptr)
__throw_bad_alloc();
__db = __hd.get();
}
// gather info
locale __loc = __iob.getloc();
const ctype<char_type>& __ct = use_facet<ctype<char_type> >(__loc);
__ct.widen(__bb, __bb + __n, __db);
bool __neg = __n > 0 && __bb[0] == '-';
money_base::pattern __pat;
char_type __dp;
char_type __ts;
string __grp;
string_type __sym;
string_type __sn;
int __fd;
this->__gather_info(__intl, __neg, __loc, __pat, __dp, __ts, __grp, __sym, __sn, __fd);
// secure memory for formatting
char_type __mbuf[__bs];
char_type* __mb = __mbuf;
unique_ptr<char_type, void(*)(void*)> __hw(0, free);
size_t __exn = static_cast<int>(__n) > __fd ?
(__n - static_cast<size_t>(__fd)) * 2 + __sn.size() +
__sym.size() + static_cast<size_t>(__fd) + 1
: __sn.size() + __sym.size() + static_cast<size_t>(__fd) + 2;
if (__exn > __bs)
{
__hw.reset((char_type*)malloc(__exn * sizeof(char_type)));
__mb = __hw.get();
if (__mb == 0)
__throw_bad_alloc();
}
// format
char_type* __mi;
char_type* __me;
this->__format(__mb, __mi, __me, __iob.flags(),
__db, __db + __n, __ct,
__neg, __pat, __dp, __ts, __grp, __sym, __sn, __fd);
return __pad_and_output(__s, __mb, __mi, __me, __iob, __fl);
}
template <class _CharT, class _OutputIterator>
_OutputIterator
money_put<_CharT, _OutputIterator>::do_put(iter_type __s, bool __intl,
ios_base& __iob, char_type __fl,
const string_type& __digits) const
{
// gather info
locale __loc = __iob.getloc();
const ctype<char_type>& __ct = use_facet<ctype<char_type> >(__loc);
bool __neg = __digits.size() > 0 && __digits[0] == __ct.widen('-');
money_base::pattern __pat;
char_type __dp;
char_type __ts;
string __grp;
string_type __sym;
string_type __sn;
int __fd;
this->__gather_info(__intl, __neg, __loc, __pat, __dp, __ts, __grp, __sym, __sn, __fd);
// secure memory for formatting
char_type __mbuf[100];
char_type* __mb = __mbuf;
unique_ptr<char_type, void(*)(void*)> __h(0, free);
size_t __exn = static_cast<int>(__digits.size()) > __fd ?
(__digits.size() - static_cast<size_t>(__fd)) * 2 +
__sn.size() + __sym.size() + static_cast<size_t>(__fd) + 1
: __sn.size() + __sym.size() + static_cast<size_t>(__fd) + 2;
if (__exn > 100)
{
__h.reset((char_type*)malloc(__exn * sizeof(char_type)));
__mb = __h.get();
if (__mb == 0)
__throw_bad_alloc();
}
// format
char_type* __mi;
char_type* __me;
this->__format(__mb, __mi, __me, __iob.flags(),
__digits.data(), __digits.data() + __digits.size(), __ct,
__neg, __pat, __dp, __ts, __grp, __sym, __sn, __fd);
return __pad_and_output(__s, __mb, __mi, __me, __iob, __fl);
}
_LIBCPP_EXTERN_TEMPLATE2(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS money_put<char>)
_LIBCPP_EXTERN_TEMPLATE2(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS money_put<wchar_t>)
// messages
class _LIBCPP_TYPE_VIS messages_base
{
public:
typedef ptrdiff_t catalog;
_LIBCPP_INLINE_VISIBILITY messages_base() {}
};
template <class _CharT>
class _LIBCPP_TEMPLATE_VIS messages
: public locale::facet,
public messages_base
{
public:
typedef _CharT char_type;
typedef basic_string<_CharT> string_type;
_LIBCPP_INLINE_VISIBILITY
explicit messages(size_t __refs = 0)
: locale::facet(__refs) {}
_LIBCPP_INLINE_VISIBILITY
catalog open(const basic_string<char>& __nm, const locale& __loc) const
{
return do_open(__nm, __loc);
}
_LIBCPP_INLINE_VISIBILITY
string_type get(catalog __c, int __set, int __msgid,
const string_type& __dflt) const
{
return do_get(__c, __set, __msgid, __dflt);
}
_LIBCPP_INLINE_VISIBILITY
void close(catalog __c) const
{
do_close(__c);
}
static locale::id id;
protected:
_LIBCPP_INLINE_VISIBILITY
~messages() {}
virtual catalog do_open(const basic_string<char>&, const locale&) const;
virtual string_type do_get(catalog, int __set, int __msgid,
const string_type& __dflt) const;
virtual void do_close(catalog) const;
};
template <class _CharT>
locale::id
messages<_CharT>::id;
template <class _CharT>
typename messages<_CharT>::catalog
messages<_CharT>::do_open(const basic_string<char>& __nm, const locale&) const
{
#ifdef _LIBCPP_HAS_CATOPEN
catalog __cat = (catalog)catopen(__nm.c_str(), NL_CAT_LOCALE);
if (__cat != -1)
__cat = static_cast<catalog>((static_cast<size_t>(__cat) >> 1));
return __cat;
#else // !_LIBCPP_HAS_CATOPEN
_LIBCPP_UNUSED_VAR(__nm);
return -1;
#endif // _LIBCPP_HAS_CATOPEN
}
template <class _CharT>
typename messages<_CharT>::string_type
messages<_CharT>::do_get(catalog __c, int __set, int __msgid,
const string_type& __dflt) const
{
#ifdef _LIBCPP_HAS_CATOPEN
string __ndflt;
__narrow_to_utf8<sizeof(char_type)*__CHAR_BIT__>()(back_inserter(__ndflt),
__dflt.c_str(),
__dflt.c_str() + __dflt.size());
if (__c != -1)
__c <<= 1;
nl_catd __cat = (nl_catd)__c;
char* __n = catgets(__cat, __set, __msgid, __ndflt.c_str());
string_type __w;
__widen_from_utf8<sizeof(char_type)*__CHAR_BIT__>()(back_inserter(__w),
__n, __n + strlen(__n));
return __w;
#else // !_LIBCPP_HAS_CATOPEN
_LIBCPP_UNUSED_VAR(__c);
_LIBCPP_UNUSED_VAR(__set);
_LIBCPP_UNUSED_VAR(__msgid);
return __dflt;
#endif // _LIBCPP_HAS_CATOPEN
}
template <class _CharT>
void
messages<_CharT>::do_close(catalog __c) const
{
#ifdef _LIBCPP_HAS_CATOPEN
if (__c != -1)
__c <<= 1;
nl_catd __cat = (nl_catd)__c;
catclose(__cat);
#else // !_LIBCPP_HAS_CATOPEN
_LIBCPP_UNUSED_VAR(__c);
#endif // _LIBCPP_HAS_CATOPEN
}
_LIBCPP_EXTERN_TEMPLATE2(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS messages<char>)
_LIBCPP_EXTERN_TEMPLATE2(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS messages<wchar_t>)
template <class _CharT>
class _LIBCPP_TEMPLATE_VIS messages_byname
: public messages<_CharT>
{
public:
typedef messages_base::catalog catalog;
typedef basic_string<_CharT> string_type;
_LIBCPP_INLINE_VISIBILITY
explicit messages_byname(const char*, size_t __refs = 0)
: messages<_CharT>(__refs) {}
_LIBCPP_INLINE_VISIBILITY
explicit messages_byname(const string&, size_t __refs = 0)
: messages<_CharT>(__refs) {}
protected:
_LIBCPP_INLINE_VISIBILITY
~messages_byname() {}
};
_LIBCPP_EXTERN_TEMPLATE2(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS messages_byname<char>)
_LIBCPP_EXTERN_TEMPLATE2(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS messages_byname<wchar_t>)
template<class _Codecvt, class _Elem = wchar_t,
class _Wide_alloc = allocator<_Elem>,
class _Byte_alloc = allocator<char> >
class _LIBCPP_TEMPLATE_VIS wstring_convert
{
public:
typedef basic_string<char, char_traits<char>, _Byte_alloc> byte_string;
typedef basic_string<_Elem, char_traits<_Elem>, _Wide_alloc> wide_string;
typedef typename _Codecvt::state_type state_type;
typedef typename wide_string::traits_type::int_type int_type;
private:
byte_string __byte_err_string_;
wide_string __wide_err_string_;
_Codecvt* __cvtptr_;
state_type __cvtstate_;
size_t __cvtcount_;
wstring_convert(const wstring_convert& __wc);
wstring_convert& operator=(const wstring_convert& __wc);
public:
_LIBCPP_INLINE_VISIBILITY
_LIBCPP_EXPLICIT_AFTER_CXX11 wstring_convert(_Codecvt* __pcvt = new _Codecvt);
_LIBCPP_INLINE_VISIBILITY
wstring_convert(_Codecvt* __pcvt, state_type __state);
_LIBCPP_EXPLICIT_AFTER_CXX11 wstring_convert(const byte_string& __byte_err,
const wide_string& __wide_err = wide_string());
#ifndef _LIBCPP_CXX03_LANG
_LIBCPP_INLINE_VISIBILITY
wstring_convert(wstring_convert&& __wc);
#endif
~wstring_convert();
_LIBCPP_INLINE_VISIBILITY
wide_string from_bytes(char __byte)
{return from_bytes(&__byte, &__byte+1);}
_LIBCPP_INLINE_VISIBILITY
wide_string from_bytes(const char* __ptr)
{return from_bytes(__ptr, __ptr + char_traits<char>::length(__ptr));}
_LIBCPP_INLINE_VISIBILITY
wide_string from_bytes(const byte_string& __str)
{return from_bytes(__str.data(), __str.data() + __str.size());}
wide_string from_bytes(const char* __first, const char* __last);
_LIBCPP_INLINE_VISIBILITY
byte_string to_bytes(_Elem __wchar)
{return to_bytes(&__wchar, &__wchar+1);}
_LIBCPP_INLINE_VISIBILITY
byte_string to_bytes(const _Elem* __wptr)
{return to_bytes(__wptr, __wptr + char_traits<_Elem>::length(__wptr));}
_LIBCPP_INLINE_VISIBILITY
byte_string to_bytes(const wide_string& __wstr)
{return to_bytes(__wstr.data(), __wstr.data() + __wstr.size());}
byte_string to_bytes(const _Elem* __first, const _Elem* __last);
_LIBCPP_INLINE_VISIBILITY
size_t converted() const _NOEXCEPT {return __cvtcount_;}
_LIBCPP_INLINE_VISIBILITY
state_type state() const {return __cvtstate_;}
};
template<class _Codecvt, class _Elem, class _Wide_alloc, class _Byte_alloc>
inline
wstring_convert<_Codecvt, _Elem, _Wide_alloc, _Byte_alloc>::
wstring_convert(_Codecvt* __pcvt)
: __cvtptr_(__pcvt), __cvtstate_(), __cvtcount_(0)
{
}
template<class _Codecvt, class _Elem, class _Wide_alloc, class _Byte_alloc>
inline
wstring_convert<_Codecvt, _Elem, _Wide_alloc, _Byte_alloc>::
wstring_convert(_Codecvt* __pcvt, state_type __state)
: __cvtptr_(__pcvt), __cvtstate_(__state), __cvtcount_(0)
{
}
template<class _Codecvt, class _Elem, class _Wide_alloc, class _Byte_alloc>
wstring_convert<_Codecvt, _Elem, _Wide_alloc, _Byte_alloc>::
wstring_convert(const byte_string& __byte_err, const wide_string& __wide_err)
: __byte_err_string_(__byte_err), __wide_err_string_(__wide_err),
__cvtstate_(), __cvtcount_(0)
{
__cvtptr_ = new _Codecvt;
}
#ifndef _LIBCPP_CXX03_LANG
template<class _Codecvt, class _Elem, class _Wide_alloc, class _Byte_alloc>
inline
wstring_convert<_Codecvt, _Elem, _Wide_alloc, _Byte_alloc>::
wstring_convert(wstring_convert&& __wc)
: __byte_err_string_(_VSTD::move(__wc.__byte_err_string_)),
__wide_err_string_(_VSTD::move(__wc.__wide_err_string_)),
__cvtptr_(__wc.__cvtptr_),
__cvtstate_(__wc.__cvtstate_), __cvtcount_(__wc.__cvtcount_)
{
__wc.__cvtptr_ = nullptr;
}
#endif // _LIBCPP_CXX03_LANG
template<class _Codecvt, class _Elem, class _Wide_alloc, class _Byte_alloc>
wstring_convert<_Codecvt, _Elem, _Wide_alloc, _Byte_alloc>::~wstring_convert()
{
delete __cvtptr_;
}
template<class _Codecvt, class _Elem, class _Wide_alloc, class _Byte_alloc>
typename wstring_convert<_Codecvt, _Elem, _Wide_alloc, _Byte_alloc>::wide_string
wstring_convert<_Codecvt, _Elem, _Wide_alloc, _Byte_alloc>::
from_bytes(const char* __frm, const char* __frm_end)
{
__cvtcount_ = 0;
if (__cvtptr_ != nullptr)
{
wide_string __ws(2*(__frm_end - __frm), _Elem());
if (__frm != __frm_end)
__ws.resize(__ws.capacity());
codecvt_base::result __r = codecvt_base::ok;
state_type __st = __cvtstate_;
if (__frm != __frm_end)
{
_Elem* __to = &__ws[0];
_Elem* __to_end = __to + __ws.size();
const char* __frm_nxt;
do
{
_Elem* __to_nxt;
__r = __cvtptr_->in(__st, __frm, __frm_end, __frm_nxt,
__to, __to_end, __to_nxt);
__cvtcount_ += __frm_nxt - __frm;
if (__frm_nxt == __frm)
{
__r = codecvt_base::error;
}
else if (__r == codecvt_base::noconv)
{
__ws.resize(__to - &__ws[0]);
// This only gets executed if _Elem is char
__ws.append((const _Elem*)__frm, (const _Elem*)__frm_end);
__frm = __frm_nxt;
__r = codecvt_base::ok;
}
else if (__r == codecvt_base::ok)
{
__ws.resize(__to_nxt - &__ws[0]);
__frm = __frm_nxt;
}
else if (__r == codecvt_base::partial)
{
ptrdiff_t __s = __to_nxt - &__ws[0];
__ws.resize(2 * __s);
__to = &__ws[0] + __s;
__to_end = &__ws[0] + __ws.size();
__frm = __frm_nxt;
}
} while (__r == codecvt_base::partial && __frm_nxt < __frm_end);
}
if (__r == codecvt_base::ok)
return __ws;
}
if (__wide_err_string_.empty())
__throw_range_error("wstring_convert: from_bytes error");
return __wide_err_string_;
}
template<class _Codecvt, class _Elem, class _Wide_alloc, class _Byte_alloc>
typename wstring_convert<_Codecvt, _Elem, _Wide_alloc, _Byte_alloc>::byte_string
wstring_convert<_Codecvt, _Elem, _Wide_alloc, _Byte_alloc>::
to_bytes(const _Elem* __frm, const _Elem* __frm_end)
{
__cvtcount_ = 0;
if (__cvtptr_ != nullptr)
{
byte_string __bs(2*(__frm_end - __frm), char());
if (__frm != __frm_end)
__bs.resize(__bs.capacity());
codecvt_base::result __r = codecvt_base::ok;
state_type __st = __cvtstate_;
if (__frm != __frm_end)
{
char* __to = &__bs[0];
char* __to_end = __to + __bs.size();
const _Elem* __frm_nxt;
do
{
char* __to_nxt;
__r = __cvtptr_->out(__st, __frm, __frm_end, __frm_nxt,
__to, __to_end, __to_nxt);
__cvtcount_ += __frm_nxt - __frm;
if (__frm_nxt == __frm)
{
__r = codecvt_base::error;
}
else if (__r == codecvt_base::noconv)
{
__bs.resize(__to - &__bs[0]);
// This only gets executed if _Elem is char
__bs.append((const char*)__frm, (const char*)__frm_end);
__frm = __frm_nxt;
__r = codecvt_base::ok;
}
else if (__r == codecvt_base::ok)
{
__bs.resize(__to_nxt - &__bs[0]);
__frm = __frm_nxt;
}
else if (__r == codecvt_base::partial)
{
ptrdiff_t __s = __to_nxt - &__bs[0];
__bs.resize(2 * __s);
__to = &__bs[0] + __s;
__to_end = &__bs[0] + __bs.size();
__frm = __frm_nxt;
}
} while (__r == codecvt_base::partial && __frm_nxt < __frm_end);
}
if (__r == codecvt_base::ok)
{
size_t __s = __bs.size();
__bs.resize(__bs.capacity());
char* __to = &__bs[0] + __s;
char* __to_end = __to + __bs.size();
do
{
char* __to_nxt;
__r = __cvtptr_->unshift(__st, __to, __to_end, __to_nxt);
if (__r == codecvt_base::noconv)
{
__bs.resize(__to - &__bs[0]);
__r = codecvt_base::ok;
}
else if (__r == codecvt_base::ok)
{
__bs.resize(__to_nxt - &__bs[0]);
}
else if (__r == codecvt_base::partial)
{
ptrdiff_t __sp = __to_nxt - &__bs[0];
__bs.resize(2 * __sp);
__to = &__bs[0] + __sp;
__to_end = &__bs[0] + __bs.size();
}
} while (__r == codecvt_base::partial);
if (__r == codecvt_base::ok)
return __bs;
}
}
if (__byte_err_string_.empty())
__throw_range_error("wstring_convert: to_bytes error");
return __byte_err_string_;
}
template <class _Codecvt, class _Elem = wchar_t, class _Tr = char_traits<_Elem> >
class _LIBCPP_TEMPLATE_VIS wbuffer_convert
: public basic_streambuf<_Elem, _Tr>
{
public:
// types:
typedef _Elem char_type;
typedef _Tr traits_type;
typedef typename traits_type::int_type int_type;
typedef typename traits_type::pos_type pos_type;
typedef typename traits_type::off_type off_type;
typedef typename _Codecvt::state_type state_type;
private:
char* __extbuf_;
const char* __extbufnext_;
const char* __extbufend_;
char __extbuf_min_[8];
size_t __ebs_;
char_type* __intbuf_;
size_t __ibs_;
streambuf* __bufptr_;
_Codecvt* __cv_;
state_type __st_;
ios_base::openmode __cm_;
bool __owns_eb_;
bool __owns_ib_;
bool __always_noconv_;
wbuffer_convert(const wbuffer_convert&);
wbuffer_convert& operator=(const wbuffer_convert&);
public:
_LIBCPP_EXPLICIT_AFTER_CXX11 wbuffer_convert(streambuf* __bytebuf = 0,
_Codecvt* __pcvt = new _Codecvt, state_type __state = state_type());
~wbuffer_convert();
_LIBCPP_INLINE_VISIBILITY
streambuf* rdbuf() const {return __bufptr_;}
_LIBCPP_INLINE_VISIBILITY
streambuf* rdbuf(streambuf* __bytebuf)
{
streambuf* __r = __bufptr_;
__bufptr_ = __bytebuf;
return __r;
}
_LIBCPP_INLINE_VISIBILITY
state_type state() const {return __st_;}
protected:
virtual int_type underflow();
virtual int_type pbackfail(int_type __c = traits_type::eof());
virtual int_type overflow (int_type __c = traits_type::eof());
virtual basic_streambuf<char_type, traits_type>* setbuf(char_type* __s,
streamsize __n);
virtual pos_type seekoff(off_type __off, ios_base::seekdir __way,
ios_base::openmode __wch = ios_base::in | ios_base::out);
virtual pos_type seekpos(pos_type __sp,
ios_base::openmode __wch = ios_base::in | ios_base::out);
virtual int sync();
private:
bool __read_mode();
void __write_mode();
wbuffer_convert* __close();
};
template <class _Codecvt, class _Elem, class _Tr>
wbuffer_convert<_Codecvt, _Elem, _Tr>::
wbuffer_convert(streambuf* __bytebuf, _Codecvt* __pcvt, state_type __state)
: __extbuf_(0),
__extbufnext_(0),
__extbufend_(0),
__ebs_(0),
__intbuf_(0),
__ibs_(0),
__bufptr_(__bytebuf),
__cv_(__pcvt),
__st_(__state),
__cm_(0),
__owns_eb_(false),
__owns_ib_(false),
__always_noconv_(__cv_ ? __cv_->always_noconv() : false)
{
setbuf(0, 4096);
}
template <class _Codecvt, class _Elem, class _Tr>
wbuffer_convert<_Codecvt, _Elem, _Tr>::~wbuffer_convert()
{
__close();
delete __cv_;
if (__owns_eb_)
delete [] __extbuf_;
if (__owns_ib_)
delete [] __intbuf_;
}
template <class _Codecvt, class _Elem, class _Tr>
typename wbuffer_convert<_Codecvt, _Elem, _Tr>::int_type
wbuffer_convert<_Codecvt, _Elem, _Tr>::underflow()
{
if (__cv_ == 0 || __bufptr_ == 0)
return traits_type::eof();
bool __initial = __read_mode();
char_type __1buf;
if (this->gptr() == 0)
this->setg(&__1buf, &__1buf+1, &__1buf+1);
const size_t __unget_sz = __initial ? 0 : min<size_t>((this->egptr() - this->eback()) / 2, 4);
int_type __c = traits_type::eof();
if (this->gptr() == this->egptr())
{
memmove(this->eback(), this->egptr() - __unget_sz, __unget_sz * sizeof(char_type));
if (__always_noconv_)
{
streamsize __nmemb = static_cast<streamsize>(this->egptr() - this->eback() - __unget_sz);
__nmemb = __bufptr_->sgetn((char*)this->eback() + __unget_sz, __nmemb);
if (__nmemb != 0)
{
this->setg(this->eback(),
this->eback() + __unget_sz,
this->eback() + __unget_sz + __nmemb);
__c = *this->gptr();
}
}
else
{
_LIBCPP_ASSERT(!(__extbufnext_ == NULL && (__extbufend_ != __extbufnext_)), "underflow moving from NULL" );
if (__extbufend_ != __extbufnext_)
memmove(__extbuf_, __extbufnext_, __extbufend_ - __extbufnext_);
__extbufnext_ = __extbuf_ + (__extbufend_ - __extbufnext_);
__extbufend_ = __extbuf_ + (__extbuf_ == __extbuf_min_ ? sizeof(__extbuf_min_) : __ebs_);
streamsize __nmemb = _VSTD::min(static_cast<streamsize>(this->egptr() - this->eback() - __unget_sz),
static_cast<streamsize>(__extbufend_ - __extbufnext_));
codecvt_base::result __r;
// FIXME: Do we ever need to restore the state here?
//state_type __svs = __st_;
streamsize __nr = __bufptr_->sgetn(const_cast<char*>(__extbufnext_), __nmemb);
if (__nr != 0)
{
__extbufend_ = __extbufnext_ + __nr;
char_type* __inext;
__r = __cv_->in(__st_, __extbuf_, __extbufend_, __extbufnext_,
this->eback() + __unget_sz,
this->egptr(), __inext);
if (__r == codecvt_base::noconv)
{
this->setg((char_type*)__extbuf_, (char_type*)__extbuf_,
(char_type*) const_cast<char *>(__extbufend_));
__c = *this->gptr();
}
else if (__inext != this->eback() + __unget_sz)
{
this->setg(this->eback(), this->eback() + __unget_sz, __inext);
__c = *this->gptr();
}
}
}
}
else
__c = *this->gptr();
if (this->eback() == &__1buf)
this->setg(0, 0, 0);
return __c;
}
template <class _Codecvt, class _Elem, class _Tr>
typename wbuffer_convert<_Codecvt, _Elem, _Tr>::int_type
wbuffer_convert<_Codecvt, _Elem, _Tr>::pbackfail(int_type __c)
{
if (__cv_ != 0 && __bufptr_ != 0 && this->eback() < this->gptr())
{
if (traits_type::eq_int_type(__c, traits_type::eof()))
{
this->gbump(-1);
return traits_type::not_eof(__c);
}
if (traits_type::eq(traits_type::to_char_type(__c), this->gptr()[-1]))
{
this->gbump(-1);
*this->gptr() = traits_type::to_char_type(__c);
return __c;
}
}
return traits_type::eof();
}
template <class _Codecvt, class _Elem, class _Tr>
typename wbuffer_convert<_Codecvt, _Elem, _Tr>::int_type
wbuffer_convert<_Codecvt, _Elem, _Tr>::overflow(int_type __c)
{
if (__cv_ == 0 || __bufptr_ == 0)
return traits_type::eof();
__write_mode();
char_type __1buf;
char_type* __pb_save = this->pbase();
char_type* __epb_save = this->epptr();
if (!traits_type::eq_int_type(__c, traits_type::eof()))
{
if (this->pptr() == 0)
this->setp(&__1buf, &__1buf+1);
*this->pptr() = traits_type::to_char_type(__c);
this->pbump(1);
}
if (this->pptr() != this->pbase())
{
if (__always_noconv_)
{
streamsize __nmemb = static_cast<streamsize>(this->pptr() - this->pbase());
if (__bufptr_->sputn((const char*)this->pbase(), __nmemb) != __nmemb)
return traits_type::eof();
}
else
{
char* __extbe = __extbuf_;
codecvt_base::result __r;
do
{
const char_type* __e;
__r = __cv_->out(__st_, this->pbase(), this->pptr(), __e,
__extbuf_, __extbuf_ + __ebs_, __extbe);
if (__e == this->pbase())
return traits_type::eof();
if (__r == codecvt_base::noconv)
{
streamsize __nmemb = static_cast<size_t>(this->pptr() - this->pbase());
if (__bufptr_->sputn((const char*)this->pbase(), __nmemb) != __nmemb)
return traits_type::eof();
}
else if (__r == codecvt_base::ok || __r == codecvt_base::partial)
{
streamsize __nmemb = static_cast<size_t>(__extbe - __extbuf_);
if (__bufptr_->sputn(__extbuf_, __nmemb) != __nmemb)
return traits_type::eof();
if (__r == codecvt_base::partial)
{
this->setp(const_cast<char_type *>(__e), this->pptr());
this->__pbump(this->epptr() - this->pbase());
}
}
else
return traits_type::eof();
} while (__r == codecvt_base::partial);
}
this->setp(__pb_save, __epb_save);
}
return traits_type::not_eof(__c);
}
template <class _Codecvt, class _Elem, class _Tr>
basic_streambuf<_Elem, _Tr>*
wbuffer_convert<_Codecvt, _Elem, _Tr>::setbuf(char_type* __s, streamsize __n)
{
this->setg(0, 0, 0);
this->setp(0, 0);
if (__owns_eb_)
delete [] __extbuf_;
if (__owns_ib_)
delete [] __intbuf_;
__ebs_ = __n;
if (__ebs_ > sizeof(__extbuf_min_))
{
if (__always_noconv_ && __s)
{
__extbuf_ = (char*)__s;
__owns_eb_ = false;
}
else
{
__extbuf_ = new char[__ebs_];
__owns_eb_ = true;
}
}
else
{
__extbuf_ = __extbuf_min_;
__ebs_ = sizeof(__extbuf_min_);
__owns_eb_ = false;
}
if (!__always_noconv_)
{
__ibs_ = max<streamsize>(__n, sizeof(__extbuf_min_));
if (__s && __ibs_ >= sizeof(__extbuf_min_))
{
__intbuf_ = __s;
__owns_ib_ = false;
}
else
{
__intbuf_ = new char_type[__ibs_];
__owns_ib_ = true;
}
}
else
{
__ibs_ = 0;
__intbuf_ = 0;
__owns_ib_ = false;
}
return this;
}
template <class _Codecvt, class _Elem, class _Tr>
typename wbuffer_convert<_Codecvt, _Elem, _Tr>::pos_type
wbuffer_convert<_Codecvt, _Elem, _Tr>::seekoff(off_type __off, ios_base::seekdir __way,
ios_base::openmode __om)
{
int __width = __cv_->encoding();
if (__cv_ == 0 || __bufptr_ == 0 || (__width <= 0 && __off != 0) || sync())
return pos_type(off_type(-1));
// __width > 0 || __off == 0, now check __way
if (__way != ios_base::beg && __way != ios_base::cur && __way != ios_base::end)
return pos_type(off_type(-1));
pos_type __r = __bufptr_->pubseekoff(__width * __off, __way, __om);
__r.state(__st_);
return __r;
}
template <class _Codecvt, class _Elem, class _Tr>
typename wbuffer_convert<_Codecvt, _Elem, _Tr>::pos_type
wbuffer_convert<_Codecvt, _Elem, _Tr>::seekpos(pos_type __sp, ios_base::openmode __wch)
{
if (__cv_ == 0 || __bufptr_ == 0 || sync())
return pos_type(off_type(-1));
if (__bufptr_->pubseekpos(__sp, __wch) == pos_type(off_type(-1)))
return pos_type(off_type(-1));
return __sp;
}
template <class _Codecvt, class _Elem, class _Tr>
int
wbuffer_convert<_Codecvt, _Elem, _Tr>::sync()
{
if (__cv_ == 0 || __bufptr_ == 0)
return 0;
if (__cm_ & ios_base::out)
{
if (this->pptr() != this->pbase())
if (overflow() == traits_type::eof())
return -1;
codecvt_base::result __r;
do
{
char* __extbe;
__r = __cv_->unshift(__st_, __extbuf_, __extbuf_ + __ebs_, __extbe);
streamsize __nmemb = static_cast<streamsize>(__extbe - __extbuf_);
if (__bufptr_->sputn(__extbuf_, __nmemb) != __nmemb)
return -1;
} while (__r == codecvt_base::partial);
if (__r == codecvt_base::error)
return -1;
if (__bufptr_->pubsync())
return -1;
}
else if (__cm_ & ios_base::in)
{
off_type __c;
if (__always_noconv_)
__c = this->egptr() - this->gptr();
else
{
int __width = __cv_->encoding();
__c = __extbufend_ - __extbufnext_;
if (__width > 0)
__c += __width * (this->egptr() - this->gptr());
else
{
if (this->gptr() != this->egptr())
{
reverse(this->gptr(), this->egptr());
codecvt_base::result __r;
const char_type* __e = this->gptr();
char* __extbe;
do
{
__r = __cv_->out(__st_, __e, this->egptr(), __e,
__extbuf_, __extbuf_ + __ebs_, __extbe);
switch (__r)
{
case codecvt_base::noconv:
__c += this->egptr() - this->gptr();
break;
case codecvt_base::ok:
case codecvt_base::partial:
__c += __extbe - __extbuf_;
break;
default:
return -1;
}
} while (__r == codecvt_base::partial);
}
}
}
if (__bufptr_->pubseekoff(-__c, ios_base::cur, __cm_) == pos_type(off_type(-1)))
return -1;
this->setg(0, 0, 0);
__cm_ = 0;
}
return 0;
}
template <class _Codecvt, class _Elem, class _Tr>
bool
wbuffer_convert<_Codecvt, _Elem, _Tr>::__read_mode()
{
if (!(__cm_ & ios_base::in))
{
this->setp(0, 0);
if (__always_noconv_)
this->setg((char_type*)__extbuf_,
(char_type*)__extbuf_ + __ebs_,
(char_type*)__extbuf_ + __ebs_);
else
this->setg(__intbuf_, __intbuf_ + __ibs_, __intbuf_ + __ibs_);
__cm_ = ios_base::in;
return true;
}
return false;
}
template <class _Codecvt, class _Elem, class _Tr>
void
wbuffer_convert<_Codecvt, _Elem, _Tr>::__write_mode()
{
if (!(__cm_ & ios_base::out))
{
this->setg(0, 0, 0);
if (__ebs_ > sizeof(__extbuf_min_))
{
if (__always_noconv_)
this->setp((char_type*)__extbuf_,
(char_type*)__extbuf_ + (__ebs_ - 1));
else
this->setp(__intbuf_, __intbuf_ + (__ibs_ - 1));
}
else
this->setp(0, 0);
__cm_ = ios_base::out;
}
}
template <class _Codecvt, class _Elem, class _Tr>
wbuffer_convert<_Codecvt, _Elem, _Tr>*
wbuffer_convert<_Codecvt, _Elem, _Tr>::__close()
{
wbuffer_convert* __rt = 0;
if (__cv_ != 0 && __bufptr_ != 0)
{
__rt = this;
if ((__cm_ & ios_base::out) && sync())
__rt = 0;
}
return __rt;
}
_LIBCPP_END_NAMESPACE_STD
_LIBCPP_POP_MACROS
#endif // _LIBCPP_LOCALE
| 154,582 | 4,349 | jart/cosmopolitan | false |
cosmopolitan/third_party/libcxx/set | // -*- C++ -*-
//===---------------------------- set -------------------------------------===//
//
// 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_SET
#define _LIBCPP_SET
#include "third_party/libcxx/__config"
#include "third_party/libcxx/__tree"
#include "third_party/libcxx/__node_handle"
#include "third_party/libcxx/functional"
#include "third_party/libcxx/version"
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
#pragma GCC system_header
#endif
_LIBCPP_BEGIN_NAMESPACE_STD
/*
set synopsis
namespace std
{
template <class Key, class Compare = less<Key>,
class Allocator = allocator<Key>>
class set
{
public:
// types:
typedef Key key_type;
typedef key_type value_type;
typedef Compare key_compare;
typedef key_compare value_compare;
typedef Allocator allocator_type;
typedef typename allocator_type::reference reference;
typedef typename allocator_type::const_reference const_reference;
typedef typename allocator_type::size_type size_type;
typedef typename allocator_type::difference_type difference_type;
typedef typename allocator_type::pointer pointer;
typedef typename allocator_type::const_pointer const_pointer;
typedef implementation-defined iterator;
typedef implementation-defined const_iterator;
typedef std::reverse_iterator<iterator> reverse_iterator;
typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
typedef unspecified node_type; // C++17
typedef INSERT_RETURN_TYPE<iterator, node_type> insert_return_type; // C++17
// construct/copy/destroy:
set()
noexcept(
is_nothrow_default_constructible<allocator_type>::value &&
is_nothrow_default_constructible<key_compare>::value &&
is_nothrow_copy_constructible<key_compare>::value);
explicit set(const value_compare& comp);
set(const value_compare& comp, const allocator_type& a);
template <class InputIterator>
set(InputIterator first, InputIterator last,
const value_compare& comp = value_compare());
template <class InputIterator>
set(InputIterator first, InputIterator last, const value_compare& comp,
const allocator_type& a);
set(const set& s);
set(set&& s)
noexcept(
is_nothrow_move_constructible<allocator_type>::value &&
is_nothrow_move_constructible<key_compare>::value);
explicit set(const allocator_type& a);
set(const set& s, const allocator_type& a);
set(set&& s, const allocator_type& a);
set(initializer_list<value_type> il, const value_compare& comp = value_compare());
set(initializer_list<value_type> il, const value_compare& comp,
const allocator_type& a);
template <class InputIterator>
set(InputIterator first, InputIterator last, const allocator_type& a)
: set(first, last, Compare(), a) {} // C++14
set(initializer_list<value_type> il, const allocator_type& a)
: set(il, Compare(), a) {} // C++14
~set();
set& operator=(const set& s);
set& operator=(set&& s)
noexcept(
allocator_type::propagate_on_container_move_assignment::value &&
is_nothrow_move_assignable<allocator_type>::value &&
is_nothrow_move_assignable<key_compare>::value);
set& operator=(initializer_list<value_type> il);
// iterators:
iterator begin() noexcept;
const_iterator begin() const noexcept;
iterator end() noexcept;
const_iterator end() const noexcept;
reverse_iterator rbegin() noexcept;
const_reverse_iterator rbegin() const noexcept;
reverse_iterator rend() noexcept;
const_reverse_iterator rend() const noexcept;
const_iterator cbegin() const noexcept;
const_iterator cend() const noexcept;
const_reverse_iterator crbegin() const noexcept;
const_reverse_iterator crend() const noexcept;
// capacity:
bool empty() const noexcept;
size_type size() const noexcept;
size_type max_size() const noexcept;
// modifiers:
template <class... Args>
pair<iterator, bool> emplace(Args&&... args);
template <class... Args>
iterator emplace_hint(const_iterator position, Args&&... args);
pair<iterator,bool> insert(const value_type& v);
pair<iterator,bool> insert(value_type&& v);
iterator insert(const_iterator position, const value_type& v);
iterator insert(const_iterator position, value_type&& v);
template <class InputIterator>
void insert(InputIterator first, InputIterator last);
void insert(initializer_list<value_type> il);
node_type extract(const_iterator position); // C++17
node_type extract(const key_type& x); // C++17
insert_return_type insert(node_type&& nh); // C++17
iterator insert(const_iterator hint, node_type&& nh); // C++17
iterator erase(const_iterator position);
iterator erase(iterator position); // C++14
size_type erase(const key_type& k);
iterator erase(const_iterator first, const_iterator last);
void clear() noexcept;
template<class C2>
void merge(set<Key, C2, Allocator>& source); // C++17
template<class C2>
void merge(set<Key, C2, Allocator>&& source); // C++17
template<class C2>
void merge(multiset<Key, C2, Allocator>& source); // C++17
template<class C2>
void merge(multiset<Key, C2, Allocator>&& source); // C++17
void swap(set& s)
noexcept(
__is_nothrow_swappable<key_compare>::value &&
(!allocator_type::propagate_on_container_swap::value ||
__is_nothrow_swappable<allocator_type>::value));
// observers:
allocator_type get_allocator() const noexcept;
key_compare key_comp() const;
value_compare value_comp() const;
// set operations:
iterator find(const key_type& k);
const_iterator find(const key_type& k) const;
template<typename K>
iterator find(const K& x);
template<typename K>
const_iterator find(const K& x) const; // C++14
template<typename K>
size_type count(const K& x) const; // C++14
size_type count(const key_type& k) const;
bool contains(const key_type& x) const; // C++20
iterator lower_bound(const key_type& k);
const_iterator lower_bound(const key_type& k) const;
template<typename K>
iterator lower_bound(const K& x); // C++14
template<typename K>
const_iterator lower_bound(const K& x) const; // C++14
iterator upper_bound(const key_type& k);
const_iterator upper_bound(const key_type& k) const;
template<typename K>
iterator upper_bound(const K& x); // C++14
template<typename K>
const_iterator upper_bound(const K& x) const; // C++14
pair<iterator,iterator> equal_range(const key_type& k);
pair<const_iterator,const_iterator> equal_range(const key_type& k) const;
template<typename K>
pair<iterator,iterator> equal_range(const K& x); // C++14
template<typename K>
pair<const_iterator,const_iterator> equal_range(const K& x) const; // C++14
};
template <class Key, class Compare, class Allocator>
bool
operator==(const set<Key, Compare, Allocator>& x,
const set<Key, Compare, Allocator>& y);
template <class Key, class Compare, class Allocator>
bool
operator< (const set<Key, Compare, Allocator>& x,
const set<Key, Compare, Allocator>& y);
template <class Key, class Compare, class Allocator>
bool
operator!=(const set<Key, Compare, Allocator>& x,
const set<Key, Compare, Allocator>& y);
template <class Key, class Compare, class Allocator>
bool
operator> (const set<Key, Compare, Allocator>& x,
const set<Key, Compare, Allocator>& y);
template <class Key, class Compare, class Allocator>
bool
operator>=(const set<Key, Compare, Allocator>& x,
const set<Key, Compare, Allocator>& y);
template <class Key, class Compare, class Allocator>
bool
operator<=(const set<Key, Compare, Allocator>& x,
const set<Key, Compare, Allocator>& y);
// specialized algorithms:
template <class Key, class Compare, class Allocator>
void
swap(set<Key, Compare, Allocator>& x, set<Key, Compare, Allocator>& y)
noexcept(noexcept(x.swap(y)));
template <class Key, class Compare, class Allocator, class Predicate>
void erase_if(set<Key, Compare, Allocator>& c, Predicate pred); // C++20
template <class Key, class Compare = less<Key>,
class Allocator = allocator<Key>>
class multiset
{
public:
// types:
typedef Key key_type;
typedef key_type value_type;
typedef Compare key_compare;
typedef key_compare value_compare;
typedef Allocator allocator_type;
typedef typename allocator_type::reference reference;
typedef typename allocator_type::const_reference const_reference;
typedef typename allocator_type::size_type size_type;
typedef typename allocator_type::difference_type difference_type;
typedef typename allocator_type::pointer pointer;
typedef typename allocator_type::const_pointer const_pointer;
typedef implementation-defined iterator;
typedef implementation-defined const_iterator;
typedef std::reverse_iterator<iterator> reverse_iterator;
typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
typedef unspecified node_type; // C++17
// construct/copy/destroy:
multiset()
noexcept(
is_nothrow_default_constructible<allocator_type>::value &&
is_nothrow_default_constructible<key_compare>::value &&
is_nothrow_copy_constructible<key_compare>::value);
explicit multiset(const value_compare& comp);
multiset(const value_compare& comp, const allocator_type& a);
template <class InputIterator>
multiset(InputIterator first, InputIterator last,
const value_compare& comp = value_compare());
template <class InputIterator>
multiset(InputIterator first, InputIterator last,
const value_compare& comp, const allocator_type& a);
multiset(const multiset& s);
multiset(multiset&& s)
noexcept(
is_nothrow_move_constructible<allocator_type>::value &&
is_nothrow_move_constructible<key_compare>::value);
explicit multiset(const allocator_type& a);
multiset(const multiset& s, const allocator_type& a);
multiset(multiset&& s, const allocator_type& a);
multiset(initializer_list<value_type> il, const value_compare& comp = value_compare());
multiset(initializer_list<value_type> il, const value_compare& comp,
const allocator_type& a);
template <class InputIterator>
multiset(InputIterator first, InputIterator last, const allocator_type& a)
: set(first, last, Compare(), a) {} // C++14
multiset(initializer_list<value_type> il, const allocator_type& a)
: set(il, Compare(), a) {} // C++14
~multiset();
multiset& operator=(const multiset& s);
multiset& operator=(multiset&& s)
noexcept(
allocator_type::propagate_on_container_move_assignment::value &&
is_nothrow_move_assignable<allocator_type>::value &&
is_nothrow_move_assignable<key_compare>::value);
multiset& operator=(initializer_list<value_type> il);
// iterators:
iterator begin() noexcept;
const_iterator begin() const noexcept;
iterator end() noexcept;
const_iterator end() const noexcept;
reverse_iterator rbegin() noexcept;
const_reverse_iterator rbegin() const noexcept;
reverse_iterator rend() noexcept;
const_reverse_iterator rend() const noexcept;
const_iterator cbegin() const noexcept;
const_iterator cend() const noexcept;
const_reverse_iterator crbegin() const noexcept;
const_reverse_iterator crend() const noexcept;
// capacity:
bool empty() const noexcept;
size_type size() const noexcept;
size_type max_size() const noexcept;
// modifiers:
template <class... Args>
iterator emplace(Args&&... args);
template <class... Args>
iterator emplace_hint(const_iterator position, Args&&... args);
iterator insert(const value_type& v);
iterator insert(value_type&& v);
iterator insert(const_iterator position, const value_type& v);
iterator insert(const_iterator position, value_type&& v);
template <class InputIterator>
void insert(InputIterator first, InputIterator last);
void insert(initializer_list<value_type> il);
node_type extract(const_iterator position); // C++17
node_type extract(const key_type& x); // C++17
iterator insert(node_type&& nh); // C++17
iterator insert(const_iterator hint, node_type&& nh); // C++17
iterator erase(const_iterator position);
iterator erase(iterator position); // C++14
size_type erase(const key_type& k);
iterator erase(const_iterator first, const_iterator last);
void clear() noexcept;
template<class C2>
void merge(multiset<Key, C2, Allocator>& source); // C++17
template<class C2>
void merge(multiset<Key, C2, Allocator>&& source); // C++17
template<class C2>
void merge(set<Key, C2, Allocator>& source); // C++17
template<class C2>
void merge(set<Key, C2, Allocator>&& source); // C++17
void swap(multiset& s)
noexcept(
__is_nothrow_swappable<key_compare>::value &&
(!allocator_type::propagate_on_container_swap::value ||
__is_nothrow_swappable<allocator_type>::value));
// observers:
allocator_type get_allocator() const noexcept;
key_compare key_comp() const;
value_compare value_comp() const;
// set operations:
iterator find(const key_type& k);
const_iterator find(const key_type& k) const;
template<typename K>
iterator find(const K& x);
template<typename K>
const_iterator find(const K& x) const; // C++14
template<typename K>
size_type count(const K& x) const; // C++14
size_type count(const key_type& k) const;
bool contains(const key_type& x) const; // C++20
iterator lower_bound(const key_type& k);
const_iterator lower_bound(const key_type& k) const;
template<typename K>
iterator lower_bound(const K& x); // C++14
template<typename K>
const_iterator lower_bound(const K& x) const; // C++14
iterator upper_bound(const key_type& k);
const_iterator upper_bound(const key_type& k) const;
template<typename K>
iterator upper_bound(const K& x); // C++14
template<typename K>
const_iterator upper_bound(const K& x) const; // C++14
pair<iterator,iterator> equal_range(const key_type& k);
pair<const_iterator,const_iterator> equal_range(const key_type& k) const;
template<typename K>
pair<iterator,iterator> equal_range(const K& x); // C++14
template<typename K>
pair<const_iterator,const_iterator> equal_range(const K& x) const; // C++14
};
template <class Key, class Compare, class Allocator>
bool
operator==(const multiset<Key, Compare, Allocator>& x,
const multiset<Key, Compare, Allocator>& y);
template <class Key, class Compare, class Allocator>
bool
operator< (const multiset<Key, Compare, Allocator>& x,
const multiset<Key, Compare, Allocator>& y);
template <class Key, class Compare, class Allocator>
bool
operator!=(const multiset<Key, Compare, Allocator>& x,
const multiset<Key, Compare, Allocator>& y);
template <class Key, class Compare, class Allocator>
bool
operator> (const multiset<Key, Compare, Allocator>& x,
const multiset<Key, Compare, Allocator>& y);
template <class Key, class Compare, class Allocator>
bool
operator>=(const multiset<Key, Compare, Allocator>& x,
const multiset<Key, Compare, Allocator>& y);
template <class Key, class Compare, class Allocator>
bool
operator<=(const multiset<Key, Compare, Allocator>& x,
const multiset<Key, Compare, Allocator>& y);
// specialized algorithms:
template <class Key, class Compare, class Allocator>
void
swap(multiset<Key, Compare, Allocator>& x, multiset<Key, Compare, Allocator>& y)
noexcept(noexcept(x.swap(y)));
template <class Key, class Compare, class Allocator, class Predicate>
void erase_if(multiset<Key, Compare, Allocator>& c, Predicate pred); // C++20
} // std
*/
template <class _Key, class _Compare, class _Allocator>
class multiset;
template <class _Key, class _Compare = less<_Key>,
class _Allocator = allocator<_Key> >
class _LIBCPP_TEMPLATE_VIS set
{
public:
// types:
typedef _Key key_type;
typedef key_type value_type;
typedef _Compare key_compare;
typedef key_compare value_compare;
typedef typename __identity<_Allocator>::type allocator_type;
typedef value_type& reference;
typedef const value_type& const_reference;
static_assert((is_same<typename allocator_type::value_type, value_type>::value),
"Allocator::value_type must be same type as value_type");
private:
typedef __tree<value_type, value_compare, allocator_type> __base;
typedef allocator_traits<allocator_type> __alloc_traits;
typedef typename __base::__node_holder __node_holder;
__base __tree_;
public:
typedef typename __base::pointer pointer;
typedef typename __base::const_pointer const_pointer;
typedef typename __base::size_type size_type;
typedef typename __base::difference_type difference_type;
typedef typename __base::const_iterator iterator;
typedef typename __base::const_iterator const_iterator;
typedef _VSTD::reverse_iterator<iterator> reverse_iterator;
typedef _VSTD::reverse_iterator<const_iterator> const_reverse_iterator;
#if _LIBCPP_STD_VER > 14
typedef __set_node_handle<typename __base::__node, allocator_type> node_type;
typedef __insert_return_type<iterator, node_type> insert_return_type;
#endif
template <class _Key2, class _Compare2, class _Alloc2>
friend class _LIBCPP_TEMPLATE_VIS set;
template <class _Key2, class _Compare2, class _Alloc2>
friend class _LIBCPP_TEMPLATE_VIS multiset;
_LIBCPP_INLINE_VISIBILITY
set()
_NOEXCEPT_(
is_nothrow_default_constructible<allocator_type>::value &&
is_nothrow_default_constructible<key_compare>::value &&
is_nothrow_copy_constructible<key_compare>::value)
: __tree_(value_compare()) {}
_LIBCPP_INLINE_VISIBILITY
explicit set(const value_compare& __comp)
_NOEXCEPT_(
is_nothrow_default_constructible<allocator_type>::value &&
is_nothrow_copy_constructible<key_compare>::value)
: __tree_(__comp) {}
_LIBCPP_INLINE_VISIBILITY
explicit set(const value_compare& __comp, const allocator_type& __a)
: __tree_(__comp, __a) {}
template <class _InputIterator>
_LIBCPP_INLINE_VISIBILITY
set(_InputIterator __f, _InputIterator __l,
const value_compare& __comp = value_compare())
: __tree_(__comp)
{
insert(__f, __l);
}
template <class _InputIterator>
_LIBCPP_INLINE_VISIBILITY
set(_InputIterator __f, _InputIterator __l, const value_compare& __comp,
const allocator_type& __a)
: __tree_(__comp, __a)
{
insert(__f, __l);
}
#if _LIBCPP_STD_VER > 11
template <class _InputIterator>
_LIBCPP_INLINE_VISIBILITY
set(_InputIterator __f, _InputIterator __l, const allocator_type& __a)
: set(__f, __l, key_compare(), __a) {}
#endif
_LIBCPP_INLINE_VISIBILITY
set(const set& __s)
: __tree_(__s.__tree_)
{
insert(__s.begin(), __s.end());
}
_LIBCPP_INLINE_VISIBILITY
set& operator=(const set& __s)
{
__tree_ = __s.__tree_;
return *this;
}
#ifndef _LIBCPP_CXX03_LANG
_LIBCPP_INLINE_VISIBILITY
set(set&& __s)
_NOEXCEPT_(is_nothrow_move_constructible<__base>::value)
: __tree_(_VSTD::move(__s.__tree_)) {}
#endif // _LIBCPP_CXX03_LANG
_LIBCPP_INLINE_VISIBILITY
explicit set(const allocator_type& __a)
: __tree_(__a) {}
_LIBCPP_INLINE_VISIBILITY
set(const set& __s, const allocator_type& __a)
: __tree_(__s.__tree_.value_comp(), __a)
{
insert(__s.begin(), __s.end());
}
#ifndef _LIBCPP_CXX03_LANG
set(set&& __s, const allocator_type& __a);
_LIBCPP_INLINE_VISIBILITY
set(initializer_list<value_type> __il, const value_compare& __comp = value_compare())
: __tree_(__comp)
{
insert(__il.begin(), __il.end());
}
_LIBCPP_INLINE_VISIBILITY
set(initializer_list<value_type> __il, const value_compare& __comp,
const allocator_type& __a)
: __tree_(__comp, __a)
{
insert(__il.begin(), __il.end());
}
#if _LIBCPP_STD_VER > 11
_LIBCPP_INLINE_VISIBILITY
set(initializer_list<value_type> __il, const allocator_type& __a)
: set(__il, key_compare(), __a) {}
#endif
_LIBCPP_INLINE_VISIBILITY
set& operator=(initializer_list<value_type> __il)
{
__tree_.__assign_unique(__il.begin(), __il.end());
return *this;
}
_LIBCPP_INLINE_VISIBILITY
set& operator=(set&& __s)
_NOEXCEPT_(is_nothrow_move_assignable<__base>::value)
{
__tree_ = _VSTD::move(__s.__tree_);
return *this;
}
#endif // _LIBCPP_CXX03_LANG
_LIBCPP_INLINE_VISIBILITY
~set() {
static_assert(sizeof(__diagnose_non_const_comparator<_Key, _Compare>()), "");
}
_LIBCPP_INLINE_VISIBILITY
iterator begin() _NOEXCEPT {return __tree_.begin();}
_LIBCPP_INLINE_VISIBILITY
const_iterator begin() const _NOEXCEPT {return __tree_.begin();}
_LIBCPP_INLINE_VISIBILITY
iterator end() _NOEXCEPT {return __tree_.end();}
_LIBCPP_INLINE_VISIBILITY
const_iterator end() const _NOEXCEPT {return __tree_.end();}
_LIBCPP_INLINE_VISIBILITY
reverse_iterator rbegin() _NOEXCEPT
{return reverse_iterator(end());}
_LIBCPP_INLINE_VISIBILITY
const_reverse_iterator rbegin() const _NOEXCEPT
{return const_reverse_iterator(end());}
_LIBCPP_INLINE_VISIBILITY
reverse_iterator rend() _NOEXCEPT
{return reverse_iterator(begin());}
_LIBCPP_INLINE_VISIBILITY
const_reverse_iterator rend() const _NOEXCEPT
{return const_reverse_iterator(begin());}
_LIBCPP_INLINE_VISIBILITY
const_iterator cbegin() const _NOEXCEPT {return begin();}
_LIBCPP_INLINE_VISIBILITY
const_iterator cend() const _NOEXCEPT {return end();}
_LIBCPP_INLINE_VISIBILITY
const_reverse_iterator crbegin() const _NOEXCEPT {return rbegin();}
_LIBCPP_INLINE_VISIBILITY
const_reverse_iterator crend() const _NOEXCEPT {return rend();}
_LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
bool empty() const _NOEXCEPT {return __tree_.size() == 0;}
_LIBCPP_INLINE_VISIBILITY
size_type size() const _NOEXCEPT {return __tree_.size();}
_LIBCPP_INLINE_VISIBILITY
size_type max_size() const _NOEXCEPT {return __tree_.max_size();}
// modifiers:
#ifndef _LIBCPP_CXX03_LANG
template <class... _Args>
_LIBCPP_INLINE_VISIBILITY
pair<iterator, bool> emplace(_Args&&... __args)
{return __tree_.__emplace_unique(_VSTD::forward<_Args>(__args)...);}
template <class... _Args>
_LIBCPP_INLINE_VISIBILITY
iterator emplace_hint(const_iterator __p, _Args&&... __args)
{return __tree_.__emplace_hint_unique(__p, _VSTD::forward<_Args>(__args)...);}
#endif // _LIBCPP_CXX03_LANG
_LIBCPP_INLINE_VISIBILITY
pair<iterator,bool> insert(const value_type& __v)
{return __tree_.__insert_unique(__v);}
_LIBCPP_INLINE_VISIBILITY
iterator insert(const_iterator __p, const value_type& __v)
{return __tree_.__insert_unique(__p, __v);}
template <class _InputIterator>
_LIBCPP_INLINE_VISIBILITY
void insert(_InputIterator __f, _InputIterator __l)
{
for (const_iterator __e = cend(); __f != __l; ++__f)
__tree_.__insert_unique(__e, *__f);
}
#ifndef _LIBCPP_CXX03_LANG
_LIBCPP_INLINE_VISIBILITY
pair<iterator,bool> insert(value_type&& __v)
{return __tree_.__insert_unique(_VSTD::move(__v));}
_LIBCPP_INLINE_VISIBILITY
iterator insert(const_iterator __p, value_type&& __v)
{return __tree_.__insert_unique(__p, _VSTD::move(__v));}
_LIBCPP_INLINE_VISIBILITY
void insert(initializer_list<value_type> __il)
{insert(__il.begin(), __il.end());}
#endif // _LIBCPP_CXX03_LANG
_LIBCPP_INLINE_VISIBILITY
iterator erase(const_iterator __p) {return __tree_.erase(__p);}
_LIBCPP_INLINE_VISIBILITY
size_type erase(const key_type& __k)
{return __tree_.__erase_unique(__k);}
_LIBCPP_INLINE_VISIBILITY
iterator erase(const_iterator __f, const_iterator __l)
{return __tree_.erase(__f, __l);}
_LIBCPP_INLINE_VISIBILITY
void clear() _NOEXCEPT {__tree_.clear();}
#if _LIBCPP_STD_VER > 14
_LIBCPP_INLINE_VISIBILITY
insert_return_type insert(node_type&& __nh)
{
_LIBCPP_ASSERT(__nh.empty() || __nh.get_allocator() == get_allocator(),
"node_type with incompatible allocator passed to set::insert()");
return __tree_.template __node_handle_insert_unique<
node_type, insert_return_type>(_VSTD::move(__nh));
}
_LIBCPP_INLINE_VISIBILITY
iterator insert(const_iterator __hint, node_type&& __nh)
{
_LIBCPP_ASSERT(__nh.empty() || __nh.get_allocator() == get_allocator(),
"node_type with incompatible allocator passed to set::insert()");
return __tree_.template __node_handle_insert_unique<node_type>(
__hint, _VSTD::move(__nh));
}
_LIBCPP_INLINE_VISIBILITY
node_type extract(key_type const& __key)
{
return __tree_.template __node_handle_extract<node_type>(__key);
}
_LIBCPP_INLINE_VISIBILITY
node_type extract(const_iterator __it)
{
return __tree_.template __node_handle_extract<node_type>(__it);
}
template <class _Compare2>
_LIBCPP_INLINE_VISIBILITY
void merge(set<key_type, _Compare2, allocator_type>& __source)
{
_LIBCPP_ASSERT(__source.get_allocator() == get_allocator(),
"merging container with incompatible allocator");
__tree_.__node_handle_merge_unique(__source.__tree_);
}
template <class _Compare2>
_LIBCPP_INLINE_VISIBILITY
void merge(set<key_type, _Compare2, allocator_type>&& __source)
{
_LIBCPP_ASSERT(__source.get_allocator() == get_allocator(),
"merging container with incompatible allocator");
__tree_.__node_handle_merge_unique(__source.__tree_);
}
template <class _Compare2>
_LIBCPP_INLINE_VISIBILITY
void merge(multiset<key_type, _Compare2, allocator_type>& __source)
{
_LIBCPP_ASSERT(__source.get_allocator() == get_allocator(),
"merging container with incompatible allocator");
__tree_.__node_handle_merge_unique(__source.__tree_);
}
template <class _Compare2>
_LIBCPP_INLINE_VISIBILITY
void merge(multiset<key_type, _Compare2, allocator_type>&& __source)
{
_LIBCPP_ASSERT(__source.get_allocator() == get_allocator(),
"merging container with incompatible allocator");
__tree_.__node_handle_merge_unique(__source.__tree_);
}
#endif
_LIBCPP_INLINE_VISIBILITY
void swap(set& __s) _NOEXCEPT_(__is_nothrow_swappable<__base>::value)
{__tree_.swap(__s.__tree_);}
_LIBCPP_INLINE_VISIBILITY
allocator_type get_allocator() const _NOEXCEPT {return __tree_.__alloc();}
_LIBCPP_INLINE_VISIBILITY
key_compare key_comp() const {return __tree_.value_comp();}
_LIBCPP_INLINE_VISIBILITY
value_compare value_comp() const {return __tree_.value_comp();}
// set operations:
_LIBCPP_INLINE_VISIBILITY
iterator find(const key_type& __k) {return __tree_.find(__k);}
_LIBCPP_INLINE_VISIBILITY
const_iterator find(const key_type& __k) const {return __tree_.find(__k);}
#if _LIBCPP_STD_VER > 11
template <typename _K2>
_LIBCPP_INLINE_VISIBILITY
typename enable_if<__is_transparent<_Compare, _K2>::value,iterator>::type
find(const _K2& __k) {return __tree_.find(__k);}
template <typename _K2>
_LIBCPP_INLINE_VISIBILITY
typename enable_if<__is_transparent<_Compare, _K2>::value,const_iterator>::type
find(const _K2& __k) const {return __tree_.find(__k);}
#endif
_LIBCPP_INLINE_VISIBILITY
size_type count(const key_type& __k) const
{return __tree_.__count_unique(__k);}
#if _LIBCPP_STD_VER > 11
template <typename _K2>
_LIBCPP_INLINE_VISIBILITY
typename enable_if<__is_transparent<_Compare, _K2>::value,size_type>::type
count(const _K2& __k) const {return __tree_.__count_multi(__k);}
#endif
#if _LIBCPP_STD_VER > 17
_LIBCPP_INLINE_VISIBILITY
bool contains(const key_type& __k) const {return find(__k) != end();}
#endif // _LIBCPP_STD_VER > 17
_LIBCPP_INLINE_VISIBILITY
iterator lower_bound(const key_type& __k)
{return __tree_.lower_bound(__k);}
_LIBCPP_INLINE_VISIBILITY
const_iterator lower_bound(const key_type& __k) const
{return __tree_.lower_bound(__k);}
#if _LIBCPP_STD_VER > 11
template <typename _K2>
_LIBCPP_INLINE_VISIBILITY
typename enable_if<__is_transparent<_Compare, _K2>::value,iterator>::type
lower_bound(const _K2& __k) {return __tree_.lower_bound(__k);}
template <typename _K2>
_LIBCPP_INLINE_VISIBILITY
typename enable_if<__is_transparent<_Compare, _K2>::value,const_iterator>::type
lower_bound(const _K2& __k) const {return __tree_.lower_bound(__k);}
#endif
_LIBCPP_INLINE_VISIBILITY
iterator upper_bound(const key_type& __k)
{return __tree_.upper_bound(__k);}
_LIBCPP_INLINE_VISIBILITY
const_iterator upper_bound(const key_type& __k) const
{return __tree_.upper_bound(__k);}
#if _LIBCPP_STD_VER > 11
template <typename _K2>
_LIBCPP_INLINE_VISIBILITY
typename enable_if<__is_transparent<_Compare, _K2>::value,iterator>::type
upper_bound(const _K2& __k) {return __tree_.upper_bound(__k);}
template <typename _K2>
_LIBCPP_INLINE_VISIBILITY
typename enable_if<__is_transparent<_Compare, _K2>::value,const_iterator>::type
upper_bound(const _K2& __k) const {return __tree_.upper_bound(__k);}
#endif
_LIBCPP_INLINE_VISIBILITY
pair<iterator,iterator> equal_range(const key_type& __k)
{return __tree_.__equal_range_unique(__k);}
_LIBCPP_INLINE_VISIBILITY
pair<const_iterator,const_iterator> equal_range(const key_type& __k) const
{return __tree_.__equal_range_unique(__k);}
#if _LIBCPP_STD_VER > 11
template <typename _K2>
_LIBCPP_INLINE_VISIBILITY
typename enable_if<__is_transparent<_Compare, _K2>::value,pair<iterator,iterator>>::type
equal_range(const _K2& __k) {return __tree_.__equal_range_multi(__k);}
template <typename _K2>
_LIBCPP_INLINE_VISIBILITY
typename enable_if<__is_transparent<_Compare, _K2>::value,pair<const_iterator,const_iterator>>::type
equal_range(const _K2& __k) const {return __tree_.__equal_range_multi(__k);}
#endif
};
#ifndef _LIBCPP_HAS_NO_DEDUCTION_GUIDES
template<class _InputIterator,
class _Compare = less<typename iterator_traits<_InputIterator>::value_type>,
class _Allocator = allocator<typename iterator_traits<_InputIterator>::value_type>,
class = _EnableIf<__is_allocator<_Allocator>::value, void>,
class = _EnableIf<!__is_allocator<_Compare>::value, void>>
set(_InputIterator, _InputIterator, _Compare = _Compare(), _Allocator = _Allocator())
-> set<typename iterator_traits<_InputIterator>::value_type, _Compare, _Allocator>;
template<class _Key, class _Compare = less<_Key>,
class _Allocator = allocator<_Key>,
class = _EnableIf<__is_allocator<_Allocator>::value, void>,
class = _EnableIf<!__is_allocator<_Compare>::value, void>>
set(initializer_list<_Key>, _Compare = _Compare(), _Allocator = _Allocator())
-> set<_Key, _Compare, _Allocator>;
template<class _InputIterator, class _Allocator,
class = _EnableIf<__is_allocator<_Allocator>::value, void>>
set(_InputIterator, _InputIterator, _Allocator)
-> set<typename iterator_traits<_InputIterator>::value_type,
less<typename iterator_traits<_InputIterator>::value_type>, _Allocator>;
template<class _Key, class _Allocator,
class = _EnableIf<__is_allocator<_Allocator>::value, void>>
set(initializer_list<_Key>, _Allocator)
-> set<_Key, less<_Key>, _Allocator>;
#endif
#ifndef _LIBCPP_CXX03_LANG
template <class _Key, class _Compare, class _Allocator>
set<_Key, _Compare, _Allocator>::set(set&& __s, const allocator_type& __a)
: __tree_(_VSTD::move(__s.__tree_), __a)
{
if (__a != __s.get_allocator())
{
const_iterator __e = cend();
while (!__s.empty())
insert(__e, _VSTD::move(__s.__tree_.remove(__s.begin())->__value_));
}
}
#endif // _LIBCPP_CXX03_LANG
template <class _Key, class _Compare, class _Allocator>
inline _LIBCPP_INLINE_VISIBILITY
bool
operator==(const set<_Key, _Compare, _Allocator>& __x,
const set<_Key, _Compare, _Allocator>& __y)
{
return __x.size() == __y.size() && _VSTD::equal(__x.begin(), __x.end(), __y.begin());
}
template <class _Key, class _Compare, class _Allocator>
inline _LIBCPP_INLINE_VISIBILITY
bool
operator< (const set<_Key, _Compare, _Allocator>& __x,
const set<_Key, _Compare, _Allocator>& __y)
{
return _VSTD::lexicographical_compare(__x.begin(), __x.end(), __y.begin(), __y.end());
}
template <class _Key, class _Compare, class _Allocator>
inline _LIBCPP_INLINE_VISIBILITY
bool
operator!=(const set<_Key, _Compare, _Allocator>& __x,
const set<_Key, _Compare, _Allocator>& __y)
{
return !(__x == __y);
}
template <class _Key, class _Compare, class _Allocator>
inline _LIBCPP_INLINE_VISIBILITY
bool
operator> (const set<_Key, _Compare, _Allocator>& __x,
const set<_Key, _Compare, _Allocator>& __y)
{
return __y < __x;
}
template <class _Key, class _Compare, class _Allocator>
inline _LIBCPP_INLINE_VISIBILITY
bool
operator>=(const set<_Key, _Compare, _Allocator>& __x,
const set<_Key, _Compare, _Allocator>& __y)
{
return !(__x < __y);
}
template <class _Key, class _Compare, class _Allocator>
inline _LIBCPP_INLINE_VISIBILITY
bool
operator<=(const set<_Key, _Compare, _Allocator>& __x,
const set<_Key, _Compare, _Allocator>& __y)
{
return !(__y < __x);
}
// specialized algorithms:
template <class _Key, class _Compare, class _Allocator>
inline _LIBCPP_INLINE_VISIBILITY
void
swap(set<_Key, _Compare, _Allocator>& __x,
set<_Key, _Compare, _Allocator>& __y)
_NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
{
__x.swap(__y);
}
#if _LIBCPP_STD_VER > 17
template <class _Key, class _Compare, class _Allocator, class _Predicate>
inline _LIBCPP_INLINE_VISIBILITY
void erase_if(set<_Key, _Compare, _Allocator>& __c, _Predicate __pred)
{ __libcpp_erase_if_container(__c, __pred); }
#endif
template <class _Key, class _Compare = less<_Key>,
class _Allocator = allocator<_Key> >
class _LIBCPP_TEMPLATE_VIS multiset
{
public:
// types:
typedef _Key key_type;
typedef key_type value_type;
typedef _Compare key_compare;
typedef key_compare value_compare;
typedef typename __identity<_Allocator>::type allocator_type;
typedef value_type& reference;
typedef const value_type& const_reference;
static_assert((is_same<typename allocator_type::value_type, value_type>::value),
"Allocator::value_type must be same type as value_type");
private:
typedef __tree<value_type, value_compare, allocator_type> __base;
typedef allocator_traits<allocator_type> __alloc_traits;
typedef typename __base::__node_holder __node_holder;
__base __tree_;
public:
typedef typename __base::pointer pointer;
typedef typename __base::const_pointer const_pointer;
typedef typename __base::size_type size_type;
typedef typename __base::difference_type difference_type;
typedef typename __base::const_iterator iterator;
typedef typename __base::const_iterator const_iterator;
typedef _VSTD::reverse_iterator<iterator> reverse_iterator;
typedef _VSTD::reverse_iterator<const_iterator> const_reverse_iterator;
#if _LIBCPP_STD_VER > 14
typedef __set_node_handle<typename __base::__node, allocator_type> node_type;
#endif
template <class _Key2, class _Compare2, class _Alloc2>
friend class _LIBCPP_TEMPLATE_VIS set;
template <class _Key2, class _Compare2, class _Alloc2>
friend class _LIBCPP_TEMPLATE_VIS multiset;
// construct/copy/destroy:
_LIBCPP_INLINE_VISIBILITY
multiset()
_NOEXCEPT_(
is_nothrow_default_constructible<allocator_type>::value &&
is_nothrow_default_constructible<key_compare>::value &&
is_nothrow_copy_constructible<key_compare>::value)
: __tree_(value_compare()) {}
_LIBCPP_INLINE_VISIBILITY
explicit multiset(const value_compare& __comp)
_NOEXCEPT_(
is_nothrow_default_constructible<allocator_type>::value &&
is_nothrow_copy_constructible<key_compare>::value)
: __tree_(__comp) {}
_LIBCPP_INLINE_VISIBILITY
explicit multiset(const value_compare& __comp, const allocator_type& __a)
: __tree_(__comp, __a) {}
template <class _InputIterator>
_LIBCPP_INLINE_VISIBILITY
multiset(_InputIterator __f, _InputIterator __l,
const value_compare& __comp = value_compare())
: __tree_(__comp)
{
insert(__f, __l);
}
#if _LIBCPP_STD_VER > 11
template <class _InputIterator>
_LIBCPP_INLINE_VISIBILITY
multiset(_InputIterator __f, _InputIterator __l, const allocator_type& __a)
: multiset(__f, __l, key_compare(), __a) {}
#endif
template <class _InputIterator>
_LIBCPP_INLINE_VISIBILITY
multiset(_InputIterator __f, _InputIterator __l,
const value_compare& __comp, const allocator_type& __a)
: __tree_(__comp, __a)
{
insert(__f, __l);
}
_LIBCPP_INLINE_VISIBILITY
multiset(const multiset& __s)
: __tree_(__s.__tree_.value_comp(),
__alloc_traits::select_on_container_copy_construction(__s.__tree_.__alloc()))
{
insert(__s.begin(), __s.end());
}
_LIBCPP_INLINE_VISIBILITY
multiset& operator=(const multiset& __s)
{
__tree_ = __s.__tree_;
return *this;
}
#ifndef _LIBCPP_CXX03_LANG
_LIBCPP_INLINE_VISIBILITY
multiset(multiset&& __s)
_NOEXCEPT_(is_nothrow_move_constructible<__base>::value)
: __tree_(_VSTD::move(__s.__tree_)) {}
multiset(multiset&& __s, const allocator_type& __a);
#endif // _LIBCPP_CXX03_LANG
_LIBCPP_INLINE_VISIBILITY
explicit multiset(const allocator_type& __a)
: __tree_(__a) {}
_LIBCPP_INLINE_VISIBILITY
multiset(const multiset& __s, const allocator_type& __a)
: __tree_(__s.__tree_.value_comp(), __a)
{
insert(__s.begin(), __s.end());
}
#ifndef _LIBCPP_CXX03_LANG
_LIBCPP_INLINE_VISIBILITY
multiset(initializer_list<value_type> __il, const value_compare& __comp = value_compare())
: __tree_(__comp)
{
insert(__il.begin(), __il.end());
}
_LIBCPP_INLINE_VISIBILITY
multiset(initializer_list<value_type> __il, const value_compare& __comp,
const allocator_type& __a)
: __tree_(__comp, __a)
{
insert(__il.begin(), __il.end());
}
#if _LIBCPP_STD_VER > 11
_LIBCPP_INLINE_VISIBILITY
multiset(initializer_list<value_type> __il, const allocator_type& __a)
: multiset(__il, key_compare(), __a) {}
#endif
_LIBCPP_INLINE_VISIBILITY
multiset& operator=(initializer_list<value_type> __il)
{
__tree_.__assign_multi(__il.begin(), __il.end());
return *this;
}
_LIBCPP_INLINE_VISIBILITY
multiset& operator=(multiset&& __s)
_NOEXCEPT_(is_nothrow_move_assignable<__base>::value)
{
__tree_ = _VSTD::move(__s.__tree_);
return *this;
}
#endif // _LIBCPP_CXX03_LANG
_LIBCPP_INLINE_VISIBILITY
~multiset() {
static_assert(sizeof(__diagnose_non_const_comparator<_Key, _Compare>()), "");
}
_LIBCPP_INLINE_VISIBILITY
iterator begin() _NOEXCEPT {return __tree_.begin();}
_LIBCPP_INLINE_VISIBILITY
const_iterator begin() const _NOEXCEPT {return __tree_.begin();}
_LIBCPP_INLINE_VISIBILITY
iterator end() _NOEXCEPT {return __tree_.end();}
_LIBCPP_INLINE_VISIBILITY
const_iterator end() const _NOEXCEPT {return __tree_.end();}
_LIBCPP_INLINE_VISIBILITY
reverse_iterator rbegin() _NOEXCEPT
{return reverse_iterator(end());}
_LIBCPP_INLINE_VISIBILITY
const_reverse_iterator rbegin() const _NOEXCEPT
{return const_reverse_iterator(end());}
_LIBCPP_INLINE_VISIBILITY
reverse_iterator rend() _NOEXCEPT
{return reverse_iterator(begin());}
_LIBCPP_INLINE_VISIBILITY
const_reverse_iterator rend() const _NOEXCEPT
{return const_reverse_iterator(begin());}
_LIBCPP_INLINE_VISIBILITY
const_iterator cbegin() const _NOEXCEPT {return begin();}
_LIBCPP_INLINE_VISIBILITY
const_iterator cend() const _NOEXCEPT {return end();}
_LIBCPP_INLINE_VISIBILITY
const_reverse_iterator crbegin() const _NOEXCEPT {return rbegin();}
_LIBCPP_INLINE_VISIBILITY
const_reverse_iterator crend() const _NOEXCEPT {return rend();}
_LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
bool empty() const _NOEXCEPT {return __tree_.size() == 0;}
_LIBCPP_INLINE_VISIBILITY
size_type size() const _NOEXCEPT {return __tree_.size();}
_LIBCPP_INLINE_VISIBILITY
size_type max_size() const _NOEXCEPT {return __tree_.max_size();}
// modifiers:
#ifndef _LIBCPP_CXX03_LANG
template <class... _Args>
_LIBCPP_INLINE_VISIBILITY
iterator emplace(_Args&&... __args)
{return __tree_.__emplace_multi(_VSTD::forward<_Args>(__args)...);}
template <class... _Args>
_LIBCPP_INLINE_VISIBILITY
iterator emplace_hint(const_iterator __p, _Args&&... __args)
{return __tree_.__emplace_hint_multi(__p, _VSTD::forward<_Args>(__args)...);}
#endif // _LIBCPP_CXX03_LANG
_LIBCPP_INLINE_VISIBILITY
iterator insert(const value_type& __v)
{return __tree_.__insert_multi(__v);}
_LIBCPP_INLINE_VISIBILITY
iterator insert(const_iterator __p, const value_type& __v)
{return __tree_.__insert_multi(__p, __v);}
template <class _InputIterator>
_LIBCPP_INLINE_VISIBILITY
void insert(_InputIterator __f, _InputIterator __l)
{
for (const_iterator __e = cend(); __f != __l; ++__f)
__tree_.__insert_multi(__e, *__f);
}
#ifndef _LIBCPP_CXX03_LANG
_LIBCPP_INLINE_VISIBILITY
iterator insert(value_type&& __v)
{return __tree_.__insert_multi(_VSTD::move(__v));}
_LIBCPP_INLINE_VISIBILITY
iterator insert(const_iterator __p, value_type&& __v)
{return __tree_.__insert_multi(__p, _VSTD::move(__v));}
_LIBCPP_INLINE_VISIBILITY
void insert(initializer_list<value_type> __il)
{insert(__il.begin(), __il.end());}
#endif // _LIBCPP_CXX03_LANG
_LIBCPP_INLINE_VISIBILITY
iterator erase(const_iterator __p) {return __tree_.erase(__p);}
_LIBCPP_INLINE_VISIBILITY
size_type erase(const key_type& __k) {return __tree_.__erase_multi(__k);}
_LIBCPP_INLINE_VISIBILITY
iterator erase(const_iterator __f, const_iterator __l)
{return __tree_.erase(__f, __l);}
_LIBCPP_INLINE_VISIBILITY
void clear() _NOEXCEPT {__tree_.clear();}
#if _LIBCPP_STD_VER > 14
_LIBCPP_INLINE_VISIBILITY
iterator insert(node_type&& __nh)
{
_LIBCPP_ASSERT(__nh.empty() || __nh.get_allocator() == get_allocator(),
"node_type with incompatible allocator passed to multiset::insert()");
return __tree_.template __node_handle_insert_multi<node_type>(
_VSTD::move(__nh));
}
_LIBCPP_INLINE_VISIBILITY
iterator insert(const_iterator __hint, node_type&& __nh)
{
_LIBCPP_ASSERT(__nh.empty() || __nh.get_allocator() == get_allocator(),
"node_type with incompatible allocator passed to multiset::insert()");
return __tree_.template __node_handle_insert_multi<node_type>(
__hint, _VSTD::move(__nh));
}
_LIBCPP_INLINE_VISIBILITY
node_type extract(key_type const& __key)
{
return __tree_.template __node_handle_extract<node_type>(__key);
}
_LIBCPP_INLINE_VISIBILITY
node_type extract(const_iterator __it)
{
return __tree_.template __node_handle_extract<node_type>(__it);
}
template <class _Compare2>
_LIBCPP_INLINE_VISIBILITY
void merge(multiset<key_type, _Compare2, allocator_type>& __source)
{
_LIBCPP_ASSERT(__source.get_allocator() == get_allocator(),
"merging container with incompatible allocator");
__tree_.__node_handle_merge_multi(__source.__tree_);
}
template <class _Compare2>
_LIBCPP_INLINE_VISIBILITY
void merge(multiset<key_type, _Compare2, allocator_type>&& __source)
{
_LIBCPP_ASSERT(__source.get_allocator() == get_allocator(),
"merging container with incompatible allocator");
__tree_.__node_handle_merge_multi(__source.__tree_);
}
template <class _Compare2>
_LIBCPP_INLINE_VISIBILITY
void merge(set<key_type, _Compare2, allocator_type>& __source)
{
_LIBCPP_ASSERT(__source.get_allocator() == get_allocator(),
"merging container with incompatible allocator");
__tree_.__node_handle_merge_multi(__source.__tree_);
}
template <class _Compare2>
_LIBCPP_INLINE_VISIBILITY
void merge(set<key_type, _Compare2, allocator_type>&& __source)
{
_LIBCPP_ASSERT(__source.get_allocator() == get_allocator(),
"merging container with incompatible allocator");
__tree_.__node_handle_merge_multi(__source.__tree_);
}
#endif
_LIBCPP_INLINE_VISIBILITY
void swap(multiset& __s)
_NOEXCEPT_(__is_nothrow_swappable<__base>::value)
{__tree_.swap(__s.__tree_);}
_LIBCPP_INLINE_VISIBILITY
allocator_type get_allocator() const _NOEXCEPT {return __tree_.__alloc();}
_LIBCPP_INLINE_VISIBILITY
key_compare key_comp() const {return __tree_.value_comp();}
_LIBCPP_INLINE_VISIBILITY
value_compare value_comp() const {return __tree_.value_comp();}
// set operations:
_LIBCPP_INLINE_VISIBILITY
iterator find(const key_type& __k) {return __tree_.find(__k);}
_LIBCPP_INLINE_VISIBILITY
const_iterator find(const key_type& __k) const {return __tree_.find(__k);}
#if _LIBCPP_STD_VER > 11
template <typename _K2>
_LIBCPP_INLINE_VISIBILITY
typename _VSTD::enable_if<_VSTD::__is_transparent<_Compare, _K2>::value,iterator>::type
find(const _K2& __k) {return __tree_.find(__k);}
template <typename _K2>
_LIBCPP_INLINE_VISIBILITY
typename _VSTD::enable_if<_VSTD::__is_transparent<_Compare, _K2>::value,const_iterator>::type
find(const _K2& __k) const {return __tree_.find(__k);}
#endif
_LIBCPP_INLINE_VISIBILITY
size_type count(const key_type& __k) const
{return __tree_.__count_multi(__k);}
#if _LIBCPP_STD_VER > 11
template <typename _K2>
_LIBCPP_INLINE_VISIBILITY
typename enable_if<__is_transparent<_Compare, _K2>::value,size_type>::type
count(const _K2& __k) const {return __tree_.__count_multi(__k);}
#endif
#if _LIBCPP_STD_VER > 17
_LIBCPP_INLINE_VISIBILITY
bool contains(const key_type& __k) const {return find(__k) != end();}
#endif // _LIBCPP_STD_VER > 17
_LIBCPP_INLINE_VISIBILITY
iterator lower_bound(const key_type& __k)
{return __tree_.lower_bound(__k);}
_LIBCPP_INLINE_VISIBILITY
const_iterator lower_bound(const key_type& __k) const
{return __tree_.lower_bound(__k);}
#if _LIBCPP_STD_VER > 11
template <typename _K2>
_LIBCPP_INLINE_VISIBILITY
typename _VSTD::enable_if<_VSTD::__is_transparent<_Compare, _K2>::value,iterator>::type
lower_bound(const _K2& __k) {return __tree_.lower_bound(__k);}
template <typename _K2>
_LIBCPP_INLINE_VISIBILITY
typename _VSTD::enable_if<_VSTD::__is_transparent<_Compare, _K2>::value,const_iterator>::type
lower_bound(const _K2& __k) const {return __tree_.lower_bound(__k);}
#endif
_LIBCPP_INLINE_VISIBILITY
iterator upper_bound(const key_type& __k)
{return __tree_.upper_bound(__k);}
_LIBCPP_INLINE_VISIBILITY
const_iterator upper_bound(const key_type& __k) const
{return __tree_.upper_bound(__k);}
#if _LIBCPP_STD_VER > 11
template <typename _K2>
_LIBCPP_INLINE_VISIBILITY
typename _VSTD::enable_if<_VSTD::__is_transparent<_Compare, _K2>::value,iterator>::type
upper_bound(const _K2& __k) {return __tree_.upper_bound(__k);}
template <typename _K2>
_LIBCPP_INLINE_VISIBILITY
typename _VSTD::enable_if<_VSTD::__is_transparent<_Compare, _K2>::value,const_iterator>::type
upper_bound(const _K2& __k) const {return __tree_.upper_bound(__k);}
#endif
_LIBCPP_INLINE_VISIBILITY
pair<iterator,iterator> equal_range(const key_type& __k)
{return __tree_.__equal_range_multi(__k);}
_LIBCPP_INLINE_VISIBILITY
pair<const_iterator,const_iterator> equal_range(const key_type& __k) const
{return __tree_.__equal_range_multi(__k);}
#if _LIBCPP_STD_VER > 11
template <typename _K2>
_LIBCPP_INLINE_VISIBILITY
typename _VSTD::enable_if<_VSTD::__is_transparent<_Compare, _K2>::value,pair<iterator,iterator>>::type
equal_range(const _K2& __k) {return __tree_.__equal_range_multi(__k);}
template <typename _K2>
_LIBCPP_INLINE_VISIBILITY
typename _VSTD::enable_if<_VSTD::__is_transparent<_Compare, _K2>::value,pair<const_iterator,const_iterator>>::type
equal_range(const _K2& __k) const {return __tree_.__equal_range_multi(__k);}
#endif
};
#ifndef _LIBCPP_HAS_NO_DEDUCTION_GUIDES
template<class _InputIterator,
class _Compare = less<typename iterator_traits<_InputIterator>::value_type>,
class _Allocator = allocator<typename iterator_traits<_InputIterator>::value_type>,
class = _EnableIf<__is_allocator<_Allocator>::value, void>,
class = _EnableIf<!__is_allocator<_Compare>::value, void>>
multiset(_InputIterator, _InputIterator, _Compare = _Compare(), _Allocator = _Allocator())
-> multiset<typename iterator_traits<_InputIterator>::value_type, _Compare, _Allocator>;
template<class _Key, class _Compare = less<_Key>,
class _Allocator = allocator<_Key>,
class = _EnableIf<__is_allocator<_Allocator>::value, void>,
class = _EnableIf<!__is_allocator<_Compare>::value, void>>
multiset(initializer_list<_Key>, _Compare = _Compare(), _Allocator = _Allocator())
-> multiset<_Key, _Compare, _Allocator>;
template<class _InputIterator, class _Allocator,
class = _EnableIf<__is_allocator<_Allocator>::value, void>>
multiset(_InputIterator, _InputIterator, _Allocator)
-> multiset<typename iterator_traits<_InputIterator>::value_type,
less<typename iterator_traits<_InputIterator>::value_type>, _Allocator>;
template<class _Key, class _Allocator,
class = _EnableIf<__is_allocator<_Allocator>::value, void>>
multiset(initializer_list<_Key>, _Allocator)
-> multiset<_Key, less<_Key>, _Allocator>;
#endif
#ifndef _LIBCPP_CXX03_LANG
template <class _Key, class _Compare, class _Allocator>
multiset<_Key, _Compare, _Allocator>::multiset(multiset&& __s, const allocator_type& __a)
: __tree_(_VSTD::move(__s.__tree_), __a)
{
if (__a != __s.get_allocator())
{
const_iterator __e = cend();
while (!__s.empty())
insert(__e, _VSTD::move(__s.__tree_.remove(__s.begin())->__value_));
}
}
#endif // _LIBCPP_CXX03_LANG
template <class _Key, class _Compare, class _Allocator>
inline _LIBCPP_INLINE_VISIBILITY
bool
operator==(const multiset<_Key, _Compare, _Allocator>& __x,
const multiset<_Key, _Compare, _Allocator>& __y)
{
return __x.size() == __y.size() && _VSTD::equal(__x.begin(), __x.end(), __y.begin());
}
template <class _Key, class _Compare, class _Allocator>
inline _LIBCPP_INLINE_VISIBILITY
bool
operator< (const multiset<_Key, _Compare, _Allocator>& __x,
const multiset<_Key, _Compare, _Allocator>& __y)
{
return _VSTD::lexicographical_compare(__x.begin(), __x.end(), __y.begin(), __y.end());
}
template <class _Key, class _Compare, class _Allocator>
inline _LIBCPP_INLINE_VISIBILITY
bool
operator!=(const multiset<_Key, _Compare, _Allocator>& __x,
const multiset<_Key, _Compare, _Allocator>& __y)
{
return !(__x == __y);
}
template <class _Key, class _Compare, class _Allocator>
inline _LIBCPP_INLINE_VISIBILITY
bool
operator> (const multiset<_Key, _Compare, _Allocator>& __x,
const multiset<_Key, _Compare, _Allocator>& __y)
{
return __y < __x;
}
template <class _Key, class _Compare, class _Allocator>
inline _LIBCPP_INLINE_VISIBILITY
bool
operator>=(const multiset<_Key, _Compare, _Allocator>& __x,
const multiset<_Key, _Compare, _Allocator>& __y)
{
return !(__x < __y);
}
template <class _Key, class _Compare, class _Allocator>
inline _LIBCPP_INLINE_VISIBILITY
bool
operator<=(const multiset<_Key, _Compare, _Allocator>& __x,
const multiset<_Key, _Compare, _Allocator>& __y)
{
return !(__y < __x);
}
template <class _Key, class _Compare, class _Allocator>
inline _LIBCPP_INLINE_VISIBILITY
void
swap(multiset<_Key, _Compare, _Allocator>& __x,
multiset<_Key, _Compare, _Allocator>& __y)
_NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
{
__x.swap(__y);
}
#if _LIBCPP_STD_VER > 17
template <class _Key, class _Compare, class _Allocator, class _Predicate>
inline _LIBCPP_INLINE_VISIBILITY
void erase_if(multiset<_Key, _Compare, _Allocator>& __c, _Predicate __pred)
{ __libcpp_erase_if_container(__c, __pred); }
#endif
_LIBCPP_END_NAMESPACE_STD
#endif // _LIBCPP_SET
| 57,197 | 1,494 | jart/cosmopolitan | false |
cosmopolitan/third_party/libcxx/string.h | // -*- C++ -*-
//===--------------------------- string.h ---------------------------------===//
//
// 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_STRING_H
#define _LIBCPP_STRING_H
#include "third_party/libcxx/__config"
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
#pragma GCC system_header
#endif
#include "libc/str/str.h"
/*
string.h synopsis
Macros:
NULL
Types:
size_t
void* memcpy(void* restrict s1, const void* restrict s2, size_t n);
void* memmove(void* s1, const void* s2, size_t n);
char* strcpy (char* restrict s1, const char* restrict s2);
char* strncpy(char* restrict s1, const char* restrict s2, size_t n);
char* strcat (char* restrict s1, const char* restrict s2);
char* strncat(char* restrict s1, const char* restrict s2, size_t n);
int memcmp(const void* s1, const void* s2, size_t n);
int strcmp (const char* s1, const char* s2);
int strncmp(const char* s1, const char* s2, size_t n);
int strcoll(const char* s1, const char* s2);
size_t strxfrm(char* restrict s1, const char* restrict s2, size_t n);
const void* memchr(const void* s, int c, size_t n);
void* memchr( void* s, int c, size_t n);
const char* strchr(const char* s, int c);
char* strchr( char* s, int c);
size_t strcspn(const char* s1, const char* s2);
const char* strpbrk(const char* s1, const char* s2);
char* strpbrk( char* s1, const char* s2);
const char* strrchr(const char* s, int c);
char* strrchr( char* s, int c);
size_t strspn(const char* s1, const char* s2);
const char* strstr(const char* s1, const char* s2);
char* strstr( char* s1, const char* s2);
char* strtok(char* restrict s1, const char* restrict s2);
void* memset(void* s, int c, size_t n);
char* strerror(int errnum);
size_t strlen(const char* s);
*/
// MSVCRT, GNU libc and its derivates may already have the correct prototype in
// <string.h>. This macro can be defined by users if their C library provides
// the right signature.
#if defined(__CORRECT_ISO_CPP_STRING_H_PROTO) || defined(_LIBCPP_MSVCRT) || \
defined(__sun__) || defined(_STRING_H_CPLUSPLUS_98_CONFORMANCE_)
#define _LIBCPP_STRING_H_HAS_CONST_OVERLOADS
#endif
#if defined(__cplusplus) && !defined(_LIBCPP_STRING_H_HAS_CONST_OVERLOADS) && \
defined(_LIBCPP_PREFERRED_OVERLOAD)
extern "C++" {
inline _LIBCPP_INLINE_VISIBILITY char* __libcpp_strchr(const char* __s,
int __c) {
return (char*)strchr(__s, __c);
}
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_PREFERRED_OVERLOAD const char*
strchr(const char* __s, int __c) {
return __libcpp_strchr(__s, __c);
}
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_PREFERRED_OVERLOAD char*
strchr(char* __s, int __c) {
return __libcpp_strchr(__s, __c);
}
inline _LIBCPP_INLINE_VISIBILITY char* __libcpp_strpbrk(const char* __s1,
const char* __s2) {
return (char*)strpbrk(__s1, __s2);
}
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_PREFERRED_OVERLOAD const char*
strpbrk(const char* __s1, const char* __s2) {
return __libcpp_strpbrk(__s1, __s2);
}
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_PREFERRED_OVERLOAD char*
strpbrk(char* __s1, const char* __s2) {
return __libcpp_strpbrk(__s1, __s2);
}
inline _LIBCPP_INLINE_VISIBILITY char* __libcpp_strrchr(const char* __s,
int __c) {
return (char*)strrchr(__s, __c);
}
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_PREFERRED_OVERLOAD const char*
strrchr(const char* __s, int __c) {
return __libcpp_strrchr(__s, __c);
}
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_PREFERRED_OVERLOAD char*
strrchr(char* __s, int __c) {
return __libcpp_strrchr(__s, __c);
}
inline _LIBCPP_INLINE_VISIBILITY void* __libcpp_memchr(const void* __s, int __c,
size_t __n) {
return (void*)memchr(__s, __c, __n);
}
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_PREFERRED_OVERLOAD const void*
memchr(const void* __s, int __c, size_t __n) {
return __libcpp_memchr(__s, __c, __n);
}
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_PREFERRED_OVERLOAD void*
memchr(void* __s, int __c, size_t __n) {
return __libcpp_memchr(__s, __c, __n);
}
inline _LIBCPP_INLINE_VISIBILITY char* __libcpp_strstr(const char* __s1,
const char* __s2) {
return (char*)strstr(__s1, __s2);
}
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_PREFERRED_OVERLOAD const char*
strstr(const char* __s1, const char* __s2) {
return __libcpp_strstr(__s1, __s2);
}
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_PREFERRED_OVERLOAD char*
strstr(char* __s1, const char* __s2) {
return __libcpp_strstr(__s1, __s2);
}
}
#endif
#endif // _LIBCPP_STRING_H
| 4,995 | 141 | jart/cosmopolitan | false |
cosmopolitan/third_party/libcxx/mutex | // -*- C++ -*-
// clang-format off
//===--------------------------- mutex ------------------------------------===//
//
// 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_MUTEX
#define _LIBCPP_MUTEX
#include "third_party/libcxx/__config"
#include "third_party/libcxx/__mutex_base"
#include "third_party/libcxx/cstdint"
#include "third_party/libcxx/functional"
#include "third_party/libcxx/memory"
#ifndef _LIBCPP_CXX03_LANG
#include "third_party/libcxx/tuple"
#endif
#include "third_party/libcxx/version"
#include "third_party/libcxx/__threading_support"
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
#pragma GCC system_header
#endif
_LIBCPP_PUSH_MACROS
#include "third_party/libcxx/__undef_macros"
_LIBCPP_BEGIN_NAMESPACE_STD
/*
mutex synopsis
namespace std
{
class mutex
{
public:
constexpr mutex() noexcept;
~mutex();
mutex(const mutex&) = delete;
mutex& operator=(const mutex&) = delete;
void lock();
bool try_lock();
void unlock();
typedef pthread_mutex_t* native_handle_type;
native_handle_type native_handle();
};
class recursive_mutex
{
public:
recursive_mutex();
~recursive_mutex();
recursive_mutex(const recursive_mutex&) = delete;
recursive_mutex& operator=(const recursive_mutex&) = delete;
void lock();
bool try_lock() noexcept;
void unlock();
typedef pthread_mutex_t* native_handle_type;
native_handle_type native_handle();
};
class timed_mutex
{
public:
timed_mutex();
~timed_mutex();
timed_mutex(const timed_mutex&) = delete;
timed_mutex& operator=(const timed_mutex&) = delete;
void lock();
bool try_lock();
template <class Rep, class Period>
bool try_lock_for(const chrono::duration<Rep, Period>& rel_time);
template <class Clock, class Duration>
bool try_lock_until(const chrono::time_point<Clock, Duration>& abs_time);
void unlock();
};
class recursive_timed_mutex
{
public:
recursive_timed_mutex();
~recursive_timed_mutex();
recursive_timed_mutex(const recursive_timed_mutex&) = delete;
recursive_timed_mutex& operator=(const recursive_timed_mutex&) = delete;
void lock();
bool try_lock() noexcept;
template <class Rep, class Period>
bool try_lock_for(const chrono::duration<Rep, Period>& rel_time);
template <class Clock, class Duration>
bool try_lock_until(const chrono::time_point<Clock, Duration>& abs_time);
void unlock();
};
struct defer_lock_t { explicit defer_lock_t() = default; };
struct try_to_lock_t { explicit try_to_lock_t() = default; };
struct adopt_lock_t { explicit adopt_lock_t() = default; };
inline constexpr defer_lock_t defer_lock{};
inline constexpr try_to_lock_t try_to_lock{};
inline constexpr adopt_lock_t adopt_lock{};
template <class Mutex>
class lock_guard
{
public:
typedef Mutex mutex_type;
explicit lock_guard(mutex_type& m);
lock_guard(mutex_type& m, adopt_lock_t);
~lock_guard();
lock_guard(lock_guard const&) = delete;
lock_guard& operator=(lock_guard const&) = delete;
};
template <class... MutexTypes>
class scoped_lock // C++17
{
public:
using mutex_type = Mutex; // If MutexTypes... consists of the single type Mutex
explicit scoped_lock(MutexTypes&... m);
scoped_lock(adopt_lock_t, MutexTypes&... m);
~scoped_lock();
scoped_lock(scoped_lock const&) = delete;
scoped_lock& operator=(scoped_lock const&) = delete;
private:
tuple<MutexTypes&...> pm; // exposition only
};
template <class Mutex>
class unique_lock
{
public:
typedef Mutex mutex_type;
unique_lock() noexcept;
explicit unique_lock(mutex_type& m);
unique_lock(mutex_type& m, defer_lock_t) noexcept;
unique_lock(mutex_type& m, try_to_lock_t);
unique_lock(mutex_type& m, adopt_lock_t);
template <class Clock, class Duration>
unique_lock(mutex_type& m, const chrono::time_point<Clock, Duration>& abs_time);
template <class Rep, class Period>
unique_lock(mutex_type& m, const chrono::duration<Rep, Period>& rel_time);
~unique_lock();
unique_lock(unique_lock const&) = delete;
unique_lock& operator=(unique_lock const&) = delete;
unique_lock(unique_lock&& u) noexcept;
unique_lock& operator=(unique_lock&& u) noexcept;
void lock();
bool try_lock();
template <class Rep, class Period>
bool try_lock_for(const chrono::duration<Rep, Period>& rel_time);
template <class Clock, class Duration>
bool try_lock_until(const chrono::time_point<Clock, Duration>& abs_time);
void unlock();
void swap(unique_lock& u) noexcept;
mutex_type* release() noexcept;
bool owns_lock() const noexcept;
explicit operator bool () const noexcept;
mutex_type* mutex() const noexcept;
};
template <class Mutex>
void swap(unique_lock<Mutex>& x, unique_lock<Mutex>& y) noexcept;
template <class L1, class L2, class... L3>
int try_lock(L1&, L2&, L3&...);
template <class L1, class L2, class... L3>
void lock(L1&, L2&, L3&...);
struct once_flag
{
constexpr once_flag() noexcept;
once_flag(const once_flag&) = delete;
once_flag& operator=(const once_flag&) = delete;
};
template<class Callable, class ...Args>
void call_once(once_flag& flag, Callable&& func, Args&&... args);
} // std
*/
#ifndef _LIBCPP_HAS_NO_THREADS
class _LIBCPP_TYPE_VIS recursive_mutex
{
__libcpp_recursive_mutex_t __m_;
public:
recursive_mutex();
~recursive_mutex();
private:
recursive_mutex(const recursive_mutex&); // = delete;
recursive_mutex& operator=(const recursive_mutex&); // = delete;
public:
void lock();
bool try_lock() _NOEXCEPT;
void unlock() _NOEXCEPT;
typedef __libcpp_recursive_mutex_t* native_handle_type;
_LIBCPP_INLINE_VISIBILITY
native_handle_type native_handle() {return &__m_;}
};
class _LIBCPP_TYPE_VIS timed_mutex
{
mutex __m_;
condition_variable __cv_;
bool __locked_;
public:
timed_mutex();
~timed_mutex();
private:
timed_mutex(const timed_mutex&); // = delete;
timed_mutex& operator=(const timed_mutex&); // = delete;
public:
void lock();
bool try_lock() _NOEXCEPT;
template <class _Rep, class _Period>
_LIBCPP_INLINE_VISIBILITY
bool try_lock_for(const chrono::duration<_Rep, _Period>& __d)
{return try_lock_until(chrono::steady_clock::now() + __d);}
template <class _Clock, class _Duration>
_LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
bool try_lock_until(const chrono::time_point<_Clock, _Duration>& __t);
void unlock() _NOEXCEPT;
};
template <class _Clock, class _Duration>
bool
timed_mutex::try_lock_until(const chrono::time_point<_Clock, _Duration>& __t)
{
using namespace chrono;
unique_lock<mutex> __lk(__m_);
bool no_timeout = _Clock::now() < __t;
while (no_timeout && __locked_)
no_timeout = __cv_.wait_until(__lk, __t) == cv_status::no_timeout;
if (!__locked_)
{
__locked_ = true;
return true;
}
return false;
}
class _LIBCPP_TYPE_VIS recursive_timed_mutex
{
mutex __m_;
condition_variable __cv_;
size_t __count_;
__thread_id __id_;
public:
recursive_timed_mutex();
~recursive_timed_mutex();
private:
recursive_timed_mutex(const recursive_timed_mutex&); // = delete;
recursive_timed_mutex& operator=(const recursive_timed_mutex&); // = delete;
public:
void lock();
bool try_lock() _NOEXCEPT;
template <class _Rep, class _Period>
_LIBCPP_INLINE_VISIBILITY
bool try_lock_for(const chrono::duration<_Rep, _Period>& __d)
{return try_lock_until(chrono::steady_clock::now() + __d);}
template <class _Clock, class _Duration>
_LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
bool try_lock_until(const chrono::time_point<_Clock, _Duration>& __t);
void unlock() _NOEXCEPT;
};
template <class _Clock, class _Duration>
bool
recursive_timed_mutex::try_lock_until(const chrono::time_point<_Clock, _Duration>& __t)
{
using namespace chrono;
__thread_id __id = this_thread::get_id();
unique_lock<mutex> lk(__m_);
if (__id == __id_)
{
if (__count_ == numeric_limits<size_t>::max())
return false;
++__count_;
return true;
}
bool no_timeout = _Clock::now() < __t;
while (no_timeout && __count_ != 0)
no_timeout = __cv_.wait_until(lk, __t) == cv_status::no_timeout;
if (__count_ == 0)
{
__count_ = 1;
__id_ = __id;
return true;
}
return false;
}
template <class _L0, class _L1>
int
try_lock(_L0& __l0, _L1& __l1)
{
unique_lock<_L0> __u0(__l0, try_to_lock);
if (__u0.owns_lock())
{
if (__l1.try_lock())
{
__u0.release();
return -1;
}
else
return 1;
}
return 0;
}
#ifndef _LIBCPP_CXX03_LANG
template <class _L0, class _L1, class _L2, class... _L3>
int
try_lock(_L0& __l0, _L1& __l1, _L2& __l2, _L3&... __l3)
{
int __r = 0;
unique_lock<_L0> __u0(__l0, try_to_lock);
if (__u0.owns_lock())
{
__r = try_lock(__l1, __l2, __l3...);
if (__r == -1)
__u0.release();
else
++__r;
}
return __r;
}
#endif // _LIBCPP_CXX03_LANG
template <class _L0, class _L1>
void
lock(_L0& __l0, _L1& __l1)
{
while (true)
{
{
unique_lock<_L0> __u0(__l0);
if (__l1.try_lock())
{
__u0.release();
break;
}
}
__libcpp_thread_yield();
{
unique_lock<_L1> __u1(__l1);
if (__l0.try_lock())
{
__u1.release();
break;
}
}
__libcpp_thread_yield();
}
}
#ifndef _LIBCPP_CXX03_LANG
template <class _L0, class _L1, class _L2, class ..._L3>
void
__lock_first(int __i, _L0& __l0, _L1& __l1, _L2& __l2, _L3& ...__l3)
{
while (true)
{
switch (__i)
{
case 0:
{
unique_lock<_L0> __u0(__l0);
__i = try_lock(__l1, __l2, __l3...);
if (__i == -1)
{
__u0.release();
return;
}
}
++__i;
__libcpp_thread_yield();
break;
case 1:
{
unique_lock<_L1> __u1(__l1);
__i = try_lock(__l2, __l3..., __l0);
if (__i == -1)
{
__u1.release();
return;
}
}
if (__i == sizeof...(_L3) + 1)
__i = 0;
else
__i += 2;
__libcpp_thread_yield();
break;
default:
__lock_first(__i - 2, __l2, __l3..., __l0, __l1);
return;
}
}
}
template <class _L0, class _L1, class _L2, class ..._L3>
inline _LIBCPP_INLINE_VISIBILITY
void
lock(_L0& __l0, _L1& __l1, _L2& __l2, _L3& ...__l3)
{
__lock_first(0, __l0, __l1, __l2, __l3...);
}
template <class _L0>
inline _LIBCPP_INLINE_VISIBILITY
void __unlock(_L0& __l0) {
__l0.unlock();
}
template <class _L0, class _L1>
inline _LIBCPP_INLINE_VISIBILITY
void __unlock(_L0& __l0, _L1& __l1) {
__l0.unlock();
__l1.unlock();
}
template <class _L0, class _L1, class _L2, class ..._L3>
inline _LIBCPP_INLINE_VISIBILITY
void __unlock(_L0& __l0, _L1& __l1, _L2& __l2, _L3&... __l3) {
__l0.unlock();
__l1.unlock();
_VSTD::__unlock(__l2, __l3...);
}
#endif // _LIBCPP_CXX03_LANG
#if _LIBCPP_STD_VER > 14
template <class ..._Mutexes>
class _LIBCPP_TEMPLATE_VIS scoped_lock;
template <>
class _LIBCPP_TEMPLATE_VIS scoped_lock<> {
public:
explicit scoped_lock() {}
~scoped_lock() = default;
_LIBCPP_INLINE_VISIBILITY
explicit scoped_lock(adopt_lock_t) {}
scoped_lock(scoped_lock const&) = delete;
scoped_lock& operator=(scoped_lock const&) = delete;
};
template <class _Mutex>
class _LIBCPP_TEMPLATE_VIS _LIBCPP_THREAD_SAFETY_ANNOTATION(scoped_lockable) scoped_lock<_Mutex> {
public:
typedef _Mutex mutex_type;
private:
mutex_type& __m_;
public:
explicit scoped_lock(mutex_type & __m) _LIBCPP_THREAD_SAFETY_ANNOTATION(acquire_capability(__m))
: __m_(__m) {__m_.lock();}
~scoped_lock() _LIBCPP_THREAD_SAFETY_ANNOTATION(release_capability()) {__m_.unlock();}
_LIBCPP_INLINE_VISIBILITY
explicit scoped_lock(adopt_lock_t, mutex_type& __m) _LIBCPP_THREAD_SAFETY_ANNOTATION(requires_capability(__m))
: __m_(__m) {}
scoped_lock(scoped_lock const&) = delete;
scoped_lock& operator=(scoped_lock const&) = delete;
};
template <class ..._MArgs>
class _LIBCPP_TEMPLATE_VIS scoped_lock
{
static_assert(sizeof...(_MArgs) > 1, "At least 2 lock types required");
typedef tuple<_MArgs&...> _MutexTuple;
public:
_LIBCPP_INLINE_VISIBILITY
explicit scoped_lock(_MArgs&... __margs)
: __t_(__margs...)
{
_VSTD::lock(__margs...);
}
_LIBCPP_INLINE_VISIBILITY
scoped_lock(adopt_lock_t, _MArgs&... __margs)
: __t_(__margs...)
{
}
_LIBCPP_INLINE_VISIBILITY
~scoped_lock() {
typedef typename __make_tuple_indices<sizeof...(_MArgs)>::type _Indices;
__unlock_unpack(_Indices{}, __t_);
}
scoped_lock(scoped_lock const&) = delete;
scoped_lock& operator=(scoped_lock const&) = delete;
private:
template <size_t ..._Indx>
_LIBCPP_INLINE_VISIBILITY
static void __unlock_unpack(__tuple_indices<_Indx...>, _MutexTuple& __mt) {
_VSTD::__unlock(_VSTD::get<_Indx>(__mt)...);
}
_MutexTuple __t_;
};
#endif // _LIBCPP_STD_VER > 14
#endif // !_LIBCPP_HAS_NO_THREADS
struct _LIBCPP_TEMPLATE_VIS once_flag;
#ifndef _LIBCPP_CXX03_LANG
template<class _Callable, class... _Args>
_LIBCPP_INLINE_VISIBILITY
void call_once(once_flag&, _Callable&&, _Args&&...);
#else // _LIBCPP_CXX03_LANG
template<class _Callable>
_LIBCPP_INLINE_VISIBILITY
void call_once(once_flag&, _Callable&);
template<class _Callable>
_LIBCPP_INLINE_VISIBILITY
void call_once(once_flag&, const _Callable&);
#endif // _LIBCPP_CXX03_LANG
struct _LIBCPP_TEMPLATE_VIS once_flag
{
_LIBCPP_INLINE_VISIBILITY
_LIBCPP_CONSTEXPR
once_flag() _NOEXCEPT : __state_(0) {}
#if defined(_LIBCPP_ABI_MICROSOFT)
typedef uintptr_t _State_type;
#else
typedef unsigned long _State_type;
#endif
private:
once_flag(const once_flag&); // = delete;
once_flag& operator=(const once_flag&); // = delete;
_State_type __state_;
#ifndef _LIBCPP_CXX03_LANG
template<class _Callable, class... _Args>
friend
void call_once(once_flag&, _Callable&&, _Args&&...);
#else // _LIBCPP_CXX03_LANG
template<class _Callable>
friend
void call_once(once_flag&, _Callable&);
template<class _Callable>
friend
void call_once(once_flag&, const _Callable&);
#endif // _LIBCPP_CXX03_LANG
};
#ifndef _LIBCPP_CXX03_LANG
template <class _Fp>
class __call_once_param
{
_Fp& __f_;
public:
_LIBCPP_INLINE_VISIBILITY
explicit __call_once_param(_Fp& __f) : __f_(__f) {}
_LIBCPP_INLINE_VISIBILITY
void operator()()
{
typedef typename __make_tuple_indices<tuple_size<_Fp>::value, 1>::type _Index;
__execute(_Index());
}
private:
template <size_t ..._Indices>
_LIBCPP_INLINE_VISIBILITY
void __execute(__tuple_indices<_Indices...>)
{
__invoke(_VSTD::get<0>(_VSTD::move(__f_)), _VSTD::get<_Indices>(_VSTD::move(__f_))...);
}
};
#else
template <class _Fp>
class __call_once_param
{
_Fp& __f_;
public:
_LIBCPP_INLINE_VISIBILITY
explicit __call_once_param(_Fp& __f) : __f_(__f) {}
_LIBCPP_INLINE_VISIBILITY
void operator()()
{
__f_();
}
};
#endif
template <class _Fp>
void
__call_once_proxy(void* __vp)
{
__call_once_param<_Fp>* __p = static_cast<__call_once_param<_Fp>*>(__vp);
(*__p)();
}
_LIBCPP_FUNC_VIS void __call_once(volatile once_flag::_State_type&, void*,
void (*)(void*));
#ifndef _LIBCPP_CXX03_LANG
template<class _Callable, class... _Args>
inline _LIBCPP_INLINE_VISIBILITY
void
call_once(once_flag& __flag, _Callable&& __func, _Args&&... __args)
{
if (__libcpp_acquire_load(&__flag.__state_) != ~once_flag::_State_type(0))
{
typedef tuple<_Callable&&, _Args&&...> _Gp;
_Gp __f(_VSTD::forward<_Callable>(__func), _VSTD::forward<_Args>(__args)...);
__call_once_param<_Gp> __p(__f);
__call_once(__flag.__state_, &__p, &__call_once_proxy<_Gp>);
}
}
#else // _LIBCPP_CXX03_LANG
template<class _Callable>
inline _LIBCPP_INLINE_VISIBILITY
void
call_once(once_flag& __flag, _Callable& __func)
{
if (__libcpp_acquire_load(&__flag.__state_) != ~once_flag::_State_type(0))
{
__call_once_param<_Callable> __p(__func);
__call_once(__flag.__state_, &__p, &__call_once_proxy<_Callable>);
}
}
template<class _Callable>
inline _LIBCPP_INLINE_VISIBILITY
void
call_once(once_flag& __flag, const _Callable& __func)
{
if (__libcpp_acquire_load(&__flag.__state_) != ~once_flag::_State_type(0))
{
__call_once_param<const _Callable> __p(__func);
__call_once(__flag.__state_, &__p, &__call_once_proxy<const _Callable>);
}
}
#endif // _LIBCPP_CXX03_LANG
_LIBCPP_END_NAMESPACE_STD
_LIBCPP_POP_MACROS
#endif // _LIBCPP_MUTEX
| 17,833 | 713 | jart/cosmopolitan | false |
cosmopolitan/third_party/libcxx/fstream | // -*- C++ -*-
// clang-format off
//===------------------------- fstream ------------------------------------===//
//
// 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_FSTREAM
#define _LIBCPP_FSTREAM
/*
fstream synopsis
template <class charT, class traits = char_traits<charT> >
class basic_filebuf
: public basic_streambuf<charT, traits>
{
public:
typedef charT char_type;
typedef traits traits_type;
typedef typename traits_type::int_type int_type;
typedef typename traits_type::pos_type pos_type;
typedef typename traits_type::off_type off_type;
// 27.9.1.2 Constructors/destructor:
basic_filebuf();
basic_filebuf(basic_filebuf&& rhs);
virtual ~basic_filebuf();
// 27.9.1.3 Assign/swap:
basic_filebuf& operator=(basic_filebuf&& rhs);
void swap(basic_filebuf& rhs);
// 27.9.1.4 Members:
bool is_open() const;
basic_filebuf* open(const char* s, ios_base::openmode mode);
basic_filebuf* open(const string& s, ios_base::openmode mode);
basic_filebuf* open(const filesystem::path& p, ios_base::openmode mode); // C++17
basic_filebuf* close();
protected:
// 27.9.1.5 Overridden virtual functions:
virtual streamsize showmanyc();
virtual int_type underflow();
virtual int_type uflow();
virtual int_type pbackfail(int_type c = traits_type::eof());
virtual int_type overflow (int_type c = traits_type::eof());
virtual basic_streambuf<char_type, traits_type>* setbuf(char_type* s, streamsize n);
virtual pos_type seekoff(off_type off, ios_base::seekdir way,
ios_base::openmode which = ios_base::in | ios_base::out);
virtual pos_type seekpos(pos_type sp,
ios_base::openmode which = ios_base::in | ios_base::out);
virtual int sync();
virtual void imbue(const locale& loc);
};
template <class charT, class traits>
void
swap(basic_filebuf<charT, traits>& x, basic_filebuf<charT, traits>& y);
typedef basic_filebuf<char> filebuf;
typedef basic_filebuf<wchar_t> wfilebuf;
template <class charT, class traits = char_traits<charT> >
class basic_ifstream
: public basic_istream<charT,traits>
{
public:
typedef charT char_type;
typedef traits traits_type;
typedef typename traits_type::int_type int_type;
typedef typename traits_type::pos_type pos_type;
typedef typename traits_type::off_type off_type;
basic_ifstream();
explicit basic_ifstream(const char* s, ios_base::openmode mode = ios_base::in);
explicit basic_ifstream(const string& s, ios_base::openmode mode = ios_base::in);
explicit basic_ifstream(const filesystem::path& p,
ios_base::openmode mode = ios_base::in); // C++17
basic_ifstream(basic_ifstream&& rhs);
basic_ifstream& operator=(basic_ifstream&& rhs);
void swap(basic_ifstream& rhs);
basic_filebuf<char_type, traits_type>* rdbuf() const;
bool is_open() const;
void open(const char* s, ios_base::openmode mode = ios_base::in);
void open(const string& s, ios_base::openmode mode = ios_base::in);
void open(const filesystem::path& s, ios_base::openmode mode = ios_base::in); // C++17
void close();
};
template <class charT, class traits>
void
swap(basic_ifstream<charT, traits>& x, basic_ifstream<charT, traits>& y);
typedef basic_ifstream<char> ifstream;
typedef basic_ifstream<wchar_t> wifstream;
template <class charT, class traits = char_traits<charT> >
class basic_ofstream
: public basic_ostream<charT,traits>
{
public:
typedef charT char_type;
typedef traits traits_type;
typedef typename traits_type::int_type int_type;
typedef typename traits_type::pos_type pos_type;
typedef typename traits_type::off_type off_type;
basic_ofstream();
explicit basic_ofstream(const char* s, ios_base::openmode mode = ios_base::out);
explicit basic_ofstream(const string& s, ios_base::openmode mode = ios_base::out);
explicit basic_ofstream(const filesystem::path& p,
ios_base::openmode mode = ios_base::out); // C++17
basic_ofstream(basic_ofstream&& rhs);
basic_ofstream& operator=(basic_ofstream&& rhs);
void swap(basic_ofstream& rhs);
basic_filebuf<char_type, traits_type>* rdbuf() const;
bool is_open() const;
void open(const char* s, ios_base::openmode mode = ios_base::out);
void open(const string& s, ios_base::openmode mode = ios_base::out);
void open(const filesystem::path& p,
ios_base::openmode mode = ios_base::out); // C++17
void close();
};
template <class charT, class traits>
void
swap(basic_ofstream<charT, traits>& x, basic_ofstream<charT, traits>& y);
typedef basic_ofstream<char> ofstream;
typedef basic_ofstream<wchar_t> wofstream;
template <class charT, class traits=char_traits<charT> >
class basic_fstream
: public basic_iostream<charT,traits>
{
public:
typedef charT char_type;
typedef traits traits_type;
typedef typename traits_type::int_type int_type;
typedef typename traits_type::pos_type pos_type;
typedef typename traits_type::off_type off_type;
basic_fstream();
explicit basic_fstream(const char* s, ios_base::openmode mode = ios_base::in|ios_base::out);
explicit basic_fstream(const string& s, ios_base::openmode mode = ios_base::in|ios_base::out);
explicit basic_fstream(const filesystem::path& p,
ios_base::openmode mode = ios_base::in|ios_base::out); C++17
basic_fstream(basic_fstream&& rhs);
basic_fstream& operator=(basic_fstream&& rhs);
void swap(basic_fstream& rhs);
basic_filebuf<char_type, traits_type>* rdbuf() const;
bool is_open() const;
void open(const char* s, ios_base::openmode mode = ios_base::in|ios_base::out);
void open(const string& s, ios_base::openmode mode = ios_base::in|ios_base::out);
void open(const filesystem::path& s,
ios_base::openmode mode = ios_base::in|ios_base::out); // C++17
void close();
};
template <class charT, class traits>
void swap(basic_fstream<charT, traits>& x, basic_fstream<charT, traits>& y);
typedef basic_fstream<char> fstream;
typedef basic_fstream<wchar_t> wfstream;
} // std
*/
#include "third_party/libcxx/__config"
#include "third_party/libcxx/ostream"
#include "third_party/libcxx/istream"
#include "third_party/libcxx/__locale"
#include "third_party/libcxx/cstdio"
#include "third_party/libcxx/cstdlib"
#include "third_party/libcxx/filesystem"
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
#pragma GCC system_header
#endif
_LIBCPP_PUSH_MACROS
#include "third_party/libcxx/__undef_macros"
_LIBCPP_BEGIN_NAMESPACE_STD
template <class _CharT, class _Traits>
class _LIBCPP_TEMPLATE_VIS basic_filebuf
: public basic_streambuf<_CharT, _Traits>
{
public:
typedef _CharT char_type;
typedef _Traits traits_type;
typedef typename traits_type::int_type int_type;
typedef typename traits_type::pos_type pos_type;
typedef typename traits_type::off_type off_type;
typedef typename traits_type::state_type state_type;
// 27.9.1.2 Constructors/destructor:
basic_filebuf();
#ifndef _LIBCPP_CXX03_LANG
basic_filebuf(basic_filebuf&& __rhs);
#endif
virtual ~basic_filebuf();
// 27.9.1.3 Assign/swap:
#ifndef _LIBCPP_CXX03_LANG
_LIBCPP_INLINE_VISIBILITY
basic_filebuf& operator=(basic_filebuf&& __rhs);
#endif
void swap(basic_filebuf& __rhs);
// 27.9.1.4 Members:
_LIBCPP_INLINE_VISIBILITY
bool is_open() const;
#ifndef _LIBCPP_HAS_NO_GLOBAL_FILESYSTEM_NAMESPACE
basic_filebuf* open(const char* __s, ios_base::openmode __mode);
#ifdef _LIBCPP_HAS_OPEN_WITH_WCHAR
basic_filebuf* open(const wchar_t* __s, ios_base::openmode __mode);
#endif
_LIBCPP_INLINE_VISIBILITY
basic_filebuf* open(const string& __s, ios_base::openmode __mode);
#if _LIBCPP_STD_VER >= 17
_LIBCPP_AVAILABILITY_FILESYSTEM _LIBCPP_INLINE_VISIBILITY
basic_filebuf* open(const _VSTD_FS::path& __p, ios_base::openmode __mode) {
return open(__p.c_str(), __mode);
}
#endif
_LIBCPP_INLINE_VISIBILITY
basic_filebuf* __open(int __fd, ios_base::openmode __mode);
#endif
basic_filebuf* close();
_LIBCPP_INLINE_VISIBILITY
inline static const char*
__make_mdstring(ios_base::openmode __mode) _NOEXCEPT;
protected:
// 27.9.1.5 Overridden virtual functions:
virtual int_type underflow();
virtual int_type pbackfail(int_type __c = traits_type::eof());
virtual int_type overflow (int_type __c = traits_type::eof());
virtual basic_streambuf<char_type, traits_type>* setbuf(char_type* __s, streamsize __n);
virtual pos_type seekoff(off_type __off, ios_base::seekdir __way,
ios_base::openmode __wch = ios_base::in | ios_base::out);
virtual pos_type seekpos(pos_type __sp,
ios_base::openmode __wch = ios_base::in | ios_base::out);
virtual int sync();
virtual void imbue(const locale& __loc);
private:
char* __extbuf_;
const char* __extbufnext_;
const char* __extbufend_;
char __extbuf_min_[8];
size_t __ebs_;
char_type* __intbuf_;
size_t __ibs_;
FILE* __file_;
const codecvt<char_type, char, state_type>* __cv_;
state_type __st_;
state_type __st_last_;
ios_base::openmode __om_;
ios_base::openmode __cm_;
bool __owns_eb_;
bool __owns_ib_;
bool __always_noconv_;
bool __read_mode();
void __write_mode();
};
template <class _CharT, class _Traits>
basic_filebuf<_CharT, _Traits>::basic_filebuf()
: __extbuf_(0),
__extbufnext_(0),
__extbufend_(0),
__ebs_(0),
__intbuf_(0),
__ibs_(0),
__file_(0),
__cv_(nullptr),
__st_(),
__st_last_(),
__om_(0),
__cm_(0),
__owns_eb_(false),
__owns_ib_(false),
__always_noconv_(false)
{
if (has_facet<codecvt<char_type, char, state_type> >(this->getloc()))
{
__cv_ = &use_facet<codecvt<char_type, char, state_type> >(this->getloc());
__always_noconv_ = __cv_->always_noconv();
}
setbuf(0, 4096);
}
#ifndef _LIBCPP_CXX03_LANG
template <class _CharT, class _Traits>
basic_filebuf<_CharT, _Traits>::basic_filebuf(basic_filebuf&& __rhs)
: basic_streambuf<_CharT, _Traits>(__rhs)
{
if (__rhs.__extbuf_ == __rhs.__extbuf_min_)
{
__extbuf_ = __extbuf_min_;
__extbufnext_ = __extbuf_ + (__rhs.__extbufnext_ - __rhs.__extbuf_);
__extbufend_ = __extbuf_ + (__rhs.__extbufend_ - __rhs.__extbuf_);
}
else
{
__extbuf_ = __rhs.__extbuf_;
__extbufnext_ = __rhs.__extbufnext_;
__extbufend_ = __rhs.__extbufend_;
}
__ebs_ = __rhs.__ebs_;
__intbuf_ = __rhs.__intbuf_;
__ibs_ = __rhs.__ibs_;
__file_ = __rhs.__file_;
__cv_ = __rhs.__cv_;
__st_ = __rhs.__st_;
__st_last_ = __rhs.__st_last_;
__om_ = __rhs.__om_;
__cm_ = __rhs.__cm_;
__owns_eb_ = __rhs.__owns_eb_;
__owns_ib_ = __rhs.__owns_ib_;
__always_noconv_ = __rhs.__always_noconv_;
if (__rhs.pbase())
{
if (__rhs.pbase() == __rhs.__intbuf_)
this->setp(__intbuf_, __intbuf_ + (__rhs. epptr() - __rhs.pbase()));
else
this->setp((char_type*)__extbuf_,
(char_type*)__extbuf_ + (__rhs. epptr() - __rhs.pbase()));
this->__pbump(__rhs. pptr() - __rhs.pbase());
}
else if (__rhs.eback())
{
if (__rhs.eback() == __rhs.__intbuf_)
this->setg(__intbuf_, __intbuf_ + (__rhs.gptr() - __rhs.eback()),
__intbuf_ + (__rhs.egptr() - __rhs.eback()));
else
this->setg((char_type*)__extbuf_,
(char_type*)__extbuf_ + (__rhs.gptr() - __rhs.eback()),
(char_type*)__extbuf_ + (__rhs.egptr() - __rhs.eback()));
}
__rhs.__extbuf_ = 0;
__rhs.__extbufnext_ = 0;
__rhs.__extbufend_ = 0;
__rhs.__ebs_ = 0;
__rhs.__intbuf_ = 0;
__rhs.__ibs_ = 0;
__rhs.__file_ = 0;
__rhs.__st_ = state_type();
__rhs.__st_last_ = state_type();
__rhs.__om_ = 0;
__rhs.__cm_ = 0;
__rhs.__owns_eb_ = false;
__rhs.__owns_ib_ = false;
__rhs.setg(0, 0, 0);
__rhs.setp(0, 0);
}
template <class _CharT, class _Traits>
inline
basic_filebuf<_CharT, _Traits>&
basic_filebuf<_CharT, _Traits>::operator=(basic_filebuf&& __rhs)
{
close();
swap(__rhs);
return *this;
}
#endif // _LIBCPP_CXX03_LANG
template <class _CharT, class _Traits>
basic_filebuf<_CharT, _Traits>::~basic_filebuf()
{
#ifndef _LIBCPP_NO_EXCEPTIONS
try
{
#endif // _LIBCPP_NO_EXCEPTIONS
close();
#ifndef _LIBCPP_NO_EXCEPTIONS
}
catch (...)
{
}
#endif // _LIBCPP_NO_EXCEPTIONS
if (__owns_eb_)
delete [] __extbuf_;
if (__owns_ib_)
delete [] __intbuf_;
}
template <class _CharT, class _Traits>
void
basic_filebuf<_CharT, _Traits>::swap(basic_filebuf& __rhs)
{
basic_streambuf<char_type, traits_type>::swap(__rhs);
if (__extbuf_ != __extbuf_min_ && __rhs.__extbuf_ != __rhs.__extbuf_min_)
{
_VSTD::swap(__extbuf_, __rhs.__extbuf_);
_VSTD::swap(__extbufnext_, __rhs.__extbufnext_);
_VSTD::swap(__extbufend_, __rhs.__extbufend_);
}
else
{
ptrdiff_t __ln = __extbufnext_ - __extbuf_;
ptrdiff_t __le = __extbufend_ - __extbuf_;
ptrdiff_t __rn = __rhs.__extbufnext_ - __rhs.__extbuf_;
ptrdiff_t __re = __rhs.__extbufend_ - __rhs.__extbuf_;
if (__extbuf_ == __extbuf_min_ && __rhs.__extbuf_ != __rhs.__extbuf_min_)
{
__extbuf_ = __rhs.__extbuf_;
__rhs.__extbuf_ = __rhs.__extbuf_min_;
}
else if (__extbuf_ != __extbuf_min_ && __rhs.__extbuf_ == __rhs.__extbuf_min_)
{
__rhs.__extbuf_ = __extbuf_;
__extbuf_ = __extbuf_min_;
}
__extbufnext_ = __extbuf_ + __rn;
__extbufend_ = __extbuf_ + __re;
__rhs.__extbufnext_ = __rhs.__extbuf_ + __ln;
__rhs.__extbufend_ = __rhs.__extbuf_ + __le;
}
_VSTD::swap(__ebs_, __rhs.__ebs_);
_VSTD::swap(__intbuf_, __rhs.__intbuf_);
_VSTD::swap(__ibs_, __rhs.__ibs_);
_VSTD::swap(__file_, __rhs.__file_);
_VSTD::swap(__cv_, __rhs.__cv_);
_VSTD::swap(__st_, __rhs.__st_);
_VSTD::swap(__st_last_, __rhs.__st_last_);
_VSTD::swap(__om_, __rhs.__om_);
_VSTD::swap(__cm_, __rhs.__cm_);
_VSTD::swap(__owns_eb_, __rhs.__owns_eb_);
_VSTD::swap(__owns_ib_, __rhs.__owns_ib_);
_VSTD::swap(__always_noconv_, __rhs.__always_noconv_);
if (this->eback() == (char_type*)__rhs.__extbuf_min_)
{
ptrdiff_t __n = this->gptr() - this->eback();
ptrdiff_t __e = this->egptr() - this->eback();
this->setg((char_type*)__extbuf_min_,
(char_type*)__extbuf_min_ + __n,
(char_type*)__extbuf_min_ + __e);
}
else if (this->pbase() == (char_type*)__rhs.__extbuf_min_)
{
ptrdiff_t __n = this->pptr() - this->pbase();
ptrdiff_t __e = this->epptr() - this->pbase();
this->setp((char_type*)__extbuf_min_,
(char_type*)__extbuf_min_ + __e);
this->__pbump(__n);
}
if (__rhs.eback() == (char_type*)__extbuf_min_)
{
ptrdiff_t __n = __rhs.gptr() - __rhs.eback();
ptrdiff_t __e = __rhs.egptr() - __rhs.eback();
__rhs.setg((char_type*)__rhs.__extbuf_min_,
(char_type*)__rhs.__extbuf_min_ + __n,
(char_type*)__rhs.__extbuf_min_ + __e);
}
else if (__rhs.pbase() == (char_type*)__extbuf_min_)
{
ptrdiff_t __n = __rhs.pptr() - __rhs.pbase();
ptrdiff_t __e = __rhs.epptr() - __rhs.pbase();
__rhs.setp((char_type*)__rhs.__extbuf_min_,
(char_type*)__rhs.__extbuf_min_ + __e);
__rhs.__pbump(__n);
}
}
template <class _CharT, class _Traits>
inline _LIBCPP_INLINE_VISIBILITY
void
swap(basic_filebuf<_CharT, _Traits>& __x, basic_filebuf<_CharT, _Traits>& __y)
{
__x.swap(__y);
}
template <class _CharT, class _Traits>
inline
bool
basic_filebuf<_CharT, _Traits>::is_open() const
{
return __file_ != 0;
}
template <class _CharT, class _Traits>
const char* basic_filebuf<_CharT, _Traits>::__make_mdstring(
ios_base::openmode __mode) _NOEXCEPT {
switch (__mode & ~ios_base::ate) {
case ios_base::out:
case ios_base::out | ios_base::trunc:
return "w" _LIBCPP_FOPEN_CLOEXEC_MODE;
case ios_base::out | ios_base::app:
case ios_base::app:
return "a" _LIBCPP_FOPEN_CLOEXEC_MODE;
case ios_base::in:
return "r" _LIBCPP_FOPEN_CLOEXEC_MODE;
case ios_base::in | ios_base::out:
return "r+" _LIBCPP_FOPEN_CLOEXEC_MODE;
case ios_base::in | ios_base::out | ios_base::trunc:
return "w+" _LIBCPP_FOPEN_CLOEXEC_MODE;
case ios_base::in | ios_base::out | ios_base::app:
case ios_base::in | ios_base::app:
return "a+" _LIBCPP_FOPEN_CLOEXEC_MODE;
case ios_base::out | ios_base::binary:
case ios_base::out | ios_base::trunc | ios_base::binary:
return "wb" _LIBCPP_FOPEN_CLOEXEC_MODE;
case ios_base::out | ios_base::app | ios_base::binary:
case ios_base::app | ios_base::binary:
return "ab" _LIBCPP_FOPEN_CLOEXEC_MODE;
case ios_base::in | ios_base::binary:
return "rb" _LIBCPP_FOPEN_CLOEXEC_MODE;
case ios_base::in | ios_base::out | ios_base::binary:
return "r+b" _LIBCPP_FOPEN_CLOEXEC_MODE;
case ios_base::in | ios_base::out | ios_base::trunc | ios_base::binary:
return "w+b" _LIBCPP_FOPEN_CLOEXEC_MODE;
case ios_base::in | ios_base::out | ios_base::app | ios_base::binary:
case ios_base::in | ios_base::app | ios_base::binary:
return "a+b" _LIBCPP_FOPEN_CLOEXEC_MODE;
default:
return nullptr;
}
_LIBCPP_UNREACHABLE();
}
#ifndef _LIBCPP_HAS_NO_GLOBAL_FILESYSTEM_NAMESPACE
template <class _CharT, class _Traits>
basic_filebuf<_CharT, _Traits>*
basic_filebuf<_CharT, _Traits>::open(const char* __s, ios_base::openmode __mode)
{
basic_filebuf<_CharT, _Traits>* __rt = 0;
if (__file_ == 0)
{
if (const char* __mdstr = __make_mdstring(__mode)) {
__rt = this;
__file_ = fopen(__s, __mdstr);
if (__file_) {
__om_ = __mode;
if (__mode & ios_base::ate) {
if (fseek(__file_, 0, SEEK_END)) {
fclose(__file_);
__file_ = 0;
__rt = 0;
}
}
} else
__rt = 0;
}
}
return __rt;
}
template <class _CharT, class _Traits>
_LIBCPP_INLINE_VISIBILITY basic_filebuf<_CharT, _Traits>*
basic_filebuf<_CharT, _Traits>::__open(int __fd, ios_base::openmode __mode) {
basic_filebuf<_CharT, _Traits>* __rt = 0;
if (__file_ == 0) {
if (const char* __mdstr = __make_mdstring(__mode)) {
__rt = this;
__file_ = fdopen(__fd, __mdstr);
if (__file_) {
__om_ = __mode;
if (__mode & ios_base::ate) {
if (fseek(__file_, 0, SEEK_END)) {
fclose(__file_);
__file_ = 0;
__rt = 0;
}
}
} else
__rt = 0;
}
}
return __rt;
}
#ifdef _LIBCPP_HAS_OPEN_WITH_WCHAR
// This is basically the same as the char* overload except that it uses _wfopen
// and long mode strings.
template <class _CharT, class _Traits>
basic_filebuf<_CharT, _Traits>*
basic_filebuf<_CharT, _Traits>::open(const wchar_t* __s, ios_base::openmode __mode)
{
basic_filebuf<_CharT, _Traits>* __rt = 0;
if (__file_ == 0)
{
__rt = this;
const wchar_t* __mdstr;
switch (__mode & ~ios_base::ate)
{
case ios_base::out:
case ios_base::out | ios_base::trunc:
__mdstr = L"w";
break;
case ios_base::out | ios_base::app:
case ios_base::app:
__mdstr = L"a";
break;
case ios_base::in:
__mdstr = L"r";
break;
case ios_base::in | ios_base::out:
__mdstr = L"r+";
break;
case ios_base::in | ios_base::out | ios_base::trunc:
__mdstr = L"w+";
break;
case ios_base::in | ios_base::out | ios_base::app:
case ios_base::in | ios_base::app:
__mdstr = L"a+";
break;
case ios_base::out | ios_base::binary:
case ios_base::out | ios_base::trunc | ios_base::binary:
__mdstr = L"wb";
break;
case ios_base::out | ios_base::app | ios_base::binary:
case ios_base::app | ios_base::binary:
__mdstr = L"ab";
break;
case ios_base::in | ios_base::binary:
__mdstr = L"rb";
break;
case ios_base::in | ios_base::out | ios_base::binary:
__mdstr = L"r+b";
break;
case ios_base::in | ios_base::out | ios_base::trunc | ios_base::binary:
__mdstr = L"w+b";
break;
case ios_base::in | ios_base::out | ios_base::app | ios_base::binary:
case ios_base::in | ios_base::app | ios_base::binary:
__mdstr = L"a+b";
break;
default:
__rt = 0;
break;
}
if (__rt)
{
__file_ = _wfopen(__s, __mdstr);
if (__file_)
{
__om_ = __mode;
if (__mode & ios_base::ate)
{
if (fseek(__file_, 0, SEEK_END))
{
fclose(__file_);
__file_ = 0;
__rt = 0;
}
}
}
else
__rt = 0;
}
}
return __rt;
}
#endif
template <class _CharT, class _Traits>
inline
basic_filebuf<_CharT, _Traits>*
basic_filebuf<_CharT, _Traits>::open(const string& __s, ios_base::openmode __mode)
{
return open(__s.c_str(), __mode);
}
#endif
template <class _CharT, class _Traits>
basic_filebuf<_CharT, _Traits>*
basic_filebuf<_CharT, _Traits>::close()
{
basic_filebuf<_CharT, _Traits>* __rt = 0;
if (__file_)
{
__rt = this;
unique_ptr<FILE, int(*)(FILE*)> __h(__file_, fclose);
if (sync())
__rt = 0;
if (fclose(__h.release()))
__rt = 0;
__file_ = 0;
setbuf(0, 0);
}
return __rt;
}
template <class _CharT, class _Traits>
typename basic_filebuf<_CharT, _Traits>::int_type
basic_filebuf<_CharT, _Traits>::underflow()
{
if (__file_ == 0)
return traits_type::eof();
bool __initial = __read_mode();
char_type __1buf;
if (this->gptr() == 0)
this->setg(&__1buf, &__1buf+1, &__1buf+1);
const size_t __unget_sz = __initial ? 0 : min<size_t>((this->egptr() - this->eback()) / 2, 4);
int_type __c = traits_type::eof();
if (this->gptr() == this->egptr())
{
memmove(this->eback(), this->egptr() - __unget_sz, __unget_sz * sizeof(char_type));
if (__always_noconv_)
{
size_t __nmemb = static_cast<size_t>(this->egptr() - this->eback() - __unget_sz);
__nmemb = fread(this->eback() + __unget_sz, 1, __nmemb, __file_);
if (__nmemb != 0)
{
this->setg(this->eback(),
this->eback() + __unget_sz,
this->eback() + __unget_sz + __nmemb);
__c = traits_type::to_int_type(*this->gptr());
}
}
else
{
_LIBCPP_ASSERT ( !(__extbufnext_ == NULL && (__extbufend_ != __extbufnext_)), "underflow moving from NULL" );
if (__extbufend_ != __extbufnext_)
memmove(__extbuf_, __extbufnext_, __extbufend_ - __extbufnext_);
__extbufnext_ = __extbuf_ + (__extbufend_ - __extbufnext_);
__extbufend_ = __extbuf_ + (__extbuf_ == __extbuf_min_ ? sizeof(__extbuf_min_) : __ebs_);
size_t __nmemb = _VSTD::min(static_cast<size_t>(__ibs_ - __unget_sz),
static_cast<size_t>(__extbufend_ - __extbufnext_));
codecvt_base::result __r;
__st_last_ = __st_;
size_t __nr = fread((void*) const_cast<char *>(__extbufnext_), 1, __nmemb, __file_);
if (__nr != 0)
{
if (!__cv_)
__throw_bad_cast();
__extbufend_ = __extbufnext_ + __nr;
char_type* __inext;
__r = __cv_->in(__st_, __extbuf_, __extbufend_, __extbufnext_,
this->eback() + __unget_sz,
this->eback() + __ibs_, __inext);
if (__r == codecvt_base::noconv)
{
this->setg((char_type*)__extbuf_, (char_type*)__extbuf_,
(char_type*)const_cast<char *>(__extbufend_));
__c = traits_type::to_int_type(*this->gptr());
}
else if (__inext != this->eback() + __unget_sz)
{
this->setg(this->eback(), this->eback() + __unget_sz, __inext);
__c = traits_type::to_int_type(*this->gptr());
}
}
}
}
else
__c = traits_type::to_int_type(*this->gptr());
if (this->eback() == &__1buf)
this->setg(0, 0, 0);
return __c;
}
template <class _CharT, class _Traits>
typename basic_filebuf<_CharT, _Traits>::int_type
basic_filebuf<_CharT, _Traits>::pbackfail(int_type __c)
{
if (__file_ && this->eback() < this->gptr())
{
if (traits_type::eq_int_type(__c, traits_type::eof()))
{
this->gbump(-1);
return traits_type::not_eof(__c);
}
if ((__om_ & ios_base::out) ||
traits_type::eq(traits_type::to_char_type(__c), this->gptr()[-1]))
{
this->gbump(-1);
*this->gptr() = traits_type::to_char_type(__c);
return __c;
}
}
return traits_type::eof();
}
template <class _CharT, class _Traits>
typename basic_filebuf<_CharT, _Traits>::int_type
basic_filebuf<_CharT, _Traits>::overflow(int_type __c)
{
if (__file_ == 0)
return traits_type::eof();
__write_mode();
char_type __1buf;
char_type* __pb_save = this->pbase();
char_type* __epb_save = this->epptr();
if (!traits_type::eq_int_type(__c, traits_type::eof()))
{
if (this->pptr() == 0)
this->setp(&__1buf, &__1buf+1);
*this->pptr() = traits_type::to_char_type(__c);
this->pbump(1);
}
if (this->pptr() != this->pbase())
{
if (__always_noconv_)
{
size_t __nmemb = static_cast<size_t>(this->pptr() - this->pbase());
if (fwrite(this->pbase(), sizeof(char_type), __nmemb, __file_) != __nmemb)
return traits_type::eof();
}
else
{
char* __extbe = __extbuf_;
codecvt_base::result __r;
do
{
if (!__cv_)
__throw_bad_cast();
const char_type* __e;
__r = __cv_->out(__st_, this->pbase(), this->pptr(), __e,
__extbuf_, __extbuf_ + __ebs_, __extbe);
if (__e == this->pbase())
return traits_type::eof();
if (__r == codecvt_base::noconv)
{
size_t __nmemb = static_cast<size_t>(this->pptr() - this->pbase());
if (fwrite(this->pbase(), 1, __nmemb, __file_) != __nmemb)
return traits_type::eof();
}
else if (__r == codecvt_base::ok || __r == codecvt_base::partial)
{
size_t __nmemb = static_cast<size_t>(__extbe - __extbuf_);
if (fwrite(__extbuf_, 1, __nmemb, __file_) != __nmemb)
return traits_type::eof();
if (__r == codecvt_base::partial)
{
this->setp(const_cast<char_type*>(__e), this->pptr());
this->__pbump(this->epptr() - this->pbase());
}
}
else
return traits_type::eof();
} while (__r == codecvt_base::partial);
}
this->setp(__pb_save, __epb_save);
}
return traits_type::not_eof(__c);
}
template <class _CharT, class _Traits>
basic_streambuf<_CharT, _Traits>*
basic_filebuf<_CharT, _Traits>::setbuf(char_type* __s, streamsize __n)
{
this->setg(0, 0, 0);
this->setp(0, 0);
if (__owns_eb_)
delete [] __extbuf_;
if (__owns_ib_)
delete [] __intbuf_;
__ebs_ = __n;
if (__ebs_ > sizeof(__extbuf_min_))
{
if (__always_noconv_ && __s)
{
__extbuf_ = (char*)__s;
__owns_eb_ = false;
}
else
{
__extbuf_ = new char[__ebs_];
__owns_eb_ = true;
}
}
else
{
__extbuf_ = __extbuf_min_;
__ebs_ = sizeof(__extbuf_min_);
__owns_eb_ = false;
}
if (!__always_noconv_)
{
__ibs_ = max<streamsize>(__n, sizeof(__extbuf_min_));
if (__s && __ibs_ >= sizeof(__extbuf_min_))
{
__intbuf_ = __s;
__owns_ib_ = false;
}
else
{
__intbuf_ = new char_type[__ibs_];
__owns_ib_ = true;
}
}
else
{
__ibs_ = 0;
__intbuf_ = 0;
__owns_ib_ = false;
}
return this;
}
template <class _CharT, class _Traits>
typename basic_filebuf<_CharT, _Traits>::pos_type
basic_filebuf<_CharT, _Traits>::seekoff(off_type __off, ios_base::seekdir __way,
ios_base::openmode)
{
if (!__cv_)
__throw_bad_cast();
int __width = __cv_->encoding();
if (__file_ == 0 || (__width <= 0 && __off != 0) || sync())
return pos_type(off_type(-1));
// __width > 0 || __off == 0
int __whence;
switch (__way)
{
case ios_base::beg:
__whence = SEEK_SET;
break;
case ios_base::cur:
__whence = SEEK_CUR;
break;
case ios_base::end:
__whence = SEEK_END;
break;
default:
return pos_type(off_type(-1));
}
#if defined(_LIBCPP_HAS_NO_OFF_T_FUNCTIONS)
if (fseek(__file_, __width > 0 ? __width * __off : 0, __whence))
return pos_type(off_type(-1));
pos_type __r = ftell(__file_);
#else
if (fseeko(__file_, __width > 0 ? __width * __off : 0, __whence))
return pos_type(off_type(-1));
pos_type __r = ftello(__file_);
#endif
__r.state(__st_);
return __r;
}
template <class _CharT, class _Traits>
typename basic_filebuf<_CharT, _Traits>::pos_type
basic_filebuf<_CharT, _Traits>::seekpos(pos_type __sp, ios_base::openmode)
{
if (__file_ == 0 || sync())
return pos_type(off_type(-1));
#if defined(_LIBCPP_HAS_NO_OFF_T_FUNCTIONS)
if (fseek(__file_, __sp, SEEK_SET))
return pos_type(off_type(-1));
#else
if (fseeko(__file_, __sp, SEEK_SET))
return pos_type(off_type(-1));
#endif
__st_ = __sp.state();
return __sp;
}
template <class _CharT, class _Traits>
int
basic_filebuf<_CharT, _Traits>::sync()
{
if (__file_ == 0)
return 0;
if (!__cv_)
__throw_bad_cast();
if (__cm_ & ios_base::out)
{
if (this->pptr() != this->pbase())
if (overflow() == traits_type::eof())
return -1;
codecvt_base::result __r;
do
{
char* __extbe;
__r = __cv_->unshift(__st_, __extbuf_, __extbuf_ + __ebs_, __extbe);
size_t __nmemb = static_cast<size_t>(__extbe - __extbuf_);
if (fwrite(__extbuf_, 1, __nmemb, __file_) != __nmemb)
return -1;
} while (__r == codecvt_base::partial);
if (__r == codecvt_base::error)
return -1;
if (fflush(__file_))
return -1;
}
else if (__cm_ & ios_base::in)
{
off_type __c;
state_type __state = __st_last_;
bool __update_st = false;
if (__always_noconv_)
__c = this->egptr() - this->gptr();
else
{
int __width = __cv_->encoding();
__c = __extbufend_ - __extbufnext_;
if (__width > 0)
__c += __width * (this->egptr() - this->gptr());
else
{
if (this->gptr() != this->egptr())
{
const int __off = __cv_->length(__state, __extbuf_,
__extbufnext_,
this->gptr() - this->eback());
__c += __extbufnext_ - __extbuf_ - __off;
__update_st = true;
}
}
}
#if defined(_LIBCPP_HAS_NO_OFF_T_FUNCTIONS)
if (fseek(__file_, -__c, SEEK_CUR))
return -1;
#else
if (fseeko(__file_, -__c, SEEK_CUR))
return -1;
#endif
if (__update_st)
__st_ = __state;
__extbufnext_ = __extbufend_ = __extbuf_;
this->setg(0, 0, 0);
__cm_ = 0;
}
return 0;
}
template <class _CharT, class _Traits>
void
basic_filebuf<_CharT, _Traits>::imbue(const locale& __loc)
{
sync();
__cv_ = &use_facet<codecvt<char_type, char, state_type> >(__loc);
bool __old_anc = __always_noconv_;
__always_noconv_ = __cv_->always_noconv();
if (__old_anc != __always_noconv_)
{
this->setg(0, 0, 0);
this->setp(0, 0);
// invariant, char_type is char, else we couldn't get here
if (__always_noconv_) // need to dump __intbuf_
{
if (__owns_eb_)
delete [] __extbuf_;
__owns_eb_ = __owns_ib_;
__ebs_ = __ibs_;
__extbuf_ = (char*)__intbuf_;
__ibs_ = 0;
__intbuf_ = 0;
__owns_ib_ = false;
}
else // need to obtain an __intbuf_.
{ // If __extbuf_ is user-supplied, use it, else new __intbuf_
if (!__owns_eb_ && __extbuf_ != __extbuf_min_)
{
__ibs_ = __ebs_;
__intbuf_ = (char_type*)__extbuf_;
__owns_ib_ = false;
__extbuf_ = new char[__ebs_];
__owns_eb_ = true;
}
else
{
__ibs_ = __ebs_;
__intbuf_ = new char_type[__ibs_];
__owns_ib_ = true;
}
}
}
}
template <class _CharT, class _Traits>
bool
basic_filebuf<_CharT, _Traits>::__read_mode()
{
if (!(__cm_ & ios_base::in))
{
this->setp(0, 0);
if (__always_noconv_)
this->setg((char_type*)__extbuf_,
(char_type*)__extbuf_ + __ebs_,
(char_type*)__extbuf_ + __ebs_);
else
this->setg(__intbuf_, __intbuf_ + __ibs_, __intbuf_ + __ibs_);
__cm_ = ios_base::in;
return true;
}
return false;
}
template <class _CharT, class _Traits>
void
basic_filebuf<_CharT, _Traits>::__write_mode()
{
if (!(__cm_ & ios_base::out))
{
this->setg(0, 0, 0);
if (__ebs_ > sizeof(__extbuf_min_))
{
if (__always_noconv_)
this->setp((char_type*)__extbuf_,
(char_type*)__extbuf_ + (__ebs_ - 1));
else
this->setp(__intbuf_, __intbuf_ + (__ibs_ - 1));
}
else
this->setp(0, 0);
__cm_ = ios_base::out;
}
}
// basic_ifstream
template <class _CharT, class _Traits>
class _LIBCPP_TEMPLATE_VIS basic_ifstream
: public basic_istream<_CharT, _Traits>
{
public:
typedef _CharT char_type;
typedef _Traits traits_type;
typedef typename traits_type::int_type int_type;
typedef typename traits_type::pos_type pos_type;
typedef typename traits_type::off_type off_type;
_LIBCPP_INLINE_VISIBILITY
basic_ifstream();
#ifndef _LIBCPP_HAS_NO_GLOBAL_FILESYSTEM_NAMESPACE
_LIBCPP_INLINE_VISIBILITY
explicit basic_ifstream(const char* __s, ios_base::openmode __mode = ios_base::in);
#ifdef _LIBCPP_HAS_OPEN_WITH_WCHAR
_LIBCPP_INLINE_VISIBILITY
explicit basic_ifstream(const wchar_t* __s, ios_base::openmode __mode = ios_base::in);
#endif
_LIBCPP_INLINE_VISIBILITY
explicit basic_ifstream(const string& __s, ios_base::openmode __mode = ios_base::in);
#if _LIBCPP_STD_VER >= 17
_LIBCPP_AVAILABILITY_FILESYSTEM _LIBCPP_INLINE_VISIBILITY
explicit basic_ifstream(const filesystem::path& __p, ios_base::openmode __mode = ios_base::in)
: basic_ifstream(__p.c_str(), __mode) {}
#endif // _LIBCPP_STD_VER >= 17
#endif
#ifndef _LIBCPP_CXX03_LANG
_LIBCPP_INLINE_VISIBILITY
basic_ifstream(basic_ifstream&& __rhs);
_LIBCPP_INLINE_VISIBILITY
basic_ifstream& operator=(basic_ifstream&& __rhs);
#endif
_LIBCPP_INLINE_VISIBILITY
void swap(basic_ifstream& __rhs);
_LIBCPP_INLINE_VISIBILITY
basic_filebuf<char_type, traits_type>* rdbuf() const;
_LIBCPP_INLINE_VISIBILITY
bool is_open() const;
#ifndef _LIBCPP_HAS_NO_GLOBAL_FILESYSTEM_NAMESPACE
void open(const char* __s, ios_base::openmode __mode = ios_base::in);
#ifdef _LIBCPP_HAS_OPEN_WITH_WCHAR
void open(const wchar_t* __s, ios_base::openmode __mode = ios_base::in);
#endif
void open(const string& __s, ios_base::openmode __mode = ios_base::in);
#if _LIBCPP_STD_VER >= 17
_LIBCPP_AVAILABILITY_FILESYSTEM _LIBCPP_INLINE_VISIBILITY
void open(const filesystem::path& __p,
ios_base::openmode __mode = ios_base::in) {
return open(__p.c_str(), __mode);
}
#endif // _LIBCPP_STD_VER >= 17
_LIBCPP_INLINE_VISIBILITY
void __open(int __fd, ios_base::openmode __mode);
#endif
_LIBCPP_INLINE_VISIBILITY
void close();
private:
basic_filebuf<char_type, traits_type> __sb_;
};
template <class _CharT, class _Traits>
inline
basic_ifstream<_CharT, _Traits>::basic_ifstream()
: basic_istream<char_type, traits_type>(&__sb_)
{
}
#ifndef _LIBCPP_HAS_NO_GLOBAL_FILESYSTEM_NAMESPACE
template <class _CharT, class _Traits>
inline
basic_ifstream<_CharT, _Traits>::basic_ifstream(const char* __s, ios_base::openmode __mode)
: basic_istream<char_type, traits_type>(&__sb_)
{
if (__sb_.open(__s, __mode | ios_base::in) == 0)
this->setstate(ios_base::failbit);
}
#ifdef _LIBCPP_HAS_OPEN_WITH_WCHAR
template <class _CharT, class _Traits>
inline
basic_ifstream<_CharT, _Traits>::basic_ifstream(const wchar_t* __s, ios_base::openmode __mode)
: basic_istream<char_type, traits_type>(&__sb_)
{
if (__sb_.open(__s, __mode | ios_base::in) == 0)
this->setstate(ios_base::failbit);
}
#endif
template <class _CharT, class _Traits>
inline
basic_ifstream<_CharT, _Traits>::basic_ifstream(const string& __s, ios_base::openmode __mode)
: basic_istream<char_type, traits_type>(&__sb_)
{
if (__sb_.open(__s, __mode | ios_base::in) == 0)
this->setstate(ios_base::failbit);
}
#endif
#ifndef _LIBCPP_CXX03_LANG
template <class _CharT, class _Traits>
inline
basic_ifstream<_CharT, _Traits>::basic_ifstream(basic_ifstream&& __rhs)
: basic_istream<char_type, traits_type>(_VSTD::move(__rhs)),
__sb_(_VSTD::move(__rhs.__sb_))
{
this->set_rdbuf(&__sb_);
}
template <class _CharT, class _Traits>
inline
basic_ifstream<_CharT, _Traits>&
basic_ifstream<_CharT, _Traits>::operator=(basic_ifstream&& __rhs)
{
basic_istream<char_type, traits_type>::operator=(_VSTD::move(__rhs));
__sb_ = _VSTD::move(__rhs.__sb_);
return *this;
}
#endif // _LIBCPP_CXX03_LANG
template <class _CharT, class _Traits>
inline
void
basic_ifstream<_CharT, _Traits>::swap(basic_ifstream& __rhs)
{
basic_istream<char_type, traits_type>::swap(__rhs);
__sb_.swap(__rhs.__sb_);
}
template <class _CharT, class _Traits>
inline _LIBCPP_INLINE_VISIBILITY
void
swap(basic_ifstream<_CharT, _Traits>& __x, basic_ifstream<_CharT, _Traits>& __y)
{
__x.swap(__y);
}
template <class _CharT, class _Traits>
inline
basic_filebuf<_CharT, _Traits>*
basic_ifstream<_CharT, _Traits>::rdbuf() const
{
return const_cast<basic_filebuf<char_type, traits_type>*>(&__sb_);
}
template <class _CharT, class _Traits>
inline
bool
basic_ifstream<_CharT, _Traits>::is_open() const
{
return __sb_.is_open();
}
#ifndef _LIBCPP_HAS_NO_GLOBAL_FILESYSTEM_NAMESPACE
template <class _CharT, class _Traits>
void
basic_ifstream<_CharT, _Traits>::open(const char* __s, ios_base::openmode __mode)
{
if (__sb_.open(__s, __mode | ios_base::in))
this->clear();
else
this->setstate(ios_base::failbit);
}
#ifdef _LIBCPP_HAS_OPEN_WITH_WCHAR
template <class _CharT, class _Traits>
void
basic_ifstream<_CharT, _Traits>::open(const wchar_t* __s, ios_base::openmode __mode)
{
if (__sb_.open(__s, __mode | ios_base::in))
this->clear();
else
this->setstate(ios_base::failbit);
}
#endif
template <class _CharT, class _Traits>
void
basic_ifstream<_CharT, _Traits>::open(const string& __s, ios_base::openmode __mode)
{
if (__sb_.open(__s, __mode | ios_base::in))
this->clear();
else
this->setstate(ios_base::failbit);
}
template <class _CharT, class _Traits>
void basic_ifstream<_CharT, _Traits>::__open(int __fd,
ios_base::openmode __mode) {
if (__sb_.__open(__fd, __mode | ios_base::in))
this->clear();
else
this->setstate(ios_base::failbit);
}
#endif
template <class _CharT, class _Traits>
inline
void
basic_ifstream<_CharT, _Traits>::close()
{
if (__sb_.close() == 0)
this->setstate(ios_base::failbit);
}
// basic_ofstream
template <class _CharT, class _Traits>
class _LIBCPP_TEMPLATE_VIS basic_ofstream
: public basic_ostream<_CharT, _Traits>
{
public:
typedef _CharT char_type;
typedef _Traits traits_type;
typedef typename traits_type::int_type int_type;
typedef typename traits_type::pos_type pos_type;
typedef typename traits_type::off_type off_type;
_LIBCPP_INLINE_VISIBILITY
basic_ofstream();
_LIBCPP_INLINE_VISIBILITY
explicit basic_ofstream(const char* __s, ios_base::openmode __mode = ios_base::out);
#ifdef _LIBCPP_HAS_OPEN_WITH_WCHAR
_LIBCPP_INLINE_VISIBILITY
explicit basic_ofstream(const wchar_t* __s, ios_base::openmode __mode = ios_base::out);
#endif
_LIBCPP_INLINE_VISIBILITY
explicit basic_ofstream(const string& __s, ios_base::openmode __mode = ios_base::out);
#if _LIBCPP_STD_VER >= 17
_LIBCPP_AVAILABILITY_FILESYSTEM _LIBCPP_INLINE_VISIBILITY
explicit basic_ofstream(const filesystem::path& __p, ios_base::openmode __mode = ios_base::out)
: basic_ofstream(__p.c_str(), __mode) {}
#endif // _LIBCPP_STD_VER >= 17
#ifndef _LIBCPP_CXX03_LANG
_LIBCPP_INLINE_VISIBILITY
basic_ofstream(basic_ofstream&& __rhs);
_LIBCPP_INLINE_VISIBILITY
basic_ofstream& operator=(basic_ofstream&& __rhs);
#endif
_LIBCPP_INLINE_VISIBILITY
void swap(basic_ofstream& __rhs);
_LIBCPP_INLINE_VISIBILITY
basic_filebuf<char_type, traits_type>* rdbuf() const;
_LIBCPP_INLINE_VISIBILITY
bool is_open() const;
#ifndef _LIBCPP_HAS_NO_GLOBAL_FILESYSTEM_NAMESPACE
void open(const char* __s, ios_base::openmode __mode = ios_base::out);
#ifdef _LIBCPP_HAS_OPEN_WITH_WCHAR
void open(const wchar_t* __s, ios_base::openmode __mode = ios_base::out);
#endif
void open(const string& __s, ios_base::openmode __mode = ios_base::out);
#if _LIBCPP_STD_VER >= 17
_LIBCPP_AVAILABILITY_FILESYSTEM _LIBCPP_INLINE_VISIBILITY
void open(const filesystem::path& __p, ios_base::openmode __mode = ios_base::out)
{ return open(__p.c_str(), __mode); }
#endif // _LIBCPP_STD_VER >= 17
_LIBCPP_INLINE_VISIBILITY
void __open(int __fd, ios_base::openmode __mode);
#endif
_LIBCPP_INLINE_VISIBILITY
void close();
private:
basic_filebuf<char_type, traits_type> __sb_;
};
template <class _CharT, class _Traits>
inline
basic_ofstream<_CharT, _Traits>::basic_ofstream()
: basic_ostream<char_type, traits_type>(&__sb_)
{
}
#ifndef _LIBCPP_HAS_NO_GLOBAL_FILESYSTEM_NAMESPACE
template <class _CharT, class _Traits>
inline
basic_ofstream<_CharT, _Traits>::basic_ofstream(const char* __s, ios_base::openmode __mode)
: basic_ostream<char_type, traits_type>(&__sb_)
{
if (__sb_.open(__s, __mode | ios_base::out) == 0)
this->setstate(ios_base::failbit);
}
#ifdef _LIBCPP_HAS_OPEN_WITH_WCHAR
template <class _CharT, class _Traits>
inline
basic_ofstream<_CharT, _Traits>::basic_ofstream(const wchar_t* __s, ios_base::openmode __mode)
: basic_ostream<char_type, traits_type>(&__sb_)
{
if (__sb_.open(__s, __mode | ios_base::out) == 0)
this->setstate(ios_base::failbit);
}
#endif
template <class _CharT, class _Traits>
inline
basic_ofstream<_CharT, _Traits>::basic_ofstream(const string& __s, ios_base::openmode __mode)
: basic_ostream<char_type, traits_type>(&__sb_)
{
if (__sb_.open(__s, __mode | ios_base::out) == 0)
this->setstate(ios_base::failbit);
}
#endif
#ifndef _LIBCPP_CXX03_LANG
template <class _CharT, class _Traits>
inline
basic_ofstream<_CharT, _Traits>::basic_ofstream(basic_ofstream&& __rhs)
: basic_ostream<char_type, traits_type>(_VSTD::move(__rhs)),
__sb_(_VSTD::move(__rhs.__sb_))
{
this->set_rdbuf(&__sb_);
}
template <class _CharT, class _Traits>
inline
basic_ofstream<_CharT, _Traits>&
basic_ofstream<_CharT, _Traits>::operator=(basic_ofstream&& __rhs)
{
basic_ostream<char_type, traits_type>::operator=(_VSTD::move(__rhs));
__sb_ = _VSTD::move(__rhs.__sb_);
return *this;
}
#endif // _LIBCPP_CXX03_LANG
template <class _CharT, class _Traits>
inline
void
basic_ofstream<_CharT, _Traits>::swap(basic_ofstream& __rhs)
{
basic_ostream<char_type, traits_type>::swap(__rhs);
__sb_.swap(__rhs.__sb_);
}
template <class _CharT, class _Traits>
inline _LIBCPP_INLINE_VISIBILITY
void
swap(basic_ofstream<_CharT, _Traits>& __x, basic_ofstream<_CharT, _Traits>& __y)
{
__x.swap(__y);
}
template <class _CharT, class _Traits>
inline
basic_filebuf<_CharT, _Traits>*
basic_ofstream<_CharT, _Traits>::rdbuf() const
{
return const_cast<basic_filebuf<char_type, traits_type>*>(&__sb_);
}
template <class _CharT, class _Traits>
inline
bool
basic_ofstream<_CharT, _Traits>::is_open() const
{
return __sb_.is_open();
}
#ifndef _LIBCPP_HAS_NO_GLOBAL_FILESYSTEM_NAMESPACE
template <class _CharT, class _Traits>
void
basic_ofstream<_CharT, _Traits>::open(const char* __s, ios_base::openmode __mode)
{
if (__sb_.open(__s, __mode | ios_base::out))
this->clear();
else
this->setstate(ios_base::failbit);
}
#ifdef _LIBCPP_HAS_OPEN_WITH_WCHAR
template <class _CharT, class _Traits>
void
basic_ofstream<_CharT, _Traits>::open(const wchar_t* __s, ios_base::openmode __mode)
{
if (__sb_.open(__s, __mode | ios_base::out))
this->clear();
else
this->setstate(ios_base::failbit);
}
#endif
template <class _CharT, class _Traits>
void
basic_ofstream<_CharT, _Traits>::open(const string& __s, ios_base::openmode __mode)
{
if (__sb_.open(__s, __mode | ios_base::out))
this->clear();
else
this->setstate(ios_base::failbit);
}
template <class _CharT, class _Traits>
void basic_ofstream<_CharT, _Traits>::__open(int __fd,
ios_base::openmode __mode) {
if (__sb_.__open(__fd, __mode | ios_base::out))
this->clear();
else
this->setstate(ios_base::failbit);
}
#endif
template <class _CharT, class _Traits>
inline
void
basic_ofstream<_CharT, _Traits>::close()
{
if (__sb_.close() == 0)
this->setstate(ios_base::failbit);
}
// basic_fstream
template <class _CharT, class _Traits>
class _LIBCPP_TEMPLATE_VIS basic_fstream
: public basic_iostream<_CharT, _Traits>
{
public:
typedef _CharT char_type;
typedef _Traits traits_type;
typedef typename traits_type::int_type int_type;
typedef typename traits_type::pos_type pos_type;
typedef typename traits_type::off_type off_type;
_LIBCPP_INLINE_VISIBILITY
basic_fstream();
#ifndef _LIBCPP_HAS_NO_GLOBAL_FILESYSTEM_NAMESPACE
_LIBCPP_INLINE_VISIBILITY
explicit basic_fstream(const char* __s, ios_base::openmode __mode = ios_base::in | ios_base::out);
#ifdef _LIBCPP_HAS_OPEN_WITH_WCHAR
_LIBCPP_INLINE_VISIBILITY
explicit basic_fstream(const wchar_t* __s, ios_base::openmode __mode = ios_base::in | ios_base::out);
#endif
_LIBCPP_INLINE_VISIBILITY
explicit basic_fstream(const string& __s, ios_base::openmode __mode = ios_base::in | ios_base::out);
#if _LIBCPP_STD_VER >= 17
_LIBCPP_AVAILABILITY_FILESYSTEM _LIBCPP_INLINE_VISIBILITY
explicit basic_fstream(const filesystem::path& __p, ios_base::openmode __mode = ios_base::in | ios_base::out)
: basic_fstream(__p.c_str(), __mode) {}
#endif // _LIBCPP_STD_VER >= 17
#endif
#ifndef _LIBCPP_CXX03_LANG
_LIBCPP_INLINE_VISIBILITY
basic_fstream(basic_fstream&& __rhs);
_LIBCPP_INLINE_VISIBILITY
basic_fstream& operator=(basic_fstream&& __rhs);
#endif
_LIBCPP_INLINE_VISIBILITY
void swap(basic_fstream& __rhs);
_LIBCPP_INLINE_VISIBILITY
basic_filebuf<char_type, traits_type>* rdbuf() const;
_LIBCPP_INLINE_VISIBILITY
bool is_open() const;
#ifndef _LIBCPP_HAS_NO_GLOBAL_FILESYSTEM_NAMESPACE
void open(const char* __s, ios_base::openmode __mode = ios_base::in | ios_base::out);
#ifdef _LIBCPP_HAS_OPEN_WITH_WCHAR
void open(const wchar_t* __s, ios_base::openmode __mode = ios_base::in | ios_base::out);
#endif
void open(const string& __s, ios_base::openmode __mode = ios_base::in | ios_base::out);
#if _LIBCPP_STD_VER >= 17
_LIBCPP_AVAILABILITY_FILESYSTEM _LIBCPP_INLINE_VISIBILITY
void open(const filesystem::path& __p, ios_base::openmode __mode = ios_base::in|ios_base::out)
{ return open(__p.c_str(), __mode); }
#endif // _LIBCPP_STD_VER >= 17
#endif
_LIBCPP_INLINE_VISIBILITY
void close();
private:
basic_filebuf<char_type, traits_type> __sb_;
};
template <class _CharT, class _Traits>
inline
basic_fstream<_CharT, _Traits>::basic_fstream()
: basic_iostream<char_type, traits_type>(&__sb_)
{
}
#ifndef _LIBCPP_HAS_NO_GLOBAL_FILESYSTEM_NAMESPACE
template <class _CharT, class _Traits>
inline
basic_fstream<_CharT, _Traits>::basic_fstream(const char* __s, ios_base::openmode __mode)
: basic_iostream<char_type, traits_type>(&__sb_)
{
if (__sb_.open(__s, __mode) == 0)
this->setstate(ios_base::failbit);
}
#ifdef _LIBCPP_HAS_OPEN_WITH_WCHAR
template <class _CharT, class _Traits>
inline
basic_fstream<_CharT, _Traits>::basic_fstream(const wchar_t* __s, ios_base::openmode __mode)
: basic_iostream<char_type, traits_type>(&__sb_)
{
if (__sb_.open(__s, __mode) == 0)
this->setstate(ios_base::failbit);
}
#endif
template <class _CharT, class _Traits>
inline
basic_fstream<_CharT, _Traits>::basic_fstream(const string& __s, ios_base::openmode __mode)
: basic_iostream<char_type, traits_type>(&__sb_)
{
if (__sb_.open(__s, __mode) == 0)
this->setstate(ios_base::failbit);
}
#endif
#ifndef _LIBCPP_CXX03_LANG
template <class _CharT, class _Traits>
inline
basic_fstream<_CharT, _Traits>::basic_fstream(basic_fstream&& __rhs)
: basic_iostream<char_type, traits_type>(_VSTD::move(__rhs)),
__sb_(_VSTD::move(__rhs.__sb_))
{
this->set_rdbuf(&__sb_);
}
template <class _CharT, class _Traits>
inline
basic_fstream<_CharT, _Traits>&
basic_fstream<_CharT, _Traits>::operator=(basic_fstream&& __rhs)
{
basic_iostream<char_type, traits_type>::operator=(_VSTD::move(__rhs));
__sb_ = _VSTD::move(__rhs.__sb_);
return *this;
}
#endif // _LIBCPP_CXX03_LANG
template <class _CharT, class _Traits>
inline
void
basic_fstream<_CharT, _Traits>::swap(basic_fstream& __rhs)
{
basic_iostream<char_type, traits_type>::swap(__rhs);
__sb_.swap(__rhs.__sb_);
}
template <class _CharT, class _Traits>
inline _LIBCPP_INLINE_VISIBILITY
void
swap(basic_fstream<_CharT, _Traits>& __x, basic_fstream<_CharT, _Traits>& __y)
{
__x.swap(__y);
}
template <class _CharT, class _Traits>
inline
basic_filebuf<_CharT, _Traits>*
basic_fstream<_CharT, _Traits>::rdbuf() const
{
return const_cast<basic_filebuf<char_type, traits_type>*>(&__sb_);
}
template <class _CharT, class _Traits>
inline
bool
basic_fstream<_CharT, _Traits>::is_open() const
{
return __sb_.is_open();
}
#ifndef _LIBCPP_HAS_NO_GLOBAL_FILESYSTEM_NAMESPACE
template <class _CharT, class _Traits>
void
basic_fstream<_CharT, _Traits>::open(const char* __s, ios_base::openmode __mode)
{
if (__sb_.open(__s, __mode))
this->clear();
else
this->setstate(ios_base::failbit);
}
#ifdef _LIBCPP_HAS_OPEN_WITH_WCHAR
template <class _CharT, class _Traits>
void
basic_fstream<_CharT, _Traits>::open(const wchar_t* __s, ios_base::openmode __mode)
{
if (__sb_.open(__s, __mode))
this->clear();
else
this->setstate(ios_base::failbit);
}
#endif
template <class _CharT, class _Traits>
void
basic_fstream<_CharT, _Traits>::open(const string& __s, ios_base::openmode __mode)
{
if (__sb_.open(__s, __mode))
this->clear();
else
this->setstate(ios_base::failbit);
}
#endif
template <class _CharT, class _Traits>
inline
void
basic_fstream<_CharT, _Traits>::close()
{
if (__sb_.close() == 0)
this->setstate(ios_base::failbit);
}
_LIBCPP_END_NAMESPACE_STD
_LIBCPP_POP_MACROS
#endif // _LIBCPP_FSTREAM
| 54,496 | 1,765 | jart/cosmopolitan | false |
cosmopolitan/third_party/libcxx/tuple | // -*- C++ -*-
//===--------------------------- tuple ------------------------------------===//
//
// 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_TUPLE
#define _LIBCPP_TUPLE
#include "third_party/libcxx/__config"
#include "third_party/libcxx/__tuple"
#include "third_party/libcxx/cstddef"
#include "third_party/libcxx/type_traits"
#include "third_party/libcxx/__functional_base"
#include "third_party/libcxx/utility"
#include "third_party/libcxx/version"
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
#pragma GCC system_header
#endif
_LIBCPP_BEGIN_NAMESPACE_STD
/*
tuple synopsis
namespace std
{
template <class... T>
class tuple {
public:
explicit(see-below) constexpr tuple();
explicit(see-below) tuple(const T&...); // constexpr in C++14
template <class... U>
explicit(see-below) tuple(U&&...); // constexpr in C++14
tuple(const tuple&) = default;
tuple(tuple&&) = default;
template <class... U>
explicit(see-below) tuple(const tuple<U...>&); // constexpr in C++14
template <class... U>
explicit(see-below) tuple(tuple<U...>&&); // constexpr in C++14
template <class U1, class U2>
explicit(see-below) tuple(const pair<U1, U2>&); // iff sizeof...(T) == 2 // constexpr in C++14
template <class U1, class U2>
explicit(see-below) tuple(pair<U1, U2>&&); // iff sizeof...(T) == 2 // constexpr in C++14
// allocator-extended constructors
template <class Alloc>
tuple(allocator_arg_t, const Alloc& a);
template <class Alloc>
explicit(see-below) tuple(allocator_arg_t, const Alloc& a, const T&...);
template <class Alloc, class... U>
explicit(see-below) tuple(allocator_arg_t, const Alloc& a, U&&...);
template <class Alloc>
tuple(allocator_arg_t, const Alloc& a, const tuple&);
template <class Alloc>
tuple(allocator_arg_t, const Alloc& a, tuple&&);
template <class Alloc, class... U>
explicit(see-below) tuple(allocator_arg_t, const Alloc& a, const tuple<U...>&);
template <class Alloc, class... U>
explicit(see-below) tuple(allocator_arg_t, const Alloc& a, tuple<U...>&&);
template <class Alloc, class U1, class U2>
explicit(see-below) tuple(allocator_arg_t, const Alloc& a, const pair<U1, U2>&);
template <class Alloc, class U1, class U2>
explicit(see-below) tuple(allocator_arg_t, const Alloc& a, pair<U1, U2>&&);
tuple& operator=(const tuple&);
tuple&
operator=(tuple&&) noexcept(AND(is_nothrow_move_assignable<T>::value ...));
template <class... U>
tuple& operator=(const tuple<U...>&);
template <class... U>
tuple& operator=(tuple<U...>&&);
template <class U1, class U2>
tuple& operator=(const pair<U1, U2>&); // iff sizeof...(T) == 2
template <class U1, class U2>
tuple& operator=(pair<U1, U2>&&); // iff sizeof...(T) == 2
void swap(tuple&) noexcept(AND(swap(declval<T&>(), declval<T&>())...));
};
template <class ...T>
tuple(T...) -> tuple<T...>; // since C++17
template <class T1, class T2>
tuple(pair<T1, T2>) -> tuple<T1, T2>; // since C++17
template <class Alloc, class ...T>
tuple(allocator_arg_t, Alloc, T...) -> tuple<T...>; // since C++17
template <class Alloc, class T1, class T2>
tuple(allocator_arg_t, Alloc, pair<T1, T2>) -> tuple<T1, T2>; // since C++17
template <class Alloc, class ...T>
tuple(allocator_arg_t, Alloc, tuple<T...>) -> tuple<T...>; // since C++17
inline constexpr unspecified ignore;
template <class... T> tuple<V...> make_tuple(T&&...); // constexpr in C++14
template <class... T> tuple<ATypes...> forward_as_tuple(T&&...) noexcept; // constexpr in C++14
template <class... T> tuple<T&...> tie(T&...) noexcept; // constexpr in C++14
template <class... Tuples> tuple<CTypes...> tuple_cat(Tuples&&... tpls); // constexpr in C++14
// [tuple.apply], calling a function with a tuple of arguments:
template <class F, class Tuple>
constexpr decltype(auto) apply(F&& f, Tuple&& t); // C++17
template <class T, class Tuple>
constexpr T make_from_tuple(Tuple&& t); // C++17
// 20.4.1.4, tuple helper classes:
template <class T> struct tuple_size; // undefined
template <class... T> struct tuple_size<tuple<T...>>;
template <class T>
inline constexpr size_t tuple_size_v = tuple_size<T>::value; // C++17
template <size_t I, class T> struct tuple_element; // undefined
template <size_t I, class... T> struct tuple_element<I, tuple<T...>>;
template <size_t I, class T>
using tuple_element_t = typename tuple_element <I, T>::type; // C++14
// 20.4.1.5, element access:
template <size_t I, class... T>
typename tuple_element<I, tuple<T...>>::type&
get(tuple<T...>&) noexcept; // constexpr in C++14
template <size_t I, class... T>
const typename tuple_element<I, tuple<T...>>::type&
get(const tuple<T...>&) noexcept; // constexpr in C++14
template <size_t I, class... T>
typename tuple_element<I, tuple<T...>>::type&&
get(tuple<T...>&&) noexcept; // constexpr in C++14
template <size_t I, class... T>
const typename tuple_element<I, tuple<T...>>::type&&
get(const tuple<T...>&&) noexcept; // constexpr in C++14
template <class T1, class... T>
constexpr T1& get(tuple<T...>&) noexcept; // C++14
template <class T1, class... T>
constexpr const T1& get(const tuple<T...>&) noexcept; // C++14
template <class T1, class... T>
constexpr T1&& get(tuple<T...>&&) noexcept; // C++14
template <class T1, class... T>
constexpr const T1&& get(const tuple<T...>&&) noexcept; // C++14
// 20.4.1.6, relational operators:
template<class... T, class... U> bool operator==(const tuple<T...>&, const tuple<U...>&); // constexpr in C++14
template<class... T, class... U> bool operator<(const tuple<T...>&, const tuple<U...>&); // constexpr in C++14
template<class... T, class... U> bool operator!=(const tuple<T...>&, const tuple<U...>&); // constexpr in C++14
template<class... T, class... U> bool operator>(const tuple<T...>&, const tuple<U...>&); // constexpr in C++14
template<class... T, class... U> bool operator<=(const tuple<T...>&, const tuple<U...>&); // constexpr in C++14
template<class... T, class... U> bool operator>=(const tuple<T...>&, const tuple<U...>&); // constexpr in C++14
template <class... Types, class Alloc>
struct uses_allocator<tuple<Types...>, Alloc>;
template <class... Types>
void
swap(tuple<Types...>& x, tuple<Types...>& y) noexcept(noexcept(x.swap(y)));
} // std
*/
#ifndef _LIBCPP_CXX03_LANG
// __tuple_leaf
template <size_t _Ip, class _Hp,
bool=is_empty<_Hp>::value && !__libcpp_is_final<_Hp>::value
>
class __tuple_leaf;
template <size_t _Ip, class _Hp, bool _Ep>
inline _LIBCPP_INLINE_VISIBILITY
void swap(__tuple_leaf<_Ip, _Hp, _Ep>& __x, __tuple_leaf<_Ip, _Hp, _Ep>& __y)
_NOEXCEPT_(__is_nothrow_swappable<_Hp>::value)
{
swap(__x.get(), __y.get());
}
template <size_t _Ip, class _Hp, bool>
class __tuple_leaf
{
_Hp __value_;
template <class _Tp>
static constexpr bool __can_bind_reference() {
#if __has_keyword(__reference_binds_to_temporary)
return !__reference_binds_to_temporary(_Hp, _Tp);
#else
return true;
#endif
}
__tuple_leaf& operator=(const __tuple_leaf&);
public:
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR __tuple_leaf()
_NOEXCEPT_(is_nothrow_default_constructible<_Hp>::value) : __value_()
{static_assert(!is_reference<_Hp>::value,
"Attempted to default construct a reference element in a tuple");}
template <class _Alloc>
_LIBCPP_INLINE_VISIBILITY
__tuple_leaf(integral_constant<int, 0>, const _Alloc&)
: __value_()
{static_assert(!is_reference<_Hp>::value,
"Attempted to default construct a reference element in a tuple");}
template <class _Alloc>
_LIBCPP_INLINE_VISIBILITY
__tuple_leaf(integral_constant<int, 1>, const _Alloc& __a)
: __value_(allocator_arg_t(), __a)
{static_assert(!is_reference<_Hp>::value,
"Attempted to default construct a reference element in a tuple");}
template <class _Alloc>
_LIBCPP_INLINE_VISIBILITY
__tuple_leaf(integral_constant<int, 2>, const _Alloc& __a)
: __value_(__a)
{static_assert(!is_reference<_Hp>::value,
"Attempted to default construct a reference element in a tuple");}
template <class _Tp,
class = _EnableIf<
_And<
_IsNotSame<__uncvref_t<_Tp>, __tuple_leaf>,
is_constructible<_Hp, _Tp>
>::value
>
>
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
explicit __tuple_leaf(_Tp&& __t) _NOEXCEPT_((is_nothrow_constructible<_Hp, _Tp>::value))
: __value_(_VSTD::forward<_Tp>(__t))
{static_assert(__can_bind_reference<_Tp&&>(),
"Attempted construction of reference element binds to a temporary whose lifetime has ended");}
template <class _Tp, class _Alloc>
_LIBCPP_INLINE_VISIBILITY
explicit __tuple_leaf(integral_constant<int, 0>, const _Alloc&, _Tp&& __t)
: __value_(_VSTD::forward<_Tp>(__t))
{static_assert(__can_bind_reference<_Tp&&>(),
"Attempted construction of reference element binds to a temporary whose lifetime has ended");}
template <class _Tp, class _Alloc>
_LIBCPP_INLINE_VISIBILITY
explicit __tuple_leaf(integral_constant<int, 1>, const _Alloc& __a, _Tp&& __t)
: __value_(allocator_arg_t(), __a, _VSTD::forward<_Tp>(__t))
{static_assert(!is_reference<_Hp>::value,
"Attempted to uses-allocator construct a reference element in a tuple");}
template <class _Tp, class _Alloc>
_LIBCPP_INLINE_VISIBILITY
explicit __tuple_leaf(integral_constant<int, 2>, const _Alloc& __a, _Tp&& __t)
: __value_(_VSTD::forward<_Tp>(__t), __a)
{static_assert(!is_reference<_Hp>::value,
"Attempted to uses-allocator construct a reference element in a tuple");}
__tuple_leaf(const __tuple_leaf& __t) = default;
__tuple_leaf(__tuple_leaf&& __t) = default;
template <class _Tp>
_LIBCPP_INLINE_VISIBILITY
__tuple_leaf&
operator=(_Tp&& __t) _NOEXCEPT_((is_nothrow_assignable<_Hp&, _Tp>::value))
{
__value_ = _VSTD::forward<_Tp>(__t);
return *this;
}
_LIBCPP_INLINE_VISIBILITY
int swap(__tuple_leaf& __t) _NOEXCEPT_(__is_nothrow_swappable<__tuple_leaf>::value)
{
_VSTD::swap(*this, __t);
return 0;
}
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 _Hp& get() _NOEXCEPT {return __value_;}
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 const _Hp& get() const _NOEXCEPT {return __value_;}
};
template <size_t _Ip, class _Hp>
class __tuple_leaf<_Ip, _Hp, true>
: private _Hp
{
__tuple_leaf& operator=(const __tuple_leaf&);
public:
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR __tuple_leaf()
_NOEXCEPT_(is_nothrow_default_constructible<_Hp>::value) {}
template <class _Alloc>
_LIBCPP_INLINE_VISIBILITY
__tuple_leaf(integral_constant<int, 0>, const _Alloc&) {}
template <class _Alloc>
_LIBCPP_INLINE_VISIBILITY
__tuple_leaf(integral_constant<int, 1>, const _Alloc& __a)
: _Hp(allocator_arg_t(), __a) {}
template <class _Alloc>
_LIBCPP_INLINE_VISIBILITY
__tuple_leaf(integral_constant<int, 2>, const _Alloc& __a)
: _Hp(__a) {}
template <class _Tp,
class = _EnableIf<
_And<
_IsNotSame<__uncvref_t<_Tp>, __tuple_leaf>,
is_constructible<_Hp, _Tp>
>::value
>
>
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
explicit __tuple_leaf(_Tp&& __t) _NOEXCEPT_((is_nothrow_constructible<_Hp, _Tp>::value))
: _Hp(_VSTD::forward<_Tp>(__t)) {}
template <class _Tp, class _Alloc>
_LIBCPP_INLINE_VISIBILITY
explicit __tuple_leaf(integral_constant<int, 0>, const _Alloc&, _Tp&& __t)
: _Hp(_VSTD::forward<_Tp>(__t)) {}
template <class _Tp, class _Alloc>
_LIBCPP_INLINE_VISIBILITY
explicit __tuple_leaf(integral_constant<int, 1>, const _Alloc& __a, _Tp&& __t)
: _Hp(allocator_arg_t(), __a, _VSTD::forward<_Tp>(__t)) {}
template <class _Tp, class _Alloc>
_LIBCPP_INLINE_VISIBILITY
explicit __tuple_leaf(integral_constant<int, 2>, const _Alloc& __a, _Tp&& __t)
: _Hp(_VSTD::forward<_Tp>(__t), __a) {}
__tuple_leaf(__tuple_leaf const &) = default;
__tuple_leaf(__tuple_leaf &&) = default;
template <class _Tp>
_LIBCPP_INLINE_VISIBILITY
__tuple_leaf&
operator=(_Tp&& __t) _NOEXCEPT_((is_nothrow_assignable<_Hp&, _Tp>::value))
{
_Hp::operator=(_VSTD::forward<_Tp>(__t));
return *this;
}
_LIBCPP_INLINE_VISIBILITY
int
swap(__tuple_leaf& __t) _NOEXCEPT_(__is_nothrow_swappable<__tuple_leaf>::value)
{
_VSTD::swap(*this, __t);
return 0;
}
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 _Hp& get() _NOEXCEPT {return static_cast<_Hp&>(*this);}
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 const _Hp& get() const _NOEXCEPT {return static_cast<const _Hp&>(*this);}
};
template <class ..._Tp>
_LIBCPP_INLINE_VISIBILITY
void __swallow(_Tp&&...) _NOEXCEPT {}
template <class _Tp>
struct __all_default_constructible;
template <class ..._Tp>
struct __all_default_constructible<__tuple_types<_Tp...>>
: __all<is_default_constructible<_Tp>::value...>
{ };
// __tuple_impl
template<class _Indx, class ..._Tp> struct __tuple_impl;
template<size_t ..._Indx, class ..._Tp>
struct _LIBCPP_DECLSPEC_EMPTY_BASES __tuple_impl<__tuple_indices<_Indx...>, _Tp...>
: public __tuple_leaf<_Indx, _Tp>...
{
_LIBCPP_INLINE_VISIBILITY
_LIBCPP_CONSTEXPR __tuple_impl()
_NOEXCEPT_(__all<is_nothrow_default_constructible<_Tp>::value...>::value) {}
template <size_t ..._Uf, class ..._Tf,
size_t ..._Ul, class ..._Tl, class ..._Up>
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
explicit
__tuple_impl(__tuple_indices<_Uf...>, __tuple_types<_Tf...>,
__tuple_indices<_Ul...>, __tuple_types<_Tl...>,
_Up&&... __u)
_NOEXCEPT_((__all<is_nothrow_constructible<_Tf, _Up>::value...>::value &&
__all<is_nothrow_default_constructible<_Tl>::value...>::value)) :
__tuple_leaf<_Uf, _Tf>(_VSTD::forward<_Up>(__u))...,
__tuple_leaf<_Ul, _Tl>()...
{}
template <class _Alloc, size_t ..._Uf, class ..._Tf,
size_t ..._Ul, class ..._Tl, class ..._Up>
_LIBCPP_INLINE_VISIBILITY
explicit
__tuple_impl(allocator_arg_t, const _Alloc& __a,
__tuple_indices<_Uf...>, __tuple_types<_Tf...>,
__tuple_indices<_Ul...>, __tuple_types<_Tl...>,
_Up&&... __u) :
__tuple_leaf<_Uf, _Tf>(__uses_alloc_ctor<_Tf, _Alloc, _Up>(), __a,
_VSTD::forward<_Up>(__u))...,
__tuple_leaf<_Ul, _Tl>(__uses_alloc_ctor<_Tl, _Alloc>(), __a)...
{}
template <class _Tuple,
class = typename enable_if
<
__tuple_constructible<_Tuple, tuple<_Tp...> >::value
>::type
>
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
__tuple_impl(_Tuple&& __t) _NOEXCEPT_((__all<is_nothrow_constructible<_Tp, typename tuple_element<_Indx,
typename __make_tuple_types<_Tuple>::type>::type>::value...>::value))
: __tuple_leaf<_Indx, _Tp>(_VSTD::forward<typename tuple_element<_Indx,
typename __make_tuple_types<_Tuple>::type>::type>(_VSTD::get<_Indx>(__t)))...
{}
template <class _Alloc, class _Tuple,
class = typename enable_if
<
__tuple_constructible<_Tuple, tuple<_Tp...> >::value
>::type
>
_LIBCPP_INLINE_VISIBILITY
__tuple_impl(allocator_arg_t, const _Alloc& __a, _Tuple&& __t)
: __tuple_leaf<_Indx, _Tp>(__uses_alloc_ctor<_Tp, _Alloc, typename tuple_element<_Indx,
typename __make_tuple_types<_Tuple>::type>::type>(), __a,
_VSTD::forward<typename tuple_element<_Indx,
typename __make_tuple_types<_Tuple>::type>::type>(_VSTD::get<_Indx>(__t)))...
{}
template <class _Tuple>
_LIBCPP_INLINE_VISIBILITY
typename enable_if
<
__tuple_assignable<_Tuple, tuple<_Tp...> >::value,
__tuple_impl&
>::type
operator=(_Tuple&& __t) _NOEXCEPT_((__all<is_nothrow_assignable<_Tp&, typename tuple_element<_Indx,
typename __make_tuple_types<_Tuple>::type>::type>::value...>::value))
{
__swallow(__tuple_leaf<_Indx, _Tp>::operator=(_VSTD::forward<typename tuple_element<_Indx,
typename __make_tuple_types<_Tuple>::type>::type>(_VSTD::get<_Indx>(__t)))...);
return *this;
}
__tuple_impl(const __tuple_impl&) = default;
__tuple_impl(__tuple_impl&&) = default;
_LIBCPP_INLINE_VISIBILITY
__tuple_impl&
operator=(const __tuple_impl& __t) _NOEXCEPT_((__all<is_nothrow_copy_assignable<_Tp>::value...>::value))
{
__swallow(__tuple_leaf<_Indx, _Tp>::operator=(static_cast<const __tuple_leaf<_Indx, _Tp>&>(__t).get())...);
return *this;
}
_LIBCPP_INLINE_VISIBILITY
__tuple_impl&
operator=(__tuple_impl&& __t) _NOEXCEPT_((__all<is_nothrow_move_assignable<_Tp>::value...>::value))
{
__swallow(__tuple_leaf<_Indx, _Tp>::operator=(_VSTD::forward<_Tp>(static_cast<__tuple_leaf<_Indx, _Tp>&>(__t).get()))...);
return *this;
}
_LIBCPP_INLINE_VISIBILITY
void swap(__tuple_impl& __t)
_NOEXCEPT_(__all<__is_nothrow_swappable<_Tp>::value...>::value)
{
__swallow(__tuple_leaf<_Indx, _Tp>::swap(static_cast<__tuple_leaf<_Indx, _Tp>&>(__t))...);
}
};
template <class ..._Tp>
class _LIBCPP_TEMPLATE_VIS tuple
{
typedef __tuple_impl<typename __make_tuple_indices<sizeof...(_Tp)>::type, _Tp...> _BaseT;
_BaseT __base_;
#if defined(_LIBCPP_ENABLE_TUPLE_IMPLICIT_REDUCED_ARITY_EXTENSION)
static constexpr bool _EnableImplicitReducedArityExtension = true;
#else
static constexpr bool _EnableImplicitReducedArityExtension = false;
#endif
template <class ..._Args>
struct _PackExpandsToThisTuple : false_type {};
template <class _Arg>
struct _PackExpandsToThisTuple<_Arg>
: is_same<typename __uncvref<_Arg>::type, tuple> {};
template <bool _MaybeEnable, class _Dummy = void>
struct _CheckArgsConstructor : __check_tuple_constructor_fail {};
template <class _Dummy>
struct _CheckArgsConstructor<true, _Dummy>
{
template <int&...>
static constexpr bool __enable_implicit_default() {
return __all<__is_implicitly_default_constructible<_Tp>::value... >::value;
}
template <int&...>
static constexpr bool __enable_explicit_default() {
return
__all<is_default_constructible<_Tp>::value...>::value &&
!__enable_implicit_default< >();
}
template <class ..._Args>
static constexpr bool __enable_explicit() {
return
__tuple_constructible<
tuple<_Args...>,
typename __make_tuple_types<tuple,
sizeof...(_Args) < sizeof...(_Tp) ?
sizeof...(_Args) :
sizeof...(_Tp)>::type
>::value &&
!__tuple_convertible<
tuple<_Args...>,
typename __make_tuple_types<tuple,
sizeof...(_Args) < sizeof...(_Tp) ?
sizeof...(_Args) :
sizeof...(_Tp)>::type
>::value &&
__all_default_constructible<
typename __make_tuple_types<tuple, sizeof...(_Tp),
sizeof...(_Args) < sizeof...(_Tp) ?
sizeof...(_Args) :
sizeof...(_Tp)>::type
>::value;
}
template <class ..._Args>
static constexpr bool __enable_implicit() {
return
__tuple_constructible<
tuple<_Args...>,
typename __make_tuple_types<tuple,
sizeof...(_Args) < sizeof...(_Tp) ?
sizeof...(_Args) :
sizeof...(_Tp)>::type
>::value &&
__tuple_convertible<
tuple<_Args...>,
typename __make_tuple_types<tuple,
sizeof...(_Args) < sizeof...(_Tp) ?
sizeof...(_Args) :
sizeof...(_Tp)>::type
>::value &&
__all_default_constructible<
typename __make_tuple_types<tuple, sizeof...(_Tp),
sizeof...(_Args) < sizeof...(_Tp) ?
sizeof...(_Args) :
sizeof...(_Tp)>::type
>::value;
}
};
template <bool _MaybeEnable,
bool = sizeof...(_Tp) == 1,
class _Dummy = void>
struct _CheckTupleLikeConstructor : __check_tuple_constructor_fail {};
template <class _Dummy>
struct _CheckTupleLikeConstructor<true, false, _Dummy>
{
template <class _Tuple>
static constexpr bool __enable_implicit() {
return __tuple_constructible<_Tuple, tuple>::value
&& __tuple_convertible<_Tuple, tuple>::value;
}
template <class _Tuple>
static constexpr bool __enable_explicit() {
return __tuple_constructible<_Tuple, tuple>::value
&& !__tuple_convertible<_Tuple, tuple>::value;
}
};
template <class _Dummy>
struct _CheckTupleLikeConstructor<true, true, _Dummy>
{
// This trait is used to disable the tuple-like constructor when
// the UTypes... constructor should be selected instead.
// See LWG issue #2549.
template <class _Tuple>
using _PreferTupleLikeConstructor = _Or<
// Don't attempt the two checks below if the tuple we are given
// has the same type as this tuple.
_IsSame<__uncvref_t<_Tuple>, tuple>,
_Lazy<_And,
_Not<is_constructible<_Tp..., _Tuple>>,
_Not<is_convertible<_Tuple, _Tp...>>
>
>;
template <class _Tuple>
static constexpr bool __enable_implicit() {
return _And<
__tuple_constructible<_Tuple, tuple>,
__tuple_convertible<_Tuple, tuple>,
_PreferTupleLikeConstructor<_Tuple>
>::value;
}
template <class _Tuple>
static constexpr bool __enable_explicit() {
return _And<
__tuple_constructible<_Tuple, tuple>,
_PreferTupleLikeConstructor<_Tuple>,
_Not<__tuple_convertible<_Tuple, tuple>>
>::value;
}
};
template <class _Tuple, bool _DisableIfLValue>
using _EnableImplicitTupleLikeConstructor = _EnableIf<
_CheckTupleLikeConstructor<
__tuple_like_with_size<_Tuple, sizeof...(_Tp)>::value
&& !_PackExpandsToThisTuple<_Tuple>::value
&& (!is_lvalue_reference<_Tuple>::value || !_DisableIfLValue)
>::template __enable_implicit<_Tuple>(),
bool
>;
template <class _Tuple, bool _DisableIfLValue>
using _EnableExplicitTupleLikeConstructor = _EnableIf<
_CheckTupleLikeConstructor<
__tuple_like_with_size<_Tuple, sizeof...(_Tp)>::value
&& !_PackExpandsToThisTuple<_Tuple>::value
&& (!is_lvalue_reference<_Tuple>::value || !_DisableIfLValue)
>::template __enable_explicit<_Tuple>(),
bool
>;
template <size_t _Jp, class ..._Up> friend _LIBCPP_CONSTEXPR_AFTER_CXX11
typename tuple_element<_Jp, tuple<_Up...> >::type& get(tuple<_Up...>&) _NOEXCEPT;
template <size_t _Jp, class ..._Up> friend _LIBCPP_CONSTEXPR_AFTER_CXX11
const typename tuple_element<_Jp, tuple<_Up...> >::type& get(const tuple<_Up...>&) _NOEXCEPT;
template <size_t _Jp, class ..._Up> friend _LIBCPP_CONSTEXPR_AFTER_CXX11
typename tuple_element<_Jp, tuple<_Up...> >::type&& get(tuple<_Up...>&&) _NOEXCEPT;
template <size_t _Jp, class ..._Up> friend _LIBCPP_CONSTEXPR_AFTER_CXX11
const typename tuple_element<_Jp, tuple<_Up...> >::type&& get(const tuple<_Up...>&&) _NOEXCEPT;
public:
template <bool _Dummy = true, _EnableIf<
_CheckArgsConstructor<_Dummy>::__enable_implicit_default()
, void*> = nullptr>
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
tuple()
_NOEXCEPT_(__all<is_nothrow_default_constructible<_Tp>::value...>::value) {}
template <bool _Dummy = true, _EnableIf<
_CheckArgsConstructor<_Dummy>::__enable_explicit_default()
, void*> = nullptr>
explicit _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
tuple()
_NOEXCEPT_(__all<is_nothrow_default_constructible<_Tp>::value...>::value) {}
tuple(tuple const&) = default;
tuple(tuple&&) = default;
template <class _AllocArgT, class _Alloc, _EnableIf<
_CheckArgsConstructor<_IsSame<allocator_arg_t, _AllocArgT>::value >::__enable_implicit_default()
, void*> = nullptr
>
_LIBCPP_INLINE_VISIBILITY
tuple(_AllocArgT, _Alloc const& __a)
: __base_(allocator_arg_t(), __a,
__tuple_indices<>(), __tuple_types<>(),
typename __make_tuple_indices<sizeof...(_Tp), 0>::type(),
__tuple_types<_Tp...>()) {}
template <class _AllocArgT, class _Alloc, _EnableIf<
_CheckArgsConstructor<_IsSame<allocator_arg_t, _AllocArgT>::value>::__enable_explicit_default()
, void*> = nullptr
>
explicit _LIBCPP_INLINE_VISIBILITY
tuple(_AllocArgT, _Alloc const& __a)
: __base_(allocator_arg_t(), __a,
__tuple_indices<>(), __tuple_types<>(),
typename __make_tuple_indices<sizeof...(_Tp), 0>::type(),
__tuple_types<_Tp...>()) {}
template <bool _Dummy = true,
typename enable_if
<
_CheckArgsConstructor<
_Dummy
>::template __enable_implicit<_Tp const&...>(),
bool
>::type = false
>
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
tuple(const _Tp& ... __t) _NOEXCEPT_((__all<is_nothrow_copy_constructible<_Tp>::value...>::value))
: __base_(typename __make_tuple_indices<sizeof...(_Tp)>::type(),
typename __make_tuple_types<tuple, sizeof...(_Tp)>::type(),
typename __make_tuple_indices<0>::type(),
typename __make_tuple_types<tuple, 0>::type(),
__t...
) {}
template <bool _Dummy = true,
typename enable_if
<
_CheckArgsConstructor<
_Dummy
>::template __enable_explicit<_Tp const&...>(),
bool
>::type = false
>
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
explicit tuple(const _Tp& ... __t) _NOEXCEPT_((__all<is_nothrow_copy_constructible<_Tp>::value...>::value))
: __base_(typename __make_tuple_indices<sizeof...(_Tp)>::type(),
typename __make_tuple_types<tuple, sizeof...(_Tp)>::type(),
typename __make_tuple_indices<0>::type(),
typename __make_tuple_types<tuple, 0>::type(),
__t...
) {}
template <class _Alloc, bool _Dummy = true,
typename enable_if
<
_CheckArgsConstructor<
_Dummy
>::template __enable_implicit<_Tp const&...>(),
bool
>::type = false
>
_LIBCPP_INLINE_VISIBILITY
tuple(allocator_arg_t, const _Alloc& __a, const _Tp& ... __t)
: __base_(allocator_arg_t(), __a,
typename __make_tuple_indices<sizeof...(_Tp)>::type(),
typename __make_tuple_types<tuple, sizeof...(_Tp)>::type(),
typename __make_tuple_indices<0>::type(),
typename __make_tuple_types<tuple, 0>::type(),
__t...
) {}
template <class _Alloc, bool _Dummy = true,
typename enable_if
<
_CheckArgsConstructor<
_Dummy
>::template __enable_explicit<_Tp const&...>(),
bool
>::type = false
>
_LIBCPP_INLINE_VISIBILITY
explicit
tuple(allocator_arg_t, const _Alloc& __a, const _Tp& ... __t)
: __base_(allocator_arg_t(), __a,
typename __make_tuple_indices<sizeof...(_Tp)>::type(),
typename __make_tuple_types<tuple, sizeof...(_Tp)>::type(),
typename __make_tuple_indices<0>::type(),
typename __make_tuple_types<tuple, 0>::type(),
__t...
) {}
template <class ..._Up,
bool _PackIsTuple = _PackExpandsToThisTuple<_Up...>::value,
typename enable_if
<
_CheckArgsConstructor<
sizeof...(_Up) == sizeof...(_Tp)
&& !_PackIsTuple
>::template __enable_implicit<_Up...>() ||
_CheckArgsConstructor<
_EnableImplicitReducedArityExtension
&& sizeof...(_Up) < sizeof...(_Tp)
&& !_PackIsTuple
>::template __enable_implicit<_Up...>(),
bool
>::type = false
>
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
tuple(_Up&&... __u)
_NOEXCEPT_((
is_nothrow_constructible<_BaseT,
typename __make_tuple_indices<sizeof...(_Up)>::type,
typename __make_tuple_types<tuple, sizeof...(_Up)>::type,
typename __make_tuple_indices<sizeof...(_Tp), sizeof...(_Up)>::type,
typename __make_tuple_types<tuple, sizeof...(_Tp), sizeof...(_Up)>::type,
_Up...
>::value
))
: __base_(typename __make_tuple_indices<sizeof...(_Up)>::type(),
typename __make_tuple_types<tuple, sizeof...(_Up)>::type(),
typename __make_tuple_indices<sizeof...(_Tp), sizeof...(_Up)>::type(),
typename __make_tuple_types<tuple, sizeof...(_Tp), sizeof...(_Up)>::type(),
_VSTD::forward<_Up>(__u)...) {}
template <class ..._Up,
typename enable_if
<
_CheckArgsConstructor<
sizeof...(_Up) <= sizeof...(_Tp)
&& !_PackExpandsToThisTuple<_Up...>::value
>::template __enable_explicit<_Up...>() ||
_CheckArgsConstructor<
!_EnableImplicitReducedArityExtension
&& sizeof...(_Up) < sizeof...(_Tp)
&& !_PackExpandsToThisTuple<_Up...>::value
>::template __enable_implicit<_Up...>(),
bool
>::type = false
>
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
explicit
tuple(_Up&&... __u)
_NOEXCEPT_((
is_nothrow_constructible<_BaseT,
typename __make_tuple_indices<sizeof...(_Up)>::type,
typename __make_tuple_types<tuple, sizeof...(_Up)>::type,
typename __make_tuple_indices<sizeof...(_Tp), sizeof...(_Up)>::type,
typename __make_tuple_types<tuple, sizeof...(_Tp), sizeof...(_Up)>::type,
_Up...
>::value
))
: __base_(typename __make_tuple_indices<sizeof...(_Up)>::type(),
typename __make_tuple_types<tuple, sizeof...(_Up)>::type(),
typename __make_tuple_indices<sizeof...(_Tp), sizeof...(_Up)>::type(),
typename __make_tuple_types<tuple, sizeof...(_Tp), sizeof...(_Up)>::type(),
_VSTD::forward<_Up>(__u)...) {}
template <class _Alloc, class ..._Up,
typename enable_if
<
_CheckArgsConstructor<
sizeof...(_Up) == sizeof...(_Tp) &&
!_PackExpandsToThisTuple<_Up...>::value
>::template __enable_implicit<_Up...>(),
bool
>::type = false
>
_LIBCPP_INLINE_VISIBILITY
tuple(allocator_arg_t, const _Alloc& __a, _Up&&... __u)
: __base_(allocator_arg_t(), __a,
typename __make_tuple_indices<sizeof...(_Up)>::type(),
typename __make_tuple_types<tuple, sizeof...(_Up)>::type(),
typename __make_tuple_indices<sizeof...(_Tp), sizeof...(_Up)>::type(),
typename __make_tuple_types<tuple, sizeof...(_Tp), sizeof...(_Up)>::type(),
_VSTD::forward<_Up>(__u)...) {}
template <class _Alloc, class ..._Up,
typename enable_if
<
_CheckArgsConstructor<
sizeof...(_Up) == sizeof...(_Tp) &&
!_PackExpandsToThisTuple<_Up...>::value
>::template __enable_explicit<_Up...>(),
bool
>::type = false
>
_LIBCPP_INLINE_VISIBILITY
explicit
tuple(allocator_arg_t, const _Alloc& __a, _Up&&... __u)
: __base_(allocator_arg_t(), __a,
typename __make_tuple_indices<sizeof...(_Up)>::type(),
typename __make_tuple_types<tuple, sizeof...(_Up)>::type(),
typename __make_tuple_indices<sizeof...(_Tp), sizeof...(_Up)>::type(),
typename __make_tuple_types<tuple, sizeof...(_Tp), sizeof...(_Up)>::type(),
_VSTD::forward<_Up>(__u)...) {}
template <class _Tuple, _EnableImplicitTupleLikeConstructor<_Tuple, true> = false>
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
tuple(_Tuple&& __t) _NOEXCEPT_((is_nothrow_constructible<_BaseT, _Tuple>::value))
: __base_(_VSTD::forward<_Tuple>(__t)) {}
template <class _Tuple, _EnableImplicitTupleLikeConstructor<const _Tuple&, false> = false>
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
tuple(const _Tuple& __t) _NOEXCEPT_((is_nothrow_constructible<_BaseT, const _Tuple&>::value))
: __base_(__t) {}
template <class _Tuple, _EnableExplicitTupleLikeConstructor<_Tuple, true> = false>
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
explicit
tuple(_Tuple&& __t) _NOEXCEPT_((is_nothrow_constructible<_BaseT, _Tuple>::value))
: __base_(_VSTD::forward<_Tuple>(__t)) {}
template <class _Tuple, _EnableExplicitTupleLikeConstructor<const _Tuple&, false> = false>
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
explicit
tuple(const _Tuple& __t) _NOEXCEPT_((is_nothrow_constructible<_BaseT, const _Tuple&>::value))
: __base_(__t) {}
template <class _Alloc, class _Tuple,
typename enable_if
<
_CheckTupleLikeConstructor<
__tuple_like_with_size<_Tuple, sizeof...(_Tp)>::value
>::template __enable_implicit<_Tuple>(),
bool
>::type = false
>
_LIBCPP_INLINE_VISIBILITY
tuple(allocator_arg_t, const _Alloc& __a, _Tuple&& __t)
: __base_(allocator_arg_t(), __a, _VSTD::forward<_Tuple>(__t)) {}
template <class _Alloc, class _Tuple,
typename enable_if
<
_CheckTupleLikeConstructor<
__tuple_like_with_size<_Tuple, sizeof...(_Tp)>::value
>::template __enable_explicit<_Tuple>(),
bool
>::type = false
>
_LIBCPP_INLINE_VISIBILITY
explicit
tuple(allocator_arg_t, const _Alloc& __a, _Tuple&& __t)
: __base_(allocator_arg_t(), __a, _VSTD::forward<_Tuple>(__t)) {}
using _CanCopyAssign = __all<is_copy_assignable<_Tp>::value...>;
using _CanMoveAssign = __all<is_move_assignable<_Tp>::value...>;
_LIBCPP_INLINE_VISIBILITY
tuple& operator=(typename conditional<_CanCopyAssign::value, tuple, __nat>::type const& __t)
_NOEXCEPT_((__all<is_nothrow_copy_assignable<_Tp>::value...>::value))
{
__base_.operator=(__t.__base_);
return *this;
}
_LIBCPP_INLINE_VISIBILITY
tuple& operator=(typename conditional<_CanMoveAssign::value, tuple, __nat>::type&& __t)
_NOEXCEPT_((__all<is_nothrow_move_assignable<_Tp>::value...>::value))
{
__base_.operator=(static_cast<_BaseT&&>(__t.__base_));
return *this;
}
template <class _Tuple,
class = typename enable_if
<
__tuple_assignable<_Tuple, tuple>::value
>::type
>
_LIBCPP_INLINE_VISIBILITY
tuple&
operator=(_Tuple&& __t) _NOEXCEPT_((is_nothrow_assignable<_BaseT&, _Tuple>::value))
{
__base_.operator=(_VSTD::forward<_Tuple>(__t));
return *this;
}
_LIBCPP_INLINE_VISIBILITY
void swap(tuple& __t) _NOEXCEPT_(__all<__is_nothrow_swappable<_Tp>::value...>::value)
{__base_.swap(__t.__base_);}
};
template <>
class _LIBCPP_TEMPLATE_VIS tuple<>
{
public:
_LIBCPP_INLINE_VISIBILITY
_LIBCPP_CONSTEXPR tuple() _NOEXCEPT = default;
template <class _Alloc>
_LIBCPP_INLINE_VISIBILITY
tuple(allocator_arg_t, const _Alloc&) _NOEXCEPT {}
template <class _Alloc>
_LIBCPP_INLINE_VISIBILITY
tuple(allocator_arg_t, const _Alloc&, const tuple&) _NOEXCEPT {}
template <class _Up>
_LIBCPP_INLINE_VISIBILITY
tuple(array<_Up, 0>) _NOEXCEPT {}
template <class _Alloc, class _Up>
_LIBCPP_INLINE_VISIBILITY
tuple(allocator_arg_t, const _Alloc&, array<_Up, 0>) _NOEXCEPT {}
_LIBCPP_INLINE_VISIBILITY
void swap(tuple&) _NOEXCEPT {}
};
#ifndef _LIBCPP_HAS_NO_DEDUCTION_GUIDES
template <class ..._Tp>
tuple(_Tp...) -> tuple<_Tp...>;
template <class _Tp1, class _Tp2>
tuple(pair<_Tp1, _Tp2>) -> tuple<_Tp1, _Tp2>;
template <class _Alloc, class ..._Tp>
tuple(allocator_arg_t, _Alloc, _Tp...) -> tuple<_Tp...>;
template <class _Alloc, class _Tp1, class _Tp2>
tuple(allocator_arg_t, _Alloc, pair<_Tp1, _Tp2>) -> tuple<_Tp1, _Tp2>;
template <class _Alloc, class ..._Tp>
tuple(allocator_arg_t, _Alloc, tuple<_Tp...>) -> tuple<_Tp...>;
#endif
template <class ..._Tp>
inline _LIBCPP_INLINE_VISIBILITY
typename enable_if
<
__all<__is_swappable<_Tp>::value...>::value,
void
>::type
swap(tuple<_Tp...>& __t, tuple<_Tp...>& __u)
_NOEXCEPT_(__all<__is_nothrow_swappable<_Tp>::value...>::value)
{__t.swap(__u);}
// get
template <size_t _Ip, class ..._Tp>
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
typename tuple_element<_Ip, tuple<_Tp...> >::type&
get(tuple<_Tp...>& __t) _NOEXCEPT
{
typedef _LIBCPP_NODEBUG_TYPE typename tuple_element<_Ip, tuple<_Tp...> >::type type;
return static_cast<__tuple_leaf<_Ip, type>&>(__t.__base_).get();
}
template <size_t _Ip, class ..._Tp>
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
const typename tuple_element<_Ip, tuple<_Tp...> >::type&
get(const tuple<_Tp...>& __t) _NOEXCEPT
{
typedef _LIBCPP_NODEBUG_TYPE typename tuple_element<_Ip, tuple<_Tp...> >::type type;
return static_cast<const __tuple_leaf<_Ip, type>&>(__t.__base_).get();
}
template <size_t _Ip, class ..._Tp>
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
typename tuple_element<_Ip, tuple<_Tp...> >::type&&
get(tuple<_Tp...>&& __t) _NOEXCEPT
{
typedef _LIBCPP_NODEBUG_TYPE typename tuple_element<_Ip, tuple<_Tp...> >::type type;
return static_cast<type&&>(
static_cast<__tuple_leaf<_Ip, type>&&>(__t.__base_).get());
}
template <size_t _Ip, class ..._Tp>
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
const typename tuple_element<_Ip, tuple<_Tp...> >::type&&
get(const tuple<_Tp...>&& __t) _NOEXCEPT
{
typedef _LIBCPP_NODEBUG_TYPE typename tuple_element<_Ip, tuple<_Tp...> >::type type;
return static_cast<const type&&>(
static_cast<const __tuple_leaf<_Ip, type>&&>(__t.__base_).get());
}
#if _LIBCPP_STD_VER > 11
namespace __find_detail {
static constexpr size_t __not_found = -1;
static constexpr size_t __ambiguous = __not_found - 1;
inline _LIBCPP_INLINE_VISIBILITY
constexpr size_t __find_idx_return(size_t __curr_i, size_t __res, bool __matches) {
return !__matches ? __res :
(__res == __not_found ? __curr_i : __ambiguous);
}
template <size_t _Nx>
inline _LIBCPP_INLINE_VISIBILITY
constexpr size_t __find_idx(size_t __i, const bool (&__matches)[_Nx]) {
return __i == _Nx ? __not_found :
__find_idx_return(__i, __find_idx(__i + 1, __matches), __matches[__i]);
}
template <class _T1, class ..._Args>
struct __find_exactly_one_checked {
static constexpr bool __matches[sizeof...(_Args)] = {is_same<_T1, _Args>::value...};
static constexpr size_t value = __find_detail::__find_idx(0, __matches);
static_assert(value != __not_found, "type not found in type list" );
static_assert(value != __ambiguous, "type occurs more than once in type list");
};
template <class _T1>
struct __find_exactly_one_checked<_T1> {
static_assert(!is_same<_T1, _T1>::value, "type not in empty type list");
};
} // namespace __find_detail;
template <typename _T1, typename... _Args>
struct __find_exactly_one_t
: public __find_detail::__find_exactly_one_checked<_T1, _Args...> {
};
template <class _T1, class... _Args>
inline _LIBCPP_INLINE_VISIBILITY
constexpr _T1& get(tuple<_Args...>& __tup) noexcept
{
return _VSTD::get<__find_exactly_one_t<_T1, _Args...>::value>(__tup);
}
template <class _T1, class... _Args>
inline _LIBCPP_INLINE_VISIBILITY
constexpr _T1 const& get(tuple<_Args...> const& __tup) noexcept
{
return _VSTD::get<__find_exactly_one_t<_T1, _Args...>::value>(__tup);
}
template <class _T1, class... _Args>
inline _LIBCPP_INLINE_VISIBILITY
constexpr _T1&& get(tuple<_Args...>&& __tup) noexcept
{
return _VSTD::get<__find_exactly_one_t<_T1, _Args...>::value>(_VSTD::move(__tup));
}
template <class _T1, class... _Args>
inline _LIBCPP_INLINE_VISIBILITY
constexpr _T1 const&& get(tuple<_Args...> const&& __tup) noexcept
{
return _VSTD::get<__find_exactly_one_t<_T1, _Args...>::value>(_VSTD::move(__tup));
}
#endif
// tie
template <class ..._Tp>
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
tuple<_Tp&...>
tie(_Tp&... __t) _NOEXCEPT
{
return tuple<_Tp&...>(__t...);
}
template <class _Up>
struct __ignore_t
{
template <class _Tp>
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
const __ignore_t& operator=(_Tp&&) const {return *this;}
};
namespace {
_LIBCPP_INLINE_VAR constexpr __ignore_t<unsigned char> ignore = __ignore_t<unsigned char>();
}
template <class... _Tp>
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
tuple<typename __unwrap_ref_decay<_Tp>::type...>
make_tuple(_Tp&&... __t)
{
return tuple<typename __unwrap_ref_decay<_Tp>::type...>(_VSTD::forward<_Tp>(__t)...);
}
template <class... _Tp>
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
tuple<_Tp&&...>
forward_as_tuple(_Tp&&... __t) _NOEXCEPT
{
return tuple<_Tp&&...>(_VSTD::forward<_Tp>(__t)...);
}
template <size_t _Ip>
struct __tuple_equal
{
template <class _Tp, class _Up>
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
bool operator()(const _Tp& __x, const _Up& __y)
{
return __tuple_equal<_Ip - 1>()(__x, __y) && _VSTD::get<_Ip-1>(__x) == _VSTD::get<_Ip-1>(__y);
}
};
template <>
struct __tuple_equal<0>
{
template <class _Tp, class _Up>
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
bool operator()(const _Tp&, const _Up&)
{
return true;
}
};
template <class ..._Tp, class ..._Up>
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
bool
operator==(const tuple<_Tp...>& __x, const tuple<_Up...>& __y)
{
static_assert (sizeof...(_Tp) == sizeof...(_Up), "Can't compare tuples of different sizes");
return __tuple_equal<sizeof...(_Tp)>()(__x, __y);
}
template <class ..._Tp, class ..._Up>
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
bool
operator!=(const tuple<_Tp...>& __x, const tuple<_Up...>& __y)
{
return !(__x == __y);
}
template <size_t _Ip>
struct __tuple_less
{
template <class _Tp, class _Up>
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
bool operator()(const _Tp& __x, const _Up& __y)
{
const size_t __idx = tuple_size<_Tp>::value - _Ip;
if (_VSTD::get<__idx>(__x) < _VSTD::get<__idx>(__y))
return true;
if (_VSTD::get<__idx>(__y) < _VSTD::get<__idx>(__x))
return false;
return __tuple_less<_Ip-1>()(__x, __y);
}
};
template <>
struct __tuple_less<0>
{
template <class _Tp, class _Up>
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
bool operator()(const _Tp&, const _Up&)
{
return false;
}
};
template <class ..._Tp, class ..._Up>
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
bool
operator<(const tuple<_Tp...>& __x, const tuple<_Up...>& __y)
{
static_assert (sizeof...(_Tp) == sizeof...(_Up), "Can't compare tuples of different sizes");
return __tuple_less<sizeof...(_Tp)>()(__x, __y);
}
template <class ..._Tp, class ..._Up>
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
bool
operator>(const tuple<_Tp...>& __x, const tuple<_Up...>& __y)
{
return __y < __x;
}
template <class ..._Tp, class ..._Up>
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
bool
operator>=(const tuple<_Tp...>& __x, const tuple<_Up...>& __y)
{
return !(__x < __y);
}
template <class ..._Tp, class ..._Up>
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
bool
operator<=(const tuple<_Tp...>& __x, const tuple<_Up...>& __y)
{
return !(__y < __x);
}
// tuple_cat
template <class _Tp, class _Up> struct __tuple_cat_type;
template <class ..._Ttypes, class ..._Utypes>
struct __tuple_cat_type<tuple<_Ttypes...>, __tuple_types<_Utypes...> >
{
typedef _LIBCPP_NODEBUG_TYPE tuple<_Ttypes..., _Utypes...> type;
};
template <class _ResultTuple, bool _Is_Tuple0TupleLike, class ..._Tuples>
struct __tuple_cat_return_1
{
};
template <class ..._Types, class _Tuple0>
struct __tuple_cat_return_1<tuple<_Types...>, true, _Tuple0>
{
typedef _LIBCPP_NODEBUG_TYPE typename __tuple_cat_type<tuple<_Types...>,
typename __make_tuple_types<typename __uncvref<_Tuple0>::type>::type>::type
type;
};
template <class ..._Types, class _Tuple0, class _Tuple1, class ..._Tuples>
struct __tuple_cat_return_1<tuple<_Types...>, true, _Tuple0, _Tuple1, _Tuples...>
: public __tuple_cat_return_1<
typename __tuple_cat_type<
tuple<_Types...>,
typename __make_tuple_types<typename __uncvref<_Tuple0>::type>::type
>::type,
__tuple_like<typename remove_reference<_Tuple1>::type>::value,
_Tuple1, _Tuples...>
{
};
template <class ..._Tuples> struct __tuple_cat_return;
template <class _Tuple0, class ..._Tuples>
struct __tuple_cat_return<_Tuple0, _Tuples...>
: public __tuple_cat_return_1<tuple<>,
__tuple_like<typename remove_reference<_Tuple0>::type>::value, _Tuple0,
_Tuples...>
{
};
template <>
struct __tuple_cat_return<>
{
typedef _LIBCPP_NODEBUG_TYPE tuple<> type;
};
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
tuple<>
tuple_cat()
{
return tuple<>();
}
template <class _Rp, class _Indices, class _Tuple0, class ..._Tuples>
struct __tuple_cat_return_ref_imp;
template <class ..._Types, size_t ..._I0, class _Tuple0>
struct __tuple_cat_return_ref_imp<tuple<_Types...>, __tuple_indices<_I0...>, _Tuple0>
{
typedef _LIBCPP_NODEBUG_TYPE typename remove_reference<_Tuple0>::type _T0;
typedef tuple<_Types..., typename __apply_cv<_Tuple0,
typename tuple_element<_I0, _T0>::type>::type&&...> type;
};
template <class ..._Types, size_t ..._I0, class _Tuple0, class _Tuple1, class ..._Tuples>
struct __tuple_cat_return_ref_imp<tuple<_Types...>, __tuple_indices<_I0...>,
_Tuple0, _Tuple1, _Tuples...>
: public __tuple_cat_return_ref_imp<
tuple<_Types..., typename __apply_cv<_Tuple0,
typename tuple_element<_I0,
typename remove_reference<_Tuple0>::type>::type>::type&&...>,
typename __make_tuple_indices<tuple_size<typename
remove_reference<_Tuple1>::type>::value>::type,
_Tuple1, _Tuples...>
{
};
template <class _Tuple0, class ..._Tuples>
struct __tuple_cat_return_ref
: public __tuple_cat_return_ref_imp<tuple<>,
typename __make_tuple_indices<
tuple_size<typename remove_reference<_Tuple0>::type>::value
>::type, _Tuple0, _Tuples...>
{
};
template <class _Types, class _I0, class _J0>
struct __tuple_cat;
template <class ..._Types, size_t ..._I0, size_t ..._J0>
struct __tuple_cat<tuple<_Types...>, __tuple_indices<_I0...>, __tuple_indices<_J0...> >
{
template <class _Tuple0>
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
typename __tuple_cat_return_ref<tuple<_Types...>&&, _Tuple0&&>::type
operator()(tuple<_Types...> __t, _Tuple0&& __t0)
{
return forward_as_tuple(_VSTD::forward<_Types>(_VSTD::get<_I0>(__t))...,
_VSTD::get<_J0>(_VSTD::forward<_Tuple0>(__t0))...);
}
template <class _Tuple0, class _Tuple1, class ..._Tuples>
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
typename __tuple_cat_return_ref<tuple<_Types...>&&, _Tuple0&&, _Tuple1&&, _Tuples&&...>::type
operator()(tuple<_Types...> __t, _Tuple0&& __t0, _Tuple1&& __t1, _Tuples&& ...__tpls)
{
typedef _LIBCPP_NODEBUG_TYPE typename remove_reference<_Tuple0>::type _T0;
typedef _LIBCPP_NODEBUG_TYPE typename remove_reference<_Tuple1>::type _T1;
return __tuple_cat<
tuple<_Types..., typename __apply_cv<_Tuple0, typename tuple_element<_J0, _T0>::type>::type&&...>,
typename __make_tuple_indices<sizeof ...(_Types) + tuple_size<_T0>::value>::type,
typename __make_tuple_indices<tuple_size<_T1>::value>::type>()
(forward_as_tuple(
_VSTD::forward<_Types>(_VSTD::get<_I0>(__t))...,
_VSTD::get<_J0>(_VSTD::forward<_Tuple0>(__t0))...
),
_VSTD::forward<_Tuple1>(__t1),
_VSTD::forward<_Tuples>(__tpls)...);
}
};
template <class _Tuple0, class... _Tuples>
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
typename __tuple_cat_return<_Tuple0, _Tuples...>::type
tuple_cat(_Tuple0&& __t0, _Tuples&&... __tpls)
{
typedef _LIBCPP_NODEBUG_TYPE typename remove_reference<_Tuple0>::type _T0;
return __tuple_cat<tuple<>, __tuple_indices<>,
typename __make_tuple_indices<tuple_size<_T0>::value>::type>()
(tuple<>(), _VSTD::forward<_Tuple0>(__t0),
_VSTD::forward<_Tuples>(__tpls)...);
}
template <class ..._Tp, class _Alloc>
struct _LIBCPP_TEMPLATE_VIS uses_allocator<tuple<_Tp...>, _Alloc>
: true_type {};
template <class _T1, class _T2>
template <class... _Args1, class... _Args2, size_t ..._I1, size_t ..._I2>
inline _LIBCPP_INLINE_VISIBILITY
pair<_T1, _T2>::pair(piecewise_construct_t,
tuple<_Args1...>& __first_args, tuple<_Args2...>& __second_args,
__tuple_indices<_I1...>, __tuple_indices<_I2...>)
: first(_VSTD::forward<_Args1>(_VSTD::get<_I1>( __first_args))...),
second(_VSTD::forward<_Args2>(_VSTD::get<_I2>(__second_args))...)
{
}
#if _LIBCPP_STD_VER > 14
template <class _Tp>
_LIBCPP_INLINE_VAR constexpr size_t tuple_size_v = tuple_size<_Tp>::value;
#define _LIBCPP_NOEXCEPT_RETURN(...) noexcept(noexcept(__VA_ARGS__)) { return __VA_ARGS__; }
template <class _Fn, class _Tuple, size_t ..._Id>
inline _LIBCPP_INLINE_VISIBILITY
constexpr decltype(auto) __apply_tuple_impl(_Fn && __f, _Tuple && __t,
__tuple_indices<_Id...>)
_LIBCPP_NOEXCEPT_RETURN(
_VSTD::__invoke_constexpr(
_VSTD::forward<_Fn>(__f),
_VSTD::get<_Id>(_VSTD::forward<_Tuple>(__t))...)
)
template <class _Fn, class _Tuple>
inline _LIBCPP_INLINE_VISIBILITY
constexpr decltype(auto) apply(_Fn && __f, _Tuple && __t)
_LIBCPP_NOEXCEPT_RETURN(
_VSTD::__apply_tuple_impl(
_VSTD::forward<_Fn>(__f), _VSTD::forward<_Tuple>(__t),
typename __make_tuple_indices<tuple_size_v<remove_reference_t<_Tuple>>>::type{})
)
template <class _Tp, class _Tuple, size_t... _Idx>
inline _LIBCPP_INLINE_VISIBILITY
constexpr _Tp __make_from_tuple_impl(_Tuple&& __t, __tuple_indices<_Idx...>)
_LIBCPP_NOEXCEPT_RETURN(
_Tp(_VSTD::get<_Idx>(_VSTD::forward<_Tuple>(__t))...)
)
template <class _Tp, class _Tuple>
inline _LIBCPP_INLINE_VISIBILITY
constexpr _Tp make_from_tuple(_Tuple&& __t)
_LIBCPP_NOEXCEPT_RETURN(
_VSTD::__make_from_tuple_impl<_Tp>(_VSTD::forward<_Tuple>(__t),
typename __make_tuple_indices<tuple_size_v<remove_reference_t<_Tuple>>>::type{})
)
#undef _LIBCPP_NOEXCEPT_RETURN
#endif // _LIBCPP_STD_VER > 14
#endif // !defined(_LIBCPP_CXX03_LANG)
_LIBCPP_END_NAMESPACE_STD
#endif // _LIBCPP_TUPLE
| 56,705 | 1,452 | jart/cosmopolitan | false |
cosmopolitan/third_party/libcxx/memory | // -*- C++ -*-
//===-------------------------- memory ------------------------------------===//
//
// 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_MEMORY
#define _LIBCPP_MEMORY
#include "third_party/libcxx/__config"
#include "third_party/libcxx/type_traits"
#include "third_party/libcxx/typeinfo"
#include "third_party/libcxx/cstddef"
#include "third_party/libcxx/cstdint"
#include "third_party/libcxx/new"
#include "third_party/libcxx/utility"
#include "third_party/libcxx/limits"
#include "third_party/libcxx/iterator"
#include "third_party/libcxx/__functional_base"
#include "third_party/libcxx/iosfwd"
#include "third_party/libcxx/tuple"
#include "third_party/libcxx/stdexcept"
#include "third_party/libcxx/cstring"
#if !defined(_LIBCPP_HAS_NO_ATOMIC_HEADER)
#include "third_party/libcxx/atomic"
#endif
#include "third_party/libcxx/version"
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
#pragma GCC system_header
#endif
_LIBCPP_PUSH_MACROS
#include "third_party/libcxx/__undef_macros"
_LIBCPP_BEGIN_NAMESPACE_STD
/*
memory synopsis
namespace std
{
struct allocator_arg_t { };
inline constexpr allocator_arg_t allocator_arg = allocator_arg_t();
template <class T, class Alloc> struct uses_allocator;
template <class Ptr>
struct pointer_traits
{
typedef Ptr pointer;
typedef <details> element_type;
typedef <details> difference_type;
template <class U> using rebind = <details>;
static pointer pointer_to(<details>);
};
template <class T>
struct pointer_traits<T*>
{
typedef T* pointer;
typedef T element_type;
typedef ptrdiff_t difference_type;
template <class U> using rebind = U*;
static pointer pointer_to(<details>) noexcept; // constexpr in C++20
};
template <class T> constexpr T* to_address(T* p) noexcept; // C++20
template <class Ptr> auto to_address(const Ptr& p) noexcept; // C++20
template <class Alloc>
struct allocator_traits
{
typedef Alloc allocator_type;
typedef typename allocator_type::value_type
value_type;
typedef Alloc::pointer | value_type* pointer;
typedef Alloc::const_pointer
| pointer_traits<pointer>::rebind<const value_type>
const_pointer;
typedef Alloc::void_pointer
| pointer_traits<pointer>::rebind<void>
void_pointer;
typedef Alloc::const_void_pointer
| pointer_traits<pointer>::rebind<const void>
const_void_pointer;
typedef Alloc::difference_type
| pointer_traits<pointer>::difference_type
difference_type;
typedef Alloc::size_type
| make_unsigned<difference_type>::type
size_type;
typedef Alloc::propagate_on_container_copy_assignment
| false_type propagate_on_container_copy_assignment;
typedef Alloc::propagate_on_container_move_assignment
| false_type propagate_on_container_move_assignment;
typedef Alloc::propagate_on_container_swap
| false_type propagate_on_container_swap;
typedef Alloc::is_always_equal
| is_empty is_always_equal;
template <class T> using rebind_alloc = Alloc::rebind<U>::other | Alloc<T, Args...>;
template <class T> using rebind_traits = allocator_traits<rebind_alloc<T>>;
static pointer allocate(allocator_type& a, size_type n); // [[nodiscard]] in C++20
static pointer allocate(allocator_type& a, size_type n, const_void_pointer hint); // [[nodiscard]] in C++20
static void deallocate(allocator_type& a, pointer p, size_type n) noexcept;
template <class T, class... Args>
static void construct(allocator_type& a, T* p, Args&&... args);
template <class T>
static void destroy(allocator_type& a, T* p);
static size_type max_size(const allocator_type& a); // noexcept in C++14
static allocator_type
select_on_container_copy_construction(const allocator_type& a);
};
template <>
class allocator<void>
{
public:
typedef void* pointer;
typedef const void* const_pointer;
typedef void value_type;
template <class _Up> struct rebind {typedef allocator<_Up> other;};
};
template <class T>
class allocator
{
public:
typedef size_t size_type;
typedef ptrdiff_t difference_type;
typedef T* pointer;
typedef const T* const_pointer;
typedef typename add_lvalue_reference<T>::type reference;
typedef typename add_lvalue_reference<const T>::type const_reference;
typedef T value_type;
template <class U> struct rebind {typedef allocator<U> other;};
constexpr allocator() noexcept; // constexpr in C++20
constexpr allocator(const allocator&) noexcept; // constexpr in C++20
template <class U>
constexpr allocator(const allocator<U>&) noexcept; // constexpr in C++20
~allocator();
pointer address(reference x) const noexcept;
const_pointer address(const_reference x) const noexcept;
pointer allocate(size_type, allocator<void>::const_pointer hint = 0);
void deallocate(pointer p, size_type n) noexcept;
size_type max_size() const noexcept;
template<class U, class... Args>
void construct(U* p, Args&&... args);
template <class U>
void destroy(U* p);
};
template <class T, class U>
bool operator==(const allocator<T>&, const allocator<U>&) noexcept;
template <class T, class U>
bool operator!=(const allocator<T>&, const allocator<U>&) noexcept;
template <class OutputIterator, class T>
class raw_storage_iterator
: public iterator<output_iterator_tag,
T, // purposefully not C++03
ptrdiff_t, // purposefully not C++03
T*, // purposefully not C++03
raw_storage_iterator&> // purposefully not C++03
{
public:
explicit raw_storage_iterator(OutputIterator x);
raw_storage_iterator& operator*();
raw_storage_iterator& operator=(const T& element);
raw_storage_iterator& operator++();
raw_storage_iterator operator++(int);
};
template <class T> pair<T*,ptrdiff_t> get_temporary_buffer(ptrdiff_t n) noexcept;
template <class T> void return_temporary_buffer(T* p) noexcept;
template <class T> T* addressof(T& r) noexcept;
template <class T> T* addressof(const T&& r) noexcept = delete;
template <class InputIterator, class ForwardIterator>
ForwardIterator
uninitialized_copy(InputIterator first, InputIterator last, ForwardIterator result);
template <class InputIterator, class Size, class ForwardIterator>
ForwardIterator
uninitialized_copy_n(InputIterator first, Size n, ForwardIterator result);
template <class ForwardIterator, class T>
void uninitialized_fill(ForwardIterator first, ForwardIterator last, const T& x);
template <class ForwardIterator, class Size, class T>
ForwardIterator
uninitialized_fill_n(ForwardIterator first, Size n, const T& x);
template <class T>
void destroy_at(T* location);
template <class ForwardIterator>
void destroy(ForwardIterator first, ForwardIterator last);
template <class ForwardIterator, class Size>
ForwardIterator destroy_n(ForwardIterator first, Size n);
template <class InputIterator, class ForwardIterator>
ForwardIterator uninitialized_move(InputIterator first, InputIterator last, ForwardIterator result);
template <class InputIterator, class Size, class ForwardIterator>
pair<InputIterator,ForwardIterator> uninitialized_move_n(InputIterator first, Size n, ForwardIterator result);
template <class ForwardIterator>
void uninitialized_value_construct(ForwardIterator first, ForwardIterator last);
template <class ForwardIterator, class Size>
ForwardIterator uninitialized_value_construct_n(ForwardIterator first, Size n);
template <class ForwardIterator>
void uninitialized_default_construct(ForwardIterator first, ForwardIterator last);
template <class ForwardIterator, class Size>
ForwardIterator uninitialized_default_construct_n(ForwardIterator first, Size n);
template <class Y> struct auto_ptr_ref {}; // deprecated in C++11, removed in C++17
template<class X>
class auto_ptr // deprecated in C++11, removed in C++17
{
public:
typedef X element_type;
explicit auto_ptr(X* p =0) throw();
auto_ptr(auto_ptr&) throw();
template<class Y> auto_ptr(auto_ptr<Y>&) throw();
auto_ptr& operator=(auto_ptr&) throw();
template<class Y> auto_ptr& operator=(auto_ptr<Y>&) throw();
auto_ptr& operator=(auto_ptr_ref<X> r) throw();
~auto_ptr() throw();
typename add_lvalue_reference<X>::type operator*() const throw();
X* operator->() const throw();
X* get() const throw();
X* release() throw();
void reset(X* p =0) throw();
auto_ptr(auto_ptr_ref<X>) throw();
template<class Y> operator auto_ptr_ref<Y>() throw();
template<class Y> operator auto_ptr<Y>() throw();
};
template <class T>
struct default_delete
{
constexpr default_delete() noexcept = default;
template <class U> default_delete(const default_delete<U>&) noexcept;
void operator()(T*) const noexcept;
};
template <class T>
struct default_delete<T[]>
{
constexpr default_delete() noexcept = default;
void operator()(T*) const noexcept;
template <class U> void operator()(U*) const = delete;
};
template <class T, class D = default_delete<T>>
class unique_ptr
{
public:
typedef see below pointer;
typedef T element_type;
typedef D deleter_type;
// constructors
constexpr unique_ptr() noexcept;
explicit unique_ptr(pointer p) noexcept;
unique_ptr(pointer p, see below d1) noexcept;
unique_ptr(pointer p, see below d2) noexcept;
unique_ptr(unique_ptr&& u) noexcept;
unique_ptr(nullptr_t) noexcept : unique_ptr() { }
template <class U, class E>
unique_ptr(unique_ptr<U, E>&& u) noexcept;
template <class U>
unique_ptr(auto_ptr<U>&& u) noexcept; // removed in C++17
// destructor
~unique_ptr();
// assignment
unique_ptr& operator=(unique_ptr&& u) noexcept;
template <class U, class E> unique_ptr& operator=(unique_ptr<U, E>&& u) noexcept;
unique_ptr& operator=(nullptr_t) noexcept;
// observers
typename add_lvalue_reference<T>::type operator*() const;
pointer operator->() const noexcept;
pointer get() const noexcept;
deleter_type& get_deleter() noexcept;
const deleter_type& get_deleter() const noexcept;
explicit operator bool() const noexcept;
// modifiers
pointer release() noexcept;
void reset(pointer p = pointer()) noexcept;
void swap(unique_ptr& u) noexcept;
};
template <class T, class D>
class unique_ptr<T[], D>
{
public:
typedef implementation-defined pointer;
typedef T element_type;
typedef D deleter_type;
// constructors
constexpr unique_ptr() noexcept;
explicit unique_ptr(pointer p) noexcept;
unique_ptr(pointer p, see below d) noexcept;
unique_ptr(pointer p, see below d) noexcept;
unique_ptr(unique_ptr&& u) noexcept;
unique_ptr(nullptr_t) noexcept : unique_ptr() { }
// destructor
~unique_ptr();
// assignment
unique_ptr& operator=(unique_ptr&& u) noexcept;
unique_ptr& operator=(nullptr_t) noexcept;
// observers
T& operator[](size_t i) const;
pointer get() const noexcept;
deleter_type& get_deleter() noexcept;
const deleter_type& get_deleter() const noexcept;
explicit operator bool() const noexcept;
// modifiers
pointer release() noexcept;
void reset(pointer p = pointer()) noexcept;
void reset(nullptr_t) noexcept;
template <class U> void reset(U) = delete;
void swap(unique_ptr& u) noexcept;
};
template <class T, class D>
void swap(unique_ptr<T, D>& x, unique_ptr<T, D>& y) noexcept;
template <class T1, class D1, class T2, class D2>
bool operator==(const unique_ptr<T1, D1>& x, const unique_ptr<T2, D2>& y);
template <class T1, class D1, class T2, class D2>
bool operator!=(const unique_ptr<T1, D1>& x, const unique_ptr<T2, D2>& y);
template <class T1, class D1, class T2, class D2>
bool operator<(const unique_ptr<T1, D1>& x, const unique_ptr<T2, D2>& y);
template <class T1, class D1, class T2, class D2>
bool operator<=(const unique_ptr<T1, D1>& x, const unique_ptr<T2, D2>& y);
template <class T1, class D1, class T2, class D2>
bool operator>(const unique_ptr<T1, D1>& x, const unique_ptr<T2, D2>& y);
template <class T1, class D1, class T2, class D2>
bool operator>=(const unique_ptr<T1, D1>& x, const unique_ptr<T2, D2>& y);
template <class T, class D>
bool operator==(const unique_ptr<T, D>& x, nullptr_t) noexcept;
template <class T, class D>
bool operator==(nullptr_t, const unique_ptr<T, D>& y) noexcept;
template <class T, class D>
bool operator!=(const unique_ptr<T, D>& x, nullptr_t) noexcept;
template <class T, class D>
bool operator!=(nullptr_t, const unique_ptr<T, D>& y) noexcept;
template <class T, class D>
bool operator<(const unique_ptr<T, D>& x, nullptr_t);
template <class T, class D>
bool operator<(nullptr_t, const unique_ptr<T, D>& y);
template <class T, class D>
bool operator<=(const unique_ptr<T, D>& x, nullptr_t);
template <class T, class D>
bool operator<=(nullptr_t, const unique_ptr<T, D>& y);
template <class T, class D>
bool operator>(const unique_ptr<T, D>& x, nullptr_t);
template <class T, class D>
bool operator>(nullptr_t, const unique_ptr<T, D>& y);
template <class T, class D>
bool operator>=(const unique_ptr<T, D>& x, nullptr_t);
template <class T, class D>
bool operator>=(nullptr_t, const unique_ptr<T, D>& y);
class bad_weak_ptr
: public std::exception
{
bad_weak_ptr() noexcept;
};
template<class T, class... Args> unique_ptr<T> make_unique(Args&&... args); // C++14
template<class T> unique_ptr<T> make_unique(size_t n); // C++14
template<class T, class... Args> unspecified make_unique(Args&&...) = delete; // C++14, T == U[N]
template<class E, class T, class Y, class D>
basic_ostream<E, T>& operator<< (basic_ostream<E, T>& os, unique_ptr<Y, D> const& p);
template<class T>
class shared_ptr
{
public:
typedef T element_type;
typedef weak_ptr<T> weak_type; // C++17
// constructors:
constexpr shared_ptr() noexcept;
template<class Y> explicit shared_ptr(Y* p);
template<class Y, class D> shared_ptr(Y* p, D d);
template<class Y, class D, class A> shared_ptr(Y* p, D d, A a);
template <class D> shared_ptr(nullptr_t p, D d);
template <class D, class A> shared_ptr(nullptr_t p, D d, A a);
template<class Y> shared_ptr(const shared_ptr<Y>& r, T *p) noexcept;
shared_ptr(const shared_ptr& r) noexcept;
template<class Y> shared_ptr(const shared_ptr<Y>& r) noexcept;
shared_ptr(shared_ptr&& r) noexcept;
template<class Y> shared_ptr(shared_ptr<Y>&& r) noexcept;
template<class Y> explicit shared_ptr(const weak_ptr<Y>& r);
template<class Y> shared_ptr(auto_ptr<Y>&& r); // removed in C++17
template <class Y, class D> shared_ptr(unique_ptr<Y, D>&& r);
shared_ptr(nullptr_t) : shared_ptr() { }
// destructor:
~shared_ptr();
// assignment:
shared_ptr& operator=(const shared_ptr& r) noexcept;
template<class Y> shared_ptr& operator=(const shared_ptr<Y>& r) noexcept;
shared_ptr& operator=(shared_ptr&& r) noexcept;
template<class Y> shared_ptr& operator=(shared_ptr<Y>&& r);
template<class Y> shared_ptr& operator=(auto_ptr<Y>&& r); // removed in C++17
template <class Y, class D> shared_ptr& operator=(unique_ptr<Y, D>&& r);
// modifiers:
void swap(shared_ptr& r) noexcept;
void reset() noexcept;
template<class Y> void reset(Y* p);
template<class Y, class D> void reset(Y* p, D d);
template<class Y, class D, class A> void reset(Y* p, D d, A a);
// observers:
T* get() const noexcept;
T& operator*() const noexcept;
T* operator->() const noexcept;
long use_count() const noexcept;
bool unique() const noexcept;
explicit operator bool() const noexcept;
template<class U> bool owner_before(shared_ptr<U> const& b) const noexcept;
template<class U> bool owner_before(weak_ptr<U> const& b) const noexcept;
};
// shared_ptr comparisons:
template<class T, class U>
bool operator==(shared_ptr<T> const& a, shared_ptr<U> const& b) noexcept;
template<class T, class U>
bool operator!=(shared_ptr<T> const& a, shared_ptr<U> const& b) noexcept;
template<class T, class U>
bool operator<(shared_ptr<T> const& a, shared_ptr<U> const& b) noexcept;
template<class T, class U>
bool operator>(shared_ptr<T> const& a, shared_ptr<U> const& b) noexcept;
template<class T, class U>
bool operator<=(shared_ptr<T> const& a, shared_ptr<U> const& b) noexcept;
template<class T, class U>
bool operator>=(shared_ptr<T> const& a, shared_ptr<U> const& b) noexcept;
template <class T>
bool operator==(const shared_ptr<T>& x, nullptr_t) noexcept;
template <class T>
bool operator==(nullptr_t, const shared_ptr<T>& y) noexcept;
template <class T>
bool operator!=(const shared_ptr<T>& x, nullptr_t) noexcept;
template <class T>
bool operator!=(nullptr_t, const shared_ptr<T>& y) noexcept;
template <class T>
bool operator<(const shared_ptr<T>& x, nullptr_t) noexcept;
template <class T>
bool operator<(nullptr_t, const shared_ptr<T>& y) noexcept;
template <class T>
bool operator<=(const shared_ptr<T>& x, nullptr_t) noexcept;
template <class T>
bool operator<=(nullptr_t, const shared_ptr<T>& y) noexcept;
template <class T>
bool operator>(const shared_ptr<T>& x, nullptr_t) noexcept;
template <class T>
bool operator>(nullptr_t, const shared_ptr<T>& y) noexcept;
template <class T>
bool operator>=(const shared_ptr<T>& x, nullptr_t) noexcept;
template <class T>
bool operator>=(nullptr_t, const shared_ptr<T>& y) noexcept;
// shared_ptr specialized algorithms:
template<class T> void swap(shared_ptr<T>& a, shared_ptr<T>& b) noexcept;
// shared_ptr casts:
template<class T, class U>
shared_ptr<T> static_pointer_cast(shared_ptr<U> const& r) noexcept;
template<class T, class U>
shared_ptr<T> dynamic_pointer_cast(shared_ptr<U> const& r) noexcept;
template<class T, class U>
shared_ptr<T> const_pointer_cast(shared_ptr<U> const& r) noexcept;
// shared_ptr I/O:
template<class E, class T, class Y>
basic_ostream<E, T>& operator<< (basic_ostream<E, T>& os, shared_ptr<Y> const& p);
// shared_ptr get_deleter:
template<class D, class T> D* get_deleter(shared_ptr<T> const& p) noexcept;
template<class T, class... Args>
shared_ptr<T> make_shared(Args&&... args);
template<class T, class A, class... Args>
shared_ptr<T> allocate_shared(const A& a, Args&&... args);
template<class T>
class weak_ptr
{
public:
typedef T element_type;
// constructors
constexpr weak_ptr() noexcept;
template<class Y> weak_ptr(shared_ptr<Y> const& r) noexcept;
weak_ptr(weak_ptr const& r) noexcept;
template<class Y> weak_ptr(weak_ptr<Y> const& r) noexcept;
weak_ptr(weak_ptr&& r) noexcept; // C++14
template<class Y> weak_ptr(weak_ptr<Y>&& r) noexcept; // C++14
// destructor
~weak_ptr();
// assignment
weak_ptr& operator=(weak_ptr const& r) noexcept;
template<class Y> weak_ptr& operator=(weak_ptr<Y> const& r) noexcept;
template<class Y> weak_ptr& operator=(shared_ptr<Y> const& r) noexcept;
weak_ptr& operator=(weak_ptr&& r) noexcept; // C++14
template<class Y> weak_ptr& operator=(weak_ptr<Y>&& r) noexcept; // C++14
// modifiers
void swap(weak_ptr& r) noexcept;
void reset() noexcept;
// observers
long use_count() const noexcept;
bool expired() const noexcept;
shared_ptr<T> lock() const noexcept;
template<class U> bool owner_before(shared_ptr<U> const& b) const noexcept;
template<class U> bool owner_before(weak_ptr<U> const& b) const noexcept;
};
// weak_ptr specialized algorithms:
template<class T> void swap(weak_ptr<T>& a, weak_ptr<T>& b) noexcept;
// class owner_less:
template<class T> struct owner_less;
template<class T>
struct owner_less<shared_ptr<T> >
: binary_function<shared_ptr<T>, shared_ptr<T>, bool>
{
typedef bool result_type;
bool operator()(shared_ptr<T> const&, shared_ptr<T> const&) const noexcept;
bool operator()(shared_ptr<T> const&, weak_ptr<T> const&) const noexcept;
bool operator()(weak_ptr<T> const&, shared_ptr<T> const&) const noexcept;
};
template<class T>
struct owner_less<weak_ptr<T> >
: binary_function<weak_ptr<T>, weak_ptr<T>, bool>
{
typedef bool result_type;
bool operator()(weak_ptr<T> const&, weak_ptr<T> const&) const noexcept;
bool operator()(shared_ptr<T> const&, weak_ptr<T> const&) const noexcept;
bool operator()(weak_ptr<T> const&, shared_ptr<T> const&) const noexcept;
};
template <> // Added in C++14
struct owner_less<void>
{
template <class _Tp, class _Up>
bool operator()( shared_ptr<_Tp> const& __x, shared_ptr<_Up> const& __y) const noexcept;
template <class _Tp, class _Up>
bool operator()( shared_ptr<_Tp> const& __x, weak_ptr<_Up> const& __y) const noexcept;
template <class _Tp, class _Up>
bool operator()( weak_ptr<_Tp> const& __x, shared_ptr<_Up> const& __y) const noexcept;
template <class _Tp, class _Up>
bool operator()( weak_ptr<_Tp> const& __x, weak_ptr<_Up> const& __y) const noexcept;
typedef void is_transparent;
};
template<class T>
class enable_shared_from_this
{
protected:
constexpr enable_shared_from_this() noexcept;
enable_shared_from_this(enable_shared_from_this const&) noexcept;
enable_shared_from_this& operator=(enable_shared_from_this const&) noexcept;
~enable_shared_from_this();
public:
shared_ptr<T> shared_from_this();
shared_ptr<T const> shared_from_this() const;
};
template<class T>
bool atomic_is_lock_free(const shared_ptr<T>* p);
template<class T>
shared_ptr<T> atomic_load(const shared_ptr<T>* p);
template<class T>
shared_ptr<T> atomic_load_explicit(const shared_ptr<T>* p, memory_order mo);
template<class T>
void atomic_store(shared_ptr<T>* p, shared_ptr<T> r);
template<class T>
void atomic_store_explicit(shared_ptr<T>* p, shared_ptr<T> r, memory_order mo);
template<class T>
shared_ptr<T> atomic_exchange(shared_ptr<T>* p, shared_ptr<T> r);
template<class T>
shared_ptr<T>
atomic_exchange_explicit(shared_ptr<T>* p, shared_ptr<T> r, memory_order mo);
template<class T>
bool
atomic_compare_exchange_weak(shared_ptr<T>* p, shared_ptr<T>* v, shared_ptr<T> w);
template<class T>
bool
atomic_compare_exchange_strong( shared_ptr<T>* p, shared_ptr<T>* v, shared_ptr<T> w);
template<class T>
bool
atomic_compare_exchange_weak_explicit(shared_ptr<T>* p, shared_ptr<T>* v,
shared_ptr<T> w, memory_order success,
memory_order failure);
template<class T>
bool
atomic_compare_exchange_strong_explicit(shared_ptr<T>* p, shared_ptr<T>* v,
shared_ptr<T> w, memory_order success,
memory_order failure);
// Hash support
template <class T> struct hash;
template <class T, class D> struct hash<unique_ptr<T, D> >;
template <class T> struct hash<shared_ptr<T> >;
template <class T, class Alloc>
inline constexpr bool uses_allocator_v = uses_allocator<T, Alloc>::value;
// Pointer safety
enum class pointer_safety { relaxed, preferred, strict };
void declare_reachable(void *p);
template <class T> T *undeclare_reachable(T *p);
void declare_no_pointers(char *p, size_t n);
void undeclare_no_pointers(char *p, size_t n);
pointer_safety get_pointer_safety() noexcept;
void* align(size_t alignment, size_t size, void*& ptr, size_t& space);
} // std
*/
template <class _ValueType>
inline _LIBCPP_INLINE_VISIBILITY
_ValueType __libcpp_relaxed_load(_ValueType const* __value) {
#if !defined(_LIBCPP_HAS_NO_THREADS) && \
defined(__ATOMIC_RELAXED) && \
(__has_builtin(__atomic_load_n) || defined(_LIBCPP_COMPILER_GCC))
return __atomic_load_n(__value, __ATOMIC_RELAXED);
#else
return *__value;
#endif
}
template <class _ValueType>
inline _LIBCPP_INLINE_VISIBILITY
_ValueType __libcpp_acquire_load(_ValueType const* __value) {
#if !defined(_LIBCPP_HAS_NO_THREADS) && \
defined(__ATOMIC_ACQUIRE) && \
(__has_builtin(__atomic_load_n) || defined(_LIBCPP_COMPILER_GCC))
return __atomic_load_n(__value, __ATOMIC_ACQUIRE);
#else
return *__value;
#endif
}
// addressof moved to <type_traits>
template <class _Tp> class allocator;
template <>
class _LIBCPP_TEMPLATE_VIS allocator<void>
{
public:
typedef void* pointer;
typedef const void* const_pointer;
typedef void value_type;
template <class _Up> struct rebind {typedef allocator<_Up> other;};
};
template <>
class _LIBCPP_TEMPLATE_VIS allocator<const void>
{
public:
typedef const void* pointer;
typedef const void* const_pointer;
typedef const void value_type;
template <class _Up> struct rebind {typedef allocator<_Up> other;};
};
// pointer_traits
template <class _Tp, class = void>
struct __has_element_type : false_type {};
template <class _Tp>
struct __has_element_type<_Tp,
typename __void_t<typename _Tp::element_type>::type> : true_type {};
template <class _Ptr, bool = __has_element_type<_Ptr>::value>
struct __pointer_traits_element_type;
template <class _Ptr>
struct __pointer_traits_element_type<_Ptr, true>
{
typedef _LIBCPP_NODEBUG_TYPE typename _Ptr::element_type type;
};
#ifndef _LIBCPP_HAS_NO_VARIADICS
template <template <class, class...> class _Sp, class _Tp, class ..._Args>
struct __pointer_traits_element_type<_Sp<_Tp, _Args...>, true>
{
typedef _LIBCPP_NODEBUG_TYPE typename _Sp<_Tp, _Args...>::element_type type;
};
template <template <class, class...> class _Sp, class _Tp, class ..._Args>
struct __pointer_traits_element_type<_Sp<_Tp, _Args...>, false>
{
typedef _LIBCPP_NODEBUG_TYPE _Tp type;
};
#else // _LIBCPP_HAS_NO_VARIADICS
template <template <class> class _Sp, class _Tp>
struct __pointer_traits_element_type<_Sp<_Tp>, true>
{
typedef typename _Sp<_Tp>::element_type type;
};
template <template <class> class _Sp, class _Tp>
struct __pointer_traits_element_type<_Sp<_Tp>, false>
{
typedef _Tp type;
};
template <template <class, class> class _Sp, class _Tp, class _A0>
struct __pointer_traits_element_type<_Sp<_Tp, _A0>, true>
{
typedef typename _Sp<_Tp, _A0>::element_type type;
};
template <template <class, class> class _Sp, class _Tp, class _A0>
struct __pointer_traits_element_type<_Sp<_Tp, _A0>, false>
{
typedef _Tp type;
};
template <template <class, class, class> class _Sp, class _Tp, class _A0, class _A1>
struct __pointer_traits_element_type<_Sp<_Tp, _A0, _A1>, true>
{
typedef typename _Sp<_Tp, _A0, _A1>::element_type type;
};
template <template <class, class, class> class _Sp, class _Tp, class _A0, class _A1>
struct __pointer_traits_element_type<_Sp<_Tp, _A0, _A1>, false>
{
typedef _Tp type;
};
template <template <class, class, class, class> class _Sp, class _Tp, class _A0,
class _A1, class _A2>
struct __pointer_traits_element_type<_Sp<_Tp, _A0, _A1, _A2>, true>
{
typedef typename _Sp<_Tp, _A0, _A1, _A2>::element_type type;
};
template <template <class, class, class, class> class _Sp, class _Tp, class _A0,
class _A1, class _A2>
struct __pointer_traits_element_type<_Sp<_Tp, _A0, _A1, _A2>, false>
{
typedef _Tp type;
};
#endif // _LIBCPP_HAS_NO_VARIADICS
template <class _Tp, class = void>
struct __has_difference_type : false_type {};
template <class _Tp>
struct __has_difference_type<_Tp,
typename __void_t<typename _Tp::difference_type>::type> : true_type {};
template <class _Ptr, bool = __has_difference_type<_Ptr>::value>
struct __pointer_traits_difference_type
{
typedef _LIBCPP_NODEBUG_TYPE ptrdiff_t type;
};
template <class _Ptr>
struct __pointer_traits_difference_type<_Ptr, true>
{
typedef _LIBCPP_NODEBUG_TYPE typename _Ptr::difference_type type;
};
template <class _Tp, class _Up>
struct __has_rebind
{
private:
struct __two {char __lx; char __lxx;};
template <class _Xp> static __two __test(...);
template <class _Xp> static char __test(typename _Xp::template rebind<_Up>* = 0);
public:
static const bool value = sizeof(__test<_Tp>(0)) == 1;
};
template <class _Tp, class _Up, bool = __has_rebind<_Tp, _Up>::value>
struct __pointer_traits_rebind
{
#ifndef _LIBCPP_CXX03_LANG
typedef _LIBCPP_NODEBUG_TYPE typename _Tp::template rebind<_Up> type;
#else
typedef _LIBCPP_NODEBUG_TYPE typename _Tp::template rebind<_Up>::other type;
#endif
};
#ifndef _LIBCPP_HAS_NO_VARIADICS
template <template <class, class...> class _Sp, class _Tp, class ..._Args, class _Up>
struct __pointer_traits_rebind<_Sp<_Tp, _Args...>, _Up, true>
{
#ifndef _LIBCPP_CXX03_LANG
typedef _LIBCPP_NODEBUG_TYPE typename _Sp<_Tp, _Args...>::template rebind<_Up> type;
#else
typedef _LIBCPP_NODEBUG_TYPE typename _Sp<_Tp, _Args...>::template rebind<_Up>::other type;
#endif
};
template <template <class, class...> class _Sp, class _Tp, class ..._Args, class _Up>
struct __pointer_traits_rebind<_Sp<_Tp, _Args...>, _Up, false>
{
typedef _Sp<_Up, _Args...> type;
};
#else // _LIBCPP_HAS_NO_VARIADICS
template <template <class> class _Sp, class _Tp, class _Up>
struct __pointer_traits_rebind<_Sp<_Tp>, _Up, true>
{
#ifndef _LIBCPP_CXX03_LANG
typedef typename _Sp<_Tp>::template rebind<_Up> type;
#else
typedef typename _Sp<_Tp>::template rebind<_Up>::other type;
#endif
};
template <template <class> class _Sp, class _Tp, class _Up>
struct __pointer_traits_rebind<_Sp<_Tp>, _Up, false>
{
typedef _Sp<_Up> type;
};
template <template <class, class> class _Sp, class _Tp, class _A0, class _Up>
struct __pointer_traits_rebind<_Sp<_Tp, _A0>, _Up, true>
{
#ifndef _LIBCPP_CXX03_LANG
typedef typename _Sp<_Tp, _A0>::template rebind<_Up> type;
#else
typedef typename _Sp<_Tp, _A0>::template rebind<_Up>::other type;
#endif
};
template <template <class, class> class _Sp, class _Tp, class _A0, class _Up>
struct __pointer_traits_rebind<_Sp<_Tp, _A0>, _Up, false>
{
typedef _Sp<_Up, _A0> type;
};
template <template <class, class, class> class _Sp, class _Tp, class _A0,
class _A1, class _Up>
struct __pointer_traits_rebind<_Sp<_Tp, _A0, _A1>, _Up, true>
{
#ifndef _LIBCPP_CXX03_LANG
typedef typename _Sp<_Tp, _A0, _A1>::template rebind<_Up> type;
#else
typedef typename _Sp<_Tp, _A0, _A1>::template rebind<_Up>::other type;
#endif
};
template <template <class, class, class> class _Sp, class _Tp, class _A0,
class _A1, class _Up>
struct __pointer_traits_rebind<_Sp<_Tp, _A0, _A1>, _Up, false>
{
typedef _Sp<_Up, _A0, _A1> type;
};
template <template <class, class, class, class> class _Sp, class _Tp, class _A0,
class _A1, class _A2, class _Up>
struct __pointer_traits_rebind<_Sp<_Tp, _A0, _A1, _A2>, _Up, true>
{
#ifndef _LIBCPP_CXX03_LANG
typedef typename _Sp<_Tp, _A0, _A1, _A2>::template rebind<_Up> type;
#else
typedef typename _Sp<_Tp, _A0, _A1, _A2>::template rebind<_Up>::other type;
#endif
};
template <template <class, class, class, class> class _Sp, class _Tp, class _A0,
class _A1, class _A2, class _Up>
struct __pointer_traits_rebind<_Sp<_Tp, _A0, _A1, _A2>, _Up, false>
{
typedef _Sp<_Up, _A0, _A1, _A2> type;
};
#endif // _LIBCPP_HAS_NO_VARIADICS
template <class _Ptr>
struct _LIBCPP_TEMPLATE_VIS pointer_traits
{
typedef _Ptr pointer;
typedef typename __pointer_traits_element_type<pointer>::type element_type;
typedef typename __pointer_traits_difference_type<pointer>::type difference_type;
#ifndef _LIBCPP_CXX03_LANG
template <class _Up> using rebind = typename __pointer_traits_rebind<pointer, _Up>::type;
#else
template <class _Up> struct rebind
{typedef typename __pointer_traits_rebind<pointer, _Up>::type other;};
#endif // _LIBCPP_CXX03_LANG
private:
struct __nat {};
public:
_LIBCPP_INLINE_VISIBILITY
static pointer pointer_to(typename conditional<is_void<element_type>::value,
__nat, element_type>::type& __r)
{return pointer::pointer_to(__r);}
};
template <class _Tp>
struct _LIBCPP_TEMPLATE_VIS pointer_traits<_Tp*>
{
typedef _Tp* pointer;
typedef _Tp element_type;
typedef ptrdiff_t difference_type;
#ifndef _LIBCPP_CXX03_LANG
template <class _Up> using rebind = _Up*;
#else
template <class _Up> struct rebind {typedef _Up* other;};
#endif
private:
struct __nat {};
public:
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
static pointer pointer_to(typename conditional<is_void<element_type>::value,
__nat, element_type>::type& __r) _NOEXCEPT
{return _VSTD::addressof(__r);}
};
template <class _From, class _To>
struct __rebind_pointer {
#ifndef _LIBCPP_CXX03_LANG
typedef typename pointer_traits<_From>::template rebind<_To> type;
#else
typedef typename pointer_traits<_From>::template rebind<_To>::other type;
#endif
};
// allocator_traits
template <class _Tp, class = void>
struct __has_pointer_type : false_type {};
template <class _Tp>
struct __has_pointer_type<_Tp,
typename __void_t<typename _Tp::pointer>::type> : true_type {};
namespace __pointer_type_imp
{
template <class _Tp, class _Dp, bool = __has_pointer_type<_Dp>::value>
struct __pointer_type
{
typedef _LIBCPP_NODEBUG_TYPE typename _Dp::pointer type;
};
template <class _Tp, class _Dp>
struct __pointer_type<_Tp, _Dp, false>
{
typedef _LIBCPP_NODEBUG_TYPE _Tp* type;
};
} // __pointer_type_imp
template <class _Tp, class _Dp>
struct __pointer_type
{
typedef _LIBCPP_NODEBUG_TYPE typename __pointer_type_imp::__pointer_type<_Tp, typename remove_reference<_Dp>::type>::type type;
};
template <class _Tp, class = void>
struct __has_const_pointer : false_type {};
template <class _Tp>
struct __has_const_pointer<_Tp,
typename __void_t<typename _Tp::const_pointer>::type> : true_type {};
template <class _Tp, class _Ptr, class _Alloc, bool = __has_const_pointer<_Alloc>::value>
struct __const_pointer
{
typedef _LIBCPP_NODEBUG_TYPE typename _Alloc::const_pointer type;
};
template <class _Tp, class _Ptr, class _Alloc>
struct __const_pointer<_Tp, _Ptr, _Alloc, false>
{
#ifndef _LIBCPP_CXX03_LANG
typedef _LIBCPP_NODEBUG_TYPE typename pointer_traits<_Ptr>::template rebind<const _Tp> type;
#else
typedef typename pointer_traits<_Ptr>::template rebind<const _Tp>::other type;
#endif
};
template <class _Tp, class = void>
struct __has_void_pointer : false_type {};
template <class _Tp>
struct __has_void_pointer<_Tp,
typename __void_t<typename _Tp::void_pointer>::type> : true_type {};
template <class _Ptr, class _Alloc, bool = __has_void_pointer<_Alloc>::value>
struct __void_pointer
{
typedef _LIBCPP_NODEBUG_TYPE typename _Alloc::void_pointer type;
};
template <class _Ptr, class _Alloc>
struct __void_pointer<_Ptr, _Alloc, false>
{
#ifndef _LIBCPP_CXX03_LANG
typedef _LIBCPP_NODEBUG_TYPE typename pointer_traits<_Ptr>::template rebind<void> type;
#else
typedef _LIBCPP_NODEBUG_TYPE typename pointer_traits<_Ptr>::template rebind<void>::other type;
#endif
};
template <class _Tp, class = void>
struct __has_const_void_pointer : false_type {};
template <class _Tp>
struct __has_const_void_pointer<_Tp,
typename __void_t<typename _Tp::const_void_pointer>::type> : true_type {};
template <class _Ptr, class _Alloc, bool = __has_const_void_pointer<_Alloc>::value>
struct __const_void_pointer
{
typedef _LIBCPP_NODEBUG_TYPE typename _Alloc::const_void_pointer type;
};
template <class _Ptr, class _Alloc>
struct __const_void_pointer<_Ptr, _Alloc, false>
{
#ifndef _LIBCPP_CXX03_LANG
typedef _LIBCPP_NODEBUG_TYPE typename pointer_traits<_Ptr>::template rebind<const void> type;
#else
typedef _LIBCPP_NODEBUG_TYPE typename pointer_traits<_Ptr>::template rebind<const void>::other type;
#endif
};
template <class _Tp>
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
_Tp*
__to_raw_pointer(_Tp* __p) _NOEXCEPT
{
return __p;
}
#if _LIBCPP_STD_VER <= 17
template <class _Pointer>
inline _LIBCPP_INLINE_VISIBILITY
typename pointer_traits<_Pointer>::element_type*
__to_raw_pointer(_Pointer __p) _NOEXCEPT
{
return _VSTD::__to_raw_pointer(__p.operator->());
}
#else
template <class _Pointer>
inline _LIBCPP_INLINE_VISIBILITY
auto
__to_raw_pointer(const _Pointer& __p) _NOEXCEPT
-> decltype(pointer_traits<_Pointer>::to_address(__p))
{
return pointer_traits<_Pointer>::to_address(__p);
}
template <class _Pointer, class... _None>
inline _LIBCPP_INLINE_VISIBILITY
auto
__to_raw_pointer(const _Pointer& __p, _None...) _NOEXCEPT
{
return _VSTD::__to_raw_pointer(__p.operator->());
}
template <class _Tp>
inline _LIBCPP_INLINE_VISIBILITY constexpr
_Tp*
to_address(_Tp* __p) _NOEXCEPT
{
static_assert(!is_function_v<_Tp>, "_Tp is a function type");
return __p;
}
template <class _Pointer>
inline _LIBCPP_INLINE_VISIBILITY
auto
to_address(const _Pointer& __p) _NOEXCEPT
{
return _VSTD::__to_raw_pointer(__p);
}
#endif
template <class _Tp, class = void>
struct __has_size_type : false_type {};
template <class _Tp>
struct __has_size_type<_Tp,
typename __void_t<typename _Tp::size_type>::type> : true_type {};
template <class _Alloc, class _DiffType, bool = __has_size_type<_Alloc>::value>
struct __size_type
{
typedef _LIBCPP_NODEBUG_TYPE typename make_unsigned<_DiffType>::type type;
};
template <class _Alloc, class _DiffType>
struct __size_type<_Alloc, _DiffType, true>
{
typedef _LIBCPP_NODEBUG_TYPE typename _Alloc::size_type type;
};
template <class _Tp, class = void>
struct __has_propagate_on_container_copy_assignment : false_type {};
template <class _Tp>
struct __has_propagate_on_container_copy_assignment<_Tp,
typename __void_t<typename _Tp::propagate_on_container_copy_assignment>::type>
: true_type {};
template <class _Alloc, bool = __has_propagate_on_container_copy_assignment<_Alloc>::value>
struct __propagate_on_container_copy_assignment
{
typedef _LIBCPP_NODEBUG_TYPE false_type type;
};
template <class _Alloc>
struct __propagate_on_container_copy_assignment<_Alloc, true>
{
typedef _LIBCPP_NODEBUG_TYPE typename _Alloc::propagate_on_container_copy_assignment type;
};
template <class _Tp, class = void>
struct __has_propagate_on_container_move_assignment : false_type {};
template <class _Tp>
struct __has_propagate_on_container_move_assignment<_Tp,
typename __void_t<typename _Tp::propagate_on_container_move_assignment>::type>
: true_type {};
template <class _Alloc, bool = __has_propagate_on_container_move_assignment<_Alloc>::value>
struct __propagate_on_container_move_assignment
{
typedef false_type type;
};
template <class _Alloc>
struct __propagate_on_container_move_assignment<_Alloc, true>
{
typedef _LIBCPP_NODEBUG_TYPE typename _Alloc::propagate_on_container_move_assignment type;
};
template <class _Tp, class = void>
struct __has_propagate_on_container_swap : false_type {};
template <class _Tp>
struct __has_propagate_on_container_swap<_Tp,
typename __void_t<typename _Tp::propagate_on_container_swap>::type>
: true_type {};
template <class _Alloc, bool = __has_propagate_on_container_swap<_Alloc>::value>
struct __propagate_on_container_swap
{
typedef false_type type;
};
template <class _Alloc>
struct __propagate_on_container_swap<_Alloc, true>
{
typedef _LIBCPP_NODEBUG_TYPE typename _Alloc::propagate_on_container_swap type;
};
template <class _Tp, class = void>
struct __has_is_always_equal : false_type {};
template <class _Tp>
struct __has_is_always_equal<_Tp,
typename __void_t<typename _Tp::is_always_equal>::type>
: true_type {};
template <class _Alloc, bool = __has_is_always_equal<_Alloc>::value>
struct __is_always_equal
{
typedef _LIBCPP_NODEBUG_TYPE typename _VSTD::is_empty<_Alloc>::type type;
};
template <class _Alloc>
struct __is_always_equal<_Alloc, true>
{
typedef _LIBCPP_NODEBUG_TYPE typename _Alloc::is_always_equal type;
};
template <class _Tp, class _Up, bool = __has_rebind<_Tp, _Up>::value>
struct __has_rebind_other
{
private:
struct __two {char __lx; char __lxx;};
template <class _Xp> static __two __test(...);
template <class _Xp> static char __test(typename _Xp::template rebind<_Up>::other* = 0);
public:
static const bool value = sizeof(__test<_Tp>(0)) == 1;
};
template <class _Tp, class _Up>
struct __has_rebind_other<_Tp, _Up, false>
{
static const bool value = false;
};
template <class _Tp, class _Up, bool = __has_rebind_other<_Tp, _Up>::value>
struct __allocator_traits_rebind
{
typedef _LIBCPP_NODEBUG_TYPE typename _Tp::template rebind<_Up>::other type;
};
#ifndef _LIBCPP_HAS_NO_VARIADICS
template <template <class, class...> class _Alloc, class _Tp, class ..._Args, class _Up>
struct __allocator_traits_rebind<_Alloc<_Tp, _Args...>, _Up, true>
{
typedef _LIBCPP_NODEBUG_TYPE typename _Alloc<_Tp, _Args...>::template rebind<_Up>::other type;
};
template <template <class, class...> class _Alloc, class _Tp, class ..._Args, class _Up>
struct __allocator_traits_rebind<_Alloc<_Tp, _Args...>, _Up, false>
{
typedef _LIBCPP_NODEBUG_TYPE _Alloc<_Up, _Args...> type;
};
#else // _LIBCPP_HAS_NO_VARIADICS
template <template <class> class _Alloc, class _Tp, class _Up>
struct __allocator_traits_rebind<_Alloc<_Tp>, _Up, true>
{
typedef typename _Alloc<_Tp>::template rebind<_Up>::other type;
};
template <template <class> class _Alloc, class _Tp, class _Up>
struct __allocator_traits_rebind<_Alloc<_Tp>, _Up, false>
{
typedef _Alloc<_Up> type;
};
template <template <class, class> class _Alloc, class _Tp, class _A0, class _Up>
struct __allocator_traits_rebind<_Alloc<_Tp, _A0>, _Up, true>
{
typedef typename _Alloc<_Tp, _A0>::template rebind<_Up>::other type;
};
template <template <class, class> class _Alloc, class _Tp, class _A0, class _Up>
struct __allocator_traits_rebind<_Alloc<_Tp, _A0>, _Up, false>
{
typedef _Alloc<_Up, _A0> type;
};
template <template <class, class, class> class _Alloc, class _Tp, class _A0,
class _A1, class _Up>
struct __allocator_traits_rebind<_Alloc<_Tp, _A0, _A1>, _Up, true>
{
typedef typename _Alloc<_Tp, _A0, _A1>::template rebind<_Up>::other type;
};
template <template <class, class, class> class _Alloc, class _Tp, class _A0,
class _A1, class _Up>
struct __allocator_traits_rebind<_Alloc<_Tp, _A0, _A1>, _Up, false>
{
typedef _Alloc<_Up, _A0, _A1> type;
};
template <template <class, class, class, class> class _Alloc, class _Tp, class _A0,
class _A1, class _A2, class _Up>
struct __allocator_traits_rebind<_Alloc<_Tp, _A0, _A1, _A2>, _Up, true>
{
typedef typename _Alloc<_Tp, _A0, _A1, _A2>::template rebind<_Up>::other type;
};
template <template <class, class, class, class> class _Alloc, class _Tp, class _A0,
class _A1, class _A2, class _Up>
struct __allocator_traits_rebind<_Alloc<_Tp, _A0, _A1, _A2>, _Up, false>
{
typedef _Alloc<_Up, _A0, _A1, _A2> type;
};
#endif // _LIBCPP_HAS_NO_VARIADICS
#ifndef _LIBCPP_CXX03_LANG
template <class _Alloc, class _SizeType, class _ConstVoidPtr>
auto
__has_allocate_hint_test(_Alloc&& __a, _SizeType&& __sz, _ConstVoidPtr&& __p)
-> decltype((void)__a.allocate(__sz, __p), true_type());
template <class _Alloc, class _SizeType, class _ConstVoidPtr>
auto
__has_allocate_hint_test(const _Alloc& __a, _SizeType&& __sz, _ConstVoidPtr&& __p)
-> false_type;
template <class _Alloc, class _SizeType, class _ConstVoidPtr>
struct __has_allocate_hint
: integral_constant<bool,
is_same<
decltype(_VSTD::__has_allocate_hint_test(declval<_Alloc>(),
declval<_SizeType>(),
declval<_ConstVoidPtr>())),
true_type>::value>
{
};
#else // _LIBCPP_CXX03_LANG
template <class _Alloc, class _SizeType, class _ConstVoidPtr>
struct __has_allocate_hint
: true_type
{
};
#endif // _LIBCPP_CXX03_LANG
#if !defined(_LIBCPP_CXX03_LANG)
template <class _Alloc, class _Tp, class ..._Args>
decltype(_VSTD::declval<_Alloc>().construct(_VSTD::declval<_Tp*>(),
_VSTD::declval<_Args>()...),
true_type())
__has_construct_test(_Alloc&& __a, _Tp* __p, _Args&& ...__args);
template <class _Alloc, class _Pointer, class ..._Args>
false_type
__has_construct_test(const _Alloc& __a, _Pointer&& __p, _Args&& ...__args);
template <class _Alloc, class _Pointer, class ..._Args>
struct __has_construct
: integral_constant<bool,
is_same<
decltype(_VSTD::__has_construct_test(declval<_Alloc>(),
declval<_Pointer>(),
declval<_Args>()...)),
true_type>::value>
{
};
template <class _Alloc, class _Pointer>
auto
__has_destroy_test(_Alloc&& __a, _Pointer&& __p)
-> decltype(__a.destroy(__p), true_type());
template <class _Alloc, class _Pointer>
auto
__has_destroy_test(const _Alloc& __a, _Pointer&& __p)
-> false_type;
template <class _Alloc, class _Pointer>
struct __has_destroy
: integral_constant<bool,
is_same<
decltype(_VSTD::__has_destroy_test(declval<_Alloc>(),
declval<_Pointer>())),
true_type>::value>
{
};
template <class _Alloc>
auto
__has_max_size_test(_Alloc&& __a)
-> decltype(__a.max_size(), true_type());
template <class _Alloc>
auto
__has_max_size_test(const volatile _Alloc& __a)
-> false_type;
template <class _Alloc>
struct __has_max_size
: integral_constant<bool,
is_same<
decltype(_VSTD::__has_max_size_test(declval<_Alloc&>())),
true_type>::value>
{
};
template <class _Alloc>
auto
__has_select_on_container_copy_construction_test(_Alloc&& __a)
-> decltype(__a.select_on_container_copy_construction(), true_type());
template <class _Alloc>
auto
__has_select_on_container_copy_construction_test(const volatile _Alloc& __a)
-> false_type;
template <class _Alloc>
struct __has_select_on_container_copy_construction
: integral_constant<bool,
is_same<
decltype(_VSTD::__has_select_on_container_copy_construction_test(declval<_Alloc&>())),
true_type>::value>
{
};
#else // _LIBCPP_CXX03_LANG
template <class _Alloc, class _Pointer, class _Tp, class = void>
struct __has_construct : std::false_type {};
template <class _Alloc, class _Pointer, class _Tp>
struct __has_construct<_Alloc, _Pointer, _Tp, typename __void_t<
decltype(_VSTD::declval<_Alloc>().construct(_VSTD::declval<_Pointer>(), _VSTD::declval<_Tp>()))
>::type> : std::true_type {};
template <class _Alloc, class _Pointer, class = void>
struct __has_destroy : false_type {};
template <class _Alloc, class _Pointer>
struct __has_destroy<_Alloc, _Pointer, typename __void_t<
decltype(_VSTD::declval<_Alloc>().destroy(_VSTD::declval<_Pointer>()))
>::type> : std::true_type {};
template <class _Alloc>
struct __has_max_size
: true_type
{
};
template <class _Alloc>
struct __has_select_on_container_copy_construction
: false_type
{
};
#endif // _LIBCPP_CXX03_LANG
template <class _Alloc, class _Ptr, bool = __has_difference_type<_Alloc>::value>
struct __alloc_traits_difference_type
{
typedef _LIBCPP_NODEBUG_TYPE typename pointer_traits<_Ptr>::difference_type type;
};
template <class _Alloc, class _Ptr>
struct __alloc_traits_difference_type<_Alloc, _Ptr, true>
{
typedef _LIBCPP_NODEBUG_TYPE typename _Alloc::difference_type type;
};
template <class _Tp>
struct __is_default_allocator : false_type {};
template <class _Tp>
struct __is_default_allocator<_VSTD::allocator<_Tp> > : true_type {};
template <class _Alloc,
bool = __has_construct<_Alloc, typename _Alloc::value_type*, typename _Alloc::value_type&&>::value && !__is_default_allocator<_Alloc>::value
>
struct __is_cpp17_move_insertable;
template <class _Alloc>
struct __is_cpp17_move_insertable<_Alloc, true> : std::true_type {};
template <class _Alloc>
struct __is_cpp17_move_insertable<_Alloc, false> : std::is_move_constructible<typename _Alloc::value_type> {};
template <class _Alloc,
bool = __has_construct<_Alloc, typename _Alloc::value_type*, const typename _Alloc::value_type&>::value && !__is_default_allocator<_Alloc>::value
>
struct __is_cpp17_copy_insertable;
template <class _Alloc>
struct __is_cpp17_copy_insertable<_Alloc, true> : __is_cpp17_move_insertable<_Alloc> {};
template <class _Alloc>
struct __is_cpp17_copy_insertable<_Alloc, false> : integral_constant<bool,
std::is_copy_constructible<typename _Alloc::value_type>::value &&
__is_cpp17_move_insertable<_Alloc>::value>
{};
template <class _Alloc>
struct _LIBCPP_TEMPLATE_VIS allocator_traits
{
typedef _Alloc allocator_type;
typedef typename allocator_type::value_type value_type;
typedef typename __pointer_type<value_type, allocator_type>::type pointer;
typedef typename __const_pointer<value_type, pointer, allocator_type>::type const_pointer;
typedef typename __void_pointer<pointer, allocator_type>::type void_pointer;
typedef typename __const_void_pointer<pointer, allocator_type>::type const_void_pointer;
typedef typename __alloc_traits_difference_type<allocator_type, pointer>::type difference_type;
typedef typename __size_type<allocator_type, difference_type>::type size_type;
typedef typename __propagate_on_container_copy_assignment<allocator_type>::type
propagate_on_container_copy_assignment;
typedef typename __propagate_on_container_move_assignment<allocator_type>::type
propagate_on_container_move_assignment;
typedef typename __propagate_on_container_swap<allocator_type>::type
propagate_on_container_swap;
typedef typename __is_always_equal<allocator_type>::type
is_always_equal;
#ifndef _LIBCPP_CXX03_LANG
template <class _Tp> using rebind_alloc =
typename __allocator_traits_rebind<allocator_type, _Tp>::type;
template <class _Tp> using rebind_traits = allocator_traits<rebind_alloc<_Tp> >;
#else // _LIBCPP_CXX03_LANG
template <class _Tp> struct rebind_alloc
{typedef typename __allocator_traits_rebind<allocator_type, _Tp>::type other;};
template <class _Tp> struct rebind_traits
{typedef allocator_traits<typename rebind_alloc<_Tp>::other> other;};
#endif // _LIBCPP_CXX03_LANG
_LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
static pointer allocate(allocator_type& __a, size_type __n)
{return __a.allocate(__n);}
_LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
static pointer allocate(allocator_type& __a, size_type __n, const_void_pointer __hint)
{return __allocate(__a, __n, __hint,
__has_allocate_hint<allocator_type, size_type, const_void_pointer>());}
_LIBCPP_INLINE_VISIBILITY
static void deallocate(allocator_type& __a, pointer __p, size_type __n) _NOEXCEPT
{__a.deallocate(__p, __n);}
#ifndef _LIBCPP_HAS_NO_VARIADICS
template <class _Tp, class... _Args>
_LIBCPP_INLINE_VISIBILITY
static void construct(allocator_type& __a, _Tp* __p, _Args&&... __args)
{__construct(__has_construct<allocator_type, _Tp*, _Args...>(),
__a, __p, _VSTD::forward<_Args>(__args)...);}
#else // _LIBCPP_HAS_NO_VARIADICS
template <class _Tp>
_LIBCPP_INLINE_VISIBILITY
static void construct(allocator_type&, _Tp* __p)
{
::new ((void*)__p) _Tp();
}
template <class _Tp, class _A0>
_LIBCPP_INLINE_VISIBILITY
static void construct(allocator_type& __a, _Tp* __p, const _A0& __a0)
{
__construct(__has_construct<allocator_type, _Tp*, const _A0&>(),
__a, __p, __a0);
}
template <class _Tp, class _A0, class _A1>
_LIBCPP_INLINE_VISIBILITY
static void construct(allocator_type&, _Tp* __p, const _A0& __a0,
const _A1& __a1)
{
::new ((void*)__p) _Tp(__a0, __a1);
}
template <class _Tp, class _A0, class _A1, class _A2>
_LIBCPP_INLINE_VISIBILITY
static void construct(allocator_type&, _Tp* __p, const _A0& __a0,
const _A1& __a1, const _A2& __a2)
{
::new ((void*)__p) _Tp(__a0, __a1, __a2);
}
#endif // _LIBCPP_HAS_NO_VARIADICS
template <class _Tp>
_LIBCPP_INLINE_VISIBILITY
static void destroy(allocator_type& __a, _Tp* __p)
{__destroy(__has_destroy<allocator_type, _Tp*>(), __a, __p);}
_LIBCPP_INLINE_VISIBILITY
static size_type max_size(const allocator_type& __a) _NOEXCEPT
{return __max_size(__has_max_size<const allocator_type>(), __a);}
_LIBCPP_INLINE_VISIBILITY
static allocator_type
select_on_container_copy_construction(const allocator_type& __a)
{return __select_on_container_copy_construction(
__has_select_on_container_copy_construction<const allocator_type>(),
__a);}
template <class _Ptr>
_LIBCPP_INLINE_VISIBILITY
static
void
__construct_forward_with_exception_guarantees(allocator_type& __a, _Ptr __begin1, _Ptr __end1, _Ptr& __begin2)
{
static_assert(__is_cpp17_move_insertable<allocator_type>::value,
"The specified type does not meet the requirements of Cpp17MoveInsertible");
for (; __begin1 != __end1; ++__begin1, (void) ++__begin2)
construct(__a, _VSTD::__to_raw_pointer(__begin2),
#ifdef _LIBCPP_NO_EXCEPTIONS
_VSTD::move(*__begin1)
#else
_VSTD::move_if_noexcept(*__begin1)
#endif
);
}
template <class _Tp>
_LIBCPP_INLINE_VISIBILITY
static
typename enable_if
<
(__is_default_allocator<allocator_type>::value
|| !__has_construct<allocator_type, _Tp*, _Tp>::value) &&
is_trivially_move_constructible<_Tp>::value,
void
>::type
__construct_forward_with_exception_guarantees(allocator_type&, _Tp* __begin1, _Tp* __end1, _Tp*& __begin2)
{
ptrdiff_t _Np = __end1 - __begin1;
if (_Np > 0)
{
_VSTD::memcpy(__begin2, __begin1, _Np * sizeof(_Tp));
__begin2 += _Np;
}
}
template <class _Iter, class _Ptr>
_LIBCPP_INLINE_VISIBILITY
static
void
__construct_range_forward(allocator_type& __a, _Iter __begin1, _Iter __end1, _Ptr& __begin2)
{
for (; __begin1 != __end1; ++__begin1, (void) ++__begin2)
construct(__a, _VSTD::__to_raw_pointer(__begin2), *__begin1);
}
template <class _SourceTp, class _DestTp,
class _RawSourceTp = typename remove_const<_SourceTp>::type,
class _RawDestTp = typename remove_const<_DestTp>::type>
_LIBCPP_INLINE_VISIBILITY
static
typename enable_if
<
is_trivially_move_constructible<_DestTp>::value &&
is_same<_RawSourceTp, _RawDestTp>::value &&
(__is_default_allocator<allocator_type>::value ||
!__has_construct<allocator_type, _DestTp*, _SourceTp&>::value),
void
>::type
__construct_range_forward(allocator_type&, _SourceTp* __begin1, _SourceTp* __end1, _DestTp*& __begin2)
{
ptrdiff_t _Np = __end1 - __begin1;
if (_Np > 0)
{
_VSTD::memcpy(const_cast<_RawDestTp*>(__begin2), __begin1, _Np * sizeof(_DestTp));
__begin2 += _Np;
}
}
template <class _Ptr>
_LIBCPP_INLINE_VISIBILITY
static
void
__construct_backward_with_exception_guarantees(allocator_type& __a, _Ptr __begin1, _Ptr __end1, _Ptr& __end2)
{
static_assert(__is_cpp17_move_insertable<allocator_type>::value,
"The specified type does not meet the requirements of Cpp17MoveInsertable");
while (__end1 != __begin1)
{
construct(__a, _VSTD::__to_raw_pointer(__end2 - 1),
#ifdef _LIBCPP_NO_EXCEPTIONS
_VSTD::move(*--__end1)
#else
_VSTD::move_if_noexcept(*--__end1)
#endif
);
--__end2;
}
}
template <class _Tp>
_LIBCPP_INLINE_VISIBILITY
static
typename enable_if
<
(__is_default_allocator<allocator_type>::value
|| !__has_construct<allocator_type, _Tp*, _Tp>::value) &&
is_trivially_move_constructible<_Tp>::value,
void
>::type
__construct_backward_with_exception_guarantees(allocator_type&, _Tp* __begin1, _Tp* __end1, _Tp*& __end2)
{
ptrdiff_t _Np = __end1 - __begin1;
__end2 -= _Np;
if (_Np > 0)
_VSTD::memcpy((void *)__end2, __begin1, _Np * sizeof(_Tp));
}
private:
_LIBCPP_INLINE_VISIBILITY
static pointer __allocate(allocator_type& __a, size_type __n,
const_void_pointer __hint, true_type)
{return __a.allocate(__n, __hint);}
_LIBCPP_INLINE_VISIBILITY
static pointer __allocate(allocator_type& __a, size_type __n,
const_void_pointer, false_type)
{return __a.allocate(__n);}
#ifndef _LIBCPP_HAS_NO_VARIADICS
template <class _Tp, class... _Args>
_LIBCPP_INLINE_VISIBILITY
static void __construct(true_type, allocator_type& __a, _Tp* __p, _Args&&... __args)
{__a.construct(__p, _VSTD::forward<_Args>(__args)...);}
template <class _Tp, class... _Args>
_LIBCPP_INLINE_VISIBILITY
static void __construct(false_type, allocator_type&, _Tp* __p, _Args&&... __args)
{
::new ((void*)__p) _Tp(_VSTD::forward<_Args>(__args)...);
}
#else // _LIBCPP_HAS_NO_VARIADICS
template <class _Tp, class _A0>
_LIBCPP_INLINE_VISIBILITY
static void __construct(true_type, allocator_type& __a, _Tp* __p,
const _A0& __a0)
{__a.construct(__p, __a0);}
template <class _Tp, class _A0>
_LIBCPP_INLINE_VISIBILITY
static void __construct(false_type, allocator_type&, _Tp* __p,
const _A0& __a0)
{
::new ((void*)__p) _Tp(__a0);
}
#endif // _LIBCPP_HAS_NO_VARIADICS
template <class _Tp>
_LIBCPP_INLINE_VISIBILITY
static void __destroy(true_type, allocator_type& __a, _Tp* __p)
{__a.destroy(__p);}
template <class _Tp>
_LIBCPP_INLINE_VISIBILITY
static void __destroy(false_type, allocator_type&, _Tp* __p)
{
__p->~_Tp();
}
_LIBCPP_INLINE_VISIBILITY
static size_type __max_size(true_type, const allocator_type& __a) _NOEXCEPT
{return __a.max_size();}
_LIBCPP_INLINE_VISIBILITY
static size_type __max_size(false_type, const allocator_type&) _NOEXCEPT
{return numeric_limits<size_type>::max() / sizeof(value_type);}
_LIBCPP_INLINE_VISIBILITY
static allocator_type
__select_on_container_copy_construction(true_type, const allocator_type& __a)
{return __a.select_on_container_copy_construction();}
_LIBCPP_INLINE_VISIBILITY
static allocator_type
__select_on_container_copy_construction(false_type, const allocator_type& __a)
{return __a;}
};
template <class _Traits, class _Tp>
struct __rebind_alloc_helper
{
#ifndef _LIBCPP_CXX03_LANG
typedef _LIBCPP_NODEBUG_TYPE typename _Traits::template rebind_alloc<_Tp> type;
#else
typedef typename _Traits::template rebind_alloc<_Tp>::other type;
#endif
};
// allocator
template <class _Tp>
class _LIBCPP_TEMPLATE_VIS allocator
{
public:
typedef size_t size_type;
typedef ptrdiff_t difference_type;
typedef _Tp* pointer;
typedef const _Tp* const_pointer;
typedef _Tp& reference;
typedef const _Tp& const_reference;
typedef _Tp value_type;
typedef true_type propagate_on_container_move_assignment;
typedef true_type is_always_equal;
template <class _Up> struct rebind {typedef allocator<_Up> other;};
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
allocator() _NOEXCEPT {}
template <class _Up>
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
allocator(const allocator<_Up>&) _NOEXCEPT {}
_LIBCPP_INLINE_VISIBILITY pointer address(reference __x) const _NOEXCEPT
{return _VSTD::addressof(__x);}
_LIBCPP_INLINE_VISIBILITY const_pointer address(const_reference __x) const _NOEXCEPT
{return _VSTD::addressof(__x);}
_LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
pointer allocate(size_type __n, allocator<void>::const_pointer = 0)
{
if (__n > max_size())
__throw_length_error("allocator<T>::allocate(size_t n)"
" 'n' exceeds maximum supported size");
return static_cast<pointer>(_VSTD::__libcpp_allocate(__n * sizeof(_Tp), _LIBCPP_ALIGNOF(_Tp)));
}
_LIBCPP_INLINE_VISIBILITY void deallocate(pointer __p, size_type __n) _NOEXCEPT
{_VSTD::__libcpp_deallocate((void*)__p, __n * sizeof(_Tp), _LIBCPP_ALIGNOF(_Tp));}
_LIBCPP_INLINE_VISIBILITY size_type max_size() const _NOEXCEPT
{return size_type(~0) / sizeof(_Tp);}
#if !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
template <class _Up, class... _Args>
_LIBCPP_INLINE_VISIBILITY
void
construct(_Up* __p, _Args&&... __args)
{
::new((void*)__p) _Up(_VSTD::forward<_Args>(__args)...);
}
#else // !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
_LIBCPP_INLINE_VISIBILITY
void
construct(pointer __p)
{
::new((void*)__p) _Tp();
}
# if defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES)
template <class _A0>
_LIBCPP_INLINE_VISIBILITY
void
construct(pointer __p, _A0& __a0)
{
::new((void*)__p) _Tp(__a0);
}
template <class _A0>
_LIBCPP_INLINE_VISIBILITY
void
construct(pointer __p, const _A0& __a0)
{
::new((void*)__p) _Tp(__a0);
}
# endif // defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES)
template <class _A0, class _A1>
_LIBCPP_INLINE_VISIBILITY
void
construct(pointer __p, _A0& __a0, _A1& __a1)
{
::new((void*)__p) _Tp(__a0, __a1);
}
template <class _A0, class _A1>
_LIBCPP_INLINE_VISIBILITY
void
construct(pointer __p, const _A0& __a0, _A1& __a1)
{
::new((void*)__p) _Tp(__a0, __a1);
}
template <class _A0, class _A1>
_LIBCPP_INLINE_VISIBILITY
void
construct(pointer __p, _A0& __a0, const _A1& __a1)
{
::new((void*)__p) _Tp(__a0, __a1);
}
template <class _A0, class _A1>
_LIBCPP_INLINE_VISIBILITY
void
construct(pointer __p, const _A0& __a0, const _A1& __a1)
{
::new((void*)__p) _Tp(__a0, __a1);
}
#endif // !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
_LIBCPP_INLINE_VISIBILITY void destroy(pointer __p) {__p->~_Tp();}
};
template <class _Tp>
class _LIBCPP_TEMPLATE_VIS allocator<const _Tp>
{
public:
typedef size_t size_type;
typedef ptrdiff_t difference_type;
typedef const _Tp* pointer;
typedef const _Tp* const_pointer;
typedef const _Tp& reference;
typedef const _Tp& const_reference;
typedef const _Tp value_type;
typedef true_type propagate_on_container_move_assignment;
typedef true_type is_always_equal;
template <class _Up> struct rebind {typedef allocator<_Up> other;};
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
allocator() _NOEXCEPT {}
template <class _Up>
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
allocator(const allocator<_Up>&) _NOEXCEPT {}
_LIBCPP_INLINE_VISIBILITY const_pointer address(const_reference __x) const _NOEXCEPT
{return _VSTD::addressof(__x);}
_LIBCPP_INLINE_VISIBILITY pointer allocate(size_type __n, allocator<void>::const_pointer = 0)
{
if (__n > max_size())
__throw_length_error("allocator<const T>::allocate(size_t n)"
" 'n' exceeds maximum supported size");
return static_cast<pointer>(_VSTD::__libcpp_allocate(__n * sizeof(_Tp), _LIBCPP_ALIGNOF(_Tp)));
}
_LIBCPP_INLINE_VISIBILITY void deallocate(pointer __p, size_type __n) _NOEXCEPT
{_VSTD::__libcpp_deallocate((void*) const_cast<_Tp *>(__p), __n * sizeof(_Tp), _LIBCPP_ALIGNOF(_Tp));}
_LIBCPP_INLINE_VISIBILITY size_type max_size() const _NOEXCEPT
{return size_type(~0) / sizeof(_Tp);}
#if !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
template <class _Up, class... _Args>
_LIBCPP_INLINE_VISIBILITY
void
construct(_Up* __p, _Args&&... __args)
{
::new((void*)__p) _Up(_VSTD::forward<_Args>(__args)...);
}
#else // !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
_LIBCPP_INLINE_VISIBILITY
void
construct(pointer __p)
{
::new((void*) const_cast<_Tp *>(__p)) _Tp();
}
# if defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES)
template <class _A0>
_LIBCPP_INLINE_VISIBILITY
void
construct(pointer __p, _A0& __a0)
{
::new((void*) const_cast<_Tp *>(__p)) _Tp(__a0);
}
template <class _A0>
_LIBCPP_INLINE_VISIBILITY
void
construct(pointer __p, const _A0& __a0)
{
::new((void*) const_cast<_Tp *>(__p)) _Tp(__a0);
}
# endif // defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES)
template <class _A0, class _A1>
_LIBCPP_INLINE_VISIBILITY
void
construct(pointer __p, _A0& __a0, _A1& __a1)
{
::new((void*) const_cast<_Tp *>(__p)) _Tp(__a0, __a1);
}
template <class _A0, class _A1>
_LIBCPP_INLINE_VISIBILITY
void
construct(pointer __p, const _A0& __a0, _A1& __a1)
{
::new((void*) const_cast<_Tp *>(__p)) _Tp(__a0, __a1);
}
template <class _A0, class _A1>
_LIBCPP_INLINE_VISIBILITY
void
construct(pointer __p, _A0& __a0, const _A1& __a1)
{
::new((void*) const_cast<_Tp *>(__p)) _Tp(__a0, __a1);
}
template <class _A0, class _A1>
_LIBCPP_INLINE_VISIBILITY
void
construct(pointer __p, const _A0& __a0, const _A1& __a1)
{
::new((void*) const_cast<_Tp *>(__p)) _Tp(__a0, __a1);
}
#endif // !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
_LIBCPP_INLINE_VISIBILITY void destroy(pointer __p) {__p->~_Tp();}
};
template <class _Tp, class _Up>
inline _LIBCPP_INLINE_VISIBILITY
bool operator==(const allocator<_Tp>&, const allocator<_Up>&) _NOEXCEPT {return true;}
template <class _Tp, class _Up>
inline _LIBCPP_INLINE_VISIBILITY
bool operator!=(const allocator<_Tp>&, const allocator<_Up>&) _NOEXCEPT {return false;}
template <class _OutputIterator, class _Tp>
class _LIBCPP_TEMPLATE_VIS raw_storage_iterator
: public iterator<output_iterator_tag,
_Tp, // purposefully not C++03
ptrdiff_t, // purposefully not C++03
_Tp*, // purposefully not C++03
raw_storage_iterator<_OutputIterator, _Tp>&> // purposefully not C++03
{
private:
_OutputIterator __x_;
public:
_LIBCPP_INLINE_VISIBILITY explicit raw_storage_iterator(_OutputIterator __x) : __x_(__x) {}
_LIBCPP_INLINE_VISIBILITY raw_storage_iterator& operator*() {return *this;}
_LIBCPP_INLINE_VISIBILITY raw_storage_iterator& operator=(const _Tp& __element)
{::new(_VSTD::addressof(*__x_)) _Tp(__element); return *this;}
#if _LIBCPP_STD_VER >= 14
_LIBCPP_INLINE_VISIBILITY raw_storage_iterator& operator=(_Tp&& __element)
{::new(_VSTD::addressof(*__x_)) _Tp(_VSTD::move(__element)); return *this;}
#endif
_LIBCPP_INLINE_VISIBILITY raw_storage_iterator& operator++() {++__x_; return *this;}
_LIBCPP_INLINE_VISIBILITY raw_storage_iterator operator++(int)
{raw_storage_iterator __t(*this); ++__x_; return __t;}
#if _LIBCPP_STD_VER >= 14
_LIBCPP_INLINE_VISIBILITY _OutputIterator base() const { return __x_; }
#endif
};
template <class _Tp>
_LIBCPP_NODISCARD_EXT _LIBCPP_NO_CFI
pair<_Tp*, ptrdiff_t>
get_temporary_buffer(ptrdiff_t __n) _NOEXCEPT
{
pair<_Tp*, ptrdiff_t> __r(0, 0);
const ptrdiff_t __m = (~ptrdiff_t(0) ^
ptrdiff_t(ptrdiff_t(1) << (sizeof(ptrdiff_t) * __CHAR_BIT__ - 1)))
/ sizeof(_Tp);
if (__n > __m)
__n = __m;
while (__n > 0)
{
#if !defined(_LIBCPP_HAS_NO_ALIGNED_ALLOCATION)
if (__is_overaligned_for_new(_LIBCPP_ALIGNOF(_Tp)))
{
std::align_val_t __al =
std::align_val_t(std::alignment_of<_Tp>::value);
__r.first = static_cast<_Tp*>(::operator new(
__n * sizeof(_Tp), __al, nothrow));
} else {
__r.first = static_cast<_Tp*>(::operator new(
__n * sizeof(_Tp), nothrow));
}
#else
if (__is_overaligned_for_new(_LIBCPP_ALIGNOF(_Tp)))
{
// Since aligned operator new is unavailable, return an empty
// buffer rather than one with invalid alignment.
return __r;
}
__r.first = static_cast<_Tp*>(::operator new(__n * sizeof(_Tp), nothrow));
#endif
if (__r.first)
{
__r.second = __n;
break;
}
__n /= 2;
}
return __r;
}
template <class _Tp>
inline _LIBCPP_INLINE_VISIBILITY
void return_temporary_buffer(_Tp* __p) _NOEXCEPT
{
_VSTD::__libcpp_deallocate_unsized((void*)__p, _LIBCPP_ALIGNOF(_Tp));
}
#if _LIBCPP_STD_VER <= 14 || defined(_LIBCPP_ENABLE_CXX17_REMOVED_AUTO_PTR)
template <class _Tp>
struct _LIBCPP_DEPRECATED_IN_CXX11 auto_ptr_ref
{
_Tp* __ptr_;
};
template<class _Tp>
class _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX11 auto_ptr
{
private:
_Tp* __ptr_;
public:
typedef _Tp element_type;
_LIBCPP_INLINE_VISIBILITY explicit auto_ptr(_Tp* __p = 0) throw() : __ptr_(__p) {}
_LIBCPP_INLINE_VISIBILITY auto_ptr(auto_ptr& __p) throw() : __ptr_(__p.release()) {}
template<class _Up> _LIBCPP_INLINE_VISIBILITY auto_ptr(auto_ptr<_Up>& __p) throw()
: __ptr_(__p.release()) {}
_LIBCPP_INLINE_VISIBILITY auto_ptr& operator=(auto_ptr& __p) throw()
{reset(__p.release()); return *this;}
template<class _Up> _LIBCPP_INLINE_VISIBILITY auto_ptr& operator=(auto_ptr<_Up>& __p) throw()
{reset(__p.release()); return *this;}
_LIBCPP_INLINE_VISIBILITY auto_ptr& operator=(auto_ptr_ref<_Tp> __p) throw()
{reset(__p.__ptr_); return *this;}
_LIBCPP_INLINE_VISIBILITY ~auto_ptr() throw() {delete __ptr_;}
_LIBCPP_INLINE_VISIBILITY _Tp& operator*() const throw()
{return *__ptr_;}
_LIBCPP_INLINE_VISIBILITY _Tp* operator->() const throw() {return __ptr_;}
_LIBCPP_INLINE_VISIBILITY _Tp* get() const throw() {return __ptr_;}
_LIBCPP_INLINE_VISIBILITY _Tp* release() throw()
{
_Tp* __t = __ptr_;
__ptr_ = 0;
return __t;
}
_LIBCPP_INLINE_VISIBILITY void reset(_Tp* __p = 0) throw()
{
if (__ptr_ != __p)
delete __ptr_;
__ptr_ = __p;
}
_LIBCPP_INLINE_VISIBILITY auto_ptr(auto_ptr_ref<_Tp> __p) throw() : __ptr_(__p.__ptr_) {}
template<class _Up> _LIBCPP_INLINE_VISIBILITY operator auto_ptr_ref<_Up>() throw()
{auto_ptr_ref<_Up> __t; __t.__ptr_ = release(); return __t;}
template<class _Up> _LIBCPP_INLINE_VISIBILITY operator auto_ptr<_Up>() throw()
{return auto_ptr<_Up>(release());}
};
template <>
class _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX11 auto_ptr<void>
{
public:
typedef void element_type;
};
#endif
template <class _Tp, int _Idx,
bool _CanBeEmptyBase =
is_empty<_Tp>::value && !__libcpp_is_final<_Tp>::value>
struct __compressed_pair_elem {
typedef _Tp _ParamT;
typedef _Tp& reference;
typedef const _Tp& const_reference;
#ifndef _LIBCPP_CXX03_LANG
_LIBCPP_INLINE_VISIBILITY constexpr __compressed_pair_elem() : __value_() {}
template <class _Up, class = typename enable_if<
!is_same<__compressed_pair_elem, typename decay<_Up>::type>::value
>::type>
_LIBCPP_INLINE_VISIBILITY
constexpr explicit
__compressed_pair_elem(_Up&& __u)
: __value_(_VSTD::forward<_Up>(__u))
{
}
template <class... _Args, size_t... _Indexes>
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
__compressed_pair_elem(piecewise_construct_t, tuple<_Args...> __args,
__tuple_indices<_Indexes...>)
: __value_(_VSTD::forward<_Args>(_VSTD::get<_Indexes>(__args))...) {}
#else
_LIBCPP_INLINE_VISIBILITY __compressed_pair_elem() : __value_() {}
_LIBCPP_INLINE_VISIBILITY
__compressed_pair_elem(_ParamT __p) : __value_(std::forward<_ParamT>(__p)) {}
#endif
_LIBCPP_INLINE_VISIBILITY reference __get() _NOEXCEPT { return __value_; }
_LIBCPP_INLINE_VISIBILITY
const_reference __get() const _NOEXCEPT { return __value_; }
private:
_Tp __value_;
};
template <class _Tp, int _Idx>
struct __compressed_pair_elem<_Tp, _Idx, true> : private _Tp {
typedef _Tp _ParamT;
typedef _Tp& reference;
typedef const _Tp& const_reference;
typedef _Tp __value_type;
#ifndef _LIBCPP_CXX03_LANG
_LIBCPP_INLINE_VISIBILITY constexpr __compressed_pair_elem() = default;
template <class _Up, class = typename enable_if<
!is_same<__compressed_pair_elem, typename decay<_Up>::type>::value
>::type>
_LIBCPP_INLINE_VISIBILITY
constexpr explicit
__compressed_pair_elem(_Up&& __u)
: __value_type(_VSTD::forward<_Up>(__u))
{}
template <class... _Args, size_t... _Indexes>
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
__compressed_pair_elem(piecewise_construct_t, tuple<_Args...> __args,
__tuple_indices<_Indexes...>)
: __value_type(_VSTD::forward<_Args>(_VSTD::get<_Indexes>(__args))...) {}
#else
_LIBCPP_INLINE_VISIBILITY __compressed_pair_elem() : __value_type() {}
_LIBCPP_INLINE_VISIBILITY
__compressed_pair_elem(_ParamT __p)
: __value_type(std::forward<_ParamT>(__p)) {}
#endif
_LIBCPP_INLINE_VISIBILITY reference __get() _NOEXCEPT { return *this; }
_LIBCPP_INLINE_VISIBILITY
const_reference __get() const _NOEXCEPT { return *this; }
};
// Tag used to construct the second element of the compressed pair.
struct __second_tag {};
template <class _T1, class _T2>
class __compressed_pair : private __compressed_pair_elem<_T1, 0>,
private __compressed_pair_elem<_T2, 1> {
typedef _LIBCPP_NODEBUG_TYPE __compressed_pair_elem<_T1, 0> _Base1;
typedef _LIBCPP_NODEBUG_TYPE __compressed_pair_elem<_T2, 1> _Base2;
// NOTE: This static assert should never fire because __compressed_pair
// is *almost never* used in a scenario where it's possible for T1 == T2.
// (The exception is std::function where it is possible that the function
// object and the allocator have the same type).
static_assert((!is_same<_T1, _T2>::value),
"__compressed_pair cannot be instantated when T1 and T2 are the same type; "
"The current implementation is NOT ABI-compatible with the previous "
"implementation for this configuration");
public:
#ifndef _LIBCPP_CXX03_LANG
template <bool _Dummy = true,
class = typename enable_if<
__dependent_type<is_default_constructible<_T1>, _Dummy>::value &&
__dependent_type<is_default_constructible<_T2>, _Dummy>::value
>::type
>
_LIBCPP_INLINE_VISIBILITY
constexpr __compressed_pair() {}
template <class _Tp, typename enable_if<!is_same<typename decay<_Tp>::type,
__compressed_pair>::value,
bool>::type = true>
_LIBCPP_INLINE_VISIBILITY constexpr explicit
__compressed_pair(_Tp&& __t)
: _Base1(std::forward<_Tp>(__t)), _Base2() {}
template <class _Tp>
_LIBCPP_INLINE_VISIBILITY constexpr
__compressed_pair(__second_tag, _Tp&& __t)
: _Base1(), _Base2(std::forward<_Tp>(__t)) {}
template <class _U1, class _U2>
_LIBCPP_INLINE_VISIBILITY constexpr
__compressed_pair(_U1&& __t1, _U2&& __t2)
: _Base1(std::forward<_U1>(__t1)), _Base2(std::forward<_U2>(__t2)) {}
template <class... _Args1, class... _Args2>
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
__compressed_pair(piecewise_construct_t __pc, tuple<_Args1...> __first_args,
tuple<_Args2...> __second_args)
: _Base1(__pc, _VSTD::move(__first_args),
typename __make_tuple_indices<sizeof...(_Args1)>::type()),
_Base2(__pc, _VSTD::move(__second_args),
typename __make_tuple_indices<sizeof...(_Args2)>::type()) {}
#else
_LIBCPP_INLINE_VISIBILITY
__compressed_pair() {}
_LIBCPP_INLINE_VISIBILITY explicit
__compressed_pair(_T1 __t1) : _Base1(_VSTD::forward<_T1>(__t1)) {}
_LIBCPP_INLINE_VISIBILITY
__compressed_pair(__second_tag, _T2 __t2)
: _Base1(), _Base2(_VSTD::forward<_T2>(__t2)) {}
_LIBCPP_INLINE_VISIBILITY
__compressed_pair(_T1 __t1, _T2 __t2)
: _Base1(_VSTD::forward<_T1>(__t1)), _Base2(_VSTD::forward<_T2>(__t2)) {}
#endif
_LIBCPP_INLINE_VISIBILITY
typename _Base1::reference first() _NOEXCEPT {
return static_cast<_Base1&>(*this).__get();
}
_LIBCPP_INLINE_VISIBILITY
typename _Base1::const_reference first() const _NOEXCEPT {
return static_cast<_Base1 const&>(*this).__get();
}
_LIBCPP_INLINE_VISIBILITY
typename _Base2::reference second() _NOEXCEPT {
return static_cast<_Base2&>(*this).__get();
}
_LIBCPP_INLINE_VISIBILITY
typename _Base2::const_reference second() const _NOEXCEPT {
return static_cast<_Base2 const&>(*this).__get();
}
_LIBCPP_INLINE_VISIBILITY
void swap(__compressed_pair& __x)
_NOEXCEPT_(__is_nothrow_swappable<_T1>::value &&
__is_nothrow_swappable<_T2>::value)
{
using std::swap;
swap(first(), __x.first());
swap(second(), __x.second());
}
};
template <class _T1, class _T2>
inline _LIBCPP_INLINE_VISIBILITY
void swap(__compressed_pair<_T1, _T2>& __x, __compressed_pair<_T1, _T2>& __y)
_NOEXCEPT_(__is_nothrow_swappable<_T1>::value &&
__is_nothrow_swappable<_T2>::value) {
__x.swap(__y);
}
// default_delete
template <class _Tp>
struct _LIBCPP_TEMPLATE_VIS default_delete {
static_assert(!is_function<_Tp>::value,
"default_delete cannot be instantiated for function types");
#ifndef _LIBCPP_CXX03_LANG
_LIBCPP_INLINE_VISIBILITY constexpr default_delete() _NOEXCEPT = default;
#else
_LIBCPP_INLINE_VISIBILITY default_delete() {}
#endif
template <class _Up>
_LIBCPP_INLINE_VISIBILITY
default_delete(const default_delete<_Up>&,
typename enable_if<is_convertible<_Up*, _Tp*>::value>::type* =
0) _NOEXCEPT {}
_LIBCPP_INLINE_VISIBILITY void operator()(_Tp* __ptr) const _NOEXCEPT {
static_assert(sizeof(_Tp) > 0,
"default_delete can not delete incomplete type");
static_assert(!is_void<_Tp>::value,
"default_delete can not delete incomplete type");
delete __ptr;
}
};
template <class _Tp>
struct _LIBCPP_TEMPLATE_VIS default_delete<_Tp[]> {
private:
template <class _Up>
struct _EnableIfConvertible
: enable_if<is_convertible<_Up(*)[], _Tp(*)[]>::value> {};
public:
#ifndef _LIBCPP_CXX03_LANG
_LIBCPP_INLINE_VISIBILITY constexpr default_delete() _NOEXCEPT = default;
#else
_LIBCPP_INLINE_VISIBILITY default_delete() {}
#endif
template <class _Up>
_LIBCPP_INLINE_VISIBILITY
default_delete(const default_delete<_Up[]>&,
typename _EnableIfConvertible<_Up>::type* = 0) _NOEXCEPT {}
template <class _Up>
_LIBCPP_INLINE_VISIBILITY
typename _EnableIfConvertible<_Up>::type
operator()(_Up* __ptr) const _NOEXCEPT {
static_assert(sizeof(_Tp) > 0,
"default_delete can not delete incomplete type");
static_assert(!is_void<_Tp>::value,
"default_delete can not delete void type");
delete[] __ptr;
}
};
template <class _Deleter>
struct __unique_ptr_deleter_sfinae {
static_assert(!is_reference<_Deleter>::value, "incorrect specialization");
typedef const _Deleter& __lval_ref_type;
typedef _Deleter&& __good_rval_ref_type;
typedef true_type __enable_rval_overload;
};
template <class _Deleter>
struct __unique_ptr_deleter_sfinae<_Deleter const&> {
typedef const _Deleter& __lval_ref_type;
typedef const _Deleter&& __bad_rval_ref_type;
typedef false_type __enable_rval_overload;
};
template <class _Deleter>
struct __unique_ptr_deleter_sfinae<_Deleter&> {
typedef _Deleter& __lval_ref_type;
typedef _Deleter&& __bad_rval_ref_type;
typedef false_type __enable_rval_overload;
};
template <class _Tp, class _Dp = default_delete<_Tp> >
class _LIBCPP_TEMPLATE_VIS unique_ptr {
public:
typedef _Tp element_type;
typedef _Dp deleter_type;
typedef _LIBCPP_NODEBUG_TYPE typename __pointer_type<_Tp, deleter_type>::type pointer;
static_assert(!is_rvalue_reference<deleter_type>::value,
"the specified deleter type cannot be an rvalue reference");
private:
__compressed_pair<pointer, deleter_type> __ptr_;
struct __nat { int __for_bool_; };
typedef _LIBCPP_NODEBUG_TYPE __unique_ptr_deleter_sfinae<_Dp> _DeleterSFINAE;
template <bool _Dummy>
using _LValRefType _LIBCPP_NODEBUG_TYPE =
typename __dependent_type<_DeleterSFINAE, _Dummy>::__lval_ref_type;
template <bool _Dummy>
using _GoodRValRefType _LIBCPP_NODEBUG_TYPE =
typename __dependent_type<_DeleterSFINAE, _Dummy>::__good_rval_ref_type;
template <bool _Dummy>
using _BadRValRefType _LIBCPP_NODEBUG_TYPE =
typename __dependent_type<_DeleterSFINAE, _Dummy>::__bad_rval_ref_type;
template <bool _Dummy, class _Deleter = typename __dependent_type<
__identity<deleter_type>, _Dummy>::type>
using _EnableIfDeleterDefaultConstructible _LIBCPP_NODEBUG_TYPE =
typename enable_if<is_default_constructible<_Deleter>::value &&
!is_pointer<_Deleter>::value>::type;
template <class _ArgType>
using _EnableIfDeleterConstructible _LIBCPP_NODEBUG_TYPE =
typename enable_if<is_constructible<deleter_type, _ArgType>::value>::type;
template <class _UPtr, class _Up>
using _EnableIfMoveConvertible _LIBCPP_NODEBUG_TYPE = typename enable_if<
is_convertible<typename _UPtr::pointer, pointer>::value &&
!is_array<_Up>::value
>::type;
template <class _UDel>
using _EnableIfDeleterConvertible _LIBCPP_NODEBUG_TYPE = typename enable_if<
(is_reference<_Dp>::value && is_same<_Dp, _UDel>::value) ||
(!is_reference<_Dp>::value && is_convertible<_UDel, _Dp>::value)
>::type;
template <class _UDel>
using _EnableIfDeleterAssignable = typename enable_if<
is_assignable<_Dp&, _UDel&&>::value
>::type;
public:
template <bool _Dummy = true,
class = _EnableIfDeleterDefaultConstructible<_Dummy> >
_LIBCPP_INLINE_VISIBILITY
_LIBCPP_CONSTEXPR unique_ptr() _NOEXCEPT : __ptr_(pointer()) {}
template <bool _Dummy = true,
class = _EnableIfDeleterDefaultConstructible<_Dummy> >
_LIBCPP_INLINE_VISIBILITY
_LIBCPP_CONSTEXPR unique_ptr(nullptr_t) _NOEXCEPT : __ptr_(pointer()) {}
template <bool _Dummy = true,
class = _EnableIfDeleterDefaultConstructible<_Dummy> >
_LIBCPP_INLINE_VISIBILITY
explicit unique_ptr(pointer __p) _NOEXCEPT : __ptr_(__p) {}
template <bool _Dummy = true,
class = _EnableIfDeleterConstructible<_LValRefType<_Dummy> > >
_LIBCPP_INLINE_VISIBILITY
unique_ptr(pointer __p, _LValRefType<_Dummy> __d) _NOEXCEPT
: __ptr_(__p, __d) {}
template <bool _Dummy = true,
class = _EnableIfDeleterConstructible<_GoodRValRefType<_Dummy> > >
_LIBCPP_INLINE_VISIBILITY
unique_ptr(pointer __p, _GoodRValRefType<_Dummy> __d) _NOEXCEPT
: __ptr_(__p, _VSTD::move(__d)) {
static_assert(!is_reference<deleter_type>::value,
"rvalue deleter bound to reference");
}
template <bool _Dummy = true,
class = _EnableIfDeleterConstructible<_BadRValRefType<_Dummy> > >
_LIBCPP_INLINE_VISIBILITY
unique_ptr(pointer __p, _BadRValRefType<_Dummy> __d) = delete;
_LIBCPP_INLINE_VISIBILITY
unique_ptr(unique_ptr&& __u) _NOEXCEPT
: __ptr_(__u.release(), _VSTD::forward<deleter_type>(__u.get_deleter())) {
}
template <class _Up, class _Ep,
class = _EnableIfMoveConvertible<unique_ptr<_Up, _Ep>, _Up>,
class = _EnableIfDeleterConvertible<_Ep>
>
_LIBCPP_INLINE_VISIBILITY
unique_ptr(unique_ptr<_Up, _Ep>&& __u) _NOEXCEPT
: __ptr_(__u.release(), _VSTD::forward<_Ep>(__u.get_deleter())) {}
#if _LIBCPP_STD_VER <= 14 || defined(_LIBCPP_ENABLE_CXX17_REMOVED_AUTO_PTR)
template <class _Up>
_LIBCPP_INLINE_VISIBILITY
unique_ptr(auto_ptr<_Up>&& __p,
typename enable_if<is_convertible<_Up*, _Tp*>::value &&
is_same<_Dp, default_delete<_Tp> >::value,
__nat>::type = __nat()) _NOEXCEPT
: __ptr_(__p.release()) {}
#endif
_LIBCPP_INLINE_VISIBILITY
unique_ptr& operator=(unique_ptr&& __u) _NOEXCEPT {
reset(__u.release());
__ptr_.second() = _VSTD::forward<deleter_type>(__u.get_deleter());
return *this;
}
template <class _Up, class _Ep,
class = _EnableIfMoveConvertible<unique_ptr<_Up, _Ep>, _Up>,
class = _EnableIfDeleterAssignable<_Ep>
>
_LIBCPP_INLINE_VISIBILITY
unique_ptr& operator=(unique_ptr<_Up, _Ep>&& __u) _NOEXCEPT {
reset(__u.release());
__ptr_.second() = _VSTD::forward<_Ep>(__u.get_deleter());
return *this;
}
#if _LIBCPP_STD_VER <= 14 || defined(_LIBCPP_ENABLE_CXX17_REMOVED_AUTO_PTR)
template <class _Up>
_LIBCPP_INLINE_VISIBILITY
typename enable_if<is_convertible<_Up*, _Tp*>::value &&
is_same<_Dp, default_delete<_Tp> >::value,
unique_ptr&>::type
operator=(auto_ptr<_Up> __p) {
reset(__p.release());
return *this;
}
#endif
#ifdef _LIBCPP_CXX03_LANG
unique_ptr(unique_ptr const&) = delete;
unique_ptr& operator=(unique_ptr const&) = delete;
#endif
_LIBCPP_INLINE_VISIBILITY
~unique_ptr() { reset(); }
_LIBCPP_INLINE_VISIBILITY
unique_ptr& operator=(nullptr_t) _NOEXCEPT {
reset();
return *this;
}
_LIBCPP_INLINE_VISIBILITY
typename add_lvalue_reference<_Tp>::type
operator*() const {
return *__ptr_.first();
}
_LIBCPP_INLINE_VISIBILITY
pointer operator->() const _NOEXCEPT {
return __ptr_.first();
}
_LIBCPP_INLINE_VISIBILITY
pointer get() const _NOEXCEPT {
return __ptr_.first();
}
_LIBCPP_INLINE_VISIBILITY
deleter_type& get_deleter() _NOEXCEPT {
return __ptr_.second();
}
_LIBCPP_INLINE_VISIBILITY
const deleter_type& get_deleter() const _NOEXCEPT {
return __ptr_.second();
}
_LIBCPP_INLINE_VISIBILITY
_LIBCPP_EXPLICIT operator bool() const _NOEXCEPT {
return __ptr_.first() != nullptr;
}
_LIBCPP_INLINE_VISIBILITY
pointer release() _NOEXCEPT {
pointer __t = __ptr_.first();
__ptr_.first() = pointer();
return __t;
}
_LIBCPP_INLINE_VISIBILITY
void reset(pointer __p = pointer()) _NOEXCEPT {
pointer __tmp = __ptr_.first();
__ptr_.first() = __p;
if (__tmp)
__ptr_.second()(__tmp);
}
_LIBCPP_INLINE_VISIBILITY
void swap(unique_ptr& __u) _NOEXCEPT {
__ptr_.swap(__u.__ptr_);
}
};
template <class _Tp, class _Dp>
class _LIBCPP_TEMPLATE_VIS unique_ptr<_Tp[], _Dp> {
public:
typedef _Tp element_type;
typedef _Dp deleter_type;
typedef typename __pointer_type<_Tp, deleter_type>::type pointer;
private:
__compressed_pair<pointer, deleter_type> __ptr_;
template <class _From>
struct _CheckArrayPointerConversion : is_same<_From, pointer> {};
template <class _FromElem>
struct _CheckArrayPointerConversion<_FromElem*>
: integral_constant<bool,
is_same<_FromElem*, pointer>::value ||
(is_same<pointer, element_type*>::value &&
is_convertible<_FromElem(*)[], element_type(*)[]>::value)
>
{};
typedef __unique_ptr_deleter_sfinae<_Dp> _DeleterSFINAE;
template <bool _Dummy>
using _LValRefType _LIBCPP_NODEBUG_TYPE =
typename __dependent_type<_DeleterSFINAE, _Dummy>::__lval_ref_type;
template <bool _Dummy>
using _GoodRValRefType _LIBCPP_NODEBUG_TYPE =
typename __dependent_type<_DeleterSFINAE, _Dummy>::__good_rval_ref_type;
template <bool _Dummy>
using _BadRValRefType _LIBCPP_NODEBUG_TYPE =
typename __dependent_type<_DeleterSFINAE, _Dummy>::__bad_rval_ref_type;
template <bool _Dummy, class _Deleter = typename __dependent_type<
__identity<deleter_type>, _Dummy>::type>
using _EnableIfDeleterDefaultConstructible _LIBCPP_NODEBUG_TYPE =
typename enable_if<is_default_constructible<_Deleter>::value &&
!is_pointer<_Deleter>::value>::type;
template <class _ArgType>
using _EnableIfDeleterConstructible _LIBCPP_NODEBUG_TYPE =
typename enable_if<is_constructible<deleter_type, _ArgType>::value>::type;
template <class _Pp>
using _EnableIfPointerConvertible _LIBCPP_NODEBUG_TYPE = typename enable_if<
_CheckArrayPointerConversion<_Pp>::value
>::type;
template <class _UPtr, class _Up,
class _ElemT = typename _UPtr::element_type>
using _EnableIfMoveConvertible _LIBCPP_NODEBUG_TYPE = typename enable_if<
is_array<_Up>::value &&
is_same<pointer, element_type*>::value &&
is_same<typename _UPtr::pointer, _ElemT*>::value &&
is_convertible<_ElemT(*)[], element_type(*)[]>::value
>::type;
template <class _UDel>
using _EnableIfDeleterConvertible _LIBCPP_NODEBUG_TYPE = typename enable_if<
(is_reference<_Dp>::value && is_same<_Dp, _UDel>::value) ||
(!is_reference<_Dp>::value && is_convertible<_UDel, _Dp>::value)
>::type;
template <class _UDel>
using _EnableIfDeleterAssignable _LIBCPP_NODEBUG_TYPE = typename enable_if<
is_assignable<_Dp&, _UDel&&>::value
>::type;
public:
template <bool _Dummy = true,
class = _EnableIfDeleterDefaultConstructible<_Dummy> >
_LIBCPP_INLINE_VISIBILITY
_LIBCPP_CONSTEXPR unique_ptr() _NOEXCEPT : __ptr_(pointer()) {}
template <bool _Dummy = true,
class = _EnableIfDeleterDefaultConstructible<_Dummy> >
_LIBCPP_INLINE_VISIBILITY
_LIBCPP_CONSTEXPR unique_ptr(nullptr_t) _NOEXCEPT : __ptr_(pointer()) {}
template <class _Pp, bool _Dummy = true,
class = _EnableIfDeleterDefaultConstructible<_Dummy>,
class = _EnableIfPointerConvertible<_Pp> >
_LIBCPP_INLINE_VISIBILITY
explicit unique_ptr(_Pp __p) _NOEXCEPT
: __ptr_(__p) {}
template <class _Pp, bool _Dummy = true,
class = _EnableIfDeleterConstructible<_LValRefType<_Dummy> >,
class = _EnableIfPointerConvertible<_Pp> >
_LIBCPP_INLINE_VISIBILITY
unique_ptr(_Pp __p, _LValRefType<_Dummy> __d) _NOEXCEPT
: __ptr_(__p, __d) {}
template <bool _Dummy = true,
class = _EnableIfDeleterConstructible<_LValRefType<_Dummy> > >
_LIBCPP_INLINE_VISIBILITY
unique_ptr(nullptr_t, _LValRefType<_Dummy> __d) _NOEXCEPT
: __ptr_(nullptr, __d) {}
template <class _Pp, bool _Dummy = true,
class = _EnableIfDeleterConstructible<_GoodRValRefType<_Dummy> >,
class = _EnableIfPointerConvertible<_Pp> >
_LIBCPP_INLINE_VISIBILITY
unique_ptr(_Pp __p, _GoodRValRefType<_Dummy> __d) _NOEXCEPT
: __ptr_(__p, _VSTD::move(__d)) {
static_assert(!is_reference<deleter_type>::value,
"rvalue deleter bound to reference");
}
template <bool _Dummy = true,
class = _EnableIfDeleterConstructible<_GoodRValRefType<_Dummy> > >
_LIBCPP_INLINE_VISIBILITY
unique_ptr(nullptr_t, _GoodRValRefType<_Dummy> __d) _NOEXCEPT
: __ptr_(nullptr, _VSTD::move(__d)) {
static_assert(!is_reference<deleter_type>::value,
"rvalue deleter bound to reference");
}
template <class _Pp, bool _Dummy = true,
class = _EnableIfDeleterConstructible<_BadRValRefType<_Dummy> >,
class = _EnableIfPointerConvertible<_Pp> >
_LIBCPP_INLINE_VISIBILITY
unique_ptr(_Pp __p, _BadRValRefType<_Dummy> __d) = delete;
_LIBCPP_INLINE_VISIBILITY
unique_ptr(unique_ptr&& __u) _NOEXCEPT
: __ptr_(__u.release(), _VSTD::forward<deleter_type>(__u.get_deleter())) {
}
_LIBCPP_INLINE_VISIBILITY
unique_ptr& operator=(unique_ptr&& __u) _NOEXCEPT {
reset(__u.release());
__ptr_.second() = _VSTD::forward<deleter_type>(__u.get_deleter());
return *this;
}
template <class _Up, class _Ep,
class = _EnableIfMoveConvertible<unique_ptr<_Up, _Ep>, _Up>,
class = _EnableIfDeleterConvertible<_Ep>
>
_LIBCPP_INLINE_VISIBILITY
unique_ptr(unique_ptr<_Up, _Ep>&& __u) _NOEXCEPT
: __ptr_(__u.release(), _VSTD::forward<_Ep>(__u.get_deleter())) {
}
template <class _Up, class _Ep,
class = _EnableIfMoveConvertible<unique_ptr<_Up, _Ep>, _Up>,
class = _EnableIfDeleterAssignable<_Ep>
>
_LIBCPP_INLINE_VISIBILITY
unique_ptr&
operator=(unique_ptr<_Up, _Ep>&& __u) _NOEXCEPT {
reset(__u.release());
__ptr_.second() = _VSTD::forward<_Ep>(__u.get_deleter());
return *this;
}
#ifdef _LIBCPP_CXX03_LANG
unique_ptr(unique_ptr const&) = delete;
unique_ptr& operator=(unique_ptr const&) = delete;
#endif
public:
_LIBCPP_INLINE_VISIBILITY
~unique_ptr() { reset(); }
_LIBCPP_INLINE_VISIBILITY
unique_ptr& operator=(nullptr_t) _NOEXCEPT {
reset();
return *this;
}
_LIBCPP_INLINE_VISIBILITY
typename add_lvalue_reference<_Tp>::type
operator[](size_t __i) const {
return __ptr_.first()[__i];
}
_LIBCPP_INLINE_VISIBILITY
pointer get() const _NOEXCEPT {
return __ptr_.first();
}
_LIBCPP_INLINE_VISIBILITY
deleter_type& get_deleter() _NOEXCEPT {
return __ptr_.second();
}
_LIBCPP_INLINE_VISIBILITY
const deleter_type& get_deleter() const _NOEXCEPT {
return __ptr_.second();
}
_LIBCPP_INLINE_VISIBILITY
_LIBCPP_EXPLICIT operator bool() const _NOEXCEPT {
return __ptr_.first() != nullptr;
}
_LIBCPP_INLINE_VISIBILITY
pointer release() _NOEXCEPT {
pointer __t = __ptr_.first();
__ptr_.first() = pointer();
return __t;
}
template <class _Pp>
_LIBCPP_INLINE_VISIBILITY
typename enable_if<
_CheckArrayPointerConversion<_Pp>::value
>::type
reset(_Pp __p) _NOEXCEPT {
pointer __tmp = __ptr_.first();
__ptr_.first() = __p;
if (__tmp)
__ptr_.second()(__tmp);
}
_LIBCPP_INLINE_VISIBILITY
void reset(nullptr_t = nullptr) _NOEXCEPT {
pointer __tmp = __ptr_.first();
__ptr_.first() = nullptr;
if (__tmp)
__ptr_.second()(__tmp);
}
_LIBCPP_INLINE_VISIBILITY
void swap(unique_ptr& __u) _NOEXCEPT {
__ptr_.swap(__u.__ptr_);
}
};
template <class _Tp, class _Dp>
inline _LIBCPP_INLINE_VISIBILITY
typename enable_if<
__is_swappable<_Dp>::value,
void
>::type
swap(unique_ptr<_Tp, _Dp>& __x, unique_ptr<_Tp, _Dp>& __y) _NOEXCEPT {__x.swap(__y);}
template <class _T1, class _D1, class _T2, class _D2>
inline _LIBCPP_INLINE_VISIBILITY
bool
operator==(const unique_ptr<_T1, _D1>& __x, const unique_ptr<_T2, _D2>& __y) {return __x.get() == __y.get();}
template <class _T1, class _D1, class _T2, class _D2>
inline _LIBCPP_INLINE_VISIBILITY
bool
operator!=(const unique_ptr<_T1, _D1>& __x, const unique_ptr<_T2, _D2>& __y) {return !(__x == __y);}
template <class _T1, class _D1, class _T2, class _D2>
inline _LIBCPP_INLINE_VISIBILITY
bool
operator< (const unique_ptr<_T1, _D1>& __x, const unique_ptr<_T2, _D2>& __y)
{
typedef typename unique_ptr<_T1, _D1>::pointer _P1;
typedef typename unique_ptr<_T2, _D2>::pointer _P2;
typedef typename common_type<_P1, _P2>::type _Vp;
return less<_Vp>()(__x.get(), __y.get());
}
template <class _T1, class _D1, class _T2, class _D2>
inline _LIBCPP_INLINE_VISIBILITY
bool
operator> (const unique_ptr<_T1, _D1>& __x, const unique_ptr<_T2, _D2>& __y) {return __y < __x;}
template <class _T1, class _D1, class _T2, class _D2>
inline _LIBCPP_INLINE_VISIBILITY
bool
operator<=(const unique_ptr<_T1, _D1>& __x, const unique_ptr<_T2, _D2>& __y) {return !(__y < __x);}
template <class _T1, class _D1, class _T2, class _D2>
inline _LIBCPP_INLINE_VISIBILITY
bool
operator>=(const unique_ptr<_T1, _D1>& __x, const unique_ptr<_T2, _D2>& __y) {return !(__x < __y);}
template <class _T1, class _D1>
inline _LIBCPP_INLINE_VISIBILITY
bool
operator==(const unique_ptr<_T1, _D1>& __x, nullptr_t) _NOEXCEPT
{
return !__x;
}
template <class _T1, class _D1>
inline _LIBCPP_INLINE_VISIBILITY
bool
operator==(nullptr_t, const unique_ptr<_T1, _D1>& __x) _NOEXCEPT
{
return !__x;
}
template <class _T1, class _D1>
inline _LIBCPP_INLINE_VISIBILITY
bool
operator!=(const unique_ptr<_T1, _D1>& __x, nullptr_t) _NOEXCEPT
{
return static_cast<bool>(__x);
}
template <class _T1, class _D1>
inline _LIBCPP_INLINE_VISIBILITY
bool
operator!=(nullptr_t, const unique_ptr<_T1, _D1>& __x) _NOEXCEPT
{
return static_cast<bool>(__x);
}
template <class _T1, class _D1>
inline _LIBCPP_INLINE_VISIBILITY
bool
operator<(const unique_ptr<_T1, _D1>& __x, nullptr_t)
{
typedef typename unique_ptr<_T1, _D1>::pointer _P1;
return less<_P1>()(__x.get(), nullptr);
}
template <class _T1, class _D1>
inline _LIBCPP_INLINE_VISIBILITY
bool
operator<(nullptr_t, const unique_ptr<_T1, _D1>& __x)
{
typedef typename unique_ptr<_T1, _D1>::pointer _P1;
return less<_P1>()(nullptr, __x.get());
}
template <class _T1, class _D1>
inline _LIBCPP_INLINE_VISIBILITY
bool
operator>(const unique_ptr<_T1, _D1>& __x, nullptr_t)
{
return nullptr < __x;
}
template <class _T1, class _D1>
inline _LIBCPP_INLINE_VISIBILITY
bool
operator>(nullptr_t, const unique_ptr<_T1, _D1>& __x)
{
return __x < nullptr;
}
template <class _T1, class _D1>
inline _LIBCPP_INLINE_VISIBILITY
bool
operator<=(const unique_ptr<_T1, _D1>& __x, nullptr_t)
{
return !(nullptr < __x);
}
template <class _T1, class _D1>
inline _LIBCPP_INLINE_VISIBILITY
bool
operator<=(nullptr_t, const unique_ptr<_T1, _D1>& __x)
{
return !(__x < nullptr);
}
template <class _T1, class _D1>
inline _LIBCPP_INLINE_VISIBILITY
bool
operator>=(const unique_ptr<_T1, _D1>& __x, nullptr_t)
{
return !(__x < nullptr);
}
template <class _T1, class _D1>
inline _LIBCPP_INLINE_VISIBILITY
bool
operator>=(nullptr_t, const unique_ptr<_T1, _D1>& __x)
{
return !(nullptr < __x);
}
#if _LIBCPP_STD_VER > 11
template<class _Tp>
struct __unique_if
{
typedef unique_ptr<_Tp> __unique_single;
};
template<class _Tp>
struct __unique_if<_Tp[]>
{
typedef unique_ptr<_Tp[]> __unique_array_unknown_bound;
};
template<class _Tp, size_t _Np>
struct __unique_if<_Tp[_Np]>
{
typedef void __unique_array_known_bound;
};
template<class _Tp, class... _Args>
inline _LIBCPP_INLINE_VISIBILITY
typename __unique_if<_Tp>::__unique_single
make_unique(_Args&&... __args)
{
return unique_ptr<_Tp>(new _Tp(_VSTD::forward<_Args>(__args)...));
}
template<class _Tp>
inline _LIBCPP_INLINE_VISIBILITY
typename __unique_if<_Tp>::__unique_array_unknown_bound
make_unique(size_t __n)
{
typedef typename remove_extent<_Tp>::type _Up;
return unique_ptr<_Tp>(new _Up[__n]());
}
template<class _Tp, class... _Args>
typename __unique_if<_Tp>::__unique_array_known_bound
make_unique(_Args&&...) = delete;
#endif // _LIBCPP_STD_VER > 11
template <class _Tp, class _Dp>
#ifdef _LIBCPP_CXX03_LANG
struct _LIBCPP_TEMPLATE_VIS hash<unique_ptr<_Tp, _Dp> >
#else
struct _LIBCPP_TEMPLATE_VIS hash<__enable_hash_helper<
unique_ptr<_Tp, _Dp>, typename unique_ptr<_Tp, _Dp>::pointer> >
#endif
{
typedef unique_ptr<_Tp, _Dp> argument_type;
typedef size_t result_type;
_LIBCPP_INLINE_VISIBILITY
result_type operator()(const argument_type& __ptr) const
{
typedef typename argument_type::pointer pointer;
return hash<pointer>()(__ptr.get());
}
};
struct __destruct_n
{
private:
size_t __size_;
template <class _Tp>
_LIBCPP_INLINE_VISIBILITY void __process(_Tp* __p, false_type) _NOEXCEPT
{for (size_t __i = 0; __i < __size_; ++__i, ++__p) __p->~_Tp();}
template <class _Tp>
_LIBCPP_INLINE_VISIBILITY void __process(_Tp*, true_type) _NOEXCEPT
{}
_LIBCPP_INLINE_VISIBILITY void __incr(false_type) _NOEXCEPT
{++__size_;}
_LIBCPP_INLINE_VISIBILITY void __incr(true_type) _NOEXCEPT
{}
_LIBCPP_INLINE_VISIBILITY void __set(size_t __s, false_type) _NOEXCEPT
{__size_ = __s;}
_LIBCPP_INLINE_VISIBILITY void __set(size_t, true_type) _NOEXCEPT
{}
public:
_LIBCPP_INLINE_VISIBILITY explicit __destruct_n(size_t __s) _NOEXCEPT
: __size_(__s) {}
template <class _Tp>
_LIBCPP_INLINE_VISIBILITY void __incr(_Tp*) _NOEXCEPT
{__incr(integral_constant<bool, is_trivially_destructible<_Tp>::value>());}
template <class _Tp>
_LIBCPP_INLINE_VISIBILITY void __set(size_t __s, _Tp*) _NOEXCEPT
{__set(__s, integral_constant<bool, is_trivially_destructible<_Tp>::value>());}
template <class _Tp>
_LIBCPP_INLINE_VISIBILITY void operator()(_Tp* __p) _NOEXCEPT
{__process(__p, integral_constant<bool, is_trivially_destructible<_Tp>::value>());}
};
template <class _Alloc>
class __allocator_destructor
{
typedef _LIBCPP_NODEBUG_TYPE allocator_traits<_Alloc> __alloc_traits;
public:
typedef _LIBCPP_NODEBUG_TYPE typename __alloc_traits::pointer pointer;
typedef _LIBCPP_NODEBUG_TYPE typename __alloc_traits::size_type size_type;
private:
_Alloc& __alloc_;
size_type __s_;
public:
_LIBCPP_INLINE_VISIBILITY __allocator_destructor(_Alloc& __a, size_type __s)
_NOEXCEPT
: __alloc_(__a), __s_(__s) {}
_LIBCPP_INLINE_VISIBILITY
void operator()(pointer __p) _NOEXCEPT
{__alloc_traits::deallocate(__alloc_, __p, __s_);}
};
template <class _InputIterator, class _ForwardIterator>
_ForwardIterator
uninitialized_copy(_InputIterator __f, _InputIterator __l, _ForwardIterator __r)
{
typedef typename iterator_traits<_ForwardIterator>::value_type value_type;
#ifndef _LIBCPP_NO_EXCEPTIONS
_ForwardIterator __s = __r;
try
{
#endif
for (; __f != __l; ++__f, (void) ++__r)
::new (static_cast<void*>(_VSTD::addressof(*__r))) value_type(*__f);
#ifndef _LIBCPP_NO_EXCEPTIONS
}
catch (...)
{
for (; __s != __r; ++__s)
__s->~value_type();
throw;
}
#endif
return __r;
}
template <class _InputIterator, class _Size, class _ForwardIterator>
_ForwardIterator
uninitialized_copy_n(_InputIterator __f, _Size __n, _ForwardIterator __r)
{
typedef typename iterator_traits<_ForwardIterator>::value_type value_type;
#ifndef _LIBCPP_NO_EXCEPTIONS
_ForwardIterator __s = __r;
try
{
#endif
for (; __n > 0; ++__f, (void) ++__r, (void) --__n)
::new (static_cast<void*>(_VSTD::addressof(*__r))) value_type(*__f);
#ifndef _LIBCPP_NO_EXCEPTIONS
}
catch (...)
{
for (; __s != __r; ++__s)
__s->~value_type();
throw;
}
#endif
return __r;
}
template <class _ForwardIterator, class _Tp>
void
uninitialized_fill(_ForwardIterator __f, _ForwardIterator __l, const _Tp& __x)
{
typedef typename iterator_traits<_ForwardIterator>::value_type value_type;
#ifndef _LIBCPP_NO_EXCEPTIONS
_ForwardIterator __s = __f;
try
{
#endif
for (; __f != __l; ++__f)
::new (static_cast<void*>(_VSTD::addressof(*__f))) value_type(__x);
#ifndef _LIBCPP_NO_EXCEPTIONS
}
catch (...)
{
for (; __s != __f; ++__s)
__s->~value_type();
throw;
}
#endif
}
template <class _ForwardIterator, class _Size, class _Tp>
_ForwardIterator
uninitialized_fill_n(_ForwardIterator __f, _Size __n, const _Tp& __x)
{
typedef typename iterator_traits<_ForwardIterator>::value_type value_type;
#ifndef _LIBCPP_NO_EXCEPTIONS
_ForwardIterator __s = __f;
try
{
#endif
for (; __n > 0; ++__f, (void) --__n)
::new (static_cast<void*>(_VSTD::addressof(*__f))) value_type(__x);
#ifndef _LIBCPP_NO_EXCEPTIONS
}
catch (...)
{
for (; __s != __f; ++__s)
__s->~value_type();
throw;
}
#endif
return __f;
}
#if _LIBCPP_STD_VER > 14
template <class _Tp>
inline _LIBCPP_INLINE_VISIBILITY
void destroy_at(_Tp* __loc) {
_LIBCPP_ASSERT(__loc, "null pointer given to destroy_at");
__loc->~_Tp();
}
template <class _ForwardIterator>
inline _LIBCPP_INLINE_VISIBILITY
void destroy(_ForwardIterator __first, _ForwardIterator __last) {
for (; __first != __last; ++__first)
_VSTD::destroy_at(_VSTD::addressof(*__first));
}
template <class _ForwardIterator, class _Size>
inline _LIBCPP_INLINE_VISIBILITY
_ForwardIterator destroy_n(_ForwardIterator __first, _Size __n) {
for (; __n > 0; (void)++__first, --__n)
_VSTD::destroy_at(_VSTD::addressof(*__first));
return __first;
}
template <class _ForwardIterator>
inline _LIBCPP_INLINE_VISIBILITY
void uninitialized_default_construct(_ForwardIterator __first, _ForwardIterator __last) {
using _Vt = typename iterator_traits<_ForwardIterator>::value_type;
auto __idx = __first;
#ifndef _LIBCPP_NO_EXCEPTIONS
try {
#endif
for (; __idx != __last; ++__idx)
::new((void*)_VSTD::addressof(*__idx)) _Vt;
#ifndef _LIBCPP_NO_EXCEPTIONS
} catch (...) {
_VSTD::destroy(__first, __idx);
throw;
}
#endif
}
template <class _ForwardIterator, class _Size>
inline _LIBCPP_INLINE_VISIBILITY
_ForwardIterator uninitialized_default_construct_n(_ForwardIterator __first, _Size __n) {
using _Vt = typename iterator_traits<_ForwardIterator>::value_type;
auto __idx = __first;
#ifndef _LIBCPP_NO_EXCEPTIONS
try {
#endif
for (; __n > 0; (void)++__idx, --__n)
::new((void*)_VSTD::addressof(*__idx)) _Vt;
return __idx;
#ifndef _LIBCPP_NO_EXCEPTIONS
} catch (...) {
_VSTD::destroy(__first, __idx);
throw;
}
#endif
}
template <class _ForwardIterator>
inline _LIBCPP_INLINE_VISIBILITY
void uninitialized_value_construct(_ForwardIterator __first, _ForwardIterator __last) {
using _Vt = typename iterator_traits<_ForwardIterator>::value_type;
auto __idx = __first;
#ifndef _LIBCPP_NO_EXCEPTIONS
try {
#endif
for (; __idx != __last; ++__idx)
::new((void*)_VSTD::addressof(*__idx)) _Vt();
#ifndef _LIBCPP_NO_EXCEPTIONS
} catch (...) {
_VSTD::destroy(__first, __idx);
throw;
}
#endif
}
template <class _ForwardIterator, class _Size>
inline _LIBCPP_INLINE_VISIBILITY
_ForwardIterator uninitialized_value_construct_n(_ForwardIterator __first, _Size __n) {
using _Vt = typename iterator_traits<_ForwardIterator>::value_type;
auto __idx = __first;
#ifndef _LIBCPP_NO_EXCEPTIONS
try {
#endif
for (; __n > 0; (void)++__idx, --__n)
::new((void*)_VSTD::addressof(*__idx)) _Vt();
return __idx;
#ifndef _LIBCPP_NO_EXCEPTIONS
} catch (...) {
_VSTD::destroy(__first, __idx);
throw;
}
#endif
}
template <class _InputIt, class _ForwardIt>
inline _LIBCPP_INLINE_VISIBILITY
_ForwardIt uninitialized_move(_InputIt __first, _InputIt __last, _ForwardIt __first_res) {
using _Vt = typename iterator_traits<_ForwardIt>::value_type;
auto __idx = __first_res;
#ifndef _LIBCPP_NO_EXCEPTIONS
try {
#endif
for (; __first != __last; (void)++__idx, ++__first)
::new((void*)_VSTD::addressof(*__idx)) _Vt(std::move(*__first));
return __idx;
#ifndef _LIBCPP_NO_EXCEPTIONS
} catch (...) {
_VSTD::destroy(__first_res, __idx);
throw;
}
#endif
}
template <class _InputIt, class _Size, class _ForwardIt>
inline _LIBCPP_INLINE_VISIBILITY
pair<_InputIt, _ForwardIt>
uninitialized_move_n(_InputIt __first, _Size __n, _ForwardIt __first_res) {
using _Vt = typename iterator_traits<_ForwardIt>::value_type;
auto __idx = __first_res;
#ifndef _LIBCPP_NO_EXCEPTIONS
try {
#endif
for (; __n > 0; ++__idx, (void)++__first, --__n)
::new((void*)_VSTD::addressof(*__idx)) _Vt(std::move(*__first));
return {__first, __idx};
#ifndef _LIBCPP_NO_EXCEPTIONS
} catch (...) {
_VSTD::destroy(__first_res, __idx);
throw;
}
#endif
}
#endif // _LIBCPP_STD_VER > 14
// NOTE: Relaxed and acq/rel atomics (for increment and decrement respectively)
// should be sufficient for thread safety.
// See https://bugs.llvm.org/show_bug.cgi?id=22803
#if defined(__clang__) && __has_builtin(__atomic_add_fetch) \
&& defined(__ATOMIC_RELAXED) \
&& defined(__ATOMIC_ACQ_REL)
# define _LIBCPP_HAS_BUILTIN_ATOMIC_SUPPORT
#elif defined(_LIBCPP_COMPILER_GCC)
# define _LIBCPP_HAS_BUILTIN_ATOMIC_SUPPORT
#endif
template <class _Tp>
inline _LIBCPP_INLINE_VISIBILITY _Tp
__libcpp_atomic_refcount_increment(_Tp& __t) _NOEXCEPT
{
#if defined(_LIBCPP_HAS_BUILTIN_ATOMIC_SUPPORT) && !defined(_LIBCPP_HAS_NO_THREADS)
return __atomic_add_fetch(&__t, 1, __ATOMIC_RELAXED);
#else
return __t += 1;
#endif
}
template <class _Tp>
inline _LIBCPP_INLINE_VISIBILITY _Tp
__libcpp_atomic_refcount_decrement(_Tp& __t) _NOEXCEPT
{
#if defined(_LIBCPP_HAS_BUILTIN_ATOMIC_SUPPORT) && !defined(_LIBCPP_HAS_NO_THREADS)
return __atomic_add_fetch(&__t, -1, __ATOMIC_ACQ_REL);
#else
return __t -= 1;
#endif
}
class _LIBCPP_EXCEPTION_ABI bad_weak_ptr
: public std::exception
{
public:
virtual ~bad_weak_ptr() _NOEXCEPT;
virtual const char* what() const _NOEXCEPT;
};
_LIBCPP_NORETURN inline _LIBCPP_INLINE_VISIBILITY
void __throw_bad_weak_ptr()
{
#ifndef _LIBCPP_NO_EXCEPTIONS
throw bad_weak_ptr();
#else
_VSTD::abort();
#endif
}
template<class _Tp> class _LIBCPP_TEMPLATE_VIS weak_ptr;
class _LIBCPP_TYPE_VIS __shared_count
{
__shared_count(const __shared_count&);
__shared_count& operator=(const __shared_count&);
protected:
long __shared_owners_;
virtual ~__shared_count();
private:
virtual void __on_zero_shared() _NOEXCEPT = 0;
public:
_LIBCPP_INLINE_VISIBILITY
explicit __shared_count(long __refs = 0) _NOEXCEPT
: __shared_owners_(__refs) {}
#if defined(_LIBCPP_BUILDING_LIBRARY) && \
defined(_LIBCPP_DEPRECATED_ABI_LEGACY_LIBRARY_DEFINITIONS_FOR_INLINE_FUNCTIONS)
void __add_shared() _NOEXCEPT;
bool __release_shared() _NOEXCEPT;
#else
_LIBCPP_INLINE_VISIBILITY
void __add_shared() _NOEXCEPT {
__libcpp_atomic_refcount_increment(__shared_owners_);
}
_LIBCPP_INLINE_VISIBILITY
bool __release_shared() _NOEXCEPT {
if (__libcpp_atomic_refcount_decrement(__shared_owners_) == -1) {
__on_zero_shared();
return true;
}
return false;
}
#endif
_LIBCPP_INLINE_VISIBILITY
long use_count() const _NOEXCEPT {
return __libcpp_relaxed_load(&__shared_owners_) + 1;
}
};
class _LIBCPP_TYPE_VIS __shared_weak_count
: private __shared_count
{
long __shared_weak_owners_;
public:
_LIBCPP_INLINE_VISIBILITY
explicit __shared_weak_count(long __refs = 0) _NOEXCEPT
: __shared_count(__refs),
__shared_weak_owners_(__refs) {}
protected:
virtual ~__shared_weak_count();
public:
#if defined(_LIBCPP_BUILDING_LIBRARY) && \
defined(_LIBCPP_DEPRECATED_ABI_LEGACY_LIBRARY_DEFINITIONS_FOR_INLINE_FUNCTIONS)
void __add_shared() _NOEXCEPT;
void __add_weak() _NOEXCEPT;
void __release_shared() _NOEXCEPT;
#else
_LIBCPP_INLINE_VISIBILITY
void __add_shared() _NOEXCEPT {
__shared_count::__add_shared();
}
_LIBCPP_INLINE_VISIBILITY
void __add_weak() _NOEXCEPT {
__libcpp_atomic_refcount_increment(__shared_weak_owners_);
}
_LIBCPP_INLINE_VISIBILITY
void __release_shared() _NOEXCEPT {
if (__shared_count::__release_shared())
__release_weak();
}
#endif
void __release_weak() _NOEXCEPT;
_LIBCPP_INLINE_VISIBILITY
long use_count() const _NOEXCEPT {return __shared_count::use_count();}
__shared_weak_count* lock() _NOEXCEPT;
// Define the function out only if we build static libc++ without RTTI.
// Otherwise we may break clients who need to compile their projects with
// -fno-rtti and yet link against a libc++.dylib compiled
// without -fno-rtti.
#if !defined(_LIBCPP_NO_RTTI) || !defined(_LIBCPP_BUILD_STATIC)
virtual const void* __get_deleter(const type_info&) const _NOEXCEPT;
#endif
private:
virtual void __on_zero_shared_weak() _NOEXCEPT = 0;
};
template <class _Tp, class _Dp, class _Alloc>
class __shared_ptr_pointer
: public __shared_weak_count
{
__compressed_pair<__compressed_pair<_Tp, _Dp>, _Alloc> __data_;
public:
_LIBCPP_INLINE_VISIBILITY
__shared_ptr_pointer(_Tp __p, _Dp __d, _Alloc __a)
: __data_(__compressed_pair<_Tp, _Dp>(__p, _VSTD::move(__d)), _VSTD::move(__a)) {}
#ifndef _LIBCPP_NO_RTTI
virtual const void* __get_deleter(const type_info&) const _NOEXCEPT;
#endif
private:
virtual void __on_zero_shared() _NOEXCEPT;
virtual void __on_zero_shared_weak() _NOEXCEPT;
};
#ifndef _LIBCPP_NO_RTTI
template <class _Tp, class _Dp, class _Alloc>
const void*
__shared_ptr_pointer<_Tp, _Dp, _Alloc>::__get_deleter(const type_info& __t) const _NOEXCEPT
{
return __t == typeid(_Dp) ? _VSTD::addressof(__data_.first().second()) : nullptr;
}
#endif // _LIBCPP_NO_RTTI
template <class _Tp, class _Dp, class _Alloc>
void
__shared_ptr_pointer<_Tp, _Dp, _Alloc>::__on_zero_shared() _NOEXCEPT
{
__data_.first().second()(__data_.first().first());
__data_.first().second().~_Dp();
}
template <class _Tp, class _Dp, class _Alloc>
void
__shared_ptr_pointer<_Tp, _Dp, _Alloc>::__on_zero_shared_weak() _NOEXCEPT
{
typedef typename __allocator_traits_rebind<_Alloc, __shared_ptr_pointer>::type _Al;
typedef allocator_traits<_Al> _ATraits;
typedef pointer_traits<typename _ATraits::pointer> _PTraits;
_Al __a(__data_.second());
__data_.second().~_Alloc();
__a.deallocate(_PTraits::pointer_to(*this), 1);
}
template <class _Tp, class _Alloc>
class __shared_ptr_emplace
: public __shared_weak_count
{
__compressed_pair<_Alloc, _Tp> __data_;
public:
#ifndef _LIBCPP_HAS_NO_VARIADICS
_LIBCPP_INLINE_VISIBILITY
__shared_ptr_emplace(_Alloc __a)
: __data_(_VSTD::move(__a)) {}
template <class ..._Args>
_LIBCPP_INLINE_VISIBILITY
__shared_ptr_emplace(_Alloc __a, _Args&& ...__args)
: __data_(piecewise_construct, _VSTD::forward_as_tuple(__a),
_VSTD::forward_as_tuple(_VSTD::forward<_Args>(__args)...)) {}
#else // _LIBCPP_HAS_NO_VARIADICS
_LIBCPP_INLINE_VISIBILITY
__shared_ptr_emplace(_Alloc __a)
: __data_(__a) {}
template <class _A0>
_LIBCPP_INLINE_VISIBILITY
__shared_ptr_emplace(_Alloc __a, _A0& __a0)
: __data_(__a, _Tp(__a0)) {}
template <class _A0, class _A1>
_LIBCPP_INLINE_VISIBILITY
__shared_ptr_emplace(_Alloc __a, _A0& __a0, _A1& __a1)
: __data_(__a, _Tp(__a0, __a1)) {}
template <class _A0, class _A1, class _A2>
_LIBCPP_INLINE_VISIBILITY
__shared_ptr_emplace(_Alloc __a, _A0& __a0, _A1& __a1, _A2& __a2)
: __data_(__a, _Tp(__a0, __a1, __a2)) {}
#endif // _LIBCPP_HAS_NO_VARIADICS
private:
virtual void __on_zero_shared() _NOEXCEPT;
virtual void __on_zero_shared_weak() _NOEXCEPT;
public:
_LIBCPP_INLINE_VISIBILITY
_Tp* get() _NOEXCEPT {return _VSTD::addressof(__data_.second());}
};
template <class _Tp, class _Alloc>
void
__shared_ptr_emplace<_Tp, _Alloc>::__on_zero_shared() _NOEXCEPT
{
__data_.second().~_Tp();
}
template <class _Tp, class _Alloc>
void
__shared_ptr_emplace<_Tp, _Alloc>::__on_zero_shared_weak() _NOEXCEPT
{
typedef typename __allocator_traits_rebind<_Alloc, __shared_ptr_emplace>::type _Al;
typedef allocator_traits<_Al> _ATraits;
typedef pointer_traits<typename _ATraits::pointer> _PTraits;
_Al __a(__data_.first());
__data_.first().~_Alloc();
__a.deallocate(_PTraits::pointer_to(*this), 1);
}
struct __shared_ptr_dummy_rebind_allocator_type;
template <>
class _LIBCPP_TEMPLATE_VIS allocator<__shared_ptr_dummy_rebind_allocator_type>
{
public:
template <class _Other>
struct rebind
{
typedef allocator<_Other> other;
};
};
template<class _Tp> class _LIBCPP_TEMPLATE_VIS enable_shared_from_this;
template<class _Tp>
class _LIBCPP_TEMPLATE_VIS shared_ptr
{
public:
typedef _Tp element_type;
#if _LIBCPP_STD_VER > 14
typedef weak_ptr<_Tp> weak_type;
#endif
private:
element_type* __ptr_;
__shared_weak_count* __cntrl_;
struct __nat {int __for_bool_;};
public:
_LIBCPP_INLINE_VISIBILITY
_LIBCPP_CONSTEXPR shared_ptr() _NOEXCEPT;
_LIBCPP_INLINE_VISIBILITY
_LIBCPP_CONSTEXPR shared_ptr(nullptr_t) _NOEXCEPT;
template<class _Yp>
explicit shared_ptr(_Yp* __p,
typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type = __nat());
template<class _Yp, class _Dp>
shared_ptr(_Yp* __p, _Dp __d,
typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type = __nat());
template<class _Yp, class _Dp, class _Alloc>
shared_ptr(_Yp* __p, _Dp __d, _Alloc __a,
typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type = __nat());
template <class _Dp> shared_ptr(nullptr_t __p, _Dp __d);
template <class _Dp, class _Alloc> shared_ptr(nullptr_t __p, _Dp __d, _Alloc __a);
template<class _Yp> _LIBCPP_INLINE_VISIBILITY shared_ptr(const shared_ptr<_Yp>& __r, element_type* __p) _NOEXCEPT;
_LIBCPP_INLINE_VISIBILITY
shared_ptr(const shared_ptr& __r) _NOEXCEPT;
template<class _Yp>
_LIBCPP_INLINE_VISIBILITY
shared_ptr(const shared_ptr<_Yp>& __r,
typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type = __nat())
_NOEXCEPT;
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
_LIBCPP_INLINE_VISIBILITY
shared_ptr(shared_ptr&& __r) _NOEXCEPT;
template<class _Yp> _LIBCPP_INLINE_VISIBILITY shared_ptr(shared_ptr<_Yp>&& __r,
typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type = __nat())
_NOEXCEPT;
#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
template<class _Yp> explicit shared_ptr(const weak_ptr<_Yp>& __r,
typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type= __nat());
#if _LIBCPP_STD_VER <= 14 || defined(_LIBCPP_ENABLE_CXX17_REMOVED_AUTO_PTR)
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
template<class _Yp>
shared_ptr(auto_ptr<_Yp>&& __r,
typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type = __nat());
#else
template<class _Yp>
shared_ptr(auto_ptr<_Yp> __r,
typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type = __nat());
#endif
#endif
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
template <class _Yp, class _Dp>
shared_ptr(unique_ptr<_Yp, _Dp>&&,
typename enable_if
<
!is_lvalue_reference<_Dp>::value &&
!is_array<_Yp>::value &&
is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value,
__nat
>::type = __nat());
template <class _Yp, class _Dp>
shared_ptr(unique_ptr<_Yp, _Dp>&&,
typename enable_if
<
is_lvalue_reference<_Dp>::value &&
!is_array<_Yp>::value &&
is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value,
__nat
>::type = __nat());
#else // _LIBCPP_HAS_NO_RVALUE_REFERENCES
template <class _Yp, class _Dp>
shared_ptr(unique_ptr<_Yp, _Dp>,
typename enable_if
<
!is_lvalue_reference<_Dp>::value &&
!is_array<_Yp>::value &&
is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value,
__nat
>::type = __nat());
template <class _Yp, class _Dp>
shared_ptr(unique_ptr<_Yp, _Dp>,
typename enable_if
<
is_lvalue_reference<_Dp>::value &&
!is_array<_Yp>::value &&
is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value,
__nat
>::type = __nat());
#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
~shared_ptr();
_LIBCPP_INLINE_VISIBILITY
shared_ptr& operator=(const shared_ptr& __r) _NOEXCEPT;
template<class _Yp>
typename enable_if
<
is_convertible<_Yp*, element_type*>::value,
shared_ptr&
>::type
_LIBCPP_INLINE_VISIBILITY
operator=(const shared_ptr<_Yp>& __r) _NOEXCEPT;
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
_LIBCPP_INLINE_VISIBILITY
shared_ptr& operator=(shared_ptr&& __r) _NOEXCEPT;
template<class _Yp>
typename enable_if
<
is_convertible<_Yp*, element_type*>::value,
shared_ptr<_Tp>&
>::type
_LIBCPP_INLINE_VISIBILITY
operator=(shared_ptr<_Yp>&& __r);
#if _LIBCPP_STD_VER <= 14 || defined(_LIBCPP_ENABLE_CXX17_REMOVED_AUTO_PTR)
template<class _Yp>
_LIBCPP_INLINE_VISIBILITY
typename enable_if
<
!is_array<_Yp>::value &&
is_convertible<_Yp*, element_type*>::value,
shared_ptr
>::type&
operator=(auto_ptr<_Yp>&& __r);
#endif
#else // _LIBCPP_HAS_NO_RVALUE_REFERENCES
#if _LIBCPP_STD_VER <= 14 || defined(_LIBCPP_ENABLE_CXX17_REMOVED_AUTO_PTR)
template<class _Yp>
_LIBCPP_INLINE_VISIBILITY
typename enable_if
<
!is_array<_Yp>::value &&
is_convertible<_Yp*, element_type*>::value,
shared_ptr&
>::type
operator=(auto_ptr<_Yp> __r);
#endif
#endif
template <class _Yp, class _Dp>
typename enable_if
<
!is_array<_Yp>::value &&
is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value,
shared_ptr&
>::type
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
_LIBCPP_INLINE_VISIBILITY
operator=(unique_ptr<_Yp, _Dp>&& __r);
#else // _LIBCPP_HAS_NO_RVALUE_REFERENCES
_LIBCPP_INLINE_VISIBILITY
operator=(unique_ptr<_Yp, _Dp> __r);
#endif
_LIBCPP_INLINE_VISIBILITY
void swap(shared_ptr& __r) _NOEXCEPT;
_LIBCPP_INLINE_VISIBILITY
void reset() _NOEXCEPT;
template<class _Yp>
typename enable_if
<
is_convertible<_Yp*, element_type*>::value,
void
>::type
_LIBCPP_INLINE_VISIBILITY
reset(_Yp* __p);
template<class _Yp, class _Dp>
typename enable_if
<
is_convertible<_Yp*, element_type*>::value,
void
>::type
_LIBCPP_INLINE_VISIBILITY
reset(_Yp* __p, _Dp __d);
template<class _Yp, class _Dp, class _Alloc>
typename enable_if
<
is_convertible<_Yp*, element_type*>::value,
void
>::type
_LIBCPP_INLINE_VISIBILITY
reset(_Yp* __p, _Dp __d, _Alloc __a);
_LIBCPP_INLINE_VISIBILITY
element_type* get() const _NOEXCEPT {return __ptr_;}
_LIBCPP_INLINE_VISIBILITY
typename add_lvalue_reference<element_type>::type operator*() const _NOEXCEPT
{return *__ptr_;}
_LIBCPP_INLINE_VISIBILITY
element_type* operator->() const _NOEXCEPT {return __ptr_;}
_LIBCPP_INLINE_VISIBILITY
long use_count() const _NOEXCEPT {return __cntrl_ ? __cntrl_->use_count() : 0;}
_LIBCPP_INLINE_VISIBILITY
bool unique() const _NOEXCEPT {return use_count() == 1;}
_LIBCPP_INLINE_VISIBILITY
_LIBCPP_EXPLICIT operator bool() const _NOEXCEPT {return get() != 0;}
template <class _Up>
_LIBCPP_INLINE_VISIBILITY
bool owner_before(shared_ptr<_Up> const& __p) const _NOEXCEPT
{return __cntrl_ < __p.__cntrl_;}
template <class _Up>
_LIBCPP_INLINE_VISIBILITY
bool owner_before(weak_ptr<_Up> const& __p) const _NOEXCEPT
{return __cntrl_ < __p.__cntrl_;}
_LIBCPP_INLINE_VISIBILITY
bool
__owner_equivalent(const shared_ptr& __p) const
{return __cntrl_ == __p.__cntrl_;}
#ifndef _LIBCPP_NO_RTTI
template <class _Dp>
_LIBCPP_INLINE_VISIBILITY
_Dp* __get_deleter() const _NOEXCEPT
{return static_cast<_Dp*>(__cntrl_
? const_cast<void *>(__cntrl_->__get_deleter(typeid(_Dp)))
: nullptr);}
#endif // _LIBCPP_NO_RTTI
template<class _Yp, class _CntrlBlk>
static shared_ptr<_Tp>
__create_with_control_block(_Yp* __p, _CntrlBlk* __cntrl)
{
shared_ptr<_Tp> __r;
__r.__ptr_ = __p;
__r.__cntrl_ = __cntrl;
__r.__enable_weak_this(__r.__ptr_, __r.__ptr_);
return __r;
}
template<class _Alloc, class ..._Args>
static
shared_ptr<_Tp>
allocate_shared(const _Alloc& __a, _Args&& ...__args);
private:
template <class _Yp, bool = is_function<_Yp>::value>
struct __shared_ptr_default_allocator
{
typedef allocator<_Yp> type;
};
template <class _Yp>
struct __shared_ptr_default_allocator<_Yp, true>
{
typedef allocator<__shared_ptr_dummy_rebind_allocator_type> type;
};
template <class _Yp, class _OrigPtr>
_LIBCPP_INLINE_VISIBILITY
typename enable_if<is_convertible<_OrigPtr*,
const enable_shared_from_this<_Yp>*
>::value,
void>::type
__enable_weak_this(const enable_shared_from_this<_Yp>* __e,
_OrigPtr* __ptr) _NOEXCEPT
{
typedef typename remove_cv<_Yp>::type _RawYp;
if (__e && __e->__weak_this_.expired())
{
__e->__weak_this_ = shared_ptr<_RawYp>(*this,
const_cast<_RawYp*>(static_cast<const _Yp*>(__ptr)));
}
}
_LIBCPP_INLINE_VISIBILITY void __enable_weak_this(...) _NOEXCEPT {}
template <class _Up> friend class _LIBCPP_TEMPLATE_VIS shared_ptr;
template <class _Up> friend class _LIBCPP_TEMPLATE_VIS weak_ptr;
};
template<class _Tp>
inline
_LIBCPP_CONSTEXPR
shared_ptr<_Tp>::shared_ptr() _NOEXCEPT
: __ptr_(0),
__cntrl_(0)
{
}
template<class _Tp>
inline
_LIBCPP_CONSTEXPR
shared_ptr<_Tp>::shared_ptr(nullptr_t) _NOEXCEPT
: __ptr_(0),
__cntrl_(0)
{
}
template<class _Tp>
template<class _Yp>
shared_ptr<_Tp>::shared_ptr(_Yp* __p,
typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type)
: __ptr_(__p)
{
unique_ptr<_Yp> __hold(__p);
typedef typename __shared_ptr_default_allocator<_Yp>::type _AllocT;
typedef __shared_ptr_pointer<_Yp*, default_delete<_Yp>, _AllocT > _CntrlBlk;
__cntrl_ = new _CntrlBlk(__p, default_delete<_Yp>(), _AllocT());
__hold.release();
__enable_weak_this(__p, __p);
}
template<class _Tp>
template<class _Yp, class _Dp>
shared_ptr<_Tp>::shared_ptr(_Yp* __p, _Dp __d,
typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type)
: __ptr_(__p)
{
#ifndef _LIBCPP_NO_EXCEPTIONS
try
{
#endif // _LIBCPP_NO_EXCEPTIONS
typedef typename __shared_ptr_default_allocator<_Yp>::type _AllocT;
typedef __shared_ptr_pointer<_Yp*, _Dp, _AllocT > _CntrlBlk;
__cntrl_ = new _CntrlBlk(__p, __d, _AllocT());
__enable_weak_this(__p, __p);
#ifndef _LIBCPP_NO_EXCEPTIONS
}
catch (...)
{
__d(__p);
throw;
}
#endif // _LIBCPP_NO_EXCEPTIONS
}
template<class _Tp>
template<class _Dp>
shared_ptr<_Tp>::shared_ptr(nullptr_t __p, _Dp __d)
: __ptr_(0)
{
#ifndef _LIBCPP_NO_EXCEPTIONS
try
{
#endif // _LIBCPP_NO_EXCEPTIONS
typedef typename __shared_ptr_default_allocator<_Tp>::type _AllocT;
typedef __shared_ptr_pointer<nullptr_t, _Dp, _AllocT > _CntrlBlk;
__cntrl_ = new _CntrlBlk(__p, __d, _AllocT());
#ifndef _LIBCPP_NO_EXCEPTIONS
}
catch (...)
{
__d(__p);
throw;
}
#endif // _LIBCPP_NO_EXCEPTIONS
}
template<class _Tp>
template<class _Yp, class _Dp, class _Alloc>
shared_ptr<_Tp>::shared_ptr(_Yp* __p, _Dp __d, _Alloc __a,
typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type)
: __ptr_(__p)
{
#ifndef _LIBCPP_NO_EXCEPTIONS
try
{
#endif // _LIBCPP_NO_EXCEPTIONS
typedef __shared_ptr_pointer<_Yp*, _Dp, _Alloc> _CntrlBlk;
typedef typename __allocator_traits_rebind<_Alloc, _CntrlBlk>::type _A2;
typedef __allocator_destructor<_A2> _D2;
_A2 __a2(__a);
unique_ptr<_CntrlBlk, _D2> __hold2(__a2.allocate(1), _D2(__a2, 1));
::new(static_cast<void*>(_VSTD::addressof(*__hold2.get())))
_CntrlBlk(__p, __d, __a);
__cntrl_ = _VSTD::addressof(*__hold2.release());
__enable_weak_this(__p, __p);
#ifndef _LIBCPP_NO_EXCEPTIONS
}
catch (...)
{
__d(__p);
throw;
}
#endif // _LIBCPP_NO_EXCEPTIONS
}
template<class _Tp>
template<class _Dp, class _Alloc>
shared_ptr<_Tp>::shared_ptr(nullptr_t __p, _Dp __d, _Alloc __a)
: __ptr_(0)
{
#ifndef _LIBCPP_NO_EXCEPTIONS
try
{
#endif // _LIBCPP_NO_EXCEPTIONS
typedef __shared_ptr_pointer<nullptr_t, _Dp, _Alloc> _CntrlBlk;
typedef typename __allocator_traits_rebind<_Alloc, _CntrlBlk>::type _A2;
typedef __allocator_destructor<_A2> _D2;
_A2 __a2(__a);
unique_ptr<_CntrlBlk, _D2> __hold2(__a2.allocate(1), _D2(__a2, 1));
::new(static_cast<void*>(_VSTD::addressof(*__hold2.get())))
_CntrlBlk(__p, __d, __a);
__cntrl_ = _VSTD::addressof(*__hold2.release());
#ifndef _LIBCPP_NO_EXCEPTIONS
}
catch (...)
{
__d(__p);
throw;
}
#endif // _LIBCPP_NO_EXCEPTIONS
}
template<class _Tp>
template<class _Yp>
inline
shared_ptr<_Tp>::shared_ptr(const shared_ptr<_Yp>& __r, element_type *__p) _NOEXCEPT
: __ptr_(__p),
__cntrl_(__r.__cntrl_)
{
if (__cntrl_)
__cntrl_->__add_shared();
}
template<class _Tp>
inline
shared_ptr<_Tp>::shared_ptr(const shared_ptr& __r) _NOEXCEPT
: __ptr_(__r.__ptr_),
__cntrl_(__r.__cntrl_)
{
if (__cntrl_)
__cntrl_->__add_shared();
}
template<class _Tp>
template<class _Yp>
inline
shared_ptr<_Tp>::shared_ptr(const shared_ptr<_Yp>& __r,
typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type)
_NOEXCEPT
: __ptr_(__r.__ptr_),
__cntrl_(__r.__cntrl_)
{
if (__cntrl_)
__cntrl_->__add_shared();
}
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
template<class _Tp>
inline
shared_ptr<_Tp>::shared_ptr(shared_ptr&& __r) _NOEXCEPT
: __ptr_(__r.__ptr_),
__cntrl_(__r.__cntrl_)
{
__r.__ptr_ = 0;
__r.__cntrl_ = 0;
}
template<class _Tp>
template<class _Yp>
inline
shared_ptr<_Tp>::shared_ptr(shared_ptr<_Yp>&& __r,
typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type)
_NOEXCEPT
: __ptr_(__r.__ptr_),
__cntrl_(__r.__cntrl_)
{
__r.__ptr_ = 0;
__r.__cntrl_ = 0;
}
#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
#if _LIBCPP_STD_VER <= 14 || defined(_LIBCPP_ENABLE_CXX17_REMOVED_AUTO_PTR)
template<class _Tp>
template<class _Yp>
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
shared_ptr<_Tp>::shared_ptr(auto_ptr<_Yp>&& __r,
#else
shared_ptr<_Tp>::shared_ptr(auto_ptr<_Yp> __r,
#endif
typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type)
: __ptr_(__r.get())
{
typedef __shared_ptr_pointer<_Yp*, default_delete<_Yp>, allocator<_Yp> > _CntrlBlk;
__cntrl_ = new _CntrlBlk(__r.get(), default_delete<_Yp>(), allocator<_Yp>());
__enable_weak_this(__r.get(), __r.get());
__r.release();
}
#endif
template<class _Tp>
template <class _Yp, class _Dp>
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
shared_ptr<_Tp>::shared_ptr(unique_ptr<_Yp, _Dp>&& __r,
#else
shared_ptr<_Tp>::shared_ptr(unique_ptr<_Yp, _Dp> __r,
#endif
typename enable_if
<
!is_lvalue_reference<_Dp>::value &&
!is_array<_Yp>::value &&
is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value,
__nat
>::type)
: __ptr_(__r.get())
{
#if _LIBCPP_STD_VER > 11
if (__ptr_ == nullptr)
__cntrl_ = nullptr;
else
#endif
{
typedef typename __shared_ptr_default_allocator<_Yp>::type _AllocT;
typedef __shared_ptr_pointer<_Yp*, _Dp, _AllocT > _CntrlBlk;
__cntrl_ = new _CntrlBlk(__r.get(), __r.get_deleter(), _AllocT());
__enable_weak_this(__r.get(), __r.get());
}
__r.release();
}
template<class _Tp>
template <class _Yp, class _Dp>
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
shared_ptr<_Tp>::shared_ptr(unique_ptr<_Yp, _Dp>&& __r,
#else
shared_ptr<_Tp>::shared_ptr(unique_ptr<_Yp, _Dp> __r,
#endif
typename enable_if
<
is_lvalue_reference<_Dp>::value &&
!is_array<_Yp>::value &&
is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value,
__nat
>::type)
: __ptr_(__r.get())
{
#if _LIBCPP_STD_VER > 11
if (__ptr_ == nullptr)
__cntrl_ = nullptr;
else
#endif
{
typedef typename __shared_ptr_default_allocator<_Yp>::type _AllocT;
typedef __shared_ptr_pointer<_Yp*,
reference_wrapper<typename remove_reference<_Dp>::type>,
_AllocT > _CntrlBlk;
__cntrl_ = new _CntrlBlk(__r.get(), ref(__r.get_deleter()), _AllocT());
__enable_weak_this(__r.get(), __r.get());
}
__r.release();
}
template<class _Tp>
template<class _Alloc, class ..._Args>
shared_ptr<_Tp>
shared_ptr<_Tp>::allocate_shared(const _Alloc& __a, _Args&& ...__args)
{
static_assert( is_constructible<_Tp, _Args...>::value, "Can't construct object in allocate_shared" );
typedef __shared_ptr_emplace<_Tp, _Alloc> _CntrlBlk;
typedef typename __allocator_traits_rebind<_Alloc, _CntrlBlk>::type _A2;
typedef __allocator_destructor<_A2> _D2;
_A2 __a2(__a);
unique_ptr<_CntrlBlk, _D2> __hold2(__a2.allocate(1), _D2(__a2, 1));
::new(static_cast<void*>(_VSTD::addressof(*__hold2.get())))
_CntrlBlk(__a, _VSTD::forward<_Args>(__args)...);
shared_ptr<_Tp> __r;
__r.__ptr_ = __hold2.get()->get();
__r.__cntrl_ = _VSTD::addressof(*__hold2.release());
__r.__enable_weak_this(__r.__ptr_, __r.__ptr_);
return __r;
}
template<class _Tp>
shared_ptr<_Tp>::~shared_ptr()
{
if (__cntrl_)
__cntrl_->__release_shared();
}
template<class _Tp>
inline
shared_ptr<_Tp>&
shared_ptr<_Tp>::operator=(const shared_ptr& __r) _NOEXCEPT
{
shared_ptr(__r).swap(*this);
return *this;
}
template<class _Tp>
template<class _Yp>
inline
typename enable_if
<
is_convertible<_Yp*, typename shared_ptr<_Tp>::element_type*>::value,
shared_ptr<_Tp>&
>::type
shared_ptr<_Tp>::operator=(const shared_ptr<_Yp>& __r) _NOEXCEPT
{
shared_ptr(__r).swap(*this);
return *this;
}
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
template<class _Tp>
inline
shared_ptr<_Tp>&
shared_ptr<_Tp>::operator=(shared_ptr&& __r) _NOEXCEPT
{
shared_ptr(_VSTD::move(__r)).swap(*this);
return *this;
}
template<class _Tp>
template<class _Yp>
inline
typename enable_if
<
is_convertible<_Yp*, typename shared_ptr<_Tp>::element_type*>::value,
shared_ptr<_Tp>&
>::type
shared_ptr<_Tp>::operator=(shared_ptr<_Yp>&& __r)
{
shared_ptr(_VSTD::move(__r)).swap(*this);
return *this;
}
#if _LIBCPP_STD_VER <= 14 || defined(_LIBCPP_ENABLE_CXX17_REMOVED_AUTO_PTR)
template<class _Tp>
template<class _Yp>
inline
typename enable_if
<
!is_array<_Yp>::value &&
is_convertible<_Yp*, typename shared_ptr<_Tp>::element_type*>::value,
shared_ptr<_Tp>
>::type&
shared_ptr<_Tp>::operator=(auto_ptr<_Yp>&& __r)
{
shared_ptr(_VSTD::move(__r)).swap(*this);
return *this;
}
#endif
template<class _Tp>
template <class _Yp, class _Dp>
inline
typename enable_if
<
!is_array<_Yp>::value &&
is_convertible<typename unique_ptr<_Yp, _Dp>::pointer,
typename shared_ptr<_Tp>::element_type*>::value,
shared_ptr<_Tp>&
>::type
shared_ptr<_Tp>::operator=(unique_ptr<_Yp, _Dp>&& __r)
{
shared_ptr(_VSTD::move(__r)).swap(*this);
return *this;
}
#else // _LIBCPP_HAS_NO_RVALUE_REFERENCES
#if _LIBCPP_STD_VER <= 14 || defined(_LIBCPP_ENABLE_CXX17_REMOVED_AUTO_PTR)
template<class _Tp>
template<class _Yp>
inline _LIBCPP_INLINE_VISIBILITY
typename enable_if
<
!is_array<_Yp>::value &&
is_convertible<_Yp*, typename shared_ptr<_Tp>::element_type*>::value,
shared_ptr<_Tp>&
>::type
shared_ptr<_Tp>::operator=(auto_ptr<_Yp> __r)
{
shared_ptr(__r).swap(*this);
return *this;
}
#endif
template<class _Tp>
template <class _Yp, class _Dp>
inline _LIBCPP_INLINE_VISIBILITY
typename enable_if
<
!is_array<_Yp>::value &&
is_convertible<typename unique_ptr<_Yp, _Dp>::pointer,
typename shared_ptr<_Tp>::element_type*>::value,
shared_ptr<_Tp>&
>::type
shared_ptr<_Tp>::operator=(unique_ptr<_Yp, _Dp> __r)
{
shared_ptr(_VSTD::move(__r)).swap(*this);
return *this;
}
#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
template<class _Tp>
inline
void
shared_ptr<_Tp>::swap(shared_ptr& __r) _NOEXCEPT
{
_VSTD::swap(__ptr_, __r.__ptr_);
_VSTD::swap(__cntrl_, __r.__cntrl_);
}
template<class _Tp>
inline
void
shared_ptr<_Tp>::reset() _NOEXCEPT
{
shared_ptr().swap(*this);
}
template<class _Tp>
template<class _Yp>
inline
typename enable_if
<
is_convertible<_Yp*, typename shared_ptr<_Tp>::element_type*>::value,
void
>::type
shared_ptr<_Tp>::reset(_Yp* __p)
{
shared_ptr(__p).swap(*this);
}
template<class _Tp>
template<class _Yp, class _Dp>
inline
typename enable_if
<
is_convertible<_Yp*, typename shared_ptr<_Tp>::element_type*>::value,
void
>::type
shared_ptr<_Tp>::reset(_Yp* __p, _Dp __d)
{
shared_ptr(__p, __d).swap(*this);
}
template<class _Tp>
template<class _Yp, class _Dp, class _Alloc>
inline
typename enable_if
<
is_convertible<_Yp*, typename shared_ptr<_Tp>::element_type*>::value,
void
>::type
shared_ptr<_Tp>::reset(_Yp* __p, _Dp __d, _Alloc __a)
{
shared_ptr(__p, __d, __a).swap(*this);
}
template<class _Tp, class ..._Args>
inline _LIBCPP_INLINE_VISIBILITY
typename enable_if
<
!is_array<_Tp>::value,
shared_ptr<_Tp>
>::type
make_shared(_Args&& ...__args)
{
static_assert(is_constructible<_Tp, _Args...>::value, "Can't construct object in make_shared");
typedef __shared_ptr_emplace<_Tp, allocator<_Tp> > _CntrlBlk;
typedef allocator<_CntrlBlk> _A2;
typedef __allocator_destructor<_A2> _D2;
_A2 __a2;
unique_ptr<_CntrlBlk, _D2> __hold2(__a2.allocate(1), _D2(__a2, 1));
::new(__hold2.get()) _CntrlBlk(__a2, _VSTD::forward<_Args>(__args)...);
_Tp *__ptr = __hold2.get()->get();
return shared_ptr<_Tp>::__create_with_control_block(__ptr, __hold2.release());
}
template<class _Tp, class _Alloc, class ..._Args>
inline _LIBCPP_INLINE_VISIBILITY
typename enable_if
<
!is_array<_Tp>::value,
shared_ptr<_Tp>
>::type
allocate_shared(const _Alloc& __a, _Args&& ...__args)
{
return shared_ptr<_Tp>::allocate_shared(__a, _VSTD::forward<_Args>(__args)...);
}
template<class _Tp, class _Up>
inline _LIBCPP_INLINE_VISIBILITY
bool
operator==(const shared_ptr<_Tp>& __x, const shared_ptr<_Up>& __y) _NOEXCEPT
{
return __x.get() == __y.get();
}
template<class _Tp, class _Up>
inline _LIBCPP_INLINE_VISIBILITY
bool
operator!=(const shared_ptr<_Tp>& __x, const shared_ptr<_Up>& __y) _NOEXCEPT
{
return !(__x == __y);
}
template<class _Tp, class _Up>
inline _LIBCPP_INLINE_VISIBILITY
bool
operator<(const shared_ptr<_Tp>& __x, const shared_ptr<_Up>& __y) _NOEXCEPT
{
#if _LIBCPP_STD_VER <= 11
typedef typename common_type<_Tp*, _Up*>::type _Vp;
return less<_Vp>()(__x.get(), __y.get());
#else
return less<>()(__x.get(), __y.get());
#endif
}
template<class _Tp, class _Up>
inline _LIBCPP_INLINE_VISIBILITY
bool
operator>(const shared_ptr<_Tp>& __x, const shared_ptr<_Up>& __y) _NOEXCEPT
{
return __y < __x;
}
template<class _Tp, class _Up>
inline _LIBCPP_INLINE_VISIBILITY
bool
operator<=(const shared_ptr<_Tp>& __x, const shared_ptr<_Up>& __y) _NOEXCEPT
{
return !(__y < __x);
}
template<class _Tp, class _Up>
inline _LIBCPP_INLINE_VISIBILITY
bool
operator>=(const shared_ptr<_Tp>& __x, const shared_ptr<_Up>& __y) _NOEXCEPT
{
return !(__x < __y);
}
template<class _Tp>
inline _LIBCPP_INLINE_VISIBILITY
bool
operator==(const shared_ptr<_Tp>& __x, nullptr_t) _NOEXCEPT
{
return !__x;
}
template<class _Tp>
inline _LIBCPP_INLINE_VISIBILITY
bool
operator==(nullptr_t, const shared_ptr<_Tp>& __x) _NOEXCEPT
{
return !__x;
}
template<class _Tp>
inline _LIBCPP_INLINE_VISIBILITY
bool
operator!=(const shared_ptr<_Tp>& __x, nullptr_t) _NOEXCEPT
{
return static_cast<bool>(__x);
}
template<class _Tp>
inline _LIBCPP_INLINE_VISIBILITY
bool
operator!=(nullptr_t, const shared_ptr<_Tp>& __x) _NOEXCEPT
{
return static_cast<bool>(__x);
}
template<class _Tp>
inline _LIBCPP_INLINE_VISIBILITY
bool
operator<(const shared_ptr<_Tp>& __x, nullptr_t) _NOEXCEPT
{
return less<_Tp*>()(__x.get(), nullptr);
}
template<class _Tp>
inline _LIBCPP_INLINE_VISIBILITY
bool
operator<(nullptr_t, const shared_ptr<_Tp>& __x) _NOEXCEPT
{
return less<_Tp*>()(nullptr, __x.get());
}
template<class _Tp>
inline _LIBCPP_INLINE_VISIBILITY
bool
operator>(const shared_ptr<_Tp>& __x, nullptr_t) _NOEXCEPT
{
return nullptr < __x;
}
template<class _Tp>
inline _LIBCPP_INLINE_VISIBILITY
bool
operator>(nullptr_t, const shared_ptr<_Tp>& __x) _NOEXCEPT
{
return __x < nullptr;
}
template<class _Tp>
inline _LIBCPP_INLINE_VISIBILITY
bool
operator<=(const shared_ptr<_Tp>& __x, nullptr_t) _NOEXCEPT
{
return !(nullptr < __x);
}
template<class _Tp>
inline _LIBCPP_INLINE_VISIBILITY
bool
operator<=(nullptr_t, const shared_ptr<_Tp>& __x) _NOEXCEPT
{
return !(__x < nullptr);
}
template<class _Tp>
inline _LIBCPP_INLINE_VISIBILITY
bool
operator>=(const shared_ptr<_Tp>& __x, nullptr_t) _NOEXCEPT
{
return !(__x < nullptr);
}
template<class _Tp>
inline _LIBCPP_INLINE_VISIBILITY
bool
operator>=(nullptr_t, const shared_ptr<_Tp>& __x) _NOEXCEPT
{
return !(nullptr < __x);
}
template<class _Tp>
inline _LIBCPP_INLINE_VISIBILITY
void
swap(shared_ptr<_Tp>& __x, shared_ptr<_Tp>& __y) _NOEXCEPT
{
__x.swap(__y);
}
template<class _Tp, class _Up>
inline _LIBCPP_INLINE_VISIBILITY
typename enable_if
<
!is_array<_Tp>::value && !is_array<_Up>::value,
shared_ptr<_Tp>
>::type
static_pointer_cast(const shared_ptr<_Up>& __r) _NOEXCEPT
{
return shared_ptr<_Tp>(__r, static_cast<_Tp*>(__r.get()));
}
template<class _Tp, class _Up>
inline _LIBCPP_INLINE_VISIBILITY
typename enable_if
<
!is_array<_Tp>::value && !is_array<_Up>::value,
shared_ptr<_Tp>
>::type
dynamic_pointer_cast(const shared_ptr<_Up>& __r) _NOEXCEPT
{
_Tp* __p = dynamic_cast<_Tp*>(__r.get());
return __p ? shared_ptr<_Tp>(__r, __p) : shared_ptr<_Tp>();
}
template<class _Tp, class _Up>
typename enable_if
<
is_array<_Tp>::value == is_array<_Up>::value,
shared_ptr<_Tp>
>::type
const_pointer_cast(const shared_ptr<_Up>& __r) _NOEXCEPT
{
typedef typename remove_extent<_Tp>::type _RTp;
return shared_ptr<_Tp>(__r, const_cast<_RTp*>(__r.get()));
}
#ifndef _LIBCPP_NO_RTTI
template<class _Dp, class _Tp>
inline _LIBCPP_INLINE_VISIBILITY
_Dp*
get_deleter(const shared_ptr<_Tp>& __p) _NOEXCEPT
{
return __p.template __get_deleter<_Dp>();
}
#endif // _LIBCPP_NO_RTTI
template<class _Tp>
class _LIBCPP_TEMPLATE_VIS weak_ptr
{
public:
typedef _Tp element_type;
private:
element_type* __ptr_;
__shared_weak_count* __cntrl_;
public:
_LIBCPP_INLINE_VISIBILITY
_LIBCPP_CONSTEXPR weak_ptr() _NOEXCEPT;
template<class _Yp> _LIBCPP_INLINE_VISIBILITY weak_ptr(shared_ptr<_Yp> const& __r,
typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat*>::type = 0)
_NOEXCEPT;
_LIBCPP_INLINE_VISIBILITY
weak_ptr(weak_ptr const& __r) _NOEXCEPT;
template<class _Yp> _LIBCPP_INLINE_VISIBILITY weak_ptr(weak_ptr<_Yp> const& __r,
typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat*>::type = 0)
_NOEXCEPT;
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
_LIBCPP_INLINE_VISIBILITY
weak_ptr(weak_ptr&& __r) _NOEXCEPT;
template<class _Yp> _LIBCPP_INLINE_VISIBILITY weak_ptr(weak_ptr<_Yp>&& __r,
typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat*>::type = 0)
_NOEXCEPT;
#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
~weak_ptr();
_LIBCPP_INLINE_VISIBILITY
weak_ptr& operator=(weak_ptr const& __r) _NOEXCEPT;
template<class _Yp>
typename enable_if
<
is_convertible<_Yp*, element_type*>::value,
weak_ptr&
>::type
_LIBCPP_INLINE_VISIBILITY
operator=(weak_ptr<_Yp> const& __r) _NOEXCEPT;
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
_LIBCPP_INLINE_VISIBILITY
weak_ptr& operator=(weak_ptr&& __r) _NOEXCEPT;
template<class _Yp>
typename enable_if
<
is_convertible<_Yp*, element_type*>::value,
weak_ptr&
>::type
_LIBCPP_INLINE_VISIBILITY
operator=(weak_ptr<_Yp>&& __r) _NOEXCEPT;
#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
template<class _Yp>
typename enable_if
<
is_convertible<_Yp*, element_type*>::value,
weak_ptr&
>::type
_LIBCPP_INLINE_VISIBILITY
operator=(shared_ptr<_Yp> const& __r) _NOEXCEPT;
_LIBCPP_INLINE_VISIBILITY
void swap(weak_ptr& __r) _NOEXCEPT;
_LIBCPP_INLINE_VISIBILITY
void reset() _NOEXCEPT;
_LIBCPP_INLINE_VISIBILITY
long use_count() const _NOEXCEPT
{return __cntrl_ ? __cntrl_->use_count() : 0;}
_LIBCPP_INLINE_VISIBILITY
bool expired() const _NOEXCEPT
{return __cntrl_ == 0 || __cntrl_->use_count() == 0;}
shared_ptr<_Tp> lock() const _NOEXCEPT;
template<class _Up>
_LIBCPP_INLINE_VISIBILITY
bool owner_before(const shared_ptr<_Up>& __r) const _NOEXCEPT
{return __cntrl_ < __r.__cntrl_;}
template<class _Up>
_LIBCPP_INLINE_VISIBILITY
bool owner_before(const weak_ptr<_Up>& __r) const _NOEXCEPT
{return __cntrl_ < __r.__cntrl_;}
template <class _Up> friend class _LIBCPP_TEMPLATE_VIS weak_ptr;
template <class _Up> friend class _LIBCPP_TEMPLATE_VIS shared_ptr;
};
template<class _Tp>
inline
_LIBCPP_CONSTEXPR
weak_ptr<_Tp>::weak_ptr() _NOEXCEPT
: __ptr_(0),
__cntrl_(0)
{
}
template<class _Tp>
inline
weak_ptr<_Tp>::weak_ptr(weak_ptr const& __r) _NOEXCEPT
: __ptr_(__r.__ptr_),
__cntrl_(__r.__cntrl_)
{
if (__cntrl_)
__cntrl_->__add_weak();
}
template<class _Tp>
template<class _Yp>
inline
weak_ptr<_Tp>::weak_ptr(shared_ptr<_Yp> const& __r,
typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat*>::type)
_NOEXCEPT
: __ptr_(__r.__ptr_),
__cntrl_(__r.__cntrl_)
{
if (__cntrl_)
__cntrl_->__add_weak();
}
template<class _Tp>
template<class _Yp>
inline
weak_ptr<_Tp>::weak_ptr(weak_ptr<_Yp> const& __r,
typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat*>::type)
_NOEXCEPT
: __ptr_(__r.__ptr_),
__cntrl_(__r.__cntrl_)
{
if (__cntrl_)
__cntrl_->__add_weak();
}
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
template<class _Tp>
inline
weak_ptr<_Tp>::weak_ptr(weak_ptr&& __r) _NOEXCEPT
: __ptr_(__r.__ptr_),
__cntrl_(__r.__cntrl_)
{
__r.__ptr_ = 0;
__r.__cntrl_ = 0;
}
template<class _Tp>
template<class _Yp>
inline
weak_ptr<_Tp>::weak_ptr(weak_ptr<_Yp>&& __r,
typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat*>::type)
_NOEXCEPT
: __ptr_(__r.__ptr_),
__cntrl_(__r.__cntrl_)
{
__r.__ptr_ = 0;
__r.__cntrl_ = 0;
}
#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
template<class _Tp>
weak_ptr<_Tp>::~weak_ptr()
{
if (__cntrl_)
__cntrl_->__release_weak();
}
template<class _Tp>
inline
weak_ptr<_Tp>&
weak_ptr<_Tp>::operator=(weak_ptr const& __r) _NOEXCEPT
{
weak_ptr(__r).swap(*this);
return *this;
}
template<class _Tp>
template<class _Yp>
inline
typename enable_if
<
is_convertible<_Yp*, _Tp*>::value,
weak_ptr<_Tp>&
>::type
weak_ptr<_Tp>::operator=(weak_ptr<_Yp> const& __r) _NOEXCEPT
{
weak_ptr(__r).swap(*this);
return *this;
}
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
template<class _Tp>
inline
weak_ptr<_Tp>&
weak_ptr<_Tp>::operator=(weak_ptr&& __r) _NOEXCEPT
{
weak_ptr(_VSTD::move(__r)).swap(*this);
return *this;
}
template<class _Tp>
template<class _Yp>
inline
typename enable_if
<
is_convertible<_Yp*, _Tp*>::value,
weak_ptr<_Tp>&
>::type
weak_ptr<_Tp>::operator=(weak_ptr<_Yp>&& __r) _NOEXCEPT
{
weak_ptr(_VSTD::move(__r)).swap(*this);
return *this;
}
#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
template<class _Tp>
template<class _Yp>
inline
typename enable_if
<
is_convertible<_Yp*, _Tp*>::value,
weak_ptr<_Tp>&
>::type
weak_ptr<_Tp>::operator=(shared_ptr<_Yp> const& __r) _NOEXCEPT
{
weak_ptr(__r).swap(*this);
return *this;
}
template<class _Tp>
inline
void
weak_ptr<_Tp>::swap(weak_ptr& __r) _NOEXCEPT
{
_VSTD::swap(__ptr_, __r.__ptr_);
_VSTD::swap(__cntrl_, __r.__cntrl_);
}
template<class _Tp>
inline _LIBCPP_INLINE_VISIBILITY
void
swap(weak_ptr<_Tp>& __x, weak_ptr<_Tp>& __y) _NOEXCEPT
{
__x.swap(__y);
}
template<class _Tp>
inline
void
weak_ptr<_Tp>::reset() _NOEXCEPT
{
weak_ptr().swap(*this);
}
template<class _Tp>
template<class _Yp>
shared_ptr<_Tp>::shared_ptr(const weak_ptr<_Yp>& __r,
typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type)
: __ptr_(__r.__ptr_),
__cntrl_(__r.__cntrl_ ? __r.__cntrl_->lock() : __r.__cntrl_)
{
if (__cntrl_ == 0)
__throw_bad_weak_ptr();
}
template<class _Tp>
shared_ptr<_Tp>
weak_ptr<_Tp>::lock() const _NOEXCEPT
{
shared_ptr<_Tp> __r;
__r.__cntrl_ = __cntrl_ ? __cntrl_->lock() : __cntrl_;
if (__r.__cntrl_)
__r.__ptr_ = __ptr_;
return __r;
}
#if _LIBCPP_STD_VER > 14
template <class _Tp = void> struct owner_less;
#else
template <class _Tp> struct owner_less;
#endif
template <class _Tp>
struct _LIBCPP_TEMPLATE_VIS owner_less<shared_ptr<_Tp> >
: binary_function<shared_ptr<_Tp>, shared_ptr<_Tp>, bool>
{
typedef bool result_type;
_LIBCPP_INLINE_VISIBILITY
bool operator()(shared_ptr<_Tp> const& __x, shared_ptr<_Tp> const& __y) const _NOEXCEPT
{return __x.owner_before(__y);}
_LIBCPP_INLINE_VISIBILITY
bool operator()(shared_ptr<_Tp> const& __x, weak_ptr<_Tp> const& __y) const _NOEXCEPT
{return __x.owner_before(__y);}
_LIBCPP_INLINE_VISIBILITY
bool operator()( weak_ptr<_Tp> const& __x, shared_ptr<_Tp> const& __y) const _NOEXCEPT
{return __x.owner_before(__y);}
};
template <class _Tp>
struct _LIBCPP_TEMPLATE_VIS owner_less<weak_ptr<_Tp> >
: binary_function<weak_ptr<_Tp>, weak_ptr<_Tp>, bool>
{
typedef bool result_type;
_LIBCPP_INLINE_VISIBILITY
bool operator()( weak_ptr<_Tp> const& __x, weak_ptr<_Tp> const& __y) const _NOEXCEPT
{return __x.owner_before(__y);}
_LIBCPP_INLINE_VISIBILITY
bool operator()(shared_ptr<_Tp> const& __x, weak_ptr<_Tp> const& __y) const _NOEXCEPT
{return __x.owner_before(__y);}
_LIBCPP_INLINE_VISIBILITY
bool operator()( weak_ptr<_Tp> const& __x, shared_ptr<_Tp> const& __y) const _NOEXCEPT
{return __x.owner_before(__y);}
};
#if _LIBCPP_STD_VER > 14
template <>
struct _LIBCPP_TEMPLATE_VIS owner_less<void>
{
template <class _Tp, class _Up>
_LIBCPP_INLINE_VISIBILITY
bool operator()( shared_ptr<_Tp> const& __x, shared_ptr<_Up> const& __y) const _NOEXCEPT
{return __x.owner_before(__y);}
template <class _Tp, class _Up>
_LIBCPP_INLINE_VISIBILITY
bool operator()( shared_ptr<_Tp> const& __x, weak_ptr<_Up> const& __y) const _NOEXCEPT
{return __x.owner_before(__y);}
template <class _Tp, class _Up>
_LIBCPP_INLINE_VISIBILITY
bool operator()( weak_ptr<_Tp> const& __x, shared_ptr<_Up> const& __y) const _NOEXCEPT
{return __x.owner_before(__y);}
template <class _Tp, class _Up>
_LIBCPP_INLINE_VISIBILITY
bool operator()( weak_ptr<_Tp> const& __x, weak_ptr<_Up> const& __y) const _NOEXCEPT
{return __x.owner_before(__y);}
typedef void is_transparent;
};
#endif
template<class _Tp>
class _LIBCPP_TEMPLATE_VIS enable_shared_from_this
{
mutable weak_ptr<_Tp> __weak_this_;
protected:
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
enable_shared_from_this() _NOEXCEPT {}
_LIBCPP_INLINE_VISIBILITY
enable_shared_from_this(enable_shared_from_this const&) _NOEXCEPT {}
_LIBCPP_INLINE_VISIBILITY
enable_shared_from_this& operator=(enable_shared_from_this const&) _NOEXCEPT
{return *this;}
_LIBCPP_INLINE_VISIBILITY
~enable_shared_from_this() {}
public:
_LIBCPP_INLINE_VISIBILITY
shared_ptr<_Tp> shared_from_this()
{return shared_ptr<_Tp>(__weak_this_);}
_LIBCPP_INLINE_VISIBILITY
shared_ptr<_Tp const> shared_from_this() const
{return shared_ptr<const _Tp>(__weak_this_);}
#if _LIBCPP_STD_VER > 14
_LIBCPP_INLINE_VISIBILITY
weak_ptr<_Tp> weak_from_this() _NOEXCEPT
{ return __weak_this_; }
_LIBCPP_INLINE_VISIBILITY
weak_ptr<const _Tp> weak_from_this() const _NOEXCEPT
{ return __weak_this_; }
#endif // _LIBCPP_STD_VER > 14
template <class _Up> friend class shared_ptr;
};
template <class _Tp>
struct _LIBCPP_TEMPLATE_VIS hash<shared_ptr<_Tp> >
{
typedef shared_ptr<_Tp> argument_type;
typedef size_t result_type;
_LIBCPP_INLINE_VISIBILITY
result_type operator()(const argument_type& __ptr) const _NOEXCEPT
{
return hash<_Tp*>()(__ptr.get());
}
};
template<class _CharT, class _Traits, class _Yp>
inline _LIBCPP_INLINE_VISIBILITY
basic_ostream<_CharT, _Traits>&
operator<<(basic_ostream<_CharT, _Traits>& __os, shared_ptr<_Yp> const& __p);
#if !defined(_LIBCPP_HAS_NO_ATOMIC_HEADER)
class _LIBCPP_TYPE_VIS __sp_mut
{
void* __lx;
public:
void lock() _NOEXCEPT;
void unlock() _NOEXCEPT;
private:
_LIBCPP_CONSTEXPR __sp_mut(void*) _NOEXCEPT;
__sp_mut(const __sp_mut&);
__sp_mut& operator=(const __sp_mut&);
friend _LIBCPP_FUNC_VIS __sp_mut& __get_sp_mut(const void*);
};
_LIBCPP_FUNC_VIS _LIBCPP_AVAILABILITY_ATOMIC_SHARED_PTR
__sp_mut& __get_sp_mut(const void*);
template <class _Tp>
inline _LIBCPP_INLINE_VISIBILITY
bool
atomic_is_lock_free(const shared_ptr<_Tp>*)
{
return false;
}
template <class _Tp>
_LIBCPP_AVAILABILITY_ATOMIC_SHARED_PTR
shared_ptr<_Tp>
atomic_load(const shared_ptr<_Tp>* __p)
{
__sp_mut& __m = __get_sp_mut(__p);
__m.lock();
shared_ptr<_Tp> __q = *__p;
__m.unlock();
return __q;
}
template <class _Tp>
inline _LIBCPP_INLINE_VISIBILITY
_LIBCPP_AVAILABILITY_ATOMIC_SHARED_PTR
shared_ptr<_Tp>
atomic_load_explicit(const shared_ptr<_Tp>* __p, memory_order)
{
return atomic_load(__p);
}
template <class _Tp>
_LIBCPP_AVAILABILITY_ATOMIC_SHARED_PTR
void
atomic_store(shared_ptr<_Tp>* __p, shared_ptr<_Tp> __r)
{
__sp_mut& __m = __get_sp_mut(__p);
__m.lock();
__p->swap(__r);
__m.unlock();
}
template <class _Tp>
inline _LIBCPP_INLINE_VISIBILITY
_LIBCPP_AVAILABILITY_ATOMIC_SHARED_PTR
void
atomic_store_explicit(shared_ptr<_Tp>* __p, shared_ptr<_Tp> __r, memory_order)
{
atomic_store(__p, __r);
}
template <class _Tp>
_LIBCPP_AVAILABILITY_ATOMIC_SHARED_PTR
shared_ptr<_Tp>
atomic_exchange(shared_ptr<_Tp>* __p, shared_ptr<_Tp> __r)
{
__sp_mut& __m = __get_sp_mut(__p);
__m.lock();
__p->swap(__r);
__m.unlock();
return __r;
}
template <class _Tp>
inline _LIBCPP_INLINE_VISIBILITY
_LIBCPP_AVAILABILITY_ATOMIC_SHARED_PTR
shared_ptr<_Tp>
atomic_exchange_explicit(shared_ptr<_Tp>* __p, shared_ptr<_Tp> __r, memory_order)
{
return atomic_exchange(__p, __r);
}
template <class _Tp>
_LIBCPP_AVAILABILITY_ATOMIC_SHARED_PTR
bool
atomic_compare_exchange_strong(shared_ptr<_Tp>* __p, shared_ptr<_Tp>* __v, shared_ptr<_Tp> __w)
{
shared_ptr<_Tp> __temp;
__sp_mut& __m = __get_sp_mut(__p);
__m.lock();
if (__p->__owner_equivalent(*__v))
{
_VSTD::swap(__temp, *__p);
*__p = __w;
__m.unlock();
return true;
}
_VSTD::swap(__temp, *__v);
*__v = *__p;
__m.unlock();
return false;
}
template <class _Tp>
inline _LIBCPP_INLINE_VISIBILITY
_LIBCPP_AVAILABILITY_ATOMIC_SHARED_PTR
bool
atomic_compare_exchange_weak(shared_ptr<_Tp>* __p, shared_ptr<_Tp>* __v, shared_ptr<_Tp> __w)
{
return atomic_compare_exchange_strong(__p, __v, __w);
}
template <class _Tp>
inline _LIBCPP_INLINE_VISIBILITY
_LIBCPP_AVAILABILITY_ATOMIC_SHARED_PTR
bool
atomic_compare_exchange_strong_explicit(shared_ptr<_Tp>* __p, shared_ptr<_Tp>* __v,
shared_ptr<_Tp> __w, memory_order, memory_order)
{
return atomic_compare_exchange_strong(__p, __v, __w);
}
template <class _Tp>
inline _LIBCPP_INLINE_VISIBILITY
_LIBCPP_AVAILABILITY_ATOMIC_SHARED_PTR
bool
atomic_compare_exchange_weak_explicit(shared_ptr<_Tp>* __p, shared_ptr<_Tp>* __v,
shared_ptr<_Tp> __w, memory_order, memory_order)
{
return atomic_compare_exchange_weak(__p, __v, __w);
}
#endif // !defined(_LIBCPP_HAS_NO_ATOMIC_HEADER)
//enum class
#if defined(_LIBCPP_ABI_POINTER_SAFETY_ENUM_TYPE)
# ifndef _LIBCPP_CXX03_LANG
enum class pointer_safety : unsigned char {
relaxed,
preferred,
strict
};
# endif
#else
struct _LIBCPP_TYPE_VIS pointer_safety
{
enum __lx
{
relaxed,
preferred,
strict
};
__lx __v_;
_LIBCPP_INLINE_VISIBILITY
pointer_safety() : __v_() {}
_LIBCPP_INLINE_VISIBILITY
pointer_safety(__lx __v) : __v_(__v) {}
_LIBCPP_INLINE_VISIBILITY
operator int() const {return __v_;}
};
#endif
#if !defined(_LIBCPP_ABI_POINTER_SAFETY_ENUM_TYPE) && \
defined(_LIBCPP_BUILDING_LIBRARY)
_LIBCPP_FUNC_VIS pointer_safety get_pointer_safety() _NOEXCEPT;
#else
// This function is only offered in C++03 under ABI v1.
# if !defined(_LIBCPP_ABI_POINTER_SAFETY_ENUM_TYPE) || !defined(_LIBCPP_CXX03_LANG)
inline _LIBCPP_INLINE_VISIBILITY
pointer_safety get_pointer_safety() _NOEXCEPT {
return pointer_safety::relaxed;
}
# endif
#endif
_LIBCPP_FUNC_VIS void declare_reachable(void* __p);
_LIBCPP_FUNC_VIS void declare_no_pointers(char* __p, size_t __n);
_LIBCPP_FUNC_VIS void undeclare_no_pointers(char* __p, size_t __n);
_LIBCPP_FUNC_VIS void* __undeclare_reachable(void* __p);
template <class _Tp>
inline _LIBCPP_INLINE_VISIBILITY
_Tp*
undeclare_reachable(_Tp* __p)
{
return static_cast<_Tp*>(__undeclare_reachable(__p));
}
_LIBCPP_FUNC_VIS void* align(size_t __align, size_t __sz, void*& __ptr, size_t& __space);
// --- Helper for container swap --
template <typename _Alloc>
inline _LIBCPP_INLINE_VISIBILITY
void __swap_allocator(_Alloc & __a1, _Alloc & __a2)
#if _LIBCPP_STD_VER >= 14
_NOEXCEPT
#else
_NOEXCEPT_(__is_nothrow_swappable<_Alloc>::value)
#endif
{
__swap_allocator(__a1, __a2,
integral_constant<bool, _VSTD::allocator_traits<_Alloc>::propagate_on_container_swap::value>());
}
template <typename _Alloc>
_LIBCPP_INLINE_VISIBILITY
void __swap_allocator(_Alloc & __a1, _Alloc & __a2, true_type)
#if _LIBCPP_STD_VER >= 14
_NOEXCEPT
#else
_NOEXCEPT_(__is_nothrow_swappable<_Alloc>::value)
#endif
{
using _VSTD::swap;
swap(__a1, __a2);
}
template <typename _Alloc>
inline _LIBCPP_INLINE_VISIBILITY
void __swap_allocator(_Alloc &, _Alloc &, false_type) _NOEXCEPT {}
template <typename _Alloc, typename _Traits=allocator_traits<_Alloc> >
struct __noexcept_move_assign_container : public integral_constant<bool,
_Traits::propagate_on_container_move_assignment::value
#if _LIBCPP_STD_VER > 14
|| _Traits::is_always_equal::value
#else
&& is_nothrow_move_assignable<_Alloc>::value
#endif
> {};
#ifndef _LIBCPP_HAS_NO_VARIADICS
template <class _Tp, class _Alloc>
struct __temp_value {
typedef allocator_traits<_Alloc> _Traits;
typename aligned_storage<sizeof(_Tp), _LIBCPP_ALIGNOF(_Tp)>::type __v;
_Alloc &__a;
_Tp *__addr() { return reinterpret_cast<_Tp *>(addressof(__v)); }
_Tp & get() { return *__addr(); }
template<class... _Args>
_LIBCPP_NO_CFI
__temp_value(_Alloc &__alloc, _Args&& ... __args) : __a(__alloc) {
_Traits::construct(__a, reinterpret_cast<_Tp*>(addressof(__v)),
_VSTD::forward<_Args>(__args)...);
}
~__temp_value() { _Traits::destroy(__a, __addr()); }
};
#endif
template<typename _Alloc, typename = void, typename = void>
struct __is_allocator : false_type {};
template<typename _Alloc>
struct __is_allocator<_Alloc,
typename __void_t<typename _Alloc::value_type>::type,
typename __void_t<decltype(_VSTD::declval<_Alloc&>().allocate(size_t(0)))>::type
>
: true_type {};
// __builtin_new_allocator -- A non-templated helper for allocating and
// deallocating memory using __builtin_operator_new and
// __builtin_operator_delete. It should be used in preference to
// `std::allocator<T>` to avoid additional instantiations.
struct __builtin_new_allocator {
struct __builtin_new_deleter {
typedef void* pointer_type;
_LIBCPP_CONSTEXPR explicit __builtin_new_deleter(size_t __size, size_t __align)
: __size_(__size), __align_(__align) {}
void operator()(void* p) const _NOEXCEPT {
std::__libcpp_deallocate(p, __size_, __align_);
}
private:
size_t __size_;
size_t __align_;
};
typedef unique_ptr<void, __builtin_new_deleter> __holder_t;
static __holder_t __allocate_bytes(size_t __s, size_t __align) {
return __holder_t(std::__libcpp_allocate(__s, __align),
__builtin_new_deleter(__s, __align));
}
static void __deallocate_bytes(void* __p, size_t __s,
size_t __align) _NOEXCEPT {
std::__libcpp_deallocate(__p, __s, __align);
}
template <class _Tp>
_LIBCPP_NODEBUG _LIBCPP_ALWAYS_INLINE
static __holder_t __allocate_type(size_t __n) {
return __allocate_bytes(__n * sizeof(_Tp), _LIBCPP_ALIGNOF(_Tp));
}
template <class _Tp>
_LIBCPP_NODEBUG _LIBCPP_ALWAYS_INLINE
static void __deallocate_type(void* __p, size_t __n) _NOEXCEPT {
__deallocate_bytes(__p, __n * sizeof(_Tp), _LIBCPP_ALIGNOF(_Tp));
}
};
_LIBCPP_END_NAMESPACE_STD
_LIBCPP_POP_MACROS
#if defined(_LIBCPP_HAS_PARALLEL_ALGORITHMS) && _LIBCPP_STD_VER >= 17
# include "third_party/libcxx/__pstl_memory"
#endif
#endif // _LIBCPP_MEMORY
| 167,654 | 5,371 | jart/cosmopolitan | false |
cosmopolitan/third_party/libcxx/ios | // -*- C++ -*-
//===---------------------------- ios -------------------------------------===//
//
// 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_IOS
#define _LIBCPP_IOS
#include "third_party/libcxx/__config"
#include "third_party/libcxx/iosfwd"
#include "third_party/libcxx/__locale"
#include "third_party/libcxx/system_error"
#if !defined(_LIBCPP_HAS_NO_ATOMIC_HEADER)
#include "third_party/libcxx/atomic" // for __xindex_
#endif
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
#pragma GCC system_header
#endif
_LIBCPP_BEGIN_NAMESPACE_STD
/*
ios synopsis
#include "third_party/libcxx/iosfwd"
namespace std
{
typedef OFF_T streamoff;
typedef SZ_T streamsize;
template <class stateT> class fpos;
class ios_base
{
public:
class failure;
typedef T1 fmtflags;
static constexpr fmtflags boolalpha;
static constexpr fmtflags dec;
static constexpr fmtflags fixed;
static constexpr fmtflags hex;
static constexpr fmtflags internal;
static constexpr fmtflags left;
static constexpr fmtflags oct;
static constexpr fmtflags right;
static constexpr fmtflags scientific;
static constexpr fmtflags showbase;
static constexpr fmtflags showpoint;
static constexpr fmtflags showpos;
static constexpr fmtflags skipws;
static constexpr fmtflags unitbuf;
static constexpr fmtflags uppercase;
static constexpr fmtflags adjustfield;
static constexpr fmtflags basefield;
static constexpr fmtflags floatfield;
typedef T2 iostate;
static constexpr iostate badbit;
static constexpr iostate eofbit;
static constexpr iostate failbit;
static constexpr iostate goodbit;
typedef T3 openmode;
static constexpr openmode app;
static constexpr openmode ate;
static constexpr openmode binary;
static constexpr openmode in;
static constexpr openmode out;
static constexpr openmode trunc;
typedef T4 seekdir;
static constexpr seekdir beg;
static constexpr seekdir cur;
static constexpr seekdir end;
class Init;
// 27.5.2.2 fmtflags state:
fmtflags flags() const;
fmtflags flags(fmtflags fmtfl);
fmtflags setf(fmtflags fmtfl);
fmtflags setf(fmtflags fmtfl, fmtflags mask);
void unsetf(fmtflags mask);
streamsize precision() const;
streamsize precision(streamsize prec);
streamsize width() const;
streamsize width(streamsize wide);
// 27.5.2.3 locales:
locale imbue(const locale& loc);
locale getloc() const;
// 27.5.2.5 storage:
static int xalloc();
long& iword(int index);
void*& pword(int index);
// destructor
virtual ~ios_base();
// 27.5.2.6 callbacks;
enum event { erase_event, imbue_event, copyfmt_event };
typedef void (*event_callback)(event, ios_base&, int index);
void register_callback(event_callback fn, int index);
ios_base(const ios_base&) = delete;
ios_base& operator=(const ios_base&) = delete;
static bool sync_with_stdio(bool sync = true);
protected:
ios_base();
};
template <class charT, class traits = char_traits<charT> >
class basic_ios
: public ios_base
{
public:
// types:
typedef charT char_type;
typedef typename traits::int_type int_type; // removed in C++17
typedef typename traits::pos_type pos_type; // removed in C++17
typedef typename traits::off_type off_type; // removed in C++17
typedef traits traits_type;
operator unspecified-bool-type() const;
bool operator!() const;
iostate rdstate() const;
void clear(iostate state = goodbit);
void setstate(iostate state);
bool good() const;
bool eof() const;
bool fail() const;
bool bad() const;
iostate exceptions() const;
void exceptions(iostate except);
// 27.5.4.1 Constructor/destructor:
explicit basic_ios(basic_streambuf<charT,traits>* sb);
virtual ~basic_ios();
// 27.5.4.2 Members:
basic_ostream<charT,traits>* tie() const;
basic_ostream<charT,traits>* tie(basic_ostream<charT,traits>* tiestr);
basic_streambuf<charT,traits>* rdbuf() const;
basic_streambuf<charT,traits>* rdbuf(basic_streambuf<charT,traits>* sb);
basic_ios& copyfmt(const basic_ios& rhs);
char_type fill() const;
char_type fill(char_type ch);
locale imbue(const locale& loc);
char narrow(char_type c, char dfault) const;
char_type widen(char c) const;
basic_ios(const basic_ios& ) = delete;
basic_ios& operator=(const basic_ios&) = delete;
protected:
basic_ios();
void init(basic_streambuf<charT,traits>* sb);
void move(basic_ios& rhs);
void swap(basic_ios& rhs) noexcept;
void set_rdbuf(basic_streambuf<charT, traits>* sb);
};
// 27.5.5, manipulators:
ios_base& boolalpha (ios_base& str);
ios_base& noboolalpha(ios_base& str);
ios_base& showbase (ios_base& str);
ios_base& noshowbase (ios_base& str);
ios_base& showpoint (ios_base& str);
ios_base& noshowpoint(ios_base& str);
ios_base& showpos (ios_base& str);
ios_base& noshowpos (ios_base& str);
ios_base& skipws (ios_base& str);
ios_base& noskipws (ios_base& str);
ios_base& uppercase (ios_base& str);
ios_base& nouppercase(ios_base& str);
ios_base& unitbuf (ios_base& str);
ios_base& nounitbuf (ios_base& str);
// 27.5.5.2 adjustfield:
ios_base& internal (ios_base& str);
ios_base& left (ios_base& str);
ios_base& right (ios_base& str);
// 27.5.5.3 basefield:
ios_base& dec (ios_base& str);
ios_base& hex (ios_base& str);
ios_base& oct (ios_base& str);
// 27.5.5.4 floatfield:
ios_base& fixed (ios_base& str);
ios_base& scientific (ios_base& str);
ios_base& hexfloat (ios_base& str);
ios_base& defaultfloat(ios_base& str);
// 27.5.5.5 error reporting:
enum class io_errc
{
stream = 1
};
concept_map ErrorCodeEnum<io_errc> { };
error_code make_error_code(io_errc e) noexcept;
error_condition make_error_condition(io_errc e) noexcept;
storage-class-specifier const error_category& iostream_category() noexcept;
} // std
*/
typedef ptrdiff_t streamsize;
class _LIBCPP_TYPE_VIS ios_base
{
public:
class _LIBCPP_EXCEPTION_ABI failure;
typedef unsigned int fmtflags;
static const fmtflags boolalpha = 0x0001;
static const fmtflags dec = 0x0002;
static const fmtflags fixed = 0x0004;
static const fmtflags hex = 0x0008;
static const fmtflags internal = 0x0010;
static const fmtflags left = 0x0020;
static const fmtflags oct = 0x0040;
static const fmtflags right = 0x0080;
static const fmtflags scientific = 0x0100;
static const fmtflags showbase = 0x0200;
static const fmtflags showpoint = 0x0400;
static const fmtflags showpos = 0x0800;
static const fmtflags skipws = 0x1000;
static const fmtflags unitbuf = 0x2000;
static const fmtflags uppercase = 0x4000;
static const fmtflags adjustfield = left | right | internal;
static const fmtflags basefield = dec | oct | hex;
static const fmtflags floatfield = scientific | fixed;
typedef unsigned int iostate;
static const iostate badbit = 0x1;
static const iostate eofbit = 0x2;
static const iostate failbit = 0x4;
static const iostate goodbit = 0x0;
typedef unsigned int openmode;
static const openmode app = 0x01;
static const openmode ate = 0x02;
static const openmode binary = 0x04;
static const openmode in = 0x08;
static const openmode out = 0x10;
static const openmode trunc = 0x20;
enum seekdir {beg, cur, end};
#if _LIBCPP_STD_VER <= 14
typedef iostate io_state;
typedef openmode open_mode;
typedef seekdir seek_dir;
typedef _VSTD::streamoff streamoff;
typedef _VSTD::streampos streampos;
#endif
class _LIBCPP_TYPE_VIS Init;
// 27.5.2.2 fmtflags state:
_LIBCPP_INLINE_VISIBILITY fmtflags flags() const;
_LIBCPP_INLINE_VISIBILITY fmtflags flags(fmtflags __fmtfl);
_LIBCPP_INLINE_VISIBILITY fmtflags setf(fmtflags __fmtfl);
_LIBCPP_INLINE_VISIBILITY fmtflags setf(fmtflags __fmtfl, fmtflags __mask);
_LIBCPP_INLINE_VISIBILITY void unsetf(fmtflags __mask);
_LIBCPP_INLINE_VISIBILITY streamsize precision() const;
_LIBCPP_INLINE_VISIBILITY streamsize precision(streamsize __prec);
_LIBCPP_INLINE_VISIBILITY streamsize width() const;
_LIBCPP_INLINE_VISIBILITY streamsize width(streamsize __wide);
// 27.5.2.3 locales:
locale imbue(const locale& __loc);
locale getloc() const;
// 27.5.2.5 storage:
static int xalloc();
long& iword(int __index);
void*& pword(int __index);
// destructor
virtual ~ios_base();
// 27.5.2.6 callbacks;
enum event { erase_event, imbue_event, copyfmt_event };
typedef void (*event_callback)(event, ios_base&, int __index);
void register_callback(event_callback __fn, int __index);
private:
ios_base(const ios_base&); // = delete;
ios_base& operator=(const ios_base&); // = delete;
public:
static bool sync_with_stdio(bool __sync = true);
_LIBCPP_INLINE_VISIBILITY iostate rdstate() const;
void clear(iostate __state = goodbit);
_LIBCPP_INLINE_VISIBILITY void setstate(iostate __state);
_LIBCPP_INLINE_VISIBILITY bool good() const;
_LIBCPP_INLINE_VISIBILITY bool eof() const;
_LIBCPP_INLINE_VISIBILITY bool fail() const;
_LIBCPP_INLINE_VISIBILITY bool bad() const;
_LIBCPP_INLINE_VISIBILITY iostate exceptions() const;
_LIBCPP_INLINE_VISIBILITY void exceptions(iostate __iostate);
void __set_badbit_and_consider_rethrow();
void __set_failbit_and_consider_rethrow();
_LIBCPP_INLINE_VISIBILITY
void __setstate_nothrow(iostate __state)
{
if (__rdbuf_)
__rdstate_ |= __state;
else
__rdstate_ |= __state | ios_base::badbit;
}
protected:
_LIBCPP_INLINE_VISIBILITY
ios_base() {// purposefully does no initialization
}
void init(void* __sb);
_LIBCPP_INLINE_VISIBILITY void* rdbuf() const {return __rdbuf_;}
_LIBCPP_INLINE_VISIBILITY
void rdbuf(void* __sb)
{
__rdbuf_ = __sb;
clear();
}
void __call_callbacks(event);
void copyfmt(const ios_base&);
void move(ios_base&);
void swap(ios_base&) _NOEXCEPT;
_LIBCPP_INLINE_VISIBILITY
void set_rdbuf(void* __sb)
{
__rdbuf_ = __sb;
}
private:
// All data members must be scalars
fmtflags __fmtflags_;
streamsize __precision_;
streamsize __width_;
iostate __rdstate_;
iostate __exceptions_;
void* __rdbuf_;
void* __loc_;
event_callback* __fn_;
int* __index_;
size_t __event_size_;
size_t __event_cap_;
// TODO(EricWF): Enable this for both Clang and GCC. Currently it is only
// enabled with clang.
#if defined(_LIBCPP_HAS_C_ATOMIC_IMP) && !defined(_LIBCPP_HAS_NO_THREADS)
static atomic<int> __xindex_;
#else
static int __xindex_;
#endif
long* __iarray_;
size_t __iarray_size_;
size_t __iarray_cap_;
void** __parray_;
size_t __parray_size_;
size_t __parray_cap_;
};
//enum class io_errc
_LIBCPP_DECLARE_STRONG_ENUM(io_errc)
{
stream = 1
};
_LIBCPP_DECLARE_STRONG_ENUM_EPILOG(io_errc)
template <>
struct _LIBCPP_TEMPLATE_VIS is_error_code_enum<io_errc> : public true_type { };
#ifdef _LIBCPP_HAS_NO_STRONG_ENUMS
template <>
struct _LIBCPP_TEMPLATE_VIS is_error_code_enum<io_errc::__lx> : public true_type { };
#endif
_LIBCPP_FUNC_VIS
const error_category& iostream_category() _NOEXCEPT;
inline _LIBCPP_INLINE_VISIBILITY
error_code
make_error_code(io_errc __e) _NOEXCEPT
{
return error_code(static_cast<int>(__e), iostream_category());
}
inline _LIBCPP_INLINE_VISIBILITY
error_condition
make_error_condition(io_errc __e) _NOEXCEPT
{
return error_condition(static_cast<int>(__e), iostream_category());
}
class _LIBCPP_EXCEPTION_ABI ios_base::failure
: public system_error
{
public:
explicit failure(const string& __msg, const error_code& __ec = io_errc::stream);
explicit failure(const char* __msg, const error_code& __ec = io_errc::stream);
virtual ~failure() throw();
};
_LIBCPP_NORETURN inline _LIBCPP_INLINE_VISIBILITY
void __throw_failure(char const* __msg) {
#ifndef _LIBCPP_NO_EXCEPTIONS
throw ios_base::failure(__msg);
#else
((void)__msg);
_VSTD::abort();
#endif
}
class _LIBCPP_TYPE_VIS ios_base::Init
{
public:
Init();
~Init();
};
// fmtflags
inline _LIBCPP_INLINE_VISIBILITY
ios_base::fmtflags
ios_base::flags() const
{
return __fmtflags_;
}
inline _LIBCPP_INLINE_VISIBILITY
ios_base::fmtflags
ios_base::flags(fmtflags __fmtfl)
{
fmtflags __r = __fmtflags_;
__fmtflags_ = __fmtfl;
return __r;
}
inline _LIBCPP_INLINE_VISIBILITY
ios_base::fmtflags
ios_base::setf(fmtflags __fmtfl)
{
fmtflags __r = __fmtflags_;
__fmtflags_ |= __fmtfl;
return __r;
}
inline _LIBCPP_INLINE_VISIBILITY
void
ios_base::unsetf(fmtflags __mask)
{
__fmtflags_ &= ~__mask;
}
inline _LIBCPP_INLINE_VISIBILITY
ios_base::fmtflags
ios_base::setf(fmtflags __fmtfl, fmtflags __mask)
{
fmtflags __r = __fmtflags_;
unsetf(__mask);
__fmtflags_ |= __fmtfl & __mask;
return __r;
}
// precision
inline _LIBCPP_INLINE_VISIBILITY
streamsize
ios_base::precision() const
{
return __precision_;
}
inline _LIBCPP_INLINE_VISIBILITY
streamsize
ios_base::precision(streamsize __prec)
{
streamsize __r = __precision_;
__precision_ = __prec;
return __r;
}
// width
inline _LIBCPP_INLINE_VISIBILITY
streamsize
ios_base::width() const
{
return __width_;
}
inline _LIBCPP_INLINE_VISIBILITY
streamsize
ios_base::width(streamsize __wide)
{
streamsize __r = __width_;
__width_ = __wide;
return __r;
}
// iostate
inline _LIBCPP_INLINE_VISIBILITY
ios_base::iostate
ios_base::rdstate() const
{
return __rdstate_;
}
inline _LIBCPP_INLINE_VISIBILITY
void
ios_base::setstate(iostate __state)
{
clear(__rdstate_ | __state);
}
inline _LIBCPP_INLINE_VISIBILITY
bool
ios_base::good() const
{
return __rdstate_ == 0;
}
inline _LIBCPP_INLINE_VISIBILITY
bool
ios_base::eof() const
{
return (__rdstate_ & eofbit) != 0;
}
inline _LIBCPP_INLINE_VISIBILITY
bool
ios_base::fail() const
{
return (__rdstate_ & (failbit | badbit)) != 0;
}
inline _LIBCPP_INLINE_VISIBILITY
bool
ios_base::bad() const
{
return (__rdstate_ & badbit) != 0;
}
inline _LIBCPP_INLINE_VISIBILITY
ios_base::iostate
ios_base::exceptions() const
{
return __exceptions_;
}
inline _LIBCPP_INLINE_VISIBILITY
void
ios_base::exceptions(iostate __iostate)
{
__exceptions_ = __iostate;
clear(__rdstate_);
}
#if defined(_LIBCPP_CXX03_LANG)
struct _LIBCPP_TYPE_VIS __cxx03_bool {
typedef void (__cxx03_bool::*__bool_type)();
void __true_value() {}
};
#endif
template <class _CharT, class _Traits>
class _LIBCPP_TEMPLATE_VIS basic_ios
: public ios_base
{
public:
// types:
typedef _CharT char_type;
typedef _Traits traits_type;
typedef typename traits_type::int_type int_type;
typedef typename traits_type::pos_type pos_type;
typedef typename traits_type::off_type off_type;
static_assert((is_same<_CharT, typename traits_type::char_type>::value),
"traits_type::char_type must be the same type as CharT");
// __true_value will generate undefined references when linking unless
// we give it internal linkage.
#if defined(_LIBCPP_CXX03_LANG)
_LIBCPP_INLINE_VISIBILITY
operator __cxx03_bool::__bool_type() const {
return !fail() ? &__cxx03_bool::__true_value : nullptr;
}
#else
_LIBCPP_INLINE_VISIBILITY
_LIBCPP_EXPLICIT operator bool() const {return !fail();}
#endif
_LIBCPP_INLINE_VISIBILITY bool operator!() const {return fail();}
_LIBCPP_INLINE_VISIBILITY iostate rdstate() const {return ios_base::rdstate();}
_LIBCPP_INLINE_VISIBILITY void clear(iostate __state = goodbit) {ios_base::clear(__state);}
_LIBCPP_INLINE_VISIBILITY void setstate(iostate __state) {ios_base::setstate(__state);}
_LIBCPP_INLINE_VISIBILITY bool good() const {return ios_base::good();}
_LIBCPP_INLINE_VISIBILITY bool eof() const {return ios_base::eof();}
_LIBCPP_INLINE_VISIBILITY bool fail() const {return ios_base::fail();}
_LIBCPP_INLINE_VISIBILITY bool bad() const {return ios_base::bad();}
_LIBCPP_INLINE_VISIBILITY iostate exceptions() const {return ios_base::exceptions();}
_LIBCPP_INLINE_VISIBILITY void exceptions(iostate __iostate) {ios_base::exceptions(__iostate);}
// 27.5.4.1 Constructor/destructor:
_LIBCPP_INLINE_VISIBILITY
explicit basic_ios(basic_streambuf<char_type,traits_type>* __sb);
virtual ~basic_ios();
// 27.5.4.2 Members:
_LIBCPP_INLINE_VISIBILITY
basic_ostream<char_type, traits_type>* tie() const;
_LIBCPP_INLINE_VISIBILITY
basic_ostream<char_type, traits_type>* tie(basic_ostream<char_type, traits_type>* __tiestr);
_LIBCPP_INLINE_VISIBILITY
basic_streambuf<char_type, traits_type>* rdbuf() const;
_LIBCPP_INLINE_VISIBILITY
basic_streambuf<char_type, traits_type>* rdbuf(basic_streambuf<char_type, traits_type>* __sb);
basic_ios& copyfmt(const basic_ios& __rhs);
_LIBCPP_INLINE_VISIBILITY
char_type fill() const;
_LIBCPP_INLINE_VISIBILITY
char_type fill(char_type __ch);
_LIBCPP_INLINE_VISIBILITY
locale imbue(const locale& __loc);
_LIBCPP_INLINE_VISIBILITY
char narrow(char_type __c, char __dfault) const;
_LIBCPP_INLINE_VISIBILITY
char_type widen(char __c) const;
protected:
_LIBCPP_INLINE_VISIBILITY
basic_ios() {// purposefully does no initialization
}
_LIBCPP_INLINE_VISIBILITY
void init(basic_streambuf<char_type, traits_type>* __sb);
_LIBCPP_INLINE_VISIBILITY
void move(basic_ios& __rhs);
#ifndef _LIBCPP_CXX03_LANG
_LIBCPP_INLINE_VISIBILITY
void move(basic_ios&& __rhs) {move(__rhs);}
#endif
_LIBCPP_INLINE_VISIBILITY
void swap(basic_ios& __rhs) _NOEXCEPT;
_LIBCPP_INLINE_VISIBILITY
void set_rdbuf(basic_streambuf<char_type, traits_type>* __sb);
private:
basic_ostream<char_type, traits_type>* __tie_;
mutable int_type __fill_;
};
template <class _CharT, class _Traits>
inline _LIBCPP_INLINE_VISIBILITY
basic_ios<_CharT, _Traits>::basic_ios(basic_streambuf<char_type,traits_type>* __sb)
{
init(__sb);
}
template <class _CharT, class _Traits>
basic_ios<_CharT, _Traits>::~basic_ios()
{
}
template <class _CharT, class _Traits>
inline _LIBCPP_INLINE_VISIBILITY
void
basic_ios<_CharT, _Traits>::init(basic_streambuf<char_type, traits_type>* __sb)
{
ios_base::init(__sb);
__tie_ = 0;
__fill_ = traits_type::eof();
}
template <class _CharT, class _Traits>
inline _LIBCPP_INLINE_VISIBILITY
basic_ostream<_CharT, _Traits>*
basic_ios<_CharT, _Traits>::tie() const
{
return __tie_;
}
template <class _CharT, class _Traits>
inline _LIBCPP_INLINE_VISIBILITY
basic_ostream<_CharT, _Traits>*
basic_ios<_CharT, _Traits>::tie(basic_ostream<char_type, traits_type>* __tiestr)
{
basic_ostream<char_type, traits_type>* __r = __tie_;
__tie_ = __tiestr;
return __r;
}
template <class _CharT, class _Traits>
inline _LIBCPP_INLINE_VISIBILITY
basic_streambuf<_CharT, _Traits>*
basic_ios<_CharT, _Traits>::rdbuf() const
{
return static_cast<basic_streambuf<char_type, traits_type>*>(ios_base::rdbuf());
}
template <class _CharT, class _Traits>
inline _LIBCPP_INLINE_VISIBILITY
basic_streambuf<_CharT, _Traits>*
basic_ios<_CharT, _Traits>::rdbuf(basic_streambuf<char_type, traits_type>* __sb)
{
basic_streambuf<char_type, traits_type>* __r = rdbuf();
ios_base::rdbuf(__sb);
return __r;
}
template <class _CharT, class _Traits>
inline _LIBCPP_INLINE_VISIBILITY
locale
basic_ios<_CharT, _Traits>::imbue(const locale& __loc)
{
locale __r = getloc();
ios_base::imbue(__loc);
if (rdbuf())
rdbuf()->pubimbue(__loc);
return __r;
}
template <class _CharT, class _Traits>
inline _LIBCPP_INLINE_VISIBILITY
char
basic_ios<_CharT, _Traits>::narrow(char_type __c, char __dfault) const
{
return use_facet<ctype<char_type> >(getloc()).narrow(__c, __dfault);
}
template <class _CharT, class _Traits>
inline _LIBCPP_INLINE_VISIBILITY
_CharT
basic_ios<_CharT, _Traits>::widen(char __c) const
{
return use_facet<ctype<char_type> >(getloc()).widen(__c);
}
template <class _CharT, class _Traits>
inline _LIBCPP_INLINE_VISIBILITY
_CharT
basic_ios<_CharT, _Traits>::fill() const
{
if (traits_type::eq_int_type(traits_type::eof(), __fill_))
__fill_ = widen(' ');
return __fill_;
}
template <class _CharT, class _Traits>
inline _LIBCPP_INLINE_VISIBILITY
_CharT
basic_ios<_CharT, _Traits>::fill(char_type __ch)
{
char_type __r = __fill_;
__fill_ = __ch;
return __r;
}
template <class _CharT, class _Traits>
basic_ios<_CharT, _Traits>&
basic_ios<_CharT, _Traits>::copyfmt(const basic_ios& __rhs)
{
if (this != &__rhs)
{
__call_callbacks(erase_event);
ios_base::copyfmt(__rhs);
__tie_ = __rhs.__tie_;
__fill_ = __rhs.__fill_;
__call_callbacks(copyfmt_event);
exceptions(__rhs.exceptions());
}
return *this;
}
template <class _CharT, class _Traits>
inline _LIBCPP_INLINE_VISIBILITY
void
basic_ios<_CharT, _Traits>::move(basic_ios& __rhs)
{
ios_base::move(__rhs);
__tie_ = __rhs.__tie_;
__rhs.__tie_ = 0;
__fill_ = __rhs.__fill_;
}
template <class _CharT, class _Traits>
inline _LIBCPP_INLINE_VISIBILITY
void
basic_ios<_CharT, _Traits>::swap(basic_ios& __rhs) _NOEXCEPT
{
ios_base::swap(__rhs);
_VSTD::swap(__tie_, __rhs.__tie_);
_VSTD::swap(__fill_, __rhs.__fill_);
}
template <class _CharT, class _Traits>
inline _LIBCPP_INLINE_VISIBILITY
void
basic_ios<_CharT, _Traits>::set_rdbuf(basic_streambuf<char_type, traits_type>* __sb)
{
ios_base::set_rdbuf(__sb);
}
inline _LIBCPP_INLINE_VISIBILITY
ios_base&
boolalpha(ios_base& __str)
{
__str.setf(ios_base::boolalpha);
return __str;
}
inline _LIBCPP_INLINE_VISIBILITY
ios_base&
noboolalpha(ios_base& __str)
{
__str.unsetf(ios_base::boolalpha);
return __str;
}
inline _LIBCPP_INLINE_VISIBILITY
ios_base&
showbase(ios_base& __str)
{
__str.setf(ios_base::showbase);
return __str;
}
inline _LIBCPP_INLINE_VISIBILITY
ios_base&
noshowbase(ios_base& __str)
{
__str.unsetf(ios_base::showbase);
return __str;
}
inline _LIBCPP_INLINE_VISIBILITY
ios_base&
showpoint(ios_base& __str)
{
__str.setf(ios_base::showpoint);
return __str;
}
inline _LIBCPP_INLINE_VISIBILITY
ios_base&
noshowpoint(ios_base& __str)
{
__str.unsetf(ios_base::showpoint);
return __str;
}
inline _LIBCPP_INLINE_VISIBILITY
ios_base&
showpos(ios_base& __str)
{
__str.setf(ios_base::showpos);
return __str;
}
inline _LIBCPP_INLINE_VISIBILITY
ios_base&
noshowpos(ios_base& __str)
{
__str.unsetf(ios_base::showpos);
return __str;
}
inline _LIBCPP_INLINE_VISIBILITY
ios_base&
skipws(ios_base& __str)
{
__str.setf(ios_base::skipws);
return __str;
}
inline _LIBCPP_INLINE_VISIBILITY
ios_base&
noskipws(ios_base& __str)
{
__str.unsetf(ios_base::skipws);
return __str;
}
inline _LIBCPP_INLINE_VISIBILITY
ios_base&
uppercase(ios_base& __str)
{
__str.setf(ios_base::uppercase);
return __str;
}
inline _LIBCPP_INLINE_VISIBILITY
ios_base&
nouppercase(ios_base& __str)
{
__str.unsetf(ios_base::uppercase);
return __str;
}
inline _LIBCPP_INLINE_VISIBILITY
ios_base&
unitbuf(ios_base& __str)
{
__str.setf(ios_base::unitbuf);
return __str;
}
inline _LIBCPP_INLINE_VISIBILITY
ios_base&
nounitbuf(ios_base& __str)
{
__str.unsetf(ios_base::unitbuf);
return __str;
}
inline _LIBCPP_INLINE_VISIBILITY
ios_base&
internal(ios_base& __str)
{
__str.setf(ios_base::internal, ios_base::adjustfield);
return __str;
}
inline _LIBCPP_INLINE_VISIBILITY
ios_base&
left(ios_base& __str)
{
__str.setf(ios_base::left, ios_base::adjustfield);
return __str;
}
inline _LIBCPP_INLINE_VISIBILITY
ios_base&
right(ios_base& __str)
{
__str.setf(ios_base::right, ios_base::adjustfield);
return __str;
}
inline _LIBCPP_INLINE_VISIBILITY
ios_base&
dec(ios_base& __str)
{
__str.setf(ios_base::dec, ios_base::basefield);
return __str;
}
inline _LIBCPP_INLINE_VISIBILITY
ios_base&
hex(ios_base& __str)
{
__str.setf(ios_base::hex, ios_base::basefield);
return __str;
}
inline _LIBCPP_INLINE_VISIBILITY
ios_base&
oct(ios_base& __str)
{
__str.setf(ios_base::oct, ios_base::basefield);
return __str;
}
inline _LIBCPP_INLINE_VISIBILITY
ios_base&
fixed(ios_base& __str)
{
__str.setf(ios_base::fixed, ios_base::floatfield);
return __str;
}
inline _LIBCPP_INLINE_VISIBILITY
ios_base&
scientific(ios_base& __str)
{
__str.setf(ios_base::scientific, ios_base::floatfield);
return __str;
}
inline _LIBCPP_INLINE_VISIBILITY
ios_base&
hexfloat(ios_base& __str)
{
__str.setf(ios_base::fixed | ios_base::scientific, ios_base::floatfield);
return __str;
}
inline _LIBCPP_INLINE_VISIBILITY
ios_base&
defaultfloat(ios_base& __str)
{
__str.unsetf(ios_base::floatfield);
return __str;
}
template <class _CharT, class _Traits>
class __save_flags
{
typedef basic_ios<_CharT, _Traits> __stream_type;
typedef typename __stream_type::fmtflags fmtflags;
__stream_type& __stream_;
fmtflags __fmtflags_;
_CharT __fill_;
__save_flags(const __save_flags&);
__save_flags& operator=(const __save_flags&);
public:
_LIBCPP_INLINE_VISIBILITY
explicit __save_flags(__stream_type& __stream)
: __stream_(__stream),
__fmtflags_(__stream.flags()),
__fill_(__stream.fill())
{}
_LIBCPP_INLINE_VISIBILITY
~__save_flags()
{
__stream_.flags(__fmtflags_);
__stream_.fill(__fill_);
}
};
_LIBCPP_END_NAMESPACE_STD
#endif // _LIBCPP_IOS
| 26,281 | 1,067 | jart/cosmopolitan | false |
cosmopolitan/third_party/libcxx/cstddef | // -*- C++ -*-
//===--------------------------- cstddef ----------------------------------===//
//
// 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_CSTDDEF
#define _LIBCPP_CSTDDEF
/*
cstddef synopsis
Macros:
offsetof(type,member-designator)
NULL
namespace std
{
Types:
ptrdiff_t
size_t
max_align_t
nullptr_t
byte // C++17
} // std
*/
#include "third_party/libcxx/__config"
#include "third_party/libcxx/version"
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
#pragma GCC system_header
#endif
// Don't include our own <stddef.h>; we don't want to declare ::nullptr_t.
// #include_next <stddef.h>
#include "third_party/libcxx/__nullptr"
_LIBCPP_BEGIN_NAMESPACE_STD
using ::ptrdiff_t;
using ::size_t;
#if defined(__CLANG_MAX_ALIGN_T_DEFINED) || defined(_GCC_MAX_ALIGN_T) || \
defined(__DEFINED_max_align_t) || defined(__NetBSD__)
// Re-use the compiler's <stddef.h> max_align_t where possible.
using ::max_align_t;
#else
typedef long double max_align_t;
#endif
_LIBCPP_END_NAMESPACE_STD
#if _LIBCPP_STD_VER > 14
namespace std // purposefully not versioned
{
enum class byte : unsigned char {};
constexpr byte operator| (byte __lhs, byte __rhs) noexcept
{
return static_cast<byte>(
static_cast<unsigned char>(
static_cast<unsigned int>(__lhs) | static_cast<unsigned int>(__rhs)
));
}
constexpr byte& operator|=(byte& __lhs, byte __rhs) noexcept
{ return __lhs = __lhs | __rhs; }
constexpr byte operator& (byte __lhs, byte __rhs) noexcept
{
return static_cast<byte>(
static_cast<unsigned char>(
static_cast<unsigned int>(__lhs) & static_cast<unsigned int>(__rhs)
));
}
constexpr byte& operator&=(byte& __lhs, byte __rhs) noexcept
{ return __lhs = __lhs & __rhs; }
constexpr byte operator^ (byte __lhs, byte __rhs) noexcept
{
return static_cast<byte>(
static_cast<unsigned char>(
static_cast<unsigned int>(__lhs) ^ static_cast<unsigned int>(__rhs)
));
}
constexpr byte& operator^=(byte& __lhs, byte __rhs) noexcept
{ return __lhs = __lhs ^ __rhs; }
constexpr byte operator~ (byte __b) noexcept
{
return static_cast<byte>(
static_cast<unsigned char>(
~static_cast<unsigned int>(__b)
));
}
}
#include "third_party/libcxx/type_traits" // rest of byte
#endif
#endif // _LIBCPP_CSTDDEF
| 2,594 | 114 | jart/cosmopolitan | false |
cosmopolitan/third_party/libcxx/refstring.hh | //===------------------------ __refstring ---------------------------------===//
//
// 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_REFSTRING_H
#define _LIBCPP_REFSTRING_H
#include "third_party/libcxx/__config"
#include "third_party/libcxx/stdexcept"
#include "third_party/libcxx/cstddef"
#include "third_party/libcxx/cstring"
#include "third_party/libcxx/atomic_support.hh"
_LIBCPP_BEGIN_NAMESPACE_STD
namespace __refstring_imp {
namespace {
typedef int count_t;
struct _Rep_base {
std::size_t len;
std::size_t cap;
count_t count;
};
inline _Rep_base* rep_from_data(const char* data_) noexcept {
char* data = const_cast<char*>(data_);
return reinterpret_cast<_Rep_base*>(data - sizeof(_Rep_base));
}
inline char* data_from_rep(_Rep_base* rep) noexcept {
char* data = reinterpret_cast<char*>(rep);
return data + sizeof(*rep);
}
#if defined(__APPLE__)
inline const char* compute_gcc_empty_string_storage() _NOEXCEPT {
void* handle = dlopen("/usr/lib/libstdc++.6.dylib", RTLD_NOLOAD);
if (handle == nullptr)
return nullptr;
void* sym = dlsym(handle, "_ZNSs4_Rep20_S_empty_rep_storageE");
if (sym == nullptr)
return nullptr;
return data_from_rep(reinterpret_cast<_Rep_base*>(sym));
}
inline const char* get_gcc_empty_string_storage() _NOEXCEPT {
static const char* p = compute_gcc_empty_string_storage();
return p;
}
#endif
} // namespace
} // namespace __refstring_imp
using namespace __refstring_imp;
inline __libcpp_refstring::__libcpp_refstring(const char* msg) {
std::size_t len = strlen(msg);
_Rep_base* rep =
static_cast<_Rep_base*>(::operator new(sizeof(*rep) + len + 1));
rep->len = len;
rep->cap = len;
rep->count = 0;
char* data = data_from_rep(rep);
std::memcpy(data, msg, len + 1);
__imp_ = data;
}
inline __libcpp_refstring::__libcpp_refstring(
const __libcpp_refstring& s) _NOEXCEPT : __imp_(s.__imp_) {
if (__uses_refcount())
__libcpp_atomic_add(&rep_from_data(__imp_)->count, 1);
}
inline __libcpp_refstring&
__libcpp_refstring::operator=(__libcpp_refstring const& s) _NOEXCEPT {
bool adjust_old_count = __uses_refcount();
struct _Rep_base* old_rep = rep_from_data(__imp_);
__imp_ = s.__imp_;
if (__uses_refcount())
__libcpp_atomic_add(&rep_from_data(__imp_)->count, 1);
if (adjust_old_count) {
if (__libcpp_atomic_add(&old_rep->count, count_t(-1)) < 0) {
::operator delete(old_rep);
}
}
return *this;
}
inline __libcpp_refstring::~__libcpp_refstring() {
if (__uses_refcount()) {
_Rep_base* rep = rep_from_data(__imp_);
if (__libcpp_atomic_add(&rep->count, count_t(-1)) < 0) {
::operator delete(rep);
}
}
}
inline bool __libcpp_refstring::__uses_refcount() const {
#ifdef __APPLE__
return __imp_ != get_gcc_empty_string_storage();
#else
return true;
#endif
}
_LIBCPP_END_NAMESPACE_STD
#endif //_LIBCPP_REFSTRING_H
| 3,125 | 115 | jart/cosmopolitan | false |
cosmopolitan/third_party/libcxx/errno.h | // -*- C++ -*-
//===-------------------------- errno.h -----------------------------------===//
//
// 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_ERRNO_H
#define _LIBCPP_ERRNO_H
/*
errno.h synopsis
Macros:
EDOM
EILSEQ // C99
ERANGE
errno
*/
#include "third_party/libcxx/__config"
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
#pragma GCC system_header
#endif
#include "libc/isystem/errno.h"
#ifdef __cplusplus
#if !defined(EOWNERDEAD) || !defined(ENOTRECOVERABLE)
#ifdef ELAST
static const int __elast1 = ELAST + 1;
static const int __elast2 = ELAST + 2;
#else
static const int __elast1 = 104;
static const int __elast2 = 105;
#endif
#ifdef ENOTRECOVERABLE
#define EOWNERDEAD __elast1
#ifdef ELAST
#undef ELAST
#define ELAST EOWNERDEAD
#endif
#elif defined(EOWNERDEAD)
#define ENOTRECOVERABLE __elast1
#ifdef ELAST
#undef ELAST
#define ELAST ENOTRECOVERABLE
#endif
#else // defined(EOWNERDEAD)
#define EOWNERDEAD __elast1
#define ENOTRECOVERABLE __elast2
#ifdef ELAST
#undef ELAST
#define ELAST ENOTRECOVERABLE
#endif
#endif // defined(EOWNERDEAD)
#endif // !defined(EOWNERDEAD) || !defined(ENOTRECOVERABLE)
// supply errno values likely to be missing, particularly on Windows
#endif // __cplusplus
#endif // _LIBCPP_ERRNO_H
| 1,532 | 84 | jart/cosmopolitan | false |
cosmopolitan/third_party/libcxx/__debug | // -*- C++ -*-
//===--------------------------- __debug ----------------------------------===//
//
// 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_DEBUG_H
#define _LIBCPP_DEBUG_H
#include "third_party/libcxx/__config"
#include "third_party/libcxx/iosfwd"
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
#pragma GCC system_header
#endif
#if defined(_LIBCPP_HAS_NO_NULLPTR)
#include "third_party/libcxx/cstddef"
#endif
#if _LIBCPP_DEBUG_LEVEL >= 1 || defined(_LIBCPP_BUILDING_LIBRARY)
#include "third_party/libcxx/cstdlib"
#include "third_party/libcxx/cstdio"
#include "third_party/libcxx/cstddef"
#endif
#if _LIBCPP_DEBUG_LEVEL >= 1 && !defined(_LIBCPP_ASSERT)
# define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : \
_VSTD::__libcpp_debug_function(_VSTD::__libcpp_debug_info(__FILE__, __LINE__, #x, m)))
#endif
#if _LIBCPP_DEBUG_LEVEL >= 2
#ifndef _LIBCPP_DEBUG_ASSERT
#define _LIBCPP_DEBUG_ASSERT(x, m) _LIBCPP_ASSERT(x, m)
#endif
#define _LIBCPP_DEBUG_MODE(...) __VA_ARGS__
#endif
#ifndef _LIBCPP_ASSERT
# define _LIBCPP_ASSERT(x, m) ((void)0)
#endif
#ifndef _LIBCPP_DEBUG_ASSERT
# define _LIBCPP_DEBUG_ASSERT(x, m) ((void)0)
#endif
#ifndef _LIBCPP_DEBUG_MODE
#define _LIBCPP_DEBUG_MODE(...) ((void)0)
#endif
_LIBCPP_BEGIN_NAMESPACE_STD
struct _LIBCPP_TEMPLATE_VIS __libcpp_debug_info {
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
__libcpp_debug_info()
: __file_(nullptr), __line_(-1), __pred_(nullptr), __msg_(nullptr) {}
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
__libcpp_debug_info(const char* __f, int __l, const char* __p, const char* __m)
: __file_(__f), __line_(__l), __pred_(__p), __msg_(__m) {}
_LIBCPP_FUNC_VIS std::string what() const;
const char* __file_;
int __line_;
const char* __pred_;
const char* __msg_;
};
/// __libcpp_debug_function_type - The type of the assertion failure handler.
typedef void(*__libcpp_debug_function_type)(__libcpp_debug_info const&);
/// __libcpp_debug_function - The handler function called when a _LIBCPP_ASSERT
/// fails.
extern _LIBCPP_EXPORTED_FROM_ABI __libcpp_debug_function_type __libcpp_debug_function;
/// __libcpp_abort_debug_function - A debug handler that aborts when called.
_LIBCPP_NORETURN _LIBCPP_FUNC_VIS
void __libcpp_abort_debug_function(__libcpp_debug_info const&);
/// __libcpp_set_debug_function - Set the debug handler to the specified
/// function.
_LIBCPP_FUNC_VIS
bool __libcpp_set_debug_function(__libcpp_debug_function_type __func);
#if _LIBCPP_DEBUG_LEVEL >= 2 || defined(_LIBCPP_BUILDING_LIBRARY)
struct _LIBCPP_TYPE_VIS __c_node;
struct _LIBCPP_TYPE_VIS __i_node
{
void* __i_;
__i_node* __next_;
__c_node* __c_;
#ifndef _LIBCPP_CXX03_LANG
__i_node(const __i_node&) = delete;
__i_node& operator=(const __i_node&) = delete;
#else
private:
__i_node(const __i_node&);
__i_node& operator=(const __i_node&);
public:
#endif
_LIBCPP_INLINE_VISIBILITY
__i_node(void* __i, __i_node* __next, __c_node* __c)
: __i_(__i), __next_(__next), __c_(__c) {}
~__i_node();
};
struct _LIBCPP_TYPE_VIS __c_node
{
void* __c_;
__c_node* __next_;
__i_node** beg_;
__i_node** end_;
__i_node** cap_;
#ifndef _LIBCPP_CXX03_LANG
__c_node(const __c_node&) = delete;
__c_node& operator=(const __c_node&) = delete;
#else
private:
__c_node(const __c_node&);
__c_node& operator=(const __c_node&);
public:
#endif
_LIBCPP_INLINE_VISIBILITY
__c_node(void* __c, __c_node* __next)
: __c_(__c), __next_(__next), beg_(nullptr), end_(nullptr), cap_(nullptr) {}
virtual ~__c_node();
virtual bool __dereferenceable(const void*) const = 0;
virtual bool __decrementable(const void*) const = 0;
virtual bool __addable(const void*, ptrdiff_t) const = 0;
virtual bool __subscriptable(const void*, ptrdiff_t) const = 0;
void __add(__i_node* __i);
_LIBCPP_HIDDEN void __remove(__i_node* __i);
};
template <class _Cont>
struct _C_node
: public __c_node
{
_C_node(void* __c, __c_node* __n)
: __c_node(__c, __n) {}
virtual bool __dereferenceable(const void*) const;
virtual bool __decrementable(const void*) const;
virtual bool __addable(const void*, ptrdiff_t) const;
virtual bool __subscriptable(const void*, ptrdiff_t) const;
};
template <class _Cont>
inline bool
_C_node<_Cont>::__dereferenceable(const void* __i) const
{
typedef typename _Cont::const_iterator iterator;
const iterator* __j = static_cast<const iterator*>(__i);
_Cont* _Cp = static_cast<_Cont*>(__c_);
return _Cp->__dereferenceable(__j);
}
template <class _Cont>
inline bool
_C_node<_Cont>::__decrementable(const void* __i) const
{
typedef typename _Cont::const_iterator iterator;
const iterator* __j = static_cast<const iterator*>(__i);
_Cont* _Cp = static_cast<_Cont*>(__c_);
return _Cp->__decrementable(__j);
}
template <class _Cont>
inline bool
_C_node<_Cont>::__addable(const void* __i, ptrdiff_t __n) const
{
typedef typename _Cont::const_iterator iterator;
const iterator* __j = static_cast<const iterator*>(__i);
_Cont* _Cp = static_cast<_Cont*>(__c_);
return _Cp->__addable(__j, __n);
}
template <class _Cont>
inline bool
_C_node<_Cont>::__subscriptable(const void* __i, ptrdiff_t __n) const
{
typedef typename _Cont::const_iterator iterator;
const iterator* __j = static_cast<const iterator*>(__i);
_Cont* _Cp = static_cast<_Cont*>(__c_);
return _Cp->__subscriptable(__j, __n);
}
class _LIBCPP_TYPE_VIS __libcpp_db
{
__c_node** __cbeg_;
__c_node** __cend_;
size_t __csz_;
__i_node** __ibeg_;
__i_node** __iend_;
size_t __isz_;
__libcpp_db();
public:
#ifndef _LIBCPP_CXX03_LANG
__libcpp_db(const __libcpp_db&) = delete;
__libcpp_db& operator=(const __libcpp_db&) = delete;
#else
private:
__libcpp_db(const __libcpp_db&);
__libcpp_db& operator=(const __libcpp_db&);
public:
#endif
~__libcpp_db();
class __db_c_iterator;
class __db_c_const_iterator;
class __db_i_iterator;
class __db_i_const_iterator;
__db_c_const_iterator __c_end() const;
__db_i_const_iterator __i_end() const;
typedef __c_node*(_InsertConstruct)(void*, void*, __c_node*);
template <class _Cont>
_LIBCPP_INLINE_VISIBILITY static __c_node* __create_C_node(void *__mem, void *__c, __c_node *__next) {
return ::new(__mem) _C_node<_Cont>(__c, __next);
}
template <class _Cont>
_LIBCPP_INLINE_VISIBILITY
void __insert_c(_Cont* __c)
{
__insert_c(static_cast<void*>(__c), &__create_C_node<_Cont>);
}
void __insert_i(void* __i);
void __insert_c(void* __c, _InsertConstruct* __fn);
void __erase_c(void* __c);
void __insert_ic(void* __i, const void* __c);
void __iterator_copy(void* __i, const void* __i0);
void __erase_i(void* __i);
void* __find_c_from_i(void* __i) const;
void __invalidate_all(void* __c);
__c_node* __find_c_and_lock(void* __c) const;
__c_node* __find_c(void* __c) const;
void unlock() const;
void swap(void* __c1, void* __c2);
bool __dereferenceable(const void* __i) const;
bool __decrementable(const void* __i) const;
bool __addable(const void* __i, ptrdiff_t __n) const;
bool __subscriptable(const void* __i, ptrdiff_t __n) const;
bool __less_than_comparable(const void* __i, const void* __j) const;
private:
_LIBCPP_HIDDEN
__i_node* __insert_iterator(void* __i);
_LIBCPP_HIDDEN
__i_node* __find_iterator(const void* __i) const;
friend _LIBCPP_FUNC_VIS __libcpp_db* __get_db();
};
_LIBCPP_FUNC_VIS __libcpp_db* __get_db();
_LIBCPP_FUNC_VIS const __libcpp_db* __get_const_db();
#endif // _LIBCPP_DEBUG_LEVEL >= 2 || defined(_LIBCPP_BUILDING_LIBRARY)
_LIBCPP_END_NAMESPACE_STD
#endif // _LIBCPP_DEBUG_H
| 8,060 | 280 | jart/cosmopolitan | false |
cosmopolitan/third_party/libcxx/cstdint | // -*- C++ -*-
//===--------------------------- cstdint ----------------------------------===//
//
// 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_CSTDINT
#define _LIBCPP_CSTDINT
#include "libc/inttypes.h"
#include "libc/calls/weirdtypes.h"
#include "third_party/libcxx/__config"
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
#pragma GCC system_header
#endif
_LIBCPP_BEGIN_NAMESPACE_STD
/*
cstdint synopsis
Macros:
INT8_MIN
INT16_MIN
INT32_MIN
INT64_MIN
INT8_MAX
INT16_MAX
INT32_MAX
INT64_MAX
UINT8_MAX
UINT16_MAX
UINT32_MAX
UINT64_MAX
INT_LEAST8_MIN
INT_LEAST16_MIN
INT_LEAST32_MIN
INT_LEAST64_MIN
INT_LEAST8_MAX
INT_LEAST16_MAX
INT_LEAST32_MAX
INT_LEAST64_MAX
UINT_LEAST8_MAX
UINT_LEAST16_MAX
UINT_LEAST32_MAX
UINT_LEAST64_MAX
INT_FAST8_MIN
INT_FAST16_MIN
INT_FAST32_MIN
INT_FAST64_MIN
INT_FAST8_MAX
INT_FAST16_MAX
INT_FAST32_MAX
INT_FAST64_MAX
UINT_FAST8_MAX
UINT_FAST16_MAX
UINT_FAST32_MAX
UINT_FAST64_MAX
INTPTR_MIN
INTPTR_MAX
UINTPTR_MAX
INTMAX_MIN
INTMAX_MAX
UINTMAX_MAX
PTRDIFF_MIN
PTRDIFF_MAX
SIG_ATOMIC_MIN
SIG_ATOMIC_MAX
SIZE_MAX
WCHAR_MIN
WCHAR_MAX
WINT_MIN
WINT_MAX
INT8_C(value)
INT16_C(value)
INT32_C(value)
INT64_C(value)
UINT8_C(value)
UINT16_C(value)
UINT32_C(value)
UINT64_C(value)
INTMAX_C(value)
UINTMAX_C(value)
namespace std
{
Types:
int8_t
int16_t
int32_t
int64_t
uint8_t
uint16_t
uint32_t
uint64_t
int_least8_t
int_least16_t
int_least32_t
int_least64_t
uint_least8_t
uint_least16_t
uint_least32_t
uint_least64_t
int_fast8_t
int_fast16_t
int_fast32_t
int_fast64_t
uint_fast8_t
uint_fast16_t
uint_fast32_t
uint_fast64_t
intptr_t
uintptr_t
intmax_t
uintmax_t
} // std
*/
using::int8_t;
using::int16_t;
using::int32_t;
using::int64_t;
using::uint8_t;
using::uint16_t;
using::uint32_t;
using::uint64_t;
using::int_least8_t;
using::int_least16_t;
using::int_least32_t;
using::int_least64_t;
using::uint_least8_t;
using::uint_least16_t;
using::uint_least32_t;
using::uint_least64_t;
using::int_fast8_t;
using::int_fast16_t;
using::int_fast32_t;
using::int_fast64_t;
using::uint_fast8_t;
using::uint_fast16_t;
using::uint_fast32_t;
using::uint_fast64_t;
using::intptr_t;
using::uintptr_t;
using::intmax_t;
using::uintmax_t;
_LIBCPP_END_NAMESPACE_STD
#endif // _LIBCPP_CSTDINT
| 2,859 | 192 | jart/cosmopolitan | false |
cosmopolitan/third_party/libcxx/stack | // -*- C++ -*-
// clang-format off
//===---------------------------- stack -----------------------------------===//
//
// 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_STACK
#define _LIBCPP_STACK
#include "third_party/libcxx/__config"
#include "third_party/libcxx/deque"
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
#pragma GCC system_header
#endif
_LIBCPP_BEGIN_NAMESPACE_STD
/*
stack synopsis
namespace std
{
template <class T, class Container = deque<T>>
class stack
{
public:
typedef Container container_type;
typedef typename container_type::value_type value_type;
typedef typename container_type::reference reference;
typedef typename container_type::const_reference const_reference;
typedef typename container_type::size_type size_type;
protected:
container_type c;
public:
stack() = default;
~stack() = default;
stack(const stack& q) = default;
stack(stack&& q) = default;
stack& operator=(const stack& q) = default;
stack& operator=(stack&& q) = default;
explicit stack(const container_type& c);
explicit stack(container_type&& c);
template <class Alloc> explicit stack(const Alloc& a);
template <class Alloc> stack(const container_type& c, const Alloc& a);
template <class Alloc> stack(container_type&& c, const Alloc& a);
template <class Alloc> stack(const stack& c, const Alloc& a);
template <class Alloc> stack(stack&& c, const Alloc& a);
bool empty() const;
size_type size() const;
reference top();
const_reference top() const;
void push(const value_type& x);
void push(value_type&& x);
template <class... Args> reference emplace(Args&&... args); // reference in C++17
void pop();
void swap(stack& c) noexcept(is_nothrow_swappable_v<Container>)
};
template<class Container>
stack(Container) -> stack<typename Container::value_type, Container>; // C++17
template<class Container, class Allocator>
stack(Container, Allocator) -> stack<typename Container::value_type, Container>; // C++17
template <class T, class Container>
bool operator==(const stack<T, Container>& x, const stack<T, Container>& y);
template <class T, class Container>
bool operator< (const stack<T, Container>& x, const stack<T, Container>& y);
template <class T, class Container>
bool operator!=(const stack<T, Container>& x, const stack<T, Container>& y);
template <class T, class Container>
bool operator> (const stack<T, Container>& x, const stack<T, Container>& y);
template <class T, class Container>
bool operator>=(const stack<T, Container>& x, const stack<T, Container>& y);
template <class T, class Container>
bool operator<=(const stack<T, Container>& x, const stack<T, Container>& y);
template <class T, class Container>
void swap(stack<T, Container>& x, stack<T, Container>& y)
noexcept(noexcept(x.swap(y)));
} // std
*/
template <class _Tp, class _Container = deque<_Tp> > class _LIBCPP_TEMPLATE_VIS stack;
template <class _Tp, class _Container>
_LIBCPP_INLINE_VISIBILITY
bool
operator==(const stack<_Tp, _Container>& __x, const stack<_Tp, _Container>& __y);
template <class _Tp, class _Container>
_LIBCPP_INLINE_VISIBILITY
bool
operator< (const stack<_Tp, _Container>& __x, const stack<_Tp, _Container>& __y);
template <class _Tp, class _Container /*= deque<_Tp>*/>
class _LIBCPP_TEMPLATE_VIS stack
{
public:
typedef _Container container_type;
typedef typename container_type::value_type value_type;
typedef typename container_type::reference reference;
typedef typename container_type::const_reference const_reference;
typedef typename container_type::size_type size_type;
static_assert((is_same<_Tp, value_type>::value), "" );
protected:
container_type c;
public:
_LIBCPP_INLINE_VISIBILITY
stack()
_NOEXCEPT_(is_nothrow_default_constructible<container_type>::value)
: c() {}
_LIBCPP_INLINE_VISIBILITY
stack(const stack& __q) : c(__q.c) {}
_LIBCPP_INLINE_VISIBILITY
stack& operator=(const stack& __q) {c = __q.c; return *this;}
#ifndef _LIBCPP_CXX03_LANG
_LIBCPP_INLINE_VISIBILITY
stack(stack&& __q)
_NOEXCEPT_(is_nothrow_move_constructible<container_type>::value)
: c(_VSTD::move(__q.c)) {}
_LIBCPP_INLINE_VISIBILITY
stack& operator=(stack&& __q)
_NOEXCEPT_(is_nothrow_move_assignable<container_type>::value)
{c = _VSTD::move(__q.c); return *this;}
_LIBCPP_INLINE_VISIBILITY
explicit stack(container_type&& __c) : c(_VSTD::move(__c)) {}
#endif // _LIBCPP_CXX03_LANG
_LIBCPP_INLINE_VISIBILITY
explicit stack(const container_type& __c) : c(__c) {}
template <class _Alloc>
_LIBCPP_INLINE_VISIBILITY
explicit stack(const _Alloc& __a,
typename enable_if<uses_allocator<container_type,
_Alloc>::value>::type* = 0)
: c(__a) {}
template <class _Alloc>
_LIBCPP_INLINE_VISIBILITY
stack(const container_type& __c, const _Alloc& __a,
typename enable_if<uses_allocator<container_type,
_Alloc>::value>::type* = 0)
: c(__c, __a) {}
template <class _Alloc>
_LIBCPP_INLINE_VISIBILITY
stack(const stack& __s, const _Alloc& __a,
typename enable_if<uses_allocator<container_type,
_Alloc>::value>::type* = 0)
: c(__s.c, __a) {}
#ifndef _LIBCPP_CXX03_LANG
template <class _Alloc>
_LIBCPP_INLINE_VISIBILITY
stack(container_type&& __c, const _Alloc& __a,
typename enable_if<uses_allocator<container_type,
_Alloc>::value>::type* = 0)
: c(_VSTD::move(__c), __a) {}
template <class _Alloc>
_LIBCPP_INLINE_VISIBILITY
stack(stack&& __s, const _Alloc& __a,
typename enable_if<uses_allocator<container_type,
_Alloc>::value>::type* = 0)
: c(_VSTD::move(__s.c), __a) {}
#endif // _LIBCPP_CXX03_LANG
_LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
bool empty() const {return c.empty();}
_LIBCPP_INLINE_VISIBILITY
size_type size() const {return c.size();}
_LIBCPP_INLINE_VISIBILITY
reference top() {return c.back();}
_LIBCPP_INLINE_VISIBILITY
const_reference top() const {return c.back();}
_LIBCPP_INLINE_VISIBILITY
void push(const value_type& __v) {c.push_back(__v);}
#ifndef _LIBCPP_CXX03_LANG
_LIBCPP_INLINE_VISIBILITY
void push(value_type&& __v) {c.push_back(_VSTD::move(__v));}
template <class... _Args>
_LIBCPP_INLINE_VISIBILITY
#if _LIBCPP_STD_VER > 14
decltype(auto) emplace(_Args&&... __args)
{ return c.emplace_back(_VSTD::forward<_Args>(__args)...);}
#else
void emplace(_Args&&... __args)
{ c.emplace_back(_VSTD::forward<_Args>(__args)...);}
#endif
#endif // _LIBCPP_CXX03_LANG
_LIBCPP_INLINE_VISIBILITY
void pop() {c.pop_back();}
_LIBCPP_INLINE_VISIBILITY
void swap(stack& __s)
_NOEXCEPT_(__is_nothrow_swappable<container_type>::value)
{
using _VSTD::swap;
swap(c, __s.c);
}
template <class T1, class _C1>
friend
bool
operator==(const stack<T1, _C1>& __x, const stack<T1, _C1>& __y);
template <class T1, class _C1>
friend
bool
operator< (const stack<T1, _C1>& __x, const stack<T1, _C1>& __y);
};
#ifndef _LIBCPP_HAS_NO_DEDUCTION_GUIDES
template<class _Container,
class = typename enable_if<!__is_allocator<_Container>::value, nullptr_t>::type
>
stack(_Container)
-> stack<typename _Container::value_type, _Container>;
template<class _Container,
class _Alloc,
class = typename enable_if<!__is_allocator<_Container>::value, nullptr_t>::type,
class = typename enable_if< __is_allocator<_Alloc>::value, nullptr_t>::type
>
stack(_Container, _Alloc)
-> stack<typename _Container::value_type, _Container>;
#endif
template <class _Tp, class _Container>
inline _LIBCPP_INLINE_VISIBILITY
bool
operator==(const stack<_Tp, _Container>& __x, const stack<_Tp, _Container>& __y)
{
return __x.c == __y.c;
}
template <class _Tp, class _Container>
inline _LIBCPP_INLINE_VISIBILITY
bool
operator< (const stack<_Tp, _Container>& __x, const stack<_Tp, _Container>& __y)
{
return __x.c < __y.c;
}
template <class _Tp, class _Container>
inline _LIBCPP_INLINE_VISIBILITY
bool
operator!=(const stack<_Tp, _Container>& __x, const stack<_Tp, _Container>& __y)
{
return !(__x == __y);
}
template <class _Tp, class _Container>
inline _LIBCPP_INLINE_VISIBILITY
bool
operator> (const stack<_Tp, _Container>& __x, const stack<_Tp, _Container>& __y)
{
return __y < __x;
}
template <class _Tp, class _Container>
inline _LIBCPP_INLINE_VISIBILITY
bool
operator>=(const stack<_Tp, _Container>& __x, const stack<_Tp, _Container>& __y)
{
return !(__x < __y);
}
template <class _Tp, class _Container>
inline _LIBCPP_INLINE_VISIBILITY
bool
operator<=(const stack<_Tp, _Container>& __x, const stack<_Tp, _Container>& __y)
{
return !(__y < __x);
}
template <class _Tp, class _Container>
inline _LIBCPP_INLINE_VISIBILITY
typename enable_if<
__is_swappable<_Container>::value,
void
>::type
swap(stack<_Tp, _Container>& __x, stack<_Tp, _Container>& __y)
_NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
{
__x.swap(__y);
}
template <class _Tp, class _Container, class _Alloc>
struct _LIBCPP_TEMPLATE_VIS uses_allocator<stack<_Tp, _Container>, _Alloc>
: public uses_allocator<_Container, _Alloc>
{
};
_LIBCPP_END_NAMESPACE_STD
#endif // _LIBCPP_STACK
| 10,150 | 323 | jart/cosmopolitan | false |
cosmopolitan/third_party/libcxx/cerrno | // -*- C++ -*-
//===-------------------------- cerrno ------------------------------------===//
//
// 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_CERRNO
#define _LIBCPP_CERRNO
#include "third_party/libcxx/__config"
#include "third_party/libcxx/errno.h"
/*
cerrno synopsis
Macros:
EDOM
EILSEQ // C99
ERANGE
errno
*/
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
#pragma GCC system_header
#endif
#endif // _LIBCPP_CERRNO
| 707 | 33 | jart/cosmopolitan | false |
cosmopolitan/third_party/libcxx/condition_variable | // -*- C++ -*-
// clang-format off
//===---------------------- condition_variable ----------------------------===//
//
// 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_CONDITION_VARIABLE
#define _LIBCPP_CONDITION_VARIABLE
#include "third_party/libcxx/__config"
#include "third_party/libcxx/__mutex_base"
#include "third_party/libcxx/memory"
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
#pragma GCC system_header
#endif
#ifndef _LIBCPP_HAS_NO_THREADS
_LIBCPP_BEGIN_NAMESPACE_STD
/*
condition_variable synopsis
namespace std
{
enum class cv_status { no_timeout, timeout };
class condition_variable
{
public:
condition_variable();
~condition_variable();
condition_variable(const condition_variable&) = delete;
condition_variable& operator=(const condition_variable&) = delete;
void notify_one() noexcept;
void notify_all() noexcept;
void wait(unique_lock<mutex>& lock);
template <class Predicate>
void wait(unique_lock<mutex>& lock, Predicate pred);
template <class Clock, class Duration>
cv_status
wait_until(unique_lock<mutex>& lock,
const chrono::time_point<Clock, Duration>& abs_time);
template <class Clock, class Duration, class Predicate>
bool
wait_until(unique_lock<mutex>& lock,
const chrono::time_point<Clock, Duration>& abs_time,
Predicate pred);
template <class Rep, class Period>
cv_status
wait_for(unique_lock<mutex>& lock,
const chrono::duration<Rep, Period>& rel_time);
template <class Rep, class Period, class Predicate>
bool
wait_for(unique_lock<mutex>& lock,
const chrono::duration<Rep, Period>& rel_time,
Predicate pred);
typedef pthread_cond_t* native_handle_type;
native_handle_type native_handle();
};
void notify_all_at_thread_exit(condition_variable& cond, unique_lock<mutex> lk);
class condition_variable_any
{
public:
condition_variable_any();
~condition_variable_any();
condition_variable_any(const condition_variable_any&) = delete;
condition_variable_any& operator=(const condition_variable_any&) = delete;
void notify_one() noexcept;
void notify_all() noexcept;
template <class Lock>
void wait(Lock& lock);
template <class Lock, class Predicate>
void wait(Lock& lock, Predicate pred);
template <class Lock, class Clock, class Duration>
cv_status
wait_until(Lock& lock,
const chrono::time_point<Clock, Duration>& abs_time);
template <class Lock, class Clock, class Duration, class Predicate>
bool
wait_until(Lock& lock,
const chrono::time_point<Clock, Duration>& abs_time,
Predicate pred);
template <class Lock, class Rep, class Period>
cv_status
wait_for(Lock& lock,
const chrono::duration<Rep, Period>& rel_time);
template <class Lock, class Rep, class Period, class Predicate>
bool
wait_for(Lock& lock,
const chrono::duration<Rep, Period>& rel_time,
Predicate pred);
};
} // std
*/
class _LIBCPP_TYPE_VIS condition_variable_any
{
condition_variable __cv_;
shared_ptr<mutex> __mut_;
public:
_LIBCPP_INLINE_VISIBILITY
condition_variable_any();
_LIBCPP_INLINE_VISIBILITY
void notify_one() _NOEXCEPT;
_LIBCPP_INLINE_VISIBILITY
void notify_all() _NOEXCEPT;
template <class _Lock>
_LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
void wait(_Lock& __lock);
template <class _Lock, class _Predicate>
_LIBCPP_INLINE_VISIBILITY
void wait(_Lock& __lock, _Predicate __pred);
template <class _Lock, class _Clock, class _Duration>
_LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
cv_status
wait_until(_Lock& __lock,
const chrono::time_point<_Clock, _Duration>& __t);
template <class _Lock, class _Clock, class _Duration, class _Predicate>
bool
_LIBCPP_INLINE_VISIBILITY
wait_until(_Lock& __lock,
const chrono::time_point<_Clock, _Duration>& __t,
_Predicate __pred);
template <class _Lock, class _Rep, class _Period>
cv_status
_LIBCPP_INLINE_VISIBILITY
wait_for(_Lock& __lock,
const chrono::duration<_Rep, _Period>& __d);
template <class _Lock, class _Rep, class _Period, class _Predicate>
bool
_LIBCPP_INLINE_VISIBILITY
wait_for(_Lock& __lock,
const chrono::duration<_Rep, _Period>& __d,
_Predicate __pred);
};
inline
condition_variable_any::condition_variable_any()
: __mut_(make_shared<mutex>()) {}
inline
void
condition_variable_any::notify_one() _NOEXCEPT
{
{lock_guard<mutex> __lx(*__mut_);}
__cv_.notify_one();
}
inline
void
condition_variable_any::notify_all() _NOEXCEPT
{
{lock_guard<mutex> __lx(*__mut_);}
__cv_.notify_all();
}
struct __lock_external
{
template <class _Lock>
void operator()(_Lock* __m) {__m->lock();}
};
template <class _Lock>
void
condition_variable_any::wait(_Lock& __lock)
{
shared_ptr<mutex> __mut = __mut_;
unique_lock<mutex> __lk(*__mut);
__lock.unlock();
unique_ptr<_Lock, __lock_external> __lxx(&__lock);
lock_guard<unique_lock<mutex> > __lx(__lk, adopt_lock);
__cv_.wait(__lk);
} // __mut_.unlock(), __lock.lock()
template <class _Lock, class _Predicate>
inline
void
condition_variable_any::wait(_Lock& __lock, _Predicate __pred)
{
while (!__pred())
wait(__lock);
}
template <class _Lock, class _Clock, class _Duration>
cv_status
condition_variable_any::wait_until(_Lock& __lock,
const chrono::time_point<_Clock, _Duration>& __t)
{
shared_ptr<mutex> __mut = __mut_;
unique_lock<mutex> __lk(*__mut);
__lock.unlock();
unique_ptr<_Lock, __lock_external> __lxx(&__lock);
lock_guard<unique_lock<mutex> > __lx(__lk, adopt_lock);
return __cv_.wait_until(__lk, __t);
} // __mut_.unlock(), __lock.lock()
template <class _Lock, class _Clock, class _Duration, class _Predicate>
inline
bool
condition_variable_any::wait_until(_Lock& __lock,
const chrono::time_point<_Clock, _Duration>& __t,
_Predicate __pred)
{
while (!__pred())
if (wait_until(__lock, __t) == cv_status::timeout)
return __pred();
return true;
}
template <class _Lock, class _Rep, class _Period>
inline
cv_status
condition_variable_any::wait_for(_Lock& __lock,
const chrono::duration<_Rep, _Period>& __d)
{
return wait_until(__lock, chrono::steady_clock::now() + __d);
}
template <class _Lock, class _Rep, class _Period, class _Predicate>
inline
bool
condition_variable_any::wait_for(_Lock& __lock,
const chrono::duration<_Rep, _Period>& __d,
_Predicate __pred)
{
return wait_until(__lock, chrono::steady_clock::now() + __d,
_VSTD::move(__pred));
}
_LIBCPP_FUNC_VIS
void notify_all_at_thread_exit(condition_variable& cond, unique_lock<mutex> lk);
_LIBCPP_END_NAMESPACE_STD
#endif // !_LIBCPP_HAS_NO_THREADS
#endif // _LIBCPP_CONDITION_VARIABLE
| 7,683 | 270 | jart/cosmopolitan | false |
cosmopolitan/third_party/libcxx/stdio.h | // -*- C++ -*-
//===---------------------------- stdio.h ---------------------------------===//
//
// 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
//
//===----------------------------------------------------------------------===//
#if defined(__need_FILE) || defined(__need___FILE)
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
#pragma GCC system_header
#endif
#include "libc/isystem/stdio.h"
#elif !defined(_LIBCPP_STDIO_H)
#define _LIBCPP_STDIO_H
/*
stdio.h synopsis
Macros:
BUFSIZ
EOF
FILENAME_MAX
FOPEN_MAX
L_tmpnam
NULL
SEEK_CUR
SEEK_END
SEEK_SET
TMP_MAX
_IOFBF
_IOLBF
_IONBF
stderr
stdin
stdout
Types:
FILE
fpos_t
size_t
int remove(const char* filename);
int rename(const char* old, const char* new);
FILE* tmpfile(void);
char* tmpnam(char* s);
int fclose(FILE* stream);
int fflush(FILE* stream);
FILE* fopen(const char* restrict filename, const char* restrict mode);
FILE* freopen(const char* restrict filename, const char * restrict mode,
FILE * restrict stream);
void setbuf(FILE* restrict stream, char* restrict buf);
int setvbuf(FILE* restrict stream, char* restrict buf, int mode, size_t size);
int fprintf(FILE* restrict stream, const char* restrict format, ...);
int fscanf(FILE* restrict stream, const char * restrict format, ...);
int printf(const char* restrict format, ...);
int scanf(const char* restrict format, ...);
int snprintf(char* restrict s, size_t n, const char* restrict format, ...); // C99
int sprintf(char* restrict s, const char* restrict format, ...);
int sscanf(const char* restrict s, const char* restrict format, ...);
int vfprintf(FILE* restrict stream, const char* restrict format, va_list arg);
int vfscanf(FILE* restrict stream, const char* restrict format, va_list arg); // C99
int vprintf(const char* restrict format, va_list arg);
int vscanf(const char* restrict format, va_list arg); // C99
int vsnprintf(char* restrict s, size_t n, const char* restrict format, // C99
va_list arg);
int vsprintf(char* restrict s, const char* restrict format, va_list arg);
int vsscanf(const char* restrict s, const char* restrict format, va_list arg); // C99
int fgetc(FILE* stream);
char* fgets(char* restrict s, int n, FILE* restrict stream);
int fputc(int c, FILE* stream);
int fputs(const char* restrict s, FILE* restrict stream);
int getc(FILE* stream);
int getchar(void);
char* gets(char* s); // removed in C++14
int putc(int c, FILE* stream);
int putchar(int c);
int puts(const char* s);
int ungetc(int c, FILE* stream);
size_t fread(void* restrict ptr, size_t size, size_t nmemb,
FILE* restrict stream);
size_t fwrite(const void* restrict ptr, size_t size, size_t nmemb,
FILE* restrict stream);
int fgetpos(FILE* restrict stream, fpos_t* restrict pos);
int fseek(FILE* stream, long offset, int whence);
int fsetpos(FILE*stream, const fpos_t* pos);
long ftell(FILE* stream);
void rewind(FILE* stream);
void clearerr(FILE* stream);
int feof(FILE* stream);
int ferror(FILE* stream);
void perror(const char* s);
*/
#include "third_party/libcxx/__config"
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
#pragma GCC system_header
#endif
#include "libc/isystem/stdio.h"
#ifdef __cplusplus
#undef getc
#undef putc
#undef clearerr
#undef feof
#undef ferror
#endif
#endif // _LIBCPP_STDIO_H
| 3,555 | 120 | jart/cosmopolitan | false |
cosmopolitan/third_party/libcxx/atomic | // -*- C++ -*-
// clang-format off
//===--------------------------- atomic -----------------------------------===//
//
// 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_ATOMIC
#define _LIBCPP_ATOMIC
/*
atomic synopsis
namespace std
{
// feature test macro
#define __cpp_lib_atomic_is_always_lock_free // as specified by SG10
// order and consistency
enum memory_order: unspecified // enum class in C++20
{
relaxed,
consume, // load-consume
acquire, // load-acquire
release, // store-release
acq_rel, // store-release load-acquire
seq_cst // store-release load-acquire
};
inline constexpr auto memory_order_relaxed = memory_order::relaxed;
inline constexpr auto memory_order_consume = memory_order::consume;
inline constexpr auto memory_order_acquire = memory_order::acquire;
inline constexpr auto memory_order_release = memory_order::release;
inline constexpr auto memory_order_acq_rel = memory_order::acq_rel;
inline constexpr auto memory_order_seq_cst = memory_order::seq_cst;
template <class T> T kill_dependency(T y) noexcept;
// lock-free property
#define ATOMIC_BOOL_LOCK_FREE unspecified
#define ATOMIC_CHAR_LOCK_FREE unspecified
#define ATOMIC_CHAR16_T_LOCK_FREE unspecified
#define ATOMIC_CHAR32_T_LOCK_FREE unspecified
#define ATOMIC_WCHAR_T_LOCK_FREE unspecified
#define ATOMIC_SHORT_LOCK_FREE unspecified
#define ATOMIC_INT_LOCK_FREE unspecified
#define ATOMIC_LONG_LOCK_FREE unspecified
#define ATOMIC_LLONG_LOCK_FREE unspecified
#define ATOMIC_POINTER_LOCK_FREE unspecified
// flag type and operations
typedef struct atomic_flag
{
bool test_and_set(memory_order m = memory_order_seq_cst) volatile noexcept;
bool test_and_set(memory_order m = memory_order_seq_cst) noexcept;
void clear(memory_order m = memory_order_seq_cst) volatile noexcept;
void clear(memory_order m = memory_order_seq_cst) noexcept;
atomic_flag() noexcept = default;
atomic_flag(const atomic_flag&) = delete;
atomic_flag& operator=(const atomic_flag&) = delete;
atomic_flag& operator=(const atomic_flag&) volatile = delete;
} atomic_flag;
bool
atomic_flag_test_and_set(volatile atomic_flag* obj) noexcept;
bool
atomic_flag_test_and_set(atomic_flag* obj) noexcept;
bool
atomic_flag_test_and_set_explicit(volatile atomic_flag* obj,
memory_order m) noexcept;
bool
atomic_flag_test_and_set_explicit(atomic_flag* obj, memory_order m) noexcept;
void
atomic_flag_clear(volatile atomic_flag* obj) noexcept;
void
atomic_flag_clear(atomic_flag* obj) noexcept;
void
atomic_flag_clear_explicit(volatile atomic_flag* obj, memory_order m) noexcept;
void
atomic_flag_clear_explicit(atomic_flag* obj, memory_order m) noexcept;
#define ATOMIC_FLAG_INIT see below
#define ATOMIC_VAR_INIT(value) see below
template <class T>
struct atomic
{
static constexpr bool is_always_lock_free;
bool is_lock_free() const volatile noexcept;
bool is_lock_free() const noexcept;
void store(T desr, memory_order m = memory_order_seq_cst) volatile noexcept;
void store(T desr, memory_order m = memory_order_seq_cst) noexcept;
T load(memory_order m = memory_order_seq_cst) const volatile noexcept;
T load(memory_order m = memory_order_seq_cst) const noexcept;
operator T() const volatile noexcept;
operator T() const noexcept;
T exchange(T desr, memory_order m = memory_order_seq_cst) volatile noexcept;
T exchange(T desr, memory_order m = memory_order_seq_cst) noexcept;
bool compare_exchange_weak(T& expc, T desr,
memory_order s, memory_order f) volatile noexcept;
bool compare_exchange_weak(T& expc, T desr, memory_order s, memory_order f) noexcept;
bool compare_exchange_strong(T& expc, T desr,
memory_order s, memory_order f) volatile noexcept;
bool compare_exchange_strong(T& expc, T desr,
memory_order s, memory_order f) noexcept;
bool compare_exchange_weak(T& expc, T desr,
memory_order m = memory_order_seq_cst) volatile noexcept;
bool compare_exchange_weak(T& expc, T desr,
memory_order m = memory_order_seq_cst) noexcept;
bool compare_exchange_strong(T& expc, T desr,
memory_order m = memory_order_seq_cst) volatile noexcept;
bool compare_exchange_strong(T& expc, T desr,
memory_order m = memory_order_seq_cst) noexcept;
atomic() noexcept = default;
constexpr atomic(T desr) noexcept;
atomic(const atomic&) = delete;
atomic& operator=(const atomic&) = delete;
atomic& operator=(const atomic&) volatile = delete;
T operator=(T) volatile noexcept;
T operator=(T) noexcept;
};
template <>
struct atomic<integral>
{
static constexpr bool is_always_lock_free;
bool is_lock_free() const volatile noexcept;
bool is_lock_free() const noexcept;
void store(integral desr, memory_order m = memory_order_seq_cst) volatile noexcept;
void store(integral desr, memory_order m = memory_order_seq_cst) noexcept;
integral load(memory_order m = memory_order_seq_cst) const volatile noexcept;
integral load(memory_order m = memory_order_seq_cst) const noexcept;
operator integral() const volatile noexcept;
operator integral() const noexcept;
integral exchange(integral desr,
memory_order m = memory_order_seq_cst) volatile noexcept;
integral exchange(integral desr, memory_order m = memory_order_seq_cst) noexcept;
bool compare_exchange_weak(integral& expc, integral desr,
memory_order s, memory_order f) volatile noexcept;
bool compare_exchange_weak(integral& expc, integral desr,
memory_order s, memory_order f) noexcept;
bool compare_exchange_strong(integral& expc, integral desr,
memory_order s, memory_order f) volatile noexcept;
bool compare_exchange_strong(integral& expc, integral desr,
memory_order s, memory_order f) noexcept;
bool compare_exchange_weak(integral& expc, integral desr,
memory_order m = memory_order_seq_cst) volatile noexcept;
bool compare_exchange_weak(integral& expc, integral desr,
memory_order m = memory_order_seq_cst) noexcept;
bool compare_exchange_strong(integral& expc, integral desr,
memory_order m = memory_order_seq_cst) volatile noexcept;
bool compare_exchange_strong(integral& expc, integral desr,
memory_order m = memory_order_seq_cst) noexcept;
integral
fetch_add(integral op, memory_order m = memory_order_seq_cst) volatile noexcept;
integral fetch_add(integral op, memory_order m = memory_order_seq_cst) noexcept;
integral
fetch_sub(integral op, memory_order m = memory_order_seq_cst) volatile noexcept;
integral fetch_sub(integral op, memory_order m = memory_order_seq_cst) noexcept;
integral
fetch_and(integral op, memory_order m = memory_order_seq_cst) volatile noexcept;
integral fetch_and(integral op, memory_order m = memory_order_seq_cst) noexcept;
integral
fetch_or(integral op, memory_order m = memory_order_seq_cst) volatile noexcept;
integral fetch_or(integral op, memory_order m = memory_order_seq_cst) noexcept;
integral
fetch_xor(integral op, memory_order m = memory_order_seq_cst) volatile noexcept;
integral fetch_xor(integral op, memory_order m = memory_order_seq_cst) noexcept;
atomic() noexcept = default;
constexpr atomic(integral desr) noexcept;
atomic(const atomic&) = delete;
atomic& operator=(const atomic&) = delete;
atomic& operator=(const atomic&) volatile = delete;
integral operator=(integral desr) volatile noexcept;
integral operator=(integral desr) noexcept;
integral operator++(int) volatile noexcept;
integral operator++(int) noexcept;
integral operator--(int) volatile noexcept;
integral operator--(int) noexcept;
integral operator++() volatile noexcept;
integral operator++() noexcept;
integral operator--() volatile noexcept;
integral operator--() noexcept;
integral operator+=(integral op) volatile noexcept;
integral operator+=(integral op) noexcept;
integral operator-=(integral op) volatile noexcept;
integral operator-=(integral op) noexcept;
integral operator&=(integral op) volatile noexcept;
integral operator&=(integral op) noexcept;
integral operator|=(integral op) volatile noexcept;
integral operator|=(integral op) noexcept;
integral operator^=(integral op) volatile noexcept;
integral operator^=(integral op) noexcept;
};
template <class T>
struct atomic<T*>
{
static constexpr bool is_always_lock_free;
bool is_lock_free() const volatile noexcept;
bool is_lock_free() const noexcept;
void store(T* desr, memory_order m = memory_order_seq_cst) volatile noexcept;
void store(T* desr, memory_order m = memory_order_seq_cst) noexcept;
T* load(memory_order m = memory_order_seq_cst) const volatile noexcept;
T* load(memory_order m = memory_order_seq_cst) const noexcept;
operator T*() const volatile noexcept;
operator T*() const noexcept;
T* exchange(T* desr, memory_order m = memory_order_seq_cst) volatile noexcept;
T* exchange(T* desr, memory_order m = memory_order_seq_cst) noexcept;
bool compare_exchange_weak(T*& expc, T* desr,
memory_order s, memory_order f) volatile noexcept;
bool compare_exchange_weak(T*& expc, T* desr,
memory_order s, memory_order f) noexcept;
bool compare_exchange_strong(T*& expc, T* desr,
memory_order s, memory_order f) volatile noexcept;
bool compare_exchange_strong(T*& expc, T* desr,
memory_order s, memory_order f) noexcept;
bool compare_exchange_weak(T*& expc, T* desr,
memory_order m = memory_order_seq_cst) volatile noexcept;
bool compare_exchange_weak(T*& expc, T* desr,
memory_order m = memory_order_seq_cst) noexcept;
bool compare_exchange_strong(T*& expc, T* desr,
memory_order m = memory_order_seq_cst) volatile noexcept;
bool compare_exchange_strong(T*& expc, T* desr,
memory_order m = memory_order_seq_cst) noexcept;
T* fetch_add(ptrdiff_t op, memory_order m = memory_order_seq_cst) volatile noexcept;
T* fetch_add(ptrdiff_t op, memory_order m = memory_order_seq_cst) noexcept;
T* fetch_sub(ptrdiff_t op, memory_order m = memory_order_seq_cst) volatile noexcept;
T* fetch_sub(ptrdiff_t op, memory_order m = memory_order_seq_cst) noexcept;
atomic() noexcept = default;
constexpr atomic(T* desr) noexcept;
atomic(const atomic&) = delete;
atomic& operator=(const atomic&) = delete;
atomic& operator=(const atomic&) volatile = delete;
T* operator=(T*) volatile noexcept;
T* operator=(T*) noexcept;
T* operator++(int) volatile noexcept;
T* operator++(int) noexcept;
T* operator--(int) volatile noexcept;
T* operator--(int) noexcept;
T* operator++() volatile noexcept;
T* operator++() noexcept;
T* operator--() volatile noexcept;
T* operator--() noexcept;
T* operator+=(ptrdiff_t op) volatile noexcept;
T* operator+=(ptrdiff_t op) noexcept;
T* operator-=(ptrdiff_t op) volatile noexcept;
T* operator-=(ptrdiff_t op) noexcept;
};
template <class T>
bool
atomic_is_lock_free(const volatile atomic<T>* obj) noexcept;
template <class T>
bool
atomic_is_lock_free(const atomic<T>* obj) noexcept;
template <class T>
void
atomic_init(volatile atomic<T>* obj, T desr) noexcept;
template <class T>
void
atomic_init(atomic<T>* obj, T desr) noexcept;
template <class T>
void
atomic_store(volatile atomic<T>* obj, T desr) noexcept;
template <class T>
void
atomic_store(atomic<T>* obj, T desr) noexcept;
template <class T>
void
atomic_store_explicit(volatile atomic<T>* obj, T desr, memory_order m) noexcept;
template <class T>
void
atomic_store_explicit(atomic<T>* obj, T desr, memory_order m) noexcept;
template <class T>
T
atomic_load(const volatile atomic<T>* obj) noexcept;
template <class T>
T
atomic_load(const atomic<T>* obj) noexcept;
template <class T>
T
atomic_load_explicit(const volatile atomic<T>* obj, memory_order m) noexcept;
template <class T>
T
atomic_load_explicit(const atomic<T>* obj, memory_order m) noexcept;
template <class T>
T
atomic_exchange(volatile atomic<T>* obj, T desr) noexcept;
template <class T>
T
atomic_exchange(atomic<T>* obj, T desr) noexcept;
template <class T>
T
atomic_exchange_explicit(volatile atomic<T>* obj, T desr, memory_order m) noexcept;
template <class T>
T
atomic_exchange_explicit(atomic<T>* obj, T desr, memory_order m) noexcept;
template <class T>
bool
atomic_compare_exchange_weak(volatile atomic<T>* obj, T* expc, T desr) noexcept;
template <class T>
bool
atomic_compare_exchange_weak(atomic<T>* obj, T* expc, T desr) noexcept;
template <class T>
bool
atomic_compare_exchange_strong(volatile atomic<T>* obj, T* expc, T desr) noexcept;
template <class T>
bool
atomic_compare_exchange_strong(atomic<T>* obj, T* expc, T desr) noexcept;
template <class T>
bool
atomic_compare_exchange_weak_explicit(volatile atomic<T>* obj, T* expc,
T desr,
memory_order s, memory_order f) noexcept;
template <class T>
bool
atomic_compare_exchange_weak_explicit(atomic<T>* obj, T* expc, T desr,
memory_order s, memory_order f) noexcept;
template <class T>
bool
atomic_compare_exchange_strong_explicit(volatile atomic<T>* obj,
T* expc, T desr,
memory_order s, memory_order f) noexcept;
template <class T>
bool
atomic_compare_exchange_strong_explicit(atomic<T>* obj, T* expc,
T desr,
memory_order s, memory_order f) noexcept;
template <class Integral>
Integral
atomic_fetch_add(volatile atomic<Integral>* obj, Integral op) noexcept;
template <class Integral>
Integral
atomic_fetch_add(atomic<Integral>* obj, Integral op) noexcept;
template <class Integral>
Integral
atomic_fetch_add_explicit(volatile atomic<Integral>* obj, Integral op,
memory_order m) noexcept;
template <class Integral>
Integral
atomic_fetch_add_explicit(atomic<Integral>* obj, Integral op,
memory_order m) noexcept;
template <class Integral>
Integral
atomic_fetch_sub(volatile atomic<Integral>* obj, Integral op) noexcept;
template <class Integral>
Integral
atomic_fetch_sub(atomic<Integral>* obj, Integral op) noexcept;
template <class Integral>
Integral
atomic_fetch_sub_explicit(volatile atomic<Integral>* obj, Integral op,
memory_order m) noexcept;
template <class Integral>
Integral
atomic_fetch_sub_explicit(atomic<Integral>* obj, Integral op,
memory_order m) noexcept;
template <class Integral>
Integral
atomic_fetch_and(volatile atomic<Integral>* obj, Integral op) noexcept;
template <class Integral>
Integral
atomic_fetch_and(atomic<Integral>* obj, Integral op) noexcept;
template <class Integral>
Integral
atomic_fetch_and_explicit(volatile atomic<Integral>* obj, Integral op,
memory_order m) noexcept;
template <class Integral>
Integral
atomic_fetch_and_explicit(atomic<Integral>* obj, Integral op,
memory_order m) noexcept;
template <class Integral>
Integral
atomic_fetch_or(volatile atomic<Integral>* obj, Integral op) noexcept;
template <class Integral>
Integral
atomic_fetch_or(atomic<Integral>* obj, Integral op) noexcept;
template <class Integral>
Integral
atomic_fetch_or_explicit(volatile atomic<Integral>* obj, Integral op,
memory_order m) noexcept;
template <class Integral>
Integral
atomic_fetch_or_explicit(atomic<Integral>* obj, Integral op,
memory_order m) noexcept;
template <class Integral>
Integral
atomic_fetch_xor(volatile atomic<Integral>* obj, Integral op) noexcept;
template <class Integral>
Integral
atomic_fetch_xor(atomic<Integral>* obj, Integral op) noexcept;
template <class Integral>
Integral
atomic_fetch_xor_explicit(volatile atomic<Integral>* obj, Integral op,
memory_order m) noexcept;
template <class Integral>
Integral
atomic_fetch_xor_explicit(atomic<Integral>* obj, Integral op,
memory_order m) noexcept;
template <class T>
T*
atomic_fetch_add(volatile atomic<T*>* obj, ptrdiff_t op) noexcept;
template <class T>
T*
atomic_fetch_add(atomic<T*>* obj, ptrdiff_t op) noexcept;
template <class T>
T*
atomic_fetch_add_explicit(volatile atomic<T*>* obj, ptrdiff_t op,
memory_order m) noexcept;
template <class T>
T*
atomic_fetch_add_explicit(atomic<T*>* obj, ptrdiff_t op, memory_order m) noexcept;
template <class T>
T*
atomic_fetch_sub(volatile atomic<T*>* obj, ptrdiff_t op) noexcept;
template <class T>
T*
atomic_fetch_sub(atomic<T*>* obj, ptrdiff_t op) noexcept;
template <class T>
T*
atomic_fetch_sub_explicit(volatile atomic<T*>* obj, ptrdiff_t op,
memory_order m) noexcept;
template <class T>
T*
atomic_fetch_sub_explicit(atomic<T*>* obj, ptrdiff_t op, memory_order m) noexcept;
// Atomics for standard typedef types
typedef atomic<bool> atomic_bool;
typedef atomic<char> atomic_char;
typedef atomic<signed char> atomic_schar;
typedef atomic<unsigned char> atomic_uchar;
typedef atomic<short> atomic_short;
typedef atomic<unsigned short> atomic_ushort;
typedef atomic<int> atomic_int;
typedef atomic<unsigned int> atomic_uint;
typedef atomic<long> atomic_long;
typedef atomic<unsigned long> atomic_ulong;
typedef atomic<long long> atomic_llong;
typedef atomic<unsigned long long> atomic_ullong;
typedef atomic<char16_t> atomic_char16_t;
typedef atomic<char32_t> atomic_char32_t;
typedef atomic<wchar_t> atomic_wchar_t;
typedef atomic<int_least8_t> atomic_int_least8_t;
typedef atomic<uint_least8_t> atomic_uint_least8_t;
typedef atomic<int_least16_t> atomic_int_least16_t;
typedef atomic<uint_least16_t> atomic_uint_least16_t;
typedef atomic<int_least32_t> atomic_int_least32_t;
typedef atomic<uint_least32_t> atomic_uint_least32_t;
typedef atomic<int_least64_t> atomic_int_least64_t;
typedef atomic<uint_least64_t> atomic_uint_least64_t;
typedef atomic<int_fast8_t> atomic_int_fast8_t;
typedef atomic<uint_fast8_t> atomic_uint_fast8_t;
typedef atomic<int_fast16_t> atomic_int_fast16_t;
typedef atomic<uint_fast16_t> atomic_uint_fast16_t;
typedef atomic<int_fast32_t> atomic_int_fast32_t;
typedef atomic<uint_fast32_t> atomic_uint_fast32_t;
typedef atomic<int_fast64_t> atomic_int_fast64_t;
typedef atomic<uint_fast64_t> atomic_uint_fast64_t;
typedef atomic<int8_t> atomic_int8_t;
typedef atomic<uint8_t> atomic_uint8_t;
typedef atomic<int16_t> atomic_int16_t;
typedef atomic<uint16_t> atomic_uint16_t;
typedef atomic<int32_t> atomic_int32_t;
typedef atomic<uint32_t> atomic_uint32_t;
typedef atomic<int64_t> atomic_int64_t;
typedef atomic<uint64_t> atomic_uint64_t;
typedef atomic<intptr_t> atomic_intptr_t;
typedef atomic<uintptr_t> atomic_uintptr_t;
typedef atomic<size_t> atomic_size_t;
typedef atomic<ptrdiff_t> atomic_ptrdiff_t;
typedef atomic<intmax_t> atomic_intmax_t;
typedef atomic<uintmax_t> atomic_uintmax_t;
// fences
void atomic_thread_fence(memory_order m) noexcept;
void atomic_signal_fence(memory_order m) noexcept;
} // std
*/
#include "third_party/libcxx/__config"
#include "third_party/libcxx/cstddef"
#include "third_party/libcxx/cstdint"
#include "third_party/libcxx/type_traits"
#include "third_party/libcxx/version"
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
#pragma GCC system_header
#endif
#ifdef _LIBCPP_HAS_NO_THREADS
# error <atomic> is not supported on this single threaded system
#endif
#ifdef _LIBCPP_HAS_NO_ATOMIC_HEADER
# error <atomic> is not implemented
#endif
#ifdef kill_dependency
# error C++ standard library is incompatible with <stdatomic.h>
#endif
#define _LIBCPP_CHECK_STORE_MEMORY_ORDER(__m) \
_LIBCPP_DIAGNOSE_WARNING(__m == memory_order_consume || \
__m == memory_order_acquire || \
__m == memory_order_acq_rel, \
"memory order argument to atomic operation is invalid")
#define _LIBCPP_CHECK_LOAD_MEMORY_ORDER(__m) \
_LIBCPP_DIAGNOSE_WARNING(__m == memory_order_release || \
__m == memory_order_acq_rel, \
"memory order argument to atomic operation is invalid")
#define _LIBCPP_CHECK_EXCHANGE_MEMORY_ORDER(__m, __f) \
_LIBCPP_DIAGNOSE_WARNING(__f == memory_order_release || \
__f == memory_order_acq_rel, \
"memory order argument to atomic operation is invalid")
_LIBCPP_BEGIN_NAMESPACE_STD
// Figure out what the underlying type for `memory_order` would be if it were
// declared as an unscoped enum (accounting for -fshort-enums). Use this result
// to pin the underlying type in C++20.
enum __legacy_memory_order {
__mo_relaxed,
__mo_consume,
__mo_acquire,
__mo_release,
__mo_acq_rel,
__mo_seq_cst
};
typedef underlying_type<__legacy_memory_order>::type __memory_order_underlying_t;
#if _LIBCPP_STD_VER > 17
enum class memory_order : __memory_order_underlying_t {
relaxed = __mo_relaxed,
consume = __mo_consume,
acquire = __mo_acquire,
release = __mo_release,
acq_rel = __mo_acq_rel,
seq_cst = __mo_seq_cst
};
inline constexpr auto memory_order_relaxed = memory_order::relaxed;
inline constexpr auto memory_order_consume = memory_order::consume;
inline constexpr auto memory_order_acquire = memory_order::acquire;
inline constexpr auto memory_order_release = memory_order::release;
inline constexpr auto memory_order_acq_rel = memory_order::acq_rel;
inline constexpr auto memory_order_seq_cst = memory_order::seq_cst;
#else
typedef enum memory_order {
memory_order_relaxed = __mo_relaxed,
memory_order_consume = __mo_consume,
memory_order_acquire = __mo_acquire,
memory_order_release = __mo_release,
memory_order_acq_rel = __mo_acq_rel,
memory_order_seq_cst = __mo_seq_cst,
} memory_order;
#endif // _LIBCPP_STD_VER > 17
static_assert((is_same<underlying_type<memory_order>::type, __memory_order_underlying_t>::value),
"unexpected underlying type for std::memory_order");
#if defined(_LIBCPP_HAS_GCC_ATOMIC_IMP) || \
defined(_LIBCPP_ATOMIC_ONLY_USE_BUILTINS)
// [atomics.types.generic]p1 guarantees _Tp is trivially copyable. Because
// the default operator= in an object is not volatile, a byte-by-byte copy
// is required.
template <typename _Tp, typename _Tv> _LIBCPP_INLINE_VISIBILITY
typename enable_if<is_assignable<_Tp&, _Tv>::value>::type
__cxx_atomic_assign_volatile(_Tp& __a_value, _Tv const& __val) {
__a_value = __val;
}
template <typename _Tp, typename _Tv> _LIBCPP_INLINE_VISIBILITY
typename enable_if<is_assignable<_Tp&, _Tv>::value>::type
__cxx_atomic_assign_volatile(_Tp volatile& __a_value, _Tv volatile const& __val) {
volatile char* __to = reinterpret_cast<volatile char*>(&__a_value);
volatile char* __end = __to + sizeof(_Tp);
volatile const char* __from = reinterpret_cast<volatile const char*>(&__val);
while (__to != __end)
*__to++ = *__from++;
}
#endif
#if defined(_LIBCPP_HAS_GCC_ATOMIC_IMP)
template <typename _Tp>
struct __cxx_atomic_base_impl {
_LIBCPP_INLINE_VISIBILITY
#ifndef _LIBCPP_CXX03_LANG
__cxx_atomic_base_impl() _NOEXCEPT = default;
#else
__cxx_atomic_base_impl() _NOEXCEPT : __a_value() {}
#endif // _LIBCPP_CXX03_LANG
_LIBCPP_CONSTEXPR explicit __cxx_atomic_base_impl(_Tp value) _NOEXCEPT
: __a_value(value) {}
_Tp __a_value;
};
_LIBCPP_INLINE_VISIBILITY inline _LIBCPP_CONSTEXPR int __to_gcc_order(memory_order __order) {
// Avoid switch statement to make this a constexpr.
return __order == memory_order_relaxed ? __ATOMIC_RELAXED:
(__order == memory_order_acquire ? __ATOMIC_ACQUIRE:
(__order == memory_order_release ? __ATOMIC_RELEASE:
(__order == memory_order_seq_cst ? __ATOMIC_SEQ_CST:
(__order == memory_order_acq_rel ? __ATOMIC_ACQ_REL:
__ATOMIC_CONSUME))));
}
_LIBCPP_INLINE_VISIBILITY inline _LIBCPP_CONSTEXPR int __to_gcc_failure_order(memory_order __order) {
// Avoid switch statement to make this a constexpr.
return __order == memory_order_relaxed ? __ATOMIC_RELAXED:
(__order == memory_order_acquire ? __ATOMIC_ACQUIRE:
(__order == memory_order_release ? __ATOMIC_RELAXED:
(__order == memory_order_seq_cst ? __ATOMIC_SEQ_CST:
(__order == memory_order_acq_rel ? __ATOMIC_ACQUIRE:
__ATOMIC_CONSUME))));
}
template <typename _Tp>
_LIBCPP_INLINE_VISIBILITY
void __cxx_atomic_init(volatile __cxx_atomic_base_impl<_Tp>* __a, _Tp __val) {
__cxx_atomic_assign_volatile(__a->__a_value, __val);
}
template <typename _Tp>
_LIBCPP_INLINE_VISIBILITY
void __cxx_atomic_init(__cxx_atomic_base_impl<_Tp>* __a, _Tp __val) {
__a->__a_value = __val;
}
_LIBCPP_INLINE_VISIBILITY inline
void __cxx_atomic_thread_fence(memory_order __order) {
__atomic_thread_fence(__to_gcc_order(__order));
}
_LIBCPP_INLINE_VISIBILITY inline
void __cxx_atomic_signal_fence(memory_order __order) {
__atomic_signal_fence(__to_gcc_order(__order));
}
template <typename _Tp>
_LIBCPP_INLINE_VISIBILITY inline
void __cxx_atomic_store(volatile __cxx_atomic_base_impl<_Tp>* __a, _Tp __val,
memory_order __order) {
__atomic_store(&__a->__a_value, &__val,
__to_gcc_order(__order));
}
template <typename _Tp>
_LIBCPP_INLINE_VISIBILITY inline
void __cxx_atomic_store(__cxx_atomic_base_impl<_Tp>* __a, _Tp __val,
memory_order __order) {
__atomic_store(&__a->__a_value, &__val,
__to_gcc_order(__order));
}
template <typename _Tp>
_LIBCPP_INLINE_VISIBILITY inline
_Tp __cxx_atomic_load(const volatile __cxx_atomic_base_impl<_Tp>* __a,
memory_order __order) {
_Tp __ret;
__atomic_load(&__a->__a_value, &__ret,
__to_gcc_order(__order));
return __ret;
}
template <typename _Tp>
_LIBCPP_INLINE_VISIBILITY inline
_Tp __cxx_atomic_load(const __cxx_atomic_base_impl<_Tp>* __a, memory_order __order) {
_Tp __ret;
__atomic_load(&__a->__a_value, &__ret,
__to_gcc_order(__order));
return __ret;
}
template <typename _Tp>
_LIBCPP_INLINE_VISIBILITY inline
_Tp __cxx_atomic_exchange(volatile __cxx_atomic_base_impl<_Tp>* __a,
_Tp __value, memory_order __order) {
_Tp __ret;
__atomic_exchange(&__a->__a_value, &__value, &__ret,
__to_gcc_order(__order));
return __ret;
}
template <typename _Tp>
_LIBCPP_INLINE_VISIBILITY inline
_Tp __cxx_atomic_exchange(__cxx_atomic_base_impl<_Tp>* __a, _Tp __value,
memory_order __order) {
_Tp __ret;
__atomic_exchange(&__a->__a_value, &__value, &__ret,
__to_gcc_order(__order));
return __ret;
}
template <typename _Tp>
_LIBCPP_INLINE_VISIBILITY
bool __cxx_atomic_compare_exchange_strong(
volatile __cxx_atomic_base_impl<_Tp>* __a, _Tp* __expected, _Tp __value,
memory_order __success, memory_order __failure) {
return __atomic_compare_exchange(&__a->__a_value, __expected, &__value,
false,
__to_gcc_order(__success),
__to_gcc_failure_order(__failure));
}
template <typename _Tp>
_LIBCPP_INLINE_VISIBILITY
bool __cxx_atomic_compare_exchange_strong(
__cxx_atomic_base_impl<_Tp>* __a, _Tp* __expected, _Tp __value, memory_order __success,
memory_order __failure) {
return __atomic_compare_exchange(&__a->__a_value, __expected, &__value,
false,
__to_gcc_order(__success),
__to_gcc_failure_order(__failure));
}
template <typename _Tp>
_LIBCPP_INLINE_VISIBILITY
bool __cxx_atomic_compare_exchange_weak(
volatile __cxx_atomic_base_impl<_Tp>* __a, _Tp* __expected, _Tp __value,
memory_order __success, memory_order __failure) {
return __atomic_compare_exchange(&__a->__a_value, __expected, &__value,
true,
__to_gcc_order(__success),
__to_gcc_failure_order(__failure));
}
template <typename _Tp>
_LIBCPP_INLINE_VISIBILITY
bool __cxx_atomic_compare_exchange_weak(
__cxx_atomic_base_impl<_Tp>* __a, _Tp* __expected, _Tp __value, memory_order __success,
memory_order __failure) {
return __atomic_compare_exchange(&__a->__a_value, __expected, &__value,
true,
__to_gcc_order(__success),
__to_gcc_failure_order(__failure));
}
template <typename _Tp>
struct __skip_amt { enum {value = 1}; };
template <typename _Tp>
struct __skip_amt<_Tp*> { enum {value = sizeof(_Tp)}; };
// FIXME: Haven't figured out what the spec says about using arrays with
// atomic_fetch_add. Force a failure rather than creating bad behavior.
template <typename _Tp>
struct __skip_amt<_Tp[]> { };
template <typename _Tp, int n>
struct __skip_amt<_Tp[n]> { };
template <typename _Tp, typename _Td>
_LIBCPP_INLINE_VISIBILITY
_Tp __cxx_atomic_fetch_add(volatile __cxx_atomic_base_impl<_Tp>* __a,
_Td __delta, memory_order __order) {
return __atomic_fetch_add(&__a->__a_value, __delta * __skip_amt<_Tp>::value,
__to_gcc_order(__order));
}
template <typename _Tp, typename _Td>
_LIBCPP_INLINE_VISIBILITY
_Tp __cxx_atomic_fetch_add(__cxx_atomic_base_impl<_Tp>* __a, _Td __delta,
memory_order __order) {
return __atomic_fetch_add(&__a->__a_value, __delta * __skip_amt<_Tp>::value,
__to_gcc_order(__order));
}
template <typename _Tp, typename _Td>
_LIBCPP_INLINE_VISIBILITY
_Tp __cxx_atomic_fetch_sub(volatile __cxx_atomic_base_impl<_Tp>* __a,
_Td __delta, memory_order __order) {
return __atomic_fetch_sub(&__a->__a_value, __delta * __skip_amt<_Tp>::value,
__to_gcc_order(__order));
}
template <typename _Tp, typename _Td>
_LIBCPP_INLINE_VISIBILITY
_Tp __cxx_atomic_fetch_sub(__cxx_atomic_base_impl<_Tp>* __a, _Td __delta,
memory_order __order) {
return __atomic_fetch_sub(&__a->__a_value, __delta * __skip_amt<_Tp>::value,
__to_gcc_order(__order));
}
template <typename _Tp>
_LIBCPP_INLINE_VISIBILITY
_Tp __cxx_atomic_fetch_and(volatile __cxx_atomic_base_impl<_Tp>* __a,
_Tp __pattern, memory_order __order) {
return __atomic_fetch_and(&__a->__a_value, __pattern,
__to_gcc_order(__order));
}
template <typename _Tp>
_LIBCPP_INLINE_VISIBILITY
_Tp __cxx_atomic_fetch_and(__cxx_atomic_base_impl<_Tp>* __a,
_Tp __pattern, memory_order __order) {
return __atomic_fetch_and(&__a->__a_value, __pattern,
__to_gcc_order(__order));
}
template <typename _Tp>
_LIBCPP_INLINE_VISIBILITY
_Tp __cxx_atomic_fetch_or(volatile __cxx_atomic_base_impl<_Tp>* __a,
_Tp __pattern, memory_order __order) {
return __atomic_fetch_or(&__a->__a_value, __pattern,
__to_gcc_order(__order));
}
template <typename _Tp>
_LIBCPP_INLINE_VISIBILITY
_Tp __cxx_atomic_fetch_or(__cxx_atomic_base_impl<_Tp>* __a, _Tp __pattern,
memory_order __order) {
return __atomic_fetch_or(&__a->__a_value, __pattern,
__to_gcc_order(__order));
}
template <typename _Tp>
_LIBCPP_INLINE_VISIBILITY
_Tp __cxx_atomic_fetch_xor(volatile __cxx_atomic_base_impl<_Tp>* __a,
_Tp __pattern, memory_order __order) {
return __atomic_fetch_xor(&__a->__a_value, __pattern,
__to_gcc_order(__order));
}
template <typename _Tp>
_LIBCPP_INLINE_VISIBILITY
_Tp __cxx_atomic_fetch_xor(__cxx_atomic_base_impl<_Tp>* __a, _Tp __pattern,
memory_order __order) {
return __atomic_fetch_xor(&__a->__a_value, __pattern,
__to_gcc_order(__order));
}
#define __cxx_atomic_is_lock_free(__s) __atomic_is_lock_free(__s, 0)
#elif defined(_LIBCPP_HAS_C_ATOMIC_IMP)
template <typename _Tp>
struct __cxx_atomic_base_impl {
_LIBCPP_INLINE_VISIBILITY
#ifndef _LIBCPP_CXX03_LANG
__cxx_atomic_base_impl() _NOEXCEPT = default;
#else
__cxx_atomic_base_impl() _NOEXCEPT : __a_value() {}
#endif // _LIBCPP_CXX03_LANG
_LIBCPP_CONSTEXPR explicit __cxx_atomic_base_impl(_Tp value) _NOEXCEPT
: __a_value(value) {}
_LIBCPP_DISABLE_EXTENSION_WARNING _Atomic(_Tp) __a_value;
};
#define __cxx_atomic_is_lock_free(__s) __c11_atomic_is_lock_free(__s)
_LIBCPP_INLINE_VISIBILITY inline
void __cxx_atomic_thread_fence(memory_order __order) _NOEXCEPT {
__c11_atomic_thread_fence(static_cast<__memory_order_underlying_t>(__order));
}
_LIBCPP_INLINE_VISIBILITY inline
void __cxx_atomic_signal_fence(memory_order __order) _NOEXCEPT {
__c11_atomic_signal_fence(static_cast<__memory_order_underlying_t>(__order));
}
template<class _Tp>
_LIBCPP_INLINE_VISIBILITY
void __cxx_atomic_init(__cxx_atomic_base_impl<_Tp> volatile* __a, _Tp __val) _NOEXCEPT {
__c11_atomic_init(&__a->__a_value, __val);
}
template<class _Tp>
_LIBCPP_INLINE_VISIBILITY
void __cxx_atomic_init(__cxx_atomic_base_impl<_Tp> * __a, _Tp __val) _NOEXCEPT {
__c11_atomic_init(&__a->__a_value, __val);
}
template<class _Tp>
_LIBCPP_INLINE_VISIBILITY
void __cxx_atomic_store(__cxx_atomic_base_impl<_Tp> volatile* __a, _Tp __val, memory_order __order) _NOEXCEPT {
__c11_atomic_store(&__a->__a_value, __val, static_cast<__memory_order_underlying_t>(__order));
}
template<class _Tp>
_LIBCPP_INLINE_VISIBILITY
void __cxx_atomic_store(__cxx_atomic_base_impl<_Tp> * __a, _Tp __val, memory_order __order) _NOEXCEPT {
__c11_atomic_store(&__a->__a_value, __val, static_cast<__memory_order_underlying_t>(__order));
}
template<class _Tp>
_LIBCPP_INLINE_VISIBILITY
_Tp __cxx_atomic_load(__cxx_atomic_base_impl<_Tp> const volatile* __a, memory_order __order) _NOEXCEPT {
using __ptr_type = typename remove_const<decltype(__a->__a_value)>::type*;
return __c11_atomic_load(const_cast<__ptr_type>(&__a->__a_value), static_cast<__memory_order_underlying_t>(__order));
}
template<class _Tp>
_LIBCPP_INLINE_VISIBILITY
_Tp __cxx_atomic_load(__cxx_atomic_base_impl<_Tp> const* __a, memory_order __order) _NOEXCEPT {
using __ptr_type = typename remove_const<decltype(__a->__a_value)>::type*;
return __c11_atomic_load(const_cast<__ptr_type>(&__a->__a_value), static_cast<__memory_order_underlying_t>(__order));
}
template<class _Tp>
_LIBCPP_INLINE_VISIBILITY
_Tp __cxx_atomic_exchange(__cxx_atomic_base_impl<_Tp> volatile* __a, _Tp __value, memory_order __order) _NOEXCEPT {
return __c11_atomic_exchange(&__a->__a_value, __value, static_cast<__memory_order_underlying_t>(__order));
}
template<class _Tp>
_LIBCPP_INLINE_VISIBILITY
_Tp __cxx_atomic_exchange(__cxx_atomic_base_impl<_Tp> * __a, _Tp __value, memory_order __order) _NOEXCEPT {
return __c11_atomic_exchange(&__a->__a_value, __value, static_cast<__memory_order_underlying_t>(__order));
}
template<class _Tp>
_LIBCPP_INLINE_VISIBILITY
bool __cxx_atomic_compare_exchange_strong(__cxx_atomic_base_impl<_Tp> volatile* __a, _Tp* __expected, _Tp __value, memory_order __success, memory_order __failure) _NOEXCEPT {
return __c11_atomic_compare_exchange_strong(&__a->__a_value, __expected, __value, static_cast<__memory_order_underlying_t>(__success), static_cast<__memory_order_underlying_t>(__failure));
}
template<class _Tp>
_LIBCPP_INLINE_VISIBILITY
bool __cxx_atomic_compare_exchange_strong(__cxx_atomic_base_impl<_Tp> * __a, _Tp* __expected, _Tp __value, memory_order __success, memory_order __failure) _NOEXCEPT {
return __c11_atomic_compare_exchange_strong(&__a->__a_value, __expected, __value, static_cast<__memory_order_underlying_t>(__success), static_cast<__memory_order_underlying_t>(__failure));
}
template<class _Tp>
_LIBCPP_INLINE_VISIBILITY
bool __cxx_atomic_compare_exchange_weak(__cxx_atomic_base_impl<_Tp> volatile* __a, _Tp* __expected, _Tp __value, memory_order __success, memory_order __failure) _NOEXCEPT {
return __c11_atomic_compare_exchange_weak(&__a->__a_value, __expected, __value, static_cast<__memory_order_underlying_t>(__success), static_cast<__memory_order_underlying_t>(__failure));
}
template<class _Tp>
_LIBCPP_INLINE_VISIBILITY
bool __cxx_atomic_compare_exchange_weak(__cxx_atomic_base_impl<_Tp> * __a, _Tp* __expected, _Tp __value, memory_order __success, memory_order __failure) _NOEXCEPT {
return __c11_atomic_compare_exchange_weak(&__a->__a_value, __expected, __value, static_cast<__memory_order_underlying_t>(__success), static_cast<__memory_order_underlying_t>(__failure));
}
template<class _Tp>
_LIBCPP_INLINE_VISIBILITY
_Tp __cxx_atomic_fetch_add(__cxx_atomic_base_impl<_Tp> volatile* __a, _Tp __delta, memory_order __order) _NOEXCEPT {
return __c11_atomic_fetch_add(&__a->__a_value, __delta, static_cast<__memory_order_underlying_t>(__order));
}
template<class _Tp>
_LIBCPP_INLINE_VISIBILITY
_Tp __cxx_atomic_fetch_add(__cxx_atomic_base_impl<_Tp> * __a, _Tp __delta, memory_order __order) _NOEXCEPT {
return __c11_atomic_fetch_add(&__a->__a_value, __delta, static_cast<__memory_order_underlying_t>(__order));
}
template<class _Tp>
_LIBCPP_INLINE_VISIBILITY
_Tp* __cxx_atomic_fetch_add(__cxx_atomic_base_impl<_Tp*> volatile* __a, ptrdiff_t __delta, memory_order __order) _NOEXCEPT {
return __c11_atomic_fetch_add(&__a->__a_value, __delta, static_cast<__memory_order_underlying_t>(__order));
}
template<class _Tp>
_LIBCPP_INLINE_VISIBILITY
_Tp* __cxx_atomic_fetch_add(__cxx_atomic_base_impl<_Tp*> * __a, ptrdiff_t __delta, memory_order __order) _NOEXCEPT {
return __c11_atomic_fetch_add(&__a->__a_value, __delta, static_cast<__memory_order_underlying_t>(__order));
}
template<class _Tp>
_LIBCPP_INLINE_VISIBILITY
_Tp __cxx_atomic_fetch_sub(__cxx_atomic_base_impl<_Tp> volatile* __a, _Tp __delta, memory_order __order) _NOEXCEPT {
return __c11_atomic_fetch_sub(&__a->__a_value, __delta, static_cast<__memory_order_underlying_t>(__order));
}
template<class _Tp>
_LIBCPP_INLINE_VISIBILITY
_Tp __cxx_atomic_fetch_sub(__cxx_atomic_base_impl<_Tp> * __a, _Tp __delta, memory_order __order) _NOEXCEPT {
return __c11_atomic_fetch_sub(&__a->__a_value, __delta, static_cast<__memory_order_underlying_t>(__order));
}
template<class _Tp>
_LIBCPP_INLINE_VISIBILITY
_Tp* __cxx_atomic_fetch_sub(__cxx_atomic_base_impl<_Tp*> volatile* __a, ptrdiff_t __delta, memory_order __order) _NOEXCEPT {
return __c11_atomic_fetch_sub(&__a->__a_value, __delta, static_cast<__memory_order_underlying_t>(__order));
}
template<class _Tp>
_LIBCPP_INLINE_VISIBILITY
_Tp* __cxx_atomic_fetch_sub(__cxx_atomic_base_impl<_Tp*> * __a, ptrdiff_t __delta, memory_order __order) _NOEXCEPT {
return __c11_atomic_fetch_sub(&__a->__a_value, __delta, static_cast<__memory_order_underlying_t>(__order));
}
template<class _Tp>
_LIBCPP_INLINE_VISIBILITY
_Tp __cxx_atomic_fetch_and(__cxx_atomic_base_impl<_Tp> volatile* __a, _Tp __pattern, memory_order __order) _NOEXCEPT {
return __c11_atomic_fetch_and(&__a->__a_value, __pattern, static_cast<__memory_order_underlying_t>(__order));
}
template<class _Tp>
_LIBCPP_INLINE_VISIBILITY
_Tp __cxx_atomic_fetch_and(__cxx_atomic_base_impl<_Tp> * __a, _Tp __pattern, memory_order __order) _NOEXCEPT {
return __c11_atomic_fetch_and(&__a->__a_value, __pattern, static_cast<__memory_order_underlying_t>(__order));
}
template<class _Tp>
_LIBCPP_INLINE_VISIBILITY
_Tp __cxx_atomic_fetch_or(__cxx_atomic_base_impl<_Tp> volatile* __a, _Tp __pattern, memory_order __order) _NOEXCEPT {
return __c11_atomic_fetch_or(&__a->__a_value, __pattern, static_cast<__memory_order_underlying_t>(__order));
}
template<class _Tp>
_LIBCPP_INLINE_VISIBILITY
_Tp __cxx_atomic_fetch_or(__cxx_atomic_base_impl<_Tp> * __a, _Tp __pattern, memory_order __order) _NOEXCEPT {
return __c11_atomic_fetch_or(&__a->__a_value, __pattern, static_cast<__memory_order_underlying_t>(__order));
}
template<class _Tp>
_LIBCPP_INLINE_VISIBILITY
_Tp __cxx_atomic_fetch_xor(__cxx_atomic_base_impl<_Tp> volatile* __a, _Tp __pattern, memory_order __order) _NOEXCEPT {
return __c11_atomic_fetch_xor(&__a->__a_value, __pattern, static_cast<__memory_order_underlying_t>(__order));
}
template<class _Tp>
_LIBCPP_INLINE_VISIBILITY
_Tp __cxx_atomic_fetch_xor(__cxx_atomic_base_impl<_Tp> * __a, _Tp __pattern, memory_order __order) _NOEXCEPT {
return __c11_atomic_fetch_xor(&__a->__a_value, __pattern, static_cast<__memory_order_underlying_t>(__order));
}
#endif // _LIBCPP_HAS_GCC_ATOMIC_IMP, _LIBCPP_HAS_C_ATOMIC_IMP
template <class _Tp>
_LIBCPP_INLINE_VISIBILITY
_Tp kill_dependency(_Tp __y) _NOEXCEPT
{
return __y;
}
#if defined(__CLANG_ATOMIC_BOOL_LOCK_FREE)
# define ATOMIC_BOOL_LOCK_FREE __CLANG_ATOMIC_BOOL_LOCK_FREE
# define ATOMIC_CHAR_LOCK_FREE __CLANG_ATOMIC_CHAR_LOCK_FREE
# define ATOMIC_CHAR16_T_LOCK_FREE __CLANG_ATOMIC_CHAR16_T_LOCK_FREE
# define ATOMIC_CHAR32_T_LOCK_FREE __CLANG_ATOMIC_CHAR32_T_LOCK_FREE
# define ATOMIC_WCHAR_T_LOCK_FREE __CLANG_ATOMIC_WCHAR_T_LOCK_FREE
# define ATOMIC_SHORT_LOCK_FREE __CLANG_ATOMIC_SHORT_LOCK_FREE
# define ATOMIC_INT_LOCK_FREE __CLANG_ATOMIC_INT_LOCK_FREE
# define ATOMIC_LONG_LOCK_FREE __CLANG_ATOMIC_LONG_LOCK_FREE
# define ATOMIC_LLONG_LOCK_FREE __CLANG_ATOMIC_LLONG_LOCK_FREE
# define ATOMIC_POINTER_LOCK_FREE __CLANG_ATOMIC_POINTER_LOCK_FREE
#elif defined(__GCC_ATOMIC_BOOL_LOCK_FREE)
# define ATOMIC_BOOL_LOCK_FREE __GCC_ATOMIC_BOOL_LOCK_FREE
# define ATOMIC_CHAR_LOCK_FREE __GCC_ATOMIC_CHAR_LOCK_FREE
# define ATOMIC_CHAR16_T_LOCK_FREE __GCC_ATOMIC_CHAR16_T_LOCK_FREE
# define ATOMIC_CHAR32_T_LOCK_FREE __GCC_ATOMIC_CHAR32_T_LOCK_FREE
# define ATOMIC_WCHAR_T_LOCK_FREE __GCC_ATOMIC_WCHAR_T_LOCK_FREE
# define ATOMIC_SHORT_LOCK_FREE __GCC_ATOMIC_SHORT_LOCK_FREE
# define ATOMIC_INT_LOCK_FREE __GCC_ATOMIC_INT_LOCK_FREE
# define ATOMIC_LONG_LOCK_FREE __GCC_ATOMIC_LONG_LOCK_FREE
# define ATOMIC_LLONG_LOCK_FREE __GCC_ATOMIC_LLONG_LOCK_FREE
# define ATOMIC_POINTER_LOCK_FREE __GCC_ATOMIC_POINTER_LOCK_FREE
#endif
#ifdef _LIBCPP_ATOMIC_ONLY_USE_BUILTINS
template<typename _Tp>
struct __cxx_atomic_lock_impl {
_LIBCPP_INLINE_VISIBILITY
__cxx_atomic_lock_impl() _NOEXCEPT
: __a_value(), __a_lock(0) {}
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR explicit
__cxx_atomic_lock_impl(_Tp value) _NOEXCEPT
: __a_value(value), __a_lock(0) {}
_Tp __a_value;
mutable __cxx_atomic_base_impl<_LIBCPP_ATOMIC_FLAG_TYPE> __a_lock;
_LIBCPP_INLINE_VISIBILITY void __lock() const volatile {
while(1 == __cxx_atomic_exchange(&__a_lock, _LIBCPP_ATOMIC_FLAG_TYPE(true), memory_order_acquire))
/*spin*/;
}
_LIBCPP_INLINE_VISIBILITY void __lock() const {
while(1 == __cxx_atomic_exchange(&__a_lock, _LIBCPP_ATOMIC_FLAG_TYPE(true), memory_order_acquire))
/*spin*/;
}
_LIBCPP_INLINE_VISIBILITY void __unlock() const volatile {
__cxx_atomic_store(&__a_lock, _LIBCPP_ATOMIC_FLAG_TYPE(false), memory_order_release);
}
_LIBCPP_INLINE_VISIBILITY void __unlock() const {
__cxx_atomic_store(&__a_lock, _LIBCPP_ATOMIC_FLAG_TYPE(false), memory_order_release);
}
_LIBCPP_INLINE_VISIBILITY _Tp __read() const volatile {
__lock();
_Tp __old;
__cxx_atomic_assign_volatile(__old, __a_value);
__unlock();
return __old;
}
_LIBCPP_INLINE_VISIBILITY _Tp __read() const {
__lock();
_Tp __old = __a_value;
__unlock();
return __old;
}
};
template <typename _Tp>
_LIBCPP_INLINE_VISIBILITY
void __cxx_atomic_init(volatile __cxx_atomic_lock_impl<_Tp>* __a, _Tp __val) {
__cxx_atomic_assign_volatile(__a->__a_value, __val);
}
template <typename _Tp>
_LIBCPP_INLINE_VISIBILITY
void __cxx_atomic_init(__cxx_atomic_lock_impl<_Tp>* __a, _Tp __val) {
__a->__a_value = __val;
}
template <typename _Tp>
_LIBCPP_INLINE_VISIBILITY
void __cxx_atomic_store(volatile __cxx_atomic_lock_impl<_Tp>* __a, _Tp __val, memory_order) {
__a->__lock();
__cxx_atomic_assign_volatile(__a->__a_value, __val);
__a->__unlock();
}
template <typename _Tp>
_LIBCPP_INLINE_VISIBILITY
void __cxx_atomic_store(__cxx_atomic_lock_impl<_Tp>* __a, _Tp __val, memory_order) {
__a->__lock();
__a->__a_value = __val;
__a->__unlock();
}
template <typename _Tp>
_LIBCPP_INLINE_VISIBILITY
_Tp __cxx_atomic_load(const volatile __cxx_atomic_lock_impl<_Tp>* __a, memory_order) {
return __a->__read();
}
template <typename _Tp>
_LIBCPP_INLINE_VISIBILITY
_Tp __cxx_atomic_load(const __cxx_atomic_lock_impl<_Tp>* __a, memory_order) {
return __a->__read();
}
template <typename _Tp>
_LIBCPP_INLINE_VISIBILITY
_Tp __cxx_atomic_exchange(volatile __cxx_atomic_lock_impl<_Tp>* __a, _Tp __value, memory_order) {
__a->__lock();
_Tp __old;
__cxx_atomic_assign_volatile(__old, __a->__a_value);
__cxx_atomic_assign_volatile(__a->__a_value, __value);
__a->__unlock();
return __old;
}
template <typename _Tp>
_LIBCPP_INLINE_VISIBILITY
_Tp __cxx_atomic_exchange(__cxx_atomic_lock_impl<_Tp>* __a, _Tp __value, memory_order) {
__a->__lock();
_Tp __old = __a->__a_value;
__a->__a_value = __value;
__a->__unlock();
return __old;
}
template <typename _Tp>
_LIBCPP_INLINE_VISIBILITY
bool __cxx_atomic_compare_exchange_strong(volatile __cxx_atomic_lock_impl<_Tp>* __a,
_Tp* __expected, _Tp __value, memory_order, memory_order) {
__a->__lock();
_Tp temp;
__cxx_atomic_assign_volatile(temp, __a->__a_value);
bool __ret = temp == *__expected;
if(__ret)
__cxx_atomic_assign_volatile(__a->__a_value, __value);
else
__cxx_atomic_assign_volatile(*__expected, __a->__a_value);
__a->__unlock();
return __ret;
}
template <typename _Tp>
_LIBCPP_INLINE_VISIBILITY
bool __cxx_atomic_compare_exchange_strong(__cxx_atomic_lock_impl<_Tp>* __a,
_Tp* __expected, _Tp __value, memory_order, memory_order) {
__a->__lock();
bool __ret = __a->__a_value == *__expected;
if(__ret)
__a->__a_value = __value;
else
*__expected = __a->__a_value;
__a->__unlock();
return __ret;
}
template <typename _Tp>
_LIBCPP_INLINE_VISIBILITY
bool __cxx_atomic_compare_exchange_weak(volatile __cxx_atomic_lock_impl<_Tp>* __a,
_Tp* __expected, _Tp __value, memory_order, memory_order) {
__a->__lock();
_Tp temp;
__cxx_atomic_assign_volatile(temp, __a->__a_value);
bool __ret = temp == *__expected;
if(__ret)
__cxx_atomic_assign_volatile(__a->__a_value, __value);
else
__cxx_atomic_assign_volatile(*__expected, __a->__a_value);
__a->__unlock();
return __ret;
}
template <typename _Tp>
_LIBCPP_INLINE_VISIBILITY
bool __cxx_atomic_compare_exchange_weak(__cxx_atomic_lock_impl<_Tp>* __a,
_Tp* __expected, _Tp __value, memory_order, memory_order) {
__a->__lock();
bool __ret = __a->__a_value == *__expected;
if(__ret)
__a->__a_value = __value;
else
*__expected = __a->__a_value;
__a->__unlock();
return __ret;
}
template <typename _Tp, typename _Td>
_LIBCPP_INLINE_VISIBILITY
_Tp __cxx_atomic_fetch_add(volatile __cxx_atomic_lock_impl<_Tp>* __a,
_Td __delta, memory_order) {
__a->__lock();
_Tp __old;
__cxx_atomic_assign_volatile(__old, __a->__a_value);
__cxx_atomic_assign_volatile(__a->__a_value, _Tp(__old + __delta));
__a->__unlock();
return __old;
}
template <typename _Tp, typename _Td>
_LIBCPP_INLINE_VISIBILITY
_Tp __cxx_atomic_fetch_add(__cxx_atomic_lock_impl<_Tp>* __a,
_Td __delta, memory_order) {
__a->__lock();
_Tp __old = __a->__a_value;
__a->__a_value += __delta;
__a->__unlock();
return __old;
}
template <typename _Tp, typename _Td>
_LIBCPP_INLINE_VISIBILITY
_Tp* __cxx_atomic_fetch_add(volatile __cxx_atomic_lock_impl<_Tp*>* __a,
ptrdiff_t __delta, memory_order) {
__a->__lock();
_Tp* __old;
__cxx_atomic_assign_volatile(__old, __a->__a_value);
__cxx_atomic_assign_volatile(__a->__a_value, __old + __delta);
__a->__unlock();
return __old;
}
template <typename _Tp, typename _Td>
_LIBCPP_INLINE_VISIBILITY
_Tp* __cxx_atomic_fetch_add(__cxx_atomic_lock_impl<_Tp*>* __a,
ptrdiff_t __delta, memory_order) {
__a->__lock();
_Tp* __old = __a->__a_value;
__a->__a_value += __delta;
__a->__unlock();
return __old;
}
template <typename _Tp, typename _Td>
_LIBCPP_INLINE_VISIBILITY
_Tp __cxx_atomic_fetch_sub(volatile __cxx_atomic_lock_impl<_Tp>* __a,
_Td __delta, memory_order) {
__a->__lock();
_Tp __old;
__cxx_atomic_assign_volatile(__old, __a->__a_value);
__cxx_atomic_assign_volatile(__a->__a_value, _Tp(__old - __delta));
__a->__unlock();
return __old;
}
template <typename _Tp, typename _Td>
_LIBCPP_INLINE_VISIBILITY
_Tp __cxx_atomic_fetch_sub(__cxx_atomic_lock_impl<_Tp>* __a,
_Td __delta, memory_order) {
__a->__lock();
_Tp __old = __a->__a_value;
__a->__a_value -= __delta;
__a->__unlock();
return __old;
}
template <typename _Tp>
_LIBCPP_INLINE_VISIBILITY
_Tp __cxx_atomic_fetch_and(volatile __cxx_atomic_lock_impl<_Tp>* __a,
_Tp __pattern, memory_order) {
__a->__lock();
_Tp __old;
__cxx_atomic_assign_volatile(__old, __a->__a_value);
__cxx_atomic_assign_volatile(__a->__a_value, _Tp(__old & __pattern));
__a->__unlock();
return __old;
}
template <typename _Tp>
_LIBCPP_INLINE_VISIBILITY
_Tp __cxx_atomic_fetch_and(__cxx_atomic_lock_impl<_Tp>* __a,
_Tp __pattern, memory_order) {
__a->__lock();
_Tp __old = __a->__a_value;
__a->__a_value &= __pattern;
__a->__unlock();
return __old;
}
template <typename _Tp>
_LIBCPP_INLINE_VISIBILITY
_Tp __cxx_atomic_fetch_or(volatile __cxx_atomic_lock_impl<_Tp>* __a,
_Tp __pattern, memory_order) {
__a->__lock();
_Tp __old;
__cxx_atomic_assign_volatile(__old, __a->__a_value);
__cxx_atomic_assign_volatile(__a->__a_value, _Tp(__old | __pattern));
__a->__unlock();
return __old;
}
template <typename _Tp>
_LIBCPP_INLINE_VISIBILITY
_Tp __cxx_atomic_fetch_or(__cxx_atomic_lock_impl<_Tp>* __a,
_Tp __pattern, memory_order) {
__a->__lock();
_Tp __old = __a->__a_value;
__a->__a_value |= __pattern;
__a->__unlock();
return __old;
}
template <typename _Tp>
_LIBCPP_INLINE_VISIBILITY
_Tp __cxx_atomic_fetch_xor(volatile __cxx_atomic_lock_impl<_Tp>* __a,
_Tp __pattern, memory_order) {
__a->__lock();
_Tp __old;
__cxx_atomic_assign_volatile(__old, __a->__a_value);
__cxx_atomic_assign_volatile(__a->__a_value, _Tp(__old ^ __pattern));
__a->__unlock();
return __old;
}
template <typename _Tp>
_LIBCPP_INLINE_VISIBILITY
_Tp __cxx_atomic_fetch_xor(__cxx_atomic_lock_impl<_Tp>* __a,
_Tp __pattern, memory_order) {
__a->__lock();
_Tp __old = __a->__a_value;
__a->__a_value ^= __pattern;
__a->__unlock();
return __old;
}
#ifdef __cpp_lib_atomic_is_always_lock_free
template<typename _Tp> struct __cxx_is_always_lock_free {
enum { __value = __atomic_always_lock_free(sizeof(_Tp), 0) }; };
#else
template<typename _Tp> struct __cxx_is_always_lock_free { enum { __value = false }; };
// Implementations must match the C ATOMIC_*_LOCK_FREE macro values.
template<> struct __cxx_is_always_lock_free<bool> { enum { __value = 2 == ATOMIC_BOOL_LOCK_FREE }; };
template<> struct __cxx_is_always_lock_free<char> { enum { __value = 2 == ATOMIC_CHAR_LOCK_FREE }; };
template<> struct __cxx_is_always_lock_free<signed char> { enum { __value = 2 == ATOMIC_CHAR_LOCK_FREE }; };
template<> struct __cxx_is_always_lock_free<unsigned char> { enum { __value = 2 == ATOMIC_CHAR_LOCK_FREE }; };
template<> struct __cxx_is_always_lock_free<char16_t> { enum { __value = 2 == ATOMIC_CHAR16_T_LOCK_FREE }; };
template<> struct __cxx_is_always_lock_free<char32_t> { enum { __value = 2 == ATOMIC_CHAR32_T_LOCK_FREE }; };
template<> struct __cxx_is_always_lock_free<wchar_t> { enum { __value = 2 == ATOMIC_WCHAR_T_LOCK_FREE }; };
template<> struct __cxx_is_always_lock_free<short> { enum { __value = 2 == ATOMIC_SHORT_LOCK_FREE }; };
template<> struct __cxx_is_always_lock_free<unsigned short> { enum { __value = 2 == ATOMIC_SHORT_LOCK_FREE }; };
template<> struct __cxx_is_always_lock_free<int> { enum { __value = 2 == ATOMIC_INT_LOCK_FREE }; };
template<> struct __cxx_is_always_lock_free<unsigned int> { enum { __value = 2 == ATOMIC_INT_LOCK_FREE }; };
template<> struct __cxx_is_always_lock_free<long> { enum { __value = 2 == ATOMIC_LONG_LOCK_FREE }; };
template<> struct __cxx_is_always_lock_free<unsigned long> { enum { __value = 2 == ATOMIC_LONG_LOCK_FREE }; };
template<> struct __cxx_is_always_lock_free<long long> { enum { __value = 2 == ATOMIC_LLONG_LOCK_FREE }; };
template<> struct __cxx_is_always_lock_free<unsigned long long> { enum { __value = 2 == ATOMIC_LLONG_LOCK_FREE }; };
template<typename _Tp> struct __cxx_is_always_lock_free<_Tp*> { enum { __value = 2 == ATOMIC_POINTER_LOCK_FREE }; };
template<> struct __cxx_is_always_lock_free<std::nullptr_t> { enum { __value = 2 == ATOMIC_POINTER_LOCK_FREE }; };
#endif //__cpp_lib_atomic_is_always_lock_free
template <typename _Tp,
typename _Base = typename conditional<__cxx_is_always_lock_free<_Tp>::__value,
__cxx_atomic_base_impl<_Tp>,
__cxx_atomic_lock_impl<_Tp> >::type>
#else
template <typename _Tp,
typename _Base = __cxx_atomic_base_impl<_Tp> >
#endif //_LIBCPP_ATOMIC_ONLY_USE_BUILTINS
struct __cxx_atomic_impl : public _Base {
#if _GNUC_VER >= 501
static_assert(is_trivially_copyable<_Tp>::value,
"std::atomic<Tp> requires that 'Tp' be a trivially copyable type");
#endif
_LIBCPP_INLINE_VISIBILITY __cxx_atomic_impl() _NOEXCEPT _LIBCPP_DEFAULT
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR explicit __cxx_atomic_impl(_Tp value) _NOEXCEPT
: _Base(value) {}
};
// general atomic<T>
template <class _Tp, bool = is_integral<_Tp>::value && !is_same<_Tp, bool>::value>
struct __atomic_base // false
{
mutable __cxx_atomic_impl<_Tp> __a_;
#if defined(__cpp_lib_atomic_is_always_lock_free)
static _LIBCPP_CONSTEXPR bool is_always_lock_free = __atomic_always_lock_free(sizeof(__a_), 0);
#endif
_LIBCPP_INLINE_VISIBILITY
bool is_lock_free() const volatile _NOEXCEPT
{return __cxx_atomic_is_lock_free(sizeof(_Tp));}
_LIBCPP_INLINE_VISIBILITY
bool is_lock_free() const _NOEXCEPT
{return static_cast<__atomic_base const volatile*>(this)->is_lock_free();}
_LIBCPP_INLINE_VISIBILITY
void store(_Tp __d, memory_order __m = memory_order_seq_cst) volatile _NOEXCEPT
_LIBCPP_CHECK_STORE_MEMORY_ORDER(__m)
{__cxx_atomic_store(&__a_, __d, __m);}
_LIBCPP_INLINE_VISIBILITY
void store(_Tp __d, memory_order __m = memory_order_seq_cst) _NOEXCEPT
_LIBCPP_CHECK_STORE_MEMORY_ORDER(__m)
{__cxx_atomic_store(&__a_, __d, __m);}
_LIBCPP_INLINE_VISIBILITY
_Tp load(memory_order __m = memory_order_seq_cst) const volatile _NOEXCEPT
_LIBCPP_CHECK_LOAD_MEMORY_ORDER(__m)
{return __cxx_atomic_load(&__a_, __m);}
_LIBCPP_INLINE_VISIBILITY
_Tp load(memory_order __m = memory_order_seq_cst) const _NOEXCEPT
_LIBCPP_CHECK_LOAD_MEMORY_ORDER(__m)
{return __cxx_atomic_load(&__a_, __m);}
_LIBCPP_INLINE_VISIBILITY
operator _Tp() const volatile _NOEXCEPT {return load();}
_LIBCPP_INLINE_VISIBILITY
operator _Tp() const _NOEXCEPT {return load();}
_LIBCPP_INLINE_VISIBILITY
_Tp exchange(_Tp __d, memory_order __m = memory_order_seq_cst) volatile _NOEXCEPT
{return __cxx_atomic_exchange(&__a_, __d, __m);}
_LIBCPP_INLINE_VISIBILITY
_Tp exchange(_Tp __d, memory_order __m = memory_order_seq_cst) _NOEXCEPT
{return __cxx_atomic_exchange(&__a_, __d, __m);}
_LIBCPP_INLINE_VISIBILITY
bool compare_exchange_weak(_Tp& __e, _Tp __d,
memory_order __s, memory_order __f) volatile _NOEXCEPT
_LIBCPP_CHECK_EXCHANGE_MEMORY_ORDER(__s, __f)
{return __cxx_atomic_compare_exchange_weak(&__a_, &__e, __d, __s, __f);}
_LIBCPP_INLINE_VISIBILITY
bool compare_exchange_weak(_Tp& __e, _Tp __d,
memory_order __s, memory_order __f) _NOEXCEPT
_LIBCPP_CHECK_EXCHANGE_MEMORY_ORDER(__s, __f)
{return __cxx_atomic_compare_exchange_weak(&__a_, &__e, __d, __s, __f);}
_LIBCPP_INLINE_VISIBILITY
bool compare_exchange_strong(_Tp& __e, _Tp __d,
memory_order __s, memory_order __f) volatile _NOEXCEPT
_LIBCPP_CHECK_EXCHANGE_MEMORY_ORDER(__s, __f)
{return __cxx_atomic_compare_exchange_strong(&__a_, &__e, __d, __s, __f);}
_LIBCPP_INLINE_VISIBILITY
bool compare_exchange_strong(_Tp& __e, _Tp __d,
memory_order __s, memory_order __f) _NOEXCEPT
_LIBCPP_CHECK_EXCHANGE_MEMORY_ORDER(__s, __f)
{return __cxx_atomic_compare_exchange_strong(&__a_, &__e, __d, __s, __f);}
_LIBCPP_INLINE_VISIBILITY
bool compare_exchange_weak(_Tp& __e, _Tp __d,
memory_order __m = memory_order_seq_cst) volatile _NOEXCEPT
{return __cxx_atomic_compare_exchange_weak(&__a_, &__e, __d, __m, __m);}
_LIBCPP_INLINE_VISIBILITY
bool compare_exchange_weak(_Tp& __e, _Tp __d,
memory_order __m = memory_order_seq_cst) _NOEXCEPT
{return __cxx_atomic_compare_exchange_weak(&__a_, &__e, __d, __m, __m);}
_LIBCPP_INLINE_VISIBILITY
bool compare_exchange_strong(_Tp& __e, _Tp __d,
memory_order __m = memory_order_seq_cst) volatile _NOEXCEPT
{return __cxx_atomic_compare_exchange_strong(&__a_, &__e, __d, __m, __m);}
_LIBCPP_INLINE_VISIBILITY
bool compare_exchange_strong(_Tp& __e, _Tp __d,
memory_order __m = memory_order_seq_cst) _NOEXCEPT
{return __cxx_atomic_compare_exchange_strong(&__a_, &__e, __d, __m, __m);}
_LIBCPP_INLINE_VISIBILITY
__atomic_base() _NOEXCEPT _LIBCPP_DEFAULT
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
__atomic_base(_Tp __d) _NOEXCEPT : __a_(__d) {}
#ifndef _LIBCPP_CXX03_LANG
__atomic_base(const __atomic_base&) = delete;
__atomic_base& operator=(const __atomic_base&) = delete;
__atomic_base& operator=(const __atomic_base&) volatile = delete;
#else
private:
__atomic_base(const __atomic_base&);
__atomic_base& operator=(const __atomic_base&);
__atomic_base& operator=(const __atomic_base&) volatile;
#endif
};
#if defined(__cpp_lib_atomic_is_always_lock_free)
template <class _Tp, bool __b>
_LIBCPP_CONSTEXPR bool __atomic_base<_Tp, __b>::is_always_lock_free;
#endif
// atomic<Integral>
template <class _Tp>
struct __atomic_base<_Tp, true>
: public __atomic_base<_Tp, false>
{
typedef __atomic_base<_Tp, false> __base;
_LIBCPP_INLINE_VISIBILITY
__atomic_base() _NOEXCEPT _LIBCPP_DEFAULT
_LIBCPP_INLINE_VISIBILITY
_LIBCPP_CONSTEXPR __atomic_base(_Tp __d) _NOEXCEPT : __base(__d) {}
_LIBCPP_INLINE_VISIBILITY
_Tp fetch_add(_Tp __op, memory_order __m = memory_order_seq_cst) volatile _NOEXCEPT
{return __cxx_atomic_fetch_add(&this->__a_, __op, __m);}
_LIBCPP_INLINE_VISIBILITY
_Tp fetch_add(_Tp __op, memory_order __m = memory_order_seq_cst) _NOEXCEPT
{return __cxx_atomic_fetch_add(&this->__a_, __op, __m);}
_LIBCPP_INLINE_VISIBILITY
_Tp fetch_sub(_Tp __op, memory_order __m = memory_order_seq_cst) volatile _NOEXCEPT
{return __cxx_atomic_fetch_sub(&this->__a_, __op, __m);}
_LIBCPP_INLINE_VISIBILITY
_Tp fetch_sub(_Tp __op, memory_order __m = memory_order_seq_cst) _NOEXCEPT
{return __cxx_atomic_fetch_sub(&this->__a_, __op, __m);}
_LIBCPP_INLINE_VISIBILITY
_Tp fetch_and(_Tp __op, memory_order __m = memory_order_seq_cst) volatile _NOEXCEPT
{return __cxx_atomic_fetch_and(&this->__a_, __op, __m);}
_LIBCPP_INLINE_VISIBILITY
_Tp fetch_and(_Tp __op, memory_order __m = memory_order_seq_cst) _NOEXCEPT
{return __cxx_atomic_fetch_and(&this->__a_, __op, __m);}
_LIBCPP_INLINE_VISIBILITY
_Tp fetch_or(_Tp __op, memory_order __m = memory_order_seq_cst) volatile _NOEXCEPT
{return __cxx_atomic_fetch_or(&this->__a_, __op, __m);}
_LIBCPP_INLINE_VISIBILITY
_Tp fetch_or(_Tp __op, memory_order __m = memory_order_seq_cst) _NOEXCEPT
{return __cxx_atomic_fetch_or(&this->__a_, __op, __m);}
_LIBCPP_INLINE_VISIBILITY
_Tp fetch_xor(_Tp __op, memory_order __m = memory_order_seq_cst) volatile _NOEXCEPT
{return __cxx_atomic_fetch_xor(&this->__a_, __op, __m);}
_LIBCPP_INLINE_VISIBILITY
_Tp fetch_xor(_Tp __op, memory_order __m = memory_order_seq_cst) _NOEXCEPT
{return __cxx_atomic_fetch_xor(&this->__a_, __op, __m);}
_LIBCPP_INLINE_VISIBILITY
_Tp operator++(int) volatile _NOEXCEPT {return fetch_add(_Tp(1));}
_LIBCPP_INLINE_VISIBILITY
_Tp operator++(int) _NOEXCEPT {return fetch_add(_Tp(1));}
_LIBCPP_INLINE_VISIBILITY
_Tp operator--(int) volatile _NOEXCEPT {return fetch_sub(_Tp(1));}
_LIBCPP_INLINE_VISIBILITY
_Tp operator--(int) _NOEXCEPT {return fetch_sub(_Tp(1));}
_LIBCPP_INLINE_VISIBILITY
_Tp operator++() volatile _NOEXCEPT {return fetch_add(_Tp(1)) + _Tp(1);}
_LIBCPP_INLINE_VISIBILITY
_Tp operator++() _NOEXCEPT {return fetch_add(_Tp(1)) + _Tp(1);}
_LIBCPP_INLINE_VISIBILITY
_Tp operator--() volatile _NOEXCEPT {return fetch_sub(_Tp(1)) - _Tp(1);}
_LIBCPP_INLINE_VISIBILITY
_Tp operator--() _NOEXCEPT {return fetch_sub(_Tp(1)) - _Tp(1);}
_LIBCPP_INLINE_VISIBILITY
_Tp operator+=(_Tp __op) volatile _NOEXCEPT {return fetch_add(__op) + __op;}
_LIBCPP_INLINE_VISIBILITY
_Tp operator+=(_Tp __op) _NOEXCEPT {return fetch_add(__op) + __op;}
_LIBCPP_INLINE_VISIBILITY
_Tp operator-=(_Tp __op) volatile _NOEXCEPT {return fetch_sub(__op) - __op;}
_LIBCPP_INLINE_VISIBILITY
_Tp operator-=(_Tp __op) _NOEXCEPT {return fetch_sub(__op) - __op;}
_LIBCPP_INLINE_VISIBILITY
_Tp operator&=(_Tp __op) volatile _NOEXCEPT {return fetch_and(__op) & __op;}
_LIBCPP_INLINE_VISIBILITY
_Tp operator&=(_Tp __op) _NOEXCEPT {return fetch_and(__op) & __op;}
_LIBCPP_INLINE_VISIBILITY
_Tp operator|=(_Tp __op) volatile _NOEXCEPT {return fetch_or(__op) | __op;}
_LIBCPP_INLINE_VISIBILITY
_Tp operator|=(_Tp __op) _NOEXCEPT {return fetch_or(__op) | __op;}
_LIBCPP_INLINE_VISIBILITY
_Tp operator^=(_Tp __op) volatile _NOEXCEPT {return fetch_xor(__op) ^ __op;}
_LIBCPP_INLINE_VISIBILITY
_Tp operator^=(_Tp __op) _NOEXCEPT {return fetch_xor(__op) ^ __op;}
};
// atomic<T>
template <class _Tp>
struct atomic
: public __atomic_base<_Tp>
{
typedef __atomic_base<_Tp> __base;
_LIBCPP_INLINE_VISIBILITY
atomic() _NOEXCEPT _LIBCPP_DEFAULT
_LIBCPP_INLINE_VISIBILITY
_LIBCPP_CONSTEXPR atomic(_Tp __d) _NOEXCEPT : __base(__d) {}
_LIBCPP_INLINE_VISIBILITY
_Tp operator=(_Tp __d) volatile _NOEXCEPT
{__base::store(__d); return __d;}
_LIBCPP_INLINE_VISIBILITY
_Tp operator=(_Tp __d) _NOEXCEPT
{__base::store(__d); return __d;}
};
// atomic<T*>
template <class _Tp>
struct atomic<_Tp*>
: public __atomic_base<_Tp*>
{
typedef __atomic_base<_Tp*> __base;
_LIBCPP_INLINE_VISIBILITY
atomic() _NOEXCEPT _LIBCPP_DEFAULT
_LIBCPP_INLINE_VISIBILITY
_LIBCPP_CONSTEXPR atomic(_Tp* __d) _NOEXCEPT : __base(__d) {}
_LIBCPP_INLINE_VISIBILITY
_Tp* operator=(_Tp* __d) volatile _NOEXCEPT
{__base::store(__d); return __d;}
_LIBCPP_INLINE_VISIBILITY
_Tp* operator=(_Tp* __d) _NOEXCEPT
{__base::store(__d); return __d;}
_LIBCPP_INLINE_VISIBILITY
_Tp* fetch_add(ptrdiff_t __op, memory_order __m = memory_order_seq_cst)
volatile _NOEXCEPT
{return __cxx_atomic_fetch_add(&this->__a_, __op, __m);}
_LIBCPP_INLINE_VISIBILITY
_Tp* fetch_add(ptrdiff_t __op, memory_order __m = memory_order_seq_cst) _NOEXCEPT
{return __cxx_atomic_fetch_add(&this->__a_, __op, __m);}
_LIBCPP_INLINE_VISIBILITY
_Tp* fetch_sub(ptrdiff_t __op, memory_order __m = memory_order_seq_cst)
volatile _NOEXCEPT
{return __cxx_atomic_fetch_sub(&this->__a_, __op, __m);}
_LIBCPP_INLINE_VISIBILITY
_Tp* fetch_sub(ptrdiff_t __op, memory_order __m = memory_order_seq_cst) _NOEXCEPT
{return __cxx_atomic_fetch_sub(&this->__a_, __op, __m);}
_LIBCPP_INLINE_VISIBILITY
_Tp* operator++(int) volatile _NOEXCEPT {return fetch_add(1);}
_LIBCPP_INLINE_VISIBILITY
_Tp* operator++(int) _NOEXCEPT {return fetch_add(1);}
_LIBCPP_INLINE_VISIBILITY
_Tp* operator--(int) volatile _NOEXCEPT {return fetch_sub(1);}
_LIBCPP_INLINE_VISIBILITY
_Tp* operator--(int) _NOEXCEPT {return fetch_sub(1);}
_LIBCPP_INLINE_VISIBILITY
_Tp* operator++() volatile _NOEXCEPT {return fetch_add(1) + 1;}
_LIBCPP_INLINE_VISIBILITY
_Tp* operator++() _NOEXCEPT {return fetch_add(1) + 1;}
_LIBCPP_INLINE_VISIBILITY
_Tp* operator--() volatile _NOEXCEPT {return fetch_sub(1) - 1;}
_LIBCPP_INLINE_VISIBILITY
_Tp* operator--() _NOEXCEPT {return fetch_sub(1) - 1;}
_LIBCPP_INLINE_VISIBILITY
_Tp* operator+=(ptrdiff_t __op) volatile _NOEXCEPT {return fetch_add(__op) + __op;}
_LIBCPP_INLINE_VISIBILITY
_Tp* operator+=(ptrdiff_t __op) _NOEXCEPT {return fetch_add(__op) + __op;}
_LIBCPP_INLINE_VISIBILITY
_Tp* operator-=(ptrdiff_t __op) volatile _NOEXCEPT {return fetch_sub(__op) - __op;}
_LIBCPP_INLINE_VISIBILITY
_Tp* operator-=(ptrdiff_t __op) _NOEXCEPT {return fetch_sub(__op) - __op;}
};
// atomic_is_lock_free
template <class _Tp>
_LIBCPP_INLINE_VISIBILITY
bool
atomic_is_lock_free(const volatile atomic<_Tp>* __o) _NOEXCEPT
{
return __o->is_lock_free();
}
template <class _Tp>
_LIBCPP_INLINE_VISIBILITY
bool
atomic_is_lock_free(const atomic<_Tp>* __o) _NOEXCEPT
{
return __o->is_lock_free();
}
// atomic_init
template <class _Tp>
_LIBCPP_INLINE_VISIBILITY
void
atomic_init(volatile atomic<_Tp>* __o, _Tp __d) _NOEXCEPT
{
__cxx_atomic_init(&__o->__a_, __d);
}
template <class _Tp>
_LIBCPP_INLINE_VISIBILITY
void
atomic_init(atomic<_Tp>* __o, _Tp __d) _NOEXCEPT
{
__cxx_atomic_init(&__o->__a_, __d);
}
// atomic_store
template <class _Tp>
_LIBCPP_INLINE_VISIBILITY
void
atomic_store(volatile atomic<_Tp>* __o, _Tp __d) _NOEXCEPT
{
__o->store(__d);
}
template <class _Tp>
_LIBCPP_INLINE_VISIBILITY
void
atomic_store(atomic<_Tp>* __o, _Tp __d) _NOEXCEPT
{
__o->store(__d);
}
// atomic_store_explicit
template <class _Tp>
_LIBCPP_INLINE_VISIBILITY
void
atomic_store_explicit(volatile atomic<_Tp>* __o, _Tp __d, memory_order __m) _NOEXCEPT
_LIBCPP_CHECK_STORE_MEMORY_ORDER(__m)
{
__o->store(__d, __m);
}
template <class _Tp>
_LIBCPP_INLINE_VISIBILITY
void
atomic_store_explicit(atomic<_Tp>* __o, _Tp __d, memory_order __m) _NOEXCEPT
_LIBCPP_CHECK_STORE_MEMORY_ORDER(__m)
{
__o->store(__d, __m);
}
// atomic_load
template <class _Tp>
_LIBCPP_INLINE_VISIBILITY
_Tp
atomic_load(const volatile atomic<_Tp>* __o) _NOEXCEPT
{
return __o->load();
}
template <class _Tp>
_LIBCPP_INLINE_VISIBILITY
_Tp
atomic_load(const atomic<_Tp>* __o) _NOEXCEPT
{
return __o->load();
}
// atomic_load_explicit
template <class _Tp>
_LIBCPP_INLINE_VISIBILITY
_Tp
atomic_load_explicit(const volatile atomic<_Tp>* __o, memory_order __m) _NOEXCEPT
_LIBCPP_CHECK_LOAD_MEMORY_ORDER(__m)
{
return __o->load(__m);
}
template <class _Tp>
_LIBCPP_INLINE_VISIBILITY
_Tp
atomic_load_explicit(const atomic<_Tp>* __o, memory_order __m) _NOEXCEPT
_LIBCPP_CHECK_LOAD_MEMORY_ORDER(__m)
{
return __o->load(__m);
}
// atomic_exchange
template <class _Tp>
_LIBCPP_INLINE_VISIBILITY
_Tp
atomic_exchange(volatile atomic<_Tp>* __o, _Tp __d) _NOEXCEPT
{
return __o->exchange(__d);
}
template <class _Tp>
_LIBCPP_INLINE_VISIBILITY
_Tp
atomic_exchange(atomic<_Tp>* __o, _Tp __d) _NOEXCEPT
{
return __o->exchange(__d);
}
// atomic_exchange_explicit
template <class _Tp>
_LIBCPP_INLINE_VISIBILITY
_Tp
atomic_exchange_explicit(volatile atomic<_Tp>* __o, _Tp __d, memory_order __m) _NOEXCEPT
{
return __o->exchange(__d, __m);
}
template <class _Tp>
_LIBCPP_INLINE_VISIBILITY
_Tp
atomic_exchange_explicit(atomic<_Tp>* __o, _Tp __d, memory_order __m) _NOEXCEPT
{
return __o->exchange(__d, __m);
}
// atomic_compare_exchange_weak
template <class _Tp>
_LIBCPP_INLINE_VISIBILITY
bool
atomic_compare_exchange_weak(volatile atomic<_Tp>* __o, _Tp* __e, _Tp __d) _NOEXCEPT
{
return __o->compare_exchange_weak(*__e, __d);
}
template <class _Tp>
_LIBCPP_INLINE_VISIBILITY
bool
atomic_compare_exchange_weak(atomic<_Tp>* __o, _Tp* __e, _Tp __d) _NOEXCEPT
{
return __o->compare_exchange_weak(*__e, __d);
}
// atomic_compare_exchange_strong
template <class _Tp>
_LIBCPP_INLINE_VISIBILITY
bool
atomic_compare_exchange_strong(volatile atomic<_Tp>* __o, _Tp* __e, _Tp __d) _NOEXCEPT
{
return __o->compare_exchange_strong(*__e, __d);
}
template <class _Tp>
_LIBCPP_INLINE_VISIBILITY
bool
atomic_compare_exchange_strong(atomic<_Tp>* __o, _Tp* __e, _Tp __d) _NOEXCEPT
{
return __o->compare_exchange_strong(*__e, __d);
}
// atomic_compare_exchange_weak_explicit
template <class _Tp>
_LIBCPP_INLINE_VISIBILITY
bool
atomic_compare_exchange_weak_explicit(volatile atomic<_Tp>* __o, _Tp* __e,
_Tp __d,
memory_order __s, memory_order __f) _NOEXCEPT
_LIBCPP_CHECK_EXCHANGE_MEMORY_ORDER(__s, __f)
{
return __o->compare_exchange_weak(*__e, __d, __s, __f);
}
template <class _Tp>
_LIBCPP_INLINE_VISIBILITY
bool
atomic_compare_exchange_weak_explicit(atomic<_Tp>* __o, _Tp* __e, _Tp __d,
memory_order __s, memory_order __f) _NOEXCEPT
_LIBCPP_CHECK_EXCHANGE_MEMORY_ORDER(__s, __f)
{
return __o->compare_exchange_weak(*__e, __d, __s, __f);
}
// atomic_compare_exchange_strong_explicit
template <class _Tp>
_LIBCPP_INLINE_VISIBILITY
bool
atomic_compare_exchange_strong_explicit(volatile atomic<_Tp>* __o,
_Tp* __e, _Tp __d,
memory_order __s, memory_order __f) _NOEXCEPT
_LIBCPP_CHECK_EXCHANGE_MEMORY_ORDER(__s, __f)
{
return __o->compare_exchange_strong(*__e, __d, __s, __f);
}
template <class _Tp>
_LIBCPP_INLINE_VISIBILITY
bool
atomic_compare_exchange_strong_explicit(atomic<_Tp>* __o, _Tp* __e,
_Tp __d,
memory_order __s, memory_order __f) _NOEXCEPT
_LIBCPP_CHECK_EXCHANGE_MEMORY_ORDER(__s, __f)
{
return __o->compare_exchange_strong(*__e, __d, __s, __f);
}
// atomic_fetch_add
template <class _Tp>
_LIBCPP_INLINE_VISIBILITY
typename enable_if
<
is_integral<_Tp>::value && !is_same<_Tp, bool>::value,
_Tp
>::type
atomic_fetch_add(volatile atomic<_Tp>* __o, _Tp __op) _NOEXCEPT
{
return __o->fetch_add(__op);
}
template <class _Tp>
_LIBCPP_INLINE_VISIBILITY
typename enable_if
<
is_integral<_Tp>::value && !is_same<_Tp, bool>::value,
_Tp
>::type
atomic_fetch_add(atomic<_Tp>* __o, _Tp __op) _NOEXCEPT
{
return __o->fetch_add(__op);
}
template <class _Tp>
_LIBCPP_INLINE_VISIBILITY
_Tp*
atomic_fetch_add(volatile atomic<_Tp*>* __o, ptrdiff_t __op) _NOEXCEPT
{
return __o->fetch_add(__op);
}
template <class _Tp>
_LIBCPP_INLINE_VISIBILITY
_Tp*
atomic_fetch_add(atomic<_Tp*>* __o, ptrdiff_t __op) _NOEXCEPT
{
return __o->fetch_add(__op);
}
// atomic_fetch_add_explicit
template <class _Tp>
_LIBCPP_INLINE_VISIBILITY
typename enable_if
<
is_integral<_Tp>::value && !is_same<_Tp, bool>::value,
_Tp
>::type
atomic_fetch_add_explicit(volatile atomic<_Tp>* __o, _Tp __op, memory_order __m) _NOEXCEPT
{
return __o->fetch_add(__op, __m);
}
template <class _Tp>
_LIBCPP_INLINE_VISIBILITY
typename enable_if
<
is_integral<_Tp>::value && !is_same<_Tp, bool>::value,
_Tp
>::type
atomic_fetch_add_explicit(atomic<_Tp>* __o, _Tp __op, memory_order __m) _NOEXCEPT
{
return __o->fetch_add(__op, __m);
}
template <class _Tp>
_LIBCPP_INLINE_VISIBILITY
_Tp*
atomic_fetch_add_explicit(volatile atomic<_Tp*>* __o, ptrdiff_t __op,
memory_order __m) _NOEXCEPT
{
return __o->fetch_add(__op, __m);
}
template <class _Tp>
_LIBCPP_INLINE_VISIBILITY
_Tp*
atomic_fetch_add_explicit(atomic<_Tp*>* __o, ptrdiff_t __op, memory_order __m) _NOEXCEPT
{
return __o->fetch_add(__op, __m);
}
// atomic_fetch_sub
template <class _Tp>
_LIBCPP_INLINE_VISIBILITY
typename enable_if
<
is_integral<_Tp>::value && !is_same<_Tp, bool>::value,
_Tp
>::type
atomic_fetch_sub(volatile atomic<_Tp>* __o, _Tp __op) _NOEXCEPT
{
return __o->fetch_sub(__op);
}
template <class _Tp>
_LIBCPP_INLINE_VISIBILITY
typename enable_if
<
is_integral<_Tp>::value && !is_same<_Tp, bool>::value,
_Tp
>::type
atomic_fetch_sub(atomic<_Tp>* __o, _Tp __op) _NOEXCEPT
{
return __o->fetch_sub(__op);
}
template <class _Tp>
_LIBCPP_INLINE_VISIBILITY
_Tp*
atomic_fetch_sub(volatile atomic<_Tp*>* __o, ptrdiff_t __op) _NOEXCEPT
{
return __o->fetch_sub(__op);
}
template <class _Tp>
_LIBCPP_INLINE_VISIBILITY
_Tp*
atomic_fetch_sub(atomic<_Tp*>* __o, ptrdiff_t __op) _NOEXCEPT
{
return __o->fetch_sub(__op);
}
// atomic_fetch_sub_explicit
template <class _Tp>
_LIBCPP_INLINE_VISIBILITY
typename enable_if
<
is_integral<_Tp>::value && !is_same<_Tp, bool>::value,
_Tp
>::type
atomic_fetch_sub_explicit(volatile atomic<_Tp>* __o, _Tp __op, memory_order __m) _NOEXCEPT
{
return __o->fetch_sub(__op, __m);
}
template <class _Tp>
_LIBCPP_INLINE_VISIBILITY
typename enable_if
<
is_integral<_Tp>::value && !is_same<_Tp, bool>::value,
_Tp
>::type
atomic_fetch_sub_explicit(atomic<_Tp>* __o, _Tp __op, memory_order __m) _NOEXCEPT
{
return __o->fetch_sub(__op, __m);
}
template <class _Tp>
_LIBCPP_INLINE_VISIBILITY
_Tp*
atomic_fetch_sub_explicit(volatile atomic<_Tp*>* __o, ptrdiff_t __op,
memory_order __m) _NOEXCEPT
{
return __o->fetch_sub(__op, __m);
}
template <class _Tp>
_LIBCPP_INLINE_VISIBILITY
_Tp*
atomic_fetch_sub_explicit(atomic<_Tp*>* __o, ptrdiff_t __op, memory_order __m) _NOEXCEPT
{
return __o->fetch_sub(__op, __m);
}
// atomic_fetch_and
template <class _Tp>
_LIBCPP_INLINE_VISIBILITY
typename enable_if
<
is_integral<_Tp>::value && !is_same<_Tp, bool>::value,
_Tp
>::type
atomic_fetch_and(volatile atomic<_Tp>* __o, _Tp __op) _NOEXCEPT
{
return __o->fetch_and(__op);
}
template <class _Tp>
_LIBCPP_INLINE_VISIBILITY
typename enable_if
<
is_integral<_Tp>::value && !is_same<_Tp, bool>::value,
_Tp
>::type
atomic_fetch_and(atomic<_Tp>* __o, _Tp __op) _NOEXCEPT
{
return __o->fetch_and(__op);
}
// atomic_fetch_and_explicit
template <class _Tp>
_LIBCPP_INLINE_VISIBILITY
typename enable_if
<
is_integral<_Tp>::value && !is_same<_Tp, bool>::value,
_Tp
>::type
atomic_fetch_and_explicit(volatile atomic<_Tp>* __o, _Tp __op, memory_order __m) _NOEXCEPT
{
return __o->fetch_and(__op, __m);
}
template <class _Tp>
_LIBCPP_INLINE_VISIBILITY
typename enable_if
<
is_integral<_Tp>::value && !is_same<_Tp, bool>::value,
_Tp
>::type
atomic_fetch_and_explicit(atomic<_Tp>* __o, _Tp __op, memory_order __m) _NOEXCEPT
{
return __o->fetch_and(__op, __m);
}
// atomic_fetch_or
template <class _Tp>
_LIBCPP_INLINE_VISIBILITY
typename enable_if
<
is_integral<_Tp>::value && !is_same<_Tp, bool>::value,
_Tp
>::type
atomic_fetch_or(volatile atomic<_Tp>* __o, _Tp __op) _NOEXCEPT
{
return __o->fetch_or(__op);
}
template <class _Tp>
_LIBCPP_INLINE_VISIBILITY
typename enable_if
<
is_integral<_Tp>::value && !is_same<_Tp, bool>::value,
_Tp
>::type
atomic_fetch_or(atomic<_Tp>* __o, _Tp __op) _NOEXCEPT
{
return __o->fetch_or(__op);
}
// atomic_fetch_or_explicit
template <class _Tp>
_LIBCPP_INLINE_VISIBILITY
typename enable_if
<
is_integral<_Tp>::value && !is_same<_Tp, bool>::value,
_Tp
>::type
atomic_fetch_or_explicit(volatile atomic<_Tp>* __o, _Tp __op, memory_order __m) _NOEXCEPT
{
return __o->fetch_or(__op, __m);
}
template <class _Tp>
_LIBCPP_INLINE_VISIBILITY
typename enable_if
<
is_integral<_Tp>::value && !is_same<_Tp, bool>::value,
_Tp
>::type
atomic_fetch_or_explicit(atomic<_Tp>* __o, _Tp __op, memory_order __m) _NOEXCEPT
{
return __o->fetch_or(__op, __m);
}
// atomic_fetch_xor
template <class _Tp>
_LIBCPP_INLINE_VISIBILITY
typename enable_if
<
is_integral<_Tp>::value && !is_same<_Tp, bool>::value,
_Tp
>::type
atomic_fetch_xor(volatile atomic<_Tp>* __o, _Tp __op) _NOEXCEPT
{
return __o->fetch_xor(__op);
}
template <class _Tp>
_LIBCPP_INLINE_VISIBILITY
typename enable_if
<
is_integral<_Tp>::value && !is_same<_Tp, bool>::value,
_Tp
>::type
atomic_fetch_xor(atomic<_Tp>* __o, _Tp __op) _NOEXCEPT
{
return __o->fetch_xor(__op);
}
// atomic_fetch_xor_explicit
template <class _Tp>
_LIBCPP_INLINE_VISIBILITY
typename enable_if
<
is_integral<_Tp>::value && !is_same<_Tp, bool>::value,
_Tp
>::type
atomic_fetch_xor_explicit(volatile atomic<_Tp>* __o, _Tp __op, memory_order __m) _NOEXCEPT
{
return __o->fetch_xor(__op, __m);
}
template <class _Tp>
_LIBCPP_INLINE_VISIBILITY
typename enable_if
<
is_integral<_Tp>::value && !is_same<_Tp, bool>::value,
_Tp
>::type
atomic_fetch_xor_explicit(atomic<_Tp>* __o, _Tp __op, memory_order __m) _NOEXCEPT
{
return __o->fetch_xor(__op, __m);
}
// flag type and operations
typedef struct atomic_flag
{
__cxx_atomic_impl<_LIBCPP_ATOMIC_FLAG_TYPE> __a_;
_LIBCPP_INLINE_VISIBILITY
bool test_and_set(memory_order __m = memory_order_seq_cst) volatile _NOEXCEPT
{return __cxx_atomic_exchange(&__a_, _LIBCPP_ATOMIC_FLAG_TYPE(true), __m);}
_LIBCPP_INLINE_VISIBILITY
bool test_and_set(memory_order __m = memory_order_seq_cst) _NOEXCEPT
{return __cxx_atomic_exchange(&__a_, _LIBCPP_ATOMIC_FLAG_TYPE(true), __m);}
_LIBCPP_INLINE_VISIBILITY
void clear(memory_order __m = memory_order_seq_cst) volatile _NOEXCEPT
{__cxx_atomic_store(&__a_, _LIBCPP_ATOMIC_FLAG_TYPE(false), __m);}
_LIBCPP_INLINE_VISIBILITY
void clear(memory_order __m = memory_order_seq_cst) _NOEXCEPT
{__cxx_atomic_store(&__a_, _LIBCPP_ATOMIC_FLAG_TYPE(false), __m);}
_LIBCPP_INLINE_VISIBILITY
atomic_flag() _NOEXCEPT _LIBCPP_DEFAULT
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
atomic_flag(bool __b) _NOEXCEPT : __a_(__b) {} // EXTENSION
#ifndef _LIBCPP_CXX03_LANG
atomic_flag(const atomic_flag&) = delete;
atomic_flag& operator=(const atomic_flag&) = delete;
atomic_flag& operator=(const atomic_flag&) volatile = delete;
#else
private:
atomic_flag(const atomic_flag&);
atomic_flag& operator=(const atomic_flag&);
atomic_flag& operator=(const atomic_flag&) volatile;
#endif
} atomic_flag;
inline _LIBCPP_INLINE_VISIBILITY
bool
atomic_flag_test_and_set(volatile atomic_flag* __o) _NOEXCEPT
{
return __o->test_and_set();
}
inline _LIBCPP_INLINE_VISIBILITY
bool
atomic_flag_test_and_set(atomic_flag* __o) _NOEXCEPT
{
return __o->test_and_set();
}
inline _LIBCPP_INLINE_VISIBILITY
bool
atomic_flag_test_and_set_explicit(volatile atomic_flag* __o, memory_order __m) _NOEXCEPT
{
return __o->test_and_set(__m);
}
inline _LIBCPP_INLINE_VISIBILITY
bool
atomic_flag_test_and_set_explicit(atomic_flag* __o, memory_order __m) _NOEXCEPT
{
return __o->test_and_set(__m);
}
inline _LIBCPP_INLINE_VISIBILITY
void
atomic_flag_clear(volatile atomic_flag* __o) _NOEXCEPT
{
__o->clear();
}
inline _LIBCPP_INLINE_VISIBILITY
void
atomic_flag_clear(atomic_flag* __o) _NOEXCEPT
{
__o->clear();
}
inline _LIBCPP_INLINE_VISIBILITY
void
atomic_flag_clear_explicit(volatile atomic_flag* __o, memory_order __m) _NOEXCEPT
{
__o->clear(__m);
}
inline _LIBCPP_INLINE_VISIBILITY
void
atomic_flag_clear_explicit(atomic_flag* __o, memory_order __m) _NOEXCEPT
{
__o->clear(__m);
}
// fences
inline _LIBCPP_INLINE_VISIBILITY
void
atomic_thread_fence(memory_order __m) _NOEXCEPT
{
__cxx_atomic_thread_fence(__m);
}
inline _LIBCPP_INLINE_VISIBILITY
void
atomic_signal_fence(memory_order __m) _NOEXCEPT
{
__cxx_atomic_signal_fence(__m);
}
// Atomics for standard typedef types
typedef atomic<bool> atomic_bool;
typedef atomic<char> atomic_char;
typedef atomic<signed char> atomic_schar;
typedef atomic<unsigned char> atomic_uchar;
typedef atomic<short> atomic_short;
typedef atomic<unsigned short> atomic_ushort;
typedef atomic<int> atomic_int;
typedef atomic<unsigned int> atomic_uint;
typedef atomic<long> atomic_long;
typedef atomic<unsigned long> atomic_ulong;
typedef atomic<long long> atomic_llong;
typedef atomic<unsigned long long> atomic_ullong;
typedef atomic<char16_t> atomic_char16_t;
typedef atomic<char32_t> atomic_char32_t;
typedef atomic<wchar_t> atomic_wchar_t;
typedef atomic<int_least8_t> atomic_int_least8_t;
typedef atomic<uint_least8_t> atomic_uint_least8_t;
typedef atomic<int_least16_t> atomic_int_least16_t;
typedef atomic<uint_least16_t> atomic_uint_least16_t;
typedef atomic<int_least32_t> atomic_int_least32_t;
typedef atomic<uint_least32_t> atomic_uint_least32_t;
typedef atomic<int_least64_t> atomic_int_least64_t;
typedef atomic<uint_least64_t> atomic_uint_least64_t;
typedef atomic<int_fast8_t> atomic_int_fast8_t;
typedef atomic<uint_fast8_t> atomic_uint_fast8_t;
typedef atomic<int_fast16_t> atomic_int_fast16_t;
typedef atomic<uint_fast16_t> atomic_uint_fast16_t;
typedef atomic<int_fast32_t> atomic_int_fast32_t;
typedef atomic<uint_fast32_t> atomic_uint_fast32_t;
typedef atomic<int_fast64_t> atomic_int_fast64_t;
typedef atomic<uint_fast64_t> atomic_uint_fast64_t;
typedef atomic< int8_t> atomic_int8_t;
typedef atomic<uint8_t> atomic_uint8_t;
typedef atomic< int16_t> atomic_int16_t;
typedef atomic<uint16_t> atomic_uint16_t;
typedef atomic< int32_t> atomic_int32_t;
typedef atomic<uint32_t> atomic_uint32_t;
typedef atomic< int64_t> atomic_int64_t;
typedef atomic<uint64_t> atomic_uint64_t;
typedef atomic<intptr_t> atomic_intptr_t;
typedef atomic<uintptr_t> atomic_uintptr_t;
typedef atomic<size_t> atomic_size_t;
typedef atomic<ptrdiff_t> atomic_ptrdiff_t;
typedef atomic<intmax_t> atomic_intmax_t;
typedef atomic<uintmax_t> atomic_uintmax_t;
#define ATOMIC_FLAG_INIT {false}
#define ATOMIC_VAR_INIT(__v) {__v}
_LIBCPP_END_NAMESPACE_STD
#endif // _LIBCPP_ATOMIC
| 85,307 | 2,444 | jart/cosmopolitan | false |
cosmopolitan/third_party/libcxx/ciso646 | // -*- C++ -*-
// clang-format off
//===--------------------------- ciso646 ----------------------------------===//
//
// 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_CISO646
#define _LIBCPP_CISO646
/*
ciso646 synopsis
*/
#include "third_party/libcxx/__config"
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
#pragma GCC system_header
#endif
#endif // _LIBCPP_CISO646
| 634 | 26 | jart/cosmopolitan | false |
cosmopolitan/third_party/libcxx/valarray.cc | // clang-format off
//===------------------------ valarray.cpp --------------------------------===//
//
// 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
//
//===----------------------------------------------------------------------===//
#include "third_party/libcxx/valarray"
_LIBCPP_BEGIN_NAMESPACE_STD
// These two symbols are part of the v1 ABI but not part of the >=v2 ABI.
#if _LIBCPP_ABI_VERSION == 1
template _LIBCPP_FUNC_VIS valarray<size_t>::valarray(size_t);
template _LIBCPP_FUNC_VIS valarray<size_t>::~valarray();
#endif
template void valarray<size_t>::resize(size_t, size_t);
void
gslice::__init(size_t __start)
{
valarray<size_t> __indices(__size_.size());
size_t __k = __size_.size() != 0;
for (size_t __i = 0; __i < __size_.size(); ++__i)
__k *= __size_[__i];
__1d_.resize(__k);
if (__1d_.size())
{
__k = 0;
__1d_[__k] = __start;
while (true)
{
size_t __i = __indices.size() - 1;
while (true)
{
if (++__indices[__i] < __size_[__i])
{
++__k;
__1d_[__k] = __1d_[__k-1] + __stride_[__i];
for (size_t __j = __i + 1; __j != __indices.size(); ++__j)
__1d_[__k] -= __stride_[__j] * (__size_[__j] - 1);
break;
}
else
{
if (__i == 0)
return;
__indices[__i--] = 0;
}
}
}
}
}
_LIBCPP_END_NAMESPACE_STD
| 1,753 | 59 | jart/cosmopolitan | false |
cosmopolitan/third_party/libcxx/__functional_base | // -*- 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_BASE
#define _LIBCPP_FUNCTIONAL_BASE
#include "third_party/libcxx/__config"
#include "third_party/libcxx/type_traits"
#include "third_party/libcxx/typeinfo"
#include "third_party/libcxx/exception"
#include "third_party/libcxx/new"
#include "third_party/libcxx/utility"
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
#pragma GCC system_header
#endif
_LIBCPP_BEGIN_NAMESPACE_STD
template <class _Arg1, class _Arg2, class _Result>
struct _LIBCPP_TEMPLATE_VIS binary_function
{
typedef _Arg1 first_argument_type;
typedef _Arg2 second_argument_type;
typedef _Result result_type;
};
template <class _Tp>
struct __has_result_type
{
private:
struct __two {char __lx; char __lxx;};
template <class _Up> static __two __test(...);
template <class _Up> static char __test(typename _Up::result_type* = 0);
public:
static const bool value = sizeof(__test<_Tp>(0)) == 1;
};
#if _LIBCPP_STD_VER > 11
template <class _Tp = void>
#else
template <class _Tp>
#endif
struct _LIBCPP_TEMPLATE_VIS less : binary_function<_Tp, _Tp, bool>
{
_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
bool operator()(const _Tp& __x, const _Tp& __y) const
{return __x < __y;}
};
#if _LIBCPP_STD_VER > 11
template <>
struct _LIBCPP_TEMPLATE_VIS less<void>
{
template <class _T1, class _T2>
_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
auto operator()(_T1&& __t, _T2&& __u) const
_NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) < _VSTD::forward<_T2>(__u)))
-> decltype (_VSTD::forward<_T1>(__t) < _VSTD::forward<_T2>(__u))
{ return _VSTD::forward<_T1>(__t) < _VSTD::forward<_T2>(__u); }
typedef void is_transparent;
};
#endif
// __weak_result_type
template <class _Tp>
struct __derives_from_unary_function
{
private:
struct __two {char __lx; char __lxx;};
static __two __test(...);
template <class _Ap, class _Rp>
static unary_function<_Ap, _Rp>
__test(const volatile unary_function<_Ap, _Rp>*);
public:
static const bool value = !is_same<decltype(__test((_Tp*)0)), __two>::value;
typedef decltype(__test((_Tp*)0)) type;
};
template <class _Tp>
struct __derives_from_binary_function
{
private:
struct __two {char __lx; char __lxx;};
static __two __test(...);
template <class _A1, class _A2, class _Rp>
static binary_function<_A1, _A2, _Rp>
__test(const volatile binary_function<_A1, _A2, _Rp>*);
public:
static const bool value = !is_same<decltype(__test((_Tp*)0)), __two>::value;
typedef decltype(__test((_Tp*)0)) type;
};
template <class _Tp, bool = __derives_from_unary_function<_Tp>::value>
struct __maybe_derive_from_unary_function // bool is true
: public __derives_from_unary_function<_Tp>::type
{
};
template <class _Tp>
struct __maybe_derive_from_unary_function<_Tp, false>
{
};
template <class _Tp, bool = __derives_from_binary_function<_Tp>::value>
struct __maybe_derive_from_binary_function // bool is true
: public __derives_from_binary_function<_Tp>::type
{
};
template <class _Tp>
struct __maybe_derive_from_binary_function<_Tp, false>
{
};
template <class _Tp, bool = __has_result_type<_Tp>::value>
struct __weak_result_type_imp // bool is true
: public __maybe_derive_from_unary_function<_Tp>,
public __maybe_derive_from_binary_function<_Tp>
{
typedef _LIBCPP_NODEBUG_TYPE typename _Tp::result_type result_type;
};
template <class _Tp>
struct __weak_result_type_imp<_Tp, false>
: public __maybe_derive_from_unary_function<_Tp>,
public __maybe_derive_from_binary_function<_Tp>
{
};
template <class _Tp>
struct __weak_result_type
: public __weak_result_type_imp<_Tp>
{
};
// 0 argument case
template <class _Rp>
struct __weak_result_type<_Rp ()>
{
typedef _LIBCPP_NODEBUG_TYPE _Rp result_type;
};
template <class _Rp>
struct __weak_result_type<_Rp (&)()>
{
typedef _LIBCPP_NODEBUG_TYPE _Rp result_type;
};
template <class _Rp>
struct __weak_result_type<_Rp (*)()>
{
typedef _LIBCPP_NODEBUG_TYPE _Rp result_type;
};
// 1 argument case
template <class _Rp, class _A1>
struct __weak_result_type<_Rp (_A1)>
: public unary_function<_A1, _Rp>
{
};
template <class _Rp, class _A1>
struct __weak_result_type<_Rp (&)(_A1)>
: public unary_function<_A1, _Rp>
{
};
template <class _Rp, class _A1>
struct __weak_result_type<_Rp (*)(_A1)>
: public unary_function<_A1, _Rp>
{
};
template <class _Rp, class _Cp>
struct __weak_result_type<_Rp (_Cp::*)()>
: public unary_function<_Cp*, _Rp>
{
};
template <class _Rp, class _Cp>
struct __weak_result_type<_Rp (_Cp::*)() const>
: public unary_function<const _Cp*, _Rp>
{
};
template <class _Rp, class _Cp>
struct __weak_result_type<_Rp (_Cp::*)() volatile>
: public unary_function<volatile _Cp*, _Rp>
{
};
template <class _Rp, class _Cp>
struct __weak_result_type<_Rp (_Cp::*)() const volatile>
: public unary_function<const volatile _Cp*, _Rp>
{
};
// 2 argument case
template <class _Rp, class _A1, class _A2>
struct __weak_result_type<_Rp (_A1, _A2)>
: public binary_function<_A1, _A2, _Rp>
{
};
template <class _Rp, class _A1, class _A2>
struct __weak_result_type<_Rp (*)(_A1, _A2)>
: public binary_function<_A1, _A2, _Rp>
{
};
template <class _Rp, class _A1, class _A2>
struct __weak_result_type<_Rp (&)(_A1, _A2)>
: public binary_function<_A1, _A2, _Rp>
{
};
template <class _Rp, class _Cp, class _A1>
struct __weak_result_type<_Rp (_Cp::*)(_A1)>
: public binary_function<_Cp*, _A1, _Rp>
{
};
template <class _Rp, class _Cp, class _A1>
struct __weak_result_type<_Rp (_Cp::*)(_A1) const>
: public binary_function<const _Cp*, _A1, _Rp>
{
};
template <class _Rp, class _Cp, class _A1>
struct __weak_result_type<_Rp (_Cp::*)(_A1) volatile>
: public binary_function<volatile _Cp*, _A1, _Rp>
{
};
template <class _Rp, class _Cp, class _A1>
struct __weak_result_type<_Rp (_Cp::*)(_A1) const volatile>
: public binary_function<const volatile _Cp*, _A1, _Rp>
{
};
#ifndef _LIBCPP_CXX03_LANG
// 3 or more arguments
template <class _Rp, class _A1, class _A2, class _A3, class ..._A4>
struct __weak_result_type<_Rp (_A1, _A2, _A3, _A4...)>
{
typedef _Rp result_type;
};
template <class _Rp, class _A1, class _A2, class _A3, class ..._A4>
struct __weak_result_type<_Rp (&)(_A1, _A2, _A3, _A4...)>
{
typedef _Rp result_type;
};
template <class _Rp, class _A1, class _A2, class _A3, class ..._A4>
struct __weak_result_type<_Rp (*)(_A1, _A2, _A3, _A4...)>
{
typedef _Rp result_type;
};
template <class _Rp, class _Cp, class _A1, class _A2, class ..._A3>
struct __weak_result_type<_Rp (_Cp::*)(_A1, _A2, _A3...)>
{
typedef _Rp result_type;
};
template <class _Rp, class _Cp, class _A1, class _A2, class ..._A3>
struct __weak_result_type<_Rp (_Cp::*)(_A1, _A2, _A3...) const>
{
typedef _Rp result_type;
};
template <class _Rp, class _Cp, class _A1, class _A2, class ..._A3>
struct __weak_result_type<_Rp (_Cp::*)(_A1, _A2, _A3...) volatile>
{
typedef _Rp result_type;
};
template <class _Rp, class _Cp, class _A1, class _A2, class ..._A3>
struct __weak_result_type<_Rp (_Cp::*)(_A1, _A2, _A3...) const volatile>
{
typedef _Rp result_type;
};
template <class _Tp, class ..._Args>
struct __invoke_return
{
typedef decltype(__invoke(_VSTD::declval<_Tp>(), _VSTD::declval<_Args>()...)) type;
};
#else // defined(_LIBCPP_CXX03_LANG)
#include "third_party/libcxx/__functional_base_03"
#endif // !defined(_LIBCPP_CXX03_LANG)
template <class _Ret>
struct __invoke_void_return_wrapper
{
#ifndef _LIBCPP_CXX03_LANG
template <class ..._Args>
static _Ret __call(_Args&&... __args) {
return __invoke(_VSTD::forward<_Args>(__args)...);
}
#else
template <class _Fn>
static _Ret __call(_Fn __f) {
return __invoke(__f);
}
template <class _Fn, class _A0>
static _Ret __call(_Fn __f, _A0& __a0) {
return __invoke(__f, __a0);
}
template <class _Fn, class _A0, class _A1>
static _Ret __call(_Fn __f, _A0& __a0, _A1& __a1) {
return __invoke(__f, __a0, __a1);
}
template <class _Fn, class _A0, class _A1, class _A2>
static _Ret __call(_Fn __f, _A0& __a0, _A1& __a1, _A2& __a2){
return __invoke(__f, __a0, __a1, __a2);
}
#endif
};
template <>
struct __invoke_void_return_wrapper<void>
{
#ifndef _LIBCPP_CXX03_LANG
template <class ..._Args>
static void __call(_Args&&... __args) {
__invoke(_VSTD::forward<_Args>(__args)...);
}
#else
template <class _Fn>
static void __call(_Fn __f) {
__invoke(__f);
}
template <class _Fn, class _A0>
static void __call(_Fn __f, _A0& __a0) {
__invoke(__f, __a0);
}
template <class _Fn, class _A0, class _A1>
static void __call(_Fn __f, _A0& __a0, _A1& __a1) {
__invoke(__f, __a0, __a1);
}
template <class _Fn, class _A0, class _A1, class _A2>
static void __call(_Fn __f, _A0& __a0, _A1& __a1, _A2& __a2) {
__invoke(__f, __a0, __a1, __a2);
}
#endif
};
template <class _Tp>
class _LIBCPP_TEMPLATE_VIS reference_wrapper
: public __weak_result_type<_Tp>
{
public:
// types
typedef _Tp type;
private:
type* __f_;
public:
// construct/copy/destroy
_LIBCPP_INLINE_VISIBILITY reference_wrapper(type& __f) _NOEXCEPT
: __f_(_VSTD::addressof(__f)) {}
#ifndef _LIBCPP_CXX03_LANG
private: reference_wrapper(type&&); public: // = delete; // do not bind to temps
#endif
// access
_LIBCPP_INLINE_VISIBILITY operator type& () const _NOEXCEPT {return *__f_;}
_LIBCPP_INLINE_VISIBILITY type& get() const _NOEXCEPT {return *__f_;}
#ifndef _LIBCPP_CXX03_LANG
// invoke
template <class... _ArgTypes>
_LIBCPP_INLINE_VISIBILITY
typename __invoke_of<type&, _ArgTypes...>::type
operator() (_ArgTypes&&... __args) const {
return __invoke(get(), _VSTD::forward<_ArgTypes>(__args)...);
}
#else
_LIBCPP_INLINE_VISIBILITY
typename __invoke_return<type>::type
operator() () const {
return __invoke(get());
}
template <class _A0>
_LIBCPP_INLINE_VISIBILITY
typename __invoke_return0<type, _A0>::type
operator() (_A0& __a0) const {
return __invoke(get(), __a0);
}
template <class _A0>
_LIBCPP_INLINE_VISIBILITY
typename __invoke_return0<type, _A0 const>::type
operator() (_A0 const& __a0) const {
return __invoke(get(), __a0);
}
template <class _A0, class _A1>
_LIBCPP_INLINE_VISIBILITY
typename __invoke_return1<type, _A0, _A1>::type
operator() (_A0& __a0, _A1& __a1) const {
return __invoke(get(), __a0, __a1);
}
template <class _A0, class _A1>
_LIBCPP_INLINE_VISIBILITY
typename __invoke_return1<type, _A0 const, _A1>::type
operator() (_A0 const& __a0, _A1& __a1) const {
return __invoke(get(), __a0, __a1);
}
template <class _A0, class _A1>
_LIBCPP_INLINE_VISIBILITY
typename __invoke_return1<type, _A0, _A1 const>::type
operator() (_A0& __a0, _A1 const& __a1) const {
return __invoke(get(), __a0, __a1);
}
template <class _A0, class _A1>
_LIBCPP_INLINE_VISIBILITY
typename __invoke_return1<type, _A0 const, _A1 const>::type
operator() (_A0 const& __a0, _A1 const& __a1) const {
return __invoke(get(), __a0, __a1);
}
template <class _A0, class _A1, class _A2>
_LIBCPP_INLINE_VISIBILITY
typename __invoke_return2<type, _A0, _A1, _A2>::type
operator() (_A0& __a0, _A1& __a1, _A2& __a2) const {
return __invoke(get(), __a0, __a1, __a2);
}
template <class _A0, class _A1, class _A2>
_LIBCPP_INLINE_VISIBILITY
typename __invoke_return2<type, _A0 const, _A1, _A2>::type
operator() (_A0 const& __a0, _A1& __a1, _A2& __a2) const {
return __invoke(get(), __a0, __a1, __a2);
}
template <class _A0, class _A1, class _A2>
_LIBCPP_INLINE_VISIBILITY
typename __invoke_return2<type, _A0, _A1 const, _A2>::type
operator() (_A0& __a0, _A1 const& __a1, _A2& __a2) const {
return __invoke(get(), __a0, __a1, __a2);
}
template <class _A0, class _A1, class _A2>
_LIBCPP_INLINE_VISIBILITY
typename __invoke_return2<type, _A0, _A1, _A2 const>::type
operator() (_A0& __a0, _A1& __a1, _A2 const& __a2) const {
return __invoke(get(), __a0, __a1, __a2);
}
template <class _A0, class _A1, class _A2>
_LIBCPP_INLINE_VISIBILITY
typename __invoke_return2<type, _A0 const, _A1 const, _A2>::type
operator() (_A0 const& __a0, _A1 const& __a1, _A2& __a2) const {
return __invoke(get(), __a0, __a1, __a2);
}
template <class _A0, class _A1, class _A2>
_LIBCPP_INLINE_VISIBILITY
typename __invoke_return2<type, _A0 const, _A1, _A2 const>::type
operator() (_A0 const& __a0, _A1& __a1, _A2 const& __a2) const {
return __invoke(get(), __a0, __a1, __a2);
}
template <class _A0, class _A1, class _A2>
_LIBCPP_INLINE_VISIBILITY
typename __invoke_return2<type, _A0, _A1 const, _A2 const>::type
operator() (_A0& __a0, _A1 const& __a1, _A2 const& __a2) const {
return __invoke(get(), __a0, __a1, __a2);
}
template <class _A0, class _A1, class _A2>
_LIBCPP_INLINE_VISIBILITY
typename __invoke_return2<type, _A0 const, _A1 const, _A2 const>::type
operator() (_A0 const& __a0, _A1 const& __a1, _A2 const& __a2) const {
return __invoke(get(), __a0, __a1, __a2);
}
#endif // _LIBCPP_CXX03_LANG
};
template <class _Tp>
inline _LIBCPP_INLINE_VISIBILITY
reference_wrapper<_Tp>
ref(_Tp& __t) _NOEXCEPT
{
return reference_wrapper<_Tp>(__t);
}
template <class _Tp>
inline _LIBCPP_INLINE_VISIBILITY
reference_wrapper<_Tp>
ref(reference_wrapper<_Tp> __t) _NOEXCEPT
{
return ref(__t.get());
}
template <class _Tp>
inline _LIBCPP_INLINE_VISIBILITY
reference_wrapper<const _Tp>
cref(const _Tp& __t) _NOEXCEPT
{
return reference_wrapper<const _Tp>(__t);
}
template <class _Tp>
inline _LIBCPP_INLINE_VISIBILITY
reference_wrapper<const _Tp>
cref(reference_wrapper<_Tp> __t) _NOEXCEPT
{
return cref(__t.get());
}
#ifndef _LIBCPP_CXX03_LANG
template <class _Tp> void ref(const _Tp&&) = delete;
template <class _Tp> void cref(const _Tp&&) = delete;
#endif
#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
// allocator_arg_t
struct _LIBCPP_TEMPLATE_VIS allocator_arg_t { explicit allocator_arg_t() = default; };
#if defined(_LIBCPP_CXX03_LANG) || defined(_LIBCPP_BUILDING_LIBRARY)
extern _LIBCPP_EXPORTED_FROM_ABI const allocator_arg_t allocator_arg;
#else
/* _LIBCPP_INLINE_VAR */ constexpr allocator_arg_t allocator_arg = allocator_arg_t();
#endif
// uses_allocator
template <class _Tp>
struct __has_allocator_type
{
private:
struct __two {char __lx; char __lxx;};
template <class _Up> static __two __test(...);
template <class _Up> static char __test(typename _Up::allocator_type* = 0);
public:
static const bool value = sizeof(__test<_Tp>(0)) == 1;
};
template <class _Tp, class _Alloc, bool = __has_allocator_type<_Tp>::value>
struct __uses_allocator
: public integral_constant<bool,
is_convertible<_Alloc, typename _Tp::allocator_type>::value>
{
};
template <class _Tp, class _Alloc>
struct __uses_allocator<_Tp, _Alloc, false>
: public false_type
{
};
template <class _Tp, class _Alloc>
struct _LIBCPP_TEMPLATE_VIS uses_allocator
: public __uses_allocator<_Tp, _Alloc>
{
};
#if _LIBCPP_STD_VER > 14
template <class _Tp, class _Alloc>
_LIBCPP_INLINE_VAR constexpr size_t uses_allocator_v = uses_allocator<_Tp, _Alloc>::value;
#endif
#ifndef _LIBCPP_CXX03_LANG
// allocator construction
template <class _Tp, class _Alloc, class ..._Args>
struct __uses_alloc_ctor_imp
{
typedef _LIBCPP_NODEBUG_TYPE typename __uncvref<_Alloc>::type _RawAlloc;
static const bool __ua = uses_allocator<_Tp, _RawAlloc>::value;
static const bool __ic =
is_constructible<_Tp, allocator_arg_t, _Alloc, _Args...>::value;
static const int value = __ua ? 2 - __ic : 0;
};
template <class _Tp, class _Alloc, class ..._Args>
struct __uses_alloc_ctor
: integral_constant<int, __uses_alloc_ctor_imp<_Tp, _Alloc, _Args...>::value>
{};
template <class _Tp, class _Allocator, class... _Args>
inline _LIBCPP_INLINE_VISIBILITY
void __user_alloc_construct_impl (integral_constant<int, 0>, _Tp *__storage, const _Allocator &, _Args &&... __args )
{
new (__storage) _Tp (_VSTD::forward<_Args>(__args)...);
}
// FIXME: This should have a version which takes a non-const alloc.
template <class _Tp, class _Allocator, class... _Args>
inline _LIBCPP_INLINE_VISIBILITY
void __user_alloc_construct_impl (integral_constant<int, 1>, _Tp *__storage, const _Allocator &__a, _Args &&... __args )
{
new (__storage) _Tp (allocator_arg, __a, _VSTD::forward<_Args>(__args)...);
}
// FIXME: This should have a version which takes a non-const alloc.
template <class _Tp, class _Allocator, class... _Args>
inline _LIBCPP_INLINE_VISIBILITY
void __user_alloc_construct_impl (integral_constant<int, 2>, _Tp *__storage, const _Allocator &__a, _Args &&... __args )
{
new (__storage) _Tp (_VSTD::forward<_Args>(__args)..., __a);
}
#endif // _LIBCPP_CXX03_LANG
_LIBCPP_END_NAMESPACE_STD
#endif // _LIBCPP_FUNCTIONAL_BASE
| 17,940 | 653 | jart/cosmopolitan | false |
cosmopolitan/third_party/libcxx/queue | // -*- C++ -*-
//===--------------------------- queue ------------------------------------===//
//
// 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_QUEUE
#define _LIBCPP_QUEUE
#include "third_party/libcxx/__config"
#include "third_party/libcxx/deque"
#include "third_party/libcxx/vector"
#include "third_party/libcxx/functional"
#include "third_party/libcxx/algorithm"
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
#pragma GCC system_header
#endif
_LIBCPP_BEGIN_NAMESPACE_STD
/*
queue synopsis
namespace std
{
template <class T, class Container = deque<T>>
class queue
{
public:
typedef Container container_type;
typedef typename container_type::value_type value_type;
typedef typename container_type::reference reference;
typedef typename container_type::const_reference const_reference;
typedef typename container_type::size_type size_type;
protected:
container_type c;
public:
queue() = default;
~queue() = default;
queue(const queue& q) = default;
queue(queue&& q) = default;
queue& operator=(const queue& q) = default;
queue& operator=(queue&& q) = default;
explicit queue(const container_type& c);
explicit queue(container_type&& c)
template <class Alloc>
explicit queue(const Alloc& a);
template <class Alloc>
queue(const container_type& c, const Alloc& a);
template <class Alloc>
queue(container_type&& c, const Alloc& a);
template <class Alloc>
queue(const queue& q, const Alloc& a);
template <class Alloc>
queue(queue&& q, const Alloc& a);
bool empty() const;
size_type size() const;
reference front();
const_reference front() const;
reference back();
const_reference back() const;
void push(const value_type& v);
void push(value_type&& v);
template <class... Args> reference emplace(Args&&... args); // reference in C++17
void pop();
void swap(queue& q) noexcept(is_nothrow_swappable_v<Container>)
};
template<class Container>
queue(Container) -> queue<typename Container::value_type, Container>; // C++17
template<class Container, class Allocator>
queue(Container, Allocator) -> queue<typename Container::value_type, Container>; // C++17
template <class T, class Container>
bool operator==(const queue<T, Container>& x,const queue<T, Container>& y);
template <class T, class Container>
bool operator< (const queue<T, Container>& x,const queue<T, Container>& y);
template <class T, class Container>
bool operator!=(const queue<T, Container>& x,const queue<T, Container>& y);
template <class T, class Container>
bool operator> (const queue<T, Container>& x,const queue<T, Container>& y);
template <class T, class Container>
bool operator>=(const queue<T, Container>& x,const queue<T, Container>& y);
template <class T, class Container>
bool operator<=(const queue<T, Container>& x,const queue<T, Container>& y);
template <class T, class Container>
void swap(queue<T, Container>& x, queue<T, Container>& y)
noexcept(noexcept(x.swap(y)));
template <class T, class Container = vector<T>,
class Compare = less<typename Container::value_type>>
class priority_queue
{
public:
typedef Container container_type;
typedef typename container_type::value_type value_type;
typedef typename container_type::reference reference;
typedef typename container_type::const_reference const_reference;
typedef typename container_type::size_type size_type;
protected:
container_type c;
Compare comp;
public:
priority_queue() = default;
~priority_queue() = default;
priority_queue(const priority_queue& q) = default;
priority_queue(priority_queue&& q) = default;
priority_queue& operator=(const priority_queue& q) = default;
priority_queue& operator=(priority_queue&& q) = default;
explicit priority_queue(const Compare& comp);
priority_queue(const Compare& comp, const container_type& c);
explicit priority_queue(const Compare& comp, container_type&& c);
template <class InputIterator>
priority_queue(InputIterator first, InputIterator last,
const Compare& comp = Compare());
template <class InputIterator>
priority_queue(InputIterator first, InputIterator last,
const Compare& comp, const container_type& c);
template <class InputIterator>
priority_queue(InputIterator first, InputIterator last,
const Compare& comp, container_type&& c);
template <class Alloc>
explicit priority_queue(const Alloc& a);
template <class Alloc>
priority_queue(const Compare& comp, const Alloc& a);
template <class Alloc>
priority_queue(const Compare& comp, const container_type& c,
const Alloc& a);
template <class Alloc>
priority_queue(const Compare& comp, container_type&& c,
const Alloc& a);
template <class Alloc>
priority_queue(const priority_queue& q, const Alloc& a);
template <class Alloc>
priority_queue(priority_queue&& q, const Alloc& a);
bool empty() const;
size_type size() const;
const_reference top() const;
void push(const value_type& v);
void push(value_type&& v);
template <class... Args> void emplace(Args&&... args);
void pop();
void swap(priority_queue& q)
noexcept(is_nothrow_swappable_v<Container> &&
is_nothrow_swappable_v<Comp>)
};
template <class Compare, class Container>
priority_queue(Compare, Container)
-> priority_queue<typename Container::value_type, Container, Compare>; // C++17
template<class InputIterator,
class Compare = less<typename iterator_traits<InputIterator>::value_type>,
class Container = vector<typename iterator_traits<InputIterator>::value_type>>
priority_queue(InputIterator, InputIterator, Compare = Compare(), Container = Container())
-> priority_queue<typename iterator_traits<InputIterator>::value_type, Container, Compare>; // C++17
template<class Compare, class Container, class Allocator>
priority_queue(Compare, Container, Allocator)
-> priority_queue<typename Container::value_type, Container, Compare>; // C++17
template <class T, class Container, class Compare>
void swap(priority_queue<T, Container, Compare>& x,
priority_queue<T, Container, Compare>& y)
noexcept(noexcept(x.swap(y)));
} // std
*/
template <class _Tp, class _Container = deque<_Tp> > class _LIBCPP_TEMPLATE_VIS queue;
template <class _Tp, class _Container>
_LIBCPP_INLINE_VISIBILITY
bool
operator==(const queue<_Tp, _Container>& __x,const queue<_Tp, _Container>& __y);
template <class _Tp, class _Container>
_LIBCPP_INLINE_VISIBILITY
bool
operator< (const queue<_Tp, _Container>& __x,const queue<_Tp, _Container>& __y);
template <class _Tp, class _Container /*= deque<_Tp>*/>
class _LIBCPP_TEMPLATE_VIS queue
{
public:
typedef _Container container_type;
typedef typename container_type::value_type value_type;
typedef typename container_type::reference reference;
typedef typename container_type::const_reference const_reference;
typedef typename container_type::size_type size_type;
static_assert((is_same<_Tp, value_type>::value), "" );
protected:
container_type c;
public:
_LIBCPP_INLINE_VISIBILITY
queue()
_NOEXCEPT_(is_nothrow_default_constructible<container_type>::value)
: c() {}
_LIBCPP_INLINE_VISIBILITY
queue(const queue& __q) : c(__q.c) {}
_LIBCPP_INLINE_VISIBILITY
queue& operator=(const queue& __q) {c = __q.c; return *this;}
#ifndef _LIBCPP_CXX03_LANG
_LIBCPP_INLINE_VISIBILITY
queue(queue&& __q)
_NOEXCEPT_(is_nothrow_move_constructible<container_type>::value)
: c(_VSTD::move(__q.c)) {}
_LIBCPP_INLINE_VISIBILITY
queue& operator=(queue&& __q)
_NOEXCEPT_(is_nothrow_move_assignable<container_type>::value)
{c = _VSTD::move(__q.c); return *this;}
#endif // _LIBCPP_CXX03_LANG
_LIBCPP_INLINE_VISIBILITY
explicit queue(const container_type& __c) : c(__c) {}
#ifndef _LIBCPP_CXX03_LANG
_LIBCPP_INLINE_VISIBILITY
explicit queue(container_type&& __c) : c(_VSTD::move(__c)) {}
#endif // _LIBCPP_CXX03_LANG
template <class _Alloc>
_LIBCPP_INLINE_VISIBILITY
explicit queue(const _Alloc& __a,
typename enable_if<uses_allocator<container_type,
_Alloc>::value>::type* = 0)
: c(__a) {}
template <class _Alloc>
_LIBCPP_INLINE_VISIBILITY
queue(const queue& __q, const _Alloc& __a,
typename enable_if<uses_allocator<container_type,
_Alloc>::value>::type* = 0)
: c(__q.c, __a) {}
template <class _Alloc>
_LIBCPP_INLINE_VISIBILITY
queue(const container_type& __c, const _Alloc& __a,
typename enable_if<uses_allocator<container_type,
_Alloc>::value>::type* = 0)
: c(__c, __a) {}
#ifndef _LIBCPP_CXX03_LANG
template <class _Alloc>
_LIBCPP_INLINE_VISIBILITY
queue(container_type&& __c, const _Alloc& __a,
typename enable_if<uses_allocator<container_type,
_Alloc>::value>::type* = 0)
: c(_VSTD::move(__c), __a) {}
template <class _Alloc>
_LIBCPP_INLINE_VISIBILITY
queue(queue&& __q, const _Alloc& __a,
typename enable_if<uses_allocator<container_type,
_Alloc>::value>::type* = 0)
: c(_VSTD::move(__q.c), __a) {}
#endif // _LIBCPP_CXX03_LANG
_LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
bool empty() const {return c.empty();}
_LIBCPP_INLINE_VISIBILITY
size_type size() const {return c.size();}
_LIBCPP_INLINE_VISIBILITY
reference front() {return c.front();}
_LIBCPP_INLINE_VISIBILITY
const_reference front() const {return c.front();}
_LIBCPP_INLINE_VISIBILITY
reference back() {return c.back();}
_LIBCPP_INLINE_VISIBILITY
const_reference back() const {return c.back();}
_LIBCPP_INLINE_VISIBILITY
void push(const value_type& __v) {c.push_back(__v);}
#ifndef _LIBCPP_CXX03_LANG
_LIBCPP_INLINE_VISIBILITY
void push(value_type&& __v) {c.push_back(_VSTD::move(__v));}
template <class... _Args>
_LIBCPP_INLINE_VISIBILITY
#if _LIBCPP_STD_VER > 14
decltype(auto) emplace(_Args&&... __args)
{ return c.emplace_back(_VSTD::forward<_Args>(__args)...);}
#else
void emplace(_Args&&... __args)
{ c.emplace_back(_VSTD::forward<_Args>(__args)...);}
#endif
#endif // _LIBCPP_CXX03_LANG
_LIBCPP_INLINE_VISIBILITY
void pop() {c.pop_front();}
_LIBCPP_INLINE_VISIBILITY
void swap(queue& __q)
_NOEXCEPT_(__is_nothrow_swappable<container_type>::value)
{
using _VSTD::swap;
swap(c, __q.c);
}
template <class _T1, class _C1>
friend
_LIBCPP_INLINE_VISIBILITY
bool
operator==(const queue<_T1, _C1>& __x,const queue<_T1, _C1>& __y);
template <class _T1, class _C1>
friend
_LIBCPP_INLINE_VISIBILITY
bool
operator< (const queue<_T1, _C1>& __x,const queue<_T1, _C1>& __y);
};
#ifndef _LIBCPP_HAS_NO_DEDUCTION_GUIDES
template<class _Container,
class = typename enable_if<!__is_allocator<_Container>::value, nullptr_t>::type
>
queue(_Container)
-> queue<typename _Container::value_type, _Container>;
template<class _Container,
class _Alloc,
class = typename enable_if<!__is_allocator<_Container>::value, nullptr_t>::type,
class = typename enable_if< __is_allocator<_Alloc>::value, nullptr_t>::type
>
queue(_Container, _Alloc)
-> queue<typename _Container::value_type, _Container>;
#endif
template <class _Tp, class _Container>
inline _LIBCPP_INLINE_VISIBILITY
bool
operator==(const queue<_Tp, _Container>& __x,const queue<_Tp, _Container>& __y)
{
return __x.c == __y.c;
}
template <class _Tp, class _Container>
inline _LIBCPP_INLINE_VISIBILITY
bool
operator< (const queue<_Tp, _Container>& __x,const queue<_Tp, _Container>& __y)
{
return __x.c < __y.c;
}
template <class _Tp, class _Container>
inline _LIBCPP_INLINE_VISIBILITY
bool
operator!=(const queue<_Tp, _Container>& __x,const queue<_Tp, _Container>& __y)
{
return !(__x == __y);
}
template <class _Tp, class _Container>
inline _LIBCPP_INLINE_VISIBILITY
bool
operator> (const queue<_Tp, _Container>& __x,const queue<_Tp, _Container>& __y)
{
return __y < __x;
}
template <class _Tp, class _Container>
inline _LIBCPP_INLINE_VISIBILITY
bool
operator>=(const queue<_Tp, _Container>& __x,const queue<_Tp, _Container>& __y)
{
return !(__x < __y);
}
template <class _Tp, class _Container>
inline _LIBCPP_INLINE_VISIBILITY
bool
operator<=(const queue<_Tp, _Container>& __x,const queue<_Tp, _Container>& __y)
{
return !(__y < __x);
}
template <class _Tp, class _Container>
inline _LIBCPP_INLINE_VISIBILITY
typename enable_if<
__is_swappable<_Container>::value,
void
>::type
swap(queue<_Tp, _Container>& __x, queue<_Tp, _Container>& __y)
_NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
{
__x.swap(__y);
}
template <class _Tp, class _Container, class _Alloc>
struct _LIBCPP_TEMPLATE_VIS uses_allocator<queue<_Tp, _Container>, _Alloc>
: public uses_allocator<_Container, _Alloc>
{
};
template <class _Tp, class _Container = vector<_Tp>,
class _Compare = less<typename _Container::value_type> >
class _LIBCPP_TEMPLATE_VIS priority_queue
{
public:
typedef _Container container_type;
typedef _Compare value_compare;
typedef typename container_type::value_type value_type;
typedef typename container_type::reference reference;
typedef typename container_type::const_reference const_reference;
typedef typename container_type::size_type size_type;
static_assert((is_same<_Tp, value_type>::value), "" );
protected:
container_type c;
value_compare comp;
public:
_LIBCPP_INLINE_VISIBILITY
priority_queue()
_NOEXCEPT_(is_nothrow_default_constructible<container_type>::value &&
is_nothrow_default_constructible<value_compare>::value)
: c(), comp() {}
_LIBCPP_INLINE_VISIBILITY
priority_queue(const priority_queue& __q) : c(__q.c), comp(__q.comp) {}
_LIBCPP_INLINE_VISIBILITY
priority_queue& operator=(const priority_queue& __q)
{c = __q.c; comp = __q.comp; return *this;}
#ifndef _LIBCPP_CXX03_LANG
_LIBCPP_INLINE_VISIBILITY
priority_queue(priority_queue&& __q)
_NOEXCEPT_(is_nothrow_move_constructible<container_type>::value &&
is_nothrow_move_constructible<value_compare>::value)
: c(_VSTD::move(__q.c)), comp(_VSTD::move(__q.comp)) {}
_LIBCPP_INLINE_VISIBILITY
priority_queue& operator=(priority_queue&& __q)
_NOEXCEPT_(is_nothrow_move_assignable<container_type>::value &&
is_nothrow_move_assignable<value_compare>::value)
{c = _VSTD::move(__q.c); comp = _VSTD::move(__q.comp); return *this;}
#endif // _LIBCPP_CXX03_LANG
_LIBCPP_INLINE_VISIBILITY
explicit priority_queue(const value_compare& __comp)
: c(), comp(__comp) {}
_LIBCPP_INLINE_VISIBILITY
priority_queue(const value_compare& __comp, const container_type& __c);
#ifndef _LIBCPP_CXX03_LANG
_LIBCPP_INLINE_VISIBILITY
explicit priority_queue(const value_compare& __comp, container_type&& __c);
#endif
template <class _InputIter>
_LIBCPP_INLINE_VISIBILITY
priority_queue(_InputIter __f, _InputIter __l,
const value_compare& __comp = value_compare());
template <class _InputIter>
_LIBCPP_INLINE_VISIBILITY
priority_queue(_InputIter __f, _InputIter __l,
const value_compare& __comp, const container_type& __c);
#ifndef _LIBCPP_CXX03_LANG
template <class _InputIter>
_LIBCPP_INLINE_VISIBILITY
priority_queue(_InputIter __f, _InputIter __l,
const value_compare& __comp, container_type&& __c);
#endif // _LIBCPP_CXX03_LANG
template <class _Alloc>
_LIBCPP_INLINE_VISIBILITY
explicit priority_queue(const _Alloc& __a,
typename enable_if<uses_allocator<container_type,
_Alloc>::value>::type* = 0);
template <class _Alloc>
_LIBCPP_INLINE_VISIBILITY
priority_queue(const value_compare& __comp, const _Alloc& __a,
typename enable_if<uses_allocator<container_type,
_Alloc>::value>::type* = 0);
template <class _Alloc>
_LIBCPP_INLINE_VISIBILITY
priority_queue(const value_compare& __comp, const container_type& __c,
const _Alloc& __a,
typename enable_if<uses_allocator<container_type,
_Alloc>::value>::type* = 0);
template <class _Alloc>
_LIBCPP_INLINE_VISIBILITY
priority_queue(const priority_queue& __q, const _Alloc& __a,
typename enable_if<uses_allocator<container_type,
_Alloc>::value>::type* = 0);
#ifndef _LIBCPP_CXX03_LANG
template <class _Alloc>
_LIBCPP_INLINE_VISIBILITY
priority_queue(const value_compare& __comp, container_type&& __c,
const _Alloc& __a,
typename enable_if<uses_allocator<container_type,
_Alloc>::value>::type* = 0);
template <class _Alloc>
_LIBCPP_INLINE_VISIBILITY
priority_queue(priority_queue&& __q, const _Alloc& __a,
typename enable_if<uses_allocator<container_type,
_Alloc>::value>::type* = 0);
#endif // _LIBCPP_CXX03_LANG
_LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
bool empty() const {return c.empty();}
_LIBCPP_INLINE_VISIBILITY
size_type size() const {return c.size();}
_LIBCPP_INLINE_VISIBILITY
const_reference top() const {return c.front();}
_LIBCPP_INLINE_VISIBILITY
void push(const value_type& __v);
#ifndef _LIBCPP_CXX03_LANG
_LIBCPP_INLINE_VISIBILITY
void push(value_type&& __v);
template <class... _Args>
_LIBCPP_INLINE_VISIBILITY
void emplace(_Args&&... __args);
#endif // _LIBCPP_CXX03_LANG
_LIBCPP_INLINE_VISIBILITY
void pop();
_LIBCPP_INLINE_VISIBILITY
void swap(priority_queue& __q)
_NOEXCEPT_(__is_nothrow_swappable<container_type>::value &&
__is_nothrow_swappable<value_compare>::value);
};
#ifndef _LIBCPP_HAS_NO_DEDUCTION_GUIDES
template <class _Compare,
class _Container,
class = typename enable_if<!__is_allocator<_Compare>::value, nullptr_t>::type,
class = typename enable_if<!__is_allocator<_Container>::value, nullptr_t>::type
>
priority_queue(_Compare, _Container)
-> priority_queue<typename _Container::value_type, _Container, _Compare>;
template<class _InputIterator,
class _Compare = less<typename iterator_traits<_InputIterator>::value_type>,
class _Container = vector<typename iterator_traits<_InputIterator>::value_type>,
class = typename enable_if< __is_input_iterator<_InputIterator>::value, nullptr_t>::type,
class = typename enable_if<!__is_allocator<_Compare>::value, nullptr_t>::type,
class = typename enable_if<!__is_allocator<_Container>::value, nullptr_t>::type
>
priority_queue(_InputIterator, _InputIterator, _Compare = _Compare(), _Container = _Container())
-> priority_queue<typename iterator_traits<_InputIterator>::value_type, _Container, _Compare>;
template<class _Compare,
class _Container,
class _Alloc,
class = typename enable_if<!__is_allocator<_Compare>::value, nullptr_t>::type,
class = typename enable_if<!__is_allocator<_Container>::value, nullptr_t>::type,
class = typename enable_if< __is_allocator<_Alloc>::value, nullptr_t>::type
>
priority_queue(_Compare, _Container, _Alloc)
-> priority_queue<typename _Container::value_type, _Container, _Compare>;
#endif
template <class _Tp, class _Container, class _Compare>
inline
priority_queue<_Tp, _Container, _Compare>::priority_queue(const _Compare& __comp,
const container_type& __c)
: c(__c),
comp(__comp)
{
_VSTD::make_heap(c.begin(), c.end(), comp);
}
#ifndef _LIBCPP_CXX03_LANG
template <class _Tp, class _Container, class _Compare>
inline
priority_queue<_Tp, _Container, _Compare>::priority_queue(const value_compare& __comp,
container_type&& __c)
: c(_VSTD::move(__c)),
comp(__comp)
{
_VSTD::make_heap(c.begin(), c.end(), comp);
}
#endif // _LIBCPP_CXX03_LANG
template <class _Tp, class _Container, class _Compare>
template <class _InputIter>
inline
priority_queue<_Tp, _Container, _Compare>::priority_queue(_InputIter __f, _InputIter __l,
const value_compare& __comp)
: c(__f, __l),
comp(__comp)
{
_VSTD::make_heap(c.begin(), c.end(), comp);
}
template <class _Tp, class _Container, class _Compare>
template <class _InputIter>
inline
priority_queue<_Tp, _Container, _Compare>::priority_queue(_InputIter __f, _InputIter __l,
const value_compare& __comp,
const container_type& __c)
: c(__c),
comp(__comp)
{
c.insert(c.end(), __f, __l);
_VSTD::make_heap(c.begin(), c.end(), comp);
}
#ifndef _LIBCPP_CXX03_LANG
template <class _Tp, class _Container, class _Compare>
template <class _InputIter>
inline
priority_queue<_Tp, _Container, _Compare>::priority_queue(_InputIter __f, _InputIter __l,
const value_compare& __comp,
container_type&& __c)
: c(_VSTD::move(__c)),
comp(__comp)
{
c.insert(c.end(), __f, __l);
_VSTD::make_heap(c.begin(), c.end(), comp);
}
#endif // _LIBCPP_CXX03_LANG
template <class _Tp, class _Container, class _Compare>
template <class _Alloc>
inline
priority_queue<_Tp, _Container, _Compare>::priority_queue(const _Alloc& __a,
typename enable_if<uses_allocator<container_type,
_Alloc>::value>::type*)
: c(__a)
{
}
template <class _Tp, class _Container, class _Compare>
template <class _Alloc>
inline
priority_queue<_Tp, _Container, _Compare>::priority_queue(const value_compare& __comp,
const _Alloc& __a,
typename enable_if<uses_allocator<container_type,
_Alloc>::value>::type*)
: c(__a),
comp(__comp)
{
}
template <class _Tp, class _Container, class _Compare>
template <class _Alloc>
inline
priority_queue<_Tp, _Container, _Compare>::priority_queue(const value_compare& __comp,
const container_type& __c,
const _Alloc& __a,
typename enable_if<uses_allocator<container_type,
_Alloc>::value>::type*)
: c(__c, __a),
comp(__comp)
{
_VSTD::make_heap(c.begin(), c.end(), comp);
}
template <class _Tp, class _Container, class _Compare>
template <class _Alloc>
inline
priority_queue<_Tp, _Container, _Compare>::priority_queue(const priority_queue& __q,
const _Alloc& __a,
typename enable_if<uses_allocator<container_type,
_Alloc>::value>::type*)
: c(__q.c, __a),
comp(__q.comp)
{
_VSTD::make_heap(c.begin(), c.end(), comp);
}
#ifndef _LIBCPP_CXX03_LANG
template <class _Tp, class _Container, class _Compare>
template <class _Alloc>
inline
priority_queue<_Tp, _Container, _Compare>::priority_queue(const value_compare& __comp,
container_type&& __c,
const _Alloc& __a,
typename enable_if<uses_allocator<container_type,
_Alloc>::value>::type*)
: c(_VSTD::move(__c), __a),
comp(__comp)
{
_VSTD::make_heap(c.begin(), c.end(), comp);
}
template <class _Tp, class _Container, class _Compare>
template <class _Alloc>
inline
priority_queue<_Tp, _Container, _Compare>::priority_queue(priority_queue&& __q,
const _Alloc& __a,
typename enable_if<uses_allocator<container_type,
_Alloc>::value>::type*)
: c(_VSTD::move(__q.c), __a),
comp(_VSTD::move(__q.comp))
{
_VSTD::make_heap(c.begin(), c.end(), comp);
}
#endif // _LIBCPP_CXX03_LANG
template <class _Tp, class _Container, class _Compare>
inline
void
priority_queue<_Tp, _Container, _Compare>::push(const value_type& __v)
{
c.push_back(__v);
_VSTD::push_heap(c.begin(), c.end(), comp);
}
#ifndef _LIBCPP_CXX03_LANG
template <class _Tp, class _Container, class _Compare>
inline
void
priority_queue<_Tp, _Container, _Compare>::push(value_type&& __v)
{
c.push_back(_VSTD::move(__v));
_VSTD::push_heap(c.begin(), c.end(), comp);
}
template <class _Tp, class _Container, class _Compare>
template <class... _Args>
inline
void
priority_queue<_Tp, _Container, _Compare>::emplace(_Args&&... __args)
{
c.emplace_back(_VSTD::forward<_Args>(__args)...);
_VSTD::push_heap(c.begin(), c.end(), comp);
}
#endif // _LIBCPP_CXX03_LANG
template <class _Tp, class _Container, class _Compare>
inline
void
priority_queue<_Tp, _Container, _Compare>::pop()
{
_VSTD::pop_heap(c.begin(), c.end(), comp);
c.pop_back();
}
template <class _Tp, class _Container, class _Compare>
inline
void
priority_queue<_Tp, _Container, _Compare>::swap(priority_queue& __q)
_NOEXCEPT_(__is_nothrow_swappable<container_type>::value &&
__is_nothrow_swappable<value_compare>::value)
{
using _VSTD::swap;
swap(c, __q.c);
swap(comp, __q.comp);
}
template <class _Tp, class _Container, class _Compare>
inline _LIBCPP_INLINE_VISIBILITY
typename enable_if<
__is_swappable<_Container>::value
&& __is_swappable<_Compare>::value,
void
>::type
swap(priority_queue<_Tp, _Container, _Compare>& __x,
priority_queue<_Tp, _Container, _Compare>& __y)
_NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
{
__x.swap(__y);
}
template <class _Tp, class _Container, class _Compare, class _Alloc>
struct _LIBCPP_TEMPLATE_VIS uses_allocator<priority_queue<_Tp, _Container, _Compare>, _Alloc>
: public uses_allocator<_Container, _Alloc>
{
};
_LIBCPP_END_NAMESPACE_STD
#endif // _LIBCPP_QUEUE
| 28,215 | 804 | jart/cosmopolitan | false |
cosmopolitan/third_party/libcxx/condition_variable_destructor.cc | // clang-format off
//===---------------- condition_variable_destructor.cpp ------------------===//
//
// 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
//
//===----------------------------------------------------------------------===//
// Define ~condition_variable.
//
// On some platforms ~condition_variable has been made trivial and the
// definition is only provided for ABI compatibility.
#include "third_party/libcxx/__config"
#include "third_party/libcxx/__threading_support"
#if !defined(_LIBCPP_HAS_NO_THREADS)
# if _LIBCPP_ABI_VERSION == 1 || !defined(_LIBCPP_HAS_TRIVIAL_CONDVAR_DESTRUCTION)
# define NEEDS_CONDVAR_DESTRUCTOR
# endif
#endif
_LIBCPP_BEGIN_NAMESPACE_STD
#ifdef NEEDS_CONDVAR_DESTRUCTOR
class _LIBCPP_TYPE_VIS condition_variable
{
__libcpp_condvar_t __cv_ = _LIBCPP_CONDVAR_INITIALIZER;
public:
_LIBCPP_INLINE_VISIBILITY
constexpr condition_variable() noexcept = default;
~condition_variable();
condition_variable(const condition_variable&) = delete;
condition_variable& operator=(const condition_variable&) = delete;
};
condition_variable::~condition_variable()
{
__libcpp_condvar_destroy(&__cv_);
}
#endif
_LIBCPP_END_NAMESPACE_STD
| 1,353 | 48 | jart/cosmopolitan | false |
cosmopolitan/third_party/libcxx/list | // -*- C++ -*-
//===---------------------------- list ------------------------------------===//
//
// 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_LIST
#define _LIBCPP_LIST
#include "third_party/libcxx/__config"
#include "third_party/libcxx/memory"
#include "third_party/libcxx/limits"
#include "third_party/libcxx/initializer_list"
#include "third_party/libcxx/iterator"
#include "third_party/libcxx/algorithm"
#include "third_party/libcxx/type_traits"
#include "third_party/libcxx/version"
#include "third_party/libcxx/__debug"
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
#pragma GCC system_header
#endif
_LIBCPP_PUSH_MACROS
#include "third_party/libcxx/__undef_macros"
_LIBCPP_BEGIN_NAMESPACE_STD
/*
list synopsis
namespace std
{
template <class T, class Alloc = allocator<T> >
class list
{
public:
// types:
typedef T value_type;
typedef Alloc allocator_type;
typedef typename allocator_type::reference reference;
typedef typename allocator_type::const_reference const_reference;
typedef typename allocator_type::pointer pointer;
typedef typename allocator_type::const_pointer const_pointer;
typedef implementation-defined iterator;
typedef implementation-defined const_iterator;
typedef implementation-defined size_type;
typedef implementation-defined difference_type;
typedef reverse_iterator<iterator> reverse_iterator;
typedef reverse_iterator<const_iterator> const_reverse_iterator;
list()
noexcept(is_nothrow_default_constructible<allocator_type>::value);
explicit list(const allocator_type& a);
explicit list(size_type n);
explicit list(size_type n, const allocator_type& a); // C++14
list(size_type n, const value_type& value);
list(size_type n, const value_type& value, const allocator_type& a);
template <class Iter>
list(Iter first, Iter last);
template <class Iter>
list(Iter first, Iter last, const allocator_type& a);
list(const list& x);
list(const list&, const allocator_type& a);
list(list&& x)
noexcept(is_nothrow_move_constructible<allocator_type>::value);
list(list&&, const allocator_type& a);
list(initializer_list<value_type>);
list(initializer_list<value_type>, const allocator_type& a);
~list();
list& operator=(const list& x);
list& operator=(list&& x)
noexcept(
allocator_type::propagate_on_container_move_assignment::value &&
is_nothrow_move_assignable<allocator_type>::value);
list& operator=(initializer_list<value_type>);
template <class Iter>
void assign(Iter first, Iter last);
void assign(size_type n, const value_type& t);
void assign(initializer_list<value_type>);
allocator_type get_allocator() const noexcept;
iterator begin() noexcept;
const_iterator begin() const noexcept;
iterator end() noexcept;
const_iterator end() const noexcept;
reverse_iterator rbegin() noexcept;
const_reverse_iterator rbegin() const noexcept;
reverse_iterator rend() noexcept;
const_reverse_iterator rend() const noexcept;
const_iterator cbegin() const noexcept;
const_iterator cend() const noexcept;
const_reverse_iterator crbegin() const noexcept;
const_reverse_iterator crend() const noexcept;
reference front();
const_reference front() const;
reference back();
const_reference back() const;
bool empty() const noexcept;
size_type size() const noexcept;
size_type max_size() const noexcept;
template <class... Args>
reference emplace_front(Args&&... args); // reference in C++17
void pop_front();
template <class... Args>
reference emplace_back(Args&&... args); // reference in C++17
void pop_back();
void push_front(const value_type& x);
void push_front(value_type&& x);
void push_back(const value_type& x);
void push_back(value_type&& x);
template <class... Args>
iterator emplace(const_iterator position, Args&&... args);
iterator insert(const_iterator position, const value_type& x);
iterator insert(const_iterator position, value_type&& x);
iterator insert(const_iterator position, size_type n, const value_type& x);
template <class Iter>
iterator insert(const_iterator position, Iter first, Iter last);
iterator insert(const_iterator position, initializer_list<value_type> il);
iterator erase(const_iterator position);
iterator erase(const_iterator position, const_iterator last);
void resize(size_type sz);
void resize(size_type sz, const value_type& c);
void swap(list&)
noexcept(allocator_traits<allocator_type>::is_always_equal::value); // C++17
void clear() noexcept;
void splice(const_iterator position, list& x);
void splice(const_iterator position, list&& x);
void splice(const_iterator position, list& x, const_iterator i);
void splice(const_iterator position, list&& x, const_iterator i);
void splice(const_iterator position, list& x, const_iterator first,
const_iterator last);
void splice(const_iterator position, list&& x, const_iterator first,
const_iterator last);
size_type remove(const value_type& value); // void before C++20
template <class Pred>
size_type remove_if(Pred pred); // void before C++20
size_type unique(); // void before C++20
template <class BinaryPredicate>
size_type unique(BinaryPredicate binary_pred); // void before C++20
void merge(list& x);
void merge(list&& x);
template <class Compare>
void merge(list& x, Compare comp);
template <class Compare>
void merge(list&& x, Compare comp);
void sort();
template <class Compare>
void sort(Compare comp);
void reverse() noexcept;
};
template <class InputIterator, class Allocator = allocator<typename iterator_traits<InputIterator>::value_type>>
list(InputIterator, InputIterator, Allocator = Allocator())
-> list<typename iterator_traits<InputIterator>::value_type, Allocator>; // C++17
template <class T, class Alloc>
bool operator==(const list<T,Alloc>& x, const list<T,Alloc>& y);
template <class T, class Alloc>
bool operator< (const list<T,Alloc>& x, const list<T,Alloc>& y);
template <class T, class Alloc>
bool operator!=(const list<T,Alloc>& x, const list<T,Alloc>& y);
template <class T, class Alloc>
bool operator> (const list<T,Alloc>& x, const list<T,Alloc>& y);
template <class T, class Alloc>
bool operator>=(const list<T,Alloc>& x, const list<T,Alloc>& y);
template <class T, class Alloc>
bool operator<=(const list<T,Alloc>& x, const list<T,Alloc>& y);
template <class T, class Alloc>
void swap(list<T,Alloc>& x, list<T,Alloc>& y)
noexcept(noexcept(x.swap(y)));
template <class T, class Allocator, class U>
void erase(list<T, Allocator>& c, const U& value); // C++20
template <class T, class Allocator, class Predicate>
void erase_if(list<T, Allocator>& c, Predicate pred); // C++20
} // std
*/
template <class _Tp, class _VoidPtr> struct __list_node;
template <class _Tp, class _VoidPtr> struct __list_node_base;
template <class _Tp, class _VoidPtr>
struct __list_node_pointer_traits {
typedef typename __rebind_pointer<_VoidPtr, __list_node<_Tp, _VoidPtr> >::type
__node_pointer;
typedef typename __rebind_pointer<_VoidPtr, __list_node_base<_Tp, _VoidPtr> >::type
__base_pointer;
#if defined(_LIBCPP_ABI_LIST_REMOVE_NODE_POINTER_UB)
typedef __base_pointer __link_pointer;
#else
typedef typename conditional<
is_pointer<_VoidPtr>::value,
__base_pointer,
__node_pointer
>::type __link_pointer;
#endif
typedef typename conditional<
is_same<__link_pointer, __node_pointer>::value,
__base_pointer,
__node_pointer
>::type __non_link_pointer;
static _LIBCPP_INLINE_VISIBILITY
__link_pointer __unsafe_link_pointer_cast(__link_pointer __p) {
return __p;
}
static _LIBCPP_INLINE_VISIBILITY
__link_pointer __unsafe_link_pointer_cast(__non_link_pointer __p) {
return static_cast<__link_pointer>(static_cast<_VoidPtr>(__p));
}
};
template <class _Tp, class _VoidPtr>
struct __list_node_base
{
typedef __list_node_pointer_traits<_Tp, _VoidPtr> _NodeTraits;
typedef typename _NodeTraits::__node_pointer __node_pointer;
typedef typename _NodeTraits::__base_pointer __base_pointer;
typedef typename _NodeTraits::__link_pointer __link_pointer;
__link_pointer __prev_;
__link_pointer __next_;
_LIBCPP_INLINE_VISIBILITY
__list_node_base() : __prev_(_NodeTraits::__unsafe_link_pointer_cast(__self())),
__next_(_NodeTraits::__unsafe_link_pointer_cast(__self())) {}
_LIBCPP_INLINE_VISIBILITY
__base_pointer __self() {
return pointer_traits<__base_pointer>::pointer_to(*this);
}
_LIBCPP_INLINE_VISIBILITY
__node_pointer __as_node() {
return static_cast<__node_pointer>(__self());
}
};
template <class _Tp, class _VoidPtr>
struct __list_node
: public __list_node_base<_Tp, _VoidPtr>
{
_Tp __value_;
typedef __list_node_base<_Tp, _VoidPtr> __base;
typedef typename __base::__link_pointer __link_pointer;
_LIBCPP_INLINE_VISIBILITY
__link_pointer __as_link() {
return static_cast<__link_pointer>(__base::__self());
}
};
template <class _Tp, class _Alloc = allocator<_Tp> > class _LIBCPP_TEMPLATE_VIS list;
template <class _Tp, class _Alloc> class __list_imp;
template <class _Tp, class _VoidPtr> class _LIBCPP_TEMPLATE_VIS __list_const_iterator;
template <class _Tp, class _VoidPtr>
class _LIBCPP_TEMPLATE_VIS __list_iterator
{
typedef __list_node_pointer_traits<_Tp, _VoidPtr> _NodeTraits;
typedef typename _NodeTraits::__link_pointer __link_pointer;
__link_pointer __ptr_;
#if _LIBCPP_DEBUG_LEVEL >= 2
_LIBCPP_INLINE_VISIBILITY
explicit __list_iterator(__link_pointer __p, const void* __c) _NOEXCEPT
: __ptr_(__p)
{
__get_db()->__insert_ic(this, __c);
}
#else
_LIBCPP_INLINE_VISIBILITY
explicit __list_iterator(__link_pointer __p) _NOEXCEPT : __ptr_(__p) {}
#endif
template<class, class> friend class list;
template<class, class> friend class __list_imp;
template<class, class> friend class __list_const_iterator;
public:
typedef bidirectional_iterator_tag iterator_category;
typedef _Tp value_type;
typedef value_type& reference;
typedef typename __rebind_pointer<_VoidPtr, value_type>::type pointer;
typedef typename pointer_traits<pointer>::difference_type difference_type;
_LIBCPP_INLINE_VISIBILITY
__list_iterator() _NOEXCEPT : __ptr_(nullptr)
{
#if _LIBCPP_DEBUG_LEVEL >= 2
__get_db()->__insert_i(this);
#endif
}
#if _LIBCPP_DEBUG_LEVEL >= 2
_LIBCPP_INLINE_VISIBILITY
__list_iterator(const __list_iterator& __p)
: __ptr_(__p.__ptr_)
{
__get_db()->__iterator_copy(this, &__p);
}
_LIBCPP_INLINE_VISIBILITY
~__list_iterator()
{
__get_db()->__erase_i(this);
}
_LIBCPP_INLINE_VISIBILITY
__list_iterator& operator=(const __list_iterator& __p)
{
if (this != &__p)
{
__get_db()->__iterator_copy(this, &__p);
__ptr_ = __p.__ptr_;
}
return *this;
}
#endif // _LIBCPP_DEBUG_LEVEL >= 2
_LIBCPP_INLINE_VISIBILITY
reference operator*() const
{
#if _LIBCPP_DEBUG_LEVEL >= 2
_LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this),
"Attempted to dereference a non-dereferenceable list::iterator");
#endif
return __ptr_->__as_node()->__value_;
}
_LIBCPP_INLINE_VISIBILITY
pointer operator->() const
{
#if _LIBCPP_DEBUG_LEVEL >= 2
_LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this),
"Attempted to dereference a non-dereferenceable list::iterator");
#endif
return pointer_traits<pointer>::pointer_to(__ptr_->__as_node()->__value_);
}
_LIBCPP_INLINE_VISIBILITY
__list_iterator& operator++()
{
#if _LIBCPP_DEBUG_LEVEL >= 2
_LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this),
"Attempted to increment non-incrementable list::iterator");
#endif
__ptr_ = __ptr_->__next_;
return *this;
}
_LIBCPP_INLINE_VISIBILITY
__list_iterator operator++(int) {__list_iterator __t(*this); ++(*this); return __t;}
_LIBCPP_INLINE_VISIBILITY
__list_iterator& operator--()
{
#if _LIBCPP_DEBUG_LEVEL >= 2
_LIBCPP_ASSERT(__get_const_db()->__decrementable(this),
"Attempted to decrement non-decrementable list::iterator");
#endif
__ptr_ = __ptr_->__prev_;
return *this;
}
_LIBCPP_INLINE_VISIBILITY
__list_iterator operator--(int) {__list_iterator __t(*this); --(*this); return __t;}
friend _LIBCPP_INLINE_VISIBILITY
bool operator==(const __list_iterator& __x, const __list_iterator& __y)
{
return __x.__ptr_ == __y.__ptr_;
}
friend _LIBCPP_INLINE_VISIBILITY
bool operator!=(const __list_iterator& __x, const __list_iterator& __y)
{return !(__x == __y);}
};
template <class _Tp, class _VoidPtr>
class _LIBCPP_TEMPLATE_VIS __list_const_iterator
{
typedef __list_node_pointer_traits<_Tp, _VoidPtr> _NodeTraits;
typedef typename _NodeTraits::__link_pointer __link_pointer;
__link_pointer __ptr_;
#if _LIBCPP_DEBUG_LEVEL >= 2
_LIBCPP_INLINE_VISIBILITY
explicit __list_const_iterator(__link_pointer __p, const void* __c) _NOEXCEPT
: __ptr_(__p)
{
__get_db()->__insert_ic(this, __c);
}
#else
_LIBCPP_INLINE_VISIBILITY
explicit __list_const_iterator(__link_pointer __p) _NOEXCEPT : __ptr_(__p) {}
#endif
template<class, class> friend class list;
template<class, class> friend class __list_imp;
public:
typedef bidirectional_iterator_tag iterator_category;
typedef _Tp value_type;
typedef const value_type& reference;
typedef typename __rebind_pointer<_VoidPtr, const value_type>::type pointer;
typedef typename pointer_traits<pointer>::difference_type difference_type;
_LIBCPP_INLINE_VISIBILITY
__list_const_iterator() _NOEXCEPT : __ptr_(nullptr)
{
#if _LIBCPP_DEBUG_LEVEL >= 2
__get_db()->__insert_i(this);
#endif
}
_LIBCPP_INLINE_VISIBILITY
__list_const_iterator(const __list_iterator<_Tp, _VoidPtr>& __p) _NOEXCEPT
: __ptr_(__p.__ptr_)
{
#if _LIBCPP_DEBUG_LEVEL >= 2
__get_db()->__iterator_copy(this, &__p);
#endif
}
#if _LIBCPP_DEBUG_LEVEL >= 2
_LIBCPP_INLINE_VISIBILITY
__list_const_iterator(const __list_const_iterator& __p)
: __ptr_(__p.__ptr_)
{
__get_db()->__iterator_copy(this, &__p);
}
_LIBCPP_INLINE_VISIBILITY
~__list_const_iterator()
{
__get_db()->__erase_i(this);
}
_LIBCPP_INLINE_VISIBILITY
__list_const_iterator& operator=(const __list_const_iterator& __p)
{
if (this != &__p)
{
__get_db()->__iterator_copy(this, &__p);
__ptr_ = __p.__ptr_;
}
return *this;
}
#endif // _LIBCPP_DEBUG_LEVEL >= 2
_LIBCPP_INLINE_VISIBILITY
reference operator*() const
{
#if _LIBCPP_DEBUG_LEVEL >= 2
_LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this),
"Attempted to dereference a non-dereferenceable list::const_iterator");
#endif
return __ptr_->__as_node()->__value_;
}
_LIBCPP_INLINE_VISIBILITY
pointer operator->() const
{
#if _LIBCPP_DEBUG_LEVEL >= 2
_LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this),
"Attempted to dereference a non-dereferenceable list::const_iterator");
#endif
return pointer_traits<pointer>::pointer_to(__ptr_->__as_node()->__value_);
}
_LIBCPP_INLINE_VISIBILITY
__list_const_iterator& operator++()
{
#if _LIBCPP_DEBUG_LEVEL >= 2
_LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this),
"Attempted to increment non-incrementable list::const_iterator");
#endif
__ptr_ = __ptr_->__next_;
return *this;
}
_LIBCPP_INLINE_VISIBILITY
__list_const_iterator operator++(int) {__list_const_iterator __t(*this); ++(*this); return __t;}
_LIBCPP_INLINE_VISIBILITY
__list_const_iterator& operator--()
{
#if _LIBCPP_DEBUG_LEVEL >= 2
_LIBCPP_ASSERT(__get_const_db()->__decrementable(this),
"Attempted to decrement non-decrementable list::const_iterator");
#endif
__ptr_ = __ptr_->__prev_;
return *this;
}
_LIBCPP_INLINE_VISIBILITY
__list_const_iterator operator--(int) {__list_const_iterator __t(*this); --(*this); return __t;}
friend _LIBCPP_INLINE_VISIBILITY
bool operator==(const __list_const_iterator& __x, const __list_const_iterator& __y)
{
return __x.__ptr_ == __y.__ptr_;
}
friend _LIBCPP_INLINE_VISIBILITY
bool operator!=(const __list_const_iterator& __x, const __list_const_iterator& __y)
{return !(__x == __y);}
};
template <class _Tp, class _Alloc>
class __list_imp
{
__list_imp(const __list_imp&);
__list_imp& operator=(const __list_imp&);
public:
typedef _Alloc allocator_type;
typedef allocator_traits<allocator_type> __alloc_traits;
typedef typename __alloc_traits::size_type size_type;
protected:
typedef _Tp value_type;
typedef typename __alloc_traits::void_pointer __void_pointer;
typedef __list_iterator<value_type, __void_pointer> iterator;
typedef __list_const_iterator<value_type, __void_pointer> const_iterator;
typedef __list_node_base<value_type, __void_pointer> __node_base;
typedef __list_node<value_type, __void_pointer> __node;
typedef typename __rebind_alloc_helper<__alloc_traits, __node>::type __node_allocator;
typedef allocator_traits<__node_allocator> __node_alloc_traits;
typedef typename __node_alloc_traits::pointer __node_pointer;
typedef typename __node_alloc_traits::pointer __node_const_pointer;
typedef __list_node_pointer_traits<value_type, __void_pointer> __node_pointer_traits;
typedef typename __node_pointer_traits::__link_pointer __link_pointer;
typedef __link_pointer __link_const_pointer;
typedef typename __alloc_traits::pointer pointer;
typedef typename __alloc_traits::const_pointer const_pointer;
typedef typename __alloc_traits::difference_type difference_type;
typedef typename __rebind_alloc_helper<__alloc_traits, __node_base>::type __node_base_allocator;
typedef typename allocator_traits<__node_base_allocator>::pointer __node_base_pointer;
static_assert((!is_same<allocator_type, __node_allocator>::value),
"internal allocator type must differ from user-specified "
"type; otherwise overload resolution breaks");
__node_base __end_;
__compressed_pair<size_type, __node_allocator> __size_alloc_;
_LIBCPP_INLINE_VISIBILITY
__link_pointer __end_as_link() const _NOEXCEPT {
return __node_pointer_traits::__unsafe_link_pointer_cast(
const_cast<__node_base&>(__end_).__self());
}
_LIBCPP_INLINE_VISIBILITY
size_type& __sz() _NOEXCEPT {return __size_alloc_.first();}
_LIBCPP_INLINE_VISIBILITY
const size_type& __sz() const _NOEXCEPT
{return __size_alloc_.first();}
_LIBCPP_INLINE_VISIBILITY
__node_allocator& __node_alloc() _NOEXCEPT
{return __size_alloc_.second();}
_LIBCPP_INLINE_VISIBILITY
const __node_allocator& __node_alloc() const _NOEXCEPT
{return __size_alloc_.second();}
_LIBCPP_INLINE_VISIBILITY
size_type __node_alloc_max_size() const _NOEXCEPT {
return __node_alloc_traits::max_size(__node_alloc());
}
_LIBCPP_INLINE_VISIBILITY
static void __unlink_nodes(__link_pointer __f, __link_pointer __l) _NOEXCEPT;
_LIBCPP_INLINE_VISIBILITY
__list_imp()
_NOEXCEPT_(is_nothrow_default_constructible<__node_allocator>::value);
_LIBCPP_INLINE_VISIBILITY
__list_imp(const allocator_type& __a);
_LIBCPP_INLINE_VISIBILITY
__list_imp(const __node_allocator& __a);
#ifndef _LIBCPP_CXX03_LANG
__list_imp(__node_allocator&& __a) _NOEXCEPT;
#endif
~__list_imp();
void clear() _NOEXCEPT;
_LIBCPP_INLINE_VISIBILITY
bool empty() const _NOEXCEPT {return __sz() == 0;}
_LIBCPP_INLINE_VISIBILITY
iterator begin() _NOEXCEPT
{
#if _LIBCPP_DEBUG_LEVEL >= 2
return iterator(__end_.__next_, this);
#else
return iterator(__end_.__next_);
#endif
}
_LIBCPP_INLINE_VISIBILITY
const_iterator begin() const _NOEXCEPT
{
#if _LIBCPP_DEBUG_LEVEL >= 2
return const_iterator(__end_.__next_, this);
#else
return const_iterator(__end_.__next_);
#endif
}
_LIBCPP_INLINE_VISIBILITY
iterator end() _NOEXCEPT
{
#if _LIBCPP_DEBUG_LEVEL >= 2
return iterator(__end_as_link(), this);
#else
return iterator(__end_as_link());
#endif
}
_LIBCPP_INLINE_VISIBILITY
const_iterator end() const _NOEXCEPT
{
#if _LIBCPP_DEBUG_LEVEL >= 2
return const_iterator(__end_as_link(), this);
#else
return const_iterator(__end_as_link());
#endif
}
void swap(__list_imp& __c)
#if _LIBCPP_STD_VER >= 14
_NOEXCEPT;
#else
_NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value ||
__is_nothrow_swappable<allocator_type>::value);
#endif
_LIBCPP_INLINE_VISIBILITY
void __copy_assign_alloc(const __list_imp& __c)
{__copy_assign_alloc(__c, integral_constant<bool,
__node_alloc_traits::propagate_on_container_copy_assignment::value>());}
_LIBCPP_INLINE_VISIBILITY
void __move_assign_alloc(__list_imp& __c)
_NOEXCEPT_(
!__node_alloc_traits::propagate_on_container_move_assignment::value ||
is_nothrow_move_assignable<__node_allocator>::value)
{__move_assign_alloc(__c, integral_constant<bool,
__node_alloc_traits::propagate_on_container_move_assignment::value>());}
private:
_LIBCPP_INLINE_VISIBILITY
void __copy_assign_alloc(const __list_imp& __c, true_type)
{
if (__node_alloc() != __c.__node_alloc())
clear();
__node_alloc() = __c.__node_alloc();
}
_LIBCPP_INLINE_VISIBILITY
void __copy_assign_alloc(const __list_imp&, false_type)
{}
_LIBCPP_INLINE_VISIBILITY
void __move_assign_alloc(__list_imp& __c, true_type)
_NOEXCEPT_(is_nothrow_move_assignable<__node_allocator>::value)
{
__node_alloc() = _VSTD::move(__c.__node_alloc());
}
_LIBCPP_INLINE_VISIBILITY
void __move_assign_alloc(__list_imp&, false_type)
_NOEXCEPT
{}
_LIBCPP_INLINE_VISIBILITY
void __invalidate_all_iterators() {
#if _LIBCPP_DEBUG_LEVEL >= 2
__get_db()->__invalidate_all(this);
#endif
}
};
// Unlink nodes [__f, __l]
template <class _Tp, class _Alloc>
inline
void
__list_imp<_Tp, _Alloc>::__unlink_nodes(__link_pointer __f, __link_pointer __l)
_NOEXCEPT
{
__f->__prev_->__next_ = __l->__next_;
__l->__next_->__prev_ = __f->__prev_;
}
template <class _Tp, class _Alloc>
inline
__list_imp<_Tp, _Alloc>::__list_imp()
_NOEXCEPT_(is_nothrow_default_constructible<__node_allocator>::value)
: __size_alloc_(0)
{
}
template <class _Tp, class _Alloc>
inline
__list_imp<_Tp, _Alloc>::__list_imp(const allocator_type& __a)
: __size_alloc_(0, __node_allocator(__a))
{
}
template <class _Tp, class _Alloc>
inline __list_imp<_Tp, _Alloc>::__list_imp(const __node_allocator& __a)
: __size_alloc_(0, __a) {}
#ifndef _LIBCPP_CXX03_LANG
template <class _Tp, class _Alloc>
inline __list_imp<_Tp, _Alloc>::__list_imp(__node_allocator&& __a) _NOEXCEPT
: __size_alloc_(0, std::move(__a)) {}
#endif
template <class _Tp, class _Alloc>
__list_imp<_Tp, _Alloc>::~__list_imp() {
clear();
#if _LIBCPP_DEBUG_LEVEL >= 2
__get_db()->__erase_c(this);
#endif
}
template <class _Tp, class _Alloc>
void
__list_imp<_Tp, _Alloc>::clear() _NOEXCEPT
{
if (!empty())
{
__node_allocator& __na = __node_alloc();
__link_pointer __f = __end_.__next_;
__link_pointer __l = __end_as_link();
__unlink_nodes(__f, __l->__prev_);
__sz() = 0;
while (__f != __l)
{
__node_pointer __np = __f->__as_node();
__f = __f->__next_;
__node_alloc_traits::destroy(__na, _VSTD::addressof(__np->__value_));
__node_alloc_traits::deallocate(__na, __np, 1);
}
__invalidate_all_iterators();
}
}
template <class _Tp, class _Alloc>
void
__list_imp<_Tp, _Alloc>::swap(__list_imp& __c)
#if _LIBCPP_STD_VER >= 14
_NOEXCEPT
#else
_NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value ||
__is_nothrow_swappable<allocator_type>::value)
#endif
{
_LIBCPP_ASSERT(__alloc_traits::propagate_on_container_swap::value ||
this->__node_alloc() == __c.__node_alloc(),
"list::swap: Either propagate_on_container_swap must be true"
" or the allocators must compare equal");
using _VSTD::swap;
__swap_allocator(__node_alloc(), __c.__node_alloc());
swap(__sz(), __c.__sz());
swap(__end_, __c.__end_);
if (__sz() == 0)
__end_.__next_ = __end_.__prev_ = __end_as_link();
else
__end_.__prev_->__next_ = __end_.__next_->__prev_ = __end_as_link();
if (__c.__sz() == 0)
__c.__end_.__next_ = __c.__end_.__prev_ = __c.__end_as_link();
else
__c.__end_.__prev_->__next_ = __c.__end_.__next_->__prev_ = __c.__end_as_link();
#if _LIBCPP_DEBUG_LEVEL >= 2
__libcpp_db* __db = __get_db();
__c_node* __cn1 = __db->__find_c_and_lock(this);
__c_node* __cn2 = __db->__find_c(&__c);
std::swap(__cn1->beg_, __cn2->beg_);
std::swap(__cn1->end_, __cn2->end_);
std::swap(__cn1->cap_, __cn2->cap_);
for (__i_node** __p = __cn1->end_; __p != __cn1->beg_;)
{
--__p;
const_iterator* __i = static_cast<const_iterator*>((*__p)->__i_);
if (__i->__ptr_ == __c.__end_as_link())
{
__cn2->__add(*__p);
if (--__cn1->end_ != __p)
memmove(__p, __p+1, (__cn1->end_ - __p)*sizeof(__i_node*));
}
else
(*__p)->__c_ = __cn1;
}
for (__i_node** __p = __cn2->end_; __p != __cn2->beg_;)
{
--__p;
const_iterator* __i = static_cast<const_iterator*>((*__p)->__i_);
if (__i->__ptr_ == __end_as_link())
{
__cn1->__add(*__p);
if (--__cn2->end_ != __p)
memmove(__p, __p+1, (__cn2->end_ - __p)*sizeof(__i_node*));
}
else
(*__p)->__c_ = __cn2;
}
__db->unlock();
#endif
}
template <class _Tp, class _Alloc /*= allocator<_Tp>*/>
class _LIBCPP_TEMPLATE_VIS list
: private __list_imp<_Tp, _Alloc>
{
typedef __list_imp<_Tp, _Alloc> base;
typedef typename base::__node __node;
typedef typename base::__node_allocator __node_allocator;
typedef typename base::__node_pointer __node_pointer;
typedef typename base::__node_alloc_traits __node_alloc_traits;
typedef typename base::__node_base __node_base;
typedef typename base::__node_base_pointer __node_base_pointer;
typedef typename base::__link_pointer __link_pointer;
public:
typedef _Tp value_type;
typedef _Alloc allocator_type;
static_assert((is_same<value_type, typename allocator_type::value_type>::value),
"Invalid allocator::value_type");
typedef value_type& reference;
typedef const value_type& const_reference;
typedef typename base::pointer pointer;
typedef typename base::const_pointer const_pointer;
typedef typename base::size_type size_type;
typedef typename base::difference_type difference_type;
typedef typename base::iterator iterator;
typedef typename base::const_iterator const_iterator;
typedef _VSTD::reverse_iterator<iterator> reverse_iterator;
typedef _VSTD::reverse_iterator<const_iterator> const_reverse_iterator;
#if _LIBCPP_STD_VER > 17
typedef size_type __remove_return_type;
#else
typedef void __remove_return_type;
#endif
_LIBCPP_INLINE_VISIBILITY
list()
_NOEXCEPT_(is_nothrow_default_constructible<__node_allocator>::value)
{
#if _LIBCPP_DEBUG_LEVEL >= 2
__get_db()->__insert_c(this);
#endif
}
_LIBCPP_INLINE_VISIBILITY
explicit list(const allocator_type& __a) : base(__a)
{
#if _LIBCPP_DEBUG_LEVEL >= 2
__get_db()->__insert_c(this);
#endif
}
explicit list(size_type __n);
#if _LIBCPP_STD_VER > 11
explicit list(size_type __n, const allocator_type& __a);
#endif
list(size_type __n, const value_type& __x);
list(size_type __n, const value_type& __x, const allocator_type& __a);
template <class _InpIter>
list(_InpIter __f, _InpIter __l,
typename enable_if<__is_input_iterator<_InpIter>::value>::type* = 0);
template <class _InpIter>
list(_InpIter __f, _InpIter __l, const allocator_type& __a,
typename enable_if<__is_input_iterator<_InpIter>::value>::type* = 0);
list(const list& __c);
list(const list& __c, const allocator_type& __a);
_LIBCPP_INLINE_VISIBILITY
list& operator=(const list& __c);
#ifndef _LIBCPP_CXX03_LANG
list(initializer_list<value_type> __il);
list(initializer_list<value_type> __il, const allocator_type& __a);
_LIBCPP_INLINE_VISIBILITY
list(list&& __c)
_NOEXCEPT_(is_nothrow_move_constructible<__node_allocator>::value);
_LIBCPP_INLINE_VISIBILITY
list(list&& __c, const allocator_type& __a);
_LIBCPP_INLINE_VISIBILITY
list& operator=(list&& __c)
_NOEXCEPT_(
__node_alloc_traits::propagate_on_container_move_assignment::value &&
is_nothrow_move_assignable<__node_allocator>::value);
_LIBCPP_INLINE_VISIBILITY
list& operator=(initializer_list<value_type> __il)
{assign(__il.begin(), __il.end()); return *this;}
_LIBCPP_INLINE_VISIBILITY
void assign(initializer_list<value_type> __il)
{assign(__il.begin(), __il.end());}
#endif // _LIBCPP_CXX03_LANG
template <class _InpIter>
void assign(_InpIter __f, _InpIter __l,
typename enable_if<__is_input_iterator<_InpIter>::value>::type* = 0);
void assign(size_type __n, const value_type& __x);
_LIBCPP_INLINE_VISIBILITY
allocator_type get_allocator() const _NOEXCEPT;
_LIBCPP_INLINE_VISIBILITY
size_type size() const _NOEXCEPT {return base::__sz();}
_LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
bool empty() const _NOEXCEPT {return base::empty();}
_LIBCPP_INLINE_VISIBILITY
size_type max_size() const _NOEXCEPT
{
return std::min<size_type>(
base::__node_alloc_max_size(),
numeric_limits<difference_type >::max());
}
_LIBCPP_INLINE_VISIBILITY
iterator begin() _NOEXCEPT {return base::begin();}
_LIBCPP_INLINE_VISIBILITY
const_iterator begin() const _NOEXCEPT {return base::begin();}
_LIBCPP_INLINE_VISIBILITY
iterator end() _NOEXCEPT {return base::end();}
_LIBCPP_INLINE_VISIBILITY
const_iterator end() const _NOEXCEPT {return base::end();}
_LIBCPP_INLINE_VISIBILITY
const_iterator cbegin() const _NOEXCEPT {return base::begin();}
_LIBCPP_INLINE_VISIBILITY
const_iterator cend() const _NOEXCEPT {return base::end();}
_LIBCPP_INLINE_VISIBILITY
reverse_iterator rbegin() _NOEXCEPT
{return reverse_iterator(end());}
_LIBCPP_INLINE_VISIBILITY
const_reverse_iterator rbegin() const _NOEXCEPT
{return const_reverse_iterator(end());}
_LIBCPP_INLINE_VISIBILITY
reverse_iterator rend() _NOEXCEPT
{return reverse_iterator(begin());}
_LIBCPP_INLINE_VISIBILITY
const_reverse_iterator rend() const _NOEXCEPT
{return const_reverse_iterator(begin());}
_LIBCPP_INLINE_VISIBILITY
const_reverse_iterator crbegin() const _NOEXCEPT
{return const_reverse_iterator(end());}
_LIBCPP_INLINE_VISIBILITY
const_reverse_iterator crend() const _NOEXCEPT
{return const_reverse_iterator(begin());}
_LIBCPP_INLINE_VISIBILITY
reference front()
{
_LIBCPP_ASSERT(!empty(), "list::front called on empty list");
return base::__end_.__next_->__as_node()->__value_;
}
_LIBCPP_INLINE_VISIBILITY
const_reference front() const
{
_LIBCPP_ASSERT(!empty(), "list::front called on empty list");
return base::__end_.__next_->__as_node()->__value_;
}
_LIBCPP_INLINE_VISIBILITY
reference back()
{
_LIBCPP_ASSERT(!empty(), "list::back called on empty list");
return base::__end_.__prev_->__as_node()->__value_;
}
_LIBCPP_INLINE_VISIBILITY
const_reference back() const
{
_LIBCPP_ASSERT(!empty(), "list::back called on empty list");
return base::__end_.__prev_->__as_node()->__value_;
}
#ifndef _LIBCPP_CXX03_LANG
void push_front(value_type&& __x);
void push_back(value_type&& __x);
template <class... _Args>
#if _LIBCPP_STD_VER > 14
reference emplace_front(_Args&&... __args);
#else
void emplace_front(_Args&&... __args);
#endif
template <class... _Args>
#if _LIBCPP_STD_VER > 14
reference emplace_back(_Args&&... __args);
#else
void emplace_back(_Args&&... __args);
#endif
template <class... _Args>
iterator emplace(const_iterator __p, _Args&&... __args);
iterator insert(const_iterator __p, value_type&& __x);
_LIBCPP_INLINE_VISIBILITY
iterator insert(const_iterator __p, initializer_list<value_type> __il)
{return insert(__p, __il.begin(), __il.end());}
#endif // _LIBCPP_CXX03_LANG
void push_front(const value_type& __x);
void push_back(const value_type& __x);
#ifndef _LIBCPP_CXX03_LANG
template <class _Arg>
_LIBCPP_INLINE_VISIBILITY
void __emplace_back(_Arg&& __arg) { emplace_back(_VSTD::forward<_Arg>(__arg)); }
#else
_LIBCPP_INLINE_VISIBILITY
void __emplace_back(value_type const& __arg) { push_back(__arg); }
#endif
iterator insert(const_iterator __p, const value_type& __x);
iterator insert(const_iterator __p, size_type __n, const value_type& __x);
template <class _InpIter>
iterator insert(const_iterator __p, _InpIter __f, _InpIter __l,
typename enable_if<__is_input_iterator<_InpIter>::value>::type* = 0);
_LIBCPP_INLINE_VISIBILITY
void swap(list& __c)
#if _LIBCPP_STD_VER >= 14
_NOEXCEPT
#else
_NOEXCEPT_(!__node_alloc_traits::propagate_on_container_swap::value ||
__is_nothrow_swappable<__node_allocator>::value)
#endif
{base::swap(__c);}
_LIBCPP_INLINE_VISIBILITY
void clear() _NOEXCEPT {base::clear();}
void pop_front();
void pop_back();
iterator erase(const_iterator __p);
iterator erase(const_iterator __f, const_iterator __l);
void resize(size_type __n);
void resize(size_type __n, const value_type& __x);
void splice(const_iterator __p, list& __c);
#ifndef _LIBCPP_CXX03_LANG
_LIBCPP_INLINE_VISIBILITY
void splice(const_iterator __p, list&& __c) {splice(__p, __c);}
_LIBCPP_INLINE_VISIBILITY
void splice(const_iterator __p, list&& __c, const_iterator __i)
{splice(__p, __c, __i);}
_LIBCPP_INLINE_VISIBILITY
void splice(const_iterator __p, list&& __c, const_iterator __f, const_iterator __l)
{splice(__p, __c, __f, __l);}
#endif
void splice(const_iterator __p, list& __c, const_iterator __i);
void splice(const_iterator __p, list& __c, const_iterator __f, const_iterator __l);
__remove_return_type remove(const value_type& __x);
template <class _Pred> __remove_return_type remove_if(_Pred __pred);
_LIBCPP_INLINE_VISIBILITY
__remove_return_type unique() { return unique(__equal_to<value_type>()); }
template <class _BinaryPred>
__remove_return_type unique(_BinaryPred __binary_pred);
_LIBCPP_INLINE_VISIBILITY
void merge(list& __c);
#ifndef _LIBCPP_CXX03_LANG
_LIBCPP_INLINE_VISIBILITY
void merge(list&& __c) {merge(__c);}
template <class _Comp>
_LIBCPP_INLINE_VISIBILITY
void merge(list&& __c, _Comp __comp) {merge(__c, __comp);}
#endif
template <class _Comp>
void merge(list& __c, _Comp __comp);
_LIBCPP_INLINE_VISIBILITY
void sort();
template <class _Comp>
_LIBCPP_INLINE_VISIBILITY
void sort(_Comp __comp);
void reverse() _NOEXCEPT;
bool __invariants() const;
typedef __allocator_destructor<__node_allocator> __node_destructor;
typedef unique_ptr<__node, __node_destructor> __hold_pointer;
_LIBCPP_INLINE_VISIBILITY
__hold_pointer __allocate_node(__node_allocator& __na) {
__node_pointer __p = __node_alloc_traits::allocate(__na, 1);
__p->__prev_ = nullptr;
return __hold_pointer(__p, __node_destructor(__na, 1));
}
#if _LIBCPP_DEBUG_LEVEL >= 2
bool __dereferenceable(const const_iterator* __i) const;
bool __decrementable(const const_iterator* __i) const;
bool __addable(const const_iterator* __i, ptrdiff_t __n) const;
bool __subscriptable(const const_iterator* __i, ptrdiff_t __n) const;
#endif // _LIBCPP_DEBUG_LEVEL >= 2
private:
_LIBCPP_INLINE_VISIBILITY
static void __link_nodes (__link_pointer __p, __link_pointer __f, __link_pointer __l);
_LIBCPP_INLINE_VISIBILITY
void __link_nodes_at_front(__link_pointer __f, __link_pointer __l);
_LIBCPP_INLINE_VISIBILITY
void __link_nodes_at_back (__link_pointer __f, __link_pointer __l);
iterator __iterator(size_type __n);
template <class _Comp>
static iterator __sort(iterator __f1, iterator __e2, size_type __n, _Comp& __comp);
void __move_assign(list& __c, true_type)
_NOEXCEPT_(is_nothrow_move_assignable<__node_allocator>::value);
void __move_assign(list& __c, false_type);
};
#ifndef _LIBCPP_HAS_NO_DEDUCTION_GUIDES
template<class _InputIterator,
class _Alloc = typename std::allocator<typename iterator_traits<_InputIterator>::value_type>,
class = typename enable_if<__is_allocator<_Alloc>::value, void>::type
>
list(_InputIterator, _InputIterator)
-> list<typename iterator_traits<_InputIterator>::value_type, _Alloc>;
template<class _InputIterator,
class _Alloc,
class = typename enable_if<__is_allocator<_Alloc>::value, void>::type
>
list(_InputIterator, _InputIterator, _Alloc)
-> list<typename iterator_traits<_InputIterator>::value_type, _Alloc>;
#endif
// Link in nodes [__f, __l] just prior to __p
template <class _Tp, class _Alloc>
inline
void
list<_Tp, _Alloc>::__link_nodes(__link_pointer __p, __link_pointer __f, __link_pointer __l)
{
__p->__prev_->__next_ = __f;
__f->__prev_ = __p->__prev_;
__p->__prev_ = __l;
__l->__next_ = __p;
}
// Link in nodes [__f, __l] at the front of the list
template <class _Tp, class _Alloc>
inline
void
list<_Tp, _Alloc>::__link_nodes_at_front(__link_pointer __f, __link_pointer __l)
{
__f->__prev_ = base::__end_as_link();
__l->__next_ = base::__end_.__next_;
__l->__next_->__prev_ = __l;
base::__end_.__next_ = __f;
}
// Link in nodes [__f, __l] at the back of the list
template <class _Tp, class _Alloc>
inline
void
list<_Tp, _Alloc>::__link_nodes_at_back(__link_pointer __f, __link_pointer __l)
{
__l->__next_ = base::__end_as_link();
__f->__prev_ = base::__end_.__prev_;
__f->__prev_->__next_ = __f;
base::__end_.__prev_ = __l;
}
template <class _Tp, class _Alloc>
inline
typename list<_Tp, _Alloc>::iterator
list<_Tp, _Alloc>::__iterator(size_type __n)
{
return __n <= base::__sz() / 2 ? _VSTD::next(begin(), __n)
: _VSTD::prev(end(), base::__sz() - __n);
}
template <class _Tp, class _Alloc>
list<_Tp, _Alloc>::list(size_type __n)
{
#if _LIBCPP_DEBUG_LEVEL >= 2
__get_db()->__insert_c(this);
#endif
for (; __n > 0; --__n)
#ifndef _LIBCPP_CXX03_LANG
emplace_back();
#else
push_back(value_type());
#endif
}
#if _LIBCPP_STD_VER > 11
template <class _Tp, class _Alloc>
list<_Tp, _Alloc>::list(size_type __n, const allocator_type& __a) : base(__a)
{
#if _LIBCPP_DEBUG_LEVEL >= 2
__get_db()->__insert_c(this);
#endif
for (; __n > 0; --__n)
emplace_back();
}
#endif
template <class _Tp, class _Alloc>
list<_Tp, _Alloc>::list(size_type __n, const value_type& __x)
{
#if _LIBCPP_DEBUG_LEVEL >= 2
__get_db()->__insert_c(this);
#endif
for (; __n > 0; --__n)
push_back(__x);
}
template <class _Tp, class _Alloc>
list<_Tp, _Alloc>::list(size_type __n, const value_type& __x, const allocator_type& __a)
: base(__a)
{
#if _LIBCPP_DEBUG_LEVEL >= 2
__get_db()->__insert_c(this);
#endif
for (; __n > 0; --__n)
push_back(__x);
}
template <class _Tp, class _Alloc>
template <class _InpIter>
list<_Tp, _Alloc>::list(_InpIter __f, _InpIter __l,
typename enable_if<__is_input_iterator<_InpIter>::value>::type*)
{
#if _LIBCPP_DEBUG_LEVEL >= 2
__get_db()->__insert_c(this);
#endif
for (; __f != __l; ++__f)
__emplace_back(*__f);
}
template <class _Tp, class _Alloc>
template <class _InpIter>
list<_Tp, _Alloc>::list(_InpIter __f, _InpIter __l, const allocator_type& __a,
typename enable_if<__is_input_iterator<_InpIter>::value>::type*)
: base(__a)
{
#if _LIBCPP_DEBUG_LEVEL >= 2
__get_db()->__insert_c(this);
#endif
for (; __f != __l; ++__f)
__emplace_back(*__f);
}
template <class _Tp, class _Alloc>
list<_Tp, _Alloc>::list(const list& __c)
: base(__node_alloc_traits::select_on_container_copy_construction(
__c.__node_alloc())) {
#if _LIBCPP_DEBUG_LEVEL >= 2
__get_db()->__insert_c(this);
#endif
for (const_iterator __i = __c.begin(), __e = __c.end(); __i != __e; ++__i)
push_back(*__i);
}
template <class _Tp, class _Alloc>
list<_Tp, _Alloc>::list(const list& __c, const allocator_type& __a)
: base(__a)
{
#if _LIBCPP_DEBUG_LEVEL >= 2
__get_db()->__insert_c(this);
#endif
for (const_iterator __i = __c.begin(), __e = __c.end(); __i != __e; ++__i)
push_back(*__i);
}
#ifndef _LIBCPP_CXX03_LANG
template <class _Tp, class _Alloc>
list<_Tp, _Alloc>::list(initializer_list<value_type> __il, const allocator_type& __a)
: base(__a)
{
#if _LIBCPP_DEBUG_LEVEL >= 2
__get_db()->__insert_c(this);
#endif
for (typename initializer_list<value_type>::const_iterator __i = __il.begin(),
__e = __il.end(); __i != __e; ++__i)
push_back(*__i);
}
template <class _Tp, class _Alloc>
list<_Tp, _Alloc>::list(initializer_list<value_type> __il)
{
#if _LIBCPP_DEBUG_LEVEL >= 2
__get_db()->__insert_c(this);
#endif
for (typename initializer_list<value_type>::const_iterator __i = __il.begin(),
__e = __il.end(); __i != __e; ++__i)
push_back(*__i);
}
template <class _Tp, class _Alloc>
inline list<_Tp, _Alloc>::list(list&& __c)
_NOEXCEPT_(is_nothrow_move_constructible<__node_allocator>::value)
: base(_VSTD::move(__c.__node_alloc())) {
#if _LIBCPP_DEBUG_LEVEL >= 2
__get_db()->__insert_c(this);
#endif
splice(end(), __c);
}
template <class _Tp, class _Alloc>
inline
list<_Tp, _Alloc>::list(list&& __c, const allocator_type& __a)
: base(__a)
{
#if _LIBCPP_DEBUG_LEVEL >= 2
__get_db()->__insert_c(this);
#endif
if (__a == __c.get_allocator())
splice(end(), __c);
else
{
typedef move_iterator<iterator> _Ip;
assign(_Ip(__c.begin()), _Ip(__c.end()));
}
}
template <class _Tp, class _Alloc>
inline
list<_Tp, _Alloc>&
list<_Tp, _Alloc>::operator=(list&& __c)
_NOEXCEPT_(
__node_alloc_traits::propagate_on_container_move_assignment::value &&
is_nothrow_move_assignable<__node_allocator>::value)
{
__move_assign(__c, integral_constant<bool,
__node_alloc_traits::propagate_on_container_move_assignment::value>());
return *this;
}
template <class _Tp, class _Alloc>
void
list<_Tp, _Alloc>::__move_assign(list& __c, false_type)
{
if (base::__node_alloc() != __c.__node_alloc())
{
typedef move_iterator<iterator> _Ip;
assign(_Ip(__c.begin()), _Ip(__c.end()));
}
else
__move_assign(__c, true_type());
}
template <class _Tp, class _Alloc>
void
list<_Tp, _Alloc>::__move_assign(list& __c, true_type)
_NOEXCEPT_(is_nothrow_move_assignable<__node_allocator>::value)
{
clear();
base::__move_assign_alloc(__c);
splice(end(), __c);
}
#endif // _LIBCPP_CXX03_LANG
template <class _Tp, class _Alloc>
inline
list<_Tp, _Alloc>&
list<_Tp, _Alloc>::operator=(const list& __c)
{
if (this != &__c)
{
base::__copy_assign_alloc(__c);
assign(__c.begin(), __c.end());
}
return *this;
}
template <class _Tp, class _Alloc>
template <class _InpIter>
void
list<_Tp, _Alloc>::assign(_InpIter __f, _InpIter __l,
typename enable_if<__is_input_iterator<_InpIter>::value>::type*)
{
iterator __i = begin();
iterator __e = end();
for (; __f != __l && __i != __e; ++__f, ++__i)
*__i = *__f;
if (__i == __e)
insert(__e, __f, __l);
else
erase(__i, __e);
#if _LIBCPP_DEBUG_LEVEL >= 2
__get_db()->__invalidate_all(this);
#endif
}
template <class _Tp, class _Alloc>
void
list<_Tp, _Alloc>::assign(size_type __n, const value_type& __x)
{
iterator __i = begin();
iterator __e = end();
for (; __n > 0 && __i != __e; --__n, ++__i)
*__i = __x;
if (__i == __e)
insert(__e, __n, __x);
else
erase(__i, __e);
#if _LIBCPP_DEBUG_LEVEL >= 2
__get_db()->__invalidate_all(this);
#endif
}
template <class _Tp, class _Alloc>
inline
_Alloc
list<_Tp, _Alloc>::get_allocator() const _NOEXCEPT
{
return allocator_type(base::__node_alloc());
}
template <class _Tp, class _Alloc>
typename list<_Tp, _Alloc>::iterator
list<_Tp, _Alloc>::insert(const_iterator __p, const value_type& __x)
{
#if _LIBCPP_DEBUG_LEVEL >= 2
_LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this,
"list::insert(iterator, x) called with an iterator not"
" referring to this list");
#endif
__node_allocator& __na = base::__node_alloc();
__hold_pointer __hold = __allocate_node(__na);
__node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), __x);
__link_nodes(__p.__ptr_, __hold->__as_link(), __hold->__as_link());
++base::__sz();
#if _LIBCPP_DEBUG_LEVEL >= 2
return iterator(__hold.release()->__as_link(), this);
#else
return iterator(__hold.release()->__as_link());
#endif
}
template <class _Tp, class _Alloc>
typename list<_Tp, _Alloc>::iterator
list<_Tp, _Alloc>::insert(const_iterator __p, size_type __n, const value_type& __x)
{
#if _LIBCPP_DEBUG_LEVEL >= 2
_LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this,
"list::insert(iterator, n, x) called with an iterator not"
" referring to this list");
iterator __r(__p.__ptr_, this);
#else
iterator __r(__p.__ptr_);
#endif
if (__n > 0)
{
size_type __ds = 0;
__node_allocator& __na = base::__node_alloc();
__hold_pointer __hold = __allocate_node(__na);
__node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), __x);
++__ds;
#if _LIBCPP_DEBUG_LEVEL >= 2
__r = iterator(__hold->__as_link(), this);
#else
__r = iterator(__hold->__as_link());
#endif
__hold.release();
iterator __e = __r;
#ifndef _LIBCPP_NO_EXCEPTIONS
try
{
#endif // _LIBCPP_NO_EXCEPTIONS
for (--__n; __n != 0; --__n, ++__e, ++__ds)
{
__hold.reset(__node_alloc_traits::allocate(__na, 1));
__node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), __x);
__e.__ptr_->__next_ = __hold->__as_link();
__hold->__prev_ = __e.__ptr_;
__hold.release();
}
#ifndef _LIBCPP_NO_EXCEPTIONS
}
catch (...)
{
while (true)
{
__node_alloc_traits::destroy(__na, _VSTD::addressof(*__e));
__link_pointer __prev = __e.__ptr_->__prev_;
__node_alloc_traits::deallocate(__na, __e.__ptr_->__as_node(), 1);
if (__prev == 0)
break;
#if _LIBCPP_DEBUG_LEVEL >= 2
__e = iterator(__prev, this);
#else
__e = iterator(__prev);
#endif
}
throw;
}
#endif // _LIBCPP_NO_EXCEPTIONS
__link_nodes(__p.__ptr_, __r.__ptr_, __e.__ptr_);
base::__sz() += __ds;
}
return __r;
}
template <class _Tp, class _Alloc>
template <class _InpIter>
typename list<_Tp, _Alloc>::iterator
list<_Tp, _Alloc>::insert(const_iterator __p, _InpIter __f, _InpIter __l,
typename enable_if<__is_input_iterator<_InpIter>::value>::type*)
{
#if _LIBCPP_DEBUG_LEVEL >= 2
_LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this,
"list::insert(iterator, range) called with an iterator not"
" referring to this list");
iterator __r(__p.__ptr_, this);
#else
iterator __r(__p.__ptr_);
#endif
if (__f != __l)
{
size_type __ds = 0;
__node_allocator& __na = base::__node_alloc();
__hold_pointer __hold = __allocate_node(__na);
__node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), *__f);
++__ds;
#if _LIBCPP_DEBUG_LEVEL >= 2
__r = iterator(__hold.get()->__as_link(), this);
#else
__r = iterator(__hold.get()->__as_link());
#endif
__hold.release();
iterator __e = __r;
#ifndef _LIBCPP_NO_EXCEPTIONS
try
{
#endif // _LIBCPP_NO_EXCEPTIONS
for (++__f; __f != __l; ++__f, (void) ++__e, (void) ++__ds)
{
__hold.reset(__node_alloc_traits::allocate(__na, 1));
__node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), *__f);
__e.__ptr_->__next_ = __hold.get()->__as_link();
__hold->__prev_ = __e.__ptr_;
__hold.release();
}
#ifndef _LIBCPP_NO_EXCEPTIONS
}
catch (...)
{
while (true)
{
__node_alloc_traits::destroy(__na, _VSTD::addressof(*__e));
__link_pointer __prev = __e.__ptr_->__prev_;
__node_alloc_traits::deallocate(__na, __e.__ptr_->__as_node(), 1);
if (__prev == 0)
break;
#if _LIBCPP_DEBUG_LEVEL >= 2
__e = iterator(__prev, this);
#else
__e = iterator(__prev);
#endif
}
throw;
}
#endif // _LIBCPP_NO_EXCEPTIONS
__link_nodes(__p.__ptr_, __r.__ptr_, __e.__ptr_);
base::__sz() += __ds;
}
return __r;
}
template <class _Tp, class _Alloc>
void
list<_Tp, _Alloc>::push_front(const value_type& __x)
{
__node_allocator& __na = base::__node_alloc();
__hold_pointer __hold = __allocate_node(__na);
__node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), __x);
__link_pointer __nl = __hold->__as_link();
__link_nodes_at_front(__nl, __nl);
++base::__sz();
__hold.release();
}
template <class _Tp, class _Alloc>
void
list<_Tp, _Alloc>::push_back(const value_type& __x)
{
__node_allocator& __na = base::__node_alloc();
__hold_pointer __hold = __allocate_node(__na);
__node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), __x);
__link_nodes_at_back(__hold.get()->__as_link(), __hold.get()->__as_link());
++base::__sz();
__hold.release();
}
#ifndef _LIBCPP_CXX03_LANG
template <class _Tp, class _Alloc>
void
list<_Tp, _Alloc>::push_front(value_type&& __x)
{
__node_allocator& __na = base::__node_alloc();
__hold_pointer __hold = __allocate_node(__na);
__node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), _VSTD::move(__x));
__link_nodes_at_front(__hold.get()->__as_link(), __hold.get()->__as_link());
++base::__sz();
__hold.release();
}
template <class _Tp, class _Alloc>
void
list<_Tp, _Alloc>::push_back(value_type&& __x)
{
__node_allocator& __na = base::__node_alloc();
__hold_pointer __hold = __allocate_node(__na);
__node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), _VSTD::move(__x));
__link_nodes_at_back(__hold.get()->__as_link(), __hold.get()->__as_link());
++base::__sz();
__hold.release();
}
template <class _Tp, class _Alloc>
template <class... _Args>
#if _LIBCPP_STD_VER > 14
typename list<_Tp, _Alloc>::reference
#else
void
#endif
list<_Tp, _Alloc>::emplace_front(_Args&&... __args)
{
__node_allocator& __na = base::__node_alloc();
__hold_pointer __hold = __allocate_node(__na);
__node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), _VSTD::forward<_Args>(__args)...);
__link_nodes_at_front(__hold.get()->__as_link(), __hold.get()->__as_link());
++base::__sz();
#if _LIBCPP_STD_VER > 14
return __hold.release()->__value_;
#else
__hold.release();
#endif
}
template <class _Tp, class _Alloc>
template <class... _Args>
#if _LIBCPP_STD_VER > 14
typename list<_Tp, _Alloc>::reference
#else
void
#endif
list<_Tp, _Alloc>::emplace_back(_Args&&... __args)
{
__node_allocator& __na = base::__node_alloc();
__hold_pointer __hold = __allocate_node(__na);
__node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), _VSTD::forward<_Args>(__args)...);
__link_pointer __nl = __hold->__as_link();
__link_nodes_at_back(__nl, __nl);
++base::__sz();
#if _LIBCPP_STD_VER > 14
return __hold.release()->__value_;
#else
__hold.release();
#endif
}
template <class _Tp, class _Alloc>
template <class... _Args>
typename list<_Tp, _Alloc>::iterator
list<_Tp, _Alloc>::emplace(const_iterator __p, _Args&&... __args)
{
#if _LIBCPP_DEBUG_LEVEL >= 2
_LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this,
"list::emplace(iterator, args...) called with an iterator not"
" referring to this list");
#endif
__node_allocator& __na = base::__node_alloc();
__hold_pointer __hold = __allocate_node(__na);
__node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), _VSTD::forward<_Args>(__args)...);
__link_pointer __nl = __hold.get()->__as_link();
__link_nodes(__p.__ptr_, __nl, __nl);
++base::__sz();
__hold.release();
#if _LIBCPP_DEBUG_LEVEL >= 2
return iterator(__nl, this);
#else
return iterator(__nl);
#endif
}
template <class _Tp, class _Alloc>
typename list<_Tp, _Alloc>::iterator
list<_Tp, _Alloc>::insert(const_iterator __p, value_type&& __x)
{
#if _LIBCPP_DEBUG_LEVEL >= 2
_LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this,
"list::insert(iterator, x) called with an iterator not"
" referring to this list");
#endif
__node_allocator& __na = base::__node_alloc();
__hold_pointer __hold = __allocate_node(__na);
__node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), _VSTD::move(__x));
__link_pointer __nl = __hold->__as_link();
__link_nodes(__p.__ptr_, __nl, __nl);
++base::__sz();
__hold.release();
#if _LIBCPP_DEBUG_LEVEL >= 2
return iterator(__nl, this);
#else
return iterator(__nl);
#endif
}
#endif // _LIBCPP_CXX03_LANG
template <class _Tp, class _Alloc>
void
list<_Tp, _Alloc>::pop_front()
{
_LIBCPP_ASSERT(!empty(), "list::pop_front() called with empty list");
__node_allocator& __na = base::__node_alloc();
__link_pointer __n = base::__end_.__next_;
base::__unlink_nodes(__n, __n);
--base::__sz();
#if _LIBCPP_DEBUG_LEVEL >= 2
__c_node* __c = __get_db()->__find_c_and_lock(this);
for (__i_node** __p = __c->end_; __p != __c->beg_; )
{
--__p;
iterator* __i = static_cast<iterator*>((*__p)->__i_);
if (__i->__ptr_ == __n)
{
(*__p)->__c_ = nullptr;
if (--__c->end_ != __p)
memmove(__p, __p+1, (__c->end_ - __p)*sizeof(__i_node*));
}
}
__get_db()->unlock();
#endif
__node_pointer __np = __n->__as_node();
__node_alloc_traits::destroy(__na, _VSTD::addressof(__np->__value_));
__node_alloc_traits::deallocate(__na, __np, 1);
}
template <class _Tp, class _Alloc>
void
list<_Tp, _Alloc>::pop_back()
{
_LIBCPP_ASSERT(!empty(), "list::pop_back() called with empty list");
__node_allocator& __na = base::__node_alloc();
__link_pointer __n = base::__end_.__prev_;
base::__unlink_nodes(__n, __n);
--base::__sz();
#if _LIBCPP_DEBUG_LEVEL >= 2
__c_node* __c = __get_db()->__find_c_and_lock(this);
for (__i_node** __p = __c->end_; __p != __c->beg_; )
{
--__p;
iterator* __i = static_cast<iterator*>((*__p)->__i_);
if (__i->__ptr_ == __n)
{
(*__p)->__c_ = nullptr;
if (--__c->end_ != __p)
memmove(__p, __p+1, (__c->end_ - __p)*sizeof(__i_node*));
}
}
__get_db()->unlock();
#endif
__node_pointer __np = __n->__as_node();
__node_alloc_traits::destroy(__na, _VSTD::addressof(__np->__value_));
__node_alloc_traits::deallocate(__na, __np, 1);
}
template <class _Tp, class _Alloc>
typename list<_Tp, _Alloc>::iterator
list<_Tp, _Alloc>::erase(const_iterator __p)
{
#if _LIBCPP_DEBUG_LEVEL >= 2
_LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this,
"list::erase(iterator) called with an iterator not"
" referring to this list");
#endif
_LIBCPP_ASSERT(__p != end(),
"list::erase(iterator) called with a non-dereferenceable iterator");
__node_allocator& __na = base::__node_alloc();
__link_pointer __n = __p.__ptr_;
__link_pointer __r = __n->__next_;
base::__unlink_nodes(__n, __n);
--base::__sz();
#if _LIBCPP_DEBUG_LEVEL >= 2
__c_node* __c = __get_db()->__find_c_and_lock(this);
for (__i_node** __ip = __c->end_; __ip != __c->beg_; )
{
--__ip;
iterator* __i = static_cast<iterator*>((*__ip)->__i_);
if (__i->__ptr_ == __n)
{
(*__ip)->__c_ = nullptr;
if (--__c->end_ != __ip)
memmove(__ip, __ip+1, (__c->end_ - __ip)*sizeof(__i_node*));
}
}
__get_db()->unlock();
#endif
__node_pointer __np = __n->__as_node();
__node_alloc_traits::destroy(__na, _VSTD::addressof(__np->__value_));
__node_alloc_traits::deallocate(__na, __np, 1);
#if _LIBCPP_DEBUG_LEVEL >= 2
return iterator(__r, this);
#else
return iterator(__r);
#endif
}
template <class _Tp, class _Alloc>
typename list<_Tp, _Alloc>::iterator
list<_Tp, _Alloc>::erase(const_iterator __f, const_iterator __l)
{
#if _LIBCPP_DEBUG_LEVEL >= 2
_LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__f) == this,
"list::erase(iterator, iterator) called with an iterator not"
" referring to this list");
_LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__l) == this,
"list::erase(iterator, iterator) called with an iterator not"
" referring to this list");
#endif
if (__f != __l)
{
__node_allocator& __na = base::__node_alloc();
base::__unlink_nodes(__f.__ptr_, __l.__ptr_->__prev_);
while (__f != __l)
{
__link_pointer __n = __f.__ptr_;
++__f;
--base::__sz();
#if _LIBCPP_DEBUG_LEVEL >= 2
__c_node* __c = __get_db()->__find_c_and_lock(this);
for (__i_node** __p = __c->end_; __p != __c->beg_; )
{
--__p;
iterator* __i = static_cast<iterator*>((*__p)->__i_);
if (__i->__ptr_ == __n)
{
(*__p)->__c_ = nullptr;
if (--__c->end_ != __p)
memmove(__p, __p+1, (__c->end_ - __p)*sizeof(__i_node*));
}
}
__get_db()->unlock();
#endif
__node_pointer __np = __n->__as_node();
__node_alloc_traits::destroy(__na, _VSTD::addressof(__np->__value_));
__node_alloc_traits::deallocate(__na, __np, 1);
}
}
#if _LIBCPP_DEBUG_LEVEL >= 2
return iterator(__l.__ptr_, this);
#else
return iterator(__l.__ptr_);
#endif
}
template <class _Tp, class _Alloc>
void
list<_Tp, _Alloc>::resize(size_type __n)
{
if (__n < base::__sz())
erase(__iterator(__n), end());
else if (__n > base::__sz())
{
__n -= base::__sz();
size_type __ds = 0;
__node_allocator& __na = base::__node_alloc();
__hold_pointer __hold = __allocate_node(__na);
__node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_));
++__ds;
#if _LIBCPP_DEBUG_LEVEL >= 2
iterator __r = iterator(__hold.release()->__as_link(), this);
#else
iterator __r = iterator(__hold.release()->__as_link());
#endif
iterator __e = __r;
#ifndef _LIBCPP_NO_EXCEPTIONS
try
{
#endif // _LIBCPP_NO_EXCEPTIONS
for (--__n; __n != 0; --__n, ++__e, ++__ds)
{
__hold.reset(__node_alloc_traits::allocate(__na, 1));
__node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_));
__e.__ptr_->__next_ = __hold.get()->__as_link();
__hold->__prev_ = __e.__ptr_;
__hold.release();
}
#ifndef _LIBCPP_NO_EXCEPTIONS
}
catch (...)
{
while (true)
{
__node_alloc_traits::destroy(__na, _VSTD::addressof(*__e));
__link_pointer __prev = __e.__ptr_->__prev_;
__node_alloc_traits::deallocate(__na, __e.__ptr_->__as_node(), 1);
if (__prev == 0)
break;
#if _LIBCPP_DEBUG_LEVEL >= 2
__e = iterator(__prev, this);
#else
__e = iterator(__prev);
#endif
}
throw;
}
#endif // _LIBCPP_NO_EXCEPTIONS
__link_nodes_at_back(__r.__ptr_, __e.__ptr_);
base::__sz() += __ds;
}
}
template <class _Tp, class _Alloc>
void
list<_Tp, _Alloc>::resize(size_type __n, const value_type& __x)
{
if (__n < base::__sz())
erase(__iterator(__n), end());
else if (__n > base::__sz())
{
__n -= base::__sz();
size_type __ds = 0;
__node_allocator& __na = base::__node_alloc();
__hold_pointer __hold = __allocate_node(__na);
__node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), __x);
++__ds;
__link_pointer __nl = __hold.release()->__as_link();
#if _LIBCPP_DEBUG_LEVEL >= 2
iterator __r = iterator(__nl, this);
#else
iterator __r = iterator(__nl);
#endif
iterator __e = __r;
#ifndef _LIBCPP_NO_EXCEPTIONS
try
{
#endif // _LIBCPP_NO_EXCEPTIONS
for (--__n; __n != 0; --__n, ++__e, ++__ds)
{
__hold.reset(__node_alloc_traits::allocate(__na, 1));
__node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), __x);
__e.__ptr_->__next_ = __hold.get()->__as_link();
__hold->__prev_ = __e.__ptr_;
__hold.release();
}
#ifndef _LIBCPP_NO_EXCEPTIONS
}
catch (...)
{
while (true)
{
__node_alloc_traits::destroy(__na, _VSTD::addressof(*__e));
__link_pointer __prev = __e.__ptr_->__prev_;
__node_alloc_traits::deallocate(__na, __e.__ptr_->__as_node(), 1);
if (__prev == 0)
break;
#if _LIBCPP_DEBUG_LEVEL >= 2
__e = iterator(__prev, this);
#else
__e = iterator(__prev);
#endif
}
throw;
}
#endif // _LIBCPP_NO_EXCEPTIONS
__link_nodes(base::__end_as_link(), __r.__ptr_, __e.__ptr_);
base::__sz() += __ds;
}
}
template <class _Tp, class _Alloc>
void
list<_Tp, _Alloc>::splice(const_iterator __p, list& __c)
{
_LIBCPP_ASSERT(this != &__c,
"list::splice(iterator, list) called with this == &list");
#if _LIBCPP_DEBUG_LEVEL >= 2
_LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this,
"list::splice(iterator, list) called with an iterator not"
" referring to this list");
#endif
if (!__c.empty())
{
__link_pointer __f = __c.__end_.__next_;
__link_pointer __l = __c.__end_.__prev_;
base::__unlink_nodes(__f, __l);
__link_nodes(__p.__ptr_, __f, __l);
base::__sz() += __c.__sz();
__c.__sz() = 0;
#if _LIBCPP_DEBUG_LEVEL >= 2
if (&__c != this) {
__libcpp_db* __db = __get_db();
__c_node* __cn1 = __db->__find_c_and_lock(this);
__c_node* __cn2 = __db->__find_c(&__c);
for (__i_node** __ip = __cn2->end_; __ip != __cn2->beg_;)
{
--__ip;
iterator* __i = static_cast<iterator*>((*__ip)->__i_);
if (__i->__ptr_ != __c.__end_as_link())
{
__cn1->__add(*__ip);
(*__ip)->__c_ = __cn1;
if (--__cn2->end_ != __ip)
memmove(__ip, __ip+1, (__cn2->end_ - __ip)*sizeof(__i_node*));
}
}
__db->unlock();
}
#endif
}
}
template <class _Tp, class _Alloc>
void
list<_Tp, _Alloc>::splice(const_iterator __p, list& __c, const_iterator __i)
{
#if _LIBCPP_DEBUG_LEVEL >= 2
_LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this,
"list::splice(iterator, list, iterator) called with first iterator not"
" referring to this list");
_LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__i) == &__c,
"list::splice(iterator, list, iterator) called with second iterator not"
" referring to list argument");
_LIBCPP_ASSERT(__get_const_db()->__dereferenceable(&__i),
"list::splice(iterator, list, iterator) called with second iterator not"
" derefereceable");
#endif
if (__p.__ptr_ != __i.__ptr_ && __p.__ptr_ != __i.__ptr_->__next_)
{
__link_pointer __f = __i.__ptr_;
base::__unlink_nodes(__f, __f);
__link_nodes(__p.__ptr_, __f, __f);
--__c.__sz();
++base::__sz();
#if _LIBCPP_DEBUG_LEVEL >= 2
if (&__c != this) {
__libcpp_db* __db = __get_db();
__c_node* __cn1 = __db->__find_c_and_lock(this);
__c_node* __cn2 = __db->__find_c(&__c);
for (__i_node** __ip = __cn2->end_; __ip != __cn2->beg_;)
{
--__ip;
iterator* __j = static_cast<iterator*>((*__ip)->__i_);
if (__j->__ptr_ == __f)
{
__cn1->__add(*__ip);
(*__ip)->__c_ = __cn1;
if (--__cn2->end_ != __ip)
memmove(__ip, __ip+1, (__cn2->end_ - __ip)*sizeof(__i_node*));
}
}
__db->unlock();
}
#endif
}
}
template <class _Tp, class _Alloc>
void
list<_Tp, _Alloc>::splice(const_iterator __p, list& __c, const_iterator __f, const_iterator __l)
{
#if _LIBCPP_DEBUG_LEVEL >= 2
_LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this,
"list::splice(iterator, list, iterator, iterator) called with first iterator not"
" referring to this list");
_LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__f) == &__c,
"list::splice(iterator, list, iterator, iterator) called with second iterator not"
" referring to list argument");
if (this == &__c)
{
for (const_iterator __i = __f; __i != __l; ++__i)
_LIBCPP_ASSERT(__i != __p,
"list::splice(iterator, list, iterator, iterator)"
" called with the first iterator within the range"
" of the second and third iterators");
}
#endif
if (__f != __l)
{
__link_pointer __first = __f.__ptr_;
--__l;
__link_pointer __last = __l.__ptr_;
if (this != &__c)
{
size_type __s = _VSTD::distance(__f, __l) + 1;
__c.__sz() -= __s;
base::__sz() += __s;
}
base::__unlink_nodes(__first, __last);
__link_nodes(__p.__ptr_, __first, __last);
#if _LIBCPP_DEBUG_LEVEL >= 2
if (&__c != this) {
__libcpp_db* __db = __get_db();
__c_node* __cn1 = __db->__find_c_and_lock(this);
__c_node* __cn2 = __db->__find_c(&__c);
for (__i_node** __ip = __cn2->end_; __ip != __cn2->beg_;)
{
--__ip;
iterator* __j = static_cast<iterator*>((*__ip)->__i_);
for (__link_pointer __k = __f.__ptr_;
__k != __l.__ptr_; __k = __k->__next_)
{
if (__j->__ptr_ == __k)
{
__cn1->__add(*__ip);
(*__ip)->__c_ = __cn1;
if (--__cn2->end_ != __ip)
memmove(__ip, __ip+1, (__cn2->end_ - __ip)*sizeof(__i_node*));
}
}
}
__db->unlock();
}
#endif
}
}
template <class _Tp, class _Alloc>
typename list<_Tp, _Alloc>::__remove_return_type
list<_Tp, _Alloc>::remove(const value_type& __x)
{
list<_Tp, _Alloc> __deleted_nodes(get_allocator()); // collect the nodes we're removing
for (const_iterator __i = begin(), __e = end(); __i != __e;)
{
if (*__i == __x)
{
const_iterator __j = _VSTD::next(__i);
for (; __j != __e && *__j == __x; ++__j)
;
__deleted_nodes.splice(__deleted_nodes.end(), *this, __i, __j);
__i = __j;
if (__i != __e)
++__i;
}
else
++__i;
}
return (__remove_return_type) __deleted_nodes.size();
}
template <class _Tp, class _Alloc>
template <class _Pred>
typename list<_Tp, _Alloc>::__remove_return_type
list<_Tp, _Alloc>::remove_if(_Pred __pred)
{
list<_Tp, _Alloc> __deleted_nodes(get_allocator()); // collect the nodes we're removing
for (iterator __i = begin(), __e = end(); __i != __e;)
{
if (__pred(*__i))
{
iterator __j = _VSTD::next(__i);
for (; __j != __e && __pred(*__j); ++__j)
;
__deleted_nodes.splice(__deleted_nodes.end(), *this, __i, __j);
__i = __j;
if (__i != __e)
++__i;
}
else
++__i;
}
return (__remove_return_type) __deleted_nodes.size();
}
template <class _Tp, class _Alloc>
template <class _BinaryPred>
typename list<_Tp, _Alloc>::__remove_return_type
list<_Tp, _Alloc>::unique(_BinaryPred __binary_pred)
{
list<_Tp, _Alloc> __deleted_nodes(get_allocator()); // collect the nodes we're removing
for (iterator __i = begin(), __e = end(); __i != __e;)
{
iterator __j = _VSTD::next(__i);
for (; __j != __e && __binary_pred(*__i, *__j); ++__j)
;
if (++__i != __j) {
__deleted_nodes.splice(__deleted_nodes.end(), *this, __i, __j);
__i = __j;
}
}
return (__remove_return_type) __deleted_nodes.size();
}
template <class _Tp, class _Alloc>
inline
void
list<_Tp, _Alloc>::merge(list& __c)
{
merge(__c, __less<value_type>());
}
template <class _Tp, class _Alloc>
template <class _Comp>
void
list<_Tp, _Alloc>::merge(list& __c, _Comp __comp)
{
if (this != _VSTD::addressof(__c))
{
iterator __f1 = begin();
iterator __e1 = end();
iterator __f2 = __c.begin();
iterator __e2 = __c.end();
while (__f1 != __e1 && __f2 != __e2)
{
if (__comp(*__f2, *__f1))
{
size_type __ds = 1;
iterator __m2 = _VSTD::next(__f2);
for (; __m2 != __e2 && __comp(*__m2, *__f1); ++__m2, ++__ds)
;
base::__sz() += __ds;
__c.__sz() -= __ds;
__link_pointer __f = __f2.__ptr_;
__link_pointer __l = __m2.__ptr_->__prev_;
__f2 = __m2;
base::__unlink_nodes(__f, __l);
__m2 = _VSTD::next(__f1);
__link_nodes(__f1.__ptr_, __f, __l);
__f1 = __m2;
}
else
++__f1;
}
splice(__e1, __c);
#if _LIBCPP_DEBUG_LEVEL >= 2
__libcpp_db* __db = __get_db();
__c_node* __cn1 = __db->__find_c_and_lock(this);
__c_node* __cn2 = __db->__find_c(&__c);
for (__i_node** __p = __cn2->end_; __p != __cn2->beg_;)
{
--__p;
iterator* __i = static_cast<iterator*>((*__p)->__i_);
if (__i->__ptr_ != __c.__end_as_link())
{
__cn1->__add(*__p);
(*__p)->__c_ = __cn1;
if (--__cn2->end_ != __p)
memmove(__p, __p+1, (__cn2->end_ - __p)*sizeof(__i_node*));
}
}
__db->unlock();
#endif
}
}
template <class _Tp, class _Alloc>
inline
void
list<_Tp, _Alloc>::sort()
{
sort(__less<value_type>());
}
template <class _Tp, class _Alloc>
template <class _Comp>
inline
void
list<_Tp, _Alloc>::sort(_Comp __comp)
{
__sort(begin(), end(), base::__sz(), __comp);
}
template <class _Tp, class _Alloc>
template <class _Comp>
typename list<_Tp, _Alloc>::iterator
list<_Tp, _Alloc>::__sort(iterator __f1, iterator __e2, size_type __n, _Comp& __comp)
{
switch (__n)
{
case 0:
case 1:
return __f1;
case 2:
if (__comp(*--__e2, *__f1))
{
__link_pointer __f = __e2.__ptr_;
base::__unlink_nodes(__f, __f);
__link_nodes(__f1.__ptr_, __f, __f);
return __e2;
}
return __f1;
}
size_type __n2 = __n / 2;
iterator __e1 = _VSTD::next(__f1, __n2);
iterator __r = __f1 = __sort(__f1, __e1, __n2, __comp);
iterator __f2 = __e1 = __sort(__e1, __e2, __n - __n2, __comp);
if (__comp(*__f2, *__f1))
{
iterator __m2 = _VSTD::next(__f2);
for (; __m2 != __e2 && __comp(*__m2, *__f1); ++__m2)
;
__link_pointer __f = __f2.__ptr_;
__link_pointer __l = __m2.__ptr_->__prev_;
__r = __f2;
__e1 = __f2 = __m2;
base::__unlink_nodes(__f, __l);
__m2 = _VSTD::next(__f1);
__link_nodes(__f1.__ptr_, __f, __l);
__f1 = __m2;
}
else
++__f1;
while (__f1 != __e1 && __f2 != __e2)
{
if (__comp(*__f2, *__f1))
{
iterator __m2 = _VSTD::next(__f2);
for (; __m2 != __e2 && __comp(*__m2, *__f1); ++__m2)
;
__link_pointer __f = __f2.__ptr_;
__link_pointer __l = __m2.__ptr_->__prev_;
if (__e1 == __f2)
__e1 = __m2;
__f2 = __m2;
base::__unlink_nodes(__f, __l);
__m2 = _VSTD::next(__f1);
__link_nodes(__f1.__ptr_, __f, __l);
__f1 = __m2;
}
else
++__f1;
}
return __r;
}
template <class _Tp, class _Alloc>
void
list<_Tp, _Alloc>::reverse() _NOEXCEPT
{
if (base::__sz() > 1)
{
iterator __e = end();
for (iterator __i = begin(); __i.__ptr_ != __e.__ptr_;)
{
_VSTD::swap(__i.__ptr_->__prev_, __i.__ptr_->__next_);
__i.__ptr_ = __i.__ptr_->__prev_;
}
_VSTD::swap(__e.__ptr_->__prev_, __e.__ptr_->__next_);
}
}
template <class _Tp, class _Alloc>
bool
list<_Tp, _Alloc>::__invariants() const
{
return size() == _VSTD::distance(begin(), end());
}
#if _LIBCPP_DEBUG_LEVEL >= 2
template <class _Tp, class _Alloc>
bool
list<_Tp, _Alloc>::__dereferenceable(const const_iterator* __i) const
{
return __i->__ptr_ != this->__end_as_link();
}
template <class _Tp, class _Alloc>
bool
list<_Tp, _Alloc>::__decrementable(const const_iterator* __i) const
{
return !empty() && __i->__ptr_ != base::__end_.__next_;
}
template <class _Tp, class _Alloc>
bool
list<_Tp, _Alloc>::__addable(const const_iterator*, ptrdiff_t) const
{
return false;
}
template <class _Tp, class _Alloc>
bool
list<_Tp, _Alloc>::__subscriptable(const const_iterator*, ptrdiff_t) const
{
return false;
}
#endif // _LIBCPP_DEBUG_LEVEL >= 2
template <class _Tp, class _Alloc>
inline _LIBCPP_INLINE_VISIBILITY
bool
operator==(const list<_Tp, _Alloc>& __x, const list<_Tp, _Alloc>& __y)
{
return __x.size() == __y.size() && _VSTD::equal(__x.begin(), __x.end(), __y.begin());
}
template <class _Tp, class _Alloc>
inline _LIBCPP_INLINE_VISIBILITY
bool
operator< (const list<_Tp, _Alloc>& __x, const list<_Tp, _Alloc>& __y)
{
return _VSTD::lexicographical_compare(__x.begin(), __x.end(), __y.begin(), __y.end());
}
template <class _Tp, class _Alloc>
inline _LIBCPP_INLINE_VISIBILITY
bool
operator!=(const list<_Tp, _Alloc>& __x, const list<_Tp, _Alloc>& __y)
{
return !(__x == __y);
}
template <class _Tp, class _Alloc>
inline _LIBCPP_INLINE_VISIBILITY
bool
operator> (const list<_Tp, _Alloc>& __x, const list<_Tp, _Alloc>& __y)
{
return __y < __x;
}
template <class _Tp, class _Alloc>
inline _LIBCPP_INLINE_VISIBILITY
bool
operator>=(const list<_Tp, _Alloc>& __x, const list<_Tp, _Alloc>& __y)
{
return !(__x < __y);
}
template <class _Tp, class _Alloc>
inline _LIBCPP_INLINE_VISIBILITY
bool
operator<=(const list<_Tp, _Alloc>& __x, const list<_Tp, _Alloc>& __y)
{
return !(__y < __x);
}
template <class _Tp, class _Alloc>
inline _LIBCPP_INLINE_VISIBILITY
void
swap(list<_Tp, _Alloc>& __x, list<_Tp, _Alloc>& __y)
_NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
{
__x.swap(__y);
}
#if _LIBCPP_STD_VER > 17
template <class _Tp, class _Allocator, class _Predicate>
inline _LIBCPP_INLINE_VISIBILITY
void erase_if(list<_Tp, _Allocator>& __c, _Predicate __pred)
{ __c.remove_if(__pred); }
template <class _Tp, class _Allocator, class _Up>
inline _LIBCPP_INLINE_VISIBILITY
void erase(list<_Tp, _Allocator>& __c, const _Up& __v)
{ _VSTD::erase_if(__c, [&](auto& __elem) { return __elem == __v; }); }
#endif
_LIBCPP_END_NAMESPACE_STD
_LIBCPP_POP_MACROS
#endif // _LIBCPP_LIST
| 80,318 | 2,489 | jart/cosmopolitan | false |
cosmopolitan/third_party/libcxx/cwctype | // -*- C++ -*-
//===--------------------------- cwctype ----------------------------------===//
//
// 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_CWCTYPE
#define _LIBCPP_CWCTYPE
/*
cwctype synopsis
Macros:
WEOF
namespace std
{
Types:
wint_t
wctrans_t
wctype_t
int iswalnum(wint_t wc);
int iswalpha(wint_t wc);
int iswblank(wint_t wc); // C99
int iswcntrl(wint_t wc);
int iswdigit(wint_t wc);
int iswgraph(wint_t wc);
int iswlower(wint_t wc);
int iswprint(wint_t wc);
int iswpunct(wint_t wc);
int iswspace(wint_t wc);
int iswupper(wint_t wc);
int iswxdigit(wint_t wc);
int iswctype(wint_t wc, wctype_t desc);
wctype_t wctype(const char* property);
wint_t towlower(wint_t wc);
wint_t towupper(wint_t wc);
wint_t towctrans(wint_t wc, wctrans_t desc);
wctrans_t wctrans(const char* property);
} // std
*/
#include "third_party/libcxx/__config"
#include "third_party/libcxx/cctype"
#include "third_party/libcxx/wctype.h"
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
#pragma GCC system_header
#endif
_LIBCPP_BEGIN_NAMESPACE_STD
using ::wint_t;
using ::wctrans_t;
using ::wctype_t;
using ::iswalnum;
using ::iswalpha;
using ::iswblank;
using ::iswcntrl;
using ::iswdigit;
using ::iswgraph;
using ::iswlower;
using ::iswprint;
using ::iswpunct;
using ::iswspace;
using ::iswupper;
using ::iswxdigit;
using ::iswctype;
using ::wctype;
using ::towlower;
using ::towupper;
using ::towctrans;
using ::wctrans;
_LIBCPP_END_NAMESPACE_STD
#endif // _LIBCPP_CWCTYPE
| 1,748 | 87 | jart/cosmopolitan | false |
cosmopolitan/third_party/libcxx/experimental/__config | // -*- C++ -*-
// clang-format off
//===--------------------------- __config ---------------------------------===//
//
// 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_EXPERIMENTAL_CONFIG
#define _LIBCPP_EXPERIMENTAL_CONFIG
#include "third_party/libcxx/__config"
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
#pragma GCC system_header
#endif
#define _LIBCPP_BEGIN_NAMESPACE_EXPERIMENTAL namespace std { namespace experimental {
#define _LIBCPP_END_NAMESPACE_EXPERIMENTAL } }
#define _VSTD_EXPERIMENTAL std::experimental
#define _LIBCPP_BEGIN_NAMESPACE_LFTS _LIBCPP_BEGIN_NAMESPACE_EXPERIMENTAL inline namespace fundamentals_v1 {
#define _LIBCPP_END_NAMESPACE_LFTS } } }
#define _VSTD_LFTS _VSTD_EXPERIMENTAL::fundamentals_v1
#define _LIBCPP_BEGIN_NAMESPACE_LFTS_V2 _LIBCPP_BEGIN_NAMESPACE_EXPERIMENTAL inline namespace fundamentals_v2 {
#define _LIBCPP_END_NAMESPACE_LFTS_V2 } } }
#define _VSTD_LFTS_V2 _VSTD_EXPERIMENTAL::fundamentals_v2
#define _LIBCPP_BEGIN_NAMESPACE_LFTS_PMR _LIBCPP_BEGIN_NAMESPACE_LFTS namespace pmr {
#define _LIBCPP_END_NAMESPACE_LFTS_PMR _LIBCPP_END_NAMESPACE_LFTS }
#define _VSTD_LFTS_PMR _VSTD_LFTS::pmr
#define _LIBCPP_BEGIN_NAMESPACE_CHRONO_LFTS _LIBCPP_BEGIN_NAMESPACE_STD \
namespace chrono { namespace experimental { inline namespace fundamentals_v1 {
#define _LIBCPP_END_NAMESPACE_CHRONO_LFTS _LIBCPP_END_NAMESPACE_STD } } }
#if defined(_LIBCPP_NO_EXPERIMENTAL_DEPRECATION_WARNING_FILESYSTEM)
# define _LIBCPP_DEPRECATED_EXPERIMENTAL_FILESYSTEM /* nothing */
#else
# define _LIBCPP_DEPRECATED_EXPERIMENTAL_FILESYSTEM __attribute__((deprecated("std::experimental::filesystem has now been deprecated in favor of C++17's std::filesystem. Please stop using it and start using std::filesystem. This experimental version will be removed in LLVM 11. You can remove this warning by defining the _LIBCPP_NO_EXPERIMENTAL_DEPRECATION_WARNING_FILESYSTEM macro.")))
#endif
#define _LIBCPP_BEGIN_NAMESPACE_EXPERIMENTAL_FILESYSTEM \
_LIBCPP_BEGIN_NAMESPACE_EXPERIMENTAL namespace filesystem _LIBCPP_DEPRECATED_EXPERIMENTAL_FILESYSTEM { \
inline namespace v1 {
#define _LIBCPP_END_NAMESPACE_EXPERIMENTAL_FILESYSTEM \
} } _LIBCPP_END_NAMESPACE_EXPERIMENTAL
#define _LIBCPP_BEGIN_NAMESPACE_EXPERIMENTAL_COROUTINES \
_LIBCPP_BEGIN_NAMESPACE_EXPERIMENTAL inline namespace coroutines_v1 {
#define _LIBCPP_END_NAMESPACE_EXPERIMENTAL_COROUTINES \
} _LIBCPP_END_NAMESPACE_EXPERIMENTAL
#define _VSTD_CORO _VSTD_EXPERIMENTAL::coroutines_v1
#define _LIBCPP_BEGIN_NAMESPACE_EXPERIMENTAL_SIMD \
_LIBCPP_BEGIN_NAMESPACE_EXPERIMENTAL inline namespace parallelism_v2 {
#define _LIBCPP_END_NAMESPACE_EXPERIMENTAL_SIMD \
} _LIBCPP_END_NAMESPACE_EXPERIMENTAL
#define _LIBCPP_BEGIN_NAMESPACE_EXPERIMENTAL_SIMD_ABI \
_LIBCPP_BEGIN_NAMESPACE_EXPERIMENTAL_SIMD namespace simd_abi {
#define _LIBCPP_END_NAMESPACE_EXPERIMENTAL_SIMD_ABI \
} _LIBCPP_END_NAMESPACE_EXPERIMENTAL_SIMD
// TODO: support more targets
#if defined(__AVX__)
#define _LIBCPP_NATIVE_SIMD_WIDTH_IN_BYTES 32
#else
#define _LIBCPP_NATIVE_SIMD_WIDTH_IN_BYTES 16
#endif
#endif
| 3,360 | 81 | jart/cosmopolitan | false |
cosmopolitan/third_party/libcxx/include/atomic_support.hh | // clang-format off
//===----------------------------------------------------------------------===////
//
// 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 ATOMIC_SUPPORT_H
#define ATOMIC_SUPPORT_H
#include "third_party/libcxx/__config"
#include "third_party/libcxx/memory" // for __libcpp_relaxed_loa"
#if defined(__clang__) && __has_builtin(__atomic_load_n) \
&& __has_builtin(__atomic_store_n) \
&& __has_builtin(__atomic_add_fetch) \
&& __has_builtin(__atomic_exchange_n) \
&& __has_builtin(__atomic_compare_exchange_n) \
&& defined(__ATOMIC_RELAXED) \
&& defined(__ATOMIC_CONSUME) \
&& defined(__ATOMIC_ACQUIRE) \
&& defined(__ATOMIC_RELEASE) \
&& defined(__ATOMIC_ACQ_REL) \
&& defined(__ATOMIC_SEQ_CST)
# define _LIBCPP_HAS_ATOMIC_BUILTINS
#elif !defined(__clang__) && defined(_GNUC_VER) && _GNUC_VER >= 407
# define _LIBCPP_HAS_ATOMIC_BUILTINS
#endif
#if !defined(_LIBCPP_HAS_ATOMIC_BUILTINS) && !defined(_LIBCPP_HAS_NO_THREADS)
# if defined(_LIBCPP_WARNING)
_LIBCPP_WARNING("Building libc++ without __atomic builtins is unsupported")
# else
# warning Building libc++ without __atomic builtins is unsupported
# endif
#endif
_LIBCPP_BEGIN_NAMESPACE_STD
namespace {
#if defined(_LIBCPP_HAS_ATOMIC_BUILTINS) && !defined(_LIBCPP_HAS_NO_THREADS)
enum __libcpp_atomic_order {
_AO_Relaxed = __ATOMIC_RELAXED,
_AO_Consume = __ATOMIC_CONSUME,
_AO_Acquire = __ATOMIC_ACQUIRE,
_AO_Release = __ATOMIC_RELEASE,
_AO_Acq_Rel = __ATOMIC_ACQ_REL,
_AO_Seq = __ATOMIC_SEQ_CST
};
template <class _ValueType, class _FromType>
inline _LIBCPP_INLINE_VISIBILITY
void __libcpp_atomic_store(_ValueType* __dest, _FromType __val,
int __order = _AO_Seq)
{
__atomic_store_n(__dest, __val, __order);
}
template <class _ValueType, class _FromType>
inline _LIBCPP_INLINE_VISIBILITY
void __libcpp_relaxed_store(_ValueType* __dest, _FromType __val)
{
__atomic_store_n(__dest, __val, _AO_Relaxed);
}
template <class _ValueType>
inline _LIBCPP_INLINE_VISIBILITY
_ValueType __libcpp_atomic_load(_ValueType const* __val,
int __order = _AO_Seq)
{
return __atomic_load_n(__val, __order);
}
template <class _ValueType, class _AddType>
inline _LIBCPP_INLINE_VISIBILITY
_ValueType __libcpp_atomic_add(_ValueType* __val, _AddType __a,
int __order = _AO_Seq)
{
return __atomic_add_fetch(__val, __a, __order);
}
template <class _ValueType>
inline _LIBCPP_INLINE_VISIBILITY
_ValueType __libcpp_atomic_exchange(_ValueType* __target,
_ValueType __value, int __order = _AO_Seq)
{
return __atomic_exchange_n(__target, __value, __order);
}
template <class _ValueType>
inline _LIBCPP_INLINE_VISIBILITY
bool __libcpp_atomic_compare_exchange(_ValueType* __val,
_ValueType* __expected, _ValueType __after,
int __success_order = _AO_Seq,
int __fail_order = _AO_Seq)
{
return __atomic_compare_exchange_n(__val, __expected, __after, true,
__success_order, __fail_order);
}
#else // _LIBCPP_HAS_NO_THREADS
enum __libcpp_atomic_order {
_AO_Relaxed,
_AO_Consume,
_AO_Acquire,
_AO_Release,
_AO_Acq_Rel,
_AO_Seq
};
template <class _ValueType, class _FromType>
inline _LIBCPP_INLINE_VISIBILITY
void __libcpp_atomic_store(_ValueType* __dest, _FromType __val,
int = 0)
{
*__dest = __val;
}
template <class _ValueType, class _FromType>
inline _LIBCPP_INLINE_VISIBILITY
void __libcpp_relaxed_store(_ValueType* __dest, _FromType __val)
{
*__dest = __val;
}
template <class _ValueType>
inline _LIBCPP_INLINE_VISIBILITY
_ValueType __libcpp_atomic_load(_ValueType const* __val,
int = 0)
{
return *__val;
}
template <class _ValueType, class _AddType>
inline _LIBCPP_INLINE_VISIBILITY
_ValueType __libcpp_atomic_add(_ValueType* __val, _AddType __a,
int = 0)
{
return *__val += __a;
}
template <class _ValueType>
inline _LIBCPP_INLINE_VISIBILITY
_ValueType __libcpp_atomic_exchange(_ValueType* __target,
_ValueType __value, int __order = _AO_Seq)
{
_ValueType old = *__target;
*__target = __value;
return old;
}
template <class _ValueType>
inline _LIBCPP_INLINE_VISIBILITY
bool __libcpp_atomic_compare_exchange(_ValueType* __val,
_ValueType* __expected, _ValueType __after,
int = 0, int = 0)
{
if (*__val == *__expected) {
*__val = __after;
return true;
}
*__expected = *__val;
return false;
}
#endif // _LIBCPP_HAS_NO_THREADS
} // end namespace
_LIBCPP_END_NAMESPACE_STD
#endif // ATOMIC_SUPPORT_H
| 5,313 | 178 | jart/cosmopolitan | false |
cosmopolitan/third_party/libcxx/include/config_elast.hh | // clang-format off
//===----------------------- config_elast.h -------------------------------===//
//
// 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_CONFIG_ELAST
#define _LIBCPP_CONFIG_ELAST
#include "third_party/libcxx/__config"
#if defined(ELAST)
#define _LIBCPP_ELAST ELAST
#elif defined(_NEWLIB_VERSION)
#define _LIBCPP_ELAST __ELASTERROR
#elif defined(__Fuchsia__)
// No _LIBCPP_ELAST needed on Fuchsia
#elif defined(__wasi__)
// No _LIBCPP_ELAST needed on WASI
#elif defined(__linux__) || defined(_LIBCPP_HAS_MUSL_LIBC)
#define _LIBCPP_ELAST 4095
#elif defined(__APPLE__)
// No _LIBCPP_ELAST needed on Apple
#elif defined(__sun__)
#define _LIBCPP_ELAST ESTALE
#elif defined(_LIBCPP_MSVCRT_LIKE)
#define _LIBCPP_ELAST (_sys_nerr - 1)
#else
// Warn here so that the person doing the libcxx port has an easier time:
#warning ELAST for this platform not yet implemented
#endif
#endif // _LIBCPP_CONFIG_ELAST
| 1,170 | 37 | jart/cosmopolitan | false |
cosmopolitan/third_party/xed/eamode.c | /*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-â
âvi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :viâ
ââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââ¡
â Copyright 2021 Justine Alexandra Roberts Tunney â
â â
â Permission to use, copy, modify, and/or distribute this software for â
â any purpose with or without fee is hereby granted, provided that the â
â above copyright notice and this permission notice appear in all copies. â
â â
â THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL â
â WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED â
â WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE â
â AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL â
â DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR â
â PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER â
â TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR â
â PERFORMANCE OF THIS SOFTWARE. â
ââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââ*/
#include "third_party/xed/x86.h"
const uint8_t kXedEamode[2][3] = {
[0][XED_MODE_REAL] = XED_MODE_REAL,
[0][XED_MODE_LEGACY] = XED_MODE_LEGACY,
[0][XED_MODE_LONG] = XED_MODE_LONG,
[1][XED_MODE_REAL] = XED_MODE_LEGACY,
[1][XED_MODE_LEGACY] = XED_MODE_REAL,
[1][XED_MODE_LONG] = XED_MODE_LEGACY,
};
| 2,158 | 29 | jart/cosmopolitan | false |
cosmopolitan/third_party/xed/x86isa.h | #ifndef COSMOPOLITAN_THIRD_PARTY_XED_X86ISA_H_
#define COSMOPOLITAN_THIRD_PARTY_XED_X86ISA_H_
#include "third_party/xed/x86.h"
#if !(__ASSEMBLER__ + __LINKER__ + 0)
COSMOPOLITAN_C_START_
#define XED_CHIP_INVALID 1
#define XED_CHIP_I86 2
#define XED_CHIP_I86FP 3
#define XED_CHIP_I186 4
#define XED_CHIP_I186FP 5
#define XED_CHIP_I286REAL 6
#define XED_CHIP_I286 7
#define XED_CHIP_I2186FP 8
#define XED_CHIP_I386REAL 9
#define XED_CHIP_I386 10
#define XED_CHIP_I386FP 11
#define XED_CHIP_I486REAL 12
#define XED_CHIP_I486 13
#define XED_CHIP_PENTIUMREAL 14
#define XED_CHIP_PENTIUM 15
#define XED_CHIP_QUARK 16
#define XED_CHIP_PENTIUMMMXREAL 17
#define XED_CHIP_PENTIUMMMX 18
#define XED_CHIP_ALLREAL 19
#define XED_CHIP_PENTIUMPRO 20
#define XED_CHIP_PENTIUM2 21
#define XED_CHIP_PENTIUM3 22
#define XED_CHIP_PENTIUM4 23
#define XED_CHIP_P4PRESCOTT 24
#define XED_CHIP_P4PRESCOTT_NOLAHF 25
#define XED_CHIP_P4PRESCOTT_VTX 26
#define XED_CHIP_CORE2 27
#define XED_CHIP_PENRYN 28
#define XED_CHIP_PENRYN_E 29
#define XED_CHIP_NEHALEM 30
#define XED_CHIP_WESTMERE 31
#define XED_CHIP_BONNELL 32
#define XED_CHIP_SALTWELL 33
#define XED_CHIP_SILVERMONT 34
#define XED_CHIP_AMD 35
#define XED_CHIP_GOLDMONT 36
#define XED_CHIP_GOLDMONT_PLUS 37
#define XED_CHIP_TREMONT 38
#define XED_CHIP_SANDYBRIDGE 39
#define XED_CHIP_IVYBRIDGE 40
#define XED_CHIP_HASWELL 41
#define XED_CHIP_BROADWELL 42
#define XED_CHIP_SKYLAKE 43
#define XED_CHIP_SKYLAKE_SERVER 44
#define XED_CHIP_CASCADE_LAKE 45
#define XED_CHIP_KNL 46
#define XED_CHIP_KNM 47
#define XED_CHIP_CANNONLAKE 48
#define XED_CHIP_ICELAKE 49
#define XED_CHIP_ICELAKE_SERVER 50
#define XED_CHIP_FUTURE 51
#define XED_CHIP_ALL 52
#define XED_CHIP_LAST 53
#define XED_ISA_SET_INVALID 0
#define XED_ISA_SET_3DNOW 1
#define XED_ISA_SET_ADOX_ADCX 2
#define XED_ISA_SET_AES 3
#define XED_ISA_SET_AMD 4
#define XED_ISA_SET_AVX 5
#define XED_ISA_SET_AVX2 6
#define XED_ISA_SET_AVX2GATHER 7
#define XED_ISA_SET_AVX512BW_128 8
#define XED_ISA_SET_AVX512BW_128N 9
#define XED_ISA_SET_AVX512BW_256 10
#define XED_ISA_SET_AVX512BW_512 11
#define XED_ISA_SET_AVX512BW_KOP 12
#define XED_ISA_SET_AVX512CD_128 13
#define XED_ISA_SET_AVX512CD_256 14
#define XED_ISA_SET_AVX512CD_512 15
#define XED_ISA_SET_AVX512DQ_128 16
#define XED_ISA_SET_AVX512DQ_128N 17
#define XED_ISA_SET_AVX512DQ_256 18
#define XED_ISA_SET_AVX512DQ_512 19
#define XED_ISA_SET_AVX512DQ_KOP 20
#define XED_ISA_SET_AVX512DQ_SCALAR 21
#define XED_ISA_SET_AVX512ER_512 22
#define XED_ISA_SET_AVX512ER_SCALAR 23
#define XED_ISA_SET_AVX512F_128 24
#define XED_ISA_SET_AVX512F_128N 25
#define XED_ISA_SET_AVX512F_256 26
#define XED_ISA_SET_AVX512F_512 27
#define XED_ISA_SET_AVX512F_KOP 28
#define XED_ISA_SET_AVX512F_SCALAR 29
#define XED_ISA_SET_AVX512PF_512 30
#define XED_ISA_SET_AVX512_4FMAPS_512 31
#define XED_ISA_SET_AVX512_4FMAPS_SCALAR 32
#define XED_ISA_SET_AVX512_4VNNIW_512 33
#define XED_ISA_SET_AVX512_BITALG_128 34
#define XED_ISA_SET_AVX512_BITALG_256 35
#define XED_ISA_SET_AVX512_BITALG_512 36
#define XED_ISA_SET_AVX512_GFNI_128 37
#define XED_ISA_SET_AVX512_GFNI_256 38
#define XED_ISA_SET_AVX512_GFNI_512 39
#define XED_ISA_SET_AVX512_IFMA_128 40
#define XED_ISA_SET_AVX512_IFMA_256 41
#define XED_ISA_SET_AVX512_IFMA_512 42
#define XED_ISA_SET_AVX512_VAES_128 43
#define XED_ISA_SET_AVX512_VAES_256 44
#define XED_ISA_SET_AVX512_VAES_512 45
#define XED_ISA_SET_AVX512_VBMI2_128 46
#define XED_ISA_SET_AVX512_VBMI2_256 47
#define XED_ISA_SET_AVX512_VBMI2_512 48
#define XED_ISA_SET_AVX512_VBMI_128 49
#define XED_ISA_SET_AVX512_VBMI_256 50
#define XED_ISA_SET_AVX512_VBMI_512 51
#define XED_ISA_SET_AVX512_VNNI_128 52
#define XED_ISA_SET_AVX512_VNNI_256 53
#define XED_ISA_SET_AVX512_VNNI_512 54
#define XED_ISA_SET_AVX512_VPCLMULQDQ_128 55
#define XED_ISA_SET_AVX512_VPCLMULQDQ_256 56
#define XED_ISA_SET_AVX512_VPCLMULQDQ_512 57
#define XED_ISA_SET_AVX512_VPOPCNTDQ_128 58
#define XED_ISA_SET_AVX512_VPOPCNTDQ_256 59
#define XED_ISA_SET_AVX512_VPOPCNTDQ_512 60
#define XED_ISA_SET_AVXAES 61
#define XED_ISA_SET_AVX_GFNI 62
#define XED_ISA_SET_BMI1 63
#define XED_ISA_SET_BMI2 64
#define XED_ISA_SET_CET 65
#define XED_ISA_SET_CLDEMOTE 66
#define XED_ISA_SET_CLFLUSHOPT 67
#define XED_ISA_SET_CLFSH 68
#define XED_ISA_SET_CLWB 69
#define XED_ISA_SET_CLZERO 70
#define XED_ISA_SET_CMOV 71
#define XED_ISA_SET_CMPXCHG16B 72
#define XED_ISA_SET_F16C 73
#define XED_ISA_SET_FAT_NOP 74
#define XED_ISA_SET_FCMOV 75
#define XED_ISA_SET_FMA 76
#define XED_ISA_SET_FMA4 77
#define XED_ISA_SET_FXSAVE 78
#define XED_ISA_SET_FXSAVE64 79
#define XED_ISA_SET_GFNI 80
#define XED_ISA_SET_I186 81
#define XED_ISA_SET_I286PROTECTED 82
#define XED_ISA_SET_I286REAL 83
#define XED_ISA_SET_I386 84
#define XED_ISA_SET_I486 85
#define XED_ISA_SET_I486REAL 86
#define XED_ISA_SET_I86 87
#define XED_ISA_SET_INVPCID 88
#define XED_ISA_SET_LAHF 89
#define XED_ISA_SET_LONGMODE 90
#define XED_ISA_SET_LZCNT 91
#define XED_ISA_SET_MONITOR 92
#define XED_ISA_SET_MONITORX 93
#define XED_ISA_SET_MOVBE 94
#define XED_ISA_SET_MOVDIR 95
#define XED_ISA_SET_MPX 96
#define XED_ISA_SET_PAUSE 97
#define XED_ISA_SET_PCLMULQDQ 98
#define XED_ISA_SET_PCONFIG 99
#define XED_ISA_SET_PENTIUMMMX 100
#define XED_ISA_SET_PENTIUMREAL 101
#define XED_ISA_SET_PKU 102
#define XED_ISA_SET_POPCNT 103
#define XED_ISA_SET_PPRO 104
#define XED_ISA_SET_PREFETCHW 105
#define XED_ISA_SET_PREFETCHWT1 106
#define XED_ISA_SET_PREFETCH_NOP 107
#define XED_ISA_SET_PT 108
#define XED_ISA_SET_RDPID 109
#define XED_ISA_SET_RDPMC 110
#define XED_ISA_SET_RDRAND 111
#define XED_ISA_SET_RDSEED 112
#define XED_ISA_SET_RDTSCP 113
#define XED_ISA_SET_RDWRFSGS 114
#define XED_ISA_SET_RTM 115
#define XED_ISA_SET_SGX 116
#define XED_ISA_SET_SGX_ENCLV 117
#define XED_ISA_SET_SHA 118
#define XED_ISA_SET_SMAP 119
#define XED_ISA_SET_SMX 120
#define XED_ISA_SET_SSE 121
#define XED_ISA_SET_SSE2 122
#define XED_ISA_SET_SSE2MMX 123
#define XED_ISA_SET_SSE3 124
#define XED_ISA_SET_SSE3X87 125
#define XED_ISA_SET_SSE4 126
#define XED_ISA_SET_SSE42 127
#define XED_ISA_SET_SSE4A 128
#define XED_ISA_SET_SSEMXCSR 129
#define XED_ISA_SET_SSE_PREFETCH 130
#define XED_ISA_SET_SSSE3 131
#define XED_ISA_SET_SSSE3MMX 132
#define XED_ISA_SET_SVM 133
#define XED_ISA_SET_TBM 134
#define XED_ISA_SET_VAES 135
#define XED_ISA_SET_VMFUNC 136
#define XED_ISA_SET_VPCLMULQDQ 137
#define XED_ISA_SET_VTX 138
#define XED_ISA_SET_WAITPKG 139
#define XED_ISA_SET_WBNOINVD 140
#define XED_ISA_SET_X87 141
#define XED_ISA_SET_XOP 142
#define XED_ISA_SET_XSAVE 143
#define XED_ISA_SET_XSAVEC 144
#define XED_ISA_SET_XSAVEOPT 145
#define XED_ISA_SET_XSAVES 146
#define XED_ISA_SET_LAST 147
struct XedChipFeatures {
uint64_t f[3];
};
#define xed_set_chip_modes(d, chip) \
do { \
struct XedDecodedInst *__d = d; \
switch (chip) { \
case XED_CHIP_INVALID: \
break; \
case XED_CHIP_I86: \
case XED_CHIP_I86FP: \
case XED_CHIP_I186: \
case XED_CHIP_I186FP: \
case XED_CHIP_I286REAL: \
case XED_CHIP_I286: \
case XED_CHIP_I2186FP: \
case XED_CHIP_I386REAL: \
case XED_CHIP_I386: \
case XED_CHIP_I386FP: \
case XED_CHIP_I486REAL: \
case XED_CHIP_I486: \
case XED_CHIP_QUARK: \
case XED_CHIP_PENTIUM: \
case XED_CHIP_PENTIUMREAL: \
case XED_CHIP_PENTIUMMMX: \
case XED_CHIP_PENTIUMMMXREAL: \
__d->op.mode_first_prefix = 1; \
break; \
default: \
break; \
} \
switch (chip) { \
case XED_CHIP_INVALID: \
case XED_CHIP_ALL: \
case XED_CHIP_AMD: \
break; \
default: \
__d->op.is_intel_specific = 1; \
break; \
} \
} while (0)
extern const uint64_t kXedChipFeatures[XED_CHIP_LAST][3];
bool xed_test_chip_features(struct XedChipFeatures *, int);
void xed_get_chip_features(struct XedChipFeatures *, int);
bool xed_isa_set_is_valid_for_chip(int, int);
COSMOPOLITAN_C_END_
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
#endif /* COSMOPOLITAN_THIRD_PARTY_XED_X86ISA_H_ */
| 10,815 | 262 | jart/cosmopolitan | false |
cosmopolitan/third_party/xed/x86ild.greg.c | /*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-â
âvi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :viâ
ââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââ¡
â Copyright 2018 Intel Corporation â
â Copyright 2020 Justine Alexandra Roberts Tunney â
â â
â Licensed under the Apache License, Version 2.0 (the "License"); â
â you may not use this file except in compliance with the License. â
â You may obtain a copy of the License at â
â â
â http://www.apache.org/licenses/LICENSE-2.0 â
â â
â Unless required by applicable law or agreed to in writing, software â
â distributed under the License is distributed on an "AS IS" BASIS, â
â WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. â
â See the License for the specific language governing permissions and â
â limitations under the License. â
ââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââ*/
#include "libc/assert.h"
#include "libc/dce.h"
#include "libc/intrin/bits.h"
#include "libc/intrin/bsr.h"
#include "libc/macros.internal.h"
#include "libc/runtime/runtime.h"
#include "libc/str/str.h"
#include "third_party/xed/avx512.h"
#include "third_party/xed/private.h"
#include "third_party/xed/x86.h"
asm(".ident\t\"\\n\\n\
Xed (Apache 2.0)\\n\
Copyright 2018 Intel Corporation\\n\
Copyright 2019 Justine Alexandra Roberts Tunney\\n\
Modifications: Trimmed down to 3kb [2019-03-22 jart]\"");
asm(".include \"libc/disclaimer.inc\"");
#define XED_ILD_HASMODRM_IGNORE_MOD 2
#define XED_I_LF_BRDISP8_BRDISP_WIDTH_CONST_l2 1
#define XED_I_LF_BRDISPz_BRDISP_WIDTH_OSZ_NONTERM_EOSZ_l2 2
#define XED_I_LF_DISP_BUCKET_0_l1 3
#define XED_I_LF_EMPTY_DISP_CONST_l2 4
#define XED_I_LF_MEMDISPv_DISP_WIDTH_ASZ_NONTERM_EASZ_l2 5
#define XED_I_LF_RESOLVE_BYREG_DISP_map0x0_op0xc7_l1 6
#define XED_I_LF_0_IMM_WIDTH_CONST_l2 1
#define XED_I_LF_RESOLVE_BYREG_IMM_WIDTH_map0x0_op0xc7_l1 2
#define XED_I_LF_RESOLVE_BYREG_IMM_WIDTH_map0x0_op0xf6_l1 3
#define XED_I_LF_RESOLVE_BYREG_IMM_WIDTH_map0x0_op0xf7_l1 4
#define XED_I_LF_SIMM8_IMM_WIDTH_CONST_l2 5
#define XED_I_LF_SIMMz_IMM_WIDTH_OSZ_NONTERM_DF64_EOSZ_l2 6
#define XED_I_LF_SIMMz_IMM_WIDTH_OSZ_NONTERM_EOSZ_l2 7
#define XED_I_LF_UIMM16_IMM_WIDTH_CONST_l2 8
#define XED_I_LF_UIMM8_IMM_WIDTH_CONST_l2 9
#define XED_I_LF_UIMMv_IMM_WIDTH_OSZ_NONTERM_EOSZ_l2 10
#define xed_i_ild_hasimm_map0x0_op0xc8_l1 11
#define xed_i_ild_hasimm_map0x0F_op0x78_l1 12
#define XED_LF_SIMMz_IMM_WIDTH_OSZ_NONTERM_IGNORE66_EOSZ_l2(X) \
xed_set_simmz_imm_width_eosz(X, kXed.OSZ_NONTERM_IGNORE66_EOSZ)
#define XED_LF_SIMMz_IMM_WIDTH_OSZ_NONTERM_REFINING66_EOSZ_l2(X) \
xed_set_simmz_imm_width_eosz(X, kXed.OSZ_NONTERM_REFINING66_EOSZ)
#define XED_LF_SIMMz_IMM_WIDTH_OSZ_NONTERM_DF64_FORCE64_EOSZ_l2(X) \
xed_set_simmz_imm_width_eosz(X, kXed.OSZ_NONTERM_DF64_FORCE64_EOSZ)
#define XED_LF_SIMMz_IMM_WIDTH_OSZ_NONTERM_FORCE64_EOSZ_l2(X) \
xed_set_simmz_imm_width_eosz(X, kXed.OSZ_NONTERM_FORCE64_EOSZ)
#define XED_LF_SIMMz_IMM_WIDTH_OSZ_NONTERM_EOSZ_l2(X) \
xed_set_simmz_imm_width_eosz(X, kXed.OSZ_NONTERM_EOSZ)
#define XED_LF_SIMMz_IMM_WIDTH_OSZ_NONTERM_REFINING66_CR_WIDTH_EOSZ_l2(X) \
xed_set_simmz_imm_width_eosz(X, kXed.OSZ_NONTERM_REFINING66_CR_WIDTH_EOSZ)
#define XED_LF_SIMMz_IMM_WIDTH_OSZ_NONTERM_DF64_EOSZ_l2(X) \
xed_set_simmz_imm_width_eosz(X, kXed.OSZ_NONTERM_DF64_EOSZ)
#define XED_LF_SIMMz_IMM_WIDTH_OSZ_NONTERM_DF64_IMMUNE66_LOOP64_EOSZ_l2(X) \
xed_set_simmz_imm_width_eosz(X, kXed.OSZ_NONTERM_DF64_IMMUNE66_LOOP64_EOSZ)
#define XED_LF_SIMMz_IMM_WIDTH_OSZ_NONTERM_IMMUNE66_EOSZ_l2(X) \
xed_set_simmz_imm_width_eosz(X, kXed.OSZ_NONTERM_IMMUNE66_EOSZ)
#define XED_LF_SIMMz_IMM_WIDTH_OSZ_NONTERM_CR_WIDTH_EOSZ_l2(X) \
xed_set_simmz_imm_width_eosz(X, kXed.OSZ_NONTERM_CR_WIDTH_EOSZ)
#define XED_LF_SIMMz_IMM_WIDTH_OSZ_NONTERM_IMMUNE_REXW_EOSZ_l2(X) \
xed_set_simmz_imm_width_eosz(X, kXed.OSZ_NONTERM_IMMUNE_REXW_EOSZ)
#define XED_LF_UIMMv_IMM_WIDTH_OSZ_NONTERM_IGNORE66_EOSZ_l2(X) \
xed_set_uimmv_imm_width_eosz(X, kXed.OSZ_NONTERM_IGNORE66_EOSZ)
#define XED_LF_UIMMv_IMM_WIDTH_OSZ_NONTERM_REFINING66_EOSZ_l2(X) \
xed_set_uimmv_imm_width_eosz(X, kXed.OSZ_NONTERM_REFINING66_EOSZ)
#define XED_LF_UIMMv_IMM_WIDTH_OSZ_NONTERM_DF64_FORCE64_EOSZ_l2(X) \
xed_set_uimmv_imm_width_eosz(X, kXed.OSZ_NONTERM_DF64_FORCE64_EOSZ)
#define XED_LF_UIMMv_IMM_WIDTH_OSZ_NONTERM_FORCE64_EOSZ_l2(X) \
xed_set_uimmv_imm_width_eosz(X, kXed.OSZ_NONTERM_FORCE64_EOSZ)
#define XED_LF_UIMMv_IMM_WIDTH_OSZ_NONTERM_EOSZ_l2(X) \
xed_set_uimmv_imm_width_eosz(X, kXed.OSZ_NONTERM_EOSZ)
#define XED_LF_UIMMv_IMM_WIDTH_OSZ_NONTERM_REFINING66_CR_WIDTH_EOSZ_l2(X) \
xed_set_uimmv_imm_width_eosz(X, kXed.OSZ_NONTERM_REFINING66_CR_WIDTH_EOSZ)
#define XED_LF_UIMMv_IMM_WIDTH_OSZ_NONTERM_DF64_EOSZ_l2(X) \
xed_set_uimmv_imm_width_eosz(X, kXed.OSZ_NONTERM_DF64_EOSZ)
#define XED_LF_UIMMv_IMM_WIDTH_OSZ_NONTERM_DF64_IMMUNE66_LOOP64_EOSZ_l2(X) \
xed_set_uimmv_imm_width_eosz(X, kXed.OSZ_NONTERM_DF64_IMMUNE66_LOOP64_EOSZ)
#define XED_LF_UIMMv_IMM_WIDTH_OSZ_NONTERM_IMMUNE66_EOSZ_l2(X) \
xed_set_uimmv_imm_width_eosz(X, kXed.OSZ_NONTERM_IMMUNE66_EOSZ)
#define XED_LF_UIMMv_IMM_WIDTH_OSZ_NONTERM_CR_WIDTH_EOSZ_l2(X) \
xed_set_uimmv_imm_width_eosz(X, kXed.OSZ_NONTERM_CR_WIDTH_EOSZ)
#define XED_LF_UIMMv_IMM_WIDTH_OSZ_NONTERM_IMMUNE_REXW_EOSZ_l2(X) \
xed_set_uimmv_imm_width_eosz(X, kXed.OSZ_NONTERM_IMMUNE_REXW_EOSZ)
static const uint32_t xed_prefix_table_bit[8] = {
0x00000000, 0x40404040, 0x0000ffff, 0x000000f0,
0x00000000, 0x00000000, 0x00000000, 0x000d0000,
};
static const uint8_t xed_imm_bits_2d[2][256] = {
{1, 1, 1, 1, 5, 7, 1, 1, 1, 1, 1, 1, 9, 7, 1, 0, 1, 1, 1, 1, 5, 7,
1, 1, 1, 1, 1, 1, 5, 7, 1, 1, 1, 1, 1, 1, 5, 7, 0, 1, 1, 1, 1, 1,
5, 7, 0, 1, 1, 1, 1, 1, 9, 7, 0, 1, 1, 1, 1, 1, 5, 7, 0, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 6, 7, 5, 5, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 5, 7, 5, 5,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
8, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 5, 7, 1, 1, 1, 1, 1, 1,
9, 9, 9, 9, 9, 9, 9, 9, 10, 10, 10, 10, 10, 10, 10, 10, 9, 9, 8, 1, 1, 1,
9, 2, 11, 1, 8, 1, 1, 9, 1, 1, 1, 1, 1, 1, 9, 9, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 9, 9, 9, 9, 1, 1, 8, 1, 1, 1, 1, 1, 0, 1,
0, 0, 1, 1, 3, 4, 1, 1, 1, 1, 1, 1, 1, 1},
{1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 0, 1, 0, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 9, 9, 9, 9, 1, 1, 1, 1,
12, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 9, 1, 0, 0,
1, 1, 1, 1, 9, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 9, 1, 1, 1, 1, 1,
1, 1, 9, 1, 9, 9, 9, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
};
static const uint8_t xed_has_modrm_2d[XED_ILD_MAP2][256] = {
{1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 3, 1, 1, 1, 1, 0, 0, 0, 0,
1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 3, 0, 1, 1, 1, 1, 0, 0, 3, 0,
1, 1, 1, 1, 0, 0, 3, 0, 1, 1, 1, 1, 0, 0, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 1, 1, 3, 3, 3, 3, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1, 1, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0,
1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
3, 0, 3, 3, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 1, 1},
{1, 1, 1, 1, 3, 0, 0, 0, 0, 0, 3, 0, 3, 1, 0, 3, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 1, 1, 1, 1, 1, 1, 1, 1,
0, 0, 0, 0, 0, 0, 3, 0, 3, 3, 3, 3, 3, 3, 3, 3, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0,
1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 1, 1, 1, 3, 3,
0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
};
static const uint8_t xed_has_sib_table[3][4][8] = {
{{0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0}},
{{0, 0, 0, 0, 1, 0, 0, 0},
{0, 0, 0, 0, 1, 0, 0, 0},
{0, 0, 0, 0, 1, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0}},
{{0, 0, 0, 0, 1, 0, 0, 0},
{0, 0, 0, 0, 1, 0, 0, 0},
{0, 0, 0, 0, 1, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0}},
};
static const uint8_t xed_has_disp_regular[3][4][8] = {
{{0, 0, 0, 0, 0, 0, 2, 0},
{1, 1, 1, 1, 1, 1, 1, 1},
{2, 2, 2, 2, 2, 2, 2, 2},
{0, 0, 0, 0, 0, 0, 0, 0}},
{{0, 0, 0, 0, 0, 4, 0, 0},
{1, 1, 1, 1, 1, 1, 1, 1},
{4, 4, 4, 4, 4, 4, 4, 4},
{0, 0, 0, 0, 0, 0, 0, 0}},
{{0, 0, 0, 0, 0, 4, 0, 0},
{1, 1, 1, 1, 1, 1, 1, 1},
{4, 4, 4, 4, 4, 4, 4, 4},
{0, 0, 0, 0, 0, 0, 0, 0}},
};
static const uint8_t xed_disp_bits_2d[XED_ILD_MAP2][256] = {
{4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 0, 4, 4, 4, 4, 4, 4, 4, 4,
4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 0, 4, 4, 4, 4, 4, 4, 4, 0, 4,
4, 4, 4, 4, 4, 4, 0, 4, 4, 4, 4, 4, 4, 4, 0, 4, 4, 4, 4, 4, 4, 4, 4, 4,
4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
4, 4, 4, 4, 0, 0, 0, 0, 4, 4, 4, 4, 4, 4, 4, 4, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 2, 4, 4, 4, 4, 4, 5, 5, 5, 5, 4, 4, 4, 4,
4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
4, 4, 4, 4, 4, 4, 4, 6, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
4, 4, 4, 4, 4, 4, 4, 4, 1, 1, 1, 1, 4, 4, 4, 4, 3, 3, 2, 1, 4, 4, 4, 4,
0, 4, 0, 0, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4},
{4, 4, 4, 4, 0, 4, 4, 4, 4, 4, 0, 4, 0, 4, 4, 0, 4, 4, 4, 4, 4, 4, 4, 4,
4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 0, 0, 0, 0, 4, 4, 4, 4, 4, 4, 4, 4,
4, 4, 4, 4, 4, 4, 0, 4, 0, 0, 0, 0, 0, 0, 0, 0, 4, 4, 4, 4, 4, 4, 4, 4,
4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
4, 4, 4, 4, 4, 4, 4, 4, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 0, 0,
4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4},
};
static const struct XedDenseMagnums {
unsigned vex_prefix_recoding[4];
xed_bits_t BRDISPz_BRDISP_WIDTH[4];
xed_bits_t MEMDISPv_DISP_WIDTH[4];
xed_bits_t SIMMz_IMM_WIDTH[4];
xed_bits_t UIMMv_IMM_WIDTH[4];
xed_bits_t ASZ_NONTERM_EASZ[2][3];
xed_bits_t OSZ_NONTERM_CR_WIDTH_EOSZ[2][2][3];
xed_bits_t OSZ_NONTERM_DF64_EOSZ[2][2][3];
xed_bits_t OSZ_NONTERM_DF64_FORCE64_EOSZ[2][2][3];
xed_bits_t OSZ_NONTERM_DF64_IMMUNE66_LOOP64_EOSZ[2][2][3];
xed_bits_t OSZ_NONTERM_EOSZ[2][2][3];
xed_bits_t OSZ_NONTERM_FORCE64_EOSZ[2][2][3];
xed_bits_t OSZ_NONTERM_IGNORE66_EOSZ[2][2][3];
xed_bits_t OSZ_NONTERM_IMMUNE66_EOSZ[2][2][3];
xed_bits_t OSZ_NONTERM_IMMUNE_REXW_EOSZ[2][2][3];
xed_bits_t OSZ_NONTERM_REFINING66_CR_WIDTH_EOSZ[2][2][3];
xed_bits_t OSZ_NONTERM_REFINING66_EOSZ[2][2][3];
} kXed = {
.vex_prefix_recoding = {0, 1, 3, 2},
.BRDISPz_BRDISP_WIDTH = {0, 16, 32, 32},
.MEMDISPv_DISP_WIDTH = {0, 16, 32, 64},
.SIMMz_IMM_WIDTH = {0x00, 0x10, 0x20, 0x20},
.UIMMv_IMM_WIDTH = {0x00, 0x10, 0x20, 0x40},
.ASZ_NONTERM_EASZ =
{
[0][0] = 1,
[1][0] = 2,
[0][1] = 2,
[1][1] = 1,
[0][2] = 3,
[1][2] = 2,
},
.OSZ_NONTERM_CR_WIDTH_EOSZ =
{
[0][0][0] = 2,
[1][0][0] = 2,
[0][1][0] = 2,
[1][1][0] = 2,
[0][1][1] = 2,
[1][1][1] = 2,
[0][0][1] = 2,
[1][0][1] = 2,
[0][1][2] = 3,
[0][0][2] = 3,
[1][1][2] = 3,
[1][0][2] = 3,
},
.OSZ_NONTERM_DF64_EOSZ =
{
[0][0][0] = 1,
[1][0][0] = 1,
[0][1][0] = 2,
[1][1][0] = 2,
[0][1][1] = 1,
[1][1][1] = 1,
[0][0][1] = 2,
[1][0][1] = 2,
[0][1][2] = 1,
[0][0][2] = 3,
[1][1][2] = 3,
[1][0][2] = 3,
},
.OSZ_NONTERM_DF64_FORCE64_EOSZ =
{
[0][0][0] = 1,
[1][0][0] = 1,
[0][1][0] = 2,
[1][1][0] = 2,
[0][1][1] = 1,
[1][1][1] = 1,
[0][0][1] = 2,
[1][0][1] = 2,
[0][1][2] = 3,
[0][0][2] = 3,
[1][1][2] = 3,
[1][0][2] = 3,
},
.OSZ_NONTERM_DF64_IMMUNE66_LOOP64_EOSZ =
{
[0][0][0] = 1,
[1][0][0] = 1,
[0][1][0] = 2,
[1][1][0] = 2,
[0][1][1] = 1,
[1][1][1] = 1,
[0][0][1] = 2,
[1][0][1] = 2,
[0][1][2] = 3,
[0][0][2] = 3,
[1][1][2] = 3,
[1][0][2] = 3,
},
.OSZ_NONTERM_EOSZ =
{
[0][0][0] = 1,
[1][0][0] = 1,
[0][1][0] = 2,
[1][1][0] = 2,
[0][1][1] = 1,
[1][1][1] = 1,
[0][0][1] = 2,
[1][0][1] = 2,
[0][1][2] = 1,
[0][0][2] = 2,
[1][1][2] = 3,
[1][0][2] = 3,
},
.OSZ_NONTERM_FORCE64_EOSZ =
{
[0][0][0] = 1,
[1][0][0] = 1,
[0][1][0] = 2,
[1][1][0] = 2,
[0][1][1] = 1,
[1][1][1] = 1,
[0][0][1] = 2,
[1][0][1] = 2,
[0][1][2] = 3,
[0][0][2] = 3,
[1][1][2] = 3,
[1][0][2] = 3,
},
.OSZ_NONTERM_IGNORE66_EOSZ =
{
[0][0][0] = 1,
[1][0][0] = 1,
[0][1][0] = 1,
[1][1][0] = 1,
[0][1][1] = 2,
[1][1][1] = 2,
[0][0][1] = 2,
[1][0][1] = 2,
[0][1][2] = 2,
[0][0][2] = 2,
[1][1][2] = 3,
[1][0][2] = 3,
},
.OSZ_NONTERM_IMMUNE66_EOSZ =
{
[0][0][0] = 2,
[1][0][0] = 2,
[0][1][0] = 2,
[1][1][0] = 2,
[0][1][1] = 2,
[1][1][1] = 2,
[0][0][1] = 2,
[1][0][1] = 2,
[0][1][2] = 2,
[0][0][2] = 2,
[1][1][2] = 3,
[1][0][2] = 3,
},
.OSZ_NONTERM_IMMUNE_REXW_EOSZ =
{
[0][0][0] = 1,
[1][0][0] = 1,
[0][1][0] = 2,
[1][1][0] = 2,
[0][1][1] = 1,
[1][1][1] = 1,
[0][0][1] = 2,
[1][0][1] = 2,
[0][1][2] = 1,
[0][0][2] = 2,
[1][1][2] = 2,
[1][0][2] = 2,
},
.OSZ_NONTERM_REFINING66_CR_WIDTH_EOSZ =
{
[0][0][0] = 2,
[1][0][0] = 2,
[0][1][0] = 2,
[1][1][0] = 2,
[0][1][1] = 2,
[1][1][1] = 2,
[0][0][1] = 2,
[1][0][1] = 2,
[0][1][2] = 3,
[0][0][2] = 3,
[1][1][2] = 3,
[1][0][2] = 3,
},
.OSZ_NONTERM_REFINING66_EOSZ =
{
[0][0][0] = 1,
[1][0][0] = 1,
[0][1][0] = 1,
[1][1][0] = 1,
[0][1][1] = 2,
[1][1][1] = 2,
[0][0][1] = 2,
[1][0][1] = 2,
[0][1][2] = 2,
[0][0][2] = 2,
[1][1][2] = 3,
[1][0][2] = 3,
},
};
privileged static void xed_too_short(struct XedDecodedInst *d) {
d->op.out_of_bytes = 1;
if (d->op.max_bytes >= 15) {
d->op.error = XED_ERROR_INSTR_TOO_LONG;
} else {
d->op.error = XED_ERROR_BUFFER_TOO_SHORT;
}
}
privileged static void xed_bad_map(struct XedDecodedInst *d) {
d->op.map = XED_ILD_MAP_INVALID;
d->op.error = XED_ERROR_BAD_MAP;
}
privileged static void xed_bad_v4(struct XedDecodedInst *d) {
d->op.error = XED_ERROR_BAD_EVEX_V_PRIME;
}
privileged static void xed_bad_z_aaa(struct XedDecodedInst *d) {
d->op.error = XED_ERROR_BAD_EVEX_Z_NO_MASKING;
}
privileged static xed_bits_t xed_get_prefix_table_bit(xed_bits_t a) {
return (xed_prefix_table_bit[a >> 5] >> (a & 0x1F)) & 1;
}
privileged static size_t xed_bits2bytes(unsigned bits) {
return bits >> 3;
}
privileged static size_t xed_bytes2bits(unsigned bytes) {
return bytes << 3;
}
privileged static bool xed3_mode_64b(struct XedDecodedInst *d) {
return d->op.mode == XED_MODE_LONG;
}
privileged static void xed_set_hint(char b, struct XedDecodedInst *d) {
switch (b) {
case 0x2e:
d->op.hint = XED_HINT_NTAKEN;
return;
case 0x3e:
d->op.hint = XED_HINT_TAKEN;
return;
default:
break;
}
}
privileged static void XED_LF_SIMM8_IMM_WIDTH_CONST_l2(
struct XedDecodedInst *x) {
x->op.imm_width = 8;
x->op.imm_signed = true;
}
privileged static void XED_LF_UIMM16_IMM_WIDTH_CONST_l2(
struct XedDecodedInst *x) {
x->op.imm_width = 16;
}
privileged static void XED_LF_SE_IMM8_IMM_WIDTH_CONST_l2(
struct XedDecodedInst *x) {
x->op.imm_width = 8;
}
privileged static void XED_LF_UIMM32_IMM_WIDTH_CONST_l2(
struct XedDecodedInst *x) {
x->op.imm_width = 32;
}
privileged static void xed_set_simmz_imm_width_eosz(
struct XedDecodedInst *x, const xed_bits_t eosz[2][2][3]) {
x->op.imm_width =
kXed.SIMMz_IMM_WIDTH[eosz[x->op.rexw][x->op.osz][x->op.mode]];
x->op.imm_signed = true;
}
privileged static void xed_set_uimmv_imm_width_eosz(
struct XedDecodedInst *x, const xed_bits_t eosz[2][2][3]) {
x->op.imm_width =
kXed.UIMMv_IMM_WIDTH[eosz[x->op.rexw][x->op.osz][x->op.mode]];
}
privileged static void XED_LF_UIMM8_IMM_WIDTH_CONST_l2(
struct XedDecodedInst *x) {
x->op.imm_width = 8;
}
privileged static void XED_LF_0_IMM_WIDTH_CONST_l2(struct XedDecodedInst *x) {
x->op.imm_width = 0;
}
privileged static void XED_LF_RESOLVE_BYREG_IMM_WIDTH_map0x0_op0xc7_l1(
struct XedDecodedInst *x) {
switch (x->op.reg) {
case 0:
XED_LF_SIMMz_IMM_WIDTH_OSZ_NONTERM_EOSZ_l2(x);
break;
case 7:
XED_LF_0_IMM_WIDTH_CONST_l2(x);
break;
default:
break;
}
}
privileged static void XED_LF_RESOLVE_BYREG_IMM_WIDTH_map0x0_op0xf6_l1(
struct XedDecodedInst *x) {
if (x->op.reg <= 1) {
XED_LF_SIMM8_IMM_WIDTH_CONST_l2(x);
} else if (2 <= x->op.reg && x->op.reg <= 7) {
XED_LF_0_IMM_WIDTH_CONST_l2(x);
}
}
privileged static void XED_LF_RESOLVE_BYREG_IMM_WIDTH_map0x0_op0xf7_l1(
struct XedDecodedInst *x) {
if (x->op.reg <= 1) {
XED_LF_SIMMz_IMM_WIDTH_OSZ_NONTERM_EOSZ_l2(x);
} else if (2 <= x->op.reg && x->op.reg <= 7) {
XED_LF_0_IMM_WIDTH_CONST_l2(x);
}
}
privileged static void xed_ild_hasimm_map0x0F_op0x78_l1(
struct XedDecodedInst *x) {
if (x->op.osz || x->op.ild_f2) {
x->op.imm_width = xed_bytes2bits(1);
x->op.imm1_bytes = 1;
}
}
privileged static void xed_ild_hasimm_map0x0_op0xc8_l1(
struct XedDecodedInst *x) {
x->op.imm_width = xed_bytes2bits(2);
x->op.imm1_bytes = 1;
}
privileged static void xed_set_imm_bytes(struct XedDecodedInst *d) {
if (!d->op.imm_width && d->op.map < XED_ILD_MAP2) {
switch (xed_imm_bits_2d[d->op.map][d->op.opcode]) {
case XED_I_LF_0_IMM_WIDTH_CONST_l2:
XED_LF_0_IMM_WIDTH_CONST_l2(d);
break;
case XED_I_LF_RESOLVE_BYREG_IMM_WIDTH_map0x0_op0xc7_l1:
XED_LF_RESOLVE_BYREG_IMM_WIDTH_map0x0_op0xc7_l1(d);
break;
case XED_I_LF_RESOLVE_BYREG_IMM_WIDTH_map0x0_op0xf6_l1:
XED_LF_RESOLVE_BYREG_IMM_WIDTH_map0x0_op0xf6_l1(d);
break;
case XED_I_LF_RESOLVE_BYREG_IMM_WIDTH_map0x0_op0xf7_l1:
XED_LF_RESOLVE_BYREG_IMM_WIDTH_map0x0_op0xf7_l1(d);
break;
case XED_I_LF_SIMM8_IMM_WIDTH_CONST_l2:
XED_LF_SIMM8_IMM_WIDTH_CONST_l2(d);
break;
case XED_I_LF_SIMMz_IMM_WIDTH_OSZ_NONTERM_DF64_EOSZ_l2:
XED_LF_SIMMz_IMM_WIDTH_OSZ_NONTERM_DF64_EOSZ_l2(d);
break;
case XED_I_LF_SIMMz_IMM_WIDTH_OSZ_NONTERM_EOSZ_l2:
XED_LF_SIMMz_IMM_WIDTH_OSZ_NONTERM_EOSZ_l2(d);
break;
case XED_I_LF_UIMM16_IMM_WIDTH_CONST_l2:
XED_LF_UIMM16_IMM_WIDTH_CONST_l2(d);
break;
case XED_I_LF_UIMM8_IMM_WIDTH_CONST_l2:
XED_LF_UIMM8_IMM_WIDTH_CONST_l2(d);
break;
case XED_I_LF_UIMMv_IMM_WIDTH_OSZ_NONTERM_EOSZ_l2:
XED_LF_UIMMv_IMM_WIDTH_OSZ_NONTERM_EOSZ_l2(d);
break;
case xed_i_ild_hasimm_map0x0_op0xc8_l1:
xed_ild_hasimm_map0x0_op0xc8_l1(d);
break;
case xed_i_ild_hasimm_map0x0F_op0x78_l1:
xed_ild_hasimm_map0x0F_op0x78_l1(d);
break;
default:
d->op.error = XED_ERROR_GENERAL_ERROR;
return;
}
}
}
privileged static int xed_consume_byte(struct XedDecodedInst *d) {
if (d->length < d->op.max_bytes) {
return d->bytes[d->length++];
} else {
xed_too_short(d);
return -1;
}
}
privileged static void xed_prefix_scanner(struct XedDecodedInst *d) {
xed_bits_t first_f2f3, last_f2f3, seg;
xed_bits_t b, max_bytes, length, nprefixes, nseg_prefixes, nrexes, rex;
seg = 0;
length = d->length;
max_bytes = d->op.max_bytes;
first_f2f3 = last_f2f3 = rex = nrexes = nprefixes = nseg_prefixes = 0;
while (length < max_bytes) {
b = d->bytes[length];
if (xed_get_prefix_table_bit(b) == 0) goto out;
switch (b) {
case 0x66:
d->op.osz = true;
rex = 0;
break;
case 0x67:
d->op.asz = true;
rex = 0;
break;
case 0x2E:
case 0x3E:
xed_set_hint(b, d);
/* fallthrough */
case 0x26:
case 0x36:
if (!xed3_mode_64b(d)) seg = b;
nseg_prefixes++;
rex = 0;
break;
case 0x64:
case 0x65:
seg = b;
nseg_prefixes++;
rex = 0;
break;
case 0xF0:
d->op.lock = true;
rex = 0;
break;
case 0xF3:
d->op.ild_f3 = true;
last_f2f3 = 3;
if (!first_f2f3) {
first_f2f3 = 3;
}
rex = 0;
break;
case 0xF2:
d->op.ild_f2 = true;
last_f2f3 = 2;
if (!first_f2f3) {
first_f2f3 = 2;
}
rex = 0;
break;
default:
if (xed3_mode_64b(d) && (b & 0xf0) == 0x40) {
nrexes++;
rex = b;
break;
} else {
goto out;
}
}
length++;
nprefixes++;
}
out:
d->length = length;
d->op.nprefixes = nprefixes;
d->op.nseg_prefixes = nseg_prefixes;
d->op.nrexes = nrexes;
if (rex) {
d->op.rexw = rex >> 3 & 1;
d->op.rexr = rex >> 2 & 1;
d->op.rexx = rex >> 1 & 1;
d->op.rexb = rex & 1;
d->op.rex = true;
}
if (d->op.mode_first_prefix) {
d->op.rep = first_f2f3;
} else {
d->op.rep = last_f2f3;
}
switch (seg) {
case 0x26: /* ES */
d->op.seg_ovd = 0 + 1;
break;
case 0x2e: /* CS */
d->op.seg_ovd = 1 + 1;
break;
case 0x36: /* SS */
d->op.seg_ovd = 2 + 1;
break;
case 0x3e: /* DS */
d->op.seg_ovd = 3 + 1;
break;
case 0x64: /* FS */
d->op.seg_ovd = 4 + 1;
break;
case 0x65: /* GS */
d->op.seg_ovd = 5 + 1;
break;
default:
break;
}
if (length >= max_bytes) {
xed_too_short(d);
return;
}
}
privileged static void xed_get_next_as_opcode(struct XedDecodedInst *d) {
xed_bits_t b, length;
length = d->length;
if (length < d->op.max_bytes) {
b = d->bytes[length];
d->op.opcode = b;
d->length++;
} else {
xed_too_short(d);
}
}
privileged static void xed_catch_invalid_rex_or_legacy_prefixes(
struct XedDecodedInst *d) {
if (xed3_mode_64b(d) && d->op.rex) {
d->op.error = XED_ERROR_BAD_REX_PREFIX;
} else if (d->op.osz || d->op.ild_f3 || d->op.ild_f2) {
d->op.error = XED_ERROR_BAD_LEGACY_PREFIX;
}
}
privileged static void xed_catch_invalid_mode(struct XedDecodedInst *d) {
if (d->op.realmode) {
d->op.error = XED_ERROR_INVALID_MODE;
}
}
privileged static void xed_evex_vex_opcode_scanner(struct XedDecodedInst *d) {
d->op.opcode = d->bytes[d->length];
d->op.pos_opcode = d->length++;
xed_catch_invalid_rex_or_legacy_prefixes(d);
xed_catch_invalid_mode(d);
}
privileged static void xed_opcode_scanner(struct XedDecodedInst *d) {
xed_bits_t b, length;
length = d->length;
if ((b = d->bytes[length]) != 0x0F) {
d->op.map = XED_ILD_MAP0;
d->op.opcode = b;
d->op.pos_opcode = length;
d->length++;
} else {
length++;
d->op.pos_opcode = length;
if (length < d->op.max_bytes) {
switch ((b = d->bytes[length])) {
case 0x38:
length++;
d->op.map = XED_ILD_MAP2;
d->length = length;
xed_get_next_as_opcode(d);
return;
case 0x3A:
length++;
d->op.map = XED_ILD_MAP3;
d->length = length;
d->op.imm_width = xed_bytes2bits(1);
xed_get_next_as_opcode(d);
return;
case 0x3B:
length++;
xed_bad_map(d);
d->length = length;
xed_get_next_as_opcode(d);
return;
case 0x39:
case 0x3C:
case 0x3D:
case 0x3E:
case 0x3F:
length++;
xed_bad_map(d);
d->length = length;
xed_get_next_as_opcode(d);
return;
case 0x0F:
d->op.amd3dnow = true;
length++;
d->op.opcode = 0x0F;
d->op.map = XED_ILD_MAPAMD;
d->length = length;
break;
default:
length++;
d->op.opcode = b;
d->op.map = XED_ILD_MAP1;
d->length = length;
break;
}
} else {
xed_too_short(d);
return;
}
}
}
privileged static bool xed_is_bound_instruction(struct XedDecodedInst *d) {
return !xed3_mode_64b(d) && d->length + 1 < d->op.max_bytes &&
(d->bytes[d->length + 1] & 0xC0) != 0xC0;
}
privileged static void xed_evex_scanner(struct XedDecodedInst *d) {
xed_bits_t length, max_bytes;
union XedAvx512Payload1 evex1;
union XedAvx512Payload2 evex2;
union XedAvx512Payload3 evex3;
length = d->length;
max_bytes = d->op.max_bytes;
/* @assume prefix_scanner() checked length */
if (d->bytes[length] != 0x62) return;
if (xed_is_bound_instruction(d)) return;
if (length + 4 < max_bytes) {
evex1.u32 = d->bytes[length + 1];
evex2.u32 = d->bytes[length + 2];
if (xed3_mode_64b(d)) {
d->op.rexr = ~evex1.s.r_inv & 1;
d->op.rexx = ~evex1.s.x_inv & 1;
d->op.rexb = ~evex1.s.b_inv & 1;
d->op.rexrr = ~evex1.s.rr_inv & 1;
}
d->op.rexw = evex2.s.rexw & 1;
d->op.map = evex1.s.map;
d->op.vexdest3 = evex2.s.vexdest3;
d->op.vexdest210 = evex2.s.vexdest210;
d->op.ubit = evex2.s.ubit;
if (evex2.s.ubit) {
d->op.vexvalid = 2;
} else {
d->op.error = XED_ERROR_BAD_EVEX_UBIT;
}
d->op.vex_prefix = kXed.vex_prefix_recoding[evex2.s.pp];
if (evex1.s.map == XED_ILD_MAP3) {
d->op.imm_width = xed_bytes2bits(1);
}
if (evex2.s.ubit) {
evex3.u32 = d->bytes[length + 3];
d->op.zeroing = evex3.s.z;
d->op.llrc = evex3.s.llrc;
d->op.vl = evex3.s.llrc;
d->op.bcrc = evex3.s.bcrc;
d->op.vexdest4 = ~evex3.s.vexdest4p & 1;
if (!xed3_mode_64b(d) && evex3.s.vexdest4p == 0) {
xed_bad_v4(d);
}
d->op.mask = evex3.s.mask;
if (evex3.s.mask == 0 && evex3.s.z == 1) {
xed_bad_z_aaa(d);
}
}
length += 4;
d->length = length;
xed_evex_vex_opcode_scanner(d);
} else {
xed_too_short(d);
}
}
privileged static uint64_t xed_read_number(uint8_t *p, size_t n, bool s) {
switch (s << 2 | _bsr(n)) {
case 0b000:
return *p;
case 0b100:
return (int8_t)*p;
case 0b001:
return READ16LE(p);
case 0b101:
return (int16_t)READ16LE(p);
case 0b010:
return READ32LE(p);
case 0b110:
return (int32_t)READ32LE(p);
case 0b011:
case 0b111:
return READ64LE(p);
default:
unreachable;
}
}
privileged static void xed_evex_imm_scanner(struct XedDecodedInst *d) {
uint64_t uimm0;
uint8_t *itext, *imm_ptr;
xed_bits_t length, imm_bytes, imm1_bytes, max_bytes;
imm_ptr = 0;
itext = d->bytes;
xed_set_imm_bytes(d);
length = d->length;
max_bytes = d->op.max_bytes;
if (d->op.amd3dnow) {
if (length < max_bytes) {
d->op.opcode = d->bytes[length];
d->length++;
return;
} else {
xed_too_short(d);
return;
}
}
imm_bytes = xed_bits2bytes(d->op.imm_width);
imm1_bytes = d->op.imm1_bytes;
if (imm_bytes) {
if (length + imm_bytes <= max_bytes) {
d->op.pos_imm = length;
length += imm_bytes;
d->length = length;
if (imm1_bytes) {
if (length + imm1_bytes <= max_bytes) {
d->op.pos_imm1 = length;
imm_ptr = itext + length;
length += imm1_bytes;
d->length = length;
d->op.uimm1 = *imm_ptr;
} else {
xed_too_short(d);
return;
}
}
} else {
xed_too_short(d);
return;
}
}
if (imm_bytes) {
d->op.uimm0 =
xed_read_number(itext + d->op.pos_imm, imm_bytes, d->op.imm_signed);
}
}
privileged static void xed_vex_c4_scanner(struct XedDecodedInst *d) {
unsigned length, b1, b2;
if (xed_is_bound_instruction(d)) return;
length = d->length;
length++;
if (length + 2 < d->op.max_bytes) {
// map: 5-bit
// rex.b: 1-bit
// rex.x: 1-bit
// rex.r: 1-bit
b1 = d->bytes[length];
d->op.rexr = !(b1 & 128);
d->op.rexx = !(b1 & 64);
d->op.rexb = xed3_mode_64b(d) & !(b1 & 32);
// prefix: 2-bit â {none, osz, rep3, rep2}
// vector_length: 1-bit â {xmm, ymm}
// vexdest210: 3-bit
// vexdest3: 1-bit
// rex.w: 1-bit
b2 = d->bytes[length + 1];
d->op.rexw = !!(b2 & 128);
d->op.vexdest3 = !!(b2 & 64);
d->op.vexdest210 = (b2 >> 3) & 7;
d->op.vl = !!(b2 & 4);
d->op.vex_prefix = kXed.vex_prefix_recoding[b2 & 3];
d->op.map = b1 & 31;
if ((b1 & 3) == XED_ILD_MAP3) {
d->op.imm_width = xed_bytes2bits(1);
}
d->op.vexvalid = 1;
length += 2;
d->length = length;
xed_evex_vex_opcode_scanner(d);
} else {
d->length = length;
xed_too_short(d);
}
}
privileged static void xed_vex_c5_scanner(struct XedDecodedInst *d) {
unsigned length, b;
length = d->length;
if (xed_is_bound_instruction(d)) return;
length++;
if (length + 1 < d->op.max_bytes) {
// prefix: 2-bit â {none, osz, rep3, rep2}
// vector_length: 1-bit â {xmm, ymm}
// vexdest210: 3-bit
// vexdest3: 1-bit
// rex.r: 1-bit
b = d->bytes[length];
d->op.rexr = !(b & 128);
d->op.vexdest3 = !!(b & 64);
d->op.vexdest210 = (b >> 3) & 7;
d->op.vl = (b >> 2) & 1;
d->op.vex_prefix = kXed.vex_prefix_recoding[b & 3];
d->op.map = XED_ILD_MAP1;
d->op.vexvalid = 1;
length++;
d->length = length;
xed_evex_vex_opcode_scanner(d);
} else {
d->length = length;
xed_too_short(d);
}
}
privileged static void xed_vex_scanner(struct XedDecodedInst *d) {
if (!d->op.out_of_bytes) {
switch (d->bytes[d->length]) {
case 0xC5:
xed_vex_c5_scanner(d);
break;
case 0xC4:
xed_vex_c4_scanner(d);
break;
default:
break;
}
}
}
privileged static void xed_bad_ll(struct XedDecodedInst *d) {
d->op.error = XED_ERROR_BAD_EVEX_LL;
}
privileged static void xed_bad_ll_check(struct XedDecodedInst *d) {
if (d->op.llrc == 3) {
if (d->op.mod != 3) {
xed_bad_ll(d);
} else if (d->op.bcrc == 0) {
xed_bad_ll(d);
}
}
}
privileged static void xed_set_has_modrm(struct XedDecodedInst *d) {
if (d->op.map < ARRAYLEN(xed_has_modrm_2d)) {
d->op.has_modrm = xed_has_modrm_2d[d->op.map][d->op.opcode];
} else {
d->op.has_modrm = 1;
}
}
privileged static void xed_modrm_scanner(struct XedDecodedInst *d) {
uint8_t b;
xed_bits_t eamode, mod, rm, asz, mode, length, has_modrm;
xed_set_has_modrm(d);
has_modrm = d->op.has_modrm;
if (has_modrm) {
length = d->length;
if (length < d->op.max_bytes) {
b = d->bytes[length];
d->op.modrm = b;
d->op.pos_modrm = length;
d->length++;
mod = xed_modrm_mod(b);
rm = xed_modrm_rm(b);
d->op.mod = mod;
d->op.rm = rm;
d->op.reg = xed_modrm_reg(b);
xed_bad_ll_check(d);
if (has_modrm != XED_ILD_HASMODRM_IGNORE_MOD) {
asz = d->op.asz;
mode = d->op.mode;
eamode = kXedEamode[asz][mode];
d->op.disp_width =
xed_bytes2bits(xed_has_disp_regular[eamode][mod][rm]);
d->op.has_sib = xed_has_sib_table[eamode][mod][rm];
}
} else {
xed_too_short(d);
}
}
}
privileged static void xed_sib_scanner(struct XedDecodedInst *d) {
uint8_t b;
xed_bits_t length;
if (d->op.has_sib) {
length = d->length;
if (length < d->op.max_bytes) {
b = d->bytes[length];
d->op.pos_sib = length;
d->op.sib = b;
d->length++;
if (xed_sib_base(b) == 5) {
if (d->op.mod == 0) {
d->op.disp_width = xed_bytes2bits(4);
}
}
} else {
xed_too_short(d);
}
}
}
privileged static void XED_LF_EMPTY_DISP_CONST_l2(struct XedDecodedInst *x) {
/* This function does nothing for map-opcodes whose
* disp_bytes value is set earlier in xed-ild.c
* (regular displacement resolution by modrm/sib)*/
(void)x;
}
privileged static void XED_LF_BRDISP8_BRDISP_WIDTH_CONST_l2(
struct XedDecodedInst *x) {
x->op.disp_width = 0x8;
}
privileged static void XED_LF_BRDISPz_BRDISP_WIDTH_OSZ_NONTERM_EOSZ_l2(
struct XedDecodedInst *x) {
x->op.disp_width =
kXed.BRDISPz_BRDISP_WIDTH[kXed.OSZ_NONTERM_EOSZ[x->op.rexw][x->op.osz]
[x->op.mode]];
x->op.disp_unsigned = true;
}
privileged static void XED_LF_RESOLVE_BYREG_DISP_map0x0_op0xc7_l1(
struct XedDecodedInst *x) {
switch (x->op.reg) {
case 0:
XED_LF_EMPTY_DISP_CONST_l2(x);
break;
case 7:
XED_LF_BRDISPz_BRDISP_WIDTH_OSZ_NONTERM_EOSZ_l2(x);
break;
default:
break;
}
}
privileged static void XED_LF_MEMDISPv_DISP_WIDTH_ASZ_NONTERM_EASZ_l2(
struct XedDecodedInst *x) {
x->op.disp_width =
kXed.MEMDISPv_DISP_WIDTH[kXed.ASZ_NONTERM_EASZ[x->op.asz][x->op.mode]];
x->op.disp_unsigned = true;
}
privileged static void XED_LF_BRDISP32_BRDISP_WIDTH_CONST_l2(
struct XedDecodedInst *x) {
x->op.disp_width = 0x20;
}
privileged static void XED_LF_DISP_BUCKET_0_l1(struct XedDecodedInst *x) {
if (x->op.mode <= XED_MODE_LEGACY) {
XED_LF_BRDISPz_BRDISP_WIDTH_OSZ_NONTERM_EOSZ_l2(x);
x->op.disp_unsigned = false;
} else if (x->op.mode == XED_MODE_LONG) {
XED_LF_BRDISP32_BRDISP_WIDTH_CONST_l2(x);
}
}
privileged static void xed_disp_scanner(struct XedDecodedInst *d) {
xed_bits_t length, disp_width, disp_bytes, max_bytes;
length = d->length;
if (d->op.map < XED_ILD_MAP2) {
switch (xed_disp_bits_2d[d->op.map][d->op.opcode]) {
case XED_I_LF_BRDISP8_BRDISP_WIDTH_CONST_l2:
XED_LF_BRDISP8_BRDISP_WIDTH_CONST_l2(d);
break;
case XED_I_LF_BRDISPz_BRDISP_WIDTH_OSZ_NONTERM_EOSZ_l2:
XED_LF_BRDISPz_BRDISP_WIDTH_OSZ_NONTERM_EOSZ_l2(d);
break;
case XED_I_LF_DISP_BUCKET_0_l1:
XED_LF_DISP_BUCKET_0_l1(d);
break;
case XED_I_LF_EMPTY_DISP_CONST_l2:
XED_LF_EMPTY_DISP_CONST_l2(d);
break;
case XED_I_LF_MEMDISPv_DISP_WIDTH_ASZ_NONTERM_EASZ_l2:
XED_LF_MEMDISPv_DISP_WIDTH_ASZ_NONTERM_EASZ_l2(d);
break;
case XED_I_LF_RESOLVE_BYREG_DISP_map0x0_op0xc7_l1:
XED_LF_RESOLVE_BYREG_DISP_map0x0_op0xc7_l1(d);
break;
default:
d->op.error = XED_ERROR_GENERAL_ERROR;
return;
}
}
disp_bytes = xed_bits2bytes(d->op.disp_width);
if (disp_bytes) {
max_bytes = d->op.max_bytes;
if (length + disp_bytes <= max_bytes) {
d->op.disp =
xed_read_number(d->bytes + length, disp_bytes, !d->op.disp_unsigned);
d->op.pos_disp = length;
d->length = length + disp_bytes;
} else {
xed_too_short(d);
}
}
}
privileged static void xed_decode_instruction_length(
struct XedDecodedInst *ild) {
xed_prefix_scanner(ild);
if (!ild->op.out_of_bytes) {
xed_vex_scanner(ild);
if (!ild->op.out_of_bytes) {
if (!ild->op.vexvalid) xed_evex_scanner(ild);
if (!ild->op.out_of_bytes) {
if (!ild->op.vexvalid && !ild->op.error) {
xed_opcode_scanner(ild);
}
xed_modrm_scanner(ild);
xed_sib_scanner(ild);
xed_disp_scanner(ild);
xed_evex_imm_scanner(ild);
}
}
}
}
/**
* Clears instruction decoder state.
*/
privileged struct XedDecodedInst *xed_decoded_inst_zero_set_mode(
struct XedDecodedInst *p, int mmode) {
__builtin_memset(p, 0, sizeof(*p));
xed_operands_set_mode(&p->op, mmode);
return p;
}
/**
* Decodes machine instruction length.
*
* This function also decodes other useful attributes, such as the
* offsets of displacement, immediates, etc. It works for all ISAs from
* 1977 to 2020.
*
* @note binary footprint increases ~4kb if this is used
* @see biggest code in gdb/clang/tensorflow binaries
*/
privileged int xed_instruction_length_decode(struct XedDecodedInst *xedd,
const void *itext, size_t bytes) {
__builtin_memcpy(xedd->bytes, itext, MIN(15, bytes));
xedd->op.max_bytes = MIN(15, bytes);
xed_decode_instruction_length(xedd);
if (!xedd->op.out_of_bytes) {
if (xedd->op.map != XED_ILD_MAP_INVALID) {
return xedd->op.error;
} else {
return XED_ERROR_GENERAL_ERROR;
}
} else {
return XED_ERROR_BUFFER_TOO_SHORT;
}
}
| 40,792 | 1,260 | jart/cosmopolitan | false |
cosmopolitan/third_party/xed/x86.h | #ifndef COSMOPOLITAN_THIRD_PARTY_XED_X86_H_
#define COSMOPOLITAN_THIRD_PARTY_XED_X86_H_
/* âââââââââââââ ââââ
âââââââââââââ ââââââââ âââââââââ âââââ
ââââ âââââ â ââââ ââ âââ âââââ
â¬â¬â¬â¬â¬â¬â¬â¬â¬â¬â¬â¬â¬ââââââââââââââ¬â¬â¬â¬â¬â¬â¬â¬â¬â¬â¬ââââ¬â¬â¬ââââ¬â¬â¬â¬â¬â¬â¬â¬âââ¬â¬â¬â¬ââââââ¬â¬â¬â¬â¬â¬â¬â¬â¬â¬â¬â¬â¬â¬â¬
â ââââ âââââ âââ ââââ âââ ââââ â
â¬â¬â¬â¬â¬â¬â¬â¬â¬â¬â¬â¬â¬ââââ ââââââ¬â¬â¬â¬â¬â¬â¬â¬ââââââââ¬â¬â¬ââââââââââââ¬â¬ââââââââââââââ¬â¬â¬â¬â¬â¬â¬â¬â¬â¬
â ââââ âââââ ââââââ âââââââââââ ââââ ââââ â
â¬â¬â¬â¬â¬â¬â¬â¬â¬â¬â¬â¬â¬ââââ ââââââ¬â¬â¬â¬â¬â¬â¬â¬â¬â¬â¬ââââââââââ âââââââââââââ¬â¬â¬â¬â¬â¬â¬â¬ââââ¬â¬â¬â¬â¬â¬â¬â¬
â¬â¬â¬â¬â¬â¬â¬â¬ââ¬â¬â¬â¬ââââ ââââââ¬â¬â¬â¬â¬â¬â¬â¬â¬â¬â¬â¬ââââââââ¬â¬â¬â¬â¬â¬â¬â¬â¬âââ ââââ¬â¬â¬â¬â¬â¬â¬â¬ââââ¬â¬â¬â¬ââ¬â¬â¬
â¬â¬â¬â¬â¬â¬â¬â¬â¬â¬â¬â¬â¬ââââ ââââââ¬â¬â¬â¬â¬â¬â¬â¬â¬â¬â¬âââââ¬â¬ââââ¬â¬â¬â¬â¬â¬â¬â¬ââââ¬âââââ¬â¬â¬â¬â¬â¬â¬ââââ¬â¬â¬â¬â¬â¬â¬â¬
â â â â â â â â ââ â â â ââââ ââââââ â â âââââââââââ â â â â¬ââââââââââââ â â â â¬âââââââââââââ â â â ââ â â
â â â â â â â â â â â â â ââââââââââââââ â â â â âââââ â â â â â â â â â â â â â âââ â â â â â â â â â â â âââââ â â â â â â â â â â â â
âââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââ
âââââââââ¨ââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââ¨âââ
â cosmopolitan § virtual machine » byte code language â
ââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââ*/
#define XED_MAX_INSTRUCTION_BYTES 15
#define XED_MODE_REAL 0
#define XED_MODE_LEGACY 1
#define XED_MODE_LONG 2
#define XED_HINT_NTAKEN 2
#define XED_HINT_TAKEN 4
#define XED_HINT_ALTER 6
#define XED_SEG_ES 1
#define XED_SEG_CS 2
#define XED_SEG_SS 3
#define XED_SEG_DS 4
#define XED_SEG_FS 5
#define XED_SEG_GS 6
#define xed_modrm_mod(M) (((M)&0xff) >> 6)
#define xed_modrm_reg(M) (((M)&0b00111000) >> 3)
#define xed_modrm_rm(M) ((M)&7)
#define xed_sib_base(M) ((M)&7)
#define xed_sib_index(M) (((M)&0b00111000) >> 3)
#define xed_sib_scale(M) (((M)&0xff) >> 6)
#define xed_get_modrm_reg_field(M) (((M)&0x38) >> 3)
#if !(__ASSEMBLER__ + __LINKER__ + 0)
COSMOPOLITAN_C_START_
#define XED_MACHINE_MODE_REAL XED_MODE_REAL
#define XED_MACHINE_MODE_LEGACY_32 XED_MODE_LEGACY
#define XED_MACHINE_MODE_LONG_64 XED_MODE_LONG
#define XED_MACHINE_MODE_UNREAL (1 << 2 | XED_MODE_REAL)
#define XED_MACHINE_MODE_LEGACY_16 (2 << 2 | XED_MODE_REAL)
#define XED_MACHINE_MODE_LONG_COMPAT_16 (3 << 2 | XED_MODE_REAL)
#define XED_MACHINE_MODE_LONG_COMPAT_32 (4 << 2 | XED_MODE_LEGACY)
#define XED_MACHINE_MODE_LAST (XED_MACHINE_MODE_LONG_COMPAT_32 + 1)
#define XED_ERROR_NONE 0
#define XED_ERROR_BUFFER_TOO_SHORT 1
#define XED_ERROR_GENERAL_ERROR 2
#define XED_ERROR_INVALID_FOR_CHIP 3
#define XED_ERROR_BAD_REGISTER 4
#define XED_ERROR_BAD_LOCK_PREFIX 5
#define XED_ERROR_BAD_REP_PREFIX 6
#define XED_ERROR_BAD_LEGACY_PREFIX 7
#define XED_ERROR_BAD_REX_PREFIX 8
#define XED_ERROR_BAD_EVEX_UBIT 9
#define XED_ERROR_BAD_MAP 10
#define XED_ERROR_BAD_EVEX_V_PRIME 11
#define XED_ERROR_BAD_EVEX_Z_NO_MASKING 12
#define XED_ERROR_NO_OUTPUT_POINTER 13
#define XED_ERROR_NO_AGEN_CALL_BACK_REGISTERED 14
#define XED_ERROR_BAD_MEMOP_INDEX 15
#define XED_ERROR_CALLBACK_PROBLEM 16
#define XED_ERROR_GATHER_REGS 17
#define XED_ERROR_INSTR_TOO_LONG 18
#define XED_ERROR_INVALID_MODE 19
#define XED_ERROR_BAD_EVEX_LL 20
#define XED_ERROR_UNIMPLEMENTED 21
#define XED_ERROR_LAST 22
#define XED_ADDRESS_WIDTH_INVALID 0
#define XED_ADDRESS_WIDTH_16b 2
#define XED_ADDRESS_WIDTH_32b 4
#define XED_ADDRESS_WIDTH_64b 8
#define XED_ADDRESS_WIDTH_LAST 9
#define XED_ILD_MAP0 0 /* 8086+ ... */
#define XED_ILD_MAP1 1 /* 286+ 0x0F,... */
#define XED_ILD_MAP2 2 /* Core2+ 0x0F,0x38,... */
#define XED_ILD_MAP3 3 /* Core2+ 0x0F,0x3A,... */
#define XED_ILD_MAP4 4
#define XED_ILD_MAP5 5
#define XED_ILD_MAP6 6
#define XED_ILD_MAPAMD 7
#define XED_ILD_MAP_XOP8 8
#define XED_ILD_MAP_XOP9 9
#define XED_ILD_MAP_XOPA 10
#define XED_ILD_MAP_LAST 11
#define XED_ILD_MAP_INVALID 12
struct XedOperands { /*
ârep
â âlogâð
â â âmode
â â â âeamode
â â â â âmod
â â â â â
â â â â â âsego
â â â â â â
â â â â â â ârex REGISTER
â â â â â â âârexb DISPATCH
â â â â â â âââsrm ENCODING
â â â â â â âââ ârex
â â â â â â âââ âârexb
â â â â â â âââ ââârm
â â â â â â âââ âââ ârexw
â â â â â â âââ âââ ââosz
â â â â â â âââ âââ ââârex
â â â â â â âââ âââ âââârexr
â â â â â â âââ âââ âââââreg
â3â2â2â2â2 â âââ âââ âââââ
â0â8â6â4â2 â18 âââ12âââ 7âââââ 0
ââââââââââ âââ âââââââââââââââââ
00000000000000000000000000000000*/
uint32_t rde;
union {
struct {
union {
uint8_t opcode;
uint8_t srm : 3;
};
uint8_t map : 4;
};
uint16_t dispatch;
};
union {
uint8_t sib;
struct {
uint8_t base : 3;
uint8_t index : 3;
uint8_t scale : 2;
};
};
bool osz : 1; /* operand size override prefix */
bool rexw : 1; /* rex.w or rex.wb or etc. 64-bit override */
bool rexb : 1; /* rex.b or rex.wb or etc. see modrm table */
bool rexr : 1; /* rex.r or rex.wr or etc. see modrm table */
bool rex : 1; /* any rex prefix including rex */
bool rexx : 1; /* rex.x or rex.wx or etc. see sib table */
bool rexrr : 1; /* evex */
bool asz : 1; /* address size override */
int64_t disp; /* displacement(%xxx) mostly sign-extended */
uint64_t uimm0; /* $immediate mostly sign-extended */
bool out_of_bytes : 1;
bool is_intel_specific : 1;
bool ild_f2 : 1;
bool ild_f3 : 1;
bool has_sib : 1;
bool realmode : 1;
bool amd3dnow : 1;
bool lock : 1;
union {
uint8_t modrm; /* selects address register */
struct {
uint8_t rm : 3;
uint8_t reg : 3;
uint8_t mod : 2;
};
};
uint8_t max_bytes;
uint8_t rep : 2; /* 0, 2 (0xf2 repnz), 3 (0xf3 rep/repe) */
uint8_t has_modrm : 2;
bool imm_signed : 1; /* internal */
bool disp_unsigned : 1; /* internal */
uint8_t seg_ovd : 3; /* XED_SEG_xx */
uint8_t error : 5; /* enum XedError */
uint8_t mode : 2; /* real,legacy,long */
uint8_t hint : 3; /* static branch prediction */
uint8_t uimm1; /* enter $x,$y */
uint8_t disp_width; /* in bits */
uint8_t imm_width; /* in bits */
uint8_t mode_first_prefix; /* see xed_set_chip_modes() */
uint8_t nrexes;
uint8_t nprefixes;
uint8_t nseg_prefixes;
uint8_t ubit; /* vex */
uint8_t vexvalid; /* vex */
uint8_t vexdest3; /* vex */
uint8_t vexdest4; /* vex */
uint8_t vexdest210; /* vex */
uint8_t vex_prefix; /* vex */
uint8_t zeroing; /* evex */
uint8_t bcrc; /* evex */
uint8_t llrc; /* evex */
uint8_t vl; /* evex */
uint8_t mask; /* evex */
uint8_t imm1_bytes; /* evex */
uint8_t pos_disp;
uint8_t pos_imm;
uint8_t pos_imm1;
uint8_t pos_modrm;
uint8_t pos_opcode;
uint8_t pos_sib;
};
struct XedDecodedInst {
unsigned char length;
uint8_t bytes[15];
struct XedOperands op;
};
#define xed_operands_set_mode(p, machine_mode) \
do { \
struct XedOperands *__p = p; \
__p->realmode = false; \
switch (machine_mode) { \
default: \
case XED_MACHINE_MODE_LONG_64: \
__p->mode = XED_MODE_LONG; \
break; \
case XED_MACHINE_MODE_LEGACY_32: \
case XED_MACHINE_MODE_LONG_COMPAT_32: \
__p->mode = XED_MODE_LEGACY; \
break; \
case XED_MACHINE_MODE_REAL: \
__p->realmode = true; \
__p->mode = XED_MODE_REAL; \
break; \
case XED_MACHINE_MODE_UNREAL: \
__p->realmode = true; \
__p->mode = XED_MODE_LEGACY; \
break; \
case XED_MACHINE_MODE_LEGACY_16: \
case XED_MACHINE_MODE_LONG_COMPAT_16: \
__p->mode = XED_MODE_REAL; \
break; \
} \
} while (0)
extern const char kXedErrorNames[];
extern const uint8_t kXedEamode[2][3];
struct XedDecodedInst *xed_decoded_inst_zero_set_mode(struct XedDecodedInst *,
int);
int xed_instruction_length_decode(struct XedDecodedInst *, const void *,
size_t);
COSMOPOLITAN_C_END_
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
#endif /* COSMOPOLITAN_THIRD_PARTY_XED_X86_H_ */
| 11,486 | 251 | jart/cosmopolitan | false |
cosmopolitan/third_party/xed/x86features.c | /*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-â
âvi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :viâ
ââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââ¡
â Copyright 2018 Intel Corporation â
â Copyright 2019 Justine Alexandra Roberts Tunney â
â â
â Licensed under the Apache License, Version 2.0 (the "License"); â
â you may not use this file except in compliance with the License. â
â You may obtain a copy of the License at â
â â
â http://www.apache.org/licenses/LICENSE-2.0 â
â â
â Unless required by applicable law or agreed to in writing, software â
â distributed under the License is distributed on an "AS IS" BASIS, â
â WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. â
â See the License for the specific language governing permissions and â
â limitations under the License. â
ââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââ*/
#include "third_party/xed/x86isa.h"
asm(".ident\t\"\\n\\n\
Xed (Apache 2.0)\\n\
Copyright 2018 Intel Corporation\\n\
Copyright 2019 Justine Alexandra Roberts Tunney\\n\
Modifications: Trimmed down to 3kb [2019-03-22 jart]\"");
asm(".include \"libc/disclaimer.inc\"");
/**
* Mapping of enum XedChip -> bitset<enum XedIsaSet>.
*
* See related APIs, e.g. xed_isa_set_is_valid_for_chip().
*
* This information can be reproduced by building Xed and running the C
* preprocessor on xed-chip-features-table.c (see xed-chips.txt) which
* turns several thousand lines of non-evolving code into fifty. For
* example, 0x2800000ul was calculated as: 1UL<<(XED_ISA_SET_I86-64) |
* 1UL<<(XED_ISA_SET_LAHF-64).
*/
const uint64_t kXedChipFeatures[XED_CHIP_LAST][3] /* clang-format off */ = {
{0, 0, 0, },
{0, 0x02800000, 0, }, /*I86*/
{0, 0x02800000, 0x02000}, /*I86FP*/
{0, 0x02820000, 0, }, /*I186*/
{0, 0x02820000, 0x02000}, /*I186FP*/
{0, 0x028a0000, 0x02000}, /*I286REAL*/
{0, 0x028e0000, 0x02000}, /*I286*/
{0, 0x028e0000, 0x02000}, /*I2186FP*/
{0, 0x028a0000, 0x02000}, /*I386REAL*/
{0, 0x029e0000, 0x02000}, /*I386*/
{0, 0x029e0000, 0x02000}, /*I386FP*/
{0, 0x02ca0000, 0x02000}, /*I486REAL*/
{0, 0x02fe0000, 0x02000}, /*I486*/
{0, 0x2002ca0000, 0x02000}, /*PENTIUMREAL*/
{0, 0x2002fe0000, 0x02000}, /*PENTIUM*/
{0, 0x2002fe0000, 0x02000}, /*QUARK*/
{0, 0x402002ca0000, 0x02000}, /*PEN..MMXREAL*/
{0, 0x403002fe0000, 0x02000}, /*PENTIUMMMX*/
{0, 0x402002ca0000, 0x02000}, /*ALLREAL*/
{0, 0x492002fe0c80, 0x02000}, /*PENTIUMPRO*/
{0, 0x493002fe4c80, 0x02000}, /*PENTIUM2*/
{0, 0x200493002fe4c80, 0x02006}, /*PENTIUM3*/
{0, 0xe00493202fe4c90, 0x02006}, /*PENTIUM4*/
{0, 0x3e00493216fecd90, 0x02006}, /*P4PRESCOTT*/
{0, 0x3e00493214fecd90, 0x02000}, /*P4PR..NOLAHF*/
{0, 0x3e00493216fecd90, 0x02406}, /*P4PRESC..VTX*/
{0, 0x3f00493216fecd90, 0x0241e}, /*CORE2*/
{0, 0x7f00493216fecd90, 0x0241e}, /*PENRYN*/
{0, 0x7f00493216fecd90, 0x0a41e}, /*PENRYN_E*/
{0, 0xff0249b216fecd90, 0x0241e}, /*NEHALEM*/
{8, 0xff0249b616fecd90, 0x0241e}, /*WESTMERE*/
{0, 0x3e00493256fecd90, 0x0241e}, /*BONNELL*/
{0, 0x3e00493256fecd90, 0x0241e}, /*SALTWELL*/
{8, 0xff02cbb656fecd90, 0x0241e}, /*SILVERMONT*/
{18, 0x00000a0020002040, 0x04061}, /*AMD*/
{8, 0xffc7cbb756fecd98, 0x7a41e}, /*GOLDMONT*/
{8, 0xffd7fbb756fecd98, 0x7a41e}, /*GOLDMONTPLUS*/
{8, 0xfff7fbb7d6ffcdbc, 0x7ac1e}, /*TREMONT*/
{0x2000000000000028, 0xff0249b616fecd90, 0x2a41e}, /*SANDYBRIDGE*/
{0x2000000000000028, 0xff06c9b616fecf90, 0x2a41e}, /*IVYBRIDGE*/
{0xa0000000000000e8, 0xff0ec9b65ffedf91, 0x2a51e}, /*HASWELL*/
{0xa0000000000000ec, 0xff8fcbb65ffedf91, 0x2a51e}, /*BROADWELL*/
{0xa0000000000000ec, 0xff9fcbb75ffedf99, 0x7a51e}, /*SKYLAKE*/
{0xa00000003f3fffec, 0xff9fcbf75ffedfb9, 0x7a51e}, /*SKYL..SERVER*/
{0xa07000003f3fffec, 0xff9fcbf75ffedfb9, 0x7a51e}, /*CASCADE_LAKE*/
{0xa00000007ac080ec, 0xff07cdb65efedf91, 0x2a41e}, /*KNL*/
{0xb0000003fac080ec, 0xff07cdb65efedf91, 0x2a51e}, /*KNM*/
{0xa00e07003f3fffec, 0xffdfcbf75ffedf99, 0x7a51e}, /*CANNONLAKE*/
{0xfffffffc3f3fffec, 0xffdfebf75fffdfb9, 0x7a79e}, /*ICELAKE*/
{0xfffffffc3f3fffec, 0xffffebff5fffdfb9, 0x7b79e}, /*ICEL..SERVER*/
{0xfffffffc3f3fffec, 0xffdffbf75fffdfbb, 0x7a79e}, /*FUTURE*/
{0xfffffffffffffffe, 0xffffffffffffffff, 0x7ffff} /*ALL*/
} /* clang-format on */;
| 6,150 | 93 | jart/cosmopolitan | false |
cosmopolitan/third_party/xed/x86isa.c | /*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-â
âvi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :viâ
ââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââ¡
â Copyright 2018 Intel Corporation â
â Copyright 2019 Justine Alexandra Roberts Tunney â
â â
â Licensed under the Apache License, Version 2.0 (the "License"); â
â you may not use this file except in compliance with the License. â
â You may obtain a copy of the License at â
â â
â http://www.apache.org/licenses/LICENSE-2.0 â
â â
â Unless required by applicable law or agreed to in writing, software â
â distributed under the License is distributed on an "AS IS" BASIS, â
â WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. â
â See the License for the specific language governing permissions and â
â limitations under the License. â
ââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââ*/
#include "third_party/xed/x86.h"
#include "third_party/xed/x86isa.h"
asm(".ident\t\"\\n\\n\
Xed (Apache 2.0)\\n\
Copyright 2018 Intel Corporation\\n\
Copyright 2019 Justine Alexandra Roberts Tunney\\n\
Modifications: Trimmed down to 3kb [2019-03-22 jart]\"");
asm(".include \"libc/disclaimer.inc\"");
bool xed_isa_set_is_valid_for_chip(int isa_set, int chip) {
unsigned n, r;
n = isa_set / 64;
r = isa_set - (64 * n);
return !!(kXedChipFeatures[chip][n] & (1ul << r));
}
bool xed_test_chip_features(struct XedChipFeatures *p, int isa_set) {
unsigned n, r;
n = isa_set / 64;
r = isa_set - (64 * n);
return !!(p->f[n] & (1ul << r));
}
void xed_get_chip_features(struct XedChipFeatures *p, int chip) {
if (p) {
if (chip < XED_CHIP_LAST) {
p->f[0] = kXedChipFeatures[chip][0];
p->f[1] = kXedChipFeatures[chip][1];
p->f[2] = kXedChipFeatures[chip][2];
} else {
p->f[0] = 0;
p->f[1] = 0;
p->f[2] = 0;
}
}
}
| 2,809 | 56 | jart/cosmopolitan | false |
cosmopolitan/third_party/xed/xed.mk | #-*-mode:makefile-gmake;indent-tabs-mode:t;tab-width:8;coding:utf-8-*-â
#âââvi: set et ft=make ts=8 tw=8 fenc=utf-8 :viââââââââââââââââââââââââ
#
# SYNOPSIS
#
# Cosmopolitan x86 Instruction Decoding
#
# DESCRIPTION
#
# See test/libc/xed/x86ild_test.c for more information.
PKGS += THIRD_PARTY_XED
THIRD_PARTY_XED_ARTIFACTS += THIRD_PARTY_XED_A
THIRD_PARTY_XED = $(THIRD_PARTY_XED_A_DEPS) $(THIRD_PARTY_XED_A)
THIRD_PARTY_XED_A = o/$(MODE)/third_party/xed/xed.a
THIRD_PARTY_XED_A_FILES := $(wildcard third_party/xed/*)
THIRD_PARTY_XED_A_HDRS = $(filter %.h,$(THIRD_PARTY_XED_A_FILES))
THIRD_PARTY_XED_A_SRCS = $(filter %.c,$(THIRD_PARTY_XED_A_FILES))
THIRD_PARTY_XED_A_OBJS = $(THIRD_PARTY_XED_A_SRCS:%.c=o/$(MODE)/%.o)
THIRD_PARTY_XED_A_CHECKS = \
$(THIRD_PARTY_XED_A).pkg \
$(THIRD_PARTY_XED_A_HDRS:%=o/$(MODE)/%.ok)
THIRD_PARTY_XED_A_DIRECTDEPS = \
LIBC_INTRIN \
LIBC_NEXGEN32E \
LIBC_STR \
LIBC_STUBS
THIRD_PARTY_XED_A_DEPS := \
$(call uniq,$(foreach x,$(THIRD_PARTY_XED_A_DIRECTDEPS),$($(x))))
ifneq ($(ARCH), aarch64)
o/$(MODE)/third_party/xed/x86ild.greg.o: private \
OVERRIDE_CFLAGS += \
-mstringop-strategy=unrolled_loop
endif
$(THIRD_PARTY_XED_A): \
third_party/xed/ \
$(THIRD_PARTY_XED_A).pkg \
$(THIRD_PARTY_XED_A_OBJS)
$(THIRD_PARTY_XED_A).pkg: \
$(THIRD_PARTY_XED_A_OBJS) \
$(foreach x,$(THIRD_PARTY_XED_A_DIRECTDEPS),$($(x)_A).pkg)
o/$(MODE)/third_party/xed/x86ild.greg.o: private \
OVERRIDE_CFLAGS += \
-O3
HIRD_PARTY_XED_LIBS = $(foreach x,$(THIRD_PARTY_XED_ARTIFACTS),$($(x)))
THIRD_PARTY_XED_SRCS = $(foreach x,$(THIRD_PARTY_XED_ARTIFACTS),$($(x)_SRCS))
THIRD_PARTY_XED_HDRS = $(foreach x,$(THIRD_PARTY_XED_ARTIFACTS),$($(x)_HDRS))
THIRD_PARTY_XED_CHECKS = $(foreach x,$(THIRD_PARTY_XED_ARTIFACTS),$($(x)_CHECKS))
THIRD_PARTY_XED_OBJS = $(foreach x,$(THIRD_PARTY_XED_ARTIFACTS),$($(x)_OBJS))
$(THIRD_PARTY_XED_OBJS): $(BUILD_FILES) third_party/xed/xed.mk
.PHONY: o/$(MODE)/third_party/xed
o/$(MODE)/third_party/xed: $(THIRD_PARTY_XED_CHECKS)
| 2,096 | 63 | jart/cosmopolitan | false |
cosmopolitan/third_party/xed/xederror.c | /*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-â
âvi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :viâ
ââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââ¡
â Copyright 2020 Justine Alexandra Roberts Tunney â
â â
â Permission to use, copy, modify, and/or distribute this software for â
â any purpose with or without fee is hereby granted, provided that the â
â above copyright notice and this permission notice appear in all copies. â
â â
â THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL â
â WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED â
â WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE â
â AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL â
â DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR â
â PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER â
â TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR â
â PERFORMANCE OF THIS SOFTWARE. â
ââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââ*/
#include "third_party/xed/x86.h"
/**
* Xed error code names.
*
* puts(IndexDoubleNulString(kXedErrorNames, xedd->op.error));
*
* @see XedError
*/
const char kXedErrorNames[] = "\
none\0\
buffer too short\0\
general error\0\
invalid for chip\0\
bad register\0\
bad lock prefix\0\
bad rep prefix\0\
bad legacy prefix\0\
bad rex prefix\0\
bad evex ubit\0\
bad map\0\
bad evex v prime\0\
bad evex z no masking\0\
no output pointer\0\
no agen call back registered\0\
bad memop index\0\
callback problem\0\
gather regs\0\
instr too long\0\
invalid mode\0\
bad evex ll\0\
unimplemented\0\
";
| 2,430 | 52 | jart/cosmopolitan | false |
cosmopolitan/third_party/xed/avx512.h | #ifndef COSMOPOLITAN_THIRD_PARTY_XED_AVX512_H_
#define COSMOPOLITAN_THIRD_PARTY_XED_AVX512_H_
#if !(__ASSEMBLER__ + __LINKER__ + 0)
COSMOPOLITAN_C_START_
union XedAvx512Payload1 {
struct {
unsigned map : 4;
unsigned rr_inv : 1;
unsigned b_inv : 1;
unsigned x_inv : 1;
unsigned r_inv : 1;
unsigned pad : 24;
} s;
unsigned u32;
};
union XedAvx512Payload2 {
struct {
unsigned pp : 2;
unsigned ubit : 1;
unsigned vexdest210 : 3;
unsigned vexdest3 : 1;
unsigned rexw : 1;
unsigned pad : 24;
} s;
unsigned u32;
};
union XedAvx512Payload3 {
struct {
unsigned mask : 3;
unsigned vexdest4p : 1;
unsigned bcrc : 1;
unsigned llrc : 2;
unsigned z : 1;
unsigned pad : 24;
} s;
unsigned u32;
};
COSMOPOLITAN_C_END_
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
#endif /* COSMOPOLITAN_THIRD_PARTY_XED_AVX512_H_ */
| 894 | 45 | jart/cosmopolitan | false |
cosmopolitan/third_party/xed/private.h | #ifndef COSMOPOLITAN_THIRD_PARTY_XED_PRIVATE_H_
#define COSMOPOLITAN_THIRD_PARTY_XED_PRIVATE_H_
#include "third_party/xed/x86.h"
#if !(__ASSEMBLER__ + __LINKER__ + 0)
COSMOPOLITAN_C_START_
typedef int xed_int_t;
typedef unsigned int xed_uint_t;
typedef unsigned int xed_uint_t;
typedef unsigned char xed_bits_t;
typedef intptr_t xed_addr_t;
typedef bool xed_bool_t;
COSMOPOLITAN_C_END_
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
#endif /* COSMOPOLITAN_THIRD_PARTY_XED_PRIVATE_H_ */
| 488 | 17 | jart/cosmopolitan | false |
cosmopolitan/third_party/double-conversion/diy-fp.h | // -*- c++ -*-
#ifndef DOUBLE_CONVERSION_DIY_FP_H_
#define DOUBLE_CONVERSION_DIY_FP_H_
#include "third_party/double-conversion/utils.h"
// clang-format off
namespace double_conversion {
// This "Do It Yourself Floating Point" class implements a floating-point number
// with a uint64 significand and an int exponent. Normalized DiyFp numbers will
// have the most significant bit of the significand set.
// Multiplication and Subtraction do not normalize their results.
// DiyFp store only non-negative numbers and are not designed to contain special
// doubles (NaN and Infinity).
class DiyFp {
public:
static const int kSignificandSize = 64;
DiyFp() : f_(0), e_(0) {}
DiyFp(const uint64_t significand, const int32_t exponent) : f_(significand), e_(exponent) {}
// this -= other.
// The exponents of both numbers must be the same and the significand of this
// must be greater or equal than the significand of other.
// The result will not be normalized.
void Subtract(const DiyFp& other) {
DOUBLE_CONVERSION_ASSERT(e_ == other.e_);
DOUBLE_CONVERSION_ASSERT(f_ >= other.f_);
f_ -= other.f_;
}
// Returns a - b.
// The exponents of both numbers must be the same and a must be greater
// or equal than b. The result will not be normalized.
static DiyFp Minus(const DiyFp& a, const DiyFp& b) {
DiyFp result = a;
result.Subtract(b);
return result;
}
// this *= other.
void Multiply(const DiyFp& other) {
// Simply "emulates" a 128 bit multiplication.
// However: the resulting number only contains 64 bits. The least
// significant 64 bits are only used for rounding the most significant 64
// bits.
const uint64_t kM32 = 0xFFFFFFFFU;
const uint64_t a = f_ >> 32;
const uint64_t b = f_ & kM32;
const uint64_t c = other.f_ >> 32;
const uint64_t d = other.f_ & kM32;
const uint64_t ac = a * c;
const uint64_t bc = b * c;
const uint64_t ad = a * d;
const uint64_t bd = b * d;
// By adding 1U << 31 to tmp we round the final result.
// Halfway cases will be rounded up.
const uint64_t tmp = (bd >> 32) + (ad & kM32) + (bc & kM32) + (1U << 31);
e_ += other.e_ + 64;
f_ = ac + (ad >> 32) + (bc >> 32) + (tmp >> 32);
}
// returns a * b;
static DiyFp Times(const DiyFp& a, const DiyFp& b) {
DiyFp result = a;
result.Multiply(b);
return result;
}
void Normalize() {
DOUBLE_CONVERSION_ASSERT(f_ != 0);
uint64_t significand = f_;
int32_t exponent = e_;
// This method is mainly called for normalizing boundaries. In general,
// boundaries need to be shifted by 10 bits, and we optimize for this case.
const uint64_t k10MSBits = DOUBLE_CONVERSION_UINT64_2PART_C(0xFFC00000, 00000000);
while ((significand & k10MSBits) == 0) {
significand <<= 10;
exponent -= 10;
}
while ((significand & kUint64MSB) == 0) {
significand <<= 1;
exponent--;
}
f_ = significand;
e_ = exponent;
}
static DiyFp Normalize(const DiyFp& a) {
DiyFp result = a;
result.Normalize();
return result;
}
uint64_t f() const { return f_; }
int32_t e() const { return e_; }
void set_f(uint64_t new_value) { f_ = new_value; }
void set_e(int32_t new_value) { e_ = new_value; }
private:
static const uint64_t kUint64MSB = DOUBLE_CONVERSION_UINT64_2PART_C(0x80000000, 00000000);
uint64_t f_;
int32_t e_;
};
} // namespace double_conversion
#endif // DOUBLE_CONVERSION_DIY_FP_H_
| 3,496 | 112 | jart/cosmopolitan | false |
cosmopolitan/third_party/double-conversion/string-to-double.cc | // Copyright 2010 the V8 project authors. All rights reserved.
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following
// disclaimer in the documentation and/or other materials provided
// with the distribution.
// * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "third_party/double-conversion/ieee.h"
#include "third_party/double-conversion/string-to-double.h"
#include "third_party/double-conversion/strtod.h"
#include "third_party/double-conversion/utils.h"
#include "third_party/libcxx/climits"
#include "third_party/libcxx/cmath"
#include "third_party/libcxx/locale"
// clang-format off
asm(".ident\t\"\\n\\n\
double-conversion (BSD-3 License)\\n\
Copyright 2006-2012 the V8 project authors\"");
asm(".include \"libc/disclaimer.inc\"");
#ifdef _MSC_VER
# if _MSC_VER >= 1900
// Fix MSVC >= 2015 (_MSC_VER == 1900) warning
// C4244: 'argument': conversion from 'const uc16' to 'char', possible loss of data
// against Advance and friends, when instantiated with **it as char, not uc16.
__pragma(warning(disable: 4244))
# endif
# if _MSC_VER <= 1700 // VS2012, see IsDecimalDigitForRadix warning fix, below
# define VS2012_RADIXWARN
# endif
#endif
namespace double_conversion {
namespace {
inline char ToLower(char ch) {
/* static const std::ctype<char>& cType =
std::use_facet<std::ctype<char> >(std::locale::classic());
return cType.tolower(ch); */
return tolower(ch);
}
inline char Pass(char ch) {
return ch;
}
template <class Iterator, class Converter>
static inline bool ConsumeSubStringImpl(Iterator* current,
Iterator end,
const char* substring,
Converter converter) {
DOUBLE_CONVERSION_ASSERT(converter(**current) == *substring);
for (substring++; *substring != '\0'; substring++) {
++*current;
if (*current == end || converter(**current) != *substring) {
return false;
}
}
++*current;
return true;
}
// Consumes the given substring from the iterator.
// Returns false, if the substring does not match.
template <class Iterator>
static bool ConsumeSubString(Iterator* current,
Iterator end,
const char* substring,
bool allow_case_insensitivity) {
if (allow_case_insensitivity) {
return ConsumeSubStringImpl(current, end, substring, ToLower);
} else {
return ConsumeSubStringImpl(current, end, substring, Pass);
}
}
// Consumes first character of the str is equal to ch
inline bool ConsumeFirstCharacter(char ch,
const char* str,
bool case_insensitivity) {
return case_insensitivity ? ToLower(ch) == str[0] : ch == str[0];
}
} // namespace
// Maximum number of significant digits in decimal representation.
// The longest possible double in decimal representation is
// (2^53 - 1) * 2 ^ -1074 that is (2 ^ 53 - 1) * 5 ^ 1074 / 10 ^ 1074
// (768 digits). If we parse a number whose first digits are equal to a
// mean of 2 adjacent doubles (that could have up to 769 digits) the result
// must be rounded to the bigger one unless the tail consists of zeros, so
// we don't need to preserve all the digits.
const int kMaxSignificantDigits = 772;
static const char kWhitespaceTable7[] = { 32, 13, 10, 9, 11, 12 };
static const int kWhitespaceTable7Length = DOUBLE_CONVERSION_ARRAY_SIZE(kWhitespaceTable7);
static const uc16 kWhitespaceTable16[] = {
160, 8232, 8233, 5760, 6158, 8192, 8193, 8194, 8195,
8196, 8197, 8198, 8199, 8200, 8201, 8202, 8239, 8287, 12288, 65279
};
static const int kWhitespaceTable16Length = DOUBLE_CONVERSION_ARRAY_SIZE(kWhitespaceTable16);
static bool isWhitespace(int x) {
if (x < 128) {
for (int i = 0; i < kWhitespaceTable7Length; i++) {
if (kWhitespaceTable7[i] == x) return true;
}
} else {
for (int i = 0; i < kWhitespaceTable16Length; i++) {
if (kWhitespaceTable16[i] == x) return true;
}
}
return false;
}
// Returns true if a nonspace found and false if the end has reached.
template <class Iterator>
static inline bool AdvanceToNonspace(Iterator* current, Iterator end) {
while (*current != end) {
if (!isWhitespace(**current)) return true;
++*current;
}
return false;
}
static bool isDigit(int x, int radix) {
return (x >= '0' && x <= '9' && x < '0' + radix)
|| (radix > 10 && x >= 'a' && x < 'a' + radix - 10)
|| (radix > 10 && x >= 'A' && x < 'A' + radix - 10);
}
static double SignedZero(bool sign) {
return sign ? -0.0 : 0.0;
}
// Returns true if 'c' is a decimal digit that is valid for the given radix.
//
// The function is small and could be inlined, but VS2012 emitted a warning
// because it constant-propagated the radix and concluded that the last
// condition was always true. Moving it into a separate function and
// suppressing optimisation keeps the compiler from warning.
#ifdef VS2012_RADIXWARN
#pragma optimize("",off)
static bool IsDecimalDigitForRadix(int c, int radix) {
return '0' <= c && c <= '9' && (c - '0') < radix;
}
#pragma optimize("",on)
#else
static bool inline IsDecimalDigitForRadix(int c, int radix) {
return '0' <= c && c <= '9' && (c - '0') < radix;
}
#endif
// Returns true if 'c' is a character digit that is valid for the given radix.
// The 'a_character' should be 'a' or 'A'.
//
// The function is small and could be inlined, but VS2012 emitted a warning
// because it constant-propagated the radix and concluded that the first
// condition was always false. By moving it into a separate function the
// compiler wouldn't warn anymore.
static bool IsCharacterDigitForRadix(int c, int radix, char a_character) {
return radix > 10 && c >= a_character && c < a_character + radix - 10;
}
// Returns true, when the iterator is equal to end.
template<class Iterator>
static bool Advance (Iterator* it, uc16 separator, int base, Iterator& end) {
if (separator == StringToDoubleConverter::kNoSeparator) {
++(*it);
return *it == end;
}
if (!isDigit(**it, base)) {
++(*it);
return *it == end;
}
++(*it);
if (*it == end) return true;
if (*it + 1 == end) return false;
if (**it == separator && isDigit(*(*it + 1), base)) {
++(*it);
}
return *it == end;
}
// Checks whether the string in the range start-end is a hex-float string.
// This function assumes that the leading '0x'/'0X' is already consumed.
//
// Hex float strings are of one of the following forms:
// - hex_digits+ 'p' ('+'|'-')? exponent_digits+
// - hex_digits* '.' hex_digits+ 'p' ('+'|'-')? exponent_digits+
// - hex_digits+ '.' 'p' ('+'|'-')? exponent_digits+
template<class Iterator>
static bool IsHexFloatString(Iterator start,
Iterator end,
uc16 separator,
bool allow_trailing_junk) {
DOUBLE_CONVERSION_ASSERT(start != end);
Iterator current = start;
bool saw_digit = false;
while (isDigit(*current, 16)) {
saw_digit = true;
if (Advance(¤t, separator, 16, end)) return false;
}
if (*current == '.') {
if (Advance(¤t, separator, 16, end)) return false;
while (isDigit(*current, 16)) {
saw_digit = true;
if (Advance(¤t, separator, 16, end)) return false;
}
}
if (!saw_digit) return false;
if (*current != 'p' && *current != 'P') return false;
if (Advance(¤t, separator, 16, end)) return false;
if (*current == '+' || *current == '-') {
if (Advance(¤t, separator, 16, end)) return false;
}
if (!isDigit(*current, 10)) return false;
if (Advance(¤t, separator, 16, end)) return true;
while (isDigit(*current, 10)) {
if (Advance(¤t, separator, 16, end)) return true;
}
return allow_trailing_junk || !AdvanceToNonspace(¤t, end);
}
// Parsing integers with radix 2, 4, 8, 16, 32. Assumes current != end.
//
// If parse_as_hex_float is true, then the string must be a valid
// hex-float.
template <int radix_log_2, class Iterator>
static double RadixStringToIeee(Iterator* current,
Iterator end,
bool sign,
uc16 separator,
bool parse_as_hex_float,
bool allow_trailing_junk,
double junk_string_value,
bool read_as_double,
bool* result_is_junk) {
DOUBLE_CONVERSION_ASSERT(*current != end);
DOUBLE_CONVERSION_ASSERT(!parse_as_hex_float ||
IsHexFloatString(*current, end, separator, allow_trailing_junk));
const int kDoubleSize = Double::kSignificandSize;
const int kSingleSize = Single::kSignificandSize;
const int kSignificandSize = read_as_double? kDoubleSize: kSingleSize;
*result_is_junk = true;
int64_t number = 0;
int exponent = 0;
const int radix = (1 << radix_log_2);
// Whether we have encountered a '.' and are parsing the decimal digits.
// Only relevant if parse_as_hex_float is true.
bool post_decimal = false;
// Skip leading 0s.
while (**current == '0') {
if (Advance(current, separator, radix, end)) {
*result_is_junk = false;
return SignedZero(sign);
}
}
while (true) {
int digit;
if (IsDecimalDigitForRadix(**current, radix)) {
digit = static_cast<char>(**current) - '0';
if (post_decimal) exponent -= radix_log_2;
} else if (IsCharacterDigitForRadix(**current, radix, 'a')) {
digit = static_cast<char>(**current) - 'a' + 10;
if (post_decimal) exponent -= radix_log_2;
} else if (IsCharacterDigitForRadix(**current, radix, 'A')) {
digit = static_cast<char>(**current) - 'A' + 10;
if (post_decimal) exponent -= radix_log_2;
} else if (parse_as_hex_float && **current == '.') {
post_decimal = true;
Advance(current, separator, radix, end);
DOUBLE_CONVERSION_ASSERT(*current != end);
continue;
} else if (parse_as_hex_float && (**current == 'p' || **current == 'P')) {
break;
} else {
if (allow_trailing_junk || !AdvanceToNonspace(current, end)) {
break;
} else {
return junk_string_value;
}
}
number = number * radix + digit;
int overflow = static_cast<int>(number >> kSignificandSize);
if (overflow != 0) {
// Overflow occurred. Need to determine which direction to round the
// result.
int overflow_bits_count = 1;
while (overflow > 1) {
overflow_bits_count++;
overflow >>= 1;
}
int dropped_bits_mask = ((1 << overflow_bits_count) - 1);
int dropped_bits = static_cast<int>(number) & dropped_bits_mask;
number >>= overflow_bits_count;
exponent += overflow_bits_count;
bool zero_tail = true;
for (;;) {
if (Advance(current, separator, radix, end)) break;
if (parse_as_hex_float && **current == '.') {
// Just run over the '.'. We are just trying to see whether there is
// a non-zero digit somewhere.
Advance(current, separator, radix, end);
DOUBLE_CONVERSION_ASSERT(*current != end);
post_decimal = true;
}
if (!isDigit(**current, radix)) break;
zero_tail = zero_tail && **current == '0';
if (!post_decimal) exponent += radix_log_2;
}
if (!parse_as_hex_float &&
!allow_trailing_junk &&
AdvanceToNonspace(current, end)) {
return junk_string_value;
}
int middle_value = (1 << (overflow_bits_count - 1));
if (dropped_bits > middle_value) {
number++; // Rounding up.
} else if (dropped_bits == middle_value) {
// Rounding to even to consistency with decimals: half-way case rounds
// up if significant part is odd and down otherwise.
if ((number & 1) != 0 || !zero_tail) {
number++; // Rounding up.
}
}
// Rounding up may cause overflow.
if ((number & ((int64_t)1 << kSignificandSize)) != 0) {
exponent++;
number >>= 1;
}
break;
}
if (Advance(current, separator, radix, end)) break;
}
DOUBLE_CONVERSION_ASSERT(number < ((int64_t)1 << kSignificandSize));
DOUBLE_CONVERSION_ASSERT(static_cast<int64_t>(static_cast<double>(number)) == number);
*result_is_junk = false;
if (parse_as_hex_float) {
DOUBLE_CONVERSION_ASSERT(**current == 'p' || **current == 'P');
Advance(current, separator, radix, end);
DOUBLE_CONVERSION_ASSERT(*current != end);
bool is_negative = false;
if (**current == '+') {
Advance(current, separator, radix, end);
DOUBLE_CONVERSION_ASSERT(*current != end);
} else if (**current == '-') {
is_negative = true;
Advance(current, separator, radix, end);
DOUBLE_CONVERSION_ASSERT(*current != end);
}
int written_exponent = 0;
while (IsDecimalDigitForRadix(**current, 10)) {
// No need to read exponents if they are too big. That could potentially overflow
// the `written_exponent` variable.
if (abs(written_exponent) <= 100 * Double::kMaxExponent) {
written_exponent = 10 * written_exponent + **current - '0';
}
if (Advance(current, separator, radix, end)) break;
}
if (is_negative) written_exponent = -written_exponent;
exponent += written_exponent;
}
if (exponent == 0 || number == 0) {
if (sign) {
if (number == 0) return -0.0;
number = -number;
}
return static_cast<double>(number);
}
DOUBLE_CONVERSION_ASSERT(number != 0);
double result = Double(DiyFp(number, exponent)).value();
return sign ? -result : result;
}
template <class Iterator>
double StringToDoubleConverter::StringToIeee(
Iterator input,
int length,
bool read_as_double,
int* processed_characters_count) const {
Iterator current = input;
Iterator end = input + length;
*processed_characters_count = 0;
const bool allow_trailing_junk = (flags_ & ALLOW_TRAILING_JUNK) != 0;
const bool allow_leading_spaces = (flags_ & ALLOW_LEADING_SPACES) != 0;
const bool allow_trailing_spaces = (flags_ & ALLOW_TRAILING_SPACES) != 0;
const bool allow_spaces_after_sign = (flags_ & ALLOW_SPACES_AFTER_SIGN) != 0;
const bool allow_case_insensitivity = (flags_ & ALLOW_CASE_INSENSITIVITY) != 0;
// To make sure that iterator dereferencing is valid the following
// convention is used:
// 1. Each '++current' statement is followed by check for equality to 'end'.
// 2. If AdvanceToNonspace returned false then current == end.
// 3. If 'current' becomes equal to 'end' the function returns or goes to
// 'parsing_done'.
// 4. 'current' is not dereferenced after the 'parsing_done' label.
// 5. Code before 'parsing_done' may rely on 'current != end'.
if (current == end) return empty_string_value_;
if (allow_leading_spaces || allow_trailing_spaces) {
if (!AdvanceToNonspace(¤t, end)) {
*processed_characters_count = static_cast<int>(current - input);
return empty_string_value_;
}
if (!allow_leading_spaces && (input != current)) {
// No leading spaces allowed, but AdvanceToNonspace moved forward.
return junk_string_value_;
}
}
// Exponent will be adjusted if insignificant digits of the integer part
// or insignificant leading zeros of the fractional part are dropped.
int exponent = 0;
int significant_digits = 0;
int insignificant_digits = 0;
bool nonzero_digit_dropped = false;
bool sign = false;
if (*current == '+' || *current == '-') {
sign = (*current == '-');
++current;
Iterator next_non_space = current;
// Skip following spaces (if allowed).
if (!AdvanceToNonspace(&next_non_space, end)) return junk_string_value_;
if (!allow_spaces_after_sign && (current != next_non_space)) {
return junk_string_value_;
}
current = next_non_space;
}
if (infinity_symbol_ != NULL) {
if (ConsumeFirstCharacter(*current, infinity_symbol_, allow_case_insensitivity)) {
if (!ConsumeSubString(¤t, end, infinity_symbol_, allow_case_insensitivity)) {
return junk_string_value_;
}
if (!(allow_trailing_spaces || allow_trailing_junk) && (current != end)) {
return junk_string_value_;
}
if (!allow_trailing_junk && AdvanceToNonspace(¤t, end)) {
return junk_string_value_;
}
*processed_characters_count = static_cast<int>(current - input);
return sign ? -Double::Infinity() : Double::Infinity();
}
}
if (nan_symbol_ != NULL) {
if (ConsumeFirstCharacter(*current, nan_symbol_, allow_case_insensitivity)) {
if (!ConsumeSubString(¤t, end, nan_symbol_, allow_case_insensitivity)) {
return junk_string_value_;
}
if (!(allow_trailing_spaces || allow_trailing_junk) && (current != end)) {
return junk_string_value_;
}
if (!allow_trailing_junk && AdvanceToNonspace(¤t, end)) {
return junk_string_value_;
}
*processed_characters_count = static_cast<int>(current - input);
return sign ? -Double::NaN() : Double::NaN();
}
}
bool leading_zero = false;
if (*current == '0') {
if (Advance(¤t, separator_, 10, end)) {
*processed_characters_count = static_cast<int>(current - input);
return SignedZero(sign);
}
leading_zero = true;
// It could be hexadecimal value.
if (((flags_ & ALLOW_HEX) || (flags_ & ALLOW_HEX_FLOATS)) &&
(*current == 'x' || *current == 'X')) {
++current;
if (current == end) return junk_string_value_; // "0x"
bool parse_as_hex_float = (flags_ & ALLOW_HEX_FLOATS) &&
IsHexFloatString(current, end, separator_, allow_trailing_junk);
if (!parse_as_hex_float && !isDigit(*current, 16)) {
return junk_string_value_;
}
bool result_is_junk;
double result = RadixStringToIeee<4>(¤t,
end,
sign,
separator_,
parse_as_hex_float,
allow_trailing_junk,
junk_string_value_,
read_as_double,
&result_is_junk);
if (!result_is_junk) {
if (allow_trailing_spaces) AdvanceToNonspace(¤t, end);
*processed_characters_count = static_cast<int>(current - input);
}
return result;
}
// Ignore leading zeros in the integer part.
while (*current == '0') {
if (Advance(¤t, separator_, 10, end)) {
*processed_characters_count = static_cast<int>(current - input);
return SignedZero(sign);
}
}
}
bool octal = leading_zero && (flags_ & ALLOW_OCTALS) != 0;
// The longest form of simplified number is: "-<significant digits>.1eXXX\0".
const int kBufferSize = kMaxSignificantDigits + 10;
DOUBLE_CONVERSION_STACK_UNINITIALIZED char
buffer[kBufferSize]; // NOLINT: size is known at compile time.
int buffer_pos = 0;
// Copy significant digits of the integer part (if any) to the buffer.
while (*current >= '0' && *current <= '9') {
if (significant_digits < kMaxSignificantDigits) {
DOUBLE_CONVERSION_ASSERT(buffer_pos < kBufferSize);
buffer[buffer_pos++] = static_cast<char>(*current);
significant_digits++;
// Will later check if it's an octal in the buffer.
} else {
insignificant_digits++; // Move the digit into the exponential part.
nonzero_digit_dropped = nonzero_digit_dropped || *current != '0';
}
octal = octal && *current < '8';
if (Advance(¤t, separator_, 10, end)) goto parsing_done;
}
if (significant_digits == 0) {
octal = false;
}
if (*current == '.') {
if (octal && !allow_trailing_junk) return junk_string_value_;
if (octal) goto parsing_done;
if (Advance(¤t, separator_, 10, end)) {
if (significant_digits == 0 && !leading_zero) {
return junk_string_value_;
} else {
goto parsing_done;
}
}
if (significant_digits == 0) {
// octal = false;
// Integer part consists of 0 or is absent. Significant digits start after
// leading zeros (if any).
while (*current == '0') {
if (Advance(¤t, separator_, 10, end)) {
*processed_characters_count = static_cast<int>(current - input);
return SignedZero(sign);
}
exponent--; // Move this 0 into the exponent.
}
}
// There is a fractional part.
// We don't emit a '.', but adjust the exponent instead.
while (*current >= '0' && *current <= '9') {
if (significant_digits < kMaxSignificantDigits) {
DOUBLE_CONVERSION_ASSERT(buffer_pos < kBufferSize);
buffer[buffer_pos++] = static_cast<char>(*current);
significant_digits++;
exponent--;
} else {
// Ignore insignificant digits in the fractional part.
nonzero_digit_dropped = nonzero_digit_dropped || *current != '0';
}
if (Advance(¤t, separator_, 10, end)) goto parsing_done;
}
}
if (!leading_zero && exponent == 0 && significant_digits == 0) {
// If leading_zeros is true then the string contains zeros.
// If exponent < 0 then string was [+-]\.0*...
// If significant_digits != 0 the string is not equal to 0.
// Otherwise there are no digits in the string.
return junk_string_value_;
}
// Parse exponential part.
if (*current == 'e' || *current == 'E') {
if (octal && !allow_trailing_junk) return junk_string_value_;
if (octal) goto parsing_done;
Iterator junk_begin = current;
++current;
if (current == end) {
if (allow_trailing_junk) {
current = junk_begin;
goto parsing_done;
} else {
return junk_string_value_;
}
}
char exponen_sign = '+';
if (*current == '+' || *current == '-') {
exponen_sign = static_cast<char>(*current);
++current;
if (current == end) {
if (allow_trailing_junk) {
current = junk_begin;
goto parsing_done;
} else {
return junk_string_value_;
}
}
}
if (current == end || *current < '0' || *current > '9') {
if (allow_trailing_junk) {
current = junk_begin;
goto parsing_done;
} else {
return junk_string_value_;
}
}
const int max_exponent = INT_MAX / 2;
DOUBLE_CONVERSION_ASSERT(-max_exponent / 2 <= exponent && exponent <= max_exponent / 2);
int num = 0;
do {
// Check overflow.
int digit = *current - '0';
if (num >= max_exponent / 10
&& !(num == max_exponent / 10 && digit <= max_exponent % 10)) {
num = max_exponent;
} else {
num = num * 10 + digit;
}
++current;
} while (current != end && *current >= '0' && *current <= '9');
exponent += (exponen_sign == '-' ? -num : num);
}
if (!(allow_trailing_spaces || allow_trailing_junk) && (current != end)) {
return junk_string_value_;
}
if (!allow_trailing_junk && AdvanceToNonspace(¤t, end)) {
return junk_string_value_;
}
if (allow_trailing_spaces) {
AdvanceToNonspace(¤t, end);
}
parsing_done:
exponent += insignificant_digits;
if (octal) {
double result;
bool result_is_junk;
char* start = buffer;
result = RadixStringToIeee<3>(&start,
buffer + buffer_pos,
sign,
separator_,
false, // Don't parse as hex_float.
allow_trailing_junk,
junk_string_value_,
read_as_double,
&result_is_junk);
DOUBLE_CONVERSION_ASSERT(!result_is_junk);
*processed_characters_count = static_cast<int>(current - input);
return result;
}
if (nonzero_digit_dropped) {
buffer[buffer_pos++] = '1';
exponent--;
}
DOUBLE_CONVERSION_ASSERT(buffer_pos < kBufferSize);
buffer[buffer_pos] = '\0';
// Code above ensures there are no leading zeros and the buffer has fewer than
// kMaxSignificantDecimalDigits characters. Trim trailing zeros.
Vector<const char> chars(buffer, buffer_pos);
chars = TrimTrailingZeros(chars);
exponent += buffer_pos - chars.length();
double converted;
if (read_as_double) {
converted = StrtodTrimmed(chars, exponent);
} else {
converted = StrtofTrimmed(chars, exponent);
}
*processed_characters_count = static_cast<int>(current - input);
return sign? -converted: converted;
}
double StringToDoubleConverter::StringToDouble(
const char* buffer,
int length,
int* processed_characters_count) const {
return StringToIeee(buffer, length, true, processed_characters_count);
}
double StringToDoubleConverter::StringToDouble(
const uc16* buffer,
int length,
int* processed_characters_count) const {
return StringToIeee(buffer, length, true, processed_characters_count);
}
float StringToDoubleConverter::StringToFloat(
const char* buffer,
int length,
int* processed_characters_count) const {
return static_cast<float>(StringToIeee(buffer, length, false,
processed_characters_count));
}
float StringToDoubleConverter::StringToFloat(
const uc16* buffer,
int length,
int* processed_characters_count) const {
return static_cast<float>(StringToIeee(buffer, length, false,
processed_characters_count));
}
template<>
double StringToDoubleConverter::StringTo<double>(
const char* buffer,
int length,
int* processed_characters_count) const {
return StringToDouble(buffer, length, processed_characters_count);
}
template<>
float StringToDoubleConverter::StringTo<float>(
const char* buffer,
int length,
int* processed_characters_count) const {
return StringToFloat(buffer, length, processed_characters_count);
}
template<>
double StringToDoubleConverter::StringTo<double>(
const uc16* buffer,
int length,
int* processed_characters_count) const {
return StringToDouble(buffer, length, processed_characters_count);
}
template<>
float StringToDoubleConverter::StringTo<float>(
const uc16* buffer,
int length,
int* processed_characters_count) const {
return StringToFloat(buffer, length, processed_characters_count);
}
} // namespace double_conversion
| 28,230 | 823 | jart/cosmopolitan | false |
Subsets and Splits
No saved queries yet
Save your SQL queries to embed, download, and access them later. Queries will appear here once saved.