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/gcc/aarch64-linux-musl/bin/strip.sym | ../../bin/aarch64-linux-musl-strip | 34 | 1 | jart/cosmopolitan | false |
cosmopolitan/third_party/gcc/aarch64-linux-musl/bin/ld.sym | ld.bfd | 6 | 1 | jart/cosmopolitan | false |
cosmopolitan/third_party/gcc/aarch64-linux-musl/bin/ranlib.sym | ../../bin/aarch64-linux-musl-ranlib | 35 | 1 | jart/cosmopolitan | false |
cosmopolitan/third_party/gcc/libexec/gcc/aarch64-linux-musl/9.2.0/collect-ld.sym | ../../../../x86_64-linux-musl/bin/ld.bfd
| 41 | 2 | jart/cosmopolitan | false |
cosmopolitan/third_party/gcc/libexec/gcc/aarch64-linux-musl/9.2.0/as.sym | ../../../../bin/aarch64-linux-musl-as | 37 | 1 | jart/cosmopolitan | false |
cosmopolitan/third_party/gcc/libexec/gcc/aarch64-linux-musl/9.2.0/ld.sym | ../../../../bin/aarch64-linux-musl-ld.bfd | 41 | 1 | jart/cosmopolitan | false |
cosmopolitan/third_party/gcc/libexec/gcc/x86_64-linux-musl/9.2.0/as.sym | ../../../../bin/x86_64-linux-musl-as | 36 | 1 | jart/cosmopolitan | false |
cosmopolitan/third_party/gcc/lib/gcc/x86_64-linux-musl/9.2.0/specs | *asm:
%{m16|m32:--32} %{m16|m32:;:--64} %{msse2avx:%{!mavx:-msse2avx}}
*asm_debug:
%{%:debug-level-gt(0):%{gstabs*:--gstabs}%{!gstabs*:%{g*:--gdwarf2}}} %{fdebug-prefix-map=*:--debug-prefix-map %*}
*asm_final:
%{gsplit-dwarf:
objcopy --extract-dwo %{c:%{o*:%*}%{!o*:%b%O}}%{!c:%U%O} %{c:%{o*:%:replace-extension(%{o*:%*} .dwo)}%{!o*:%b.dwo}}%{!c:%b.dwo}
objcopy --strip-dwo %{c:%{o*:%*}%{!o*:%b%O}}%{!c:%U%O} }
*asm_options:
%{-target-help:%:print-asm-header()} %{v} %{w:-W} %{I*} %{gz|gz=zlib:--compress-debug-sections=zlib} %{gz=none:--compress-debug-sections=none} %{gz=zlib-gnu:--compress-debug-sections=zlib-gnu} %a %Y %{c:%W{o*}%{!o*:-o %w%b%O}}%{!c:-o %d%w%u%O}
*invoke_as:
%{!fwpa*: %{fcompare-debug=*|fdump-final-insns=*:%:compare-debug-dump-opt()} %{!S:-o %|.s |
as %(asm_options) %m.s %A } }
*cpp:
%{posix:-D_POSIX_SOURCE} %{pthread:-D_REENTRANT}
*cpp_options:
%(cpp_unique_options) %1 %{m*} %{std*&ansi&trigraphs} %{W*&pedantic*} %{w} %{f*} %{g*:%{%:debug-level-gt(0):%{g*} %{!fno-working-directory:-fworking-directory}}} %{O*} %{undef} %{save-temps*:-fpch-preprocess}
*cpp_debug_options:
%{d*}
*cpp_unique_options:
%{!Q:-quiet} %{nostdinc*} %{C} %{CC} %{v} %@{I*&F*} %{P} %I %{MD:-MD %{!o:%b.d}%{o*:%.d%*}} %{MMD:-MMD %{!o:%b.d}%{o*:%.d%*}} %{M} %{MM} %{MF*} %{MG} %{MP} %{MQ*} %{MT*} %{!E:%{!M:%{!MM:%{!MT:%{!MQ:%{MD|MMD:%{o*:-MQ %*}}}}}}} %{remap} %{g3|ggdb3|gstabs3|gxcoff3|gvms3:-dD} %{!iplugindir*:%{fplugin*:%:find-plugindir()}} %{H} %C %{D*&U*&A*} %{i*} %Z %i %{E|M|MM:%W{o*}}
*trad_capable_cpp:
cc1 -E %{traditional|traditional-cpp:-traditional-cpp}
*cc1:
%{!mandroid|tno-android-cc:%(cc1_cpu) %{profile:-p};:%(cc1_cpu) %{profile:-p} %{!fno-pic:%{!fno-PIC:%{!fpic:%{!fPIC: -fPIC}}}}}
*cc1_options:
%{pg:%{fomit-frame-pointer:%e-pg and -fomit-frame-pointer are incompatible}} %{!iplugindir*:%{fplugin*:%:find-plugindir()}} %1 %{!Q:-quiet} %{!dumpbase:-dumpbase %B} %{d*} %{m*} %{aux-info*} %{fcompare-debug-second:%:compare-debug-auxbase-opt(%b)} %{!fcompare-debug-second:%{c|S:%{o*:-auxbase-strip %*}%{!o*:-auxbase %b}}}%{!c:%{!S:-auxbase %b}} %{g*} %{O*} %{W*&pedantic*} %{w} %{std*&ansi&trigraphs} %{v:-version} %{pg:-p} %{p} %{f*} %{undef} %{Qn:-fno-ident} %{Qy:} %{-help:--help} %{-target-help:--target-help} %{-version:--version} %{-help=*:--help=%*} %{!fsyntax-only:%{S:%W{o*}%{!o*:-o %b.s}}} %{fsyntax-only:-o %j} %{-param*} %{coverage:-fprofile-arcs -ftest-coverage} %{fprofile-arcs|fprofile-generate*|coverage: %{!fprofile-update=single: %{pthread:-fprofile-update=prefer-atomic}}}
*cc1plus:
*link_gcc_c_sequence:
%{static|static-pie:--start-group} %G %{!nolibc:%L} %{static|static-pie:--end-group}%{!static:%{!static-pie:%G}}
*link_ssp:
%{fstack-protector|fstack-protector-all|fstack-protector-strong|fstack-protector-explicit:-lssp_nonshared}
*endfile:
--push-state --pop-state
*link:
%{!mandroid|tno-android-ld:%{m16|m32:;:-m elf_x86_64} %{m16|m32:-m elf_i386} %{shared:-shared} %{!shared: %{!static: %{!static-pie: %{rdynamic:-export-dynamic} }} %{static:-static} %{static-pie:-static -pie --no-dynamic-linker -z text}};:%{m16|m32:;:-m elf_x86_64} %{m16|m32:-m elf_i386} %{mx32:-m elf32_x86_64} %{shared:-shared} %{!shared: %{!static: %{!static-pie: %{rdynamic:-export-dynamic} %{m16|m32:-dynamic-linker } %{m16|m32:;:-dynamic-linker} }} %{static:-static} %{static-pie:-static -pie --no-dynamic-linker -z text}} %{shared: -Bsymbolic}}
*lib:
--push-state --pop-state
*link_gomp:
*libgcc:
--push-state --pop-state
*startfile:
--push-state --pop-state
*cross_compile:
1
*version:
9.2.0
*multilib:
. ;
*multilib_defaults:
m64
*multilib_extra:
*multilib_matches:
*multilib_exclusions:
*multilib_options:
*multilib_reuse:
*linker:
collect2
*linker_plugin_file:
*lto_wrapper:
*lto_gcc:
*post_link:
*link_libgcc:
%D
*md_exec_prefix:
*md_startfile_prefix:
*md_startfile_prefix_1:
*startfile_prefix_spec:
*sysroot_spec:
--sysroot=%R
*sysroot_suffix_spec:
*sysroot_hdrs_suffix_spec:
*self_spec:
*cc1_cpu:
%{march=native:%>march=native %:local_cpu_detect(arch) %{!mtune=*:%>mtune=native %:local_cpu_detect(tune)}} %{mtune=native:%>mtune=native %:local_cpu_detect(tune)}
*link_command:
%{!fsyntax-only:%{!c:%{!M:%{!MM:%{!E:%{!S: %(linker) %{fuse-linker-plugin: %e-fuse-linker-plugin is not supported in this configuration}%{flto|flto=*:%<fcompare-debug*} %{flto} %{fno-lto} %{flto=*} %l %{shared|r:;pie|static-pie:-pie %{static|static-pie:--no-dynamic-linker -z text -Bsymbolic}} %{fuse-ld=*:-fuse-ld=%*} %{gz|gz=zlib:--compress-debug-sections=zlib} %{gz=none:--compress-debug-sections=none} %{gz=zlib-gnu:--compress-debug-sections=zlib-gnu} %X %{o*} %{e*} %{N} %{n} %{r} %{s} %{t} %{u*} %{z} %{Z} %{!nostdlib:%{!r:%{!nostartfiles:%S}}} %{static|no-pie|static-pie:} %@{L*} %(mfwrap) %(link_libgcc) %{fvtable-verify=none:} %{fvtable-verify=std: %e-fvtable-verify=std is not supported in this configuration} %{fvtable-verify=preinit: %e-fvtable-verify=preinit is not supported in this configuration} %{!nostdlib:%{!r:%{!nodefaultlibs:%{%:sanitize(address):%{!shared:libasan_preinit%O%s} %{static-libasan:%{!shared:-Bstatic --whole-archive -lasan --no-whole-archive -Bdynamic}}%{!static-libasan:-lasan}} %{%:sanitize(thread):%{!shared:libtsan_preinit%O%s} %{static-libtsan:%{!shared:-Bstatic --whole-archive -ltsan --no-whole-archive -Bdynamic}}%{!static-libtsan:-ltsan}} %{%:sanitize(leak):%{!shared:liblsan_preinit%O%s} %{static-liblsan:%{!shared:-Bstatic --whole-archive -llsan --no-whole-archive -Bdynamic}}%{!static-liblsan:-llsan}}}}} %o %{fopenacc|fopenmp|%:gt(%{ftree-parallelize-loops=*:%*} 1): %:include(libgomp.spec)%(link_gomp)} %{fgnu-tm:%:include(libitm.spec)%(link_itm)} %(mflib) %{fsplit-stack: --wrap=pthread_create} %{fprofile-arcs|fprofile-generate*|coverage:-lgcov} %{!nostdlib:%{!r:%{!nodefaultlibs:%{%:sanitize(address): %{static-libasan|static:%:include(libsanitizer.spec)%(link_libasan)} %{static:%ecannot specify -static with -fsanitize=address}} %{%:sanitize(thread): %{static-libtsan|static:%:include(libsanitizer.spec)%(link_libtsan)} %{static:%ecannot specify -static with -fsanitize=thread}} %{%:sanitize(undefined):%{static-libubsan:-Bstatic} -lubsan %{static-libubsan:-Bdynamic} %{static-libubsan|static:%:include(libsanitizer.spec)%(link_libubsan)}} %{%:sanitize(leak): %{static-liblsan|static:%:include(libsanitizer.spec)%(link_liblsan)}}}}} %{!nostdlib:%{!r:%{!nodefaultlibs:%(link_ssp) %(link_gcc_c_sequence)}}} %{!nostdlib:%{!r:%{!nostartfiles:%E}}} %{T*}
%(post_link) }}}}}}
| 6,715 | 142 | jart/cosmopolitan | false |
cosmopolitan/third_party/gcc/x86_64-linux-musl/bin/ar.sym | ../../bin/x86_64-linux-musl-ar | 30 | 1 | jart/cosmopolitan | false |
cosmopolitan/third_party/gcc/x86_64-linux-musl/bin/readelf.sym | ../../bin/x86_64-linux-musl-readelf | 35 | 1 | jart/cosmopolitan | false |
cosmopolitan/third_party/gcc/x86_64-linux-musl/bin/objcopy.sym | ../../bin/x86_64-linux-musl-objcopy | 35 | 1 | jart/cosmopolitan | false |
cosmopolitan/third_party/gcc/x86_64-linux-musl/bin/objdump.sym | ../../bin/x86_64-linux-musl-objdump | 35 | 1 | jart/cosmopolitan | false |
cosmopolitan/third_party/gcc/x86_64-linux-musl/bin/as.sym | ../../bin/x86_64-linux-musl-as | 30 | 1 | jart/cosmopolitan | false |
cosmopolitan/third_party/gcc/x86_64-linux-musl/bin/nm.sym | ../../bin/x86_64-linux-musl-nm | 30 | 1 | jart/cosmopolitan | false |
cosmopolitan/third_party/gcc/x86_64-linux-musl/bin/strip.sym | ../../bin/x86_64-linux-musl-strip | 33 | 1 | jart/cosmopolitan | false |
cosmopolitan/third_party/gcc/x86_64-linux-musl/bin/ld.sym | ld.bfd | 6 | 1 | jart/cosmopolitan | false |
cosmopolitan/third_party/gcc/x86_64-linux-musl/bin/ranlib.sym | ../../bin/x86_64-linux-musl-ranlib | 34 | 1 | jart/cosmopolitan | false |
cosmopolitan/third_party/gcc/bin/aarch64-linux-musl-cc.sym | aarch64-linux-musl-gcc | 22 | 1 | jart/cosmopolitan | false |
cosmopolitan/third_party/gcc/bin/x86_64-linux-musl-ld.bfd.sym | ../x86_64-linux-musl/bin/ld.bfd | 31 | 1 | jart/cosmopolitan | false |
cosmopolitan/third_party/gcc/bin/aarch64-linux-musl-c++.sym | aarch64-linux-musl-g++ | 22 | 1 | jart/cosmopolitan | false |
cosmopolitan/third_party/gcc/bin/x86_64-linux-musl-c++.sym | x86_64-linux-musl-g++ | 21 | 1 | jart/cosmopolitan | false |
cosmopolitan/third_party/gcc/bin/x86_64-linux-musl-gcc-9.2.0.sym | x86_64-linux-musl-gcc | 21 | 1 | jart/cosmopolitan | false |
cosmopolitan/third_party/gcc/bin/aarch64-linux-musl-ld.bfd.sym | ../aarch64-linux-musl/bin/ld.bfd | 32 | 1 | jart/cosmopolitan | false |
cosmopolitan/third_party/gcc/bin/x86_64-linux-musl-cc.sym | x86_64-linux-musl-gcc | 21 | 1 | jart/cosmopolitan | false |
cosmopolitan/third_party/gcc/bin/aarch64-linux-musl-ld.sym | ../aarch64-linux-musl/bin/ld.bfd | 32 | 1 | jart/cosmopolitan | false |
cosmopolitan/third_party/gcc/bin/aarch64-linux-musl-gcc-9.2.0.sym | aarch64-linux-musl-gcc | 22 | 1 | jart/cosmopolitan | false |
cosmopolitan/third_party/gcc/bin/x86_64-linux-musl-ld.sym | ../x86_64-linux-musl/bin/ld.bfd | 31 | 1 | jart/cosmopolitan | false |
cosmopolitan/third_party/libcxx/numeric | // -*- C++ -*-
//===---------------------------- numeric ---------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
#ifndef _LIBCPP_NUMERIC
#define _LIBCPP_NUMERIC
#include "third_party/libcxx/__config"
#include "third_party/libcxx/iterator"
#include "third_party/libcxx/limits" // for numeric_limits
#include "third_party/libcxx/functional"
#include "third_party/libcxx/cmath" // for isnormal
#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
/*
numeric synopsis
namespace std
{
template <class InputIterator, class T>
T
accumulate(InputIterator first, InputIterator last, T init);
template <class InputIterator, class T, class BinaryOperation>
T
accumulate(InputIterator first, InputIterator last, T init, BinaryOperation binary_op);
template<class InputIterator>
typename iterator_traits<InputIterator>::value_type
reduce(InputIterator first, InputIterator last); // C++17
template<class InputIterator, class T>
T
reduce(InputIterator first, InputIterator last, T init); // C++17
template<class InputIterator, class T, class BinaryOperation>
T
reduce(InputIterator first, InputIterator last, T init, BinaryOperation binary_op); // C++17
template <class InputIterator1, class InputIterator2, class T>
T
inner_product(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, T init);
template <class InputIterator1, class InputIterator2, class T, class BinaryOperation1, class BinaryOperation2>
T
inner_product(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2,
T init, BinaryOperation1 binary_op1, BinaryOperation2 binary_op2);
template<class InputIterator1, class InputIterator2, class T>
T
transform_reduce(InputIterator1 first1, InputIterator1 last1,
InputIterator2 first2, T init); // C++17
template<class InputIterator1, class InputIterator2, class T, class BinaryOperation1, class BinaryOperation2>
T
transform_reduce(InputIterator1 first1, InputIterator1 last1,
InputIterator2 first2, T init,
BinaryOperation1 binary_op1, BinaryOperation2 binary_op2); // C++17
template<class InputIterator, class T, class BinaryOperation, class UnaryOperation>
T
transform_reduce(InputIterator first, InputIterator last, T init,
BinaryOperation binary_op, UnaryOperation unary_op); // C++17
template <class InputIterator, class OutputIterator>
OutputIterator
partial_sum(InputIterator first, InputIterator last, OutputIterator result);
template <class InputIterator, class OutputIterator, class BinaryOperation>
OutputIterator
partial_sum(InputIterator first, InputIterator last, OutputIterator result, BinaryOperation binary_op);
template<class InputIterator, class OutputIterator, class T>
OutputIterator
exclusive_scan(InputIterator first, InputIterator last,
OutputIterator result, T init); // C++17
template<class InputIterator, class OutputIterator, class T, class BinaryOperation>
OutputIterator
exclusive_scan(InputIterator first, InputIterator last,
OutputIterator result, T init, BinaryOperation binary_op); // C++17
template<class InputIterator, class OutputIterator>
OutputIterator
inclusive_scan(InputIterator first, InputIterator last, OutputIterator result); // C++17
template<class InputIterator, class OutputIterator, class BinaryOperation>
OutputIterator
inclusive_scan(InputIterator first, InputIterator last,
OutputIterator result, BinaryOperation binary_op); // C++17
template<class InputIterator, class OutputIterator, class BinaryOperation, class T>
OutputIterator
inclusive_scan(InputIterator first, InputIterator last,
OutputIterator result, BinaryOperation binary_op, T init); // C++17
template<class InputIterator, class OutputIterator, class T,
class BinaryOperation, class UnaryOperation>
OutputIterator
transform_exclusive_scan(InputIterator first, InputIterator last,
OutputIterator result, T init,
BinaryOperation binary_op, UnaryOperation unary_op); // C++17
template<class InputIterator, class OutputIterator,
class BinaryOperation, class UnaryOperation>
OutputIterator
transform_inclusive_scan(InputIterator first, InputIterator last,
OutputIterator result,
BinaryOperation binary_op, UnaryOperation unary_op); // C++17
template<class InputIterator, class OutputIterator,
class BinaryOperation, class UnaryOperation, class T>
OutputIterator
transform_inclusive_scan(InputIterator first, InputIterator last,
OutputIterator result,
BinaryOperation binary_op, UnaryOperation unary_op,
T init); // C++17
template <class InputIterator, class OutputIterator>
OutputIterator
adjacent_difference(InputIterator first, InputIterator last, OutputIterator result);
template <class InputIterator, class OutputIterator, class BinaryOperation>
OutputIterator
adjacent_difference(InputIterator first, InputIterator last, OutputIterator result, BinaryOperation binary_op);
template <class ForwardIterator, class T>
void iota(ForwardIterator first, ForwardIterator last, T value);
template <class M, class N>
constexpr common_type_t<M,N> gcd(M m, N n); // C++17
template <class M, class N>
constexpr common_type_t<M,N> lcm(M m, N n); // C++17
integer midpoint(integer a, integer b); // C++20
pointer midpoint(pointer a, pointer b); // C++20
floating_point midpoint(floating_point a, floating_point b); // C++20
} // std
*/
template <class _InputIterator, class _Tp>
inline _LIBCPP_INLINE_VISIBILITY
_Tp
accumulate(_InputIterator __first, _InputIterator __last, _Tp __init)
{
for (; __first != __last; ++__first)
__init = __init + *__first;
return __init;
}
template <class _InputIterator, class _Tp, class _BinaryOperation>
inline _LIBCPP_INLINE_VISIBILITY
_Tp
accumulate(_InputIterator __first, _InputIterator __last, _Tp __init, _BinaryOperation __binary_op)
{
for (; __first != __last; ++__first)
__init = __binary_op(__init, *__first);
return __init;
}
#if _LIBCPP_STD_VER > 14
template <class _InputIterator, class _Tp, class _BinaryOp>
inline _LIBCPP_INLINE_VISIBILITY
_Tp
reduce(_InputIterator __first, _InputIterator __last, _Tp __init, _BinaryOp __b)
{
for (; __first != __last; ++__first)
__init = __b(__init, *__first);
return __init;
}
template <class _InputIterator, class _Tp>
inline _LIBCPP_INLINE_VISIBILITY
_Tp
reduce(_InputIterator __first, _InputIterator __last, _Tp __init)
{
return _VSTD::reduce(__first, __last, __init, _VSTD::plus<>());
}
template <class _InputIterator>
inline _LIBCPP_INLINE_VISIBILITY
typename iterator_traits<_InputIterator>::value_type
reduce(_InputIterator __first, _InputIterator __last)
{
return _VSTD::reduce(__first, __last,
typename iterator_traits<_InputIterator>::value_type{});
}
#endif
template <class _InputIterator1, class _InputIterator2, class _Tp>
inline _LIBCPP_INLINE_VISIBILITY
_Tp
inner_product(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2, _Tp __init)
{
for (; __first1 != __last1; ++__first1, (void) ++__first2)
__init = __init + *__first1 * *__first2;
return __init;
}
template <class _InputIterator1, class _InputIterator2, class _Tp, class _BinaryOperation1, class _BinaryOperation2>
inline _LIBCPP_INLINE_VISIBILITY
_Tp
inner_product(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2,
_Tp __init, _BinaryOperation1 __binary_op1, _BinaryOperation2 __binary_op2)
{
for (; __first1 != __last1; ++__first1, (void) ++__first2)
__init = __binary_op1(__init, __binary_op2(*__first1, *__first2));
return __init;
}
#if _LIBCPP_STD_VER > 14
template <class _InputIterator, class _Tp, class _BinaryOp, class _UnaryOp>
inline _LIBCPP_INLINE_VISIBILITY
_Tp
transform_reduce(_InputIterator __first, _InputIterator __last,
_Tp __init, _BinaryOp __b, _UnaryOp __u)
{
for (; __first != __last; ++__first)
__init = __b(__init, __u(*__first));
return __init;
}
template <class _InputIterator1, class _InputIterator2,
class _Tp, class _BinaryOp1, class _BinaryOp2>
inline _LIBCPP_INLINE_VISIBILITY
_Tp
transform_reduce(_InputIterator1 __first1, _InputIterator1 __last1,
_InputIterator2 __first2, _Tp __init, _BinaryOp1 __b1, _BinaryOp2 __b2)
{
for (; __first1 != __last1; ++__first1, (void) ++__first2)
__init = __b1(__init, __b2(*__first1, *__first2));
return __init;
}
template <class _InputIterator1, class _InputIterator2, class _Tp>
inline _LIBCPP_INLINE_VISIBILITY
_Tp
transform_reduce(_InputIterator1 __first1, _InputIterator1 __last1,
_InputIterator2 __first2, _Tp __init)
{
return _VSTD::transform_reduce(__first1, __last1, __first2, _VSTD::move(__init),
_VSTD::plus<>(), _VSTD::multiplies<>());
}
#endif
template <class _InputIterator, class _OutputIterator>
inline _LIBCPP_INLINE_VISIBILITY
_OutputIterator
partial_sum(_InputIterator __first, _InputIterator __last, _OutputIterator __result)
{
if (__first != __last)
{
typename iterator_traits<_InputIterator>::value_type __t(*__first);
*__result = __t;
for (++__first, (void) ++__result; __first != __last; ++__first, (void) ++__result)
{
__t = __t + *__first;
*__result = __t;
}
}
return __result;
}
template <class _InputIterator, class _OutputIterator, class _BinaryOperation>
inline _LIBCPP_INLINE_VISIBILITY
_OutputIterator
partial_sum(_InputIterator __first, _InputIterator __last, _OutputIterator __result,
_BinaryOperation __binary_op)
{
if (__first != __last)
{
typename iterator_traits<_InputIterator>::value_type __t(*__first);
*__result = __t;
for (++__first, (void) ++__result; __first != __last; ++__first, (void) ++__result)
{
__t = __binary_op(__t, *__first);
*__result = __t;
}
}
return __result;
}
#if _LIBCPP_STD_VER > 14
template <class _InputIterator, class _OutputIterator, class _Tp, class _BinaryOp>
inline _LIBCPP_INLINE_VISIBILITY
_OutputIterator
exclusive_scan(_InputIterator __first, _InputIterator __last,
_OutputIterator __result, _Tp __init, _BinaryOp __b)
{
if (__first != __last)
{
_Tp __saved = __init;
do
{
__init = __b(__init, *__first);
*__result = __saved;
__saved = __init;
++__result;
} while (++__first != __last);
}
return __result;
}
template <class _InputIterator, class _OutputIterator, class _Tp>
inline _LIBCPP_INLINE_VISIBILITY
_OutputIterator
exclusive_scan(_InputIterator __first, _InputIterator __last,
_OutputIterator __result, _Tp __init)
{
return _VSTD::exclusive_scan(__first, __last, __result, __init, _VSTD::plus<>());
}
template <class _InputIterator, class _OutputIterator, class _Tp, class _BinaryOp>
_OutputIterator inclusive_scan(_InputIterator __first, _InputIterator __last,
_OutputIterator __result, _BinaryOp __b, _Tp __init)
{
for (; __first != __last; ++__first, (void) ++__result) {
__init = __b(__init, *__first);
*__result = __init;
}
return __result;
}
template <class _InputIterator, class _OutputIterator, class _BinaryOp>
_OutputIterator inclusive_scan(_InputIterator __first, _InputIterator __last,
_OutputIterator __result, _BinaryOp __b)
{
if (__first != __last) {
typename std::iterator_traits<_InputIterator>::value_type __init = *__first;
*__result++ = __init;
if (++__first != __last)
return _VSTD::inclusive_scan(__first, __last, __result, __b, __init);
}
return __result;
}
template <class _InputIterator, class _OutputIterator>
_OutputIterator inclusive_scan(_InputIterator __first, _InputIterator __last,
_OutputIterator __result)
{
return _VSTD::inclusive_scan(__first, __last, __result, std::plus<>());
}
template <class _InputIterator, class _OutputIterator, class _Tp,
class _BinaryOp, class _UnaryOp>
inline _LIBCPP_INLINE_VISIBILITY
_OutputIterator
transform_exclusive_scan(_InputIterator __first, _InputIterator __last,
_OutputIterator __result, _Tp __init,
_BinaryOp __b, _UnaryOp __u)
{
if (__first != __last)
{
_Tp __saved = __init;
do
{
__init = __b(__init, __u(*__first));
*__result = __saved;
__saved = __init;
++__result;
} while (++__first != __last);
}
return __result;
}
template <class _InputIterator, class _OutputIterator, class _Tp, class _BinaryOp, class _UnaryOp>
_OutputIterator transform_inclusive_scan(_InputIterator __first, _InputIterator __last,
_OutputIterator __result, _BinaryOp __b, _UnaryOp __u, _Tp __init)
{
for (; __first != __last; ++__first, (void) ++__result) {
__init = __b(__init, __u(*__first));
*__result = __init;
}
return __result;
}
template <class _InputIterator, class _OutputIterator, class _BinaryOp, class _UnaryOp>
_OutputIterator transform_inclusive_scan(_InputIterator __first, _InputIterator __last,
_OutputIterator __result, _BinaryOp __b, _UnaryOp __u)
{
if (__first != __last) {
typename std::iterator_traits<_InputIterator>::value_type __init = __u(*__first);
*__result++ = __init;
if (++__first != __last)
return _VSTD::transform_inclusive_scan(__first, __last, __result, __b, __u, __init);
}
return __result;
}
#endif
template <class _InputIterator, class _OutputIterator>
inline _LIBCPP_INLINE_VISIBILITY
_OutputIterator
adjacent_difference(_InputIterator __first, _InputIterator __last, _OutputIterator __result)
{
if (__first != __last)
{
typename iterator_traits<_InputIterator>::value_type __t1(*__first);
*__result = __t1;
for (++__first, (void) ++__result; __first != __last; ++__first, (void) ++__result)
{
typename iterator_traits<_InputIterator>::value_type __t2(*__first);
*__result = __t2 - __t1;
__t1 = _VSTD::move(__t2);
}
}
return __result;
}
template <class _InputIterator, class _OutputIterator, class _BinaryOperation>
inline _LIBCPP_INLINE_VISIBILITY
_OutputIterator
adjacent_difference(_InputIterator __first, _InputIterator __last, _OutputIterator __result,
_BinaryOperation __binary_op)
{
if (__first != __last)
{
typename iterator_traits<_InputIterator>::value_type __t1(*__first);
*__result = __t1;
for (++__first, (void) ++__result; __first != __last; ++__first, (void) ++__result)
{
typename iterator_traits<_InputIterator>::value_type __t2(*__first);
*__result = __binary_op(__t2, __t1);
__t1 = _VSTD::move(__t2);
}
}
return __result;
}
template <class _ForwardIterator, class _Tp>
inline _LIBCPP_INLINE_VISIBILITY
void
iota(_ForwardIterator __first, _ForwardIterator __last, _Tp __value_)
{
for (; __first != __last; ++__first, (void) ++__value_)
*__first = __value_;
}
#if _LIBCPP_STD_VER > 14
template <typename _Result, typename _Source, bool _IsSigned = is_signed<_Source>::value> struct __ct_abs;
template <typename _Result, typename _Source>
struct __ct_abs<_Result, _Source, true> {
_LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY
_Result operator()(_Source __t) const noexcept
{
if (__t >= 0) return __t;
if (__t == numeric_limits<_Source>::min()) return -static_cast<_Result>(__t);
return -__t;
}
};
template <typename _Result, typename _Source>
struct __ct_abs<_Result, _Source, false> {
_LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY
_Result operator()(_Source __t) const noexcept { return __t; }
};
template<class _Tp>
_LIBCPP_CONSTEXPR _LIBCPP_HIDDEN
_Tp __gcd(_Tp __m, _Tp __n)
{
static_assert((!is_signed<_Tp>::value), "");
return __n == 0 ? __m : _VSTD::__gcd<_Tp>(__n, __m % __n);
}
template<class _Tp, class _Up>
_LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY
common_type_t<_Tp,_Up>
gcd(_Tp __m, _Up __n)
{
static_assert((is_integral<_Tp>::value && is_integral<_Up>::value), "Arguments to gcd must be integer types");
static_assert((!is_same<typename remove_cv<_Tp>::type, bool>::value), "First argument to gcd cannot be bool" );
static_assert((!is_same<typename remove_cv<_Up>::type, bool>::value), "Second argument to gcd cannot be bool" );
using _Rp = common_type_t<_Tp,_Up>;
using _Wp = make_unsigned_t<_Rp>;
return static_cast<_Rp>(_VSTD::__gcd(
static_cast<_Wp>(__ct_abs<_Rp, _Tp>()(__m)),
static_cast<_Wp>(__ct_abs<_Rp, _Up>()(__n))));
}
template<class _Tp, class _Up>
_LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY
common_type_t<_Tp,_Up>
lcm(_Tp __m, _Up __n)
{
static_assert((is_integral<_Tp>::value && is_integral<_Up>::value), "Arguments to lcm must be integer types");
static_assert((!is_same<typename remove_cv<_Tp>::type, bool>::value), "First argument to lcm cannot be bool" );
static_assert((!is_same<typename remove_cv<_Up>::type, bool>::value), "Second argument to lcm cannot be bool" );
if (__m == 0 || __n == 0)
return 0;
using _Rp = common_type_t<_Tp,_Up>;
_Rp __val1 = __ct_abs<_Rp, _Tp>()(__m) / _VSTD::gcd(__m, __n);
_Rp __val2 = __ct_abs<_Rp, _Up>()(__n);
_LIBCPP_ASSERT((numeric_limits<_Rp>::max() / __val1 > __val2), "Overflow in lcm");
return __val1 * __val2;
}
#endif /* _LIBCPP_STD_VER > 14 */
#if _LIBCPP_STD_VER > 17
template <class _Tp>
_LIBCPP_INLINE_VISIBILITY constexpr
enable_if_t<is_integral_v<_Tp> && !is_same_v<bool, _Tp> && !is_null_pointer_v<_Tp>, _Tp>
midpoint(_Tp __a, _Tp __b) noexcept
_LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK
{
using _Up = std::make_unsigned_t<_Tp>;
int __sign = 1;
_Up __m = __a;
_Up __M = __b;
if (__a > __b)
{
__sign = -1;
__m = __b;
__M = __a;
}
return __a + __sign * _Tp(_Up(__M-__m) >> 1);
}
template <class _TPtr>
_LIBCPP_INLINE_VISIBILITY constexpr
enable_if_t<is_pointer_v<_TPtr>
&& is_object_v<remove_pointer_t<_TPtr>>
&& ! is_void_v<remove_pointer_t<_TPtr>>
&& (sizeof(remove_pointer_t<_TPtr>) > 0), _TPtr>
midpoint(_TPtr __a, _TPtr __b) noexcept
{
return __a + _VSTD::midpoint(ptrdiff_t(0), __b - __a);
}
template <typename _Tp>
constexpr int __sign(_Tp __val) {
return (_Tp(0) < __val) - (__val < _Tp(0));
}
template <typename _Fp>
constexpr _Fp __fp_abs(_Fp __f) { return __f >= 0 ? __f : -__f; }
template <class _Fp>
_LIBCPP_INLINE_VISIBILITY constexpr
enable_if_t<is_floating_point_v<_Fp>, _Fp>
midpoint(_Fp __a, _Fp __b) noexcept
{
constexpr _Fp __lo = numeric_limits<_Fp>::min()*2;
constexpr _Fp __hi = numeric_limits<_Fp>::max()/2;
return __fp_abs(__a) <= __hi && __fp_abs(__b) <= __hi ? // typical case: overflow is impossible
(__a + __b)/2 : // always correctly rounded
__fp_abs(__a) < __lo ? __a + __b/2 : // not safe to halve a
__fp_abs(__a) < __lo ? __a/2 + __b : // not safe to halve b
__a/2 + __b/2; // otherwise correctly rounded
}
#endif // _LIBCPP_STD_VER > 17
_LIBCPP_END_NAMESPACE_STD
_LIBCPP_POP_MACROS
#if defined(_LIBCPP_HAS_PARALLEL_ALGORITHMS) && _LIBCPP_STD_VER >= 17
# include "third_party/libcxx/__pstl_numeric"
#endif
#endif // _LIBCPP_NUMERIC
| 20,653 | 594 | jart/cosmopolitan | false |
cosmopolitan/third_party/libcxx/chrono | // -*- C++ -*-
//===---------------------------- chrono ----------------------------------===//
//
// 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_CHRONO
#define _LIBCPP_CHRONO
#include "third_party/libcxx/__config"
#include "third_party/libcxx/ctime"
#include "third_party/libcxx/type_traits"
#include "third_party/libcxx/ratio"
#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"
#ifndef _LIBCPP_CXX03_LANG
_LIBCPP_BEGIN_NAMESPACE_FILESYSTEM
struct _FilesystemClock;
_LIBCPP_END_NAMESPACE_FILESYSTEM
#endif // !_LIBCPP_CXX03_LANG
_LIBCPP_BEGIN_NAMESPACE_STD
/*
chrono synopsis
namespace std
{
namespace chrono
{
template <class ToDuration, class Rep, class Period>
constexpr
ToDuration
duration_cast(const duration<Rep, Period>& fd);
template <class Rep> struct treat_as_floating_point : is_floating_point<Rep> {};
template <class Rep> inline constexpr bool treat_as_floating_point_v
= treat_as_floating_point<Rep>::value; // C++17
template <class Rep>
struct duration_values
{
public:
static constexpr Rep zero(); // noexcept in C++20
static constexpr Rep max(); // noexcept in C++20
static constexpr Rep min(); // noexcept in C++20
};
// duration
template <class Rep, class Period = ratio<1>>
class duration
{
static_assert(!__is_duration<Rep>::value, "A duration representation can not be a duration");
static_assert(__is_ratio<Period>::value, "Second template parameter of duration must be a std::ratio");
static_assert(Period::num > 0, "duration period must be positive");
public:
typedef Rep rep;
typedef typename _Period::type period;
constexpr duration() = default;
template <class Rep2>
constexpr explicit duration(const Rep2& r,
typename enable_if
<
is_convertible<Rep2, rep>::value &&
(treat_as_floating_point<rep>::value ||
!treat_as_floating_point<rep>::value && !treat_as_floating_point<Rep2>::value)
>::type* = 0);
// conversions
template <class Rep2, class Period2>
constexpr duration(const duration<Rep2, Period2>& d,
typename enable_if
<
treat_as_floating_point<rep>::value ||
ratio_divide<Period2, period>::type::den == 1
>::type* = 0);
// observer
constexpr rep count() const;
// arithmetic
constexpr common_type<duration>::type operator+() const;
constexpr common_type<duration>::type operator-() const;
constexpr duration& operator++(); // constexpr in C++17
constexpr duration operator++(int); // constexpr in C++17
constexpr duration& operator--(); // constexpr in C++17
constexpr duration operator--(int); // constexpr in C++17
constexpr duration& operator+=(const duration& d); // constexpr in C++17
constexpr duration& operator-=(const duration& d); // constexpr in C++17
duration& operator*=(const rep& rhs); // constexpr in C++17
duration& operator/=(const rep& rhs); // constexpr in C++17
duration& operator%=(const rep& rhs); // constexpr in C++17
duration& operator%=(const duration& rhs); // constexpr in C++17
// special values
static constexpr duration zero(); // noexcept in C++20
static constexpr duration min(); // noexcept in C++20
static constexpr duration max(); // noexcept in C++20
};
typedef duration<long long, nano> nanoseconds;
typedef duration<long long, micro> microseconds;
typedef duration<long long, milli> milliseconds;
typedef duration<long long > seconds;
typedef duration< long, ratio< 60> > minutes;
typedef duration< long, ratio<3600> > hours;
template <class Clock, class Duration = typename Clock::duration>
class time_point
{
public:
typedef Clock clock;
typedef Duration duration;
typedef typename duration::rep rep;
typedef typename duration::period period;
private:
duration d_; // exposition only
public:
time_point(); // has value "epoch" // constexpr in C++14
explicit time_point(const duration& d); // same as time_point() + d // constexpr in C++14
// conversions
template <class Duration2>
time_point(const time_point<clock, Duration2>& t); // constexpr in C++14
// observer
duration time_since_epoch() const; // constexpr in C++14
// arithmetic
time_point& operator+=(const duration& d); // constexpr in C++17
time_point& operator-=(const duration& d); // constexpr in C++17
// special values
static constexpr time_point min(); // noexcept in C++20
static constexpr time_point max(); // noexcept in C++20
};
} // chrono
// common_type traits
template <class Rep1, class Period1, class Rep2, class Period2>
struct common_type<chrono::duration<Rep1, Period1>, chrono::duration<Rep2, Period2>>;
template <class Clock, class Duration1, class Duration2>
struct common_type<chrono::time_point<Clock, Duration1>, chrono::time_point<Clock, Duration2>>;
namespace chrono {
template<class T> struct is_clock; // C++20
template<class T> inline constexpr bool is_clock_v = is_clock<T>::value; // C++20
// duration arithmetic
template <class Rep1, class Period1, class Rep2, class Period2>
constexpr
typename common_type<duration<Rep1, Period1>, duration<Rep2, Period2>>::type
operator+(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs);
template <class Rep1, class Period1, class Rep2, class Period2>
constexpr
typename common_type<duration<Rep1, Period1>, duration<Rep2, Period2>>::type
operator-(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs);
template <class Rep1, class Period, class Rep2>
constexpr
duration<typename common_type<Rep1, Rep2>::type, Period>
operator*(const duration<Rep1, Period>& d, const Rep2& s);
template <class Rep1, class Period, class Rep2>
constexpr
duration<typename common_type<Rep1, Rep2>::type, Period>
operator*(const Rep1& s, const duration<Rep2, Period>& d);
template <class Rep1, class Period, class Rep2>
constexpr
duration<typename common_type<Rep1, Rep2>::type, Period>
operator/(const duration<Rep1, Period>& d, const Rep2& s);
template <class Rep1, class Period1, class Rep2, class Period2>
constexpr
typename common_type<Rep1, Rep2>::type
operator/(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs);
// duration comparisons
template <class Rep1, class Period1, class Rep2, class Period2>
constexpr
bool operator==(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs);
template <class Rep1, class Period1, class Rep2, class Period2>
constexpr
bool operator!=(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs);
template <class Rep1, class Period1, class Rep2, class Period2>
constexpr
bool operator< (const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs);
template <class Rep1, class Period1, class Rep2, class Period2>
constexpr
bool operator<=(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs);
template <class Rep1, class Period1, class Rep2, class Period2>
constexpr
bool operator> (const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs);
template <class Rep1, class Period1, class Rep2, class Period2>
constexpr
bool operator>=(const duration<Rep1, Period1>& lhs, const duration<Rep2, Period2>& rhs);
// duration_cast
template <class ToDuration, class Rep, class Period>
ToDuration duration_cast(const duration<Rep, Period>& d);
template <class ToDuration, class Rep, class Period>
constexpr ToDuration floor(const duration<Rep, Period>& d); // C++17
template <class ToDuration, class Rep, class Period>
constexpr ToDuration ceil(const duration<Rep, Period>& d); // C++17
template <class ToDuration, class Rep, class Period>
constexpr ToDuration round(const duration<Rep, Period>& d); // C++17
// duration I/O is elsewhere
// time_point arithmetic (all constexpr in C++14)
template <class Clock, class Duration1, class Rep2, class Period2>
time_point<Clock, typename common_type<Duration1, duration<Rep2, Period2>>::type>
operator+(const time_point<Clock, Duration1>& lhs, const duration<Rep2, Period2>& rhs);
template <class Rep1, class Period1, class Clock, class Duration2>
time_point<Clock, typename common_type<duration<Rep1, Period1>, Duration2>::type>
operator+(const duration<Rep1, Period1>& lhs, const time_point<Clock, Duration2>& rhs);
template <class Clock, class Duration1, class Rep2, class Period2>
time_point<Clock, typename common_type<Duration1, duration<Rep2, Period2>>::type>
operator-(const time_point<Clock, Duration1>& lhs, const duration<Rep2, Period2>& rhs);
template <class Clock, class Duration1, class Duration2>
typename common_type<Duration1, Duration2>::type
operator-(const time_point<Clock, Duration1>& lhs, const time_point<Clock, Duration2>& rhs);
// time_point comparisons (all constexpr in C++14)
template <class Clock, class Duration1, class Duration2>
bool operator==(const time_point<Clock, Duration1>& lhs, const time_point<Clock, Duration2>& rhs);
template <class Clock, class Duration1, class Duration2>
bool operator!=(const time_point<Clock, Duration1>& lhs, const time_point<Clock, Duration2>& rhs);
template <class Clock, class Duration1, class Duration2>
bool operator< (const time_point<Clock, Duration1>& lhs, const time_point<Clock, Duration2>& rhs);
template <class Clock, class Duration1, class Duration2>
bool operator<=(const time_point<Clock, Duration1>& lhs, const time_point<Clock, Duration2>& rhs);
template <class Clock, class Duration1, class Duration2>
bool operator> (const time_point<Clock, Duration1>& lhs, const time_point<Clock, Duration2>& rhs);
template <class Clock, class Duration1, class Duration2>
bool operator>=(const time_point<Clock, Duration1>& lhs, const time_point<Clock, Duration2>& rhs);
// time_point_cast (constexpr in C++14)
template <class ToDuration, class Clock, class Duration>
time_point<Clock, ToDuration> time_point_cast(const time_point<Clock, Duration>& t);
template <class ToDuration, class Clock, class Duration>
constexpr time_point<Clock, ToDuration>
floor(const time_point<Clock, Duration>& tp); // C++17
template <class ToDuration, class Clock, class Duration>
constexpr time_point<Clock, ToDuration>
ceil(const time_point<Clock, Duration>& tp); // C++17
template <class ToDuration, class Clock, class Duration>
constexpr time_point<Clock, ToDuration>
round(const time_point<Clock, Duration>& tp); // C++17
template <class Rep, class Period>
constexpr duration<Rep, Period> abs(duration<Rep, Period> d); // C++17
// Clocks
class system_clock
{
public:
typedef microseconds duration;
typedef duration::rep rep;
typedef duration::period period;
typedef chrono::time_point<system_clock> time_point;
static const bool is_steady = false; // constexpr in C++14
static time_point now() noexcept;
static time_t to_time_t (const time_point& __t) noexcept;
static time_point from_time_t(time_t __t) noexcept;
};
template <class Duration>
using sys_time = time_point<system_clock, Duration>; // C++20
using sys_seconds = sys_time<seconds>; // C++20
using sys_days = sys_time<days>; // C++20
class utc_clock; // C++20
template <class Duration>
using utc_time = time_point<utc_clock, Duration>; // C++20
using utc_seconds = utc_time<seconds>; // C++20
class tai_clock; // C++20
template <class Duration>
using tai_time = time_point<tai_clock, Duration>; // C++20
using tai_seconds = tai_time<seconds>; // C++20
class file_clock; // C++20
template<class Duration>
using file_time = time_point<file_clock, Duration>; // C++20
class steady_clock
{
public:
typedef nanoseconds duration;
typedef duration::rep rep;
typedef duration::period period;
typedef chrono::time_point<steady_clock, duration> time_point;
static const bool is_steady = true; // constexpr in C++14
static time_point now() noexcept;
};
typedef steady_clock high_resolution_clock;
// 25.7.8, local time // C++20
struct local_t {};
template<class Duration>
using local_time = time_point<local_t, Duration>;
using local_seconds = local_time<seconds>;
using local_days = local_time<days>;
// 25.7.9, time_point conversions template<class DestClock, class SourceClock> // C++20
struct clock_time_conversion;
template<class DestClock, class SourceClock, class Duration>
auto clock_cast(const time_point<SourceClock, Duration>& t);
// 25.8.2, class last_spec // C++20
struct last_spec;
// 25.8.3, class day // C++20
class day;
constexpr bool operator==(const day& x, const day& y) noexcept;
constexpr bool operator!=(const day& x, const day& y) noexcept;
constexpr bool operator< (const day& x, const day& y) noexcept;
constexpr bool operator> (const day& x, const day& y) noexcept;
constexpr bool operator<=(const day& x, const day& y) noexcept;
constexpr bool operator>=(const day& x, const day& y) noexcept;
constexpr day operator+(const day& x, const days& y) noexcept;
constexpr day operator+(const days& x, const day& y) noexcept;
constexpr day operator-(const day& x, const days& y) noexcept;
constexpr days operator-(const day& x, const day& y) noexcept;
// 25.8.4, class month // C++20
class month;
constexpr bool operator==(const month& x, const month& y) noexcept;
constexpr bool operator!=(const month& x, const month& y) noexcept;
constexpr bool operator< (const month& x, const month& y) noexcept;
constexpr bool operator> (const month& x, const month& y) noexcept;
constexpr bool operator<=(const month& x, const month& y) noexcept;
constexpr bool operator>=(const month& x, const month& y) noexcept;
constexpr month operator+(const month& x, const months& y) noexcept;
constexpr month operator+(const months& x, const month& y) noexcept;
constexpr month operator-(const month& x, const months& y) noexcept;
constexpr months operator-(const month& x, const month& y) noexcept;
// 25.8.5, class year // C++20
class year;
constexpr bool operator==(const year& x, const year& y) noexcept;
constexpr bool operator!=(const year& x, const year& y) noexcept;
constexpr bool operator< (const year& x, const year& y) noexcept;
constexpr bool operator> (const year& x, const year& y) noexcept;
constexpr bool operator<=(const year& x, const year& y) noexcept;
constexpr bool operator>=(const year& x, const year& y) noexcept;
constexpr year operator+(const year& x, const years& y) noexcept;
constexpr year operator+(const years& x, const year& y) noexcept;
constexpr year operator-(const year& x, const years& y) noexcept;
constexpr years operator-(const year& x, const year& y) noexcept;
// 25.8.6, class weekday // C++20
class weekday;
constexpr bool operator==(const weekday& x, const weekday& y) noexcept;
constexpr bool operator!=(const weekday& x, const weekday& y) noexcept;
constexpr weekday operator+(const weekday& x, const days& y) noexcept;
constexpr weekday operator+(const days& x, const weekday& y) noexcept;
constexpr weekday operator-(const weekday& x, const days& y) noexcept;
constexpr days operator-(const weekday& x, const weekday& y) noexcept;
// 25.8.7, class weekday_indexed // C++20
class weekday_indexed;
constexpr bool operator==(const weekday_indexed& x, const weekday_indexed& y) noexcept;
constexpr bool operator!=(const weekday_indexed& x, const weekday_indexed& y) noexcept;
// 25.8.8, class weekday_last // C++20
class weekday_last;
constexpr bool operator==(const weekday_last& x, const weekday_last& y) noexcept;
constexpr bool operator!=(const weekday_last& x, const weekday_last& y) noexcept;
// 25.8.9, class month_day // C++20
class month_day;
constexpr bool operator==(const month_day& x, const month_day& y) noexcept;
constexpr bool operator!=(const month_day& x, const month_day& y) noexcept;
constexpr bool operator< (const month_day& x, const month_day& y) noexcept;
constexpr bool operator> (const month_day& x, const month_day& y) noexcept;
constexpr bool operator<=(const month_day& x, const month_day& y) noexcept;
constexpr bool operator>=(const month_day& x, const month_day& y) noexcept;
// 25.8.10, class month_day_last // C++20
class month_day_last;
constexpr bool operator==(const month_day_last& x, const month_day_last& y) noexcept;
constexpr bool operator!=(const month_day_last& x, const month_day_last& y) noexcept;
constexpr bool operator< (const month_day_last& x, const month_day_last& y) noexcept;
constexpr bool operator> (const month_day_last& x, const month_day_last& y) noexcept;
constexpr bool operator<=(const month_day_last& x, const month_day_last& y) noexcept;
constexpr bool operator>=(const month_day_last& x, const month_day_last& y) noexcept;
// 25.8.11, class month_weekday // C++20
class month_weekday;
constexpr bool operator==(const month_weekday& x, const month_weekday& y) noexcept;
constexpr bool operator!=(const month_weekday& x, const month_weekday& y) noexcept;
// 25.8.12, class month_weekday_last // C++20
class month_weekday_last;
constexpr bool operator==(const month_weekday_last& x, const month_weekday_last& y) noexcept;
constexpr bool operator!=(const month_weekday_last& x, const month_weekday_last& y) noexcept;
// 25.8.13, class year_month // C++20
class year_month;
constexpr bool operator==(const year_month& x, const year_month& y) noexcept;
constexpr bool operator!=(const year_month& x, const year_month& y) noexcept;
constexpr bool operator< (const year_month& x, const year_month& y) noexcept;
constexpr bool operator> (const year_month& x, const year_month& y) noexcept;
constexpr bool operator<=(const year_month& x, const year_month& y) noexcept;
constexpr bool operator>=(const year_month& x, const year_month& y) noexcept;
constexpr year_month operator+(const year_month& ym, const months& dm) noexcept;
constexpr year_month operator+(const months& dm, const year_month& ym) noexcept;
constexpr year_month operator-(const year_month& ym, const months& dm) noexcept;
constexpr months operator-(const year_month& x, const year_month& y) noexcept;
constexpr year_month operator+(const year_month& ym, const years& dy) noexcept;
constexpr year_month operator+(const years& dy, const year_month& ym) noexcept;
constexpr year_month operator-(const year_month& ym, const years& dy) noexcept;
// 25.8.14, class year_month_day class // C++20
year_month_day;
constexpr bool operator==(const year_month_day& x, const year_month_day& y) noexcept;
constexpr bool operator!=(const year_month_day& x, const year_month_day& y) noexcept;
constexpr bool operator< (const year_month_day& x, const year_month_day& y) noexcept;
constexpr bool operator> (const year_month_day& x, const year_month_day& y) noexcept;
constexpr bool operator<=(const year_month_day& x, const year_month_day& y) noexcept;
constexpr bool operator>=(const year_month_day& x, const year_month_day& y) noexcept;
constexpr year_month_day operator+(const year_month_day& ymd, const months& dm) noexcept;
constexpr year_month_day operator+(const months& dm, const year_month_day& ymd) noexcept;
constexpr year_month_day operator+(const year_month_day& ymd, const years& dy) noexcept;
constexpr year_month_day operator+(const years& dy, const year_month_day& ymd) noexcept;
constexpr year_month_day operator-(const year_month_day& ymd, const months& dm) noexcept;
constexpr year_month_day operator-(const year_month_day& ymd, const years& dy) noexcept;
// 25.8.15, class year_month_day_last // C++20
class year_month_day_last;
constexpr bool operator==(const year_month_day_last& x,
const year_month_day_last& y) noexcept;
constexpr bool operator!=(const year_month_day_last& x,
const year_month_day_last& y) noexcept;
constexpr bool operator< (const year_month_day_last& x,
const year_month_day_last& y) noexcept;
constexpr bool operator> (const year_month_day_last& x,
const year_month_day_last& y) noexcept;
constexpr bool operator<=(const year_month_day_last& x,
const year_month_day_last& y) noexcept;
constexpr bool operator>=(const year_month_day_last& x,
const year_month_day_last& y) noexcept;
constexpr year_month_day_last
operator+(const year_month_day_last& ymdl, const months& dm) noexcept;
constexpr year_month_day_last
operator+(const months& dm, const year_month_day_last& ymdl) noexcept;
constexpr year_month_day_last
operator+(const year_month_day_last& ymdl, const years& dy) noexcept;
constexpr year_month_day_last
operator+(const years& dy, const year_month_day_last& ymdl) noexcept;
constexpr year_month_day_last
operator-(const year_month_day_last& ymdl, const months& dm) noexcept;
constexpr year_month_day_last
operator-(const year_month_day_last& ymdl, const years& dy) noexcept;
// 25.8.16, class year_month_weekday // C++20
class year_month_weekday;
constexpr bool operator==(const year_month_weekday& x,
const year_month_weekday& y) noexcept;
constexpr bool operator!=(const year_month_weekday& x,
const year_month_weekday& y) noexcept;
constexpr year_month_weekday
operator+(const year_month_weekday& ymwd, const months& dm) noexcept;
constexpr year_month_weekday
operator+(const months& dm, const year_month_weekday& ymwd) noexcept;
constexpr year_month_weekday
operator+(const year_month_weekday& ymwd, const years& dy) noexcept;
constexpr year_month_weekday
operator+(const years& dy, const year_month_weekday& ymwd) noexcept;
constexpr year_month_weekday
operator-(const year_month_weekday& ymwd, const months& dm) noexcept;
constexpr year_month_weekday
operator-(const year_month_weekday& ymwd, const years& dy) noexcept;
// 25.8.17, class year_month_weekday_last // C++20
class year_month_weekday_last;
constexpr bool operator==(const year_month_weekday_last& x,
const year_month_weekday_last& y) noexcept;
constexpr bool operator!=(const year_month_weekday_last& x,
const year_month_weekday_last& y) noexcept;
constexpr year_month_weekday_last
operator+(const year_month_weekday_last& ymwdl, const months& dm) noexcept;
constexpr year_month_weekday_last
operator+(const months& dm, const year_month_weekday_last& ymwdl) noexcept;
constexpr year_month_weekday_last
operator+(const year_month_weekday_last& ymwdl, const years& dy) noexcept;
constexpr year_month_weekday_last
operator+(const years& dy, const year_month_weekday_last& ymwdl) noexcept;
constexpr year_month_weekday_last
operator-(const year_month_weekday_last& ymwdl, const months& dm) noexcept;
constexpr year_month_weekday_last
operator-(const year_month_weekday_last& ymwdl, const years& dy) noexcept;
// 25.8.18, civil calendar conventional syntax operators // C++20
constexpr year_month
operator/(const year& y, const month& m) noexcept;
constexpr year_month
operator/(const year& y, int m) noexcept;
constexpr month_day
operator/(const month& m, const day& d) noexcept;
constexpr month_day
operator/(const month& m, int d) noexcept;
constexpr month_day
operator/(int m, const day& d) noexcept;
constexpr month_day
operator/(const day& d, const month& m) noexcept;
constexpr month_day
operator/(const day& d, int m) noexcept;
constexpr month_day_last
operator/(const month& m, last_spec) noexcept;
constexpr month_day_last
operator/(int m, last_spec) noexcept;
constexpr month_day_last
operator/(last_spec, const month& m) noexcept;
constexpr month_day_last
operator/(last_spec, int m) noexcept;
constexpr month_weekday
operator/(const month& m, const weekday_indexed& wdi) noexcept;
constexpr month_weekday
operator/(int m, const weekday_indexed& wdi) noexcept;
constexpr month_weekday
operator/(const weekday_indexed& wdi, const month& m) noexcept;
constexpr month_weekday
operator/(const weekday_indexed& wdi, int m) noexcept;
constexpr month_weekday_last
operator/(const month& m, const weekday_last& wdl) noexcept;
constexpr month_weekday_last
operator/(int m, const weekday_last& wdl) noexcept;
constexpr month_weekday_last
operator/(const weekday_last& wdl, const month& m) noexcept;
constexpr month_weekday_last
operator/(const weekday_last& wdl, int m) noexcept;
constexpr year_month_day
operator/(const year_month& ym, const day& d) noexcept;
constexpr year_month_day
operator/(const year_month& ym, int d) noexcept;
constexpr year_month_day
operator/(const year& y, const month_day& md) noexcept;
constexpr year_month_day
operator/(int y, const month_day& md) noexcept;
constexpr year_month_day
operator/(const month_day& md, const year& y) noexcept;
constexpr year_month_day
operator/(const month_day& md, int y) noexcept;
constexpr year_month_day_last
operator/(const year_month& ym, last_spec) noexcept;
constexpr year_month_day_last
operator/(const year& y, const month_day_last& mdl) noexcept;
constexpr year_month_day_last
operator/(int y, const month_day_last& mdl) noexcept;
constexpr year_month_day_last
operator/(const month_day_last& mdl, const year& y) noexcept;
constexpr year_month_day_last
operator/(const month_day_last& mdl, int y) noexcept;
constexpr year_month_weekday
operator/(const year_month& ym, const weekday_indexed& wdi) noexcept;
constexpr year_month_weekday
operator/(const year& y, const month_weekday& mwd) noexcept;
constexpr year_month_weekday
operator/(int y, const month_weekday& mwd) noexcept;
constexpr year_month_weekday
operator/(const month_weekday& mwd, const year& y) noexcept;
constexpr year_month_weekday
operator/(const month_weekday& mwd, int y) noexcept;
constexpr year_month_weekday_last
operator/(const year_month& ym, const weekday_last& wdl) noexcept;
constexpr year_month_weekday_last
operator/(const year& y, const month_weekday_last& mwdl) noexcept;
constexpr year_month_weekday_last
operator/(int y, const month_weekday_last& mwdl) noexcept;
constexpr year_month_weekday_last
operator/(const month_weekday_last& mwdl, const year& y) noexcept;
constexpr year_month_weekday_last
operator/(const month_weekday_last& mwdl, int y) noexcept;
// 26.9, class template hh_mm_ss
template <class Duration>
class hh_mm_ss
{
bool is_neg; // exposition only
chrono::hours h; // exposition only
chrono::minutes m; // exposition only
chrono::seconds s; // exposition only
precision ss; // exposition only
public:
static unsigned constexpr fractional_width = see below;
using precision = see below;
constexpr hh_mm_ss() noexcept : hh_mm_ss{Duration::zero()} {}
constexpr explicit hh_mm_ss(Duration d) noexcept;
constexpr bool is_negative() const noexcept;
constexpr chrono::hours hours() const noexcept;
constexpr chrono::minutes minutes() const noexcept;
constexpr chrono::seconds seconds() const noexcept;
constexpr precision subseconds() const noexcept;
constexpr explicit operator precision() const noexcept;
constexpr precision to_duration() const noexcept;
};
template <class charT, class traits, class Duration>
basic_ostream<charT, traits>&
operator<<(basic_ostream<charT, traits>& os, hh_mm_ss<Duration> const& hms);
// 26.10, 12/24 hour functions
constexpr bool is_am(hours const& h) noexcept;
constexpr bool is_pm(hours const& h) noexcept;
constexpr hours make12(const hours& h) noexcept;
constexpr hours make24(const hours& h, bool is_pm) noexcept;
// 25.10.2, time zone database // C++20
struct tzdb;
class tzdb_list;
// 25.10.2.3, time zone database access // C++20
const tzdb& get_tzdb();
tzdb_list& get_tzdb_list();
const time_zone* locate_zone(string_view tz_name);
const time_zone* current_zone();
// 25.10.2.4, remote time zone database support // C++20
const tzdb& reload_tzdb();
string remote_version();
// 25.10.3, exception classes // C++20
class nonexistent_local_time;
class ambiguous_local_time;
// 25.10.4, information classes // C++20
struct sys_info;
struct local_info;
// 25.10.5, class time_zone // C++20
enum class choose {earliest, latest};
class time_zone;
bool operator==(const time_zone& x, const time_zone& y) noexcept;
bool operator!=(const time_zone& x, const time_zone& y) noexcept;
bool operator<(const time_zone& x, const time_zone& y) noexcept;
bool operator>(const time_zone& x, const time_zone& y) noexcept;
bool operator<=(const time_zone& x, const time_zone& y) noexcept;
bool operator>=(const time_zone& x, const time_zone& y) noexcept;
// 25.10.6, class template zoned_traits // C++20
template<class T> struct zoned_traits;
// 25.10.7, class template zoned_time // C++20
template<class Duration, class TimeZonePtr = const time_zone*> class zoned_time;
using zoned_seconds = zoned_time<seconds>;
template<class Duration1, class Duration2, class TimeZonePtr>
bool operator==(const zoned_time<Duration1, TimeZonePtr>& x,
const zoned_time<Duration2, TimeZonePtr>& y);
template<class Duration1, class Duration2, class TimeZonePtr>
bool operator!=(const zoned_time<Duration1, TimeZonePtr>& x,
const zoned_time<Duration2, TimeZonePtr>& y);
// 25.10.8, leap second support // C++20
class leap;
bool operator==(const leap& x, const leap& y);
bool operator!=(const leap& x, const leap& y);
bool operator< (const leap& x, const leap& y);
bool operator> (const leap& x, const leap& y);
bool operator<=(const leap& x, const leap& y);
bool operator>=(const leap& x, const leap& y);
template<class Duration>
bool operator==(const leap& x, const sys_time<Duration>& y);
template<class Duration>
bool operator==(const sys_time<Duration>& x, const leap& y);
template<class Duration>
bool operator!=(const leap& x, const sys_time<Duration>& y);
template<class Duration>
bool operator!=(const sys_time<Duration>& x, const leap& y);
template<class Duration>
bool operator< (const leap& x, const sys_time<Duration>& y);
template<class Duration>
bool operator< (const sys_time<Duration>& x, const leap& y);
template<class Duration>
bool operator> (const leap& x, const sys_time<Duration>& y);
template<class Duration>
bool operator> (const sys_time<Duration>& x, const leap& y);
template<class Duration>
bool operator<=(const leap& x, const sys_time<Duration>& y);
template<class Duration>
bool operator<=(const sys_time<Duration>& x, const leap& y);
template<class Duration>
bool operator>=(const leap& x, const sys_time<Duration>& y);
template<class Duration>
bool operator>=(const sys_time<Duration>& x, const leap& y);
// 25.10.9, class link // C++20
class link;
bool operator==(const link& x, const link& y);
bool operator!=(const link& x, const link& y);
bool operator< (const link& x, const link& y);
bool operator> (const link& x, const link& y);
bool operator<=(const link& x, const link& y);
bool operator>=(const link& x, const link& y);
// 25.11, formatting // C++20
template<class charT, class Streamable>
basic_string<charT>
format(const charT* fmt, const Streamable& s);
template<class charT, class Streamable>
basic_string<charT>
format(const locale& loc, const charT* fmt, const Streamable& s);
template<class charT, class traits, class Alloc, class Streamable>
basic_string<charT, traits, Alloc>
format(const basic_string<charT, traits, Alloc>& fmt, const Streamable& s);
template<class charT, class traits, class Alloc, class Streamable>
basic_string<charT, traits, Alloc>
format(const locale& loc, const basic_string<charT, traits, Alloc>& fmt,
const Streamable& s);
// 25.12, parsing // C++20
template<class charT, class traits, class Alloc, class Parsable>
unspecified
parse(const basic_string<charT, traits, Alloc>& format, Parsable& tp);
template<class charT, class traits, class Alloc, class Parsable>
unspecified
parse(const basic_string<charT, traits, Alloc>& format, Parsable& tp,
basic_string<charT, traits, Alloc>& abbrev);
template<class charT, class traits, class Alloc, class Parsable>
unspecified
parse(const basic_string<charT, traits, Alloc>& format, Parsable& tp,
minutes& offset);
template<class charT, class traits, class Alloc, class Parsable>
unspecified
parse(const basic_string<charT, traits, Alloc>& format, Parsable& tp,
basic_string<charT, traits, Alloc>& abbrev, minutes& offset);
// calendrical constants
inline constexpr last_spec last{}; // C++20
inline constexpr chrono::weekday Sunday{0}; // C++20
inline constexpr chrono::weekday Monday{1}; // C++20
inline constexpr chrono::weekday Tuesday{2}; // C++20
inline constexpr chrono::weekday Wednesday{3}; // C++20
inline constexpr chrono::weekday Thursday{4}; // C++20
inline constexpr chrono::weekday Friday{5}; // C++20
inline constexpr chrono::weekday Saturday{6}; // C++20
inline constexpr chrono::month January{1}; // C++20
inline constexpr chrono::month February{2}; // C++20
inline constexpr chrono::month March{3}; // C++20
inline constexpr chrono::month April{4}; // C++20
inline constexpr chrono::month May{5}; // C++20
inline constexpr chrono::month June{6}; // C++20
inline constexpr chrono::month July{7}; // C++20
inline constexpr chrono::month August{8}; // C++20
inline constexpr chrono::month September{9}; // C++20
inline constexpr chrono::month October{10}; // C++20
inline constexpr chrono::month November{11}; // C++20
inline constexpr chrono::month December{12}; // C++20
} // chrono
inline namespace literals {
inline namespace chrono_literals {
constexpr chrono::hours operator ""h(unsigned long long); // C++14
constexpr chrono::duration<unspecified , ratio<3600,1>> operator ""h(long double); // C++14
constexpr chrono::minutes operator ""min(unsigned long long); // C++14
constexpr chrono::duration<unspecified , ratio<60,1>> operator ""min(long double); // C++14
constexpr chrono::seconds operator ""s(unsigned long long); // C++14
constexpr chrono::duration<unspecified > operator ""s(long double); // C++14
constexpr chrono::milliseconds operator ""ms(unsigned long long); // C++14
constexpr chrono::duration<unspecified , milli> operator ""ms(long double); // C++14
constexpr chrono::microseconds operator ""us(unsigned long long); // C++14
constexpr chrono::duration<unspecified , micro> operator ""us(long double); // C++14
constexpr chrono::nanoseconds operator ""ns(unsigned long long); // C++14
constexpr chrono::duration<unspecified , nano> operator ""ns(long double); // C++14
constexpr chrono::day operator ""d(unsigned long long d) noexcept; // C++20
constexpr chrono::year operator ""y(unsigned long long y) noexcept; // C++20
} // chrono_literals
} // literals
} // std
*/
namespace chrono
{
template <class _Rep, class _Period = ratio<1> > class _LIBCPP_TEMPLATE_VIS duration;
template <class _Tp>
struct __is_duration : false_type {};
template <class _Rep, class _Period>
struct __is_duration<duration<_Rep, _Period> > : true_type {};
template <class _Rep, class _Period>
struct __is_duration<const duration<_Rep, _Period> > : true_type {};
template <class _Rep, class _Period>
struct __is_duration<volatile duration<_Rep, _Period> > : true_type {};
template <class _Rep, class _Period>
struct __is_duration<const volatile duration<_Rep, _Period> > : true_type {};
} // chrono
template <class _Rep1, class _Period1, class _Rep2, class _Period2>
struct _LIBCPP_TEMPLATE_VIS common_type<chrono::duration<_Rep1, _Period1>,
chrono::duration<_Rep2, _Period2> >
{
typedef chrono::duration<typename common_type<_Rep1, _Rep2>::type,
typename __ratio_gcd<_Period1, _Period2>::type> type;
};
namespace chrono {
// duration_cast
template <class _FromDuration, class _ToDuration,
class _Period = typename ratio_divide<typename _FromDuration::period, typename _ToDuration::period>::type,
bool = _Period::num == 1,
bool = _Period::den == 1>
struct __duration_cast;
template <class _FromDuration, class _ToDuration, class _Period>
struct __duration_cast<_FromDuration, _ToDuration, _Period, true, true>
{
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
_ToDuration operator()(const _FromDuration& __fd) const
{
return _ToDuration(static_cast<typename _ToDuration::rep>(__fd.count()));
}
};
template <class _FromDuration, class _ToDuration, class _Period>
struct __duration_cast<_FromDuration, _ToDuration, _Period, true, false>
{
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
_ToDuration operator()(const _FromDuration& __fd) const
{
typedef typename common_type<typename _ToDuration::rep, typename _FromDuration::rep, intmax_t>::type _Ct;
return _ToDuration(static_cast<typename _ToDuration::rep>(
static_cast<_Ct>(__fd.count()) / static_cast<_Ct>(_Period::den)));
}
};
template <class _FromDuration, class _ToDuration, class _Period>
struct __duration_cast<_FromDuration, _ToDuration, _Period, false, true>
{
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
_ToDuration operator()(const _FromDuration& __fd) const
{
typedef typename common_type<typename _ToDuration::rep, typename _FromDuration::rep, intmax_t>::type _Ct;
return _ToDuration(static_cast<typename _ToDuration::rep>(
static_cast<_Ct>(__fd.count()) * static_cast<_Ct>(_Period::num)));
}
};
template <class _FromDuration, class _ToDuration, class _Period>
struct __duration_cast<_FromDuration, _ToDuration, _Period, false, false>
{
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
_ToDuration operator()(const _FromDuration& __fd) const
{
typedef typename common_type<typename _ToDuration::rep, typename _FromDuration::rep, intmax_t>::type _Ct;
return _ToDuration(static_cast<typename _ToDuration::rep>(
static_cast<_Ct>(__fd.count()) * static_cast<_Ct>(_Period::num)
/ static_cast<_Ct>(_Period::den)));
}
};
template <class _ToDuration, class _Rep, class _Period>
inline _LIBCPP_INLINE_VISIBILITY
_LIBCPP_CONSTEXPR
typename enable_if
<
__is_duration<_ToDuration>::value,
_ToDuration
>::type
duration_cast(const duration<_Rep, _Period>& __fd)
{
return __duration_cast<duration<_Rep, _Period>, _ToDuration>()(__fd);
}
template <class _Rep>
struct _LIBCPP_TEMPLATE_VIS treat_as_floating_point : is_floating_point<_Rep> {};
#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
template <class _Rep>
_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool treat_as_floating_point_v
= treat_as_floating_point<_Rep>::value;
#endif
template <class _Rep>
struct _LIBCPP_TEMPLATE_VIS duration_values
{
public:
_LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR _Rep zero() _NOEXCEPT {return _Rep(0);}
_LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR _Rep max() _NOEXCEPT {return numeric_limits<_Rep>::max();}
_LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR _Rep min() _NOEXCEPT {return numeric_limits<_Rep>::lowest();}
};
#if _LIBCPP_STD_VER > 14
template <class _ToDuration, class _Rep, class _Period>
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
typename enable_if
<
__is_duration<_ToDuration>::value,
_ToDuration
>::type
floor(const duration<_Rep, _Period>& __d)
{
_ToDuration __t = duration_cast<_ToDuration>(__d);
if (__t > __d)
__t = __t - _ToDuration{1};
return __t;
}
template <class _ToDuration, class _Rep, class _Period>
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
typename enable_if
<
__is_duration<_ToDuration>::value,
_ToDuration
>::type
ceil(const duration<_Rep, _Period>& __d)
{
_ToDuration __t = duration_cast<_ToDuration>(__d);
if (__t < __d)
__t = __t + _ToDuration{1};
return __t;
}
template <class _ToDuration, class _Rep, class _Period>
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
typename enable_if
<
__is_duration<_ToDuration>::value,
_ToDuration
>::type
round(const duration<_Rep, _Period>& __d)
{
_ToDuration __lower = floor<_ToDuration>(__d);
_ToDuration __upper = __lower + _ToDuration{1};
auto __lowerDiff = __d - __lower;
auto __upperDiff = __upper - __d;
if (__lowerDiff < __upperDiff)
return __lower;
if (__lowerDiff > __upperDiff)
return __upper;
return __lower.count() & 1 ? __upper : __lower;
}
#endif
// duration
template <class _Rep, class _Period>
class _LIBCPP_TEMPLATE_VIS duration
{
static_assert(!__is_duration<_Rep>::value, "A duration representation can not be a duration");
static_assert(__is_ratio<_Period>::value, "Second template parameter of duration must be a std::ratio");
static_assert(_Period::num > 0, "duration period must be positive");
template <class _R1, class _R2>
struct __no_overflow
{
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;
static const intmax_t __n1 = _R1::num / __gcd_n1_n2;
static const intmax_t __d1 = _R1::den / __gcd_d1_d2;
static const intmax_t __n2 = _R2::num / __gcd_n1_n2;
static const intmax_t __d2 = _R2::den / __gcd_d1_d2;
static const intmax_t max = -((intmax_t(1) << (sizeof(intmax_t) * CHAR_BIT - 1)) + 1);
template <intmax_t _Xp, intmax_t _Yp, bool __overflow>
struct __mul // __overflow == false
{
static const intmax_t value = _Xp * _Yp;
};
template <intmax_t _Xp, intmax_t _Yp>
struct __mul<_Xp, _Yp, true>
{
static const intmax_t value = 1;
};
public:
static const bool value = (__n1 <= max / __d2) && (__n2 <= max / __d1);
typedef ratio<__mul<__n1, __d2, !value>::value,
__mul<__n2, __d1, !value>::value> type;
};
public:
typedef _Rep rep;
typedef typename _Period::type period;
private:
rep __rep_;
public:
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
#ifndef _LIBCPP_CXX03_LANG
duration() = default;
#else
duration() {}
#endif
template <class _Rep2>
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
explicit duration(const _Rep2& __r,
typename enable_if
<
is_convertible<_Rep2, rep>::value &&
(treat_as_floating_point<rep>::value ||
!treat_as_floating_point<_Rep2>::value)
>::type* = 0)
: __rep_(__r) {}
// conversions
template <class _Rep2, class _Period2>
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
duration(const duration<_Rep2, _Period2>& __d,
typename enable_if
<
__no_overflow<_Period2, period>::value && (
treat_as_floating_point<rep>::value ||
(__no_overflow<_Period2, period>::type::den == 1 &&
!treat_as_floating_point<_Rep2>::value))
>::type* = 0)
: __rep_(_VSTD::chrono::duration_cast<duration>(__d).count()) {}
// observer
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR rep count() const {return __rep_;}
// arithmetic
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR typename common_type<duration>::type operator+() const {return typename common_type<duration>::type(*this);}
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR typename common_type<duration>::type operator-() const {return typename common_type<duration>::type(-__rep_);}
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 duration& operator++() {++__rep_; return *this;}
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 duration operator++(int) {return duration(__rep_++);}
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 duration& operator--() {--__rep_; return *this;}
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 duration operator--(int) {return duration(__rep_--);}
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 duration& operator+=(const duration& __d) {__rep_ += __d.count(); return *this;}
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 duration& operator-=(const duration& __d) {__rep_ -= __d.count(); return *this;}
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 duration& operator*=(const rep& rhs) {__rep_ *= rhs; return *this;}
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 duration& operator/=(const rep& rhs) {__rep_ /= rhs; return *this;}
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 duration& operator%=(const rep& rhs) {__rep_ %= rhs; return *this;}
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 duration& operator%=(const duration& rhs) {__rep_ %= rhs.count(); return *this;}
// special values
_LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR duration zero() _NOEXCEPT {return duration(duration_values<rep>::zero());}
_LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR duration min() _NOEXCEPT {return duration(duration_values<rep>::min());}
_LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR duration max() _NOEXCEPT {return duration(duration_values<rep>::max());}
};
typedef duration<long long, nano> nanoseconds;
typedef duration<long long, micro> microseconds;
typedef duration<long long, milli> milliseconds;
typedef duration<long long > seconds;
typedef duration< long, ratio< 60> > minutes;
typedef duration< long, ratio<3600> > hours;
#if _LIBCPP_STD_VER > 17
typedef duration< int, ratio_multiply<ratio<24>, hours::period>> days;
typedef duration< int, ratio_multiply<ratio<7>, days::period>> weeks;
typedef duration< int, ratio_multiply<ratio<146097, 400>, days::period>> years;
typedef duration< int, ratio_divide<years::period, ratio<12>>> months;
#endif
// Duration ==
template <class _LhsDuration, class _RhsDuration>
struct __duration_eq
{
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
bool operator()(const _LhsDuration& __lhs, const _RhsDuration& __rhs) const
{
typedef typename common_type<_LhsDuration, _RhsDuration>::type _Ct;
return _Ct(__lhs).count() == _Ct(__rhs).count();
}
};
template <class _LhsDuration>
struct __duration_eq<_LhsDuration, _LhsDuration>
{
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
bool operator()(const _LhsDuration& __lhs, const _LhsDuration& __rhs) const
{return __lhs.count() == __rhs.count();}
};
template <class _Rep1, class _Period1, class _Rep2, class _Period2>
inline _LIBCPP_INLINE_VISIBILITY
_LIBCPP_CONSTEXPR
bool
operator==(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs)
{
return __duration_eq<duration<_Rep1, _Period1>, duration<_Rep2, _Period2> >()(__lhs, __rhs);
}
// Duration !=
template <class _Rep1, class _Period1, class _Rep2, class _Period2>
inline _LIBCPP_INLINE_VISIBILITY
_LIBCPP_CONSTEXPR
bool
operator!=(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs)
{
return !(__lhs == __rhs);
}
// Duration <
template <class _LhsDuration, class _RhsDuration>
struct __duration_lt
{
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
bool operator()(const _LhsDuration& __lhs, const _RhsDuration& __rhs) const
{
typedef typename common_type<_LhsDuration, _RhsDuration>::type _Ct;
return _Ct(__lhs).count() < _Ct(__rhs).count();
}
};
template <class _LhsDuration>
struct __duration_lt<_LhsDuration, _LhsDuration>
{
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
bool operator()(const _LhsDuration& __lhs, const _LhsDuration& __rhs) const
{return __lhs.count() < __rhs.count();}
};
template <class _Rep1, class _Period1, class _Rep2, class _Period2>
inline _LIBCPP_INLINE_VISIBILITY
_LIBCPP_CONSTEXPR
bool
operator< (const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs)
{
return __duration_lt<duration<_Rep1, _Period1>, duration<_Rep2, _Period2> >()(__lhs, __rhs);
}
// Duration >
template <class _Rep1, class _Period1, class _Rep2, class _Period2>
inline _LIBCPP_INLINE_VISIBILITY
_LIBCPP_CONSTEXPR
bool
operator> (const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs)
{
return __rhs < __lhs;
}
// Duration <=
template <class _Rep1, class _Period1, class _Rep2, class _Period2>
inline _LIBCPP_INLINE_VISIBILITY
_LIBCPP_CONSTEXPR
bool
operator<=(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs)
{
return !(__rhs < __lhs);
}
// Duration >=
template <class _Rep1, class _Period1, class _Rep2, class _Period2>
inline _LIBCPP_INLINE_VISIBILITY
_LIBCPP_CONSTEXPR
bool
operator>=(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs)
{
return !(__lhs < __rhs);
}
// Duration +
template <class _Rep1, class _Period1, class _Rep2, class _Period2>
inline _LIBCPP_INLINE_VISIBILITY
_LIBCPP_CONSTEXPR
typename common_type<duration<_Rep1, _Period1>, duration<_Rep2, _Period2> >::type
operator+(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs)
{
typedef typename common_type<duration<_Rep1, _Period1>, duration<_Rep2, _Period2> >::type _Cd;
return _Cd(_Cd(__lhs).count() + _Cd(__rhs).count());
}
// Duration -
template <class _Rep1, class _Period1, class _Rep2, class _Period2>
inline _LIBCPP_INLINE_VISIBILITY
_LIBCPP_CONSTEXPR
typename common_type<duration<_Rep1, _Period1>, duration<_Rep2, _Period2> >::type
operator-(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs)
{
typedef typename common_type<duration<_Rep1, _Period1>, duration<_Rep2, _Period2> >::type _Cd;
return _Cd(_Cd(__lhs).count() - _Cd(__rhs).count());
}
// Duration *
template <class _Rep1, class _Period, class _Rep2>
inline _LIBCPP_INLINE_VISIBILITY
_LIBCPP_CONSTEXPR
typename enable_if
<
is_convertible<_Rep2, typename common_type<_Rep1, _Rep2>::type>::value,
duration<typename common_type<_Rep1, _Rep2>::type, _Period>
>::type
operator*(const duration<_Rep1, _Period>& __d, const _Rep2& __s)
{
typedef typename common_type<_Rep1, _Rep2>::type _Cr;
typedef duration<_Cr, _Period> _Cd;
return _Cd(_Cd(__d).count() * static_cast<_Cr>(__s));
}
template <class _Rep1, class _Period, class _Rep2>
inline _LIBCPP_INLINE_VISIBILITY
_LIBCPP_CONSTEXPR
typename enable_if
<
is_convertible<_Rep1, typename common_type<_Rep1, _Rep2>::type>::value,
duration<typename common_type<_Rep1, _Rep2>::type, _Period>
>::type
operator*(const _Rep1& __s, const duration<_Rep2, _Period>& __d)
{
return __d * __s;
}
// Duration /
template <class _Rep1, class _Period, class _Rep2>
inline _LIBCPP_INLINE_VISIBILITY
_LIBCPP_CONSTEXPR
typename enable_if
<
!__is_duration<_Rep2>::value &&
is_convertible<_Rep2, typename common_type<_Rep1, _Rep2>::type>::value,
duration<typename common_type<_Rep1, _Rep2>::type, _Period>
>::type
operator/(const duration<_Rep1, _Period>& __d, const _Rep2& __s)
{
typedef typename common_type<_Rep1, _Rep2>::type _Cr;
typedef duration<_Cr, _Period> _Cd;
return _Cd(_Cd(__d).count() / static_cast<_Cr>(__s));
}
template <class _Rep1, class _Period1, class _Rep2, class _Period2>
inline _LIBCPP_INLINE_VISIBILITY
_LIBCPP_CONSTEXPR
typename common_type<_Rep1, _Rep2>::type
operator/(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs)
{
typedef typename common_type<duration<_Rep1, _Period1>, duration<_Rep2, _Period2> >::type _Ct;
return _Ct(__lhs).count() / _Ct(__rhs).count();
}
// Duration %
template <class _Rep1, class _Period, class _Rep2>
inline _LIBCPP_INLINE_VISIBILITY
_LIBCPP_CONSTEXPR
typename enable_if
<
!__is_duration<_Rep2>::value &&
is_convertible<_Rep2, typename common_type<_Rep1, _Rep2>::type>::value,
duration<typename common_type<_Rep1, _Rep2>::type, _Period>
>::type
operator%(const duration<_Rep1, _Period>& __d, const _Rep2& __s)
{
typedef typename common_type<_Rep1, _Rep2>::type _Cr;
typedef duration<_Cr, _Period> _Cd;
return _Cd(_Cd(__d).count() % static_cast<_Cr>(__s));
}
template <class _Rep1, class _Period1, class _Rep2, class _Period2>
inline _LIBCPP_INLINE_VISIBILITY
_LIBCPP_CONSTEXPR
typename common_type<duration<_Rep1, _Period1>, duration<_Rep2, _Period2> >::type
operator%(const duration<_Rep1, _Period1>& __lhs, const duration<_Rep2, _Period2>& __rhs)
{
typedef typename common_type<_Rep1, _Rep2>::type _Cr;
typedef typename common_type<duration<_Rep1, _Period1>, duration<_Rep2, _Period2> >::type _Cd;
return _Cd(static_cast<_Cr>(_Cd(__lhs).count()) % static_cast<_Cr>(_Cd(__rhs).count()));
}
//////////////////////////////////////////////////////////
///////////////////// time_point /////////////////////////
//////////////////////////////////////////////////////////
template <class _Clock, class _Duration = typename _Clock::duration>
class _LIBCPP_TEMPLATE_VIS time_point
{
static_assert(__is_duration<_Duration>::value,
"Second template parameter of time_point must be a std::chrono::duration");
public:
typedef _Clock clock;
typedef _Duration duration;
typedef typename duration::rep rep;
typedef typename duration::period period;
private:
duration __d_;
public:
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 time_point() : __d_(duration::zero()) {}
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 explicit time_point(const duration& __d) : __d_(__d) {}
// conversions
template <class _Duration2>
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
time_point(const time_point<clock, _Duration2>& t,
typename enable_if
<
is_convertible<_Duration2, duration>::value
>::type* = 0)
: __d_(t.time_since_epoch()) {}
// observer
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 duration time_since_epoch() const {return __d_;}
// arithmetic
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 time_point& operator+=(const duration& __d) {__d_ += __d; return *this;}
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 time_point& operator-=(const duration& __d) {__d_ -= __d; return *this;}
// special values
_LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR time_point min() _NOEXCEPT {return time_point(duration::min());}
_LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR time_point max() _NOEXCEPT {return time_point(duration::max());}
};
} // chrono
template <class _Clock, class _Duration1, class _Duration2>
struct _LIBCPP_TEMPLATE_VIS common_type<chrono::time_point<_Clock, _Duration1>,
chrono::time_point<_Clock, _Duration2> >
{
typedef chrono::time_point<_Clock, typename common_type<_Duration1, _Duration2>::type> type;
};
namespace chrono {
template <class _ToDuration, class _Clock, class _Duration>
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
time_point<_Clock, _ToDuration>
time_point_cast(const time_point<_Clock, _Duration>& __t)
{
return time_point<_Clock, _ToDuration>(_VSTD::chrono::duration_cast<_ToDuration>(__t.time_since_epoch()));
}
#if _LIBCPP_STD_VER > 14
template <class _ToDuration, class _Clock, class _Duration>
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
typename enable_if
<
__is_duration<_ToDuration>::value,
time_point<_Clock, _ToDuration>
>::type
floor(const time_point<_Clock, _Duration>& __t)
{
return time_point<_Clock, _ToDuration>{floor<_ToDuration>(__t.time_since_epoch())};
}
template <class _ToDuration, class _Clock, class _Duration>
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
typename enable_if
<
__is_duration<_ToDuration>::value,
time_point<_Clock, _ToDuration>
>::type
ceil(const time_point<_Clock, _Duration>& __t)
{
return time_point<_Clock, _ToDuration>{ceil<_ToDuration>(__t.time_since_epoch())};
}
template <class _ToDuration, class _Clock, class _Duration>
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
typename enable_if
<
__is_duration<_ToDuration>::value,
time_point<_Clock, _ToDuration>
>::type
round(const time_point<_Clock, _Duration>& __t)
{
return time_point<_Clock, _ToDuration>{round<_ToDuration>(__t.time_since_epoch())};
}
template <class _Rep, class _Period>
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
typename enable_if
<
numeric_limits<_Rep>::is_signed,
duration<_Rep, _Period>
>::type
abs(duration<_Rep, _Period> __d)
{
return __d >= __d.zero() ? +__d : -__d;
}
#endif
// time_point ==
template <class _Clock, class _Duration1, class _Duration2>
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
bool
operator==(const time_point<_Clock, _Duration1>& __lhs, const time_point<_Clock, _Duration2>& __rhs)
{
return __lhs.time_since_epoch() == __rhs.time_since_epoch();
}
// time_point !=
template <class _Clock, class _Duration1, class _Duration2>
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
bool
operator!=(const time_point<_Clock, _Duration1>& __lhs, const time_point<_Clock, _Duration2>& __rhs)
{
return !(__lhs == __rhs);
}
// time_point <
template <class _Clock, class _Duration1, class _Duration2>
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
bool
operator<(const time_point<_Clock, _Duration1>& __lhs, const time_point<_Clock, _Duration2>& __rhs)
{
return __lhs.time_since_epoch() < __rhs.time_since_epoch();
}
// time_point >
template <class _Clock, class _Duration1, class _Duration2>
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
bool
operator>(const time_point<_Clock, _Duration1>& __lhs, const time_point<_Clock, _Duration2>& __rhs)
{
return __rhs < __lhs;
}
// time_point <=
template <class _Clock, class _Duration1, class _Duration2>
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
bool
operator<=(const time_point<_Clock, _Duration1>& __lhs, const time_point<_Clock, _Duration2>& __rhs)
{
return !(__rhs < __lhs);
}
// time_point >=
template <class _Clock, class _Duration1, class _Duration2>
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
bool
operator>=(const time_point<_Clock, _Duration1>& __lhs, const time_point<_Clock, _Duration2>& __rhs)
{
return !(__lhs < __rhs);
}
// time_point operator+(time_point x, duration y);
template <class _Clock, class _Duration1, class _Rep2, class _Period2>
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
time_point<_Clock, typename common_type<_Duration1, duration<_Rep2, _Period2> >::type>
operator+(const time_point<_Clock, _Duration1>& __lhs, const duration<_Rep2, _Period2>& __rhs)
{
typedef time_point<_Clock, typename common_type<_Duration1, duration<_Rep2, _Period2> >::type> _Tr;
return _Tr (__lhs.time_since_epoch() + __rhs);
}
// time_point operator+(duration x, time_point y);
template <class _Rep1, class _Period1, class _Clock, class _Duration2>
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
time_point<_Clock, typename common_type<duration<_Rep1, _Period1>, _Duration2>::type>
operator+(const duration<_Rep1, _Period1>& __lhs, const time_point<_Clock, _Duration2>& __rhs)
{
return __rhs + __lhs;
}
// time_point operator-(time_point x, duration y);
template <class _Clock, class _Duration1, class _Rep2, class _Period2>
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
time_point<_Clock, typename common_type<_Duration1, duration<_Rep2, _Period2> >::type>
operator-(const time_point<_Clock, _Duration1>& __lhs, const duration<_Rep2, _Period2>& __rhs)
{
typedef time_point<_Clock, typename common_type<_Duration1, duration<_Rep2, _Period2> >::type> _Ret;
return _Ret(__lhs.time_since_epoch() -__rhs);
}
// duration operator-(time_point x, time_point y);
template <class _Clock, class _Duration1, class _Duration2>
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
typename common_type<_Duration1, _Duration2>::type
operator-(const time_point<_Clock, _Duration1>& __lhs, const time_point<_Clock, _Duration2>& __rhs)
{
return __lhs.time_since_epoch() - __rhs.time_since_epoch();
}
//////////////////////////////////////////////////////////
/////////////////////// clocks ///////////////////////////
//////////////////////////////////////////////////////////
class _LIBCPP_TYPE_VIS system_clock
{
public:
typedef microseconds duration;
typedef duration::rep rep;
typedef duration::period period;
typedef chrono::time_point<system_clock> time_point;
static _LIBCPP_CONSTEXPR_AFTER_CXX11 const bool is_steady = false;
static time_point now() _NOEXCEPT;
static time_t to_time_t (const time_point& __t) _NOEXCEPT;
static time_point from_time_t(time_t __t) _NOEXCEPT;
};
#ifndef _LIBCPP_HAS_NO_MONOTONIC_CLOCK
class _LIBCPP_TYPE_VIS steady_clock
{
public:
typedef nanoseconds duration;
typedef duration::rep rep;
typedef duration::period period;
typedef chrono::time_point<steady_clock, duration> time_point;
static _LIBCPP_CONSTEXPR_AFTER_CXX11 const bool is_steady = true;
static time_point now() _NOEXCEPT;
};
typedef steady_clock high_resolution_clock;
#else
typedef system_clock high_resolution_clock;
#endif
#if _LIBCPP_STD_VER > 17
// [time.clock.file], type file_clock
using file_clock = _VSTD_FS::_FilesystemClock;
template<class _Duration>
using file_time = time_point<file_clock, _Duration>;
template <class _Duration>
using sys_time = time_point<system_clock, _Duration>;
using sys_seconds = sys_time<seconds>;
using sys_days = sys_time<days>;
struct local_t {};
template<class Duration>
using local_time = time_point<local_t, Duration>;
using local_seconds = local_time<seconds>;
using local_days = local_time<days>;
struct last_spec { explicit last_spec() = default; };
class day {
private:
unsigned char __d;
public:
day() = default;
explicit inline constexpr day(unsigned __val) noexcept : __d(static_cast<unsigned char>(__val)) {}
inline constexpr day& operator++() noexcept { ++__d; return *this; }
inline constexpr day operator++(int) noexcept { day __tmp = *this; ++(*this); return __tmp; }
inline constexpr day& operator--() noexcept { --__d; return *this; }
inline constexpr day operator--(int) noexcept { day __tmp = *this; --(*this); return __tmp; }
constexpr day& operator+=(const days& __dd) noexcept;
constexpr day& operator-=(const days& __dd) noexcept;
explicit inline constexpr operator unsigned() const noexcept { return __d; }
inline constexpr bool ok() const noexcept { return __d >= 1 && __d <= 31; }
};
inline constexpr
bool operator==(const day& __lhs, const day& __rhs) noexcept
{ return static_cast<unsigned>(__lhs) == static_cast<unsigned>(__rhs); }
inline constexpr
bool operator!=(const day& __lhs, const day& __rhs) noexcept
{ return !(__lhs == __rhs); }
inline constexpr
bool operator< (const day& __lhs, const day& __rhs) noexcept
{ return static_cast<unsigned>(__lhs) < static_cast<unsigned>(__rhs); }
inline constexpr
bool operator> (const day& __lhs, const day& __rhs) noexcept
{ return __rhs < __lhs; }
inline constexpr
bool operator<=(const day& __lhs, const day& __rhs) noexcept
{ return !(__rhs < __lhs);}
inline constexpr
bool operator>=(const day& __lhs, const day& __rhs) noexcept
{ return !(__lhs < __rhs); }
inline constexpr
day operator+ (const day& __lhs, const days& __rhs) noexcept
{ return day(static_cast<unsigned>(__lhs) + __rhs.count()); }
inline constexpr
day operator+ (const days& __lhs, const day& __rhs) noexcept
{ return __rhs + __lhs; }
inline constexpr
day operator- (const day& __lhs, const days& __rhs) noexcept
{ return __lhs + -__rhs; }
inline constexpr
days operator-(const day& __lhs, const day& __rhs) noexcept
{ return days(static_cast<int>(static_cast<unsigned>(__lhs)) -
static_cast<int>(static_cast<unsigned>(__rhs))); }
inline constexpr day& day::operator+=(const days& __dd) noexcept
{ *this = *this + __dd; return *this; }
inline constexpr day& day::operator-=(const days& __dd) noexcept
{ *this = *this - __dd; return *this; }
class month {
private:
unsigned char __m;
public:
month() = default;
explicit inline constexpr month(unsigned __val) noexcept : __m(static_cast<unsigned char>(__val)) {}
inline constexpr month& operator++() noexcept { ++__m; return *this; }
inline constexpr month operator++(int) noexcept { month __tmp = *this; ++(*this); return __tmp; }
inline constexpr month& operator--() noexcept { --__m; return *this; }
inline constexpr month operator--(int) noexcept { month __tmp = *this; --(*this); return __tmp; }
constexpr month& operator+=(const months& __m1) noexcept;
constexpr month& operator-=(const months& __m1) noexcept;
explicit inline constexpr operator unsigned() const noexcept { return __m; }
inline constexpr bool ok() const noexcept { return __m >= 1 && __m <= 12; }
};
inline constexpr
bool operator==(const month& __lhs, const month& __rhs) noexcept
{ return static_cast<unsigned>(__lhs) == static_cast<unsigned>(__rhs); }
inline constexpr
bool operator!=(const month& __lhs, const month& __rhs) noexcept
{ return !(__lhs == __rhs); }
inline constexpr
bool operator< (const month& __lhs, const month& __rhs) noexcept
{ return static_cast<unsigned>(__lhs) < static_cast<unsigned>(__rhs); }
inline constexpr
bool operator> (const month& __lhs, const month& __rhs) noexcept
{ return __rhs < __lhs; }
inline constexpr
bool operator<=(const month& __lhs, const month& __rhs) noexcept
{ return !(__rhs < __lhs); }
inline constexpr
bool operator>=(const month& __lhs, const month& __rhs) noexcept
{ return !(__lhs < __rhs); }
inline constexpr
month operator+ (const month& __lhs, const months& __rhs) noexcept
{
auto const __mu = static_cast<long long>(static_cast<unsigned>(__lhs)) + (__rhs.count() - 1);
auto const __yr = (__mu >= 0 ? __mu : __mu - 11) / 12;
return month{static_cast<unsigned>(__mu - __yr * 12 + 1)};
}
inline constexpr
month operator+ (const months& __lhs, const month& __rhs) noexcept
{ return __rhs + __lhs; }
inline constexpr
month operator- (const month& __lhs, const months& __rhs) noexcept
{ return __lhs + -__rhs; }
inline constexpr
months operator-(const month& __lhs, const month& __rhs) noexcept
{
auto const __dm = static_cast<unsigned>(__lhs) - static_cast<unsigned>(__rhs);
return months(__dm <= 11 ? __dm : __dm + 12);
}
inline constexpr month& month::operator+=(const months& __dm) noexcept
{ *this = *this + __dm; return *this; }
inline constexpr month& month::operator-=(const months& __dm) noexcept
{ *this = *this - __dm; return *this; }
class year {
private:
short __y;
public:
year() = default;
explicit inline constexpr year(int __val) noexcept : __y(static_cast<short>(__val)) {}
inline constexpr year& operator++() noexcept { ++__y; return *this; }
inline constexpr year operator++(int) noexcept { year __tmp = *this; ++(*this); return __tmp; }
inline constexpr year& operator--() noexcept { --__y; return *this; }
inline constexpr year operator--(int) noexcept { year __tmp = *this; --(*this); return __tmp; }
constexpr year& operator+=(const years& __dy) noexcept;
constexpr year& operator-=(const years& __dy) noexcept;
inline constexpr year operator+() const noexcept { return *this; }
inline constexpr year operator-() const noexcept { return year{-__y}; }
inline constexpr bool is_leap() const noexcept { return __y % 4 == 0 && (__y % 100 != 0 || __y % 400 == 0); }
explicit inline constexpr operator int() const noexcept { return __y; }
constexpr bool ok() const noexcept;
static inline constexpr year min() noexcept { return year{-32767}; }
static inline constexpr year max() noexcept { return year{ 32767}; }
};
inline constexpr
bool operator==(const year& __lhs, const year& __rhs) noexcept
{ return static_cast<int>(__lhs) == static_cast<int>(__rhs); }
inline constexpr
bool operator!=(const year& __lhs, const year& __rhs) noexcept
{ return !(__lhs == __rhs); }
inline constexpr
bool operator< (const year& __lhs, const year& __rhs) noexcept
{ return static_cast<int>(__lhs) < static_cast<int>(__rhs); }
inline constexpr
bool operator> (const year& __lhs, const year& __rhs) noexcept
{ return __rhs < __lhs; }
inline constexpr
bool operator<=(const year& __lhs, const year& __rhs) noexcept
{ return !(__rhs < __lhs); }
inline constexpr
bool operator>=(const year& __lhs, const year& __rhs) noexcept
{ return !(__lhs < __rhs); }
inline constexpr
year operator+ (const year& __lhs, const years& __rhs) noexcept
{ return year(static_cast<int>(__lhs) + __rhs.count()); }
inline constexpr
year operator+ (const years& __lhs, const year& __rhs) noexcept
{ return __rhs + __lhs; }
inline constexpr
year operator- (const year& __lhs, const years& __rhs) noexcept
{ return __lhs + -__rhs; }
inline constexpr
years operator-(const year& __lhs, const year& __rhs) noexcept
{ return years{static_cast<int>(__lhs) - static_cast<int>(__rhs)}; }
inline constexpr year& year::operator+=(const years& __dy) noexcept
{ *this = *this + __dy; return *this; }
inline constexpr year& year::operator-=(const years& __dy) noexcept
{ *this = *this - __dy; return *this; }
inline constexpr bool year::ok() const noexcept
{ return static_cast<int>(min()) <= __y && __y <= static_cast<int>(max()); }
class weekday_indexed;
class weekday_last;
class weekday {
private:
unsigned char __wd;
public:
weekday() = default;
inline explicit constexpr weekday(unsigned __val) noexcept : __wd(static_cast<unsigned char>(__val == 7 ? 0 : __val)) {}
inline constexpr weekday(const sys_days& __sysd) noexcept
: __wd(__weekday_from_days(__sysd.time_since_epoch().count())) {}
inline explicit constexpr weekday(const local_days& __locd) noexcept
: __wd(__weekday_from_days(__locd.time_since_epoch().count())) {}
inline constexpr weekday& operator++() noexcept { __wd = (__wd == 6 ? 0 : __wd + 1); return *this; }
inline constexpr weekday operator++(int) noexcept { weekday __tmp = *this; ++(*this); return __tmp; }
inline constexpr weekday& operator--() noexcept { __wd = (__wd == 0 ? 6 : __wd - 1); return *this; }
inline constexpr weekday operator--(int) noexcept { weekday __tmp = *this; --(*this); return __tmp; }
constexpr weekday& operator+=(const days& __dd) noexcept;
constexpr weekday& operator-=(const days& __dd) noexcept;
inline constexpr unsigned c_encoding() const noexcept { return __wd; }
inline constexpr unsigned iso_encoding() const noexcept { return __wd == 0u ? 7 : __wd; }
inline constexpr bool ok() const noexcept { return __wd <= 6; }
constexpr weekday_indexed operator[](unsigned __index) const noexcept;
constexpr weekday_last operator[](last_spec) const noexcept;
static constexpr unsigned char __weekday_from_days(int __days) noexcept;
};
// https://howardhinnant.github.io/date_algorithms.html#weekday_from_days
inline constexpr
unsigned char weekday::__weekday_from_days(int __days) noexcept
{
return static_cast<unsigned char>(
static_cast<unsigned>(__days >= -4 ? (__days+4) % 7 : (__days+5) % 7 + 6)
);
}
inline constexpr
bool operator==(const weekday& __lhs, const weekday& __rhs) noexcept
{ return __lhs.c_encoding() == __rhs.c_encoding(); }
inline constexpr
bool operator!=(const weekday& __lhs, const weekday& __rhs) noexcept
{ return !(__lhs == __rhs); }
inline constexpr
bool operator< (const weekday& __lhs, const weekday& __rhs) noexcept
{ return __lhs.c_encoding() < __rhs.c_encoding(); }
inline constexpr
bool operator> (const weekday& __lhs, const weekday& __rhs) noexcept
{ return __rhs < __lhs; }
inline constexpr
bool operator<=(const weekday& __lhs, const weekday& __rhs) noexcept
{ return !(__rhs < __lhs);}
inline constexpr
bool operator>=(const weekday& __lhs, const weekday& __rhs) noexcept
{ return !(__lhs < __rhs); }
constexpr weekday operator+(const weekday& __lhs, const days& __rhs) noexcept
{
auto const __mu = static_cast<long long>(__lhs.c_encoding()) + __rhs.count();
auto const __yr = (__mu >= 0 ? __mu : __mu - 6) / 7;
return weekday{static_cast<unsigned>(__mu - __yr * 7)};
}
constexpr weekday operator+(const days& __lhs, const weekday& __rhs) noexcept
{ return __rhs + __lhs; }
constexpr weekday operator-(const weekday& __lhs, const days& __rhs) noexcept
{ return __lhs + -__rhs; }
constexpr days operator-(const weekday& __lhs, const weekday& __rhs) noexcept
{
const int __wdu = __lhs.c_encoding() - __rhs.c_encoding();
const int __wk = (__wdu >= 0 ? __wdu : __wdu-6) / 7;
return days{__wdu - __wk * 7};
}
inline constexpr weekday& weekday::operator+=(const days& __dd) noexcept
{ *this = *this + __dd; return *this; }
inline constexpr weekday& weekday::operator-=(const days& __dd) noexcept
{ *this = *this - __dd; return *this; }
class weekday_indexed {
private:
_VSTD::chrono::weekday __wd;
unsigned char __idx;
public:
weekday_indexed() = default;
inline constexpr weekday_indexed(const _VSTD::chrono::weekday& __wdval, unsigned __idxval) noexcept
: __wd{__wdval}, __idx(__idxval) {}
inline constexpr _VSTD::chrono::weekday weekday() const noexcept { return __wd; }
inline constexpr unsigned index() const noexcept { return __idx; }
inline constexpr bool ok() const noexcept { return __wd.ok() && __idx >= 1 && __idx <= 5; }
};
inline constexpr
bool operator==(const weekday_indexed& __lhs, const weekday_indexed& __rhs) noexcept
{ return __lhs.weekday() == __rhs.weekday() && __lhs.index() == __rhs.index(); }
inline constexpr
bool operator!=(const weekday_indexed& __lhs, const weekday_indexed& __rhs) noexcept
{ return !(__lhs == __rhs); }
class weekday_last {
private:
_VSTD::chrono::weekday __wd;
public:
explicit constexpr weekday_last(const _VSTD::chrono::weekday& __val) noexcept
: __wd{__val} {}
constexpr _VSTD::chrono::weekday weekday() const noexcept { return __wd; }
constexpr bool ok() const noexcept { return __wd.ok(); }
};
inline constexpr
bool operator==(const weekday_last& __lhs, const weekday_last& __rhs) noexcept
{ return __lhs.weekday() == __rhs.weekday(); }
inline constexpr
bool operator!=(const weekday_last& __lhs, const weekday_last& __rhs) noexcept
{ return !(__lhs == __rhs); }
inline constexpr
weekday_indexed weekday::operator[](unsigned __index) const noexcept { return weekday_indexed{*this, __index}; }
inline constexpr
weekday_last weekday::operator[](last_spec) const noexcept { return weekday_last{*this}; }
inline constexpr last_spec last{};
inline constexpr weekday Sunday{0};
inline constexpr weekday Monday{1};
inline constexpr weekday Tuesday{2};
inline constexpr weekday Wednesday{3};
inline constexpr weekday Thursday{4};
inline constexpr weekday Friday{5};
inline constexpr weekday Saturday{6};
inline constexpr month January{1};
inline constexpr month February{2};
inline constexpr month March{3};
inline constexpr month April{4};
inline constexpr month May{5};
inline constexpr month June{6};
inline constexpr month July{7};
inline constexpr month August{8};
inline constexpr month September{9};
inline constexpr month October{10};
inline constexpr month November{11};
inline constexpr month December{12};
class month_day {
private:
chrono::month __m;
chrono::day __d;
public:
month_day() = default;
constexpr month_day(const chrono::month& __mval, const chrono::day& __dval) noexcept
: __m{__mval}, __d{__dval} {}
inline constexpr chrono::month month() const noexcept { return __m; }
inline constexpr chrono::day day() const noexcept { return __d; }
constexpr bool ok() const noexcept;
};
inline constexpr
bool month_day::ok() const noexcept
{
if (!__m.ok()) return false;
const unsigned __dval = static_cast<unsigned>(__d);
if (__dval < 1 || __dval > 31) return false;
if (__dval <= 29) return true;
// Now we've got either 30 or 31
const unsigned __mval = static_cast<unsigned>(__m);
if (__mval == 2) return false;
if (__mval == 4 || __mval == 6 || __mval == 9 || __mval == 11)
return __dval == 30;
return true;
}
inline constexpr
bool operator==(const month_day& __lhs, const month_day& __rhs) noexcept
{ return __lhs.month() == __rhs.month() && __lhs.day() == __rhs.day(); }
inline constexpr
bool operator!=(const month_day& __lhs, const month_day& __rhs) noexcept
{ return !(__lhs == __rhs); }
inline constexpr
month_day operator/(const month& __lhs, const day& __rhs) noexcept
{ return month_day{__lhs, __rhs}; }
constexpr
month_day operator/(const day& __lhs, const month& __rhs) noexcept
{ return __rhs / __lhs; }
inline constexpr
month_day operator/(const month& __lhs, int __rhs) noexcept
{ return __lhs / day(__rhs); }
constexpr
month_day operator/(int __lhs, const day& __rhs) noexcept
{ return month(__lhs) / __rhs; }
constexpr
month_day operator/(const day& __lhs, int __rhs) noexcept
{ return month(__rhs) / __lhs; }
inline constexpr
bool operator< (const month_day& __lhs, const month_day& __rhs) noexcept
{ return __lhs.month() != __rhs.month() ? __lhs.month() < __rhs.month() : __lhs.day() < __rhs.day(); }
inline constexpr
bool operator> (const month_day& __lhs, const month_day& __rhs) noexcept
{ return __rhs < __lhs; }
inline constexpr
bool operator<=(const month_day& __lhs, const month_day& __rhs) noexcept
{ return !(__rhs < __lhs);}
inline constexpr
bool operator>=(const month_day& __lhs, const month_day& __rhs) noexcept
{ return !(__lhs < __rhs); }
class month_day_last {
private:
chrono::month __m;
public:
explicit constexpr month_day_last(const chrono::month& __val) noexcept
: __m{__val} {}
inline constexpr chrono::month month() const noexcept { return __m; }
inline constexpr bool ok() const noexcept { return __m.ok(); }
};
inline constexpr
bool operator==(const month_day_last& __lhs, const month_day_last& __rhs) noexcept
{ return __lhs.month() == __rhs.month(); }
inline constexpr
bool operator!=(const month_day_last& __lhs, const month_day_last& __rhs) noexcept
{ return !(__lhs == __rhs); }
inline constexpr
bool operator< (const month_day_last& __lhs, const month_day_last& __rhs) noexcept
{ return __lhs.month() < __rhs.month(); }
inline constexpr
bool operator> (const month_day_last& __lhs, const month_day_last& __rhs) noexcept
{ return __rhs < __lhs; }
inline constexpr
bool operator<=(const month_day_last& __lhs, const month_day_last& __rhs) noexcept
{ return !(__rhs < __lhs);}
inline constexpr
bool operator>=(const month_day_last& __lhs, const month_day_last& __rhs) noexcept
{ return !(__lhs < __rhs); }
inline constexpr
month_day_last operator/(const month& __lhs, last_spec) noexcept
{ return month_day_last{__lhs}; }
inline constexpr
month_day_last operator/(last_spec, const month& __rhs) noexcept
{ return month_day_last{__rhs}; }
inline constexpr
month_day_last operator/(int __lhs, last_spec) noexcept
{ return month_day_last{month(__lhs)}; }
inline constexpr
month_day_last operator/(last_spec, int __rhs) noexcept
{ return month_day_last{month(__rhs)}; }
class month_weekday {
private:
chrono::month __m;
chrono::weekday_indexed __wdi;
public:
month_weekday() = default;
constexpr month_weekday(const chrono::month& __mval, const chrono::weekday_indexed& __wdival) noexcept
: __m{__mval}, __wdi{__wdival} {}
inline constexpr chrono::month month() const noexcept { return __m; }
inline constexpr chrono::weekday_indexed weekday_indexed() const noexcept { return __wdi; }
inline constexpr bool ok() const noexcept { return __m.ok() && __wdi.ok(); }
};
inline constexpr
bool operator==(const month_weekday& __lhs, const month_weekday& __rhs) noexcept
{ return __lhs.month() == __rhs.month() && __lhs.weekday_indexed() == __rhs.weekday_indexed(); }
inline constexpr
bool operator!=(const month_weekday& __lhs, const month_weekday& __rhs) noexcept
{ return !(__lhs == __rhs); }
inline constexpr
month_weekday operator/(const month& __lhs, const weekday_indexed& __rhs) noexcept
{ return month_weekday{__lhs, __rhs}; }
inline constexpr
month_weekday operator/(int __lhs, const weekday_indexed& __rhs) noexcept
{ return month_weekday{month(__lhs), __rhs}; }
inline constexpr
month_weekday operator/(const weekday_indexed& __lhs, const month& __rhs) noexcept
{ return month_weekday{__rhs, __lhs}; }
inline constexpr
month_weekday operator/(const weekday_indexed& __lhs, int __rhs) noexcept
{ return month_weekday{month(__rhs), __lhs}; }
class month_weekday_last {
chrono::month __m;
chrono::weekday_last __wdl;
public:
constexpr month_weekday_last(const chrono::month& __mval, const chrono::weekday_last& __wdlval) noexcept
: __m{__mval}, __wdl{__wdlval} {}
inline constexpr chrono::month month() const noexcept { return __m; }
inline constexpr chrono::weekday_last weekday_last() const noexcept { return __wdl; }
inline constexpr bool ok() const noexcept { return __m.ok() && __wdl.ok(); }
};
inline constexpr
bool operator==(const month_weekday_last& __lhs, const month_weekday_last& __rhs) noexcept
{ return __lhs.month() == __rhs.month() && __lhs.weekday_last() == __rhs.weekday_last(); }
inline constexpr
bool operator!=(const month_weekday_last& __lhs, const month_weekday_last& __rhs) noexcept
{ return !(__lhs == __rhs); }
inline constexpr
month_weekday_last operator/(const month& __lhs, const weekday_last& __rhs) noexcept
{ return month_weekday_last{__lhs, __rhs}; }
inline constexpr
month_weekday_last operator/(int __lhs, const weekday_last& __rhs) noexcept
{ return month_weekday_last{month(__lhs), __rhs}; }
inline constexpr
month_weekday_last operator/(const weekday_last& __lhs, const month& __rhs) noexcept
{ return month_weekday_last{__rhs, __lhs}; }
inline constexpr
month_weekday_last operator/(const weekday_last& __lhs, int __rhs) noexcept
{ return month_weekday_last{month(__rhs), __lhs}; }
class year_month {
chrono::year __y;
chrono::month __m;
public:
year_month() = default;
constexpr year_month(const chrono::year& __yval, const chrono::month& __mval) noexcept
: __y{__yval}, __m{__mval} {}
inline constexpr chrono::year year() const noexcept { return __y; }
inline constexpr chrono::month month() const noexcept { return __m; }
inline constexpr year_month& operator+=(const months& __dm) noexcept { this->__m += __dm; return *this; }
inline constexpr year_month& operator-=(const months& __dm) noexcept { this->__m -= __dm; return *this; }
inline constexpr year_month& operator+=(const years& __dy) noexcept { this->__y += __dy; return *this; }
inline constexpr year_month& operator-=(const years& __dy) noexcept { this->__y -= __dy; return *this; }
inline constexpr bool ok() const noexcept { return __y.ok() && __m.ok(); }
};
inline constexpr
year_month operator/(const year& __y, const month& __m) noexcept { return year_month{__y, __m}; }
inline constexpr
year_month operator/(const year& __y, int __m) noexcept { return year_month{__y, month(__m)}; }
inline constexpr
bool operator==(const year_month& __lhs, const year_month& __rhs) noexcept
{ return __lhs.year() == __rhs.year() && __lhs.month() == __rhs.month(); }
inline constexpr
bool operator!=(const year_month& __lhs, const year_month& __rhs) noexcept
{ return !(__lhs == __rhs); }
inline constexpr
bool operator< (const year_month& __lhs, const year_month& __rhs) noexcept
{ return __lhs.year() != __rhs.year() ? __lhs.year() < __rhs.year() : __lhs.month() < __rhs.month(); }
inline constexpr
bool operator> (const year_month& __lhs, const year_month& __rhs) noexcept
{ return __rhs < __lhs; }
inline constexpr
bool operator<=(const year_month& __lhs, const year_month& __rhs) noexcept
{ return !(__rhs < __lhs);}
inline constexpr
bool operator>=(const year_month& __lhs, const year_month& __rhs) noexcept
{ return !(__lhs < __rhs); }
constexpr year_month operator+(const year_month& __lhs, const months& __rhs) noexcept
{
int __dmi = static_cast<int>(static_cast<unsigned>(__lhs.month())) - 1 + __rhs.count();
const int __dy = (__dmi >= 0 ? __dmi : __dmi-11) / 12;
__dmi = __dmi - __dy * 12 + 1;
return (__lhs.year() + years(__dy)) / month(static_cast<unsigned>(__dmi));
}
constexpr year_month operator+(const months& __lhs, const year_month& __rhs) noexcept
{ return __rhs + __lhs; }
constexpr year_month operator+(const year_month& __lhs, const years& __rhs) noexcept
{ return (__lhs.year() + __rhs) / __lhs.month(); }
constexpr year_month operator+(const years& __lhs, const year_month& __rhs) noexcept
{ return __rhs + __lhs; }
constexpr months operator-(const year_month& __lhs, const year_month& __rhs) noexcept
{ return (__lhs.year() - __rhs.year()) + months(static_cast<unsigned>(__lhs.month()) - static_cast<unsigned>(__rhs.month())); }
constexpr year_month operator-(const year_month& __lhs, const months& __rhs) noexcept
{ return __lhs + -__rhs; }
constexpr year_month operator-(const year_month& __lhs, const years& __rhs) noexcept
{ return __lhs + -__rhs; }
class year_month_day_last;
class year_month_day {
private:
chrono::year __y;
chrono::month __m;
chrono::day __d;
public:
year_month_day() = default;
inline constexpr year_month_day(
const chrono::year& __yval, const chrono::month& __mval, const chrono::day& __dval) noexcept
: __y{__yval}, __m{__mval}, __d{__dval} {}
constexpr year_month_day(const year_month_day_last& __ymdl) noexcept;
inline constexpr year_month_day(const sys_days& __sysd) noexcept
: year_month_day(__from_days(__sysd.time_since_epoch())) {}
inline explicit constexpr year_month_day(const local_days& __locd) noexcept
: year_month_day(__from_days(__locd.time_since_epoch())) {}
constexpr year_month_day& operator+=(const months& __dm) noexcept;
constexpr year_month_day& operator-=(const months& __dm) noexcept;
constexpr year_month_day& operator+=(const years& __dy) noexcept;
constexpr year_month_day& operator-=(const years& __dy) noexcept;
inline constexpr chrono::year year() const noexcept { return __y; }
inline constexpr chrono::month month() const noexcept { return __m; }
inline constexpr chrono::day day() const noexcept { return __d; }
inline constexpr operator sys_days() const noexcept { return sys_days{__to_days()}; }
inline explicit constexpr operator local_days() const noexcept { return local_days{__to_days()}; }
constexpr bool ok() const noexcept;
static constexpr year_month_day __from_days(days __d) noexcept;
constexpr days __to_days() const noexcept;
};
// https://howardhinnant.github.io/date_algorithms.html#civil_from_days
inline constexpr
year_month_day
year_month_day::__from_days(days __d) noexcept
{
static_assert(std::numeric_limits<unsigned>::digits >= 18, "");
static_assert(std::numeric_limits<int>::digits >= 20 , "");
const int __z = __d.count() + 719468;
const int __era = (__z >= 0 ? __z : __z - 146096) / 146097;
const unsigned __doe = static_cast<unsigned>(__z - __era * 146097); // [0, 146096]
const unsigned __yoe = (__doe - __doe/1460 + __doe/36524 - __doe/146096) / 365; // [0, 399]
const int __yr = static_cast<int>(__yoe) + __era * 400;
const unsigned __doy = __doe - (365 * __yoe + __yoe/4 - __yoe/100); // [0, 365]
const unsigned __mp = (5 * __doy + 2)/153; // [0, 11]
const unsigned __dy = __doy - (153 * __mp + 2)/5 + 1; // [1, 31]
const unsigned __mth = __mp + (__mp < 10 ? 3 : -9); // [1, 12]
return year_month_day{chrono::year{__yr + (__mth <= 2)}, chrono::month{__mth}, chrono::day{__dy}};
}
// https://howardhinnant.github.io/date_algorithms.html#days_from_civil
inline constexpr days year_month_day::__to_days() const noexcept
{
static_assert(std::numeric_limits<unsigned>::digits >= 18, "");
static_assert(std::numeric_limits<int>::digits >= 20 , "");
const int __yr = static_cast<int>(__y) - (__m <= February);
const unsigned __mth = static_cast<unsigned>(__m);
const unsigned __dy = static_cast<unsigned>(__d);
const int __era = (__yr >= 0 ? __yr : __yr - 399) / 400;
const unsigned __yoe = static_cast<unsigned>(__yr - __era * 400); // [0, 399]
const unsigned __doy = (153 * (__mth + (__mth > 2 ? -3 : 9)) + 2) / 5 + __dy-1; // [0, 365]
const unsigned __doe = __yoe * 365 + __yoe/4 - __yoe/100 + __doy; // [0, 146096]
return days{__era * 146097 + static_cast<int>(__doe) - 719468};
}
inline constexpr
bool operator==(const year_month_day& __lhs, const year_month_day& __rhs) noexcept
{ return __lhs.year() == __rhs.year() && __lhs.month() == __rhs.month() && __lhs.day() == __rhs.day(); }
inline constexpr
bool operator!=(const year_month_day& __lhs, const year_month_day& __rhs) noexcept
{ return !(__lhs == __rhs); }
inline constexpr
bool operator< (const year_month_day& __lhs, const year_month_day& __rhs) noexcept
{
if (__lhs.year() < __rhs.year()) return true;
if (__lhs.year() > __rhs.year()) return false;
if (__lhs.month() < __rhs.month()) return true;
if (__lhs.month() > __rhs.month()) return false;
return __lhs.day() < __rhs.day();
}
inline constexpr
bool operator> (const year_month_day& __lhs, const year_month_day& __rhs) noexcept
{ return __rhs < __lhs; }
inline constexpr
bool operator<=(const year_month_day& __lhs, const year_month_day& __rhs) noexcept
{ return !(__rhs < __lhs);}
inline constexpr
bool operator>=(const year_month_day& __lhs, const year_month_day& __rhs) noexcept
{ return !(__lhs < __rhs); }
inline constexpr
year_month_day operator/(const year_month& __lhs, const day& __rhs) noexcept
{ return year_month_day{__lhs.year(), __lhs.month(), __rhs}; }
inline constexpr
year_month_day operator/(const year_month& __lhs, int __rhs) noexcept
{ return __lhs / day(__rhs); }
inline constexpr
year_month_day operator/(const year& __lhs, const month_day& __rhs) noexcept
{ return __lhs / __rhs.month() / __rhs.day(); }
inline constexpr
year_month_day operator/(int __lhs, const month_day& __rhs) noexcept
{ return year(__lhs) / __rhs; }
inline constexpr
year_month_day operator/(const month_day& __lhs, const year& __rhs) noexcept
{ return __rhs / __lhs; }
inline constexpr
year_month_day operator/(const month_day& __lhs, int __rhs) noexcept
{ return year(__rhs) / __lhs; }
inline constexpr
year_month_day operator+(const year_month_day& __lhs, const months& __rhs) noexcept
{ return (__lhs.year()/__lhs.month() + __rhs)/__lhs.day(); }
inline constexpr
year_month_day operator+(const months& __lhs, const year_month_day& __rhs) noexcept
{ return __rhs + __lhs; }
inline constexpr
year_month_day operator-(const year_month_day& __lhs, const months& __rhs) noexcept
{ return __lhs + -__rhs; }
inline constexpr
year_month_day operator+(const year_month_day& __lhs, const years& __rhs) noexcept
{ return (__lhs.year() + __rhs) / __lhs.month() / __lhs.day(); }
inline constexpr
year_month_day operator+(const years& __lhs, const year_month_day& __rhs) noexcept
{ return __rhs + __lhs; }
inline constexpr
year_month_day operator-(const year_month_day& __lhs, const years& __rhs) noexcept
{ return __lhs + -__rhs; }
inline constexpr year_month_day& year_month_day::operator+=(const months& __dm) noexcept { *this = *this + __dm; return *this; }
inline constexpr year_month_day& year_month_day::operator-=(const months& __dm) noexcept { *this = *this - __dm; return *this; }
inline constexpr year_month_day& year_month_day::operator+=(const years& __dy) noexcept { *this = *this + __dy; return *this; }
inline constexpr year_month_day& year_month_day::operator-=(const years& __dy) noexcept { *this = *this - __dy; return *this; }
class year_month_day_last {
private:
chrono::year __y;
chrono::month_day_last __mdl;
public:
constexpr year_month_day_last(const year& __yval, const month_day_last& __mdlval) noexcept
: __y{__yval}, __mdl{__mdlval} {}
constexpr year_month_day_last& operator+=(const months& __m) noexcept;
constexpr year_month_day_last& operator-=(const months& __m) noexcept;
constexpr year_month_day_last& operator+=(const years& __y) noexcept;
constexpr year_month_day_last& operator-=(const years& __y) noexcept;
inline constexpr chrono::year year() const noexcept { return __y; }
inline constexpr chrono::month month() const noexcept { return __mdl.month(); }
inline constexpr chrono::month_day_last month_day_last() const noexcept { return __mdl; }
constexpr chrono::day day() const noexcept;
inline constexpr operator sys_days() const noexcept { return sys_days{year()/month()/day()}; }
inline explicit constexpr operator local_days() const noexcept { return local_days{year()/month()/day()}; }
inline constexpr bool ok() const noexcept { return __y.ok() && __mdl.ok(); }
};
inline constexpr
chrono::day year_month_day_last::day() const noexcept
{
constexpr chrono::day __d[] =
{
chrono::day(31), chrono::day(28), chrono::day(31),
chrono::day(30), chrono::day(31), chrono::day(30),
chrono::day(31), chrono::day(31), chrono::day(30),
chrono::day(31), chrono::day(30), chrono::day(31)
};
return month() != February || !__y.is_leap() ?
__d[static_cast<unsigned>(month()) - 1] : chrono::day{29};
}
inline constexpr
bool operator==(const year_month_day_last& __lhs, const year_month_day_last& __rhs) noexcept
{ return __lhs.year() == __rhs.year() && __lhs.month_day_last() == __rhs.month_day_last(); }
inline constexpr
bool operator!=(const year_month_day_last& __lhs, const year_month_day_last& __rhs) noexcept
{ return !(__lhs == __rhs); }
inline constexpr
bool operator< (const year_month_day_last& __lhs, const year_month_day_last& __rhs) noexcept
{
if (__lhs.year() < __rhs.year()) return true;
if (__lhs.year() > __rhs.year()) return false;
return __lhs.month_day_last() < __rhs.month_day_last();
}
inline constexpr
bool operator> (const year_month_day_last& __lhs, const year_month_day_last& __rhs) noexcept
{ return __rhs < __lhs; }
inline constexpr
bool operator<=(const year_month_day_last& __lhs, const year_month_day_last& __rhs) noexcept
{ return !(__rhs < __lhs);}
inline constexpr
bool operator>=(const year_month_day_last& __lhs, const year_month_day_last& __rhs) noexcept
{ return !(__lhs < __rhs); }
inline constexpr year_month_day_last operator/(const year_month& __lhs, last_spec) noexcept
{ return year_month_day_last{__lhs.year(), month_day_last{__lhs.month()}}; }
inline constexpr year_month_day_last operator/(const year& __lhs, const month_day_last& __rhs) noexcept
{ return year_month_day_last{__lhs, __rhs}; }
inline constexpr year_month_day_last operator/(int __lhs, const month_day_last& __rhs) noexcept
{ return year_month_day_last{year{__lhs}, __rhs}; }
inline constexpr year_month_day_last operator/(const month_day_last& __lhs, const year& __rhs) noexcept
{ return __rhs / __lhs; }
inline constexpr year_month_day_last operator/(const month_day_last& __lhs, int __rhs) noexcept
{ return year{__rhs} / __lhs; }
inline constexpr
year_month_day_last operator+(const year_month_day_last& __lhs, const months& __rhs) noexcept
{ return (__lhs.year() / __lhs.month() + __rhs) / last; }
inline constexpr
year_month_day_last operator+(const months& __lhs, const year_month_day_last& __rhs) noexcept
{ return __rhs + __lhs; }
inline constexpr
year_month_day_last operator-(const year_month_day_last& __lhs, const months& __rhs) noexcept
{ return __lhs + (-__rhs); }
inline constexpr
year_month_day_last operator+(const year_month_day_last& __lhs, const years& __rhs) noexcept
{ return year_month_day_last{__lhs.year() + __rhs, __lhs.month_day_last()}; }
inline constexpr
year_month_day_last operator+(const years& __lhs, const year_month_day_last& __rhs) noexcept
{ return __rhs + __lhs; }
inline constexpr
year_month_day_last operator-(const year_month_day_last& __lhs, const years& __rhs) noexcept
{ return __lhs + (-__rhs); }
inline constexpr year_month_day_last& year_month_day_last::operator+=(const months& __dm) noexcept { *this = *this + __dm; return *this; }
inline constexpr year_month_day_last& year_month_day_last::operator-=(const months& __dm) noexcept { *this = *this - __dm; return *this; }
inline constexpr year_month_day_last& year_month_day_last::operator+=(const years& __dy) noexcept { *this = *this + __dy; return *this; }
inline constexpr year_month_day_last& year_month_day_last::operator-=(const years& __dy) noexcept { *this = *this - __dy; return *this; }
inline constexpr year_month_day::year_month_day(const year_month_day_last& __ymdl) noexcept
: __y{__ymdl.year()}, __m{__ymdl.month()}, __d{__ymdl.day()} {}
inline constexpr bool year_month_day::ok() const noexcept
{
if (!__y.ok() || !__m.ok()) return false;
return chrono::day{1} <= __d && __d <= (__y / __m / last).day();
}
class year_month_weekday {
chrono::year __y;
chrono::month __m;
chrono::weekday_indexed __wdi;
public:
year_month_weekday() = default;
constexpr year_month_weekday(const chrono::year& __yval, const chrono::month& __mval,
const chrono::weekday_indexed& __wdival) noexcept
: __y{__yval}, __m{__mval}, __wdi{__wdival} {}
constexpr year_month_weekday(const sys_days& __sysd) noexcept
: year_month_weekday(__from_days(__sysd.time_since_epoch())) {}
inline explicit constexpr year_month_weekday(const local_days& __locd) noexcept
: year_month_weekday(__from_days(__locd.time_since_epoch())) {}
constexpr year_month_weekday& operator+=(const months& m) noexcept;
constexpr year_month_weekday& operator-=(const months& m) noexcept;
constexpr year_month_weekday& operator+=(const years& y) noexcept;
constexpr year_month_weekday& operator-=(const years& y) noexcept;
inline constexpr chrono::year year() const noexcept { return __y; }
inline constexpr chrono::month month() const noexcept { return __m; }
inline constexpr chrono::weekday weekday() const noexcept { return __wdi.weekday(); }
inline constexpr unsigned index() const noexcept { return __wdi.index(); }
inline constexpr chrono::weekday_indexed weekday_indexed() const noexcept { return __wdi; }
inline constexpr operator sys_days() const noexcept { return sys_days{__to_days()}; }
inline explicit constexpr operator local_days() const noexcept { return local_days{__to_days()}; }
inline constexpr bool ok() const noexcept
{
if (!__y.ok() || !__m.ok() || !__wdi.ok()) return false;
// TODO: make sure it's a valid date
return true;
}
static constexpr year_month_weekday __from_days(days __d) noexcept;
constexpr days __to_days() const noexcept;
};
inline constexpr
year_month_weekday year_month_weekday::__from_days(days __d) noexcept
{
const sys_days __sysd{__d};
const chrono::weekday __wd = chrono::weekday(__sysd);
const year_month_day __ymd = year_month_day(__sysd);
return year_month_weekday{__ymd.year(), __ymd.month(),
__wd[(static_cast<unsigned>(__ymd.day())-1)/7+1]};
}
inline constexpr
days year_month_weekday::__to_days() const noexcept
{
const sys_days __sysd = sys_days(__y/__m/1);
return (__sysd + (__wdi.weekday() - chrono::weekday(__sysd) + days{(__wdi.index()-1)*7}))
.time_since_epoch();
}
inline constexpr
bool operator==(const year_month_weekday& __lhs, const year_month_weekday& __rhs) noexcept
{ return __lhs.year() == __rhs.year() && __lhs.month() == __rhs.month() && __lhs.weekday_indexed() == __rhs.weekday_indexed(); }
inline constexpr
bool operator!=(const year_month_weekday& __lhs, const year_month_weekday& __rhs) noexcept
{ return !(__lhs == __rhs); }
inline constexpr
year_month_weekday operator/(const year_month& __lhs, const weekday_indexed& __rhs) noexcept
{ return year_month_weekday{__lhs.year(), __lhs.month(), __rhs}; }
inline constexpr
year_month_weekday operator/(const year& __lhs, const month_weekday& __rhs) noexcept
{ return year_month_weekday{__lhs, __rhs.month(), __rhs.weekday_indexed()}; }
inline constexpr
year_month_weekday operator/(int __lhs, const month_weekday& __rhs) noexcept
{ return year(__lhs) / __rhs; }
inline constexpr
year_month_weekday operator/(const month_weekday& __lhs, const year& __rhs) noexcept
{ return __rhs / __lhs; }
inline constexpr
year_month_weekday operator/(const month_weekday& __lhs, int __rhs) noexcept
{ return year(__rhs) / __lhs; }
inline constexpr
year_month_weekday operator+(const year_month_weekday& __lhs, const months& __rhs) noexcept
{ return (__lhs.year() / __lhs.month() + __rhs) / __lhs.weekday_indexed(); }
inline constexpr
year_month_weekday operator+(const months& __lhs, const year_month_weekday& __rhs) noexcept
{ return __rhs + __lhs; }
inline constexpr
year_month_weekday operator-(const year_month_weekday& __lhs, const months& __rhs) noexcept
{ return __lhs + (-__rhs); }
inline constexpr
year_month_weekday operator+(const year_month_weekday& __lhs, const years& __rhs) noexcept
{ return year_month_weekday{__lhs.year() + __rhs, __lhs.month(), __lhs.weekday_indexed()}; }
inline constexpr
year_month_weekday operator+(const years& __lhs, const year_month_weekday& __rhs) noexcept
{ return __rhs + __lhs; }
inline constexpr
year_month_weekday operator-(const year_month_weekday& __lhs, const years& __rhs) noexcept
{ return __lhs + (-__rhs); }
inline constexpr year_month_weekday& year_month_weekday::operator+=(const months& __dm) noexcept { *this = *this + __dm; return *this; }
inline constexpr year_month_weekday& year_month_weekday::operator-=(const months& __dm) noexcept { *this = *this - __dm; return *this; }
inline constexpr year_month_weekday& year_month_weekday::operator+=(const years& __dy) noexcept { *this = *this + __dy; return *this; }
inline constexpr year_month_weekday& year_month_weekday::operator-=(const years& __dy) noexcept { *this = *this - __dy; return *this; }
class year_month_weekday_last {
private:
chrono::year __y;
chrono::month __m;
chrono::weekday_last __wdl;
public:
constexpr year_month_weekday_last(const chrono::year& __yval, const chrono::month& __mval,
const chrono::weekday_last& __wdlval) noexcept
: __y{__yval}, __m{__mval}, __wdl{__wdlval} {}
constexpr year_month_weekday_last& operator+=(const months& __dm) noexcept;
constexpr year_month_weekday_last& operator-=(const months& __dm) noexcept;
constexpr year_month_weekday_last& operator+=(const years& __dy) noexcept;
constexpr year_month_weekday_last& operator-=(const years& __dy) noexcept;
inline constexpr chrono::year year() const noexcept { return __y; }
inline constexpr chrono::month month() const noexcept { return __m; }
inline constexpr chrono::weekday weekday() const noexcept { return __wdl.weekday(); }
inline constexpr chrono::weekday_last weekday_last() const noexcept { return __wdl; }
inline constexpr operator sys_days() const noexcept { return sys_days{__to_days()}; }
inline explicit constexpr operator local_days() const noexcept { return local_days{__to_days()}; }
inline constexpr bool ok() const noexcept { return __y.ok() && __m.ok() && __wdl.ok(); }
constexpr days __to_days() const noexcept;
};
inline constexpr
days year_month_weekday_last::__to_days() const noexcept
{
const sys_days __last = sys_days{__y/__m/last};
return (__last - (chrono::weekday{__last} - __wdl.weekday())).time_since_epoch();
}
inline constexpr
bool operator==(const year_month_weekday_last& __lhs, const year_month_weekday_last& __rhs) noexcept
{ return __lhs.year() == __rhs.year() && __lhs.month() == __rhs.month() && __lhs.weekday_last() == __rhs.weekday_last(); }
inline constexpr
bool operator!=(const year_month_weekday_last& __lhs, const year_month_weekday_last& __rhs) noexcept
{ return !(__lhs == __rhs); }
inline constexpr
year_month_weekday_last operator/(const year_month& __lhs, const weekday_last& __rhs) noexcept
{ return year_month_weekday_last{__lhs.year(), __lhs.month(), __rhs}; }
inline constexpr
year_month_weekday_last operator/(const year& __lhs, const month_weekday_last& __rhs) noexcept
{ return year_month_weekday_last{__lhs, __rhs.month(), __rhs.weekday_last()}; }
inline constexpr
year_month_weekday_last operator/(int __lhs, const month_weekday_last& __rhs) noexcept
{ return year(__lhs) / __rhs; }
inline constexpr
year_month_weekday_last operator/(const month_weekday_last& __lhs, const year& __rhs) noexcept
{ return __rhs / __lhs; }
inline constexpr
year_month_weekday_last operator/(const month_weekday_last& __lhs, int __rhs) noexcept
{ return year(__rhs) / __lhs; }
inline constexpr
year_month_weekday_last operator+(const year_month_weekday_last& __lhs, const months& __rhs) noexcept
{ return (__lhs.year() / __lhs.month() + __rhs) / __lhs.weekday_last(); }
inline constexpr
year_month_weekday_last operator+(const months& __lhs, const year_month_weekday_last& __rhs) noexcept
{ return __rhs + __lhs; }
inline constexpr
year_month_weekday_last operator-(const year_month_weekday_last& __lhs, const months& __rhs) noexcept
{ return __lhs + (-__rhs); }
inline constexpr
year_month_weekday_last operator+(const year_month_weekday_last& __lhs, const years& __rhs) noexcept
{ return year_month_weekday_last{__lhs.year() + __rhs, __lhs.month(), __lhs.weekday_last()}; }
inline constexpr
year_month_weekday_last operator+(const years& __lhs, const year_month_weekday_last& __rhs) noexcept
{ return __rhs + __lhs; }
inline constexpr
year_month_weekday_last operator-(const year_month_weekday_last& __lhs, const years& __rhs) noexcept
{ return __lhs + (-__rhs); }
inline constexpr year_month_weekday_last& year_month_weekday_last::operator+=(const months& __dm) noexcept { *this = *this + __dm; return *this; }
inline constexpr year_month_weekday_last& year_month_weekday_last::operator-=(const months& __dm) noexcept { *this = *this - __dm; return *this; }
inline constexpr year_month_weekday_last& year_month_weekday_last::operator+=(const years& __dy) noexcept { *this = *this + __dy; return *this; }
inline constexpr year_month_weekday_last& year_month_weekday_last::operator-=(const years& __dy) noexcept { *this = *this - __dy; return *this; }
template <class _Duration>
class hh_mm_ss
{
private:
static_assert(__is_duration<_Duration>::value, "template parameter of hh_mm_ss must be a std::chrono::duration");
using __CommonType = common_type_t<_Duration, chrono::seconds>;
static constexpr uint64_t __pow10(unsigned __exp)
{
uint64_t __ret = 1;
for (unsigned __i = 0; __i < __exp; ++__i)
__ret *= 10U;
return __ret;
}
static constexpr unsigned __width(uint64_t __n, uint64_t __d = 10, unsigned __w = 0)
{
if (__n >= 2 && __d != 0 && __w < 19)
return 1 + __width(__n, __d % __n * 10, __w+1);
return 0;
}
public:
static unsigned constexpr fractional_width = __width(__CommonType::period::den) < 19 ?
__width(__CommonType::period::den) : 6u;
using precision = duration<typename __CommonType::rep, ratio<1, __pow10(fractional_width)>>;
constexpr hh_mm_ss() noexcept : hh_mm_ss{_Duration::zero()} {}
constexpr explicit hh_mm_ss(_Duration __d) noexcept :
__is_neg(__d < _Duration(0)),
__h(duration_cast<chrono::hours> (abs(__d))),
__m(duration_cast<chrono::minutes>(abs(__d) - hours())),
__s(duration_cast<chrono::seconds>(abs(__d) - hours() - minutes())),
__f(duration_cast<precision> (abs(__d) - hours() - minutes() - seconds()))
{}
constexpr bool is_negative() const noexcept { return __is_neg; }
constexpr chrono::hours hours() const noexcept { return __h; }
constexpr chrono::minutes minutes() const noexcept { return __m; }
constexpr chrono::seconds seconds() const noexcept { return __s; }
constexpr precision subseconds() const noexcept { return __f; }
constexpr precision to_duration() const noexcept
{
auto __dur = __h + __m + __s + __f;
return __is_neg ? -__dur : __dur;
}
constexpr explicit operator precision() const noexcept { return to_duration(); }
private:
bool __is_neg;
chrono::hours __h;
chrono::minutes __m;
chrono::seconds __s;
precision __f;
};
constexpr bool is_am(const hours& __h) noexcept { return __h >= hours( 0) && __h < hours(12); }
constexpr bool is_pm(const hours& __h) noexcept { return __h >= hours(12) && __h < hours(24); }
constexpr hours make12(const hours& __h) noexcept
{
if (__h == hours( 0)) return hours(12);
else if (__h <= hours(12)) return __h;
else return __h - hours(12);
}
constexpr hours make24(const hours& __h, bool __is_pm) noexcept
{
if (__is_pm)
return __h == hours(12) ? __h : __h + hours(12);
else
return __h == hours(12) ? hours(0) : __h;
}
#endif // _LIBCPP_STD_VER > 17
} // chrono
#if _LIBCPP_STD_VER > 11
// Suffixes for duration literals [time.duration.literals]
inline namespace literals
{
inline namespace chrono_literals
{
constexpr chrono::hours operator""h(unsigned long long __h)
{
return chrono::hours(static_cast<chrono::hours::rep>(__h));
}
constexpr chrono::duration<long double, ratio<3600,1>> operator""h(long double __h)
{
return chrono::duration<long double, ratio<3600,1>>(__h);
}
constexpr chrono::minutes operator""min(unsigned long long __m)
{
return chrono::minutes(static_cast<chrono::minutes::rep>(__m));
}
constexpr chrono::duration<long double, ratio<60,1>> operator""min(long double __m)
{
return chrono::duration<long double, ratio<60,1>> (__m);
}
constexpr chrono::seconds operator""s(unsigned long long __s)
{
return chrono::seconds(static_cast<chrono::seconds::rep>(__s));
}
constexpr chrono::duration<long double> operator""s(long double __s)
{
return chrono::duration<long double> (__s);
}
constexpr chrono::milliseconds operator""ms(unsigned long long __ms)
{
return chrono::milliseconds(static_cast<chrono::milliseconds::rep>(__ms));
}
constexpr chrono::duration<long double, milli> operator""ms(long double __ms)
{
return chrono::duration<long double, milli>(__ms);
}
constexpr chrono::microseconds operator""us(unsigned long long __us)
{
return chrono::microseconds(static_cast<chrono::microseconds::rep>(__us));
}
constexpr chrono::duration<long double, micro> operator""us(long double __us)
{
return chrono::duration<long double, micro> (__us);
}
constexpr chrono::nanoseconds operator""ns(unsigned long long __ns)
{
return chrono::nanoseconds(static_cast<chrono::nanoseconds::rep>(__ns));
}
constexpr chrono::duration<long double, nano> operator""ns(long double __ns)
{
return chrono::duration<long double, nano> (__ns);
}
#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_CXX20_CHRONO_LITERALS)
constexpr chrono::day operator ""d(unsigned long long __d) noexcept
{
return chrono::day(static_cast<unsigned>(__d));
}
constexpr chrono::year operator ""y(unsigned long long __y) noexcept
{
return chrono::year(static_cast<int>(__y));
}
#endif
}}
namespace chrono { // hoist the literals into namespace std::chrono
using namespace literals::chrono_literals;
}
#endif
_LIBCPP_END_NAMESPACE_STD
#ifndef _LIBCPP_CXX03_LANG
_LIBCPP_BEGIN_NAMESPACE_FILESYSTEM
struct _FilesystemClock {
#if !defined(_LIBCPP_HAS_NO_INT128)
typedef __int128_t rep;
typedef nano period;
#else
typedef long long rep;
typedef nano period;
#endif
typedef chrono::duration<rep, period> duration;
typedef chrono::time_point<_FilesystemClock> time_point;
_LIBCPP_EXPORTED_FROM_ABI
static _LIBCPP_CONSTEXPR_AFTER_CXX11 const bool is_steady = false;
_LIBCPP_AVAILABILITY_FILESYSTEM _LIBCPP_FUNC_VIS static time_point now() noexcept;
_LIBCPP_INLINE_VISIBILITY
static time_t to_time_t(const time_point& __t) noexcept {
typedef chrono::duration<rep> __secs;
return time_t(
chrono::duration_cast<__secs>(__t.time_since_epoch()).count());
}
_LIBCPP_INLINE_VISIBILITY
static time_point from_time_t(time_t __t) noexcept {
typedef chrono::duration<rep> __secs;
return time_point(__secs(__t));
}
};
_LIBCPP_END_NAMESPACE_FILESYSTEM
#endif // !_LIBCPP_CXX03_LANG
_LIBCPP_POP_MACROS
#endif // _LIBCPP_CHRONO
| 116,116 | 2,961 | jart/cosmopolitan | false |
cosmopolitan/third_party/libcxx/__bsd_locale_fallbacks.h | // -*- C++ -*-
//===---------------------- __bsd_locale_fallbacks.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
//
//===----------------------------------------------------------------------===//
// The BSDs have lots of *_l functions. This file provides reimplementations
// of those functions for non-BSD platforms.
//===----------------------------------------------------------------------===//
#ifndef _LIBCPP_BSD_LOCALE_FALLBACKS_DEFAULTS_H
#define _LIBCPP_BSD_LOCALE_FALLBACKS_DEFAULTS_H
#include "third_party/libcxx/stdlib.h"
#include "libc/mem/fmt.h"
#include "libc/str/unicode.h"
#include "libc/fmt/fmt.h"
#include "libc/str/locale.h"
#include "third_party/libcxx/memory"
#include "third_party/libcxx/__locale"
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
#pragma GCC system_header
#endif
_LIBCPP_BEGIN_NAMESPACE_STD
inline _LIBCPP_INLINE_VISIBILITY decltype(MB_CUR_MAX)
__libcpp_mb_cur_max_l(locale_t __l) {
__libcpp_locale_guard __current(__l);
return MB_CUR_MAX;
}
inline _LIBCPP_INLINE_VISIBILITY wint_t __libcpp_btowc_l(int __c,
locale_t __l) {
__libcpp_locale_guard __current(__l);
return btowc(__c);
}
inline _LIBCPP_INLINE_VISIBILITY int __libcpp_wctob_l(wint_t __c,
locale_t __l) {
__libcpp_locale_guard __current(__l);
return wctob(__c);
}
inline _LIBCPP_INLINE_VISIBILITY size_t
__libcpp_wcsnrtombs_l(char* __dest, const wchar_t** __src, size_t __nwc,
size_t __len, mbstate_t* __ps, locale_t __l) {
__libcpp_locale_guard __current(__l);
return wcsnrtombs(__dest, __src, __nwc, __len, __ps);
}
inline _LIBCPP_INLINE_VISIBILITY size_t __libcpp_wcrtomb_l(char* __s,
wchar_t __wc,
mbstate_t* __ps,
locale_t __l) {
__libcpp_locale_guard __current(__l);
return wcrtomb(__s, __wc, __ps);
}
inline _LIBCPP_INLINE_VISIBILITY size_t
__libcpp_mbsnrtowcs_l(wchar_t* __dest, const char** __src, size_t __nms,
size_t __len, mbstate_t* __ps, locale_t __l) {
__libcpp_locale_guard __current(__l);
return mbsnrtowcs(__dest, __src, __nms, __len, __ps);
}
inline _LIBCPP_INLINE_VISIBILITY size_t __libcpp_mbrtowc_l(wchar_t* __pwc,
const char* __s,
size_t __n,
mbstate_t* __ps,
locale_t __l) {
__libcpp_locale_guard __current(__l);
return mbrtowc(__pwc, __s, __n, __ps);
}
inline _LIBCPP_INLINE_VISIBILITY int __libcpp_mbtowc_l(wchar_t* __pwc,
const char* __pmb,
size_t __max,
locale_t __l) {
__libcpp_locale_guard __current(__l);
return mbtowc(__pwc, __pmb, __max);
}
inline _LIBCPP_INLINE_VISIBILITY size_t __libcpp_mbrlen_l(const char* __s,
size_t __n,
mbstate_t* __ps,
locale_t __l) {
__libcpp_locale_guard __current(__l);
return mbrlen(__s, __n, __ps);
}
inline _LIBCPP_INLINE_VISIBILITY lconv* __libcpp_localeconv_l(locale_t __l) {
__libcpp_locale_guard __current(__l);
return localeconv();
}
inline _LIBCPP_INLINE_VISIBILITY size_t __libcpp_mbsrtowcs_l(wchar_t* __dest,
const char** __src,
size_t __len,
mbstate_t* __ps,
locale_t __l) {
__libcpp_locale_guard __current(__l);
return mbsrtowcs(__dest, __src, __len, __ps);
}
inline int __libcpp_snprintf_l(char* __s, size_t __n, locale_t __l,
const char* __format, ...) {
va_list __va;
va_start(__va, __format);
__libcpp_locale_guard __current(__l);
int __res = vsnprintf(__s, __n, __format, __va);
va_end(__va);
return __res;
}
inline int __libcpp_asprintf_l(char** __s, locale_t __l, const char* __format,
...) {
va_list __va;
va_start(__va, __format);
__libcpp_locale_guard __current(__l);
int __res = vasprintf(__s, __format, __va);
va_end(__va);
return __res;
}
inline int __libcpp_sscanf_l(const char* __s, locale_t __l,
const char* __format, ...) {
va_list __va;
va_start(__va, __format);
__libcpp_locale_guard __current(__l);
int __res = vsscanf(__s, __format, __va);
va_end(__va);
return __res;
}
_LIBCPP_END_NAMESPACE_STD
#endif // _LIBCPP_BSD_LOCALE_FALLBACKS_DEFAULTS_H
| 5,278 | 142 | jart/cosmopolitan | false |
cosmopolitan/third_party/libcxx/limits.h | // -*- C++ -*-
//===--------------------------- limits.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_LIMITS_H
#define _LIBCPP_LIMITS_H
/*
limits.h 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"
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
#pragma GCC system_header
#endif
#ifndef __GNUC__
#include "libc/limits.h"
#else
// GCC header limits.h recursively includes itself through another header called
// syslimits.h for some reason. This setup breaks down if we directly
// #include_next GCC's limits.h (reasons not entirely clear to me). Therefore,
// we manually re-create the necessary include sequence below:
// Get the system limits.h defines (force recurse into the next level)
#define _GCC_LIMITS_H_
#define _GCC_NEXT_LIMITS_H
#include "libc/limits.h"
// Get the ISO C defines
#undef _GCC_LIMITS_H_
#include "libc/limits.h"
#endif // __GNUC__
#endif // _LIBCPP_LIMITS_H
| 1,490 | 65 | jart/cosmopolitan | false |
cosmopolitan/third_party/libcxx/optional | // -*- C++ -*-
//===-------------------------- optional ----------------------------------===//
//
// 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_OPTIONAL
#define _LIBCPP_OPTIONAL
#include "third_party/libcxx/__config"
#include "third_party/libcxx/__debug"
#include "third_party/libcxx/__functional_base"
#include "third_party/libcxx/functional"
#include "third_party/libcxx/initializer_list"
#include "third_party/libcxx/new"
#include "third_party/libcxx/stdexcept"
#include "third_party/libcxx/type_traits"
#include "third_party/libcxx/utility"
#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"
/*
optional synopsis
// C++1z
namespace std {
// 23.6.3, optional for object types
template <class T> class optional;
// 23.6.4, no-value state indicator
struct nullopt_t{see below };
inline constexpr nullopt_t nullopt(unspecified );
// 23.6.5, class bad_optional_access
class bad_optional_access;
// 23.6.6, relational operators
template <class T, class U>
constexpr bool operator==(const optional<T>&, const optional<U>&);
template <class T, class U>
constexpr bool operator!=(const optional<T>&, const optional<U>&);
template <class T, class U>
constexpr bool operator<(const optional<T>&, const optional<U>&);
template <class T, class U>
constexpr bool operator>(const optional<T>&, const optional<U>&);
template <class T, class U>
constexpr bool operator<=(const optional<T>&, const optional<U>&);
template <class T, class U>
constexpr bool operator>=(const optional<T>&, const optional<U>&);
// 23.6.7 comparison with nullopt
template <class T> constexpr bool operator==(const optional<T>&, nullopt_t) noexcept;
template <class T> constexpr bool operator==(nullopt_t, const optional<T>&) noexcept;
template <class T> constexpr bool operator!=(const optional<T>&, nullopt_t) noexcept;
template <class T> constexpr bool operator!=(nullopt_t, const optional<T>&) noexcept;
template <class T> constexpr bool operator<(const optional<T>&, nullopt_t) noexcept;
template <class T> constexpr bool operator<(nullopt_t, const optional<T>&) noexcept;
template <class T> constexpr bool operator<=(const optional<T>&, nullopt_t) noexcept;
template <class T> constexpr bool operator<=(nullopt_t, const optional<T>&) noexcept;
template <class T> constexpr bool operator>(const optional<T>&, nullopt_t) noexcept;
template <class T> constexpr bool operator>(nullopt_t, const optional<T>&) noexcept;
template <class T> constexpr bool operator>=(const optional<T>&, nullopt_t) noexcept;
template <class T> constexpr bool operator>=(nullopt_t, const optional<T>&) noexcept;
// 23.6.8, comparison with T
template <class T, class U> constexpr bool operator==(const optional<T>&, const U&);
template <class T, class U> constexpr bool operator==(const T&, const optional<U>&);
template <class T, class U> constexpr bool operator!=(const optional<T>&, const U&);
template <class T, class U> constexpr bool operator!=(const T&, const optional<U>&);
template <class T, class U> constexpr bool operator<(const optional<T>&, const U&);
template <class T, class U> constexpr bool operator<(const T&, const optional<U>&);
template <class T, class U> constexpr bool operator<=(const optional<T>&, const U&);
template <class T, class U> constexpr bool operator<=(const T&, const optional<U>&);
template <class T, class U> constexpr bool operator>(const optional<T>&, const U&);
template <class T, class U> constexpr bool operator>(const T&, const optional<U>&);
template <class T, class U> constexpr bool operator>=(const optional<T>&, const U&);
template <class T, class U> constexpr bool operator>=(const T&, const optional<U>&);
// 23.6.9, specialized algorithms
template <class T> void swap(optional<T>&, optional<T>&) noexcept(see below );
template <class T> constexpr optional<see below > make_optional(T&&);
template <class T, class... Args>
constexpr optional<T> make_optional(Args&&... args);
template <class T, class U, class... Args>
constexpr optional<T> make_optional(initializer_list<U> il, Args&&... args);
// 23.6.10, hash support
template <class T> struct hash;
template <class T> struct hash<optional<T>>;
template <class T> class optional {
public:
using value_type = T;
// 23.6.3.1, constructors
constexpr optional() noexcept;
constexpr optional(nullopt_t) noexcept;
optional(const optional &);
optional(optional &&) noexcept(see below);
template <class... Args> constexpr explicit optional(in_place_t, Args &&...);
template <class U, class... Args>
constexpr explicit optional(in_place_t, initializer_list<U>, Args &&...);
template <class U = T>
constexpr EXPLICIT optional(U &&);
template <class U>
constexpr EXPLICIT optional(const optional<U> &);
template <class U>
constexpr EXPLICIT optional(optional<U> &&);
// 23.6.3.2, destructor
~optional();
// 23.6.3.3, assignment
optional &operator=(nullopt_t) noexcept;
optional &operator=(const optional &); // constexpr in C++20
optional &operator=(optional &&) noexcept(see below); // constexpr in C++20
template <class U = T> optional &operator=(U &&);
template <class U> optional &operator=(const optional<U> &);
template <class U> optional &operator=(optional<U> &&);
template <class... Args> T& emplace(Args &&...);
template <class U, class... Args>
T& emplace(initializer_list<U>, Args &&...);
// 23.6.3.4, swap
void swap(optional &) noexcept(see below );
// 23.6.3.5, observers
constexpr T const *operator->() const;
constexpr T *operator->();
constexpr T const &operator*() const &;
constexpr T &operator*() &;
constexpr T &&operator*() &&;
constexpr const T &&operator*() const &&;
constexpr explicit operator bool() const noexcept;
constexpr bool has_value() const noexcept;
constexpr T const &value() const &;
constexpr T &value() &;
constexpr T &&value() &&;
constexpr const T &&value() const &&;
template <class U> constexpr T value_or(U &&) const &;
template <class U> constexpr T value_or(U &&) &&;
// 23.6.3.6, modifiers
void reset() noexcept;
private:
T *val; // exposition only
};
template<class T>
optional(T) -> optional<T>;
} // namespace std
*/
namespace std // purposefully not using versioning namespace
{
class _LIBCPP_EXCEPTION_ABI _LIBCPP_AVAILABILITY_BAD_OPTIONAL_ACCESS bad_optional_access
: public exception
{
public:
// Get the key function ~bad_optional_access() into the dylib
virtual ~bad_optional_access() _NOEXCEPT;
virtual const char* what() const _NOEXCEPT;
};
} // std
#if _LIBCPP_STD_VER > 14
_LIBCPP_BEGIN_NAMESPACE_STD
_LIBCPP_NORETURN
inline _LIBCPP_INLINE_VISIBILITY
_LIBCPP_AVAILABILITY_THROW_BAD_OPTIONAL_ACCESS
void __throw_bad_optional_access() {
#ifndef _LIBCPP_NO_EXCEPTIONS
throw bad_optional_access();
#else
_VSTD::abort();
#endif
}
struct nullopt_t
{
struct __secret_tag { _LIBCPP_INLINE_VISIBILITY explicit __secret_tag() = default; };
_LIBCPP_INLINE_VISIBILITY constexpr explicit nullopt_t(__secret_tag, __secret_tag) noexcept {}
};
_LIBCPP_INLINE_VAR constexpr nullopt_t nullopt{nullopt_t::__secret_tag{}, nullopt_t::__secret_tag{}};
template <class _Tp, bool = is_trivially_destructible<_Tp>::value>
struct __optional_destruct_base;
template <class _Tp>
struct __optional_destruct_base<_Tp, false>
{
typedef _Tp value_type;
static_assert(is_object_v<value_type>,
"instantiation of optional with a non-object type is undefined behavior");
union
{
char __null_state_;
value_type __val_;
};
bool __engaged_;
_LIBCPP_INLINE_VISIBILITY
~__optional_destruct_base()
{
if (__engaged_)
__val_.~value_type();
}
_LIBCPP_INLINE_VISIBILITY
constexpr __optional_destruct_base() noexcept
: __null_state_(),
__engaged_(false) {}
template <class... _Args>
_LIBCPP_INLINE_VISIBILITY
constexpr explicit __optional_destruct_base(in_place_t, _Args&&... __args)
: __val_(_VSTD::forward<_Args>(__args)...),
__engaged_(true) {}
_LIBCPP_INLINE_VISIBILITY
void reset() noexcept
{
if (__engaged_)
{
__val_.~value_type();
__engaged_ = false;
}
}
};
template <class _Tp>
struct __optional_destruct_base<_Tp, true>
{
typedef _Tp value_type;
static_assert(is_object_v<value_type>,
"instantiation of optional with a non-object type is undefined behavior");
union
{
char __null_state_;
value_type __val_;
};
bool __engaged_;
_LIBCPP_INLINE_VISIBILITY
constexpr __optional_destruct_base() noexcept
: __null_state_(),
__engaged_(false) {}
template <class... _Args>
_LIBCPP_INLINE_VISIBILITY
constexpr explicit __optional_destruct_base(in_place_t, _Args&&... __args)
: __val_(_VSTD::forward<_Args>(__args)...),
__engaged_(true) {}
_LIBCPP_INLINE_VISIBILITY
void reset() noexcept
{
if (__engaged_)
{
__engaged_ = false;
}
}
};
template <class _Tp, bool = is_reference<_Tp>::value>
struct __optional_storage_base : __optional_destruct_base<_Tp>
{
using __base = __optional_destruct_base<_Tp>;
using value_type = _Tp;
using __base::__base;
_LIBCPP_INLINE_VISIBILITY
constexpr bool has_value() const noexcept
{
return this->__engaged_;
}
_LIBCPP_INLINE_VISIBILITY
constexpr value_type& __get() & noexcept
{
return this->__val_;
}
_LIBCPP_INLINE_VISIBILITY
constexpr const value_type& __get() const& noexcept
{
return this->__val_;
}
_LIBCPP_INLINE_VISIBILITY
constexpr value_type&& __get() && noexcept
{
return _VSTD::move(this->__val_);
}
_LIBCPP_INLINE_VISIBILITY
constexpr const value_type&& __get() const&& noexcept
{
return _VSTD::move(this->__val_);
}
template <class... _Args>
_LIBCPP_INLINE_VISIBILITY
void __construct(_Args&&... __args)
{
_LIBCPP_ASSERT(!has_value(), "__construct called for engaged __optional_storage");
::new((void*)_VSTD::addressof(this->__val_)) value_type(_VSTD::forward<_Args>(__args)...);
this->__engaged_ = true;
}
template <class _That>
_LIBCPP_INLINE_VISIBILITY
void __construct_from(_That&& __opt)
{
if (__opt.has_value())
__construct(_VSTD::forward<_That>(__opt).__get());
}
template <class _That>
_LIBCPP_INLINE_VISIBILITY
void __assign_from(_That&& __opt)
{
if (this->__engaged_ == __opt.has_value())
{
if (this->__engaged_)
this->__val_ = _VSTD::forward<_That>(__opt).__get();
}
else
{
if (this->__engaged_)
this->reset();
else
__construct(_VSTD::forward<_That>(__opt).__get());
}
}
};
// optional<T&> is currently required ill-formed, however it may to be in the
// future. For this reason it has already been implemented to ensure we can
// make the change in an ABI compatible manner.
template <class _Tp>
struct __optional_storage_base<_Tp, true>
{
using value_type = _Tp;
using __raw_type = remove_reference_t<_Tp>;
__raw_type* __value_;
template <class _Up>
static constexpr bool __can_bind_reference() {
using _RawUp = typename remove_reference<_Up>::type;
using _UpPtr = _RawUp*;
using _RawTp = typename remove_reference<_Tp>::type;
using _TpPtr = _RawTp*;
using _CheckLValueArg = integral_constant<bool,
(is_lvalue_reference<_Up>::value && is_convertible<_UpPtr, _TpPtr>::value)
|| is_same<_RawUp, reference_wrapper<_RawTp>>::value
|| is_same<_RawUp, reference_wrapper<typename remove_const<_RawTp>::type>>::value
>;
return (is_lvalue_reference<_Tp>::value && _CheckLValueArg::value)
|| (is_rvalue_reference<_Tp>::value && !is_lvalue_reference<_Up>::value &&
is_convertible<_UpPtr, _TpPtr>::value);
}
_LIBCPP_INLINE_VISIBILITY
constexpr __optional_storage_base() noexcept
: __value_(nullptr) {}
template <class _UArg>
_LIBCPP_INLINE_VISIBILITY
constexpr explicit __optional_storage_base(in_place_t, _UArg&& __uarg)
: __value_(_VSTD::addressof(__uarg))
{
static_assert(__can_bind_reference<_UArg>(),
"Attempted to construct a reference element in tuple from a "
"possible temporary");
}
_LIBCPP_INLINE_VISIBILITY
void reset() noexcept { __value_ = nullptr; }
_LIBCPP_INLINE_VISIBILITY
constexpr bool has_value() const noexcept
{ return __value_ != nullptr; }
_LIBCPP_INLINE_VISIBILITY
constexpr value_type& __get() const& noexcept
{ return *__value_; }
_LIBCPP_INLINE_VISIBILITY
constexpr value_type&& __get() const&& noexcept
{ return _VSTD::forward<value_type>(*__value_); }
template <class _UArg>
_LIBCPP_INLINE_VISIBILITY
void __construct(_UArg&& __val)
{
_LIBCPP_ASSERT(!has_value(), "__construct called for engaged __optional_storage");
static_assert(__can_bind_reference<_UArg>(),
"Attempted to construct a reference element in tuple from a "
"possible temporary");
__value_ = _VSTD::addressof(__val);
}
template <class _That>
_LIBCPP_INLINE_VISIBILITY
void __construct_from(_That&& __opt)
{
if (__opt.has_value())
__construct(_VSTD::forward<_That>(__opt).__get());
}
template <class _That>
_LIBCPP_INLINE_VISIBILITY
void __assign_from(_That&& __opt)
{
if (has_value() == __opt.has_value())
{
if (has_value())
*__value_ = _VSTD::forward<_That>(__opt).__get();
}
else
{
if (has_value())
reset();
else
__construct(_VSTD::forward<_That>(__opt).__get());
}
}
};
template <class _Tp, bool = is_trivially_copy_constructible<_Tp>::value>
struct __optional_copy_base : __optional_storage_base<_Tp>
{
using __optional_storage_base<_Tp>::__optional_storage_base;
};
template <class _Tp>
struct __optional_copy_base<_Tp, false> : __optional_storage_base<_Tp>
{
using __optional_storage_base<_Tp>::__optional_storage_base;
_LIBCPP_INLINE_VISIBILITY
__optional_copy_base() = default;
_LIBCPP_INLINE_VISIBILITY
__optional_copy_base(const __optional_copy_base& __opt)
{
this->__construct_from(__opt);
}
_LIBCPP_INLINE_VISIBILITY
__optional_copy_base(__optional_copy_base&&) = default;
_LIBCPP_INLINE_VISIBILITY
__optional_copy_base& operator=(const __optional_copy_base&) = default;
_LIBCPP_INLINE_VISIBILITY
__optional_copy_base& operator=(__optional_copy_base&&) = default;
};
template <class _Tp, bool = is_trivially_move_constructible<_Tp>::value>
struct __optional_move_base : __optional_copy_base<_Tp>
{
using __optional_copy_base<_Tp>::__optional_copy_base;
};
template <class _Tp>
struct __optional_move_base<_Tp, false> : __optional_copy_base<_Tp>
{
using value_type = _Tp;
using __optional_copy_base<_Tp>::__optional_copy_base;
_LIBCPP_INLINE_VISIBILITY
__optional_move_base() = default;
_LIBCPP_INLINE_VISIBILITY
__optional_move_base(const __optional_move_base&) = default;
_LIBCPP_INLINE_VISIBILITY
__optional_move_base(__optional_move_base&& __opt)
noexcept(is_nothrow_move_constructible_v<value_type>)
{
this->__construct_from(_VSTD::move(__opt));
}
_LIBCPP_INLINE_VISIBILITY
__optional_move_base& operator=(const __optional_move_base&) = default;
_LIBCPP_INLINE_VISIBILITY
__optional_move_base& operator=(__optional_move_base&&) = default;
};
template <class _Tp, bool =
is_trivially_destructible<_Tp>::value &&
is_trivially_copy_constructible<_Tp>::value &&
is_trivially_copy_assignable<_Tp>::value>
struct __optional_copy_assign_base : __optional_move_base<_Tp>
{
using __optional_move_base<_Tp>::__optional_move_base;
};
template <class _Tp>
struct __optional_copy_assign_base<_Tp, false> : __optional_move_base<_Tp>
{
using __optional_move_base<_Tp>::__optional_move_base;
_LIBCPP_INLINE_VISIBILITY
__optional_copy_assign_base() = default;
_LIBCPP_INLINE_VISIBILITY
__optional_copy_assign_base(const __optional_copy_assign_base&) = default;
_LIBCPP_INLINE_VISIBILITY
__optional_copy_assign_base(__optional_copy_assign_base&&) = default;
_LIBCPP_INLINE_VISIBILITY
__optional_copy_assign_base& operator=(const __optional_copy_assign_base& __opt)
{
this->__assign_from(__opt);
return *this;
}
_LIBCPP_INLINE_VISIBILITY
__optional_copy_assign_base& operator=(__optional_copy_assign_base&&) = default;
};
template <class _Tp, bool =
is_trivially_destructible<_Tp>::value &&
is_trivially_move_constructible<_Tp>::value &&
is_trivially_move_assignable<_Tp>::value>
struct __optional_move_assign_base : __optional_copy_assign_base<_Tp>
{
using __optional_copy_assign_base<_Tp>::__optional_copy_assign_base;
};
template <class _Tp>
struct __optional_move_assign_base<_Tp, false> : __optional_copy_assign_base<_Tp>
{
using value_type = _Tp;
using __optional_copy_assign_base<_Tp>::__optional_copy_assign_base;
_LIBCPP_INLINE_VISIBILITY
__optional_move_assign_base() = default;
_LIBCPP_INLINE_VISIBILITY
__optional_move_assign_base(const __optional_move_assign_base& __opt) = default;
_LIBCPP_INLINE_VISIBILITY
__optional_move_assign_base(__optional_move_assign_base&&) = default;
_LIBCPP_INLINE_VISIBILITY
__optional_move_assign_base& operator=(const __optional_move_assign_base&) = default;
_LIBCPP_INLINE_VISIBILITY
__optional_move_assign_base& operator=(__optional_move_assign_base&& __opt)
noexcept(is_nothrow_move_assignable_v<value_type> &&
is_nothrow_move_constructible_v<value_type>)
{
this->__assign_from(_VSTD::move(__opt));
return *this;
}
};
template <class _Tp>
using __optional_sfinae_ctor_base_t = __sfinae_ctor_base<
is_copy_constructible<_Tp>::value,
is_move_constructible<_Tp>::value
>;
template <class _Tp>
using __optional_sfinae_assign_base_t = __sfinae_assign_base<
(is_copy_constructible<_Tp>::value && is_copy_assignable<_Tp>::value),
(is_move_constructible<_Tp>::value && is_move_assignable<_Tp>::value)
>;
template <class _Tp>
class optional
: private __optional_move_assign_base<_Tp>
, private __optional_sfinae_ctor_base_t<_Tp>
, private __optional_sfinae_assign_base_t<_Tp>
{
using __base = __optional_move_assign_base<_Tp>;
public:
using value_type = _Tp;
private:
// Disable the reference extension using this static assert.
static_assert(!is_same_v<__uncvref_t<value_type>, in_place_t>,
"instantiation of optional with in_place_t is ill-formed");
static_assert(!is_same_v<__uncvref_t<value_type>, nullopt_t>,
"instantiation of optional with nullopt_t is ill-formed");
static_assert(!is_reference_v<value_type>,
"instantiation of optional with a reference type is ill-formed");
static_assert(is_destructible_v<value_type>,
"instantiation of optional with a non-destructible type is ill-formed");
static_assert(!is_array_v<value_type>,
"instantiation of optional with an array type is ill-formed");
// LWG2756: conditionally explicit conversion from _Up
struct _CheckOptionalArgsConstructor {
template <class _Up>
static constexpr bool __enable_implicit() {
return is_constructible_v<_Tp, _Up&&> &&
is_convertible_v<_Up&&, _Tp>;
}
template <class _Up>
static constexpr bool __enable_explicit() {
return is_constructible_v<_Tp, _Up&&> &&
!is_convertible_v<_Up&&, _Tp>;
}
};
template <class _Up>
using _CheckOptionalArgsCtor = _If<
_IsNotSame<__uncvref_t<_Up>, in_place_t>::value &&
_IsNotSame<__uncvref_t<_Up>, optional>::value,
_CheckOptionalArgsConstructor,
__check_tuple_constructor_fail
>;
template <class _QualUp>
struct _CheckOptionalLikeConstructor {
template <class _Up, class _Opt = optional<_Up>>
using __check_constructible_from_opt = _Or<
is_constructible<_Tp, _Opt&>,
is_constructible<_Tp, _Opt const&>,
is_constructible<_Tp, _Opt&&>,
is_constructible<_Tp, _Opt const&&>,
is_convertible<_Opt&, _Tp>,
is_convertible<_Opt const&, _Tp>,
is_convertible<_Opt&&, _Tp>,
is_convertible<_Opt const&&, _Tp>
>;
template <class _Up, class _Opt = optional<_Up>>
using __check_assignable_from_opt = _Or<
is_assignable<_Tp&, _Opt&>,
is_assignable<_Tp&, _Opt const&>,
is_assignable<_Tp&, _Opt&&>,
is_assignable<_Tp&, _Opt const&&>
>;
template <class _Up, class _QUp = _QualUp>
static constexpr bool __enable_implicit() {
return is_convertible<_QUp, _Tp>::value &&
!__check_constructible_from_opt<_Up>::value;
}
template <class _Up, class _QUp = _QualUp>
static constexpr bool __enable_explicit() {
return !is_convertible<_QUp, _Tp>::value &&
!__check_constructible_from_opt<_Up>::value;
}
template <class _Up, class _QUp = _QualUp>
static constexpr bool __enable_assign() {
// Construction and assignability of _Qup to _Tp has already been
// checked.
return !__check_constructible_from_opt<_Up>::value &&
!__check_assignable_from_opt<_Up>::value;
}
};
template <class _Up, class _QualUp>
using _CheckOptionalLikeCtor = _If<
_And<
_IsNotSame<_Up, _Tp>,
is_constructible<_Tp, _QualUp>
>::value,
_CheckOptionalLikeConstructor<_QualUp>,
__check_tuple_constructor_fail
>;
template <class _Up, class _QualUp>
using _CheckOptionalLikeAssign = _If<
_And<
_IsNotSame<_Up, _Tp>,
is_constructible<_Tp, _QualUp>,
is_assignable<_Tp&, _QualUp>
>::value,
_CheckOptionalLikeConstructor<_QualUp>,
__check_tuple_constructor_fail
>;
public:
_LIBCPP_INLINE_VISIBILITY constexpr optional() noexcept {}
_LIBCPP_INLINE_VISIBILITY constexpr optional(const optional&) = default;
_LIBCPP_INLINE_VISIBILITY constexpr optional(optional&&) = default;
_LIBCPP_INLINE_VISIBILITY constexpr optional(nullopt_t) noexcept {}
template <class _InPlaceT, class... _Args, class = _EnableIf<
_And<
_IsSame<_InPlaceT, in_place_t>,
is_constructible<value_type, _Args...>
>::value
>
>
_LIBCPP_INLINE_VISIBILITY
constexpr explicit optional(_InPlaceT, _Args&&... __args)
: __base(in_place, _VSTD::forward<_Args>(__args)...) {}
template <class _Up, class... _Args, class = _EnableIf<
is_constructible_v<value_type, initializer_list<_Up>&, _Args...>>
>
_LIBCPP_INLINE_VISIBILITY
constexpr explicit optional(in_place_t, initializer_list<_Up> __il, _Args&&... __args)
: __base(in_place, __il, _VSTD::forward<_Args>(__args)...) {}
template <class _Up = value_type, _EnableIf<
_CheckOptionalArgsCtor<_Up>::template __enable_implicit<_Up>()
, int> = 0>
_LIBCPP_INLINE_VISIBILITY
constexpr optional(_Up&& __v)
: __base(in_place, _VSTD::forward<_Up>(__v)) {}
template <class _Up, _EnableIf<
_CheckOptionalArgsCtor<_Up>::template __enable_explicit<_Up>()
, int> = 0>
_LIBCPP_INLINE_VISIBILITY
constexpr explicit optional(_Up&& __v)
: __base(in_place, _VSTD::forward<_Up>(__v)) {}
// LWG2756: conditionally explicit conversion from const optional<_Up>&
template <class _Up, _EnableIf<
_CheckOptionalLikeCtor<_Up, _Up const&>::template __enable_implicit<_Up>()
, int> = 0>
_LIBCPP_INLINE_VISIBILITY
optional(const optional<_Up>& __v)
{
this->__construct_from(__v);
}
template <class _Up, _EnableIf<
_CheckOptionalLikeCtor<_Up, _Up const&>::template __enable_explicit<_Up>()
, int> = 0>
_LIBCPP_INLINE_VISIBILITY
explicit optional(const optional<_Up>& __v)
{
this->__construct_from(__v);
}
// LWG2756: conditionally explicit conversion from optional<_Up>&&
template <class _Up, _EnableIf<
_CheckOptionalLikeCtor<_Up, _Up &&>::template __enable_implicit<_Up>()
, int> = 0>
_LIBCPP_INLINE_VISIBILITY
optional(optional<_Up>&& __v)
{
this->__construct_from(_VSTD::move(__v));
}
template <class _Up, _EnableIf<
_CheckOptionalLikeCtor<_Up, _Up &&>::template __enable_explicit<_Up>()
, int> = 0>
_LIBCPP_INLINE_VISIBILITY
explicit optional(optional<_Up>&& __v)
{
this->__construct_from(_VSTD::move(__v));
}
_LIBCPP_INLINE_VISIBILITY
optional& operator=(nullopt_t) noexcept
{
reset();
return *this;
}
_LIBCPP_INLINE_VISIBILITY optional& operator=(const optional&) = default;
_LIBCPP_INLINE_VISIBILITY optional& operator=(optional&&) = default;
// LWG2756
template <class _Up = value_type,
class = _EnableIf<
_And<
_IsNotSame<__uncvref_t<_Up>, optional>,
_Or<
_IsNotSame<__uncvref_t<_Up>, value_type>,
_Not<is_scalar<value_type>>
>,
is_constructible<value_type, _Up>,
is_assignable<value_type&, _Up>
>::value>
>
_LIBCPP_INLINE_VISIBILITY
optional&
operator=(_Up&& __v)
{
if (this->has_value())
this->__get() = _VSTD::forward<_Up>(__v);
else
this->__construct(_VSTD::forward<_Up>(__v));
return *this;
}
// LWG2756
template <class _Up, _EnableIf<
_CheckOptionalLikeAssign<_Up, _Up const&>::template __enable_assign<_Up>()
, int> = 0>
_LIBCPP_INLINE_VISIBILITY
optional&
operator=(const optional<_Up>& __v)
{
this->__assign_from(__v);
return *this;
}
// LWG2756
template <class _Up, _EnableIf<
_CheckOptionalLikeCtor<_Up, _Up &&>::template __enable_assign<_Up>()
, int> = 0>
_LIBCPP_INLINE_VISIBILITY
optional&
operator=(optional<_Up>&& __v)
{
this->__assign_from(_VSTD::move(__v));
return *this;
}
template <class... _Args,
class = _EnableIf
<
is_constructible_v<value_type, _Args...>
>
>
_LIBCPP_INLINE_VISIBILITY
_Tp &
emplace(_Args&&... __args)
{
reset();
this->__construct(_VSTD::forward<_Args>(__args)...);
return this->__get();
}
template <class _Up, class... _Args,
class = _EnableIf
<
is_constructible_v<value_type, initializer_list<_Up>&, _Args...>
>
>
_LIBCPP_INLINE_VISIBILITY
_Tp &
emplace(initializer_list<_Up> __il, _Args&&... __args)
{
reset();
this->__construct(__il, _VSTD::forward<_Args>(__args)...);
return this->__get();
}
_LIBCPP_INLINE_VISIBILITY
void swap(optional& __opt)
noexcept(is_nothrow_move_constructible_v<value_type> &&
is_nothrow_swappable_v<value_type>)
{
if (this->has_value() == __opt.has_value())
{
using _VSTD::swap;
if (this->has_value())
swap(this->__get(), __opt.__get());
}
else
{
if (this->has_value())
{
__opt.__construct(_VSTD::move(this->__get()));
reset();
}
else
{
this->__construct(_VSTD::move(__opt.__get()));
__opt.reset();
}
}
}
_LIBCPP_INLINE_VISIBILITY
constexpr
add_pointer_t<value_type const>
operator->() const
{
_LIBCPP_ASSERT(this->has_value(), "optional operator-> called for disengaged value");
#ifndef _LIBCPP_HAS_NO_BUILTIN_ADDRESSOF
return _VSTD::addressof(this->__get());
#else
return __operator_arrow(__has_operator_addressof<value_type>{}, this->__get());
#endif
}
_LIBCPP_INLINE_VISIBILITY
constexpr
add_pointer_t<value_type>
operator->()
{
_LIBCPP_ASSERT(this->has_value(), "optional operator-> called for disengaged value");
#ifndef _LIBCPP_HAS_NO_BUILTIN_ADDRESSOF
return _VSTD::addressof(this->__get());
#else
return __operator_arrow(__has_operator_addressof<value_type>{}, this->__get());
#endif
}
_LIBCPP_INLINE_VISIBILITY
constexpr
const value_type&
operator*() const&
{
_LIBCPP_ASSERT(this->has_value(), "optional operator* called for disengaged value");
return this->__get();
}
_LIBCPP_INLINE_VISIBILITY
constexpr
value_type&
operator*() &
{
_LIBCPP_ASSERT(this->has_value(), "optional operator* called for disengaged value");
return this->__get();
}
_LIBCPP_INLINE_VISIBILITY
constexpr
value_type&&
operator*() &&
{
_LIBCPP_ASSERT(this->has_value(), "optional operator* called for disengaged value");
return _VSTD::move(this->__get());
}
_LIBCPP_INLINE_VISIBILITY
constexpr
const value_type&&
operator*() const&&
{
_LIBCPP_ASSERT(this->has_value(), "optional operator* called for disengaged value");
return _VSTD::move(this->__get());
}
_LIBCPP_INLINE_VISIBILITY
constexpr explicit operator bool() const noexcept { return has_value(); }
using __base::has_value;
using __base::__get;
_LIBCPP_INLINE_VISIBILITY
_LIBCPP_AVAILABILITY_THROW_BAD_OPTIONAL_ACCESS
constexpr value_type const& value() const&
{
if (!this->has_value())
__throw_bad_optional_access();
return this->__get();
}
_LIBCPP_INLINE_VISIBILITY
_LIBCPP_AVAILABILITY_THROW_BAD_OPTIONAL_ACCESS
constexpr value_type& value() &
{
if (!this->has_value())
__throw_bad_optional_access();
return this->__get();
}
_LIBCPP_INLINE_VISIBILITY
_LIBCPP_AVAILABILITY_THROW_BAD_OPTIONAL_ACCESS
constexpr value_type&& value() &&
{
if (!this->has_value())
__throw_bad_optional_access();
return _VSTD::move(this->__get());
}
_LIBCPP_INLINE_VISIBILITY
_LIBCPP_AVAILABILITY_THROW_BAD_OPTIONAL_ACCESS
constexpr value_type const&& value() const&&
{
if (!this->has_value())
__throw_bad_optional_access();
return _VSTD::move(this->__get());
}
template <class _Up>
_LIBCPP_INLINE_VISIBILITY
constexpr value_type value_or(_Up&& __v) const&
{
static_assert(is_copy_constructible_v<value_type>,
"optional<T>::value_or: T must be copy constructible");
static_assert(is_convertible_v<_Up, value_type>,
"optional<T>::value_or: U must be convertible to T");
return this->has_value() ? this->__get() :
static_cast<value_type>(_VSTD::forward<_Up>(__v));
}
template <class _Up>
_LIBCPP_INLINE_VISIBILITY
constexpr value_type value_or(_Up&& __v) &&
{
static_assert(is_move_constructible_v<value_type>,
"optional<T>::value_or: T must be move constructible");
static_assert(is_convertible_v<_Up, value_type>,
"optional<T>::value_or: U must be convertible to T");
return this->has_value() ? _VSTD::move(this->__get()) :
static_cast<value_type>(_VSTD::forward<_Up>(__v));
}
using __base::reset;
private:
template <class _Up>
_LIBCPP_INLINE_VISIBILITY
static _Up*
__operator_arrow(true_type, _Up& __x)
{
return _VSTD::addressof(__x);
}
template <class _Up>
_LIBCPP_INLINE_VISIBILITY
static constexpr _Up*
__operator_arrow(false_type, _Up& __x)
{
return &__x;
}
};
#ifndef _LIBCPP_HAS_NO_DEDUCTION_GUIDES
template<class T>
optional(T) -> optional<T>;
#endif
// Comparisons between optionals
template <class _Tp, class _Up>
_LIBCPP_INLINE_VISIBILITY constexpr
_EnableIf<
is_convertible_v<decltype(_VSTD::declval<const _Tp&>() ==
_VSTD::declval<const _Up&>()), bool>,
bool
>
operator==(const optional<_Tp>& __x, const optional<_Up>& __y)
{
if (static_cast<bool>(__x) != static_cast<bool>(__y))
return false;
if (!static_cast<bool>(__x))
return true;
return *__x == *__y;
}
template <class _Tp, class _Up>
_LIBCPP_INLINE_VISIBILITY constexpr
_EnableIf<
is_convertible_v<decltype(_VSTD::declval<const _Tp&>() !=
_VSTD::declval<const _Up&>()), bool>,
bool
>
operator!=(const optional<_Tp>& __x, const optional<_Up>& __y)
{
if (static_cast<bool>(__x) != static_cast<bool>(__y))
return true;
if (!static_cast<bool>(__x))
return false;
return *__x != *__y;
}
template <class _Tp, class _Up>
_LIBCPP_INLINE_VISIBILITY constexpr
_EnableIf<
is_convertible_v<decltype(_VSTD::declval<const _Tp&>() <
_VSTD::declval<const _Up&>()), bool>,
bool
>
operator<(const optional<_Tp>& __x, const optional<_Up>& __y)
{
if (!static_cast<bool>(__y))
return false;
if (!static_cast<bool>(__x))
return true;
return *__x < *__y;
}
template <class _Tp, class _Up>
_LIBCPP_INLINE_VISIBILITY constexpr
_EnableIf<
is_convertible_v<decltype(_VSTD::declval<const _Tp&>() >
_VSTD::declval<const _Up&>()), bool>,
bool
>
operator>(const optional<_Tp>& __x, const optional<_Up>& __y)
{
if (!static_cast<bool>(__x))
return false;
if (!static_cast<bool>(__y))
return true;
return *__x > *__y;
}
template <class _Tp, class _Up>
_LIBCPP_INLINE_VISIBILITY constexpr
_EnableIf<
is_convertible_v<decltype(_VSTD::declval<const _Tp&>() <=
_VSTD::declval<const _Up&>()), bool>,
bool
>
operator<=(const optional<_Tp>& __x, const optional<_Up>& __y)
{
if (!static_cast<bool>(__x))
return true;
if (!static_cast<bool>(__y))
return false;
return *__x <= *__y;
}
template <class _Tp, class _Up>
_LIBCPP_INLINE_VISIBILITY constexpr
_EnableIf<
is_convertible_v<decltype(_VSTD::declval<const _Tp&>() >=
_VSTD::declval<const _Up&>()), bool>,
bool
>
operator>=(const optional<_Tp>& __x, const optional<_Up>& __y)
{
if (!static_cast<bool>(__y))
return true;
if (!static_cast<bool>(__x))
return false;
return *__x >= *__y;
}
// Comparisons with nullopt
template <class _Tp>
_LIBCPP_INLINE_VISIBILITY constexpr
bool
operator==(const optional<_Tp>& __x, nullopt_t) noexcept
{
return !static_cast<bool>(__x);
}
template <class _Tp>
_LIBCPP_INLINE_VISIBILITY constexpr
bool
operator==(nullopt_t, const optional<_Tp>& __x) noexcept
{
return !static_cast<bool>(__x);
}
template <class _Tp>
_LIBCPP_INLINE_VISIBILITY constexpr
bool
operator!=(const optional<_Tp>& __x, nullopt_t) noexcept
{
return static_cast<bool>(__x);
}
template <class _Tp>
_LIBCPP_INLINE_VISIBILITY constexpr
bool
operator!=(nullopt_t, const optional<_Tp>& __x) noexcept
{
return static_cast<bool>(__x);
}
template <class _Tp>
_LIBCPP_INLINE_VISIBILITY constexpr
bool
operator<(const optional<_Tp>&, nullopt_t) noexcept
{
return false;
}
template <class _Tp>
_LIBCPP_INLINE_VISIBILITY constexpr
bool
operator<(nullopt_t, const optional<_Tp>& __x) noexcept
{
return static_cast<bool>(__x);
}
template <class _Tp>
_LIBCPP_INLINE_VISIBILITY constexpr
bool
operator<=(const optional<_Tp>& __x, nullopt_t) noexcept
{
return !static_cast<bool>(__x);
}
template <class _Tp>
_LIBCPP_INLINE_VISIBILITY constexpr
bool
operator<=(nullopt_t, const optional<_Tp>&) noexcept
{
return true;
}
template <class _Tp>
_LIBCPP_INLINE_VISIBILITY constexpr
bool
operator>(const optional<_Tp>& __x, nullopt_t) noexcept
{
return static_cast<bool>(__x);
}
template <class _Tp>
_LIBCPP_INLINE_VISIBILITY constexpr
bool
operator>(nullopt_t, const optional<_Tp>&) noexcept
{
return false;
}
template <class _Tp>
_LIBCPP_INLINE_VISIBILITY constexpr
bool
operator>=(const optional<_Tp>&, nullopt_t) noexcept
{
return true;
}
template <class _Tp>
_LIBCPP_INLINE_VISIBILITY constexpr
bool
operator>=(nullopt_t, const optional<_Tp>& __x) noexcept
{
return !static_cast<bool>(__x);
}
// Comparisons with T
template <class _Tp, class _Up>
_LIBCPP_INLINE_VISIBILITY constexpr
_EnableIf<
is_convertible_v<decltype(_VSTD::declval<const _Tp&>() ==
_VSTD::declval<const _Up&>()), bool>,
bool
>
operator==(const optional<_Tp>& __x, const _Up& __v)
{
return static_cast<bool>(__x) ? *__x == __v : false;
}
template <class _Tp, class _Up>
_LIBCPP_INLINE_VISIBILITY constexpr
_EnableIf<
is_convertible_v<decltype(_VSTD::declval<const _Tp&>() ==
_VSTD::declval<const _Up&>()), bool>,
bool
>
operator==(const _Tp& __v, const optional<_Up>& __x)
{
return static_cast<bool>(__x) ? __v == *__x : false;
}
template <class _Tp, class _Up>
_LIBCPP_INLINE_VISIBILITY constexpr
_EnableIf<
is_convertible_v<decltype(_VSTD::declval<const _Tp&>() !=
_VSTD::declval<const _Up&>()), bool>,
bool
>
operator!=(const optional<_Tp>& __x, const _Up& __v)
{
return static_cast<bool>(__x) ? *__x != __v : true;
}
template <class _Tp, class _Up>
_LIBCPP_INLINE_VISIBILITY constexpr
_EnableIf<
is_convertible_v<decltype(_VSTD::declval<const _Tp&>() !=
_VSTD::declval<const _Up&>()), bool>,
bool
>
operator!=(const _Tp& __v, const optional<_Up>& __x)
{
return static_cast<bool>(__x) ? __v != *__x : true;
}
template <class _Tp, class _Up>
_LIBCPP_INLINE_VISIBILITY constexpr
_EnableIf<
is_convertible_v<decltype(_VSTD::declval<const _Tp&>() <
_VSTD::declval<const _Up&>()), bool>,
bool
>
operator<(const optional<_Tp>& __x, const _Up& __v)
{
return static_cast<bool>(__x) ? *__x < __v : true;
}
template <class _Tp, class _Up>
_LIBCPP_INLINE_VISIBILITY constexpr
_EnableIf<
is_convertible_v<decltype(_VSTD::declval<const _Tp&>() <
_VSTD::declval<const _Up&>()), bool>,
bool
>
operator<(const _Tp& __v, const optional<_Up>& __x)
{
return static_cast<bool>(__x) ? __v < *__x : false;
}
template <class _Tp, class _Up>
_LIBCPP_INLINE_VISIBILITY constexpr
_EnableIf<
is_convertible_v<decltype(_VSTD::declval<const _Tp&>() <=
_VSTD::declval<const _Up&>()), bool>,
bool
>
operator<=(const optional<_Tp>& __x, const _Up& __v)
{
return static_cast<bool>(__x) ? *__x <= __v : true;
}
template <class _Tp, class _Up>
_LIBCPP_INLINE_VISIBILITY constexpr
_EnableIf<
is_convertible_v<decltype(_VSTD::declval<const _Tp&>() <=
_VSTD::declval<const _Up&>()), bool>,
bool
>
operator<=(const _Tp& __v, const optional<_Up>& __x)
{
return static_cast<bool>(__x) ? __v <= *__x : false;
}
template <class _Tp, class _Up>
_LIBCPP_INLINE_VISIBILITY constexpr
_EnableIf<
is_convertible_v<decltype(_VSTD::declval<const _Tp&>() >
_VSTD::declval<const _Up&>()), bool>,
bool
>
operator>(const optional<_Tp>& __x, const _Up& __v)
{
return static_cast<bool>(__x) ? *__x > __v : false;
}
template <class _Tp, class _Up>
_LIBCPP_INLINE_VISIBILITY constexpr
_EnableIf<
is_convertible_v<decltype(_VSTD::declval<const _Tp&>() >
_VSTD::declval<const _Up&>()), bool>,
bool
>
operator>(const _Tp& __v, const optional<_Up>& __x)
{
return static_cast<bool>(__x) ? __v > *__x : true;
}
template <class _Tp, class _Up>
_LIBCPP_INLINE_VISIBILITY constexpr
_EnableIf<
is_convertible_v<decltype(_VSTD::declval<const _Tp&>() >=
_VSTD::declval<const _Up&>()), bool>,
bool
>
operator>=(const optional<_Tp>& __x, const _Up& __v)
{
return static_cast<bool>(__x) ? *__x >= __v : false;
}
template <class _Tp, class _Up>
_LIBCPP_INLINE_VISIBILITY constexpr
_EnableIf<
is_convertible_v<decltype(_VSTD::declval<const _Tp&>() >=
_VSTD::declval<const _Up&>()), bool>,
bool
>
operator>=(const _Tp& __v, const optional<_Up>& __x)
{
return static_cast<bool>(__x) ? __v >= *__x : true;
}
template <class _Tp>
inline _LIBCPP_INLINE_VISIBILITY
_EnableIf<
is_move_constructible_v<_Tp> && is_swappable_v<_Tp>,
void
>
swap(optional<_Tp>& __x, optional<_Tp>& __y) noexcept(noexcept(__x.swap(__y)))
{
__x.swap(__y);
}
template <class _Tp>
_LIBCPP_INLINE_VISIBILITY constexpr
optional<decay_t<_Tp>> make_optional(_Tp&& __v)
{
return optional<decay_t<_Tp>>(_VSTD::forward<_Tp>(__v));
}
template <class _Tp, class... _Args>
_LIBCPP_INLINE_VISIBILITY constexpr
optional<_Tp> make_optional(_Args&&... __args)
{
return optional<_Tp>(in_place, _VSTD::forward<_Args>(__args)...);
}
template <class _Tp, class _Up, class... _Args>
_LIBCPP_INLINE_VISIBILITY constexpr
optional<_Tp> make_optional(initializer_list<_Up> __il, _Args&&... __args)
{
return optional<_Tp>(in_place, __il, _VSTD::forward<_Args>(__args)...);
}
template <class _Tp>
struct _LIBCPP_TEMPLATE_VIS hash<
__enable_hash_helper<optional<_Tp>, remove_const_t<_Tp>>
>
{
typedef optional<_Tp> argument_type;
typedef size_t result_type;
_LIBCPP_INLINE_VISIBILITY
result_type operator()(const argument_type& __opt) const
{
return static_cast<bool>(__opt) ? hash<remove_const_t<_Tp>>()(*__opt) : 0;
}
};
_LIBCPP_END_NAMESPACE_STD
#endif // _LIBCPP_STD_VER > 14
_LIBCPP_POP_MACROS
#endif // _LIBCPP_OPTIONAL
| 42,801 | 1,421 | jart/cosmopolitan | false |
cosmopolitan/third_party/libcxx/locale3.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
bool __checked_string_to_wchar_convert(wchar_t& dest,
const char* ptr,
locale_t loc);
bool __checked_string_to_char_convert(char& dest,
const char* ptr,
locale_t __loc);
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&);
};
// moneypunct_byname
template <class charT>
static
void
__init_pat(money_base::pattern& pat, basic_string<charT>& __curr_symbol_,
bool intl, char cs_precedes, char sep_by_space, char sign_posn,
charT space_char)
{
const char sign = static_cast<char>(money_base::sign);
const char space = static_cast<char>(money_base::space);
const char none = static_cast<char>(money_base::none);
const char symbol = static_cast<char>(money_base::symbol);
const char value = static_cast<char>(money_base::value);
const bool symbol_contains_sep = intl && __curr_symbol_.size() == 4;
// Comments on case branches reflect 'C11 7.11.2.1 The localeconv
// function'. "Space between sign and symbol or value" means that
// if the sign is adjacent to the symbol, there's a space between
// them, and otherwise there's a space between the sign and value.
//
// C11's localeconv specifies that the fourth character of an
// international curr_symbol is used to separate the sign and
// value when sep_by_space says to do so. C++ can't represent
// that, so we just use a space. When sep_by_space says to
// separate the symbol and value-or-sign with a space, we rearrange the
// curr_symbol to put its spacing character on the correct side of
// the symbol.
//
// We also need to avoid adding an extra space between the sign
// and value when the currency symbol is suppressed (by not
// setting showbase). We match glibc's strfmon by interpreting
// sep_by_space==1 as "omit the space when the currency symbol is
// absent".
//
// Users who want to get this right should use ICU instead.
switch (cs_precedes)
{
case 0: // value before curr_symbol
if (symbol_contains_sep) {
// Move the separator to before the symbol, to place it
// between the value and symbol.
rotate(__curr_symbol_.begin(), __curr_symbol_.begin() + 3,
__curr_symbol_.end());
}
switch (sign_posn)
{
case 0: // Parentheses surround the quantity and currency symbol.
pat.field[0] = sign;
pat.field[1] = value;
pat.field[2] = none; // Any space appears in the symbol.
pat.field[3] = symbol;
switch (sep_by_space)
{
case 0: // No space separates the currency symbol and value.
// This case may have changed between C99 and C11;
// assume the currency symbol matches the intention.
case 2: // Space between sign and currency or value.
// The "sign" is two parentheses, so no space here either.
return;
case 1: // Space between currency-and-sign or currency and value.
if (!symbol_contains_sep) {
// We insert the space into the symbol instead of
// setting pat.field[2]=space so that when
// showbase is not set, the space goes away too.
__curr_symbol_.insert(0, 1, space_char);
}
return;
default:
break;
}
break;
case 1: // The sign string precedes the quantity and currency symbol.
pat.field[0] = sign;
pat.field[3] = symbol;
switch (sep_by_space)
{
case 0: // No space separates the currency symbol and value.
pat.field[1] = value;
pat.field[2] = none;
return;
case 1: // Space between currency-and-sign or currency and value.
pat.field[1] = value;
pat.field[2] = none;
if (!symbol_contains_sep) {
// We insert the space into the symbol instead of
// setting pat.field[2]=space so that when
// showbase is not set, the space goes away too.
__curr_symbol_.insert(0, 1, space_char);
}
return;
case 2: // Space between sign and currency or value.
pat.field[1] = space;
pat.field[2] = value;
if (symbol_contains_sep) {
// Remove the separator from the symbol, since it
// has already appeared after the sign.
__curr_symbol_.erase(__curr_symbol_.begin());
}
return;
default:
break;
}
break;
case 2: // The sign string succeeds the quantity and currency symbol.
pat.field[0] = value;
pat.field[3] = sign;
switch (sep_by_space)
{
case 0: // No space separates the currency symbol and value.
pat.field[1] = none;
pat.field[2] = symbol;
return;
case 1: // Space between currency-and-sign or currency and value.
if (!symbol_contains_sep) {
// We insert the space into the symbol instead of
// setting pat.field[1]=space so that when
// showbase is not set, the space goes away too.
__curr_symbol_.insert(0, 1, space_char);
}
pat.field[1] = none;
pat.field[2] = symbol;
return;
case 2: // Space between sign and currency or value.
pat.field[1] = symbol;
pat.field[2] = space;
if (symbol_contains_sep) {
// Remove the separator from the symbol, since it
// should not be removed if showbase is absent.
__curr_symbol_.erase(__curr_symbol_.begin());
}
return;
default:
break;
}
break;
case 3: // The sign string immediately precedes the currency symbol.
pat.field[0] = value;
pat.field[3] = symbol;
switch (sep_by_space)
{
case 0: // No space separates the currency symbol and value.
pat.field[1] = none;
pat.field[2] = sign;
return;
case 1: // Space between currency-and-sign or currency and value.
pat.field[1] = space;
pat.field[2] = sign;
if (symbol_contains_sep) {
// Remove the separator from the symbol, since it
// has already appeared before the sign.
__curr_symbol_.erase(__curr_symbol_.begin());
}
return;
case 2: // Space between sign and currency or value.
pat.field[1] = sign;
pat.field[2] = none;
if (!symbol_contains_sep) {
// We insert the space into the symbol instead of
// setting pat.field[2]=space so that when
// showbase is not set, the space goes away too.
__curr_symbol_.insert(0, 1, space_char);
}
return;
default:
break;
}
break;
case 4: // The sign string immediately succeeds the currency symbol.
pat.field[0] = value;
pat.field[3] = sign;
switch (sep_by_space)
{
case 0: // No space separates the currency symbol and value.
pat.field[1] = none;
pat.field[2] = symbol;
return;
case 1: // Space between currency-and-sign or currency and value.
pat.field[1] = none;
pat.field[2] = symbol;
if (!symbol_contains_sep) {
// We insert the space into the symbol instead of
// setting pat.field[1]=space so that when
// showbase is not set, the space goes away too.
__curr_symbol_.insert(0, 1, space_char);
}
return;
case 2: // Space between sign and currency or value.
pat.field[1] = symbol;
pat.field[2] = space;
if (symbol_contains_sep) {
// Remove the separator from the symbol, since it
// should not disappear when showbase is absent.
__curr_symbol_.erase(__curr_symbol_.begin());
}
return;
default:
break;
}
break;
default:
break;
}
break;
case 1: // curr_symbol before value
switch (sign_posn)
{
case 0: // Parentheses surround the quantity and currency symbol.
pat.field[0] = sign;
pat.field[1] = symbol;
pat.field[2] = none; // Any space appears in the symbol.
pat.field[3] = value;
switch (sep_by_space)
{
case 0: // No space separates the currency symbol and value.
// This case may have changed between C99 and C11;
// assume the currency symbol matches the intention.
case 2: // Space between sign and currency or value.
// The "sign" is two parentheses, so no space here either.
return;
case 1: // Space between currency-and-sign or currency and value.
if (!symbol_contains_sep) {
// We insert the space into the symbol instead of
// setting pat.field[2]=space so that when
// showbase is not set, the space goes away too.
__curr_symbol_.insert(0, 1, space_char);
}
return;
default:
break;
}
break;
case 1: // The sign string precedes the quantity and currency symbol.
pat.field[0] = sign;
pat.field[3] = value;
switch (sep_by_space)
{
case 0: // No space separates the currency symbol and value.
pat.field[1] = symbol;
pat.field[2] = none;
return;
case 1: // Space between currency-and-sign or currency and value.
pat.field[1] = symbol;
pat.field[2] = none;
if (!symbol_contains_sep) {
// We insert the space into the symbol instead of
// setting pat.field[2]=space so that when
// showbase is not set, the space goes away too.
__curr_symbol_.push_back(space_char);
}
return;
case 2: // Space between sign and currency or value.
pat.field[1] = space;
pat.field[2] = symbol;
if (symbol_contains_sep) {
// Remove the separator from the symbol, since it
// has already appeared after the sign.
__curr_symbol_.pop_back();
}
return;
default:
break;
}
break;
case 2: // The sign string succeeds the quantity and currency symbol.
pat.field[0] = symbol;
pat.field[3] = sign;
switch (sep_by_space)
{
case 0: // No space separates the currency symbol and value.
pat.field[1] = none;
pat.field[2] = value;
return;
case 1: // Space between currency-and-sign or currency and value.
pat.field[1] = none;
pat.field[2] = value;
if (!symbol_contains_sep) {
// We insert the space into the symbol instead of
// setting pat.field[1]=space so that when
// showbase is not set, the space goes away too.
__curr_symbol_.push_back(space_char);
}
return;
case 2: // Space between sign and currency or value.
pat.field[1] = value;
pat.field[2] = space;
if (symbol_contains_sep) {
// Remove the separator from the symbol, since it
// will appear before the sign.
__curr_symbol_.pop_back();
}
return;
default:
break;
}
break;
case 3: // The sign string immediately precedes the currency symbol.
pat.field[0] = sign;
pat.field[3] = value;
switch (sep_by_space)
{
case 0: // No space separates the currency symbol and value.
pat.field[1] = symbol;
pat.field[2] = none;
return;
case 1: // Space between currency-and-sign or currency and value.
pat.field[1] = symbol;
pat.field[2] = none;
if (!symbol_contains_sep) {
// We insert the space into the symbol instead of
// setting pat.field[2]=space so that when
// showbase is not set, the space goes away too.
__curr_symbol_.push_back(space_char);
}
return;
case 2: // Space between sign and currency or value.
pat.field[1] = space;
pat.field[2] = symbol;
if (symbol_contains_sep) {
// Remove the separator from the symbol, since it
// has already appeared after the sign.
__curr_symbol_.pop_back();
}
return;
default:
break;
}
break;
case 4: // The sign string immediately succeeds the currency symbol.
pat.field[0] = symbol;
pat.field[3] = value;
switch (sep_by_space)
{
case 0: // No space separates the currency symbol and value.
pat.field[1] = sign;
pat.field[2] = none;
return;
case 1: // Space between currency-and-sign or currency and value.
pat.field[1] = sign;
pat.field[2] = space;
if (symbol_contains_sep) {
// Remove the separator from the symbol, since it
// should not disappear when showbase is absent.
__curr_symbol_.pop_back();
}
return;
case 2: // Space between sign and currency or value.
pat.field[1] = none;
pat.field[2] = sign;
if (!symbol_contains_sep) {
// We insert the space into the symbol instead of
// setting pat.field[1]=space so that when
// showbase is not set, the space goes away too.
__curr_symbol_.push_back(space_char);
}
return;
default:
break;
}
break;
default:
break;
}
break;
default:
break;
}
pat.field[0] = symbol;
pat.field[1] = sign;
pat.field[2] = none;
pat.field[3] = value;
}
template<>
void
moneypunct_byname<char, false>::init(const char* nm)
{
typedef moneypunct<char, false> base;
__libcpp_unique_locale loc(nm);
if (!loc)
__throw_runtime_error("moneypunct_byname"
" failed to construct for " + string(nm));
lconv* lc = __libcpp_localeconv_l(loc.get());
if (!__checked_string_to_char_convert(__decimal_point_,
lc->mon_decimal_point,
loc.get()))
__decimal_point_ = base::do_decimal_point();
if (!__checked_string_to_char_convert(__thousands_sep_,
lc->mon_thousands_sep,
loc.get()))
__thousands_sep_ = base::do_thousands_sep();
__grouping_ = lc->mon_grouping;
__curr_symbol_ = lc->currency_symbol;
if (lc->frac_digits != CHAR_MAX)
__frac_digits_ = lc->frac_digits;
else
__frac_digits_ = base::do_frac_digits();
if (lc->p_sign_posn == 0)
__positive_sign_ = "()";
else
__positive_sign_ = lc->positive_sign;
if (lc->n_sign_posn == 0)
__negative_sign_ = "()";
else
__negative_sign_ = lc->negative_sign;
// Assume the positive and negative formats will want spaces in
// the same places in curr_symbol since there's no way to
// represent anything else.
string_type __dummy_curr_symbol = __curr_symbol_;
__init_pat(__pos_format_, __dummy_curr_symbol, false,
lc->p_cs_precedes, lc->p_sep_by_space, lc->p_sign_posn, ' ');
__init_pat(__neg_format_, __curr_symbol_, false,
lc->n_cs_precedes, lc->n_sep_by_space, lc->n_sign_posn, ' ');
}
template<>
void
moneypunct_byname<char, true>::init(const char* nm)
{
typedef moneypunct<char, true> base;
__libcpp_unique_locale loc(nm);
if (!loc)
__throw_runtime_error("moneypunct_byname"
" failed to construct for " + string(nm));
lconv* lc = __libcpp_localeconv_l(loc.get());
if (!__checked_string_to_char_convert(__decimal_point_,
lc->mon_decimal_point,
loc.get()))
__decimal_point_ = base::do_decimal_point();
if (!__checked_string_to_char_convert(__thousands_sep_,
lc->mon_thousands_sep,
loc.get()))
__thousands_sep_ = base::do_thousands_sep();
__grouping_ = lc->mon_grouping;
__curr_symbol_ = lc->int_curr_symbol;
if (lc->int_frac_digits != CHAR_MAX)
__frac_digits_ = lc->int_frac_digits;
else
__frac_digits_ = base::do_frac_digits();
#if defined(_LIBCPP_MSVCRT) || defined(__MINGW32__)
if (lc->p_sign_posn == 0)
#else // _LIBCPP_MSVCRT
if (lc->int_p_sign_posn == 0)
#endif // !_LIBCPP_MSVCRT
__positive_sign_ = "()";
else
__positive_sign_ = lc->positive_sign;
#if defined(_LIBCPP_MSVCRT) || defined(__MINGW32__)
if(lc->n_sign_posn == 0)
#else // _LIBCPP_MSVCRT
if (lc->int_n_sign_posn == 0)
#endif // !_LIBCPP_MSVCRT
__negative_sign_ = "()";
else
__negative_sign_ = lc->negative_sign;
// Assume the positive and negative formats will want spaces in
// the same places in curr_symbol since there's no way to
// represent anything else.
string_type __dummy_curr_symbol = __curr_symbol_;
#if defined(_LIBCPP_MSVCRT) || defined(__MINGW32__)
__init_pat(__pos_format_, __dummy_curr_symbol, true,
lc->p_cs_precedes, lc->p_sep_by_space, lc->p_sign_posn, ' ');
__init_pat(__neg_format_, __curr_symbol_, true,
lc->n_cs_precedes, lc->n_sep_by_space, lc->n_sign_posn, ' ');
#else // _LIBCPP_MSVCRT
__init_pat(__pos_format_, __dummy_curr_symbol, true,
lc->int_p_cs_precedes, lc->int_p_sep_by_space,
lc->int_p_sign_posn, ' ');
__init_pat(__neg_format_, __curr_symbol_, true,
lc->int_n_cs_precedes, lc->int_n_sep_by_space,
lc->int_n_sign_posn, ' ');
#endif // !_LIBCPP_MSVCRT
}
template<>
void
moneypunct_byname<wchar_t, false>::init(const char* nm)
{
typedef moneypunct<wchar_t, false> base;
__libcpp_unique_locale loc(nm);
if (!loc)
__throw_runtime_error("moneypunct_byname"
" failed to construct for " + string(nm));
lconv* lc = __libcpp_localeconv_l(loc.get());
if (!__checked_string_to_wchar_convert(__decimal_point_,
lc->mon_decimal_point,
loc.get()))
__decimal_point_ = base::do_decimal_point();
if (!__checked_string_to_wchar_convert(__thousands_sep_,
lc->mon_thousands_sep,
loc.get()))
__thousands_sep_ = base::do_thousands_sep();
__grouping_ = lc->mon_grouping;
wchar_t wbuf[100];
mbstate_t mb = {0};
const char* bb = lc->currency_symbol;
size_t j = __libcpp_mbsrtowcs_l(wbuf, &bb, countof(wbuf), &mb, loc.get());
if (j == size_t(-1))
__throw_runtime_error("locale not supported");
wchar_t* wbe = wbuf + j;
__curr_symbol_.assign(wbuf, wbe);
if (lc->frac_digits != CHAR_MAX)
__frac_digits_ = lc->frac_digits;
else
__frac_digits_ = base::do_frac_digits();
if (lc->p_sign_posn == 0)
__positive_sign_ = L"()";
else
{
mb = mbstate_t();
bb = lc->positive_sign;
j = __libcpp_mbsrtowcs_l(wbuf, &bb, countof(wbuf), &mb, loc.get());
if (j == size_t(-1))
__throw_runtime_error("locale not supported");
wbe = wbuf + j;
__positive_sign_.assign(wbuf, wbe);
}
if (lc->n_sign_posn == 0)
__negative_sign_ = L"()";
else
{
mb = mbstate_t();
bb = lc->negative_sign;
j = __libcpp_mbsrtowcs_l(wbuf, &bb, countof(wbuf), &mb, loc.get());
if (j == size_t(-1))
__throw_runtime_error("locale not supported");
wbe = wbuf + j;
__negative_sign_.assign(wbuf, wbe);
}
// Assume the positive and negative formats will want spaces in
// the same places in curr_symbol since there's no way to
// represent anything else.
string_type __dummy_curr_symbol = __curr_symbol_;
__init_pat(__pos_format_, __dummy_curr_symbol, false,
lc->p_cs_precedes, lc->p_sep_by_space, lc->p_sign_posn, L' ');
__init_pat(__neg_format_, __curr_symbol_, false,
lc->n_cs_precedes, lc->n_sep_by_space, lc->n_sign_posn, L' ');
}
template<>
void
moneypunct_byname<wchar_t, true>::init(const char* nm)
{
typedef moneypunct<wchar_t, true> base;
__libcpp_unique_locale loc(nm);
if (!loc)
__throw_runtime_error("moneypunct_byname"
" failed to construct for " + string(nm));
lconv* lc = __libcpp_localeconv_l(loc.get());
if (!__checked_string_to_wchar_convert(__decimal_point_,
lc->mon_decimal_point,
loc.get()))
__decimal_point_ = base::do_decimal_point();
if (!__checked_string_to_wchar_convert(__thousands_sep_,
lc->mon_thousands_sep,
loc.get()))
__thousands_sep_ = base::do_thousands_sep();
__grouping_ = lc->mon_grouping;
wchar_t wbuf[100];
mbstate_t mb = {0};
const char* bb = lc->int_curr_symbol;
size_t j = __libcpp_mbsrtowcs_l(wbuf, &bb, countof(wbuf), &mb, loc.get());
if (j == size_t(-1))
__throw_runtime_error("locale not supported");
wchar_t* wbe = wbuf + j;
__curr_symbol_.assign(wbuf, wbe);
if (lc->int_frac_digits != CHAR_MAX)
__frac_digits_ = lc->int_frac_digits;
else
__frac_digits_ = base::do_frac_digits();
#if defined(_LIBCPP_MSVCRT) || defined(__MINGW32__)
if (lc->p_sign_posn == 0)
#else // _LIBCPP_MSVCRT
if (lc->int_p_sign_posn == 0)
#endif // !_LIBCPP_MSVCRT
__positive_sign_ = L"()";
else
{
mb = mbstate_t();
bb = lc->positive_sign;
j = __libcpp_mbsrtowcs_l(wbuf, &bb, countof(wbuf), &mb, loc.get());
if (j == size_t(-1))
__throw_runtime_error("locale not supported");
wbe = wbuf + j;
__positive_sign_.assign(wbuf, wbe);
}
#if defined(_LIBCPP_MSVCRT) || defined(__MINGW32__)
if (lc->n_sign_posn == 0)
#else // _LIBCPP_MSVCRT
if (lc->int_n_sign_posn == 0)
#endif // !_LIBCPP_MSVCRT
__negative_sign_ = L"()";
else
{
mb = mbstate_t();
bb = lc->negative_sign;
j = __libcpp_mbsrtowcs_l(wbuf, &bb, countof(wbuf), &mb, loc.get());
if (j == size_t(-1))
__throw_runtime_error("locale not supported");
wbe = wbuf + j;
__negative_sign_.assign(wbuf, wbe);
}
// Assume the positive and negative formats will want spaces in
// the same places in curr_symbol since there's no way to
// represent anything else.
string_type __dummy_curr_symbol = __curr_symbol_;
#if defined(_LIBCPP_MSVCRT) || defined(__MINGW32__)
__init_pat(__pos_format_, __dummy_curr_symbol, true,
lc->p_cs_precedes, lc->p_sep_by_space, lc->p_sign_posn, L' ');
__init_pat(__neg_format_, __curr_symbol_, true,
lc->n_cs_precedes, lc->n_sep_by_space, lc->n_sign_posn, L' ');
#else // _LIBCPP_MSVCRT
__init_pat(__pos_format_, __dummy_curr_symbol, true,
lc->int_p_cs_precedes, lc->int_p_sep_by_space,
lc->int_p_sign_posn, L' ');
__init_pat(__neg_format_, __curr_symbol_, true,
lc->int_n_cs_precedes, lc->int_n_sep_by_space,
lc->int_n_sign_posn, L' ');
#endif // !_LIBCPP_MSVCRT
}
template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS moneypunct<char, false>;
template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS moneypunct<char, true>;
template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS moneypunct<wchar_t, false>;
template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS moneypunct<wchar_t, true>;
template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS moneypunct_byname<char, false>;
template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS moneypunct_byname<char, true>;
template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS moneypunct_byname<wchar_t, false>;
template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS moneypunct_byname<wchar_t, true>;
template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS money_get<char>;
template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS money_get<wchar_t>;
template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS __money_get<char>;
template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS __money_get<wchar_t>;
template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS money_put<char>;
template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS money_put<wchar_t>;
template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS __money_put<char>;
template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS __money_put<wchar_t>;
_LIBCPP_END_NAMESPACE_STD
| 29,166 | 724 | jart/cosmopolitan | false |
cosmopolitan/third_party/libcxx/functional.cc | // clang-format off
//===----------------------- functional.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/functional"
_LIBCPP_BEGIN_NAMESPACE_STD
#ifdef _LIBCPP_ABI_BAD_FUNCTION_CALL_KEY_FUNCTION
bad_function_call::~bad_function_call() _NOEXCEPT
{
}
const char*
bad_function_call::what() const _NOEXCEPT
{
return "std::bad_function_call";
}
#endif
_LIBCPP_END_NAMESPACE_STD
| 695 | 27 | jart/cosmopolitan | false |
cosmopolitan/third_party/libcxx/streambuf | // -*- C++ -*-
//===------------------------- streambuf ----------------------------------===//
//
// 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_STEAMBUF
#define _LIBCPP_STEAMBUF
#include "third_party/libcxx/__config"
#include "third_party/libcxx/iosfwd"
#include "third_party/libcxx/ios"
#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
/*
streambuf synopsis
namespace std
{
template <class charT, class traits = char_traits<charT> >
class basic_streambuf
{
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;
virtual ~basic_streambuf();
// 27.6.2.2.1 locales:
locale pubimbue(const locale& loc);
locale getloc() const;
// 27.6.2.2.2 buffer and positioning:
basic_streambuf* pubsetbuf(char_type* s, streamsize n);
pos_type pubseekoff(off_type off, ios_base::seekdir way,
ios_base::openmode which = ios_base::in | ios_base::out);
pos_type pubseekpos(pos_type sp,
ios_base::openmode which = ios_base::in | ios_base::out);
int pubsync();
// Get and put areas:
// 27.6.2.2.3 Get area:
streamsize in_avail();
int_type snextc();
int_type sbumpc();
int_type sgetc();
streamsize sgetn(char_type* s, streamsize n);
// 27.6.2.2.4 Putback:
int_type sputbackc(char_type c);
int_type sungetc();
// 27.6.2.2.5 Put area:
int_type sputc(char_type c);
streamsize sputn(const char_type* s, streamsize n);
protected:
basic_streambuf();
basic_streambuf(const basic_streambuf& rhs);
basic_streambuf& operator=(const basic_streambuf& rhs);
void swap(basic_streambuf& rhs);
// 27.6.2.3.2 Get area:
char_type* eback() const;
char_type* gptr() const;
char_type* egptr() const;
void gbump(int n);
void setg(char_type* gbeg, char_type* gnext, char_type* gend);
// 27.6.2.3.3 Put area:
char_type* pbase() const;
char_type* pptr() const;
char_type* epptr() const;
void pbump(int n);
void setp(char_type* pbeg, char_type* pend);
// 27.6.2.4 virtual functions:
// 27.6.2.4.1 Locales:
virtual void imbue(const locale& loc);
// 27.6.2.4.2 Buffer management and positioning:
virtual basic_streambuf* 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();
// 27.6.2.4.3 Get area:
virtual streamsize showmanyc();
virtual streamsize xsgetn(char_type* s, streamsize n);
virtual int_type underflow();
virtual int_type uflow();
// 27.6.2.4.4 Putback:
virtual int_type pbackfail(int_type c = traits_type::eof());
// 27.6.2.4.5 Put area:
virtual streamsize xsputn(const char_type* s, streamsize n);
virtual int_type overflow (int_type c = traits_type::eof());
};
} // std
*/
template <class _CharT, class _Traits>
class _LIBCPP_TEMPLATE_VIS basic_streambuf
{
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");
virtual ~basic_streambuf();
// 27.6.2.2.1 locales:
inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1
locale pubimbue(const locale& __loc) {
imbue(__loc);
locale __r = __loc_;
__loc_ = __loc;
return __r;
}
inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1
locale getloc() const { return __loc_; }
// 27.6.2.2.2 buffer and positioning:
inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1
basic_streambuf* pubsetbuf(char_type* __s, streamsize __n)
{ return setbuf(__s, __n); }
inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1
pos_type pubseekoff(off_type __off, ios_base::seekdir __way,
ios_base::openmode __which = ios_base::in | ios_base::out)
{ return seekoff(__off, __way, __which); }
inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1
pos_type pubseekpos(pos_type __sp,
ios_base::openmode __which = ios_base::in | ios_base::out)
{ return seekpos(__sp, __which); }
inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1
int pubsync() { return sync(); }
// Get and put areas:
// 27.6.2.2.3 Get area:
inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1
streamsize in_avail() {
if (__ninp_ < __einp_)
return static_cast<streamsize>(__einp_ - __ninp_);
return showmanyc();
}
inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1
int_type snextc() {
if (sbumpc() == traits_type::eof())
return traits_type::eof();
return sgetc();
}
inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1
int_type sbumpc() {
if (__ninp_ == __einp_)
return uflow();
return traits_type::to_int_type(*__ninp_++);
}
inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1
int_type sgetc() {
if (__ninp_ == __einp_)
return underflow();
return traits_type::to_int_type(*__ninp_);
}
inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1
streamsize sgetn(char_type* __s, streamsize __n)
{ return xsgetn(__s, __n); }
// 27.6.2.2.4 Putback:
inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1
int_type sputbackc(char_type __c) {
if (__binp_ == __ninp_ || !traits_type::eq(__c, __ninp_[-1]))
return pbackfail(traits_type::to_int_type(__c));
return traits_type::to_int_type(*--__ninp_);
}
inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1
int_type sungetc() {
if (__binp_ == __ninp_)
return pbackfail();
return traits_type::to_int_type(*--__ninp_);
}
// 27.6.2.2.5 Put area:
inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1
int_type sputc(char_type __c) {
if (__nout_ == __eout_)
return overflow(traits_type::to_int_type(__c));
*__nout_++ = __c;
return traits_type::to_int_type(__c);
}
inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1
streamsize sputn(const char_type* __s, streamsize __n)
{ return xsputn(__s, __n); }
protected:
basic_streambuf();
basic_streambuf(const basic_streambuf& __rhs);
basic_streambuf& operator=(const basic_streambuf& __rhs);
void swap(basic_streambuf& __rhs);
// 27.6.2.3.2 Get area:
_LIBCPP_INLINE_VISIBILITY char_type* eback() const {return __binp_;}
_LIBCPP_INLINE_VISIBILITY char_type* gptr() const {return __ninp_;}
_LIBCPP_INLINE_VISIBILITY char_type* egptr() const {return __einp_;}
inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1
void gbump(int __n) { __ninp_ += __n; }
inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1
void setg(char_type* __gbeg, char_type* __gnext, char_type* __gend) {
__binp_ = __gbeg;
__ninp_ = __gnext;
__einp_ = __gend;
}
// 27.6.2.3.3 Put area:
_LIBCPP_INLINE_VISIBILITY char_type* pbase() const {return __bout_;}
_LIBCPP_INLINE_VISIBILITY char_type* pptr() const {return __nout_;}
_LIBCPP_INLINE_VISIBILITY char_type* epptr() const {return __eout_;}
inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1
void pbump(int __n) { __nout_ += __n; }
_LIBCPP_INLINE_VISIBILITY
void __pbump(streamsize __n) { __nout_ += __n; }
inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1
void setp(char_type* __pbeg, char_type* __pend) {
__bout_ = __nout_ = __pbeg;
__eout_ = __pend;
}
// 27.6.2.4 virtual functions:
// 27.6.2.4.1 Locales:
virtual void imbue(const locale& __loc);
// 27.6.2.4.2 Buffer management and positioning:
virtual basic_streambuf* 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();
// 27.6.2.4.3 Get area:
virtual streamsize showmanyc();
virtual streamsize xsgetn(char_type* __s, streamsize __n);
virtual int_type underflow();
virtual int_type uflow();
// 27.6.2.4.4 Putback:
virtual int_type pbackfail(int_type __c = traits_type::eof());
// 27.6.2.4.5 Put area:
virtual streamsize xsputn(const char_type* __s, streamsize __n);
virtual int_type overflow(int_type __c = traits_type::eof());
private:
locale __loc_;
char_type* __binp_;
char_type* __ninp_;
char_type* __einp_;
char_type* __bout_;
char_type* __nout_;
char_type* __eout_;
};
template <class _CharT, class _Traits>
basic_streambuf<_CharT, _Traits>::~basic_streambuf()
{
}
template <class _CharT, class _Traits>
basic_streambuf<_CharT, _Traits>::basic_streambuf()
: __binp_(0),
__ninp_(0),
__einp_(0),
__bout_(0),
__nout_(0),
__eout_(0)
{
}
template <class _CharT, class _Traits>
basic_streambuf<_CharT, _Traits>::basic_streambuf(const basic_streambuf& __sb)
: __loc_(__sb.__loc_),
__binp_(__sb.__binp_),
__ninp_(__sb.__ninp_),
__einp_(__sb.__einp_),
__bout_(__sb.__bout_),
__nout_(__sb.__nout_),
__eout_(__sb.__eout_)
{
}
template <class _CharT, class _Traits>
basic_streambuf<_CharT, _Traits>&
basic_streambuf<_CharT, _Traits>::operator=(const basic_streambuf& __sb)
{
__loc_ = __sb.__loc_;
__binp_ = __sb.__binp_;
__ninp_ = __sb.__ninp_;
__einp_ = __sb.__einp_;
__bout_ = __sb.__bout_;
__nout_ = __sb.__nout_;
__eout_ = __sb.__eout_;
return *this;
}
template <class _CharT, class _Traits>
void
basic_streambuf<_CharT, _Traits>::swap(basic_streambuf& __sb)
{
_VSTD::swap(__loc_, __sb.__loc_);
_VSTD::swap(__binp_, __sb.__binp_);
_VSTD::swap(__ninp_, __sb.__ninp_);
_VSTD::swap(__einp_, __sb.__einp_);
_VSTD::swap(__bout_, __sb.__bout_);
_VSTD::swap(__nout_, __sb.__nout_);
_VSTD::swap(__eout_, __sb.__eout_);
}
template <class _CharT, class _Traits>
void
basic_streambuf<_CharT, _Traits>::imbue(const locale&)
{
}
template <class _CharT, class _Traits>
basic_streambuf<_CharT, _Traits>*
basic_streambuf<_CharT, _Traits>::setbuf(char_type*, streamsize)
{
return this;
}
template <class _CharT, class _Traits>
typename basic_streambuf<_CharT, _Traits>::pos_type
basic_streambuf<_CharT, _Traits>::seekoff(off_type, ios_base::seekdir,
ios_base::openmode)
{
return pos_type(off_type(-1));
}
template <class _CharT, class _Traits>
typename basic_streambuf<_CharT, _Traits>::pos_type
basic_streambuf<_CharT, _Traits>::seekpos(pos_type, ios_base::openmode)
{
return pos_type(off_type(-1));
}
template <class _CharT, class _Traits>
int
basic_streambuf<_CharT, _Traits>::sync()
{
return 0;
}
template <class _CharT, class _Traits>
streamsize
basic_streambuf<_CharT, _Traits>::showmanyc()
{
return 0;
}
template <class _CharT, class _Traits>
streamsize
basic_streambuf<_CharT, _Traits>::xsgetn(char_type* __s, streamsize __n)
{
const int_type __eof = traits_type::eof();
int_type __c;
streamsize __i = 0;
while(__i < __n)
{
if (__ninp_ < __einp_)
{
const streamsize __len = _VSTD::min(static_cast<streamsize>(INT_MAX),
_VSTD::min(__einp_ - __ninp_, __n - __i));
traits_type::copy(__s, __ninp_, __len);
__s += __len;
__i += __len;
this->gbump(__len);
}
else if ((__c = uflow()) != __eof)
{
*__s = traits_type::to_char_type(__c);
++__s;
++__i;
}
else
break;
}
return __i;
}
template <class _CharT, class _Traits>
typename basic_streambuf<_CharT, _Traits>::int_type
basic_streambuf<_CharT, _Traits>::underflow()
{
return traits_type::eof();
}
template <class _CharT, class _Traits>
typename basic_streambuf<_CharT, _Traits>::int_type
basic_streambuf<_CharT, _Traits>::uflow()
{
if (underflow() == traits_type::eof())
return traits_type::eof();
return traits_type::to_int_type(*__ninp_++);
}
template <class _CharT, class _Traits>
typename basic_streambuf<_CharT, _Traits>::int_type
basic_streambuf<_CharT, _Traits>::pbackfail(int_type)
{
return traits_type::eof();
}
template <class _CharT, class _Traits>
streamsize
basic_streambuf<_CharT, _Traits>::xsputn(const char_type* __s, streamsize __n)
{
streamsize __i = 0;
int_type __eof = traits_type::eof();
while( __i < __n)
{
if (__nout_ >= __eout_)
{
if (overflow(traits_type::to_int_type(*__s)) == __eof)
break;
++__s;
++__i;
}
else
{
streamsize __chunk_size = _VSTD::min(__eout_ - __nout_, __n - __i);
traits_type::copy(__nout_, __s, __chunk_size);
__nout_ += __chunk_size;
__s += __chunk_size;
__i += __chunk_size;
}
}
return __i;
}
template <class _CharT, class _Traits>
typename basic_streambuf<_CharT, _Traits>::int_type
basic_streambuf<_CharT, _Traits>::overflow(int_type)
{
return traits_type::eof();
}
#ifndef _LIBCPP_DO_NOT_ASSUME_STREAMS_EXPLICIT_INSTANTIATION_IN_DYLIB
_LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_streambuf<char>)
_LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_streambuf<wchar_t>)
_LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_ios<char>)
_LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_ios<wchar_t>)
#endif
_LIBCPP_END_NAMESPACE_STD
_LIBCPP_POP_MACROS
#endif // _LIBCPP_STEAMBUF
| 14,592 | 501 | jart/cosmopolitan | false |
cosmopolitan/third_party/libcxx/codecvt | // -*- C++ -*-
// clang-format off
//===-------------------------- codecvt -----------------------------------===//
//
// 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_CODECVT
#define _LIBCPP_CODECVT
#include "third_party/libcxx/__config"
#include "third_party/libcxx/__locale"
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
#pragma GCC system_header
#endif
_LIBCPP_BEGIN_NAMESPACE_STD
/*
codecvt synopsis
namespace std
{
enum codecvt_mode
{
consume_header = 4,
generate_header = 2,
little_endian = 1
};
template <class Elem, unsigned long Maxcode = 0x10ffff,
codecvt_mode Mode = (codecvt_mode)0>
class codecvt_utf8
: public codecvt<Elem, char, mbstate_t>
{
explicit codecvt_utf8(size_t refs = 0);
~codecvt_utf8();
};
template <class Elem, unsigned long Maxcode = 0x10ffff,
codecvt_mode Mode = (codecvt_mode)0>
class codecvt_utf16
: public codecvt<Elem, char, mbstate_t>
{
explicit codecvt_utf16(size_t refs = 0);
~codecvt_utf16();
};
template <class Elem, unsigned long Maxcode = 0x10ffff,
codecvt_mode Mode = (codecvt_mode)0>
class codecvt_utf8_utf16
: public codecvt<Elem, char, mbstate_t>
{
explicit codecvt_utf8_utf16(size_t refs = 0);
~codecvt_utf8_utf16();
};
} // std
*/
enum codecvt_mode
{
consume_header = 4,
generate_header = 2,
little_endian = 1
};
// codecvt_utf8
template <class _Elem> class __codecvt_utf8;
template <>
class _LIBCPP_TYPE_VIS __codecvt_utf8<wchar_t>
: public codecvt<wchar_t, char, mbstate_t>
{
unsigned long _Maxcode_;
codecvt_mode _Mode_;
public:
typedef wchar_t intern_type;
typedef char extern_type;
typedef mbstate_t state_type;
_LIBCPP_INLINE_VISIBILITY
explicit __codecvt_utf8(size_t __refs, unsigned long _Maxcode,
codecvt_mode _Mode)
: codecvt<wchar_t, char, mbstate_t>(__refs), _Maxcode_(_Maxcode),
_Mode_(_Mode) {}
protected:
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 throw();
virtual bool do_always_noconv() const throw();
virtual int do_length(state_type&, const extern_type* __frm, const extern_type* __end,
size_t __mx) const;
virtual int do_max_length() const throw();
};
template <>
class _LIBCPP_TYPE_VIS __codecvt_utf8<char16_t>
: public codecvt<char16_t, char, mbstate_t>
{
unsigned long _Maxcode_;
codecvt_mode _Mode_;
public:
typedef char16_t intern_type;
typedef char extern_type;
typedef mbstate_t state_type;
_LIBCPP_INLINE_VISIBILITY
explicit __codecvt_utf8(size_t __refs, unsigned long _Maxcode,
codecvt_mode _Mode)
: codecvt<char16_t, char, mbstate_t>(__refs), _Maxcode_(_Maxcode),
_Mode_(_Mode) {}
protected:
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 throw();
virtual bool do_always_noconv() const throw();
virtual int do_length(state_type&, const extern_type* __frm, const extern_type* __end,
size_t __mx) const;
virtual int do_max_length() const throw();
};
template <>
class _LIBCPP_TYPE_VIS __codecvt_utf8<char32_t>
: public codecvt<char32_t, char, mbstate_t>
{
unsigned long _Maxcode_;
codecvt_mode _Mode_;
public:
typedef char32_t intern_type;
typedef char extern_type;
typedef mbstate_t state_type;
_LIBCPP_INLINE_VISIBILITY
explicit __codecvt_utf8(size_t __refs, unsigned long _Maxcode,
codecvt_mode _Mode)
: codecvt<char32_t, char, mbstate_t>(__refs), _Maxcode_(_Maxcode),
_Mode_(_Mode) {}
protected:
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 throw();
virtual bool do_always_noconv() const throw();
virtual int do_length(state_type&, const extern_type* __frm, const extern_type* __end,
size_t __mx) const;
virtual int do_max_length() const throw();
};
template <class _Elem, unsigned long _Maxcode = 0x10ffff,
codecvt_mode _Mode = (codecvt_mode)0>
class _LIBCPP_TEMPLATE_VIS codecvt_utf8
: public __codecvt_utf8<_Elem>
{
public:
_LIBCPP_INLINE_VISIBILITY
explicit codecvt_utf8(size_t __refs = 0)
: __codecvt_utf8<_Elem>(__refs, _Maxcode, _Mode) {}
_LIBCPP_INLINE_VISIBILITY
~codecvt_utf8() {}
};
// codecvt_utf16
template <class _Elem, bool _LittleEndian> class __codecvt_utf16;
template <>
class _LIBCPP_TYPE_VIS __codecvt_utf16<wchar_t, false>
: public codecvt<wchar_t, char, mbstate_t>
{
unsigned long _Maxcode_;
codecvt_mode _Mode_;
public:
typedef wchar_t intern_type;
typedef char extern_type;
typedef mbstate_t state_type;
_LIBCPP_INLINE_VISIBILITY
explicit __codecvt_utf16(size_t __refs, unsigned long _Maxcode,
codecvt_mode _Mode)
: codecvt<wchar_t, char, mbstate_t>(__refs), _Maxcode_(_Maxcode),
_Mode_(_Mode) {}
protected:
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 throw();
virtual bool do_always_noconv() const throw();
virtual int do_length(state_type&, const extern_type* __frm, const extern_type* __end,
size_t __mx) const;
virtual int do_max_length() const throw();
};
template <>
class _LIBCPP_TYPE_VIS __codecvt_utf16<wchar_t, true>
: public codecvt<wchar_t, char, mbstate_t>
{
unsigned long _Maxcode_;
codecvt_mode _Mode_;
public:
typedef wchar_t intern_type;
typedef char extern_type;
typedef mbstate_t state_type;
_LIBCPP_INLINE_VISIBILITY
explicit __codecvt_utf16(size_t __refs, unsigned long _Maxcode,
codecvt_mode _Mode)
: codecvt<wchar_t, char, mbstate_t>(__refs), _Maxcode_(_Maxcode),
_Mode_(_Mode) {}
protected:
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 throw();
virtual bool do_always_noconv() const throw();
virtual int do_length(state_type&, const extern_type* __frm, const extern_type* __end,
size_t __mx) const;
virtual int do_max_length() const throw();
};
template <>
class _LIBCPP_TYPE_VIS __codecvt_utf16<char16_t, false>
: public codecvt<char16_t, char, mbstate_t>
{
unsigned long _Maxcode_;
codecvt_mode _Mode_;
public:
typedef char16_t intern_type;
typedef char extern_type;
typedef mbstate_t state_type;
_LIBCPP_INLINE_VISIBILITY
explicit __codecvt_utf16(size_t __refs, unsigned long _Maxcode,
codecvt_mode _Mode)
: codecvt<char16_t, char, mbstate_t>(__refs), _Maxcode_(_Maxcode),
_Mode_(_Mode) {}
protected:
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 throw();
virtual bool do_always_noconv() const throw();
virtual int do_length(state_type&, const extern_type* __frm, const extern_type* __end,
size_t __mx) const;
virtual int do_max_length() const throw();
};
template <>
class _LIBCPP_TYPE_VIS __codecvt_utf16<char16_t, true>
: public codecvt<char16_t, char, mbstate_t>
{
unsigned long _Maxcode_;
codecvt_mode _Mode_;
public:
typedef char16_t intern_type;
typedef char extern_type;
typedef mbstate_t state_type;
_LIBCPP_INLINE_VISIBILITY
explicit __codecvt_utf16(size_t __refs, unsigned long _Maxcode,
codecvt_mode _Mode)
: codecvt<char16_t, char, mbstate_t>(__refs), _Maxcode_(_Maxcode),
_Mode_(_Mode) {}
protected:
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 throw();
virtual bool do_always_noconv() const throw();
virtual int do_length(state_type&, const extern_type* __frm, const extern_type* __end,
size_t __mx) const;
virtual int do_max_length() const throw();
};
template <>
class _LIBCPP_TYPE_VIS __codecvt_utf16<char32_t, false>
: public codecvt<char32_t, char, mbstate_t>
{
unsigned long _Maxcode_;
codecvt_mode _Mode_;
public:
typedef char32_t intern_type;
typedef char extern_type;
typedef mbstate_t state_type;
_LIBCPP_INLINE_VISIBILITY
explicit __codecvt_utf16(size_t __refs, unsigned long _Maxcode,
codecvt_mode _Mode)
: codecvt<char32_t, char, mbstate_t>(__refs), _Maxcode_(_Maxcode),
_Mode_(_Mode) {}
protected:
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 throw();
virtual bool do_always_noconv() const throw();
virtual int do_length(state_type&, const extern_type* __frm, const extern_type* __end,
size_t __mx) const;
virtual int do_max_length() const throw();
};
template <>
class _LIBCPP_TYPE_VIS __codecvt_utf16<char32_t, true>
: public codecvt<char32_t, char, mbstate_t>
{
unsigned long _Maxcode_;
codecvt_mode _Mode_;
public:
typedef char32_t intern_type;
typedef char extern_type;
typedef mbstate_t state_type;
_LIBCPP_INLINE_VISIBILITY
explicit __codecvt_utf16(size_t __refs, unsigned long _Maxcode,
codecvt_mode _Mode)
: codecvt<char32_t, char, mbstate_t>(__refs), _Maxcode_(_Maxcode),
_Mode_(_Mode) {}
protected:
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 throw();
virtual bool do_always_noconv() const throw();
virtual int do_length(state_type&, const extern_type* __frm, const extern_type* __end,
size_t __mx) const;
virtual int do_max_length() const throw();
};
template <class _Elem, unsigned long _Maxcode = 0x10ffff,
codecvt_mode _Mode = (codecvt_mode)0>
class _LIBCPP_TEMPLATE_VIS codecvt_utf16
: public __codecvt_utf16<_Elem, _Mode & little_endian>
{
public:
_LIBCPP_INLINE_VISIBILITY
explicit codecvt_utf16(size_t __refs = 0)
: __codecvt_utf16<_Elem, _Mode & little_endian>(__refs, _Maxcode, _Mode) {}
_LIBCPP_INLINE_VISIBILITY
~codecvt_utf16() {}
};
// codecvt_utf8_utf16
template <class _Elem> class __codecvt_utf8_utf16;
template <>
class _LIBCPP_TYPE_VIS __codecvt_utf8_utf16<wchar_t>
: public codecvt<wchar_t, char, mbstate_t>
{
unsigned long _Maxcode_;
codecvt_mode _Mode_;
public:
typedef wchar_t intern_type;
typedef char extern_type;
typedef mbstate_t state_type;
_LIBCPP_INLINE_VISIBILITY
explicit __codecvt_utf8_utf16(size_t __refs, unsigned long _Maxcode,
codecvt_mode _Mode)
: codecvt<wchar_t, char, mbstate_t>(__refs), _Maxcode_(_Maxcode),
_Mode_(_Mode) {}
protected:
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 throw();
virtual bool do_always_noconv() const throw();
virtual int do_length(state_type&, const extern_type* __frm, const extern_type* __end,
size_t __mx) const;
virtual int do_max_length() const throw();
};
template <>
class _LIBCPP_TYPE_VIS __codecvt_utf8_utf16<char32_t>
: public codecvt<char32_t, char, mbstate_t>
{
unsigned long _Maxcode_;
codecvt_mode _Mode_;
public:
typedef char32_t intern_type;
typedef char extern_type;
typedef mbstate_t state_type;
_LIBCPP_INLINE_VISIBILITY
explicit __codecvt_utf8_utf16(size_t __refs, unsigned long _Maxcode,
codecvt_mode _Mode)
: codecvt<char32_t, char, mbstate_t>(__refs), _Maxcode_(_Maxcode),
_Mode_(_Mode) {}
protected:
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 throw();
virtual bool do_always_noconv() const throw();
virtual int do_length(state_type&, const extern_type* __frm, const extern_type* __end,
size_t __mx) const;
virtual int do_max_length() const throw();
};
template <>
class _LIBCPP_TYPE_VIS __codecvt_utf8_utf16<char16_t>
: public codecvt<char16_t, char, mbstate_t>
{
unsigned long _Maxcode_;
codecvt_mode _Mode_;
public:
typedef char16_t intern_type;
typedef char extern_type;
typedef mbstate_t state_type;
_LIBCPP_INLINE_VISIBILITY
explicit __codecvt_utf8_utf16(size_t __refs, unsigned long _Maxcode,
codecvt_mode _Mode)
: codecvt<char16_t, char, mbstate_t>(__refs), _Maxcode_(_Maxcode),
_Mode_(_Mode) {}
protected:
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 throw();
virtual bool do_always_noconv() const throw();
virtual int do_length(state_type&, const extern_type* __frm, const extern_type* __end,
size_t __mx) const;
virtual int do_max_length() const throw();
};
template <class _Elem, unsigned long _Maxcode = 0x10ffff,
codecvt_mode _Mode = (codecvt_mode)0>
class _LIBCPP_TEMPLATE_VIS codecvt_utf8_utf16
: public __codecvt_utf8_utf16<_Elem>
{
public:
_LIBCPP_INLINE_VISIBILITY
explicit codecvt_utf8_utf16(size_t __refs = 0)
: __codecvt_utf8_utf16<_Elem>(__refs, _Maxcode, _Mode) {}
_LIBCPP_INLINE_VISIBILITY
~codecvt_utf8_utf16() {}
};
_LIBCPP_END_NAMESPACE_STD
#endif // _LIBCPP_CODECVT
| 20,586 | 551 | jart/cosmopolitan | false |
cosmopolitan/third_party/libcxx/exception_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/exception"
#include "third_party/libcxx/cstdio"
#include "third_party/libcxx/atomic_support.hh"
namespace std {
_LIBCPP_SAFE_STATIC static std::terminate_handler __terminate_handler;
#if _LIBCPP_STD_VER <= 14 || \
defined(_LIBCPP_ENABLE_CXX17_REMOVED_UNEXPECTED_FUNCTIONS) || \
defined(_LIBCPP_BUILDING_LIBRARY)
_LIBCPP_SAFE_STATIC static std::unexpected_handler __unexpected_handler;
// libcxxrt provides implementations of these functions itself.
unexpected_handler set_unexpected(unexpected_handler func) _NOEXCEPT {
return __libcpp_atomic_exchange(&__unexpected_handler, func);
}
unexpected_handler get_unexpected() _NOEXCEPT {
return __libcpp_atomic_load(&__unexpected_handler);
}
_LIBCPP_NORETURN
void unexpected() {
(*get_unexpected())();
// unexpected handler should not return
terminate();
}
#endif
terminate_handler set_terminate(terminate_handler func) _NOEXCEPT {
return __libcpp_atomic_exchange(&__terminate_handler, func);
}
terminate_handler get_terminate() _NOEXCEPT {
return __libcpp_atomic_load(&__terminate_handler);
}
#ifndef __EMSCRIPTEN__ // We provide this in JS
_LIBCPP_NORETURN
void terminate() _NOEXCEPT {
#ifndef _LIBCPP_NO_EXCEPTIONS
try {
#endif // _LIBCPP_NO_EXCEPTIONS
(*get_terminate())();
// handler should not return
fprintf(stderr, "terminate_handler unexpectedly returned\n");
::abort();
#ifndef _LIBCPP_NO_EXCEPTIONS
} catch (...) {
// handler should not throw exception
fprintf(stderr, "terminate_handler unexpectedly threw an exception\n");
::abort();
}
#endif // _LIBCPP_NO_EXCEPTIONS
}
#endif // !__EMSCRIPTEN__
#if !defined(__EMSCRIPTEN__)
bool uncaught_exception() _NOEXCEPT { return uncaught_exceptions() > 0; }
int uncaught_exceptions() _NOEXCEPT {
// #warning uncaught_exception not yet implemented
fprintf(stderr, "uncaught_exceptions not yet implemented\n");
::abort();
}
#endif // !__EMSCRIPTEN__
exception::~exception() _NOEXCEPT {}
const char* exception::what() const _NOEXCEPT { return "std::exception"; }
bad_exception::~bad_exception() _NOEXCEPT {}
const char* bad_exception::what() const _NOEXCEPT {
return "std::bad_exception";
}
bad_alloc::bad_alloc() _NOEXCEPT {}
bad_alloc::~bad_alloc() _NOEXCEPT {}
const char* bad_alloc::what() const _NOEXCEPT { return "std::bad_alloc"; }
bad_array_new_length::bad_array_new_length() _NOEXCEPT {}
bad_array_new_length::~bad_array_new_length() _NOEXCEPT {}
const char* bad_array_new_length::what() const _NOEXCEPT {
return "bad_array_new_length";
}
bad_cast::bad_cast() _NOEXCEPT {}
bad_typeid::bad_typeid() _NOEXCEPT {}
bad_cast::~bad_cast() _NOEXCEPT {}
const char* bad_cast::what() const _NOEXCEPT { return "std::bad_cast"; }
bad_typeid::~bad_typeid() _NOEXCEPT {}
const char* bad_typeid::what() const _NOEXCEPT { return "std::bad_typeid"; }
} // namespace std
| 3,326 | 112 | jart/cosmopolitan | false |
cosmopolitan/third_party/libcxx/__nullptr | // -*- C++ -*-
//===--------------------------- __nullptr --------------------------------===//
//
// 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_NULLPTR
#define _LIBCPP_NULLPTR
#include "third_party/libcxx/__config"
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
#pragma GCC system_header
#endif
#ifdef _LIBCPP_HAS_NO_NULLPTR
_LIBCPP_BEGIN_NAMESPACE_STD
struct _LIBCPP_TEMPLATE_VIS nullptr_t
{
void* __lx;
struct __nat {int __for_bool_;};
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR nullptr_t() : __lx(0) {}
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR nullptr_t(int __nat::*) : __lx(0) {}
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR operator int __nat::*() const {return 0;}
template <class _Tp>
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
operator _Tp* () const {return 0;}
template <class _Tp, class _Up>
_LIBCPP_INLINE_VISIBILITY
operator _Tp _Up::* () const {return 0;}
friend _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR bool operator==(nullptr_t, nullptr_t) {return true;}
friend _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR bool operator!=(nullptr_t, nullptr_t) {return false;}
};
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR nullptr_t __get_nullptr_t() {return nullptr_t(0);}
#define nullptr _VSTD::__get_nullptr_t()
_LIBCPP_END_NAMESPACE_STD
#else // _LIBCPP_HAS_NO_NULLPTR
namespace std
{
typedef decltype(nullptr) nullptr_t;
}
#endif // _LIBCPP_HAS_NO_NULLPTR
#endif // _LIBCPP_NULLPTR
| 1,753 | 62 | jart/cosmopolitan | false |
cosmopolitan/third_party/libcxx/typeindex | // -*- C++ -*-
// clang-format off
//===-------------------------- typeindex ---------------------------------===//
//
// 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_TYPEINDEX
#define _LIBCPP_TYPEINDEX
/*
typeindex synopsis
namespace std
{
class type_index
{
public:
type_index(const type_info& rhs) noexcept;
bool operator==(const type_index& rhs) const noexcept;
bool operator!=(const type_index& rhs) const noexcept;
bool operator< (const type_index& rhs) const noexcept;
bool operator<=(const type_index& rhs) const noexcept;
bool operator> (const type_index& rhs) const noexcept;
bool operator>=(const type_index& rhs) const noexcept;
size_t hash_code() const noexcept;
const char* name() const noexcept;
};
template <>
struct hash<type_index>
: public unary_function<type_index, size_t>
{
size_t operator()(type_index index) const noexcept;
};
} // std
*/
#include "third_party/libcxx/__config"
#include "third_party/libcxx/typeinfo"
#include "third_party/libcxx/__functional_base"
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
#pragma GCC system_header
#endif
_LIBCPP_BEGIN_NAMESPACE_STD
class _LIBCPP_TEMPLATE_VIS type_index
{
const type_info* __t_;
public:
_LIBCPP_INLINE_VISIBILITY
type_index(const type_info& __y) _NOEXCEPT : __t_(&__y) {}
_LIBCPP_INLINE_VISIBILITY
bool operator==(const type_index& __y) const _NOEXCEPT
{return *__t_ == *__y.__t_;}
_LIBCPP_INLINE_VISIBILITY
bool operator!=(const type_index& __y) const _NOEXCEPT
{return *__t_ != *__y.__t_;}
_LIBCPP_INLINE_VISIBILITY
bool operator< (const type_index& __y) const _NOEXCEPT
{return __t_->before(*__y.__t_);}
_LIBCPP_INLINE_VISIBILITY
bool operator<=(const type_index& __y) const _NOEXCEPT
{return !__y.__t_->before(*__t_);}
_LIBCPP_INLINE_VISIBILITY
bool operator> (const type_index& __y) const _NOEXCEPT
{return __y.__t_->before(*__t_);}
_LIBCPP_INLINE_VISIBILITY
bool operator>=(const type_index& __y) const _NOEXCEPT
{return !__t_->before(*__y.__t_);}
_LIBCPP_INLINE_VISIBILITY
size_t hash_code() const _NOEXCEPT {return __t_->hash_code();}
_LIBCPP_INLINE_VISIBILITY
const char* name() const _NOEXCEPT {return __t_->name();}
};
template <class _Tp> struct _LIBCPP_TEMPLATE_VIS hash;
template <>
struct _LIBCPP_TEMPLATE_VIS hash<type_index>
: public unary_function<type_index, size_t>
{
_LIBCPP_INLINE_VISIBILITY
size_t operator()(type_index __index) const _NOEXCEPT
{return __index.hash_code();}
};
_LIBCPP_END_NAMESPACE_STD
#endif // _LIBCPP_TYPEINDEX
| 2,908 | 104 | jart/cosmopolitan | false |
cosmopolitan/third_party/libcxx/regex.cc | // clang-format off
//===-------------------------- regex.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/regex"
#include "third_party/libcxx/algorithm"
#include "third_party/libcxx/iterator"
_LIBCPP_BEGIN_NAMESPACE_STD
static
const char*
make_error_type_string(regex_constants::error_type ecode)
{
switch (ecode)
{
case regex_constants::error_collate:
return "The expression contained an invalid collating element name.";
case regex_constants::error_ctype:
return "The expression contained an invalid character class name.";
case regex_constants::error_escape:
return "The expression contained an invalid escaped character, or a "
"trailing escape.";
case regex_constants::error_backref:
return "The expression contained an invalid back reference.";
case regex_constants::error_brack:
return "The expression contained mismatched [ and ].";
case regex_constants::error_paren:
return "The expression contained mismatched ( and ).";
case regex_constants::error_brace:
return "The expression contained mismatched { and }.";
case regex_constants::error_badbrace:
return "The expression contained an invalid range in a {} expression.";
case regex_constants::error_range:
return "The expression contained an invalid character range, "
"such as [b-a] in most encodings.";
case regex_constants::error_space:
return "There was insufficient memory to convert the expression into "
"a finite state machine.";
case regex_constants::error_badrepeat:
return "One of *?+{ was not preceded by a valid regular expression.";
case regex_constants::error_complexity:
return "The complexity of an attempted match against a regular "
"expression exceeded a pre-set level.";
case regex_constants::error_stack:
return "There was insufficient memory to determine whether the regular "
"expression could match the specified character sequence.";
case regex_constants::__re_err_grammar:
return "An invalid regex grammar has been requested.";
case regex_constants::__re_err_empty:
return "An empty regex is not allowed in the POSIX grammar.";
default:
break;
}
return "Unknown error type";
}
regex_error::regex_error(regex_constants::error_type ecode)
: runtime_error(make_error_type_string(ecode)),
__code_(ecode)
{}
regex_error::~regex_error() throw() {}
namespace {
struct collationnames
{
const char* elem_;
char char_;
};
const collationnames collatenames[] =
{
{"A", 0x41},
{"B", 0x42},
{"C", 0x43},
{"D", 0x44},
{"E", 0x45},
{"F", 0x46},
{"G", 0x47},
{"H", 0x48},
{"I", 0x49},
{"J", 0x4a},
{"K", 0x4b},
{"L", 0x4c},
{"M", 0x4d},
{"N", 0x4e},
{"NUL", 0x00},
{"O", 0x4f},
{"P", 0x50},
{"Q", 0x51},
{"R", 0x52},
{"S", 0x53},
{"T", 0x54},
{"U", 0x55},
{"V", 0x56},
{"W", 0x57},
{"X", 0x58},
{"Y", 0x59},
{"Z", 0x5a},
{"a", 0x61},
{"alert", 0x07},
{"ampersand", 0x26},
{"apostrophe", 0x27},
{"asterisk", 0x2a},
{"b", 0x62},
{"backslash", 0x5c},
{"backspace", 0x08},
{"c", 0x63},
{"carriage-return", 0x0d},
{"circumflex", 0x5e},
{"circumflex-accent", 0x5e},
{"colon", 0x3a},
{"comma", 0x2c},
{"commercial-at", 0x40},
{"d", 0x64},
{"dollar-sign", 0x24},
{"e", 0x65},
{"eight", 0x38},
{"equals-sign", 0x3d},
{"exclamation-mark", 0x21},
{"f", 0x66},
{"five", 0x35},
{"form-feed", 0x0c},
{"four", 0x34},
{"full-stop", 0x2e},
{"g", 0x67},
{"grave-accent", 0x60},
{"greater-than-sign", 0x3e},
{"h", 0x68},
{"hyphen", 0x2d},
{"hyphen-minus", 0x2d},
{"i", 0x69},
{"j", 0x6a},
{"k", 0x6b},
{"l", 0x6c},
{"left-brace", 0x7b},
{"left-curly-bracket", 0x7b},
{"left-parenthesis", 0x28},
{"left-square-bracket", 0x5b},
{"less-than-sign", 0x3c},
{"low-line", 0x5f},
{"m", 0x6d},
{"n", 0x6e},
{"newline", 0x0a},
{"nine", 0x39},
{"number-sign", 0x23},
{"o", 0x6f},
{"one", 0x31},
{"p", 0x70},
{"percent-sign", 0x25},
{"period", 0x2e},
{"plus-sign", 0x2b},
{"q", 0x71},
{"question-mark", 0x3f},
{"quotation-mark", 0x22},
{"r", 0x72},
{"reverse-solidus", 0x5c},
{"right-brace", 0x7d},
{"right-curly-bracket", 0x7d},
{"right-parenthesis", 0x29},
{"right-square-bracket", 0x5d},
{"s", 0x73},
{"semicolon", 0x3b},
{"seven", 0x37},
{"six", 0x36},
{"slash", 0x2f},
{"solidus", 0x2f},
{"space", 0x20},
{"t", 0x74},
{"tab", 0x09},
{"three", 0x33},
{"tilde", 0x7e},
{"two", 0x32},
{"u", 0x75},
{"underscore", 0x5f},
{"v", 0x76},
{"vertical-line", 0x7c},
{"vertical-tab", 0x0b},
{"w", 0x77},
{"x", 0x78},
{"y", 0x79},
{"z", 0x7a},
{"zero", 0x30}
};
struct classnames
{
const char* elem_;
regex_traits<char>::char_class_type mask_;
};
const classnames ClassNames[] =
{
{"alnum", ctype_base::alnum},
{"alpha", ctype_base::alpha},
{"blank", ctype_base::blank},
{"cntrl", ctype_base::cntrl},
{"d", ctype_base::digit},
{"digit", ctype_base::digit},
{"graph", ctype_base::graph},
{"lower", ctype_base::lower},
{"print", ctype_base::print},
{"punct", ctype_base::punct},
{"s", ctype_base::space},
{"space", ctype_base::space},
{"upper", ctype_base::upper},
{"w", regex_traits<char>::__regex_word},
{"xdigit", ctype_base::xdigit}
};
struct use_strcmp
{
bool operator()(const collationnames& x, const char* y)
{return strcmp(x.elem_, y) < 0;}
bool operator()(const classnames& x, const char* y)
{return strcmp(x.elem_, y) < 0;}
};
}
string
__get_collation_name(const char* s)
{
const collationnames* i =
_VSTD::lower_bound(begin(collatenames), end(collatenames), s, use_strcmp());
string r;
if (i != end(collatenames) && strcmp(s, i->elem_) == 0)
r = char(i->char_);
return r;
}
regex_traits<char>::char_class_type
__get_classname(const char* s, bool __icase)
{
const classnames* i =
_VSTD::lower_bound(begin(ClassNames), end(ClassNames), s, use_strcmp());
regex_traits<char>::char_class_type r = 0;
if (i != end(ClassNames) && strcmp(s, i->elem_) == 0)
{
r = i->mask_;
if (r == regex_traits<char>::__regex_word)
r |= ctype_base::alnum | ctype_base::upper | ctype_base::lower;
else if (__icase)
{
if (r & (ctype_base::lower | ctype_base::upper))
r |= ctype_base::alpha;
}
}
return r;
}
template <>
void
__match_any_but_newline<char>::__exec(__state& __s) const
{
if (__s.__current_ != __s.__last_)
{
switch (*__s.__current_)
{
case '\r':
case '\n':
__s.__do_ = __state::__reject;
__s.__node_ = nullptr;
break;
default:
__s.__do_ = __state::__accept_and_consume;
++__s.__current_;
__s.__node_ = this->first();
break;
}
}
else
{
__s.__do_ = __state::__reject;
__s.__node_ = nullptr;
}
}
template <>
void
__match_any_but_newline<wchar_t>::__exec(__state& __s) const
{
if (__s.__current_ != __s.__last_)
{
switch (*__s.__current_)
{
case '\r':
case '\n':
case 0x2028:
case 0x2029:
__s.__do_ = __state::__reject;
__s.__node_ = nullptr;
break;
default:
__s.__do_ = __state::__accept_and_consume;
++__s.__current_;
__s.__node_ = this->first();
break;
}
}
else
{
__s.__do_ = __state::__reject;
__s.__node_ = nullptr;
}
}
_LIBCPP_END_NAMESPACE_STD
| 8,379 | 316 | jart/cosmopolitan | false |
cosmopolitan/third_party/libcxx/cfenv | // -*- C++ -*-
// clang-format off
//===---------------------------- cfenv -----------------------------------===//
//
// 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_CFENV
#define _LIBCPP_CFENV
/*
cfenv synopsis
This entire header is C99 / C++0X
Macros:
FE_DIVBYZERO
FE_INEXACT
FE_INVALID
FE_OVERFLOW
FE_UNDERFLOW
FE_ALL_EXCEPT
FE_DOWNWARD
FE_TONEAREST
FE_TOWARDZERO
FE_UPWARD
FE_DFL_ENV
namespace std
{
Types:
fenv_t
fexcept_t
int feclearexcept(int excepts);
int fegetexceptflag(fexcept_t* flagp, int excepts);
int feraiseexcept(int excepts);
int fesetexceptflag(const fexcept_t* flagp, int excepts);
int fetestexcept(int excepts);
int fegetround();
int fesetround(int round);
int fegetenv(fenv_t* envp);
int feholdexcept(fenv_t* envp);
int fesetenv(const fenv_t* envp);
int feupdateenv(const fenv_t* envp);
} // std
*/
#include "third_party/libcxx/__config"
#include "libc/runtime/fenv.h"
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
#pragma GCC system_header
#endif
_LIBCPP_BEGIN_NAMESPACE_STD
using ::fenv_t;
using ::fexcept_t;
using ::feclearexcept;
using ::fegetexceptflag;
using ::feraiseexcept;
using ::fesetexceptflag;
using ::fetestexcept;
using ::fegetround;
using ::fesetround;
using ::fegetenv;
using ::feholdexcept;
using ::fesetenv;
using ::feupdateenv;
_LIBCPP_END_NAMESPACE_STD
#endif // _LIBCPP_CFENV
| 1,653 | 83 | jart/cosmopolitan | false |
cosmopolitan/third_party/libcxx/unordered_map | // -*- C++ -*-
//===-------------------------- unordered_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_UNORDERED_MAP
#define _LIBCPP_UNORDERED_MAP
#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/stdexcept"
#include "third_party/libcxx/tuple"
#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_map synopsis
#include "third_party/libcxx/initializer_list"
namespace std
{
template <class Key, class T, class Hash = hash<Key>, class Pred = equal_to<Key>,
class Alloc = allocator<pair<const Key, T>>>
class unordered_map
{
public:
// types
typedef Key key_type;
typedef T mapped_type;
typedef Hash hasher;
typedef Pred key_equal;
typedef Alloc allocator_type;
typedef pair<const key_type, mapped_type> value_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; // C++17
typedef INSERT_RETURN_TYPE<iterator, node_type> insert_return_type; // C++17
unordered_map()
noexcept(
is_nothrow_default_constructible<hasher>::value &&
is_nothrow_default_constructible<key_equal>::value &&
is_nothrow_default_constructible<allocator_type>::value);
explicit unordered_map(size_type n, const hasher& hf = hasher(),
const key_equal& eql = key_equal(),
const allocator_type& a = allocator_type());
template <class InputIterator>
unordered_map(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_map(const allocator_type&);
unordered_map(const unordered_map&);
unordered_map(const unordered_map&, const Allocator&);
unordered_map(unordered_map&&)
noexcept(
is_nothrow_move_constructible<hasher>::value &&
is_nothrow_move_constructible<key_equal>::value &&
is_nothrow_move_constructible<allocator_type>::value);
unordered_map(unordered_map&&, const Allocator&);
unordered_map(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_map(size_type n, const allocator_type& a)
: unordered_map(n, hasher(), key_equal(), a) {} // C++14
unordered_map(size_type n, const hasher& hf, const allocator_type& a)
: unordered_map(n, hf, key_equal(), a) {} // C++14
template <class InputIterator>
unordered_map(InputIterator f, InputIterator l, size_type n, const allocator_type& a)
: unordered_map(f, l, n, hasher(), key_equal(), a) {} // C++14
template <class InputIterator>
unordered_map(InputIterator f, InputIterator l, size_type n, const hasher& hf,
const allocator_type& a)
: unordered_map(f, l, n, hf, key_equal(), a) {} // C++14
unordered_map(initializer_list<value_type> il, size_type n, const allocator_type& a)
: unordered_map(il, n, hasher(), key_equal(), a) {} // C++14
unordered_map(initializer_list<value_type> il, size_type n, const hasher& hf,
const allocator_type& a)
: unordered_map(il, n, hf, key_equal(), a) {} // C++14
~unordered_map();
unordered_map& operator=(const unordered_map&);
unordered_map& operator=(unordered_map&&)
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_map& 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);
template <class P>
pair<iterator, bool> insert(P&& obj);
iterator insert(const_iterator hint, const value_type& obj);
template <class P>
iterator insert(const_iterator hint, P&& 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
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 H2, class P2>
void merge(unordered_map<Key, T, H2, P2, Allocator>& source); // C++17
template<class H2, class P2>
void merge(unordered_map<Key, T, H2, P2, Allocator>&& source); // C++17
template<class H2, class P2>
void merge(unordered_multimap<Key, T, H2, P2, Allocator>& source); // C++17
template<class H2, class P2>
void merge(unordered_multimap<Key, T, H2, P2, Allocator>&& source); // C++17
void swap(unordered_map&)
noexcept(
(!allocator_type::propagate_on_container_swap::value ||
__is_nothrow_swappable<allocator_type>::value) &&
__is_nothrow_swappable<hasher>::value &&
__is_nothrow_swappable<key_equal>::value);
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;
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;
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 Key, class T, class Hash, class Pred, class Alloc>
void swap(unordered_map<Key, T, Hash, Pred, Alloc>& x,
unordered_map<Key, T, Hash, Pred, Alloc>& y)
noexcept(noexcept(x.swap(y)));
template <class Key, class T, class Hash, class Pred, class Alloc>
bool
operator==(const unordered_map<Key, T, Hash, Pred, Alloc>& x,
const unordered_map<Key, T, Hash, Pred, Alloc>& y);
template <class Key, class T, class Hash, class Pred, class Alloc>
bool
operator!=(const unordered_map<Key, T, Hash, Pred, Alloc>& x,
const unordered_map<Key, T, Hash, Pred, Alloc>& y);
template <class Key, class T, class Hash = hash<Key>, class Pred = equal_to<Key>,
class Alloc = allocator<pair<const Key, T>>>
class unordered_multimap
{
public:
// types
typedef Key key_type;
typedef T mapped_type;
typedef Hash hasher;
typedef Pred key_equal;
typedef Alloc allocator_type;
typedef pair<const key_type, mapped_type> value_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; // C++17
unordered_multimap()
noexcept(
is_nothrow_default_constructible<hasher>::value &&
is_nothrow_default_constructible<key_equal>::value &&
is_nothrow_default_constructible<allocator_type>::value);
explicit unordered_multimap(size_type n, const hasher& hf = hasher(),
const key_equal& eql = key_equal(),
const allocator_type& a = allocator_type());
template <class InputIterator>
unordered_multimap(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_multimap(const allocator_type&);
unordered_multimap(const unordered_multimap&);
unordered_multimap(const unordered_multimap&, const Allocator&);
unordered_multimap(unordered_multimap&&)
noexcept(
is_nothrow_move_constructible<hasher>::value &&
is_nothrow_move_constructible<key_equal>::value &&
is_nothrow_move_constructible<allocator_type>::value);
unordered_multimap(unordered_multimap&&, const Allocator&);
unordered_multimap(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_multimap(size_type n, const allocator_type& a)
: unordered_multimap(n, hasher(), key_equal(), a) {} // C++14
unordered_multimap(size_type n, const hasher& hf, const allocator_type& a)
: unordered_multimap(n, hf, key_equal(), a) {} // C++14
template <class InputIterator>
unordered_multimap(InputIterator f, InputIterator l, size_type n, const allocator_type& a)
: unordered_multimap(f, l, n, hasher(), key_equal(), a) {} // C++14
template <class InputIterator>
unordered_multimap(InputIterator f, InputIterator l, size_type n, const hasher& hf,
const allocator_type& a)
: unordered_multimap(f, l, n, hf, key_equal(), a) {} // C++14
unordered_multimap(initializer_list<value_type> il, size_type n, const allocator_type& a)
: unordered_multimap(il, n, hasher(), key_equal(), a) {} // C++14
unordered_multimap(initializer_list<value_type> il, size_type n, const hasher& hf,
const allocator_type& a)
: unordered_multimap(il, n, hf, key_equal(), a) {} // C++14
~unordered_multimap();
unordered_multimap& operator=(const unordered_multimap&);
unordered_multimap& operator=(unordered_multimap&&)
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_multimap& 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);
template <class P>
iterator insert(P&& obj);
iterator insert(const_iterator hint, const value_type& obj);
template <class P>
iterator insert(const_iterator hint, P&& 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_multimap<Key, T, H2, P2, Allocator>& source); // C++17
template<class H2, class P2>
void merge(unordered_multimap<Key, T, H2, P2, Allocator>&& source); // C++17
template<class H2, class P2>
void merge(unordered_map<Key, T, H2, P2, Allocator>& source); // C++17
template<class H2, class P2>
void merge(unordered_map<Key, T, H2, P2, Allocator>&& source); // C++17
void swap(unordered_multimap&)
noexcept(
(!allocator_type::propagate_on_container_swap::value ||
__is_nothrow_swappable<allocator_type>::value) &&
__is_nothrow_swappable<hasher>::value &&
__is_nothrow_swappable<key_equal>::value);
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 Key, class T, class Hash, class Pred, class Alloc>
void swap(unordered_multimap<Key, T, Hash, Pred, Alloc>& x,
unordered_multimap<Key, T, 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 Key, class T, class Hash, class Pred, class Alloc>
bool
operator==(const unordered_multimap<Key, T, Hash, Pred, Alloc>& x,
const unordered_multimap<Key, T, Hash, Pred, Alloc>& y);
template <class Key, class T, class Hash, class Pred, class Alloc>
bool
operator!=(const unordered_multimap<Key, T, Hash, Pred, Alloc>& x,
const unordered_multimap<Key, T, Hash, Pred, Alloc>& y);
} // std
*/
template <class _Key, class _Cp, class _Hash,
bool = is_empty<_Hash>::value && !__libcpp_is_final<_Hash>::value>
class __unordered_map_hasher
: private _Hash
{
public:
_LIBCPP_INLINE_VISIBILITY
__unordered_map_hasher()
_NOEXCEPT_(is_nothrow_default_constructible<_Hash>::value)
: _Hash() {}
_LIBCPP_INLINE_VISIBILITY
__unordered_map_hasher(const _Hash& __h)
_NOEXCEPT_(is_nothrow_copy_constructible<_Hash>::value)
: _Hash(__h) {}
_LIBCPP_INLINE_VISIBILITY
const _Hash& hash_function() const _NOEXCEPT {return *this;}
_LIBCPP_INLINE_VISIBILITY
size_t operator()(const _Cp& __x) const
{return static_cast<const _Hash&>(*this)(__x.__get_value().first);}
_LIBCPP_INLINE_VISIBILITY
size_t operator()(const _Key& __x) const
{return static_cast<const _Hash&>(*this)(__x);}
void swap(__unordered_map_hasher&__y)
_NOEXCEPT_(__is_nothrow_swappable<_Hash>::value)
{
using _VSTD::swap;
swap(static_cast<_Hash&>(*this), static_cast<_Hash&>(__y));
}
};
template <class _Key, class _Cp, class _Hash>
class __unordered_map_hasher<_Key, _Cp, _Hash, false>
{
_Hash __hash_;
public:
_LIBCPP_INLINE_VISIBILITY
__unordered_map_hasher()
_NOEXCEPT_(is_nothrow_default_constructible<_Hash>::value)
: __hash_() {}
_LIBCPP_INLINE_VISIBILITY
__unordered_map_hasher(const _Hash& __h)
_NOEXCEPT_(is_nothrow_copy_constructible<_Hash>::value)
: __hash_(__h) {}
_LIBCPP_INLINE_VISIBILITY
const _Hash& hash_function() const _NOEXCEPT {return __hash_;}
_LIBCPP_INLINE_VISIBILITY
size_t operator()(const _Cp& __x) const
{return __hash_(__x.__get_value().first);}
_LIBCPP_INLINE_VISIBILITY
size_t operator()(const _Key& __x) const
{return __hash_(__x);}
void swap(__unordered_map_hasher&__y)
_NOEXCEPT_(__is_nothrow_swappable<_Hash>::value)
{
using _VSTD::swap;
swap(__hash_, __y.__hash_);
}
};
template <class _Key, class _Cp, class _Hash, bool __b>
inline _LIBCPP_INLINE_VISIBILITY
void
swap(__unordered_map_hasher<_Key, _Cp, _Hash, __b>& __x,
__unordered_map_hasher<_Key, _Cp, _Hash, __b>& __y)
_NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
{
__x.swap(__y);
}
template <class _Key, class _Cp, class _Pred,
bool = is_empty<_Pred>::value && !__libcpp_is_final<_Pred>::value>
class __unordered_map_equal
: private _Pred
{
public:
_LIBCPP_INLINE_VISIBILITY
__unordered_map_equal()
_NOEXCEPT_(is_nothrow_default_constructible<_Pred>::value)
: _Pred() {}
_LIBCPP_INLINE_VISIBILITY
__unordered_map_equal(const _Pred& __p)
_NOEXCEPT_(is_nothrow_copy_constructible<_Pred>::value)
: _Pred(__p) {}
_LIBCPP_INLINE_VISIBILITY
const _Pred& key_eq() const _NOEXCEPT {return *this;}
_LIBCPP_INLINE_VISIBILITY
bool operator()(const _Cp& __x, const _Cp& __y) const
{return static_cast<const _Pred&>(*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 _Pred&>(*this)(__x.__get_value().first, __y);}
_LIBCPP_INLINE_VISIBILITY
bool operator()(const _Key& __x, const _Cp& __y) const
{return static_cast<const _Pred&>(*this)(__x, __y.__get_value().first);}
void swap(__unordered_map_equal&__y)
_NOEXCEPT_(__is_nothrow_swappable<_Pred>::value)
{
using _VSTD::swap;
swap(static_cast<_Pred&>(*this), static_cast<_Pred&>(__y));
}
};
template <class _Key, class _Cp, class _Pred>
class __unordered_map_equal<_Key, _Cp, _Pred, false>
{
_Pred __pred_;
public:
_LIBCPP_INLINE_VISIBILITY
__unordered_map_equal()
_NOEXCEPT_(is_nothrow_default_constructible<_Pred>::value)
: __pred_() {}
_LIBCPP_INLINE_VISIBILITY
__unordered_map_equal(const _Pred& __p)
_NOEXCEPT_(is_nothrow_copy_constructible<_Pred>::value)
: __pred_(__p) {}
_LIBCPP_INLINE_VISIBILITY
const _Pred& key_eq() const _NOEXCEPT {return __pred_;}
_LIBCPP_INLINE_VISIBILITY
bool operator()(const _Cp& __x, const _Cp& __y) const
{return __pred_(__x.__get_value().first, __y.__get_value().first);}
_LIBCPP_INLINE_VISIBILITY
bool operator()(const _Cp& __x, const _Key& __y) const
{return __pred_(__x.__get_value().first, __y);}
_LIBCPP_INLINE_VISIBILITY
bool operator()(const _Key& __x, const _Cp& __y) const
{return __pred_(__x, __y.__get_value().first);}
void swap(__unordered_map_equal&__y)
_NOEXCEPT_(__is_nothrow_swappable<_Pred>::value)
{
using _VSTD::swap;
swap(__pred_, __y.__pred_);
}
};
template <class _Key, class _Cp, class _Pred, bool __b>
inline _LIBCPP_INLINE_VISIBILITY
void
swap(__unordered_map_equal<_Key, _Cp, _Pred, __b>& __x,
__unordered_map_equal<_Key, _Cp, _Pred, __b>& __y)
_NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
{
__x.swap(__y);
}
template <class _Alloc>
class __hash_map_node_destructor
{
typedef _Alloc allocator_type;
typedef allocator_traits<allocator_type> __alloc_traits;
public:
typedef typename __alloc_traits::pointer pointer;
private:
allocator_type& __na_;
__hash_map_node_destructor& operator=(const __hash_map_node_destructor&);
public:
bool __first_constructed;
bool __second_constructed;
_LIBCPP_INLINE_VISIBILITY
explicit __hash_map_node_destructor(allocator_type& __na) _NOEXCEPT
: __na_(__na),
__first_constructed(false),
__second_constructed(false)
{}
#ifndef _LIBCPP_CXX03_LANG
_LIBCPP_INLINE_VISIBILITY
__hash_map_node_destructor(__hash_node_destructor<allocator_type>&& __x)
_NOEXCEPT
: __na_(__x.__na_),
__first_constructed(__x.__value_constructed),
__second_constructed(__x.__value_constructed)
{
__x.__value_constructed = false;
}
#else // _LIBCPP_CXX03_LANG
_LIBCPP_INLINE_VISIBILITY
__hash_map_node_destructor(const __hash_node_destructor<allocator_type>& __x)
: __na_(__x.__na_),
__first_constructed(__x.__value_constructed),
__second_constructed(__x.__value_constructed)
{
const_cast<bool&>(__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);
}
};
#ifndef _LIBCPP_CXX03_LANG
template <class _Key, class _Tp>
struct __hash_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
__hash_value_type& operator=(const __hash_value_type& __v)
{
__ref() = __v.__get_value();
return *this;
}
_LIBCPP_INLINE_VISIBILITY
__hash_value_type& operator=(__hash_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
__hash_value_type& operator=(_ValueTp&& __v)
{
__ref() = _VSTD::forward<_ValueTp>(__v);
return *this;
}
private:
__hash_value_type(const __hash_value_type& __v) = delete;
__hash_value_type(__hash_value_type&& __v) = delete;
template <class ..._Args>
explicit __hash_value_type(_Args&& ...__args) = delete;
~__hash_value_type() = delete;
};
#else
template <class _Key, class _Tp>
struct __hash_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:
~__hash_value_type();
};
#endif
template <class _HashIterator>
class _LIBCPP_TEMPLATE_VIS __hash_map_iterator
{
_HashIterator __i_;
typedef __hash_node_types_from_iterator<_HashIterator> _NodeTypes;
public:
typedef forward_iterator_tag iterator_category;
typedef typename _NodeTypes::__map_value_type value_type;
typedef typename _NodeTypes::difference_type difference_type;
typedef value_type& reference;
typedef typename _NodeTypes::__map_value_type_pointer pointer;
_LIBCPP_INLINE_VISIBILITY
__hash_map_iterator() _NOEXCEPT {}
_LIBCPP_INLINE_VISIBILITY
__hash_map_iterator(_HashIterator __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
__hash_map_iterator& operator++() {++__i_; return *this;}
_LIBCPP_INLINE_VISIBILITY
__hash_map_iterator operator++(int)
{
__hash_map_iterator __t(*this);
++(*this);
return __t;
}
friend _LIBCPP_INLINE_VISIBILITY
bool operator==(const __hash_map_iterator& __x, const __hash_map_iterator& __y)
{return __x.__i_ == __y.__i_;}
friend _LIBCPP_INLINE_VISIBILITY
bool operator!=(const __hash_map_iterator& __x, const __hash_map_iterator& __y)
{return __x.__i_ != __y.__i_;}
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> friend class _LIBCPP_TEMPLATE_VIS __hash_const_iterator;
template <class> friend class _LIBCPP_TEMPLATE_VIS __hash_const_local_iterator;
template <class> friend class _LIBCPP_TEMPLATE_VIS __hash_map_const_iterator;
};
template <class _HashIterator>
class _LIBCPP_TEMPLATE_VIS __hash_map_const_iterator
{
_HashIterator __i_;
typedef __hash_node_types_from_iterator<_HashIterator> _NodeTypes;
public:
typedef forward_iterator_tag iterator_category;
typedef typename _NodeTypes::__map_value_type value_type;
typedef typename _NodeTypes::difference_type difference_type;
typedef const value_type& reference;
typedef typename _NodeTypes::__const_map_value_type_pointer pointer;
_LIBCPP_INLINE_VISIBILITY
__hash_map_const_iterator() _NOEXCEPT {}
_LIBCPP_INLINE_VISIBILITY
__hash_map_const_iterator(_HashIterator __i) _NOEXCEPT : __i_(__i) {}
_LIBCPP_INLINE_VISIBILITY
__hash_map_const_iterator(
__hash_map_iterator<typename _HashIterator::__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
__hash_map_const_iterator& operator++() {++__i_; return *this;}
_LIBCPP_INLINE_VISIBILITY
__hash_map_const_iterator operator++(int)
{
__hash_map_const_iterator __t(*this);
++(*this);
return __t;
}
friend _LIBCPP_INLINE_VISIBILITY
bool operator==(const __hash_map_const_iterator& __x, const __hash_map_const_iterator& __y)
{return __x.__i_ == __y.__i_;}
friend _LIBCPP_INLINE_VISIBILITY
bool operator!=(const __hash_map_const_iterator& __x, const __hash_map_const_iterator& __y)
{return __x.__i_ != __y.__i_;}
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> friend class _LIBCPP_TEMPLATE_VIS __hash_const_iterator;
template <class> friend class _LIBCPP_TEMPLATE_VIS __hash_const_local_iterator;
};
template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
class unordered_multimap;
template <class _Key, class _Tp, class _Hash = hash<_Key>, class _Pred = equal_to<_Key>,
class _Alloc = allocator<pair<const _Key, _Tp> > >
class _LIBCPP_TEMPLATE_VIS unordered_map
{
public:
// types
typedef _Key key_type;
typedef _Tp mapped_type;
typedef typename __identity<_Hash>::type hasher;
typedef typename __identity<_Pred>::type key_equal;
typedef typename __identity<_Alloc>::type allocator_type;
typedef pair<const key_type, mapped_type> value_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_value_type<key_type, mapped_type> __value_type;
typedef __unordered_map_hasher<key_type, __value_type, hasher> __hasher;
typedef __unordered_map_equal<key_type, __value_type, key_equal> __key_equal;
typedef typename __rebind_alloc_helper<allocator_traits<allocator_type>,
__value_type>::type __allocator_type;
typedef __hash_table<__value_type, __hasher,
__key_equal, __allocator_type> __table;
__table __table_;
typedef typename __table::_NodeTypes _NodeTypes;
typedef typename __table::__node_pointer __node_pointer;
typedef typename __table::__node_const_pointer __node_const_pointer;
typedef typename __table::__node_traits __node_traits;
typedef typename __table::__node_allocator __node_allocator;
typedef typename __table::__node __node;
typedef __hash_map_node_destructor<__node_allocator> _Dp;
typedef unique_ptr<__node, _Dp> __node_holder;
typedef allocator_traits<allocator_type> __alloc_traits;
static_assert((is_same<typename __table::__container_value_type, value_type>::value), "");
static_assert((is_same<typename __table::__node_value_type, __value_type>::value), "");
public:
typedef typename __alloc_traits::pointer pointer;
typedef typename __alloc_traits::const_pointer const_pointer;
typedef typename __table::size_type size_type;
typedef typename __table::difference_type difference_type;
typedef __hash_map_iterator<typename __table::iterator> iterator;
typedef __hash_map_const_iterator<typename __table::const_iterator> const_iterator;
typedef __hash_map_iterator<typename __table::local_iterator> local_iterator;
typedef __hash_map_const_iterator<typename __table::const_local_iterator> const_local_iterator;
#if _LIBCPP_STD_VER > 14
typedef __map_node_handle<__node, allocator_type> node_type;
typedef __insert_return_type<iterator, node_type> insert_return_type;
#endif
template <class _Key2, class _Tp2, class _Hash2, class _Pred2, class _Alloc2>
friend class _LIBCPP_TEMPLATE_VIS unordered_map;
template <class _Key2, class _Tp2, class _Hash2, class _Pred2, class _Alloc2>
friend class _LIBCPP_TEMPLATE_VIS unordered_multimap;
_LIBCPP_INLINE_VISIBILITY
unordered_map()
_NOEXCEPT_(is_nothrow_default_constructible<__table>::value)
{
#if _LIBCPP_DEBUG_LEVEL >= 2
__get_db()->__insert_c(this);
#endif
}
explicit unordered_map(size_type __n, const hasher& __hf = hasher(),
const key_equal& __eql = key_equal());
unordered_map(size_type __n, const hasher& __hf,
const key_equal& __eql,
const allocator_type& __a);
template <class _InputIterator>
unordered_map(_InputIterator __first, _InputIterator __last);
template <class _InputIterator>
unordered_map(_InputIterator __first, _InputIterator __last,
size_type __n, const hasher& __hf = hasher(),
const key_equal& __eql = key_equal());
template <class _InputIterator>
unordered_map(_InputIterator __first, _InputIterator __last,
size_type __n, const hasher& __hf,
const key_equal& __eql,
const allocator_type& __a);
_LIBCPP_INLINE_VISIBILITY
explicit unordered_map(const allocator_type& __a);
unordered_map(const unordered_map& __u);
unordered_map(const unordered_map& __u, const allocator_type& __a);
#ifndef _LIBCPP_CXX03_LANG
_LIBCPP_INLINE_VISIBILITY
unordered_map(unordered_map&& __u)
_NOEXCEPT_(is_nothrow_move_constructible<__table>::value);
unordered_map(unordered_map&& __u, const allocator_type& __a);
unordered_map(initializer_list<value_type> __il);
unordered_map(initializer_list<value_type> __il, size_type __n,
const hasher& __hf = hasher(), const key_equal& __eql = key_equal());
unordered_map(initializer_list<value_type> __il, size_type __n,
const hasher& __hf, const key_equal& __eql,
const allocator_type& __a);
#endif // _LIBCPP_CXX03_LANG
#if _LIBCPP_STD_VER > 11
_LIBCPP_INLINE_VISIBILITY
unordered_map(size_type __n, const allocator_type& __a)
: unordered_map(__n, hasher(), key_equal(), __a) {}
_LIBCPP_INLINE_VISIBILITY
unordered_map(size_type __n, const hasher& __hf, const allocator_type& __a)
: unordered_map(__n, __hf, key_equal(), __a) {}
template <class _InputIterator>
_LIBCPP_INLINE_VISIBILITY
unordered_map(_InputIterator __first, _InputIterator __last, size_type __n, const allocator_type& __a)
: unordered_map(__first, __last, __n, hasher(), key_equal(), __a) {}
template <class _InputIterator>
_LIBCPP_INLINE_VISIBILITY
unordered_map(_InputIterator __first, _InputIterator __last, size_type __n, const hasher& __hf,
const allocator_type& __a)
: unordered_map(__first, __last, __n, __hf, key_equal(), __a) {}
_LIBCPP_INLINE_VISIBILITY
unordered_map(initializer_list<value_type> __il, size_type __n, const allocator_type& __a)
: unordered_map(__il, __n, hasher(), key_equal(), __a) {}
_LIBCPP_INLINE_VISIBILITY
unordered_map(initializer_list<value_type> __il, size_type __n, const hasher& __hf,
const allocator_type& __a)
: unordered_map(__il, __n, __hf, key_equal(), __a) {}
#endif
_LIBCPP_INLINE_VISIBILITY
~unordered_map() {
static_assert(sizeof(__diagnose_unordered_container_requirements<_Key, _Hash, _Pred>(0)), "");
}
_LIBCPP_INLINE_VISIBILITY
unordered_map& operator=(const unordered_map& __u)
{
#ifndef _LIBCPP_CXX03_LANG
__table_ = __u.__table_;
#else
if (this != &__u) {
__table_.clear();
__table_.hash_function() = __u.__table_.hash_function();
__table_.key_eq() = __u.__table_.key_eq();
__table_.max_load_factor() = __u.__table_.max_load_factor();
__table_.__copy_assign_alloc(__u.__table_);
insert(__u.begin(), __u.end());
}
#endif
return *this;
}
#ifndef _LIBCPP_CXX03_LANG
_LIBCPP_INLINE_VISIBILITY
unordered_map& operator=(unordered_map&& __u)
_NOEXCEPT_(is_nothrow_move_assignable<__table>::value);
_LIBCPP_INLINE_VISIBILITY
unordered_map& 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();}
_LIBCPP_INLINE_VISIBILITY
pair<iterator, bool> insert(const value_type& __x)
{return __table_.__insert_unique(__x);}
iterator insert(const_iterator __p, const value_type& __x) {
#if _LIBCPP_DEBUG_LEVEL >= 2
_LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this,
"unordered_map::insert(const_iterator, const value_type&) called with an iterator not"
" referring to this unordered_map");
#else
((void)__p);
#endif
return insert(__x).first;
}
template <class _InputIterator>
_LIBCPP_INLINE_VISIBILITY
void insert(_InputIterator __first, _InputIterator __last);
#ifndef _LIBCPP_CXX03_LANG
_LIBCPP_INLINE_VISIBILITY
void insert(initializer_list<value_type> __il)
{insert(__il.begin(), __il.end());}
_LIBCPP_INLINE_VISIBILITY
pair<iterator, bool> insert(value_type&& __x)
{return __table_.__insert_unique(_VSTD::move(__x));}
iterator insert(const_iterator __p, value_type&& __x) {
#if _LIBCPP_DEBUG_LEVEL >= 2
_LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this,
"unordered_map::insert(const_iterator, const value_type&) called with an iterator not"
" referring to this unordered_map");
#else
((void)__p);
#endif
return __table_.__insert_unique(_VSTD::move(__x)).first;
}
template <class _Pp,
class = typename enable_if<is_constructible<value_type, _Pp>::value>::type>
_LIBCPP_INLINE_VISIBILITY
pair<iterator, bool> insert(_Pp&& __x)
{return __table_.__insert_unique(_VSTD::forward<_Pp>(__x));}
template <class _Pp,
class = typename enable_if<is_constructible<value_type, _Pp>::value>::type>
_LIBCPP_INLINE_VISIBILITY
iterator insert(const_iterator __p, _Pp&& __x)
{
#if _LIBCPP_DEBUG_LEVEL >= 2
_LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this,
"unordered_map::insert(const_iterator, value_type&&) called with an iterator not"
" referring to this unordered_map");
#else
((void)__p);
#endif
return insert(_VSTD::forward<_Pp>(__x)).first;
}
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
iterator emplace_hint(const_iterator __p, _Args&&... __args) {
#if _LIBCPP_DEBUG_LEVEL >= 2
_LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this,
"unordered_map::emplace_hint(const_iterator, args...) called with an iterator not"
" referring to this unordered_map");
#else
((void)__p);
#endif
return __table_.__emplace_unique(_VSTD::forward<_Args>(__args)...).first;
}
#endif // _LIBCPP_CXX03_LANG
#if _LIBCPP_STD_VER > 14
template <class... _Args>
_LIBCPP_INLINE_VISIBILITY
pair<iterator, bool> try_emplace(const key_type& __k, _Args&&... __args)
{
return __table_.__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 __table_.__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)
{
#if _LIBCPP_DEBUG_LEVEL >= 2
_LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__h) == this,
"unordered_map::try_emplace(const_iterator, key, args...) called with an iterator not"
" referring to this unordered_map");
#else
((void)__h);
#endif
return try_emplace(__k, _VSTD::forward<_Args>(__args)...).first;
}
template <class... _Args>
_LIBCPP_INLINE_VISIBILITY
iterator try_emplace(const_iterator __h, key_type&& __k, _Args&&... __args)
{
#if _LIBCPP_DEBUG_LEVEL >= 2
_LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__h) == this,
"unordered_map::try_emplace(const_iterator, key, args...) called with an iterator not"
" referring to this unordered_map");
#else
((void)__h);
#endif
return try_emplace(_VSTD::move(__k), _VSTD::forward<_Args>(__args)...).first;
}
template <class _Vp>
_LIBCPP_INLINE_VISIBILITY
pair<iterator, bool> insert_or_assign(const key_type& __k, _Vp&& __v)
{
pair<iterator, bool> __res = __table_.__emplace_unique_key_args(__k,
__k, _VSTD::forward<_Vp>(__v));
if (!__res.second) {
__res.first->second = _VSTD::forward<_Vp>(__v);
}
return __res;
}
template <class _Vp>
_LIBCPP_INLINE_VISIBILITY
pair<iterator, bool> insert_or_assign(key_type&& __k, _Vp&& __v)
{
pair<iterator, bool> __res = __table_.__emplace_unique_key_args(__k,
_VSTD::move(__k), _VSTD::forward<_Vp>(__v));
if (!__res.second) {
__res.first->second = _VSTD::forward<_Vp>(__v);
}
return __res;
}
template <class _Vp>
_LIBCPP_INLINE_VISIBILITY
iterator insert_or_assign(const_iterator, const key_type& __k, _Vp&& __v)
{
// FIXME: Add debug mode checking for the iterator input
return insert_or_assign(__k, _VSTD::forward<_Vp>(__v)).first;
}
template <class _Vp>
_LIBCPP_INLINE_VISIBILITY
iterator insert_or_assign(const_iterator, key_type&& __k, _Vp&& __v)
{
// FIXME: Add debug mode checking for the iterator input
return insert_or_assign(_VSTD::move(__k), _VSTD::forward<_Vp>(__v)).first;
}
#endif // _LIBCPP_STD_VER > 14
_LIBCPP_INLINE_VISIBILITY
iterator erase(const_iterator __p) {return __table_.erase(__p.__i_);}
_LIBCPP_INLINE_VISIBILITY
iterator erase(iterator __p) {return __table_.erase(__p.__i_);}
_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.__i_, __last.__i_);}
_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_map::insert()");
return __table_.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 unordered_map::insert()");
return __table_.template __node_handle_insert_unique<node_type>(
__hint.__i_, _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.__i_);
}
template <class _H2, class _P2>
_LIBCPP_INLINE_VISIBILITY
void merge(unordered_map<key_type, mapped_type, _H2, _P2, allocator_type>& __source)
{
_LIBCPP_ASSERT(__source.get_allocator() == get_allocator(),
"merging container with incompatible allocator");
return __table_.__node_handle_merge_unique(__source.__table_);
}
template <class _H2, class _P2>
_LIBCPP_INLINE_VISIBILITY
void merge(unordered_map<key_type, mapped_type, _H2, _P2, allocator_type>&& __source)
{
_LIBCPP_ASSERT(__source.get_allocator() == get_allocator(),
"merging container with incompatible allocator");
return __table_.__node_handle_merge_unique(__source.__table_);
}
template <class _H2, class _P2>
_LIBCPP_INLINE_VISIBILITY
void merge(unordered_multimap<key_type, mapped_type, _H2, _P2, allocator_type>& __source)
{
_LIBCPP_ASSERT(__source.get_allocator() == get_allocator(),
"merging container with incompatible allocator");
return __table_.__node_handle_merge_unique(__source.__table_);
}
template <class _H2, class _P2>
_LIBCPP_INLINE_VISIBILITY
void merge(unordered_multimap<key_type, mapped_type, _H2, _P2, allocator_type>&& __source)
{
_LIBCPP_ASSERT(__source.get_allocator() == get_allocator(),
"merging container with incompatible allocator");
return __table_.__node_handle_merge_unique(__source.__table_);
}
#endif
_LIBCPP_INLINE_VISIBILITY
void swap(unordered_map& __u)
_NOEXCEPT_(__is_nothrow_swappable<__table>::value)
{ __table_.swap(__u.__table_);}
_LIBCPP_INLINE_VISIBILITY
hasher hash_function() const
{return __table_.hash_function().hash_function();}
_LIBCPP_INLINE_VISIBILITY
key_equal key_eq() const
{return __table_.key_eq().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);}
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
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->__i_);}
bool __decrementable(const const_iterator* __i) const
{return __table_.__decrementable(&__i->__i_);}
bool __addable(const const_iterator* __i, ptrdiff_t __n) const
{return __table_.__addable(&__i->__i_, __n);}
bool __subscriptable(const const_iterator* __i, ptrdiff_t __n) const
{return __table_.__addable(&__i->__i_, __n);}
#endif // _LIBCPP_DEBUG_LEVEL >= 2
private:
#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 _Hash = hash<__iter_key_type<_InputIterator>>,
class _Pred = equal_to<__iter_key_type<_InputIterator>>,
class _Allocator = allocator<__iter_to_alloc_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_map(_InputIterator, _InputIterator, typename allocator_traits<_Allocator>::size_type = 0,
_Hash = _Hash(), _Pred = _Pred(), _Allocator = _Allocator())
-> unordered_map<__iter_key_type<_InputIterator>, __iter_mapped_type<_InputIterator>, _Hash, _Pred, _Allocator>;
template<class _Key, class _Tp, class _Hash = hash<remove_const_t<_Key>>,
class _Pred = equal_to<remove_const_t<_Key>>,
class _Allocator = allocator<pair<const _Key, _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_map(initializer_list<pair<_Key, _Tp>>, typename allocator_traits<_Allocator>::size_type = 0,
_Hash = _Hash(), _Pred = _Pred(), _Allocator = _Allocator())
-> unordered_map<remove_const_t<_Key>, _Tp, _Hash, _Pred, _Allocator>;
template<class _InputIterator, class _Allocator,
class = _EnableIf<__is_allocator<_Allocator>::value>>
unordered_map(_InputIterator, _InputIterator, typename allocator_traits<_Allocator>::size_type, _Allocator)
-> unordered_map<__iter_key_type<_InputIterator>, __iter_mapped_type<_InputIterator>,
hash<__iter_key_type<_InputIterator>>, equal_to<__iter_key_type<_InputIterator>>, _Allocator>;
template<class _InputIterator, class _Allocator,
class = _EnableIf<__is_allocator<_Allocator>::value>>
unordered_map(_InputIterator, _InputIterator, _Allocator)
-> unordered_map<__iter_key_type<_InputIterator>, __iter_mapped_type<_InputIterator>,
hash<__iter_key_type<_InputIterator>>, equal_to<__iter_key_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_map(_InputIterator, _InputIterator, typename allocator_traits<_Allocator>::size_type, _Hash, _Allocator)
-> unordered_map<__iter_key_type<_InputIterator>, __iter_mapped_type<_InputIterator>,
_Hash, equal_to<__iter_key_type<_InputIterator>>, _Allocator>;
template<class _Key, class _Tp, class _Allocator,
class = _EnableIf<__is_allocator<_Allocator>::value>>
unordered_map(initializer_list<pair<_Key, _Tp>>, typename allocator_traits<_Allocator>::size_type, _Allocator)
-> unordered_map<remove_const_t<_Key>, _Tp,
hash<remove_const_t<_Key>>,
equal_to<remove_const_t<_Key>>, _Allocator>;
template<class _Key, class _Tp, class _Allocator,
class = _EnableIf<__is_allocator<_Allocator>::value>>
unordered_map(initializer_list<pair<_Key, _Tp>>, _Allocator)
-> unordered_map<remove_const_t<_Key>, _Tp,
hash<remove_const_t<_Key>>,
equal_to<remove_const_t<_Key>>, _Allocator>;
template<class _Key, 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_map(initializer_list<pair<_Key, _Tp>>, typename allocator_traits<_Allocator>::size_type, _Hash, _Allocator)
-> unordered_map<remove_const_t<_Key>, _Tp, _Hash,
equal_to<remove_const_t<_Key>>, _Allocator>;
#endif
template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
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 _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
size_type __n, const hasher& __hf, const key_equal& __eql,
const allocator_type& __a)
: __table_(__hf, __eql, typename __table::allocator_type(__a))
{
#if _LIBCPP_DEBUG_LEVEL >= 2
__get_db()->__insert_c(this);
#endif
__table_.rehash(__n);
}
template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
inline
unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
const allocator_type& __a)
: __table_(typename __table::allocator_type(__a))
{
#if _LIBCPP_DEBUG_LEVEL >= 2
__get_db()->__insert_c(this);
#endif
}
template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
template <class _InputIterator>
unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
_InputIterator __first, _InputIterator __last)
{
#if _LIBCPP_DEBUG_LEVEL >= 2
__get_db()->__insert_c(this);
#endif
insert(__first, __last);
}
template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
template <class _InputIterator>
unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
_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 _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
template <class _InputIterator>
unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
_InputIterator __first, _InputIterator __last, size_type __n,
const hasher& __hf, const key_equal& __eql, const allocator_type& __a)
: __table_(__hf, __eql, typename __table::allocator_type(__a))
{
#if _LIBCPP_DEBUG_LEVEL >= 2
__get_db()->__insert_c(this);
#endif
__table_.rehash(__n);
insert(__first, __last);
}
template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
const unordered_map& __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 _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
const unordered_map& __u, const allocator_type& __a)
: __table_(__u.__table_, typename __table::allocator_type(__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 _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
inline
unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
unordered_map&& __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 _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
unordered_map&& __u, const allocator_type& __a)
: __table_(_VSTD::move(__u.__table_), typename __table::allocator_type(__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_.__emplace_unique(
__u.__table_.remove((__i++).__i_)->__value_.__move());
}
}
#if _LIBCPP_DEBUG_LEVEL >= 2
else
__get_db()->swap(this, &__u);
#endif
}
template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
initializer_list<value_type> __il)
{
#if _LIBCPP_DEBUG_LEVEL >= 2
__get_db()->__insert_c(this);
#endif
insert(__il.begin(), __il.end());
}
template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
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 _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_map(
initializer_list<value_type> __il, size_type __n, const hasher& __hf,
const key_equal& __eql, const allocator_type& __a)
: __table_(__hf, __eql, typename __table::allocator_type(__a))
{
#if _LIBCPP_DEBUG_LEVEL >= 2
__get_db()->__insert_c(this);
#endif
__table_.rehash(__n);
insert(__il.begin(), __il.end());
}
template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
inline
unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>&
unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::operator=(unordered_map&& __u)
_NOEXCEPT_(is_nothrow_move_assignable<__table>::value)
{
__table_ = _VSTD::move(__u.__table_);
return *this;
}
template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
inline
unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>&
unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::operator=(
initializer_list<value_type> __il)
{
__table_.__assign_unique(__il.begin(), __il.end());
return *this;
}
#endif // _LIBCPP_CXX03_LANG
template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
template <class _InputIterator>
inline
void
unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::insert(_InputIterator __first,
_InputIterator __last)
{
for (; __first != __last; ++__first)
__table_.__insert_unique(*__first);
}
#ifndef _LIBCPP_CXX03_LANG
template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
_Tp&
unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::operator[](const key_type& __k)
{
return __table_.__emplace_unique_key_args(__k,
std::piecewise_construct, std::forward_as_tuple(__k),
std::forward_as_tuple()).first->__get_value().second;
}
template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
_Tp&
unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::operator[](key_type&& __k)
{
return __table_.__emplace_unique_key_args(__k,
std::piecewise_construct, std::forward_as_tuple(std::move(__k)),
std::forward_as_tuple()).first->__get_value().second;
}
#else // _LIBCPP_CXX03_LANG
template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
typename unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::__node_holder
unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::__construct_node_with_key(const key_type& __k)
{
__node_allocator& __na = __table_.__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 _Hash, class _Pred, class _Alloc>
_Tp&
unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::operator[](const key_type& __k)
{
iterator __i = find(__k);
if (__i != end())
return __i->second;
__node_holder __h = __construct_node_with_key(__k);
pair<iterator, bool> __r = __table_.__node_insert_unique(__h.get());
__h.release();
return __r.first->second;
}
#endif // _LIBCPP_CXX03_MODE
template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
_Tp&
unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::at(const key_type& __k)
{
iterator __i = find(__k);
if (__i == end())
__throw_out_of_range("unordered_map::at: key not found");
return __i->second;
}
template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
const _Tp&
unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>::at(const key_type& __k) const
{
const_iterator __i = find(__k);
if (__i == end())
__throw_out_of_range("unordered_map::at: key not found");
return __i->second;
}
template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
inline _LIBCPP_INLINE_VISIBILITY
void
swap(unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __x,
unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __y)
_NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
{
__x.swap(__y);
}
#if _LIBCPP_STD_VER > 17
template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc, class _Predicate>
inline _LIBCPP_INLINE_VISIBILITY
void erase_if(unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __c, _Predicate __pred)
{ __libcpp_erase_if_container(__c, __pred); }
#endif
template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
bool
operator==(const unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __x,
const unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __y)
{
if (__x.size() != __y.size())
return false;
typedef typename unordered_map<_Key, _Tp, _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->first);
if (__j == __ey || !(*__i == *__j))
return false;
}
return true;
}
template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
inline _LIBCPP_INLINE_VISIBILITY
bool
operator!=(const unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __x,
const unordered_map<_Key, _Tp, _Hash, _Pred, _Alloc>& __y)
{
return !(__x == __y);
}
template <class _Key, class _Tp, class _Hash = hash<_Key>, class _Pred = equal_to<_Key>,
class _Alloc = allocator<pair<const _Key, _Tp> > >
class _LIBCPP_TEMPLATE_VIS unordered_multimap
{
public:
// types
typedef _Key key_type;
typedef _Tp mapped_type;
typedef typename __identity<_Hash>::type hasher;
typedef typename __identity<_Pred>::type key_equal;
typedef typename __identity<_Alloc>::type allocator_type;
typedef pair<const key_type, mapped_type> value_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_value_type<key_type, mapped_type> __value_type;
typedef __unordered_map_hasher<key_type, __value_type, hasher> __hasher;
typedef __unordered_map_equal<key_type, __value_type, key_equal> __key_equal;
typedef typename __rebind_alloc_helper<allocator_traits<allocator_type>,
__value_type>::type __allocator_type;
typedef __hash_table<__value_type, __hasher,
__key_equal, __allocator_type> __table;
__table __table_;
typedef typename __table::_NodeTypes _NodeTypes;
typedef typename __table::__node_traits __node_traits;
typedef typename __table::__node_allocator __node_allocator;
typedef typename __table::__node __node;
typedef __hash_map_node_destructor<__node_allocator> _Dp;
typedef unique_ptr<__node, _Dp> __node_holder;
typedef allocator_traits<allocator_type> __alloc_traits;
static_assert((is_same<typename __node_traits::size_type,
typename __alloc_traits::size_type>::value),
"Allocator uses different size_type for different types");
public:
typedef typename __alloc_traits::pointer pointer;
typedef typename __alloc_traits::const_pointer const_pointer;
typedef typename __table::size_type size_type;
typedef typename __table::difference_type difference_type;
typedef __hash_map_iterator<typename __table::iterator> iterator;
typedef __hash_map_const_iterator<typename __table::const_iterator> const_iterator;
typedef __hash_map_iterator<typename __table::local_iterator> local_iterator;
typedef __hash_map_const_iterator<typename __table::const_local_iterator> const_local_iterator;
#if _LIBCPP_STD_VER > 14
typedef __map_node_handle<__node, allocator_type> node_type;
#endif
template <class _Key2, class _Tp2, class _Hash2, class _Pred2, class _Alloc2>
friend class _LIBCPP_TEMPLATE_VIS unordered_map;
template <class _Key2, class _Tp2, class _Hash2, class _Pred2, class _Alloc2>
friend class _LIBCPP_TEMPLATE_VIS unordered_multimap;
_LIBCPP_INLINE_VISIBILITY
unordered_multimap()
_NOEXCEPT_(is_nothrow_default_constructible<__table>::value)
{
#if _LIBCPP_DEBUG_LEVEL >= 2
__get_db()->__insert_c(this);
#endif
}
explicit unordered_multimap(size_type __n, const hasher& __hf = hasher(),
const key_equal& __eql = key_equal());
unordered_multimap(size_type __n, const hasher& __hf,
const key_equal& __eql,
const allocator_type& __a);
template <class _InputIterator>
unordered_multimap(_InputIterator __first, _InputIterator __last);
template <class _InputIterator>
unordered_multimap(_InputIterator __first, _InputIterator __last,
size_type __n, const hasher& __hf = hasher(),
const key_equal& __eql = key_equal());
template <class _InputIterator>
unordered_multimap(_InputIterator __first, _InputIterator __last,
size_type __n, const hasher& __hf,
const key_equal& __eql,
const allocator_type& __a);
_LIBCPP_INLINE_VISIBILITY
explicit unordered_multimap(const allocator_type& __a);
unordered_multimap(const unordered_multimap& __u);
unordered_multimap(const unordered_multimap& __u, const allocator_type& __a);
#ifndef _LIBCPP_CXX03_LANG
_LIBCPP_INLINE_VISIBILITY
unordered_multimap(unordered_multimap&& __u)
_NOEXCEPT_(is_nothrow_move_constructible<__table>::value);
unordered_multimap(unordered_multimap&& __u, const allocator_type& __a);
unordered_multimap(initializer_list<value_type> __il);
unordered_multimap(initializer_list<value_type> __il, size_type __n,
const hasher& __hf = hasher(),
const key_equal& __eql = key_equal());
unordered_multimap(initializer_list<value_type> __il, size_type __n,
const hasher& __hf, const key_equal& __eql,
const allocator_type& __a);
#endif // _LIBCPP_CXX03_LANG
#if _LIBCPP_STD_VER > 11
_LIBCPP_INLINE_VISIBILITY
unordered_multimap(size_type __n, const allocator_type& __a)
: unordered_multimap(__n, hasher(), key_equal(), __a) {}
_LIBCPP_INLINE_VISIBILITY
unordered_multimap(size_type __n, const hasher& __hf, const allocator_type& __a)
: unordered_multimap(__n, __hf, key_equal(), __a) {}
template <class _InputIterator>
_LIBCPP_INLINE_VISIBILITY
unordered_multimap(_InputIterator __first, _InputIterator __last, size_type __n, const allocator_type& __a)
: unordered_multimap(__first, __last, __n, hasher(), key_equal(), __a) {}
template <class _InputIterator>
_LIBCPP_INLINE_VISIBILITY
unordered_multimap(_InputIterator __first, _InputIterator __last, size_type __n, const hasher& __hf,
const allocator_type& __a)
: unordered_multimap(__first, __last, __n, __hf, key_equal(), __a) {}
_LIBCPP_INLINE_VISIBILITY
unordered_multimap(initializer_list<value_type> __il, size_type __n, const allocator_type& __a)
: unordered_multimap(__il, __n, hasher(), key_equal(), __a) {}
_LIBCPP_INLINE_VISIBILITY
unordered_multimap(initializer_list<value_type> __il, size_type __n, const hasher& __hf,
const allocator_type& __a)
: unordered_multimap(__il, __n, __hf, key_equal(), __a) {}
#endif
_LIBCPP_INLINE_VISIBILITY
~unordered_multimap() {
static_assert(sizeof(__diagnose_unordered_container_requirements<_Key, _Hash, _Pred>(0)), "");
}
_LIBCPP_INLINE_VISIBILITY
unordered_multimap& operator=(const unordered_multimap& __u)
{
#ifndef _LIBCPP_CXX03_LANG
__table_ = __u.__table_;
#else
if (this != &__u) {
__table_.clear();
__table_.hash_function() = __u.__table_.hash_function();
__table_.key_eq() = __u.__table_.key_eq();
__table_.max_load_factor() = __u.__table_.max_load_factor();
__table_.__copy_assign_alloc(__u.__table_);
insert(__u.begin(), __u.end());
}
#endif
return *this;
}
#ifndef _LIBCPP_CXX03_LANG
_LIBCPP_INLINE_VISIBILITY
unordered_multimap& operator=(unordered_multimap&& __u)
_NOEXCEPT_(is_nothrow_move_assignable<__table>::value);
_LIBCPP_INLINE_VISIBILITY
unordered_multimap& 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();}
_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.__i_, __x);}
template <class _InputIterator>
_LIBCPP_INLINE_VISIBILITY
void insert(_InputIterator __first, _InputIterator __last);
#ifndef _LIBCPP_CXX03_LANG
_LIBCPP_INLINE_VISIBILITY
void insert(initializer_list<value_type> __il)
{insert(__il.begin(), __il.end());}
_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.__i_, _VSTD::move(__x));}
template <class _Pp,
class = typename enable_if<is_constructible<value_type, _Pp>::value>::type>
_LIBCPP_INLINE_VISIBILITY
iterator insert(_Pp&& __x)
{return __table_.__insert_multi(_VSTD::forward<_Pp>(__x));}
template <class _Pp,
class = typename enable_if<is_constructible<value_type, _Pp>::value>::type>
_LIBCPP_INLINE_VISIBILITY
iterator insert(const_iterator __p, _Pp&& __x)
{return __table_.__insert_multi(__p.__i_, _VSTD::forward<_Pp>(__x));}
template <class... _Args>
iterator emplace(_Args&&... __args) {
return __table_.__emplace_multi(_VSTD::forward<_Args>(__args)...);
}
template <class... _Args>
iterator emplace_hint(const_iterator __p, _Args&&... __args) {
return __table_.__emplace_hint_multi(__p.__i_, _VSTD::forward<_Args>(__args)...);
}
#endif // _LIBCPP_CXX03_LANG
_LIBCPP_INLINE_VISIBILITY
iterator erase(const_iterator __p) {return __table_.erase(__p.__i_);}
_LIBCPP_INLINE_VISIBILITY
iterator erase(iterator __p) {return __table_.erase(__p.__i_);}
_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.__i_, __last.__i_);}
_LIBCPP_INLINE_VISIBILITY
void clear() _NOEXCEPT {__table_.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 unordered_multimap::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_multimap::insert()");
return __table_.template __node_handle_insert_multi<node_type>(
__hint.__i_, _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.__i_);
}
template <class _H2, class _P2>
_LIBCPP_INLINE_VISIBILITY
void merge(unordered_multimap<key_type, mapped_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_multimap<key_type, mapped_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_map<key_type, mapped_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_map<key_type, mapped_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
void swap(unordered_multimap& __u)
_NOEXCEPT_(__is_nothrow_swappable<__table>::value)
{__table_.swap(__u.__table_);}
_LIBCPP_INLINE_VISIBILITY
hasher hash_function() const
{return __table_.hash_function().hash_function();}
_LIBCPP_INLINE_VISIBILITY
key_equal key_eq() const
{return __table_.key_eq().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->__i_);}
bool __decrementable(const const_iterator* __i) const
{return __table_.__decrementable(&__i->__i_);}
bool __addable(const const_iterator* __i, ptrdiff_t __n) const
{return __table_.__addable(&__i->__i_, __n);}
bool __subscriptable(const const_iterator* __i, ptrdiff_t __n) const
{return __table_.__addable(&__i->__i_, __n);}
#endif // _LIBCPP_DEBUG_LEVEL >= 2
};
#ifndef _LIBCPP_HAS_NO_DEDUCTION_GUIDES
template<class _InputIterator,
class _Hash = hash<__iter_key_type<_InputIterator>>,
class _Pred = equal_to<__iter_key_type<_InputIterator>>,
class _Allocator = allocator<__iter_to_alloc_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_multimap(_InputIterator, _InputIterator, typename allocator_traits<_Allocator>::size_type = 0,
_Hash = _Hash(), _Pred = _Pred(), _Allocator = _Allocator())
-> unordered_multimap<__iter_key_type<_InputIterator>, __iter_mapped_type<_InputIterator>, _Hash, _Pred, _Allocator>;
template<class _Key, class _Tp, class _Hash = hash<remove_const_t<_Key>>,
class _Pred = equal_to<remove_const_t<_Key>>,
class _Allocator = allocator<pair<const _Key, _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_multimap(initializer_list<pair<_Key, _Tp>>, typename allocator_traits<_Allocator>::size_type = 0,
_Hash = _Hash(), _Pred = _Pred(), _Allocator = _Allocator())
-> unordered_multimap<remove_const_t<_Key>, _Tp, _Hash, _Pred, _Allocator>;
template<class _InputIterator, class _Allocator,
class = _EnableIf<__is_allocator<_Allocator>::value>>
unordered_multimap(_InputIterator, _InputIterator, typename allocator_traits<_Allocator>::size_type, _Allocator)
-> unordered_multimap<__iter_key_type<_InputIterator>, __iter_mapped_type<_InputIterator>,
hash<__iter_key_type<_InputIterator>>, equal_to<__iter_key_type<_InputIterator>>, _Allocator>;
template<class _InputIterator, class _Allocator,
class = _EnableIf<__is_allocator<_Allocator>::value>>
unordered_multimap(_InputIterator, _InputIterator, _Allocator)
-> unordered_multimap<__iter_key_type<_InputIterator>, __iter_mapped_type<_InputIterator>,
hash<__iter_key_type<_InputIterator>>, equal_to<__iter_key_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_multimap(_InputIterator, _InputIterator, typename allocator_traits<_Allocator>::size_type, _Hash, _Allocator)
-> unordered_multimap<__iter_key_type<_InputIterator>, __iter_mapped_type<_InputIterator>,
_Hash, equal_to<__iter_key_type<_InputIterator>>, _Allocator>;
template<class _Key, class _Tp, class _Allocator,
class = _EnableIf<__is_allocator<_Allocator>::value>>
unordered_multimap(initializer_list<pair<_Key, _Tp>>, typename allocator_traits<_Allocator>::size_type, _Allocator)
-> unordered_multimap<remove_const_t<_Key>, _Tp,
hash<remove_const_t<_Key>>,
equal_to<remove_const_t<_Key>>, _Allocator>;
template<class _Key, class _Tp, class _Allocator,
class = _EnableIf<__is_allocator<_Allocator>::value>>
unordered_multimap(initializer_list<pair<_Key, _Tp>>, _Allocator)
-> unordered_multimap<remove_const_t<_Key>, _Tp,
hash<remove_const_t<_Key>>,
equal_to<remove_const_t<_Key>>, _Allocator>;
template<class _Key, 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_multimap(initializer_list<pair<_Key, _Tp>>, typename allocator_traits<_Allocator>::size_type, _Hash, _Allocator)
-> unordered_multimap<remove_const_t<_Key>, _Tp, _Hash,
equal_to<remove_const_t<_Key>>, _Allocator>;
#endif
template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
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 _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
size_type __n, const hasher& __hf, const key_equal& __eql,
const allocator_type& __a)
: __table_(__hf, __eql, typename __table::allocator_type(__a))
{
#if _LIBCPP_DEBUG_LEVEL >= 2
__get_db()->__insert_c(this);
#endif
__table_.rehash(__n);
}
template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
template <class _InputIterator>
unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
_InputIterator __first, _InputIterator __last)
{
#if _LIBCPP_DEBUG_LEVEL >= 2
__get_db()->__insert_c(this);
#endif
insert(__first, __last);
}
template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
template <class _InputIterator>
unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
_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 _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
template <class _InputIterator>
unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
_InputIterator __first, _InputIterator __last, size_type __n,
const hasher& __hf, const key_equal& __eql, const allocator_type& __a)
: __table_(__hf, __eql, typename __table::allocator_type(__a))
{
#if _LIBCPP_DEBUG_LEVEL >= 2
__get_db()->__insert_c(this);
#endif
__table_.rehash(__n);
insert(__first, __last);
}
template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
inline
unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
const allocator_type& __a)
: __table_(typename __table::allocator_type(__a))
{
#if _LIBCPP_DEBUG_LEVEL >= 2
__get_db()->__insert_c(this);
#endif
}
template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
const unordered_multimap& __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 _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
const unordered_multimap& __u, const allocator_type& __a)
: __table_(__u.__table_, typename __table::allocator_type(__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 _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
inline
unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
unordered_multimap&& __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 _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
unordered_multimap&& __u, const allocator_type& __a)
: __table_(_VSTD::move(__u.__table_), typename __table::allocator_type(__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(
__u.__table_.remove((__i++).__i_)->__value_.__move());
}
}
#if _LIBCPP_DEBUG_LEVEL >= 2
else
__get_db()->swap(this, &__u);
#endif
}
template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
initializer_list<value_type> __il)
{
#if _LIBCPP_DEBUG_LEVEL >= 2
__get_db()->__insert_c(this);
#endif
insert(__il.begin(), __il.end());
}
template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
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 _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::unordered_multimap(
initializer_list<value_type> __il, size_type __n, const hasher& __hf,
const key_equal& __eql, const allocator_type& __a)
: __table_(__hf, __eql, typename __table::allocator_type(__a))
{
#if _LIBCPP_DEBUG_LEVEL >= 2
__get_db()->__insert_c(this);
#endif
__table_.rehash(__n);
insert(__il.begin(), __il.end());
}
template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
inline
unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>&
unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::operator=(unordered_multimap&& __u)
_NOEXCEPT_(is_nothrow_move_assignable<__table>::value)
{
__table_ = _VSTD::move(__u.__table_);
return *this;
}
template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
inline
unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>&
unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::operator=(
initializer_list<value_type> __il)
{
__table_.__assign_multi(__il.begin(), __il.end());
return *this;
}
#endif // _LIBCPP_CXX03_LANG
template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
template <class _InputIterator>
inline
void
unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>::insert(_InputIterator __first,
_InputIterator __last)
{
for (; __first != __last; ++__first)
__table_.__insert_multi(*__first);
}
template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
inline _LIBCPP_INLINE_VISIBILITY
void
swap(unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __x,
unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __y)
_NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
{
__x.swap(__y);
}
#if _LIBCPP_STD_VER > 17
template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc, class _Predicate>
inline _LIBCPP_INLINE_VISIBILITY
void erase_if(unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __c, _Predicate __pred)
{ __libcpp_erase_if_container(__c, __pred); }
#endif
template <class _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
bool
operator==(const unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __x,
const unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __y)
{
if (__x.size() != __y.size())
return false;
typedef typename unordered_multimap<_Key, _Tp, _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->first);
_EqRng __yeq = __y.equal_range(__i->first);
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 _Key, class _Tp, class _Hash, class _Pred, class _Alloc>
inline _LIBCPP_INLINE_VISIBILITY
bool
operator!=(const unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __x,
const unordered_multimap<_Key, _Tp, _Hash, _Pred, _Alloc>& __y)
{
return !(__x == __y);
}
_LIBCPP_END_NAMESPACE_STD
#endif // _LIBCPP_UNORDERED_MAP
| 99,351 | 2,446 | jart/cosmopolitan | false |
cosmopolitan/third_party/libcxx/functional | // -*- C++ -*-
//===------------------------ functional ----------------------------------===//
//
// 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
#define _LIBCPP_FUNCTIONAL
#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/memory"
#include "third_party/libcxx/tuple"
#include "third_party/libcxx/utility"
#include "third_party/libcxx/version"
#include "third_party/libcxx/__functional_base"
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
#pragma GCC system_header
#endif
/*
functional synopsis
namespace std
{
template <class Arg, class Result>
struct unary_function
{
typedef Arg argument_type;
typedef Result result_type;
};
template <class Arg1, class Arg2, class Result>
struct binary_function
{
typedef Arg1 first_argument_type;
typedef Arg2 second_argument_type;
typedef Result result_type;
};
template <class T>
class reference_wrapper
: public unary_function<T1, R> // if wrapping a unary functor
: public binary_function<T1, T2, R> // if wraping a binary functor
{
public:
// types
typedef T type;
typedef see below result_type; // Not always defined
// construct/copy/destroy
reference_wrapper(T&) noexcept;
reference_wrapper(T&&) = delete; // do not bind to temps
reference_wrapper(const reference_wrapper<T>& x) noexcept;
// assignment
reference_wrapper& operator=(const reference_wrapper<T>& x) noexcept;
// access
operator T& () const noexcept;
T& get() const noexcept;
// invoke
template <class... ArgTypes>
typename result_of<T&(ArgTypes&&...)>::type
operator() (ArgTypes&&...) const;
};
template <class T> reference_wrapper<T> ref(T& t) noexcept;
template <class T> void ref(const T&& t) = delete;
template <class T> reference_wrapper<T> ref(reference_wrapper<T>t) noexcept;
template <class T> reference_wrapper<const T> cref(const T& t) noexcept;
template <class T> void cref(const T&& t) = delete;
template <class T> reference_wrapper<const T> cref(reference_wrapper<T> t) noexcept;
template <class T> struct unwrap_reference; // since C++20
template <class T> struct unwrap_ref_decay : unwrap_reference<decay_t<T>> { }; // since C++20
template <class T> using unwrap_reference_t = typename unwrap_reference<T>::type; // since C++20
template <class T> using unwrap_ref_decay_t = typename unwrap_ref_decay<T>::type; // since C++20
template <class T> // <class T=void> in C++14
struct plus : binary_function<T, T, T>
{
T operator()(const T& x, const T& y) const;
};
template <class T> // <class T=void> in C++14
struct minus : binary_function<T, T, T>
{
T operator()(const T& x, const T& y) const;
};
template <class T> // <class T=void> in C++14
struct multiplies : binary_function<T, T, T>
{
T operator()(const T& x, const T& y) const;
};
template <class T> // <class T=void> in C++14
struct divides : binary_function<T, T, T>
{
T operator()(const T& x, const T& y) const;
};
template <class T> // <class T=void> in C++14
struct modulus : binary_function<T, T, T>
{
T operator()(const T& x, const T& y) const;
};
template <class T> // <class T=void> in C++14
struct negate : unary_function<T, T>
{
T operator()(const T& x) const;
};
template <class T> // <class T=void> in C++14
struct equal_to : binary_function<T, T, bool>
{
bool operator()(const T& x, const T& y) const;
};
template <class T> // <class T=void> in C++14
struct not_equal_to : binary_function<T, T, bool>
{
bool operator()(const T& x, const T& y) const;
};
template <class T> // <class T=void> in C++14
struct greater : binary_function<T, T, bool>
{
bool operator()(const T& x, const T& y) const;
};
template <class T> // <class T=void> in C++14
struct less : binary_function<T, T, bool>
{
bool operator()(const T& x, const T& y) const;
};
template <class T> // <class T=void> in C++14
struct greater_equal : binary_function<T, T, bool>
{
bool operator()(const T& x, const T& y) const;
};
template <class T> // <class T=void> in C++14
struct less_equal : binary_function<T, T, bool>
{
bool operator()(const T& x, const T& y) const;
};
template <class T> // <class T=void> in C++14
struct logical_and : binary_function<T, T, bool>
{
bool operator()(const T& x, const T& y) const;
};
template <class T> // <class T=void> in C++14
struct logical_or : binary_function<T, T, bool>
{
bool operator()(const T& x, const T& y) const;
};
template <class T> // <class T=void> in C++14
struct logical_not : unary_function<T, bool>
{
bool operator()(const T& x) const;
};
template <class T> // <class T=void> in C++14
struct bit_and : unary_function<T, bool>
{
bool operator()(const T& x, const T& y) const;
};
template <class T> // <class T=void> in C++14
struct bit_or : unary_function<T, bool>
{
bool operator()(const T& x, const T& y) const;
};
template <class T> // <class T=void> in C++14
struct bit_xor : unary_function<T, bool>
{
bool operator()(const T& x, const T& y) const;
};
template <class T=void> // C++14
struct bit_xor : unary_function<T, bool>
{
bool operator()(const T& x) const;
};
template <class Predicate>
class unary_negate // deprecated in C++17
: public unary_function<typename Predicate::argument_type, bool>
{
public:
explicit unary_negate(const Predicate& pred);
bool operator()(const typename Predicate::argument_type& x) const;
};
template <class Predicate> // deprecated in C++17
unary_negate<Predicate> not1(const Predicate& pred);
template <class Predicate>
class binary_negate // deprecated in C++17
: public binary_function<typename Predicate::first_argument_type,
typename Predicate::second_argument_type,
bool>
{
public:
explicit binary_negate(const Predicate& pred);
bool operator()(const typename Predicate::first_argument_type& x,
const typename Predicate::second_argument_type& y) const;
};
template <class Predicate> // deprecated in C++17
binary_negate<Predicate> not2(const Predicate& pred);
template <class F> unspecified not_fn(F&& f); // C++17
template<class T> struct is_bind_expression;
template<class T> struct is_placeholder;
// See C++14 20.9.9, Function object binders
template <class T> inline constexpr bool is_bind_expression_v
= is_bind_expression<T>::value; // C++17
template <class T> inline constexpr int is_placeholder_v
= is_placeholder<T>::value; // C++17
template<class Fn, class... BoundArgs>
unspecified bind(Fn&&, BoundArgs&&...);
template<class R, class Fn, class... BoundArgs>
unspecified bind(Fn&&, BoundArgs&&...);
template<class F, class... Args>
invoke_result_t<F, Args...> invoke(F&& f, Args&&... args) // C++17
noexcept(is_nothrow_invocable_v<F, Args...>);
namespace placeholders {
// M is the implementation-defined number of placeholders
extern unspecified _1;
extern unspecified _2;
.
.
.
extern unspecified _Mp;
}
template <class Operation>
class binder1st // deprecated in C++11, removed in C++17
: public unary_function<typename Operation::second_argument_type,
typename Operation::result_type>
{
protected:
Operation op;
typename Operation::first_argument_type value;
public:
binder1st(const Operation& x, const typename Operation::first_argument_type y);
typename Operation::result_type operator()( typename Operation::second_argument_type& x) const;
typename Operation::result_type operator()(const typename Operation::second_argument_type& x) const;
};
template <class Operation, class T>
binder1st<Operation> bind1st(const Operation& op, const T& x); // deprecated in C++11, removed in C++17
template <class Operation>
class binder2nd // deprecated in C++11, removed in C++17
: public unary_function<typename Operation::first_argument_type,
typename Operation::result_type>
{
protected:
Operation op;
typename Operation::second_argument_type value;
public:
binder2nd(const Operation& x, const typename Operation::second_argument_type y);
typename Operation::result_type operator()( typename Operation::first_argument_type& x) const;
typename Operation::result_type operator()(const typename Operation::first_argument_type& x) const;
};
template <class Operation, class T>
binder2nd<Operation> bind2nd(const Operation& op, const T& x); // deprecated in C++11, removed in C++17
template <class Arg, class Result> // deprecated in C++11, removed in C++17
class pointer_to_unary_function : public unary_function<Arg, Result>
{
public:
explicit pointer_to_unary_function(Result (*f)(Arg));
Result operator()(Arg x) const;
};
template <class Arg, class Result>
pointer_to_unary_function<Arg,Result> ptr_fun(Result (*f)(Arg)); // deprecated in C++11, removed in C++17
template <class Arg1, class Arg2, class Result> // deprecated in C++11, removed in C++17
class pointer_to_binary_function : public binary_function<Arg1, Arg2, Result>
{
public:
explicit pointer_to_binary_function(Result (*f)(Arg1, Arg2));
Result operator()(Arg1 x, Arg2 y) const;
};
template <class Arg1, class Arg2, class Result>
pointer_to_binary_function<Arg1,Arg2,Result> ptr_fun(Result (*f)(Arg1,Arg2)); // deprecated in C++11, removed in C++17
template<class S, class T> // deprecated in C++11, removed in C++17
class mem_fun_t : public unary_function<T*, S>
{
public:
explicit mem_fun_t(S (T::*p)());
S operator()(T* p) const;
};
template<class S, class T, class A>
class mem_fun1_t : public binary_function<T*, A, S> // deprecated in C++11, removed in C++17
{
public:
explicit mem_fun1_t(S (T::*p)(A));
S operator()(T* p, A x) const;
};
template<class S, class T> mem_fun_t<S,T> mem_fun(S (T::*f)()); // deprecated in C++11, removed in C++17
template<class S, class T, class A> mem_fun1_t<S,T,A> mem_fun(S (T::*f)(A)); // deprecated in C++11, removed in C++17
template<class S, class T>
class mem_fun_ref_t : public unary_function<T, S> // deprecated in C++11, removed in C++17
{
public:
explicit mem_fun_ref_t(S (T::*p)());
S operator()(T& p) const;
};
template<class S, class T, class A>
class mem_fun1_ref_t : public binary_function<T, A, S> // deprecated in C++11, removed in C++17
{
public:
explicit mem_fun1_ref_t(S (T::*p)(A));
S operator()(T& p, A x) const;
};
template<class S, class T> mem_fun_ref_t<S,T> mem_fun_ref(S (T::*f)()); // deprecated in C++11, removed in C++17
template<class S, class T, class A> mem_fun1_ref_t<S,T,A> mem_fun_ref(S (T::*f)(A)); // deprecated in C++11, removed in C++17
template <class S, class T>
class const_mem_fun_t : public unary_function<const T*, S> // deprecated in C++11, removed in C++17
{
public:
explicit const_mem_fun_t(S (T::*p)() const);
S operator()(const T* p) const;
};
template <class S, class T, class A>
class const_mem_fun1_t : public binary_function<const T*, A, S> // deprecated in C++11, removed in C++17
{
public:
explicit const_mem_fun1_t(S (T::*p)(A) const);
S operator()(const T* p, A x) const;
};
template <class S, class T> const_mem_fun_t<S,T> mem_fun(S (T::*f)() const); // deprecated in C++11, removed in C++17
template <class S, class T, class A> const_mem_fun1_t<S,T,A> mem_fun(S (T::*f)(A) const); // deprecated in C++11, removed in C++17
template <class S, class T>
class const_mem_fun_ref_t : public unary_function<T, S> // deprecated in C++11, removed in C++17
{
public:
explicit const_mem_fun_ref_t(S (T::*p)() const);
S operator()(const T& p) const;
};
template <class S, class T, class A>
class const_mem_fun1_ref_t : public binary_function<T, A, S> // deprecated in C++11, removed in C++17
{
public:
explicit const_mem_fun1_ref_t(S (T::*p)(A) const);
S operator()(const T& p, A x) const;
};
template <class S, class T> const_mem_fun_ref_t<S,T> mem_fun_ref(S (T::*f)() const); // deprecated in C++11, removed in C++17
template <class S, class T, class A> const_mem_fun1_ref_t<S,T,A> mem_fun_ref(S (T::*f)(A) const); // deprecated in C++11, removed in C++17
template<class R, class T> unspecified mem_fn(R T::*);
class bad_function_call
: public exception
{
};
template<class> class function; // undefined
template<class R, class... ArgTypes>
class function<R(ArgTypes...)>
: public unary_function<T1, R> // iff sizeof...(ArgTypes) == 1 and
// ArgTypes contains T1
: public binary_function<T1, T2, R> // iff sizeof...(ArgTypes) == 2 and
// ArgTypes contains T1 and T2
{
public:
typedef R result_type;
// construct/copy/destroy:
function() noexcept;
function(nullptr_t) noexcept;
function(const function&);
function(function&&) noexcept;
template<class F>
function(F);
template<Allocator Alloc>
function(allocator_arg_t, const Alloc&) noexcept; // removed in C++17
template<Allocator Alloc>
function(allocator_arg_t, const Alloc&, nullptr_t) noexcept; // removed in C++17
template<Allocator Alloc>
function(allocator_arg_t, const Alloc&, const function&); // removed in C++17
template<Allocator Alloc>
function(allocator_arg_t, const Alloc&, function&&); // removed in C++17
template<class F, Allocator Alloc>
function(allocator_arg_t, const Alloc&, F); // removed in C++17
function& operator=(const function&);
function& operator=(function&&) noexcept;
function& operator=(nullptr_t) noexcept;
template<class F>
function& operator=(F&&);
template<class F>
function& operator=(reference_wrapper<F>) noexcept;
~function();
// function modifiers:
void swap(function&) noexcept;
template<class F, class Alloc>
void assign(F&&, const Alloc&); // Removed in C++17
// function capacity:
explicit operator bool() const noexcept;
// function invocation:
R operator()(ArgTypes...) const;
// function target access:
const std::type_info& target_type() const noexcept;
template <typename T> T* target() noexcept;
template <typename T> const T* target() const noexcept;
};
// Deduction guides
template<class R, class ...Args>
function(R(*)(Args...)) -> function<R(Args...)>; // since C++17
template<class F>
function(F) -> function<see-below>; // since C++17
// Null pointer comparisons:
template <class R, class ... ArgTypes>
bool operator==(const function<R(ArgTypes...)>&, nullptr_t) noexcept;
template <class R, class ... ArgTypes>
bool operator==(nullptr_t, const function<R(ArgTypes...)>&) noexcept;
template <class R, class ... ArgTypes>
bool operator!=(const function<R(ArgTypes...)>&, nullptr_t) noexcept;
template <class R, class ... ArgTypes>
bool operator!=(nullptr_t, const function<R(ArgTypes...)>&) noexcept;
// specialized algorithms:
template <class R, class ... ArgTypes>
void swap(function<R(ArgTypes...)>&, function<R(ArgTypes...)>&) noexcept;
template <class T> struct hash;
template <> struct hash<bool>;
template <> struct hash<char>;
template <> struct hash<signed char>;
template <> struct hash<unsigned char>;
template <> struct hash<char16_t>;
template <> struct hash<char32_t>;
template <> struct hash<wchar_t>;
template <> struct hash<short>;
template <> struct hash<unsigned short>;
template <> struct hash<int>;
template <> struct hash<unsigned int>;
template <> struct hash<long>;
template <> struct hash<long long>;
template <> struct hash<unsigned long>;
template <> struct hash<unsigned long long>;
template <> struct hash<float>;
template <> struct hash<double>;
template <> struct hash<long double>;
template<class T> struct hash<T*>;
template <> struct hash<nullptr_t>; // C++17
} // std
POLICY: For non-variadic implementations, the number of arguments is limited
to 3. It is hoped that the need for non-variadic implementations
will be minimal.
*/
_LIBCPP_BEGIN_NAMESPACE_STD
#if _LIBCPP_STD_VER > 11
template <class _Tp = void>
#else
template <class _Tp>
#endif
struct _LIBCPP_TEMPLATE_VIS plus : binary_function<_Tp, _Tp, _Tp>
{
_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
_Tp operator()(const _Tp& __x, const _Tp& __y) const
{return __x + __y;}
};
#if _LIBCPP_STD_VER > 11
template <>
struct _LIBCPP_TEMPLATE_VIS plus<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
#if _LIBCPP_STD_VER > 11
template <class _Tp = void>
#else
template <class _Tp>
#endif
struct _LIBCPP_TEMPLATE_VIS minus : binary_function<_Tp, _Tp, _Tp>
{
_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
_Tp operator()(const _Tp& __x, const _Tp& __y) const
{return __x - __y;}
};
#if _LIBCPP_STD_VER > 11
template <>
struct _LIBCPP_TEMPLATE_VIS minus<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
#if _LIBCPP_STD_VER > 11
template <class _Tp = void>
#else
template <class _Tp>
#endif
struct _LIBCPP_TEMPLATE_VIS multiplies : binary_function<_Tp, _Tp, _Tp>
{
_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
_Tp operator()(const _Tp& __x, const _Tp& __y) const
{return __x * __y;}
};
#if _LIBCPP_STD_VER > 11
template <>
struct _LIBCPP_TEMPLATE_VIS multiplies<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
#if _LIBCPP_STD_VER > 11
template <class _Tp = void>
#else
template <class _Tp>
#endif
struct _LIBCPP_TEMPLATE_VIS divides : binary_function<_Tp, _Tp, _Tp>
{
_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
_Tp operator()(const _Tp& __x, const _Tp& __y) const
{return __x / __y;}
};
#if _LIBCPP_STD_VER > 11
template <>
struct _LIBCPP_TEMPLATE_VIS divides<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
#if _LIBCPP_STD_VER > 11
template <class _Tp = void>
#else
template <class _Tp>
#endif
struct _LIBCPP_TEMPLATE_VIS modulus : binary_function<_Tp, _Tp, _Tp>
{
_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
_Tp operator()(const _Tp& __x, const _Tp& __y) const
{return __x % __y;}
};
#if _LIBCPP_STD_VER > 11
template <>
struct _LIBCPP_TEMPLATE_VIS modulus<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
#if _LIBCPP_STD_VER > 11
template <class _Tp = void>
#else
template <class _Tp>
#endif
struct _LIBCPP_TEMPLATE_VIS negate : unary_function<_Tp, _Tp>
{
_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
_Tp operator()(const _Tp& __x) const
{return -__x;}
};
#if _LIBCPP_STD_VER > 11
template <>
struct _LIBCPP_TEMPLATE_VIS negate<void>
{
template <class _Tp>
_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
auto operator()(_Tp&& __x) const
_NOEXCEPT_(noexcept(- _VSTD::forward<_Tp>(__x)))
-> decltype (- _VSTD::forward<_Tp>(__x))
{ return - _VSTD::forward<_Tp>(__x); }
typedef void is_transparent;
};
#endif
#if _LIBCPP_STD_VER > 11
template <class _Tp = void>
#else
template <class _Tp>
#endif
struct _LIBCPP_TEMPLATE_VIS equal_to : 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 equal_to<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
#if _LIBCPP_STD_VER > 11
template <class _Tp = void>
#else
template <class _Tp>
#endif
struct _LIBCPP_TEMPLATE_VIS not_equal_to : 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 not_equal_to<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
#if _LIBCPP_STD_VER > 11
template <class _Tp = void>
#else
template <class _Tp>
#endif
struct _LIBCPP_TEMPLATE_VIS greater : 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 greater<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
// less in <__functional_base>
#if _LIBCPP_STD_VER > 11
template <class _Tp = void>
#else
template <class _Tp>
#endif
struct _LIBCPP_TEMPLATE_VIS greater_equal : 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 greater_equal<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
#if _LIBCPP_STD_VER > 11
template <class _Tp = void>
#else
template <class _Tp>
#endif
struct _LIBCPP_TEMPLATE_VIS less_equal : 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_equal<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
#if _LIBCPP_STD_VER > 11
template <class _Tp = void>
#else
template <class _Tp>
#endif
struct _LIBCPP_TEMPLATE_VIS logical_and : 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 logical_and<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
#if _LIBCPP_STD_VER > 11
template <class _Tp = void>
#else
template <class _Tp>
#endif
struct _LIBCPP_TEMPLATE_VIS logical_or : 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 logical_or<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
#if _LIBCPP_STD_VER > 11
template <class _Tp = void>
#else
template <class _Tp>
#endif
struct _LIBCPP_TEMPLATE_VIS logical_not : unary_function<_Tp, bool>
{
_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
bool operator()(const _Tp& __x) const
{return !__x;}
};
#if _LIBCPP_STD_VER > 11
template <>
struct _LIBCPP_TEMPLATE_VIS logical_not<void>
{
template <class _Tp>
_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
auto operator()(_Tp&& __x) const
_NOEXCEPT_(noexcept(!_VSTD::forward<_Tp>(__x)))
-> decltype (!_VSTD::forward<_Tp>(__x))
{ return !_VSTD::forward<_Tp>(__x); }
typedef void is_transparent;
};
#endif
#if _LIBCPP_STD_VER > 11
template <class _Tp = void>
#else
template <class _Tp>
#endif
struct _LIBCPP_TEMPLATE_VIS bit_and : binary_function<_Tp, _Tp, _Tp>
{
_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
_Tp operator()(const _Tp& __x, const _Tp& __y) const
{return __x & __y;}
};
#if _LIBCPP_STD_VER > 11
template <>
struct _LIBCPP_TEMPLATE_VIS bit_and<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
#if _LIBCPP_STD_VER > 11
template <class _Tp = void>
#else
template <class _Tp>
#endif
struct _LIBCPP_TEMPLATE_VIS bit_or : binary_function<_Tp, _Tp, _Tp>
{
_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
_Tp operator()(const _Tp& __x, const _Tp& __y) const
{return __x | __y;}
};
#if _LIBCPP_STD_VER > 11
template <>
struct _LIBCPP_TEMPLATE_VIS bit_or<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
#if _LIBCPP_STD_VER > 11
template <class _Tp = void>
#else
template <class _Tp>
#endif
struct _LIBCPP_TEMPLATE_VIS bit_xor : binary_function<_Tp, _Tp, _Tp>
{
_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
_Tp operator()(const _Tp& __x, const _Tp& __y) const
{return __x ^ __y;}
};
#if _LIBCPP_STD_VER > 11
template <>
struct _LIBCPP_TEMPLATE_VIS bit_xor<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
#if _LIBCPP_STD_VER > 11
template <class _Tp = void>
struct _LIBCPP_TEMPLATE_VIS bit_not : unary_function<_Tp, _Tp>
{
_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
_Tp operator()(const _Tp& __x) const
{return ~__x;}
};
template <>
struct _LIBCPP_TEMPLATE_VIS bit_not<void>
{
template <class _Tp>
_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
auto operator()(_Tp&& __x) const
_NOEXCEPT_(noexcept(~_VSTD::forward<_Tp>(__x)))
-> decltype (~_VSTD::forward<_Tp>(__x))
{ return ~_VSTD::forward<_Tp>(__x); }
typedef void is_transparent;
};
#endif
template <class _Predicate>
class _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX17 unary_negate
: public unary_function<typename _Predicate::argument_type, bool>
{
_Predicate __pred_;
public:
_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
explicit unary_negate(const _Predicate& __pred)
: __pred_(__pred) {}
_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
bool operator()(const typename _Predicate::argument_type& __x) const
{return !__pred_(__x);}
};
template <class _Predicate>
_LIBCPP_DEPRECATED_IN_CXX17 inline _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
unary_negate<_Predicate>
not1(const _Predicate& __pred) {return unary_negate<_Predicate>(__pred);}
template <class _Predicate>
class _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX17 binary_negate
: public binary_function<typename _Predicate::first_argument_type,
typename _Predicate::second_argument_type,
bool>
{
_Predicate __pred_;
public:
_LIBCPP_INLINE_VISIBILITY explicit _LIBCPP_CONSTEXPR_AFTER_CXX11
binary_negate(const _Predicate& __pred) : __pred_(__pred) {}
_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
bool operator()(const typename _Predicate::first_argument_type& __x,
const typename _Predicate::second_argument_type& __y) const
{return !__pred_(__x, __y);}
};
template <class _Predicate>
_LIBCPP_DEPRECATED_IN_CXX17 inline _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
binary_negate<_Predicate>
not2(const _Predicate& __pred) {return binary_negate<_Predicate>(__pred);}
#if _LIBCPP_STD_VER <= 14 || defined(_LIBCPP_ENABLE_CXX17_REMOVED_BINDERS)
template <class __Operation>
class _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX11 binder1st
: public unary_function<typename __Operation::second_argument_type,
typename __Operation::result_type>
{
protected:
__Operation op;
typename __Operation::first_argument_type value;
public:
_LIBCPP_INLINE_VISIBILITY binder1st(const __Operation& __x,
const typename __Operation::first_argument_type __y)
: op(__x), value(__y) {}
_LIBCPP_INLINE_VISIBILITY typename __Operation::result_type operator()
(typename __Operation::second_argument_type& __x) const
{return op(value, __x);}
_LIBCPP_INLINE_VISIBILITY typename __Operation::result_type operator()
(const typename __Operation::second_argument_type& __x) const
{return op(value, __x);}
};
template <class __Operation, class _Tp>
_LIBCPP_DEPRECATED_IN_CXX11 inline _LIBCPP_INLINE_VISIBILITY
binder1st<__Operation>
bind1st(const __Operation& __op, const _Tp& __x)
{return binder1st<__Operation>(__op, __x);}
template <class __Operation>
class _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX11 binder2nd
: public unary_function<typename __Operation::first_argument_type,
typename __Operation::result_type>
{
protected:
__Operation op;
typename __Operation::second_argument_type value;
public:
_LIBCPP_INLINE_VISIBILITY
binder2nd(const __Operation& __x, const typename __Operation::second_argument_type __y)
: op(__x), value(__y) {}
_LIBCPP_INLINE_VISIBILITY typename __Operation::result_type operator()
( typename __Operation::first_argument_type& __x) const
{return op(__x, value);}
_LIBCPP_INLINE_VISIBILITY typename __Operation::result_type operator()
(const typename __Operation::first_argument_type& __x) const
{return op(__x, value);}
};
template <class __Operation, class _Tp>
_LIBCPP_DEPRECATED_IN_CXX11 inline _LIBCPP_INLINE_VISIBILITY
binder2nd<__Operation>
bind2nd(const __Operation& __op, const _Tp& __x)
{return binder2nd<__Operation>(__op, __x);}
template <class _Arg, class _Result>
class _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX11 pointer_to_unary_function
: public unary_function<_Arg, _Result>
{
_Result (*__f_)(_Arg);
public:
_LIBCPP_INLINE_VISIBILITY explicit pointer_to_unary_function(_Result (*__f)(_Arg))
: __f_(__f) {}
_LIBCPP_INLINE_VISIBILITY _Result operator()(_Arg __x) const
{return __f_(__x);}
};
template <class _Arg, class _Result>
_LIBCPP_DEPRECATED_IN_CXX11 inline _LIBCPP_INLINE_VISIBILITY
pointer_to_unary_function<_Arg,_Result>
ptr_fun(_Result (*__f)(_Arg))
{return pointer_to_unary_function<_Arg,_Result>(__f);}
template <class _Arg1, class _Arg2, class _Result>
class _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX11 pointer_to_binary_function
: public binary_function<_Arg1, _Arg2, _Result>
{
_Result (*__f_)(_Arg1, _Arg2);
public:
_LIBCPP_INLINE_VISIBILITY explicit pointer_to_binary_function(_Result (*__f)(_Arg1, _Arg2))
: __f_(__f) {}
_LIBCPP_INLINE_VISIBILITY _Result operator()(_Arg1 __x, _Arg2 __y) const
{return __f_(__x, __y);}
};
template <class _Arg1, class _Arg2, class _Result>
_LIBCPP_DEPRECATED_IN_CXX11 inline _LIBCPP_INLINE_VISIBILITY
pointer_to_binary_function<_Arg1,_Arg2,_Result>
ptr_fun(_Result (*__f)(_Arg1,_Arg2))
{return pointer_to_binary_function<_Arg1,_Arg2,_Result>(__f);}
template<class _Sp, class _Tp>
class _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX11 mem_fun_t
: public unary_function<_Tp*, _Sp>
{
_Sp (_Tp::*__p_)();
public:
_LIBCPP_INLINE_VISIBILITY explicit mem_fun_t(_Sp (_Tp::*__p)())
: __p_(__p) {}
_LIBCPP_INLINE_VISIBILITY _Sp operator()(_Tp* __p) const
{return (__p->*__p_)();}
};
template<class _Sp, class _Tp, class _Ap>
class _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX11 mem_fun1_t
: public binary_function<_Tp*, _Ap, _Sp>
{
_Sp (_Tp::*__p_)(_Ap);
public:
_LIBCPP_INLINE_VISIBILITY explicit mem_fun1_t(_Sp (_Tp::*__p)(_Ap))
: __p_(__p) {}
_LIBCPP_INLINE_VISIBILITY _Sp operator()(_Tp* __p, _Ap __x) const
{return (__p->*__p_)(__x);}
};
template<class _Sp, class _Tp>
_LIBCPP_DEPRECATED_IN_CXX11 inline _LIBCPP_INLINE_VISIBILITY
mem_fun_t<_Sp,_Tp>
mem_fun(_Sp (_Tp::*__f)())
{return mem_fun_t<_Sp,_Tp>(__f);}
template<class _Sp, class _Tp, class _Ap>
_LIBCPP_DEPRECATED_IN_CXX11 inline _LIBCPP_INLINE_VISIBILITY
mem_fun1_t<_Sp,_Tp,_Ap>
mem_fun(_Sp (_Tp::*__f)(_Ap))
{return mem_fun1_t<_Sp,_Tp,_Ap>(__f);}
template<class _Sp, class _Tp>
class _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX11 mem_fun_ref_t
: public unary_function<_Tp, _Sp>
{
_Sp (_Tp::*__p_)();
public:
_LIBCPP_INLINE_VISIBILITY explicit mem_fun_ref_t(_Sp (_Tp::*__p)())
: __p_(__p) {}
_LIBCPP_INLINE_VISIBILITY _Sp operator()(_Tp& __p) const
{return (__p.*__p_)();}
};
template<class _Sp, class _Tp, class _Ap>
class _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX11 mem_fun1_ref_t
: public binary_function<_Tp, _Ap, _Sp>
{
_Sp (_Tp::*__p_)(_Ap);
public:
_LIBCPP_INLINE_VISIBILITY explicit mem_fun1_ref_t(_Sp (_Tp::*__p)(_Ap))
: __p_(__p) {}
_LIBCPP_INLINE_VISIBILITY _Sp operator()(_Tp& __p, _Ap __x) const
{return (__p.*__p_)(__x);}
};
template<class _Sp, class _Tp>
_LIBCPP_DEPRECATED_IN_CXX11 inline _LIBCPP_INLINE_VISIBILITY
mem_fun_ref_t<_Sp,_Tp>
mem_fun_ref(_Sp (_Tp::*__f)())
{return mem_fun_ref_t<_Sp,_Tp>(__f);}
template<class _Sp, class _Tp, class _Ap>
_LIBCPP_DEPRECATED_IN_CXX11 inline _LIBCPP_INLINE_VISIBILITY
mem_fun1_ref_t<_Sp,_Tp,_Ap>
mem_fun_ref(_Sp (_Tp::*__f)(_Ap))
{return mem_fun1_ref_t<_Sp,_Tp,_Ap>(__f);}
template <class _Sp, class _Tp>
class _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX11 const_mem_fun_t
: public unary_function<const _Tp*, _Sp>
{
_Sp (_Tp::*__p_)() const;
public:
_LIBCPP_INLINE_VISIBILITY explicit const_mem_fun_t(_Sp (_Tp::*__p)() const)
: __p_(__p) {}
_LIBCPP_INLINE_VISIBILITY _Sp operator()(const _Tp* __p) const
{return (__p->*__p_)();}
};
template <class _Sp, class _Tp, class _Ap>
class _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX11 const_mem_fun1_t
: public binary_function<const _Tp*, _Ap, _Sp>
{
_Sp (_Tp::*__p_)(_Ap) const;
public:
_LIBCPP_INLINE_VISIBILITY explicit const_mem_fun1_t(_Sp (_Tp::*__p)(_Ap) const)
: __p_(__p) {}
_LIBCPP_INLINE_VISIBILITY _Sp operator()(const _Tp* __p, _Ap __x) const
{return (__p->*__p_)(__x);}
};
template <class _Sp, class _Tp>
_LIBCPP_DEPRECATED_IN_CXX11 inline _LIBCPP_INLINE_VISIBILITY
const_mem_fun_t<_Sp,_Tp>
mem_fun(_Sp (_Tp::*__f)() const)
{return const_mem_fun_t<_Sp,_Tp>(__f);}
template <class _Sp, class _Tp, class _Ap>
_LIBCPP_DEPRECATED_IN_CXX11 inline _LIBCPP_INLINE_VISIBILITY
const_mem_fun1_t<_Sp,_Tp,_Ap>
mem_fun(_Sp (_Tp::*__f)(_Ap) const)
{return const_mem_fun1_t<_Sp,_Tp,_Ap>(__f);}
template <class _Sp, class _Tp>
class _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX11 const_mem_fun_ref_t
: public unary_function<_Tp, _Sp>
{
_Sp (_Tp::*__p_)() const;
public:
_LIBCPP_INLINE_VISIBILITY explicit const_mem_fun_ref_t(_Sp (_Tp::*__p)() const)
: __p_(__p) {}
_LIBCPP_INLINE_VISIBILITY _Sp operator()(const _Tp& __p) const
{return (__p.*__p_)();}
};
template <class _Sp, class _Tp, class _Ap>
class _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX11 const_mem_fun1_ref_t
: public binary_function<_Tp, _Ap, _Sp>
{
_Sp (_Tp::*__p_)(_Ap) const;
public:
_LIBCPP_INLINE_VISIBILITY explicit const_mem_fun1_ref_t(_Sp (_Tp::*__p)(_Ap) const)
: __p_(__p) {}
_LIBCPP_INLINE_VISIBILITY _Sp operator()(const _Tp& __p, _Ap __x) const
{return (__p.*__p_)(__x);}
};
template <class _Sp, class _Tp>
_LIBCPP_DEPRECATED_IN_CXX11 inline _LIBCPP_INLINE_VISIBILITY
const_mem_fun_ref_t<_Sp,_Tp>
mem_fun_ref(_Sp (_Tp::*__f)() const)
{return const_mem_fun_ref_t<_Sp,_Tp>(__f);}
template <class _Sp, class _Tp, class _Ap>
_LIBCPP_DEPRECATED_IN_CXX11 inline _LIBCPP_INLINE_VISIBILITY
const_mem_fun1_ref_t<_Sp,_Tp,_Ap>
mem_fun_ref(_Sp (_Tp::*__f)(_Ap) const)
{return const_mem_fun1_ref_t<_Sp,_Tp,_Ap>(__f);}
#endif
////////////////////////////////////////////////////////////////////////////////
// MEMFUN
//==============================================================================
template <class _Tp>
class __mem_fn
: public __weak_result_type<_Tp>
{
public:
// types
typedef _Tp type;
private:
type __f_;
public:
_LIBCPP_INLINE_VISIBILITY __mem_fn(type __f) _NOEXCEPT : __f_(__f) {}
#ifndef _LIBCPP_CXX03_LANG
// invoke
template <class... _ArgTypes>
_LIBCPP_INLINE_VISIBILITY
typename __invoke_return<type, _ArgTypes...>::type
operator() (_ArgTypes&&... __args) const {
return __invoke(__f_, _VSTD::forward<_ArgTypes>(__args)...);
}
#else
template <class _A0>
_LIBCPP_INLINE_VISIBILITY
typename __invoke_return0<type, _A0>::type
operator() (_A0& __a0) const {
return __invoke(__f_, __a0);
}
template <class _A0>
_LIBCPP_INLINE_VISIBILITY
typename __invoke_return0<type, _A0 const>::type
operator() (_A0 const& __a0) const {
return __invoke(__f_, __a0);
}
template <class _A0, class _A1>
_LIBCPP_INLINE_VISIBILITY
typename __invoke_return1<type, _A0, _A1>::type
operator() (_A0& __a0, _A1& __a1) const {
return __invoke(__f_, __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(__f_, __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(__f_, __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(__f_, __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(__f_, __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(__f_, __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(__f_, __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(__f_, __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(__f_, __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(__f_, __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(__f_, __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(__f_, __a0, __a1, __a2);
}
#endif
};
template<class _Rp, class _Tp>
inline _LIBCPP_INLINE_VISIBILITY
__mem_fn<_Rp _Tp::*>
mem_fn(_Rp _Tp::* __pm) _NOEXCEPT
{
return __mem_fn<_Rp _Tp::*>(__pm);
}
////////////////////////////////////////////////////////////////////////////////
// FUNCTION
//==============================================================================
// bad_function_call
class _LIBCPP_EXCEPTION_ABI bad_function_call
: public exception
{
#ifdef _LIBCPP_ABI_BAD_FUNCTION_CALL_KEY_FUNCTION
public:
virtual ~bad_function_call() _NOEXCEPT;
virtual const char* what() const _NOEXCEPT;
#endif
};
_LIBCPP_NORETURN inline _LIBCPP_INLINE_VISIBILITY
void __throw_bad_function_call()
{
#ifndef _LIBCPP_NO_EXCEPTIONS
throw bad_function_call();
#else
_VSTD::abort();
#endif
}
template<class _Fp> class _LIBCPP_TEMPLATE_VIS function; // undefined
namespace __function
{
template<class _Rp>
struct __maybe_derive_from_unary_function
{
};
template<class _Rp, class _A1>
struct __maybe_derive_from_unary_function<_Rp(_A1)>
: public unary_function<_A1, _Rp>
{
};
template<class _Rp>
struct __maybe_derive_from_binary_function
{
};
template<class _Rp, class _A1, class _A2>
struct __maybe_derive_from_binary_function<_Rp(_A1, _A2)>
: public binary_function<_A1, _A2, _Rp>
{
};
template <class _Fp>
_LIBCPP_INLINE_VISIBILITY
bool __not_null(_Fp const&) { return true; }
template <class _Fp>
_LIBCPP_INLINE_VISIBILITY
bool __not_null(_Fp* __ptr) { return __ptr; }
template <class _Ret, class _Class>
_LIBCPP_INLINE_VISIBILITY
bool __not_null(_Ret _Class::*__ptr) { return __ptr; }
template <class _Fp>
_LIBCPP_INLINE_VISIBILITY
bool __not_null(function<_Fp> const& __f) { return !!__f; }
} // namespace __function
#ifndef _LIBCPP_CXX03_LANG
namespace __function {
// __alloc_func holds a functor and an allocator.
template <class _Fp, class _Ap, class _FB> class __alloc_func;
template <class _Fp, class _FB>
class __default_alloc_func;
template <class _Fp, class _Ap, class _Rp, class... _ArgTypes>
class __alloc_func<_Fp, _Ap, _Rp(_ArgTypes...)>
{
__compressed_pair<_Fp, _Ap> __f_;
public:
typedef _LIBCPP_NODEBUG_TYPE _Fp _Target;
typedef _LIBCPP_NODEBUG_TYPE _Ap _Alloc;
_LIBCPP_INLINE_VISIBILITY
const _Target& __target() const { return __f_.first(); }
// WIN32 APIs may define __allocator, so use __get_allocator instead.
_LIBCPP_INLINE_VISIBILITY
const _Alloc& __get_allocator() const { return __f_.second(); }
_LIBCPP_INLINE_VISIBILITY
explicit __alloc_func(_Target&& __f)
: __f_(piecewise_construct, _VSTD::forward_as_tuple(_VSTD::move(__f)),
_VSTD::forward_as_tuple())
{
}
_LIBCPP_INLINE_VISIBILITY
explicit __alloc_func(const _Target& __f, const _Alloc& __a)
: __f_(piecewise_construct, _VSTD::forward_as_tuple(__f),
_VSTD::forward_as_tuple(__a))
{
}
_LIBCPP_INLINE_VISIBILITY
explicit __alloc_func(const _Target& __f, _Alloc&& __a)
: __f_(piecewise_construct, _VSTD::forward_as_tuple(__f),
_VSTD::forward_as_tuple(_VSTD::move(__a)))
{
}
_LIBCPP_INLINE_VISIBILITY
explicit __alloc_func(_Target&& __f, _Alloc&& __a)
: __f_(piecewise_construct, _VSTD::forward_as_tuple(_VSTD::move(__f)),
_VSTD::forward_as_tuple(_VSTD::move(__a)))
{
}
_LIBCPP_INLINE_VISIBILITY
_Rp operator()(_ArgTypes&&... __arg)
{
typedef __invoke_void_return_wrapper<_Rp> _Invoker;
return _Invoker::__call(__f_.first(),
_VSTD::forward<_ArgTypes>(__arg)...);
}
_LIBCPP_INLINE_VISIBILITY
__alloc_func* __clone() const
{
typedef allocator_traits<_Alloc> __alloc_traits;
typedef
typename __rebind_alloc_helper<__alloc_traits, __alloc_func>::type
_AA;
_AA __a(__f_.second());
typedef __allocator_destructor<_AA> _Dp;
unique_ptr<__alloc_func, _Dp> __hold(__a.allocate(1), _Dp(__a, 1));
::new ((void*)__hold.get()) __alloc_func(__f_.first(), _Alloc(__a));
return __hold.release();
}
_LIBCPP_INLINE_VISIBILITY
void destroy() _NOEXCEPT { __f_.~__compressed_pair<_Target, _Alloc>(); }
static void __destroy_and_delete(__alloc_func* __f) {
typedef allocator_traits<_Alloc> __alloc_traits;
typedef typename __rebind_alloc_helper<__alloc_traits, __alloc_func>::type
_FunAlloc;
_FunAlloc __a(__f->__get_allocator());
__f->destroy();
__a.deallocate(__f, 1);
}
};
template <class _Fp, class _Rp, class... _ArgTypes>
class __default_alloc_func<_Fp, _Rp(_ArgTypes...)> {
_Fp __f_;
public:
typedef _LIBCPP_NODEBUG_TYPE _Fp _Target;
_LIBCPP_INLINE_VISIBILITY
const _Target& __target() const { return __f_; }
_LIBCPP_INLINE_VISIBILITY
explicit __default_alloc_func(_Target&& __f) : __f_(std::move(__f)) {}
_LIBCPP_INLINE_VISIBILITY
explicit __default_alloc_func(const _Target& __f) : __f_(__f) {}
_LIBCPP_INLINE_VISIBILITY
_Rp operator()(_ArgTypes&&... __arg) {
typedef __invoke_void_return_wrapper<_Rp> _Invoker;
return _Invoker::__call(__f_, _VSTD::forward<_ArgTypes>(__arg)...);
}
_LIBCPP_INLINE_VISIBILITY
__default_alloc_func* __clone() const {
__builtin_new_allocator::__holder_t __hold =
__builtin_new_allocator::__allocate_type<__default_alloc_func>(1);
__default_alloc_func* __res =
::new (__hold.get()) __default_alloc_func(__f_);
(void)__hold.release();
return __res;
}
_LIBCPP_INLINE_VISIBILITY
void destroy() _NOEXCEPT { __f_.~_Target(); }
static void __destroy_and_delete(__default_alloc_func* __f) {
__f->destroy();
__builtin_new_allocator::__deallocate_type<__default_alloc_func>(__f, 1);
}
};
// __base provides an abstract interface for copyable functors.
template<class _Fp> class __base;
template<class _Rp, class ..._ArgTypes>
class __base<_Rp(_ArgTypes...)>
{
__base(const __base&);
__base& operator=(const __base&);
public:
_LIBCPP_INLINE_VISIBILITY __base() {}
_LIBCPP_INLINE_VISIBILITY virtual ~__base() {}
virtual __base* __clone() const = 0;
virtual void __clone(__base*) const = 0;
virtual void destroy() _NOEXCEPT = 0;
virtual void destroy_deallocate() _NOEXCEPT = 0;
virtual _Rp operator()(_ArgTypes&& ...) = 0;
#ifndef _LIBCPP_NO_RTTI
virtual const void* target(const type_info&) const _NOEXCEPT = 0;
virtual const std::type_info& target_type() const _NOEXCEPT = 0;
#endif // _LIBCPP_NO_RTTI
};
// __func implements __base for a given functor type.
template<class _FD, class _Alloc, class _FB> class __func;
template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes>
class __func<_Fp, _Alloc, _Rp(_ArgTypes...)>
: public __base<_Rp(_ArgTypes...)>
{
__alloc_func<_Fp, _Alloc, _Rp(_ArgTypes...)> __f_;
public:
_LIBCPP_INLINE_VISIBILITY
explicit __func(_Fp&& __f)
: __f_(_VSTD::move(__f)) {}
_LIBCPP_INLINE_VISIBILITY
explicit __func(const _Fp& __f, const _Alloc& __a)
: __f_(__f, __a) {}
_LIBCPP_INLINE_VISIBILITY
explicit __func(const _Fp& __f, _Alloc&& __a)
: __f_(__f, _VSTD::move(__a)) {}
_LIBCPP_INLINE_VISIBILITY
explicit __func(_Fp&& __f, _Alloc&& __a)
: __f_(_VSTD::move(__f), _VSTD::move(__a)) {}
virtual __base<_Rp(_ArgTypes...)>* __clone() const;
virtual void __clone(__base<_Rp(_ArgTypes...)>*) const;
virtual void destroy() _NOEXCEPT;
virtual void destroy_deallocate() _NOEXCEPT;
virtual _Rp operator()(_ArgTypes&&... __arg);
#ifndef _LIBCPP_NO_RTTI
virtual const void* target(const type_info&) const _NOEXCEPT;
virtual const std::type_info& target_type() const _NOEXCEPT;
#endif // _LIBCPP_NO_RTTI
};
template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes>
__base<_Rp(_ArgTypes...)>*
__func<_Fp, _Alloc, _Rp(_ArgTypes...)>::__clone() const
{
typedef allocator_traits<_Alloc> __alloc_traits;
typedef typename __rebind_alloc_helper<__alloc_traits, __func>::type _Ap;
_Ap __a(__f_.__get_allocator());
typedef __allocator_destructor<_Ap> _Dp;
unique_ptr<__func, _Dp> __hold(__a.allocate(1), _Dp(__a, 1));
::new ((void*)__hold.get()) __func(__f_.__target(), _Alloc(__a));
return __hold.release();
}
template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes>
void
__func<_Fp, _Alloc, _Rp(_ArgTypes...)>::__clone(__base<_Rp(_ArgTypes...)>* __p) const
{
::new (__p) __func(__f_.__target(), __f_.__get_allocator());
}
template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes>
void
__func<_Fp, _Alloc, _Rp(_ArgTypes...)>::destroy() _NOEXCEPT
{
__f_.destroy();
}
template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes>
void
__func<_Fp, _Alloc, _Rp(_ArgTypes...)>::destroy_deallocate() _NOEXCEPT
{
typedef allocator_traits<_Alloc> __alloc_traits;
typedef typename __rebind_alloc_helper<__alloc_traits, __func>::type _Ap;
_Ap __a(__f_.__get_allocator());
__f_.destroy();
__a.deallocate(this, 1);
}
template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes>
_Rp
__func<_Fp, _Alloc, _Rp(_ArgTypes...)>::operator()(_ArgTypes&& ... __arg)
{
return __f_(_VSTD::forward<_ArgTypes>(__arg)...);
}
#ifndef _LIBCPP_NO_RTTI
template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes>
const void*
__func<_Fp, _Alloc, _Rp(_ArgTypes...)>::target(const type_info& __ti) const _NOEXCEPT
{
if (__ti == typeid(_Fp))
return &__f_.__target();
return (const void*)0;
}
template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes>
const std::type_info&
__func<_Fp, _Alloc, _Rp(_ArgTypes...)>::target_type() const _NOEXCEPT
{
return typeid(_Fp);
}
#endif // _LIBCPP_NO_RTTI
// __value_func creates a value-type from a __func.
template <class _Fp> class __value_func;
template <class _Rp, class... _ArgTypes> class __value_func<_Rp(_ArgTypes...)>
{
typename aligned_storage<3 * sizeof(void*)>::type __buf_;
typedef __base<_Rp(_ArgTypes...)> __func;
__func* __f_;
_LIBCPP_NO_CFI static __func* __as_base(void* p)
{
return reinterpret_cast<__func*>(p);
}
public:
_LIBCPP_INLINE_VISIBILITY
__value_func() _NOEXCEPT : __f_(0) {}
template <class _Fp, class _Alloc>
_LIBCPP_INLINE_VISIBILITY __value_func(_Fp&& __f, const _Alloc& __a)
: __f_(0)
{
typedef allocator_traits<_Alloc> __alloc_traits;
typedef __function::__func<_Fp, _Alloc, _Rp(_ArgTypes...)> _Fun;
typedef typename __rebind_alloc_helper<__alloc_traits, _Fun>::type
_FunAlloc;
if (__function::__not_null(__f))
{
_FunAlloc __af(__a);
if (sizeof(_Fun) <= sizeof(__buf_) &&
is_nothrow_copy_constructible<_Fp>::value &&
is_nothrow_copy_constructible<_FunAlloc>::value)
{
__f_ =
::new ((void*)&__buf_) _Fun(_VSTD::move(__f), _Alloc(__af));
}
else
{
typedef __allocator_destructor<_FunAlloc> _Dp;
unique_ptr<__func, _Dp> __hold(__af.allocate(1), _Dp(__af, 1));
::new ((void*)__hold.get()) _Fun(_VSTD::move(__f), _Alloc(__a));
__f_ = __hold.release();
}
}
}
template <class _Fp,
class = typename enable_if<!is_same<typename decay<_Fp>::type, __value_func>::value>::type>
_LIBCPP_INLINE_VISIBILITY explicit __value_func(_Fp&& __f)
: __value_func(std::forward<_Fp>(__f), allocator<_Fp>()) {}
_LIBCPP_INLINE_VISIBILITY
__value_func(const __value_func& __f)
{
if (__f.__f_ == 0)
__f_ = 0;
else if ((void*)__f.__f_ == &__f.__buf_)
{
__f_ = __as_base(&__buf_);
__f.__f_->__clone(__f_);
}
else
__f_ = __f.__f_->__clone();
}
_LIBCPP_INLINE_VISIBILITY
__value_func(__value_func&& __f) _NOEXCEPT
{
if (__f.__f_ == 0)
__f_ = 0;
else if ((void*)__f.__f_ == &__f.__buf_)
{
__f_ = __as_base(&__buf_);
__f.__f_->__clone(__f_);
}
else
{
__f_ = __f.__f_;
__f.__f_ = 0;
}
}
_LIBCPP_INLINE_VISIBILITY
~__value_func()
{
if ((void*)__f_ == &__buf_)
__f_->destroy();
else if (__f_)
__f_->destroy_deallocate();
}
_LIBCPP_INLINE_VISIBILITY
__value_func& operator=(__value_func&& __f)
{
*this = nullptr;
if (__f.__f_ == 0)
__f_ = 0;
else if ((void*)__f.__f_ == &__f.__buf_)
{
__f_ = __as_base(&__buf_);
__f.__f_->__clone(__f_);
}
else
{
__f_ = __f.__f_;
__f.__f_ = 0;
}
return *this;
}
_LIBCPP_INLINE_VISIBILITY
__value_func& operator=(nullptr_t)
{
__func* __f = __f_;
__f_ = 0;
if ((void*)__f == &__buf_)
__f->destroy();
else if (__f)
__f->destroy_deallocate();
return *this;
}
_LIBCPP_INLINE_VISIBILITY
_Rp operator()(_ArgTypes&&... __args) const
{
if (__f_ == 0)
__throw_bad_function_call();
return (*__f_)(_VSTD::forward<_ArgTypes>(__args)...);
}
_LIBCPP_INLINE_VISIBILITY
void swap(__value_func& __f) _NOEXCEPT
{
if (&__f == this)
return;
if ((void*)__f_ == &__buf_ && (void*)__f.__f_ == &__f.__buf_)
{
typename aligned_storage<sizeof(__buf_)>::type __tempbuf;
__func* __t = __as_base(&__tempbuf);
__f_->__clone(__t);
__f_->destroy();
__f_ = 0;
__f.__f_->__clone(__as_base(&__buf_));
__f.__f_->destroy();
__f.__f_ = 0;
__f_ = __as_base(&__buf_);
__t->__clone(__as_base(&__f.__buf_));
__t->destroy();
__f.__f_ = __as_base(&__f.__buf_);
}
else if ((void*)__f_ == &__buf_)
{
__f_->__clone(__as_base(&__f.__buf_));
__f_->destroy();
__f_ = __f.__f_;
__f.__f_ = __as_base(&__f.__buf_);
}
else if ((void*)__f.__f_ == &__f.__buf_)
{
__f.__f_->__clone(__as_base(&__buf_));
__f.__f_->destroy();
__f.__f_ = __f_;
__f_ = __as_base(&__buf_);
}
else
_VSTD::swap(__f_, __f.__f_);
}
_LIBCPP_INLINE_VISIBILITY
_LIBCPP_EXPLICIT operator bool() const _NOEXCEPT { return __f_ != 0; }
#ifndef _LIBCPP_NO_RTTI
_LIBCPP_INLINE_VISIBILITY
const std::type_info& target_type() const _NOEXCEPT
{
if (__f_ == 0)
return typeid(void);
return __f_->target_type();
}
template <typename _Tp>
_LIBCPP_INLINE_VISIBILITY const _Tp* target() const _NOEXCEPT
{
if (__f_ == 0)
return 0;
return (const _Tp*)__f_->target(typeid(_Tp));
}
#endif // _LIBCPP_NO_RTTI
};
// Storage for a functor object, to be used with __policy to manage copy and
// destruction.
union __policy_storage
{
mutable char __small[sizeof(void*) * 2];
void* __large;
};
// True if _Fun can safely be held in __policy_storage.__small.
template <typename _Fun>
struct __use_small_storage
: public _VSTD::integral_constant<
bool, sizeof(_Fun) <= sizeof(__policy_storage) &&
_LIBCPP_ALIGNOF(_Fun) <= _LIBCPP_ALIGNOF(__policy_storage) &&
_VSTD::is_trivially_copy_constructible<_Fun>::value &&
_VSTD::is_trivially_destructible<_Fun>::value> {};
// Policy contains information about how to copy, destroy, and move the
// underlying functor. You can think of it as a vtable of sorts.
struct __policy
{
// Used to copy or destroy __large values. null for trivial objects.
void* (*const __clone)(const void*);
void (*const __destroy)(void*);
// True if this is the null policy (no value).
const bool __is_null;
// The target type. May be null if RTTI is disabled.
const std::type_info* const __type_info;
// Returns a pointer to a static policy object suitable for the functor
// type.
template <typename _Fun>
_LIBCPP_INLINE_VISIBILITY static const __policy* __create()
{
return __choose_policy<_Fun>(__use_small_storage<_Fun>());
}
_LIBCPP_INLINE_VISIBILITY
static const __policy* __create_empty()
{
static const _LIBCPP_CONSTEXPR __policy __policy_ = {nullptr, nullptr,
true,
#ifndef _LIBCPP_NO_RTTI
&typeid(void)
#else
nullptr
#endif
};
return &__policy_;
}
private:
template <typename _Fun> static void* __large_clone(const void* __s)
{
const _Fun* __f = static_cast<const _Fun*>(__s);
return __f->__clone();
}
template <typename _Fun>
static void __large_destroy(void* __s) {
_Fun::__destroy_and_delete(static_cast<_Fun*>(__s));
}
template <typename _Fun>
_LIBCPP_INLINE_VISIBILITY static const __policy*
__choose_policy(/* is_small = */ false_type) {
static const _LIBCPP_CONSTEXPR __policy __policy_ = {
&__large_clone<_Fun>, &__large_destroy<_Fun>, false,
#ifndef _LIBCPP_NO_RTTI
&typeid(typename _Fun::_Target)
#else
nullptr
#endif
};
return &__policy_;
}
template <typename _Fun>
_LIBCPP_INLINE_VISIBILITY static const __policy*
__choose_policy(/* is_small = */ true_type)
{
static const _LIBCPP_CONSTEXPR __policy __policy_ = {
nullptr, nullptr, false,
#ifndef _LIBCPP_NO_RTTI
&typeid(typename _Fun::_Target)
#else
nullptr
#endif
};
return &__policy_;
}
};
// Used to choose between perfect forwarding or pass-by-value. Pass-by-value is
// faster for types that can be passed in registers.
template <typename _Tp>
using __fast_forward =
typename _VSTD::conditional<_VSTD::is_scalar<_Tp>::value, _Tp, _Tp&&>::type;
// __policy_invoker calls an instance of __alloc_func held in __policy_storage.
template <class _Fp> struct __policy_invoker;
template <class _Rp, class... _ArgTypes>
struct __policy_invoker<_Rp(_ArgTypes...)>
{
typedef _Rp (*__Call)(const __policy_storage*,
__fast_forward<_ArgTypes>...);
__Call __call_;
// Creates an invoker that throws bad_function_call.
_LIBCPP_INLINE_VISIBILITY
__policy_invoker() : __call_(&__call_empty) {}
// Creates an invoker that calls the given instance of __func.
template <typename _Fun>
_LIBCPP_INLINE_VISIBILITY static __policy_invoker __create()
{
return __policy_invoker(&__call_impl<_Fun>);
}
private:
_LIBCPP_INLINE_VISIBILITY
explicit __policy_invoker(__Call __c) : __call_(__c) {}
static _Rp __call_empty(const __policy_storage*,
__fast_forward<_ArgTypes>...)
{
__throw_bad_function_call();
}
template <typename _Fun>
static _Rp __call_impl(const __policy_storage* __buf,
__fast_forward<_ArgTypes>... __args)
{
_Fun* __f = reinterpret_cast<_Fun*>(__use_small_storage<_Fun>::value
? &__buf->__small
: __buf->__large);
return (*__f)(_VSTD::forward<_ArgTypes>(__args)...);
}
};
// __policy_func uses a __policy and __policy_invoker to create a type-erased,
// copyable functor.
template <class _Fp> class __policy_func;
template <class _Rp, class... _ArgTypes> class __policy_func<_Rp(_ArgTypes...)>
{
// Inline storage for small objects.
__policy_storage __buf_;
// Calls the value stored in __buf_. This could technically be part of
// policy, but storing it here eliminates a level of indirection inside
// operator().
typedef __function::__policy_invoker<_Rp(_ArgTypes...)> __invoker;
__invoker __invoker_;
// The policy that describes how to move / copy / destroy __buf_. Never
// null, even if the function is empty.
const __policy* __policy_;
public:
_LIBCPP_INLINE_VISIBILITY
__policy_func() : __policy_(__policy::__create_empty()) {}
template <class _Fp, class _Alloc>
_LIBCPP_INLINE_VISIBILITY __policy_func(_Fp&& __f, const _Alloc& __a)
: __policy_(__policy::__create_empty())
{
typedef __alloc_func<_Fp, _Alloc, _Rp(_ArgTypes...)> _Fun;
typedef allocator_traits<_Alloc> __alloc_traits;
typedef typename __rebind_alloc_helper<__alloc_traits, _Fun>::type
_FunAlloc;
if (__function::__not_null(__f))
{
__invoker_ = __invoker::template __create<_Fun>();
__policy_ = __policy::__create<_Fun>();
_FunAlloc __af(__a);
if (__use_small_storage<_Fun>())
{
::new ((void*)&__buf_.__small)
_Fun(_VSTD::move(__f), _Alloc(__af));
}
else
{
typedef __allocator_destructor<_FunAlloc> _Dp;
unique_ptr<_Fun, _Dp> __hold(__af.allocate(1), _Dp(__af, 1));
::new ((void*)__hold.get())
_Fun(_VSTD::move(__f), _Alloc(__af));
__buf_.__large = __hold.release();
}
}
}
template <class _Fp, class = typename enable_if<!is_same<typename decay<_Fp>::type, __policy_func>::value>::type>
_LIBCPP_INLINE_VISIBILITY explicit __policy_func(_Fp&& __f)
: __policy_(__policy::__create_empty()) {
typedef __default_alloc_func<_Fp, _Rp(_ArgTypes...)> _Fun;
if (__function::__not_null(__f)) {
__invoker_ = __invoker::template __create<_Fun>();
__policy_ = __policy::__create<_Fun>();
if (__use_small_storage<_Fun>()) {
::new ((void*)&__buf_.__small) _Fun(_VSTD::move(__f));
} else {
__builtin_new_allocator::__holder_t __hold =
__builtin_new_allocator::__allocate_type<_Fun>(1);
__buf_.__large = ::new (__hold.get()) _Fun(_VSTD::move(__f));
(void)__hold.release();
}
}
}
_LIBCPP_INLINE_VISIBILITY
__policy_func(const __policy_func& __f)
: __buf_(__f.__buf_), __invoker_(__f.__invoker_),
__policy_(__f.__policy_)
{
if (__policy_->__clone)
__buf_.__large = __policy_->__clone(__f.__buf_.__large);
}
_LIBCPP_INLINE_VISIBILITY
__policy_func(__policy_func&& __f)
: __buf_(__f.__buf_), __invoker_(__f.__invoker_),
__policy_(__f.__policy_)
{
if (__policy_->__destroy)
{
__f.__policy_ = __policy::__create_empty();
__f.__invoker_ = __invoker();
}
}
_LIBCPP_INLINE_VISIBILITY
~__policy_func()
{
if (__policy_->__destroy)
__policy_->__destroy(__buf_.__large);
}
_LIBCPP_INLINE_VISIBILITY
__policy_func& operator=(__policy_func&& __f)
{
*this = nullptr;
__buf_ = __f.__buf_;
__invoker_ = __f.__invoker_;
__policy_ = __f.__policy_;
__f.__policy_ = __policy::__create_empty();
__f.__invoker_ = __invoker();
return *this;
}
_LIBCPP_INLINE_VISIBILITY
__policy_func& operator=(nullptr_t)
{
const __policy* __p = __policy_;
__policy_ = __policy::__create_empty();
__invoker_ = __invoker();
if (__p->__destroy)
__p->__destroy(__buf_.__large);
return *this;
}
_LIBCPP_INLINE_VISIBILITY
_Rp operator()(_ArgTypes&&... __args) const
{
return __invoker_.__call_(_VSTD::addressof(__buf_),
_VSTD::forward<_ArgTypes>(__args)...);
}
_LIBCPP_INLINE_VISIBILITY
void swap(__policy_func& __f)
{
_VSTD::swap(__invoker_, __f.__invoker_);
_VSTD::swap(__policy_, __f.__policy_);
_VSTD::swap(__buf_, __f.__buf_);
}
_LIBCPP_INLINE_VISIBILITY
explicit operator bool() const _NOEXCEPT
{
return !__policy_->__is_null;
}
#ifndef _LIBCPP_NO_RTTI
_LIBCPP_INLINE_VISIBILITY
const std::type_info& target_type() const _NOEXCEPT
{
return *__policy_->__type_info;
}
template <typename _Tp>
_LIBCPP_INLINE_VISIBILITY const _Tp* target() const _NOEXCEPT
{
if (__policy_->__is_null || typeid(_Tp) != *__policy_->__type_info)
return nullptr;
if (__policy_->__clone) // Out of line storage.
return reinterpret_cast<const _Tp*>(__buf_.__large);
else
return reinterpret_cast<const _Tp*>(&__buf_.__small);
}
#endif // _LIBCPP_NO_RTTI
};
} // __function
template<class _Rp, class ..._ArgTypes>
class _LIBCPP_TEMPLATE_VIS function<_Rp(_ArgTypes...)>
: public __function::__maybe_derive_from_unary_function<_Rp(_ArgTypes...)>,
public __function::__maybe_derive_from_binary_function<_Rp(_ArgTypes...)>
{
#ifndef _LIBCPP_ABI_OPTIMIZED_FUNCTION
typedef __function::__value_func<_Rp(_ArgTypes...)> __func;
#else
typedef __function::__policy_func<_Rp(_ArgTypes...)> __func;
#endif
__func __f_;
template <class _Fp, bool = _And<
_IsNotSame<__uncvref_t<_Fp>, function>,
__invokable<_Fp&, _ArgTypes...>
>::value>
struct __callable;
template <class _Fp>
struct __callable<_Fp, true>
{
static const bool value = is_same<void, _Rp>::value ||
is_convertible<typename __invoke_of<_Fp&, _ArgTypes...>::type,
_Rp>::value;
};
template <class _Fp>
struct __callable<_Fp, false>
{
static const bool value = false;
};
template <class _Fp>
using _EnableIfCallable = typename enable_if<__callable<_Fp>::value>::type;
public:
typedef _Rp result_type;
// construct/copy/destroy:
_LIBCPP_INLINE_VISIBILITY
function() _NOEXCEPT { }
_LIBCPP_INLINE_VISIBILITY
function(nullptr_t) _NOEXCEPT {}
function(const function&);
function(function&&) _NOEXCEPT;
template<class _Fp, class = _EnableIfCallable<_Fp>>
function(_Fp);
#if _LIBCPP_STD_VER <= 14
template<class _Alloc>
_LIBCPP_INLINE_VISIBILITY
function(allocator_arg_t, const _Alloc&) _NOEXCEPT {}
template<class _Alloc>
_LIBCPP_INLINE_VISIBILITY
function(allocator_arg_t, const _Alloc&, nullptr_t) _NOEXCEPT {}
template<class _Alloc>
function(allocator_arg_t, const _Alloc&, const function&);
template<class _Alloc>
function(allocator_arg_t, const _Alloc&, function&&);
template<class _Fp, class _Alloc, class = _EnableIfCallable<_Fp>>
function(allocator_arg_t, const _Alloc& __a, _Fp __f);
#endif
function& operator=(const function&);
function& operator=(function&&) _NOEXCEPT;
function& operator=(nullptr_t) _NOEXCEPT;
template<class _Fp, class = _EnableIfCallable<_Fp>>
function& operator=(_Fp&&);
~function();
// function modifiers:
void swap(function&) _NOEXCEPT;
#if _LIBCPP_STD_VER <= 14
template<class _Fp, class _Alloc>
_LIBCPP_INLINE_VISIBILITY
void assign(_Fp&& __f, const _Alloc& __a)
{function(allocator_arg, __a, _VSTD::forward<_Fp>(__f)).swap(*this);}
#endif
// function capacity:
_LIBCPP_INLINE_VISIBILITY
_LIBCPP_EXPLICIT operator bool() const _NOEXCEPT {
return static_cast<bool>(__f_);
}
// deleted overloads close possible hole in the type system
template<class _R2, class... _ArgTypes2>
bool operator==(const function<_R2(_ArgTypes2...)>&) const = delete;
template<class _R2, class... _ArgTypes2>
bool operator!=(const function<_R2(_ArgTypes2...)>&) const = delete;
public:
// function invocation:
_Rp operator()(_ArgTypes...) const;
#ifndef _LIBCPP_NO_RTTI
// function target access:
const std::type_info& target_type() const _NOEXCEPT;
template <typename _Tp> _Tp* target() _NOEXCEPT;
template <typename _Tp> const _Tp* target() const _NOEXCEPT;
#endif // _LIBCPP_NO_RTTI
};
#ifndef _LIBCPP_HAS_NO_DEDUCTION_GUIDES
template<class _Rp, class ..._Ap>
function(_Rp(*)(_Ap...)) -> function<_Rp(_Ap...)>;
template<class _Fp>
struct __strip_signature;
template<class _Rp, class _Gp, class ..._Ap>
struct __strip_signature<_Rp (_Gp::*) (_Ap...)> { using type = _Rp(_Ap...); };
template<class _Rp, class _Gp, class ..._Ap>
struct __strip_signature<_Rp (_Gp::*) (_Ap...) const> { using type = _Rp(_Ap...); };
template<class _Rp, class _Gp, class ..._Ap>
struct __strip_signature<_Rp (_Gp::*) (_Ap...) volatile> { using type = _Rp(_Ap...); };
template<class _Rp, class _Gp, class ..._Ap>
struct __strip_signature<_Rp (_Gp::*) (_Ap...) const volatile> { using type = _Rp(_Ap...); };
template<class _Rp, class _Gp, class ..._Ap>
struct __strip_signature<_Rp (_Gp::*) (_Ap...) &> { using type = _Rp(_Ap...); };
template<class _Rp, class _Gp, class ..._Ap>
struct __strip_signature<_Rp (_Gp::*) (_Ap...) const &> { using type = _Rp(_Ap...); };
template<class _Rp, class _Gp, class ..._Ap>
struct __strip_signature<_Rp (_Gp::*) (_Ap...) volatile &> { using type = _Rp(_Ap...); };
template<class _Rp, class _Gp, class ..._Ap>
struct __strip_signature<_Rp (_Gp::*) (_Ap...) const volatile &> { using type = _Rp(_Ap...); };
template<class _Rp, class _Gp, class ..._Ap>
struct __strip_signature<_Rp (_Gp::*) (_Ap...) noexcept> { using type = _Rp(_Ap...); };
template<class _Rp, class _Gp, class ..._Ap>
struct __strip_signature<_Rp (_Gp::*) (_Ap...) const noexcept> { using type = _Rp(_Ap...); };
template<class _Rp, class _Gp, class ..._Ap>
struct __strip_signature<_Rp (_Gp::*) (_Ap...) volatile noexcept> { using type = _Rp(_Ap...); };
template<class _Rp, class _Gp, class ..._Ap>
struct __strip_signature<_Rp (_Gp::*) (_Ap...) const volatile noexcept> { using type = _Rp(_Ap...); };
template<class _Rp, class _Gp, class ..._Ap>
struct __strip_signature<_Rp (_Gp::*) (_Ap...) & noexcept> { using type = _Rp(_Ap...); };
template<class _Rp, class _Gp, class ..._Ap>
struct __strip_signature<_Rp (_Gp::*) (_Ap...) const & noexcept> { using type = _Rp(_Ap...); };
template<class _Rp, class _Gp, class ..._Ap>
struct __strip_signature<_Rp (_Gp::*) (_Ap...) volatile & noexcept> { using type = _Rp(_Ap...); };
template<class _Rp, class _Gp, class ..._Ap>
struct __strip_signature<_Rp (_Gp::*) (_Ap...) const volatile & noexcept> { using type = _Rp(_Ap...); };
template<class _Fp, class _Stripped = typename __strip_signature<decltype(&_Fp::operator())>::type>
function(_Fp) -> function<_Stripped>;
#endif // !_LIBCPP_HAS_NO_DEDUCTION_GUIDES
template<class _Rp, class ..._ArgTypes>
function<_Rp(_ArgTypes...)>::function(const function& __f) : __f_(__f.__f_) {}
#if _LIBCPP_STD_VER <= 14
template<class _Rp, class ..._ArgTypes>
template <class _Alloc>
function<_Rp(_ArgTypes...)>::function(allocator_arg_t, const _Alloc&,
const function& __f) : __f_(__f.__f_) {}
#endif
template <class _Rp, class... _ArgTypes>
function<_Rp(_ArgTypes...)>::function(function&& __f) _NOEXCEPT
: __f_(_VSTD::move(__f.__f_)) {}
#if _LIBCPP_STD_VER <= 14
template<class _Rp, class ..._ArgTypes>
template <class _Alloc>
function<_Rp(_ArgTypes...)>::function(allocator_arg_t, const _Alloc&,
function&& __f)
: __f_(_VSTD::move(__f.__f_)) {}
#endif
template <class _Rp, class... _ArgTypes>
template <class _Fp, class>
function<_Rp(_ArgTypes...)>::function(_Fp __f) : __f_(_VSTD::move(__f)) {}
#if _LIBCPP_STD_VER <= 14
template <class _Rp, class... _ArgTypes>
template <class _Fp, class _Alloc, class>
function<_Rp(_ArgTypes...)>::function(allocator_arg_t, const _Alloc& __a,
_Fp __f)
: __f_(_VSTD::move(__f), __a) {}
#endif
template<class _Rp, class ..._ArgTypes>
function<_Rp(_ArgTypes...)>&
function<_Rp(_ArgTypes...)>::operator=(const function& __f)
{
function(__f).swap(*this);
return *this;
}
template<class _Rp, class ..._ArgTypes>
function<_Rp(_ArgTypes...)>&
function<_Rp(_ArgTypes...)>::operator=(function&& __f) _NOEXCEPT
{
__f_ = std::move(__f.__f_);
return *this;
}
template<class _Rp, class ..._ArgTypes>
function<_Rp(_ArgTypes...)>&
function<_Rp(_ArgTypes...)>::operator=(nullptr_t) _NOEXCEPT
{
__f_ = nullptr;
return *this;
}
template<class _Rp, class ..._ArgTypes>
template <class _Fp, class>
function<_Rp(_ArgTypes...)>&
function<_Rp(_ArgTypes...)>::operator=(_Fp&& __f)
{
function(_VSTD::forward<_Fp>(__f)).swap(*this);
return *this;
}
template<class _Rp, class ..._ArgTypes>
function<_Rp(_ArgTypes...)>::~function() {}
template<class _Rp, class ..._ArgTypes>
void
function<_Rp(_ArgTypes...)>::swap(function& __f) _NOEXCEPT
{
__f_.swap(__f.__f_);
}
template<class _Rp, class ..._ArgTypes>
_Rp
function<_Rp(_ArgTypes...)>::operator()(_ArgTypes... __arg) const
{
return __f_(_VSTD::forward<_ArgTypes>(__arg)...);
}
#ifndef _LIBCPP_NO_RTTI
template<class _Rp, class ..._ArgTypes>
const std::type_info&
function<_Rp(_ArgTypes...)>::target_type() const _NOEXCEPT
{
return __f_.target_type();
}
template<class _Rp, class ..._ArgTypes>
template <typename _Tp>
_Tp*
function<_Rp(_ArgTypes...)>::target() _NOEXCEPT
{
return (_Tp*)(__f_.template target<_Tp>());
}
template<class _Rp, class ..._ArgTypes>
template <typename _Tp>
const _Tp*
function<_Rp(_ArgTypes...)>::target() const _NOEXCEPT
{
return __f_.template target<_Tp>();
}
#endif // _LIBCPP_NO_RTTI
template <class _Rp, class... _ArgTypes>
inline _LIBCPP_INLINE_VISIBILITY
bool
operator==(const function<_Rp(_ArgTypes...)>& __f, nullptr_t) _NOEXCEPT {return !__f;}
template <class _Rp, class... _ArgTypes>
inline _LIBCPP_INLINE_VISIBILITY
bool
operator==(nullptr_t, const function<_Rp(_ArgTypes...)>& __f) _NOEXCEPT {return !__f;}
template <class _Rp, class... _ArgTypes>
inline _LIBCPP_INLINE_VISIBILITY
bool
operator!=(const function<_Rp(_ArgTypes...)>& __f, nullptr_t) _NOEXCEPT {return (bool)__f;}
template <class _Rp, class... _ArgTypes>
inline _LIBCPP_INLINE_VISIBILITY
bool
operator!=(nullptr_t, const function<_Rp(_ArgTypes...)>& __f) _NOEXCEPT {return (bool)__f;}
template <class _Rp, class... _ArgTypes>
inline _LIBCPP_INLINE_VISIBILITY
void
swap(function<_Rp(_ArgTypes...)>& __x, function<_Rp(_ArgTypes...)>& __y) _NOEXCEPT
{return __x.swap(__y);}
#else // _LIBCPP_CXX03_LANG
# include "third_party/libcxx/__functional_03"
#endif
////////////////////////////////////////////////////////////////////////////////
// BIND
//==============================================================================
template<class _Tp> struct __is_bind_expression : public false_type {};
template<class _Tp> struct _LIBCPP_TEMPLATE_VIS is_bind_expression
: public __is_bind_expression<typename remove_cv<_Tp>::type> {};
#if _LIBCPP_STD_VER > 14
template <class _Tp>
_LIBCPP_INLINE_VAR constexpr size_t is_bind_expression_v = is_bind_expression<_Tp>::value;
#endif
template<class _Tp> struct __is_placeholder : public integral_constant<int, 0> {};
template<class _Tp> struct _LIBCPP_TEMPLATE_VIS is_placeholder
: public __is_placeholder<typename remove_cv<_Tp>::type> {};
#if _LIBCPP_STD_VER > 14
template <class _Tp>
_LIBCPP_INLINE_VAR constexpr size_t is_placeholder_v = is_placeholder<_Tp>::value;
#endif
namespace placeholders
{
template <int _Np> struct __ph {};
#if defined(_LIBCPP_CXX03_LANG) || defined(_LIBCPP_BUILDING_LIBRARY)
_LIBCPP_FUNC_VIS extern const __ph<1> _1;
_LIBCPP_FUNC_VIS extern const __ph<2> _2;
_LIBCPP_FUNC_VIS extern const __ph<3> _3;
_LIBCPP_FUNC_VIS extern const __ph<4> _4;
_LIBCPP_FUNC_VIS extern const __ph<5> _5;
_LIBCPP_FUNC_VIS extern const __ph<6> _6;
_LIBCPP_FUNC_VIS extern const __ph<7> _7;
_LIBCPP_FUNC_VIS extern const __ph<8> _8;
_LIBCPP_FUNC_VIS extern const __ph<9> _9;
_LIBCPP_FUNC_VIS extern const __ph<10> _10;
#else
/* _LIBCPP_INLINE_VAR */ constexpr __ph<1> _1{};
/* _LIBCPP_INLINE_VAR */ constexpr __ph<2> _2{};
/* _LIBCPP_INLINE_VAR */ constexpr __ph<3> _3{};
/* _LIBCPP_INLINE_VAR */ constexpr __ph<4> _4{};
/* _LIBCPP_INLINE_VAR */ constexpr __ph<5> _5{};
/* _LIBCPP_INLINE_VAR */ constexpr __ph<6> _6{};
/* _LIBCPP_INLINE_VAR */ constexpr __ph<7> _7{};
/* _LIBCPP_INLINE_VAR */ constexpr __ph<8> _8{};
/* _LIBCPP_INLINE_VAR */ constexpr __ph<9> _9{};
/* _LIBCPP_INLINE_VAR */ constexpr __ph<10> _10{};
#endif // defined(_LIBCPP_CXX03_LANG) || defined(_LIBCPP_BUILDING_LIBRARY)
} // placeholders
template<int _Np>
struct __is_placeholder<placeholders::__ph<_Np> >
: public integral_constant<int, _Np> {};
#ifndef _LIBCPP_CXX03_LANG
template <class _Tp, class _Uj>
inline _LIBCPP_INLINE_VISIBILITY
_Tp&
__mu(reference_wrapper<_Tp> __t, _Uj&)
{
return __t.get();
}
template <class _Ti, class ..._Uj, size_t ..._Indx>
inline _LIBCPP_INLINE_VISIBILITY
typename __invoke_of<_Ti&, _Uj...>::type
__mu_expand(_Ti& __ti, tuple<_Uj...>& __uj, __tuple_indices<_Indx...>)
{
return __ti(_VSTD::forward<_Uj>(_VSTD::get<_Indx>(__uj))...);
}
template <class _Ti, class ..._Uj>
inline _LIBCPP_INLINE_VISIBILITY
typename _EnableIf
<
is_bind_expression<_Ti>::value,
__invoke_of<_Ti&, _Uj...>
>::type
__mu(_Ti& __ti, tuple<_Uj...>& __uj)
{
typedef typename __make_tuple_indices<sizeof...(_Uj)>::type __indices;
return __mu_expand(__ti, __uj, __indices());
}
template <bool IsPh, class _Ti, class _Uj>
struct __mu_return2 {};
template <class _Ti, class _Uj>
struct __mu_return2<true, _Ti, _Uj>
{
typedef typename tuple_element<is_placeholder<_Ti>::value - 1, _Uj>::type type;
};
template <class _Ti, class _Uj>
inline _LIBCPP_INLINE_VISIBILITY
typename enable_if
<
0 < is_placeholder<_Ti>::value,
typename __mu_return2<0 < is_placeholder<_Ti>::value, _Ti, _Uj>::type
>::type
__mu(_Ti&, _Uj& __uj)
{
const size_t _Indx = is_placeholder<_Ti>::value - 1;
return _VSTD::forward<typename tuple_element<_Indx, _Uj>::type>(_VSTD::get<_Indx>(__uj));
}
template <class _Ti, class _Uj>
inline _LIBCPP_INLINE_VISIBILITY
typename enable_if
<
!is_bind_expression<_Ti>::value &&
is_placeholder<_Ti>::value == 0 &&
!__is_reference_wrapper<_Ti>::value,
_Ti&
>::type
__mu(_Ti& __ti, _Uj&)
{
return __ti;
}
template <class _Ti, bool IsReferenceWrapper, bool IsBindEx, bool IsPh,
class _TupleUj>
struct __mu_return_impl;
template <bool _Invokable, class _Ti, class ..._Uj>
struct __mu_return_invokable // false
{
typedef __nat type;
};
template <class _Ti, class ..._Uj>
struct __mu_return_invokable<true, _Ti, _Uj...>
{
typedef typename __invoke_of<_Ti&, _Uj...>::type type;
};
template <class _Ti, class ..._Uj>
struct __mu_return_impl<_Ti, false, true, false, tuple<_Uj...> >
: public __mu_return_invokable<__invokable<_Ti&, _Uj...>::value, _Ti, _Uj...>
{
};
template <class _Ti, class _TupleUj>
struct __mu_return_impl<_Ti, false, false, true, _TupleUj>
{
typedef typename tuple_element<is_placeholder<_Ti>::value - 1,
_TupleUj>::type&& type;
};
template <class _Ti, class _TupleUj>
struct __mu_return_impl<_Ti, true, false, false, _TupleUj>
{
typedef typename _Ti::type& type;
};
template <class _Ti, class _TupleUj>
struct __mu_return_impl<_Ti, false, false, false, _TupleUj>
{
typedef _Ti& type;
};
template <class _Ti, class _TupleUj>
struct __mu_return
: public __mu_return_impl<_Ti,
__is_reference_wrapper<_Ti>::value,
is_bind_expression<_Ti>::value,
0 < is_placeholder<_Ti>::value &&
is_placeholder<_Ti>::value <= tuple_size<_TupleUj>::value,
_TupleUj>
{
};
template <class _Fp, class _BoundArgs, class _TupleUj>
struct __is_valid_bind_return
{
static const bool value = false;
};
template <class _Fp, class ..._BoundArgs, class _TupleUj>
struct __is_valid_bind_return<_Fp, tuple<_BoundArgs...>, _TupleUj>
{
static const bool value = __invokable<_Fp,
typename __mu_return<_BoundArgs, _TupleUj>::type...>::value;
};
template <class _Fp, class ..._BoundArgs, class _TupleUj>
struct __is_valid_bind_return<_Fp, const tuple<_BoundArgs...>, _TupleUj>
{
static const bool value = __invokable<_Fp,
typename __mu_return<const _BoundArgs, _TupleUj>::type...>::value;
};
template <class _Fp, class _BoundArgs, class _TupleUj,
bool = __is_valid_bind_return<_Fp, _BoundArgs, _TupleUj>::value>
struct __bind_return;
template <class _Fp, class ..._BoundArgs, class _TupleUj>
struct __bind_return<_Fp, tuple<_BoundArgs...>, _TupleUj, true>
{
typedef typename __invoke_of
<
_Fp&,
typename __mu_return
<
_BoundArgs,
_TupleUj
>::type...
>::type type;
};
template <class _Fp, class ..._BoundArgs, class _TupleUj>
struct __bind_return<_Fp, const tuple<_BoundArgs...>, _TupleUj, true>
{
typedef typename __invoke_of
<
_Fp&,
typename __mu_return
<
const _BoundArgs,
_TupleUj
>::type...
>::type type;
};
template <class _Fp, class _BoundArgs, size_t ..._Indx, class _Args>
inline _LIBCPP_INLINE_VISIBILITY
typename __bind_return<_Fp, _BoundArgs, _Args>::type
__apply_functor(_Fp& __f, _BoundArgs& __bound_args, __tuple_indices<_Indx...>,
_Args&& __args)
{
return _VSTD::__invoke(__f, _VSTD::__mu(_VSTD::get<_Indx>(__bound_args), __args)...);
}
template<class _Fp, class ..._BoundArgs>
class __bind
: public __weak_result_type<typename decay<_Fp>::type>
{
protected:
typedef typename decay<_Fp>::type _Fd;
typedef tuple<typename decay<_BoundArgs>::type...> _Td;
private:
_Fd __f_;
_Td __bound_args_;
typedef typename __make_tuple_indices<sizeof...(_BoundArgs)>::type __indices;
public:
template <class _Gp, class ..._BA,
class = typename enable_if
<
is_constructible<_Fd, _Gp>::value &&
!is_same<typename remove_reference<_Gp>::type,
__bind>::value
>::type>
_LIBCPP_INLINE_VISIBILITY
explicit __bind(_Gp&& __f, _BA&& ...__bound_args)
: __f_(_VSTD::forward<_Gp>(__f)),
__bound_args_(_VSTD::forward<_BA>(__bound_args)...) {}
template <class ..._Args>
_LIBCPP_INLINE_VISIBILITY
typename __bind_return<_Fd, _Td, tuple<_Args&&...> >::type
operator()(_Args&& ...__args)
{
return _VSTD::__apply_functor(__f_, __bound_args_, __indices(),
tuple<_Args&&...>(_VSTD::forward<_Args>(__args)...));
}
template <class ..._Args>
_LIBCPP_INLINE_VISIBILITY
typename __bind_return<const _Fd, const _Td, tuple<_Args&&...> >::type
operator()(_Args&& ...__args) const
{
return _VSTD::__apply_functor(__f_, __bound_args_, __indices(),
tuple<_Args&&...>(_VSTD::forward<_Args>(__args)...));
}
};
template<class _Fp, class ..._BoundArgs>
struct __is_bind_expression<__bind<_Fp, _BoundArgs...> > : public true_type {};
template<class _Rp, class _Fp, class ..._BoundArgs>
class __bind_r
: public __bind<_Fp, _BoundArgs...>
{
typedef __bind<_Fp, _BoundArgs...> base;
typedef typename base::_Fd _Fd;
typedef typename base::_Td _Td;
public:
typedef _Rp result_type;
template <class _Gp, class ..._BA,
class = typename enable_if
<
is_constructible<_Fd, _Gp>::value &&
!is_same<typename remove_reference<_Gp>::type,
__bind_r>::value
>::type>
_LIBCPP_INLINE_VISIBILITY
explicit __bind_r(_Gp&& __f, _BA&& ...__bound_args)
: base(_VSTD::forward<_Gp>(__f),
_VSTD::forward<_BA>(__bound_args)...) {}
template <class ..._Args>
_LIBCPP_INLINE_VISIBILITY
typename enable_if
<
is_convertible<typename __bind_return<_Fd, _Td, tuple<_Args&&...> >::type,
result_type>::value || is_void<_Rp>::value,
result_type
>::type
operator()(_Args&& ...__args)
{
typedef __invoke_void_return_wrapper<_Rp> _Invoker;
return _Invoker::__call(static_cast<base&>(*this), _VSTD::forward<_Args>(__args)...);
}
template <class ..._Args>
_LIBCPP_INLINE_VISIBILITY
typename enable_if
<
is_convertible<typename __bind_return<const _Fd, const _Td, tuple<_Args&&...> >::type,
result_type>::value || is_void<_Rp>::value,
result_type
>::type
operator()(_Args&& ...__args) const
{
typedef __invoke_void_return_wrapper<_Rp> _Invoker;
return _Invoker::__call(static_cast<base const&>(*this), _VSTD::forward<_Args>(__args)...);
}
};
template<class _Rp, class _Fp, class ..._BoundArgs>
struct __is_bind_expression<__bind_r<_Rp, _Fp, _BoundArgs...> > : public true_type {};
template<class _Fp, class ..._BoundArgs>
inline _LIBCPP_INLINE_VISIBILITY
__bind<_Fp, _BoundArgs...>
bind(_Fp&& __f, _BoundArgs&&... __bound_args)
{
typedef __bind<_Fp, _BoundArgs...> type;
return type(_VSTD::forward<_Fp>(__f), _VSTD::forward<_BoundArgs>(__bound_args)...);
}
template<class _Rp, class _Fp, class ..._BoundArgs>
inline _LIBCPP_INLINE_VISIBILITY
__bind_r<_Rp, _Fp, _BoundArgs...>
bind(_Fp&& __f, _BoundArgs&&... __bound_args)
{
typedef __bind_r<_Rp, _Fp, _BoundArgs...> type;
return type(_VSTD::forward<_Fp>(__f), _VSTD::forward<_BoundArgs>(__bound_args)...);
}
#endif // _LIBCPP_CXX03_LANG
#if _LIBCPP_STD_VER > 14
template <class _Fn, class ..._Args>
invoke_result_t<_Fn, _Args...>
invoke(_Fn&& __f, _Args&&... __args)
noexcept(is_nothrow_invocable_v<_Fn, _Args...>)
{
return _VSTD::__invoke(_VSTD::forward<_Fn>(__f), _VSTD::forward<_Args>(__args)...);
}
template <class _DecayFunc>
class _LIBCPP_TEMPLATE_VIS __not_fn_imp {
_DecayFunc __fd;
public:
__not_fn_imp() = delete;
template <class ..._Args>
_LIBCPP_INLINE_VISIBILITY
auto operator()(_Args&& ...__args) &
noexcept(noexcept(!_VSTD::invoke(__fd, _VSTD::forward<_Args>(__args)...)))
-> decltype( !_VSTD::invoke(__fd, _VSTD::forward<_Args>(__args)...))
{ return !_VSTD::invoke(__fd, _VSTD::forward<_Args>(__args)...); }
template <class ..._Args>
_LIBCPP_INLINE_VISIBILITY
auto operator()(_Args&& ...__args) &&
noexcept(noexcept(!_VSTD::invoke(_VSTD::move(__fd), _VSTD::forward<_Args>(__args)...)))
-> decltype( !_VSTD::invoke(_VSTD::move(__fd), _VSTD::forward<_Args>(__args)...))
{ return !_VSTD::invoke(_VSTD::move(__fd), _VSTD::forward<_Args>(__args)...); }
template <class ..._Args>
_LIBCPP_INLINE_VISIBILITY
auto operator()(_Args&& ...__args) const&
noexcept(noexcept(!_VSTD::invoke(__fd, _VSTD::forward<_Args>(__args)...)))
-> decltype( !_VSTD::invoke(__fd, _VSTD::forward<_Args>(__args)...))
{ return !_VSTD::invoke(__fd, _VSTD::forward<_Args>(__args)...); }
template <class ..._Args>
_LIBCPP_INLINE_VISIBILITY
auto operator()(_Args&& ...__args) const&&
noexcept(noexcept(!_VSTD::invoke(_VSTD::move(__fd), _VSTD::forward<_Args>(__args)...)))
-> decltype( !_VSTD::invoke(_VSTD::move(__fd), _VSTD::forward<_Args>(__args)...))
{ return !_VSTD::invoke(_VSTD::move(__fd), _VSTD::forward<_Args>(__args)...); }
private:
template <class _RawFunc,
class = enable_if_t<!is_same<decay_t<_RawFunc>, __not_fn_imp>::value>>
_LIBCPP_INLINE_VISIBILITY
explicit __not_fn_imp(_RawFunc&& __rf)
: __fd(_VSTD::forward<_RawFunc>(__rf)) {}
template <class _RawFunc>
friend inline _LIBCPP_INLINE_VISIBILITY
__not_fn_imp<decay_t<_RawFunc>> not_fn(_RawFunc&&);
};
template <class _RawFunc>
inline _LIBCPP_INLINE_VISIBILITY
__not_fn_imp<decay_t<_RawFunc>> not_fn(_RawFunc&& __fn) {
return __not_fn_imp<decay_t<_RawFunc>>(_VSTD::forward<_RawFunc>(__fn));
}
#endif
// struct hash<T*> in <memory>
template <class _BinaryPredicate, class _ForwardIterator1, class _ForwardIterator2>
pair<_ForwardIterator1, _ForwardIterator1> _LIBCPP_CONSTEXPR_AFTER_CXX11
__search(_ForwardIterator1 __first1, _ForwardIterator1 __last1,
_ForwardIterator2 __first2, _ForwardIterator2 __last2, _BinaryPredicate __pred,
forward_iterator_tag, forward_iterator_tag)
{
if (__first2 == __last2)
return make_pair(__first1, __first1); // Everything matches an empty sequence
while (true)
{
// Find first element in sequence 1 that matchs *__first2, with a mininum of loop checks
while (true)
{
if (__first1 == __last1) // return __last1 if no element matches *__first2
return make_pair(__last1, __last1);
if (__pred(*__first1, *__first2))
break;
++__first1;
}
// *__first1 matches *__first2, now match elements after here
_ForwardIterator1 __m1 = __first1;
_ForwardIterator2 __m2 = __first2;
while (true)
{
if (++__m2 == __last2) // If pattern exhausted, __first1 is the answer (works for 1 element pattern)
return make_pair(__first1, __m1);
if (++__m1 == __last1) // Otherwise if source exhaused, pattern not found
return make_pair(__last1, __last1);
if (!__pred(*__m1, *__m2)) // if there is a mismatch, restart with a new __first1
{
++__first1;
break;
} // else there is a match, check next elements
}
}
}
template <class _BinaryPredicate, class _RandomAccessIterator1, class _RandomAccessIterator2>
_LIBCPP_CONSTEXPR_AFTER_CXX11
pair<_RandomAccessIterator1, _RandomAccessIterator1>
__search(_RandomAccessIterator1 __first1, _RandomAccessIterator1 __last1,
_RandomAccessIterator2 __first2, _RandomAccessIterator2 __last2, _BinaryPredicate __pred,
random_access_iterator_tag, random_access_iterator_tag)
{
typedef typename iterator_traits<_RandomAccessIterator1>::difference_type _D1;
typedef typename iterator_traits<_RandomAccessIterator2>::difference_type _D2;
// Take advantage of knowing source and pattern lengths. Stop short when source is smaller than pattern
const _D2 __len2 = __last2 - __first2;
if (__len2 == 0)
return make_pair(__first1, __first1);
const _D1 __len1 = __last1 - __first1;
if (__len1 < __len2)
return make_pair(__last1, __last1);
const _RandomAccessIterator1 __s = __last1 - (__len2 - 1); // Start of pattern match can't go beyond here
while (true)
{
while (true)
{
if (__first1 == __s)
return make_pair(__last1, __last1);
if (__pred(*__first1, *__first2))
break;
++__first1;
}
_RandomAccessIterator1 __m1 = __first1;
_RandomAccessIterator2 __m2 = __first2;
while (true)
{
if (++__m2 == __last2)
return make_pair(__first1, __first1 + __len2);
++__m1; // no need to check range on __m1 because __s guarantees we have enough source
if (!__pred(*__m1, *__m2))
{
++__first1;
break;
}
}
}
}
#if _LIBCPP_STD_VER > 14
// default searcher
template<class _ForwardIterator, class _BinaryPredicate = equal_to<>>
class _LIBCPP_TYPE_VIS default_searcher {
public:
_LIBCPP_INLINE_VISIBILITY
default_searcher(_ForwardIterator __f, _ForwardIterator __l,
_BinaryPredicate __p = _BinaryPredicate())
: __first_(__f), __last_(__l), __pred_(__p) {}
template <typename _ForwardIterator2>
_LIBCPP_INLINE_VISIBILITY
pair<_ForwardIterator2, _ForwardIterator2>
operator () (_ForwardIterator2 __f, _ForwardIterator2 __l) const
{
return _VSTD::__search(__f, __l, __first_, __last_, __pred_,
typename _VSTD::iterator_traits<_ForwardIterator>::iterator_category(),
typename _VSTD::iterator_traits<_ForwardIterator2>::iterator_category());
}
private:
_ForwardIterator __first_;
_ForwardIterator __last_;
_BinaryPredicate __pred_;
};
#endif // _LIBCPP_STD_VER > 14
#if _LIBCPP_STD_VER > 17
template <class _Tp>
using unwrap_reference_t = typename unwrap_reference<_Tp>::type;
template <class _Tp>
using unwrap_ref_decay_t = typename unwrap_ref_decay<_Tp>::type;
#endif // > C++17
template <class _Container, class _Predicate>
inline void __libcpp_erase_if_container( _Container& __c, _Predicate __pred)
{
for (typename _Container::iterator __iter = __c.begin(), __last = __c.end(); __iter != __last;)
{
if (__pred(*__iter))
__iter = __c.erase(__iter);
else
++__iter;
}
}
_LIBCPP_END_NAMESPACE_STD
#endif // _LIBCPP_FUNCTIONAL
| 99,093 | 3,097 | jart/cosmopolitan | false |
cosmopolitan/third_party/libcxx/countof.internal.hh | #ifndef COSMOPOLITAN_THIRD_PARTY_LIBCXX_COUNTOF_H_
#define COSMOPOLITAN_THIRD_PARTY_LIBCXX_COUNTOF_H_
#include "third_party/libcxx/__config"
namespace {
template <typename T, size_t N>
inline _LIBCPP_CONSTEXPR size_t countof(const T (&)[N]) {
return N;
}
template <typename T>
inline _LIBCPP_CONSTEXPR size_t countof(const T* const begin,
const T* const end) {
return static_cast<size_t>(end - begin);
}
} // namespace
#endif /* COSMOPOLITAN_THIRD_PARTY_LIBCXX_COUNTOF_H_ */
| 524 | 21 | jart/cosmopolitan | false |
cosmopolitan/third_party/libcxx/__tuple | // -*- 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___TUPLE
#define _LIBCPP___TUPLE
#include "third_party/libcxx/__config"
#include "third_party/libcxx/cstddef"
#include "third_party/libcxx/type_traits"
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
#pragma GCC system_header
#endif
_LIBCPP_BEGIN_NAMESPACE_STD
template <class _Tp> struct _LIBCPP_TEMPLATE_VIS tuple_size;
#if !defined(_LIBCPP_CXX03_LANG)
template <class _Tp, class...>
using __enable_if_tuple_size_imp = _Tp;
template <class _Tp>
struct _LIBCPP_TEMPLATE_VIS tuple_size<__enable_if_tuple_size_imp<
const _Tp,
typename enable_if<!is_volatile<_Tp>::value>::type,
integral_constant<size_t, sizeof(tuple_size<_Tp>)>>>
: public integral_constant<size_t, tuple_size<_Tp>::value> {};
template <class _Tp>
struct _LIBCPP_TEMPLATE_VIS tuple_size<__enable_if_tuple_size_imp<
volatile _Tp,
typename enable_if<!is_const<_Tp>::value>::type,
integral_constant<size_t, sizeof(tuple_size<_Tp>)>>>
: public integral_constant<size_t, tuple_size<_Tp>::value> {};
template <class _Tp>
struct _LIBCPP_TEMPLATE_VIS tuple_size<__enable_if_tuple_size_imp<
const volatile _Tp,
integral_constant<size_t, sizeof(tuple_size<_Tp>)>>>
: public integral_constant<size_t, tuple_size<_Tp>::value> {};
#else
template <class _Tp> struct _LIBCPP_TEMPLATE_VIS tuple_size<const _Tp> : public tuple_size<_Tp> {};
template <class _Tp> struct _LIBCPP_TEMPLATE_VIS tuple_size<volatile _Tp> : public tuple_size<_Tp> {};
template <class _Tp> struct _LIBCPP_TEMPLATE_VIS tuple_size<const volatile _Tp> : public tuple_size<_Tp> {};
#endif
template <size_t _Ip, class _Tp> struct _LIBCPP_TEMPLATE_VIS tuple_element;
template <size_t _Ip, class _Tp>
struct _LIBCPP_TEMPLATE_VIS tuple_element<_Ip, const _Tp>
{
typedef _LIBCPP_NODEBUG_TYPE typename add_const<typename tuple_element<_Ip, _Tp>::type>::type type;
};
template <size_t _Ip, class _Tp>
struct _LIBCPP_TEMPLATE_VIS tuple_element<_Ip, volatile _Tp>
{
typedef _LIBCPP_NODEBUG_TYPE typename add_volatile<typename tuple_element<_Ip, _Tp>::type>::type type;
};
template <size_t _Ip, class _Tp>
struct _LIBCPP_TEMPLATE_VIS tuple_element<_Ip, const volatile _Tp>
{
typedef _LIBCPP_NODEBUG_TYPE typename add_cv<typename tuple_element<_Ip, _Tp>::type>::type type;
};
template <class _Tp> struct __tuple_like : false_type {};
template <class _Tp> struct __tuple_like<const _Tp> : public __tuple_like<_Tp> {};
template <class _Tp> struct __tuple_like<volatile _Tp> : public __tuple_like<_Tp> {};
template <class _Tp> struct __tuple_like<const volatile _Tp> : public __tuple_like<_Tp> {};
// tuple specializations
#ifndef _LIBCPP_CXX03_LANG
template <size_t...> struct __tuple_indices {};
template <class _IdxType, _IdxType... _Values>
struct __integer_sequence {
template <template <class _OIdxType, _OIdxType...> class _ToIndexSeq, class _ToIndexType>
using __convert = _ToIndexSeq<_ToIndexType, _Values...>;
template <size_t _Sp>
using __to_tuple_indices = __tuple_indices<(_Values + _Sp)...>;
};
#if !__has_builtin(__make_integer_seq) || defined(_LIBCPP_TESTING_FALLBACK_MAKE_INTEGER_SEQUENCE)
namespace __detail {
template<typename _Tp, size_t ..._Extra> struct __repeat;
template<typename _Tp, _Tp ..._Np, size_t ..._Extra> struct __repeat<__integer_sequence<_Tp, _Np...>, _Extra...> {
typedef _LIBCPP_NODEBUG_TYPE __integer_sequence<_Tp,
_Np...,
sizeof...(_Np) + _Np...,
2 * sizeof...(_Np) + _Np...,
3 * sizeof...(_Np) + _Np...,
4 * sizeof...(_Np) + _Np...,
5 * sizeof...(_Np) + _Np...,
6 * sizeof...(_Np) + _Np...,
7 * sizeof...(_Np) + _Np...,
_Extra...> type;
};
template<size_t _Np> struct __parity;
template<size_t _Np> struct __make : __parity<_Np % 8>::template __pmake<_Np> {};
template<> struct __make<0> { typedef __integer_sequence<size_t> type; };
template<> struct __make<1> { typedef __integer_sequence<size_t, 0> type; };
template<> struct __make<2> { typedef __integer_sequence<size_t, 0, 1> type; };
template<> struct __make<3> { typedef __integer_sequence<size_t, 0, 1, 2> type; };
template<> struct __make<4> { typedef __integer_sequence<size_t, 0, 1, 2, 3> type; };
template<> struct __make<5> { typedef __integer_sequence<size_t, 0, 1, 2, 3, 4> type; };
template<> struct __make<6> { typedef __integer_sequence<size_t, 0, 1, 2, 3, 4, 5> type; };
template<> struct __make<7> { typedef __integer_sequence<size_t, 0, 1, 2, 3, 4, 5, 6> type; };
template<> struct __parity<0> { template<size_t _Np> struct __pmake : __repeat<typename __make<_Np / 8>::type> {}; };
template<> struct __parity<1> { template<size_t _Np> struct __pmake : __repeat<typename __make<_Np / 8>::type, _Np - 1> {}; };
template<> struct __parity<2> { template<size_t _Np> struct __pmake : __repeat<typename __make<_Np / 8>::type, _Np - 2, _Np - 1> {}; };
template<> struct __parity<3> { template<size_t _Np> struct __pmake : __repeat<typename __make<_Np / 8>::type, _Np - 3, _Np - 2, _Np - 1> {}; };
template<> struct __parity<4> { template<size_t _Np> struct __pmake : __repeat<typename __make<_Np / 8>::type, _Np - 4, _Np - 3, _Np - 2, _Np - 1> {}; };
template<> struct __parity<5> { template<size_t _Np> struct __pmake : __repeat<typename __make<_Np / 8>::type, _Np - 5, _Np - 4, _Np - 3, _Np - 2, _Np - 1> {}; };
template<> struct __parity<6> { template<size_t _Np> struct __pmake : __repeat<typename __make<_Np / 8>::type, _Np - 6, _Np - 5, _Np - 4, _Np - 3, _Np - 2, _Np - 1> {}; };
template<> struct __parity<7> { template<size_t _Np> struct __pmake : __repeat<typename __make<_Np / 8>::type, _Np - 7, _Np - 6, _Np - 5, _Np - 4, _Np - 3, _Np - 2, _Np - 1> {}; };
} // namespace detail
#endif // !__has_builtin(__make_integer_seq) || defined(_LIBCPP_TESTING_FALLBACK_MAKE_INTEGER_SEQUENCE)
#if __has_builtin(__make_integer_seq)
template <size_t _Ep, size_t _Sp>
using __make_indices_imp =
typename __make_integer_seq<__integer_sequence, size_t, _Ep - _Sp>::template
__to_tuple_indices<_Sp>;
#else
template <size_t _Ep, size_t _Sp>
using __make_indices_imp =
typename __detail::__make<_Ep - _Sp>::type::template __to_tuple_indices<_Sp>;
#endif
template <size_t _Ep, size_t _Sp = 0>
struct __make_tuple_indices
{
static_assert(_Sp <= _Ep, "__make_tuple_indices input error");
typedef __make_indices_imp<_Ep, _Sp> type;
};
template <class ..._Tp> class _LIBCPP_TEMPLATE_VIS tuple;
template <class... _Tp> struct __tuple_like<tuple<_Tp...> > : true_type {};
template <class ..._Tp>
struct _LIBCPP_TEMPLATE_VIS tuple_size<tuple<_Tp...> >
: public integral_constant<size_t, sizeof...(_Tp)>
{
};
template <size_t _Ip, class ..._Tp>
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
typename tuple_element<_Ip, tuple<_Tp...> >::type&
get(tuple<_Tp...>&) _NOEXCEPT;
template <size_t _Ip, class ..._Tp>
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
const typename tuple_element<_Ip, tuple<_Tp...> >::type&
get(const tuple<_Tp...>&) _NOEXCEPT;
template <size_t _Ip, class ..._Tp>
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
typename tuple_element<_Ip, tuple<_Tp...> >::type&&
get(tuple<_Tp...>&&) _NOEXCEPT;
template <size_t _Ip, class ..._Tp>
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
const typename tuple_element<_Ip, tuple<_Tp...> >::type&&
get(const tuple<_Tp...>&&) _NOEXCEPT;
#endif // !defined(_LIBCPP_CXX03_LANG)
// pair specializations
template <class _T1, class _T2> struct __tuple_like<pair<_T1, _T2> > : true_type {};
template <size_t _Ip, class _T1, class _T2>
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
typename tuple_element<_Ip, pair<_T1, _T2> >::type&
get(pair<_T1, _T2>&) _NOEXCEPT;
template <size_t _Ip, class _T1, class _T2>
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
const typename tuple_element<_Ip, pair<_T1, _T2> >::type&
get(const pair<_T1, _T2>&) _NOEXCEPT;
#ifndef _LIBCPP_CXX03_LANG
template <size_t _Ip, class _T1, class _T2>
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
typename tuple_element<_Ip, pair<_T1, _T2> >::type&&
get(pair<_T1, _T2>&&) _NOEXCEPT;
template <size_t _Ip, class _T1, class _T2>
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
const typename tuple_element<_Ip, pair<_T1, _T2> >::type&&
get(const pair<_T1, _T2>&&) _NOEXCEPT;
#endif
// array specializations
template <class _Tp, size_t _Size> struct _LIBCPP_TEMPLATE_VIS array;
template <class _Tp, size_t _Size> struct __tuple_like<array<_Tp, _Size> > : true_type {};
template <size_t _Ip, class _Tp, size_t _Size>
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
_Tp&
get(array<_Tp, _Size>&) _NOEXCEPT;
template <size_t _Ip, class _Tp, size_t _Size>
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
const _Tp&
get(const array<_Tp, _Size>&) _NOEXCEPT;
#ifndef _LIBCPP_CXX03_LANG
template <size_t _Ip, class _Tp, size_t _Size>
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
_Tp&&
get(array<_Tp, _Size>&&) _NOEXCEPT;
template <size_t _Ip, class _Tp, size_t _Size>
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
const _Tp&&
get(const array<_Tp, _Size>&&) _NOEXCEPT;
#endif
#ifndef _LIBCPP_CXX03_LANG
// __tuple_types
template <class ..._Tp> struct __tuple_types {};
#if !__has_builtin(__type_pack_element)
namespace __indexer_detail {
template <size_t _Idx, class _Tp>
struct __indexed { using type _LIBCPP_NODEBUG_TYPE = _Tp; };
template <class _Types, class _Indexes> struct __indexer;
template <class ..._Types, size_t ..._Idx>
struct __indexer<__tuple_types<_Types...>, __tuple_indices<_Idx...>>
: __indexed<_Idx, _Types>...
{};
template <size_t _Idx, class _Tp>
__indexed<_Idx, _Tp> __at_index(__indexed<_Idx, _Tp> const&);
} // namespace __indexer_detail
template <size_t _Idx, class ..._Types>
using __type_pack_element _LIBCPP_NODEBUG_TYPE = typename decltype(
__indexer_detail::__at_index<_Idx>(
__indexer_detail::__indexer<
__tuple_types<_Types...>,
typename __make_tuple_indices<sizeof...(_Types)>::type
>{})
)::type;
#endif
template <size_t _Ip, class ..._Types>
struct _LIBCPP_TEMPLATE_VIS tuple_element<_Ip, __tuple_types<_Types...>>
{
static_assert(_Ip < sizeof...(_Types), "tuple_element index out of range");
typedef _LIBCPP_NODEBUG_TYPE __type_pack_element<_Ip, _Types...> type;
};
template <class ..._Tp>
struct _LIBCPP_TEMPLATE_VIS tuple_size<__tuple_types<_Tp...> >
: public integral_constant<size_t, sizeof...(_Tp)>
{
};
template <class... _Tp> struct __tuple_like<__tuple_types<_Tp...> > : true_type {};
template <bool _ApplyLV, bool _ApplyConst, bool _ApplyVolatile>
struct __apply_cv_mf;
template <>
struct __apply_cv_mf<false, false, false> {
template <class _Tp> using __apply = _Tp;
};
template <>
struct __apply_cv_mf<false, true, false> {
template <class _Tp> using __apply _LIBCPP_NODEBUG_TYPE = const _Tp;
};
template <>
struct __apply_cv_mf<false, false, true> {
template <class _Tp> using __apply _LIBCPP_NODEBUG_TYPE = volatile _Tp;
};
template <>
struct __apply_cv_mf<false, true, true> {
template <class _Tp> using __apply _LIBCPP_NODEBUG_TYPE = const volatile _Tp;
};
template <>
struct __apply_cv_mf<true, false, false> {
template <class _Tp> using __apply _LIBCPP_NODEBUG_TYPE = _Tp&;
};
template <>
struct __apply_cv_mf<true, true, false> {
template <class _Tp> using __apply _LIBCPP_NODEBUG_TYPE = const _Tp&;
};
template <>
struct __apply_cv_mf<true, false, true> {
template <class _Tp> using __apply _LIBCPP_NODEBUG_TYPE = volatile _Tp&;
};
template <>
struct __apply_cv_mf<true, true, true> {
template <class _Tp> using __apply _LIBCPP_NODEBUG_TYPE = const volatile _Tp&;
};
template <class _Tp, class _RawTp = typename remove_reference<_Tp>::type>
using __apply_cv_t _LIBCPP_NODEBUG_TYPE = __apply_cv_mf<
is_lvalue_reference<_Tp>::value,
is_const<_RawTp>::value,
is_volatile<_RawTp>::value>;
// __make_tuple_types
// __make_tuple_types<_Tuple<_Types...>, _Ep, _Sp>::type is a
// __tuple_types<_Types...> using only those _Types in the range [_Sp, _Ep).
// _Sp defaults to 0 and _Ep defaults to tuple_size<_Tuple>. If _Tuple is a
// lvalue_reference type, then __tuple_types<_Types&...> is the result.
template <class _TupleTypes, class _TupleIndices>
struct __make_tuple_types_flat;
template <template <class...> class _Tuple, class ..._Types, size_t ..._Idx>
struct __make_tuple_types_flat<_Tuple<_Types...>, __tuple_indices<_Idx...>> {
// Specialization for pair, tuple, and __tuple_types
template <class _Tp, class _ApplyFn = __apply_cv_t<_Tp>>
using __apply_quals _LIBCPP_NODEBUG_TYPE = __tuple_types<
typename _ApplyFn::template __apply<__type_pack_element<_Idx, _Types...>>...
>;
};
template <class _Vt, size_t _Np, size_t ..._Idx>
struct __make_tuple_types_flat<array<_Vt, _Np>, __tuple_indices<_Idx...>> {
template <size_t>
using __value_type = _Vt;
template <class _Tp, class _ApplyFn = __apply_cv_t<_Tp>>
using __apply_quals = __tuple_types<
typename _ApplyFn::template __apply<__value_type<_Idx>>...
>;
};
template <class _Tp, size_t _Ep = tuple_size<typename remove_reference<_Tp>::type>::value,
size_t _Sp = 0,
bool _SameSize = (_Ep == tuple_size<typename remove_reference<_Tp>::type>::value)>
struct __make_tuple_types
{
static_assert(_Sp <= _Ep, "__make_tuple_types input error");
using _RawTp = typename remove_cv<typename remove_reference<_Tp>::type>::type;
using _Maker = __make_tuple_types_flat<_RawTp, typename __make_tuple_indices<_Ep, _Sp>::type>;
using type = typename _Maker::template __apply_quals<_Tp>;
};
template <class ..._Types, size_t _Ep>
struct __make_tuple_types<tuple<_Types...>, _Ep, 0, true> {
typedef _LIBCPP_NODEBUG_TYPE __tuple_types<_Types...> type;
};
template <class ..._Types, size_t _Ep>
struct __make_tuple_types<__tuple_types<_Types...>, _Ep, 0, true> {
typedef _LIBCPP_NODEBUG_TYPE __tuple_types<_Types...> type;
};
template <bool ..._Preds>
struct __all_dummy;
template <bool ..._Pred>
using __all = _IsSame<__all_dummy<_Pred...>, __all_dummy<((void)_Pred, true)...>>;
struct __tuple_sfinae_base {
template <template <class, class...> class _Trait,
class ..._LArgs, class ..._RArgs>
static auto __do_test(__tuple_types<_LArgs...>, __tuple_types<_RArgs...>)
-> __all<typename enable_if<_Trait<_LArgs, _RArgs>::value, bool>::type{true}...>;
template <template <class...> class>
static auto __do_test(...) -> false_type;
template <class _FromArgs, class _ToArgs>
using __constructible = decltype(__do_test<is_constructible>(_ToArgs{}, _FromArgs{}));
template <class _FromArgs, class _ToArgs>
using __convertible = decltype(__do_test<is_convertible>(_FromArgs{}, _ToArgs{}));
template <class _FromArgs, class _ToArgs>
using __assignable = decltype(__do_test<is_assignable>(_ToArgs{}, _FromArgs{}));
};
// __tuple_convertible
template <class _Tp, class _Up, bool = __tuple_like<typename remove_reference<_Tp>::type>::value,
bool = __tuple_like<_Up>::value>
struct __tuple_convertible
: public false_type {};
template <class _Tp, class _Up>
struct __tuple_convertible<_Tp, _Up, true, true>
: public __tuple_sfinae_base::__convertible<
typename __make_tuple_types<_Tp>::type
, typename __make_tuple_types<_Up>::type
>
{};
// __tuple_constructible
template <class _Tp, class _Up, bool = __tuple_like<typename remove_reference<_Tp>::type>::value,
bool = __tuple_like<_Up>::value>
struct __tuple_constructible
: public false_type {};
template <class _Tp, class _Up>
struct __tuple_constructible<_Tp, _Up, true, true>
: public __tuple_sfinae_base::__constructible<
typename __make_tuple_types<_Tp>::type
, typename __make_tuple_types<_Up>::type
>
{};
// __tuple_assignable
template <class _Tp, class _Up, bool = __tuple_like<typename remove_reference<_Tp>::type>::value,
bool = __tuple_like<_Up>::value>
struct __tuple_assignable
: public false_type {};
template <class _Tp, class _Up>
struct __tuple_assignable<_Tp, _Up, true, true>
: public __tuple_sfinae_base::__assignable<
typename __make_tuple_types<_Tp>::type
, typename __make_tuple_types<_Up&>::type
>
{};
template <size_t _Ip, class ..._Tp>
struct _LIBCPP_TEMPLATE_VIS tuple_element<_Ip, tuple<_Tp...> >
{
typedef _LIBCPP_NODEBUG_TYPE typename tuple_element<_Ip, __tuple_types<_Tp...> >::type type;
};
#if _LIBCPP_STD_VER > 11
template <size_t _Ip, class ..._Tp>
using tuple_element_t _LIBCPP_NODEBUG_TYPE = typename tuple_element <_Ip, _Tp...>::type;
#endif
template <bool _IsTuple, class _SizeTrait, size_t _Expected>
struct __tuple_like_with_size_imp : false_type {};
template <class _SizeTrait, size_t _Expected>
struct __tuple_like_with_size_imp<true, _SizeTrait, _Expected>
: integral_constant<bool, _SizeTrait::value == _Expected> {};
template <class _Tuple, size_t _ExpectedSize,
class _RawTuple = typename __uncvref<_Tuple>::type>
using __tuple_like_with_size _LIBCPP_NODEBUG_TYPE = __tuple_like_with_size_imp<
__tuple_like<_RawTuple>::value,
tuple_size<_RawTuple>, _ExpectedSize
>;
struct _LIBCPP_TYPE_VIS __check_tuple_constructor_fail {
static constexpr bool __enable_explicit_default() { return false; }
static constexpr bool __enable_implicit_default() { return false; }
template <class ...>
static constexpr bool __enable_explicit() { return false; }
template <class ...>
static constexpr bool __enable_implicit() { return false; }
template <class ...>
static constexpr bool __enable_assign() { return false; }
};
#endif // !defined(_LIBCPP_CXX03_LANG)
#if _LIBCPP_STD_VER > 14
template <bool _CanCopy, bool _CanMove>
struct __sfinae_ctor_base {};
template <>
struct __sfinae_ctor_base<false, false> {
__sfinae_ctor_base() = default;
__sfinae_ctor_base(__sfinae_ctor_base const&) = delete;
__sfinae_ctor_base(__sfinae_ctor_base &&) = delete;
__sfinae_ctor_base& operator=(__sfinae_ctor_base const&) = default;
__sfinae_ctor_base& operator=(__sfinae_ctor_base&&) = default;
};
template <>
struct __sfinae_ctor_base<true, false> {
__sfinae_ctor_base() = default;
__sfinae_ctor_base(__sfinae_ctor_base const&) = default;
__sfinae_ctor_base(__sfinae_ctor_base &&) = delete;
__sfinae_ctor_base& operator=(__sfinae_ctor_base const&) = default;
__sfinae_ctor_base& operator=(__sfinae_ctor_base&&) = default;
};
template <>
struct __sfinae_ctor_base<false, true> {
__sfinae_ctor_base() = default;
__sfinae_ctor_base(__sfinae_ctor_base const&) = delete;
__sfinae_ctor_base(__sfinae_ctor_base &&) = default;
__sfinae_ctor_base& operator=(__sfinae_ctor_base const&) = default;
__sfinae_ctor_base& operator=(__sfinae_ctor_base&&) = default;
};
template <bool _CanCopy, bool _CanMove>
struct __sfinae_assign_base {};
template <>
struct __sfinae_assign_base<false, false> {
__sfinae_assign_base() = default;
__sfinae_assign_base(__sfinae_assign_base const&) = default;
__sfinae_assign_base(__sfinae_assign_base &&) = default;
__sfinae_assign_base& operator=(__sfinae_assign_base const&) = delete;
__sfinae_assign_base& operator=(__sfinae_assign_base&&) = delete;
};
template <>
struct __sfinae_assign_base<true, false> {
__sfinae_assign_base() = default;
__sfinae_assign_base(__sfinae_assign_base const&) = default;
__sfinae_assign_base(__sfinae_assign_base &&) = default;
__sfinae_assign_base& operator=(__sfinae_assign_base const&) = default;
__sfinae_assign_base& operator=(__sfinae_assign_base&&) = delete;
};
template <>
struct __sfinae_assign_base<false, true> {
__sfinae_assign_base() = default;
__sfinae_assign_base(__sfinae_assign_base const&) = default;
__sfinae_assign_base(__sfinae_assign_base &&) = default;
__sfinae_assign_base& operator=(__sfinae_assign_base const&) = delete;
__sfinae_assign_base& operator=(__sfinae_assign_base&&) = default;
};
#endif // _LIBCPP_STD_VER > 14
_LIBCPP_END_NAMESPACE_STD
#endif // _LIBCPP___TUPLE
| 20,732 | 552 | jart/cosmopolitan | false |
cosmopolitan/third_party/libcxx/system_error | // -*- C++ -*-
//===---------------------------- system_error ----------------------------===//
//
// 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_SYSTEM_ERROR
#define _LIBCPP_SYSTEM_ERROR
#include "third_party/libcxx/__errc"
#include "third_party/libcxx/type_traits"
#include "third_party/libcxx/stdexcept"
#include "third_party/libcxx/__functional_base"
#include "third_party/libcxx/string"
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
#pragma GCC system_header
#endif
_LIBCPP_BEGIN_NAMESPACE_STD
/*
system_error synopsis
namespace std
{
class error_category
{
public:
virtual ~error_category() noexcept;
constexpr error_category();
error_category(const error_category&) = delete;
error_category& operator=(const error_category&) = delete;
virtual const char* name() const noexcept = 0;
virtual error_condition default_error_condition(int ev) const noexcept;
virtual bool equivalent(int code, const error_condition& condition) const noexcept;
virtual bool equivalent(const error_code& code, int condition) const noexcept;
virtual string message(int ev) const = 0;
bool operator==(const error_category& rhs) const noexcept;
bool operator!=(const error_category& rhs) const noexcept;
bool operator<(const error_category& rhs) const noexcept;
};
const error_category& generic_category() noexcept;
const error_category& system_category() noexcept;
template <class T> struct is_error_code_enum
: public false_type {};
template <class T> struct is_error_condition_enum
: public false_type {};
template <class _Tp>
inline constexpr size_t is_error_condition_enum_v = is_error_condition_enum<_Tp>::value; // C++17
template <class _Tp>
inline constexpr size_t is_error_code_enum_v = is_error_code_enum<_Tp>::value; // C++17
class error_code
{
public:
// constructors:
error_code() noexcept;
error_code(int val, const error_category& cat) noexcept;
template <class ErrorCodeEnum>
error_code(ErrorCodeEnum e) noexcept;
// modifiers:
void assign(int val, const error_category& cat) noexcept;
template <class ErrorCodeEnum>
error_code& operator=(ErrorCodeEnum e) noexcept;
void clear() noexcept;
// observers:
int value() const noexcept;
const error_category& category() const noexcept;
error_condition default_error_condition() const noexcept;
string message() const;
explicit operator bool() const noexcept;
};
// non-member functions:
bool operator<(const error_code& lhs, const error_code& rhs) noexcept;
template <class charT, class traits>
basic_ostream<charT,traits>&
operator<<(basic_ostream<charT,traits>& os, const error_code& ec);
class error_condition
{
public:
// constructors:
error_condition() noexcept;
error_condition(int val, const error_category& cat) noexcept;
template <class ErrorConditionEnum>
error_condition(ErrorConditionEnum e) noexcept;
// modifiers:
void assign(int val, const error_category& cat) noexcept;
template <class ErrorConditionEnum>
error_condition& operator=(ErrorConditionEnum e) noexcept;
void clear() noexcept;
// observers:
int value() const noexcept;
const error_category& category() const noexcept;
string message() const noexcept;
explicit operator bool() const noexcept;
};
bool operator<(const error_condition& lhs, const error_condition& rhs) noexcept;
class system_error
: public runtime_error
{
public:
system_error(error_code ec, const string& what_arg);
system_error(error_code ec, const char* what_arg);
system_error(error_code ec);
system_error(int ev, const error_category& ecat, const string& what_arg);
system_error(int ev, const error_category& ecat, const char* what_arg);
system_error(int ev, const error_category& ecat);
const error_code& code() const noexcept;
const char* what() const noexcept;
};
template <> struct is_error_condition_enum<errc>
: true_type { }
error_code make_error_code(errc e) noexcept;
error_condition make_error_condition(errc e) noexcept;
// Comparison operators:
bool operator==(const error_code& lhs, const error_code& rhs) noexcept;
bool operator==(const error_code& lhs, const error_condition& rhs) noexcept;
bool operator==(const error_condition& lhs, const error_code& rhs) noexcept;
bool operator==(const error_condition& lhs, const error_condition& rhs) noexcept;
bool operator!=(const error_code& lhs, const error_code& rhs) noexcept;
bool operator!=(const error_code& lhs, const error_condition& rhs) noexcept;
bool operator!=(const error_condition& lhs, const error_code& rhs) noexcept;
bool operator!=(const error_condition& lhs, const error_condition& rhs) noexcept;
template <> struct hash<std::error_code>;
template <> struct hash<std::error_condition>;
} // std
*/
// is_error_code_enum
template <class _Tp>
struct _LIBCPP_TEMPLATE_VIS is_error_code_enum
: public false_type {};
#if _LIBCPP_STD_VER > 14
template <class _Tp>
_LIBCPP_INLINE_VAR constexpr size_t is_error_code_enum_v = is_error_code_enum<_Tp>::value;
#endif
// is_error_condition_enum
template <class _Tp>
struct _LIBCPP_TEMPLATE_VIS is_error_condition_enum
: public false_type {};
#if _LIBCPP_STD_VER > 14
template <class _Tp>
_LIBCPP_INLINE_VAR constexpr size_t is_error_condition_enum_v = is_error_condition_enum<_Tp>::value;
#endif
template <>
struct _LIBCPP_TEMPLATE_VIS is_error_condition_enum<errc>
: true_type { };
#ifdef _LIBCPP_HAS_NO_STRONG_ENUMS
template <>
struct _LIBCPP_TEMPLATE_VIS is_error_condition_enum<errc::__lx>
: true_type { };
#endif
class _LIBCPP_TYPE_VIS error_condition;
class _LIBCPP_TYPE_VIS error_code;
// class error_category
class _LIBCPP_HIDDEN __do_message;
class _LIBCPP_TYPE_VIS error_category
{
public:
virtual ~error_category() _NOEXCEPT;
#if defined(_LIBCPP_BUILDING_LIBRARY) && \
defined(_LIBCPP_DEPRECATED_ABI_LEGACY_LIBRARY_DEFINITIONS_FOR_INLINE_FUNCTIONS)
error_category() _NOEXCEPT;
#else
_LIBCPP_INLINE_VISIBILITY
_LIBCPP_CONSTEXPR_AFTER_CXX11 error_category() _NOEXCEPT _LIBCPP_DEFAULT
#endif
private:
error_category(const error_category&);// = delete;
error_category& operator=(const error_category&);// = delete;
public:
virtual const char* name() const _NOEXCEPT = 0;
virtual error_condition default_error_condition(int __ev) const _NOEXCEPT;
virtual bool equivalent(int __code, const error_condition& __condition) const _NOEXCEPT;
virtual bool equivalent(const error_code& __code, int __condition) const _NOEXCEPT;
virtual string message(int __ev) const = 0;
_LIBCPP_INLINE_VISIBILITY
bool operator==(const error_category& __rhs) const _NOEXCEPT {return this == &__rhs;}
_LIBCPP_INLINE_VISIBILITY
bool operator!=(const error_category& __rhs) const _NOEXCEPT {return !(*this == __rhs);}
_LIBCPP_INLINE_VISIBILITY
bool operator< (const error_category& __rhs) const _NOEXCEPT {return this < &__rhs;}
friend class _LIBCPP_HIDDEN __do_message;
};
class _LIBCPP_HIDDEN __do_message
: public error_category
{
public:
virtual string message(int ev) const;
};
_LIBCPP_FUNC_VIS const error_category& generic_category() _NOEXCEPT;
_LIBCPP_FUNC_VIS const error_category& system_category() _NOEXCEPT;
class _LIBCPP_TYPE_VIS error_condition
{
int __val_;
const error_category* __cat_;
public:
_LIBCPP_INLINE_VISIBILITY
error_condition() _NOEXCEPT : __val_(0), __cat_(&generic_category()) {}
_LIBCPP_INLINE_VISIBILITY
error_condition(int __val, const error_category& __cat) _NOEXCEPT
: __val_(__val), __cat_(&__cat) {}
template <class _Ep>
_LIBCPP_INLINE_VISIBILITY
error_condition(_Ep __e,
typename enable_if<is_error_condition_enum<_Ep>::value>::type* = 0
) _NOEXCEPT
{*this = make_error_condition(__e);}
_LIBCPP_INLINE_VISIBILITY
void assign(int __val, const error_category& __cat) _NOEXCEPT
{
__val_ = __val;
__cat_ = &__cat;
}
template <class _Ep>
_LIBCPP_INLINE_VISIBILITY
typename enable_if
<
is_error_condition_enum<_Ep>::value,
error_condition&
>::type
operator=(_Ep __e) _NOEXCEPT
{*this = make_error_condition(__e); return *this;}
_LIBCPP_INLINE_VISIBILITY
void clear() _NOEXCEPT
{
__val_ = 0;
__cat_ = &generic_category();
}
_LIBCPP_INLINE_VISIBILITY
int value() const _NOEXCEPT {return __val_;}
_LIBCPP_INLINE_VISIBILITY
const error_category& category() const _NOEXCEPT {return *__cat_;}
string message() const;
_LIBCPP_INLINE_VISIBILITY
_LIBCPP_EXPLICIT
operator bool() const _NOEXCEPT {return __val_ != 0;}
};
inline _LIBCPP_INLINE_VISIBILITY
error_condition
make_error_condition(errc __e) _NOEXCEPT
{
return error_condition(static_cast<int>(__e), generic_category());
}
inline _LIBCPP_INLINE_VISIBILITY
bool
operator<(const error_condition& __x, const error_condition& __y) _NOEXCEPT
{
return __x.category() < __y.category()
|| (__x.category() == __y.category() && __x.value() < __y.value());
}
// error_code
class _LIBCPP_TYPE_VIS error_code
{
int __val_;
const error_category* __cat_;
public:
_LIBCPP_INLINE_VISIBILITY
error_code() _NOEXCEPT : __val_(0), __cat_(&system_category()) {}
_LIBCPP_INLINE_VISIBILITY
error_code(int __val, const error_category& __cat) _NOEXCEPT
: __val_(__val), __cat_(&__cat) {}
template <class _Ep>
_LIBCPP_INLINE_VISIBILITY
error_code(_Ep __e,
typename enable_if<is_error_code_enum<_Ep>::value>::type* = 0
) _NOEXCEPT
{*this = make_error_code(__e);}
_LIBCPP_INLINE_VISIBILITY
void assign(int __val, const error_category& __cat) _NOEXCEPT
{
__val_ = __val;
__cat_ = &__cat;
}
template <class _Ep>
_LIBCPP_INLINE_VISIBILITY
typename enable_if
<
is_error_code_enum<_Ep>::value,
error_code&
>::type
operator=(_Ep __e) _NOEXCEPT
{*this = make_error_code(__e); return *this;}
_LIBCPP_INLINE_VISIBILITY
void clear() _NOEXCEPT
{
__val_ = 0;
__cat_ = &system_category();
}
_LIBCPP_INLINE_VISIBILITY
int value() const _NOEXCEPT {return __val_;}
_LIBCPP_INLINE_VISIBILITY
const error_category& category() const _NOEXCEPT {return *__cat_;}
_LIBCPP_INLINE_VISIBILITY
error_condition default_error_condition() const _NOEXCEPT
{return __cat_->default_error_condition(__val_);}
string message() const;
_LIBCPP_INLINE_VISIBILITY
_LIBCPP_EXPLICIT
operator bool() const _NOEXCEPT {return __val_ != 0;}
};
inline _LIBCPP_INLINE_VISIBILITY
error_code
make_error_code(errc __e) _NOEXCEPT
{
return error_code(static_cast<int>(__e), generic_category());
}
inline _LIBCPP_INLINE_VISIBILITY
bool
operator<(const error_code& __x, const error_code& __y) _NOEXCEPT
{
return __x.category() < __y.category()
|| (__x.category() == __y.category() && __x.value() < __y.value());
}
inline _LIBCPP_INLINE_VISIBILITY
bool
operator==(const error_code& __x, const error_code& __y) _NOEXCEPT
{
return __x.category() == __y.category() && __x.value() == __y.value();
}
inline _LIBCPP_INLINE_VISIBILITY
bool
operator==(const error_code& __x, const error_condition& __y) _NOEXCEPT
{
return __x.category().equivalent(__x.value(), __y)
|| __y.category().equivalent(__x, __y.value());
}
inline _LIBCPP_INLINE_VISIBILITY
bool
operator==(const error_condition& __x, const error_code& __y) _NOEXCEPT
{
return __y == __x;
}
inline _LIBCPP_INLINE_VISIBILITY
bool
operator==(const error_condition& __x, const error_condition& __y) _NOEXCEPT
{
return __x.category() == __y.category() && __x.value() == __y.value();
}
inline _LIBCPP_INLINE_VISIBILITY
bool
operator!=(const error_code& __x, const error_code& __y) _NOEXCEPT
{return !(__x == __y);}
inline _LIBCPP_INLINE_VISIBILITY
bool
operator!=(const error_code& __x, const error_condition& __y) _NOEXCEPT
{return !(__x == __y);}
inline _LIBCPP_INLINE_VISIBILITY
bool
operator!=(const error_condition& __x, const error_code& __y) _NOEXCEPT
{return !(__x == __y);}
inline _LIBCPP_INLINE_VISIBILITY
bool
operator!=(const error_condition& __x, const error_condition& __y) _NOEXCEPT
{return !(__x == __y);}
template <>
struct _LIBCPP_TEMPLATE_VIS hash<error_code>
: public unary_function<error_code, size_t>
{
_LIBCPP_INLINE_VISIBILITY
size_t operator()(const error_code& __ec) const _NOEXCEPT
{
return static_cast<size_t>(__ec.value());
}
};
template <>
struct _LIBCPP_TEMPLATE_VIS hash<error_condition>
: public unary_function<error_condition, size_t>
{
_LIBCPP_INLINE_VISIBILITY
size_t operator()(const error_condition& __ec) const _NOEXCEPT
{
return static_cast<size_t>(__ec.value());
}
};
// system_error
class _LIBCPP_TYPE_VIS system_error
: public runtime_error
{
error_code __ec_;
public:
system_error(error_code __ec, const string& __what_arg);
system_error(error_code __ec, const char* __what_arg);
system_error(error_code __ec);
system_error(int __ev, const error_category& __ecat, const string& __what_arg);
system_error(int __ev, const error_category& __ecat, const char* __what_arg);
system_error(int __ev, const error_category& __ecat);
~system_error() _NOEXCEPT;
_LIBCPP_INLINE_VISIBILITY
const error_code& code() const _NOEXCEPT {return __ec_;}
private:
static string __init(const error_code&, string);
};
_LIBCPP_NORETURN _LIBCPP_FUNC_VIS
void __throw_system_error(int ev, const char* what_arg);
_LIBCPP_END_NAMESPACE_STD
#endif // _LIBCPP_SYSTEM_ERROR
| 14,251 | 487 | jart/cosmopolitan | false |
cosmopolitan/third_party/libcxx/cstring | // -*- C++ -*-
//===--------------------------- cstring ----------------------------------===//
//
// 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_CSTRING
#define _LIBCPP_CSTRING
#include "third_party/libcxx/__config"
#include "third_party/libcxx/string.h"
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
#pragma GCC system_header
#endif
_LIBCPP_BEGIN_NAMESPACE_STD
/*
cstring synopsis
Macros:
NULL
namespace std
{
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);
} // std
*/
using ::size_t;
using ::memcpy;
using ::memmove;
using ::strcpy;
using ::strncpy;
using ::strcat;
using ::strncat;
using ::memcmp;
using ::strcmp;
using ::strncmp;
using ::strcoll;
using ::strxfrm;
using ::memchr;
using ::strchr;
using ::strcspn;
using ::strpbrk;
using ::strrchr;
using ::strspn;
using ::strstr;
#ifndef _LIBCPP_HAS_NO_THREAD_UNSAFE_C_FUNCTIONS
using ::strtok;
#endif
using ::memset;
using ::strerror;
using ::strlen;
_LIBCPP_END_NAMESPACE_STD
#endif // _LIBCPP_CSTRING
| 2,592 | 97 | jart/cosmopolitan | false |
cosmopolitan/third_party/libcxx/iterator | // -*- C++ -*-
//===-------------------------- iterator ----------------------------------===//
//
// 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_ITERATOR
#define _LIBCPP_ITERATOR
#include "third_party/libcxx/__config"
#include "third_party/libcxx/iosfwd" // for forward declarations of vector and string.
#include "third_party/libcxx/__functional_base"
#include "third_party/libcxx/type_traits"
#include "third_party/libcxx/cstddef"
#include "third_party/libcxx/initializer_list"
#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
/*
iterator synopsis
namespace std
{
template<class Iterator>
struct iterator_traits
{
typedef typename Iterator::difference_type difference_type;
typedef typename Iterator::value_type value_type;
typedef typename Iterator::pointer pointer;
typedef typename Iterator::reference reference;
typedef typename Iterator::iterator_category iterator_category;
};
template<class T>
struct iterator_traits<T*>
{
typedef ptrdiff_t difference_type;
typedef T value_type;
typedef T* pointer;
typedef T& reference;
typedef random_access_iterator_tag iterator_category;
};
template<class Category, class T, class Distance = ptrdiff_t,
class Pointer = T*, class Reference = T&>
struct iterator
{
typedef T value_type;
typedef Distance difference_type;
typedef Pointer pointer;
typedef Reference reference;
typedef Category iterator_category;
};
struct input_iterator_tag {};
struct output_iterator_tag {};
struct forward_iterator_tag : public input_iterator_tag {};
struct bidirectional_iterator_tag : public forward_iterator_tag {};
struct random_access_iterator_tag : public bidirectional_iterator_tag {};
// 27.4.3, iterator operations
// extension: second argument not conforming to C++03
template <class InputIterator> // constexpr in C++17
constexpr void advance(InputIterator& i,
typename iterator_traits<InputIterator>::difference_type n);
template <class InputIterator> // constexpr in C++17
constexpr typename iterator_traits<InputIterator>::difference_type
distance(InputIterator first, InputIterator last);
template <class InputIterator> // constexpr in C++17
constexpr InputIterator next(InputIterator x,
typename iterator_traits<InputIterator>::difference_type n = 1);
template <class BidirectionalIterator> // constexpr in C++17
constexpr BidirectionalIterator prev(BidirectionalIterator x,
typename iterator_traits<BidirectionalIterator>::difference_type n = 1);
template <class Iterator>
class reverse_iterator
: public iterator<typename iterator_traits<Iterator>::iterator_category,
typename iterator_traits<Iterator>::value_type,
typename iterator_traits<Iterator>::difference_type,
typename iterator_traits<Iterator>::pointer,
typename iterator_traits<Iterator>::reference>
{
protected:
Iterator current;
public:
typedef Iterator iterator_type;
typedef typename iterator_traits<Iterator>::difference_type difference_type;
typedef typename iterator_traits<Iterator>::reference reference;
typedef typename iterator_traits<Iterator>::pointer pointer;
constexpr reverse_iterator();
constexpr explicit reverse_iterator(Iterator x);
template <class U> constexpr reverse_iterator(const reverse_iterator<U>& u);
template <class U> constexpr reverse_iterator& operator=(const reverse_iterator<U>& u);
constexpr Iterator base() const;
constexpr reference operator*() const;
constexpr pointer operator->() const;
constexpr reverse_iterator& operator++();
constexpr reverse_iterator operator++(int);
constexpr reverse_iterator& operator--();
constexpr reverse_iterator operator--(int);
constexpr reverse_iterator operator+ (difference_type n) const;
constexpr reverse_iterator& operator+=(difference_type n);
constexpr reverse_iterator operator- (difference_type n) const;
constexpr reverse_iterator& operator-=(difference_type n);
constexpr reference operator[](difference_type n) const;
};
template <class Iterator1, class Iterator2>
constexpr bool // constexpr in C++17
operator==(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2>& y);
template <class Iterator1, class Iterator2>
constexpr bool // constexpr in C++17
operator<(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2>& y);
template <class Iterator1, class Iterator2>
constexpr bool // constexpr in C++17
operator!=(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2>& y);
template <class Iterator1, class Iterator2>
constexpr bool // constexpr in C++17
operator>(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2>& y);
template <class Iterator1, class Iterator2>
constexpr bool // constexpr in C++17
operator>=(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2>& y);
template <class Iterator1, class Iterator2>
constexpr bool // constexpr in C++17
operator<=(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2>& y);
template <class Iterator1, class Iterator2>
constexpr auto
operator-(const reverse_iterator<Iterator1>& x, const reverse_iterator<Iterator2>& y)
-> decltype(__y.base() - __x.base()); // constexpr in C++17
template <class Iterator>
constexpr reverse_iterator<Iterator>
operator+(typename reverse_iterator<Iterator>::difference_type n,
const reverse_iterator<Iterator>& x); // constexpr in C++17
template <class Iterator>
constexpr reverse_iterator<Iterator> make_reverse_iterator(Iterator i); // C++14, constexpr in C++17
template <class Container>
class back_insert_iterator
{
protected:
Container* container;
public:
typedef Container container_type;
typedef void value_type;
typedef void difference_type;
typedef void reference;
typedef void pointer;
explicit back_insert_iterator(Container& x);
back_insert_iterator& operator=(const typename Container::value_type& value);
back_insert_iterator& operator*();
back_insert_iterator& operator++();
back_insert_iterator operator++(int);
};
template <class Container> back_insert_iterator<Container> back_inserter(Container& x);
template <class Container>
class front_insert_iterator
{
protected:
Container* container;
public:
typedef Container container_type;
typedef void value_type;
typedef void difference_type;
typedef void reference;
typedef void pointer;
explicit front_insert_iterator(Container& x);
front_insert_iterator& operator=(const typename Container::value_type& value);
front_insert_iterator& operator*();
front_insert_iterator& operator++();
front_insert_iterator operator++(int);
};
template <class Container> front_insert_iterator<Container> front_inserter(Container& x);
template <class Container>
class insert_iterator
{
protected:
Container* container;
typename Container::iterator iter;
public:
typedef Container container_type;
typedef void value_type;
typedef void difference_type;
typedef void reference;
typedef void pointer;
insert_iterator(Container& x, typename Container::iterator i);
insert_iterator& operator=(const typename Container::value_type& value);
insert_iterator& operator*();
insert_iterator& operator++();
insert_iterator& operator++(int);
};
template <class Container, class Iterator>
insert_iterator<Container> inserter(Container& x, Iterator i);
template <class Iterator>
class move_iterator {
public:
typedef Iterator iterator_type;
typedef typename iterator_traits<Iterator>::difference_type difference_type;
typedef Iterator pointer;
typedef typename iterator_traits<Iterator>::value_type value_type;
typedef typename iterator_traits<Iterator>::iterator_category iterator_category;
typedef value_type&& reference;
constexpr move_iterator(); // all the constexprs are in C++17
constexpr explicit move_iterator(Iterator i);
template <class U>
constexpr move_iterator(const move_iterator<U>& u);
template <class U>
constexpr move_iterator& operator=(const move_iterator<U>& u);
constexpr iterator_type base() const;
constexpr reference operator*() const;
constexpr pointer operator->() const;
constexpr move_iterator& operator++();
constexpr move_iterator operator++(int);
constexpr move_iterator& operator--();
constexpr move_iterator operator--(int);
constexpr move_iterator operator+(difference_type n) const;
constexpr move_iterator& operator+=(difference_type n);
constexpr move_iterator operator-(difference_type n) const;
constexpr move_iterator& operator-=(difference_type n);
constexpr unspecified operator[](difference_type n) const;
private:
Iterator current; // exposition only
};
template <class Iterator1, class Iterator2>
constexpr bool // constexpr in C++17
operator==(const move_iterator<Iterator1>& x, const move_iterator<Iterator2>& y);
template <class Iterator1, class Iterator2>
constexpr bool // constexpr in C++17
operator!=(const move_iterator<Iterator1>& x, const move_iterator<Iterator2>& y);
template <class Iterator1, class Iterator2>
constexpr bool // constexpr in C++17
operator<(const move_iterator<Iterator1>& x, const move_iterator<Iterator2>& y);
template <class Iterator1, class Iterator2>
constexpr bool // constexpr in C++17
operator<=(const move_iterator<Iterator1>& x, const move_iterator<Iterator2>& y);
template <class Iterator1, class Iterator2>
constexpr bool // constexpr in C++17
operator>(const move_iterator<Iterator1>& x, const move_iterator<Iterator2>& y);
template <class Iterator1, class Iterator2>
constexpr bool // constexpr in C++17
operator>=(const move_iterator<Iterator1>& x, const move_iterator<Iterator2>& y);
template <class Iterator1, class Iterator2>
constexpr auto // constexpr in C++17
operator-(const move_iterator<Iterator1>& x,
const move_iterator<Iterator2>& y) -> decltype(x.base() - y.base());
template <class Iterator>
constexpr move_iterator<Iterator> operator+( // constexpr in C++17
typename move_iterator<Iterator>::difference_type n,
const move_iterator<Iterator>& x);
template <class Iterator> // constexpr in C++17
constexpr move_iterator<Iterator> make_move_iterator(const Iterator& i);
template <class T, class charT = char, class traits = char_traits<charT>, class Distance = ptrdiff_t>
class istream_iterator
: public iterator<input_iterator_tag, T, Distance, const T*, const T&>
{
public:
typedef charT char_type;
typedef traits traits_type;
typedef basic_istream<charT,traits> istream_type;
constexpr istream_iterator();
istream_iterator(istream_type& s);
istream_iterator(const istream_iterator& x);
~istream_iterator();
const T& operator*() const;
const T* operator->() const;
istream_iterator& operator++();
istream_iterator operator++(int);
};
template <class T, class charT, class traits, class Distance>
bool operator==(const istream_iterator<T,charT,traits,Distance>& x,
const istream_iterator<T,charT,traits,Distance>& y);
template <class T, class charT, class traits, class Distance>
bool operator!=(const istream_iterator<T,charT,traits,Distance>& x,
const istream_iterator<T,charT,traits,Distance>& y);
template <class T, class charT = char, class traits = char_traits<charT> >
class ostream_iterator
: public iterator<output_iterator_tag, void, void, void ,void>
{
public:
typedef charT char_type;
typedef traits traits_type;
typedef basic_ostream<charT,traits> ostream_type;
ostream_iterator(ostream_type& s);
ostream_iterator(ostream_type& s, const charT* delimiter);
ostream_iterator(const ostream_iterator& x);
~ostream_iterator();
ostream_iterator& operator=(const T& value);
ostream_iterator& operator*();
ostream_iterator& operator++();
ostream_iterator& operator++(int);
};
template<class charT, class traits = char_traits<charT> >
class istreambuf_iterator
: public iterator<input_iterator_tag, charT,
typename traits::off_type, unspecified,
charT>
{
public:
typedef charT char_type;
typedef traits traits_type;
typedef typename traits::int_type int_type;
typedef basic_streambuf<charT,traits> streambuf_type;
typedef basic_istream<charT,traits> istream_type;
istreambuf_iterator() noexcept;
istreambuf_iterator(istream_type& s) noexcept;
istreambuf_iterator(streambuf_type* s) noexcept;
istreambuf_iterator(a-private-type) noexcept;
charT operator*() const;
pointer operator->() const;
istreambuf_iterator& operator++();
a-private-type operator++(int);
bool equal(const istreambuf_iterator& b) const;
};
template <class charT, class traits>
bool operator==(const istreambuf_iterator<charT,traits>& a,
const istreambuf_iterator<charT,traits>& b);
template <class charT, class traits>
bool operator!=(const istreambuf_iterator<charT,traits>& a,
const istreambuf_iterator<charT,traits>& b);
template <class charT, class traits = char_traits<charT> >
class ostreambuf_iterator
: public iterator<output_iterator_tag, void, void, void, void>
{
public:
typedef charT char_type;
typedef traits traits_type;
typedef basic_streambuf<charT,traits> streambuf_type;
typedef basic_ostream<charT,traits> ostream_type;
ostreambuf_iterator(ostream_type& s) noexcept;
ostreambuf_iterator(streambuf_type* s) noexcept;
ostreambuf_iterator& operator=(charT c);
ostreambuf_iterator& operator*();
ostreambuf_iterator& operator++();
ostreambuf_iterator& operator++(int);
bool failed() const noexcept;
};
template <class C> constexpr auto begin(C& c) -> decltype(c.begin());
template <class C> constexpr auto begin(const C& c) -> decltype(c.begin());
template <class C> constexpr auto end(C& c) -> decltype(c.end());
template <class C> constexpr auto end(const C& c) -> decltype(c.end());
template <class T, size_t N> constexpr T* begin(T (&array)[N]);
template <class T, size_t N> constexpr T* end(T (&array)[N]);
template <class C> auto constexpr cbegin(const C& c) -> decltype(std::begin(c)); // C++14
template <class C> auto constexpr cend(const C& c) -> decltype(std::end(c)); // C++14
template <class C> auto constexpr rbegin(C& c) -> decltype(c.rbegin()); // C++14
template <class C> auto constexpr rbegin(const C& c) -> decltype(c.rbegin()); // C++14
template <class C> auto constexpr rend(C& c) -> decltype(c.rend()); // C++14
template <class C> constexpr auto rend(const C& c) -> decltype(c.rend()); // C++14
template <class E> reverse_iterator<const E*> constexpr rbegin(initializer_list<E> il); // C++14
template <class E> reverse_iterator<const E*> constexpr rend(initializer_list<E> il); // C++14
template <class T, size_t N> reverse_iterator<T*> constexpr rbegin(T (&array)[N]); // C++14
template <class T, size_t N> reverse_iterator<T*> constexpr rend(T (&array)[N]); // C++14
template <class C> constexpr auto crbegin(const C& c) -> decltype(std::rbegin(c)); // C++14
template <class C> constexpr auto crend(const C& c) -> decltype(std::rend(c)); // C++14
// 24.8, container access:
template <class C> constexpr auto size(const C& c) -> decltype(c.size()); // C++17
template <class T, size_t N> constexpr size_t size(const T (&array)[N]) noexcept; // C++17
template <class C> constexpr auto ssize(const C& c)
-> common_type_t<ptrdiff_t, make_signed_t<decltype(c.size())>>; // C++20
template <class T, ptrdiff_t> constexpr ptrdiff_t ssize(const T (&array)[N]) noexcept; // C++20
template <class C> constexpr auto empty(const C& c) -> decltype(c.empty()); // C++17
template <class T, size_t N> constexpr bool empty(const T (&array)[N]) noexcept; // C++17
template <class E> constexpr bool empty(initializer_list<E> il) noexcept; // C++17
template <class C> constexpr auto data(C& c) -> decltype(c.data()); // C++17
template <class C> constexpr auto data(const C& c) -> decltype(c.data()); // C++17
template <class T, size_t N> constexpr T* data(T (&array)[N]) noexcept; // C++17
template <class E> constexpr const E* data(initializer_list<E> il) noexcept; // C++17
} // std
*/
struct _LIBCPP_TEMPLATE_VIS input_iterator_tag {};
struct _LIBCPP_TEMPLATE_VIS output_iterator_tag {};
struct _LIBCPP_TEMPLATE_VIS forward_iterator_tag : public input_iterator_tag {};
struct _LIBCPP_TEMPLATE_VIS bidirectional_iterator_tag : public forward_iterator_tag {};
struct _LIBCPP_TEMPLATE_VIS random_access_iterator_tag : public bidirectional_iterator_tag {};
template <class _Tp>
struct __has_iterator_typedefs
{
private:
struct __two {char __lx; char __lxx;};
template <class _Up> static __two __test(...);
template <class _Up> static char __test(typename std::__void_t<typename _Up::iterator_category>::type* = 0,
typename std::__void_t<typename _Up::difference_type>::type* = 0,
typename std::__void_t<typename _Up::value_type>::type* = 0,
typename std::__void_t<typename _Up::reference>::type* = 0,
typename std::__void_t<typename _Up::pointer>::type* = 0
);
public:
static const bool value = sizeof(__test<_Tp>(0,0,0,0,0)) == 1;
};
template <class _Tp>
struct __has_iterator_category
{
private:
struct __two {char __lx; char __lxx;};
template <class _Up> static __two __test(...);
template <class _Up> static char __test(typename _Up::iterator_category* = 0);
public:
static const bool value = sizeof(__test<_Tp>(0)) == 1;
};
template <class _Iter, bool> struct __iterator_traits_impl {};
template <class _Iter>
struct __iterator_traits_impl<_Iter, true>
{
typedef typename _Iter::difference_type difference_type;
typedef typename _Iter::value_type value_type;
typedef typename _Iter::pointer pointer;
typedef typename _Iter::reference reference;
typedef typename _Iter::iterator_category iterator_category;
};
template <class _Iter, bool> struct __iterator_traits {};
template <class _Iter>
struct __iterator_traits<_Iter, true>
: __iterator_traits_impl
<
_Iter,
is_convertible<typename _Iter::iterator_category, input_iterator_tag>::value ||
is_convertible<typename _Iter::iterator_category, output_iterator_tag>::value
>
{};
// iterator_traits<Iterator> will only have the nested types if Iterator::iterator_category
// exists. Else iterator_traits<Iterator> will be an empty class. This is a
// conforming extension which allows some programs to compile and behave as
// the client expects instead of failing at compile time.
template <class _Iter>
struct _LIBCPP_TEMPLATE_VIS iterator_traits
: __iterator_traits<_Iter, __has_iterator_typedefs<_Iter>::value> {};
template<class _Tp>
struct _LIBCPP_TEMPLATE_VIS iterator_traits<_Tp*>
{
typedef ptrdiff_t difference_type;
typedef typename remove_cv<_Tp>::type value_type;
typedef _Tp* pointer;
typedef _Tp& reference;
typedef random_access_iterator_tag iterator_category;
};
template <class _Tp, class _Up, bool = __has_iterator_category<iterator_traits<_Tp> >::value>
struct __has_iterator_category_convertible_to
: public integral_constant<bool, is_convertible<typename iterator_traits<_Tp>::iterator_category, _Up>::value>
{};
template <class _Tp, class _Up>
struct __has_iterator_category_convertible_to<_Tp, _Up, false> : public false_type {};
template <class _Tp>
struct __is_input_iterator : public __has_iterator_category_convertible_to<_Tp, input_iterator_tag> {};
template <class _Tp>
struct __is_forward_iterator : public __has_iterator_category_convertible_to<_Tp, forward_iterator_tag> {};
template <class _Tp>
struct __is_bidirectional_iterator : public __has_iterator_category_convertible_to<_Tp, bidirectional_iterator_tag> {};
template <class _Tp>
struct __is_random_access_iterator : public __has_iterator_category_convertible_to<_Tp, random_access_iterator_tag> {};
template <class _Tp>
struct __is_exactly_input_iterator
: public integral_constant<bool,
__has_iterator_category_convertible_to<_Tp, input_iterator_tag>::value &&
!__has_iterator_category_convertible_to<_Tp, forward_iterator_tag>::value> {};
#ifndef _LIBCPP_HAS_NO_DEDUCTION_GUIDES
template<class _InputIterator>
using __iter_value_type = typename iterator_traits<_InputIterator>::value_type;
template<class _InputIterator>
using __iter_key_type = remove_const_t<typename iterator_traits<_InputIterator>::value_type::first_type>;
template<class _InputIterator>
using __iter_mapped_type = typename iterator_traits<_InputIterator>::value_type::second_type;
template<class _InputIterator>
using __iter_to_alloc_type = pair<
add_const_t<typename iterator_traits<_InputIterator>::value_type::first_type>,
typename iterator_traits<_InputIterator>::value_type::second_type>;
#endif
template<class _Category, class _Tp, class _Distance = ptrdiff_t,
class _Pointer = _Tp*, class _Reference = _Tp&>
struct _LIBCPP_TEMPLATE_VIS iterator
{
typedef _Tp value_type;
typedef _Distance difference_type;
typedef _Pointer pointer;
typedef _Reference reference;
typedef _Category iterator_category;
};
template <class _InputIter>
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
void __advance(_InputIter& __i,
typename iterator_traits<_InputIter>::difference_type __n, input_iterator_tag)
{
for (; __n > 0; --__n)
++__i;
}
template <class _BiDirIter>
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
void __advance(_BiDirIter& __i,
typename iterator_traits<_BiDirIter>::difference_type __n, bidirectional_iterator_tag)
{
if (__n >= 0)
for (; __n > 0; --__n)
++__i;
else
for (; __n < 0; ++__n)
--__i;
}
template <class _RandIter>
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
void __advance(_RandIter& __i,
typename iterator_traits<_RandIter>::difference_type __n, random_access_iterator_tag)
{
__i += __n;
}
template <class _InputIter>
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
void advance(_InputIter& __i,
typename iterator_traits<_InputIter>::difference_type __n)
{
_LIBCPP_ASSERT(__n >= 0 || __is_bidirectional_iterator<_InputIter>::value,
"Attempt to advance(it, -n) on a non-bidi iterator");
__advance(__i, __n, typename iterator_traits<_InputIter>::iterator_category());
}
template <class _InputIter>
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
typename iterator_traits<_InputIter>::difference_type
__distance(_InputIter __first, _InputIter __last, input_iterator_tag)
{
typename iterator_traits<_InputIter>::difference_type __r(0);
for (; __first != __last; ++__first)
++__r;
return __r;
}
template <class _RandIter>
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
typename iterator_traits<_RandIter>::difference_type
__distance(_RandIter __first, _RandIter __last, random_access_iterator_tag)
{
return __last - __first;
}
template <class _InputIter>
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
typename iterator_traits<_InputIter>::difference_type
distance(_InputIter __first, _InputIter __last)
{
return __distance(__first, __last, typename iterator_traits<_InputIter>::iterator_category());
}
template <class _InputIter>
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
typename enable_if
<
__is_input_iterator<_InputIter>::value,
_InputIter
>::type
next(_InputIter __x,
typename iterator_traits<_InputIter>::difference_type __n = 1)
{
_LIBCPP_ASSERT(__n >= 0 || __is_bidirectional_iterator<_InputIter>::value,
"Attempt to next(it, -n) on a non-bidi iterator");
_VSTD::advance(__x, __n);
return __x;
}
template <class _InputIter>
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
typename enable_if
<
__is_input_iterator<_InputIter>::value,
_InputIter
>::type
prev(_InputIter __x,
typename iterator_traits<_InputIter>::difference_type __n = 1)
{
_LIBCPP_ASSERT(__n <= 0 || __is_bidirectional_iterator<_InputIter>::value,
"Attempt to prev(it, +n) on a non-bidi iterator");
_VSTD::advance(__x, -__n);
return __x;
}
template <class _Tp, class = void>
struct __is_stashing_iterator : false_type {};
template <class _Tp>
struct __is_stashing_iterator<_Tp, typename __void_t<typename _Tp::__stashing_iterator_tag>::type>
: true_type {};
template <class _Iter>
class _LIBCPP_TEMPLATE_VIS reverse_iterator
: public iterator<typename iterator_traits<_Iter>::iterator_category,
typename iterator_traits<_Iter>::value_type,
typename iterator_traits<_Iter>::difference_type,
typename iterator_traits<_Iter>::pointer,
typename iterator_traits<_Iter>::reference>
{
private:
/*mutable*/ _Iter __t; // no longer used as of LWG #2360, not removed due to ABI break
static_assert(!__is_stashing_iterator<_Iter>::value,
"The specified iterator type cannot be used with reverse_iterator; "
"Using stashing iterators with reverse_iterator causes undefined behavior");
protected:
_Iter current;
public:
typedef _Iter iterator_type;
typedef typename iterator_traits<_Iter>::difference_type difference_type;
typedef typename iterator_traits<_Iter>::reference reference;
typedef typename iterator_traits<_Iter>::pointer pointer;
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
reverse_iterator() : __t(), current() {}
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
explicit reverse_iterator(_Iter __x) : __t(__x), current(__x) {}
template <class _Up>
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
reverse_iterator(const reverse_iterator<_Up>& __u) : __t(__u.base()), current(__u.base()) {}
template <class _Up>
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
reverse_iterator& operator=(const reverse_iterator<_Up>& __u)
{ __t = current = __u.base(); return *this; }
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
_Iter base() const {return current;}
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
reference operator*() const {_Iter __tmp = current; return *--__tmp;}
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
pointer operator->() const {return _VSTD::addressof(operator*());}
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
reverse_iterator& operator++() {--current; return *this;}
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
reverse_iterator operator++(int) {reverse_iterator __tmp(*this); --current; return __tmp;}
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
reverse_iterator& operator--() {++current; return *this;}
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
reverse_iterator operator--(int) {reverse_iterator __tmp(*this); ++current; return __tmp;}
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
reverse_iterator operator+ (difference_type __n) const {return reverse_iterator(current - __n);}
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
reverse_iterator& operator+=(difference_type __n) {current -= __n; return *this;}
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
reverse_iterator operator- (difference_type __n) const {return reverse_iterator(current + __n);}
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
reverse_iterator& operator-=(difference_type __n) {current += __n; return *this;}
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
reference operator[](difference_type __n) const {return *(*this + __n);}
};
template <class _Iter1, class _Iter2>
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
bool
operator==(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
{
return __x.base() == __y.base();
}
template <class _Iter1, class _Iter2>
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
bool
operator<(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
{
return __x.base() > __y.base();
}
template <class _Iter1, class _Iter2>
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
bool
operator!=(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
{
return __x.base() != __y.base();
}
template <class _Iter1, class _Iter2>
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
bool
operator>(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
{
return __x.base() < __y.base();
}
template <class _Iter1, class _Iter2>
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
bool
operator>=(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
{
return __x.base() <= __y.base();
}
template <class _Iter1, class _Iter2>
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
bool
operator<=(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
{
return __x.base() >= __y.base();
}
#ifndef _LIBCPP_CXX03_LANG
template <class _Iter1, class _Iter2>
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
auto
operator-(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
-> decltype(__y.base() - __x.base())
{
return __y.base() - __x.base();
}
#else
template <class _Iter1, class _Iter2>
inline _LIBCPP_INLINE_VISIBILITY
typename reverse_iterator<_Iter1>::difference_type
operator-(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
{
return __y.base() - __x.base();
}
#endif
template <class _Iter>
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
reverse_iterator<_Iter>
operator+(typename reverse_iterator<_Iter>::difference_type __n, const reverse_iterator<_Iter>& __x)
{
return reverse_iterator<_Iter>(__x.base() - __n);
}
#if _LIBCPP_STD_VER > 11
template <class _Iter>
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
reverse_iterator<_Iter> make_reverse_iterator(_Iter __i)
{
return reverse_iterator<_Iter>(__i);
}
#endif
template <class _Container>
class _LIBCPP_TEMPLATE_VIS back_insert_iterator
: public iterator<output_iterator_tag,
void,
void,
void,
void>
{
protected:
_Container* container;
public:
typedef _Container container_type;
_LIBCPP_INLINE_VISIBILITY explicit back_insert_iterator(_Container& __x) : container(_VSTD::addressof(__x)) {}
_LIBCPP_INLINE_VISIBILITY back_insert_iterator& operator=(const typename _Container::value_type& __value_)
{container->push_back(__value_); return *this;}
#ifndef _LIBCPP_CXX03_LANG
_LIBCPP_INLINE_VISIBILITY back_insert_iterator& operator=(typename _Container::value_type&& __value_)
{container->push_back(_VSTD::move(__value_)); return *this;}
#endif // _LIBCPP_CXX03_LANG
_LIBCPP_INLINE_VISIBILITY back_insert_iterator& operator*() {return *this;}
_LIBCPP_INLINE_VISIBILITY back_insert_iterator& operator++() {return *this;}
_LIBCPP_INLINE_VISIBILITY back_insert_iterator operator++(int) {return *this;}
};
template <class _Container>
inline _LIBCPP_INLINE_VISIBILITY
back_insert_iterator<_Container>
back_inserter(_Container& __x)
{
return back_insert_iterator<_Container>(__x);
}
template <class _Container>
class _LIBCPP_TEMPLATE_VIS front_insert_iterator
: public iterator<output_iterator_tag,
void,
void,
void,
void>
{
protected:
_Container* container;
public:
typedef _Container container_type;
_LIBCPP_INLINE_VISIBILITY explicit front_insert_iterator(_Container& __x) : container(_VSTD::addressof(__x)) {}
_LIBCPP_INLINE_VISIBILITY front_insert_iterator& operator=(const typename _Container::value_type& __value_)
{container->push_front(__value_); return *this;}
#ifndef _LIBCPP_CXX03_LANG
_LIBCPP_INLINE_VISIBILITY front_insert_iterator& operator=(typename _Container::value_type&& __value_)
{container->push_front(_VSTD::move(__value_)); return *this;}
#endif // _LIBCPP_CXX03_LANG
_LIBCPP_INLINE_VISIBILITY front_insert_iterator& operator*() {return *this;}
_LIBCPP_INLINE_VISIBILITY front_insert_iterator& operator++() {return *this;}
_LIBCPP_INLINE_VISIBILITY front_insert_iterator operator++(int) {return *this;}
};
template <class _Container>
inline _LIBCPP_INLINE_VISIBILITY
front_insert_iterator<_Container>
front_inserter(_Container& __x)
{
return front_insert_iterator<_Container>(__x);
}
template <class _Container>
class _LIBCPP_TEMPLATE_VIS insert_iterator
: public iterator<output_iterator_tag,
void,
void,
void,
void>
{
protected:
_Container* container;
typename _Container::iterator iter;
public:
typedef _Container container_type;
_LIBCPP_INLINE_VISIBILITY insert_iterator(_Container& __x, typename _Container::iterator __i)
: container(_VSTD::addressof(__x)), iter(__i) {}
_LIBCPP_INLINE_VISIBILITY insert_iterator& operator=(const typename _Container::value_type& __value_)
{iter = container->insert(iter, __value_); ++iter; return *this;}
#ifndef _LIBCPP_CXX03_LANG
_LIBCPP_INLINE_VISIBILITY insert_iterator& operator=(typename _Container::value_type&& __value_)
{iter = container->insert(iter, _VSTD::move(__value_)); ++iter; return *this;}
#endif // _LIBCPP_CXX03_LANG
_LIBCPP_INLINE_VISIBILITY insert_iterator& operator*() {return *this;}
_LIBCPP_INLINE_VISIBILITY insert_iterator& operator++() {return *this;}
_LIBCPP_INLINE_VISIBILITY insert_iterator& operator++(int) {return *this;}
};
template <class _Container>
inline _LIBCPP_INLINE_VISIBILITY
insert_iterator<_Container>
inserter(_Container& __x, typename _Container::iterator __i)
{
return insert_iterator<_Container>(__x, __i);
}
template <class _Tp, class _CharT = char,
class _Traits = char_traits<_CharT>, class _Distance = ptrdiff_t>
class _LIBCPP_TEMPLATE_VIS istream_iterator
: public iterator<input_iterator_tag, _Tp, _Distance, const _Tp*, const _Tp&>
{
public:
typedef _CharT char_type;
typedef _Traits traits_type;
typedef basic_istream<_CharT,_Traits> istream_type;
private:
istream_type* __in_stream_;
_Tp __value_;
public:
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR istream_iterator() : __in_stream_(0), __value_() {}
_LIBCPP_INLINE_VISIBILITY istream_iterator(istream_type& __s) : __in_stream_(_VSTD::addressof(__s))
{
if (!(*__in_stream_ >> __value_))
__in_stream_ = 0;
}
_LIBCPP_INLINE_VISIBILITY const _Tp& operator*() const {return __value_;}
_LIBCPP_INLINE_VISIBILITY const _Tp* operator->() const {return _VSTD::addressof((operator*()));}
_LIBCPP_INLINE_VISIBILITY istream_iterator& operator++()
{
if (!(*__in_stream_ >> __value_))
__in_stream_ = 0;
return *this;
}
_LIBCPP_INLINE_VISIBILITY istream_iterator operator++(int)
{istream_iterator __t(*this); ++(*this); return __t;}
template <class _Up, class _CharU, class _TraitsU, class _DistanceU>
friend _LIBCPP_INLINE_VISIBILITY
bool
operator==(const istream_iterator<_Up, _CharU, _TraitsU, _DistanceU>& __x,
const istream_iterator<_Up, _CharU, _TraitsU, _DistanceU>& __y);
template <class _Up, class _CharU, class _TraitsU, class _DistanceU>
friend _LIBCPP_INLINE_VISIBILITY
bool
operator==(const istream_iterator<_Up, _CharU, _TraitsU, _DistanceU>& __x,
const istream_iterator<_Up, _CharU, _TraitsU, _DistanceU>& __y);
};
template <class _Tp, class _CharT, class _Traits, class _Distance>
inline _LIBCPP_INLINE_VISIBILITY
bool
operator==(const istream_iterator<_Tp, _CharT, _Traits, _Distance>& __x,
const istream_iterator<_Tp, _CharT, _Traits, _Distance>& __y)
{
return __x.__in_stream_ == __y.__in_stream_;
}
template <class _Tp, class _CharT, class _Traits, class _Distance>
inline _LIBCPP_INLINE_VISIBILITY
bool
operator!=(const istream_iterator<_Tp, _CharT, _Traits, _Distance>& __x,
const istream_iterator<_Tp, _CharT, _Traits, _Distance>& __y)
{
return !(__x == __y);
}
template <class _Tp, class _CharT = char, class _Traits = char_traits<_CharT> >
class _LIBCPP_TEMPLATE_VIS ostream_iterator
: public iterator<output_iterator_tag, void, void, void, void>
{
public:
typedef _CharT char_type;
typedef _Traits traits_type;
typedef basic_ostream<_CharT,_Traits> ostream_type;
private:
ostream_type* __out_stream_;
const char_type* __delim_;
public:
_LIBCPP_INLINE_VISIBILITY ostream_iterator(ostream_type& __s) _NOEXCEPT
: __out_stream_(_VSTD::addressof(__s)), __delim_(0) {}
_LIBCPP_INLINE_VISIBILITY ostream_iterator(ostream_type& __s, const _CharT* __delimiter) _NOEXCEPT
: __out_stream_(_VSTD::addressof(__s)), __delim_(__delimiter) {}
_LIBCPP_INLINE_VISIBILITY ostream_iterator& operator=(const _Tp& __value_)
{
*__out_stream_ << __value_;
if (__delim_)
*__out_stream_ << __delim_;
return *this;
}
_LIBCPP_INLINE_VISIBILITY ostream_iterator& operator*() {return *this;}
_LIBCPP_INLINE_VISIBILITY ostream_iterator& operator++() {return *this;}
_LIBCPP_INLINE_VISIBILITY ostream_iterator& operator++(int) {return *this;}
};
template<class _CharT, class _Traits>
class _LIBCPP_TEMPLATE_VIS istreambuf_iterator
: public iterator<input_iterator_tag, _CharT,
typename _Traits::off_type, _CharT*,
_CharT>
{
public:
typedef _CharT char_type;
typedef _Traits traits_type;
typedef typename _Traits::int_type int_type;
typedef basic_streambuf<_CharT,_Traits> streambuf_type;
typedef basic_istream<_CharT,_Traits> istream_type;
private:
mutable streambuf_type* __sbuf_;
class __proxy
{
char_type __keep_;
streambuf_type* __sbuf_;
_LIBCPP_INLINE_VISIBILITY __proxy(char_type __c, streambuf_type* __s)
: __keep_(__c), __sbuf_(__s) {}
friend class istreambuf_iterator;
public:
_LIBCPP_INLINE_VISIBILITY char_type operator*() const {return __keep_;}
};
_LIBCPP_INLINE_VISIBILITY
bool __test_for_eof() const
{
if (__sbuf_ && traits_type::eq_int_type(__sbuf_->sgetc(), traits_type::eof()))
__sbuf_ = 0;
return __sbuf_ == 0;
}
public:
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR istreambuf_iterator() _NOEXCEPT : __sbuf_(0) {}
_LIBCPP_INLINE_VISIBILITY istreambuf_iterator(istream_type& __s) _NOEXCEPT
: __sbuf_(__s.rdbuf()) {}
_LIBCPP_INLINE_VISIBILITY istreambuf_iterator(streambuf_type* __s) _NOEXCEPT
: __sbuf_(__s) {}
_LIBCPP_INLINE_VISIBILITY istreambuf_iterator(const __proxy& __p) _NOEXCEPT
: __sbuf_(__p.__sbuf_) {}
_LIBCPP_INLINE_VISIBILITY char_type operator*() const
{return static_cast<char_type>(__sbuf_->sgetc());}
_LIBCPP_INLINE_VISIBILITY istreambuf_iterator& operator++()
{
__sbuf_->sbumpc();
return *this;
}
_LIBCPP_INLINE_VISIBILITY __proxy operator++(int)
{
return __proxy(__sbuf_->sbumpc(), __sbuf_);
}
_LIBCPP_INLINE_VISIBILITY bool equal(const istreambuf_iterator& __b) const
{return __test_for_eof() == __b.__test_for_eof();}
};
template <class _CharT, class _Traits>
inline _LIBCPP_INLINE_VISIBILITY
bool operator==(const istreambuf_iterator<_CharT,_Traits>& __a,
const istreambuf_iterator<_CharT,_Traits>& __b)
{return __a.equal(__b);}
template <class _CharT, class _Traits>
inline _LIBCPP_INLINE_VISIBILITY
bool operator!=(const istreambuf_iterator<_CharT,_Traits>& __a,
const istreambuf_iterator<_CharT,_Traits>& __b)
{return !__a.equal(__b);}
template <class _CharT, class _Traits>
class _LIBCPP_TEMPLATE_VIS ostreambuf_iterator
: public iterator<output_iterator_tag, void, void, void, void>
{
public:
typedef _CharT char_type;
typedef _Traits traits_type;
typedef basic_streambuf<_CharT,_Traits> streambuf_type;
typedef basic_ostream<_CharT,_Traits> ostream_type;
private:
streambuf_type* __sbuf_;
public:
_LIBCPP_INLINE_VISIBILITY ostreambuf_iterator(ostream_type& __s) _NOEXCEPT
: __sbuf_(__s.rdbuf()) {}
_LIBCPP_INLINE_VISIBILITY ostreambuf_iterator(streambuf_type* __s) _NOEXCEPT
: __sbuf_(__s) {}
_LIBCPP_INLINE_VISIBILITY ostreambuf_iterator& operator=(_CharT __c)
{
if (__sbuf_ && traits_type::eq_int_type(__sbuf_->sputc(__c), traits_type::eof()))
__sbuf_ = 0;
return *this;
}
_LIBCPP_INLINE_VISIBILITY ostreambuf_iterator& operator*() {return *this;}
_LIBCPP_INLINE_VISIBILITY ostreambuf_iterator& operator++() {return *this;}
_LIBCPP_INLINE_VISIBILITY ostreambuf_iterator& operator++(int) {return *this;}
_LIBCPP_INLINE_VISIBILITY bool failed() const _NOEXCEPT {return __sbuf_ == 0;}
template <class _Ch, class _Tr>
friend
_LIBCPP_HIDDEN
ostreambuf_iterator<_Ch, _Tr>
__pad_and_output(ostreambuf_iterator<_Ch, _Tr> __s,
const _Ch* __ob, const _Ch* __op, const _Ch* __oe,
ios_base& __iob, _Ch __fl);
};
template <class _Iter>
class _LIBCPP_TEMPLATE_VIS move_iterator
{
private:
_Iter __i;
public:
typedef _Iter iterator_type;
typedef typename iterator_traits<iterator_type>::iterator_category iterator_category;
typedef typename iterator_traits<iterator_type>::value_type value_type;
typedef typename iterator_traits<iterator_type>::difference_type difference_type;
typedef iterator_type pointer;
#ifndef _LIBCPP_CXX03_LANG
typedef typename iterator_traits<iterator_type>::reference __reference;
typedef typename conditional<
is_reference<__reference>::value,
typename remove_reference<__reference>::type&&,
__reference
>::type reference;
#else
typedef typename iterator_traits<iterator_type>::reference reference;
#endif
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
move_iterator() : __i() {}
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
explicit move_iterator(_Iter __x) : __i(__x) {}
template <class _Up>
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
move_iterator(const move_iterator<_Up>& __u) : __i(__u.base()) {}
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14 _Iter base() const {return __i;}
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
reference operator*() const { return static_cast<reference>(*__i); }
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
pointer operator->() const { return __i;}
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
move_iterator& operator++() {++__i; return *this;}
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
move_iterator operator++(int) {move_iterator __tmp(*this); ++__i; return __tmp;}
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
move_iterator& operator--() {--__i; return *this;}
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
move_iterator operator--(int) {move_iterator __tmp(*this); --__i; return __tmp;}
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
move_iterator operator+ (difference_type __n) const {return move_iterator(__i + __n);}
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
move_iterator& operator+=(difference_type __n) {__i += __n; return *this;}
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
move_iterator operator- (difference_type __n) const {return move_iterator(__i - __n);}
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
move_iterator& operator-=(difference_type __n) {__i -= __n; return *this;}
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
reference operator[](difference_type __n) const { return static_cast<reference>(__i[__n]); }
};
template <class _Iter1, class _Iter2>
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
bool
operator==(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
{
return __x.base() == __y.base();
}
template <class _Iter1, class _Iter2>
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
bool
operator<(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
{
return __x.base() < __y.base();
}
template <class _Iter1, class _Iter2>
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
bool
operator!=(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
{
return __x.base() != __y.base();
}
template <class _Iter1, class _Iter2>
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
bool
operator>(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
{
return __x.base() > __y.base();
}
template <class _Iter1, class _Iter2>
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
bool
operator>=(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
{
return __x.base() >= __y.base();
}
template <class _Iter1, class _Iter2>
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
bool
operator<=(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
{
return __x.base() <= __y.base();
}
#ifndef _LIBCPP_CXX03_LANG
template <class _Iter1, class _Iter2>
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
auto
operator-(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
-> decltype(__x.base() - __y.base())
{
return __x.base() - __y.base();
}
#else
template <class _Iter1, class _Iter2>
inline _LIBCPP_INLINE_VISIBILITY
typename move_iterator<_Iter1>::difference_type
operator-(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
{
return __x.base() - __y.base();
}
#endif
template <class _Iter>
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
move_iterator<_Iter>
operator+(typename move_iterator<_Iter>::difference_type __n, const move_iterator<_Iter>& __x)
{
return move_iterator<_Iter>(__x.base() + __n);
}
template <class _Iter>
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
move_iterator<_Iter>
make_move_iterator(_Iter __i)
{
return move_iterator<_Iter>(__i);
}
// __wrap_iter
template <class _Iter> class __wrap_iter;
template <class _Iter1, class _Iter2>
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
bool
operator==(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
template <class _Iter1, class _Iter2>
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
bool
operator<(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
template <class _Iter1, class _Iter2>
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
bool
operator!=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
template <class _Iter1, class _Iter2>
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
bool
operator>(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
template <class _Iter1, class _Iter2>
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
bool
operator>=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
template <class _Iter1, class _Iter2>
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
bool
operator<=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
#ifndef _LIBCPP_CXX03_LANG
template <class _Iter1, class _Iter2>
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
auto
operator-(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
-> decltype(__x.base() - __y.base());
#else
template <class _Iter1, class _Iter2>
_LIBCPP_INLINE_VISIBILITY
typename __wrap_iter<_Iter1>::difference_type
operator-(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
#endif
template <class _Iter>
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
__wrap_iter<_Iter>
operator+(typename __wrap_iter<_Iter>::difference_type, __wrap_iter<_Iter>) _NOEXCEPT;
template <class _Ip, class _Op> _Op _LIBCPP_INLINE_VISIBILITY copy(_Ip, _Ip, _Op);
template <class _B1, class _B2> _B2 _LIBCPP_INLINE_VISIBILITY copy_backward(_B1, _B1, _B2);
template <class _Ip, class _Op> _Op _LIBCPP_INLINE_VISIBILITY move(_Ip, _Ip, _Op);
template <class _B1, class _B2> _B2 _LIBCPP_INLINE_VISIBILITY move_backward(_B1, _B1, _B2);
#if _LIBCPP_DEBUG_LEVEL < 2
template <class _Tp>
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
typename enable_if
<
is_trivially_copy_assignable<_Tp>::value,
_Tp*
>::type
__unwrap_iter(__wrap_iter<_Tp*>);
#else
template <class _Tp>
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
typename enable_if
<
is_trivially_copy_assignable<_Tp>::value,
__wrap_iter<_Tp*>
>::type
__unwrap_iter(__wrap_iter<_Tp*> __i);
#endif
template <class _Iter>
class __wrap_iter
{
public:
typedef _Iter iterator_type;
typedef typename iterator_traits<iterator_type>::iterator_category iterator_category;
typedef typename iterator_traits<iterator_type>::value_type value_type;
typedef typename iterator_traits<iterator_type>::difference_type difference_type;
typedef typename iterator_traits<iterator_type>::pointer pointer;
typedef typename iterator_traits<iterator_type>::reference reference;
private:
iterator_type __i;
public:
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter() _NOEXCEPT
#if _LIBCPP_STD_VER > 11
: __i{}
#endif
{
#if _LIBCPP_DEBUG_LEVEL >= 2
__get_db()->__insert_i(this);
#endif
}
template <class _Up> _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
__wrap_iter(const __wrap_iter<_Up>& __u,
typename enable_if<is_convertible<_Up, iterator_type>::value>::type* = 0) _NOEXCEPT
: __i(__u.base())
{
#if _LIBCPP_DEBUG_LEVEL >= 2
__get_db()->__iterator_copy(this, &__u);
#endif
}
#if _LIBCPP_DEBUG_LEVEL >= 2
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
__wrap_iter(const __wrap_iter& __x)
: __i(__x.base())
{
__get_db()->__iterator_copy(this, &__x);
}
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
__wrap_iter& operator=(const __wrap_iter& __x)
{
if (this != &__x)
{
__get_db()->__iterator_copy(this, &__x);
__i = __x.__i;
}
return *this;
}
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
~__wrap_iter()
{
__get_db()->__erase_i(this);
}
#endif
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG reference operator*() const _NOEXCEPT
{
#if _LIBCPP_DEBUG_LEVEL >= 2
_LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this),
"Attempted to dereference a non-dereferenceable iterator");
#endif
return *__i;
}
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG pointer operator->() const _NOEXCEPT
{
#if _LIBCPP_DEBUG_LEVEL >= 2
_LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this),
"Attempted to dereference a non-dereferenceable iterator");
#endif
return (pointer)_VSTD::addressof(*__i);
}
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter& operator++() _NOEXCEPT
{
#if _LIBCPP_DEBUG_LEVEL >= 2
_LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this),
"Attempted to increment non-incrementable iterator");
#endif
++__i;
return *this;
}
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter operator++(int) _NOEXCEPT
{__wrap_iter __tmp(*this); ++(*this); return __tmp;}
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter& operator--() _NOEXCEPT
{
#if _LIBCPP_DEBUG_LEVEL >= 2
_LIBCPP_ASSERT(__get_const_db()->__decrementable(this),
"Attempted to decrement non-decrementable iterator");
#endif
--__i;
return *this;
}
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter operator--(int) _NOEXCEPT
{__wrap_iter __tmp(*this); --(*this); return __tmp;}
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter operator+ (difference_type __n) const _NOEXCEPT
{__wrap_iter __w(*this); __w += __n; return __w;}
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter& operator+=(difference_type __n) _NOEXCEPT
{
#if _LIBCPP_DEBUG_LEVEL >= 2
_LIBCPP_ASSERT(__get_const_db()->__addable(this, __n),
"Attempted to add/subtract iterator outside of valid range");
#endif
__i += __n;
return *this;
}
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter operator- (difference_type __n) const _NOEXCEPT
{return *this + (-__n);}
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter& operator-=(difference_type __n) _NOEXCEPT
{*this += -__n; return *this;}
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG reference operator[](difference_type __n) const _NOEXCEPT
{
#if _LIBCPP_DEBUG_LEVEL >= 2
_LIBCPP_ASSERT(__get_const_db()->__subscriptable(this, __n),
"Attempted to subscript iterator outside of valid range");
#endif
return __i[__n];
}
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG iterator_type base() const _NOEXCEPT {return __i;}
private:
#if _LIBCPP_DEBUG_LEVEL >= 2
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter(const void* __p, iterator_type __x) : __i(__x)
{
__get_db()->__insert_ic(this, __p);
}
#else
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG __wrap_iter(iterator_type __x) _NOEXCEPT : __i(__x) {}
#endif
template <class _Up> friend class __wrap_iter;
template <class _CharT, class _Traits, class _Alloc> friend class basic_string;
template <class _Tp, class _Alloc> friend class _LIBCPP_TEMPLATE_VIS vector;
template <class _Tp, size_t> friend class _LIBCPP_TEMPLATE_VIS span;
template <class _Iter1, class _Iter2>
_LIBCPP_CONSTEXPR_IF_NODEBUG friend
bool
operator==(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
template <class _Iter1, class _Iter2>
_LIBCPP_CONSTEXPR_IF_NODEBUG friend
bool
operator<(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
template <class _Iter1, class _Iter2>
_LIBCPP_CONSTEXPR_IF_NODEBUG friend
bool
operator!=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
template <class _Iter1, class _Iter2>
_LIBCPP_CONSTEXPR_IF_NODEBUG friend
bool
operator>(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
template <class _Iter1, class _Iter2>
_LIBCPP_CONSTEXPR_IF_NODEBUG friend
bool
operator>=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
template <class _Iter1, class _Iter2>
_LIBCPP_CONSTEXPR_IF_NODEBUG friend
bool
operator<=(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
#ifndef _LIBCPP_CXX03_LANG
template <class _Iter1, class _Iter2>
_LIBCPP_CONSTEXPR_IF_NODEBUG friend
auto
operator-(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
-> decltype(__x.base() - __y.base());
#else
template <class _Iter1, class _Iter2>
_LIBCPP_CONSTEXPR_IF_NODEBUG friend
typename __wrap_iter<_Iter1>::difference_type
operator-(const __wrap_iter<_Iter1>&, const __wrap_iter<_Iter2>&) _NOEXCEPT;
#endif
template <class _Iter1>
_LIBCPP_CONSTEXPR_IF_NODEBUG friend
__wrap_iter<_Iter1>
operator+(typename __wrap_iter<_Iter1>::difference_type, __wrap_iter<_Iter1>) _NOEXCEPT;
template <class _Ip, class _Op> friend _Op copy(_Ip, _Ip, _Op);
template <class _B1, class _B2> friend _B2 copy_backward(_B1, _B1, _B2);
template <class _Ip, class _Op> friend _Op move(_Ip, _Ip, _Op);
template <class _B1, class _B2> friend _B2 move_backward(_B1, _B1, _B2);
#if _LIBCPP_DEBUG_LEVEL < 2
template <class _Tp>
_LIBCPP_CONSTEXPR_IF_NODEBUG friend
typename enable_if
<
is_trivially_copy_assignable<_Tp>::value,
_Tp*
>::type
__unwrap_iter(__wrap_iter<_Tp*>);
#else
template <class _Tp>
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
typename enable_if
<
is_trivially_copy_assignable<_Tp>::value,
__wrap_iter<_Tp*>
>::type
__unwrap_iter(__wrap_iter<_Tp*> __i);
#endif
};
template <class _Iter1, class _Iter2>
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
bool
operator==(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
{
return __x.base() == __y.base();
}
template <class _Iter1, class _Iter2>
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
bool
operator<(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
{
#if _LIBCPP_DEBUG_LEVEL >= 2
_LIBCPP_ASSERT(__get_const_db()->__less_than_comparable(&__x, &__y),
"Attempted to compare incomparable iterators");
#endif
return __x.base() < __y.base();
}
template <class _Iter1, class _Iter2>
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
bool
operator!=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
{
return !(__x == __y);
}
template <class _Iter1, class _Iter2>
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
bool
operator>(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
{
return __y < __x;
}
template <class _Iter1, class _Iter2>
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
bool
operator>=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
{
return !(__x < __y);
}
template <class _Iter1, class _Iter2>
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
bool
operator<=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
{
return !(__y < __x);
}
template <class _Iter1>
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
bool
operator!=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter1>& __y) _NOEXCEPT
{
return !(__x == __y);
}
template <class _Iter1>
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
bool
operator>(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter1>& __y) _NOEXCEPT
{
return __y < __x;
}
template <class _Iter1>
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
bool
operator>=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter1>& __y) _NOEXCEPT
{
return !(__x < __y);
}
template <class _Iter1>
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
bool
operator<=(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter1>& __y) _NOEXCEPT
{
return !(__y < __x);
}
#ifndef _LIBCPP_CXX03_LANG
template <class _Iter1, class _Iter2>
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
auto
operator-(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
-> decltype(__x.base() - __y.base())
{
#if _LIBCPP_DEBUG_LEVEL >= 2
_LIBCPP_ASSERT(__get_const_db()->__less_than_comparable(&__x, &__y),
"Attempted to subtract incompatible iterators");
#endif
return __x.base() - __y.base();
}
#else
template <class _Iter1, class _Iter2>
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
typename __wrap_iter<_Iter1>::difference_type
operator-(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
{
#if _LIBCPP_DEBUG_LEVEL >= 2
_LIBCPP_ASSERT(__get_const_db()->__less_than_comparable(&__x, &__y),
"Attempted to subtract incompatible iterators");
#endif
return __x.base() - __y.base();
}
#endif
template <class _Iter>
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
__wrap_iter<_Iter>
operator+(typename __wrap_iter<_Iter>::difference_type __n,
__wrap_iter<_Iter> __x) _NOEXCEPT
{
__x += __n;
return __x;
}
template <class _Iter>
struct __libcpp_is_trivial_iterator
: public _LIBCPP_BOOL_CONSTANT(is_pointer<_Iter>::value) {};
template <class _Iter>
struct __libcpp_is_trivial_iterator<move_iterator<_Iter> >
: public _LIBCPP_BOOL_CONSTANT(__libcpp_is_trivial_iterator<_Iter>::value) {};
template <class _Iter>
struct __libcpp_is_trivial_iterator<reverse_iterator<_Iter> >
: public _LIBCPP_BOOL_CONSTANT(__libcpp_is_trivial_iterator<_Iter>::value) {};
template <class _Iter>
struct __libcpp_is_trivial_iterator<__wrap_iter<_Iter> >
: public _LIBCPP_BOOL_CONSTANT(__libcpp_is_trivial_iterator<_Iter>::value) {};
template <class _Tp, size_t _Np>
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
_Tp*
begin(_Tp (&__array)[_Np])
{
return __array;
}
template <class _Tp, size_t _Np>
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
_Tp*
end(_Tp (&__array)[_Np])
{
return __array + _Np;
}
#if !defined(_LIBCPP_CXX03_LANG)
template <class _Cp>
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
auto
begin(_Cp& __c) -> decltype(__c.begin())
{
return __c.begin();
}
template <class _Cp>
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
auto
begin(const _Cp& __c) -> decltype(__c.begin())
{
return __c.begin();
}
template <class _Cp>
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
auto
end(_Cp& __c) -> decltype(__c.end())
{
return __c.end();
}
template <class _Cp>
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
auto
end(const _Cp& __c) -> decltype(__c.end())
{
return __c.end();
}
#if _LIBCPP_STD_VER > 11
template <class _Tp, size_t _Np>
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
reverse_iterator<_Tp*> rbegin(_Tp (&__array)[_Np])
{
return reverse_iterator<_Tp*>(__array + _Np);
}
template <class _Tp, size_t _Np>
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
reverse_iterator<_Tp*> rend(_Tp (&__array)[_Np])
{
return reverse_iterator<_Tp*>(__array);
}
template <class _Ep>
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
reverse_iterator<const _Ep*> rbegin(initializer_list<_Ep> __il)
{
return reverse_iterator<const _Ep*>(__il.end());
}
template <class _Ep>
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
reverse_iterator<const _Ep*> rend(initializer_list<_Ep> __il)
{
return reverse_iterator<const _Ep*>(__il.begin());
}
template <class _Cp>
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
auto cbegin(const _Cp& __c) -> decltype(_VSTD::begin(__c))
{
return _VSTD::begin(__c);
}
template <class _Cp>
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
auto cend(const _Cp& __c) -> decltype(_VSTD::end(__c))
{
return _VSTD::end(__c);
}
template <class _Cp>
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
auto rbegin(_Cp& __c) -> decltype(__c.rbegin())
{
return __c.rbegin();
}
template <class _Cp>
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
auto rbegin(const _Cp& __c) -> decltype(__c.rbegin())
{
return __c.rbegin();
}
template <class _Cp>
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
auto rend(_Cp& __c) -> decltype(__c.rend())
{
return __c.rend();
}
template <class _Cp>
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
auto rend(const _Cp& __c) -> decltype(__c.rend())
{
return __c.rend();
}
template <class _Cp>
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
auto crbegin(const _Cp& __c) -> decltype(_VSTD::rbegin(__c))
{
return _VSTD::rbegin(__c);
}
template <class _Cp>
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX14
auto crend(const _Cp& __c) -> decltype(_VSTD::rend(__c))
{
return _VSTD::rend(__c);
}
#endif
#else // defined(_LIBCPP_CXX03_LANG)
template <class _Cp>
_LIBCPP_INLINE_VISIBILITY
typename _Cp::iterator
begin(_Cp& __c)
{
return __c.begin();
}
template <class _Cp>
_LIBCPP_INLINE_VISIBILITY
typename _Cp::const_iterator
begin(const _Cp& __c)
{
return __c.begin();
}
template <class _Cp>
_LIBCPP_INLINE_VISIBILITY
typename _Cp::iterator
end(_Cp& __c)
{
return __c.end();
}
template <class _Cp>
_LIBCPP_INLINE_VISIBILITY
typename _Cp::const_iterator
end(const _Cp& __c)
{
return __c.end();
}
#endif // !defined(_LIBCPP_CXX03_LANG)
#if _LIBCPP_STD_VER > 14
// #if _LIBCPP_STD_VER > 11
// template <>
// struct _LIBCPP_TEMPLATE_VIS plus<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
template <class _Cont>
_LIBCPP_INLINE_VISIBILITY
constexpr auto size(const _Cont& __c)
_NOEXCEPT_(noexcept(__c.size()))
-> decltype (__c.size())
{ return __c.size(); }
template <class _Tp, size_t _Sz>
_LIBCPP_INLINE_VISIBILITY
constexpr size_t size(const _Tp (&)[_Sz]) noexcept { return _Sz; }
#if _LIBCPP_STD_VER > 17
template <class _Cont>
_LIBCPP_INLINE_VISIBILITY
constexpr auto ssize(const _Cont& __c)
_NOEXCEPT_(noexcept(static_cast<common_type_t<ptrdiff_t, make_signed_t<decltype(__c.size())>>>(__c.size())))
-> common_type_t<ptrdiff_t, make_signed_t<decltype(__c.size())>>
{ return static_cast<common_type_t<ptrdiff_t, make_signed_t<decltype(__c.size())>>>(__c.size()); }
template <class _Tp, ptrdiff_t _Sz>
_LIBCPP_INLINE_VISIBILITY
constexpr ptrdiff_t ssize(const _Tp (&)[_Sz]) noexcept { return _Sz; }
#endif
template <class _Cont>
_LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
constexpr auto empty(const _Cont& __c)
_NOEXCEPT_(noexcept(__c.empty()))
-> decltype (__c.empty())
{ return __c.empty(); }
template <class _Tp, size_t _Sz>
_LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
constexpr bool empty(const _Tp (&)[_Sz]) noexcept { return false; }
template <class _Ep>
_LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
constexpr bool empty(initializer_list<_Ep> __il) noexcept { return __il.size() == 0; }
template <class _Cont> constexpr
_LIBCPP_INLINE_VISIBILITY
auto data(_Cont& __c)
_NOEXCEPT_(noexcept(__c.data()))
-> decltype (__c.data())
{ return __c.data(); }
template <class _Cont> constexpr
_LIBCPP_INLINE_VISIBILITY
auto data(const _Cont& __c)
_NOEXCEPT_(noexcept(__c.data()))
-> decltype (__c.data())
{ return __c.data(); }
template <class _Tp, size_t _Sz>
_LIBCPP_INLINE_VISIBILITY
constexpr _Tp* data(_Tp (&__array)[_Sz]) noexcept { return __array; }
template <class _Ep>
_LIBCPP_INLINE_VISIBILITY
constexpr const _Ep* data(initializer_list<_Ep> __il) noexcept { return __il.begin(); }
#endif
_LIBCPP_END_NAMESPACE_STD
#endif // _LIBCPP_ITERATOR
| 69,610 | 1,936 | jart/cosmopolitan | false |
cosmopolitan/third_party/libcxx/regex | // -*- C++ -*-
// clang-format off
//===--------------------------- regex ------------------------------------===//
//
// 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_REGEX
#define _LIBCPP_REGEX
/*
regex synopsis
#include "third_party/libcxx/initializer_list"
namespace std
{
namespace regex_constants
{
emum syntax_option_type
{
icase = unspecified,
nosubs = unspecified,
optimize = unspecified,
collate = unspecified,
ECMAScript = unspecified,
basic = unspecified,
extended = unspecified,
awk = unspecified,
grep = unspecified,
egrep = unspecified
};
constexpr syntax_option_type operator~(syntax_option_type f);
constexpr syntax_option_type operator&(syntax_option_type lhs, syntax_option_type rhs);
constexpr syntax_option_type operator|(syntax_option_type lhs, syntax_option_type rhs);
enum match_flag_type
{
match_default = 0,
match_not_bol = unspecified,
match_not_eol = unspecified,
match_not_bow = unspecified,
match_not_eow = unspecified,
match_any = unspecified,
match_not_null = unspecified,
match_continuous = unspecified,
match_prev_avail = unspecified,
format_default = 0,
format_sed = unspecified,
format_no_copy = unspecified,
format_first_only = unspecified
};
constexpr match_flag_type operator~(match_flag_type f);
constexpr match_flag_type operator&(match_flag_type lhs, match_flag_type rhs);
constexpr match_flag_type operator|(match_flag_type lhs, match_flag_type rhs);
enum error_type
{
error_collate = unspecified,
error_ctype = unspecified,
error_escape = unspecified,
error_backref = unspecified,
error_brack = unspecified,
error_paren = unspecified,
error_brace = unspecified,
error_badbrace = unspecified,
error_range = unspecified,
error_space = unspecified,
error_badrepeat = unspecified,
error_complexity = unspecified,
error_stack = unspecified
};
} // regex_constants
class regex_error
: public runtime_error
{
public:
explicit regex_error(regex_constants::error_type ecode);
regex_constants::error_type code() const;
};
template <class charT>
struct regex_traits
{
public:
typedef charT char_type;
typedef basic_string<char_type> string_type;
typedef locale locale_type;
typedef /bitmask_type/ char_class_type;
regex_traits();
static size_t length(const char_type* p);
charT translate(charT c) const;
charT translate_nocase(charT c) const;
template <class ForwardIterator>
string_type
transform(ForwardIterator first, ForwardIterator last) const;
template <class ForwardIterator>
string_type
transform_primary( ForwardIterator first, ForwardIterator last) const;
template <class ForwardIterator>
string_type
lookup_collatename(ForwardIterator first, ForwardIterator last) const;
template <class ForwardIterator>
char_class_type
lookup_classname(ForwardIterator first, ForwardIterator last,
bool icase = false) const;
bool isctype(charT c, char_class_type f) const;
int value(charT ch, int radix) const;
locale_type imbue(locale_type l);
locale_type getloc()const;
};
template <class charT, class traits = regex_traits<charT>>
class basic_regex
{
public:
// types:
typedef charT value_type;
typedef traits traits_type;
typedef typename traits::string_type string_type;
typedef regex_constants::syntax_option_type flag_type;
typedef typename traits::locale_type locale_type;
// constants:
static constexpr regex_constants::syntax_option_type icase = regex_constants::icase;
static constexpr regex_constants::syntax_option_type nosubs = regex_constants::nosubs;
static constexpr regex_constants::syntax_option_type optimize = regex_constants::optimize;
static constexpr regex_constants::syntax_option_type collate = regex_constants::collate;
static constexpr regex_constants::syntax_option_type ECMAScript = regex_constants::ECMAScript;
static constexpr regex_constants::syntax_option_type basic = regex_constants::basic;
static constexpr regex_constants::syntax_option_type extended = regex_constants::extended;
static constexpr regex_constants::syntax_option_type awk = regex_constants::awk;
static constexpr regex_constants::syntax_option_type grep = regex_constants::grep;
static constexpr regex_constants::syntax_option_type egrep = regex_constants::egrep;
// construct/copy/destroy:
basic_regex();
explicit basic_regex(const charT* p, flag_type f = regex_constants::ECMAScript);
basic_regex(const charT* p, size_t len, flag_type f = regex_constants::ECMAScript);
basic_regex(const basic_regex&);
basic_regex(basic_regex&&) noexcept;
template <class ST, class SA>
explicit basic_regex(const basic_string<charT, ST, SA>& p,
flag_type f = regex_constants::ECMAScript);
template <class ForwardIterator>
basic_regex(ForwardIterator first, ForwardIterator last,
flag_type f = regex_constants::ECMAScript);
basic_regex(initializer_list<charT>, flag_type = regex_constants::ECMAScript);
~basic_regex();
basic_regex& operator=(const basic_regex&);
basic_regex& operator=(basic_regex&&) noexcept;
basic_regex& operator=(const charT* ptr);
basic_regex& operator=(initializer_list<charT> il);
template <class ST, class SA>
basic_regex& operator=(const basic_string<charT, ST, SA>& p);
// assign:
basic_regex& assign(const basic_regex& that);
basic_regex& assign(basic_regex&& that) noexcept;
basic_regex& assign(const charT* ptr, flag_type f = regex_constants::ECMAScript);
basic_regex& assign(const charT* p, size_t len, flag_type f = regex_constants::ECMAScript);
template <class string_traits, class A>
basic_regex& assign(const basic_string<charT, string_traits, A>& s,
flag_type f = regex_constants::ECMAScript);
template <class InputIterator>
basic_regex& assign(InputIterator first, InputIterator last,
flag_type f = regex_constants::ECMAScript);
basic_regex& assign(initializer_list<charT>, flag_type f = regex_constants::ECMAScript);
// const operations:
unsigned mark_count() const;
flag_type flags() const;
// locale:
locale_type imbue(locale_type loc);
locale_type getloc() const;
// swap:
void swap(basic_regex&);
};
template<class ForwardIterator>
basic_regex(ForwardIterator, ForwardIterator,
regex_constants::syntax_option_type = regex_constants::ECMAScript)
-> basic_regex<typename iterator_traits<ForwardIterator>::value_type>; // C++17
typedef basic_regex<char> regex;
typedef basic_regex<wchar_t> wregex;
template <class charT, class traits>
void swap(basic_regex<charT, traits>& e1, basic_regex<charT, traits>& e2);
template <class BidirectionalIterator>
class sub_match
: public pair<BidirectionalIterator, BidirectionalIterator>
{
public:
typedef typename iterator_traits<BidirectionalIterator>::value_type value_type;
typedef typename iterator_traits<BidirectionalIterator>::difference_type difference_type;
typedef BidirectionalIterator iterator;
typedef basic_string<value_type> string_type;
bool matched;
constexpr sub_match();
difference_type length() const;
operator string_type() const;
string_type str() const;
int compare(const sub_match& s) const;
int compare(const string_type& s) const;
int compare(const value_type* s) const;
};
typedef sub_match<const char*> csub_match;
typedef sub_match<const wchar_t*> wcsub_match;
typedef sub_match<string::const_iterator> ssub_match;
typedef sub_match<wstring::const_iterator> wssub_match;
template <class BiIter>
bool
operator==(const sub_match<BiIter>& lhs, const sub_match<BiIter>& rhs);
template <class BiIter>
bool
operator!=(const sub_match<BiIter>& lhs, const sub_match<BiIter>& rhs);
template <class BiIter>
bool
operator<(const sub_match<BiIter>& lhs, const sub_match<BiIter>& rhs);
template <class BiIter>
bool
operator<=(const sub_match<BiIter>& lhs, const sub_match<BiIter>& rhs);
template <class BiIter>
bool
operator>=(const sub_match<BiIter>& lhs, const sub_match<BiIter>& rhs);
template <class BiIter>
bool
operator>(const sub_match<BiIter>& lhs, const sub_match<BiIter>& rhs);
template <class BiIter, class ST, class SA>
bool
operator==(const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& lhs,
const sub_match<BiIter>& rhs);
template <class BiIter, class ST, class SA>
bool
operator!=(const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& lhs,
const sub_match<BiIter>& rhs);
template <class BiIter, class ST, class SA>
bool
operator<(const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& lhs,
const sub_match<BiIter>& rhs);
template <class BiIter, class ST, class SA>
bool
operator>(const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& lhs,
const sub_match<BiIter>& rhs);
template <class BiIter, class ST, class SA>
bool operator>=(const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& lhs,
const sub_match<BiIter>& rhs);
template <class BiIter, class ST, class SA>
bool
operator<=(const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& lhs,
const sub_match<BiIter>& rhs);
template <class BiIter, class ST, class SA>
bool
operator==(const sub_match<BiIter>& lhs,
const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& rhs);
template <class BiIter, class ST, class SA>
bool
operator!=(const sub_match<BiIter>& lhs,
const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& rhs);
template <class BiIter, class ST, class SA>
bool
operator<(const sub_match<BiIter>& lhs,
const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& rhs);
template <class BiIter, class ST, class SA>
bool operator>(const sub_match<BiIter>& lhs,
const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& rhs);
template <class BiIter, class ST, class SA>
bool
operator>=(const sub_match<BiIter>& lhs,
const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& rhs);
template <class BiIter, class ST, class SA>
bool
operator<=(const sub_match<BiIter>& lhs,
const basic_string<typename iterator_traits<BiIter>::value_type, ST, SA>& rhs);
template <class BiIter>
bool
operator==(typename iterator_traits<BiIter>::value_type const* lhs,
const sub_match<BiIter>& rhs);
template <class BiIter>
bool
operator!=(typename iterator_traits<BiIter>::value_type const* lhs,
const sub_match<BiIter>& rhs);
template <class BiIter>
bool
operator<(typename iterator_traits<BiIter>::value_type const* lhs,
const sub_match<BiIter>& rhs);
template <class BiIter>
bool
operator>(typename iterator_traits<BiIter>::value_type const* lhs,
const sub_match<BiIter>& rhs);
template <class BiIter>
bool
operator>=(typename iterator_traits<BiIter>::value_type const* lhs,
const sub_match<BiIter>& rhs);
template <class BiIter>
bool
operator<=(typename iterator_traits<BiIter>::value_type const* lhs,
const sub_match<BiIter>& rhs);
template <class BiIter>
bool
operator==(const sub_match<BiIter>& lhs,
typename iterator_traits<BiIter>::value_type const* rhs);
template <class BiIter>
bool
operator!=(const sub_match<BiIter>& lhs,
typename iterator_traits<BiIter>::value_type const* rhs);
template <class BiIter>
bool
operator<(const sub_match<BiIter>& lhs,
typename iterator_traits<BiIter>::value_type const* rhs);
template <class BiIter>
bool
operator>(const sub_match<BiIter>& lhs,
typename iterator_traits<BiIter>::value_type const* rhs);
template <class BiIter>
bool
operator>=(const sub_match<BiIter>& lhs,
typename iterator_traits<BiIter>::value_type const* rhs);
template <class BiIter>
bool
operator<=(const sub_match<BiIter>& lhs,
typename iterator_traits<BiIter>::value_type const* rhs);
template <class BiIter>
bool
operator==(typename iterator_traits<BiIter>::value_type const& lhs,
const sub_match<BiIter>& rhs);
template <class BiIter>
bool
operator!=(typename iterator_traits<BiIter>::value_type const& lhs,
const sub_match<BiIter>& rhs);
template <class BiIter>
bool
operator<(typename iterator_traits<BiIter>::value_type const& lhs,
const sub_match<BiIter>& rhs);
template <class BiIter>
bool
operator>(typename iterator_traits<BiIter>::value_type const& lhs,
const sub_match<BiIter>& rhs);
template <class BiIter>
bool
operator>=(typename iterator_traits<BiIter>::value_type const& lhs,
const sub_match<BiIter>& rhs);
template <class BiIter>
bool
operator<=(typename iterator_traits<BiIter>::value_type const& lhs,
const sub_match<BiIter>& rhs);
template <class BiIter>
bool
operator==(const sub_match<BiIter>& lhs,
typename iterator_traits<BiIter>::value_type const& rhs);
template <class BiIter>
bool
operator!=(const sub_match<BiIter>& lhs,
typename iterator_traits<BiIter>::value_type const& rhs);
template <class BiIter>
bool
operator<(const sub_match<BiIter>& lhs,
typename iterator_traits<BiIter>::value_type const& rhs);
template <class BiIter>
bool
operator>(const sub_match<BiIter>& lhs,
typename iterator_traits<BiIter>::value_type const& rhs);
template <class BiIter>
bool
operator>=(const sub_match<BiIter>& lhs,
typename iterator_traits<BiIter>::value_type const& rhs);
template <class BiIter>
bool
operator<=(const sub_match<BiIter>& lhs,
typename iterator_traits<BiIter>::value_type const& rhs);
template <class charT, class ST, class BiIter>
basic_ostream<charT, ST>&
operator<<(basic_ostream<charT, ST>& os, const sub_match<BiIter>& m);
template <class BidirectionalIterator,
class Allocator = allocator<sub_match<BidirectionalIterator>>>
class match_results
{
public:
typedef sub_match<BidirectionalIterator> value_type;
typedef const value_type& const_reference;
typedef value_type& reference;
typedef /implementation-defined/ const_iterator;
typedef const_iterator iterator;
typedef typename iterator_traits<BidirectionalIterator>::difference_type difference_type;
typedef typename allocator_traits<Allocator>::size_type size_type;
typedef Allocator allocator_type;
typedef typename iterator_traits<BidirectionalIterator>::value_type char_type;
typedef basic_string<char_type> string_type;
// construct/copy/destroy:
explicit match_results(const Allocator& a = Allocator());
match_results(const match_results& m);
match_results(match_results&& m) noexcept;
match_results& operator=(const match_results& m);
match_results& operator=(match_results&& m);
~match_results();
bool ready() const;
// size:
size_type size() const;
size_type max_size() const;
bool empty() const;
// element access:
difference_type length(size_type sub = 0) const;
difference_type position(size_type sub = 0) const;
string_type str(size_type sub = 0) const;
const_reference operator[](size_type n) const;
const_reference prefix() const;
const_reference suffix() const;
const_iterator begin() const;
const_iterator end() const;
const_iterator cbegin() const;
const_iterator cend() const;
// format:
template <class OutputIter>
OutputIter
format(OutputIter out, const char_type* fmt_first,
const char_type* fmt_last,
regex_constants::match_flag_type flags = regex_constants::format_default) const;
template <class OutputIter, class ST, class SA>
OutputIter
format(OutputIter out, const basic_string<char_type, ST, SA>& fmt,
regex_constants::match_flag_type flags = regex_constants::format_default) const;
template <class ST, class SA>
basic_string<char_type, ST, SA>
format(const basic_string<char_type, ST, SA>& fmt,
regex_constants::match_flag_type flags = regex_constants::format_default) const;
string_type
format(const char_type* fmt,
regex_constants::match_flag_type flags = regex_constants::format_default) const;
// allocator:
allocator_type get_allocator() const;
// swap:
void swap(match_results& that);
};
typedef match_results<const char*> cmatch;
typedef match_results<const wchar_t*> wcmatch;
typedef match_results<string::const_iterator> smatch;
typedef match_results<wstring::const_iterator> wsmatch;
template <class BidirectionalIterator, class Allocator>
bool
operator==(const match_results<BidirectionalIterator, Allocator>& m1,
const match_results<BidirectionalIterator, Allocator>& m2);
template <class BidirectionalIterator, class Allocator>
bool
operator!=(const match_results<BidirectionalIterator, Allocator>& m1,
const match_results<BidirectionalIterator, Allocator>& m2);
template <class BidirectionalIterator, class Allocator>
void
swap(match_results<BidirectionalIterator, Allocator>& m1,
match_results<BidirectionalIterator, Allocator>& m2);
template <class BidirectionalIterator, class Allocator, class charT, class traits>
bool
regex_match(BidirectionalIterator first, BidirectionalIterator last,
match_results<BidirectionalIterator, Allocator>& m,
const basic_regex<charT, traits>& e,
regex_constants::match_flag_type flags = regex_constants::match_default);
template <class BidirectionalIterator, class charT, class traits>
bool
regex_match(BidirectionalIterator first, BidirectionalIterator last,
const basic_regex<charT, traits>& e,
regex_constants::match_flag_type flags = regex_constants::match_default);
template <class charT, class Allocator, class traits>
bool
regex_match(const charT* str, match_results<const charT*, Allocator>& m,
const basic_regex<charT, traits>& e,
regex_constants::match_flag_type flags = regex_constants::match_default);
template <class ST, class SA, class Allocator, class charT, class traits>
bool
regex_match(const basic_string<charT, ST, SA>& s,
match_results<typename basic_string<charT, ST, SA>::const_iterator, Allocator>& m,
const basic_regex<charT, traits>& e,
regex_constants::match_flag_type flags = regex_constants::match_default);
template <class ST, class SA, class Allocator, class charT, class traits>
bool
regex_match(const basic_string<charT, ST, SA>&& s,
match_results<typename basic_string<charT, ST, SA>::const_iterator, Allocator>& m,
const basic_regex<charT, traits>& e,
regex_constants::match_flag_type flags = regex_constants::match_default) = delete; // C++14
template <class charT, class traits>
bool
regex_match(const charT* str, const basic_regex<charT, traits>& e,
regex_constants::match_flag_type flags = regex_constants::match_default);
template <class ST, class SA, class charT, class traits>
bool
regex_match(const basic_string<charT, ST, SA>& s,
const basic_regex<charT, traits>& e,
regex_constants::match_flag_type flags = regex_constants::match_default);
template <class BidirectionalIterator, class Allocator, class charT, class traits>
bool
regex_search(BidirectionalIterator first, BidirectionalIterator last,
match_results<BidirectionalIterator, Allocator>& m,
const basic_regex<charT, traits>& e,
regex_constants::match_flag_type flags = regex_constants::match_default);
template <class BidirectionalIterator, class charT, class traits>
bool
regex_search(BidirectionalIterator first, BidirectionalIterator last,
const basic_regex<charT, traits>& e,
regex_constants::match_flag_type flags = regex_constants::match_default);
template <class charT, class Allocator, class traits>
bool
regex_search(const charT* str, match_results<const charT*, Allocator>& m,
const basic_regex<charT, traits>& e,
regex_constants::match_flag_type flags = regex_constants::match_default);
template <class charT, class traits>
bool
regex_search(const charT* str, const basic_regex<charT, traits>& e,
regex_constants::match_flag_type flags = regex_constants::match_default);
template <class ST, class SA, class charT, class traits>
bool
regex_search(const basic_string<charT, ST, SA>& s,
const basic_regex<charT, traits>& e,
regex_constants::match_flag_type flags = regex_constants::match_default);
template <class ST, class SA, class Allocator, class charT, class traits>
bool
regex_search(const basic_string<charT, ST, SA>& s,
match_results<typename basic_string<charT, ST, SA>::const_iterator, Allocator>& m,
const basic_regex<charT, traits>& e,
regex_constants::match_flag_type flags = regex_constants::match_default);
template <class ST, class SA, class Allocator, class charT, class traits>
bool
regex_search(const basic_string<charT, ST, SA>&& s,
match_results<typename basic_string<charT, ST, SA>::const_iterator, Allocator>& m,
const basic_regex<charT, traits>& e,
regex_constants::match_flag_type flags = regex_constants::match_default) = delete; // C++14
template <class OutputIterator, class BidirectionalIterator,
class traits, class charT, class ST, class SA>
OutputIterator
regex_replace(OutputIterator out,
BidirectionalIterator first, BidirectionalIterator last,
const basic_regex<charT, traits>& e,
const basic_string<charT, ST, SA>& fmt,
regex_constants::match_flag_type flags = regex_constants::match_default);
template <class OutputIterator, class BidirectionalIterator,
class traits, class charT>
OutputIterator
regex_replace(OutputIterator out,
BidirectionalIterator first, BidirectionalIterator last,
const basic_regex<charT, traits>& e, const charT* fmt,
regex_constants::match_flag_type flags = regex_constants::match_default);
template <class traits, class charT, class ST, class SA, class FST, class FSA>>
basic_string<charT, ST, SA>
regex_replace(const basic_string<charT, ST, SA>& s,
const basic_regex<charT, traits>& e,
const basic_string<charT, FST, FSA>& fmt,
regex_constants::match_flag_type flags = regex_constants::match_default);
template <class traits, class charT, class ST, class SA>
basic_string<charT, ST, SA>
regex_replace(const basic_string<charT, ST, SA>& s,
const basic_regex<charT, traits>& e, const charT* fmt,
regex_constants::match_flag_type flags = regex_constants::match_default);
template <class traits, class charT, class ST, class SA>
basic_string<charT>
regex_replace(const charT* s,
const basic_regex<charT, traits>& e,
const basic_string<charT, ST, SA>& fmt,
regex_constants::match_flag_type flags = regex_constants::match_default);
template <class traits, class charT>
basic_string<charT>
regex_replace(const charT* s,
const basic_regex<charT, traits>& e,
const charT* fmt,
regex_constants::match_flag_type flags = regex_constants::match_default);
template <class BidirectionalIterator,
class charT = typename iterator_traits< BidirectionalIterator>::value_type,
class traits = regex_traits<charT>>
class regex_iterator
{
public:
typedef basic_regex<charT, traits> regex_type;
typedef match_results<BidirectionalIterator> value_type;
typedef ptrdiff_t difference_type;
typedef const value_type* pointer;
typedef const value_type& reference;
typedef forward_iterator_tag iterator_category;
regex_iterator();
regex_iterator(BidirectionalIterator a, BidirectionalIterator b,
const regex_type& re,
regex_constants::match_flag_type m = regex_constants::match_default);
regex_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b,
const regex_type&& __re,
regex_constants::match_flag_type __m
= regex_constants::match_default) = delete; // C++14
regex_iterator(const regex_iterator&);
regex_iterator& operator=(const regex_iterator&);
bool operator==(const regex_iterator&) const;
bool operator!=(const regex_iterator&) const;
const value_type& operator*() const;
const value_type* operator->() const;
regex_iterator& operator++();
regex_iterator operator++(int);
};
typedef regex_iterator<const char*> cregex_iterator;
typedef regex_iterator<const wchar_t*> wcregex_iterator;
typedef regex_iterator<string::const_iterator> sregex_iterator;
typedef regex_iterator<wstring::const_iterator> wsregex_iterator;
template <class BidirectionalIterator,
class charT = typename iterator_traits< BidirectionalIterator>::value_type,
class traits = regex_traits<charT>>
class regex_token_iterator
{
public:
typedef basic_regex<charT, traits> regex_type;
typedef sub_match<BidirectionalIterator> value_type;
typedef ptrdiff_t difference_type;
typedef const value_type* pointer;
typedef const value_type& reference;
typedef forward_iterator_tag iterator_category;
regex_token_iterator();
regex_token_iterator(BidirectionalIterator a, BidirectionalIterator b,
const regex_type& re, int submatch = 0,
regex_constants::match_flag_type m = regex_constants::match_default);
regex_token_iterator(BidirectionalIterator a, BidirectionalIterator b,
const regex_type&& re, int submatch = 0,
regex_constants::match_flag_type m = regex_constants::match_default) = delete; // C++14
regex_token_iterator(BidirectionalIterator a, BidirectionalIterator b,
const regex_type& re, const vector<int>& submatches,
regex_constants::match_flag_type m = regex_constants::match_default);
regex_token_iterator(BidirectionalIterator a, BidirectionalIterator b,
const regex_type&& re, const vector<int>& submatches,
regex_constants::match_flag_type m = regex_constants::match_default) = delete; // C++14
regex_token_iterator(BidirectionalIterator a, BidirectionalIterator b,
const regex_type& re, initializer_list<int> submatches,
regex_constants::match_flag_type m = regex_constants::match_default);
regex_token_iterator(BidirectionalIterator a, BidirectionalIterator b,
const regex_type&& re, initializer_list<int> submatches,
regex_constants::match_flag_type m = regex_constants::match_default) = delete; // C++14
template <size_t N>
regex_token_iterator(BidirectionalIterator a, BidirectionalIterator b,
const regex_type& re, const int (&submatches)[N],
regex_constants::match_flag_type m = regex_constants::match_default);
template <size_t N>
regex_token_iterator(BidirectionalIterator a, BidirectionalIterator b,
const regex_type& re, const int (&submatches)[N],
regex_constants::match_flag_type m = regex_constants::match_default) = delete // C++14;
regex_token_iterator(const regex_token_iterator&);
regex_token_iterator& operator=(const regex_token_iterator&);
bool operator==(const regex_token_iterator&) const;
bool operator!=(const regex_token_iterator&) const;
const value_type& operator*() const;
const value_type* operator->() const;
regex_token_iterator& operator++();
regex_token_iterator operator++(int);
};
typedef regex_token_iterator<const char*> cregex_token_iterator;
typedef regex_token_iterator<const wchar_t*> wcregex_token_iterator;
typedef regex_token_iterator<string::const_iterator> sregex_token_iterator;
typedef regex_token_iterator<wstring::const_iterator> wsregex_token_iterator;
} // std
*/
#include "third_party/libcxx/__config"
#include "third_party/libcxx/stdexcept"
#include "third_party/libcxx/__locale"
#include "third_party/libcxx/initializer_list"
#include "third_party/libcxx/utility"
#include "third_party/libcxx/iterator"
#include "third_party/libcxx/string"
#include "third_party/libcxx/memory"
#include "third_party/libcxx/vector"
#include "third_party/libcxx/deque"
#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"
#define _LIBCPP_REGEX_COMPLEXITY_FACTOR 4096
_LIBCPP_BEGIN_NAMESPACE_STD
namespace regex_constants
{
// syntax_option_type
enum syntax_option_type
{
icase = 1 << 0,
nosubs = 1 << 1,
optimize = 1 << 2,
collate = 1 << 3,
#ifdef _LIBCPP_ABI_REGEX_CONSTANTS_NONZERO
ECMAScript = 1 << 9,
#else
ECMAScript = 0,
#endif
basic = 1 << 4,
extended = 1 << 5,
awk = 1 << 6,
grep = 1 << 7,
egrep = 1 << 8
};
inline _LIBCPP_CONSTEXPR
syntax_option_type __get_grammar(syntax_option_type __g)
{
#ifdef _LIBCPP_ABI_REGEX_CONSTANTS_NONZERO
return static_cast<syntax_option_type>(__g & 0x3F0);
#else
return static_cast<syntax_option_type>(__g & 0x1F0);
#endif
}
inline _LIBCPP_INLINE_VISIBILITY
_LIBCPP_CONSTEXPR
syntax_option_type
operator~(syntax_option_type __x)
{
return syntax_option_type(~int(__x) & 0x1FF);
}
inline _LIBCPP_INLINE_VISIBILITY
_LIBCPP_CONSTEXPR
syntax_option_type
operator&(syntax_option_type __x, syntax_option_type __y)
{
return syntax_option_type(int(__x) & int(__y));
}
inline _LIBCPP_INLINE_VISIBILITY
_LIBCPP_CONSTEXPR
syntax_option_type
operator|(syntax_option_type __x, syntax_option_type __y)
{
return syntax_option_type(int(__x) | int(__y));
}
inline _LIBCPP_INLINE_VISIBILITY
_LIBCPP_CONSTEXPR
syntax_option_type
operator^(syntax_option_type __x, syntax_option_type __y)
{
return syntax_option_type(int(__x) ^ int(__y));
}
inline _LIBCPP_INLINE_VISIBILITY
syntax_option_type&
operator&=(syntax_option_type& __x, syntax_option_type __y)
{
__x = __x & __y;
return __x;
}
inline _LIBCPP_INLINE_VISIBILITY
syntax_option_type&
operator|=(syntax_option_type& __x, syntax_option_type __y)
{
__x = __x | __y;
return __x;
}
inline _LIBCPP_INLINE_VISIBILITY
syntax_option_type&
operator^=(syntax_option_type& __x, syntax_option_type __y)
{
__x = __x ^ __y;
return __x;
}
// match_flag_type
enum match_flag_type
{
match_default = 0,
match_not_bol = 1 << 0,
match_not_eol = 1 << 1,
match_not_bow = 1 << 2,
match_not_eow = 1 << 3,
match_any = 1 << 4,
match_not_null = 1 << 5,
match_continuous = 1 << 6,
match_prev_avail = 1 << 7,
format_default = 0,
format_sed = 1 << 8,
format_no_copy = 1 << 9,
format_first_only = 1 << 10,
__no_update_pos = 1 << 11,
__full_match = 1 << 12
};
inline _LIBCPP_INLINE_VISIBILITY
_LIBCPP_CONSTEXPR
match_flag_type
operator~(match_flag_type __x)
{
return match_flag_type(~int(__x) & 0x0FFF);
}
inline _LIBCPP_INLINE_VISIBILITY
_LIBCPP_CONSTEXPR
match_flag_type
operator&(match_flag_type __x, match_flag_type __y)
{
return match_flag_type(int(__x) & int(__y));
}
inline _LIBCPP_INLINE_VISIBILITY
_LIBCPP_CONSTEXPR
match_flag_type
operator|(match_flag_type __x, match_flag_type __y)
{
return match_flag_type(int(__x) | int(__y));
}
inline _LIBCPP_INLINE_VISIBILITY
_LIBCPP_CONSTEXPR
match_flag_type
operator^(match_flag_type __x, match_flag_type __y)
{
return match_flag_type(int(__x) ^ int(__y));
}
inline _LIBCPP_INLINE_VISIBILITY
match_flag_type&
operator&=(match_flag_type& __x, match_flag_type __y)
{
__x = __x & __y;
return __x;
}
inline _LIBCPP_INLINE_VISIBILITY
match_flag_type&
operator|=(match_flag_type& __x, match_flag_type __y)
{
__x = __x | __y;
return __x;
}
inline _LIBCPP_INLINE_VISIBILITY
match_flag_type&
operator^=(match_flag_type& __x, match_flag_type __y)
{
__x = __x ^ __y;
return __x;
}
enum error_type
{
error_collate = 1,
error_ctype,
error_escape,
error_backref,
error_brack,
error_paren,
error_brace,
error_badbrace,
error_range,
error_space,
error_badrepeat,
error_complexity,
error_stack,
__re_err_grammar,
__re_err_empty,
__re_err_unknown
};
} // regex_constants
class _LIBCPP_EXCEPTION_ABI regex_error
: public runtime_error
{
regex_constants::error_type __code_;
public:
explicit regex_error(regex_constants::error_type __ecode);
virtual ~regex_error() throw();
_LIBCPP_INLINE_VISIBILITY
regex_constants::error_type code() const {return __code_;}
};
template <regex_constants::error_type _Ev>
_LIBCPP_NORETURN inline _LIBCPP_INLINE_VISIBILITY
void __throw_regex_error()
{
#ifndef _LIBCPP_NO_EXCEPTIONS
throw regex_error(_Ev);
#else
_VSTD::abort();
#endif
}
template <class _CharT>
struct _LIBCPP_TEMPLATE_VIS regex_traits
{
public:
typedef _CharT char_type;
typedef basic_string<char_type> string_type;
typedef locale locale_type;
typedef ctype_base::mask char_class_type;
static const char_class_type __regex_word = ctype_base::__regex_word;
private:
locale __loc_;
const ctype<char_type>* __ct_;
const collate<char_type>* __col_;
public:
regex_traits();
_LIBCPP_INLINE_VISIBILITY
static size_t length(const char_type* __p)
{return char_traits<char_type>::length(__p);}
_LIBCPP_INLINE_VISIBILITY
char_type translate(char_type __c) const {return __c;}
char_type translate_nocase(char_type __c) const;
template <class _ForwardIterator>
string_type
transform(_ForwardIterator __f, _ForwardIterator __l) const;
template <class _ForwardIterator>
_LIBCPP_INLINE_VISIBILITY
string_type
transform_primary( _ForwardIterator __f, _ForwardIterator __l) const
{return __transform_primary(__f, __l, char_type());}
template <class _ForwardIterator>
_LIBCPP_INLINE_VISIBILITY
string_type
lookup_collatename(_ForwardIterator __f, _ForwardIterator __l) const
{return __lookup_collatename(__f, __l, char_type());}
template <class _ForwardIterator>
_LIBCPP_INLINE_VISIBILITY
char_class_type
lookup_classname(_ForwardIterator __f, _ForwardIterator __l,
bool __icase = false) const
{return __lookup_classname(__f, __l, __icase, char_type());}
bool isctype(char_type __c, char_class_type __m) const;
_LIBCPP_INLINE_VISIBILITY
int value(char_type __ch, int __radix) const
{return __regex_traits_value(__ch, __radix);}
locale_type imbue(locale_type __l);
_LIBCPP_INLINE_VISIBILITY
locale_type getloc()const {return __loc_;}
private:
void __init();
template <class _ForwardIterator>
string_type
__transform_primary(_ForwardIterator __f, _ForwardIterator __l, char) const;
template <class _ForwardIterator>
string_type
__transform_primary(_ForwardIterator __f, _ForwardIterator __l, wchar_t) const;
template <class _ForwardIterator>
string_type
__lookup_collatename(_ForwardIterator __f, _ForwardIterator __l, char) const;
template <class _ForwardIterator>
string_type
__lookup_collatename(_ForwardIterator __f, _ForwardIterator __l, wchar_t) const;
template <class _ForwardIterator>
char_class_type
__lookup_classname(_ForwardIterator __f, _ForwardIterator __l,
bool __icase, char) const;
template <class _ForwardIterator>
char_class_type
__lookup_classname(_ForwardIterator __f, _ForwardIterator __l,
bool __icase, wchar_t) const;
static int __regex_traits_value(unsigned char __ch, int __radix);
_LIBCPP_INLINE_VISIBILITY
int __regex_traits_value(char __ch, int __radix) const
{return __regex_traits_value(static_cast<unsigned char>(__ch), __radix);}
_LIBCPP_INLINE_VISIBILITY
int __regex_traits_value(wchar_t __ch, int __radix) const;
};
template <class _CharT>
const typename regex_traits<_CharT>::char_class_type
regex_traits<_CharT>::__regex_word;
template <class _CharT>
regex_traits<_CharT>::regex_traits()
{
__init();
}
template <class _CharT>
typename regex_traits<_CharT>::char_type
regex_traits<_CharT>::translate_nocase(char_type __c) const
{
return __ct_->tolower(__c);
}
template <class _CharT>
template <class _ForwardIterator>
typename regex_traits<_CharT>::string_type
regex_traits<_CharT>::transform(_ForwardIterator __f, _ForwardIterator __l) const
{
string_type __s(__f, __l);
return __col_->transform(__s.data(), __s.data() + __s.size());
}
template <class _CharT>
void
regex_traits<_CharT>::__init()
{
__ct_ = &use_facet<ctype<char_type> >(__loc_);
__col_ = &use_facet<collate<char_type> >(__loc_);
}
template <class _CharT>
typename regex_traits<_CharT>::locale_type
regex_traits<_CharT>::imbue(locale_type __l)
{
locale __r = __loc_;
__loc_ = __l;
__init();
return __r;
}
// transform_primary is very FreeBSD-specific
template <class _CharT>
template <class _ForwardIterator>
typename regex_traits<_CharT>::string_type
regex_traits<_CharT>::__transform_primary(_ForwardIterator __f,
_ForwardIterator __l, char) const
{
const string_type __s(__f, __l);
string_type __d = __col_->transform(__s.data(), __s.data() + __s.size());
switch (__d.size())
{
case 1:
break;
case 12:
__d[11] = __d[3];
break;
default:
__d.clear();
break;
}
return __d;
}
template <class _CharT>
template <class _ForwardIterator>
typename regex_traits<_CharT>::string_type
regex_traits<_CharT>::__transform_primary(_ForwardIterator __f,
_ForwardIterator __l, wchar_t) const
{
const string_type __s(__f, __l);
string_type __d = __col_->transform(__s.data(), __s.data() + __s.size());
switch (__d.size())
{
case 1:
break;
case 3:
__d[2] = __d[0];
break;
default:
__d.clear();
break;
}
return __d;
}
// lookup_collatename is very FreeBSD-specific
_LIBCPP_FUNC_VIS string __get_collation_name(const char* __s);
template <class _CharT>
template <class _ForwardIterator>
typename regex_traits<_CharT>::string_type
regex_traits<_CharT>::__lookup_collatename(_ForwardIterator __f,
_ForwardIterator __l, char) const
{
string_type __s(__f, __l);
string_type __r;
if (!__s.empty())
{
__r = __get_collation_name(__s.c_str());
if (__r.empty() && __s.size() <= 2)
{
__r = __col_->transform(__s.data(), __s.data() + __s.size());
if (__r.size() == 1 || __r.size() == 12)
__r = __s;
else
__r.clear();
}
}
return __r;
}
template <class _CharT>
template <class _ForwardIterator>
typename regex_traits<_CharT>::string_type
regex_traits<_CharT>::__lookup_collatename(_ForwardIterator __f,
_ForwardIterator __l, wchar_t) const
{
string_type __s(__f, __l);
string __n;
__n.reserve(__s.size());
for (typename string_type::const_iterator __i = __s.begin(), __e = __s.end();
__i != __e; ++__i)
{
if (static_cast<unsigned>(*__i) >= 127)
return string_type();
__n.push_back(char(*__i));
}
string_type __r;
if (!__s.empty())
{
__n = __get_collation_name(__n.c_str());
if (!__n.empty())
__r.assign(__n.begin(), __n.end());
else if (__s.size() <= 2)
{
__r = __col_->transform(__s.data(), __s.data() + __s.size());
if (__r.size() == 1 || __r.size() == 3)
__r = __s;
else
__r.clear();
}
}
return __r;
}
// lookup_classname
regex_traits<char>::char_class_type _LIBCPP_FUNC_VIS
__get_classname(const char* __s, bool __icase);
template <class _CharT>
template <class _ForwardIterator>
typename regex_traits<_CharT>::char_class_type
regex_traits<_CharT>::__lookup_classname(_ForwardIterator __f,
_ForwardIterator __l,
bool __icase, char) const
{
string_type __s(__f, __l);
__ct_->tolower(&__s[0], &__s[0] + __s.size());
return __get_classname(__s.c_str(), __icase);
}
template <class _CharT>
template <class _ForwardIterator>
typename regex_traits<_CharT>::char_class_type
regex_traits<_CharT>::__lookup_classname(_ForwardIterator __f,
_ForwardIterator __l,
bool __icase, wchar_t) const
{
string_type __s(__f, __l);
__ct_->tolower(&__s[0], &__s[0] + __s.size());
string __n;
__n.reserve(__s.size());
for (typename string_type::const_iterator __i = __s.begin(), __e = __s.end();
__i != __e; ++__i)
{
if (static_cast<unsigned>(*__i) >= 127)
return char_class_type();
__n.push_back(char(*__i));
}
return __get_classname(__n.c_str(), __icase);
}
template <class _CharT>
bool
regex_traits<_CharT>::isctype(char_type __c, char_class_type __m) const
{
if (__ct_->is(__m, __c))
return true;
return (__c == '_' && (__m & __regex_word));
}
template <class _CharT>
int
regex_traits<_CharT>::__regex_traits_value(unsigned char __ch, int __radix)
{
if ((__ch & 0xF8u) == 0x30) // '0' <= __ch && __ch <= '7'
return __ch - '0';
if (__radix != 8)
{
if ((__ch & 0xFEu) == 0x38) // '8' <= __ch && __ch <= '9'
return __ch - '0';
if (__radix == 16)
{
__ch |= 0x20; // tolower
if ('a' <= __ch && __ch <= 'f')
return __ch - ('a' - 10);
}
}
return -1;
}
template <class _CharT>
inline
int
regex_traits<_CharT>::__regex_traits_value(wchar_t __ch, int __radix) const
{
return __regex_traits_value(static_cast<unsigned char>(__ct_->narrow(__ch, char_type())), __radix);
}
template <class _CharT> class __node;
template <class _BidirectionalIterator> class _LIBCPP_TEMPLATE_VIS sub_match;
template <class _BidirectionalIterator,
class _Allocator = allocator<sub_match<_BidirectionalIterator> > >
class _LIBCPP_TEMPLATE_VIS match_results;
template <class _CharT>
struct __state
{
enum
{
__end_state = -1000,
__consume_input, // -999
__begin_marked_expr, // -998
__end_marked_expr, // -997
__pop_state, // -996
__accept_and_consume, // -995
__accept_but_not_consume, // -994
__reject, // -993
__split,
__repeat
};
int __do_;
const _CharT* __first_;
const _CharT* __current_;
const _CharT* __last_;
vector<sub_match<const _CharT*> > __sub_matches_;
vector<pair<size_t, const _CharT*> > __loop_data_;
const __node<_CharT>* __node_;
regex_constants::match_flag_type __flags_;
bool __at_first_;
_LIBCPP_INLINE_VISIBILITY
__state()
: __do_(0), __first_(nullptr), __current_(nullptr), __last_(nullptr),
__node_(nullptr), __flags_() {}
};
// __node
template <class _CharT>
class __node
{
__node(const __node&);
__node& operator=(const __node&);
public:
typedef _VSTD::__state<_CharT> __state;
_LIBCPP_INLINE_VISIBILITY
__node() {}
_LIBCPP_INLINE_VISIBILITY
virtual ~__node() {}
_LIBCPP_INLINE_VISIBILITY
virtual void __exec(__state&) const {}
_LIBCPP_INLINE_VISIBILITY
virtual void __exec_split(bool, __state&) const {}
};
// __end_state
template <class _CharT>
class __end_state
: public __node<_CharT>
{
public:
typedef _VSTD::__state<_CharT> __state;
_LIBCPP_INLINE_VISIBILITY
__end_state() {}
virtual void __exec(__state&) const;
};
template <class _CharT>
void
__end_state<_CharT>::__exec(__state& __s) const
{
__s.__do_ = __state::__end_state;
}
// __has_one_state
template <class _CharT>
class __has_one_state
: public __node<_CharT>
{
__node<_CharT>* __first_;
public:
_LIBCPP_INLINE_VISIBILITY
explicit __has_one_state(__node<_CharT>* __s)
: __first_(__s) {}
_LIBCPP_INLINE_VISIBILITY
__node<_CharT>* first() const {return __first_;}
_LIBCPP_INLINE_VISIBILITY
__node<_CharT>*& first() {return __first_;}
};
// __owns_one_state
template <class _CharT>
class __owns_one_state
: public __has_one_state<_CharT>
{
typedef __has_one_state<_CharT> base;
public:
_LIBCPP_INLINE_VISIBILITY
explicit __owns_one_state(__node<_CharT>* __s)
: base(__s) {}
virtual ~__owns_one_state();
};
template <class _CharT>
__owns_one_state<_CharT>::~__owns_one_state()
{
delete this->first();
}
// __empty_state
template <class _CharT>
class __empty_state
: public __owns_one_state<_CharT>
{
typedef __owns_one_state<_CharT> base;
public:
typedef _VSTD::__state<_CharT> __state;
_LIBCPP_INLINE_VISIBILITY
explicit __empty_state(__node<_CharT>* __s)
: base(__s) {}
virtual void __exec(__state&) const;
};
template <class _CharT>
void
__empty_state<_CharT>::__exec(__state& __s) const
{
__s.__do_ = __state::__accept_but_not_consume;
__s.__node_ = this->first();
}
// __empty_non_own_state
template <class _CharT>
class __empty_non_own_state
: public __has_one_state<_CharT>
{
typedef __has_one_state<_CharT> base;
public:
typedef _VSTD::__state<_CharT> __state;
_LIBCPP_INLINE_VISIBILITY
explicit __empty_non_own_state(__node<_CharT>* __s)
: base(__s) {}
virtual void __exec(__state&) const;
};
template <class _CharT>
void
__empty_non_own_state<_CharT>::__exec(__state& __s) const
{
__s.__do_ = __state::__accept_but_not_consume;
__s.__node_ = this->first();
}
// __repeat_one_loop
template <class _CharT>
class __repeat_one_loop
: public __has_one_state<_CharT>
{
typedef __has_one_state<_CharT> base;
public:
typedef _VSTD::__state<_CharT> __state;
_LIBCPP_INLINE_VISIBILITY
explicit __repeat_one_loop(__node<_CharT>* __s)
: base(__s) {}
virtual void __exec(__state&) const;
};
template <class _CharT>
void
__repeat_one_loop<_CharT>::__exec(__state& __s) const
{
__s.__do_ = __state::__repeat;
__s.__node_ = this->first();
}
// __owns_two_states
template <class _CharT>
class __owns_two_states
: public __owns_one_state<_CharT>
{
typedef __owns_one_state<_CharT> base;
base* __second_;
public:
_LIBCPP_INLINE_VISIBILITY
explicit __owns_two_states(__node<_CharT>* __s1, base* __s2)
: base(__s1), __second_(__s2) {}
virtual ~__owns_two_states();
_LIBCPP_INLINE_VISIBILITY
base* second() const {return __second_;}
_LIBCPP_INLINE_VISIBILITY
base*& second() {return __second_;}
};
template <class _CharT>
__owns_two_states<_CharT>::~__owns_two_states()
{
delete __second_;
}
// __loop
template <class _CharT>
class __loop
: public __owns_two_states<_CharT>
{
typedef __owns_two_states<_CharT> base;
size_t __min_;
size_t __max_;
unsigned __loop_id_;
unsigned __mexp_begin_;
unsigned __mexp_end_;
bool __greedy_;
public:
typedef _VSTD::__state<_CharT> __state;
_LIBCPP_INLINE_VISIBILITY
explicit __loop(unsigned __loop_id,
__node<_CharT>* __s1, __owns_one_state<_CharT>* __s2,
unsigned __mexp_begin, unsigned __mexp_end,
bool __greedy = true,
size_t __min = 0,
size_t __max = numeric_limits<size_t>::max())
: base(__s1, __s2), __min_(__min), __max_(__max), __loop_id_(__loop_id),
__mexp_begin_(__mexp_begin), __mexp_end_(__mexp_end),
__greedy_(__greedy) {}
virtual void __exec(__state& __s) const;
virtual void __exec_split(bool __second, __state& __s) const;
private:
_LIBCPP_INLINE_VISIBILITY
void __init_repeat(__state& __s) const
{
__s.__loop_data_[__loop_id_].second = __s.__current_;
for (size_t __i = __mexp_begin_-1; __i != __mexp_end_-1; ++__i)
{
__s.__sub_matches_[__i].first = __s.__last_;
__s.__sub_matches_[__i].second = __s.__last_;
__s.__sub_matches_[__i].matched = false;
}
}
};
template <class _CharT>
void
__loop<_CharT>::__exec(__state& __s) const
{
if (__s.__do_ == __state::__repeat)
{
bool __do_repeat = ++__s.__loop_data_[__loop_id_].first < __max_;
bool __do_alt = __s.__loop_data_[__loop_id_].first >= __min_;
if (__do_repeat && __do_alt &&
__s.__loop_data_[__loop_id_].second == __s.__current_)
__do_repeat = false;
if (__do_repeat && __do_alt)
__s.__do_ = __state::__split;
else if (__do_repeat)
{
__s.__do_ = __state::__accept_but_not_consume;
__s.__node_ = this->first();
__init_repeat(__s);
}
else
{
__s.__do_ = __state::__accept_but_not_consume;
__s.__node_ = this->second();
}
}
else
{
__s.__loop_data_[__loop_id_].first = 0;
bool __do_repeat = 0 < __max_;
bool __do_alt = 0 >= __min_;
if (__do_repeat && __do_alt)
__s.__do_ = __state::__split;
else if (__do_repeat)
{
__s.__do_ = __state::__accept_but_not_consume;
__s.__node_ = this->first();
__init_repeat(__s);
}
else
{
__s.__do_ = __state::__accept_but_not_consume;
__s.__node_ = this->second();
}
}
}
template <class _CharT>
void
__loop<_CharT>::__exec_split(bool __second, __state& __s) const
{
__s.__do_ = __state::__accept_but_not_consume;
if (__greedy_ != __second)
{
__s.__node_ = this->first();
__init_repeat(__s);
}
else
__s.__node_ = this->second();
}
// __alternate
template <class _CharT>
class __alternate
: public __owns_two_states<_CharT>
{
typedef __owns_two_states<_CharT> base;
public:
typedef _VSTD::__state<_CharT> __state;
_LIBCPP_INLINE_VISIBILITY
explicit __alternate(__owns_one_state<_CharT>* __s1,
__owns_one_state<_CharT>* __s2)
: base(__s1, __s2) {}
virtual void __exec(__state& __s) const;
virtual void __exec_split(bool __second, __state& __s) const;
};
template <class _CharT>
void
__alternate<_CharT>::__exec(__state& __s) const
{
__s.__do_ = __state::__split;
}
template <class _CharT>
void
__alternate<_CharT>::__exec_split(bool __second, __state& __s) const
{
__s.__do_ = __state::__accept_but_not_consume;
if (__second)
__s.__node_ = this->second();
else
__s.__node_ = this->first();
}
// __begin_marked_subexpression
template <class _CharT>
class __begin_marked_subexpression
: public __owns_one_state<_CharT>
{
typedef __owns_one_state<_CharT> base;
unsigned __mexp_;
public:
typedef _VSTD::__state<_CharT> __state;
_LIBCPP_INLINE_VISIBILITY
explicit __begin_marked_subexpression(unsigned __mexp, __node<_CharT>* __s)
: base(__s), __mexp_(__mexp) {}
virtual void __exec(__state&) const;
};
template <class _CharT>
void
__begin_marked_subexpression<_CharT>::__exec(__state& __s) const
{
__s.__do_ = __state::__accept_but_not_consume;
__s.__sub_matches_[__mexp_-1].first = __s.__current_;
__s.__node_ = this->first();
}
// __end_marked_subexpression
template <class _CharT>
class __end_marked_subexpression
: public __owns_one_state<_CharT>
{
typedef __owns_one_state<_CharT> base;
unsigned __mexp_;
public:
typedef _VSTD::__state<_CharT> __state;
_LIBCPP_INLINE_VISIBILITY
explicit __end_marked_subexpression(unsigned __mexp, __node<_CharT>* __s)
: base(__s), __mexp_(__mexp) {}
virtual void __exec(__state&) const;
};
template <class _CharT>
void
__end_marked_subexpression<_CharT>::__exec(__state& __s) const
{
__s.__do_ = __state::__accept_but_not_consume;
__s.__sub_matches_[__mexp_-1].second = __s.__current_;
__s.__sub_matches_[__mexp_-1].matched = true;
__s.__node_ = this->first();
}
// __back_ref
template <class _CharT>
class __back_ref
: public __owns_one_state<_CharT>
{
typedef __owns_one_state<_CharT> base;
unsigned __mexp_;
public:
typedef _VSTD::__state<_CharT> __state;
_LIBCPP_INLINE_VISIBILITY
explicit __back_ref(unsigned __mexp, __node<_CharT>* __s)
: base(__s), __mexp_(__mexp) {}
virtual void __exec(__state&) const;
};
template <class _CharT>
void
__back_ref<_CharT>::__exec(__state& __s) const
{
if (__mexp_ > __s.__sub_matches_.size())
__throw_regex_error<regex_constants::error_backref>();
sub_match<const _CharT*>& __sm = __s.__sub_matches_[__mexp_-1];
if (__sm.matched)
{
ptrdiff_t __len = __sm.second - __sm.first;
if (__s.__last_ - __s.__current_ >= __len &&
_VSTD::equal(__sm.first, __sm.second, __s.__current_))
{
__s.__do_ = __state::__accept_but_not_consume;
__s.__current_ += __len;
__s.__node_ = this->first();
}
else
{
__s.__do_ = __state::__reject;
__s.__node_ = nullptr;
}
}
else
{
__s.__do_ = __state::__reject;
__s.__node_ = nullptr;
}
}
// __back_ref_icase
template <class _CharT, class _Traits>
class __back_ref_icase
: public __owns_one_state<_CharT>
{
typedef __owns_one_state<_CharT> base;
_Traits __traits_;
unsigned __mexp_;
public:
typedef _VSTD::__state<_CharT> __state;
_LIBCPP_INLINE_VISIBILITY
explicit __back_ref_icase(const _Traits& __traits, unsigned __mexp,
__node<_CharT>* __s)
: base(__s), __traits_(__traits), __mexp_(__mexp) {}
virtual void __exec(__state&) const;
};
template <class _CharT, class _Traits>
void
__back_ref_icase<_CharT, _Traits>::__exec(__state& __s) const
{
sub_match<const _CharT*>& __sm = __s.__sub_matches_[__mexp_-1];
if (__sm.matched)
{
ptrdiff_t __len = __sm.second - __sm.first;
if (__s.__last_ - __s.__current_ >= __len)
{
for (ptrdiff_t __i = 0; __i < __len; ++__i)
{
if (__traits_.translate_nocase(__sm.first[__i]) !=
__traits_.translate_nocase(__s.__current_[__i]))
goto __not_equal;
}
__s.__do_ = __state::__accept_but_not_consume;
__s.__current_ += __len;
__s.__node_ = this->first();
}
else
{
__s.__do_ = __state::__reject;
__s.__node_ = nullptr;
}
}
else
{
__not_equal:
__s.__do_ = __state::__reject;
__s.__node_ = nullptr;
}
}
// __back_ref_collate
template <class _CharT, class _Traits>
class __back_ref_collate
: public __owns_one_state<_CharT>
{
typedef __owns_one_state<_CharT> base;
_Traits __traits_;
unsigned __mexp_;
public:
typedef _VSTD::__state<_CharT> __state;
_LIBCPP_INLINE_VISIBILITY
explicit __back_ref_collate(const _Traits& __traits, unsigned __mexp,
__node<_CharT>* __s)
: base(__s), __traits_(__traits), __mexp_(__mexp) {}
virtual void __exec(__state&) const;
};
template <class _CharT, class _Traits>
void
__back_ref_collate<_CharT, _Traits>::__exec(__state& __s) const
{
sub_match<const _CharT*>& __sm = __s.__sub_matches_[__mexp_-1];
if (__sm.matched)
{
ptrdiff_t __len = __sm.second - __sm.first;
if (__s.__last_ - __s.__current_ >= __len)
{
for (ptrdiff_t __i = 0; __i < __len; ++__i)
{
if (__traits_.translate(__sm.first[__i]) !=
__traits_.translate(__s.__current_[__i]))
goto __not_equal;
}
__s.__do_ = __state::__accept_but_not_consume;
__s.__current_ += __len;
__s.__node_ = this->first();
}
else
{
__s.__do_ = __state::__reject;
__s.__node_ = nullptr;
}
}
else
{
__not_equal:
__s.__do_ = __state::__reject;
__s.__node_ = nullptr;
}
}
// __word_boundary
template <class _CharT, class _Traits>
class __word_boundary
: public __owns_one_state<_CharT>
{
typedef __owns_one_state<_CharT> base;
_Traits __traits_;
bool __invert_;
public:
typedef _VSTD::__state<_CharT> __state;
_LIBCPP_INLINE_VISIBILITY
explicit __word_boundary(const _Traits& __traits, bool __invert,
__node<_CharT>* __s)
: base(__s), __traits_(__traits), __invert_(__invert) {}
virtual void __exec(__state&) const;
};
template <class _CharT, class _Traits>
void
__word_boundary<_CharT, _Traits>::__exec(__state& __s) const
{
bool __is_word_b = false;
if (__s.__first_ != __s.__last_)
{
if (__s.__current_ == __s.__last_)
{
if (!(__s.__flags_ & regex_constants::match_not_eow))
{
_CharT __c = __s.__current_[-1];
__is_word_b = __c == '_' ||
__traits_.isctype(__c, ctype_base::alnum);
}
}
else if (__s.__current_ == __s.__first_ &&
!(__s.__flags_ & regex_constants::match_prev_avail))
{
if (!(__s.__flags_ & regex_constants::match_not_bow))
{
_CharT __c = *__s.__current_;
__is_word_b = __c == '_' ||
__traits_.isctype(__c, ctype_base::alnum);
}
}
else
{
_CharT __c1 = __s.__current_[-1];
_CharT __c2 = *__s.__current_;
bool __is_c1_b = __c1 == '_' ||
__traits_.isctype(__c1, ctype_base::alnum);
bool __is_c2_b = __c2 == '_' ||
__traits_.isctype(__c2, ctype_base::alnum);
__is_word_b = __is_c1_b != __is_c2_b;
}
}
if (__is_word_b != __invert_)
{
__s.__do_ = __state::__accept_but_not_consume;
__s.__node_ = this->first();
}
else
{
__s.__do_ = __state::__reject;
__s.__node_ = nullptr;
}
}
// __l_anchor
template <class _CharT>
class __l_anchor
: public __owns_one_state<_CharT>
{
typedef __owns_one_state<_CharT> base;
public:
typedef _VSTD::__state<_CharT> __state;
_LIBCPP_INLINE_VISIBILITY
__l_anchor(__node<_CharT>* __s)
: base(__s) {}
virtual void __exec(__state&) const;
};
template <class _CharT>
void
__l_anchor<_CharT>::__exec(__state& __s) const
{
if (__s.__at_first_ && __s.__current_ == __s.__first_ &&
!(__s.__flags_ & regex_constants::match_not_bol))
{
__s.__do_ = __state::__accept_but_not_consume;
__s.__node_ = this->first();
}
else
{
__s.__do_ = __state::__reject;
__s.__node_ = nullptr;
}
}
// __r_anchor
template <class _CharT>
class __r_anchor
: public __owns_one_state<_CharT>
{
typedef __owns_one_state<_CharT> base;
public:
typedef _VSTD::__state<_CharT> __state;
_LIBCPP_INLINE_VISIBILITY
__r_anchor(__node<_CharT>* __s)
: base(__s) {}
virtual void __exec(__state&) const;
};
template <class _CharT>
void
__r_anchor<_CharT>::__exec(__state& __s) const
{
if (__s.__current_ == __s.__last_ &&
!(__s.__flags_ & regex_constants::match_not_eol))
{
__s.__do_ = __state::__accept_but_not_consume;
__s.__node_ = this->first();
}
else
{
__s.__do_ = __state::__reject;
__s.__node_ = nullptr;
}
}
// __match_any
template <class _CharT>
class __match_any
: public __owns_one_state<_CharT>
{
typedef __owns_one_state<_CharT> base;
public:
typedef _VSTD::__state<_CharT> __state;
_LIBCPP_INLINE_VISIBILITY
__match_any(__node<_CharT>* __s)
: base(__s) {}
virtual void __exec(__state&) const;
};
template <class _CharT>
void
__match_any<_CharT>::__exec(__state& __s) const
{
if (__s.__current_ != __s.__last_ && *__s.__current_ != 0)
{
__s.__do_ = __state::__accept_and_consume;
++__s.__current_;
__s.__node_ = this->first();
}
else
{
__s.__do_ = __state::__reject;
__s.__node_ = nullptr;
}
}
// __match_any_but_newline
template <class _CharT>
class __match_any_but_newline
: public __owns_one_state<_CharT>
{
typedef __owns_one_state<_CharT> base;
public:
typedef _VSTD::__state<_CharT> __state;
_LIBCPP_INLINE_VISIBILITY
__match_any_but_newline(__node<_CharT>* __s)
: base(__s) {}
virtual void __exec(__state&) const;
};
template <> _LIBCPP_FUNC_VIS void __match_any_but_newline<char>::__exec(__state&) const;
template <> _LIBCPP_FUNC_VIS void __match_any_but_newline<wchar_t>::__exec(__state&) const;
// __match_char
template <class _CharT>
class __match_char
: public __owns_one_state<_CharT>
{
typedef __owns_one_state<_CharT> base;
_CharT __c_;
__match_char(const __match_char&);
__match_char& operator=(const __match_char&);
public:
typedef _VSTD::__state<_CharT> __state;
_LIBCPP_INLINE_VISIBILITY
__match_char(_CharT __c, __node<_CharT>* __s)
: base(__s), __c_(__c) {}
virtual void __exec(__state&) const;
};
template <class _CharT>
void
__match_char<_CharT>::__exec(__state& __s) const
{
if (__s.__current_ != __s.__last_ && *__s.__current_ == __c_)
{
__s.__do_ = __state::__accept_and_consume;
++__s.__current_;
__s.__node_ = this->first();
}
else
{
__s.__do_ = __state::__reject;
__s.__node_ = nullptr;
}
}
// __match_char_icase
template <class _CharT, class _Traits>
class __match_char_icase
: public __owns_one_state<_CharT>
{
typedef __owns_one_state<_CharT> base;
_Traits __traits_;
_CharT __c_;
__match_char_icase(const __match_char_icase&);
__match_char_icase& operator=(const __match_char_icase&);
public:
typedef _VSTD::__state<_CharT> __state;
_LIBCPP_INLINE_VISIBILITY
__match_char_icase(const _Traits& __traits, _CharT __c, __node<_CharT>* __s)
: base(__s), __traits_(__traits), __c_(__traits.translate_nocase(__c)) {}
virtual void __exec(__state&) const;
};
template <class _CharT, class _Traits>
void
__match_char_icase<_CharT, _Traits>::__exec(__state& __s) const
{
if (__s.__current_ != __s.__last_ &&
__traits_.translate_nocase(*__s.__current_) == __c_)
{
__s.__do_ = __state::__accept_and_consume;
++__s.__current_;
__s.__node_ = this->first();
}
else
{
__s.__do_ = __state::__reject;
__s.__node_ = nullptr;
}
}
// __match_char_collate
template <class _CharT, class _Traits>
class __match_char_collate
: public __owns_one_state<_CharT>
{
typedef __owns_one_state<_CharT> base;
_Traits __traits_;
_CharT __c_;
__match_char_collate(const __match_char_collate&);
__match_char_collate& operator=(const __match_char_collate&);
public:
typedef _VSTD::__state<_CharT> __state;
_LIBCPP_INLINE_VISIBILITY
__match_char_collate(const _Traits& __traits, _CharT __c, __node<_CharT>* __s)
: base(__s), __traits_(__traits), __c_(__traits.translate(__c)) {}
virtual void __exec(__state&) const;
};
template <class _CharT, class _Traits>
void
__match_char_collate<_CharT, _Traits>::__exec(__state& __s) const
{
if (__s.__current_ != __s.__last_ &&
__traits_.translate(*__s.__current_) == __c_)
{
__s.__do_ = __state::__accept_and_consume;
++__s.__current_;
__s.__node_ = this->first();
}
else
{
__s.__do_ = __state::__reject;
__s.__node_ = nullptr;
}
}
// __bracket_expression
template <class _CharT, class _Traits>
class __bracket_expression
: public __owns_one_state<_CharT>
{
typedef __owns_one_state<_CharT> base;
typedef typename _Traits::string_type string_type;
_Traits __traits_;
vector<_CharT> __chars_;
vector<_CharT> __neg_chars_;
vector<pair<string_type, string_type> > __ranges_;
vector<pair<_CharT, _CharT> > __digraphs_;
vector<string_type> __equivalences_;
typename regex_traits<_CharT>::char_class_type __mask_;
typename regex_traits<_CharT>::char_class_type __neg_mask_;
bool __negate_;
bool __icase_;
bool __collate_;
bool __might_have_digraph_;
__bracket_expression(const __bracket_expression&);
__bracket_expression& operator=(const __bracket_expression&);
public:
typedef _VSTD::__state<_CharT> __state;
_LIBCPP_INLINE_VISIBILITY
__bracket_expression(const _Traits& __traits, __node<_CharT>* __s,
bool __negate, bool __icase, bool __collate)
: base(__s), __traits_(__traits), __mask_(), __neg_mask_(),
__negate_(__negate), __icase_(__icase), __collate_(__collate),
__might_have_digraph_(__traits_.getloc().name() != "C") {}
virtual void __exec(__state&) const;
_LIBCPP_INLINE_VISIBILITY
bool __negated() const {return __negate_;}
_LIBCPP_INLINE_VISIBILITY
void __add_char(_CharT __c)
{
if (__icase_)
__chars_.push_back(__traits_.translate_nocase(__c));
else if (__collate_)
__chars_.push_back(__traits_.translate(__c));
else
__chars_.push_back(__c);
}
_LIBCPP_INLINE_VISIBILITY
void __add_neg_char(_CharT __c)
{
if (__icase_)
__neg_chars_.push_back(__traits_.translate_nocase(__c));
else if (__collate_)
__neg_chars_.push_back(__traits_.translate(__c));
else
__neg_chars_.push_back(__c);
}
_LIBCPP_INLINE_VISIBILITY
void __add_range(string_type __b, string_type __e)
{
if (__collate_)
{
if (__icase_)
{
for (size_t __i = 0; __i < __b.size(); ++__i)
__b[__i] = __traits_.translate_nocase(__b[__i]);
for (size_t __i = 0; __i < __e.size(); ++__i)
__e[__i] = __traits_.translate_nocase(__e[__i]);
}
else
{
for (size_t __i = 0; __i < __b.size(); ++__i)
__b[__i] = __traits_.translate(__b[__i]);
for (size_t __i = 0; __i < __e.size(); ++__i)
__e[__i] = __traits_.translate(__e[__i]);
}
__ranges_.push_back(make_pair(
__traits_.transform(__b.begin(), __b.end()),
__traits_.transform(__e.begin(), __e.end())));
}
else
{
if (__b.size() != 1 || __e.size() != 1)
__throw_regex_error<regex_constants::error_range>();
if (__icase_)
{
__b[0] = __traits_.translate_nocase(__b[0]);
__e[0] = __traits_.translate_nocase(__e[0]);
}
__ranges_.push_back(make_pair(_VSTD::move(__b), _VSTD::move(__e)));
}
}
_LIBCPP_INLINE_VISIBILITY
void __add_digraph(_CharT __c1, _CharT __c2)
{
if (__icase_)
__digraphs_.push_back(make_pair(__traits_.translate_nocase(__c1),
__traits_.translate_nocase(__c2)));
else if (__collate_)
__digraphs_.push_back(make_pair(__traits_.translate(__c1),
__traits_.translate(__c2)));
else
__digraphs_.push_back(make_pair(__c1, __c2));
}
_LIBCPP_INLINE_VISIBILITY
void __add_equivalence(const string_type& __s)
{__equivalences_.push_back(__s);}
_LIBCPP_INLINE_VISIBILITY
void __add_class(typename regex_traits<_CharT>::char_class_type __mask)
{__mask_ |= __mask;}
_LIBCPP_INLINE_VISIBILITY
void __add_neg_class(typename regex_traits<_CharT>::char_class_type __mask)
{__neg_mask_ |= __mask;}
};
template <class _CharT, class _Traits>
void
__bracket_expression<_CharT, _Traits>::__exec(__state& __s) const
{
bool __found = false;
unsigned __consumed = 0;
if (__s.__current_ != __s.__last_)
{
++__consumed;
if (__might_have_digraph_)
{
const _CharT* __next = _VSTD::next(__s.__current_);
if (__next != __s.__last_)
{
pair<_CharT, _CharT> __ch2(*__s.__current_, *__next);
if (__icase_)
{
__ch2.first = __traits_.translate_nocase(__ch2.first);
__ch2.second = __traits_.translate_nocase(__ch2.second);
}
else if (__collate_)
{
__ch2.first = __traits_.translate(__ch2.first);
__ch2.second = __traits_.translate(__ch2.second);
}
if (!__traits_.lookup_collatename(&__ch2.first, &__ch2.first+2).empty())
{
// __ch2 is a digraph in this locale
++__consumed;
for (size_t __i = 0; __i < __digraphs_.size(); ++__i)
{
if (__ch2 == __digraphs_[__i])
{
__found = true;
goto __exit;
}
}
if (__collate_ && !__ranges_.empty())
{
string_type __s2 = __traits_.transform(&__ch2.first,
&__ch2.first + 2);
for (size_t __i = 0; __i < __ranges_.size(); ++__i)
{
if (__ranges_[__i].first <= __s2 &&
__s2 <= __ranges_[__i].second)
{
__found = true;
goto __exit;
}
}
}
if (!__equivalences_.empty())
{
string_type __s2 = __traits_.transform_primary(&__ch2.first,
&__ch2.first + 2);
for (size_t __i = 0; __i < __equivalences_.size(); ++__i)
{
if (__s2 == __equivalences_[__i])
{
__found = true;
goto __exit;
}
}
}
if (__traits_.isctype(__ch2.first, __mask_) &&
__traits_.isctype(__ch2.second, __mask_))
{
__found = true;
goto __exit;
}
if (!__traits_.isctype(__ch2.first, __neg_mask_) &&
!__traits_.isctype(__ch2.second, __neg_mask_))
{
__found = true;
goto __exit;
}
goto __exit;
}
}
}
// test *__s.__current_ as not a digraph
_CharT __ch = *__s.__current_;
if (__icase_)
__ch = __traits_.translate_nocase(__ch);
else if (__collate_)
__ch = __traits_.translate(__ch);
for (size_t __i = 0; __i < __chars_.size(); ++__i)
{
if (__ch == __chars_[__i])
{
__found = true;
goto __exit;
}
}
// When there's at least one of __neg_chars_ and __neg_mask_, the set
// of "__found" chars is
// union(complement(union(__neg_chars_, __neg_mask_)),
// other cases...)
//
// It doesn't make sense to check this when there are no __neg_chars_
// and no __neg_mask_.
if (!(__neg_mask_ == 0 && __neg_chars_.empty()))
{
const bool __in_neg_mask = __traits_.isctype(__ch, __neg_mask_);
const bool __in_neg_chars =
std::find(__neg_chars_.begin(), __neg_chars_.end(), __ch) !=
__neg_chars_.end();
if (!(__in_neg_mask || __in_neg_chars))
{
__found = true;
goto __exit;
}
}
if (!__ranges_.empty())
{
string_type __s2 = __collate_ ?
__traits_.transform(&__ch, &__ch + 1) :
string_type(1, __ch);
for (size_t __i = 0; __i < __ranges_.size(); ++__i)
{
if (__ranges_[__i].first <= __s2 && __s2 <= __ranges_[__i].second)
{
__found = true;
goto __exit;
}
}
}
if (!__equivalences_.empty())
{
string_type __s2 = __traits_.transform_primary(&__ch, &__ch + 1);
for (size_t __i = 0; __i < __equivalences_.size(); ++__i)
{
if (__s2 == __equivalences_[__i])
{
__found = true;
goto __exit;
}
}
}
if (__traits_.isctype(__ch, __mask_))
{
__found = true;
goto __exit;
}
}
else
__found = __negate_; // force reject
__exit:
if (__found != __negate_)
{
__s.__do_ = __state::__accept_and_consume;
__s.__current_ += __consumed;
__s.__node_ = this->first();
}
else
{
__s.__do_ = __state::__reject;
__s.__node_ = nullptr;
}
}
template <class _CharT, class _Traits> class __lookahead;
template <class _CharT, class _Traits = regex_traits<_CharT> >
class _LIBCPP_TEMPLATE_VIS basic_regex
{
public:
// types:
typedef _CharT value_type;
typedef _Traits traits_type;
typedef typename _Traits::string_type string_type;
typedef regex_constants::syntax_option_type flag_type;
typedef typename _Traits::locale_type locale_type;
private:
_Traits __traits_;
flag_type __flags_;
unsigned __marked_count_;
unsigned __loop_count_;
int __open_count_;
shared_ptr<__empty_state<_CharT> > __start_;
__owns_one_state<_CharT>* __end_;
typedef _VSTD::__state<_CharT> __state;
typedef _VSTD::__node<_CharT> __node;
public:
// constants:
static const regex_constants::syntax_option_type icase = regex_constants::icase;
static const regex_constants::syntax_option_type nosubs = regex_constants::nosubs;
static const regex_constants::syntax_option_type optimize = regex_constants::optimize;
static const regex_constants::syntax_option_type collate = regex_constants::collate;
static const regex_constants::syntax_option_type ECMAScript = regex_constants::ECMAScript;
static const regex_constants::syntax_option_type basic = regex_constants::basic;
static const regex_constants::syntax_option_type extended = regex_constants::extended;
static const regex_constants::syntax_option_type awk = regex_constants::awk;
static const regex_constants::syntax_option_type grep = regex_constants::grep;
static const regex_constants::syntax_option_type egrep = regex_constants::egrep;
// construct/copy/destroy:
_LIBCPP_INLINE_VISIBILITY
basic_regex()
: __flags_(regex_constants::ECMAScript), __marked_count_(0), __loop_count_(0), __open_count_(0),
__end_(0)
{}
_LIBCPP_INLINE_VISIBILITY
explicit basic_regex(const value_type* __p, flag_type __f = regex_constants::ECMAScript)
: __flags_(__f), __marked_count_(0), __loop_count_(0), __open_count_(0),
__end_(0)
{
if (__get_grammar(__flags_) == 0) __flags_ |= regex_constants::ECMAScript;
__parse(__p, __p + __traits_.length(__p));
}
_LIBCPP_INLINE_VISIBILITY
basic_regex(const value_type* __p, size_t __len, flag_type __f = regex_constants::ECMAScript)
: __flags_(__f), __marked_count_(0), __loop_count_(0), __open_count_(0),
__end_(0)
{
if (__get_grammar(__flags_) == 0) __flags_ |= regex_constants::ECMAScript;
__parse(__p, __p + __len);
}
// basic_regex(const basic_regex&) = default;
// basic_regex(basic_regex&&) = default;
template <class _ST, class _SA>
_LIBCPP_INLINE_VISIBILITY
explicit basic_regex(const basic_string<value_type, _ST, _SA>& __p,
flag_type __f = regex_constants::ECMAScript)
: __flags_(__f), __marked_count_(0), __loop_count_(0), __open_count_(0),
__end_(0)
{
if (__get_grammar(__flags_) == 0) __flags_ |= regex_constants::ECMAScript;
__parse(__p.begin(), __p.end());
}
template <class _ForwardIterator>
_LIBCPP_INLINE_VISIBILITY
basic_regex(_ForwardIterator __first, _ForwardIterator __last,
flag_type __f = regex_constants::ECMAScript)
: __flags_(__f), __marked_count_(0), __loop_count_(0), __open_count_(0),
__end_(0)
{
if (__get_grammar(__flags_) == 0) __flags_ |= regex_constants::ECMAScript;
__parse(__first, __last);
}
#ifndef _LIBCPP_CXX03_LANG
_LIBCPP_INLINE_VISIBILITY
basic_regex(initializer_list<value_type> __il,
flag_type __f = regex_constants::ECMAScript)
: __flags_(__f), __marked_count_(0), __loop_count_(0), __open_count_(0),
__end_(0)
{
if (__get_grammar(__flags_) == 0) __flags_ |= regex_constants::ECMAScript;
__parse(__il.begin(), __il.end());
}
#endif // _LIBCPP_CXX03_LANG
// ~basic_regex() = default;
// basic_regex& operator=(const basic_regex&) = default;
// basic_regex& operator=(basic_regex&&) = default;
_LIBCPP_INLINE_VISIBILITY
basic_regex& operator=(const value_type* __p)
{return assign(__p);}
#ifndef _LIBCPP_CXX03_LANG
_LIBCPP_INLINE_VISIBILITY
basic_regex& operator=(initializer_list<value_type> __il)
{return assign(__il);}
#endif // _LIBCPP_CXX03_LANG
template <class _ST, class _SA>
_LIBCPP_INLINE_VISIBILITY
basic_regex& operator=(const basic_string<value_type, _ST, _SA>& __p)
{return assign(__p);}
// assign:
_LIBCPP_INLINE_VISIBILITY
basic_regex& assign(const basic_regex& __that)
{return *this = __that;}
#ifndef _LIBCPP_CXX03_LANG
_LIBCPP_INLINE_VISIBILITY
basic_regex& assign(basic_regex&& __that) _NOEXCEPT
{return *this = _VSTD::move(__that);}
#endif
_LIBCPP_INLINE_VISIBILITY
basic_regex& assign(const value_type* __p, flag_type __f = regex_constants::ECMAScript)
{return assign(__p, __p + __traits_.length(__p), __f);}
_LIBCPP_INLINE_VISIBILITY
basic_regex& assign(const value_type* __p, size_t __len, flag_type __f = regex_constants::ECMAScript)
{return assign(__p, __p + __len, __f);}
template <class _ST, class _SA>
_LIBCPP_INLINE_VISIBILITY
basic_regex& assign(const basic_string<value_type, _ST, _SA>& __s,
flag_type __f = regex_constants::ECMAScript)
{return assign(__s.begin(), __s.end(), __f);}
template <class _InputIterator>
_LIBCPP_INLINE_VISIBILITY
typename enable_if
<
__is_input_iterator <_InputIterator>::value &&
!__is_forward_iterator<_InputIterator>::value,
basic_regex&
>::type
assign(_InputIterator __first, _InputIterator __last,
flag_type __f = regex_constants::ECMAScript)
{
basic_string<_CharT> __t(__first, __last);
return assign(__t.begin(), __t.end(), __f);
}
private:
_LIBCPP_INLINE_VISIBILITY
void __member_init(flag_type __f)
{
__flags_ = __f;
__marked_count_ = 0;
__loop_count_ = 0;
__open_count_ = 0;
__end_ = nullptr;
}
public:
template <class _ForwardIterator>
_LIBCPP_INLINE_VISIBILITY
typename enable_if
<
__is_forward_iterator<_ForwardIterator>::value,
basic_regex&
>::type
assign(_ForwardIterator __first, _ForwardIterator __last,
flag_type __f = regex_constants::ECMAScript)
{
return assign(basic_regex(__first, __last, __f));
}
#ifndef _LIBCPP_CXX03_LANG
_LIBCPP_INLINE_VISIBILITY
basic_regex& assign(initializer_list<value_type> __il,
flag_type __f = regex_constants::ECMAScript)
{return assign(__il.begin(), __il.end(), __f);}
#endif // _LIBCPP_CXX03_LANG
// const operations:
_LIBCPP_INLINE_VISIBILITY
unsigned mark_count() const {return __marked_count_;}
_LIBCPP_INLINE_VISIBILITY
flag_type flags() const {return __flags_;}
// locale:
_LIBCPP_INLINE_VISIBILITY
locale_type imbue(locale_type __loc)
{
__member_init(ECMAScript);
__start_.reset();
return __traits_.imbue(__loc);
}
_LIBCPP_INLINE_VISIBILITY
locale_type getloc() const {return __traits_.getloc();}
// swap:
void swap(basic_regex& __r);
private:
_LIBCPP_INLINE_VISIBILITY
unsigned __loop_count() const {return __loop_count_;}
template <class _ForwardIterator>
_ForwardIterator
__parse(_ForwardIterator __first, _ForwardIterator __last);
template <class _ForwardIterator>
_ForwardIterator
__parse_basic_reg_exp(_ForwardIterator __first, _ForwardIterator __last);
template <class _ForwardIterator>
_ForwardIterator
__parse_RE_expression(_ForwardIterator __first, _ForwardIterator __last);
template <class _ForwardIterator>
_ForwardIterator
__parse_simple_RE(_ForwardIterator __first, _ForwardIterator __last);
template <class _ForwardIterator>
_ForwardIterator
__parse_nondupl_RE(_ForwardIterator __first, _ForwardIterator __last);
template <class _ForwardIterator>
_ForwardIterator
__parse_one_char_or_coll_elem_RE(_ForwardIterator __first, _ForwardIterator __last);
template <class _ForwardIterator>
_ForwardIterator
__parse_Back_open_paren(_ForwardIterator __first, _ForwardIterator __last);
template <class _ForwardIterator>
_ForwardIterator
__parse_Back_close_paren(_ForwardIterator __first, _ForwardIterator __last);
template <class _ForwardIterator>
_ForwardIterator
__parse_Back_open_brace(_ForwardIterator __first, _ForwardIterator __last);
template <class _ForwardIterator>
_ForwardIterator
__parse_Back_close_brace(_ForwardIterator __first, _ForwardIterator __last);
template <class _ForwardIterator>
_ForwardIterator
__parse_BACKREF(_ForwardIterator __first, _ForwardIterator __last);
template <class _ForwardIterator>
_ForwardIterator
__parse_ORD_CHAR(_ForwardIterator __first, _ForwardIterator __last);
template <class _ForwardIterator>
_ForwardIterator
__parse_QUOTED_CHAR(_ForwardIterator __first, _ForwardIterator __last);
template <class _ForwardIterator>
_ForwardIterator
__parse_RE_dupl_symbol(_ForwardIterator __first, _ForwardIterator __last,
__owns_one_state<_CharT>* __s,
unsigned __mexp_begin, unsigned __mexp_end);
template <class _ForwardIterator>
_ForwardIterator
__parse_ERE_dupl_symbol(_ForwardIterator __first, _ForwardIterator __last,
__owns_one_state<_CharT>* __s,
unsigned __mexp_begin, unsigned __mexp_end);
template <class _ForwardIterator>
_ForwardIterator
__parse_bracket_expression(_ForwardIterator __first, _ForwardIterator __last);
template <class _ForwardIterator>
_ForwardIterator
__parse_follow_list(_ForwardIterator __first, _ForwardIterator __last,
__bracket_expression<_CharT, _Traits>* __ml);
template <class _ForwardIterator>
_ForwardIterator
__parse_expression_term(_ForwardIterator __first, _ForwardIterator __last,
__bracket_expression<_CharT, _Traits>* __ml);
template <class _ForwardIterator>
_ForwardIterator
__parse_equivalence_class(_ForwardIterator __first, _ForwardIterator __last,
__bracket_expression<_CharT, _Traits>* __ml);
template <class _ForwardIterator>
_ForwardIterator
__parse_character_class(_ForwardIterator __first, _ForwardIterator __last,
__bracket_expression<_CharT, _Traits>* __ml);
template <class _ForwardIterator>
_ForwardIterator
__parse_collating_symbol(_ForwardIterator __first, _ForwardIterator __last,
basic_string<_CharT>& __col_sym);
template <class _ForwardIterator>
_ForwardIterator
__parse_DUP_COUNT(_ForwardIterator __first, _ForwardIterator __last, int& __c);
template <class _ForwardIterator>
_ForwardIterator
__parse_extended_reg_exp(_ForwardIterator __first, _ForwardIterator __last);
template <class _ForwardIterator>
_ForwardIterator
__parse_ERE_branch(_ForwardIterator __first, _ForwardIterator __last);
template <class _ForwardIterator>
_ForwardIterator
__parse_ERE_expression(_ForwardIterator __first, _ForwardIterator __last);
template <class _ForwardIterator>
_ForwardIterator
__parse_one_char_or_coll_elem_ERE(_ForwardIterator __first, _ForwardIterator __last);
template <class _ForwardIterator>
_ForwardIterator
__parse_ORD_CHAR_ERE(_ForwardIterator __first, _ForwardIterator __last);
template <class _ForwardIterator>
_ForwardIterator
__parse_QUOTED_CHAR_ERE(_ForwardIterator __first, _ForwardIterator __last);
template <class _ForwardIterator>
_ForwardIterator
__parse_ecma_exp(_ForwardIterator __first, _ForwardIterator __last);
template <class _ForwardIterator>
_ForwardIterator
__parse_alternative(_ForwardIterator __first, _ForwardIterator __last);
template <class _ForwardIterator>
_ForwardIterator
__parse_term(_ForwardIterator __first, _ForwardIterator __last);
template <class _ForwardIterator>
_ForwardIterator
__parse_assertion(_ForwardIterator __first, _ForwardIterator __last);
template <class _ForwardIterator>
_ForwardIterator
__parse_atom(_ForwardIterator __first, _ForwardIterator __last);
template <class _ForwardIterator>
_ForwardIterator
__parse_atom_escape(_ForwardIterator __first, _ForwardIterator __last);
template <class _ForwardIterator>
_ForwardIterator
__parse_decimal_escape(_ForwardIterator __first, _ForwardIterator __last);
template <class _ForwardIterator>
_ForwardIterator
__parse_character_class_escape(_ForwardIterator __first, _ForwardIterator __last);
template <class _ForwardIterator>
_ForwardIterator
__parse_character_escape(_ForwardIterator __first, _ForwardIterator __last,
basic_string<_CharT>* __str = nullptr);
template <class _ForwardIterator>
_ForwardIterator
__parse_pattern_character(_ForwardIterator __first, _ForwardIterator __last);
template <class _ForwardIterator>
_ForwardIterator
__parse_grep(_ForwardIterator __first, _ForwardIterator __last);
template <class _ForwardIterator>
_ForwardIterator
__parse_egrep(_ForwardIterator __first, _ForwardIterator __last);
template <class _ForwardIterator>
_ForwardIterator
__parse_class_escape(_ForwardIterator __first, _ForwardIterator __last,
basic_string<_CharT>& __str,
__bracket_expression<_CharT, _Traits>* __ml);
template <class _ForwardIterator>
_ForwardIterator
__parse_awk_escape(_ForwardIterator __first, _ForwardIterator __last,
basic_string<_CharT>* __str = nullptr);
_LIBCPP_INLINE_VISIBILITY
void __push_l_anchor();
void __push_r_anchor();
void __push_match_any();
void __push_match_any_but_newline();
_LIBCPP_INLINE_VISIBILITY
void __push_greedy_inf_repeat(size_t __min, __owns_one_state<_CharT>* __s,
unsigned __mexp_begin = 0, unsigned __mexp_end = 0)
{__push_loop(__min, numeric_limits<size_t>::max(), __s,
__mexp_begin, __mexp_end);}
_LIBCPP_INLINE_VISIBILITY
void __push_nongreedy_inf_repeat(size_t __min, __owns_one_state<_CharT>* __s,
unsigned __mexp_begin = 0, unsigned __mexp_end = 0)
{__push_loop(__min, numeric_limits<size_t>::max(), __s,
__mexp_begin, __mexp_end, false);}
void __push_loop(size_t __min, size_t __max, __owns_one_state<_CharT>* __s,
size_t __mexp_begin = 0, size_t __mexp_end = 0,
bool __greedy = true);
__bracket_expression<_CharT, _Traits>* __start_matching_list(bool __negate);
void __push_char(value_type __c);
void __push_back_ref(int __i);
void __push_alternation(__owns_one_state<_CharT>* __sa,
__owns_one_state<_CharT>* __sb);
void __push_begin_marked_subexpression();
void __push_end_marked_subexpression(unsigned);
void __push_empty();
void __push_word_boundary(bool);
void __push_lookahead(const basic_regex&, bool, unsigned);
template <class _Allocator>
bool
__search(const _CharT* __first, const _CharT* __last,
match_results<const _CharT*, _Allocator>& __m,
regex_constants::match_flag_type __flags) const;
template <class _Allocator>
bool
__match_at_start(const _CharT* __first, const _CharT* __last,
match_results<const _CharT*, _Allocator>& __m,
regex_constants::match_flag_type __flags, bool) const;
template <class _Allocator>
bool
__match_at_start_ecma(const _CharT* __first, const _CharT* __last,
match_results<const _CharT*, _Allocator>& __m,
regex_constants::match_flag_type __flags, bool) const;
template <class _Allocator>
bool
__match_at_start_posix_nosubs(const _CharT* __first, const _CharT* __last,
match_results<const _CharT*, _Allocator>& __m,
regex_constants::match_flag_type __flags, bool) const;
template <class _Allocator>
bool
__match_at_start_posix_subs(const _CharT* __first, const _CharT* __last,
match_results<const _CharT*, _Allocator>& __m,
regex_constants::match_flag_type __flags, bool) const;
template <class _Bp, class _Ap, class _Cp, class _Tp>
friend
bool
regex_search(_Bp, _Bp, match_results<_Bp, _Ap>&, const basic_regex<_Cp, _Tp>&,
regex_constants::match_flag_type);
template <class _Ap, class _Cp, class _Tp>
friend
bool
regex_search(const _Cp*, const _Cp*, match_results<const _Cp*, _Ap>&,
const basic_regex<_Cp, _Tp>&, regex_constants::match_flag_type);
template <class _Bp, class _Cp, class _Tp>
friend
bool
regex_search(_Bp, _Bp, const basic_regex<_Cp, _Tp>&,
regex_constants::match_flag_type);
template <class _Cp, class _Tp>
friend
bool
regex_search(const _Cp*, const _Cp*,
const basic_regex<_Cp, _Tp>&, regex_constants::match_flag_type);
template <class _Cp, class _Ap, class _Tp>
friend
bool
regex_search(const _Cp*, match_results<const _Cp*, _Ap>&, const basic_regex<_Cp, _Tp>&,
regex_constants::match_flag_type);
template <class _ST, class _SA, class _Cp, class _Tp>
friend
bool
regex_search(const basic_string<_Cp, _ST, _SA>& __s,
const basic_regex<_Cp, _Tp>& __e,
regex_constants::match_flag_type __flags);
template <class _ST, class _SA, class _Ap, class _Cp, class _Tp>
friend
bool
regex_search(const basic_string<_Cp, _ST, _SA>& __s,
match_results<typename basic_string<_Cp, _ST, _SA>::const_iterator, _Ap>&,
const basic_regex<_Cp, _Tp>& __e,
regex_constants::match_flag_type __flags);
template <class _Iter, class _Ap, class _Cp, class _Tp>
friend
bool
regex_search(__wrap_iter<_Iter> __first,
__wrap_iter<_Iter> __last,
match_results<__wrap_iter<_Iter>, _Ap>& __m,
const basic_regex<_Cp, _Tp>& __e,
regex_constants::match_flag_type __flags);
template <class, class> friend class __lookahead;
};
#ifndef _LIBCPP_HAS_NO_DEDUCTION_GUIDES
template <class _ForwardIterator,
class = typename enable_if<__is_forward_iterator<_ForwardIterator>::value, nullptr_t>::type
>
basic_regex(_ForwardIterator, _ForwardIterator,
regex_constants::syntax_option_type = regex_constants::ECMAScript)
-> basic_regex<typename iterator_traits<_ForwardIterator>::value_type>;
#endif
template <class _CharT, class _Traits>
const regex_constants::syntax_option_type basic_regex<_CharT, _Traits>::icase;
template <class _CharT, class _Traits>
const regex_constants::syntax_option_type basic_regex<_CharT, _Traits>::nosubs;
template <class _CharT, class _Traits>
const regex_constants::syntax_option_type basic_regex<_CharT, _Traits>::optimize;
template <class _CharT, class _Traits>
const regex_constants::syntax_option_type basic_regex<_CharT, _Traits>::collate;
template <class _CharT, class _Traits>
const regex_constants::syntax_option_type basic_regex<_CharT, _Traits>::ECMAScript;
template <class _CharT, class _Traits>
const regex_constants::syntax_option_type basic_regex<_CharT, _Traits>::basic;
template <class _CharT, class _Traits>
const regex_constants::syntax_option_type basic_regex<_CharT, _Traits>::extended;
template <class _CharT, class _Traits>
const regex_constants::syntax_option_type basic_regex<_CharT, _Traits>::awk;
template <class _CharT, class _Traits>
const regex_constants::syntax_option_type basic_regex<_CharT, _Traits>::grep;
template <class _CharT, class _Traits>
const regex_constants::syntax_option_type basic_regex<_CharT, _Traits>::egrep;
template <class _CharT, class _Traits>
void
basic_regex<_CharT, _Traits>::swap(basic_regex& __r)
{
using _VSTD::swap;
swap(__traits_, __r.__traits_);
swap(__flags_, __r.__flags_);
swap(__marked_count_, __r.__marked_count_);
swap(__loop_count_, __r.__loop_count_);
swap(__open_count_, __r.__open_count_);
swap(__start_, __r.__start_);
swap(__end_, __r.__end_);
}
template <class _CharT, class _Traits>
inline _LIBCPP_INLINE_VISIBILITY
void
swap(basic_regex<_CharT, _Traits>& __x, basic_regex<_CharT, _Traits>& __y)
{
return __x.swap(__y);
}
// __lookahead
template <class _CharT, class _Traits>
class __lookahead
: public __owns_one_state<_CharT>
{
typedef __owns_one_state<_CharT> base;
basic_regex<_CharT, _Traits> __exp_;
unsigned __mexp_;
bool __invert_;
__lookahead(const __lookahead&);
__lookahead& operator=(const __lookahead&);
public:
typedef _VSTD::__state<_CharT> __state;
_LIBCPP_INLINE_VISIBILITY
__lookahead(const basic_regex<_CharT, _Traits>& __exp, bool __invert, __node<_CharT>* __s, unsigned __mexp)
: base(__s), __exp_(__exp), __mexp_(__mexp), __invert_(__invert) {}
virtual void __exec(__state&) const;
};
template <class _CharT, class _Traits>
void
__lookahead<_CharT, _Traits>::__exec(__state& __s) const
{
match_results<const _CharT*> __m;
__m.__init(1 + __exp_.mark_count(), __s.__current_, __s.__last_);
bool __matched = __exp_.__match_at_start_ecma(
__s.__current_, __s.__last_,
__m,
(__s.__flags_ | regex_constants::match_continuous) &
~regex_constants::__full_match,
__s.__at_first_ && __s.__current_ == __s.__first_);
if (__matched != __invert_)
{
__s.__do_ = __state::__accept_but_not_consume;
__s.__node_ = this->first();
for (unsigned __i = 1; __i < __m.size(); ++__i) {
__s.__sub_matches_[__mexp_ + __i - 1] = __m.__matches_[__i];
}
}
else
{
__s.__do_ = __state::__reject;
__s.__node_ = nullptr;
}
}
template <class _CharT, class _Traits>
template <class _ForwardIterator>
_ForwardIterator
basic_regex<_CharT, _Traits>::__parse(_ForwardIterator __first,
_ForwardIterator __last)
{
{
unique_ptr<__node> __h(new __end_state<_CharT>);
__start_.reset(new __empty_state<_CharT>(__h.get()));
__h.release();
__end_ = __start_.get();
}
switch (__get_grammar(__flags_))
{
case ECMAScript:
__first = __parse_ecma_exp(__first, __last);
break;
case basic:
__first = __parse_basic_reg_exp(__first, __last);
break;
case extended:
case awk:
__first = __parse_extended_reg_exp(__first, __last);
break;
case grep:
__first = __parse_grep(__first, __last);
break;
case egrep:
__first = __parse_egrep(__first, __last);
break;
default:
__throw_regex_error<regex_constants::__re_err_grammar>();
}
return __first;
}
template <class _CharT, class _Traits>
template <class _ForwardIterator>
_ForwardIterator
basic_regex<_CharT, _Traits>::__parse_basic_reg_exp(_ForwardIterator __first,
_ForwardIterator __last)
{
if (__first != __last)
{
if (*__first == '^')
{
__push_l_anchor();
++__first;
}
if (__first != __last)
{
__first = __parse_RE_expression(__first, __last);
if (__first != __last)
{
_ForwardIterator __temp = _VSTD::next(__first);
if (__temp == __last && *__first == '$')
{
__push_r_anchor();
++__first;
}
}
}
if (__first != __last)
__throw_regex_error<regex_constants::__re_err_empty>();
}
return __first;
}
template <class _CharT, class _Traits>
template <class _ForwardIterator>
_ForwardIterator
basic_regex<_CharT, _Traits>::__parse_extended_reg_exp(_ForwardIterator __first,
_ForwardIterator __last)
{
__owns_one_state<_CharT>* __sa = __end_;
_ForwardIterator __temp = __parse_ERE_branch(__first, __last);
if (__temp == __first)
__throw_regex_error<regex_constants::__re_err_empty>();
__first = __temp;
while (__first != __last && *__first == '|')
{
__owns_one_state<_CharT>* __sb = __end_;
__temp = __parse_ERE_branch(++__first, __last);
if (__temp == __first)
__throw_regex_error<regex_constants::__re_err_empty>();
__push_alternation(__sa, __sb);
__first = __temp;
}
return __first;
}
template <class _CharT, class _Traits>
template <class _ForwardIterator>
_ForwardIterator
basic_regex<_CharT, _Traits>::__parse_ERE_branch(_ForwardIterator __first,
_ForwardIterator __last)
{
_ForwardIterator __temp = __parse_ERE_expression(__first, __last);
if (__temp == __first)
__throw_regex_error<regex_constants::__re_err_empty>();
do
{
__first = __temp;
__temp = __parse_ERE_expression(__first, __last);
} while (__temp != __first);
return __first;
}
template <class _CharT, class _Traits>
template <class _ForwardIterator>
_ForwardIterator
basic_regex<_CharT, _Traits>::__parse_ERE_expression(_ForwardIterator __first,
_ForwardIterator __last)
{
__owns_one_state<_CharT>* __e = __end_;
unsigned __mexp_begin = __marked_count_;
_ForwardIterator __temp = __parse_one_char_or_coll_elem_ERE(__first, __last);
if (__temp == __first && __temp != __last)
{
switch (*__temp)
{
case '^':
__push_l_anchor();
++__temp;
break;
case '$':
__push_r_anchor();
++__temp;
break;
case '(':
__push_begin_marked_subexpression();
unsigned __temp_count = __marked_count_;
++__open_count_;
__temp = __parse_extended_reg_exp(++__temp, __last);
if (__temp == __last || *__temp != ')')
__throw_regex_error<regex_constants::error_paren>();
__push_end_marked_subexpression(__temp_count);
--__open_count_;
++__temp;
break;
}
}
if (__temp != __first)
__temp = __parse_ERE_dupl_symbol(__temp, __last, __e, __mexp_begin+1,
__marked_count_+1);
__first = __temp;
return __first;
}
template <class _CharT, class _Traits>
template <class _ForwardIterator>
_ForwardIterator
basic_regex<_CharT, _Traits>::__parse_RE_expression(_ForwardIterator __first,
_ForwardIterator __last)
{
while (true)
{
_ForwardIterator __temp = __parse_simple_RE(__first, __last);
if (__temp == __first)
break;
__first = __temp;
}
return __first;
}
template <class _CharT, class _Traits>
template <class _ForwardIterator>
_ForwardIterator
basic_regex<_CharT, _Traits>::__parse_simple_RE(_ForwardIterator __first,
_ForwardIterator __last)
{
if (__first != __last)
{
__owns_one_state<_CharT>* __e = __end_;
unsigned __mexp_begin = __marked_count_;
_ForwardIterator __temp = __parse_nondupl_RE(__first, __last);
if (__temp != __first)
__first = __parse_RE_dupl_symbol(__temp, __last, __e,
__mexp_begin+1, __marked_count_+1);
}
return __first;
}
template <class _CharT, class _Traits>
template <class _ForwardIterator>
_ForwardIterator
basic_regex<_CharT, _Traits>::__parse_nondupl_RE(_ForwardIterator __first,
_ForwardIterator __last)
{
_ForwardIterator __temp = __first;
__first = __parse_one_char_or_coll_elem_RE(__first, __last);
if (__temp == __first)
{
__temp = __parse_Back_open_paren(__first, __last);
if (__temp != __first)
{
__push_begin_marked_subexpression();
unsigned __temp_count = __marked_count_;
__first = __parse_RE_expression(__temp, __last);
__temp = __parse_Back_close_paren(__first, __last);
if (__temp == __first)
__throw_regex_error<regex_constants::error_paren>();
__push_end_marked_subexpression(__temp_count);
__first = __temp;
}
else
__first = __parse_BACKREF(__first, __last);
}
return __first;
}
template <class _CharT, class _Traits>
template <class _ForwardIterator>
_ForwardIterator
basic_regex<_CharT, _Traits>::__parse_one_char_or_coll_elem_RE(
_ForwardIterator __first,
_ForwardIterator __last)
{
_ForwardIterator __temp = __parse_ORD_CHAR(__first, __last);
if (__temp == __first)
{
__temp = __parse_QUOTED_CHAR(__first, __last);
if (__temp == __first)
{
if (__temp != __last && *__temp == '.')
{
__push_match_any();
++__temp;
}
else
__temp = __parse_bracket_expression(__first, __last);
}
}
__first = __temp;
return __first;
}
template <class _CharT, class _Traits>
template <class _ForwardIterator>
_ForwardIterator
basic_regex<_CharT, _Traits>::__parse_one_char_or_coll_elem_ERE(
_ForwardIterator __first,
_ForwardIterator __last)
{
_ForwardIterator __temp = __parse_ORD_CHAR_ERE(__first, __last);
if (__temp == __first)
{
__temp = __parse_QUOTED_CHAR_ERE(__first, __last);
if (__temp == __first)
{
if (__temp != __last && *__temp == '.')
{
__push_match_any();
++__temp;
}
else
__temp = __parse_bracket_expression(__first, __last);
}
}
__first = __temp;
return __first;
}
template <class _CharT, class _Traits>
template <class _ForwardIterator>
_ForwardIterator
basic_regex<_CharT, _Traits>::__parse_Back_open_paren(_ForwardIterator __first,
_ForwardIterator __last)
{
if (__first != __last)
{
_ForwardIterator __temp = _VSTD::next(__first);
if (__temp != __last)
{
if (*__first == '\\' && *__temp == '(')
__first = ++__temp;
}
}
return __first;
}
template <class _CharT, class _Traits>
template <class _ForwardIterator>
_ForwardIterator
basic_regex<_CharT, _Traits>::__parse_Back_close_paren(_ForwardIterator __first,
_ForwardIterator __last)
{
if (__first != __last)
{
_ForwardIterator __temp = _VSTD::next(__first);
if (__temp != __last)
{
if (*__first == '\\' && *__temp == ')')
__first = ++__temp;
}
}
return __first;
}
template <class _CharT, class _Traits>
template <class _ForwardIterator>
_ForwardIterator
basic_regex<_CharT, _Traits>::__parse_Back_open_brace(_ForwardIterator __first,
_ForwardIterator __last)
{
if (__first != __last)
{
_ForwardIterator __temp = _VSTD::next(__first);
if (__temp != __last)
{
if (*__first == '\\' && *__temp == '{')
__first = ++__temp;
}
}
return __first;
}
template <class _CharT, class _Traits>
template <class _ForwardIterator>
_ForwardIterator
basic_regex<_CharT, _Traits>::__parse_Back_close_brace(_ForwardIterator __first,
_ForwardIterator __last)
{
if (__first != __last)
{
_ForwardIterator __temp = _VSTD::next(__first);
if (__temp != __last)
{
if (*__first == '\\' && *__temp == '}')
__first = ++__temp;
}
}
return __first;
}
template <class _CharT, class _Traits>
template <class _ForwardIterator>
_ForwardIterator
basic_regex<_CharT, _Traits>::__parse_BACKREF(_ForwardIterator __first,
_ForwardIterator __last)
{
if (__first != __last)
{
_ForwardIterator __temp = _VSTD::next(__first);
if (__temp != __last)
{
if (*__first == '\\')
{
int __val = __traits_.value(*__temp, 10);
if (__val >= 1 && __val <= 9)
{
__push_back_ref(__val);
__first = ++__temp;
}
}
}
}
return __first;
}
template <class _CharT, class _Traits>
template <class _ForwardIterator>
_ForwardIterator
basic_regex<_CharT, _Traits>::__parse_ORD_CHAR(_ForwardIterator __first,
_ForwardIterator __last)
{
if (__first != __last)
{
_ForwardIterator __temp = _VSTD::next(__first);
if (__temp == __last && *__first == '$')
return __first;
// Not called inside a bracket
if (*__first == '.' || *__first == '\\' || *__first == '[')
return __first;
__push_char(*__first);
++__first;
}
return __first;
}
template <class _CharT, class _Traits>
template <class _ForwardIterator>
_ForwardIterator
basic_regex<_CharT, _Traits>::__parse_ORD_CHAR_ERE(_ForwardIterator __first,
_ForwardIterator __last)
{
if (__first != __last)
{
switch (*__first)
{
case '^':
case '.':
case '[':
case '$':
case '(':
case '|':
case '*':
case '+':
case '?':
case '{':
case '\\':
break;
case ')':
if (__open_count_ == 0)
{
__push_char(*__first);
++__first;
}
break;
default:
__push_char(*__first);
++__first;
break;
}
}
return __first;
}
template <class _CharT, class _Traits>
template <class _ForwardIterator>
_ForwardIterator
basic_regex<_CharT, _Traits>::__parse_QUOTED_CHAR(_ForwardIterator __first,
_ForwardIterator __last)
{
if (__first != __last)
{
_ForwardIterator __temp = _VSTD::next(__first);
if (__temp != __last)
{
if (*__first == '\\')
{
switch (*__temp)
{
case '^':
case '.':
case '*':
case '[':
case '$':
case '\\':
__push_char(*__temp);
__first = ++__temp;
break;
}
}
}
}
return __first;
}
template <class _CharT, class _Traits>
template <class _ForwardIterator>
_ForwardIterator
basic_regex<_CharT, _Traits>::__parse_QUOTED_CHAR_ERE(_ForwardIterator __first,
_ForwardIterator __last)
{
if (__first != __last)
{
_ForwardIterator __temp = _VSTD::next(__first);
if (__temp != __last)
{
if (*__first == '\\')
{
switch (*__temp)
{
case '^':
case '.':
case '*':
case '[':
case '$':
case '\\':
case '(':
case ')':
case '|':
case '+':
case '?':
case '{':
case '}':
__push_char(*__temp);
__first = ++__temp;
break;
default:
if (__get_grammar(__flags_) == awk)
__first = __parse_awk_escape(++__first, __last);
break;
}
}
}
}
return __first;
}
template <class _CharT, class _Traits>
template <class _ForwardIterator>
_ForwardIterator
basic_regex<_CharT, _Traits>::__parse_RE_dupl_symbol(_ForwardIterator __first,
_ForwardIterator __last,
__owns_one_state<_CharT>* __s,
unsigned __mexp_begin,
unsigned __mexp_end)
{
if (__first != __last)
{
if (*__first == '*')
{
__push_greedy_inf_repeat(0, __s, __mexp_begin, __mexp_end);
++__first;
}
else
{
_ForwardIterator __temp = __parse_Back_open_brace(__first, __last);
if (__temp != __first)
{
int __min = 0;
__first = __temp;
__temp = __parse_DUP_COUNT(__first, __last, __min);
if (__temp == __first)
__throw_regex_error<regex_constants::error_badbrace>();
__first = __temp;
if (__first == __last)
__throw_regex_error<regex_constants::error_brace>();
if (*__first != ',')
{
__temp = __parse_Back_close_brace(__first, __last);
if (__temp == __first)
__throw_regex_error<regex_constants::error_brace>();
__push_loop(__min, __min, __s, __mexp_begin, __mexp_end,
true);
__first = __temp;
}
else
{
++__first; // consume ','
int __max = -1;
__first = __parse_DUP_COUNT(__first, __last, __max);
__temp = __parse_Back_close_brace(__first, __last);
if (__temp == __first)
__throw_regex_error<regex_constants::error_brace>();
if (__max == -1)
__push_greedy_inf_repeat(__min, __s, __mexp_begin, __mexp_end);
else
{
if (__max < __min)
__throw_regex_error<regex_constants::error_badbrace>();
__push_loop(__min, __max, __s, __mexp_begin, __mexp_end,
true);
}
__first = __temp;
}
}
}
}
return __first;
}
template <class _CharT, class _Traits>
template <class _ForwardIterator>
_ForwardIterator
basic_regex<_CharT, _Traits>::__parse_ERE_dupl_symbol(_ForwardIterator __first,
_ForwardIterator __last,
__owns_one_state<_CharT>* __s,
unsigned __mexp_begin,
unsigned __mexp_end)
{
if (__first != __last)
{
unsigned __grammar = __get_grammar(__flags_);
switch (*__first)
{
case '*':
++__first;
if (__grammar == ECMAScript && __first != __last && *__first == '?')
{
++__first;
__push_nongreedy_inf_repeat(0, __s, __mexp_begin, __mexp_end);
}
else
__push_greedy_inf_repeat(0, __s, __mexp_begin, __mexp_end);
break;
case '+':
++__first;
if (__grammar == ECMAScript && __first != __last && *__first == '?')
{
++__first;
__push_nongreedy_inf_repeat(1, __s, __mexp_begin, __mexp_end);
}
else
__push_greedy_inf_repeat(1, __s, __mexp_begin, __mexp_end);
break;
case '?':
++__first;
if (__grammar == ECMAScript && __first != __last && *__first == '?')
{
++__first;
__push_loop(0, 1, __s, __mexp_begin, __mexp_end, false);
}
else
__push_loop(0, 1, __s, __mexp_begin, __mexp_end);
break;
case '{':
{
int __min;
_ForwardIterator __temp = __parse_DUP_COUNT(++__first, __last, __min);
if (__temp == __first)
__throw_regex_error<regex_constants::error_badbrace>();
__first = __temp;
if (__first == __last)
__throw_regex_error<regex_constants::error_brace>();
switch (*__first)
{
case '}':
++__first;
if (__grammar == ECMAScript && __first != __last && *__first == '?')
{
++__first;
__push_loop(__min, __min, __s, __mexp_begin, __mexp_end, false);
}
else
__push_loop(__min, __min, __s, __mexp_begin, __mexp_end);
break;
case ',':
++__first;
if (__first == __last)
__throw_regex_error<regex_constants::error_badbrace>();
if (*__first == '}')
{
++__first;
if (__grammar == ECMAScript && __first != __last && *__first == '?')
{
++__first;
__push_nongreedy_inf_repeat(__min, __s, __mexp_begin, __mexp_end);
}
else
__push_greedy_inf_repeat(__min, __s, __mexp_begin, __mexp_end);
}
else
{
int __max = -1;
__temp = __parse_DUP_COUNT(__first, __last, __max);
if (__temp == __first)
__throw_regex_error<regex_constants::error_brace>();
__first = __temp;
if (__first == __last || *__first != '}')
__throw_regex_error<regex_constants::error_brace>();
++__first;
if (__max < __min)
__throw_regex_error<regex_constants::error_badbrace>();
if (__grammar == ECMAScript && __first != __last && *__first == '?')
{
++__first;
__push_loop(__min, __max, __s, __mexp_begin, __mexp_end, false);
}
else
__push_loop(__min, __max, __s, __mexp_begin, __mexp_end);
}
break;
default:
__throw_regex_error<regex_constants::error_badbrace>();
}
}
break;
}
}
return __first;
}
template <class _CharT, class _Traits>
template <class _ForwardIterator>
_ForwardIterator
basic_regex<_CharT, _Traits>::__parse_bracket_expression(_ForwardIterator __first,
_ForwardIterator __last)
{
if (__first != __last && *__first == '[')
{
++__first;
if (__first == __last)
__throw_regex_error<regex_constants::error_brack>();
bool __negate = false;
if (*__first == '^')
{
++__first;
__negate = true;
}
__bracket_expression<_CharT, _Traits>* __ml = __start_matching_list(__negate);
// __ml owned by *this
if (__first == __last)
__throw_regex_error<regex_constants::error_brack>();
if (__get_grammar(__flags_) != ECMAScript && *__first == ']')
{
__ml->__add_char(']');
++__first;
}
__first = __parse_follow_list(__first, __last, __ml);
if (__first == __last)
__throw_regex_error<regex_constants::error_brack>();
if (*__first == '-')
{
__ml->__add_char('-');
++__first;
}
if (__first == __last || *__first != ']')
__throw_regex_error<regex_constants::error_brack>();
++__first;
}
return __first;
}
template <class _CharT, class _Traits>
template <class _ForwardIterator>
_ForwardIterator
basic_regex<_CharT, _Traits>::__parse_follow_list(_ForwardIterator __first,
_ForwardIterator __last,
__bracket_expression<_CharT, _Traits>* __ml)
{
if (__first != __last)
{
while (true)
{
_ForwardIterator __temp = __parse_expression_term(__first, __last,
__ml);
if (__temp == __first)
break;
__first = __temp;
}
}
return __first;
}
template <class _CharT, class _Traits>
template <class _ForwardIterator>
_ForwardIterator
basic_regex<_CharT, _Traits>::__parse_expression_term(_ForwardIterator __first,
_ForwardIterator __last,
__bracket_expression<_CharT, _Traits>* __ml)
{
if (__first != __last && *__first != ']')
{
_ForwardIterator __temp = _VSTD::next(__first);
basic_string<_CharT> __start_range;
if (__temp != __last && *__first == '[')
{
if (*__temp == '=')
return __parse_equivalence_class(++__temp, __last, __ml);
else if (*__temp == ':')
return __parse_character_class(++__temp, __last, __ml);
else if (*__temp == '.')
__first = __parse_collating_symbol(++__temp, __last, __start_range);
}
unsigned __grammar = __get_grammar(__flags_);
if (__start_range.empty())
{
if ((__grammar == ECMAScript || __grammar == awk) && *__first == '\\')
{
if (__grammar == ECMAScript)
__first = __parse_class_escape(++__first, __last, __start_range, __ml);
else
__first = __parse_awk_escape(++__first, __last, &__start_range);
}
else
{
__start_range = *__first;
++__first;
}
}
if (__first != __last && *__first != ']')
{
__temp = _VSTD::next(__first);
if (__temp != __last && *__first == '-' && *__temp != ']')
{
// parse a range
basic_string<_CharT> __end_range;
__first = __temp;
++__temp;
if (__temp != __last && *__first == '[' && *__temp == '.')
__first = __parse_collating_symbol(++__temp, __last, __end_range);
else
{
if ((__grammar == ECMAScript || __grammar == awk) && *__first == '\\')
{
if (__grammar == ECMAScript)
__first = __parse_class_escape(++__first, __last,
__end_range, __ml);
else
__first = __parse_awk_escape(++__first, __last,
&__end_range);
}
else
{
__end_range = *__first;
++__first;
}
}
__ml->__add_range(_VSTD::move(__start_range), _VSTD::move(__end_range));
}
else if (!__start_range.empty())
{
if (__start_range.size() == 1)
__ml->__add_char(__start_range[0]);
else
__ml->__add_digraph(__start_range[0], __start_range[1]);
}
}
else if (!__start_range.empty())
{
if (__start_range.size() == 1)
__ml->__add_char(__start_range[0]);
else
__ml->__add_digraph(__start_range[0], __start_range[1]);
}
}
return __first;
}
template <class _CharT, class _Traits>
template <class _ForwardIterator>
_ForwardIterator
basic_regex<_CharT, _Traits>::__parse_class_escape(_ForwardIterator __first,
_ForwardIterator __last,
basic_string<_CharT>& __str,
__bracket_expression<_CharT, _Traits>* __ml)
{
if (__first == __last)
__throw_regex_error<regex_constants::error_escape>();
switch (*__first)
{
case 0:
__str = *__first;
return ++__first;
case 'b':
__str = _CharT(8);
return ++__first;
case 'd':
__ml->__add_class(ctype_base::digit);
return ++__first;
case 'D':
__ml->__add_neg_class(ctype_base::digit);
return ++__first;
case 's':
__ml->__add_class(ctype_base::space);
return ++__first;
case 'S':
__ml->__add_neg_class(ctype_base::space);
return ++__first;
case 'w':
__ml->__add_class(ctype_base::alnum);
__ml->__add_char('_');
return ++__first;
case 'W':
__ml->__add_neg_class(ctype_base::alnum);
__ml->__add_neg_char('_');
return ++__first;
}
__first = __parse_character_escape(__first, __last, &__str);
return __first;
}
template <class _CharT, class _Traits>
template <class _ForwardIterator>
_ForwardIterator
basic_regex<_CharT, _Traits>::__parse_awk_escape(_ForwardIterator __first,
_ForwardIterator __last,
basic_string<_CharT>* __str)
{
if (__first == __last)
__throw_regex_error<regex_constants::error_escape>();
switch (*__first)
{
case '\\':
case '"':
case '/':
if (__str)
*__str = *__first;
else
__push_char(*__first);
return ++__first;
case 'a':
if (__str)
*__str = _CharT(7);
else
__push_char(_CharT(7));
return ++__first;
case 'b':
if (__str)
*__str = _CharT(8);
else
__push_char(_CharT(8));
return ++__first;
case 'f':
if (__str)
*__str = _CharT(0xC);
else
__push_char(_CharT(0xC));
return ++__first;
case 'n':
if (__str)
*__str = _CharT(0xA);
else
__push_char(_CharT(0xA));
return ++__first;
case 'r':
if (__str)
*__str = _CharT(0xD);
else
__push_char(_CharT(0xD));
return ++__first;
case 't':
if (__str)
*__str = _CharT(0x9);
else
__push_char(_CharT(0x9));
return ++__first;
case 'v':
if (__str)
*__str = _CharT(0xB);
else
__push_char(_CharT(0xB));
return ++__first;
}
if ('0' <= *__first && *__first <= '7')
{
unsigned __val = *__first - '0';
if (++__first != __last && ('0' <= *__first && *__first <= '7'))
{
__val = 8 * __val + *__first - '0';
if (++__first != __last && ('0' <= *__first && *__first <= '7'))
__val = 8 * __val + *__first++ - '0';
}
if (__str)
*__str = _CharT(__val);
else
__push_char(_CharT(__val));
}
else
__throw_regex_error<regex_constants::error_escape>();
return __first;
}
template <class _CharT, class _Traits>
template <class _ForwardIterator>
_ForwardIterator
basic_regex<_CharT, _Traits>::__parse_equivalence_class(_ForwardIterator __first,
_ForwardIterator __last,
__bracket_expression<_CharT, _Traits>* __ml)
{
// Found [=
// This means =] must exist
value_type _Equal_close[2] = {'=', ']'};
_ForwardIterator __temp = _VSTD::search(__first, __last, _Equal_close,
_Equal_close+2);
if (__temp == __last)
__throw_regex_error<regex_constants::error_brack>();
// [__first, __temp) contains all text in [= ... =]
string_type __collate_name =
__traits_.lookup_collatename(__first, __temp);
if (__collate_name.empty())
__throw_regex_error<regex_constants::error_collate>();
string_type __equiv_name =
__traits_.transform_primary(__collate_name.begin(),
__collate_name.end());
if (!__equiv_name.empty())
__ml->__add_equivalence(__equiv_name);
else
{
switch (__collate_name.size())
{
case 1:
__ml->__add_char(__collate_name[0]);
break;
case 2:
__ml->__add_digraph(__collate_name[0], __collate_name[1]);
break;
default:
__throw_regex_error<regex_constants::error_collate>();
}
}
__first = _VSTD::next(__temp, 2);
return __first;
}
template <class _CharT, class _Traits>
template <class _ForwardIterator>
_ForwardIterator
basic_regex<_CharT, _Traits>::__parse_character_class(_ForwardIterator __first,
_ForwardIterator __last,
__bracket_expression<_CharT, _Traits>* __ml)
{
// Found [:
// This means :] must exist
value_type _Colon_close[2] = {':', ']'};
_ForwardIterator __temp = _VSTD::search(__first, __last, _Colon_close,
_Colon_close+2);
if (__temp == __last)
__throw_regex_error<regex_constants::error_brack>();
// [__first, __temp) contains all text in [: ... :]
typedef typename _Traits::char_class_type char_class_type;
char_class_type __class_type =
__traits_.lookup_classname(__first, __temp, __flags_ & icase);
if (__class_type == 0)
__throw_regex_error<regex_constants::error_ctype>();
__ml->__add_class(__class_type);
__first = _VSTD::next(__temp, 2);
return __first;
}
template <class _CharT, class _Traits>
template <class _ForwardIterator>
_ForwardIterator
basic_regex<_CharT, _Traits>::__parse_collating_symbol(_ForwardIterator __first,
_ForwardIterator __last,
basic_string<_CharT>& __col_sym)
{
// Found [.
// This means .] must exist
value_type _Dot_close[2] = {'.', ']'};
_ForwardIterator __temp = _VSTD::search(__first, __last, _Dot_close,
_Dot_close+2);
if (__temp == __last)
__throw_regex_error<regex_constants::error_brack>();
// [__first, __temp) contains all text in [. ... .]
__col_sym = __traits_.lookup_collatename(__first, __temp);
switch (__col_sym.size())
{
case 1:
case 2:
break;
default:
__throw_regex_error<regex_constants::error_collate>();
}
__first = _VSTD::next(__temp, 2);
return __first;
}
template <class _CharT, class _Traits>
template <class _ForwardIterator>
_ForwardIterator
basic_regex<_CharT, _Traits>::__parse_DUP_COUNT(_ForwardIterator __first,
_ForwardIterator __last,
int& __c)
{
if (__first != __last )
{
int __val = __traits_.value(*__first, 10);
if ( __val != -1 )
{
__c = __val;
for (++__first;
__first != __last && ( __val = __traits_.value(*__first, 10)) != -1;
++__first)
{
if (__c >= std::numeric_limits<int>::max() / 10)
__throw_regex_error<regex_constants::error_badbrace>();
__c *= 10;
__c += __val;
}
}
}
return __first;
}
template <class _CharT, class _Traits>
template <class _ForwardIterator>
_ForwardIterator
basic_regex<_CharT, _Traits>::__parse_ecma_exp(_ForwardIterator __first,
_ForwardIterator __last)
{
__owns_one_state<_CharT>* __sa = __end_;
_ForwardIterator __temp = __parse_alternative(__first, __last);
if (__temp == __first)
__push_empty();
__first = __temp;
while (__first != __last && *__first == '|')
{
__owns_one_state<_CharT>* __sb = __end_;
__temp = __parse_alternative(++__first, __last);
if (__temp == __first)
__push_empty();
__push_alternation(__sa, __sb);
__first = __temp;
}
return __first;
}
template <class _CharT, class _Traits>
template <class _ForwardIterator>
_ForwardIterator
basic_regex<_CharT, _Traits>::__parse_alternative(_ForwardIterator __first,
_ForwardIterator __last)
{
while (true)
{
_ForwardIterator __temp = __parse_term(__first, __last);
if (__temp == __first)
break;
__first = __temp;
}
return __first;
}
template <class _CharT, class _Traits>
template <class _ForwardIterator>
_ForwardIterator
basic_regex<_CharT, _Traits>::__parse_term(_ForwardIterator __first,
_ForwardIterator __last)
{
_ForwardIterator __temp = __parse_assertion(__first, __last);
if (__temp == __first)
{
__owns_one_state<_CharT>* __e = __end_;
unsigned __mexp_begin = __marked_count_;
__temp = __parse_atom(__first, __last);
if (__temp != __first)
__first = __parse_ERE_dupl_symbol(__temp, __last, __e,
__mexp_begin+1, __marked_count_+1);
}
else
__first = __temp;
return __first;
}
template <class _CharT, class _Traits>
template <class _ForwardIterator>
_ForwardIterator
basic_regex<_CharT, _Traits>::__parse_assertion(_ForwardIterator __first,
_ForwardIterator __last)
{
if (__first != __last)
{
switch (*__first)
{
case '^':
__push_l_anchor();
++__first;
break;
case '$':
__push_r_anchor();
++__first;
break;
case '\\':
{
_ForwardIterator __temp = _VSTD::next(__first);
if (__temp != __last)
{
if (*__temp == 'b')
{
__push_word_boundary(false);
__first = ++__temp;
}
else if (*__temp == 'B')
{
__push_word_boundary(true);
__first = ++__temp;
}
}
}
break;
case '(':
{
_ForwardIterator __temp = _VSTD::next(__first);
if (__temp != __last && *__temp == '?')
{
if (++__temp != __last)
{
switch (*__temp)
{
case '=':
{
basic_regex __exp;
__exp.__flags_ = __flags_;
__temp = __exp.__parse(++__temp, __last);
unsigned __mexp = __exp.__marked_count_;
__push_lookahead(_VSTD::move(__exp), false, __marked_count_);
__marked_count_ += __mexp;
if (__temp == __last || *__temp != ')')
__throw_regex_error<regex_constants::error_paren>();
__first = ++__temp;
}
break;
case '!':
{
basic_regex __exp;
__exp.__flags_ = __flags_;
__temp = __exp.__parse(++__temp, __last);
unsigned __mexp = __exp.__marked_count_;
__push_lookahead(_VSTD::move(__exp), true, __marked_count_);
__marked_count_ += __mexp;
if (__temp == __last || *__temp != ')')
__throw_regex_error<regex_constants::error_paren>();
__first = ++__temp;
}
break;
}
}
}
}
break;
}
}
return __first;
}
template <class _CharT, class _Traits>
template <class _ForwardIterator>
_ForwardIterator
basic_regex<_CharT, _Traits>::__parse_atom(_ForwardIterator __first,
_ForwardIterator __last)
{
if (__first != __last)
{
switch (*__first)
{
case '.':
__push_match_any_but_newline();
++__first;
break;
case '\\':
__first = __parse_atom_escape(__first, __last);
break;
case '[':
__first = __parse_bracket_expression(__first, __last);
break;
case '(':
{
++__first;
if (__first == __last)
__throw_regex_error<regex_constants::error_paren>();
_ForwardIterator __temp = _VSTD::next(__first);
if (__temp != __last && *__first == '?' && *__temp == ':')
{
++__open_count_;
__first = __parse_ecma_exp(++__temp, __last);
if (__first == __last || *__first != ')')
__throw_regex_error<regex_constants::error_paren>();
--__open_count_;
++__first;
}
else
{
__push_begin_marked_subexpression();
unsigned __temp_count = __marked_count_;
++__open_count_;
__first = __parse_ecma_exp(__first, __last);
if (__first == __last || *__first != ')')
__throw_regex_error<regex_constants::error_paren>();
__push_end_marked_subexpression(__temp_count);
--__open_count_;
++__first;
}
}
break;
case '*':
case '+':
case '?':
case '{':
__throw_regex_error<regex_constants::error_badrepeat>();
break;
default:
__first = __parse_pattern_character(__first, __last);
break;
}
}
return __first;
}
template <class _CharT, class _Traits>
template <class _ForwardIterator>
_ForwardIterator
basic_regex<_CharT, _Traits>::__parse_atom_escape(_ForwardIterator __first,
_ForwardIterator __last)
{
if (__first != __last && *__first == '\\')
{
_ForwardIterator __t1 = _VSTD::next(__first);
if (__t1 == __last)
__throw_regex_error<regex_constants::error_escape>();
_ForwardIterator __t2 = __parse_decimal_escape(__t1, __last);
if (__t2 != __t1)
__first = __t2;
else
{
__t2 = __parse_character_class_escape(__t1, __last);
if (__t2 != __t1)
__first = __t2;
else
{
__t2 = __parse_character_escape(__t1, __last);
if (__t2 != __t1)
__first = __t2;
}
}
}
return __first;
}
template <class _CharT, class _Traits>
template <class _ForwardIterator>
_ForwardIterator
basic_regex<_CharT, _Traits>::__parse_decimal_escape(_ForwardIterator __first,
_ForwardIterator __last)
{
if (__first != __last)
{
if (*__first == '0')
{
__push_char(_CharT());
++__first;
}
else if ('1' <= *__first && *__first <= '9')
{
unsigned __v = *__first - '0';
for (++__first;
__first != __last && '0' <= *__first && *__first <= '9'; ++__first)
{
if (__v >= std::numeric_limits<unsigned>::max() / 10)
__throw_regex_error<regex_constants::error_backref>();
__v = 10 * __v + *__first - '0';
}
if (__v == 0 || __v > mark_count())
__throw_regex_error<regex_constants::error_backref>();
__push_back_ref(__v);
}
}
return __first;
}
template <class _CharT, class _Traits>
template <class _ForwardIterator>
_ForwardIterator
basic_regex<_CharT, _Traits>::__parse_character_class_escape(_ForwardIterator __first,
_ForwardIterator __last)
{
if (__first != __last)
{
__bracket_expression<_CharT, _Traits>* __ml;
switch (*__first)
{
case 'd':
__ml = __start_matching_list(false);
__ml->__add_class(ctype_base::digit);
++__first;
break;
case 'D':
__ml = __start_matching_list(true);
__ml->__add_class(ctype_base::digit);
++__first;
break;
case 's':
__ml = __start_matching_list(false);
__ml->__add_class(ctype_base::space);
++__first;
break;
case 'S':
__ml = __start_matching_list(true);
__ml->__add_class(ctype_base::space);
++__first;
break;
case 'w':
__ml = __start_matching_list(false);
__ml->__add_class(ctype_base::alnum);
__ml->__add_char('_');
++__first;
break;
case 'W':
__ml = __start_matching_list(true);
__ml->__add_class(ctype_base::alnum);
__ml->__add_char('_');
++__first;
break;
}
}
return __first;
}
template <class _CharT, class _Traits>
template <class _ForwardIterator>
_ForwardIterator
basic_regex<_CharT, _Traits>::__parse_character_escape(_ForwardIterator __first,
_ForwardIterator __last,
basic_string<_CharT>* __str)
{
if (__first != __last)
{
_ForwardIterator __t;
unsigned __sum = 0;
int __hd;
switch (*__first)
{
case 'f':
if (__str)
*__str = _CharT(0xC);
else
__push_char(_CharT(0xC));
++__first;
break;
case 'n':
if (__str)
*__str = _CharT(0xA);
else
__push_char(_CharT(0xA));
++__first;
break;
case 'r':
if (__str)
*__str = _CharT(0xD);
else
__push_char(_CharT(0xD));
++__first;
break;
case 't':
if (__str)
*__str = _CharT(0x9);
else
__push_char(_CharT(0x9));
++__first;
break;
case 'v':
if (__str)
*__str = _CharT(0xB);
else
__push_char(_CharT(0xB));
++__first;
break;
case 'c':
if ((__t = _VSTD::next(__first)) != __last)
{
if (('A' <= *__t && *__t <= 'Z') ||
('a' <= *__t && *__t <= 'z'))
{
if (__str)
*__str = _CharT(*__t % 32);
else
__push_char(_CharT(*__t % 32));
__first = ++__t;
}
else
__throw_regex_error<regex_constants::error_escape>();
}
else
__throw_regex_error<regex_constants::error_escape>();
break;
case 'u':
++__first;
if (__first == __last)
__throw_regex_error<regex_constants::error_escape>();
__hd = __traits_.value(*__first, 16);
if (__hd == -1)
__throw_regex_error<regex_constants::error_escape>();
__sum = 16 * __sum + static_cast<unsigned>(__hd);
++__first;
if (__first == __last)
__throw_regex_error<regex_constants::error_escape>();
__hd = __traits_.value(*__first, 16);
if (__hd == -1)
__throw_regex_error<regex_constants::error_escape>();
__sum = 16 * __sum + static_cast<unsigned>(__hd);
// drop through
case 'x':
++__first;
if (__first == __last)
__throw_regex_error<regex_constants::error_escape>();
__hd = __traits_.value(*__first, 16);
if (__hd == -1)
__throw_regex_error<regex_constants::error_escape>();
__sum = 16 * __sum + static_cast<unsigned>(__hd);
++__first;
if (__first == __last)
__throw_regex_error<regex_constants::error_escape>();
__hd = __traits_.value(*__first, 16);
if (__hd == -1)
__throw_regex_error<regex_constants::error_escape>();
__sum = 16 * __sum + static_cast<unsigned>(__hd);
if (__str)
*__str = _CharT(__sum);
else
__push_char(_CharT(__sum));
++__first;
break;
case '0':
if (__str)
*__str = _CharT(0);
else
__push_char(_CharT(0));
++__first;
break;
default:
if (*__first != '_' && !__traits_.isctype(*__first, ctype_base::alnum))
{
if (__str)
*__str = *__first;
else
__push_char(*__first);
++__first;
}
else
__throw_regex_error<regex_constants::error_escape>();
break;
}
}
return __first;
}
template <class _CharT, class _Traits>
template <class _ForwardIterator>
_ForwardIterator
basic_regex<_CharT, _Traits>::__parse_pattern_character(_ForwardIterator __first,
_ForwardIterator __last)
{
if (__first != __last)
{
switch (*__first)
{
case '^':
case '$':
case '\\':
case '.':
case '*':
case '+':
case '?':
case '(':
case ')':
case '[':
case ']':
case '{':
case '}':
case '|':
break;
default:
__push_char(*__first);
++__first;
break;
}
}
return __first;
}
template <class _CharT, class _Traits>
template <class _ForwardIterator>
_ForwardIterator
basic_regex<_CharT, _Traits>::__parse_grep(_ForwardIterator __first,
_ForwardIterator __last)
{
__owns_one_state<_CharT>* __sa = __end_;
_ForwardIterator __t1 = _VSTD::find(__first, __last, _CharT('\n'));
if (__t1 != __first)
__parse_basic_reg_exp(__first, __t1);
else
__push_empty();
__first = __t1;
if (__first != __last)
++__first;
while (__first != __last)
{
__t1 = _VSTD::find(__first, __last, _CharT('\n'));
__owns_one_state<_CharT>* __sb = __end_;
if (__t1 != __first)
__parse_basic_reg_exp(__first, __t1);
else
__push_empty();
__push_alternation(__sa, __sb);
__first = __t1;
if (__first != __last)
++__first;
}
return __first;
}
template <class _CharT, class _Traits>
template <class _ForwardIterator>
_ForwardIterator
basic_regex<_CharT, _Traits>::__parse_egrep(_ForwardIterator __first,
_ForwardIterator __last)
{
__owns_one_state<_CharT>* __sa = __end_;
_ForwardIterator __t1 = _VSTD::find(__first, __last, _CharT('\n'));
if (__t1 != __first)
__parse_extended_reg_exp(__first, __t1);
else
__push_empty();
__first = __t1;
if (__first != __last)
++__first;
while (__first != __last)
{
__t1 = _VSTD::find(__first, __last, _CharT('\n'));
__owns_one_state<_CharT>* __sb = __end_;
if (__t1 != __first)
__parse_extended_reg_exp(__first, __t1);
else
__push_empty();
__push_alternation(__sa, __sb);
__first = __t1;
if (__first != __last)
++__first;
}
return __first;
}
template <class _CharT, class _Traits>
void
basic_regex<_CharT, _Traits>::__push_loop(size_t __min, size_t __max,
__owns_one_state<_CharT>* __s, size_t __mexp_begin, size_t __mexp_end,
bool __greedy)
{
unique_ptr<__empty_state<_CharT> > __e1(new __empty_state<_CharT>(__end_->first()));
__end_->first() = nullptr;
unique_ptr<__loop<_CharT> > __e2(new __loop<_CharT>(__loop_count_,
__s->first(), __e1.get(), __mexp_begin, __mexp_end, __greedy,
__min, __max));
__s->first() = nullptr;
__e1.release();
__end_->first() = new __repeat_one_loop<_CharT>(__e2.get());
__end_ = __e2->second();
__s->first() = __e2.release();
++__loop_count_;
}
template <class _CharT, class _Traits>
void
basic_regex<_CharT, _Traits>::__push_char(value_type __c)
{
if (flags() & icase)
__end_->first() = new __match_char_icase<_CharT, _Traits>
(__traits_, __c, __end_->first());
else if (flags() & collate)
__end_->first() = new __match_char_collate<_CharT, _Traits>
(__traits_, __c, __end_->first());
else
__end_->first() = new __match_char<_CharT>(__c, __end_->first());
__end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first());
}
template <class _CharT, class _Traits>
void
basic_regex<_CharT, _Traits>::__push_begin_marked_subexpression()
{
if (!(__flags_ & nosubs))
{
__end_->first() =
new __begin_marked_subexpression<_CharT>(++__marked_count_,
__end_->first());
__end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first());
}
}
template <class _CharT, class _Traits>
void
basic_regex<_CharT, _Traits>::__push_end_marked_subexpression(unsigned __sub)
{
if (!(__flags_ & nosubs))
{
__end_->first() =
new __end_marked_subexpression<_CharT>(__sub, __end_->first());
__end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first());
}
}
template <class _CharT, class _Traits>
void
basic_regex<_CharT, _Traits>::__push_l_anchor()
{
__end_->first() = new __l_anchor<_CharT>(__end_->first());
__end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first());
}
template <class _CharT, class _Traits>
void
basic_regex<_CharT, _Traits>::__push_r_anchor()
{
__end_->first() = new __r_anchor<_CharT>(__end_->first());
__end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first());
}
template <class _CharT, class _Traits>
void
basic_regex<_CharT, _Traits>::__push_match_any()
{
__end_->first() = new __match_any<_CharT>(__end_->first());
__end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first());
}
template <class _CharT, class _Traits>
void
basic_regex<_CharT, _Traits>::__push_match_any_but_newline()
{
__end_->first() = new __match_any_but_newline<_CharT>(__end_->first());
__end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first());
}
template <class _CharT, class _Traits>
void
basic_regex<_CharT, _Traits>::__push_empty()
{
__end_->first() = new __empty_state<_CharT>(__end_->first());
__end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first());
}
template <class _CharT, class _Traits>
void
basic_regex<_CharT, _Traits>::__push_word_boundary(bool __invert)
{
__end_->first() = new __word_boundary<_CharT, _Traits>(__traits_, __invert,
__end_->first());
__end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first());
}
template <class _CharT, class _Traits>
void
basic_regex<_CharT, _Traits>::__push_back_ref(int __i)
{
if (flags() & icase)
__end_->first() = new __back_ref_icase<_CharT, _Traits>
(__traits_, __i, __end_->first());
else if (flags() & collate)
__end_->first() = new __back_ref_collate<_CharT, _Traits>
(__traits_, __i, __end_->first());
else
__end_->first() = new __back_ref<_CharT>(__i, __end_->first());
__end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first());
}
template <class _CharT, class _Traits>
void
basic_regex<_CharT, _Traits>::__push_alternation(__owns_one_state<_CharT>* __sa,
__owns_one_state<_CharT>* __ea)
{
__sa->first() = new __alternate<_CharT>(
static_cast<__owns_one_state<_CharT>*>(__sa->first()),
static_cast<__owns_one_state<_CharT>*>(__ea->first()));
__ea->first() = nullptr;
__ea->first() = new __empty_state<_CharT>(__end_->first());
__end_->first() = nullptr;
__end_->first() = new __empty_non_own_state<_CharT>(__ea->first());
__end_ = static_cast<__owns_one_state<_CharT>*>(__ea->first());
}
template <class _CharT, class _Traits>
__bracket_expression<_CharT, _Traits>*
basic_regex<_CharT, _Traits>::__start_matching_list(bool __negate)
{
__bracket_expression<_CharT, _Traits>* __r =
new __bracket_expression<_CharT, _Traits>(__traits_, __end_->first(),
__negate, __flags_ & icase,
__flags_ & collate);
__end_->first() = __r;
__end_ = __r;
return __r;
}
template <class _CharT, class _Traits>
void
basic_regex<_CharT, _Traits>::__push_lookahead(const basic_regex& __exp,
bool __invert,
unsigned __mexp)
{
__end_->first() = new __lookahead<_CharT, _Traits>(__exp, __invert,
__end_->first(), __mexp);
__end_ = static_cast<__owns_one_state<_CharT>*>(__end_->first());
}
typedef basic_regex<char> regex;
typedef basic_regex<wchar_t> wregex;
// sub_match
template <class _BidirectionalIterator>
class _LIBCPP_TEMPLATE_VIS sub_match
: public pair<_BidirectionalIterator, _BidirectionalIterator>
{
public:
typedef _BidirectionalIterator iterator;
typedef typename iterator_traits<iterator>::value_type value_type;
typedef typename iterator_traits<iterator>::difference_type difference_type;
typedef basic_string<value_type> string_type;
bool matched;
_LIBCPP_INLINE_VISIBILITY
_LIBCPP_CONSTEXPR sub_match() : matched() {}
_LIBCPP_INLINE_VISIBILITY
difference_type length() const
{return matched ? _VSTD::distance(this->first, this->second) : 0;}
_LIBCPP_INLINE_VISIBILITY
string_type str() const
{return matched ? string_type(this->first, this->second) : string_type();}
_LIBCPP_INLINE_VISIBILITY
operator string_type() const
{return str();}
_LIBCPP_INLINE_VISIBILITY
int compare(const sub_match& __s) const
{return str().compare(__s.str());}
_LIBCPP_INLINE_VISIBILITY
int compare(const string_type& __s) const
{return str().compare(__s);}
_LIBCPP_INLINE_VISIBILITY
int compare(const value_type* __s) const
{return str().compare(__s);}
};
typedef sub_match<const char*> csub_match;
typedef sub_match<const wchar_t*> wcsub_match;
typedef sub_match<string::const_iterator> ssub_match;
typedef sub_match<wstring::const_iterator> wssub_match;
template <class _BiIter>
inline _LIBCPP_INLINE_VISIBILITY
bool
operator==(const sub_match<_BiIter>& __x, const sub_match<_BiIter>& __y)
{
return __x.compare(__y) == 0;
}
template <class _BiIter>
inline _LIBCPP_INLINE_VISIBILITY
bool
operator!=(const sub_match<_BiIter>& __x, const sub_match<_BiIter>& __y)
{
return !(__x == __y);
}
template <class _BiIter>
inline _LIBCPP_INLINE_VISIBILITY
bool
operator<(const sub_match<_BiIter>& __x, const sub_match<_BiIter>& __y)
{
return __x.compare(__y) < 0;
}
template <class _BiIter>
inline _LIBCPP_INLINE_VISIBILITY
bool
operator<=(const sub_match<_BiIter>& __x, const sub_match<_BiIter>& __y)
{
return !(__y < __x);
}
template <class _BiIter>
inline _LIBCPP_INLINE_VISIBILITY
bool
operator>=(const sub_match<_BiIter>& __x, const sub_match<_BiIter>& __y)
{
return !(__x < __y);
}
template <class _BiIter>
inline _LIBCPP_INLINE_VISIBILITY
bool
operator>(const sub_match<_BiIter>& __x, const sub_match<_BiIter>& __y)
{
return __y < __x;
}
template <class _BiIter, class _ST, class _SA>
inline _LIBCPP_INLINE_VISIBILITY
bool
operator==(const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __x,
const sub_match<_BiIter>& __y)
{
return __y.compare(typename sub_match<_BiIter>::string_type(__x.data(), __x.size())) == 0;
}
template <class _BiIter, class _ST, class _SA>
inline _LIBCPP_INLINE_VISIBILITY
bool
operator!=(const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __x,
const sub_match<_BiIter>& __y)
{
return !(__x == __y);
}
template <class _BiIter, class _ST, class _SA>
inline _LIBCPP_INLINE_VISIBILITY
bool
operator<(const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __x,
const sub_match<_BiIter>& __y)
{
return __y.compare(typename sub_match<_BiIter>::string_type(__x.data(), __x.size())) > 0;
}
template <class _BiIter, class _ST, class _SA>
inline _LIBCPP_INLINE_VISIBILITY
bool
operator>(const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __x,
const sub_match<_BiIter>& __y)
{
return __y < __x;
}
template <class _BiIter, class _ST, class _SA>
inline _LIBCPP_INLINE_VISIBILITY
bool operator>=(const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __x,
const sub_match<_BiIter>& __y)
{
return !(__x < __y);
}
template <class _BiIter, class _ST, class _SA>
inline _LIBCPP_INLINE_VISIBILITY
bool
operator<=(const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __x,
const sub_match<_BiIter>& __y)
{
return !(__y < __x);
}
template <class _BiIter, class _ST, class _SA>
inline _LIBCPP_INLINE_VISIBILITY
bool
operator==(const sub_match<_BiIter>& __x,
const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __y)
{
return __x.compare(typename sub_match<_BiIter>::string_type(__y.data(), __y.size())) == 0;
}
template <class _BiIter, class _ST, class _SA>
inline _LIBCPP_INLINE_VISIBILITY
bool
operator!=(const sub_match<_BiIter>& __x,
const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __y)
{
return !(__x == __y);
}
template <class _BiIter, class _ST, class _SA>
inline _LIBCPP_INLINE_VISIBILITY
bool
operator<(const sub_match<_BiIter>& __x,
const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __y)
{
return __x.compare(typename sub_match<_BiIter>::string_type(__y.data(), __y.size())) < 0;
}
template <class _BiIter, class _ST, class _SA>
inline _LIBCPP_INLINE_VISIBILITY
bool operator>(const sub_match<_BiIter>& __x,
const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __y)
{
return __y < __x;
}
template <class _BiIter, class _ST, class _SA>
inline _LIBCPP_INLINE_VISIBILITY
bool
operator>=(const sub_match<_BiIter>& __x,
const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __y)
{
return !(__x < __y);
}
template <class _BiIter, class _ST, class _SA>
inline _LIBCPP_INLINE_VISIBILITY
bool
operator<=(const sub_match<_BiIter>& __x,
const basic_string<typename iterator_traits<_BiIter>::value_type, _ST, _SA>& __y)
{
return !(__y < __x);
}
template <class _BiIter>
inline _LIBCPP_INLINE_VISIBILITY
bool
operator==(typename iterator_traits<_BiIter>::value_type const* __x,
const sub_match<_BiIter>& __y)
{
return __y.compare(__x) == 0;
}
template <class _BiIter>
inline _LIBCPP_INLINE_VISIBILITY
bool
operator!=(typename iterator_traits<_BiIter>::value_type const* __x,
const sub_match<_BiIter>& __y)
{
return !(__x == __y);
}
template <class _BiIter>
inline _LIBCPP_INLINE_VISIBILITY
bool
operator<(typename iterator_traits<_BiIter>::value_type const* __x,
const sub_match<_BiIter>& __y)
{
return __y.compare(__x) > 0;
}
template <class _BiIter>
inline _LIBCPP_INLINE_VISIBILITY
bool
operator>(typename iterator_traits<_BiIter>::value_type const* __x,
const sub_match<_BiIter>& __y)
{
return __y < __x;
}
template <class _BiIter>
inline _LIBCPP_INLINE_VISIBILITY
bool
operator>=(typename iterator_traits<_BiIter>::value_type const* __x,
const sub_match<_BiIter>& __y)
{
return !(__x < __y);
}
template <class _BiIter>
inline _LIBCPP_INLINE_VISIBILITY
bool
operator<=(typename iterator_traits<_BiIter>::value_type const* __x,
const sub_match<_BiIter>& __y)
{
return !(__y < __x);
}
template <class _BiIter>
inline _LIBCPP_INLINE_VISIBILITY
bool
operator==(const sub_match<_BiIter>& __x,
typename iterator_traits<_BiIter>::value_type const* __y)
{
return __x.compare(__y) == 0;
}
template <class _BiIter>
inline _LIBCPP_INLINE_VISIBILITY
bool
operator!=(const sub_match<_BiIter>& __x,
typename iterator_traits<_BiIter>::value_type const* __y)
{
return !(__x == __y);
}
template <class _BiIter>
inline _LIBCPP_INLINE_VISIBILITY
bool
operator<(const sub_match<_BiIter>& __x,
typename iterator_traits<_BiIter>::value_type const* __y)
{
return __x.compare(__y) < 0;
}
template <class _BiIter>
inline _LIBCPP_INLINE_VISIBILITY
bool
operator>(const sub_match<_BiIter>& __x,
typename iterator_traits<_BiIter>::value_type const* __y)
{
return __y < __x;
}
template <class _BiIter>
inline _LIBCPP_INLINE_VISIBILITY
bool
operator>=(const sub_match<_BiIter>& __x,
typename iterator_traits<_BiIter>::value_type const* __y)
{
return !(__x < __y);
}
template <class _BiIter>
inline _LIBCPP_INLINE_VISIBILITY
bool
operator<=(const sub_match<_BiIter>& __x,
typename iterator_traits<_BiIter>::value_type const* __y)
{
return !(__y < __x);
}
template <class _BiIter>
inline _LIBCPP_INLINE_VISIBILITY
bool
operator==(typename iterator_traits<_BiIter>::value_type const& __x,
const sub_match<_BiIter>& __y)
{
typedef basic_string<typename iterator_traits<_BiIter>::value_type> string_type;
return __y.compare(string_type(1, __x)) == 0;
}
template <class _BiIter>
inline _LIBCPP_INLINE_VISIBILITY
bool
operator!=(typename iterator_traits<_BiIter>::value_type const& __x,
const sub_match<_BiIter>& __y)
{
return !(__x == __y);
}
template <class _BiIter>
inline _LIBCPP_INLINE_VISIBILITY
bool
operator<(typename iterator_traits<_BiIter>::value_type const& __x,
const sub_match<_BiIter>& __y)
{
typedef basic_string<typename iterator_traits<_BiIter>::value_type> string_type;
return __y.compare(string_type(1, __x)) > 0;
}
template <class _BiIter>
inline _LIBCPP_INLINE_VISIBILITY
bool
operator>(typename iterator_traits<_BiIter>::value_type const& __x,
const sub_match<_BiIter>& __y)
{
return __y < __x;
}
template <class _BiIter>
inline _LIBCPP_INLINE_VISIBILITY
bool
operator>=(typename iterator_traits<_BiIter>::value_type const& __x,
const sub_match<_BiIter>& __y)
{
return !(__x < __y);
}
template <class _BiIter>
inline _LIBCPP_INLINE_VISIBILITY
bool
operator<=(typename iterator_traits<_BiIter>::value_type const& __x,
const sub_match<_BiIter>& __y)
{
return !(__y < __x);
}
template <class _BiIter>
inline _LIBCPP_INLINE_VISIBILITY
bool
operator==(const sub_match<_BiIter>& __x,
typename iterator_traits<_BiIter>::value_type const& __y)
{
typedef basic_string<typename iterator_traits<_BiIter>::value_type> string_type;
return __x.compare(string_type(1, __y)) == 0;
}
template <class _BiIter>
inline _LIBCPP_INLINE_VISIBILITY
bool
operator!=(const sub_match<_BiIter>& __x,
typename iterator_traits<_BiIter>::value_type const& __y)
{
return !(__x == __y);
}
template <class _BiIter>
inline _LIBCPP_INLINE_VISIBILITY
bool
operator<(const sub_match<_BiIter>& __x,
typename iterator_traits<_BiIter>::value_type const& __y)
{
typedef basic_string<typename iterator_traits<_BiIter>::value_type> string_type;
return __x.compare(string_type(1, __y)) < 0;
}
template <class _BiIter>
inline _LIBCPP_INLINE_VISIBILITY
bool
operator>(const sub_match<_BiIter>& __x,
typename iterator_traits<_BiIter>::value_type const& __y)
{
return __y < __x;
}
template <class _BiIter>
inline _LIBCPP_INLINE_VISIBILITY
bool
operator>=(const sub_match<_BiIter>& __x,
typename iterator_traits<_BiIter>::value_type const& __y)
{
return !(__x < __y);
}
template <class _BiIter>
inline _LIBCPP_INLINE_VISIBILITY
bool
operator<=(const sub_match<_BiIter>& __x,
typename iterator_traits<_BiIter>::value_type const& __y)
{
return !(__y < __x);
}
template <class _CharT, class _ST, class _BiIter>
inline _LIBCPP_INLINE_VISIBILITY
basic_ostream<_CharT, _ST>&
operator<<(basic_ostream<_CharT, _ST>& __os, const sub_match<_BiIter>& __m)
{
return __os << __m.str();
}
template <class _BidirectionalIterator, class _Allocator>
class _LIBCPP_TEMPLATE_VIS match_results
{
public:
typedef _Allocator allocator_type;
typedef sub_match<_BidirectionalIterator> value_type;
private:
typedef vector<value_type, allocator_type> __container_type;
__container_type __matches_;
value_type __unmatched_;
value_type __prefix_;
value_type __suffix_;
bool __ready_;
public:
_BidirectionalIterator __position_start_;
typedef const value_type& const_reference;
typedef value_type& reference;
typedef typename __container_type::const_iterator const_iterator;
typedef const_iterator iterator;
typedef typename iterator_traits<_BidirectionalIterator>::difference_type difference_type;
typedef typename allocator_traits<allocator_type>::size_type size_type;
typedef typename iterator_traits<_BidirectionalIterator>::value_type char_type;
typedef basic_string<char_type> string_type;
// construct/copy/destroy:
explicit match_results(const allocator_type& __a = allocator_type());
// match_results(const match_results&) = default;
// match_results& operator=(const match_results&) = default;
// match_results(match_results&& __m) = default;
// match_results& operator=(match_results&& __m) = default;
// ~match_results() = default;
_LIBCPP_INLINE_VISIBILITY
bool ready() const {return __ready_;}
// size:
_LIBCPP_INLINE_VISIBILITY
size_type size() const _NOEXCEPT {return __matches_.size();}
_LIBCPP_INLINE_VISIBILITY
size_type max_size() const _NOEXCEPT {return __matches_.max_size();}
_LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
bool empty() const _NOEXCEPT {return size() == 0;}
// element access:
_LIBCPP_INLINE_VISIBILITY
difference_type length(size_type __sub = 0) const
{
_LIBCPP_ASSERT(ready(), "match_results::length() called when not ready");
return (*this)[__sub].length();
}
_LIBCPP_INLINE_VISIBILITY
difference_type position(size_type __sub = 0) const
{
_LIBCPP_ASSERT(ready(), "match_results::position() called when not ready");
return _VSTD::distance(__position_start_, (*this)[__sub].first);
}
_LIBCPP_INLINE_VISIBILITY
string_type str(size_type __sub = 0) const
{
_LIBCPP_ASSERT(ready(), "match_results::str() called when not ready");
return (*this)[__sub].str();
}
_LIBCPP_INLINE_VISIBILITY
const_reference operator[](size_type __n) const
{
_LIBCPP_ASSERT(ready(), "match_results::operator[]() called when not ready");
return __n < __matches_.size() ? __matches_[__n] : __unmatched_;
}
_LIBCPP_INLINE_VISIBILITY
const_reference prefix() const
{
_LIBCPP_ASSERT(ready(), "match_results::prefix() called when not ready");
return __prefix_;
}
_LIBCPP_INLINE_VISIBILITY
const_reference suffix() const
{
_LIBCPP_ASSERT(ready(), "match_results::suffix() called when not ready");
return __suffix_;
}
_LIBCPP_INLINE_VISIBILITY
const_iterator begin() const {return empty() ? __matches_.end() : __matches_.begin();}
_LIBCPP_INLINE_VISIBILITY
const_iterator end() const {return __matches_.end();}
_LIBCPP_INLINE_VISIBILITY
const_iterator cbegin() const {return empty() ? __matches_.end() : __matches_.begin();}
_LIBCPP_INLINE_VISIBILITY
const_iterator cend() const {return __matches_.end();}
// format:
template <class _OutputIter>
_OutputIter
format(_OutputIter __output_iter, const char_type* __fmt_first,
const char_type* __fmt_last,
regex_constants::match_flag_type __flags = regex_constants::format_default) const;
template <class _OutputIter, class _ST, class _SA>
_LIBCPP_INLINE_VISIBILITY
_OutputIter
format(_OutputIter __output_iter, const basic_string<char_type, _ST, _SA>& __fmt,
regex_constants::match_flag_type __flags = regex_constants::format_default) const
{return format(__output_iter, __fmt.data(), __fmt.data() + __fmt.size(), __flags);}
template <class _ST, class _SA>
_LIBCPP_INLINE_VISIBILITY
basic_string<char_type, _ST, _SA>
format(const basic_string<char_type, _ST, _SA>& __fmt,
regex_constants::match_flag_type __flags = regex_constants::format_default) const
{
basic_string<char_type, _ST, _SA> __r;
format(back_inserter(__r), __fmt.data(), __fmt.data() + __fmt.size(),
__flags);
return __r;
}
_LIBCPP_INLINE_VISIBILITY
string_type
format(const char_type* __fmt,
regex_constants::match_flag_type __flags = regex_constants::format_default) const
{
string_type __r;
format(back_inserter(__r), __fmt,
__fmt + char_traits<char_type>::length(__fmt), __flags);
return __r;
}
// allocator:
_LIBCPP_INLINE_VISIBILITY
allocator_type get_allocator() const {return __matches_.get_allocator();}
// swap:
void swap(match_results& __m);
template <class _Bp, class _Ap>
_LIBCPP_INLINE_VISIBILITY
void __assign(_BidirectionalIterator __f, _BidirectionalIterator __l,
const match_results<_Bp, _Ap>& __m, bool __no_update_pos)
{
_Bp __mf = __m.prefix().first;
__matches_.resize(__m.size());
for (size_type __i = 0; __i < __matches_.size(); ++__i)
{
__matches_[__i].first = _VSTD::next(__f, _VSTD::distance(__mf, __m[__i].first));
__matches_[__i].second = _VSTD::next(__f, _VSTD::distance(__mf, __m[__i].second));
__matches_[__i].matched = __m[__i].matched;
}
__unmatched_.first = __l;
__unmatched_.second = __l;
__unmatched_.matched = false;
__prefix_.first = _VSTD::next(__f, _VSTD::distance(__mf, __m.prefix().first));
__prefix_.second = _VSTD::next(__f, _VSTD::distance(__mf, __m.prefix().second));
__prefix_.matched = __m.prefix().matched;
__suffix_.first = _VSTD::next(__f, _VSTD::distance(__mf, __m.suffix().first));
__suffix_.second = _VSTD::next(__f, _VSTD::distance(__mf, __m.suffix().second));
__suffix_.matched = __m.suffix().matched;
if (!__no_update_pos)
__position_start_ = __prefix_.first;
__ready_ = __m.ready();
}
private:
void __init(unsigned __s,
_BidirectionalIterator __f, _BidirectionalIterator __l,
bool __no_update_pos = false);
template <class, class> friend class basic_regex;
template <class _Bp, class _Ap, class _Cp, class _Tp>
friend
bool
regex_match(_Bp, _Bp, match_results<_Bp, _Ap>&, const basic_regex<_Cp, _Tp>&,
regex_constants::match_flag_type);
template <class _Bp, class _Ap>
friend
bool
operator==(const match_results<_Bp, _Ap>&, const match_results<_Bp, _Ap>&);
template <class, class> friend class __lookahead;
};
template <class _BidirectionalIterator, class _Allocator>
match_results<_BidirectionalIterator, _Allocator>::match_results(
const allocator_type& __a)
: __matches_(__a),
__unmatched_(),
__prefix_(),
__suffix_(),
__ready_(false),
__position_start_()
{
}
template <class _BidirectionalIterator, class _Allocator>
void
match_results<_BidirectionalIterator, _Allocator>::__init(unsigned __s,
_BidirectionalIterator __f, _BidirectionalIterator __l,
bool __no_update_pos)
{
__unmatched_.first = __l;
__unmatched_.second = __l;
__unmatched_.matched = false;
__matches_.assign(__s, __unmatched_);
__prefix_.first = __f;
__prefix_.second = __f;
__prefix_.matched = false;
__suffix_ = __unmatched_;
if (!__no_update_pos)
__position_start_ = __prefix_.first;
__ready_ = true;
}
template <class _BidirectionalIterator, class _Allocator>
template <class _OutputIter>
_OutputIter
match_results<_BidirectionalIterator, _Allocator>::format(_OutputIter __output_iter,
const char_type* __fmt_first, const char_type* __fmt_last,
regex_constants::match_flag_type __flags) const
{
_LIBCPP_ASSERT(ready(), "match_results::format() called when not ready");
if (__flags & regex_constants::format_sed)
{
for (; __fmt_first != __fmt_last; ++__fmt_first)
{
if (*__fmt_first == '&')
__output_iter = _VSTD::copy(__matches_[0].first, __matches_[0].second,
__output_iter);
else if (*__fmt_first == '\\' && __fmt_first + 1 != __fmt_last)
{
++__fmt_first;
if ('0' <= *__fmt_first && *__fmt_first <= '9')
{
size_t __i = *__fmt_first - '0';
__output_iter = _VSTD::copy((*this)[__i].first,
(*this)[__i].second, __output_iter);
}
else
{
*__output_iter = *__fmt_first;
++__output_iter;
}
}
else
{
*__output_iter = *__fmt_first;
++__output_iter;
}
}
}
else
{
for (; __fmt_first != __fmt_last; ++__fmt_first)
{
if (*__fmt_first == '$' && __fmt_first + 1 != __fmt_last)
{
switch (__fmt_first[1])
{
case '$':
*__output_iter = *++__fmt_first;
++__output_iter;
break;
case '&':
++__fmt_first;
__output_iter = _VSTD::copy(__matches_[0].first, __matches_[0].second,
__output_iter);
break;
case '`':
++__fmt_first;
__output_iter = _VSTD::copy(__prefix_.first, __prefix_.second, __output_iter);
break;
case '\'':
++__fmt_first;
__output_iter = _VSTD::copy(__suffix_.first, __suffix_.second, __output_iter);
break;
default:
if ('0' <= __fmt_first[1] && __fmt_first[1] <= '9')
{
++__fmt_first;
size_t __idx = *__fmt_first - '0';
if (__fmt_first + 1 != __fmt_last &&
'0' <= __fmt_first[1] && __fmt_first[1] <= '9')
{
++__fmt_first;
if (__idx >= std::numeric_limits<size_t>::max() / 10)
__throw_regex_error<regex_constants::error_escape>();
__idx = 10 * __idx + *__fmt_first - '0';
}
__output_iter = _VSTD::copy((*this)[__idx].first,
(*this)[__idx].second, __output_iter);
}
else
{
*__output_iter = *__fmt_first;
++__output_iter;
}
break;
}
}
else
{
*__output_iter = *__fmt_first;
++__output_iter;
}
}
}
return __output_iter;
}
template <class _BidirectionalIterator, class _Allocator>
void
match_results<_BidirectionalIterator, _Allocator>::swap(match_results& __m)
{
using _VSTD::swap;
swap(__matches_, __m.__matches_);
swap(__unmatched_, __m.__unmatched_);
swap(__prefix_, __m.__prefix_);
swap(__suffix_, __m.__suffix_);
swap(__position_start_, __m.__position_start_);
swap(__ready_, __m.__ready_);
}
typedef match_results<const char*> cmatch;
typedef match_results<const wchar_t*> wcmatch;
typedef match_results<string::const_iterator> smatch;
typedef match_results<wstring::const_iterator> wsmatch;
template <class _BidirectionalIterator, class _Allocator>
bool
operator==(const match_results<_BidirectionalIterator, _Allocator>& __x,
const match_results<_BidirectionalIterator, _Allocator>& __y)
{
if (__x.__ready_ != __y.__ready_)
return false;
if (!__x.__ready_)
return true;
return __x.__matches_ == __y.__matches_ &&
__x.__prefix_ == __y.__prefix_ &&
__x.__suffix_ == __y.__suffix_;
}
template <class _BidirectionalIterator, class _Allocator>
inline _LIBCPP_INLINE_VISIBILITY
bool
operator!=(const match_results<_BidirectionalIterator, _Allocator>& __x,
const match_results<_BidirectionalIterator, _Allocator>& __y)
{
return !(__x == __y);
}
template <class _BidirectionalIterator, class _Allocator>
inline _LIBCPP_INLINE_VISIBILITY
void
swap(match_results<_BidirectionalIterator, _Allocator>& __x,
match_results<_BidirectionalIterator, _Allocator>& __y)
{
__x.swap(__y);
}
// regex_search
template <class _CharT, class _Traits>
template <class _Allocator>
bool
basic_regex<_CharT, _Traits>::__match_at_start_ecma(
const _CharT* __first, const _CharT* __last,
match_results<const _CharT*, _Allocator>& __m,
regex_constants::match_flag_type __flags, bool __at_first) const
{
vector<__state> __states;
__node* __st = __start_.get();
if (__st)
{
sub_match<const _CharT*> __unmatched;
__unmatched.first = __last;
__unmatched.second = __last;
__unmatched.matched = false;
__states.push_back(__state());
__states.back().__do_ = 0;
__states.back().__first_ = __first;
__states.back().__current_ = __first;
__states.back().__last_ = __last;
__states.back().__sub_matches_.resize(mark_count(), __unmatched);
__states.back().__loop_data_.resize(__loop_count());
__states.back().__node_ = __st;
__states.back().__flags_ = __flags;
__states.back().__at_first_ = __at_first;
int __counter = 0;
int __length = __last - __first;
do
{
++__counter;
if (__counter % _LIBCPP_REGEX_COMPLEXITY_FACTOR == 0 &&
__counter / _LIBCPP_REGEX_COMPLEXITY_FACTOR >= __length)
__throw_regex_error<regex_constants::error_complexity>();
__state& __s = __states.back();
if (__s.__node_)
__s.__node_->__exec(__s);
switch (__s.__do_)
{
case __state::__end_state:
if ((__flags & regex_constants::match_not_null) &&
__s.__current_ == __first)
{
__states.pop_back();
break;
}
if ((__flags & regex_constants::__full_match) &&
__s.__current_ != __last)
{
__states.pop_back();
break;
}
__m.__matches_[0].first = __first;
__m.__matches_[0].second = _VSTD::next(__first, __s.__current_ - __first);
__m.__matches_[0].matched = true;
for (unsigned __i = 0; __i < __s.__sub_matches_.size(); ++__i)
__m.__matches_[__i+1] = __s.__sub_matches_[__i];
return true;
case __state::__accept_and_consume:
case __state::__repeat:
case __state::__accept_but_not_consume:
break;
case __state::__split:
{
__state __snext = __s;
__s.__node_->__exec_split(true, __s);
__snext.__node_->__exec_split(false, __snext);
__states.push_back(_VSTD::move(__snext));
}
break;
case __state::__reject:
__states.pop_back();
break;
default:
__throw_regex_error<regex_constants::__re_err_unknown>();
break;
}
} while (!__states.empty());
}
return false;
}
template <class _CharT, class _Traits>
template <class _Allocator>
bool
basic_regex<_CharT, _Traits>::__match_at_start_posix_nosubs(
const _CharT* __first, const _CharT* __last,
match_results<const _CharT*, _Allocator>& __m,
regex_constants::match_flag_type __flags, bool __at_first) const
{
deque<__state> __states;
ptrdiff_t __highest_j = 0;
ptrdiff_t _Np = _VSTD::distance(__first, __last);
__node* __st = __start_.get();
if (__st)
{
__states.push_back(__state());
__states.back().__do_ = 0;
__states.back().__first_ = __first;
__states.back().__current_ = __first;
__states.back().__last_ = __last;
__states.back().__loop_data_.resize(__loop_count());
__states.back().__node_ = __st;
__states.back().__flags_ = __flags;
__states.back().__at_first_ = __at_first;
bool __matched = false;
int __counter = 0;
int __length = __last - __first;
do
{
++__counter;
if (__counter % _LIBCPP_REGEX_COMPLEXITY_FACTOR == 0 &&
__counter / _LIBCPP_REGEX_COMPLEXITY_FACTOR >= __length)
__throw_regex_error<regex_constants::error_complexity>();
__state& __s = __states.back();
if (__s.__node_)
__s.__node_->__exec(__s);
switch (__s.__do_)
{
case __state::__end_state:
if ((__flags & regex_constants::match_not_null) &&
__s.__current_ == __first)
{
__states.pop_back();
break;
}
if ((__flags & regex_constants::__full_match) &&
__s.__current_ != __last)
{
__states.pop_back();
break;
}
if (!__matched || __highest_j < __s.__current_ - __s.__first_)
__highest_j = __s.__current_ - __s.__first_;
__matched = true;
if (__highest_j == _Np)
__states.clear();
else
__states.pop_back();
break;
case __state::__consume_input:
break;
case __state::__accept_and_consume:
__states.push_front(_VSTD::move(__s));
__states.pop_back();
break;
case __state::__repeat:
case __state::__accept_but_not_consume:
break;
case __state::__split:
{
__state __snext = __s;
__s.__node_->__exec_split(true, __s);
__snext.__node_->__exec_split(false, __snext);
__states.push_back(_VSTD::move(__snext));
}
break;
case __state::__reject:
__states.pop_back();
break;
default:
__throw_regex_error<regex_constants::__re_err_unknown>();
break;
}
} while (!__states.empty());
if (__matched)
{
__m.__matches_[0].first = __first;
__m.__matches_[0].second = _VSTD::next(__first, __highest_j);
__m.__matches_[0].matched = true;
return true;
}
}
return false;
}
template <class _CharT, class _Traits>
template <class _Allocator>
bool
basic_regex<_CharT, _Traits>::__match_at_start_posix_subs(
const _CharT* __first, const _CharT* __last,
match_results<const _CharT*, _Allocator>& __m,
regex_constants::match_flag_type __flags, bool __at_first) const
{
vector<__state> __states;
__state __best_state;
ptrdiff_t __j = 0;
ptrdiff_t __highest_j = 0;
ptrdiff_t _Np = _VSTD::distance(__first, __last);
__node* __st = __start_.get();
if (__st)
{
sub_match<const _CharT*> __unmatched;
__unmatched.first = __last;
__unmatched.second = __last;
__unmatched.matched = false;
__states.push_back(__state());
__states.back().__do_ = 0;
__states.back().__first_ = __first;
__states.back().__current_ = __first;
__states.back().__last_ = __last;
__states.back().__sub_matches_.resize(mark_count(), __unmatched);
__states.back().__loop_data_.resize(__loop_count());
__states.back().__node_ = __st;
__states.back().__flags_ = __flags;
__states.back().__at_first_ = __at_first;
const _CharT* __current = __first;
bool __matched = false;
int __counter = 0;
int __length = __last - __first;
do
{
++__counter;
if (__counter % _LIBCPP_REGEX_COMPLEXITY_FACTOR == 0 &&
__counter / _LIBCPP_REGEX_COMPLEXITY_FACTOR >= __length)
__throw_regex_error<regex_constants::error_complexity>();
__state& __s = __states.back();
if (__s.__node_)
__s.__node_->__exec(__s);
switch (__s.__do_)
{
case __state::__end_state:
if ((__flags & regex_constants::match_not_null) &&
__s.__current_ == __first)
{
__states.pop_back();
break;
}
if ((__flags & regex_constants::__full_match) &&
__s.__current_ != __last)
{
__states.pop_back();
break;
}
if (!__matched || __highest_j < __s.__current_ - __s.__first_)
{
__highest_j = __s.__current_ - __s.__first_;
__best_state = __s;
}
__matched = true;
if (__highest_j == _Np)
__states.clear();
else
__states.pop_back();
break;
case __state::__accept_and_consume:
__j += __s.__current_ - __current;
__current = __s.__current_;
break;
case __state::__repeat:
case __state::__accept_but_not_consume:
break;
case __state::__split:
{
__state __snext = __s;
__s.__node_->__exec_split(true, __s);
__snext.__node_->__exec_split(false, __snext);
__states.push_back(_VSTD::move(__snext));
}
break;
case __state::__reject:
__states.pop_back();
break;
default:
__throw_regex_error<regex_constants::__re_err_unknown>();
break;
}
} while (!__states.empty());
if (__matched)
{
__m.__matches_[0].first = __first;
__m.__matches_[0].second = _VSTD::next(__first, __highest_j);
__m.__matches_[0].matched = true;
for (unsigned __i = 0; __i < __best_state.__sub_matches_.size(); ++__i)
__m.__matches_[__i+1] = __best_state.__sub_matches_[__i];
return true;
}
}
return false;
}
template <class _CharT, class _Traits>
template <class _Allocator>
bool
basic_regex<_CharT, _Traits>::__match_at_start(
const _CharT* __first, const _CharT* __last,
match_results<const _CharT*, _Allocator>& __m,
regex_constants::match_flag_type __flags, bool __at_first) const
{
if (__get_grammar(__flags_) == ECMAScript)
return __match_at_start_ecma(__first, __last, __m, __flags, __at_first);
if (mark_count() == 0)
return __match_at_start_posix_nosubs(__first, __last, __m, __flags, __at_first);
return __match_at_start_posix_subs(__first, __last, __m, __flags, __at_first);
}
template <class _CharT, class _Traits>
template <class _Allocator>
bool
basic_regex<_CharT, _Traits>::__search(
const _CharT* __first, const _CharT* __last,
match_results<const _CharT*, _Allocator>& __m,
regex_constants::match_flag_type __flags) const
{
__m.__init(1 + mark_count(), __first, __last,
__flags & regex_constants::__no_update_pos);
if (__match_at_start(__first, __last, __m, __flags,
!(__flags & regex_constants::__no_update_pos)))
{
__m.__prefix_.second = __m[0].first;
__m.__prefix_.matched = __m.__prefix_.first != __m.__prefix_.second;
__m.__suffix_.first = __m[0].second;
__m.__suffix_.matched = __m.__suffix_.first != __m.__suffix_.second;
return true;
}
if (__first != __last && !(__flags & regex_constants::match_continuous))
{
__flags |= regex_constants::match_prev_avail;
for (++__first; __first != __last; ++__first)
{
__m.__matches_.assign(__m.size(), __m.__unmatched_);
if (__match_at_start(__first, __last, __m, __flags, false))
{
__m.__prefix_.second = __m[0].first;
__m.__prefix_.matched = __m.__prefix_.first != __m.__prefix_.second;
__m.__suffix_.first = __m[0].second;
__m.__suffix_.matched = __m.__suffix_.first != __m.__suffix_.second;
return true;
}
__m.__matches_.assign(__m.size(), __m.__unmatched_);
}
}
__m.__matches_.clear();
return false;
}
template <class _BidirectionalIterator, class _Allocator, class _CharT, class _Traits>
inline _LIBCPP_INLINE_VISIBILITY
bool
regex_search(_BidirectionalIterator __first, _BidirectionalIterator __last,
match_results<_BidirectionalIterator, _Allocator>& __m,
const basic_regex<_CharT, _Traits>& __e,
regex_constants::match_flag_type __flags = regex_constants::match_default)
{
int __offset = (__flags & regex_constants::match_prev_avail) ? 1 : 0;
basic_string<_CharT> __s(_VSTD::prev(__first, __offset), __last);
match_results<const _CharT*> __mc;
bool __r = __e.__search(__s.data() + __offset, __s.data() + __s.size(), __mc, __flags);
__m.__assign(__first, __last, __mc, __flags & regex_constants::__no_update_pos);
return __r;
}
template <class _Iter, class _Allocator, class _CharT, class _Traits>
inline _LIBCPP_INLINE_VISIBILITY
bool
regex_search(__wrap_iter<_Iter> __first,
__wrap_iter<_Iter> __last,
match_results<__wrap_iter<_Iter>, _Allocator>& __m,
const basic_regex<_CharT, _Traits>& __e,
regex_constants::match_flag_type __flags = regex_constants::match_default)
{
match_results<const _CharT*> __mc;
bool __r = __e.__search(__first.base(), __last.base(), __mc, __flags);
__m.__assign(__first, __last, __mc, __flags & regex_constants::__no_update_pos);
return __r;
}
template <class _Allocator, class _CharT, class _Traits>
inline _LIBCPP_INLINE_VISIBILITY
bool
regex_search(const _CharT* __first, const _CharT* __last,
match_results<const _CharT*, _Allocator>& __m,
const basic_regex<_CharT, _Traits>& __e,
regex_constants::match_flag_type __flags = regex_constants::match_default)
{
return __e.__search(__first, __last, __m, __flags);
}
template <class _BidirectionalIterator, class _CharT, class _Traits>
inline _LIBCPP_INLINE_VISIBILITY
bool
regex_search(_BidirectionalIterator __first, _BidirectionalIterator __last,
const basic_regex<_CharT, _Traits>& __e,
regex_constants::match_flag_type __flags = regex_constants::match_default)
{
basic_string<_CharT> __s(__first, __last);
match_results<const _CharT*> __mc;
return __e.__search(__s.data(), __s.data() + __s.size(), __mc, __flags);
}
template <class _CharT, class _Traits>
inline _LIBCPP_INLINE_VISIBILITY
bool
regex_search(const _CharT* __first, const _CharT* __last,
const basic_regex<_CharT, _Traits>& __e,
regex_constants::match_flag_type __flags = regex_constants::match_default)
{
match_results<const _CharT*> __mc;
return __e.__search(__first, __last, __mc, __flags);
}
template <class _CharT, class _Allocator, class _Traits>
inline _LIBCPP_INLINE_VISIBILITY
bool
regex_search(const _CharT* __str, match_results<const _CharT*, _Allocator>& __m,
const basic_regex<_CharT, _Traits>& __e,
regex_constants::match_flag_type __flags = regex_constants::match_default)
{
return __e.__search(__str, __str + _Traits::length(__str), __m, __flags);
}
template <class _CharT, class _Traits>
inline _LIBCPP_INLINE_VISIBILITY
bool
regex_search(const _CharT* __str, const basic_regex<_CharT, _Traits>& __e,
regex_constants::match_flag_type __flags = regex_constants::match_default)
{
match_results<const _CharT*> __m;
return _VSTD::regex_search(__str, __m, __e, __flags);
}
template <class _ST, class _SA, class _CharT, class _Traits>
inline _LIBCPP_INLINE_VISIBILITY
bool
regex_search(const basic_string<_CharT, _ST, _SA>& __s,
const basic_regex<_CharT, _Traits>& __e,
regex_constants::match_flag_type __flags = regex_constants::match_default)
{
match_results<const _CharT*> __mc;
return __e.__search(__s.data(), __s.data() + __s.size(), __mc, __flags);
}
template <class _ST, class _SA, class _Allocator, class _CharT, class _Traits>
inline _LIBCPP_INLINE_VISIBILITY
bool
regex_search(const basic_string<_CharT, _ST, _SA>& __s,
match_results<typename basic_string<_CharT, _ST, _SA>::const_iterator, _Allocator>& __m,
const basic_regex<_CharT, _Traits>& __e,
regex_constants::match_flag_type __flags = regex_constants::match_default)
{
match_results<const _CharT*> __mc;
bool __r = __e.__search(__s.data(), __s.data() + __s.size(), __mc, __flags);
__m.__assign(__s.begin(), __s.end(), __mc, __flags & regex_constants::__no_update_pos);
return __r;
}
#if _LIBCPP_STD_VER > 11
template <class _ST, class _SA, class _Ap, class _Cp, class _Tp>
bool
regex_search(const basic_string<_Cp, _ST, _SA>&& __s,
match_results<typename basic_string<_Cp, _ST, _SA>::const_iterator, _Ap>&,
const basic_regex<_Cp, _Tp>& __e,
regex_constants::match_flag_type __flags = regex_constants::match_default) = delete;
#endif
// regex_match
template <class _BidirectionalIterator, class _Allocator, class _CharT, class _Traits>
bool
regex_match(_BidirectionalIterator __first, _BidirectionalIterator __last,
match_results<_BidirectionalIterator, _Allocator>& __m,
const basic_regex<_CharT, _Traits>& __e,
regex_constants::match_flag_type __flags = regex_constants::match_default)
{
bool __r = _VSTD::regex_search(
__first, __last, __m, __e,
__flags | regex_constants::match_continuous |
regex_constants::__full_match);
if (__r)
{
__r = !__m.suffix().matched;
if (!__r)
__m.__matches_.clear();
}
return __r;
}
template <class _BidirectionalIterator, class _CharT, class _Traits>
inline _LIBCPP_INLINE_VISIBILITY
bool
regex_match(_BidirectionalIterator __first, _BidirectionalIterator __last,
const basic_regex<_CharT, _Traits>& __e,
regex_constants::match_flag_type __flags = regex_constants::match_default)
{
match_results<_BidirectionalIterator> __m;
return _VSTD::regex_match(__first, __last, __m, __e, __flags);
}
template <class _CharT, class _Allocator, class _Traits>
inline _LIBCPP_INLINE_VISIBILITY
bool
regex_match(const _CharT* __str, match_results<const _CharT*, _Allocator>& __m,
const basic_regex<_CharT, _Traits>& __e,
regex_constants::match_flag_type __flags = regex_constants::match_default)
{
return _VSTD::regex_match(__str, __str + _Traits::length(__str), __m, __e, __flags);
}
template <class _ST, class _SA, class _Allocator, class _CharT, class _Traits>
inline _LIBCPP_INLINE_VISIBILITY
bool
regex_match(const basic_string<_CharT, _ST, _SA>& __s,
match_results<typename basic_string<_CharT, _ST, _SA>::const_iterator, _Allocator>& __m,
const basic_regex<_CharT, _Traits>& __e,
regex_constants::match_flag_type __flags = regex_constants::match_default)
{
return _VSTD::regex_match(__s.begin(), __s.end(), __m, __e, __flags);
}
#if _LIBCPP_STD_VER > 11
template <class _ST, class _SA, class _Allocator, class _CharT, class _Traits>
inline _LIBCPP_INLINE_VISIBILITY
bool
regex_match(const basic_string<_CharT, _ST, _SA>&& __s,
match_results<typename basic_string<_CharT, _ST, _SA>::const_iterator, _Allocator>& __m,
const basic_regex<_CharT, _Traits>& __e,
regex_constants::match_flag_type __flags = regex_constants::match_default) = delete;
#endif
template <class _CharT, class _Traits>
inline _LIBCPP_INLINE_VISIBILITY
bool
regex_match(const _CharT* __str, const basic_regex<_CharT, _Traits>& __e,
regex_constants::match_flag_type __flags = regex_constants::match_default)
{
return _VSTD::regex_match(__str, __str + _Traits::length(__str), __e, __flags);
}
template <class _ST, class _SA, class _CharT, class _Traits>
inline _LIBCPP_INLINE_VISIBILITY
bool
regex_match(const basic_string<_CharT, _ST, _SA>& __s,
const basic_regex<_CharT, _Traits>& __e,
regex_constants::match_flag_type __flags = regex_constants::match_default)
{
return _VSTD::regex_match(__s.begin(), __s.end(), __e, __flags);
}
// regex_iterator
template <class _BidirectionalIterator,
class _CharT = typename iterator_traits<_BidirectionalIterator>::value_type,
class _Traits = regex_traits<_CharT> >
class _LIBCPP_TEMPLATE_VIS regex_iterator
{
public:
typedef basic_regex<_CharT, _Traits> regex_type;
typedef match_results<_BidirectionalIterator> value_type;
typedef ptrdiff_t difference_type;
typedef const value_type* pointer;
typedef const value_type& reference;
typedef forward_iterator_tag iterator_category;
private:
_BidirectionalIterator __begin_;
_BidirectionalIterator __end_;
const regex_type* __pregex_;
regex_constants::match_flag_type __flags_;
value_type __match_;
public:
regex_iterator();
regex_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b,
const regex_type& __re,
regex_constants::match_flag_type __m
= regex_constants::match_default);
#if _LIBCPP_STD_VER > 11
regex_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b,
const regex_type&& __re,
regex_constants::match_flag_type __m
= regex_constants::match_default) = delete;
#endif
bool operator==(const regex_iterator& __x) const;
_LIBCPP_INLINE_VISIBILITY
bool operator!=(const regex_iterator& __x) const {return !(*this == __x);}
_LIBCPP_INLINE_VISIBILITY
reference operator*() const {return __match_;}
_LIBCPP_INLINE_VISIBILITY
pointer operator->() const {return _VSTD::addressof(__match_);}
regex_iterator& operator++();
_LIBCPP_INLINE_VISIBILITY
regex_iterator operator++(int)
{
regex_iterator __t(*this);
++(*this);
return __t;
}
};
template <class _BidirectionalIterator, class _CharT, class _Traits>
regex_iterator<_BidirectionalIterator, _CharT, _Traits>::regex_iterator()
: __begin_(), __end_(), __pregex_(nullptr), __flags_(), __match_()
{
}
template <class _BidirectionalIterator, class _CharT, class _Traits>
regex_iterator<_BidirectionalIterator, _CharT, _Traits>::
regex_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b,
const regex_type& __re, regex_constants::match_flag_type __m)
: __begin_(__a),
__end_(__b),
__pregex_(_VSTD::addressof(__re)),
__flags_(__m)
{
_VSTD::regex_search(__begin_, __end_, __match_, *__pregex_, __flags_);
}
template <class _BidirectionalIterator, class _CharT, class _Traits>
bool
regex_iterator<_BidirectionalIterator, _CharT, _Traits>::
operator==(const regex_iterator& __x) const
{
if (__match_.empty() && __x.__match_.empty())
return true;
if (__match_.empty() || __x.__match_.empty())
return false;
return __begin_ == __x.__begin_ &&
__end_ == __x.__end_ &&
__pregex_ == __x.__pregex_ &&
__flags_ == __x.__flags_ &&
__match_[0] == __x.__match_[0];
}
template <class _BidirectionalIterator, class _CharT, class _Traits>
regex_iterator<_BidirectionalIterator, _CharT, _Traits>&
regex_iterator<_BidirectionalIterator, _CharT, _Traits>::operator++()
{
__flags_ |= regex_constants::__no_update_pos;
_BidirectionalIterator __start = __match_[0].second;
if (__match_[0].first == __match_[0].second)
{
if (__start == __end_)
{
__match_ = value_type();
return *this;
}
else if (_VSTD::regex_search(__start, __end_, __match_, *__pregex_,
__flags_ | regex_constants::match_not_null |
regex_constants::match_continuous))
return *this;
else
++__start;
}
__flags_ |= regex_constants::match_prev_avail;
if (!_VSTD::regex_search(__start, __end_, __match_, *__pregex_, __flags_))
__match_ = value_type();
return *this;
}
typedef regex_iterator<const char*> cregex_iterator;
typedef regex_iterator<const wchar_t*> wcregex_iterator;
typedef regex_iterator<string::const_iterator> sregex_iterator;
typedef regex_iterator<wstring::const_iterator> wsregex_iterator;
// regex_token_iterator
template <class _BidirectionalIterator,
class _CharT = typename iterator_traits<_BidirectionalIterator>::value_type,
class _Traits = regex_traits<_CharT> >
class _LIBCPP_TEMPLATE_VIS regex_token_iterator
{
public:
typedef basic_regex<_CharT, _Traits> regex_type;
typedef sub_match<_BidirectionalIterator> value_type;
typedef ptrdiff_t difference_type;
typedef const value_type* pointer;
typedef const value_type& reference;
typedef forward_iterator_tag iterator_category;
private:
typedef regex_iterator<_BidirectionalIterator, _CharT, _Traits> _Position;
_Position __position_;
const value_type* __result_;
value_type __suffix_;
ptrdiff_t __n_;
vector<int> __subs_;
public:
regex_token_iterator();
regex_token_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b,
const regex_type& __re, int __submatch = 0,
regex_constants::match_flag_type __m =
regex_constants::match_default);
#if _LIBCPP_STD_VER > 11
regex_token_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b,
const regex_type&& __re, int __submatch = 0,
regex_constants::match_flag_type __m =
regex_constants::match_default) = delete;
#endif
regex_token_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b,
const regex_type& __re, const vector<int>& __submatches,
regex_constants::match_flag_type __m =
regex_constants::match_default);
#if _LIBCPP_STD_VER > 11
regex_token_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b,
const regex_type&& __re, const vector<int>& __submatches,
regex_constants::match_flag_type __m =
regex_constants::match_default) = delete;
#endif
#ifndef _LIBCPP_CXX03_LANG
regex_token_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b,
const regex_type& __re,
initializer_list<int> __submatches,
regex_constants::match_flag_type __m =
regex_constants::match_default);
#if _LIBCPP_STD_VER > 11
regex_token_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b,
const regex_type&& __re,
initializer_list<int> __submatches,
regex_constants::match_flag_type __m =
regex_constants::match_default) = delete;
#endif
#endif // _LIBCPP_CXX03_LANG
template <size_t _Np>
regex_token_iterator(_BidirectionalIterator __a,
_BidirectionalIterator __b,
const regex_type& __re,
const int (&__submatches)[_Np],
regex_constants::match_flag_type __m =
regex_constants::match_default);
#if _LIBCPP_STD_VER > 11
template <std::size_t _Np>
regex_token_iterator(_BidirectionalIterator __a,
_BidirectionalIterator __b,
const regex_type&& __re,
const int (&__submatches)[_Np],
regex_constants::match_flag_type __m =
regex_constants::match_default) = delete;
#endif
regex_token_iterator(const regex_token_iterator&);
regex_token_iterator& operator=(const regex_token_iterator&);
bool operator==(const regex_token_iterator& __x) const;
_LIBCPP_INLINE_VISIBILITY
bool operator!=(const regex_token_iterator& __x) const {return !(*this == __x);}
_LIBCPP_INLINE_VISIBILITY
const value_type& operator*() const {return *__result_;}
_LIBCPP_INLINE_VISIBILITY
const value_type* operator->() const {return __result_;}
regex_token_iterator& operator++();
_LIBCPP_INLINE_VISIBILITY
regex_token_iterator operator++(int)
{
regex_token_iterator __t(*this);
++(*this);
return __t;
}
private:
void __init(_BidirectionalIterator __a, _BidirectionalIterator __b);
void __establish_result () {
if (__subs_[__n_] == -1)
__result_ = &__position_->prefix();
else
__result_ = &(*__position_)[__subs_[__n_]];
}
};
template <class _BidirectionalIterator, class _CharT, class _Traits>
regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>::
regex_token_iterator()
: __result_(nullptr),
__suffix_(),
__n_(0)
{
}
template <class _BidirectionalIterator, class _CharT, class _Traits>
void
regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>::
__init(_BidirectionalIterator __a, _BidirectionalIterator __b)
{
if (__position_ != _Position())
__establish_result ();
else if (__subs_[__n_] == -1)
{
__suffix_.matched = true;
__suffix_.first = __a;
__suffix_.second = __b;
__result_ = &__suffix_;
}
else
__result_ = nullptr;
}
template <class _BidirectionalIterator, class _CharT, class _Traits>
regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>::
regex_token_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b,
const regex_type& __re, int __submatch,
regex_constants::match_flag_type __m)
: __position_(__a, __b, __re, __m),
__n_(0),
__subs_(1, __submatch)
{
__init(__a, __b);
}
template <class _BidirectionalIterator, class _CharT, class _Traits>
regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>::
regex_token_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b,
const regex_type& __re, const vector<int>& __submatches,
regex_constants::match_flag_type __m)
: __position_(__a, __b, __re, __m),
__n_(0),
__subs_(__submatches)
{
__init(__a, __b);
}
#ifndef _LIBCPP_CXX03_LANG
template <class _BidirectionalIterator, class _CharT, class _Traits>
regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>::
regex_token_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b,
const regex_type& __re,
initializer_list<int> __submatches,
regex_constants::match_flag_type __m)
: __position_(__a, __b, __re, __m),
__n_(0),
__subs_(__submatches)
{
__init(__a, __b);
}
#endif // _LIBCPP_CXX03_LANG
template <class _BidirectionalIterator, class _CharT, class _Traits>
template <size_t _Np>
regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>::
regex_token_iterator(_BidirectionalIterator __a, _BidirectionalIterator __b,
const regex_type& __re,
const int (&__submatches)[_Np],
regex_constants::match_flag_type __m)
: __position_(__a, __b, __re, __m),
__n_(0),
__subs_(begin(__submatches), end(__submatches))
{
__init(__a, __b);
}
template <class _BidirectionalIterator, class _CharT, class _Traits>
regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>::
regex_token_iterator(const regex_token_iterator& __x)
: __position_(__x.__position_),
__result_(__x.__result_),
__suffix_(__x.__suffix_),
__n_(__x.__n_),
__subs_(__x.__subs_)
{
if (__x.__result_ == &__x.__suffix_)
__result_ = &__suffix_;
else if ( __result_ != nullptr )
__establish_result ();
}
template <class _BidirectionalIterator, class _CharT, class _Traits>
regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>&
regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>::
operator=(const regex_token_iterator& __x)
{
if (this != &__x)
{
__position_ = __x.__position_;
if (__x.__result_ == &__x.__suffix_)
__result_ = &__suffix_;
else
__result_ = __x.__result_;
__suffix_ = __x.__suffix_;
__n_ = __x.__n_;
__subs_ = __x.__subs_;
if ( __result_ != nullptr && __result_ != &__suffix_ )
__establish_result();
}
return *this;
}
template <class _BidirectionalIterator, class _CharT, class _Traits>
bool
regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>::
operator==(const regex_token_iterator& __x) const
{
if (__result_ == nullptr && __x.__result_ == nullptr)
return true;
if (__result_ == &__suffix_ && __x.__result_ == &__x.__suffix_ &&
__suffix_ == __x.__suffix_)
return true;
if (__result_ == nullptr || __x.__result_ == nullptr)
return false;
if (__result_ == &__suffix_ || __x.__result_ == &__x.__suffix_)
return false;
return __position_ == __x.__position_ && __n_ == __x.__n_ &&
__subs_ == __x.__subs_;
}
template <class _BidirectionalIterator, class _CharT, class _Traits>
regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>&
regex_token_iterator<_BidirectionalIterator, _CharT, _Traits>::operator++()
{
_Position __prev = __position_;
if (__result_ == &__suffix_)
__result_ = nullptr;
else if (static_cast<size_t>(__n_ + 1) < __subs_.size())
{
++__n_;
__establish_result();
}
else
{
__n_ = 0;
++__position_;
if (__position_ != _Position())
__establish_result();
else
{
if (_VSTD::find(__subs_.begin(), __subs_.end(), -1) != __subs_.end()
&& __prev->suffix().length() != 0)
{
__suffix_.matched = true;
__suffix_.first = __prev->suffix().first;
__suffix_.second = __prev->suffix().second;
__result_ = &__suffix_;
}
else
__result_ = nullptr;
}
}
return *this;
}
typedef regex_token_iterator<const char*> cregex_token_iterator;
typedef regex_token_iterator<const wchar_t*> wcregex_token_iterator;
typedef regex_token_iterator<string::const_iterator> sregex_token_iterator;
typedef regex_token_iterator<wstring::const_iterator> wsregex_token_iterator;
// regex_replace
template <class _OutputIterator, class _BidirectionalIterator,
class _Traits, class _CharT>
_OutputIterator
regex_replace(_OutputIterator __output_iter,
_BidirectionalIterator __first, _BidirectionalIterator __last,
const basic_regex<_CharT, _Traits>& __e, const _CharT* __fmt,
regex_constants::match_flag_type __flags = regex_constants::match_default)
{
typedef regex_iterator<_BidirectionalIterator, _CharT, _Traits> _Iter;
_Iter __i(__first, __last, __e, __flags);
_Iter __eof;
if (__i == __eof)
{
if (!(__flags & regex_constants::format_no_copy))
__output_iter = _VSTD::copy(__first, __last, __output_iter);
}
else
{
sub_match<_BidirectionalIterator> __lm;
for (size_t __len = char_traits<_CharT>::length(__fmt); __i != __eof; ++__i)
{
if (!(__flags & regex_constants::format_no_copy))
__output_iter = _VSTD::copy(__i->prefix().first, __i->prefix().second, __output_iter);
__output_iter = __i->format(__output_iter, __fmt, __fmt + __len, __flags);
__lm = __i->suffix();
if (__flags & regex_constants::format_first_only)
break;
}
if (!(__flags & regex_constants::format_no_copy))
__output_iter = _VSTD::copy(__lm.first, __lm.second, __output_iter);
}
return __output_iter;
}
template <class _OutputIterator, class _BidirectionalIterator,
class _Traits, class _CharT, class _ST, class _SA>
inline _LIBCPP_INLINE_VISIBILITY
_OutputIterator
regex_replace(_OutputIterator __output_iter,
_BidirectionalIterator __first, _BidirectionalIterator __last,
const basic_regex<_CharT, _Traits>& __e,
const basic_string<_CharT, _ST, _SA>& __fmt,
regex_constants::match_flag_type __flags = regex_constants::match_default)
{
return _VSTD::regex_replace(__output_iter, __first, __last, __e, __fmt.c_str(), __flags);
}
template <class _Traits, class _CharT, class _ST, class _SA, class _FST,
class _FSA>
inline _LIBCPP_INLINE_VISIBILITY
basic_string<_CharT, _ST, _SA>
regex_replace(const basic_string<_CharT, _ST, _SA>& __s,
const basic_regex<_CharT, _Traits>& __e,
const basic_string<_CharT, _FST, _FSA>& __fmt,
regex_constants::match_flag_type __flags = regex_constants::match_default)
{
basic_string<_CharT, _ST, _SA> __r;
_VSTD::regex_replace(back_inserter(__r), __s.begin(), __s.end(), __e,
__fmt.c_str(), __flags);
return __r;
}
template <class _Traits, class _CharT, class _ST, class _SA>
inline _LIBCPP_INLINE_VISIBILITY
basic_string<_CharT, _ST, _SA>
regex_replace(const basic_string<_CharT, _ST, _SA>& __s,
const basic_regex<_CharT, _Traits>& __e, const _CharT* __fmt,
regex_constants::match_flag_type __flags = regex_constants::match_default)
{
basic_string<_CharT, _ST, _SA> __r;
_VSTD::regex_replace(back_inserter(__r), __s.begin(), __s.end(), __e,
__fmt, __flags);
return __r;
}
template <class _Traits, class _CharT, class _ST, class _SA>
inline _LIBCPP_INLINE_VISIBILITY
basic_string<_CharT>
regex_replace(const _CharT* __s,
const basic_regex<_CharT, _Traits>& __e,
const basic_string<_CharT, _ST, _SA>& __fmt,
regex_constants::match_flag_type __flags = regex_constants::match_default)
{
basic_string<_CharT> __r;
_VSTD::regex_replace(back_inserter(__r), __s,
__s + char_traits<_CharT>::length(__s), __e,
__fmt.c_str(), __flags);
return __r;
}
template <class _Traits, class _CharT>
inline _LIBCPP_INLINE_VISIBILITY
basic_string<_CharT>
regex_replace(const _CharT* __s,
const basic_regex<_CharT, _Traits>& __e,
const _CharT* __fmt,
regex_constants::match_flag_type __flags = regex_constants::match_default)
{
basic_string<_CharT> __r;
_VSTD::regex_replace(back_inserter(__r), __s,
__s + char_traits<_CharT>::length(__s), __e,
__fmt, __flags);
return __r;
}
_LIBCPP_END_NAMESPACE_STD
_LIBCPP_POP_MACROS
#endif // _LIBCPP_REGEX
| 223,917 | 6,664 | jart/cosmopolitan | false |
cosmopolitan/third_party/libcxx/CREDITS.TXT | This file is a partial list of people who have contributed to the LLVM/libc++
project. If you have contributed a patch or made some other contribution to
LLVM/libc++, please submit a patch to this file to add yourself, and it will be
done!
The list is sorted by surname and formatted to allow easy grepping and
beautification by scripts. The fields are: name (N), email (E), web-address
(W), PGP key ID and fingerprint (P), description (D), and snail-mail address
(S).
N: Saleem Abdulrasool
E: [email protected]
D: Minor patches and Linux fixes.
N: Dan Albert
E: [email protected]
D: Android support and test runner improvements.
N: Dimitry Andric
E: [email protected]
D: Visibility fixes, minor FreeBSD portability patches.
N: Holger Arnold
E: [email protected]
D: Minor fix.
N: Ruben Van Boxem
E: vanboxem dot ruben at gmail dot com
D: Initial Windows patches.
N: David Chisnall
E: theraven at theravensnest dot org
D: FreeBSD and Solaris ports, libcxxrt support, some atomics work.
N: Marshall Clow
E: [email protected]
E: [email protected]
D: C++14 support, patches and bug fixes.
N: Jonathan B Coe
E: [email protected]
D: Implementation of propagate_const.
N: Glen Joseph Fernandes
E: [email protected]
D: Implementation of to_address.
N: Eric Fiselier
E: [email protected]
D: LFTS support, patches and bug fixes.
N: Bill Fisher
E: [email protected]
D: Regex bug fixes.
N: Matthew Dempsky
E: [email protected]
D: Minor patches and bug fixes.
N: Google Inc.
D: Copyright owner and contributor of the CityHash algorithm
N: Howard Hinnant
E: [email protected]
D: Architect and primary author of libc++
N: Hyeon-bin Jeong
E: [email protected]
D: Minor patches and bug fixes.
N: Argyrios Kyrtzidis
E: [email protected]
D: Bug fixes.
N: Bruce Mitchener, Jr.
E: [email protected]
D: Emscripten-related changes.
N: Michel Morin
E: [email protected]
D: Minor patches to is_convertible.
N: Andrew Morrow
E: [email protected]
D: Minor patches and Linux fixes.
N: Michael Park
E: [email protected]
D: Implementation of <variant>.
N: Arvid Picciani
E: aep at exys dot org
D: Minor patches and musl port.
N: Bjorn Reese
E: [email protected]
D: Initial regex prototype
N: Nico Rieck
E: [email protected]
D: Windows fixes
N: Jon Roelofs
E: [email protected]
D: Remote testing, Newlib port, baremetal/single-threaded support.
N: Jonathan Sauer
D: Minor patches, mostly related to constexpr
N: Craig Silverstein
E: [email protected]
D: Implemented Cityhash as the string hash function on 64-bit machines
N: Richard Smith
D: Minor patches.
N: Joerg Sonnenberger
E: [email protected]
D: NetBSD port.
N: Stephan Tolksdorf
E: [email protected]
D: Minor <atomic> fix
N: Michael van der Westhuizen
E: r1mikey at gmail dot com
N: Larisse Voufo
D: Minor patches.
N: Klaas de Vries
E: klaas at klaasgaaf dot nl
D: Minor bug fix.
N: Zhang Xiongpang
E: [email protected]
D: Minor patches and bug fixes.
N: Xing Xue
E: [email protected]
D: AIX port
N: Zhihao Yuan
E: [email protected]
D: Standard compatibility fixes.
N: Jeffrey Yasskin
E: [email protected]
E: [email protected]
D: Linux fixes.
| 3,173 | 151 | jart/cosmopolitan | false |
cosmopolitan/third_party/libcxx/algorithm | // -*- C++ -*-
//===-------------------------- algorithm ---------------------------------===//
//
// 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_ALGORITHM
#define _LIBCPP_ALGORITHM
#include "third_party/libcxx/__config"
#include "third_party/libcxx/initializer_list"
#include "third_party/libcxx/type_traits"
#include "third_party/libcxx/cstring"
#include "third_party/libcxx/utility" // needed to provide swap_ranges.
#include "third_party/libcxx/memory"
#include "third_party/libcxx/functional"
#include "third_party/libcxx/iterator"
#include "third_party/libcxx/cstddef"
#include "third_party/libcxx/bit"
#include "third_party/libcxx/version"
#if defined(_LIBCPP_HAS_PARALLEL_ALGORITHMS) && _LIBCPP_STD_VER >= 17
# include "third_party/libcxx/__pstl_algorithm"
#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
/*
algorithm synopsis
#include "third_party/libcxx/initializer_list"
namespace std
{
template <class InputIterator, class Predicate>
constexpr bool // constexpr in C++20
all_of(InputIterator first, InputIterator last, Predicate pred);
template <class InputIterator, class Predicate>
constexpr bool // constexpr in C++20
any_of(InputIterator first, InputIterator last, Predicate pred);
template <class InputIterator, class Predicate>
constexpr bool // constexpr in C++20
none_of(InputIterator first, InputIterator last, Predicate pred);
template <class InputIterator, class Function>
constexpr Function // constexpr in C++20
for_each(InputIterator first, InputIterator last, Function f);
template<class InputIterator, class Size, class Function>
constexpr InputIterator // constexpr in C++20
for_each_n(InputIterator first, Size n, Function f); // C++17
template <class InputIterator, class T>
constexpr InputIterator // constexpr in C++20
find(InputIterator first, InputIterator last, const T& value);
template <class InputIterator, class Predicate>
constexpr InputIterator // constexpr in C++20
find_if(InputIterator first, InputIterator last, Predicate pred);
template<class InputIterator, class Predicate>
InputIterator // constexpr in C++20
find_if_not(InputIterator first, InputIterator last, Predicate pred);
template <class ForwardIterator1, class ForwardIterator2>
ForwardIterator1 // constexpr in C++20
find_end(ForwardIterator1 first1, ForwardIterator1 last1,
ForwardIterator2 first2, ForwardIterator2 last2);
template <class ForwardIterator1, class ForwardIterator2, class BinaryPredicate>
ForwardIterator1 // constexpr in C++20
find_end(ForwardIterator1 first1, ForwardIterator1 last1,
ForwardIterator2 first2, ForwardIterator2 last2, BinaryPredicate pred);
template <class ForwardIterator1, class ForwardIterator2>
constexpr ForwardIterator1 // constexpr in C++20
find_first_of(ForwardIterator1 first1, ForwardIterator1 last1,
ForwardIterator2 first2, ForwardIterator2 last2);
template <class ForwardIterator1, class ForwardIterator2, class BinaryPredicate>
constexpr ForwardIterator1 // constexpr in C++20
find_first_of(ForwardIterator1 first1, ForwardIterator1 last1,
ForwardIterator2 first2, ForwardIterator2 last2, BinaryPredicate pred);
template <class ForwardIterator>
constexpr ForwardIterator // constexpr in C++20
adjacent_find(ForwardIterator first, ForwardIterator last);
template <class ForwardIterator, class BinaryPredicate>
constexpr ForwardIterator // constexpr in C++20
adjacent_find(ForwardIterator first, ForwardIterator last, BinaryPredicate pred);
template <class InputIterator, class T>
constexpr typename iterator_traits<InputIterator>::difference_type // constexpr in C++20
count(InputIterator first, InputIterator last, const T& value);
template <class InputIterator, class Predicate>
constexpr typename iterator_traits<InputIterator>::difference_type // constexpr in C++20
count_if(InputIterator first, InputIterator last, Predicate pred);
template <class InputIterator1, class InputIterator2>
constexpr pair<InputIterator1, InputIterator2> // constexpr in C++20
mismatch(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2);
template <class InputIterator1, class InputIterator2>
constexpr pair<InputIterator1, InputIterator2> // constexpr in C++20
mismatch(InputIterator1 first1, InputIterator1 last1,
InputIterator2 first2, InputIterator2 last2); // **C++14**
template <class InputIterator1, class InputIterator2, class BinaryPredicate>
constexpr pair<InputIterator1, InputIterator2> // constexpr in C++20
mismatch(InputIterator1 first1, InputIterator1 last1,
InputIterator2 first2, BinaryPredicate pred);
template <class InputIterator1, class InputIterator2, class BinaryPredicate>
constexpr pair<InputIterator1, InputIterator2> // constexpr in C++20
mismatch(InputIterator1 first1, InputIterator1 last1,
InputIterator2 first2, InputIterator2 last2,
BinaryPredicate pred); // **C++14**
template <class InputIterator1, class InputIterator2>
constexpr bool // constexpr in C++20
equal(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2);
template <class InputIterator1, class InputIterator2>
constexpr bool // constexpr in C++20
equal(InputIterator1 first1, InputIterator1 last1,
InputIterator2 first2, InputIterator2 last2); // **C++14**
template <class InputIterator1, class InputIterator2, class BinaryPredicate>
constexpr bool // constexpr in C++20
equal(InputIterator1 first1, InputIterator1 last1,
InputIterator2 first2, BinaryPredicate pred);
template <class InputIterator1, class InputIterator2, class BinaryPredicate>
constexpr bool // constexpr in C++20
equal(InputIterator1 first1, InputIterator1 last1,
InputIterator2 first2, InputIterator2 last2,
BinaryPredicate pred); // **C++14**
template<class ForwardIterator1, class ForwardIterator2>
constexpr bool // constexpr in C++20
is_permutation(ForwardIterator1 first1, ForwardIterator1 last1,
ForwardIterator2 first2);
template<class ForwardIterator1, class ForwardIterator2>
constexpr bool // constexpr in C++20
is_permutation(ForwardIterator1 first1, ForwardIterator1 last1,
ForwardIterator2 first2, ForwardIterator2 last2); // **C++14**
template<class ForwardIterator1, class ForwardIterator2, class BinaryPredicate>
constexpr bool // constexpr in C++20
is_permutation(ForwardIterator1 first1, ForwardIterator1 last1,
ForwardIterator2 first2, BinaryPredicate pred);
template<class ForwardIterator1, class ForwardIterator2, class BinaryPredicate>
constexpr bool // constexpr in C++20
is_permutation(ForwardIterator1 first1, ForwardIterator1 last1,
ForwardIterator2 first2, ForwardIterator2 last2,
BinaryPredicate pred); // **C++14**
template <class ForwardIterator1, class ForwardIterator2>
constexpr ForwardIterator1 // constexpr in C++20
search(ForwardIterator1 first1, ForwardIterator1 last1,
ForwardIterator2 first2, ForwardIterator2 last2);
template <class ForwardIterator1, class ForwardIterator2, class BinaryPredicate>
constexpr ForwardIterator1 // constexpr in C++20
search(ForwardIterator1 first1, ForwardIterator1 last1,
ForwardIterator2 first2, ForwardIterator2 last2, BinaryPredicate pred);
template <class ForwardIterator, class Size, class T>
constexpr ForwardIterator // constexpr in C++20
search_n(ForwardIterator first, ForwardIterator last, Size count, const T& value);
template <class ForwardIterator, class Size, class T, class BinaryPredicate>
constexpr ForwardIterator // constexpr in C++20
search_n(ForwardIterator first, ForwardIterator last,
Size count, const T& value, BinaryPredicate pred);
template <class InputIterator, class OutputIterator>
OutputIterator
copy(InputIterator first, InputIterator last, OutputIterator result);
template<class InputIterator, class OutputIterator, class Predicate>
OutputIterator
copy_if(InputIterator first, InputIterator last,
OutputIterator result, Predicate pred);
template<class InputIterator, class Size, class OutputIterator>
OutputIterator
copy_n(InputIterator first, Size n, OutputIterator result);
template <class BidirectionalIterator1, class BidirectionalIterator2>
BidirectionalIterator2
copy_backward(BidirectionalIterator1 first, BidirectionalIterator1 last,
BidirectionalIterator2 result);
template <class ForwardIterator1, class ForwardIterator2>
ForwardIterator2
swap_ranges(ForwardIterator1 first1, ForwardIterator1 last1, ForwardIterator2 first2);
template <class ForwardIterator1, class ForwardIterator2>
void
iter_swap(ForwardIterator1 a, ForwardIterator2 b);
template <class InputIterator, class OutputIterator, class UnaryOperation>
constexpr OutputIterator // constexpr in C++20
transform(InputIterator first, InputIterator last, OutputIterator result, UnaryOperation op);
template <class InputIterator1, class InputIterator2, class OutputIterator, class BinaryOperation>
constexpr OutputIterator // constexpr in C++20
transform(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2,
OutputIterator result, BinaryOperation binary_op);
template <class ForwardIterator, class T>
constexpr void // constexpr in C++20
replace(ForwardIterator first, ForwardIterator last, const T& old_value, const T& new_value);
template <class ForwardIterator, class Predicate, class T>
constexpr void // constexpr in C++20
replace_if(ForwardIterator first, ForwardIterator last, Predicate pred, const T& new_value);
template <class InputIterator, class OutputIterator, class T>
constexpr OutputIterator // constexpr in C++20
replace_copy(InputIterator first, InputIterator last, OutputIterator result,
const T& old_value, const T& new_value);
template <class InputIterator, class OutputIterator, class Predicate, class T>
constexpr OutputIterator // constexpr in C++20
replace_copy_if(InputIterator first, InputIterator last, OutputIterator result, Predicate pred, const T& new_value);
template <class ForwardIterator, class T>
constexpr void // constexpr in C++20
fill(ForwardIterator first, ForwardIterator last, const T& value);
template <class OutputIterator, class Size, class T>
constexpr OutputIterator // constexpr in C++20
fill_n(OutputIterator first, Size n, const T& value);
template <class ForwardIterator, class Generator>
constexpr void // constexpr in C++20
generate(ForwardIterator first, ForwardIterator last, Generator gen);
template <class OutputIterator, class Size, class Generator>
constexpr OutputIterator // constexpr in C++20
generate_n(OutputIterator first, Size n, Generator gen);
template <class ForwardIterator, class T>
constexpr ForwardIterator // constexpr in C++20
remove(ForwardIterator first, ForwardIterator last, const T& value);
template <class ForwardIterator, class Predicate>
constexpr ForwardIterator // constexpr in C++20
remove_if(ForwardIterator first, ForwardIterator last, Predicate pred);
template <class InputIterator, class OutputIterator, class T>
constexpr OutputIterator // constexpr in C++20
remove_copy(InputIterator first, InputIterator last, OutputIterator result, const T& value);
template <class InputIterator, class OutputIterator, class Predicate>
constexpr OutputIterator // constexpr in C++20
remove_copy_if(InputIterator first, InputIterator last, OutputIterator result, Predicate pred);
template <class ForwardIterator>
ForwardIterator
unique(ForwardIterator first, ForwardIterator last);
template <class ForwardIterator, class BinaryPredicate>
ForwardIterator
unique(ForwardIterator first, ForwardIterator last, BinaryPredicate pred);
template <class InputIterator, class OutputIterator>
OutputIterator
unique_copy(InputIterator first, InputIterator last, OutputIterator result);
template <class InputIterator, class OutputIterator, class BinaryPredicate>
OutputIterator
unique_copy(InputIterator first, InputIterator last, OutputIterator result, BinaryPredicate pred);
template <class BidirectionalIterator>
void
reverse(BidirectionalIterator first, BidirectionalIterator last);
template <class BidirectionalIterator, class OutputIterator>
constexpr OutputIterator // constexpr in C++20
reverse_copy(BidirectionalIterator first, BidirectionalIterator last, OutputIterator result);
template <class ForwardIterator>
ForwardIterator
rotate(ForwardIterator first, ForwardIterator middle, ForwardIterator last);
template <class ForwardIterator, class OutputIterator>
OutputIterator
rotate_copy(ForwardIterator first, ForwardIterator middle, ForwardIterator last, OutputIterator result);
template <class RandomAccessIterator>
void
random_shuffle(RandomAccessIterator first, RandomAccessIterator last); // deprecated in C++14, removed in C++17
template <class RandomAccessIterator, class RandomNumberGenerator>
void
random_shuffle(RandomAccessIterator first, RandomAccessIterator last,
RandomNumberGenerator& rand); // deprecated in C++14, removed in C++17
template<class PopulationIterator, class SampleIterator,
class Distance, class UniformRandomBitGenerator>
SampleIterator sample(PopulationIterator first, PopulationIterator last,
SampleIterator out, Distance n,
UniformRandomBitGenerator&& g); // C++17
template<class RandomAccessIterator, class UniformRandomNumberGenerator>
void shuffle(RandomAccessIterator first, RandomAccessIterator last,
UniformRandomNumberGenerator&& g);
template <class InputIterator, class Predicate>
constexpr bool // constexpr in C++20
is_partitioned(InputIterator first, InputIterator last, Predicate pred);
template <class ForwardIterator, class Predicate>
ForwardIterator
partition(ForwardIterator first, ForwardIterator last, Predicate pred);
template <class InputIterator, class OutputIterator1,
class OutputIterator2, class Predicate>
constexpr pair<OutputIterator1, OutputIterator2> // constexpr in C++20
partition_copy(InputIterator first, InputIterator last,
OutputIterator1 out_true, OutputIterator2 out_false,
Predicate pred);
template <class ForwardIterator, class Predicate>
ForwardIterator
stable_partition(ForwardIterator first, ForwardIterator last, Predicate pred);
template<class ForwardIterator, class Predicate>
constexpr ForwardIterator // constexpr in C++20
partition_point(ForwardIterator first, ForwardIterator last, Predicate pred);
template <class ForwardIterator>
constexpr bool // constexpr in C++20
is_sorted(ForwardIterator first, ForwardIterator last);
template <class ForwardIterator, class Compare>
bool
is_sorted(ForwardIterator first, ForwardIterator last, Compare comp);
template<class ForwardIterator>
constexpr ForwardIterator // constexpr in C++20
is_sorted_until(ForwardIterator first, ForwardIterator last);
template <class ForwardIterator, class Compare>
constexpr ForwardIterator // constexpr in C++20
is_sorted_until(ForwardIterator first, ForwardIterator last, Compare comp);
template <class RandomAccessIterator>
void
sort(RandomAccessIterator first, RandomAccessIterator last);
template <class RandomAccessIterator, class Compare>
void
sort(RandomAccessIterator first, RandomAccessIterator last, Compare comp);
template <class RandomAccessIterator>
void
stable_sort(RandomAccessIterator first, RandomAccessIterator last);
template <class RandomAccessIterator, class Compare>
void
stable_sort(RandomAccessIterator first, RandomAccessIterator last, Compare comp);
template <class RandomAccessIterator>
void
partial_sort(RandomAccessIterator first, RandomAccessIterator middle, RandomAccessIterator last);
template <class RandomAccessIterator, class Compare>
void
partial_sort(RandomAccessIterator first, RandomAccessIterator middle, RandomAccessIterator last, Compare comp);
template <class InputIterator, class RandomAccessIterator>
RandomAccessIterator
partial_sort_copy(InputIterator first, InputIterator last,
RandomAccessIterator result_first, RandomAccessIterator result_last);
template <class InputIterator, class RandomAccessIterator, class Compare>
RandomAccessIterator
partial_sort_copy(InputIterator first, InputIterator last,
RandomAccessIterator result_first, RandomAccessIterator result_last, Compare comp);
template <class RandomAccessIterator>
void
nth_element(RandomAccessIterator first, RandomAccessIterator nth, RandomAccessIterator last);
template <class RandomAccessIterator, class Compare>
void
nth_element(RandomAccessIterator first, RandomAccessIterator nth, RandomAccessIterator last, Compare comp);
template <class ForwardIterator, class T>
constexpr ForwardIterator // constexpr in C++20
lower_bound(ForwardIterator first, ForwardIterator last, const T& value);
template <class ForwardIterator, class T, class Compare>
constexpr ForwardIterator // constexpr in C++20
lower_bound(ForwardIterator first, ForwardIterator last, const T& value, Compare comp);
template <class ForwardIterator, class T>
constexpr ForwardIterator // constexpr in C++20
upper_bound(ForwardIterator first, ForwardIterator last, const T& value);
template <class ForwardIterator, class T, class Compare>
constexpr ForwardIterator // constexpr in C++20
upper_bound(ForwardIterator first, ForwardIterator last, const T& value, Compare comp);
template <class ForwardIterator, class T>
constexpr pair<ForwardIterator, ForwardIterator> // constexpr in C++20
equal_range(ForwardIterator first, ForwardIterator last, const T& value);
template <class ForwardIterator, class T, class Compare>
constexpr pair<ForwardIterator, ForwardIterator> // constexpr in C++20
equal_range(ForwardIterator first, ForwardIterator last, const T& value, Compare comp);
template <class ForwardIterator, class T>
constexpr bool // constexpr in C++20
binary_search(ForwardIterator first, ForwardIterator last, const T& value);
template <class ForwardIterator, class T, class Compare>
constexpr bool // constexpr in C++20
binary_search(ForwardIterator first, ForwardIterator last, const T& value, Compare comp);
template <class InputIterator1, class InputIterator2, class OutputIterator>
OutputIterator
merge(InputIterator1 first1, InputIterator1 last1,
InputIterator2 first2, InputIterator2 last2, OutputIterator result);
template <class InputIterator1, class InputIterator2, class OutputIterator, class Compare>
OutputIterator
merge(InputIterator1 first1, InputIterator1 last1,
InputIterator2 first2, InputIterator2 last2, OutputIterator result, Compare comp);
template <class BidirectionalIterator>
void
inplace_merge(BidirectionalIterator first, BidirectionalIterator middle, BidirectionalIterator last);
template <class BidirectionalIterator, class Compare>
void
inplace_merge(BidirectionalIterator first, BidirectionalIterator middle, BidirectionalIterator last, Compare comp);
template <class InputIterator1, class InputIterator2>
constexpr bool // constexpr in C++20
includes(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, InputIterator2 last2);
template <class InputIterator1, class InputIterator2, class Compare>
constexpr bool // constexpr in C++20
includes(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, InputIterator2 last2, Compare comp);
template <class InputIterator1, class InputIterator2, class OutputIterator>
OutputIterator
set_union(InputIterator1 first1, InputIterator1 last1,
InputIterator2 first2, InputIterator2 last2, OutputIterator result);
template <class InputIterator1, class InputIterator2, class OutputIterator, class Compare>
OutputIterator
set_union(InputIterator1 first1, InputIterator1 last1,
InputIterator2 first2, InputIterator2 last2, OutputIterator result, Compare comp);
template <class InputIterator1, class InputIterator2, class OutputIterator>
constexpr OutputIterator // constexpr in C++20
set_intersection(InputIterator1 first1, InputIterator1 last1,
InputIterator2 first2, InputIterator2 last2, OutputIterator result);
template <class InputIterator1, class InputIterator2, class OutputIterator, class Compare>
constexpr OutputIterator // constexpr in C++20
set_intersection(InputIterator1 first1, InputIterator1 last1,
InputIterator2 first2, InputIterator2 last2, OutputIterator result, Compare comp);
template <class InputIterator1, class InputIterator2, class OutputIterator>
OutputIterator
set_difference(InputIterator1 first1, InputIterator1 last1,
InputIterator2 first2, InputIterator2 last2, OutputIterator result);
template <class InputIterator1, class InputIterator2, class OutputIterator, class Compare>
OutputIterator
set_difference(InputIterator1 first1, InputIterator1 last1,
InputIterator2 first2, InputIterator2 last2, OutputIterator result, Compare comp);
template <class InputIterator1, class InputIterator2, class OutputIterator>
OutputIterator
set_symmetric_difference(InputIterator1 first1, InputIterator1 last1,
InputIterator2 first2, InputIterator2 last2, OutputIterator result);
template <class InputIterator1, class InputIterator2, class OutputIterator, class Compare>
OutputIterator
set_symmetric_difference(InputIterator1 first1, InputIterator1 last1,
InputIterator2 first2, InputIterator2 last2, OutputIterator result, Compare comp);
template <class RandomAccessIterator>
void
push_heap(RandomAccessIterator first, RandomAccessIterator last);
template <class RandomAccessIterator, class Compare>
void
push_heap(RandomAccessIterator first, RandomAccessIterator last, Compare comp);
template <class RandomAccessIterator>
void
pop_heap(RandomAccessIterator first, RandomAccessIterator last);
template <class RandomAccessIterator, class Compare>
void
pop_heap(RandomAccessIterator first, RandomAccessIterator last, Compare comp);
template <class RandomAccessIterator>
void
make_heap(RandomAccessIterator first, RandomAccessIterator last);
template <class RandomAccessIterator, class Compare>
void
make_heap(RandomAccessIterator first, RandomAccessIterator last, Compare comp);
template <class RandomAccessIterator>
void
sort_heap(RandomAccessIterator first, RandomAccessIterator last);
template <class RandomAccessIterator, class Compare>
void
sort_heap(RandomAccessIterator first, RandomAccessIterator last, Compare comp);
template <class RandomAccessIterator>
constexpr bool // constexpr in C++20
is_heap(RandomAccessIterator first, RandomAccessiterator last);
template <class RandomAccessIterator, class Compare>
constexpr bool // constexpr in C++20
is_heap(RandomAccessIterator first, RandomAccessiterator last, Compare comp);
template <class RandomAccessIterator>
constexpr RandomAccessIterator // constexpr in C++20
is_heap_until(RandomAccessIterator first, RandomAccessiterator last);
template <class RandomAccessIterator, class Compare>
constexpr RandomAccessIterator // constexpr in C++20
is_heap_until(RandomAccessIterator first, RandomAccessiterator last, Compare comp);
template <class ForwardIterator>
ForwardIterator
min_element(ForwardIterator first, ForwardIterator last); // constexpr in C++14
template <class ForwardIterator, class Compare>
ForwardIterator
min_element(ForwardIterator first, ForwardIterator last, Compare comp); // constexpr in C++14
template <class T>
const T&
min(const T& a, const T& b); // constexpr in C++14
template <class T, class Compare>
const T&
min(const T& a, const T& b, Compare comp); // constexpr in C++14
template<class T>
T
min(initializer_list<T> t); // constexpr in C++14
template<class T, class Compare>
T
min(initializer_list<T> t, Compare comp); // constexpr in C++14
template<class T>
constexpr const T& clamp( const T& v, const T& lo, const T& hi ); // C++17
template<class T, class Compare>
constexpr const T& clamp( const T& v, const T& lo, const T& hi, Compare comp ); // C++17
template <class ForwardIterator>
ForwardIterator
max_element(ForwardIterator first, ForwardIterator last); // constexpr in C++14
template <class ForwardIterator, class Compare>
ForwardIterator
max_element(ForwardIterator first, ForwardIterator last, Compare comp); // constexpr in C++14
template <class T>
const T&
max(const T& a, const T& b); // constexpr in C++14
template <class T, class Compare>
const T&
max(const T& a, const T& b, Compare comp); // constexpr in C++14
template<class T>
T
max(initializer_list<T> t); // constexpr in C++14
template<class T, class Compare>
T
max(initializer_list<T> t, Compare comp); // constexpr in C++14
template<class ForwardIterator>
pair<ForwardIterator, ForwardIterator>
minmax_element(ForwardIterator first, ForwardIterator last); // constexpr in C++14
template<class ForwardIterator, class Compare>
pair<ForwardIterator, ForwardIterator>
minmax_element(ForwardIterator first, ForwardIterator last, Compare comp); // constexpr in C++14
template<class T>
pair<const T&, const T&>
minmax(const T& a, const T& b); // constexpr in C++14
template<class T, class Compare>
pair<const T&, const T&>
minmax(const T& a, const T& b, Compare comp); // constexpr in C++14
template<class T>
pair<T, T>
minmax(initializer_list<T> t); // constexpr in C++14
template<class T, class Compare>
pair<T, T>
minmax(initializer_list<T> t, Compare comp); // constexpr in C++14
template <class InputIterator1, class InputIterator2>
constexpr bool // constexpr in C++20
lexicographical_compare(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, InputIterator2 last2);
template <class InputIterator1, class InputIterator2, class Compare>
constexpr bool // constexpr in C++20
lexicographical_compare(InputIterator1 first1, InputIterator1 last1,
InputIterator2 first2, InputIterator2 last2, Compare comp);
template <class BidirectionalIterator>
bool
next_permutation(BidirectionalIterator first, BidirectionalIterator last);
template <class BidirectionalIterator, class Compare>
bool
next_permutation(BidirectionalIterator first, BidirectionalIterator last, Compare comp);
template <class BidirectionalIterator>
bool
prev_permutation(BidirectionalIterator first, BidirectionalIterator last);
template <class BidirectionalIterator, class Compare>
bool
prev_permutation(BidirectionalIterator first, BidirectionalIterator last, Compare comp);
} // std
*/
// I'd like to replace these with _VSTD::equal_to<void>, but can't because:
// * That only works with C++14 and later, and
// * We haven't included <functional> here.
template <class _T1, class _T2 = _T1>
struct __equal_to
{
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 bool operator()(const _T1& __x, const _T1& __y) const {return __x == __y;}
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 bool operator()(const _T1& __x, const _T2& __y) const {return __x == __y;}
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 bool operator()(const _T2& __x, const _T1& __y) const {return __x == __y;}
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 bool operator()(const _T2& __x, const _T2& __y) const {return __x == __y;}
};
template <class _T1>
struct __equal_to<_T1, _T1>
{
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
bool operator()(const _T1& __x, const _T1& __y) const {return __x == __y;}
};
template <class _T1>
struct __equal_to<const _T1, _T1>
{
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
bool operator()(const _T1& __x, const _T1& __y) const {return __x == __y;}
};
template <class _T1>
struct __equal_to<_T1, const _T1>
{
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
bool operator()(const _T1& __x, const _T1& __y) const {return __x == __y;}
};
template <class _T1, class _T2 = _T1>
struct __less
{
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
bool operator()(const _T1& __x, const _T1& __y) const {return __x < __y;}
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
bool operator()(const _T1& __x, const _T2& __y) const {return __x < __y;}
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
bool operator()(const _T2& __x, const _T1& __y) const {return __x < __y;}
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
bool operator()(const _T2& __x, const _T2& __y) const {return __x < __y;}
};
template <class _T1>
struct __less<_T1, _T1>
{
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
bool operator()(const _T1& __x, const _T1& __y) const {return __x < __y;}
};
template <class _T1>
struct __less<const _T1, _T1>
{
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
bool operator()(const _T1& __x, const _T1& __y) const {return __x < __y;}
};
template <class _T1>
struct __less<_T1, const _T1>
{
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
bool operator()(const _T1& __x, const _T1& __y) const {return __x < __y;}
};
template <class _Predicate>
class __invert // invert the sense of a comparison
{
private:
_Predicate __p_;
public:
_LIBCPP_INLINE_VISIBILITY __invert() {}
_LIBCPP_INLINE_VISIBILITY
explicit __invert(_Predicate __p) : __p_(__p) {}
template <class _T1>
_LIBCPP_INLINE_VISIBILITY
bool operator()(const _T1& __x) {return !__p_(__x);}
template <class _T1, class _T2>
_LIBCPP_INLINE_VISIBILITY
bool operator()(const _T1& __x, const _T2& __y) {return __p_(__y, __x);}
};
// Perform division by two quickly for positive integers (llvm.org/PR39129)
template <typename _Integral>
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
typename enable_if
<
is_integral<_Integral>::value,
_Integral
>::type
__half_positive(_Integral __value)
{
return static_cast<_Integral>(static_cast<typename make_unsigned<_Integral>::type>(__value) / 2);
}
template <typename _Tp>
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
typename enable_if
<
!is_integral<_Tp>::value,
_Tp
>::type
__half_positive(_Tp __value)
{
return __value / 2;
}
#ifdef _LIBCPP_DEBUG
template <class _Compare>
struct __debug_less
{
_Compare &__comp_;
_LIBCPP_CONSTEXPR_AFTER_CXX17
__debug_less(_Compare& __c) : __comp_(__c) {}
template <class _Tp, class _Up>
_LIBCPP_CONSTEXPR_AFTER_CXX17
bool operator()(const _Tp& __x, const _Up& __y)
{
bool __r = __comp_(__x, __y);
if (__r)
__do_compare_assert(0, __y, __x);
return __r;
}
template <class _Tp, class _Up>
_LIBCPP_CONSTEXPR_AFTER_CXX17
bool operator()(_Tp& __x, _Up& __y)
{
bool __r = __comp_(__x, __y);
if (__r)
__do_compare_assert(0, __y, __x);
return __r;
}
template <class _LHS, class _RHS>
_LIBCPP_CONSTEXPR_AFTER_CXX17
inline _LIBCPP_INLINE_VISIBILITY
decltype((void)_VSTD::declval<_Compare&>()(
_VSTD::declval<_LHS &>(), _VSTD::declval<_RHS &>()))
__do_compare_assert(int, _LHS & __l, _RHS & __r) {
_LIBCPP_ASSERT(!__comp_(__l, __r),
"Comparator does not induce a strict weak ordering");
}
template <class _LHS, class _RHS>
_LIBCPP_CONSTEXPR_AFTER_CXX17
inline _LIBCPP_INLINE_VISIBILITY
void __do_compare_assert(long, _LHS &, _RHS &) {}
};
#endif // _LIBCPP_DEBUG
template <class _Comp>
struct __comp_ref_type {
// Pass the comparator by lvalue reference. Or in debug mode, using a
// debugging wrapper that stores a reference.
#ifndef _LIBCPP_DEBUG
typedef typename add_lvalue_reference<_Comp>::type type;
#else
typedef __debug_less<_Comp> type;
#endif
};
// all_of
template <class _InputIterator, class _Predicate>
_LIBCPP_NODISCARD_EXT inline
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
bool
all_of(_InputIterator __first, _InputIterator __last, _Predicate __pred)
{
for (; __first != __last; ++__first)
if (!__pred(*__first))
return false;
return true;
}
// any_of
template <class _InputIterator, class _Predicate>
_LIBCPP_NODISCARD_EXT inline
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
bool
any_of(_InputIterator __first, _InputIterator __last, _Predicate __pred)
{
for (; __first != __last; ++__first)
if (__pred(*__first))
return true;
return false;
}
// none_of
template <class _InputIterator, class _Predicate>
_LIBCPP_NODISCARD_EXT inline
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
bool
none_of(_InputIterator __first, _InputIterator __last, _Predicate __pred)
{
for (; __first != __last; ++__first)
if (__pred(*__first))
return false;
return true;
}
// for_each
template <class _InputIterator, class _Function>
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
_Function
for_each(_InputIterator __first, _InputIterator __last, _Function __f)
{
for (; __first != __last; ++__first)
__f(*__first);
return __f;
}
#if _LIBCPP_STD_VER > 14
// for_each_n
template <class _InputIterator, class _Size, class _Function>
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
_InputIterator
for_each_n(_InputIterator __first, _Size __orig_n, _Function __f)
{
typedef decltype(__convert_to_integral(__orig_n)) _IntegralSize;
_IntegralSize __n = __orig_n;
while (__n > 0)
{
__f(*__first);
++__first;
--__n;
}
return __first;
}
#endif
// find
template <class _InputIterator, class _Tp>
_LIBCPP_NODISCARD_EXT inline
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
_InputIterator
find(_InputIterator __first, _InputIterator __last, const _Tp& __value_)
{
for (; __first != __last; ++__first)
if (*__first == __value_)
break;
return __first;
}
// find_if
template <class _InputIterator, class _Predicate>
_LIBCPP_NODISCARD_EXT inline
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
_InputIterator
find_if(_InputIterator __first, _InputIterator __last, _Predicate __pred)
{
for (; __first != __last; ++__first)
if (__pred(*__first))
break;
return __first;
}
// find_if_not
template<class _InputIterator, class _Predicate>
_LIBCPP_NODISCARD_EXT inline
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
_InputIterator
find_if_not(_InputIterator __first, _InputIterator __last, _Predicate __pred)
{
for (; __first != __last; ++__first)
if (!__pred(*__first))
break;
return __first;
}
// find_end
template <class _BinaryPredicate, class _ForwardIterator1, class _ForwardIterator2>
_LIBCPP_CONSTEXPR_AFTER_CXX17 _ForwardIterator1
__find_end(_ForwardIterator1 __first1, _ForwardIterator1 __last1,
_ForwardIterator2 __first2, _ForwardIterator2 __last2, _BinaryPredicate __pred,
forward_iterator_tag, forward_iterator_tag)
{
// modeled after search algorithm
_ForwardIterator1 __r = __last1; // __last1 is the "default" answer
if (__first2 == __last2)
return __r;
while (true)
{
while (true)
{
if (__first1 == __last1) // if source exhausted return last correct answer
return __r; // (or __last1 if never found)
if (__pred(*__first1, *__first2))
break;
++__first1;
}
// *__first1 matches *__first2, now match elements after here
_ForwardIterator1 __m1 = __first1;
_ForwardIterator2 __m2 = __first2;
while (true)
{
if (++__m2 == __last2)
{ // Pattern exhaused, record answer and search for another one
__r = __first1;
++__first1;
break;
}
if (++__m1 == __last1) // Source exhausted, return last answer
return __r;
if (!__pred(*__m1, *__m2)) // mismatch, restart with a new __first
{
++__first1;
break;
} // else there is a match, check next elements
}
}
}
template <class _BinaryPredicate, class _BidirectionalIterator1, class _BidirectionalIterator2>
_LIBCPP_CONSTEXPR_AFTER_CXX17 _BidirectionalIterator1
__find_end(_BidirectionalIterator1 __first1, _BidirectionalIterator1 __last1,
_BidirectionalIterator2 __first2, _BidirectionalIterator2 __last2, _BinaryPredicate __pred,
bidirectional_iterator_tag, bidirectional_iterator_tag)
{
// modeled after search algorithm (in reverse)
if (__first2 == __last2)
return __last1; // Everything matches an empty sequence
_BidirectionalIterator1 __l1 = __last1;
_BidirectionalIterator2 __l2 = __last2;
--__l2;
while (true)
{
// Find last element in sequence 1 that matchs *(__last2-1), with a mininum of loop checks
while (true)
{
if (__first1 == __l1) // return __last1 if no element matches *__first2
return __last1;
if (__pred(*--__l1, *__l2))
break;
}
// *__l1 matches *__l2, now match elements before here
_BidirectionalIterator1 __m1 = __l1;
_BidirectionalIterator2 __m2 = __l2;
while (true)
{
if (__m2 == __first2) // If pattern exhausted, __m1 is the answer (works for 1 element pattern)
return __m1;
if (__m1 == __first1) // Otherwise if source exhaused, pattern not found
return __last1;
if (!__pred(*--__m1, *--__m2)) // if there is a mismatch, restart with a new __l1
{
break;
} // else there is a match, check next elements
}
}
}
template <class _BinaryPredicate, class _RandomAccessIterator1, class _RandomAccessIterator2>
_LIBCPP_CONSTEXPR_AFTER_CXX11 _RandomAccessIterator1
__find_end(_RandomAccessIterator1 __first1, _RandomAccessIterator1 __last1,
_RandomAccessIterator2 __first2, _RandomAccessIterator2 __last2, _BinaryPredicate __pred,
random_access_iterator_tag, random_access_iterator_tag)
{
// Take advantage of knowing source and pattern lengths. Stop short when source is smaller than pattern
typename iterator_traits<_RandomAccessIterator2>::difference_type __len2 = __last2 - __first2;
if (__len2 == 0)
return __last1;
typename iterator_traits<_RandomAccessIterator1>::difference_type __len1 = __last1 - __first1;
if (__len1 < __len2)
return __last1;
const _RandomAccessIterator1 __s = __first1 + (__len2 - 1); // End of pattern match can't go before here
_RandomAccessIterator1 __l1 = __last1;
_RandomAccessIterator2 __l2 = __last2;
--__l2;
while (true)
{
while (true)
{
if (__s == __l1)
return __last1;
if (__pred(*--__l1, *__l2))
break;
}
_RandomAccessIterator1 __m1 = __l1;
_RandomAccessIterator2 __m2 = __l2;
while (true)
{
if (__m2 == __first2)
return __m1;
// no need to check range on __m1 because __s guarantees we have enough source
if (!__pred(*--__m1, *--__m2))
{
break;
}
}
}
}
template <class _ForwardIterator1, class _ForwardIterator2, class _BinaryPredicate>
_LIBCPP_NODISCARD_EXT inline
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
_ForwardIterator1
find_end(_ForwardIterator1 __first1, _ForwardIterator1 __last1,
_ForwardIterator2 __first2, _ForwardIterator2 __last2, _BinaryPredicate __pred)
{
return _VSTD::__find_end<typename add_lvalue_reference<_BinaryPredicate>::type>
(__first1, __last1, __first2, __last2, __pred,
typename iterator_traits<_ForwardIterator1>::iterator_category(),
typename iterator_traits<_ForwardIterator2>::iterator_category());
}
template <class _ForwardIterator1, class _ForwardIterator2>
_LIBCPP_NODISCARD_EXT inline
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
_ForwardIterator1
find_end(_ForwardIterator1 __first1, _ForwardIterator1 __last1,
_ForwardIterator2 __first2, _ForwardIterator2 __last2)
{
typedef typename iterator_traits<_ForwardIterator1>::value_type __v1;
typedef typename iterator_traits<_ForwardIterator2>::value_type __v2;
return _VSTD::find_end(__first1, __last1, __first2, __last2, __equal_to<__v1, __v2>());
}
// find_first_of
template <class _ForwardIterator1, class _ForwardIterator2, class _BinaryPredicate>
_LIBCPP_CONSTEXPR_AFTER_CXX11 _ForwardIterator1
__find_first_of_ce(_ForwardIterator1 __first1, _ForwardIterator1 __last1,
_ForwardIterator2 __first2, _ForwardIterator2 __last2, _BinaryPredicate __pred)
{
for (; __first1 != __last1; ++__first1)
for (_ForwardIterator2 __j = __first2; __j != __last2; ++__j)
if (__pred(*__first1, *__j))
return __first1;
return __last1;
}
template <class _ForwardIterator1, class _ForwardIterator2, class _BinaryPredicate>
_LIBCPP_NODISCARD_EXT inline
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
_ForwardIterator1
find_first_of(_ForwardIterator1 __first1, _ForwardIterator1 __last1,
_ForwardIterator2 __first2, _ForwardIterator2 __last2, _BinaryPredicate __pred)
{
return _VSTD::__find_first_of_ce(__first1, __last1, __first2, __last2, __pred);
}
template <class _ForwardIterator1, class _ForwardIterator2>
_LIBCPP_NODISCARD_EXT inline
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
_ForwardIterator1
find_first_of(_ForwardIterator1 __first1, _ForwardIterator1 __last1,
_ForwardIterator2 __first2, _ForwardIterator2 __last2)
{
typedef typename iterator_traits<_ForwardIterator1>::value_type __v1;
typedef typename iterator_traits<_ForwardIterator2>::value_type __v2;
return _VSTD::__find_first_of_ce(__first1, __last1, __first2, __last2, __equal_to<__v1, __v2>());
}
// adjacent_find
template <class _ForwardIterator, class _BinaryPredicate>
_LIBCPP_NODISCARD_EXT inline
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
_ForwardIterator
adjacent_find(_ForwardIterator __first, _ForwardIterator __last, _BinaryPredicate __pred)
{
if (__first != __last)
{
_ForwardIterator __i = __first;
while (++__i != __last)
{
if (__pred(*__first, *__i))
return __first;
__first = __i;
}
}
return __last;
}
template <class _ForwardIterator>
_LIBCPP_NODISCARD_EXT inline
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
_ForwardIterator
adjacent_find(_ForwardIterator __first, _ForwardIterator __last)
{
typedef typename iterator_traits<_ForwardIterator>::value_type __v;
return _VSTD::adjacent_find(__first, __last, __equal_to<__v>());
}
// count
template <class _InputIterator, class _Tp>
_LIBCPP_NODISCARD_EXT inline
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
typename iterator_traits<_InputIterator>::difference_type
count(_InputIterator __first, _InputIterator __last, const _Tp& __value_)
{
typename iterator_traits<_InputIterator>::difference_type __r(0);
for (; __first != __last; ++__first)
if (*__first == __value_)
++__r;
return __r;
}
// count_if
template <class _InputIterator, class _Predicate>
_LIBCPP_NODISCARD_EXT inline
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
typename iterator_traits<_InputIterator>::difference_type
count_if(_InputIterator __first, _InputIterator __last, _Predicate __pred)
{
typename iterator_traits<_InputIterator>::difference_type __r(0);
for (; __first != __last; ++__first)
if (__pred(*__first))
++__r;
return __r;
}
// mismatch
template <class _InputIterator1, class _InputIterator2, class _BinaryPredicate>
_LIBCPP_NODISCARD_EXT inline
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
pair<_InputIterator1, _InputIterator2>
mismatch(_InputIterator1 __first1, _InputIterator1 __last1,
_InputIterator2 __first2, _BinaryPredicate __pred)
{
for (; __first1 != __last1; ++__first1, (void) ++__first2)
if (!__pred(*__first1, *__first2))
break;
return pair<_InputIterator1, _InputIterator2>(__first1, __first2);
}
template <class _InputIterator1, class _InputIterator2>
_LIBCPP_NODISCARD_EXT inline
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
pair<_InputIterator1, _InputIterator2>
mismatch(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2)
{
typedef typename iterator_traits<_InputIterator1>::value_type __v1;
typedef typename iterator_traits<_InputIterator2>::value_type __v2;
return _VSTD::mismatch(__first1, __last1, __first2, __equal_to<__v1, __v2>());
}
#if _LIBCPP_STD_VER > 11
template <class _InputIterator1, class _InputIterator2, class _BinaryPredicate>
_LIBCPP_NODISCARD_EXT inline
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
pair<_InputIterator1, _InputIterator2>
mismatch(_InputIterator1 __first1, _InputIterator1 __last1,
_InputIterator2 __first2, _InputIterator2 __last2,
_BinaryPredicate __pred)
{
for (; __first1 != __last1 && __first2 != __last2; ++__first1, (void) ++__first2)
if (!__pred(*__first1, *__first2))
break;
return pair<_InputIterator1, _InputIterator2>(__first1, __first2);
}
template <class _InputIterator1, class _InputIterator2>
_LIBCPP_NODISCARD_EXT inline
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
pair<_InputIterator1, _InputIterator2>
mismatch(_InputIterator1 __first1, _InputIterator1 __last1,
_InputIterator2 __first2, _InputIterator2 __last2)
{
typedef typename iterator_traits<_InputIterator1>::value_type __v1;
typedef typename iterator_traits<_InputIterator2>::value_type __v2;
return _VSTD::mismatch(__first1, __last1, __first2, __last2, __equal_to<__v1, __v2>());
}
#endif
// equal
template <class _InputIterator1, class _InputIterator2, class _BinaryPredicate>
_LIBCPP_NODISCARD_EXT inline
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
bool
equal(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2, _BinaryPredicate __pred)
{
for (; __first1 != __last1; ++__first1, (void) ++__first2)
if (!__pred(*__first1, *__first2))
return false;
return true;
}
template <class _InputIterator1, class _InputIterator2>
_LIBCPP_NODISCARD_EXT inline
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
bool
equal(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2)
{
typedef typename iterator_traits<_InputIterator1>::value_type __v1;
typedef typename iterator_traits<_InputIterator2>::value_type __v2;
return _VSTD::equal(__first1, __last1, __first2, __equal_to<__v1, __v2>());
}
#if _LIBCPP_STD_VER > 11
template <class _BinaryPredicate, class _InputIterator1, class _InputIterator2>
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
bool
__equal(_InputIterator1 __first1, _InputIterator1 __last1,
_InputIterator2 __first2, _InputIterator2 __last2, _BinaryPredicate __pred,
input_iterator_tag, input_iterator_tag )
{
for (; __first1 != __last1 && __first2 != __last2; ++__first1, (void) ++__first2)
if (!__pred(*__first1, *__first2))
return false;
return __first1 == __last1 && __first2 == __last2;
}
template <class _BinaryPredicate, class _RandomAccessIterator1, class _RandomAccessIterator2>
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
bool
__equal(_RandomAccessIterator1 __first1, _RandomAccessIterator1 __last1,
_RandomAccessIterator2 __first2, _RandomAccessIterator2 __last2, _BinaryPredicate __pred,
random_access_iterator_tag, random_access_iterator_tag )
{
if ( _VSTD::distance(__first1, __last1) != _VSTD::distance(__first2, __last2))
return false;
return _VSTD::equal<_RandomAccessIterator1, _RandomAccessIterator2,
typename add_lvalue_reference<_BinaryPredicate>::type>
(__first1, __last1, __first2, __pred );
}
template <class _InputIterator1, class _InputIterator2, class _BinaryPredicate>
_LIBCPP_NODISCARD_EXT inline
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
bool
equal(_InputIterator1 __first1, _InputIterator1 __last1,
_InputIterator2 __first2, _InputIterator2 __last2, _BinaryPredicate __pred )
{
return _VSTD::__equal<typename add_lvalue_reference<_BinaryPredicate>::type>
(__first1, __last1, __first2, __last2, __pred,
typename iterator_traits<_InputIterator1>::iterator_category(),
typename iterator_traits<_InputIterator2>::iterator_category());
}
template <class _InputIterator1, class _InputIterator2>
_LIBCPP_NODISCARD_EXT inline
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
bool
equal(_InputIterator1 __first1, _InputIterator1 __last1,
_InputIterator2 __first2, _InputIterator2 __last2)
{
typedef typename iterator_traits<_InputIterator1>::value_type __v1;
typedef typename iterator_traits<_InputIterator2>::value_type __v2;
return _VSTD::__equal(__first1, __last1, __first2, __last2, __equal_to<__v1, __v2>(),
typename iterator_traits<_InputIterator1>::iterator_category(),
typename iterator_traits<_InputIterator2>::iterator_category());
}
#endif
// is_permutation
template<class _ForwardIterator1, class _ForwardIterator2, class _BinaryPredicate>
_LIBCPP_NODISCARD_EXT _LIBCPP_CONSTEXPR_AFTER_CXX17 bool
is_permutation(_ForwardIterator1 __first1, _ForwardIterator1 __last1,
_ForwardIterator2 __first2, _BinaryPredicate __pred)
{
// shorten sequences as much as possible by lopping of any equal prefix
for (; __first1 != __last1; ++__first1, (void) ++__first2)
if (!__pred(*__first1, *__first2))
break;
if (__first1 == __last1)
return true;
// __first1 != __last1 && *__first1 != *__first2
typedef typename iterator_traits<_ForwardIterator1>::difference_type _D1;
_D1 __l1 = _VSTD::distance(__first1, __last1);
if (__l1 == _D1(1))
return false;
_ForwardIterator2 __last2 = _VSTD::next(__first2, __l1);
// For each element in [f1, l1) see if there are the same number of
// equal elements in [f2, l2)
for (_ForwardIterator1 __i = __first1; __i != __last1; ++__i)
{
// Have we already counted the number of *__i in [f1, l1)?
_ForwardIterator1 __match = __first1;
for (; __match != __i; ++__match)
if (__pred(*__match, *__i))
break;
if (__match == __i) {
// Count number of *__i in [f2, l2)
_D1 __c2 = 0;
for (_ForwardIterator2 __j = __first2; __j != __last2; ++__j)
if (__pred(*__i, *__j))
++__c2;
if (__c2 == 0)
return false;
// Count number of *__i in [__i, l1) (we can start with 1)
_D1 __c1 = 1;
for (_ForwardIterator1 __j = _VSTD::next(__i); __j != __last1; ++__j)
if (__pred(*__i, *__j))
++__c1;
if (__c1 != __c2)
return false;
}
}
return true;
}
template<class _ForwardIterator1, class _ForwardIterator2>
_LIBCPP_NODISCARD_EXT inline
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
bool
is_permutation(_ForwardIterator1 __first1, _ForwardIterator1 __last1,
_ForwardIterator2 __first2)
{
typedef typename iterator_traits<_ForwardIterator1>::value_type __v1;
typedef typename iterator_traits<_ForwardIterator2>::value_type __v2;
return _VSTD::is_permutation(__first1, __last1, __first2, __equal_to<__v1, __v2>());
}
#if _LIBCPP_STD_VER > 11
template<class _BinaryPredicate, class _ForwardIterator1, class _ForwardIterator2>
_LIBCPP_CONSTEXPR_AFTER_CXX17 bool
__is_permutation(_ForwardIterator1 __first1, _ForwardIterator1 __last1,
_ForwardIterator2 __first2, _ForwardIterator2 __last2,
_BinaryPredicate __pred,
forward_iterator_tag, forward_iterator_tag )
{
// shorten sequences as much as possible by lopping of any equal prefix
for (; __first1 != __last1 && __first2 != __last2; ++__first1, (void) ++__first2)
if (!__pred(*__first1, *__first2))
break;
if (__first1 == __last1)
return __first2 == __last2;
else if (__first2 == __last2)
return false;
typedef typename iterator_traits<_ForwardIterator1>::difference_type _D1;
_D1 __l1 = _VSTD::distance(__first1, __last1);
typedef typename iterator_traits<_ForwardIterator2>::difference_type _D2;
_D2 __l2 = _VSTD::distance(__first2, __last2);
if (__l1 != __l2)
return false;
// For each element in [f1, l1) see if there are the same number of
// equal elements in [f2, l2)
for (_ForwardIterator1 __i = __first1; __i != __last1; ++__i)
{
// Have we already counted the number of *__i in [f1, l1)?
_ForwardIterator1 __match = __first1;
for (; __match != __i; ++__match)
if (__pred(*__match, *__i))
break;
if (__match == __i) {
// Count number of *__i in [f2, l2)
_D1 __c2 = 0;
for (_ForwardIterator2 __j = __first2; __j != __last2; ++__j)
if (__pred(*__i, *__j))
++__c2;
if (__c2 == 0)
return false;
// Count number of *__i in [__i, l1) (we can start with 1)
_D1 __c1 = 1;
for (_ForwardIterator1 __j = _VSTD::next(__i); __j != __last1; ++__j)
if (__pred(*__i, *__j))
++__c1;
if (__c1 != __c2)
return false;
}
}
return true;
}
template<class _BinaryPredicate, class _RandomAccessIterator1, class _RandomAccessIterator2>
_LIBCPP_CONSTEXPR_AFTER_CXX17 bool
__is_permutation(_RandomAccessIterator1 __first1, _RandomAccessIterator2 __last1,
_RandomAccessIterator1 __first2, _RandomAccessIterator2 __last2,
_BinaryPredicate __pred,
random_access_iterator_tag, random_access_iterator_tag )
{
if ( _VSTD::distance(__first1, __last1) != _VSTD::distance(__first2, __last2))
return false;
return _VSTD::is_permutation<_RandomAccessIterator1, _RandomAccessIterator2,
typename add_lvalue_reference<_BinaryPredicate>::type>
(__first1, __last1, __first2, __pred );
}
template<class _ForwardIterator1, class _ForwardIterator2, class _BinaryPredicate>
_LIBCPP_NODISCARD_EXT inline
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
bool
is_permutation(_ForwardIterator1 __first1, _ForwardIterator1 __last1,
_ForwardIterator2 __first2, _ForwardIterator2 __last2,
_BinaryPredicate __pred )
{
return _VSTD::__is_permutation<typename add_lvalue_reference<_BinaryPredicate>::type>
(__first1, __last1, __first2, __last2, __pred,
typename iterator_traits<_ForwardIterator1>::iterator_category(),
typename iterator_traits<_ForwardIterator2>::iterator_category());
}
template<class _ForwardIterator1, class _ForwardIterator2>
_LIBCPP_NODISCARD_EXT inline
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
bool
is_permutation(_ForwardIterator1 __first1, _ForwardIterator1 __last1,
_ForwardIterator2 __first2, _ForwardIterator2 __last2)
{
typedef typename iterator_traits<_ForwardIterator1>::value_type __v1;
typedef typename iterator_traits<_ForwardIterator2>::value_type __v2;
return _VSTD::__is_permutation(__first1, __last1, __first2, __last2,
__equal_to<__v1, __v2>(),
typename iterator_traits<_ForwardIterator1>::iterator_category(),
typename iterator_traits<_ForwardIterator2>::iterator_category());
}
#endif
// search
// __search is in <functional>
template <class _ForwardIterator1, class _ForwardIterator2, class _BinaryPredicate>
_LIBCPP_NODISCARD_EXT inline
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
_ForwardIterator1
search(_ForwardIterator1 __first1, _ForwardIterator1 __last1,
_ForwardIterator2 __first2, _ForwardIterator2 __last2, _BinaryPredicate __pred)
{
return _VSTD::__search<typename add_lvalue_reference<_BinaryPredicate>::type>
(__first1, __last1, __first2, __last2, __pred,
typename iterator_traits<_ForwardIterator1>::iterator_category(),
typename iterator_traits<_ForwardIterator2>::iterator_category())
.first;
}
template <class _ForwardIterator1, class _ForwardIterator2>
_LIBCPP_NODISCARD_EXT inline
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
_ForwardIterator1
search(_ForwardIterator1 __first1, _ForwardIterator1 __last1,
_ForwardIterator2 __first2, _ForwardIterator2 __last2)
{
typedef typename iterator_traits<_ForwardIterator1>::value_type __v1;
typedef typename iterator_traits<_ForwardIterator2>::value_type __v2;
return _VSTD::search(__first1, __last1, __first2, __last2, __equal_to<__v1, __v2>());
}
#if _LIBCPP_STD_VER > 14
template <class _ForwardIterator, class _Searcher>
_LIBCPP_NODISCARD_EXT _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
_ForwardIterator search(_ForwardIterator __f, _ForwardIterator __l, const _Searcher &__s)
{ return __s(__f, __l).first; }
#endif
// search_n
template <class _BinaryPredicate, class _ForwardIterator, class _Size, class _Tp>
_LIBCPP_CONSTEXPR_AFTER_CXX17 _ForwardIterator
__search_n(_ForwardIterator __first, _ForwardIterator __last,
_Size __count, const _Tp& __value_, _BinaryPredicate __pred, forward_iterator_tag)
{
if (__count <= 0)
return __first;
while (true)
{
// Find first element in sequence that matchs __value_, with a mininum of loop checks
while (true)
{
if (__first == __last) // return __last if no element matches __value_
return __last;
if (__pred(*__first, __value_))
break;
++__first;
}
// *__first matches __value_, now match elements after here
_ForwardIterator __m = __first;
_Size __c(0);
while (true)
{
if (++__c == __count) // If pattern exhausted, __first is the answer (works for 1 element pattern)
return __first;
if (++__m == __last) // Otherwise if source exhaused, pattern not found
return __last;
if (!__pred(*__m, __value_)) // if there is a mismatch, restart with a new __first
{
__first = __m;
++__first;
break;
} // else there is a match, check next elements
}
}
}
template <class _BinaryPredicate, class _RandomAccessIterator, class _Size, class _Tp>
_LIBCPP_CONSTEXPR_AFTER_CXX17 _RandomAccessIterator
__search_n(_RandomAccessIterator __first, _RandomAccessIterator __last,
_Size __count, const _Tp& __value_, _BinaryPredicate __pred, random_access_iterator_tag)
{
if (__count <= 0)
return __first;
_Size __len = static_cast<_Size>(__last - __first);
if (__len < __count)
return __last;
const _RandomAccessIterator __s = __last - (__count - 1); // Start of pattern match can't go beyond here
while (true)
{
// Find first element in sequence that matchs __value_, with a mininum of loop checks
while (true)
{
if (__first >= __s) // return __last if no element matches __value_
return __last;
if (__pred(*__first, __value_))
break;
++__first;
}
// *__first matches __value_, now match elements after here
_RandomAccessIterator __m = __first;
_Size __c(0);
while (true)
{
if (++__c == __count) // If pattern exhausted, __first is the answer (works for 1 element pattern)
return __first;
++__m; // no need to check range on __m because __s guarantees we have enough source
if (!__pred(*__m, __value_)) // if there is a mismatch, restart with a new __first
{
__first = __m;
++__first;
break;
} // else there is a match, check next elements
}
}
}
template <class _ForwardIterator, class _Size, class _Tp, class _BinaryPredicate>
_LIBCPP_NODISCARD_EXT inline
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
_ForwardIterator
search_n(_ForwardIterator __first, _ForwardIterator __last,
_Size __count, const _Tp& __value_, _BinaryPredicate __pred)
{
return _VSTD::__search_n<typename add_lvalue_reference<_BinaryPredicate>::type>
(__first, __last, __convert_to_integral(__count), __value_, __pred,
typename iterator_traits<_ForwardIterator>::iterator_category());
}
template <class _ForwardIterator, class _Size, class _Tp>
_LIBCPP_NODISCARD_EXT inline
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
_ForwardIterator
search_n(_ForwardIterator __first, _ForwardIterator __last, _Size __count, const _Tp& __value_)
{
typedef typename iterator_traits<_ForwardIterator>::value_type __v;
return _VSTD::search_n(__first, __last, __convert_to_integral(__count),
__value_, __equal_to<__v, _Tp>());
}
// copy
template <class _Iter>
inline _LIBCPP_INLINE_VISIBILITY
_Iter
__unwrap_iter(_Iter __i)
{
return __i;
}
template <class _Tp>
inline _LIBCPP_INLINE_VISIBILITY
typename enable_if
<
is_trivially_copy_assignable<_Tp>::value,
_Tp*
>::type
__unwrap_iter(move_iterator<_Tp*> __i)
{
return __i.base();
}
#if _LIBCPP_DEBUG_LEVEL < 2
template <class _Tp>
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
typename enable_if
<
is_trivially_copy_assignable<_Tp>::value,
_Tp*
>::type
__unwrap_iter(__wrap_iter<_Tp*> __i)
{
return __i.base();
}
template <class _Tp>
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
typename enable_if
<
is_trivially_copy_assignable<_Tp>::value,
const _Tp*
>::type
__unwrap_iter(__wrap_iter<const _Tp*> __i)
{
return __i.base();
}
#else
template <class _Tp>
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_IF_NODEBUG
typename enable_if
<
is_trivially_copy_assignable<_Tp>::value,
__wrap_iter<_Tp*>
>::type
__unwrap_iter(__wrap_iter<_Tp*> __i)
{
return __i;
}
#endif // _LIBCPP_DEBUG_LEVEL < 2
template <class _InputIterator, class _OutputIterator>
inline _LIBCPP_INLINE_VISIBILITY
_OutputIterator
__copy(_InputIterator __first, _InputIterator __last, _OutputIterator __result)
{
for (; __first != __last; ++__first, (void) ++__result)
*__result = *__first;
return __result;
}
template <class _Tp, class _Up>
inline _LIBCPP_INLINE_VISIBILITY
typename enable_if
<
is_same<typename remove_const<_Tp>::type, _Up>::value &&
is_trivially_copy_assignable<_Up>::value,
_Up*
>::type
__copy(_Tp* __first, _Tp* __last, _Up* __result)
{
const size_t __n = static_cast<size_t>(__last - __first);
if (__n > 0)
_VSTD::memmove(__result, __first, __n * sizeof(_Up));
return __result + __n;
}
template <class _InputIterator, class _OutputIterator>
inline _LIBCPP_INLINE_VISIBILITY
_OutputIterator
copy(_InputIterator __first, _InputIterator __last, _OutputIterator __result)
{
return _VSTD::__copy(__unwrap_iter(__first), __unwrap_iter(__last), __unwrap_iter(__result));
}
// copy_backward
template <class _BidirectionalIterator, class _OutputIterator>
inline _LIBCPP_INLINE_VISIBILITY
_OutputIterator
__copy_backward(_BidirectionalIterator __first, _BidirectionalIterator __last, _OutputIterator __result)
{
while (__first != __last)
*--__result = *--__last;
return __result;
}
template <class _Tp, class _Up>
inline _LIBCPP_INLINE_VISIBILITY
typename enable_if
<
is_same<typename remove_const<_Tp>::type, _Up>::value &&
is_trivially_copy_assignable<_Up>::value,
_Up*
>::type
__copy_backward(_Tp* __first, _Tp* __last, _Up* __result)
{
const size_t __n = static_cast<size_t>(__last - __first);
if (__n > 0)
{
__result -= __n;
_VSTD::memmove(__result, __first, __n * sizeof(_Up));
}
return __result;
}
template <class _BidirectionalIterator1, class _BidirectionalIterator2>
inline _LIBCPP_INLINE_VISIBILITY
_BidirectionalIterator2
copy_backward(_BidirectionalIterator1 __first, _BidirectionalIterator1 __last,
_BidirectionalIterator2 __result)
{
return _VSTD::__copy_backward(__unwrap_iter(__first),
__unwrap_iter(__last),
__unwrap_iter(__result));
}
// copy_if
template<class _InputIterator, class _OutputIterator, class _Predicate>
inline _LIBCPP_INLINE_VISIBILITY
_OutputIterator
copy_if(_InputIterator __first, _InputIterator __last,
_OutputIterator __result, _Predicate __pred)
{
for (; __first != __last; ++__first)
{
if (__pred(*__first))
{
*__result = *__first;
++__result;
}
}
return __result;
}
// copy_n
template<class _InputIterator, class _Size, class _OutputIterator>
inline _LIBCPP_INLINE_VISIBILITY
typename enable_if
<
__is_input_iterator<_InputIterator>::value &&
!__is_random_access_iterator<_InputIterator>::value,
_OutputIterator
>::type
copy_n(_InputIterator __first, _Size __orig_n, _OutputIterator __result)
{
typedef decltype(__convert_to_integral(__orig_n)) _IntegralSize;
_IntegralSize __n = __orig_n;
if (__n > 0)
{
*__result = *__first;
++__result;
for (--__n; __n > 0; --__n)
{
++__first;
*__result = *__first;
++__result;
}
}
return __result;
}
template<class _InputIterator, class _Size, class _OutputIterator>
inline _LIBCPP_INLINE_VISIBILITY
typename enable_if
<
__is_random_access_iterator<_InputIterator>::value,
_OutputIterator
>::type
copy_n(_InputIterator __first, _Size __orig_n, _OutputIterator __result)
{
typedef decltype(__convert_to_integral(__orig_n)) _IntegralSize;
_IntegralSize __n = __orig_n;
return _VSTD::copy(__first, __first + __n, __result);
}
// move
template <class _InputIterator, class _OutputIterator>
inline _LIBCPP_INLINE_VISIBILITY
_OutputIterator
__move(_InputIterator __first, _InputIterator __last, _OutputIterator __result)
{
for (; __first != __last; ++__first, (void) ++__result)
*__result = _VSTD::move(*__first);
return __result;
}
template <class _Tp, class _Up>
inline _LIBCPP_INLINE_VISIBILITY
typename enable_if
<
is_same<typename remove_const<_Tp>::type, _Up>::value &&
is_trivially_copy_assignable<_Up>::value,
_Up*
>::type
__move(_Tp* __first, _Tp* __last, _Up* __result)
{
const size_t __n = static_cast<size_t>(__last - __first);
if (__n > 0)
_VSTD::memmove(__result, __first, __n * sizeof(_Up));
return __result + __n;
}
template <class _InputIterator, class _OutputIterator>
inline _LIBCPP_INLINE_VISIBILITY
_OutputIterator
move(_InputIterator __first, _InputIterator __last, _OutputIterator __result)
{
return _VSTD::__move(__unwrap_iter(__first), __unwrap_iter(__last), __unwrap_iter(__result));
}
// move_backward
template <class _InputIterator, class _OutputIterator>
inline _LIBCPP_INLINE_VISIBILITY
_OutputIterator
__move_backward(_InputIterator __first, _InputIterator __last, _OutputIterator __result)
{
while (__first != __last)
*--__result = _VSTD::move(*--__last);
return __result;
}
template <class _Tp, class _Up>
inline _LIBCPP_INLINE_VISIBILITY
typename enable_if
<
is_same<typename remove_const<_Tp>::type, _Up>::value &&
is_trivially_copy_assignable<_Up>::value,
_Up*
>::type
__move_backward(_Tp* __first, _Tp* __last, _Up* __result)
{
const size_t __n = static_cast<size_t>(__last - __first);
if (__n > 0)
{
__result -= __n;
_VSTD::memmove(__result, __first, __n * sizeof(_Up));
}
return __result;
}
template <class _BidirectionalIterator1, class _BidirectionalIterator2>
inline _LIBCPP_INLINE_VISIBILITY
_BidirectionalIterator2
move_backward(_BidirectionalIterator1 __first, _BidirectionalIterator1 __last,
_BidirectionalIterator2 __result)
{
return _VSTD::__move_backward(__unwrap_iter(__first), __unwrap_iter(__last), __unwrap_iter(__result));
}
// iter_swap
// moved to <type_traits> for better swap / noexcept support
// transform
template <class _InputIterator, class _OutputIterator, class _UnaryOperation>
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
_OutputIterator
transform(_InputIterator __first, _InputIterator __last, _OutputIterator __result, _UnaryOperation __op)
{
for (; __first != __last; ++__first, (void) ++__result)
*__result = __op(*__first);
return __result;
}
template <class _InputIterator1, class _InputIterator2, class _OutputIterator, class _BinaryOperation>
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
_OutputIterator
transform(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2,
_OutputIterator __result, _BinaryOperation __binary_op)
{
for (; __first1 != __last1; ++__first1, (void) ++__first2, ++__result)
*__result = __binary_op(*__first1, *__first2);
return __result;
}
// replace
template <class _ForwardIterator, class _Tp>
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
void
replace(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __old_value, const _Tp& __new_value)
{
for (; __first != __last; ++__first)
if (*__first == __old_value)
*__first = __new_value;
}
// replace_if
template <class _ForwardIterator, class _Predicate, class _Tp>
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
void
replace_if(_ForwardIterator __first, _ForwardIterator __last, _Predicate __pred, const _Tp& __new_value)
{
for (; __first != __last; ++__first)
if (__pred(*__first))
*__first = __new_value;
}
// replace_copy
template <class _InputIterator, class _OutputIterator, class _Tp>
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
_OutputIterator
replace_copy(_InputIterator __first, _InputIterator __last, _OutputIterator __result,
const _Tp& __old_value, const _Tp& __new_value)
{
for (; __first != __last; ++__first, (void) ++__result)
if (*__first == __old_value)
*__result = __new_value;
else
*__result = *__first;
return __result;
}
// replace_copy_if
template <class _InputIterator, class _OutputIterator, class _Predicate, class _Tp>
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
_OutputIterator
replace_copy_if(_InputIterator __first, _InputIterator __last, _OutputIterator __result,
_Predicate __pred, const _Tp& __new_value)
{
for (; __first != __last; ++__first, (void) ++__result)
if (__pred(*__first))
*__result = __new_value;
else
*__result = *__first;
return __result;
}
// fill_n
template <class _OutputIterator, class _Size, class _Tp>
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
_OutputIterator
__fill_n(_OutputIterator __first, _Size __n, const _Tp& __value_)
{
for (; __n > 0; ++__first, (void) --__n)
*__first = __value_;
return __first;
}
template <class _OutputIterator, class _Size, class _Tp>
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
_OutputIterator
fill_n(_OutputIterator __first, _Size __n, const _Tp& __value_)
{
return _VSTD::__fill_n(__first, __convert_to_integral(__n), __value_);
}
// fill
template <class _ForwardIterator, class _Tp>
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
void
__fill(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value_, forward_iterator_tag)
{
for (; __first != __last; ++__first)
*__first = __value_;
}
template <class _RandomAccessIterator, class _Tp>
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
void
__fill(_RandomAccessIterator __first, _RandomAccessIterator __last, const _Tp& __value_, random_access_iterator_tag)
{
_VSTD::fill_n(__first, __last - __first, __value_);
}
template <class _ForwardIterator, class _Tp>
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
void
fill(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value_)
{
_VSTD::__fill(__first, __last, __value_, typename iterator_traits<_ForwardIterator>::iterator_category());
}
// generate
template <class _ForwardIterator, class _Generator>
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
void
generate(_ForwardIterator __first, _ForwardIterator __last, _Generator __gen)
{
for (; __first != __last; ++__first)
*__first = __gen();
}
// generate_n
template <class _OutputIterator, class _Size, class _Generator>
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
_OutputIterator
generate_n(_OutputIterator __first, _Size __orig_n, _Generator __gen)
{
typedef decltype(__convert_to_integral(__orig_n)) _IntegralSize;
_IntegralSize __n = __orig_n;
for (; __n > 0; ++__first, (void) --__n)
*__first = __gen();
return __first;
}
// remove
template <class _ForwardIterator, class _Tp>
_LIBCPP_NODISCARD_EXT _LIBCPP_CONSTEXPR_AFTER_CXX17 _ForwardIterator
remove(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value_)
{
__first = _VSTD::find(__first, __last, __value_);
if (__first != __last)
{
_ForwardIterator __i = __first;
while (++__i != __last)
{
if (!(*__i == __value_))
{
*__first = _VSTD::move(*__i);
++__first;
}
}
}
return __first;
}
// remove_if
template <class _ForwardIterator, class _Predicate>
_LIBCPP_NODISCARD_EXT _LIBCPP_CONSTEXPR_AFTER_CXX17 _ForwardIterator
remove_if(_ForwardIterator __first, _ForwardIterator __last, _Predicate __pred)
{
__first = _VSTD::find_if<_ForwardIterator, typename add_lvalue_reference<_Predicate>::type>
(__first, __last, __pred);
if (__first != __last)
{
_ForwardIterator __i = __first;
while (++__i != __last)
{
if (!__pred(*__i))
{
*__first = _VSTD::move(*__i);
++__first;
}
}
}
return __first;
}
// remove_copy
template <class _InputIterator, class _OutputIterator, class _Tp>
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
_OutputIterator
remove_copy(_InputIterator __first, _InputIterator __last, _OutputIterator __result, const _Tp& __value_)
{
for (; __first != __last; ++__first)
{
if (!(*__first == __value_))
{
*__result = *__first;
++__result;
}
}
return __result;
}
// remove_copy_if
template <class _InputIterator, class _OutputIterator, class _Predicate>
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
_OutputIterator
remove_copy_if(_InputIterator __first, _InputIterator __last, _OutputIterator __result, _Predicate __pred)
{
for (; __first != __last; ++__first)
{
if (!__pred(*__first))
{
*__result = *__first;
++__result;
}
}
return __result;
}
// unique
template <class _ForwardIterator, class _BinaryPredicate>
_LIBCPP_NODISCARD_EXT _LIBCPP_CONSTEXPR_AFTER_CXX17 _ForwardIterator
unique(_ForwardIterator __first, _ForwardIterator __last, _BinaryPredicate __pred)
{
__first = _VSTD::adjacent_find<_ForwardIterator, typename add_lvalue_reference<_BinaryPredicate>::type>
(__first, __last, __pred);
if (__first != __last)
{
// ... a a ? ...
// f i
_ForwardIterator __i = __first;
for (++__i; ++__i != __last;)
if (!__pred(*__first, *__i))
*++__first = _VSTD::move(*__i);
++__first;
}
return __first;
}
template <class _ForwardIterator>
_LIBCPP_NODISCARD_EXT inline
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
_ForwardIterator
unique(_ForwardIterator __first, _ForwardIterator __last)
{
typedef typename iterator_traits<_ForwardIterator>::value_type __v;
return _VSTD::unique(__first, __last, __equal_to<__v>());
}
// unique_copy
template <class _BinaryPredicate, class _InputIterator, class _OutputIterator>
_LIBCPP_CONSTEXPR_AFTER_CXX17 _OutputIterator
__unique_copy(_InputIterator __first, _InputIterator __last, _OutputIterator __result, _BinaryPredicate __pred,
input_iterator_tag, output_iterator_tag)
{
if (__first != __last)
{
typename iterator_traits<_InputIterator>::value_type __t(*__first);
*__result = __t;
++__result;
while (++__first != __last)
{
if (!__pred(__t, *__first))
{
__t = *__first;
*__result = __t;
++__result;
}
}
}
return __result;
}
template <class _BinaryPredicate, class _ForwardIterator, class _OutputIterator>
_LIBCPP_CONSTEXPR_AFTER_CXX17 _OutputIterator
__unique_copy(_ForwardIterator __first, _ForwardIterator __last, _OutputIterator __result, _BinaryPredicate __pred,
forward_iterator_tag, output_iterator_tag)
{
if (__first != __last)
{
_ForwardIterator __i = __first;
*__result = *__i;
++__result;
while (++__first != __last)
{
if (!__pred(*__i, *__first))
{
*__result = *__first;
++__result;
__i = __first;
}
}
}
return __result;
}
template <class _BinaryPredicate, class _InputIterator, class _ForwardIterator>
_LIBCPP_CONSTEXPR_AFTER_CXX17 _ForwardIterator
__unique_copy(_InputIterator __first, _InputIterator __last, _ForwardIterator __result, _BinaryPredicate __pred,
input_iterator_tag, forward_iterator_tag)
{
if (__first != __last)
{
*__result = *__first;
while (++__first != __last)
if (!__pred(*__result, *__first))
*++__result = *__first;
++__result;
}
return __result;
}
template <class _InputIterator, class _OutputIterator, class _BinaryPredicate>
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
_OutputIterator
unique_copy(_InputIterator __first, _InputIterator __last, _OutputIterator __result, _BinaryPredicate __pred)
{
return _VSTD::__unique_copy<typename add_lvalue_reference<_BinaryPredicate>::type>
(__first, __last, __result, __pred,
typename iterator_traits<_InputIterator>::iterator_category(),
typename iterator_traits<_OutputIterator>::iterator_category());
}
template <class _InputIterator, class _OutputIterator>
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
_OutputIterator
unique_copy(_InputIterator __first, _InputIterator __last, _OutputIterator __result)
{
typedef typename iterator_traits<_InputIterator>::value_type __v;
return _VSTD::unique_copy(__first, __last, __result, __equal_to<__v>());
}
// reverse
template <class _BidirectionalIterator>
inline _LIBCPP_INLINE_VISIBILITY
void
__reverse(_BidirectionalIterator __first, _BidirectionalIterator __last, bidirectional_iterator_tag)
{
while (__first != __last)
{
if (__first == --__last)
break;
_VSTD::iter_swap(__first, __last);
++__first;
}
}
template <class _RandomAccessIterator>
inline _LIBCPP_INLINE_VISIBILITY
void
__reverse(_RandomAccessIterator __first, _RandomAccessIterator __last, random_access_iterator_tag)
{
if (__first != __last)
for (; __first < --__last; ++__first)
_VSTD::iter_swap(__first, __last);
}
template <class _BidirectionalIterator>
inline _LIBCPP_INLINE_VISIBILITY
void
reverse(_BidirectionalIterator __first, _BidirectionalIterator __last)
{
_VSTD::__reverse(__first, __last, typename iterator_traits<_BidirectionalIterator>::iterator_category());
}
// reverse_copy
template <class _BidirectionalIterator, class _OutputIterator>
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
_OutputIterator
reverse_copy(_BidirectionalIterator __first, _BidirectionalIterator __last, _OutputIterator __result)
{
for (; __first != __last; ++__result)
*__result = *--__last;
return __result;
}
// rotate
template <class _ForwardIterator>
_ForwardIterator
__rotate_left(_ForwardIterator __first, _ForwardIterator __last)
{
typedef typename iterator_traits<_ForwardIterator>::value_type value_type;
value_type __tmp = _VSTD::move(*__first);
_ForwardIterator __lm1 = _VSTD::move(_VSTD::next(__first), __last, __first);
*__lm1 = _VSTD::move(__tmp);
return __lm1;
}
template <class _BidirectionalIterator>
_BidirectionalIterator
__rotate_right(_BidirectionalIterator __first, _BidirectionalIterator __last)
{
typedef typename iterator_traits<_BidirectionalIterator>::value_type value_type;
_BidirectionalIterator __lm1 = _VSTD::prev(__last);
value_type __tmp = _VSTD::move(*__lm1);
_BidirectionalIterator __fp1 = _VSTD::move_backward(__first, __lm1, __last);
*__first = _VSTD::move(__tmp);
return __fp1;
}
template <class _ForwardIterator>
_ForwardIterator
__rotate_forward(_ForwardIterator __first, _ForwardIterator __middle, _ForwardIterator __last)
{
_ForwardIterator __i = __middle;
while (true)
{
swap(*__first, *__i);
++__first;
if (++__i == __last)
break;
if (__first == __middle)
__middle = __i;
}
_ForwardIterator __r = __first;
if (__first != __middle)
{
__i = __middle;
while (true)
{
swap(*__first, *__i);
++__first;
if (++__i == __last)
{
if (__first == __middle)
break;
__i = __middle;
}
else if (__first == __middle)
__middle = __i;
}
}
return __r;
}
template<typename _Integral>
inline _LIBCPP_INLINE_VISIBILITY
_Integral
__algo_gcd(_Integral __x, _Integral __y)
{
do
{
_Integral __t = __x % __y;
__x = __y;
__y = __t;
} while (__y);
return __x;
}
template<typename _RandomAccessIterator>
_RandomAccessIterator
__rotate_gcd(_RandomAccessIterator __first, _RandomAccessIterator __middle, _RandomAccessIterator __last)
{
typedef typename iterator_traits<_RandomAccessIterator>::difference_type difference_type;
typedef typename iterator_traits<_RandomAccessIterator>::value_type value_type;
const difference_type __m1 = __middle - __first;
const difference_type __m2 = __last - __middle;
if (__m1 == __m2)
{
_VSTD::swap_ranges(__first, __middle, __middle);
return __middle;
}
const difference_type __g = _VSTD::__algo_gcd(__m1, __m2);
for (_RandomAccessIterator __p = __first + __g; __p != __first;)
{
value_type __t(_VSTD::move(*--__p));
_RandomAccessIterator __p1 = __p;
_RandomAccessIterator __p2 = __p1 + __m1;
do
{
*__p1 = _VSTD::move(*__p2);
__p1 = __p2;
const difference_type __d = __last - __p2;
if (__m1 < __d)
__p2 += __m1;
else
__p2 = __first + (__m1 - __d);
} while (__p2 != __p);
*__p1 = _VSTD::move(__t);
}
return __first + __m2;
}
template <class _ForwardIterator>
inline _LIBCPP_INLINE_VISIBILITY
_ForwardIterator
__rotate(_ForwardIterator __first, _ForwardIterator __middle, _ForwardIterator __last,
_VSTD::forward_iterator_tag)
{
typedef typename _VSTD::iterator_traits<_ForwardIterator>::value_type value_type;
if (_VSTD::is_trivially_move_assignable<value_type>::value)
{
if (_VSTD::next(__first) == __middle)
return _VSTD::__rotate_left(__first, __last);
}
return _VSTD::__rotate_forward(__first, __middle, __last);
}
template <class _BidirectionalIterator>
inline _LIBCPP_INLINE_VISIBILITY
_BidirectionalIterator
__rotate(_BidirectionalIterator __first, _BidirectionalIterator __middle, _BidirectionalIterator __last,
_VSTD::bidirectional_iterator_tag)
{
typedef typename _VSTD::iterator_traits<_BidirectionalIterator>::value_type value_type;
if (_VSTD::is_trivially_move_assignable<value_type>::value)
{
if (_VSTD::next(__first) == __middle)
return _VSTD::__rotate_left(__first, __last);
if (_VSTD::next(__middle) == __last)
return _VSTD::__rotate_right(__first, __last);
}
return _VSTD::__rotate_forward(__first, __middle, __last);
}
template <class _RandomAccessIterator>
inline _LIBCPP_INLINE_VISIBILITY
_RandomAccessIterator
__rotate(_RandomAccessIterator __first, _RandomAccessIterator __middle, _RandomAccessIterator __last,
_VSTD::random_access_iterator_tag)
{
typedef typename _VSTD::iterator_traits<_RandomAccessIterator>::value_type value_type;
if (_VSTD::is_trivially_move_assignable<value_type>::value)
{
if (_VSTD::next(__first) == __middle)
return _VSTD::__rotate_left(__first, __last);
if (_VSTD::next(__middle) == __last)
return _VSTD::__rotate_right(__first, __last);
return _VSTD::__rotate_gcd(__first, __middle, __last);
}
return _VSTD::__rotate_forward(__first, __middle, __last);
}
template <class _ForwardIterator>
inline _LIBCPP_INLINE_VISIBILITY
_ForwardIterator
rotate(_ForwardIterator __first, _ForwardIterator __middle, _ForwardIterator __last)
{
if (__first == __middle)
return __last;
if (__middle == __last)
return __first;
return _VSTD::__rotate(__first, __middle, __last,
typename _VSTD::iterator_traits<_ForwardIterator>::iterator_category());
}
// rotate_copy
template <class _ForwardIterator, class _OutputIterator>
inline _LIBCPP_INLINE_VISIBILITY
_OutputIterator
rotate_copy(_ForwardIterator __first, _ForwardIterator __middle, _ForwardIterator __last, _OutputIterator __result)
{
return _VSTD::copy(__first, __middle, _VSTD::copy(__middle, __last, __result));
}
// min_element
template <class _ForwardIterator, class _Compare>
_LIBCPP_NODISCARD_EXT inline
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
_ForwardIterator
min_element(_ForwardIterator __first, _ForwardIterator __last, _Compare __comp)
{
static_assert(__is_forward_iterator<_ForwardIterator>::value,
"std::min_element requires a ForwardIterator");
if (__first != __last)
{
_ForwardIterator __i = __first;
while (++__i != __last)
if (__comp(*__i, *__first))
__first = __i;
}
return __first;
}
template <class _ForwardIterator>
_LIBCPP_NODISCARD_EXT inline
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
_ForwardIterator
min_element(_ForwardIterator __first, _ForwardIterator __last)
{
return _VSTD::min_element(__first, __last,
__less<typename iterator_traits<_ForwardIterator>::value_type>());
}
// min
template <class _Tp, class _Compare>
_LIBCPP_NODISCARD_EXT inline
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
const _Tp&
min(const _Tp& __a, const _Tp& __b, _Compare __comp)
{
return __comp(__b, __a) ? __b : __a;
}
template <class _Tp>
_LIBCPP_NODISCARD_EXT inline
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
const _Tp&
min(const _Tp& __a, const _Tp& __b)
{
return _VSTD::min(__a, __b, __less<_Tp>());
}
#ifndef _LIBCPP_CXX03_LANG
template<class _Tp, class _Compare>
_LIBCPP_NODISCARD_EXT inline
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
_Tp
min(initializer_list<_Tp> __t, _Compare __comp)
{
return *_VSTD::min_element(__t.begin(), __t.end(), __comp);
}
template<class _Tp>
_LIBCPP_NODISCARD_EXT inline
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
_Tp
min(initializer_list<_Tp> __t)
{
return *_VSTD::min_element(__t.begin(), __t.end(), __less<_Tp>());
}
#endif // _LIBCPP_CXX03_LANG
// max_element
template <class _ForwardIterator, class _Compare>
_LIBCPP_NODISCARD_EXT inline
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
_ForwardIterator
max_element(_ForwardIterator __first, _ForwardIterator __last, _Compare __comp)
{
static_assert(__is_forward_iterator<_ForwardIterator>::value,
"std::max_element requires a ForwardIterator");
if (__first != __last)
{
_ForwardIterator __i = __first;
while (++__i != __last)
if (__comp(*__first, *__i))
__first = __i;
}
return __first;
}
template <class _ForwardIterator>
_LIBCPP_NODISCARD_EXT inline
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
_ForwardIterator
max_element(_ForwardIterator __first, _ForwardIterator __last)
{
return _VSTD::max_element(__first, __last,
__less<typename iterator_traits<_ForwardIterator>::value_type>());
}
// max
template <class _Tp, class _Compare>
_LIBCPP_NODISCARD_EXT inline
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
const _Tp&
max(const _Tp& __a, const _Tp& __b, _Compare __comp)
{
return __comp(__a, __b) ? __b : __a;
}
template <class _Tp>
_LIBCPP_NODISCARD_EXT inline
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
const _Tp&
max(const _Tp& __a, const _Tp& __b)
{
return _VSTD::max(__a, __b, __less<_Tp>());
}
#ifndef _LIBCPP_CXX03_LANG
template<class _Tp, class _Compare>
_LIBCPP_NODISCARD_EXT inline
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
_Tp
max(initializer_list<_Tp> __t, _Compare __comp)
{
return *_VSTD::max_element(__t.begin(), __t.end(), __comp);
}
template<class _Tp>
_LIBCPP_NODISCARD_EXT inline
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
_Tp
max(initializer_list<_Tp> __t)
{
return *_VSTD::max_element(__t.begin(), __t.end(), __less<_Tp>());
}
#endif // _LIBCPP_CXX03_LANG
#if _LIBCPP_STD_VER > 14
// clamp
template<class _Tp, class _Compare>
_LIBCPP_NODISCARD_EXT inline
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
const _Tp&
clamp(const _Tp& __v, const _Tp& __lo, const _Tp& __hi, _Compare __comp)
{
_LIBCPP_ASSERT(!__comp(__hi, __lo), "Bad bounds passed to std::clamp");
return __comp(__v, __lo) ? __lo : __comp(__hi, __v) ? __hi : __v;
}
template<class _Tp>
_LIBCPP_NODISCARD_EXT inline
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
const _Tp&
clamp(const _Tp& __v, const _Tp& __lo, const _Tp& __hi)
{
return _VSTD::clamp(__v, __lo, __hi, __less<_Tp>());
}
#endif
// minmax_element
template <class _ForwardIterator, class _Compare>
_LIBCPP_NODISCARD_EXT _LIBCPP_CONSTEXPR_AFTER_CXX11
std::pair<_ForwardIterator, _ForwardIterator>
minmax_element(_ForwardIterator __first, _ForwardIterator __last, _Compare __comp)
{
static_assert(__is_forward_iterator<_ForwardIterator>::value,
"std::minmax_element requires a ForwardIterator");
std::pair<_ForwardIterator, _ForwardIterator> __result(__first, __first);
if (__first != __last)
{
if (++__first != __last)
{
if (__comp(*__first, *__result.first))
__result.first = __first;
else
__result.second = __first;
while (++__first != __last)
{
_ForwardIterator __i = __first;
if (++__first == __last)
{
if (__comp(*__i, *__result.first))
__result.first = __i;
else if (!__comp(*__i, *__result.second))
__result.second = __i;
break;
}
else
{
if (__comp(*__first, *__i))
{
if (__comp(*__first, *__result.first))
__result.first = __first;
if (!__comp(*__i, *__result.second))
__result.second = __i;
}
else
{
if (__comp(*__i, *__result.first))
__result.first = __i;
if (!__comp(*__first, *__result.second))
__result.second = __first;
}
}
}
}
}
return __result;
}
template <class _ForwardIterator>
_LIBCPP_NODISCARD_EXT inline
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
std::pair<_ForwardIterator, _ForwardIterator>
minmax_element(_ForwardIterator __first, _ForwardIterator __last)
{
return _VSTD::minmax_element(__first, __last,
__less<typename iterator_traits<_ForwardIterator>::value_type>());
}
// minmax
template<class _Tp, class _Compare>
_LIBCPP_NODISCARD_EXT inline
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
pair<const _Tp&, const _Tp&>
minmax(const _Tp& __a, const _Tp& __b, _Compare __comp)
{
return __comp(__b, __a) ? pair<const _Tp&, const _Tp&>(__b, __a) :
pair<const _Tp&, const _Tp&>(__a, __b);
}
template<class _Tp>
_LIBCPP_NODISCARD_EXT inline
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
pair<const _Tp&, const _Tp&>
minmax(const _Tp& __a, const _Tp& __b)
{
return _VSTD::minmax(__a, __b, __less<_Tp>());
}
#ifndef _LIBCPP_CXX03_LANG
template<class _Tp, class _Compare>
_LIBCPP_NODISCARD_EXT inline
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
pair<_Tp, _Tp>
minmax(initializer_list<_Tp> __t, _Compare __comp)
{
typedef typename initializer_list<_Tp>::const_iterator _Iter;
_Iter __first = __t.begin();
_Iter __last = __t.end();
std::pair<_Tp, _Tp> __result(*__first, *__first);
++__first;
if (__t.size() % 2 == 0)
{
if (__comp(*__first, __result.first))
__result.first = *__first;
else
__result.second = *__first;
++__first;
}
while (__first != __last)
{
_Tp __prev = *__first++;
if (__comp(*__first, __prev)) {
if ( __comp(*__first, __result.first)) __result.first = *__first;
if (!__comp(__prev, __result.second)) __result.second = __prev;
}
else {
if ( __comp(__prev, __result.first)) __result.first = __prev;
if (!__comp(*__first, __result.second)) __result.second = *__first;
}
__first++;
}
return __result;
}
template<class _Tp>
_LIBCPP_NODISCARD_EXT inline
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
pair<_Tp, _Tp>
minmax(initializer_list<_Tp> __t)
{
return _VSTD::minmax(__t, __less<_Tp>());
}
#endif // _LIBCPP_CXX03_LANG
// random_shuffle
// __independent_bits_engine
template <unsigned long long _Xp, size_t _Rp>
struct __log2_imp
{
static const size_t value = _Xp & ((unsigned long long)(1) << _Rp) ? _Rp
: __log2_imp<_Xp, _Rp - 1>::value;
};
template <unsigned long long _Xp>
struct __log2_imp<_Xp, 0>
{
static const size_t value = 0;
};
template <size_t _Rp>
struct __log2_imp<0, _Rp>
{
static const size_t value = _Rp + 1;
};
template <class _UIntType, _UIntType _Xp>
struct __log2
{
static const size_t value = __log2_imp<_Xp,
sizeof(_UIntType) * __CHAR_BIT__ - 1>::value;
};
template<class _Engine, class _UIntType>
class __independent_bits_engine
{
public:
// types
typedef _UIntType result_type;
private:
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;
_Engine& __e_;
size_t __w_;
size_t __w0_;
size_t __n_;
size_t __n0_;
_Working_result_type __y0_;
_Working_result_type __y1_;
_Engine_result_type __mask0_;
_Engine_result_type __mask1_;
#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 _WDt = numeric_limits<_Working_result_type>::digits;
static _LIBCPP_CONSTEXPR const size_t _EDt = numeric_limits<_Engine_result_type>::digits;
public:
// constructors and seeding functions
__independent_bits_engine(_Engine& __e, size_t __w);
// generating functions
result_type operator()() {return __eval(integral_constant<bool, _Rp != 0>());}
private:
result_type __eval(false_type);
result_type __eval(true_type);
};
template<class _Engine, class _UIntType>
__independent_bits_engine<_Engine, _UIntType>
::__independent_bits_engine(_Engine& __e, size_t __w)
: __e_(__e),
__w_(__w)
{
__n_ = __w_ / __m + (__w_ % __m != 0);
__w0_ = __w_ / __n_;
if (_Rp == 0)
__y0_ = _Rp;
else if (__w0_ < _WDt)
__y0_ = (_Rp >> __w0_) << __w0_;
else
__y0_ = 0;
if (_Rp - __y0_ > __y0_ / __n_)
{
++__n_;
__w0_ = __w_ / __n_;
if (__w0_ < _WDt)
__y0_ = (_Rp >> __w0_) << __w0_;
else
__y0_ = 0;
}
__n0_ = __n_ - __w_ % __n_;
if (__w0_ < _WDt - 1)
__y1_ = (_Rp >> (__w0_ + 1)) << (__w0_ + 1);
else
__y1_ = 0;
__mask0_ = __w0_ > 0 ? _Engine_result_type(~0) >> (_EDt - __w0_) :
_Engine_result_type(0);
__mask1_ = __w0_ < _EDt - 1 ?
_Engine_result_type(~0) >> (_EDt - (__w0_ + 1)) :
_Engine_result_type(~0);
}
template<class _Engine, class _UIntType>
inline
_UIntType
__independent_bits_engine<_Engine, _UIntType>::__eval(false_type)
{
return static_cast<result_type>(__e_() & __mask0_);
}
template<class _Engine, class _UIntType>
_UIntType
__independent_bits_engine<_Engine, _UIntType>::__eval(true_type)
{
const size_t _WRt = numeric_limits<result_type>::digits;
result_type _Sp = 0;
for (size_t __k = 0; __k < __n0_; ++__k)
{
_Engine_result_type __u;
do
{
__u = __e_() - _Engine::min();
} while (__u >= __y0_);
if (__w0_ < _WRt)
_Sp <<= __w0_;
else
_Sp = 0;
_Sp += __u & __mask0_;
}
for (size_t __k = __n0_; __k < __n_; ++__k)
{
_Engine_result_type __u;
do
{
__u = __e_() - _Engine::min();
} while (__u >= __y1_);
if (__w0_ < _WRt - 1)
_Sp <<= __w0_ + 1;
else
_Sp = 0;
_Sp += __u & __mask1_;
}
return _Sp;
}
// uniform_int_distribution
template<class _IntType = int>
class uniform_int_distribution
{
public:
// types
typedef _IntType result_type;
class param_type
{
result_type __a_;
result_type __b_;
public:
typedef uniform_int_distribution distribution_type;
explicit param_type(result_type __a = 0,
result_type __b = numeric_limits<result_type>::max())
: __a_(__a), __b_(__b) {}
result_type a() const {return __a_;}
result_type b() const {return __b_;}
friend bool operator==(const param_type& __x, const param_type& __y)
{return __x.__a_ == __y.__a_ && __x.__b_ == __y.__b_;}
friend bool operator!=(const param_type& __x, const param_type& __y)
{return !(__x == __y);}
};
private:
param_type __p_;
public:
// constructors and reset functions
explicit uniform_int_distribution(result_type __a = 0,
result_type __b = numeric_limits<result_type>::max())
: __p_(param_type(__a, __b)) {}
explicit uniform_int_distribution(const param_type& __p) : __p_(__p) {}
void reset() {}
// generating functions
template<class _URNG> result_type operator()(_URNG& __g)
{return (*this)(__g, __p_);}
template<class _URNG> result_type operator()(_URNG& __g, const param_type& __p);
// property functions
result_type a() const {return __p_.a();}
result_type b() const {return __p_.b();}
param_type param() const {return __p_;}
void param(const param_type& __p) {__p_ = __p;}
result_type min() const {return a();}
result_type max() const {return b();}
friend bool operator==(const uniform_int_distribution& __x,
const uniform_int_distribution& __y)
{return __x.__p_ == __y.__p_;}
friend bool operator!=(const uniform_int_distribution& __x,
const uniform_int_distribution& __y)
{return !(__x == __y);}
};
template<class _IntType>
template<class _URNG>
typename uniform_int_distribution<_IntType>::result_type
uniform_int_distribution<_IntType>::operator()(_URNG& __g, const param_type& __p)
_LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK
{
typedef typename conditional<sizeof(result_type) <= sizeof(uint32_t),
uint32_t, uint64_t>::type _UIntType;
const _UIntType _Rp = _UIntType(__p.b()) - _UIntType(__p.a()) + _UIntType(1);
if (_Rp == 1)
return __p.a();
const size_t _Dt = numeric_limits<_UIntType>::digits;
typedef __independent_bits_engine<_URNG, _UIntType> _Eng;
if (_Rp == 0)
return static_cast<result_type>(_Eng(__g, _Dt)());
size_t __w = _Dt - __libcpp_clz(_Rp) - 1;
if ((_Rp & (std::numeric_limits<_UIntType>::max() >> (_Dt - __w))) != 0)
++__w;
_Eng __e(__g, __w);
_UIntType __u;
do
{
__u = __e();
} while (__u >= _Rp);
return static_cast<result_type>(__u + __p.a());
}
#if _LIBCPP_STD_VER <= 14 || defined(_LIBCPP_ENABLE_CXX17_REMOVED_RANDOM_SHUFFLE) \
|| defined(_LIBCPP_BUILDING_LIBRARY)
class _LIBCPP_TYPE_VIS __rs_default;
_LIBCPP_FUNC_VIS __rs_default __rs_get();
class _LIBCPP_TYPE_VIS __rs_default
{
static unsigned __c_;
__rs_default();
public:
typedef uint_fast32_t result_type;
static const result_type _Min = 0;
static const result_type _Max = 0xFFFFFFFF;
__rs_default(const __rs_default&);
~__rs_default();
result_type operator()();
static _LIBCPP_CONSTEXPR result_type min() {return _Min;}
static _LIBCPP_CONSTEXPR result_type max() {return _Max;}
friend _LIBCPP_FUNC_VIS __rs_default __rs_get();
};
_LIBCPP_FUNC_VIS __rs_default __rs_get();
template <class _RandomAccessIterator>
_LIBCPP_DEPRECATED_IN_CXX14 void
random_shuffle(_RandomAccessIterator __first, _RandomAccessIterator __last)
{
typedef typename iterator_traits<_RandomAccessIterator>::difference_type difference_type;
typedef uniform_int_distribution<ptrdiff_t> _Dp;
typedef typename _Dp::param_type _Pp;
difference_type __d = __last - __first;
if (__d > 1)
{
_Dp __uid;
__rs_default __g = __rs_get();
for (--__last, (void) --__d; __first < __last; ++__first, (void) --__d)
{
difference_type __i = __uid(__g, _Pp(0, __d));
if (__i != difference_type(0))
swap(*__first, *(__first + __i));
}
}
}
template <class _RandomAccessIterator, class _RandomNumberGenerator>
_LIBCPP_DEPRECATED_IN_CXX14 void
random_shuffle(_RandomAccessIterator __first, _RandomAccessIterator __last,
#ifndef _LIBCPP_CXX03_LANG
_RandomNumberGenerator&& __rand)
#else
_RandomNumberGenerator& __rand)
#endif
{
typedef typename iterator_traits<_RandomAccessIterator>::difference_type difference_type;
difference_type __d = __last - __first;
if (__d > 1)
{
for (--__last; __first < __last; ++__first, (void) --__d)
{
difference_type __i = __rand(__d);
if (__i != difference_type(0))
swap(*__first, *(__first + __i));
}
}
}
#endif
template <class _PopulationIterator, class _SampleIterator, class _Distance,
class _UniformRandomNumberGenerator>
_LIBCPP_INLINE_VISIBILITY
_SampleIterator __sample(_PopulationIterator __first,
_PopulationIterator __last, _SampleIterator __output_iter,
_Distance __n,
_UniformRandomNumberGenerator & __g,
input_iterator_tag) {
_Distance __k = 0;
for (; __first != __last && __k < __n; ++__first, (void) ++__k)
__output_iter[__k] = *__first;
_Distance __sz = __k;
for (; __first != __last; ++__first, (void) ++__k) {
_Distance __r = _VSTD::uniform_int_distribution<_Distance>(0, __k)(__g);
if (__r < __sz)
__output_iter[__r] = *__first;
}
return __output_iter + _VSTD::min(__n, __k);
}
template <class _PopulationIterator, class _SampleIterator, class _Distance,
class _UniformRandomNumberGenerator>
_LIBCPP_INLINE_VISIBILITY
_SampleIterator __sample(_PopulationIterator __first,
_PopulationIterator __last, _SampleIterator __output_iter,
_Distance __n,
_UniformRandomNumberGenerator& __g,
forward_iterator_tag) {
_Distance __unsampled_sz = _VSTD::distance(__first, __last);
for (__n = _VSTD::min(__n, __unsampled_sz); __n != 0; ++__first) {
_Distance __r =
_VSTD::uniform_int_distribution<_Distance>(0, --__unsampled_sz)(__g);
if (__r < __n) {
*__output_iter++ = *__first;
--__n;
}
}
return __output_iter;
}
template <class _PopulationIterator, class _SampleIterator, class _Distance,
class _UniformRandomNumberGenerator>
_LIBCPP_INLINE_VISIBILITY
_SampleIterator __sample(_PopulationIterator __first,
_PopulationIterator __last, _SampleIterator __output_iter,
_Distance __n, _UniformRandomNumberGenerator& __g) {
typedef typename iterator_traits<_PopulationIterator>::iterator_category
_PopCategory;
typedef typename iterator_traits<_PopulationIterator>::difference_type
_Difference;
static_assert(__is_forward_iterator<_PopulationIterator>::value ||
__is_random_access_iterator<_SampleIterator>::value,
"SampleIterator must meet the requirements of RandomAccessIterator");
typedef typename common_type<_Distance, _Difference>::type _CommonType;
_LIBCPP_ASSERT(__n >= 0, "N must be a positive number.");
return _VSTD::__sample(
__first, __last, __output_iter, _CommonType(__n),
__g, _PopCategory());
}
#if _LIBCPP_STD_VER > 14
template <class _PopulationIterator, class _SampleIterator, class _Distance,
class _UniformRandomNumberGenerator>
inline _LIBCPP_INLINE_VISIBILITY
_SampleIterator sample(_PopulationIterator __first,
_PopulationIterator __last, _SampleIterator __output_iter,
_Distance __n, _UniformRandomNumberGenerator&& __g) {
return _VSTD::__sample(__first, __last, __output_iter, __n, __g);
}
#endif // _LIBCPP_STD_VER > 14
template<class _RandomAccessIterator, class _UniformRandomNumberGenerator>
void shuffle(_RandomAccessIterator __first, _RandomAccessIterator __last,
_UniformRandomNumberGenerator&& __g)
{
typedef typename iterator_traits<_RandomAccessIterator>::difference_type difference_type;
typedef uniform_int_distribution<ptrdiff_t> _Dp;
typedef typename _Dp::param_type _Pp;
difference_type __d = __last - __first;
if (__d > 1)
{
_Dp __uid;
for (--__last, (void) --__d; __first < __last; ++__first, (void) --__d)
{
difference_type __i = __uid(__g, _Pp(0, __d));
if (__i != difference_type(0))
swap(*__first, *(__first + __i));
}
}
}
template <class _InputIterator, class _Predicate>
_LIBCPP_NODISCARD_EXT _LIBCPP_CONSTEXPR_AFTER_CXX17 bool
is_partitioned(_InputIterator __first, _InputIterator __last, _Predicate __pred)
{
for (; __first != __last; ++__first)
if (!__pred(*__first))
break;
if ( __first == __last )
return true;
++__first;
for (; __first != __last; ++__first)
if (__pred(*__first))
return false;
return true;
}
// partition
template <class _Predicate, class _ForwardIterator>
_ForwardIterator
__partition(_ForwardIterator __first, _ForwardIterator __last, _Predicate __pred, forward_iterator_tag)
{
while (true)
{
if (__first == __last)
return __first;
if (!__pred(*__first))
break;
++__first;
}
for (_ForwardIterator __p = __first; ++__p != __last;)
{
if (__pred(*__p))
{
swap(*__first, *__p);
++__first;
}
}
return __first;
}
template <class _Predicate, class _BidirectionalIterator>
_BidirectionalIterator
__partition(_BidirectionalIterator __first, _BidirectionalIterator __last, _Predicate __pred,
bidirectional_iterator_tag)
{
while (true)
{
while (true)
{
if (__first == __last)
return __first;
if (!__pred(*__first))
break;
++__first;
}
do
{
if (__first == --__last)
return __first;
} while (!__pred(*__last));
swap(*__first, *__last);
++__first;
}
}
template <class _ForwardIterator, class _Predicate>
inline _LIBCPP_INLINE_VISIBILITY
_ForwardIterator
partition(_ForwardIterator __first, _ForwardIterator __last, _Predicate __pred)
{
return _VSTD::__partition<typename add_lvalue_reference<_Predicate>::type>
(__first, __last, __pred, typename iterator_traits<_ForwardIterator>::iterator_category());
}
// partition_copy
template <class _InputIterator, class _OutputIterator1,
class _OutputIterator2, class _Predicate>
_LIBCPP_CONSTEXPR_AFTER_CXX17 pair<_OutputIterator1, _OutputIterator2>
partition_copy(_InputIterator __first, _InputIterator __last,
_OutputIterator1 __out_true, _OutputIterator2 __out_false,
_Predicate __pred)
{
for (; __first != __last; ++__first)
{
if (__pred(*__first))
{
*__out_true = *__first;
++__out_true;
}
else
{
*__out_false = *__first;
++__out_false;
}
}
return pair<_OutputIterator1, _OutputIterator2>(__out_true, __out_false);
}
// partition_point
template<class _ForwardIterator, class _Predicate>
_LIBCPP_CONSTEXPR_AFTER_CXX17 _ForwardIterator
partition_point(_ForwardIterator __first, _ForwardIterator __last, _Predicate __pred)
{
typedef typename iterator_traits<_ForwardIterator>::difference_type difference_type;
difference_type __len = _VSTD::distance(__first, __last);
while (__len != 0)
{
difference_type __l2 = _VSTD::__half_positive(__len);
_ForwardIterator __m = __first;
_VSTD::advance(__m, __l2);
if (__pred(*__m))
{
__first = ++__m;
__len -= __l2 + 1;
}
else
__len = __l2;
}
return __first;
}
// stable_partition
template <class _Predicate, class _ForwardIterator, class _Distance, class _Pair>
_ForwardIterator
__stable_partition(_ForwardIterator __first, _ForwardIterator __last, _Predicate __pred,
_Distance __len, _Pair __p, forward_iterator_tag __fit)
{
// *__first is known to be false
// __len >= 1
if (__len == 1)
return __first;
if (__len == 2)
{
_ForwardIterator __m = __first;
if (__pred(*++__m))
{
swap(*__first, *__m);
return __m;
}
return __first;
}
if (__len <= __p.second)
{ // The buffer is big enough to use
typedef typename iterator_traits<_ForwardIterator>::value_type value_type;
__destruct_n __d(0);
unique_ptr<value_type, __destruct_n&> __h(__p.first, __d);
// Move the falses into the temporary buffer, and the trues to the front of the line
// Update __first to always point to the end of the trues
value_type* __t = __p.first;
::new(__t) value_type(_VSTD::move(*__first));
__d.__incr((value_type*)0);
++__t;
_ForwardIterator __i = __first;
while (++__i != __last)
{
if (__pred(*__i))
{
*__first = _VSTD::move(*__i);
++__first;
}
else
{
::new(__t) value_type(_VSTD::move(*__i));
__d.__incr((value_type*)0);
++__t;
}
}
// All trues now at start of range, all falses in buffer
// Move falses back into range, but don't mess up __first which points to first false
__i = __first;
for (value_type* __t2 = __p.first; __t2 < __t; ++__t2, (void) ++__i)
*__i = _VSTD::move(*__t2);
// __h destructs moved-from values out of the temp buffer, but doesn't deallocate buffer
return __first;
}
// Else not enough buffer, do in place
// __len >= 3
_ForwardIterator __m = __first;
_Distance __len2 = __len / 2; // __len2 >= 2
_VSTD::advance(__m, __len2);
// recurse on [__first, __m), *__first know to be false
// F?????????????????
// f m l
typedef typename add_lvalue_reference<_Predicate>::type _PredRef;
_ForwardIterator __first_false = __stable_partition<_PredRef>(__first, __m, __pred, __len2, __p, __fit);
// TTTFFFFF??????????
// f ff m l
// recurse on [__m, __last], except increase __m until *(__m) is false, *__last know to be true
_ForwardIterator __m1 = __m;
_ForwardIterator __second_false = __last;
_Distance __len_half = __len - __len2;
while (__pred(*__m1))
{
if (++__m1 == __last)
goto __second_half_done;
--__len_half;
}
// TTTFFFFFTTTF??????
// f ff m m1 l
__second_false = __stable_partition<_PredRef>(__m1, __last, __pred, __len_half, __p, __fit);
__second_half_done:
// TTTFFFFFTTTTTFFFFF
// f ff m sf l
return _VSTD::rotate(__first_false, __m, __second_false);
// TTTTTTTTFFFFFFFFFF
// |
}
struct __return_temporary_buffer
{
template <class _Tp>
_LIBCPP_INLINE_VISIBILITY void operator()(_Tp* __p) const {_VSTD::return_temporary_buffer(__p);}
};
template <class _Predicate, class _ForwardIterator>
_ForwardIterator
__stable_partition(_ForwardIterator __first, _ForwardIterator __last, _Predicate __pred,
forward_iterator_tag)
{
const unsigned __alloc_limit = 3; // might want to make this a function of trivial assignment
// Either prove all true and return __first or point to first false
while (true)
{
if (__first == __last)
return __first;
if (!__pred(*__first))
break;
++__first;
}
// We now have a reduced range [__first, __last)
// *__first is known to be false
typedef typename iterator_traits<_ForwardIterator>::difference_type difference_type;
typedef typename iterator_traits<_ForwardIterator>::value_type value_type;
difference_type __len = _VSTD::distance(__first, __last);
pair<value_type*, ptrdiff_t> __p(0, 0);
unique_ptr<value_type, __return_temporary_buffer> __h;
if (__len >= __alloc_limit)
{
__p = _VSTD::get_temporary_buffer<value_type>(__len);
__h.reset(__p.first);
}
return __stable_partition<typename add_lvalue_reference<_Predicate>::type>
(__first, __last, __pred, __len, __p, forward_iterator_tag());
}
template <class _Predicate, class _BidirectionalIterator, class _Distance, class _Pair>
_BidirectionalIterator
__stable_partition(_BidirectionalIterator __first, _BidirectionalIterator __last, _Predicate __pred,
_Distance __len, _Pair __p, bidirectional_iterator_tag __bit)
{
// *__first is known to be false
// *__last is known to be true
// __len >= 2
if (__len == 2)
{
swap(*__first, *__last);
return __last;
}
if (__len == 3)
{
_BidirectionalIterator __m = __first;
if (__pred(*++__m))
{
swap(*__first, *__m);
swap(*__m, *__last);
return __last;
}
swap(*__m, *__last);
swap(*__first, *__m);
return __m;
}
if (__len <= __p.second)
{ // The buffer is big enough to use
typedef typename iterator_traits<_BidirectionalIterator>::value_type value_type;
__destruct_n __d(0);
unique_ptr<value_type, __destruct_n&> __h(__p.first, __d);
// Move the falses into the temporary buffer, and the trues to the front of the line
// Update __first to always point to the end of the trues
value_type* __t = __p.first;
::new(__t) value_type(_VSTD::move(*__first));
__d.__incr((value_type*)0);
++__t;
_BidirectionalIterator __i = __first;
while (++__i != __last)
{
if (__pred(*__i))
{
*__first = _VSTD::move(*__i);
++__first;
}
else
{
::new(__t) value_type(_VSTD::move(*__i));
__d.__incr((value_type*)0);
++__t;
}
}
// move *__last, known to be true
*__first = _VSTD::move(*__i);
__i = ++__first;
// All trues now at start of range, all falses in buffer
// Move falses back into range, but don't mess up __first which points to first false
for (value_type* __t2 = __p.first; __t2 < __t; ++__t2, (void) ++__i)
*__i = _VSTD::move(*__t2);
// __h destructs moved-from values out of the temp buffer, but doesn't deallocate buffer
return __first;
}
// Else not enough buffer, do in place
// __len >= 4
_BidirectionalIterator __m = __first;
_Distance __len2 = __len / 2; // __len2 >= 2
_VSTD::advance(__m, __len2);
// recurse on [__first, __m-1], except reduce __m-1 until *(__m-1) is true, *__first know to be false
// F????????????????T
// f m l
_BidirectionalIterator __m1 = __m;
_BidirectionalIterator __first_false = __first;
_Distance __len_half = __len2;
while (!__pred(*--__m1))
{
if (__m1 == __first)
goto __first_half_done;
--__len_half;
}
// F???TFFF?????????T
// f m1 m l
typedef typename add_lvalue_reference<_Predicate>::type _PredRef;
__first_false = __stable_partition<_PredRef>(__first, __m1, __pred, __len_half, __p, __bit);
__first_half_done:
// TTTFFFFF?????????T
// f ff m l
// recurse on [__m, __last], except increase __m until *(__m) is false, *__last know to be true
__m1 = __m;
_BidirectionalIterator __second_false = __last;
++__second_false;
__len_half = __len - __len2;
while (__pred(*__m1))
{
if (++__m1 == __last)
goto __second_half_done;
--__len_half;
}
// TTTFFFFFTTTF?????T
// f ff m m1 l
__second_false = __stable_partition<_PredRef>(__m1, __last, __pred, __len_half, __p, __bit);
__second_half_done:
// TTTFFFFFTTTTTFFFFF
// f ff m sf l
return _VSTD::rotate(__first_false, __m, __second_false);
// TTTTTTTTFFFFFFFFFF
// |
}
template <class _Predicate, class _BidirectionalIterator>
_BidirectionalIterator
__stable_partition(_BidirectionalIterator __first, _BidirectionalIterator __last, _Predicate __pred,
bidirectional_iterator_tag)
{
typedef typename iterator_traits<_BidirectionalIterator>::difference_type difference_type;
typedef typename iterator_traits<_BidirectionalIterator>::value_type value_type;
const difference_type __alloc_limit = 4; // might want to make this a function of trivial assignment
// Either prove all true and return __first or point to first false
while (true)
{
if (__first == __last)
return __first;
if (!__pred(*__first))
break;
++__first;
}
// __first points to first false, everything prior to __first is already set.
// Either prove [__first, __last) is all false and return __first, or point __last to last true
do
{
if (__first == --__last)
return __first;
} while (!__pred(*__last));
// We now have a reduced range [__first, __last]
// *__first is known to be false
// *__last is known to be true
// __len >= 2
difference_type __len = _VSTD::distance(__first, __last) + 1;
pair<value_type*, ptrdiff_t> __p(0, 0);
unique_ptr<value_type, __return_temporary_buffer> __h;
if (__len >= __alloc_limit)
{
__p = _VSTD::get_temporary_buffer<value_type>(__len);
__h.reset(__p.first);
}
return __stable_partition<typename add_lvalue_reference<_Predicate>::type>
(__first, __last, __pred, __len, __p, bidirectional_iterator_tag());
}
template <class _ForwardIterator, class _Predicate>
inline _LIBCPP_INLINE_VISIBILITY
_ForwardIterator
stable_partition(_ForwardIterator __first, _ForwardIterator __last, _Predicate __pred)
{
return __stable_partition<typename add_lvalue_reference<_Predicate>::type>
(__first, __last, __pred, typename iterator_traits<_ForwardIterator>::iterator_category());
}
// is_sorted_until
template <class _ForwardIterator, class _Compare>
_LIBCPP_NODISCARD_EXT _LIBCPP_CONSTEXPR_AFTER_CXX17 _ForwardIterator
is_sorted_until(_ForwardIterator __first, _ForwardIterator __last, _Compare __comp)
{
if (__first != __last)
{
_ForwardIterator __i = __first;
while (++__i != __last)
{
if (__comp(*__i, *__first))
return __i;
__first = __i;
}
}
return __last;
}
template<class _ForwardIterator>
_LIBCPP_NODISCARD_EXT inline
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
_ForwardIterator
is_sorted_until(_ForwardIterator __first, _ForwardIterator __last)
{
return _VSTD::is_sorted_until(__first, __last, __less<typename iterator_traits<_ForwardIterator>::value_type>());
}
// is_sorted
template <class _ForwardIterator, class _Compare>
_LIBCPP_NODISCARD_EXT inline
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
bool
is_sorted(_ForwardIterator __first, _ForwardIterator __last, _Compare __comp)
{
return _VSTD::is_sorted_until(__first, __last, __comp) == __last;
}
template<class _ForwardIterator>
_LIBCPP_NODISCARD_EXT inline
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
bool
is_sorted(_ForwardIterator __first, _ForwardIterator __last)
{
return _VSTD::is_sorted(__first, __last, __less<typename iterator_traits<_ForwardIterator>::value_type>());
}
// sort
// stable, 2-3 compares, 0-2 swaps
template <class _Compare, class _ForwardIterator>
unsigned
__sort3(_ForwardIterator __x, _ForwardIterator __y, _ForwardIterator __z, _Compare __c)
{
unsigned __r = 0;
if (!__c(*__y, *__x)) // if x <= y
{
if (!__c(*__z, *__y)) // if y <= z
return __r; // x <= y && y <= z
// x <= y && y > z
swap(*__y, *__z); // x <= z && y < z
__r = 1;
if (__c(*__y, *__x)) // if x > y
{
swap(*__x, *__y); // x < y && y <= z
__r = 2;
}
return __r; // x <= y && y < z
}
if (__c(*__z, *__y)) // x > y, if y > z
{
swap(*__x, *__z); // x < y && y < z
__r = 1;
return __r;
}
swap(*__x, *__y); // x > y && y <= z
__r = 1; // x < y && x <= z
if (__c(*__z, *__y)) // if y > z
{
swap(*__y, *__z); // x <= y && y < z
__r = 2;
}
return __r;
} // x <= y && y <= z
// stable, 3-6 compares, 0-5 swaps
template <class _Compare, class _ForwardIterator>
unsigned
__sort4(_ForwardIterator __x1, _ForwardIterator __x2, _ForwardIterator __x3,
_ForwardIterator __x4, _Compare __c)
{
unsigned __r = __sort3<_Compare>(__x1, __x2, __x3, __c);
if (__c(*__x4, *__x3))
{
swap(*__x3, *__x4);
++__r;
if (__c(*__x3, *__x2))
{
swap(*__x2, *__x3);
++__r;
if (__c(*__x2, *__x1))
{
swap(*__x1, *__x2);
++__r;
}
}
}
return __r;
}
// stable, 4-10 compares, 0-9 swaps
template <class _Compare, class _ForwardIterator>
_LIBCPP_HIDDEN
unsigned
__sort5(_ForwardIterator __x1, _ForwardIterator __x2, _ForwardIterator __x3,
_ForwardIterator __x4, _ForwardIterator __x5, _Compare __c)
{
unsigned __r = __sort4<_Compare>(__x1, __x2, __x3, __x4, __c);
if (__c(*__x5, *__x4))
{
swap(*__x4, *__x5);
++__r;
if (__c(*__x4, *__x3))
{
swap(*__x3, *__x4);
++__r;
if (__c(*__x3, *__x2))
{
swap(*__x2, *__x3);
++__r;
if (__c(*__x2, *__x1))
{
swap(*__x1, *__x2);
++__r;
}
}
}
}
return __r;
}
// Assumes size > 0
template <class _Compare, class _BirdirectionalIterator>
void
__selection_sort(_BirdirectionalIterator __first, _BirdirectionalIterator __last, _Compare __comp)
{
_BirdirectionalIterator __lm1 = __last;
for (--__lm1; __first != __lm1; ++__first)
{
_BirdirectionalIterator __i = _VSTD::min_element<_BirdirectionalIterator,
typename add_lvalue_reference<_Compare>::type>
(__first, __last, __comp);
if (__i != __first)
swap(*__first, *__i);
}
}
template <class _Compare, class _BirdirectionalIterator>
void
__insertion_sort(_BirdirectionalIterator __first, _BirdirectionalIterator __last, _Compare __comp)
{
typedef typename iterator_traits<_BirdirectionalIterator>::value_type value_type;
if (__first != __last)
{
_BirdirectionalIterator __i = __first;
for (++__i; __i != __last; ++__i)
{
_BirdirectionalIterator __j = __i;
value_type __t(_VSTD::move(*__j));
for (_BirdirectionalIterator __k = __i; __k != __first && __comp(__t, *--__k); --__j)
*__j = _VSTD::move(*__k);
*__j = _VSTD::move(__t);
}
}
}
template <class _Compare, class _RandomAccessIterator>
void
__insertion_sort_3(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp)
{
typedef typename iterator_traits<_RandomAccessIterator>::value_type value_type;
_RandomAccessIterator __j = __first+2;
__sort3<_Compare>(__first, __first+1, __j, __comp);
for (_RandomAccessIterator __i = __j+1; __i != __last; ++__i)
{
if (__comp(*__i, *__j))
{
value_type __t(_VSTD::move(*__i));
_RandomAccessIterator __k = __j;
__j = __i;
do
{
*__j = _VSTD::move(*__k);
__j = __k;
} while (__j != __first && __comp(__t, *--__k));
*__j = _VSTD::move(__t);
}
__j = __i;
}
}
template <class _Compare, class _RandomAccessIterator>
bool
__insertion_sort_incomplete(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp)
{
switch (__last - __first)
{
case 0:
case 1:
return true;
case 2:
if (__comp(*--__last, *__first))
swap(*__first, *__last);
return true;
case 3:
_VSTD::__sort3<_Compare>(__first, __first+1, --__last, __comp);
return true;
case 4:
_VSTD::__sort4<_Compare>(__first, __first+1, __first+2, --__last, __comp);
return true;
case 5:
_VSTD::__sort5<_Compare>(__first, __first+1, __first+2, __first+3, --__last, __comp);
return true;
}
typedef typename iterator_traits<_RandomAccessIterator>::value_type value_type;
_RandomAccessIterator __j = __first+2;
__sort3<_Compare>(__first, __first+1, __j, __comp);
const unsigned __limit = 8;
unsigned __count = 0;
for (_RandomAccessIterator __i = __j+1; __i != __last; ++__i)
{
if (__comp(*__i, *__j))
{
value_type __t(_VSTD::move(*__i));
_RandomAccessIterator __k = __j;
__j = __i;
do
{
*__j = _VSTD::move(*__k);
__j = __k;
} while (__j != __first && __comp(__t, *--__k));
*__j = _VSTD::move(__t);
if (++__count == __limit)
return ++__i == __last;
}
__j = __i;
}
return true;
}
template <class _Compare, class _BirdirectionalIterator>
void
__insertion_sort_move(_BirdirectionalIterator __first1, _BirdirectionalIterator __last1,
typename iterator_traits<_BirdirectionalIterator>::value_type* __first2, _Compare __comp)
{
typedef typename iterator_traits<_BirdirectionalIterator>::value_type value_type;
if (__first1 != __last1)
{
__destruct_n __d(0);
unique_ptr<value_type, __destruct_n&> __h(__first2, __d);
value_type* __last2 = __first2;
::new(__last2) value_type(_VSTD::move(*__first1));
__d.__incr((value_type*)0);
for (++__last2; ++__first1 != __last1; ++__last2)
{
value_type* __j2 = __last2;
value_type* __i2 = __j2;
if (__comp(*__first1, *--__i2))
{
::new(__j2) value_type(_VSTD::move(*__i2));
__d.__incr((value_type*)0);
for (--__j2; __i2 != __first2 && __comp(*__first1, *--__i2); --__j2)
*__j2 = _VSTD::move(*__i2);
*__j2 = _VSTD::move(*__first1);
}
else
{
::new(__j2) value_type(_VSTD::move(*__first1));
__d.__incr((value_type*)0);
}
}
__h.release();
}
}
template <class _Compare, class _RandomAccessIterator>
void
__sort(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp)
{
// _Compare is known to be a reference type
typedef typename iterator_traits<_RandomAccessIterator>::difference_type difference_type;
typedef typename iterator_traits<_RandomAccessIterator>::value_type value_type;
const difference_type __limit = is_trivially_copy_constructible<value_type>::value &&
is_trivially_copy_assignable<value_type>::value ? 30 : 6;
while (true)
{
__restart:
difference_type __len = __last - __first;
switch (__len)
{
case 0:
case 1:
return;
case 2:
if (__comp(*--__last, *__first))
swap(*__first, *__last);
return;
case 3:
_VSTD::__sort3<_Compare>(__first, __first+1, --__last, __comp);
return;
case 4:
_VSTD::__sort4<_Compare>(__first, __first+1, __first+2, --__last, __comp);
return;
case 5:
_VSTD::__sort5<_Compare>(__first, __first+1, __first+2, __first+3, --__last, __comp);
return;
}
if (__len <= __limit)
{
_VSTD::__insertion_sort_3<_Compare>(__first, __last, __comp);
return;
}
// __len > 5
_RandomAccessIterator __m = __first;
_RandomAccessIterator __lm1 = __last;
--__lm1;
unsigned __n_swaps;
{
difference_type __delta;
if (__len >= 1000)
{
__delta = __len/2;
__m += __delta;
__delta /= 2;
__n_swaps = _VSTD::__sort5<_Compare>(__first, __first + __delta, __m, __m+__delta, __lm1, __comp);
}
else
{
__delta = __len/2;
__m += __delta;
__n_swaps = _VSTD::__sort3<_Compare>(__first, __m, __lm1, __comp);
}
}
// *__m is median
// partition [__first, __m) < *__m and *__m <= [__m, __last)
// (this inhibits tossing elements equivalent to __m around unnecessarily)
_RandomAccessIterator __i = __first;
_RandomAccessIterator __j = __lm1;
// j points beyond range to be tested, *__m is known to be <= *__lm1
// The search going up is known to be guarded but the search coming down isn't.
// Prime the downward search with a guard.
if (!__comp(*__i, *__m)) // if *__first == *__m
{
// *__first == *__m, *__first doesn't go in first part
// manually guard downward moving __j against __i
while (true)
{
if (__i == --__j)
{
// *__first == *__m, *__m <= all other elements
// Parition instead into [__first, __i) == *__first and *__first < [__i, __last)
++__i; // __first + 1
__j = __last;
if (!__comp(*__first, *--__j)) // we need a guard if *__first == *(__last-1)
{
while (true)
{
if (__i == __j)
return; // [__first, __last) all equivalent elements
if (__comp(*__first, *__i))
{
swap(*__i, *__j);
++__n_swaps;
++__i;
break;
}
++__i;
}
}
// [__first, __i) == *__first and *__first < [__j, __last) and __j == __last - 1
if (__i == __j)
return;
while (true)
{
while (!__comp(*__first, *__i))
++__i;
while (__comp(*__first, *--__j))
;
if (__i >= __j)
break;
swap(*__i, *__j);
++__n_swaps;
++__i;
}
// [__first, __i) == *__first and *__first < [__i, __last)
// The first part is sorted, sort the secod part
// _VSTD::__sort<_Compare>(__i, __last, __comp);
__first = __i;
goto __restart;
}
if (__comp(*__j, *__m))
{
swap(*__i, *__j);
++__n_swaps;
break; // found guard for downward moving __j, now use unguarded partition
}
}
}
// It is known that *__i < *__m
++__i;
// j points beyond range to be tested, *__m is known to be <= *__lm1
// if not yet partitioned...
if (__i < __j)
{
// known that *(__i - 1) < *__m
// known that __i <= __m
while (true)
{
// __m still guards upward moving __i
while (__comp(*__i, *__m))
++__i;
// It is now known that a guard exists for downward moving __j
while (!__comp(*--__j, *__m))
;
if (__i > __j)
break;
swap(*__i, *__j);
++__n_swaps;
// It is known that __m != __j
// If __m just moved, follow it
if (__m == __i)
__m = __j;
++__i;
}
}
// [__first, __i) < *__m and *__m <= [__i, __last)
if (__i != __m && __comp(*__m, *__i))
{
swap(*__i, *__m);
++__n_swaps;
}
// [__first, __i) < *__i and *__i <= [__i+1, __last)
// If we were given a perfect partition, see if insertion sort is quick...
if (__n_swaps == 0)
{
bool __fs = _VSTD::__insertion_sort_incomplete<_Compare>(__first, __i, __comp);
if (_VSTD::__insertion_sort_incomplete<_Compare>(__i+1, __last, __comp))
{
if (__fs)
return;
__last = __i;
continue;
}
else
{
if (__fs)
{
__first = ++__i;
continue;
}
}
}
// sort smaller range with recursive call and larger with tail recursion elimination
if (__i - __first < __last - __i)
{
_VSTD::__sort<_Compare>(__first, __i, __comp);
// _VSTD::__sort<_Compare>(__i+1, __last, __comp);
__first = ++__i;
}
else
{
_VSTD::__sort<_Compare>(__i+1, __last, __comp);
// _VSTD::__sort<_Compare>(__first, __i, __comp);
__last = __i;
}
}
}
// This forwarder keeps the top call and the recursive calls using the same instantiation, forcing a reference _Compare
template <class _RandomAccessIterator, class _Compare>
inline _LIBCPP_INLINE_VISIBILITY
void
sort(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp)
{
typedef typename __comp_ref_type<_Compare>::type _Comp_ref;
_VSTD::__sort<_Comp_ref>(__first, __last, _Comp_ref(__comp));
}
template <class _RandomAccessIterator>
inline _LIBCPP_INLINE_VISIBILITY
void
sort(_RandomAccessIterator __first, _RandomAccessIterator __last)
{
_VSTD::sort(__first, __last, __less<typename iterator_traits<_RandomAccessIterator>::value_type>());
}
template <class _Tp>
inline _LIBCPP_INLINE_VISIBILITY
void
sort(_Tp** __first, _Tp** __last)
{
_VSTD::sort((size_t*)__first, (size_t*)__last, __less<size_t>());
}
template <class _Tp>
inline _LIBCPP_INLINE_VISIBILITY
void
sort(__wrap_iter<_Tp*> __first, __wrap_iter<_Tp*> __last)
{
_VSTD::sort(__first.base(), __last.base());
}
template <class _Tp, class _Compare>
inline _LIBCPP_INLINE_VISIBILITY
void
sort(__wrap_iter<_Tp*> __first, __wrap_iter<_Tp*> __last, _Compare __comp)
{
typedef typename add_lvalue_reference<_Compare>::type _Comp_ref;
_VSTD::sort<_Tp*, _Comp_ref>(__first.base(), __last.base(), __comp);
}
_LIBCPP_EXTERN_TEMPLATE(_LIBCPP_FUNC_VIS void __sort<__less<char>&, char*>(char*, char*, __less<char>&))
_LIBCPP_EXTERN_TEMPLATE(_LIBCPP_FUNC_VIS void __sort<__less<wchar_t>&, wchar_t*>(wchar_t*, wchar_t*, __less<wchar_t>&))
_LIBCPP_EXTERN_TEMPLATE(_LIBCPP_FUNC_VIS void __sort<__less<signed char>&, signed char*>(signed char*, signed char*, __less<signed char>&))
_LIBCPP_EXTERN_TEMPLATE(_LIBCPP_FUNC_VIS void __sort<__less<unsigned char>&, unsigned char*>(unsigned char*, unsigned char*, __less<unsigned char>&))
_LIBCPP_EXTERN_TEMPLATE(_LIBCPP_FUNC_VIS void __sort<__less<short>&, short*>(short*, short*, __less<short>&))
_LIBCPP_EXTERN_TEMPLATE(_LIBCPP_FUNC_VIS void __sort<__less<unsigned short>&, unsigned short*>(unsigned short*, unsigned short*, __less<unsigned short>&))
_LIBCPP_EXTERN_TEMPLATE(_LIBCPP_FUNC_VIS void __sort<__less<int>&, int*>(int*, int*, __less<int>&))
_LIBCPP_EXTERN_TEMPLATE(_LIBCPP_FUNC_VIS void __sort<__less<unsigned>&, unsigned*>(unsigned*, unsigned*, __less<unsigned>&))
_LIBCPP_EXTERN_TEMPLATE(_LIBCPP_FUNC_VIS void __sort<__less<long>&, long*>(long*, long*, __less<long>&))
_LIBCPP_EXTERN_TEMPLATE(_LIBCPP_FUNC_VIS void __sort<__less<unsigned long>&, unsigned long*>(unsigned long*, unsigned long*, __less<unsigned long>&))
_LIBCPP_EXTERN_TEMPLATE(_LIBCPP_FUNC_VIS void __sort<__less<long long>&, long long*>(long long*, long long*, __less<long long>&))
_LIBCPP_EXTERN_TEMPLATE(_LIBCPP_FUNC_VIS void __sort<__less<unsigned long long>&, unsigned long long*>(unsigned long long*, unsigned long long*, __less<unsigned long long>&))
_LIBCPP_EXTERN_TEMPLATE(_LIBCPP_FUNC_VIS void __sort<__less<float>&, float*>(float*, float*, __less<float>&))
_LIBCPP_EXTERN_TEMPLATE(_LIBCPP_FUNC_VIS void __sort<__less<double>&, double*>(double*, double*, __less<double>&))
_LIBCPP_EXTERN_TEMPLATE(_LIBCPP_FUNC_VIS void __sort<__less<long double>&, long double*>(long double*, long double*, __less<long double>&))
_LIBCPP_EXTERN_TEMPLATE(_LIBCPP_FUNC_VIS bool __insertion_sort_incomplete<__less<char>&, char*>(char*, char*, __less<char>&))
_LIBCPP_EXTERN_TEMPLATE(_LIBCPP_FUNC_VIS bool __insertion_sort_incomplete<__less<wchar_t>&, wchar_t*>(wchar_t*, wchar_t*, __less<wchar_t>&))
_LIBCPP_EXTERN_TEMPLATE(_LIBCPP_FUNC_VIS bool __insertion_sort_incomplete<__less<signed char>&, signed char*>(signed char*, signed char*, __less<signed char>&))
_LIBCPP_EXTERN_TEMPLATE(_LIBCPP_FUNC_VIS bool __insertion_sort_incomplete<__less<unsigned char>&, unsigned char*>(unsigned char*, unsigned char*, __less<unsigned char>&))
_LIBCPP_EXTERN_TEMPLATE(_LIBCPP_FUNC_VIS bool __insertion_sort_incomplete<__less<short>&, short*>(short*, short*, __less<short>&))
_LIBCPP_EXTERN_TEMPLATE(_LIBCPP_FUNC_VIS bool __insertion_sort_incomplete<__less<unsigned short>&, unsigned short*>(unsigned short*, unsigned short*, __less<unsigned short>&))
_LIBCPP_EXTERN_TEMPLATE(_LIBCPP_FUNC_VIS bool __insertion_sort_incomplete<__less<int>&, int*>(int*, int*, __less<int>&))
_LIBCPP_EXTERN_TEMPLATE(_LIBCPP_FUNC_VIS bool __insertion_sort_incomplete<__less<unsigned>&, unsigned*>(unsigned*, unsigned*, __less<unsigned>&))
_LIBCPP_EXTERN_TEMPLATE(_LIBCPP_FUNC_VIS bool __insertion_sort_incomplete<__less<long>&, long*>(long*, long*, __less<long>&))
_LIBCPP_EXTERN_TEMPLATE(_LIBCPP_FUNC_VIS bool __insertion_sort_incomplete<__less<unsigned long>&, unsigned long*>(unsigned long*, unsigned long*, __less<unsigned long>&))
_LIBCPP_EXTERN_TEMPLATE(_LIBCPP_FUNC_VIS bool __insertion_sort_incomplete<__less<long long>&, long long*>(long long*, long long*, __less<long long>&))
_LIBCPP_EXTERN_TEMPLATE(_LIBCPP_FUNC_VIS bool __insertion_sort_incomplete<__less<unsigned long long>&, unsigned long long*>(unsigned long long*, unsigned long long*, __less<unsigned long long>&))
_LIBCPP_EXTERN_TEMPLATE(_LIBCPP_FUNC_VIS bool __insertion_sort_incomplete<__less<float>&, float*>(float*, float*, __less<float>&))
_LIBCPP_EXTERN_TEMPLATE(_LIBCPP_FUNC_VIS bool __insertion_sort_incomplete<__less<double>&, double*>(double*, double*, __less<double>&))
_LIBCPP_EXTERN_TEMPLATE(_LIBCPP_FUNC_VIS bool __insertion_sort_incomplete<__less<long double>&, long double*>(long double*, long double*, __less<long double>&))
_LIBCPP_EXTERN_TEMPLATE(_LIBCPP_FUNC_VIS unsigned __sort5<__less<long double>&, long double*>(long double*, long double*, long double*, long double*, long double*, __less<long double>&))
// lower_bound
template <class _Compare, class _ForwardIterator, class _Tp>
_LIBCPP_CONSTEXPR_AFTER_CXX17 _ForwardIterator
__lower_bound(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value_, _Compare __comp)
{
typedef typename iterator_traits<_ForwardIterator>::difference_type difference_type;
difference_type __len = _VSTD::distance(__first, __last);
while (__len != 0)
{
difference_type __l2 = _VSTD::__half_positive(__len);
_ForwardIterator __m = __first;
_VSTD::advance(__m, __l2);
if (__comp(*__m, __value_))
{
__first = ++__m;
__len -= __l2 + 1;
}
else
__len = __l2;
}
return __first;
}
template <class _ForwardIterator, class _Tp, class _Compare>
_LIBCPP_NODISCARD_EXT inline
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
_ForwardIterator
lower_bound(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value_, _Compare __comp)
{
typedef typename add_lvalue_reference<_Compare>::type _Comp_ref;
return __lower_bound<_Comp_ref>(__first, __last, __value_, __comp);
}
template <class _ForwardIterator, class _Tp>
_LIBCPP_NODISCARD_EXT inline
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
_ForwardIterator
lower_bound(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value_)
{
return _VSTD::lower_bound(__first, __last, __value_,
__less<typename iterator_traits<_ForwardIterator>::value_type, _Tp>());
}
// upper_bound
template <class _Compare, class _ForwardIterator, class _Tp>
_LIBCPP_CONSTEXPR_AFTER_CXX17 _ForwardIterator
__upper_bound(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value_, _Compare __comp)
{
typedef typename iterator_traits<_ForwardIterator>::difference_type difference_type;
difference_type __len = _VSTD::distance(__first, __last);
while (__len != 0)
{
difference_type __l2 = _VSTD::__half_positive(__len);
_ForwardIterator __m = __first;
_VSTD::advance(__m, __l2);
if (__comp(__value_, *__m))
__len = __l2;
else
{
__first = ++__m;
__len -= __l2 + 1;
}
}
return __first;
}
template <class _ForwardIterator, class _Tp, class _Compare>
_LIBCPP_NODISCARD_EXT inline
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
_ForwardIterator
upper_bound(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value_, _Compare __comp)
{
typedef typename add_lvalue_reference<_Compare>::type _Comp_ref;
return __upper_bound<_Comp_ref>(__first, __last, __value_, __comp);
}
template <class _ForwardIterator, class _Tp>
_LIBCPP_NODISCARD_EXT inline
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
_ForwardIterator
upper_bound(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value_)
{
return _VSTD::upper_bound(__first, __last, __value_,
__less<_Tp, typename iterator_traits<_ForwardIterator>::value_type>());
}
// equal_range
template <class _Compare, class _ForwardIterator, class _Tp>
_LIBCPP_CONSTEXPR_AFTER_CXX17 pair<_ForwardIterator, _ForwardIterator>
__equal_range(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value_, _Compare __comp)
{
typedef typename iterator_traits<_ForwardIterator>::difference_type difference_type;
difference_type __len = _VSTD::distance(__first, __last);
while (__len != 0)
{
difference_type __l2 = _VSTD::__half_positive(__len);
_ForwardIterator __m = __first;
_VSTD::advance(__m, __l2);
if (__comp(*__m, __value_))
{
__first = ++__m;
__len -= __l2 + 1;
}
else if (__comp(__value_, *__m))
{
__last = __m;
__len = __l2;
}
else
{
_ForwardIterator __mp1 = __m;
return pair<_ForwardIterator, _ForwardIterator>
(
__lower_bound<_Compare>(__first, __m, __value_, __comp),
__upper_bound<_Compare>(++__mp1, __last, __value_, __comp)
);
}
}
return pair<_ForwardIterator, _ForwardIterator>(__first, __first);
}
template <class _ForwardIterator, class _Tp, class _Compare>
_LIBCPP_NODISCARD_EXT inline
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
pair<_ForwardIterator, _ForwardIterator>
equal_range(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value_, _Compare __comp)
{
typedef typename __comp_ref_type<_Compare>::type _Comp_ref;
return __equal_range<_Comp_ref>(__first, __last, __value_, __comp);
}
template <class _ForwardIterator, class _Tp>
_LIBCPP_NODISCARD_EXT inline
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
pair<_ForwardIterator, _ForwardIterator>
equal_range(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value_)
{
return _VSTD::equal_range(__first, __last, __value_,
__less<typename iterator_traits<_ForwardIterator>::value_type, _Tp>());
}
// binary_search
template <class _Compare, class _ForwardIterator, class _Tp>
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
bool
__binary_search(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value_, _Compare __comp)
{
__first = __lower_bound<_Compare>(__first, __last, __value_, __comp);
return __first != __last && !__comp(__value_, *__first);
}
template <class _ForwardIterator, class _Tp, class _Compare>
_LIBCPP_NODISCARD_EXT inline
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
bool
binary_search(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value_, _Compare __comp)
{
typedef typename __comp_ref_type<_Compare>::type _Comp_ref;
return __binary_search<_Comp_ref>(__first, __last, __value_, __comp);
}
template <class _ForwardIterator, class _Tp>
_LIBCPP_NODISCARD_EXT inline
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
bool
binary_search(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value_)
{
return _VSTD::binary_search(__first, __last, __value_,
__less<typename iterator_traits<_ForwardIterator>::value_type, _Tp>());
}
// merge
template <class _Compare, class _InputIterator1, class _InputIterator2, class _OutputIterator>
_OutputIterator
__merge(_InputIterator1 __first1, _InputIterator1 __last1,
_InputIterator2 __first2, _InputIterator2 __last2, _OutputIterator __result, _Compare __comp)
{
for (; __first1 != __last1; ++__result)
{
if (__first2 == __last2)
return _VSTD::copy(__first1, __last1, __result);
if (__comp(*__first2, *__first1))
{
*__result = *__first2;
++__first2;
}
else
{
*__result = *__first1;
++__first1;
}
}
return _VSTD::copy(__first2, __last2, __result);
}
template <class _InputIterator1, class _InputIterator2, class _OutputIterator, class _Compare>
inline _LIBCPP_INLINE_VISIBILITY
_OutputIterator
merge(_InputIterator1 __first1, _InputIterator1 __last1,
_InputIterator2 __first2, _InputIterator2 __last2, _OutputIterator __result, _Compare __comp)
{
typedef typename __comp_ref_type<_Compare>::type _Comp_ref;
return _VSTD::__merge<_Comp_ref>(__first1, __last1, __first2, __last2, __result, __comp);
}
template <class _InputIterator1, class _InputIterator2, class _OutputIterator>
inline _LIBCPP_INLINE_VISIBILITY
_OutputIterator
merge(_InputIterator1 __first1, _InputIterator1 __last1,
_InputIterator2 __first2, _InputIterator2 __last2, _OutputIterator __result)
{
typedef typename iterator_traits<_InputIterator1>::value_type __v1;
typedef typename iterator_traits<_InputIterator2>::value_type __v2;
return _VSTD::merge(__first1, __last1, __first2, __last2, __result, __less<__v1, __v2>());
}
// inplace_merge
template <class _Compare, class _InputIterator1, class _InputIterator2,
class _OutputIterator>
void __half_inplace_merge(_InputIterator1 __first1, _InputIterator1 __last1,
_InputIterator2 __first2, _InputIterator2 __last2,
_OutputIterator __result, _Compare __comp)
{
for (; __first1 != __last1; ++__result)
{
if (__first2 == __last2)
{
_VSTD::move(__first1, __last1, __result);
return;
}
if (__comp(*__first2, *__first1))
{
*__result = _VSTD::move(*__first2);
++__first2;
}
else
{
*__result = _VSTD::move(*__first1);
++__first1;
}
}
// __first2 through __last2 are already in the right spot.
}
template <class _Compare, class _BidirectionalIterator>
void
__buffered_inplace_merge(_BidirectionalIterator __first, _BidirectionalIterator __middle, _BidirectionalIterator __last,
_Compare __comp, typename iterator_traits<_BidirectionalIterator>::difference_type __len1,
typename iterator_traits<_BidirectionalIterator>::difference_type __len2,
typename iterator_traits<_BidirectionalIterator>::value_type* __buff)
{
typedef typename iterator_traits<_BidirectionalIterator>::value_type value_type;
__destruct_n __d(0);
unique_ptr<value_type, __destruct_n&> __h2(__buff, __d);
if (__len1 <= __len2)
{
value_type* __p = __buff;
for (_BidirectionalIterator __i = __first; __i != __middle; __d.__incr((value_type*)0), (void) ++__i, (void) ++__p)
::new(__p) value_type(_VSTD::move(*__i));
__half_inplace_merge(__buff, __p, __middle, __last, __first, __comp);
}
else
{
value_type* __p = __buff;
for (_BidirectionalIterator __i = __middle; __i != __last; __d.__incr((value_type*)0), (void) ++__i, (void) ++__p)
::new(__p) value_type(_VSTD::move(*__i));
typedef reverse_iterator<_BidirectionalIterator> _RBi;
typedef reverse_iterator<value_type*> _Rv;
__half_inplace_merge(_Rv(__p), _Rv(__buff),
_RBi(__middle), _RBi(__first),
_RBi(__last), __invert<_Compare>(__comp));
}
}
template <class _Compare, class _BidirectionalIterator>
void
__inplace_merge(_BidirectionalIterator __first, _BidirectionalIterator __middle, _BidirectionalIterator __last,
_Compare __comp, typename iterator_traits<_BidirectionalIterator>::difference_type __len1,
typename iterator_traits<_BidirectionalIterator>::difference_type __len2,
typename iterator_traits<_BidirectionalIterator>::value_type* __buff, ptrdiff_t __buff_size)
{
typedef typename iterator_traits<_BidirectionalIterator>::difference_type difference_type;
while (true)
{
// if __middle == __last, we're done
if (__len2 == 0)
return;
if (__len1 <= __buff_size || __len2 <= __buff_size)
return __buffered_inplace_merge<_Compare>
(__first, __middle, __last, __comp, __len1, __len2, __buff);
// shrink [__first, __middle) as much as possible (with no moves), returning if it shrinks to 0
for (; true; ++__first, (void) --__len1)
{
if (__len1 == 0)
return;
if (__comp(*__middle, *__first))
break;
}
// __first < __middle < __last
// *__first > *__middle
// partition [__first, __m1) [__m1, __middle) [__middle, __m2) [__m2, __last) such that
// all elements in:
// [__first, __m1) <= [__middle, __m2)
// [__middle, __m2) < [__m1, __middle)
// [__m1, __middle) <= [__m2, __last)
// and __m1 or __m2 is in the middle of its range
_BidirectionalIterator __m1; // "median" of [__first, __middle)
_BidirectionalIterator __m2; // "median" of [__middle, __last)
difference_type __len11; // distance(__first, __m1)
difference_type __len21; // distance(__middle, __m2)
// binary search smaller range
if (__len1 < __len2)
{ // __len >= 1, __len2 >= 2
__len21 = __len2 / 2;
__m2 = __middle;
_VSTD::advance(__m2, __len21);
__m1 = __upper_bound<_Compare>(__first, __middle, *__m2, __comp);
__len11 = _VSTD::distance(__first, __m1);
}
else
{
if (__len1 == 1)
{ // __len1 >= __len2 && __len2 > 0, therefore __len2 == 1
// It is known *__first > *__middle
swap(*__first, *__middle);
return;
}
// __len1 >= 2, __len2 >= 1
__len11 = __len1 / 2;
__m1 = __first;
_VSTD::advance(__m1, __len11);
__m2 = __lower_bound<_Compare>(__middle, __last, *__m1, __comp);
__len21 = _VSTD::distance(__middle, __m2);
}
difference_type __len12 = __len1 - __len11; // distance(__m1, __middle)
difference_type __len22 = __len2 - __len21; // distance(__m2, __last)
// [__first, __m1) [__m1, __middle) [__middle, __m2) [__m2, __last)
// swap middle two partitions
__middle = _VSTD::rotate(__m1, __middle, __m2);
// __len12 and __len21 now have swapped meanings
// merge smaller range with recurisve call and larger with tail recursion elimination
if (__len11 + __len21 < __len12 + __len22)
{
__inplace_merge<_Compare>(__first, __m1, __middle, __comp, __len11, __len21, __buff, __buff_size);
// __inplace_merge<_Compare>(__middle, __m2, __last, __comp, __len12, __len22, __buff, __buff_size);
__first = __middle;
__middle = __m2;
__len1 = __len12;
__len2 = __len22;
}
else
{
__inplace_merge<_Compare>(__middle, __m2, __last, __comp, __len12, __len22, __buff, __buff_size);
// __inplace_merge<_Compare>(__first, __m1, __middle, __comp, __len11, __len21, __buff, __buff_size);
__last = __middle;
__middle = __m1;
__len1 = __len11;
__len2 = __len21;
}
}
}
template <class _BidirectionalIterator, class _Compare>
inline _LIBCPP_INLINE_VISIBILITY
void
inplace_merge(_BidirectionalIterator __first, _BidirectionalIterator __middle, _BidirectionalIterator __last,
_Compare __comp)
{
typedef typename iterator_traits<_BidirectionalIterator>::value_type value_type;
typedef typename iterator_traits<_BidirectionalIterator>::difference_type difference_type;
difference_type __len1 = _VSTD::distance(__first, __middle);
difference_type __len2 = _VSTD::distance(__middle, __last);
difference_type __buf_size = _VSTD::min(__len1, __len2);
pair<value_type*, ptrdiff_t> __buf = _VSTD::get_temporary_buffer<value_type>(__buf_size);
unique_ptr<value_type, __return_temporary_buffer> __h(__buf.first);
typedef typename __comp_ref_type<_Compare>::type _Comp_ref;
return _VSTD::__inplace_merge<_Comp_ref>(__first, __middle, __last, __comp, __len1, __len2,
__buf.first, __buf.second);
}
template <class _BidirectionalIterator>
inline _LIBCPP_INLINE_VISIBILITY
void
inplace_merge(_BidirectionalIterator __first, _BidirectionalIterator __middle, _BidirectionalIterator __last)
{
_VSTD::inplace_merge(__first, __middle, __last,
__less<typename iterator_traits<_BidirectionalIterator>::value_type>());
}
// stable_sort
template <class _Compare, class _InputIterator1, class _InputIterator2>
void
__merge_move_construct(_InputIterator1 __first1, _InputIterator1 __last1,
_InputIterator2 __first2, _InputIterator2 __last2,
typename iterator_traits<_InputIterator1>::value_type* __result, _Compare __comp)
{
typedef typename iterator_traits<_InputIterator1>::value_type value_type;
__destruct_n __d(0);
unique_ptr<value_type, __destruct_n&> __h(__result, __d);
for (; true; ++__result)
{
if (__first1 == __last1)
{
for (; __first2 != __last2; ++__first2, ++__result, (void) __d.__incr((value_type*)0))
::new (__result) value_type(_VSTD::move(*__first2));
__h.release();
return;
}
if (__first2 == __last2)
{
for (; __first1 != __last1; ++__first1, ++__result, (void) __d.__incr((value_type*)0))
::new (__result) value_type(_VSTD::move(*__first1));
__h.release();
return;
}
if (__comp(*__first2, *__first1))
{
::new (__result) value_type(_VSTD::move(*__first2));
__d.__incr((value_type*)0);
++__first2;
}
else
{
::new (__result) value_type(_VSTD::move(*__first1));
__d.__incr((value_type*)0);
++__first1;
}
}
}
template <class _Compare, class _InputIterator1, class _InputIterator2, class _OutputIterator>
void
__merge_move_assign(_InputIterator1 __first1, _InputIterator1 __last1,
_InputIterator2 __first2, _InputIterator2 __last2,
_OutputIterator __result, _Compare __comp)
{
for (; __first1 != __last1; ++__result)
{
if (__first2 == __last2)
{
for (; __first1 != __last1; ++__first1, (void) ++__result)
*__result = _VSTD::move(*__first1);
return;
}
if (__comp(*__first2, *__first1))
{
*__result = _VSTD::move(*__first2);
++__first2;
}
else
{
*__result = _VSTD::move(*__first1);
++__first1;
}
}
for (; __first2 != __last2; ++__first2, (void) ++__result)
*__result = _VSTD::move(*__first2);
}
template <class _Compare, class _RandomAccessIterator>
void
__stable_sort(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp,
typename iterator_traits<_RandomAccessIterator>::difference_type __len,
typename iterator_traits<_RandomAccessIterator>::value_type* __buff, ptrdiff_t __buff_size);
template <class _Compare, class _RandomAccessIterator>
void
__stable_sort_move(_RandomAccessIterator __first1, _RandomAccessIterator __last1, _Compare __comp,
typename iterator_traits<_RandomAccessIterator>::difference_type __len,
typename iterator_traits<_RandomAccessIterator>::value_type* __first2)
{
typedef typename iterator_traits<_RandomAccessIterator>::value_type value_type;
switch (__len)
{
case 0:
return;
case 1:
::new(__first2) value_type(_VSTD::move(*__first1));
return;
case 2:
__destruct_n __d(0);
unique_ptr<value_type, __destruct_n&> __h2(__first2, __d);
if (__comp(*--__last1, *__first1))
{
::new(__first2) value_type(_VSTD::move(*__last1));
__d.__incr((value_type*)0);
++__first2;
::new(__first2) value_type(_VSTD::move(*__first1));
}
else
{
::new(__first2) value_type(_VSTD::move(*__first1));
__d.__incr((value_type*)0);
++__first2;
::new(__first2) value_type(_VSTD::move(*__last1));
}
__h2.release();
return;
}
if (__len <= 8)
{
__insertion_sort_move<_Compare>(__first1, __last1, __first2, __comp);
return;
}
typename iterator_traits<_RandomAccessIterator>::difference_type __l2 = __len / 2;
_RandomAccessIterator __m = __first1 + __l2;
__stable_sort<_Compare>(__first1, __m, __comp, __l2, __first2, __l2);
__stable_sort<_Compare>(__m, __last1, __comp, __len - __l2, __first2 + __l2, __len - __l2);
__merge_move_construct<_Compare>(__first1, __m, __m, __last1, __first2, __comp);
}
template <class _Tp>
struct __stable_sort_switch
{
static const unsigned value = 128*is_trivially_copy_assignable<_Tp>::value;
};
template <class _Compare, class _RandomAccessIterator>
void
__stable_sort(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp,
typename iterator_traits<_RandomAccessIterator>::difference_type __len,
typename iterator_traits<_RandomAccessIterator>::value_type* __buff, ptrdiff_t __buff_size)
{
typedef typename iterator_traits<_RandomAccessIterator>::value_type value_type;
typedef typename iterator_traits<_RandomAccessIterator>::difference_type difference_type;
switch (__len)
{
case 0:
case 1:
return;
case 2:
if (__comp(*--__last, *__first))
swap(*__first, *__last);
return;
}
if (__len <= static_cast<difference_type>(__stable_sort_switch<value_type>::value))
{
__insertion_sort<_Compare>(__first, __last, __comp);
return;
}
typename iterator_traits<_RandomAccessIterator>::difference_type __l2 = __len / 2;
_RandomAccessIterator __m = __first + __l2;
if (__len <= __buff_size)
{
__destruct_n __d(0);
unique_ptr<value_type, __destruct_n&> __h2(__buff, __d);
__stable_sort_move<_Compare>(__first, __m, __comp, __l2, __buff);
__d.__set(__l2, (value_type*)0);
__stable_sort_move<_Compare>(__m, __last, __comp, __len - __l2, __buff + __l2);
__d.__set(__len, (value_type*)0);
__merge_move_assign<_Compare>(__buff, __buff + __l2, __buff + __l2, __buff + __len, __first, __comp);
// __merge<_Compare>(move_iterator<value_type*>(__buff),
// move_iterator<value_type*>(__buff + __l2),
// move_iterator<_RandomAccessIterator>(__buff + __l2),
// move_iterator<_RandomAccessIterator>(__buff + __len),
// __first, __comp);
return;
}
__stable_sort<_Compare>(__first, __m, __comp, __l2, __buff, __buff_size);
__stable_sort<_Compare>(__m, __last, __comp, __len - __l2, __buff, __buff_size);
__inplace_merge<_Compare>(__first, __m, __last, __comp, __l2, __len - __l2, __buff, __buff_size);
}
template <class _RandomAccessIterator, class _Compare>
inline _LIBCPP_INLINE_VISIBILITY
void
stable_sort(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp)
{
typedef typename iterator_traits<_RandomAccessIterator>::value_type value_type;
typedef typename iterator_traits<_RandomAccessIterator>::difference_type difference_type;
difference_type __len = __last - __first;
pair<value_type*, ptrdiff_t> __buf(0, 0);
unique_ptr<value_type, __return_temporary_buffer> __h;
if (__len > static_cast<difference_type>(__stable_sort_switch<value_type>::value))
{
__buf = _VSTD::get_temporary_buffer<value_type>(__len);
__h.reset(__buf.first);
}
typedef typename __comp_ref_type<_Compare>::type _Comp_ref;
__stable_sort<_Comp_ref>(__first, __last, __comp, __len, __buf.first, __buf.second);
}
template <class _RandomAccessIterator>
inline _LIBCPP_INLINE_VISIBILITY
void
stable_sort(_RandomAccessIterator __first, _RandomAccessIterator __last)
{
_VSTD::stable_sort(__first, __last, __less<typename iterator_traits<_RandomAccessIterator>::value_type>());
}
// is_heap_until
template <class _RandomAccessIterator, class _Compare>
_LIBCPP_NODISCARD_EXT _LIBCPP_CONSTEXPR_AFTER_CXX17 _RandomAccessIterator
is_heap_until(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp)
{
typedef typename _VSTD::iterator_traits<_RandomAccessIterator>::difference_type difference_type;
difference_type __len = __last - __first;
difference_type __p = 0;
difference_type __c = 1;
_RandomAccessIterator __pp = __first;
while (__c < __len)
{
_RandomAccessIterator __cp = __first + __c;
if (__comp(*__pp, *__cp))
return __cp;
++__c;
++__cp;
if (__c == __len)
return __last;
if (__comp(*__pp, *__cp))
return __cp;
++__p;
++__pp;
__c = 2 * __p + 1;
}
return __last;
}
template<class _RandomAccessIterator>
_LIBCPP_NODISCARD_EXT inline
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
_RandomAccessIterator
is_heap_until(_RandomAccessIterator __first, _RandomAccessIterator __last)
{
return _VSTD::is_heap_until(__first, __last, __less<typename iterator_traits<_RandomAccessIterator>::value_type>());
}
// is_heap
template <class _RandomAccessIterator, class _Compare>
_LIBCPP_NODISCARD_EXT inline
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
bool
is_heap(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp)
{
return _VSTD::is_heap_until(__first, __last, __comp) == __last;
}
template<class _RandomAccessIterator>
_LIBCPP_NODISCARD_EXT inline
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
bool
is_heap(_RandomAccessIterator __first, _RandomAccessIterator __last)
{
return _VSTD::is_heap(__first, __last, __less<typename iterator_traits<_RandomAccessIterator>::value_type>());
}
// push_heap
template <class _Compare, class _RandomAccessIterator>
void
__sift_up(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp,
typename iterator_traits<_RandomAccessIterator>::difference_type __len)
{
typedef typename iterator_traits<_RandomAccessIterator>::value_type value_type;
if (__len > 1)
{
__len = (__len - 2) / 2;
_RandomAccessIterator __ptr = __first + __len;
if (__comp(*__ptr, *--__last))
{
value_type __t(_VSTD::move(*__last));
do
{
*__last = _VSTD::move(*__ptr);
__last = __ptr;
if (__len == 0)
break;
__len = (__len - 1) / 2;
__ptr = __first + __len;
} while (__comp(*__ptr, __t));
*__last = _VSTD::move(__t);
}
}
}
template <class _RandomAccessIterator, class _Compare>
inline _LIBCPP_INLINE_VISIBILITY
void
push_heap(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp)
{
typedef typename __comp_ref_type<_Compare>::type _Comp_ref;
__sift_up<_Comp_ref>(__first, __last, __comp, __last - __first);
}
template <class _RandomAccessIterator>
inline _LIBCPP_INLINE_VISIBILITY
void
push_heap(_RandomAccessIterator __first, _RandomAccessIterator __last)
{
_VSTD::push_heap(__first, __last, __less<typename iterator_traits<_RandomAccessIterator>::value_type>());
}
// pop_heap
template <class _Compare, class _RandomAccessIterator>
void
__sift_down(_RandomAccessIterator __first, _RandomAccessIterator /*__last*/,
_Compare __comp,
typename iterator_traits<_RandomAccessIterator>::difference_type __len,
_RandomAccessIterator __start)
{
typedef typename iterator_traits<_RandomAccessIterator>::difference_type difference_type;
typedef typename iterator_traits<_RandomAccessIterator>::value_type value_type;
// left-child of __start is at 2 * __start + 1
// right-child of __start is at 2 * __start + 2
difference_type __child = __start - __first;
if (__len < 2 || (__len - 2) / 2 < __child)
return;
__child = 2 * __child + 1;
_RandomAccessIterator __child_i = __first + __child;
if ((__child + 1) < __len && __comp(*__child_i, *(__child_i + 1))) {
// right-child exists and is greater than left-child
++__child_i;
++__child;
}
// check if we are in heap-order
if (__comp(*__child_i, *__start))
// we are, __start is larger than it's largest child
return;
value_type __top(_VSTD::move(*__start));
do
{
// we are not in heap-order, swap the parent with it's largest child
*__start = _VSTD::move(*__child_i);
__start = __child_i;
if ((__len - 2) / 2 < __child)
break;
// recompute the child based off of the updated parent
__child = 2 * __child + 1;
__child_i = __first + __child;
if ((__child + 1) < __len && __comp(*__child_i, *(__child_i + 1))) {
// right-child exists and is greater than left-child
++__child_i;
++__child;
}
// check if we are in heap-order
} while (!__comp(*__child_i, __top));
*__start = _VSTD::move(__top);
}
template <class _Compare, class _RandomAccessIterator>
inline _LIBCPP_INLINE_VISIBILITY
void
__pop_heap(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp,
typename iterator_traits<_RandomAccessIterator>::difference_type __len)
{
if (__len > 1)
{
swap(*__first, *--__last);
__sift_down<_Compare>(__first, __last, __comp, __len - 1, __first);
}
}
template <class _RandomAccessIterator, class _Compare>
inline _LIBCPP_INLINE_VISIBILITY
void
pop_heap(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp)
{
typedef typename __comp_ref_type<_Compare>::type _Comp_ref;
__pop_heap<_Comp_ref>(__first, __last, __comp, __last - __first);
}
template <class _RandomAccessIterator>
inline _LIBCPP_INLINE_VISIBILITY
void
pop_heap(_RandomAccessIterator __first, _RandomAccessIterator __last)
{
_VSTD::pop_heap(__first, __last, __less<typename iterator_traits<_RandomAccessIterator>::value_type>());
}
// make_heap
template <class _Compare, class _RandomAccessIterator>
void
__make_heap(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp)
{
typedef typename iterator_traits<_RandomAccessIterator>::difference_type difference_type;
difference_type __n = __last - __first;
if (__n > 1)
{
// start from the first parent, there is no need to consider children
for (difference_type __start = (__n - 2) / 2; __start >= 0; --__start)
{
__sift_down<_Compare>(__first, __last, __comp, __n, __first + __start);
}
}
}
template <class _RandomAccessIterator, class _Compare>
inline _LIBCPP_INLINE_VISIBILITY
void
make_heap(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp)
{
typedef typename __comp_ref_type<_Compare>::type _Comp_ref;
__make_heap<_Comp_ref>(__first, __last, __comp);
}
template <class _RandomAccessIterator>
inline _LIBCPP_INLINE_VISIBILITY
void
make_heap(_RandomAccessIterator __first, _RandomAccessIterator __last)
{
_VSTD::make_heap(__first, __last, __less<typename iterator_traits<_RandomAccessIterator>::value_type>());
}
// sort_heap
template <class _Compare, class _RandomAccessIterator>
void
__sort_heap(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp)
{
typedef typename iterator_traits<_RandomAccessIterator>::difference_type difference_type;
for (difference_type __n = __last - __first; __n > 1; --__last, (void) --__n)
__pop_heap<_Compare>(__first, __last, __comp, __n);
}
template <class _RandomAccessIterator, class _Compare>
inline _LIBCPP_INLINE_VISIBILITY
void
sort_heap(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp)
{
typedef typename __comp_ref_type<_Compare>::type _Comp_ref;
__sort_heap<_Comp_ref>(__first, __last, __comp);
}
template <class _RandomAccessIterator>
inline _LIBCPP_INLINE_VISIBILITY
void
sort_heap(_RandomAccessIterator __first, _RandomAccessIterator __last)
{
_VSTD::sort_heap(__first, __last, __less<typename iterator_traits<_RandomAccessIterator>::value_type>());
}
// partial_sort
template <class _Compare, class _RandomAccessIterator>
void
__partial_sort(_RandomAccessIterator __first, _RandomAccessIterator __middle, _RandomAccessIterator __last,
_Compare __comp)
{
__make_heap<_Compare>(__first, __middle, __comp);
typename iterator_traits<_RandomAccessIterator>::difference_type __len = __middle - __first;
for (_RandomAccessIterator __i = __middle; __i != __last; ++__i)
{
if (__comp(*__i, *__first))
{
swap(*__i, *__first);
__sift_down<_Compare>(__first, __middle, __comp, __len, __first);
}
}
__sort_heap<_Compare>(__first, __middle, __comp);
}
template <class _RandomAccessIterator, class _Compare>
inline _LIBCPP_INLINE_VISIBILITY
void
partial_sort(_RandomAccessIterator __first, _RandomAccessIterator __middle, _RandomAccessIterator __last,
_Compare __comp)
{
typedef typename __comp_ref_type<_Compare>::type _Comp_ref;
__partial_sort<_Comp_ref>(__first, __middle, __last, __comp);
}
template <class _RandomAccessIterator>
inline _LIBCPP_INLINE_VISIBILITY
void
partial_sort(_RandomAccessIterator __first, _RandomAccessIterator __middle, _RandomAccessIterator __last)
{
_VSTD::partial_sort(__first, __middle, __last,
__less<typename iterator_traits<_RandomAccessIterator>::value_type>());
}
// partial_sort_copy
template <class _Compare, class _InputIterator, class _RandomAccessIterator>
_RandomAccessIterator
__partial_sort_copy(_InputIterator __first, _InputIterator __last,
_RandomAccessIterator __result_first, _RandomAccessIterator __result_last, _Compare __comp)
{
_RandomAccessIterator __r = __result_first;
if (__r != __result_last)
{
for (; __first != __last && __r != __result_last; ++__first, (void) ++__r)
*__r = *__first;
__make_heap<_Compare>(__result_first, __r, __comp);
typename iterator_traits<_RandomAccessIterator>::difference_type __len = __r - __result_first;
for (; __first != __last; ++__first)
if (__comp(*__first, *__result_first))
{
*__result_first = *__first;
__sift_down<_Compare>(__result_first, __r, __comp, __len, __result_first);
}
__sort_heap<_Compare>(__result_first, __r, __comp);
}
return __r;
}
template <class _InputIterator, class _RandomAccessIterator, class _Compare>
inline _LIBCPP_INLINE_VISIBILITY
_RandomAccessIterator
partial_sort_copy(_InputIterator __first, _InputIterator __last,
_RandomAccessIterator __result_first, _RandomAccessIterator __result_last, _Compare __comp)
{
typedef typename __comp_ref_type<_Compare>::type _Comp_ref;
return __partial_sort_copy<_Comp_ref>(__first, __last, __result_first, __result_last, __comp);
}
template <class _InputIterator, class _RandomAccessIterator>
inline _LIBCPP_INLINE_VISIBILITY
_RandomAccessIterator
partial_sort_copy(_InputIterator __first, _InputIterator __last,
_RandomAccessIterator __result_first, _RandomAccessIterator __result_last)
{
return _VSTD::partial_sort_copy(__first, __last, __result_first, __result_last,
__less<typename iterator_traits<_RandomAccessIterator>::value_type>());
}
// nth_element
template <class _Compare, class _RandomAccessIterator>
void
__nth_element(_RandomAccessIterator __first, _RandomAccessIterator __nth, _RandomAccessIterator __last, _Compare __comp)
{
// _Compare is known to be a reference type
typedef typename iterator_traits<_RandomAccessIterator>::difference_type difference_type;
const difference_type __limit = 7;
while (true)
{
__restart:
if (__nth == __last)
return;
difference_type __len = __last - __first;
switch (__len)
{
case 0:
case 1:
return;
case 2:
if (__comp(*--__last, *__first))
swap(*__first, *__last);
return;
case 3:
{
_RandomAccessIterator __m = __first;
_VSTD::__sort3<_Compare>(__first, ++__m, --__last, __comp);
return;
}
}
if (__len <= __limit)
{
__selection_sort<_Compare>(__first, __last, __comp);
return;
}
// __len > __limit >= 3
_RandomAccessIterator __m = __first + __len/2;
_RandomAccessIterator __lm1 = __last;
unsigned __n_swaps = _VSTD::__sort3<_Compare>(__first, __m, --__lm1, __comp);
// *__m is median
// partition [__first, __m) < *__m and *__m <= [__m, __last)
// (this inhibits tossing elements equivalent to __m around unnecessarily)
_RandomAccessIterator __i = __first;
_RandomAccessIterator __j = __lm1;
// j points beyond range to be tested, *__lm1 is known to be <= *__m
// The search going up is known to be guarded but the search coming down isn't.
// Prime the downward search with a guard.
if (!__comp(*__i, *__m)) // if *__first == *__m
{
// *__first == *__m, *__first doesn't go in first part
// manually guard downward moving __j against __i
while (true)
{
if (__i == --__j)
{
// *__first == *__m, *__m <= all other elements
// Parition instead into [__first, __i) == *__first and *__first < [__i, __last)
++__i; // __first + 1
__j = __last;
if (!__comp(*__first, *--__j)) // we need a guard if *__first == *(__last-1)
{
while (true)
{
if (__i == __j)
return; // [__first, __last) all equivalent elements
if (__comp(*__first, *__i))
{
swap(*__i, *__j);
++__n_swaps;
++__i;
break;
}
++__i;
}
}
// [__first, __i) == *__first and *__first < [__j, __last) and __j == __last - 1
if (__i == __j)
return;
while (true)
{
while (!__comp(*__first, *__i))
++__i;
while (__comp(*__first, *--__j))
;
if (__i >= __j)
break;
swap(*__i, *__j);
++__n_swaps;
++__i;
}
// [__first, __i) == *__first and *__first < [__i, __last)
// The first part is sorted,
if (__nth < __i)
return;
// __nth_element the secod part
// __nth_element<_Compare>(__i, __nth, __last, __comp);
__first = __i;
goto __restart;
}
if (__comp(*__j, *__m))
{
swap(*__i, *__j);
++__n_swaps;
break; // found guard for downward moving __j, now use unguarded partition
}
}
}
++__i;
// j points beyond range to be tested, *__lm1 is known to be <= *__m
// if not yet partitioned...
if (__i < __j)
{
// known that *(__i - 1) < *__m
while (true)
{
// __m still guards upward moving __i
while (__comp(*__i, *__m))
++__i;
// It is now known that a guard exists for downward moving __j
while (!__comp(*--__j, *__m))
;
if (__i >= __j)
break;
swap(*__i, *__j);
++__n_swaps;
// It is known that __m != __j
// If __m just moved, follow it
if (__m == __i)
__m = __j;
++__i;
}
}
// [__first, __i) < *__m and *__m <= [__i, __last)
if (__i != __m && __comp(*__m, *__i))
{
swap(*__i, *__m);
++__n_swaps;
}
// [__first, __i) < *__i and *__i <= [__i+1, __last)
if (__nth == __i)
return;
if (__n_swaps == 0)
{
// We were given a perfectly partitioned sequence. Coincidence?
if (__nth < __i)
{
// Check for [__first, __i) already sorted
__j = __m = __first;
while (++__j != __i)
{
if (__comp(*__j, *__m))
// not yet sorted, so sort
goto not_sorted;
__m = __j;
}
// [__first, __i) sorted
return;
}
else
{
// Check for [__i, __last) already sorted
__j = __m = __i;
while (++__j != __last)
{
if (__comp(*__j, *__m))
// not yet sorted, so sort
goto not_sorted;
__m = __j;
}
// [__i, __last) sorted
return;
}
}
not_sorted:
// __nth_element on range containing __nth
if (__nth < __i)
{
// __nth_element<_Compare>(__first, __nth, __i, __comp);
__last = __i;
}
else
{
// __nth_element<_Compare>(__i+1, __nth, __last, __comp);
__first = ++__i;
}
}
}
template <class _RandomAccessIterator, class _Compare>
inline _LIBCPP_INLINE_VISIBILITY
void
nth_element(_RandomAccessIterator __first, _RandomAccessIterator __nth, _RandomAccessIterator __last, _Compare __comp)
{
typedef typename __comp_ref_type<_Compare>::type _Comp_ref;
__nth_element<_Comp_ref>(__first, __nth, __last, __comp);
}
template <class _RandomAccessIterator>
inline _LIBCPP_INLINE_VISIBILITY
void
nth_element(_RandomAccessIterator __first, _RandomAccessIterator __nth, _RandomAccessIterator __last)
{
_VSTD::nth_element(__first, __nth, __last, __less<typename iterator_traits<_RandomAccessIterator>::value_type>());
}
// includes
template <class _Compare, class _InputIterator1, class _InputIterator2>
_LIBCPP_CONSTEXPR_AFTER_CXX17 bool
__includes(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2, _InputIterator2 __last2,
_Compare __comp)
{
for (; __first2 != __last2; ++__first1)
{
if (__first1 == __last1 || __comp(*__first2, *__first1))
return false;
if (!__comp(*__first1, *__first2))
++__first2;
}
return true;
}
template <class _InputIterator1, class _InputIterator2, class _Compare>
_LIBCPP_NODISCARD_EXT inline
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
bool
includes(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2, _InputIterator2 __last2,
_Compare __comp)
{
typedef typename __comp_ref_type<_Compare>::type _Comp_ref;
return __includes<_Comp_ref>(__first1, __last1, __first2, __last2, __comp);
}
template <class _InputIterator1, class _InputIterator2>
_LIBCPP_NODISCARD_EXT inline
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
bool
includes(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2, _InputIterator2 __last2)
{
return _VSTD::includes(__first1, __last1, __first2, __last2,
__less<typename iterator_traits<_InputIterator1>::value_type,
typename iterator_traits<_InputIterator2>::value_type>());
}
// set_union
template <class _Compare, class _InputIterator1, class _InputIterator2, class _OutputIterator>
_OutputIterator
__set_union(_InputIterator1 __first1, _InputIterator1 __last1,
_InputIterator2 __first2, _InputIterator2 __last2, _OutputIterator __result, _Compare __comp)
{
for (; __first1 != __last1; ++__result)
{
if (__first2 == __last2)
return _VSTD::copy(__first1, __last1, __result);
if (__comp(*__first2, *__first1))
{
*__result = *__first2;
++__first2;
}
else
{
if (!__comp(*__first1, *__first2))
++__first2;
*__result = *__first1;
++__first1;
}
}
return _VSTD::copy(__first2, __last2, __result);
}
template <class _InputIterator1, class _InputIterator2, class _OutputIterator, class _Compare>
inline _LIBCPP_INLINE_VISIBILITY
_OutputIterator
set_union(_InputIterator1 __first1, _InputIterator1 __last1,
_InputIterator2 __first2, _InputIterator2 __last2, _OutputIterator __result, _Compare __comp)
{
typedef typename __comp_ref_type<_Compare>::type _Comp_ref;
return __set_union<_Comp_ref>(__first1, __last1, __first2, __last2, __result, __comp);
}
template <class _InputIterator1, class _InputIterator2, class _OutputIterator>
inline _LIBCPP_INLINE_VISIBILITY
_OutputIterator
set_union(_InputIterator1 __first1, _InputIterator1 __last1,
_InputIterator2 __first2, _InputIterator2 __last2, _OutputIterator __result)
{
return _VSTD::set_union(__first1, __last1, __first2, __last2, __result,
__less<typename iterator_traits<_InputIterator1>::value_type,
typename iterator_traits<_InputIterator2>::value_type>());
}
// set_intersection
template <class _Compare, class _InputIterator1, class _InputIterator2, class _OutputIterator>
_LIBCPP_CONSTEXPR_AFTER_CXX17 _OutputIterator
__set_intersection(_InputIterator1 __first1, _InputIterator1 __last1,
_InputIterator2 __first2, _InputIterator2 __last2, _OutputIterator __result, _Compare __comp)
{
while (__first1 != __last1 && __first2 != __last2)
{
if (__comp(*__first1, *__first2))
++__first1;
else
{
if (!__comp(*__first2, *__first1))
{
*__result = *__first1;
++__result;
++__first1;
}
++__first2;
}
}
return __result;
}
template <class _InputIterator1, class _InputIterator2, class _OutputIterator, class _Compare>
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
_OutputIterator
set_intersection(_InputIterator1 __first1, _InputIterator1 __last1,
_InputIterator2 __first2, _InputIterator2 __last2, _OutputIterator __result, _Compare __comp)
{
typedef typename __comp_ref_type<_Compare>::type _Comp_ref;
return __set_intersection<_Comp_ref>(__first1, __last1, __first2, __last2, __result, __comp);
}
template <class _InputIterator1, class _InputIterator2, class _OutputIterator>
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
_OutputIterator
set_intersection(_InputIterator1 __first1, _InputIterator1 __last1,
_InputIterator2 __first2, _InputIterator2 __last2, _OutputIterator __result)
{
return _VSTD::set_intersection(__first1, __last1, __first2, __last2, __result,
__less<typename iterator_traits<_InputIterator1>::value_type,
typename iterator_traits<_InputIterator2>::value_type>());
}
// set_difference
template <class _Compare, class _InputIterator1, class _InputIterator2, class _OutputIterator>
_OutputIterator
__set_difference(_InputIterator1 __first1, _InputIterator1 __last1,
_InputIterator2 __first2, _InputIterator2 __last2, _OutputIterator __result, _Compare __comp)
{
while (__first1 != __last1)
{
if (__first2 == __last2)
return _VSTD::copy(__first1, __last1, __result);
if (__comp(*__first1, *__first2))
{
*__result = *__first1;
++__result;
++__first1;
}
else
{
if (!__comp(*__first2, *__first1))
++__first1;
++__first2;
}
}
return __result;
}
template <class _InputIterator1, class _InputIterator2, class _OutputIterator, class _Compare>
inline _LIBCPP_INLINE_VISIBILITY
_OutputIterator
set_difference(_InputIterator1 __first1, _InputIterator1 __last1,
_InputIterator2 __first2, _InputIterator2 __last2, _OutputIterator __result, _Compare __comp)
{
typedef typename __comp_ref_type<_Compare>::type _Comp_ref;
return __set_difference<_Comp_ref>(__first1, __last1, __first2, __last2, __result, __comp);
}
template <class _InputIterator1, class _InputIterator2, class _OutputIterator>
inline _LIBCPP_INLINE_VISIBILITY
_OutputIterator
set_difference(_InputIterator1 __first1, _InputIterator1 __last1,
_InputIterator2 __first2, _InputIterator2 __last2, _OutputIterator __result)
{
return _VSTD::set_difference(__first1, __last1, __first2, __last2, __result,
__less<typename iterator_traits<_InputIterator1>::value_type,
typename iterator_traits<_InputIterator2>::value_type>());
}
// set_symmetric_difference
template <class _Compare, class _InputIterator1, class _InputIterator2, class _OutputIterator>
_OutputIterator
__set_symmetric_difference(_InputIterator1 __first1, _InputIterator1 __last1,
_InputIterator2 __first2, _InputIterator2 __last2, _OutputIterator __result, _Compare __comp)
{
while (__first1 != __last1)
{
if (__first2 == __last2)
return _VSTD::copy(__first1, __last1, __result);
if (__comp(*__first1, *__first2))
{
*__result = *__first1;
++__result;
++__first1;
}
else
{
if (__comp(*__first2, *__first1))
{
*__result = *__first2;
++__result;
}
else
++__first1;
++__first2;
}
}
return _VSTD::copy(__first2, __last2, __result);
}
template <class _InputIterator1, class _InputIterator2, class _OutputIterator, class _Compare>
inline _LIBCPP_INLINE_VISIBILITY
_OutputIterator
set_symmetric_difference(_InputIterator1 __first1, _InputIterator1 __last1,
_InputIterator2 __first2, _InputIterator2 __last2, _OutputIterator __result, _Compare __comp)
{
typedef typename __comp_ref_type<_Compare>::type _Comp_ref;
return __set_symmetric_difference<_Comp_ref>(__first1, __last1, __first2, __last2, __result, __comp);
}
template <class _InputIterator1, class _InputIterator2, class _OutputIterator>
inline _LIBCPP_INLINE_VISIBILITY
_OutputIterator
set_symmetric_difference(_InputIterator1 __first1, _InputIterator1 __last1,
_InputIterator2 __first2, _InputIterator2 __last2, _OutputIterator __result)
{
return _VSTD::set_symmetric_difference(__first1, __last1, __first2, __last2, __result,
__less<typename iterator_traits<_InputIterator1>::value_type,
typename iterator_traits<_InputIterator2>::value_type>());
}
// lexicographical_compare
template <class _Compare, class _InputIterator1, class _InputIterator2>
_LIBCPP_CONSTEXPR_AFTER_CXX17 bool
__lexicographical_compare(_InputIterator1 __first1, _InputIterator1 __last1,
_InputIterator2 __first2, _InputIterator2 __last2, _Compare __comp)
{
for (; __first2 != __last2; ++__first1, (void) ++__first2)
{
if (__first1 == __last1 || __comp(*__first1, *__first2))
return true;
if (__comp(*__first2, *__first1))
return false;
}
return false;
}
template <class _InputIterator1, class _InputIterator2, class _Compare>
_LIBCPP_NODISCARD_EXT inline
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
bool
lexicographical_compare(_InputIterator1 __first1, _InputIterator1 __last1,
_InputIterator2 __first2, _InputIterator2 __last2, _Compare __comp)
{
typedef typename __comp_ref_type<_Compare>::type _Comp_ref;
return __lexicographical_compare<_Comp_ref>(__first1, __last1, __first2, __last2, __comp);
}
template <class _InputIterator1, class _InputIterator2>
_LIBCPP_NODISCARD_EXT inline
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
bool
lexicographical_compare(_InputIterator1 __first1, _InputIterator1 __last1,
_InputIterator2 __first2, _InputIterator2 __last2)
{
return _VSTD::lexicographical_compare(__first1, __last1, __first2, __last2,
__less<typename iterator_traits<_InputIterator1>::value_type,
typename iterator_traits<_InputIterator2>::value_type>());
}
// next_permutation
template <class _Compare, class _BidirectionalIterator>
bool
__next_permutation(_BidirectionalIterator __first, _BidirectionalIterator __last, _Compare __comp)
{
_BidirectionalIterator __i = __last;
if (__first == __last || __first == --__i)
return false;
while (true)
{
_BidirectionalIterator __ip1 = __i;
if (__comp(*--__i, *__ip1))
{
_BidirectionalIterator __j = __last;
while (!__comp(*__i, *--__j))
;
swap(*__i, *__j);
_VSTD::reverse(__ip1, __last);
return true;
}
if (__i == __first)
{
_VSTD::reverse(__first, __last);
return false;
}
}
}
template <class _BidirectionalIterator, class _Compare>
inline _LIBCPP_INLINE_VISIBILITY
bool
next_permutation(_BidirectionalIterator __first, _BidirectionalIterator __last, _Compare __comp)
{
typedef typename __comp_ref_type<_Compare>::type _Comp_ref;
return __next_permutation<_Comp_ref>(__first, __last, __comp);
}
template <class _BidirectionalIterator>
inline _LIBCPP_INLINE_VISIBILITY
bool
next_permutation(_BidirectionalIterator __first, _BidirectionalIterator __last)
{
return _VSTD::next_permutation(__first, __last,
__less<typename iterator_traits<_BidirectionalIterator>::value_type>());
}
// prev_permutation
template <class _Compare, class _BidirectionalIterator>
bool
__prev_permutation(_BidirectionalIterator __first, _BidirectionalIterator __last, _Compare __comp)
{
_BidirectionalIterator __i = __last;
if (__first == __last || __first == --__i)
return false;
while (true)
{
_BidirectionalIterator __ip1 = __i;
if (__comp(*__ip1, *--__i))
{
_BidirectionalIterator __j = __last;
while (!__comp(*--__j, *__i))
;
swap(*__i, *__j);
_VSTD::reverse(__ip1, __last);
return true;
}
if (__i == __first)
{
_VSTD::reverse(__first, __last);
return false;
}
}
}
template <class _BidirectionalIterator, class _Compare>
inline _LIBCPP_INLINE_VISIBILITY
bool
prev_permutation(_BidirectionalIterator __first, _BidirectionalIterator __last, _Compare __comp)
{
typedef typename __comp_ref_type<_Compare>::type _Comp_ref;
return __prev_permutation<_Comp_ref>(__first, __last, __comp);
}
template <class _BidirectionalIterator>
inline _LIBCPP_INLINE_VISIBILITY
bool
prev_permutation(_BidirectionalIterator __first, _BidirectionalIterator __last)
{
return _VSTD::prev_permutation(__first, __last,
__less<typename iterator_traits<_BidirectionalIterator>::value_type>());
}
_LIBCPP_END_NAMESPACE_STD
_LIBCPP_POP_MACROS
#endif // _LIBCPP_ALGORITHM
| 202,432 | 5,686 | jart/cosmopolitan | false |
cosmopolitan/third_party/libcxx/cmath | // -*- C++ -*-
//===---------------------------- cmath -----------------------------------===//
//
// 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_CMATH
#define _LIBCPP_CMATH
#include "third_party/libcxx/__config"
#include "third_party/libcxx/math.h"
#include "third_party/libcxx/version"
#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
/*
cmath synopsis
Macros:
HUGE_VAL
HUGE_VALF // C99
HUGE_VALL // C99
INFINITY // C99
NAN // C99
FP_INFINITE // C99
FP_NAN // C99
FP_NORMAL // C99
FP_SUBNORMAL // C99
FP_ZERO // C99
FP_FAST_FMA // C99
FP_FAST_FMAF // C99
FP_FAST_FMAL // C99
FP_ILOGB0 // C99
FP_ILOGBNAN // C99
MATH_ERRNO // C99
MATH_ERREXCEPT // C99
math_errhandling // C99
namespace std
{
Types:
float_t // C99
double_t // C99
// C90
floating_point abs(floating_point x);
floating_point acos (arithmetic x);
float acosf(float x);
long double acosl(long double x);
floating_point asin (arithmetic x);
float asinf(float x);
long double asinl(long double x);
floating_point atan (arithmetic x);
float atanf(float x);
long double atanl(long double x);
floating_point atan2 (arithmetic y, arithmetic x);
float atan2f(float y, float x);
long double atan2l(long double y, long double x);
floating_point ceil (arithmetic x);
float ceilf(float x);
long double ceill(long double x);
floating_point cos (arithmetic x);
float cosf(float x);
long double cosl(long double x);
floating_point cosh (arithmetic x);
float coshf(float x);
long double coshl(long double x);
floating_point exp (arithmetic x);
float expf(float x);
long double expl(long double x);
floating_point fabs (arithmetic x);
float fabsf(float x);
long double fabsl(long double x);
floating_point floor (arithmetic x);
float floorf(float x);
long double floorl(long double x);
floating_point fmod (arithmetic x, arithmetic y);
float fmodf(float x, float y);
long double fmodl(long double x, long double y);
floating_point frexp (arithmetic value, int* exp);
float frexpf(float value, int* exp);
long double frexpl(long double value, int* exp);
floating_point ldexp (arithmetic value, int exp);
float ldexpf(float value, int exp);
long double ldexpl(long double value, int exp);
floating_point log (arithmetic x);
float logf(float x);
long double logl(long double x);
floating_point log10 (arithmetic x);
float log10f(float x);
long double log10l(long double x);
floating_point modf (floating_point value, floating_point* iptr);
float modff(float value, float* iptr);
long double modfl(long double value, long double* iptr);
floating_point pow (arithmetic x, arithmetic y);
float powf(float x, float y);
long double powl(long double x, long double y);
floating_point sin (arithmetic x);
float sinf(float x);
long double sinl(long double x);
floating_point sinh (arithmetic x);
float sinhf(float x);
long double sinhl(long double x);
floating_point sqrt (arithmetic x);
float sqrtf(float x);
long double sqrtl(long double x);
floating_point tan (arithmetic x);
float tanf(float x);
long double tanl(long double x);
floating_point tanh (arithmetic x);
float tanhf(float x);
long double tanhl(long double x);
// C99
bool signbit(arithmetic x);
int fpclassify(arithmetic x);
bool isfinite(arithmetic x);
bool isinf(arithmetic x);
bool isnan(arithmetic x);
bool isnormal(arithmetic x);
bool isgreater(arithmetic x, arithmetic y);
bool isgreaterequal(arithmetic x, arithmetic y);
bool isless(arithmetic x, arithmetic y);
bool islessequal(arithmetic x, arithmetic y);
bool islessgreater(arithmetic x, arithmetic y);
bool isunordered(arithmetic x, arithmetic y);
floating_point acosh (arithmetic x);
float acoshf(float x);
long double acoshl(long double x);
floating_point asinh (arithmetic x);
float asinhf(float x);
long double asinhl(long double x);
floating_point atanh (arithmetic x);
float atanhf(float x);
long double atanhl(long double x);
floating_point cbrt (arithmetic x);
float cbrtf(float x);
long double cbrtl(long double x);
floating_point copysign (arithmetic x, arithmetic y);
float copysignf(float x, float y);
long double copysignl(long double x, long double y);
floating_point erf (arithmetic x);
float erff(float x);
long double erfl(long double x);
floating_point erfc (arithmetic x);
float erfcf(float x);
long double erfcl(long double x);
floating_point exp2 (arithmetic x);
float exp2f(float x);
long double exp2l(long double x);
floating_point expm1 (arithmetic x);
float expm1f(float x);
long double expm1l(long double x);
floating_point fdim (arithmetic x, arithmetic y);
float fdimf(float x, float y);
long double fdiml(long double x, long double y);
floating_point fma (arithmetic x, arithmetic y, arithmetic z);
float fmaf(float x, float y, float z);
long double fmal(long double x, long double y, long double z);
floating_point fmax (arithmetic x, arithmetic y);
float fmaxf(float x, float y);
long double fmaxl(long double x, long double y);
floating_point fmin (arithmetic x, arithmetic y);
float fminf(float x, float y);
long double fminl(long double x, long double y);
floating_point hypot (arithmetic x, arithmetic y);
float hypotf(float x, float y);
long double hypotl(long double x, long double y);
double hypot(double x, double y, double z); // C++17
float hypot(float x, float y, float z); // C++17
long double hypot(long double x, long double y, long double z); // C++17
int ilogb (arithmetic x);
int ilogbf(float x);
int ilogbl(long double x);
floating_point lgamma (arithmetic x);
float lgammaf(float x);
long double lgammal(long double x);
long long llrint (arithmetic x);
long long llrintf(float x);
long long llrintl(long double x);
long long llround (arithmetic x);
long long llroundf(float x);
long long llroundl(long double x);
floating_point log1p (arithmetic x);
float log1pf(float x);
long double log1pl(long double x);
floating_point log2 (arithmetic x);
float log2f(float x);
long double log2l(long double x);
floating_point logb (arithmetic x);
float logbf(float x);
long double logbl(long double x);
long lrint (arithmetic x);
long lrintf(float x);
long lrintl(long double x);
long lround (arithmetic x);
long lroundf(float x);
long lroundl(long double x);
double nan (const char* str);
float nanf(const char* str);
long double nanl(const char* str);
floating_point nearbyint (arithmetic x);
float nearbyintf(float x);
long double nearbyintl(long double x);
floating_point nextafter (arithmetic x, arithmetic y);
float nextafterf(float x, float y);
long double nextafterl(long double x, long double y);
floating_point nexttoward (arithmetic x, long double y);
float nexttowardf(float x, long double y);
long double nexttowardl(long double x, long double y);
floating_point remainder (arithmetic x, arithmetic y);
float remainderf(float x, float y);
long double remainderl(long double x, long double y);
floating_point remquo (arithmetic x, arithmetic y, int* pquo);
float remquof(float x, float y, int* pquo);
long double remquol(long double x, long double y, int* pquo);
floating_point rint (arithmetic x);
float rintf(float x);
long double rintl(long double x);
floating_point round (arithmetic x);
float roundf(float x);
long double roundl(long double x);
floating_point scalbln (arithmetic x, long ex);
float scalblnf(float x, long ex);
long double scalblnl(long double x, long ex);
floating_point scalbn (arithmetic x, int ex);
float scalbnf(float x, int ex);
long double scalbnl(long double x, int ex);
floating_point tgamma (arithmetic x);
float tgammaf(float x);
long double tgammal(long double x);
floating_point trunc (arithmetic x);
float truncf(float x);
long double truncl(long double x);
} // std
*/
using ::signbit;
using ::fpclassify;
using ::isfinite;
using ::isinf;
using ::isnan;
using ::isnormal;
using ::isgreater;
using ::isgreaterequal;
using ::isless;
using ::islessequal;
using ::islessgreater;
using ::isunordered;
using ::isunordered;
using ::float_t;
using ::double_t;
#ifndef _AIX
using ::abs;
#endif
using ::acos;
using ::acosf;
using ::asin;
using ::asinf;
using ::atan;
using ::atanf;
using ::atan2;
using ::atan2f;
using ::ceil;
using ::ceilf;
using ::cos;
using ::cosf;
using ::cosh;
using ::coshf;
using ::exp;
using ::expf;
using ::fabs;
using ::fabsf;
using ::floor;
using ::floorf;
using ::fmod;
using ::fmodf;
using ::frexp;
using ::frexpf;
using ::ldexp;
using ::ldexpf;
using ::log;
using ::logf;
using ::log10;
using ::log10f;
using ::modf;
using ::modff;
using ::pow;
using ::powf;
using ::sin;
using ::sinf;
using ::sinh;
using ::sinhf;
using ::sqrt;
using ::sqrtf;
using ::tan;
using ::tanf;
using ::tanh;
using ::tanhf;
using ::acosh;
using ::acoshf;
using ::asinh;
using ::asinhf;
using ::atanh;
using ::atanhf;
using ::cbrt;
using ::cbrtf;
using ::copysign;
using ::copysignf;
using ::erf;
using ::erff;
using ::erfc;
using ::erfcf;
using ::exp2;
using ::exp2f;
using ::expm1;
using ::expm1f;
using ::fdim;
using ::fdimf;
using ::fmaf;
using ::fma;
using ::fmax;
using ::fmaxf;
using ::fmin;
using ::fminf;
using ::hypot;
using ::hypotf;
using ::ilogb;
using ::ilogbf;
using ::lgamma;
using ::lgammaf;
using ::llrint;
using ::llrintf;
using ::llround;
using ::llroundf;
using ::log1p;
using ::log1pf;
using ::log2;
using ::log2f;
using ::logb;
using ::logbf;
using ::lrint;
using ::lrintf;
using ::lround;
using ::lroundf;
using ::nan;
using ::nanf;
using ::nearbyint;
using ::nearbyintf;
using ::nextafter;
using ::nextafterf;
using ::nexttoward;
using ::nexttowardf;
using ::remainder;
using ::remainderf;
using ::remquo;
using ::remquof;
using ::rint;
using ::rintf;
using ::round;
using ::roundf;
using ::scalbln;
using ::scalblnf;
using ::scalbn;
using ::scalbnf;
using ::tgamma;
using ::tgammaf;
using ::trunc;
using ::truncf;
using ::acosl;
using ::asinl;
using ::atanl;
using ::atan2l;
using ::ceill;
using ::cosl;
using ::coshl;
using ::expl;
using ::fabsl;
using ::floorl;
using ::fmodl;
using ::frexpl;
using ::ldexpl;
using ::logl;
using ::log10l;
using ::modfl;
using ::powl;
using ::sinl;
using ::sinhl;
using ::sqrtl;
using ::tanl;
using ::tanhl;
using ::acoshl;
using ::asinhl;
using ::atanhl;
using ::cbrtl;
using ::copysignl;
using ::erfl;
using ::erfcl;
using ::exp2l;
using ::expm1l;
using ::fdiml;
using ::fmal;
using ::fmaxl;
using ::fminl;
using ::hypotl;
using ::ilogbl;
using ::lgammal;
using ::llrintl;
using ::llroundl;
using ::log1pl;
using ::log2l;
using ::logbl;
using ::lrintl;
using ::lroundl;
using ::nanl;
using ::nearbyintl;
using ::nextafterl;
using ::nexttowardl;
using ::remainderl;
using ::remquol;
using ::rintl;
using ::roundl;
using ::scalblnl;
using ::scalbnl;
using ::tgammal;
using ::truncl;
#if _LIBCPP_STD_VER > 14
inline _LIBCPP_INLINE_VISIBILITY float hypot( float x, float y, float z ) { return sqrt(x*x + y*y + z*z); }
inline _LIBCPP_INLINE_VISIBILITY double hypot( double x, double y, double z ) { return sqrt(x*x + y*y + z*z); }
inline _LIBCPP_INLINE_VISIBILITY long double hypot( long double x, long double y, long double z ) { return sqrt(x*x + y*y + z*z); }
template <class _A1, class _A2, class _A3>
inline _LIBCPP_INLINE_VISIBILITY
typename _EnableIf
<
is_arithmetic<_A1>::value &&
is_arithmetic<_A2>::value &&
is_arithmetic<_A3>::value,
__promote<_A1, _A2, _A3>
>::type
hypot(_A1 __lcpp_x, _A2 __lcpp_y, _A3 __lcpp_z) _NOEXCEPT
{
typedef typename __promote<_A1, _A2, _A3>::type __result_type;
static_assert((!(is_same<_A1, __result_type>::value &&
is_same<_A2, __result_type>::value &&
is_same<_A3, __result_type>::value)), "");
return hypot((__result_type)__lcpp_x, (__result_type)__lcpp_y, (__result_type)__lcpp_z);
}
#endif
template <class _A1>
_LIBCPP_INLINE_VISIBILITY
_LIBCPP_CONSTEXPR typename enable_if<is_floating_point<_A1>::value, bool>::type
__libcpp_isnan_or_builtin(_A1 __lcpp_x) _NOEXCEPT
{
#if __has_builtin(__builtin_isnan)
return __builtin_isnan(__lcpp_x);
#else
return isnan(__lcpp_x);
#endif
}
template <class _A1>
_LIBCPP_INLINE_VISIBILITY
_LIBCPP_CONSTEXPR typename enable_if<!is_floating_point<_A1>::value, bool>::type
__libcpp_isnan_or_builtin(_A1 __lcpp_x) _NOEXCEPT
{
return isnan(__lcpp_x);
}
template <class _A1>
_LIBCPP_INLINE_VISIBILITY
_LIBCPP_CONSTEXPR typename enable_if<is_floating_point<_A1>::value, bool>::type
__libcpp_isinf_or_builtin(_A1 __lcpp_x) _NOEXCEPT
{
#if __has_builtin(__builtin_isinf)
return __builtin_isinf(__lcpp_x);
#else
return isinf(__lcpp_x);
#endif
}
template <class _A1>
_LIBCPP_INLINE_VISIBILITY
_LIBCPP_CONSTEXPR typename enable_if<!is_floating_point<_A1>::value, bool>::type
__libcpp_isinf_or_builtin(_A1 __lcpp_x) _NOEXCEPT
{
return isinf(__lcpp_x);
}
template <class _A1>
_LIBCPP_INLINE_VISIBILITY
_LIBCPP_CONSTEXPR typename enable_if<is_floating_point<_A1>::value, bool>::type
__libcpp_isfinite_or_builtin(_A1 __lcpp_x) _NOEXCEPT
{
#if __has_builtin(__builtin_isfinite)
return __builtin_isfinite(__lcpp_x);
#else
return isfinite(__lcpp_x);
#endif
}
template <class _A1>
_LIBCPP_INLINE_VISIBILITY
_LIBCPP_CONSTEXPR typename enable_if<!is_floating_point<_A1>::value, bool>::type
__libcpp_isfinite_or_builtin(_A1 __lcpp_x) _NOEXCEPT
{
return isfinite(__lcpp_x);
}
#if _LIBCPP_STD_VER > 17
template <typename _Fp>
constexpr
_Fp __lerp(_Fp __a, _Fp __b, _Fp __t) noexcept {
if ((__a <= 0 && __b >= 0) || (__a >= 0 && __b <= 0))
return __t * __b + (1 - __t) * __a;
if (__t == 1) return __b;
const _Fp __x = __a + __t * (__b - __a);
if (__t > 1 == __b > __a)
return __b < __x ? __x : __b;
else
return __x < __b ? __x : __b;
}
constexpr float
lerp(float __a, float __b, float __t) _NOEXCEPT { return __lerp(__a, __b, __t); }
constexpr double
lerp(double __a, double __b, double __t) _NOEXCEPT { return __lerp(__a, __b, __t); }
constexpr long double
lerp(long double __a, long double __b, long double __t) _NOEXCEPT { return __lerp(__a, __b, __t); }
#endif // _LIBCPP_STD_VER > 17
template <class _IntT, class _FloatT,
bool _FloatBigger = (numeric_limits<_FloatT>::digits > numeric_limits<_IntT>::digits),
int _Bits = (numeric_limits<_IntT>::digits - numeric_limits<_FloatT>::digits)>
_LIBCPP_INLINE_VISIBILITY
_LIBCPP_CONSTEXPR _IntT __max_representable_int_for_float() _NOEXCEPT {
static_assert(is_floating_point<_FloatT>::value, "must be a floating point type");
static_assert(is_integral<_IntT>::value, "must be an integral type");
static_assert(numeric_limits<_FloatT>::radix == 2, "FloatT has incorrect radix");
static_assert((_IsSame<_FloatT, float>::value || _IsSame<_FloatT, double>::value
|| _IsSame<_FloatT,long double>::value), "unsupported floating point type");
return _FloatBigger ? numeric_limits<_IntT>::max() : (numeric_limits<_IntT>::max() >> _Bits << _Bits);
}
// Convert a floating point number to the specified integral type after
// clamping to the integral types representable range.
//
// The behavior is undefined if `__r` is NaN.
template <class _IntT, class _RealT>
_LIBCPP_INLINE_VISIBILITY
_IntT __clamp_to_integral(_RealT __r) _NOEXCEPT {
using _Lim = std::numeric_limits<_IntT>;
const _IntT _MaxVal = std::__max_representable_int_for_float<_IntT, _RealT>();
if (__r >= ::nextafter(static_cast<_RealT>(_MaxVal), INFINITY)) {
return _Lim::max();
} else if (__r <= _Lim::lowest()) {
return _Lim::min();
}
return static_cast<_IntT>(__r);
}
_LIBCPP_END_NAMESPACE_STD
_LIBCPP_POP_MACROS
#endif // _LIBCPP_CMATH
| 16,933 | 674 | jart/cosmopolitan | false |
cosmopolitan/third_party/libcxx/hash.cc | // clang-format off
//===-------------------------- hash.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/__hash_table"
#include "third_party/libcxx/algorithm"
#include "third_party/libcxx/stdexcept"
#include "third_party/libcxx/type_traits"
#ifdef __clang__
#pragma clang diagnostic ignored "-Wtautological-constant-out-of-range-compare"
#endif
_LIBCPP_BEGIN_NAMESPACE_STD
namespace {
// handle all next_prime(i) for i in [1, 210), special case 0
const unsigned small_primes[] =
{
0,
2,
3,
5,
7,
11,
13,
17,
19,
23,
29,
31,
37,
41,
43,
47,
53,
59,
61,
67,
71,
73,
79,
83,
89,
97,
101,
103,
107,
109,
113,
127,
131,
137,
139,
149,
151,
157,
163,
167,
173,
179,
181,
191,
193,
197,
199,
211
};
// potential primes = 210*k + indices[i], k >= 1
// these numbers are not divisible by 2, 3, 5 or 7
// (or any integer 2 <= j <= 10 for that matter).
const unsigned indices[] =
{
1,
11,
13,
17,
19,
23,
29,
31,
37,
41,
43,
47,
53,
59,
61,
67,
71,
73,
79,
83,
89,
97,
101,
103,
107,
109,
113,
121,
127,
131,
137,
139,
143,
149,
151,
157,
163,
167,
169,
173,
179,
181,
187,
191,
193,
197,
199,
209
};
}
// Returns: If n == 0, returns 0. Else returns the lowest prime number that
// is greater than or equal to n.
//
// The algorithm creates a list of small primes, plus an open-ended list of
// potential primes. All prime numbers are potential prime numbers. However
// some potential prime numbers are not prime. In an ideal world, all potential
// prime numbers would be prime. Candidate prime numbers are chosen as the next
// highest potential prime. Then this number is tested for prime by dividing it
// by all potential prime numbers less than the sqrt of the candidate.
//
// This implementation defines potential primes as those numbers not divisible
// by 2, 3, 5, and 7. Other (common) implementations define potential primes
// as those not divisible by 2. A few other implementations define potential
// primes as those not divisible by 2 or 3. By raising the number of small
// primes which the potential prime is not divisible by, the set of potential
// primes more closely approximates the set of prime numbers. And thus there
// are fewer potential primes to search, and fewer potential primes to divide
// against.
template <size_t _Sz = sizeof(size_t)>
inline _LIBCPP_INLINE_VISIBILITY
typename enable_if<_Sz == 4, void>::type
__check_for_overflow(size_t N)
{
if (N > 0xFFFFFFFB)
__throw_overflow_error("__next_prime overflow");
}
template <size_t _Sz = sizeof(size_t)>
inline _LIBCPP_INLINE_VISIBILITY
typename enable_if<_Sz == 8, void>::type
__check_for_overflow(size_t N)
{
if (N > 0xFFFFFFFFFFFFFFC5ull)
__throw_overflow_error("__next_prime overflow");
}
size_t
__next_prime(size_t n)
{
const size_t L = 210;
const size_t N = sizeof(small_primes) / sizeof(small_primes[0]);
// If n is small enough, search in small_primes
if (n <= small_primes[N-1])
return *std::lower_bound(small_primes, small_primes + N, n);
// Else n > largest small_primes
// Check for overflow
__check_for_overflow(n);
// Start searching list of potential primes: L * k0 + indices[in]
const size_t M = sizeof(indices) / sizeof(indices[0]);
// Select first potential prime >= n
// Known a-priori n >= L
size_t k0 = n / L;
size_t in = static_cast<size_t>(std::lower_bound(indices, indices + M, n - k0 * L)
- indices);
n = L * k0 + indices[in];
while (true)
{
// Divide n by all primes or potential primes (i) until:
// 1. The division is even, so try next potential prime.
// 2. The i > sqrt(n), in which case n is prime.
// It is known a-priori that n is not divisible by 2, 3, 5 or 7,
// so don't test those (j == 5 -> divide by 11 first). And the
// potential primes start with 211, so don't test against the last
// small prime.
for (size_t j = 5; j < N - 1; ++j)
{
const std::size_t p = small_primes[j];
const std::size_t q = n / p;
if (q < p)
return n;
if (n == q * p)
goto next;
}
// n wasn't divisible by small primes, try potential primes
{
size_t i = 211;
while (true)
{
std::size_t q = n / i;
if (q < i)
return n;
if (n == q * i)
break;
i += 10;
q = n / i;
if (q < i)
return n;
if (n == q * i)
break;
i += 2;
q = n / i;
if (q < i)
return n;
if (n == q * i)
break;
i += 4;
q = n / i;
if (q < i)
return n;
if (n == q * i)
break;
i += 2;
q = n / i;
if (q < i)
return n;
if (n == q * i)
break;
i += 4;
q = n / i;
if (q < i)
return n;
if (n == q * i)
break;
i += 6;
q = n / i;
if (q < i)
return n;
if (n == q * i)
break;
i += 2;
q = n / i;
if (q < i)
return n;
if (n == q * i)
break;
i += 6;
q = n / i;
if (q < i)
return n;
if (n == q * i)
break;
i += 4;
q = n / i;
if (q < i)
return n;
if (n == q * i)
break;
i += 2;
q = n / i;
if (q < i)
return n;
if (n == q * i)
break;
i += 4;
q = n / i;
if (q < i)
return n;
if (n == q * i)
break;
i += 6;
q = n / i;
if (q < i)
return n;
if (n == q * i)
break;
i += 6;
q = n / i;
if (q < i)
return n;
if (n == q * i)
break;
i += 2;
q = n / i;
if (q < i)
return n;
if (n == q * i)
break;
i += 6;
q = n / i;
if (q < i)
return n;
if (n == q * i)
break;
i += 4;
q = n / i;
if (q < i)
return n;
if (n == q * i)
break;
i += 2;
q = n / i;
if (q < i)
return n;
if (n == q * i)
break;
i += 6;
q = n / i;
if (q < i)
return n;
if (n == q * i)
break;
i += 4;
q = n / i;
if (q < i)
return n;
if (n == q * i)
break;
i += 6;
q = n / i;
if (q < i)
return n;
if (n == q * i)
break;
i += 8;
q = n / i;
if (q < i)
return n;
if (n == q * i)
break;
i += 4;
q = n / i;
if (q < i)
return n;
if (n == q * i)
break;
i += 2;
q = n / i;
if (q < i)
return n;
if (n == q * i)
break;
i += 4;
q = n / i;
if (q < i)
return n;
if (n == q * i)
break;
i += 2;
q = n / i;
if (q < i)
return n;
if (n == q * i)
break;
i += 4;
q = n / i;
if (q < i)
return n;
if (n == q * i)
break;
i += 8;
q = n / i;
if (q < i)
return n;
if (n == q * i)
break;
i += 6;
q = n / i;
if (q < i)
return n;
if (n == q * i)
break;
i += 4;
q = n / i;
if (q < i)
return n;
if (n == q * i)
break;
i += 6;
q = n / i;
if (q < i)
return n;
if (n == q * i)
break;
i += 2;
q = n / i;
if (q < i)
return n;
if (n == q * i)
break;
i += 4;
q = n / i;
if (q < i)
return n;
if (n == q * i)
break;
i += 6;
q = n / i;
if (q < i)
return n;
if (n == q * i)
break;
i += 2;
q = n / i;
if (q < i)
return n;
if (n == q * i)
break;
i += 6;
q = n / i;
if (q < i)
return n;
if (n == q * i)
break;
i += 6;
q = n / i;
if (q < i)
return n;
if (n == q * i)
break;
i += 4;
q = n / i;
if (q < i)
return n;
if (n == q * i)
break;
i += 2;
q = n / i;
if (q < i)
return n;
if (n == q * i)
break;
i += 4;
q = n / i;
if (q < i)
return n;
if (n == q * i)
break;
i += 6;
q = n / i;
if (q < i)
return n;
if (n == q * i)
break;
i += 2;
q = n / i;
if (q < i)
return n;
if (n == q * i)
break;
i += 6;
q = n / i;
if (q < i)
return n;
if (n == q * i)
break;
i += 4;
q = n / i;
if (q < i)
return n;
if (n == q * i)
break;
i += 2;
q = n / i;
if (q < i)
return n;
if (n == q * i)
break;
i += 4;
q = n / i;
if (q < i)
return n;
if (n == q * i)
break;
i += 2;
q = n / i;
if (q < i)
return n;
if (n == q * i)
break;
i += 10;
q = n / i;
if (q < i)
return n;
if (n == q * i)
break;
// This will loop i to the next "plane" of potential primes
i += 2;
}
}
next:
// n is not prime. Increment n to next potential prime.
if (++in == M)
{
++k0;
in = 0;
}
n = L * k0 + indices[in];
}
}
_LIBCPP_END_NAMESPACE_STD
| 13,452 | 563 | jart/cosmopolitan | false |
cosmopolitan/third_party/libcxx/ios.cc | // clang-format off
//===-------------------------- ios.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/ios"
#include "third_party/libcxx/__locale"
#include "third_party/libcxx/algorithm"
#include "third_party/libcxx/include/config_elast.hh"
#include "third_party/libcxx/istream"
#include "third_party/libcxx/limits"
#include "third_party/libcxx/memory"
#include "third_party/libcxx/new"
#include "third_party/libcxx/streambuf"
#include "third_party/libcxx/string"
#include "third_party/libcxx/__undef_macros"
_LIBCPP_BEGIN_NAMESPACE_STD
template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS basic_ios<char>;
template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS basic_ios<wchar_t>;
template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS basic_streambuf<char>;
template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS basic_streambuf<wchar_t>;
template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS basic_istream<char>;
template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS basic_istream<wchar_t>;
template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS basic_ostream<char>;
template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS basic_ostream<wchar_t>;
template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS basic_iostream<char>;
class _LIBCPP_HIDDEN __iostream_category
: public __do_message
{
public:
virtual const char* name() const _NOEXCEPT;
virtual string message(int ev) const;
};
const char*
__iostream_category::name() const _NOEXCEPT
{
return "iostream";
}
string
__iostream_category::message(int ev) const
{
if (ev != static_cast<int>(io_errc::stream)
#ifdef _LIBCPP_ELAST
&& ev <= _LIBCPP_ELAST
#endif // _LIBCPP_ELAST
)
return __do_message::message(ev);
return string("unspecified iostream_category error");
}
const error_category&
iostream_category() _NOEXCEPT
{
static __iostream_category s;
return s;
}
// ios_base::failure
ios_base::failure::failure(const string& msg, const error_code& ec)
: system_error(ec, msg)
{
}
ios_base::failure::failure(const char* msg, const error_code& ec)
: system_error(ec, msg)
{
}
ios_base::failure::~failure() throw()
{
}
// ios_base locale
const ios_base::fmtflags ios_base::boolalpha;
const ios_base::fmtflags ios_base::dec;
const ios_base::fmtflags ios_base::fixed;
const ios_base::fmtflags ios_base::hex;
const ios_base::fmtflags ios_base::internal;
const ios_base::fmtflags ios_base::left;
const ios_base::fmtflags ios_base::oct;
const ios_base::fmtflags ios_base::right;
const ios_base::fmtflags ios_base::scientific;
const ios_base::fmtflags ios_base::showbase;
const ios_base::fmtflags ios_base::showpoint;
const ios_base::fmtflags ios_base::showpos;
const ios_base::fmtflags ios_base::skipws;
const ios_base::fmtflags ios_base::unitbuf;
const ios_base::fmtflags ios_base::uppercase;
const ios_base::fmtflags ios_base::adjustfield;
const ios_base::fmtflags ios_base::basefield;
const ios_base::fmtflags ios_base::floatfield;
const ios_base::iostate ios_base::badbit;
const ios_base::iostate ios_base::eofbit;
const ios_base::iostate ios_base::failbit;
const ios_base::iostate ios_base::goodbit;
const ios_base::openmode ios_base::app;
const ios_base::openmode ios_base::ate;
const ios_base::openmode ios_base::binary;
const ios_base::openmode ios_base::in;
const ios_base::openmode ios_base::out;
const ios_base::openmode ios_base::trunc;
void
ios_base::__call_callbacks(event ev)
{
for (size_t i = __event_size_; i;)
{
--i;
__fn_[i](ev, *this, __index_[i]);
}
}
// locale
locale
ios_base::imbue(const locale& newloc)
{
static_assert(sizeof(locale) == sizeof(__loc_), "");
locale& loc_storage = *reinterpret_cast<locale*>(&__loc_);
locale oldloc = loc_storage;
loc_storage = newloc;
__call_callbacks(imbue_event);
return oldloc;
}
locale
ios_base::getloc() const
{
const locale& loc_storage = *reinterpret_cast<const locale*>(&__loc_);
return loc_storage;
}
// xalloc
#if defined(_LIBCPP_HAS_C_ATOMIC_IMP) && !defined(_LIBCPP_HAS_NO_THREADS)
atomic<int> ios_base::__xindex_ = ATOMIC_VAR_INIT(0);
#else
int ios_base::__xindex_ = 0;
#endif
template <typename _Tp>
static size_t __ios_new_cap(size_t __req_size, size_t __current_cap)
{ // Precondition: __req_size > __current_cap
const size_t mx = std::numeric_limits<size_t>::max() / sizeof(_Tp);
if (__req_size < mx/2)
return _VSTD::max(2 * __current_cap, __req_size);
else
return mx;
}
int
ios_base::xalloc()
{
return __xindex_++;
}
long&
ios_base::iword(int index)
{
size_t req_size = static_cast<size_t>(index)+1;
if (req_size > __iarray_cap_)
{
size_t newcap = __ios_new_cap<long>(req_size, __iarray_cap_);
long* iarray = static_cast<long*>(realloc(__iarray_, newcap * sizeof(long)));
if (iarray == 0)
{
setstate(badbit);
static long error;
error = 0;
return error;
}
__iarray_ = iarray;
for (long* p = __iarray_ + __iarray_size_; p < __iarray_ + newcap; ++p)
*p = 0;
__iarray_cap_ = newcap;
}
__iarray_size_ = max<size_t>(__iarray_size_, req_size);
return __iarray_[index];
}
void*&
ios_base::pword(int index)
{
size_t req_size = static_cast<size_t>(index)+1;
if (req_size > __parray_cap_)
{
size_t newcap = __ios_new_cap<void *>(req_size, __iarray_cap_);
void** parray = static_cast<void**>(realloc(__parray_, newcap * sizeof(void *)));
if (parray == 0)
{
setstate(badbit);
static void* error;
error = 0;
return error;
}
__parray_ = parray;
for (void** p = __parray_ + __parray_size_; p < __parray_ + newcap; ++p)
*p = 0;
__parray_cap_ = newcap;
}
__parray_size_ = max<size_t>(__parray_size_, req_size);
return __parray_[index];
}
// register_callback
void
ios_base::register_callback(event_callback fn, int index)
{
size_t req_size = __event_size_ + 1;
if (req_size > __event_cap_)
{
size_t newcap = __ios_new_cap<event_callback>(req_size, __event_cap_);
event_callback* fns = static_cast<event_callback*>(realloc(__fn_, newcap * sizeof(event_callback)));
if (fns == 0)
setstate(badbit);
__fn_ = fns;
int* indxs = static_cast<int *>(realloc(__index_, newcap * sizeof(int)));
if (indxs == 0)
setstate(badbit);
__index_ = indxs;
__event_cap_ = newcap;
}
__fn_[__event_size_] = fn;
__index_[__event_size_] = index;
++__event_size_;
}
ios_base::~ios_base()
{
__call_callbacks(erase_event);
locale& loc_storage = *reinterpret_cast<locale*>(&__loc_);
loc_storage.~locale();
free(__fn_);
free(__index_);
free(__iarray_);
free(__parray_);
}
// iostate
void
ios_base::clear(iostate state)
{
if (__rdbuf_)
__rdstate_ = state;
else
__rdstate_ = state | badbit;
if (((state | (__rdbuf_ ? goodbit : badbit)) & __exceptions_) != 0)
__throw_failure("ios_base::clear");
}
// init
void
ios_base::init(void* sb)
{
__rdbuf_ = sb;
__rdstate_ = __rdbuf_ ? goodbit : badbit;
__exceptions_ = goodbit;
__fmtflags_ = skipws | dec;
__width_ = 0;
__precision_ = 6;
__fn_ = 0;
__index_ = 0;
__event_size_ = 0;
__event_cap_ = 0;
__iarray_ = 0;
__iarray_size_ = 0;
__iarray_cap_ = 0;
__parray_ = 0;
__parray_size_ = 0;
__parray_cap_ = 0;
::new(&__loc_) locale;
}
void
ios_base::copyfmt(const ios_base& rhs)
{
// If we can't acquire the needed resources, throw bad_alloc (can't set badbit)
// Don't alter *this until all needed resources are acquired
unique_ptr<event_callback, void (*)(void*)> new_callbacks(0, free);
unique_ptr<int, void (*)(void*)> new_ints(0, free);
unique_ptr<long, void (*)(void*)> new_longs(0, free);
unique_ptr<void*, void (*)(void*)> new_pointers(0, free);
if (__event_cap_ < rhs.__event_size_)
{
size_t newesize = sizeof(event_callback) * rhs.__event_size_;
new_callbacks.reset(static_cast<event_callback*>(malloc(newesize)));
if (!new_callbacks)
__throw_bad_alloc();
size_t newisize = sizeof(int) * rhs.__event_size_;
new_ints.reset(static_cast<int *>(malloc(newisize)));
if (!new_ints)
__throw_bad_alloc();
}
if (__iarray_cap_ < rhs.__iarray_size_)
{
size_t newsize = sizeof(long) * rhs.__iarray_size_;
new_longs.reset(static_cast<long*>(malloc(newsize)));
if (!new_longs)
__throw_bad_alloc();
}
if (__parray_cap_ < rhs.__parray_size_)
{
size_t newsize = sizeof(void*) * rhs.__parray_size_;
new_pointers.reset(static_cast<void**>(malloc(newsize)));
if (!new_pointers)
__throw_bad_alloc();
}
// Got everything we need. Copy everything but __rdstate_, __rdbuf_ and __exceptions_
__fmtflags_ = rhs.__fmtflags_;
__precision_ = rhs.__precision_;
__width_ = rhs.__width_;
locale& lhs_loc = *reinterpret_cast<locale*>(&__loc_);
const locale& rhs_loc = *reinterpret_cast<const locale*>(&rhs.__loc_);
lhs_loc = rhs_loc;
if (__event_cap_ < rhs.__event_size_)
{
free(__fn_);
__fn_ = new_callbacks.release();
free(__index_);
__index_ = new_ints.release();
__event_cap_ = rhs.__event_size_;
}
for (__event_size_ = 0; __event_size_ < rhs.__event_size_; ++__event_size_)
{
__fn_[__event_size_] = rhs.__fn_[__event_size_];
__index_[__event_size_] = rhs.__index_[__event_size_];
}
if (__iarray_cap_ < rhs.__iarray_size_)
{
free(__iarray_);
__iarray_ = new_longs.release();
__iarray_cap_ = rhs.__iarray_size_;
}
for (__iarray_size_ = 0; __iarray_size_ < rhs.__iarray_size_; ++__iarray_size_)
__iarray_[__iarray_size_] = rhs.__iarray_[__iarray_size_];
if (__parray_cap_ < rhs.__parray_size_)
{
free(__parray_);
__parray_ = new_pointers.release();
__parray_cap_ = rhs.__parray_size_;
}
for (__parray_size_ = 0; __parray_size_ < rhs.__parray_size_; ++__parray_size_)
__parray_[__parray_size_] = rhs.__parray_[__parray_size_];
}
void
ios_base::move(ios_base& rhs)
{
// *this is uninitialized
__fmtflags_ = rhs.__fmtflags_;
__precision_ = rhs.__precision_;
__width_ = rhs.__width_;
__rdstate_ = rhs.__rdstate_;
__exceptions_ = rhs.__exceptions_;
__rdbuf_ = 0;
locale& rhs_loc = *reinterpret_cast<locale*>(&rhs.__loc_);
::new(&__loc_) locale(rhs_loc);
__fn_ = rhs.__fn_;
rhs.__fn_ = 0;
__index_ = rhs.__index_;
rhs.__index_ = 0;
__event_size_ = rhs.__event_size_;
rhs.__event_size_ = 0;
__event_cap_ = rhs.__event_cap_;
rhs.__event_cap_ = 0;
__iarray_ = rhs.__iarray_;
rhs.__iarray_ = 0;
__iarray_size_ = rhs.__iarray_size_;
rhs.__iarray_size_ = 0;
__iarray_cap_ = rhs.__iarray_cap_;
rhs.__iarray_cap_ = 0;
__parray_ = rhs.__parray_;
rhs.__parray_ = 0;
__parray_size_ = rhs.__parray_size_;
rhs.__parray_size_ = 0;
__parray_cap_ = rhs.__parray_cap_;
rhs.__parray_cap_ = 0;
}
void
ios_base::swap(ios_base& rhs) _NOEXCEPT
{
_VSTD::swap(__fmtflags_, rhs.__fmtflags_);
_VSTD::swap(__precision_, rhs.__precision_);
_VSTD::swap(__width_, rhs.__width_);
_VSTD::swap(__rdstate_, rhs.__rdstate_);
_VSTD::swap(__exceptions_, rhs.__exceptions_);
locale& lhs_loc = *reinterpret_cast<locale*>(&__loc_);
locale& rhs_loc = *reinterpret_cast<locale*>(&rhs.__loc_);
_VSTD::swap(lhs_loc, rhs_loc);
_VSTD::swap(__fn_, rhs.__fn_);
_VSTD::swap(__index_, rhs.__index_);
_VSTD::swap(__event_size_, rhs.__event_size_);
_VSTD::swap(__event_cap_, rhs.__event_cap_);
_VSTD::swap(__iarray_, rhs.__iarray_);
_VSTD::swap(__iarray_size_, rhs.__iarray_size_);
_VSTD::swap(__iarray_cap_, rhs.__iarray_cap_);
_VSTD::swap(__parray_, rhs.__parray_);
_VSTD::swap(__parray_size_, rhs.__parray_size_);
_VSTD::swap(__parray_cap_, rhs.__parray_cap_);
}
void
ios_base::__set_badbit_and_consider_rethrow()
{
__rdstate_ |= badbit;
#ifndef _LIBCPP_NO_EXCEPTIONS
if (__exceptions_ & badbit)
throw;
#endif // _LIBCPP_NO_EXCEPTIONS
}
void
ios_base::__set_failbit_and_consider_rethrow()
{
__rdstate_ |= failbit;
#ifndef _LIBCPP_NO_EXCEPTIONS
if (__exceptions_ & failbit)
throw;
#endif // _LIBCPP_NO_EXCEPTIONS
}
bool
ios_base::sync_with_stdio(bool sync)
{
static bool previous_state = true;
bool r = previous_state;
previous_state = sync;
return r;
}
_LIBCPP_END_NAMESPACE_STD
| 13,151 | 457 | jart/cosmopolitan | false |
cosmopolitan/third_party/libcxx/system_error.cc | //===---------------------- system_error.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/system_error"
#include "third_party/libcxx/config_elast.h"
#include "third_party/libcxx/cerrno"
#include "third_party/libcxx/cstring"
#include "third_party/libcxx/cstdio"
#include "third_party/libcxx/cstdlib"
#include "third_party/libcxx/string"
#include "third_party/libcxx/string.h"
#include "third_party/libcxx/__debug"
_LIBCPP_BEGIN_NAMESPACE_STD
// class error_category
#if defined( \
_LIBCPP_DEPRECATED_ABI_LEGACY_LIBRARY_DEFINITIONS_FOR_INLINE_FUNCTIONS)
error_category::error_category() _NOEXCEPT {}
#endif
error_category::~error_category() _NOEXCEPT {}
error_condition
error_category::default_error_condition(int ev) const _NOEXCEPT {
return error_condition(ev, *this);
}
bool error_category::equivalent(
int code, const error_condition& condition) const _NOEXCEPT {
return default_error_condition(code) == condition;
}
bool error_category::equivalent(const error_code& code,
int condition) const _NOEXCEPT {
return *this == code.category() && code.value() == condition;
}
#if !defined(_LIBCPP_HAS_NO_THREADS)
namespace {
// GLIBC also uses 1024 as the maximum buffer size internally.
constexpr size_t strerror_buff_size = 1024;
string do_strerror_r(int ev);
#if defined(_LIBCPP_MSVCRT_LIKE)
string do_strerror_r(int ev) {
char buffer[strerror_buff_size];
if (::strerror_s(buffer, strerror_buff_size, ev) == 0)
return string(buffer);
std::snprintf(buffer, strerror_buff_size, "unknown error %d", ev);
return string(buffer);
}
#else
// Only one of the two following functions will be used, depending on
// the return type of strerror_r:
// For the GNU variant, a char* return value:
__attribute__((unused)) const char*
handle_strerror_r_return(char* strerror_return, char* buffer) {
// GNU always returns a string pointer in its return value. The
// string might point to either the input buffer, or a static
// buffer, but we don't care which.
return strerror_return;
}
// For the POSIX variant: an int return value.
__attribute__((unused)) const char*
handle_strerror_r_return(int strerror_return, char* buffer) {
// The POSIX variant either:
// - fills in the provided buffer and returns 0
// - returns a positive error value, or
// - returns -1 and fills in errno with an error value.
if (strerror_return == 0)
return buffer;
// Only handle EINVAL. Other errors abort.
int new_errno = strerror_return == -1 ? errno : strerror_return;
if (new_errno == EINVAL)
return "";
_LIBCPP_ASSERT(new_errno == ERANGE, "unexpected error from ::strerror_r");
// FIXME maybe? 'strerror_buff_size' is likely to exceed the
// maximum error size so ERANGE shouldn't be returned.
std::abort();
}
// This function handles both GNU and POSIX variants, dispatching to
// one of the two above functions.
string do_strerror_r(int ev) {
char buffer[strerror_buff_size];
// Preserve errno around the call. (The C++ standard requires that
// system_error functions not modify errno).
const int old_errno = errno;
const char* error_message = handle_strerror_r_return(
::strerror_r(ev, buffer, strerror_buff_size), buffer);
// If we didn't get any message, print one now.
if (!error_message[0]) {
std::snprintf(buffer, strerror_buff_size, "Unknown error %d", ev);
error_message = buffer;
}
errno = old_errno;
return string(error_message);
}
#endif
} // end namespace
#endif
string __do_message::message(int ev) const {
#if defined(_LIBCPP_HAS_NO_THREADS)
return string(::strerror(ev));
#else
return do_strerror_r(ev);
#endif
}
class _LIBCPP_HIDDEN __generic_error_category : public __do_message {
public:
virtual const char* name() const _NOEXCEPT;
virtual string message(int ev) const;
};
const char* __generic_error_category::name() const _NOEXCEPT {
return "generic";
}
string __generic_error_category::message(int ev) const {
#ifdef _LIBCPP_ELAST
if (ev > _LIBCPP_ELAST)
return string("unspecified generic_category error");
#endif // _LIBCPP_ELAST
return __do_message::message(ev);
}
const error_category& generic_category() _NOEXCEPT {
static __generic_error_category s;
return s;
}
class _LIBCPP_HIDDEN __system_error_category : public __do_message {
public:
virtual const char* name() const _NOEXCEPT;
virtual string message(int ev) const;
virtual error_condition default_error_condition(int ev) const _NOEXCEPT;
};
const char* __system_error_category::name() const _NOEXCEPT { return "system"; }
string __system_error_category::message(int ev) const {
#ifdef _LIBCPP_ELAST
if (ev > _LIBCPP_ELAST)
return string("unspecified system_category error");
#endif // _LIBCPP_ELAST
return __do_message::message(ev);
}
error_condition
__system_error_category::default_error_condition(int ev) const _NOEXCEPT {
#ifdef _LIBCPP_ELAST
if (ev > _LIBCPP_ELAST)
return error_condition(ev, system_category());
#endif // _LIBCPP_ELAST
return error_condition(ev, generic_category());
}
const error_category& system_category() _NOEXCEPT {
static __system_error_category s;
return s;
}
// error_condition
string error_condition::message() const { return __cat_->message(__val_); }
// error_code
string error_code::message() const { return __cat_->message(__val_); }
// system_error
string system_error::__init(const error_code& ec, string what_arg) {
if (ec) {
if (!what_arg.empty())
what_arg += ": ";
what_arg += ec.message();
}
return what_arg;
}
system_error::system_error(error_code ec, const string& what_arg)
: runtime_error(__init(ec, what_arg)), __ec_(ec) {}
system_error::system_error(error_code ec, const char* what_arg)
: runtime_error(__init(ec, what_arg)), __ec_(ec) {}
system_error::system_error(error_code ec)
: runtime_error(__init(ec, "")), __ec_(ec) {}
system_error::system_error(int ev, const error_category& ecat,
const string& what_arg)
: runtime_error(__init(error_code(ev, ecat), what_arg)),
__ec_(error_code(ev, ecat)) {}
system_error::system_error(int ev, const error_category& ecat,
const char* what_arg)
: runtime_error(__init(error_code(ev, ecat), what_arg)),
__ec_(error_code(ev, ecat)) {}
system_error::system_error(int ev, const error_category& ecat)
: runtime_error(__init(error_code(ev, ecat), "")),
__ec_(error_code(ev, ecat)) {}
system_error::~system_error() _NOEXCEPT {}
void __throw_system_error(int ev, const char* what_arg) {
#ifndef _LIBCPP_NO_EXCEPTIONS
throw system_error(error_code(ev, system_category()), what_arg);
#else
(void)ev;
(void)what_arg;
_VSTD::abort();
#endif
}
_LIBCPP_END_NAMESPACE_STD
| 7,165 | 237 | jart/cosmopolitan | false |
cosmopolitan/third_party/libcxx/deque | // -*- C++ -*-
//===---------------------------- deque -----------------------------------===//
//
// 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_DEQUE
#define _LIBCPP_DEQUE
#include "third_party/libcxx/__config"
#include "third_party/libcxx/__split_buffer"
#include "third_party/libcxx/type_traits"
#include "third_party/libcxx/initializer_list"
#include "third_party/libcxx/iterator"
#include "third_party/libcxx/algorithm"
#include "third_party/libcxx/stdexcept"
#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
/*
deque synopsis
namespace std
{
template <class T, class Allocator = allocator<T> >
class deque
{
public:
// types:
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;
// construct/copy/destroy:
deque() noexcept(is_nothrow_default_constructible<allocator_type>::value);
explicit deque(const allocator_type& a);
explicit deque(size_type n);
explicit deque(size_type n, const allocator_type& a); // C++14
deque(size_type n, const value_type& v);
deque(size_type n, const value_type& v, const allocator_type& a);
template <class InputIterator>
deque(InputIterator f, InputIterator l);
template <class InputIterator>
deque(InputIterator f, InputIterator l, const allocator_type& a);
deque(const deque& c);
deque(deque&& c)
noexcept(is_nothrow_move_constructible<allocator_type>::value);
deque(initializer_list<value_type> il, const Allocator& a = allocator_type());
deque(const deque& c, const allocator_type& a);
deque(deque&& c, const allocator_type& a);
~deque();
deque& operator=(const deque& c);
deque& operator=(deque&& c)
noexcept(
allocator_type::propagate_on_container_move_assignment::value &&
is_nothrow_move_assignable<allocator_type>::value);
deque& operator=(initializer_list<value_type> il);
template <class InputIterator>
void assign(InputIterator f, InputIterator l);
void assign(size_type n, const value_type& v);
void assign(initializer_list<value_type> il);
allocator_type get_allocator() const noexcept;
// 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:
size_type size() const noexcept;
size_type max_size() const noexcept;
void resize(size_type n);
void resize(size_type n, const value_type& v);
void shrink_to_fit();
bool empty() const noexcept;
// element access:
reference operator[](size_type i);
const_reference operator[](size_type i) const;
reference at(size_type i);
const_reference at(size_type i) const;
reference front();
const_reference front() const;
reference back();
const_reference back() const;
// modifiers:
void push_front(const value_type& v);
void push_front(value_type&& v);
void push_back(const value_type& v);
void push_back(value_type&& v);
template <class... Args> reference emplace_front(Args&&... args); // reference in C++17
template <class... Args> reference emplace_back(Args&&... args); // reference in C++17
template <class... Args> iterator emplace(const_iterator p, Args&&... args);
iterator insert(const_iterator p, const value_type& v);
iterator insert(const_iterator p, value_type&& v);
iterator insert(const_iterator p, size_type n, const value_type& v);
template <class InputIterator>
iterator insert(const_iterator p, InputIterator f, InputIterator l);
iterator insert(const_iterator p, initializer_list<value_type> il);
void pop_front();
void pop_back();
iterator erase(const_iterator p);
iterator erase(const_iterator f, const_iterator l);
void swap(deque& c)
noexcept(allocator_traits<allocator_type>::is_always_equal::value); // C++17
void clear() noexcept;
};
template <class InputIterator, class Allocator = allocator<typename iterator_traits<InputIterator>::value_type>>
deque(InputIterator, InputIterator, Allocator = Allocator())
-> deque<typename iterator_traits<InputIterator>::value_type, Allocator>;
template <class T, class Allocator>
bool operator==(const deque<T,Allocator>& x, const deque<T,Allocator>& y);
template <class T, class Allocator>
bool operator< (const deque<T,Allocator>& x, const deque<T,Allocator>& y);
template <class T, class Allocator>
bool operator!=(const deque<T,Allocator>& x, const deque<T,Allocator>& y);
template <class T, class Allocator>
bool operator> (const deque<T,Allocator>& x, const deque<T,Allocator>& y);
template <class T, class Allocator>
bool operator>=(const deque<T,Allocator>& x, const deque<T,Allocator>& y);
template <class T, class Allocator>
bool operator<=(const deque<T,Allocator>& x, const deque<T,Allocator>& y);
// specialized algorithms:
template <class T, class Allocator>
void swap(deque<T,Allocator>& x, deque<T,Allocator>& y)
noexcept(noexcept(x.swap(y)));
template <class T, class Allocator, class U>
void erase(deque<T, Allocator>& c, const U& value); // C++20
template <class T, class Allocator, class Predicate>
void erase_if(deque<T, Allocator>& c, Predicate pred); // C++20
} // std
*/
template <class _Tp, class _Allocator> class __deque_base;
template <class _Tp, class _Allocator = allocator<_Tp> > class _LIBCPP_TEMPLATE_VIS deque;
template <class _ValueType, class _Pointer, class _Reference, class _MapPointer,
class _DiffType, _DiffType _BlockSize>
class _LIBCPP_TEMPLATE_VIS __deque_iterator;
template <class _RAIter,
class _V2, class _P2, class _R2, class _M2, class _D2, _D2 _B2>
__deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2>
copy(_RAIter __f,
_RAIter __l,
__deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r,
typename enable_if<__is_random_access_iterator<_RAIter>::value>::type* = 0);
template <class _V1, class _P1, class _R1, class _M1, class _D1, _D1 _B1,
class _OutputIterator>
_OutputIterator
copy(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f,
__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l,
_OutputIterator __r);
template <class _V1, class _P1, class _R1, class _M1, class _D1, _D1 _B1,
class _V2, class _P2, class _R2, class _M2, class _D2, _D2 _B2>
__deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2>
copy(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f,
__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l,
__deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r);
template <class _RAIter,
class _V2, class _P2, class _R2, class _M2, class _D2, _D2 _B2>
__deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2>
copy_backward(_RAIter __f,
_RAIter __l,
__deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r,
typename enable_if<__is_random_access_iterator<_RAIter>::value>::type* = 0);
template <class _V1, class _P1, class _R1, class _M1, class _D1, _D1 _B1,
class _OutputIterator>
_OutputIterator
copy_backward(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f,
__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l,
_OutputIterator __r);
template <class _V1, class _P1, class _R1, class _M1, class _D1, _D1 _B1,
class _V2, class _P2, class _R2, class _M2, class _D2, _D2 _B2>
__deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2>
copy_backward(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f,
__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l,
__deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r);
template <class _RAIter,
class _V2, class _P2, class _R2, class _M2, class _D2, _D2 _B2>
__deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2>
move(_RAIter __f,
_RAIter __l,
__deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r,
typename enable_if<__is_random_access_iterator<_RAIter>::value>::type* = 0);
template <class _V1, class _P1, class _R1, class _M1, class _D1, _D1 _B1,
class _OutputIterator>
_OutputIterator
move(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f,
__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l,
_OutputIterator __r);
template <class _V1, class _P1, class _R1, class _M1, class _D1, _D1 _B1,
class _V2, class _P2, class _R2, class _M2, class _D2, _D2 _B2>
__deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2>
move(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f,
__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l,
__deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r);
template <class _RAIter,
class _V2, class _P2, class _R2, class _M2, class _D2, _D2 _B2>
__deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2>
move_backward(_RAIter __f,
_RAIter __l,
__deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r,
typename enable_if<__is_random_access_iterator<_RAIter>::value>::type* = 0);
template <class _V1, class _P1, class _R1, class _M1, class _D1, _D1 _B1,
class _OutputIterator>
_OutputIterator
move_backward(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f,
__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l,
_OutputIterator __r);
template <class _V1, class _P1, class _R1, class _M1, class _D1, _D1 _B1,
class _V2, class _P2, class _R2, class _M2, class _D2, _D2 _B2>
__deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2>
move_backward(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f,
__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l,
__deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r);
template <class _ValueType, class _DiffType>
struct __deque_block_size {
static const _DiffType value = sizeof(_ValueType) < 256 ? 4096 / sizeof(_ValueType) : 16;
};
template <class _ValueType, class _Pointer, class _Reference, class _MapPointer,
class _DiffType, _DiffType _BS =
#ifdef _LIBCPP_ABI_INCOMPLETE_TYPES_IN_DEQUE
// Keep template parameter to avoid changing all template declarations thoughout
// this file.
0
#else
__deque_block_size<_ValueType, _DiffType>::value
#endif
>
class _LIBCPP_TEMPLATE_VIS __deque_iterator
{
typedef _MapPointer __map_iterator;
public:
typedef _Pointer pointer;
typedef _DiffType difference_type;
private:
__map_iterator __m_iter_;
pointer __ptr_;
static const difference_type __block_size;
public:
typedef _ValueType value_type;
typedef random_access_iterator_tag iterator_category;
typedef _Reference reference;
_LIBCPP_INLINE_VISIBILITY __deque_iterator() _NOEXCEPT
#if _LIBCPP_STD_VER > 11
: __m_iter_(nullptr), __ptr_(nullptr)
#endif
{}
template <class _Pp, class _Rp, class _MP>
_LIBCPP_INLINE_VISIBILITY
__deque_iterator(const __deque_iterator<value_type, _Pp, _Rp, _MP, difference_type, _BS>& __it,
typename enable_if<is_convertible<_Pp, pointer>::value>::type* = 0) _NOEXCEPT
: __m_iter_(__it.__m_iter_), __ptr_(__it.__ptr_) {}
_LIBCPP_INLINE_VISIBILITY reference operator*() const {return *__ptr_;}
_LIBCPP_INLINE_VISIBILITY pointer operator->() const {return __ptr_;}
_LIBCPP_INLINE_VISIBILITY __deque_iterator& operator++()
{
if (++__ptr_ - *__m_iter_ == __block_size)
{
++__m_iter_;
__ptr_ = *__m_iter_;
}
return *this;
}
_LIBCPP_INLINE_VISIBILITY __deque_iterator operator++(int)
{
__deque_iterator __tmp = *this;
++(*this);
return __tmp;
}
_LIBCPP_INLINE_VISIBILITY __deque_iterator& operator--()
{
if (__ptr_ == *__m_iter_)
{
--__m_iter_;
__ptr_ = *__m_iter_ + __block_size;
}
--__ptr_;
return *this;
}
_LIBCPP_INLINE_VISIBILITY __deque_iterator operator--(int)
{
__deque_iterator __tmp = *this;
--(*this);
return __tmp;
}
_LIBCPP_INLINE_VISIBILITY __deque_iterator& operator+=(difference_type __n)
{
if (__n != 0)
{
__n += __ptr_ - *__m_iter_;
if (__n > 0)
{
__m_iter_ += __n / __block_size;
__ptr_ = *__m_iter_ + __n % __block_size;
}
else // (__n < 0)
{
difference_type __z = __block_size - 1 - __n;
__m_iter_ -= __z / __block_size;
__ptr_ = *__m_iter_ + (__block_size - 1 - __z % __block_size);
}
}
return *this;
}
_LIBCPP_INLINE_VISIBILITY __deque_iterator& operator-=(difference_type __n)
{
return *this += -__n;
}
_LIBCPP_INLINE_VISIBILITY __deque_iterator operator+(difference_type __n) const
{
__deque_iterator __t(*this);
__t += __n;
return __t;
}
_LIBCPP_INLINE_VISIBILITY __deque_iterator operator-(difference_type __n) const
{
__deque_iterator __t(*this);
__t -= __n;
return __t;
}
_LIBCPP_INLINE_VISIBILITY
friend __deque_iterator operator+(difference_type __n, const __deque_iterator& __it)
{return __it + __n;}
_LIBCPP_INLINE_VISIBILITY
friend difference_type operator-(const __deque_iterator& __x, const __deque_iterator& __y)
{
if (__x != __y)
return (__x.__m_iter_ - __y.__m_iter_) * __block_size
+ (__x.__ptr_ - *__x.__m_iter_)
- (__y.__ptr_ - *__y.__m_iter_);
return 0;
}
_LIBCPP_INLINE_VISIBILITY reference operator[](difference_type __n) const
{return *(*this + __n);}
_LIBCPP_INLINE_VISIBILITY friend
bool operator==(const __deque_iterator& __x, const __deque_iterator& __y)
{return __x.__ptr_ == __y.__ptr_;}
_LIBCPP_INLINE_VISIBILITY friend
bool operator!=(const __deque_iterator& __x, const __deque_iterator& __y)
{return !(__x == __y);}
_LIBCPP_INLINE_VISIBILITY friend
bool operator<(const __deque_iterator& __x, const __deque_iterator& __y)
{return __x.__m_iter_ < __y.__m_iter_ ||
(__x.__m_iter_ == __y.__m_iter_ && __x.__ptr_ < __y.__ptr_);}
_LIBCPP_INLINE_VISIBILITY friend
bool operator>(const __deque_iterator& __x, const __deque_iterator& __y)
{return __y < __x;}
_LIBCPP_INLINE_VISIBILITY friend
bool operator<=(const __deque_iterator& __x, const __deque_iterator& __y)
{return !(__y < __x);}
_LIBCPP_INLINE_VISIBILITY friend
bool operator>=(const __deque_iterator& __x, const __deque_iterator& __y)
{return !(__x < __y);}
private:
_LIBCPP_INLINE_VISIBILITY __deque_iterator(__map_iterator __m, pointer __p) _NOEXCEPT
: __m_iter_(__m), __ptr_(__p) {}
template <class _Tp, class _Ap> friend class __deque_base;
template <class _Tp, class _Ap> friend class _LIBCPP_TEMPLATE_VIS deque;
template <class _Vp, class _Pp, class _Rp, class _MP, class _Dp, _Dp>
friend class _LIBCPP_TEMPLATE_VIS __deque_iterator;
template <class _RAIter,
class _V2, class _P2, class _R2, class _M2, class _D2, _D2 _B2>
friend
__deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2>
copy(_RAIter __f,
_RAIter __l,
__deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r,
typename enable_if<__is_random_access_iterator<_RAIter>::value>::type*);
template <class _V1, class _P1, class _R1, class _M1, class _D1, _D1 _B1,
class _OutputIterator>
friend
_OutputIterator
copy(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f,
__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l,
_OutputIterator __r);
template <class _V1, class _P1, class _R1, class _M1, class _D1, _D1 _B1,
class _V2, class _P2, class _R2, class _M2, class _D2, _D2 _B2>
friend
__deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2>
copy(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f,
__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l,
__deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r);
template <class _RAIter,
class _V2, class _P2, class _R2, class _M2, class _D2, _D2 _B2>
friend
__deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2>
copy_backward(_RAIter __f,
_RAIter __l,
__deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r,
typename enable_if<__is_random_access_iterator<_RAIter>::value>::type*);
template <class _V1, class _P1, class _R1, class _M1, class _D1, _D1 _B1,
class _OutputIterator>
friend
_OutputIterator
copy_backward(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f,
__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l,
_OutputIterator __r);
template <class _V1, class _P1, class _R1, class _M1, class _D1, _D1 _B1,
class _V2, class _P2, class _R2, class _M2, class _D2, _D2 _B2>
friend
__deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2>
copy_backward(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f,
__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l,
__deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r);
template <class _RAIter,
class _V2, class _P2, class _R2, class _M2, class _D2, _D2 _B2>
friend
__deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2>
move(_RAIter __f,
_RAIter __l,
__deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r,
typename enable_if<__is_random_access_iterator<_RAIter>::value>::type*);
template <class _V1, class _P1, class _R1, class _M1, class _D1, _D1 _B1,
class _OutputIterator>
friend
_OutputIterator
move(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f,
__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l,
_OutputIterator __r);
template <class _V1, class _P1, class _R1, class _M1, class _D1, _D1 _B1,
class _V2, class _P2, class _R2, class _M2, class _D2, _D2 _B2>
friend
__deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2>
move(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f,
__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l,
__deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r);
template <class _RAIter,
class _V2, class _P2, class _R2, class _M2, class _D2, _D2 _B2>
friend
__deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2>
move_backward(_RAIter __f,
_RAIter __l,
__deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r,
typename enable_if<__is_random_access_iterator<_RAIter>::value>::type*);
template <class _V1, class _P1, class _R1, class _M1, class _D1, _D1 _B1,
class _OutputIterator>
friend
_OutputIterator
move_backward(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f,
__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l,
_OutputIterator __r);
template <class _V1, class _P1, class _R1, class _M1, class _D1, _D1 _B1,
class _V2, class _P2, class _R2, class _M2, class _D2, _D2 _B2>
friend
__deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2>
move_backward(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f,
__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l,
__deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r);
};
template <class _ValueType, class _Pointer, class _Reference, class _MapPointer,
class _DiffType, _DiffType _BlockSize>
const _DiffType __deque_iterator<_ValueType, _Pointer, _Reference, _MapPointer,
_DiffType, _BlockSize>::__block_size =
__deque_block_size<_ValueType, _DiffType>::value;
// copy
template <class _RAIter,
class _V2, class _P2, class _R2, class _M2, class _D2, _D2 _B2>
__deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2>
copy(_RAIter __f,
_RAIter __l,
__deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r,
typename enable_if<__is_random_access_iterator<_RAIter>::value>::type*)
{
typedef typename __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2>::difference_type difference_type;
typedef typename __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2>::pointer pointer;
const difference_type __block_size = __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2>::__block_size;
while (__f != __l)
{
pointer __rb = __r.__ptr_;
pointer __re = *__r.__m_iter_ + __block_size;
difference_type __bs = __re - __rb;
difference_type __n = __l - __f;
_RAIter __m = __l;
if (__n > __bs)
{
__n = __bs;
__m = __f + __n;
}
_VSTD::copy(__f, __m, __rb);
__f = __m;
__r += __n;
}
return __r;
}
template <class _V1, class _P1, class _R1, class _M1, class _D1, _D1 _B1,
class _OutputIterator>
_OutputIterator
copy(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f,
__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l,
_OutputIterator __r)
{
typedef typename __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1>::difference_type difference_type;
typedef typename __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1>::pointer pointer;
const difference_type __block_size = __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1>::__block_size;
difference_type __n = __l - __f;
while (__n > 0)
{
pointer __fb = __f.__ptr_;
pointer __fe = *__f.__m_iter_ + __block_size;
difference_type __bs = __fe - __fb;
if (__bs > __n)
{
__bs = __n;
__fe = __fb + __bs;
}
__r = _VSTD::copy(__fb, __fe, __r);
__n -= __bs;
__f += __bs;
}
return __r;
}
template <class _V1, class _P1, class _R1, class _M1, class _D1, _D1 _B1,
class _V2, class _P2, class _R2, class _M2, class _D2, _D2 _B2>
__deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2>
copy(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f,
__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l,
__deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r)
{
typedef typename __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1>::difference_type difference_type;
typedef typename __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1>::pointer pointer;
const difference_type __block_size = __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1>::__block_size;
difference_type __n = __l - __f;
while (__n > 0)
{
pointer __fb = __f.__ptr_;
pointer __fe = *__f.__m_iter_ + __block_size;
difference_type __bs = __fe - __fb;
if (__bs > __n)
{
__bs = __n;
__fe = __fb + __bs;
}
__r = _VSTD::copy(__fb, __fe, __r);
__n -= __bs;
__f += __bs;
}
return __r;
}
// copy_backward
template <class _RAIter,
class _V2, class _P2, class _R2, class _M2, class _D2, _D2 _B2>
__deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2>
copy_backward(_RAIter __f,
_RAIter __l,
__deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r,
typename enable_if<__is_random_access_iterator<_RAIter>::value>::type*)
{
typedef typename __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2>::difference_type difference_type;
typedef typename __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2>::pointer pointer;
while (__f != __l)
{
__deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __rp = _VSTD::prev(__r);
pointer __rb = *__rp.__m_iter_;
pointer __re = __rp.__ptr_ + 1;
difference_type __bs = __re - __rb;
difference_type __n = __l - __f;
_RAIter __m = __f;
if (__n > __bs)
{
__n = __bs;
__m = __l - __n;
}
_VSTD::copy_backward(__m, __l, __re);
__l = __m;
__r -= __n;
}
return __r;
}
template <class _V1, class _P1, class _R1, class _M1, class _D1, _D1 _B1,
class _OutputIterator>
_OutputIterator
copy_backward(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f,
__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l,
_OutputIterator __r)
{
typedef typename __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1>::difference_type difference_type;
typedef typename __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1>::pointer pointer;
difference_type __n = __l - __f;
while (__n > 0)
{
--__l;
pointer __lb = *__l.__m_iter_;
pointer __le = __l.__ptr_ + 1;
difference_type __bs = __le - __lb;
if (__bs > __n)
{
__bs = __n;
__lb = __le - __bs;
}
__r = _VSTD::copy_backward(__lb, __le, __r);
__n -= __bs;
__l -= __bs - 1;
}
return __r;
}
template <class _V1, class _P1, class _R1, class _M1, class _D1, _D1 _B1,
class _V2, class _P2, class _R2, class _M2, class _D2, _D2 _B2>
__deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2>
copy_backward(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f,
__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l,
__deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r)
{
typedef typename __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1>::difference_type difference_type;
typedef typename __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1>::pointer pointer;
difference_type __n = __l - __f;
while (__n > 0)
{
--__l;
pointer __lb = *__l.__m_iter_;
pointer __le = __l.__ptr_ + 1;
difference_type __bs = __le - __lb;
if (__bs > __n)
{
__bs = __n;
__lb = __le - __bs;
}
__r = _VSTD::copy_backward(__lb, __le, __r);
__n -= __bs;
__l -= __bs - 1;
}
return __r;
}
// move
template <class _RAIter,
class _V2, class _P2, class _R2, class _M2, class _D2, _D2 _B2>
__deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2>
move(_RAIter __f,
_RAIter __l,
__deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r,
typename enable_if<__is_random_access_iterator<_RAIter>::value>::type*)
{
typedef typename __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2>::difference_type difference_type;
typedef typename __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2>::pointer pointer;
const difference_type __block_size = __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2>::__block_size;
while (__f != __l)
{
pointer __rb = __r.__ptr_;
pointer __re = *__r.__m_iter_ + __block_size;
difference_type __bs = __re - __rb;
difference_type __n = __l - __f;
_RAIter __m = __l;
if (__n > __bs)
{
__n = __bs;
__m = __f + __n;
}
_VSTD::move(__f, __m, __rb);
__f = __m;
__r += __n;
}
return __r;
}
template <class _V1, class _P1, class _R1, class _M1, class _D1, _D1 _B1,
class _OutputIterator>
_OutputIterator
move(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f,
__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l,
_OutputIterator __r)
{
typedef typename __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1>::difference_type difference_type;
typedef typename __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1>::pointer pointer;
const difference_type __block_size = __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1>::__block_size;
difference_type __n = __l - __f;
while (__n > 0)
{
pointer __fb = __f.__ptr_;
pointer __fe = *__f.__m_iter_ + __block_size;
difference_type __bs = __fe - __fb;
if (__bs > __n)
{
__bs = __n;
__fe = __fb + __bs;
}
__r = _VSTD::move(__fb, __fe, __r);
__n -= __bs;
__f += __bs;
}
return __r;
}
template <class _V1, class _P1, class _R1, class _M1, class _D1, _D1 _B1,
class _V2, class _P2, class _R2, class _M2, class _D2, _D2 _B2>
__deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2>
move(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f,
__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l,
__deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r)
{
typedef typename __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1>::difference_type difference_type;
typedef typename __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1>::pointer pointer;
const difference_type __block_size = __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1>::__block_size;
difference_type __n = __l - __f;
while (__n > 0)
{
pointer __fb = __f.__ptr_;
pointer __fe = *__f.__m_iter_ + __block_size;
difference_type __bs = __fe - __fb;
if (__bs > __n)
{
__bs = __n;
__fe = __fb + __bs;
}
__r = _VSTD::move(__fb, __fe, __r);
__n -= __bs;
__f += __bs;
}
return __r;
}
// move_backward
template <class _RAIter,
class _V2, class _P2, class _R2, class _M2, class _D2, _D2 _B2>
__deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2>
move_backward(_RAIter __f,
_RAIter __l,
__deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r,
typename enable_if<__is_random_access_iterator<_RAIter>::value>::type*)
{
typedef typename __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2>::difference_type difference_type;
typedef typename __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2>::pointer pointer;
while (__f != __l)
{
__deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __rp = _VSTD::prev(__r);
pointer __rb = *__rp.__m_iter_;
pointer __re = __rp.__ptr_ + 1;
difference_type __bs = __re - __rb;
difference_type __n = __l - __f;
_RAIter __m = __f;
if (__n > __bs)
{
__n = __bs;
__m = __l - __n;
}
_VSTD::move_backward(__m, __l, __re);
__l = __m;
__r -= __n;
}
return __r;
}
template <class _V1, class _P1, class _R1, class _M1, class _D1, _D1 _B1,
class _OutputIterator>
_OutputIterator
move_backward(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f,
__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l,
_OutputIterator __r)
{
typedef typename __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1>::difference_type difference_type;
typedef typename __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1>::pointer pointer;
difference_type __n = __l - __f;
while (__n > 0)
{
--__l;
pointer __lb = *__l.__m_iter_;
pointer __le = __l.__ptr_ + 1;
difference_type __bs = __le - __lb;
if (__bs > __n)
{
__bs = __n;
__lb = __le - __bs;
}
__r = _VSTD::move_backward(__lb, __le, __r);
__n -= __bs;
__l -= __bs - 1;
}
return __r;
}
template <class _V1, class _P1, class _R1, class _M1, class _D1, _D1 _B1,
class _V2, class _P2, class _R2, class _M2, class _D2, _D2 _B2>
__deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2>
move_backward(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f,
__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l,
__deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r)
{
typedef typename __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1>::difference_type difference_type;
typedef typename __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1>::pointer pointer;
difference_type __n = __l - __f;
while (__n > 0)
{
--__l;
pointer __lb = *__l.__m_iter_;
pointer __le = __l.__ptr_ + 1;
difference_type __bs = __le - __lb;
if (__bs > __n)
{
__bs = __n;
__lb = __le - __bs;
}
__r = _VSTD::move_backward(__lb, __le, __r);
__n -= __bs;
__l -= __bs - 1;
}
return __r;
}
template <bool>
class __deque_base_common
{
protected:
_LIBCPP_NORETURN void __throw_length_error() const;
_LIBCPP_NORETURN void __throw_out_of_range() const;
};
template <bool __b>
void
__deque_base_common<__b>::__throw_length_error() const
{
_VSTD::__throw_length_error("deque");
}
template <bool __b>
void
__deque_base_common<__b>::__throw_out_of_range() const
{
_VSTD::__throw_out_of_range("deque");
}
template <class _Tp, class _Allocator>
class __deque_base
: protected __deque_base_common<true>
{
__deque_base(const __deque_base& __c);
__deque_base& operator=(const __deque_base& __c);
public:
typedef _Allocator allocator_type;
typedef allocator_traits<allocator_type> __alloc_traits;
typedef typename __alloc_traits::size_type size_type;
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;
static const difference_type __block_size;
typedef typename __rebind_alloc_helper<__alloc_traits, pointer>::type __pointer_allocator;
typedef allocator_traits<__pointer_allocator> __map_traits;
typedef typename __map_traits::pointer __map_pointer;
typedef typename __rebind_alloc_helper<__alloc_traits, const_pointer>::type __const_pointer_allocator;
typedef typename allocator_traits<__const_pointer_allocator>::const_pointer __map_const_pointer;
typedef __split_buffer<pointer, __pointer_allocator> __map;
typedef __deque_iterator<value_type, pointer, reference, __map_pointer,
difference_type> iterator;
typedef __deque_iterator<value_type, const_pointer, const_reference, __map_const_pointer,
difference_type> const_iterator;
struct __deque_block_range {
explicit __deque_block_range(pointer __b, pointer __e) _NOEXCEPT : __begin_(__b), __end_(__e) {}
const pointer __begin_;
const pointer __end_;
};
struct __deque_range {
iterator __pos_;
const iterator __end_;
__deque_range(iterator __pos, iterator __e) _NOEXCEPT
: __pos_(__pos), __end_(__e) {}
explicit operator bool() const _NOEXCEPT {
return __pos_ != __end_;
}
__deque_range begin() const {
return *this;
}
__deque_range end() const {
return __deque_range(__end_, __end_);
}
__deque_block_range operator*() const _NOEXCEPT {
if (__pos_.__m_iter_ == __end_.__m_iter_) {
return __deque_block_range(__pos_.__ptr_, __end_.__ptr_);
}
return __deque_block_range(__pos_.__ptr_, *__pos_.__m_iter_ + __block_size);
}
__deque_range& operator++() _NOEXCEPT {
if (__pos_.__m_iter_ == __end_.__m_iter_) {
__pos_ = __end_;
} else {
++__pos_.__m_iter_;
__pos_.__ptr_ = *__pos_.__m_iter_;
}
return *this;
}
friend bool operator==(__deque_range const& __lhs, __deque_range const& __rhs) {
return __lhs.__pos_ == __rhs.__pos_;
}
friend bool operator!=(__deque_range const& __lhs, __deque_range const& __rhs) {
return !(__lhs == __rhs);
}
};
struct _ConstructTransaction {
_ConstructTransaction(__deque_base* __db, __deque_block_range& __r)
: __pos_(__r.__begin_), __end_(__r.__end_), __begin_(__r.__begin_), __base_(__db) {}
~_ConstructTransaction() {
__base_->size() += (__pos_ - __begin_);
}
pointer __pos_;
const pointer __end_;
private:
const pointer __begin_;
__deque_base * const __base_;
};
protected:
__map __map_;
size_type __start_;
__compressed_pair<size_type, allocator_type> __size_;
iterator begin() _NOEXCEPT;
const_iterator begin() const _NOEXCEPT;
iterator end() _NOEXCEPT;
const_iterator end() const _NOEXCEPT;
_LIBCPP_INLINE_VISIBILITY size_type& size() {return __size_.first();}
_LIBCPP_INLINE_VISIBILITY
const size_type& size() const _NOEXCEPT {return __size_.first();}
_LIBCPP_INLINE_VISIBILITY allocator_type& __alloc() {return __size_.second();}
_LIBCPP_INLINE_VISIBILITY
const allocator_type& __alloc() const _NOEXCEPT {return __size_.second();}
_LIBCPP_INLINE_VISIBILITY
__deque_base()
_NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value);
_LIBCPP_INLINE_VISIBILITY
explicit __deque_base(const allocator_type& __a);
public:
~__deque_base();
#ifndef _LIBCPP_CXX03_LANG
__deque_base(__deque_base&& __c)
_NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value);
__deque_base(__deque_base&& __c, const allocator_type& __a);
#endif // _LIBCPP_CXX03_LANG
void swap(__deque_base& __c)
#if _LIBCPP_STD_VER >= 14
_NOEXCEPT;
#else
_NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value ||
__is_nothrow_swappable<allocator_type>::value);
#endif
protected:
void clear() _NOEXCEPT;
bool __invariants() const;
_LIBCPP_INLINE_VISIBILITY
void __move_assign(__deque_base& __c)
_NOEXCEPT_(__alloc_traits::propagate_on_container_move_assignment::value &&
is_nothrow_move_assignable<allocator_type>::value)
{
__map_ = _VSTD::move(__c.__map_);
__start_ = __c.__start_;
size() = __c.size();
__move_assign_alloc(__c);
__c.__start_ = __c.size() = 0;
}
_LIBCPP_INLINE_VISIBILITY
void __move_assign_alloc(__deque_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 __move_assign_alloc(__deque_base& __c, true_type)
_NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value)
{
__alloc() = _VSTD::move(__c.__alloc());
}
_LIBCPP_INLINE_VISIBILITY
void __move_assign_alloc(__deque_base&, false_type) _NOEXCEPT
{}
};
template <class _Tp, class _Allocator>
const typename __deque_base<_Tp, _Allocator>::difference_type
__deque_base<_Tp, _Allocator>::__block_size =
__deque_block_size<value_type, difference_type>::value;
template <class _Tp, class _Allocator>
bool
__deque_base<_Tp, _Allocator>::__invariants() const
{
if (!__map_.__invariants())
return false;
if (__map_.size() >= size_type(-1) / __block_size)
return false;
for (typename __map::const_iterator __i = __map_.begin(), __e = __map_.end();
__i != __e; ++__i)
if (*__i == nullptr)
return false;
if (__map_.size() != 0)
{
if (size() >= __map_.size() * __block_size)
return false;
if (__start_ >= __map_.size() * __block_size - size())
return false;
}
else
{
if (size() != 0)
return false;
if (__start_ != 0)
return false;
}
return true;
}
template <class _Tp, class _Allocator>
typename __deque_base<_Tp, _Allocator>::iterator
__deque_base<_Tp, _Allocator>::begin() _NOEXCEPT
{
__map_pointer __mp = __map_.begin() + __start_ / __block_size;
return iterator(__mp, __map_.empty() ? 0 : *__mp + __start_ % __block_size);
}
template <class _Tp, class _Allocator>
typename __deque_base<_Tp, _Allocator>::const_iterator
__deque_base<_Tp, _Allocator>::begin() const _NOEXCEPT
{
__map_const_pointer __mp = static_cast<__map_const_pointer>(__map_.begin() + __start_ / __block_size);
return const_iterator(__mp, __map_.empty() ? 0 : *__mp + __start_ % __block_size);
}
template <class _Tp, class _Allocator>
typename __deque_base<_Tp, _Allocator>::iterator
__deque_base<_Tp, _Allocator>::end() _NOEXCEPT
{
size_type __p = size() + __start_;
__map_pointer __mp = __map_.begin() + __p / __block_size;
return iterator(__mp, __map_.empty() ? 0 : *__mp + __p % __block_size);
}
template <class _Tp, class _Allocator>
typename __deque_base<_Tp, _Allocator>::const_iterator
__deque_base<_Tp, _Allocator>::end() const _NOEXCEPT
{
size_type __p = size() + __start_;
__map_const_pointer __mp = static_cast<__map_const_pointer>(__map_.begin() + __p / __block_size);
return const_iterator(__mp, __map_.empty() ? 0 : *__mp + __p % __block_size);
}
template <class _Tp, class _Allocator>
inline
__deque_base<_Tp, _Allocator>::__deque_base()
_NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value)
: __start_(0), __size_(0) {}
template <class _Tp, class _Allocator>
inline
__deque_base<_Tp, _Allocator>::__deque_base(const allocator_type& __a)
: __map_(__pointer_allocator(__a)), __start_(0), __size_(0, __a) {}
template <class _Tp, class _Allocator>
__deque_base<_Tp, _Allocator>::~__deque_base()
{
clear();
typename __map::iterator __i = __map_.begin();
typename __map::iterator __e = __map_.end();
for (; __i != __e; ++__i)
__alloc_traits::deallocate(__alloc(), *__i, __block_size);
}
#ifndef _LIBCPP_CXX03_LANG
template <class _Tp, class _Allocator>
__deque_base<_Tp, _Allocator>::__deque_base(__deque_base&& __c)
_NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value)
: __map_(_VSTD::move(__c.__map_)),
__start_(_VSTD::move(__c.__start_)),
__size_(_VSTD::move(__c.__size_))
{
__c.__start_ = 0;
__c.size() = 0;
}
template <class _Tp, class _Allocator>
__deque_base<_Tp, _Allocator>::__deque_base(__deque_base&& __c, const allocator_type& __a)
: __map_(_VSTD::move(__c.__map_), __pointer_allocator(__a)),
__start_(_VSTD::move(__c.__start_)),
__size_(_VSTD::move(__c.size()), __a)
{
if (__a == __c.__alloc())
{
__c.__start_ = 0;
__c.size() = 0;
}
else
{
__map_.clear();
__start_ = 0;
size() = 0;
}
}
#endif // _LIBCPP_CXX03_LANG
template <class _Tp, class _Allocator>
void
__deque_base<_Tp, _Allocator>::swap(__deque_base& __c)
#if _LIBCPP_STD_VER >= 14
_NOEXCEPT
#else
_NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value ||
__is_nothrow_swappable<allocator_type>::value)
#endif
{
__map_.swap(__c.__map_);
_VSTD::swap(__start_, __c.__start_);
_VSTD::swap(size(), __c.size());
__swap_allocator(__alloc(), __c.__alloc());
}
template <class _Tp, class _Allocator>
void
__deque_base<_Tp, _Allocator>::clear() _NOEXCEPT
{
allocator_type& __a = __alloc();
for (iterator __i = begin(), __e = end(); __i != __e; ++__i)
__alloc_traits::destroy(__a, _VSTD::addressof(*__i));
size() = 0;
while (__map_.size() > 2)
{
__alloc_traits::deallocate(__a, __map_.front(), __block_size);
__map_.pop_front();
}
switch (__map_.size())
{
case 1:
__start_ = __block_size / 2;
break;
case 2:
__start_ = __block_size;
break;
}
}
template <class _Tp, class _Allocator /*= allocator<_Tp>*/>
class _LIBCPP_TEMPLATE_VIS deque
: private __deque_base<_Tp, _Allocator>
{
public:
// types:
typedef _Tp value_type;
typedef _Allocator allocator_type;
static_assert((is_same<typename allocator_type::value_type, value_type>::value),
"Allocator::value_type must be same type as value_type");
typedef __deque_base<value_type, allocator_type> __base;
typedef typename __base::__alloc_traits __alloc_traits;
typedef typename __base::reference reference;
typedef typename __base::const_reference const_reference;
typedef typename __base::iterator iterator;
typedef typename __base::const_iterator const_iterator;
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 _VSTD::reverse_iterator<iterator> reverse_iterator;
typedef _VSTD::reverse_iterator<const_iterator> const_reverse_iterator;
using typename __base::__deque_range;
using typename __base::__deque_block_range;
using typename __base::_ConstructTransaction;
// construct/copy/destroy:
_LIBCPP_INLINE_VISIBILITY
deque()
_NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value)
{}
_LIBCPP_INLINE_VISIBILITY explicit deque(const allocator_type& __a) : __base(__a) {}
explicit deque(size_type __n);
#if _LIBCPP_STD_VER > 11
explicit deque(size_type __n, const _Allocator& __a);
#endif
deque(size_type __n, const value_type& __v);
deque(size_type __n, const value_type& __v, const allocator_type& __a);
template <class _InputIter>
deque(_InputIter __f, _InputIter __l,
typename enable_if<__is_input_iterator<_InputIter>::value>::type* = 0);
template <class _InputIter>
deque(_InputIter __f, _InputIter __l, const allocator_type& __a,
typename enable_if<__is_input_iterator<_InputIter>::value>::type* = 0);
deque(const deque& __c);
deque(const deque& __c, const allocator_type& __a);
deque& operator=(const deque& __c);
#ifndef _LIBCPP_CXX03_LANG
deque(initializer_list<value_type> __il);
deque(initializer_list<value_type> __il, const allocator_type& __a);
_LIBCPP_INLINE_VISIBILITY
deque& operator=(initializer_list<value_type> __il) {assign(__il); return *this;}
_LIBCPP_INLINE_VISIBILITY
deque(deque&& __c) _NOEXCEPT_(is_nothrow_move_constructible<__base>::value);
_LIBCPP_INLINE_VISIBILITY
deque(deque&& __c, const allocator_type& __a);
_LIBCPP_INLINE_VISIBILITY
deque& operator=(deque&& __c)
_NOEXCEPT_(__alloc_traits::propagate_on_container_move_assignment::value &&
is_nothrow_move_assignable<allocator_type>::value);
_LIBCPP_INLINE_VISIBILITY
void assign(initializer_list<value_type> __il) {assign(__il.begin(), __il.end());}
#endif // _LIBCPP_CXX03_LANG
template <class _InputIter>
void assign(_InputIter __f, _InputIter __l,
typename enable_if<__is_input_iterator<_InputIter>::value &&
!__is_random_access_iterator<_InputIter>::value>::type* = 0);
template <class _RAIter>
void assign(_RAIter __f, _RAIter __l,
typename enable_if<__is_random_access_iterator<_RAIter>::value>::type* = 0);
void assign(size_type __n, const value_type& __v);
_LIBCPP_INLINE_VISIBILITY
allocator_type get_allocator() const _NOEXCEPT;
// iterators:
_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
reverse_iterator rbegin() _NOEXCEPT
{return reverse_iterator(__base::end());}
_LIBCPP_INLINE_VISIBILITY
const_reverse_iterator rbegin() const _NOEXCEPT
{return const_reverse_iterator(__base::end());}
_LIBCPP_INLINE_VISIBILITY
reverse_iterator rend() _NOEXCEPT
{return reverse_iterator(__base::begin());}
_LIBCPP_INLINE_VISIBILITY
const_reverse_iterator rend() const _NOEXCEPT
{return const_reverse_iterator(__base::begin());}
_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
const_reverse_iterator crbegin() const _NOEXCEPT
{return const_reverse_iterator(__base::end());}
_LIBCPP_INLINE_VISIBILITY
const_reverse_iterator crend() const _NOEXCEPT
{return const_reverse_iterator(__base::begin());}
// capacity:
_LIBCPP_INLINE_VISIBILITY
size_type size() const _NOEXCEPT {return __base::size();}
_LIBCPP_INLINE_VISIBILITY
size_type max_size() const _NOEXCEPT
{return std::min<size_type>(
__alloc_traits::max_size(__base::__alloc()),
numeric_limits<difference_type>::max());}
void resize(size_type __n);
void resize(size_type __n, const value_type& __v);
void shrink_to_fit() _NOEXCEPT;
_LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
bool empty() const _NOEXCEPT {return __base::size() == 0;}
// element access:
_LIBCPP_INLINE_VISIBILITY
reference operator[](size_type __i) _NOEXCEPT;
_LIBCPP_INLINE_VISIBILITY
const_reference operator[](size_type __i) const _NOEXCEPT;
_LIBCPP_INLINE_VISIBILITY
reference at(size_type __i);
_LIBCPP_INLINE_VISIBILITY
const_reference at(size_type __i) const;
_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;
// 23.2.2.3 modifiers:
void push_front(const value_type& __v);
void push_back(const value_type& __v);
#ifndef _LIBCPP_CXX03_LANG
#if _LIBCPP_STD_VER > 14
template <class... _Args> reference emplace_front(_Args&&... __args);
template <class... _Args> reference emplace_back (_Args&&... __args);
#else
template <class... _Args> void emplace_front(_Args&&... __args);
template <class... _Args> void emplace_back (_Args&&... __args);
#endif
template <class... _Args> iterator emplace(const_iterator __p, _Args&&... __args);
void push_front(value_type&& __v);
void push_back(value_type&& __v);
iterator insert(const_iterator __p, value_type&& __v);
_LIBCPP_INLINE_VISIBILITY
iterator insert(const_iterator __p, initializer_list<value_type> __il)
{return insert(__p, __il.begin(), __il.end());}
#endif // _LIBCPP_CXX03_LANG
iterator insert(const_iterator __p, const value_type& __v);
iterator insert(const_iterator __p, size_type __n, const value_type& __v);
template <class _InputIter>
iterator insert(const_iterator __p, _InputIter __f, _InputIter __l,
typename enable_if<__is_input_iterator<_InputIter>::value
&&!__is_forward_iterator<_InputIter>::value>::type* = 0);
template <class _ForwardIterator>
iterator insert(const_iterator __p, _ForwardIterator __f, _ForwardIterator __l,
typename enable_if<__is_forward_iterator<_ForwardIterator>::value
&&!__is_bidirectional_iterator<_ForwardIterator>::value>::type* = 0);
template <class _BiIter>
iterator insert(const_iterator __p, _BiIter __f, _BiIter __l,
typename enable_if<__is_bidirectional_iterator<_BiIter>::value>::type* = 0);
void pop_front();
void pop_back();
iterator erase(const_iterator __p);
iterator erase(const_iterator __f, const_iterator __l);
_LIBCPP_INLINE_VISIBILITY
void swap(deque& __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 clear() _NOEXCEPT;
_LIBCPP_INLINE_VISIBILITY
bool __invariants() const {return __base::__invariants();}
typedef typename __base::__map_const_pointer __map_const_pointer;
_LIBCPP_INLINE_VISIBILITY
static size_type __recommend_blocks(size_type __n)
{
return __n / __base::__block_size + (__n % __base::__block_size != 0);
}
_LIBCPP_INLINE_VISIBILITY
size_type __capacity() const
{
return __base::__map_.size() == 0 ? 0 : __base::__map_.size() * __base::__block_size - 1;
}
_LIBCPP_INLINE_VISIBILITY
size_type __block_count() const
{
return __base::__map_.size();
}
_LIBCPP_INLINE_VISIBILITY
size_type __front_spare() const
{
return __base::__start_;
}
_LIBCPP_INLINE_VISIBILITY
size_type __front_spare_blocks() const {
return __front_spare() / __base::__block_size;
}
_LIBCPP_INLINE_VISIBILITY
size_type __back_spare() const
{
return __capacity() - (__base::__start_ + __base::size());
}
_LIBCPP_INLINE_VISIBILITY
size_type __back_spare_blocks() const {
return __back_spare() / __base::__block_size;
}
private:
_LIBCPP_INLINE_VISIBILITY
bool __maybe_remove_front_spare(bool __keep_one = true) {
if (__front_spare_blocks() >= 2 || (!__keep_one && __front_spare_blocks())) {
__alloc_traits::deallocate(__base::__alloc(), __base::__map_.front(),
__base::__block_size);
__base::__map_.pop_front();
__base::__start_ -= __base::__block_size;
return true;
}
return false;
}
_LIBCPP_INLINE_VISIBILITY
bool __maybe_remove_back_spare(bool __keep_one = true) {
if (__back_spare_blocks() >= 2 || (!__keep_one && __back_spare_blocks())) {
__alloc_traits::deallocate(__base::__alloc(), __base::__map_.back(),
__base::__block_size);
__base::__map_.pop_back();
return true;
}
return false;
}
template <class _InpIter>
void __append(_InpIter __f, _InpIter __l,
typename enable_if<__is_input_iterator<_InpIter>::value &&
!__is_forward_iterator<_InpIter>::value>::type* = 0);
template <class _ForIter>
void __append(_ForIter __f, _ForIter __l,
typename enable_if<__is_forward_iterator<_ForIter>::value>::type* = 0);
void __append(size_type __n);
void __append(size_type __n, const value_type& __v);
void __erase_to_end(const_iterator __f);
void __add_front_capacity();
void __add_front_capacity(size_type __n);
void __add_back_capacity();
void __add_back_capacity(size_type __n);
iterator __move_and_check(iterator __f, iterator __l, iterator __r,
const_pointer& __vt);
iterator __move_backward_and_check(iterator __f, iterator __l, iterator __r,
const_pointer& __vt);
void __move_construct_and_check(iterator __f, iterator __l,
iterator __r, const_pointer& __vt);
void __move_construct_backward_and_check(iterator __f, iterator __l,
iterator __r, const_pointer& __vt);
_LIBCPP_INLINE_VISIBILITY
void __copy_assign_alloc(const deque& __c)
{__copy_assign_alloc(__c, integral_constant<bool,
__alloc_traits::propagate_on_container_copy_assignment::value>());}
_LIBCPP_INLINE_VISIBILITY
void __copy_assign_alloc(const deque& __c, true_type)
{
if (__base::__alloc() != __c.__alloc())
{
clear();
shrink_to_fit();
}
__base::__alloc() = __c.__alloc();
__base::__map_.__alloc() = __c.__map_.__alloc();
}
_LIBCPP_INLINE_VISIBILITY
void __copy_assign_alloc(const deque&, false_type)
{}
void __move_assign(deque& __c, true_type)
_NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value);
void __move_assign(deque& __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
>
deque(_InputIterator, _InputIterator)
-> deque<typename iterator_traits<_InputIterator>::value_type, _Alloc>;
template<class _InputIterator,
class _Alloc,
class = typename enable_if<__is_allocator<_Alloc>::value, void>::type
>
deque(_InputIterator, _InputIterator, _Alloc)
-> deque<typename iterator_traits<_InputIterator>::value_type, _Alloc>;
#endif
template <class _Tp, class _Allocator>
deque<_Tp, _Allocator>::deque(size_type __n)
{
if (__n > 0)
__append(__n);
}
#if _LIBCPP_STD_VER > 11
template <class _Tp, class _Allocator>
deque<_Tp, _Allocator>::deque(size_type __n, const _Allocator& __a)
: __base(__a)
{
if (__n > 0)
__append(__n);
}
#endif
template <class _Tp, class _Allocator>
deque<_Tp, _Allocator>::deque(size_type __n, const value_type& __v)
{
if (__n > 0)
__append(__n, __v);
}
template <class _Tp, class _Allocator>
deque<_Tp, _Allocator>::deque(size_type __n, const value_type& __v, const allocator_type& __a)
: __base(__a)
{
if (__n > 0)
__append(__n, __v);
}
template <class _Tp, class _Allocator>
template <class _InputIter>
deque<_Tp, _Allocator>::deque(_InputIter __f, _InputIter __l,
typename enable_if<__is_input_iterator<_InputIter>::value>::type*)
{
__append(__f, __l);
}
template <class _Tp, class _Allocator>
template <class _InputIter>
deque<_Tp, _Allocator>::deque(_InputIter __f, _InputIter __l, const allocator_type& __a,
typename enable_if<__is_input_iterator<_InputIter>::value>::type*)
: __base(__a)
{
__append(__f, __l);
}
template <class _Tp, class _Allocator>
deque<_Tp, _Allocator>::deque(const deque& __c)
: __base(__alloc_traits::select_on_container_copy_construction(__c.__alloc()))
{
__append(__c.begin(), __c.end());
}
template <class _Tp, class _Allocator>
deque<_Tp, _Allocator>::deque(const deque& __c, const allocator_type& __a)
: __base(__a)
{
__append(__c.begin(), __c.end());
}
template <class _Tp, class _Allocator>
deque<_Tp, _Allocator>&
deque<_Tp, _Allocator>::operator=(const deque& __c)
{
if (this != &__c)
{
__copy_assign_alloc(__c);
assign(__c.begin(), __c.end());
}
return *this;
}
#ifndef _LIBCPP_CXX03_LANG
template <class _Tp, class _Allocator>
deque<_Tp, _Allocator>::deque(initializer_list<value_type> __il)
{
__append(__il.begin(), __il.end());
}
template <class _Tp, class _Allocator>
deque<_Tp, _Allocator>::deque(initializer_list<value_type> __il, const allocator_type& __a)
: __base(__a)
{
__append(__il.begin(), __il.end());
}
template <class _Tp, class _Allocator>
inline
deque<_Tp, _Allocator>::deque(deque&& __c)
_NOEXCEPT_(is_nothrow_move_constructible<__base>::value)
: __base(_VSTD::move(__c))
{
}
template <class _Tp, class _Allocator>
inline
deque<_Tp, _Allocator>::deque(deque&& __c, const allocator_type& __a)
: __base(_VSTD::move(__c), __a)
{
if (__a != __c.__alloc())
{
typedef move_iterator<iterator> _Ip;
assign(_Ip(__c.begin()), _Ip(__c.end()));
}
}
template <class _Tp, class _Allocator>
inline
deque<_Tp, _Allocator>&
deque<_Tp, _Allocator>::operator=(deque&& __c)
_NOEXCEPT_(__alloc_traits::propagate_on_container_move_assignment::value &&
is_nothrow_move_assignable<allocator_type>::value)
{
__move_assign(__c, integral_constant<bool,
__alloc_traits::propagate_on_container_move_assignment::value>());
return *this;
}
template <class _Tp, class _Allocator>
void
deque<_Tp, _Allocator>::__move_assign(deque& __c, false_type)
{
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
deque<_Tp, _Allocator>::__move_assign(deque& __c, true_type)
_NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value)
{
clear();
shrink_to_fit();
__base::__move_assign(__c);
}
#endif // _LIBCPP_CXX03_LANG
template <class _Tp, class _Allocator>
template <class _InputIter>
void
deque<_Tp, _Allocator>::assign(_InputIter __f, _InputIter __l,
typename enable_if<__is_input_iterator<_InputIter>::value &&
!__is_random_access_iterator<_InputIter>::value>::type*)
{
iterator __i = __base::begin();
iterator __e = __base::end();
for (; __f != __l && __i != __e; ++__f, (void) ++__i)
*__i = *__f;
if (__f != __l)
__append(__f, __l);
else
__erase_to_end(__i);
}
template <class _Tp, class _Allocator>
template <class _RAIter>
void
deque<_Tp, _Allocator>::assign(_RAIter __f, _RAIter __l,
typename enable_if<__is_random_access_iterator<_RAIter>::value>::type*)
{
if (static_cast<size_type>(__l - __f) > __base::size())
{
_RAIter __m = __f + __base::size();
_VSTD::copy(__f, __m, __base::begin());
__append(__m, __l);
}
else
__erase_to_end(_VSTD::copy(__f, __l, __base::begin()));
}
template <class _Tp, class _Allocator>
void
deque<_Tp, _Allocator>::assign(size_type __n, const value_type& __v)
{
if (__n > __base::size())
{
_VSTD::fill_n(__base::begin(), __base::size(), __v);
__n -= __base::size();
__append(__n, __v);
}
else
__erase_to_end(_VSTD::fill_n(__base::begin(), __n, __v));
}
template <class _Tp, class _Allocator>
inline
_Allocator
deque<_Tp, _Allocator>::get_allocator() const _NOEXCEPT
{
return __base::__alloc();
}
template <class _Tp, class _Allocator>
void
deque<_Tp, _Allocator>::resize(size_type __n)
{
if (__n > __base::size())
__append(__n - __base::size());
else if (__n < __base::size())
__erase_to_end(__base::begin() + __n);
}
template <class _Tp, class _Allocator>
void
deque<_Tp, _Allocator>::resize(size_type __n, const value_type& __v)
{
if (__n > __base::size())
__append(__n - __base::size(), __v);
else if (__n < __base::size())
__erase_to_end(__base::begin() + __n);
}
template <class _Tp, class _Allocator>
void
deque<_Tp, _Allocator>::shrink_to_fit() _NOEXCEPT
{
allocator_type& __a = __base::__alloc();
if (empty())
{
while (__base::__map_.size() > 0)
{
__alloc_traits::deallocate(__a, __base::__map_.back(), __base::__block_size);
__base::__map_.pop_back();
}
__base::__start_ = 0;
}
else
{
__maybe_remove_front_spare(/*__keep_one=*/false);
__maybe_remove_back_spare(/*__keep_one=*/false);
}
__base::__map_.shrink_to_fit();
}
template <class _Tp, class _Allocator>
inline
typename deque<_Tp, _Allocator>::reference
deque<_Tp, _Allocator>::operator[](size_type __i) _NOEXCEPT
{
size_type __p = __base::__start_ + __i;
return *(*(__base::__map_.begin() + __p / __base::__block_size) + __p % __base::__block_size);
}
template <class _Tp, class _Allocator>
inline
typename deque<_Tp, _Allocator>::const_reference
deque<_Tp, _Allocator>::operator[](size_type __i) const _NOEXCEPT
{
size_type __p = __base::__start_ + __i;
return *(*(__base::__map_.begin() + __p / __base::__block_size) + __p % __base::__block_size);
}
template <class _Tp, class _Allocator>
inline
typename deque<_Tp, _Allocator>::reference
deque<_Tp, _Allocator>::at(size_type __i)
{
if (__i >= __base::size())
__base::__throw_out_of_range();
size_type __p = __base::__start_ + __i;
return *(*(__base::__map_.begin() + __p / __base::__block_size) + __p % __base::__block_size);
}
template <class _Tp, class _Allocator>
inline
typename deque<_Tp, _Allocator>::const_reference
deque<_Tp, _Allocator>::at(size_type __i) const
{
if (__i >= __base::size())
__base::__throw_out_of_range();
size_type __p = __base::__start_ + __i;
return *(*(__base::__map_.begin() + __p / __base::__block_size) + __p % __base::__block_size);
}
template <class _Tp, class _Allocator>
inline
typename deque<_Tp, _Allocator>::reference
deque<_Tp, _Allocator>::front() _NOEXCEPT
{
return *(*(__base::__map_.begin() + __base::__start_ / __base::__block_size)
+ __base::__start_ % __base::__block_size);
}
template <class _Tp, class _Allocator>
inline
typename deque<_Tp, _Allocator>::const_reference
deque<_Tp, _Allocator>::front() const _NOEXCEPT
{
return *(*(__base::__map_.begin() + __base::__start_ / __base::__block_size)
+ __base::__start_ % __base::__block_size);
}
template <class _Tp, class _Allocator>
inline
typename deque<_Tp, _Allocator>::reference
deque<_Tp, _Allocator>::back() _NOEXCEPT
{
size_type __p = __base::size() + __base::__start_ - 1;
return *(*(__base::__map_.begin() + __p / __base::__block_size) + __p % __base::__block_size);
}
template <class _Tp, class _Allocator>
inline
typename deque<_Tp, _Allocator>::const_reference
deque<_Tp, _Allocator>::back() const _NOEXCEPT
{
size_type __p = __base::size() + __base::__start_ - 1;
return *(*(__base::__map_.begin() + __p / __base::__block_size) + __p % __base::__block_size);
}
template <class _Tp, class _Allocator>
void
deque<_Tp, _Allocator>::push_back(const value_type& __v)
{
allocator_type& __a = __base::__alloc();
if (__back_spare() == 0)
__add_back_capacity();
// __back_spare() >= 1
__alloc_traits::construct(__a, _VSTD::addressof(*__base::end()), __v);
++__base::size();
}
template <class _Tp, class _Allocator>
void
deque<_Tp, _Allocator>::push_front(const value_type& __v)
{
allocator_type& __a = __base::__alloc();
if (__front_spare() == 0)
__add_front_capacity();
// __front_spare() >= 1
__alloc_traits::construct(__a, _VSTD::addressof(*--__base::begin()), __v);
--__base::__start_;
++__base::size();
}
#ifndef _LIBCPP_CXX03_LANG
template <class _Tp, class _Allocator>
void
deque<_Tp, _Allocator>::push_back(value_type&& __v)
{
allocator_type& __a = __base::__alloc();
if (__back_spare() == 0)
__add_back_capacity();
// __back_spare() >= 1
__alloc_traits::construct(__a, _VSTD::addressof(*__base::end()), _VSTD::move(__v));
++__base::size();
}
template <class _Tp, class _Allocator>
template <class... _Args>
#if _LIBCPP_STD_VER > 14
typename deque<_Tp, _Allocator>::reference
#else
void
#endif
deque<_Tp, _Allocator>::emplace_back(_Args&&... __args)
{
allocator_type& __a = __base::__alloc();
if (__back_spare() == 0)
__add_back_capacity();
// __back_spare() >= 1
__alloc_traits::construct(__a, _VSTD::addressof(*__base::end()),
_VSTD::forward<_Args>(__args)...);
++__base::size();
#if _LIBCPP_STD_VER > 14
return *--__base::end();
#endif
}
template <class _Tp, class _Allocator>
void
deque<_Tp, _Allocator>::push_front(value_type&& __v)
{
allocator_type& __a = __base::__alloc();
if (__front_spare() == 0)
__add_front_capacity();
// __front_spare() >= 1
__alloc_traits::construct(__a, _VSTD::addressof(*--__base::begin()), _VSTD::move(__v));
--__base::__start_;
++__base::size();
}
template <class _Tp, class _Allocator>
template <class... _Args>
#if _LIBCPP_STD_VER > 14
typename deque<_Tp, _Allocator>::reference
#else
void
#endif
deque<_Tp, _Allocator>::emplace_front(_Args&&... __args)
{
allocator_type& __a = __base::__alloc();
if (__front_spare() == 0)
__add_front_capacity();
// __front_spare() >= 1
__alloc_traits::construct(__a, _VSTD::addressof(*--__base::begin()), _VSTD::forward<_Args>(__args)...);
--__base::__start_;
++__base::size();
#if _LIBCPP_STD_VER > 14
return *__base::begin();
#endif
}
template <class _Tp, class _Allocator>
typename deque<_Tp, _Allocator>::iterator
deque<_Tp, _Allocator>::insert(const_iterator __p, value_type&& __v)
{
size_type __pos = __p - __base::begin();
size_type __to_end = __base::size() - __pos;
allocator_type& __a = __base::__alloc();
if (__pos < __to_end)
{ // insert by shifting things backward
if (__front_spare() == 0)
__add_front_capacity();
// __front_spare() >= 1
if (__pos == 0)
{
__alloc_traits::construct(__a, _VSTD::addressof(*--__base::begin()), _VSTD::move(__v));
--__base::__start_;
++__base::size();
}
else
{
iterator __b = __base::begin();
iterator __bm1 = _VSTD::prev(__b);
__alloc_traits::construct(__a, _VSTD::addressof(*__bm1), _VSTD::move(*__b));
--__base::__start_;
++__base::size();
if (__pos > 1)
__b = _VSTD::move(_VSTD::next(__b), __b + __pos, __b);
*__b = _VSTD::move(__v);
}
}
else
{ // insert by shifting things forward
if (__back_spare() == 0)
__add_back_capacity();
// __back_capacity >= 1
size_type __de = __base::size() - __pos;
if (__de == 0)
{
__alloc_traits::construct(__a, _VSTD::addressof(*__base::end()), _VSTD::move(__v));
++__base::size();
}
else
{
iterator __e = __base::end();
iterator __em1 = _VSTD::prev(__e);
__alloc_traits::construct(__a, _VSTD::addressof(*__e), _VSTD::move(*__em1));
++__base::size();
if (__de > 1)
__e = _VSTD::move_backward(__e - __de, __em1, __e);
*--__e = _VSTD::move(__v);
}
}
return __base::begin() + __pos;
}
template <class _Tp, class _Allocator>
template <class... _Args>
typename deque<_Tp, _Allocator>::iterator
deque<_Tp, _Allocator>::emplace(const_iterator __p, _Args&&... __args)
{
size_type __pos = __p - __base::begin();
size_type __to_end = __base::size() - __pos;
allocator_type& __a = __base::__alloc();
if (__pos < __to_end)
{ // insert by shifting things backward
if (__front_spare() == 0)
__add_front_capacity();
// __front_spare() >= 1
if (__pos == 0)
{
__alloc_traits::construct(__a, _VSTD::addressof(*--__base::begin()), _VSTD::forward<_Args>(__args)...);
--__base::__start_;
++__base::size();
}
else
{
__temp_value<value_type, _Allocator> __tmp(this->__alloc(), _VSTD::forward<_Args>(__args)...);
iterator __b = __base::begin();
iterator __bm1 = _VSTD::prev(__b);
__alloc_traits::construct(__a, _VSTD::addressof(*__bm1), _VSTD::move(*__b));
--__base::__start_;
++__base::size();
if (__pos > 1)
__b = _VSTD::move(_VSTD::next(__b), __b + __pos, __b);
*__b = _VSTD::move(__tmp.get());
}
}
else
{ // insert by shifting things forward
if (__back_spare() == 0)
__add_back_capacity();
// __back_capacity >= 1
size_type __de = __base::size() - __pos;
if (__de == 0)
{
__alloc_traits::construct(__a, _VSTD::addressof(*__base::end()), _VSTD::forward<_Args>(__args)...);
++__base::size();
}
else
{
__temp_value<value_type, _Allocator> __tmp(this->__alloc(), _VSTD::forward<_Args>(__args)...);
iterator __e = __base::end();
iterator __em1 = _VSTD::prev(__e);
__alloc_traits::construct(__a, _VSTD::addressof(*__e), _VSTD::move(*__em1));
++__base::size();
if (__de > 1)
__e = _VSTD::move_backward(__e - __de, __em1, __e);
*--__e = _VSTD::move(__tmp.get());
}
}
return __base::begin() + __pos;
}
#endif // _LIBCPP_CXX03_LANG
template <class _Tp, class _Allocator>
typename deque<_Tp, _Allocator>::iterator
deque<_Tp, _Allocator>::insert(const_iterator __p, const value_type& __v)
{
size_type __pos = __p - __base::begin();
size_type __to_end = __base::size() - __pos;
allocator_type& __a = __base::__alloc();
if (__pos < __to_end)
{ // insert by shifting things backward
if (__front_spare() == 0)
__add_front_capacity();
// __front_spare() >= 1
if (__pos == 0)
{
__alloc_traits::construct(__a, _VSTD::addressof(*--__base::begin()), __v);
--__base::__start_;
++__base::size();
}
else
{
const_pointer __vt = pointer_traits<const_pointer>::pointer_to(__v);
iterator __b = __base::begin();
iterator __bm1 = _VSTD::prev(__b);
if (__vt == pointer_traits<const_pointer>::pointer_to(*__b))
__vt = pointer_traits<const_pointer>::pointer_to(*__bm1);
__alloc_traits::construct(__a, _VSTD::addressof(*__bm1), _VSTD::move(*__b));
--__base::__start_;
++__base::size();
if (__pos > 1)
__b = __move_and_check(_VSTD::next(__b), __b + __pos, __b, __vt);
*__b = *__vt;
}
}
else
{ // insert by shifting things forward
if (__back_spare() == 0)
__add_back_capacity();
// __back_capacity >= 1
size_type __de = __base::size() - __pos;
if (__de == 0)
{
__alloc_traits::construct(__a, _VSTD::addressof(*__base::end()), __v);
++__base::size();
}
else
{
const_pointer __vt = pointer_traits<const_pointer>::pointer_to(__v);
iterator __e = __base::end();
iterator __em1 = _VSTD::prev(__e);
if (__vt == pointer_traits<const_pointer>::pointer_to(*__em1))
__vt = pointer_traits<const_pointer>::pointer_to(*__e);
__alloc_traits::construct(__a, _VSTD::addressof(*__e), _VSTD::move(*__em1));
++__base::size();
if (__de > 1)
__e = __move_backward_and_check(__e - __de, __em1, __e, __vt);
*--__e = *__vt;
}
}
return __base::begin() + __pos;
}
template <class _Tp, class _Allocator>
typename deque<_Tp, _Allocator>::iterator
deque<_Tp, _Allocator>::insert(const_iterator __p, size_type __n, const value_type& __v)
{
size_type __pos = __p - __base::begin();
size_type __to_end = __base::size() - __pos;
allocator_type& __a = __base::__alloc();
if (__pos < __to_end)
{ // insert by shifting things backward
if (__n > __front_spare())
__add_front_capacity(__n - __front_spare());
// __n <= __front_spare()
iterator __old_begin = __base::begin();
iterator __i = __old_begin;
if (__n > __pos)
{
for (size_type __m = __n - __pos; __m; --__m, --__base::__start_, ++__base::size())
__alloc_traits::construct(__a, _VSTD::addressof(*--__i), __v);
__n = __pos;
}
if (__n > 0)
{
const_pointer __vt = pointer_traits<const_pointer>::pointer_to(__v);
iterator __obn = __old_begin + __n;
__move_construct_backward_and_check(__old_begin, __obn, __i, __vt);
if (__n < __pos)
__old_begin = __move_and_check(__obn, __old_begin + __pos, __old_begin, __vt);
_VSTD::fill_n(__old_begin, __n, *__vt);
}
}
else
{ // insert by shifting things forward
size_type __back_capacity = __back_spare();
if (__n > __back_capacity)
__add_back_capacity(__n - __back_capacity);
// __n <= __back_capacity
iterator __old_end = __base::end();
iterator __i = __old_end;
size_type __de = __base::size() - __pos;
if (__n > __de)
{
for (size_type __m = __n - __de; __m; --__m, ++__i, ++__base::size())
__alloc_traits::construct(__a, _VSTD::addressof(*__i), __v);
__n = __de;
}
if (__n > 0)
{
const_pointer __vt = pointer_traits<const_pointer>::pointer_to(__v);
iterator __oen = __old_end - __n;
__move_construct_and_check(__oen, __old_end, __i, __vt);
if (__n < __de)
__old_end = __move_backward_and_check(__old_end - __de, __oen, __old_end, __vt);
_VSTD::fill_n(__old_end - __n, __n, *__vt);
}
}
return __base::begin() + __pos;
}
template <class _Tp, class _Allocator>
template <class _InputIter>
typename deque<_Tp, _Allocator>::iterator
deque<_Tp, _Allocator>::insert(const_iterator __p, _InputIter __f, _InputIter __l,
typename enable_if<__is_input_iterator<_InputIter>::value
&&!__is_forward_iterator<_InputIter>::value>::type*)
{
__split_buffer<value_type, allocator_type&> __buf(__base::__alloc());
__buf.__construct_at_end(__f, __l);
typedef typename __split_buffer<value_type, allocator_type&>::iterator __bi;
return insert(__p, move_iterator<__bi>(__buf.begin()), move_iterator<__bi>(__buf.end()));
}
template <class _Tp, class _Allocator>
template <class _ForwardIterator>
typename deque<_Tp, _Allocator>::iterator
deque<_Tp, _Allocator>::insert(const_iterator __p, _ForwardIterator __f, _ForwardIterator __l,
typename enable_if<__is_forward_iterator<_ForwardIterator>::value
&&!__is_bidirectional_iterator<_ForwardIterator>::value>::type*)
{
size_type __n = _VSTD::distance(__f, __l);
__split_buffer<value_type, allocator_type&> __buf(__n, 0, __base::__alloc());
__buf.__construct_at_end(__f, __l);
typedef typename __split_buffer<value_type, allocator_type&>::iterator __fwd;
return insert(__p, move_iterator<__fwd>(__buf.begin()), move_iterator<__fwd>(__buf.end()));
}
template <class _Tp, class _Allocator>
template <class _BiIter>
typename deque<_Tp, _Allocator>::iterator
deque<_Tp, _Allocator>::insert(const_iterator __p, _BiIter __f, _BiIter __l,
typename enable_if<__is_bidirectional_iterator<_BiIter>::value>::type*)
{
size_type __n = _VSTD::distance(__f, __l);
size_type __pos = __p - __base::begin();
size_type __to_end = __base::size() - __pos;
allocator_type& __a = __base::__alloc();
if (__pos < __to_end)
{ // insert by shifting things backward
if (__n > __front_spare())
__add_front_capacity(__n - __front_spare());
// __n <= __front_spare()
iterator __old_begin = __base::begin();
iterator __i = __old_begin;
_BiIter __m = __f;
if (__n > __pos)
{
__m = __pos < __n / 2 ? _VSTD::prev(__l, __pos) : _VSTD::next(__f, __n - __pos);
for (_BiIter __j = __m; __j != __f; --__base::__start_, ++__base::size())
__alloc_traits::construct(__a, _VSTD::addressof(*--__i), *--__j);
__n = __pos;
}
if (__n > 0)
{
iterator __obn = __old_begin + __n;
for (iterator __j = __obn; __j != __old_begin;)
{
__alloc_traits::construct(__a, _VSTD::addressof(*--__i), _VSTD::move(*--__j));
--__base::__start_;
++__base::size();
}
if (__n < __pos)
__old_begin = _VSTD::move(__obn, __old_begin + __pos, __old_begin);
_VSTD::copy(__m, __l, __old_begin);
}
}
else
{ // insert by shifting things forward
size_type __back_capacity = __back_spare();
if (__n > __back_capacity)
__add_back_capacity(__n - __back_capacity);
// __n <= __back_capacity
iterator __old_end = __base::end();
iterator __i = __old_end;
_BiIter __m = __l;
size_type __de = __base::size() - __pos;
if (__n > __de)
{
__m = __de < __n / 2 ? _VSTD::next(__f, __de) : _VSTD::prev(__l, __n - __de);
for (_BiIter __j = __m; __j != __l; ++__i, (void) ++__j, ++__base::size())
__alloc_traits::construct(__a, _VSTD::addressof(*__i), *__j);
__n = __de;
}
if (__n > 0)
{
iterator __oen = __old_end - __n;
for (iterator __j = __oen; __j != __old_end; ++__i, ++__j, ++__base::size())
__alloc_traits::construct(__a, _VSTD::addressof(*__i), _VSTD::move(*__j));
if (__n < __de)
__old_end = _VSTD::move_backward(__old_end - __de, __oen, __old_end);
_VSTD::copy_backward(__f, __m, __old_end);
}
}
return __base::begin() + __pos;
}
template <class _Tp, class _Allocator>
template <class _InpIter>
void
deque<_Tp, _Allocator>::__append(_InpIter __f, _InpIter __l,
typename enable_if<__is_input_iterator<_InpIter>::value &&
!__is_forward_iterator<_InpIter>::value>::type*)
{
for (; __f != __l; ++__f)
#ifdef _LIBCPP_CXX03_LANG
push_back(*__f);
#else
emplace_back(*__f);
#endif
}
template <class _Tp, class _Allocator>
template <class _ForIter>
void
deque<_Tp, _Allocator>::__append(_ForIter __f, _ForIter __l,
typename enable_if<__is_forward_iterator<_ForIter>::value>::type*)
{
size_type __n = _VSTD::distance(__f, __l);
allocator_type& __a = __base::__alloc();
size_type __back_capacity = __back_spare();
if (__n > __back_capacity)
__add_back_capacity(__n - __back_capacity);
// __n <= __back_capacity
for (__deque_block_range __br : __deque_range(__base::end(), __base::end() + __n)) {
_ConstructTransaction __tx(this, __br);
for (; __tx.__pos_ != __tx.__end_; ++__tx.__pos_, (void)++__f) {
__alloc_traits::construct(__a, std::__to_raw_pointer(__tx.__pos_), *__f);
}
}
}
template <class _Tp, class _Allocator>
void
deque<_Tp, _Allocator>::__append(size_type __n)
{
allocator_type& __a = __base::__alloc();
size_type __back_capacity = __back_spare();
if (__n > __back_capacity)
__add_back_capacity(__n - __back_capacity);
// __n <= __back_capacity
for (__deque_block_range __br : __deque_range(__base::end(), __base::end() + __n)) {
_ConstructTransaction __tx(this, __br);
for (; __tx.__pos_ != __tx.__end_; ++__tx.__pos_) {
__alloc_traits::construct(__a, std::__to_raw_pointer(__tx.__pos_));
}
}
}
template <class _Tp, class _Allocator>
void
deque<_Tp, _Allocator>::__append(size_type __n, const value_type& __v)
{
allocator_type& __a = __base::__alloc();
size_type __back_capacity = __back_spare();
if (__n > __back_capacity)
__add_back_capacity(__n - __back_capacity);
// __n <= __back_capacity
for (__deque_block_range __br : __deque_range(__base::end(), __base::end() + __n)) {
_ConstructTransaction __tx(this, __br);
for (; __tx.__pos_ != __tx.__end_; ++__tx.__pos_) {
__alloc_traits::construct(__a, std::__to_raw_pointer(__tx.__pos_), __v);
}
}
}
// Create front capacity for one block of elements.
// Strong guarantee. Either do it or don't touch anything.
template <class _Tp, class _Allocator>
void
deque<_Tp, _Allocator>::__add_front_capacity()
{
allocator_type& __a = __base::__alloc();
if (__back_spare() >= __base::__block_size)
{
__base::__start_ += __base::__block_size;
pointer __pt = __base::__map_.back();
__base::__map_.pop_back();
__base::__map_.push_front(__pt);
}
// Else if __base::__map_.size() < __base::__map_.capacity() then we need to allocate 1 buffer
else if (__base::__map_.size() < __base::__map_.capacity())
{ // we can put the new buffer into the map, but don't shift things around
// until all buffers are allocated. If we throw, we don't need to fix
// anything up (any added buffers are undetectible)
if (__base::__map_.__front_spare() > 0)
__base::__map_.push_front(__alloc_traits::allocate(__a, __base::__block_size));
else
{
__base::__map_.push_back(__alloc_traits::allocate(__a, __base::__block_size));
// Done allocating, reorder capacity
pointer __pt = __base::__map_.back();
__base::__map_.pop_back();
__base::__map_.push_front(__pt);
}
__base::__start_ = __base::__map_.size() == 1 ?
__base::__block_size / 2 :
__base::__start_ + __base::__block_size;
}
// Else need to allocate 1 buffer, *and* we need to reallocate __map_.
else
{
__split_buffer<pointer, typename __base::__pointer_allocator&>
__buf(max<size_type>(2 * __base::__map_.capacity(), 1),
0, __base::__map_.__alloc());
typedef __allocator_destructor<_Allocator> _Dp;
unique_ptr<pointer, _Dp> __hold(
__alloc_traits::allocate(__a, __base::__block_size),
_Dp(__a, __base::__block_size));
__buf.push_back(__hold.get());
__hold.release();
for (typename __base::__map_pointer __i = __base::__map_.begin();
__i != __base::__map_.end(); ++__i)
__buf.push_back(*__i);
_VSTD::swap(__base::__map_.__first_, __buf.__first_);
_VSTD::swap(__base::__map_.__begin_, __buf.__begin_);
_VSTD::swap(__base::__map_.__end_, __buf.__end_);
_VSTD::swap(__base::__map_.__end_cap(), __buf.__end_cap());
__base::__start_ = __base::__map_.size() == 1 ?
__base::__block_size / 2 :
__base::__start_ + __base::__block_size;
}
}
// Create front capacity for __n elements.
// Strong guarantee. Either do it or don't touch anything.
template <class _Tp, class _Allocator>
void
deque<_Tp, _Allocator>::__add_front_capacity(size_type __n)
{
allocator_type& __a = __base::__alloc();
size_type __nb = __recommend_blocks(__n + __base::__map_.empty());
// Number of unused blocks at back:
size_type __back_capacity = __back_spare() / __base::__block_size;
__back_capacity = _VSTD::min(__back_capacity, __nb); // don't take more than you need
__nb -= __back_capacity; // number of blocks need to allocate
// If __nb == 0, then we have sufficient capacity.
if (__nb == 0)
{
__base::__start_ += __base::__block_size * __back_capacity;
for (; __back_capacity > 0; --__back_capacity)
{
pointer __pt = __base::__map_.back();
__base::__map_.pop_back();
__base::__map_.push_front(__pt);
}
}
// Else if __nb <= __map_.capacity() - __map_.size() then we need to allocate __nb buffers
else if (__nb <= __base::__map_.capacity() - __base::__map_.size())
{ // we can put the new buffers into the map, but don't shift things around
// until all buffers are allocated. If we throw, we don't need to fix
// anything up (any added buffers are undetectible)
for (; __nb > 0; --__nb, __base::__start_ += __base::__block_size - (__base::__map_.size() == 1))
{
if (__base::__map_.__front_spare() == 0)
break;
__base::__map_.push_front(__alloc_traits::allocate(__a, __base::__block_size));
}
for (; __nb > 0; --__nb, ++__back_capacity)
__base::__map_.push_back(__alloc_traits::allocate(__a, __base::__block_size));
// Done allocating, reorder capacity
__base::__start_ += __back_capacity * __base::__block_size;
for (; __back_capacity > 0; --__back_capacity)
{
pointer __pt = __base::__map_.back();
__base::__map_.pop_back();
__base::__map_.push_front(__pt);
}
}
// Else need to allocate __nb buffers, *and* we need to reallocate __map_.
else
{
size_type __ds = (__nb + __back_capacity) * __base::__block_size - __base::__map_.empty();
__split_buffer<pointer, typename __base::__pointer_allocator&>
__buf(max<size_type>(2* __base::__map_.capacity(),
__nb + __base::__map_.size()),
0, __base::__map_.__alloc());
#ifndef _LIBCPP_NO_EXCEPTIONS
try
{
#endif // _LIBCPP_NO_EXCEPTIONS
for (; __nb > 0; --__nb)
__buf.push_back(__alloc_traits::allocate(__a, __base::__block_size));
#ifndef _LIBCPP_NO_EXCEPTIONS
}
catch (...)
{
for (typename __base::__map_pointer __i = __buf.begin();
__i != __buf.end(); ++__i)
__alloc_traits::deallocate(__a, *__i, __base::__block_size);
throw;
}
#endif // _LIBCPP_NO_EXCEPTIONS
for (; __back_capacity > 0; --__back_capacity)
{
__buf.push_back(__base::__map_.back());
__base::__map_.pop_back();
}
for (typename __base::__map_pointer __i = __base::__map_.begin();
__i != __base::__map_.end(); ++__i)
__buf.push_back(*__i);
_VSTD::swap(__base::__map_.__first_, __buf.__first_);
_VSTD::swap(__base::__map_.__begin_, __buf.__begin_);
_VSTD::swap(__base::__map_.__end_, __buf.__end_);
_VSTD::swap(__base::__map_.__end_cap(), __buf.__end_cap());
__base::__start_ += __ds;
}
}
// Create back capacity for one block of elements.
// Strong guarantee. Either do it or don't touch anything.
template <class _Tp, class _Allocator>
void
deque<_Tp, _Allocator>::__add_back_capacity()
{
allocator_type& __a = __base::__alloc();
if (__front_spare() >= __base::__block_size)
{
__base::__start_ -= __base::__block_size;
pointer __pt = __base::__map_.front();
__base::__map_.pop_front();
__base::__map_.push_back(__pt);
}
// Else if __nb <= __map_.capacity() - __map_.size() then we need to allocate __nb buffers
else if (__base::__map_.size() < __base::__map_.capacity())
{ // we can put the new buffer into the map, but don't shift things around
// until it is allocated. If we throw, we don't need to fix
// anything up (any added buffers are undetectible)
if (__base::__map_.__back_spare() != 0)
__base::__map_.push_back(__alloc_traits::allocate(__a, __base::__block_size));
else
{
__base::__map_.push_front(__alloc_traits::allocate(__a, __base::__block_size));
// Done allocating, reorder capacity
pointer __pt = __base::__map_.front();
__base::__map_.pop_front();
__base::__map_.push_back(__pt);
}
}
// Else need to allocate 1 buffer, *and* we need to reallocate __map_.
else
{
__split_buffer<pointer, typename __base::__pointer_allocator&>
__buf(max<size_type>(2* __base::__map_.capacity(), 1),
__base::__map_.size(),
__base::__map_.__alloc());
typedef __allocator_destructor<_Allocator> _Dp;
unique_ptr<pointer, _Dp> __hold(
__alloc_traits::allocate(__a, __base::__block_size),
_Dp(__a, __base::__block_size));
__buf.push_back(__hold.get());
__hold.release();
for (typename __base::__map_pointer __i = __base::__map_.end();
__i != __base::__map_.begin();)
__buf.push_front(*--__i);
_VSTD::swap(__base::__map_.__first_, __buf.__first_);
_VSTD::swap(__base::__map_.__begin_, __buf.__begin_);
_VSTD::swap(__base::__map_.__end_, __buf.__end_);
_VSTD::swap(__base::__map_.__end_cap(), __buf.__end_cap());
}
}
// Create back capacity for __n elements.
// Strong guarantee. Either do it or don't touch anything.
template <class _Tp, class _Allocator>
void
deque<_Tp, _Allocator>::__add_back_capacity(size_type __n)
{
allocator_type& __a = __base::__alloc();
size_type __nb = __recommend_blocks(__n + __base::__map_.empty());
// Number of unused blocks at front:
size_type __front_capacity = __front_spare() / __base::__block_size;
__front_capacity = _VSTD::min(__front_capacity, __nb); // don't take more than you need
__nb -= __front_capacity; // number of blocks need to allocate
// If __nb == 0, then we have sufficient capacity.
if (__nb == 0)
{
__base::__start_ -= __base::__block_size * __front_capacity;
for (; __front_capacity > 0; --__front_capacity)
{
pointer __pt = __base::__map_.front();
__base::__map_.pop_front();
__base::__map_.push_back(__pt);
}
}
// Else if __nb <= __map_.capacity() - __map_.size() then we need to allocate __nb buffers
else if (__nb <= __base::__map_.capacity() - __base::__map_.size())
{ // we can put the new buffers into the map, but don't shift things around
// until all buffers are allocated. If we throw, we don't need to fix
// anything up (any added buffers are undetectible)
for (; __nb > 0; --__nb)
{
if (__base::__map_.__back_spare() == 0)
break;
__base::__map_.push_back(__alloc_traits::allocate(__a, __base::__block_size));
}
for (; __nb > 0; --__nb, ++__front_capacity, __base::__start_ +=
__base::__block_size - (__base::__map_.size() == 1))
__base::__map_.push_front(__alloc_traits::allocate(__a, __base::__block_size));
// Done allocating, reorder capacity
__base::__start_ -= __base::__block_size * __front_capacity;
for (; __front_capacity > 0; --__front_capacity)
{
pointer __pt = __base::__map_.front();
__base::__map_.pop_front();
__base::__map_.push_back(__pt);
}
}
// Else need to allocate __nb buffers, *and* we need to reallocate __map_.
else
{
size_type __ds = __front_capacity * __base::__block_size;
__split_buffer<pointer, typename __base::__pointer_allocator&>
__buf(max<size_type>(2* __base::__map_.capacity(),
__nb + __base::__map_.size()),
__base::__map_.size() - __front_capacity,
__base::__map_.__alloc());
#ifndef _LIBCPP_NO_EXCEPTIONS
try
{
#endif // _LIBCPP_NO_EXCEPTIONS
for (; __nb > 0; --__nb)
__buf.push_back(__alloc_traits::allocate(__a, __base::__block_size));
#ifndef _LIBCPP_NO_EXCEPTIONS
}
catch (...)
{
for (typename __base::__map_pointer __i = __buf.begin();
__i != __buf.end(); ++__i)
__alloc_traits::deallocate(__a, *__i, __base::__block_size);
throw;
}
#endif // _LIBCPP_NO_EXCEPTIONS
for (; __front_capacity > 0; --__front_capacity)
{
__buf.push_back(__base::__map_.front());
__base::__map_.pop_front();
}
for (typename __base::__map_pointer __i = __base::__map_.end();
__i != __base::__map_.begin();)
__buf.push_front(*--__i);
_VSTD::swap(__base::__map_.__first_, __buf.__first_);
_VSTD::swap(__base::__map_.__begin_, __buf.__begin_);
_VSTD::swap(__base::__map_.__end_, __buf.__end_);
_VSTD::swap(__base::__map_.__end_cap(), __buf.__end_cap());
__base::__start_ -= __ds;
}
}
template <class _Tp, class _Allocator>
void
deque<_Tp, _Allocator>::pop_front()
{
allocator_type& __a = __base::__alloc();
__alloc_traits::destroy(__a, __to_raw_pointer(*(__base::__map_.begin() +
__base::__start_ / __base::__block_size) +
__base::__start_ % __base::__block_size));
--__base::size();
++__base::__start_;
__maybe_remove_front_spare();
}
template <class _Tp, class _Allocator>
void
deque<_Tp, _Allocator>::pop_back()
{
_LIBCPP_ASSERT(!empty(), "deque::pop_back called for empty deque");
allocator_type& __a = __base::__alloc();
size_type __p = __base::size() + __base::__start_ - 1;
__alloc_traits::destroy(__a, __to_raw_pointer(*(__base::__map_.begin() +
__p / __base::__block_size) +
__p % __base::__block_size));
--__base::size();
__maybe_remove_back_spare();
}
// move assign [__f, __l) to [__r, __r + (__l-__f)).
// If __vt points into [__f, __l), then subtract (__f - __r) from __vt.
template <class _Tp, class _Allocator>
typename deque<_Tp, _Allocator>::iterator
deque<_Tp, _Allocator>::__move_and_check(iterator __f, iterator __l, iterator __r,
const_pointer& __vt)
{
// as if
// for (; __f != __l; ++__f, ++__r)
// *__r = _VSTD::move(*__f);
difference_type __n = __l - __f;
while (__n > 0)
{
pointer __fb = __f.__ptr_;
pointer __fe = *__f.__m_iter_ + __base::__block_size;
difference_type __bs = __fe - __fb;
if (__bs > __n)
{
__bs = __n;
__fe = __fb + __bs;
}
if (__fb <= __vt && __vt < __fe)
__vt = (const_iterator(static_cast<__map_const_pointer>(__f.__m_iter_), __vt) -= __f - __r).__ptr_;
__r = _VSTD::move(__fb, __fe, __r);
__n -= __bs;
__f += __bs;
}
return __r;
}
// move assign [__f, __l) to [__r - (__l-__f), __r) backwards.
// If __vt points into [__f, __l), then add (__r - __l) to __vt.
template <class _Tp, class _Allocator>
typename deque<_Tp, _Allocator>::iterator
deque<_Tp, _Allocator>::__move_backward_and_check(iterator __f, iterator __l, iterator __r,
const_pointer& __vt)
{
// as if
// while (__f != __l)
// *--__r = _VSTD::move(*--__l);
difference_type __n = __l - __f;
while (__n > 0)
{
--__l;
pointer __lb = *__l.__m_iter_;
pointer __le = __l.__ptr_ + 1;
difference_type __bs = __le - __lb;
if (__bs > __n)
{
__bs = __n;
__lb = __le - __bs;
}
if (__lb <= __vt && __vt < __le)
__vt = (const_iterator(static_cast<__map_const_pointer>(__l.__m_iter_), __vt) += __r - __l - 1).__ptr_;
__r = _VSTD::move_backward(__lb, __le, __r);
__n -= __bs;
__l -= __bs - 1;
}
return __r;
}
// move construct [__f, __l) to [__r, __r + (__l-__f)).
// If __vt points into [__f, __l), then add (__r - __f) to __vt.
template <class _Tp, class _Allocator>
void
deque<_Tp, _Allocator>::__move_construct_and_check(iterator __f, iterator __l,
iterator __r, const_pointer& __vt)
{
allocator_type& __a = __base::__alloc();
// as if
// for (; __f != __l; ++__r, ++__f, ++__base::size())
// __alloc_traits::construct(__a, _VSTD::addressof(*__r), _VSTD::move(*__f));
difference_type __n = __l - __f;
while (__n > 0)
{
pointer __fb = __f.__ptr_;
pointer __fe = *__f.__m_iter_ + __base::__block_size;
difference_type __bs = __fe - __fb;
if (__bs > __n)
{
__bs = __n;
__fe = __fb + __bs;
}
if (__fb <= __vt && __vt < __fe)
__vt = (const_iterator(static_cast<__map_const_pointer>(__f.__m_iter_), __vt) += __r - __f).__ptr_;
for (; __fb != __fe; ++__fb, ++__r, ++__base::size())
__alloc_traits::construct(__a, _VSTD::addressof(*__r), _VSTD::move(*__fb));
__n -= __bs;
__f += __bs;
}
}
// move construct [__f, __l) to [__r - (__l-__f), __r) backwards.
// If __vt points into [__f, __l), then subtract (__l - __r) from __vt.
template <class _Tp, class _Allocator>
void
deque<_Tp, _Allocator>::__move_construct_backward_and_check(iterator __f, iterator __l,
iterator __r, const_pointer& __vt)
{
allocator_type& __a = __base::__alloc();
// as if
// for (iterator __j = __l; __j != __f;)
// {
// __alloc_traitsconstruct(__a, _VSTD::addressof(*--__r), _VSTD::move(*--__j));
// --__base::__start_;
// ++__base::size();
// }
difference_type __n = __l - __f;
while (__n > 0)
{
--__l;
pointer __lb = *__l.__m_iter_;
pointer __le = __l.__ptr_ + 1;
difference_type __bs = __le - __lb;
if (__bs > __n)
{
__bs = __n;
__lb = __le - __bs;
}
if (__lb <= __vt && __vt < __le)
__vt = (const_iterator(static_cast<__map_const_pointer>(__l.__m_iter_), __vt) -= __l - __r + 1).__ptr_;
while (__le != __lb)
{
__alloc_traits::construct(__a, _VSTD::addressof(*--__r), _VSTD::move(*--__le));
--__base::__start_;
++__base::size();
}
__n -= __bs;
__l -= __bs - 1;
}
}
template <class _Tp, class _Allocator>
typename deque<_Tp, _Allocator>::iterator
deque<_Tp, _Allocator>::erase(const_iterator __f)
{
iterator __b = __base::begin();
difference_type __pos = __f - __b;
iterator __p = __b + __pos;
allocator_type& __a = __base::__alloc();
if (static_cast<size_t>(__pos) <= (__base::size() - 1) / 2)
{ // erase from front
_VSTD::move_backward(__b, __p, _VSTD::next(__p));
__alloc_traits::destroy(__a, _VSTD::addressof(*__b));
--__base::size();
++__base::__start_;
__maybe_remove_front_spare();
}
else
{ // erase from back
iterator __i = _VSTD::move(_VSTD::next(__p), __base::end(), __p);
__alloc_traits::destroy(__a, _VSTD::addressof(*__i));
--__base::size();
__maybe_remove_back_spare();
}
return __base::begin() + __pos;
}
template <class _Tp, class _Allocator>
typename deque<_Tp, _Allocator>::iterator
deque<_Tp, _Allocator>::erase(const_iterator __f, const_iterator __l)
{
difference_type __n = __l - __f;
iterator __b = __base::begin();
difference_type __pos = __f - __b;
iterator __p = __b + __pos;
if (__n > 0)
{
allocator_type& __a = __base::__alloc();
if (static_cast<size_t>(__pos) <= (__base::size() - __n) / 2)
{ // erase from front
iterator __i = _VSTD::move_backward(__b, __p, __p + __n);
for (; __b != __i; ++__b)
__alloc_traits::destroy(__a, _VSTD::addressof(*__b));
__base::size() -= __n;
__base::__start_ += __n;
while (__maybe_remove_front_spare()) {
}
}
else
{ // erase from back
iterator __i = _VSTD::move(__p + __n, __base::end(), __p);
for (iterator __e = __base::end(); __i != __e; ++__i)
__alloc_traits::destroy(__a, _VSTD::addressof(*__i));
__base::size() -= __n;
while (__maybe_remove_back_spare()) {
}
}
}
return __base::begin() + __pos;
}
template <class _Tp, class _Allocator>
void
deque<_Tp, _Allocator>::__erase_to_end(const_iterator __f)
{
iterator __e = __base::end();
difference_type __n = __e - __f;
if (__n > 0)
{
allocator_type& __a = __base::__alloc();
iterator __b = __base::begin();
difference_type __pos = __f - __b;
for (iterator __p = __b + __pos; __p != __e; ++__p)
__alloc_traits::destroy(__a, _VSTD::addressof(*__p));
__base::size() -= __n;
while (__maybe_remove_back_spare()) {
}
}
}
template <class _Tp, class _Allocator>
inline
void
deque<_Tp, _Allocator>::swap(deque& __c)
#if _LIBCPP_STD_VER >= 14
_NOEXCEPT
#else
_NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value ||
__is_nothrow_swappable<allocator_type>::value)
#endif
{
__base::swap(__c);
}
template <class _Tp, class _Allocator>
inline
void
deque<_Tp, _Allocator>::clear() _NOEXCEPT
{
__base::clear();
}
template <class _Tp, class _Allocator>
inline _LIBCPP_INLINE_VISIBILITY
bool
operator==(const deque<_Tp, _Allocator>& __x, const deque<_Tp, _Allocator>& __y)
{
const typename deque<_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 deque<_Tp, _Allocator>& __x, const deque<_Tp, _Allocator>& __y)
{
return !(__x == __y);
}
template <class _Tp, class _Allocator>
inline _LIBCPP_INLINE_VISIBILITY
bool
operator< (const deque<_Tp, _Allocator>& __x, const deque<_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 deque<_Tp, _Allocator>& __x, const deque<_Tp, _Allocator>& __y)
{
return __y < __x;
}
template <class _Tp, class _Allocator>
inline _LIBCPP_INLINE_VISIBILITY
bool
operator>=(const deque<_Tp, _Allocator>& __x, const deque<_Tp, _Allocator>& __y)
{
return !(__x < __y);
}
template <class _Tp, class _Allocator>
inline _LIBCPP_INLINE_VISIBILITY
bool
operator<=(const deque<_Tp, _Allocator>& __x, const deque<_Tp, _Allocator>& __y)
{
return !(__y < __x);
}
template <class _Tp, class _Allocator>
inline _LIBCPP_INLINE_VISIBILITY
void
swap(deque<_Tp, _Allocator>& __x, deque<_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(deque<_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(deque<_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_DEQUE
| 108,540 | 3,039 | jart/cosmopolitan | false |
cosmopolitan/third_party/libcxx/limits | // -*- C++ -*-
//===---------------------------- limits ----------------------------------===//
//
// 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_LIMITS
#define _LIBCPP_LIMITS
#include "third_party/libcxx/__config"
#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"
#include "third_party/libcxx/version"
_LIBCPP_BEGIN_NAMESPACE_STD
/*
limits synopsis
namespace std
{
template<class T>
class numeric_limits
{
public:
static constexpr bool is_specialized = false;
static constexpr T min() noexcept;
static constexpr T max() noexcept;
static constexpr T lowest() noexcept;
static constexpr int digits = 0;
static constexpr int digits10 = 0;
static constexpr int max_digits10 = 0;
static constexpr bool is_signed = false;
static constexpr bool is_integer = false;
static constexpr bool is_exact = false;
static constexpr int radix = 0;
static constexpr T epsilon() noexcept;
static constexpr T round_error() noexcept;
static constexpr int min_exponent = 0;
static constexpr int min_exponent10 = 0;
static constexpr int max_exponent = 0;
static constexpr int max_exponent10 = 0;
static constexpr bool has_infinity = false;
static constexpr bool has_quiet_NaN = false;
static constexpr bool has_signaling_NaN = false;
static constexpr float_denorm_style has_denorm = denorm_absent;
static constexpr bool has_denorm_loss = false;
static constexpr T infinity() noexcept;
static constexpr T quiet_NaN() noexcept;
static constexpr T signaling_NaN() noexcept;
static constexpr T denorm_min() noexcept;
static constexpr bool is_iec559 = false;
static constexpr bool is_bounded = false;
static constexpr bool is_modulo = false;
static constexpr bool traps = false;
static constexpr bool tinyness_before = false;
static constexpr float_round_style round_style = round_toward_zero;
};
enum float_round_style
{
round_indeterminate = -1,
round_toward_zero = 0,
round_to_nearest = 1,
round_toward_infinity = 2,
round_toward_neg_infinity = 3
};
enum float_denorm_style
{
denorm_indeterminate = -1,
denorm_absent = 0,
denorm_present = 1
};
template<> class numeric_limits<cv bool>;
template<> class numeric_limits<cv char>;
template<> class numeric_limits<cv signed char>;
template<> class numeric_limits<cv unsigned char>;
template<> class numeric_limits<cv wchar_t>;
template<> class numeric_limits<cv char8_t>; // C++20
template<> class numeric_limits<cv char16_t>;
template<> class numeric_limits<cv char32_t>;
template<> class numeric_limits<cv short>;
template<> class numeric_limits<cv int>;
template<> class numeric_limits<cv long>;
template<> class numeric_limits<cv long long>;
template<> class numeric_limits<cv unsigned short>;
template<> class numeric_limits<cv unsigned int>;
template<> class numeric_limits<cv unsigned long>;
template<> class numeric_limits<cv unsigned long long>;
template<> class numeric_limits<cv float>;
template<> class numeric_limits<cv double>;
template<> class numeric_limits<cv long double>;
} // std
*/
enum float_round_style
{
round_indeterminate = -1,
round_toward_zero = 0,
round_to_nearest = 1,
round_toward_infinity = 2,
round_toward_neg_infinity = 3
};
enum float_denorm_style
{
denorm_indeterminate = -1,
denorm_absent = 0,
denorm_present = 1
};
template <class _Tp, bool = is_arithmetic<_Tp>::value>
class __libcpp_numeric_limits
{
protected:
typedef _Tp type;
static _LIBCPP_CONSTEXPR const bool is_specialized = false;
_LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR type min() _NOEXCEPT {return type();}
_LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR type max() _NOEXCEPT {return type();}
_LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR type lowest() _NOEXCEPT {return type();}
static _LIBCPP_CONSTEXPR const int digits = 0;
static _LIBCPP_CONSTEXPR const int digits10 = 0;
static _LIBCPP_CONSTEXPR const int max_digits10 = 0;
static _LIBCPP_CONSTEXPR const bool is_signed = false;
static _LIBCPP_CONSTEXPR const bool is_integer = false;
static _LIBCPP_CONSTEXPR const bool is_exact = false;
static _LIBCPP_CONSTEXPR const int radix = 0;
_LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR type epsilon() _NOEXCEPT {return type();}
_LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR type round_error() _NOEXCEPT {return type();}
static _LIBCPP_CONSTEXPR const int min_exponent = 0;
static _LIBCPP_CONSTEXPR const int min_exponent10 = 0;
static _LIBCPP_CONSTEXPR const int max_exponent = 0;
static _LIBCPP_CONSTEXPR const int max_exponent10 = 0;
static _LIBCPP_CONSTEXPR const bool has_infinity = false;
static _LIBCPP_CONSTEXPR const bool has_quiet_NaN = false;
static _LIBCPP_CONSTEXPR const bool has_signaling_NaN = false;
static _LIBCPP_CONSTEXPR const float_denorm_style has_denorm = denorm_absent;
static _LIBCPP_CONSTEXPR const bool has_denorm_loss = false;
_LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR type infinity() _NOEXCEPT {return type();}
_LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR type quiet_NaN() _NOEXCEPT {return type();}
_LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR type signaling_NaN() _NOEXCEPT {return type();}
_LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR type denorm_min() _NOEXCEPT {return type();}
static _LIBCPP_CONSTEXPR const bool is_iec559 = false;
static _LIBCPP_CONSTEXPR const bool is_bounded = false;
static _LIBCPP_CONSTEXPR const bool is_modulo = false;
static _LIBCPP_CONSTEXPR const bool traps = false;
static _LIBCPP_CONSTEXPR const bool tinyness_before = false;
static _LIBCPP_CONSTEXPR const float_round_style round_style = round_toward_zero;
};
template <class _Tp, int __digits, bool _IsSigned>
struct __libcpp_compute_min
{
static _LIBCPP_CONSTEXPR const _Tp value = _Tp(_Tp(1) << __digits);
};
template <class _Tp, int __digits>
struct __libcpp_compute_min<_Tp, __digits, false>
{
static _LIBCPP_CONSTEXPR const _Tp value = _Tp(0);
};
template <class _Tp>
class __libcpp_numeric_limits<_Tp, true>
{
protected:
typedef _Tp type;
static _LIBCPP_CONSTEXPR const bool is_specialized = true;
static _LIBCPP_CONSTEXPR const bool is_signed = type(-1) < type(0);
static _LIBCPP_CONSTEXPR const int digits = static_cast<int>(sizeof(type) * __CHAR_BIT__ - is_signed);
static _LIBCPP_CONSTEXPR const int digits10 = digits * 3 / 10;
static _LIBCPP_CONSTEXPR const int max_digits10 = 0;
static _LIBCPP_CONSTEXPR const type __min = __libcpp_compute_min<type, digits, is_signed>::value;
static _LIBCPP_CONSTEXPR const type __max = is_signed ? type(type(~0) ^ __min) : type(~0);
_LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR type min() _NOEXCEPT {return __min;}
_LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR type max() _NOEXCEPT {return __max;}
_LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR type lowest() _NOEXCEPT {return min();}
static _LIBCPP_CONSTEXPR const bool is_integer = true;
static _LIBCPP_CONSTEXPR const bool is_exact = true;
static _LIBCPP_CONSTEXPR const int radix = 2;
_LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR type epsilon() _NOEXCEPT {return type(0);}
_LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR type round_error() _NOEXCEPT {return type(0);}
static _LIBCPP_CONSTEXPR const int min_exponent = 0;
static _LIBCPP_CONSTEXPR const int min_exponent10 = 0;
static _LIBCPP_CONSTEXPR const int max_exponent = 0;
static _LIBCPP_CONSTEXPR const int max_exponent10 = 0;
static _LIBCPP_CONSTEXPR const bool has_infinity = false;
static _LIBCPP_CONSTEXPR const bool has_quiet_NaN = false;
static _LIBCPP_CONSTEXPR const bool has_signaling_NaN = false;
static _LIBCPP_CONSTEXPR const float_denorm_style has_denorm = denorm_absent;
static _LIBCPP_CONSTEXPR const bool has_denorm_loss = false;
_LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR type infinity() _NOEXCEPT {return type(0);}
_LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR type quiet_NaN() _NOEXCEPT {return type(0);}
_LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR type signaling_NaN() _NOEXCEPT {return type(0);}
_LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR type denorm_min() _NOEXCEPT {return type(0);}
static _LIBCPP_CONSTEXPR const bool is_iec559 = false;
static _LIBCPP_CONSTEXPR const bool is_bounded = true;
static _LIBCPP_CONSTEXPR const bool is_modulo = !_VSTD::is_signed<_Tp>::value;
#if defined(__i386__) || defined(__x86_64__) || defined(__pnacl__) || \
defined(__wasm__)
static _LIBCPP_CONSTEXPR const bool traps = true;
#else
static _LIBCPP_CONSTEXPR const bool traps = false;
#endif
static _LIBCPP_CONSTEXPR const bool tinyness_before = false;
static _LIBCPP_CONSTEXPR const float_round_style round_style = round_toward_zero;
};
template <>
class __libcpp_numeric_limits<bool, true>
{
protected:
typedef bool type;
static _LIBCPP_CONSTEXPR const bool is_specialized = true;
static _LIBCPP_CONSTEXPR const bool is_signed = false;
static _LIBCPP_CONSTEXPR const int digits = 1;
static _LIBCPP_CONSTEXPR const int digits10 = 0;
static _LIBCPP_CONSTEXPR const int max_digits10 = 0;
static _LIBCPP_CONSTEXPR const type __min = false;
static _LIBCPP_CONSTEXPR const type __max = true;
_LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR type min() _NOEXCEPT {return __min;}
_LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR type max() _NOEXCEPT {return __max;}
_LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR type lowest() _NOEXCEPT {return min();}
static _LIBCPP_CONSTEXPR const bool is_integer = true;
static _LIBCPP_CONSTEXPR const bool is_exact = true;
static _LIBCPP_CONSTEXPR const int radix = 2;
_LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR type epsilon() _NOEXCEPT {return type(0);}
_LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR type round_error() _NOEXCEPT {return type(0);}
static _LIBCPP_CONSTEXPR const int min_exponent = 0;
static _LIBCPP_CONSTEXPR const int min_exponent10 = 0;
static _LIBCPP_CONSTEXPR const int max_exponent = 0;
static _LIBCPP_CONSTEXPR const int max_exponent10 = 0;
static _LIBCPP_CONSTEXPR const bool has_infinity = false;
static _LIBCPP_CONSTEXPR const bool has_quiet_NaN = false;
static _LIBCPP_CONSTEXPR const bool has_signaling_NaN = false;
static _LIBCPP_CONSTEXPR const float_denorm_style has_denorm = denorm_absent;
static _LIBCPP_CONSTEXPR const bool has_denorm_loss = false;
_LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR type infinity() _NOEXCEPT {return type(0);}
_LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR type quiet_NaN() _NOEXCEPT {return type(0);}
_LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR type signaling_NaN() _NOEXCEPT {return type(0);}
_LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR type denorm_min() _NOEXCEPT {return type(0);}
static _LIBCPP_CONSTEXPR const bool is_iec559 = false;
static _LIBCPP_CONSTEXPR const bool is_bounded = true;
static _LIBCPP_CONSTEXPR const bool is_modulo = false;
static _LIBCPP_CONSTEXPR const bool traps = false;
static _LIBCPP_CONSTEXPR const bool tinyness_before = false;
static _LIBCPP_CONSTEXPR const float_round_style round_style = round_toward_zero;
};
template <>
class __libcpp_numeric_limits<float, true>
{
protected:
typedef float type;
static _LIBCPP_CONSTEXPR const bool is_specialized = true;
static _LIBCPP_CONSTEXPR const bool is_signed = true;
static _LIBCPP_CONSTEXPR const int digits = __FLT_MANT_DIG__;
static _LIBCPP_CONSTEXPR const int digits10 = __FLT_DIG__;
static _LIBCPP_CONSTEXPR const int max_digits10 = 2+(digits * 30103l)/100000l;
_LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR type min() _NOEXCEPT {return __FLT_MIN__;}
_LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR type max() _NOEXCEPT {return __FLT_MAX__;}
_LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR type lowest() _NOEXCEPT {return -max();}
static _LIBCPP_CONSTEXPR const bool is_integer = false;
static _LIBCPP_CONSTEXPR const bool is_exact = false;
static _LIBCPP_CONSTEXPR const int radix = __FLT_RADIX__;
_LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR type epsilon() _NOEXCEPT {return __FLT_EPSILON__;}
_LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR type round_error() _NOEXCEPT {return 0.5F;}
static _LIBCPP_CONSTEXPR const int min_exponent = __FLT_MIN_EXP__;
static _LIBCPP_CONSTEXPR const int min_exponent10 = __FLT_MIN_10_EXP__;
static _LIBCPP_CONSTEXPR const int max_exponent = __FLT_MAX_EXP__;
static _LIBCPP_CONSTEXPR const int max_exponent10 = __FLT_MAX_10_EXP__;
static _LIBCPP_CONSTEXPR const bool has_infinity = true;
static _LIBCPP_CONSTEXPR const bool has_quiet_NaN = true;
static _LIBCPP_CONSTEXPR const bool has_signaling_NaN = true;
static _LIBCPP_CONSTEXPR const float_denorm_style has_denorm = denorm_present;
static _LIBCPP_CONSTEXPR const bool has_denorm_loss = false;
_LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR type infinity() _NOEXCEPT {return __builtin_huge_valf();}
_LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR type quiet_NaN() _NOEXCEPT {return __builtin_nanf("");}
_LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR type signaling_NaN() _NOEXCEPT {return __builtin_nansf("");}
_LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR type denorm_min() _NOEXCEPT {return __FLT_DENORM_MIN__;}
static _LIBCPP_CONSTEXPR const bool is_iec559 = true;
static _LIBCPP_CONSTEXPR const bool is_bounded = true;
static _LIBCPP_CONSTEXPR const bool is_modulo = false;
static _LIBCPP_CONSTEXPR const bool traps = false;
static _LIBCPP_CONSTEXPR const bool tinyness_before = false;
static _LIBCPP_CONSTEXPR const float_round_style round_style = round_to_nearest;
};
template <>
class __libcpp_numeric_limits<double, true>
{
protected:
typedef double type;
static _LIBCPP_CONSTEXPR const bool is_specialized = true;
static _LIBCPP_CONSTEXPR const bool is_signed = true;
static _LIBCPP_CONSTEXPR const int digits = __DBL_MANT_DIG__;
static _LIBCPP_CONSTEXPR const int digits10 = __DBL_DIG__;
static _LIBCPP_CONSTEXPR const int max_digits10 = 2+(digits * 30103l)/100000l;
_LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR type min() _NOEXCEPT {return __DBL_MIN__;}
_LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR type max() _NOEXCEPT {return __DBL_MAX__;}
_LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR type lowest() _NOEXCEPT {return -max();}
static _LIBCPP_CONSTEXPR const bool is_integer = false;
static _LIBCPP_CONSTEXPR const bool is_exact = false;
static _LIBCPP_CONSTEXPR const int radix = __FLT_RADIX__;
_LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR type epsilon() _NOEXCEPT {return __DBL_EPSILON__;}
_LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR type round_error() _NOEXCEPT {return 0.5;}
static _LIBCPP_CONSTEXPR const int min_exponent = __DBL_MIN_EXP__;
static _LIBCPP_CONSTEXPR const int min_exponent10 = __DBL_MIN_10_EXP__;
static _LIBCPP_CONSTEXPR const int max_exponent = __DBL_MAX_EXP__;
static _LIBCPP_CONSTEXPR const int max_exponent10 = __DBL_MAX_10_EXP__;
static _LIBCPP_CONSTEXPR const bool has_infinity = true;
static _LIBCPP_CONSTEXPR const bool has_quiet_NaN = true;
static _LIBCPP_CONSTEXPR const bool has_signaling_NaN = true;
static _LIBCPP_CONSTEXPR const float_denorm_style has_denorm = denorm_present;
static _LIBCPP_CONSTEXPR const bool has_denorm_loss = false;
_LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR type infinity() _NOEXCEPT {return __builtin_huge_val();}
_LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR type quiet_NaN() _NOEXCEPT {return __builtin_nan("");}
_LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR type signaling_NaN() _NOEXCEPT {return __builtin_nans("");}
_LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR type denorm_min() _NOEXCEPT {return __DBL_DENORM_MIN__;}
static _LIBCPP_CONSTEXPR const bool is_iec559 = true;
static _LIBCPP_CONSTEXPR const bool is_bounded = true;
static _LIBCPP_CONSTEXPR const bool is_modulo = false;
static _LIBCPP_CONSTEXPR const bool traps = false;
static _LIBCPP_CONSTEXPR const bool tinyness_before = false;
static _LIBCPP_CONSTEXPR const float_round_style round_style = round_to_nearest;
};
template <>
class __libcpp_numeric_limits<long double, true>
{
protected:
typedef long double type;
static _LIBCPP_CONSTEXPR const bool is_specialized = true;
static _LIBCPP_CONSTEXPR const bool is_signed = true;
static _LIBCPP_CONSTEXPR const int digits = __LDBL_MANT_DIG__;
static _LIBCPP_CONSTEXPR const int digits10 = __LDBL_DIG__;
static _LIBCPP_CONSTEXPR const int max_digits10 = 2+(digits * 30103l)/100000l;
_LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR type min() _NOEXCEPT {return __LDBL_MIN__;}
_LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR type max() _NOEXCEPT {return __LDBL_MAX__;}
_LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR type lowest() _NOEXCEPT {return -max();}
static _LIBCPP_CONSTEXPR const bool is_integer = false;
static _LIBCPP_CONSTEXPR const bool is_exact = false;
static _LIBCPP_CONSTEXPR const int radix = __FLT_RADIX__;
_LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR type epsilon() _NOEXCEPT {return __LDBL_EPSILON__;}
_LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR type round_error() _NOEXCEPT {return 0.5L;}
static _LIBCPP_CONSTEXPR const int min_exponent = __LDBL_MIN_EXP__;
static _LIBCPP_CONSTEXPR const int min_exponent10 = __LDBL_MIN_10_EXP__;
static _LIBCPP_CONSTEXPR const int max_exponent = __LDBL_MAX_EXP__;
static _LIBCPP_CONSTEXPR const int max_exponent10 = __LDBL_MAX_10_EXP__;
static _LIBCPP_CONSTEXPR const bool has_infinity = true;
static _LIBCPP_CONSTEXPR const bool has_quiet_NaN = true;
static _LIBCPP_CONSTEXPR const bool has_signaling_NaN = true;
static _LIBCPP_CONSTEXPR const float_denorm_style has_denorm = denorm_present;
static _LIBCPP_CONSTEXPR const bool has_denorm_loss = false;
_LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR type infinity() _NOEXCEPT {return __builtin_huge_vall();}
_LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR type quiet_NaN() _NOEXCEPT {return __builtin_nanl("");}
_LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR type signaling_NaN() _NOEXCEPT {return __builtin_nansl("");}
_LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR type denorm_min() _NOEXCEPT {return __LDBL_DENORM_MIN__;}
#if (defined(__ppc__) || defined(__ppc64__))
static _LIBCPP_CONSTEXPR const bool is_iec559 = false;
#else
static _LIBCPP_CONSTEXPR const bool is_iec559 = true;
#endif
static _LIBCPP_CONSTEXPR const bool is_bounded = true;
static _LIBCPP_CONSTEXPR const bool is_modulo = false;
static _LIBCPP_CONSTEXPR const bool traps = false;
static _LIBCPP_CONSTEXPR const bool tinyness_before = false;
static _LIBCPP_CONSTEXPR const float_round_style round_style = round_to_nearest;
};
template <class _Tp>
class _LIBCPP_TEMPLATE_VIS numeric_limits
: private __libcpp_numeric_limits<typename remove_cv<_Tp>::type>
{
typedef __libcpp_numeric_limits<typename remove_cv<_Tp>::type> __base;
typedef typename __base::type type;
public:
static _LIBCPP_CONSTEXPR const bool is_specialized = __base::is_specialized;
_LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR type min() _NOEXCEPT {return __base::min();}
_LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR type max() _NOEXCEPT {return __base::max();}
_LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR type lowest() _NOEXCEPT {return __base::lowest();}
static _LIBCPP_CONSTEXPR const int digits = __base::digits;
static _LIBCPP_CONSTEXPR const int digits10 = __base::digits10;
static _LIBCPP_CONSTEXPR const int max_digits10 = __base::max_digits10;
static _LIBCPP_CONSTEXPR const bool is_signed = __base::is_signed;
static _LIBCPP_CONSTEXPR const bool is_integer = __base::is_integer;
static _LIBCPP_CONSTEXPR const bool is_exact = __base::is_exact;
static _LIBCPP_CONSTEXPR const int radix = __base::radix;
_LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR type epsilon() _NOEXCEPT {return __base::epsilon();}
_LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR type round_error() _NOEXCEPT {return __base::round_error();}
static _LIBCPP_CONSTEXPR const int min_exponent = __base::min_exponent;
static _LIBCPP_CONSTEXPR const int min_exponent10 = __base::min_exponent10;
static _LIBCPP_CONSTEXPR const int max_exponent = __base::max_exponent;
static _LIBCPP_CONSTEXPR const int max_exponent10 = __base::max_exponent10;
static _LIBCPP_CONSTEXPR const bool has_infinity = __base::has_infinity;
static _LIBCPP_CONSTEXPR const bool has_quiet_NaN = __base::has_quiet_NaN;
static _LIBCPP_CONSTEXPR const bool has_signaling_NaN = __base::has_signaling_NaN;
static _LIBCPP_CONSTEXPR const float_denorm_style has_denorm = __base::has_denorm;
static _LIBCPP_CONSTEXPR const bool has_denorm_loss = __base::has_denorm_loss;
_LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR type infinity() _NOEXCEPT {return __base::infinity();}
_LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR type quiet_NaN() _NOEXCEPT {return __base::quiet_NaN();}
_LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR type signaling_NaN() _NOEXCEPT {return __base::signaling_NaN();}
_LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR type denorm_min() _NOEXCEPT {return __base::denorm_min();}
static _LIBCPP_CONSTEXPR const bool is_iec559 = __base::is_iec559;
static _LIBCPP_CONSTEXPR const bool is_bounded = __base::is_bounded;
static _LIBCPP_CONSTEXPR const bool is_modulo = __base::is_modulo;
static _LIBCPP_CONSTEXPR const bool traps = __base::traps;
static _LIBCPP_CONSTEXPR const bool tinyness_before = __base::tinyness_before;
static _LIBCPP_CONSTEXPR const float_round_style round_style = __base::round_style;
};
template <class _Tp>
_LIBCPP_CONSTEXPR const bool numeric_limits<_Tp>::is_specialized;
template <class _Tp>
_LIBCPP_CONSTEXPR const int numeric_limits<_Tp>::digits;
template <class _Tp>
_LIBCPP_CONSTEXPR const int numeric_limits<_Tp>::digits10;
template <class _Tp>
_LIBCPP_CONSTEXPR const int numeric_limits<_Tp>::max_digits10;
template <class _Tp>
_LIBCPP_CONSTEXPR const bool numeric_limits<_Tp>::is_signed;
template <class _Tp>
_LIBCPP_CONSTEXPR const bool numeric_limits<_Tp>::is_integer;
template <class _Tp>
_LIBCPP_CONSTEXPR const bool numeric_limits<_Tp>::is_exact;
template <class _Tp>
_LIBCPP_CONSTEXPR const int numeric_limits<_Tp>::radix;
template <class _Tp>
_LIBCPP_CONSTEXPR const int numeric_limits<_Tp>::min_exponent;
template <class _Tp>
_LIBCPP_CONSTEXPR const int numeric_limits<_Tp>::min_exponent10;
template <class _Tp>
_LIBCPP_CONSTEXPR const int numeric_limits<_Tp>::max_exponent;
template <class _Tp>
_LIBCPP_CONSTEXPR const int numeric_limits<_Tp>::max_exponent10;
template <class _Tp>
_LIBCPP_CONSTEXPR const bool numeric_limits<_Tp>::has_infinity;
template <class _Tp>
_LIBCPP_CONSTEXPR const bool numeric_limits<_Tp>::has_quiet_NaN;
template <class _Tp>
_LIBCPP_CONSTEXPR const bool numeric_limits<_Tp>::has_signaling_NaN;
template <class _Tp>
_LIBCPP_CONSTEXPR const float_denorm_style numeric_limits<_Tp>::has_denorm;
template <class _Tp>
_LIBCPP_CONSTEXPR const bool numeric_limits<_Tp>::has_denorm_loss;
template <class _Tp>
_LIBCPP_CONSTEXPR const bool numeric_limits<_Tp>::is_iec559;
template <class _Tp>
_LIBCPP_CONSTEXPR const bool numeric_limits<_Tp>::is_bounded;
template <class _Tp>
_LIBCPP_CONSTEXPR const bool numeric_limits<_Tp>::is_modulo;
template <class _Tp>
_LIBCPP_CONSTEXPR const bool numeric_limits<_Tp>::traps;
template <class _Tp>
_LIBCPP_CONSTEXPR const bool numeric_limits<_Tp>::tinyness_before;
template <class _Tp>
_LIBCPP_CONSTEXPR const float_round_style numeric_limits<_Tp>::round_style;
template <class _Tp>
class _LIBCPP_TEMPLATE_VIS numeric_limits<const _Tp>
: private numeric_limits<_Tp>
{
typedef numeric_limits<_Tp> __base;
typedef _Tp type;
public:
static _LIBCPP_CONSTEXPR const bool is_specialized = __base::is_specialized;
_LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR type min() _NOEXCEPT {return __base::min();}
_LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR type max() _NOEXCEPT {return __base::max();}
_LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR type lowest() _NOEXCEPT {return __base::lowest();}
static _LIBCPP_CONSTEXPR const int digits = __base::digits;
static _LIBCPP_CONSTEXPR const int digits10 = __base::digits10;
static _LIBCPP_CONSTEXPR const int max_digits10 = __base::max_digits10;
static _LIBCPP_CONSTEXPR const bool is_signed = __base::is_signed;
static _LIBCPP_CONSTEXPR const bool is_integer = __base::is_integer;
static _LIBCPP_CONSTEXPR const bool is_exact = __base::is_exact;
static _LIBCPP_CONSTEXPR const int radix = __base::radix;
_LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR type epsilon() _NOEXCEPT {return __base::epsilon();}
_LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR type round_error() _NOEXCEPT {return __base::round_error();}
static _LIBCPP_CONSTEXPR const int min_exponent = __base::min_exponent;
static _LIBCPP_CONSTEXPR const int min_exponent10 = __base::min_exponent10;
static _LIBCPP_CONSTEXPR const int max_exponent = __base::max_exponent;
static _LIBCPP_CONSTEXPR const int max_exponent10 = __base::max_exponent10;
static _LIBCPP_CONSTEXPR const bool has_infinity = __base::has_infinity;
static _LIBCPP_CONSTEXPR const bool has_quiet_NaN = __base::has_quiet_NaN;
static _LIBCPP_CONSTEXPR const bool has_signaling_NaN = __base::has_signaling_NaN;
static _LIBCPP_CONSTEXPR const float_denorm_style has_denorm = __base::has_denorm;
static _LIBCPP_CONSTEXPR const bool has_denorm_loss = __base::has_denorm_loss;
_LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR type infinity() _NOEXCEPT {return __base::infinity();}
_LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR type quiet_NaN() _NOEXCEPT {return __base::quiet_NaN();}
_LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR type signaling_NaN() _NOEXCEPT {return __base::signaling_NaN();}
_LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR type denorm_min() _NOEXCEPT {return __base::denorm_min();}
static _LIBCPP_CONSTEXPR const bool is_iec559 = __base::is_iec559;
static _LIBCPP_CONSTEXPR const bool is_bounded = __base::is_bounded;
static _LIBCPP_CONSTEXPR const bool is_modulo = __base::is_modulo;
static _LIBCPP_CONSTEXPR const bool traps = __base::traps;
static _LIBCPP_CONSTEXPR const bool tinyness_before = __base::tinyness_before;
static _LIBCPP_CONSTEXPR const float_round_style round_style = __base::round_style;
};
template <class _Tp>
_LIBCPP_CONSTEXPR const bool numeric_limits<const _Tp>::is_specialized;
template <class _Tp>
_LIBCPP_CONSTEXPR const int numeric_limits<const _Tp>::digits;
template <class _Tp>
_LIBCPP_CONSTEXPR const int numeric_limits<const _Tp>::digits10;
template <class _Tp>
_LIBCPP_CONSTEXPR const int numeric_limits<const _Tp>::max_digits10;
template <class _Tp>
_LIBCPP_CONSTEXPR const bool numeric_limits<const _Tp>::is_signed;
template <class _Tp>
_LIBCPP_CONSTEXPR const bool numeric_limits<const _Tp>::is_integer;
template <class _Tp>
_LIBCPP_CONSTEXPR const bool numeric_limits<const _Tp>::is_exact;
template <class _Tp>
_LIBCPP_CONSTEXPR const int numeric_limits<const _Tp>::radix;
template <class _Tp>
_LIBCPP_CONSTEXPR const int numeric_limits<const _Tp>::min_exponent;
template <class _Tp>
_LIBCPP_CONSTEXPR const int numeric_limits<const _Tp>::min_exponent10;
template <class _Tp>
_LIBCPP_CONSTEXPR const int numeric_limits<const _Tp>::max_exponent;
template <class _Tp>
_LIBCPP_CONSTEXPR const int numeric_limits<const _Tp>::max_exponent10;
template <class _Tp>
_LIBCPP_CONSTEXPR const bool numeric_limits<const _Tp>::has_infinity;
template <class _Tp>
_LIBCPP_CONSTEXPR const bool numeric_limits<const _Tp>::has_quiet_NaN;
template <class _Tp>
_LIBCPP_CONSTEXPR const bool numeric_limits<const _Tp>::has_signaling_NaN;
template <class _Tp>
_LIBCPP_CONSTEXPR const float_denorm_style numeric_limits<const _Tp>::has_denorm;
template <class _Tp>
_LIBCPP_CONSTEXPR const bool numeric_limits<const _Tp>::has_denorm_loss;
template <class _Tp>
_LIBCPP_CONSTEXPR const bool numeric_limits<const _Tp>::is_iec559;
template <class _Tp>
_LIBCPP_CONSTEXPR const bool numeric_limits<const _Tp>::is_bounded;
template <class _Tp>
_LIBCPP_CONSTEXPR const bool numeric_limits<const _Tp>::is_modulo;
template <class _Tp>
_LIBCPP_CONSTEXPR const bool numeric_limits<const _Tp>::traps;
template <class _Tp>
_LIBCPP_CONSTEXPR const bool numeric_limits<const _Tp>::tinyness_before;
template <class _Tp>
_LIBCPP_CONSTEXPR const float_round_style numeric_limits<const _Tp>::round_style;
template <class _Tp>
class _LIBCPP_TEMPLATE_VIS numeric_limits<volatile _Tp>
: private numeric_limits<_Tp>
{
typedef numeric_limits<_Tp> __base;
typedef _Tp type;
public:
static _LIBCPP_CONSTEXPR const bool is_specialized = __base::is_specialized;
_LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR type min() _NOEXCEPT {return __base::min();}
_LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR type max() _NOEXCEPT {return __base::max();}
_LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR type lowest() _NOEXCEPT {return __base::lowest();}
static _LIBCPP_CONSTEXPR const int digits = __base::digits;
static _LIBCPP_CONSTEXPR const int digits10 = __base::digits10;
static _LIBCPP_CONSTEXPR const int max_digits10 = __base::max_digits10;
static _LIBCPP_CONSTEXPR const bool is_signed = __base::is_signed;
static _LIBCPP_CONSTEXPR const bool is_integer = __base::is_integer;
static _LIBCPP_CONSTEXPR const bool is_exact = __base::is_exact;
static _LIBCPP_CONSTEXPR const int radix = __base::radix;
_LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR type epsilon() _NOEXCEPT {return __base::epsilon();}
_LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR type round_error() _NOEXCEPT {return __base::round_error();}
static _LIBCPP_CONSTEXPR const int min_exponent = __base::min_exponent;
static _LIBCPP_CONSTEXPR const int min_exponent10 = __base::min_exponent10;
static _LIBCPP_CONSTEXPR const int max_exponent = __base::max_exponent;
static _LIBCPP_CONSTEXPR const int max_exponent10 = __base::max_exponent10;
static _LIBCPP_CONSTEXPR const bool has_infinity = __base::has_infinity;
static _LIBCPP_CONSTEXPR const bool has_quiet_NaN = __base::has_quiet_NaN;
static _LIBCPP_CONSTEXPR const bool has_signaling_NaN = __base::has_signaling_NaN;
static _LIBCPP_CONSTEXPR const float_denorm_style has_denorm = __base::has_denorm;
static _LIBCPP_CONSTEXPR const bool has_denorm_loss = __base::has_denorm_loss;
_LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR type infinity() _NOEXCEPT {return __base::infinity();}
_LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR type quiet_NaN() _NOEXCEPT {return __base::quiet_NaN();}
_LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR type signaling_NaN() _NOEXCEPT {return __base::signaling_NaN();}
_LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR type denorm_min() _NOEXCEPT {return __base::denorm_min();}
static _LIBCPP_CONSTEXPR const bool is_iec559 = __base::is_iec559;
static _LIBCPP_CONSTEXPR const bool is_bounded = __base::is_bounded;
static _LIBCPP_CONSTEXPR const bool is_modulo = __base::is_modulo;
static _LIBCPP_CONSTEXPR const bool traps = __base::traps;
static _LIBCPP_CONSTEXPR const bool tinyness_before = __base::tinyness_before;
static _LIBCPP_CONSTEXPR const float_round_style round_style = __base::round_style;
};
template <class _Tp>
_LIBCPP_CONSTEXPR const bool numeric_limits<volatile _Tp>::is_specialized;
template <class _Tp>
_LIBCPP_CONSTEXPR const int numeric_limits<volatile _Tp>::digits;
template <class _Tp>
_LIBCPP_CONSTEXPR const int numeric_limits<volatile _Tp>::digits10;
template <class _Tp>
_LIBCPP_CONSTEXPR const int numeric_limits<volatile _Tp>::max_digits10;
template <class _Tp>
_LIBCPP_CONSTEXPR const bool numeric_limits<volatile _Tp>::is_signed;
template <class _Tp>
_LIBCPP_CONSTEXPR const bool numeric_limits<volatile _Tp>::is_integer;
template <class _Tp>
_LIBCPP_CONSTEXPR const bool numeric_limits<volatile _Tp>::is_exact;
template <class _Tp>
_LIBCPP_CONSTEXPR const int numeric_limits<volatile _Tp>::radix;
template <class _Tp>
_LIBCPP_CONSTEXPR const int numeric_limits<volatile _Tp>::min_exponent;
template <class _Tp>
_LIBCPP_CONSTEXPR const int numeric_limits<volatile _Tp>::min_exponent10;
template <class _Tp>
_LIBCPP_CONSTEXPR const int numeric_limits<volatile _Tp>::max_exponent;
template <class _Tp>
_LIBCPP_CONSTEXPR const int numeric_limits<volatile _Tp>::max_exponent10;
template <class _Tp>
_LIBCPP_CONSTEXPR const bool numeric_limits<volatile _Tp>::has_infinity;
template <class _Tp>
_LIBCPP_CONSTEXPR const bool numeric_limits<volatile _Tp>::has_quiet_NaN;
template <class _Tp>
_LIBCPP_CONSTEXPR const bool numeric_limits<volatile _Tp>::has_signaling_NaN;
template <class _Tp>
_LIBCPP_CONSTEXPR const float_denorm_style numeric_limits<volatile _Tp>::has_denorm;
template <class _Tp>
_LIBCPP_CONSTEXPR const bool numeric_limits<volatile _Tp>::has_denorm_loss;
template <class _Tp>
_LIBCPP_CONSTEXPR const bool numeric_limits<volatile _Tp>::is_iec559;
template <class _Tp>
_LIBCPP_CONSTEXPR const bool numeric_limits<volatile _Tp>::is_bounded;
template <class _Tp>
_LIBCPP_CONSTEXPR const bool numeric_limits<volatile _Tp>::is_modulo;
template <class _Tp>
_LIBCPP_CONSTEXPR const bool numeric_limits<volatile _Tp>::traps;
template <class _Tp>
_LIBCPP_CONSTEXPR const bool numeric_limits<volatile _Tp>::tinyness_before;
template <class _Tp>
_LIBCPP_CONSTEXPR const float_round_style numeric_limits<volatile _Tp>::round_style;
template <class _Tp>
class _LIBCPP_TEMPLATE_VIS numeric_limits<const volatile _Tp>
: private numeric_limits<_Tp>
{
typedef numeric_limits<_Tp> __base;
typedef _Tp type;
public:
static _LIBCPP_CONSTEXPR const bool is_specialized = __base::is_specialized;
_LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR type min() _NOEXCEPT {return __base::min();}
_LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR type max() _NOEXCEPT {return __base::max();}
_LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR type lowest() _NOEXCEPT {return __base::lowest();}
static _LIBCPP_CONSTEXPR const int digits = __base::digits;
static _LIBCPP_CONSTEXPR const int digits10 = __base::digits10;
static _LIBCPP_CONSTEXPR const int max_digits10 = __base::max_digits10;
static _LIBCPP_CONSTEXPR const bool is_signed = __base::is_signed;
static _LIBCPP_CONSTEXPR const bool is_integer = __base::is_integer;
static _LIBCPP_CONSTEXPR const bool is_exact = __base::is_exact;
static _LIBCPP_CONSTEXPR const int radix = __base::radix;
_LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR type epsilon() _NOEXCEPT {return __base::epsilon();}
_LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR type round_error() _NOEXCEPT {return __base::round_error();}
static _LIBCPP_CONSTEXPR const int min_exponent = __base::min_exponent;
static _LIBCPP_CONSTEXPR const int min_exponent10 = __base::min_exponent10;
static _LIBCPP_CONSTEXPR const int max_exponent = __base::max_exponent;
static _LIBCPP_CONSTEXPR const int max_exponent10 = __base::max_exponent10;
static _LIBCPP_CONSTEXPR const bool has_infinity = __base::has_infinity;
static _LIBCPP_CONSTEXPR const bool has_quiet_NaN = __base::has_quiet_NaN;
static _LIBCPP_CONSTEXPR const bool has_signaling_NaN = __base::has_signaling_NaN;
static _LIBCPP_CONSTEXPR const float_denorm_style has_denorm = __base::has_denorm;
static _LIBCPP_CONSTEXPR const bool has_denorm_loss = __base::has_denorm_loss;
_LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR type infinity() _NOEXCEPT {return __base::infinity();}
_LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR type quiet_NaN() _NOEXCEPT {return __base::quiet_NaN();}
_LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR type signaling_NaN() _NOEXCEPT {return __base::signaling_NaN();}
_LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR type denorm_min() _NOEXCEPT {return __base::denorm_min();}
static _LIBCPP_CONSTEXPR const bool is_iec559 = __base::is_iec559;
static _LIBCPP_CONSTEXPR const bool is_bounded = __base::is_bounded;
static _LIBCPP_CONSTEXPR const bool is_modulo = __base::is_modulo;
static _LIBCPP_CONSTEXPR const bool traps = __base::traps;
static _LIBCPP_CONSTEXPR const bool tinyness_before = __base::tinyness_before;
static _LIBCPP_CONSTEXPR const float_round_style round_style = __base::round_style;
};
template <class _Tp>
_LIBCPP_CONSTEXPR const bool numeric_limits<const volatile _Tp>::is_specialized;
template <class _Tp>
_LIBCPP_CONSTEXPR const int numeric_limits<const volatile _Tp>::digits;
template <class _Tp>
_LIBCPP_CONSTEXPR const int numeric_limits<const volatile _Tp>::digits10;
template <class _Tp>
_LIBCPP_CONSTEXPR const int numeric_limits<const volatile _Tp>::max_digits10;
template <class _Tp>
_LIBCPP_CONSTEXPR const bool numeric_limits<const volatile _Tp>::is_signed;
template <class _Tp>
_LIBCPP_CONSTEXPR const bool numeric_limits<const volatile _Tp>::is_integer;
template <class _Tp>
_LIBCPP_CONSTEXPR const bool numeric_limits<const volatile _Tp>::is_exact;
template <class _Tp>
_LIBCPP_CONSTEXPR const int numeric_limits<const volatile _Tp>::radix;
template <class _Tp>
_LIBCPP_CONSTEXPR const int numeric_limits<const volatile _Tp>::min_exponent;
template <class _Tp>
_LIBCPP_CONSTEXPR const int numeric_limits<const volatile _Tp>::min_exponent10;
template <class _Tp>
_LIBCPP_CONSTEXPR const int numeric_limits<const volatile _Tp>::max_exponent;
template <class _Tp>
_LIBCPP_CONSTEXPR const int numeric_limits<const volatile _Tp>::max_exponent10;
template <class _Tp>
_LIBCPP_CONSTEXPR const bool numeric_limits<const volatile _Tp>::has_infinity;
template <class _Tp>
_LIBCPP_CONSTEXPR const bool numeric_limits<const volatile _Tp>::has_quiet_NaN;
template <class _Tp>
_LIBCPP_CONSTEXPR const bool numeric_limits<const volatile _Tp>::has_signaling_NaN;
template <class _Tp>
_LIBCPP_CONSTEXPR const float_denorm_style numeric_limits<const volatile _Tp>::has_denorm;
template <class _Tp>
_LIBCPP_CONSTEXPR const bool numeric_limits<const volatile _Tp>::has_denorm_loss;
template <class _Tp>
_LIBCPP_CONSTEXPR const bool numeric_limits<const volatile _Tp>::is_iec559;
template <class _Tp>
_LIBCPP_CONSTEXPR const bool numeric_limits<const volatile _Tp>::is_bounded;
template <class _Tp>
_LIBCPP_CONSTEXPR const bool numeric_limits<const volatile _Tp>::is_modulo;
template <class _Tp>
_LIBCPP_CONSTEXPR const bool numeric_limits<const volatile _Tp>::traps;
template <class _Tp>
_LIBCPP_CONSTEXPR const bool numeric_limits<const volatile _Tp>::tinyness_before;
template <class _Tp>
_LIBCPP_CONSTEXPR const float_round_style numeric_limits<const volatile _Tp>::round_style;
_LIBCPP_END_NAMESPACE_STD
_LIBCPP_POP_MACROS
#endif // _LIBCPP_LIMITS
| 40,551 | 811 | jart/cosmopolitan | false |
cosmopolitan/third_party/libcxx/strstream.cc | // clang-format off
//===------------------------ strstream.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/strstream"
#include "third_party/libcxx/algorithm"
#include "third_party/libcxx/climits"
#include "third_party/libcxx/cstring"
#include "third_party/libcxx/cstdlib"
#include "third_party/libcxx/__debug"
#include "third_party/libcxx/__undef_macros"
_LIBCPP_BEGIN_NAMESPACE_STD
strstreambuf::strstreambuf(streamsize __alsize)
: __strmode_(__dynamic),
__alsize_(__alsize),
__palloc_(nullptr),
__pfree_(nullptr)
{
}
strstreambuf::strstreambuf(void* (*__palloc)(size_t), void (*__pfree)(void*))
: __strmode_(__dynamic),
__alsize_(__default_alsize),
__palloc_(__palloc),
__pfree_(__pfree)
{
}
void
strstreambuf::__init(char* __gnext, streamsize __n, char* __pbeg)
{
if (__n == 0)
__n = static_cast<streamsize>(strlen(__gnext));
else if (__n < 0)
__n = INT_MAX;
if (__pbeg == nullptr)
setg(__gnext, __gnext, __gnext + __n);
else
{
setg(__gnext, __gnext, __pbeg);
setp(__pbeg, __pbeg + __n);
}
}
strstreambuf::strstreambuf(char* __gnext, streamsize __n, char* __pbeg)
: __strmode_(),
__alsize_(__default_alsize),
__palloc_(nullptr),
__pfree_(nullptr)
{
__init(__gnext, __n, __pbeg);
}
strstreambuf::strstreambuf(const char* __gnext, streamsize __n)
: __strmode_(__constant),
__alsize_(__default_alsize),
__palloc_(nullptr),
__pfree_(nullptr)
{
__init(const_cast<char *>(__gnext), __n, nullptr);
}
strstreambuf::strstreambuf(signed char* __gnext, streamsize __n, signed char* __pbeg)
: __strmode_(),
__alsize_(__default_alsize),
__palloc_(nullptr),
__pfree_(nullptr)
{
__init(const_cast<char *>(reinterpret_cast<const char*>(__gnext)), __n, reinterpret_cast<char*>(__pbeg));
}
strstreambuf::strstreambuf(const signed char* __gnext, streamsize __n)
: __strmode_(__constant),
__alsize_(__default_alsize),
__palloc_(nullptr),
__pfree_(nullptr)
{
__init(const_cast<char *>(reinterpret_cast<const char*>(__gnext)), __n, nullptr);
}
strstreambuf::strstreambuf(unsigned char* __gnext, streamsize __n, unsigned char* __pbeg)
: __strmode_(),
__alsize_(__default_alsize),
__palloc_(nullptr),
__pfree_(nullptr)
{
__init(const_cast<char *>(reinterpret_cast<const char*>(__gnext)), __n, reinterpret_cast<char*>(__pbeg));
}
strstreambuf::strstreambuf(const unsigned char* __gnext, streamsize __n)
: __strmode_(__constant),
__alsize_(__default_alsize),
__palloc_(nullptr),
__pfree_(nullptr)
{
__init(const_cast<char *>(reinterpret_cast<const char*>(__gnext)), __n, nullptr);
}
strstreambuf::~strstreambuf()
{
if (eback() && (__strmode_ & __allocated) != 0 && (__strmode_ & __frozen) == 0)
{
if (__pfree_)
__pfree_(eback());
else
delete [] eback();
}
}
void
strstreambuf::swap(strstreambuf& __rhs)
{
streambuf::swap(__rhs);
_VSTD::swap(__strmode_, __rhs.__strmode_);
_VSTD::swap(__alsize_, __rhs.__alsize_);
_VSTD::swap(__palloc_, __rhs.__palloc_);
_VSTD::swap(__pfree_, __rhs.__pfree_);
}
void
strstreambuf::freeze(bool __freezefl)
{
if (__strmode_ & __dynamic)
{
if (__freezefl)
__strmode_ |= __frozen;
else
__strmode_ &= ~__frozen;
}
}
char*
strstreambuf::str()
{
if (__strmode_ & __dynamic)
__strmode_ |= __frozen;
return eback();
}
int
strstreambuf::pcount() const
{
return static_cast<int>(pptr() - pbase());
}
strstreambuf::int_type
strstreambuf::overflow(int_type __c)
{
if (__c == EOF)
return int_type(0);
if (pptr() == epptr())
{
if ((__strmode_ & __dynamic) == 0 || (__strmode_ & __frozen) != 0)
return int_type(EOF);
size_t old_size = static_cast<size_t> ((epptr() ? epptr() : egptr()) - eback());
size_t new_size = max<size_t>(static_cast<size_t>(__alsize_), 2*old_size);
if (new_size == 0)
new_size = __default_alsize;
char* buf = nullptr;
if (__palloc_)
buf = static_cast<char*>(__palloc_(new_size));
else
buf = new char[new_size];
if (buf == nullptr)
return int_type(EOF);
if (old_size != 0) {
_LIBCPP_ASSERT(eback(), "overflow copying from NULL");
memcpy(buf, eback(), static_cast<size_t>(old_size));
}
ptrdiff_t ninp = gptr() - eback();
ptrdiff_t einp = egptr() - eback();
ptrdiff_t nout = pptr() - pbase();
if (__strmode_ & __allocated)
{
if (__pfree_)
__pfree_(eback());
else
delete [] eback();
}
setg(buf, buf + ninp, buf + einp);
setp(buf + einp, buf + new_size);
__pbump(nout);
__strmode_ |= __allocated;
}
*pptr() = static_cast<char>(__c);
pbump(1);
return int_type(static_cast<unsigned char>(__c));
}
strstreambuf::int_type
strstreambuf::pbackfail(int_type __c)
{
if (eback() == gptr())
return EOF;
if (__c == EOF)
{
gbump(-1);
return int_type(0);
}
if (__strmode_ & __constant)
{
if (gptr()[-1] == static_cast<char>(__c))
{
gbump(-1);
return __c;
}
return EOF;
}
gbump(-1);
*gptr() = static_cast<char>(__c);
return __c;
}
strstreambuf::int_type
strstreambuf::underflow()
{
if (gptr() == egptr())
{
if (egptr() >= pptr())
return EOF;
setg(eback(), gptr(), pptr());
}
return int_type(static_cast<unsigned char>(*gptr()));
}
strstreambuf::pos_type
strstreambuf::seekoff(off_type __off, ios_base::seekdir __way, ios_base::openmode __which)
{
off_type __p(-1);
bool pos_in = (__which & ios::in) != 0;
bool pos_out = (__which & ios::out) != 0;
bool legal = false;
switch (__way)
{
case ios::beg:
case ios::end:
if (pos_in || pos_out)
legal = true;
break;
case ios::cur:
if (pos_in != pos_out)
legal = true;
break;
}
if (pos_in && gptr() == nullptr)
legal = false;
if (pos_out && pptr() == nullptr)
legal = false;
if (legal)
{
off_type newoff;
char* seekhigh = epptr() ? epptr() : egptr();
switch (__way)
{
case ios::beg:
newoff = 0;
break;
case ios::cur:
newoff = (pos_in ? gptr() : pptr()) - eback();
break;
case ios::end:
newoff = seekhigh - eback();
break;
default:
_LIBCPP_UNREACHABLE();
}
newoff += __off;
if (0 <= newoff && newoff <= seekhigh - eback())
{
char* newpos = eback() + newoff;
if (pos_in)
setg(eback(), newpos, _VSTD::max(newpos, egptr()));
if (pos_out)
{
// min(pbase, newpos), newpos, epptr()
__off = epptr() - newpos;
setp(min(pbase(), newpos), epptr());
__pbump((epptr() - pbase()) - __off);
}
__p = newoff;
}
}
return pos_type(__p);
}
strstreambuf::pos_type
strstreambuf::seekpos(pos_type __sp, ios_base::openmode __which)
{
off_type __p(-1);
bool pos_in = (__which & ios::in) != 0;
bool pos_out = (__which & ios::out) != 0;
if (pos_in || pos_out)
{
if (!((pos_in && gptr() == nullptr) || (pos_out && pptr() == nullptr)))
{
off_type newoff = __sp;
char* seekhigh = epptr() ? epptr() : egptr();
if (0 <= newoff && newoff <= seekhigh - eback())
{
char* newpos = eback() + newoff;
if (pos_in)
setg(eback(), newpos, _VSTD::max(newpos, egptr()));
if (pos_out)
{
// min(pbase, newpos), newpos, epptr()
off_type temp = epptr() - newpos;
setp(min(pbase(), newpos), epptr());
__pbump((epptr() - pbase()) - temp);
}
__p = newoff;
}
}
}
return pos_type(__p);
}
istrstream::~istrstream()
{
}
ostrstream::~ostrstream()
{
}
strstream::~strstream()
{
}
_LIBCPP_END_NAMESPACE_STD
| 8,819 | 337 | jart/cosmopolitan | false |
cosmopolitan/third_party/libcxx/new.cc | //===--------------------------- new.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/stdlib.h"
#include "third_party/libcxx/new"
#include "third_party/libcxx/atomic_support.hh"
#include "third_party/libcxx/new_handler_fallback.hh"
namespace std {
#ifndef __GLIBCXX__
const nothrow_t nothrow{};
#endif
#ifndef LIBSTDCXX
void __throw_bad_alloc() {
#ifndef _LIBCPP_NO_EXCEPTIONS
throw bad_alloc();
#else
_VSTD::abort();
#endif
}
#endif // !LIBSTDCXX
} // namespace std
#if !defined(__GLIBCXX__) && !defined(_LIBCPP_ABI_VCRUNTIME) && \
!defined(_LIBCPP_DISABLE_NEW_DELETE_DEFINITIONS)
// Implement all new and delete operators as weak definitions
// in this shared library, so that they can be overridden by programs
// that define non-weak copies of the functions.
_LIBCPP_WEAK
void* operator new(std::size_t size) _THROW_BAD_ALLOC {
if (size == 0)
size = 1;
void* p;
while ((p = ::malloc(size)) == 0) {
// If malloc fails and there is a new_handler,
// call it to try free up memory.
std::new_handler nh = std::get_new_handler();
if (nh)
nh();
else
#ifndef _LIBCPP_NO_EXCEPTIONS
throw std::bad_alloc();
#else
break;
#endif
}
return p;
}
_LIBCPP_WEAK
void* operator new(size_t size, const std::nothrow_t&) _NOEXCEPT {
void* p = 0;
#ifndef _LIBCPP_NO_EXCEPTIONS
try {
#endif // _LIBCPP_NO_EXCEPTIONS
p = ::operator new(size);
#ifndef _LIBCPP_NO_EXCEPTIONS
} catch (...) {
}
#endif // _LIBCPP_NO_EXCEPTIONS
return p;
}
_LIBCPP_WEAK
void* operator new[](size_t size) _THROW_BAD_ALLOC {
return ::operator new(size);
}
_LIBCPP_WEAK
void* operator new[](size_t size, const std::nothrow_t&) _NOEXCEPT {
void* p = 0;
#ifndef _LIBCPP_NO_EXCEPTIONS
try {
#endif // _LIBCPP_NO_EXCEPTIONS
p = ::operator new[](size);
#ifndef _LIBCPP_NO_EXCEPTIONS
} catch (...) {
}
#endif // _LIBCPP_NO_EXCEPTIONS
return p;
}
_LIBCPP_WEAK
void operator delete(void* ptr)_NOEXCEPT { ::free(ptr); }
_LIBCPP_WEAK
void operator delete(void* ptr, const std::nothrow_t&)_NOEXCEPT {
::operator delete(ptr);
}
_LIBCPP_WEAK
void operator delete(void* ptr, size_t)_NOEXCEPT { ::operator delete(ptr); }
_LIBCPP_WEAK
void operator delete[](void* ptr) _NOEXCEPT { ::operator delete(ptr); }
_LIBCPP_WEAK
void operator delete[](void* ptr, const std::nothrow_t&) _NOEXCEPT {
::operator delete[](ptr);
}
_LIBCPP_WEAK
void operator delete[](void* ptr, size_t) _NOEXCEPT {
::operator delete[](ptr);
}
#if !defined(_LIBCPP_HAS_NO_LIBRARY_ALIGNED_ALLOCATION)
_LIBCPP_WEAK
void* operator new(std::size_t size,
std::align_val_t alignment) _THROW_BAD_ALLOC {
if (size == 0)
size = 1;
if (static_cast<size_t>(alignment) < sizeof(void*))
alignment = std::align_val_t(sizeof(void*));
void* p;
#if defined(_LIBCPP_MSVCRT_LIKE)
while ((p = _aligned_malloc(size, static_cast<size_t>(alignment))) == nullptr)
#else
while (::posix_memalign(&p, static_cast<size_t>(alignment), size) != 0)
#endif
{
// If posix_memalign fails and there is a new_handler,
// call it to try free up memory.
std::new_handler nh = std::get_new_handler();
if (nh)
nh();
else {
#ifndef _LIBCPP_NO_EXCEPTIONS
throw std::bad_alloc();
#else
p = nullptr; // posix_memalign doesn't initialize 'p' on failure
break;
#endif
}
}
return p;
}
_LIBCPP_WEAK
void* operator new(size_t size, std::align_val_t alignment,
const std::nothrow_t&) _NOEXCEPT {
void* p = 0;
#ifndef _LIBCPP_NO_EXCEPTIONS
try {
#endif // _LIBCPP_NO_EXCEPTIONS
p = ::operator new(size, alignment);
#ifndef _LIBCPP_NO_EXCEPTIONS
} catch (...) {
}
#endif // _LIBCPP_NO_EXCEPTIONS
return p;
}
_LIBCPP_WEAK
void* operator new[](size_t size, std::align_val_t alignment) _THROW_BAD_ALLOC {
return ::operator new(size, alignment);
}
_LIBCPP_WEAK
void* operator new[](size_t size, std::align_val_t alignment,
const std::nothrow_t&) _NOEXCEPT {
void* p = 0;
#ifndef _LIBCPP_NO_EXCEPTIONS
try {
#endif // _LIBCPP_NO_EXCEPTIONS
p = ::operator new[](size, alignment);
#ifndef _LIBCPP_NO_EXCEPTIONS
} catch (...) {
}
#endif // _LIBCPP_NO_EXCEPTIONS
return p;
}
_LIBCPP_WEAK
void operator delete(void* ptr, std::align_val_t)_NOEXCEPT {
#if defined(_LIBCPP_MSVCRT_LIKE)
::_aligned_free(ptr);
#else
::free(ptr);
#endif
}
_LIBCPP_WEAK
void operator delete(void* ptr, std::align_val_t alignment,
const std::nothrow_t&)_NOEXCEPT {
::operator delete(ptr, alignment);
}
_LIBCPP_WEAK
void operator delete(void* ptr, size_t, std::align_val_t alignment)_NOEXCEPT {
::operator delete(ptr, alignment);
}
_LIBCPP_WEAK
void operator delete[](void* ptr, std::align_val_t alignment) _NOEXCEPT {
::operator delete(ptr, alignment);
}
_LIBCPP_WEAK
void operator delete[](void* ptr, std::align_val_t alignment,
const std::nothrow_t&) _NOEXCEPT {
::operator delete[](ptr, alignment);
}
_LIBCPP_WEAK
void operator delete[](void* ptr, size_t,
std::align_val_t alignment) _NOEXCEPT {
::operator delete[](ptr, alignment);
}
#endif // !_LIBCPP_HAS_NO_LIBRARY_ALIGNED_ALLOCATION
#endif // !__GLIBCXX__ && !_LIBCPP_ABI_VCRUNTIME && !_LIBCPP_DISABLE_NEW_DELETE_DEFINITIONS
| 5,600 | 227 | jart/cosmopolitan | false |
cosmopolitan/third_party/libcxx/stdexcept | // -*- C++ -*-
//===--------------------------- stdexcept --------------------------------===//
//
// 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_STDEXCEPT
#define _LIBCPP_STDEXCEPT
/*
stdexcept synopsis
namespace std
{
class logic_error;
class domain_error;
class invalid_argument;
class length_error;
class out_of_range;
class runtime_error;
class range_error;
class overflow_error;
class underflow_error;
for each class xxx_error:
class xxx_error : public exception // at least indirectly
{
public:
explicit xxx_error(const string& what_arg);
explicit xxx_error(const char* what_arg);
virtual const char* what() const noexcept // returns what_arg
};
} // std
*/
#include "third_party/libcxx/__config"
#include "third_party/libcxx/exception"
#include "third_party/libcxx/iosfwd" // for string forward decl
#ifdef _LIBCPP_NO_EXCEPTIONS
#include "third_party/libcxx/cstdlib"
#endif
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
#pragma GCC system_header
#endif
_LIBCPP_BEGIN_NAMESPACE_STD
#ifndef _LIBCPP_ABI_VCRUNTIME
class _LIBCPP_HIDDEN __libcpp_refstring
{
const char* __imp_;
bool __uses_refcount() const;
public:
explicit __libcpp_refstring(const char* __msg);
__libcpp_refstring(const __libcpp_refstring& __s) _NOEXCEPT;
__libcpp_refstring& operator=(const __libcpp_refstring& __s) _NOEXCEPT;
~__libcpp_refstring();
const char* c_str() const _NOEXCEPT {return __imp_;}
};
#endif // !_LIBCPP_ABI_VCRUNTIME
_LIBCPP_END_NAMESPACE_STD
namespace std // purposefully not using versioning namespace
{
class _LIBCPP_EXCEPTION_ABI logic_error
: public exception
{
#ifndef _LIBCPP_ABI_VCRUNTIME
private:
_VSTD::__libcpp_refstring __imp_;
public:
explicit logic_error(const string&);
explicit logic_error(const char*);
logic_error(const logic_error&) _NOEXCEPT;
logic_error& operator=(const logic_error&) _NOEXCEPT;
virtual ~logic_error() _NOEXCEPT;
virtual const char* what() const _NOEXCEPT;
#else
public:
explicit logic_error(const _VSTD::string&); // Symbol uses versioned std::string
_LIBCPP_INLINE_VISIBILITY explicit logic_error(const char* __s) : exception(__s) {}
#endif
};
class _LIBCPP_EXCEPTION_ABI runtime_error
: public exception
{
#ifndef _LIBCPP_ABI_VCRUNTIME
private:
_VSTD::__libcpp_refstring __imp_;
public:
explicit runtime_error(const string&);
explicit runtime_error(const char*);
runtime_error(const runtime_error&) _NOEXCEPT;
runtime_error& operator=(const runtime_error&) _NOEXCEPT;
virtual ~runtime_error() _NOEXCEPT;
virtual const char* what() const _NOEXCEPT;
#else
public:
explicit runtime_error(const _VSTD::string&); // Symbol uses versioned std::string
_LIBCPP_INLINE_VISIBILITY explicit runtime_error(const char* __s) : exception(__s) {}
#endif // _LIBCPP_ABI_VCRUNTIME
};
class _LIBCPP_EXCEPTION_ABI domain_error
: public logic_error
{
public:
_LIBCPP_INLINE_VISIBILITY explicit domain_error(const string& __s) : logic_error(__s) {}
_LIBCPP_INLINE_VISIBILITY explicit domain_error(const char* __s) : logic_error(__s) {}
#ifndef _LIBCPP_ABI_VCRUNTIME
virtual ~domain_error() _NOEXCEPT;
#endif
};
class _LIBCPP_EXCEPTION_ABI invalid_argument
: public logic_error
{
public:
_LIBCPP_INLINE_VISIBILITY explicit invalid_argument(const string& __s) : logic_error(__s) {}
_LIBCPP_INLINE_VISIBILITY explicit invalid_argument(const char* __s) : logic_error(__s) {}
#ifndef _LIBCPP_ABI_VCRUNTIME
virtual ~invalid_argument() _NOEXCEPT;
#endif
};
class _LIBCPP_EXCEPTION_ABI length_error
: public logic_error
{
public:
_LIBCPP_INLINE_VISIBILITY explicit length_error(const string& __s) : logic_error(__s) {}
_LIBCPP_INLINE_VISIBILITY explicit length_error(const char* __s) : logic_error(__s) {}
#ifndef _LIBCPP_ABI_VCRUNTIME
virtual ~length_error() _NOEXCEPT;
#endif
};
class _LIBCPP_EXCEPTION_ABI out_of_range
: public logic_error
{
public:
_LIBCPP_INLINE_VISIBILITY explicit out_of_range(const string& __s) : logic_error(__s) {}
_LIBCPP_INLINE_VISIBILITY explicit out_of_range(const char* __s) : logic_error(__s) {}
#ifndef _LIBCPP_ABI_VCRUNTIME
virtual ~out_of_range() _NOEXCEPT;
#endif
};
class _LIBCPP_EXCEPTION_ABI range_error
: public runtime_error
{
public:
_LIBCPP_INLINE_VISIBILITY explicit range_error(const string& __s) : runtime_error(__s) {}
_LIBCPP_INLINE_VISIBILITY explicit range_error(const char* __s) : runtime_error(__s) {}
#ifndef _LIBCPP_ABI_VCRUNTIME
virtual ~range_error() _NOEXCEPT;
#endif
};
class _LIBCPP_EXCEPTION_ABI overflow_error
: public runtime_error
{
public:
_LIBCPP_INLINE_VISIBILITY explicit overflow_error(const string& __s) : runtime_error(__s) {}
_LIBCPP_INLINE_VISIBILITY explicit overflow_error(const char* __s) : runtime_error(__s) {}
#ifndef _LIBCPP_ABI_VCRUNTIME
virtual ~overflow_error() _NOEXCEPT;
#endif
};
class _LIBCPP_EXCEPTION_ABI underflow_error
: public runtime_error
{
public:
_LIBCPP_INLINE_VISIBILITY explicit underflow_error(const string& __s) : runtime_error(__s) {}
_LIBCPP_INLINE_VISIBILITY explicit underflow_error(const char* __s) : runtime_error(__s) {}
#ifndef _LIBCPP_ABI_VCRUNTIME
virtual ~underflow_error() _NOEXCEPT;
#endif
};
} // std
_LIBCPP_BEGIN_NAMESPACE_STD
// in the dylib
_LIBCPP_NORETURN _LIBCPP_FUNC_VIS void __throw_runtime_error(const char*);
_LIBCPP_NORETURN inline _LIBCPP_INLINE_VISIBILITY
void __throw_logic_error(const char*__msg)
{
#ifndef _LIBCPP_NO_EXCEPTIONS
throw logic_error(__msg);
#else
((void)__msg);
_VSTD::abort();
#endif
}
_LIBCPP_NORETURN inline _LIBCPP_INLINE_VISIBILITY
void __throw_domain_error(const char*__msg)
{
#ifndef _LIBCPP_NO_EXCEPTIONS
throw domain_error(__msg);
#else
((void)__msg);
_VSTD::abort();
#endif
}
_LIBCPP_NORETURN inline _LIBCPP_INLINE_VISIBILITY
void __throw_invalid_argument(const char*__msg)
{
#ifndef _LIBCPP_NO_EXCEPTIONS
throw invalid_argument(__msg);
#else
((void)__msg);
_VSTD::abort();
#endif
}
_LIBCPP_NORETURN inline _LIBCPP_INLINE_VISIBILITY
void __throw_length_error(const char*__msg)
{
#ifndef _LIBCPP_NO_EXCEPTIONS
throw length_error(__msg);
#else
((void)__msg);
_VSTD::abort();
#endif
}
_LIBCPP_NORETURN inline _LIBCPP_INLINE_VISIBILITY
void __throw_out_of_range(const char*__msg)
{
#ifndef _LIBCPP_NO_EXCEPTIONS
throw out_of_range(__msg);
#else
((void)__msg);
_VSTD::abort();
#endif
}
_LIBCPP_NORETURN inline _LIBCPP_INLINE_VISIBILITY
void __throw_range_error(const char*__msg)
{
#ifndef _LIBCPP_NO_EXCEPTIONS
throw range_error(__msg);
#else
((void)__msg);
_VSTD::abort();
#endif
}
_LIBCPP_NORETURN inline _LIBCPP_INLINE_VISIBILITY
void __throw_overflow_error(const char*__msg)
{
#ifndef _LIBCPP_NO_EXCEPTIONS
throw overflow_error(__msg);
#else
((void)__msg);
_VSTD::abort();
#endif
}
_LIBCPP_NORETURN inline _LIBCPP_INLINE_VISIBILITY
void __throw_underflow_error(const char*__msg)
{
#ifndef _LIBCPP_NO_EXCEPTIONS
throw underflow_error(__msg);
#else
((void)__msg);
_VSTD::abort();
#endif
}
_LIBCPP_END_NAMESPACE_STD
#endif // _LIBCPP_STDEXCEPT
| 7,489 | 305 | jart/cosmopolitan | false |
cosmopolitan/third_party/libcxx/scoped_allocator | // -*- C++ -*-
// clang-format off
//===-------------------------- scoped_allocator --------------------------===//
//
// 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_SCOPED_ALLOCATOR
#define _LIBCPP_SCOPED_ALLOCATOR
/*
scoped_allocator synopsis
namespace std
{
template <class OuterAlloc, class... InnerAllocs>
class scoped_allocator_adaptor : public OuterAlloc
{
typedef allocator_traits<OuterAlloc> OuterTraits; // exposition only
scoped_allocator_adaptor<InnerAllocs...> inner; // exposition only
public:
typedef OuterAlloc outer_allocator_type;
typedef see below inner_allocator_type;
typedef typename OuterTraits::value_type value_type;
typedef typename OuterTraits::size_type size_type;
typedef typename OuterTraits::difference_type difference_type;
typedef typename OuterTraits::pointer pointer;
typedef typename OuterTraits::const_pointer const_pointer;
typedef typename OuterTraits::void_pointer void_pointer;
typedef typename OuterTraits::const_void_pointer const_void_pointer;
typedef see below propagate_on_container_copy_assignment;
typedef see below propagate_on_container_move_assignment;
typedef see below propagate_on_container_swap;
typedef see below is_always_equal;
template <class Tp>
struct rebind
{
typedef scoped_allocator_adaptor<
OuterTraits::template rebind_alloc<Tp>, InnerAllocs...> other;
};
scoped_allocator_adaptor();
template <class OuterA2>
scoped_allocator_adaptor(OuterA2&& outerAlloc,
const InnerAllocs&... innerAllocs) noexcept;
scoped_allocator_adaptor(const scoped_allocator_adaptor& other) noexcept;
scoped_allocator_adaptor(scoped_allocator_adaptor&& other) noexcept;
template <class OuterA2>
scoped_allocator_adaptor(const scoped_allocator_adaptor<OuterA2, InnerAllocs...>& other) noexcept;
template <class OuterA2>
scoped_allocator_adaptor(const scoped_allocator_adaptor<OuterA2, InnerAllocs...>&& other) noexcept;
scoped_allocator_adaptor& operator=(const scoped_allocator_adaptor&) = default;
scoped_allocator_adaptor& operator=(scoped_allocator_adaptor&&) = default;
~scoped_allocator_adaptor();
inner_allocator_type& inner_allocator() noexcept;
const inner_allocator_type& inner_allocator() const noexcept;
outer_allocator_type& outer_allocator() noexcept;
const outer_allocator_type& outer_allocator() const noexcept;
pointer allocate(size_type n); // [[nodiscard]] in C++20
pointer allocate(size_type n, const_void_pointer hint); // [[nodiscard]] in C++20
void deallocate(pointer p, size_type n) noexcept;
size_type max_size() const;
template <class T, class... Args> void construct(T* p, Args&& args);
template <class T1, class T2, class... Args1, class... Args2>
void construct(pair<T1, T2>* p, piecewise_construct t, tuple<Args1...> x,
tuple<Args2...> y);
template <class T1, class T2>
void construct(pair<T1, T2>* p);
template <class T1, class T2, class U, class V>
void construct(pair<T1, T2>* p, U&& x, V&& y);
template <class T1, class T2, class U, class V>
void construct(pair<T1, T2>* p, const pair<U, V>& x);
template <class T1, class T2, class U, class V>
void construct(pair<T1, T2>* p, pair<U, V>&& x);
template <class T> void destroy(T* p);
template <class T> void destroy(T* p) noexcept;
scoped_allocator_adaptor select_on_container_copy_construction() const noexcept;
};
template <class OuterA1, class OuterA2, class... InnerAllocs>
bool
operator==(const scoped_allocator_adaptor<OuterA1, InnerAllocs...>& a,
const scoped_allocator_adaptor<OuterA2, InnerAllocs...>& b) noexcept;
template <class OuterA1, class OuterA2, class... InnerAllocs>
bool
operator!=(const scoped_allocator_adaptor<OuterA1, InnerAllocs...>& a,
const scoped_allocator_adaptor<OuterA2, InnerAllocs...>& b) noexcept;
} // std
*/
#include "third_party/libcxx/__config"
#include "third_party/libcxx/memory"
#include "third_party/libcxx/version"
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
#pragma GCC system_header
#endif
_LIBCPP_BEGIN_NAMESPACE_STD
#if !defined(_LIBCPP_CXX03_LANG)
// scoped_allocator_adaptor
template <class ..._Allocs>
class scoped_allocator_adaptor;
template <class ..._Allocs> struct __get_poc_copy_assignment;
template <class _A0>
struct __get_poc_copy_assignment<_A0>
{
static const bool value = allocator_traits<_A0>::
propagate_on_container_copy_assignment::value;
};
template <class _A0, class ..._Allocs>
struct __get_poc_copy_assignment<_A0, _Allocs...>
{
static const bool value =
allocator_traits<_A0>::propagate_on_container_copy_assignment::value ||
__get_poc_copy_assignment<_Allocs...>::value;
};
template <class ..._Allocs> struct __get_poc_move_assignment;
template <class _A0>
struct __get_poc_move_assignment<_A0>
{
static const bool value = allocator_traits<_A0>::
propagate_on_container_move_assignment::value;
};
template <class _A0, class ..._Allocs>
struct __get_poc_move_assignment<_A0, _Allocs...>
{
static const bool value =
allocator_traits<_A0>::propagate_on_container_move_assignment::value ||
__get_poc_move_assignment<_Allocs...>::value;
};
template <class ..._Allocs> struct __get_poc_swap;
template <class _A0>
struct __get_poc_swap<_A0>
{
static const bool value = allocator_traits<_A0>::
propagate_on_container_swap::value;
};
template <class _A0, class ..._Allocs>
struct __get_poc_swap<_A0, _Allocs...>
{
static const bool value =
allocator_traits<_A0>::propagate_on_container_swap::value ||
__get_poc_swap<_Allocs...>::value;
};
template <class ..._Allocs> struct __get_is_always_equal;
template <class _A0>
struct __get_is_always_equal<_A0>
{
static const bool value = allocator_traits<_A0>::is_always_equal::value;
};
template <class _A0, class ..._Allocs>
struct __get_is_always_equal<_A0, _Allocs...>
{
static const bool value =
allocator_traits<_A0>::is_always_equal::value &&
__get_is_always_equal<_Allocs...>::value;
};
template <class ..._Allocs>
class __scoped_allocator_storage;
template <class _OuterAlloc, class... _InnerAllocs>
class __scoped_allocator_storage<_OuterAlloc, _InnerAllocs...>
: public _OuterAlloc
{
typedef _OuterAlloc outer_allocator_type;
protected:
typedef scoped_allocator_adaptor<_InnerAllocs...> inner_allocator_type;
private:
inner_allocator_type __inner_;
protected:
_LIBCPP_INLINE_VISIBILITY
__scoped_allocator_storage() _NOEXCEPT {}
template <class _OuterA2,
class = typename enable_if<
is_constructible<outer_allocator_type, _OuterA2>::value
>::type>
_LIBCPP_INLINE_VISIBILITY
__scoped_allocator_storage(_OuterA2&& __outerAlloc,
const _InnerAllocs& ...__innerAllocs) _NOEXCEPT
: outer_allocator_type(_VSTD::forward<_OuterA2>(__outerAlloc)),
__inner_(__innerAllocs...) {}
template <class _OuterA2,
class = typename enable_if<
is_constructible<outer_allocator_type, const _OuterA2&>::value
>::type>
_LIBCPP_INLINE_VISIBILITY
__scoped_allocator_storage(
const __scoped_allocator_storage<_OuterA2, _InnerAllocs...>& __other) _NOEXCEPT
: outer_allocator_type(__other.outer_allocator()),
__inner_(__other.inner_allocator()) {}
template <class _OuterA2,
class = typename enable_if<
is_constructible<outer_allocator_type, _OuterA2>::value
>::type>
_LIBCPP_INLINE_VISIBILITY
__scoped_allocator_storage(
__scoped_allocator_storage<_OuterA2, _InnerAllocs...>&& __other) _NOEXCEPT
: outer_allocator_type(_VSTD::move(__other.outer_allocator())),
__inner_(_VSTD::move(__other.inner_allocator())) {}
template <class _OuterA2,
class = typename enable_if<
is_constructible<outer_allocator_type, _OuterA2>::value
>::type>
_LIBCPP_INLINE_VISIBILITY
__scoped_allocator_storage(_OuterA2&& __o,
const inner_allocator_type& __i) _NOEXCEPT
: outer_allocator_type(_VSTD::forward<_OuterA2>(__o)),
__inner_(__i)
{
}
_LIBCPP_INLINE_VISIBILITY
inner_allocator_type& inner_allocator() _NOEXCEPT {return __inner_;}
_LIBCPP_INLINE_VISIBILITY
const inner_allocator_type& inner_allocator() const _NOEXCEPT {return __inner_;}
_LIBCPP_INLINE_VISIBILITY
outer_allocator_type& outer_allocator() _NOEXCEPT
{return static_cast<outer_allocator_type&>(*this);}
_LIBCPP_INLINE_VISIBILITY
const outer_allocator_type& outer_allocator() const _NOEXCEPT
{return static_cast<const outer_allocator_type&>(*this);}
scoped_allocator_adaptor<outer_allocator_type, _InnerAllocs...>
_LIBCPP_INLINE_VISIBILITY
select_on_container_copy_construction() const _NOEXCEPT
{
return scoped_allocator_adaptor<outer_allocator_type, _InnerAllocs...>
(
allocator_traits<outer_allocator_type>::
select_on_container_copy_construction(outer_allocator()),
allocator_traits<inner_allocator_type>::
select_on_container_copy_construction(inner_allocator())
);
}
template <class...> friend class __scoped_allocator_storage;
};
template <class _OuterAlloc>
class __scoped_allocator_storage<_OuterAlloc>
: public _OuterAlloc
{
typedef _OuterAlloc outer_allocator_type;
protected:
typedef scoped_allocator_adaptor<_OuterAlloc> inner_allocator_type;
_LIBCPP_INLINE_VISIBILITY
__scoped_allocator_storage() _NOEXCEPT {}
template <class _OuterA2,
class = typename enable_if<
is_constructible<outer_allocator_type, _OuterA2>::value
>::type>
_LIBCPP_INLINE_VISIBILITY
__scoped_allocator_storage(_OuterA2&& __outerAlloc) _NOEXCEPT
: outer_allocator_type(_VSTD::forward<_OuterA2>(__outerAlloc)) {}
template <class _OuterA2,
class = typename enable_if<
is_constructible<outer_allocator_type, const _OuterA2&>::value
>::type>
_LIBCPP_INLINE_VISIBILITY
__scoped_allocator_storage(
const __scoped_allocator_storage<_OuterA2>& __other) _NOEXCEPT
: outer_allocator_type(__other.outer_allocator()) {}
template <class _OuterA2,
class = typename enable_if<
is_constructible<outer_allocator_type, _OuterA2>::value
>::type>
_LIBCPP_INLINE_VISIBILITY
__scoped_allocator_storage(
__scoped_allocator_storage<_OuterA2>&& __other) _NOEXCEPT
: outer_allocator_type(_VSTD::move(__other.outer_allocator())) {}
_LIBCPP_INLINE_VISIBILITY
inner_allocator_type& inner_allocator() _NOEXCEPT
{return static_cast<inner_allocator_type&>(*this);}
_LIBCPP_INLINE_VISIBILITY
const inner_allocator_type& inner_allocator() const _NOEXCEPT
{return static_cast<const inner_allocator_type&>(*this);}
_LIBCPP_INLINE_VISIBILITY
outer_allocator_type& outer_allocator() _NOEXCEPT
{return static_cast<outer_allocator_type&>(*this);}
_LIBCPP_INLINE_VISIBILITY
const outer_allocator_type& outer_allocator() const _NOEXCEPT
{return static_cast<const outer_allocator_type&>(*this);}
_LIBCPP_INLINE_VISIBILITY
scoped_allocator_adaptor<outer_allocator_type>
select_on_container_copy_construction() const _NOEXCEPT
{return scoped_allocator_adaptor<outer_allocator_type>(
allocator_traits<outer_allocator_type>::
select_on_container_copy_construction(outer_allocator())
);}
__scoped_allocator_storage(const outer_allocator_type& __o,
const inner_allocator_type& __i) _NOEXCEPT;
template <class...> friend class __scoped_allocator_storage;
};
// __outermost
template <class _Alloc>
decltype(declval<_Alloc>().outer_allocator(), true_type())
__has_outer_allocator_test(_Alloc&& __a);
template <class _Alloc>
false_type
__has_outer_allocator_test(const volatile _Alloc& __a);
template <class _Alloc>
struct __has_outer_allocator
: public common_type
<
decltype(__has_outer_allocator_test(declval<_Alloc&>()))
>::type
{
};
template <class _Alloc, bool = __has_outer_allocator<_Alloc>::value>
struct __outermost
{
typedef _Alloc type;
_LIBCPP_INLINE_VISIBILITY
type& operator()(type& __a) const _NOEXCEPT {return __a;}
};
template <class _Alloc>
struct __outermost<_Alloc, true>
{
typedef typename remove_reference
<
decltype(_VSTD::declval<_Alloc>().outer_allocator())
>::type _OuterAlloc;
typedef typename __outermost<_OuterAlloc>::type type;
_LIBCPP_INLINE_VISIBILITY
type& operator()(_Alloc& __a) const _NOEXCEPT
{return __outermost<_OuterAlloc>()(__a.outer_allocator());}
};
template <class _OuterAlloc, class... _InnerAllocs>
class _LIBCPP_TEMPLATE_VIS scoped_allocator_adaptor<_OuterAlloc, _InnerAllocs...>
: public __scoped_allocator_storage<_OuterAlloc, _InnerAllocs...>
{
typedef __scoped_allocator_storage<_OuterAlloc, _InnerAllocs...> base;
typedef allocator_traits<_OuterAlloc> _OuterTraits;
public:
typedef _OuterAlloc outer_allocator_type;
typedef typename base::inner_allocator_type inner_allocator_type;
typedef typename _OuterTraits::size_type size_type;
typedef typename _OuterTraits::difference_type difference_type;
typedef typename _OuterTraits::pointer pointer;
typedef typename _OuterTraits::const_pointer const_pointer;
typedef typename _OuterTraits::void_pointer void_pointer;
typedef typename _OuterTraits::const_void_pointer const_void_pointer;
typedef integral_constant
<
bool,
__get_poc_copy_assignment<outer_allocator_type,
_InnerAllocs...>::value
> propagate_on_container_copy_assignment;
typedef integral_constant
<
bool,
__get_poc_move_assignment<outer_allocator_type,
_InnerAllocs...>::value
> propagate_on_container_move_assignment;
typedef integral_constant
<
bool,
__get_poc_swap<outer_allocator_type, _InnerAllocs...>::value
> propagate_on_container_swap;
typedef integral_constant
<
bool,
__get_is_always_equal<outer_allocator_type, _InnerAllocs...>::value
> is_always_equal;
template <class _Tp>
struct rebind
{
typedef scoped_allocator_adaptor
<
typename _OuterTraits::template rebind_alloc<_Tp>, _InnerAllocs...
> other;
};
_LIBCPP_INLINE_VISIBILITY
scoped_allocator_adaptor() _NOEXCEPT {}
template <class _OuterA2,
class = typename enable_if<
is_constructible<outer_allocator_type, _OuterA2>::value
>::type>
_LIBCPP_INLINE_VISIBILITY
scoped_allocator_adaptor(_OuterA2&& __outerAlloc,
const _InnerAllocs& ...__innerAllocs) _NOEXCEPT
: base(_VSTD::forward<_OuterA2>(__outerAlloc), __innerAllocs...) {}
// scoped_allocator_adaptor(const scoped_allocator_adaptor& __other) = default;
template <class _OuterA2,
class = typename enable_if<
is_constructible<outer_allocator_type, const _OuterA2&>::value
>::type>
_LIBCPP_INLINE_VISIBILITY
scoped_allocator_adaptor(
const scoped_allocator_adaptor<_OuterA2, _InnerAllocs...>& __other) _NOEXCEPT
: base(__other) {}
template <class _OuterA2,
class = typename enable_if<
is_constructible<outer_allocator_type, _OuterA2>::value
>::type>
_LIBCPP_INLINE_VISIBILITY
scoped_allocator_adaptor(
scoped_allocator_adaptor<_OuterA2, _InnerAllocs...>&& __other) _NOEXCEPT
: base(_VSTD::move(__other)) {}
// scoped_allocator_adaptor& operator=(const scoped_allocator_adaptor&) = default;
// scoped_allocator_adaptor& operator=(scoped_allocator_adaptor&&) = default;
// ~scoped_allocator_adaptor() = default;
_LIBCPP_INLINE_VISIBILITY
inner_allocator_type& inner_allocator() _NOEXCEPT
{return base::inner_allocator();}
_LIBCPP_INLINE_VISIBILITY
const inner_allocator_type& inner_allocator() const _NOEXCEPT
{return base::inner_allocator();}
_LIBCPP_INLINE_VISIBILITY
outer_allocator_type& outer_allocator() _NOEXCEPT
{return base::outer_allocator();}
_LIBCPP_INLINE_VISIBILITY
const outer_allocator_type& outer_allocator() const _NOEXCEPT
{return base::outer_allocator();}
_LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
pointer allocate(size_type __n)
{return allocator_traits<outer_allocator_type>::
allocate(outer_allocator(), __n);}
_LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
pointer allocate(size_type __n, const_void_pointer __hint)
{return allocator_traits<outer_allocator_type>::
allocate(outer_allocator(), __n, __hint);}
_LIBCPP_INLINE_VISIBILITY
void deallocate(pointer __p, size_type __n) _NOEXCEPT
{allocator_traits<outer_allocator_type>::
deallocate(outer_allocator(), __p, __n);}
_LIBCPP_INLINE_VISIBILITY
size_type max_size() const
{return allocator_traits<outer_allocator_type>::max_size(outer_allocator());}
template <class _Tp, class... _Args>
_LIBCPP_INLINE_VISIBILITY
void construct(_Tp* __p, _Args&& ...__args)
{__construct(__uses_alloc_ctor<_Tp, inner_allocator_type&, _Args...>(),
__p, _VSTD::forward<_Args>(__args)...);}
template <class _T1, class _T2, class... _Args1, class... _Args2>
void construct(pair<_T1, _T2>* __p, piecewise_construct_t,
tuple<_Args1...> __x, tuple<_Args2...> __y)
{
typedef __outermost<outer_allocator_type> _OM;
allocator_traits<typename _OM::type>::construct(
_OM()(outer_allocator()), __p, piecewise_construct
, __transform_tuple(
typename __uses_alloc_ctor<
_T1, inner_allocator_type&, _Args1...
>::type()
, _VSTD::move(__x)
, typename __make_tuple_indices<sizeof...(_Args1)>::type{}
)
, __transform_tuple(
typename __uses_alloc_ctor<
_T2, inner_allocator_type&, _Args2...
>::type()
, _VSTD::move(__y)
, typename __make_tuple_indices<sizeof...(_Args2)>::type{}
)
);
}
template <class _T1, class _T2>
void construct(pair<_T1, _T2>* __p)
{ construct(__p, piecewise_construct, tuple<>{}, tuple<>{}); }
template <class _T1, class _T2, class _Up, class _Vp>
void construct(pair<_T1, _T2>* __p, _Up&& __x, _Vp&& __y) {
construct(__p, piecewise_construct,
_VSTD::forward_as_tuple(_VSTD::forward<_Up>(__x)),
_VSTD::forward_as_tuple(_VSTD::forward<_Vp>(__y)));
}
template <class _T1, class _T2, class _Up, class _Vp>
void construct(pair<_T1, _T2>* __p, const pair<_Up, _Vp>& __x) {
construct(__p, piecewise_construct,
_VSTD::forward_as_tuple(__x.first),
_VSTD::forward_as_tuple(__x.second));
}
template <class _T1, class _T2, class _Up, class _Vp>
void construct(pair<_T1, _T2>* __p, pair<_Up, _Vp>&& __x) {
construct(__p, piecewise_construct,
_VSTD::forward_as_tuple(_VSTD::forward<_Up>(__x.first)),
_VSTD::forward_as_tuple(_VSTD::forward<_Vp>(__x.second)));
}
template <class _Tp>
_LIBCPP_INLINE_VISIBILITY
void destroy(_Tp* __p)
{
typedef __outermost<outer_allocator_type> _OM;
allocator_traits<typename _OM::type>::
destroy(_OM()(outer_allocator()), __p);
}
_LIBCPP_INLINE_VISIBILITY
scoped_allocator_adaptor select_on_container_copy_construction() const _NOEXCEPT
{return base::select_on_container_copy_construction();}
private:
template <class _OuterA2,
class = typename enable_if<
is_constructible<outer_allocator_type, _OuterA2>::value
>::type>
_LIBCPP_INLINE_VISIBILITY
scoped_allocator_adaptor(_OuterA2&& __o,
const inner_allocator_type& __i) _NOEXCEPT
: base(_VSTD::forward<_OuterA2>(__o), __i) {}
template <class _Tp, class... _Args>
_LIBCPP_INLINE_VISIBILITY
void __construct(integral_constant<int, 0>, _Tp* __p, _Args&& ...__args)
{
typedef __outermost<outer_allocator_type> _OM;
allocator_traits<typename _OM::type>::construct
(
_OM()(outer_allocator()),
__p,
_VSTD::forward<_Args>(__args)...
);
}
template <class _Tp, class... _Args>
_LIBCPP_INLINE_VISIBILITY
void __construct(integral_constant<int, 1>, _Tp* __p, _Args&& ...__args)
{
typedef __outermost<outer_allocator_type> _OM;
allocator_traits<typename _OM::type>::construct
(
_OM()(outer_allocator()),
__p, allocator_arg, inner_allocator(),
_VSTD::forward<_Args>(__args)...
);
}
template <class _Tp, class... _Args>
_LIBCPP_INLINE_VISIBILITY
void __construct(integral_constant<int, 2>, _Tp* __p, _Args&& ...__args)
{
typedef __outermost<outer_allocator_type> _OM;
allocator_traits<typename _OM::type>::construct
(
_OM()(outer_allocator()),
__p,
_VSTD::forward<_Args>(__args)...,
inner_allocator()
);
}
template <class ..._Args, size_t ..._Idx>
_LIBCPP_INLINE_VISIBILITY
tuple<_Args&&...>
__transform_tuple(integral_constant<int, 0>, tuple<_Args...>&& __t,
__tuple_indices<_Idx...>)
{
return _VSTD::forward_as_tuple(_VSTD::get<_Idx>(_VSTD::move(__t))...);
}
template <class ..._Args, size_t ..._Idx>
_LIBCPP_INLINE_VISIBILITY
tuple<allocator_arg_t, inner_allocator_type&, _Args&&...>
__transform_tuple(integral_constant<int, 1>, tuple<_Args...> && __t,
__tuple_indices<_Idx...>)
{
using _Tup = tuple<allocator_arg_t, inner_allocator_type&, _Args&&...>;
return _Tup(allocator_arg, inner_allocator(),
_VSTD::get<_Idx>(_VSTD::move(__t))...);
}
template <class ..._Args, size_t ..._Idx>
_LIBCPP_INLINE_VISIBILITY
tuple<_Args&&..., inner_allocator_type&>
__transform_tuple(integral_constant<int, 2>, tuple<_Args...> && __t,
__tuple_indices<_Idx...>)
{
using _Tup = tuple<_Args&&..., inner_allocator_type&>;
return _Tup(_VSTD::get<_Idx>(_VSTD::move(__t))..., inner_allocator());
}
template <class...> friend class __scoped_allocator_storage;
};
template <class _OuterA1, class _OuterA2>
inline _LIBCPP_INLINE_VISIBILITY
bool
operator==(const scoped_allocator_adaptor<_OuterA1>& __a,
const scoped_allocator_adaptor<_OuterA2>& __b) _NOEXCEPT
{
return __a.outer_allocator() == __b.outer_allocator();
}
template <class _OuterA1, class _OuterA2, class _InnerA0, class... _InnerAllocs>
inline _LIBCPP_INLINE_VISIBILITY
bool
operator==(const scoped_allocator_adaptor<_OuterA1, _InnerA0, _InnerAllocs...>& __a,
const scoped_allocator_adaptor<_OuterA2, _InnerA0, _InnerAllocs...>& __b) _NOEXCEPT
{
return __a.outer_allocator() == __b.outer_allocator() &&
__a.inner_allocator() == __b.inner_allocator();
}
template <class _OuterA1, class _OuterA2, class... _InnerAllocs>
inline _LIBCPP_INLINE_VISIBILITY
bool
operator!=(const scoped_allocator_adaptor<_OuterA1, _InnerAllocs...>& __a,
const scoped_allocator_adaptor<_OuterA2, _InnerAllocs...>& __b) _NOEXCEPT
{
return !(__a == __b);
}
#endif // !defined(_LIBCPP_CXX03_LANG)
_LIBCPP_END_NAMESPACE_STD
#endif // _LIBCPP_SCOPED_ALLOCATOR
| 25,817 | 685 | jart/cosmopolitan | false |
cosmopolitan/third_party/libcxx/algorithm.cc | // clang-format off
//===----------------------- algorithm.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/algorithm"
#include "third_party/libcxx/random"
#ifndef _LIBCPP_HAS_NO_THREADS
#include "third_party/libcxx/mutex"
#if defined(__unix__) && !defined(__ANDROID__) && defined(__ELF__) && defined(_LIBCPP_HAS_COMMENT_LIB_PRAGMA)
#pragma comment(lib, "pthread")
#endif
#endif
_LIBCPP_BEGIN_NAMESPACE_STD
template void __sort<__less<char>&, char*>(char*, char*, __less<char>&);
template void __sort<__less<wchar_t>&, wchar_t*>(wchar_t*, wchar_t*, __less<wchar_t>&);
template void __sort<__less<signed char>&, signed char*>(signed char*, signed char*, __less<signed char>&);
template void __sort<__less<unsigned char>&, unsigned char*>(unsigned char*, unsigned char*, __less<unsigned char>&);
template void __sort<__less<short>&, short*>(short*, short*, __less<short>&);
template void __sort<__less<unsigned short>&, unsigned short*>(unsigned short*, unsigned short*, __less<unsigned short>&);
template void __sort<__less<int>&, int*>(int*, int*, __less<int>&);
template void __sort<__less<unsigned>&, unsigned*>(unsigned*, unsigned*, __less<unsigned>&);
template void __sort<__less<long>&, long*>(long*, long*, __less<long>&);
template void __sort<__less<unsigned long>&, unsigned long*>(unsigned long*, unsigned long*, __less<unsigned long>&);
template void __sort<__less<long long>&, long long*>(long long*, long long*, __less<long long>&);
template void __sort<__less<unsigned long long>&, unsigned long long*>(unsigned long long*, unsigned long long*, __less<unsigned long long>&);
template void __sort<__less<float>&, float*>(float*, float*, __less<float>&);
template void __sort<__less<double>&, double*>(double*, double*, __less<double>&);
template void __sort<__less<long double>&, long double*>(long double*, long double*, __less<long double>&);
template bool __insertion_sort_incomplete<__less<char>&, char*>(char*, char*, __less<char>&);
template bool __insertion_sort_incomplete<__less<wchar_t>&, wchar_t*>(wchar_t*, wchar_t*, __less<wchar_t>&);
template bool __insertion_sort_incomplete<__less<signed char>&, signed char*>(signed char*, signed char*, __less<signed char>&);
template bool __insertion_sort_incomplete<__less<unsigned char>&, unsigned char*>(unsigned char*, unsigned char*, __less<unsigned char>&);
template bool __insertion_sort_incomplete<__less<short>&, short*>(short*, short*, __less<short>&);
template bool __insertion_sort_incomplete<__less<unsigned short>&, unsigned short*>(unsigned short*, unsigned short*, __less<unsigned short>&);
template bool __insertion_sort_incomplete<__less<int>&, int*>(int*, int*, __less<int>&);
template bool __insertion_sort_incomplete<__less<unsigned>&, unsigned*>(unsigned*, unsigned*, __less<unsigned>&);
template bool __insertion_sort_incomplete<__less<long>&, long*>(long*, long*, __less<long>&);
template bool __insertion_sort_incomplete<__less<unsigned long>&, unsigned long*>(unsigned long*, unsigned long*, __less<unsigned long>&);
template bool __insertion_sort_incomplete<__less<long long>&, long long*>(long long*, long long*, __less<long long>&);
template bool __insertion_sort_incomplete<__less<unsigned long long>&, unsigned long long*>(unsigned long long*, unsigned long long*, __less<unsigned long long>&);
template bool __insertion_sort_incomplete<__less<float>&, float*>(float*, float*, __less<float>&);
template bool __insertion_sort_incomplete<__less<double>&, double*>(double*, double*, __less<double>&);
template bool __insertion_sort_incomplete<__less<long double>&, long double*>(long double*, long double*, __less<long double>&);
template unsigned __sort5<__less<long double>&, long double*>(long double*, long double*, long double*, long double*, long double*, __less<long double>&);
#ifndef _LIBCPP_HAS_NO_THREADS
_LIBCPP_SAFE_STATIC static __libcpp_mutex_t __rs_mut = _LIBCPP_MUTEX_INITIALIZER;
#endif
#if _LIBCPP_STD_VER <= 14 || defined(_LIBCPP_ENABLE_CXX17_REMOVED_RANDOM_SHUFFLE) \
|| defined(_LIBCPP_BUILDING_LIBRARY)
unsigned __rs_default::__c_ = 0;
__rs_default::__rs_default()
{
#ifndef _LIBCPP_HAS_NO_THREADS
__libcpp_mutex_lock(&__rs_mut);
#endif
__c_ = 1;
}
__rs_default::__rs_default(const __rs_default&)
{
++__c_;
}
__rs_default::~__rs_default()
{
#ifndef _LIBCPP_HAS_NO_THREADS
if (--__c_ == 0)
__libcpp_mutex_unlock(&__rs_mut);
#else
--__c_;
#endif
}
__rs_default::result_type
__rs_default::operator()()
{
static mt19937 __rs_g;
return __rs_g();
}
#endif
__rs_default
__rs_get()
{
return __rs_default();
}
_LIBCPP_END_NAMESPACE_STD
| 4,902 | 97 | jart/cosmopolitan | false |
cosmopolitan/third_party/libcxx/istream | // -*- C++ -*-
//===--------------------------- istream ----------------------------------===//
//
// 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_ISTREAM
#define _LIBCPP_ISTREAM
#include "third_party/libcxx/__config"
#include "third_party/libcxx/version"
#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
/*
istream synopsis
template <class charT, class traits = char_traits<charT> >
class basic_istream
: virtual public basic_ios<charT,traits>
{
public:
// types (inherited from basic_ios (27.5.4)):
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.7.1.1.1 Constructor/destructor:
explicit basic_istream(basic_streambuf<char_type, traits_type>* sb);
basic_istream(basic_istream&& rhs);
virtual ~basic_istream();
// 27.7.1.1.2 Assign/swap:
basic_istream& operator=(basic_istream&& rhs);
void swap(basic_istream& rhs);
// 27.7.1.1.3 Prefix/suffix:
class sentry;
// 27.7.1.2 Formatted input:
basic_istream& operator>>(basic_istream& (*pf)(basic_istream&));
basic_istream& operator>>(basic_ios<char_type, traits_type>&
(*pf)(basic_ios<char_type, traits_type>&));
basic_istream& operator>>(ios_base& (*pf)(ios_base&));
basic_istream& operator>>(basic_streambuf<char_type, traits_type>* sb);
basic_istream& operator>>(bool& n);
basic_istream& operator>>(short& n);
basic_istream& operator>>(unsigned short& n);
basic_istream& operator>>(int& n);
basic_istream& operator>>(unsigned int& n);
basic_istream& operator>>(long& n);
basic_istream& operator>>(unsigned long& n);
basic_istream& operator>>(long long& n);
basic_istream& operator>>(unsigned long long& n);
basic_istream& operator>>(float& f);
basic_istream& operator>>(double& f);
basic_istream& operator>>(long double& f);
basic_istream& operator>>(void*& p);
// 27.7.1.3 Unformatted input:
streamsize gcount() const;
int_type get();
basic_istream& get(char_type& c);
basic_istream& get(char_type* s, streamsize n);
basic_istream& get(char_type* s, streamsize n, char_type delim);
basic_istream& get(basic_streambuf<char_type,traits_type>& sb);
basic_istream& get(basic_streambuf<char_type,traits_type>& sb, char_type delim);
basic_istream& getline(char_type* s, streamsize n);
basic_istream& getline(char_type* s, streamsize n, char_type delim);
basic_istream& ignore(streamsize n = 1, int_type delim = traits_type::eof());
int_type peek();
basic_istream& read (char_type* s, streamsize n);
streamsize readsome(char_type* s, streamsize n);
basic_istream& putback(char_type c);
basic_istream& unget();
int sync();
pos_type tellg();
basic_istream& seekg(pos_type);
basic_istream& seekg(off_type, ios_base::seekdir);
protected:
basic_istream(const basic_istream& rhs) = delete;
basic_istream(basic_istream&& rhs);
// 27.7.2.1.2 Assign/swap:
basic_istream& operator=(const basic_istream& rhs) = delete;
basic_istream& operator=(basic_istream&& rhs);
void swap(basic_istream& rhs);
};
// 27.7.1.2.3 character extraction templates:
template<class charT, class traits>
basic_istream<charT,traits>& operator>>(basic_istream<charT,traits>&, charT&);
template<class traits>
basic_istream<char,traits>& operator>>(basic_istream<char,traits>&, unsigned char&);
template<class traits>
basic_istream<char,traits>& operator>>(basic_istream<char,traits>&, signed char&);
template<class charT, class traits>
basic_istream<charT,traits>& operator>>(basic_istream<charT,traits>&, charT*);
template<class traits>
basic_istream<char,traits>& operator>>(basic_istream<char,traits>&, unsigned char*);
template<class traits>
basic_istream<char,traits>& operator>>(basic_istream<char,traits>&, signed char*);
template <class charT, class traits>
void
swap(basic_istream<charT, traits>& x, basic_istream<charT, traits>& y);
typedef basic_istream<char> istream;
typedef basic_istream<wchar_t> wistream;
template <class charT, class traits = char_traits<charT> >
class basic_iostream :
public basic_istream<charT,traits>,
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;
// constructor/destructor
explicit basic_iostream(basic_streambuf<char_type, traits_type>* sb);
basic_iostream(basic_iostream&& rhs);
virtual ~basic_iostream();
// assign/swap
basic_iostream& operator=(basic_iostream&& rhs);
void swap(basic_iostream& rhs);
};
template <class charT, class traits>
void
swap(basic_iostream<charT, traits>& x, basic_iostream<charT, traits>& y);
typedef basic_iostream<char> iostream;
typedef basic_iostream<wchar_t> wiostream;
template <class charT, class traits>
basic_istream<charT,traits>&
ws(basic_istream<charT,traits>& is);
template <class charT, class traits, class T>
basic_istream<charT, traits>&
operator>>(basic_istream<charT, traits>&& is, T& x);
} // std
*/
template <class _CharT, class _Traits>
class _LIBCPP_TEMPLATE_VIS basic_istream
: virtual public basic_ios<_CharT, _Traits>
{
streamsize __gc_;
public:
// types (inherited from basic_ios (27.5.4)):
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.7.1.1.1 Constructor/destructor:
inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1
explicit basic_istream(basic_streambuf<char_type, traits_type>* __sb) : __gc_(0)
{ this->init(__sb); }
virtual ~basic_istream();
protected:
#ifndef _LIBCPP_CXX03_LANG
inline _LIBCPP_INLINE_VISIBILITY
basic_istream(basic_istream&& __rhs);
// 27.7.1.1.2 Assign/swap:
inline _LIBCPP_INLINE_VISIBILITY
basic_istream& operator=(basic_istream&& __rhs);
#endif
inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1
void swap(basic_istream& __rhs) {
_VSTD::swap(__gc_, __rhs.__gc_);
basic_ios<char_type, traits_type>::swap(__rhs);
}
#ifndef _LIBCPP_CXX03_LANG
basic_istream (const basic_istream& __rhs) = delete;
basic_istream& operator=(const basic_istream& __rhs) = delete;
#endif
public:
// 27.7.1.1.3 Prefix/suffix:
class _LIBCPP_TEMPLATE_VIS sentry;
// 27.7.1.2 Formatted input:
inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1
basic_istream& operator>>(basic_istream& (*__pf)(basic_istream&))
{ return __pf(*this); }
inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1
basic_istream& operator>>(basic_ios<char_type, traits_type>&
(*__pf)(basic_ios<char_type, traits_type>&))
{ __pf(*this); return *this; }
inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1
basic_istream& operator>>(ios_base& (*__pf)(ios_base&))
{ __pf(*this); return *this; }
basic_istream& operator>>(basic_streambuf<char_type, traits_type>* __sb);
basic_istream& operator>>(bool& __n);
basic_istream& operator>>(short& __n);
basic_istream& operator>>(unsigned short& __n);
basic_istream& operator>>(int& __n);
basic_istream& operator>>(unsigned int& __n);
basic_istream& operator>>(long& __n);
basic_istream& operator>>(unsigned long& __n);
basic_istream& operator>>(long long& __n);
basic_istream& operator>>(unsigned long long& __n);
basic_istream& operator>>(float& __f);
basic_istream& operator>>(double& __f);
basic_istream& operator>>(long double& __f);
basic_istream& operator>>(void*& __p);
// 27.7.1.3 Unformatted input:
_LIBCPP_INLINE_VISIBILITY
streamsize gcount() const {return __gc_;}
int_type get();
inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1
basic_istream& get(char_type& __c) {
int_type __ch = get();
if (__ch != traits_type::eof())
__c = traits_type::to_char_type(__ch);
return *this;
}
inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1
basic_istream& get(char_type* __s, streamsize __n)
{ return get(__s, __n, this->widen('\n')); }
basic_istream& get(char_type* __s, streamsize __n, char_type __dlm);
inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1
basic_istream& get(basic_streambuf<char_type, traits_type>& __sb)
{ return get(__sb, this->widen('\n')); }
basic_istream& get(basic_streambuf<char_type, traits_type>& __sb, char_type __dlm);
inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1
basic_istream& getline(char_type* __s, streamsize __n)
{ return getline(__s, __n, this->widen('\n')); }
basic_istream& getline(char_type* __s, streamsize __n, char_type __dlm);
basic_istream& ignore(streamsize __n = 1, int_type __dlm = traits_type::eof());
int_type peek();
basic_istream& read (char_type* __s, streamsize __n);
streamsize readsome(char_type* __s, streamsize __n);
basic_istream& putback(char_type __c);
basic_istream& unget();
int sync();
pos_type tellg();
basic_istream& seekg(pos_type __pos);
basic_istream& seekg(off_type __off, ios_base::seekdir __dir);
};
template <class _CharT, class _Traits>
class _LIBCPP_TEMPLATE_VIS basic_istream<_CharT, _Traits>::sentry
{
bool __ok_;
sentry(const sentry&); // = delete;
sentry& operator=(const sentry&); // = delete;
public:
explicit sentry(basic_istream<_CharT, _Traits>& __is, bool __noskipws = false);
// ~sentry() = default;
_LIBCPP_INLINE_VISIBILITY
_LIBCPP_EXPLICIT
operator bool() const {return __ok_;}
};
template <class _CharT, class _Traits>
basic_istream<_CharT, _Traits>::sentry::sentry(basic_istream<_CharT, _Traits>& __is,
bool __noskipws)
: __ok_(false)
{
if (__is.good())
{
if (__is.tie())
__is.tie()->flush();
if (!__noskipws && (__is.flags() & ios_base::skipws))
{
typedef istreambuf_iterator<_CharT, _Traits> _Ip;
const ctype<_CharT>& __ct = use_facet<ctype<_CharT> >(__is.getloc());
_Ip __i(__is);
_Ip __eof;
for (; __i != __eof; ++__i)
if (!__ct.is(__ct.space, *__i))
break;
if (__i == __eof)
__is.setstate(ios_base::failbit | ios_base::eofbit);
}
__ok_ = __is.good();
}
else
__is.setstate(ios_base::failbit);
}
#ifndef _LIBCPP_CXX03_LANG
template <class _CharT, class _Traits>
basic_istream<_CharT, _Traits>::basic_istream(basic_istream&& __rhs)
: __gc_(__rhs.__gc_)
{
__rhs.__gc_ = 0;
this->move(__rhs);
}
template <class _CharT, class _Traits>
basic_istream<_CharT, _Traits>&
basic_istream<_CharT, _Traits>::operator=(basic_istream&& __rhs)
{
swap(__rhs);
return *this;
}
#endif // _LIBCPP_CXX03_LANG
template <class _CharT, class _Traits>
basic_istream<_CharT, _Traits>::~basic_istream()
{
}
template <class _Tp, class _CharT, class _Traits>
inline _LIBCPP_INLINE_VISIBILITY
basic_istream<_CharT, _Traits>&
__input_arithmetic(basic_istream<_CharT, _Traits>& __is, _Tp& __n) {
ios_base::iostate __state = ios_base::goodbit;
typename basic_istream<_CharT, _Traits>::sentry __s(__is);
if (__s)
{
#ifndef _LIBCPP_NO_EXCEPTIONS
try
{
#endif // _LIBCPP_NO_EXCEPTIONS
typedef istreambuf_iterator<_CharT, _Traits> _Ip;
typedef num_get<_CharT, _Ip> _Fp;
use_facet<_Fp>(__is.getloc()).get(_Ip(__is), _Ip(), __is, __state, __n);
#ifndef _LIBCPP_NO_EXCEPTIONS
}
catch (...)
{
__state |= ios_base::badbit;
__is.__setstate_nothrow(__state);
if (__is.exceptions() & ios_base::badbit)
{
throw;
}
}
#endif
__is.setstate(__state);
}
return __is;
}
template <class _CharT, class _Traits>
basic_istream<_CharT, _Traits>&
basic_istream<_CharT, _Traits>::operator>>(unsigned short& __n)
{
return _VSTD::__input_arithmetic<unsigned short>(*this, __n);
}
template <class _CharT, class _Traits>
basic_istream<_CharT, _Traits>&
basic_istream<_CharT, _Traits>::operator>>(unsigned int& __n)
{
return _VSTD::__input_arithmetic<unsigned int>(*this, __n);
}
template <class _CharT, class _Traits>
basic_istream<_CharT, _Traits>&
basic_istream<_CharT, _Traits>::operator>>(long& __n)
{
return _VSTD::__input_arithmetic<long>(*this, __n);
}
template <class _CharT, class _Traits>
basic_istream<_CharT, _Traits>&
basic_istream<_CharT, _Traits>::operator>>(unsigned long& __n)
{
return _VSTD::__input_arithmetic<unsigned long>(*this, __n);
}
template <class _CharT, class _Traits>
basic_istream<_CharT, _Traits>&
basic_istream<_CharT, _Traits>::operator>>(long long& __n)
{
return _VSTD::__input_arithmetic<long long>(*this, __n);
}
template <class _CharT, class _Traits>
basic_istream<_CharT, _Traits>&
basic_istream<_CharT, _Traits>::operator>>(unsigned long long& __n)
{
return _VSTD::__input_arithmetic<unsigned long long>(*this, __n);
}
template <class _CharT, class _Traits>
basic_istream<_CharT, _Traits>&
basic_istream<_CharT, _Traits>::operator>>(float& __n)
{
return _VSTD::__input_arithmetic<float>(*this, __n);
}
template <class _CharT, class _Traits>
basic_istream<_CharT, _Traits>&
basic_istream<_CharT, _Traits>::operator>>(double& __n)
{
return _VSTD::__input_arithmetic<double>(*this, __n);
}
template <class _CharT, class _Traits>
basic_istream<_CharT, _Traits>&
basic_istream<_CharT, _Traits>::operator>>(long double& __n)
{
return _VSTD::__input_arithmetic<long double>(*this, __n);
}
template <class _CharT, class _Traits>
basic_istream<_CharT, _Traits>&
basic_istream<_CharT, _Traits>::operator>>(bool& __n)
{
return _VSTD::__input_arithmetic<bool>(*this, __n);
}
template <class _CharT, class _Traits>
basic_istream<_CharT, _Traits>&
basic_istream<_CharT, _Traits>::operator>>(void*& __n)
{
return _VSTD::__input_arithmetic<void*>(*this, __n);
}
template <class _Tp, class _CharT, class _Traits>
inline _LIBCPP_INLINE_VISIBILITY
basic_istream<_CharT, _Traits>&
__input_arithmetic_with_numeric_limits(basic_istream<_CharT, _Traits>& __is, _Tp& __n) {
ios_base::iostate __state = ios_base::goodbit;
typename basic_istream<_CharT, _Traits>::sentry __s(__is);
if (__s)
{
#ifndef _LIBCPP_NO_EXCEPTIONS
try
{
#endif // _LIBCPP_NO_EXCEPTIONS
typedef istreambuf_iterator<_CharT, _Traits> _Ip;
typedef num_get<_CharT, _Ip> _Fp;
long __temp;
use_facet<_Fp>(__is.getloc()).get(_Ip(__is), _Ip(), __is, __state, __temp);
if (__temp < numeric_limits<_Tp>::min())
{
__state |= ios_base::failbit;
__n = numeric_limits<_Tp>::min();
}
else if (__temp > numeric_limits<_Tp>::max())
{
__state |= ios_base::failbit;
__n = numeric_limits<_Tp>::max();
}
else
{
__n = static_cast<_Tp>(__temp);
}
#ifndef _LIBCPP_NO_EXCEPTIONS
}
catch (...)
{
__state |= ios_base::badbit;
__is.__setstate_nothrow(__state);
if (__is.exceptions() & ios_base::badbit)
{
throw;
}
}
#endif // _LIBCPP_NO_EXCEPTIONS
__is.setstate(__state);
}
return __is;
}
template <class _CharT, class _Traits>
basic_istream<_CharT, _Traits>&
basic_istream<_CharT, _Traits>::operator>>(short& __n)
{
return _VSTD::__input_arithmetic_with_numeric_limits<short>(*this, __n);
}
template <class _CharT, class _Traits>
basic_istream<_CharT, _Traits>&
basic_istream<_CharT, _Traits>::operator>>(int& __n)
{
return _VSTD::__input_arithmetic_with_numeric_limits<int>(*this, __n);
}
template<class _CharT, class _Traits>
_LIBCPP_INLINE_VISIBILITY
basic_istream<_CharT, _Traits>&
__input_c_string(basic_istream<_CharT, _Traits>& __is, _CharT* __p, size_t __n)
{
ios_base::iostate __state = ios_base::goodbit;
typename basic_istream<_CharT, _Traits>::sentry __sen(__is);
if (__sen)
{
#ifndef _LIBCPP_NO_EXCEPTIONS
try
{
#endif
_CharT* __s = __p;
const ctype<_CharT>& __ct = use_facet<ctype<_CharT> >(__is.getloc());
while (__s != __p + (__n-1))
{
typename _Traits::int_type __i = __is.rdbuf()->sgetc();
if (_Traits::eq_int_type(__i, _Traits::eof()))
{
__state |= ios_base::eofbit;
break;
}
_CharT __ch = _Traits::to_char_type(__i);
if (__ct.is(__ct.space, __ch))
break;
*__s++ = __ch;
__is.rdbuf()->sbumpc();
}
*__s = _CharT();
__is.width(0);
if (__s == __p)
__state |= ios_base::failbit;
#ifndef _LIBCPP_NO_EXCEPTIONS
}
catch (...)
{
__state |= ios_base::badbit;
__is.__setstate_nothrow(__state);
if (__is.exceptions() & ios_base::badbit)
{
throw;
}
}
#endif
__is.setstate(__state);
}
return __is;
}
#if _LIBCPP_STD_VER > 17
template<class _CharT, class _Traits, size_t _Np>
inline _LIBCPP_INLINE_VISIBILITY
basic_istream<_CharT, _Traits>&
operator>>(basic_istream<_CharT, _Traits>& __is, _CharT (&__buf)[_Np])
{
size_t __n = _Np;
if (__is.width() > 0)
__n = _VSTD::min(size_t(__is.width()), _Np);
return _VSTD::__input_c_string(__is, __buf, __n);
}
template<class _Traits, size_t _Np>
inline _LIBCPP_INLINE_VISIBILITY
basic_istream<char, _Traits>&
operator>>(basic_istream<char, _Traits>& __is, unsigned char (&__buf)[_Np])
{
return __is >> (char(&)[_Np])__buf;
}
template<class _Traits, size_t _Np>
inline _LIBCPP_INLINE_VISIBILITY
basic_istream<char, _Traits>&
operator>>(basic_istream<char, _Traits>& __is, signed char (&__buf)[_Np])
{
return __is >> (char(&)[_Np])__buf;
}
#else
template<class _CharT, class _Traits>
inline _LIBCPP_INLINE_VISIBILITY
basic_istream<_CharT, _Traits>&
operator>>(basic_istream<_CharT, _Traits>& __is, _CharT* __s)
{
streamsize __n = __is.width();
if (__n <= 0)
__n = numeric_limits<streamsize>::max() / sizeof(_CharT) - 1;
return _VSTD::__input_c_string(__is, __s, size_t(__n));
}
template<class _Traits>
inline _LIBCPP_INLINE_VISIBILITY
basic_istream<char, _Traits>&
operator>>(basic_istream<char, _Traits>& __is, unsigned char* __s)
{
return __is >> (char*)__s;
}
template<class _Traits>
inline _LIBCPP_INLINE_VISIBILITY
basic_istream<char, _Traits>&
operator>>(basic_istream<char, _Traits>& __is, signed char* __s)
{
return __is >> (char*)__s;
}
#endif // _LIBCPP_STD_VER > 17
template<class _CharT, class _Traits>
basic_istream<_CharT, _Traits>&
operator>>(basic_istream<_CharT, _Traits>& __is, _CharT& __c)
{
ios_base::iostate __state = ios_base::goodbit;
typename basic_istream<_CharT, _Traits>::sentry __sen(__is);
if (__sen)
{
#ifndef _LIBCPP_NO_EXCEPTIONS
try
{
#endif
typename _Traits::int_type __i = __is.rdbuf()->sbumpc();
if (_Traits::eq_int_type(__i, _Traits::eof()))
__state |= ios_base::eofbit | ios_base::failbit;
else
__c = _Traits::to_char_type(__i);
#ifndef _LIBCPP_NO_EXCEPTIONS
}
catch (...)
{
__state |= ios_base::badbit;
__is.__setstate_nothrow(__state);
if (__is.exceptions() & ios_base::badbit)
{
throw;
}
}
#endif
__is.setstate(__state);
}
return __is;
}
template<class _Traits>
inline _LIBCPP_INLINE_VISIBILITY
basic_istream<char, _Traits>&
operator>>(basic_istream<char, _Traits>& __is, unsigned char& __c)
{
return __is >> (char&)__c;
}
template<class _Traits>
inline _LIBCPP_INLINE_VISIBILITY
basic_istream<char, _Traits>&
operator>>(basic_istream<char, _Traits>& __is, signed char& __c)
{
return __is >> (char&)__c;
}
template<class _CharT, class _Traits>
basic_istream<_CharT, _Traits>&
basic_istream<_CharT, _Traits>::operator>>(basic_streambuf<char_type, traits_type>* __sb)
{
ios_base::iostate __state = ios_base::goodbit;
__gc_ = 0;
sentry __s(*this, true);
if (__s)
{
if (__sb)
{
#ifndef _LIBCPP_NO_EXCEPTIONS
try
{
#endif // _LIBCPP_NO_EXCEPTIONS
while (true)
{
typename traits_type::int_type __i = this->rdbuf()->sgetc();
if (traits_type::eq_int_type(__i, _Traits::eof()))
{
__state |= ios_base::eofbit;
break;
}
if (traits_type::eq_int_type(
__sb->sputc(traits_type::to_char_type(__i)),
traits_type::eof()))
break;
++__gc_;
this->rdbuf()->sbumpc();
}
if (__gc_ == 0)
__state |= ios_base::failbit;
#ifndef _LIBCPP_NO_EXCEPTIONS
}
catch (...)
{
__state |= ios_base::badbit;
if (__gc_ == 0)
__state |= ios_base::failbit;
this->__setstate_nothrow(__state);
if (this->exceptions() & ios_base::failbit || this->exceptions() & ios_base::badbit)
{
throw;
}
}
#endif // _LIBCPP_NO_EXCEPTIONS
}
else
{
__state |= ios_base::failbit;
}
this->setstate(__state);
}
return *this;
}
template<class _CharT, class _Traits>
typename basic_istream<_CharT, _Traits>::int_type
basic_istream<_CharT, _Traits>::get()
{
ios_base::iostate __state = ios_base::goodbit;
__gc_ = 0;
int_type __r = traits_type::eof();
sentry __s(*this, true);
if (__s)
{
#ifndef _LIBCPP_NO_EXCEPTIONS
try
{
#endif
__r = this->rdbuf()->sbumpc();
if (traits_type::eq_int_type(__r, traits_type::eof()))
__state |= ios_base::failbit | ios_base::eofbit;
else
__gc_ = 1;
#ifndef _LIBCPP_NO_EXCEPTIONS
}
catch (...)
{
this->__setstate_nothrow(this->rdstate() | ios_base::badbit);
if (this->exceptions() & ios_base::badbit)
{
throw;
}
}
#endif
this->setstate(__state);
}
return __r;
}
template<class _CharT, class _Traits>
basic_istream<_CharT, _Traits>&
basic_istream<_CharT, _Traits>::get(char_type* __s, streamsize __n, char_type __dlm)
{
ios_base::iostate __state = ios_base::goodbit;
__gc_ = 0;
sentry __sen(*this, true);
if (__sen)
{
if (__n > 0)
{
#ifndef _LIBCPP_NO_EXCEPTIONS
try
{
#endif
while (__gc_ < __n-1)
{
int_type __i = this->rdbuf()->sgetc();
if (traits_type::eq_int_type(__i, traits_type::eof()))
{
__state |= ios_base::eofbit;
break;
}
char_type __ch = traits_type::to_char_type(__i);
if (traits_type::eq(__ch, __dlm))
break;
*__s++ = __ch;
++__gc_;
this->rdbuf()->sbumpc();
}
if (__gc_ == 0)
__state |= ios_base::failbit;
#ifndef _LIBCPP_NO_EXCEPTIONS
}
catch (...)
{
__state |= ios_base::badbit;
this->__setstate_nothrow(__state);
if (this->exceptions() & ios_base::badbit)
{
if (__n > 0)
*__s = char_type();
throw;
}
}
#endif
}
else
{
__state |= ios_base::failbit;
}
if (__n > 0)
*__s = char_type();
this->setstate(__state);
}
if (__n > 0)
*__s = char_type();
return *this;
}
template<class _CharT, class _Traits>
basic_istream<_CharT, _Traits>&
basic_istream<_CharT, _Traits>::get(basic_streambuf<char_type, traits_type>& __sb,
char_type __dlm)
{
ios_base::iostate __state = ios_base::goodbit;
__gc_ = 0;
sentry __sen(*this, true);
if (__sen)
{
#ifndef _LIBCPP_NO_EXCEPTIONS
try
{
#endif // _LIBCPP_NO_EXCEPTIONS
while (true)
{
typename traits_type::int_type __i = this->rdbuf()->sgetc();
if (traits_type::eq_int_type(__i, traits_type::eof()))
{
__state |= ios_base::eofbit;
break;
}
char_type __ch = traits_type::to_char_type(__i);
if (traits_type::eq(__ch, __dlm))
break;
if (traits_type::eq_int_type(__sb.sputc(__ch), traits_type::eof()))
break;
++__gc_;
this->rdbuf()->sbumpc();
}
#ifndef _LIBCPP_NO_EXCEPTIONS
}
catch (...)
{
__state |= ios_base::badbit;
// according to the spec, exceptions here are caught but not rethrown
}
#endif // _LIBCPP_NO_EXCEPTIONS
if (__gc_ == 0)
__state |= ios_base::failbit;
this->setstate(__state);
}
return *this;
}
template<class _CharT, class _Traits>
basic_istream<_CharT, _Traits>&
basic_istream<_CharT, _Traits>::getline(char_type* __s, streamsize __n, char_type __dlm)
{
ios_base::iostate __state = ios_base::goodbit;
__gc_ = 0;
sentry __sen(*this, true);
if (__sen)
{
#ifndef _LIBCPP_NO_EXCEPTIONS
try
{
#endif // _LIBCPP_NO_EXCEPTIONS
while (true)
{
typename traits_type::int_type __i = this->rdbuf()->sgetc();
if (traits_type::eq_int_type(__i, traits_type::eof()))
{
__state |= ios_base::eofbit;
break;
}
char_type __ch = traits_type::to_char_type(__i);
if (traits_type::eq(__ch, __dlm))
{
this->rdbuf()->sbumpc();
++__gc_;
break;
}
if (__gc_ >= __n-1)
{
__state |= ios_base::failbit;
break;
}
*__s++ = __ch;
this->rdbuf()->sbumpc();
++__gc_;
}
#ifndef _LIBCPP_NO_EXCEPTIONS
}
catch (...)
{
__state |= ios_base::badbit;
this->__setstate_nothrow(__state);
if (this->exceptions() & ios_base::badbit)
{
if (__n > 0)
*__s = char_type();
if (__gc_ == 0)
__state |= ios_base::failbit;
throw;
}
}
#endif // _LIBCPP_NO_EXCEPTIONS
}
if (__n > 0)
*__s = char_type();
if (__gc_ == 0)
__state |= ios_base::failbit;
this->setstate(__state);
return *this;
}
template<class _CharT, class _Traits>
basic_istream<_CharT, _Traits>&
basic_istream<_CharT, _Traits>::ignore(streamsize __n, int_type __dlm)
{
ios_base::iostate __state = ios_base::goodbit;
__gc_ = 0;
sentry __sen(*this, true);
if (__sen)
{
#ifndef _LIBCPP_NO_EXCEPTIONS
try
{
#endif // _LIBCPP_NO_EXCEPTIONS
if (__n == numeric_limits<streamsize>::max())
{
while (true)
{
typename traits_type::int_type __i = this->rdbuf()->sbumpc();
if (traits_type::eq_int_type(__i, traits_type::eof()))
{
__state |= ios_base::eofbit;
break;
}
++__gc_;
if (traits_type::eq_int_type(__i, __dlm))
break;
}
}
else
{
while (__gc_ < __n)
{
typename traits_type::int_type __i = this->rdbuf()->sbumpc();
if (traits_type::eq_int_type(__i, traits_type::eof()))
{
__state |= ios_base::eofbit;
break;
}
++__gc_;
if (traits_type::eq_int_type(__i, __dlm))
break;
}
}
#ifndef _LIBCPP_NO_EXCEPTIONS
}
catch (...)
{
__state |= ios_base::badbit;
this->__setstate_nothrow(__state);
if (this->exceptions() & ios_base::badbit)
{
throw;
}
}
#endif // _LIBCPP_NO_EXCEPTIONS
this->setstate(__state);
}
return *this;
}
template<class _CharT, class _Traits>
typename basic_istream<_CharT, _Traits>::int_type
basic_istream<_CharT, _Traits>::peek()
{
ios_base::iostate __state = ios_base::goodbit;
__gc_ = 0;
int_type __r = traits_type::eof();
sentry __sen(*this, true);
if (__sen)
{
#ifndef _LIBCPP_NO_EXCEPTIONS
try
{
#endif // _LIBCPP_NO_EXCEPTIONS
__r = this->rdbuf()->sgetc();
if (traits_type::eq_int_type(__r, traits_type::eof()))
__state |= ios_base::eofbit;
#ifndef _LIBCPP_NO_EXCEPTIONS
}
catch (...)
{
__state |= ios_base::badbit;
this->__setstate_nothrow(__state);
if (this->exceptions() & ios_base::badbit)
{
throw;
}
}
#endif // _LIBCPP_NO_EXCEPTIONS
this->setstate(__state);
}
return __r;
}
template<class _CharT, class _Traits>
basic_istream<_CharT, _Traits>&
basic_istream<_CharT, _Traits>::read(char_type* __s, streamsize __n)
{
ios_base::iostate __state = ios_base::goodbit;
__gc_ = 0;
sentry __sen(*this, true);
if (__sen)
{
#ifndef _LIBCPP_NO_EXCEPTIONS
try
{
#endif // _LIBCPP_NO_EXCEPTIONS
__gc_ = this->rdbuf()->sgetn(__s, __n);
if (__gc_ != __n)
__state |= ios_base::failbit | ios_base::eofbit;
#ifndef _LIBCPP_NO_EXCEPTIONS
}
catch (...)
{
__state |= ios_base::badbit;
this->__setstate_nothrow(__state);
if (this->exceptions() & ios_base::badbit)
{
throw;
}
}
#endif // _LIBCPP_NO_EXCEPTIONS
}
else
{
__state |= ios_base::failbit;
}
this->setstate(__state);
return *this;
}
template<class _CharT, class _Traits>
streamsize
basic_istream<_CharT, _Traits>::readsome(char_type* __s, streamsize __n)
{
ios_base::iostate __state = ios_base::goodbit;
__gc_ = 0;
sentry __sen(*this, true);
if (__sen)
{
#ifndef _LIBCPP_NO_EXCEPTIONS
try
{
#endif // _LIBCPP_NO_EXCEPTIONS
streamsize __c = this->rdbuf()->in_avail();
switch (__c)
{
case -1:
__state |= ios_base::eofbit;
break;
case 0:
break;
default:
__n = _VSTD::min(__c, __n);
__gc_ = this->rdbuf()->sgetn(__s, __n);
if (__gc_ != __n)
__state |= ios_base::failbit | ios_base::eofbit;
break;
}
#ifndef _LIBCPP_NO_EXCEPTIONS
}
catch (...)
{
__state |= ios_base::badbit;
this->__setstate_nothrow(__state);
if (this->exceptions() & ios_base::badbit)
{
throw;
}
}
#endif // _LIBCPP_NO_EXCEPTIONS
}
else
{
__state |= ios_base::failbit;
}
this->setstate(__state);
return __gc_;
}
template<class _CharT, class _Traits>
basic_istream<_CharT, _Traits>&
basic_istream<_CharT, _Traits>::putback(char_type __c)
{
ios_base::iostate __state = this->rdstate() & ~ios_base::eofbit;
__gc_ = 0;
this->clear(__state);
sentry __sen(*this, true);
if (__sen)
{
#ifndef _LIBCPP_NO_EXCEPTIONS
try
{
#endif // _LIBCPP_NO_EXCEPTIONS
if (this->rdbuf() == 0 || this->rdbuf()->sputbackc(__c) == traits_type::eof())
__state |= ios_base::badbit;
#ifndef _LIBCPP_NO_EXCEPTIONS
}
catch (...)
{
__state |= ios_base::badbit;
this->__setstate_nothrow(__state);
if (this->exceptions() & ios_base::badbit)
{
throw;
}
}
#endif // _LIBCPP_NO_EXCEPTIONS
}
else
{
__state |= ios_base::failbit;
}
this->setstate(__state);
return *this;
}
template<class _CharT, class _Traits>
basic_istream<_CharT, _Traits>&
basic_istream<_CharT, _Traits>::unget()
{
ios_base::iostate __state = this->rdstate() & ~ios_base::eofbit;
__gc_ = 0;
this->clear(__state);
sentry __sen(*this, true);
if (__sen)
{
#ifndef _LIBCPP_NO_EXCEPTIONS
try
{
#endif // _LIBCPP_NO_EXCEPTIONS
if (this->rdbuf() == 0 || this->rdbuf()->sungetc() == traits_type::eof())
__state |= ios_base::badbit;
#ifndef _LIBCPP_NO_EXCEPTIONS
}
catch (...)
{
__state |= ios_base::badbit;
this->__setstate_nothrow(__state);
if (this->exceptions() & ios_base::badbit)
{
throw;
}
}
#endif // _LIBCPP_NO_EXCEPTIONS
}
else
{
__state |= ios_base::failbit;
}
this->setstate(__state);
return *this;
}
template<class _CharT, class _Traits>
int
basic_istream<_CharT, _Traits>::sync()
{
ios_base::iostate __state = ios_base::goodbit;
int __r = 0;
sentry __sen(*this, true);
if (__sen)
{
#ifndef _LIBCPP_NO_EXCEPTIONS
try
{
#endif // _LIBCPP_NO_EXCEPTIONS
if (this->rdbuf() == 0)
return -1;
if (this->rdbuf()->pubsync() == -1)
{
__state |= ios_base::badbit;
return -1;
}
#ifndef _LIBCPP_NO_EXCEPTIONS
}
catch (...)
{
__state |= ios_base::badbit;
this->__setstate_nothrow(__state);
if (this->exceptions() & ios_base::badbit)
{
throw;
}
}
#endif // _LIBCPP_NO_EXCEPTIONS
this->setstate(__state);
}
return __r;
}
template<class _CharT, class _Traits>
typename basic_istream<_CharT, _Traits>::pos_type
basic_istream<_CharT, _Traits>::tellg()
{
ios_base::iostate __state = ios_base::goodbit;
pos_type __r(-1);
sentry __sen(*this, true);
if (__sen)
{
#ifndef _LIBCPP_NO_EXCEPTIONS
try
{
#endif // _LIBCPP_NO_EXCEPTIONS
__r = this->rdbuf()->pubseekoff(0, ios_base::cur, ios_base::in);
#ifndef _LIBCPP_NO_EXCEPTIONS
}
catch (...)
{
__state |= ios_base::badbit;
this->__setstate_nothrow(__state);
if (this->exceptions() & ios_base::badbit)
{
throw;
}
}
#endif // _LIBCPP_NO_EXCEPTIONS
this->setstate(__state);
}
return __r;
}
template<class _CharT, class _Traits>
basic_istream<_CharT, _Traits>&
basic_istream<_CharT, _Traits>::seekg(pos_type __pos)
{
ios_base::iostate __state = this->rdstate() & ~ios_base::eofbit;
this->clear(__state);
sentry __sen(*this, true);
if (__sen)
{
#ifndef _LIBCPP_NO_EXCEPTIONS
try
{
#endif // _LIBCPP_NO_EXCEPTIONS
if (this->rdbuf()->pubseekpos(__pos, ios_base::in) == pos_type(-1))
__state |= ios_base::failbit;
#ifndef _LIBCPP_NO_EXCEPTIONS
}
catch (...)
{
__state |= ios_base::badbit;
this->__setstate_nothrow(__state);
if (this->exceptions() & ios_base::badbit)
{
throw;
}
}
#endif // _LIBCPP_NO_EXCEPTIONS
this->setstate(__state);
}
return *this;
}
template<class _CharT, class _Traits>
basic_istream<_CharT, _Traits>&
basic_istream<_CharT, _Traits>::seekg(off_type __off, ios_base::seekdir __dir)
{
ios_base::iostate __state = this->rdstate() & ~ios_base::eofbit;
this->clear(__state);
sentry __sen(*this, true);
if (__sen)
{
#ifndef _LIBCPP_NO_EXCEPTIONS
try
{
#endif // _LIBCPP_NO_EXCEPTIONS
if (this->rdbuf()->pubseekoff(__off, __dir, ios_base::in) == pos_type(-1))
__state |= ios_base::failbit;
#ifndef _LIBCPP_NO_EXCEPTIONS
}
catch (...)
{
__state |= ios_base::badbit;
this->__setstate_nothrow(__state);
if (this->exceptions() & ios_base::badbit)
{
throw;
}
}
#endif // _LIBCPP_NO_EXCEPTIONS
this->setstate(__state);
}
return *this;
}
template <class _CharT, class _Traits>
basic_istream<_CharT, _Traits>&
ws(basic_istream<_CharT, _Traits>& __is)
{
ios_base::iostate __state = ios_base::goodbit;
typename basic_istream<_CharT, _Traits>::sentry __sen(__is, true);
if (__sen)
{
#ifndef _LIBCPP_NO_EXCEPTIONS
try
{
#endif // _LIBCPP_NO_EXCEPTIONS
const ctype<_CharT>& __ct = use_facet<ctype<_CharT> >(__is.getloc());
while (true)
{
typename _Traits::int_type __i = __is.rdbuf()->sgetc();
if (_Traits::eq_int_type(__i, _Traits::eof()))
{
__state |= ios_base::eofbit;
break;
}
if (!__ct.is(__ct.space, _Traits::to_char_type(__i)))
break;
__is.rdbuf()->sbumpc();
}
#ifndef _LIBCPP_NO_EXCEPTIONS
}
catch (...)
{
__state |= ios_base::badbit;
__is.__setstate_nothrow(__state);
if (__is.exceptions() & ios_base::badbit)
{
throw;
}
}
#endif // _LIBCPP_NO_EXCEPTIONS
__is.setstate(__state);
}
return __is;
}
#ifndef _LIBCPP_CXX03_LANG
template <class _CharT, class _Traits, class _Tp>
inline _LIBCPP_INLINE_VISIBILITY
basic_istream<_CharT, _Traits>&
operator>>(basic_istream<_CharT, _Traits>&& __is, _Tp&& __x)
{
__is >> _VSTD::forward<_Tp>(__x);
return __is;
}
#endif // _LIBCPP_CXX03_LANG
template <class _CharT, class _Traits>
class _LIBCPP_TEMPLATE_VIS basic_iostream
: public basic_istream<_CharT, _Traits>,
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;
// constructor/destructor
inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1
explicit basic_iostream(basic_streambuf<char_type, traits_type>* __sb)
: basic_istream<_CharT, _Traits>(__sb)
{}
virtual ~basic_iostream();
protected:
#ifndef _LIBCPP_CXX03_LANG
inline _LIBCPP_INLINE_VISIBILITY
basic_iostream(basic_iostream&& __rhs);
// assign/swap
inline _LIBCPP_INLINE_VISIBILITY
basic_iostream& operator=(basic_iostream&& __rhs);
#endif
inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1
void swap(basic_iostream& __rhs)
{ basic_istream<char_type, traits_type>::swap(__rhs); }
};
#ifndef _LIBCPP_CXX03_LANG
template <class _CharT, class _Traits>
basic_iostream<_CharT, _Traits>::basic_iostream(basic_iostream&& __rhs)
: basic_istream<_CharT, _Traits>(_VSTD::move(__rhs))
{
}
template <class _CharT, class _Traits>
basic_iostream<_CharT, _Traits>&
basic_iostream<_CharT, _Traits>::operator=(basic_iostream&& __rhs)
{
swap(__rhs);
return *this;
}
#endif // _LIBCPP_CXX03_LANG
template <class _CharT, class _Traits>
basic_iostream<_CharT, _Traits>::~basic_iostream()
{
}
template<class _CharT, class _Traits, class _Allocator>
basic_istream<_CharT, _Traits>&
operator>>(basic_istream<_CharT, _Traits>& __is,
basic_string<_CharT, _Traits, _Allocator>& __str)
{
ios_base::iostate __state = ios_base::goodbit;
typename basic_istream<_CharT, _Traits>::sentry __sen(__is);
if (__sen)
{
#ifndef _LIBCPP_NO_EXCEPTIONS
try
{
#endif
__str.clear();
streamsize __n = __is.width();
if (__n <= 0)
__n = __str.max_size();
if (__n <= 0)
__n = numeric_limits<streamsize>::max();
streamsize __c = 0;
const ctype<_CharT>& __ct = use_facet<ctype<_CharT> >(__is.getloc());
while (__c < __n)
{
typename _Traits::int_type __i = __is.rdbuf()->sgetc();
if (_Traits::eq_int_type(__i, _Traits::eof()))
{
__state |= ios_base::eofbit;
break;
}
_CharT __ch = _Traits::to_char_type(__i);
if (__ct.is(__ct.space, __ch))
break;
__str.push_back(__ch);
++__c;
__is.rdbuf()->sbumpc();
}
__is.width(0);
if (__c == 0)
__state |= ios_base::failbit;
#ifndef _LIBCPP_NO_EXCEPTIONS
}
catch (...)
{
__state |= ios_base::badbit;
__is.__setstate_nothrow(__state);
if (__is.exceptions() & ios_base::badbit)
{
throw;
}
}
#endif
__is.setstate(__state);
}
return __is;
}
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)
{
ios_base::iostate __state = ios_base::goodbit;
typename basic_istream<_CharT, _Traits>::sentry __sen(__is, true);
if (__sen)
{
#ifndef _LIBCPP_NO_EXCEPTIONS
try
{
#endif
__str.clear();
streamsize __extr = 0;
while (true)
{
typename _Traits::int_type __i = __is.rdbuf()->sbumpc();
if (_Traits::eq_int_type(__i, _Traits::eof()))
{
__state |= ios_base::eofbit;
break;
}
++__extr;
_CharT __ch = _Traits::to_char_type(__i);
if (_Traits::eq(__ch, __dlm))
break;
__str.push_back(__ch);
if (__str.size() == __str.max_size())
{
__state |= ios_base::failbit;
break;
}
}
if (__extr == 0)
__state |= ios_base::failbit;
#ifndef _LIBCPP_NO_EXCEPTIONS
}
catch (...)
{
__state |= ios_base::badbit;
__is.__setstate_nothrow(__state);
if (__is.exceptions() & ios_base::badbit)
{
throw;
}
}
#endif
__is.setstate(__state);
}
return __is;
}
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)
{
return getline(__is, __str, __is.widen('\n'));
}
#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)
{
return getline(__is, __str, __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)
{
return getline(__is, __str, __is.widen('\n'));
}
#endif // _LIBCPP_CXX03_LANG
template <class _CharT, class _Traits, size_t _Size>
basic_istream<_CharT, _Traits>&
operator>>(basic_istream<_CharT, _Traits>& __is, bitset<_Size>& __x)
{
ios_base::iostate __state = ios_base::goodbit;
typename basic_istream<_CharT, _Traits>::sentry __sen(__is);
if (__sen)
{
#ifndef _LIBCPP_NO_EXCEPTIONS
try
{
#endif
basic_string<_CharT, _Traits> __str;
const ctype<_CharT>& __ct = use_facet<ctype<_CharT> >(__is.getloc());
size_t __c = 0;
_CharT __zero = __ct.widen('0');
_CharT __one = __ct.widen('1');
while (__c < _Size)
{
typename _Traits::int_type __i = __is.rdbuf()->sgetc();
if (_Traits::eq_int_type(__i, _Traits::eof()))
{
__state |= ios_base::eofbit;
break;
}
_CharT __ch = _Traits::to_char_type(__i);
if (!_Traits::eq(__ch, __zero) && !_Traits::eq(__ch, __one))
break;
__str.push_back(__ch);
++__c;
__is.rdbuf()->sbumpc();
}
__x = bitset<_Size>(__str);
if (_Size > 0 && __c == 0)
__state |= ios_base::failbit;
#ifndef _LIBCPP_NO_EXCEPTIONS
}
catch (...)
{
__state |= ios_base::badbit;
__is.__setstate_nothrow(__state);
if (__is.exceptions() & ios_base::badbit)
{
throw;
}
}
#endif
__is.setstate(__state);
}
return __is;
}
#ifndef _LIBCPP_DO_NOT_ASSUME_STREAMS_EXPLICIT_INSTANTIATION_IN_DYLIB
_LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_istream<char>)
_LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_istream<wchar_t>)
_LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_iostream<char>)
#endif
_LIBCPP_END_NAMESPACE_STD
_LIBCPP_POP_MACROS
#endif // _LIBCPP_ISTREAM
| 47,938 | 1,652 | jart/cosmopolitan | false |
cosmopolitan/third_party/libcxx/typeinfo | // -*- C++ -*-
//===-------------------------- typeinfo ----------------------------------===//
//
// 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_TYPEINFO
#define __LIBCPP_TYPEINFO
#include "third_party/libcxx/__config"
#include "third_party/libcxx/exception"
#include "third_party/libcxx/cstddef"
#include "third_party/libcxx/cstdint"
#ifdef _LIBCPP_NO_EXCEPTIONS
#include "third_party/libcxx/cstdlib"
#endif
/*
typeinfo synopsis
namespace std {
class type_info
{
public:
virtual ~type_info();
bool operator==(const type_info& rhs) const noexcept;
bool operator!=(const type_info& rhs) const noexcept;
bool before(const type_info& rhs) const noexcept;
size_t hash_code() const noexcept;
const char* name() const noexcept;
type_info(const type_info& rhs) = delete;
type_info& operator=(const type_info& rhs) = delete;
};
class bad_cast
: public exception
{
public:
bad_cast() noexcept;
bad_cast(const bad_cast&) noexcept;
bad_cast& operator=(const bad_cast&) noexcept;
virtual const char* what() const noexcept;
};
class bad_typeid
: public exception
{
public:
bad_typeid() noexcept;
bad_typeid(const bad_typeid&) noexcept;
bad_typeid& operator=(const bad_typeid&) noexcept;
virtual const char* what() const noexcept;
};
} // std
*/
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
#pragma GCC system_header
#endif
#if defined(_LIBCPP_ABI_VCRUNTIME)
//#include "third_party/libcxx/vcruntime_typeinfo.h"
#else
namespace std // purposefully not using versioning namespace
{
#if defined(_LIBCPP_ABI_MICROSOFT)
class _LIBCPP_EXCEPTION_ABI type_info
{
type_info& operator=(const type_info&);
type_info(const type_info&);
mutable struct {
const char *__undecorated_name;
const char __decorated_name[1];
} __data;
int __compare(const type_info &__rhs) const _NOEXCEPT;
public:
_LIBCPP_AVAILABILITY_TYPEINFO_VTABLE
virtual ~type_info();
const char *name() const _NOEXCEPT;
_LIBCPP_INLINE_VISIBILITY
bool before(const type_info& __arg) const _NOEXCEPT {
return __compare(__arg) < 0;
}
size_t hash_code() const _NOEXCEPT;
_LIBCPP_INLINE_VISIBILITY
bool operator==(const type_info& __arg) const _NOEXCEPT {
return __compare(__arg) == 0;
}
_LIBCPP_INLINE_VISIBILITY
bool operator!=(const type_info& __arg) const _NOEXCEPT
{ return !operator==(__arg); }
};
#else // !defined(_LIBCPP_ABI_MICROSOFT)
// ========================================================================== //
// Implementations
// ========================================================================== //
// ------------------------------------------------------------------------- //
// Unique
// ------------------------------------------------------------------------- //
// This implementation of type_info assumes a unique copy of the RTTI for a
// given type inside a program. This is a valid assumption when abiding to
// Itanium ABI (http://itanium-cxx-abi.github.io/cxx-abi/abi.html#vtable-components).
// Under this assumption, we can always compare the addresses of the type names
// to implement equality-comparison of type_infos instead of having to perform
// a deep string comparison.
// -------------------------------------------------------------------------- //
// NonUnique
// -------------------------------------------------------------------------- //
// This implementation of type_info does not assume there is always a unique
// copy of the RTTI for a given type inside a program. For various reasons
// the linker may have failed to merge every copy of a types RTTI
// (For example: -Bsymbolic or llvm.org/PR37398). Under this assumption, two
// type_infos are equal if their addresses are equal or if a deep string
// comparison is equal.
// -------------------------------------------------------------------------- //
// NonUniqueARMRTTIBit
// -------------------------------------------------------------------------- //
// This implementation of type_info does not assume always a unique copy of
// the RTTI for a given type inside a program. It packs the pointer to the
// type name into a uintptr_t and reserves the high bit of that pointer (which
// is assumed to be free for use under the ABI in use) to represent whether
// that specific copy of the RTTI can be assumed unique inside the program.
// To implement equality-comparison of type_infos, we check whether BOTH
// type_infos are guaranteed unique, and if so, we simply compare the addresses
// of their type names instead of doing a deep string comparison, which is
// faster. If at least one of the type_infos can't guarantee uniqueness, we
// have no choice but to fall back to a deep string comparison.
//
// This implementation is specific to ARM64 on Apple platforms.
//
// Note that the compiler is the one setting (or unsetting) the high bit of
// the pointer when it constructs the type_info, depending on whether it can
// guarantee uniqueness for that specific type_info.
struct __type_info_implementations {
struct __string_impl_base {
typedef const char* __type_name_t;
_LIBCPP_INLINE_VISIBILITY _LIBCPP_ALWAYS_INLINE
_LIBCPP_CONSTEXPR static const char* __type_name_to_string(__type_name_t __v) _NOEXCEPT {
return __v;
}
_LIBCPP_INLINE_VISIBILITY _LIBCPP_ALWAYS_INLINE
_LIBCPP_CONSTEXPR static __type_name_t __string_to_type_name(const char* __v) _NOEXCEPT {
return __v;
}
};
struct __unique_impl : __string_impl_base {
_LIBCPP_INLINE_VISIBILITY _LIBCPP_ALWAYS_INLINE
static size_t __hash(__type_name_t __v) _NOEXCEPT {
return reinterpret_cast<size_t>(__v);
}
_LIBCPP_INLINE_VISIBILITY _LIBCPP_ALWAYS_INLINE
static bool __eq(__type_name_t __lhs, __type_name_t __rhs) _NOEXCEPT {
return __lhs == __rhs;
}
_LIBCPP_INLINE_VISIBILITY _LIBCPP_ALWAYS_INLINE
static bool __lt(__type_name_t __lhs, __type_name_t __rhs) _NOEXCEPT {
return __lhs < __rhs;
}
};
struct __non_unique_impl : __string_impl_base {
_LIBCPP_INLINE_VISIBILITY _LIBCPP_ALWAYS_INLINE
static size_t __hash(__type_name_t __ptr) _NOEXCEPT {
size_t __hash = 5381;
while (unsigned char __c = static_cast<unsigned char>(*__ptr++))
__hash = (__hash * 33) ^ __c;
return __hash;
}
_LIBCPP_INLINE_VISIBILITY _LIBCPP_ALWAYS_INLINE
static bool __eq(__type_name_t __lhs, __type_name_t __rhs) _NOEXCEPT {
return __lhs == __rhs || __builtin_strcmp(__lhs, __rhs) == 0;
}
_LIBCPP_INLINE_VISIBILITY _LIBCPP_ALWAYS_INLINE
static bool __lt(__type_name_t __lhs, __type_name_t __rhs) _NOEXCEPT {
return __builtin_strcmp(__lhs, __rhs) < 0;
}
};
struct __non_unique_arm_rtti_bit_impl {
typedef uintptr_t __type_name_t;
_LIBCPP_INLINE_VISIBILITY _LIBCPP_ALWAYS_INLINE
static const char* __type_name_to_string(__type_name_t __v) _NOEXCEPT {
return reinterpret_cast<const char*>(__v &
~__non_unique_rtti_bit::value);
}
_LIBCPP_INLINE_VISIBILITY _LIBCPP_ALWAYS_INLINE
static __type_name_t __string_to_type_name(const char* __v) _NOEXCEPT {
return reinterpret_cast<__type_name_t>(__v);
}
_LIBCPP_INLINE_VISIBILITY _LIBCPP_ALWAYS_INLINE
static size_t __hash(__type_name_t __v) _NOEXCEPT {
if (__is_type_name_unique(__v))
return reinterpret_cast<size_t>(__v);
return __non_unique_impl::__hash(__type_name_to_string(__v));
}
_LIBCPP_INLINE_VISIBILITY _LIBCPP_ALWAYS_INLINE
static bool __eq(__type_name_t __lhs, __type_name_t __rhs) _NOEXCEPT {
if (__lhs == __rhs)
return true;
if (__is_type_name_unique(__lhs, __rhs))
return false;
return __builtin_strcmp(__type_name_to_string(__lhs), __type_name_to_string(__rhs)) == 0;
}
_LIBCPP_INLINE_VISIBILITY _LIBCPP_ALWAYS_INLINE
static bool __lt(__type_name_t __lhs, __type_name_t __rhs) _NOEXCEPT {
if (__is_type_name_unique(__lhs, __rhs))
return __lhs < __rhs;
return __builtin_strcmp(__type_name_to_string(__lhs), __type_name_to_string(__rhs)) < 0;
}
private:
// The unique bit is the top bit. It is expected that __type_name_t is 64 bits when
// this implementation is actually used.
typedef std::integral_constant<__type_name_t,
(1ULL << ((__CHAR_BIT__ * sizeof(__type_name_t)) - 1))> __non_unique_rtti_bit;
_LIBCPP_INLINE_VISIBILITY
static bool __is_type_name_unique(__type_name_t __lhs) _NOEXCEPT {
return !(__lhs & __non_unique_rtti_bit::value);
}
_LIBCPP_INLINE_VISIBILITY
static bool __is_type_name_unique(__type_name_t __lhs, __type_name_t __rhs) _NOEXCEPT {
return !((__lhs & __rhs) & __non_unique_rtti_bit::value);
}
};
typedef
#if defined(__APPLE__) && defined(__LP64__) && !defined(__x86_64__)
__non_unique_arm_rtti_bit_impl
#elif _LIBCPP_HAS_MERGED_TYPEINFO_NAMES_DEFAULT == 0
__non_unique_impl
#elif _LIBCPP_HAS_MERGED_TYPEINFO_NAMES_DEFAULT == 1
__unique_impl
#else
# error invalid configuration for _LIBCPP_HAS_MERGED_TYPEINFO_NAMES_DEFAULT
#endif
__impl;
};
class _LIBCPP_EXCEPTION_ABI type_info
{
type_info& operator=(const type_info&);
type_info(const type_info&);
protected:
typedef __type_info_implementations::__impl __impl;
__impl::__type_name_t __type_name;
_LIBCPP_INLINE_VISIBILITY
explicit type_info(const char* __n)
: __type_name(__impl::__string_to_type_name(__n)) {}
public:
_LIBCPP_AVAILABILITY_TYPEINFO_VTABLE
virtual ~type_info();
_LIBCPP_INLINE_VISIBILITY
const char* name() const _NOEXCEPT
{
return __impl::__type_name_to_string(__type_name);
}
_LIBCPP_INLINE_VISIBILITY
bool before(const type_info& __arg) const _NOEXCEPT
{
return __impl::__lt(__type_name, __arg.__type_name);
}
_LIBCPP_INLINE_VISIBILITY
size_t hash_code() const _NOEXCEPT
{
return __impl::__hash(__type_name);
}
_LIBCPP_INLINE_VISIBILITY
bool operator==(const type_info& __arg) const _NOEXCEPT
{
return __impl::__eq(__type_name, __arg.__type_name);
}
_LIBCPP_INLINE_VISIBILITY
bool operator!=(const type_info& __arg) const _NOEXCEPT
{ return !operator==(__arg); }
};
#endif // defined(_LIBCPP_ABI_MICROSOFT)
class _LIBCPP_EXCEPTION_ABI bad_cast
: public exception
{
public:
bad_cast() _NOEXCEPT;
virtual ~bad_cast() _NOEXCEPT;
virtual const char* what() const _NOEXCEPT;
};
class _LIBCPP_EXCEPTION_ABI bad_typeid
: public exception
{
public:
bad_typeid() _NOEXCEPT;
virtual ~bad_typeid() _NOEXCEPT;
virtual const char* what() const _NOEXCEPT;
};
} // std
#endif // defined(_LIBCPP_ABI_VCRUNTIME)
_LIBCPP_BEGIN_NAMESPACE_STD
_LIBCPP_NORETURN inline _LIBCPP_INLINE_VISIBILITY
void __throw_bad_cast()
{
#ifndef _LIBCPP_NO_EXCEPTIONS
throw bad_cast();
#else
_VSTD::abort();
#endif
}
_LIBCPP_END_NAMESPACE_STD
#endif // __LIBCPP_TYPEINFO
| 11,365 | 351 | jart/cosmopolitan | false |
cosmopolitan/third_party/libcxx/stdexcept.cc | //===------------------------ stdexcept.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/stdexcept"
#include "third_party/libcxx/new"
#include "third_party/libcxx/string"
#include "third_party/libcxx/system_error"
#include "third_party/libcxx/stdexcept_default.hh"
| 576 | 15 | jart/cosmopolitan | false |
cosmopolitan/third_party/libcxx/optional.cc | // clang-format off
//===------------------------ optional.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/optional"
namespace std
{
bad_optional_access::~bad_optional_access() _NOEXCEPT = default;
const char* bad_optional_access::what() const _NOEXCEPT {
return "bad_optional_access";
}
} // std
#include "third_party/libcxx/experimental/__config"
// Preserve std::experimental::bad_optional_access for ABI compatibility
// Even though it no longer exists in a header file
_LIBCPP_BEGIN_NAMESPACE_EXPERIMENTAL
class _LIBCPP_EXCEPTION_ABI _LIBCPP_AVAILABILITY_BAD_OPTIONAL_ACCESS bad_optional_access
: public std::logic_error
{
public:
bad_optional_access() : std::logic_error("Bad optional Access") {}
// Get the key function ~bad_optional_access() into the dylib
virtual ~bad_optional_access() _NOEXCEPT;
};
bad_optional_access::~bad_optional_access() _NOEXCEPT = default;
_LIBCPP_END_NAMESPACE_EXPERIMENTAL
| 1,248 | 43 | jart/cosmopolitan | false |
cosmopolitan/third_party/libcxx/type_traits | // -*- C++ -*-
//===------------------------ type_traits ---------------------------------===//
//
// 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_TYPE_TRAITS
#define _LIBCPP_TYPE_TRAITS
#include "third_party/libcxx/__config"
#include "third_party/libcxx/cstddef"
#include "third_party/libcxx/version"
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
#pragma GCC system_header
#endif
_LIBCPP_BEGIN_NAMESPACE_STD
/*
type_traits synopsis
namespace std
{
// helper class:
template <class T, T v> struct integral_constant;
typedef integral_constant<bool, true> true_type; // C++11
typedef integral_constant<bool, false> false_type; // C++11
template <bool B> // C++14
using bool_constant = integral_constant<bool, B>; // C++14
typedef bool_constant<true> true_type; // C++14
typedef bool_constant<false> false_type; // C++14
// helper traits
template <bool, class T = void> struct enable_if;
template <bool, class T, class F> struct conditional;
// Primary classification traits:
template <class T> struct is_void;
template <class T> struct is_null_pointer; // C++14
template <class T> struct is_integral;
template <class T> struct is_floating_point;
template <class T> struct is_array;
template <class T> struct is_pointer;
template <class T> struct is_lvalue_reference;
template <class T> struct is_rvalue_reference;
template <class T> struct is_member_object_pointer;
template <class T> struct is_member_function_pointer;
template <class T> struct is_enum;
template <class T> struct is_union;
template <class T> struct is_class;
template <class T> struct is_function;
// Secondary classification traits:
template <class T> struct is_reference;
template <class T> struct is_arithmetic;
template <class T> struct is_fundamental;
template <class T> struct is_member_pointer;
template <class T> struct is_scalar;
template <class T> struct is_object;
template <class T> struct is_compound;
// Const-volatile properties and transformations:
template <class T> struct is_const;
template <class T> struct is_volatile;
template <class T> struct remove_const;
template <class T> struct remove_volatile;
template <class T> struct remove_cv;
template <class T> struct add_const;
template <class T> struct add_volatile;
template <class T> struct add_cv;
// Reference transformations:
template <class T> struct remove_reference;
template <class T> struct add_lvalue_reference;
template <class T> struct add_rvalue_reference;
// Pointer transformations:
template <class T> struct remove_pointer;
template <class T> struct add_pointer;
template<class T> struct type_identity; // C++20
template<class T>
using type_identity_t = typename type_identity<T>::type; // C++20
// Integral properties:
template <class T> struct is_signed;
template <class T> struct is_unsigned;
template <class T> struct make_signed;
template <class T> struct make_unsigned;
// Array properties and transformations:
template <class T> struct rank;
template <class T, unsigned I = 0> struct extent;
template <class T> struct remove_extent;
template <class T> struct remove_all_extents;
template <class T> struct is_bounded_array; // C++20
template <class T> struct is_unbounded_array; // C++20
// Member introspection:
template <class T> struct is_pod;
template <class T> struct is_trivial;
template <class T> struct is_trivially_copyable;
template <class T> struct is_standard_layout;
template <class T> struct is_literal_type;
template <class T> struct is_empty;
template <class T> struct is_polymorphic;
template <class T> struct is_abstract;
template <class T> struct is_final; // C++14
template <class T> struct is_aggregate; // C++17
template <class T, class... Args> struct is_constructible;
template <class T> struct is_default_constructible;
template <class T> struct is_copy_constructible;
template <class T> struct is_move_constructible;
template <class T, class U> struct is_assignable;
template <class T> struct is_copy_assignable;
template <class T> struct is_move_assignable;
template <class T, class U> struct is_swappable_with; // C++17
template <class T> struct is_swappable; // C++17
template <class T> struct is_destructible;
template <class T, class... Args> struct is_trivially_constructible;
template <class T> struct is_trivially_default_constructible;
template <class T> struct is_trivially_copy_constructible;
template <class T> struct is_trivially_move_constructible;
template <class T, class U> struct is_trivially_assignable;
template <class T> struct is_trivially_copy_assignable;
template <class T> struct is_trivially_move_assignable;
template <class T> struct is_trivially_destructible;
template <class T, class... Args> struct is_nothrow_constructible;
template <class T> struct is_nothrow_default_constructible;
template <class T> struct is_nothrow_copy_constructible;
template <class T> struct is_nothrow_move_constructible;
template <class T, class U> struct is_nothrow_assignable;
template <class T> struct is_nothrow_copy_assignable;
template <class T> struct is_nothrow_move_assignable;
template <class T, class U> struct is_nothrow_swappable_with; // C++17
template <class T> struct is_nothrow_swappable; // C++17
template <class T> struct is_nothrow_destructible;
template <class T> struct has_virtual_destructor;
template<class T> struct has_unique_object_representations; // C++17
// Relationships between types:
template <class T, class U> struct is_same;
template <class Base, class Derived> struct is_base_of;
template <class From, class To> struct is_convertible;
template <typename From, typename To> struct is_nothrow_convertible; // C++20
template <typename From, typename To> inline constexpr bool is_nothrow_convertible_v; // C++20
template <class Fn, class... ArgTypes> struct is_invocable;
template <class R, class Fn, class... ArgTypes> struct is_invocable_r;
template <class Fn, class... ArgTypes> struct is_nothrow_invocable;
template <class R, class Fn, class... ArgTypes> struct is_nothrow_invocable_r;
// Alignment properties and transformations:
template <class T> struct alignment_of;
template <size_t Len, size_t Align = most_stringent_alignment_requirement>
struct aligned_storage;
template <size_t Len, class... Types> struct aligned_union;
template <class T> struct remove_cvref; // C++20
template <class T> struct decay;
template <class... T> struct common_type;
template <class T> struct underlying_type;
template <class> class result_of; // undefined
template <class Fn, class... ArgTypes> class result_of<Fn(ArgTypes...)>;
template <class Fn, class... ArgTypes> struct invoke_result; // C++17
// const-volatile modifications:
template <class T>
using remove_const_t = typename remove_const<T>::type; // C++14
template <class T>
using remove_volatile_t = typename remove_volatile<T>::type; // C++14
template <class T>
using remove_cv_t = typename remove_cv<T>::type; // C++14
template <class T>
using add_const_t = typename add_const<T>::type; // C++14
template <class T>
using add_volatile_t = typename add_volatile<T>::type; // C++14
template <class T>
using add_cv_t = typename add_cv<T>::type; // C++14
// reference modifications:
template <class T>
using remove_reference_t = typename remove_reference<T>::type; // C++14
template <class T>
using add_lvalue_reference_t = typename add_lvalue_reference<T>::type; // C++14
template <class T>
using add_rvalue_reference_t = typename add_rvalue_reference<T>::type; // C++14
// sign modifications:
template <class T>
using make_signed_t = typename make_signed<T>::type; // C++14
template <class T>
using make_unsigned_t = typename make_unsigned<T>::type; // C++14
// array modifications:
template <class T>
using remove_extent_t = typename remove_extent<T>::type; // C++14
template <class T>
using remove_all_extents_t = typename remove_all_extents<T>::type; // C++14
template <class T>
inline constexpr bool is_bounded_array_v
= is_bounded_array<T>::value; // C++20
inline constexpr bool is_unbounded_array_v
= is_unbounded_array<T>::value; // C++20
// pointer modifications:
template <class T>
using remove_pointer_t = typename remove_pointer<T>::type; // C++14
template <class T>
using add_pointer_t = typename add_pointer<T>::type; // C++14
// other transformations:
template <size_t Len, std::size_t Align=default-alignment>
using aligned_storage_t = typename aligned_storage<Len,Align>::type; // C++14
template <std::size_t Len, class... Types>
using aligned_union_t = typename aligned_union<Len,Types...>::type; // C++14
template <class T>
using remove_cvref_t = typename remove_cvref<T>::type; // C++20
template <class T>
using decay_t = typename decay<T>::type; // C++14
template <bool b, class T=void>
using enable_if_t = typename enable_if<b,T>::type; // C++14
template <bool b, class T, class F>
using conditional_t = typename conditional<b,T,F>::type; // C++14
template <class... T>
using common_type_t = typename common_type<T...>::type; // C++14
template <class T>
using underlying_type_t = typename underlying_type<T>::type; // C++14
template <class T>
using result_of_t = typename result_of<T>::type; // C++14
template <class Fn, class... ArgTypes>
using invoke_result_t = typename invoke_result<Fn, ArgTypes...>::type; // C++17
template <class...>
using void_t = void; // C++17
// See C++14 20.10.4.1, primary type categories
template <class T> inline constexpr bool is_void_v
= is_void<T>::value; // C++17
template <class T> inline constexpr bool is_null_pointer_v
= is_null_pointer<T>::value; // C++17
template <class T> inline constexpr bool is_integral_v
= is_integral<T>::value; // C++17
template <class T> inline constexpr bool is_floating_point_v
= is_floating_point<T>::value; // C++17
template <class T> inline constexpr bool is_array_v
= is_array<T>::value; // C++17
template <class T> inline constexpr bool is_pointer_v
= is_pointer<T>::value; // C++17
template <class T> inline constexpr bool is_lvalue_reference_v
= is_lvalue_reference<T>::value; // C++17
template <class T> inline constexpr bool is_rvalue_reference_v
= is_rvalue_reference<T>::value; // C++17
template <class T> inline constexpr bool is_member_object_pointer_v
= is_member_object_pointer<T>::value; // C++17
template <class T> inline constexpr bool is_member_function_pointer_v
= is_member_function_pointer<T>::value; // C++17
template <class T> inline constexpr bool is_enum_v
= is_enum<T>::value; // C++17
template <class T> inline constexpr bool is_union_v
= is_union<T>::value; // C++17
template <class T> inline constexpr bool is_class_v
= is_class<T>::value; // C++17
template <class T> inline constexpr bool is_function_v
= is_function<T>::value; // C++17
// See C++14 20.10.4.2, composite type categories
template <class T> inline constexpr bool is_reference_v
= is_reference<T>::value; // C++17
template <class T> inline constexpr bool is_arithmetic_v
= is_arithmetic<T>::value; // C++17
template <class T> inline constexpr bool is_fundamental_v
= is_fundamental<T>::value; // C++17
template <class T> inline constexpr bool is_object_v
= is_object<T>::value; // C++17
template <class T> inline constexpr bool is_scalar_v
= is_scalar<T>::value; // C++17
template <class T> inline constexpr bool is_compound_v
= is_compound<T>::value; // C++17
template <class T> inline constexpr bool is_member_pointer_v
= is_member_pointer<T>::value; // C++17
// See C++14 20.10.4.3, type properties
template <class T> inline constexpr bool is_const_v
= is_const<T>::value; // C++17
template <class T> inline constexpr bool is_volatile_v
= is_volatile<T>::value; // C++17
template <class T> inline constexpr bool is_trivial_v
= is_trivial<T>::value; // C++17
template <class T> inline constexpr bool is_trivially_copyable_v
= is_trivially_copyable<T>::value; // C++17
template <class T> inline constexpr bool is_standard_layout_v
= is_standard_layout<T>::value; // C++17
template <class T> inline constexpr bool is_pod_v
= is_pod<T>::value; // C++17
template <class T> inline constexpr bool is_literal_type_v
= is_literal_type<T>::value; // C++17
template <class T> inline constexpr bool is_empty_v
= is_empty<T>::value; // C++17
template <class T> inline constexpr bool is_polymorphic_v
= is_polymorphic<T>::value; // C++17
template <class T> inline constexpr bool is_abstract_v
= is_abstract<T>::value; // C++17
template <class T> inline constexpr bool is_final_v
= is_final<T>::value; // C++17
template <class T> inline constexpr bool is_aggregate_v
= is_aggregate<T>::value; // C++17
template <class T> inline constexpr bool is_signed_v
= is_signed<T>::value; // C++17
template <class T> inline constexpr bool is_unsigned_v
= is_unsigned<T>::value; // C++17
template <class T, class... Args> inline constexpr bool is_constructible_v
= is_constructible<T, Args...>::value; // C++17
template <class T> inline constexpr bool is_default_constructible_v
= is_default_constructible<T>::value; // C++17
template <class T> inline constexpr bool is_copy_constructible_v
= is_copy_constructible<T>::value; // C++17
template <class T> inline constexpr bool is_move_constructible_v
= is_move_constructible<T>::value; // C++17
template <class T, class U> inline constexpr bool is_assignable_v
= is_assignable<T, U>::value; // C++17
template <class T> inline constexpr bool is_copy_assignable_v
= is_copy_assignable<T>::value; // C++17
template <class T> inline constexpr bool is_move_assignable_v
= is_move_assignable<T>::value; // C++17
template <class T, class U> inline constexpr bool is_swappable_with_v
= is_swappable_with<T, U>::value; // C++17
template <class T> inline constexpr bool is_swappable_v
= is_swappable<T>::value; // C++17
template <class T> inline constexpr bool is_destructible_v
= is_destructible<T>::value; // C++17
template <class T, class... Args> inline constexpr bool is_trivially_constructible_v
= is_trivially_constructible<T, Args...>::value; // C++17
template <class T> inline constexpr bool is_trivially_default_constructible_v
= is_trivially_default_constructible<T>::value; // C++17
template <class T> inline constexpr bool is_trivially_copy_constructible_v
= is_trivially_copy_constructible<T>::value; // C++17
template <class T> inline constexpr bool is_trivially_move_constructible_v
= is_trivially_move_constructible<T>::value; // C++17
template <class T, class U> inline constexpr bool is_trivially_assignable_v
= is_trivially_assignable<T, U>::value; // C++17
template <class T> inline constexpr bool is_trivially_copy_assignable_v
= is_trivially_copy_assignable<T>::value; // C++17
template <class T> inline constexpr bool is_trivially_move_assignable_v
= is_trivially_move_assignable<T>::value; // C++17
template <class T> inline constexpr bool is_trivially_destructible_v
= is_trivially_destructible<T>::value; // C++17
template <class T, class... Args> inline constexpr bool is_nothrow_constructible_v
= is_nothrow_constructible<T, Args...>::value; // C++17
template <class T> inline constexpr bool is_nothrow_default_constructible_v
= is_nothrow_default_constructible<T>::value; // C++17
template <class T> inline constexpr bool is_nothrow_copy_constructible_v
= is_nothrow_copy_constructible<T>::value; // C++17
template <class T> inline constexpr bool is_nothrow_move_constructible_v
= is_nothrow_move_constructible<T>::value; // C++17
template <class T, class U> inline constexpr bool is_nothrow_assignable_v
= is_nothrow_assignable<T, U>::value; // C++17
template <class T> inline constexpr bool is_nothrow_copy_assignable_v
= is_nothrow_copy_assignable<T>::value; // C++17
template <class T> inline constexpr bool is_nothrow_move_assignable_v
= is_nothrow_move_assignable<T>::value; // C++17
template <class T, class U> inline constexpr bool is_nothrow_swappable_with_v
= is_nothrow_swappable_with<T, U>::value; // C++17
template <class T> inline constexpr bool is_nothrow_swappable_v
= is_nothrow_swappable<T>::value; // C++17
template <class T> inline constexpr bool is_nothrow_destructible_v
= is_nothrow_destructible<T>::value; // C++17
template <class T> inline constexpr bool has_virtual_destructor_v
= has_virtual_destructor<T>::value; // C++17
template<class T> inline constexpr bool has_unique_object_representations_v // C++17
= has_unique_object_representations<T>::value;
// See C++14 20.10.5, type property queries
template <class T> inline constexpr size_t alignment_of_v
= alignment_of<T>::value; // C++17
template <class T> inline constexpr size_t rank_v
= rank<T>::value; // C++17
template <class T, unsigned I = 0> inline constexpr size_t extent_v
= extent<T, I>::value; // C++17
// See C++14 20.10.6, type relations
template <class T, class U> inline constexpr bool is_same_v
= is_same<T, U>::value; // C++17
template <class Base, class Derived> inline constexpr bool is_base_of_v
= is_base_of<Base, Derived>::value; // C++17
template <class From, class To> inline constexpr bool is_convertible_v
= is_convertible<From, To>::value; // C++17
template <class Fn, class... ArgTypes> inline constexpr bool is_invocable_v
= is_invocable<Fn, ArgTypes...>::value; // C++17
template <class R, class Fn, class... ArgTypes> inline constexpr bool is_invocable_r_v
= is_invocable_r<R, Fn, ArgTypes...>::value; // C++17
template <class Fn, class... ArgTypes> inline constexpr bool is_nothrow_invocable_v
= is_nothrow_invocable<Fn, ArgTypes...>::value; // C++17
template <class R, class Fn, class... ArgTypes> inline constexpr bool is_nothrow_invocable_r_v
= is_nothrow_invocable_r<R, Fn, ArgTypes...>::value; // C++17
// [meta.logical], logical operator traits:
template<class... B> struct conjunction; // C++17
template<class... B>
inline constexpr bool conjunction_v = conjunction<B...>::value; // C++17
template<class... B> struct disjunction; // C++17
template<class... B>
inline constexpr bool disjunction_v = disjunction<B...>::value; // C++17
template<class B> struct negation; // C++17
template<class B>
inline constexpr bool negation_v = negation<B>::value; // C++17
}
*/
template <class _T1, class _T2> struct _LIBCPP_TEMPLATE_VIS pair;
template <class _Tp> class _LIBCPP_TEMPLATE_VIS reference_wrapper;
template <class _Tp> struct _LIBCPP_TEMPLATE_VIS hash;
template <class _Tp, _Tp __v>
struct _LIBCPP_TEMPLATE_VIS integral_constant
{
static _LIBCPP_CONSTEXPR const _Tp value = __v;
typedef _Tp value_type;
typedef integral_constant type;
_LIBCPP_INLINE_VISIBILITY
_LIBCPP_CONSTEXPR operator value_type() const _NOEXCEPT {return value;}
#if _LIBCPP_STD_VER > 11
_LIBCPP_INLINE_VISIBILITY
constexpr value_type operator ()() const _NOEXCEPT {return value;}
#endif
};
template <class _Tp, _Tp __v>
_LIBCPP_CONSTEXPR const _Tp integral_constant<_Tp, __v>::value;
#if _LIBCPP_STD_VER > 14
template <bool __b>
using bool_constant = integral_constant<bool, __b>;
#define _LIBCPP_BOOL_CONSTANT(__b) bool_constant<(__b)>
#else
#define _LIBCPP_BOOL_CONSTANT(__b) integral_constant<bool,(__b)>
#endif
typedef _LIBCPP_BOOL_CONSTANT(true) true_type;
typedef _LIBCPP_BOOL_CONSTANT(false) false_type;
template <bool _Val>
using _BoolConstant _LIBCPP_NODEBUG_TYPE = integral_constant<bool, _Val>;
template <bool> struct _MetaBase;
template <>
struct _MetaBase<true> {
template <class _Tp, class _Up>
using _SelectImpl _LIBCPP_NODEBUG_TYPE = _Tp;
template <template <class...> class _FirstFn, template <class...> class, class ..._Args>
using _SelectApplyImpl _LIBCPP_NODEBUG_TYPE = _FirstFn<_Args...>;
template <class _First, class...>
using _FirstImpl _LIBCPP_NODEBUG_TYPE = _First;
template <class, class _Second, class...>
using _SecondImpl _LIBCPP_NODEBUG_TYPE = _Second;
template <class _Tp = void>
using _EnableIfImpl _LIBCPP_NODEBUG_TYPE = _Tp;
template <class _Result, class _First, class ..._Rest>
using _OrImpl _LIBCPP_NODEBUG_TYPE = typename _MetaBase<_First::value != true && sizeof...(_Rest) != 0>::template _OrImpl<_First, _Rest...>;
template <class _Result, class _First, class ..._Rest>
using _AndImpl _LIBCPP_NODEBUG_TYPE = typename _MetaBase<_First::value == true && sizeof...(_Rest) != 0>::template _AndImpl<_First, _Rest...>;
};
template <>
struct _MetaBase<false> {
template <class _Tp, class _Up>
using _SelectImpl _LIBCPP_NODEBUG_TYPE = _Up;
template <template <class...> class, template <class...> class _SecondFn, class ..._Args>
using _SelectApplyImpl _LIBCPP_NODEBUG_TYPE = _SecondFn<_Args...>;
template <class _Result, class ...>
using _OrImpl _LIBCPP_NODEBUG_TYPE = _Result;
template <class _Result, class ...>
using _AndImpl _LIBCPP_NODEBUG_TYPE = _Result;
};
template <bool _Cond, class _Ret = void>
using _EnableIf _LIBCPP_NODEBUG_TYPE = typename _MetaBase<_Cond>::template _EnableIfImpl<_Ret>;
template <bool _Cond, class _IfRes, class _ElseRes>
using _If _LIBCPP_NODEBUG_TYPE = typename _MetaBase<_Cond>::template _SelectImpl<_IfRes, _ElseRes>;
template <class ..._Rest>
using _Or _LIBCPP_NODEBUG_TYPE = typename _MetaBase< sizeof...(_Rest) != 0 >::template _OrImpl<false_type, _Rest...>;
template <class ..._Rest>
using _And _LIBCPP_NODEBUG_TYPE = typename _MetaBase< sizeof...(_Rest) != 0 >::template _AndImpl<true_type, _Rest...>;
template <class _Pred>
struct _Not : _BoolConstant<!_Pred::value> {};
template <class ..._Args>
using _FirstType _LIBCPP_NODEBUG_TYPE = typename _MetaBase<(sizeof...(_Args) >= 1)>::template _FirstImpl<_Args...>;
template <class ..._Args>
using _SecondType _LIBCPP_NODEBUG_TYPE = typename _MetaBase<(sizeof...(_Args) >= 2)>::template _SecondImpl<_Args...>;
template <template <class...> class _Func, class ..._Args>
struct _Lazy : _Func<_Args...> {};
// Member detector base
template <template <class...> class _Templ, class ..._Args, class = _Templ<_Args...> >
true_type __sfinae_test_impl(int);
template <template <class...> class, class ...>
false_type __sfinae_test_impl(...);
template <template <class ...> class _Templ, class ..._Args>
using _IsValidExpansion _LIBCPP_NODEBUG_TYPE = decltype(std::__sfinae_test_impl<_Templ, _Args...>(0));
template <class>
struct __void_t { typedef void type; };
template <class _Tp>
struct __identity { typedef _Tp type; };
template <class _Tp, bool>
struct _LIBCPP_TEMPLATE_VIS __dependent_type : public _Tp {};
template <bool _Bp, class _If, class _Then>
struct _LIBCPP_TEMPLATE_VIS conditional {typedef _If type;};
template <class _If, class _Then>
struct _LIBCPP_TEMPLATE_VIS conditional<false, _If, _Then> {typedef _Then type;};
#if _LIBCPP_STD_VER > 11
template <bool _Bp, class _If, class _Then> using conditional_t = typename conditional<_Bp, _If, _Then>::type;
#endif
template <bool, class _Tp = void> struct _LIBCPP_TEMPLATE_VIS enable_if {};
template <class _Tp> struct _LIBCPP_TEMPLATE_VIS enable_if<true, _Tp> {typedef _Tp type;};
#if _LIBCPP_STD_VER > 11
template <bool _Bp, class _Tp = void> using enable_if_t = typename enable_if<_Bp, _Tp>::type;
#endif
// is_same
template <class _Tp, class _Up> struct _LIBCPP_TEMPLATE_VIS is_same : public false_type {};
template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_same<_Tp, _Tp> : public true_type {};
#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
template <class _Tp, class _Up>
_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_same_v
= is_same<_Tp, _Up>::value;
#endif
template <class _Tp, class _Up>
using _IsSame = _BoolConstant<
#ifdef __clang__
__is_same(_Tp, _Up)
#else
_VSTD::is_same<_Tp, _Up>::value
#endif
>;
template <class _Tp, class _Up>
using _IsNotSame = _BoolConstant<
#ifdef __clang__
!__is_same(_Tp, _Up)
#else
!_VSTD::is_same<_Tp, _Up>::value
#endif
>;
// addressof
#ifndef _LIBCPP_HAS_NO_BUILTIN_ADDRESSOF
template <class _Tp>
inline _LIBCPP_CONSTEXPR_AFTER_CXX14
_LIBCPP_NO_CFI _LIBCPP_INLINE_VISIBILITY
_Tp*
addressof(_Tp& __x) _NOEXCEPT
{
return __builtin_addressof(__x);
}
#else
template <class _Tp>
inline _LIBCPP_NO_CFI _LIBCPP_INLINE_VISIBILITY
_Tp*
addressof(_Tp& __x) _NOEXCEPT
{
return reinterpret_cast<_Tp *>(
const_cast<char *>(&reinterpret_cast<const volatile char &>(__x)));
}
#endif // _LIBCPP_HAS_NO_BUILTIN_ADDRESSOF
#if defined(_LIBCPP_HAS_OBJC_ARC) && !defined(_LIBCPP_PREDEFINED_OBJC_ARC_ADDRESSOF)
// Objective-C++ Automatic Reference Counting uses qualified pointers
// that require special addressof() signatures. When
// _LIBCPP_PREDEFINED_OBJC_ARC_ADDRESSOF is defined, the compiler
// itself is providing these definitions. Otherwise, we provide them.
template <class _Tp>
inline _LIBCPP_INLINE_VISIBILITY
__strong _Tp*
addressof(__strong _Tp& __x) _NOEXCEPT
{
return &__x;
}
#ifdef _LIBCPP_HAS_OBJC_ARC_WEAK
template <class _Tp>
inline _LIBCPP_INLINE_VISIBILITY
__weak _Tp*
addressof(__weak _Tp& __x) _NOEXCEPT
{
return &__x;
}
#endif
template <class _Tp>
inline _LIBCPP_INLINE_VISIBILITY
__autoreleasing _Tp*
addressof(__autoreleasing _Tp& __x) _NOEXCEPT
{
return &__x;
}
template <class _Tp>
inline _LIBCPP_INLINE_VISIBILITY
__unsafe_unretained _Tp*
addressof(__unsafe_unretained _Tp& __x) _NOEXCEPT
{
return &__x;
}
#endif
#if !defined(_LIBCPP_CXX03_LANG)
template <class _Tp> _Tp* addressof(const _Tp&&) noexcept = delete;
#endif
struct __two {char __lx[2];};
// helper class:
// is_const
template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_const : public false_type {};
template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_const<_Tp const> : public true_type {};
#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
template <class _Tp>
_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_const_v
= is_const<_Tp>::value;
#endif
// is_volatile
template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_volatile : public false_type {};
template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_volatile<_Tp volatile> : public true_type {};
#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
template <class _Tp>
_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_volatile_v
= is_volatile<_Tp>::value;
#endif
// remove_const
template <class _Tp> struct _LIBCPP_TEMPLATE_VIS remove_const {typedef _Tp type;};
template <class _Tp> struct _LIBCPP_TEMPLATE_VIS remove_const<const _Tp> {typedef _Tp type;};
#if _LIBCPP_STD_VER > 11
template <class _Tp> using remove_const_t = typename remove_const<_Tp>::type;
#endif
// remove_volatile
template <class _Tp> struct _LIBCPP_TEMPLATE_VIS remove_volatile {typedef _Tp type;};
template <class _Tp> struct _LIBCPP_TEMPLATE_VIS remove_volatile<volatile _Tp> {typedef _Tp type;};
#if _LIBCPP_STD_VER > 11
template <class _Tp> using remove_volatile_t = typename remove_volatile<_Tp>::type;
#endif
// remove_cv
template <class _Tp> struct _LIBCPP_TEMPLATE_VIS remove_cv
{typedef typename remove_volatile<typename remove_const<_Tp>::type>::type type;};
#if _LIBCPP_STD_VER > 11
template <class _Tp> using remove_cv_t = typename remove_cv<_Tp>::type;
#endif
// is_void
template <class _Tp> struct __libcpp_is_void : public false_type {};
template <> struct __libcpp_is_void<void> : public true_type {};
template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_void
: public __libcpp_is_void<typename remove_cv<_Tp>::type> {};
#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
template <class _Tp>
_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_void_v
= is_void<_Tp>::value;
#endif
// __is_nullptr_t
template <class _Tp> struct __is_nullptr_t_impl : public false_type {};
template <> struct __is_nullptr_t_impl<nullptr_t> : public true_type {};
template <class _Tp> struct _LIBCPP_TEMPLATE_VIS __is_nullptr_t
: public __is_nullptr_t_impl<typename remove_cv<_Tp>::type> {};
#if _LIBCPP_STD_VER > 11
template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_null_pointer
: public __is_nullptr_t_impl<typename remove_cv<_Tp>::type> {};
#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
template <class _Tp>
_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_null_pointer_v
= is_null_pointer<_Tp>::value;
#endif
#endif
// is_integral
template <class _Tp> struct __libcpp_is_integral : public false_type {};
template <> struct __libcpp_is_integral<bool> : public true_type {};
template <> struct __libcpp_is_integral<char> : public true_type {};
template <> struct __libcpp_is_integral<signed char> : public true_type {};
template <> struct __libcpp_is_integral<unsigned char> : public true_type {};
template <> struct __libcpp_is_integral<wchar_t> : public true_type {};
#ifndef _LIBCPP_NO_HAS_CHAR8_T
template <> struct __libcpp_is_integral<char8_t> : public true_type {};
#endif
#ifndef _LIBCPP_HAS_NO_UNICODE_CHARS
template <> struct __libcpp_is_integral<char16_t> : public true_type {};
template <> struct __libcpp_is_integral<char32_t> : public true_type {};
#endif // _LIBCPP_HAS_NO_UNICODE_CHARS
template <> struct __libcpp_is_integral<short> : public true_type {};
template <> struct __libcpp_is_integral<unsigned short> : public true_type {};
template <> struct __libcpp_is_integral<int> : public true_type {};
template <> struct __libcpp_is_integral<unsigned int> : public true_type {};
template <> struct __libcpp_is_integral<long> : public true_type {};
template <> struct __libcpp_is_integral<unsigned long> : public true_type {};
template <> struct __libcpp_is_integral<long long> : public true_type {};
template <> struct __libcpp_is_integral<unsigned long long> : public true_type {};
#ifndef _LIBCPP_HAS_NO_INT128
template <> struct __libcpp_is_integral<__int128_t> : public true_type {};
template <> struct __libcpp_is_integral<__uint128_t> : public true_type {};
#endif
template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_integral
: public __libcpp_is_integral<typename remove_cv<_Tp>::type> {};
#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
template <class _Tp>
_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_integral_v
= is_integral<_Tp>::value;
#endif
// is_floating_point
template <class _Tp> struct __libcpp_is_floating_point : public false_type {};
template <> struct __libcpp_is_floating_point<float> : public true_type {};
template <> struct __libcpp_is_floating_point<double> : public true_type {};
template <> struct __libcpp_is_floating_point<long double> : public true_type {};
template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_floating_point
: public __libcpp_is_floating_point<typename remove_cv<_Tp>::type> {};
#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
template <class _Tp>
_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_floating_point_v
= is_floating_point<_Tp>::value;
#endif
// is_array
template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_array
: public false_type {};
template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_array<_Tp[]>
: public true_type {};
template <class _Tp, size_t _Np> struct _LIBCPP_TEMPLATE_VIS is_array<_Tp[_Np]>
: public true_type {};
#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
template <class _Tp>
_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_array_v
= is_array<_Tp>::value;
#endif
// is_pointer
template <class _Tp> struct __libcpp_is_pointer : public false_type {};
template <class _Tp> struct __libcpp_is_pointer<_Tp*> : public true_type {};
template <class _Tp> struct __libcpp_remove_objc_qualifiers { typedef _Tp type; };
#if defined(_LIBCPP_HAS_OBJC_ARC)
template <class _Tp> struct __libcpp_remove_objc_qualifiers<_Tp __strong> { typedef _Tp type; };
template <class _Tp> struct __libcpp_remove_objc_qualifiers<_Tp __weak> { typedef _Tp type; };
template <class _Tp> struct __libcpp_remove_objc_qualifiers<_Tp __autoreleasing> { typedef _Tp type; };
template <class _Tp> struct __libcpp_remove_objc_qualifiers<_Tp __unsafe_unretained> { typedef _Tp type; };
#endif
template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_pointer
: public __libcpp_is_pointer<typename __libcpp_remove_objc_qualifiers<typename remove_cv<_Tp>::type>::type> {};
#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
template <class _Tp>
_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_pointer_v
= is_pointer<_Tp>::value;
#endif
// is_reference
template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_lvalue_reference : public false_type {};
template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_lvalue_reference<_Tp&> : public true_type {};
template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_rvalue_reference : public false_type {};
template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_rvalue_reference<_Tp&&> : public true_type {};
template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_reference : public false_type {};
template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_reference<_Tp&> : public true_type {};
template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_reference<_Tp&&> : public true_type {};
#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
template <class _Tp>
_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_reference_v
= is_reference<_Tp>::value;
template <class _Tp>
_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_lvalue_reference_v
= is_lvalue_reference<_Tp>::value;
template <class _Tp>
_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_rvalue_reference_v
= is_rvalue_reference<_Tp>::value;
#endif
// is_union
#if __has_feature(is_union) || defined(_LIBCPP_COMPILER_GCC)
template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_union
: public integral_constant<bool, __is_union(_Tp)> {};
#else
template <class _Tp> struct __libcpp_union : public false_type {};
template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_union
: public __libcpp_union<typename remove_cv<_Tp>::type> {};
#endif
#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
template <class _Tp>
_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_union_v
= is_union<_Tp>::value;
#endif
// is_class
#if __has_feature(is_class) || defined(_LIBCPP_COMPILER_GCC)
template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_class
: public integral_constant<bool, __is_class(_Tp)> {};
#else
namespace __is_class_imp
{
template <class _Tp> char __test(int _Tp::*);
template <class _Tp> __two __test(...);
}
template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_class
: public integral_constant<bool, sizeof(__is_class_imp::__test<_Tp>(0)) == 1 && !is_union<_Tp>::value> {};
#endif
#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
template <class _Tp>
_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_class_v
= is_class<_Tp>::value;
#endif
// is_function
template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_function
: public _BoolConstant<
#ifdef __clang__
__is_function(_Tp)
#else
!(is_reference<_Tp>::value || is_const<const _Tp>::value)
#endif
> {};
#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
template <class _Tp>
_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_function_v
= is_function<_Tp>::value;
#endif
template <class _Tp> struct __libcpp_is_member_pointer {
enum {
__is_member = false,
__is_func = false,
__is_obj = false
};
};
template <class _Tp, class _Up> struct __libcpp_is_member_pointer<_Tp _Up::*> {
enum {
__is_member = true,
__is_func = is_function<_Tp>::value,
__is_obj = !__is_func,
};
};
template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_member_function_pointer
: public _BoolConstant< __libcpp_is_member_pointer<typename remove_cv<_Tp>::type>::__is_func > {};
#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
template <class _Tp>
_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_member_function_pointer_v
= is_member_function_pointer<_Tp>::value;
#endif
// is_member_pointer
template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_member_pointer
: public _BoolConstant< __libcpp_is_member_pointer<typename remove_cv<_Tp>::type>::__is_member > {};
#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
template <class _Tp>
_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_member_pointer_v
= is_member_pointer<_Tp>::value;
#endif
// is_member_object_pointer
template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_member_object_pointer
: public _BoolConstant< __libcpp_is_member_pointer<typename remove_cv<_Tp>::type>::__is_obj > {};
#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
template <class _Tp>
_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_member_object_pointer_v
= is_member_object_pointer<_Tp>::value;
#endif
// is_enum
#if __has_feature(is_enum) || defined(_LIBCPP_COMPILER_GCC)
template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_enum
: public integral_constant<bool, __is_enum(_Tp)> {};
#else
template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_enum
: public integral_constant<bool, !is_void<_Tp>::value &&
!is_integral<_Tp>::value &&
!is_floating_point<_Tp>::value &&
!is_array<_Tp>::value &&
!is_pointer<_Tp>::value &&
!is_reference<_Tp>::value &&
!is_member_pointer<_Tp>::value &&
!is_union<_Tp>::value &&
!is_class<_Tp>::value &&
!is_function<_Tp>::value > {};
#endif
#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
template <class _Tp>
_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_enum_v
= is_enum<_Tp>::value;
#endif
// is_arithmetic
template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_arithmetic
: public integral_constant<bool, is_integral<_Tp>::value ||
is_floating_point<_Tp>::value> {};
#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
template <class _Tp>
_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_arithmetic_v
= is_arithmetic<_Tp>::value;
#endif
// is_fundamental
template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_fundamental
: public integral_constant<bool, is_void<_Tp>::value ||
__is_nullptr_t<_Tp>::value ||
is_arithmetic<_Tp>::value> {};
#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
template <class _Tp>
_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_fundamental_v
= is_fundamental<_Tp>::value;
#endif
// is_scalar
template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_scalar
: public integral_constant<bool, is_arithmetic<_Tp>::value ||
is_member_pointer<_Tp>::value ||
is_pointer<_Tp>::value ||
__is_nullptr_t<_Tp>::value ||
is_enum<_Tp>::value > {};
template <> struct _LIBCPP_TEMPLATE_VIS is_scalar<nullptr_t> : public true_type {};
#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
template <class _Tp>
_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_scalar_v
= is_scalar<_Tp>::value;
#endif
// is_object
template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_object
: public integral_constant<bool, is_scalar<_Tp>::value ||
is_array<_Tp>::value ||
is_union<_Tp>::value ||
is_class<_Tp>::value > {};
#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
template <class _Tp>
_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_object_v
= is_object<_Tp>::value;
#endif
// is_compound
template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_compound
: public integral_constant<bool, !is_fundamental<_Tp>::value> {};
#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
template <class _Tp>
_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_compound_v
= is_compound<_Tp>::value;
#endif
// __is_referenceable [defns.referenceable]
struct __is_referenceable_impl {
template <class _Tp> static _Tp& __test(int);
template <class _Tp> static __two __test(...);
};
template <class _Tp>
struct __is_referenceable : integral_constant<bool,
_IsNotSame<decltype(__is_referenceable_impl::__test<_Tp>(0)), __two>::value> {};
// add_const
template <class _Tp> struct _LIBCPP_TEMPLATE_VIS add_const {
typedef _LIBCPP_NODEBUG_TYPE const _Tp type;
};
#if _LIBCPP_STD_VER > 11
template <class _Tp> using add_const_t = typename add_const<_Tp>::type;
#endif
// add_volatile
template <class _Tp> struct _LIBCPP_TEMPLATE_VIS add_volatile {
typedef _LIBCPP_NODEBUG_TYPE volatile _Tp type;
};
#if _LIBCPP_STD_VER > 11
template <class _Tp> using add_volatile_t = typename add_volatile<_Tp>::type;
#endif
// add_cv
template <class _Tp> struct _LIBCPP_TEMPLATE_VIS add_cv {
typedef _LIBCPP_NODEBUG_TYPE const volatile _Tp type;
};
#if _LIBCPP_STD_VER > 11
template <class _Tp> using add_cv_t = typename add_cv<_Tp>::type;
#endif
// remove_reference
template <class _Tp> struct _LIBCPP_TEMPLATE_VIS remove_reference {typedef _LIBCPP_NODEBUG_TYPE _Tp type;};
template <class _Tp> struct _LIBCPP_TEMPLATE_VIS remove_reference<_Tp&> {typedef _LIBCPP_NODEBUG_TYPE _Tp type;};
template <class _Tp> struct _LIBCPP_TEMPLATE_VIS remove_reference<_Tp&&> {typedef _LIBCPP_NODEBUG_TYPE _Tp type;};
#if _LIBCPP_STD_VER > 11
template <class _Tp> using remove_reference_t = typename remove_reference<_Tp>::type;
#endif
// add_lvalue_reference
template <class _Tp, bool = __is_referenceable<_Tp>::value> struct __add_lvalue_reference_impl { typedef _LIBCPP_NODEBUG_TYPE _Tp type; };
template <class _Tp > struct __add_lvalue_reference_impl<_Tp, true> { typedef _LIBCPP_NODEBUG_TYPE _Tp& type; };
template <class _Tp> struct _LIBCPP_TEMPLATE_VIS add_lvalue_reference
{typedef _LIBCPP_NODEBUG_TYPE typename __add_lvalue_reference_impl<_Tp>::type type;};
#if _LIBCPP_STD_VER > 11
template <class _Tp> using add_lvalue_reference_t = typename add_lvalue_reference<_Tp>::type;
#endif
template <class _Tp, bool = __is_referenceable<_Tp>::value> struct __add_rvalue_reference_impl { typedef _LIBCPP_NODEBUG_TYPE _Tp type; };
template <class _Tp > struct __add_rvalue_reference_impl<_Tp, true> { typedef _LIBCPP_NODEBUG_TYPE _Tp&& type; };
template <class _Tp> struct _LIBCPP_TEMPLATE_VIS add_rvalue_reference
{typedef _LIBCPP_NODEBUG_TYPE typename __add_rvalue_reference_impl<_Tp>::type type;};
#if _LIBCPP_STD_VER > 11
template <class _Tp> using add_rvalue_reference_t = typename add_rvalue_reference<_Tp>::type;
#endif
// Suppress deprecation notice for volatile-qualified return type resulting
// from volatile-qualified types _Tp.
_LIBCPP_SUPPRESS_DEPRECATED_PUSH
template <class _Tp> _Tp&& __declval(int);
template <class _Tp> _Tp __declval(long);
_LIBCPP_SUPPRESS_DEPRECATED_POP
template <class _Tp>
decltype(_VSTD::__declval<_Tp>(0))
declval() _NOEXCEPT;
// __uncvref
template <class _Tp>
struct __uncvref {
typedef _LIBCPP_NODEBUG_TYPE typename remove_cv<typename remove_reference<_Tp>::type>::type type;
};
template <class _Tp>
struct __unconstref {
typedef _LIBCPP_NODEBUG_TYPE typename remove_const<typename remove_reference<_Tp>::type>::type type;
};
#ifndef _LIBCPP_CXX03_LANG
template <class _Tp>
using __uncvref_t _LIBCPP_NODEBUG_TYPE = typename __uncvref<_Tp>::type;
#endif
// __is_same_uncvref
template <class _Tp, class _Up>
struct __is_same_uncvref : _IsSame<typename __uncvref<_Tp>::type,
typename __uncvref<_Up>::type> {};
#if _LIBCPP_STD_VER > 17
// remove_cvref - same as __uncvref
template <class _Tp>
struct remove_cvref : public __uncvref<_Tp> {};
template <class _Tp> using remove_cvref_t = typename remove_cvref<_Tp>::type;
#endif
struct __any
{
__any(...);
};
// remove_pointer
template <class _Tp> struct _LIBCPP_TEMPLATE_VIS remove_pointer {typedef _LIBCPP_NODEBUG_TYPE _Tp type;};
template <class _Tp> struct _LIBCPP_TEMPLATE_VIS remove_pointer<_Tp*> {typedef _LIBCPP_NODEBUG_TYPE _Tp type;};
template <class _Tp> struct _LIBCPP_TEMPLATE_VIS remove_pointer<_Tp* const> {typedef _LIBCPP_NODEBUG_TYPE _Tp type;};
template <class _Tp> struct _LIBCPP_TEMPLATE_VIS remove_pointer<_Tp* volatile> {typedef _LIBCPP_NODEBUG_TYPE _Tp type;};
template <class _Tp> struct _LIBCPP_TEMPLATE_VIS remove_pointer<_Tp* const volatile> {typedef _LIBCPP_NODEBUG_TYPE _Tp type;};
#if _LIBCPP_STD_VER > 11
template <class _Tp> using remove_pointer_t = typename remove_pointer<_Tp>::type;
#endif
// add_pointer
template <class _Tp,
bool = __is_referenceable<_Tp>::value ||
_IsSame<typename remove_cv<_Tp>::type, void>::value>
struct __add_pointer_impl
{typedef _LIBCPP_NODEBUG_TYPE typename remove_reference<_Tp>::type* type;};
template <class _Tp> struct __add_pointer_impl<_Tp, false>
{typedef _LIBCPP_NODEBUG_TYPE _Tp type;};
template <class _Tp> struct _LIBCPP_TEMPLATE_VIS add_pointer
{typedef _LIBCPP_NODEBUG_TYPE typename __add_pointer_impl<_Tp>::type type;};
#if _LIBCPP_STD_VER > 11
template <class _Tp> using add_pointer_t = typename add_pointer<_Tp>::type;
#endif
// type_identity
#if _LIBCPP_STD_VER > 17
template<class _Tp> struct type_identity { typedef _Tp type; };
template<class _Tp> using type_identity_t = typename type_identity<_Tp>::type;
#endif
// is_signed
template <class _Tp, bool = is_integral<_Tp>::value>
struct __libcpp_is_signed_impl : public _LIBCPP_BOOL_CONSTANT(_Tp(-1) < _Tp(0)) {};
template <class _Tp>
struct __libcpp_is_signed_impl<_Tp, false> : public true_type {}; // floating point
template <class _Tp, bool = is_arithmetic<_Tp>::value>
struct __libcpp_is_signed : public __libcpp_is_signed_impl<_Tp> {};
template <class _Tp> struct __libcpp_is_signed<_Tp, false> : public false_type {};
template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_signed : public __libcpp_is_signed<_Tp> {};
#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
template <class _Tp>
_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_signed_v
= is_signed<_Tp>::value;
#endif
// is_unsigned
template <class _Tp, bool = is_integral<_Tp>::value>
struct __libcpp_is_unsigned_impl : public _LIBCPP_BOOL_CONSTANT(_Tp(0) < _Tp(-1)) {};
template <class _Tp>
struct __libcpp_is_unsigned_impl<_Tp, false> : public false_type {}; // floating point
template <class _Tp, bool = is_arithmetic<_Tp>::value>
struct __libcpp_is_unsigned : public __libcpp_is_unsigned_impl<_Tp> {};
template <class _Tp> struct __libcpp_is_unsigned<_Tp, false> : public false_type {};
template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_unsigned : public __libcpp_is_unsigned<_Tp> {};
#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
template <class _Tp>
_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_unsigned_v
= is_unsigned<_Tp>::value;
#endif
// rank
template <class _Tp> struct _LIBCPP_TEMPLATE_VIS rank
: public integral_constant<size_t, 0> {};
template <class _Tp> struct _LIBCPP_TEMPLATE_VIS rank<_Tp[]>
: public integral_constant<size_t, rank<_Tp>::value + 1> {};
template <class _Tp, size_t _Np> struct _LIBCPP_TEMPLATE_VIS rank<_Tp[_Np]>
: public integral_constant<size_t, rank<_Tp>::value + 1> {};
#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
template <class _Tp>
_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR size_t rank_v
= rank<_Tp>::value;
#endif
// extent
template <class _Tp, unsigned _Ip = 0> struct _LIBCPP_TEMPLATE_VIS extent
: public integral_constant<size_t, 0> {};
template <class _Tp> struct _LIBCPP_TEMPLATE_VIS extent<_Tp[], 0>
: public integral_constant<size_t, 0> {};
template <class _Tp, unsigned _Ip> struct _LIBCPP_TEMPLATE_VIS extent<_Tp[], _Ip>
: public integral_constant<size_t, extent<_Tp, _Ip-1>::value> {};
template <class _Tp, size_t _Np> struct _LIBCPP_TEMPLATE_VIS extent<_Tp[_Np], 0>
: public integral_constant<size_t, _Np> {};
template <class _Tp, size_t _Np, unsigned _Ip> struct _LIBCPP_TEMPLATE_VIS extent<_Tp[_Np], _Ip>
: public integral_constant<size_t, extent<_Tp, _Ip-1>::value> {};
#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
template <class _Tp, unsigned _Ip = 0>
_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR size_t extent_v
= extent<_Tp, _Ip>::value;
#endif
// remove_extent
template <class _Tp> struct _LIBCPP_TEMPLATE_VIS remove_extent
{typedef _Tp type;};
template <class _Tp> struct _LIBCPP_TEMPLATE_VIS remove_extent<_Tp[]>
{typedef _Tp type;};
template <class _Tp, size_t _Np> struct _LIBCPP_TEMPLATE_VIS remove_extent<_Tp[_Np]>
{typedef _Tp type;};
#if _LIBCPP_STD_VER > 11
template <class _Tp> using remove_extent_t = typename remove_extent<_Tp>::type;
#endif
// remove_all_extents
template <class _Tp> struct _LIBCPP_TEMPLATE_VIS remove_all_extents
{typedef _Tp type;};
template <class _Tp> struct _LIBCPP_TEMPLATE_VIS remove_all_extents<_Tp[]>
{typedef typename remove_all_extents<_Tp>::type type;};
template <class _Tp, size_t _Np> struct _LIBCPP_TEMPLATE_VIS remove_all_extents<_Tp[_Np]>
{typedef typename remove_all_extents<_Tp>::type type;};
#if _LIBCPP_STD_VER > 11
template <class _Tp> using remove_all_extents_t = typename remove_all_extents<_Tp>::type;
#endif
#if _LIBCPP_STD_VER > 17
// is_bounded_array
template <class> struct _LIBCPP_TEMPLATE_VIS is_bounded_array : false_type {};
template <class _Tp, size_t _Np> struct _LIBCPP_TEMPLATE_VIS is_bounded_array<_Tp[_Np]> : true_type {};
template <class _Tp>
_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR
bool is_bounded_array_v = is_bounded_array<_Tp>::value;
// is_unbounded_array
template <class> struct _LIBCPP_TEMPLATE_VIS is_unbounded_array : false_type {};
template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_unbounded_array<_Tp[]> : true_type {};
template <class _Tp>
_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR
bool is_unbounded_array_v = is_unbounded_array<_Tp>::value;
#endif
// decay
template <class _Up, bool>
struct __decay {
typedef _LIBCPP_NODEBUG_TYPE typename remove_cv<_Up>::type type;
};
template <class _Up>
struct __decay<_Up, true> {
public:
typedef _LIBCPP_NODEBUG_TYPE typename conditional
<
is_array<_Up>::value,
typename remove_extent<_Up>::type*,
typename conditional
<
is_function<_Up>::value,
typename add_pointer<_Up>::type,
typename remove_cv<_Up>::type
>::type
>::type type;
};
template <class _Tp>
struct _LIBCPP_TEMPLATE_VIS decay
{
private:
typedef _LIBCPP_NODEBUG_TYPE typename remove_reference<_Tp>::type _Up;
public:
typedef _LIBCPP_NODEBUG_TYPE typename __decay<_Up, __is_referenceable<_Up>::value>::type type;
};
#if _LIBCPP_STD_VER > 11
template <class _Tp> using decay_t = typename decay<_Tp>::type;
#endif
// is_abstract
template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_abstract
: public integral_constant<bool, __is_abstract(_Tp)> {};
#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
template <class _Tp>
_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_abstract_v
= is_abstract<_Tp>::value;
#endif
// is_final
template <class _Tp> struct _LIBCPP_TEMPLATE_VIS
__libcpp_is_final : public integral_constant<bool, __is_final(_Tp)> {};
#if _LIBCPP_STD_VER > 11
template <class _Tp> struct _LIBCPP_TEMPLATE_VIS
is_final : public integral_constant<bool, __is_final(_Tp)> {};
#endif
#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
template <class _Tp>
_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_final_v
= is_final<_Tp>::value;
#endif
// is_aggregate
#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_IS_AGGREGATE)
template <class _Tp> struct _LIBCPP_TEMPLATE_VIS
is_aggregate : public integral_constant<bool, __is_aggregate(_Tp)> {};
#if !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
template <class _Tp>
_LIBCPP_INLINE_VAR constexpr bool is_aggregate_v
= is_aggregate<_Tp>::value;
#endif
#endif // _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_IS_AGGREGATE)
// is_base_of
template <class _Bp, class _Dp>
struct _LIBCPP_TEMPLATE_VIS is_base_of
: public integral_constant<bool, __is_base_of(_Bp, _Dp)> {};
#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
template <class _Bp, class _Dp>
_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_base_of_v
= is_base_of<_Bp, _Dp>::value;
#endif
// is_convertible
#if __has_feature(is_convertible_to) && !defined(_LIBCPP_USE_IS_CONVERTIBLE_FALLBACK)
template <class _T1, class _T2> struct _LIBCPP_TEMPLATE_VIS is_convertible
: public integral_constant<bool, __is_convertible_to(_T1, _T2) &&
!is_abstract<_T2>::value> {};
#else // __has_feature(is_convertible_to)
namespace __is_convertible_imp
{
template <class _Tp> void __test_convert(_Tp);
template <class _From, class _To, class = void>
struct __is_convertible_test : public false_type {};
template <class _From, class _To>
struct __is_convertible_test<_From, _To,
decltype(_VSTD::__is_convertible_imp::__test_convert<_To>(_VSTD::declval<_From>()))> : public true_type
{};
template <class _Tp, bool _IsArray = is_array<_Tp>::value,
bool _IsFunction = is_function<_Tp>::value,
bool _IsVoid = is_void<_Tp>::value>
struct __is_array_function_or_void {enum {value = 0};};
template <class _Tp> struct __is_array_function_or_void<_Tp, true, false, false> {enum {value = 1};};
template <class _Tp> struct __is_array_function_or_void<_Tp, false, true, false> {enum {value = 2};};
template <class _Tp> struct __is_array_function_or_void<_Tp, false, false, true> {enum {value = 3};};
}
template <class _Tp,
unsigned = __is_convertible_imp::__is_array_function_or_void<typename remove_reference<_Tp>::type>::value>
struct __is_convertible_check
{
static const size_t __v = 0;
};
template <class _Tp>
struct __is_convertible_check<_Tp, 0>
{
static const size_t __v = sizeof(_Tp);
};
template <class _T1, class _T2,
unsigned _T1_is_array_function_or_void = __is_convertible_imp::__is_array_function_or_void<_T1>::value,
unsigned _T2_is_array_function_or_void = __is_convertible_imp::__is_array_function_or_void<_T2>::value>
struct __is_convertible
: public integral_constant<bool,
__is_convertible_imp::__is_convertible_test<_T1, _T2>::value
>
{};
template <class _T1, class _T2> struct __is_convertible<_T1, _T2, 0, 1> : public false_type {};
template <class _T1, class _T2> struct __is_convertible<_T1, _T2, 1, 1> : public false_type {};
template <class _T1, class _T2> struct __is_convertible<_T1, _T2, 2, 1> : public false_type {};
template <class _T1, class _T2> struct __is_convertible<_T1, _T2, 3, 1> : public false_type {};
template <class _T1, class _T2> struct __is_convertible<_T1, _T2, 0, 2> : public false_type {};
template <class _T1, class _T2> struct __is_convertible<_T1, _T2, 1, 2> : public false_type {};
template <class _T1, class _T2> struct __is_convertible<_T1, _T2, 2, 2> : public false_type {};
template <class _T1, class _T2> struct __is_convertible<_T1, _T2, 3, 2> : public false_type {};
template <class _T1, class _T2> struct __is_convertible<_T1, _T2, 0, 3> : public false_type {};
template <class _T1, class _T2> struct __is_convertible<_T1, _T2, 1, 3> : public false_type {};
template <class _T1, class _T2> struct __is_convertible<_T1, _T2, 2, 3> : public false_type {};
template <class _T1, class _T2> struct __is_convertible<_T1, _T2, 3, 3> : public true_type {};
template <class _T1, class _T2> struct _LIBCPP_TEMPLATE_VIS is_convertible
: public __is_convertible<_T1, _T2>
{
static const size_t __complete_check1 = __is_convertible_check<_T1>::__v;
static const size_t __complete_check2 = __is_convertible_check<_T2>::__v;
};
#endif // __has_feature(is_convertible_to)
#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
template <class _From, class _To>
_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_convertible_v
= is_convertible<_From, _To>::value;
#endif
// is_nothrow_convertible
#if _LIBCPP_STD_VER > 17
template <typename _Tp>
static void __test_noexcept(_Tp) noexcept;
template<typename _Fm, typename _To>
static bool_constant<noexcept(__test_noexcept<_To>(declval<_Fm>()))>
__is_nothrow_convertible_test();
template <typename _Fm, typename _To>
struct __is_nothrow_convertible_helper: decltype(__is_nothrow_convertible_test<_Fm, _To>())
{ };
template <typename _Fm, typename _To>
struct is_nothrow_convertible : _Or<
_And<is_void<_To>, is_void<_Fm>>,
_Lazy<_And, is_convertible<_Fm, _To>, __is_nothrow_convertible_helper<_Fm, _To>>
>::type { };
template <typename _Fm, typename _To>
inline constexpr bool is_nothrow_convertible_v = is_nothrow_convertible<_Fm, _To>::value;
#endif // _LIBCPP_STD_VER > 17
// is_empty
#if __has_feature(is_empty) || defined(_LIBCPP_COMPILER_GCC)
template <class _Tp>
struct _LIBCPP_TEMPLATE_VIS is_empty
: public integral_constant<bool, __is_empty(_Tp)> {};
#else // __has_feature(is_empty)
template <class _Tp>
struct __is_empty1
: public _Tp
{
double __lx;
};
struct __is_empty2
{
double __lx;
};
template <class _Tp, bool = is_class<_Tp>::value>
struct __libcpp_empty : public integral_constant<bool, sizeof(__is_empty1<_Tp>) == sizeof(__is_empty2)> {};
template <class _Tp> struct __libcpp_empty<_Tp, false> : public false_type {};
template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_empty : public __libcpp_empty<_Tp> {};
#endif // __has_feature(is_empty)
#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
template <class _Tp>
_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_empty_v
= is_empty<_Tp>::value;
#endif
// is_polymorphic
#if __has_feature(is_polymorphic) || defined(_LIBCPP_COMPILER_MSVC)
template <class _Tp>
struct _LIBCPP_TEMPLATE_VIS is_polymorphic
: public integral_constant<bool, __is_polymorphic(_Tp)> {};
#else
template<typename _Tp> char &__is_polymorphic_impl(
typename enable_if<sizeof((_Tp*)dynamic_cast<const volatile void*>(declval<_Tp*>())) != 0,
int>::type);
template<typename _Tp> __two &__is_polymorphic_impl(...);
template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_polymorphic
: public integral_constant<bool, sizeof(__is_polymorphic_impl<_Tp>(0)) == 1> {};
#endif // __has_feature(is_polymorphic)
#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
template <class _Tp>
_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_polymorphic_v
= is_polymorphic<_Tp>::value;
#endif
// has_virtual_destructor
#if __has_feature(has_virtual_destructor) || defined(_LIBCPP_COMPILER_GCC)
template <class _Tp> struct _LIBCPP_TEMPLATE_VIS has_virtual_destructor
: public integral_constant<bool, __has_virtual_destructor(_Tp)> {};
#else
template <class _Tp> struct _LIBCPP_TEMPLATE_VIS has_virtual_destructor
: public false_type {};
#endif
#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
template <class _Tp>
_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool has_virtual_destructor_v
= has_virtual_destructor<_Tp>::value;
#endif
// has_unique_object_representations
#if _LIBCPP_STD_VER > 14 && defined(_LIBCPP_HAS_UNIQUE_OBJECT_REPRESENTATIONS)
template <class _Tp> struct _LIBCPP_TEMPLATE_VIS has_unique_object_representations
: public integral_constant<bool,
__has_unique_object_representations(remove_cv_t<remove_all_extents_t<_Tp>>)> {};
#if !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
template <class _Tp>
_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool has_unique_object_representations_v
= has_unique_object_representations<_Tp>::value;
#endif
#endif
// alignment_of
template <class _Tp> struct _LIBCPP_TEMPLATE_VIS alignment_of
: public integral_constant<size_t, _LIBCPP_ALIGNOF(_Tp)> {};
#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
template <class _Tp>
_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR size_t alignment_of_v
= alignment_of<_Tp>::value;
#endif
// aligned_storage
template <class _Hp, class _Tp>
struct __type_list
{
typedef _Hp _Head;
typedef _Tp _Tail;
};
struct __nat
{
#ifndef _LIBCPP_CXX03_LANG
__nat() = delete;
__nat(const __nat&) = delete;
__nat& operator=(const __nat&) = delete;
~__nat() = delete;
#endif
};
template <class _Tp>
struct __align_type
{
static const size_t value = _LIBCPP_PREFERRED_ALIGNOF(_Tp);
typedef _Tp type;
};
struct __struct_double {long double __lx;};
struct __struct_double4 {double __lx[4];};
typedef
__type_list<__align_type<unsigned char>,
__type_list<__align_type<unsigned short>,
__type_list<__align_type<unsigned int>,
__type_list<__align_type<unsigned long>,
__type_list<__align_type<unsigned long long>,
__type_list<__align_type<double>,
__type_list<__align_type<long double>,
__type_list<__align_type<__struct_double>,
__type_list<__align_type<__struct_double4>,
__type_list<__align_type<int*>,
__nat
> > > > > > > > > > __all_types;
template <size_t _Align>
struct _ALIGNAS(_Align) __fallback_overaligned {};
template <class _TL, size_t _Align> struct __find_pod;
template <class _Hp, size_t _Align>
struct __find_pod<__type_list<_Hp, __nat>, _Align>
{
typedef typename conditional<
_Align == _Hp::value,
typename _Hp::type,
__fallback_overaligned<_Align>
>::type type;
};
template <class _Hp, class _Tp, size_t _Align>
struct __find_pod<__type_list<_Hp, _Tp>, _Align>
{
typedef typename conditional<
_Align == _Hp::value,
typename _Hp::type,
typename __find_pod<_Tp, _Align>::type
>::type type;
};
template <class _TL, size_t _Len> struct __find_max_align;
template <class _Hp, size_t _Len>
struct __find_max_align<__type_list<_Hp, __nat>, _Len> : public integral_constant<size_t, _Hp::value> {};
template <size_t _Len, size_t _A1, size_t _A2>
struct __select_align
{
private:
static const size_t __min = _A2 < _A1 ? _A2 : _A1;
static const size_t __max = _A1 < _A2 ? _A2 : _A1;
public:
static const size_t value = _Len < __max ? __min : __max;
};
template <class _Hp, class _Tp, size_t _Len>
struct __find_max_align<__type_list<_Hp, _Tp>, _Len>
: public integral_constant<size_t, __select_align<_Len, _Hp::value, __find_max_align<_Tp, _Len>::value>::value> {};
template <size_t _Len, size_t _Align = __find_max_align<__all_types, _Len>::value>
struct _LIBCPP_TEMPLATE_VIS aligned_storage
{
typedef typename __find_pod<__all_types, _Align>::type _Aligner;
union type
{
_Aligner __align;
unsigned char __data[(_Len + _Align - 1)/_Align * _Align];
};
};
#if _LIBCPP_STD_VER > 11
template <size_t _Len, size_t _Align = __find_max_align<__all_types, _Len>::value>
using aligned_storage_t = typename aligned_storage<_Len, _Align>::type;
#endif
#define _CREATE_ALIGNED_STORAGE_SPECIALIZATION(n) \
template <size_t _Len>\
struct _LIBCPP_TEMPLATE_VIS aligned_storage<_Len, n>\
{\
struct _ALIGNAS(n) type\
{\
unsigned char __lx[(_Len + n - 1)/n * n];\
};\
}
_CREATE_ALIGNED_STORAGE_SPECIALIZATION(0x1);
_CREATE_ALIGNED_STORAGE_SPECIALIZATION(0x2);
_CREATE_ALIGNED_STORAGE_SPECIALIZATION(0x4);
_CREATE_ALIGNED_STORAGE_SPECIALIZATION(0x8);
_CREATE_ALIGNED_STORAGE_SPECIALIZATION(0x10);
_CREATE_ALIGNED_STORAGE_SPECIALIZATION(0x20);
_CREATE_ALIGNED_STORAGE_SPECIALIZATION(0x40);
_CREATE_ALIGNED_STORAGE_SPECIALIZATION(0x80);
_CREATE_ALIGNED_STORAGE_SPECIALIZATION(0x100);
_CREATE_ALIGNED_STORAGE_SPECIALIZATION(0x200);
_CREATE_ALIGNED_STORAGE_SPECIALIZATION(0x400);
_CREATE_ALIGNED_STORAGE_SPECIALIZATION(0x800);
_CREATE_ALIGNED_STORAGE_SPECIALIZATION(0x1000);
_CREATE_ALIGNED_STORAGE_SPECIALIZATION(0x2000);
// PE/COFF does not support alignment beyond 8192 (=0x2000)
#if !defined(_LIBCPP_OBJECT_FORMAT_COFF)
_CREATE_ALIGNED_STORAGE_SPECIALIZATION(0x4000);
#endif // !defined(_LIBCPP_OBJECT_FORMAT_COFF)
#undef _CREATE_ALIGNED_STORAGE_SPECIALIZATION
// aligned_union
template <size_t _I0, size_t ..._In>
struct __static_max;
template <size_t _I0>
struct __static_max<_I0>
{
static const size_t value = _I0;
};
template <size_t _I0, size_t _I1, size_t ..._In>
struct __static_max<_I0, _I1, _In...>
{
static const size_t value = _I0 >= _I1 ? __static_max<_I0, _In...>::value :
__static_max<_I1, _In...>::value;
};
template <size_t _Len, class _Type0, class ..._Types>
struct aligned_union
{
static const size_t alignment_value = __static_max<_LIBCPP_PREFERRED_ALIGNOF(_Type0),
_LIBCPP_PREFERRED_ALIGNOF(_Types)...>::value;
static const size_t __len = __static_max<_Len, sizeof(_Type0),
sizeof(_Types)...>::value;
typedef typename aligned_storage<__len, alignment_value>::type type;
};
#if _LIBCPP_STD_VER > 11
template <size_t _Len, class ..._Types> using aligned_union_t = typename aligned_union<_Len, _Types...>::type;
#endif
template <class _Tp>
struct __numeric_type
{
static void __test(...);
static float __test(float);
static double __test(char);
static double __test(int);
static double __test(unsigned);
static double __test(long);
static double __test(unsigned long);
static double __test(long long);
static double __test(unsigned long long);
static double __test(double);
static long double __test(long double);
typedef decltype(__test(declval<_Tp>())) type;
static const bool value = _IsNotSame<type, void>::value;
};
template <>
struct __numeric_type<void>
{
static const bool value = true;
};
// __promote
template <class _A1, class _A2 = void, class _A3 = void,
bool = __numeric_type<_A1>::value &&
__numeric_type<_A2>::value &&
__numeric_type<_A3>::value>
class __promote_imp
{
public:
static const bool value = false;
};
template <class _A1, class _A2, class _A3>
class __promote_imp<_A1, _A2, _A3, true>
{
private:
typedef typename __promote_imp<_A1>::type __type1;
typedef typename __promote_imp<_A2>::type __type2;
typedef typename __promote_imp<_A3>::type __type3;
public:
typedef decltype(__type1() + __type2() + __type3()) type;
static const bool value = true;
};
template <class _A1, class _A2>
class __promote_imp<_A1, _A2, void, true>
{
private:
typedef typename __promote_imp<_A1>::type __type1;
typedef typename __promote_imp<_A2>::type __type2;
public:
typedef decltype(__type1() + __type2()) type;
static const bool value = true;
};
template <class _A1>
class __promote_imp<_A1, void, void, true>
{
public:
typedef typename __numeric_type<_A1>::type type;
static const bool value = true;
};
template <class _A1, class _A2 = void, class _A3 = void>
class __promote : public __promote_imp<_A1, _A2, _A3> {};
// make_signed / make_unsigned
typedef
__type_list<signed char,
__type_list<signed short,
__type_list<signed int,
__type_list<signed long,
__type_list<signed long long,
#ifndef _LIBCPP_HAS_NO_INT128
__type_list<__int128_t,
#endif
__nat
#ifndef _LIBCPP_HAS_NO_INT128
>
#endif
> > > > > __signed_types;
typedef
__type_list<unsigned char,
__type_list<unsigned short,
__type_list<unsigned int,
__type_list<unsigned long,
__type_list<unsigned long long,
#ifndef _LIBCPP_HAS_NO_INT128
__type_list<__uint128_t,
#endif
__nat
#ifndef _LIBCPP_HAS_NO_INT128
>
#endif
> > > > > __unsigned_types;
template <class _TypeList, size_t _Size, bool = _Size <= sizeof(typename _TypeList::_Head)> struct __find_first;
template <class _Hp, class _Tp, size_t _Size>
struct __find_first<__type_list<_Hp, _Tp>, _Size, true>
{
typedef _LIBCPP_NODEBUG_TYPE _Hp type;
};
template <class _Hp, class _Tp, size_t _Size>
struct __find_first<__type_list<_Hp, _Tp>, _Size, false>
{
typedef _LIBCPP_NODEBUG_TYPE typename __find_first<_Tp, _Size>::type type;
};
template <class _Tp, class _Up, bool = is_const<typename remove_reference<_Tp>::type>::value,
bool = is_volatile<typename remove_reference<_Tp>::type>::value>
struct __apply_cv
{
typedef _LIBCPP_NODEBUG_TYPE _Up type;
};
template <class _Tp, class _Up>
struct __apply_cv<_Tp, _Up, true, false>
{
typedef _LIBCPP_NODEBUG_TYPE const _Up type;
};
template <class _Tp, class _Up>
struct __apply_cv<_Tp, _Up, false, true>
{
typedef volatile _Up type;
};
template <class _Tp, class _Up>
struct __apply_cv<_Tp, _Up, true, true>
{
typedef const volatile _Up type;
};
template <class _Tp, class _Up>
struct __apply_cv<_Tp&, _Up, false, false>
{
typedef _Up& type;
};
template <class _Tp, class _Up>
struct __apply_cv<_Tp&, _Up, true, false>
{
typedef const _Up& type;
};
template <class _Tp, class _Up>
struct __apply_cv<_Tp&, _Up, false, true>
{
typedef volatile _Up& type;
};
template <class _Tp, class _Up>
struct __apply_cv<_Tp&, _Up, true, true>
{
typedef const volatile _Up& type;
};
template <class _Tp, bool = is_integral<_Tp>::value || is_enum<_Tp>::value>
struct __make_signed {};
template <class _Tp>
struct __make_signed<_Tp, true>
{
typedef typename __find_first<__signed_types, sizeof(_Tp)>::type type;
};
template <> struct __make_signed<bool, true> {};
template <> struct __make_signed< signed short, true> {typedef short type;};
template <> struct __make_signed<unsigned short, true> {typedef short type;};
template <> struct __make_signed< signed int, true> {typedef int type;};
template <> struct __make_signed<unsigned int, true> {typedef int type;};
template <> struct __make_signed< signed long, true> {typedef long type;};
template <> struct __make_signed<unsigned long, true> {typedef long type;};
template <> struct __make_signed< signed long long, true> {typedef long long type;};
template <> struct __make_signed<unsigned long long, true> {typedef long long type;};
#ifndef _LIBCPP_HAS_NO_INT128
template <> struct __make_signed<__int128_t, true> {typedef __int128_t type;};
template <> struct __make_signed<__uint128_t, true> {typedef __int128_t type;};
#endif
template <class _Tp>
struct _LIBCPP_TEMPLATE_VIS make_signed
{
typedef typename __apply_cv<_Tp, typename __make_signed<typename remove_cv<_Tp>::type>::type>::type type;
};
#if _LIBCPP_STD_VER > 11
template <class _Tp> using make_signed_t = typename make_signed<_Tp>::type;
#endif
template <class _Tp, bool = is_integral<_Tp>::value || is_enum<_Tp>::value>
struct __make_unsigned {};
template <class _Tp>
struct __make_unsigned<_Tp, true>
{
typedef typename __find_first<__unsigned_types, sizeof(_Tp)>::type type;
};
template <> struct __make_unsigned<bool, true> {};
template <> struct __make_unsigned< signed short, true> {typedef unsigned short type;};
template <> struct __make_unsigned<unsigned short, true> {typedef unsigned short type;};
template <> struct __make_unsigned< signed int, true> {typedef unsigned int type;};
template <> struct __make_unsigned<unsigned int, true> {typedef unsigned int type;};
template <> struct __make_unsigned< signed long, true> {typedef unsigned long type;};
template <> struct __make_unsigned<unsigned long, true> {typedef unsigned long type;};
template <> struct __make_unsigned< signed long long, true> {typedef unsigned long long type;};
template <> struct __make_unsigned<unsigned long long, true> {typedef unsigned long long type;};
#ifndef _LIBCPP_HAS_NO_INT128
template <> struct __make_unsigned<__int128_t, true> {typedef __uint128_t type;};
template <> struct __make_unsigned<__uint128_t, true> {typedef __uint128_t type;};
#endif
template <class _Tp>
struct _LIBCPP_TEMPLATE_VIS make_unsigned
{
typedef typename __apply_cv<_Tp, typename __make_unsigned<typename remove_cv<_Tp>::type>::type>::type type;
};
#if _LIBCPP_STD_VER > 11
template <class _Tp> using make_unsigned_t = typename make_unsigned<_Tp>::type;
#endif
template <class _Tp, class _Up, class = void>
struct __common_type2_imp {};
template <class _Tp, class _Up>
struct __common_type2_imp<_Tp, _Up,
typename __void_t<decltype(
true ? _VSTD::declval<_Tp>() : _VSTD::declval<_Up>()
)>::type>
{
typedef _LIBCPP_NODEBUG_TYPE typename decay<decltype(
true ? _VSTD::declval<_Tp>() : _VSTD::declval<_Up>()
)>::type type;
};
template <class, class = void>
struct __common_type_impl {};
// Clang provides variadic templates in C++03 as an extension.
#if !defined(_LIBCPP_CXX03_LANG) || defined(__clang__)
# define _LIBCPP_OPTIONAL_PACK(...) , __VA_ARGS__
template <class... Tp>
struct __common_types;
template <class... _Tp>
struct _LIBCPP_TEMPLATE_VIS common_type;
#else
# define _LIBCPP_OPTIONAL_PACK(...)
struct __no_arg;
template <class _Tp, class _Up, class = __no_arg>
struct __common_types;
template <class _Tp = __no_arg, class _Up = __no_arg, class _Vp = __no_arg,
class _Unused = __no_arg>
struct common_type {
static_assert(sizeof(_Unused) == 0,
"common_type accepts at most 3 arguments in C++03");
};
#endif // _LIBCPP_CXX03_LANG
template <class _Tp, class _Up>
struct __common_type_impl<
__common_types<_Tp, _Up>,
typename __void_t<typename common_type<_Tp, _Up>::type>::type>
{
typedef typename common_type<_Tp, _Up>::type type;
};
template <class _Tp, class _Up, class _Vp _LIBCPP_OPTIONAL_PACK(class... _Rest)>
struct __common_type_impl<
__common_types<_Tp, _Up, _Vp _LIBCPP_OPTIONAL_PACK(_Rest...)>,
typename __void_t<typename common_type<_Tp, _Up>::type>::type>
: __common_type_impl<__common_types<typename common_type<_Tp, _Up>::type,
_Vp _LIBCPP_OPTIONAL_PACK(_Rest...)> > {
};
// bullet 1 - sizeof...(Tp) == 0
template <>
struct _LIBCPP_TEMPLATE_VIS common_type<> {};
// bullet 2 - sizeof...(Tp) == 1
template <class _Tp>
struct _LIBCPP_TEMPLATE_VIS common_type<_Tp>
: public common_type<_Tp, _Tp> {};
// bullet 3 - sizeof...(Tp) == 2
template <class _Tp, class _Up>
struct _LIBCPP_TEMPLATE_VIS common_type<_Tp, _Up>
: conditional<
_IsSame<_Tp, typename decay<_Tp>::type>::value && _IsSame<_Up, typename decay<_Up>::type>::value,
__common_type2_imp<_Tp, _Up>,
common_type<typename decay<_Tp>::type, typename decay<_Up>::type>
>::type
{};
// bullet 4 - sizeof...(Tp) > 2
template <class _Tp, class _Up, class _Vp _LIBCPP_OPTIONAL_PACK(class... _Rest)>
struct _LIBCPP_TEMPLATE_VIS
common_type<_Tp, _Up, _Vp _LIBCPP_OPTIONAL_PACK(_Rest...)>
: __common_type_impl<
__common_types<_Tp, _Up, _Vp _LIBCPP_OPTIONAL_PACK(_Rest...)> > {};
#undef _LIBCPP_OPTIONAL_PACK
#if _LIBCPP_STD_VER > 11
template <class ..._Tp> using common_type_t = typename common_type<_Tp...>::type;
#endif
// is_assignable
template<typename, typename _Tp> struct __select_2nd { typedef _LIBCPP_NODEBUG_TYPE _Tp type; };
template <class _Tp, class _Arg>
typename __select_2nd<decltype((_VSTD::declval<_Tp>() = _VSTD::declval<_Arg>())), true_type>::type
__is_assignable_test(int);
template <class, class>
false_type __is_assignable_test(...);
template <class _Tp, class _Arg, bool = is_void<_Tp>::value || is_void<_Arg>::value>
struct __is_assignable_imp
: public decltype((_VSTD::__is_assignable_test<_Tp, _Arg>(0))) {};
template <class _Tp, class _Arg>
struct __is_assignable_imp<_Tp, _Arg, true>
: public false_type
{
};
template <class _Tp, class _Arg>
struct is_assignable
: public __is_assignable_imp<_Tp, _Arg> {};
#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
template <class _Tp, class _Arg>
_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_assignable_v
= is_assignable<_Tp, _Arg>::value;
#endif
// is_copy_assignable
template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_copy_assignable
: public is_assignable<typename add_lvalue_reference<_Tp>::type,
typename add_lvalue_reference<typename add_const<_Tp>::type>::type> {};
#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
template <class _Tp>
_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_copy_assignable_v
= is_copy_assignable<_Tp>::value;
#endif
// is_move_assignable
template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_move_assignable
: public is_assignable<typename add_lvalue_reference<_Tp>::type,
typename add_rvalue_reference<_Tp>::type> {};
#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
template <class _Tp>
_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_move_assignable_v
= is_move_assignable<_Tp>::value;
#endif
// is_destructible
// if it's a reference, return true
// if it's a function, return false
// if it's void, return false
// if it's an array of unknown bound, return false
// Otherwise, return "std::declval<_Up&>().~_Up()" is well-formed
// where _Up is remove_all_extents<_Tp>::type
template <class>
struct __is_destructible_apply { typedef int type; };
template <typename _Tp>
struct __is_destructor_wellformed {
template <typename _Tp1>
static char __test (
typename __is_destructible_apply<decltype(_VSTD::declval<_Tp1&>().~_Tp1())>::type
);
template <typename _Tp1>
static __two __test (...);
static const bool value = sizeof(__test<_Tp>(12)) == sizeof(char);
};
template <class _Tp, bool>
struct __destructible_imp;
template <class _Tp>
struct __destructible_imp<_Tp, false>
: public _VSTD::integral_constant<bool,
__is_destructor_wellformed<typename _VSTD::remove_all_extents<_Tp>::type>::value> {};
template <class _Tp>
struct __destructible_imp<_Tp, true>
: public _VSTD::true_type {};
template <class _Tp, bool>
struct __destructible_false;
template <class _Tp>
struct __destructible_false<_Tp, false> : public __destructible_imp<_Tp, _VSTD::is_reference<_Tp>::value> {};
template <class _Tp>
struct __destructible_false<_Tp, true> : public _VSTD::false_type {};
template <class _Tp>
struct is_destructible
: public __destructible_false<_Tp, _VSTD::is_function<_Tp>::value> {};
template <class _Tp>
struct is_destructible<_Tp[]>
: public _VSTD::false_type {};
template <>
struct is_destructible<void>
: public _VSTD::false_type {};
#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
template <class _Tp>
_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_destructible_v
= is_destructible<_Tp>::value;
#endif
// move
template <class _Tp>
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
typename remove_reference<_Tp>::type&&
move(_Tp&& __t) _NOEXCEPT
{
typedef _LIBCPP_NODEBUG_TYPE typename remove_reference<_Tp>::type _Up;
return static_cast<_Up&&>(__t);
}
template <class _Tp>
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
_Tp&&
forward(typename remove_reference<_Tp>::type& __t) _NOEXCEPT
{
return static_cast<_Tp&&>(__t);
}
template <class _Tp>
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
_Tp&&
forward(typename remove_reference<_Tp>::type&& __t) _NOEXCEPT
{
static_assert(!is_lvalue_reference<_Tp>::value,
"can not forward an rvalue as an lvalue");
return static_cast<_Tp&&>(__t);
}
template <class _Tp>
inline _LIBCPP_INLINE_VISIBILITY
typename decay<_Tp>::type
__decay_copy(_Tp&& __t)
{
return _VSTD::forward<_Tp>(__t);
}
template <class _MP, bool _IsMemberFunctionPtr, bool _IsMemberObjectPtr>
struct __member_pointer_traits_imp
{
};
template <class _Rp, class _Class, class ..._Param>
struct __member_pointer_traits_imp<_Rp (_Class::*)(_Param...), true, false>
{
typedef _Class _ClassType;
typedef _Rp _ReturnType;
typedef _Rp (_FnType) (_Param...);
};
template <class _Rp, class _Class, class ..._Param>
struct __member_pointer_traits_imp<_Rp (_Class::*)(_Param..., ...), true, false>
{
typedef _Class _ClassType;
typedef _Rp _ReturnType;
typedef _Rp (_FnType) (_Param..., ...);
};
template <class _Rp, class _Class, class ..._Param>
struct __member_pointer_traits_imp<_Rp (_Class::*)(_Param...) const, true, false>
{
typedef _Class const _ClassType;
typedef _Rp _ReturnType;
typedef _Rp (_FnType) (_Param...);
};
template <class _Rp, class _Class, class ..._Param>
struct __member_pointer_traits_imp<_Rp (_Class::*)(_Param..., ...) const, true, false>
{
typedef _Class const _ClassType;
typedef _Rp _ReturnType;
typedef _Rp (_FnType) (_Param..., ...);
};
template <class _Rp, class _Class, class ..._Param>
struct __member_pointer_traits_imp<_Rp (_Class::*)(_Param...) volatile, true, false>
{
typedef _Class volatile _ClassType;
typedef _Rp _ReturnType;
typedef _Rp (_FnType) (_Param...);
};
template <class _Rp, class _Class, class ..._Param>
struct __member_pointer_traits_imp<_Rp (_Class::*)(_Param..., ...) volatile, true, false>
{
typedef _Class volatile _ClassType;
typedef _Rp _ReturnType;
typedef _Rp (_FnType) (_Param..., ...);
};
template <class _Rp, class _Class, class ..._Param>
struct __member_pointer_traits_imp<_Rp (_Class::*)(_Param...) const volatile, true, false>
{
typedef _Class const volatile _ClassType;
typedef _Rp _ReturnType;
typedef _Rp (_FnType) (_Param...);
};
template <class _Rp, class _Class, class ..._Param>
struct __member_pointer_traits_imp<_Rp (_Class::*)(_Param..., ...) const volatile, true, false>
{
typedef _Class const volatile _ClassType;
typedef _Rp _ReturnType;
typedef _Rp (_FnType) (_Param..., ...);
};
#if __has_feature(cxx_reference_qualified_functions) || defined(_LIBCPP_COMPILER_GCC)
template <class _Rp, class _Class, class ..._Param>
struct __member_pointer_traits_imp<_Rp (_Class::*)(_Param...) &, true, false>
{
typedef _Class& _ClassType;
typedef _Rp _ReturnType;
typedef _Rp (_FnType) (_Param...);
};
template <class _Rp, class _Class, class ..._Param>
struct __member_pointer_traits_imp<_Rp (_Class::*)(_Param..., ...) &, true, false>
{
typedef _Class& _ClassType;
typedef _Rp _ReturnType;
typedef _Rp (_FnType) (_Param..., ...);
};
template <class _Rp, class _Class, class ..._Param>
struct __member_pointer_traits_imp<_Rp (_Class::*)(_Param...) const&, true, false>
{
typedef _Class const& _ClassType;
typedef _Rp _ReturnType;
typedef _Rp (_FnType) (_Param...);
};
template <class _Rp, class _Class, class ..._Param>
struct __member_pointer_traits_imp<_Rp (_Class::*)(_Param..., ...) const&, true, false>
{
typedef _Class const& _ClassType;
typedef _Rp _ReturnType;
typedef _Rp (_FnType) (_Param..., ...);
};
template <class _Rp, class _Class, class ..._Param>
struct __member_pointer_traits_imp<_Rp (_Class::*)(_Param...) volatile&, true, false>
{
typedef _Class volatile& _ClassType;
typedef _Rp _ReturnType;
typedef _Rp (_FnType) (_Param...);
};
template <class _Rp, class _Class, class ..._Param>
struct __member_pointer_traits_imp<_Rp (_Class::*)(_Param..., ...) volatile&, true, false>
{
typedef _Class volatile& _ClassType;
typedef _Rp _ReturnType;
typedef _Rp (_FnType) (_Param..., ...);
};
template <class _Rp, class _Class, class ..._Param>
struct __member_pointer_traits_imp<_Rp (_Class::*)(_Param...) const volatile&, true, false>
{
typedef _Class const volatile& _ClassType;
typedef _Rp _ReturnType;
typedef _Rp (_FnType) (_Param...);
};
template <class _Rp, class _Class, class ..._Param>
struct __member_pointer_traits_imp<_Rp (_Class::*)(_Param..., ...) const volatile&, true, false>
{
typedef _Class const volatile& _ClassType;
typedef _Rp _ReturnType;
typedef _Rp (_FnType) (_Param..., ...);
};
template <class _Rp, class _Class, class ..._Param>
struct __member_pointer_traits_imp<_Rp (_Class::*)(_Param...) &&, true, false>
{
typedef _Class&& _ClassType;
typedef _Rp _ReturnType;
typedef _Rp (_FnType) (_Param...);
};
template <class _Rp, class _Class, class ..._Param>
struct __member_pointer_traits_imp<_Rp (_Class::*)(_Param..., ...) &&, true, false>
{
typedef _Class&& _ClassType;
typedef _Rp _ReturnType;
typedef _Rp (_FnType) (_Param..., ...);
};
template <class _Rp, class _Class, class ..._Param>
struct __member_pointer_traits_imp<_Rp (_Class::*)(_Param...) const&&, true, false>
{
typedef _Class const&& _ClassType;
typedef _Rp _ReturnType;
typedef _Rp (_FnType) (_Param...);
};
template <class _Rp, class _Class, class ..._Param>
struct __member_pointer_traits_imp<_Rp (_Class::*)(_Param..., ...) const&&, true, false>
{
typedef _Class const&& _ClassType;
typedef _Rp _ReturnType;
typedef _Rp (_FnType) (_Param..., ...);
};
template <class _Rp, class _Class, class ..._Param>
struct __member_pointer_traits_imp<_Rp (_Class::*)(_Param...) volatile&&, true, false>
{
typedef _Class volatile&& _ClassType;
typedef _Rp _ReturnType;
typedef _Rp (_FnType) (_Param...);
};
template <class _Rp, class _Class, class ..._Param>
struct __member_pointer_traits_imp<_Rp (_Class::*)(_Param..., ...) volatile&&, true, false>
{
typedef _Class volatile&& _ClassType;
typedef _Rp _ReturnType;
typedef _Rp (_FnType) (_Param..., ...);
};
template <class _Rp, class _Class, class ..._Param>
struct __member_pointer_traits_imp<_Rp (_Class::*)(_Param...) const volatile&&, true, false>
{
typedef _Class const volatile&& _ClassType;
typedef _Rp _ReturnType;
typedef _Rp (_FnType) (_Param...);
};
template <class _Rp, class _Class, class ..._Param>
struct __member_pointer_traits_imp<_Rp (_Class::*)(_Param..., ...) const volatile&&, true, false>
{
typedef _Class const volatile&& _ClassType;
typedef _Rp _ReturnType;
typedef _Rp (_FnType) (_Param..., ...);
};
#endif // __has_feature(cxx_reference_qualified_functions) || defined(_LIBCPP_COMPILER_GCC)
template <class _Rp, class _Class>
struct __member_pointer_traits_imp<_Rp _Class::*, false, true>
{
typedef _Class _ClassType;
typedef _Rp _ReturnType;
};
template <class _MP>
struct __member_pointer_traits
: public __member_pointer_traits_imp<typename remove_cv<_MP>::type,
is_member_function_pointer<_MP>::value,
is_member_object_pointer<_MP>::value>
{
// typedef ... _ClassType;
// typedef ... _ReturnType;
// typedef ... _FnType;
};
template <class _DecayedFp>
struct __member_pointer_class_type {};
template <class _Ret, class _ClassType>
struct __member_pointer_class_type<_Ret _ClassType::*> {
typedef _ClassType type;
};
// result_of
template <class _Callable> class result_of;
#ifdef _LIBCPP_HAS_NO_VARIADICS
template <class _Fn, bool, bool>
class __result_of
{
};
template <class _Fn>
class __result_of<_Fn(), true, false>
{
public:
typedef decltype(declval<_Fn>()()) type;
};
template <class _Fn, class _A0>
class __result_of<_Fn(_A0), true, false>
{
public:
typedef decltype(declval<_Fn>()(declval<_A0>())) type;
};
template <class _Fn, class _A0, class _A1>
class __result_of<_Fn(_A0, _A1), true, false>
{
public:
typedef decltype(declval<_Fn>()(declval<_A0>(), declval<_A1>())) type;
};
template <class _Fn, class _A0, class _A1, class _A2>
class __result_of<_Fn(_A0, _A1, _A2), true, false>
{
public:
typedef decltype(declval<_Fn>()(declval<_A0>(), declval<_A1>(), declval<_A2>())) type;
};
template <class _MP, class _Tp, bool _IsMemberFunctionPtr>
struct __result_of_mp;
// member function pointer
template <class _MP, class _Tp>
struct __result_of_mp<_MP, _Tp, true>
: public __identity<typename __member_pointer_traits<_MP>::_ReturnType>
{
};
// member data pointer
template <class _MP, class _Tp, bool>
struct __result_of_mdp;
template <class _Rp, class _Class, class _Tp>
struct __result_of_mdp<_Rp _Class::*, _Tp, false>
{
typedef typename __apply_cv<decltype(*_VSTD::declval<_Tp>()), _Rp>::type& type;
};
template <class _Rp, class _Class, class _Tp>
struct __result_of_mdp<_Rp _Class::*, _Tp, true>
{
typedef typename __apply_cv<_Tp, _Rp>::type& type;
};
template <class _Rp, class _Class, class _Tp>
struct __result_of_mp<_Rp _Class::*, _Tp, false>
: public __result_of_mdp<_Rp _Class::*, _Tp,
is_base_of<_Class, typename remove_reference<_Tp>::type>::value>
{
};
template <class _Fn, class _Tp>
class __result_of<_Fn(_Tp), false, true> // _Fn must be member pointer
: public __result_of_mp<typename remove_reference<_Fn>::type,
_Tp,
is_member_function_pointer<typename remove_reference<_Fn>::type>::value>
{
};
template <class _Fn, class _Tp, class _A0>
class __result_of<_Fn(_Tp, _A0), false, true> // _Fn must be member pointer
: public __result_of_mp<typename remove_reference<_Fn>::type,
_Tp,
is_member_function_pointer<typename remove_reference<_Fn>::type>::value>
{
};
template <class _Fn, class _Tp, class _A0, class _A1>
class __result_of<_Fn(_Tp, _A0, _A1), false, true> // _Fn must be member pointer
: public __result_of_mp<typename remove_reference<_Fn>::type,
_Tp,
is_member_function_pointer<typename remove_reference<_Fn>::type>::value>
{
};
template <class _Fn, class _Tp, class _A0, class _A1, class _A2>
class __result_of<_Fn(_Tp, _A0, _A1, _A2), false, true> // _Fn must be member pointer
: public __result_of_mp<typename remove_reference<_Fn>::type,
_Tp,
is_member_function_pointer<typename remove_reference<_Fn>::type>::value>
{
};
// result_of
template <class _Fn>
class _LIBCPP_TEMPLATE_VIS result_of<_Fn()>
: public __result_of<_Fn(),
is_class<typename remove_reference<_Fn>::type>::value ||
is_function<typename remove_pointer<typename remove_reference<_Fn>::type>::type>::value,
is_member_pointer<typename remove_reference<_Fn>::type>::value
>
{
};
template <class _Fn, class _A0>
class _LIBCPP_TEMPLATE_VIS result_of<_Fn(_A0)>
: public __result_of<_Fn(_A0),
is_class<typename remove_reference<_Fn>::type>::value ||
is_function<typename remove_pointer<typename remove_reference<_Fn>::type>::type>::value,
is_member_pointer<typename remove_reference<_Fn>::type>::value
>
{
};
template <class _Fn, class _A0, class _A1>
class _LIBCPP_TEMPLATE_VIS result_of<_Fn(_A0, _A1)>
: public __result_of<_Fn(_A0, _A1),
is_class<typename remove_reference<_Fn>::type>::value ||
is_function<typename remove_pointer<typename remove_reference<_Fn>::type>::type>::value,
is_member_pointer<typename remove_reference<_Fn>::type>::value
>
{
};
template <class _Fn, class _A0, class _A1, class _A2>
class _LIBCPP_TEMPLATE_VIS result_of<_Fn(_A0, _A1, _A2)>
: public __result_of<_Fn(_A0, _A1, _A2),
is_class<typename remove_reference<_Fn>::type>::value ||
is_function<typename remove_pointer<typename remove_reference<_Fn>::type>::type>::value,
is_member_pointer<typename remove_reference<_Fn>::type>::value
>
{
};
#endif // _LIBCPP_HAS_NO_VARIADICS
// template <class T, class... Args> struct is_constructible;
namespace __is_construct
{
struct __nat {};
}
#if !defined(_LIBCPP_CXX03_LANG) && (!__has_feature(is_constructible) || \
defined(_LIBCPP_TESTING_FALLBACK_IS_CONSTRUCTIBLE))
template <class _Tp, class... _Args>
struct __libcpp_is_constructible;
template <class _To, class _From>
struct __is_invalid_base_to_derived_cast {
static_assert(is_reference<_To>::value, "Wrong specialization");
using _RawFrom = __uncvref_t<_From>;
using _RawTo = __uncvref_t<_To>;
static const bool value = _And<
_IsNotSame<_RawFrom, _RawTo>,
is_base_of<_RawFrom, _RawTo>,
_Not<__libcpp_is_constructible<_RawTo, _From>>
>::value;
};
template <class _To, class _From>
struct __is_invalid_lvalue_to_rvalue_cast : false_type {
static_assert(is_reference<_To>::value, "Wrong specialization");
};
template <class _ToRef, class _FromRef>
struct __is_invalid_lvalue_to_rvalue_cast<_ToRef&&, _FromRef&> {
using _RawFrom = __uncvref_t<_FromRef>;
using _RawTo = __uncvref_t<_ToRef>;
static const bool value = _And<
_Not<is_function<_RawTo>>,
_Or<
_IsSame<_RawFrom, _RawTo>,
is_base_of<_RawTo, _RawFrom>>
>::value;
};
struct __is_constructible_helper
{
template <class _To>
static void __eat(_To);
// This overload is needed to work around a Clang bug that disallows
// static_cast<T&&>(e) for non-reference-compatible types.
// Example: static_cast<int&&>(declval<double>());
// NOTE: The static_cast implementation below is required to support
// classes with explicit conversion operators.
template <class _To, class _From,
class = decltype(__eat<_To>(_VSTD::declval<_From>()))>
static true_type __test_cast(int);
template <class _To, class _From,
class = decltype(static_cast<_To>(_VSTD::declval<_From>()))>
static integral_constant<bool,
!__is_invalid_base_to_derived_cast<_To, _From>::value &&
!__is_invalid_lvalue_to_rvalue_cast<_To, _From>::value
> __test_cast(long);
template <class, class>
static false_type __test_cast(...);
template <class _Tp, class ..._Args,
class = decltype(_Tp(_VSTD::declval<_Args>()...))>
static true_type __test_nary(int);
template <class _Tp, class...>
static false_type __test_nary(...);
template <class _Tp, class _A0, class = decltype(::new _Tp(_VSTD::declval<_A0>()))>
static is_destructible<_Tp> __test_unary(int);
template <class, class>
static false_type __test_unary(...);
};
template <class _Tp, bool = is_void<_Tp>::value>
struct __is_default_constructible
: decltype(__is_constructible_helper::__test_nary<_Tp>(0))
{};
template <class _Tp>
struct __is_default_constructible<_Tp, true> : false_type {};
template <class _Tp>
struct __is_default_constructible<_Tp[], false> : false_type {};
template <class _Tp, size_t _Nx>
struct __is_default_constructible<_Tp[_Nx], false>
: __is_default_constructible<typename remove_all_extents<_Tp>::type> {};
template <class _Tp, class... _Args>
struct __libcpp_is_constructible
{
static_assert(sizeof...(_Args) > 1, "Wrong specialization");
typedef decltype(__is_constructible_helper::__test_nary<_Tp, _Args...>(0))
type;
};
template <class _Tp>
struct __libcpp_is_constructible<_Tp> : __is_default_constructible<_Tp> {};
template <class _Tp, class _A0>
struct __libcpp_is_constructible<_Tp, _A0>
: public decltype(__is_constructible_helper::__test_unary<_Tp, _A0>(0))
{};
template <class _Tp, class _A0>
struct __libcpp_is_constructible<_Tp&, _A0>
: public decltype(__is_constructible_helper::
__test_cast<_Tp&, _A0>(0))
{};
template <class _Tp, class _A0>
struct __libcpp_is_constructible<_Tp&&, _A0>
: public decltype(__is_constructible_helper::
__test_cast<_Tp&&, _A0>(0))
{};
#endif
#if __has_feature(is_constructible)
template <class _Tp, class ..._Args>
struct _LIBCPP_TEMPLATE_VIS is_constructible
: public integral_constant<bool, __is_constructible(_Tp, _Args...)>
{};
#else
template <class _Tp, class... _Args>
struct _LIBCPP_TEMPLATE_VIS is_constructible
: public __libcpp_is_constructible<_Tp, _Args...>::type {};
#endif
#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
template <class _Tp, class ..._Args>
_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_constructible_v
= is_constructible<_Tp, _Args...>::value;
#endif
// is_default_constructible
template <class _Tp>
struct _LIBCPP_TEMPLATE_VIS is_default_constructible
: public is_constructible<_Tp>
{};
#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
template <class _Tp>
_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_default_constructible_v
= is_default_constructible<_Tp>::value;
#endif
#ifndef _LIBCPP_CXX03_LANG
// First of all, we can't implement this check in C++03 mode because the {}
// default initialization syntax isn't valid.
// Second, we implement the trait in a funny manner with two defaulted template
// arguments to workaround Clang's PR43454.
template <class _Tp>
void __test_implicit_default_constructible(_Tp);
template <class _Tp, class = void, bool = is_default_constructible<_Tp>::value>
struct __is_implicitly_default_constructible
: false_type
{ };
template <class _Tp>
struct __is_implicitly_default_constructible<_Tp, decltype(__test_implicit_default_constructible<_Tp const&>({})), true>
: true_type
{ };
template <class _Tp>
struct __is_implicitly_default_constructible<_Tp, decltype(__test_implicit_default_constructible<_Tp const&>({})), false>
: false_type
{ };
#endif // !C++03
// is_copy_constructible
template <class _Tp>
struct _LIBCPP_TEMPLATE_VIS is_copy_constructible
: public is_constructible<_Tp,
typename add_lvalue_reference<typename add_const<_Tp>::type>::type> {};
#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
template <class _Tp>
_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_copy_constructible_v
= is_copy_constructible<_Tp>::value;
#endif
// is_move_constructible
template <class _Tp>
struct _LIBCPP_TEMPLATE_VIS is_move_constructible
: public is_constructible<_Tp, typename add_rvalue_reference<_Tp>::type>
{};
#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
template <class _Tp>
_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_move_constructible_v
= is_move_constructible<_Tp>::value;
#endif
// is_trivially_constructible
#if __has_feature(is_trivially_constructible) || _GNUC_VER >= 501
template <class _Tp, class... _Args>
struct _LIBCPP_TEMPLATE_VIS is_trivially_constructible
: integral_constant<bool, __is_trivially_constructible(_Tp, _Args...)>
{
};
#else // !__has_feature(is_trivially_constructible)
template <class _Tp, class... _Args>
struct _LIBCPP_TEMPLATE_VIS is_trivially_constructible
: false_type
{
};
template <class _Tp>
struct _LIBCPP_TEMPLATE_VIS is_trivially_constructible<_Tp>
#if __has_feature(has_trivial_constructor) || defined(_LIBCPP_COMPILER_GCC)
: integral_constant<bool, __has_trivial_constructor(_Tp)>
#else
: integral_constant<bool, is_scalar<_Tp>::value>
#endif
{
};
template <class _Tp>
struct _LIBCPP_TEMPLATE_VIS is_trivially_constructible<_Tp, _Tp&&>
: integral_constant<bool, is_scalar<_Tp>::value>
{
};
template <class _Tp>
struct _LIBCPP_TEMPLATE_VIS is_trivially_constructible<_Tp, const _Tp&>
: integral_constant<bool, is_scalar<_Tp>::value>
{
};
template <class _Tp>
struct _LIBCPP_TEMPLATE_VIS is_trivially_constructible<_Tp, _Tp&>
: integral_constant<bool, is_scalar<_Tp>::value>
{
};
#endif // !__has_feature(is_trivially_constructible)
#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
template <class _Tp, class... _Args>
_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_trivially_constructible_v
= is_trivially_constructible<_Tp, _Args...>::value;
#endif
// is_trivially_default_constructible
template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_trivially_default_constructible
: public is_trivially_constructible<_Tp>
{};
#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
template <class _Tp>
_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_trivially_default_constructible_v
= is_trivially_default_constructible<_Tp>::value;
#endif
// is_trivially_copy_constructible
template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_trivially_copy_constructible
: public is_trivially_constructible<_Tp, typename add_lvalue_reference<const _Tp>::type>
{};
#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
template <class _Tp>
_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_trivially_copy_constructible_v
= is_trivially_copy_constructible<_Tp>::value;
#endif
// is_trivially_move_constructible
template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_trivially_move_constructible
: public is_trivially_constructible<_Tp, typename add_rvalue_reference<_Tp>::type>
{};
#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
template <class _Tp>
_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_trivially_move_constructible_v
= is_trivially_move_constructible<_Tp>::value;
#endif
// is_trivially_assignable
#if __has_feature(is_trivially_assignable) || _GNUC_VER >= 501
template <class _Tp, class _Arg>
struct is_trivially_assignable
: integral_constant<bool, __is_trivially_assignable(_Tp, _Arg)>
{
};
#else // !__has_feature(is_trivially_assignable)
template <class _Tp, class _Arg>
struct is_trivially_assignable
: public false_type {};
template <class _Tp>
struct is_trivially_assignable<_Tp&, _Tp>
: integral_constant<bool, is_scalar<_Tp>::value> {};
template <class _Tp>
struct is_trivially_assignable<_Tp&, _Tp&>
: integral_constant<bool, is_scalar<_Tp>::value> {};
template <class _Tp>
struct is_trivially_assignable<_Tp&, const _Tp&>
: integral_constant<bool, is_scalar<_Tp>::value> {};
template <class _Tp>
struct is_trivially_assignable<_Tp&, _Tp&&>
: integral_constant<bool, is_scalar<_Tp>::value> {};
#endif // !__has_feature(is_trivially_assignable)
#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
template <class _Tp, class _Arg>
_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_trivially_assignable_v
= is_trivially_assignable<_Tp, _Arg>::value;
#endif
// is_trivially_copy_assignable
template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_trivially_copy_assignable
: public is_trivially_assignable<typename add_lvalue_reference<_Tp>::type,
typename add_lvalue_reference<typename add_const<_Tp>::type>::type> {};
#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
template <class _Tp>
_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_trivially_copy_assignable_v
= is_trivially_copy_assignable<_Tp>::value;
#endif
// is_trivially_move_assignable
template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_trivially_move_assignable
: public is_trivially_assignable<typename add_lvalue_reference<_Tp>::type,
typename add_rvalue_reference<_Tp>::type>
{};
#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
template <class _Tp>
_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_trivially_move_assignable_v
= is_trivially_move_assignable<_Tp>::value;
#endif
// is_trivially_destructible
#if __has_keyword(__is_trivially_destructible)
template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_trivially_destructible
: public integral_constant<bool, __is_trivially_destructible(_Tp)> {};
#elif __has_feature(has_trivial_destructor) || defined(_LIBCPP_COMPILER_GCC)
template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_trivially_destructible
: public integral_constant<bool, is_destructible<_Tp>::value && __has_trivial_destructor(_Tp)> {};
#else
template <class _Tp> struct __libcpp_trivial_destructor
: public integral_constant<bool, is_scalar<_Tp>::value ||
is_reference<_Tp>::value> {};
template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_trivially_destructible
: public __libcpp_trivial_destructor<typename remove_all_extents<_Tp>::type> {};
template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_trivially_destructible<_Tp[]>
: public false_type {};
#endif
#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
template <class _Tp>
_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_trivially_destructible_v
= is_trivially_destructible<_Tp>::value;
#endif
// is_nothrow_constructible
#if __has_keyword(__is_nothrow_constructible)
template <class _Tp, class... _Args>
struct _LIBCPP_TEMPLATE_VIS is_nothrow_constructible
: public integral_constant<bool, __is_nothrow_constructible(_Tp, _Args...)> {};
#else
template <bool, bool, class _Tp, class... _Args> struct __libcpp_is_nothrow_constructible;
template <class _Tp, class... _Args>
struct __libcpp_is_nothrow_constructible</*is constructible*/true, /*is reference*/false, _Tp, _Args...>
: public integral_constant<bool, noexcept(_Tp(declval<_Args>()...))>
{
};
template <class _Tp>
void __implicit_conversion_to(_Tp) noexcept { }
template <class _Tp, class _Arg>
struct __libcpp_is_nothrow_constructible</*is constructible*/true, /*is reference*/true, _Tp, _Arg>
: public integral_constant<bool, noexcept(__implicit_conversion_to<_Tp>(declval<_Arg>()))>
{
};
template <class _Tp, bool _IsReference, class... _Args>
struct __libcpp_is_nothrow_constructible</*is constructible*/false, _IsReference, _Tp, _Args...>
: public false_type
{
};
template <class _Tp, class... _Args>
struct _LIBCPP_TEMPLATE_VIS is_nothrow_constructible
: __libcpp_is_nothrow_constructible<is_constructible<_Tp, _Args...>::value, is_reference<_Tp>::value, _Tp, _Args...>
{
};
template <class _Tp, size_t _Ns>
struct _LIBCPP_TEMPLATE_VIS is_nothrow_constructible<_Tp[_Ns]>
: __libcpp_is_nothrow_constructible<is_constructible<_Tp>::value, is_reference<_Tp>::value, _Tp>
{
};
#endif // _LIBCPP_HAS_NO_NOEXCEPT
#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
template <class _Tp, class ..._Args>
_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_nothrow_constructible_v
= is_nothrow_constructible<_Tp, _Args...>::value;
#endif
// is_nothrow_default_constructible
template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_nothrow_default_constructible
: public is_nothrow_constructible<_Tp>
{};
#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
template <class _Tp>
_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_nothrow_default_constructible_v
= is_nothrow_default_constructible<_Tp>::value;
#endif
// is_nothrow_copy_constructible
template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_nothrow_copy_constructible
: public is_nothrow_constructible<_Tp,
typename add_lvalue_reference<typename add_const<_Tp>::type>::type> {};
#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
template <class _Tp>
_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_nothrow_copy_constructible_v
= is_nothrow_copy_constructible<_Tp>::value;
#endif
// is_nothrow_move_constructible
template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_nothrow_move_constructible
: public is_nothrow_constructible<_Tp, typename add_rvalue_reference<_Tp>::type>
{};
#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
template <class _Tp>
_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_nothrow_move_constructible_v
= is_nothrow_move_constructible<_Tp>::value;
#endif
// is_nothrow_assignable
#if __has_keyword(__is_nothrow_assignable)
template <class _Tp, class _Arg>
struct _LIBCPP_TEMPLATE_VIS is_nothrow_assignable
: public integral_constant<bool, __is_nothrow_assignable(_Tp, _Arg)> {};
#else
template <bool, class _Tp, class _Arg> struct __libcpp_is_nothrow_assignable;
template <class _Tp, class _Arg>
struct __libcpp_is_nothrow_assignable<false, _Tp, _Arg>
: public false_type
{
};
template <class _Tp, class _Arg>
struct __libcpp_is_nothrow_assignable<true, _Tp, _Arg>
: public integral_constant<bool, noexcept(_VSTD::declval<_Tp>() = _VSTD::declval<_Arg>()) >
{
};
template <class _Tp, class _Arg>
struct _LIBCPP_TEMPLATE_VIS is_nothrow_assignable
: public __libcpp_is_nothrow_assignable<is_assignable<_Tp, _Arg>::value, _Tp, _Arg>
{
};
#endif // _LIBCPP_HAS_NO_NOEXCEPT
#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
template <class _Tp, class _Arg>
_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_nothrow_assignable_v
= is_nothrow_assignable<_Tp, _Arg>::value;
#endif
// is_nothrow_copy_assignable
template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_nothrow_copy_assignable
: public is_nothrow_assignable<typename add_lvalue_reference<_Tp>::type,
typename add_lvalue_reference<typename add_const<_Tp>::type>::type> {};
#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
template <class _Tp>
_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_nothrow_copy_assignable_v
= is_nothrow_copy_assignable<_Tp>::value;
#endif
// is_nothrow_move_assignable
template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_nothrow_move_assignable
: public is_nothrow_assignable<typename add_lvalue_reference<_Tp>::type,
typename add_rvalue_reference<_Tp>::type>
{};
#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
template <class _Tp>
_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_nothrow_move_assignable_v
= is_nothrow_move_assignable<_Tp>::value;
#endif
// is_nothrow_destructible
#if !defined(_LIBCPP_CXX03_LANG)
template <bool, class _Tp> struct __libcpp_is_nothrow_destructible;
template <class _Tp>
struct __libcpp_is_nothrow_destructible<false, _Tp>
: public false_type
{
};
template <class _Tp>
struct __libcpp_is_nothrow_destructible<true, _Tp>
: public integral_constant<bool, noexcept(_VSTD::declval<_Tp>().~_Tp()) >
{
};
template <class _Tp>
struct _LIBCPP_TEMPLATE_VIS is_nothrow_destructible
: public __libcpp_is_nothrow_destructible<is_destructible<_Tp>::value, _Tp>
{
};
template <class _Tp, size_t _Ns>
struct _LIBCPP_TEMPLATE_VIS is_nothrow_destructible<_Tp[_Ns]>
: public is_nothrow_destructible<_Tp>
{
};
template <class _Tp>
struct _LIBCPP_TEMPLATE_VIS is_nothrow_destructible<_Tp&>
: public true_type
{
};
template <class _Tp>
struct _LIBCPP_TEMPLATE_VIS is_nothrow_destructible<_Tp&&>
: public true_type
{
};
#else
template <class _Tp> struct __libcpp_nothrow_destructor
: public integral_constant<bool, is_scalar<_Tp>::value ||
is_reference<_Tp>::value> {};
template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_nothrow_destructible
: public __libcpp_nothrow_destructor<typename remove_all_extents<_Tp>::type> {};
template <class _Tp>
struct _LIBCPP_TEMPLATE_VIS is_nothrow_destructible<_Tp[]>
: public false_type {};
#endif
#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
template <class _Tp>
_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_nothrow_destructible_v
= is_nothrow_destructible<_Tp>::value;
#endif
// is_pod
#if __has_feature(is_pod) || defined(_LIBCPP_COMPILER_GCC)
template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_pod
: public integral_constant<bool, __is_pod(_Tp)> {};
#else
template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_pod
: public integral_constant<bool, is_trivially_default_constructible<_Tp>::value &&
is_trivially_copy_constructible<_Tp>::value &&
is_trivially_copy_assignable<_Tp>::value &&
is_trivially_destructible<_Tp>::value> {};
#endif
#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
template <class _Tp>
_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_pod_v
= is_pod<_Tp>::value;
#endif
// is_literal_type;
template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_literal_type
: public integral_constant<bool, __is_literal_type(_Tp)>
{};
#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
template <class _Tp>
_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_literal_type_v
= is_literal_type<_Tp>::value;
#endif
// is_standard_layout;
template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_standard_layout
#if __has_feature(is_standard_layout) || defined(_LIBCPP_COMPILER_GCC)
: public integral_constant<bool, __is_standard_layout(_Tp)>
#else
: integral_constant<bool, is_scalar<typename remove_all_extents<_Tp>::type>::value>
#endif
{};
#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
template <class _Tp>
_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_standard_layout_v
= is_standard_layout<_Tp>::value;
#endif
// is_trivially_copyable;
template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_trivially_copyable
#if __has_feature(is_trivially_copyable)
: public integral_constant<bool, __is_trivially_copyable(_Tp)>
#elif _GNUC_VER >= 501
: public integral_constant<bool, !is_volatile<_Tp>::value && __is_trivially_copyable(_Tp)>
#else
: integral_constant<bool, is_scalar<typename remove_all_extents<_Tp>::type>::value>
#endif
{};
#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
template <class _Tp>
_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_trivially_copyable_v
= is_trivially_copyable<_Tp>::value;
#endif
// is_trivial;
template <class _Tp> struct _LIBCPP_TEMPLATE_VIS is_trivial
#if __has_feature(is_trivial) || defined(_LIBCPP_COMPILER_GCC)
: public integral_constant<bool, __is_trivial(_Tp)>
#else
: integral_constant<bool, is_trivially_copyable<_Tp>::value &&
is_trivially_default_constructible<_Tp>::value>
#endif
{};
#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES)
template <class _Tp>
_LIBCPP_INLINE_VAR _LIBCPP_CONSTEXPR bool is_trivial_v
= is_trivial<_Tp>::value;
#endif
template <class _Tp> struct __is_reference_wrapper_impl : public false_type {};
template <class _Tp> struct __is_reference_wrapper_impl<reference_wrapper<_Tp> > : public true_type {};
template <class _Tp> struct __is_reference_wrapper
: public __is_reference_wrapper_impl<typename remove_cv<_Tp>::type> {};
#ifndef _LIBCPP_CXX03_LANG
template <class _Fp, class _A0,
class _DecayFp = typename decay<_Fp>::type,
class _DecayA0 = typename decay<_A0>::type,
class _ClassT = typename __member_pointer_class_type<_DecayFp>::type>
using __enable_if_bullet1 = typename enable_if
<
is_member_function_pointer<_DecayFp>::value
&& is_base_of<_ClassT, _DecayA0>::value
>::type;
template <class _Fp, class _A0,
class _DecayFp = typename decay<_Fp>::type,
class _DecayA0 = typename decay<_A0>::type>
using __enable_if_bullet2 = typename enable_if
<
is_member_function_pointer<_DecayFp>::value
&& __is_reference_wrapper<_DecayA0>::value
>::type;
template <class _Fp, class _A0,
class _DecayFp = typename decay<_Fp>::type,
class _DecayA0 = typename decay<_A0>::type,
class _ClassT = typename __member_pointer_class_type<_DecayFp>::type>
using __enable_if_bullet3 = typename enable_if
<
is_member_function_pointer<_DecayFp>::value
&& !is_base_of<_ClassT, _DecayA0>::value
&& !__is_reference_wrapper<_DecayA0>::value
>::type;
template <class _Fp, class _A0,
class _DecayFp = typename decay<_Fp>::type,
class _DecayA0 = typename decay<_A0>::type,
class _ClassT = typename __member_pointer_class_type<_DecayFp>::type>
using __enable_if_bullet4 = typename enable_if
<
is_member_object_pointer<_DecayFp>::value
&& is_base_of<_ClassT, _DecayA0>::value
>::type;
template <class _Fp, class _A0,
class _DecayFp = typename decay<_Fp>::type,
class _DecayA0 = typename decay<_A0>::type>
using __enable_if_bullet5 = typename enable_if
<
is_member_object_pointer<_DecayFp>::value
&& __is_reference_wrapper<_DecayA0>::value
>::type;
template <class _Fp, class _A0,
class _DecayFp = typename decay<_Fp>::type,
class _DecayA0 = typename decay<_A0>::type,
class _ClassT = typename __member_pointer_class_type<_DecayFp>::type>
using __enable_if_bullet6 = typename enable_if
<
is_member_object_pointer<_DecayFp>::value
&& !is_base_of<_ClassT, _DecayA0>::value
&& !__is_reference_wrapper<_DecayA0>::value
>::type;
// __invoke forward declarations
// fall back - none of the bullets
#define _LIBCPP_INVOKE_RETURN(...) \
noexcept(noexcept(__VA_ARGS__)) -> decltype(__VA_ARGS__) \
{ return __VA_ARGS__; }
template <class ..._Args>
auto __invoke(__any, _Args&& ...__args) -> __nat;
template <class ..._Args>
auto __invoke_constexpr(__any, _Args&& ...__args) -> __nat;
// bullets 1, 2 and 3
template <class _Fp, class _A0, class ..._Args,
class = __enable_if_bullet1<_Fp, _A0>>
inline _LIBCPP_INLINE_VISIBILITY
auto
__invoke(_Fp&& __f, _A0&& __a0, _Args&& ...__args)
_LIBCPP_INVOKE_RETURN((_VSTD::forward<_A0>(__a0).*__f)(_VSTD::forward<_Args>(__args)...))
template <class _Fp, class _A0, class ..._Args,
class = __enable_if_bullet1<_Fp, _A0>>
inline _LIBCPP_INLINE_VISIBILITY
_LIBCPP_CONSTEXPR auto
__invoke_constexpr(_Fp&& __f, _A0&& __a0, _Args&& ...__args)
_LIBCPP_INVOKE_RETURN((_VSTD::forward<_A0>(__a0).*__f)(_VSTD::forward<_Args>(__args)...))
template <class _Fp, class _A0, class ..._Args,
class = __enable_if_bullet2<_Fp, _A0>>
inline _LIBCPP_INLINE_VISIBILITY
auto
__invoke(_Fp&& __f, _A0&& __a0, _Args&& ...__args)
_LIBCPP_INVOKE_RETURN((__a0.get().*__f)(_VSTD::forward<_Args>(__args)...))
template <class _Fp, class _A0, class ..._Args,
class = __enable_if_bullet2<_Fp, _A0>>
inline _LIBCPP_INLINE_VISIBILITY
_LIBCPP_CONSTEXPR auto
__invoke_constexpr(_Fp&& __f, _A0&& __a0, _Args&& ...__args)
_LIBCPP_INVOKE_RETURN((__a0.get().*__f)(_VSTD::forward<_Args>(__args)...))
template <class _Fp, class _A0, class ..._Args,
class = __enable_if_bullet3<_Fp, _A0>>
inline _LIBCPP_INLINE_VISIBILITY
auto
__invoke(_Fp&& __f, _A0&& __a0, _Args&& ...__args)
_LIBCPP_INVOKE_RETURN(((*_VSTD::forward<_A0>(__a0)).*__f)(_VSTD::forward<_Args>(__args)...))
template <class _Fp, class _A0, class ..._Args,
class = __enable_if_bullet3<_Fp, _A0>>
inline _LIBCPP_INLINE_VISIBILITY
_LIBCPP_CONSTEXPR auto
__invoke_constexpr(_Fp&& __f, _A0&& __a0, _Args&& ...__args)
_LIBCPP_INVOKE_RETURN(((*_VSTD::forward<_A0>(__a0)).*__f)(_VSTD::forward<_Args>(__args)...))
// bullets 4, 5 and 6
template <class _Fp, class _A0,
class = __enable_if_bullet4<_Fp, _A0>>
inline _LIBCPP_INLINE_VISIBILITY
auto
__invoke(_Fp&& __f, _A0&& __a0)
_LIBCPP_INVOKE_RETURN(_VSTD::forward<_A0>(__a0).*__f)
template <class _Fp, class _A0,
class = __enable_if_bullet4<_Fp, _A0>>
inline _LIBCPP_INLINE_VISIBILITY
_LIBCPP_CONSTEXPR auto
__invoke_constexpr(_Fp&& __f, _A0&& __a0)
_LIBCPP_INVOKE_RETURN(_VSTD::forward<_A0>(__a0).*__f)
template <class _Fp, class _A0,
class = __enable_if_bullet5<_Fp, _A0>>
inline _LIBCPP_INLINE_VISIBILITY
auto
__invoke(_Fp&& __f, _A0&& __a0)
_LIBCPP_INVOKE_RETURN(__a0.get().*__f)
template <class _Fp, class _A0,
class = __enable_if_bullet5<_Fp, _A0>>
inline _LIBCPP_INLINE_VISIBILITY
_LIBCPP_CONSTEXPR auto
__invoke_constexpr(_Fp&& __f, _A0&& __a0)
_LIBCPP_INVOKE_RETURN(__a0.get().*__f)
template <class _Fp, class _A0,
class = __enable_if_bullet6<_Fp, _A0>>
inline _LIBCPP_INLINE_VISIBILITY
auto
__invoke(_Fp&& __f, _A0&& __a0)
_LIBCPP_INVOKE_RETURN((*_VSTD::forward<_A0>(__a0)).*__f)
template <class _Fp, class _A0,
class = __enable_if_bullet6<_Fp, _A0>>
inline _LIBCPP_INLINE_VISIBILITY
_LIBCPP_CONSTEXPR auto
__invoke_constexpr(_Fp&& __f, _A0&& __a0)
_LIBCPP_INVOKE_RETURN((*_VSTD::forward<_A0>(__a0)).*__f)
// bullet 7
template <class _Fp, class ..._Args>
inline _LIBCPP_INLINE_VISIBILITY
auto
__invoke(_Fp&& __f, _Args&& ...__args)
_LIBCPP_INVOKE_RETURN(_VSTD::forward<_Fp>(__f)(_VSTD::forward<_Args>(__args)...))
template <class _Fp, class ..._Args>
inline _LIBCPP_INLINE_VISIBILITY
_LIBCPP_CONSTEXPR auto
__invoke_constexpr(_Fp&& __f, _Args&& ...__args)
_LIBCPP_INVOKE_RETURN(_VSTD::forward<_Fp>(__f)(_VSTD::forward<_Args>(__args)...))
#undef _LIBCPP_INVOKE_RETURN
// __invokable
template <class _Ret, class _Fp, class ..._Args>
struct __invokable_r
{
template <class _XFp, class ..._XArgs>
static auto __try_call(int) -> decltype(
_VSTD::__invoke(_VSTD::declval<_XFp>(), _VSTD::declval<_XArgs>()...));
template <class _XFp, class ..._XArgs>
static __nat __try_call(...);
// FIXME: Check that _Ret, _Fp, and _Args... are all complete types, cv void,
// or incomplete array types as required by the standard.
using _Result = decltype(__try_call<_Fp, _Args...>(0));
using type =
typename conditional<
_IsNotSame<_Result, __nat>::value,
typename conditional<
is_void<_Ret>::value,
true_type,
is_convertible<_Result, _Ret>
>::type,
false_type
>::type;
static const bool value = type::value;
};
template <class _Fp, class ..._Args>
using __invokable = __invokable_r<void, _Fp, _Args...>;
template <bool _IsInvokable, bool _IsCVVoid, class _Ret, class _Fp, class ..._Args>
struct __nothrow_invokable_r_imp {
static const bool value = false;
};
template <class _Ret, class _Fp, class ..._Args>
struct __nothrow_invokable_r_imp<true, false, _Ret, _Fp, _Args...>
{
typedef __nothrow_invokable_r_imp _ThisT;
template <class _Tp>
static void __test_noexcept(_Tp) noexcept;
static const bool value = noexcept(_ThisT::__test_noexcept<_Ret>(
_VSTD::__invoke(_VSTD::declval<_Fp>(), _VSTD::declval<_Args>()...)));
};
template <class _Ret, class _Fp, class ..._Args>
struct __nothrow_invokable_r_imp<true, true, _Ret, _Fp, _Args...>
{
static const bool value = noexcept(
_VSTD::__invoke(_VSTD::declval<_Fp>(), _VSTD::declval<_Args>()...));
};
template <class _Ret, class _Fp, class ..._Args>
using __nothrow_invokable_r =
__nothrow_invokable_r_imp<
__invokable_r<_Ret, _Fp, _Args...>::value,
is_void<_Ret>::value,
_Ret, _Fp, _Args...
>;
template <class _Fp, class ..._Args>
using __nothrow_invokable =
__nothrow_invokable_r_imp<
__invokable<_Fp, _Args...>::value,
true, void, _Fp, _Args...
>;
template <class _Fp, class ..._Args>
struct __invoke_of
: public enable_if<
__invokable<_Fp, _Args...>::value,
typename __invokable_r<void, _Fp, _Args...>::_Result>
{
};
// result_of
template <class _Fp, class ..._Args>
class _LIBCPP_TEMPLATE_VIS result_of<_Fp(_Args...)>
: public __invoke_of<_Fp, _Args...>
{
};
#if _LIBCPP_STD_VER > 11
template <class _Tp> using result_of_t = typename result_of<_Tp>::type;
#endif
#if _LIBCPP_STD_VER > 14
// invoke_result
template <class _Fn, class... _Args>
struct _LIBCPP_TEMPLATE_VIS invoke_result
: __invoke_of<_Fn, _Args...>
{
};
template <class _Fn, class... _Args>
using invoke_result_t = typename invoke_result<_Fn, _Args...>::type;
// is_invocable
template <class _Fn, class ..._Args>
struct _LIBCPP_TEMPLATE_VIS is_invocable
: integral_constant<bool, __invokable<_Fn, _Args...>::value> {};
template <class _Ret, class _Fn, class ..._Args>
struct _LIBCPP_TEMPLATE_VIS is_invocable_r
: integral_constant<bool, __invokable_r<_Ret, _Fn, _Args...>::value> {};
template <class _Fn, class ..._Args>
_LIBCPP_INLINE_VAR constexpr bool is_invocable_v
= is_invocable<_Fn, _Args...>::value;
template <class _Ret, class _Fn, class ..._Args>
_LIBCPP_INLINE_VAR constexpr bool is_invocable_r_v
= is_invocable_r<_Ret, _Fn, _Args...>::value;
// is_nothrow_invocable
template <class _Fn, class ..._Args>
struct _LIBCPP_TEMPLATE_VIS is_nothrow_invocable
: integral_constant<bool, __nothrow_invokable<_Fn, _Args...>::value> {};
template <class _Ret, class _Fn, class ..._Args>
struct _LIBCPP_TEMPLATE_VIS is_nothrow_invocable_r
: integral_constant<bool, __nothrow_invokable_r<_Ret, _Fn, _Args...>::value> {};
template <class _Fn, class ..._Args>
_LIBCPP_INLINE_VAR constexpr bool is_nothrow_invocable_v
= is_nothrow_invocable<_Fn, _Args...>::value;
template <class _Ret, class _Fn, class ..._Args>
_LIBCPP_INLINE_VAR constexpr bool is_nothrow_invocable_r_v
= is_nothrow_invocable_r<_Ret, _Fn, _Args...>::value;
#endif // _LIBCPP_STD_VER > 14
#endif // !defined(_LIBCPP_CXX03_LANG)
template <class _Tp> struct __is_swappable;
template <class _Tp> struct __is_nothrow_swappable;
// swap, swap_ranges
template <class _ForwardIterator1, class _ForwardIterator2>
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
_ForwardIterator2
swap_ranges(_ForwardIterator1 __first1, _ForwardIterator1 __last1, _ForwardIterator2 __first2);
template <class _Tp>
inline _LIBCPP_INLINE_VISIBILITY
#ifndef _LIBCPP_CXX03_LANG
typename enable_if
<
is_move_constructible<_Tp>::value &&
is_move_assignable<_Tp>::value
>::type
#else
void
#endif
_LIBCPP_CONSTEXPR_AFTER_CXX17
swap(_Tp& __x, _Tp& __y) _NOEXCEPT_(is_nothrow_move_constructible<_Tp>::value &&
is_nothrow_move_assignable<_Tp>::value)
{
_Tp __t(_VSTD::move(__x));
__x = _VSTD::move(__y);
__y = _VSTD::move(__t);
}
template<class _Tp, size_t _Np>
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
typename enable_if<
__is_swappable<_Tp>::value
>::type
swap(_Tp (&__a)[_Np], _Tp (&__b)[_Np]) _NOEXCEPT_(__is_nothrow_swappable<_Tp>::value)
{
_VSTD::swap_ranges(__a, __a + _Np, __b);
}
template <class _ForwardIterator1, class _ForwardIterator2>
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
_ForwardIterator2
swap_ranges(_ForwardIterator1 __first1, _ForwardIterator1 __last1, _ForwardIterator2 __first2)
{
for(; __first1 != __last1; ++__first1, (void) ++__first2)
swap(*__first1, *__first2);
return __first2;
}
// iter_swap
template <class _ForwardIterator1, class _ForwardIterator2>
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
void
iter_swap(_ForwardIterator1 __a, _ForwardIterator2 __b)
// _NOEXCEPT_(_NOEXCEPT_(swap(*__a, *__b)))
_NOEXCEPT_(_NOEXCEPT_(swap(*_VSTD::declval<_ForwardIterator1>(),
*_VSTD::declval<_ForwardIterator2>())))
{
swap(*__a, *__b);
}
// __swappable
namespace __detail
{
// ALL generic swap overloads MUST already have a declaration available at this point.
template <class _Tp, class _Up = _Tp,
bool _NotVoid = !is_void<_Tp>::value && !is_void<_Up>::value>
struct __swappable_with
{
template <class _LHS, class _RHS>
static decltype(swap(_VSTD::declval<_LHS>(), _VSTD::declval<_RHS>()))
__test_swap(int);
template <class, class>
static __nat __test_swap(long);
// Extra parens are needed for the C++03 definition of decltype.
typedef decltype((__test_swap<_Tp, _Up>(0))) __swap1;
typedef decltype((__test_swap<_Up, _Tp>(0))) __swap2;
static const bool value = _IsNotSame<__swap1, __nat>::value
&& _IsNotSame<__swap2, __nat>::value;
};
template <class _Tp, class _Up>
struct __swappable_with<_Tp, _Up, false> : false_type {};
template <class _Tp, class _Up = _Tp, bool _Swappable = __swappable_with<_Tp, _Up>::value>
struct __nothrow_swappable_with {
static const bool value =
#ifndef _LIBCPP_HAS_NO_NOEXCEPT
noexcept(swap(_VSTD::declval<_Tp>(), _VSTD::declval<_Up>()))
&& noexcept(swap(_VSTD::declval<_Up>(), _VSTD::declval<_Tp>()));
#else
false;
#endif
};
template <class _Tp, class _Up>
struct __nothrow_swappable_with<_Tp, _Up, false> : false_type {};
} // __detail
template <class _Tp>
struct __is_swappable
: public integral_constant<bool, __detail::__swappable_with<_Tp&>::value>
{
};
template <class _Tp>
struct __is_nothrow_swappable
: public integral_constant<bool, __detail::__nothrow_swappable_with<_Tp&>::value>
{
};
#if _LIBCPP_STD_VER > 14
template <class _Tp, class _Up>
struct _LIBCPP_TEMPLATE_VIS is_swappable_with
: public integral_constant<bool, __detail::__swappable_with<_Tp, _Up>::value>
{
};
template <class _Tp>
struct _LIBCPP_TEMPLATE_VIS is_swappable
: public conditional<
__is_referenceable<_Tp>::value,
is_swappable_with<
typename add_lvalue_reference<_Tp>::type,
typename add_lvalue_reference<_Tp>::type>,
false_type
>::type
{
};
template <class _Tp, class _Up>
struct _LIBCPP_TEMPLATE_VIS is_nothrow_swappable_with
: public integral_constant<bool, __detail::__nothrow_swappable_with<_Tp, _Up>::value>
{
};
template <class _Tp>
struct _LIBCPP_TEMPLATE_VIS is_nothrow_swappable
: public conditional<
__is_referenceable<_Tp>::value,
is_nothrow_swappable_with<
typename add_lvalue_reference<_Tp>::type,
typename add_lvalue_reference<_Tp>::type>,
false_type
>::type
{
};
template <class _Tp, class _Up>
_LIBCPP_INLINE_VAR constexpr bool is_swappable_with_v
= is_swappable_with<_Tp, _Up>::value;
template <class _Tp>
_LIBCPP_INLINE_VAR constexpr bool is_swappable_v
= is_swappable<_Tp>::value;
template <class _Tp, class _Up>
_LIBCPP_INLINE_VAR constexpr bool is_nothrow_swappable_with_v
= is_nothrow_swappable_with<_Tp, _Up>::value;
template <class _Tp>
_LIBCPP_INLINE_VAR constexpr bool is_nothrow_swappable_v
= is_nothrow_swappable<_Tp>::value;
#endif // _LIBCPP_STD_VER > 14
template <class _Tp, bool = is_enum<_Tp>::value> struct __underlying_type_impl;
template <class _Tp>
struct __underlying_type_impl<_Tp, false> {};
template <class _Tp>
struct __underlying_type_impl<_Tp, true>
{
typedef __underlying_type(_Tp) type;
};
template <class _Tp>
struct underlying_type : __underlying_type_impl<_Tp, is_enum<_Tp>::value> {};
#if _LIBCPP_STD_VER > 11
template <class _Tp> using underlying_type_t = typename underlying_type<_Tp>::type;
#endif
template <class _Tp, bool = is_enum<_Tp>::value>
struct __sfinae_underlying_type
{
typedef typename underlying_type<_Tp>::type type;
typedef decltype(((type)1) + 0) __promoted_type;
};
template <class _Tp>
struct __sfinae_underlying_type<_Tp, false> {};
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
int __convert_to_integral(int __val) { return __val; }
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
unsigned __convert_to_integral(unsigned __val) { return __val; }
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
long __convert_to_integral(long __val) { return __val; }
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
unsigned long __convert_to_integral(unsigned long __val) { return __val; }
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
long long __convert_to_integral(long long __val) { return __val; }
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
unsigned long long __convert_to_integral(unsigned long long __val) {return __val; }
template<typename _Fp>
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
typename enable_if<is_floating_point<_Fp>::value, long long>::type
__convert_to_integral(_Fp __val) { return __val; }
#ifndef _LIBCPP_HAS_NO_INT128
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
__int128_t __convert_to_integral(__int128_t __val) { return __val; }
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
__uint128_t __convert_to_integral(__uint128_t __val) { return __val; }
#endif
template <class _Tp>
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
typename __sfinae_underlying_type<_Tp>::__promoted_type
__convert_to_integral(_Tp __val) { return __val; }
#ifndef _LIBCPP_CXX03_LANG
template <class _Tp>
struct __has_operator_addressof_member_imp
{
template <class _Up>
static auto __test(int)
-> typename __select_2nd<decltype(_VSTD::declval<_Up>().operator&()), true_type>::type;
template <class>
static auto __test(long) -> false_type;
static const bool value = decltype(__test<_Tp>(0))::value;
};
template <class _Tp>
struct __has_operator_addressof_free_imp
{
template <class _Up>
static auto __test(int)
-> typename __select_2nd<decltype(operator&(_VSTD::declval<_Up>())), true_type>::type;
template <class>
static auto __test(long) -> false_type;
static const bool value = decltype(__test<_Tp>(0))::value;
};
template <class _Tp>
struct __has_operator_addressof
: public integral_constant<bool, __has_operator_addressof_member_imp<_Tp>::value
|| __has_operator_addressof_free_imp<_Tp>::value>
{};
#endif // _LIBCPP_CXX03_LANG
#if _LIBCPP_STD_VER > 14
template <class...> using void_t = void;
template <class... _Args>
struct conjunction : _And<_Args...> {};
template<class... _Args>
_LIBCPP_INLINE_VAR constexpr bool conjunction_v
= conjunction<_Args...>::value;
template <class... _Args>
struct disjunction : _Or<_Args...> {};
template<class... _Args>
_LIBCPP_INLINE_VAR constexpr bool disjunction_v
= disjunction<_Args...>::value;
template <class _Tp>
struct negation : _Not<_Tp> {};
template<class _Tp>
_LIBCPP_INLINE_VAR constexpr bool negation_v
= negation<_Tp>::value;
#endif // _LIBCPP_STD_VER > 14
// These traits are used in __tree and __hash_table
#ifndef _LIBCPP_CXX03_LANG
struct __extract_key_fail_tag {};
struct __extract_key_self_tag {};
struct __extract_key_first_tag {};
template <class _ValTy, class _Key,
class _RawValTy = typename __unconstref<_ValTy>::type>
struct __can_extract_key
: conditional<_IsSame<_RawValTy, _Key>::value, __extract_key_self_tag,
__extract_key_fail_tag>::type {};
template <class _Pair, class _Key, class _First, class _Second>
struct __can_extract_key<_Pair, _Key, pair<_First, _Second>>
: conditional<_IsSame<typename remove_const<_First>::type, _Key>::value,
__extract_key_first_tag, __extract_key_fail_tag>::type {};
// __can_extract_map_key uses true_type/false_type instead of the tags.
// It returns true if _Key != _ContainerValueTy (the container is a map not a set)
// and _ValTy == _Key.
template <class _ValTy, class _Key, class _ContainerValueTy,
class _RawValTy = typename __unconstref<_ValTy>::type>
struct __can_extract_map_key
: integral_constant<bool, _IsSame<_RawValTy, _Key>::value> {};
// This specialization returns __extract_key_fail_tag for non-map containers
// because _Key == _ContainerValueTy
template <class _ValTy, class _Key, class _RawValTy>
struct __can_extract_map_key<_ValTy, _Key, _Key, _RawValTy>
: false_type {};
#endif
#ifndef _LIBCPP_HAS_NO_BUILTIN_IS_CONSTANT_EVALUATED
#if _LIBCPP_STD_VER > 17
_LIBCPP_INLINE_VISIBILITY
inline constexpr bool is_constant_evaluated() noexcept {
return __builtin_is_constant_evaluated();
}
#endif
inline _LIBCPP_CONSTEXPR
bool __libcpp_is_constant_evaluated() _NOEXCEPT { return __builtin_is_constant_evaluated(); }
#else
inline _LIBCPP_CONSTEXPR
bool __libcpp_is_constant_evaluated() _NOEXCEPT { return false; }
#endif
template <class _CharT>
using _IsCharLikeType = _And<is_standard_layout<_CharT>, is_trivial<_CharT> >;
_LIBCPP_END_NAMESPACE_STD
#if _LIBCPP_STD_VER > 14
// std::byte
namespace std // purposefully not versioned
{
template <class _Integer>
constexpr typename enable_if<is_integral_v<_Integer>, byte>::type &
operator<<=(byte& __lhs, _Integer __shift) noexcept
{ return __lhs = __lhs << __shift; }
template <class _Integer>
constexpr typename enable_if<is_integral_v<_Integer>, byte>::type
operator<< (byte __lhs, _Integer __shift) noexcept
{ return static_cast<byte>(static_cast<unsigned char>(static_cast<unsigned int>(__lhs) << __shift)); }
template <class _Integer>
constexpr typename enable_if<is_integral_v<_Integer>, byte>::type &
operator>>=(byte& __lhs, _Integer __shift) noexcept
{ return __lhs = __lhs >> __shift; }
template <class _Integer>
constexpr typename enable_if<is_integral_v<_Integer>, byte>::type
operator>> (byte __lhs, _Integer __shift) noexcept
{ return static_cast<byte>(static_cast<unsigned char>(static_cast<unsigned int>(__lhs) >> __shift)); }
template <class _Integer>
constexpr typename enable_if<is_integral_v<_Integer>, _Integer>::type
to_integer(byte __b) noexcept { return static_cast<_Integer>(__b); }
}
#endif
#endif // _LIBCPP_TYPE_TRAITS
| 142,803 | 4,062 | jart/cosmopolitan | false |
cosmopolitan/third_party/libcxx/LICENSE.TXT | ==============================================================================
The LLVM Project is under the Apache License v2.0 with LLVM Exceptions:
==============================================================================
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
APPENDIX: How to apply the Apache License to your work.
To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "[]"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.
Copyright [yyyy] [name of copyright owner]
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.
---- LLVM Exceptions to the Apache 2.0 License ----
As an exception, if, as a result of your compiling your source code, portions
of this Software are embedded into an Object form of such source code, you
may redistribute such embedded portions in such Object form without complying
with the conditions of Sections 4(a), 4(b) and 4(d) of the License.
In addition, if you combine or link compiled forms of this Software with
software that is licensed under the GPLv2 ("Combined Software") and if a
court of competent jurisdiction determines that the patent provision (Section
3), the indemnity provision (Section 9) or other Section of the License
conflicts with the conditions of the GPLv2, you may retroactively and
prospectively choose to deem waived or otherwise exclude such Section(s) of
the License, but only in their entirety and only with respect to the Combined
Software.
==============================================================================
Software from third parties included in the LLVM Project:
==============================================================================
The LLVM Project contains third party software which is under different license
terms. All such code will be identified clearly using at least one of two
mechanisms:
1) It will be in a separate directory tree with its own `LICENSE.txt` or
`LICENSE` file at the top containing the specific license and restrictions
which apply to that software, or
2) It will contain specific license and restriction terms at the top of every
file.
==============================================================================
Legacy LLVM License (https://llvm.org/docs/DeveloperPolicy.html#legacy):
==============================================================================
The libc++ library is dual licensed under both the University of Illinois
"BSD-Like" license and the MIT license. As a user of this code you may choose
to use it under either license. As a contributor, you agree to allow your code
to be used under both.
Full text of the relevant licenses is included below.
==============================================================================
University of Illinois/NCSA
Open Source License
Copyright (c) 2009-2019 by the contributors listed in CREDITS.TXT
All rights reserved.
Developed by:
LLVM Team
University of Illinois at Urbana-Champaign
http://llvm.org
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal with
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:
* Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimers.
* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimers in the
documentation and/or other materials provided with the distribution.
* Neither the names of the LLVM Team, University of Illinois at
Urbana-Champaign, nor the names of its contributors may be used to
endorse or promote products derived from this Software without specific
prior written permission.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS WITH THE
SOFTWARE.
==============================================================================
Copyright (c) 2009-2014 by the contributors listed in CREDITS.TXT
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
| 16,703 | 312 | jart/cosmopolitan | false |
cosmopolitan/third_party/libcxx/utility | // -*- C++ -*-
//===-------------------------- utility -----------------------------------===//
//
// 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_UTILITY
#define _LIBCPP_UTILITY
#include "third_party/libcxx/__config"
#include "third_party/libcxx/__tuple"
#include "third_party/libcxx/type_traits"
#include "third_party/libcxx/initializer_list"
#include "third_party/libcxx/cstddef"
#include "third_party/libcxx/cstring"
#include "third_party/libcxx/cstdint"
#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
/*
utility synopsis
#include "third_party/libcxx/initializer_list"
namespace std
{
template <class T>
void
swap(T& a, T& b);
namespace rel_ops
{
template<class T> bool operator!=(const T&, const T&);
template<class T> bool operator> (const T&, const T&);
template<class T> bool operator<=(const T&, const T&);
template<class T> bool operator>=(const T&, const T&);
}
template<class T>
void
swap(T& a, T& b) noexcept(is_nothrow_move_constructible<T>::value &&
is_nothrow_move_assignable<T>::value);
template <class T, size_t N>
void
swap(T (&a)[N], T (&b)[N]) noexcept(noexcept(swap(*a, *b)));
template <class T> T&& forward(typename remove_reference<T>::type& t) noexcept; // constexpr in C++14
template <class T> T&& forward(typename remove_reference<T>::type&& t) noexcept; // constexpr in C++14
template <class T> typename remove_reference<T>::type&& move(T&&) noexcept; // constexpr in C++14
template <class T>
typename conditional
<
!is_nothrow_move_constructible<T>::value && is_copy_constructible<T>::value,
const T&,
T&&
>::type
move_if_noexcept(T& x) noexcept; // constexpr in C++14
template <class T> constexpr add_const_t<T>& as_const(T& t) noexcept; // C++17
template <class T> void as_const(const T&&) = delete; // C++17
template <class T> typename add_rvalue_reference<T>::type declval() noexcept;
template <class T1, class T2>
struct pair
{
typedef T1 first_type;
typedef T2 second_type;
T1 first;
T2 second;
pair(const pair&) = default;
pair(pair&&) = default;
explicit(see-below) constexpr pair();
explicit(see-below) pair(const T1& x, const T2& y); // constexpr in C++14
template <class U, class V> explicit(see-below) pair(U&& x, V&& y); // constexpr in C++14
template <class U, class V> explicit(see-below) pair(const pair<U, V>& p); // constexpr in C++14
template <class U, class V> explicit(see-below) pair(pair<U, V>&& p); // constexpr in C++14
template <class... Args1, class... Args2>
pair(piecewise_construct_t, tuple<Args1...> first_args,
tuple<Args2...> second_args);
template <class U, class V> pair& operator=(const pair<U, V>& p);
pair& operator=(pair&& p) noexcept(is_nothrow_move_assignable<T1>::value &&
is_nothrow_move_assignable<T2>::value);
template <class U, class V> pair& operator=(pair<U, V>&& p);
void swap(pair& p) noexcept(is_nothrow_swappable_v<T1> &&
is_nothrow_swappable_v<T2>);
};
template <class T1, class T2> bool operator==(const pair<T1,T2>&, const pair<T1,T2>&); // constexpr in C++14
template <class T1, class T2> bool operator!=(const pair<T1,T2>&, const pair<T1,T2>&); // constexpr in C++14
template <class T1, class T2> bool operator< (const pair<T1,T2>&, const pair<T1,T2>&); // constexpr in C++14
template <class T1, class T2> bool operator> (const pair<T1,T2>&, const pair<T1,T2>&); // constexpr in C++14
template <class T1, class T2> bool operator>=(const pair<T1,T2>&, const pair<T1,T2>&); // constexpr in C++14
template <class T1, class T2> bool operator<=(const pair<T1,T2>&, const pair<T1,T2>&); // constexpr in C++14
template <class T1, class T2> pair<V1, V2> make_pair(T1&&, T2&&); // constexpr in C++14
template <class T1, class T2>
void
swap(pair<T1, T2>& x, pair<T1, T2>& y) noexcept(noexcept(x.swap(y)));
struct piecewise_construct_t { explicit piecewise_construct_t() = default; };
inline constexpr piecewise_construct_t piecewise_construct = piecewise_construct_t();
template <class T> struct tuple_size;
template <size_t I, class T> struct tuple_element;
template <class T1, class T2> struct tuple_size<pair<T1, T2> >;
template <class T1, class T2> struct tuple_element<0, pair<T1, T2> >;
template <class T1, class T2> struct tuple_element<1, pair<T1, T2> >;
template<size_t I, class T1, class T2>
typename tuple_element<I, pair<T1, T2> >::type&
get(pair<T1, T2>&) noexcept; // constexpr in C++14
template<size_t I, class T1, class T2>
const typename tuple_element<I, pair<T1, T2> >::type&
get(const pair<T1, T2>&) noexcept; // constexpr in C++14
template<size_t I, class T1, class T2>
typename tuple_element<I, pair<T1, T2> >::type&&
get(pair<T1, T2>&&) noexcept; // constexpr in C++14
template<size_t I, class T1, class T2>
const typename tuple_element<I, pair<T1, T2> >::type&&
get(const pair<T1, T2>&&) noexcept; // constexpr in C++14
template<class T1, class T2>
constexpr T1& get(pair<T1, T2>&) noexcept; // C++14
template<class T1, class T2>
constexpr const T1& get(const pair<T1, T2>&) noexcept; // C++14
template<class T1, class T2>
constexpr T1&& get(pair<T1, T2>&&) noexcept; // C++14
template<class T1, class T2>
constexpr const T1&& get(const pair<T1, T2>&&) noexcept; // C++14
template<class T1, class T2>
constexpr T1& get(pair<T2, T1>&) noexcept; // C++14
template<class T1, class T2>
constexpr const T1& get(const pair<T2, T1>&) noexcept; // C++14
template<class T1, class T2>
constexpr T1&& get(pair<T2, T1>&&) noexcept; // C++14
template<class T1, class T2>
constexpr const T1&& get(const pair<T2, T1>&&) noexcept; // C++14
// C++14
template<class T, T... I>
struct integer_sequence
{
typedef T value_type;
static constexpr size_t size() noexcept;
};
template<size_t... I>
using index_sequence = integer_sequence<size_t, I...>;
template<class T, T N>
using make_integer_sequence = integer_sequence<T, 0, 1, ..., N-1>;
template<size_t N>
using make_index_sequence = make_integer_sequence<size_t, N>;
template<class... T>
using index_sequence_for = make_index_sequence<sizeof...(T)>;
template<class T, class U=T>
T exchange(T& obj, U&& new_value);
// 20.2.7, in-place construction // C++17
struct in_place_t {
explicit in_place_t() = default;
};
inline constexpr in_place_t in_place{};
template <class T>
struct in_place_type_t {
explicit in_place_type_t() = default;
};
template <class T>
inline constexpr in_place_type_t<T> in_place_type{};
template <size_t I>
struct in_place_index_t {
explicit in_place_index_t() = default;
};
template <size_t I>
inline constexpr in_place_index_t<I> in_place_index{};
} // std
*/
namespace rel_ops
{
template<class _Tp>
inline _LIBCPP_INLINE_VISIBILITY
bool
operator!=(const _Tp& __x, const _Tp& __y)
{
return !(__x == __y);
}
template<class _Tp>
inline _LIBCPP_INLINE_VISIBILITY
bool
operator> (const _Tp& __x, const _Tp& __y)
{
return __y < __x;
}
template<class _Tp>
inline _LIBCPP_INLINE_VISIBILITY
bool
operator<=(const _Tp& __x, const _Tp& __y)
{
return !(__y < __x);
}
template<class _Tp>
inline _LIBCPP_INLINE_VISIBILITY
bool
operator>=(const _Tp& __x, const _Tp& __y)
{
return !(__x < __y);
}
} // rel_ops
// swap_ranges is defined in <type_traits>`
// swap is defined in <type_traits>
// move_if_noexcept
template <class _Tp>
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
#ifndef _LIBCPP_CXX03_LANG
typename conditional
<
!is_nothrow_move_constructible<_Tp>::value && is_copy_constructible<_Tp>::value,
const _Tp&,
_Tp&&
>::type
#else // _LIBCPP_CXX03_LANG
const _Tp&
#endif
move_if_noexcept(_Tp& __x) _NOEXCEPT
{
return _VSTD::move(__x);
}
#if _LIBCPP_STD_VER > 14
template <class _Tp> constexpr add_const_t<_Tp>& as_const(_Tp& __t) noexcept { return __t; }
template <class _Tp> void as_const(const _Tp&&) = delete;
#endif
struct _LIBCPP_TEMPLATE_VIS piecewise_construct_t { explicit piecewise_construct_t() = default; };
#if defined(_LIBCPP_CXX03_LANG) || defined(_LIBCPP_BUILDING_LIBRARY)
extern _LIBCPP_EXPORTED_FROM_ABI const piecewise_construct_t piecewise_construct;// = piecewise_construct_t();
#else
/* _LIBCPP_INLINE_VAR */ constexpr piecewise_construct_t piecewise_construct = piecewise_construct_t();
#endif
#if defined(_LIBCPP_DEPRECATED_ABI_DISABLE_PAIR_TRIVIAL_COPY_CTOR)
template <class, class>
struct __non_trivially_copyable_base {
_LIBCPP_CONSTEXPR _LIBCPP_INLINE_VISIBILITY
__non_trivially_copyable_base() _NOEXCEPT {}
_LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
__non_trivially_copyable_base(__non_trivially_copyable_base const&) _NOEXCEPT {}
};
#endif
template <class _T1, class _T2>
struct _LIBCPP_TEMPLATE_VIS pair
#if defined(_LIBCPP_DEPRECATED_ABI_DISABLE_PAIR_TRIVIAL_COPY_CTOR)
: private __non_trivially_copyable_base<_T1, _T2>
#endif
{
typedef _T1 first_type;
typedef _T2 second_type;
_T1 first;
_T2 second;
#if !defined(_LIBCPP_CXX03_LANG)
pair(pair const&) = default;
pair(pair&&) = default;
#else
// Use the implicitly declared copy constructor in C++03
#endif
#ifdef _LIBCPP_CXX03_LANG
_LIBCPP_INLINE_VISIBILITY
pair() : first(), second() {}
_LIBCPP_INLINE_VISIBILITY
pair(_T1 const& __t1, _T2 const& __t2) : first(__t1), second(__t2) {}
template <class _U1, class _U2>
_LIBCPP_INLINE_VISIBILITY
pair(const pair<_U1, _U2>& __p) : first(__p.first), second(__p.second) {}
_LIBCPP_INLINE_VISIBILITY
pair& operator=(pair const& __p) {
first = __p.first;
second = __p.second;
return *this;
}
#else
template <bool _Val>
using _EnableB _LIBCPP_NODEBUG_TYPE = typename enable_if<_Val, bool>::type;
struct _CheckArgs {
template <int&...>
static constexpr bool __enable_explicit_default() {
return is_default_constructible<_T1>::value
&& is_default_constructible<_T2>::value
&& !__enable_implicit_default<>();
}
template <int&...>
static constexpr bool __enable_implicit_default() {
return __is_implicitly_default_constructible<_T1>::value
&& __is_implicitly_default_constructible<_T2>::value;
}
template <class _U1, class _U2>
static constexpr bool __enable_explicit() {
return is_constructible<first_type, _U1>::value
&& is_constructible<second_type, _U2>::value
&& (!is_convertible<_U1, first_type>::value
|| !is_convertible<_U2, second_type>::value);
}
template <class _U1, class _U2>
static constexpr bool __enable_implicit() {
return is_constructible<first_type, _U1>::value
&& is_constructible<second_type, _U2>::value
&& is_convertible<_U1, first_type>::value
&& is_convertible<_U2, second_type>::value;
}
};
template <bool _MaybeEnable>
using _CheckArgsDep _LIBCPP_NODEBUG_TYPE = typename conditional<
_MaybeEnable, _CheckArgs, __check_tuple_constructor_fail>::type;
struct _CheckTupleLikeConstructor {
template <class _Tuple>
static constexpr bool __enable_implicit() {
return __tuple_convertible<_Tuple, pair>::value;
}
template <class _Tuple>
static constexpr bool __enable_explicit() {
return __tuple_constructible<_Tuple, pair>::value
&& !__tuple_convertible<_Tuple, pair>::value;
}
template <class _Tuple>
static constexpr bool __enable_assign() {
return __tuple_assignable<_Tuple, pair>::value;
}
};
template <class _Tuple>
using _CheckTLC _LIBCPP_NODEBUG_TYPE = typename conditional<
__tuple_like_with_size<_Tuple, 2>::value
&& !is_same<typename decay<_Tuple>::type, pair>::value,
_CheckTupleLikeConstructor,
__check_tuple_constructor_fail
>::type;
template<bool _Dummy = true, _EnableB<
_CheckArgsDep<_Dummy>::__enable_explicit_default()
> = false>
explicit _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
pair() _NOEXCEPT_(is_nothrow_default_constructible<first_type>::value &&
is_nothrow_default_constructible<second_type>::value)
: first(), second() {}
template<bool _Dummy = true, _EnableB<
_CheckArgsDep<_Dummy>::__enable_implicit_default()
> = false>
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
pair() _NOEXCEPT_(is_nothrow_default_constructible<first_type>::value &&
is_nothrow_default_constructible<second_type>::value)
: first(), second() {}
template <bool _Dummy = true, _EnableB<
_CheckArgsDep<_Dummy>::template __enable_explicit<_T1 const&, _T2 const&>()
> = false>
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
explicit pair(_T1 const& __t1, _T2 const& __t2)
_NOEXCEPT_(is_nothrow_copy_constructible<first_type>::value &&
is_nothrow_copy_constructible<second_type>::value)
: first(__t1), second(__t2) {}
template<bool _Dummy = true, _EnableB<
_CheckArgsDep<_Dummy>::template __enable_implicit<_T1 const&, _T2 const&>()
> = false>
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
pair(_T1 const& __t1, _T2 const& __t2)
_NOEXCEPT_(is_nothrow_copy_constructible<first_type>::value &&
is_nothrow_copy_constructible<second_type>::value)
: first(__t1), second(__t2) {}
template<class _U1, class _U2, _EnableB<
_CheckArgs::template __enable_explicit<_U1, _U2>()
> = false>
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
explicit pair(_U1&& __u1, _U2&& __u2)
_NOEXCEPT_((is_nothrow_constructible<first_type, _U1>::value &&
is_nothrow_constructible<second_type, _U2>::value))
: first(_VSTD::forward<_U1>(__u1)), second(_VSTD::forward<_U2>(__u2)) {}
template<class _U1, class _U2, _EnableB<
_CheckArgs::template __enable_implicit<_U1, _U2>()
> = false>
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
pair(_U1&& __u1, _U2&& __u2)
_NOEXCEPT_((is_nothrow_constructible<first_type, _U1>::value &&
is_nothrow_constructible<second_type, _U2>::value))
: first(_VSTD::forward<_U1>(__u1)), second(_VSTD::forward<_U2>(__u2)) {}
template<class _U1, class _U2, _EnableB<
_CheckArgs::template __enable_explicit<_U1 const&, _U2 const&>()
> = false>
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
explicit pair(pair<_U1, _U2> const& __p)
_NOEXCEPT_((is_nothrow_constructible<first_type, _U1 const&>::value &&
is_nothrow_constructible<second_type, _U2 const&>::value))
: first(__p.first), second(__p.second) {}
template<class _U1, class _U2, _EnableB<
_CheckArgs::template __enable_implicit<_U1 const&, _U2 const&>()
> = false>
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
pair(pair<_U1, _U2> const& __p)
_NOEXCEPT_((is_nothrow_constructible<first_type, _U1 const&>::value &&
is_nothrow_constructible<second_type, _U2 const&>::value))
: first(__p.first), second(__p.second) {}
template<class _U1, class _U2, _EnableB<
_CheckArgs::template __enable_explicit<_U1, _U2>()
> = false>
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
explicit pair(pair<_U1, _U2>&&__p)
_NOEXCEPT_((is_nothrow_constructible<first_type, _U1&&>::value &&
is_nothrow_constructible<second_type, _U2&&>::value))
: first(_VSTD::forward<_U1>(__p.first)), second(_VSTD::forward<_U2>(__p.second)) {}
template<class _U1, class _U2, _EnableB<
_CheckArgs::template __enable_implicit<_U1, _U2>()
> = false>
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
pair(pair<_U1, _U2>&& __p)
_NOEXCEPT_((is_nothrow_constructible<first_type, _U1&&>::value &&
is_nothrow_constructible<second_type, _U2&&>::value))
: first(_VSTD::forward<_U1>(__p.first)), second(_VSTD::forward<_U2>(__p.second)) {}
template<class _Tuple, _EnableB<
_CheckTLC<_Tuple>::template __enable_explicit<_Tuple>()
> = false>
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
explicit pair(_Tuple&& __p)
: first(_VSTD::get<0>(_VSTD::forward<_Tuple>(__p))),
second(_VSTD::get<1>(_VSTD::forward<_Tuple>(__p))) {}
template<class _Tuple, _EnableB<
_CheckTLC<_Tuple>::template __enable_implicit<_Tuple>()
> = false>
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
pair(_Tuple&& __p)
: first(_VSTD::get<0>(_VSTD::forward<_Tuple>(__p))),
second(_VSTD::get<1>(_VSTD::forward<_Tuple>(__p))) {}
template <class... _Args1, class... _Args2>
_LIBCPP_INLINE_VISIBILITY
pair(piecewise_construct_t __pc,
tuple<_Args1...> __first_args, tuple<_Args2...> __second_args)
_NOEXCEPT_((is_nothrow_constructible<first_type, _Args1...>::value &&
is_nothrow_constructible<second_type, _Args2...>::value))
: pair(__pc, __first_args, __second_args,
typename __make_tuple_indices<sizeof...(_Args1)>::type(),
typename __make_tuple_indices<sizeof...(_Args2) >::type()) {}
_LIBCPP_INLINE_VISIBILITY
pair& operator=(typename conditional<
is_copy_assignable<first_type>::value &&
is_copy_assignable<second_type>::value,
pair, __nat>::type const& __p)
_NOEXCEPT_(is_nothrow_copy_assignable<first_type>::value &&
is_nothrow_copy_assignable<second_type>::value)
{
first = __p.first;
second = __p.second;
return *this;
}
_LIBCPP_INLINE_VISIBILITY
pair& operator=(typename conditional<
is_move_assignable<first_type>::value &&
is_move_assignable<second_type>::value,
pair, __nat>::type&& __p)
_NOEXCEPT_(is_nothrow_move_assignable<first_type>::value &&
is_nothrow_move_assignable<second_type>::value)
{
first = _VSTD::forward<first_type>(__p.first);
second = _VSTD::forward<second_type>(__p.second);
return *this;
}
template <class _Tuple, _EnableB<
_CheckTLC<_Tuple>::template __enable_assign<_Tuple>()
> = false>
_LIBCPP_INLINE_VISIBILITY
pair& operator=(_Tuple&& __p) {
first = _VSTD::get<0>(_VSTD::forward<_Tuple>(__p));
second = _VSTD::get<1>(_VSTD::forward<_Tuple>(__p));
return *this;
}
#endif
_LIBCPP_INLINE_VISIBILITY
void
swap(pair& __p) _NOEXCEPT_(__is_nothrow_swappable<first_type>::value &&
__is_nothrow_swappable<second_type>::value)
{
using _VSTD::swap;
swap(first, __p.first);
swap(second, __p.second);
}
private:
#ifndef _LIBCPP_CXX03_LANG
template <class... _Args1, class... _Args2, size_t... _I1, size_t... _I2>
_LIBCPP_INLINE_VISIBILITY
pair(piecewise_construct_t,
tuple<_Args1...>& __first_args, tuple<_Args2...>& __second_args,
__tuple_indices<_I1...>, __tuple_indices<_I2...>);
#endif
};
#ifndef _LIBCPP_HAS_NO_DEDUCTION_GUIDES
template<class _T1, class _T2>
pair(_T1, _T2) -> pair<_T1, _T2>;
#endif // _LIBCPP_HAS_NO_DEDUCTION_GUIDES
template <class _T1, class _T2>
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
bool
operator==(const pair<_T1,_T2>& __x, const pair<_T1,_T2>& __y)
{
return __x.first == __y.first && __x.second == __y.second;
}
template <class _T1, class _T2>
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
bool
operator!=(const pair<_T1,_T2>& __x, const pair<_T1,_T2>& __y)
{
return !(__x == __y);
}
template <class _T1, class _T2>
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
bool
operator< (const pair<_T1,_T2>& __x, const pair<_T1,_T2>& __y)
{
return __x.first < __y.first || (!(__y.first < __x.first) && __x.second < __y.second);
}
template <class _T1, class _T2>
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
bool
operator> (const pair<_T1,_T2>& __x, const pair<_T1,_T2>& __y)
{
return __y < __x;
}
template <class _T1, class _T2>
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
bool
operator>=(const pair<_T1,_T2>& __x, const pair<_T1,_T2>& __y)
{
return !(__x < __y);
}
template <class _T1, class _T2>
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
bool
operator<=(const pair<_T1,_T2>& __x, const pair<_T1,_T2>& __y)
{
return !(__y < __x);
}
template <class _T1, class _T2>
inline _LIBCPP_INLINE_VISIBILITY
typename enable_if
<
__is_swappable<_T1>::value &&
__is_swappable<_T2>::value,
void
>::type
swap(pair<_T1, _T2>& __x, pair<_T1, _T2>& __y)
_NOEXCEPT_((__is_nothrow_swappable<_T1>::value &&
__is_nothrow_swappable<_T2>::value))
{
__x.swap(__y);
}
template <class _Tp>
struct __unwrap_reference { typedef _LIBCPP_NODEBUG_TYPE _Tp type; };
template <class _Tp>
struct __unwrap_reference<reference_wrapper<_Tp> > { typedef _LIBCPP_NODEBUG_TYPE _Tp& type; };
#if _LIBCPP_STD_VER > 17
template <class _Tp>
struct unwrap_reference : __unwrap_reference<_Tp> { };
template <class _Tp>
struct unwrap_ref_decay : unwrap_reference<typename decay<_Tp>::type> { };
#endif // > C++17
template <class _Tp>
struct __unwrap_ref_decay
#if _LIBCPP_STD_VER > 17
: unwrap_ref_decay<_Tp>
#else
: __unwrap_reference<typename decay<_Tp>::type>
#endif
{ };
#ifndef _LIBCPP_CXX03_LANG
template <class _T1, class _T2>
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
pair<typename __unwrap_ref_decay<_T1>::type, typename __unwrap_ref_decay<_T2>::type>
make_pair(_T1&& __t1, _T2&& __t2)
{
return pair<typename __unwrap_ref_decay<_T1>::type, typename __unwrap_ref_decay<_T2>::type>
(_VSTD::forward<_T1>(__t1), _VSTD::forward<_T2>(__t2));
}
#else // _LIBCPP_CXX03_LANG
template <class _T1, class _T2>
inline _LIBCPP_INLINE_VISIBILITY
pair<_T1,_T2>
make_pair(_T1 __x, _T2 __y)
{
return pair<_T1, _T2>(__x, __y);
}
#endif // _LIBCPP_CXX03_LANG
template <class _T1, class _T2>
struct _LIBCPP_TEMPLATE_VIS tuple_size<pair<_T1, _T2> >
: public integral_constant<size_t, 2> {};
template <size_t _Ip, class _T1, class _T2>
struct _LIBCPP_TEMPLATE_VIS tuple_element<_Ip, pair<_T1, _T2> >
{
static_assert(_Ip < 2, "Index out of bounds in std::tuple_element<std::pair<T1, T2>>");
};
template <class _T1, class _T2>
struct _LIBCPP_TEMPLATE_VIS tuple_element<0, pair<_T1, _T2> >
{
typedef _LIBCPP_NODEBUG_TYPE _T1 type;
};
template <class _T1, class _T2>
struct _LIBCPP_TEMPLATE_VIS tuple_element<1, pair<_T1, _T2> >
{
typedef _LIBCPP_NODEBUG_TYPE _T2 type;
};
template <size_t _Ip> struct __get_pair;
template <>
struct __get_pair<0>
{
template <class _T1, class _T2>
static
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
_T1&
get(pair<_T1, _T2>& __p) _NOEXCEPT {return __p.first;}
template <class _T1, class _T2>
static
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
const _T1&
get(const pair<_T1, _T2>& __p) _NOEXCEPT {return __p.first;}
#ifndef _LIBCPP_CXX03_LANG
template <class _T1, class _T2>
static
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
_T1&&
get(pair<_T1, _T2>&& __p) _NOEXCEPT {return _VSTD::forward<_T1>(__p.first);}
template <class _T1, class _T2>
static
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
const _T1&&
get(const pair<_T1, _T2>&& __p) _NOEXCEPT {return _VSTD::forward<const _T1>(__p.first);}
#endif // _LIBCPP_CXX03_LANG
};
template <>
struct __get_pair<1>
{
template <class _T1, class _T2>
static
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
_T2&
get(pair<_T1, _T2>& __p) _NOEXCEPT {return __p.second;}
template <class _T1, class _T2>
static
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
const _T2&
get(const pair<_T1, _T2>& __p) _NOEXCEPT {return __p.second;}
#ifndef _LIBCPP_CXX03_LANG
template <class _T1, class _T2>
static
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
_T2&&
get(pair<_T1, _T2>&& __p) _NOEXCEPT {return _VSTD::forward<_T2>(__p.second);}
template <class _T1, class _T2>
static
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
const _T2&&
get(const pair<_T1, _T2>&& __p) _NOEXCEPT {return _VSTD::forward<const _T2>(__p.second);}
#endif // _LIBCPP_CXX03_LANG
};
template <size_t _Ip, class _T1, class _T2>
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
typename tuple_element<_Ip, pair<_T1, _T2> >::type&
get(pair<_T1, _T2>& __p) _NOEXCEPT
{
return __get_pair<_Ip>::get(__p);
}
template <size_t _Ip, class _T1, class _T2>
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
const typename tuple_element<_Ip, pair<_T1, _T2> >::type&
get(const pair<_T1, _T2>& __p) _NOEXCEPT
{
return __get_pair<_Ip>::get(__p);
}
#ifndef _LIBCPP_CXX03_LANG
template <size_t _Ip, class _T1, class _T2>
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
typename tuple_element<_Ip, pair<_T1, _T2> >::type&&
get(pair<_T1, _T2>&& __p) _NOEXCEPT
{
return __get_pair<_Ip>::get(_VSTD::move(__p));
}
template <size_t _Ip, class _T1, class _T2>
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
const typename tuple_element<_Ip, pair<_T1, _T2> >::type&&
get(const pair<_T1, _T2>&& __p) _NOEXCEPT
{
return __get_pair<_Ip>::get(_VSTD::move(__p));
}
#endif // _LIBCPP_CXX03_LANG
#if _LIBCPP_STD_VER > 11
template <class _T1, class _T2>
inline _LIBCPP_INLINE_VISIBILITY
constexpr _T1 & get(pair<_T1, _T2>& __p) _NOEXCEPT
{
return __get_pair<0>::get(__p);
}
template <class _T1, class _T2>
inline _LIBCPP_INLINE_VISIBILITY
constexpr _T1 const & get(pair<_T1, _T2> const& __p) _NOEXCEPT
{
return __get_pair<0>::get(__p);
}
template <class _T1, class _T2>
inline _LIBCPP_INLINE_VISIBILITY
constexpr _T1 && get(pair<_T1, _T2>&& __p) _NOEXCEPT
{
return __get_pair<0>::get(_VSTD::move(__p));
}
template <class _T1, class _T2>
inline _LIBCPP_INLINE_VISIBILITY
constexpr _T1 const && get(pair<_T1, _T2> const&& __p) _NOEXCEPT
{
return __get_pair<0>::get(_VSTD::move(__p));
}
template <class _T1, class _T2>
inline _LIBCPP_INLINE_VISIBILITY
constexpr _T1 & get(pair<_T2, _T1>& __p) _NOEXCEPT
{
return __get_pair<1>::get(__p);
}
template <class _T1, class _T2>
inline _LIBCPP_INLINE_VISIBILITY
constexpr _T1 const & get(pair<_T2, _T1> const& __p) _NOEXCEPT
{
return __get_pair<1>::get(__p);
}
template <class _T1, class _T2>
inline _LIBCPP_INLINE_VISIBILITY
constexpr _T1 && get(pair<_T2, _T1>&& __p) _NOEXCEPT
{
return __get_pair<1>::get(_VSTD::move(__p));
}
template <class _T1, class _T2>
inline _LIBCPP_INLINE_VISIBILITY
constexpr _T1 const && get(pair<_T2, _T1> const&& __p) _NOEXCEPT
{
return __get_pair<1>::get(_VSTD::move(__p));
}
#endif
#if _LIBCPP_STD_VER > 11
template<class _Tp, _Tp... _Ip>
struct _LIBCPP_TEMPLATE_VIS integer_sequence
{
typedef _Tp value_type;
static_assert( is_integral<_Tp>::value,
"std::integer_sequence can only be instantiated with an integral type" );
static
_LIBCPP_INLINE_VISIBILITY
constexpr
size_t
size() noexcept { return sizeof...(_Ip); }
};
template<size_t... _Ip>
using index_sequence = integer_sequence<size_t, _Ip...>;
#if __has_builtin(__make_integer_seq) && !defined(_LIBCPP_TESTING_FALLBACK_MAKE_INTEGER_SEQUENCE)
template <class _Tp, _Tp _Ep>
using __make_integer_sequence _LIBCPP_NODEBUG_TYPE = __make_integer_seq<integer_sequence, _Tp, _Ep>;
#else
template<typename _Tp, _Tp _Np> using __make_integer_sequence_unchecked _LIBCPP_NODEBUG_TYPE =
typename __detail::__make<_Np>::type::template __convert<integer_sequence, _Tp>;
template <class _Tp, _Tp _Ep>
struct __make_integer_sequence_checked
{
static_assert(is_integral<_Tp>::value,
"std::make_integer_sequence can only be instantiated with an integral type" );
static_assert(0 <= _Ep, "std::make_integer_sequence must have a non-negative sequence length");
// Workaround GCC bug by preventing bad installations when 0 <= _Ep
// https://gcc.gnu.org/bugzilla/show_bug.cgi?id=68929
typedef _LIBCPP_NODEBUG_TYPE __make_integer_sequence_unchecked<_Tp, 0 <= _Ep ? _Ep : 0> type;
};
template <class _Tp, _Tp _Ep>
using __make_integer_sequence _LIBCPP_NODEBUG_TYPE = typename __make_integer_sequence_checked<_Tp, _Ep>::type;
#endif
template<class _Tp, _Tp _Np>
using make_integer_sequence = __make_integer_sequence<_Tp, _Np>;
template<size_t _Np>
using make_index_sequence = make_integer_sequence<size_t, _Np>;
template<class... _Tp>
using index_sequence_for = make_index_sequence<sizeof...(_Tp)>;
#endif // _LIBCPP_STD_VER > 11
#if _LIBCPP_STD_VER > 11
template<class _T1, class _T2 = _T1>
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
_T1 exchange(_T1& __obj, _T2 && __new_value)
{
_T1 __old_value = _VSTD::move(__obj);
__obj = _VSTD::forward<_T2>(__new_value);
return __old_value;
}
#endif // _LIBCPP_STD_VER > 11
#if _LIBCPP_STD_VER > 14
struct _LIBCPP_TYPE_VIS in_place_t {
explicit in_place_t() = default;
};
_LIBCPP_INLINE_VAR constexpr in_place_t in_place{};
template <class _Tp>
struct _LIBCPP_TEMPLATE_VIS in_place_type_t {
explicit in_place_type_t() = default;
};
template <class _Tp>
_LIBCPP_INLINE_VAR constexpr in_place_type_t<_Tp> in_place_type{};
template <size_t _Idx>
struct _LIBCPP_TYPE_VIS in_place_index_t {
explicit in_place_index_t() = default;
};
template <size_t _Idx>
_LIBCPP_INLINE_VAR constexpr in_place_index_t<_Idx> in_place_index{};
template <class _Tp> struct __is_inplace_type_imp : false_type {};
template <class _Tp> struct __is_inplace_type_imp<in_place_type_t<_Tp>> : true_type {};
template <class _Tp>
using __is_inplace_type = __is_inplace_type_imp<__uncvref_t<_Tp>>;
template <class _Tp> struct __is_inplace_index_imp : false_type {};
template <size_t _Idx> struct __is_inplace_index_imp<in_place_index_t<_Idx>> : true_type {};
template <class _Tp>
using __is_inplace_index = __is_inplace_index_imp<__uncvref_t<_Tp>>;
#endif // _LIBCPP_STD_VER > 14
template <class _Arg, class _Result>
struct _LIBCPP_TEMPLATE_VIS unary_function
{
typedef _Arg argument_type;
typedef _Result result_type;
};
template <class _Size>
inline _LIBCPP_INLINE_VISIBILITY
_Size
__loadword(const void* __p)
{
_Size __r;
std::memcpy(&__r, __p, sizeof(__r));
return __r;
}
// We use murmur2 when size_t is 32 bits, and cityhash64 when size_t
// is 64 bits. This is because cityhash64 uses 64bit x 64bit
// multiplication, which can be very slow on 32-bit systems.
template <class _Size, size_t = sizeof(_Size)*__CHAR_BIT__>
struct __murmur2_or_cityhash;
template <class _Size>
struct __murmur2_or_cityhash<_Size, 32>
{
inline _Size operator()(const void* __key, _Size __len)
_LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK;
};
// murmur2
template <class _Size>
_Size
__murmur2_or_cityhash<_Size, 32>::operator()(const void* __key, _Size __len)
{
const _Size __m = 0x5bd1e995;
const _Size __r = 24;
_Size __h = __len;
const unsigned char* __data = static_cast<const unsigned char*>(__key);
for (; __len >= 4; __data += 4, __len -= 4)
{
_Size __k = __loadword<_Size>(__data);
__k *= __m;
__k ^= __k >> __r;
__k *= __m;
__h *= __m;
__h ^= __k;
}
switch (__len)
{
case 3:
__h ^= __data[2] << 16;
_LIBCPP_FALLTHROUGH();
case 2:
__h ^= __data[1] << 8;
_LIBCPP_FALLTHROUGH();
case 1:
__h ^= __data[0];
__h *= __m;
}
__h ^= __h >> 13;
__h *= __m;
__h ^= __h >> 15;
return __h;
}
template <class _Size>
struct __murmur2_or_cityhash<_Size, 64>
{
inline _Size operator()(const void* __key, _Size __len) _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK;
private:
// Some primes between 2^63 and 2^64.
static const _Size __k0 = 0xc3a5c85c97cb3127ULL;
static const _Size __k1 = 0xb492b66fbe98f273ULL;
static const _Size __k2 = 0x9ae16a3b2f90404fULL;
static const _Size __k3 = 0xc949d7c7509e6557ULL;
static _Size __rotate(_Size __val, int __shift) {
return __shift == 0 ? __val : ((__val >> __shift) | (__val << (64 - __shift)));
}
static _Size __rotate_by_at_least_1(_Size __val, int __shift) {
return (__val >> __shift) | (__val << (64 - __shift));
}
static _Size __shift_mix(_Size __val) {
return __val ^ (__val >> 47);
}
static _Size __hash_len_16(_Size __u, _Size __v)
_LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK
{
const _Size __mul = 0x9ddfea08eb382d69ULL;
_Size __a = (__u ^ __v) * __mul;
__a ^= (__a >> 47);
_Size __b = (__v ^ __a) * __mul;
__b ^= (__b >> 47);
__b *= __mul;
return __b;
}
static _Size __hash_len_0_to_16(const char* __s, _Size __len)
_LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK
{
if (__len > 8) {
const _Size __a = __loadword<_Size>(__s);
const _Size __b = __loadword<_Size>(__s + __len - 8);
return __hash_len_16(__a, __rotate_by_at_least_1(__b + __len, __len)) ^ __b;
}
if (__len >= 4) {
const uint32_t __a = __loadword<uint32_t>(__s);
const uint32_t __b = __loadword<uint32_t>(__s + __len - 4);
return __hash_len_16(__len + (__a << 3), __b);
}
if (__len > 0) {
const unsigned char __a = __s[0];
const unsigned char __b = __s[__len >> 1];
const unsigned char __c = __s[__len - 1];
const uint32_t __y = static_cast<uint32_t>(__a) +
(static_cast<uint32_t>(__b) << 8);
const uint32_t __z = __len + (static_cast<uint32_t>(__c) << 2);
return __shift_mix(__y * __k2 ^ __z * __k3) * __k2;
}
return __k2;
}
static _Size __hash_len_17_to_32(const char *__s, _Size __len)
_LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK
{
const _Size __a = __loadword<_Size>(__s) * __k1;
const _Size __b = __loadword<_Size>(__s + 8);
const _Size __c = __loadword<_Size>(__s + __len - 8) * __k2;
const _Size __d = __loadword<_Size>(__s + __len - 16) * __k0;
return __hash_len_16(__rotate(__a - __b, 43) + __rotate(__c, 30) + __d,
__a + __rotate(__b ^ __k3, 20) - __c + __len);
}
// Return a 16-byte hash for 48 bytes. Quick and dirty.
// Callers do best to use "random-looking" values for a and b.
static pair<_Size, _Size> __weak_hash_len_32_with_seeds(
_Size __w, _Size __x, _Size __y, _Size __z, _Size __a, _Size __b)
_LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK
{
__a += __w;
__b = __rotate(__b + __a + __z, 21);
const _Size __c = __a;
__a += __x;
__a += __y;
__b += __rotate(__a, 44);
return pair<_Size, _Size>(__a + __z, __b + __c);
}
// Return a 16-byte hash for s[0] ... s[31], a, and b. Quick and dirty.
static pair<_Size, _Size> __weak_hash_len_32_with_seeds(
const char* __s, _Size __a, _Size __b)
_LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK
{
return __weak_hash_len_32_with_seeds(__loadword<_Size>(__s),
__loadword<_Size>(__s + 8),
__loadword<_Size>(__s + 16),
__loadword<_Size>(__s + 24),
__a,
__b);
}
// Return an 8-byte hash for 33 to 64 bytes.
static _Size __hash_len_33_to_64(const char *__s, size_t __len)
_LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK
{
_Size __z = __loadword<_Size>(__s + 24);
_Size __a = __loadword<_Size>(__s) +
(__len + __loadword<_Size>(__s + __len - 16)) * __k0;
_Size __b = __rotate(__a + __z, 52);
_Size __c = __rotate(__a, 37);
__a += __loadword<_Size>(__s + 8);
__c += __rotate(__a, 7);
__a += __loadword<_Size>(__s + 16);
_Size __vf = __a + __z;
_Size __vs = __b + __rotate(__a, 31) + __c;
__a = __loadword<_Size>(__s + 16) + __loadword<_Size>(__s + __len - 32);
__z += __loadword<_Size>(__s + __len - 8);
__b = __rotate(__a + __z, 52);
__c = __rotate(__a, 37);
__a += __loadword<_Size>(__s + __len - 24);
__c += __rotate(__a, 7);
__a += __loadword<_Size>(__s + __len - 16);
_Size __wf = __a + __z;
_Size __ws = __b + __rotate(__a, 31) + __c;
_Size __r = __shift_mix((__vf + __ws) * __k2 + (__wf + __vs) * __k0);
return __shift_mix(__r * __k0 + __vs) * __k2;
}
};
// cityhash64
template <class _Size>
_Size
__murmur2_or_cityhash<_Size, 64>::operator()(const void* __key, _Size __len)
{
const char* __s = static_cast<const char*>(__key);
if (__len <= 32) {
if (__len <= 16) {
return __hash_len_0_to_16(__s, __len);
} else {
return __hash_len_17_to_32(__s, __len);
}
} else if (__len <= 64) {
return __hash_len_33_to_64(__s, __len);
}
// For strings over 64 bytes we hash the end first, and then as we
// loop we keep 56 bytes of state: v, w, x, y, and z.
_Size __x = __loadword<_Size>(__s + __len - 40);
_Size __y = __loadword<_Size>(__s + __len - 16) +
__loadword<_Size>(__s + __len - 56);
_Size __z = __hash_len_16(__loadword<_Size>(__s + __len - 48) + __len,
__loadword<_Size>(__s + __len - 24));
pair<_Size, _Size> __v = __weak_hash_len_32_with_seeds(__s + __len - 64, __len, __z);
pair<_Size, _Size> __w = __weak_hash_len_32_with_seeds(__s + __len - 32, __y + __k1, __x);
__x = __x * __k1 + __loadword<_Size>(__s);
// Decrease len to the nearest multiple of 64, and operate on 64-byte chunks.
__len = (__len - 1) & ~static_cast<_Size>(63);
do {
__x = __rotate(__x + __y + __v.first + __loadword<_Size>(__s + 8), 37) * __k1;
__y = __rotate(__y + __v.second + __loadword<_Size>(__s + 48), 42) * __k1;
__x ^= __w.second;
__y += __v.first + __loadword<_Size>(__s + 40);
__z = __rotate(__z + __w.first, 33) * __k1;
__v = __weak_hash_len_32_with_seeds(__s, __v.second * __k1, __x + __w.first);
__w = __weak_hash_len_32_with_seeds(__s + 32, __z + __w.second,
__y + __loadword<_Size>(__s + 16));
std::swap(__z, __x);
__s += 64;
__len -= 64;
} while (__len != 0);
return __hash_len_16(
__hash_len_16(__v.first, __w.first) + __shift_mix(__y) * __k1 + __z,
__hash_len_16(__v.second, __w.second) + __x);
}
template <class _Tp, size_t = sizeof(_Tp) / sizeof(size_t)>
struct __scalar_hash;
template <class _Tp>
struct __scalar_hash<_Tp, 0>
: public unary_function<_Tp, size_t>
{
_LIBCPP_INLINE_VISIBILITY
size_t operator()(_Tp __v) const _NOEXCEPT
{
union
{
_Tp __t;
size_t __a;
} __u;
__u.__a = 0;
__u.__t = __v;
return __u.__a;
}
};
template <class _Tp>
struct __scalar_hash<_Tp, 1>
: public unary_function<_Tp, size_t>
{
_LIBCPP_INLINE_VISIBILITY
size_t operator()(_Tp __v) const _NOEXCEPT
{
union
{
_Tp __t;
size_t __a;
} __u;
__u.__t = __v;
return __u.__a;
}
};
template <class _Tp>
struct __scalar_hash<_Tp, 2>
: public unary_function<_Tp, size_t>
{
_LIBCPP_INLINE_VISIBILITY
size_t operator()(_Tp __v) const _NOEXCEPT
{
union
{
_Tp __t;
struct
{
size_t __a;
size_t __b;
} __s;
} __u;
__u.__t = __v;
return __murmur2_or_cityhash<size_t>()(&__u, sizeof(__u));
}
};
template <class _Tp>
struct __scalar_hash<_Tp, 3>
: public unary_function<_Tp, size_t>
{
_LIBCPP_INLINE_VISIBILITY
size_t operator()(_Tp __v) const _NOEXCEPT
{
union
{
_Tp __t;
struct
{
size_t __a;
size_t __b;
size_t __c;
} __s;
} __u;
__u.__t = __v;
return __murmur2_or_cityhash<size_t>()(&__u, sizeof(__u));
}
};
template <class _Tp>
struct __scalar_hash<_Tp, 4>
: public unary_function<_Tp, size_t>
{
_LIBCPP_INLINE_VISIBILITY
size_t operator()(_Tp __v) const _NOEXCEPT
{
union
{
_Tp __t;
struct
{
size_t __a;
size_t __b;
size_t __c;
size_t __d;
} __s;
} __u;
__u.__t = __v;
return __murmur2_or_cityhash<size_t>()(&__u, sizeof(__u));
}
};
struct _PairT {
size_t first;
size_t second;
};
_LIBCPP_INLINE_VISIBILITY
inline size_t __hash_combine(size_t __lhs, size_t __rhs) _NOEXCEPT {
typedef __scalar_hash<_PairT> _HashT;
const _PairT __p = {__lhs, __rhs};
return _HashT()(__p);
}
template<class _Tp>
struct _LIBCPP_TEMPLATE_VIS hash<_Tp*>
: public unary_function<_Tp*, size_t>
{
_LIBCPP_INLINE_VISIBILITY
size_t operator()(_Tp* __v) const _NOEXCEPT
{
union
{
_Tp* __t;
size_t __a;
} __u;
__u.__t = __v;
return __murmur2_or_cityhash<size_t>()(&__u, sizeof(__u));
}
};
template <>
struct _LIBCPP_TEMPLATE_VIS hash<bool>
: public unary_function<bool, size_t>
{
_LIBCPP_INLINE_VISIBILITY
size_t operator()(bool __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
};
template <>
struct _LIBCPP_TEMPLATE_VIS hash<char>
: public unary_function<char, size_t>
{
_LIBCPP_INLINE_VISIBILITY
size_t operator()(char __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
};
template <>
struct _LIBCPP_TEMPLATE_VIS hash<signed char>
: public unary_function<signed char, size_t>
{
_LIBCPP_INLINE_VISIBILITY
size_t operator()(signed char __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
};
template <>
struct _LIBCPP_TEMPLATE_VIS hash<unsigned char>
: public unary_function<unsigned char, size_t>
{
_LIBCPP_INLINE_VISIBILITY
size_t operator()(unsigned char __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
};
#ifndef _LIBCPP_HAS_NO_UNICODE_CHARS
template <>
struct _LIBCPP_TEMPLATE_VIS hash<char16_t>
: public unary_function<char16_t, size_t>
{
_LIBCPP_INLINE_VISIBILITY
size_t operator()(char16_t __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
};
template <>
struct _LIBCPP_TEMPLATE_VIS hash<char32_t>
: public unary_function<char32_t, size_t>
{
_LIBCPP_INLINE_VISIBILITY
size_t operator()(char32_t __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
};
#endif // _LIBCPP_HAS_NO_UNICODE_CHARS
template <>
struct _LIBCPP_TEMPLATE_VIS hash<wchar_t>
: public unary_function<wchar_t, size_t>
{
_LIBCPP_INLINE_VISIBILITY
size_t operator()(wchar_t __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
};
template <>
struct _LIBCPP_TEMPLATE_VIS hash<short>
: public unary_function<short, size_t>
{
_LIBCPP_INLINE_VISIBILITY
size_t operator()(short __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
};
template <>
struct _LIBCPP_TEMPLATE_VIS hash<unsigned short>
: public unary_function<unsigned short, size_t>
{
_LIBCPP_INLINE_VISIBILITY
size_t operator()(unsigned short __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
};
template <>
struct _LIBCPP_TEMPLATE_VIS hash<int>
: public unary_function<int, size_t>
{
_LIBCPP_INLINE_VISIBILITY
size_t operator()(int __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
};
template <>
struct _LIBCPP_TEMPLATE_VIS hash<unsigned int>
: public unary_function<unsigned int, size_t>
{
_LIBCPP_INLINE_VISIBILITY
size_t operator()(unsigned int __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
};
template <>
struct _LIBCPP_TEMPLATE_VIS hash<long>
: public unary_function<long, size_t>
{
_LIBCPP_INLINE_VISIBILITY
size_t operator()(long __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
};
template <>
struct _LIBCPP_TEMPLATE_VIS hash<unsigned long>
: public unary_function<unsigned long, size_t>
{
_LIBCPP_INLINE_VISIBILITY
size_t operator()(unsigned long __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
};
template <>
struct _LIBCPP_TEMPLATE_VIS hash<long long>
: public __scalar_hash<long long>
{
};
template <>
struct _LIBCPP_TEMPLATE_VIS hash<unsigned long long>
: public __scalar_hash<unsigned long long>
{
};
#ifndef _LIBCPP_HAS_NO_INT128
template <>
struct _LIBCPP_TEMPLATE_VIS hash<__int128_t>
: public __scalar_hash<__int128_t>
{
};
template <>
struct _LIBCPP_TEMPLATE_VIS hash<__uint128_t>
: public __scalar_hash<__uint128_t>
{
};
#endif
template <>
struct _LIBCPP_TEMPLATE_VIS hash<float>
: public __scalar_hash<float>
{
_LIBCPP_INLINE_VISIBILITY
size_t operator()(float __v) const _NOEXCEPT
{
// -0.0 and 0.0 should return same hash
if (__v == 0.0f)
return 0;
return __scalar_hash<float>::operator()(__v);
}
};
template <>
struct _LIBCPP_TEMPLATE_VIS hash<double>
: public __scalar_hash<double>
{
_LIBCPP_INLINE_VISIBILITY
size_t operator()(double __v) const _NOEXCEPT
{
// -0.0 and 0.0 should return same hash
if (__v == 0.0)
return 0;
return __scalar_hash<double>::operator()(__v);
}
};
template <>
struct _LIBCPP_TEMPLATE_VIS hash<long double>
: public __scalar_hash<long double>
{
_LIBCPP_INLINE_VISIBILITY
size_t operator()(long double __v) const _NOEXCEPT
{
// -0.0 and 0.0 should return same hash
if (__v == 0.0L)
return 0;
#if defined(__i386__)
// Zero out padding bits
union
{
long double __t;
struct
{
size_t __a;
size_t __b;
size_t __c;
size_t __d;
} __s;
} __u;
__u.__s.__a = 0;
__u.__s.__b = 0;
__u.__s.__c = 0;
__u.__s.__d = 0;
__u.__t = __v;
return __u.__s.__a ^ __u.__s.__b ^ __u.__s.__c ^ __u.__s.__d;
#elif defined(__x86_64__)
// Zero out padding bits
union
{
long double __t;
struct
{
size_t __a;
size_t __b;
} __s;
} __u;
__u.__s.__a = 0;
__u.__s.__b = 0;
__u.__t = __v;
return __u.__s.__a ^ __u.__s.__b;
#else
return __scalar_hash<long double>::operator()(__v);
#endif
}
};
#if _LIBCPP_STD_VER > 11
template <class _Tp, bool = is_enum<_Tp>::value>
struct _LIBCPP_TEMPLATE_VIS __enum_hash
: public unary_function<_Tp, size_t>
{
_LIBCPP_INLINE_VISIBILITY
size_t operator()(_Tp __v) const _NOEXCEPT
{
typedef typename underlying_type<_Tp>::type type;
return hash<type>{}(static_cast<type>(__v));
}
};
template <class _Tp>
struct _LIBCPP_TEMPLATE_VIS __enum_hash<_Tp, false> {
__enum_hash() = delete;
__enum_hash(__enum_hash const&) = delete;
__enum_hash& operator=(__enum_hash const&) = delete;
};
template <class _Tp>
struct _LIBCPP_TEMPLATE_VIS hash : public __enum_hash<_Tp>
{
};
#endif
#if _LIBCPP_STD_VER > 14
template <>
struct _LIBCPP_TEMPLATE_VIS hash<nullptr_t>
: public unary_function<nullptr_t, size_t>
{
_LIBCPP_INLINE_VISIBILITY
size_t operator()(nullptr_t) const _NOEXCEPT {
return 662607004ull;
}
};
#endif
#ifndef _LIBCPP_CXX03_LANG
template <class _Key, class _Hash>
using __check_hash_requirements _LIBCPP_NODEBUG_TYPE = integral_constant<bool,
is_copy_constructible<_Hash>::value &&
is_move_constructible<_Hash>::value &&
__invokable_r<size_t, _Hash, _Key const&>::value
>;
template <class _Key, class _Hash = std::hash<_Key> >
using __has_enabled_hash _LIBCPP_NODEBUG_TYPE = integral_constant<bool,
__check_hash_requirements<_Key, _Hash>::value &&
is_default_constructible<_Hash>::value
>;
#if _LIBCPP_STD_VER > 14
template <class _Type, class>
using __enable_hash_helper_imp _LIBCPP_NODEBUG_TYPE = _Type;
template <class _Type, class ..._Keys>
using __enable_hash_helper _LIBCPP_NODEBUG_TYPE = __enable_hash_helper_imp<_Type,
typename enable_if<__all<__has_enabled_hash<_Keys>::value...>::value>::type
>;
#else
template <class _Type, class ...>
using __enable_hash_helper _LIBCPP_NODEBUG_TYPE = _Type;
#endif
#endif // !_LIBCPP_CXX03_LANG
_LIBCPP_END_NAMESPACE_STD
#endif // _LIBCPP_UTILITY
| 49,631 | 1,620 | jart/cosmopolitan | false |
cosmopolitan/third_party/libcxx/charconv.cc | //===------------------------- charconv.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/charconv"
#include "third_party/libcxx/string.h"
_LIBCPP_BEGIN_NAMESPACE_STD
namespace __itoa
{
static constexpr char cDigitsLut[200] = {
'0', '0', '0', '1', '0', '2', '0', '3', '0', '4', '0', '5', '0', '6', '0',
'7', '0', '8', '0', '9', '1', '0', '1', '1', '1', '2', '1', '3', '1', '4',
'1', '5', '1', '6', '1', '7', '1', '8', '1', '9', '2', '0', '2', '1', '2',
'2', '2', '3', '2', '4', '2', '5', '2', '6', '2', '7', '2', '8', '2', '9',
'3', '0', '3', '1', '3', '2', '3', '3', '3', '4', '3', '5', '3', '6', '3',
'7', '3', '8', '3', '9', '4', '0', '4', '1', '4', '2', '4', '3', '4', '4',
'4', '5', '4', '6', '4', '7', '4', '8', '4', '9', '5', '0', '5', '1', '5',
'2', '5', '3', '5', '4', '5', '5', '5', '6', '5', '7', '5', '8', '5', '9',
'6', '0', '6', '1', '6', '2', '6', '3', '6', '4', '6', '5', '6', '6', '6',
'7', '6', '8', '6', '9', '7', '0', '7', '1', '7', '2', '7', '3', '7', '4',
'7', '5', '7', '6', '7', '7', '7', '8', '7', '9', '8', '0', '8', '1', '8',
'2', '8', '3', '8', '4', '8', '5', '8', '6', '8', '7', '8', '8', '8', '9',
'9', '0', '9', '1', '9', '2', '9', '3', '9', '4', '9', '5', '9', '6', '9',
'7', '9', '8', '9', '9'};
template <typename T>
inline _LIBCPP_INLINE_VISIBILITY char*
append1(char* buffer, T i)
{
*buffer = '0' + static_cast<char>(i);
return buffer + 1;
}
template <typename T>
inline _LIBCPP_INLINE_VISIBILITY char*
append2(char* buffer, T i)
{
memcpy(buffer, &cDigitsLut[(i)*2], 2);
return buffer + 2;
}
template <typename T>
inline _LIBCPP_INLINE_VISIBILITY char*
append3(char* buffer, T i)
{
return append2(append1(buffer, (i) / 100), (i) % 100);
}
template <typename T>
inline _LIBCPP_INLINE_VISIBILITY char*
append4(char* buffer, T i)
{
return append2(append2(buffer, (i) / 100), (i) % 100);
}
template <typename T>
inline _LIBCPP_INLINE_VISIBILITY char*
append2_no_zeros(char* buffer, T v)
{
if (v < 10)
return append1(buffer, v);
else
return append2(buffer, v);
}
template <typename T>
inline _LIBCPP_INLINE_VISIBILITY char*
append4_no_zeros(char* buffer, T v)
{
if (v < 100)
return append2_no_zeros(buffer, v);
else if (v < 1000)
return append3(buffer, v);
else
return append4(buffer, v);
}
template <typename T>
inline _LIBCPP_INLINE_VISIBILITY char*
append8_no_zeros(char* buffer, T v)
{
if (v < 10000)
{
buffer = append4_no_zeros(buffer, v);
}
else
{
buffer = append4_no_zeros(buffer, v / 10000);
buffer = append4(buffer, v % 10000);
}
return buffer;
}
char*
__u32toa(uint32_t value, char* buffer)
{
if (value < 100000000)
{
buffer = append8_no_zeros(buffer, value);
}
else
{
// value = aabbbbcccc in decimal
const uint32_t a = value / 100000000; // 1 to 42
value %= 100000000;
buffer = append2_no_zeros(buffer, a);
buffer = append4(buffer, value / 10000);
buffer = append4(buffer, value % 10000);
}
return buffer;
}
char*
__u64toa(uint64_t value, char* buffer)
{
if (value < 100000000)
{
uint32_t v = static_cast<uint32_t>(value);
buffer = append8_no_zeros(buffer, v);
}
else if (value < 10000000000000000)
{
const uint32_t v0 = static_cast<uint32_t>(value / 100000000);
const uint32_t v1 = static_cast<uint32_t>(value % 100000000);
buffer = append8_no_zeros(buffer, v0);
buffer = append4(buffer, v1 / 10000);
buffer = append4(buffer, v1 % 10000);
}
else
{
const uint32_t a =
static_cast<uint32_t>(value / 10000000000000000); // 1 to 1844
value %= 10000000000000000;
buffer = append4_no_zeros(buffer, a);
const uint32_t v0 = static_cast<uint32_t>(value / 100000000);
const uint32_t v1 = static_cast<uint32_t>(value % 100000000);
buffer = append4(buffer, v0 / 10000);
buffer = append4(buffer, v0 % 10000);
buffer = append4(buffer, v1 / 10000);
buffer = append4(buffer, v1 % 10000);
}
return buffer;
}
} // namespace __itoa
_LIBCPP_END_NAMESPACE_STD
| 4,571 | 161 | jart/cosmopolitan | false |
cosmopolitan/third_party/libcxx/any | // -*- C++ -*-
// clang-format off
//===------------------------------ any -----------------------------------===//
//
// 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_ANY
#define _LIBCPP_ANY
/*
any synopsis
namespace std {
class bad_any_cast : public bad_cast
{
public:
virtual const char* what() const noexcept;
};
class any
{
public:
// 6.3.1 any construct/destruct
any() noexcept;
any(const any& other);
any(any&& other) noexcept;
template <class ValueType>
any(ValueType&& value);
~any();
// 6.3.2 any assignments
any& operator=(const any& rhs);
any& operator=(any&& rhs) noexcept;
template <class ValueType>
any& operator=(ValueType&& rhs);
// 6.3.3 any modifiers
template <class ValueType, class... Args>
decay_t<ValueType>& emplace(Args&&... args);
template <class ValueType, class U, class... Args>
decay_t<ValueType>& emplace(initializer_list<U>, Args&&...);
void reset() noexcept;
void swap(any& rhs) noexcept;
// 6.3.4 any observers
bool has_value() const noexcept;
const type_info& type() const noexcept;
};
// 6.4 Non-member functions
void swap(any& x, any& y) noexcept;
template <class T, class ...Args>
any make_any(Args&& ...args);
template <class T, class U, class ...Args>
any make_any(initializer_list<U>, Args&& ...args);
template<class ValueType>
ValueType any_cast(const any& operand);
template<class ValueType>
ValueType any_cast(any& operand);
template<class ValueType>
ValueType any_cast(any&& operand);
template<class ValueType>
const ValueType* any_cast(const any* operand) noexcept;
template<class ValueType>
ValueType* any_cast(any* operand) noexcept;
} // namespace std
*/
#include "third_party/libcxx/experimental/__config"
#include "third_party/libcxx/memory"
#include "third_party/libcxx/new"
#include "third_party/libcxx/typeinfo"
#include "third_party/libcxx/type_traits"
#include "third_party/libcxx/cstdlib"
#include "third_party/libcxx/version"
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
#pragma GCC system_header
#endif
namespace std {
class _LIBCPP_EXCEPTION_ABI _LIBCPP_AVAILABILITY_BAD_ANY_CAST bad_any_cast : public bad_cast
{
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_ANY_CAST
void __throw_bad_any_cast()
{
#ifndef _LIBCPP_NO_EXCEPTIONS
throw bad_any_cast();
#else
_VSTD::abort();
#endif
}
// Forward declarations
class _LIBCPP_TEMPLATE_VIS any;
template <class _ValueType>
_LIBCPP_INLINE_VISIBILITY
add_pointer_t<add_const_t<_ValueType>>
any_cast(any const *) _NOEXCEPT;
template <class _ValueType>
_LIBCPP_INLINE_VISIBILITY
add_pointer_t<_ValueType> any_cast(any *) _NOEXCEPT;
namespace __any_imp
{
using _Buffer = aligned_storage_t<3*sizeof(void*), alignment_of<void*>::value>;
template <class _Tp>
using _IsSmallObject = integral_constant<bool
, sizeof(_Tp) <= sizeof(_Buffer)
&& alignment_of<_Buffer>::value
% alignment_of<_Tp>::value == 0
&& is_nothrow_move_constructible<_Tp>::value
>;
enum class _Action {
_Destroy,
_Copy,
_Move,
_Get,
_TypeInfo
};
template <class _Tp> struct _SmallHandler;
template <class _Tp> struct _LargeHandler;
template <class _Tp>
struct _LIBCPP_TEMPLATE_VIS __unique_typeinfo { static constexpr int __id = 0; };
template <class _Tp> constexpr int __unique_typeinfo<_Tp>::__id;
template <class _Tp>
inline _LIBCPP_INLINE_VISIBILITY
constexpr const void* __get_fallback_typeid() {
return &__unique_typeinfo<decay_t<_Tp>>::__id;
}
template <class _Tp>
inline _LIBCPP_INLINE_VISIBILITY
bool __compare_typeid(type_info const* __id, const void* __fallback_id)
{
#if !defined(_LIBCPP_NO_RTTI)
if (__id && *__id == typeid(_Tp))
return true;
#endif
if (!__id && __fallback_id == __any_imp::__get_fallback_typeid<_Tp>())
return true;
return false;
}
template <class _Tp>
using _Handler = conditional_t<
_IsSmallObject<_Tp>::value, _SmallHandler<_Tp>, _LargeHandler<_Tp>>;
} // namespace __any_imp
class _LIBCPP_TEMPLATE_VIS any
{
public:
// construct/destruct
_LIBCPP_INLINE_VISIBILITY
constexpr any() _NOEXCEPT : __h(nullptr) {}
_LIBCPP_INLINE_VISIBILITY
any(any const & __other) : __h(nullptr)
{
if (__other.__h) __other.__call(_Action::_Copy, this);
}
_LIBCPP_INLINE_VISIBILITY
any(any && __other) _NOEXCEPT : __h(nullptr)
{
if (__other.__h) __other.__call(_Action::_Move, this);
}
template <
class _ValueType
, class _Tp = decay_t<_ValueType>
, class = enable_if_t<
!is_same<_Tp, any>::value &&
!__is_inplace_type<_ValueType>::value &&
is_copy_constructible<_Tp>::value>
>
_LIBCPP_INLINE_VISIBILITY
any(_ValueType && __value);
template <class _ValueType, class ..._Args,
class _Tp = decay_t<_ValueType>,
class = enable_if_t<
is_constructible<_Tp, _Args...>::value &&
is_copy_constructible<_Tp>::value
>
>
_LIBCPP_INLINE_VISIBILITY
explicit any(in_place_type_t<_ValueType>, _Args&&... __args);
template <class _ValueType, class _Up, class ..._Args,
class _Tp = decay_t<_ValueType>,
class = enable_if_t<
is_constructible<_Tp, initializer_list<_Up>&, _Args...>::value &&
is_copy_constructible<_Tp>::value>
>
_LIBCPP_INLINE_VISIBILITY
explicit any(in_place_type_t<_ValueType>, initializer_list<_Up>, _Args&&... __args);
_LIBCPP_INLINE_VISIBILITY
~any() { this->reset(); }
// assignments
_LIBCPP_INLINE_VISIBILITY
any & operator=(any const & __rhs) {
any(__rhs).swap(*this);
return *this;
}
_LIBCPP_INLINE_VISIBILITY
any & operator=(any && __rhs) _NOEXCEPT {
any(_VSTD::move(__rhs)).swap(*this);
return *this;
}
template <
class _ValueType
, class _Tp = decay_t<_ValueType>
, class = enable_if_t<
!is_same<_Tp, any>::value
&& is_copy_constructible<_Tp>::value>
>
_LIBCPP_INLINE_VISIBILITY
any & operator=(_ValueType && __rhs);
template <class _ValueType, class ..._Args,
class _Tp = decay_t<_ValueType>,
class = enable_if_t<
is_constructible<_Tp, _Args...>::value &&
is_copy_constructible<_Tp>::value>
>
_LIBCPP_INLINE_VISIBILITY
_Tp& emplace(_Args&&... args);
template <class _ValueType, class _Up, class ..._Args,
class _Tp = decay_t<_ValueType>,
class = enable_if_t<
is_constructible<_Tp, initializer_list<_Up>&, _Args...>::value &&
is_copy_constructible<_Tp>::value>
>
_LIBCPP_INLINE_VISIBILITY
_Tp& emplace(initializer_list<_Up>, _Args&&...);
// 6.3.3 any modifiers
_LIBCPP_INLINE_VISIBILITY
void reset() _NOEXCEPT { if (__h) this->__call(_Action::_Destroy); }
_LIBCPP_INLINE_VISIBILITY
void swap(any & __rhs) _NOEXCEPT;
// 6.3.4 any observers
_LIBCPP_INLINE_VISIBILITY
bool has_value() const _NOEXCEPT { return __h != nullptr; }
#if !defined(_LIBCPP_NO_RTTI)
_LIBCPP_INLINE_VISIBILITY
const type_info & type() const _NOEXCEPT {
if (__h) {
return *static_cast<type_info const *>(this->__call(_Action::_TypeInfo));
} else {
return typeid(void);
}
}
#endif
private:
typedef __any_imp::_Action _Action;
using _HandleFuncPtr = void* (*)(_Action, any const *, any *, const type_info *,
const void* __fallback_info);
union _Storage {
constexpr _Storage() : __ptr(nullptr) {}
void * __ptr;
__any_imp::_Buffer __buf;
};
_LIBCPP_INLINE_VISIBILITY
void * __call(_Action __a, any * __other = nullptr,
type_info const * __info = nullptr,
const void* __fallback_info = nullptr) const
{
return __h(__a, this, __other, __info, __fallback_info);
}
_LIBCPP_INLINE_VISIBILITY
void * __call(_Action __a, any * __other = nullptr,
type_info const * __info = nullptr,
const void* __fallback_info = nullptr)
{
return __h(__a, this, __other, __info, __fallback_info);
}
template <class>
friend struct __any_imp::_SmallHandler;
template <class>
friend struct __any_imp::_LargeHandler;
template <class _ValueType>
friend add_pointer_t<add_const_t<_ValueType>>
any_cast(any const *) _NOEXCEPT;
template <class _ValueType>
friend add_pointer_t<_ValueType>
any_cast(any *) _NOEXCEPT;
_HandleFuncPtr __h = nullptr;
_Storage __s;
};
namespace __any_imp
{
template <class _Tp>
struct _LIBCPP_TEMPLATE_VIS _SmallHandler
{
_LIBCPP_INLINE_VISIBILITY
static void* __handle(_Action __act, any const * __this, any * __other,
type_info const * __info, const void* __fallback_info)
{
switch (__act)
{
case _Action::_Destroy:
__destroy(const_cast<any &>(*__this));
return nullptr;
case _Action::_Copy:
__copy(*__this, *__other);
return nullptr;
case _Action::_Move:
__move(const_cast<any &>(*__this), *__other);
return nullptr;
case _Action::_Get:
return __get(const_cast<any &>(*__this), __info, __fallback_info);
case _Action::_TypeInfo:
return __type_info();
}
}
template <class ..._Args>
_LIBCPP_INLINE_VISIBILITY
static _Tp& __create(any & __dest, _Args&&... __args) {
_Tp* __ret = ::new (static_cast<void*>(&__dest.__s.__buf)) _Tp(_VSTD::forward<_Args>(__args)...);
__dest.__h = &_SmallHandler::__handle;
return *__ret;
}
private:
_LIBCPP_INLINE_VISIBILITY
static void __destroy(any & __this) {
_Tp & __value = *static_cast<_Tp *>(static_cast<void*>(&__this.__s.__buf));
__value.~_Tp();
__this.__h = nullptr;
}
_LIBCPP_INLINE_VISIBILITY
static void __copy(any const & __this, any & __dest) {
_SmallHandler::__create(__dest, *static_cast<_Tp const *>(
static_cast<void const *>(&__this.__s.__buf)));
}
_LIBCPP_INLINE_VISIBILITY
static void __move(any & __this, any & __dest) {
_SmallHandler::__create(__dest, _VSTD::move(
*static_cast<_Tp*>(static_cast<void*>(&__this.__s.__buf))));
__destroy(__this);
}
_LIBCPP_INLINE_VISIBILITY
static void* __get(any & __this,
type_info const * __info,
const void* __fallback_id)
{
if (__any_imp::__compare_typeid<_Tp>(__info, __fallback_id))
return static_cast<void*>(&__this.__s.__buf);
return nullptr;
}
_LIBCPP_INLINE_VISIBILITY
static void* __type_info()
{
#if !defined(_LIBCPP_NO_RTTI)
return const_cast<void*>(static_cast<void const *>(&typeid(_Tp)));
#else
return nullptr;
#endif
}
};
template <class _Tp>
struct _LIBCPP_TEMPLATE_VIS _LargeHandler
{
_LIBCPP_INLINE_VISIBILITY
static void* __handle(_Action __act, any const * __this,
any * __other, type_info const * __info,
void const* __fallback_info)
{
switch (__act)
{
case _Action::_Destroy:
__destroy(const_cast<any &>(*__this));
return nullptr;
case _Action::_Copy:
__copy(*__this, *__other);
return nullptr;
case _Action::_Move:
__move(const_cast<any &>(*__this), *__other);
return nullptr;
case _Action::_Get:
return __get(const_cast<any &>(*__this), __info, __fallback_info);
case _Action::_TypeInfo:
return __type_info();
}
}
template <class ..._Args>
_LIBCPP_INLINE_VISIBILITY
static _Tp& __create(any & __dest, _Args&&... __args) {
typedef allocator<_Tp> _Alloc;
typedef __allocator_destructor<_Alloc> _Dp;
_Alloc __a;
unique_ptr<_Tp, _Dp> __hold(__a.allocate(1), _Dp(__a, 1));
_Tp* __ret = ::new ((void*)__hold.get()) _Tp(_VSTD::forward<_Args>(__args)...);
__dest.__s.__ptr = __hold.release();
__dest.__h = &_LargeHandler::__handle;
return *__ret;
}
private:
_LIBCPP_INLINE_VISIBILITY
static void __destroy(any & __this){
delete static_cast<_Tp*>(__this.__s.__ptr);
__this.__h = nullptr;
}
_LIBCPP_INLINE_VISIBILITY
static void __copy(any const & __this, any & __dest) {
_LargeHandler::__create(__dest, *static_cast<_Tp const *>(__this.__s.__ptr));
}
_LIBCPP_INLINE_VISIBILITY
static void __move(any & __this, any & __dest) {
__dest.__s.__ptr = __this.__s.__ptr;
__dest.__h = &_LargeHandler::__handle;
__this.__h = nullptr;
}
_LIBCPP_INLINE_VISIBILITY
static void* __get(any & __this, type_info const * __info,
void const* __fallback_info)
{
if (__any_imp::__compare_typeid<_Tp>(__info, __fallback_info))
return static_cast<void*>(__this.__s.__ptr);
return nullptr;
}
_LIBCPP_INLINE_VISIBILITY
static void* __type_info()
{
#if !defined(_LIBCPP_NO_RTTI)
return const_cast<void*>(static_cast<void const *>(&typeid(_Tp)));
#else
return nullptr;
#endif
}
};
} // namespace __any_imp
template <class _ValueType, class _Tp, class>
any::any(_ValueType && __v) : __h(nullptr)
{
__any_imp::_Handler<_Tp>::__create(*this, _VSTD::forward<_ValueType>(__v));
}
template <class _ValueType, class ..._Args, class _Tp, class>
any::any(in_place_type_t<_ValueType>, _Args&&... __args) {
__any_imp::_Handler<_Tp>::__create(*this, _VSTD::forward<_Args>(__args)...);
}
template <class _ValueType, class _Up, class ..._Args, class _Tp, class>
any::any(in_place_type_t<_ValueType>, initializer_list<_Up> __il, _Args&&... __args) {
__any_imp::_Handler<_Tp>::__create(*this, __il, _VSTD::forward<_Args>(__args)...);
}
template <class _ValueType, class, class>
inline _LIBCPP_INLINE_VISIBILITY
any & any::operator=(_ValueType && __v)
{
any(_VSTD::forward<_ValueType>(__v)).swap(*this);
return *this;
}
template <class _ValueType, class ..._Args, class _Tp, class>
inline _LIBCPP_INLINE_VISIBILITY
_Tp& any::emplace(_Args&&... __args) {
reset();
return __any_imp::_Handler<_Tp>::__create(*this, _VSTD::forward<_Args>(__args)...);
}
template <class _ValueType, class _Up, class ..._Args, class _Tp, class>
inline _LIBCPP_INLINE_VISIBILITY
_Tp& any::emplace(initializer_list<_Up> __il, _Args&&... __args) {
reset();
return __any_imp::_Handler<_Tp>::__create(*this, __il, _VSTD::forward<_Args>(__args)...);
}
inline _LIBCPP_INLINE_VISIBILITY
void any::swap(any & __rhs) _NOEXCEPT
{
if (this == &__rhs)
return;
if (__h && __rhs.__h) {
any __tmp;
__rhs.__call(_Action::_Move, &__tmp);
this->__call(_Action::_Move, &__rhs);
__tmp.__call(_Action::_Move, this);
}
else if (__h) {
this->__call(_Action::_Move, &__rhs);
}
else if (__rhs.__h) {
__rhs.__call(_Action::_Move, this);
}
}
// 6.4 Non-member functions
inline _LIBCPP_INLINE_VISIBILITY
void swap(any & __lhs, any & __rhs) _NOEXCEPT
{
__lhs.swap(__rhs);
}
template <class _Tp, class ..._Args>
inline _LIBCPP_INLINE_VISIBILITY
any make_any(_Args&&... __args) {
return any(in_place_type<_Tp>, _VSTD::forward<_Args>(__args)...);
}
template <class _Tp, class _Up, class ..._Args>
inline _LIBCPP_INLINE_VISIBILITY
any make_any(initializer_list<_Up> __il, _Args&&... __args) {
return any(in_place_type<_Tp>, __il, _VSTD::forward<_Args>(__args)...);
}
template <class _ValueType>
inline _LIBCPP_INLINE_VISIBILITY
_LIBCPP_AVAILABILITY_THROW_BAD_ANY_CAST
_ValueType any_cast(any const & __v)
{
using _RawValueType = __uncvref_t<_ValueType>;
static_assert(is_constructible<_ValueType, _RawValueType const &>::value,
"ValueType is required to be a const lvalue reference "
"or a CopyConstructible type");
auto __tmp = _VSTD::any_cast<add_const_t<_RawValueType>>(&__v);
if (__tmp == nullptr)
__throw_bad_any_cast();
return static_cast<_ValueType>(*__tmp);
}
template <class _ValueType>
inline _LIBCPP_INLINE_VISIBILITY
_LIBCPP_AVAILABILITY_THROW_BAD_ANY_CAST
_ValueType any_cast(any & __v)
{
using _RawValueType = __uncvref_t<_ValueType>;
static_assert(is_constructible<_ValueType, _RawValueType &>::value,
"ValueType is required to be an lvalue reference "
"or a CopyConstructible type");
auto __tmp = _VSTD::any_cast<_RawValueType>(&__v);
if (__tmp == nullptr)
__throw_bad_any_cast();
return static_cast<_ValueType>(*__tmp);
}
template <class _ValueType>
inline _LIBCPP_INLINE_VISIBILITY
_LIBCPP_AVAILABILITY_THROW_BAD_ANY_CAST
_ValueType any_cast(any && __v)
{
using _RawValueType = __uncvref_t<_ValueType>;
static_assert(is_constructible<_ValueType, _RawValueType>::value,
"ValueType is required to be an rvalue reference "
"or a CopyConstructible type");
auto __tmp = _VSTD::any_cast<_RawValueType>(&__v);
if (__tmp == nullptr)
__throw_bad_any_cast();
return static_cast<_ValueType>(_VSTD::move(*__tmp));
}
template <class _ValueType>
inline _LIBCPP_INLINE_VISIBILITY
add_pointer_t<add_const_t<_ValueType>>
any_cast(any const * __any) _NOEXCEPT
{
static_assert(!is_reference<_ValueType>::value,
"_ValueType may not be a reference.");
return _VSTD::any_cast<_ValueType>(const_cast<any *>(__any));
}
template <class _RetType>
inline _LIBCPP_INLINE_VISIBILITY
_RetType __pointer_or_func_cast(void* __p, /*IsFunction*/false_type) noexcept {
return static_cast<_RetType>(__p);
}
template <class _RetType>
inline _LIBCPP_INLINE_VISIBILITY
_RetType __pointer_or_func_cast(void*, /*IsFunction*/true_type) noexcept {
return nullptr;
}
template <class _ValueType>
add_pointer_t<_ValueType>
any_cast(any * __any) _NOEXCEPT
{
using __any_imp::_Action;
static_assert(!is_reference<_ValueType>::value,
"_ValueType may not be a reference.");
typedef typename add_pointer<_ValueType>::type _ReturnType;
if (__any && __any->__h) {
void *__p = __any->__call(_Action::_Get, nullptr,
#if !defined(_LIBCPP_NO_RTTI)
&typeid(_ValueType),
#else
nullptr,
#endif
__any_imp::__get_fallback_typeid<_ValueType>());
return _VSTD::__pointer_or_func_cast<_ReturnType>(
__p, is_function<_ValueType>{});
}
return nullptr;
}
#endif // _LIBCPP_STD_VER > 14
_LIBCPP_END_NAMESPACE_STD
#endif // _LIBCPP_ANY
| 19,184 | 673 | jart/cosmopolitan | false |
cosmopolitan/third_party/libcxx/complex | // -*- C++ -*-
// clang-format off
//===--------------------------- complex ----------------------------------===//
//
// 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_COMPLEX
#define _LIBCPP_COMPLEX
/*
complex synopsis
namespace std
{
template<class T>
class complex
{
public:
typedef T value_type;
complex(const T& re = T(), const T& im = T()); // constexpr in C++14
complex(const complex&); // constexpr in C++14
template<class X> complex(const complex<X>&); // constexpr in C++14
T real() const; // constexpr in C++14
T imag() const; // constexpr in C++14
void real(T);
void imag(T);
complex<T>& operator= (const T&);
complex<T>& operator+=(const T&);
complex<T>& operator-=(const T&);
complex<T>& operator*=(const T&);
complex<T>& operator/=(const T&);
complex& operator=(const complex&);
template<class X> complex<T>& operator= (const complex<X>&);
template<class X> complex<T>& operator+=(const complex<X>&);
template<class X> complex<T>& operator-=(const complex<X>&);
template<class X> complex<T>& operator*=(const complex<X>&);
template<class X> complex<T>& operator/=(const complex<X>&);
};
template<>
class complex<float>
{
public:
typedef float value_type;
constexpr complex(float re = 0.0f, float im = 0.0f);
explicit constexpr complex(const complex<double>&);
explicit constexpr complex(const complex<long double>&);
constexpr float real() const;
void real(float);
constexpr float imag() const;
void imag(float);
complex<float>& operator= (float);
complex<float>& operator+=(float);
complex<float>& operator-=(float);
complex<float>& operator*=(float);
complex<float>& operator/=(float);
complex<float>& operator=(const complex<float>&);
template<class X> complex<float>& operator= (const complex<X>&);
template<class X> complex<float>& operator+=(const complex<X>&);
template<class X> complex<float>& operator-=(const complex<X>&);
template<class X> complex<float>& operator*=(const complex<X>&);
template<class X> complex<float>& operator/=(const complex<X>&);
};
template<>
class complex<double>
{
public:
typedef double value_type;
constexpr complex(double re = 0.0, double im = 0.0);
constexpr complex(const complex<float>&);
explicit constexpr complex(const complex<long double>&);
constexpr double real() const;
void real(double);
constexpr double imag() const;
void imag(double);
complex<double>& operator= (double);
complex<double>& operator+=(double);
complex<double>& operator-=(double);
complex<double>& operator*=(double);
complex<double>& operator/=(double);
complex<double>& operator=(const complex<double>&);
template<class X> complex<double>& operator= (const complex<X>&);
template<class X> complex<double>& operator+=(const complex<X>&);
template<class X> complex<double>& operator-=(const complex<X>&);
template<class X> complex<double>& operator*=(const complex<X>&);
template<class X> complex<double>& operator/=(const complex<X>&);
};
template<>
class complex<long double>
{
public:
typedef long double value_type;
constexpr complex(long double re = 0.0L, long double im = 0.0L);
constexpr complex(const complex<float>&);
constexpr complex(const complex<double>&);
constexpr long double real() const;
void real(long double);
constexpr long double imag() const;
void imag(long double);
complex<long double>& operator=(const complex<long double>&);
complex<long double>& operator= (long double);
complex<long double>& operator+=(long double);
complex<long double>& operator-=(long double);
complex<long double>& operator*=(long double);
complex<long double>& operator/=(long double);
template<class X> complex<long double>& operator= (const complex<X>&);
template<class X> complex<long double>& operator+=(const complex<X>&);
template<class X> complex<long double>& operator-=(const complex<X>&);
template<class X> complex<long double>& operator*=(const complex<X>&);
template<class X> complex<long double>& operator/=(const complex<X>&);
};
// 26.3.6 operators:
template<class T> complex<T> operator+(const complex<T>&, const complex<T>&);
template<class T> complex<T> operator+(const complex<T>&, const T&);
template<class T> complex<T> operator+(const T&, const complex<T>&);
template<class T> complex<T> operator-(const complex<T>&, const complex<T>&);
template<class T> complex<T> operator-(const complex<T>&, const T&);
template<class T> complex<T> operator-(const T&, const complex<T>&);
template<class T> complex<T> operator*(const complex<T>&, const complex<T>&);
template<class T> complex<T> operator*(const complex<T>&, const T&);
template<class T> complex<T> operator*(const T&, const complex<T>&);
template<class T> complex<T> operator/(const complex<T>&, const complex<T>&);
template<class T> complex<T> operator/(const complex<T>&, const T&);
template<class T> complex<T> operator/(const T&, const complex<T>&);
template<class T> complex<T> operator+(const complex<T>&);
template<class T> complex<T> operator-(const complex<T>&);
template<class T> bool operator==(const complex<T>&, const complex<T>&); // constexpr in C++14
template<class T> bool operator==(const complex<T>&, const T&); // constexpr in C++14
template<class T> bool operator==(const T&, const complex<T>&); // constexpr in C++14
template<class T> bool operator!=(const complex<T>&, const complex<T>&); // constexpr in C++14
template<class T> bool operator!=(const complex<T>&, const T&); // constexpr in C++14
template<class T> bool operator!=(const T&, const complex<T>&); // constexpr in C++14
template<class T, class charT, class traits>
basic_istream<charT, traits>&
operator>>(basic_istream<charT, traits>&, complex<T>&);
template<class T, class charT, class traits>
basic_ostream<charT, traits>&
operator<<(basic_ostream<charT, traits>&, const complex<T>&);
// 26.3.7 values:
template<class T> T real(const complex<T>&); // constexpr in C++14
long double real(long double); // constexpr in C++14
double real(double); // constexpr in C++14
template<Integral T> double real(T); // constexpr in C++14
float real(float); // constexpr in C++14
template<class T> T imag(const complex<T>&); // constexpr in C++14
long double imag(long double); // constexpr in C++14
double imag(double); // constexpr in C++14
template<Integral T> double imag(T); // constexpr in C++14
float imag(float); // constexpr in C++14
template<class T> T abs(const complex<T>&);
template<class T> T arg(const complex<T>&);
long double arg(long double);
double arg(double);
template<Integral T> double arg(T);
float arg(float);
template<class T> T norm(const complex<T>&);
long double norm(long double);
double norm(double);
template<Integral T> double norm(T);
float norm(float);
template<class T> complex<T> conj(const complex<T>&);
complex<long double> conj(long double);
complex<double> conj(double);
template<Integral T> complex<double> conj(T);
complex<float> conj(float);
template<class T> complex<T> proj(const complex<T>&);
complex<long double> proj(long double);
complex<double> proj(double);
template<Integral T> complex<double> proj(T);
complex<float> proj(float);
template<class T> complex<T> polar(const T&, const T& = T());
// 26.3.8 transcendentals:
template<class T> complex<T> acos(const complex<T>&);
template<class T> complex<T> asin(const complex<T>&);
template<class T> complex<T> atan(const complex<T>&);
template<class T> complex<T> acosh(const complex<T>&);
template<class T> complex<T> asinh(const complex<T>&);
template<class T> complex<T> atanh(const complex<T>&);
template<class T> complex<T> cos (const complex<T>&);
template<class T> complex<T> cosh (const complex<T>&);
template<class T> complex<T> exp (const complex<T>&);
template<class T> complex<T> log (const complex<T>&);
template<class T> complex<T> log10(const complex<T>&);
template<class T> complex<T> pow(const complex<T>&, const T&);
template<class T> complex<T> pow(const complex<T>&, const complex<T>&);
template<class T> complex<T> pow(const T&, const complex<T>&);
template<class T> complex<T> sin (const complex<T>&);
template<class T> complex<T> sinh (const complex<T>&);
template<class T> complex<T> sqrt (const complex<T>&);
template<class T> complex<T> tan (const complex<T>&);
template<class T> complex<T> tanh (const complex<T>&);
template<class T, class charT, class traits>
basic_istream<charT, traits>&
operator>>(basic_istream<charT, traits>& is, complex<T>& x);
template<class T, class charT, class traits>
basic_ostream<charT, traits>&
operator<<(basic_ostream<charT, traits>& o, const complex<T>& x);
} // std
*/
#include "third_party/libcxx/__config"
#include "third_party/libcxx/type_traits"
#include "third_party/libcxx/stdexcept"
#include "third_party/libcxx/cmath"
#include "third_party/libcxx/sstream"
#include "third_party/libcxx/version"
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
#pragma GCC system_header
#endif
_LIBCPP_BEGIN_NAMESPACE_STD
template<class _Tp> class _LIBCPP_TEMPLATE_VIS complex;
template<class _Tp> complex<_Tp> operator*(const complex<_Tp>& __z, const complex<_Tp>& __w);
template<class _Tp> complex<_Tp> operator/(const complex<_Tp>& __x, const complex<_Tp>& __y);
template<class _Tp>
class _LIBCPP_TEMPLATE_VIS complex
{
public:
typedef _Tp value_type;
private:
value_type __re_;
value_type __im_;
public:
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
complex(const value_type& __re = value_type(), const value_type& __im = value_type())
: __re_(__re), __im_(__im) {}
template<class _Xp> _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
complex(const complex<_Xp>& __c)
: __re_(__c.real()), __im_(__c.imag()) {}
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 value_type real() const {return __re_;}
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 value_type imag() const {return __im_;}
_LIBCPP_INLINE_VISIBILITY void real(value_type __re) {__re_ = __re;}
_LIBCPP_INLINE_VISIBILITY void imag(value_type __im) {__im_ = __im;}
_LIBCPP_INLINE_VISIBILITY complex& operator= (const value_type& __re)
{__re_ = __re; __im_ = value_type(); return *this;}
_LIBCPP_INLINE_VISIBILITY complex& operator+=(const value_type& __re) {__re_ += __re; return *this;}
_LIBCPP_INLINE_VISIBILITY complex& operator-=(const value_type& __re) {__re_ -= __re; return *this;}
_LIBCPP_INLINE_VISIBILITY complex& operator*=(const value_type& __re) {__re_ *= __re; __im_ *= __re; return *this;}
_LIBCPP_INLINE_VISIBILITY complex& operator/=(const value_type& __re) {__re_ /= __re; __im_ /= __re; return *this;}
template<class _Xp> _LIBCPP_INLINE_VISIBILITY complex& operator= (const complex<_Xp>& __c)
{
__re_ = __c.real();
__im_ = __c.imag();
return *this;
}
template<class _Xp> _LIBCPP_INLINE_VISIBILITY complex& operator+=(const complex<_Xp>& __c)
{
__re_ += __c.real();
__im_ += __c.imag();
return *this;
}
template<class _Xp> _LIBCPP_INLINE_VISIBILITY complex& operator-=(const complex<_Xp>& __c)
{
__re_ -= __c.real();
__im_ -= __c.imag();
return *this;
}
template<class _Xp> _LIBCPP_INLINE_VISIBILITY complex& operator*=(const complex<_Xp>& __c)
{
*this = *this * complex(__c.real(), __c.imag());
return *this;
}
template<class _Xp> _LIBCPP_INLINE_VISIBILITY complex& operator/=(const complex<_Xp>& __c)
{
*this = *this / complex(__c.real(), __c.imag());
return *this;
}
};
template<> class _LIBCPP_TEMPLATE_VIS complex<double>;
template<> class _LIBCPP_TEMPLATE_VIS complex<long double>;
template<>
class _LIBCPP_TEMPLATE_VIS complex<float>
{
float __re_;
float __im_;
public:
typedef float value_type;
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR complex(float __re = 0.0f, float __im = 0.0f)
: __re_(__re), __im_(__im) {}
_LIBCPP_INLINE_VISIBILITY
explicit _LIBCPP_CONSTEXPR complex(const complex<double>& __c);
_LIBCPP_INLINE_VISIBILITY
explicit _LIBCPP_CONSTEXPR complex(const complex<long double>& __c);
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR float real() const {return __re_;}
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR float imag() const {return __im_;}
_LIBCPP_INLINE_VISIBILITY void real(value_type __re) {__re_ = __re;}
_LIBCPP_INLINE_VISIBILITY void imag(value_type __im) {__im_ = __im;}
_LIBCPP_INLINE_VISIBILITY complex& operator= (float __re)
{__re_ = __re; __im_ = value_type(); return *this;}
_LIBCPP_INLINE_VISIBILITY complex& operator+=(float __re) {__re_ += __re; return *this;}
_LIBCPP_INLINE_VISIBILITY complex& operator-=(float __re) {__re_ -= __re; return *this;}
_LIBCPP_INLINE_VISIBILITY complex& operator*=(float __re) {__re_ *= __re; __im_ *= __re; return *this;}
_LIBCPP_INLINE_VISIBILITY complex& operator/=(float __re) {__re_ /= __re; __im_ /= __re; return *this;}
template<class _Xp> _LIBCPP_INLINE_VISIBILITY complex& operator= (const complex<_Xp>& __c)
{
__re_ = __c.real();
__im_ = __c.imag();
return *this;
}
template<class _Xp> _LIBCPP_INLINE_VISIBILITY complex& operator+=(const complex<_Xp>& __c)
{
__re_ += __c.real();
__im_ += __c.imag();
return *this;
}
template<class _Xp> _LIBCPP_INLINE_VISIBILITY complex& operator-=(const complex<_Xp>& __c)
{
__re_ -= __c.real();
__im_ -= __c.imag();
return *this;
}
template<class _Xp> _LIBCPP_INLINE_VISIBILITY complex& operator*=(const complex<_Xp>& __c)
{
*this = *this * complex(__c.real(), __c.imag());
return *this;
}
template<class _Xp> _LIBCPP_INLINE_VISIBILITY complex& operator/=(const complex<_Xp>& __c)
{
*this = *this / complex(__c.real(), __c.imag());
return *this;
}
};
template<>
class _LIBCPP_TEMPLATE_VIS complex<double>
{
double __re_;
double __im_;
public:
typedef double value_type;
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR complex(double __re = 0.0, double __im = 0.0)
: __re_(__re), __im_(__im) {}
_LIBCPP_INLINE_VISIBILITY
_LIBCPP_CONSTEXPR complex(const complex<float>& __c);
_LIBCPP_INLINE_VISIBILITY
explicit _LIBCPP_CONSTEXPR complex(const complex<long double>& __c);
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR double real() const {return __re_;}
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR double imag() const {return __im_;}
_LIBCPP_INLINE_VISIBILITY void real(value_type __re) {__re_ = __re;}
_LIBCPP_INLINE_VISIBILITY void imag(value_type __im) {__im_ = __im;}
_LIBCPP_INLINE_VISIBILITY complex& operator= (double __re)
{__re_ = __re; __im_ = value_type(); return *this;}
_LIBCPP_INLINE_VISIBILITY complex& operator+=(double __re) {__re_ += __re; return *this;}
_LIBCPP_INLINE_VISIBILITY complex& operator-=(double __re) {__re_ -= __re; return *this;}
_LIBCPP_INLINE_VISIBILITY complex& operator*=(double __re) {__re_ *= __re; __im_ *= __re; return *this;}
_LIBCPP_INLINE_VISIBILITY complex& operator/=(double __re) {__re_ /= __re; __im_ /= __re; return *this;}
template<class _Xp> _LIBCPP_INLINE_VISIBILITY complex& operator= (const complex<_Xp>& __c)
{
__re_ = __c.real();
__im_ = __c.imag();
return *this;
}
template<class _Xp> _LIBCPP_INLINE_VISIBILITY complex& operator+=(const complex<_Xp>& __c)
{
__re_ += __c.real();
__im_ += __c.imag();
return *this;
}
template<class _Xp> _LIBCPP_INLINE_VISIBILITY complex& operator-=(const complex<_Xp>& __c)
{
__re_ -= __c.real();
__im_ -= __c.imag();
return *this;
}
template<class _Xp> _LIBCPP_INLINE_VISIBILITY complex& operator*=(const complex<_Xp>& __c)
{
*this = *this * complex(__c.real(), __c.imag());
return *this;
}
template<class _Xp> _LIBCPP_INLINE_VISIBILITY complex& operator/=(const complex<_Xp>& __c)
{
*this = *this / complex(__c.real(), __c.imag());
return *this;
}
};
template<>
class _LIBCPP_TEMPLATE_VIS complex<long double>
{
long double __re_;
long double __im_;
public:
typedef long double value_type;
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR complex(long double __re = 0.0L, long double __im = 0.0L)
: __re_(__re), __im_(__im) {}
_LIBCPP_INLINE_VISIBILITY
_LIBCPP_CONSTEXPR complex(const complex<float>& __c);
_LIBCPP_INLINE_VISIBILITY
_LIBCPP_CONSTEXPR complex(const complex<double>& __c);
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR long double real() const {return __re_;}
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR long double imag() const {return __im_;}
_LIBCPP_INLINE_VISIBILITY void real(value_type __re) {__re_ = __re;}
_LIBCPP_INLINE_VISIBILITY void imag(value_type __im) {__im_ = __im;}
_LIBCPP_INLINE_VISIBILITY complex& operator= (long double __re)
{__re_ = __re; __im_ = value_type(); return *this;}
_LIBCPP_INLINE_VISIBILITY complex& operator+=(long double __re) {__re_ += __re; return *this;}
_LIBCPP_INLINE_VISIBILITY complex& operator-=(long double __re) {__re_ -= __re; return *this;}
_LIBCPP_INLINE_VISIBILITY complex& operator*=(long double __re) {__re_ *= __re; __im_ *= __re; return *this;}
_LIBCPP_INLINE_VISIBILITY complex& operator/=(long double __re) {__re_ /= __re; __im_ /= __re; return *this;}
template<class _Xp> _LIBCPP_INLINE_VISIBILITY complex& operator= (const complex<_Xp>& __c)
{
__re_ = __c.real();
__im_ = __c.imag();
return *this;
}
template<class _Xp> _LIBCPP_INLINE_VISIBILITY complex& operator+=(const complex<_Xp>& __c)
{
__re_ += __c.real();
__im_ += __c.imag();
return *this;
}
template<class _Xp> _LIBCPP_INLINE_VISIBILITY complex& operator-=(const complex<_Xp>& __c)
{
__re_ -= __c.real();
__im_ -= __c.imag();
return *this;
}
template<class _Xp> _LIBCPP_INLINE_VISIBILITY complex& operator*=(const complex<_Xp>& __c)
{
*this = *this * complex(__c.real(), __c.imag());
return *this;
}
template<class _Xp> _LIBCPP_INLINE_VISIBILITY complex& operator/=(const complex<_Xp>& __c)
{
*this = *this / complex(__c.real(), __c.imag());
return *this;
}
};
inline
_LIBCPP_CONSTEXPR
complex<float>::complex(const complex<double>& __c)
: __re_(__c.real()), __im_(__c.imag()) {}
inline
_LIBCPP_CONSTEXPR
complex<float>::complex(const complex<long double>& __c)
: __re_(__c.real()), __im_(__c.imag()) {}
inline
_LIBCPP_CONSTEXPR
complex<double>::complex(const complex<float>& __c)
: __re_(__c.real()), __im_(__c.imag()) {}
inline
_LIBCPP_CONSTEXPR
complex<double>::complex(const complex<long double>& __c)
: __re_(__c.real()), __im_(__c.imag()) {}
inline
_LIBCPP_CONSTEXPR
complex<long double>::complex(const complex<float>& __c)
: __re_(__c.real()), __im_(__c.imag()) {}
inline
_LIBCPP_CONSTEXPR
complex<long double>::complex(const complex<double>& __c)
: __re_(__c.real()), __im_(__c.imag()) {}
// 26.3.6 operators:
template<class _Tp>
inline _LIBCPP_INLINE_VISIBILITY
complex<_Tp>
operator+(const complex<_Tp>& __x, const complex<_Tp>& __y)
{
complex<_Tp> __t(__x);
__t += __y;
return __t;
}
template<class _Tp>
inline _LIBCPP_INLINE_VISIBILITY
complex<_Tp>
operator+(const complex<_Tp>& __x, const _Tp& __y)
{
complex<_Tp> __t(__x);
__t += __y;
return __t;
}
template<class _Tp>
inline _LIBCPP_INLINE_VISIBILITY
complex<_Tp>
operator+(const _Tp& __x, const complex<_Tp>& __y)
{
complex<_Tp> __t(__y);
__t += __x;
return __t;
}
template<class _Tp>
inline _LIBCPP_INLINE_VISIBILITY
complex<_Tp>
operator-(const complex<_Tp>& __x, const complex<_Tp>& __y)
{
complex<_Tp> __t(__x);
__t -= __y;
return __t;
}
template<class _Tp>
inline _LIBCPP_INLINE_VISIBILITY
complex<_Tp>
operator-(const complex<_Tp>& __x, const _Tp& __y)
{
complex<_Tp> __t(__x);
__t -= __y;
return __t;
}
template<class _Tp>
inline _LIBCPP_INLINE_VISIBILITY
complex<_Tp>
operator-(const _Tp& __x, const complex<_Tp>& __y)
{
complex<_Tp> __t(-__y);
__t += __x;
return __t;
}
template<class _Tp>
complex<_Tp>
operator*(const complex<_Tp>& __z, const complex<_Tp>& __w)
{
_Tp __a = __z.real();
_Tp __b = __z.imag();
_Tp __c = __w.real();
_Tp __d = __w.imag();
_Tp __ac = __a * __c;
_Tp __bd = __b * __d;
_Tp __ad = __a * __d;
_Tp __bc = __b * __c;
_Tp __x = __ac - __bd;
_Tp __y = __ad + __bc;
if (__libcpp_isnan_or_builtin(__x) && __libcpp_isnan_or_builtin(__y))
{
bool __recalc = false;
if (__libcpp_isinf_or_builtin(__a) || __libcpp_isinf_or_builtin(__b))
{
__a = copysign(__libcpp_isinf_or_builtin(__a) ? _Tp(1) : _Tp(0), __a);
__b = copysign(__libcpp_isinf_or_builtin(__b) ? _Tp(1) : _Tp(0), __b);
if (__libcpp_isnan_or_builtin(__c))
__c = copysign(_Tp(0), __c);
if (__libcpp_isnan_or_builtin(__d))
__d = copysign(_Tp(0), __d);
__recalc = true;
}
if (__libcpp_isinf_or_builtin(__c) || __libcpp_isinf_or_builtin(__d))
{
__c = copysign(__libcpp_isinf_or_builtin(__c) ? _Tp(1) : _Tp(0), __c);
__d = copysign(__libcpp_isinf_or_builtin(__d) ? _Tp(1) : _Tp(0), __d);
if (__libcpp_isnan_or_builtin(__a))
__a = copysign(_Tp(0), __a);
if (__libcpp_isnan_or_builtin(__b))
__b = copysign(_Tp(0), __b);
__recalc = true;
}
if (!__recalc && (__libcpp_isinf_or_builtin(__ac) || __libcpp_isinf_or_builtin(__bd) ||
__libcpp_isinf_or_builtin(__ad) || __libcpp_isinf_or_builtin(__bc)))
{
if (__libcpp_isnan_or_builtin(__a))
__a = copysign(_Tp(0), __a);
if (__libcpp_isnan_or_builtin(__b))
__b = copysign(_Tp(0), __b);
if (__libcpp_isnan_or_builtin(__c))
__c = copysign(_Tp(0), __c);
if (__libcpp_isnan_or_builtin(__d))
__d = copysign(_Tp(0), __d);
__recalc = true;
}
if (__recalc)
{
__x = _Tp(INFINITY) * (__a * __c - __b * __d);
__y = _Tp(INFINITY) * (__a * __d + __b * __c);
}
}
return complex<_Tp>(__x, __y);
}
template<class _Tp>
inline _LIBCPP_INLINE_VISIBILITY
complex<_Tp>
operator*(const complex<_Tp>& __x, const _Tp& __y)
{
complex<_Tp> __t(__x);
__t *= __y;
return __t;
}
template<class _Tp>
inline _LIBCPP_INLINE_VISIBILITY
complex<_Tp>
operator*(const _Tp& __x, const complex<_Tp>& __y)
{
complex<_Tp> __t(__y);
__t *= __x;
return __t;
}
template<class _Tp>
complex<_Tp>
operator/(const complex<_Tp>& __z, const complex<_Tp>& __w)
{
int __ilogbw = 0;
_Tp __a = __z.real();
_Tp __b = __z.imag();
_Tp __c = __w.real();
_Tp __d = __w.imag();
_Tp __logbw = logb(fmax(fabs(__c), fabs(__d)));
if (__libcpp_isfinite_or_builtin(__logbw))
{
__ilogbw = static_cast<int>(__logbw);
__c = scalbn(__c, -__ilogbw);
__d = scalbn(__d, -__ilogbw);
}
_Tp __denom = __c * __c + __d * __d;
_Tp __x = scalbn((__a * __c + __b * __d) / __denom, -__ilogbw);
_Tp __y = scalbn((__b * __c - __a * __d) / __denom, -__ilogbw);
if (__libcpp_isnan_or_builtin(__x) && __libcpp_isnan_or_builtin(__y))
{
if ((__denom == _Tp(0)) && (!__libcpp_isnan_or_builtin(__a) || !__libcpp_isnan_or_builtin(__b)))
{
__x = copysign(_Tp(INFINITY), __c) * __a;
__y = copysign(_Tp(INFINITY), __c) * __b;
}
else if ((__libcpp_isinf_or_builtin(__a) || __libcpp_isinf_or_builtin(__b)) && __libcpp_isfinite_or_builtin(__c) && __libcpp_isfinite_or_builtin(__d))
{
__a = copysign(__libcpp_isinf_or_builtin(__a) ? _Tp(1) : _Tp(0), __a);
__b = copysign(__libcpp_isinf_or_builtin(__b) ? _Tp(1) : _Tp(0), __b);
__x = _Tp(INFINITY) * (__a * __c + __b * __d);
__y = _Tp(INFINITY) * (__b * __c - __a * __d);
}
else if (__libcpp_isinf_or_builtin(__logbw) && __logbw > _Tp(0) && __libcpp_isfinite_or_builtin(__a) && __libcpp_isfinite_or_builtin(__b))
{
__c = copysign(__libcpp_isinf_or_builtin(__c) ? _Tp(1) : _Tp(0), __c);
__d = copysign(__libcpp_isinf_or_builtin(__d) ? _Tp(1) : _Tp(0), __d);
__x = _Tp(0) * (__a * __c + __b * __d);
__y = _Tp(0) * (__b * __c - __a * __d);
}
}
return complex<_Tp>(__x, __y);
}
template<class _Tp>
inline _LIBCPP_INLINE_VISIBILITY
complex<_Tp>
operator/(const complex<_Tp>& __x, const _Tp& __y)
{
return complex<_Tp>(__x.real() / __y, __x.imag() / __y);
}
template<class _Tp>
inline _LIBCPP_INLINE_VISIBILITY
complex<_Tp>
operator/(const _Tp& __x, const complex<_Tp>& __y)
{
complex<_Tp> __t(__x);
__t /= __y;
return __t;
}
template<class _Tp>
inline _LIBCPP_INLINE_VISIBILITY
complex<_Tp>
operator+(const complex<_Tp>& __x)
{
return __x;
}
template<class _Tp>
inline _LIBCPP_INLINE_VISIBILITY
complex<_Tp>
operator-(const complex<_Tp>& __x)
{
return complex<_Tp>(-__x.real(), -__x.imag());
}
template<class _Tp>
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
bool
operator==(const complex<_Tp>& __x, const complex<_Tp>& __y)
{
return __x.real() == __y.real() && __x.imag() == __y.imag();
}
template<class _Tp>
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
bool
operator==(const complex<_Tp>& __x, const _Tp& __y)
{
return __x.real() == __y && __x.imag() == 0;
}
template<class _Tp>
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
bool
operator==(const _Tp& __x, const complex<_Tp>& __y)
{
return __x == __y.real() && 0 == __y.imag();
}
template<class _Tp>
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
bool
operator!=(const complex<_Tp>& __x, const complex<_Tp>& __y)
{
return !(__x == __y);
}
template<class _Tp>
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
bool
operator!=(const complex<_Tp>& __x, const _Tp& __y)
{
return !(__x == __y);
}
template<class _Tp>
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
bool
operator!=(const _Tp& __x, const complex<_Tp>& __y)
{
return !(__x == __y);
}
// 26.3.7 values:
template <class _Tp, bool = is_integral<_Tp>::value,
bool = is_floating_point<_Tp>::value
>
struct __libcpp_complex_overload_traits {};
// Integral Types
template <class _Tp>
struct __libcpp_complex_overload_traits<_Tp, true, false>
{
typedef double _ValueType;
typedef complex<double> _ComplexType;
};
// Floating point types
template <class _Tp>
struct __libcpp_complex_overload_traits<_Tp, false, true>
{
typedef _Tp _ValueType;
typedef complex<_Tp> _ComplexType;
};
// real
template<class _Tp>
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
_Tp
real(const complex<_Tp>& __c)
{
return __c.real();
}
template <class _Tp>
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
typename __libcpp_complex_overload_traits<_Tp>::_ValueType
real(_Tp __re)
{
return __re;
}
// imag
template<class _Tp>
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
_Tp
imag(const complex<_Tp>& __c)
{
return __c.imag();
}
template <class _Tp>
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
typename __libcpp_complex_overload_traits<_Tp>::_ValueType
imag(_Tp)
{
return 0;
}
// abs
template<class _Tp>
inline _LIBCPP_INLINE_VISIBILITY
_Tp
abs(const complex<_Tp>& __c)
{
return hypot(__c.real(), __c.imag());
}
// arg
template<class _Tp>
inline _LIBCPP_INLINE_VISIBILITY
_Tp
arg(const complex<_Tp>& __c)
{
return atan2(__c.imag(), __c.real());
}
template <class _Tp>
inline _LIBCPP_INLINE_VISIBILITY
typename enable_if<
is_same<_Tp, long double>::value,
long double
>::type
arg(_Tp __re)
{
return atan2l(0.L, __re);
}
template<class _Tp>
inline _LIBCPP_INLINE_VISIBILITY
typename enable_if
<
is_integral<_Tp>::value || is_same<_Tp, double>::value,
double
>::type
arg(_Tp __re)
{
return atan2(0., __re);
}
template <class _Tp>
inline _LIBCPP_INLINE_VISIBILITY
typename enable_if<
is_same<_Tp, float>::value,
float
>::type
arg(_Tp __re)
{
return atan2f(0.F, __re);
}
// norm
template<class _Tp>
inline _LIBCPP_INLINE_VISIBILITY
_Tp
norm(const complex<_Tp>& __c)
{
if (__libcpp_isinf_or_builtin(__c.real()))
return abs(__c.real());
if (__libcpp_isinf_or_builtin(__c.imag()))
return abs(__c.imag());
return __c.real() * __c.real() + __c.imag() * __c.imag();
}
template <class _Tp>
inline _LIBCPP_INLINE_VISIBILITY
typename __libcpp_complex_overload_traits<_Tp>::_ValueType
norm(_Tp __re)
{
typedef typename __libcpp_complex_overload_traits<_Tp>::_ValueType _ValueType;
return static_cast<_ValueType>(__re) * __re;
}
// conj
template<class _Tp>
inline _LIBCPP_INLINE_VISIBILITY
complex<_Tp>
conj(const complex<_Tp>& __c)
{
return complex<_Tp>(__c.real(), -__c.imag());
}
template <class _Tp>
inline _LIBCPP_INLINE_VISIBILITY
typename __libcpp_complex_overload_traits<_Tp>::_ComplexType
conj(_Tp __re)
{
typedef typename __libcpp_complex_overload_traits<_Tp>::_ComplexType _ComplexType;
return _ComplexType(__re);
}
// proj
template<class _Tp>
inline _LIBCPP_INLINE_VISIBILITY
complex<_Tp>
proj(const complex<_Tp>& __c)
{
std::complex<_Tp> __r = __c;
if (__libcpp_isinf_or_builtin(__c.real()) || __libcpp_isinf_or_builtin(__c.imag()))
__r = complex<_Tp>(INFINITY, copysign(_Tp(0), __c.imag()));
return __r;
}
template <class _Tp>
inline _LIBCPP_INLINE_VISIBILITY
typename enable_if
<
is_floating_point<_Tp>::value,
typename __libcpp_complex_overload_traits<_Tp>::_ComplexType
>::type
proj(_Tp __re)
{
if (__libcpp_isinf_or_builtin(__re))
__re = abs(__re);
return complex<_Tp>(__re);
}
template <class _Tp>
inline _LIBCPP_INLINE_VISIBILITY
typename enable_if
<
is_integral<_Tp>::value,
typename __libcpp_complex_overload_traits<_Tp>::_ComplexType
>::type
proj(_Tp __re)
{
typedef typename __libcpp_complex_overload_traits<_Tp>::_ComplexType _ComplexType;
return _ComplexType(__re);
}
// polar
template<class _Tp>
complex<_Tp>
polar(const _Tp& __rho, const _Tp& __theta = _Tp())
{
if (__libcpp_isnan_or_builtin(__rho) || signbit(__rho))
return complex<_Tp>(_Tp(NAN), _Tp(NAN));
if (__libcpp_isnan_or_builtin(__theta))
{
if (__libcpp_isinf_or_builtin(__rho))
return complex<_Tp>(__rho, __theta);
return complex<_Tp>(__theta, __theta);
}
if (__libcpp_isinf_or_builtin(__theta))
{
if (__libcpp_isinf_or_builtin(__rho))
return complex<_Tp>(__rho, _Tp(NAN));
return complex<_Tp>(_Tp(NAN), _Tp(NAN));
}
_Tp __x = __rho * cos(__theta);
if (__libcpp_isnan_or_builtin(__x))
__x = 0;
_Tp __y = __rho * sin(__theta);
if (__libcpp_isnan_or_builtin(__y))
__y = 0;
return complex<_Tp>(__x, __y);
}
// log
template<class _Tp>
inline _LIBCPP_INLINE_VISIBILITY
complex<_Tp>
log(const complex<_Tp>& __x)
{
return complex<_Tp>(log(abs(__x)), arg(__x));
}
// log10
template<class _Tp>
inline _LIBCPP_INLINE_VISIBILITY
complex<_Tp>
log10(const complex<_Tp>& __x)
{
return log(__x) / log(_Tp(10));
}
// sqrt
template<class _Tp>
complex<_Tp>
sqrt(const complex<_Tp>& __x)
{
if (__libcpp_isinf_or_builtin(__x.imag()))
return complex<_Tp>(_Tp(INFINITY), __x.imag());
if (__libcpp_isinf_or_builtin(__x.real()))
{
if (__x.real() > _Tp(0))
return complex<_Tp>(__x.real(), __libcpp_isnan_or_builtin(__x.imag()) ? __x.imag() : copysign(_Tp(0), __x.imag()));
return complex<_Tp>(__libcpp_isnan_or_builtin(__x.imag()) ? __x.imag() : _Tp(0), copysign(__x.real(), __x.imag()));
}
return polar(sqrt(abs(__x)), arg(__x) / _Tp(2));
}
// exp
template<class _Tp>
complex<_Tp>
exp(const complex<_Tp>& __x)
{
_Tp __i = __x.imag();
if (__libcpp_isinf_or_builtin(__x.real()))
{
if (__x.real() < _Tp(0))
{
if (!__libcpp_isfinite_or_builtin(__i))
__i = _Tp(1);
}
else if (__i == 0 || !__libcpp_isfinite_or_builtin(__i))
{
if (__libcpp_isinf_or_builtin(__i))
__i = _Tp(NAN);
return complex<_Tp>(__x.real(), __i);
}
}
else if (__libcpp_isnan_or_builtin(__x.real()) && __x.imag() == 0)
return __x;
_Tp __e = exp(__x.real());
return complex<_Tp>(__e * cos(__i), __e * sin(__i));
}
// pow
template<class _Tp>
inline _LIBCPP_INLINE_VISIBILITY
complex<_Tp>
pow(const complex<_Tp>& __x, const complex<_Tp>& __y)
{
return exp(__y * log(__x));
}
template<class _Tp, class _Up>
inline _LIBCPP_INLINE_VISIBILITY
complex<typename __promote<_Tp, _Up>::type>
pow(const complex<_Tp>& __x, const complex<_Up>& __y)
{
typedef complex<typename __promote<_Tp, _Up>::type> result_type;
return _VSTD::pow(result_type(__x), result_type(__y));
}
template<class _Tp, class _Up>
inline _LIBCPP_INLINE_VISIBILITY
typename enable_if
<
is_arithmetic<_Up>::value,
complex<typename __promote<_Tp, _Up>::type>
>::type
pow(const complex<_Tp>& __x, const _Up& __y)
{
typedef complex<typename __promote<_Tp, _Up>::type> result_type;
return _VSTD::pow(result_type(__x), result_type(__y));
}
template<class _Tp, class _Up>
inline _LIBCPP_INLINE_VISIBILITY
typename enable_if
<
is_arithmetic<_Tp>::value,
complex<typename __promote<_Tp, _Up>::type>
>::type
pow(const _Tp& __x, const complex<_Up>& __y)
{
typedef complex<typename __promote<_Tp, _Up>::type> result_type;
return _VSTD::pow(result_type(__x), result_type(__y));
}
// __sqr, computes pow(x, 2)
template<class _Tp>
inline _LIBCPP_INLINE_VISIBILITY
complex<_Tp>
__sqr(const complex<_Tp>& __x)
{
return complex<_Tp>((__x.real() - __x.imag()) * (__x.real() + __x.imag()),
_Tp(2) * __x.real() * __x.imag());
}
// asinh
template<class _Tp>
complex<_Tp>
asinh(const complex<_Tp>& __x)
{
const _Tp __pi(atan2(+0., -0.));
if (__libcpp_isinf_or_builtin(__x.real()))
{
if (__libcpp_isnan_or_builtin(__x.imag()))
return __x;
if (__libcpp_isinf_or_builtin(__x.imag()))
return complex<_Tp>(__x.real(), copysign(__pi * _Tp(0.25), __x.imag()));
return complex<_Tp>(__x.real(), copysign(_Tp(0), __x.imag()));
}
if (__libcpp_isnan_or_builtin(__x.real()))
{
if (__libcpp_isinf_or_builtin(__x.imag()))
return complex<_Tp>(__x.imag(), __x.real());
if (__x.imag() == 0)
return __x;
return complex<_Tp>(__x.real(), __x.real());
}
if (__libcpp_isinf_or_builtin(__x.imag()))
return complex<_Tp>(copysign(__x.imag(), __x.real()), copysign(__pi/_Tp(2), __x.imag()));
complex<_Tp> __z = log(__x + sqrt(__sqr(__x) + _Tp(1)));
return complex<_Tp>(copysign(__z.real(), __x.real()), copysign(__z.imag(), __x.imag()));
}
// acosh
template<class _Tp>
complex<_Tp>
acosh(const complex<_Tp>& __x)
{
const _Tp __pi(atan2(+0., -0.));
if (__libcpp_isinf_or_builtin(__x.real()))
{
if (__libcpp_isnan_or_builtin(__x.imag()))
return complex<_Tp>(abs(__x.real()), __x.imag());
if (__libcpp_isinf_or_builtin(__x.imag()))
{
if (__x.real() > 0)
return complex<_Tp>(__x.real(), copysign(__pi * _Tp(0.25), __x.imag()));
else
return complex<_Tp>(-__x.real(), copysign(__pi * _Tp(0.75), __x.imag()));
}
if (__x.real() < 0)
return complex<_Tp>(-__x.real(), copysign(__pi, __x.imag()));
return complex<_Tp>(__x.real(), copysign(_Tp(0), __x.imag()));
}
if (__libcpp_isnan_or_builtin(__x.real()))
{
if (__libcpp_isinf_or_builtin(__x.imag()))
return complex<_Tp>(abs(__x.imag()), __x.real());
return complex<_Tp>(__x.real(), __x.real());
}
if (__libcpp_isinf_or_builtin(__x.imag()))
return complex<_Tp>(abs(__x.imag()), copysign(__pi/_Tp(2), __x.imag()));
complex<_Tp> __z = log(__x + sqrt(__sqr(__x) - _Tp(1)));
return complex<_Tp>(copysign(__z.real(), _Tp(0)), copysign(__z.imag(), __x.imag()));
}
// atanh
template<class _Tp>
complex<_Tp>
atanh(const complex<_Tp>& __x)
{
const _Tp __pi(atan2(+0., -0.));
if (__libcpp_isinf_or_builtin(__x.imag()))
{
return complex<_Tp>(copysign(_Tp(0), __x.real()), copysign(__pi/_Tp(2), __x.imag()));
}
if (__libcpp_isnan_or_builtin(__x.imag()))
{
if (__libcpp_isinf_or_builtin(__x.real()) || __x.real() == 0)
return complex<_Tp>(copysign(_Tp(0), __x.real()), __x.imag());
return complex<_Tp>(__x.imag(), __x.imag());
}
if (__libcpp_isnan_or_builtin(__x.real()))
{
return complex<_Tp>(__x.real(), __x.real());
}
if (__libcpp_isinf_or_builtin(__x.real()))
{
return complex<_Tp>(copysign(_Tp(0), __x.real()), copysign(__pi/_Tp(2), __x.imag()));
}
if (abs(__x.real()) == _Tp(1) && __x.imag() == _Tp(0))
{
return complex<_Tp>(copysign(_Tp(INFINITY), __x.real()), copysign(_Tp(0), __x.imag()));
}
complex<_Tp> __z = log((_Tp(1) + __x) / (_Tp(1) - __x)) / _Tp(2);
return complex<_Tp>(copysign(__z.real(), __x.real()), copysign(__z.imag(), __x.imag()));
}
// sinh
template<class _Tp>
complex<_Tp>
sinh(const complex<_Tp>& __x)
{
if (__libcpp_isinf_or_builtin(__x.real()) && !__libcpp_isfinite_or_builtin(__x.imag()))
return complex<_Tp>(__x.real(), _Tp(NAN));
if (__x.real() == 0 && !__libcpp_isfinite_or_builtin(__x.imag()))
return complex<_Tp>(__x.real(), _Tp(NAN));
if (__x.imag() == 0 && !__libcpp_isfinite_or_builtin(__x.real()))
return __x;
return complex<_Tp>(sinh(__x.real()) * cos(__x.imag()), cosh(__x.real()) * sin(__x.imag()));
}
// cosh
template<class _Tp>
complex<_Tp>
cosh(const complex<_Tp>& __x)
{
if (__libcpp_isinf_or_builtin(__x.real()) && !__libcpp_isfinite_or_builtin(__x.imag()))
return complex<_Tp>(abs(__x.real()), _Tp(NAN));
if (__x.real() == 0 && !__libcpp_isfinite_or_builtin(__x.imag()))
return complex<_Tp>(_Tp(NAN), __x.real());
if (__x.real() == 0 && __x.imag() == 0)
return complex<_Tp>(_Tp(1), __x.imag());
if (__x.imag() == 0 && !__libcpp_isfinite_or_builtin(__x.real()))
return complex<_Tp>(abs(__x.real()), __x.imag());
return complex<_Tp>(cosh(__x.real()) * cos(__x.imag()), sinh(__x.real()) * sin(__x.imag()));
}
// tanh
template<class _Tp>
complex<_Tp>
tanh(const complex<_Tp>& __x)
{
if (__libcpp_isinf_or_builtin(__x.real()))
{
if (!__libcpp_isfinite_or_builtin(__x.imag()))
return complex<_Tp>(_Tp(1), _Tp(0));
return complex<_Tp>(_Tp(1), copysign(_Tp(0), sin(_Tp(2) * __x.imag())));
}
if (__libcpp_isnan_or_builtin(__x.real()) && __x.imag() == 0)
return __x;
_Tp __2r(_Tp(2) * __x.real());
_Tp __2i(_Tp(2) * __x.imag());
_Tp __d(cosh(__2r) + cos(__2i));
_Tp __2rsh(sinh(__2r));
if (__libcpp_isinf_or_builtin(__2rsh) && __libcpp_isinf_or_builtin(__d))
return complex<_Tp>(__2rsh > _Tp(0) ? _Tp(1) : _Tp(-1),
__2i > _Tp(0) ? _Tp(0) : _Tp(-0.));
return complex<_Tp>(__2rsh/__d, sin(__2i)/__d);
}
// asin
template<class _Tp>
complex<_Tp>
asin(const complex<_Tp>& __x)
{
complex<_Tp> __z = asinh(complex<_Tp>(-__x.imag(), __x.real()));
return complex<_Tp>(__z.imag(), -__z.real());
}
// acos
template<class _Tp>
complex<_Tp>
acos(const complex<_Tp>& __x)
{
const _Tp __pi(atan2(+0., -0.));
if (__libcpp_isinf_or_builtin(__x.real()))
{
if (__libcpp_isnan_or_builtin(__x.imag()))
return complex<_Tp>(__x.imag(), __x.real());
if (__libcpp_isinf_or_builtin(__x.imag()))
{
if (__x.real() < _Tp(0))
return complex<_Tp>(_Tp(0.75) * __pi, -__x.imag());
return complex<_Tp>(_Tp(0.25) * __pi, -__x.imag());
}
if (__x.real() < _Tp(0))
return complex<_Tp>(__pi, signbit(__x.imag()) ? -__x.real() : __x.real());
return complex<_Tp>(_Tp(0), signbit(__x.imag()) ? __x.real() : -__x.real());
}
if (__libcpp_isnan_or_builtin(__x.real()))
{
if (__libcpp_isinf_or_builtin(__x.imag()))
return complex<_Tp>(__x.real(), -__x.imag());
return complex<_Tp>(__x.real(), __x.real());
}
if (__libcpp_isinf_or_builtin(__x.imag()))
return complex<_Tp>(__pi/_Tp(2), -__x.imag());
if (__x.real() == 0 && (__x.imag() == 0 || isnan(__x.imag())))
return complex<_Tp>(__pi/_Tp(2), -__x.imag());
complex<_Tp> __z = log(__x + sqrt(__sqr(__x) - _Tp(1)));
if (signbit(__x.imag()))
return complex<_Tp>(abs(__z.imag()), abs(__z.real()));
return complex<_Tp>(abs(__z.imag()), -abs(__z.real()));
}
// atan
template<class _Tp>
complex<_Tp>
atan(const complex<_Tp>& __x)
{
complex<_Tp> __z = atanh(complex<_Tp>(-__x.imag(), __x.real()));
return complex<_Tp>(__z.imag(), -__z.real());
}
// sin
template<class _Tp>
complex<_Tp>
sin(const complex<_Tp>& __x)
{
complex<_Tp> __z = sinh(complex<_Tp>(-__x.imag(), __x.real()));
return complex<_Tp>(__z.imag(), -__z.real());
}
// cos
template<class _Tp>
inline _LIBCPP_INLINE_VISIBILITY
complex<_Tp>
cos(const complex<_Tp>& __x)
{
return cosh(complex<_Tp>(-__x.imag(), __x.real()));
}
// tan
template<class _Tp>
complex<_Tp>
tan(const complex<_Tp>& __x)
{
complex<_Tp> __z = tanh(complex<_Tp>(-__x.imag(), __x.real()));
return complex<_Tp>(__z.imag(), -__z.real());
}
template<class _Tp, class _CharT, class _Traits>
basic_istream<_CharT, _Traits>&
operator>>(basic_istream<_CharT, _Traits>& __is, complex<_Tp>& __x)
{
if (__is.good())
{
ws(__is);
if (__is.peek() == _CharT('('))
{
__is.get();
_Tp __r;
__is >> __r;
if (!__is.fail())
{
ws(__is);
_CharT __c = __is.peek();
if (__c == _CharT(','))
{
__is.get();
_Tp __i;
__is >> __i;
if (!__is.fail())
{
ws(__is);
__c = __is.peek();
if (__c == _CharT(')'))
{
__is.get();
__x = complex<_Tp>(__r, __i);
}
else
__is.setstate(ios_base::failbit);
}
else
__is.setstate(ios_base::failbit);
}
else if (__c == _CharT(')'))
{
__is.get();
__x = complex<_Tp>(__r, _Tp(0));
}
else
__is.setstate(ios_base::failbit);
}
else
__is.setstate(ios_base::failbit);
}
else
{
_Tp __r;
__is >> __r;
if (!__is.fail())
__x = complex<_Tp>(__r, _Tp(0));
else
__is.setstate(ios_base::failbit);
}
}
else
__is.setstate(ios_base::failbit);
return __is;
}
template<class _Tp, class _CharT, class _Traits>
basic_ostream<_CharT, _Traits>&
operator<<(basic_ostream<_CharT, _Traits>& __os, const complex<_Tp>& __x)
{
basic_ostringstream<_CharT, _Traits> __s;
__s.flags(__os.flags());
__s.imbue(__os.getloc());
__s.precision(__os.precision());
__s << '(' << __x.real() << ',' << __x.imag() << ')';
return __os << __s.str();
}
#if _LIBCPP_STD_VER > 11
// Literal suffix for complex number literals [complex.literals]
inline namespace literals
{
inline namespace complex_literals
{
constexpr complex<long double> operator""il(long double __im)
{
return { 0.0l, __im };
}
constexpr complex<long double> operator""il(unsigned long long __im)
{
return { 0.0l, static_cast<long double>(__im) };
}
constexpr complex<double> operator""i(long double __im)
{
return { 0.0, static_cast<double>(__im) };
}
constexpr complex<double> operator""i(unsigned long long __im)
{
return { 0.0, static_cast<double>(__im) };
}
constexpr complex<float> operator""if(long double __im)
{
return { 0.0f, static_cast<float>(__im) };
}
constexpr complex<float> operator""if(unsigned long long __im)
{
return { 0.0f, static_cast<float>(__im) };
}
}
}
#endif
_LIBCPP_END_NAMESPACE_STD
#endif // _LIBCPP_COMPLEX
| 46,752 | 1,497 | jart/cosmopolitan | false |
cosmopolitan/third_party/libcxx/__config | // -*- C++ -*-
//===--------------------------- __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_CONFIG
#define _LIBCPP_CONFIG
#include "libc/isystem/features.h"
#define _LIBCPP_ABI_UNSTABLE
#define _LIBCPP_NO_EXCEPTIONS
#define _LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER
#define _LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS
#define _LIBCPP_HAS_TRIVIAL_MUTEX_DESTRUCTION
#define _LIBCPP_ENABLE_CXX17_REMOVED_RANDOM_SHUFFLE
#if defined(_MSC_VER) && !defined(__clang__)
# if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
# define _LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER
# endif
#endif
#ifndef _LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER
#pragma GCC system_header
#endif
#ifdef __cplusplus
#ifdef __GNUC__
# define _GNUC_VER (__GNUC__ * 100 + __GNUC_MINOR__)
// The _GNUC_VER_NEW macro better represents the new GCC versioning scheme
// introduced in GCC 5.0.
# define _GNUC_VER_NEW (_GNUC_VER * 10 + __GNUC_PATCHLEVEL__)
#else
# define _GNUC_VER 0
# define _GNUC_VER_NEW 0
#endif
#define _LIBCPP_VERSION 10000
#ifndef _LIBCPP_ABI_VERSION
# define _LIBCPP_ABI_VERSION 1
#endif
#ifndef __STDC_HOSTED__
# define _LIBCPP_FREESTANDING
#endif
#ifndef _LIBCPP_STD_VER
# if __cplusplus <= 201103L
# define _LIBCPP_STD_VER 11
# elif __cplusplus <= 201402L
# define _LIBCPP_STD_VER 14
# elif __cplusplus <= 201703L
# define _LIBCPP_STD_VER 17
# else
# define _LIBCPP_STD_VER 18 // current year, or date of c++2a ratification
# endif
#endif // _LIBCPP_STD_VER
#if defined(__ELF__)
# define _LIBCPP_OBJECT_FORMAT_ELF 1
#elif defined(__MACH__)
# define _LIBCPP_OBJECT_FORMAT_MACHO 1
#elif defined(_WIN32)
# define _LIBCPP_OBJECT_FORMAT_COFF 1
#elif defined(__wasm__)
# define _LIBCPP_OBJECT_FORMAT_WASM 1
#else
# error Unknown object file format
#endif
#if defined(_LIBCPP_ABI_UNSTABLE) || _LIBCPP_ABI_VERSION >= 2
// Change short string representation so that string data starts at offset 0,
// improving its alignment in some cases.
# define _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
// Fix deque iterator type in order to support incomplete types.
# define _LIBCPP_ABI_INCOMPLETE_TYPES_IN_DEQUE
// Fix undefined behavior in how std::list stores its linked nodes.
# define _LIBCPP_ABI_LIST_REMOVE_NODE_POINTER_UB
// Fix undefined behavior in how __tree stores its end and parent nodes.
# define _LIBCPP_ABI_TREE_REMOVE_NODE_POINTER_UB
// Fix undefined behavior in how __hash_table stores its pointer types.
# define _LIBCPP_ABI_FIX_UNORDERED_NODE_POINTER_UB
# define _LIBCPP_ABI_FORWARD_LIST_REMOVE_NODE_POINTER_UB
# define _LIBCPP_ABI_FIX_UNORDERED_CONTAINER_SIZE_TYPE
// Don't use a nullptr_t simulation type in C++03 instead using C++11 nullptr
// provided under the alternate keyword __nullptr, which changes the mangling
// of nullptr_t. This option is ABI incompatible with GCC in C++03 mode.
# define _LIBCPP_ABI_ALWAYS_USE_CXX11_NULLPTR
// Define the `pointer_safety` enum as a C++11 strongly typed enumeration
// instead of as a class simulating an enum. If this option is enabled
// `pointer_safety` and `get_pointer_safety()` will no longer be available
// in C++03.
# define _LIBCPP_ABI_POINTER_SAFETY_ENUM_TYPE
// Define a key function for `bad_function_call` in the library, to centralize
// its vtable and typeinfo to libc++ rather than having all other libraries
// using that class define their own copies.
# define _LIBCPP_ABI_BAD_FUNCTION_CALL_KEY_FUNCTION
// Enable optimized version of __do_get_(un)signed which avoids redundant copies.
# define _LIBCPP_ABI_OPTIMIZED_LOCALE_NUM_GET
// Use the smallest possible integer type to represent the index of the variant.
// Previously libc++ used "unsigned int" exclusively.
# define _LIBCPP_ABI_VARIANT_INDEX_TYPE_OPTIMIZATION
// Unstable attempt to provide a more optimized std::function
# define _LIBCPP_ABI_OPTIMIZED_FUNCTION
// All the regex constants must be distinct and nonzero.
# define _LIBCPP_ABI_REGEX_CONSTANTS_NONZERO
#elif _LIBCPP_ABI_VERSION == 1
# if !defined(_LIBCPP_OBJECT_FORMAT_COFF)
// Enable compiling copies of now inline methods into the dylib to support
// applications compiled against older libraries. This is unnecessary with
// COFF dllexport semantics, since dllexport forces a non-inline definition
// of inline functions to be emitted anyway. Our own non-inline copy would
// conflict with the dllexport-emitted copy, so we disable it.
// [jart] no thanks
//# define _LIBCPP_DEPRECATED_ABI_LEGACY_LIBRARY_DEFINITIONS_FOR_INLINE_FUNCTIONS
# endif
// Feature macros for disabling pre ABI v1 features. All of these options
// are deprecated.
# if defined(__FreeBSD__)
# define _LIBCPP_DEPRECATED_ABI_DISABLE_PAIR_TRIVIAL_COPY_CTOR
# endif
#endif
#ifdef _LIBCPP_TRIVIAL_PAIR_COPY_CTOR
#error "_LIBCPP_TRIVIAL_PAIR_COPY_CTOR" is no longer supported. \
use _LIBCPP_DEPRECATED_ABI_DISABLE_PAIR_TRIVIAL_COPY_CTOR instead
#endif
#define _LIBCPP_CONCAT1(_LIBCPP_X,_LIBCPP_Y) _LIBCPP_X##_LIBCPP_Y
#define _LIBCPP_CONCAT(_LIBCPP_X,_LIBCPP_Y) _LIBCPP_CONCAT1(_LIBCPP_X,_LIBCPP_Y)
#ifndef _LIBCPP_ABI_NAMESPACE
# define _LIBCPP_ABI_NAMESPACE _LIBCPP_CONCAT(__,_LIBCPP_ABI_VERSION)
#endif
#if __cplusplus < 201103L
#define _LIBCPP_CXX03_LANG
#endif
#ifndef __has_attribute
#define __has_attribute(__x) 0
#endif
#ifndef __has_builtin
#define __has_builtin(__x) 0
#endif
#ifndef __has_extension
#define __has_extension(__x) 0
#endif
#ifndef __has_feature
#define __has_feature(__x) 0
#endif
#ifndef __has_cpp_attribute
#define __has_cpp_attribute(__x) 0
#endif
// '__is_identifier' returns '0' if '__x' is a reserved identifier provided by
// the compiler and '1' otherwise.
#ifndef __is_identifier
#define __is_identifier(__x) 1
#endif
#ifndef __has_declspec_attribute
#define __has_declspec_attribute(__x) 0
#endif
#define __has_keyword(__x) !(__is_identifier(__x))
#ifndef __has_include
#define __has_include(...) 0
#endif
#if defined(__clang__)
# define _LIBCPP_COMPILER_CLANG
# ifndef __apple_build_version__
# define _LIBCPP_CLANG_VER (__clang_major__ * 100 + __clang_minor__)
# endif
#elif defined(__GNUC__)
# define _LIBCPP_COMPILER_GCC
#elif defined(_MSC_VER)
# define _LIBCPP_COMPILER_MSVC
#elif defined(__IBMCPP__)
# define _LIBCPP_COMPILER_IBM
#endif
#if defined(_LIBCPP_COMPILER_GCC) && __cplusplus < 201103L
#error "libc++ does not support using GCC with C++03. Please enable C++11"
#endif
// FIXME: ABI detection should be done via compiler builtin macros. This
// is just a placeholder until Clang implements such macros. For now assume
// that Windows compilers pretending to be MSVC++ target the Microsoft ABI,
// and allow the user to explicitly specify the ABI to handle cases where this
// heuristic falls short.
#if defined(_LIBCPP_ABI_FORCE_ITANIUM) && defined(_LIBCPP_ABI_FORCE_MICROSOFT)
# error "Only one of _LIBCPP_ABI_FORCE_ITANIUM and _LIBCPP_ABI_FORCE_MICROSOFT can be defined"
#elif defined(_LIBCPP_ABI_FORCE_ITANIUM)
# define _LIBCPP_ABI_ITANIUM
#elif defined(_LIBCPP_ABI_FORCE_MICROSOFT)
# define _LIBCPP_ABI_MICROSOFT
#else
# if defined(_WIN32) && defined(_MSC_VER)
# define _LIBCPP_ABI_MICROSOFT
# else
# define _LIBCPP_ABI_ITANIUM
# endif
#endif
#if defined(_LIBCPP_ABI_MICROSOFT) && !defined(_LIBCPP_NO_VCRUNTIME)
# define _LIBCPP_ABI_VCRUNTIME
#endif
// Need to detect which libc we're using if we're on Linux.
#if defined(__linux__)
# if defined(__GLIBC_PREREQ)
# define _LIBCPP_GLIBC_PREREQ(a, b) __GLIBC_PREREQ(a, b)
# else
# define _LIBCPP_GLIBC_PREREQ(a, b) 0
# endif // defined(__GLIBC_PREREQ)
#endif // defined(__linux__)
#ifdef __LITTLE_ENDIAN__
# if __LITTLE_ENDIAN__
# define _LIBCPP_LITTLE_ENDIAN
# endif // __LITTLE_ENDIAN__
#endif // __LITTLE_ENDIAN__
#ifdef __BIG_ENDIAN__
# if __BIG_ENDIAN__
# define _LIBCPP_BIG_ENDIAN
# endif // __BIG_ENDIAN__
#endif // __BIG_ENDIAN__
#ifdef __BYTE_ORDER__
# if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
# define _LIBCPP_LITTLE_ENDIAN
# elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
# define _LIBCPP_BIG_ENDIAN
# endif // __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
#endif // __BYTE_ORDER__
#if defined(__CloudABI__)
// Certain architectures provide arc4random(). Prefer using
// arc4random() over /dev/{u,}random to make it possible to obtain
// random data even when using sandboxing mechanisms such as chroots,
// Capsicum, etc.
# define _LIBCPP_USING_ARC4_RANDOM
#elif defined(__Fuchsia__) || defined(__wasi__) || defined(__COSMOPOLITAN__)
# define _LIBCPP_USING_GETENTROPY
#elif defined(__native_client__)
// NaCl's sandbox (which PNaCl also runs in) doesn't allow filesystem access,
// including accesses to the special files under /dev. C++11's
// std::random_device is instead exposed through a NaCl syscall.
# define _LIBCPP_USING_NACL_RANDOM
#elif defined(_LIBCPP_WIN32API)
# define _LIBCPP_USING_WIN32_RANDOM
#else
# define _LIBCPP_USING_DEV_RANDOM
#endif
#if !defined(_LIBCPP_LITTLE_ENDIAN) && !defined(_LIBCPP_BIG_ENDIAN)
#include "libc/isystem/endian.h"
# if __BYTE_ORDER == __LITTLE_ENDIAN
# define _LIBCPP_LITTLE_ENDIAN
# elif __BYTE_ORDER == __BIG_ENDIAN
# define _LIBCPP_BIG_ENDIAN
# else // __BYTE_ORDER == __BIG_ENDIAN
# error unable to determine endian
# endif
#endif // !defined(_LIBCPP_LITTLE_ENDIAN) && !defined(_LIBCPP_BIG_ENDIAN)
#if __has_attribute(__no_sanitize__) && !defined(_LIBCPP_COMPILER_GCC)
# define _LIBCPP_NO_CFI __attribute__((__no_sanitize__("cfi")))
#else
# define _LIBCPP_NO_CFI
#endif
#if __ISO_C_VISIBLE >= 2011 || __cplusplus >= 201103L
# if defined(__FreeBSD__)
# define _LIBCPP_HAS_QUICK_EXIT
# define _LIBCPP_HAS_C11_FEATURES
# elif defined(__Fuchsia__) || defined(__wasi__)
# define _LIBCPP_HAS_QUICK_EXIT
# define _LIBCPP_HAS_TIMESPEC_GET
# define _LIBCPP_HAS_C11_FEATURES
# elif defined(__linux__)
# if !defined(_LIBCPP_HAS_MUSL_LIBC)
# if _LIBCPP_GLIBC_PREREQ(2, 15) || defined(__BIONIC__)
# define _LIBCPP_HAS_QUICK_EXIT
# endif
# if _LIBCPP_GLIBC_PREREQ(2, 17)
# define _LIBCPP_HAS_C11_FEATURES
# define _LIBCPP_HAS_TIMESPEC_GET
# endif
# else // defined(_LIBCPP_HAS_MUSL_LIBC)
# define _LIBCPP_HAS_QUICK_EXIT
# define _LIBCPP_HAS_TIMESPEC_GET
# define _LIBCPP_HAS_C11_FEATURES
# endif
# endif // __linux__
#endif
#ifndef _LIBCPP_CXX03_LANG
# define _LIBCPP_ALIGNOF(_Tp) alignof(_Tp)
#elif defined(_LIBCPP_COMPILER_CLANG)
# define _LIBCPP_ALIGNOF(_Tp) _Alignof(_Tp)
#else
// This definition is potentially buggy, but it's only taken with GCC in C++03,
// which we barely support anyway. See llvm.org/PR39713
# define _LIBCPP_ALIGNOF(_Tp) __alignof(_Tp)
#endif
#define _LIBCPP_PREFERRED_ALIGNOF(_Tp) __alignof(_Tp)
#if defined(_LIBCPP_COMPILER_CLANG)
// _LIBCPP_ALTERNATE_STRING_LAYOUT is an old name for
// _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT left here for backward compatibility.
#if (defined(__APPLE__) && !defined(__i386__) && !defined(__x86_64__) && \
(!defined(__arm__) || __ARM_ARCH_7K__ >= 2)) || \
defined(_LIBCPP_ALTERNATE_STRING_LAYOUT)
#define _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT
#endif
#if __has_feature(cxx_alignas)
# define _ALIGNAS_TYPE(x) alignas(x)
# define _ALIGNAS(x) alignas(x)
#else
# define _ALIGNAS_TYPE(x) __attribute__((__aligned__(_LIBCPP_ALIGNOF(x))))
# define _ALIGNAS(x) __attribute__((__aligned__(x)))
#endif
#if __cplusplus < 201103L
typedef __char16_t char16_t;
typedef __char32_t char32_t;
#endif
#if !(__has_feature(cxx_exceptions)) && !defined(_LIBCPP_NO_EXCEPTIONS)
#define _LIBCPP_NO_EXCEPTIONS
#endif
#if !(__has_feature(cxx_rtti)) && !defined(_LIBCPP_NO_RTTI)
#define _LIBCPP_NO_RTTI
#endif
#if !(__has_feature(cxx_strong_enums))
#define _LIBCPP_HAS_NO_STRONG_ENUMS
#endif
#if __has_feature(cxx_attributes)
# define _LIBCPP_NORETURN [[noreturn]]
#else
# define _LIBCPP_NORETURN __attribute__ ((__noreturn__))
#endif
#if !(__has_feature(cxx_lambdas))
#define _LIBCPP_HAS_NO_LAMBDAS
#endif
#if !(__has_feature(cxx_nullptr))
# if (__has_extension(cxx_nullptr) || __has_keyword(__nullptr)) && defined(_LIBCPP_ABI_ALWAYS_USE_CXX11_NULLPTR)
# define nullptr __nullptr
# else
# define _LIBCPP_HAS_NO_NULLPTR
# endif
#endif
#if !(__has_feature(cxx_rvalue_references))
#define _LIBCPP_HAS_NO_RVALUE_REFERENCES
#endif
#if !(__has_feature(cxx_auto_type))
#define _LIBCPP_HAS_NO_AUTO_TYPE
#endif
#if !(__has_feature(cxx_variadic_templates))
#define _LIBCPP_HAS_NO_VARIADICS
#endif
// Objective-C++ features (opt-in)
#if __has_feature(objc_arc)
#define _LIBCPP_HAS_OBJC_ARC
#endif
#if __has_feature(objc_arc_weak)
#define _LIBCPP_HAS_OBJC_ARC_WEAK
#endif
#if !(__has_feature(cxx_relaxed_constexpr))
#define _LIBCPP_HAS_NO_CXX14_CONSTEXPR
#endif
#if !(__has_feature(cxx_variable_templates))
#define _LIBCPP_HAS_NO_VARIABLE_TEMPLATES
#endif
#if !(__has_feature(cxx_noexcept))
#define _LIBCPP_HAS_NO_NOEXCEPT
#endif
#if !defined(_LIBCPP_HAS_NO_ASAN) && !__has_feature(address_sanitizer)
#define _LIBCPP_HAS_NO_ASAN
#endif
// Allow for build-time disabling of unsigned integer sanitization
#if !defined(_LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK) && __has_attribute(no_sanitize)
#define _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK __attribute__((__no_sanitize__("unsigned-integer-overflow")))
#endif
#if __has_builtin(__builtin_launder)
#define _LIBCPP_COMPILER_HAS_BUILTIN_LAUNDER
#endif
#if !__is_identifier(__has_unique_object_representations)
#define _LIBCPP_HAS_UNIQUE_OBJECT_REPRESENTATIONS
#endif
#define _LIBCPP_ALWAYS_INLINE __attribute__ ((__always_inline__))
// Literal operators ""d and ""y are supported starting with LLVM Clang 8 and AppleClang 10.0.1
#if (defined(_LIBCPP_CLANG_VER) && _LIBCPP_CLANG_VER < 800) || \
(defined(__apple_build_version__) && __apple_build_version__ < 10010000)
#define _LIBCPP_HAS_NO_CXX20_CHRONO_LITERALS
#endif
#define _LIBCPP_DISABLE_EXTENSION_WARNING __extension__
#elif defined(_LIBCPP_COMPILER_GCC)
#define _ALIGNAS(x) __attribute__((__aligned__(x)))
#define _ALIGNAS_TYPE(x) __attribute__((__aligned__(_LIBCPP_ALIGNOF(x))))
#define _LIBCPP_NORETURN __attribute__((noreturn))
#if !__EXCEPTIONS && !defined(_LIBCPP_NO_EXCEPTIONS)
#define _LIBCPP_NO_EXCEPTIONS
#endif
// Determine if GCC supports relaxed constexpr
#if !defined(__cpp_constexpr) || __cpp_constexpr < 201304L
#define _LIBCPP_HAS_NO_CXX14_CONSTEXPR
#endif
// GCC 5 supports variable templates
#if !defined(__cpp_variable_templates) || __cpp_variable_templates < 201304L
#define _LIBCPP_HAS_NO_VARIABLE_TEMPLATES
#endif
#if !defined(_LIBCPP_HAS_NO_ASAN) && !defined(__SANITIZE_ADDRESS__)
#define _LIBCPP_HAS_NO_ASAN
#endif
#if _GNUC_VER >= 700
#define _LIBCPP_COMPILER_HAS_BUILTIN_LAUNDER
#endif
#if _GNUC_VER >= 700
#define _LIBCPP_HAS_UNIQUE_OBJECT_REPRESENTATIONS
#endif
#define _LIBCPP_ALWAYS_INLINE __attribute__ ((__always_inline__))
#define _LIBCPP_DISABLE_EXTENSION_WARNING __extension__
#elif defined(_LIBCPP_COMPILER_MSVC)
#define _LIBCPP_TOSTRING2(x) #x
#define _LIBCPP_TOSTRING(x) _LIBCPP_TOSTRING2(x)
#define _LIBCPP_WARNING(x) __pragma(message(__FILE__ "(" _LIBCPP_TOSTRING(__LINE__) ") : warning note: " x))
#if _MSC_VER < 1900
#error "MSVC versions prior to Visual Studio 2015 are not supported"
#endif
#define _LIBCPP_HAS_NO_CXX14_CONSTEXPR
#define _LIBCPP_HAS_NO_VARIABLE_TEMPLATES
#define __alignof__ __alignof
#define _LIBCPP_NORETURN __declspec(noreturn)
#define _ALIGNAS(x) __declspec(align(x))
#define _ALIGNAS_TYPE(x) alignas(x)
#define _LIBCPP_WEAK
#define _LIBCPP_HAS_NO_ASAN
#define _LIBCPP_ALWAYS_INLINE __forceinline
#define _LIBCPP_HAS_NO_VECTOR_EXTENSION
#define _LIBCPP_DISABLE_EXTENSION_WARNING
#elif defined(_LIBCPP_COMPILER_IBM)
#define _ALIGNAS(x) __attribute__((__aligned__(x)))
#define _ALIGNAS_TYPE(x) __attribute__((__aligned__(_LIBCPP_ALIGNOF(x))))
#define _ATTRIBUTE(x) __attribute__((x))
#define _LIBCPP_NORETURN __attribute__((noreturn))
#define _LIBCPP_HAS_NO_UNICODE_CHARS
#define _LIBCPP_HAS_NO_VARIABLE_TEMPLATES
#if defined(_AIX)
#define __MULTILOCALE_API
#endif
#define _LIBCPP_HAS_NO_ASAN
#define _LIBCPP_ALWAYS_INLINE __attribute__ ((__always_inline__))
#define _LIBCPP_HAS_NO_VECTOR_EXTENSION
#define _LIBCPP_DISABLE_EXTENSION_WARNING
#endif // _LIBCPP_COMPILER_[CLANG|GCC|MSVC|IBM]
#if defined(_LIBCPP_OBJECT_FORMAT_COFF)
#ifdef _DLL
# define _LIBCPP_CRT_FUNC __declspec(dllimport)
#else
# define _LIBCPP_CRT_FUNC
#endif
#if defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS)
# define _LIBCPP_DLL_VIS
# define _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS
# define _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS
# define _LIBCPP_OVERRIDABLE_FUNC_VIS
# define _LIBCPP_EXPORTED_FROM_ABI
#elif defined(_LIBCPP_BUILDING_LIBRARY)
# define _LIBCPP_DLL_VIS __declspec(dllexport)
# if defined(__MINGW32__)
# define _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS _LIBCPP_DLL_VIS
# define _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS
# else
# define _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS
# define _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS _LIBCPP_DLL_VIS
# endif
# define _LIBCPP_OVERRIDABLE_FUNC_VIS _LIBCPP_DLL_VIS
# define _LIBCPP_EXPORTED_FROM_ABI __declspec(dllexport)
#else
# define _LIBCPP_DLL_VIS __declspec(dllimport)
# define _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS _LIBCPP_DLL_VIS
# define _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS
# define _LIBCPP_OVERRIDABLE_FUNC_VIS
# define _LIBCPP_EXPORTED_FROM_ABI __declspec(dllimport)
#endif
#define _LIBCPP_TYPE_VIS _LIBCPP_DLL_VIS
#define _LIBCPP_FUNC_VIS _LIBCPP_DLL_VIS
#define _LIBCPP_EXCEPTION_ABI _LIBCPP_DLL_VIS
#define _LIBCPP_HIDDEN
#define _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
#define _LIBCPP_TEMPLATE_VIS
#define _LIBCPP_ENUM_VIS
#endif // defined(_LIBCPP_OBJECT_FORMAT_COFF)
#ifndef _LIBCPP_HIDDEN
# if !defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS)
# define _LIBCPP_HIDDEN __attribute__ ((__visibility__("hidden")))
# else
# define _LIBCPP_HIDDEN
# endif
#endif
#ifndef _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
# if !defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS)
// The inline should be removed once PR32114 is resolved
# define _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS inline _LIBCPP_HIDDEN
# else
# define _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
# endif
#endif
#ifndef _LIBCPP_FUNC_VIS
# if !defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS)
# define _LIBCPP_FUNC_VIS __attribute__ ((__visibility__("default")))
# else
# define _LIBCPP_FUNC_VIS
# endif
#endif
#ifndef _LIBCPP_TYPE_VIS
# if !defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS)
# define _LIBCPP_TYPE_VIS __attribute__ ((__visibility__("default")))
# else
# define _LIBCPP_TYPE_VIS
# endif
#endif
#ifndef _LIBCPP_TEMPLATE_VIS
# if !defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS)
# if __has_attribute(__type_visibility__)
# define _LIBCPP_TEMPLATE_VIS __attribute__ ((__type_visibility__("default")))
# else
# define _LIBCPP_TEMPLATE_VIS __attribute__ ((__visibility__("default")))
# endif
# else
# define _LIBCPP_TEMPLATE_VIS
# endif
#endif
#ifndef _LIBCPP_EXPORTED_FROM_ABI
# if !defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS)
# define _LIBCPP_EXPORTED_FROM_ABI __attribute__((__visibility__("default")))
# else
# define _LIBCPP_EXPORTED_FROM_ABI
# endif
#endif
#ifndef _LIBCPP_OVERRIDABLE_FUNC_VIS
#define _LIBCPP_OVERRIDABLE_FUNC_VIS _LIBCPP_FUNC_VIS
#endif
#ifndef _LIBCPP_EXCEPTION_ABI
# if !defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS)
# define _LIBCPP_EXCEPTION_ABI __attribute__ ((__visibility__("default")))
# else
# define _LIBCPP_EXCEPTION_ABI
# endif
#endif
#ifndef _LIBCPP_ENUM_VIS
# if !defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS) && __has_attribute(__type_visibility__)
# define _LIBCPP_ENUM_VIS __attribute__ ((__type_visibility__("default")))
# else
# define _LIBCPP_ENUM_VIS
# endif
#endif
#ifndef _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS
# if !defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS) && __has_attribute(__type_visibility__)
# define _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS __attribute__ ((__visibility__("default")))
# else
# define _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS
# endif
#endif
#ifndef _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS
#define _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS
#endif
#if __has_attribute(internal_linkage)
# define _LIBCPP_INTERNAL_LINKAGE __attribute__ ((internal_linkage))
#else
# define _LIBCPP_INTERNAL_LINKAGE _LIBCPP_ALWAYS_INLINE
#endif
#if __has_attribute(exclude_from_explicit_instantiation)
# define _LIBCPP_EXCLUDE_FROM_EXPLICIT_INSTANTIATION __attribute__ ((__exclude_from_explicit_instantiation__))
#else
// Try to approximate the effect of exclude_from_explicit_instantiation
// (which is that entities are not assumed to be provided by explicit
// template instantiations in the dylib) by always inlining those entities.
# define _LIBCPP_EXCLUDE_FROM_EXPLICIT_INSTANTIATION _LIBCPP_ALWAYS_INLINE
#endif
#ifndef _LIBCPP_HIDE_FROM_ABI_PER_TU
# ifndef _LIBCPP_HIDE_FROM_ABI_PER_TU_BY_DEFAULT
# define _LIBCPP_HIDE_FROM_ABI_PER_TU 0
# else
# define _LIBCPP_HIDE_FROM_ABI_PER_TU 1
# endif
#endif
#ifndef _LIBCPP_HAS_MERGED_TYPEINFO_NAMES_DEFAULT
# ifdef _LIBCPP_OBJECT_FORMAT_COFF // Windows binaries can't merge typeinfos.
# define _LIBCPP_HAS_MERGED_TYPEINFO_NAMES_DEFAULT 0
#else
// TODO: This isn't strictly correct on ELF platforms due to llvm.org/PR37398
// And we should consider defaulting to OFF.
# define _LIBCPP_HAS_MERGED_TYPEINFO_NAMES_DEFAULT 1
#endif
#endif
#ifndef _LIBCPP_HIDE_FROM_ABI
# if _LIBCPP_HIDE_FROM_ABI_PER_TU
# define _LIBCPP_HIDE_FROM_ABI _LIBCPP_HIDDEN _LIBCPP_INTERNAL_LINKAGE
# else
# define _LIBCPP_HIDE_FROM_ABI _LIBCPP_HIDDEN _LIBCPP_EXCLUDE_FROM_EXPLICIT_INSTANTIATION
# endif
#endif
#ifdef _LIBCPP_BUILDING_LIBRARY
# if _LIBCPP_ABI_VERSION > 1
# define _LIBCPP_HIDE_FROM_ABI_AFTER_V1 _LIBCPP_HIDE_FROM_ABI
# else
# define _LIBCPP_HIDE_FROM_ABI_AFTER_V1
# endif
#else
# define _LIBCPP_HIDE_FROM_ABI_AFTER_V1 _LIBCPP_HIDE_FROM_ABI
#endif
// Just so we can migrate to the new macros gradually.
#define _LIBCPP_INLINE_VISIBILITY _LIBCPP_HIDE_FROM_ABI
// Inline namespaces are available in Clang/GCC/MSVC regardless of C++ dialect.
#define _LIBCPP_BEGIN_NAMESPACE_STD namespace std { inline namespace _LIBCPP_ABI_NAMESPACE {
#define _LIBCPP_END_NAMESPACE_STD } }
#define _VSTD std::_LIBCPP_ABI_NAMESPACE
_LIBCPP_BEGIN_NAMESPACE_STD _LIBCPP_END_NAMESPACE_STD
#if _LIBCPP_STD_VER >= 17
#define _LIBCPP_BEGIN_NAMESPACE_FILESYSTEM \
_LIBCPP_BEGIN_NAMESPACE_STD inline namespace __fs { namespace filesystem {
#else
#define _LIBCPP_BEGIN_NAMESPACE_FILESYSTEM \
_LIBCPP_BEGIN_NAMESPACE_STD namespace __fs { namespace filesystem {
#endif
#define _LIBCPP_END_NAMESPACE_FILESYSTEM \
_LIBCPP_END_NAMESPACE_STD } }
#define _VSTD_FS _VSTD::__fs::filesystem
#ifndef _LIBCPP_PREFERRED_OVERLOAD
# if __has_attribute(__enable_if__)
# define _LIBCPP_PREFERRED_OVERLOAD __attribute__ ((__enable_if__(true, "")))
# endif
#endif
#ifndef _LIBCPP_HAS_NO_NOEXCEPT
# define _NOEXCEPT noexcept
# define _NOEXCEPT_(x) noexcept(x)
#else
# define _NOEXCEPT throw()
# define _NOEXCEPT_(x)
#endif
#ifdef _LIBCPP_HAS_NO_UNICODE_CHARS
typedef unsigned short char16_t;
typedef unsigned int char32_t;
#endif // _LIBCPP_HAS_NO_UNICODE_CHARS
#ifndef __SIZEOF_INT128__
#define _LIBCPP_HAS_NO_INT128
#endif
#ifdef _LIBCPP_CXX03_LANG
# define static_assert(...) _Static_assert(__VA_ARGS__)
# define decltype(...) __decltype(__VA_ARGS__)
#endif // _LIBCPP_CXX03_LANG
#ifdef _LIBCPP_CXX03_LANG
# define _LIBCPP_CONSTEXPR
#else
# define _LIBCPP_CONSTEXPR constexpr
#endif
#ifdef _LIBCPP_CXX03_LANG
# define _LIBCPP_DEFAULT {}
#else
# define _LIBCPP_DEFAULT = default;
#endif
#ifdef _LIBCPP_CXX03_LANG
# define _LIBCPP_EQUAL_DELETE
#else
# define _LIBCPP_EQUAL_DELETE = delete
#endif
#ifdef __GNUC__
# define _LIBCPP_NOALIAS __attribute__((__malloc__))
#else
# define _LIBCPP_NOALIAS
#endif
#if __has_feature(cxx_explicit_conversions) || defined(__IBMCPP__) || \
(!defined(_LIBCPP_CXX03_LANG) && defined(__GNUC__)) // All supported GCC versions
# define _LIBCPP_EXPLICIT explicit
#else
# define _LIBCPP_EXPLICIT
#endif
#if !__has_builtin(__builtin_operator_new) || !__has_builtin(__builtin_operator_delete)
#define _LIBCPP_HAS_NO_BUILTIN_OPERATOR_NEW_DELETE
#endif
#ifdef _LIBCPP_HAS_NO_STRONG_ENUMS
# define _LIBCPP_DECLARE_STRONG_ENUM(x) struct _LIBCPP_TYPE_VIS x { enum __lx
# define _LIBCPP_DECLARE_STRONG_ENUM_EPILOG(x) \
__lx __v_; \
_LIBCPP_INLINE_VISIBILITY x(__lx __v) : __v_(__v) {} \
_LIBCPP_INLINE_VISIBILITY explicit x(int __v) : __v_(static_cast<__lx>(__v)) {} \
_LIBCPP_INLINE_VISIBILITY operator int() const {return __v_;} \
};
#else // _LIBCPP_HAS_NO_STRONG_ENUMS
# define _LIBCPP_DECLARE_STRONG_ENUM(x) enum class _LIBCPP_ENUM_VIS x
# define _LIBCPP_DECLARE_STRONG_ENUM_EPILOG(x)
#endif // _LIBCPP_HAS_NO_STRONG_ENUMS
#ifdef _LIBCPP_DEBUG
# if _LIBCPP_DEBUG == 0
# define _LIBCPP_DEBUG_LEVEL 1
# elif _LIBCPP_DEBUG == 1
# define _LIBCPP_DEBUG_LEVEL 2
# else
# error Supported values for _LIBCPP_DEBUG are 0 and 1
# endif
# if !defined(_LIBCPP_BUILDING_LIBRARY)
# define _LIBCPP_EXTERN_TEMPLATE(...)
# endif
#endif
#ifdef _LIBCPP_DISABLE_EXTERN_TEMPLATE
#define _LIBCPP_EXTERN_TEMPLATE(...)
#define _LIBCPP_EXTERN_TEMPLATE2(...)
#endif
#ifndef _LIBCPP_EXTERN_TEMPLATE
#define _LIBCPP_EXTERN_TEMPLATE(...) extern template __VA_ARGS__;
#endif
#ifndef _LIBCPP_EXTERN_TEMPLATE2
#define _LIBCPP_EXTERN_TEMPLATE2(...) extern template __VA_ARGS__;
#endif
#if defined(__APPLE__) || defined(__FreeBSD__) || defined(_LIBCPP_MSVCRT_LIKE) || \
defined(__sun__) || defined(__NetBSD__) || defined(__CloudABI__)
#define _LIBCPP_LOCALE__L_EXTENSIONS 1
#endif
#if defined(__unix__) || (defined(__APPLE__) && defined(__MACH__))
// Most unix variants have catopen. These are the specific ones that don't.
# if !defined(__BIONIC__) && !defined(_NEWLIB_VERSION) && !defined(__COSMOPOLITAN__)
# define _LIBCPP_HAS_CATOPEN 1
# endif
#endif
#ifdef __FreeBSD__
#define _DECLARE_C99_LDBL_MATH 1
#endif
// If we are getting operator new from the MSVC CRT, then allocation overloads
// for align_val_t were added in 19.12, aka VS 2017 version 15.3.
#if defined(_LIBCPP_MSVCRT) && defined(_MSC_VER) && _MSC_VER < 1912
# define _LIBCPP_HAS_NO_LIBRARY_ALIGNED_ALLOCATION
#elif defined(_LIBCPP_ABI_VCRUNTIME) && !defined(__cpp_aligned_new)
// We're deferring to Microsoft's STL to provide aligned new et al. We don't
// have it unless the language feature test macro is defined.
# define _LIBCPP_HAS_NO_LIBRARY_ALIGNED_ALLOCATION
#endif
#if defined(__APPLE__)
# if !defined(__MAC_OS_X_VERSION_MIN_REQUIRED) && \
defined(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__)
# define __MAC_OS_X_VERSION_MIN_REQUIRED __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__
# endif
#endif // defined(__APPLE__)
#if !defined(_LIBCPP_HAS_NO_ALIGNED_ALLOCATION) && \
(defined(_LIBCPP_HAS_NO_LIBRARY_ALIGNED_ALLOCATION) || \
(!defined(__cpp_aligned_new) || __cpp_aligned_new < 201606))
# define _LIBCPP_HAS_NO_ALIGNED_ALLOCATION
#endif
#if defined(__APPLE__) || defined(__FreeBSD__)
#define _LIBCPP_HAS_DEFAULTRUNELOCALE
#endif
#if defined(__APPLE__) || defined(__FreeBSD__) || defined(__sun__)
#define _LIBCPP_WCTYPE_IS_MASK
#endif
#if _LIBCPP_STD_VER <= 17 || !defined(__cpp_char8_t)
#define _LIBCPP_NO_HAS_CHAR8_T
#endif
// Deprecation macros.
//
// Deprecations warnings are always enabled, except when users explicitly opt-out
// by defining _LIBCPP_DISABLE_DEPRECATION_WARNINGS.
#if !defined(_LIBCPP_DISABLE_DEPRECATION_WARNINGS)
# if __has_attribute(deprecated)
# define _LIBCPP_DEPRECATED __attribute__ ((deprecated))
# elif _LIBCPP_STD_VER > 11
# define _LIBCPP_DEPRECATED [[deprecated]]
# else
# define _LIBCPP_DEPRECATED
# endif
#else
# define _LIBCPP_DEPRECATED
#endif
#if !defined(_LIBCPP_CXX03_LANG)
# define _LIBCPP_DEPRECATED_IN_CXX11 _LIBCPP_DEPRECATED
#else
# define _LIBCPP_DEPRECATED_IN_CXX11
#endif
#if _LIBCPP_STD_VER >= 14
# define _LIBCPP_DEPRECATED_IN_CXX14 _LIBCPP_DEPRECATED
#else
# define _LIBCPP_DEPRECATED_IN_CXX14
#endif
#if _LIBCPP_STD_VER >= 17
# define _LIBCPP_DEPRECATED_IN_CXX17 _LIBCPP_DEPRECATED
#else
# define _LIBCPP_DEPRECATED_IN_CXX17
#endif
// Macros to enter and leave a state where deprecation warnings are suppressed.
#if !defined(_LIBCPP_SUPPRESS_DEPRECATED_PUSH) && \
(defined(_LIBCPP_COMPILER_CLANG) || defined(_LIBCPP_COMPILER_GCC))
# define _LIBCPP_SUPPRESS_DEPRECATED_PUSH \
_Pragma("GCC diagnostic push") \
_Pragma("GCC diagnostic ignored \"-Wdeprecated\"")
# define _LIBCPP_SUPPRESS_DEPRECATED_POP \
_Pragma("GCC diagnostic pop")
#endif
#if !defined(_LIBCPP_SUPPRESS_DEPRECATED_PUSH)
# define _LIBCPP_SUPPRESS_DEPRECATED_PUSH
# define _LIBCPP_SUPPRESS_DEPRECATED_POP
#endif
#if _LIBCPP_STD_VER <= 11
# define _LIBCPP_EXPLICIT_AFTER_CXX11
#else
# define _LIBCPP_EXPLICIT_AFTER_CXX11 explicit
#endif
#if _LIBCPP_STD_VER > 11 && !defined(_LIBCPP_HAS_NO_CXX14_CONSTEXPR)
# define _LIBCPP_CONSTEXPR_AFTER_CXX11 constexpr
#else
# define _LIBCPP_CONSTEXPR_AFTER_CXX11
#endif
#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_CXX14_CONSTEXPR)
# define _LIBCPP_CONSTEXPR_AFTER_CXX14 constexpr
#else
# define _LIBCPP_CONSTEXPR_AFTER_CXX14
#endif
#if _LIBCPP_STD_VER > 17 && !defined(_LIBCPP_HAS_NO_CXX14_CONSTEXPR)
# define _LIBCPP_CONSTEXPR_AFTER_CXX17 constexpr
#else
# define _LIBCPP_CONSTEXPR_AFTER_CXX17
#endif
// The _LIBCPP_NODISCARD_ATTRIBUTE should only be used to define other
// NODISCARD macros to the correct attribute.
#if __has_cpp_attribute(nodiscard) || defined(_LIBCPP_COMPILER_MSVC)
# define _LIBCPP_NODISCARD_ATTRIBUTE [[nodiscard]]
#elif defined(_LIBCPP_COMPILER_CLANG) && !defined(_LIBCPP_CXX03_LANG)
# define _LIBCPP_NODISCARD_ATTRIBUTE [[clang::warn_unused_result]]
#else
// We can't use GCC's [[gnu::warn_unused_result]] and
// __attribute__((warn_unused_result)), because GCC does not silence them via
// (void) cast.
# define _LIBCPP_NODISCARD_ATTRIBUTE
#endif
// _LIBCPP_NODISCARD_EXT may be used to apply [[nodiscard]] to entities not
// specified as such as an extension.
#if defined(_LIBCPP_ENABLE_NODISCARD) && !defined(_LIBCPP_DISABLE_NODISCARD_EXT)
# define _LIBCPP_NODISCARD_EXT _LIBCPP_NODISCARD_ATTRIBUTE
#else
# define _LIBCPP_NODISCARD_EXT
#endif
#if !defined(_LIBCPP_DISABLE_NODISCARD_AFTER_CXX17) && \
(_LIBCPP_STD_VER > 17 || defined(_LIBCPP_ENABLE_NODISCARD))
# define _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_NODISCARD_ATTRIBUTE
#else
# define _LIBCPP_NODISCARD_AFTER_CXX17
#endif
#if _LIBCPP_STD_VER > 14 && defined(__cpp_inline_variables) && (__cpp_inline_variables >= 201606L)
# define _LIBCPP_INLINE_VAR inline
#else
# define _LIBCPP_INLINE_VAR
#endif
#ifdef _LIBCPP_HAS_NO_RVALUE_REFERENCES
# define _LIBCPP_EXPLICIT_MOVE(x) _VSTD::move(x)
#else
# define _LIBCPP_EXPLICIT_MOVE(x) (x)
#endif
#ifndef _LIBCPP_CONSTEXPR_IF_NODEBUG
#if defined(_LIBCPP_DEBUG) || defined(_LIBCPP_HAS_NO_CXX14_CONSTEXPR)
#define _LIBCPP_CONSTEXPR_IF_NODEBUG
#else
#define _LIBCPP_CONSTEXPR_IF_NODEBUG constexpr
#endif
#endif
#if __has_attribute(no_destroy)
# define _LIBCPP_NO_DESTROY __attribute__((__no_destroy__))
#else
# define _LIBCPP_NO_DESTROY
#endif
#ifndef _LIBCPP_HAS_NO_ASAN
extern "C" _LIBCPP_FUNC_VIS void __sanitizer_annotate_contiguous_container(
const void *, const void *, const void *, const void *);
#endif
// Try to find out if RTTI is disabled.
// g++ and cl.exe have RTTI on by default and define a macro when it is.
// g++ only defines the macro in 4.3.2 and onwards.
#if !defined(_LIBCPP_NO_RTTI)
# if defined(__GNUC__) && \
((__GNUC__ >= 5) || \
(__GNUC__ == 4 && (__GNUC_MINOR__ >= 3 || __GNUC_PATCHLEVEL__ >= 2))) && \
!defined(__GXX_RTTI)
# define _LIBCPP_NO_RTTI
# elif defined(_LIBCPP_COMPILER_MSVC) && !defined(_CPPRTTI)
# define _LIBCPP_NO_RTTI
# endif
#endif
#ifndef _LIBCPP_WEAK
#define _LIBCPP_WEAK __attribute__((__weak__))
#endif
// Thread API
#if !defined(_LIBCPP_HAS_NO_THREADS) && \
!defined(_LIBCPP_HAS_THREAD_API_PTHREAD) && \
!defined(_LIBCPP_HAS_THREAD_API_WIN32) && \
!defined(_LIBCPP_HAS_THREAD_API_EXTERNAL)
# if defined(__FreeBSD__) || \
defined(__Fuchsia__) || \
defined(__wasi__) || \
defined(__NetBSD__) || \
defined(__linux__) || \
defined(__GNU__) || \
defined(__APPLE__) || \
defined(__CloudABI__) || \
defined(__sun__) || \
(defined(__MINGW32__) && __has_include(<pthread.h>))
# define _LIBCPP_HAS_THREAD_API_PTHREAD
# elif defined(_LIBCPP_WIN32API)
# define _LIBCPP_HAS_THREAD_API_WIN32
# else
# error "No thread API"
# endif // _LIBCPP_HAS_THREAD_API
#endif // _LIBCPP_HAS_NO_THREADS
#if defined(_LIBCPP_HAS_THREAD_API_PTHREAD)
#if defined(__ANDROID__) && __ANDROID_API__ >= 30
#define _LIBCPP_HAS_COND_CLOCKWAIT
#elif defined(_LIBCPP_GLIBC_PREREQ)
#if _LIBCPP_GLIBC_PREREQ(2, 30)
#define _LIBCPP_HAS_COND_CLOCKWAIT
#endif
#endif
#endif
#if defined(_LIBCPP_HAS_NO_THREADS) && defined(_LIBCPP_HAS_THREAD_API_PTHREAD)
#error _LIBCPP_HAS_THREAD_API_PTHREAD may only be defined when \
_LIBCPP_HAS_NO_THREADS is not defined.
#endif
#if defined(_LIBCPP_HAS_NO_THREADS) && defined(_LIBCPP_HAS_THREAD_API_EXTERNAL)
#error _LIBCPP_HAS_THREAD_API_EXTERNAL may not be defined when \
_LIBCPP_HAS_NO_THREADS is defined.
#endif
#if defined(_LIBCPP_HAS_NO_MONOTONIC_CLOCK) && !defined(_LIBCPP_HAS_NO_THREADS)
#error _LIBCPP_HAS_NO_MONOTONIC_CLOCK may only be defined when \
_LIBCPP_HAS_NO_THREADS is defined.
#endif
#if defined(__STDCPP_THREADS__) && defined(_LIBCPP_HAS_NO_THREADS)
#error _LIBCPP_HAS_NO_THREADS cannot be set when __STDCPP_THREADS__ is set.
#endif
#if !defined(_LIBCPP_HAS_NO_THREADS) && !defined(__STDCPP_THREADS__)
#define __STDCPP_THREADS__ 1
#endif
// The glibc and Bionic implementation of pthreads implements
// pthread_mutex_destroy as nop for regular mutexes. Additionally, Win32
// mutexes have no destroy mechanism.
//
// This optimization can't be performed on Apple platforms, where
// pthread_mutex_destroy can allow the kernel to release resources.
// See https://llvm.org/D64298 for details.
//
// TODO(EricWF): Enable this optimization on Bionic after speaking to their
// respective stakeholders.
#if (defined(_LIBCPP_HAS_THREAD_API_PTHREAD) && defined(__GLIBC__)) \
|| defined(_LIBCPP_HAS_THREAD_API_WIN32)
# define _LIBCPP_HAS_TRIVIAL_MUTEX_DESTRUCTION
#endif
// Destroying a condvar is a nop on Windows.
//
// This optimization can't be performed on Apple platforms, where
// pthread_cond_destroy can allow the kernel to release resources.
// See https://llvm.org/D64298 for details.
//
// TODO(EricWF): This is potentially true for some pthread implementations
// as well.
#if defined(_LIBCPP_HAS_THREAD_API_WIN32)
# define _LIBCPP_HAS_TRIVIAL_CONDVAR_DESTRUCTION
#endif
// Systems that use capability-based security (FreeBSD with Capsicum,
// Nuxi CloudABI) may only provide local filesystem access (using *at()).
// Functions like open(), rename(), unlink() and stat() should not be
// used, as they attempt to access the global filesystem namespace.
#ifdef __CloudABI__
#define _LIBCPP_HAS_NO_GLOBAL_FILESYSTEM_NAMESPACE
#endif
// CloudABI is intended for running networked services. Processes do not
// have standard input and output channels.
#ifdef __CloudABI__
#define _LIBCPP_HAS_NO_STDIN
#define _LIBCPP_HAS_NO_STDOUT
#endif
// Some systems do not provide gets() in their C library, for security reasons.
#ifndef _LIBCPP_C_HAS_NO_GETS
# if defined(_LIBCPP_MSVCRT) || \
(defined(__FreeBSD_version) && __FreeBSD_version >= 1300043)
# define _LIBCPP_C_HAS_NO_GETS
# endif
#endif
#if defined(__BIONIC__) || defined(__CloudABI__) || \
defined(__Fuchsia__) || defined(__wasi__) || \
defined(_LIBCPP_HAS_MUSL_LIBC) || defined(__COSMOPOLITAN__)
#define _LIBCPP_PROVIDES_DEFAULT_RUNE_TABLE
#endif
// Thread-unsafe functions such as strtok() and localtime()
// are not available.
#ifdef __CloudABI__
#define _LIBCPP_HAS_NO_THREAD_UNSAFE_C_FUNCTIONS
#endif
#if __has_feature(cxx_atomic) || __has_extension(c_atomic) || __has_keyword(_Atomic)
# define _LIBCPP_HAS_C_ATOMIC_IMP
#elif defined(_LIBCPP_COMPILER_GCC)
# define _LIBCPP_HAS_GCC_ATOMIC_IMP
#endif
#if (!defined(_LIBCPP_HAS_C_ATOMIC_IMP) && \
!defined(_LIBCPP_HAS_GCC_ATOMIC_IMP) && \
!defined(_LIBCPP_HAS_EXTERNAL_ATOMIC_IMP)) \
|| defined(_LIBCPP_HAS_NO_THREADS)
# define _LIBCPP_HAS_NO_ATOMIC_HEADER
# define _LIBCPP_ATOMIC_FLAG_TYPE bool
#else
# ifndef _LIBCPP_ATOMIC_FLAG_TYPE
# define _LIBCPP_ATOMIC_FLAG_TYPE bool
# endif
# ifdef _LIBCPP_FREESTANDING
# define _LIBCPP_ATOMIC_ONLY_USE_BUILTINS
# endif
#endif
#ifndef _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK
#define _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK
#endif
#if defined(_LIBCPP_ENABLE_THREAD_SAFETY_ANNOTATIONS)
# if defined(__clang__) && __has_attribute(acquire_capability)
// Work around the attribute handling in clang. When both __declspec and
// __attribute__ are present, the processing goes awry preventing the definition
// of the types.
# if !defined(_LIBCPP_OBJECT_FORMAT_COFF)
# define _LIBCPP_HAS_THREAD_SAFETY_ANNOTATIONS
# endif
# endif
#endif
#if __has_attribute(require_constant_initialization)
# define _LIBCPP_SAFE_STATIC __attribute__((__require_constant_initialization__))
#else
# define _LIBCPP_SAFE_STATIC
#endif
#if !__has_builtin(__builtin_addressof) && _GNUC_VER < 700
#define _LIBCPP_HAS_NO_BUILTIN_ADDRESSOF
#endif
#if !__has_builtin(__builtin_is_constant_evaluated) && _GNUC_VER < 900
#define _LIBCPP_HAS_NO_BUILTIN_IS_CONSTANT_EVALUATED
#endif
#if !defined(_LIBCPP_HAS_NO_OFF_T_FUNCTIONS)
# if defined(_LIBCPP_MSVCRT) || defined(_NEWLIB_VERSION)
# define _LIBCPP_HAS_NO_OFF_T_FUNCTIONS
# endif
#endif
#if __has_attribute(diagnose_if) && !defined(_LIBCPP_DISABLE_ADDITIONAL_DIAGNOSTICS)
# define _LIBCPP_DIAGNOSE_WARNING(...) \
__attribute__((diagnose_if(__VA_ARGS__, "warning")))
# define _LIBCPP_DIAGNOSE_ERROR(...) \
__attribute__((diagnose_if(__VA_ARGS__, "error")))
#else
# define _LIBCPP_DIAGNOSE_WARNING(...)
# define _LIBCPP_DIAGNOSE_ERROR(...)
#endif
// Use a function like macro to imply that it must be followed by a semicolon
#if __cplusplus > 201402L && __has_cpp_attribute(fallthrough)
# define _LIBCPP_FALLTHROUGH() [[fallthrough]]
#elif __has_cpp_attribute(clang::fallthrough)
# define _LIBCPP_FALLTHROUGH() [[clang::fallthrough]]
#elif __has_attribute(fallthough) || _GNUC_VER >= 700
# define _LIBCPP_FALLTHROUGH() __attribute__((__fallthrough__))
#else
# define _LIBCPP_FALLTHROUGH() ((void)0)
#endif
#if __has_attribute(__nodebug__)
#define _LIBCPP_NODEBUG __attribute__((__nodebug__))
#else
#define _LIBCPP_NODEBUG
#endif
#ifndef _LIBCPP_NODEBUG_TYPE
#if __has_attribute(__nodebug__) && \
(defined(_LIBCPP_CLANG_VER) && _LIBCPP_CLANG_VER >= 900)
#define _LIBCPP_NODEBUG_TYPE __attribute__((nodebug))
#else
#define _LIBCPP_NODEBUG_TYPE
#endif
#endif // !defined(_LIBCPP_NODEBUG_TYPE)
#if defined(_LIBCPP_ABI_MICROSOFT) && \
(defined(_LIBCPP_COMPILER_MSVC) || __has_declspec_attribute(empty_bases))
# define _LIBCPP_DECLSPEC_EMPTY_BASES __declspec(empty_bases)
#else
# define _LIBCPP_DECLSPEC_EMPTY_BASES
#endif
#if defined(_LIBCPP_ENABLE_CXX17_REMOVED_FEATURES)
#define _LIBCPP_ENABLE_CXX17_REMOVED_AUTO_PTR
#define _LIBCPP_ENABLE_CXX17_REMOVED_UNEXPECTED_FUNCTIONS
#define _LIBCPP_ENABLE_CXX17_REMOVED_RANDOM_SHUFFLE
#define _LIBCPP_ENABLE_CXX17_REMOVED_BINDERS
#endif // _LIBCPP_ENABLE_CXX17_REMOVED_FEATURES
#if !defined(__cpp_deduction_guides) || __cpp_deduction_guides < 201611
#define _LIBCPP_HAS_NO_DEDUCTION_GUIDES
#endif
#if !__has_keyword(__is_aggregate) && (_GNUC_VER_NEW < 7001)
#define _LIBCPP_HAS_NO_IS_AGGREGATE
#endif
#if !defined(__cpp_coroutines) || __cpp_coroutines < 201703L
#define _LIBCPP_HAS_NO_COROUTINES
#endif
// FIXME: Correct this macro when either (A) a feature test macro for the
// spaceship operator is provided, or (B) a compiler provides a complete
// implementation.
#define _LIBCPP_HAS_NO_SPACESHIP_OPERATOR
// Decide whether to use availability macros.
#if !defined(_LIBCPP_BUILDING_LIBRARY) && \
!defined(_LIBCPP_DISABLE_AVAILABILITY) && \
__has_feature(attribute_availability_with_strict) && \
__has_feature(attribute_availability_in_templates) && \
__has_extension(pragma_clang_attribute_external_declaration)
# ifdef __APPLE__
# define _LIBCPP_USE_AVAILABILITY_APPLE
# endif
#endif
// Define availability macros.
#if defined(_LIBCPP_USE_AVAILABILITY_APPLE)
# define _LIBCPP_AVAILABILITY_SHARED_MUTEX \
__attribute__((availability(macosx,strict,introduced=10.12))) \
__attribute__((availability(ios,strict,introduced=10.0))) \
__attribute__((availability(tvos,strict,introduced=10.0))) \
__attribute__((availability(watchos,strict,introduced=3.0)))
# define _LIBCPP_AVAILABILITY_BAD_OPTIONAL_ACCESS \
__attribute__((availability(macosx,strict,introduced=10.14))) \
__attribute__((availability(ios,strict,introduced=12.0))) \
__attribute__((availability(tvos,strict,introduced=12.0))) \
__attribute__((availability(watchos,strict,introduced=5.0)))
# define _LIBCPP_AVAILABILITY_BAD_VARIANT_ACCESS \
_LIBCPP_AVAILABILITY_BAD_OPTIONAL_ACCESS
# define _LIBCPP_AVAILABILITY_BAD_ANY_CAST \
_LIBCPP_AVAILABILITY_BAD_OPTIONAL_ACCESS
# define _LIBCPP_AVAILABILITY_UNCAUGHT_EXCEPTIONS \
__attribute__((availability(macosx,strict,introduced=10.12))) \
__attribute__((availability(ios,strict,introduced=10.0))) \
__attribute__((availability(tvos,strict,introduced=10.0))) \
__attribute__((availability(watchos,strict,introduced=3.0)))
# define _LIBCPP_AVAILABILITY_SIZED_NEW_DELETE \
__attribute__((availability(macosx,strict,introduced=10.12))) \
__attribute__((availability(ios,strict,introduced=10.0))) \
__attribute__((availability(tvos,strict,introduced=10.0))) \
__attribute__((availability(watchos,strict,introduced=3.0)))
# define _LIBCPP_AVAILABILITY_FUTURE_ERROR \
__attribute__((availability(ios,strict,introduced=6.0)))
# define _LIBCPP_AVAILABILITY_TYPEINFO_VTABLE \
__attribute__((availability(macosx,strict,introduced=10.9))) \
__attribute__((availability(ios,strict,introduced=7.0)))
# define _LIBCPP_AVAILABILITY_LOCALE_CATEGORY \
__attribute__((availability(macosx,strict,introduced=10.9))) \
__attribute__((availability(ios,strict,introduced=7.0)))
# define _LIBCPP_AVAILABILITY_ATOMIC_SHARED_PTR \
__attribute__((availability(macosx,strict,introduced=10.9))) \
__attribute__((availability(ios,strict,introduced=7.0)))
# define _LIBCPP_AVAILABILITY_FILESYSTEM \
__attribute__((availability(macosx,strict,introduced=10.15))) \
__attribute__((availability(ios,strict,introduced=13.0))) \
__attribute__((availability(tvos,strict,introduced=13.0))) \
__attribute__((availability(watchos,strict,introduced=6.0)))
# define _LIBCPP_AVAILABILITY_FILESYSTEM_PUSH \
_Pragma("clang attribute push(__attribute__((availability(macosx,strict,introduced=10.15))), apply_to=any(function,record))") \
_Pragma("clang attribute push(__attribute__((availability(ios,strict,introduced=13.0))), apply_to=any(function,record))") \
_Pragma("clang attribute push(__attribute__((availability(tvos,strict,introduced=13.0))), apply_to=any(function,record))") \
_Pragma("clang attribute push(__attribute__((availability(watchos,strict,introduced=6.0))), apply_to=any(function,record))")
# define _LIBCPP_AVAILABILITY_FILESYSTEM_POP \
_Pragma("clang attribute pop") \
_Pragma("clang attribute pop") \
_Pragma("clang attribute pop") \
_Pragma("clang attribute pop")
#else
# define _LIBCPP_AVAILABILITY_SHARED_MUTEX
# define _LIBCPP_AVAILABILITY_BAD_VARIANT_ACCESS
# define _LIBCPP_AVAILABILITY_BAD_OPTIONAL_ACCESS
# define _LIBCPP_AVAILABILITY_BAD_ANY_CAST
# define _LIBCPP_AVAILABILITY_UNCAUGHT_EXCEPTIONS
# define _LIBCPP_AVAILABILITY_SIZED_NEW_DELETE
# define _LIBCPP_AVAILABILITY_FUTURE_ERROR
# define _LIBCPP_AVAILABILITY_TYPEINFO_VTABLE
# define _LIBCPP_AVAILABILITY_LOCALE_CATEGORY
# define _LIBCPP_AVAILABILITY_ATOMIC_SHARED_PTR
# define _LIBCPP_AVAILABILITY_FILESYSTEM
# define _LIBCPP_AVAILABILITY_FILESYSTEM_PUSH
# define _LIBCPP_AVAILABILITY_FILESYSTEM_POP
#endif
// Define availability that depends on _LIBCPP_NO_EXCEPTIONS.
#ifdef _LIBCPP_NO_EXCEPTIONS
# define _LIBCPP_AVAILABILITY_FUTURE
# define _LIBCPP_AVAILABILITY_THROW_BAD_ANY_CAST
# define _LIBCPP_AVAILABILITY_THROW_BAD_OPTIONAL_ACCESS
# define _LIBCPP_AVAILABILITY_THROW_BAD_VARIANT_ACCESS
#else
# define _LIBCPP_AVAILABILITY_FUTURE _LIBCPP_AVAILABILITY_FUTURE_ERROR
# define _LIBCPP_AVAILABILITY_THROW_BAD_ANY_CAST _LIBCPP_AVAILABILITY_BAD_ANY_CAST
# define _LIBCPP_AVAILABILITY_THROW_BAD_OPTIONAL_ACCESS _LIBCPP_AVAILABILITY_BAD_OPTIONAL_ACCESS
# define _LIBCPP_AVAILABILITY_THROW_BAD_VARIANT_ACCESS _LIBCPP_AVAILABILITY_BAD_VARIANT_ACCESS
#endif
// The stream API was dropped and re-added in the dylib shipped on macOS
// and iOS. We can only assume the dylib to provide these definitions for
// macosx >= 10.9 and ios >= 7.0. Otherwise, the definitions are available
// from the headers, but not from the dylib. Explicit instantiation
// declarations for streams exist conditionally to this; if we provide
// an explicit instantiation declaration and we try to deploy to a dylib
// that does not provide those symbols, we'll get a load-time error.
#if !defined(_LIBCPP_BUILDING_LIBRARY) && \
((defined(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__) && \
__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ < 1090) || \
(defined(__ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__) && \
__ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__ < 70000))
# define _LIBCPP_DO_NOT_ASSUME_STREAMS_EXPLICIT_INSTANTIATION_IN_DYLIB
#endif
#if defined(_LIBCPP_COMPILER_IBM)
#define _LIBCPP_HAS_NO_PRAGMA_PUSH_POP_MACRO
#endif
#if defined(_LIBCPP_HAS_NO_PRAGMA_PUSH_POP_MACRO)
# define _LIBCPP_PUSH_MACROS
# define _LIBCPP_POP_MACROS
#else
// Don't warn about macro conflicts when we can restore them at the
// end of the header.
# ifndef _LIBCPP_DISABLE_MACRO_CONFLICT_WARNINGS
# define _LIBCPP_DISABLE_MACRO_CONFLICT_WARNINGS
# endif
# if defined(_LIBCPP_COMPILER_MSVC)
# define _LIBCPP_PUSH_MACROS \
__pragma(push_macro("min")) \
__pragma(push_macro("max"))
# define _LIBCPP_POP_MACROS \
__pragma(pop_macro("min")) \
__pragma(pop_macro("max"))
# else
# define _LIBCPP_PUSH_MACROS \
_Pragma("push_macro(\"min\")") \
_Pragma("push_macro(\"max\")")
# define _LIBCPP_POP_MACROS \
_Pragma("pop_macro(\"min\")") \
_Pragma("pop_macro(\"max\")")
# endif
#endif // defined(_LIBCPP_HAS_NO_PRAGMA_PUSH_POP_MACRO)
#ifndef _LIBCPP_NO_AUTO_LINK
# if defined(_LIBCPP_ABI_MICROSOFT) && !defined(_LIBCPP_BUILDING_LIBRARY)
# if defined(_DLL)
# pragma comment(lib, "c++.lib")
# else
# pragma comment(lib, "libc++.lib")
# endif
# endif // defined(_LIBCPP_ABI_MICROSOFT) && !defined(_LIBCPP_BUILDING_LIBRARY)
#endif // _LIBCPP_NO_AUTO_LINK
#define _LIBCPP_UNUSED_VAR(x) ((void)(x))
// Configures the fopen close-on-exec mode character, if any. This string will
// be appended to any mode string used by fstream for fopen/fdopen.
//
// Not all platforms support this, but it helps avoid fd-leaks on platforms that
// do.
#if defined(__BIONIC__)
# define _LIBCPP_FOPEN_CLOEXEC_MODE "e"
#else
# define _LIBCPP_FOPEN_CLOEXEC_MODE
#endif
#endif // __cplusplus
#endif // _LIBCPP_CONFIG
| 49,229 | 1,432 | jart/cosmopolitan | false |
cosmopolitan/third_party/libcxx/README.cosmo | DESCRIPTION
LLVM's C++ Standard Template Library
ORIGIN
[email protected]:llvm-mirror/libcxx.git
commit 78d6a7767ed57b50122a161b91f59f19c9bd0d19
Author: Zoe Carver <[email protected]>
Date: Tue Oct 22 15:16:49 2019 +0000
LOCAL CHANGES
- Break apart locale.cpp due to its outrageous build times
| 312 | 15 | jart/cosmopolitan | false |
cosmopolitan/third_party/libcxx/compare | // -*- C++ -*-
// clang-format off
//===-------------------------- compare -----------------------------------===//
//
// 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_COMPARE
#define _LIBCPP_COMPARE
/*
compare synopsis
namespace std {
// [cmp.categories], comparison category types
class weak_equality;
class strong_equality;
class partial_ordering;
class weak_ordering;
class strong_ordering;
// named comparison functions
constexpr bool is_eq (weak_equality cmp) noexcept { return cmp == 0; }
constexpr bool is_neq (weak_equality cmp) noexcept { return cmp != 0; }
constexpr bool is_lt (partial_ordering cmp) noexcept { return cmp < 0; }
constexpr bool is_lteq(partial_ordering cmp) noexcept { return cmp <= 0; }
constexpr bool is_gt (partial_ordering cmp) noexcept { return cmp > 0; }
constexpr bool is_gteq(partial_ordering cmp) noexcept { return cmp >= 0; }
// [cmp.common], common comparison category type
template<class... Ts>
struct common_comparison_category {
using type = see below;
};
template<class... Ts>
using common_comparison_category_t = typename common_comparison_category<Ts...>::type;
// [cmp.alg], comparison algorithms
template<class T> constexpr strong_ordering strong_order(const T& a, const T& b);
template<class T> constexpr weak_ordering weak_order(const T& a, const T& b);
template<class T> constexpr partial_ordering partial_order(const T& a, const T& b);
template<class T> constexpr strong_equality strong_equal(const T& a, const T& b);
template<class T> constexpr weak_equality weak_equal(const T& a, const T& b);
}
*/
#include "third_party/libcxx/__config"
#include "third_party/libcxx/type_traits"
#include "third_party/libcxx/array"
#ifndef _LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER
#pragma GCC system_header
#endif
_LIBCPP_BEGIN_NAMESPACE_STD
#if _LIBCPP_STD_VER > 17
// exposition only
enum class _LIBCPP_ENUM_VIS _EqResult : unsigned char {
__zero = 0,
__equal = __zero,
__equiv = __equal,
__nonequal = 1,
__nonequiv = __nonequal
};
enum class _LIBCPP_ENUM_VIS _OrdResult : signed char {
__less = -1,
__greater = 1
};
enum class _LIBCPP_ENUM_VIS _NCmpResult : signed char {
__unordered = -127
};
struct _CmpUnspecifiedType;
using _CmpUnspecifiedParam = void (_CmpUnspecifiedType::*)();
class weak_equality {
_LIBCPP_INLINE_VISIBILITY
constexpr explicit weak_equality(_EqResult __val) noexcept : __value_(__val) {}
public:
static const weak_equality equivalent;
static const weak_equality nonequivalent;
_LIBCPP_INLINE_VISIBILITY friend constexpr bool operator==(weak_equality __v, _CmpUnspecifiedParam) noexcept;
_LIBCPP_INLINE_VISIBILITY friend constexpr bool operator==(_CmpUnspecifiedParam, weak_equality __v) noexcept;
_LIBCPP_INLINE_VISIBILITY friend constexpr bool operator!=(weak_equality __v, _CmpUnspecifiedParam) noexcept;
_LIBCPP_INLINE_VISIBILITY friend constexpr bool operator!=(_CmpUnspecifiedParam, weak_equality __v) noexcept;
#ifndef _LIBCPP_HAS_NO_SPACESHIP_OPERATOR
_LIBCPP_INLINE_VISIBILITY friend constexpr weak_equality operator<=>(weak_equality __v, _CmpUnspecifiedParam) noexcept;
_LIBCPP_INLINE_VISIBILITY friend constexpr weak_equality operator<=>(_CmpUnspecifiedParam, weak_equality __v) noexcept;
#endif
private:
_EqResult __value_;
};
_LIBCPP_INLINE_VAR constexpr weak_equality weak_equality::equivalent(_EqResult::__equiv);
_LIBCPP_INLINE_VAR constexpr weak_equality weak_equality::nonequivalent(_EqResult::__nonequiv);
_LIBCPP_INLINE_VISIBILITY
inline constexpr bool operator==(weak_equality __v, _CmpUnspecifiedParam) noexcept {
return __v.__value_ == _EqResult::__zero;
}
_LIBCPP_INLINE_VISIBILITY
inline constexpr bool operator==(_CmpUnspecifiedParam, weak_equality __v) noexcept {
return __v.__value_ == _EqResult::__zero;
}
_LIBCPP_INLINE_VISIBILITY
inline constexpr bool operator!=(weak_equality __v, _CmpUnspecifiedParam) noexcept {
return __v.__value_ != _EqResult::__zero;
}
_LIBCPP_INLINE_VISIBILITY
inline constexpr bool operator!=(_CmpUnspecifiedParam, weak_equality __v) noexcept {
return __v.__value_ != _EqResult::__zero;
}
#ifndef _LIBCPP_HAS_NO_SPACESHIP_OPERATOR
_LIBCPP_INLINE_VISIBILITY
inline constexpr weak_equality operator<=>(weak_equality __v, _CmpUnspecifiedParam) noexcept {
return __v;
}
_LIBCPP_INLINE_VISIBILITY
inline constexpr weak_equality operator<=>(_CmpUnspecifiedParam, weak_equality __v) noexcept {
return __v;
}
#endif
class strong_equality {
_LIBCPP_INLINE_VISIBILITY
explicit constexpr strong_equality(_EqResult __val) noexcept : __value_(__val) {}
public:
static const strong_equality equal;
static const strong_equality nonequal;
static const strong_equality equivalent;
static const strong_equality nonequivalent;
// conversion
_LIBCPP_INLINE_VISIBILITY constexpr operator weak_equality() const noexcept {
return __value_ == _EqResult::__zero ? weak_equality::equivalent
: weak_equality::nonequivalent;
}
// comparisons
_LIBCPP_INLINE_VISIBILITY friend constexpr bool operator==(strong_equality __v, _CmpUnspecifiedParam) noexcept;
_LIBCPP_INLINE_VISIBILITY friend constexpr bool operator!=(strong_equality __v, _CmpUnspecifiedParam) noexcept;
_LIBCPP_INLINE_VISIBILITY friend constexpr bool operator==(_CmpUnspecifiedParam, strong_equality __v) noexcept;
_LIBCPP_INLINE_VISIBILITY friend constexpr bool operator!=(_CmpUnspecifiedParam, strong_equality __v) noexcept;
#ifndef _LIBCPP_HAS_NO_SPACESHIP_OPERATOR
_LIBCPP_INLINE_VISIBILITY friend constexpr strong_equality operator<=>(strong_equality __v, _CmpUnspecifiedParam) noexcept;
_LIBCPP_INLINE_VISIBILITY friend constexpr strong_equality operator<=>(_CmpUnspecifiedParam, strong_equality __v) noexcept;
#endif
private:
_EqResult __value_;
};
_LIBCPP_INLINE_VAR constexpr strong_equality strong_equality::equal(_EqResult::__equal);
_LIBCPP_INLINE_VAR constexpr strong_equality strong_equality::nonequal(_EqResult::__nonequal);
_LIBCPP_INLINE_VAR constexpr strong_equality strong_equality::equivalent(_EqResult::__equiv);
_LIBCPP_INLINE_VAR constexpr strong_equality strong_equality::nonequivalent(_EqResult::__nonequiv);
_LIBCPP_INLINE_VISIBILITY
constexpr bool operator==(strong_equality __v, _CmpUnspecifiedParam) noexcept {
return __v.__value_ == _EqResult::__zero;
}
_LIBCPP_INLINE_VISIBILITY
constexpr bool operator==(_CmpUnspecifiedParam, strong_equality __v) noexcept {
return __v.__value_ == _EqResult::__zero;
}
_LIBCPP_INLINE_VISIBILITY
constexpr bool operator!=(strong_equality __v, _CmpUnspecifiedParam) noexcept {
return __v.__value_ != _EqResult::__zero;
}
_LIBCPP_INLINE_VISIBILITY
constexpr bool operator!=(_CmpUnspecifiedParam, strong_equality __v) noexcept {
return __v.__value_ != _EqResult::__zero;
}
#ifndef _LIBCPP_HAS_NO_SPACESHIP_OPERATOR
_LIBCPP_INLINE_VISIBILITY
constexpr strong_equality operator<=>(strong_equality __v, _CmpUnspecifiedParam) noexcept {
return __v;
}
_LIBCPP_INLINE_VISIBILITY
constexpr strong_equality operator<=>(_CmpUnspecifiedParam, strong_equality __v) noexcept {
return __v;
}
#endif // _LIBCPP_HAS_NO_SPACESHIP_OPERATOR
class partial_ordering {
using _ValueT = signed char;
_LIBCPP_INLINE_VISIBILITY
explicit constexpr partial_ordering(_EqResult __v) noexcept
: __value_(_ValueT(__v)) {}
_LIBCPP_INLINE_VISIBILITY
explicit constexpr partial_ordering(_OrdResult __v) noexcept
: __value_(_ValueT(__v)) {}
_LIBCPP_INLINE_VISIBILITY
explicit constexpr partial_ordering(_NCmpResult __v) noexcept
: __value_(_ValueT(__v)) {}
constexpr bool __is_ordered() const noexcept {
return __value_ != _ValueT(_NCmpResult::__unordered);
}
public:
// valid values
static const partial_ordering less;
static const partial_ordering equivalent;
static const partial_ordering greater;
static const partial_ordering unordered;
// conversion
constexpr operator weak_equality() const noexcept {
return __value_ == 0 ? weak_equality::equivalent : weak_equality::nonequivalent;
}
// comparisons
_LIBCPP_INLINE_VISIBILITY friend constexpr bool operator==(partial_ordering __v, _CmpUnspecifiedParam) noexcept;
_LIBCPP_INLINE_VISIBILITY friend constexpr bool operator!=(partial_ordering __v, _CmpUnspecifiedParam) noexcept;
_LIBCPP_INLINE_VISIBILITY friend constexpr bool operator< (partial_ordering __v, _CmpUnspecifiedParam) noexcept;
_LIBCPP_INLINE_VISIBILITY friend constexpr bool operator<=(partial_ordering __v, _CmpUnspecifiedParam) noexcept;
_LIBCPP_INLINE_VISIBILITY friend constexpr bool operator> (partial_ordering __v, _CmpUnspecifiedParam) noexcept;
_LIBCPP_INLINE_VISIBILITY friend constexpr bool operator>=(partial_ordering __v, _CmpUnspecifiedParam) noexcept;
_LIBCPP_INLINE_VISIBILITY friend constexpr bool operator==(_CmpUnspecifiedParam, partial_ordering __v) noexcept;
_LIBCPP_INLINE_VISIBILITY friend constexpr bool operator!=(_CmpUnspecifiedParam, partial_ordering __v) noexcept;
_LIBCPP_INLINE_VISIBILITY friend constexpr bool operator< (_CmpUnspecifiedParam, partial_ordering __v) noexcept;
_LIBCPP_INLINE_VISIBILITY friend constexpr bool operator<=(_CmpUnspecifiedParam, partial_ordering __v) noexcept;
_LIBCPP_INLINE_VISIBILITY friend constexpr bool operator> (_CmpUnspecifiedParam, partial_ordering __v) noexcept;
_LIBCPP_INLINE_VISIBILITY friend constexpr bool operator>=(_CmpUnspecifiedParam, partial_ordering __v) noexcept;
#ifndef _LIBCPP_HAS_NO_SPACESHIP_OPERATOR
_LIBCPP_INLINE_VISIBILITY friend constexpr partial_ordering operator<=>(partial_ordering __v, _CmpUnspecifiedParam) noexcept;
_LIBCPP_INLINE_VISIBILITY friend constexpr partial_ordering operator<=>(_CmpUnspecifiedParam, partial_ordering __v) noexcept;
#endif
private:
_ValueT __value_;
};
_LIBCPP_INLINE_VAR constexpr partial_ordering partial_ordering::less(_OrdResult::__less);
_LIBCPP_INLINE_VAR constexpr partial_ordering partial_ordering::equivalent(_EqResult::__equiv);
_LIBCPP_INLINE_VAR constexpr partial_ordering partial_ordering::greater(_OrdResult::__greater);
_LIBCPP_INLINE_VAR constexpr partial_ordering partial_ordering::unordered(_NCmpResult ::__unordered);
_LIBCPP_INLINE_VISIBILITY
constexpr bool operator==(partial_ordering __v, _CmpUnspecifiedParam) noexcept {
return __v.__is_ordered() && __v.__value_ == 0;
}
_LIBCPP_INLINE_VISIBILITY
constexpr bool operator< (partial_ordering __v, _CmpUnspecifiedParam) noexcept {
return __v.__is_ordered() && __v.__value_ < 0;
}
_LIBCPP_INLINE_VISIBILITY
constexpr bool operator<=(partial_ordering __v, _CmpUnspecifiedParam) noexcept {
return __v.__is_ordered() && __v.__value_ <= 0;
}
_LIBCPP_INLINE_VISIBILITY
constexpr bool operator> (partial_ordering __v, _CmpUnspecifiedParam) noexcept {
return __v.__is_ordered() && __v.__value_ > 0;
}
_LIBCPP_INLINE_VISIBILITY
constexpr bool operator>=(partial_ordering __v, _CmpUnspecifiedParam) noexcept {
return __v.__is_ordered() && __v.__value_ >= 0;
}
_LIBCPP_INLINE_VISIBILITY
constexpr bool operator==(_CmpUnspecifiedParam, partial_ordering __v) noexcept {
return __v.__is_ordered() && 0 == __v.__value_;
}
_LIBCPP_INLINE_VISIBILITY
constexpr bool operator< (_CmpUnspecifiedParam, partial_ordering __v) noexcept {
return __v.__is_ordered() && 0 < __v.__value_;
}
_LIBCPP_INLINE_VISIBILITY
constexpr bool operator<=(_CmpUnspecifiedParam, partial_ordering __v) noexcept {
return __v.__is_ordered() && 0 <= __v.__value_;
}
_LIBCPP_INLINE_VISIBILITY
constexpr bool operator> (_CmpUnspecifiedParam, partial_ordering __v) noexcept {
return __v.__is_ordered() && 0 > __v.__value_;
}
_LIBCPP_INLINE_VISIBILITY
constexpr bool operator>=(_CmpUnspecifiedParam, partial_ordering __v) noexcept {
return __v.__is_ordered() && 0 >= __v.__value_;
}
_LIBCPP_INLINE_VISIBILITY
constexpr bool operator!=(partial_ordering __v, _CmpUnspecifiedParam) noexcept {
return !__v.__is_ordered() || __v.__value_ != 0;
}
_LIBCPP_INLINE_VISIBILITY
constexpr bool operator!=(_CmpUnspecifiedParam, partial_ordering __v) noexcept {
return !__v.__is_ordered() || __v.__value_ != 0;
}
#ifndef _LIBCPP_HAS_NO_SPACESHIP_OPERATOR
_LIBCPP_INLINE_VISIBILITY
constexpr partial_ordering operator<=>(partial_ordering __v, _CmpUnspecifiedParam) noexcept {
return __v;
}
_LIBCPP_INLINE_VISIBILITY
constexpr partial_ordering operator<=>(_CmpUnspecifiedParam, partial_ordering __v) noexcept {
return __v < 0 ? partial_ordering::greater : (__v > 0 ? partial_ordering::less : __v);
}
#endif // _LIBCPP_HAS_NO_SPACESHIP_OPERATOR
class weak_ordering {
using _ValueT = signed char;
_LIBCPP_INLINE_VISIBILITY
explicit constexpr weak_ordering(_EqResult __v) noexcept : __value_(_ValueT(__v)) {}
_LIBCPP_INLINE_VISIBILITY
explicit constexpr weak_ordering(_OrdResult __v) noexcept : __value_(_ValueT(__v)) {}
public:
static const weak_ordering less;
static const weak_ordering equivalent;
static const weak_ordering greater;
// conversions
_LIBCPP_INLINE_VISIBILITY
constexpr operator weak_equality() const noexcept {
return __value_ == 0 ? weak_equality::equivalent
: weak_equality::nonequivalent;
}
_LIBCPP_INLINE_VISIBILITY
constexpr operator partial_ordering() const noexcept {
return __value_ == 0 ? partial_ordering::equivalent
: (__value_ < 0 ? partial_ordering::less : partial_ordering::greater);
}
// comparisons
_LIBCPP_INLINE_VISIBILITY friend constexpr bool operator==(weak_ordering __v, _CmpUnspecifiedParam) noexcept;
_LIBCPP_INLINE_VISIBILITY friend constexpr bool operator!=(weak_ordering __v, _CmpUnspecifiedParam) noexcept;
_LIBCPP_INLINE_VISIBILITY friend constexpr bool operator< (weak_ordering __v, _CmpUnspecifiedParam) noexcept;
_LIBCPP_INLINE_VISIBILITY friend constexpr bool operator<=(weak_ordering __v, _CmpUnspecifiedParam) noexcept;
_LIBCPP_INLINE_VISIBILITY friend constexpr bool operator> (weak_ordering __v, _CmpUnspecifiedParam) noexcept;
_LIBCPP_INLINE_VISIBILITY friend constexpr bool operator>=(weak_ordering __v, _CmpUnspecifiedParam) noexcept;
_LIBCPP_INLINE_VISIBILITY friend constexpr bool operator==(_CmpUnspecifiedParam, weak_ordering __v) noexcept;
_LIBCPP_INLINE_VISIBILITY friend constexpr bool operator!=(_CmpUnspecifiedParam, weak_ordering __v) noexcept;
_LIBCPP_INLINE_VISIBILITY friend constexpr bool operator< (_CmpUnspecifiedParam, weak_ordering __v) noexcept;
_LIBCPP_INLINE_VISIBILITY friend constexpr bool operator<=(_CmpUnspecifiedParam, weak_ordering __v) noexcept;
_LIBCPP_INLINE_VISIBILITY friend constexpr bool operator> (_CmpUnspecifiedParam, weak_ordering __v) noexcept;
_LIBCPP_INLINE_VISIBILITY friend constexpr bool operator>=(_CmpUnspecifiedParam, weak_ordering __v) noexcept;
#ifndef _LIBCPP_HAS_NO_SPACESHIP_OPERATOR
_LIBCPP_INLINE_VISIBILITY friend constexpr weak_ordering operator<=>(weak_ordering __v, _CmpUnspecifiedParam) noexcept;
_LIBCPP_INLINE_VISIBILITY friend constexpr weak_ordering operator<=>(_CmpUnspecifiedParam, weak_ordering __v) noexcept;
#endif
private:
_ValueT __value_;
};
_LIBCPP_INLINE_VAR constexpr weak_ordering weak_ordering::less(_OrdResult::__less);
_LIBCPP_INLINE_VAR constexpr weak_ordering weak_ordering::equivalent(_EqResult::__equiv);
_LIBCPP_INLINE_VAR constexpr weak_ordering weak_ordering::greater(_OrdResult::__greater);
_LIBCPP_INLINE_VISIBILITY
constexpr bool operator==(weak_ordering __v, _CmpUnspecifiedParam) noexcept {
return __v.__value_ == 0;
}
_LIBCPP_INLINE_VISIBILITY
constexpr bool operator!=(weak_ordering __v, _CmpUnspecifiedParam) noexcept {
return __v.__value_ != 0;
}
_LIBCPP_INLINE_VISIBILITY
constexpr bool operator< (weak_ordering __v, _CmpUnspecifiedParam) noexcept {
return __v.__value_ < 0;
}
_LIBCPP_INLINE_VISIBILITY
constexpr bool operator<=(weak_ordering __v, _CmpUnspecifiedParam) noexcept {
return __v.__value_ <= 0;
}
_LIBCPP_INLINE_VISIBILITY
constexpr bool operator> (weak_ordering __v, _CmpUnspecifiedParam) noexcept {
return __v.__value_ > 0;
}
_LIBCPP_INLINE_VISIBILITY
constexpr bool operator>=(weak_ordering __v, _CmpUnspecifiedParam) noexcept {
return __v.__value_ >= 0;
}
_LIBCPP_INLINE_VISIBILITY
constexpr bool operator==(_CmpUnspecifiedParam, weak_ordering __v) noexcept {
return 0 == __v.__value_;
}
_LIBCPP_INLINE_VISIBILITY
constexpr bool operator!=(_CmpUnspecifiedParam, weak_ordering __v) noexcept {
return 0 != __v.__value_;
}
_LIBCPP_INLINE_VISIBILITY
constexpr bool operator< (_CmpUnspecifiedParam, weak_ordering __v) noexcept {
return 0 < __v.__value_;
}
_LIBCPP_INLINE_VISIBILITY
constexpr bool operator<=(_CmpUnspecifiedParam, weak_ordering __v) noexcept {
return 0 <= __v.__value_;
}
_LIBCPP_INLINE_VISIBILITY
constexpr bool operator> (_CmpUnspecifiedParam, weak_ordering __v) noexcept {
return 0 > __v.__value_;
}
_LIBCPP_INLINE_VISIBILITY
constexpr bool operator>=(_CmpUnspecifiedParam, weak_ordering __v) noexcept {
return 0 >= __v.__value_;
}
#ifndef _LIBCPP_HAS_NO_SPACESHIP_OPERATOR
_LIBCPP_INLINE_VISIBILITY
constexpr weak_ordering operator<=>(weak_ordering __v, _CmpUnspecifiedParam) noexcept {
return __v;
}
_LIBCPP_INLINE_VISIBILITY
constexpr weak_ordering operator<=>(_CmpUnspecifiedParam, weak_ordering __v) noexcept {
return __v < 0 ? weak_ordering::greater : (__v > 0 ? weak_ordering::less : __v);
}
#endif // _LIBCPP_HAS_NO_SPACESHIP_OPERATOR
class strong_ordering {
using _ValueT = signed char;
_LIBCPP_INLINE_VISIBILITY
explicit constexpr strong_ordering(_EqResult __v) noexcept : __value_(_ValueT(__v)) {}
_LIBCPP_INLINE_VISIBILITY
explicit constexpr strong_ordering(_OrdResult __v) noexcept : __value_(_ValueT(__v)) {}
public:
static const strong_ordering less;
static const strong_ordering equal;
static const strong_ordering equivalent;
static const strong_ordering greater;
// conversions
_LIBCPP_INLINE_VISIBILITY
constexpr operator weak_equality() const noexcept {
return __value_ == 0 ? weak_equality::equivalent
: weak_equality::nonequivalent;
}
_LIBCPP_INLINE_VISIBILITY
constexpr operator strong_equality() const noexcept {
return __value_ == 0 ? strong_equality::equal
: strong_equality::nonequal;
}
_LIBCPP_INLINE_VISIBILITY
constexpr operator partial_ordering() const noexcept {
return __value_ == 0 ? partial_ordering::equivalent
: (__value_ < 0 ? partial_ordering::less : partial_ordering::greater);
}
_LIBCPP_INLINE_VISIBILITY
constexpr operator weak_ordering() const noexcept {
return __value_ == 0 ? weak_ordering::equivalent
: (__value_ < 0 ? weak_ordering::less : weak_ordering::greater);
}
// comparisons
_LIBCPP_INLINE_VISIBILITY friend constexpr bool operator==(strong_ordering __v, _CmpUnspecifiedParam) noexcept;
_LIBCPP_INLINE_VISIBILITY friend constexpr bool operator!=(strong_ordering __v, _CmpUnspecifiedParam) noexcept;
_LIBCPP_INLINE_VISIBILITY friend constexpr bool operator< (strong_ordering __v, _CmpUnspecifiedParam) noexcept;
_LIBCPP_INLINE_VISIBILITY friend constexpr bool operator<=(strong_ordering __v, _CmpUnspecifiedParam) noexcept;
_LIBCPP_INLINE_VISIBILITY friend constexpr bool operator> (strong_ordering __v, _CmpUnspecifiedParam) noexcept;
_LIBCPP_INLINE_VISIBILITY friend constexpr bool operator>=(strong_ordering __v, _CmpUnspecifiedParam) noexcept;
_LIBCPP_INLINE_VISIBILITY friend constexpr bool operator==(_CmpUnspecifiedParam, strong_ordering __v) noexcept;
_LIBCPP_INLINE_VISIBILITY friend constexpr bool operator!=(_CmpUnspecifiedParam, strong_ordering __v) noexcept;
_LIBCPP_INLINE_VISIBILITY friend constexpr bool operator< (_CmpUnspecifiedParam, strong_ordering __v) noexcept;
_LIBCPP_INLINE_VISIBILITY friend constexpr bool operator<=(_CmpUnspecifiedParam, strong_ordering __v) noexcept;
_LIBCPP_INLINE_VISIBILITY friend constexpr bool operator> (_CmpUnspecifiedParam, strong_ordering __v) noexcept;
_LIBCPP_INLINE_VISIBILITY friend constexpr bool operator>=(_CmpUnspecifiedParam, strong_ordering __v) noexcept;
#ifndef _LIBCPP_HAS_NO_SPACESHIP_OPERATOR
_LIBCPP_INLINE_VISIBILITY friend constexpr strong_ordering operator<=>(strong_ordering __v, _CmpUnspecifiedParam) noexcept;
_LIBCPP_INLINE_VISIBILITY friend constexpr strong_ordering operator<=>(_CmpUnspecifiedParam, strong_ordering __v) noexcept;
#endif
private:
_ValueT __value_;
};
_LIBCPP_INLINE_VAR constexpr strong_ordering strong_ordering::less(_OrdResult::__less);
_LIBCPP_INLINE_VAR constexpr strong_ordering strong_ordering::equal(_EqResult::__equal);
_LIBCPP_INLINE_VAR constexpr strong_ordering strong_ordering::equivalent(_EqResult::__equiv);
_LIBCPP_INLINE_VAR constexpr strong_ordering strong_ordering::greater(_OrdResult::__greater);
_LIBCPP_INLINE_VISIBILITY
constexpr bool operator==(strong_ordering __v, _CmpUnspecifiedParam) noexcept {
return __v.__value_ == 0;
}
_LIBCPP_INLINE_VISIBILITY
constexpr bool operator!=(strong_ordering __v, _CmpUnspecifiedParam) noexcept {
return __v.__value_ != 0;
}
_LIBCPP_INLINE_VISIBILITY
constexpr bool operator< (strong_ordering __v, _CmpUnspecifiedParam) noexcept {
return __v.__value_ < 0;
}
_LIBCPP_INLINE_VISIBILITY
constexpr bool operator<=(strong_ordering __v, _CmpUnspecifiedParam) noexcept {
return __v.__value_ <= 0;
}
_LIBCPP_INLINE_VISIBILITY
constexpr bool operator> (strong_ordering __v, _CmpUnspecifiedParam) noexcept {
return __v.__value_ > 0;
}
_LIBCPP_INLINE_VISIBILITY
constexpr bool operator>=(strong_ordering __v, _CmpUnspecifiedParam) noexcept {
return __v.__value_ >= 0;
}
_LIBCPP_INLINE_VISIBILITY
constexpr bool operator==(_CmpUnspecifiedParam, strong_ordering __v) noexcept {
return 0 == __v.__value_;
}
_LIBCPP_INLINE_VISIBILITY
constexpr bool operator!=(_CmpUnspecifiedParam, strong_ordering __v) noexcept {
return 0 != __v.__value_;
}
_LIBCPP_INLINE_VISIBILITY
constexpr bool operator< (_CmpUnspecifiedParam, strong_ordering __v) noexcept {
return 0 < __v.__value_;
}
_LIBCPP_INLINE_VISIBILITY
constexpr bool operator<=(_CmpUnspecifiedParam, strong_ordering __v) noexcept {
return 0 <= __v.__value_;
}
_LIBCPP_INLINE_VISIBILITY
constexpr bool operator> (_CmpUnspecifiedParam, strong_ordering __v) noexcept {
return 0 > __v.__value_;
}
_LIBCPP_INLINE_VISIBILITY
constexpr bool operator>=(_CmpUnspecifiedParam, strong_ordering __v) noexcept {
return 0 >= __v.__value_;
}
#ifndef _LIBCPP_HAS_NO_SPACESHIP_OPERATOR
_LIBCPP_INLINE_VISIBILITY
constexpr strong_ordering operator<=>(strong_ordering __v, _CmpUnspecifiedParam) noexcept {
return __v;
}
_LIBCPP_INLINE_VISIBILITY
constexpr strong_ordering operator<=>(_CmpUnspecifiedParam, strong_ordering __v) noexcept {
return __v < 0 ? strong_ordering::greater : (__v > 0 ? strong_ordering::less : __v);
}
#endif // _LIBCPP_HAS_NO_SPACESHIP_OPERATOR
// named comparison functions
_LIBCPP_INLINE_VISIBILITY
constexpr bool is_eq(weak_equality __cmp) noexcept { return __cmp == 0; }
_LIBCPP_INLINE_VISIBILITY
constexpr bool is_neq(weak_equality __cmp) noexcept { return __cmp != 0; }
_LIBCPP_INLINE_VISIBILITY
constexpr bool is_lt(partial_ordering __cmp) noexcept { return __cmp < 0; }
_LIBCPP_INLINE_VISIBILITY
constexpr bool is_lteq(partial_ordering __cmp) noexcept { return __cmp <= 0; }
_LIBCPP_INLINE_VISIBILITY
constexpr bool is_gt(partial_ordering __cmp) noexcept { return __cmp > 0; }
_LIBCPP_INLINE_VISIBILITY
constexpr bool is_gteq(partial_ordering __cmp) noexcept { return __cmp >= 0; }
namespace __comp_detail {
enum _ClassifyCompCategory : unsigned{
_None,
_WeakEq,
_StrongEq,
_PartialOrd,
_WeakOrd,
_StrongOrd,
_CCC_Size
};
template <class _Tp>
_LIBCPP_INLINE_VISIBILITY
constexpr _ClassifyCompCategory __type_to_enum() noexcept {
if (is_same_v<_Tp, weak_equality>)
return _WeakEq;
if (is_same_v<_Tp, strong_equality>)
return _StrongEq;
if (is_same_v<_Tp, partial_ordering>)
return _PartialOrd;
if (is_same_v<_Tp, weak_ordering>)
return _WeakOrd;
if (is_same_v<_Tp, strong_ordering>)
return _StrongOrd;
return _None;
}
template <size_t _Size>
constexpr _ClassifyCompCategory
__compute_comp_type(std::array<_ClassifyCompCategory, _Size> __types) {
std::array<int, _CCC_Size> __seen = {};
for (auto __type : __types)
++__seen[__type];
if (__seen[_None])
return _None;
if (__seen[_WeakEq])
return _WeakEq;
if (__seen[_StrongEq] && (__seen[_PartialOrd] || __seen[_WeakOrd]))
return _WeakEq;
if (__seen[_StrongEq])
return _StrongEq;
if (__seen[_PartialOrd])
return _PartialOrd;
if (__seen[_WeakOrd])
return _WeakOrd;
return _StrongOrd;
}
template <class ..._Ts>
constexpr auto __get_comp_type() {
using _CCC = _ClassifyCompCategory;
constexpr array<_CCC, sizeof...(_Ts)> __type_kinds{{__comp_detail::__type_to_enum<_Ts>()...}};
constexpr _CCC _Cat = sizeof...(_Ts) == 0 ? _StrongOrd
: __compute_comp_type(__type_kinds);
if constexpr (_Cat == _None)
return void();
else if constexpr (_Cat == _WeakEq)
return weak_equality::equivalent;
else if constexpr (_Cat == _StrongEq)
return strong_equality::equivalent;
else if constexpr (_Cat == _PartialOrd)
return partial_ordering::equivalent;
else if constexpr (_Cat == _WeakOrd)
return weak_ordering::equivalent;
else if constexpr (_Cat == _StrongOrd)
return strong_ordering::equivalent;
else
static_assert(_Cat != _Cat, "unhandled case");
}
} // namespace __comp_detail
// [cmp.common], common comparison category type
template<class... _Ts>
struct _LIBCPP_TEMPLATE_VIS common_comparison_category {
using type = decltype(__comp_detail::__get_comp_type<_Ts...>());
};
template<class... _Ts>
using common_comparison_category_t = typename common_comparison_category<_Ts...>::type;
// [cmp.alg], comparison algorithms
// TODO: unimplemented
template<class _Tp> constexpr strong_ordering strong_order(const _Tp& __lhs, const _Tp& __rhs);
template<class _Tp> constexpr weak_ordering weak_order(const _Tp& __lhs, const _Tp& __rhs);
template<class _Tp> constexpr partial_ordering partial_order(const _Tp& __lhs, const _Tp& __rhs);
template<class _Tp> constexpr strong_equality strong_equal(const _Tp& __lhs, const _Tp& __rhs);
template<class _Tp> constexpr weak_equality weak_equal(const _Tp& __lhs, const _Tp& __rhs);
#endif // _LIBCPP_STD_VER > 17
_LIBCPP_END_NAMESPACE_STD
#endif // _LIBCPP_COMPARE
| 26,603 | 680 | jart/cosmopolitan | false |
cosmopolitan/third_party/libcxx/future.cc | // clang-format off
//===------------------------- future.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/future"
#include "third_party/libcxx/string"
_LIBCPP_BEGIN_NAMESPACE_STD
class _LIBCPP_HIDDEN __future_error_category
: public __do_message
{
public:
virtual const char* name() const _NOEXCEPT;
virtual string message(int ev) const;
};
const char*
__future_error_category::name() const _NOEXCEPT
{
return "future";
}
#if defined(__clang__)
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wswitch"
#elif defined(__GNUC__) || defined(__GNUG__)
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wswitch"
#endif
string
__future_error_category::message(int ev) const
{
switch (static_cast<future_errc>(ev))
{
case future_errc(0): // For backwards compatibility with C++11 (LWG 2056)
case future_errc::broken_promise:
return string("The associated promise has been destructed prior "
"to the associated state becoming ready.");
case future_errc::future_already_retrieved:
return string("The future has already been retrieved from "
"the promise or packaged_task.");
case future_errc::promise_already_satisfied:
return string("The state of the promise has already been set.");
case future_errc::no_state:
return string("Operation not permitted on an object without "
"an associated state.");
}
return string("unspecified future_errc value\n");
}
#if defined(__clang__)
#pragma clang diagnostic pop
#elif defined(__GNUC__) || defined(__GNUG__)
#pragma GCC diagnostic pop
#endif
const error_category&
future_category() _NOEXCEPT
{
static __future_error_category __f;
return __f;
}
future_error::future_error(error_code __ec)
: logic_error(__ec.message()),
__ec_(__ec)
{
}
future_error::~future_error() _NOEXCEPT
{
}
void
__assoc_sub_state::__on_zero_shared() _NOEXCEPT
{
delete this;
}
void
__assoc_sub_state::set_value()
{
unique_lock<mutex> __lk(__mut_);
if (__has_value())
__throw_future_error(future_errc::promise_already_satisfied);
__state_ |= __constructed | ready;
__cv_.notify_all();
}
void
__assoc_sub_state::set_value_at_thread_exit()
{
unique_lock<mutex> __lk(__mut_);
if (__has_value())
__throw_future_error(future_errc::promise_already_satisfied);
__state_ |= __constructed;
__thread_local_data()->__make_ready_at_thread_exit(this);
}
void
__assoc_sub_state::set_exception(exception_ptr __p)
{
unique_lock<mutex> __lk(__mut_);
if (__has_value())
__throw_future_error(future_errc::promise_already_satisfied);
__exception_ = __p;
__state_ |= ready;
__cv_.notify_all();
}
void
__assoc_sub_state::set_exception_at_thread_exit(exception_ptr __p)
{
unique_lock<mutex> __lk(__mut_);
if (__has_value())
__throw_future_error(future_errc::promise_already_satisfied);
__exception_ = __p;
__thread_local_data()->__make_ready_at_thread_exit(this);
}
void
__assoc_sub_state::__make_ready()
{
unique_lock<mutex> __lk(__mut_);
__state_ |= ready;
__cv_.notify_all();
}
void
__assoc_sub_state::copy()
{
unique_lock<mutex> __lk(__mut_);
__sub_wait(__lk);
if (__exception_ != nullptr)
rethrow_exception(__exception_);
}
void
__assoc_sub_state::wait()
{
unique_lock<mutex> __lk(__mut_);
__sub_wait(__lk);
}
void
__assoc_sub_state::__sub_wait(unique_lock<mutex>& __lk)
{
if (!__is_ready())
{
if (__state_ & static_cast<unsigned>(deferred))
{
__state_ &= ~static_cast<unsigned>(deferred);
__lk.unlock();
__execute();
}
else
while (!__is_ready())
__cv_.wait(__lk);
}
}
void
__assoc_sub_state::__execute()
{
__throw_future_error(future_errc::no_state);
}
future<void>::future(__assoc_sub_state* __state)
: __state_(__state)
{
__state_->__attach_future();
}
future<void>::~future()
{
if (__state_)
__state_->__release_shared();
}
void
future<void>::get()
{
unique_ptr<__shared_count, __release_shared_count> __(__state_);
__assoc_sub_state* __s = __state_;
__state_ = nullptr;
__s->copy();
}
promise<void>::promise()
: __state_(new __assoc_sub_state)
{
}
promise<void>::~promise()
{
if (__state_)
{
#ifndef _LIBCPP_NO_EXCEPTIONS
if (!__state_->__has_value() && __state_->use_count() > 1)
__state_->set_exception(make_exception_ptr(
future_error(make_error_code(future_errc::broken_promise))
));
#endif // _LIBCPP_NO_EXCEPTIONS
__state_->__release_shared();
}
}
future<void>
promise<void>::get_future()
{
if (__state_ == nullptr)
__throw_future_error(future_errc::no_state);
return future<void>(__state_);
}
void
promise<void>::set_value()
{
if (__state_ == nullptr)
__throw_future_error(future_errc::no_state);
__state_->set_value();
}
void
promise<void>::set_exception(exception_ptr __p)
{
if (__state_ == nullptr)
__throw_future_error(future_errc::no_state);
__state_->set_exception(__p);
}
void
promise<void>::set_value_at_thread_exit()
{
if (__state_ == nullptr)
__throw_future_error(future_errc::no_state);
__state_->set_value_at_thread_exit();
}
void
promise<void>::set_exception_at_thread_exit(exception_ptr __p)
{
if (__state_ == nullptr)
__throw_future_error(future_errc::no_state);
__state_->set_exception_at_thread_exit(__p);
}
shared_future<void>::~shared_future()
{
if (__state_)
__state_->__release_shared();
}
shared_future<void>&
shared_future<void>::operator=(const shared_future& __rhs)
{
if (__rhs.__state_)
__rhs.__state_->__add_shared();
if (__state_)
__state_->__release_shared();
__state_ = __rhs.__state_;
return *this;
}
_LIBCPP_END_NAMESPACE_STD
#endif // !_LIBCPP_HAS_NO_THREADS
| 6,441 | 279 | jart/cosmopolitan | false |
cosmopolitan/third_party/libcxx/iosfwd | // -*- C++ -*-
//===--------------------------- iosfwd -----------------------------------===//
//
// 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_IOSFWD
#define _LIBCPP_IOSFWD
#include "third_party/libcxx/__config"
#include "third_party/libcxx/wchar.h" // for mbstate_t
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
#pragma GCC system_header
#endif
_LIBCPP_BEGIN_NAMESPACE_STD
/*
iosfwd synopsis
namespace std
{
template<class charT> struct char_traits;
template<> struct char_traits<char>;
template<> struct char_traits<char8_t>; // C++20
template<> struct char_traits<char16_t>;
template<> struct char_traits<char32_t>;
template<> struct char_traits<wchar_t>;
template<class T> class allocator;
class ios_base;
template <class charT, class traits = char_traits<charT> > class basic_ios;
template <class charT, class traits = char_traits<charT> > class basic_streambuf;
template <class charT, class traits = char_traits<charT> > class basic_istream;
template <class charT, class traits = char_traits<charT> > class basic_ostream;
template <class charT, class traits = char_traits<charT> > class basic_iostream;
template <class charT, class traits = char_traits<charT>, class Allocator = allocator<charT> >
class basic_stringbuf;
template <class charT, class traits = char_traits<charT>, class Allocator = allocator<charT> >
class basic_istringstream;
template <class charT, class traits = char_traits<charT>, class Allocator = allocator<charT> >
class basic_ostringstream;
template <class charT, class traits = char_traits<charT>, class Allocator = allocator<charT> >
class basic_stringstream;
template <class charT, class traits = char_traits<charT> > class basic_filebuf;
template <class charT, class traits = char_traits<charT> > class basic_ifstream;
template <class charT, class traits = char_traits<charT> > class basic_ofstream;
template <class charT, class traits = char_traits<charT> > class basic_fstream;
template <class charT, class traits = char_traits<charT> > class istreambuf_iterator;
template <class charT, class traits = char_traits<charT> > class ostreambuf_iterator;
typedef basic_ios<char> ios;
typedef basic_ios<wchar_t> wios;
typedef basic_streambuf<char> streambuf;
typedef basic_istream<char> istream;
typedef basic_ostream<char> ostream;
typedef basic_iostream<char> iostream;
typedef basic_stringbuf<char> stringbuf;
typedef basic_istringstream<char> istringstream;
typedef basic_ostringstream<char> ostringstream;
typedef basic_stringstream<char> stringstream;
typedef basic_filebuf<char> filebuf;
typedef basic_ifstream<char> ifstream;
typedef basic_ofstream<char> ofstream;
typedef basic_fstream<char> fstream;
typedef basic_streambuf<wchar_t> wstreambuf;
typedef basic_istream<wchar_t> wistream;
typedef basic_ostream<wchar_t> wostream;
typedef basic_iostream<wchar_t> wiostream;
typedef basic_stringbuf<wchar_t> wstringbuf;
typedef basic_istringstream<wchar_t> wistringstream;
typedef basic_ostringstream<wchar_t> wostringstream;
typedef basic_stringstream<wchar_t> wstringstream;
typedef basic_filebuf<wchar_t> wfilebuf;
typedef basic_ifstream<wchar_t> wifstream;
typedef basic_ofstream<wchar_t> wofstream;
typedef basic_fstream<wchar_t> wfstream;
template <class state> class fpos;
typedef fpos<char_traits<char>::state_type> streampos;
typedef fpos<char_traits<wchar_t>::state_type> wstreampos;
} // std
*/
class _LIBCPP_TYPE_VIS ios_base;
template<class _CharT> struct _LIBCPP_TEMPLATE_VIS char_traits;
template<> struct char_traits<char>;
#ifndef _LIBCPP_NO_HAS_CHAR8_T
template<> struct char_traits<char8_t>;
#endif
template<> struct char_traits<char16_t>;
template<> struct char_traits<char32_t>;
template<> struct char_traits<wchar_t>;
template<class _Tp> class _LIBCPP_TEMPLATE_VIS allocator;
template <class _CharT, class _Traits = char_traits<_CharT> >
class _LIBCPP_TEMPLATE_VIS basic_ios;
template <class _CharT, class _Traits = char_traits<_CharT> >
class _LIBCPP_TEMPLATE_VIS basic_streambuf;
template <class _CharT, class _Traits = char_traits<_CharT> >
class _LIBCPP_TEMPLATE_VIS basic_istream;
template <class _CharT, class _Traits = char_traits<_CharT> >
class _LIBCPP_TEMPLATE_VIS basic_ostream;
template <class _CharT, class _Traits = char_traits<_CharT> >
class _LIBCPP_TEMPLATE_VIS basic_iostream;
template <class _CharT, class _Traits = char_traits<_CharT>,
class _Allocator = allocator<_CharT> >
class _LIBCPP_TEMPLATE_VIS basic_stringbuf;
template <class _CharT, class _Traits = char_traits<_CharT>,
class _Allocator = allocator<_CharT> >
class _LIBCPP_TEMPLATE_VIS basic_istringstream;
template <class _CharT, class _Traits = char_traits<_CharT>,
class _Allocator = allocator<_CharT> >
class _LIBCPP_TEMPLATE_VIS basic_ostringstream;
template <class _CharT, class _Traits = char_traits<_CharT>,
class _Allocator = allocator<_CharT> >
class _LIBCPP_TEMPLATE_VIS basic_stringstream;
template <class _CharT, class _Traits = char_traits<_CharT> >
class _LIBCPP_TEMPLATE_VIS basic_filebuf;
template <class _CharT, class _Traits = char_traits<_CharT> >
class _LIBCPP_TEMPLATE_VIS basic_ifstream;
template <class _CharT, class _Traits = char_traits<_CharT> >
class _LIBCPP_TEMPLATE_VIS basic_ofstream;
template <class _CharT, class _Traits = char_traits<_CharT> >
class _LIBCPP_TEMPLATE_VIS basic_fstream;
template <class _CharT, class _Traits = char_traits<_CharT> >
class _LIBCPP_TEMPLATE_VIS istreambuf_iterator;
template <class _CharT, class _Traits = char_traits<_CharT> >
class _LIBCPP_TEMPLATE_VIS ostreambuf_iterator;
typedef basic_ios<char> ios;
typedef basic_ios<wchar_t> wios;
typedef basic_streambuf<char> streambuf;
typedef basic_istream<char> istream;
typedef basic_ostream<char> ostream;
typedef basic_iostream<char> iostream;
typedef basic_stringbuf<char> stringbuf;
typedef basic_istringstream<char> istringstream;
typedef basic_ostringstream<char> ostringstream;
typedef basic_stringstream<char> stringstream;
typedef basic_filebuf<char> filebuf;
typedef basic_ifstream<char> ifstream;
typedef basic_ofstream<char> ofstream;
typedef basic_fstream<char> fstream;
typedef basic_streambuf<wchar_t> wstreambuf;
typedef basic_istream<wchar_t> wistream;
typedef basic_ostream<wchar_t> wostream;
typedef basic_iostream<wchar_t> wiostream;
typedef basic_stringbuf<wchar_t> wstringbuf;
typedef basic_istringstream<wchar_t> wistringstream;
typedef basic_ostringstream<wchar_t> wostringstream;
typedef basic_stringstream<wchar_t> wstringstream;
typedef basic_filebuf<wchar_t> wfilebuf;
typedef basic_ifstream<wchar_t> wifstream;
typedef basic_ofstream<wchar_t> wofstream;
typedef basic_fstream<wchar_t> wfstream;
template <class _State> class _LIBCPP_TEMPLATE_VIS fpos;
typedef fpos<mbstate_t> streampos;
typedef fpos<mbstate_t> wstreampos;
#ifndef _LIBCPP_NO_HAS_CHAR8_T
typedef fpos<mbstate_t> u8streampos;
#endif
#ifndef _LIBCPP_HAS_NO_UNICODE_CHARS
typedef fpos<mbstate_t> u16streampos;
typedef fpos<mbstate_t> u32streampos;
#endif // _LIBCPP_HAS_NO_UNICODE_CHARS
#if defined(_NEWLIB_VERSION)
// On newlib, off_t is 'long int'
typedef long int streamoff; // for char_traits in <string>
#else
typedef long long streamoff; // for char_traits in <string>
#endif
template <class _CharT, // for <stdexcept>
class _Traits = char_traits<_CharT>,
class _Allocator = allocator<_CharT> >
class _LIBCPP_TEMPLATE_VIS basic_string;
typedef basic_string<char, char_traits<char>, allocator<char> > string;
typedef basic_string<wchar_t, char_traits<wchar_t>, allocator<wchar_t> > wstring;
// Include other forward declarations here
template <class _Tp, class _Alloc = allocator<_Tp> >
class _LIBCPP_TEMPLATE_VIS vector;
_LIBCPP_END_NAMESPACE_STD
#endif // _LIBCPP_IOSFWD
| 8,503 | 221 | jart/cosmopolitan | false |
cosmopolitan/third_party/libcxx/__node_handle | // -*- C++ -*-
//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
#ifndef _LIBCPP___NODE_HANDLE
#define _LIBCPP___NODE_HANDLE
#include "third_party/libcxx/__config"
#include "third_party/libcxx/memory"
#include "third_party/libcxx/optional"
#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 _LIBCPP_STD_VER > 14
// Specialized in __tree & __hash_table for their _NodeType.
template <class _NodeType, class _Alloc>
struct __generic_container_node_destructor;
template <class _NodeType, class _Alloc,
template <class, class> class _MapOrSetSpecifics>
class _LIBCPP_TEMPLATE_VIS __basic_node_handle
: public _MapOrSetSpecifics<
_NodeType,
__basic_node_handle<_NodeType, _Alloc, _MapOrSetSpecifics>>
{
template <class _Tp, class _Compare, class _Allocator>
friend class __tree;
template <class _Tp, class _Hash, class _Equal, class _Allocator>
friend class __hash_table;
friend struct _MapOrSetSpecifics<
_NodeType, __basic_node_handle<_NodeType, _Alloc, _MapOrSetSpecifics>>;
typedef allocator_traits<_Alloc> __alloc_traits;
typedef typename __rebind_pointer<typename __alloc_traits::void_pointer,
_NodeType>::type
__node_pointer_type;
public:
typedef _Alloc allocator_type;
private:
__node_pointer_type __ptr_ = nullptr;
optional<allocator_type> __alloc_;
_LIBCPP_INLINE_VISIBILITY
void __release_ptr()
{
__ptr_ = nullptr;
__alloc_ = _VSTD::nullopt;
}
_LIBCPP_INLINE_VISIBILITY
void __destroy_node_pointer()
{
if (__ptr_ != nullptr)
{
typedef typename __allocator_traits_rebind<
allocator_type, _NodeType>::type __node_alloc_type;
__node_alloc_type __alloc(*__alloc_);
__generic_container_node_destructor<_NodeType, __node_alloc_type>(
__alloc, true)(__ptr_);
__ptr_ = nullptr;
}
}
_LIBCPP_INLINE_VISIBILITY
__basic_node_handle(__node_pointer_type __ptr,
allocator_type const& __alloc)
: __ptr_(__ptr), __alloc_(__alloc)
{
}
public:
_LIBCPP_INLINE_VISIBILITY
__basic_node_handle() = default;
_LIBCPP_INLINE_VISIBILITY
__basic_node_handle(__basic_node_handle&& __other) noexcept
: __ptr_(__other.__ptr_),
__alloc_(_VSTD::move(__other.__alloc_))
{
__other.__ptr_ = nullptr;
__other.__alloc_ = _VSTD::nullopt;
}
_LIBCPP_INLINE_VISIBILITY
__basic_node_handle& operator=(__basic_node_handle&& __other)
{
_LIBCPP_ASSERT(
__alloc_ == _VSTD::nullopt ||
__alloc_traits::propagate_on_container_move_assignment::value ||
__alloc_ == __other.__alloc_,
"node_type with incompatible allocator passed to "
"node_type::operator=(node_type&&)");
__destroy_node_pointer();
__ptr_ = __other.__ptr_;
if (__alloc_traits::propagate_on_container_move_assignment::value ||
__alloc_ == _VSTD::nullopt)
__alloc_ = _VSTD::move(__other.__alloc_);
__other.__ptr_ = nullptr;
__other.__alloc_ = _VSTD::nullopt;
return *this;
}
_LIBCPP_INLINE_VISIBILITY
allocator_type get_allocator() const { return *__alloc_; }
_LIBCPP_INLINE_VISIBILITY
explicit operator bool() const { return __ptr_ != nullptr; }
_LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
bool empty() const { return __ptr_ == nullptr; }
_LIBCPP_INLINE_VISIBILITY
void swap(__basic_node_handle& __other) noexcept(
__alloc_traits::propagate_on_container_swap::value ||
__alloc_traits::is_always_equal::value)
{
using _VSTD::swap;
swap(__ptr_, __other.__ptr_);
if (__alloc_traits::propagate_on_container_swap::value ||
__alloc_ == _VSTD::nullopt || __other.__alloc_ == _VSTD::nullopt)
swap(__alloc_, __other.__alloc_);
}
_LIBCPP_INLINE_VISIBILITY
friend void swap(__basic_node_handle& __a, __basic_node_handle& __b)
noexcept(noexcept(__a.swap(__b))) { __a.swap(__b); }
_LIBCPP_INLINE_VISIBILITY
~__basic_node_handle()
{
__destroy_node_pointer();
}
};
template <class _NodeType, class _Derived>
struct __set_node_handle_specifics
{
typedef typename _NodeType::__node_value_type value_type;
_LIBCPP_INLINE_VISIBILITY
value_type& value() const
{
return static_cast<_Derived const*>(this)->__ptr_->__value_;
}
};
template <class _NodeType, class _Derived>
struct __map_node_handle_specifics
{
typedef typename _NodeType::__node_value_type::key_type key_type;
typedef typename _NodeType::__node_value_type::mapped_type mapped_type;
_LIBCPP_INLINE_VISIBILITY
key_type& key() const
{
return static_cast<_Derived const*>(this)->
__ptr_->__value_.__ref().first;
}
_LIBCPP_INLINE_VISIBILITY
mapped_type& mapped() const
{
return static_cast<_Derived const*>(this)->
__ptr_->__value_.__ref().second;
}
};
template <class _NodeType, class _Alloc>
using __set_node_handle =
__basic_node_handle< _NodeType, _Alloc, __set_node_handle_specifics>;
template <class _NodeType, class _Alloc>
using __map_node_handle =
__basic_node_handle< _NodeType, _Alloc, __map_node_handle_specifics>;
template <class _Iterator, class _NodeType>
struct _LIBCPP_TEMPLATE_VIS __insert_return_type
{
_Iterator position;
bool inserted;
_NodeType node;
};
#endif // _LIBCPP_STD_VER > 14
_LIBCPP_END_NAMESPACE_STD
_LIBCPP_POP_MACROS
#endif
| 6,150 | 209 | jart/cosmopolitan | false |
cosmopolitan/third_party/libcxx/csignal | // -*- C++ -*-
// clang-format off
//===--------------------------- csignal ----------------------------------===//
//
// 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_CSIGNAL
#define _LIBCPP_CSIGNAL
/*
csignal synopsis
Macros:
SIG_DFL
SIG_ERR
SIG_IGN
SIGABRT
SIGFPE
SIGILL
SIGINT
SIGSEGV
SIGTERM
namespace std
{
Types:
sig_atomic_t
void (*signal(int sig, void (*func)(int)))(int);
int raise(int sig);
} // std
*/
#include "third_party/libcxx/__config"
#include "libc/calls/calls.h"
#include "libc/calls/struct/sigaction.h"
#include "libc/calls/struct/siginfo.h"
#include "libc/sysv/consts/sa.h"
#include "libc/sysv/consts/sicode.h"
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
#pragma GCC system_header
#endif
_LIBCPP_BEGIN_NAMESPACE_STD
using ::sig_atomic_t;
using ::signal;
using ::raise;
_LIBCPP_END_NAMESPACE_STD
#endif // _LIBCPP_CSIGNAL
| 1,163 | 63 | jart/cosmopolitan | false |
cosmopolitan/third_party/libcxx/cassert | // -*- C++ -*-
//===-------------------------- cassert -----------------------------------===//
//
// 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
//
//===----------------------------------------------------------------------===//
/*
cassert synopsis
Macros:
assert
*/
#include "third_party/libcxx/__config"
#include "libc/assert.h"
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
#pragma GCC system_header
#endif
| 583 | 25 | jart/cosmopolitan | false |
cosmopolitan/third_party/libcxx/initializer_list | // -*- C++ -*-
//===----------------------- initializer_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_INITIALIZER_LIST
#define _LIBCPP_INITIALIZER_LIST
/*
initializer_list synopsis
namespace std
{
template<class E>
class initializer_list
{
public:
typedef E value_type;
typedef const E& reference;
typedef const E& const_reference;
typedef size_t size_type;
typedef const E* iterator;
typedef const E* const_iterator;
initializer_list() noexcept; // constexpr in C++14
size_t size() const noexcept; // constexpr in C++14
const E* begin() const noexcept; // constexpr in C++14
const E* end() const noexcept; // constexpr in C++14
};
template<class E> const E* begin(initializer_list<E> il) noexcept; // constexpr in C++14
template<class E> const E* end(initializer_list<E> il) noexcept; // constexpr in C++14
} // std
*/
#include "third_party/libcxx/__config"
#include "third_party/libcxx/cstddef"
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
#pragma GCC system_header
#endif
namespace std // purposefully not versioned
{
#ifndef _LIBCPP_CXX03_LANG
template<class _Ep>
class _LIBCPP_TEMPLATE_VIS initializer_list
{
const _Ep* __begin_;
size_t __size_;
_LIBCPP_INLINE_VISIBILITY
_LIBCPP_CONSTEXPR_AFTER_CXX11
initializer_list(const _Ep* __b, size_t __s) _NOEXCEPT
: __begin_(__b),
__size_(__s)
{}
public:
typedef _Ep value_type;
typedef const _Ep& reference;
typedef const _Ep& const_reference;
typedef size_t size_type;
typedef const _Ep* iterator;
typedef const _Ep* const_iterator;
_LIBCPP_INLINE_VISIBILITY
_LIBCPP_CONSTEXPR_AFTER_CXX11
initializer_list() _NOEXCEPT : __begin_(nullptr), __size_(0) {}
_LIBCPP_INLINE_VISIBILITY
_LIBCPP_CONSTEXPR_AFTER_CXX11
size_t size() const _NOEXCEPT {return __size_;}
_LIBCPP_INLINE_VISIBILITY
_LIBCPP_CONSTEXPR_AFTER_CXX11
const _Ep* begin() const _NOEXCEPT {return __begin_;}
_LIBCPP_INLINE_VISIBILITY
_LIBCPP_CONSTEXPR_AFTER_CXX11
const _Ep* end() const _NOEXCEPT {return __begin_ + __size_;}
};
template<class _Ep>
inline _LIBCPP_INLINE_VISIBILITY
_LIBCPP_CONSTEXPR_AFTER_CXX11
const _Ep*
begin(initializer_list<_Ep> __il) _NOEXCEPT
{
return __il.begin();
}
template<class _Ep>
inline _LIBCPP_INLINE_VISIBILITY
_LIBCPP_CONSTEXPR_AFTER_CXX11
const _Ep*
end(initializer_list<_Ep> __il) _NOEXCEPT
{
return __il.end();
}
#endif // !defined(_LIBCPP_CXX03_LANG)
} // std
#endif // _LIBCPP_INITIALIZER_LIST
| 2,880 | 118 | jart/cosmopolitan | false |
cosmopolitan/third_party/libcxx/__bit_reference | // -*- 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___BIT_REFERENCE
#define _LIBCPP___BIT_REFERENCE
#include "third_party/libcxx/__config"
#include "third_party/libcxx/bit"
#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
template <class _Cp, bool _IsConst, typename _Cp::__storage_type = 0> class __bit_iterator;
template <class _Cp> class __bit_const_reference;
template <class _Tp>
struct __has_storage_type
{
static const bool value = false;
};
template <class _Cp, bool = __has_storage_type<_Cp>::value>
class __bit_reference
{
typedef typename _Cp::__storage_type __storage_type;
typedef typename _Cp::__storage_pointer __storage_pointer;
__storage_pointer __seg_;
__storage_type __mask_;
friend typename _Cp::__self;
friend class __bit_const_reference<_Cp>;
friend class __bit_iterator<_Cp, false>;
public:
_LIBCPP_INLINE_VISIBILITY operator bool() const _NOEXCEPT
{return static_cast<bool>(*__seg_ & __mask_);}
_LIBCPP_INLINE_VISIBILITY bool operator ~() const _NOEXCEPT
{return !static_cast<bool>(*this);}
_LIBCPP_INLINE_VISIBILITY
__bit_reference& operator=(bool __x) _NOEXCEPT
{
if (__x)
*__seg_ |= __mask_;
else
*__seg_ &= ~__mask_;
return *this;
}
_LIBCPP_INLINE_VISIBILITY
__bit_reference& operator=(const __bit_reference& __x) _NOEXCEPT
{return operator=(static_cast<bool>(__x));}
_LIBCPP_INLINE_VISIBILITY void flip() _NOEXCEPT {*__seg_ ^= __mask_;}
_LIBCPP_INLINE_VISIBILITY __bit_iterator<_Cp, false> operator&() const _NOEXCEPT
{return __bit_iterator<_Cp, false>(__seg_, static_cast<unsigned>(__libcpp_ctz(__mask_)));}
private:
_LIBCPP_INLINE_VISIBILITY
__bit_reference(__storage_pointer __s, __storage_type __m) _NOEXCEPT
: __seg_(__s), __mask_(__m) {}
};
template <class _Cp>
class __bit_reference<_Cp, false>
{
};
template <class _Cp>
inline _LIBCPP_INLINE_VISIBILITY
void
swap(__bit_reference<_Cp> __x, __bit_reference<_Cp> __y) _NOEXCEPT
{
bool __t = __x;
__x = __y;
__y = __t;
}
template <class _Cp, class _Dp>
inline _LIBCPP_INLINE_VISIBILITY
void
swap(__bit_reference<_Cp> __x, __bit_reference<_Dp> __y) _NOEXCEPT
{
bool __t = __x;
__x = __y;
__y = __t;
}
template <class _Cp>
inline _LIBCPP_INLINE_VISIBILITY
void
swap(__bit_reference<_Cp> __x, bool& __y) _NOEXCEPT
{
bool __t = __x;
__x = __y;
__y = __t;
}
template <class _Cp>
inline _LIBCPP_INLINE_VISIBILITY
void
swap(bool& __x, __bit_reference<_Cp> __y) _NOEXCEPT
{
bool __t = __x;
__x = __y;
__y = __t;
}
template <class _Cp>
class __bit_const_reference
{
typedef typename _Cp::__storage_type __storage_type;
typedef typename _Cp::__const_storage_pointer __storage_pointer;
__storage_pointer __seg_;
__storage_type __mask_;
friend typename _Cp::__self;
friend class __bit_iterator<_Cp, true>;
public:
_LIBCPP_INLINE_VISIBILITY
__bit_const_reference(const __bit_reference<_Cp>& __x) _NOEXCEPT
: __seg_(__x.__seg_), __mask_(__x.__mask_) {}
_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR operator bool() const _NOEXCEPT
{return static_cast<bool>(*__seg_ & __mask_);}
_LIBCPP_INLINE_VISIBILITY __bit_iterator<_Cp, true> operator&() const _NOEXCEPT
{return __bit_iterator<_Cp, true>(__seg_, static_cast<unsigned>(__libcpp_ctz(__mask_)));}
private:
_LIBCPP_INLINE_VISIBILITY
_LIBCPP_CONSTEXPR
__bit_const_reference(__storage_pointer __s, __storage_type __m) _NOEXCEPT
: __seg_(__s), __mask_(__m) {}
__bit_const_reference& operator=(const __bit_const_reference& __x);
};
// find
template <class _Cp, bool _IsConst>
__bit_iterator<_Cp, _IsConst>
__find_bool_true(__bit_iterator<_Cp, _IsConst> __first, typename _Cp::size_type __n)
{
typedef __bit_iterator<_Cp, _IsConst> _It;
typedef typename _It::__storage_type __storage_type;
static const int __bits_per_word = _It::__bits_per_word;
// do first partial word
if (__first.__ctz_ != 0)
{
__storage_type __clz_f = static_cast<__storage_type>(__bits_per_word - __first.__ctz_);
__storage_type __dn = _VSTD::min(__clz_f, __n);
__storage_type __m = (~__storage_type(0) << __first.__ctz_) & (~__storage_type(0) >> (__clz_f - __dn));
__storage_type __b = *__first.__seg_ & __m;
if (__b)
return _It(__first.__seg_, static_cast<unsigned>(_VSTD::__libcpp_ctz(__b)));
if (__n == __dn)
return __first + __n;
__n -= __dn;
++__first.__seg_;
}
// do middle whole words
for (; __n >= __bits_per_word; ++__first.__seg_, __n -= __bits_per_word)
if (*__first.__seg_)
return _It(__first.__seg_, static_cast<unsigned>(_VSTD::__libcpp_ctz(*__first.__seg_)));
// do last partial word
if (__n > 0)
{
__storage_type __m = ~__storage_type(0) >> (__bits_per_word - __n);
__storage_type __b = *__first.__seg_ & __m;
if (__b)
return _It(__first.__seg_, static_cast<unsigned>(_VSTD::__libcpp_ctz(__b)));
}
return _It(__first.__seg_, static_cast<unsigned>(__n));
}
template <class _Cp, bool _IsConst>
__bit_iterator<_Cp, _IsConst>
__find_bool_false(__bit_iterator<_Cp, _IsConst> __first, typename _Cp::size_type __n)
{
typedef __bit_iterator<_Cp, _IsConst> _It;
typedef typename _It::__storage_type __storage_type;
const int __bits_per_word = _It::__bits_per_word;
// do first partial word
if (__first.__ctz_ != 0)
{
__storage_type __clz_f = static_cast<__storage_type>(__bits_per_word - __first.__ctz_);
__storage_type __dn = _VSTD::min(__clz_f, __n);
__storage_type __m = (~__storage_type(0) << __first.__ctz_) & (~__storage_type(0) >> (__clz_f - __dn));
__storage_type __b = ~*__first.__seg_ & __m;
if (__b)
return _It(__first.__seg_, static_cast<unsigned>(_VSTD::__libcpp_ctz(__b)));
if (__n == __dn)
return __first + __n;
__n -= __dn;
++__first.__seg_;
}
// do middle whole words
for (; __n >= __bits_per_word; ++__first.__seg_, __n -= __bits_per_word)
{
__storage_type __b = ~*__first.__seg_;
if (__b)
return _It(__first.__seg_, static_cast<unsigned>(_VSTD::__libcpp_ctz(__b)));
}
// do last partial word
if (__n > 0)
{
__storage_type __m = ~__storage_type(0) >> (__bits_per_word - __n);
__storage_type __b = ~*__first.__seg_ & __m;
if (__b)
return _It(__first.__seg_, static_cast<unsigned>(_VSTD::__libcpp_ctz(__b)));
}
return _It(__first.__seg_, static_cast<unsigned>(__n));
}
template <class _Cp, bool _IsConst, class _Tp>
inline _LIBCPP_INLINE_VISIBILITY
__bit_iterator<_Cp, _IsConst>
find(__bit_iterator<_Cp, _IsConst> __first, __bit_iterator<_Cp, _IsConst> __last, const _Tp& __value_)
{
if (static_cast<bool>(__value_))
return __find_bool_true(__first, static_cast<typename _Cp::size_type>(__last - __first));
return __find_bool_false(__first, static_cast<typename _Cp::size_type>(__last - __first));
}
// count
template <class _Cp, bool _IsConst>
typename __bit_iterator<_Cp, _IsConst>::difference_type
__count_bool_true(__bit_iterator<_Cp, _IsConst> __first, typename _Cp::size_type __n)
{
typedef __bit_iterator<_Cp, _IsConst> _It;
typedef typename _It::__storage_type __storage_type;
typedef typename _It::difference_type difference_type;
const int __bits_per_word = _It::__bits_per_word;
difference_type __r = 0;
// do first partial word
if (__first.__ctz_ != 0)
{
__storage_type __clz_f = static_cast<__storage_type>(__bits_per_word - __first.__ctz_);
__storage_type __dn = _VSTD::min(__clz_f, __n);
__storage_type __m = (~__storage_type(0) << __first.__ctz_) & (~__storage_type(0) >> (__clz_f - __dn));
__r = _VSTD::__libcpp_popcount(*__first.__seg_ & __m);
__n -= __dn;
++__first.__seg_;
}
// do middle whole words
for (; __n >= __bits_per_word; ++__first.__seg_, __n -= __bits_per_word)
__r += _VSTD::__libcpp_popcount(*__first.__seg_);
// do last partial word
if (__n > 0)
{
__storage_type __m = ~__storage_type(0) >> (__bits_per_word - __n);
__r += _VSTD::__libcpp_popcount(*__first.__seg_ & __m);
}
return __r;
}
template <class _Cp, bool _IsConst>
typename __bit_iterator<_Cp, _IsConst>::difference_type
__count_bool_false(__bit_iterator<_Cp, _IsConst> __first, typename _Cp::size_type __n)
{
typedef __bit_iterator<_Cp, _IsConst> _It;
typedef typename _It::__storage_type __storage_type;
typedef typename _It::difference_type difference_type;
const int __bits_per_word = _It::__bits_per_word;
difference_type __r = 0;
// do first partial word
if (__first.__ctz_ != 0)
{
__storage_type __clz_f = static_cast<__storage_type>(__bits_per_word - __first.__ctz_);
__storage_type __dn = _VSTD::min(__clz_f, __n);
__storage_type __m = (~__storage_type(0) << __first.__ctz_) & (~__storage_type(0) >> (__clz_f - __dn));
__r = _VSTD::__libcpp_popcount(~*__first.__seg_ & __m);
__n -= __dn;
++__first.__seg_;
}
// do middle whole words
for (; __n >= __bits_per_word; ++__first.__seg_, __n -= __bits_per_word)
__r += _VSTD::__libcpp_popcount(~*__first.__seg_);
// do last partial word
if (__n > 0)
{
__storage_type __m = ~__storage_type(0) >> (__bits_per_word - __n);
__r += _VSTD::__libcpp_popcount(~*__first.__seg_ & __m);
}
return __r;
}
template <class _Cp, bool _IsConst, class _Tp>
inline _LIBCPP_INLINE_VISIBILITY
typename __bit_iterator<_Cp, _IsConst>::difference_type
count(__bit_iterator<_Cp, _IsConst> __first, __bit_iterator<_Cp, _IsConst> __last, const _Tp& __value_)
{
if (static_cast<bool>(__value_))
return __count_bool_true(__first, static_cast<typename _Cp::size_type>(__last - __first));
return __count_bool_false(__first, static_cast<typename _Cp::size_type>(__last - __first));
}
// fill_n
template <class _Cp>
void
__fill_n_false(__bit_iterator<_Cp, false> __first, typename _Cp::size_type __n)
{
typedef __bit_iterator<_Cp, false> _It;
typedef typename _It::__storage_type __storage_type;
const int __bits_per_word = _It::__bits_per_word;
// do first partial word
if (__first.__ctz_ != 0)
{
__storage_type __clz_f = static_cast<__storage_type>(__bits_per_word - __first.__ctz_);
__storage_type __dn = _VSTD::min(__clz_f, __n);
__storage_type __m = (~__storage_type(0) << __first.__ctz_) & (~__storage_type(0) >> (__clz_f - __dn));
*__first.__seg_ &= ~__m;
__n -= __dn;
++__first.__seg_;
}
// do middle whole words
__storage_type __nw = __n / __bits_per_word;
_VSTD::memset(_VSTD::__to_raw_pointer(__first.__seg_), 0, __nw * sizeof(__storage_type));
__n -= __nw * __bits_per_word;
// do last partial word
if (__n > 0)
{
__first.__seg_ += __nw;
__storage_type __m = ~__storage_type(0) >> (__bits_per_word - __n);
*__first.__seg_ &= ~__m;
}
}
template <class _Cp>
void
__fill_n_true(__bit_iterator<_Cp, false> __first, typename _Cp::size_type __n)
{
typedef __bit_iterator<_Cp, false> _It;
typedef typename _It::__storage_type __storage_type;
const int __bits_per_word = _It::__bits_per_word;
// do first partial word
if (__first.__ctz_ != 0)
{
__storage_type __clz_f = static_cast<__storage_type>(__bits_per_word - __first.__ctz_);
__storage_type __dn = _VSTD::min(__clz_f, __n);
__storage_type __m = (~__storage_type(0) << __first.__ctz_) & (~__storage_type(0) >> (__clz_f - __dn));
*__first.__seg_ |= __m;
__n -= __dn;
++__first.__seg_;
}
// do middle whole words
__storage_type __nw = __n / __bits_per_word;
_VSTD::memset(_VSTD::__to_raw_pointer(__first.__seg_), -1, __nw * sizeof(__storage_type));
__n -= __nw * __bits_per_word;
// do last partial word
if (__n > 0)
{
__first.__seg_ += __nw;
__storage_type __m = ~__storage_type(0) >> (__bits_per_word - __n);
*__first.__seg_ |= __m;
}
}
template <class _Cp>
inline _LIBCPP_INLINE_VISIBILITY
void
fill_n(__bit_iterator<_Cp, false> __first, typename _Cp::size_type __n, bool __value_)
{
if (__n > 0)
{
if (__value_)
__fill_n_true(__first, __n);
else
__fill_n_false(__first, __n);
}
}
// fill
template <class _Cp>
inline _LIBCPP_INLINE_VISIBILITY
void
fill(__bit_iterator<_Cp, false> __first, __bit_iterator<_Cp, false> __last, bool __value_)
{
_VSTD::fill_n(__first, static_cast<typename _Cp::size_type>(__last - __first), __value_);
}
// copy
template <class _Cp, bool _IsConst>
__bit_iterator<_Cp, false>
__copy_aligned(__bit_iterator<_Cp, _IsConst> __first, __bit_iterator<_Cp, _IsConst> __last,
__bit_iterator<_Cp, false> __result)
{
typedef __bit_iterator<_Cp, _IsConst> _In;
typedef typename _In::difference_type difference_type;
typedef typename _In::__storage_type __storage_type;
const int __bits_per_word = _In::__bits_per_word;
difference_type __n = __last - __first;
if (__n > 0)
{
// do first word
if (__first.__ctz_ != 0)
{
unsigned __clz = __bits_per_word - __first.__ctz_;
difference_type __dn = _VSTD::min(static_cast<difference_type>(__clz), __n);
__n -= __dn;
__storage_type __m = (~__storage_type(0) << __first.__ctz_) & (~__storage_type(0) >> (__clz - __dn));
__storage_type __b = *__first.__seg_ & __m;
*__result.__seg_ &= ~__m;
*__result.__seg_ |= __b;
__result.__seg_ += (__dn + __result.__ctz_) / __bits_per_word;
__result.__ctz_ = static_cast<unsigned>((__dn + __result.__ctz_) % __bits_per_word);
++__first.__seg_;
// __first.__ctz_ = 0;
}
// __first.__ctz_ == 0;
// do middle words
__storage_type __nw = __n / __bits_per_word;
_VSTD::memmove(_VSTD::__to_raw_pointer(__result.__seg_),
_VSTD::__to_raw_pointer(__first.__seg_),
__nw * sizeof(__storage_type));
__n -= __nw * __bits_per_word;
__result.__seg_ += __nw;
// do last word
if (__n > 0)
{
__first.__seg_ += __nw;
__storage_type __m = ~__storage_type(0) >> (__bits_per_word - __n);
__storage_type __b = *__first.__seg_ & __m;
*__result.__seg_ &= ~__m;
*__result.__seg_ |= __b;
__result.__ctz_ = static_cast<unsigned>(__n);
}
}
return __result;
}
template <class _Cp, bool _IsConst>
__bit_iterator<_Cp, false>
__copy_unaligned(__bit_iterator<_Cp, _IsConst> __first, __bit_iterator<_Cp, _IsConst> __last,
__bit_iterator<_Cp, false> __result)
{
typedef __bit_iterator<_Cp, _IsConst> _In;
typedef typename _In::difference_type difference_type;
typedef typename _In::__storage_type __storage_type;
static const int __bits_per_word = _In::__bits_per_word;
difference_type __n = __last - __first;
if (__n > 0)
{
// do first word
if (__first.__ctz_ != 0)
{
unsigned __clz_f = __bits_per_word - __first.__ctz_;
difference_type __dn = _VSTD::min(static_cast<difference_type>(__clz_f), __n);
__n -= __dn;
__storage_type __m = (~__storage_type(0) << __first.__ctz_) & (~__storage_type(0) >> (__clz_f - __dn));
__storage_type __b = *__first.__seg_ & __m;
unsigned __clz_r = __bits_per_word - __result.__ctz_;
__storage_type __ddn = _VSTD::min<__storage_type>(__dn, __clz_r);
__m = (~__storage_type(0) << __result.__ctz_) & (~__storage_type(0) >> (__clz_r - __ddn));
*__result.__seg_ &= ~__m;
if (__result.__ctz_ > __first.__ctz_)
*__result.__seg_ |= __b << (__result.__ctz_ - __first.__ctz_);
else
*__result.__seg_ |= __b >> (__first.__ctz_ - __result.__ctz_);
__result.__seg_ += (__ddn + __result.__ctz_) / __bits_per_word;
__result.__ctz_ = static_cast<unsigned>((__ddn + __result.__ctz_) % __bits_per_word);
__dn -= __ddn;
if (__dn > 0)
{
__m = ~__storage_type(0) >> (__bits_per_word - __dn);
*__result.__seg_ &= ~__m;
*__result.__seg_ |= __b >> (__first.__ctz_ + __ddn);
__result.__ctz_ = static_cast<unsigned>(__dn);
}
++__first.__seg_;
// __first.__ctz_ = 0;
}
// __first.__ctz_ == 0;
// do middle words
unsigned __clz_r = __bits_per_word - __result.__ctz_;
__storage_type __m = ~__storage_type(0) << __result.__ctz_;
for (; __n >= __bits_per_word; __n -= __bits_per_word, ++__first.__seg_)
{
__storage_type __b = *__first.__seg_;
*__result.__seg_ &= ~__m;
*__result.__seg_ |= __b << __result.__ctz_;
++__result.__seg_;
*__result.__seg_ &= __m;
*__result.__seg_ |= __b >> __clz_r;
}
// do last word
if (__n > 0)
{
__m = ~__storage_type(0) >> (__bits_per_word - __n);
__storage_type __b = *__first.__seg_ & __m;
__storage_type __dn = _VSTD::min(__n, static_cast<difference_type>(__clz_r));
__m = (~__storage_type(0) << __result.__ctz_) & (~__storage_type(0) >> (__clz_r - __dn));
*__result.__seg_ &= ~__m;
*__result.__seg_ |= __b << __result.__ctz_;
__result.__seg_ += (__dn + __result.__ctz_) / __bits_per_word;
__result.__ctz_ = static_cast<unsigned>((__dn + __result.__ctz_) % __bits_per_word);
__n -= __dn;
if (__n > 0)
{
__m = ~__storage_type(0) >> (__bits_per_word - __n);
*__result.__seg_ &= ~__m;
*__result.__seg_ |= __b >> __dn;
__result.__ctz_ = static_cast<unsigned>(__n);
}
}
}
return __result;
}
template <class _Cp, bool _IsConst>
inline _LIBCPP_INLINE_VISIBILITY
__bit_iterator<_Cp, false>
copy(__bit_iterator<_Cp, _IsConst> __first, __bit_iterator<_Cp, _IsConst> __last, __bit_iterator<_Cp, false> __result)
{
if (__first.__ctz_ == __result.__ctz_)
return __copy_aligned(__first, __last, __result);
return __copy_unaligned(__first, __last, __result);
}
// copy_backward
template <class _Cp, bool _IsConst>
__bit_iterator<_Cp, false>
__copy_backward_aligned(__bit_iterator<_Cp, _IsConst> __first, __bit_iterator<_Cp, _IsConst> __last,
__bit_iterator<_Cp, false> __result)
{
typedef __bit_iterator<_Cp, _IsConst> _In;
typedef typename _In::difference_type difference_type;
typedef typename _In::__storage_type __storage_type;
const int __bits_per_word = _In::__bits_per_word;
difference_type __n = __last - __first;
if (__n > 0)
{
// do first word
if (__last.__ctz_ != 0)
{
difference_type __dn = _VSTD::min(static_cast<difference_type>(__last.__ctz_), __n);
__n -= __dn;
unsigned __clz = __bits_per_word - __last.__ctz_;
__storage_type __m = (~__storage_type(0) << (__last.__ctz_ - __dn)) & (~__storage_type(0) >> __clz);
__storage_type __b = *__last.__seg_ & __m;
*__result.__seg_ &= ~__m;
*__result.__seg_ |= __b;
__result.__ctz_ = static_cast<unsigned>(((-__dn & (__bits_per_word - 1)) +
__result.__ctz_) % __bits_per_word);
// __last.__ctz_ = 0
}
// __last.__ctz_ == 0 || __n == 0
// __result.__ctz_ == 0 || __n == 0
// do middle words
__storage_type __nw = __n / __bits_per_word;
__result.__seg_ -= __nw;
__last.__seg_ -= __nw;
_VSTD::memmove(_VSTD::__to_raw_pointer(__result.__seg_),
_VSTD::__to_raw_pointer(__last.__seg_),
__nw * sizeof(__storage_type));
__n -= __nw * __bits_per_word;
// do last word
if (__n > 0)
{
__storage_type __m = ~__storage_type(0) << (__bits_per_word - __n);
__storage_type __b = *--__last.__seg_ & __m;
*--__result.__seg_ &= ~__m;
*__result.__seg_ |= __b;
__result.__ctz_ = static_cast<unsigned>(-__n & (__bits_per_word - 1));
}
}
return __result;
}
template <class _Cp, bool _IsConst>
__bit_iterator<_Cp, false>
__copy_backward_unaligned(__bit_iterator<_Cp, _IsConst> __first, __bit_iterator<_Cp, _IsConst> __last,
__bit_iterator<_Cp, false> __result)
{
typedef __bit_iterator<_Cp, _IsConst> _In;
typedef typename _In::difference_type difference_type;
typedef typename _In::__storage_type __storage_type;
const int __bits_per_word = _In::__bits_per_word;
difference_type __n = __last - __first;
if (__n > 0)
{
// do first word
if (__last.__ctz_ != 0)
{
difference_type __dn = _VSTD::min(static_cast<difference_type>(__last.__ctz_), __n);
__n -= __dn;
unsigned __clz_l = __bits_per_word - __last.__ctz_;
__storage_type __m = (~__storage_type(0) << (__last.__ctz_ - __dn)) & (~__storage_type(0) >> __clz_l);
__storage_type __b = *__last.__seg_ & __m;
unsigned __clz_r = __bits_per_word - __result.__ctz_;
__storage_type __ddn = _VSTD::min(__dn, static_cast<difference_type>(__result.__ctz_));
if (__ddn > 0)
{
__m = (~__storage_type(0) << (__result.__ctz_ - __ddn)) & (~__storage_type(0) >> __clz_r);
*__result.__seg_ &= ~__m;
if (__result.__ctz_ > __last.__ctz_)
*__result.__seg_ |= __b << (__result.__ctz_ - __last.__ctz_);
else
*__result.__seg_ |= __b >> (__last.__ctz_ - __result.__ctz_);
__result.__ctz_ = static_cast<unsigned>(((-__ddn & (__bits_per_word - 1)) +
__result.__ctz_) % __bits_per_word);
__dn -= __ddn;
}
if (__dn > 0)
{
// __result.__ctz_ == 0
--__result.__seg_;
__result.__ctz_ = static_cast<unsigned>(-__dn & (__bits_per_word - 1));
__m = ~__storage_type(0) << __result.__ctz_;
*__result.__seg_ &= ~__m;
__last.__ctz_ -= __dn + __ddn;
*__result.__seg_ |= __b << (__result.__ctz_ - __last.__ctz_);
}
// __last.__ctz_ = 0
}
// __last.__ctz_ == 0 || __n == 0
// __result.__ctz_ != 0 || __n == 0
// do middle words
unsigned __clz_r = __bits_per_word - __result.__ctz_;
__storage_type __m = ~__storage_type(0) >> __clz_r;
for (; __n >= __bits_per_word; __n -= __bits_per_word)
{
__storage_type __b = *--__last.__seg_;
*__result.__seg_ &= ~__m;
*__result.__seg_ |= __b >> __clz_r;
*--__result.__seg_ &= __m;
*__result.__seg_ |= __b << __result.__ctz_;
}
// do last word
if (__n > 0)
{
__m = ~__storage_type(0) << (__bits_per_word - __n);
__storage_type __b = *--__last.__seg_ & __m;
__clz_r = __bits_per_word - __result.__ctz_;
__storage_type __dn = _VSTD::min(__n, static_cast<difference_type>(__result.__ctz_));
__m = (~__storage_type(0) << (__result.__ctz_ - __dn)) & (~__storage_type(0) >> __clz_r);
*__result.__seg_ &= ~__m;
*__result.__seg_ |= __b >> (__bits_per_word - __result.__ctz_);
__result.__ctz_ = static_cast<unsigned>(((-__dn & (__bits_per_word - 1)) +
__result.__ctz_) % __bits_per_word);
__n -= __dn;
if (__n > 0)
{
// __result.__ctz_ == 0
--__result.__seg_;
__result.__ctz_ = static_cast<unsigned>(-__n & (__bits_per_word - 1));
__m = ~__storage_type(0) << __result.__ctz_;
*__result.__seg_ &= ~__m;
*__result.__seg_ |= __b << (__result.__ctz_ - (__bits_per_word - __n - __dn));
}
}
}
return __result;
}
template <class _Cp, bool _IsConst>
inline _LIBCPP_INLINE_VISIBILITY
__bit_iterator<_Cp, false>
copy_backward(__bit_iterator<_Cp, _IsConst> __first, __bit_iterator<_Cp, _IsConst> __last, __bit_iterator<_Cp, false> __result)
{
if (__last.__ctz_ == __result.__ctz_)
return __copy_backward_aligned(__first, __last, __result);
return __copy_backward_unaligned(__first, __last, __result);
}
// move
template <class _Cp, bool _IsConst>
inline _LIBCPP_INLINE_VISIBILITY
__bit_iterator<_Cp, false>
move(__bit_iterator<_Cp, _IsConst> __first, __bit_iterator<_Cp, _IsConst> __last, __bit_iterator<_Cp, false> __result)
{
return _VSTD::copy(__first, __last, __result);
}
// move_backward
template <class _Cp, bool _IsConst>
inline _LIBCPP_INLINE_VISIBILITY
__bit_iterator<_Cp, false>
move_backward(__bit_iterator<_Cp, _IsConst> __first, __bit_iterator<_Cp, _IsConst> __last, __bit_iterator<_Cp, false> __result)
{
return _VSTD::copy_backward(__first, __last, __result);
}
// swap_ranges
template <class __C1, class __C2>
__bit_iterator<__C2, false>
__swap_ranges_aligned(__bit_iterator<__C1, false> __first, __bit_iterator<__C1, false> __last,
__bit_iterator<__C2, false> __result)
{
typedef __bit_iterator<__C1, false> _I1;
typedef typename _I1::difference_type difference_type;
typedef typename _I1::__storage_type __storage_type;
const int __bits_per_word = _I1::__bits_per_word;
difference_type __n = __last - __first;
if (__n > 0)
{
// do first word
if (__first.__ctz_ != 0)
{
unsigned __clz = __bits_per_word - __first.__ctz_;
difference_type __dn = _VSTD::min(static_cast<difference_type>(__clz), __n);
__n -= __dn;
__storage_type __m = (~__storage_type(0) << __first.__ctz_) & (~__storage_type(0) >> (__clz - __dn));
__storage_type __b1 = *__first.__seg_ & __m;
*__first.__seg_ &= ~__m;
__storage_type __b2 = *__result.__seg_ & __m;
*__result.__seg_ &= ~__m;
*__result.__seg_ |= __b1;
*__first.__seg_ |= __b2;
__result.__seg_ += (__dn + __result.__ctz_) / __bits_per_word;
__result.__ctz_ = static_cast<unsigned>((__dn + __result.__ctz_) % __bits_per_word);
++__first.__seg_;
// __first.__ctz_ = 0;
}
// __first.__ctz_ == 0;
// do middle words
for (; __n >= __bits_per_word; __n -= __bits_per_word, ++__first.__seg_, ++__result.__seg_)
swap(*__first.__seg_, *__result.__seg_);
// do last word
if (__n > 0)
{
__storage_type __m = ~__storage_type(0) >> (__bits_per_word - __n);
__storage_type __b1 = *__first.__seg_ & __m;
*__first.__seg_ &= ~__m;
__storage_type __b2 = *__result.__seg_ & __m;
*__result.__seg_ &= ~__m;
*__result.__seg_ |= __b1;
*__first.__seg_ |= __b2;
__result.__ctz_ = static_cast<unsigned>(__n);
}
}
return __result;
}
template <class __C1, class __C2>
__bit_iterator<__C2, false>
__swap_ranges_unaligned(__bit_iterator<__C1, false> __first, __bit_iterator<__C1, false> __last,
__bit_iterator<__C2, false> __result)
{
typedef __bit_iterator<__C1, false> _I1;
typedef typename _I1::difference_type difference_type;
typedef typename _I1::__storage_type __storage_type;
const int __bits_per_word = _I1::__bits_per_word;
difference_type __n = __last - __first;
if (__n > 0)
{
// do first word
if (__first.__ctz_ != 0)
{
unsigned __clz_f = __bits_per_word - __first.__ctz_;
difference_type __dn = _VSTD::min(static_cast<difference_type>(__clz_f), __n);
__n -= __dn;
__storage_type __m = (~__storage_type(0) << __first.__ctz_) & (~__storage_type(0) >> (__clz_f - __dn));
__storage_type __b1 = *__first.__seg_ & __m;
*__first.__seg_ &= ~__m;
unsigned __clz_r = __bits_per_word - __result.__ctz_;
__storage_type __ddn = _VSTD::min<__storage_type>(__dn, __clz_r);
__m = (~__storage_type(0) << __result.__ctz_) & (~__storage_type(0) >> (__clz_r - __ddn));
__storage_type __b2 = *__result.__seg_ & __m;
*__result.__seg_ &= ~__m;
if (__result.__ctz_ > __first.__ctz_)
{
unsigned __s = __result.__ctz_ - __first.__ctz_;
*__result.__seg_ |= __b1 << __s;
*__first.__seg_ |= __b2 >> __s;
}
else
{
unsigned __s = __first.__ctz_ - __result.__ctz_;
*__result.__seg_ |= __b1 >> __s;
*__first.__seg_ |= __b2 << __s;
}
__result.__seg_ += (__ddn + __result.__ctz_) / __bits_per_word;
__result.__ctz_ = static_cast<unsigned>((__ddn + __result.__ctz_) % __bits_per_word);
__dn -= __ddn;
if (__dn > 0)
{
__m = ~__storage_type(0) >> (__bits_per_word - __dn);
__b2 = *__result.__seg_ & __m;
*__result.__seg_ &= ~__m;
unsigned __s = __first.__ctz_ + __ddn;
*__result.__seg_ |= __b1 >> __s;
*__first.__seg_ |= __b2 << __s;
__result.__ctz_ = static_cast<unsigned>(__dn);
}
++__first.__seg_;
// __first.__ctz_ = 0;
}
// __first.__ctz_ == 0;
// do middle words
__storage_type __m = ~__storage_type(0) << __result.__ctz_;
unsigned __clz_r = __bits_per_word - __result.__ctz_;
for (; __n >= __bits_per_word; __n -= __bits_per_word, ++__first.__seg_)
{
__storage_type __b1 = *__first.__seg_;
__storage_type __b2 = *__result.__seg_ & __m;
*__result.__seg_ &= ~__m;
*__result.__seg_ |= __b1 << __result.__ctz_;
*__first.__seg_ = __b2 >> __result.__ctz_;
++__result.__seg_;
__b2 = *__result.__seg_ & ~__m;
*__result.__seg_ &= __m;
*__result.__seg_ |= __b1 >> __clz_r;
*__first.__seg_ |= __b2 << __clz_r;
}
// do last word
if (__n > 0)
{
__m = ~__storage_type(0) >> (__bits_per_word - __n);
__storage_type __b1 = *__first.__seg_ & __m;
*__first.__seg_ &= ~__m;
__storage_type __dn = _VSTD::min<__storage_type>(__n, __clz_r);
__m = (~__storage_type(0) << __result.__ctz_) & (~__storage_type(0) >> (__clz_r - __dn));
__storage_type __b2 = *__result.__seg_ & __m;
*__result.__seg_ &= ~__m;
*__result.__seg_ |= __b1 << __result.__ctz_;
*__first.__seg_ |= __b2 >> __result.__ctz_;
__result.__seg_ += (__dn + __result.__ctz_) / __bits_per_word;
__result.__ctz_ = static_cast<unsigned>((__dn + __result.__ctz_) % __bits_per_word);
__n -= __dn;
if (__n > 0)
{
__m = ~__storage_type(0) >> (__bits_per_word - __n);
__b2 = *__result.__seg_ & __m;
*__result.__seg_ &= ~__m;
*__result.__seg_ |= __b1 >> __dn;
*__first.__seg_ |= __b2 << __dn;
__result.__ctz_ = static_cast<unsigned>(__n);
}
}
}
return __result;
}
template <class __C1, class __C2>
inline _LIBCPP_INLINE_VISIBILITY
__bit_iterator<__C2, false>
swap_ranges(__bit_iterator<__C1, false> __first1, __bit_iterator<__C1, false> __last1,
__bit_iterator<__C2, false> __first2)
{
if (__first1.__ctz_ == __first2.__ctz_)
return __swap_ranges_aligned(__first1, __last1, __first2);
return __swap_ranges_unaligned(__first1, __last1, __first2);
}
// rotate
template <class _Cp>
struct __bit_array
{
typedef typename _Cp::difference_type difference_type;
typedef typename _Cp::__storage_type __storage_type;
typedef typename _Cp::__storage_pointer __storage_pointer;
typedef typename _Cp::iterator iterator;
static const unsigned __bits_per_word = _Cp::__bits_per_word;
static const unsigned _Np = 4;
difference_type __size_;
__storage_type __word_[_Np];
_LIBCPP_INLINE_VISIBILITY static difference_type capacity()
{return static_cast<difference_type>(_Np * __bits_per_word);}
_LIBCPP_INLINE_VISIBILITY explicit __bit_array(difference_type __s) : __size_(__s) {}
_LIBCPP_INLINE_VISIBILITY iterator begin()
{
return iterator(pointer_traits<__storage_pointer>::pointer_to(__word_[0]), 0);
}
_LIBCPP_INLINE_VISIBILITY iterator end()
{
return iterator(pointer_traits<__storage_pointer>::pointer_to(__word_[0]) + __size_ / __bits_per_word,
static_cast<unsigned>(__size_ % __bits_per_word));
}
};
template <class _Cp>
__bit_iterator<_Cp, false>
rotate(__bit_iterator<_Cp, false> __first, __bit_iterator<_Cp, false> __middle, __bit_iterator<_Cp, false> __last)
{
typedef __bit_iterator<_Cp, false> _I1;
typedef typename _I1::difference_type difference_type;
difference_type __d1 = __middle - __first;
difference_type __d2 = __last - __middle;
_I1 __r = __first + __d2;
while (__d1 != 0 && __d2 != 0)
{
if (__d1 <= __d2)
{
if (__d1 <= __bit_array<_Cp>::capacity())
{
__bit_array<_Cp> __b(__d1);
_VSTD::copy(__first, __middle, __b.begin());
_VSTD::copy(__b.begin(), __b.end(), _VSTD::copy(__middle, __last, __first));
break;
}
else
{
__bit_iterator<_Cp, false> __mp = _VSTD::swap_ranges(__first, __middle, __middle);
__first = __middle;
__middle = __mp;
__d2 -= __d1;
}
}
else
{
if (__d2 <= __bit_array<_Cp>::capacity())
{
__bit_array<_Cp> __b(__d2);
_VSTD::copy(__middle, __last, __b.begin());
_VSTD::copy_backward(__b.begin(), __b.end(), _VSTD::copy_backward(__first, __middle, __last));
break;
}
else
{
__bit_iterator<_Cp, false> __mp = __first + __d2;
_VSTD::swap_ranges(__first, __mp, __middle);
__first = __mp;
__d1 -= __d2;
}
}
}
return __r;
}
// equal
template <class _Cp, bool _IC1, bool _IC2>
bool
__equal_unaligned(__bit_iterator<_Cp, _IC1> __first1, __bit_iterator<_Cp, _IC1> __last1,
__bit_iterator<_Cp, _IC2> __first2)
{
typedef __bit_iterator<_Cp, _IC1> _It;
typedef typename _It::difference_type difference_type;
typedef typename _It::__storage_type __storage_type;
static const int __bits_per_word = _It::__bits_per_word;
difference_type __n = __last1 - __first1;
if (__n > 0)
{
// do first word
if (__first1.__ctz_ != 0)
{
unsigned __clz_f = __bits_per_word - __first1.__ctz_;
difference_type __dn = _VSTD::min(static_cast<difference_type>(__clz_f), __n);
__n -= __dn;
__storage_type __m = (~__storage_type(0) << __first1.__ctz_) & (~__storage_type(0) >> (__clz_f - __dn));
__storage_type __b = *__first1.__seg_ & __m;
unsigned __clz_r = __bits_per_word - __first2.__ctz_;
__storage_type __ddn = _VSTD::min<__storage_type>(__dn, __clz_r);
__m = (~__storage_type(0) << __first2.__ctz_) & (~__storage_type(0) >> (__clz_r - __ddn));
if (__first2.__ctz_ > __first1.__ctz_)
{
if ((*__first2.__seg_ & __m) != (__b << (__first2.__ctz_ - __first1.__ctz_)))
return false;
}
else
{
if ((*__first2.__seg_ & __m) != (__b >> (__first1.__ctz_ - __first2.__ctz_)))
return false;
}
__first2.__seg_ += (__ddn + __first2.__ctz_) / __bits_per_word;
__first2.__ctz_ = static_cast<unsigned>((__ddn + __first2.__ctz_) % __bits_per_word);
__dn -= __ddn;
if (__dn > 0)
{
__m = ~__storage_type(0) >> (__bits_per_word - __dn);
if ((*__first2.__seg_ & __m) != (__b >> (__first1.__ctz_ + __ddn)))
return false;
__first2.__ctz_ = static_cast<unsigned>(__dn);
}
++__first1.__seg_;
// __first1.__ctz_ = 0;
}
// __first1.__ctz_ == 0;
// do middle words
unsigned __clz_r = __bits_per_word - __first2.__ctz_;
__storage_type __m = ~__storage_type(0) << __first2.__ctz_;
for (; __n >= __bits_per_word; __n -= __bits_per_word, ++__first1.__seg_)
{
__storage_type __b = *__first1.__seg_;
if ((*__first2.__seg_ & __m) != (__b << __first2.__ctz_))
return false;
++__first2.__seg_;
if ((*__first2.__seg_ & ~__m) != (__b >> __clz_r))
return false;
}
// do last word
if (__n > 0)
{
__m = ~__storage_type(0) >> (__bits_per_word - __n);
__storage_type __b = *__first1.__seg_ & __m;
__storage_type __dn = _VSTD::min(__n, static_cast<difference_type>(__clz_r));
__m = (~__storage_type(0) << __first2.__ctz_) & (~__storage_type(0) >> (__clz_r - __dn));
if ((*__first2.__seg_ & __m) != (__b << __first2.__ctz_))
return false;
__first2.__seg_ += (__dn + __first2.__ctz_) / __bits_per_word;
__first2.__ctz_ = static_cast<unsigned>((__dn + __first2.__ctz_) % __bits_per_word);
__n -= __dn;
if (__n > 0)
{
__m = ~__storage_type(0) >> (__bits_per_word - __n);
if ((*__first2.__seg_ & __m) != (__b >> __dn))
return false;
}
}
}
return true;
}
template <class _Cp, bool _IC1, bool _IC2>
bool
__equal_aligned(__bit_iterator<_Cp, _IC1> __first1, __bit_iterator<_Cp, _IC1> __last1,
__bit_iterator<_Cp, _IC2> __first2)
{
typedef __bit_iterator<_Cp, _IC1> _It;
typedef typename _It::difference_type difference_type;
typedef typename _It::__storage_type __storage_type;
static const int __bits_per_word = _It::__bits_per_word;
difference_type __n = __last1 - __first1;
if (__n > 0)
{
// do first word
if (__first1.__ctz_ != 0)
{
unsigned __clz = __bits_per_word - __first1.__ctz_;
difference_type __dn = _VSTD::min(static_cast<difference_type>(__clz), __n);
__n -= __dn;
__storage_type __m = (~__storage_type(0) << __first1.__ctz_) & (~__storage_type(0) >> (__clz - __dn));
if ((*__first2.__seg_ & __m) != (*__first1.__seg_ & __m))
return false;
++__first2.__seg_;
++__first1.__seg_;
// __first1.__ctz_ = 0;
// __first2.__ctz_ = 0;
}
// __first1.__ctz_ == 0;
// __first2.__ctz_ == 0;
// do middle words
for (; __n >= __bits_per_word; __n -= __bits_per_word, ++__first1.__seg_, ++__first2.__seg_)
if (*__first2.__seg_ != *__first1.__seg_)
return false;
// do last word
if (__n > 0)
{
__storage_type __m = ~__storage_type(0) >> (__bits_per_word - __n);
if ((*__first2.__seg_ & __m) != (*__first1.__seg_ & __m))
return false;
}
}
return true;
}
template <class _Cp, bool _IC1, bool _IC2>
inline _LIBCPP_INLINE_VISIBILITY
bool
equal(__bit_iterator<_Cp, _IC1> __first1, __bit_iterator<_Cp, _IC1> __last1, __bit_iterator<_Cp, _IC2> __first2)
{
if (__first1.__ctz_ == __first2.__ctz_)
return __equal_aligned(__first1, __last1, __first2);
return __equal_unaligned(__first1, __last1, __first2);
}
template <class _Cp, bool _IsConst,
typename _Cp::__storage_type>
class __bit_iterator
{
public:
typedef typename _Cp::difference_type difference_type;
typedef bool value_type;
typedef __bit_iterator pointer;
typedef typename conditional<_IsConst, __bit_const_reference<_Cp>, __bit_reference<_Cp> >::type reference;
typedef random_access_iterator_tag iterator_category;
private:
typedef typename _Cp::__storage_type __storage_type;
typedef typename conditional<_IsConst, typename _Cp::__const_storage_pointer,
typename _Cp::__storage_pointer>::type __storage_pointer;
static const unsigned __bits_per_word = _Cp::__bits_per_word;
__storage_pointer __seg_;
unsigned __ctz_;
public:
_LIBCPP_INLINE_VISIBILITY __bit_iterator() _NOEXCEPT
#if _LIBCPP_STD_VER > 11
: __seg_(nullptr), __ctz_(0)
#endif
{}
_LIBCPP_INLINE_VISIBILITY
__bit_iterator(const __bit_iterator<_Cp, false>& __it) _NOEXCEPT
: __seg_(__it.__seg_), __ctz_(__it.__ctz_) {}
_LIBCPP_INLINE_VISIBILITY reference operator*() const _NOEXCEPT
{return reference(__seg_, __storage_type(1) << __ctz_);}
_LIBCPP_INLINE_VISIBILITY __bit_iterator& operator++()
{
if (__ctz_ != __bits_per_word-1)
++__ctz_;
else
{
__ctz_ = 0;
++__seg_;
}
return *this;
}
_LIBCPP_INLINE_VISIBILITY __bit_iterator operator++(int)
{
__bit_iterator __tmp = *this;
++(*this);
return __tmp;
}
_LIBCPP_INLINE_VISIBILITY __bit_iterator& operator--()
{
if (__ctz_ != 0)
--__ctz_;
else
{
__ctz_ = __bits_per_word - 1;
--__seg_;
}
return *this;
}
_LIBCPP_INLINE_VISIBILITY __bit_iterator operator--(int)
{
__bit_iterator __tmp = *this;
--(*this);
return __tmp;
}
_LIBCPP_INLINE_VISIBILITY __bit_iterator& operator+=(difference_type __n)
{
if (__n >= 0)
__seg_ += (__n + __ctz_) / __bits_per_word;
else
__seg_ += static_cast<difference_type>(__n - __bits_per_word + __ctz_ + 1)
/ static_cast<difference_type>(__bits_per_word);
__n &= (__bits_per_word - 1);
__ctz_ = static_cast<unsigned>((__n + __ctz_) % __bits_per_word);
return *this;
}
_LIBCPP_INLINE_VISIBILITY __bit_iterator& operator-=(difference_type __n)
{
return *this += -__n;
}
_LIBCPP_INLINE_VISIBILITY __bit_iterator operator+(difference_type __n) const
{
__bit_iterator __t(*this);
__t += __n;
return __t;
}
_LIBCPP_INLINE_VISIBILITY __bit_iterator operator-(difference_type __n) const
{
__bit_iterator __t(*this);
__t -= __n;
return __t;
}
_LIBCPP_INLINE_VISIBILITY
friend __bit_iterator operator+(difference_type __n, const __bit_iterator& __it) {return __it + __n;}
_LIBCPP_INLINE_VISIBILITY
friend difference_type operator-(const __bit_iterator& __x, const __bit_iterator& __y)
{return (__x.__seg_ - __y.__seg_) * __bits_per_word + __x.__ctz_ - __y.__ctz_;}
_LIBCPP_INLINE_VISIBILITY reference operator[](difference_type __n) const {return *(*this + __n);}
_LIBCPP_INLINE_VISIBILITY friend bool operator==(const __bit_iterator& __x, const __bit_iterator& __y)
{return __x.__seg_ == __y.__seg_ && __x.__ctz_ == __y.__ctz_;}
_LIBCPP_INLINE_VISIBILITY friend bool operator!=(const __bit_iterator& __x, const __bit_iterator& __y)
{return !(__x == __y);}
_LIBCPP_INLINE_VISIBILITY friend bool operator<(const __bit_iterator& __x, const __bit_iterator& __y)
{return __x.__seg_ < __y.__seg_ || (__x.__seg_ == __y.__seg_ && __x.__ctz_ < __y.__ctz_);}
_LIBCPP_INLINE_VISIBILITY friend bool operator>(const __bit_iterator& __x, const __bit_iterator& __y)
{return __y < __x;}
_LIBCPP_INLINE_VISIBILITY friend bool operator<=(const __bit_iterator& __x, const __bit_iterator& __y)
{return !(__y < __x);}
_LIBCPP_INLINE_VISIBILITY friend bool operator>=(const __bit_iterator& __x, const __bit_iterator& __y)
{return !(__x < __y);}
private:
_LIBCPP_INLINE_VISIBILITY
__bit_iterator(__storage_pointer __s, unsigned __ctz) _NOEXCEPT
: __seg_(__s), __ctz_(__ctz) {}
friend typename _Cp::__self;
friend class __bit_reference<_Cp>;
friend class __bit_const_reference<_Cp>;
friend class __bit_iterator<_Cp, true>;
template <class _Dp> friend struct __bit_array;
template <class _Dp> friend void __fill_n_false(__bit_iterator<_Dp, false> __first, typename _Dp::size_type __n);
template <class _Dp> friend void __fill_n_true(__bit_iterator<_Dp, false> __first, typename _Dp::size_type __n);
template <class _Dp, bool _IC> friend __bit_iterator<_Dp, false> __copy_aligned(__bit_iterator<_Dp, _IC> __first,
__bit_iterator<_Dp, _IC> __last,
__bit_iterator<_Dp, false> __result);
template <class _Dp, bool _IC> friend __bit_iterator<_Dp, false> __copy_unaligned(__bit_iterator<_Dp, _IC> __first,
__bit_iterator<_Dp, _IC> __last,
__bit_iterator<_Dp, false> __result);
template <class _Dp, bool _IC> friend __bit_iterator<_Dp, false> copy(__bit_iterator<_Dp, _IC> __first,
__bit_iterator<_Dp, _IC> __last,
__bit_iterator<_Dp, false> __result);
template <class _Dp, bool _IC> friend __bit_iterator<_Dp, false> __copy_backward_aligned(__bit_iterator<_Dp, _IC> __first,
__bit_iterator<_Dp, _IC> __last,
__bit_iterator<_Dp, false> __result);
template <class _Dp, bool _IC> friend __bit_iterator<_Dp, false> __copy_backward_unaligned(__bit_iterator<_Dp, _IC> __first,
__bit_iterator<_Dp, _IC> __last,
__bit_iterator<_Dp, false> __result);
template <class _Dp, bool _IC> friend __bit_iterator<_Dp, false> copy_backward(__bit_iterator<_Dp, _IC> __first,
__bit_iterator<_Dp, _IC> __last,
__bit_iterator<_Dp, false> __result);
template <class __C1, class __C2>friend __bit_iterator<__C2, false> __swap_ranges_aligned(__bit_iterator<__C1, false>,
__bit_iterator<__C1, false>,
__bit_iterator<__C2, false>);
template <class __C1, class __C2>friend __bit_iterator<__C2, false> __swap_ranges_unaligned(__bit_iterator<__C1, false>,
__bit_iterator<__C1, false>,
__bit_iterator<__C2, false>);
template <class __C1, class __C2>friend __bit_iterator<__C2, false> swap_ranges(__bit_iterator<__C1, false>,
__bit_iterator<__C1, false>,
__bit_iterator<__C2, false>);
template <class _Dp> friend __bit_iterator<_Dp, false> rotate(__bit_iterator<_Dp, false>,
__bit_iterator<_Dp, false>,
__bit_iterator<_Dp, false>);
template <class _Dp, bool _IC1, bool _IC2> friend bool __equal_aligned(__bit_iterator<_Dp, _IC1>,
__bit_iterator<_Dp, _IC1>,
__bit_iterator<_Dp, _IC2>);
template <class _Dp, bool _IC1, bool _IC2> friend bool __equal_unaligned(__bit_iterator<_Dp, _IC1>,
__bit_iterator<_Dp, _IC1>,
__bit_iterator<_Dp, _IC2>);
template <class _Dp, bool _IC1, bool _IC2> friend bool equal(__bit_iterator<_Dp, _IC1>,
__bit_iterator<_Dp, _IC1>,
__bit_iterator<_Dp, _IC2>);
template <class _Dp, bool _IC> friend __bit_iterator<_Dp, _IC> __find_bool_true(__bit_iterator<_Dp, _IC>,
typename _Dp::size_type);
template <class _Dp, bool _IC> friend __bit_iterator<_Dp, _IC> __find_bool_false(__bit_iterator<_Dp, _IC>,
typename _Dp::size_type);
template <class _Dp, bool _IC> friend typename __bit_iterator<_Dp, _IC>::difference_type
__count_bool_true(__bit_iterator<_Dp, _IC>, typename _Dp::size_type);
template <class _Dp, bool _IC> friend typename __bit_iterator<_Dp, _IC>::difference_type
__count_bool_false(__bit_iterator<_Dp, _IC>, typename _Dp::size_type);
};
_LIBCPP_END_NAMESPACE_STD
_LIBCPP_POP_MACROS
#endif // _LIBCPP___BIT_REFERENCE
| 52,270 | 1,281 | jart/cosmopolitan | false |
cosmopolitan/third_party/libcxx/wchar.h | // -*- C++ -*-
//===--------------------------- wchar.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_WCHAR_H
#define _LIBCPP_WCHAR_H
#include "libc/str/str.h"
#include "libc/time/time.h"
#include "third_party/libcxx/__config"
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
#pragma GCC system_header
#endif
/*
wchar.h synopsis
Macros:
NULL
WCHAR_MAX
WCHAR_MIN
WEOF
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);d
ouble 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);
*/
#ifdef __cplusplus
#define __CORRECT_ISO_CPP_WCHAR_H_PROTO
#endif
// #include_next <wchar.h>
// Determine whether we have const-correct overloads for wcschr and friends.
#if defined(_WCHAR_H_CPLUSPLUS_98_CONFORMANCE_)
#define _LIBCPP_WCHAR_H_HAS_CONST_OVERLOADS 1
#elif defined(__GLIBC_PREREQ)
#if __GLIBC_PREREQ(2, 10)
#define _LIBCPP_WCHAR_H_HAS_CONST_OVERLOADS 1
#endif
#elif defined(_LIBCPP_MSVCRT)
#if defined(_CRT_CONST_CORRECT_OVERLOADS)
#define _LIBCPP_WCHAR_H_HAS_CONST_OVERLOADS 1
#endif
#endif
#if defined(__cplusplus) && !defined(_LIBCPP_WCHAR_H_HAS_CONST_OVERLOADS) && \
defined(_LIBCPP_PREFERRED_OVERLOAD)
extern "C++" {
inline _LIBCPP_INLINE_VISIBILITY wchar_t* __libcpp_wcschr(const wchar_t* __s,
wchar_t __c) {
return (wchar_t*)wcschr(__s, __c);
}
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_PREFERRED_OVERLOAD const wchar_t*
wcschr(const wchar_t* __s, wchar_t __c) {
return __libcpp_wcschr(__s, __c);
}
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_PREFERRED_OVERLOAD wchar_t*
wcschr(wchar_t* __s, wchar_t __c) {
return __libcpp_wcschr(__s, __c);
}
inline _LIBCPP_INLINE_VISIBILITY wchar_t*
__libcpp_wcspbrk(const wchar_t* __s1, const wchar_t* __s2) {
return (wchar_t*)wcspbrk(__s1, __s2);
}
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_PREFERRED_OVERLOAD const wchar_t*
wcspbrk(const wchar_t* __s1, const wchar_t* __s2) {
return __libcpp_wcspbrk(__s1, __s2);
}
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_PREFERRED_OVERLOAD wchar_t*
wcspbrk(wchar_t* __s1, const wchar_t* __s2) {
return __libcpp_wcspbrk(__s1, __s2);
}
inline _LIBCPP_INLINE_VISIBILITY wchar_t* __libcpp_wcsrchr(const wchar_t* __s,
wchar_t __c) {
return (wchar_t*)wcsrchr(__s, __c);
}
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_PREFERRED_OVERLOAD const wchar_t*
wcsrchr(const wchar_t* __s, wchar_t __c) {
return __libcpp_wcsrchr(__s, __c);
}
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_PREFERRED_OVERLOAD wchar_t*
wcsrchr(wchar_t* __s, wchar_t __c) {
return __libcpp_wcsrchr(__s, __c);
}
inline _LIBCPP_INLINE_VISIBILITY wchar_t* __libcpp_wcsstr(const wchar_t* __s1,
const wchar_t* __s2) {
return (wchar_t*)wcsstr(__s1, __s2);
}
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_PREFERRED_OVERLOAD const wchar_t*
wcsstr(const wchar_t* __s1, const wchar_t* __s2) {
return __libcpp_wcsstr(__s1, __s2);
}
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_PREFERRED_OVERLOAD wchar_t*
wcsstr(wchar_t* __s1, const wchar_t* __s2) {
return __libcpp_wcsstr(__s1, __s2);
}
inline _LIBCPP_INLINE_VISIBILITY wchar_t*
__libcpp_wmemchr(const wchar_t* __s, wchar_t __c, size_t __n) {
return (wchar_t*)wmemchr(__s, __c, __n);
}
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_PREFERRED_OVERLOAD const wchar_t*
wmemchr(const wchar_t* __s, wchar_t __c, size_t __n) {
return __libcpp_wmemchr(__s, __c, __n);
}
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_PREFERRED_OVERLOAD wchar_t*
wmemchr(wchar_t* __s, wchar_t __c, size_t __n) {
return __libcpp_wmemchr(__s, __c, __n);
}
}
#endif
#if defined(__cplusplus) && defined(_LIBCPP_MSVCRT_LIKE)
extern "C" {
size_t mbsnrtowcs(wchar_t* __restrict dst, const char** __restrict src,
size_t nmc, size_t len, mbstate_t* __restrict ps);
size_t wcsnrtombs(char* __restrict dst, const wchar_t** __restrict src,
size_t nwc, size_t len, mbstate_t* __restrict ps);
} // extern "C++"
#endif // __cplusplus && _LIBCPP_MSVCRT
#endif // _LIBCPP_WCHAR_H
| 8,484 | 206 | jart/cosmopolitan | false |
cosmopolitan/third_party/libcxx/cfloat | // -*- C++ -*-
// clang-format off
//===--------------------------- cfloat -----------------------------------===//
//
// 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_CFLOAT
#define _LIBCPP_CFLOAT
/*
cfloat synopsis
Macros:
FLT_ROUNDS
FLT_EVAL_METHOD // C99
FLT_RADIX
FLT_HAS_SUBNORM // C11
DBL_HAS_SUBNORM // C11
LDBL_HAS_SUBNORM // C11
FLT_MANT_DIG
DBL_MANT_DIG
LDBL_MANT_DIG
DECIMAL_DIG // C99
FLT_DECIMAL_DIG // C11
DBL_DECIMAL_DIG // C11
LDBL_DECIMAL_DIG // C11
FLT_DIG
DBL_DIG
LDBL_DIG
FLT_MIN_EXP
DBL_MIN_EXP
LDBL_MIN_EXP
FLT_MIN_10_EXP
DBL_MIN_10_EXP
LDBL_MIN_10_EXP
FLT_MAX_EXP
DBL_MAX_EXP
LDBL_MAX_EXP
FLT_MAX_10_EXP
DBL_MAX_10_EXP
LDBL_MAX_10_EXP
FLT_MAX
DBL_MAX
LDBL_MAX
FLT_EPSILON
DBL_EPSILON
LDBL_EPSILON
FLT_MIN
DBL_MIN
LDBL_MIN
FLT_TRUE_MIN // C11
DBL_TRUE_MIN // C11
LDBL_TRUE_MIN // C11
*/
#include "third_party/libcxx/__config"
#include "libc/math.h"
#include "libc/runtime/fenv.h"
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
#pragma GCC system_header
#endif
#endif // _LIBCPP_CFLOAT
| 1,501 | 82 | jart/cosmopolitan | false |
cosmopolitan/third_party/libcxx/chrono.cc | // clang-format off
//===------------------------- chrono.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/chrono"
#include "third_party/libcxx/cerrno" // errn"
#include "libc/sysv/consts/clock.h"
#include "libc/time/time.h"
#include "libc/sysv/consts/clock.h"
#include "third_party/libcxx/system_error" // __throw_system_erro"
#define _LIBCPP_USE_CLOCK_GETTIME
_LIBCPP_BEGIN_NAMESPACE_STD
namespace chrono
{
// system_clock
const bool system_clock::is_steady;
system_clock::time_point
system_clock::now() _NOEXCEPT
{
struct timespec tp;
if (0 != clock_gettime(CLOCK_REALTIME, &tp))
__throw_system_error(errno, "clock_gettime(CLOCK_REALTIME) failed");
return time_point(seconds(tp.tv_sec) + microseconds(tp.tv_nsec / 1000));
}
time_t
system_clock::to_time_t(const time_point& t) _NOEXCEPT
{
return time_t(duration_cast<seconds>(t.time_since_epoch()).count());
}
system_clock::time_point
system_clock::from_time_t(time_t t) _NOEXCEPT
{
return system_clock::time_point(seconds(t));
}
// steady_clock
//
// Warning: If this is not truly steady, then it is non-conforming. It is
// better for it to not exist and have the rest of libc++ use system_clock
// instead.
const bool steady_clock::is_steady;
steady_clock::time_point
steady_clock::now() _NOEXCEPT
{
struct timespec tp;
if (0 != clock_gettime(CLOCK_MONOTONIC, &tp))
__throw_system_error(errno, "clock_gettime(CLOCK_MONOTONIC) failed");
return time_point(seconds(tp.tv_sec) + nanoseconds(tp.tv_nsec));
}
} // namespace chrono
_LIBCPP_END_NAMESPACE_STD
| 1,882 | 69 | jart/cosmopolitan | false |
cosmopolitan/third_party/libcxx/csetjmp | // -*- C++ -*-
// clang-format off
//===--------------------------- csetjmp ----------------------------------===//
//
// 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_CSETJMP
#define _LIBCPP_CSETJMP
/*
csetjmp synopsis
Macros:
setjmp
namespace std
{
Types:
jmp_buf
void longjmp(jmp_buf env, int val);
} // std
*/
#include "third_party/libcxx/__config"
#include "libc/runtime/runtime.h"
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
#pragma GCC system_header
#endif
_LIBCPP_BEGIN_NAMESPACE_STD
using ::jmp_buf;
using ::longjmp;
_LIBCPP_END_NAMESPACE_STD
#endif // _LIBCPP_CSETJMP
| 866 | 49 | jart/cosmopolitan | false |
cosmopolitan/third_party/libcxx/__split_buffer | // -*- C++ -*-
#ifndef _LIBCPP_SPLIT_BUFFER
#define _LIBCPP_SPLIT_BUFFER
#include "third_party/libcxx/__config"
#include "third_party/libcxx/type_traits"
#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
template <bool>
class __split_buffer_common
{
protected:
void __throw_length_error() const;
void __throw_out_of_range() const;
};
template <class _Tp, class _Allocator = allocator<_Tp> >
struct __split_buffer
: private __split_buffer_common<true>
{
private:
__split_buffer(const __split_buffer&);
__split_buffer& operator=(const __split_buffer&);
public:
typedef _Tp value_type;
typedef _Allocator allocator_type;
typedef typename remove_reference<allocator_type>::type __alloc_rr;
typedef allocator_traits<__alloc_rr> __alloc_traits;
typedef value_type& reference;
typedef const value_type& const_reference;
typedef typename __alloc_traits::size_type size_type;
typedef typename __alloc_traits::difference_type difference_type;
typedef typename __alloc_traits::pointer pointer;
typedef typename __alloc_traits::const_pointer const_pointer;
typedef pointer iterator;
typedef const_pointer const_iterator;
pointer __first_;
pointer __begin_;
pointer __end_;
__compressed_pair<pointer, allocator_type> __end_cap_;
typedef typename add_lvalue_reference<allocator_type>::type __alloc_ref;
typedef typename add_lvalue_reference<allocator_type>::type __alloc_const_ref;
_LIBCPP_INLINE_VISIBILITY __alloc_rr& __alloc() _NOEXCEPT {return __end_cap_.second();}
_LIBCPP_INLINE_VISIBILITY const __alloc_rr& __alloc() const _NOEXCEPT {return __end_cap_.second();}
_LIBCPP_INLINE_VISIBILITY pointer& __end_cap() _NOEXCEPT {return __end_cap_.first();}
_LIBCPP_INLINE_VISIBILITY const pointer& __end_cap() const _NOEXCEPT {return __end_cap_.first();}
_LIBCPP_INLINE_VISIBILITY
__split_buffer()
_NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value);
_LIBCPP_INLINE_VISIBILITY
explicit __split_buffer(__alloc_rr& __a);
_LIBCPP_INLINE_VISIBILITY
explicit __split_buffer(const __alloc_rr& __a);
__split_buffer(size_type __cap, size_type __start, __alloc_rr& __a);
~__split_buffer();
#ifndef _LIBCPP_CXX03_LANG
__split_buffer(__split_buffer&& __c)
_NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value);
__split_buffer(__split_buffer&& __c, const __alloc_rr& __a);
__split_buffer& operator=(__split_buffer&& __c)
_NOEXCEPT_((__alloc_traits::propagate_on_container_move_assignment::value &&
is_nothrow_move_assignable<allocator_type>::value) ||
!__alloc_traits::propagate_on_container_move_assignment::value);
#endif // _LIBCPP_CXX03_LANG
_LIBCPP_INLINE_VISIBILITY iterator begin() _NOEXCEPT {return __begin_;}
_LIBCPP_INLINE_VISIBILITY const_iterator begin() const _NOEXCEPT {return __begin_;}
_LIBCPP_INLINE_VISIBILITY iterator end() _NOEXCEPT {return __end_;}
_LIBCPP_INLINE_VISIBILITY const_iterator end() const _NOEXCEPT {return __end_;}
_LIBCPP_INLINE_VISIBILITY
void clear() _NOEXCEPT
{__destruct_at_end(__begin_);}
_LIBCPP_INLINE_VISIBILITY size_type size() const {return static_cast<size_type>(__end_ - __begin_);}
_LIBCPP_INLINE_VISIBILITY bool empty() const {return __end_ == __begin_;}
_LIBCPP_INLINE_VISIBILITY size_type capacity() const {return static_cast<size_type>(__end_cap() - __first_);}
_LIBCPP_INLINE_VISIBILITY size_type __front_spare() const {return static_cast<size_type>(__begin_ - __first_);}
_LIBCPP_INLINE_VISIBILITY size_type __back_spare() const {return static_cast<size_type>(__end_cap() - __end_);}
_LIBCPP_INLINE_VISIBILITY reference front() {return *__begin_;}
_LIBCPP_INLINE_VISIBILITY const_reference front() const {return *__begin_;}
_LIBCPP_INLINE_VISIBILITY reference back() {return *(__end_ - 1);}
_LIBCPP_INLINE_VISIBILITY const_reference back() const {return *(__end_ - 1);}
void reserve(size_type __n);
void shrink_to_fit() _NOEXCEPT;
void push_front(const_reference __x);
_LIBCPP_INLINE_VISIBILITY void push_back(const_reference __x);
#ifndef _LIBCPP_CXX03_LANG
void push_front(value_type&& __x);
void push_back(value_type&& __x);
template <class... _Args>
void emplace_back(_Args&&... __args);
#endif // !defined(_LIBCPP_CXX03_LANG)
_LIBCPP_INLINE_VISIBILITY void pop_front() {__destruct_at_begin(__begin_+1);}
_LIBCPP_INLINE_VISIBILITY void pop_back() {__destruct_at_end(__end_-1);}
void __construct_at_end(size_type __n);
void __construct_at_end(size_type __n, const_reference __x);
template <class _InputIter>
typename enable_if
<
__is_input_iterator<_InputIter>::value &&
!__is_forward_iterator<_InputIter>::value,
void
>::type
__construct_at_end(_InputIter __first, _InputIter __last);
template <class _ForwardIterator>
typename enable_if
<
__is_forward_iterator<_ForwardIterator>::value,
void
>::type
__construct_at_end(_ForwardIterator __first, _ForwardIterator __last);
_LIBCPP_INLINE_VISIBILITY void __destruct_at_begin(pointer __new_begin)
{__destruct_at_begin(__new_begin, is_trivially_destructible<value_type>());}
_LIBCPP_INLINE_VISIBILITY
void __destruct_at_begin(pointer __new_begin, false_type);
_LIBCPP_INLINE_VISIBILITY
void __destruct_at_begin(pointer __new_begin, true_type);
_LIBCPP_INLINE_VISIBILITY
void __destruct_at_end(pointer __new_last) _NOEXCEPT
{__destruct_at_end(__new_last, false_type());}
_LIBCPP_INLINE_VISIBILITY
void __destruct_at_end(pointer __new_last, false_type) _NOEXCEPT;
_LIBCPP_INLINE_VISIBILITY
void __destruct_at_end(pointer __new_last, true_type) _NOEXCEPT;
void swap(__split_buffer& __x)
_NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value||
__is_nothrow_swappable<__alloc_rr>::value);
bool __invariants() const;
private:
_LIBCPP_INLINE_VISIBILITY
void __move_assign_alloc(__split_buffer& __c, true_type)
_NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value)
{
__alloc() = _VSTD::move(__c.__alloc());
}
_LIBCPP_INLINE_VISIBILITY
void __move_assign_alloc(__split_buffer&, false_type) _NOEXCEPT
{}
struct _ConstructTransaction {
explicit _ConstructTransaction(pointer* __p, size_type __n) _NOEXCEPT
: __pos_(*__p), __end_(*__p + __n), __dest_(__p) {
}
~_ConstructTransaction() {
*__dest_ = __pos_;
}
pointer __pos_;
const pointer __end_;
private:
pointer *__dest_;
};
};
template <class _Tp, class _Allocator>
bool
__split_buffer<_Tp, _Allocator>::__invariants() const
{
if (__first_ == nullptr)
{
if (__begin_ != nullptr)
return false;
if (__end_ != nullptr)
return false;
if (__end_cap() != nullptr)
return false;
}
else
{
if (__begin_ < __first_)
return false;
if (__end_ < __begin_)
return false;
if (__end_cap() < __end_)
return false;
}
return true;
}
// Default constructs __n objects starting at __end_
// throws if construction throws
// Precondition: __n > 0
// Precondition: size() + __n <= capacity()
// Postcondition: size() == size() + __n
template <class _Tp, class _Allocator>
void
__split_buffer<_Tp, _Allocator>::__construct_at_end(size_type __n)
{
_ConstructTransaction __tx(&this->__end_, __n);
for (; __tx.__pos_ != __tx.__end_; ++__tx.__pos_) {
__alloc_traits::construct(this->__alloc(), _VSTD::__to_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>
void
__split_buffer<_Tp, _Allocator>::__construct_at_end(size_type __n, const_reference __x)
{
_ConstructTransaction __tx(&this->__end_, __n);
for (; __tx.__pos_ != __tx.__end_; ++__tx.__pos_) {
__alloc_traits::construct(this->__alloc(),
_VSTD::__to_raw_pointer(__tx.__pos_), __x);
}
}
template <class _Tp, class _Allocator>
template <class _InputIter>
typename enable_if
<
__is_input_iterator<_InputIter>::value &&
!__is_forward_iterator<_InputIter>::value,
void
>::type
__split_buffer<_Tp, _Allocator>::__construct_at_end(_InputIter __first, _InputIter __last)
{
__alloc_rr& __a = this->__alloc();
for (; __first != __last; ++__first)
{
if (__end_ == __end_cap())
{
size_type __old_cap = __end_cap() - __first_;
size_type __new_cap = _VSTD::max<size_type>(2 * __old_cap, 8);
__split_buffer __buf(__new_cap, 0, __a);
for (pointer __p = __begin_; __p != __end_; ++__p, ++__buf.__end_)
__alloc_traits::construct(__buf.__alloc(),
_VSTD::__to_raw_pointer(__buf.__end_), _VSTD::move(*__p));
swap(__buf);
}
__alloc_traits::construct(__a, _VSTD::__to_raw_pointer(this->__end_), *__first);
++this->__end_;
}
}
template <class _Tp, class _Allocator>
template <class _ForwardIterator>
typename enable_if
<
__is_forward_iterator<_ForwardIterator>::value,
void
>::type
__split_buffer<_Tp, _Allocator>::__construct_at_end(_ForwardIterator __first, _ForwardIterator __last)
{
_ConstructTransaction __tx(&this->__end_, std::distance(__first, __last));
for (; __tx.__pos_ != __tx.__end_; ++__tx.__pos_, ++__first) {
__alloc_traits::construct(this->__alloc(),
_VSTD::__to_raw_pointer(__tx.__pos_), *__first);
}
}
template <class _Tp, class _Allocator>
inline
void
__split_buffer<_Tp, _Allocator>::__destruct_at_begin(pointer __new_begin, false_type)
{
while (__begin_ != __new_begin)
__alloc_traits::destroy(__alloc(), __to_raw_pointer(__begin_++));
}
template <class _Tp, class _Allocator>
inline
void
__split_buffer<_Tp, _Allocator>::__destruct_at_begin(pointer __new_begin, true_type)
{
__begin_ = __new_begin;
}
template <class _Tp, class _Allocator>
inline _LIBCPP_INLINE_VISIBILITY
void
__split_buffer<_Tp, _Allocator>::__destruct_at_end(pointer __new_last, false_type) _NOEXCEPT
{
while (__new_last != __end_)
__alloc_traits::destroy(__alloc(), __to_raw_pointer(--__end_));
}
template <class _Tp, class _Allocator>
inline _LIBCPP_INLINE_VISIBILITY
void
__split_buffer<_Tp, _Allocator>::__destruct_at_end(pointer __new_last, true_type) _NOEXCEPT
{
__end_ = __new_last;
}
template <class _Tp, class _Allocator>
__split_buffer<_Tp, _Allocator>::__split_buffer(size_type __cap, size_type __start, __alloc_rr& __a)
: __end_cap_(nullptr, __a)
{
__first_ = __cap != 0 ? __alloc_traits::allocate(__alloc(), __cap) : nullptr;
__begin_ = __end_ = __first_ + __start;
__end_cap() = __first_ + __cap;
}
template <class _Tp, class _Allocator>
inline
__split_buffer<_Tp, _Allocator>::__split_buffer()
_NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value)
: __first_(nullptr), __begin_(nullptr), __end_(nullptr), __end_cap_(nullptr)
{
}
template <class _Tp, class _Allocator>
inline
__split_buffer<_Tp, _Allocator>::__split_buffer(__alloc_rr& __a)
: __first_(nullptr), __begin_(nullptr), __end_(nullptr), __end_cap_(nullptr, __a)
{
}
template <class _Tp, class _Allocator>
inline
__split_buffer<_Tp, _Allocator>::__split_buffer(const __alloc_rr& __a)
: __first_(nullptr), __begin_(nullptr), __end_(nullptr), __end_cap_(nullptr, __a)
{
}
template <class _Tp, class _Allocator>
__split_buffer<_Tp, _Allocator>::~__split_buffer()
{
clear();
if (__first_)
__alloc_traits::deallocate(__alloc(), __first_, capacity());
}
#ifndef _LIBCPP_CXX03_LANG
template <class _Tp, class _Allocator>
__split_buffer<_Tp, _Allocator>::__split_buffer(__split_buffer&& __c)
_NOEXCEPT_(is_nothrow_move_constructible<allocator_type>::value)
: __first_(_VSTD::move(__c.__first_)),
__begin_(_VSTD::move(__c.__begin_)),
__end_(_VSTD::move(__c.__end_)),
__end_cap_(_VSTD::move(__c.__end_cap_))
{
__c.__first_ = nullptr;
__c.__begin_ = nullptr;
__c.__end_ = nullptr;
__c.__end_cap() = nullptr;
}
template <class _Tp, class _Allocator>
__split_buffer<_Tp, _Allocator>::__split_buffer(__split_buffer&& __c, const __alloc_rr& __a)
: __end_cap_(__second_tag(), __a)
{
if (__a == __c.__alloc())
{
__first_ = __c.__first_;
__begin_ = __c.__begin_;
__end_ = __c.__end_;
__end_cap() = __c.__end_cap();
__c.__first_ = nullptr;
__c.__begin_ = nullptr;
__c.__end_ = nullptr;
__c.__end_cap() = nullptr;
}
else
{
size_type __cap = __c.size();
__first_ = __alloc_traits::allocate(__alloc(), __cap);
__begin_ = __end_ = __first_;
__end_cap() = __first_ + __cap;
typedef move_iterator<iterator> _Ip;
__construct_at_end(_Ip(__c.begin()), _Ip(__c.end()));
}
}
template <class _Tp, class _Allocator>
__split_buffer<_Tp, _Allocator>&
__split_buffer<_Tp, _Allocator>::operator=(__split_buffer&& __c)
_NOEXCEPT_((__alloc_traits::propagate_on_container_move_assignment::value &&
is_nothrow_move_assignable<allocator_type>::value) ||
!__alloc_traits::propagate_on_container_move_assignment::value)
{
clear();
shrink_to_fit();
__first_ = __c.__first_;
__begin_ = __c.__begin_;
__end_ = __c.__end_;
__end_cap() = __c.__end_cap();
__move_assign_alloc(__c,
integral_constant<bool,
__alloc_traits::propagate_on_container_move_assignment::value>());
__c.__first_ = __c.__begin_ = __c.__end_ = __c.__end_cap() = nullptr;
return *this;
}
#endif // _LIBCPP_CXX03_LANG
template <class _Tp, class _Allocator>
void
__split_buffer<_Tp, _Allocator>::swap(__split_buffer& __x)
_NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value||
__is_nothrow_swappable<__alloc_rr>::value)
{
_VSTD::swap(__first_, __x.__first_);
_VSTD::swap(__begin_, __x.__begin_);
_VSTD::swap(__end_, __x.__end_);
_VSTD::swap(__end_cap(), __x.__end_cap());
__swap_allocator(__alloc(), __x.__alloc());
}
template <class _Tp, class _Allocator>
void
__split_buffer<_Tp, _Allocator>::reserve(size_type __n)
{
if (__n < capacity())
{
__split_buffer<value_type, __alloc_rr&> __t(__n, 0, __alloc());
__t.__construct_at_end(move_iterator<pointer>(__begin_),
move_iterator<pointer>(__end_));
_VSTD::swap(__first_, __t.__first_);
_VSTD::swap(__begin_, __t.__begin_);
_VSTD::swap(__end_, __t.__end_);
_VSTD::swap(__end_cap(), __t.__end_cap());
}
}
template <class _Tp, class _Allocator>
void
__split_buffer<_Tp, _Allocator>::shrink_to_fit() _NOEXCEPT
{
if (capacity() > size())
{
#ifndef _LIBCPP_NO_EXCEPTIONS
try
{
#endif // _LIBCPP_NO_EXCEPTIONS
__split_buffer<value_type, __alloc_rr&> __t(size(), 0, __alloc());
__t.__construct_at_end(move_iterator<pointer>(__begin_),
move_iterator<pointer>(__end_));
__t.__end_ = __t.__begin_ + (__end_ - __begin_);
_VSTD::swap(__first_, __t.__first_);
_VSTD::swap(__begin_, __t.__begin_);
_VSTD::swap(__end_, __t.__end_);
_VSTD::swap(__end_cap(), __t.__end_cap());
#ifndef _LIBCPP_NO_EXCEPTIONS
}
catch (...)
{
}
#endif // _LIBCPP_NO_EXCEPTIONS
}
}
template <class _Tp, class _Allocator>
void
__split_buffer<_Tp, _Allocator>::push_front(const_reference __x)
{
if (__begin_ == __first_)
{
if (__end_ < __end_cap())
{
difference_type __d = __end_cap() - __end_;
__d = (__d + 1) / 2;
__begin_ = _VSTD::move_backward(__begin_, __end_, __end_ + __d);
__end_ += __d;
}
else
{
size_type __c = max<size_type>(2 * static_cast<size_t>(__end_cap() - __first_), 1);
__split_buffer<value_type, __alloc_rr&> __t(__c, (__c + 3) / 4, __alloc());
__t.__construct_at_end(move_iterator<pointer>(__begin_),
move_iterator<pointer>(__end_));
_VSTD::swap(__first_, __t.__first_);
_VSTD::swap(__begin_, __t.__begin_);
_VSTD::swap(__end_, __t.__end_);
_VSTD::swap(__end_cap(), __t.__end_cap());
}
}
__alloc_traits::construct(__alloc(), _VSTD::__to_raw_pointer(__begin_-1), __x);
--__begin_;
}
#ifndef _LIBCPP_CXX03_LANG
template <class _Tp, class _Allocator>
void
__split_buffer<_Tp, _Allocator>::push_front(value_type&& __x)
{
if (__begin_ == __first_)
{
if (__end_ < __end_cap())
{
difference_type __d = __end_cap() - __end_;
__d = (__d + 1) / 2;
__begin_ = _VSTD::move_backward(__begin_, __end_, __end_ + __d);
__end_ += __d;
}
else
{
size_type __c = max<size_type>(2 * static_cast<size_t>(__end_cap() - __first_), 1);
__split_buffer<value_type, __alloc_rr&> __t(__c, (__c + 3) / 4, __alloc());
__t.__construct_at_end(move_iterator<pointer>(__begin_),
move_iterator<pointer>(__end_));
_VSTD::swap(__first_, __t.__first_);
_VSTD::swap(__begin_, __t.__begin_);
_VSTD::swap(__end_, __t.__end_);
_VSTD::swap(__end_cap(), __t.__end_cap());
}
}
__alloc_traits::construct(__alloc(), _VSTD::__to_raw_pointer(__begin_-1),
_VSTD::move(__x));
--__begin_;
}
#endif // _LIBCPP_CXX03_LANG
template <class _Tp, class _Allocator>
inline _LIBCPP_INLINE_VISIBILITY
void
__split_buffer<_Tp, _Allocator>::push_back(const_reference __x)
{
if (__end_ == __end_cap())
{
if (__begin_ > __first_)
{
difference_type __d = __begin_ - __first_;
__d = (__d + 1) / 2;
__end_ = _VSTD::move(__begin_, __end_, __begin_ - __d);
__begin_ -= __d;
}
else
{
size_type __c = max<size_type>(2 * static_cast<size_t>(__end_cap() - __first_), 1);
__split_buffer<value_type, __alloc_rr&> __t(__c, __c / 4, __alloc());
__t.__construct_at_end(move_iterator<pointer>(__begin_),
move_iterator<pointer>(__end_));
_VSTD::swap(__first_, __t.__first_);
_VSTD::swap(__begin_, __t.__begin_);
_VSTD::swap(__end_, __t.__end_);
_VSTD::swap(__end_cap(), __t.__end_cap());
}
}
__alloc_traits::construct(__alloc(), _VSTD::__to_raw_pointer(__end_), __x);
++__end_;
}
#ifndef _LIBCPP_CXX03_LANG
template <class _Tp, class _Allocator>
void
__split_buffer<_Tp, _Allocator>::push_back(value_type&& __x)
{
if (__end_ == __end_cap())
{
if (__begin_ > __first_)
{
difference_type __d = __begin_ - __first_;
__d = (__d + 1) / 2;
__end_ = _VSTD::move(__begin_, __end_, __begin_ - __d);
__begin_ -= __d;
}
else
{
size_type __c = max<size_type>(2 * static_cast<size_t>(__end_cap() - __first_), 1);
__split_buffer<value_type, __alloc_rr&> __t(__c, __c / 4, __alloc());
__t.__construct_at_end(move_iterator<pointer>(__begin_),
move_iterator<pointer>(__end_));
_VSTD::swap(__first_, __t.__first_);
_VSTD::swap(__begin_, __t.__begin_);
_VSTD::swap(__end_, __t.__end_);
_VSTD::swap(__end_cap(), __t.__end_cap());
}
}
__alloc_traits::construct(__alloc(), _VSTD::__to_raw_pointer(__end_),
_VSTD::move(__x));
++__end_;
}
template <class _Tp, class _Allocator>
template <class... _Args>
void
__split_buffer<_Tp, _Allocator>::emplace_back(_Args&&... __args)
{
if (__end_ == __end_cap())
{
if (__begin_ > __first_)
{
difference_type __d = __begin_ - __first_;
__d = (__d + 1) / 2;
__end_ = _VSTD::move(__begin_, __end_, __begin_ - __d);
__begin_ -= __d;
}
else
{
size_type __c = max<size_type>(2 * static_cast<size_t>(__end_cap() - __first_), 1);
__split_buffer<value_type, __alloc_rr&> __t(__c, __c / 4, __alloc());
__t.__construct_at_end(move_iterator<pointer>(__begin_),
move_iterator<pointer>(__end_));
_VSTD::swap(__first_, __t.__first_);
_VSTD::swap(__begin_, __t.__begin_);
_VSTD::swap(__end_, __t.__end_);
_VSTD::swap(__end_cap(), __t.__end_cap());
}
}
__alloc_traits::construct(__alloc(), _VSTD::__to_raw_pointer(__end_),
_VSTD::forward<_Args>(__args)...);
++__end_;
}
#endif // _LIBCPP_CXX03_LANG
template <class _Tp, class _Allocator>
inline _LIBCPP_INLINE_VISIBILITY
void
swap(__split_buffer<_Tp, _Allocator>& __x, __split_buffer<_Tp, _Allocator>& __y)
_NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
{
__x.swap(__y);
}
_LIBCPP_END_NAMESPACE_STD
_LIBCPP_POP_MACROS
#endif // _LIBCPP_SPLIT_BUFFER
| 22,501 | 645 | jart/cosmopolitan | false |
cosmopolitan/third_party/libcxx/thread.cc | // clang-format off
//===------------------------- thread.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/runtime/sysconf.h"
#include "third_party/libcxx/__config"
#ifndef _LIBCPP_HAS_NO_THREADS
#include "third_party/libcxx/thread"
#include "third_party/libcxx/exception"
#include "third_party/libcxx/vector"
#include "third_party/libcxx/future"
#include "third_party/libcxx/limits"
#include "libc/calls/makedev.h"
#include "libc/calls/weirdtypes.h"
#include "libc/intrin/newbie.h"
#include "libc/calls/typedef/u.h"
#include "libc/calls/weirdtypes.h"
#include "libc/sock/select.h"
#include "libc/sysv/consts/endian.h"
#if defined(__unix__) || (defined(__APPLE__) && defined(__MACH__))
#include "libc/intrin/newbie.h"
#include "libc/calls/calls.h"
#include "libc/calls/struct/rlimit.h"
#include "libc/calls/struct/rusage.h"
#include "libc/calls/sysparam.h"
#include "libc/calls/weirdtypes.h"
#include "libc/limits.h"
#include "libc/sysv/consts/endian.h"
#include "libc/sysv/consts/prio.h"
#include "libc/sysv/consts/rlim.h"
#include "libc/sysv/consts/rlimit.h"
#include "libc/sysv/consts/rusage.h"
# if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__DragonFly__) || defined(__APPLE__)
// MISSING #include <sys/sysctl.h>
# endif
#endif // defined(__unix__) || (defined(__APPLE__) && defined(__MACH__))
#if defined(__unix__) || (defined(__APPLE__) && defined(__MACH__)) || defined(__CloudABI__) || defined(__Fuchsia__) || defined(__wasi__)
#include "libc/calls/calls.h"
#include "libc/calls/weirdtypes.h"
#include "libc/runtime/sysconf.h"
#include "libc/sysv/consts/fileno.h"
#include "libc/sysv/consts/o.h"
#include "libc/sysv/consts/ok.h"
#include "third_party/getopt/getopt.h"
#endif // defined(__unix__) || (defined(__APPLE__) && defined(__MACH__)) || defined(__CloudABI__) || defined(__Fuchsia__) || defined(__wasi__)
#if defined(_LIBCPP_WIN32API)
#include "libc/nt/accounting.h"
#include "libc/nt/automation.h"
#include "libc/nt/console.h"
#include "libc/nt/debug.h"
#include "libc/nt/dll.h"
#include "libc/nt/enum/keyaccess.h"
#include "libc/nt/enum/regtype.h"
#include "libc/nt/errors.h"
#include "libc/nt/events.h"
#include "libc/nt/files.h"
#include "libc/nt/ipc.h"
#include "libc/nt/memory.h"
#include "libc/nt/paint.h"
#include "libc/nt/process.h"
#include "libc/nt/registry.h"
#include "libc/nt/synchronization.h"
#include "libc/nt/thread.h"
#include "libc/nt/windows.h"
#include "libc/nt/winsock.h"
#endif
#if defined(__unix__) && !defined(__ANDROID__) && defined(__ELF__) && defined(_LIBCPP_HAS_COMMENT_LIB_PRAGMA)
#pragma comment(lib, "pthread")
#endif
_LIBCPP_BEGIN_NAMESPACE_STD
thread::~thread()
{
if (!__libcpp_thread_isnull(&__t_))
terminate();
}
void
thread::join()
{
int ec = EINVAL;
if (!__libcpp_thread_isnull(&__t_))
{
ec = __libcpp_thread_join(&__t_);
if (ec == 0)
__t_ = _LIBCPP_NULL_THREAD;
}
if (ec)
__throw_system_error(ec, "thread::join failed");
}
void
thread::detach()
{
int ec = EINVAL;
if (!__libcpp_thread_isnull(&__t_))
{
ec = __libcpp_thread_detach(&__t_);
if (ec == 0)
__t_ = _LIBCPP_NULL_THREAD;
}
if (ec)
__throw_system_error(ec, "thread::detach failed");
}
unsigned
thread::hardware_concurrency() _NOEXCEPT
{
#if defined(CTL_HW) && defined(HW_NCPU)
unsigned n;
int mib[2] = {CTL_HW, HW_NCPU};
std::size_t s = sizeof(n);
sysctl(mib, 2, &n, &s, 0, 0);
return n;
#elif defined(_SC_NPROCESSORS_ONLN)
long result = sysconf(_SC_NPROCESSORS_ONLN);
// sysconf returns -1 if the name is invalid, the option does not exist or
// does not have a definite limit.
// if sysconf returns some other negative number, we have no idea
// what is going on. Default to something safe.
if (result < 0)
return 0;
return static_cast<unsigned>(result);
#elif defined(_LIBCPP_WIN32API)
SYSTEM_INFO info;
GetSystemInfo(&info);
return info.dwNumberOfProcessors;
#else // defined(CTL_HW) && defined(HW_NCPU)
// TODO: grovel through /proc or check cpuid on x86 and similar
// instructions on other architectures.
# if defined(_LIBCPP_WARNING)
_LIBCPP_WARNING("hardware_concurrency not yet implemented")
# else
# warning hardware_concurrency not yet implemented
# endif
return 0; // Means not computable [thread.thread.static]
#endif // defined(CTL_HW) && defined(HW_NCPU)
}
namespace this_thread
{
void
sleep_for(const chrono::nanoseconds& ns)
{
if (ns > chrono::nanoseconds::zero())
{
__libcpp_thread_sleep_for(ns);
}
}
} // this_thread
__thread_specific_ptr<__thread_struct>&
__thread_local_data()
{
static __thread_specific_ptr<__thread_struct> __p;
return __p;
}
// __thread_struct_imp
template <class T>
class _LIBCPP_HIDDEN __hidden_allocator
{
public:
typedef T value_type;
T* allocate(size_t __n)
{return static_cast<T*>(::operator new(__n * sizeof(T)));}
void deallocate(T* __p, size_t) {::operator delete(static_cast<void*>(__p));}
size_t max_size() const {return size_t(~0) / sizeof(T);}
};
class _LIBCPP_HIDDEN __thread_struct_imp
{
typedef vector<__assoc_sub_state*,
__hidden_allocator<__assoc_sub_state*> > _AsyncStates;
typedef vector<pair<condition_variable*, mutex*>,
__hidden_allocator<pair<condition_variable*, mutex*> > > _Notify;
_AsyncStates async_states_;
_Notify notify_;
__thread_struct_imp(const __thread_struct_imp&);
__thread_struct_imp& operator=(const __thread_struct_imp&);
public:
__thread_struct_imp() {}
~__thread_struct_imp();
void notify_all_at_thread_exit(condition_variable* cv, mutex* m);
void __make_ready_at_thread_exit(__assoc_sub_state* __s);
};
__thread_struct_imp::~__thread_struct_imp()
{
for (_Notify::iterator i = notify_.begin(), e = notify_.end();
i != e; ++i)
{
i->second->unlock();
i->first->notify_all();
}
for (_AsyncStates::iterator i = async_states_.begin(), e = async_states_.end();
i != e; ++i)
{
(*i)->__make_ready();
(*i)->__release_shared();
}
}
void
__thread_struct_imp::notify_all_at_thread_exit(condition_variable* cv, mutex* m)
{
notify_.push_back(pair<condition_variable*, mutex*>(cv, m));
}
void
__thread_struct_imp::__make_ready_at_thread_exit(__assoc_sub_state* __s)
{
async_states_.push_back(__s);
__s->__add_shared();
}
// __thread_struct
__thread_struct::__thread_struct()
: __p_(new __thread_struct_imp)
{
}
__thread_struct::~__thread_struct()
{
delete __p_;
}
void
__thread_struct::notify_all_at_thread_exit(condition_variable* cv, mutex* m)
{
__p_->notify_all_at_thread_exit(cv, m);
}
void
__thread_struct::__make_ready_at_thread_exit(__assoc_sub_state* __s)
{
__p_->__make_ready_at_thread_exit(__s);
}
_LIBCPP_END_NAMESPACE_STD
#endif // !_LIBCPP_HAS_NO_THREADS
| 7,290 | 265 | jart/cosmopolitan | false |
cosmopolitan/third_party/libcxx/atomic_support.hh | //===----------------------------------------------------------------------===////
//
// 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_load
#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
| 4,883 | 151 | jart/cosmopolitan | false |
cosmopolitan/third_party/libcxx/ccomplex | // -*- C++ -*-
// clang-format off
//===--------------------------- ccomplex ---------------------------------===//
//
// 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_CCOMPLEX
#define _LIBCPP_CCOMPLEX
/*
ccomplex synopsis
#include "third_party/libcxx/complex"
*/
#include "third_party/libcxx/complex"
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
#pragma GCC system_header
#endif
// hh 080623 Created
#endif // _LIBCPP_CCOMPLEX
| 698 | 30 | jart/cosmopolitan | false |
cosmopolitan/third_party/libcxx/config_elast.h | //===----------------------- 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(_LIBCPP_MSVCRT_LIKE)
#include "third_party/libcxx/stdlib.h"
#else
#include "third_party/libcxx/errno.h"
#endif
#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,274 | 42 | jart/cosmopolitan | false |
cosmopolitan/third_party/libcxx/forward_list | // -*- C++ -*-
// clang-format off
//===----------------------- forward_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_FORWARD_LIST
#define _LIBCPP_FORWARD_LIST
/*
forward_list synopsis
namespace std
{
template <class T, class Allocator = allocator<T>>
class forward_list
{
public:
typedef T value_type;
typedef Allocator 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 <details> iterator;
typedef <details> const_iterator;
forward_list()
noexcept(is_nothrow_default_constructible<allocator_type>::value);
explicit forward_list(const allocator_type& a);
explicit forward_list(size_type n);
explicit forward_list(size_type n, const allocator_type& a); // C++14
forward_list(size_type n, const value_type& v);
forward_list(size_type n, const value_type& v, const allocator_type& a);
template <class InputIterator>
forward_list(InputIterator first, InputIterator last);
template <class InputIterator>
forward_list(InputIterator first, InputIterator last, const allocator_type& a);
forward_list(const forward_list& x);
forward_list(const forward_list& x, const allocator_type& a);
forward_list(forward_list&& x)
noexcept(is_nothrow_move_constructible<allocator_type>::value);
forward_list(forward_list&& x, const allocator_type& a);
forward_list(initializer_list<value_type> il);
forward_list(initializer_list<value_type> il, const allocator_type& a);
~forward_list();
forward_list& operator=(const forward_list& x);
forward_list& operator=(forward_list&& x)
noexcept(
allocator_type::propagate_on_container_move_assignment::value &&
is_nothrow_move_assignable<allocator_type>::value);
forward_list& operator=(initializer_list<value_type> il);
template <class InputIterator>
void assign(InputIterator first, InputIterator last);
void assign(size_type n, const value_type& v);
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;
const_iterator cbegin() const noexcept;
const_iterator cend() const noexcept;
iterator before_begin() noexcept;
const_iterator before_begin() const noexcept;
const_iterator cbefore_begin() const noexcept;
bool empty() const noexcept;
size_type max_size() const noexcept;
reference front();
const_reference front() const;
template <class... Args> reference emplace_front(Args&&... args); // reference in C++17
void push_front(const value_type& v);
void push_front(value_type&& v);
void pop_front();
template <class... Args>
iterator emplace_after(const_iterator p, Args&&... args);
iterator insert_after(const_iterator p, const value_type& v);
iterator insert_after(const_iterator p, value_type&& v);
iterator insert_after(const_iterator p, size_type n, const value_type& v);
template <class InputIterator>
iterator insert_after(const_iterator p,
InputIterator first, InputIterator last);
iterator insert_after(const_iterator p, initializer_list<value_type> il);
iterator erase_after(const_iterator p);
iterator erase_after(const_iterator first, const_iterator last);
void swap(forward_list& x)
noexcept(allocator_traits<allocator_type>::is_always_equal::value); // C++17
void resize(size_type n);
void resize(size_type n, const value_type& v);
void clear() noexcept;
void splice_after(const_iterator p, forward_list& x);
void splice_after(const_iterator p, forward_list&& x);
void splice_after(const_iterator p, forward_list& x, const_iterator i);
void splice_after(const_iterator p, forward_list&& x, const_iterator i);
void splice_after(const_iterator p, forward_list& x,
const_iterator first, const_iterator last);
void splice_after(const_iterator p, forward_list&& x,
const_iterator first, const_iterator last);
size_type remove(const value_type& v); // void before C++20
template <class Predicate>
size_type remove_if(Predicate 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(forward_list& x);
void merge(forward_list&& x);
template <class Compare> void merge(forward_list& x, Compare comp);
template <class Compare> void merge(forward_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>>
forward_list(InputIterator, InputIterator, Allocator = Allocator())
-> forward_list<typename iterator_traits<InputIterator>::value_type, Allocator>; // C++17
template <class T, class Allocator>
bool operator==(const forward_list<T, Allocator>& x,
const forward_list<T, Allocator>& y);
template <class T, class Allocator>
bool operator< (const forward_list<T, Allocator>& x,
const forward_list<T, Allocator>& y);
template <class T, class Allocator>
bool operator!=(const forward_list<T, Allocator>& x,
const forward_list<T, Allocator>& y);
template <class T, class Allocator>
bool operator> (const forward_list<T, Allocator>& x,
const forward_list<T, Allocator>& y);
template <class T, class Allocator>
bool operator>=(const forward_list<T, Allocator>& x,
const forward_list<T, Allocator>& y);
template <class T, class Allocator>
bool operator<=(const forward_list<T, Allocator>& x,
const forward_list<T, Allocator>& y);
template <class T, class Allocator>
void swap(forward_list<T, Allocator>& x, forward_list<T, Allocator>& y)
noexcept(noexcept(x.swap(y)));
template <class T, class Allocator, class U>
void erase(forward_list<T, Allocator>& c, const U& value); // C++20
template <class T, class Allocator, class Predicate>
void erase_if(forward_list<T, Allocator>& c, Predicate pred); // C++20
} // std
*/
#include "third_party/libcxx/__config"
#include "third_party/libcxx/initializer_list"
#include "third_party/libcxx/memory"
#include "third_party/libcxx/limits"
#include "third_party/libcxx/iterator"
#include "third_party/libcxx/algorithm"
#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
template <class _Tp, class _VoidPtr> struct __forward_list_node;
template <class _NodePtr> struct __forward_begin_node;
template <class>
struct __forward_list_node_value_type;
template <class _Tp, class _VoidPtr>
struct __forward_list_node_value_type<__forward_list_node<_Tp, _VoidPtr> > {
typedef _Tp type;
};
template <class _NodePtr>
struct __forward_node_traits {
typedef typename remove_cv<
typename pointer_traits<_NodePtr>::element_type>::type __node;
typedef typename __forward_list_node_value_type<__node>::type __node_value_type;
typedef _NodePtr __node_pointer;
typedef __forward_begin_node<_NodePtr> __begin_node;
typedef typename __rebind_pointer<_NodePtr, __begin_node>::type
__begin_node_pointer;
typedef typename __rebind_pointer<_NodePtr, void>::type __void_pointer;
#if defined(_LIBCPP_ABI_FORWARD_LIST_REMOVE_NODE_POINTER_UB)
typedef __begin_node_pointer __iter_node_pointer;
#else
typedef typename conditional<
is_pointer<__void_pointer>::value,
__begin_node_pointer,
__node_pointer
>::type __iter_node_pointer;
#endif
typedef typename conditional<
is_same<__iter_node_pointer, __node_pointer>::value,
__begin_node_pointer,
__node_pointer
>::type __non_iter_node_pointer;
_LIBCPP_INLINE_VISIBILITY
static __iter_node_pointer __as_iter_node(__iter_node_pointer __p) {
return __p;
}
_LIBCPP_INLINE_VISIBILITY
static __iter_node_pointer __as_iter_node(__non_iter_node_pointer __p) {
return static_cast<__iter_node_pointer>(static_cast<__void_pointer>(__p));
}
};
template <class _NodePtr>
struct __forward_begin_node
{
typedef _NodePtr pointer;
typedef typename __rebind_pointer<_NodePtr, __forward_begin_node>::type __begin_node_pointer;
pointer __next_;
_LIBCPP_INLINE_VISIBILITY __forward_begin_node() : __next_(nullptr) {}
_LIBCPP_INLINE_VISIBILITY
__begin_node_pointer __next_as_begin() const {
return static_cast<__begin_node_pointer>(__next_);
}
};
template <class _Tp, class _VoidPtr>
struct _LIBCPP_HIDDEN __begin_node_of
{
typedef __forward_begin_node<
typename __rebind_pointer<_VoidPtr, __forward_list_node<_Tp, _VoidPtr> >::type
> type;
};
template <class _Tp, class _VoidPtr>
struct __forward_list_node
: public __begin_node_of<_Tp, _VoidPtr>::type
{
typedef _Tp value_type;
value_type __value_;
};
template <class _Tp, class _Alloc = allocator<_Tp> > class _LIBCPP_TEMPLATE_VIS forward_list;
template<class _NodeConstPtr> class _LIBCPP_TEMPLATE_VIS __forward_list_const_iterator;
template <class _NodePtr>
class _LIBCPP_TEMPLATE_VIS __forward_list_iterator
{
typedef __forward_node_traits<_NodePtr> __traits;
typedef typename __traits::__node_pointer __node_pointer;
typedef typename __traits::__begin_node_pointer __begin_node_pointer;
typedef typename __traits::__iter_node_pointer __iter_node_pointer;
typedef typename __traits::__void_pointer __void_pointer;
__iter_node_pointer __ptr_;
_LIBCPP_INLINE_VISIBILITY
__begin_node_pointer __get_begin() const {
return static_cast<__begin_node_pointer>(
static_cast<__void_pointer>(__ptr_));
}
_LIBCPP_INLINE_VISIBILITY
__node_pointer __get_unsafe_node_pointer() const {
return static_cast<__node_pointer>(
static_cast<__void_pointer>(__ptr_));
}
_LIBCPP_INLINE_VISIBILITY
explicit __forward_list_iterator(nullptr_t) _NOEXCEPT : __ptr_(nullptr) {}
_LIBCPP_INLINE_VISIBILITY
explicit __forward_list_iterator(__begin_node_pointer __p) _NOEXCEPT
: __ptr_(__traits::__as_iter_node(__p)) {}
_LIBCPP_INLINE_VISIBILITY
explicit __forward_list_iterator(__node_pointer __p) _NOEXCEPT
: __ptr_(__traits::__as_iter_node(__p)) {}
template<class, class> friend class _LIBCPP_TEMPLATE_VIS forward_list;
template<class> friend class _LIBCPP_TEMPLATE_VIS __forward_list_const_iterator;
public:
typedef forward_iterator_tag iterator_category;
typedef typename __traits::__node_value_type value_type;
typedef value_type& reference;
typedef typename pointer_traits<__node_pointer>::difference_type
difference_type;
typedef typename __rebind_pointer<__node_pointer, value_type>::type pointer;
_LIBCPP_INLINE_VISIBILITY
__forward_list_iterator() _NOEXCEPT : __ptr_(nullptr) {}
_LIBCPP_INLINE_VISIBILITY
reference operator*() const {return __get_unsafe_node_pointer()->__value_;}
_LIBCPP_INLINE_VISIBILITY
pointer operator->() const {
return pointer_traits<pointer>::pointer_to(__get_unsafe_node_pointer()->__value_);
}
_LIBCPP_INLINE_VISIBILITY
__forward_list_iterator& operator++()
{
__ptr_ = __traits::__as_iter_node(__ptr_->__next_);
return *this;
}
_LIBCPP_INLINE_VISIBILITY
__forward_list_iterator operator++(int)
{
__forward_list_iterator __t(*this);
++(*this);
return __t;
}
friend _LIBCPP_INLINE_VISIBILITY
bool operator==(const __forward_list_iterator& __x,
const __forward_list_iterator& __y)
{return __x.__ptr_ == __y.__ptr_;}
friend _LIBCPP_INLINE_VISIBILITY
bool operator!=(const __forward_list_iterator& __x,
const __forward_list_iterator& __y)
{return !(__x == __y);}
};
template <class _NodeConstPtr>
class _LIBCPP_TEMPLATE_VIS __forward_list_const_iterator
{
static_assert((!is_const<typename pointer_traits<_NodeConstPtr>::element_type>::value), "");
typedef _NodeConstPtr _NodePtr;
typedef __forward_node_traits<_NodePtr> __traits;
typedef typename __traits::__node __node;
typedef typename __traits::__node_pointer __node_pointer;
typedef typename __traits::__begin_node_pointer __begin_node_pointer;
typedef typename __traits::__iter_node_pointer __iter_node_pointer;
typedef typename __traits::__void_pointer __void_pointer;
__iter_node_pointer __ptr_;
__begin_node_pointer __get_begin() const {
return static_cast<__begin_node_pointer>(
static_cast<__void_pointer>(__ptr_));
}
__node_pointer __get_unsafe_node_pointer() const {
return static_cast<__node_pointer>(
static_cast<__void_pointer>(__ptr_));
}
_LIBCPP_INLINE_VISIBILITY
explicit __forward_list_const_iterator(nullptr_t) _NOEXCEPT
: __ptr_(nullptr) {}
_LIBCPP_INLINE_VISIBILITY
explicit __forward_list_const_iterator(__begin_node_pointer __p) _NOEXCEPT
: __ptr_(__traits::__as_iter_node(__p)) {}
_LIBCPP_INLINE_VISIBILITY
explicit __forward_list_const_iterator(__node_pointer __p) _NOEXCEPT
: __ptr_(__traits::__as_iter_node(__p)) {}
template<class, class> friend class forward_list;
public:
typedef forward_iterator_tag iterator_category;
typedef typename __traits::__node_value_type value_type;
typedef const value_type& reference;
typedef typename pointer_traits<__node_pointer>::difference_type
difference_type;
typedef typename __rebind_pointer<__node_pointer, const value_type>::type
pointer;
_LIBCPP_INLINE_VISIBILITY
__forward_list_const_iterator() _NOEXCEPT : __ptr_(nullptr) {}
_LIBCPP_INLINE_VISIBILITY
__forward_list_const_iterator(__forward_list_iterator<__node_pointer> __p) _NOEXCEPT
: __ptr_(__p.__ptr_) {}
_LIBCPP_INLINE_VISIBILITY
reference operator*() const {return __get_unsafe_node_pointer()->__value_;}
_LIBCPP_INLINE_VISIBILITY
pointer operator->() const {return pointer_traits<pointer>::pointer_to(
__get_unsafe_node_pointer()->__value_);}
_LIBCPP_INLINE_VISIBILITY
__forward_list_const_iterator& operator++()
{
__ptr_ = __traits::__as_iter_node(__ptr_->__next_);
return *this;
}
_LIBCPP_INLINE_VISIBILITY
__forward_list_const_iterator operator++(int)
{
__forward_list_const_iterator __t(*this);
++(*this);
return __t;
}
friend _LIBCPP_INLINE_VISIBILITY
bool operator==(const __forward_list_const_iterator& __x,
const __forward_list_const_iterator& __y)
{return __x.__ptr_ == __y.__ptr_;}
friend _LIBCPP_INLINE_VISIBILITY
bool operator!=(const __forward_list_const_iterator& __x,
const __forward_list_const_iterator& __y)
{return !(__x == __y);}
};
template <class _Tp, class _Alloc>
class __forward_list_base
{
protected:
typedef _Tp value_type;
typedef _Alloc allocator_type;
typedef typename allocator_traits<allocator_type>::void_pointer void_pointer;
typedef __forward_list_node<value_type, void_pointer> __node;
typedef typename __begin_node_of<value_type, void_pointer>::type __begin_node;
typedef typename __rebind_alloc_helper<allocator_traits<allocator_type>, __node>::type __node_allocator;
typedef allocator_traits<__node_allocator> __node_traits;
typedef typename __node_traits::pointer __node_pointer;
typedef typename __rebind_alloc_helper<
allocator_traits<allocator_type>, __begin_node
>::type __begin_node_allocator;
typedef typename allocator_traits<__begin_node_allocator>::pointer
__begin_node_pointer;
static_assert((!is_same<allocator_type, __node_allocator>::value),
"internal allocator type must differ from user-specified "
"type; otherwise overload resolution breaks");
__compressed_pair<__begin_node, __node_allocator> __before_begin_;
_LIBCPP_INLINE_VISIBILITY
__begin_node_pointer __before_begin() _NOEXCEPT
{return pointer_traits<__begin_node_pointer>::pointer_to(__before_begin_.first());}
_LIBCPP_INLINE_VISIBILITY
__begin_node_pointer __before_begin() const _NOEXCEPT
{return pointer_traits<__begin_node_pointer>::pointer_to(const_cast<__begin_node&>(__before_begin_.first()));}
_LIBCPP_INLINE_VISIBILITY
__node_allocator& __alloc() _NOEXCEPT
{return __before_begin_.second();}
_LIBCPP_INLINE_VISIBILITY
const __node_allocator& __alloc() const _NOEXCEPT
{return __before_begin_.second();}
typedef __forward_list_iterator<__node_pointer> iterator;
typedef __forward_list_const_iterator<__node_pointer> const_iterator;
_LIBCPP_INLINE_VISIBILITY
__forward_list_base()
_NOEXCEPT_(is_nothrow_default_constructible<__node_allocator>::value)
: __before_begin_(__begin_node()) {}
_LIBCPP_INLINE_VISIBILITY
explicit __forward_list_base(const allocator_type& __a)
: __before_begin_(__begin_node(), __node_allocator(__a)) {}
_LIBCPP_INLINE_VISIBILITY
explicit __forward_list_base(const __node_allocator& __a)
: __before_begin_(__begin_node(), __a) {}
#ifndef _LIBCPP_CXX03_LANG
public:
_LIBCPP_INLINE_VISIBILITY
__forward_list_base(__forward_list_base&& __x)
_NOEXCEPT_(is_nothrow_move_constructible<__node_allocator>::value);
_LIBCPP_INLINE_VISIBILITY
__forward_list_base(__forward_list_base&& __x, const allocator_type& __a);
#endif // _LIBCPP_CXX03_LANG
private:
__forward_list_base(const __forward_list_base&);
__forward_list_base& operator=(const __forward_list_base&);
public:
~__forward_list_base();
protected:
_LIBCPP_INLINE_VISIBILITY
void __copy_assign_alloc(const __forward_list_base& __x)
{__copy_assign_alloc(__x, integral_constant<bool,
__node_traits::propagate_on_container_copy_assignment::value>());}
_LIBCPP_INLINE_VISIBILITY
void __move_assign_alloc(__forward_list_base& __x)
_NOEXCEPT_(!__node_traits::propagate_on_container_move_assignment::value ||
is_nothrow_move_assignable<__node_allocator>::value)
{__move_assign_alloc(__x, integral_constant<bool,
__node_traits::propagate_on_container_move_assignment::value>());}
public:
_LIBCPP_INLINE_VISIBILITY
void swap(__forward_list_base& __x)
#if _LIBCPP_STD_VER >= 14
_NOEXCEPT;
#else
_NOEXCEPT_(!__node_traits::propagate_on_container_move_assignment::value ||
__is_nothrow_swappable<__node_allocator>::value);
#endif
protected:
void clear() _NOEXCEPT;
private:
_LIBCPP_INLINE_VISIBILITY
void __copy_assign_alloc(const __forward_list_base&, false_type) {}
_LIBCPP_INLINE_VISIBILITY
void __copy_assign_alloc(const __forward_list_base& __x, true_type)
{
if (__alloc() != __x.__alloc())
clear();
__alloc() = __x.__alloc();
}
_LIBCPP_INLINE_VISIBILITY
void __move_assign_alloc(__forward_list_base&, false_type) _NOEXCEPT
{}
_LIBCPP_INLINE_VISIBILITY
void __move_assign_alloc(__forward_list_base& __x, true_type)
_NOEXCEPT_(is_nothrow_move_assignable<__node_allocator>::value)
{__alloc() = _VSTD::move(__x.__alloc());}
};
#ifndef _LIBCPP_CXX03_LANG
template <class _Tp, class _Alloc>
inline
__forward_list_base<_Tp, _Alloc>::__forward_list_base(__forward_list_base&& __x)
_NOEXCEPT_(is_nothrow_move_constructible<__node_allocator>::value)
: __before_begin_(_VSTD::move(__x.__before_begin_))
{
__x.__before_begin()->__next_ = nullptr;
}
template <class _Tp, class _Alloc>
inline
__forward_list_base<_Tp, _Alloc>::__forward_list_base(__forward_list_base&& __x,
const allocator_type& __a)
: __before_begin_(__begin_node(), __node_allocator(__a))
{
if (__alloc() == __x.__alloc())
{
__before_begin()->__next_ = __x.__before_begin()->__next_;
__x.__before_begin()->__next_ = nullptr;
}
}
#endif // _LIBCPP_CXX03_LANG
template <class _Tp, class _Alloc>
__forward_list_base<_Tp, _Alloc>::~__forward_list_base()
{
clear();
}
template <class _Tp, class _Alloc>
inline
void
__forward_list_base<_Tp, _Alloc>::swap(__forward_list_base& __x)
#if _LIBCPP_STD_VER >= 14
_NOEXCEPT
#else
_NOEXCEPT_(!__node_traits::propagate_on_container_move_assignment::value ||
__is_nothrow_swappable<__node_allocator>::value)
#endif
{
__swap_allocator(__alloc(), __x.__alloc(),
integral_constant<bool, __node_traits::propagate_on_container_swap::value>());
using _VSTD::swap;
swap(__before_begin()->__next_, __x.__before_begin()->__next_);
}
template <class _Tp, class _Alloc>
void
__forward_list_base<_Tp, _Alloc>::clear() _NOEXCEPT
{
__node_allocator& __a = __alloc();
for (__node_pointer __p = __before_begin()->__next_; __p != nullptr;)
{
__node_pointer __next = __p->__next_;
__node_traits::destroy(__a, _VSTD::addressof(__p->__value_));
__node_traits::deallocate(__a, __p, 1);
__p = __next;
}
__before_begin()->__next_ = nullptr;
}
template <class _Tp, class _Alloc /*= allocator<_Tp>*/>
class _LIBCPP_TEMPLATE_VIS forward_list
: private __forward_list_base<_Tp, _Alloc>
{
typedef __forward_list_base<_Tp, _Alloc> base;
typedef typename base::__node_allocator __node_allocator;
typedef typename base::__node __node;
typedef typename base::__node_traits __node_traits;
typedef typename base::__node_pointer __node_pointer;
typedef typename base::__begin_node_pointer __begin_node_pointer;
public:
typedef _Tp value_type;
typedef _Alloc allocator_type;
static_assert((is_same<typename allocator_type::value_type, value_type>::value),
"Allocator::value_type must be same type as value_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 typename base::iterator iterator;
typedef typename base::const_iterator const_iterator;
#if _LIBCPP_STD_VER > 17
typedef size_type __remove_return_type;
#else
typedef void __remove_return_type;
#endif
_LIBCPP_INLINE_VISIBILITY
forward_list()
_NOEXCEPT_(is_nothrow_default_constructible<__node_allocator>::value)
{} // = default;
_LIBCPP_INLINE_VISIBILITY
explicit forward_list(const allocator_type& __a);
explicit forward_list(size_type __n);
#if _LIBCPP_STD_VER > 11
explicit forward_list(size_type __n, const allocator_type& __a);
#endif
forward_list(size_type __n, const value_type& __v);
forward_list(size_type __n, const value_type& __v, const allocator_type& __a);
template <class _InputIterator>
forward_list(_InputIterator __f, _InputIterator __l,
typename enable_if<
__is_input_iterator<_InputIterator>::value
>::type* = nullptr);
template <class _InputIterator>
forward_list(_InputIterator __f, _InputIterator __l,
const allocator_type& __a,
typename enable_if<
__is_input_iterator<_InputIterator>::value
>::type* = nullptr);
forward_list(const forward_list& __x);
forward_list(const forward_list& __x, const allocator_type& __a);
forward_list& operator=(const forward_list& __x);
#ifndef _LIBCPP_CXX03_LANG
_LIBCPP_INLINE_VISIBILITY
forward_list(forward_list&& __x)
_NOEXCEPT_(is_nothrow_move_constructible<base>::value)
: base(_VSTD::move(__x)) {}
forward_list(forward_list&& __x, const allocator_type& __a);
forward_list(initializer_list<value_type> __il);
forward_list(initializer_list<value_type> __il, const allocator_type& __a);
_LIBCPP_INLINE_VISIBILITY
forward_list& operator=(forward_list&& __x)
_NOEXCEPT_(
__node_traits::propagate_on_container_move_assignment::value &&
is_nothrow_move_assignable<allocator_type>::value);
_LIBCPP_INLINE_VISIBILITY
forward_list& operator=(initializer_list<value_type> __il);
_LIBCPP_INLINE_VISIBILITY
void assign(initializer_list<value_type> __il);
#endif // _LIBCPP_CXX03_LANG
// ~forward_list() = default;
template <class _InputIterator>
typename enable_if
<
__is_input_iterator<_InputIterator>::value,
void
>::type
assign(_InputIterator __f, _InputIterator __l);
void assign(size_type __n, const value_type& __v);
_LIBCPP_INLINE_VISIBILITY
allocator_type get_allocator() const _NOEXCEPT
{return allocator_type(base::__alloc());}
_LIBCPP_INLINE_VISIBILITY
iterator begin() _NOEXCEPT
{return iterator(base::__before_begin()->__next_);}
_LIBCPP_INLINE_VISIBILITY
const_iterator begin() const _NOEXCEPT
{return const_iterator(base::__before_begin()->__next_);}
_LIBCPP_INLINE_VISIBILITY
iterator end() _NOEXCEPT
{return iterator(nullptr);}
_LIBCPP_INLINE_VISIBILITY
const_iterator end() const _NOEXCEPT
{return const_iterator(nullptr);}
_LIBCPP_INLINE_VISIBILITY
const_iterator cbegin() const _NOEXCEPT
{return const_iterator(base::__before_begin()->__next_);}
_LIBCPP_INLINE_VISIBILITY
const_iterator cend() const _NOEXCEPT
{return const_iterator(nullptr);}
_LIBCPP_INLINE_VISIBILITY
iterator before_begin() _NOEXCEPT
{return iterator(base::__before_begin());}
_LIBCPP_INLINE_VISIBILITY
const_iterator before_begin() const _NOEXCEPT
{return const_iterator(base::__before_begin());}
_LIBCPP_INLINE_VISIBILITY
const_iterator cbefore_begin() const _NOEXCEPT
{return const_iterator(base::__before_begin());}
_LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
bool empty() const _NOEXCEPT
{return base::__before_begin()->__next_ == nullptr;}
_LIBCPP_INLINE_VISIBILITY
size_type max_size() const _NOEXCEPT {
return std::min<size_type>(
__node_traits::max_size(base::__alloc()),
numeric_limits<difference_type>::max());
}
_LIBCPP_INLINE_VISIBILITY
reference front() {return base::__before_begin()->__next_->__value_;}
_LIBCPP_INLINE_VISIBILITY
const_reference front() const {return base::__before_begin()->__next_->__value_;}
#ifndef _LIBCPP_CXX03_LANG
#if _LIBCPP_STD_VER > 14
template <class... _Args> reference emplace_front(_Args&&... __args);
#else
template <class... _Args> void emplace_front(_Args&&... __args);
#endif
void push_front(value_type&& __v);
#endif // _LIBCPP_CXX03_LANG
void push_front(const value_type& __v);
void pop_front();
#ifndef _LIBCPP_CXX03_LANG
template <class... _Args>
iterator emplace_after(const_iterator __p, _Args&&... __args);
iterator insert_after(const_iterator __p, value_type&& __v);
iterator insert_after(const_iterator __p, initializer_list<value_type> __il)
{return insert_after(__p, __il.begin(), __il.end());}
#endif // _LIBCPP_CXX03_LANG
iterator insert_after(const_iterator __p, const value_type& __v);
iterator insert_after(const_iterator __p, size_type __n, const value_type& __v);
template <class _InputIterator>
_LIBCPP_INLINE_VISIBILITY
typename enable_if
<
__is_input_iterator<_InputIterator>::value,
iterator
>::type
insert_after(const_iterator __p, _InputIterator __f, _InputIterator __l);
iterator erase_after(const_iterator __p);
iterator erase_after(const_iterator __f, const_iterator __l);
_LIBCPP_INLINE_VISIBILITY
void swap(forward_list& __x)
#if _LIBCPP_STD_VER >= 14
_NOEXCEPT
#else
_NOEXCEPT_(!__node_traits::propagate_on_container_swap::value ||
__is_nothrow_swappable<__node_allocator>::value)
#endif
{base::swap(__x);}
void resize(size_type __n);
void resize(size_type __n, const value_type& __v);
_LIBCPP_INLINE_VISIBILITY
void clear() _NOEXCEPT {base::clear();}
_LIBCPP_INLINE_VISIBILITY
void splice_after(const_iterator __p, forward_list&& __x);
_LIBCPP_INLINE_VISIBILITY
void splice_after(const_iterator __p, forward_list&& __x, const_iterator __i);
_LIBCPP_INLINE_VISIBILITY
void splice_after(const_iterator __p, forward_list&& __x,
const_iterator __f, const_iterator __l);
void splice_after(const_iterator __p, forward_list& __x);
void splice_after(const_iterator __p, forward_list& __x, const_iterator __i);
void splice_after(const_iterator __p, forward_list& __x,
const_iterator __f, const_iterator __l);
__remove_return_type remove(const value_type& __v);
template <class _Predicate> __remove_return_type remove_if(_Predicate __pred);
_LIBCPP_INLINE_VISIBILITY
__remove_return_type unique() {return unique(__equal_to<value_type>());}
template <class _BinaryPredicate> __remove_return_type unique(_BinaryPredicate __binary_pred);
#ifndef _LIBCPP_CXX03_LANG
_LIBCPP_INLINE_VISIBILITY
void merge(forward_list&& __x) {merge(__x, __less<value_type>());}
template <class _Compare>
_LIBCPP_INLINE_VISIBILITY
void merge(forward_list&& __x, _Compare __comp)
{merge(__x, _VSTD::move(__comp));}
#endif // _LIBCPP_CXX03_LANG
_LIBCPP_INLINE_VISIBILITY
void merge(forward_list& __x) {merge(__x, __less<value_type>());}
template <class _Compare> void merge(forward_list& __x, _Compare __comp);
_LIBCPP_INLINE_VISIBILITY
void sort() {sort(__less<value_type>());}
template <class _Compare> _LIBCPP_INLINE_VISIBILITY void sort(_Compare __comp);
void reverse() _NOEXCEPT;
private:
#ifndef _LIBCPP_CXX03_LANG
void __move_assign(forward_list& __x, true_type)
_NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value);
void __move_assign(forward_list& __x, false_type);
#endif // _LIBCPP_CXX03_LANG
template <class _Compare>
static
__node_pointer
__merge(__node_pointer __f1, __node_pointer __f2, _Compare& __comp);
template <class _Compare>
static
__node_pointer
__sort(__node_pointer __f, difference_type __sz, _Compare& __comp);
};
#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
>
forward_list(_InputIterator, _InputIterator)
-> forward_list<typename iterator_traits<_InputIterator>::value_type, _Alloc>;
template<class _InputIterator,
class _Alloc,
class = typename enable_if<__is_allocator<_Alloc>::value, void>::type
>
forward_list(_InputIterator, _InputIterator, _Alloc)
-> forward_list<typename iterator_traits<_InputIterator>::value_type, _Alloc>;
#endif
template <class _Tp, class _Alloc>
inline
forward_list<_Tp, _Alloc>::forward_list(const allocator_type& __a)
: base(__a)
{
}
template <class _Tp, class _Alloc>
forward_list<_Tp, _Alloc>::forward_list(size_type __n)
{
if (__n > 0)
{
__node_allocator& __a = base::__alloc();
typedef __allocator_destructor<__node_allocator> _Dp;
unique_ptr<__node, _Dp> __h(nullptr, _Dp(__a, 1));
for (__begin_node_pointer __p = base::__before_begin(); __n > 0; --__n,
__p = __p->__next_as_begin())
{
__h.reset(__node_traits::allocate(__a, 1));
__node_traits::construct(__a, _VSTD::addressof(__h->__value_));
__h->__next_ = nullptr;
__p->__next_ = __h.release();
}
}
}
#if _LIBCPP_STD_VER > 11
template <class _Tp, class _Alloc>
forward_list<_Tp, _Alloc>::forward_list(size_type __n,
const allocator_type& __base_alloc)
: base ( __base_alloc )
{
if (__n > 0)
{
__node_allocator& __a = base::__alloc();
typedef __allocator_destructor<__node_allocator> _Dp;
unique_ptr<__node, _Dp> __h(nullptr, _Dp(__a, 1));
for (__begin_node_pointer __p = base::__before_begin(); __n > 0; --__n,
__p = __p->__next_as_begin())
{
__h.reset(__node_traits::allocate(__a, 1));
__node_traits::construct(__a, _VSTD::addressof(__h->__value_));
__h->__next_ = nullptr;
__p->__next_ = __h.release();
}
}
}
#endif
template <class _Tp, class _Alloc>
forward_list<_Tp, _Alloc>::forward_list(size_type __n, const value_type& __v)
{
insert_after(cbefore_begin(), __n, __v);
}
template <class _Tp, class _Alloc>
forward_list<_Tp, _Alloc>::forward_list(size_type __n, const value_type& __v,
const allocator_type& __a)
: base(__a)
{
insert_after(cbefore_begin(), __n, __v);
}
template <class _Tp, class _Alloc>
template <class _InputIterator>
forward_list<_Tp, _Alloc>::forward_list(_InputIterator __f, _InputIterator __l,
typename enable_if<
__is_input_iterator<_InputIterator>::value
>::type*)
{
insert_after(cbefore_begin(), __f, __l);
}
template <class _Tp, class _Alloc>
template <class _InputIterator>
forward_list<_Tp, _Alloc>::forward_list(_InputIterator __f, _InputIterator __l,
const allocator_type& __a,
typename enable_if<
__is_input_iterator<_InputIterator>::value
>::type*)
: base(__a)
{
insert_after(cbefore_begin(), __f, __l);
}
template <class _Tp, class _Alloc>
forward_list<_Tp, _Alloc>::forward_list(const forward_list& __x)
: base(
__node_traits::select_on_container_copy_construction(__x.__alloc())) {
insert_after(cbefore_begin(), __x.begin(), __x.end());
}
template <class _Tp, class _Alloc>
forward_list<_Tp, _Alloc>::forward_list(const forward_list& __x,
const allocator_type& __a)
: base(__a)
{
insert_after(cbefore_begin(), __x.begin(), __x.end());
}
template <class _Tp, class _Alloc>
forward_list<_Tp, _Alloc>&
forward_list<_Tp, _Alloc>::operator=(const forward_list& __x)
{
if (this != &__x)
{
base::__copy_assign_alloc(__x);
assign(__x.begin(), __x.end());
}
return *this;
}
#ifndef _LIBCPP_CXX03_LANG
template <class _Tp, class _Alloc>
forward_list<_Tp, _Alloc>::forward_list(forward_list&& __x,
const allocator_type& __a)
: base(_VSTD::move(__x), __a)
{
if (base::__alloc() != __x.__alloc())
{
typedef move_iterator<iterator> _Ip;
insert_after(cbefore_begin(), _Ip(__x.begin()), _Ip(__x.end()));
}
}
template <class _Tp, class _Alloc>
forward_list<_Tp, _Alloc>::forward_list(initializer_list<value_type> __il)
{
insert_after(cbefore_begin(), __il.begin(), __il.end());
}
template <class _Tp, class _Alloc>
forward_list<_Tp, _Alloc>::forward_list(initializer_list<value_type> __il,
const allocator_type& __a)
: base(__a)
{
insert_after(cbefore_begin(), __il.begin(), __il.end());
}
template <class _Tp, class _Alloc>
void
forward_list<_Tp, _Alloc>::__move_assign(forward_list& __x, true_type)
_NOEXCEPT_(is_nothrow_move_assignable<allocator_type>::value)
{
clear();
base::__move_assign_alloc(__x);
base::__before_begin()->__next_ = __x.__before_begin()->__next_;
__x.__before_begin()->__next_ = nullptr;
}
template <class _Tp, class _Alloc>
void
forward_list<_Tp, _Alloc>::__move_assign(forward_list& __x, false_type)
{
if (base::__alloc() == __x.__alloc())
__move_assign(__x, true_type());
else
{
typedef move_iterator<iterator> _Ip;
assign(_Ip(__x.begin()), _Ip(__x.end()));
}
}
template <class _Tp, class _Alloc>
inline
forward_list<_Tp, _Alloc>&
forward_list<_Tp, _Alloc>::operator=(forward_list&& __x)
_NOEXCEPT_(
__node_traits::propagate_on_container_move_assignment::value &&
is_nothrow_move_assignable<allocator_type>::value)
{
__move_assign(__x, integral_constant<bool,
__node_traits::propagate_on_container_move_assignment::value>());
return *this;
}
template <class _Tp, class _Alloc>
inline
forward_list<_Tp, _Alloc>&
forward_list<_Tp, _Alloc>::operator=(initializer_list<value_type> __il)
{
assign(__il.begin(), __il.end());
return *this;
}
#endif // _LIBCPP_CXX03_LANG
template <class _Tp, class _Alloc>
template <class _InputIterator>
typename enable_if
<
__is_input_iterator<_InputIterator>::value,
void
>::type
forward_list<_Tp, _Alloc>::assign(_InputIterator __f, _InputIterator __l)
{
iterator __i = before_begin();
iterator __j = _VSTD::next(__i);
iterator __e = end();
for (; __j != __e && __f != __l; ++__i, (void) ++__j, ++__f)
*__j = *__f;
if (__j == __e)
insert_after(__i, __f, __l);
else
erase_after(__i, __e);
}
template <class _Tp, class _Alloc>
void
forward_list<_Tp, _Alloc>::assign(size_type __n, const value_type& __v)
{
iterator __i = before_begin();
iterator __j = _VSTD::next(__i);
iterator __e = end();
for (; __j != __e && __n > 0; --__n, ++__i, ++__j)
*__j = __v;
if (__j == __e)
insert_after(__i, __n, __v);
else
erase_after(__i, __e);
}
#ifndef _LIBCPP_CXX03_LANG
template <class _Tp, class _Alloc>
inline
void
forward_list<_Tp, _Alloc>::assign(initializer_list<value_type> __il)
{
assign(__il.begin(), __il.end());
}
template <class _Tp, class _Alloc>
template <class... _Args>
#if _LIBCPP_STD_VER > 14
typename forward_list<_Tp, _Alloc>::reference
#else
void
#endif
forward_list<_Tp, _Alloc>::emplace_front(_Args&&... __args)
{
__node_allocator& __a = base::__alloc();
typedef __allocator_destructor<__node_allocator> _Dp;
unique_ptr<__node, _Dp> __h(__node_traits::allocate(__a, 1), _Dp(__a, 1));
__node_traits::construct(__a, _VSTD::addressof(__h->__value_),
_VSTD::forward<_Args>(__args)...);
__h->__next_ = base::__before_begin()->__next_;
base::__before_begin()->__next_ = __h.release();
#if _LIBCPP_STD_VER > 14
return base::__before_begin()->__next_->__value_;
#endif
}
template <class _Tp, class _Alloc>
void
forward_list<_Tp, _Alloc>::push_front(value_type&& __v)
{
__node_allocator& __a = base::__alloc();
typedef __allocator_destructor<__node_allocator> _Dp;
unique_ptr<__node, _Dp> __h(__node_traits::allocate(__a, 1), _Dp(__a, 1));
__node_traits::construct(__a, _VSTD::addressof(__h->__value_), _VSTD::move(__v));
__h->__next_ = base::__before_begin()->__next_;
base::__before_begin()->__next_ = __h.release();
}
#endif // _LIBCPP_CXX03_LANG
template <class _Tp, class _Alloc>
void
forward_list<_Tp, _Alloc>::push_front(const value_type& __v)
{
__node_allocator& __a = base::__alloc();
typedef __allocator_destructor<__node_allocator> _Dp;
unique_ptr<__node, _Dp> __h(__node_traits::allocate(__a, 1), _Dp(__a, 1));
__node_traits::construct(__a, _VSTD::addressof(__h->__value_), __v);
__h->__next_ = base::__before_begin()->__next_;
base::__before_begin()->__next_ = __h.release();
}
template <class _Tp, class _Alloc>
void
forward_list<_Tp, _Alloc>::pop_front()
{
__node_allocator& __a = base::__alloc();
__node_pointer __p = base::__before_begin()->__next_;
base::__before_begin()->__next_ = __p->__next_;
__node_traits::destroy(__a, _VSTD::addressof(__p->__value_));
__node_traits::deallocate(__a, __p, 1);
}
#ifndef _LIBCPP_CXX03_LANG
template <class _Tp, class _Alloc>
template <class... _Args>
typename forward_list<_Tp, _Alloc>::iterator
forward_list<_Tp, _Alloc>::emplace_after(const_iterator __p, _Args&&... __args)
{
__begin_node_pointer const __r = __p.__get_begin();
__node_allocator& __a = base::__alloc();
typedef __allocator_destructor<__node_allocator> _Dp;
unique_ptr<__node, _Dp> __h(__node_traits::allocate(__a, 1), _Dp(__a, 1));
__node_traits::construct(__a, _VSTD::addressof(__h->__value_),
_VSTD::forward<_Args>(__args)...);
__h->__next_ = __r->__next_;
__r->__next_ = __h.release();
return iterator(__r->__next_);
}
template <class _Tp, class _Alloc>
typename forward_list<_Tp, _Alloc>::iterator
forward_list<_Tp, _Alloc>::insert_after(const_iterator __p, value_type&& __v)
{
__begin_node_pointer const __r = __p.__get_begin();
__node_allocator& __a = base::__alloc();
typedef __allocator_destructor<__node_allocator> _Dp;
unique_ptr<__node, _Dp> __h(__node_traits::allocate(__a, 1), _Dp(__a, 1));
__node_traits::construct(__a, _VSTD::addressof(__h->__value_), _VSTD::move(__v));
__h->__next_ = __r->__next_;
__r->__next_ = __h.release();
return iterator(__r->__next_);
}
#endif // _LIBCPP_CXX03_LANG
template <class _Tp, class _Alloc>
typename forward_list<_Tp, _Alloc>::iterator
forward_list<_Tp, _Alloc>::insert_after(const_iterator __p, const value_type& __v)
{
__begin_node_pointer const __r = __p.__get_begin();
__node_allocator& __a = base::__alloc();
typedef __allocator_destructor<__node_allocator> _Dp;
unique_ptr<__node, _Dp> __h(__node_traits::allocate(__a, 1), _Dp(__a, 1));
__node_traits::construct(__a, _VSTD::addressof(__h->__value_), __v);
__h->__next_ = __r->__next_;
__r->__next_ = __h.release();
return iterator(__r->__next_);
}
template <class _Tp, class _Alloc>
typename forward_list<_Tp, _Alloc>::iterator
forward_list<_Tp, _Alloc>::insert_after(const_iterator __p, size_type __n,
const value_type& __v)
{
__begin_node_pointer __r = __p.__get_begin();
if (__n > 0)
{
__node_allocator& __a = base::__alloc();
typedef __allocator_destructor<__node_allocator> _Dp;
unique_ptr<__node, _Dp> __h(__node_traits::allocate(__a, 1), _Dp(__a, 1));
__node_traits::construct(__a, _VSTD::addressof(__h->__value_), __v);
__node_pointer __first = __h.release();
__node_pointer __last = __first;
#ifndef _LIBCPP_NO_EXCEPTIONS
try
{
#endif // _LIBCPP_NO_EXCEPTIONS
for (--__n; __n != 0; --__n, __last = __last->__next_)
{
__h.reset(__node_traits::allocate(__a, 1));
__node_traits::construct(__a, _VSTD::addressof(__h->__value_), __v);
__last->__next_ = __h.release();
}
#ifndef _LIBCPP_NO_EXCEPTIONS
}
catch (...)
{
while (__first != nullptr)
{
__node_pointer __next = __first->__next_;
__node_traits::destroy(__a, _VSTD::addressof(__first->__value_));
__node_traits::deallocate(__a, __first, 1);
__first = __next;
}
throw;
}
#endif // _LIBCPP_NO_EXCEPTIONS
__last->__next_ = __r->__next_;
__r->__next_ = __first;
__r = static_cast<__begin_node_pointer>(__last);
}
return iterator(__r);
}
template <class _Tp, class _Alloc>
template <class _InputIterator>
typename enable_if
<
__is_input_iterator<_InputIterator>::value,
typename forward_list<_Tp, _Alloc>::iterator
>::type
forward_list<_Tp, _Alloc>::insert_after(const_iterator __p,
_InputIterator __f, _InputIterator __l)
{
__begin_node_pointer __r = __p.__get_begin();
if (__f != __l)
{
__node_allocator& __a = base::__alloc();
typedef __allocator_destructor<__node_allocator> _Dp;
unique_ptr<__node, _Dp> __h(__node_traits::allocate(__a, 1), _Dp(__a, 1));
__node_traits::construct(__a, _VSTD::addressof(__h->__value_), *__f);
__node_pointer __first = __h.release();
__node_pointer __last = __first;
#ifndef _LIBCPP_NO_EXCEPTIONS
try
{
#endif // _LIBCPP_NO_EXCEPTIONS
for (++__f; __f != __l; ++__f, ((void)(__last = __last->__next_)))
{
__h.reset(__node_traits::allocate(__a, 1));
__node_traits::construct(__a, _VSTD::addressof(__h->__value_), *__f);
__last->__next_ = __h.release();
}
#ifndef _LIBCPP_NO_EXCEPTIONS
}
catch (...)
{
while (__first != nullptr)
{
__node_pointer __next = __first->__next_;
__node_traits::destroy(__a, _VSTD::addressof(__first->__value_));
__node_traits::deallocate(__a, __first, 1);
__first = __next;
}
throw;
}
#endif // _LIBCPP_NO_EXCEPTIONS
__last->__next_ = __r->__next_;
__r->__next_ = __first;
__r = static_cast<__begin_node_pointer>(__last);
}
return iterator(__r);
}
template <class _Tp, class _Alloc>
typename forward_list<_Tp, _Alloc>::iterator
forward_list<_Tp, _Alloc>::erase_after(const_iterator __f)
{
__begin_node_pointer __p = __f.__get_begin();
__node_pointer __n = __p->__next_;
__p->__next_ = __n->__next_;
__node_allocator& __a = base::__alloc();
__node_traits::destroy(__a, _VSTD::addressof(__n->__value_));
__node_traits::deallocate(__a, __n, 1);
return iterator(__p->__next_);
}
template <class _Tp, class _Alloc>
typename forward_list<_Tp, _Alloc>::iterator
forward_list<_Tp, _Alloc>::erase_after(const_iterator __f, const_iterator __l)
{
__node_pointer __e = __l.__get_unsafe_node_pointer();
if (__f != __l)
{
__begin_node_pointer __bp = __f.__get_begin();
__node_pointer __n = __bp->__next_;
if (__n != __e)
{
__bp->__next_ = __e;
__node_allocator& __a = base::__alloc();
do
{
__node_pointer __tmp = __n->__next_;
__node_traits::destroy(__a, _VSTD::addressof(__n->__value_));
__node_traits::deallocate(__a, __n, 1);
__n = __tmp;
} while (__n != __e);
}
}
return iterator(__e);
}
template <class _Tp, class _Alloc>
void
forward_list<_Tp, _Alloc>::resize(size_type __n)
{
size_type __sz = 0;
iterator __p = before_begin();
iterator __i = begin();
iterator __e = end();
for (; __i != __e && __sz < __n; ++__p, ++__i, ++__sz)
;
if (__i != __e)
erase_after(__p, __e);
else
{
__n -= __sz;
if (__n > 0)
{
__node_allocator& __a = base::__alloc();
typedef __allocator_destructor<__node_allocator> _Dp;
unique_ptr<__node, _Dp> __h(nullptr, _Dp(__a, 1));
for (__begin_node_pointer __ptr = __p.__get_begin(); __n > 0; --__n,
__ptr = __ptr->__next_as_begin())
{
__h.reset(__node_traits::allocate(__a, 1));
__node_traits::construct(__a, _VSTD::addressof(__h->__value_));
__h->__next_ = nullptr;
__ptr->__next_ = __h.release();
}
}
}
}
template <class _Tp, class _Alloc>
void
forward_list<_Tp, _Alloc>::resize(size_type __n, const value_type& __v)
{
size_type __sz = 0;
iterator __p = before_begin();
iterator __i = begin();
iterator __e = end();
for (; __i != __e && __sz < __n; ++__p, ++__i, ++__sz)
;
if (__i != __e)
erase_after(__p, __e);
else
{
__n -= __sz;
if (__n > 0)
{
__node_allocator& __a = base::__alloc();
typedef __allocator_destructor<__node_allocator> _Dp;
unique_ptr<__node, _Dp> __h(nullptr, _Dp(__a, 1));
for (__begin_node_pointer __ptr = __p.__get_begin(); __n > 0; --__n,
__ptr = __ptr->__next_as_begin())
{
__h.reset(__node_traits::allocate(__a, 1));
__node_traits::construct(__a, _VSTD::addressof(__h->__value_), __v);
__h->__next_ = nullptr;
__ptr->__next_ = __h.release();
}
}
}
}
template <class _Tp, class _Alloc>
void
forward_list<_Tp, _Alloc>::splice_after(const_iterator __p,
forward_list& __x)
{
if (!__x.empty())
{
if (__p.__get_begin()->__next_ != nullptr)
{
const_iterator __lm1 = __x.before_begin();
while (__lm1.__get_begin()->__next_ != nullptr)
++__lm1;
__lm1.__get_begin()->__next_ = __p.__get_begin()->__next_;
}
__p.__get_begin()->__next_ = __x.__before_begin()->__next_;
__x.__before_begin()->__next_ = nullptr;
}
}
template <class _Tp, class _Alloc>
void
forward_list<_Tp, _Alloc>::splice_after(const_iterator __p,
forward_list& /*__other*/,
const_iterator __i)
{
const_iterator __lm1 = _VSTD::next(__i);
if (__p != __i && __p != __lm1)
{
__i.__get_begin()->__next_ = __lm1.__get_begin()->__next_;
__lm1.__get_begin()->__next_ = __p.__get_begin()->__next_;
__p.__get_begin()->__next_ = __lm1.__get_unsafe_node_pointer();
}
}
template <class _Tp, class _Alloc>
void
forward_list<_Tp, _Alloc>::splice_after(const_iterator __p,
forward_list& /*__other*/,
const_iterator __f, const_iterator __l)
{
if (__f != __l && __p != __f)
{
const_iterator __lm1 = __f;
while (__lm1.__get_begin()->__next_ != __l.__get_begin())
++__lm1;
if (__f != __lm1)
{
__lm1.__get_begin()->__next_ = __p.__get_begin()->__next_;
__p.__get_begin()->__next_ = __f.__get_begin()->__next_;
__f.__get_begin()->__next_ = __l.__get_unsafe_node_pointer();
}
}
}
template <class _Tp, class _Alloc>
inline _LIBCPP_INLINE_VISIBILITY
void
forward_list<_Tp, _Alloc>::splice_after(const_iterator __p,
forward_list&& __x)
{
splice_after(__p, __x);
}
template <class _Tp, class _Alloc>
inline _LIBCPP_INLINE_VISIBILITY
void
forward_list<_Tp, _Alloc>::splice_after(const_iterator __p,
forward_list&& __x,
const_iterator __i)
{
splice_after(__p, __x, __i);
}
template <class _Tp, class _Alloc>
inline _LIBCPP_INLINE_VISIBILITY
void
forward_list<_Tp, _Alloc>::splice_after(const_iterator __p,
forward_list&& __x,
const_iterator __f, const_iterator __l)
{
splice_after(__p, __x, __f, __l);
}
template <class _Tp, class _Alloc>
typename forward_list<_Tp, _Alloc>::__remove_return_type
forward_list<_Tp, _Alloc>::remove(const value_type& __v)
{
forward_list<_Tp, _Alloc> __deleted_nodes(get_allocator()); // collect the nodes we're removing
typename forward_list<_Tp, _Alloc>::size_type __count_removed = 0;
const iterator __e = end();
for (iterator __i = before_begin(); __i.__get_begin()->__next_ != nullptr;)
{
if (__i.__get_begin()->__next_->__value_ == __v)
{
++__count_removed;
iterator __j = _VSTD::next(__i, 2);
for (; __j != __e && *__j == __v; ++__j)
++__count_removed;
__deleted_nodes.splice_after(__deleted_nodes.before_begin(), *this, __i, __j);
if (__j == __e)
break;
__i = __j;
}
else
++__i;
}
return (__remove_return_type) __count_removed;
}
template <class _Tp, class _Alloc>
template <class _Predicate>
typename forward_list<_Tp, _Alloc>::__remove_return_type
forward_list<_Tp, _Alloc>::remove_if(_Predicate __pred)
{
forward_list<_Tp, _Alloc> __deleted_nodes(get_allocator()); // collect the nodes we're removing
typename forward_list<_Tp, _Alloc>::size_type __count_removed = 0;
const iterator __e = end();
for (iterator __i = before_begin(); __i.__get_begin()->__next_ != nullptr;)
{
if (__pred(__i.__get_begin()->__next_->__value_))
{
++__count_removed;
iterator __j = _VSTD::next(__i, 2);
for (; __j != __e && __pred(*__j); ++__j)
++__count_removed;
__deleted_nodes.splice_after(__deleted_nodes.before_begin(), *this, __i, __j);
if (__j == __e)
break;
__i = __j;
}
else
++__i;
}
return (__remove_return_type) __count_removed;
}
template <class _Tp, class _Alloc>
template <class _BinaryPredicate>
typename forward_list<_Tp, _Alloc>::__remove_return_type
forward_list<_Tp, _Alloc>::unique(_BinaryPredicate __binary_pred)
{
forward_list<_Tp, _Alloc> __deleted_nodes(get_allocator()); // collect the nodes we're removing
typename forward_list<_Tp, _Alloc>::size_type __count_removed = 0;
for (iterator __i = begin(), __e = end(); __i != __e;)
{
iterator __j = _VSTD::next(__i);
for (; __j != __e && __binary_pred(*__i, *__j); ++__j)
++__count_removed;
if (__i.__get_begin()->__next_ != __j.__get_unsafe_node_pointer())
__deleted_nodes.splice_after(__deleted_nodes.before_begin(), *this, __i, __j);
__i = __j;
}
return (__remove_return_type) __count_removed;
}
template <class _Tp, class _Alloc>
template <class _Compare>
void
forward_list<_Tp, _Alloc>::merge(forward_list& __x, _Compare __comp)
{
if (this != &__x)
{
base::__before_begin()->__next_ = __merge(base::__before_begin()->__next_,
__x.__before_begin()->__next_,
__comp);
__x.__before_begin()->__next_ = nullptr;
}
}
template <class _Tp, class _Alloc>
template <class _Compare>
typename forward_list<_Tp, _Alloc>::__node_pointer
forward_list<_Tp, _Alloc>::__merge(__node_pointer __f1, __node_pointer __f2,
_Compare& __comp)
{
if (__f1 == nullptr)
return __f2;
if (__f2 == nullptr)
return __f1;
__node_pointer __r;
if (__comp(__f2->__value_, __f1->__value_))
{
__node_pointer __t = __f2;
while (__t->__next_ != nullptr &&
__comp(__t->__next_->__value_, __f1->__value_))
__t = __t->__next_;
__r = __f2;
__f2 = __t->__next_;
__t->__next_ = __f1;
}
else
__r = __f1;
__node_pointer __p = __f1;
__f1 = __f1->__next_;
while (__f1 != nullptr && __f2 != nullptr)
{
if (__comp(__f2->__value_, __f1->__value_))
{
__node_pointer __t = __f2;
while (__t->__next_ != nullptr &&
__comp(__t->__next_->__value_, __f1->__value_))
__t = __t->__next_;
__p->__next_ = __f2;
__f2 = __t->__next_;
__t->__next_ = __f1;
}
__p = __f1;
__f1 = __f1->__next_;
}
if (__f2 != nullptr)
__p->__next_ = __f2;
return __r;
}
template <class _Tp, class _Alloc>
template <class _Compare>
inline
void
forward_list<_Tp, _Alloc>::sort(_Compare __comp)
{
base::__before_begin()->__next_ = __sort(base::__before_begin()->__next_,
_VSTD::distance(begin(), end()), __comp);
}
template <class _Tp, class _Alloc>
template <class _Compare>
typename forward_list<_Tp, _Alloc>::__node_pointer
forward_list<_Tp, _Alloc>::__sort(__node_pointer __f1, difference_type __sz,
_Compare& __comp)
{
switch (__sz)
{
case 0:
case 1:
return __f1;
case 2:
if (__comp(__f1->__next_->__value_, __f1->__value_))
{
__node_pointer __t = __f1->__next_;
__t->__next_ = __f1;
__f1->__next_ = nullptr;
__f1 = __t;
}
return __f1;
}
difference_type __sz1 = __sz / 2;
difference_type __sz2 = __sz - __sz1;
__node_pointer __t = _VSTD::next(iterator(__f1), __sz1 - 1).__get_unsafe_node_pointer();
__node_pointer __f2 = __t->__next_;
__t->__next_ = nullptr;
return __merge(__sort(__f1, __sz1, __comp),
__sort(__f2, __sz2, __comp), __comp);
}
template <class _Tp, class _Alloc>
void
forward_list<_Tp, _Alloc>::reverse() _NOEXCEPT
{
__node_pointer __p = base::__before_begin()->__next_;
if (__p != nullptr)
{
__node_pointer __f = __p->__next_;
__p->__next_ = nullptr;
while (__f != nullptr)
{
__node_pointer __t = __f->__next_;
__f->__next_ = __p;
__p = __f;
__f = __t;
}
base::__before_begin()->__next_ = __p;
}
}
template <class _Tp, class _Alloc>
bool operator==(const forward_list<_Tp, _Alloc>& __x,
const forward_list<_Tp, _Alloc>& __y)
{
typedef forward_list<_Tp, _Alloc> _Cp;
typedef typename _Cp::const_iterator _Ip;
_Ip __ix = __x.begin();
_Ip __ex = __x.end();
_Ip __iy = __y.begin();
_Ip __ey = __y.end();
for (; __ix != __ex && __iy != __ey; ++__ix, ++__iy)
if (!(*__ix == *__iy))
return false;
return (__ix == __ex) == (__iy == __ey);
}
template <class _Tp, class _Alloc>
inline _LIBCPP_INLINE_VISIBILITY
bool operator!=(const forward_list<_Tp, _Alloc>& __x,
const forward_list<_Tp, _Alloc>& __y)
{
return !(__x == __y);
}
template <class _Tp, class _Alloc>
inline _LIBCPP_INLINE_VISIBILITY
bool operator< (const forward_list<_Tp, _Alloc>& __x,
const forward_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 forward_list<_Tp, _Alloc>& __x,
const forward_list<_Tp, _Alloc>& __y)
{
return __y < __x;
}
template <class _Tp, class _Alloc>
inline _LIBCPP_INLINE_VISIBILITY
bool operator>=(const forward_list<_Tp, _Alloc>& __x,
const forward_list<_Tp, _Alloc>& __y)
{
return !(__x < __y);
}
template <class _Tp, class _Alloc>
inline _LIBCPP_INLINE_VISIBILITY
bool operator<=(const forward_list<_Tp, _Alloc>& __x,
const forward_list<_Tp, _Alloc>& __y)
{
return !(__y < __x);
}
template <class _Tp, class _Alloc>
inline _LIBCPP_INLINE_VISIBILITY
void
swap(forward_list<_Tp, _Alloc>& __x, forward_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(forward_list<_Tp, _Allocator>& __c, _Predicate __pred)
{ __c.remove_if(__pred); }
template <class _Tp, class _Allocator, class _Up>
inline _LIBCPP_INLINE_VISIBILITY
void erase(forward_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_FORWARD_LIST
| 62,476 | 1,783 | jart/cosmopolitan | false |
cosmopolitan/third_party/libcxx/__std_stream | // -*- 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___STD_STREAM
#define _LIBCPP___STD_STREAM
#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"
#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
static const int __limit = 8;
// __stdinbuf
template <class _CharT>
class _LIBCPP_HIDDEN __stdinbuf
: public basic_streambuf<_CharT, char_traits<_CharT> >
{
public:
typedef _CharT char_type;
typedef char_traits<char_type> 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;
__stdinbuf(FILE* __fp, state_type* __st);
protected:
virtual int_type underflow();
virtual int_type uflow();
virtual int_type pbackfail(int_type __c = traits_type::eof());
virtual void imbue(const locale& __loc);
private:
FILE* __file_;
const codecvt<char_type, char, state_type>* __cv_;
state_type* __st_;
int __encoding_;
int_type __last_consumed_;
bool __last_consumed_is_next_;
bool __always_noconv_;
__stdinbuf(const __stdinbuf&);
__stdinbuf& operator=(const __stdinbuf&);
int_type __getchar(bool __consume);
};
template <class _CharT>
__stdinbuf<_CharT>::__stdinbuf(FILE* __fp, state_type* __st)
: __file_(__fp),
__st_(__st),
__last_consumed_(traits_type::eof()),
__last_consumed_is_next_(false)
{
imbue(this->getloc());
}
template <class _CharT>
void
__stdinbuf<_CharT>::imbue(const locale& __loc)
{
__cv_ = &use_facet<codecvt<char_type, char, state_type> >(__loc);
__encoding_ = __cv_->encoding();
__always_noconv_ = __cv_->always_noconv();
if (__encoding_ > __limit)
__throw_runtime_error("unsupported locale for standard input");
}
template <class _CharT>
typename __stdinbuf<_CharT>::int_type
__stdinbuf<_CharT>::underflow()
{
return __getchar(false);
}
template <class _CharT>
typename __stdinbuf<_CharT>::int_type
__stdinbuf<_CharT>::uflow()
{
return __getchar(true);
}
template <class _CharT>
typename __stdinbuf<_CharT>::int_type
__stdinbuf<_CharT>::__getchar(bool __consume)
{
if (__last_consumed_is_next_)
{
int_type __result = __last_consumed_;
if (__consume)
{
__last_consumed_ = traits_type::eof();
__last_consumed_is_next_ = false;
}
return __result;
}
char __extbuf[__limit];
int __nread = _VSTD::max(1, __encoding_);
for (int __i = 0; __i < __nread; ++__i)
{
int __c = getc(__file_);
if (__c == EOF)
return traits_type::eof();
__extbuf[__i] = static_cast<char>(__c);
}
char_type __1buf;
if (__always_noconv_)
__1buf = static_cast<char_type>(__extbuf[0]);
else
{
const char* __enxt;
char_type* __inxt;
codecvt_base::result __r;
do
{
state_type __sv_st = *__st_;
__r = __cv_->in(*__st_, __extbuf, __extbuf + __nread, __enxt,
&__1buf, &__1buf + 1, __inxt);
switch (__r)
{
case _VSTD::codecvt_base::ok:
break;
case codecvt_base::partial:
*__st_ = __sv_st;
if (__nread == sizeof(__extbuf))
return traits_type::eof();
{
int __c = getc(__file_);
if (__c == EOF)
return traits_type::eof();
__extbuf[__nread] = static_cast<char>(__c);
}
++__nread;
break;
case codecvt_base::error:
return traits_type::eof();
case _VSTD::codecvt_base::noconv:
__1buf = static_cast<char_type>(__extbuf[0]);
break;
}
} while (__r == _VSTD::codecvt_base::partial);
}
if (!__consume)
{
for (int __i = __nread; __i > 0;)
{
if (ungetc(traits_type::to_int_type(__extbuf[--__i]), __file_) == EOF)
return traits_type::eof();
}
}
else
__last_consumed_ = traits_type::to_int_type(__1buf);
return traits_type::to_int_type(__1buf);
}
template <class _CharT>
typename __stdinbuf<_CharT>::int_type
__stdinbuf<_CharT>::pbackfail(int_type __c)
{
if (traits_type::eq_int_type(__c, traits_type::eof()))
{
if (!__last_consumed_is_next_)
{
__c = __last_consumed_;
__last_consumed_is_next_ = !traits_type::eq_int_type(__last_consumed_,
traits_type::eof());
}
return __c;
}
if (__last_consumed_is_next_)
{
char __extbuf[__limit];
char* __enxt;
const char_type __ci = traits_type::to_char_type(__last_consumed_);
const char_type* __inxt;
switch (__cv_->out(*__st_, &__ci, &__ci + 1, __inxt,
__extbuf, __extbuf + sizeof(__extbuf), __enxt))
{
case _VSTD::codecvt_base::ok:
break;
case _VSTD::codecvt_base::noconv:
__extbuf[0] = static_cast<char>(__last_consumed_);
__enxt = __extbuf + 1;
break;
case codecvt_base::partial:
case codecvt_base::error:
return traits_type::eof();
}
while (__enxt > __extbuf)
if (ungetc(*--__enxt, __file_) == EOF)
return traits_type::eof();
}
__last_consumed_ = __c;
__last_consumed_is_next_ = true;
return __c;
}
// __stdoutbuf
template <class _CharT>
class _LIBCPP_HIDDEN __stdoutbuf
: public basic_streambuf<_CharT, char_traits<_CharT> >
{
public:
typedef _CharT char_type;
typedef char_traits<char_type> 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;
__stdoutbuf(FILE* __fp, state_type* __st);
protected:
virtual int_type overflow (int_type __c = traits_type::eof());
virtual streamsize xsputn(const char_type* __s, streamsize __n);
virtual int sync();
virtual void imbue(const locale& __loc);
private:
FILE* __file_;
const codecvt<char_type, char, state_type>* __cv_;
state_type* __st_;
bool __always_noconv_;
__stdoutbuf(const __stdoutbuf&);
__stdoutbuf& operator=(const __stdoutbuf&);
};
template <class _CharT>
__stdoutbuf<_CharT>::__stdoutbuf(FILE* __fp, state_type* __st)
: __file_(__fp),
__cv_(&use_facet<codecvt<char_type, char, state_type> >(this->getloc())),
__st_(__st),
__always_noconv_(__cv_->always_noconv())
{
}
template <class _CharT>
typename __stdoutbuf<_CharT>::int_type
__stdoutbuf<_CharT>::overflow(int_type __c)
{
char __extbuf[__limit];
char_type __1buf;
if (!traits_type::eq_int_type(__c, traits_type::eof()))
{
__1buf = traits_type::to_char_type(__c);
if (__always_noconv_)
{
if (fwrite(&__1buf, sizeof(char_type), 1, __file_) != 1)
return traits_type::eof();
}
else
{
char* __extbe = __extbuf;
codecvt_base::result __r;
char_type* pbase = &__1buf;
char_type* pptr = pbase + 1;
do
{
const char_type* __e;
__r = __cv_->out(*__st_, pbase, pptr, __e,
__extbuf,
__extbuf + sizeof(__extbuf),
__extbe);
if (__e == pbase)
return traits_type::eof();
if (__r == codecvt_base::noconv)
{
if (fwrite(pbase, 1, 1, __file_) != 1)
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)
{
pbase = const_cast<char_type*>(__e);
}
}
else
return traits_type::eof();
} while (__r == codecvt_base::partial);
}
}
return traits_type::not_eof(__c);
}
template <class _CharT>
streamsize
__stdoutbuf<_CharT>::xsputn(const char_type* __s, streamsize __n)
{
if (__always_noconv_)
return fwrite(__s, sizeof(char_type), __n, __file_);
streamsize __i = 0;
for (; __i < __n; ++__i, ++__s)
if (overflow(traits_type::to_int_type(*__s)) == traits_type::eof())
break;
return __i;
}
template <class _CharT>
int
__stdoutbuf<_CharT>::sync()
{
char __extbuf[__limit];
codecvt_base::result __r;
do
{
char* __extbe;
__r = __cv_->unshift(*__st_, __extbuf,
__extbuf + sizeof(__extbuf),
__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;
return 0;
}
template <class _CharT>
void
__stdoutbuf<_CharT>::imbue(const locale& __loc)
{
sync();
__cv_ = &use_facet<codecvt<char_type, char, state_type> >(__loc);
__always_noconv_ = __cv_->always_noconv();
}
_LIBCPP_END_NAMESPACE_STD
_LIBCPP_POP_MACROS
#endif // _LIBCPP___STD_STREAM
| 10,702 | 363 | jart/cosmopolitan | false |
cosmopolitan/third_party/libcxx/iostream | // -*- C++ -*-
// clang-format off
//===--------------------------- iostream ---------------------------------===//
//
// 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_IOSTREAM
#define _LIBCPP_IOSTREAM
/*
iostream synopsis
#include <ios>
#include <streambuf>
#include <istream>
#include <ostream>
namespace std {
extern istream cin;
extern ostream cout;
extern ostream cerr;
extern ostream clog;
extern wistream wcin;
extern wostream wcout;
extern wostream wcerr;
extern wostream wclog;
} // std
*/
#include "third_party/libcxx/__config"
#include "third_party/libcxx/ios"
#include "third_party/libcxx/streambuf"
#include "third_party/libcxx/istream"
#include "third_party/libcxx/ostream"
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
#pragma GCC system_header
#endif
_LIBCPP_BEGIN_NAMESPACE_STD
#ifndef _LIBCPP_HAS_NO_STDIN
extern _LIBCPP_FUNC_VIS istream cin;
extern _LIBCPP_FUNC_VIS wistream wcin;
#endif
#ifndef _LIBCPP_HAS_NO_STDOUT
extern _LIBCPP_FUNC_VIS ostream cout;
extern _LIBCPP_FUNC_VIS wostream wcout;
#endif
extern _LIBCPP_FUNC_VIS ostream cerr;
extern _LIBCPP_FUNC_VIS wostream wcerr;
extern _LIBCPP_FUNC_VIS ostream clog;
extern _LIBCPP_FUNC_VIS wostream wclog;
_LIBCPP_END_NAMESPACE_STD
#endif // _LIBCPP_IOSTREAM
| 1,506 | 65 | jart/cosmopolitan | false |
cosmopolitan/third_party/libcxx/ostream | // -*- C++ -*-
//===-------------------------- ostream -----------------------------------===//
//
// 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_OSTREAM
#define _LIBCPP_OSTREAM
#include "third_party/libcxx/__config"
#include "third_party/libcxx/ios"
#include "third_party/libcxx/streambuf"
#include "third_party/libcxx/locale"
#include "third_party/libcxx/iterator"
#include "third_party/libcxx/bitset"
#include "third_party/libcxx/version"
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
#pragma GCC system_header
#endif
_LIBCPP_BEGIN_NAMESPACE_STD
/*
ostream synopsis
template <class charT, class traits = char_traits<charT> >
class basic_ostream
: virtual public basic_ios<charT,traits>
{
public:
// types (inherited from basic_ios (27.5.4)):
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.7.2.2 Constructor/destructor:
explicit basic_ostream(basic_streambuf<char_type,traits>* sb);
basic_ostream(basic_ostream&& rhs);
virtual ~basic_ostream();
// 27.7.2.3 Assign/swap
basic_ostream& operator=(const basic_ostream& rhs) = delete; // C++14
basic_ostream& operator=(basic_ostream&& rhs);
void swap(basic_ostream& rhs);
// 27.7.2.4 Prefix/suffix:
class sentry;
// 27.7.2.6 Formatted output:
basic_ostream& operator<<(basic_ostream& (*pf)(basic_ostream&));
basic_ostream& operator<<(basic_ios<charT, traits>& (*pf)(basic_ios<charT,traits>&));
basic_ostream& operator<<(ios_base& (*pf)(ios_base&));
basic_ostream& operator<<(bool n);
basic_ostream& operator<<(short n);
basic_ostream& operator<<(unsigned short n);
basic_ostream& operator<<(int n);
basic_ostream& operator<<(unsigned int n);
basic_ostream& operator<<(long n);
basic_ostream& operator<<(unsigned long n);
basic_ostream& operator<<(long long n);
basic_ostream& operator<<(unsigned long long n);
basic_ostream& operator<<(float f);
basic_ostream& operator<<(double f);
basic_ostream& operator<<(long double f);
basic_ostream& operator<<(const void* p);
basic_ostream& operator<<(basic_streambuf<char_type,traits>* sb);
basic_ostream& operator<<(nullptr_t);
// 27.7.2.7 Unformatted output:
basic_ostream& put(char_type c);
basic_ostream& write(const char_type* s, streamsize n);
basic_ostream& flush();
// 27.7.2.5 seeks:
pos_type tellp();
basic_ostream& seekp(pos_type);
basic_ostream& seekp(off_type, ios_base::seekdir);
protected:
basic_ostream(const basic_ostream& rhs) = delete;
basic_ostream(basic_ostream&& rhs);
// 27.7.3.3 Assign/swap
basic_ostream& operator=(basic_ostream& rhs) = delete;
basic_ostream& operator=(const basic_ostream&& rhs);
void swap(basic_ostream& rhs);
};
// 27.7.2.6.4 character inserters
template<class charT, class traits>
basic_ostream<charT,traits>& operator<<(basic_ostream<charT,traits>&, charT);
template<class charT, class traits>
basic_ostream<charT,traits>& operator<<(basic_ostream<charT,traits>&, char);
template<class traits>
basic_ostream<char,traits>& operator<<(basic_ostream<char,traits>&, char);
// signed and unsigned
template<class traits>
basic_ostream<char,traits>& operator<<(basic_ostream<char,traits>&, signed char);
template<class traits>
basic_ostream<char,traits>& operator<<(basic_ostream<char,traits>&, unsigned char);
// NTBS
template<class charT, class traits>
basic_ostream<charT,traits>& operator<<(basic_ostream<charT,traits>&, const charT*);
template<class charT, class traits>
basic_ostream<charT,traits>& operator<<(basic_ostream<charT,traits>&, const char*);
template<class traits>
basic_ostream<char,traits>& operator<<(basic_ostream<char,traits>&, const char*);
// signed and unsigned
template<class traits>
basic_ostream<char,traits>& operator<<(basic_ostream<char,traits>&, const signed char*);
template<class traits>
basic_ostream<char,traits>& operator<<(basic_ostream<char,traits>&, const unsigned char*);
// swap:
template <class charT, class traits>
void swap(basic_ostream<charT, traits>& x, basic_ostream<charT, traits>& y);
template <class charT, class traits>
basic_ostream<charT,traits>& endl(basic_ostream<charT,traits>& os);
template <class charT, class traits>
basic_ostream<charT,traits>& ends(basic_ostream<charT,traits>& os);
template <class charT, class traits>
basic_ostream<charT,traits>& flush(basic_ostream<charT,traits>& os);
// rvalue stream insertion
template <class charT, class traits, class T>
basic_ostream<charT, traits>&
operator<<(basic_ostream<charT, traits>&& os, const T& x);
} // std
*/
template <class _CharT, class _Traits>
class _LIBCPP_TEMPLATE_VIS basic_ostream
: virtual public basic_ios<_CharT, _Traits>
{
public:
// types (inherited from basic_ios (27.5.4)):
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.7.2.2 Constructor/destructor:
inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1
explicit basic_ostream(basic_streambuf<char_type, traits_type>* __sb)
{ this->init(__sb); }
virtual ~basic_ostream();
protected:
#ifndef _LIBCPP_CXX03_LANG
inline _LIBCPP_INLINE_VISIBILITY
basic_ostream(basic_ostream&& __rhs);
// 27.7.2.3 Assign/swap
inline _LIBCPP_INLINE_VISIBILITY
basic_ostream& operator=(basic_ostream&& __rhs);
#endif
inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1
void swap(basic_ostream& __rhs)
{ basic_ios<char_type, traits_type>::swap(__rhs); }
#ifndef _LIBCPP_CXX03_LANG
basic_ostream (const basic_ostream& __rhs) = delete;
basic_ostream& operator=(const basic_ostream& __rhs) = delete;
#else
basic_ostream (const basic_ostream& __rhs); // not defined
basic_ostream& operator=(const basic_ostream& __rhs); // not defined
#endif
public:
// 27.7.2.4 Prefix/suffix:
class _LIBCPP_TEMPLATE_VIS sentry;
// 27.7.2.6 Formatted output:
inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1
basic_ostream& operator<<(basic_ostream& (*__pf)(basic_ostream&))
{ return __pf(*this); }
inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1
basic_ostream& operator<<(basic_ios<char_type, traits_type>&
(*__pf)(basic_ios<char_type,traits_type>&))
{ __pf(*this); return *this; }
inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1
basic_ostream& operator<<(ios_base& (*__pf)(ios_base&))
{ __pf(*this); return *this; }
basic_ostream& operator<<(bool __n);
basic_ostream& operator<<(short __n);
basic_ostream& operator<<(unsigned short __n);
basic_ostream& operator<<(int __n);
basic_ostream& operator<<(unsigned int __n);
basic_ostream& operator<<(long __n);
basic_ostream& operator<<(unsigned long __n);
basic_ostream& operator<<(long long __n);
basic_ostream& operator<<(unsigned long long __n);
basic_ostream& operator<<(float __f);
basic_ostream& operator<<(double __f);
basic_ostream& operator<<(long double __f);
basic_ostream& operator<<(const void* __p);
basic_ostream& operator<<(basic_streambuf<char_type, traits_type>* __sb);
_LIBCPP_INLINE_VISIBILITY
basic_ostream& operator<<(nullptr_t)
{ return *this << "nullptr"; }
// 27.7.2.7 Unformatted output:
basic_ostream& put(char_type __c);
basic_ostream& write(const char_type* __s, streamsize __n);
basic_ostream& flush();
// 27.7.2.5 seeks:
inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1
pos_type tellp();
inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1
basic_ostream& seekp(pos_type __pos);
inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1
basic_ostream& seekp(off_type __off, ios_base::seekdir __dir);
protected:
_LIBCPP_INLINE_VISIBILITY
basic_ostream() {} // extension, intentially does not initialize
};
template <class _CharT, class _Traits>
class _LIBCPP_TEMPLATE_VIS basic_ostream<_CharT, _Traits>::sentry
{
bool __ok_;
basic_ostream<_CharT, _Traits>& __os_;
sentry(const sentry&); // = delete;
sentry& operator=(const sentry&); // = delete;
public:
explicit sentry(basic_ostream<_CharT, _Traits>& __os);
~sentry();
_LIBCPP_INLINE_VISIBILITY
_LIBCPP_EXPLICIT
operator bool() const {return __ok_;}
};
template <class _CharT, class _Traits>
basic_ostream<_CharT, _Traits>::sentry::sentry(basic_ostream<_CharT, _Traits>& __os)
: __ok_(false),
__os_(__os)
{
if (__os.good())
{
if (__os.tie())
__os.tie()->flush();
__ok_ = true;
}
}
template <class _CharT, class _Traits>
basic_ostream<_CharT, _Traits>::sentry::~sentry()
{
if (__os_.rdbuf() && __os_.good() && (__os_.flags() & ios_base::unitbuf)
&& !uncaught_exception())
{
#ifndef _LIBCPP_NO_EXCEPTIONS
try
{
#endif // _LIBCPP_NO_EXCEPTIONS
if (__os_.rdbuf()->pubsync() == -1)
__os_.setstate(ios_base::badbit);
#ifndef _LIBCPP_NO_EXCEPTIONS
}
catch (...)
{
}
#endif // _LIBCPP_NO_EXCEPTIONS
}
}
#ifndef _LIBCPP_CXX03_LANG
template <class _CharT, class _Traits>
basic_ostream<_CharT, _Traits>::basic_ostream(basic_ostream&& __rhs)
{
this->move(__rhs);
}
template <class _CharT, class _Traits>
basic_ostream<_CharT, _Traits>&
basic_ostream<_CharT, _Traits>::operator=(basic_ostream&& __rhs)
{
swap(__rhs);
return *this;
}
#endif // _LIBCPP_CXX03_LANG
template <class _CharT, class _Traits>
basic_ostream<_CharT, _Traits>::~basic_ostream()
{
}
template <class _CharT, class _Traits>
basic_ostream<_CharT, _Traits>&
basic_ostream<_CharT, _Traits>::operator<<(basic_streambuf<char_type, traits_type>* __sb)
{
#ifndef _LIBCPP_NO_EXCEPTIONS
try
{
#endif // _LIBCPP_NO_EXCEPTIONS
sentry __s(*this);
if (__s)
{
if (__sb)
{
#ifndef _LIBCPP_NO_EXCEPTIONS
try
{
#endif // _LIBCPP_NO_EXCEPTIONS
typedef istreambuf_iterator<_CharT, _Traits> _Ip;
typedef ostreambuf_iterator<_CharT, _Traits> _Op;
_Ip __i(__sb);
_Ip __eof;
_Op __o(*this);
size_t __c = 0;
for (; __i != __eof; ++__i, ++__o, ++__c)
{
*__o = *__i;
if (__o.failed())
break;
}
if (__c == 0)
this->setstate(ios_base::failbit);
#ifndef _LIBCPP_NO_EXCEPTIONS
}
catch (...)
{
this->__set_failbit_and_consider_rethrow();
}
#endif // _LIBCPP_NO_EXCEPTIONS
}
else
this->setstate(ios_base::badbit);
}
#ifndef _LIBCPP_NO_EXCEPTIONS
}
catch (...)
{
this->__set_badbit_and_consider_rethrow();
}
#endif // _LIBCPP_NO_EXCEPTIONS
return *this;
}
template <class _CharT, class _Traits>
basic_ostream<_CharT, _Traits>&
basic_ostream<_CharT, _Traits>::operator<<(bool __n)
{
#ifndef _LIBCPP_NO_EXCEPTIONS
try
{
#endif // _LIBCPP_NO_EXCEPTIONS
sentry __s(*this);
if (__s)
{
typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp;
const _Fp& __f = use_facet<_Fp>(this->getloc());
if (__f.put(*this, *this, this->fill(), __n).failed())
this->setstate(ios_base::badbit | ios_base::failbit);
}
#ifndef _LIBCPP_NO_EXCEPTIONS
}
catch (...)
{
this->__set_badbit_and_consider_rethrow();
}
#endif // _LIBCPP_NO_EXCEPTIONS
return *this;
}
template <class _CharT, class _Traits>
basic_ostream<_CharT, _Traits>&
basic_ostream<_CharT, _Traits>::operator<<(short __n)
{
#ifndef _LIBCPP_NO_EXCEPTIONS
try
{
#endif // _LIBCPP_NO_EXCEPTIONS
sentry __s(*this);
if (__s)
{
ios_base::fmtflags __flags = ios_base::flags() & ios_base::basefield;
typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp;
const _Fp& __f = use_facet<_Fp>(this->getloc());
if (__f.put(*this, *this, this->fill(),
__flags == ios_base::oct || __flags == ios_base::hex ?
static_cast<long>(static_cast<unsigned short>(__n)) :
static_cast<long>(__n)).failed())
this->setstate(ios_base::badbit | ios_base::failbit);
}
#ifndef _LIBCPP_NO_EXCEPTIONS
}
catch (...)
{
this->__set_badbit_and_consider_rethrow();
}
#endif // _LIBCPP_NO_EXCEPTIONS
return *this;
}
template <class _CharT, class _Traits>
basic_ostream<_CharT, _Traits>&
basic_ostream<_CharT, _Traits>::operator<<(unsigned short __n)
{
#ifndef _LIBCPP_NO_EXCEPTIONS
try
{
#endif // _LIBCPP_NO_EXCEPTIONS
sentry __s(*this);
if (__s)
{
typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp;
const _Fp& __f = use_facet<_Fp>(this->getloc());
if (__f.put(*this, *this, this->fill(), static_cast<unsigned long>(__n)).failed())
this->setstate(ios_base::badbit | ios_base::failbit);
}
#ifndef _LIBCPP_NO_EXCEPTIONS
}
catch (...)
{
this->__set_badbit_and_consider_rethrow();
}
#endif // _LIBCPP_NO_EXCEPTIONS
return *this;
}
template <class _CharT, class _Traits>
basic_ostream<_CharT, _Traits>&
basic_ostream<_CharT, _Traits>::operator<<(int __n)
{
#ifndef _LIBCPP_NO_EXCEPTIONS
try
{
#endif // _LIBCPP_NO_EXCEPTIONS
sentry __s(*this);
if (__s)
{
ios_base::fmtflags __flags = ios_base::flags() & ios_base::basefield;
typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp;
const _Fp& __f = use_facet<_Fp>(this->getloc());
if (__f.put(*this, *this, this->fill(),
__flags == ios_base::oct || __flags == ios_base::hex ?
static_cast<long>(static_cast<unsigned int>(__n)) :
static_cast<long>(__n)).failed())
this->setstate(ios_base::badbit | ios_base::failbit);
}
#ifndef _LIBCPP_NO_EXCEPTIONS
}
catch (...)
{
this->__set_badbit_and_consider_rethrow();
}
#endif // _LIBCPP_NO_EXCEPTIONS
return *this;
}
template <class _CharT, class _Traits>
basic_ostream<_CharT, _Traits>&
basic_ostream<_CharT, _Traits>::operator<<(unsigned int __n)
{
#ifndef _LIBCPP_NO_EXCEPTIONS
try
{
#endif // _LIBCPP_NO_EXCEPTIONS
sentry __s(*this);
if (__s)
{
typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp;
const _Fp& __f = use_facet<_Fp>(this->getloc());
if (__f.put(*this, *this, this->fill(), static_cast<unsigned long>(__n)).failed())
this->setstate(ios_base::badbit | ios_base::failbit);
}
#ifndef _LIBCPP_NO_EXCEPTIONS
}
catch (...)
{
this->__set_badbit_and_consider_rethrow();
}
#endif // _LIBCPP_NO_EXCEPTIONS
return *this;
}
template <class _CharT, class _Traits>
basic_ostream<_CharT, _Traits>&
basic_ostream<_CharT, _Traits>::operator<<(long __n)
{
#ifndef _LIBCPP_NO_EXCEPTIONS
try
{
#endif // _LIBCPP_NO_EXCEPTIONS
sentry __s(*this);
if (__s)
{
typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp;
const _Fp& __f = use_facet<_Fp>(this->getloc());
if (__f.put(*this, *this, this->fill(), __n).failed())
this->setstate(ios_base::badbit | ios_base::failbit);
}
#ifndef _LIBCPP_NO_EXCEPTIONS
}
catch (...)
{
this->__set_badbit_and_consider_rethrow();
}
#endif // _LIBCPP_NO_EXCEPTIONS
return *this;
}
template <class _CharT, class _Traits>
basic_ostream<_CharT, _Traits>&
basic_ostream<_CharT, _Traits>::operator<<(unsigned long __n)
{
#ifndef _LIBCPP_NO_EXCEPTIONS
try
{
#endif // _LIBCPP_NO_EXCEPTIONS
sentry __s(*this);
if (__s)
{
typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp;
const _Fp& __f = use_facet<_Fp>(this->getloc());
if (__f.put(*this, *this, this->fill(), __n).failed())
this->setstate(ios_base::badbit | ios_base::failbit);
}
#ifndef _LIBCPP_NO_EXCEPTIONS
}
catch (...)
{
this->__set_badbit_and_consider_rethrow();
}
#endif // _LIBCPP_NO_EXCEPTIONS
return *this;
}
template <class _CharT, class _Traits>
basic_ostream<_CharT, _Traits>&
basic_ostream<_CharT, _Traits>::operator<<(long long __n)
{
#ifndef _LIBCPP_NO_EXCEPTIONS
try
{
#endif // _LIBCPP_NO_EXCEPTIONS
sentry __s(*this);
if (__s)
{
typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp;
const _Fp& __f = use_facet<_Fp>(this->getloc());
if (__f.put(*this, *this, this->fill(), __n).failed())
this->setstate(ios_base::badbit | ios_base::failbit);
}
#ifndef _LIBCPP_NO_EXCEPTIONS
}
catch (...)
{
this->__set_badbit_and_consider_rethrow();
}
#endif // _LIBCPP_NO_EXCEPTIONS
return *this;
}
template <class _CharT, class _Traits>
basic_ostream<_CharT, _Traits>&
basic_ostream<_CharT, _Traits>::operator<<(unsigned long long __n)
{
#ifndef _LIBCPP_NO_EXCEPTIONS
try
{
#endif // _LIBCPP_NO_EXCEPTIONS
sentry __s(*this);
if (__s)
{
typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp;
const _Fp& __f = use_facet<_Fp>(this->getloc());
if (__f.put(*this, *this, this->fill(), __n).failed())
this->setstate(ios_base::badbit | ios_base::failbit);
}
#ifndef _LIBCPP_NO_EXCEPTIONS
}
catch (...)
{
this->__set_badbit_and_consider_rethrow();
}
#endif // _LIBCPP_NO_EXCEPTIONS
return *this;
}
template <class _CharT, class _Traits>
basic_ostream<_CharT, _Traits>&
basic_ostream<_CharT, _Traits>::operator<<(float __n)
{
#ifndef _LIBCPP_NO_EXCEPTIONS
try
{
#endif // _LIBCPP_NO_EXCEPTIONS
sentry __s(*this);
if (__s)
{
typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp;
const _Fp& __f = use_facet<_Fp>(this->getloc());
if (__f.put(*this, *this, this->fill(), static_cast<double>(__n)).failed())
this->setstate(ios_base::badbit | ios_base::failbit);
}
#ifndef _LIBCPP_NO_EXCEPTIONS
}
catch (...)
{
this->__set_badbit_and_consider_rethrow();
}
#endif // _LIBCPP_NO_EXCEPTIONS
return *this;
}
template <class _CharT, class _Traits>
basic_ostream<_CharT, _Traits>&
basic_ostream<_CharT, _Traits>::operator<<(double __n)
{
#ifndef _LIBCPP_NO_EXCEPTIONS
try
{
#endif // _LIBCPP_NO_EXCEPTIONS
sentry __s(*this);
if (__s)
{
typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp;
const _Fp& __f = use_facet<_Fp>(this->getloc());
if (__f.put(*this, *this, this->fill(), __n).failed())
this->setstate(ios_base::badbit | ios_base::failbit);
}
#ifndef _LIBCPP_NO_EXCEPTIONS
}
catch (...)
{
this->__set_badbit_and_consider_rethrow();
}
#endif // _LIBCPP_NO_EXCEPTIONS
return *this;
}
template <class _CharT, class _Traits>
basic_ostream<_CharT, _Traits>&
basic_ostream<_CharT, _Traits>::operator<<(long double __n)
{
#ifndef _LIBCPP_NO_EXCEPTIONS
try
{
#endif // _LIBCPP_NO_EXCEPTIONS
sentry __s(*this);
if (__s)
{
typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp;
const _Fp& __f = use_facet<_Fp>(this->getloc());
if (__f.put(*this, *this, this->fill(), __n).failed())
this->setstate(ios_base::badbit | ios_base::failbit);
}
#ifndef _LIBCPP_NO_EXCEPTIONS
}
catch (...)
{
this->__set_badbit_and_consider_rethrow();
}
#endif // _LIBCPP_NO_EXCEPTIONS
return *this;
}
template <class _CharT, class _Traits>
basic_ostream<_CharT, _Traits>&
basic_ostream<_CharT, _Traits>::operator<<(const void* __n)
{
#ifndef _LIBCPP_NO_EXCEPTIONS
try
{
#endif // _LIBCPP_NO_EXCEPTIONS
sentry __s(*this);
if (__s)
{
typedef num_put<char_type, ostreambuf_iterator<char_type, traits_type> > _Fp;
const _Fp& __f = use_facet<_Fp>(this->getloc());
if (__f.put(*this, *this, this->fill(), __n).failed())
this->setstate(ios_base::badbit | ios_base::failbit);
}
#ifndef _LIBCPP_NO_EXCEPTIONS
}
catch (...)
{
this->__set_badbit_and_consider_rethrow();
}
#endif // _LIBCPP_NO_EXCEPTIONS
return *this;
}
template<class _CharT, class _Traits>
basic_ostream<_CharT, _Traits>&
__put_character_sequence(basic_ostream<_CharT, _Traits>& __os,
const _CharT* __str, size_t __len)
{
#ifndef _LIBCPP_NO_EXCEPTIONS
try
{
#endif // _LIBCPP_NO_EXCEPTIONS
typename basic_ostream<_CharT, _Traits>::sentry __s(__os);
if (__s)
{
typedef ostreambuf_iterator<_CharT, _Traits> _Ip;
if (__pad_and_output(_Ip(__os),
__str,
(__os.flags() & ios_base::adjustfield) == ios_base::left ?
__str + __len :
__str,
__str + __len,
__os,
__os.fill()).failed())
__os.setstate(ios_base::badbit | ios_base::failbit);
}
#ifndef _LIBCPP_NO_EXCEPTIONS
}
catch (...)
{
__os.__set_badbit_and_consider_rethrow();
}
#endif // _LIBCPP_NO_EXCEPTIONS
return __os;
}
template<class _CharT, class _Traits>
basic_ostream<_CharT, _Traits>&
operator<<(basic_ostream<_CharT, _Traits>& __os, _CharT __c)
{
return _VSTD::__put_character_sequence(__os, &__c, 1);
}
template<class _CharT, class _Traits>
basic_ostream<_CharT, _Traits>&
operator<<(basic_ostream<_CharT, _Traits>& __os, char __cn)
{
#ifndef _LIBCPP_NO_EXCEPTIONS
try
{
#endif // _LIBCPP_NO_EXCEPTIONS
typename basic_ostream<_CharT, _Traits>::sentry __s(__os);
if (__s)
{
_CharT __c = __os.widen(__cn);
typedef ostreambuf_iterator<_CharT, _Traits> _Ip;
if (__pad_and_output(_Ip(__os),
&__c,
(__os.flags() & ios_base::adjustfield) == ios_base::left ?
&__c + 1 :
&__c,
&__c + 1,
__os,
__os.fill()).failed())
__os.setstate(ios_base::badbit | ios_base::failbit);
}
#ifndef _LIBCPP_NO_EXCEPTIONS
}
catch (...)
{
__os.__set_badbit_and_consider_rethrow();
}
#endif // _LIBCPP_NO_EXCEPTIONS
return __os;
}
template<class _Traits>
basic_ostream<char, _Traits>&
operator<<(basic_ostream<char, _Traits>& __os, char __c)
{
return _VSTD::__put_character_sequence(__os, &__c, 1);
}
template<class _Traits>
basic_ostream<char, _Traits>&
operator<<(basic_ostream<char, _Traits>& __os, signed char __c)
{
return _VSTD::__put_character_sequence(__os, (char *) &__c, 1);
}
template<class _Traits>
basic_ostream<char, _Traits>&
operator<<(basic_ostream<char, _Traits>& __os, unsigned char __c)
{
return _VSTD::__put_character_sequence(__os, (char *) &__c, 1);
}
template<class _CharT, class _Traits>
basic_ostream<_CharT, _Traits>&
operator<<(basic_ostream<_CharT, _Traits>& __os, const _CharT* __str)
{
return _VSTD::__put_character_sequence(__os, __str, _Traits::length(__str));
}
template<class _CharT, class _Traits>
basic_ostream<_CharT, _Traits>&
operator<<(basic_ostream<_CharT, _Traits>& __os, const char* __strn)
{
#ifndef _LIBCPP_NO_EXCEPTIONS
try
{
#endif // _LIBCPP_NO_EXCEPTIONS
typename basic_ostream<_CharT, _Traits>::sentry __s(__os);
if (__s)
{
typedef ostreambuf_iterator<_CharT, _Traits> _Ip;
size_t __len = char_traits<char>::length(__strn);
const int __bs = 100;
_CharT __wbb[__bs];
_CharT* __wb = __wbb;
unique_ptr<_CharT, void(*)(void*)> __h(0, free);
if (__len > __bs)
{
__wb = (_CharT*)malloc(__len*sizeof(_CharT));
if (__wb == 0)
__throw_bad_alloc();
__h.reset(__wb);
}
for (_CharT* __p = __wb; *__strn != '\0'; ++__strn, ++__p)
*__p = __os.widen(*__strn);
if (__pad_and_output(_Ip(__os),
__wb,
(__os.flags() & ios_base::adjustfield) == ios_base::left ?
__wb + __len :
__wb,
__wb + __len,
__os,
__os.fill()).failed())
__os.setstate(ios_base::badbit | ios_base::failbit);
}
#ifndef _LIBCPP_NO_EXCEPTIONS
}
catch (...)
{
__os.__set_badbit_and_consider_rethrow();
}
#endif // _LIBCPP_NO_EXCEPTIONS
return __os;
}
template<class _Traits>
basic_ostream<char, _Traits>&
operator<<(basic_ostream<char, _Traits>& __os, const char* __str)
{
return _VSTD::__put_character_sequence(__os, __str, _Traits::length(__str));
}
template<class _Traits>
basic_ostream<char, _Traits>&
operator<<(basic_ostream<char, _Traits>& __os, const signed char* __str)
{
const char *__s = (const char *) __str;
return _VSTD::__put_character_sequence(__os, __s, _Traits::length(__s));
}
template<class _Traits>
basic_ostream<char, _Traits>&
operator<<(basic_ostream<char, _Traits>& __os, const unsigned char* __str)
{
const char *__s = (const char *) __str;
return _VSTD::__put_character_sequence(__os, __s, _Traits::length(__s));
}
template <class _CharT, class _Traits>
basic_ostream<_CharT, _Traits>&
basic_ostream<_CharT, _Traits>::put(char_type __c)
{
#ifndef _LIBCPP_NO_EXCEPTIONS
try
{
#endif // _LIBCPP_NO_EXCEPTIONS
sentry __s(*this);
if (__s)
{
typedef ostreambuf_iterator<_CharT, _Traits> _Op;
_Op __o(*this);
*__o = __c;
if (__o.failed())
this->setstate(ios_base::badbit);
}
#ifndef _LIBCPP_NO_EXCEPTIONS
}
catch (...)
{
this->__set_badbit_and_consider_rethrow();
}
#endif // _LIBCPP_NO_EXCEPTIONS
return *this;
}
template <class _CharT, class _Traits>
basic_ostream<_CharT, _Traits>&
basic_ostream<_CharT, _Traits>::write(const char_type* __s, streamsize __n)
{
#ifndef _LIBCPP_NO_EXCEPTIONS
try
{
#endif // _LIBCPP_NO_EXCEPTIONS
sentry __sen(*this);
if (__sen && __n)
{
if (this->rdbuf()->sputn(__s, __n) != __n)
this->setstate(ios_base::badbit);
}
#ifndef _LIBCPP_NO_EXCEPTIONS
}
catch (...)
{
this->__set_badbit_and_consider_rethrow();
}
#endif // _LIBCPP_NO_EXCEPTIONS
return *this;
}
template <class _CharT, class _Traits>
basic_ostream<_CharT, _Traits>&
basic_ostream<_CharT, _Traits>::flush()
{
#ifndef _LIBCPP_NO_EXCEPTIONS
try
{
#endif // _LIBCPP_NO_EXCEPTIONS
if (this->rdbuf())
{
sentry __s(*this);
if (__s)
{
if (this->rdbuf()->pubsync() == -1)
this->setstate(ios_base::badbit);
}
}
#ifndef _LIBCPP_NO_EXCEPTIONS
}
catch (...)
{
this->__set_badbit_and_consider_rethrow();
}
#endif // _LIBCPP_NO_EXCEPTIONS
return *this;
}
template <class _CharT, class _Traits>
typename basic_ostream<_CharT, _Traits>::pos_type
basic_ostream<_CharT, _Traits>::tellp()
{
if (this->fail())
return pos_type(-1);
return this->rdbuf()->pubseekoff(0, ios_base::cur, ios_base::out);
}
template <class _CharT, class _Traits>
basic_ostream<_CharT, _Traits>&
basic_ostream<_CharT, _Traits>::seekp(pos_type __pos)
{
sentry __s(*this);
if (!this->fail())
{
if (this->rdbuf()->pubseekpos(__pos, ios_base::out) == pos_type(-1))
this->setstate(ios_base::failbit);
}
return *this;
}
template <class _CharT, class _Traits>
basic_ostream<_CharT, _Traits>&
basic_ostream<_CharT, _Traits>::seekp(off_type __off, ios_base::seekdir __dir)
{
sentry __s(*this);
if (!this->fail())
{
if (this->rdbuf()->pubseekoff(__off, __dir, ios_base::out) == pos_type(-1))
this->setstate(ios_base::failbit);
}
return *this;
}
template <class _CharT, class _Traits>
inline _LIBCPP_INLINE_VISIBILITY
basic_ostream<_CharT, _Traits>&
endl(basic_ostream<_CharT, _Traits>& __os)
{
__os.put(__os.widen('\n'));
__os.flush();
return __os;
}
template <class _CharT, class _Traits>
inline _LIBCPP_INLINE_VISIBILITY
basic_ostream<_CharT, _Traits>&
ends(basic_ostream<_CharT, _Traits>& __os)
{
__os.put(_CharT());
return __os;
}
template <class _CharT, class _Traits>
inline _LIBCPP_INLINE_VISIBILITY
basic_ostream<_CharT, _Traits>&
flush(basic_ostream<_CharT, _Traits>& __os)
{
__os.flush();
return __os;
}
#ifndef _LIBCPP_CXX03_LANG
template <class _Stream, class _Tp>
inline _LIBCPP_INLINE_VISIBILITY
typename enable_if
<
!is_lvalue_reference<_Stream>::value &&
is_base_of<ios_base, _Stream>::value,
_Stream&&
>::type
operator<<(_Stream&& __os, const _Tp& __x)
{
__os << __x;
return _VSTD::move(__os);
}
#endif // _LIBCPP_CXX03_LANG
template<class _CharT, class _Traits, class _Allocator>
basic_ostream<_CharT, _Traits>&
operator<<(basic_ostream<_CharT, _Traits>& __os,
const basic_string<_CharT, _Traits, _Allocator>& __str)
{
return _VSTD::__put_character_sequence(__os, __str.data(), __str.size());
}
template<class _CharT, class _Traits>
basic_ostream<_CharT, _Traits>&
operator<<(basic_ostream<_CharT, _Traits>& __os,
basic_string_view<_CharT, _Traits> __sv)
{
return _VSTD::__put_character_sequence(__os, __sv.data(), __sv.size());
}
template <class _CharT, class _Traits>
inline _LIBCPP_INLINE_VISIBILITY
basic_ostream<_CharT, _Traits>&
operator<<(basic_ostream<_CharT, _Traits>& __os, const error_code& __ec)
{
return __os << __ec.category().name() << ':' << __ec.value();
}
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)
{
return __os << __p.get();
}
template<class _CharT, class _Traits, class _Yp, class _Dp>
inline _LIBCPP_INLINE_VISIBILITY
typename enable_if
<
is_same<void, typename __void_t<decltype((declval<basic_ostream<_CharT, _Traits>&>() << declval<typename unique_ptr<_Yp, _Dp>::pointer>()))>::type>::value,
basic_ostream<_CharT, _Traits>&
>::type
operator<<(basic_ostream<_CharT, _Traits>& __os, unique_ptr<_Yp, _Dp> const& __p)
{
return __os << __p.get();
}
template <class _CharT, class _Traits, size_t _Size>
basic_ostream<_CharT, _Traits>&
operator<<(basic_ostream<_CharT, _Traits>& __os, const bitset<_Size>& __x)
{
return __os << __x.template to_string<_CharT, _Traits>
(use_facet<ctype<_CharT> >(__os.getloc()).widen('0'),
use_facet<ctype<_CharT> >(__os.getloc()).widen('1'));
}
#ifndef _LIBCPP_DO_NOT_ASSUME_STREAMS_EXPLICIT_INSTANTIATION_IN_DYLIB
_LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_ostream<char>)
_LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_ostream<wchar_t>)
#endif
_LIBCPP_END_NAMESPACE_STD
#endif // _LIBCPP_OSTREAM
| 33,003 | 1,108 | jart/cosmopolitan | false |
cosmopolitan/third_party/libcxx/locale4.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
// time_get
static
string*
init_weeks()
{
static string weeks[14];
weeks[0] = "Sunday";
weeks[1] = "Monday";
weeks[2] = "Tuesday";
weeks[3] = "Wednesday";
weeks[4] = "Thursday";
weeks[5] = "Friday";
weeks[6] = "Saturday";
weeks[7] = "Sun";
weeks[8] = "Mon";
weeks[9] = "Tue";
weeks[10] = "Wed";
weeks[11] = "Thu";
weeks[12] = "Fri";
weeks[13] = "Sat";
return weeks;
}
static
wstring*
init_wweeks()
{
static wstring weeks[14];
weeks[0] = L"Sunday";
weeks[1] = L"Monday";
weeks[2] = L"Tuesday";
weeks[3] = L"Wednesday";
weeks[4] = L"Thursday";
weeks[5] = L"Friday";
weeks[6] = L"Saturday";
weeks[7] = L"Sun";
weeks[8] = L"Mon";
weeks[9] = L"Tue";
weeks[10] = L"Wed";
weeks[11] = L"Thu";
weeks[12] = L"Fri";
weeks[13] = L"Sat";
return weeks;
}
template <>
const string*
__time_get_c_storage<char>::__weeks() const
{
static const string* weeks = init_weeks();
return weeks;
}
template <>
const wstring*
__time_get_c_storage<wchar_t>::__weeks() const
{
static const wstring* weeks = init_wweeks();
return weeks;
}
static
string*
init_months()
{
static string months[24];
months[0] = "January";
months[1] = "February";
months[2] = "March";
months[3] = "April";
months[4] = "May";
months[5] = "June";
months[6] = "July";
months[7] = "August";
months[8] = "September";
months[9] = "October";
months[10] = "November";
months[11] = "December";
months[12] = "Jan";
months[13] = "Feb";
months[14] = "Mar";
months[15] = "Apr";
months[16] = "May";
months[17] = "Jun";
months[18] = "Jul";
months[19] = "Aug";
months[20] = "Sep";
months[21] = "Oct";
months[22] = "Nov";
months[23] = "Dec";
return months;
}
static
wstring*
init_wmonths()
{
static wstring months[24];
months[0] = L"January";
months[1] = L"February";
months[2] = L"March";
months[3] = L"April";
months[4] = L"May";
months[5] = L"June";
months[6] = L"July";
months[7] = L"August";
months[8] = L"September";
months[9] = L"October";
months[10] = L"November";
months[11] = L"December";
months[12] = L"Jan";
months[13] = L"Feb";
months[14] = L"Mar";
months[15] = L"Apr";
months[16] = L"May";
months[17] = L"Jun";
months[18] = L"Jul";
months[19] = L"Aug";
months[20] = L"Sep";
months[21] = L"Oct";
months[22] = L"Nov";
months[23] = L"Dec";
return months;
}
template <>
const string*
__time_get_c_storage<char>::__months() const
{
static const string* months = init_months();
return months;
}
template <>
const wstring*
__time_get_c_storage<wchar_t>::__months() const
{
static const wstring* months = init_wmonths();
return months;
}
static
string*
init_am_pm()
{
static string am_pm[2];
am_pm[0] = "AM";
am_pm[1] = "PM";
return am_pm;
}
static
wstring*
init_wam_pm()
{
static wstring am_pm[2];
am_pm[0] = L"AM";
am_pm[1] = L"PM";
return am_pm;
}
template <>
const string*
__time_get_c_storage<char>::__am_pm() const
{
static const string* am_pm = init_am_pm();
return am_pm;
}
template <>
const wstring*
__time_get_c_storage<wchar_t>::__am_pm() const
{
static const wstring* am_pm = init_wam_pm();
return am_pm;
}
template <>
const string&
__time_get_c_storage<char>::__x() const
{
static string s("%m/%d/%y");
return s;
}
template <>
const wstring&
__time_get_c_storage<wchar_t>::__x() const
{
static wstring s(L"%m/%d/%y");
return s;
}
template <>
const string&
__time_get_c_storage<char>::__X() const
{
static string s("%H:%M:%S");
return s;
}
template <>
const wstring&
__time_get_c_storage<wchar_t>::__X() const
{
static wstring s(L"%H:%M:%S");
return s;
}
template <>
const string&
__time_get_c_storage<char>::__c() const
{
static string s("%a %b %d %H:%M:%S %Y");
return s;
}
template <>
const wstring&
__time_get_c_storage<wchar_t>::__c() const
{
static wstring s(L"%a %b %d %H:%M:%S %Y");
return s;
}
template <>
const string&
__time_get_c_storage<char>::__r() const
{
static string s("%I:%M:%S %p");
return s;
}
template <>
const wstring&
__time_get_c_storage<wchar_t>::__r() const
{
static wstring s(L"%I:%M:%S %p");
return s;
}
// time_get_byname
__time_get::__time_get(const char* nm)
: __loc_(newlocale(LC_ALL_MASK, nm, 0))
{
if (__loc_ == 0)
__throw_runtime_error("time_get_byname"
" failed to construct for " + string(nm));
}
__time_get::__time_get(const string& nm)
: __loc_(newlocale(LC_ALL_MASK, nm.c_str(), 0))
{
if (__loc_ == 0)
__throw_runtime_error("time_get_byname"
" failed to construct for " + nm);
}
__time_get::~__time_get()
{
freelocale(__loc_);
}
#if defined(__clang__)
#pragma clang diagnostic ignored "-Wmissing-field-initializers"
#endif
#if defined(__GNUG__)
#pragma GCC diagnostic ignored "-Wmissing-field-initializers"
#endif
template <>
string
__time_get_storage<char>::__analyze(char fmt, const ctype<char>& ct)
{
tm t = {0};
t.tm_sec = 59;
t.tm_min = 55;
t.tm_hour = 23;
t.tm_mday = 31;
t.tm_mon = 11;
t.tm_year = 161;
t.tm_wday = 6;
t.tm_yday = 364;
t.tm_isdst = -1;
char buf[100];
char f[3] = {0};
f[0] = '%';
f[1] = fmt;
size_t n = strftime_l(buf, countof(buf), f, &t, __loc_);
char* bb = buf;
char* be = buf + n;
string result;
while (bb != be)
{
if (ct.is(ctype_base::space, *bb))
{
result.push_back(' ');
for (++bb; bb != be && ct.is(ctype_base::space, *bb); ++bb)
;
continue;
}
char* w = bb;
ios_base::iostate err = ios_base::goodbit;
ptrdiff_t i = __scan_keyword(w, be, this->__weeks_, this->__weeks_+14,
ct, err, false)
- this->__weeks_;
if (i < 14)
{
result.push_back('%');
if (i < 7)
result.push_back('A');
else
result.push_back('a');
bb = w;
continue;
}
w = bb;
i = __scan_keyword(w, be, this->__months_, this->__months_+24,
ct, err, false)
- this->__months_;
if (i < 24)
{
result.push_back('%');
if (i < 12)
result.push_back('B');
else
result.push_back('b');
if (fmt == 'x' && ct.is(ctype_base::digit, this->__months_[i][0]))
result.back() = 'm';
bb = w;
continue;
}
if (this->__am_pm_[0].size() + this->__am_pm_[1].size() > 0)
{
w = bb;
i = __scan_keyword(w, be, this->__am_pm_, this->__am_pm_+2,
ct, err, false) - this->__am_pm_;
if (i < 2)
{
result.push_back('%');
result.push_back('p');
bb = w;
continue;
}
}
w = bb;
if (ct.is(ctype_base::digit, *bb))
{
switch(__get_up_to_n_digits(bb, be, err, ct, 4))
{
case 6:
result.push_back('%');
result.push_back('w');
break;
case 7:
result.push_back('%');
result.push_back('u');
break;
case 11:
result.push_back('%');
result.push_back('I');
break;
case 12:
result.push_back('%');
result.push_back('m');
break;
case 23:
result.push_back('%');
result.push_back('H');
break;
case 31:
result.push_back('%');
result.push_back('d');
break;
case 55:
result.push_back('%');
result.push_back('M');
break;
case 59:
result.push_back('%');
result.push_back('S');
break;
case 61:
result.push_back('%');
result.push_back('y');
break;
case 364:
result.push_back('%');
result.push_back('j');
break;
case 2061:
result.push_back('%');
result.push_back('Y');
break;
default:
for (; w != bb; ++w)
result.push_back(*w);
break;
}
continue;
}
if (*bb == '%')
{
result.push_back('%');
result.push_back('%');
++bb;
continue;
}
result.push_back(*bb);
++bb;
}
return result;
}
#if defined(__clang__)
#pragma clang diagnostic ignored "-Wmissing-braces"
#endif
template <>
wstring
__time_get_storage<wchar_t>::__analyze(char fmt, const ctype<wchar_t>& ct)
{
tm t = {0};
t.tm_sec = 59;
t.tm_min = 55;
t.tm_hour = 23;
t.tm_mday = 31;
t.tm_mon = 11;
t.tm_year = 161;
t.tm_wday = 6;
t.tm_yday = 364;
t.tm_isdst = -1;
char buf[100];
char f[3] = {0};
f[0] = '%';
f[1] = fmt;
strftime_l(buf, countof(buf), f, &t, __loc_);
wchar_t wbuf[100];
wchar_t* wbb = wbuf;
mbstate_t mb = {0};
const char* bb = buf;
size_t j = __libcpp_mbsrtowcs_l( wbb, &bb, countof(wbuf), &mb, __loc_);
if (j == size_t(-1))
__throw_runtime_error("locale not supported");
wchar_t* wbe = wbb + j;
wstring result;
while (wbb != wbe)
{
if (ct.is(ctype_base::space, *wbb))
{
result.push_back(L' ');
for (++wbb; wbb != wbe && ct.is(ctype_base::space, *wbb); ++wbb)
;
continue;
}
wchar_t* w = wbb;
ios_base::iostate err = ios_base::goodbit;
ptrdiff_t i = __scan_keyword(w, wbe, this->__weeks_, this->__weeks_+14,
ct, err, false)
- this->__weeks_;
if (i < 14)
{
result.push_back(L'%');
if (i < 7)
result.push_back(L'A');
else
result.push_back(L'a');
wbb = w;
continue;
}
w = wbb;
i = __scan_keyword(w, wbe, this->__months_, this->__months_+24,
ct, err, false)
- this->__months_;
if (i < 24)
{
result.push_back(L'%');
if (i < 12)
result.push_back(L'B');
else
result.push_back(L'b');
if (fmt == 'x' && ct.is(ctype_base::digit, this->__months_[i][0]))
result.back() = L'm';
wbb = w;
continue;
}
if (this->__am_pm_[0].size() + this->__am_pm_[1].size() > 0)
{
w = wbb;
i = __scan_keyword(w, wbe, this->__am_pm_, this->__am_pm_+2,
ct, err, false) - this->__am_pm_;
if (i < 2)
{
result.push_back(L'%');
result.push_back(L'p');
wbb = w;
continue;
}
}
w = wbb;
if (ct.is(ctype_base::digit, *wbb))
{
switch(__get_up_to_n_digits(wbb, wbe, err, ct, 4))
{
case 6:
result.push_back(L'%');
result.push_back(L'w');
break;
case 7:
result.push_back(L'%');
result.push_back(L'u');
break;
case 11:
result.push_back(L'%');
result.push_back(L'I');
break;
case 12:
result.push_back(L'%');
result.push_back(L'm');
break;
case 23:
result.push_back(L'%');
result.push_back(L'H');
break;
case 31:
result.push_back(L'%');
result.push_back(L'd');
break;
case 55:
result.push_back(L'%');
result.push_back(L'M');
break;
case 59:
result.push_back(L'%');
result.push_back(L'S');
break;
case 61:
result.push_back(L'%');
result.push_back(L'y');
break;
case 364:
result.push_back(L'%');
result.push_back(L'j');
break;
case 2061:
result.push_back(L'%');
result.push_back(L'Y');
break;
default:
for (; w != wbb; ++w)
result.push_back(*w);
break;
}
continue;
}
if (ct.narrow(*wbb, 0) == '%')
{
result.push_back(L'%');
result.push_back(L'%');
++wbb;
continue;
}
result.push_back(*wbb);
++wbb;
}
return result;
}
template <>
void
__time_get_storage<char>::init(const ctype<char>& ct)
{
tm t = {0};
char buf[100];
// __weeks_
for (int i = 0; i < 7; ++i)
{
t.tm_wday = i;
strftime_l(buf, countof(buf), "%A", &t, __loc_);
__weeks_[i] = buf;
strftime_l(buf, countof(buf), "%a", &t, __loc_);
__weeks_[i+7] = buf;
}
// __months_
for (int i = 0; i < 12; ++i)
{
t.tm_mon = i;
strftime_l(buf, countof(buf), "%B", &t, __loc_);
__months_[i] = buf;
strftime_l(buf, countof(buf), "%b", &t, __loc_);
__months_[i+12] = buf;
}
// __am_pm_
t.tm_hour = 1;
strftime_l(buf, countof(buf), "%p", &t, __loc_);
__am_pm_[0] = buf;
t.tm_hour = 13;
strftime_l(buf, countof(buf), "%p", &t, __loc_);
__am_pm_[1] = buf;
__c_ = __analyze('c', ct);
__r_ = __analyze('r', ct);
__x_ = __analyze('x', ct);
__X_ = __analyze('X', ct);
}
template <>
void
__time_get_storage<wchar_t>::init(const ctype<wchar_t>& ct)
{
tm t = {0};
char buf[100];
wchar_t wbuf[100];
wchar_t* wbe;
mbstate_t mb = {0};
// __weeks_
for (int i = 0; i < 7; ++i)
{
t.tm_wday = i;
strftime_l(buf, countof(buf), "%A", &t, __loc_);
mb = mbstate_t();
const char* bb = buf;
size_t j = __libcpp_mbsrtowcs_l(wbuf, &bb, countof(wbuf), &mb, __loc_);
if (j == size_t(-1))
__throw_runtime_error("locale not supported");
wbe = wbuf + j;
__weeks_[i].assign(wbuf, wbe);
strftime_l(buf, countof(buf), "%a", &t, __loc_);
mb = mbstate_t();
bb = buf;
j = __libcpp_mbsrtowcs_l(wbuf, &bb, countof(wbuf), &mb, __loc_);
if (j == size_t(-1))
__throw_runtime_error("locale not supported");
wbe = wbuf + j;
__weeks_[i+7].assign(wbuf, wbe);
}
// __months_
for (int i = 0; i < 12; ++i)
{
t.tm_mon = i;
strftime_l(buf, countof(buf), "%B", &t, __loc_);
mb = mbstate_t();
const char* bb = buf;
size_t j = __libcpp_mbsrtowcs_l(wbuf, &bb, countof(wbuf), &mb, __loc_);
if (j == size_t(-1))
__throw_runtime_error("locale not supported");
wbe = wbuf + j;
__months_[i].assign(wbuf, wbe);
strftime_l(buf, countof(buf), "%b", &t, __loc_);
mb = mbstate_t();
bb = buf;
j = __libcpp_mbsrtowcs_l(wbuf, &bb, countof(wbuf), &mb, __loc_);
if (j == size_t(-1))
__throw_runtime_error("locale not supported");
wbe = wbuf + j;
__months_[i+12].assign(wbuf, wbe);
}
// __am_pm_
t.tm_hour = 1;
strftime_l(buf, countof(buf), "%p", &t, __loc_);
mb = mbstate_t();
const char* bb = buf;
size_t j = __libcpp_mbsrtowcs_l(wbuf, &bb, countof(wbuf), &mb, __loc_);
if (j == size_t(-1))
__throw_runtime_error("locale not supported");
wbe = wbuf + j;
__am_pm_[0].assign(wbuf, wbe);
t.tm_hour = 13;
strftime_l(buf, countof(buf), "%p", &t, __loc_);
mb = mbstate_t();
bb = buf;
j = __libcpp_mbsrtowcs_l(wbuf, &bb, countof(wbuf), &mb, __loc_);
if (j == size_t(-1))
__throw_runtime_error("locale not supported");
wbe = wbuf + j;
__am_pm_[1].assign(wbuf, wbe);
__c_ = __analyze('c', ct);
__r_ = __analyze('r', ct);
__x_ = __analyze('x', ct);
__X_ = __analyze('X', ct);
}
template <class CharT>
struct _LIBCPP_HIDDEN __time_get_temp
: public ctype_byname<CharT>
{
explicit __time_get_temp(const char* nm)
: ctype_byname<CharT>(nm, 1) {}
explicit __time_get_temp(const string& nm)
: ctype_byname<CharT>(nm, 1) {}
};
template <>
__time_get_storage<char>::__time_get_storage(const char* __nm)
: __time_get(__nm)
{
const __time_get_temp<char> ct(__nm);
init(ct);
}
template <>
__time_get_storage<char>::__time_get_storage(const string& __nm)
: __time_get(__nm)
{
const __time_get_temp<char> ct(__nm);
init(ct);
}
template <>
__time_get_storage<wchar_t>::__time_get_storage(const char* __nm)
: __time_get(__nm)
{
const __time_get_temp<wchar_t> ct(__nm);
init(ct);
}
template <>
__time_get_storage<wchar_t>::__time_get_storage(const string& __nm)
: __time_get(__nm)
{
const __time_get_temp<wchar_t> ct(__nm);
init(ct);
}
template <>
time_base::dateorder
__time_get_storage<char>::__do_date_order() const
{
unsigned i;
for (i = 0; i < __x_.size(); ++i)
if (__x_[i] == '%')
break;
++i;
switch (__x_[i])
{
case 'y':
case 'Y':
for (++i; i < __x_.size(); ++i)
if (__x_[i] == '%')
break;
if (i == __x_.size())
break;
++i;
switch (__x_[i])
{
case 'm':
for (++i; i < __x_.size(); ++i)
if (__x_[i] == '%')
break;
if (i == __x_.size())
break;
++i;
if (__x_[i] == 'd')
return time_base::ymd;
break;
case 'd':
for (++i; i < __x_.size(); ++i)
if (__x_[i] == '%')
break;
if (i == __x_.size())
break;
++i;
if (__x_[i] == 'm')
return time_base::ydm;
break;
}
break;
case 'm':
for (++i; i < __x_.size(); ++i)
if (__x_[i] == '%')
break;
if (i == __x_.size())
break;
++i;
if (__x_[i] == 'd')
{
for (++i; i < __x_.size(); ++i)
if (__x_[i] == '%')
break;
if (i == __x_.size())
break;
++i;
if (__x_[i] == 'y' || __x_[i] == 'Y')
return time_base::mdy;
break;
}
break;
case 'd':
for (++i; i < __x_.size(); ++i)
if (__x_[i] == '%')
break;
if (i == __x_.size())
break;
++i;
if (__x_[i] == 'm')
{
for (++i; i < __x_.size(); ++i)
if (__x_[i] == '%')
break;
if (i == __x_.size())
break;
++i;
if (__x_[i] == 'y' || __x_[i] == 'Y')
return time_base::dmy;
break;
}
break;
}
return time_base::no_order;
}
template <>
time_base::dateorder
__time_get_storage<wchar_t>::__do_date_order() const
{
unsigned i;
for (i = 0; i < __x_.size(); ++i)
if (__x_[i] == L'%')
break;
++i;
switch (__x_[i])
{
case L'y':
case L'Y':
for (++i; i < __x_.size(); ++i)
if (__x_[i] == L'%')
break;
if (i == __x_.size())
break;
++i;
switch (__x_[i])
{
case L'm':
for (++i; i < __x_.size(); ++i)
if (__x_[i] == L'%')
break;
if (i == __x_.size())
break;
++i;
if (__x_[i] == L'd')
return time_base::ymd;
break;
case L'd':
for (++i; i < __x_.size(); ++i)
if (__x_[i] == L'%')
break;
if (i == __x_.size())
break;
++i;
if (__x_[i] == L'm')
return time_base::ydm;
break;
}
break;
case L'm':
for (++i; i < __x_.size(); ++i)
if (__x_[i] == L'%')
break;
if (i == __x_.size())
break;
++i;
if (__x_[i] == L'd')
{
for (++i; i < __x_.size(); ++i)
if (__x_[i] == L'%')
break;
if (i == __x_.size())
break;
++i;
if (__x_[i] == L'y' || __x_[i] == L'Y')
return time_base::mdy;
break;
}
break;
case L'd':
for (++i; i < __x_.size(); ++i)
if (__x_[i] == L'%')
break;
if (i == __x_.size())
break;
++i;
if (__x_[i] == L'm')
{
for (++i; i < __x_.size(); ++i)
if (__x_[i] == L'%')
break;
if (i == __x_.size())
break;
++i;
if (__x_[i] == L'y' || __x_[i] == L'Y')
return time_base::dmy;
break;
}
break;
}
return time_base::no_order;
}
// time_put
__time_put::__time_put(const char* nm)
: __loc_(newlocale(LC_ALL_MASK, nm, 0))
{
if (__loc_ == 0)
__throw_runtime_error("time_put_byname"
" failed to construct for " + string(nm));
}
__time_put::__time_put(const string& nm)
: __loc_(newlocale(LC_ALL_MASK, nm.c_str(), 0))
{
if (__loc_ == 0)
__throw_runtime_error("time_put_byname"
" failed to construct for " + nm);
}
__time_put::~__time_put()
{
if (__loc_ != _LIBCPP_GET_C_LOCALE)
freelocale(__loc_);
}
void
__time_put::__do_put(char* __nb, char*& __ne, const tm* __tm,
char __fmt, char __mod) const
{
char fmt[] = {'%', __fmt, __mod, 0};
if (__mod != 0)
swap(fmt[1], fmt[2]);
size_t n = strftime_l(__nb, countof(__nb, __ne), fmt, __tm, __loc_);
__ne = __nb + n;
}
void
__time_put::__do_put(wchar_t* __wb, wchar_t*& __we, const tm* __tm,
char __fmt, char __mod) const
{
char __nar[100];
char* __ne = __nar + 100;
__do_put(__nar, __ne, __tm, __fmt, __mod);
mbstate_t mb = {0};
const char* __nb = __nar;
size_t j = __libcpp_mbsrtowcs_l(__wb, &__nb, countof(__wb, __we), &mb, __loc_);
if (j == size_t(-1))
__throw_runtime_error("locale not supported");
__we = __wb + j;
}
template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS time_get<char>;
template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS time_get<wchar_t>;
template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS time_get_byname<char>;
template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS time_get_byname<wchar_t>;
template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS time_put<char>;
template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS time_put<wchar_t>;
template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS time_put_byname<char>;
template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS time_put_byname<wchar_t>;
_LIBCPP_END_NAMESPACE_STD
| 25,753 | 1,011 | jart/cosmopolitan | false |
cosmopolitan/third_party/libcxx/cctype | // -*- C++ -*-
//===---------------------------- cctype ----------------------------------===//
//
// 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_CCTYPE
#define _LIBCPP_CCTYPE
/*
cctype synopsis
namespace std
{
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);
} // std
*/
#include "third_party/libcxx/__config"
#include "third_party/libcxx/ctype.h"
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
#pragma GCC system_header
#endif
_LIBCPP_BEGIN_NAMESPACE_STD
#ifdef isalnum
#undef isalnum
#endif
#ifdef isalpha
#undef isalpha
#endif
#ifdef isblank
#undef isblank
#endif
#ifdef iscntrl
#undef iscntrl
#endif
#ifdef isdigit
#undef isdigit
#endif
#ifdef isgraph
#undef isgraph
#endif
#ifdef islower
#undef islower
#endif
#ifdef isprint
#undef isprint
#endif
#ifdef ispunct
#undef ispunct
#endif
#ifdef isspace
#undef isspace
#endif
#ifdef isupper
#undef isupper
#endif
#ifdef isxdigit
#undef isxdigit
#endif
#ifdef tolower
#undef tolower
#endif
#ifdef toupper
#undef toupper
#endif
using ::isalnum;
using ::isalpha;
using ::isblank;
using ::iscntrl;
using ::isdigit;
using ::isgraph;
using ::islower;
using ::isprint;
using ::ispunct;
using ::isspace;
using ::isupper;
using ::isxdigit;
using ::tolower;
using ::toupper;
_LIBCPP_END_NAMESPACE_STD
#endif // _LIBCPP_CCTYPE
| 1,796 | 121 | jart/cosmopolitan | false |
cosmopolitan/third_party/libcxx/cinttypes | // -*- C++ -*-
// clang-format off
//===--------------------------- cinttypes --------------------------------===//
//
// 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_CINTTYPES
#define _LIBCPP_CINTTYPES
/*
cinttypes synopsis
This entire header is C99 / C++0X
#include "third_party/libcxx/cstdint" // <cinttypes> includes <cstdint>
Macros:
PRId8
PRId16
PRId32
PRId64
PRIdLEAST8
PRIdLEAST16
PRIdLEAST32
PRIdLEAST64
PRIdFAST8
PRIdFAST16
PRIdFAST32
PRIdFAST64
PRIdMAX
PRIdPTR
PRIi8
PRIi16
PRIi32
PRIi64
PRIiLEAST8
PRIiLEAST16
PRIiLEAST32
PRIiLEAST64
PRIiFAST8
PRIiFAST16
PRIiFAST32
PRIiFAST64
PRIiMAX
PRIiPTR
PRIo8
PRIo16
PRIo32
PRIo64
PRIoLEAST8
PRIoLEAST16
PRIoLEAST32
PRIoLEAST64
PRIoFAST8
PRIoFAST16
PRIoFAST32
PRIoFAST64
PRIoMAX
PRIoPTR
PRIu8
PRIu16
PRIu32
PRIu64
PRIuLEAST8
PRIuLEAST16
PRIuLEAST32
PRIuLEAST64
PRIuFAST8
PRIuFAST16
PRIuFAST32
PRIuFAST64
PRIuMAX
PRIuPTR
PRIx8
PRIx16
PRIx32
PRIx64
PRIxLEAST8
PRIxLEAST16
PRIxLEAST32
PRIxLEAST64
PRIxFAST8
PRIxFAST16
PRIxFAST32
PRIxFAST64
PRIxMAX
PRIxPTR
PRIX8
PRIX16
PRIX32
PRIX64
PRIXLEAST8
PRIXLEAST16
PRIXLEAST32
PRIXLEAST64
PRIXFAST8
PRIXFAST16
PRIXFAST32
PRIXFAST64
PRIXMAX
PRIXPTR
SCNd8
SCNd16
SCNd32
SCNd64
SCNdLEAST8
SCNdLEAST16
SCNdLEAST32
SCNdLEAST64
SCNdFAST8
SCNdFAST16
SCNdFAST32
SCNdFAST64
SCNdMAX
SCNdPTR
SCNi8
SCNi16
SCNi32
SCNi64
SCNiLEAST8
SCNiLEAST16
SCNiLEAST32
SCNiLEAST64
SCNiFAST8
SCNiFAST16
SCNiFAST32
SCNiFAST64
SCNiMAX
SCNiPTR
SCNo8
SCNo16
SCNo32
SCNo64
SCNoLEAST8
SCNoLEAST16
SCNoLEAST32
SCNoLEAST64
SCNoFAST8
SCNoFAST16
SCNoFAST32
SCNoFAST64
SCNoMAX
SCNoPTR
SCNu8
SCNu16
SCNu32
SCNu64
SCNuLEAST8
SCNuLEAST16
SCNuLEAST32
SCNuLEAST64
SCNuFAST8
SCNuFAST16
SCNuFAST32
SCNuFAST64
SCNuMAX
SCNuPTR
SCNx8
SCNx16
SCNx32
SCNx64
SCNxLEAST8
SCNxLEAST16
SCNxLEAST32
SCNxLEAST64
SCNxFAST8
SCNxFAST16
SCNxFAST32
SCNxFAST64
SCNxMAX
SCNxPTR
namespace std
{
Types:
imaxdiv_t
intmax_t imaxabs(intmax_t j);
imaxdiv_t imaxdiv(intmax_t numer, intmax_t denom);
intmax_t strtoimax(const char* restrict nptr, char** restrict endptr, int base);
uintmax_t strtoumax(const char* restrict nptr, char** restrict endptr, int base);
intmax_t wcstoimax(const wchar_t* restrict nptr, wchar_t** restrict endptr, int base);
uintmax_t wcstoumax(const wchar_t* restrict nptr, wchar_t** restrict endptr, int base);
} // std
*/
#include "third_party/libcxx/__config"
#include "third_party/libcxx/cstdint"
#include "libc/inttypes.h"
#include "libc/fmt/conv.h"
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
#pragma GCC system_header
#endif
_LIBCPP_BEGIN_NAMESPACE_STD
using::imaxdiv_t;
using::imaxabs;
using::imaxdiv;
using::strtoimax;
using::strtoumax;
using::wcstoimax;
using::wcstoumax;
_LIBCPP_END_NAMESPACE_STD
#endif // _LIBCPP_CINTTYPES
| 3,627 | 260 | jart/cosmopolitan | false |
cosmopolitan/third_party/libcxx/math.h | // -*- C++ -*-
//===---------------------------- math.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_MATH_H
#define _LIBCPP_MATH_H
#include "third_party/libcxx/__config"
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
#pragma GCC system_header
#endif
#define _LIBCPP_STDLIB_INCLUDE_NEXT
#include "third_party/libcxx/stdlib.h"
#include "libc/isystem/math.h"
#ifdef __cplusplus
// We support including .h headers inside 'extern "C"' contexts, so switch
// back to C++ linkage before including these C++ headers.
extern "C++" {
#include "third_party/libcxx/type_traits"
#include "third_party/libcxx/limits"
/*
math.h synopsis
Macros:
HUGE_VAL
HUGE_VALF // C99
HUGE_VALL // C99
INFINITY // C99
NAN // C99
FP_INFINITE // C99
FP_NAN // C99
FP_NORMAL // C99
FP_SUBNORMAL // C99
FP_ZERO // C99
FP_FAST_FMA // C99
FP_FAST_FMAF // C99
FP_FAST_FMAL // C99
FP_ILOGB0 // C99
FP_ILOGBNAN // C99
MATH_ERRNO // C99
MATH_ERREXCEPT // C99
math_errhandling // C99
Types:
float_t // C99
double_t // C99
// C90
floating_point abs(floating_point x);
floating_point acos (arithmetic x);
float acosf(float x);
long double acosl(long double x);
floating_point asin (arithmetic x);
float asinf(float x);
long double asinl(long double x);
floating_point atan (arithmetic x);
float atanf(float x);
long double atanl(long double x);
floating_point atan2 (arithmetic y, arithmetic x);
float atan2f(float y, float x);
long double atan2l(long double y, long double x);
floating_point ceil (arithmetic x);
float ceilf(float x);
long double ceill(long double x);
floating_point cos (arithmetic x);
float cosf(float x);
long double cosl(long double x);
floating_point cosh (arithmetic x);
float coshf(float x);
long double coshl(long double x);
floating_point exp (arithmetic x);
float expf(float x);
long double expl(long double x);
floating_point fabs (arithmetic x);
float fabsf(float x);
long double fabsl(long double x);
floating_point floor (arithmetic x);
float floorf(float x);
long double floorl(long double x);
floating_point fmod (arithmetic x, arithmetic y);
float fmodf(float x, float y);
long double fmodl(long double x, long double y);
floating_point frexp (arithmetic value, int* exp);
float frexpf(float value, int* exp);
long double frexpl(long double value, int* exp);
floating_point ldexp (arithmetic value, int exp);
float ldexpf(float value, int exp);
long double ldexpl(long double value, int exp);
floating_point log (arithmetic x);
float logf(float x);
long double logl(long double x);
floating_point log10 (arithmetic x);
float log10f(float x);
long double log10l(long double x);
floating_point modf (floating_point value, floating_point* iptr);
float modff(float value, float* iptr);
long double modfl(long double value, long double* iptr);
floating_point pow (arithmetic x, arithmetic y);
float powf(float x, float y);
long double powl(long double x, long double y);
floating_point sin (arithmetic x);
float sinf(float x);
long double sinl(long double x);
floating_point sinh (arithmetic x);
float sinhf(float x);
long double sinhl(long double x);
floating_point sqrt (arithmetic x);
float sqrtf(float x);
long double sqrtl(long double x);
floating_point tan (arithmetic x);
float tanf(float x);
long double tanl(long double x);
floating_point tanh (arithmetic x);
float tanhf(float x);
long double tanhl(long double x);
// C99
bool signbit(arithmetic x);
int fpclassify(arithmetic x);
bool isfinite(arithmetic x);
bool isinf(arithmetic x);
bool isnan(arithmetic x);
bool isnormal(arithmetic x);
bool isgreater(arithmetic x, arithmetic y);
bool isgreaterequal(arithmetic x, arithmetic y);
bool isless(arithmetic x, arithmetic y);
bool islessequal(arithmetic x, arithmetic y);
bool islessgreater(arithmetic x, arithmetic y);
bool isunordered(arithmetic x, arithmetic y);
floating_point acosh (arithmetic x);
float acoshf(float x);
long double acoshl(long double x);
floating_point asinh (arithmetic x);
float asinhf(float x);
long double asinhl(long double x);
floating_point atanh (arithmetic x);
float atanhf(float x);
long double atanhl(long double x);
floating_point cbrt (arithmetic x);
float cbrtf(float x);
long double cbrtl(long double x);
floating_point copysign (arithmetic x, arithmetic y);
float copysignf(float x, float y);
long double copysignl(long double x, long double y);
floating_point erf (arithmetic x);
float erff(float x);
long double erfl(long double x);
floating_point erfc (arithmetic x);
float erfcf(float x);
long double erfcl(long double x);
floating_point exp2 (arithmetic x);
float exp2f(float x);
long double exp2l(long double x);
floating_point expm1 (arithmetic x);
float expm1f(float x);
long double expm1l(long double x);
floating_point fdim (arithmetic x, arithmetic y);
float fdimf(float x, float y);
long double fdiml(long double x, long double y);
floating_point fma (arithmetic x, arithmetic y, arithmetic z);
float fmaf(float x, float y, float z);
long double fmal(long double x, long double y, long double z);
floating_point fmax (arithmetic x, arithmetic y);
float fmaxf(float x, float y);
long double fmaxl(long double x, long double y);
floating_point fmin (arithmetic x, arithmetic y);
float fminf(float x, float y);
long double fminl(long double x, long double y);
floating_point hypot (arithmetic x, arithmetic y);
float hypotf(float x, float y);
long double hypotl(long double x, long double y);
int ilogb (arithmetic x);
int ilogbf(float x);
int ilogbl(long double x);
floating_point lgamma (arithmetic x);
float lgammaf(float x);
long double lgammal(long double x);
long long llrint (arithmetic x);
long long llrintf(float x);
long long llrintl(long double x);
long long llround (arithmetic x);
long long llroundf(float x);
long long llroundl(long double x);
floating_point log1p (arithmetic x);
float log1pf(float x);
long double log1pl(long double x);
floating_point log2 (arithmetic x);
float log2f(float x);
long double log2l(long double x);
floating_point logb (arithmetic x);
float logbf(float x);
long double logbl(long double x);
long lrint (arithmetic x);
long lrintf(float x);
long lrintl(long double x);
long lround (arithmetic x);
long lroundf(float x);
long lroundl(long double x);
double nan (const char* str);
float nanf(const char* str);
long double nanl(const char* str);
floating_point nearbyint (arithmetic x);
float nearbyintf(float x);
long double nearbyintl(long double x);
floating_point nextafter (arithmetic x, arithmetic y);
float nextafterf(float x, float y);
long double nextafterl(long double x, long double y);
floating_point nexttoward (arithmetic x, long double y);
float nexttowardf(float x, long double y);
long double nexttowardl(long double x, long double y);
floating_point remainder (arithmetic x, arithmetic y);
float remainderf(float x, float y);
long double remainderl(long double x, long double y);
floating_point remquo (arithmetic x, arithmetic y, int* pquo);
float remquof(float x, float y, int* pquo);
long double remquol(long double x, long double y, int* pquo);
floating_point rint (arithmetic x);
float rintf(float x);
long double rintl(long double x);
floating_point round (arithmetic x);
float roundf(float x);
long double roundl(long double x);
floating_point scalbln (arithmetic x, long ex);
float scalblnf(float x, long ex);
long double scalblnl(long double x, long ex);
floating_point scalbn (arithmetic x, int ex);
float scalbnf(float x, int ex);
long double scalbnl(long double x, int ex);
floating_point tgamma (arithmetic x);
float tgammaf(float x);
long double tgammal(long double x);
floating_point trunc (arithmetic x);
float truncf(float x);
long double truncl(long double x);
*/
// signbit
#ifdef signbit
template <class _A1>
_LIBCPP_INLINE_VISIBILITY bool __libcpp_signbit(_A1 __lcpp_x) _NOEXCEPT {
return signbit(__lcpp_x);
}
#undef signbit
template <class _A1>
inline _LIBCPP_INLINE_VISIBILITY
typename std::enable_if<std::is_floating_point<_A1>::value, bool>::type
signbit(_A1 __lcpp_x) _NOEXCEPT {
return __libcpp_signbit((typename std::__promote<_A1>::type)__lcpp_x);
}
template <class _A1>
inline _LIBCPP_INLINE_VISIBILITY typename std::enable_if<
std::is_integral<_A1>::value && std::is_signed<_A1>::value, bool>::type
signbit(_A1 __lcpp_x) _NOEXCEPT {
return __lcpp_x < 0;
}
template <class _A1>
inline _LIBCPP_INLINE_VISIBILITY typename std::enable_if<
std::is_integral<_A1>::value && !std::is_signed<_A1>::value, bool>::type
signbit(_A1) _NOEXCEPT {
return false;
}
#elif defined(_LIBCPP_MSVCRT)
template <typename _A1>
inline _LIBCPP_INLINE_VISIBILITY
typename std::enable_if<std::is_floating_point<_A1>::value, bool>::type
signbit(_A1 __lcpp_x) _NOEXCEPT {
return ::signbit(static_cast<typename std::__promote<_A1>::type>(__lcpp_x));
}
template <class _A1>
inline _LIBCPP_INLINE_VISIBILITY typename std::enable_if<
std::is_integral<_A1>::value && std::is_signed<_A1>::value, bool>::type
signbit(_A1 __lcpp_x) _NOEXCEPT {
return __lcpp_x < 0;
}
template <class _A1>
inline _LIBCPP_INLINE_VISIBILITY typename std::enable_if<
std::is_integral<_A1>::value && !std::is_signed<_A1>::value, bool>::type
signbit(_A1) _NOEXCEPT {
return false;
}
#endif // signbit
// fpclassify
#ifdef fpclassify
template <class _A1>
_LIBCPP_INLINE_VISIBILITY int __libcpp_fpclassify(_A1 __lcpp_x) _NOEXCEPT {
return fpclassify(__lcpp_x);
}
#undef fpclassify
template <class _A1>
inline _LIBCPP_INLINE_VISIBILITY
typename std::enable_if<std::is_floating_point<_A1>::value, int>::type
fpclassify(_A1 __lcpp_x) _NOEXCEPT {
return __libcpp_fpclassify((typename std::__promote<_A1>::type)__lcpp_x);
}
template <class _A1>
inline _LIBCPP_INLINE_VISIBILITY
typename std::enable_if<std::is_integral<_A1>::value, int>::type
fpclassify(_A1 __lcpp_x) _NOEXCEPT {
return __lcpp_x == 0 ? FP_ZERO : FP_NORMAL;
}
#elif defined(_LIBCPP_MSVCRT)
template <typename _A1>
inline _LIBCPP_INLINE_VISIBILITY
typename std::enable_if<std::is_floating_point<_A1>::value, bool>::type
fpclassify(_A1 __lcpp_x) _NOEXCEPT {
return ::fpclassify(
static_cast<typename std::__promote<_A1>::type>(__lcpp_x));
}
template <class _A1>
inline _LIBCPP_INLINE_VISIBILITY
typename std::enable_if<std::is_integral<_A1>::value, int>::type
fpclassify(_A1 __lcpp_x) _NOEXCEPT {
return __lcpp_x == 0 ? FP_ZERO : FP_NORMAL;
}
#endif // fpclassify
// isfinite
#ifdef isfinite
template <class _A1>
_LIBCPP_INLINE_VISIBILITY bool __libcpp_isfinite(_A1 __lcpp_x) _NOEXCEPT {
return isfinite(__lcpp_x);
}
#undef isfinite
template <class _A1>
inline _LIBCPP_INLINE_VISIBILITY
typename std::enable_if<std::is_arithmetic<_A1>::value &&
std::numeric_limits<_A1>::has_infinity,
bool>::type
isfinite(_A1 __lcpp_x) _NOEXCEPT {
return __libcpp_isfinite((typename std::__promote<_A1>::type)__lcpp_x);
}
template <class _A1>
inline _LIBCPP_INLINE_VISIBILITY
typename std::enable_if<std::is_arithmetic<_A1>::value &&
!std::numeric_limits<_A1>::has_infinity,
bool>::type
isfinite(_A1) _NOEXCEPT {
return true;
}
#endif // isfinite
// isinf
#ifdef isinf
template <class _A1>
_LIBCPP_INLINE_VISIBILITY bool __libcpp_isinf(_A1 __lcpp_x) _NOEXCEPT {
return isinf(__lcpp_x);
}
#undef isinf
template <class _A1>
inline _LIBCPP_INLINE_VISIBILITY
typename std::enable_if<std::is_arithmetic<_A1>::value &&
std::numeric_limits<_A1>::has_infinity,
bool>::type
isinf(_A1 __lcpp_x) _NOEXCEPT {
return __libcpp_isinf((typename std::__promote<_A1>::type)__lcpp_x);
}
template <class _A1>
inline _LIBCPP_INLINE_VISIBILITY
typename std::enable_if<std::is_arithmetic<_A1>::value &&
!std::numeric_limits<_A1>::has_infinity,
bool>::type
isinf(_A1) _NOEXCEPT {
return false;
}
#ifdef _LIBCPP_PREFERRED_OVERLOAD
inline _LIBCPP_INLINE_VISIBILITY bool isinf(float __lcpp_x) _NOEXCEPT {
return __libcpp_isinf(__lcpp_x);
}
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_PREFERRED_OVERLOAD bool
isinf(double __lcpp_x) _NOEXCEPT {
return __libcpp_isinf(__lcpp_x);
}
inline _LIBCPP_INLINE_VISIBILITY bool isinf(long double __lcpp_x) _NOEXCEPT {
return __libcpp_isinf(__lcpp_x);
}
#endif
#endif // isinf
// isnan
#ifdef isnan
template <class _A1>
_LIBCPP_INLINE_VISIBILITY bool __libcpp_isnan(_A1 __lcpp_x) _NOEXCEPT {
return isnan(__lcpp_x);
}
#undef isnan
template <class _A1>
inline _LIBCPP_INLINE_VISIBILITY
typename std::enable_if<std::is_floating_point<_A1>::value, bool>::type
isnan(_A1 __lcpp_x) _NOEXCEPT {
return __libcpp_isnan((typename std::__promote<_A1>::type)__lcpp_x);
}
template <class _A1>
inline _LIBCPP_INLINE_VISIBILITY
typename std::enable_if<std::is_integral<_A1>::value, bool>::type
isnan(_A1) _NOEXCEPT {
return false;
}
#ifdef _LIBCPP_PREFERRED_OVERLOAD
inline _LIBCPP_INLINE_VISIBILITY bool isnan(float __lcpp_x) _NOEXCEPT {
return __libcpp_isnan(__lcpp_x);
}
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_PREFERRED_OVERLOAD bool
isnan(double __lcpp_x) _NOEXCEPT {
return __libcpp_isnan(__lcpp_x);
}
inline _LIBCPP_INLINE_VISIBILITY bool isnan(long double __lcpp_x) _NOEXCEPT {
return __libcpp_isnan(__lcpp_x);
}
#endif
#endif // isnan
// isnormal
#ifdef isnormal
template <class _A1>
_LIBCPP_INLINE_VISIBILITY bool __libcpp_isnormal(_A1 __lcpp_x) _NOEXCEPT {
return isnormal(__lcpp_x);
}
#undef isnormal
template <class _A1>
inline _LIBCPP_INLINE_VISIBILITY
typename std::enable_if<std::is_floating_point<_A1>::value, bool>::type
isnormal(_A1 __lcpp_x) _NOEXCEPT {
return __libcpp_isnormal((typename std::__promote<_A1>::type)__lcpp_x);
}
template <class _A1>
inline _LIBCPP_INLINE_VISIBILITY
typename std::enable_if<std::is_integral<_A1>::value, bool>::type
isnormal(_A1 __lcpp_x) _NOEXCEPT {
return __lcpp_x != 0;
}
#endif // isnormal
// isgreater
#ifdef isgreater
template <class _A1, class _A2>
_LIBCPP_INLINE_VISIBILITY bool __libcpp_isgreater(_A1 __lcpp_x,
_A2 __lcpp_y) _NOEXCEPT {
return isgreater(__lcpp_x, __lcpp_y);
}
#undef isgreater
template <class _A1, class _A2>
inline _LIBCPP_INLINE_VISIBILITY
typename std::enable_if<std::is_arithmetic<_A1>::value &&
std::is_arithmetic<_A2>::value,
bool>::type
isgreater(_A1 __lcpp_x, _A2 __lcpp_y) _NOEXCEPT {
typedef typename std::__promote<_A1, _A2>::type type;
return __libcpp_isgreater((type)__lcpp_x, (type)__lcpp_y);
}
#endif // isgreater
// isgreaterequal
#ifdef isgreaterequal
template <class _A1, class _A2>
_LIBCPP_INLINE_VISIBILITY bool __libcpp_isgreaterequal(_A1 __lcpp_x,
_A2 __lcpp_y) _NOEXCEPT {
return isgreaterequal(__lcpp_x, __lcpp_y);
}
#undef isgreaterequal
template <class _A1, class _A2>
inline _LIBCPP_INLINE_VISIBILITY
typename std::enable_if<std::is_arithmetic<_A1>::value &&
std::is_arithmetic<_A2>::value,
bool>::type
isgreaterequal(_A1 __lcpp_x, _A2 __lcpp_y) _NOEXCEPT {
typedef typename std::__promote<_A1, _A2>::type type;
return __libcpp_isgreaterequal((type)__lcpp_x, (type)__lcpp_y);
}
#endif // isgreaterequal
// isless
#ifdef isless
template <class _A1, class _A2>
_LIBCPP_INLINE_VISIBILITY bool __libcpp_isless(_A1 __lcpp_x,
_A2 __lcpp_y) _NOEXCEPT {
return isless(__lcpp_x, __lcpp_y);
}
#undef isless
template <class _A1, class _A2>
inline _LIBCPP_INLINE_VISIBILITY
typename std::enable_if<std::is_arithmetic<_A1>::value &&
std::is_arithmetic<_A2>::value,
bool>::type
isless(_A1 __lcpp_x, _A2 __lcpp_y) _NOEXCEPT {
typedef typename std::__promote<_A1, _A2>::type type;
return __libcpp_isless((type)__lcpp_x, (type)__lcpp_y);
}
#endif // isless
// islessequal
#ifdef islessequal
template <class _A1, class _A2>
_LIBCPP_INLINE_VISIBILITY bool __libcpp_islessequal(_A1 __lcpp_x,
_A2 __lcpp_y) _NOEXCEPT {
return islessequal(__lcpp_x, __lcpp_y);
}
#undef islessequal
template <class _A1, class _A2>
inline _LIBCPP_INLINE_VISIBILITY
typename std::enable_if<std::is_arithmetic<_A1>::value &&
std::is_arithmetic<_A2>::value,
bool>::type
islessequal(_A1 __lcpp_x, _A2 __lcpp_y) _NOEXCEPT {
typedef typename std::__promote<_A1, _A2>::type type;
return __libcpp_islessequal((type)__lcpp_x, (type)__lcpp_y);
}
#endif // islessequal
// islessgreater
#ifdef islessgreater
template <class _A1, class _A2>
_LIBCPP_INLINE_VISIBILITY bool __libcpp_islessgreater(_A1 __lcpp_x,
_A2 __lcpp_y) _NOEXCEPT {
return islessgreater(__lcpp_x, __lcpp_y);
}
#undef islessgreater
template <class _A1, class _A2>
inline _LIBCPP_INLINE_VISIBILITY
typename std::enable_if<std::is_arithmetic<_A1>::value &&
std::is_arithmetic<_A2>::value,
bool>::type
islessgreater(_A1 __lcpp_x, _A2 __lcpp_y) _NOEXCEPT {
typedef typename std::__promote<_A1, _A2>::type type;
return __libcpp_islessgreater((type)__lcpp_x, (type)__lcpp_y);
}
#endif // islessgreater
// isunordered
#ifdef isunordered
template <class _A1, class _A2>
_LIBCPP_INLINE_VISIBILITY bool __libcpp_isunordered(_A1 __lcpp_x,
_A2 __lcpp_y) _NOEXCEPT {
return isunordered(__lcpp_x, __lcpp_y);
}
#undef isunordered
template <class _A1, class _A2>
inline _LIBCPP_INLINE_VISIBILITY
typename std::enable_if<std::is_arithmetic<_A1>::value &&
std::is_arithmetic<_A2>::value,
bool>::type
isunordered(_A1 __lcpp_x, _A2 __lcpp_y) _NOEXCEPT {
typedef typename std::__promote<_A1, _A2>::type type;
return __libcpp_isunordered((type)__lcpp_x, (type)__lcpp_y);
}
#endif // isunordered
// abs
#undef abs
#undef labs
#ifndef _LIBCPP_HAS_NO_LONG_LONG
#undef llabs
#endif
// MSVCRT already has the correct prototype in <stdlib.h> if __cplusplus is defined
#if !defined(_LIBCPP_MSVCRT) && !defined(__sun__) && !defined(_AIX)
inline _LIBCPP_INLINE_VISIBILITY long abs(long __x) _NOEXCEPT {
return ::labs(__x);
}
#ifndef _LIBCPP_HAS_NO_LONG_LONG
inline _LIBCPP_INLINE_VISIBILITY long long abs(long long __x) _NOEXCEPT {
return ::llabs(__x);
}
#endif // _LIBCPP_HAS_NO_LONG_LONG
#endif // !defined(_LIBCPP_MSVCRT) && !defined(__sun__) && !defined(_AIX)
#if !(defined(_AIX) || defined(__sun__))
inline _LIBCPP_INLINE_VISIBILITY float abs(float __lcpp_x) _NOEXCEPT {
return ::fabsf(__lcpp_x);
}
inline _LIBCPP_INLINE_VISIBILITY double abs(double __lcpp_x) _NOEXCEPT {
return ::fabs(__lcpp_x);
}
inline _LIBCPP_INLINE_VISIBILITY long double
abs(long double __lcpp_x) _NOEXCEPT {
return ::fabsl(__lcpp_x);
}
#endif // !(defined(_AIX) || defined(__sun__))
// div
#undef div
#undef ldiv
#ifndef _LIBCPP_HAS_NO_LONG_LONG
#undef lldiv
#endif
// MSVCRT already has the correct prototype in <stdlib.h> if __cplusplus is defined
#if !defined(_LIBCPP_MSVCRT) && !defined(__sun__) && !defined(_AIX)
inline _LIBCPP_INLINE_VISIBILITY ldiv_t div(long __x, long __y) _NOEXCEPT {
return ::ldiv(__x, __y);
}
#ifndef _LIBCPP_HAS_NO_LONG_LONG
inline _LIBCPP_INLINE_VISIBILITY lldiv_t div(long long __x,
long long __y) _NOEXCEPT {
return ::lldiv(__x, __y);
}
#endif // _LIBCPP_HAS_NO_LONG_LONG
#endif // _LIBCPP_MSVCRT / __sun__ / _AIX
// acos
#if !(defined(_AIX) || defined(__sun__))
inline _LIBCPP_INLINE_VISIBILITY float acos(float __lcpp_x) _NOEXCEPT {
return ::acosf(__lcpp_x);
}
inline _LIBCPP_INLINE_VISIBILITY long double
acos(long double __lcpp_x) _NOEXCEPT {
return ::acosl(__lcpp_x);
}
#endif
template <class _A1>
inline _LIBCPP_INLINE_VISIBILITY
typename std::enable_if<std::is_integral<_A1>::value, double>::type
acos(_A1 __lcpp_x) _NOEXCEPT {
return ::acos((double)__lcpp_x);
}
// asin
#if !(defined(_AIX) || defined(__sun__))
inline _LIBCPP_INLINE_VISIBILITY float asin(float __lcpp_x) _NOEXCEPT {
return ::asinf(__lcpp_x);
}
inline _LIBCPP_INLINE_VISIBILITY long double
asin(long double __lcpp_x) _NOEXCEPT {
return ::asinl(__lcpp_x);
}
#endif
template <class _A1>
inline _LIBCPP_INLINE_VISIBILITY
typename std::enable_if<std::is_integral<_A1>::value, double>::type
asin(_A1 __lcpp_x) _NOEXCEPT {
return ::asin((double)__lcpp_x);
}
// atan
#if !(defined(_AIX) || defined(__sun__))
inline _LIBCPP_INLINE_VISIBILITY float atan(float __lcpp_x) _NOEXCEPT {
return ::atanf(__lcpp_x);
}
inline _LIBCPP_INLINE_VISIBILITY long double
atan(long double __lcpp_x) _NOEXCEPT {
return ::atanl(__lcpp_x);
}
#endif
template <class _A1>
inline _LIBCPP_INLINE_VISIBILITY
typename std::enable_if<std::is_integral<_A1>::value, double>::type
atan(_A1 __lcpp_x) _NOEXCEPT {
return ::atan((double)__lcpp_x);
}
// atan2
#if !(defined(_AIX) || defined(__sun__))
inline _LIBCPP_INLINE_VISIBILITY float atan2(float __lcpp_y,
float __lcpp_x) _NOEXCEPT {
return ::atan2f(__lcpp_y, __lcpp_x);
}
inline _LIBCPP_INLINE_VISIBILITY long double
atan2(long double __lcpp_y, long double __lcpp_x) _NOEXCEPT {
return ::atan2l(__lcpp_y, __lcpp_x);
}
#endif
template <class _A1, class _A2>
inline _LIBCPP_INLINE_VISIBILITY
typename std::_EnableIf<std::is_arithmetic<_A1>::value &&
std::is_arithmetic<_A2>::value,
std::__promote<_A1, _A2> >::type
atan2(_A1 __lcpp_y, _A2 __lcpp_x) _NOEXCEPT {
typedef typename std::__promote<_A1, _A2>::type __result_type;
static_assert((!(std::_IsSame<_A1, __result_type>::value &&
std::_IsSame<_A2, __result_type>::value)),
"");
return ::atan2((__result_type)__lcpp_y, (__result_type)__lcpp_x);
}
// ceil
#if !(defined(_AIX) || defined(__sun__))
inline _LIBCPP_INLINE_VISIBILITY float ceil(float __lcpp_x) _NOEXCEPT {
return ::ceilf(__lcpp_x);
}
inline _LIBCPP_INLINE_VISIBILITY long double
ceil(long double __lcpp_x) _NOEXCEPT {
return ::ceill(__lcpp_x);
}
#endif
template <class _A1>
inline _LIBCPP_INLINE_VISIBILITY
typename std::enable_if<std::is_integral<_A1>::value, double>::type
ceil(_A1 __lcpp_x) _NOEXCEPT {
return ::ceil((double)__lcpp_x);
}
// cos
#if !(defined(_AIX) || defined(__sun__))
inline _LIBCPP_INLINE_VISIBILITY float cos(float __lcpp_x) _NOEXCEPT {
return ::cosf(__lcpp_x);
}
inline _LIBCPP_INLINE_VISIBILITY long double
cos(long double __lcpp_x) _NOEXCEPT {
return ::cosl(__lcpp_x);
}
#endif
template <class _A1>
inline _LIBCPP_INLINE_VISIBILITY
typename std::enable_if<std::is_integral<_A1>::value, double>::type
cos(_A1 __lcpp_x) _NOEXCEPT {
return ::cos((double)__lcpp_x);
}
// cosh
#if !(defined(_AIX) || defined(__sun__))
inline _LIBCPP_INLINE_VISIBILITY float cosh(float __lcpp_x) _NOEXCEPT {
return ::coshf(__lcpp_x);
}
inline _LIBCPP_INLINE_VISIBILITY long double
cosh(long double __lcpp_x) _NOEXCEPT {
return ::coshl(__lcpp_x);
}
#endif
template <class _A1>
inline _LIBCPP_INLINE_VISIBILITY
typename std::enable_if<std::is_integral<_A1>::value, double>::type
cosh(_A1 __lcpp_x) _NOEXCEPT {
return ::cosh((double)__lcpp_x);
}
// exp
#if !(defined(_AIX) || defined(__sun__))
inline _LIBCPP_INLINE_VISIBILITY float exp(float __lcpp_x) _NOEXCEPT {
return ::expf(__lcpp_x);
}
inline _LIBCPP_INLINE_VISIBILITY long double
exp(long double __lcpp_x) _NOEXCEPT {
return ::expl(__lcpp_x);
}
#endif
template <class _A1>
inline _LIBCPP_INLINE_VISIBILITY
typename std::enable_if<std::is_integral<_A1>::value, double>::type
exp(_A1 __lcpp_x) _NOEXCEPT {
return ::exp((double)__lcpp_x);
}
// fabs
#if !(defined(_AIX) || defined(__sun__))
inline _LIBCPP_INLINE_VISIBILITY float fabs(float __lcpp_x) _NOEXCEPT {
return ::fabsf(__lcpp_x);
}
inline _LIBCPP_INLINE_VISIBILITY long double
fabs(long double __lcpp_x) _NOEXCEPT {
return ::fabsl(__lcpp_x);
}
#endif
template <class _A1>
inline _LIBCPP_INLINE_VISIBILITY
typename std::enable_if<std::is_integral<_A1>::value, double>::type
fabs(_A1 __lcpp_x) _NOEXCEPT {
return ::fabs((double)__lcpp_x);
}
// floor
#if !(defined(_AIX) || defined(__sun__))
inline _LIBCPP_INLINE_VISIBILITY float floor(float __lcpp_x) _NOEXCEPT {
return ::floorf(__lcpp_x);
}
inline _LIBCPP_INLINE_VISIBILITY long double
floor(long double __lcpp_x) _NOEXCEPT {
return ::floorl(__lcpp_x);
}
#endif
template <class _A1>
inline _LIBCPP_INLINE_VISIBILITY
typename std::enable_if<std::is_integral<_A1>::value, double>::type
floor(_A1 __lcpp_x) _NOEXCEPT {
return ::floor((double)__lcpp_x);
}
// fmod
#if !(defined(_AIX) || defined(__sun__))
inline _LIBCPP_INLINE_VISIBILITY float fmod(float __lcpp_x,
float __lcpp_y) _NOEXCEPT {
return ::fmodf(__lcpp_x, __lcpp_y);
}
inline _LIBCPP_INLINE_VISIBILITY long double
fmod(long double __lcpp_x, long double __lcpp_y) _NOEXCEPT {
return ::fmodl(__lcpp_x, __lcpp_y);
}
#endif
template <class _A1, class _A2>
inline _LIBCPP_INLINE_VISIBILITY
typename std::_EnableIf<std::is_arithmetic<_A1>::value &&
std::is_arithmetic<_A2>::value,
std::__promote<_A1, _A2> >::type
fmod(_A1 __lcpp_x, _A2 __lcpp_y) _NOEXCEPT {
typedef typename std::__promote<_A1, _A2>::type __result_type;
static_assert((!(std::_IsSame<_A1, __result_type>::value &&
std::_IsSame<_A2, __result_type>::value)),
"");
return ::fmod((__result_type)__lcpp_x, (__result_type)__lcpp_y);
}
// frexp
#if !(defined(_AIX) || defined(__sun__))
inline _LIBCPP_INLINE_VISIBILITY float frexp(float __lcpp_x,
int* __lcpp_e) _NOEXCEPT {
return ::frexpf(__lcpp_x, __lcpp_e);
}
inline _LIBCPP_INLINE_VISIBILITY long double frexp(long double __lcpp_x,
int* __lcpp_e) _NOEXCEPT {
return ::frexpl(__lcpp_x, __lcpp_e);
}
#endif
template <class _A1>
inline _LIBCPP_INLINE_VISIBILITY
typename std::enable_if<std::is_integral<_A1>::value, double>::type
frexp(_A1 __lcpp_x, int* __lcpp_e) _NOEXCEPT {
return ::frexp((double)__lcpp_x, __lcpp_e);
}
// ldexp
#if !(defined(_AIX) || defined(__sun__))
inline _LIBCPP_INLINE_VISIBILITY float ldexp(float __lcpp_x,
int __lcpp_e) _NOEXCEPT {
return ::ldexpf(__lcpp_x, __lcpp_e);
}
inline _LIBCPP_INLINE_VISIBILITY long double ldexp(long double __lcpp_x,
int __lcpp_e) _NOEXCEPT {
return ::ldexpl(__lcpp_x, __lcpp_e);
}
#endif
template <class _A1>
inline _LIBCPP_INLINE_VISIBILITY
typename std::enable_if<std::is_integral<_A1>::value, double>::type
ldexp(_A1 __lcpp_x, int __lcpp_e) _NOEXCEPT {
return ::ldexp((double)__lcpp_x, __lcpp_e);
}
// log
#if !(defined(_AIX) || defined(__sun__))
inline _LIBCPP_INLINE_VISIBILITY float log(float __lcpp_x) _NOEXCEPT {
return ::logf(__lcpp_x);
}
inline _LIBCPP_INLINE_VISIBILITY long double
log(long double __lcpp_x) _NOEXCEPT {
return ::logl(__lcpp_x);
}
#endif
template <class _A1>
inline _LIBCPP_INLINE_VISIBILITY
typename std::enable_if<std::is_integral<_A1>::value, double>::type
log(_A1 __lcpp_x) _NOEXCEPT {
return ::log((double)__lcpp_x);
}
// log10
#if !(defined(_AIX) || defined(__sun__))
inline _LIBCPP_INLINE_VISIBILITY float log10(float __lcpp_x) _NOEXCEPT {
return ::log10f(__lcpp_x);
}
inline _LIBCPP_INLINE_VISIBILITY long double
log10(long double __lcpp_x) _NOEXCEPT {
return ::log10l(__lcpp_x);
}
#endif
template <class _A1>
inline _LIBCPP_INLINE_VISIBILITY
typename std::enable_if<std::is_integral<_A1>::value, double>::type
log10(_A1 __lcpp_x) _NOEXCEPT {
return ::log10((double)__lcpp_x);
}
// modf
#if !(defined(_AIX) || defined(__sun__))
inline _LIBCPP_INLINE_VISIBILITY float modf(float __lcpp_x,
float* __lcpp_y) _NOEXCEPT {
return ::modff(__lcpp_x, __lcpp_y);
}
inline _LIBCPP_INLINE_VISIBILITY long double
modf(long double __lcpp_x, long double* __lcpp_y) _NOEXCEPT {
return ::modfl(__lcpp_x, __lcpp_y);
}
#endif
// pow
#if !(defined(_AIX) || defined(__sun__))
inline _LIBCPP_INLINE_VISIBILITY float pow(float __lcpp_x,
float __lcpp_y) _NOEXCEPT {
return ::powf(__lcpp_x, __lcpp_y);
}
inline _LIBCPP_INLINE_VISIBILITY long double
pow(long double __lcpp_x, long double __lcpp_y) _NOEXCEPT {
return ::powl(__lcpp_x, __lcpp_y);
}
#endif
template <class _A1, class _A2>
inline _LIBCPP_INLINE_VISIBILITY
typename std::_EnableIf<std::is_arithmetic<_A1>::value &&
std::is_arithmetic<_A2>::value,
std::__promote<_A1, _A2> >::type
pow(_A1 __lcpp_x, _A2 __lcpp_y) _NOEXCEPT {
typedef typename std::__promote<_A1, _A2>::type __result_type;
static_assert((!(std::_IsSame<_A1, __result_type>::value &&
std::_IsSame<_A2, __result_type>::value)),
"");
return ::pow((__result_type)__lcpp_x, (__result_type)__lcpp_y);
}
// sin
#if !(defined(_AIX) || defined(__sun__))
inline _LIBCPP_INLINE_VISIBILITY float sin(float __lcpp_x) _NOEXCEPT {
return ::sinf(__lcpp_x);
}
inline _LIBCPP_INLINE_VISIBILITY long double
sin(long double __lcpp_x) _NOEXCEPT {
return ::sinl(__lcpp_x);
}
#endif
template <class _A1>
inline _LIBCPP_INLINE_VISIBILITY
typename std::enable_if<std::is_integral<_A1>::value, double>::type
sin(_A1 __lcpp_x) _NOEXCEPT {
return ::sin((double)__lcpp_x);
}
// sinh
#if !(defined(_AIX) || defined(__sun__))
inline _LIBCPP_INLINE_VISIBILITY float sinh(float __lcpp_x) _NOEXCEPT {
return ::sinhf(__lcpp_x);
}
inline _LIBCPP_INLINE_VISIBILITY long double
sinh(long double __lcpp_x) _NOEXCEPT {
return ::sinhl(__lcpp_x);
}
#endif
template <class _A1>
inline _LIBCPP_INLINE_VISIBILITY
typename std::enable_if<std::is_integral<_A1>::value, double>::type
sinh(_A1 __lcpp_x) _NOEXCEPT {
return ::sinh((double)__lcpp_x);
}
// sqrt
#if !(defined(_AIX) || defined(__sun__))
inline _LIBCPP_INLINE_VISIBILITY float sqrt(float __lcpp_x) _NOEXCEPT {
return ::sqrtf(__lcpp_x);
}
inline _LIBCPP_INLINE_VISIBILITY long double
sqrt(long double __lcpp_x) _NOEXCEPT {
return ::sqrtl(__lcpp_x);
}
#endif
template <class _A1>
inline _LIBCPP_INLINE_VISIBILITY
typename std::enable_if<std::is_integral<_A1>::value, double>::type
sqrt(_A1 __lcpp_x) _NOEXCEPT {
return ::sqrt((double)__lcpp_x);
}
// tan
#if !(defined(_AIX) || defined(__sun__))
inline _LIBCPP_INLINE_VISIBILITY float tan(float __lcpp_x) _NOEXCEPT {
return ::tanf(__lcpp_x);
}
inline _LIBCPP_INLINE_VISIBILITY long double
tan(long double __lcpp_x) _NOEXCEPT {
return ::tanl(__lcpp_x);
}
#endif
template <class _A1>
inline _LIBCPP_INLINE_VISIBILITY
typename std::enable_if<std::is_integral<_A1>::value, double>::type
tan(_A1 __lcpp_x) _NOEXCEPT {
return ::tan((double)__lcpp_x);
}
// tanh
#if !(defined(_AIX) || defined(__sun__))
inline _LIBCPP_INLINE_VISIBILITY float tanh(float __lcpp_x) _NOEXCEPT {
return ::tanhf(__lcpp_x);
}
inline _LIBCPP_INLINE_VISIBILITY long double
tanh(long double __lcpp_x) _NOEXCEPT {
return ::tanhl(__lcpp_x);
}
#endif
template <class _A1>
inline _LIBCPP_INLINE_VISIBILITY
typename std::enable_if<std::is_integral<_A1>::value, double>::type
tanh(_A1 __lcpp_x) _NOEXCEPT {
return ::tanh((double)__lcpp_x);
}
// acosh
inline _LIBCPP_INLINE_VISIBILITY float acosh(float __lcpp_x) _NOEXCEPT {
return ::acoshf(__lcpp_x);
}
inline _LIBCPP_INLINE_VISIBILITY long double
acosh(long double __lcpp_x) _NOEXCEPT {
return ::acoshl(__lcpp_x);
}
template <class _A1>
inline _LIBCPP_INLINE_VISIBILITY
typename std::enable_if<std::is_integral<_A1>::value, double>::type
acosh(_A1 __lcpp_x) _NOEXCEPT {
return ::acosh((double)__lcpp_x);
}
// asinh
inline _LIBCPP_INLINE_VISIBILITY float asinh(float __lcpp_x) _NOEXCEPT {
return ::asinhf(__lcpp_x);
}
inline _LIBCPP_INLINE_VISIBILITY long double
asinh(long double __lcpp_x) _NOEXCEPT {
return ::asinhl(__lcpp_x);
}
template <class _A1>
inline _LIBCPP_INLINE_VISIBILITY
typename std::enable_if<std::is_integral<_A1>::value, double>::type
asinh(_A1 __lcpp_x) _NOEXCEPT {
return ::asinh((double)__lcpp_x);
}
// atanh
inline _LIBCPP_INLINE_VISIBILITY float atanh(float __lcpp_x) _NOEXCEPT {
return ::atanhf(__lcpp_x);
}
inline _LIBCPP_INLINE_VISIBILITY long double
atanh(long double __lcpp_x) _NOEXCEPT {
return ::atanhl(__lcpp_x);
}
template <class _A1>
inline _LIBCPP_INLINE_VISIBILITY
typename std::enable_if<std::is_integral<_A1>::value, double>::type
atanh(_A1 __lcpp_x) _NOEXCEPT {
return ::atanh((double)__lcpp_x);
}
// cbrt
inline _LIBCPP_INLINE_VISIBILITY float cbrt(float __lcpp_x) _NOEXCEPT {
return ::cbrtf(__lcpp_x);
}
inline _LIBCPP_INLINE_VISIBILITY long double
cbrt(long double __lcpp_x) _NOEXCEPT {
return ::cbrtl(__lcpp_x);
}
template <class _A1>
inline _LIBCPP_INLINE_VISIBILITY
typename std::enable_if<std::is_integral<_A1>::value, double>::type
cbrt(_A1 __lcpp_x) _NOEXCEPT {
return ::cbrt((double)__lcpp_x);
}
// copysign
inline _LIBCPP_INLINE_VISIBILITY float copysign(float __lcpp_x,
float __lcpp_y) _NOEXCEPT {
return ::copysignf(__lcpp_x, __lcpp_y);
}
inline _LIBCPP_INLINE_VISIBILITY long double
copysign(long double __lcpp_x, long double __lcpp_y) _NOEXCEPT {
return ::copysignl(__lcpp_x, __lcpp_y);
}
template <class _A1, class _A2>
inline _LIBCPP_INLINE_VISIBILITY
typename std::_EnableIf<std::is_arithmetic<_A1>::value &&
std::is_arithmetic<_A2>::value,
std::__promote<_A1, _A2> >::type
copysign(_A1 __lcpp_x, _A2 __lcpp_y) _NOEXCEPT {
typedef typename std::__promote<_A1, _A2>::type __result_type;
static_assert((!(std::_IsSame<_A1, __result_type>::value &&
std::_IsSame<_A2, __result_type>::value)),
"");
return ::copysign((__result_type)__lcpp_x, (__result_type)__lcpp_y);
}
// erf
inline _LIBCPP_INLINE_VISIBILITY float erf(float __lcpp_x) _NOEXCEPT {
return ::erff(__lcpp_x);
}
inline _LIBCPP_INLINE_VISIBILITY long double
erf(long double __lcpp_x) _NOEXCEPT {
return ::erfl(__lcpp_x);
}
template <class _A1>
inline _LIBCPP_INLINE_VISIBILITY
typename std::enable_if<std::is_integral<_A1>::value, double>::type
erf(_A1 __lcpp_x) _NOEXCEPT {
return ::erf((double)__lcpp_x);
}
// erfc
inline _LIBCPP_INLINE_VISIBILITY float erfc(float __lcpp_x) _NOEXCEPT {
return ::erfcf(__lcpp_x);
}
inline _LIBCPP_INLINE_VISIBILITY long double
erfc(long double __lcpp_x) _NOEXCEPT {
return ::erfcl(__lcpp_x);
}
template <class _A1>
inline _LIBCPP_INLINE_VISIBILITY
typename std::enable_if<std::is_integral<_A1>::value, double>::type
erfc(_A1 __lcpp_x) _NOEXCEPT {
return ::erfc((double)__lcpp_x);
}
// exp2
inline _LIBCPP_INLINE_VISIBILITY float exp2(float __lcpp_x) _NOEXCEPT {
return ::exp2f(__lcpp_x);
}
inline _LIBCPP_INLINE_VISIBILITY long double
exp2(long double __lcpp_x) _NOEXCEPT {
return ::exp2l(__lcpp_x);
}
template <class _A1>
inline _LIBCPP_INLINE_VISIBILITY
typename std::enable_if<std::is_integral<_A1>::value, double>::type
exp2(_A1 __lcpp_x) _NOEXCEPT {
return ::exp2((double)__lcpp_x);
}
// expm1
inline _LIBCPP_INLINE_VISIBILITY float expm1(float __lcpp_x) _NOEXCEPT {
return ::expm1f(__lcpp_x);
}
inline _LIBCPP_INLINE_VISIBILITY long double
expm1(long double __lcpp_x) _NOEXCEPT {
return ::expm1l(__lcpp_x);
}
template <class _A1>
inline _LIBCPP_INLINE_VISIBILITY
typename std::enable_if<std::is_integral<_A1>::value, double>::type
expm1(_A1 __lcpp_x) _NOEXCEPT {
return ::expm1((double)__lcpp_x);
}
// fdim
inline _LIBCPP_INLINE_VISIBILITY float fdim(float __lcpp_x,
float __lcpp_y) _NOEXCEPT {
return ::fdimf(__lcpp_x, __lcpp_y);
}
inline _LIBCPP_INLINE_VISIBILITY long double
fdim(long double __lcpp_x, long double __lcpp_y) _NOEXCEPT {
return ::fdiml(__lcpp_x, __lcpp_y);
}
template <class _A1, class _A2>
inline _LIBCPP_INLINE_VISIBILITY
typename std::_EnableIf<std::is_arithmetic<_A1>::value &&
std::is_arithmetic<_A2>::value,
std::__promote<_A1, _A2> >::type
fdim(_A1 __lcpp_x, _A2 __lcpp_y) _NOEXCEPT {
typedef typename std::__promote<_A1, _A2>::type __result_type;
static_assert((!(std::_IsSame<_A1, __result_type>::value &&
std::_IsSame<_A2, __result_type>::value)),
"");
return ::fdim((__result_type)__lcpp_x, (__result_type)__lcpp_y);
}
// fma
inline _LIBCPP_INLINE_VISIBILITY float fma(float __lcpp_x, float __lcpp_y,
float __lcpp_z) _NOEXCEPT {
return ::fmaf(__lcpp_x, __lcpp_y, __lcpp_z);
}
inline _LIBCPP_INLINE_VISIBILITY long double
fma(long double __lcpp_x, long double __lcpp_y,
long double __lcpp_z) _NOEXCEPT {
return ::fmal(__lcpp_x, __lcpp_y, __lcpp_z);
}
template <class _A1, class _A2, class _A3>
inline _LIBCPP_INLINE_VISIBILITY
typename std::_EnableIf<std::is_arithmetic<_A1>::value &&
std::is_arithmetic<_A2>::value &&
std::is_arithmetic<_A3>::value,
std::__promote<_A1, _A2, _A3> >::type
fma(_A1 __lcpp_x, _A2 __lcpp_y, _A3 __lcpp_z) _NOEXCEPT {
typedef typename std::__promote<_A1, _A2, _A3>::type __result_type;
static_assert((!(std::_IsSame<_A1, __result_type>::value &&
std::_IsSame<_A2, __result_type>::value &&
std::_IsSame<_A3, __result_type>::value)),
"");
return ::fma((__result_type)__lcpp_x, (__result_type)__lcpp_y,
(__result_type)__lcpp_z);
}
// fmax
inline _LIBCPP_INLINE_VISIBILITY float fmax(float __lcpp_x,
float __lcpp_y) _NOEXCEPT {
return ::fmaxf(__lcpp_x, __lcpp_y);
}
inline _LIBCPP_INLINE_VISIBILITY long double
fmax(long double __lcpp_x, long double __lcpp_y) _NOEXCEPT {
return ::fmaxl(__lcpp_x, __lcpp_y);
}
template <class _A1, class _A2>
inline _LIBCPP_INLINE_VISIBILITY
typename std::_EnableIf<std::is_arithmetic<_A1>::value &&
std::is_arithmetic<_A2>::value,
std::__promote<_A1, _A2> >::type
fmax(_A1 __lcpp_x, _A2 __lcpp_y) _NOEXCEPT {
typedef typename std::__promote<_A1, _A2>::type __result_type;
static_assert((!(std::_IsSame<_A1, __result_type>::value &&
std::_IsSame<_A2, __result_type>::value)),
"");
return ::fmax((__result_type)__lcpp_x, (__result_type)__lcpp_y);
}
// fmin
inline _LIBCPP_INLINE_VISIBILITY float fmin(float __lcpp_x,
float __lcpp_y) _NOEXCEPT {
return ::fminf(__lcpp_x, __lcpp_y);
}
inline _LIBCPP_INLINE_VISIBILITY long double
fmin(long double __lcpp_x, long double __lcpp_y) _NOEXCEPT {
return ::fminl(__lcpp_x, __lcpp_y);
}
template <class _A1, class _A2>
inline _LIBCPP_INLINE_VISIBILITY
typename std::_EnableIf<std::is_arithmetic<_A1>::value &&
std::is_arithmetic<_A2>::value,
std::__promote<_A1, _A2> >::type
fmin(_A1 __lcpp_x, _A2 __lcpp_y) _NOEXCEPT {
typedef typename std::__promote<_A1, _A2>::type __result_type;
static_assert((!(std::_IsSame<_A1, __result_type>::value &&
std::_IsSame<_A2, __result_type>::value)),
"");
return ::fmin((__result_type)__lcpp_x, (__result_type)__lcpp_y);
}
// hypot
inline _LIBCPP_INLINE_VISIBILITY float hypot(float __lcpp_x,
float __lcpp_y) _NOEXCEPT {
return ::hypotf(__lcpp_x, __lcpp_y);
}
inline _LIBCPP_INLINE_VISIBILITY long double
hypot(long double __lcpp_x, long double __lcpp_y) _NOEXCEPT {
return ::hypotl(__lcpp_x, __lcpp_y);
}
template <class _A1, class _A2>
inline _LIBCPP_INLINE_VISIBILITY
typename std::_EnableIf<std::is_arithmetic<_A1>::value &&
std::is_arithmetic<_A2>::value,
std::__promote<_A1, _A2> >::type
hypot(_A1 __lcpp_x, _A2 __lcpp_y) _NOEXCEPT {
typedef typename std::__promote<_A1, _A2>::type __result_type;
static_assert((!(std::_IsSame<_A1, __result_type>::value &&
std::_IsSame<_A2, __result_type>::value)),
"");
return ::hypot((__result_type)__lcpp_x, (__result_type)__lcpp_y);
}
// ilogb
inline _LIBCPP_INLINE_VISIBILITY int ilogb(float __lcpp_x) _NOEXCEPT {
return ::ilogbf(__lcpp_x);
}
inline _LIBCPP_INLINE_VISIBILITY int ilogb(long double __lcpp_x) _NOEXCEPT {
return ::ilogbl(__lcpp_x);
}
template <class _A1>
inline _LIBCPP_INLINE_VISIBILITY
typename std::enable_if<std::is_integral<_A1>::value, int>::type
ilogb(_A1 __lcpp_x) _NOEXCEPT {
return ::ilogb((double)__lcpp_x);
}
// lgamma
inline _LIBCPP_INLINE_VISIBILITY float lgamma(float __lcpp_x) _NOEXCEPT {
return ::lgammaf(__lcpp_x);
}
inline _LIBCPP_INLINE_VISIBILITY long double
lgamma(long double __lcpp_x) _NOEXCEPT {
return ::lgammal(__lcpp_x);
}
template <class _A1>
inline _LIBCPP_INLINE_VISIBILITY
typename std::enable_if<std::is_integral<_A1>::value, double>::type
lgamma(_A1 __lcpp_x) _NOEXCEPT {
return ::lgamma((double)__lcpp_x);
}
// llrint
inline _LIBCPP_INLINE_VISIBILITY long long llrint(float __lcpp_x) _NOEXCEPT {
return ::llrintf(__lcpp_x);
}
inline _LIBCPP_INLINE_VISIBILITY long long
llrint(long double __lcpp_x) _NOEXCEPT {
return ::llrintl(__lcpp_x);
}
template <class _A1>
inline _LIBCPP_INLINE_VISIBILITY
typename std::enable_if<std::is_integral<_A1>::value, long long>::type
llrint(_A1 __lcpp_x) _NOEXCEPT {
return ::llrint((double)__lcpp_x);
}
// llround
inline _LIBCPP_INLINE_VISIBILITY long long llround(float __lcpp_x) _NOEXCEPT {
return ::llroundf(__lcpp_x);
}
inline _LIBCPP_INLINE_VISIBILITY long long
llround(long double __lcpp_x) _NOEXCEPT {
return ::llroundl(__lcpp_x);
}
template <class _A1>
inline _LIBCPP_INLINE_VISIBILITY
typename std::enable_if<std::is_integral<_A1>::value, long long>::type
llround(_A1 __lcpp_x) _NOEXCEPT {
return ::llround((double)__lcpp_x);
}
// log1p
inline _LIBCPP_INLINE_VISIBILITY float log1p(float __lcpp_x) _NOEXCEPT {
return ::log1pf(__lcpp_x);
}
inline _LIBCPP_INLINE_VISIBILITY long double
log1p(long double __lcpp_x) _NOEXCEPT {
return ::log1pl(__lcpp_x);
}
template <class _A1>
inline _LIBCPP_INLINE_VISIBILITY
typename std::enable_if<std::is_integral<_A1>::value, double>::type
log1p(_A1 __lcpp_x) _NOEXCEPT {
return ::log1p((double)__lcpp_x);
}
// log2
inline _LIBCPP_INLINE_VISIBILITY float log2(float __lcpp_x) _NOEXCEPT {
return ::log2f(__lcpp_x);
}
inline _LIBCPP_INLINE_VISIBILITY long double
log2(long double __lcpp_x) _NOEXCEPT {
return ::log2l(__lcpp_x);
}
template <class _A1>
inline _LIBCPP_INLINE_VISIBILITY
typename std::enable_if<std::is_integral<_A1>::value, double>::type
log2(_A1 __lcpp_x) _NOEXCEPT {
return ::log2((double)__lcpp_x);
}
// logb
inline _LIBCPP_INLINE_VISIBILITY float logb(float __lcpp_x) _NOEXCEPT {
return ::logbf(__lcpp_x);
}
inline _LIBCPP_INLINE_VISIBILITY long double
logb(long double __lcpp_x) _NOEXCEPT {
return ::logbl(__lcpp_x);
}
template <class _A1>
inline _LIBCPP_INLINE_VISIBILITY
typename std::enable_if<std::is_integral<_A1>::value, double>::type
logb(_A1 __lcpp_x) _NOEXCEPT {
return ::logb((double)__lcpp_x);
}
// lrint
inline _LIBCPP_INLINE_VISIBILITY long lrint(float __lcpp_x) _NOEXCEPT {
return ::lrintf(__lcpp_x);
}
inline _LIBCPP_INLINE_VISIBILITY long lrint(long double __lcpp_x) _NOEXCEPT {
return ::lrintl(__lcpp_x);
}
template <class _A1>
inline _LIBCPP_INLINE_VISIBILITY
typename std::enable_if<std::is_integral<_A1>::value, long>::type
lrint(_A1 __lcpp_x) _NOEXCEPT {
return ::lrint((double)__lcpp_x);
}
// lround
inline _LIBCPP_INLINE_VISIBILITY long lround(float __lcpp_x) _NOEXCEPT {
return ::lroundf(__lcpp_x);
}
inline _LIBCPP_INLINE_VISIBILITY long lround(long double __lcpp_x) _NOEXCEPT {
return ::lroundl(__lcpp_x);
}
template <class _A1>
inline _LIBCPP_INLINE_VISIBILITY
typename std::enable_if<std::is_integral<_A1>::value, long>::type
lround(_A1 __lcpp_x) _NOEXCEPT {
return ::lround((double)__lcpp_x);
}
// nan
// nearbyint
inline _LIBCPP_INLINE_VISIBILITY float nearbyint(float __lcpp_x) _NOEXCEPT {
return ::nearbyintf(__lcpp_x);
}
inline _LIBCPP_INLINE_VISIBILITY long double
nearbyint(long double __lcpp_x) _NOEXCEPT {
return ::nearbyintl(__lcpp_x);
}
template <class _A1>
inline _LIBCPP_INLINE_VISIBILITY
typename std::enable_if<std::is_integral<_A1>::value, double>::type
nearbyint(_A1 __lcpp_x) _NOEXCEPT {
return ::nearbyint((double)__lcpp_x);
}
// nextafter
inline _LIBCPP_INLINE_VISIBILITY float nextafter(float __lcpp_x,
float __lcpp_y) _NOEXCEPT {
return ::nextafterf(__lcpp_x, __lcpp_y);
}
inline _LIBCPP_INLINE_VISIBILITY long double
nextafter(long double __lcpp_x, long double __lcpp_y) _NOEXCEPT {
return ::nextafterl(__lcpp_x, __lcpp_y);
}
template <class _A1, class _A2>
inline _LIBCPP_INLINE_VISIBILITY
typename std::_EnableIf<std::is_arithmetic<_A1>::value &&
std::is_arithmetic<_A2>::value,
std::__promote<_A1, _A2> >::type
nextafter(_A1 __lcpp_x, _A2 __lcpp_y) _NOEXCEPT {
typedef typename std::__promote<_A1, _A2>::type __result_type;
static_assert((!(std::_IsSame<_A1, __result_type>::value &&
std::_IsSame<_A2, __result_type>::value)),
"");
return ::nextafter((__result_type)__lcpp_x, (__result_type)__lcpp_y);
}
// nexttoward
inline _LIBCPP_INLINE_VISIBILITY float
nexttoward(float __lcpp_x, long double __lcpp_y) _NOEXCEPT {
return ::nexttowardf(__lcpp_x, __lcpp_y);
}
inline _LIBCPP_INLINE_VISIBILITY long double
nexttoward(long double __lcpp_x, long double __lcpp_y) _NOEXCEPT {
return ::nexttowardl(__lcpp_x, __lcpp_y);
}
template <class _A1>
inline _LIBCPP_INLINE_VISIBILITY
typename std::enable_if<std::is_integral<_A1>::value, double>::type
nexttoward(_A1 __lcpp_x, long double __lcpp_y) _NOEXCEPT {
return ::nexttoward((double)__lcpp_x, __lcpp_y);
}
// remainder
inline _LIBCPP_INLINE_VISIBILITY float remainder(float __lcpp_x,
float __lcpp_y) _NOEXCEPT {
return ::remainderf(__lcpp_x, __lcpp_y);
}
inline _LIBCPP_INLINE_VISIBILITY long double
remainder(long double __lcpp_x, long double __lcpp_y) _NOEXCEPT {
return ::remainderl(__lcpp_x, __lcpp_y);
}
template <class _A1, class _A2>
inline _LIBCPP_INLINE_VISIBILITY
typename std::_EnableIf<std::is_arithmetic<_A1>::value &&
std::is_arithmetic<_A2>::value,
std::__promote<_A1, _A2> >::type
remainder(_A1 __lcpp_x, _A2 __lcpp_y) _NOEXCEPT {
typedef typename std::__promote<_A1, _A2>::type __result_type;
static_assert((!(std::_IsSame<_A1, __result_type>::value &&
std::_IsSame<_A2, __result_type>::value)),
"");
return ::remainder((__result_type)__lcpp_x, (__result_type)__lcpp_y);
}
// remquo
inline _LIBCPP_INLINE_VISIBILITY float remquo(float __lcpp_x, float __lcpp_y,
int* __lcpp_z) _NOEXCEPT {
return ::remquof(__lcpp_x, __lcpp_y, __lcpp_z);
}
inline _LIBCPP_INLINE_VISIBILITY long double
remquo(long double __lcpp_x, long double __lcpp_y, int* __lcpp_z) _NOEXCEPT {
return ::remquol(__lcpp_x, __lcpp_y, __lcpp_z);
}
template <class _A1, class _A2>
inline _LIBCPP_INLINE_VISIBILITY
typename std::_EnableIf<std::is_arithmetic<_A1>::value &&
std::is_arithmetic<_A2>::value,
std::__promote<_A1, _A2> >::type
remquo(_A1 __lcpp_x, _A2 __lcpp_y, int* __lcpp_z) _NOEXCEPT {
typedef typename std::__promote<_A1, _A2>::type __result_type;
static_assert((!(std::_IsSame<_A1, __result_type>::value &&
std::_IsSame<_A2, __result_type>::value)),
"");
return ::remquo((__result_type)__lcpp_x, (__result_type)__lcpp_y, __lcpp_z);
}
// rint
inline _LIBCPP_INLINE_VISIBILITY float rint(float __lcpp_x) _NOEXCEPT {
return ::rintf(__lcpp_x);
}
inline _LIBCPP_INLINE_VISIBILITY long double
rint(long double __lcpp_x) _NOEXCEPT {
return ::rintl(__lcpp_x);
}
template <class _A1>
inline _LIBCPP_INLINE_VISIBILITY
typename std::enable_if<std::is_integral<_A1>::value, double>::type
rint(_A1 __lcpp_x) _NOEXCEPT {
return ::rint((double)__lcpp_x);
}
// round
inline _LIBCPP_INLINE_VISIBILITY float round(float __lcpp_x) _NOEXCEPT {
return ::roundf(__lcpp_x);
}
inline _LIBCPP_INLINE_VISIBILITY long double
round(long double __lcpp_x) _NOEXCEPT {
return ::roundl(__lcpp_x);
}
template <class _A1>
inline _LIBCPP_INLINE_VISIBILITY
typename std::enable_if<std::is_integral<_A1>::value, double>::type
round(_A1 __lcpp_x) _NOEXCEPT {
return ::round((double)__lcpp_x);
}
// scalbln
inline _LIBCPP_INLINE_VISIBILITY float scalbln(float __lcpp_x,
long __lcpp_y) _NOEXCEPT {
return ::scalblnf(__lcpp_x, __lcpp_y);
}
inline _LIBCPP_INLINE_VISIBILITY long double scalbln(long double __lcpp_x,
long __lcpp_y) _NOEXCEPT {
return ::scalblnl(__lcpp_x, __lcpp_y);
}
template <class _A1>
inline _LIBCPP_INLINE_VISIBILITY
typename std::enable_if<std::is_integral<_A1>::value, double>::type
scalbln(_A1 __lcpp_x, long __lcpp_y) _NOEXCEPT {
return ::scalbln((double)__lcpp_x, __lcpp_y);
}
// scalbn
inline _LIBCPP_INLINE_VISIBILITY float scalbn(float __lcpp_x,
int __lcpp_y) _NOEXCEPT {
return ::scalbnf(__lcpp_x, __lcpp_y);
}
inline _LIBCPP_INLINE_VISIBILITY long double scalbn(long double __lcpp_x,
int __lcpp_y) _NOEXCEPT {
return ::scalbnl(__lcpp_x, __lcpp_y);
}
template <class _A1>
inline _LIBCPP_INLINE_VISIBILITY
typename std::enable_if<std::is_integral<_A1>::value, double>::type
scalbn(_A1 __lcpp_x, int __lcpp_y) _NOEXCEPT {
return ::scalbn((double)__lcpp_x, __lcpp_y);
}
// tgamma
inline _LIBCPP_INLINE_VISIBILITY float tgamma(float __lcpp_x) _NOEXCEPT {
return ::tgammaf(__lcpp_x);
}
inline _LIBCPP_INLINE_VISIBILITY long double
tgamma(long double __lcpp_x) _NOEXCEPT {
return ::tgammal(__lcpp_x);
}
template <class _A1>
inline _LIBCPP_INLINE_VISIBILITY
typename std::enable_if<std::is_integral<_A1>::value, double>::type
tgamma(_A1 __lcpp_x) _NOEXCEPT {
return ::tgamma((double)__lcpp_x);
}
// trunc
inline _LIBCPP_INLINE_VISIBILITY float trunc(float __lcpp_x) _NOEXCEPT {
return ::truncf(__lcpp_x);
}
inline _LIBCPP_INLINE_VISIBILITY long double
trunc(long double __lcpp_x) _NOEXCEPT {
return ::truncl(__lcpp_x);
}
template <class _A1>
inline _LIBCPP_INLINE_VISIBILITY
typename std::enable_if<std::is_integral<_A1>::value, double>::type
trunc(_A1 __lcpp_x) _NOEXCEPT {
return ::trunc((double)__lcpp_x);
}
} // extern "C++"
#endif // __cplusplus
#else // _LIBCPP_MATH_H
// This include lives outside the header guard in order to support an MSVC
// extension which allows users to do:
//
// #define _USE_MATH_DEFINES
// #include <math.h>
//
// and receive the definitions of mathematical constants, even if <math.h>
// has previously been included.
#if defined(_LIBCPP_MSVCRT) && defined(_USE_MATH_DEFINES)
#include_next <math.h>
#endif
#endif // _LIBCPP_MATH_H
| 53,611 | 1,862 | jart/cosmopolitan | false |
cosmopolitan/third_party/libcxx/__functional_base_03 | // -*- 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_03
#define _LIBCPP_FUNCTIONAL_BASE_03
// manual variadic expansion for <functional>
// __invoke
template <class _Ret, class _T1, bool _IsFunc, bool _IsBase>
struct __enable_invoke_imp;
template <class _Ret, class _T1>
struct __enable_invoke_imp<_Ret, _T1, true, true> {
typedef _Ret _Bullet1;
typedef _Bullet1 type;
};
template <class _Ret, class _T1>
struct __enable_invoke_imp<_Ret, _T1, true, false> {
typedef _Ret _Bullet2;
typedef _Bullet2 type;
};
template <class _Ret, class _T1>
struct __enable_invoke_imp<_Ret, _T1, false, true> {
typedef typename add_lvalue_reference<
typename __apply_cv<_T1, _Ret>::type
>::type _Bullet3;
typedef _Bullet3 type;
};
template <class _Ret, class _T1>
struct __enable_invoke_imp<_Ret, _T1, false, false> {
typedef typename add_lvalue_reference<
typename __apply_cv<decltype(*_VSTD::declval<_T1>()), _Ret>::type
>::type _Bullet4;
typedef _Bullet4 type;
};
template <class _Ret, class _T1>
struct __enable_invoke_imp<_Ret, _T1*, false, false> {
typedef typename add_lvalue_reference<
typename __apply_cv<_T1, _Ret>::type
>::type _Bullet4;
typedef _Bullet4 type;
};
template <class _Fn, class _T1,
class _Traits = __member_pointer_traits<_Fn>,
class _Ret = typename _Traits::_ReturnType,
class _Class = typename _Traits::_ClassType>
struct __enable_invoke : __enable_invoke_imp<
_Ret, _T1,
is_member_function_pointer<_Fn>::value,
is_base_of<_Class, typename remove_reference<_T1>::type>::value>
{
};
__nat __invoke(__any, ...);
// first bullet
template <class _Fn, class _T1>
inline _LIBCPP_INLINE_VISIBILITY
typename __enable_invoke<_Fn, _T1>::_Bullet1
__invoke(_Fn __f, _T1& __t1) {
return (__t1.*__f)();
}
template <class _Fn, class _T1, class _A0>
inline _LIBCPP_INLINE_VISIBILITY
typename __enable_invoke<_Fn, _T1>::_Bullet1
__invoke(_Fn __f, _T1& __t1, _A0& __a0) {
return (__t1.*__f)(__a0);
}
template <class _Fn, class _T1, class _A0, class _A1>
inline _LIBCPP_INLINE_VISIBILITY
typename __enable_invoke<_Fn, _T1>::_Bullet1
__invoke(_Fn __f, _T1& __t1, _A0& __a0, _A1& __a1) {
return (__t1.*__f)(__a0, __a1);
}
template <class _Fn, class _T1, class _A0, class _A1, class _A2>
inline _LIBCPP_INLINE_VISIBILITY
typename __enable_invoke<_Fn, _T1>::_Bullet1
__invoke(_Fn __f, _T1& __t1, _A0& __a0, _A1& __a1, _A2& __a2) {
return (__t1.*__f)(__a0, __a1, __a2);
}
template <class _Fn, class _T1>
inline _LIBCPP_INLINE_VISIBILITY
typename __enable_invoke<_Fn, _T1>::_Bullet2
__invoke(_Fn __f, _T1& __t1) {
return ((*__t1).*__f)();
}
template <class _Fn, class _T1, class _A0>
inline _LIBCPP_INLINE_VISIBILITY
typename __enable_invoke<_Fn, _T1>::_Bullet2
__invoke(_Fn __f, _T1& __t1, _A0& __a0) {
return ((*__t1).*__f)(__a0);
}
template <class _Fn, class _T1, class _A0, class _A1>
inline _LIBCPP_INLINE_VISIBILITY
typename __enable_invoke<_Fn, _T1>::_Bullet2
__invoke(_Fn __f, _T1& __t1, _A0& __a0, _A1& __a1) {
return ((*__t1).*__f)(__a0, __a1);
}
template <class _Fn, class _T1, class _A0, class _A1, class _A2>
inline _LIBCPP_INLINE_VISIBILITY
typename __enable_invoke<_Fn, _T1>::_Bullet2
__invoke(_Fn __f, _T1& __t1, _A0& __a0, _A1& __a1, _A2& __a2) {
return ((*__t1).*__f)(__a0, __a1, __a2);
}
template <class _Fn, class _T1>
inline _LIBCPP_INLINE_VISIBILITY
typename __enable_invoke<_Fn, _T1>::_Bullet3
__invoke(_Fn __f, _T1& __t1) {
return __t1.*__f;
}
template <class _Fn, class _T1>
inline _LIBCPP_INLINE_VISIBILITY
typename __enable_invoke<_Fn, _T1>::_Bullet4
__invoke(_Fn __f, _T1& __t1) {
return (*__t1).*__f;
}
// fifth bullet
template <class _Fp>
inline _LIBCPP_INLINE_VISIBILITY
decltype(_VSTD::declval<_Fp&>()())
__invoke(_Fp& __f)
{
return __f();
}
template <class _Fp, class _A0>
inline _LIBCPP_INLINE_VISIBILITY
decltype(_VSTD::declval<_Fp&>()(_VSTD::declval<_A0&>()))
__invoke(_Fp& __f, _A0& __a0)
{
return __f(__a0);
}
template <class _Fp, class _A0, class _A1>
inline _LIBCPP_INLINE_VISIBILITY
decltype(_VSTD::declval<_Fp&>()(_VSTD::declval<_A0&>(), _VSTD::declval<_A1&>()))
__invoke(_Fp& __f, _A0& __a0, _A1& __a1)
{
return __f(__a0, __a1);
}
template <class _Fp, class _A0, class _A1, class _A2>
inline _LIBCPP_INLINE_VISIBILITY
decltype(_VSTD::declval<_Fp&>()(_VSTD::declval<_A0&>(), _VSTD::declval<_A1&>(), _VSTD::declval<_A2&>()))
__invoke(_Fp& __f, _A0& __a0, _A1& __a1, _A2& __a2)
{
return __f(__a0, __a1, __a2);
}
template <class _Fp, bool = __has_result_type<__weak_result_type<_Fp> >::value>
struct __invoke_return
{
typedef typename __weak_result_type<_Fp>::result_type type;
};
template <class _Fp>
struct __invoke_return<_Fp, false>
{
typedef decltype(__invoke(_VSTD::declval<_Fp&>())) type;
};
template <class _Tp, class _A0>
struct __invoke_return0
{
typedef decltype(__invoke(_VSTD::declval<_Tp&>(), _VSTD::declval<_A0&>())) type;
};
template <class _Rp, class _Tp, class _A0>
struct __invoke_return0<_Rp _Tp::*, _A0>
{
typedef typename __enable_invoke<_Rp _Tp::*, _A0>::type type;
};
template <class _Tp, class _A0, class _A1>
struct __invoke_return1
{
typedef decltype(__invoke(_VSTD::declval<_Tp&>(), _VSTD::declval<_A0&>(),
_VSTD::declval<_A1&>())) type;
};
template <class _Rp, class _Class, class _A0, class _A1>
struct __invoke_return1<_Rp _Class::*, _A0, _A1> {
typedef typename __enable_invoke<_Rp _Class::*, _A0>::type type;
};
template <class _Tp, class _A0, class _A1, class _A2>
struct __invoke_return2
{
typedef decltype(__invoke(_VSTD::declval<_Tp&>(), _VSTD::declval<_A0&>(),
_VSTD::declval<_A1&>(),
_VSTD::declval<_A2&>())) type;
};
template <class _Ret, class _Class, class _A0, class _A1, class _A2>
struct __invoke_return2<_Ret _Class::*, _A0, _A1, _A2> {
typedef typename __enable_invoke<_Ret _Class::*, _A0>::type type;
};
#endif // _LIBCPP_FUNCTIONAL_BASE_03
| 6,532 | 224 | 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.