Index: stable/9/Makefile.inc1 =================================================================== --- stable/9/Makefile.inc1 (revision 235797) +++ stable/9/Makefile.inc1 (revision 235798) @@ -1,1656 +1,1659 @@ # # $FreeBSD$ # # Make command line options: # -DNO_CLEANDIR run ${MAKE} clean, instead of ${MAKE} cleandir # -DNO_CLEAN do not clean at all # -DNO_SHARE do not go into share subdir # -DKERNFAST define NO_KERNEL{CONFIG,CLEAN,DEPEND,OBJ} # -DNO_KERNELCONFIG do not run config in ${MAKE} buildkernel # -DNO_KERNELCLEAN do not run ${MAKE} clean in ${MAKE} buildkernel # -DNO_KERNELDEPEND do not run ${MAKE} depend in ${MAKE} buildkernel # -DNO_KERNELOBJ do not run ${MAKE} obj in ${MAKE} buildkernel # -DNO_PORTSUPDATE do not update ports in ${MAKE} update # -DNO_DOCUPDATE do not update doc in ${MAKE} update # -DNO_WWWUPDATE do not update www in ${MAKE} update # -DNO_CTF do not run the DTrace CTF conversion tools on built objects # LOCAL_DIRS="list of dirs" to add additional dirs to the SUBDIR list # TARGET="machine" to crossbuild world for a different machine type # TARGET_ARCH= may be required when a TARGET supports multiple endians # # The intended user-driven targets are: # buildworld - rebuild *everything*, including glue to help do upgrades # installworld- install everything built by "buildworld" # doxygen - build API documentation of the kernel # update - convenient way to update your source tree (eg: cvsup/cvs) # # Standard targets (not defined here) are documented in the makefiles in # /usr/share/mk. These include: # obj depend all install clean cleandepend cleanobj # You are supposed to define both of these when calling Makefile.inc1 # directly. However, some old scripts don't. Cope for the moment, but # issue a new warning for a transition period. .if defined(TARGET) && !defined(TARGET_ARCH) .warning "You must pass both TARGET and TARGET_ARCH to Makefile.inc1. Setting TARGET_ARCH=${TARGET}." TARGET_ARCH=${TARGET} .endif .if !defined(TARGET) || !defined(TARGET_ARCH) .error "Both TARGET and TARGET_ARCH must be defined." .endif .include .include # We must do share/info early so that installation of info `dir' # entries works correctly. Do it first since it is less likely to # grow dependencies on include and lib than vice versa. # # We must do lib/ and libexec/ before bin/, because if installworld # installs a new /bin/sh, the 'make' command will *immediately* # use that new version. And the new (dynamically-linked) /bin/sh # will expect to find appropriate libraries in /lib and /libexec. # SUBDIR= share/info lib libexec SUBDIR+=bin .if ${MK_GAMES} != "no" SUBDIR+=games .endif .if ${MK_CDDL} != "no" SUBDIR+=cddl .else NO_CTF=1 .endif SUBDIR+=gnu include .if ${MK_KERBEROS} != "no" SUBDIR+=kerberos5 .endif .if ${MK_RESCUE} != "no" SUBDIR+=rescue .endif SUBDIR+=sbin .if ${MK_CRYPT} != "no" SUBDIR+=secure .endif .if !defined(NO_SHARE) SUBDIR+=share .endif SUBDIR+=sys usr.bin usr.sbin .if ${MK_OFED} != "no" SUBDIR+=contrib/ofed .endif # # We must do etc/ last for install/distribute to work. # SUBDIR+=etc # These are last, since it is nice to at least get the base system # rebuilt before you do them. .for _DIR in ${LOCAL_DIRS} .if exists(${.CURDIR}/${_DIR}/Makefile) SUBDIR+= ${_DIR} .endif .endfor .if defined(SUBDIR_OVERRIDE) SUBDIR= ${SUBDIR_OVERRIDE} .endif .if defined(NOCLEAN) NO_CLEAN= ${NOCLEAN} .endif .if defined(NO_CLEANDIR) CLEANDIR= clean cleandepend .else CLEANDIR= cleandir .endif CVS?= cvs CVSFLAGS?= -A -P -d -I! SVN?= svn SVNFLAGS?= -r HEAD SUP?= /usr/bin/csup SUPFLAGS?= -g -L 2 .if defined(SUPHOST) SUPFLAGS+= -h ${SUPHOST} .endif MAKEOBJDIRPREFIX?= /usr/obj .if !defined(OSRELDATE) .if exists(/usr/include/osreldate.h) OSRELDATE!= awk '/^\#define[[:space:]]*__FreeBSD_version/ { print $$3 }' \ /usr/include/osreldate.h .else OSRELDATE= 0 .endif .endif .if !defined(VERSION) VERSION!= uname -srp VERSION+= ${OSRELDATE} .endif KNOWN_ARCHES?= amd64 arm armeb/arm i386 i386/pc98 ia64 mipsel/mips mipseb/mips mips64el/mips mips64eb/mips mipsn32el/mips mipsn32eb/mips powerpc powerpc64/powerpc sparc64 .if ${TARGET} == ${TARGET_ARCH} _t= ${TARGET} .else _t= ${TARGET_ARCH}/${TARGET} .endif .for _t in ${_t} .if empty(KNOWN_ARCHES:M${_t}) .error Unknown target ${TARGET_ARCH}:${TARGET}. .endif .endfor .if ${TARGET} == ${MACHINE} TARGET_CPUTYPE?=${CPUTYPE} .else TARGET_CPUTYPE?= .endif .if !empty(TARGET_CPUTYPE) _TARGET_CPUTYPE=${TARGET_CPUTYPE} .else _TARGET_CPUTYPE=dummy .endif _CPUTYPE!= MAKEFLAGS= CPUTYPE=${_TARGET_CPUTYPE} ${MAKE} \ -f /dev/null -m ${.CURDIR}/share/mk -V CPUTYPE .if ${_CPUTYPE} != ${_TARGET_CPUTYPE} .error CPUTYPE global should be set with ?=. .endif .if make(buildworld) BUILD_ARCH!= uname -p .if ${MACHINE_ARCH} != ${BUILD_ARCH} .error To cross-build, set TARGET_ARCH. .endif .endif .if ${MACHINE} == ${TARGET} && ${MACHINE_ARCH} == ${TARGET_ARCH} && !defined(CROSS_BUILD_TESTING) OBJTREE= ${MAKEOBJDIRPREFIX} .else OBJTREE= ${MAKEOBJDIRPREFIX}/${TARGET}.${TARGET_ARCH} .endif WORLDTMP= ${OBJTREE}${.CURDIR}/tmp # /usr/games added for fortune which depend on strfile BPATH= ${WORLDTMP}/legacy/usr/sbin:${WORLDTMP}/legacy/usr/bin:${WORLDTMP}/legacy/usr/games XPATH= ${WORLDTMP}/usr/sbin:${WORLDTMP}/usr/bin:${WORLDTMP}/usr/games STRICTTMPPATH= ${BPATH}:${XPATH} TMPPATH= ${STRICTTMPPATH}:${PATH} # # Avoid running mktemp(1) unless actually needed. # It may not be functional, e.g., due to new ABI # when in the middle of installing over this system. # .if make(distributeworld) || make(installworld) INSTALLTMP!= /usr/bin/mktemp -d -u -t install .endif # # Building a world goes through the following stages # # 1. legacy stage [BMAKE] # This stage is responsible for creating compatibility # shims that are needed by the bootstrap-tools, # build-tools and cross-tools stages. # 1. bootstrap-tools stage [BMAKE] # This stage is responsible for creating programs that # are needed for backward compatibility reasons. They # are not built as cross-tools. # 2. build-tools stage [TMAKE] # This stage is responsible for creating the object # tree and building any tools that are needed during # the build process. # 3. cross-tools stage [XMAKE] # This stage is responsible for creating any tools that # are needed for cross-builds. A cross-compiler is one # of them. # 4. world stage [WMAKE] # This stage actually builds the world. # 5. install stage (optional) [IMAKE] # This stage installs a previously built world. # BOOTSTRAPPING?= 0 # Common environment for world related stages CROSSENV= MAKEOBJDIRPREFIX=${OBJTREE} \ MACHINE_ARCH=${TARGET_ARCH} \ MACHINE=${TARGET} \ CPUTYPE=${TARGET_CPUTYPE} .if ${OSRELDATE} < 700044 CROSSENV+= AR=gnu-ar RANLIB=gnu-ranlib .endif .if ${MK_GROFF} != "no" CROSSENV+= GROFF_BIN_PATH=${WORLDTMP}/legacy/usr/bin \ GROFF_FONT_PATH=${WORLDTMP}/legacy/usr/share/groff_font \ GROFF_TMAC_PATH=${WORLDTMP}/legacy/usr/share/tmac .endif # bootstrap-tools stage BMAKEENV= INSTALL="sh ${.CURDIR}/tools/install.sh" \ PATH=${BPATH}:${PATH} \ WORLDTMP=${WORLDTMP} \ VERSION="${VERSION}" \ MAKEFLAGS="-m ${.CURDIR}/tools/build/mk ${.MAKEFLAGS}" BMAKE= MAKEOBJDIRPREFIX=${WORLDTMP} \ ${BMAKEENV} ${MAKE} -f Makefile.inc1 \ DESTDIR= \ BOOTSTRAPPING=${OSRELDATE} \ SSP_CFLAGS= \ -DWITHOUT_HTML -DWITHOUT_INFO -DNO_LINT -DWITHOUT_MAN \ -DNO_PIC -DWITHOUT_PROFILE -DNO_SHARED \ -DNO_CPU_CFLAGS -DNO_WARNS -DNO_CTF # build-tools stage TMAKE= MAKEOBJDIRPREFIX=${OBJTREE} \ ${BMAKEENV} ${MAKE} -f Makefile.inc1 \ TARGET=${TARGET} TARGET_ARCH=${TARGET_ARCH} \ DESTDIR= \ BOOTSTRAPPING=${OSRELDATE} \ SSP_CFLAGS= \ -DNO_LINT \ -DNO_CPU_CFLAGS -DNO_WARNS -DNO_CTF # cross-tools stage XMAKE= TOOLS_PREFIX=${WORLDTMP} ${BMAKE} \ TARGET=${TARGET} TARGET_ARCH=${TARGET_ARCH} \ -DWITHOUT_GDB # world stage WMAKEENV= ${CROSSENV} \ _SHLIBDIRPREFIX=${WORLDTMP} \ _LDSCRIPTROOT= \ VERSION="${VERSION}" \ INSTALL="sh ${.CURDIR}/tools/install.sh" \ PATH=${TMPPATH} .if ${MK_CDDL} == "no" WMAKEENV+= NO_CTF=1 .endif WMAKE= ${WMAKEENV} ${MAKE} -f Makefile.inc1 DESTDIR=${WORLDTMP} .if ${TARGET_ARCH} == "amd64" || ${TARGET_ARCH} == "powerpc64" # 32 bit world LIB32TMP= ${OBJTREE}${.CURDIR}/lib32 .if ${TARGET_ARCH} == "amd64" .if empty(TARGET_CPUTYPE) LIB32CPUFLAGS= -march=i686 -mmmx -msse -msse2 .else LIB32CPUFLAGS= -march=${TARGET_CPUTYPE} .endif LIB32WMAKEENV= MACHINE=i386 MACHINE_ARCH=i386 \ MACHINE_CPU="i686 mmx sse sse2" \ LD="${LD} -m elf_i386_fbsd -Y P,${LIB32TMP}/usr/lib32" \ AS="${AS} --32" .elif ${TARGET_ARCH} == "powerpc64" .if empty(TARGET_CPUTYPE) LIB32CPUFLAGS= -mcpu=powerpc .else LIB32CPUFLAGS= -mcpu=${TARGET_CPUTYPE} .endif LIB32WMAKEENV= MACHINE=powerpc MACHINE_ARCH=powerpc \ LD="${LD} -m elf32ppc" .endif LIB32FLAGS= -m32 ${LIB32CPUFLAGS} -DCOMPAT_32BIT \ -isystem ${LIB32TMP}/usr/include/ \ -L${LIB32TMP}/usr/lib32 \ -B${LIB32TMP}/usr/lib32 # Yes, the flags are redundant. LIB32WMAKEENV+= MAKEOBJDIRPREFIX=${OBJTREE}/lib32 \ _SHLIBDIRPREFIX=${LIB32TMP} \ _LDSCRIPTROOT=${LIB32TMP} \ VERSION="${VERSION}" \ INSTALL="sh ${.CURDIR}/tools/install.sh" \ PATH=${TMPPATH} \ CC="${CC} ${LIB32FLAGS}" \ CXX="${CXX} ${LIB32FLAGS}" \ LIBDIR=/usr/lib32 \ SHLIBDIR=/usr/lib32 LIB32WMAKE= ${LIB32WMAKEENV} ${MAKE} -DNO_CPU_CFLAGS -DCOMPAT_32BIT \ -DWITHOUT_BIND -DWITHOUT_MAN -DWITHOUT_INFO \ -DWITHOUT_HTML -DNO_CTF -DNO_LINT -ECC -ECXX -EAS -ELD \ DESTDIR=${LIB32TMP} LIB32IMAKE= ${LIB32WMAKE:NINSTALL=*:NDESTDIR=*:N_LDSCRIPTROOT=*} -DNO_INCS .endif # install stage IMAKEENV= ${CROSSENV:N_LDSCRIPTROOT=*} IMAKE= ${IMAKEENV} ${MAKE} -f Makefile.inc1 .if empty(.MAKEFLAGS:M-n) IMAKEENV+= PATH=${STRICTTMPPATH}:${INSTALLTMP} \ LD_LIBRARY_PATH=${INSTALLTMP} \ PATH_LOCALE=${INSTALLTMP}/locale IMAKE+= __MAKE_SHELL=${INSTALLTMP}/sh .else IMAKEENV+= PATH=${TMPPATH}:${INSTALLTMP} .endif # kernel stage KMAKEENV= ${WMAKEENV} KMAKE= ${KMAKEENV} ${MAKE} KERNEL=${INSTKERNNAME} # # buildworld # # Attempt to rebuild the entire system, with reasonable chance of # success, regardless of how old your existing system is. # _worldtmp: .if ${.CURDIR:C/[^,]//g} != "" # The m4 build of sendmail files doesn't like it if ',' is used # anywhere in the path of it's files. @echo @echo "*** Error: path to source tree contains a comma ','" @echo false .endif @echo @echo "--------------------------------------------------------------" @echo ">>> Rebuilding the temporary build tree" @echo "--------------------------------------------------------------" .if !defined(NO_CLEAN) rm -rf ${WORLDTMP} .if defined(LIB32TMP) rm -rf ${LIB32TMP} .endif .else rm -rf ${WORLDTMP}/legacy/usr/include # XXX - These three can depend on any header file. rm -f ${OBJTREE}${.CURDIR}/usr.bin/kdump/ioctl.c rm -f ${OBJTREE}${.CURDIR}/usr.bin/kdump/kdump_subr.c rm -f ${OBJTREE}${.CURDIR}/usr.bin/truss/ioctl.c .endif .for _dir in \ lib usr legacy/usr mkdir -p ${WORLDTMP}/${_dir} .endfor mtree -deU -f ${.CURDIR}/etc/mtree/BSD.usr.dist \ -p ${WORLDTMP}/legacy/usr >/dev/null .if ${MK_GROFF} != "no" mtree -deU -f ${.CURDIR}/etc/mtree/BSD.groff.dist \ -p ${WORLDTMP}/legacy/usr >/dev/null .endif mtree -deU -f ${.CURDIR}/etc/mtree/BSD.usr.dist \ -p ${WORLDTMP}/usr >/dev/null mtree -deU -f ${.CURDIR}/etc/mtree/BSD.include.dist \ -p ${WORLDTMP}/usr/include >/dev/null ln -sf ${.CURDIR}/sys ${WORLDTMP} .if ${MK_BIND_LIBS} != "no" mtree -deU -f ${.CURDIR}/etc/mtree/BIND.include.dist \ -p ${WORLDTMP}/usr/include >/dev/null .endif _legacy: @echo @echo "--------------------------------------------------------------" @echo ">>> stage 1.1: legacy release compatibility shims" @echo "--------------------------------------------------------------" ${_+_}cd ${.CURDIR}; ${BMAKE} legacy _bootstrap-tools: @echo @echo "--------------------------------------------------------------" @echo ">>> stage 1.2: bootstrap tools" @echo "--------------------------------------------------------------" ${_+_}cd ${.CURDIR}; ${BMAKE} bootstrap-tools _cleanobj: .if !defined(NO_CLEAN) @echo @echo "--------------------------------------------------------------" @echo ">>> stage 2.1: cleaning up the object tree" @echo "--------------------------------------------------------------" ${_+_}cd ${.CURDIR}; ${WMAKE} ${CLEANDIR:S/^/par-/} .if defined(LIB32TMP) ${_+_}cd ${.CURDIR}; ${LIB32WMAKE} -f Makefile.inc1 ${CLEANDIR:S/^/par-/} .endif .endif _obj: @echo @echo "--------------------------------------------------------------" @echo ">>> stage 2.2: rebuilding the object tree" @echo "--------------------------------------------------------------" ${_+_}cd ${.CURDIR}; ${WMAKE} par-obj _build-tools: @echo @echo "--------------------------------------------------------------" @echo ">>> stage 2.3: build tools" @echo "--------------------------------------------------------------" ${_+_}cd ${.CURDIR}; ${TMAKE} build-tools _cross-tools: @echo @echo "--------------------------------------------------------------" @echo ">>> stage 3: cross tools" @echo "--------------------------------------------------------------" ${_+_}cd ${.CURDIR}; ${XMAKE} cross-tools _includes: @echo @echo "--------------------------------------------------------------" @echo ">>> stage 4.1: building includes" @echo "--------------------------------------------------------------" ${_+_}cd ${.CURDIR}; ${WMAKE} SHARED=symlinks par-includes _libraries: @echo @echo "--------------------------------------------------------------" @echo ">>> stage 4.2: building libraries" @echo "--------------------------------------------------------------" ${_+_}cd ${.CURDIR}; \ ${WMAKE} -DNO_FSCHG -DWITHOUT_HTML -DWITHOUT_INFO -DNO_LINT \ -DWITHOUT_MAN -DWITHOUT_PROFILE libraries _depend: @echo @echo "--------------------------------------------------------------" @echo ">>> stage 4.3: make dependencies" @echo "--------------------------------------------------------------" ${_+_}cd ${.CURDIR}; ${WMAKE} par-depend everything: @echo @echo "--------------------------------------------------------------" @echo ">>> stage 4.4: building everything" @echo "--------------------------------------------------------------" ${_+_}cd ${.CURDIR}; ${WMAKE} par-all .if defined(LIB32TMP) build32: @echo @echo "--------------------------------------------------------------" @echo ">>> stage 5.1: building 32 bit shim libraries" @echo "--------------------------------------------------------------" mkdir -p ${LIB32TMP}/usr/include mtree -deU -f ${.CURDIR}/etc/mtree/BSD.usr.dist \ -p ${LIB32TMP}/usr >/dev/null mtree -deU -f ${.CURDIR}/etc/mtree/BSD.include.dist \ -p ${LIB32TMP}/usr/include >/dev/null mkdir -p ${WORLDTMP} ln -sf ${.CURDIR}/sys ${WORLDTMP} .if ${MK_KERBEROS} != "no" .for _t in obj depend all cd ${.CURDIR}/kerberos5/tools; \ MAKEOBJDIRPREFIX=${OBJTREE}/lib32 ${MAKE} SSP_CFLAGS= DESTDIR= \ DIRPRFX=kerberos5/tools/ ${_t} .endfor .endif .for _t in obj includes cd ${.CURDIR}/include; ${LIB32WMAKE} DIRPRFX=include/ ${_t} cd ${.CURDIR}/lib; ${LIB32WMAKE} DIRPRFX=lib/ ${_t} .if ${MK_CDDL} != "no" cd ${.CURDIR}/cddl/lib; ${LIB32WMAKE} DIRPRFX=cddl/lib/ ${_t} .endif cd ${.CURDIR}/gnu/lib; ${LIB32WMAKE} DIRPRFX=gnu/lib/ ${_t} .if ${MK_CRYPT} != "no" cd ${.CURDIR}/secure/lib; ${LIB32WMAKE} DIRPRFX=secure/lib/ ${_t} .endif .if ${MK_KERBEROS} != "no" cd ${.CURDIR}/kerberos5/lib; ${LIB32WMAKE} DIRPRFX=kerberos5/lib ${_t} .endif .endfor .for _dir in usr.bin/lex/lib cd ${.CURDIR}/${_dir}; ${LIB32WMAKE} DIRPRFX=${_dir}/ obj .endfor .for _dir in lib/ncurses/ncurses lib/ncurses/ncursesw lib/libmagic cd ${.CURDIR}/${_dir}; \ MAKEOBJDIRPREFIX=${OBJTREE}/lib32 ${MAKE} SSP_CFLAGS= DESTDIR= \ DIRPRFX=${_dir}/ build-tools .endfor cd ${.CURDIR}; \ ${LIB32WMAKE} -f Makefile.inc1 libraries .for _t in obj depend all cd ${.CURDIR}/libexec/rtld-elf; PROG=ld-elf32.so.1 ${LIB32WMAKE} \ DIRPRFX=libexec/rtld-elf/ ${_t} cd ${.CURDIR}/usr.bin/ldd; PROG=ldd32 ${LIB32WMAKE} \ DIRPRFX=usr.bin/ldd ${_t} .endfor distribute32 install32: cd ${.CURDIR}/lib; ${LIB32IMAKE} ${.TARGET:S/32$//} .if ${MK_CDDL} != "no" cd ${.CURDIR}/cddl/lib; ${LIB32IMAKE} ${.TARGET:S/32$//} .endif cd ${.CURDIR}/gnu/lib; ${LIB32IMAKE} ${.TARGET:S/32$//} .if ${MK_CRYPT} != "no" cd ${.CURDIR}/secure/lib; ${LIB32IMAKE} ${.TARGET:S/32$//} .endif .if ${MK_KERBEROS} != "no" cd ${.CURDIR}/kerberos5/lib; ${LIB32IMAKE} ${.TARGET:S/32$//} .endif cd ${.CURDIR}/libexec/rtld-elf; \ PROG=ld-elf32.so.1 ${LIB32IMAKE} ${.TARGET:S/32$//} cd ${.CURDIR}/usr.bin/ldd; PROG=ldd32 ${LIB32IMAKE} ${.TARGET:S/32$//} .endif WMAKE_TGTS= .if !defined(SUBDIR_OVERRIDE) WMAKE_TGTS+= _worldtmp _legacy _bootstrap-tools .endif WMAKE_TGTS+= _cleanobj _obj _build-tools .if !defined(SUBDIR_OVERRIDE) WMAKE_TGTS+= _cross-tools .endif WMAKE_TGTS+= _includes _libraries _depend everything .if defined(LIB32TMP) && ${MK_LIB32} != "no" WMAKE_TGTS+= build32 .endif buildworld: buildworld_prologue ${WMAKE_TGTS} buildworld_epilogue .ORDER: buildworld_prologue ${WMAKE_TGTS} buildworld_epilogue buildworld_prologue: @echo "--------------------------------------------------------------" @echo ">>> World build started on `LC_ALL=C date`" @echo "--------------------------------------------------------------" buildworld_epilogue: @echo @echo "--------------------------------------------------------------" @echo ">>> World build completed on `LC_ALL=C date`" @echo "--------------------------------------------------------------" # # We need to have this as a target because the indirection between Makefile # and Makefile.inc1 causes the correct PATH to be used, rather than a # modification of the current environment's PATH. In addition, we need # to quote multiword values. # buildenvvars: @echo ${WMAKEENV:Q} buildenv: @echo Entering world for ${TARGET_ARCH}:${TARGET} @cd ${.CURDIR} && env ${WMAKEENV} sh || true TOOLCHAIN_TGTS= ${WMAKE_TGTS:N_depend:Neverything:Nbuild32} toolchain: ${TOOLCHAIN_TGTS} kernel-toolchain: ${TOOLCHAIN_TGTS:N_includes:N_libraries} # # installcheck # # Checks to be sure system is ready for installworld/installkernel. # installcheck: # # Require DESTDIR to be set if installing for a different architecture. # .if ${TARGET_ARCH} != ${MACHINE_ARCH} || ${TARGET} != ${MACHINE} .if !make(distributeworld) installcheck: installcheck_DESTDIR installcheck_DESTDIR: .if !defined(DESTDIR) || empty(DESTDIR) @echo "ERROR: Please set DESTDIR!"; \ false .endif .endif .endif # # Check for missing UIDs/GIDs. # CHECK_UIDS= CHECK_GIDS= audit .if ${MK_SENDMAIL} != "no" CHECK_UIDS+= smmsp CHECK_GIDS+= smmsp .endif .if ${MK_PF} != "no" CHECK_UIDS+= proxy CHECK_GIDS+= proxy authpf .endif installcheck: installcheck_UGID installcheck_UGID: .for uid in ${CHECK_UIDS} @if ! `id -u ${uid} >/dev/null 2>&1`; then \ echo "ERROR: Required ${uid} user is missing, see /usr/src/UPDATING."; \ false; \ fi .endfor .for gid in ${CHECK_GIDS} @if ! `find / -prune -group ${gid} >/dev/null 2>&1`; then \ echo "ERROR: Required ${gid} group is missing, see /usr/src/UPDATING."; \ false; \ fi .endfor # # Required install tools to be saved in a scratch dir for safety. # .if ${MK_INFO} != "no" _install-info= install-info .endif .if ${MK_ZONEINFO} != "no" _zoneinfo= zic tzsetup .endif ITOOLS= [ awk cap_mkdb cat chflags chmod chown \ date echo egrep find grep ${_install-info} \ ln lockf make mkdir mtree mv pwd_mkdb rm sed sh sysctl \ test true uname wc ${_zoneinfo} # # distributeworld # # Distributes everything compiled by a `buildworld'. # # installworld # # Installs everything compiled by a 'buildworld'. # # Non-base distributions produced by the base system EXTRA_DISTRIBUTIONS= doc games .if defined(LIB32TMP) && ${MK_LIB32} != "no" EXTRA_DISTRIBUTIONS+= lib32 .endif distributeworld installworld: installcheck mkdir -p ${INSTALLTMP} progs=$$(for prog in ${ITOOLS}; do \ if progpath=`which $$prog`; then \ echo $$progpath; \ else \ echo "Required tool $$prog not found in PATH." >&2; \ exit 1; \ fi; \ done); \ libs=$$(ldd -f "%o %p\n" -f "%o %p\n" $$progs 2>/dev/null | sort -u | \ while read line; do \ set -- $$line; \ if [ "$$2 $$3" != "not found" ]; then \ echo $$2; \ else \ echo "Required library $$1 not found." >&2; \ exit 1; \ fi; \ done); \ cp $$libs $$progs ${INSTALLTMP} cp -R $${PATH_LOCALE:-"/usr/share/locale"} ${INSTALLTMP}/locale .if make(distributeworld) .for dist in ${EXTRA_DISTRIBUTIONS} -mkdir ${DESTDIR}/${DISTDIR}/${dist} mtree -deU -f ${.CURDIR}/etc/mtree/BSD.root.dist \ -p ${DESTDIR}/${DISTDIR}/${dist} >/dev/null mtree -deU -f ${.CURDIR}/etc/mtree/BSD.usr.dist \ -p ${DESTDIR}/${DISTDIR}/${dist}/usr >/dev/null mtree -deU -f ${.CURDIR}/etc/mtree/BSD.include.dist \ -p ${DESTDIR}/${DISTDIR}/${dist}/usr/include >/dev/null .endfor -mkdir ${DESTDIR}/${DISTDIR}/base ${_+_}cd ${.CURDIR}; ${IMAKE} distrib-dirs \ DESTDIR=${DESTDIR}/${DISTDIR}/base .endif ${_+_}cd ${.CURDIR}; ${IMAKE} re${.TARGET:S/world$//}; \ ${IMAKEENV} rm -rf ${INSTALLTMP} .if make(distributeworld) .for dist in ${EXTRA_DISTRIBUTIONS} find ${DESTDIR}/${DISTDIR}/${dist} -empty -delete .endfor .endif packageworld: .for dist in base ${EXTRA_DISTRIBUTIONS} ${_+_}cd ${DESTDIR}/${DISTDIR}/${dist}; \ tar cvJf ${DESTDIR}/${DISTDIR}/${dist}.txz . .endfor # # reinstall # # If you have a build server, you can NFS mount the source and obj directories # and do a 'make reinstall' on the *client* to install new binaries from the # most recent server build. # reinstall: @echo "--------------------------------------------------------------" @echo ">>> Making hierarchy" @echo "--------------------------------------------------------------" ${_+_}cd ${.CURDIR}; ${MAKE} -f Makefile.inc1 hierarchy @echo @echo "--------------------------------------------------------------" @echo ">>> Installing everything" @echo "--------------------------------------------------------------" ${_+_}cd ${.CURDIR}; ${MAKE} -f Makefile.inc1 install .if defined(LIB32TMP) && ${MK_LIB32} != "no" ${_+_}cd ${.CURDIR}; ${MAKE} -f Makefile.inc1 install32 .endif redistribute: @echo "--------------------------------------------------------------" @echo ">>> Distributing everything" @echo "--------------------------------------------------------------" ${_+_}cd ${.CURDIR}; ${MAKE} -f Makefile.inc1 distribute .if defined(LIB32TMP) && ${MK_LIB32} != "no" ${_+_}cd ${.CURDIR}; ${MAKE} -f Makefile.inc1 distribute32 \ DISTRIBUTION=lib32 .endif distrib-dirs distribution: cd ${.CURDIR}/etc; ${CROSSENV} PATH=${TMPPATH} ${MAKE} ${.TARGET} # # buildkernel and installkernel # # Which kernels to build and/or install is specified by setting # KERNCONF. If not defined a GENERIC kernel is built/installed. # Only the existing (depending TARGET) config files are used # for building kernels and only the first of these is designated # as the one being installed. # # Note that we have to use TARGET instead of TARGET_ARCH when # we're in kernel-land. Since only TARGET_ARCH is (expected) to # be set to cross-build, we have to make sure TARGET is set # properly. .if defined(KERNFAST) NO_KERNELCLEAN= t NO_KERNELCONFIG= t NO_KERNELDEPEND= t NO_KERNELOBJ= t # Shortcut for KERNCONF=Blah -DKERNFAST is now KERNFAST=Blah .if !defined(KERNCONF) && ${KERNFAST} != "1" KERNCONF=${KERNFAST} .endif .endif .if !defined(KERNCONF) && defined(KERNEL) KERNCONF= ${KERNEL} KERNWARN= .else .if ${TARGET_ARCH} == "powerpc64" KERNCONF?= GENERIC64 .else KERNCONF?= GENERIC .endif .endif INSTKERNNAME?= kernel KERNSRCDIR?= ${.CURDIR}/sys KRNLCONFDIR= ${KERNSRCDIR}/${TARGET}/conf KRNLOBJDIR= ${OBJTREE}${KERNSRCDIR} KERNCONFDIR?= ${KRNLCONFDIR} BUILDKERNELS= INSTALLKERNEL= .for _kernel in ${KERNCONF} .if exists(${KERNCONFDIR}/${_kernel}) BUILDKERNELS+= ${_kernel} .if empty(INSTALLKERNEL) INSTALLKERNEL= ${_kernel} .endif .endif .endfor # # buildkernel # # Builds all kernels defined by BUILDKERNELS. # buildkernel: .if empty(BUILDKERNELS) @echo "ERROR: Missing kernel configuration file(s) (${KERNCONF})."; \ false .endif .if defined(KERNWARN) @echo "--------------------------------------------------------------" @echo ">>> WARNING: KERNEL= setting should be changed to KERNCONF=" @echo "--------------------------------------------------------------" @sleep 3 .endif @echo .for _kernel in ${BUILDKERNELS} @echo "--------------------------------------------------------------" @echo ">>> Kernel build for ${_kernel} started on `LC_ALL=C date`" @echo "--------------------------------------------------------------" @echo "===> ${_kernel}" mkdir -p ${KRNLOBJDIR} .if !defined(NO_KERNELCONFIG) @echo @echo "--------------------------------------------------------------" @echo ">>> stage 1: configuring the kernel" @echo "--------------------------------------------------------------" cd ${KRNLCONFDIR}; \ PATH=${TMPPATH} \ config ${CONFIGARGS} -d ${KRNLOBJDIR}/${_kernel} \ ${KERNCONFDIR}/${_kernel} .endif .if !defined(NO_CLEAN) && !defined(NO_KERNELCLEAN) @echo @echo "--------------------------------------------------------------" @echo ">>> stage 2.1: cleaning up the object tree" @echo "--------------------------------------------------------------" cd ${KRNLOBJDIR}/${_kernel}; ${KMAKE} ${CLEANDIR} .endif .if !defined(NO_KERNELOBJ) @echo @echo "--------------------------------------------------------------" @echo ">>> stage 2.2: rebuilding the object tree" @echo "--------------------------------------------------------------" cd ${KRNLOBJDIR}/${_kernel}; ${KMAKE} obj .endif @echo @echo "--------------------------------------------------------------" @echo ">>> stage 2.3: build tools" @echo "--------------------------------------------------------------" cd ${KRNLOBJDIR}/${_kernel}; \ PATH=${BPATH}:${PATH} \ MAKESRCPATH=${KERNSRCDIR}/dev/aic7xxx/aicasm \ ${MAKE} SSP_CFLAGS= -DNO_CPU_CFLAGS -DNO_CTF \ -f ${KERNSRCDIR}/dev/aic7xxx/aicasm/Makefile # XXX - Gratuitously builds aicasm in the ``makeoptions NO_MODULES'' case. .if !defined(MODULES_WITH_WORLD) && !defined(NO_MODULES) && exists(${KERNSRCDIR}/modules) .for target in obj depend all cd ${KERNSRCDIR}/modules/aic7xxx/aicasm; \ PATH=${BPATH}:${PATH} \ MAKEOBJDIRPREFIX=${KRNLOBJDIR}/${_kernel}/modules \ ${MAKE} SSP_CFLAGS= -DNO_CPU_CFLAGS -DNO_CTF ${target} .endfor .endif .if !defined(NO_KERNELDEPEND) @echo @echo "--------------------------------------------------------------" @echo ">>> stage 3.1: making dependencies" @echo "--------------------------------------------------------------" cd ${KRNLOBJDIR}/${_kernel}; ${KMAKE} depend -DNO_MODULES_OBJ .endif @echo @echo "--------------------------------------------------------------" @echo ">>> stage 3.2: building everything" @echo "--------------------------------------------------------------" cd ${KRNLOBJDIR}/${_kernel}; ${KMAKE} all -DNO_MODULES_OBJ @echo "--------------------------------------------------------------" @echo ">>> Kernel build for ${_kernel} completed on `LC_ALL=C date`" @echo "--------------------------------------------------------------" .endfor # # installkernel, etc. # # Install the kernel defined by INSTALLKERNEL # installkernel installkernel.debug \ reinstallkernel reinstallkernel.debug: installcheck .if empty(INSTALLKERNEL) @echo "ERROR: No kernel \"${KERNCONF}\" to install."; \ false .endif @echo "--------------------------------------------------------------" @echo ">>> Installing kernel ${INSTALLKERNEL}" @echo "--------------------------------------------------------------" cd ${KRNLOBJDIR}/${INSTALLKERNEL}; \ ${CROSSENV} PATH=${TMPPATH} \ ${MAKE} KERNEL=${INSTKERNNAME} ${.TARGET:S/kernel//} distributekernel distributekernel.debug: .if empty(INSTALLKERNEL) @echo "ERROR: No kernel \"${KERNCONF}\" to install."; \ false .endif cd ${KRNLOBJDIR}/${INSTALLKERNEL}; \ ${CROSSENV} PATH=${TMPPATH} ${MAKE} KERNEL=${INSTKERNNAME} \ DESTDIR=${DESTDIR}/${DISTDIR}/kernel \ ${.TARGET:S/distributekernel/install/} .for _kernel in ${BUILDKERNELS:S/${INSTALLKERNEL}//} cd ${KRNLOBJDIR}/${_kernel}; \ ${CROSSENV} PATH=${TMPPATH} ${MAKE} \ KERNEL=${INSTKERNNAME}.${_kernel} \ DESTDIR=${DESTDIR}/${DISTDIR}/kernel.${_kernel} \ ${.TARGET:S/distributekernel/install/} .endfor packagekernel: cd ${DESTDIR}/${DISTDIR}/kernel; \ tar cvJf ${DESTDIR}/${DISTDIR}/kernel.txz . .for _kernel in ${BUILDKERNELS:S/${INSTALLKERNEL}//} cd ${DESTDIR}/${DISTDIR}/kernel.${_kernel}; \ tar cvJf ${DESTDIR}/${DISTDIR}/kernel.${_kernel}.txz . .endfor # # doxygen # # Build the API documentation with doxygen # doxygen: @if [ ! -x `/usr/bin/which doxygen` ]; then \ echo "You need doxygen (devel/doxygen) to generate the API documentation of the kernel." | /usr/bin/fmt; \ exit 1; \ fi cd ${.CURDIR}/tools/kerneldoc/subsys && ${MAKE} obj all # # update # # Update the source tree(s), by running cvsup/cvs/svn to update to the # latest copy. # update: .if defined(SUP_UPDATE) @echo "--------------------------------------------------------------" @echo ">>> Running ${SUP}" @echo "--------------------------------------------------------------" .if defined(SUPFILE) @${SUP} ${SUPFLAGS} ${SUPFILE} .endif .if defined(SUPFILE1) @${SUP} ${SUPFLAGS} ${SUPFILE1} .endif .if defined(SUPFILE2) @${SUP} ${SUPFLAGS} ${SUPFILE2} .endif .if defined(PORTSSUPFILE) && !defined(NO_PORTSUPDATE) @${SUP} ${SUPFLAGS} ${PORTSSUPFILE} .endif .if defined(DOCSUPFILE) && !defined(NO_DOCUPDATE) @${SUP} ${SUPFLAGS} ${DOCSUPFILE} .endif .if defined(WWWSUPFILE) && !defined(NO_WWWUPDATE) @${SUP} ${SUPFLAGS} ${WWWSUPFILE} .endif .endif .if defined(CVS_UPDATE) @cd ${.CURDIR} ; \ if [ -d CVS ] ; then \ echo "--------------------------------------------------------------" ; \ echo ">>> Updating ${.CURDIR} from CVS repository" ${CVSROOT} ; \ echo "--------------------------------------------------------------" ; \ echo ${CVS} -R -q update ${CVSFLAGS} ; \ ${CVS} -R -q update ${CVSFLAGS} ; \ fi .endif .if defined(SVN_UPDATE) @cd ${.CURDIR} ; \ if [ -d .svn ] ; then \ echo "--------------------------------------------------------------" ; \ echo ">>> Updating ${.CURDIR} using Subversion" ; \ echo "--------------------------------------------------------------" ; \ echo ${SVN} update ${SVNFLAGS} ; \ ${SVN} update ${SVNFLAGS} ; \ fi .endif # # ------------------------------------------------------------------------ # # From here onwards are utility targets used by the 'make world' and # related targets. If your 'world' breaks, you may like to try to fix # the problem and manually run the following targets to attempt to # complete the build. Beware, this is *not* guaranteed to work, you # need to have a pretty good grip on the current state of the system # to attempt to manually finish it. If in doubt, 'make world' again. # # # legacy: Build compatibility shims for the next three targets # legacy: .if ${BOOTSTRAPPING} < 600034 && ${BOOTSTRAPPING} != 0 @echo "ERROR: Source upgrades from versions prior to 6.0 not supported."; \ false .endif .for _tool in tools/build ${_+_}@${ECHODIR} "===> ${_tool} (obj,includes,depend,all,install)"; \ cd ${.CURDIR}/${_tool}; \ ${MAKE} DIRPRFX=${_tool}/ obj; \ ${MAKE} DIRPRFX=${_tool}/ DESTDIR=${MAKEOBJDIRPREFIX}/legacy includes; \ ${MAKE} DIRPRFX=${_tool}/ depend; \ ${MAKE} DIRPRFX=${_tool}/ all; \ ${MAKE} DIRPRFX=${_tool}/ DESTDIR=${MAKEOBJDIRPREFIX}/legacy install .endfor # # bootstrap-tools: Build tools needed for compatibility # .if ${MK_GAMES} != "no" _strfile= games/fortune/strfile .endif .if ${MK_CXX} != "no" _gperf= gnu/usr.bin/gperf .endif .if ${MK_GROFF} != "no" _groff= gnu/usr.bin/groff .endif .if ${BOOTSTRAPPING} >= 700044 && ${BOOTSTRAPPING} < 800022 _ar= usr.bin/ar .endif .if ${BOOTSTRAPPING} < 800013 _mklocale= usr.bin/mklocale .endif .if ${BOOTSTRAPPING} < 900002 _sed= usr.bin/sed .endif .if ${BOOTSTRAPPING} < 900006 _lex= usr.bin/lex _yacc= usr.bin/yacc .endif .if ${BOOTSTRAPPING} >= 900040 && ${BOOTSTRAPPING} < 900041 _awk= usr.bin/awk .endif .if ${MK_BSNMP} != "no" && \ (${BOOTSTRAPPING} < 700018 || !exists(/usr/sbin/gensnmptree)) _gensnmptree= usr.sbin/bsnmpd/gensnmptree .endif .if ${MK_RESCUE} != "no" && \ ${BOOTSTRAPPING} < 700026 _crunchgen= usr.sbin/crunch/crunchgen .endif .if ${MK_CLANG} != "no" _clang_tblgen= \ lib/clang/libllvmsupport \ lib/clang/libllvmtablegen \ usr.bin/clang/tblgen \ usr.bin/clang/clang-tblgen .endif .if ${MK_CDDL} != "no" && \ ${BOOTSTRAPPING} < 800038 && \ !(${BOOTSTRAPPING} >= 700112 && ${BOOTSTRAPPING} < 799999) _dtrace_tools= cddl/usr.bin/sgsmsg cddl/lib/libctf lib/libelf \ lib/libdwarf cddl/usr.bin/ctfconvert cddl/usr.bin/ctfmerge .endif .if ${MK_FDT} != "no" _dtc= gnu/usr.bin/dtc .endif # Please document (add comment) why something is in 'bootstrap-tools'. # Try to bound the building of the bootstrap-tool to just the # FreeBSD versions that need the tool built at this stage of the build. bootstrap-tools: .for _tool in \ ${_clang_tblgen} \ ${_dtrace_tools} \ ${_strfile} \ ${_gperf} \ ${_groff} \ ${_ar} \ ${_dtc} \ ${_awk} \ usr.bin/lorder \ usr.bin/makewhatis \ ${_mklocale} \ usr.bin/rpcgen \ ${_sed} \ ${_lex} \ ${_yacc} \ usr.bin/xinstall \ ${_gensnmptree} \ usr.sbin/config \ ${_crunchgen} ${_+_}@${ECHODIR} "===> ${_tool} (obj,depend,all,install)"; \ cd ${.CURDIR}/${_tool}; \ ${MAKE} DIRPRFX=${_tool}/ obj; \ ${MAKE} DIRPRFX=${_tool}/ depend; \ ${MAKE} DIRPRFX=${_tool}/ all; \ ${MAKE} DIRPRFX=${_tool}/ DESTDIR=${MAKEOBJDIRPREFIX}/legacy install .endfor # # build-tools: Build special purpose build tools # .if defined(MODULES_WITH_WORLD) && exists(${KERNSRCDIR}/modules) _aicasm= sys/modules/aic7xxx/aicasm .endif .if !defined(NO_SHARE) _share= share/syscons/scrnmaps .endif .if ${MK_GCC} != "no" && ${MK_CLANG_IS_CC} == "no" _gcc_tools= gnu/usr.bin/cc/cc_tools .endif .if ${MK_KERBEROS} != "no" _kerberos5_tools= kerberos5/tools .endif .if ${MK_RESCUE} != "no" _rescue= rescue/rescue .endif build-tools: .for _tool in \ bin/csh \ bin/sh \ ${_rescue} \ lib/ncurses/ncurses \ lib/ncurses/ncursesw \ ${_share} \ ${_aicasm} \ usr.bin/awk \ lib/libmagic \ usr.sbin/sysinstall \ usr.bin/mkesdb_static \ usr.bin/mkcsmapper_static ${_+_}@${ECHODIR} "===> ${_tool} (obj,build-tools)"; \ cd ${.CURDIR}/${_tool}; \ ${MAKE} DIRPRFX=${_tool}/ obj; \ ${MAKE} DIRPRFX=${_tool}/ build-tools .endfor .for _tool in \ ${_gcc_tools} \ ${_kerberos5_tools} ${_+_}@${ECHODIR} "===> ${_tool} (obj,depend,all)"; \ cd ${.CURDIR}/${_tool}; \ ${MAKE} DIRPRFX=${_tool}/ obj; \ ${MAKE} DIRPRFX=${_tool}/ depend; \ ${MAKE} DIRPRFX=${_tool}/ all .endfor # # cross-tools: Build cross-building tools # .if ${TARGET_ARCH} != ${MACHINE_ARCH} || ${BOOTSTRAPPING} < 800035 .if ${TARGET_ARCH} == "amd64" || ${TARGET_ARCH} == "i386" _btxld= usr.sbin/btxld .endif .endif .if ${TARGET_ARCH} != ${MACHINE_ARCH} .if ${MK_RESCUE} != "no" || defined(RELEASEDIR) _crunchide= usr.sbin/crunch/crunchide .endif .if ${TARGET_ARCH} == "i386" && defined(RELEASEDIR) _kgzip= usr.sbin/kgzip .endif .endif .if ${MK_BINUTILS} != "no" _binutils= gnu/usr.bin/binutils .endif .if ${MK_CLANG} != "no" && (${MK_CLANG_IS_CC} != "no" || ${CC:T:Mclang} == "clang") _clang= usr.bin/clang _clang_libs= lib/clang .endif .if ${MK_GCC} != "no" && ${MK_CLANG_IS_CC} == "no" _cc= gnu/usr.bin/cc .endif cross-tools: .for _tool in \ ${_clang_libs} \ ${_clang} \ ${_binutils} \ ${_cc} \ usr.bin/xlint/lint1 usr.bin/xlint/lint2 usr.bin/xlint/xlint \ ${_btxld} \ ${_crunchide} \ ${_kgzip} ${_+_}@${ECHODIR} "===> ${_tool} (obj,depend,all,install)"; \ cd ${.CURDIR}/${_tool}; \ ${MAKE} DIRPRFX=${_tool}/ obj; \ ${MAKE} DIRPRFX=${_tool}/ depend; \ ${MAKE} DIRPRFX=${_tool}/ all; \ ${MAKE} DIRPRFX=${_tool}/ DESTDIR=${MAKEOBJDIRPREFIX} install .endfor # # hierarchy - ensure that all the needed directories are present # hierarchy: cd ${.CURDIR}/etc; ${MAKE} distrib-dirs # # libraries - build all libraries, and install them under ${DESTDIR}. # # The list of libraries with dependents (${_prebuild_libs}) and their # interdependencies (__L) are built automatically by the # ${.CURDIR}/tools/make_libdeps.sh script. # libraries: cd ${.CURDIR}; \ ${MAKE} -f Makefile.inc1 _prereq_libs; \ ${MAKE} -f Makefile.inc1 _startup_libs; \ ${MAKE} -f Makefile.inc1 _prebuild_libs; \ ${MAKE} -f Makefile.inc1 _generic_libs; # # static libgcc.a prerequisite for shared libc # _prereq_libs= gnu/lib/libssp/libssp_nonshared gnu/lib/libgcc lib/libcompiler_rt # These dependencies are not automatically generated: # # gnu/lib/csu, gnu/lib/libgcc, lib/csu and lib/libc must be built before # all shared libraries for ELF. # _startup_libs= gnu/lib/csu .if exists(${.CURDIR}/lib/csu/${MACHINE_ARCH}-elf) _startup_libs+= lib/csu/${MACHINE_ARCH}-elf .elif exists(${.CURDIR}/lib/csu/${MACHINE_ARCH}) _startup_libs+= lib/csu/${MACHINE_ARCH} .else _startup_libs+= lib/csu/${MACHINE_CPUARCH} .endif _startup_libs+= gnu/lib/libgcc _startup_libs+= lib/libcompiler_rt _startup_libs+= lib/libc +.if ${MK_LIBCPLUSPLUS} != "no" +_startup_libs+= lib/libcxxrt +.endif gnu/lib/libgcc__L: lib/libc__L _prebuild_libs= ${_kerberos5_lib_libasn1} ${_kerberos5_lib_libhdb} \ ${_kerberos5_lib_libheimntlm} \ ${_kerberos5_lib_libhx509} ${_kerberos5_lib_libkrb5} \ ${_kerberos5_lib_libroken} \ lib/libbz2 lib/libcom_err lib/libcrypt \ lib/libexpat \ ${_lib_libgssapi} ${_lib_libipx} \ lib/libkiconv lib/libkvm lib/liblzma lib/libmd \ lib/ncurses/ncurses lib/ncurses/ncursesw \ lib/libopie lib/libpam ${_lib_libthr} \ lib/libradius lib/libsbuf lib/libtacplus \ ${_cddl_lib_libumem} \ lib/libutil ${_lib_libypclnt} lib/libz lib/msun \ ${_secure_lib_libcrypto} ${_secure_lib_libssh} \ ${_secure_lib_libssl} .if ${MK_LIBTHR} != "no" _lib_libthr= lib/libthr .endif .if ${MK_OFED} != "no" _ofed_lib= contrib/ofed/usr.lib/ .endif _generic_libs= ${_cddl_lib} gnu/lib ${_kerberos5_lib} lib ${_secure_lib} usr.bin/lex/lib ${_ofed_lib} lib/libopie__L lib/libtacplus__L: lib/libmd__L .if ${MK_CDDL} != "no" _cddl_lib_libumem= cddl/lib/libumem _cddl_lib= cddl/lib .endif .if ${MK_CRYPT} != "no" .if ${MK_OPENSSL} != "no" _secure_lib_libcrypto= secure/lib/libcrypto _secure_lib_libssl= secure/lib/libssl lib/libradius__L secure/lib/libssl__L: secure/lib/libcrypto__L .if ${MK_OPENSSH} != "no" _secure_lib_libssh= secure/lib/libssh secure/lib/libssh__L: lib/libz__L secure/lib/libcrypto__L lib/libcrypt__L .if ${MK_KERBEROS_SUPPORT} != "no" secure/lib/libssh__L: lib/libgssapi__L kerberos5/lib/libkrb5__L \ kerberos5/lib/libhx509__L kerberos5/lib/libasn1__L lib/libcom_err__L \ lib/libmd__L kerberos5/lib/libroken__L .endif .endif .endif _secure_lib= secure/lib .endif .if ${MK_KERBEROS} != "no" kerberos5/lib/libasn1__L: lib/libcom_err__L kerberos5/lib/libroken__L kerberos5/lib/libhdb__L: kerberos5/lib/libasn1__L lib/libcom_err__L \ kerberos5/lib/libkrb5__L kerberos5/lib/libroken__L kerberos5/lib/libheimntlm__L: secure/lib/libcrypto__L kerberos5/lib/libkrb5__L kerberos5/lib/libhx509__L: kerberos5/lib/libasn1__L lib/libcom_err__L \ secure/lib/libcrypto__L kerberos5/lib/libroken__L kerberos5/lib/libkrb5__L: kerberos5/lib/libasn1__L lib/libcom_err__L \ lib/libcrypt__L secure/lib/libcrypto__L kerberos5/lib/libhx509__L \ kerberos5/lib/libroken__L kerberos5/lib/libroken__L: lib/libcrypt__L .endif .if ${MK_GSSAPI} != "no" _lib_libgssapi= lib/libgssapi .endif .if ${MK_IPX} != "no" _lib_libipx= lib/libipx .endif .if ${MK_KERBEROS} != "no" _kerberos5_lib= kerberos5/lib _kerberos5_lib_libasn1= kerberos5/lib/libasn1 _kerberos5_lib_libhdb= kerberos5/lib/libhdb _kerberos5_lib_libkrb5= kerberos5/lib/libkrb5 _kerberos5_lib_libhx509= kerberos5/lib/libhx509 _kerberos5_lib_libroken= kerberos5/lib/libroken _kerberos5_lib_libheimntlm= kerberos5/lib/libheimntlm .endif .if ${MK_NIS} != "no" _lib_libypclnt= lib/libypclnt .endif .if ${MK_OPENSSL} == "no" lib/libradius__L: lib/libmd__L .endif .for _lib in ${_prereq_libs} ${_lib}__PL: .PHONY .if exists(${.CURDIR}/${_lib}) ${_+_}@${ECHODIR} "===> ${_lib} (obj,depend,all,install)"; \ cd ${.CURDIR}/${_lib}; \ ${MAKE} DIRPRFX=${_lib}/ obj; \ ${MAKE} DIRPRFX=${_lib}/ depend; \ ${MAKE} -DWITHOUT_PROFILE -DNO_PIC DIRPRFX=${_lib}/ all; \ ${MAKE} -DWITHOUT_PROFILE -DNO_PIC DIRPRFX=${_lib}/ install .endif .endfor .for _lib in ${_startup_libs} ${_prebuild_libs:Nlib/libpam} ${_generic_libs} ${_lib}__L: .PHONY .if exists(${.CURDIR}/${_lib}) ${_+_}@${ECHODIR} "===> ${_lib} (obj,depend,all,install)"; \ cd ${.CURDIR}/${_lib}; \ ${MAKE} DIRPRFX=${_lib}/ obj; \ ${MAKE} DIRPRFX=${_lib}/ depend; \ ${MAKE} DIRPRFX=${_lib}/ all; \ ${MAKE} DIRPRFX=${_lib}/ install .endif .endfor # libpam is special: we need to build static PAM modules before # static PAM library, and dynamic PAM library before dynamic PAM # modules. lib/libpam__L: .PHONY ${_+_}@${ECHODIR} "===> lib/libpam (obj,depend,all,install)"; \ cd ${.CURDIR}/lib/libpam; \ ${MAKE} DIRPRFX=lib/libpam/ obj; \ ${MAKE} DIRPRFX=lib/libpam/ depend; \ ${MAKE} DIRPRFX=lib/libpam/ -D_NO_LIBPAM_SO_YET all; \ ${MAKE} DIRPRFX=lib/libpam/ -D_NO_LIBPAM_SO_YET install _prereq_libs: ${_prereq_libs:S/$/__PL/} _startup_libs: ${_startup_libs:S/$/__L/} _prebuild_libs: ${_prebuild_libs:S/$/__L/} _generic_libs: ${_generic_libs:S/$/__L/} .for __target in all clean cleandepend cleandir depend includes obj .for entry in ${SUBDIR} ${entry}.${__target}__D: .PHONY ${_+_}@if test -d ${.CURDIR}/${entry}.${MACHINE_ARCH}; then \ ${ECHODIR} "===> ${DIRPRFX}${entry}.${MACHINE_ARCH} (${__target})"; \ edir=${entry}.${MACHINE_ARCH}; \ cd ${.CURDIR}/$${edir}; \ else \ ${ECHODIR} "===> ${DIRPRFX}${entry} (${__target})"; \ edir=${entry}; \ cd ${.CURDIR}/$${edir}; \ fi; \ ${MAKE} ${__target} DIRPRFX=${DIRPRFX}$${edir}/ .endfor par-${__target}: ${SUBDIR:S/$/.${__target}__D/} .endfor .include .if make(check-old) || make(check-old-dirs) || \ make(check-old-files) || make(check-old-libs) || \ make(delete-old) || make(delete-old-dirs) || \ make(delete-old-files) || make(delete-old-libs) # # check for / delete old files section # .include "ObsoleteFiles.inc" OLD_LIBS_MESSAGE="Please be sure no application still uses those libraries, \ else you can not start such an application. Consult UPDATING for more \ information regarding how to cope with the removal/revision bump of a \ specific library." .if !defined(BATCH_DELETE_OLD_FILES) RM_I=-i .else RM_I=-v .endif delete-old-files: @echo ">>> Removing old files (only deletes safe to delete libs)" # Ask for every old file if the user really wants to remove it. # It's annoying, but better safe than sorry. # NB: We cannot pass the list of OLD_FILES as a parameter because the # argument list will get too long. Using .for/.endfor make "loops" will make # the Makefile parser segfault. @exec 3<&0; \ ${MAKE} -f ${.CURDIR}/Makefile.inc1 ${.MAKEFLAGS} ${.TARGET} \ -V OLD_FILES -V "OLD_FILES:Musr/share/*.gz:R" | xargs -n1 | \ while read file; do \ if [ -f "${DESTDIR}/$${file}" -o -L "${DESTDIR}/$${file}" ]; then \ chflags noschg "${DESTDIR}/$${file}" 2>/dev/null || true; \ rm ${RM_I} "${DESTDIR}/$${file}" <&3; \ fi; \ done # Remove catpages without corresponding manpages. @exec 3<&0; \ find ${DESTDIR}/usr/share/man/cat* ! -type d | \ sed -ep -e's:${DESTDIR}/usr/share/man/cat:${DESTDIR}/usr/share/man/man:' | \ while read catpage; do \ read manpage; \ if [ ! -e "$${manpage}" ]; then \ rm ${RM_I} $${catpage} <&3; \ fi; \ done @echo ">>> Old files removed" check-old-files: @echo ">>> Checking for old files" @${MAKE} -f ${.CURDIR}/Makefile.inc1 ${.MAKEFLAGS} ${.TARGET} \ -V OLD_FILES -V "OLD_FILES:Musr/share/*.gz:R" | xargs -n1 | \ while read file; do \ if [ -f "${DESTDIR}/$${file}" -o -L "${DESTDIR}/$${file}" ]; then \ echo "${DESTDIR}/$${file}"; \ fi; \ done # Check for catpages without corresponding manpages. @find ${DESTDIR}/usr/share/man/cat* ! -type d | \ sed -ep -e's:${DESTDIR}/usr/share/man/cat:${DESTDIR}/usr/share/man/man:' | \ while read catpage; do \ read manpage; \ if [ ! -e "$${manpage}" ]; then \ echo $${catpage}; \ fi; \ done delete-old-libs: @echo ">>> Removing old libraries" @echo "${OLD_LIBS_MESSAGE}" | fmt @exec 3<&0; \ ${MAKE} -f ${.CURDIR}/Makefile.inc1 ${.MAKEFLAGS} ${.TARGET} \ -V OLD_LIBS | xargs -n1 | \ while read file; do \ if [ -f "${DESTDIR}/$${file}" -o -L "${DESTDIR}/$${file}" ]; then \ chflags noschg "${DESTDIR}/$${file}" 2>/dev/null || true; \ rm ${RM_I} "${DESTDIR}/$${file}" <&3; \ fi; \ done @echo ">>> Old libraries removed" check-old-libs: @echo ">>> Checking for old libraries" @${MAKE} -f ${.CURDIR}/Makefile.inc1 ${.MAKEFLAGS} ${.TARGET} \ -V OLD_LIBS | xargs -n1 | \ while read file; do \ if [ -f "${DESTDIR}/$${file}" -o -L "${DESTDIR}/$${file}" ]; then \ echo "${DESTDIR}/$${file}"; \ fi; \ done delete-old-dirs: @echo ">>> Removing old directories" @${MAKE} -f ${.CURDIR}/Makefile.inc1 ${.MAKEFLAGS} ${.TARGET} \ -V OLD_DIRS | xargs -n1 | \ while read dir; do \ if [ -d "${DESTDIR}/$${dir}" ]; then \ rmdir -v "${DESTDIR}/$${dir}" || true; \ elif [ -L "${DESTDIR}/$${dir}" ]; then \ echo "${DESTDIR}/$${dir} is a link, please remove everything manually."; \ fi; \ done @echo ">>> Old directories removed" check-old-dirs: @echo ">>> Checking for old directories" @${MAKE} -f ${.CURDIR}/Makefile.inc1 ${.MAKEFLAGS} ${.TARGET} \ -V OLD_DIRS | xargs -n1 | \ while read dir; do \ if [ -d "${DESTDIR}/$${dir}" ]; then \ echo "${DESTDIR}/$${dir}"; \ elif [ -L "${DESTDIR}/$${dir}" ]; then \ echo "${DESTDIR}/$${dir} is a link, please remove everything manually."; \ fi; \ done delete-old: delete-old-files delete-old-dirs @echo "To remove old libraries run '${MAKE} delete-old-libs'." check-old: check-old-files check-old-libs check-old-dirs @echo "To remove old files and directories run '${MAKE} delete-old'." @echo "To remove old libraries run '${MAKE} delete-old-libs'." .endif # # showconfig - show build configuration. # showconfig: @${MAKE} -n -f bsd.own.mk -V dummy -dg1 | grep ^MK_ | sort .if !empty(KRNLOBJDIR) && !empty(KERNCONF) DTBOUTPUTPATH= ${KRNLOBJDIR}/${KERNCONF}/ .if !defined(FDT_DTS_FILE) || empty(FDT_DTS_FILE) .if exists(${KERNCONFDIR}/${KERNCONF}) FDT_DTS_FILE!= awk 'BEGIN {FS="="} /^makeoptions[[:space:]]+FDT_DTS_FILE/ {print $$2}' \ ${KERNCONFDIR}/${KERNCONF} .endif .endif .endif .if !defined(DTBOUTPUTPATH) || !exists(${DTBOUTPUTPATH}) DTBOUTPUTPATH= ${.CURDIR} .endif # # Build 'standalone' Device Tree Blob # builddtb: @if [ "${FDT_DTS_FILE}" = "" ]; then \ echo "ERROR: FDT_DTS_FILE must be specified!"; \ exit 1; \ fi; \ if [ ! -f ${.CURDIR}/sys/boot/fdt/dts/${FDT_DTS_FILE} ]; then \ echo "ERROR: Specified DTS file (${FDT_DTS_FILE}) does not \ exist!"; \ exit 1; \ fi; \ if [ "${DTBOUTPUTPATH}" = "${.CURDIR}" ]; then \ echo "WARNING: DTB will be placed in the current working \ directory"; \ fi @PATH=${TMPPATH} \ dtc -O dtb -o \ ${DTBOUTPUTPATH}/`echo ${FDT_DTS_FILE} | cut -d. -f1`.dtb -b 0 \ -p 1024 ${.CURDIR}/sys/boot/fdt/dts/${FDT_DTS_FILE} ############### .if defined(XDEV) && defined(XDEV_ARCH) .if ${XDEV} == ${MACHINE} && ${XDEV_ARCH} == ${MACHINE_ARCH} XDEV_CPUTYPE?=${CPUTYPE} .else XDEV_CPUTYPE?=${TARGET_CPUTYPE} .endif NOFUN=-DNO_FSCHG -DWITHOUT_HTML -DWITHOUT_INFO -DNO_LINT \ -DWITHOUT_MAN -DWITHOUT_NLS -DWITHOUT_PROFILE \ -DWITHOUT_KERBEROS -DWITHOUT_RESCUE -DNO_WARNS \ TARGET=${XDEV} TARGET_ARCH=${XDEV_ARCH} \ CPUTYPE=${XDEV_CPUTYPE} XDDIR=${XDEV_ARCH}-freebsd XDTP=/usr/${XDDIR} CDBENV=MAKEOBJDIRPREFIX=${MAKEOBJDIRPREFIX}/${XDDIR} CDENV= ${CDBENV} \ _SHLIBDIRPREFIX=${XDTP} \ TOOLS_PREFIX=${XDTP} CD2ENV=${CDENV} \ MACHINE=${XDEV} MACHINE_ARCH=${XDEV_ARCH} CDTMP= ${MAKEOBJDIRPREFIX}/${XDEV}/${.CURDIR}/tmp CDMAKE=${CDENV} ${MAKE} ${NOFUN} CD2MAKE=${CD2ENV} PATH=${CDTMP}/usr/bin:${XDTP}/usr/bin:${PATH} ${MAKE} ${NOFUN} XDDESTDIR=${DESTDIR}${XDTP} .if !defined(OSREL) OSREL!= uname -r | sed -e 's/[-(].*//' .endif .ORDER: xdev-build xdev-install xdev: xdev-build xdev-install .ORDER: _xb-build-tools _xb-cross-tools xdev-build: _xb-build-tools _xb-cross-tools _xb-build-tools: ${_+_}@cd ${.CURDIR}; \ ${CDBENV} ${MAKE} -f Makefile.inc1 ${NOFUN} build-tools _xb-cross-tools: .for _tool in \ gnu/usr.bin/binutils \ gnu/usr.bin/cc \ usr.bin/ar ${_+_}@${ECHODIR} "===> xdev ${_tool} (obj,depend,all)"; \ cd ${.CURDIR}/${_tool}; \ ${CDMAKE} DIRPRFX=${_tool}/ obj; \ ${CDMAKE} DIRPRFX=${_tool}/ depend; \ ${CDMAKE} DIRPRFX=${_tool}/ all .endfor _xi-mtree: ${_+_}@${ECHODIR} "mtree populating ${XDDESTDIR}" mkdir -p ${XDDESTDIR} mtree -deU -f ${.CURDIR}/etc/mtree/BSD.root.dist \ -p ${XDDESTDIR} >/dev/null mtree -deU -f ${.CURDIR}/etc/mtree/BSD.usr.dist \ -p ${XDDESTDIR}/usr >/dev/null mtree -deU -f ${.CURDIR}/etc/mtree/BSD.include.dist \ -p ${XDDESTDIR}/usr/include >/dev/null .ORDER: _xi-mtree _xi-cross-tools _xi-includes _xi-libraries _xi-links xdev-install: _xi-mtree _xi-cross-tools _xi-includes _xi-libraries _xi-links _xi-cross-tools: @echo "_xi-cross-tools" .for _tool in \ gnu/usr.bin/binutils \ gnu/usr.bin/cc \ usr.bin/ar ${_+_}@${ECHODIR} "===> xdev ${_tool} (install)"; \ cd ${.CURDIR}/${_tool}; \ ${CDMAKE} DIRPRFX=${_tool}/ install DESTDIR=${XDDESTDIR} .endfor _xi-includes: ${_+_}cd ${.CURDIR}; ${CD2MAKE} -f Makefile.inc1 par-includes \ DESTDIR=${XDDESTDIR} _xi-libraries: ${_+_}cd ${.CURDIR}; ${CD2MAKE} -f Makefile.inc1 libraries \ DESTDIR=${XDDESTDIR} _xi-links: ${_+_}cd ${XDDESTDIR}/usr/bin; \ for i in *; do \ ln -sf ../../${XDTP}/usr/bin/$$i \ ../../../../usr/bin/${XDDIR}-$$i; \ ln -sf ../../${XDTP}/usr/bin/$$i \ ../../../../usr/bin/${XDDIR}${OSREL}-$$i; \ done .endif Property changes on: stable/9/Makefile.inc1 ___________________________________________________________________ Modified: svn:mergeinfo ## -0,0 +0,1 ## Merged /head/Makefile.inc1:r227983,227987 Index: stable/9/contrib/libc++/include/__config =================================================================== --- stable/9/contrib/libc++/include/__config (nonexistent) +++ stable/9/contrib/libc++/include/__config (revision 235798) @@ -0,0 +1,445 @@ +// -*- C++ -*- +//===--------------------------- __config ---------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP_CONFIG +#define _LIBCPP_CONFIG + +#if !_MSC_VER // explicit macro necessary because it is only defined below in this file +#pragma GCC system_header +#endif + +#define _LIBCPP_VERSION 1001 + +#define _LIBCPP_ABI_VERSION 1 + +#define _LIBCPP_CONCAT1(_LIBCPP_X,_LIBCPP_Y) _LIBCPP_X##_LIBCPP_Y +#define _LIBCPP_CONCAT(_LIBCPP_X,_LIBCPP_Y) _LIBCPP_CONCAT1(_LIBCPP_X,_LIBCPP_Y) + +#define _LIBCPP_NAMESPACE _LIBCPP_CONCAT(__,_LIBCPP_ABI_VERSION) + +#ifdef __LITTLE_ENDIAN__ +#if __LITTLE_ENDIAN__ +#define _LIBCPP_LITTLE_ENDIAN 1 +#define _LIBCPP_BIG_ENDIAN 0 +#endif // __LITTLE_ENDIAN__ +#endif // __LITTLE_ENDIAN__ + +#ifdef __BIG_ENDIAN__ +#if __BIG_ENDIAN__ +#define _LIBCPP_LITTLE_ENDIAN 0 +#define _LIBCPP_BIG_ENDIAN 1 +#endif // __BIG_ENDIAN__ +#endif // __BIG_ENDIAN__ + +#ifdef __FreeBSD__ +# include +# if _BYTE_ORDER == _LITTLE_ENDIAN +# define _LIBCPP_LITTLE_ENDIAN 1 +# define _LIBCPP_BIG_ENDIAN 0 +# else // _BYTE_ORDER == _LITTLE_ENDIAN +# define _LIBCPP_LITTLE_ENDIAN 0 +# define _LIBCPP_BIG_ENDIAN 1 +# endif // _BYTE_ORDER == _LITTLE_ENDIAN +#endif // __FreeBSD__ + +#ifdef _WIN32 +# define _LIBCPP_LITTLE_ENDIAN 1 +# define _LIBCPP_BIG_ENDIAN 0 +// Compiler intrinsics (GCC or MSVC) +# if (defined(_MSC_VER) && _MSC_VER >= 1400) || (__GNUC__ >= 4 && __GNUC_MINOR__ > 3) +# define _LIBCP_HAS_IS_BASE_OF +# endif +#endif // _WIN32 + +#ifdef __sun__ +# include +# ifdef _LITTLE_ENDIAN +# define _LIBCPP_LITTLE_ENDIAN 1 +# define _LIBCPP_BIG_ENDIAN 0 +# else +# define _LIBCPP_LITTLE_ENDIAN 0 +# define _LIBCPP_BIG_ENDIAN 1 +# endif +#endif // __sun__ + +#if !defined(_LIBCPP_LITTLE_ENDIAN) || !defined(_LIBCPP_BIG_ENDIAN) +# include +# if __BYTE_ORDER == __LITTLE_ENDIAN +# define _LIBCPP_LITTLE_ENDIAN 1 +# define _LIBCPP_BIG_ENDIAN 0 +# elif __BYTE_ORDER == __BIG_ENDIAN +# define _LIBCPP_LITTLE_ENDIAN 0 +# define _LIBCPP_BIG_ENDIAN 1 +# else // __BYTE_ORDER == __BIG_ENDIAN +# error unable to determine endian +# endif +#endif // !defined(_LIBCPP_LITTLE_ENDIAN) || !defined(_LIBCPP_BIG_ENDIAN) + +#if _WIN32 + +// only really useful for a DLL +#ifdef _LIBCPP_DLL // this should be a compiler builtin define ideally... +# ifdef cxx_EXPORTS +# define _LIBCPP_HIDDEN +# define _LIBCPP_VISIBLE __declspec(dllexport) +# else +# define _LIBCPP_HIDDEN +# define _LIBCPP_VISIBLE __declspec(dllimport) +# endif +#else +# define _LIBCPP_HIDDEN +# define _LIBCPP_VISIBLE +#endif + +#ifndef _LIBCPP_INLINE_VISIBILITY +# if _MSC_VER +# define _LIBCPP_INLINE_VISIBILITY __forceinline +# else // MinGW GCC and Clang +# define _LIBCPP_INLINE_VISIBILITY __attribute__ ((__always_inline__)) +# endif +#endif + +#ifndef _LIBCPP_EXCEPTION_ABI +#define _LIBCPP_EXCEPTION_ABI _LIBCPP_VISIBLE +#endif + +#ifndef _LIBCPP_ALWAYS_INLINE +# if _MSC_VER +# define _LIBCPP_ALWAYS_INLINE __forceinline +# endif +#endif + +#endif // _WIN32 + +#ifndef _LIBCPP_HIDDEN +#define _LIBCPP_HIDDEN __attribute__ ((__visibility__("hidden"))) +#endif + +#ifndef _LIBCPP_VISIBLE +#define _LIBCPP_VISIBLE __attribute__ ((__visibility__("default"))) +#endif + +#ifndef _LIBCPP_INLINE_VISIBILITY +#define _LIBCPP_INLINE_VISIBILITY __attribute__ ((__visibility__("hidden"), __always_inline__)) +#endif + +#ifndef _LIBCPP_EXCEPTION_ABI +#define _LIBCPP_EXCEPTION_ABI __attribute__ ((__visibility__("default"))) +#endif + +#ifndef _LIBCPP_CANTTHROW +#define _LIBCPP_CANTTHROW __attribute__ ((__nothrow__)) +#endif + +#ifndef _LIBCPP_ALWAYS_INLINE +#define _LIBCPP_ALWAYS_INLINE __attribute__ ((__visibility__("hidden"), __always_inline__)) +#endif + +#if defined(__clang__) + +#if __has_feature(cxx_alignas) +# define _ALIGNAS(x) alignas(x) +#else +# define _ALIGNAS(x) __attribute__((__aligned__(x))) +#endif + +#if !__has_feature(cxx_alias_templates) +#define _LIBCPP_HAS_NO_TEMPLATE_ALIASES +#endif + +#ifndef __GXX_EXPERIMENTAL_CXX0X__ +#ifdef __linux__ +#define _LIBCPP_HAS_NO_UNICODE_CHARS +#else +typedef __char16_t char16_t; +typedef __char32_t char32_t; +#endif +#endif + +#if !(__has_feature(cxx_exceptions)) +#define _LIBCPP_NO_EXCEPTIONS +#endif + +#if !(__has_feature(cxx_rtti)) +#define _LIBCPP_NO_RTTI +#endif + +#if !(__has_feature(cxx_strong_enums)) +#define _LIBCPP_HAS_NO_STRONG_ENUMS +#endif + +#if !(__has_feature(cxx_decltype)) +#define _LIBCPP_HAS_NO_DECLTYPE +#endif + +#if __has_feature(cxx_attributes) +# define _ATTRIBUTE(x) [[x]] +#else +# define _ATTRIBUTE(x) __attribute__ ((x)) +#endif + +#define _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS + +#if !(__has_feature(cxx_deleted_functions)) +#define _LIBCPP_HAS_NO_DELETED_FUNCTIONS +#endif // !(__has_feature(cxx_deleted_functions)) + +#if !(__has_feature(cxx_lambdas)) +#define _LIBCPP_HAS_NO_LAMBDAS +#endif + +#if !(__has_feature(cxx_nullptr)) +#define _LIBCPP_HAS_NO_NULLPTR +#endif + +#if !(__has_feature(cxx_rvalue_references)) +#define _LIBCPP_HAS_NO_RVALUE_REFERENCES +#endif + +#if !(__has_feature(cxx_static_assert)) +#define _LIBCPP_HAS_NO_STATIC_ASSERT +#endif + +#if !(__has_feature(cxx_auto_type)) +#define _LIBCPP_HAS_NO_AUTO_TYPE +#endif + +#if !(__has_feature(cxx_access_control_sfinae)) || !__has_feature(cxx_trailing_return) +#define _LIBCPP_HAS_NO_ADVANCED_SFINAE +#endif + +#if !(__has_feature(cxx_variadic_templates)) +#define _LIBCPP_HAS_NO_VARIADICS +#endif + +#if !(__has_feature(cxx_trailing_return)) +#define _LIBCPP_HAS_NO_TRAILING_RETURN +#endif + +#if !(__has_feature(cxx_generalized_initializers)) +#define _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS +#endif + +#if __has_feature(is_base_of) +# define _LIBCP_HAS_IS_BASE_OF +#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 +#define _LIBCPP_HAS_NO_STRONG_ENUMS +#endif + +#if !(__has_feature(cxx_constexpr)) +#define _LIBCPP_HAS_NO_CONSTEXPR +#endif + +#if __FreeBSD__ +#define _LIBCPP_HAS_QUICK_EXIT +#endif + +#if (__has_feature(cxx_noexcept)) +# define _NOEXCEPT noexcept +# define _NOEXCEPT_(x) noexcept(x) +#else +# define _NOEXCEPT throw() +# define _NOEXCEPT_(x) +#endif + +#if __has_feature(underlying_type) +# define _LIBCXX_UNDERLYING_TYPE(T) __underlying_type(T) +#endif + +// Inline namespaces are available in Clang regardless of C++ dialect. +#define _LIBCPP_BEGIN_NAMESPACE_STD namespace std {inline namespace _LIBCPP_NAMESPACE { +#define _LIBCPP_END_NAMESPACE_STD } } +#define _VSTD std::_LIBCPP_NAMESPACE + +namespace std { + inline namespace _LIBCPP_NAMESPACE { + } +} + +#elif defined(__GNUC__) + +#define _ALIGNAS(x) __attribute__((__aligned__(x))) + +#define _ATTRIBUTE(x) __attribute__((x)) + +#if !__EXCEPTIONS +#define _LIBCPP_NO_EXCEPTIONS +#endif + +#define _LIBCPP_HAS_NO_TEMPLATE_ALIASES +#define _LIBCPP_HAS_NO_CONSTEXPR + +#define _NOEXCEPT throw() +#define _NOEXCEPT_(x) + +#ifndef __GXX_EXPERIMENTAL_CXX0X__ + +#define _LIBCPP_HAS_NO_ADVANCED_SFINAE +#define _LIBCPP_HAS_NO_DECLTYPE +#define _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS +#define _LIBCPP_HAS_NO_DELETED_FUNCTIONS +#define _LIBCPP_HAS_NO_NULLPTR +#define _LIBCPP_HAS_NO_STATIC_ASSERT +#define _LIBCPP_HAS_NO_UNICODE_CHARS +#define _LIBCPP_HAS_NO_VARIADICS +#define _LIBCPP_HAS_NO_RVALUE_REFERENCES +#define _LIBCPP_HAS_NO_ALWAYS_INLINE_VARIADICS + +#else // __GXX_EXPERIMENTAL_CXX0X__ + +#define _LIBCPP_HAS_NO_TRAILING_RETURN +#define _LIBCPP_HAS_NO_ALWAYS_INLINE_VARIADICS + +#if !(__GNUC__ >= 4 && __GNUC_MINOR__ >= 3) +#define _LIBCPP_HAS_NO_RVALUE_REFERENCES +#endif + +#if !(__GNUC__ >= 4 && __GNUC_MINOR__ >= 3) +#define _LIBCPP_HAS_NO_STATIC_ASSERT +#endif + +#if !(__GNUC__ >= 4 && __GNUC_MINOR__ >= 4) +#define _LIBCPP_HAS_NO_ADVANCED_SFINAE +#define _LIBCPP_HAS_NO_DECLTYPE +#define _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS +#define _LIBCPP_HAS_NO_DELETED_FUNCTIONS +#define _LIBCPP_HAS_NO_UNICODE_CHARS +#define _LIBCPP_HAS_NO_VARIADICS +#define _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS +#endif // !(__GNUC__ >= 4 && __GNUC_MINOR__ >= 4) + +#if !(__GNUC__ >= 4 && __GNUC_MINOR__ >= 6) +#define _LIBCPP_HAS_NO_NULLPTR +#endif + +#endif // __GXX_EXPERIMENTAL_CXX0X__ + +#define _LIBCPP_BEGIN_NAMESPACE_STD namespace std { namespace _LIBCPP_NAMESPACE { +#define _LIBCPP_END_NAMESPACE_STD } } +#define _VSTD std::_LIBCPP_NAMESPACE + +namespace std { +namespace _LIBCPP_NAMESPACE { +} +using namespace _LIBCPP_NAMESPACE __attribute__((__strong__)); +} + +#elif defined(_MSC_VER) + +#define _LIBCPP_HAS_NO_TEMPLATE_ALIASES +#define _LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER +#define _LIBCPP_HAS_NO_CONSTEXPR +#define _LIBCPP_HAS_NO_UNICODE_CHARS +#define _LIBCPP_HAS_NO_DELETED_FUNCTIONS +#define __alignof__ __alignof +#define _ATTRIBUTE __declspec +#define _ALIGNAS(x) __declspec(align(x)) +#define _LIBCPP_HAS_NO_VARIADICS + +#define _NOEXCEPT throw() +#define _NOEXCEPT_(x) + +#define _LIBCPP_BEGIN_NAMESPACE_STD namespace std { +#define _LIBCPP_END_NAMESPACE_STD } +#define _VSTD std + +namespace std { +} + +#endif // __clang__ || __GNUC___ || _MSC_VER + +#ifdef _LIBCPP_HAS_NO_UNICODE_CHARS +typedef unsigned short char16_t; +typedef unsigned int char32_t; +#endif // _LIBCPP_HAS_NO_UNICODE_CHARS + +#ifdef _LIBCPP_HAS_NO_STATIC_ASSERT + +template struct __static_assert_test; +template <> struct __static_assert_test {}; +template struct __static_assert_check {}; +#define static_assert(__b, __m) \ + typedef __static_assert_check)> \ + _LIBCPP_CONCAT(__t, __LINE__) + +#endif // _LIBCPP_HAS_NO_STATIC_ASSERT + +#ifdef _LIBCPP_HAS_NO_DECLTYPE +#define decltype(x) __typeof__(x) +#endif + +#ifdef _LIBCPP_HAS_NO_CONSTEXPR +#define _LIBCPP_CONSTEXPR +#else +#define _LIBCPP_CONSTEXPR constexpr +#endif + +#ifndef __has_feature +#define __has_feature(__x) 0 +#endif + +#if __has_feature(cxx_explicit_conversions) +# define _LIBCPP_EXPLICIT explicit +#else +# define _LIBCPP_EXPLICIT +#endif + +#ifdef _LIBCPP_HAS_NO_STRONG_ENUMS +#define _LIBCPP_DECLARE_STRONG_ENUM(x) struct _LIBCPP_VISIBLE x { enum _ +#define _LIBCPP_DECLARE_STRONG_ENUM_EPILOG(x) \ + _ __v_; \ + _LIBCPP_ALWAYS_INLINE x(_ __v) : __v_(__v) {} \ + _LIBCPP_ALWAYS_INLINE operator int() const {return __v_;} \ + }; +#else // _LIBCPP_HAS_NO_STRONG_ENUMS +#define _LIBCPP_DECLARE_STRONG_ENUM(x) enum class _LIBCPP_VISIBLE x +#define _LIBCPP_DECLARE_STRONG_ENUM_EPILOG(x) +#endif // _LIBCPP_HAS_NO_STRONG_ENUMS + +#if __APPLE__ || __FreeBSD__ || _WIN32 || __sun__ +#define _LIBCPP_LOCALE__L_EXTENSIONS 1 +#endif +#if __FreeBSD__ +#define _DECLARE_C99_LDBL_MATH 1 +#endif + +#if __APPLE__ || __FreeBSD__ +#define _LIBCPP_HAS_DEFAULTRUNELOCALE +#endif + +#if __APPLE__ || __FreeBSD__ || __sun__ +#define _LIBCPP_WCTYPE_IS_MASK +#endif + +#ifdef _LIBCPP_DEBUG2 +# if _LIBCPP_DEBUG2 == 0 +# define _LIBCPP_DEBUG_LEVEL 1 +# elif _LIBCPP_DEBUG2 == 1 +# define _LIBCPP_DEBUG_LEVEL 2 +# else +# error Supported values for _LIBCPP_DEBUG2 are 0 and 1 +# endif +#endif + +#ifdef _LIBCPP_DEBUG2 +# include <__debug> +#else +# define _LIBCPP_ASSERT(x, m) ((void)0) +#endif + +#endif // _LIBCPP_CONFIG Index: stable/9/contrib/libc++/include/__tuple =================================================================== --- stable/9/contrib/libc++/include/__tuple (nonexistent) +++ stable/9/contrib/libc++/include/__tuple (revision 235798) @@ -0,0 +1,296 @@ +// -*- C++ -*- +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP___TUPLE +#define _LIBCPP___TUPLE + +#include <__config> +#include +#include + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +#ifdef _LIBCPP_HAS_NO_VARIADICS + +#include <__tuple_03> + +#else // _LIBCPP_HAS_NO_VARIADICS + +_LIBCPP_BEGIN_NAMESPACE_STD + +template class _LIBCPP_VISIBLE tuple_size; + +template +class _LIBCPP_VISIBLE tuple_size + : public tuple_size<_Tp> {}; + +template +class _LIBCPP_VISIBLE tuple_size + : public tuple_size<_Tp> {}; + +template +class _LIBCPP_VISIBLE tuple_size + : public tuple_size<_Tp> {}; + +template class _LIBCPP_VISIBLE tuple_element; + +template +class _LIBCPP_VISIBLE tuple_element<_Ip, const _Tp> +{ +public: + typedef typename add_const::type>::type type; +}; + +template +class _LIBCPP_VISIBLE tuple_element<_Ip, volatile _Tp> +{ +public: + typedef typename add_volatile::type>::type type; +}; + +template +class _LIBCPP_VISIBLE tuple_element<_Ip, const volatile _Tp> +{ +public: + typedef typename add_cv::type>::type type; +}; + +template class _LIBCPP_VISIBLE tuple; +template struct _LIBCPP_VISIBLE pair; +template struct _LIBCPP_VISIBLE array; + +template struct __tuple_like : false_type {}; + +template struct __tuple_like : public __tuple_like<_Tp> {}; +template struct __tuple_like : public __tuple_like<_Tp> {}; +template struct __tuple_like : public __tuple_like<_Tp> {}; + +template struct __tuple_like > : true_type {}; +template struct __tuple_like > : true_type {}; +template struct __tuple_like > : true_type {}; + +template +typename tuple_element<_Ip, tuple<_Tp...> >::type& +get(tuple<_Tp...>&) _NOEXCEPT; + +template +const typename tuple_element<_Ip, tuple<_Tp...> >::type& +get(const tuple<_Tp...>&) _NOEXCEPT; + +template +typename tuple_element<_Ip, tuple<_Tp...> >::type&& +get(tuple<_Tp...>&&) _NOEXCEPT; + +template +typename tuple_element<_Ip, pair<_T1, _T2> >::type& +get(pair<_T1, _T2>&) _NOEXCEPT; + +template +const typename tuple_element<_Ip, pair<_T1, _T2> >::type& +get(const pair<_T1, _T2>&) _NOEXCEPT; + +template +typename tuple_element<_Ip, pair<_T1, _T2> >::type&& +get(pair<_T1, _T2>&&) _NOEXCEPT; + +template +_Tp& +get(array<_Tp, _Size>&) _NOEXCEPT; + +template +const _Tp& +get(const array<_Tp, _Size>&) _NOEXCEPT; + +template +_Tp&& +get(array<_Tp, _Size>&&) _NOEXCEPT; + +// __make_tuple_indices + +template struct __tuple_indices {}; + +template +struct __make_indices_imp; + +template +struct __make_indices_imp<_Sp, __tuple_indices<_Indices...>, _Ep> +{ + typedef typename __make_indices_imp<_Sp+1, __tuple_indices<_Indices..., _Sp>, _Ep>::type type; +}; + +template +struct __make_indices_imp<_Ep, __tuple_indices<_Indices...>, _Ep> +{ + typedef __tuple_indices<_Indices...> type; +}; + +template +struct __make_tuple_indices +{ + static_assert(_Sp <= _Ep, "__make_tuple_indices input error"); + typedef typename __make_indices_imp<_Sp, __tuple_indices<>, _Ep>::type type; +}; + +// __tuple_types + +template struct __tuple_types {}; + +template +class _LIBCPP_VISIBLE tuple_element<_Ip, __tuple_types<> > +{ +public: + static_assert(_Ip == 0, "tuple_element index out of range"); + static_assert(_Ip != 0, "tuple_element index out of range"); +}; + +template +class _LIBCPP_VISIBLE tuple_element<0, __tuple_types<_Hp, _Tp...> > +{ +public: + typedef _Hp type; +}; + +template +class _LIBCPP_VISIBLE tuple_element<_Ip, __tuple_types<_Hp, _Tp...> > +{ +public: + typedef typename tuple_element<_Ip-1, __tuple_types<_Tp...> >::type type; +}; + +template +class _LIBCPP_VISIBLE tuple_size<__tuple_types<_Tp...> > + : public integral_constant +{ +}; + +template struct __tuple_like<__tuple_types<_Tp...> > : true_type {}; + +// __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 +struct __make_tuple_types_imp; + +template +struct __make_tuple_types_imp<__tuple_types<_Types...>, _Tp, _Sp, _Ep> +{ + typedef typename remove_reference<_Tp>::type _Tpr; + typedef typename __make_tuple_types_imp<__tuple_types<_Types..., + typename conditional::value, + typename tuple_element<_Sp, _Tpr>::type&, + typename tuple_element<_Sp, _Tpr>::type>::type>, + _Tp, _Sp+1, _Ep>::type type; +}; + +template +struct __make_tuple_types_imp<__tuple_types<_Types...>, _Tp, _Ep, _Ep> +{ + typedef __tuple_types<_Types...> type; +}; + +template ::type>::value, size_t _Sp = 0> +struct __make_tuple_types +{ + static_assert(_Sp <= _Ep, "__make_tuple_types input error"); + typedef typename __make_tuple_types_imp<__tuple_types<>, _Tp, _Sp, _Ep>::type type; +}; + +// __tuple_convertible + +template +struct __tuple_convertible_imp : public false_type {}; + +template +struct __tuple_convertible_imp, __tuple_types<_Up0, _Up...> > + : public integral_constant::value && + __tuple_convertible_imp, __tuple_types<_Up...> >::value> {}; + +template <> +struct __tuple_convertible_imp, __tuple_types<> > + : public true_type {}; + +template ::type>::value, + bool = __tuple_like<_Up>::value> +struct __tuple_convertible + : public false_type {}; + +template +struct __tuple_convertible<_Tp, _Up, true, true> + : public __tuple_convertible_imp::type>::value == + tuple_size<_Up>::value, + typename __make_tuple_types<_Tp>::type, typename __make_tuple_types<_Up>::type> +{}; + +// __tuple_constructible + +template +struct __tuple_constructible_imp : public false_type {}; + +template +struct __tuple_constructible_imp, __tuple_types<_Up0, _Up...> > + : public integral_constant::value && + __tuple_constructible_imp, __tuple_types<_Up...> >::value> {}; + +template <> +struct __tuple_constructible_imp, __tuple_types<> > + : public true_type {}; + +template ::type>::value, + bool = __tuple_like<_Up>::value> +struct __tuple_constructible + : public false_type {}; + +template +struct __tuple_constructible<_Tp, _Up, true, true> + : public __tuple_constructible_imp::type>::value == + tuple_size<_Up>::value, + typename __make_tuple_types<_Tp>::type, typename __make_tuple_types<_Up>::type> +{}; + +// __tuple_assignable + +template +struct __tuple_assignable_imp : public false_type {}; + +template +struct __tuple_assignable_imp, __tuple_types<_Up0, _Up...> > + : public integral_constant::value && + __tuple_assignable_imp, __tuple_types<_Up...> >::value> {}; + +template <> +struct __tuple_assignable_imp, __tuple_types<> > + : public true_type {}; + +template ::type>::value, + bool = __tuple_like<_Up>::value> +struct __tuple_assignable + : public false_type {}; + +template +struct __tuple_assignable<_Tp, _Up, true, true> + : public __tuple_assignable_imp::type>::value == + tuple_size<_Up>::value, + typename __make_tuple_types<_Tp>::type, typename __make_tuple_types<_Up>::type> +{}; + +_LIBCPP_END_NAMESPACE_STD + +#endif // _LIBCPP_HAS_NO_VARIADICS + +#endif // _LIBCPP___TUPLE Index: stable/9/contrib/libc++/include/algorithm =================================================================== --- stable/9/contrib/libc++/include/algorithm (nonexistent) +++ stable/9/contrib/libc++/include/algorithm (revision 235798) @@ -0,0 +1,5401 @@ +// -*- C++ -*- +//===-------------------------- algorithm ---------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP_ALGORITHM +#define _LIBCPP_ALGORITHM + +/* + algorithm synopsis + +#include + +namespace std +{ + +template + bool + all_of(InputIterator first, InputIterator last, Predicate pred); + +template + bool + any_of(InputIterator first, InputIterator last, Predicate pred); + +template + bool + none_of(InputIterator first, InputIterator last, Predicate pred); + +template + Function + for_each(InputIterator first, InputIterator last, Function f); + +template + InputIterator + find(InputIterator first, InputIterator last, const T& value); + +template + InputIterator + find_if(InputIterator first, InputIterator last, Predicate pred); + +template + InputIterator + find_if_not(InputIterator first, InputIterator last, Predicate pred); + +template + ForwardIterator1 + find_end(ForwardIterator1 first1, ForwardIterator1 last1, + ForwardIterator2 first2, ForwardIterator2 last2); + +template + ForwardIterator1 + find_end(ForwardIterator1 first1, ForwardIterator1 last1, + ForwardIterator2 first2, ForwardIterator2 last2, BinaryPredicate pred); + +template + ForwardIterator1 + find_first_of(ForwardIterator1 first1, ForwardIterator1 last1, + ForwardIterator2 first2, ForwardIterator2 last2); + +template + ForwardIterator1 + find_first_of(ForwardIterator1 first1, ForwardIterator1 last1, + ForwardIterator2 first2, ForwardIterator2 last2, BinaryPredicate pred); + +template + ForwardIterator + adjacent_find(ForwardIterator first, ForwardIterator last); + +template + ForwardIterator + adjacent_find(ForwardIterator first, ForwardIterator last, BinaryPredicate pred); + +template + typename iterator_traits::difference_type + count(InputIterator first, InputIterator last, const T& value); + +template + typename iterator_traits::difference_type + count_if(InputIterator first, InputIterator last, Predicate pred); + +template + pair + mismatch(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2); + +template + pair + mismatch(InputIterator1 first1, InputIterator1 last1, + InputIterator2 first2, BinaryPredicate pred); + +template + bool + equal(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2); + +template + bool + equal(InputIterator1 first1, InputIterator1 last1, + InputIterator2 first2, BinaryPredicate pred); + +template + bool + is_permutation(ForwardIterator1 first1, ForwardIterator1 last1, + ForwardIterator2 first2); + +template + bool + is_permutation(ForwardIterator1 first1, ForwardIterator1 last1, + ForwardIterator2 first2, BinaryPredicate pred); + +template + ForwardIterator1 + search(ForwardIterator1 first1, ForwardIterator1 last1, + ForwardIterator2 first2, ForwardIterator2 last2); + +template + ForwardIterator1 + search(ForwardIterator1 first1, ForwardIterator1 last1, + ForwardIterator2 first2, ForwardIterator2 last2, BinaryPredicate pred); + +template + ForwardIterator + search_n(ForwardIterator first, ForwardIterator last, Size count, const T& value); + +template + ForwardIterator + search_n(ForwardIterator first, ForwardIterator last, + Size count, const T& value, BinaryPredicate pred); + +template + OutputIterator + copy(InputIterator first, InputIterator last, OutputIterator result); + +template + OutputIterator + copy_if(InputIterator first, InputIterator last, + OutputIterator result, Predicate pred); + +template + OutputIterator + copy_n(InputIterator first, Size n, OutputIterator result); + +template + BidirectionalIterator2 + copy_backward(BidirectionalIterator1 first, BidirectionalIterator1 last, + BidirectionalIterator2 result); + +template + ForwardIterator2 + swap_ranges(ForwardIterator1 first1, ForwardIterator1 last1, ForwardIterator2 first2); + +template + void + iter_swap(ForwardIterator1 a, ForwardIterator2 b); + +template + OutputIterator + transform(InputIterator first, InputIterator last, OutputIterator result, UnaryOperation op); + +template + OutputIterator + transform(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, + OutputIterator result, BinaryOperation binary_op); + +template + void + replace(ForwardIterator first, ForwardIterator last, const T& old_value, const T& new_value); + +template + void + replace_if(ForwardIterator first, ForwardIterator last, Predicate pred, const T& new_value); + +template + OutputIterator + replace_copy(InputIterator first, InputIterator last, OutputIterator result, + const T& old_value, const T& new_value); + +template + OutputIterator + replace_copy_if(InputIterator first, InputIterator last, OutputIterator result, Predicate pred, const T& new_value); + +template + void + fill(ForwardIterator first, ForwardIterator last, const T& value); + +template + OutputIterator + fill_n(OutputIterator first, Size n, const T& value); + +template + void + generate(ForwardIterator first, ForwardIterator last, Generator gen); + +template + OutputIterator + generate_n(OutputIterator first, Size n, Generator gen); + +template + ForwardIterator + remove(ForwardIterator first, ForwardIterator last, const T& value); + +template + ForwardIterator + remove_if(ForwardIterator first, ForwardIterator last, Predicate pred); + +template + OutputIterator + remove_copy(InputIterator first, InputIterator last, OutputIterator result, const T& value); + +template + OutputIterator + remove_copy_if(InputIterator first, InputIterator last, OutputIterator result, Predicate pred); + +template + ForwardIterator + unique(ForwardIterator first, ForwardIterator last); + +template + ForwardIterator + unique(ForwardIterator first, ForwardIterator last, BinaryPredicate pred); + +template + OutputIterator + unique_copy(InputIterator first, InputIterator last, OutputIterator result); + +template + OutputIterator + unique_copy(InputIterator first, InputIterator last, OutputIterator result, BinaryPredicate pred); + +template + void + reverse(BidirectionalIterator first, BidirectionalIterator last); + +template + OutputIterator + reverse_copy(BidirectionalIterator first, BidirectionalIterator last, OutputIterator result); + +template + ForwardIterator + rotate(ForwardIterator first, ForwardIterator middle, ForwardIterator last); + +template + OutputIterator + rotate_copy(ForwardIterator first, ForwardIterator middle, ForwardIterator last, OutputIterator result); + +template + void + random_shuffle(RandomAccessIterator first, RandomAccessIterator last); + +template + void + random_shuffle(RandomAccessIterator first, RandomAccessIterator last, RandomNumberGenerator& rand); + +template + void shuffle(RandomAccessIterator first, RandomAccessIterator last, + UniformRandomNumberGenerator&& g); + +template + bool + is_partitioned(InputIterator first, InputIterator last, Predicate pred); + +template + ForwardIterator + partition(ForwardIterator first, ForwardIterator last, Predicate pred); + +template + pair + partition_copy(InputIterator first, InputIterator last, + OutputIterator1 out_true, OutputIterator2 out_false, + Predicate pred); + +template + ForwardIterator + stable_partition(ForwardIterator first, ForwardIterator last, Predicate pred); + +template + ForwardIterator + partition_point(ForwardIterator first, ForwardIterator last, Predicate pred); + +template + bool + is_sorted(ForwardIterator first, ForwardIterator last); + +template + bool + is_sorted(ForwardIterator first, ForwardIterator last, Compare comp); + +template + ForwardIterator + is_sorted_until(ForwardIterator first, ForwardIterator last); + +template + ForwardIterator + is_sorted_until(ForwardIterator first, ForwardIterator last, Compare comp); + +template + void + sort(RandomAccessIterator first, RandomAccessIterator last); + +template + void + sort(RandomAccessIterator first, RandomAccessIterator last, Compare comp); + +template + void + stable_sort(RandomAccessIterator first, RandomAccessIterator last); + +template + void + stable_sort(RandomAccessIterator first, RandomAccessIterator last, Compare comp); + +template + void + partial_sort(RandomAccessIterator first, RandomAccessIterator middle, RandomAccessIterator last); + +template + void + partial_sort(RandomAccessIterator first, RandomAccessIterator middle, RandomAccessIterator last, Compare comp); + +template + RandomAccessIterator + partial_sort_copy(InputIterator first, InputIterator last, + RandomAccessIterator result_first, RandomAccessIterator result_last); + +template + RandomAccessIterator + partial_sort_copy(InputIterator first, InputIterator last, + RandomAccessIterator result_first, RandomAccessIterator result_last, Compare comp); + +template + void + nth_element(RandomAccessIterator first, RandomAccessIterator nth, RandomAccessIterator last); + +template + void + nth_element(RandomAccessIterator first, RandomAccessIterator nth, RandomAccessIterator last, Compare comp); + +template + ForwardIterator + lower_bound(ForwardIterator first, ForwardIterator last, const T& value); + +template + ForwardIterator + lower_bound(ForwardIterator first, ForwardIterator last, const T& value, Compare comp); + +template + ForwardIterator + upper_bound(ForwardIterator first, ForwardIterator last, const T& value); + +template + ForwardIterator + upper_bound(ForwardIterator first, ForwardIterator last, const T& value, Compare comp); + +template + pair + equal_range(ForwardIterator first, ForwardIterator last, const T& value); + +template + pair + equal_range(ForwardIterator first, ForwardIterator last, const T& value, Compare comp); + +template + bool + binary_search(ForwardIterator first, ForwardIterator last, const T& value); + +template + bool + binary_search(ForwardIterator first, ForwardIterator last, const T& value, Compare comp); + +template + OutputIterator + merge(InputIterator1 first1, InputIterator1 last1, + InputIterator2 first2, InputIterator2 last2, OutputIterator result); + +template + OutputIterator + merge(InputIterator1 first1, InputIterator1 last1, + InputIterator2 first2, InputIterator2 last2, OutputIterator result, Compare comp); + +template + void + inplace_merge(BidirectionalIterator first, BidirectionalIterator middle, BidirectionalIterator last); + +template + void + inplace_merge(BidirectionalIterator first, BidirectionalIterator middle, BidirectionalIterator last, Compare comp); + +template + bool + includes(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, InputIterator2 last2); + +template + bool + includes(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, InputIterator2 last2, Compare comp); + +template + OutputIterator + set_union(InputIterator1 first1, InputIterator1 last1, + InputIterator2 first2, InputIterator2 last2, OutputIterator result); + +template + OutputIterator + set_union(InputIterator1 first1, InputIterator1 last1, + InputIterator2 first2, InputIterator2 last2, OutputIterator result, Compare comp); + +template + OutputIterator + set_intersection(InputIterator1 first1, InputIterator1 last1, + InputIterator2 first2, InputIterator2 last2, OutputIterator result); + +template + OutputIterator + set_intersection(InputIterator1 first1, InputIterator1 last1, + InputIterator2 first2, InputIterator2 last2, OutputIterator result, Compare comp); + +template + OutputIterator + set_difference(InputIterator1 first1, InputIterator1 last1, + InputIterator2 first2, InputIterator2 last2, OutputIterator result); + +template + OutputIterator + set_difference(InputIterator1 first1, InputIterator1 last1, + InputIterator2 first2, InputIterator2 last2, OutputIterator result, Compare comp); + +template + OutputIterator + set_symmetric_difference(InputIterator1 first1, InputIterator1 last1, + InputIterator2 first2, InputIterator2 last2, OutputIterator result); + +template + OutputIterator + set_symmetric_difference(InputIterator1 first1, InputIterator1 last1, + InputIterator2 first2, InputIterator2 last2, OutputIterator result, Compare comp); + +template + void + push_heap(RandomAccessIterator first, RandomAccessIterator last); + +template + void + push_heap(RandomAccessIterator first, RandomAccessIterator last, Compare comp); + +template + void + pop_heap(RandomAccessIterator first, RandomAccessIterator last); + +template + void + pop_heap(RandomAccessIterator first, RandomAccessIterator last, Compare comp); + +template + void + make_heap(RandomAccessIterator first, RandomAccessIterator last); + +template + void + make_heap(RandomAccessIterator first, RandomAccessIterator last, Compare comp); + +template + void + sort_heap(RandomAccessIterator first, RandomAccessIterator last); + +template + void + sort_heap(RandomAccessIterator first, RandomAccessIterator last, Compare comp); + +template + bool + is_heap(RandomAccessIterator first, RandomAccessiterator last); + +template + bool + is_heap(RandomAccessIterator first, RandomAccessiterator last, Compare comp); + +template + RandomAccessIterator + is_heap_until(RandomAccessIterator first, RandomAccessiterator last); + +template + RandomAccessIterator + is_heap_until(RandomAccessIterator first, RandomAccessiterator last, Compare comp); + +template + ForwardIterator + min_element(ForwardIterator first, ForwardIterator last); + +template + ForwardIterator + min_element(ForwardIterator first, ForwardIterator last, Compare comp); + +template + const T& + min(const T& a, const T& b); + +template + const T& + min(const T& a, const T& b, Compare comp); + +template + T + min(initializer_list t); + +template + T + min(initializer_list t, Compare comp); + +template + ForwardIterator + max_element(ForwardIterator first, ForwardIterator last); + +template + ForwardIterator + max_element(ForwardIterator first, ForwardIterator last, Compare comp); + +template + const T& + max(const T& a, const T& b); + +template + const T& + max(const T& a, const T& b, Compare comp); + +template + T + max(initializer_list t); + +template + T + max(initializer_list t, Compare comp); + +template + pair + minmax_element(ForwardIterator first, ForwardIterator last); + +template + pair + minmax_element(ForwardIterator first, ForwardIterator last, Compare comp); + +template + pair + minmax(const T& a, const T& b); + +template + pair + minmax(const T& a, const T& b, Compare comp); + +template + pair + minmax(initializer_list t); + +template + pair + minmax(initializer_list t, Compare comp); + +template + bool + lexicographical_compare(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, InputIterator2 last2); + +template + bool + lexicographical_compare(InputIterator1 first1, InputIterator1 last1, + InputIterator2 first2, InputIterator2 last2, Compare comp); + +template + bool + next_permutation(BidirectionalIterator first, BidirectionalIterator last); + +template + bool + next_permutation(BidirectionalIterator first, BidirectionalIterator last, Compare comp); + +template + bool + prev_permutation(BidirectionalIterator first, BidirectionalIterator last); + +template + bool + prev_permutation(BidirectionalIterator first, BidirectionalIterator last, Compare comp); + +} // std + +*/ + +#include <__config> +#include +#include +#include +#include +#include +#include +#include + +#include <__undef_min_max> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCPP_BEGIN_NAMESPACE_STD + +template +struct __equal_to +{ + _LIBCPP_INLINE_VISIBILITY bool operator()(const _T1& __x, const _T1& __y) const {return __x == __y;} + _LIBCPP_INLINE_VISIBILITY bool operator()(const _T1& __x, const _T2& __y) const {return __x == __y;} + _LIBCPP_INLINE_VISIBILITY bool operator()(const _T2& __x, const _T1& __y) const {return __x == __y;} + _LIBCPP_INLINE_VISIBILITY bool operator()(const _T2& __x, const _T2& __y) const {return __x == __y;} +}; + +template +struct __equal_to<_T1, _T1> +{ + _LIBCPP_INLINE_VISIBILITY bool operator()(const _T1& __x, const _T1& __y) const {return __x == __y;} +}; + +template +struct __equal_to +{ + _LIBCPP_INLINE_VISIBILITY bool operator()(const _T1& __x, const _T1& __y) const {return __x == __y;} +}; + +template +struct __equal_to<_T1, const _T1> +{ + _LIBCPP_INLINE_VISIBILITY bool operator()(const _T1& __x, const _T1& __y) const {return __x == __y;} +}; + +template +struct __less +{ + _LIBCPP_INLINE_VISIBILITY bool operator()(const _T1& __x, const _T1& __y) const {return __x < __y;} + _LIBCPP_INLINE_VISIBILITY bool operator()(const _T1& __x, const _T2& __y) const {return __x < __y;} + _LIBCPP_INLINE_VISIBILITY bool operator()(const _T2& __x, const _T1& __y) const {return __x < __y;} + _LIBCPP_INLINE_VISIBILITY bool operator()(const _T2& __x, const _T2& __y) const {return __x < __y;} +}; + +template +struct __less<_T1, _T1> +{ + _LIBCPP_INLINE_VISIBILITY bool operator()(const _T1& __x, const _T1& __y) const {return __x < __y;} +}; + +template +struct __less +{ + _LIBCPP_INLINE_VISIBILITY bool operator()(const _T1& __x, const _T1& __y) const {return __x < __y;} +}; + +template +struct __less<_T1, const _T1> +{ + _LIBCPP_INLINE_VISIBILITY bool operator()(const _T1& __x, const _T1& __y) const {return __x < __y;} +}; + +template +class __negate +{ +private: + _Predicate __p_; +public: + _LIBCPP_INLINE_VISIBILITY __negate() {} + + _LIBCPP_INLINE_VISIBILITY + explicit __negate(_Predicate __p) : __p_(__p) {} + + template + _LIBCPP_INLINE_VISIBILITY + bool operator()(const _T1& __x) {return !__p_(__x);} + + template + _LIBCPP_INLINE_VISIBILITY + bool operator()(const _T1& __x, const _T2& __y) {return !__p_(__x, __y);} +}; + +#ifdef _LIBCPP_DEBUG2 + +template +struct __debug_less +{ + _Compare __comp_; + __debug_less(_Compare& __c) : __comp_(__c) {} + template + bool operator()(const _Tp& __x, const _Up& __y) + { + bool __r = __comp_(__x, __y); + if (__r) + _LIBCPP_ASSERT(!__comp_(__y, __x), "Comparator does not induce a strict weak ordering"); + return __r; + } +}; + +#endif // _LIBCPP_DEBUG2 + +// Precondition: __x != 0 +inline _LIBCPP_INLINE_VISIBILITY +unsigned +__ctz(unsigned __x) +{ + return static_cast(__builtin_ctz(__x)); +} + +inline _LIBCPP_INLINE_VISIBILITY +unsigned long +__ctz(unsigned long __x) +{ + return static_cast(__builtin_ctzl(__x)); +} + +inline _LIBCPP_INLINE_VISIBILITY +unsigned long long +__ctz(unsigned long long __x) +{ + return static_cast(__builtin_ctzll(__x)); +} + +// Precondition: __x != 0 +inline _LIBCPP_INLINE_VISIBILITY +unsigned +__clz(unsigned __x) +{ + return static_cast(__builtin_clz(__x)); +} + +inline _LIBCPP_INLINE_VISIBILITY +unsigned long +__clz(unsigned long __x) +{ + return static_cast(__builtin_clzl (__x)); +} + +inline _LIBCPP_INLINE_VISIBILITY +unsigned long long +__clz(unsigned long long __x) +{ + return static_cast(__builtin_clzll(__x)); +} + +inline _LIBCPP_INLINE_VISIBILITY int __pop_count(unsigned __x) {return __builtin_popcount (__x);} +inline _LIBCPP_INLINE_VISIBILITY int __pop_count(unsigned long __x) {return __builtin_popcountl (__x);} +inline _LIBCPP_INLINE_VISIBILITY int __pop_count(unsigned long long __x) {return __builtin_popcountll(__x);} + +// all_of + +template +inline _LIBCPP_INLINE_VISIBILITY +bool +all_of(_InputIterator __first, _InputIterator __last, _Predicate __pred) +{ + for (; __first != __last; ++__first) + if (!__pred(*__first)) + return false; + return true; +} + +// any_of + +template +inline _LIBCPP_INLINE_VISIBILITY +bool +any_of(_InputIterator __first, _InputIterator __last, _Predicate __pred) +{ + for (; __first != __last; ++__first) + if (__pred(*__first)) + return true; + return false; +} + +// none_of + +template +inline _LIBCPP_INLINE_VISIBILITY +bool +none_of(_InputIterator __first, _InputIterator __last, _Predicate __pred) +{ + for (; __first != __last; ++__first) + if (__pred(*__first)) + return false; + return true; +} + +// for_each + +template +inline _LIBCPP_INLINE_VISIBILITY +_Function +for_each(_InputIterator __first, _InputIterator __last, _Function __f) +{ + for (; __first != __last; ++__first) + __f(*__first); + return _VSTD::move(__f); +} + +// find + +template +inline _LIBCPP_INLINE_VISIBILITY +_InputIterator +find(_InputIterator __first, _InputIterator __last, const _Tp& __value_) +{ + for (; __first != __last; ++__first) + if (*__first == __value_) + break; + return __first; +} + +// find_if + +template +inline _LIBCPP_INLINE_VISIBILITY +_InputIterator +find_if(_InputIterator __first, _InputIterator __last, _Predicate __pred) +{ + for (; __first != __last; ++__first) + if (__pred(*__first)) + break; + return __first; +} + +// find_if_not + +template +inline _LIBCPP_INLINE_VISIBILITY +_InputIterator +find_if_not(_InputIterator __first, _InputIterator __last, _Predicate __pred) +{ + for (; __first != __last; ++__first) + if (!__pred(*__first)) + break; + return __first; +} + +// find_end + +template +_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 +_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 +_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 +inline _LIBCPP_INLINE_VISIBILITY +_ForwardIterator1 +find_end(_ForwardIterator1 __first1, _ForwardIterator1 __last1, + _ForwardIterator2 __first2, _ForwardIterator2 __last2, _BinaryPredicate __pred) +{ + return _VSTD::__find_end::type> + (__first1, __last1, __first2, __last2, __pred, + typename iterator_traits<_ForwardIterator1>::iterator_category(), + typename iterator_traits<_ForwardIterator2>::iterator_category()); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +_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 +_ForwardIterator1 +find_first_of(_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 +inline _LIBCPP_INLINE_VISIBILITY +_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(__first1, __last1, __first2, __last2, __equal_to<__v1, __v2>()); +} + +// adjacent_find + +template +inline _LIBCPP_INLINE_VISIBILITY +_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 +inline _LIBCPP_INLINE_VISIBILITY +_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 +inline _LIBCPP_INLINE_VISIBILITY +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 +inline _LIBCPP_INLINE_VISIBILITY +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 +inline _LIBCPP_INLINE_VISIBILITY +pair<_InputIterator1, _InputIterator2> +mismatch(_InputIterator1 __first1, _InputIterator1 __last1, + _InputIterator2 __first2, _BinaryPredicate __pred) +{ + for (; __first1 != __last1; ++__first1, ++__first2) + if (!__pred(*__first1, *__first2)) + break; + return pair<_InputIterator1, _InputIterator2>(__first1, __first2); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +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>()); +} + +// equal + +template +inline _LIBCPP_INLINE_VISIBILITY +bool +equal(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2, _BinaryPredicate __pred) +{ + for (; __first1 != __last1; ++__first1, ++__first2) + if (!__pred(*__first1, *__first2)) + return false; + return true; +} + +template +inline _LIBCPP_INLINE_VISIBILITY +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>()); +} + +// is_permutation + +template +bool +is_permutation(_ForwardIterator1 __first1, _ForwardIterator1 __last1, + _ForwardIterator2 __first2, _BinaryPredicate __pred) +{ + // shorten sequences as much as possible by lopping of any equal parts + for (; __first1 != __last1; ++__first1, ++__first2) + if (!__pred(*__first1, *__first2)) + goto __not_done; + return true; +__not_done: + // __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)? + for (_ForwardIterator1 __j = __first1; __j != __i; ++__j) + if (__pred(*__j, *__i)) + goto __next_iter; + { + // 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; + } +__next_iter:; + } + return true; +} + +template +inline _LIBCPP_INLINE_VISIBILITY +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>()); +} + +// search + +template +_ForwardIterator1 +__search(_ForwardIterator1 __first1, _ForwardIterator1 __last1, + _ForwardIterator2 __first2, _ForwardIterator2 __last2, _BinaryPredicate __pred, + forward_iterator_tag, forward_iterator_tag) +{ + if (__first2 == __last2) + return __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 __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 __first1; + if (++__m1 == __last1) // Otherwise if source exhaused, pattern not found + return __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 +_RandomAccessIterator1 +__search(_RandomAccessIterator1 __first1, _RandomAccessIterator1 __last1, + _RandomAccessIterator2 __first2, _RandomAccessIterator2 __last2, _BinaryPredicate __pred, + random_access_iterator_tag, random_access_iterator_tag) +{ + typedef typename std::iterator_traits<_RandomAccessIterator1>::difference_type _D1; + typedef typename std::iterator_traits<_RandomAccessIterator2>::difference_type _D2; + // Take advantage of knowing source and pattern lengths. Stop short when source is smaller than pattern + _D2 __len2 = __last2 - __first2; + if (__len2 == 0) + return __first1; + _D1 __len1 = __last1 - __first1; + if (__len1 < __len2) + return __last1; + const _RandomAccessIterator1 __s = __last1 - (__len2 - 1); // Start of pattern match can't go beyond here + while (true) + { +#if !_LIBCPP_UNROLL_LOOPS + while (true) + { + if (__first1 == __s) + return __last1; + if (__pred(*__first1, *__first2)) + break; + ++__first1; + } +#else // !_LIBCPP_UNROLL_LOOPS + for (_D1 __loop_unroll = (__s - __first1) / 4; __loop_unroll > 0; --__loop_unroll) + { + if (__pred(*__first1, *__first2)) + goto __phase2; + if (__pred(*++__first1, *__first2)) + goto __phase2; + if (__pred(*++__first1, *__first2)) + goto __phase2; + if (__pred(*++__first1, *__first2)) + goto __phase2; + ++__first1; + } + switch (__s - __first1) + { + case 3: + if (__pred(*__first1, *__first2)) + break; + ++__first1; + case 2: + if (__pred(*__first1, *__first2)) + break; + ++__first1; + case 1: + if (__pred(*__first1, *__first2)) + break; + case 0: + return __last1; + } + __phase2: +#endif // !_LIBCPP_UNROLL_LOOPS + _RandomAccessIterator1 __m1 = __first1; + _RandomAccessIterator2 __m2 = __first2; +#if !_LIBCPP_UNROLL_LOOPS + while (true) + { + if (++__m2 == __last2) + return __first1; + ++__m1; // no need to check range on __m1 because __s guarantees we have enough source + if (!__pred(*__m1, *__m2)) + { + ++__first1; + break; + } + } +#else // !_LIBCPP_UNROLL_LOOPS + ++__m2; + ++__m1; + for (_D2 __loop_unroll = (__last2 - __m2) / 4; __loop_unroll > 0; --__loop_unroll) + { + if (!__pred(*__m1, *__m2)) + goto __continue; + if (!__pred(*++__m1, *++__m2)) + goto __continue; + if (!__pred(*++__m1, *++__m2)) + goto __continue; + if (!__pred(*++__m1, *++__m2)) + goto __continue; + ++__m1; + ++__m2; + } + switch (__last2 - __m2) + { + case 3: + if (!__pred(*__m1, *__m2)) + break; + ++__m1; + ++__m2; + case 2: + if (!__pred(*__m1, *__m2)) + break; + ++__m1; + ++__m2; + case 1: + if (!__pred(*__m1, *__m2)) + break; + case 0: + return __first1; + } + __continue: + ++__first1; +#endif // !_LIBCPP_UNROLL_LOOPS + } +} + +template +inline _LIBCPP_INLINE_VISIBILITY +_ForwardIterator1 +search(_ForwardIterator1 __first1, _ForwardIterator1 __last1, + _ForwardIterator2 __first2, _ForwardIterator2 __last2, _BinaryPredicate __pred) +{ + return _VSTD::__search::type> + (__first1, __last1, __first2, __last2, __pred, + typename std::iterator_traits<_ForwardIterator1>::iterator_category(), + typename std::iterator_traits<_ForwardIterator2>::iterator_category()); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +_ForwardIterator1 +search(_ForwardIterator1 __first1, _ForwardIterator1 __last1, + _ForwardIterator2 __first2, _ForwardIterator2 __last2) +{ + typedef typename std::iterator_traits<_ForwardIterator1>::value_type __v1; + typedef typename std::iterator_traits<_ForwardIterator2>::value_type __v2; + return _VSTD::search(__first1, __last1, __first2, __last2, __equal_to<__v1, __v2>()); +} + +// search_n + +template +_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 +_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 +inline _LIBCPP_INLINE_VISIBILITY +_ForwardIterator +search_n(_ForwardIterator __first, _ForwardIterator __last, + _Size __count, const _Tp& __value_, _BinaryPredicate __pred) +{ + return _VSTD::__search_n::type> + (__first, __last, __count, __value_, __pred, typename iterator_traits<_ForwardIterator>::iterator_category()); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +_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, __count, __value_, __equal_to<__v, _Tp>()); +} + +// copy + +template +struct __libcpp_is_trivial_iterator +{ + static const bool value = is_pointer<_Iter>::value; +}; + +template +struct __libcpp_is_trivial_iterator > +{ + static const bool value = is_pointer<_Iter>::value; +}; + +template +struct __libcpp_is_trivial_iterator<__wrap_iter<_Iter> > +{ + static const bool value = is_pointer<_Iter>::value; +}; + +template +inline _LIBCPP_INLINE_VISIBILITY +_Iter +__unwrap_iter(_Iter __i) +{ + return __i; +} + +template +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if +< + is_trivially_copy_assignable<_Tp>::value, + _Tp* +>::type +__unwrap_iter(move_iterator<_Tp*> __i) +{ + return __i.base(); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if +< + is_trivially_copy_assignable<_Tp>::value, + _Tp* +>::type +__unwrap_iter(__wrap_iter<_Tp*> __i) +{ + return __i.base(); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +_OutputIterator +__copy(_InputIterator __first, _InputIterator __last, _OutputIterator __result) +{ + for (; __first != __last; ++__first, ++__result) + *__result = *__first; + return __result; +} + +template +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if +< + is_same::type, _Up>::value && + is_trivially_copy_assignable<_Up>::value, + _Up* +>::type +__copy(_Tp* __first, _Tp* __last, _Up* __result) +{ + const size_t __n = static_cast(__last - __first); + _VSTD::memmove(__result, __first, __n * sizeof(_Up)); + return __result + __n; +} + +template +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 +inline _LIBCPP_INLINE_VISIBILITY +_OutputIterator +__copy_backward(_InputIterator __first, _InputIterator __last, _OutputIterator __result) +{ + while (__first != __last) + *--__result = *--__last; + return __result; +} + +template +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if +< + is_same::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(__last - __first); + __result -= __n; + _VSTD::memmove(__result, __first, __n * sizeof(_Up)); + return __result; +} + +template +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 +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 +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 __n, _OutputIterator __result) +{ + if (__n > 0) + { + *__result = *__first; + ++__result; + for (--__n; __n > 0; --__n) + { + ++__first; + *__result = *__first; + ++__result; + } + } + return __result; +} + +template +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if +< + __is_random_access_iterator<_InputIterator>::value, + _OutputIterator +>::type +copy_n(_InputIterator __first, _Size __n, _OutputIterator __result) +{ + return _VSTD::copy(__first, __first + __n, __result); +} + +// move + +template +inline _LIBCPP_INLINE_VISIBILITY +_OutputIterator +__move(_InputIterator __first, _InputIterator __last, _OutputIterator __result) +{ + for (; __first != __last; ++__first, ++__result) + *__result = _VSTD::move(*__first); + return __result; +} + +template +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if +< + is_same::type, _Up>::value && + is_trivially_copy_assignable<_Up>::value, + _Up* +>::type +__move(_Tp* __first, _Tp* __last, _Up* __result) +{ + const size_t __n = static_cast(__last - __first); + _VSTD::memmove(__result, __first, __n * sizeof(_Up)); + return __result + __n; +} + +template +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 +inline _LIBCPP_INLINE_VISIBILITY +_OutputIterator +__move_backward(_InputIterator __first, _InputIterator __last, _OutputIterator __result) +{ + while (__first != __last) + *--__result = _VSTD::move(*--__last); + return __result; +} + +template +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if +< + is_same::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(__last - __first); + __result -= __n; + _VSTD::memmove(__result, __first, __n * sizeof(_Up)); + return __result; +} + +template +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 for better swap / noexcept support + +// transform + +template +inline _LIBCPP_INLINE_VISIBILITY +_OutputIterator +transform(_InputIterator __first, _InputIterator __last, _OutputIterator __result, _UnaryOperation __op) +{ + for (; __first != __last; ++__first, ++__result) + *__result = __op(*__first); + return __result; +} + +template +inline _LIBCPP_INLINE_VISIBILITY +_OutputIterator +transform(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2, + _OutputIterator __result, _BinaryOperation __binary_op) +{ + for (; __first1 != __last1; ++__first1, ++__first2, ++__result) + *__result = __binary_op(*__first1, *__first2); + return __result; +} + +// replace + +template +inline _LIBCPP_INLINE_VISIBILITY +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 +inline _LIBCPP_INLINE_VISIBILITY +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 +inline _LIBCPP_INLINE_VISIBILITY +_OutputIterator +replace_copy(_InputIterator __first, _InputIterator __last, _OutputIterator __result, + const _Tp& __old_value, const _Tp& __new_value) +{ + for (; __first != __last; ++__first, ++__result) + if (*__first == __old_value) + *__result = __new_value; + else + *__result = *__first; + return __result; +} + +// replace_copy_if + +template +inline _LIBCPP_INLINE_VISIBILITY +_OutputIterator +replace_copy_if(_InputIterator __first, _InputIterator __last, _OutputIterator __result, + _Predicate __pred, const _Tp& __new_value) +{ + for (; __first != __last; ++__first, ++__result) + if (__pred(*__first)) + *__result = __new_value; + else + *__result = *__first; + return __result; +} + +// fill_n + +template +inline _LIBCPP_INLINE_VISIBILITY +_OutputIterator +__fill_n(_OutputIterator __first, _Size __n, const _Tp& __value_, false_type) +{ + for (; __n > 0; ++__first, --__n) + *__first = __value_; + return __first; +} + +template +inline _LIBCPP_INLINE_VISIBILITY +_OutputIterator +__fill_n(_OutputIterator __first, _Size __n, const _Tp& __value_, true_type) +{ + if (__n > 0) + _VSTD::memset(__first, (unsigned char)__value_, (size_t)(__n)); + return __first + __n; +} + +template +inline _LIBCPP_INLINE_VISIBILITY +_OutputIterator +fill_n(_OutputIterator __first, _Size __n, const _Tp& __value_) +{ + return _VSTD::__fill_n(__first, __n, __value_, integral_constant::value && + is_trivially_copy_assignable<_Tp>::value && + sizeof(_Tp) == 1>()); +} + +// fill + +template +inline _LIBCPP_INLINE_VISIBILITY +void +__fill(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value_, forward_iterator_tag) +{ + for (; __first != __last; ++__first) + *__first = __value_; +} + +template +inline _LIBCPP_INLINE_VISIBILITY +void +__fill(_RandomAccessIterator __first, _RandomAccessIterator __last, const _Tp& __value_, random_access_iterator_tag) +{ + _VSTD::fill_n(__first, __last - __first, __value_); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +void +fill(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value_) +{ + _VSTD::__fill(__first, __last, __value_, typename iterator_traits<_ForwardIterator>::iterator_category()); +} + +// generate + +template +inline _LIBCPP_INLINE_VISIBILITY +void +generate(_ForwardIterator __first, _ForwardIterator __last, _Generator __gen) +{ + for (; __first != __last; ++__first) + *__first = __gen(); +} + +// generate_n + +template +inline _LIBCPP_INLINE_VISIBILITY +_OutputIterator +generate_n(_OutputIterator __first, _Size __n, _Generator __gen) +{ + for (; __n > 0; ++__first, --__n) + *__first = __gen(); + return __first; +} + +// remove + +template +_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 +_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 +inline _LIBCPP_INLINE_VISIBILITY +_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 +inline _LIBCPP_INLINE_VISIBILITY +_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 +_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 +inline _LIBCPP_INLINE_VISIBILITY +_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 +_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 +_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 +_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 +inline _LIBCPP_INLINE_VISIBILITY +_OutputIterator +unique_copy(_InputIterator __first, _InputIterator __last, _OutputIterator __result, _BinaryPredicate __pred) +{ + return _VSTD::__unique_copy::type> + (__first, __last, __result, __pred, + typename iterator_traits<_InputIterator>::iterator_category(), + typename iterator_traits<_OutputIterator>::iterator_category()); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +_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 +inline _LIBCPP_INLINE_VISIBILITY +void +__reverse(_BidirectionalIterator __first, _BidirectionalIterator __last, bidirectional_iterator_tag) +{ + while (__first != __last) + { + if (__first == --__last) + break; + swap(*__first, *__last); + ++__first; + } +} + +template +inline _LIBCPP_INLINE_VISIBILITY +void +__reverse(_RandomAccessIterator __first, _RandomAccessIterator __last, random_access_iterator_tag) +{ + if (__first != __last) + for (; __first < --__last; ++__first) + swap(*__first, *__last); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +void +reverse(_BidirectionalIterator __first, _BidirectionalIterator __last) +{ + _VSTD::__reverse(__first, __last, typename iterator_traits<_BidirectionalIterator>::iterator_category()); +} + +// reverse_copy + +template +inline _LIBCPP_INLINE_VISIBILITY +_OutputIterator +reverse_copy(_BidirectionalIterator __first, _BidirectionalIterator __last, _OutputIterator __result) +{ + for (; __first != __last; ++__result) + *__result = *--__last; + return __result; +} + +// rotate + +template +_ForwardIterator +__rotate(_ForwardIterator __first, _ForwardIterator __middle, _ForwardIterator __last, false_type) +{ + if (__first == __middle) + return __last; + if (__middle == __last) + return __first; + _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 +inline _LIBCPP_INLINE_VISIBILITY +_Integral +__gcd(_Integral __x, _Integral __y) +{ + do + { + _Integral __t = __x % __y; + __x = __y; + __y = __t; + } while (__y); + return __x; +} + +template +_RandomAccessIterator +__rotate(_RandomAccessIterator __first, _RandomAccessIterator __middle, _RandomAccessIterator __last, true_type) +{ + typedef typename iterator_traits<_RandomAccessIterator>::difference_type difference_type; + typedef typename iterator_traits<_RandomAccessIterator>::value_type value_type; + + if (__first == __middle) + return __last; + if (__middle == __last) + return __first; + 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 = __gcd(__m1, __m2); + for (_RandomAccessIterator __p = __first + __g; __p != __first;) + { + value_type __t(*--__p); + _RandomAccessIterator __p1 = __p; + _RandomAccessIterator __p2 = __p1 + __m1; + do + { + *__p1 = *__p2; + __p1 = __p2; + const difference_type __d = __last - __p2; + if (__m1 < __d) + __p2 += __m1; + else + __p2 = __first + (__m1 - __d); + } while (__p2 != __p); + *__p1 = __t; + } + return __first + __m2; +} + +template +inline _LIBCPP_INLINE_VISIBILITY +_ForwardIterator +rotate(_ForwardIterator __first, _ForwardIterator __middle, _ForwardIterator __last) +{ + return _VSTD::__rotate(__first, __middle, __last, + integral_constant + < + bool, + is_convertible + < + typename iterator_traits<_ForwardIterator>::iterator_category, + random_access_iterator_tag + >::value && + is_trivially_copy_assignable + < + typename iterator_traits<_ForwardIterator>::value_type + >::value + >()); +} + +// rotate_copy + +template +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 +inline _LIBCPP_INLINE_VISIBILITY +_ForwardIterator +min_element(_ForwardIterator __first, _ForwardIterator __last, _Compare __comp) +{ + if (__first != __last) + { + _ForwardIterator __i = __first; + while (++__i != __last) + if (__comp(*__i, *__first)) + __first = __i; + } + return __first; +} + +template +inline _LIBCPP_INLINE_VISIBILITY +_ForwardIterator +min_element(_ForwardIterator __first, _ForwardIterator __last) +{ + return _VSTD::min_element(__first, __last, + __less::value_type>()); +} + +// min + +template +inline _LIBCPP_INLINE_VISIBILITY +const _Tp& +min(const _Tp& __a, const _Tp& __b, _Compare __comp) +{ + return __comp(__b, __a) ? __b : __a; +} + +template +inline _LIBCPP_INLINE_VISIBILITY +const _Tp& +min(const _Tp& __a, const _Tp& __b) +{ + return _VSTD::min(__a, __b, __less<_Tp>()); +} + +#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS + +template +inline _LIBCPP_INLINE_VISIBILITY +_Tp +min(initializer_list<_Tp> __t, _Compare __comp) +{ + return *_VSTD::min_element(__t.begin(), __t.end(), __comp); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +_Tp +min(initializer_list<_Tp> __t) +{ + return *_VSTD::min_element(__t.begin(), __t.end()); +} + +#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS + +// max_element + +template +inline _LIBCPP_INLINE_VISIBILITY +_ForwardIterator +max_element(_ForwardIterator __first, _ForwardIterator __last, _Compare __comp) +{ + if (__first != __last) + { + _ForwardIterator __i = __first; + while (++__i != __last) + if (__comp(*__first, *__i)) + __first = __i; + } + return __first; +} + +template +inline _LIBCPP_INLINE_VISIBILITY +_ForwardIterator +max_element(_ForwardIterator __first, _ForwardIterator __last) +{ + return _VSTD::max_element(__first, __last, + __less::value_type>()); +} + +// max + +template +inline _LIBCPP_INLINE_VISIBILITY +const _Tp& +max(const _Tp& __a, const _Tp& __b, _Compare __comp) +{ + return __comp(__a, __b) ? __b : __a; +} + +template +inline _LIBCPP_INLINE_VISIBILITY +const _Tp& +max(const _Tp& __a, const _Tp& __b) +{ + return _VSTD::max(__a, __b, __less<_Tp>()); +} + +#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS + +template +inline _LIBCPP_INLINE_VISIBILITY +_Tp +max(initializer_list<_Tp> __t, _Compare __comp) +{ + return *_VSTD::max_element(__t.begin(), __t.end(), __comp); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +_Tp +max(initializer_list<_Tp> __t) +{ + return *_VSTD::max_element(__t.begin(), __t.end()); +} + +#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS + +// minmax_element + +template +std::pair<_ForwardIterator, _ForwardIterator> +minmax_element(_ForwardIterator __first, _ForwardIterator __last, _Compare __comp) +{ + 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 +inline _LIBCPP_INLINE_VISIBILITY +std::pair<_ForwardIterator, _ForwardIterator> +minmax_element(_ForwardIterator __first, _ForwardIterator __last) +{ + return _VSTD::minmax_element(__first, __last, __less::value_type>()); +} + +// minmax + +template +inline _LIBCPP_INLINE_VISIBILITY +pair +minmax(const _Tp& __a, const _Tp& __b, _Compare __comp) +{ + return __comp(__b, __a) ? pair(__b, __a) : + pair(__a, __b); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +pair +minmax(const _Tp& __a, const _Tp& __b) +{ + return _VSTD::minmax(__a, __b, __less<_Tp>()); +} + +#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS + +template +inline _LIBCPP_INLINE_VISIBILITY +pair<_Tp, _Tp> +minmax(initializer_list<_Tp> __t) +{ + pair __p = + _VSTD::minmax_element(__t.begin(), __t.end()); + return pair<_Tp, _Tp>(*__p.first, *__p.second); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +pair<_Tp, _Tp> +minmax(initializer_list<_Tp> __t, _Compare __comp) +{ + pair __p = + _VSTD::minmax_element(__t.begin(), __t.end(), __comp); + return pair<_Tp, _Tp>(*__p.first, *__p.second); +} + +#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS + +// random_shuffle + +// __independent_bits_engine + +template +struct __log2_imp +{ + static const size_t value = _Xp & ((unsigned long long)(1) << _Rp) ? _Rp + : __log2_imp<_Xp, _Rp - 1>::value; +}; + +template +struct __log2_imp<_Xp, 0> +{ + static const size_t value = 0; +}; + +template +struct __log2_imp<0, _Rp> +{ + static const size_t value = _Rp + 1; +}; + +template +struct __log2 +{ + static const size_t value = __log2_imp<_Xp, + sizeof(_UI) * __CHAR_BIT__ - 1>::value; +}; + +template +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_HAS_NO_CONSTEXPR + 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());} + +private: + result_type __eval(false_type); + result_type __eval(true_type); +}; + +template +__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 +inline +_UIntType +__independent_bits_engine<_Engine, _UIntType>::__eval(false_type) +{ + return static_cast(__e_() & __mask0_); +} + +template +_UIntType +__independent_bits_engine<_Engine, _UIntType>::__eval(true_type) +{ + result_type _Sp = 0; + for (size_t __k = 0; __k < __n0_; ++__k) + { + _Engine_result_type __u; + do + { + __u = __e_() - _Engine::min(); + } while (__u >= __y0_); + if (__w0_ < _WDt) + _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_ < _WDt - 1) + _Sp <<= __w0_ + 1; + else + _Sp = 0; + _Sp += __u & __mask1_; + } + return _Sp; +} + +// uniform_int_distribution + +template +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::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::max()) + : __p_(param_type(__a, __b)) {} + explicit uniform_int_distribution(const param_type& __p) : __p_(__p) {} + void reset() {} + + // generating functions + template result_type operator()(_URNG& __g) + {return (*this)(__g, __p_);} + template 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 +template +typename uniform_int_distribution<_IntType>::result_type +uniform_int_distribution<_IntType>::operator()(_URNG& __g, const param_type& __p) +{ + typedef typename conditional::type _UIntType; + const _UIntType _Rp = __p.b() - __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(_Eng(__g, _Dt)()); + size_t __w = _Dt - __clz(_Rp) - 1; + if ((_Rp & (_UIntType(~0) >> (_Dt - __w))) != 0) + ++__w; + _Eng __e(__g, __w); + _UIntType __u; + do + { + __u = __e(); + } while (__u >= _Rp); + return static_cast(__u + __p.a()); +} + +class __rs_default; + +__rs_default __rs_get(); + +class __rs_default +{ + static unsigned __c_; + + __rs_default(); +public: + typedef unsigned 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 __rs_default __rs_get(); +}; + +__rs_default __rs_get(); + +template +void +random_shuffle(_RandomAccessIterator __first, _RandomAccessIterator __last) +{ + typedef typename iterator_traits<_RandomAccessIterator>::difference_type difference_type; + typedef uniform_int_distribution _Dp; + typedef typename _Dp::param_type _Pp; + difference_type __d = __last - __first; + if (__d > 1) + { + _Dp __uid; + __rs_default __g = __rs_get(); + for (--__last, --__d; __first < __last; ++__first, --__d) + { + difference_type __i = __uid(__g, _Pp(0, __d)); + if (__i != difference_type(0)) + swap(*__first, *(__first + __i)); + } + } +} + +template +void +random_shuffle(_RandomAccessIterator __first, _RandomAccessIterator __last, +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + _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, --__d) + { + difference_type __i = __rand(__d); + swap(*__first, *(__first + __i)); + } + } +} + +template + void shuffle(_RandomAccessIterator __first, _RandomAccessIterator __last, +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + _UniformRandomNumberGenerator&& __g) +#else + _UniformRandomNumberGenerator& __g) +#endif +{ + typedef typename iterator_traits<_RandomAccessIterator>::difference_type difference_type; + typedef uniform_int_distribution _Dp; + typedef typename _Dp::param_type _Pp; + difference_type __d = __last - __first; + if (__d > 1) + { + _Dp __uid; + for (--__last, --__d; __first < __last; ++__first, --__d) + { + difference_type __i = __uid(__g, _Pp(0, __d)); + if (__i != difference_type(0)) + swap(*__first, *(__first + __i)); + } + } +} + +template +bool +is_partitioned(_InputIterator __first, _InputIterator __last, _Predicate __pred) +{ + for (; __first != __last; ++__first) + if (!__pred(*__first)) + break; + for (; __first != __last; ++__first) + if (__pred(*__first)) + return false; + return true; +} + +// partition + +template +_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 +_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 +inline _LIBCPP_INLINE_VISIBILITY +_ForwardIterator +partition(_ForwardIterator __first, _ForwardIterator __last, _Predicate __pred) +{ + return _VSTD::__partition::type> + (__first, __last, __pred, typename iterator_traits<_ForwardIterator>::iterator_category()); +} + +// partition_copy + +template +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 +_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 = __len / 2; + _ForwardIterator __m = __first; + _VSTD::advance(__m, __l2); + if (__pred(*__m)) + { + __first = ++__m; + __len -= __l2 + 1; + } + else + __len = __l2; + } + return __first; +} + +// stable_partition + +template +_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 __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, ++__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 + _LIBCPP_INLINE_VISIBILITY void operator()(_Tp* __p) const {_VSTD::return_temporary_buffer(__p);} +}; + +template +_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 __p(0, 0); + unique_ptr __h; + if (__len >= __alloc_limit) + { + __p = _VSTD::get_temporary_buffer(__len); + __h.reset(__p.first); + } + return __stable_partition::type> + (__first, __last, __pred, __len, __p, forward_iterator_tag()); +} + +template +_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 __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, ++__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 +_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 __p(0, 0); + unique_ptr __h; + if (__len >= __alloc_limit) + { + __p = _VSTD::get_temporary_buffer(__len); + __h.reset(__p.first); + } + return __stable_partition::type> + (__first, __last, __pred, __len, __p, bidirectional_iterator_tag()); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +_ForwardIterator +stable_partition(_ForwardIterator __first, _ForwardIterator __last, _Predicate __pred) +{ + return __stable_partition::type> + (__first, __last, __pred, typename iterator_traits<_ForwardIterator>::iterator_category()); +} + +// is_sorted_until + +template +_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 +inline _LIBCPP_INLINE_VISIBILITY +_ForwardIterator +is_sorted_until(_ForwardIterator __first, _ForwardIterator __last) +{ + return _VSTD::is_sorted_until(__first, __last, __less::value_type>()); +} + +// is_sorted + +template +inline _LIBCPP_INLINE_VISIBILITY +bool +is_sorted(_ForwardIterator __first, _ForwardIterator __last, _Compare __comp) +{ + return _VSTD::is_sorted_until(__first, __last, __comp) == __last; +} + +template +inline _LIBCPP_INLINE_VISIBILITY +bool +is_sorted(_ForwardIterator __first, _ForwardIterator __last) +{ + return _VSTD::is_sorted(__first, __last, __less::value_type>()); +} + +// sort + +// stable, 2-3 compares, 0-2 swaps + +template +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 +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 +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 +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 +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 +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 +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 +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 __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 +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 && + is_trivially_copy_assignable::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 +inline _LIBCPP_INLINE_VISIBILITY +void +sort(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp) +{ +#ifdef _LIBCPP_DEBUG2 + typedef typename add_lvalue_reference<__debug_less<_Compare> >::type _Comp_ref; + __debug_less<_Compare> __c(__comp); + __sort<_Comp_ref>(__first, __last, __c); +#else // _LIBCPP_DEBUG2 + typedef typename add_lvalue_reference<_Compare>::type _Comp_ref; + __sort<_Comp_ref>(__first, __last, __comp); +#endif // _LIBCPP_DEBUG2 +} + +template +inline _LIBCPP_INLINE_VISIBILITY +void +sort(_RandomAccessIterator __first, _RandomAccessIterator __last) +{ + _VSTD::sort(__first, __last, __less::value_type>()); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +void +sort(_Tp** __first, _Tp** __last) +{ + _VSTD::sort((size_t*)__first, (size_t*)__last, __less()); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +void +sort(__wrap_iter<_Tp*> __first, __wrap_iter<_Tp*> __last) +{ + _VSTD::sort(__first.base(), __last.base()); +} + +template +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); +} + +#ifdef _MSC_VER +#pragma warning( push ) +#pragma warning( disable: 4231) +#endif // _MSC_VER +extern template void __sort<__less&, char*>(char*, char*, __less&); +extern template void __sort<__less&, wchar_t*>(wchar_t*, wchar_t*, __less&); +extern template void __sort<__less&, signed char*>(signed char*, signed char*, __less&); +extern template void __sort<__less&, unsigned char*>(unsigned char*, unsigned char*, __less&); +extern template void __sort<__less&, short*>(short*, short*, __less&); +extern template void __sort<__less&, unsigned short*>(unsigned short*, unsigned short*, __less&); +extern template void __sort<__less&, int*>(int*, int*, __less&); +extern template void __sort<__less&, unsigned*>(unsigned*, unsigned*, __less&); +extern template void __sort<__less&, long*>(long*, long*, __less&); +extern template void __sort<__less&, unsigned long*>(unsigned long*, unsigned long*, __less&); +extern template void __sort<__less&, long long*>(long long*, long long*, __less&); +extern template void __sort<__less&, unsigned long long*>(unsigned long long*, unsigned long long*, __less&); +extern template void __sort<__less&, float*>(float*, float*, __less&); +extern template void __sort<__less&, double*>(double*, double*, __less&); +extern template void __sort<__less&, long double*>(long double*, long double*, __less&); + +extern template bool __insertion_sort_incomplete<__less&, char*>(char*, char*, __less&); +extern template bool __insertion_sort_incomplete<__less&, wchar_t*>(wchar_t*, wchar_t*, __less&); +extern template bool __insertion_sort_incomplete<__less&, signed char*>(signed char*, signed char*, __less&); +extern template bool __insertion_sort_incomplete<__less&, unsigned char*>(unsigned char*, unsigned char*, __less&); +extern template bool __insertion_sort_incomplete<__less&, short*>(short*, short*, __less&); +extern template bool __insertion_sort_incomplete<__less&, unsigned short*>(unsigned short*, unsigned short*, __less&); +extern template bool __insertion_sort_incomplete<__less&, int*>(int*, int*, __less&); +extern template bool __insertion_sort_incomplete<__less&, unsigned*>(unsigned*, unsigned*, __less&); +extern template bool __insertion_sort_incomplete<__less&, long*>(long*, long*, __less&); +extern template bool __insertion_sort_incomplete<__less&, unsigned long*>(unsigned long*, unsigned long*, __less&); +extern template bool __insertion_sort_incomplete<__less&, long long*>(long long*, long long*, __less&); +extern template bool __insertion_sort_incomplete<__less&, unsigned long long*>(unsigned long long*, unsigned long long*, __less&); +extern template bool __insertion_sort_incomplete<__less&, float*>(float*, float*, __less&); +extern template bool __insertion_sort_incomplete<__less&, double*>(double*, double*, __less&); +extern template bool __insertion_sort_incomplete<__less&, long double*>(long double*, long double*, __less&); + +extern template unsigned __sort5<__less&, long double*>(long double*, long double*, long double*, long double*, long double*, __less&); +#ifdef _MSC_VER +#pragma warning( pop ) +#endif // _MSC_VER + +// lower_bound + +template +_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 = __len / 2; + _ForwardIterator __m = __first; + _VSTD::advance(__m, __l2); + if (__comp(*__m, __value_)) + { + __first = ++__m; + __len -= __l2 + 1; + } + else + __len = __l2; + } + return __first; +} + +template +inline _LIBCPP_INLINE_VISIBILITY +_ForwardIterator +lower_bound(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value_, _Compare __comp) +{ +#ifdef _LIBCPP_DEBUG2 + typedef typename add_lvalue_reference<__debug_less<_Compare> >::type _Comp_ref; + __debug_less<_Compare> __c(__comp); + return __lower_bound<_Comp_ref>(__first, __last, __value_, __c); +#else // _LIBCPP_DEBUG2 + typedef typename add_lvalue_reference<_Compare>::type _Comp_ref; + return __lower_bound<_Comp_ref>(__first, __last, __value_, __comp); +#endif // _LIBCPP_DEBUG2 +} + +template +inline _LIBCPP_INLINE_VISIBILITY +_ForwardIterator +lower_bound(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value_) +{ + return _VSTD::lower_bound(__first, __last, __value_, + __less::value_type, _Tp>()); +} + +// upper_bound + +template +_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 = __len / 2; + _ForwardIterator __m = __first; + _VSTD::advance(__m, __l2); + if (__comp(__value_, *__m)) + __len = __l2; + else + { + __first = ++__m; + __len -= __l2 + 1; + } + } + return __first; +} + +template +inline _LIBCPP_INLINE_VISIBILITY +_ForwardIterator +upper_bound(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value_, _Compare __comp) +{ +#ifdef _LIBCPP_DEBUG2 + typedef typename add_lvalue_reference<__debug_less<_Compare> >::type _Comp_ref; + __debug_less<_Compare> __c(__comp); + return __upper_bound<_Comp_ref>(__first, __last, __value_, __c); +#else // _LIBCPP_DEBUG2 + typedef typename add_lvalue_reference<_Compare>::type _Comp_ref; + return __upper_bound<_Comp_ref>(__first, __last, __value_, __comp); +#endif // _LIBCPP_DEBUG2 +} + +template +inline _LIBCPP_INLINE_VISIBILITY +_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 +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 = __len / 2; + _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 +inline _LIBCPP_INLINE_VISIBILITY +pair<_ForwardIterator, _ForwardIterator> +equal_range(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value_, _Compare __comp) +{ +#ifdef _LIBCPP_DEBUG2 + typedef typename add_lvalue_reference<__debug_less<_Compare> >::type _Comp_ref; + __debug_less<_Compare> __c(__comp); + return __equal_range<_Comp_ref>(__first, __last, __value_, __c); +#else // _LIBCPP_DEBUG2 + typedef typename add_lvalue_reference<_Compare>::type _Comp_ref; + return __equal_range<_Comp_ref>(__first, __last, __value_, __comp); +#endif // _LIBCPP_DEBUG2 +} + +template +inline _LIBCPP_INLINE_VISIBILITY +pair<_ForwardIterator, _ForwardIterator> +equal_range(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value_) +{ + return _VSTD::equal_range(__first, __last, __value_, + __less::value_type, _Tp>()); +} + +// binary_search + +template +inline _LIBCPP_INLINE_VISIBILITY +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 +inline _LIBCPP_INLINE_VISIBILITY +bool +binary_search(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value_, _Compare __comp) +{ +#ifdef _LIBCPP_DEBUG2 + typedef typename add_lvalue_reference<__debug_less<_Compare> >::type _Comp_ref; + __debug_less<_Compare> __c(__comp); + return __binary_search<_Comp_ref>(__first, __last, __value_, __c); +#else // _LIBCPP_DEBUG2 + typedef typename add_lvalue_reference<_Compare>::type _Comp_ref; + return __binary_search<_Comp_ref>(__first, __last, __value_, __comp); +#endif // _LIBCPP_DEBUG2 +} + +template +inline _LIBCPP_INLINE_VISIBILITY +bool +binary_search(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value_) +{ + return _VSTD::binary_search(__first, __last, __value_, + __less::value_type, _Tp>()); +} + +// merge + +template +_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 +inline _LIBCPP_INLINE_VISIBILITY +_OutputIterator +merge(_InputIterator1 __first1, _InputIterator1 __last1, + _InputIterator2 __first2, _InputIterator2 __last2, _OutputIterator __result, _Compare __comp) +{ +#ifdef _LIBCPP_DEBUG2 + typedef typename add_lvalue_reference<__debug_less<_Compare> >::type _Comp_ref; + __debug_less<_Compare> __c(__comp); + return _VSTD::__merge<_Comp_ref>(__first1, __last1, __first2, __last2, __result, __c); +#else // _LIBCPP_DEBUG2 + typedef typename add_lvalue_reference<_Compare>::type _Comp_ref; + return _VSTD::__merge<_Comp_ref>(__first1, __last1, __first2, __last2, __result, __comp); +#endif // _LIBCPP_DEBUG2 +} + +template +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 merge(__first1, __last1, __first2, __last2, __result, __less<__v1, __v2>()); +} + +// inplace_merge + +template +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; + typedef typename iterator_traits<_BidirectionalIterator>::difference_type difference_type; + typedef typename iterator_traits<_BidirectionalIterator>::pointer pointer; + __destruct_n __d(0); + unique_ptr __h2(__buff, __d); + if (__len1 <= __len2) + { + value_type* __p = __buff; + for (_BidirectionalIterator __i = __first; __i != __middle; __d.__incr((value_type*)0), ++__i, ++__p) + ::new(__p) value_type(_VSTD::move(*__i)); + __merge<_Compare>(move_iterator(__buff), + move_iterator(__p), + move_iterator<_BidirectionalIterator>(__middle), + move_iterator<_BidirectionalIterator>(__last), + __first, __comp); + } + else + { + value_type* __p = __buff; + for (_BidirectionalIterator __i = __middle; __i != __last; __d.__incr((value_type*)0), ++__i, ++__p) + ::new(__p) value_type(_VSTD::move(*__i)); + typedef reverse_iterator<_BidirectionalIterator> _RBi; + typedef reverse_iterator _Rv; + __merge(move_iterator<_RBi>(_RBi(__middle)), move_iterator<_RBi>(_RBi(__first)), + move_iterator<_Rv>(_Rv(__p)), move_iterator<_Rv>(_Rv(__buff)), + _RBi(__last), __negate<_Compare>(__comp)); + } +} + +template +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>::value_type value_type; + typedef typename iterator_traits<_BidirectionalIterator>::difference_type difference_type; + while (true) + { + // if __middle == __last, we're done + if (__len2 == 0) + return; + // shrink [__first, __middle) as much as possible (with no moves), returning if it shrinks to 0 + for (; true; ++__first, --__len1) + { + if (__len1 == 0) + return; + if (__comp(*__middle, *__first)) + break; + } + if (__len1 <= __buff_size || __len2 <= __buff_size) + { + __buffered_inplace_merge<_Compare>(__first, __middle, __last, __comp, __len1, __len2, __buff); + return; + } + // __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 +struct __inplace_merge_switch +{ + static const unsigned value = is_trivially_copy_assignable<_Tp>::value; +}; + +template +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 __buf(0, 0); + unique_ptr __h; + if (__inplace_merge_switch::value && __buf_size > 8) + { + __buf = _VSTD::get_temporary_buffer(__buf_size); + __h.reset(__buf.first); + } +#ifdef _LIBCPP_DEBUG2 + typedef typename add_lvalue_reference<__debug_less<_Compare> >::type _Comp_ref; + __debug_less<_Compare> __c(__comp); + return _VSTD::__inplace_merge<_Comp_ref>(__first, __middle, __last, __c, __len1, __len2, + __buf.first, __buf.second); +#else // _LIBCPP_DEBUG2 + typedef typename add_lvalue_reference<_Compare>::type _Comp_ref; + return _VSTD::__inplace_merge<_Comp_ref>(__first, __middle, __last, __comp, __len1, __len2, + __buf.first, __buf.second); +#endif // _LIBCPP_DEBUG2 +} + +template +inline _LIBCPP_INLINE_VISIBILITY +void +inplace_merge(_BidirectionalIterator __first, _BidirectionalIterator __middle, _BidirectionalIterator __last) +{ + _VSTD::inplace_merge(__first, __middle, __last, + __less::value_type>()); +} + +// stable_sort + +template +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 __h(__result, __d); + for (; true; ++__result) + { + if (__first1 == __last1) + { + for (; __first2 != __last2; ++__first2, ++__result, __d.__incr((value_type*)0)) + ::new (__result) value_type(_VSTD::move(*__first2)); + __h.release(); + return; + } + if (__first2 == __last2) + { + for (; __first1 != __last1; ++__first1, ++__result, __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 +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, ++__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, ++__result) + *__result = _VSTD::move(*__first2); +} + +template +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 +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 __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 +struct __stable_sort_switch +{ + static const unsigned value = 128*is_trivially_copy_assignable<_Tp>::value; +}; + +template +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(__stable_sort_switch::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 __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(__buff), +// move_iterator(__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 +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 __buf(0, 0); + unique_ptr __h; + if (__len > static_cast(__stable_sort_switch::value)) + { + __buf = _VSTD::get_temporary_buffer(__len); + __h.reset(__buf.first); + } +#ifdef _LIBCPP_DEBUG2 + typedef typename add_lvalue_reference<__debug_less<_Compare> >::type _Comp_ref; + __debug_less<_Compare> __c(__comp); + __stable_sort<_Comp_ref>(__first, __last, __c, __len, __buf.first, __buf.second); +#else // _LIBCPP_DEBUG2 + typedef typename add_lvalue_reference<_Compare>::type _Comp_ref; + __stable_sort<_Comp_ref>(__first, __last, __comp, __len, __buf.first, __buf.second); +#endif // _LIBCPP_DEBUG2 +} + +template +inline _LIBCPP_INLINE_VISIBILITY +void +stable_sort(_RandomAccessIterator __first, _RandomAccessIterator __last) +{ + _VSTD::stable_sort(__first, __last, __less::value_type>()); +} + +// is_heap_until + +template +_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 +inline _LIBCPP_INLINE_VISIBILITY +_RandomAccessIterator +is_heap_until(_RandomAccessIterator __first, _RandomAccessIterator __last) +{ + return _VSTD::is_heap_until(__first, __last, __less::value_type>()); +} + +// is_heap + +template +inline _LIBCPP_INLINE_VISIBILITY +bool +is_heap(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp) +{ + return _VSTD::is_heap_until(__first, __last, __comp) == __last; +} + +template +inline _LIBCPP_INLINE_VISIBILITY +bool +is_heap(_RandomAccessIterator __first, _RandomAccessIterator __last) +{ + return _VSTD::is_heap(__first, __last, __less::value_type>()); +} + +// push_heap + +template +void +__push_heap_front(_RandomAccessIterator __first, _RandomAccessIterator, _Compare __comp, + typename iterator_traits<_RandomAccessIterator>::difference_type __len) +{ + typedef typename iterator_traits<_RandomAccessIterator>::difference_type difference_type; + typedef typename iterator_traits<_RandomAccessIterator>::value_type value_type; + if (__len > 1) + { + difference_type __p = 0; + _RandomAccessIterator __pp = __first; + difference_type __c = 2; + _RandomAccessIterator __cp = __first + __c; + if (__c == __len || __comp(*__cp, *(__cp - 1))) + { + --__c; + --__cp; + } + if (__comp(*__pp, *__cp)) + { + value_type __t(_VSTD::move(*__pp)); + do + { + *__pp = _VSTD::move(*__cp); + __pp = __cp; + __p = __c; + __c = (__p + 1) * 2; + if (__c > __len) + break; + __cp = __first + __c; + if (__c == __len || __comp(*__cp, *(__cp - 1))) + { + --__c; + --__cp; + } + } while (__comp(__t, *__cp)); + *__pp = _VSTD::move(__t); + } + } +} + +template +void +__push_heap_back(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp, + typename iterator_traits<_RandomAccessIterator>::difference_type __len) +{ + typedef typename iterator_traits<_RandomAccessIterator>::difference_type difference_type; + 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 +inline _LIBCPP_INLINE_VISIBILITY +void +push_heap(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp) +{ +#ifdef _LIBCPP_DEBUG2 + typedef typename add_lvalue_reference<__debug_less<_Compare> >::type _Comp_ref; + __debug_less<_Compare> __c(__comp); + __push_heap_back<_Comp_ref>(__first, __last, __c, __last - __first); +#else // _LIBCPP_DEBUG2 + typedef typename add_lvalue_reference<_Compare>::type _Comp_ref; + __push_heap_back<_Comp_ref>(__first, __last, __comp, __last - __first); +#endif // _LIBCPP_DEBUG2 +} + +template +inline _LIBCPP_INLINE_VISIBILITY +void +push_heap(_RandomAccessIterator __first, _RandomAccessIterator __last) +{ + _VSTD::push_heap(__first, __last, __less::value_type>()); +} + +// pop_heap + +template +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); + __push_heap_front<_Compare>(__first, __last, __comp, __len-1); + } +} + +template +inline _LIBCPP_INLINE_VISIBILITY +void +pop_heap(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp) +{ +#ifdef _LIBCPP_DEBUG2 + typedef typename add_lvalue_reference<__debug_less<_Compare> >::type _Comp_ref; + __debug_less<_Compare> __c(__comp); + __pop_heap<_Comp_ref>(__first, __last, __c, __last - __first); +#else // _LIBCPP_DEBUG2 + typedef typename add_lvalue_reference<_Compare>::type _Comp_ref; + __pop_heap<_Comp_ref>(__first, __last, __comp, __last - __first); +#endif // _LIBCPP_DEBUG2 +} + +template +inline _LIBCPP_INLINE_VISIBILITY +void +pop_heap(_RandomAccessIterator __first, _RandomAccessIterator __last) +{ + _VSTD::pop_heap(__first, __last, __less::value_type>()); +} + +// make_heap + +template +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) + { + __last = __first; + ++__last; + for (difference_type __i = 1; __i < __n;) + __push_heap_back<_Compare>(__first, ++__last, __comp, ++__i); + } +} + +template +inline _LIBCPP_INLINE_VISIBILITY +void +make_heap(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp) +{ +#ifdef _LIBCPP_DEBUG2 + typedef typename add_lvalue_reference<__debug_less<_Compare> >::type _Comp_ref; + __debug_less<_Compare> __c(__comp); + __make_heap<_Comp_ref>(__first, __last, __c); +#else // _LIBCPP_DEBUG2 + typedef typename add_lvalue_reference<_Compare>::type _Comp_ref; + __make_heap<_Comp_ref>(__first, __last, __comp); +#endif // _LIBCPP_DEBUG2 +} + +template +inline _LIBCPP_INLINE_VISIBILITY +void +make_heap(_RandomAccessIterator __first, _RandomAccessIterator __last) +{ + _VSTD::make_heap(__first, __last, __less::value_type>()); +} + +// sort_heap + +template +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, --__n) + __pop_heap<_Compare>(__first, __last, __comp, __n); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +void +sort_heap(_RandomAccessIterator __first, _RandomAccessIterator __last, _Compare __comp) +{ +#ifdef _LIBCPP_DEBUG2 + typedef typename add_lvalue_reference<__debug_less<_Compare> >::type _Comp_ref; + __debug_less<_Compare> __c(__comp); + __sort_heap<_Comp_ref>(__first, __last, __c); +#else // _LIBCPP_DEBUG2 + typedef typename add_lvalue_reference<_Compare>::type _Comp_ref; + __sort_heap<_Comp_ref>(__first, __last, __comp); +#endif // _LIBCPP_DEBUG2 +} + +template +inline _LIBCPP_INLINE_VISIBILITY +void +sort_heap(_RandomAccessIterator __first, _RandomAccessIterator __last) +{ + _VSTD::sort_heap(__first, __last, __less::value_type>()); +} + +// partial_sort + +template +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); + __push_heap_front<_Compare>(__first, __middle, __comp, __len); + } + } + __sort_heap<_Compare>(__first, __middle, __comp); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +void +partial_sort(_RandomAccessIterator __first, _RandomAccessIterator __middle, _RandomAccessIterator __last, + _Compare __comp) +{ +#ifdef _LIBCPP_DEBUG2 + typedef typename add_lvalue_reference<__debug_less<_Compare> >::type _Comp_ref; + __debug_less<_Compare> __c(__comp); + __partial_sort<_Comp_ref>(__first, __middle, __last, __c); +#else // _LIBCPP_DEBUG2 + typedef typename add_lvalue_reference<_Compare>::type _Comp_ref; + __partial_sort<_Comp_ref>(__first, __middle, __last, __comp); +#endif // _LIBCPP_DEBUG2 +} + +template +inline _LIBCPP_INLINE_VISIBILITY +void +partial_sort(_RandomAccessIterator __first, _RandomAccessIterator __middle, _RandomAccessIterator __last) +{ + _VSTD::partial_sort(__first, __middle, __last, + __less::value_type>()); +} + +// partial_sort_copy + +template +_RandomAccessIterator +__partial_sort_copy(_InputIterator __first, _InputIterator __last, + _RandomAccessIterator __result_first, _RandomAccessIterator __result_last, _Compare __comp) +{ + _RandomAccessIterator __r = __result_first; + if (__r != __result_last) + { + typename iterator_traits<_RandomAccessIterator>::difference_type __len = 0; + for (; __first != __last && __r != __result_last; ++__first, ++__r, ++__len) + *__r = *__first; + __make_heap<_Compare>(__result_first, __r, __comp); + for (; __first != __last; ++__first) + if (__comp(*__first, *__result_first)) + { + *__result_first = *__first; + __push_heap_front<_Compare>(__result_first, __r, __comp, __len); + } + __sort_heap<_Compare>(__result_first, __r, __comp); + } + return __r; +} + +template +inline _LIBCPP_INLINE_VISIBILITY +_RandomAccessIterator +partial_sort_copy(_InputIterator __first, _InputIterator __last, + _RandomAccessIterator __result_first, _RandomAccessIterator __result_last, _Compare __comp) +{ +#ifdef _LIBCPP_DEBUG2 + typedef typename add_lvalue_reference<__debug_less<_Compare> >::type _Comp_ref; + __debug_less<_Compare> __c(__comp); + return __partial_sort_copy<_Comp_ref>(__first, __last, __result_first, __result_last, __c); +#else // _LIBCPP_DEBUG2 + typedef typename add_lvalue_reference<_Compare>::type _Comp_ref; + return __partial_sort_copy<_Comp_ref>(__first, __last, __result_first, __result_last, __comp); +#endif // _LIBCPP_DEBUG2 +} + +template +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::value_type>()); +} + +// nth_element + +template +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 +inline _LIBCPP_INLINE_VISIBILITY +void +nth_element(_RandomAccessIterator __first, _RandomAccessIterator __nth, _RandomAccessIterator __last, _Compare __comp) +{ +#ifdef _LIBCPP_DEBUG2 + typedef typename add_lvalue_reference<__debug_less<_Compare> >::type _Comp_ref; + __debug_less<_Compare> __c(__comp); + __nth_element<_Comp_ref>(__first, __nth, __last, __c); +#else // _LIBCPP_DEBUG2 + typedef typename add_lvalue_reference<_Compare>::type _Comp_ref; + __nth_element<_Comp_ref>(__first, __nth, __last, __comp); +#endif // _LIBCPP_DEBUG2 +} + +template +inline _LIBCPP_INLINE_VISIBILITY +void +nth_element(_RandomAccessIterator __first, _RandomAccessIterator __nth, _RandomAccessIterator __last) +{ + _VSTD::nth_element(__first, __nth, __last, __less::value_type>()); +} + +// includes + +template +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 +inline _LIBCPP_INLINE_VISIBILITY +bool +includes(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2, _InputIterator2 __last2, + _Compare __comp) +{ +#ifdef _LIBCPP_DEBUG2 + typedef typename add_lvalue_reference<__debug_less<_Compare> >::type _Comp_ref; + __debug_less<_Compare> __c(__comp); + return __includes<_Comp_ref>(__first1, __last1, __first2, __last2, __c); +#else // _LIBCPP_DEBUG2 + typedef typename add_lvalue_reference<_Compare>::type _Comp_ref; + return __includes<_Comp_ref>(__first1, __last1, __first2, __last2, __comp); +#endif // _LIBCPP_DEBUG2 +} + +template +inline _LIBCPP_INLINE_VISIBILITY +bool +includes(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2, _InputIterator2 __last2) +{ + return _VSTD::includes(__first1, __last1, __first2, __last2, + __less::value_type, + typename iterator_traits<_InputIterator2>::value_type>()); +} + +// set_union + +template +_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 + { + *__result = *__first1; + if (!__comp(*__first1, *__first2)) + ++__first2; + ++__first1; + } + } + return _VSTD::copy(__first2, __last2, __result); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +_OutputIterator +set_union(_InputIterator1 __first1, _InputIterator1 __last1, + _InputIterator2 __first2, _InputIterator2 __last2, _OutputIterator __result, _Compare __comp) +{ +#ifdef _LIBCPP_DEBUG2 + typedef typename add_lvalue_reference<__debug_less<_Compare> >::type _Comp_ref; + __debug_less<_Compare> __c(__comp); + return __set_union<_Comp_ref>(__first1, __last1, __first2, __last2, __result, __c); +#else // _LIBCPP_DEBUG2 + typedef typename add_lvalue_reference<_Compare>::type _Comp_ref; + return __set_union<_Comp_ref>(__first1, __last1, __first2, __last2, __result, __comp); +#endif // _LIBCPP_DEBUG2 +} + +template +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::value_type, + typename iterator_traits<_InputIterator2>::value_type>()); +} + +// set_intersection + +template +_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 +inline _LIBCPP_INLINE_VISIBILITY +_OutputIterator +set_intersection(_InputIterator1 __first1, _InputIterator1 __last1, + _InputIterator2 __first2, _InputIterator2 __last2, _OutputIterator __result, _Compare __comp) +{ +#ifdef _LIBCPP_DEBUG2 + typedef typename add_lvalue_reference<__debug_less<_Compare> >::type _Comp_ref; + __debug_less<_Compare> __c(__comp); + return __set_intersection<_Comp_ref>(__first1, __last1, __first2, __last2, __result, __c); +#else // _LIBCPP_DEBUG2 + typedef typename add_lvalue_reference<_Compare>::type _Comp_ref; + return __set_intersection<_Comp_ref>(__first1, __last1, __first2, __last2, __result, __comp); +#endif // _LIBCPP_DEBUG2 +} + +template +inline _LIBCPP_INLINE_VISIBILITY +_OutputIterator +set_intersection(_InputIterator1 __first1, _InputIterator1 __last1, + _InputIterator2 __first2, _InputIterator2 __last2, _OutputIterator __result) +{ + return _VSTD::set_intersection(__first1, __last1, __first2, __last2, __result, + __less::value_type, + typename iterator_traits<_InputIterator2>::value_type>()); +} + +// set_difference + +template +_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 +inline _LIBCPP_INLINE_VISIBILITY +_OutputIterator +set_difference(_InputIterator1 __first1, _InputIterator1 __last1, + _InputIterator2 __first2, _InputIterator2 __last2, _OutputIterator __result, _Compare __comp) +{ +#ifdef _LIBCPP_DEBUG2 + typedef typename add_lvalue_reference<__debug_less<_Compare> >::type _Comp_ref; + __debug_less<_Compare> __c(__comp); + return __set_difference<_Comp_ref>(__first1, __last1, __first2, __last2, __result, __c); +#else // _LIBCPP_DEBUG2 + typedef typename add_lvalue_reference<_Compare>::type _Comp_ref; + return __set_difference<_Comp_ref>(__first1, __last1, __first2, __last2, __result, __comp); +#endif // _LIBCPP_DEBUG2 +} + +template +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::value_type, + typename iterator_traits<_InputIterator2>::value_type>()); +} + +// set_symmetric_difference + +template +_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 +inline _LIBCPP_INLINE_VISIBILITY +_OutputIterator +set_symmetric_difference(_InputIterator1 __first1, _InputIterator1 __last1, + _InputIterator2 __first2, _InputIterator2 __last2, _OutputIterator __result, _Compare __comp) +{ +#ifdef _LIBCPP_DEBUG2 + typedef typename add_lvalue_reference<__debug_less<_Compare> >::type _Comp_ref; + __debug_less<_Compare> __c(__comp); + return __set_symmetric_difference<_Comp_ref>(__first1, __last1, __first2, __last2, __result, __c); +#else // _LIBCPP_DEBUG2 + typedef typename add_lvalue_reference<_Compare>::type _Comp_ref; + return __set_symmetric_difference<_Comp_ref>(__first1, __last1, __first2, __last2, __result, __comp); +#endif // _LIBCPP_DEBUG2 +} + +template +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::value_type, + typename iterator_traits<_InputIterator2>::value_type>()); +} + +// lexicographical_compare + +template +bool +__lexicographical_compare(_InputIterator1 __first1, _InputIterator1 __last1, + _InputIterator2 __first2, _InputIterator2 __last2, _Compare __comp) +{ + for (; __first2 != __last2; ++__first1, ++__first2) + { + if (__first1 == __last1 || __comp(*__first1, *__first2)) + return true; + if (__comp(*__first2, *__first1)) + return false; + } + return false; +} + +template +inline _LIBCPP_INLINE_VISIBILITY +bool +lexicographical_compare(_InputIterator1 __first1, _InputIterator1 __last1, + _InputIterator2 __first2, _InputIterator2 __last2, _Compare __comp) +{ +#ifdef _LIBCPP_DEBUG2 + typedef typename add_lvalue_reference<__debug_less<_Compare> >::type _Comp_ref; + __debug_less<_Compare> __c(__comp); + return __lexicographical_compare<_Comp_ref>(__first1, __last1, __first2, __last2, __c); +#else // _LIBCPP_DEBUG2 + typedef typename add_lvalue_reference<_Compare>::type _Comp_ref; + return __lexicographical_compare<_Comp_ref>(__first1, __last1, __first2, __last2, __comp); +#endif // _LIBCPP_DEBUG2 +} + +template +inline _LIBCPP_INLINE_VISIBILITY +bool +lexicographical_compare(_InputIterator1 __first1, _InputIterator1 __last1, + _InputIterator2 __first2, _InputIterator2 __last2) +{ + return _VSTD::lexicographical_compare(__first1, __last1, __first2, __last2, + __less::value_type, + typename iterator_traits<_InputIterator2>::value_type>()); +} + +// next_permutation + +template +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 +inline _LIBCPP_INLINE_VISIBILITY +bool +next_permutation(_BidirectionalIterator __first, _BidirectionalIterator __last, _Compare __comp) +{ +#ifdef _LIBCPP_DEBUG2 + typedef typename add_lvalue_reference<__debug_less<_Compare> >::type _Comp_ref; + __debug_less<_Compare> __c(__comp); + return __next_permutation<_Comp_ref>(__first, __last, __c); +#else // _LIBCPP_DEBUG2 + typedef typename add_lvalue_reference<_Compare>::type _Comp_ref; + return __next_permutation<_Comp_ref>(__first, __last, __comp); +#endif // _LIBCPP_DEBUG2 +} + +template +inline _LIBCPP_INLINE_VISIBILITY +bool +next_permutation(_BidirectionalIterator __first, _BidirectionalIterator __last) +{ + return _VSTD::next_permutation(__first, __last, + __less::value_type>()); +} + +// prev_permutation + +template +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 +inline _LIBCPP_INLINE_VISIBILITY +bool +prev_permutation(_BidirectionalIterator __first, _BidirectionalIterator __last, _Compare __comp) +{ +#ifdef _LIBCPP_DEBUG2 + typedef typename add_lvalue_reference<__debug_less<_Compare> >::type _Comp_ref; + __debug_less<_Compare> __c(__comp); + return __prev_permutation<_Comp_ref>(__first, __last, __c); +#else // _LIBCPP_DEBUG2 + typedef typename add_lvalue_reference<_Compare>::type _Comp_ref; + return __prev_permutation<_Comp_ref>(__first, __last, __comp); +#endif // _LIBCPP_DEBUG2 +} + +template +inline _LIBCPP_INLINE_VISIBILITY +bool +prev_permutation(_BidirectionalIterator __first, _BidirectionalIterator __last) +{ + return _VSTD::prev_permutation(__first, __last, + __less::value_type>()); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if +< + is_integral<_Tp>::value, + _Tp +>::type +__rotate_left(_Tp __t, _Tp __n = 1) +{ + const unsigned __bits = static_cast(sizeof(_Tp) * __CHAR_BIT__ - 1); + __n &= __bits; + return static_cast<_Tp>((__t << __n) | (static_cast::type>(__t) >> (__bits - __n))); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if +< + is_integral<_Tp>::value, + _Tp +>::type +__rotate_right(_Tp __t, _Tp __n = 1) +{ + const unsigned __bits = static_cast(sizeof(_Tp) * __CHAR_BIT__ - 1); + __n &= __bits; + return static_cast<_Tp>((__t << (__bits - __n)) | (static_cast::type>(__t) >> __n)); +} + +_LIBCPP_END_NAMESPACE_STD + +#endif // _LIBCPP_ALGORITHM Index: stable/9/contrib/libc++/include/atomic =================================================================== --- stable/9/contrib/libc++/include/atomic (nonexistent) +++ stable/9/contrib/libc++/include/atomic (revision 235798) @@ -0,0 +1,1515 @@ +// -*- C++ -*- +//===--------------------------- atomic -----------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP_ATOMIC +#define _LIBCPP_ATOMIC + +/* + atomic synopsis + +namespace std +{ + +// order and consistency + +typedef enum memory_order +{ + memory_order_relaxed, + memory_order_consume, // load-consume + memory_order_acquire, // load-acquire + memory_order_release, // store-release + memory_order_acq_rel, // store-release load-acquire + memory_order_seq_cst // store-release load-acquire +} memory_order; + +template T kill_dependency(T y) noexcept; + +// lock-free property + +#define ATOMIC_CHAR_LOCK_FREE unspecified +#define ATOMIC_CHAR16_T_LOCK_FREE unspecified +#define ATOMIC_CHAR32_T_LOCK_FREE unspecified +#define ATOMIC_WCHAR_T_LOCK_FREE unspecified +#define ATOMIC_SHORT_LOCK_FREE unspecified +#define ATOMIC_INT_LOCK_FREE unspecified +#define ATOMIC_LONG_LOCK_FREE unspecified +#define ATOMIC_LLONG_LOCK_FREE unspecified + +// flag type and operations + +typedef struct atomic_flag +{ + bool test_and_set(memory_order m = memory_order_seq_cst) volatile noexcept; + bool test_and_set(memory_order m = memory_order_seq_cst) noexcept; + void clear(memory_order m = memory_order_seq_cst) volatile noexcept; + void clear(memory_order m = memory_order_seq_cst) noexcept; + atomic_flag() noexcept = default; + atomic_flag(const atomic_flag&) = delete; + atomic_flag& operator=(const atomic_flag&) = delete; + atomic_flag& operator=(const atomic_flag&) volatile = delete; +} atomic_flag; + +bool + atomic_flag_test_and_set(volatile atomic_flag* obj) noexcept; + +bool + atomic_flag_test_and_set(atomic_flag* obj) noexcept; + +bool + atomic_flag_test_and_set_explicit(volatile atomic_flag* obj, + memory_order m) noexcept; + +bool + atomic_flag_test_and_set_explicit(atomic_flag* obj, memory_order m) noexcept; + +void + atomic_flag_clear(volatile atomic_flag* obj) noexcept; + +void + atomic_flag_clear(atomic_flag* obj) noexcept; + +void + atomic_flag_clear_explicit(volatile atomic_flag* obj, memory_order m) noexcept; + +void + atomic_flag_clear_explicit(atomic_flag* obj, memory_order m) noexcept; + +#define ATOMIC_FLAG_INIT see below +#define ATOMIC_VAR_INIT(value) see below + +template +struct atomic +{ + bool is_lock_free() const volatile noexcept; + bool is_lock_free() const noexcept; + void store(T desr, memory_order m = memory_order_seq_cst) volatile noexcept; + void store(T desr, memory_order m = memory_order_seq_cst) noexcept; + T load(memory_order m = memory_order_seq_cst) const volatile noexcept; + T load(memory_order m = memory_order_seq_cst) const noexcept; + operator T() const volatile noexcept; + operator T() const noexcept; + T exchange(T desr, memory_order m = memory_order_seq_cst) volatile noexcept; + T exchange(T desr, memory_order m = memory_order_seq_cst) noexcept; + bool compare_exchange_weak(T& expc, T desr, + memory_order s, memory_order f) volatile noexcept; + bool compare_exchange_weak(T& expc, T desr, memory_order s, memory_order f) noexcept; + bool compare_exchange_strong(T& expc, T desr, + memory_order s, memory_order f) volatile noexcept; + bool compare_exchange_strong(T& expc, T desr, + memory_order s, memory_order f) noexcept; + bool compare_exchange_weak(T& expc, T desr, + memory_order m = memory_order_seq_cst) volatile noexcept; + bool compare_exchange_weak(T& expc, T desr, + memory_order m = memory_order_seq_cst) noexcept; + bool compare_exchange_strong(T& expc, T desr, + memory_order m = memory_order_seq_cst) volatile noexcept; + bool compare_exchange_strong(T& expc, T desr, + memory_order m = memory_order_seq_cst) noexcept; + + atomic() noexcept = default; + constexpr atomic(T desr) noexcept; + atomic(const atomic&) = delete; + atomic& operator=(const atomic&) = delete; + atomic& operator=(const atomic&) volatile = delete; + T operator=(T) volatile noexcept; + T operator=(T) noexcept; +}; + +template <> +struct atomic +{ + bool is_lock_free() const volatile noexcept; + bool is_lock_free() const noexcept; + void store(integral desr, memory_order m = memory_order_seq_cst) volatile noexcept; + void store(integral desr, memory_order m = memory_order_seq_cst) noexcept; + integral load(memory_order m = memory_order_seq_cst) const volatile noexcept; + integral load(memory_order m = memory_order_seq_cst) const noexcept; + operator integral() const volatile noexcept; + operator integral() const noexcept; + integral exchange(integral desr, + memory_order m = memory_order_seq_cst) volatile noexcept; + integral exchange(integral desr, memory_order m = memory_order_seq_cst) noexcept; + bool compare_exchange_weak(integral& expc, integral desr, + memory_order s, memory_order f) volatile noexcept; + bool compare_exchange_weak(integral& expc, integral desr, + memory_order s, memory_order f) noexcept; + bool compare_exchange_strong(integral& expc, integral desr, + memory_order s, memory_order f) volatile noexcept; + bool compare_exchange_strong(integral& expc, integral desr, + memory_order s, memory_order f) noexcept; + bool compare_exchange_weak(integral& expc, integral desr, + memory_order m = memory_order_seq_cst) volatile noexcept; + bool compare_exchange_weak(integral& expc, integral desr, + memory_order m = memory_order_seq_cst) noexcept; + bool compare_exchange_strong(integral& expc, integral desr, + memory_order m = memory_order_seq_cst) volatile noexcept; + bool compare_exchange_strong(integral& expc, integral desr, + memory_order m = memory_order_seq_cst) noexcept; + + integral + fetch_add(integral op, memory_order m = memory_order_seq_cst) volatile noexcept; + integral fetch_add(integral op, memory_order m = memory_order_seq_cst) noexcept; + integral + fetch_sub(integral op, memory_order m = memory_order_seq_cst) volatile noexcept; + integral fetch_sub(integral op, memory_order m = memory_order_seq_cst) noexcept; + integral + fetch_and(integral op, memory_order m = memory_order_seq_cst) volatile noexcept; + integral fetch_and(integral op, memory_order m = memory_order_seq_cst) noexcept; + integral + fetch_or(integral op, memory_order m = memory_order_seq_cst) volatile noexcept; + integral fetch_or(integral op, memory_order m = memory_order_seq_cst) noexcept; + integral + fetch_xor(integral op, memory_order m = memory_order_seq_cst) volatile noexcept; + integral fetch_xor(integral op, memory_order m = memory_order_seq_cst) noexcept; + + atomic() noexcept = default; + constexpr atomic(integral desr) noexcept; + atomic(const atomic&) = delete; + atomic& operator=(const atomic&) = delete; + atomic& operator=(const atomic&) volatile = delete; + integral operator=(integral desr) volatile noexcept; + integral operator=(integral desr) noexcept; + + integral operator++(int) volatile noexcept; + integral operator++(int) noexcept; + integral operator--(int) volatile noexcept; + integral operator--(int) noexcept; + integral operator++() volatile noexcept; + integral operator++() noexcept; + integral operator--() volatile noexcept; + integral operator--() noexcept; + integral operator+=(integral op) volatile noexcept; + integral operator+=(integral op) noexcept; + integral operator-=(integral op) volatile noexcept; + integral operator-=(integral op) noexcept; + integral operator&=(integral op) volatile noexcept; + integral operator&=(integral op) noexcept; + integral operator|=(integral op) volatile noexcept; + integral operator|=(integral op) noexcept; + integral operator^=(integral op) volatile noexcept; + integral operator^=(integral op) noexcept; +}; + +template +struct atomic +{ + bool is_lock_free() const volatile noexcept; + bool is_lock_free() const noexcept; + void store(T* desr, memory_order m = memory_order_seq_cst) volatile noexcept; + void store(T* desr, memory_order m = memory_order_seq_cst) noexcept; + T* load(memory_order m = memory_order_seq_cst) const volatile noexcept; + T* load(memory_order m = memory_order_seq_cst) const noexcept; + operator T*() const volatile noexcept; + operator T*() const noexcept; + T* exchange(T* desr, memory_order m = memory_order_seq_cst) volatile noexcept; + T* exchange(T* desr, memory_order m = memory_order_seq_cst) noexcept; + bool compare_exchange_weak(T*& expc, T* desr, + memory_order s, memory_order f) volatile noexcept; + bool compare_exchange_weak(T*& expc, T* desr, + memory_order s, memory_order f) noexcept; + bool compare_exchange_strong(T*& expc, T* desr, + memory_order s, memory_order f) volatile noexcept; + bool compare_exchange_strong(T*& expc, T* desr, + memory_order s, memory_order f) noexcept; + bool compare_exchange_weak(T*& expc, T* desr, + memory_order m = memory_order_seq_cst) volatile noexcept; + bool compare_exchange_weak(T*& expc, T* desr, + memory_order m = memory_order_seq_cst) noexcept; + bool compare_exchange_strong(T*& expc, T* desr, + memory_order m = memory_order_seq_cst) volatile noexcept; + bool compare_exchange_strong(T*& expc, T* desr, + memory_order m = memory_order_seq_cst) noexcept; + T* fetch_add(ptrdiff_t op, memory_order m = memory_order_seq_cst) volatile noexcept; + T* fetch_add(ptrdiff_t op, memory_order m = memory_order_seq_cst) noexcept; + T* fetch_sub(ptrdiff_t op, memory_order m = memory_order_seq_cst) volatile noexcept; + T* fetch_sub(ptrdiff_t op, memory_order m = memory_order_seq_cst) noexcept; + + atomic() noexcept = default; + constexpr atomic(T* desr) noexcept; + atomic(const atomic&) = delete; + atomic& operator=(const atomic&) = delete; + atomic& operator=(const atomic&) volatile = delete; + + T* operator=(T*) volatile noexcept; + T* operator=(T*) noexcept; + T* operator++(int) volatile noexcept; + T* operator++(int) noexcept; + T* operator--(int) volatile noexcept; + T* operator--(int) noexcept; + T* operator++() volatile noexcept; + T* operator++() noexcept; + T* operator--() volatile noexcept; + T* operator--() noexcept; + T* operator+=(ptrdiff_t op) volatile noexcept; + T* operator+=(ptrdiff_t op) noexcept; + T* operator-=(ptrdiff_t op) volatile noexcept; + T* operator-=(ptrdiff_t op) noexcept; +}; + + +template + bool + atomic_is_lock_free(const volatile atomic* obj) noexcept; + +template + bool + atomic_is_lock_free(const atomic* obj) noexcept; + +template + void + atomic_init(volatile atomic* obj, T desr) noexcept; + +template + void + atomic_init(atomic* obj, T desr) noexcept; + +template + void + atomic_store(volatile atomic* obj, T desr) noexcept; + +template + void + atomic_store(atomic* obj, T desr) noexcept; + +template + void + atomic_store_explicit(volatile atomic* obj, T desr, memory_order m) noexcept; + +template + void + atomic_store_explicit(atomic* obj, T desr, memory_order m) noexcept; + +template + T + atomic_load(const volatile atomic* obj) noexcept; + +template + T + atomic_load(const atomic* obj) noexcept; + +template + T + atomic_load_explicit(const volatile atomic* obj, memory_order m) noexcept; + +template + T + atomic_load_explicit(const atomic* obj, memory_order m) noexcept; + +template + T + atomic_exchange(volatile atomic* obj, T desr) noexcept; + +template + T + atomic_exchange(atomic* obj, T desr) noexcept; + +template + T + atomic_exchange_explicit(volatile atomic* obj, T desr, memory_order m) noexcept; + +template + T + atomic_exchange_explicit(atomic* obj, T desr, memory_order m) noexcept; + +template + bool + atomic_compare_exchange_weak(volatile atomic* obj, T* expc, T desr) noexcept; + +template + bool + atomic_compare_exchange_weak(atomic* obj, T* expc, T desr) noexcept; + +template + bool + atomic_compare_exchange_strong(volatile atomic* obj, T* expc, T desr) noexcept; + +template + bool + atomic_compare_exchange_strong(atomic* obj, T* expc, T desr) noexcept; + +template + bool + atomic_compare_exchange_weak_explicit(volatile atomic* obj, T* expc, + T desr, + memory_order s, memory_order f) noexcept; + +template + bool + atomic_compare_exchange_weak_explicit(atomic* obj, T* expc, T desr, + memory_order s, memory_order f) noexcept; + +template + bool + atomic_compare_exchange_strong_explicit(volatile atomic* obj, + T* expc, T desr, + memory_order s, memory_order f) noexcept; + +template + bool + atomic_compare_exchange_strong_explicit(atomic* obj, T* expc, + T desr, + memory_order s, memory_order f) noexcept; + +template + Integral + atomic_fetch_add(volatile atomic* obj, Integral op) noexcept; + +template + Integral + atomic_fetch_add(atomic* obj, Integral op) noexcept; + +template + Integral + atomic_fetch_add_explicit(volatile atomic* obj, Integral op, + memory_order m) noexcept; +template + Integral + atomic_fetch_add_explicit(atomic* obj, Integral op, + memory_order m) noexcept; +template + Integral + atomic_fetch_sub(volatile atomic* obj, Integral op) noexcept; + +template + Integral + atomic_fetch_sub(atomic* obj, Integral op) noexcept; + +template + Integral + atomic_fetch_sub_explicit(volatile atomic* obj, Integral op, + memory_order m) noexcept; +template + Integral + atomic_fetch_sub_explicit(atomic* obj, Integral op, + memory_order m) noexcept; +template + Integral + atomic_fetch_and(volatile atomic* obj, Integral op) noexcept; + +template + Integral + atomic_fetch_and(atomic* obj, Integral op) noexcept; + +template + Integral + atomic_fetch_and_explicit(volatile atomic* obj, Integral op, + memory_order m) noexcept; +template + Integral + atomic_fetch_and_explicit(atomic* obj, Integral op, + memory_order m) noexcept; +template + Integral + atomic_fetch_or(volatile atomic* obj, Integral op) noexcept; + +template + Integral + atomic_fetch_or(atomic* obj, Integral op) noexcept; + +template + Integral + atomic_fetch_or_explicit(volatile atomic* obj, Integral op, + memory_order m) noexcept; +template + Integral + atomic_fetch_or_explicit(atomic* obj, Integral op, + memory_order m) noexcept; +template + Integral + atomic_fetch_xor(volatile atomic* obj, Integral op) noexcept; + +template + Integral + atomic_fetch_xor(atomic* obj, Integral op) noexcept; + +template + Integral + atomic_fetch_xor_explicit(volatile atomic* obj, Integral op, + memory_order m) noexcept; +template + Integral + atomic_fetch_xor_explicit(atomic* obj, Integral op, + memory_order m) noexcept; + +template + T* + atomic_fetch_add(volatile atomic* obj, ptrdiff_t op) noexcept; + +template + T* + atomic_fetch_add(atomic* obj, ptrdiff_t op) noexcept; + +template + T* + atomic_fetch_add_explicit(volatile atomic* obj, ptrdiff_t op, + memory_order m) noexcept; +template + T* + atomic_fetch_add_explicit(atomic* obj, ptrdiff_t op, memory_order m) noexcept; + +template + T* + atomic_fetch_sub(volatile atomic* obj, ptrdiff_t op) noexcept; + +template + T* + atomic_fetch_sub(atomic* obj, ptrdiff_t op) noexcept; + +template + T* + atomic_fetch_sub_explicit(volatile atomic* obj, ptrdiff_t op, + memory_order m) noexcept; +template + T* + atomic_fetch_sub_explicit(atomic* obj, ptrdiff_t op, memory_order m) noexcept; + +// Atomics for standard typedef types + +typedef atomic atomic_char; +typedef atomic atomic_schar; +typedef atomic atomic_uchar; +typedef atomic atomic_short; +typedef atomic atomic_ushort; +typedef atomic atomic_int; +typedef atomic atomic_uint; +typedef atomic atomic_long; +typedef atomic atomic_ulong; +typedef atomic atomic_llong; +typedef atomic atomic_ullong; +typedef atomic atomic_char16_t; +typedef atomic atomic_char32_t; +typedef atomic atomic_wchar_t; + +typedef atomic atomic_int_least8_t; +typedef atomic atomic_uint_least8_t; +typedef atomic atomic_int_least16_t; +typedef atomic atomic_uint_least16_t; +typedef atomic atomic_int_least32_t; +typedef atomic atomic_uint_least32_t; +typedef atomic atomic_int_least64_t; +typedef atomic atomic_uint_least64_t; + +typedef atomic atomic_int_fast8_t; +typedef atomic atomic_uint_fast8_t; +typedef atomic atomic_int_fast16_t; +typedef atomic atomic_uint_fast16_t; +typedef atomic atomic_int_fast32_t; +typedef atomic atomic_uint_fast32_t; +typedef atomic atomic_int_fast64_t; +typedef atomic atomic_uint_fast64_t; + +typedef atomic atomic_intptr_t; +typedef atomic atomic_uintptr_t; +typedef atomic atomic_size_t; +typedef atomic atomic_ptrdiff_t; +typedef atomic atomic_intmax_t; +typedef atomic atomic_uintmax_t; + +// fences + +void atomic_thread_fence(memory_order m) noexcept; +void atomic_signal_fence(memory_order m) noexcept; + +} // std + +*/ + +#include <__config> +#include +#include +#include + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCPP_BEGIN_NAMESPACE_STD + +#if !__has_feature(cxx_atomic) +#error is not implemented +#else + +typedef enum memory_order +{ + memory_order_relaxed, memory_order_consume, memory_order_acquire, + memory_order_release, memory_order_acq_rel, memory_order_seq_cst +} memory_order; + +template +inline _LIBCPP_INLINE_VISIBILITY +_Tp +kill_dependency(_Tp __y) _NOEXCEPT +{ + return __y; +} + +// general atomic + +template ::value && !is_same<_Tp, bool>::value> +struct __atomic_base // false +{ + _Atomic(_Tp) __a_; + + _LIBCPP_INLINE_VISIBILITY + bool is_lock_free() const volatile _NOEXCEPT + {return __c11_atomic_is_lock_free(sizeof(_Tp));} + _LIBCPP_INLINE_VISIBILITY + bool is_lock_free() const _NOEXCEPT + {return __c11_atomic_is_lock_free(sizeof(_Tp));} + _LIBCPP_INLINE_VISIBILITY + void store(_Tp __d, memory_order __m = memory_order_seq_cst) volatile _NOEXCEPT + {__c11_atomic_store(&__a_, __d, __m);} + _LIBCPP_INLINE_VISIBILITY + void store(_Tp __d, memory_order __m = memory_order_seq_cst) _NOEXCEPT + {__c11_atomic_store(&__a_, __d, __m);} + _LIBCPP_INLINE_VISIBILITY + _Tp load(memory_order __m = memory_order_seq_cst) const volatile _NOEXCEPT + {return __c11_atomic_load(&__a_, __m);} + _LIBCPP_INLINE_VISIBILITY + _Tp load(memory_order __m = memory_order_seq_cst) const _NOEXCEPT + {return __c11_atomic_load(&__a_, __m);} + _LIBCPP_INLINE_VISIBILITY + operator _Tp() const volatile _NOEXCEPT {return load();} + _LIBCPP_INLINE_VISIBILITY + operator _Tp() const _NOEXCEPT {return load();} + _LIBCPP_INLINE_VISIBILITY + _Tp exchange(_Tp __d, memory_order __m = memory_order_seq_cst) volatile _NOEXCEPT + {return __c11_atomic_exchange(&__a_, __d, __m);} + _LIBCPP_INLINE_VISIBILITY + _Tp exchange(_Tp __d, memory_order __m = memory_order_seq_cst) _NOEXCEPT + {return __c11_atomic_exchange(&__a_, __d, __m);} + _LIBCPP_INLINE_VISIBILITY + bool compare_exchange_weak(_Tp& __e, _Tp __d, + memory_order __s, memory_order __f) volatile _NOEXCEPT + {return __c11_atomic_compare_exchange_weak(&__a_, &__e, __d, __s, __f);} + _LIBCPP_INLINE_VISIBILITY + bool compare_exchange_weak(_Tp& __e, _Tp __d, + memory_order __s, memory_order __f) _NOEXCEPT + {return __c11_atomic_compare_exchange_weak(&__a_, &__e, __d, __s, __f);} + _LIBCPP_INLINE_VISIBILITY + bool compare_exchange_strong(_Tp& __e, _Tp __d, + memory_order __s, memory_order __f) volatile _NOEXCEPT + {return __c11_atomic_compare_exchange_strong(&__a_, &__e, __d, __s, __f);} + _LIBCPP_INLINE_VISIBILITY + bool compare_exchange_strong(_Tp& __e, _Tp __d, + memory_order __s, memory_order __f) _NOEXCEPT + {return __c11_atomic_compare_exchange_strong(&__a_, &__e, __d, __s, __f);} + _LIBCPP_INLINE_VISIBILITY + bool compare_exchange_weak(_Tp& __e, _Tp __d, + memory_order __m = memory_order_seq_cst) volatile _NOEXCEPT + {return __c11_atomic_compare_exchange_weak(&__a_, &__e, __d, __m, __m);} + _LIBCPP_INLINE_VISIBILITY + bool compare_exchange_weak(_Tp& __e, _Tp __d, + memory_order __m = memory_order_seq_cst) _NOEXCEPT + {return __c11_atomic_compare_exchange_weak(&__a_, &__e, __d, __m, __m);} + _LIBCPP_INLINE_VISIBILITY + bool compare_exchange_strong(_Tp& __e, _Tp __d, + memory_order __m = memory_order_seq_cst) volatile _NOEXCEPT + {return __c11_atomic_compare_exchange_strong(&__a_, &__e, __d, __m, __m);} + _LIBCPP_INLINE_VISIBILITY + bool compare_exchange_strong(_Tp& __e, _Tp __d, + memory_order __m = memory_order_seq_cst) _NOEXCEPT + {return __c11_atomic_compare_exchange_strong(&__a_, &__e, __d, __m, __m);} + + _LIBCPP_INLINE_VISIBILITY + __atomic_base() _NOEXCEPT {} // = default; + _LIBCPP_INLINE_VISIBILITY + _LIBCPP_CONSTEXPR __atomic_base(_Tp __d) _NOEXCEPT : __a_(__d) {} +#ifndef _LIBCPP_HAS_NO_DELETED_FUNCTIONS + __atomic_base(const __atomic_base&) = delete; + __atomic_base& operator=(const __atomic_base&) = delete; + __atomic_base& operator=(const __atomic_base&) volatile = delete; +#else // _LIBCPP_HAS_NO_DELETED_FUNCTIONS +private: + __atomic_base(const __atomic_base&); + __atomic_base& operator=(const __atomic_base&); + __atomic_base& operator=(const __atomic_base&) volatile; +#endif // _LIBCPP_HAS_NO_DELETED_FUNCTIONS +}; + +// atomic + +template +struct __atomic_base<_Tp, true> + : public __atomic_base<_Tp, false> +{ + typedef __atomic_base<_Tp, false> __base; + _LIBCPP_INLINE_VISIBILITY + __atomic_base() _NOEXCEPT {} // = default; + _LIBCPP_INLINE_VISIBILITY + _LIBCPP_CONSTEXPR __atomic_base(_Tp __d) _NOEXCEPT : __base(__d) {} + + _LIBCPP_INLINE_VISIBILITY + _Tp fetch_add(_Tp __op, memory_order __m = memory_order_seq_cst) volatile _NOEXCEPT + {return __c11_atomic_fetch_add(&this->__a_, __op, __m);} + _LIBCPP_INLINE_VISIBILITY + _Tp fetch_add(_Tp __op, memory_order __m = memory_order_seq_cst) _NOEXCEPT + {return __c11_atomic_fetch_add(&this->__a_, __op, __m);} + _LIBCPP_INLINE_VISIBILITY + _Tp fetch_sub(_Tp __op, memory_order __m = memory_order_seq_cst) volatile _NOEXCEPT + {return __c11_atomic_fetch_sub(&this->__a_, __op, __m);} + _LIBCPP_INLINE_VISIBILITY + _Tp fetch_sub(_Tp __op, memory_order __m = memory_order_seq_cst) _NOEXCEPT + {return __c11_atomic_fetch_sub(&this->__a_, __op, __m);} + _LIBCPP_INLINE_VISIBILITY + _Tp fetch_and(_Tp __op, memory_order __m = memory_order_seq_cst) volatile _NOEXCEPT + {return __c11_atomic_fetch_and(&this->__a_, __op, __m);} + _LIBCPP_INLINE_VISIBILITY + _Tp fetch_and(_Tp __op, memory_order __m = memory_order_seq_cst) _NOEXCEPT + {return __c11_atomic_fetch_and(&this->__a_, __op, __m);} + _LIBCPP_INLINE_VISIBILITY + _Tp fetch_or(_Tp __op, memory_order __m = memory_order_seq_cst) volatile _NOEXCEPT + {return __c11_atomic_fetch_or(&this->__a_, __op, __m);} + _LIBCPP_INLINE_VISIBILITY + _Tp fetch_or(_Tp __op, memory_order __m = memory_order_seq_cst) _NOEXCEPT + {return __c11_atomic_fetch_or(&this->__a_, __op, __m);} + _LIBCPP_INLINE_VISIBILITY + _Tp fetch_xor(_Tp __op, memory_order __m = memory_order_seq_cst) volatile _NOEXCEPT + {return __c11_atomic_fetch_xor(&this->__a_, __op, __m);} + _LIBCPP_INLINE_VISIBILITY + _Tp fetch_xor(_Tp __op, memory_order __m = memory_order_seq_cst) _NOEXCEPT + {return __c11_atomic_fetch_xor(&this->__a_, __op, __m);} + + _LIBCPP_INLINE_VISIBILITY + _Tp operator++(int) volatile _NOEXCEPT {return fetch_add(_Tp(1));} + _LIBCPP_INLINE_VISIBILITY + _Tp operator++(int) _NOEXCEPT {return fetch_add(_Tp(1));} + _LIBCPP_INLINE_VISIBILITY + _Tp operator--(int) volatile _NOEXCEPT {return fetch_sub(_Tp(1));} + _LIBCPP_INLINE_VISIBILITY + _Tp operator--(int) _NOEXCEPT {return fetch_sub(_Tp(1));} + _LIBCPP_INLINE_VISIBILITY + _Tp operator++() volatile _NOEXCEPT {return fetch_add(_Tp(1)) + _Tp(1);} + _LIBCPP_INLINE_VISIBILITY + _Tp operator++() _NOEXCEPT {return fetch_add(_Tp(1)) + _Tp(1);} + _LIBCPP_INLINE_VISIBILITY + _Tp operator--() volatile _NOEXCEPT {return fetch_sub(_Tp(1)) - _Tp(1);} + _LIBCPP_INLINE_VISIBILITY + _Tp operator--() _NOEXCEPT {return fetch_sub(_Tp(1)) - _Tp(1);} + _LIBCPP_INLINE_VISIBILITY + _Tp operator+=(_Tp __op) volatile _NOEXCEPT {return fetch_add(__op) + __op;} + _LIBCPP_INLINE_VISIBILITY + _Tp operator+=(_Tp __op) _NOEXCEPT {return fetch_add(__op) + __op;} + _LIBCPP_INLINE_VISIBILITY + _Tp operator-=(_Tp __op) volatile _NOEXCEPT {return fetch_sub(__op) - __op;} + _LIBCPP_INLINE_VISIBILITY + _Tp operator-=(_Tp __op) _NOEXCEPT {return fetch_sub(__op) - __op;} + _LIBCPP_INLINE_VISIBILITY + _Tp operator&=(_Tp __op) volatile _NOEXCEPT {return fetch_and(__op) & __op;} + _LIBCPP_INLINE_VISIBILITY + _Tp operator&=(_Tp __op) _NOEXCEPT {return fetch_and(__op) & __op;} + _LIBCPP_INLINE_VISIBILITY + _Tp operator|=(_Tp __op) volatile _NOEXCEPT {return fetch_or(__op) | __op;} + _LIBCPP_INLINE_VISIBILITY + _Tp operator|=(_Tp __op) _NOEXCEPT {return fetch_or(__op) | __op;} + _LIBCPP_INLINE_VISIBILITY + _Tp operator^=(_Tp __op) volatile _NOEXCEPT {return fetch_xor(__op) ^ __op;} + _LIBCPP_INLINE_VISIBILITY + _Tp operator^=(_Tp __op) _NOEXCEPT {return fetch_xor(__op) ^ __op;} +}; + +// atomic + +template +struct atomic + : public __atomic_base<_Tp> +{ + typedef __atomic_base<_Tp> __base; + _LIBCPP_INLINE_VISIBILITY + atomic() _NOEXCEPT {} // = default; + _LIBCPP_INLINE_VISIBILITY + _LIBCPP_CONSTEXPR atomic(_Tp __d) _NOEXCEPT : __base(__d) {} + + _LIBCPP_INLINE_VISIBILITY + _Tp operator=(_Tp __d) volatile _NOEXCEPT + {__base::store(__d); return __d;} + _LIBCPP_INLINE_VISIBILITY + _Tp operator=(_Tp __d) _NOEXCEPT + {__base::store(__d); return __d;} +}; + +// atomic + +template +struct atomic<_Tp*> + : public __atomic_base<_Tp*> +{ + typedef __atomic_base<_Tp*> __base; + _LIBCPP_INLINE_VISIBILITY + atomic() _NOEXCEPT {} // = default; + _LIBCPP_INLINE_VISIBILITY + _LIBCPP_CONSTEXPR atomic(_Tp* __d) _NOEXCEPT : __base(__d) {} + + _LIBCPP_INLINE_VISIBILITY + _Tp* operator=(_Tp* __d) volatile _NOEXCEPT + {__base::store(__d); return __d;} + _LIBCPP_INLINE_VISIBILITY + _Tp* operator=(_Tp* __d) _NOEXCEPT + {__base::store(__d); return __d;} + + _LIBCPP_INLINE_VISIBILITY + _Tp* fetch_add(ptrdiff_t __op, memory_order __m = memory_order_seq_cst) + volatile _NOEXCEPT + {return __c11_atomic_fetch_add(&this->__a_, __op, __m);} + _LIBCPP_INLINE_VISIBILITY + _Tp* fetch_add(ptrdiff_t __op, memory_order __m = memory_order_seq_cst) _NOEXCEPT + {return __c11_atomic_fetch_add(&this->__a_, __op, __m);} + _LIBCPP_INLINE_VISIBILITY + _Tp* fetch_sub(ptrdiff_t __op, memory_order __m = memory_order_seq_cst) + volatile _NOEXCEPT + {return __c11_atomic_fetch_sub(&this->__a_, __op, __m);} + _LIBCPP_INLINE_VISIBILITY + _Tp* fetch_sub(ptrdiff_t __op, memory_order __m = memory_order_seq_cst) _NOEXCEPT + {return __c11_atomic_fetch_sub(&this->__a_, __op, __m);} + + _LIBCPP_INLINE_VISIBILITY + _Tp* operator++(int) volatile _NOEXCEPT {return fetch_add(1);} + _LIBCPP_INLINE_VISIBILITY + _Tp* operator++(int) _NOEXCEPT {return fetch_add(1);} + _LIBCPP_INLINE_VISIBILITY + _Tp* operator--(int) volatile _NOEXCEPT {return fetch_sub(1);} + _LIBCPP_INLINE_VISIBILITY + _Tp* operator--(int) _NOEXCEPT {return fetch_sub(1);} + _LIBCPP_INLINE_VISIBILITY + _Tp* operator++() volatile _NOEXCEPT {return fetch_add(1) + 1;} + _LIBCPP_INLINE_VISIBILITY + _Tp* operator++() _NOEXCEPT {return fetch_add(1) + 1;} + _LIBCPP_INLINE_VISIBILITY + _Tp* operator--() volatile _NOEXCEPT {return fetch_sub(1) - 1;} + _LIBCPP_INLINE_VISIBILITY + _Tp* operator--() _NOEXCEPT {return fetch_sub(1) - 1;} + _LIBCPP_INLINE_VISIBILITY + _Tp* operator+=(ptrdiff_t __op) volatile _NOEXCEPT {return fetch_add(__op) + __op;} + _LIBCPP_INLINE_VISIBILITY + _Tp* operator+=(ptrdiff_t __op) _NOEXCEPT {return fetch_add(__op) + __op;} + _LIBCPP_INLINE_VISIBILITY + _Tp* operator-=(ptrdiff_t __op) volatile _NOEXCEPT {return fetch_sub(__op) - __op;} + _LIBCPP_INLINE_VISIBILITY + _Tp* operator-=(ptrdiff_t __op) _NOEXCEPT {return fetch_sub(__op) - __op;} +}; + +// atomic_is_lock_free + +template +inline _LIBCPP_INLINE_VISIBILITY +bool +atomic_is_lock_free(const volatile atomic<_Tp>* __o) _NOEXCEPT +{ + return __o->is_lock_free(); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +bool +atomic_is_lock_free(const atomic<_Tp>* __o) _NOEXCEPT +{ + return __o->is_lock_free(); +} + +// atomic_init + +template +inline _LIBCPP_INLINE_VISIBILITY +void +atomic_init(volatile atomic<_Tp>* __o, _Tp __d) _NOEXCEPT +{ + __c11_atomic_init(&__o->__a_, __d); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +void +atomic_init(atomic<_Tp>* __o, _Tp __d) _NOEXCEPT +{ + __c11_atomic_init(&__o->__a_, __d); +} + +// atomic_store + +template +inline _LIBCPP_INLINE_VISIBILITY +void +atomic_store(volatile atomic<_Tp>* __o, _Tp __d) _NOEXCEPT +{ + __o->store(__d); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +void +atomic_store(atomic<_Tp>* __o, _Tp __d) _NOEXCEPT +{ + __o->store(__d); +} + +// atomic_store_explicit + +template +inline _LIBCPP_INLINE_VISIBILITY +void +atomic_store_explicit(volatile atomic<_Tp>* __o, _Tp __d, memory_order __m) _NOEXCEPT +{ + __o->store(__d, __m); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +void +atomic_store_explicit(atomic<_Tp>* __o, _Tp __d, memory_order __m) _NOEXCEPT +{ + __o->store(__d, __m); +} + +// atomic_load + +template +inline _LIBCPP_INLINE_VISIBILITY +_Tp +atomic_load(const volatile atomic<_Tp>* __o) _NOEXCEPT +{ + return __o->load(); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +_Tp +atomic_load(const atomic<_Tp>* __o) _NOEXCEPT +{ + return __o->load(); +} + +// atomic_load_explicit + +template +inline _LIBCPP_INLINE_VISIBILITY +_Tp +atomic_load_explicit(const volatile atomic<_Tp>* __o, memory_order __m) _NOEXCEPT +{ + return __o->load(__m); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +_Tp +atomic_load_explicit(const atomic<_Tp>* __o, memory_order __m) _NOEXCEPT +{ + return __o->load(__m); +} + +// atomic_exchange + +template +inline _LIBCPP_INLINE_VISIBILITY +_Tp +atomic_exchange(volatile atomic<_Tp>* __o, _Tp __d) _NOEXCEPT +{ + return __o->exchange(__d); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +_Tp +atomic_exchange(atomic<_Tp>* __o, _Tp __d) _NOEXCEPT +{ + return __o->exchange(__d); +} + +// atomic_exchange_explicit + +template +inline _LIBCPP_INLINE_VISIBILITY +_Tp +atomic_exchange_explicit(volatile atomic<_Tp>* __o, _Tp __d, memory_order __m) _NOEXCEPT +{ + return __o->exchange(__d, __m); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +_Tp +atomic_exchange_explicit(atomic<_Tp>* __o, _Tp __d, memory_order __m) _NOEXCEPT +{ + return __o->exchange(__d, __m); +} + +// atomic_compare_exchange_weak + +template +inline _LIBCPP_INLINE_VISIBILITY +bool +atomic_compare_exchange_weak(volatile atomic<_Tp>* __o, _Tp* __e, _Tp __d) _NOEXCEPT +{ + return __o->compare_exchange_weak(*__e, __d); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +bool +atomic_compare_exchange_weak(atomic<_Tp>* __o, _Tp* __e, _Tp __d) _NOEXCEPT +{ + return __o->compare_exchange_weak(*__e, __d); +} + +// atomic_compare_exchange_strong + +template +inline _LIBCPP_INLINE_VISIBILITY +bool +atomic_compare_exchange_strong(volatile atomic<_Tp>* __o, _Tp* __e, _Tp __d) _NOEXCEPT +{ + return __o->compare_exchange_strong(*__e, __d); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +bool +atomic_compare_exchange_strong(atomic<_Tp>* __o, _Tp* __e, _Tp __d) _NOEXCEPT +{ + return __o->compare_exchange_strong(*__e, __d); +} + +// atomic_compare_exchange_weak_explicit + +template +inline _LIBCPP_INLINE_VISIBILITY +bool +atomic_compare_exchange_weak_explicit(volatile atomic<_Tp>* __o, _Tp* __e, + _Tp __d, + memory_order __s, memory_order __f) _NOEXCEPT +{ + return __o->compare_exchange_weak(*__e, __d, __s, __f); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +bool +atomic_compare_exchange_weak_explicit(atomic<_Tp>* __o, _Tp* __e, _Tp __d, + memory_order __s, memory_order __f) _NOEXCEPT +{ + return __o->compare_exchange_weak(*__e, __d, __s, __f); +} + +// atomic_compare_exchange_strong_explicit + +template +inline _LIBCPP_INLINE_VISIBILITY +bool +atomic_compare_exchange_strong_explicit(volatile atomic<_Tp>* __o, + _Tp* __e, _Tp __d, + memory_order __s, memory_order __f) _NOEXCEPT +{ + return __o->compare_exchange_strong(*__e, __d, __s, __f); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +bool +atomic_compare_exchange_strong_explicit(atomic<_Tp>* __o, _Tp* __e, + _Tp __d, + memory_order __s, memory_order __f) _NOEXCEPT +{ + return __o->compare_exchange_strong(*__e, __d, __s, __f); +} + +// atomic_fetch_add + +template +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if +< + is_integral<_Tp>::value && !is_same<_Tp, bool>::value, + _Tp +>::type +atomic_fetch_add(volatile atomic<_Tp>* __o, _Tp __op) _NOEXCEPT +{ + return __o->fetch_add(__op); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if +< + is_integral<_Tp>::value && !is_same<_Tp, bool>::value, + _Tp +>::type +atomic_fetch_add(atomic<_Tp>* __o, _Tp __op) _NOEXCEPT +{ + return __o->fetch_add(__op); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +_Tp* +atomic_fetch_add(volatile atomic<_Tp*>* __o, ptrdiff_t __op) _NOEXCEPT +{ + return __o->fetch_add(__op); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +_Tp* +atomic_fetch_add(atomic<_Tp*>* __o, ptrdiff_t __op) _NOEXCEPT +{ + return __o->fetch_add(__op); +} + +// atomic_fetch_add_explicit + +template +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if +< + is_integral<_Tp>::value && !is_same<_Tp, bool>::value, + _Tp +>::type +atomic_fetch_add_explicit(volatile atomic<_Tp>* __o, _Tp __op, memory_order __m) _NOEXCEPT +{ + return __o->fetch_add(__op, __m); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if +< + is_integral<_Tp>::value && !is_same<_Tp, bool>::value, + _Tp +>::type +atomic_fetch_add_explicit(atomic<_Tp>* __o, _Tp __op, memory_order __m) _NOEXCEPT +{ + return __o->fetch_add(__op, __m); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +_Tp* +atomic_fetch_add_explicit(volatile atomic<_Tp*>* __o, ptrdiff_t __op, + memory_order __m) _NOEXCEPT +{ + return __o->fetch_add(__op, __m); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +_Tp* +atomic_fetch_add_explicit(atomic<_Tp*>* __o, ptrdiff_t __op, memory_order __m) _NOEXCEPT +{ + return __o->fetch_add(__op, __m); +} + +// atomic_fetch_sub + +template +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if +< + is_integral<_Tp>::value && !is_same<_Tp, bool>::value, + _Tp +>::type +atomic_fetch_sub(volatile atomic<_Tp>* __o, _Tp __op) _NOEXCEPT +{ + return __o->fetch_sub(__op); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if +< + is_integral<_Tp>::value && !is_same<_Tp, bool>::value, + _Tp +>::type +atomic_fetch_sub(atomic<_Tp>* __o, _Tp __op) _NOEXCEPT +{ + return __o->fetch_sub(__op); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +_Tp* +atomic_fetch_sub(volatile atomic<_Tp*>* __o, ptrdiff_t __op) _NOEXCEPT +{ + return __o->fetch_sub(__op); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +_Tp* +atomic_fetch_sub(atomic<_Tp*>* __o, ptrdiff_t __op) _NOEXCEPT +{ + return __o->fetch_sub(__op); +} + +// atomic_fetch_sub_explicit + +template +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if +< + is_integral<_Tp>::value && !is_same<_Tp, bool>::value, + _Tp +>::type +atomic_fetch_sub_explicit(volatile atomic<_Tp>* __o, _Tp __op, memory_order __m) _NOEXCEPT +{ + return __o->fetch_sub(__op, __m); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if +< + is_integral<_Tp>::value && !is_same<_Tp, bool>::value, + _Tp +>::type +atomic_fetch_sub_explicit(atomic<_Tp>* __o, _Tp __op, memory_order __m) _NOEXCEPT +{ + return __o->fetch_sub(__op, __m); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +_Tp* +atomic_fetch_sub_explicit(volatile atomic<_Tp*>* __o, ptrdiff_t __op, + memory_order __m) _NOEXCEPT +{ + return __o->fetch_sub(__op, __m); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +_Tp* +atomic_fetch_sub_explicit(atomic<_Tp*>* __o, ptrdiff_t __op, memory_order __m) _NOEXCEPT +{ + return __o->fetch_sub(__op, __m); +} + +// atomic_fetch_and + +template +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if +< + is_integral<_Tp>::value && !is_same<_Tp, bool>::value, + _Tp +>::type +atomic_fetch_and(volatile atomic<_Tp>* __o, _Tp __op) _NOEXCEPT +{ + return __o->fetch_and(__op); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if +< + is_integral<_Tp>::value && !is_same<_Tp, bool>::value, + _Tp +>::type +atomic_fetch_and(atomic<_Tp>* __o, _Tp __op) _NOEXCEPT +{ + return __o->fetch_and(__op); +} + +// atomic_fetch_and_explicit + +template +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if +< + is_integral<_Tp>::value && !is_same<_Tp, bool>::value, + _Tp +>::type +atomic_fetch_and_explicit(volatile atomic<_Tp>* __o, _Tp __op, memory_order __m) _NOEXCEPT +{ + return __o->fetch_and(__op, __m); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if +< + is_integral<_Tp>::value && !is_same<_Tp, bool>::value, + _Tp +>::type +atomic_fetch_and_explicit(atomic<_Tp>* __o, _Tp __op, memory_order __m) _NOEXCEPT +{ + return __o->fetch_and(__op, __m); +} + +// atomic_fetch_or + +template +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if +< + is_integral<_Tp>::value && !is_same<_Tp, bool>::value, + _Tp +>::type +atomic_fetch_or(volatile atomic<_Tp>* __o, _Tp __op) _NOEXCEPT +{ + return __o->fetch_or(__op); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if +< + is_integral<_Tp>::value && !is_same<_Tp, bool>::value, + _Tp +>::type +atomic_fetch_or(atomic<_Tp>* __o, _Tp __op) _NOEXCEPT +{ + return __o->fetch_or(__op); +} + +// atomic_fetch_or_explicit + +template +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if +< + is_integral<_Tp>::value && !is_same<_Tp, bool>::value, + _Tp +>::type +atomic_fetch_or_explicit(volatile atomic<_Tp>* __o, _Tp __op, memory_order __m) _NOEXCEPT +{ + return __o->fetch_or(__op, __m); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if +< + is_integral<_Tp>::value && !is_same<_Tp, bool>::value, + _Tp +>::type +atomic_fetch_or_explicit(atomic<_Tp>* __o, _Tp __op, memory_order __m) _NOEXCEPT +{ + return __o->fetch_or(__op, __m); +} + +// atomic_fetch_xor + +template +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if +< + is_integral<_Tp>::value && !is_same<_Tp, bool>::value, + _Tp +>::type +atomic_fetch_xor(volatile atomic<_Tp>* __o, _Tp __op) _NOEXCEPT +{ + return __o->fetch_xor(__op); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if +< + is_integral<_Tp>::value && !is_same<_Tp, bool>::value, + _Tp +>::type +atomic_fetch_xor(atomic<_Tp>* __o, _Tp __op) _NOEXCEPT +{ + return __o->fetch_xor(__op); +} + +// atomic_fetch_xor_explicit + +template +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if +< + is_integral<_Tp>::value && !is_same<_Tp, bool>::value, + _Tp +>::type +atomic_fetch_xor_explicit(volatile atomic<_Tp>* __o, _Tp __op, memory_order __m) _NOEXCEPT +{ + return __o->fetch_xor(__op, __m); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if +< + is_integral<_Tp>::value && !is_same<_Tp, bool>::value, + _Tp +>::type +atomic_fetch_xor_explicit(atomic<_Tp>* __o, _Tp __op, memory_order __m) _NOEXCEPT +{ + return __o->fetch_xor(__op, __m); +} + +// flag type and operations + +typedef struct atomic_flag +{ + _Atomic(bool) __a_; + + _LIBCPP_INLINE_VISIBILITY + bool test_and_set(memory_order __m = memory_order_seq_cst) volatile _NOEXCEPT + {return __c11_atomic_exchange(&__a_, true, __m);} + _LIBCPP_INLINE_VISIBILITY + bool test_and_set(memory_order __m = memory_order_seq_cst) _NOEXCEPT + {return __c11_atomic_exchange(&__a_, true, __m);} + _LIBCPP_INLINE_VISIBILITY + void clear(memory_order __m = memory_order_seq_cst) volatile _NOEXCEPT + {__c11_atomic_store(&__a_, false, __m);} + _LIBCPP_INLINE_VISIBILITY + void clear(memory_order __m = memory_order_seq_cst) _NOEXCEPT + {__c11_atomic_store(&__a_, false, __m);} + + _LIBCPP_INLINE_VISIBILITY + atomic_flag() _NOEXCEPT {} // = default; + _LIBCPP_INLINE_VISIBILITY + atomic_flag(bool __b) _NOEXCEPT : __a_(__b) {} + +#ifndef _LIBCPP_HAS_NO_DELETED_FUNCTIONS + atomic_flag(const atomic_flag&) = delete; + atomic_flag& operator=(const atomic_flag&) = delete; + atomic_flag& operator=(const atomic_flag&) volatile = delete; +#else // _LIBCPP_HAS_NO_DELETED_FUNCTIONS +private: + atomic_flag(const atomic_flag&); + atomic_flag& operator=(const atomic_flag&); + atomic_flag& operator=(const atomic_flag&) volatile; +#endif // _LIBCPP_HAS_NO_DELETED_FUNCTIONS +} atomic_flag; + +inline _LIBCPP_INLINE_VISIBILITY +bool +atomic_flag_test_and_set(volatile atomic_flag* __o) _NOEXCEPT +{ + return __o->test_and_set(); +} + +inline _LIBCPP_INLINE_VISIBILITY +bool +atomic_flag_test_and_set(atomic_flag* __o) _NOEXCEPT +{ + return __o->test_and_set(); +} + +inline _LIBCPP_INLINE_VISIBILITY +bool +atomic_flag_test_and_set_explicit(volatile atomic_flag* __o, memory_order __m) _NOEXCEPT +{ + return __o->test_and_set(__m); +} + +inline _LIBCPP_INLINE_VISIBILITY +bool +atomic_flag_test_and_set_explicit(atomic_flag* __o, memory_order __m) _NOEXCEPT +{ + return __o->test_and_set(__m); +} + +inline _LIBCPP_INLINE_VISIBILITY +void +atomic_flag_clear(volatile atomic_flag* __o) _NOEXCEPT +{ + __o->clear(); +} + +inline _LIBCPP_INLINE_VISIBILITY +void +atomic_flag_clear(atomic_flag* __o) _NOEXCEPT +{ + __o->clear(); +} + +inline _LIBCPP_INLINE_VISIBILITY +void +atomic_flag_clear_explicit(volatile atomic_flag* __o, memory_order __m) _NOEXCEPT +{ + __o->clear(__m); +} + +inline _LIBCPP_INLINE_VISIBILITY +void +atomic_flag_clear_explicit(atomic_flag* __o, memory_order __m) _NOEXCEPT +{ + __o->clear(__m); +} + +// fences + +inline _LIBCPP_INLINE_VISIBILITY +void +atomic_thread_fence(memory_order __m) _NOEXCEPT +{ + __c11_atomic_thread_fence(__m); +} + +inline _LIBCPP_INLINE_VISIBILITY +void +atomic_signal_fence(memory_order __m) _NOEXCEPT +{ + __c11_atomic_signal_fence(__m); +} + +// Atomics for standard typedef types + +typedef atomic atomic_char; +typedef atomic atomic_schar; +typedef atomic atomic_uchar; +typedef atomic atomic_short; +typedef atomic atomic_ushort; +typedef atomic atomic_int; +typedef atomic atomic_uint; +typedef atomic atomic_long; +typedef atomic atomic_ulong; +typedef atomic atomic_llong; +typedef atomic atomic_ullong; +typedef atomic atomic_char16_t; +typedef atomic atomic_char32_t; +typedef atomic atomic_wchar_t; + +typedef atomic atomic_int_least8_t; +typedef atomic atomic_uint_least8_t; +typedef atomic atomic_int_least16_t; +typedef atomic atomic_uint_least16_t; +typedef atomic atomic_int_least32_t; +typedef atomic atomic_uint_least32_t; +typedef atomic atomic_int_least64_t; +typedef atomic atomic_uint_least64_t; + +typedef atomic atomic_int_fast8_t; +typedef atomic atomic_uint_fast8_t; +typedef atomic atomic_int_fast16_t; +typedef atomic atomic_uint_fast16_t; +typedef atomic atomic_int_fast32_t; +typedef atomic atomic_uint_fast32_t; +typedef atomic atomic_int_fast64_t; +typedef atomic atomic_uint_fast64_t; + +typedef atomic atomic_intptr_t; +typedef atomic atomic_uintptr_t; +typedef atomic atomic_size_t; +typedef atomic atomic_ptrdiff_t; +typedef atomic atomic_intmax_t; +typedef atomic atomic_uintmax_t; + +#define ATOMIC_FLAG_INIT {false} +#define ATOMIC_VAR_INIT(__v) {__v} + +// lock-free property + +#define ATOMIC_CHAR_LOCK_FREE 0 +#define ATOMIC_CHAR16_T_LOCK_FREE 0 +#define ATOMIC_CHAR32_T_LOCK_FREE 0 +#define ATOMIC_WCHAR_T_LOCK_FREE 0 +#define ATOMIC_SHORT_LOCK_FREE 0 +#define ATOMIC_INT_LOCK_FREE 0 +#define ATOMIC_LONG_LOCK_FREE 0 +#define ATOMIC_LLONG_LOCK_FREE 0 + +#endif // !__has_feature(cxx_atomic) + +_LIBCPP_END_NAMESPACE_STD + +#endif // _LIBCPP_ATOMIC Index: stable/9/contrib/libc++/include/cmath =================================================================== --- stable/9/contrib/libc++/include/cmath (nonexistent) +++ stable/9/contrib/libc++/include/cmath (revision 235798) @@ -0,0 +1,1675 @@ +// -*- C++ -*- +//===---------------------------- cmath -----------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP_CMATH +#define _LIBCPP_CMATH + +/* + 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(floating_point x); + +int fpclassify(floating_point x); + +bool isfinite(floating_point x); +bool isinf(floating_point x); +bool isnan(floating_point x); +bool isnormal(floating_point x); + +bool isgreater(floating_point x, floating_point y); +bool isgreaterequal(floating_point x, floating_point y); +bool isless(floating_point x, floating_point y); +bool islessequal(floating_point x, floating_point y); +bool islessgreater(floating_point x, floating_point y); +bool isunordered(floating_point x, floating_point 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); + +} // std + +*/ + +#include <__config> +#include +#include + +#ifdef _MSC_VER +#include "support/win32/math_win32.h" +#endif + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +// signbit + +#ifdef signbit + +template +_LIBCPP_ALWAYS_INLINE +bool +__libcpp_signbit(_A1 __x) +{ + return signbit(__x); +} + +#undef signbit + +template +inline _LIBCPP_INLINE_VISIBILITY +typename std::enable_if::value, bool>::type +signbit(_A1 __x) +{ + return __libcpp_signbit(__x); +} + +#endif // signbit + +// fpclassify + +#ifdef fpclassify + +template +_LIBCPP_ALWAYS_INLINE +int +__libcpp_fpclassify(_A1 __x) +{ + return fpclassify(__x); +} + +#undef fpclassify + +template +inline _LIBCPP_INLINE_VISIBILITY +typename std::enable_if::value, int>::type +fpclassify(_A1 __x) +{ + return __libcpp_fpclassify(__x); +} + +#endif // fpclassify + +// isfinite + +#ifdef isfinite + +template +_LIBCPP_ALWAYS_INLINE +bool +__libcpp_isfinite(_A1 __x) +{ + return isfinite(__x); +} + +#undef isfinite + +template +inline _LIBCPP_INLINE_VISIBILITY +typename std::enable_if::value, bool>::type +isfinite(_A1 __x) +{ + return __libcpp_isfinite(__x); +} + +#endif // isfinite + +// isinf + +#ifdef isinf + +template +_LIBCPP_ALWAYS_INLINE +bool +__libcpp_isinf(_A1 __x) +{ + return isinf(__x); +} + +#undef isinf + +template +inline _LIBCPP_INLINE_VISIBILITY +typename std::enable_if::value, bool>::type +isinf(_A1 __x) +{ + return __libcpp_isinf(__x); +} + +#endif // isinf + +// isnan + +#ifdef isnan + +template +_LIBCPP_ALWAYS_INLINE +bool +__libcpp_isnan(_A1 __x) +{ + return isnan(__x); +} + +#undef isnan + +template +inline _LIBCPP_INLINE_VISIBILITY +typename std::enable_if::value, bool>::type +isnan(_A1 __x) +{ + return __libcpp_isnan(__x); +} + +#endif // isnan + +// isnormal + +#ifdef isnormal + +template +_LIBCPP_ALWAYS_INLINE +bool +__libcpp_isnormal(_A1 __x) +{ + return isnormal(__x); +} + +#undef isnormal + +template +inline _LIBCPP_INLINE_VISIBILITY +typename std::enable_if::value, bool>::type +isnormal(_A1 __x) +{ + return __libcpp_isnormal(__x); +} + +#endif // isnormal + +// isgreater + +#ifdef isgreater + +template +_LIBCPP_ALWAYS_INLINE +bool +__libcpp_isgreater(_A1 __x, _A2 __y) +{ + return isgreater(__x, __y); +} + +#undef isgreater + +template +inline _LIBCPP_INLINE_VISIBILITY +typename std::enable_if +< + std::is_floating_point<_A1>::value && + std::is_floating_point<_A2>::value, + bool +>::type +isgreater(_A1 __x, _A2 __y) +{ + return __libcpp_isgreater(__x, __y); +} + +#endif // isgreater + +// isgreaterequal + +#ifdef isgreaterequal + +template +_LIBCPP_ALWAYS_INLINE +bool +__libcpp_isgreaterequal(_A1 __x, _A2 __y) +{ + return isgreaterequal(__x, __y); +} + +#undef isgreaterequal + +template +inline _LIBCPP_INLINE_VISIBILITY +typename std::enable_if +< + std::is_floating_point<_A1>::value && + std::is_floating_point<_A2>::value, + bool +>::type +isgreaterequal(_A1 __x, _A2 __y) +{ + return __libcpp_isgreaterequal(__x, __y); +} + +#endif // isgreaterequal + +// isless + +#ifdef isless + +template +_LIBCPP_ALWAYS_INLINE +bool +__libcpp_isless(_A1 __x, _A2 __y) +{ + return isless(__x, __y); +} + +#undef isless + +template +inline _LIBCPP_INLINE_VISIBILITY +typename std::enable_if +< + std::is_floating_point<_A1>::value && + std::is_floating_point<_A2>::value, + bool +>::type +isless(_A1 __x, _A2 __y) +{ + return __libcpp_isless(__x, __y); +} + +#endif // isless + +// islessequal + +#ifdef islessequal + +template +_LIBCPP_ALWAYS_INLINE +bool +__libcpp_islessequal(_A1 __x, _A2 __y) +{ + return islessequal(__x, __y); +} + +#undef islessequal + +template +inline _LIBCPP_INLINE_VISIBILITY +typename std::enable_if +< + std::is_floating_point<_A1>::value && + std::is_floating_point<_A2>::value, + bool +>::type +islessequal(_A1 __x, _A2 __y) +{ + return __libcpp_islessequal(__x, __y); +} + +#endif // islessequal + +// islessgreater + +#ifdef islessgreater + +template +_LIBCPP_ALWAYS_INLINE +bool +__libcpp_islessgreater(_A1 __x, _A2 __y) +{ + return islessgreater(__x, __y); +} + +#undef islessgreater + +template +inline _LIBCPP_INLINE_VISIBILITY +typename std::enable_if +< + std::is_floating_point<_A1>::value && + std::is_floating_point<_A2>::value, + bool +>::type +islessgreater(_A1 __x, _A2 __y) +{ + return __libcpp_islessgreater(__x, __y); +} + +#endif // islessgreater + +// isunordered + +#ifdef isunordered + +template +_LIBCPP_ALWAYS_INLINE +bool +__libcpp_isunordered(_A1 __x, _A2 __y) +{ + return isunordered(__x, __y); +} + +#undef isunordered + +template +inline _LIBCPP_INLINE_VISIBILITY +typename std::enable_if +< + std::is_floating_point<_A1>::value && + std::is_floating_point<_A2>::value, + bool +>::type +isunordered(_A1 __x, _A2 __y) +{ + return __libcpp_isunordered(__x, __y); +} + +#endif // isunordered + +_LIBCPP_BEGIN_NAMESPACE_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; + +// abs + +inline _LIBCPP_INLINE_VISIBILITY +float +abs(float __x) {return fabsf(__x);} + +inline _LIBCPP_INLINE_VISIBILITY +double +abs(double __x) {return fabs(__x);} + +inline _LIBCPP_INLINE_VISIBILITY +long double +abs(long double __x) {return fabsl(__x);} + +#ifndef __sun__ + +// acos + +using ::acos; +using ::acosf; + +#ifndef _MSC_VER +inline _LIBCPP_INLINE_VISIBILITY float acos(float __x) {return acosf(__x);} +inline _LIBCPP_INLINE_VISIBILITY long double acos(long double __x) {return acosl(__x);} +#endif + +template +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if::value, double>::type +acos(_A1 __x) {return acos((double)__x);} + +// asin + +using ::asin; +using ::asinf; + +#ifndef _MSC_VER +inline _LIBCPP_INLINE_VISIBILITY float asin(float __x) {return asinf(__x);} +inline _LIBCPP_INLINE_VISIBILITY long double asin(long double __x) {return asinl(__x);} +#endif + +template +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if::value, double>::type +asin(_A1 __x) {return asin((double)__x);} + +// atan + +using ::atan; +using ::atanf; + +#ifndef _MSC_VER +inline _LIBCPP_INLINE_VISIBILITY float atan(float __x) {return atanf(__x);} +inline _LIBCPP_INLINE_VISIBILITY long double atan(long double __x) {return atanl(__x);} +#endif + +template +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if::value, double>::type +atan(_A1 __x) {return atan((double)__x);} + +// atan2 + +using ::atan2; +using ::atan2f; + +#ifndef _MSC_VER +inline _LIBCPP_INLINE_VISIBILITY float atan2(float __y, float __x) {return atan2f(__y, __x);} +inline _LIBCPP_INLINE_VISIBILITY long double atan2(long double __y, long double __x) {return atan2l(__y, __x);} +#endif + +template +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if +< + is_arithmetic<_A1>::value && + is_arithmetic<_A2>::value, + typename __promote<_A1, _A2>::type +>::type +atan2(_A1 __y, _A2 __x) +{ + typedef typename __promote<_A1, _A2>::type __result_type; + static_assert((!(is_same<_A1, __result_type>::value && + is_same<_A2, __result_type>::value)), ""); + return atan2((__result_type)__y, (__result_type)__x); +} + +// ceil + +using ::ceil; +using ::ceilf; + +#ifndef _MSC_VER +inline _LIBCPP_INLINE_VISIBILITY float ceil(float __x) {return ceilf(__x);} +inline _LIBCPP_INLINE_VISIBILITY long double ceil(long double __x) {return ceill(__x);} +#endif + +template +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if::value, double>::type +ceil(_A1 __x) {return ceil((double)__x);} + +// cos + +using ::cos; +using ::cosf; + +#ifndef _MSC_VER +inline _LIBCPP_INLINE_VISIBILITY float cos(float __x) {return cosf(__x);} +inline _LIBCPP_INLINE_VISIBILITY long double cos(long double __x) {return cosl(__x);} +#endif + +template +inline _LIBCPP_ALWAYS_INLINE _LIBCPP_INLINE_VISIBILITY +typename enable_if::value, double>::type +cos(_A1 __x) {return cos((double)__x);} + +// cosh + +using ::cosh; +using ::coshf; + +#ifndef _MSC_VER +inline _LIBCPP_INLINE_VISIBILITY float cosh(float __x) {return coshf(__x);} +inline _LIBCPP_INLINE_VISIBILITY long double cosh(long double __x) {return coshl(__x);} +#endif + +template +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if::value, double>::type +cosh(_A1 __x) {return cosh((double)__x);} + +#endif // __sun__ +// exp + +using ::exp; +using ::expf; + +#ifndef __sun__ + +#ifndef _MSC_VER +inline _LIBCPP_INLINE_VISIBILITY float exp(float __x) {return expf(__x);} +inline _LIBCPP_INLINE_VISIBILITY long double exp(long double __x) {return expl(__x);} +#endif + + +template +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if::value, double>::type +exp(_A1 __x) {return exp((double)__x);} + +// fabs + +using ::fabs; +using ::fabsf; + +#ifndef _MSC_VER +inline _LIBCPP_INLINE_VISIBILITY float fabs(float __x) {return fabsf(__x);} +inline _LIBCPP_INLINE_VISIBILITY long double fabs(long double __x) {return fabsl(__x);} +#endif + +template +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if::value, double>::type +fabs(_A1 __x) {return fabs((double)__x);} + +// floor + +using ::floor; +using ::floorf; + +#ifndef _MSC_VER +inline _LIBCPP_INLINE_VISIBILITY float floor(float __x) {return floorf(__x);} +inline _LIBCPP_INLINE_VISIBILITY long double floor(long double __x) {return floorl(__x);} +#endif + +template +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if::value, double>::type +floor(_A1 __x) {return floor((double)__x);} + +// fmod + +#endif //__sun__ +using ::fmod; +using ::fmodf; +#ifndef __sun__ + +#ifndef _MSC_VER +inline _LIBCPP_INLINE_VISIBILITY float fmod(float __x, float __y) {return fmodf(__x, __y);} +inline _LIBCPP_INLINE_VISIBILITY long double fmod(long double __x, long double __y) {return fmodl(__x, __y);} +#endif + +template +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if +< + is_arithmetic<_A1>::value && + is_arithmetic<_A2>::value, + typename __promote<_A1, _A2>::type +>::type +fmod(_A1 __x, _A2 __y) +{ + typedef typename __promote<_A1, _A2>::type __result_type; + static_assert((!(is_same<_A1, __result_type>::value && + is_same<_A2, __result_type>::value)), ""); + return fmod((__result_type)__x, (__result_type)__y); +} + + +// frexp + +using ::frexp; +using ::frexpf; + +#ifndef _MSC_VER +inline _LIBCPP_INLINE_VISIBILITY float frexp(float __x, int* __e) {return frexpf(__x, __e);} +inline _LIBCPP_INLINE_VISIBILITY long double frexp(long double __x, int* __e) {return frexpl(__x, __e);} +#endif + +template +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if::value, double>::type +frexp(_A1 __x, int* __e) {return frexp((double)__x, __e);} + +// ldexp + +using ::ldexp; +using ::ldexpf; + +#ifndef _MSC_VER +inline _LIBCPP_INLINE_VISIBILITY float ldexp(float __x, int __e) {return ldexpf(__x, __e);} +inline _LIBCPP_INLINE_VISIBILITY long double ldexp(long double __x, int __e) {return ldexpl(__x, __e);} +#endif + +template +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if::value, double>::type +ldexp(_A1 __x, int __e) {return ldexp((double)__x, __e);} + +// log + +#endif // __sun__ +using ::log; +using ::logf; +#ifndef __sun__ + +#ifndef _MSC_VER +inline _LIBCPP_INLINE_VISIBILITY float log(float __x) {return logf(__x);} +inline _LIBCPP_INLINE_VISIBILITY long double log(long double __x) {return logl(__x);} +#endif + +template +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if::value, double>::type +log(_A1 __x) {return log((double)__x);} + + +// log10 + +using ::log10; +using ::log10f; + +#ifndef _MSC_VER +inline _LIBCPP_INLINE_VISIBILITY float log10(float __x) {return log10f(__x);} +inline _LIBCPP_INLINE_VISIBILITY long double log10(long double __x) {return log10l(__x);} +#endif + +template +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if::value, double>::type +log10(_A1 __x) {return log10((double)__x);} + +// modf + +using ::modf; +using ::modff; + +#ifndef _MSC_VER +inline _LIBCPP_INLINE_VISIBILITY float modf(float __x, float* __y) {return modff(__x, __y);} +inline _LIBCPP_INLINE_VISIBILITY long double modf(long double __x, long double* __y) {return modfl(__x, __y);} +#endif + +// pow + +#endif // __sun__ +using ::pow; +using ::powf; + +#ifndef __sun__ + +#ifndef _MSC_VER +inline _LIBCPP_INLINE_VISIBILITY float pow(float __x, float __y) {return powf(__x, __y);} +inline _LIBCPP_INLINE_VISIBILITY long double pow(long double __x, long double __y) {return powl(__x, __y);} +#endif + +template +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if +< + is_arithmetic<_A1>::value && + is_arithmetic<_A2>::value, + typename __promote<_A1, _A2>::type +>::type +pow(_A1 __x, _A2 __y) +{ + typedef typename __promote<_A1, _A2>::type __result_type; + static_assert((!(is_same<_A1, __result_type>::value && + is_same<_A2, __result_type>::value)), ""); + return pow((__result_type)__x, (__result_type)__y); +} + + +// sin + +using ::sin; +using ::sinf; + +#ifndef _MSC_VER +inline _LIBCPP_INLINE_VISIBILITY float sin(float __x) {return sinf(__x);} +inline _LIBCPP_INLINE_VISIBILITY long double sin(long double __x) {return sinl(__x);} +#endif + +template +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if::value, double>::type +sin(_A1 __x) {return sin((double)__x);} + +// sinh + +using ::sinh; +using ::sinhf; + +#ifndef _MSC_VER +inline _LIBCPP_INLINE_VISIBILITY float sinh(float __x) {return sinhf(__x);} +inline _LIBCPP_INLINE_VISIBILITY long double sinh(long double __x) {return sinhl(__x);} +#endif + +template +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if::value, double>::type +sinh(_A1 __x) {return sinh((double)__x);} + +// sqrt + +#endif // __sun__ +using ::sqrt; +using ::sqrtf; + + +#if !(defined(_MSC_VER) || defined(__sun__)) +inline _LIBCPP_INLINE_VISIBILITY float sqrt(float __x) {return sqrtf(__x);} +inline _LIBCPP_INLINE_VISIBILITY long double sqrt(long double __x) {return sqrtl(__x);} +#endif + +template +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if::value, double>::type +sqrt(_A1 __x) {return sqrt((double)__x);} + +// tan + +using ::tan; +using ::tanf; +#ifndef __sun__ + +#ifndef _MSC_VER +inline _LIBCPP_INLINE_VISIBILITY float tan(float __x) {return tanf(__x);} +inline _LIBCPP_INLINE_VISIBILITY long double tan(long double __x) {return tanl(__x);} +#endif + +template +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if::value, double>::type +tan(_A1 __x) {return tan((double)__x);} + +// tanh + +using ::tanh; +using ::tanhf; + +#ifndef _MSC_VER +inline _LIBCPP_INLINE_VISIBILITY float tanh(float __x) {return tanhf(__x);} +inline _LIBCPP_INLINE_VISIBILITY long double tanh(long double __x) {return tanhl(__x);} +#endif + +template +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if::value, double>::type +tanh(_A1 __x) {return tanh((double)__x);} + +// acosh + +#ifndef _MSC_VER +using ::acosh; +using ::acoshf; + +inline _LIBCPP_INLINE_VISIBILITY float acosh(float __x) {return acoshf(__x);} +inline _LIBCPP_INLINE_VISIBILITY long double acosh(long double __x) {return acoshl(__x);} + +template +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if::value, double>::type +acosh(_A1 __x) {return acosh((double)__x);} +#endif + +// asinh + +#ifndef _MSC_VER +using ::asinh; +using ::asinhf; + +inline _LIBCPP_INLINE_VISIBILITY float asinh(float __x) {return asinhf(__x);} +inline _LIBCPP_INLINE_VISIBILITY long double asinh(long double __x) {return asinhl(__x);} + +template +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if::value, double>::type +asinh(_A1 __x) {return asinh((double)__x);} +#endif + +// atanh + +#ifndef _MSC_VER +using ::atanh; +using ::atanhf; + +inline _LIBCPP_INLINE_VISIBILITY float atanh(float __x) {return atanhf(__x);} +inline _LIBCPP_INLINE_VISIBILITY long double atanh(long double __x) {return atanhl(__x);} + +template +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if::value, double>::type +atanh(_A1 __x) {return atanh((double)__x);} +#endif + +// cbrt + +#ifndef _MSC_VER +using ::cbrt; +using ::cbrtf; + +inline _LIBCPP_INLINE_VISIBILITY float cbrt(float __x) {return cbrtf(__x);} +inline _LIBCPP_INLINE_VISIBILITY long double cbrt(long double __x) {return cbrtl(__x);} + +template +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if::value, double>::type +cbrt(_A1 __x) {return cbrt((double)__x);} +#endif + +// copysign + +using ::copysign; +using ::copysignf; + +inline _LIBCPP_INLINE_VISIBILITY float copysign(float __x, float __y) {return copysignf(__x, __y);} +inline _LIBCPP_INLINE_VISIBILITY long double copysign(long double __x, long double __y) {return copysignl(__x, __y);} + +template +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if +< + is_arithmetic<_A1>::value && + is_arithmetic<_A2>::value, + typename __promote<_A1, _A2>::type +>::type +copysign(_A1 __x, _A2 __y) +{ + typedef typename __promote<_A1, _A2>::type __result_type; + static_assert((!(is_same<_A1, __result_type>::value && + is_same<_A2, __result_type>::value)), ""); + return copysign((__result_type)__x, (__result_type)__y); +} + +#ifndef _MSC_VER + +// erf + +using ::erf; +using ::erff; + +inline _LIBCPP_INLINE_VISIBILITY float erf(float __x) {return erff(__x);} +inline _LIBCPP_INLINE_VISIBILITY long double erf(long double __x) {return erfl(__x);} + +template +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if::value, double>::type +erf(_A1 __x) {return erf((double)__x);} + +// erfc + +using ::erfc; +using ::erfcf; + +inline _LIBCPP_INLINE_VISIBILITY float erfc(float __x) {return erfcf(__x);} +inline _LIBCPP_INLINE_VISIBILITY long double erfc(long double __x) {return erfcl(__x);} + +template +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if::value, double>::type +erfc(_A1 __x) {return erfc((double)__x);} + +// exp2 + +using ::exp2; +using ::exp2f; + +inline _LIBCPP_INLINE_VISIBILITY float exp2(float __x) {return exp2f(__x);} +inline _LIBCPP_INLINE_VISIBILITY long double exp2(long double __x) {return exp2l(__x);} + +template +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if::value, double>::type +exp2(_A1 __x) {return exp2((double)__x);} + +// expm1 + +using ::expm1; +using ::expm1f; + +inline _LIBCPP_INLINE_VISIBILITY float expm1(float __x) {return expm1f(__x);} +inline _LIBCPP_INLINE_VISIBILITY long double expm1(long double __x) {return expm1l(__x);} + +template +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if::value, double>::type +expm1(_A1 __x) {return expm1((double)__x);} + +// fdim + +using ::fdim; +using ::fdimf; + +inline _LIBCPP_INLINE_VISIBILITY float fdim(float __x, float __y) {return fdimf(__x, __y);} +inline _LIBCPP_INLINE_VISIBILITY long double fdim(long double __x, long double __y) {return fdiml(__x, __y);} + +template +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if +< + is_arithmetic<_A1>::value && + is_arithmetic<_A2>::value, + typename __promote<_A1, _A2>::type +>::type +fdim(_A1 __x, _A2 __y) +{ + typedef typename __promote<_A1, _A2>::type __result_type; + static_assert((!(is_same<_A1, __result_type>::value && + is_same<_A2, __result_type>::value)), ""); + return fdim((__result_type)__x, (__result_type)__y); +} + +// fma + +inline _LIBCPP_INLINE_VISIBILITY float fmaf(float __x, float __y, float __z) {return (float)((double)__x*__y + __z);} +#define FP_FAST_FMAF + +using ::fma; + +inline _LIBCPP_INLINE_VISIBILITY float fma(float __x, float __y, float __z) {return fmaf(__x, __y, __z);} +inline _LIBCPP_INLINE_VISIBILITY long double fma(long double __x, long double __y, long double __z) {return fmal(__x, __y, __z);} + +template +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if +< + is_arithmetic<_A1>::value && + is_arithmetic<_A2>::value && + is_arithmetic<_A3>::value, + typename __promote<_A1, _A2, _A3>::type +>::type +fma(_A1 __x, _A2 __y, _A3 __z) +{ + 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 fma((__result_type)__x, (__result_type)__y, (__result_type)__z); +} + +// fmax + +using ::fmax; +using ::fmaxf; + +inline _LIBCPP_INLINE_VISIBILITY float fmax(float __x, float __y) {return fmaxf(__x, __y);} +inline _LIBCPP_INLINE_VISIBILITY long double fmax(long double __x, long double __y) {return fmaxl(__x, __y);} + +template +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if +< + is_arithmetic<_A1>::value && + is_arithmetic<_A2>::value, + typename __promote<_A1, _A2>::type +>::type +fmax(_A1 __x, _A2 __y) +{ + typedef typename __promote<_A1, _A2>::type __result_type; + static_assert((!(is_same<_A1, __result_type>::value && + is_same<_A2, __result_type>::value)), ""); + return fmax((__result_type)__x, (__result_type)__y); +} + +// fmin + +using ::fmin; +using ::fminf; + +inline _LIBCPP_INLINE_VISIBILITY float fmin(float __x, float __y) {return fminf(__x, __y);} +inline _LIBCPP_INLINE_VISIBILITY long double fmin(long double __x, long double __y) {return fminl(__x, __y);} + +template +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if +< + is_arithmetic<_A1>::value && + is_arithmetic<_A2>::value, + typename __promote<_A1, _A2>::type +>::type +fmin(_A1 __x, _A2 __y) +{ + typedef typename __promote<_A1, _A2>::type __result_type; + static_assert((!(is_same<_A1, __result_type>::value && + is_same<_A2, __result_type>::value)), ""); + return fmin((__result_type)__x, (__result_type)__y); +} + +// hypot + +using ::hypot; +using ::hypotf; + +inline _LIBCPP_INLINE_VISIBILITY float hypot(float __x, float __y) {return hypotf(__x, __y);} +inline _LIBCPP_INLINE_VISIBILITY long double hypot(long double __x, long double __y) {return hypotl(__x, __y);} + +template +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if +< + is_arithmetic<_A1>::value && + is_arithmetic<_A2>::value, + typename __promote<_A1, _A2>::type +>::type +hypot(_A1 __x, _A2 __y) +{ + typedef typename __promote<_A1, _A2>::type __result_type; + static_assert((!(is_same<_A1, __result_type>::value && + is_same<_A2, __result_type>::value)), ""); + return hypot((__result_type)__x, (__result_type)__y); +} + +// ilogb + +using ::ilogb; +using ::ilogbf; + +inline _LIBCPP_INLINE_VISIBILITY int ilogb(float __x) {return ilogbf(__x);} +inline _LIBCPP_INLINE_VISIBILITY int ilogb(long double __x) {return ilogbl(__x);} + +template +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if::value, int>::type +ilogb(_A1 __x) {return ilogb((double)__x);} + +// lgamma + +using ::lgamma; +using ::lgammaf; + +inline _LIBCPP_INLINE_VISIBILITY float lgamma(float __x) {return lgammaf(__x);} +inline _LIBCPP_INLINE_VISIBILITY long double lgamma(long double __x) {return lgammal(__x);} + + +template +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if::value, double>::type +lgamma(_A1 __x) {return lgamma((double)__x);} + + +// llrint + +using ::llrint; +using ::llrintf; + +inline _LIBCPP_INLINE_VISIBILITY long long llrint(float __x) {return llrintf(__x);} +inline _LIBCPP_INLINE_VISIBILITY long long llrint(long double __x) {return llrintl(__x);} + +template +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if::value, long long>::type +llrint(_A1 __x) {return llrint((double)__x);} + +// llround + +using ::llround; +using ::llroundf; + +inline _LIBCPP_INLINE_VISIBILITY long long llround(float __x) {return llroundf(__x);} +inline _LIBCPP_INLINE_VISIBILITY long long llround(long double __x) {return llroundl(__x);} + +template +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if::value, long long>::type +llround(_A1 __x) {return llround((double)__x);} + +// log1p + +using ::log1p; +using ::log1pf; + +inline _LIBCPP_INLINE_VISIBILITY float log1p(float __x) {return log1pf(__x);} +inline _LIBCPP_INLINE_VISIBILITY long double log1p(long double __x) {return log1pl(__x);} + +template +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if::value, double>::type +log1p(_A1 __x) {return log1p((double)__x);} + +// log2 + +using ::log2; +using ::log2f; + +inline _LIBCPP_INLINE_VISIBILITY float log2(float __x) {return log2f(__x);} +inline _LIBCPP_INLINE_VISIBILITY long double log2(long double __x) {return log2l(__x);} + +template +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if::value, double>::type +log2(_A1 __x) {return log2((double)__x);} + +// logb + +using ::logb; +using ::logbf; + +inline _LIBCPP_INLINE_VISIBILITY float logb(float __x) {return logbf(__x);} +inline _LIBCPP_INLINE_VISIBILITY long double logb(long double __x) {return logbl(__x);} + +template +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if::value, double>::type +logb(_A1 __x) {return logb((double)__x);} + +// lrint + +using ::lrint; +using ::lrintf; + +inline _LIBCPP_INLINE_VISIBILITY long lrint(float __x) {return lrintf(__x);} +inline _LIBCPP_INLINE_VISIBILITY long lrint(long double __x) {return lrintl(__x);} + +template +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if::value, long>::type +lrint(_A1 __x) {return lrint((double)__x);} + +// lround + +using ::lround; +using ::lroundf; + +inline _LIBCPP_INLINE_VISIBILITY long lround(float __x) {return lroundf(__x);} +inline _LIBCPP_INLINE_VISIBILITY long lround(long double __x) {return lroundl(__x);} + +template +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if::value, long>::type +lround(_A1 __x) {return lround((double)__x);} + +// nan +#endif // _MSC_VER +#endif // __sun__ +using ::nan; +using ::nanf; +#ifndef __sun__ +#ifndef _MSC_VER + +// nearbyint + +using ::nearbyint; +using ::nearbyintf; + +inline _LIBCPP_INLINE_VISIBILITY float nearbyint(float __x) {return nearbyintf(__x);} +inline _LIBCPP_INLINE_VISIBILITY long double nearbyint(long double __x) {return nearbyintl(__x);} + +template +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if::value, double>::type +nearbyint(_A1 __x) {return nearbyint((double)__x);} + +// nextafter + +using ::nextafter; +using ::nextafterf; + +inline _LIBCPP_INLINE_VISIBILITY float nextafter(float __x, float __y) {return nextafterf(__x, __y);} +inline _LIBCPP_INLINE_VISIBILITY long double nextafter(long double __x, long double __y) {return nextafterl(__x, __y);} + +template +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if +< + is_arithmetic<_A1>::value && + is_arithmetic<_A2>::value, + typename __promote<_A1, _A2>::type +>::type +nextafter(_A1 __x, _A2 __y) +{ + typedef typename __promote<_A1, _A2>::type __result_type; + static_assert((!(is_same<_A1, __result_type>::value && + is_same<_A2, __result_type>::value)), ""); + return nextafter((__result_type)__x, (__result_type)__y); +} + +// nexttoward + +using ::nexttoward; +using ::nexttowardf; + +inline _LIBCPP_INLINE_VISIBILITY float nexttoward(float __x, long double __y) {return nexttowardf(__x, __y);} +inline _LIBCPP_INLINE_VISIBILITY long double nexttoward(long double __x, long double __y) {return nexttowardl(__x, __y);} + +template +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if::value, double>::type +nexttoward(_A1 __x, long double __y) {return nexttoward((double)__x, __y);} + +// remainder + +using ::remainder; +using ::remainderf; + +inline _LIBCPP_INLINE_VISIBILITY float remainder(float __x, float __y) {return remainderf(__x, __y);} +inline _LIBCPP_INLINE_VISIBILITY long double remainder(long double __x, long double __y) {return remainderl(__x, __y);} + +template +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if +< + is_arithmetic<_A1>::value && + is_arithmetic<_A2>::value, + typename __promote<_A1, _A2>::type +>::type +remainder(_A1 __x, _A2 __y) +{ + typedef typename __promote<_A1, _A2>::type __result_type; + static_assert((!(is_same<_A1, __result_type>::value && + is_same<_A2, __result_type>::value)), ""); + return remainder((__result_type)__x, (__result_type)__y); +} + +// remquo + +using ::remquo; +using ::remquof; + +inline _LIBCPP_INLINE_VISIBILITY float remquo(float __x, float __y, int* __z) {return remquof(__x, __y, __z);} +inline _LIBCPP_INLINE_VISIBILITY long double remquo(long double __x, long double __y, int* __z) {return remquol(__x, __y, __z);} + +template +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if +< + is_arithmetic<_A1>::value && + is_arithmetic<_A2>::value, + typename __promote<_A1, _A2>::type +>::type +remquo(_A1 __x, _A2 __y, int* __z) +{ + typedef typename __promote<_A1, _A2>::type __result_type; + static_assert((!(is_same<_A1, __result_type>::value && + is_same<_A2, __result_type>::value)), ""); + return remquo((__result_type)__x, (__result_type)__y, __z); +} + +// rint + +using ::rint; +using ::rintf; + +inline _LIBCPP_INLINE_VISIBILITY float rint(float __x) {return rintf(__x);} +inline _LIBCPP_INLINE_VISIBILITY long double rint(long double __x) {return rintl(__x);} + +template +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if::value, double>::type +rint(_A1 __x) {return rint((double)__x);} + +// round + +using ::round; +using ::roundf; + +inline _LIBCPP_INLINE_VISIBILITY float round(float __x) {return roundf(__x);} +inline _LIBCPP_INLINE_VISIBILITY long double round(long double __x) {return roundl(__x);} + +template +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if::value, double>::type +round(_A1 __x) {return round((double)__x);} + +// scalbln + +using ::scalbln; +using ::scalblnf; + +inline _LIBCPP_INLINE_VISIBILITY float scalbln(float __x, long __y) {return scalblnf(__x, __y);} +inline _LIBCPP_INLINE_VISIBILITY long double scalbln(long double __x, long __y) {return scalblnl(__x, __y);} + +template +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if::value, double>::type +scalbln(_A1 __x, long __y) {return scalbln((double)__x, __y);} + +// scalbn + +using ::scalbn; +using ::scalbnf; + +inline _LIBCPP_INLINE_VISIBILITY float scalbn(float __x, int __y) {return scalbnf(__x, __y);} +inline _LIBCPP_INLINE_VISIBILITY long double scalbn(long double __x, int __y) {return scalbnl(__x, __y);} + +template +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if::value, double>::type +scalbn(_A1 __x, int __y) {return scalbn((double)__x, __y);} + +// tgamma + +using ::tgamma; +using ::tgammaf; + +inline _LIBCPP_INLINE_VISIBILITY float tgamma(float __x) {return tgammaf(__x);} +inline _LIBCPP_INLINE_VISIBILITY long double tgamma(long double __x) {return tgammal(__x);} + +template +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if::value, double>::type +tgamma(_A1 __x) {return tgamma((double)__x);} + +// trunc + +using ::trunc; +using ::truncf; + +inline _LIBCPP_INLINE_VISIBILITY float trunc(float __x) {return truncf(__x);} +inline _LIBCPP_INLINE_VISIBILITY long double trunc(long double __x) {return truncl(__x);} + +template +inline _LIBCPP_INLINE_VISIBILITY +typename enable_if::value, double>::type +trunc(_A1 __x) {return trunc((double)__x);} + +#endif // !_MSC_VER + +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; +#ifndef _MSC_VER +using ::tanhl; +using ::acoshl; +using ::asinhl; +using ::atanhl; +using ::cbrtl; +#endif // !_MSC_VER +using ::copysignl; +#ifndef _MSC_VER +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; +#endif // !_MSC_VER + +#else +using ::lgamma; +using ::lgammaf; +#endif // __sun__ +_LIBCPP_END_NAMESPACE_STD + +#endif // _LIBCPP_CMATH Index: stable/9/contrib/libc++/include/limits =================================================================== --- stable/9/contrib/libc++/include/limits (nonexistent) +++ stable/9/contrib/libc++/include/limits (revision 235798) @@ -0,0 +1,621 @@ +// -*- C++ -*- +//===---------------------------- limits ----------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP_LIMITS +#define _LIBCPP_LIMITS + +/* + limits synopsis + +namespace std +{ + +template +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; + +template<> class numeric_limits; +template<> class numeric_limits; +template<> class numeric_limits; +template<> class numeric_limits; +template<> class numeric_limits; +template<> class numeric_limits; + +template<> class numeric_limits; +template<> class numeric_limits; +template<> class numeric_limits; +template<> class numeric_limits; +template<> class numeric_limits; +template<> class numeric_limits; +template<> class numeric_limits; +template<> class numeric_limits; + +template<> class numeric_limits; +template<> class numeric_limits; +template<> class numeric_limits; + +} // std + +*/ + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +#include <__config> +#include + +#include <__undef_min_max> + +#if defined(_MSC_VER) +#include "support/win32/limits_win32.h" +#endif // _MSC_VER + +_LIBCPP_BEGIN_NAMESPACE_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 ::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 +struct __libcpp_compute_min +{ + static _LIBCPP_CONSTEXPR const _Tp value = _Tp(_Tp(1) << digits); +}; + +template +struct __libcpp_compute_min<_Tp, digits, false> +{ + static _LIBCPP_CONSTEXPR const _Tp value = _Tp(0); +}; + +template +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(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::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 = true; + +#if __i386__ || __x86_64__ + 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 +{ +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 +{ +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 * 30103)/100000; + _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 +{ +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 * 30103)/100000; + _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 +{ +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 * 30103)/100000; + _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.5;} + + 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 _LIBCPP_VISIBLE numeric_limits + : private __libcpp_numeric_limits::type> +{ + typedef __libcpp_numeric_limits::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 _LIBCPP_VISIBLE numeric_limits + : 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 _LIBCPP_VISIBLE numeric_limits + : 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 _LIBCPP_VISIBLE numeric_limits + : 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; +}; + +_LIBCPP_END_NAMESPACE_STD + +#endif // _LIBCPP_LIMITS Index: stable/9/contrib/libc++/include/memory =================================================================== --- stable/9/contrib/libc++/include/memory (nonexistent) +++ stable/9/contrib/libc++/include/memory (revision 235798) @@ -0,0 +1,5270 @@ +// -*- C++ -*- +//===-------------------------- memory ------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP_MEMORY +#define _LIBCPP_MEMORY + +/* + memory synopsis + +namespace std +{ + +struct allocator_arg_t { }; +constexpr allocator_arg_t allocator_arg = allocator_arg_t(); + +template struct uses_allocator; + +template +struct pointer_traits +{ + typedef Ptr pointer; + typedef
element_type; + typedef
difference_type; + + template using rebind =
; + + static pointer pointer_to(
); +}; + +template +struct pointer_traits +{ + typedef T* pointer; + typedef T element_type; + typedef ptrdiff_t difference_type; + + template using rebind = U*; + + static pointer pointer_to(
) noexcept; +}; + +template +struct allocator_traits +{ + typedef Alloc allocator_type; + typedef typename allocator_type::value_type + value_type; + + typedef Alloc::pointer | value_type* pointer; + typedef Alloc::const_pointer + | pointer_traits::rebind + const_pointer; + typedef Alloc::void_pointer + | pointer_traits::rebind + void_pointer; + typedef Alloc::const_void_pointer + | pointer_traits::rebind + const_void_pointer; + typedef Alloc::difference_type + | pointer_traits::difference_type + difference_type; + typedef Alloc::size_type + | make_unsigned::type + size_type; + typedef Alloc::propagate_on_container_copy_assignment + | false_type propagate_on_container_copy_assignment; + typedef Alloc::propagate_on_container_move_assignment + | false_type propagate_on_container_move_assignment; + typedef Alloc::propagate_on_container_swap + | false_type propagate_on_container_swap; + + template using rebind_alloc = Alloc::rebind::other | Alloc; + template using rebind_traits = allocator_traits>; + + static pointer allocate(allocator_type& a, size_type n); + static pointer allocate(allocator_type& a, size_type n, const_void_pointer hint); + + static void deallocate(allocator_type& a, pointer p, size_type n) noexcept; + + template + static void construct(allocator_type& a, T* p, Args&&... args); + + template + static void destroy(allocator_type& a, T* p); + + static size_type max_size(const allocator_type& a); + + static allocator_type + select_on_container_copy_construction(const allocator_type& a); +}; + +template <> +class allocator +{ +public: + typedef void* pointer; + typedef const void* const_pointer; + typedef void value_type; + + template struct rebind {typedef allocator<_Up> other;}; +}; + +template +class allocator +{ +public: + typedef size_t size_type; + typedef ptrdiff_t difference_type; + typedef T* pointer; + typedef const T* const_pointer; + typedef typename add_lvalue_reference::type reference; + typedef typename add_lvalue_reference::type const_reference; + typedef T value_type; + + template struct rebind {typedef allocator other;}; + + allocator() noexcept; + allocator(const allocator&) noexcept; + template allocator(const allocator&) noexcept; + ~allocator(); + pointer address(reference x) const noexcept; + const_pointer address(const_reference x) const noexcept; + pointer allocate(size_type, allocator::const_pointer hint = 0); + void deallocate(pointer p, size_type n) noexcept; + size_type max_size() const noexcept; + template + void construct(U* p, Args&&... args); + template + void destroy(U* p); +}; + +template +bool operator==(const allocator&, const allocator&) noexcept; + +template +bool operator!=(const allocator&, const allocator&) noexcept; + +template +class raw_storage_iterator + : public iterator // purposefully not C++03 +{ +public: + explicit raw_storage_iterator(OutputIterator x); + raw_storage_iterator& operator*(); + raw_storage_iterator& operator=(const T& element); + raw_storage_iterator& operator++(); + raw_storage_iterator operator++(int); +}; + +template pair get_temporary_buffer(ptrdiff_t n) noexcept; +template void return_temporary_buffer(T* p) noexcept; + +template T* addressof(T& r) noexcept; + +template +ForwardIterator +uninitialized_copy(InputIterator first, InputIterator last, ForwardIterator result); + +template +ForwardIterator +uninitialized_copy_n(InputIterator first, Size n, ForwardIterator result); + +template +void uninitialized_fill(ForwardIterator first, ForwardIterator last, const T& x); + +template +ForwardIterator +uninitialized_fill_n(ForwardIterator first, Size n, const T& x); + +template struct auto_ptr_ref {}; + +template +class auto_ptr +{ +public: + typedef X element_type; + + explicit auto_ptr(X* p =0) throw(); + auto_ptr(auto_ptr&) throw(); + template auto_ptr(auto_ptr&) throw(); + auto_ptr& operator=(auto_ptr&) throw(); + template auto_ptr& operator=(auto_ptr&) throw(); + auto_ptr& operator=(auto_ptr_ref r) throw(); + ~auto_ptr() throw(); + + typename add_lvalue_reference::type operator*() const throw(); + X* operator->() const throw(); + X* get() const throw(); + X* release() throw(); + void reset(X* p =0) throw(); + + auto_ptr(auto_ptr_ref) throw(); + template operator auto_ptr_ref() throw(); + template operator auto_ptr() throw(); +}; + +template +struct default_delete +{ + constexpr default_delete() noexcept = default; + template default_delete(const default_delete&) noexcept; + + void operator()(T*) const noexcept; +}; + +template +struct default_delete +{ + constexpr default_delete() noexcept = default; + void operator()(T*) const noexcept; + template void operator()(U*) const = delete; +}; + +template > +class unique_ptr +{ +public: + typedef see below pointer; + typedef T element_type; + typedef D deleter_type; + + // constructors + constexpr unique_ptr() noexcept; + explicit unique_ptr(pointer p) noexcept; + unique_ptr(pointer p, see below d1) noexcept; + unique_ptr(pointer p, see below d2) noexcept; + unique_ptr(unique_ptr&& u) noexcept; + unique_ptr(nullptr_t) noexcept : unique_ptr() { } + template + unique_ptr(unique_ptr&& u) noexcept; + template + unique_ptr(auto_ptr&& u) noexcept; + + // destructor + ~unique_ptr(); + + // assignment + unique_ptr& operator=(unique_ptr&& u) noexcept; + template unique_ptr& operator=(unique_ptr&& u) noexcept; + unique_ptr& operator=(nullptr_t) noexcept; + + // observers + typename add_lvalue_reference::type operator*() const; + pointer operator->() const noexcept; + pointer get() const noexcept; + deleter_type& get_deleter() noexcept; + const deleter_type& get_deleter() const noexcept; + explicit operator bool() const noexcept; + + // modifiers + pointer release() noexcept; + void reset(pointer p = pointer()) noexcept; + void swap(unique_ptr& u) noexcept; +}; + +template +class unique_ptr +{ +public: + typedef implementation-defined pointer; + typedef T element_type; + typedef D deleter_type; + + // constructors + constexpr unique_ptr() noexcept; + explicit unique_ptr(pointer p) noexcept; + unique_ptr(pointer p, see below d) noexcept; + unique_ptr(pointer p, see below d) noexcept; + unique_ptr(unique_ptr&& u) noexcept; + unique_ptr(nullptr_t) noexcept : unique_ptr() { } + + // destructor + ~unique_ptr(); + + // assignment + unique_ptr& operator=(unique_ptr&& u) noexcept; + unique_ptr& operator=(nullptr_t) noexcept; + + // observers + T& operator[](size_t i) const; + pointer get() const noexcept; + deleter_type& get_deleter() noexcept; + const deleter_type& get_deleter() const noexcept; + explicit operator bool() const noexcept; + + // modifiers + pointer release() noexcept; + void reset(pointer p = pointer()) noexcept; + void reset(nullptr_t) noexcept; + template void reset(U) = delete; + void swap(unique_ptr& u) noexcept; +}; + +template + void swap(unique_ptr& x, unique_ptr& y) noexcept; + +template + bool operator==(const unique_ptr& x, const unique_ptr& y); +template + bool operator!=(const unique_ptr& x, const unique_ptr& y); +template + bool operator<(const unique_ptr& x, const unique_ptr& y); +template + bool operator<=(const unique_ptr& x, const unique_ptr& y); +template + bool operator>(const unique_ptr& x, const unique_ptr& y); +template + bool operator>=(const unique_ptr& x, const unique_ptr& y); + +template + bool operator==(const unique_ptr& x, nullptr_t) noexcept; +template + bool operator==(nullptr_t, const unique_ptr& y) noexcept; +template + bool operator!=(const unique_ptr& x, nullptr_t) noexcept; +template + bool operator!=(nullptr_t, const unique_ptr& y) noexcept; + +template + bool operator<(const unique_ptr& x, nullptr_t); +template + bool operator<(nullptr_t, const unique_ptr& y); +template + bool operator<=(const unique_ptr& x, nullptr_t); +template + bool operator<=(nullptr_t, const unique_ptr& y); +template + bool operator>(const unique_ptr& x, nullptr_t); +template + bool operator>(nullptr_t, const unique_ptr& y); +template + bool operator>=(const unique_ptr& x, nullptr_t); +template + bool operator>=(nullptr_t, const unique_ptr& y); + +class bad_weak_ptr + : public std::exception +{ + bad_weak_ptr() noexcept; +}; + +template +class shared_ptr +{ +public: + typedef T element_type; + + // constructors: + constexpr shared_ptr() noexcept; + template explicit shared_ptr(Y* p); + template shared_ptr(Y* p, D d); + template shared_ptr(Y* p, D d, A a); + template shared_ptr(nullptr_t p, D d); + template shared_ptr(nullptr_t p, D d, A a); + template shared_ptr(const shared_ptr& r, T *p) noexcept; + shared_ptr(const shared_ptr& r) noexcept; + template shared_ptr(const shared_ptr& r) noexcept; + shared_ptr(shared_ptr&& r) noexcept; + template shared_ptr(shared_ptr&& r) noexcept; + template explicit shared_ptr(const weak_ptr& r); + template shared_ptr(auto_ptr&& r); + template shared_ptr(unique_ptr&& r); + shared_ptr(nullptr_t) : shared_ptr() { } + + // destructor: + ~shared_ptr(); + + // assignment: + shared_ptr& operator=(const shared_ptr& r) noexcept; + template shared_ptr& operator=(const shared_ptr& r) noexcept; + shared_ptr& operator=(shared_ptr&& r) noexcept; + template shared_ptr& operator=(shared_ptr&& r); + template shared_ptr& operator=(auto_ptr&& r); + template shared_ptr& operator=(unique_ptr&& r); + + // modifiers: + void swap(shared_ptr& r) noexcept; + void reset() noexcept; + template void reset(Y* p); + template void reset(Y* p, D d); + template void reset(Y* p, D d, A a); + + // observers: + T* get() const noexcept; + T& operator*() const noexcept; + T* operator->() const noexcept; + long use_count() const noexcept; + bool unique() const noexcept; + explicit operator bool() const noexcept; + template bool owner_before(shared_ptr const& b) const; + template bool owner_before(weak_ptr const& b) const; +}; + +// shared_ptr comparisons: +template + bool operator==(shared_ptr const& a, shared_ptr const& b) noexcept; +template + bool operator!=(shared_ptr const& a, shared_ptr const& b) noexcept; +template + bool operator<(shared_ptr const& a, shared_ptr const& b) noexcept; +template + bool operator>(shared_ptr const& a, shared_ptr const& b) noexcept; +template + bool operator<=(shared_ptr const& a, shared_ptr const& b) noexcept; +template + bool operator>=(shared_ptr const& a, shared_ptr const& b) noexcept; + +template + bool operator==(const shared_ptr& x, nullptr_t) noexcept; +template + bool operator==(nullptr_t, const shared_ptr& y) noexcept; +template + bool operator!=(const shared_ptr& x, nullptr_t) noexcept; +template + bool operator!=(nullptr_t, const shared_ptr& y) noexcept; +template + bool operator<(const shared_ptr& x, nullptr_t) noexcept; +template +bool operator<(nullptr_t, const shared_ptr& y) noexcept; +template + bool operator<=(const shared_ptr& x, nullptr_t) noexcept; +template + bool operator<=(nullptr_t, const shared_ptr& y) noexcept; +template + bool operator>(const shared_ptr& x, nullptr_t) noexcept; +template + bool operator>(nullptr_t, const shared_ptr& y) noexcept; +template + bool operator>=(const shared_ptr& x, nullptr_t) noexcept; +template + bool operator>=(nullptr_t, const shared_ptr& y) noexcept; + +// shared_ptr specialized algorithms: +template void swap(shared_ptr& a, shared_ptr& b) noexcept; + +// shared_ptr casts: +template + shared_ptr static_pointer_cast(shared_ptr const& r) noexcept; +template + shared_ptr dynamic_pointer_cast(shared_ptr const& r) noexcept; +template + shared_ptr const_pointer_cast(shared_ptr const& r) noexcept; + +// shared_ptr I/O: +template + basic_ostream& operator<< (basic_ostream& os, shared_ptr const& p); + +// shared_ptr get_deleter: +template D* get_deleter(shared_ptr const& p) noexcept; + +template + shared_ptr make_shared(Args&&... args); +template + shared_ptr allocate_shared(const A& a, Args&&... args); + +template +class weak_ptr +{ +public: + typedef T element_type; + + // constructors + constexpr weak_ptr() noexcept; + template weak_ptr(shared_ptr const& r) noexcept; + weak_ptr(weak_ptr const& r) noexcept; + template weak_ptr(weak_ptr const& r) noexcept; + + // destructor + ~weak_ptr(); + + // assignment + weak_ptr& operator=(weak_ptr const& r) noexcept; + template weak_ptr& operator=(weak_ptr const& r) noexcept; + template weak_ptr& operator=(shared_ptr const& r) noexcept; + + // modifiers + void swap(weak_ptr& r) noexcept; + void reset() noexcept; + + // observers + long use_count() const noexcept; + bool expired() const noexcept; + shared_ptr lock() const noexcept; + template bool owner_before(shared_ptr const& b); + template bool owner_before(weak_ptr const& b); +}; + +// weak_ptr specialized algorithms: +template void swap(weak_ptr& a, weak_ptr& b) noexcept; + +// class owner_less: +template struct owner_less; + +template +struct owner_less> + : binary_function, shared_ptr, bool> +{ + typedef bool result_type; + bool operator()(shared_ptr const&, shared_ptr const&) const; + bool operator()(shared_ptr const&, weak_ptr const&) const; + bool operator()(weak_ptr const&, shared_ptr const&) const; +}; + +template +struct owner_less> + : binary_function, weak_ptr, bool> +{ + typedef bool result_type; + bool operator()(weak_ptr const&, weak_ptr const&) const; + bool operator()(shared_ptr const&, weak_ptr const&) const; + bool operator()(weak_ptr const&, shared_ptr const&) const; +}; + +template +class enable_shared_from_this +{ +protected: + constexpr enable_shared_from_this() noexcept; + enable_shared_from_this(enable_shared_from_this const&) noexcept; + enable_shared_from_this& operator=(enable_shared_from_this const&) noexcept; + ~enable_shared_from_this(); +public: + shared_ptr shared_from_this(); + shared_ptr shared_from_this() const; +}; + +template + bool atomic_is_lock_free(const shared_ptr* p); +template + shared_ptr atomic_load(const shared_ptr* p); +template + shared_ptr atomic_load_explicit(const shared_ptr* p, memory_order mo); +template + void atomic_store(shared_ptr* p, shared_ptr r); +template + void atomic_store_explicit(shared_ptr* p, shared_ptr r, memory_order mo); +template + shared_ptr atomic_exchange(shared_ptr* p, shared_ptr r); +template + shared_ptr + atomic_exchange_explicit(shared_ptr* p, shared_ptr r, memory_order mo); +template + bool + atomic_compare_exchange_weak(shared_ptr* p, shared_ptr* v, shared_ptr w); +template + bool + atomic_compare_exchange_strong( shared_ptr* p, shared_ptr* v, shared_ptr w); +template + bool + atomic_compare_exchange_weak_explicit(shared_ptr* p, shared_ptr* v, + shared_ptr w, memory_order success, + memory_order failure); +template + bool + atomic_compare_exchange_strong_explicit(shared_ptr* p, shared_ptr* v, + shared_ptr w, memory_order success, + memory_order failure); +// Hash support +template struct hash; +template struct hash >; +template struct hash >; + +// Pointer safety +enum class pointer_safety { relaxed, preferred, strict }; +void declare_reachable(void *p); +template T *undeclare_reachable(T *p); +void declare_no_pointers(char *p, size_t n); +void undeclare_no_pointers(char *p, size_t n); +pointer_safety get_pointer_safety() noexcept; + +void* align(size_t alignment, size_t size, void*& ptr, size_t& space); + +} // std + +*/ + +#include <__config> +#include +#include +#include +#include +#include +#include +#include +#include +#include <__functional_base> +#include +#include +#include +#if defined(_LIBCPP_NO_EXCEPTIONS) + #include +#endif + +#include <__undef_min_max> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCPP_BEGIN_NAMESPACE_STD + +// addressof + +template +inline _LIBCPP_INLINE_VISIBILITY +_Tp* +addressof(_Tp& __x) _NOEXCEPT +{ + return (_Tp*)&(char&)__x; +} + +#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 +inline _LIBCPP_INLINE_VISIBILITY +__strong _Tp* +addressof(__strong _Tp& __x) _NOEXCEPT +{ + return &__x; +} + +#ifdef _LIBCPP_HAS_OBJC_ARC_WEAK +template +inline _LIBCPP_INLINE_VISIBILITY +__weak _Tp* +addressof(__weak _Tp& __x) _NOEXCEPT +{ + return &__x; +} +#endif + +template +inline _LIBCPP_INLINE_VISIBILITY +__autoreleasing _Tp* +addressof(__autoreleasing _Tp& __x) _NOEXCEPT +{ + return &__x; +} + +template +inline _LIBCPP_INLINE_VISIBILITY +__unsafe_unretained _Tp* +addressof(__unsafe_unretained _Tp& __x) _NOEXCEPT +{ + return &__x; +} +#endif + +template class allocator; + +template <> +class _LIBCPP_VISIBLE allocator +{ +public: + typedef void* pointer; + typedef const void* const_pointer; + typedef void value_type; + + template struct rebind {typedef allocator<_Up> other;}; +}; + +template <> +class _LIBCPP_VISIBLE allocator +{ +public: + typedef const void* pointer; + typedef const void* const_pointer; + typedef const void value_type; + + template struct rebind {typedef allocator<_Up> other;}; +}; + +// pointer_traits + +template +struct __has_element_type +{ +private: + struct __two {char _; char __;}; + template static __two __test(...); + template static char __test(typename _Up::element_type* = 0); +public: + static const bool value = sizeof(__test<_Tp>(0)) == 1; +}; + +template ::value> +struct __pointer_traits_element_type; + +template +struct __pointer_traits_element_type<_Ptr, true> +{ + typedef typename _Ptr::element_type type; +}; + +#ifndef _LIBCPP_HAS_NO_VARIADICS + +template