diff options
author | Dimitry Andric <dim@FreeBSD.org> | 2015-12-30 11:54:09 +0000 |
---|---|---|
committer | Dimitry Andric <dim@FreeBSD.org> | 2015-12-30 11:54:09 +0000 |
commit | b4c64ad90b81d2a779786b7edb4c5c6dd28cc57d (patch) | |
tree | 13f237c02db4d1894ab06884d1b739344766bede | |
parent | 61b9a7258a7693d7f3674a5a1daf7b036ff1d382 (diff) | |
download | src-b4c64ad90b81d2a779786b7edb4c5c6dd28cc57d.tar.gz src-b4c64ad90b81d2a779786b7edb4c5c6dd28cc57d.zip |
Vendor import of libc++ trunk r256633:vendor/libc++/r256633
Notes
Notes:
svn path=/vendor/libc++/dist/; revision=292928
svn path=/vendor/libc++/r256633/; revision=292930; tag=vendor/libc++/r256633
809 files changed, 24694 insertions, 10085 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 687c4cfc29a9..e6c96f64711b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,13 +3,16 @@ #=============================================================================== # Setup Project #=============================================================================== - -project(libcxx CXX C) cmake_minimum_required(VERSION 2.8) if(POLICY CMP0042) cmake_policy(SET CMP0042 NEW) # Set MACOSX_RPATH=YES by default endif() +if(POLICY CMP0022) + cmake_policy(SET CMP0022 NEW) # Required when interacting with LLVM and Clang +endif() + +project(libcxx CXX C) set(PACKAGE_NAME libcxx) set(PACKAGE_VERSION trunk-svn) @@ -30,61 +33,40 @@ MACRO_ENSURE_OUT_OF_SOURCE_BUILD( build directory and run 'cmake /path/to/${PROJECT_NAME} [options]' there." ) -if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR) - set(LIBCXX_LIBDIR_SUFFIX "" CACHE STRING - "Define suffix of library directory name (32/64)") - - set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib${LIBCXX_LIBDIR_SUFFIX}) - set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib${LIBCXX_LIBDIR_SUFFIX}) - - set(LIBCXX_BUILT_STANDALONE 1) -else() - set(LIBCXX_LIBDIR_SUFFIX ${LLVM_LIBDIR_SUFFIX}) +# Find the LLVM sources and simulate LLVM CMake options. +include(HandleOutOfTreeLLVM) +if (LIBCXX_BUILT_STANDALONE AND NOT LLVM_FOUND) + message(WARNING "UNSUPPORTED LIBCXX CONFIGURATION DETECTED: " + "llvm-config not found and LLVM_PATH not defined.\n" + "Reconfigure with -DLLVM_CONFIG=path/to/llvm-config " + "or -DLLVM_PATH=path/to/llvm-source-root.") endif() #=============================================================================== # Setup CMake Options #=============================================================================== -# Define options. -option(LIBCXX_ENABLE_EXCEPTIONS "Use exceptions." ON) -option(LIBCXX_ENABLE_RTTI "Use run time type information." ON) +# Basic options --------------------------------------------------------------- option(LIBCXX_ENABLE_ASSERTIONS "Enable assertions independent of build mode." ON) -option(LIBCXX_ENABLE_PEDANTIC "Compile with pedantic enabled." ON) -option(LIBCXX_ENABLE_WERROR "Fail and stop if a warning is triggered." OFF) -option(LIBCXX_ENABLE_CXX1Y "Enable -std=c++1y and use of c++1y language features if the compiler supports it." OFF) option(LIBCXX_ENABLE_SHARED "Build libc++ as a shared library." ON) -option(LIBCXX_ENABLE_GLOBAL_FILESYSTEM_NAMESPACE "Build libc++ with support for the global filesystem namespace." ON) -option(LIBCXX_ENABLE_STDIN "Build libc++ with support for stdin/std::cin." ON) -option(LIBCXX_ENABLE_STDOUT "Build libc++ with support for stdout/std::cout." ON) -option(LIBCXX_ENABLE_THREADS "Build libc++ with support for threads." ON) -option(LIBCXX_ENABLE_THREAD_UNSAFE_C_FUNCTIONS "Build libc++ with support for thread-unsafe C functions" ON) -option(LIBCXX_BUILD_32_BITS "Build 32 bit libc++" OFF) -option(LIBCXX_ENABLE_MONOTONIC_CLOCK - "Build libc++ with support for a monotonic clock. - This option may only be used when LIBCXX_ENABLE_THREADS=OFF." ON) + +option(LIBCXX_INCLUDE_TESTS "Build the libc++ tests." ${LLVM_INCLUDE_TESTS}) +option(LIBCXX_INCLUDE_DOCS "Build the libc++ documentation." ${LLVM_INCLUDE_DOCS}) +set(LIBCXX_LIBDIR_SUFFIX "${LLVM_LIBDIR_SUFFIX}" CACHE STRING + "Define suffix of library directory name (32/64)") option(LIBCXX_INSTALL_HEADERS "Install the libc++ headers." ON) +option(LIBCXX_INSTALL_LIBRARY "Install the libc++ library." ON) option(LIBCXX_INSTALL_SUPPORT_HEADERS "Install libc++ support headers." ON) -option(LIBCXX_GENERATE_COVERAGE "Enable generating code coverage." OFF) -set(LIBCXX_COVERAGE_LIBRARY "" CACHE STRING - "The Profile-rt library used to build with code coverage") -option(LIBCXX_ENABLE_STATIC_ABI_LIBRARY "Statically link the ABI library" OFF) -set(LIBCXX_SYSROOT "" CACHE STRING "Use alternate sysroot.") -set(LIBCXX_GCC_TOOLCHAIN "" CACHE STRING "Use alternate GCC toolchain.") -if (LIBCXX_BUILT_STANDALONE) - set(LLVM_USE_SANITIZER "" CACHE STRING - "Define the sanitizer used to build the library and tests") -endif() - -if (LIBCXX_ENABLE_STATIC_ABI_LIBRARY) - if (APPLE) - message(FATAL_ERROR "LIBCXX_ENABLE_STATIC_ABI_LIBRARY is not supported on OS X") - else() - message(WARNING "LIBCXX_ENABLE_STATIC_ABI_LIBRARY is an experimental option") - endif() -endif() +set(LIBCXX_ABI_VERSION 1 CACHE STRING "ABI version of libc++.") +option(LIBCXX_ABI_UNSTABLE "Unstable ABI of libc++." OFF) +# ABI Library options --------------------------------------------------------- +set(LIBCXX_CXX_ABI "${LIBCXX_CXX_ABI}" CACHE STRING + "Specify C++ ABI library to use." FORCE) set(CXXABIS none libcxxabi libcxxrt libstdc++ libsupc++) +set_property(CACHE LIBCXX_CXX_ABI PROPERTY STRINGS ;${CXXABIS}) + +# Setup the default options if LIBCXX_CXX_ABI is not specified. if (NOT LIBCXX_CXX_ABI) if (NOT DEFINED LIBCXX_BUILT_STANDALONE AND IS_DIRECTORY "${CMAKE_SOURCE_DIR}/projects/libcxxabi") @@ -97,14 +79,139 @@ if (NOT LIBCXX_CXX_ABI) else () set(LIBCXX_CXX_ABI_LIBNAME "${LIBCXX_CXX_ABI}") endif () -set(LIBCXX_CXX_ABI "${LIBCXX_CXX_ABI}" CACHE STRING - "Specify C++ ABI library to use." FORCE) -set_property(CACHE LIBCXX_CXX_ABI PROPERTY STRINGS ;${CXXABIS}) + +# Use a static copy of the ABI library when linking libc++. This option +# cannot be used with LIBCXX_ENABLE_ABI_LINKER_SCRIPT. +option(LIBCXX_ENABLE_STATIC_ABI_LIBRARY "Statically link the ABI library" OFF) + +# Generate and install a linker script inplace of libc++.so. The linker script +# will link libc++ to the correct ABI library. This option is on by default +# On UNIX platforms other than Apple unless 'LIBCXX_ENABLE_STATIC_ABI_LIBRARY' +# is on. This option is also disabled when the ABI library is not specified +# or is specified to be "none". +set(ENABLE_LINKER_SCRIPT_DEFAULT_VALUE OFF) +if (LLVM_HAVE_LINK_VERSION_SCRIPT AND NOT LIBCXX_ENABLE_STATIC_ABI_LIBRARY + AND NOT LIBCXX_CXX_ABI_LIBNAME STREQUAL "none" + AND PYTHONINTERP_FOUND) + set(ENABLE_LINKER_SCRIPT_DEFAULT_VALUE ON) +endif() + +option(LIBCXX_ENABLE_ABI_LINKER_SCRIPT + "Use and install a linker script for the given ABI library" + ${ENABLE_LINKER_SCRIPT_DEFAULT_VALUE}) # Build libc++abi with libunwind. We need this option to determine whether to # link with libunwind or libgcc_s while running the test cases. option(LIBCXXABI_USE_LLVM_UNWINDER "Build and use the LLVM unwinder." OFF) +# Target options -------------------------------------------------------------- +option(LIBCXX_BUILD_32_BITS "Build 32 bit libc++." ${LLVM_BUILD_32_BITS}) +set(LIBCXX_SYSROOT "" CACHE STRING "Use alternate sysroot.") +set(LIBCXX_GCC_TOOLCHAIN "" CACHE STRING "Use alternate GCC toolchain.") + +# Feature options ------------------------------------------------------------- +option(LIBCXX_ENABLE_EXCEPTIONS "Use exceptions." ON) +option(LIBCXX_ENABLE_RTTI "Use run time type information." ON) +option(LIBCXX_ENABLE_GLOBAL_FILESYSTEM_NAMESPACE "Build libc++ with support for the global filesystem namespace." ON) +option(LIBCXX_ENABLE_STDIN "Build libc++ with support for stdin/std::cin." ON) +option(LIBCXX_ENABLE_STDOUT "Build libc++ with support for stdout/std::cout." ON) +option(LIBCXX_ENABLE_THREADS "Build libc++ with support for threads." ON) +option(LIBCXX_ENABLE_THREAD_UNSAFE_C_FUNCTIONS "Build libc++ with support for thread-unsafe C functions" ON) +option(LIBCXX_ENABLE_MONOTONIC_CLOCK + "Build libc++ with support for a monotonic clock. + This option may only be set to OFF when LIBCXX_ENABLE_THREADS=OFF." ON) +option(LIBCXX_HAS_MUSL_LIBC "Build libc++ with support for the Musl C library" OFF) + +# Misc options ---------------------------------------------------------------- +# FIXME: Turn -pedantic back ON. It is currently off because it warns +# about #include_next which is used everywhere. +option(LIBCXX_ENABLE_PEDANTIC "Compile with pedantic enabled." OFF) +option(LIBCXX_ENABLE_WERROR "Fail and stop if a warning is triggered." OFF) + +option(LIBCXX_GENERATE_COVERAGE "Enable generating code coverage." OFF) +set(LIBCXX_COVERAGE_LIBRARY "" CACHE STRING + "The Profile-rt library used to build with code coverage") + +# Don't allow a user to accidentally overwrite the system libc++ installation on Darwin. +# If the user specifies -DCMAKE_INSTALL_PREFIX=/usr the install rules for libc++ +# will not be generated and a warning will be issued. +option(LIBCXX_OVERRIDE_DARWIN_INSTALL "Enable overwriting darwins libc++ installation." OFF) +mark_as_advanced(LIBCXX_OVERRIDE_DARWIN_INSTALL) # Don't show this option by default. + +if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin" AND NOT LIBCXX_OVERRIDE_DARWIN_INSTALL) + if ("${CMAKE_INSTALL_PREFIX}" STREQUAL "/usr") + message(WARNING "Disabling libc++ install rules because installation would " + "overwrite the systems installation. Configure with " + "-DLIBCXX_OVERRIDE_DARWIN_INSTALL=ON to suppress this behaviour.") + mark_as_advanced(CLEAR LIBCXX_OVERRIDE_DARWIN_INSTALL) # Show the override option. + set(LIBCXX_INSTALL_HEADERS OFF) + set(LIBCXX_INSTALL_LIBRARY OFF) + endif() +endif() + +set(LIBCXX_CONFIGURE_IDE_DEFAULT OFF) +if (XCODE OR MSVC_IDE) + set(LIBCXX_CONFIGURE_IDE_DEFAULT ON) +endif() +option(LIBCXX_CONFIGURE_IDE "Configure libcxx for use within an IDE" + ${LIBCXX_CONFIGURE_IDE_DEFAULT}) + +#=============================================================================== +# Check option configurations +#=============================================================================== + +# Ensure LIBCXX_ENABLE_MONOTONIC_CLOCK is set to ON only when +# LIBCXX_ENABLE_THREADS is on. +if(LIBCXX_ENABLE_THREADS AND NOT LIBCXX_ENABLE_MONOTONIC_CLOCK) + message(FATAL_ERROR "LIBCXX_ENABLE_MONOTONIC_CLOCK can only be set to OFF" + " when LIBCXX_ENABLE_THREADS is also set to OFF.") +endif() + +# Ensure LLVM_USE_SANITIZER is not specified when LIBCXX_GENERATE_COVERAGE +# is ON. +if (LLVM_USE_SANITIZER AND LIBCXX_GENERATE_COVERAGE) + message(FATAL_ERROR "LLVM_USE_SANITIZER cannot be used with LIBCXX_GENERATE_COVERAGE") +endif() + +# Set LIBCXX_BUILD_32_BITS to (LIBCXX_BUILD_32_BITS OR LLVM_BUILD_32_BITS) +# and check that we can build with 32 bits if requested. +if (CMAKE_SIZEOF_VOID_P EQUAL 8 AND NOT WIN32) + if (LIBCXX_BUILD_32_BITS AND NOT LLVM_BUILD_32_BITS) # Don't duplicate the output from LLVM + message(STATUS "Building 32 bits executables and libraries.") + endif() +elseif(LIBCXX_BUILD_32_BITS) + message(FATAL_ERROR "LIBCXX_BUILD_32_BITS=ON is not supported on this platform.") +endif() + +# Check that this option is not enabled on Apple and emit a usage warning. +if (LIBCXX_ENABLE_STATIC_ABI_LIBRARY) + if (APPLE) + message(FATAL_ERROR "LIBCXX_ENABLE_STATIC_ABI_LIBRARY is not supported on OS X") + else() + message(WARNING "LIBCXX_ENABLE_STATIC_ABI_LIBRARY is an experimental option") + endif() +endif() + +if (LIBCXX_ENABLE_ABI_LINKER_SCRIPT) + if (APPLE) + message(FATAL_ERROR "LIBCXX_ENABLE_ABI_LINKER_SCRIPT cannot be used on APPLE targets") + endif() + if (NOT PYTHONINTERP_FOUND) + message(FATAL_ERROR "LIBCXX_ENABLE_ABI_LINKER_SCRIPT requires python but it was not found.") + endif() +endif() + +if (LIBCXX_ENABLE_STATIC_ABI_LIBRARY AND LIBCXX_ENABLE_ABI_LINKER_SCRIPT) + message(FATAL_ERROR "Conflicting options given. + LIBCXX_ENABLE_STATIC_ABI_LIBRARY cannot be specified with + LIBCXX_ENABLE_ABI_LINKER_SCRIPT") +endif() + +if (LIBCXX_HAS_MUSL_LIBC AND NOT LIBCXX_INSTALL_SUPPORT_HEADERS) + message(FATAL_ERROR "LIBCXX_INSTALL_SUPPORT_HEADERS can not be turned off" + "when building for Musl with LIBCXX_HAS_MUSL_LIBC.") +endif() + #=============================================================================== # Configure System #=============================================================================== @@ -114,232 +221,183 @@ set(LIBCXX_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}) set(LIBCXX_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}) set(LIBCXX_LIBRARY_DIR ${CMAKE_BINARY_DIR}/lib${LIBCXX_LIBDIR_SUFFIX}) +set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${LIBCXX_LIBRARY_DIR}) +set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${LIBCXX_LIBRARY_DIR}) + # Declare libc++ configuration variables. # They are intended for use as follows: # LIBCXX_CXX_FLAGS: General flags for both the compiler and linker. # LIBCXX_COMPILE_FLAGS: Compile only flags. # LIBCXX_LINK_FLAGS: Linker only flags. -set(LIBCXX_CXX_FLAGS "") set(LIBCXX_COMPILE_FLAGS "") set(LIBCXX_LINK_FLAGS "") +set(LIBCXX_LIBRARIES "") # Configure compiler. include(config-ix) -# Configure ABI library -include(HandleLibCXXABI) + # Configure coverage options. if (LIBCXX_GENERATE_COVERAGE) include(CodeCoverage) set(CMAKE_BUILD_TYPE "COVERAGE" CACHE STRING "" FORCE) endif() +string(TOUPPER "${CMAKE_BUILD_TYPE}" uppercase_CMAKE_BUILD_TYPE) + #=============================================================================== # Setup Compiler Flags #=============================================================================== -# Get required flags. -# On all systems the system c++ standard library headers need to be excluded. -if (MSVC) - # MSVC only has -X, which disables all default includes; including the crt. - # Thus, we do nothing and hope we don't accidentally include any of the C++ - # headers. -else() - if (LIBCXX_HAS_NOSTDINCXX_FLAG) - list(APPEND LIBCXX_COMPILE_FLAGS -nostdinc++) - string(REPLACE "-stdlib=libc++" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") - string(REPLACE "-stdlib=libstdc++" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") - endif() - # If c++1y has been enabled then attempt to use it. Fail if it is no supported - # by the compiler. Otherwise choose c++11 and ensure the compiler supports it. - if (LIBCXX_ENABLE_CXX1Y) - if (LIBCXX_HAS_STDCXX1Y_FLAG) - set(LIBCXX_STD_VERSION c++1y) - else() - message(FATAL_ERROR "c++1y was enabled but the compiler does not support it.") - endif() - else() - if (LIBCXX_HAS_STDCXX11_FLAG) - set(LIBCXX_STD_VERSION c++11) - else() - message(FATAL_ERROR "c++11 is required by libc++ but is not supported by the compiler") - endif() - endif() - # LIBCXX_STD_VERSION should always be set at this point. - list(APPEND LIBCXX_CXX_FLAGS "-std=${LIBCXX_STD_VERSION}") -endif() +include(HandleLibCXXABI) # Steup the ABI library flags -macro(append_if list condition var) - if (${condition}) - list(APPEND ${list} ${var}) - endif() -endmacro() +# Include macros for adding and removing libc++ flags. +include(HandleLibcxxFlags) -# Get warning flags -if (NOT MSVC) - append_if(LIBCXX_COMPILE_FLAGS LIBCXX_HAS_WALL_FLAG -Wall) - list(APPEND LIBCXX_COMPILE_FLAGS -Werror=return-type) +# Remove flags that may have snuck in. +remove_flags(-DNDEBUG -UNDEBUG -D_DEBUG + -stdlib=libc++ -stdlib=libstdc++ -lc++abi -m32) + +# FIXME(EricWF): See the FIXME on LIBCXX_ENABLE_PEDANTIC. +# Remove the -pedantic flag and -Wno-pedantic and -pedantic-errors +# so they don't get transformed into -Wno and -errors respectivly. +remove_flags(-Wno-pedantic -pedantic-errors -pedantic) + +# Required flags ============================================================== +add_compile_flags_if_supported(-std=c++11) +if (NOT MSVC AND NOT LIBCXX_SUPPORTS_STD_EQ_CXX11_FLAG) + message(FATAL_ERROR "C++11 is required but the compiler does not support -std=c++11") endif() -append_if(LIBCXX_COMPILE_FLAGS LIBCXX_HAS_W_FLAG -W) -append_if(LIBCXX_COMPILE_FLAGS LIBCXX_HAS_WNO_UNUSED_PARAMETER_FLAG -Wno-unused-parameter) -append_if(LIBCXX_COMPILE_FLAGS LIBCXX_HAS_WWRITE_STRINGS_FLAG -Wwrite-strings) -append_if(LIBCXX_COMPILE_FLAGS LIBCXX_HAS_WNO_LONG_LONG_FLAG -Wno-long-long) +# On all systems the system c++ standard library headers need to be excluded. +# MSVC only has -X, which disables all default includes; including the crt. +# Thus, we do nothing and hope we don't accidentally include any of the C++ +# headers +add_compile_flags_if_supported(-nostdinc++) + +# Target flags ================================================================ +add_flags_if(LIBCXX_BUILD_32_BITS -m32) +add_flags_if(LIBCXX_TARGET_TRIPLE "-target ${LIBCXX_TARGET_TRIPLE}") +add_flags_if(LIBCXX_SYSROOT "--sysroot ${LIBCXX_SYSROOT}") +add_flags_if(LIBCXX_GCC_TOOLCHAIN "-gcc-toolchain ${LIBCXX_GCC_TOOLCHAIN}") + +# Warning flags =============================================================== +add_definitions(-D_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +add_compile_flags_if_supported( + -Wall -W -Wwrite-strings + -Wno-unused-parameter -Wno-long-long + -Werror=return-type) if (LIBCXX_ENABLE_WERROR) - append_if(LIBCXX_COMPILE_FLAGS LIBCXX_HAS_WERROR_FLAG -Werror) - append_if(LIBCXX_COMPILE_FLAGS LIBCXX_HAS_WX_FLAG -WX) + add_compile_flags_if_supported(-Werror) + add_compile_flags_if_supported(-WX) else() - append_if(LIBCXX_COMPILE_FLAGS LIBCXX_HAS_WNO_ERROR_FLAG -Wno-error) - append_if(LIBCXX_COMPILE_FLAGS LIBCXX_HAS_NO_WX_FLAG -WX-) + # TODO(EricWF) Remove this. We shouldn't be suppressing errors when -Werror is + # added elsewhere. + add_compile_flags_if_supported(-Wno-error) endif() if (LIBCXX_ENABLE_PEDANTIC) - append_if(LIBCXX_COMPILE_FLAGS LIBCXX_HAS_PEDANTIC_FLAG -pedantic) + add_compile_flags_if_supported(-pedantic) endif() -# Get feature flags. -# Exceptions +# Exception flags ============================================================= if (LIBCXX_ENABLE_EXCEPTIONS) # Catches C++ exceptions only and tells the compiler to assume that extern C # functions never throw a C++ exception. - append_if(LIBCXX_CXX_FLAGS LIBCXX_HAS_EHSC_FLAG -EHsc) + add_compile_flags_if_supported(-EHsc) else() - list(APPEND LIBCXX_CXX_FLAGS -D_LIBCPP_NO_EXCEPTIONS) - append_if(LIBCXX_CXX_FLAGS LIBCXX_HAS_NO_EHS_FLAG -EHs-) - append_if(LIBCXX_CXX_FLAGS LIBCXX_HAS_NO_EHA_FLAG -EHa-) - append_if(LIBCXX_CXX_FLAGS LIBCXX_HAS_FNO_EXCEPTIONS_FLAG -fno-exceptions) + add_definitions(-D_LIBCPP_NO_EXCEPTIONS) + add_compile_flags_if_supported(-EHs- -EHa-) + add_compile_flags_if_supported(-fno-exceptions) endif() -# RTTI + +# RTTI flags ================================================================== if (NOT LIBCXX_ENABLE_RTTI) - list(APPEND LIBCXX_CXX_FLAGS -D_LIBCPP_NO_RTTI) - append_if(LIBCXX_CXX_FLAGS LIBCXX_HAS_NO_GR_FLAG -GR-) - append_if(LIBCXX_CXX_FLAGS LIBCXX_HAS_FNO_RTTI_FLAG -fno-rtti) + add_definitions(-D_LIBCPP_NO_RTTI) + add_compile_flags_if_supported(-GR-) + add_compile_flags_if_supported(-fno-rtti) endif() -# Assert -string(TOUPPER "${CMAKE_BUILD_TYPE}" uppercase_CMAKE_BUILD_TYPE) + +# Assertion flags ============================================================= +define_if(LIBCXX_ENABLE_ASSERTIONS -UNDEBUG) +define_if_not(LIBCXX_ENABLE_ASSERTIONS -DNDEBUG) if (LIBCXX_ENABLE_ASSERTIONS) # MSVC doesn't like _DEBUG on release builds. See PR 4379. - if (NOT MSVC) - list(APPEND LIBCXX_COMPILE_FLAGS -D_DEBUG) - endif() - # On Release builds cmake automatically defines NDEBUG, so we - # explicitly undefine it: - if (uppercase_CMAKE_BUILD_TYPE STREQUAL "RELEASE") - list(APPEND LIBCXX_COMPILE_FLAGS -UNDEBUG) - endif() -else() - if (NOT uppercase_CMAKE_BUILD_TYPE STREQUAL "RELEASE") - list(APPEND LIBCXX_COMPILE_FLAGS -DNDEBUG) - endif() -endif() -# Static library -if (NOT LIBCXX_ENABLE_SHARED) - list(APPEND LIBCXX_COMPILE_FLAGS -D_LIBCPP_BUILD_STATIC) + define_if_not(MSVC -D_DEBUG) endif() -if (CMAKE_SIZEOF_VOID_P EQUAL 8 AND NOT WIN32) - if (LIBCXX_BUILD_32_BITS) - message(STATUS "Building 32 bits executables and libraries.") - list(APPEND LIBCXX_CXX_FLAGS "-m32") - endif() -elseif(LIBCXX_BUILD_32_BITS) - message(FATAL_ERROR "LIBCXX_BUILD_32_BITS=ON is not supported on this platform.") -endif() -# This is the _ONLY_ place where add_definitions is called. -if (MSVC) - add_definitions(-D_CRT_SECURE_NO_WARNINGS) -endif() - -# LIBCXX_ENABLE_GLOBAL_FILESYSTEM_NAMESPACE configuration -if (NOT LIBCXX_ENABLE_GLOBAL_FILESYSTEM_NAMESPACE) - add_definitions(-D_LIBCPP_HAS_NO_GLOBAL_FILESYSTEM_NAMESPACE) -endif() - -# LIBCXX_ENABLE_STDIN configuration -if (NOT LIBCXX_ENABLE_STDIN) - add_definitions(-D_LIBCPP_HAS_NO_STDIN) -endif() +# Feature flags =============================================================== +define_if(MSVC -D_CRT_SECURE_NO_WARNINGS) -# LIBCXX_ENABLE_STDOUT configuration -if (NOT LIBCXX_ENABLE_STDOUT) - add_definitions(-D_LIBCPP_HAS_NO_STDOUT) -endif() - -# LIBCXX_ENABLE_THREADS configuration -if (NOT LIBCXX_ENABLE_THREADS) - add_definitions(-D_LIBCPP_HAS_NO_THREADS) - if (NOT LIBCXX_ENABLE_MONOTONIC_CLOCK) - add_definitions(-D_LIBCPP_HAS_NO_MONOTONIC_CLOCK) - endif() -# Ensure LIBCXX_ENABLE_MONOTONIC_CLOCK is set to ON. -elseif(NOT LIBCXX_ENABLE_MONOTONIC_CLOCK) - message(FATAL_ERROR "LIBCXX_ENABLE_MONOTONIC_CLOCK can only be set to OFF" - " when LIBCXX_ENABLE_THREADS is also set to OFF.") -endif() - -# LIBCXX_ENABLE_THREAD_UNSAFE_C_FUNCTIONS configuration -if (NOT LIBCXX_ENABLE_THREAD_UNSAFE_C_FUNCTIONS) - add_definitions(-D_LIBCPP_HAS_NO_THREAD_UNSAFE_C_FUNCTIONS) -endif() +# Sanitizer flags ============================================================= # Configure for sanitizers. If LIBCXX_BUILT_STANDALONE then we have to do # the flag translation ourselves. Othewise LLVM's CMakeList.txt will handle it. if (LIBCXX_BUILT_STANDALONE) + set(LLVM_USE_SANITIZER "" CACHE STRING + "Define the sanitizer used to build the library and tests") # NOTE: LLVM_USE_SANITIZER checks for a UNIX like system instead of MSVC. # But we don't have LLVM_ON_UNIX so checking for MSVC is the best we can do. if (LLVM_USE_SANITIZER AND NOT MSVC) - append_if(LIBCXX_CXX_FLAGS LIBCXX_HAS_FNO_OMIT_FRAME_POINTER_FLAG - "-fno-omit-frame-pointer") + add_flags_if_supported("-fno-omit-frame-pointer") + add_flags_if_supported("-gline-tables-only") + if (NOT uppercase_CMAKE_BUILD_TYPE STREQUAL "DEBUG" AND NOT uppercase_CMAKE_BUILD_TYPE STREQUAL "RELWITHDEBINFO") - append_if(LIBCXX_CXX_FLAGS LIBCXX_HAS_GLINE_TABLES_ONLY_FLAG - "-gline-tables-only") + add_flags_if_supported("-gline-tables-only") endif() if (LLVM_USE_SANITIZER STREQUAL "Address") - list(APPEND LIBCXX_CXX_FLAGS "-fsanitize=address") + add_flags("-fsanitize=address") elseif (LLVM_USE_SANITIZER MATCHES "Memory(WithOrigins)?") - list(APPEND LIBCXX_CXX_FLAGS "-fsanitize=memory") + add_flags(-fsanitize=memory) if (LLVM_USE_SANITIZER STREQUAL "MemoryWithOrigins") - list(APPEND LIBCXX_CXX_FLAGS "-fsanitize-memory-track-origins") + add_flags("-fsanitize-memory-track-origins") endif() elseif (LLVM_USE_SANITIZER STREQUAL "Undefined") - list(APPEND LIBCXX_CXX_FLAGS - "-fsanitize=undefined -fno-sanitize=vptr,function -fno-sanitize-recover") + add_flags("-fsanitize=undefined -fno-sanitize=vptr,function -fno-sanitize-recover=all") elseif (LLVM_USE_SANITIZER STREQUAL "Thread") - list(APPEND LIBCXX_CXX_FLAGS "-fsanitize=thread") + add_flags(-fsanitize=thread) else() message(WARNING "Unsupported value of LLVM_USE_SANITIZER: ${LLVM_USE_SANITIZER}") endif() - elseif(MSVC) - message(WARNING "LLVM_USE_SANITIZER is not supported with MSVC") + elseif(LLVM_USE_SANITIZER AND MSVC) + message(WARNING "LLVM_USE_SANITIZER is not supported on this platform.") endif() endif() -append_if(LIBCXX_CXX_FLAGS LIBCXX_TARGET_TRIPLE - "-target ${LIBCXX_TARGET_TRIPLE}") - -append_if(LIBCXX_CXX_FLAGS LIBCXX_SYSROOT "--sysroot ${LIBCXX_SYSROOT}") -append_if(LIBCXX_CXX_FLAGS LIBCXX_GCC_TOOLCHAIN - "-gcc-toolchain ${LIBCXX_GCC_TOOLCHAIN}") - -if (LLVM_USE_SANITIZER AND LIBCXX_GENERATE_COVERAGE) - message(FATAL_ERROR "LLVM_USE_SANITIZER cannot be used with LIBCXX_GENERATE_COVERAGE") +# Configuration file flags ===================================================== +if (NOT LIBCXX_ABI_VERSION EQUAL "1") + config_define(${LIBCXX_ABI_VERSION} _LIBCPP_ABI_VERSION) +endif() +config_define_if(LIBCXX_ABI_UNSTABLE _LIBCPP_ABI_UNSTABLE) + +config_define_if_not(LIBCXX_ENABLE_GLOBAL_FILESYSTEM_NAMESPACE _LIBCPP_HAS_NO_GLOBAL_FILESYSTEM_NAMESPACE) +config_define_if_not(LIBCXX_ENABLE_STDIN _LIBCPP_HAS_NO_STDIN) +config_define_if_not(LIBCXX_ENABLE_STDOUT _LIBCPP_HAS_NO_STDOUT) +config_define_if_not(LIBCXX_ENABLE_THREADS _LIBCPP_HAS_NO_THREADS) +config_define_if_not(LIBCXX_ENABLE_MONOTONIC_CLOCK _LIBCPP_HAS_NO_MONOTONIC_CLOCK) +config_define_if_not(LIBCXX_ENABLE_THREAD_UNSAFE_C_FUNCTIONS _LIBCPP_HAS_NO_THREAD_UNSAFE_C_FUNCTIONS) + +config_define_if(LIBCXX_HAS_MUSL_LIBC _LIBCPP_HAS_MUSL_LIBC) + +if (LIBCXX_NEEDS_SITE_CONFIG) + configure_file( + include/__config_site.in + ${LIBCXX_BINARY_DIR}/__config_site + @ONLY) + # Provide the config definitions by included the generated __config_site + # file at compile time. + add_compile_flags("-include ${LIBCXX_BINARY_DIR}/__config_site") endif() - -string(REPLACE ";" " " LIBCXX_CXX_FLAGS "${LIBCXX_CXX_FLAGS}") -set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${LIBCXX_CXX_FLAGS}") #=============================================================================== -# Setup Source Code +# Setup Source Code And Tests #=============================================================================== - include_directories(include) add_subdirectory(include) - -# Add source code. This also contains all of the logic for deciding linker flags -# soname, etc... add_subdirectory(lib) -#=============================================================================== -# Setup Tests -#=============================================================================== - -add_subdirectory(test) +if (LIBCXX_INCLUDE_TESTS) + add_subdirectory(test) +endif() +if (LIBCXX_INCLUDE_DOCS) + add_subdirectory(docs) +endif() @@ -1,5 +1,15 @@ This is meant to be a general place to list things that should be done "someday" +3.8 Release Goals +================= +* LFTS v1 (EricWF, MClow) +* Filesystem TS (EricWF) +* ASIO TS (MClow) +* <regex> Improvements (MClow) +* Setup ABI Versioning policy (EricWF) +* Fix PR19302 - Fix UB in list and __tree. + + ABI Related Tasks ================= * Explicitly manage and verify symbols exported from the dylib. @@ -21,18 +31,18 @@ CXX Runtime Library Tasks Atomic Related Tasks ==================== -* Support <atomic> in C++03 (needed for internal use). +* Enable mixing of clang and GCC atomics internally. Currently some + parts of libc++ use atomics only when clang provides them. + (see memory@5380 for an example) * Audit use of libatomic builtins in <atomic> with GCC. * future should use <atomic> for synchronization. -* call_once should use <atomic> for synchronization. -* Audit shared_ptr use of <atomic> Test Suite Tasks ================ -* Get test suite passing in C++03. * Move all libc++ specific tests from test/std into test/libcxx. * Improve how LIT handles compiler warnings. * Improve the quality and portability of the locale test data. +* Convert failure tests to use Clang Verify. Misc Tasks ========== @@ -42,8 +52,5 @@ Misc Tasks * Look at basic_string's move assignment operator, re LWG 2063 and POCMA * libc++ is missing try_emplace * Put a static_assert in std::allocator to deny const/volatile types (LWG 2447) -* Investigate the effect of using __decltype instead of __typeof__ to provide - decltype in C++03. What code could be broken by this change? -* Convert failure tests to use Clang Verify. * Document support (or lack of) for C++11 libraries in C++03. * Document supported compilers. diff --git a/cmake/Modules/HandleLibCXXABI.cmake b/cmake/Modules/HandleLibCXXABI.cmake index 73723e3559b1..d9c652d87bad 100644 --- a/cmake/Modules/HandleLibCXXABI.cmake +++ b/cmake/Modules/HandleLibCXXABI.cmake @@ -41,10 +41,13 @@ macro(setup_abi_lib abidefines abilib abifiles abidirs) file(COPY "${incpath}/${fpath}" DESTINATION "${CMAKE_BINARY_DIR}/include/${dstdir}" ) - install(FILES "${CMAKE_BINARY_DIR}/include/${fpath}" - DESTINATION include/c++/v1/${dstdir} - PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ - ) + if (LIBCXX_INSTALL_HEADERS) + install(FILES "${CMAKE_BINARY_DIR}/include/${fpath}" + DESTINATION include/c++/v1/${dstdir} + COMPONENT libcxx + PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ + ) + endif() list(APPEND abilib_headers "${CMAKE_BINARY_DIR}/include/${fpath}") endif() endforeach() @@ -58,6 +61,8 @@ macro(setup_abi_lib abidefines abilib abifiles abidirs) endmacro() + +# Configure based on the selected ABI library. if ("${LIBCXX_CXX_ABI_LIBNAME}" STREQUAL "libstdc++" OR "${LIBCXX_CXX_ABI_LIBNAME}" STREQUAL "libsupc++") set(_LIBSUPCXX_INCLUDE_FILES diff --git a/cmake/Modules/HandleLibcxxFlags.cmake b/cmake/Modules/HandleLibcxxFlags.cmake new file mode 100644 index 000000000000..bb886fa8a01f --- /dev/null +++ b/cmake/Modules/HandleLibcxxFlags.cmake @@ -0,0 +1,169 @@ +# HandleLibcxxFlags - A set of macros used to setup the flags used to compile +# and link libc++. These macros add flags to the following CMake variables. +# - LIBCXX_COMPILE_FLAGS: flags used to compile libc++ +# - LIBCXX_LINK_FLAGS: flags used to link libc++ +# - LIBCXX_LIBRARIES: libraries to link libc++ to. + +include(CheckCXXCompilerFlag) + +unset(add_flag_if_supported) + +# Mangle the name of a compiler flag into a valid CMake identifier. +# Ex: --std=c++11 -> STD_EQ_CXX11 +macro(mangle_name str output) + string(STRIP "${str}" strippedStr) + string(REGEX REPLACE "^/" "" strippedStr "${strippedStr}") + string(REGEX REPLACE "^-+" "" strippedStr "${strippedStr}") + string(REGEX REPLACE "-+$" "" strippedStr "${strippedStr}") + string(REPLACE "-" "_" strippedStr "${strippedStr}") + string(REPLACE "=" "_EQ_" strippedStr "${strippedStr}") + string(REPLACE "+" "X" strippedStr "${strippedStr}") + string(TOUPPER "${strippedStr}" ${output}) +endmacro() + +# Remove a list of flags from all CMake variables that affect compile flags. +# This can be used to remove unwanted flags specified on the command line +# or added in other parts of LLVM's cmake configuration. +macro(remove_flags) + foreach(var ${ARGN}) + string(REPLACE "${var}" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") + string(REPLACE "${var}" "" CMAKE_C_FLAGS "${CMAKE_C_FLAGS}") + string(REPLACE "${var}" "" CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS}") + string(REPLACE "${var}" "" CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS}") + string(REPLACE "${var}" "" CMAKE_SHARED_MODULE_FLAGS "${CMAKE_SHARED_MODULE_FLAGS}") + remove_definitions(${var}) + endforeach() +endmacro(remove_flags) + +# Add a macro definition if condition is true. +macro(define_if condition def) + if (${condition}) + add_definitions(${def}) + endif() +endmacro() + +# Add a macro definition if condition is not true. +macro(define_if_not condition def) + if (NOT ${condition}) + add_definitions(${def}) + endif() +endmacro() + +# Add a macro definition to the __config_site file if the specified condition +# is 'true'. Note that '-D${def}' is not added. Instead it is expected that +# the build include the '__config_site' header. +macro(config_define_if condition def) + if (${condition}) + set(${def} ON) + set(LIBCXX_NEEDS_SITE_CONFIG ON) + endif() +endmacro() + +macro(config_define_if_not condition def) + if (NOT ${condition}) + set(${def} ON) + set(LIBCXX_NEEDS_SITE_CONFIG ON) + endif() +endmacro() + +macro(config_define value def) + set(${def} ${value}) + set(LIBCXX_NEEDS_SITE_CONFIG ON) +endmacro() + +# Add a specified list of flags to both 'LIBCXX_COMPILE_FLAGS' and +# 'LIBCXX_LINK_FLAGS'. +macro(add_flags) + foreach(value ${ARGN}) + list(APPEND LIBCXX_COMPILE_FLAGS ${value}) + list(APPEND LIBCXX_LINK_FLAGS ${value}) + endforeach() +endmacro() + +# If the specified 'condition' is true then add a list of flags to both +# 'LIBCXX_COMPILE_FLAGS' and 'LIBCXX_LINK_FLAGS'. +macro(add_flags_if condition) + if (${condition}) + add_flags(${ARGN}) + endif() +endmacro() + +# Add each flag in the list to LIBCXX_COMPILE_FLAGS and LIBCXX_LINK_FLAGS +# if that flag is supported by the current compiler. +macro(add_flags_if_supported) + foreach(flag ${ARGN}) + mangle_name("${flag}" flagname) + check_cxx_compiler_flag("${flag}" "LIBCXX_SUPPORTS_${flagname}_FLAG") + add_flags_if(LIBCXX_SUPPORTS_${flagname}_FLAG ${flag}) + endforeach() +endmacro() + +# Add a list of flags to 'LIBCXX_COMPILE_FLAGS'. +macro(add_compile_flags) + foreach(f ${ARGN}) + list(APPEND LIBCXX_COMPILE_FLAGS ${f}) + endforeach() +endmacro() + +# If 'condition' is true then add the specified list of flags to +# 'LIBCXX_COMPILE_FLAGS' +macro(add_compile_flags_if condition) + if (${condition}) + add_compile_flags(${ARGN}) + endif() +endmacro() + +# For each specified flag, add that flag to 'LIBCXX_COMPILE_FLAGS' if the +# flag is supported by the C++ compiler. +macro(add_compile_flags_if_supported) + foreach(flag ${ARGN}) + mangle_name("${flag}" flagname) + check_cxx_compiler_flag("${flag}" "LIBCXX_SUPPORTS_${flagname}_FLAG") + add_compile_flags_if(LIBCXX_SUPPORTS_${flagname}_FLAG ${flag}) + endforeach() +endmacro() + +# Add a list of flags to 'LIBCXX_LINK_FLAGS'. +macro(add_link_flags) + foreach(f ${ARGN}) + list(APPEND LIBCXX_LINK_FLAGS ${f}) + endforeach() +endmacro() + +# If 'condition' is true then add the specified list of flags to +# 'LIBCXX_LINK_FLAGS' +macro(add_link_flags_if condition) + if (${condition}) + add_link_flags(${ARGN}) + endif() +endmacro() + +# For each specified flag, add that flag to 'LIBCXX_LINK_FLAGS' if the +# flag is supported by the C++ compiler. +macro(add_link_flags_if_supported) + foreach(flag ${ARGN}) + mangle_name("${flag}" flagname) + check_cxx_compiler_flag("${flag}" "LIBCXX_SUPPORTS_${flagname}_FLAG") + add_link_flags_if(LIBCXX_SUPPORTS_${flagname}_FLAG ${flag}) + endforeach() +endmacro() + +# Add a list of libraries or link flags to 'LIBCXX_LIBRARIES'. +macro(add_library_flags) + foreach(lib ${ARGN}) + list(APPEND LIBCXX_LIBRARIES ${lib}) + endforeach() +endmacro() + +# if 'condition' is true then add the specified list of libraries and flags +# to 'LIBCXX_LIBRARIES'. +macro(add_library_flags_if condition) + if(${condition}) + add_library_flags(${ARGN}) + endif() +endmacro() + +# Turn a comma separated CMake list into a space separated string. +macro(split_list listname) + string(REPLACE ";" " " ${listname} "${${listname}}") +endmacro() diff --git a/cmake/Modules/HandleOutOfTreeLLVM.cmake b/cmake/Modules/HandleOutOfTreeLLVM.cmake new file mode 100644 index 000000000000..6215be7f586a --- /dev/null +++ b/cmake/Modules/HandleOutOfTreeLLVM.cmake @@ -0,0 +1,138 @@ +macro(find_llvm_parts) +# Rely on llvm-config. + set(CONFIG_OUTPUT) + find_program(LLVM_CONFIG "llvm-config") + if(DEFINED LLVM_PATH) + set(LLVM_INCLUDE_DIR ${LLVM_INCLUDE_DIR} CACHE PATH "Path to llvm/include") + set(LLVM_PATH ${LLVM_PATH} CACHE PATH "Path to LLVM source tree") + set(LLVM_MAIN_SRC_DIR ${LLVM_PATH}) + set(LLVM_CMAKE_PATH "${LLVM_PATH}/cmake/modules") + elseif(LLVM_CONFIG) + message(STATUS "Found LLVM_CONFIG as ${LLVM_CONFIG}") + set(CONFIG_COMMAND ${LLVM_CONFIG} + "--includedir" + "--prefix" + "--src-root") + execute_process( + COMMAND ${CONFIG_COMMAND} + RESULT_VARIABLE HAD_ERROR + OUTPUT_VARIABLE CONFIG_OUTPUT + ) + if(NOT HAD_ERROR) + string(REGEX REPLACE + "[ \t]*[\r\n]+[ \t]*" ";" + CONFIG_OUTPUT ${CONFIG_OUTPUT}) + else() + string(REPLACE ";" " " CONFIG_COMMAND_STR "${CONFIG_COMMAND}") + message(STATUS "${CONFIG_COMMAND_STR}") + message(FATAL_ERROR "llvm-config failed with status ${HAD_ERROR}") + endif() + + list(GET CONFIG_OUTPUT 0 INCLUDE_DIR) + list(GET CONFIG_OUTPUT 1 LLVM_OBJ_ROOT) + list(GET CONFIG_OUTPUT 2 MAIN_SRC_DIR) + + set(LLVM_INCLUDE_DIR ${INCLUDE_DIR} CACHE PATH "Path to llvm/include") + set(LLVM_BINARY_DIR ${LLVM_OBJ_ROOT} CACHE PATH "Path to LLVM build tree") + set(LLVM_MAIN_SRC_DIR ${MAIN_SRC_DIR} CACHE PATH "Path to LLVM source tree") + set(LLVM_CMAKE_PATH "${LLVM_BINARY_DIR}/share/llvm/cmake") + else() + set(LLVM_FOUND OFF) + return() + endif() + + if (NOT EXISTS ${LLVM_MAIN_SRC_DIR}) + set(LLVM_FOUND OFF) + message(WARNING "Not found: ${LLVM_MAIN_SRC_DIR}") + return() + endif() + + if(NOT EXISTS ${LLVM_CMAKE_PATH}) + set(LLVM_FOUND OFF) + message(WARNING "Not found: ${LLVM_CMAKE_PATH}") + return() + endif() + + list(APPEND CMAKE_MODULE_PATH "${LLVM_CMAKE_PATH}") + list(APPEND CMAKE_MODULE_PATH "${LLVM_MAIN_SRC_DIR}/cmake/modules") + + set(LLVM_FOUND ON) +endmacro(find_llvm_parts) + + +if (CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR) + set(LIBCXX_BUILT_STANDALONE 1) + message(STATUS "Configuring for standalone build.") + + find_llvm_parts() + + # LLVM Options -------------------------------------------------------------- + include(FindPythonInterp) + if( NOT PYTHONINTERP_FOUND ) + message(WARNING "Failed to find python interpreter. " + "The libc++ test suite will be disabled.") + set(LLVM_INCLUDE_TESTS OFF) + endif() + + if (NOT DEFINED LLVM_INCLUDE_TESTS) + set(LLVM_INCLUDE_TESTS ${LLVM_FOUND}) + endif() + if (NOT DEFINED LLVM_INCLUDE_DOCS) + set(LLVM_INCLUDE_DOCS ${LLVM_FOUND}) + endif() + if (NOT DEFINED LLVM_ENABLE_SPHINX) + set(LLVM_ENABLE_SPHINX OFF) + endif() + + # Required LIT Configuration ------------------------------------------------ + # Define the default arguments to use with 'lit', and an option for the user + # to override. + set(LIT_ARGS_DEFAULT "-sv --show-xfail --show-unsupported") + if (MSVC OR XCODE) + set(LIT_ARGS_DEFAULT "${LIT_ARGS_DEFAULT} --no-progress-bar") + endif() + set(LLVM_LIT_ARGS "${LIT_ARGS_DEFAULT}" CACHE STRING "Default options for lit") + + # Make sure we can use the console pool for recent cmake and ninja > 1.5 + # Needed for add_lit_testsuite + if(CMAKE_VERSION VERSION_LESS 3.1.20141117) + set(cmake_3_2_USES_TERMINAL) + else() + set(cmake_3_2_USES_TERMINAL USES_TERMINAL) + endif() + + # Required doc configuration + if (LLVM_ENABLE_SPHINX) + message(STATUS "Sphinx enabled.") + find_package(Sphinx REQUIRED) + else() + message(STATUS "Sphinx disabled.") + endif() + + # FIXME - This is cribbed from HandleLLVMOptions.cmake. + if(WIN32) + set(LLVM_HAVE_LINK_VERSION_SCRIPT 0) + if(CYGWIN) + set(LLVM_ON_WIN32 0) + set(LLVM_ON_UNIX 1) + else(CYGWIN) + set(LLVM_ON_WIN32 1) + set(LLVM_ON_UNIX 0) + endif(CYGWIN) + else(WIN32) + if(UNIX) + set(LLVM_ON_WIN32 0) + set(LLVM_ON_UNIX 1) + if(APPLE) + set(LLVM_HAVE_LINK_VERSION_SCRIPT 0) + else(APPLE) + set(LLVM_HAVE_LINK_VERSION_SCRIPT 1) + endif(APPLE) + else(UNIX) + MESSAGE(SEND_ERROR "Unable to determine platform") + endif(UNIX) + endif(WIN32) + + # Add LLVM Functions -------------------------------------------------------- + include(AddLLVM OPTIONAL) +endif() diff --git a/cmake/config-ix.cmake b/cmake/config-ix.cmake index 428d737c749d..c05597ea73dd 100644 --- a/cmake/config-ix.cmake +++ b/cmake/config-ix.cmake @@ -2,23 +2,7 @@ include(CheckLibraryExists) include(CheckCXXCompilerFlag) # Check compiler flags -check_cxx_compiler_flag(-std=c++11 LIBCXX_HAS_STDCXX11_FLAG) -check_cxx_compiler_flag(-std=c++1y LIBCXX_HAS_STDCXX1Y_FLAG) -check_cxx_compiler_flag(-fPIC LIBCXX_HAS_FPIC_FLAG) -check_cxx_compiler_flag(-fno-omit-frame-pointer LIBCXX_HAS_FNO_OMIT_FRAME_POINTER_FLAG) -check_cxx_compiler_flag(-nodefaultlibs LIBCXX_HAS_NODEFAULTLIBS_FLAG) -check_cxx_compiler_flag(-nostdinc++ LIBCXX_HAS_NOSTDINCXX_FLAG) -check_cxx_compiler_flag(-Wall LIBCXX_HAS_WALL_FLAG) -check_cxx_compiler_flag(-W LIBCXX_HAS_W_FLAG) -check_cxx_compiler_flag(-Wno-unused-parameter LIBCXX_HAS_WNO_UNUSED_PARAMETER_FLAG) -check_cxx_compiler_flag(-Wwrite-strings LIBCXX_HAS_WWRITE_STRINGS_FLAG) -check_cxx_compiler_flag(-Wno-long-long LIBCXX_HAS_WNO_LONG_LONG_FLAG) -check_cxx_compiler_flag(-pedantic LIBCXX_HAS_PEDANTIC_FLAG) -check_cxx_compiler_flag(-Werror LIBCXX_HAS_WERROR_FLAG) -check_cxx_compiler_flag(-Wno-error LIBCXX_HAS_WNO_ERROR_FLAG) -check_cxx_compiler_flag(-fno-exceptions LIBCXX_HAS_FNO_EXCEPTIONS_FLAG) -check_cxx_compiler_flag(-fno-rtti LIBCXX_HAS_FNO_RTTI_FLAG) -check_cxx_compiler_flag(-gline-tables-only LIBCXX_HAS_GLINE_TABLES_ONLY_FLAG) + check_cxx_compiler_flag(/WX LIBCXX_HAS_WX_FLAG) check_cxx_compiler_flag(/WX- LIBCXX_HAS_NO_WX_FLAG) check_cxx_compiler_flag(/EHsc LIBCXX_HAS_EHSC_FLAG) @@ -26,10 +10,10 @@ check_cxx_compiler_flag(/EHs- LIBCXX_HAS_NO_EHS_FLAG) check_cxx_compiler_flag(/EHa- LIBCXX_HAS_NO_EHA_FLAG) check_cxx_compiler_flag(/GR- LIBCXX_HAS_NO_GR_FLAG) + # Check libraries check_library_exists(pthread pthread_create "" LIBCXX_HAS_PTHREAD_LIB) -check_library_exists(c printf "" LIBCXX_HAS_C_LIB) +check_library_exists(c fopen "" LIBCXX_HAS_C_LIB) check_library_exists(m ccos "" LIBCXX_HAS_M_LIB) check_library_exists(rt clock_gettime "" LIBCXX_HAS_RT_LIB) check_library_exists(gcc_s __gcc_personality_v0 "" LIBCXX_HAS_GCC_S_LIB) - diff --git a/docs/BuildingLibcxx.rst b/docs/BuildingLibcxx.rst new file mode 100644 index 000000000000..f00ce4f9cff1 --- /dev/null +++ b/docs/BuildingLibcxx.rst @@ -0,0 +1,306 @@ + +=============== +Building libc++ +=============== + +.. contents:: + :local: + +Getting Started +=============== + +On Mac OS 10.7 (Lion) and later, the easiest way to get this library is to install +Xcode 4.2 or later. However if you want to install tip-of-trunk from here +(getting the bleeding edge), read on. + +The basic steps needed to build libc++ are: + +#. Checkout LLVM: + + * ``cd where-you-want-llvm-to-live`` + * ``svn co http://llvm.org/svn/llvm-project/llvm/trunk llvm`` + +#. Checkout libc++: + + * ``cd where-you-want-llvm-to-live`` + * ``cd llvm/projects`` + * ``svn co http://llvm.org/svn/llvm-project/libcxx/trunk libcxx`` + +#. Checkout libc++abi: + + * ``cd where-you-want-llvm-to-live`` + * ``cd llvm/projects`` + * ``svn co http://llvm.org/svn/llvm-project/libcxxabi/trunk libcxxabi`` + +#. Configure and build libc++ with libc++abi: + + CMake is the only supported configuration system. Unlike other LLVM + projects autotools is not supported for either libc++ or libc++abi. + + Clang is the preferred compiler when building and using libc++. + + * ``cd where you want to build llvm`` + * ``mkdir build`` + * ``cd build`` + * ``cmake -G <generator> [options] <path to llvm sources>`` + + For more information about configuring libc++ see :ref:`CMake Options`. + + * ``make cxx`` --- will build libc++ and libc++abi. + * ``make check-libcxx check-libcxxabi`` --- will run the test suites. + + Shared libraries for libc++ and libc++ abi should now be present in llvm/build/lib. + See :ref:`using an alternate libc++ installation <alternate libcxx>` + +#. **Optional**: Install libc++ and libc++abi + + If your system already provides a libc++ installation it is important to be + careful not to replace it. Remember Use the CMake option ``CMAKE_INSTALL_PREFIX`` to + select a safe place to install libc++. + + * ``make install-libcxx install-libcxxabi`` --- Will install the libraries and the headers + + .. warning:: + * Replacing your systems libc++ installation could render the system non-functional. + * Mac OS X will not boot without a valid copy of ``libc++.1.dylib`` in ``/usr/lib``. + + +The instructions are for building libc++ on +FreeBSD, Linux, or Mac using `libc++abi`_ as the C++ ABI library. +On Linux, it is also possible to use :ref:`libsupc++ <libsupcxx>` or libcxxrt. + +It is sometimes beneficial to build outside of the LLVM tree. An out-of-tree +build would look like this: + +.. code-block:: bash + + $ cd where-you-want-libcxx-to-live + $ # Check out llvm, libc++ and libc++abi. + $ ``svn co http://llvm.org/svn/llvm-project/llvm/trunk llvm`` + $ ``svn co http://llvm.org/svn/llvm-project/libcxx/trunk libcxx`` + $ ``svn co http://llvm.org/svn/llvm-project/libcxxabi/trunk libcxxabi`` + $ cd where-you-want-to-build + $ mkdir build && cd build + $ export CC=clang CXX=clang++ + $ cmake -DLLVM_PATH=path/to/llvm \ + -DLIBCXX_CXX_ABI=libcxxabi \ + -DLIBCXX_CXX_ABI_INCLUDE_PATHS=path/to/libcxxabi/include \ + path/to/libcxx + $ make + $ make check-libcxx # optional + + +.. _`libc++abi`: http://libcxxabi.llvm.org/ + + +.. _CMake Options: + +CMake Options +============= + +Here are some of the CMake variables that are used often, along with a +brief explanation and LLVM-specific notes. For full documentation, check the +CMake docs or execute ``cmake --help-variable VARIABLE_NAME``. + +**CMAKE_BUILD_TYPE**:STRING + Sets the build type for ``make`` based generators. Possible values are + Release, Debug, RelWithDebInfo and MinSizeRel. On systems like Visual Studio + the user sets the build type with the IDE settings. + +**CMAKE_INSTALL_PREFIX**:PATH + Path where LLVM will be installed if "make install" is invoked or the + "INSTALL" target is built. + +**CMAKE_CXX_COMPILER**:STRING + The C++ compiler to use when building and testing libc++. + + +.. _libcxx-specific options: + +libc++ specific options +----------------------- + +.. option:: LIBCXX_ENABLE_ASSERTIONS:BOOL + + **Default**: ``ON`` + + Build libc++ with assertions enabled. + +.. option:: LIBCXX_BUILD_32_BITS:BOOL + + **Default**: ``OFF`` + + Build libc++ as a 32 bit library. Also see :option:`LLVM_BUILD_32_BITS`. + +.. option:: LIBCXX_ENABLE_SHARED:BOOL + + **Default**: ``ON`` + + Build libc++ as a shared library. If ``OFF`` is specified then libc++ is + built as a static library. + +.. option:: LIBCXX_LIBDIR_SUFFIX:STRING + + Extra suffix to append to the directory where libraries are to be installed. + This option overrides :option:`LLVM_LIBDIR_SUFFIX`. + +.. _ABI Library Specific Options: + +ABI Library Specific Options +---------------------------- + +.. option:: LIBCXX_CXX_ABI:STRING + + **Values**: ``none``, ``libcxxabi``, ``libcxxrt``, ``libstdc++``, ``libsupc++``. + + Select the ABI library to build libc++ against. + +.. option:: LIBCXX_CXX_ABI_INCLUDE_PATHS:PATHS + + Provide additional search paths for the ABI library headers. + +.. option:: LIBCXX_CXX_ABI_LIBRARY_PATH:PATH + + Provide the path to the ABI library that libc++ should link against. + +.. option:: LIBCXX_ENABLE_STATIC_ABI_LIBRARY:BOOL + + **Default**: ``OFF`` + + If this option is enabled, libc++ will try and link the selected ABI library + statically. + +.. option:: LIBCXX_ENABLE_ABI_LINKER_SCRIPT:BOOL + + **Default**: ``ON`` by default on UNIX platforms other than Apple unless + 'LIBCXX_ENABLE_STATIC_ABI_LIBRARY' is ON. Otherwise the default value is ``OFF``. + + This option generate and installs a linker script as ``libc++.so`` which + links the correct ABI library. + +.. option:: LIBCXXABI_USE_LLVM_UNWINDER:BOOL + + **Default**: ``OFF`` + + Build and use the LLVM unwinder. Note: This option can only be used when + libc++abi is the C++ ABI library used. + + +libc++ Feature options +---------------------- + +.. option:: LIBCXX_ENABLE_EXCEPTIONS:BOOL + + **Default**: ``ON`` + + Build libc++ with exception support. + +.. option:: LIBCXX_ENABLE_RTTI:BOOL + + **Default**: ``ON`` + + Build libc++ with run time type information. + + +libc++ Feature options +---------------------- + +The following options allow building libc++ for a different ABI version. + +.. option:: LIBCXX_ABI_VERSION:STRING + + **Default**: ``1`` + + Defines the target ABI version of libc++. + +.. option:: LIBCXX_ABI_UNSTABLE:BOOL + + **Default**: ``OFF`` + + Build the "unstable" ABI version of libc++. Includes all ABI changing features + on top of the current stable version. + +.. _LLVM-specific variables: + +LLVM-specific options +--------------------- + +.. option:: LLVM_LIBDIR_SUFFIX:STRING + + Extra suffix to append to the directory where libraries are to be + installed. On a 64-bit architecture, one could use ``-DLLVM_LIBDIR_SUFFIX=64`` + to install libraries to ``/usr/lib64``. + +.. option:: LLVM_BUILD_32_BITS:BOOL + + Build 32-bits executables and libraries on 64-bits systems. This option is + available only on some 64-bits unix systems. Defaults to OFF. + +.. option:: LLVM_LIT_ARGS:STRING + + Arguments given to lit. ``make check`` and ``make clang-test`` are affected. + By default, ``'-sv --no-progress-bar'`` on Visual C++ and Xcode, ``'-sv'`` on + others. + + +Using Alternate ABI libraries +============================= + + +.. _libsupcxx: + +Using libsupc++ on Linux +------------------------ + +You will need libstdc++ in order to provide libsupc++. + +Figure out where the libsupc++ headers are on your system. On Ubuntu this +is ``/usr/include/c++/<version>`` and ``/usr/include/c++/<version>/<target-triple>`` + +You can also figure this out by running + +.. code-block:: bash + + $ echo | g++ -Wp,-v -x c++ - -fsyntax-only + ignoring nonexistent directory "/usr/local/include/x86_64-linux-gnu" + ignoring nonexistent directory "/usr/lib/gcc/x86_64-linux-gnu/4.7/../../../../x86_64-linux-gnu/include" + #include "..." search starts here: + #include <...> search starts here: + /usr/include/c++/4.7 + /usr/include/c++/4.7/x86_64-linux-gnu + /usr/include/c++/4.7/backward + /usr/lib/gcc/x86_64-linux-gnu/4.7/include + /usr/local/include + /usr/lib/gcc/x86_64-linux-gnu/4.7/include-fixed + /usr/include/x86_64-linux-gnu + /usr/include + End of search list. + +Note that the first two entries happen to be what we are looking for. This +may not be correct on other platforms. + +We can now run CMake: + +.. code-block:: bash + + $ CC=clang CXX=clang++ cmake -G "Unix Makefiles" \ + -DLIBCXX_CXX_ABI=libstdc++ \ + -DLIBCXX_CXX_ABI_INCLUDE_PATHS="/usr/include/c++/4.7/;/usr/include/c++/4.7/x86_64-linux-gnu/" \ + -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/usr \ + <libc++-source-dir> + + +You can also substitute ``-DLIBCXX_CXX_ABI=libsupc++`` +above, which will cause the library to be linked to libsupc++ instead +of libstdc++, but this is only recommended if you know that you will +never need to link against libstdc++ in the same executable as libc++. +GCC ships libsupc++ separately but only as a static library. If a +program also needs to link against libstdc++, it will provide its +own copy of libsupc++ and this can lead to subtle problems. + +.. code-block:: bash + + $ make cxx + $ make install + +You can now run clang with -stdlib=libc++. diff --git a/docs/CMakeLists.txt b/docs/CMakeLists.txt new file mode 100644 index 000000000000..f63ee00a5a02 --- /dev/null +++ b/docs/CMakeLists.txt @@ -0,0 +1,9 @@ + +if (LLVM_ENABLE_SPHINX) + if (SPHINX_FOUND) + include(AddSphinxTarget) + if (${SPHINX_OUTPUT_HTML}) + add_sphinx_target(html libcxx) + endif() + endif() +endif()
\ No newline at end of file diff --git a/docs/DesignDocs/ABIVersioning.rst b/docs/DesignDocs/ABIVersioning.rst new file mode 100644 index 000000000000..5960dd18610c --- /dev/null +++ b/docs/DesignDocs/ABIVersioning.rst @@ -0,0 +1,17 @@ + +==================== +Libc++ ABI stability +==================== + +Libc++ aims to preserve stable ABI to avoid subtle bugs when code built to the old ABI +is linked with the code build to the new ABI. At the same time, libc++ allows ABI-breaking +improvements and bugfixes for the scenarios when ABI change is not a issue. + +To support both cases, libc++ allows specifying the ABI version at the +build time. The version is defined with a cmake option +LIBCXX_ABI_VERSION. Another option LIBCXX_ABI_UNSTABLE can be used to +include all present ABI breaking features. These options translate +into C++ macro definitions _LIBCPP_ABI_VERSION, _LIBCPP_ABI_UNSTABLE. + +Any ABI-changing feature is placed under it's own macro, _LIBCPP_ABI_XXX, which is enabled +based on the value of _LIBCPP_ABI_VERSION. _LIBCPP_ABI_UNSTABLE, if set, enables all features at once. diff --git a/docs/DesignDocs/CapturingConfigInfo.rst b/docs/DesignDocs/CapturingConfigInfo.rst new file mode 100644 index 000000000000..73378a21c0a9 --- /dev/null +++ b/docs/DesignDocs/CapturingConfigInfo.rst @@ -0,0 +1,88 @@ +======================================================= +Capturing configuration information during installation +======================================================= + +.. contents:: + :local: + +The Problem +=========== + +Currently the libc++ supports building the library with a number of different +configuration options. Unfortunately all of that configuration information is +lost when libc++ is installed. In order to support "persistent" +configurations libc++ needs a mechanism to capture the configuration options +in the INSTALLED headers. + + +Design Goals +============ + +* The solution should not INSTALL any additional headers. We don't want an extra + #include slowing everybody down. + +* The solution should not unduly affect libc++ developers. The problem is limited + to installed versions of libc++ and the solution should be as well. + +* The solution should not modify any existing headers EXCEPT during installation. + It makes developers lives harder if they have to regenerate the libc++ headers + every time they are modified. + +* The solution should not make any of the libc++ headers dependant on + files generated by the build system. The headers should be able to compile + out of the box without any modification. + +* The solution should not have ANY effect on users who don't need special + configuration options. The vast majority of users will never need this so it + shouldn't cost them. + + +The Solution +============ + +When you first configure libc++ using CMake we check to see if we need to +capture any options. If we haven't been given any "persistent" options then +we do NOTHING. + +Otherwise we create a custom installation rule that modifies the installed __config +header. The rule first generates a dummy "__config_site" header containing the required +#defines. The contents of the dummy header are then prependend to the installed +__config header. By manually prepending the files we avoid the cost of an +extra #include and we allow the __config header to be ignorant of the extra +configuration all together. An example "__config" header generated when +-DLIBCXX_ENABLE_THREADS=OFF is given to CMake would look something like: + +.. code-block:: cpp + + //===----------------------------------------------------------------------===// + // + // 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_SITE + #define _LIBCPP_CONFIG_SITE + + /* #undef _LIBCPP_HAS_NO_GLOBAL_FILESYSTEM_NAMESPACE */ + /* #undef _LIBCPP_HAS_NO_STDIN */ + /* #undef _LIBCPP_HAS_NO_STDOUT */ + #define _LIBCPP_HAS_NO_THREADS + /* #undef _LIBCPP_HAS_NO_MONOTONIC_CLOCK */ + /* #undef _LIBCPP_HAS_NO_THREAD_UNSAFE_C_FUNCTIONS */ + + #endif + // -*- 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 diff --git a/docs/Makefile.sphinx b/docs/Makefile.sphinx new file mode 100644 index 000000000000..2ca1e4d3faf2 --- /dev/null +++ b/docs/Makefile.sphinx @@ -0,0 +1,37 @@ +# Makefile for Sphinx documentation +# +# FIXME: This hack is only in place to allow the libcxx.llvm.org/docs builder +# to work with libcxx. This should be removed when that builder supports +# out-of-tree builds. + +# You can set these variables from the command line. +SPHINXOPTS = +SPHINXBUILD = sphinx-build +PAPER = +BUILDDIR = _build + +# Internal variables. +PAPEROPT_a4 = -D latex_paper_size=a4 +PAPEROPT_letter = -D latex_paper_size=letter +ALLSPHINXOPTS = -d $(BUILDDIR)/doctrees $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) . +# the i18n builder cannot share the environment and doctrees with the others +I18NSPHINXOPTS = $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) . + +.PHONY: help clean html dirhtml singlehtml pickle json htmlhelp qthelp devhelp epub latex latexpdf text man changes linkcheck doctest gettext default + +default: html + +help: + @echo "Please use \`make <target>' where <target> is one of" + @echo " html to make standalone HTML files" + +clean: + -rm -rf $(BUILDDIR)/* + +html: + $(SPHINXBUILD) -b html $(ALLSPHINXOPTS) $(BUILDDIR)/html + @echo + @# FIXME: Remove this `cp` once HTML->Sphinx transition is completed. + @# Kind of a hack, but HTML-formatted docs are on the way out anyway. + @echo "Build finished. The HTML pages are in $(BUILDDIR)/html." + diff --git a/docs/README.txt b/docs/README.txt new file mode 100644 index 000000000000..06d94f5b5fc4 --- /dev/null +++ b/docs/README.txt @@ -0,0 +1,13 @@ +libc++ Documentation +==================== + +The libc++ documentation is written using the Sphinx documentation generator. It is +currently tested with Sphinx 1.1.3. + +To build the documents into html configure libc++ with the following cmake options: + + * -DLLVM_ENABLE_SPHINX=ON + * -DLIBCXX_INCLUDE_DOCS=ON + +After configuring libc++ with these options the make rule `docs-libcxx-html` +should be available. diff --git a/docs/TestingLibcxx.rst b/docs/TestingLibcxx.rst new file mode 100644 index 000000000000..98162d9c2e05 --- /dev/null +++ b/docs/TestingLibcxx.rst @@ -0,0 +1,191 @@ +============== +Testing libc++ +============== + +.. contents:: + :local: + +Getting Started +=============== + +libc++ uses LIT to configure and run its tests. The primary way to run the +libc++ tests is by using make check-libcxx. However since libc++ can be used +in any number of possible configurations it is important to customize the way +LIT builds and runs the tests. This guide provides information on how to use +LIT directly to test libc++. + +Please see the `Lit Command Guide`_ for more information about LIT. + +.. _LIT Command Guide: http://llvm.org/docs/CommandGuide/lit.html + +Setting up the Environment +-------------------------- + +After building libc++ you must setup your environment to test libc++ using +LIT. + +#. Create a shortcut to the actual lit executable so that you can invoke it + easily from the command line. + + .. code-block:: bash + + $ alias lit='python path/to/llvm/utils/lit/lit.py' + +#. Tell LIT where to find your build configuration. + + .. code-block:: bash + + $ export LIBCXX_SITE_CONFIG=path/to/build-libcxx/test/lit.site.cfg + +Example Usage +------------- + +Once you have your environment set up and you have built libc++ you can run +parts of the libc++ test suite by simply running `lit` on a specified test or +directory. For example: + +.. code-block:: bash + + $ cd path/to/src/libcxx + $ lit -sv test/std/re # Run all of the std::regex tests + $ lit -sv test/std/depr/depr.c.headers/stdlib_h.pass.cpp # Run a single test + $ lit -sv test/std/atomics test/std/threads # Test std::thread and std::atomic + +Sometimes you'll want to change the way LIT is running the tests. Custom options +can be specified using the `--param=<name>=<val>` flag. The most common option +you'll want to change is the standard dialect (ie -std=c++XX). By default the +test suite will select the newest C++ dialect supported by the compiler and use +that. However if you want to manually specify the option like so: + +.. code-block:: bash + + $ lit -sv test/std/containers # Run the tests with the newest -std + $ lit -sv --param=std=c++03 test/std/containers # Run the tests in C++03 + +Occasionally you'll want to add extra compile or link flags when testing. +You can do this as follows: + +.. code-block:: bash + + $ lit -sv --param=compile_flags='-Wcustom-warning' + $ lit -sv --param=link_flags='-L/custom/library/path' + +Some other common examples include: + +.. code-block:: bash + + # Specify a custom compiler. + $ lit -sv --param=cxx_under_test=/opt/bin/g++ test/std + + # Enable warnings in the test suite + $ lit -sv --param=enable_warnings=true test/std + + # Use UBSAN when running the tests. + $ lit -sv --param=use_sanitizer=Undefined + + +LIT Options +=========== + +:program:`lit` [*options*...] [*filenames*...] + +Command Line Options +-------------------- + +To use these options you pass them on the LIT command line as --param NAME or +--param NAME=VALUE. Some options have default values specified during CMake's +configuration. Passing the option on the command line will override the default. + +.. program:: lit + +.. option:: cxx_under_test=<path/to/compiler> + + Specify the compiler used to build the tests. + +.. option:: std=<standard version> + + **Values**: c++98, c++03, c++11, c++14, c++1z + + Change the standard version used when building the tests. + +.. option:: libcxx_site_config=<path/to/lit.site.cfg> + + Specify the site configuration to use when running the tests. This option + overrides the enviroment variable LIBCXX_SITE_CONFIG. + +.. option:: libcxx_headers=<path/to/headers> + + Specify the libc++ headers that are tested. By default the headers in the + source tree are used. + +.. option:: libcxx_library=<path/to/libc++.so> + + Specify the libc++ library that is tested. By default the library in the + build directory is used. This option cannot be used when use_system_lib is + provided. + +.. option:: use_system_lib=<bool> + + **Default**: False + + Enable or disable testing against the installed version of libc++ library. + Note: This does not use the installed headers. + +.. option:: use_lit_shell=<bool> + + Enable or disable the use of LIT's internal shell in ShTests. If the + environment variable LIT_USE_INTERNAL_SHELL is present then that is used as + the default value. Otherwise the default value is True on Windows and False + on every other platform. + +.. option:: no_default_flags=<bool> + + **Default**: False + + Disable all default compile and link flags from being added. When this + option is used only flags specified using the compile_flags and link_flags + will be used. + +.. option:: compile_flags="<list-of-args>" + + Specify additional compile flags as a space delimited string. + Note: This options should not be used to change the standard version used. + +.. option:: link_flags="<list-of-args>" + + Specify additional link flags as a space delimited string. + +.. option:: debug_level=<level> + + **Values**: 0, 1 + + Enable the use of debug mode. Level 0 enables assertions and level 1 enables + assertions and debugging of iterator misuse. + +.. option:: use_sanitizer=<sanitizer name> + + **Values**: Memory, MemoryWithOrigins, Address, Undefined + + Run the tests using the given sanitizer. If LLVM_USE_SANITIZER was given when + building libc++ then that sanitizer will be used by default. + +.. option:: color_diagnostics + + Enable the use of colorized compile diagnostics. If the color_diagnostics + option is specified or the environment variable LIBCXX_COLOR_DIAGNOSTICS is + present then color diagnostics will be enabled. + + +Environment Variables +--------------------- + +.. envvar:: LIBCXX_SITE_CONFIG=<path/to/lit.site.cfg> + + Specify the site configuration to use when running the tests. + Also see :option:`libcxx_site_config`. + +.. envvar:: LIBCXX_COLOR_DIAGNOSTICS + + If ``LIBCXX_COLOR_DIAGNOSTICS`` is defined then the test suite will attempt + to use color diagnostic outputs from the compiler. + Also see :option:`color_diagnostics`. diff --git a/docs/UsingLibcxx.rst b/docs/UsingLibcxx.rst new file mode 100644 index 000000000000..2a117917638c --- /dev/null +++ b/docs/UsingLibcxx.rst @@ -0,0 +1,89 @@ +============ +Using libc++ +============ + +.. contents:: + :local: + +Getting Started +=============== + +If you already have libc++ installed you can use it with clang. + +.. code-block:: bash + + $ clang++ -stdlib=libc++ test.cpp + $ clang++ -std=c++11 -stdlib=libc++ test.cpp + +On OS X and FreeBSD libc++ is the default standard library +and the ``-stdlib=libc++`` is not required. + +.. _alternate libcxx: + +If you want to select an alternate installation of libc++ you +can use the following options. + +.. code-block:: bash + + $ clang++ -std=c++11 -stdlib=libc++ -nostdinc++ \ + -I<libcxx-install-prefix>/include/c++/v1 \ + -L<libcxx-install-prefix>/lib \ + -Wl,-rpath,<libcxx-install-prefix>/lib \ + test.cpp + +The option ``-Wl,-rpath,<libcxx-install-prefix>/lib`` adds a runtime library +search path. Meaning that the systems dynamic linker will look for libc++ in +``<libcxx-install-prefix>/lib`` whenever the program is run. Alternatively the +environment variable ``LD_LIBRARY_PATH`` (``DYLD_LIBRARY_PATH`` on OS X) can +be used to change the dynamic linkers search paths after a program is compiled. + +An example of using ``LD_LIBRARY_PATH``: + +.. code-block:: bash + + $ clang++ -stdlib=libc++ -nostdinc++ \ + -I<libcxx-install-prefix>/include/c++/v1 + -L<libcxx-install-prefix>/lib \ + test.cpp -o + $ ./a.out # Searches for libc++ in the systems library paths. + $ export LD_LIBRARY_PATH=<libcxx-install-prefix>/lib + $ ./a.out # Searches for libc++ along LD_LIBRARY_PATH + + + +Using libc++ on Linux +===================== + +On Linux libc++ can typically be used with only '-stdlib=libc++'. However +some libc++ installations require the user manually link libc++abi themselves. +If you are running into linker errors when using libc++ try adding '-lc++abi' +to the link line. For example: + +.. code-block:: bash + + $ clang++ -stdlib=libc++ test.cpp -lc++ -lc++abi -lm -lc -lgcc_s -lgcc + +Alternately, you could just add libc++abi to your libraries list, which in +most situations will give the same result: + +.. code-block:: bash + + $ clang++ -stdlib=libc++ test.cpp -lc++abi + + +Using libc++ with GCC +--------------------- + +GCC does not provide a way to switch from libstdc++ to libc++. You must manually +configure the compile and link commands. + +In particular you must tell GCC to remove the libstdc++ include directories +using ``-nostdinc++`` and to not link libstdc++.so using ``-nodefaultlibs``. + +Note that ``-nodefaultlibs`` removes all of the standard system libraries and +not just libstdc++ so they must be manually linked. For example: + +.. code-block:: bash + + $ g++ -nostdinc++ -I<libcxx-install-prefix>/include/c++/v1 \ + test.cpp -nodefaultlibs -lc++ -lc++abi -lm -lc -lgcc_s -lgcc diff --git a/docs/conf.py b/docs/conf.py new file mode 100644 index 000000000000..915daa47a514 --- /dev/null +++ b/docs/conf.py @@ -0,0 +1,251 @@ +# -*- coding: utf-8 -*- +# +# libc++ documentation build configuration file. +# +# This file is execfile()d with the current directory set to its containing dir. +# +# Note that not all possible configuration values are present in this +# autogenerated file. +# +# All configuration values have a default; values that are commented out +# serve to show the default. + +import sys, os + +# If extensions (or modules to document with autodoc) are in another directory, +# add these directories to sys.path here. If the directory is relative to the +# documentation root, use os.path.abspath to make it absolute, like shown here. +#sys.path.insert(0, os.path.abspath('.')) + +# -- General configuration ----------------------------------------------------- + +# If your documentation needs a minimal Sphinx version, state it here. +#needs_sphinx = '1.0' + +# Add any Sphinx extension module names here, as strings. They can be extensions +# coming with Sphinx (named 'sphinx.ext.*') or your custom ones. +extensions = ['sphinx.ext.intersphinx', 'sphinx.ext.todo'] + +# Add any paths that contain templates here, relative to this directory. +templates_path = ['_templates'] + +# The suffix of source filenames. +source_suffix = '.rst' + +# The encoding of source files. +#source_encoding = 'utf-8-sig' + +# The master toctree document. +master_doc = 'index' + +# General information about the project. +project = u'libc++' +copyright = u'2011-2015, LLVM Project' + +# The version info for the project you're documenting, acts as replacement for +# |version| and |release|, also used in various other places throughout the +# built documents. +# +# The short X.Y version. +version = '3.8' +# The full version, including alpha/beta/rc tags. +release = '3.8' + +# The language for content autogenerated by Sphinx. Refer to documentation +# for a list of supported languages. +#language = None + +# There are two options for replacing |today|: either, you set today to some +# non-false value, then it is used: +#today = '' +# Else, today_fmt is used as the format for a strftime call. +today_fmt = '%Y-%m-%d' + +# List of patterns, relative to source directory, that match files and +# directories to ignore when looking for source files. +exclude_patterns = ['_build'] + +# The reST default role (used for this markup: `text`) to use for all documents. +#default_role = None + +# If true, '()' will be appended to :func: etc. cross-reference text. +#add_function_parentheses = True + +# If true, the current module name will be prepended to all description +# unit titles (such as .. function::). +#add_module_names = True + +# If true, sectionauthor and moduleauthor directives will be shown in the +# output. They are ignored by default. +show_authors = True + +# The name of the Pygments (syntax highlighting) style to use. +pygments_style = 'friendly' + +# A list of ignored prefixes for module index sorting. +#modindex_common_prefix = [] + + +# -- Options for HTML output --------------------------------------------------- + +# The theme to use for HTML and HTML Help pages. See the documentation for +# a list of builtin themes. +html_theme = 'haiku' + +# Theme options are theme-specific and customize the look and feel of a theme +# further. For a list of options available for each theme, see the +# documentation. +#html_theme_options = {} + +# Add any paths that contain custom themes here, relative to this directory. +#html_theme_path = [] + +# The name for this set of Sphinx documents. If None, it defaults to +# "<project> v<release> documentation". +#html_title = None + +# A shorter title for the navigation bar. Default is the same as html_title. +#html_short_title = None + +# The name of an image file (relative to this directory) to place at the top +# of the sidebar. +#html_logo = None + +# The name of an image file (within the static path) to use as favicon of the +# docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32 +# pixels large. +#html_favicon = None + +# Add any paths that contain custom static files (such as style sheets) here, +# relative to this directory. They are copied after the builtin static files, +# so a file named "default.css" will overwrite the builtin "default.css". +html_static_path = [] + +# If not '', a 'Last updated on:' timestamp is inserted at every page bottom, +# using the given strftime format. +#html_last_updated_fmt = '%b %d, %Y' + +# If true, SmartyPants will be used to convert quotes and dashes to +# typographically correct entities. +#html_use_smartypants = True + +# Custom sidebar templates, maps document names to template names. +#html_sidebars = {} + +# Additional templates that should be rendered to pages, maps page names to +# template names. +#html_additional_pages = {} + +# If false, no module index is generated. +#html_domain_indices = True + +# If false, no index is generated. +#html_use_index = True + +# If true, the index is split into individual pages for each letter. +#html_split_index = False + +# If true, links to the reST sources are added to the pages. +#html_show_sourcelink = True + +# If true, "Created using Sphinx" is shown in the HTML footer. Default is True. +#html_show_sphinx = True + +# If true, "(C) Copyright ..." is shown in the HTML footer. Default is True. +#html_show_copyright = True + +# If true, an OpenSearch description file will be output, and all pages will +# contain a <link> tag referring to it. The value of this option must be the +# base URL from which the finished HTML is served. +#html_use_opensearch = '' + +# This is the file name suffix for HTML files (e.g. ".xhtml"). +#html_file_suffix = None + +# Output file base name for HTML help builder. +htmlhelp_basename = 'libcxxdoc' + + +# -- Options for LaTeX output -------------------------------------------------- + +latex_elements = { +# The paper size ('letterpaper' or 'a4paper'). +#'papersize': 'letterpaper', + +# The font size ('10pt', '11pt' or '12pt'). +#'pointsize': '10pt', + +# Additional stuff for the LaTeX preamble. +#'preamble': '', +} + +# Grouping the document tree into LaTeX files. List of tuples +# (source start file, target name, title, author, documentclass [howto/manual]). +latex_documents = [ + ('contents', 'libcxx.tex', u'libcxx Documentation', + u'LLVM project', 'manual'), +] + +# The name of an image file (relative to this directory) to place at the top of +# the title page. +#latex_logo = None + +# For "manual" documents, if this is true, then toplevel headings are parts, +# not chapters. +#latex_use_parts = False + +# If true, show page references after internal links. +#latex_show_pagerefs = False + +# If true, show URL addresses after external links. +#latex_show_urls = False + +# Documents to append as an appendix to all manuals. +#latex_appendices = [] + +# If false, no module index is generated. +#latex_domain_indices = True + + +# -- Options for manual page output -------------------------------------------- + +# One entry per manual page. List of tuples +# (source start file, name, description, authors, manual section). +man_pages = [ + ('contents', 'libc++', u'libc++ Documentation', + [u'LLVM project'], 1) +] + +# If true, show URL addresses after external links. +#man_show_urls = False + + +# -- Options for Texinfo output ------------------------------------------------ + +# Grouping the document tree into Texinfo files. List of tuples +# (source start file, target name, title, author, +# dir menu entry, description, category) +texinfo_documents = [ + ('contents', 'libc++', u'libc++ Documentation', + u'LLVM project', 'libc++', 'One line description of project.', + 'Miscellaneous'), +] + +# Documents to append as an appendix to all manuals. +#texinfo_appendices = [] + +# If false, no module index is generated. +#texinfo_domain_indices = True + +# How to display URL addresses: 'footnote', 'no', or 'inline'. +#texinfo_show_urls = 'footnote' + + +# FIXME: Define intersphinx configration. +intersphinx_mapping = {} + + +# -- Options for extensions ---------------------------------------------------- + +# Enable this if you want TODOs to show up in the generated documentation. +todo_include_todos = True diff --git a/docs/index.rst b/docs/index.rst new file mode 100644 index 000000000000..b0c8b813f57f --- /dev/null +++ b/docs/index.rst @@ -0,0 +1,185 @@ +.. _index: + +============================= +"libc++" C++ Standard Library +============================= + +Overview +======== + +libc++ is a new implementation of the C++ standard library, targeting C++11. + +* Features and Goals + + * Correctness as defined by the C++11 standard. + * Fast execution. + * Minimal memory use. + * Fast compile times. + * ABI compatibility with gcc's libstdc++ for some low-level features + such as exception objects, rtti and memory allocation. + * Extensive unit tests. + +* Design and Implementation: + + * Extensive unit tests + * Internal linker model can be dumped/read to textual format + * Additional linking features can be plugged in as "passes" + * OS specific and CPU specific code factored out + + +Getting Started with libc++ +--------------------------- + +.. toctree:: + :maxdepth: 2 + + UsingLibcxx + BuildingLibcxx + TestingLibcxx + + +Current Status +-------------- + +After its initial introduction, many people have asked "why start a new +library instead of contributing to an existing library?" (like Apache's +libstdcxx, GNU's libstdc++, STLport, etc). There are many contributing +reasons, but some of the major ones are: + +* From years of experience (including having implemented the standard + library before), we've learned many things about implementing + the standard containers which require ABI breakage and fundamental changes + to how they are implemented. For example, it is generally accepted that + building std::string using the "short string optimization" instead of + using Copy On Write (COW) is a superior approach for multicore + machines (particularly in C++11, which has rvalue references). Breaking + ABI compatibility with old versions of the library was + determined to be critical to achieving the performance goals of + libc++. + +* Mainline libstdc++ has switched to GPL3, a license which the developers + of libc++ cannot use. libstdc++ 4.2 (the last GPL2 version) could be + independently extended to support C++11, but this would be a fork of the + codebase (which is often seen as worse for a project than starting a new + independent one). Another problem with libstdc++ is that it is tightly + integrated with G++ development, tending to be tied fairly closely to the + matching version of G++. + +* STLport and the Apache libstdcxx library are two other popular + candidates, but both lack C++11 support. Our experience (and the + experience of libstdc++ developers) is that adding support for C++11 (in + particular rvalue references and move-only types) requires changes to + almost every class and function, essentially amounting to a rewrite. + Faced with a rewrite, we decided to start from scratch and evaluate every + design decision from first principles based on experience. + Further, both projects are apparently abandoned: STLport 5.2.1 was + released in Oct'08, and STDCXX 4.2.1 in May'08. + +Platform and Compiler Support +----------------------------- + +libc++ is known to work on the following platforms, using gcc-4.2 and +clang (lack of C++11 language support disables some functionality). +Note that functionality provided by ``<atomic>`` is only functional with clang +and GCC. + +============ ==================== ============ ======================== +OS Arch Compilers ABI Library +============ ==================== ============ ======================== +Mac OS X i386, x86_64 Clang, GCC libc++abi +FreeBSD 10+ i386, x86_64, ARM Clang, GCC libcxxrt, libc++abi +Linux i386, x86_64 Clang, GCC libc++abi +============ ==================== ============ ======================== + +The following minimum compiler versions are strongly recommended. + +* Clang 3.5 and above +* GCC 4.7 and above. + +Anything older *may* work. + +C++ Dialect Support +--------------------- + +* C++11 - Complete +* `C++14 - Complete <http://libcxx.llvm.org/cxx1y_status.html>`__ +* `C++1z - In Progress <http://libcxx.llvm.org/cxx1z_status.html>`__ +* `Post C++14 Technical Specifications - In Progress <http://libcxx.llvm.org/ts1z_status.html>`__ + +Notes and Known Issues +---------------------- + +This list contains known issues with libc++ + +* Building libc++ with ``-fno-rtti`` is not supported. However + linking against it with ``-fno-rtti`` is supported. +* On OS X v10.8 and older the CMake option ``-DLIBCXX_LIBCPPABI_VERSION=""`` + must be used during configuration. + + +A full list of currently open libc++ bugs can be `found here`__. + +.. __: https://llvm.org/bugs/buglist.cgi?component=All%20Bugs&product=libc%2B%2B&query_format=advanced&resolution=---&order=changeddate%20DESC%2Cassigned_to%20DESC%2Cbug_status%2Cpriority%2Cbug_id&list_id=74184 + +Design Documents +---------------- + +.. toctree:: + :maxdepth: 1 + + DesignDocs/CapturingConfigInfo + DesignDocs/ABIVersioning + + +* `<atomic> design <http://libcxx.llvm.org/atomic_design.html>`_ +* `<type_traits> design <http://libcxx.llvm.org/type_traits_design.html>`_ +* `Status of debug mode <http://libcxx.llvm.org/debug_mode.html>`_ +* `Notes by Marshall Clow`__ + +.. __: https://cplusplusmusings.wordpress.com/2012/07/05/clang-and-standard-libraries-on-mac-os-x/ + +Build Bots and Test Coverage +---------------------------- + +* `LLVM Buildbot Builders <http://lab.llvm.org:8011/console>`_ +* `Apple Jenkins Builders <http://lab.llvm.org:8080/green/view/Libcxx/>`_ +* `EricWF's Nightly Builders <http://ds2.efcs.ca:8080/console>`_ +* `Code Coverage Results <http://efcs.ca/libcxx-coverage>`_ + +Getting Involved +================ + +First please review our `Developer's Policy <http://llvm.org/docs/DeveloperPolicy.html>`__ +and `Getting started with LLVM <http://llvm.org/docs/GettingStarted.html>`__. + +**Bug Reports** + +If you think you've found a bug in libc++, please report it using +the `LLVM Bugzilla`_. If you're not sure, you +can post a message to the `cfe-dev mailing list`_ or on IRC. +Please include "libc++" in your subject. + +**Patches** + +If you want to contribute a patch to libc++, the best place for that is +`Phabricator <http://llvm.org/docs/Phabricator.html>`_. Please include [libcxx] in the subject and +add `cfe-commits` as a subscriber. Also make sure you are subscribed to the +`cfe-commits mailing list <http://lists.llvm.org/mailman/listinfo/cfe-commits>`_. + +**Discussion and Questions** + +Send discussions and questions to the +`cfe-dev mailing list <http://lists.llvm.org/mailman/listinfo/cfe-dev>`_. +Please include [libcxx] in the subject. + + + +Quick Links +=========== +* `LLVM Homepage <http://llvm.org/>`_ +* `libc++abi Homepage <http://libcxxabi.llvm.org/>`_ +* `LLVM Bugzilla <http://llvm.org/bugs/>`_ +* `cfe-commits Mailing List`_ +* `cfe-dev Mailing List`_ +* `Browse libc++ -- SVN <http://llvm.org/svn/llvm-project/libcxx/trunk/>`_ +* `Browse libc++ -- ViewVC <http://llvm.org/viewvc/llvm-project/libcxx/trunk/>`_ diff --git a/include/CMakeLists.txt b/include/CMakeLists.txt index 95206bfeeaff..e16dc8b4de63 100644 --- a/include/CMakeLists.txt +++ b/include/CMakeLists.txt @@ -1,10 +1,12 @@ if (NOT LIBCXX_INSTALL_SUPPORT_HEADERS) set(LIBCXX_SUPPORT_HEADER_PATTERN PATTERN "support" EXCLUDE) endif() + set(LIBCXX_HEADER_PATTERN PATTERN "*" PATTERN "CMakeLists.txt" EXCLUDE PATTERN ".svn" EXCLUDE + PATTERN "__config_site.in" EXCLUDE ${LIBCXX_SUPPORT_HEADER_PATTERN} ) @@ -17,8 +19,34 @@ file(COPY . if (LIBCXX_INSTALL_HEADERS) install(DIRECTORY . DESTINATION include/c++/v1 + COMPONENT libcxx FILES_MATCHING ${LIBCXX_HEADER_PATTERN} PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ ) + + if (LIBCXX_NEEDS_SITE_CONFIG) + set(UNIX_CAT cat) + if (WIN32) + set(UNIX_CAT type) + endif() + # Generate and install a custom __config header. The new header is created + # by prepending __config_site to the current __config header. + add_custom_command(OUTPUT ${LIBCXX_BINARY_DIR}/__generated_config + COMMAND ${CMAKE_COMMAND} -E copy ${LIBCXX_BINARY_DIR}/__config_site ${LIBCXX_BINARY_DIR}/__generated_config + COMMAND ${UNIX_CAT} ${LIBCXX_SOURCE_DIR}/include/__config >> ${LIBCXX_BINARY_DIR}/__generated_config + DEPENDS ${LIBCXX_SOURCE_DIR}/include/__config + ${LIBCXX_BINARY_DIR}/__config_site + ) + # Add a target that executes the generation commands. + add_custom_target(generate_config_header ALL + DEPENDS ${LIBCXX_BINARY_DIR}/__generated_config) + # Install the generated header as __config. + install(FILES ${LIBCXX_BINARY_DIR}/__generated_config + DESTINATION include/c++/v1 + PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ + RENAME __config + COMPONENT libcxx) + endif() + endif() diff --git a/include/__config b/include/__config index 888f3c098cf4..f141f4f1b7f9 100644 --- a/include/__config +++ b/include/__config @@ -11,19 +11,35 @@ #ifndef _LIBCPP_CONFIG #define _LIBCPP_CONFIG -#if !defined(_MSC_VER) || defined(__clang__) +#if defined(_MSC_VER) && !defined(__clang__) +#define _LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER +#endif + +#ifndef _LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER #pragma GCC system_header #endif +#ifdef __cplusplus + #ifdef __GNUC__ #define _GNUC_VER (__GNUC__ * 100 + __GNUC_MINOR__) #else #define _GNUC_VER 0 #endif -#define _LIBCPP_VERSION 3700 +#define _LIBCPP_VERSION 3800 +#ifndef _LIBCPP_ABI_VERSION #define _LIBCPP_ABI_VERSION 1 +#endif + +#if defined(_LIBCPP_ABI_UNSTABLE) || _LIBCPP_ABI_VERSION >= 2 +// Change short string represention so that string data starts at offset 0, +// improving its alignment in some cases. +#define _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT +// Fix deque iterator type in order to support incomplete types. +#define _LIBCPP_ABI_INCOMPLETE_TYPES_IN_DEQUE +#endif #define _LIBCPP_CONCAT1(_LIBCPP_X,_LIBCPP_Y) _LIBCPP_X##_LIBCPP_Y #define _LIBCPP_CONCAT(_LIBCPP_X,_LIBCPP_Y) _LIBCPP_CONCAT1(_LIBCPP_X,_LIBCPP_Y) @@ -37,6 +53,9 @@ #ifndef __has_builtin #define __has_builtin(__x) 0 #endif +#ifndef __has_extension +#define __has_extension(__x) 0 +#endif #ifndef __has_feature #define __has_feature(__x) 0 #endif @@ -61,6 +80,16 @@ #endif // __BIG_ENDIAN__ #endif // __BIG_ENDIAN__ +#ifdef __BYTE_ORDER__ +#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ +#define _LIBCPP_LITTLE_ENDIAN 1 +#define _LIBCPP_BIG_ENDIAN 0 +#elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ +#define _LIBCPP_LITTLE_ENDIAN 0 +#define _LIBCPP_BIG_ENDIAN 1 +#endif // __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ +#endif // __BYTE_ORDER__ + #ifdef __FreeBSD__ # include <sys/endian.h> # if _BYTE_ORDER == _LITTLE_ENDIAN @@ -227,9 +256,12 @@ #if defined(__clang__) -#if defined(__APPLE__) && !defined(__i386__) && !defined(__x86_64__) && \ - !defined(__arm__) -#define _LIBCPP_ALTERNATE_STRING_LAYOUT +// _LIBCPP_ALTERNATE_STRING_LAYOUT is an old name for +// _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT left here for backward compatibility. +#if (defined(__APPLE__) && !defined(__i386__) && !defined(__x86_64__) && \ + !defined(__arm__)) || \ + defined(_LIBCPP_ALTERNATE_STRING_LAYOUT) +#define _LIBCPP_ABI_ALTERNATE_STRING_LAYOUT #endif #if __has_feature(cxx_alignas) @@ -273,6 +305,10 @@ typedef __char32_t char32_t; #define _LIBCPP_UNUSED __attribute__((__unused__)) +#if !(__has_feature(cxx_default_function_template_args)) +#define _LIBCPP_HAS_NO_DEFAULT_FUNCTION_TEMPLATE_ARGS +#endif + #if !(__has_feature(cxx_defaulted_functions)) #define _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS #endif // !(__has_feature(cxx_defaulted_functions)) @@ -354,24 +390,23 @@ typedef __char32_t char32_t; #elif defined(__ANDROID__) #define _LIBCPP_HAS_QUICK_EXIT #elif defined(__linux__) -#include <features.h> +#if !defined(_LIBCPP_HAS_MUSL_LIBC) +# include <features.h> #if __GLIBC_PREREQ(2, 15) #define _LIBCPP_HAS_QUICK_EXIT #endif #if __GLIBC_PREREQ(2, 17) #define _LIBCPP_HAS_C11_FEATURES #endif +#else // defined(_LIBCPP_HAS_MUSL_LIBC) +#define _LIBCPP_HAS_QUICK_EXIT +#define _LIBCPP_HAS_C11_FEATURES #endif +#endif // __linux__ #endif -#if (__has_feature(cxx_noexcept)) -# define _NOEXCEPT noexcept -# define _NOEXCEPT_(x) noexcept(x) -# define _NOEXCEPT_OR_FALSE(x) noexcept(x) -#else -# define _NOEXCEPT throw() -# define _NOEXCEPT_(x) -# define _NOEXCEPT_OR_FALSE(x) false +#if !(__has_feature(cxx_noexcept)) +#define _LIBCPP_HAS_NO_NOEXCEPT #endif #if __has_feature(underlying_type) @@ -429,19 +464,21 @@ namespace std { #define _LIBCPP_HAS_NO_CONSTEXPR #endif -// No version of GCC supports relaxed constexpr rules +// Determine if GCC supports relaxed constexpr +#if !defined(__cpp_constexpr) || __cpp_constexpr < 201304L #define _LIBCPP_HAS_NO_CXX14_CONSTEXPR +#endif + // GCC 5 will support variable templates +#if !defined(__cpp_variable_templates) || __cpp_variable_templates < 201304L #define _LIBCPP_HAS_NO_VARIABLE_TEMPLATES - -#define _NOEXCEPT throw() -#define _NOEXCEPT_(x) -#define _NOEXCEPT_OR_FALSE(x) false +#endif #ifndef __GXX_EXPERIMENTAL_CXX0X__ #define _LIBCPP_HAS_NO_ADVANCED_SFINAE #define _LIBCPP_HAS_NO_DECLTYPE +#define _LIBCPP_HAS_NO_DEFAULT_FUNCTION_TEMPLATE_ARGS #define _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS #define _LIBCPP_HAS_NO_DELETED_FUNCTIONS #define _LIBCPP_HAS_NO_NULLPTR @@ -449,31 +486,29 @@ namespace std { #define _LIBCPP_HAS_NO_UNICODE_CHARS #define _LIBCPP_HAS_NO_VARIADICS #define _LIBCPP_HAS_NO_RVALUE_REFERENCES -#define _LIBCPP_HAS_NO_ALWAYS_INLINE_VARIADICS #define _LIBCPP_HAS_NO_STRONG_ENUMS +#define _LIBCPP_HAS_NO_NOEXCEPT #else // __GXX_EXPERIMENTAL_CXX0X__ -#define _LIBCPP_HAS_NO_TRAILING_RETURN -#define _LIBCPP_HAS_NO_ALWAYS_INLINE_VARIADICS - #if _GNUC_VER < 403 +#define _LIBCPP_HAS_NO_DEFAULT_FUNCTION_TEMPLATE_ARGS #define _LIBCPP_HAS_NO_RVALUE_REFERENCES -#endif - -#if _GNUC_VER < 403 #define _LIBCPP_HAS_NO_STATIC_ASSERT #endif + #if _GNUC_VER < 404 #define _LIBCPP_HAS_NO_DECLTYPE #define _LIBCPP_HAS_NO_DELETED_FUNCTIONS +#define _LIBCPP_HAS_NO_TRAILING_RETURN #define _LIBCPP_HAS_NO_UNICODE_CHARS #define _LIBCPP_HAS_NO_VARIADICS #define _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS #endif // _GNUC_VER < 404 #if _GNUC_VER < 406 +#define _LIBCPP_HAS_NO_NOEXCEPT #define _LIBCPP_HAS_NO_NULLPTR #endif @@ -501,22 +536,20 @@ using namespace _LIBCPP_NAMESPACE __attribute__((__strong__)); #elif defined(_LIBCPP_MSVC) #define _LIBCPP_HAS_NO_TEMPLATE_ALIASES -#define _LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER #define _LIBCPP_HAS_NO_CONSTEXPR #define _LIBCPP_HAS_NO_CXX14_CONSTEXPR #define _LIBCPP_HAS_NO_VARIABLE_TEMPLATES #define _LIBCPP_HAS_NO_UNICODE_CHARS #define _LIBCPP_HAS_NO_DELETED_FUNCTIONS #define _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS +#define _LIBCPP_HAS_NO_NOEXCEPT #define __alignof__ __alignof #define _LIBCPP_NORETURN __declspec(noreturn) #define _LIBCPP_UNUSED #define _ALIGNAS(x) __declspec(align(x)) #define _LIBCPP_HAS_NO_VARIADICS -#define _NOEXCEPT throw () -#define _NOEXCEPT_(x) -#define _NOEXCEPT_OR_FALSE(x) false + #define _LIBCPP_BEGIN_NAMESPACE_STD namespace std { #define _LIBCPP_END_NAMESPACE_STD } @@ -536,14 +569,11 @@ namespace std { #define _LIBCPP_NORETURN __attribute__((noreturn)) #define _LIBCPP_UNUSED -#define _NOEXCEPT throw() -#define _NOEXCEPT_(x) -#define _NOEXCEPT_OR_FALSE(x) false - +#define _LIBCPP_HAS_NO_DEFAULT_FUNCTION_TEMPLATE_ARGS #define _LIBCPP_HAS_NO_TEMPLATE_ALIASES #define _LIBCPP_HAS_NO_ADVANCED_SFINAE -#define _LIBCPP_HAS_NO_ALWAYS_INLINE_VARIADICS #define _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS +#define _LIBCPP_HAS_NO_NOEXCEPT #define _LIBCPP_HAS_NO_NULLPTR #define _LIBCPP_HAS_NO_UNICODE_CHARS #define _LIBCPP_HAS_IS_BASE_OF @@ -567,6 +597,14 @@ namespace std { #endif // __clang__ || __GNUC__ || _MSC_VER || __IBMCPP__ +#ifndef _LIBCPP_HAS_NO_NOEXCEPT +# define _NOEXCEPT noexcept +# define _NOEXCEPT_(x) noexcept(x) +#else +# define _NOEXCEPT throw() +# define _NOEXCEPT_(x) +#endif + #ifdef _LIBCPP_HAS_NO_UNICODE_CHARS typedef unsigned short char16_t; typedef unsigned int char32_t; @@ -578,9 +616,11 @@ typedef unsigned int char32_t; #ifdef _LIBCPP_HAS_NO_STATIC_ASSERT +extern "C++" { template <bool> struct __static_assert_test; template <> struct __static_assert_test<true> {}; template <unsigned> struct __static_assert_check {}; +} #define static_assert(__b, __m) \ typedef __static_assert_check<sizeof(__static_assert_test<(__b)>)> \ _LIBCPP_CONCAT(__t, __LINE__) @@ -716,6 +756,12 @@ template <unsigned> struct __static_assert_check {}; #define _LIBCPP_CONSTEXPR_AFTER_CXX11 #endif +#ifdef _LIBCPP_HAS_NO_RVALUE_REFERENCES +# define _LIBCPP_EXPLICIT_MOVE(x) _VSTD::move(x) +#else +# define _LIBCPP_EXPLICIT_MOVE(x) (x) +#endif + #ifndef _LIBCPP_HAS_NO_ASAN extern "C" void __sanitizer_annotate_contiguous_container( const void *, const void *, const void *, const void *); @@ -725,7 +771,7 @@ extern "C" void __sanitizer_annotate_contiguous_container( // g++ and cl.exe have RTTI on by default and define a macro when it is. // g++ only defines the macro in 4.3.2 and onwards. #if !defined(_LIBCPP_NO_RTTI) -# if defined(__GNUG__) && ((__GNUC__ >= 5) || (__GNUC__ == 4 && \ +# if defined(__GNUC__) && ((__GNUC__ >= 5) || (__GNUC__ == 4 && \ (__GNUC_MINOR__ >= 3 || __GNUC_PATCHLEVEL__ >= 2))) && !defined(__GXX_RTTI) # define _LIBCPP_NO_RTTI # elif (defined(_MSC_VER) && !defined(__clang__)) && !defined(_CPPRTTI) @@ -757,7 +803,7 @@ extern "C" void __sanitizer_annotate_contiguous_container( #define _LIBCPP_HAS_NO_STDOUT #endif -#if defined(__ANDROID__) || defined(__CloudABI__) +#if defined(__ANDROID__) || defined(__CloudABI__) || defined(_LIBCPP_HAS_MUSL_LIBC) #define _LIBCPP_PROVIDES_DEFAULT_RUNE_TABLE #endif @@ -767,4 +813,17 @@ extern "C" void __sanitizer_annotate_contiguous_container( #define _LIBCPP_HAS_NO_THREAD_UNSAFE_C_FUNCTIONS #endif -#endif // _LIBCPP_CONFIG +#if __has_feature(cxx_atomic) || __has_extension(c_atomic) +#define _LIBCPP_HAS_C_ATOMIC_IMP +#elif _GNUC_VER > 407 +#define _LIBCPP_HAS_GCC_ATOMIC_IMP +#endif + +#if (!defined(_LIBCPP_HAS_C_ATOMIC_IMP) && !defined(_LIBCPP_HAS_GCC_ATOMIC_IMP)) \ + || defined(_LIBCPP_HAS_NO_THREADS) +#define _LIBCPP_HAS_NO_ATOMIC_HEADER +#endif + +#endif // __cplusplus + +#endif // _LIBCPP_CONFIG diff --git a/include/__config_site.in b/include/__config_site.in new file mode 100644 index 000000000000..ec64485289fa --- /dev/null +++ b/include/__config_site.in @@ -0,0 +1,23 @@ +//===----------------------------------------------------------------------===// +// +// 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_SITE +#define _LIBCPP_CONFIG_SITE + +#cmakedefine _LIBCPP_ABI_VERSION @_LIBCPP_ABI_VERSION@ +#cmakedefine _LIBCPP_ABI_UNSTABLE +#cmakedefine _LIBCPP_HAS_NO_GLOBAL_FILESYSTEM_NAMESPACE +#cmakedefine _LIBCPP_HAS_NO_STDIN +#cmakedefine _LIBCPP_HAS_NO_STDOUT +#cmakedefine _LIBCPP_HAS_NO_THREADS +#cmakedefine _LIBCPP_HAS_NO_MONOTONIC_CLOCK +#cmakedefine _LIBCPP_HAS_NO_THREAD_UNSAFE_C_FUNCTIONS +#cmakedefine _LIBCPP_HAS_MUSL_LIBC + +#endif // _LIBCPP_CONFIG_SITE diff --git a/include/__functional_03 b/include/__functional_03 index 13c38d8548d9..4edbb0996ca0 100644 --- a/include/__functional_03 +++ b/include/__functional_03 @@ -17,218 +17,7 @@ #pragma GCC system_header #endif -template <class _Tp> -class __mem_fn - : public __weak_result_type<_Tp> -{ -public: - // types - typedef _Tp type; -private: - type __f_; - -public: - _LIBCPP_INLINE_VISIBILITY __mem_fn(type __f) : __f_(__f) {} - - // invoke - - typename __invoke_return<type>::type - operator() () const - { - return __invoke(__f_); - } - - template <class _A0> - typename __invoke_return0<type, _A0>::type - operator() (_A0& __a0) const - { - return __invoke(__f_, __a0); - } - - template <class _A0, class _A1> - typename __invoke_return1<type, _A0, _A1>::type - operator() (_A0& __a0, _A1& __a1) const - { - return __invoke(__f_, __a0, __a1); - } - - template <class _A0, class _A1, class _A2> - typename __invoke_return2<type, _A0, _A1, _A2>::type - operator() (_A0& __a0, _A1& __a1, _A2& __a2) const - { - return __invoke(__f_, __a0, __a1, __a2); - } -}; - -template<class _Rp, class _Tp> -inline _LIBCPP_INLINE_VISIBILITY -__mem_fn<_Rp _Tp::*> -mem_fn(_Rp _Tp::* __pm) -{ - return __mem_fn<_Rp _Tp::*>(__pm); -} - -template<class _Rp, class _Tp> -inline _LIBCPP_INLINE_VISIBILITY -__mem_fn<_Rp (_Tp::*)()> -mem_fn(_Rp (_Tp::* __pm)()) -{ - return __mem_fn<_Rp (_Tp::*)()>(__pm); -} - -template<class _Rp, class _Tp, class _A0> -inline _LIBCPP_INLINE_VISIBILITY -__mem_fn<_Rp (_Tp::*)(_A0)> -mem_fn(_Rp (_Tp::* __pm)(_A0)) -{ - return __mem_fn<_Rp (_Tp::*)(_A0)>(__pm); -} - -template<class _Rp, class _Tp, class _A0, class _A1> -inline _LIBCPP_INLINE_VISIBILITY -__mem_fn<_Rp (_Tp::*)(_A0, _A1)> -mem_fn(_Rp (_Tp::* __pm)(_A0, _A1)) -{ - return __mem_fn<_Rp (_Tp::*)(_A0, _A1)>(__pm); -} - -template<class _Rp, class _Tp, class _A0, class _A1, class _A2> -inline _LIBCPP_INLINE_VISIBILITY -__mem_fn<_Rp (_Tp::*)(_A0, _A1, _A2)> -mem_fn(_Rp (_Tp::* __pm)(_A0, _A1, _A2)) -{ - return __mem_fn<_Rp (_Tp::*)(_A0, _A1, _A2)>(__pm); -} - -template<class _Rp, class _Tp> -inline _LIBCPP_INLINE_VISIBILITY -__mem_fn<_Rp (_Tp::*)() const> -mem_fn(_Rp (_Tp::* __pm)() const) -{ - return __mem_fn<_Rp (_Tp::*)() const>(__pm); -} - -template<class _Rp, class _Tp, class _A0> -inline _LIBCPP_INLINE_VISIBILITY -__mem_fn<_Rp (_Tp::*)(_A0) const> -mem_fn(_Rp (_Tp::* __pm)(_A0) const) -{ - return __mem_fn<_Rp (_Tp::*)(_A0) const>(__pm); -} - -template<class _Rp, class _Tp, class _A0, class _A1> -inline _LIBCPP_INLINE_VISIBILITY -__mem_fn<_Rp (_Tp::*)(_A0, _A1) const> -mem_fn(_Rp (_Tp::* __pm)(_A0, _A1) const) -{ - return __mem_fn<_Rp (_Tp::*)(_A0, _A1) const>(__pm); -} - -template<class _Rp, class _Tp, class _A0, class _A1, class _A2> -inline _LIBCPP_INLINE_VISIBILITY -__mem_fn<_Rp (_Tp::*)(_A0, _A1, _A2) const> -mem_fn(_Rp (_Tp::* __pm)(_A0, _A1, _A2) const) -{ - return __mem_fn<_Rp (_Tp::*)(_A0, _A1, _A2) const>(__pm); -} - -template<class _Rp, class _Tp> -inline _LIBCPP_INLINE_VISIBILITY -__mem_fn<_Rp (_Tp::*)() volatile> -mem_fn(_Rp (_Tp::* __pm)() volatile) -{ - return __mem_fn<_Rp (_Tp::*)() volatile>(__pm); -} - -template<class _Rp, class _Tp, class _A0> -inline _LIBCPP_INLINE_VISIBILITY -__mem_fn<_Rp (_Tp::*)(_A0) volatile> -mem_fn(_Rp (_Tp::* __pm)(_A0) volatile) -{ - return __mem_fn<_Rp (_Tp::*)(_A0) volatile>(__pm); -} - -template<class _Rp, class _Tp, class _A0, class _A1> -inline _LIBCPP_INLINE_VISIBILITY -__mem_fn<_Rp (_Tp::*)(_A0, _A1) volatile> -mem_fn(_Rp (_Tp::* __pm)(_A0, _A1) volatile) -{ - return __mem_fn<_Rp (_Tp::*)(_A0, _A1) volatile>(__pm); -} - -template<class _Rp, class _Tp, class _A0, class _A1, class _A2> -inline _LIBCPP_INLINE_VISIBILITY -__mem_fn<_Rp (_Tp::*)(_A0, _A1, _A2) volatile> -mem_fn(_Rp (_Tp::* __pm)(_A0, _A1, _A2) volatile) -{ - return __mem_fn<_Rp (_Tp::*)(_A0, _A1, _A2) volatile>(__pm); -} - -template<class _Rp, class _Tp> -inline _LIBCPP_INLINE_VISIBILITY -__mem_fn<_Rp (_Tp::*)() const volatile> -mem_fn(_Rp (_Tp::* __pm)() const volatile) -{ - return __mem_fn<_Rp (_Tp::*)() const volatile>(__pm); -} - -template<class _Rp, class _Tp, class _A0> -inline _LIBCPP_INLINE_VISIBILITY -__mem_fn<_Rp (_Tp::*)(_A0) const volatile> -mem_fn(_Rp (_Tp::* __pm)(_A0) const volatile) -{ - return __mem_fn<_Rp (_Tp::*)(_A0) const volatile>(__pm); -} - -template<class _Rp, class _Tp, class _A0, class _A1> -inline _LIBCPP_INLINE_VISIBILITY -__mem_fn<_Rp (_Tp::*)(_A0, _A1) const volatile> -mem_fn(_Rp (_Tp::* __pm)(_A0, _A1) const volatile) -{ - return __mem_fn<_Rp (_Tp::*)(_A0, _A1) const volatile>(__pm); -} - -template<class _Rp, class _Tp, class _A0, class _A1, class _A2> -inline _LIBCPP_INLINE_VISIBILITY -__mem_fn<_Rp (_Tp::*)(_A0, _A1, _A2) const volatile> -mem_fn(_Rp (_Tp::* __pm)(_A0, _A1, _A2) const volatile) -{ - return __mem_fn<_Rp (_Tp::*)(_A0, _A1, _A2) const volatile>(__pm); -} - -// bad_function_call - -class _LIBCPP_EXCEPTION_ABI bad_function_call - : public exception -{ -}; - -template<class _Fp> class _LIBCPP_TYPE_VIS_ONLY function; // undefined - -namespace __function -{ - -template<class _Fp> -struct __maybe_derive_from_unary_function -{ -}; - -template<class _Rp, class _A1> -struct __maybe_derive_from_unary_function<_Rp(_A1)> - : public unary_function<_A1, _Rp> -{ -}; - -template<class _Fp> -struct __maybe_derive_from_binary_function -{ -}; - -template<class _Rp, class _A1, class _A2> -struct __maybe_derive_from_binary_function<_Rp(_A1, _A2)> - : public binary_function<_A1, _A2, _Rp> -{ -}; +namespace __function { template<class _Fp> class __base; @@ -662,15 +451,6 @@ class _LIBCPP_TYPE_VIS_ONLY function<_Rp()> aligned_storage<3*sizeof(void*)>::type __buf_; __base* __f_; - template <class _Fp> - _LIBCPP_INLINE_VISIBILITY - static bool __not_null(const _Fp&) {return true;} - template <class _R2> - _LIBCPP_INLINE_VISIBILITY - static bool __not_null(_R2 (*__p)()) {return __p;} - template <class _R2> - _LIBCPP_INLINE_VISIBILITY - static bool __not_null(const function<_R2()>& __p) {return __p;} public: typedef _Rp result_type; @@ -769,7 +549,7 @@ function<_Rp()>::function(_Fp __f, typename enable_if<!is_integral<_Fp>::value>::type*) : __f_(0) { - if (__not_null(__f)) + if (__function::__not_null(__f)) { typedef __function::__func<_Fp, allocator<_Fp>, _Rp()> _FF; if (sizeof(_FF) <= sizeof(__buf_)) @@ -796,7 +576,7 @@ function<_Rp()>::function(allocator_arg_t, const _Alloc& __a0, _Fp __f, : __f_(0) { typedef allocator_traits<_Alloc> __alloc_traits; - if (__not_null(__f)) + if (__function::__not_null(__f)) { typedef __function::__func<_Fp, _Alloc, _Rp()> _FF; if (sizeof(_FF) <= sizeof(__buf_)) @@ -947,27 +727,6 @@ class _LIBCPP_TYPE_VIS_ONLY function<_Rp(_A0)> aligned_storage<3*sizeof(void*)>::type __buf_; __base* __f_; - template <class _Fp> - _LIBCPP_INLINE_VISIBILITY - static bool __not_null(const _Fp&) {return true;} - template <class _R2, class _B0> - _LIBCPP_INLINE_VISIBILITY - static bool __not_null(_R2 (*__p)(_B0)) {return __p;} - template <class _R2, class _Cp> - _LIBCPP_INLINE_VISIBILITY - static bool __not_null(_R2 (_Cp::*__p)()) {return __p;} - template <class _R2, class _Cp> - _LIBCPP_INLINE_VISIBILITY - static bool __not_null(_R2 (_Cp::*__p)() const) {return __p;} - template <class _R2, class _Cp> - _LIBCPP_INLINE_VISIBILITY - static bool __not_null(_R2 (_Cp::*__p)() volatile) {return __p;} - template <class _R2, class _Cp> - _LIBCPP_INLINE_VISIBILITY - static bool __not_null(_R2 (_Cp::*__p)() const volatile) {return __p;} - template <class _R2, class _B0> - _LIBCPP_INLINE_VISIBILITY - static bool __not_null(const function<_R2(_B0)>& __p) {return __p;} public: typedef _Rp result_type; @@ -1066,7 +825,7 @@ function<_Rp(_A0)>::function(_Fp __f, typename enable_if<!is_integral<_Fp>::value>::type*) : __f_(0) { - if (__not_null(__f)) + if (__function::__not_null(__f)) { typedef __function::__func<_Fp, allocator<_Fp>, _Rp(_A0)> _FF; if (sizeof(_FF) <= sizeof(__buf_)) @@ -1093,7 +852,7 @@ function<_Rp(_A0)>::function(allocator_arg_t, const _Alloc& __a0, _Fp __f, : __f_(0) { typedef allocator_traits<_Alloc> __alloc_traits; - if (__not_null(__f)) + if (__function::__not_null(__f)) { typedef __function::__func<_Fp, _Alloc, _Rp(_A0)> _FF; if (sizeof(_FF) <= sizeof(__buf_)) @@ -1244,27 +1003,6 @@ class _LIBCPP_TYPE_VIS_ONLY function<_Rp(_A0, _A1)> aligned_storage<3*sizeof(void*)>::type __buf_; __base* __f_; - template <class _Fp> - _LIBCPP_INLINE_VISIBILITY - static bool __not_null(const _Fp&) {return true;} - template <class _R2, class _B0, class _B1> - _LIBCPP_INLINE_VISIBILITY - static bool __not_null(_R2 (*__p)(_B0, _B1)) {return __p;} - template <class _R2, class _Cp, class _B1> - _LIBCPP_INLINE_VISIBILITY - static bool __not_null(_R2 (_Cp::*__p)(_B1)) {return __p;} - template <class _R2, class _Cp, class _B1> - _LIBCPP_INLINE_VISIBILITY - static bool __not_null(_R2 (_Cp::*__p)(_B1) const) {return __p;} - template <class _R2, class _Cp, class _B1> - _LIBCPP_INLINE_VISIBILITY - static bool __not_null(_R2 (_Cp::*__p)(_B1) volatile) {return __p;} - template <class _R2, class _Cp, class _B1> - _LIBCPP_INLINE_VISIBILITY - static bool __not_null(_R2 (_Cp::*__p)(_B1) const volatile) {return __p;} - template <class _R2, class _B0, class _B1> - _LIBCPP_INLINE_VISIBILITY - static bool __not_null(const function<_R2(_B0, _B1)>& __p) {return __p;} public: typedef _Rp result_type; @@ -1363,7 +1101,7 @@ function<_Rp(_A0, _A1)>::function(_Fp __f, typename enable_if<!is_integral<_Fp>::value>::type*) : __f_(0) { - if (__not_null(__f)) + if (__function::__not_null(__f)) { typedef __function::__func<_Fp, allocator<_Fp>, _Rp(_A0, _A1)> _FF; if (sizeof(_FF) <= sizeof(__buf_)) @@ -1390,7 +1128,7 @@ function<_Rp(_A0, _A1)>::function(allocator_arg_t, const _Alloc& __a0, _Fp __f, : __f_(0) { typedef allocator_traits<_Alloc> __alloc_traits; - if (__not_null(__f)) + if (__function::__not_null(__f)) { typedef __function::__func<_Fp, _Alloc, _Rp(_A0, _A1)> _FF; if (sizeof(_FF) <= sizeof(__buf_)) @@ -1540,27 +1278,6 @@ class _LIBCPP_TYPE_VIS_ONLY function<_Rp(_A0, _A1, _A2)> aligned_storage<3*sizeof(void*)>::type __buf_; __base* __f_; - template <class _Fp> - _LIBCPP_INLINE_VISIBILITY - static bool __not_null(const _Fp&) {return true;} - template <class _R2, class _B0, class _B1, class _B2> - _LIBCPP_INLINE_VISIBILITY - static bool __not_null(_R2 (*__p)(_B0, _B1, _B2)) {return __p;} - template <class _R2, class _Cp, class _B1, class _B2> - _LIBCPP_INLINE_VISIBILITY - static bool __not_null(_R2 (_Cp::*__p)(_B1, _B2)) {return __p;} - template <class _R2, class _Cp, class _B1, class _B2> - _LIBCPP_INLINE_VISIBILITY - static bool __not_null(_R2 (_Cp::*__p)(_B1, _B2) const) {return __p;} - template <class _R2, class _Cp, class _B1, class _B2> - _LIBCPP_INLINE_VISIBILITY - static bool __not_null(_R2 (_Cp::*__p)(_B1, _B2) volatile) {return __p;} - template <class _R2, class _Cp, class _B1, class _B2> - _LIBCPP_INLINE_VISIBILITY - static bool __not_null(_R2 (_Cp::*__p)(_B1, _B2) const volatile) {return __p;} - template <class _R2, class _B0, class _B1, class _B2> - _LIBCPP_INLINE_VISIBILITY - static bool __not_null(const function<_R2(_B0, _B1, _B2)>& __p) {return __p;} public: typedef _Rp result_type; @@ -1660,7 +1377,7 @@ function<_Rp(_A0, _A1, _A2)>::function(_Fp __f, typename enable_if<!is_integral<_Fp>::value>::type*) : __f_(0) { - if (__not_null(__f)) + if (__function::__not_null(__f)) { typedef __function::__func<_Fp, allocator<_Fp>, _Rp(_A0, _A1, _A2)> _FF; if (sizeof(_FF) <= sizeof(__buf_)) @@ -1687,7 +1404,7 @@ function<_Rp(_A0, _A1, _A2)>::function(allocator_arg_t, const _Alloc& __a0, _Fp : __f_(0) { typedef allocator_traits<_Alloc> __alloc_traits; - if (__not_null(__f)) + if (__function::__not_null(__f)) { typedef __function::__func<_Fp, _Alloc, _Rp(_A0, _A1, _A2)> _FF; if (sizeof(_FF) <= sizeof(__buf_)) @@ -1856,274 +1573,4 @@ void swap(function<_Fp>& __x, function<_Fp>& __y) {return __x.swap(__y);} -template<class _Tp> struct __is_bind_expression : public false_type {}; -template<class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_bind_expression - : public __is_bind_expression<typename remove_cv<_Tp>::type> {}; - -template<class _Tp> struct __is_placeholder : public integral_constant<int, 0> {}; -template<class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_placeholder - : public __is_placeholder<typename remove_cv<_Tp>::type> {}; - -namespace placeholders -{ - -template <int _Np> struct __ph {}; - -extern __ph<1> _1; -extern __ph<2> _2; -extern __ph<3> _3; -extern __ph<4> _4; -extern __ph<5> _5; -extern __ph<6> _6; -extern __ph<7> _7; -extern __ph<8> _8; -extern __ph<9> _9; -extern __ph<10> _10; - -} // placeholders - -template<int _Np> -struct __is_placeholder<placeholders::__ph<_Np> > - : public integral_constant<int, _Np> {}; - -template <class _Tp, class _Uj> -inline _LIBCPP_INLINE_VISIBILITY -_Tp& -__mu(reference_wrapper<_Tp> __t, _Uj&) -{ - return __t.get(); -} -/* -template <bool _IsBindExpr, class _Ti, class ..._Uj> -struct __mu_return1 {}; - -template <class _Ti, class ..._Uj> -struct __mu_return1<true, _Ti, _Uj...> -{ - typedef typename result_of<_Ti(_Uj...)>::type type; -}; - -template <class _Ti, class ..._Uj, size_t ..._Indx> -inline _LIBCPP_INLINE_VISIBILITY -typename __mu_return1<true, _Ti, _Uj...>::type -__mu_expand(_Ti& __ti, tuple<_Uj...>&& __uj, __tuple_indices<_Indx...>) -{ - __ti(_VSTD::forward<typename tuple_element<_Indx, _Uj>::type>(_VSTD::get<_Indx>(__uj))...); -} - -template <class _Ti, class ..._Uj> -inline _LIBCPP_INLINE_VISIBILITY -typename enable_if -< - is_bind_expression<_Ti>::value, - typename __mu_return1<is_bind_expression<_Ti>::value, _Ti, _Uj...>::type ->::type -__mu(_Ti& __ti, tuple<_Uj...>& __uj) -{ - typedef typename __make_tuple_indices<sizeof...(_Uj)>::type __indices; - return __mu_expand(__ti, __uj, __indices()); -} - -template <bool IsPh, class _Ti, class _Uj> -struct __mu_return2 {}; - -template <class _Ti, class _Uj> -struct __mu_return2<true, _Ti, _Uj> -{ - typedef typename tuple_element<is_placeholder<_Ti>::value - 1, _Uj>::type type; -}; - -template <class _Ti, class _Uj> -inline _LIBCPP_INLINE_VISIBILITY -typename enable_if -< - 0 < is_placeholder<_Ti>::value, - typename __mu_return2<0 < is_placeholder<_Ti>::value, _Ti, _Uj>::type ->::type -__mu(_Ti&, _Uj& __uj) -{ - const size_t _Indx = is_placeholder<_Ti>::value - 1; - // compiler bug workaround - typename tuple_element<_Indx, _Uj>::type __t = _VSTD::get<_Indx>(__uj); - return __t; -// return _VSTD::forward<typename tuple_element<_Indx, _Uj>::type>(_VSTD::get<_Indx>(__uj)); -} - -template <class _Ti, class _Uj> -inline _LIBCPP_INLINE_VISIBILITY -typename enable_if -< - !is_bind_expression<_Ti>::value && - is_placeholder<_Ti>::value == 0 && - !__is_reference_wrapper<_Ti>::value, - _Ti& ->::type -__mu(_Ti& __ti, _Uj& __uj) -{ - return __ti; -} - -template <class _Ti, bool IsBindEx, bool IsPh, class _TupleUj> -struct ____mu_return; - -template <class _Ti, class ..._Uj> -struct ____mu_return<_Ti, true, false, tuple<_Uj...> > -{ - typedef typename result_of<_Ti(_Uj...)>::type type; -}; - -template <class _Ti, class _TupleUj> -struct ____mu_return<_Ti, false, true, _TupleUj> -{ - typedef typename tuple_element<is_placeholder<_Ti>::value - 1, - _TupleUj>::type&& type; -}; - -template <class _Ti, class _TupleUj> -struct ____mu_return<_Ti, false, false, _TupleUj> -{ - typedef _Ti& type; -}; - -template <class _Ti, class _TupleUj> -struct __mu_return - : public ____mu_return<_Ti, - is_bind_expression<_Ti>::value, - 0 < is_placeholder<_Ti>::value, - _TupleUj> -{ -}; - -template <class _Ti, class _TupleUj> -struct __mu_return<reference_wrapper<_Ti>, _TupleUj> -{ - typedef _Ti& type; -}; - -template <class _Fp, class _BoundArgs, class _TupleUj> -struct __bind_return; - -template <class _Fp, class ..._BoundArgs, class _TupleUj> -struct __bind_return<_Fp, tuple<_BoundArgs...>, _TupleUj> -{ - typedef typename __ref_return - < - _Fp&, - typename __mu_return - < - _BoundArgs, - _TupleUj - >::type... - >::type type; -}; - -template <class _Fp, class ..._BoundArgs, class _TupleUj> -struct __bind_return<_Fp, const tuple<_BoundArgs...>, _TupleUj> -{ - typedef typename __ref_return - < - _Fp&, - typename __mu_return - < - const _BoundArgs, - _TupleUj - >::type... - >::type type; -}; - -template <class _Fp, class _BoundArgs, size_t ..._Indx, class _Args> -inline _LIBCPP_INLINE_VISIBILITY -typename __bind_return<_Fp, _BoundArgs, _Args>::type -__apply_functor(_Fp& __f, _BoundArgs& __bound_args, __tuple_indices<_Indx...>, - _Args&& __args) -{ - return __invoke(__f, __mu(_VSTD::get<_Indx>(__bound_args), __args)...); -} - -template<class _Fp, class ..._BoundArgs> -class __bind -{ - _Fp __f_; - tuple<_BoundArgs...> __bound_args_; - - typedef typename __make_tuple_indices<sizeof...(_BoundArgs)>::type __indices; -public: - template <class _Gp, class ..._BA> - explicit __bind(_Gp&& __f, _BA&& ...__bound_args) - : __f_(_VSTD::forward<_Gp>(__f)), - __bound_args_(_VSTD::forward<_BA>(__bound_args)...) {} - - template <class ..._Args> - typename __bind_return<_Fp, tuple<_BoundArgs...>, tuple<_Args&&...> >::type - operator()(_Args&& ...__args) - { - // compiler bug workaround - return __apply_functor(__f_, __bound_args_, __indices(), - tuple<_Args&&...>(__args...)); - } - - template <class ..._Args> - typename __bind_return<_Fp, tuple<_BoundArgs...>, tuple<_Args&&...> >::type - operator()(_Args&& ...__args) const - { - return __apply_functor(__f_, __bound_args_, __indices(), - tuple<_Args&&...>(__args...)); - } -}; - -template<class _Fp, class ..._BoundArgs> -struct __is_bind_expression<__bind<_Fp, _BoundArgs...> > : public true_type {}; - -template<class _Rp, class _Fp, class ..._BoundArgs> -class __bind_r - : public __bind<_Fp, _BoundArgs...> -{ - typedef __bind<_Fp, _BoundArgs...> base; -public: - typedef _Rp result_type; - - template <class _Gp, class ..._BA> - explicit __bind_r(_Gp&& __f, _BA&& ...__bound_args) - : base(_VSTD::forward<_Gp>(__f), - _VSTD::forward<_BA>(__bound_args)...) {} - - template <class ..._Args> - result_type - operator()(_Args&& ...__args) - { - typedef __invoke_void_return_wrapper<_Rp> _Invoker; - return _Invoker::__call(static_cast<base&>(*this), _VSTD::forward<_Args>(__args)...); - } - - template <class ..._Args> - result_type - operator()(_Args&& ...__args) const - { - typedef __invoke_void_return_wrapper<_Rp> _Invoker; - return _Invoker::__call(static_cast<base const&>(*this), _VSTD::forward<_Args>(__args)...); - } -}; - -template<class _Rp, class _Fp, class ..._BoundArgs> -struct __is_bind_expression<__bind_r<_Rp, _Fp, _BoundArgs...> > : public true_type {}; - -template<class _Fp, class ..._BoundArgs> -inline _LIBCPP_INLINE_VISIBILITY -__bind<typename decay<_Fp>::type, typename decay<_BoundArgs>::type...> -bind(_Fp&& __f, _BoundArgs&&... __bound_args) -{ - typedef __bind<typename decay<_Fp>::type, typename decay<_BoundArgs>::type...> type; - return type(_VSTD::forward<_Fp>(__f), _VSTD::forward<_BoundArgs>(__bound_args)...); -} - -template<class _Rp, class _Fp, class ..._BoundArgs> -inline _LIBCPP_INLINE_VISIBILITY -__bind_r<_Rp, typename decay<_Fp>::type, typename decay<_BoundArgs>::type...> -bind(_Fp&& __f, _BoundArgs&&... __bound_args) -{ - typedef __bind_r<_Rp, typename decay<_Fp>::type, typename decay<_BoundArgs>::type...> type; - return type(_VSTD::forward<_Fp>(__f), _VSTD::forward<_BoundArgs>(__bound_args)...); -} -*/ - #endif // _LIBCPP_FUNCTIONAL_03 diff --git a/include/__functional_base b/include/__functional_base index 09424bc025a9..52c535aa3ea1 100644 --- a/include/__functional_base +++ b/include/__functional_base @@ -77,62 +77,6 @@ struct _LIBCPP_TYPE_VIS_ONLY less<void> }; #endif -// addressof - -template <class _Tp> -inline _LIBCPP_INLINE_VISIBILITY -_Tp* -addressof(_Tp& __x) _NOEXCEPT -{ - return (_Tp*)&reinterpret_cast<const volatile 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 <class _Tp> -inline _LIBCPP_INLINE_VISIBILITY -__strong _Tp* -addressof(__strong _Tp& __x) _NOEXCEPT -{ - return &__x; -} - -#ifdef _LIBCPP_HAS_OBJC_ARC_WEAK -template <class _Tp> -inline _LIBCPP_INLINE_VISIBILITY -__weak _Tp* -addressof(__weak _Tp& __x) _NOEXCEPT -{ - return &__x; -} -#endif - -template <class _Tp> -inline _LIBCPP_INLINE_VISIBILITY -__autoreleasing _Tp* -addressof(__autoreleasing _Tp& __x) _NOEXCEPT -{ - return &__x; -} - -template <class _Tp> -inline _LIBCPP_INLINE_VISIBILITY -__unsafe_unretained _Tp* -addressof(__unsafe_unretained _Tp& __x) _NOEXCEPT -{ - return &__x; -} -#endif - -#ifdef _LIBCPP_HAS_NO_VARIADICS - -#include <__functional_base_03> - -#else // _LIBCPP_HAS_NO_VARIADICS - // __weak_result_type template <class _Tp> @@ -314,6 +258,8 @@ struct __weak_result_type<_Rp (_Cp::*)(_A1) const volatile> { }; + +#ifndef _LIBCPP_HAS_NO_VARIADICS // 3 or more arguments template <class _Rp, class _A1, class _A2, class _A3, class ..._A4> @@ -358,8 +304,12 @@ struct __weak_result_type<_Rp (_Cp::*)(_A1, _A2, _A3...) const volatile> typedef _Rp result_type; }; +#endif // _LIBCPP_HAS_NO_VARIADICS + // __invoke +#ifndef _LIBCPP_HAS_NO_VARIADICS + // bullets 1 and 2 template <class _Fp, class _A0, class ..._Args, @@ -414,31 +364,79 @@ __invoke(_Fp&& __f, _Args&& ...__args) { return _VSTD::forward<_Fp>(__f)(_VSTD::forward<_Args>(__args)...); } - template <class _Tp, class ..._Args> struct __invoke_return { typedef decltype(__invoke(_VSTD::declval<_Tp>(), _VSTD::declval<_Args>()...)) type; }; +#else // _LIBCPP_HAS_NO_VARIADICS + +#include <__functional_base_03> + +#endif // _LIBCPP_HAS_NO_VARIADICS + + template <class _Ret> struct __invoke_void_return_wrapper { +#ifndef _LIBCPP_HAS_NO_VARIADICS template <class ..._Args> - static _Ret __call(_Args&&... __args) - { + static _Ret __call(_Args&&... __args) { return __invoke(_VSTD::forward<_Args>(__args)...); } +#else + template <class _Fn> + static _Ret __call(_Fn __f) { + return __invoke(__f); + } + + template <class _Fn, class _A0> + static _Ret __call(_Fn __f, _A0& __a0) { + return __invoke(__f, __a0); + } + + template <class _Fn, class _A0, class _A1> + static _Ret __call(_Fn __f, _A0& __a0, _A1& __a1) { + return __invoke(__f, __a0, __a1); + } + + template <class _Fn, class _A0, class _A1, class _A2> + static _Ret __call(_Fn __f, _A0& __a0, _A1& __a1, _A2& __a2){ + return __invoke(__f, __a0, __a1, __a2); + } +#endif }; template <> struct __invoke_void_return_wrapper<void> { +#ifndef _LIBCPP_HAS_NO_VARIADICS template <class ..._Args> - static void __call(_Args&&... __args) - { + static void __call(_Args&&... __args) { __invoke(_VSTD::forward<_Args>(__args)...); } +#else + template <class _Fn> + static void __call(_Fn __f) { + __invoke(__f); + } + + template <class _Fn, class _A0> + static void __call(_Fn __f, _A0& __a0) { + __invoke(__f, __a0); + } + + template <class _Fn, class _A0, class _A1> + static void __call(_Fn __f, _A0& __a0, _A1& __a1) { + __invoke(__f, __a0, __a1); + } + + template <class _Fn, class _A0, class _A1, class _A2> + static void __call(_Fn __f, _A0& __a0, _A1& __a1, _A2& __a2) { + __invoke(__f, __a0, __a1, __a2); + } +#endif }; template <class _Tp> @@ -463,14 +461,120 @@ public: _LIBCPP_INLINE_VISIBILITY operator type& () const _NOEXCEPT {return *__f_;} _LIBCPP_INLINE_VISIBILITY type& get() const _NOEXCEPT {return *__f_;} +#ifndef _LIBCPP_HAS_NO_VARIADICS // invoke template <class... _ArgTypes> - _LIBCPP_INLINE_VISIBILITY - typename __invoke_of<type&, _ArgTypes...>::type - operator() (_ArgTypes&&... __args) const - { - return __invoke(get(), _VSTD::forward<_ArgTypes>(__args)...); - } + _LIBCPP_INLINE_VISIBILITY + typename __invoke_of<type&, _ArgTypes...>::type + operator() (_ArgTypes&&... __args) const { + return __invoke(get(), _VSTD::forward<_ArgTypes>(__args)...); + } +#else + + _LIBCPP_INLINE_VISIBILITY + typename __invoke_return<type>::type + operator() () const { + return __invoke(get()); + } + + template <class _A0> + _LIBCPP_INLINE_VISIBILITY + typename __invoke_return0<type, _A0>::type + operator() (_A0& __a0) const { + return __invoke(get(), __a0); + } + + template <class _A0> + _LIBCPP_INLINE_VISIBILITY + typename __invoke_return0<type, _A0 const>::type + operator() (_A0 const& __a0) const { + return __invoke(get(), __a0); + } + + template <class _A0, class _A1> + _LIBCPP_INLINE_VISIBILITY + typename __invoke_return1<type, _A0, _A1>::type + operator() (_A0& __a0, _A1& __a1) const { + return __invoke(get(), __a0, __a1); + } + + template <class _A0, class _A1> + _LIBCPP_INLINE_VISIBILITY + typename __invoke_return1<type, _A0 const, _A1>::type + operator() (_A0 const& __a0, _A1& __a1) const { + return __invoke(get(), __a0, __a1); + } + + template <class _A0, class _A1> + _LIBCPP_INLINE_VISIBILITY + typename __invoke_return1<type, _A0, _A1 const>::type + operator() (_A0& __a0, _A1 const& __a1) const { + return __invoke(get(), __a0, __a1); + } + + template <class _A0, class _A1> + _LIBCPP_INLINE_VISIBILITY + typename __invoke_return1<type, _A0 const, _A1 const>::type + operator() (_A0 const& __a0, _A1 const& __a1) const { + return __invoke(get(), __a0, __a1); + } + + template <class _A0, class _A1, class _A2> + _LIBCPP_INLINE_VISIBILITY + typename __invoke_return2<type, _A0, _A1, _A2>::type + operator() (_A0& __a0, _A1& __a1, _A2& __a2) const { + return __invoke(get(), __a0, __a1, __a2); + } + + template <class _A0, class _A1, class _A2> + _LIBCPP_INLINE_VISIBILITY + typename __invoke_return2<type, _A0 const, _A1, _A2>::type + operator() (_A0 const& __a0, _A1& __a1, _A2& __a2) const { + return __invoke(get(), __a0, __a1, __a2); + } + + template <class _A0, class _A1, class _A2> + _LIBCPP_INLINE_VISIBILITY + typename __invoke_return2<type, _A0, _A1 const, _A2>::type + operator() (_A0& __a0, _A1 const& __a1, _A2& __a2) const { + return __invoke(get(), __a0, __a1, __a2); + } + + template <class _A0, class _A1, class _A2> + _LIBCPP_INLINE_VISIBILITY + typename __invoke_return2<type, _A0, _A1, _A2 const>::type + operator() (_A0& __a0, _A1& __a1, _A2 const& __a2) const { + return __invoke(get(), __a0, __a1, __a2); + } + + template <class _A0, class _A1, class _A2> + _LIBCPP_INLINE_VISIBILITY + typename __invoke_return2<type, _A0 const, _A1 const, _A2>::type + operator() (_A0 const& __a0, _A1 const& __a1, _A2& __a2) const { + return __invoke(get(), __a0, __a1, __a2); + } + + template <class _A0, class _A1, class _A2> + _LIBCPP_INLINE_VISIBILITY + typename __invoke_return2<type, _A0 const, _A1, _A2 const>::type + operator() (_A0 const& __a0, _A1& __a1, _A2 const& __a2) const { + return __invoke(get(), __a0, __a1, __a2); + } + + template <class _A0, class _A1, class _A2> + _LIBCPP_INLINE_VISIBILITY + typename __invoke_return2<type, _A0, _A1 const, _A2 const>::type + operator() (_A0& __a0, _A1 const& __a1, _A2 const& __a2) const { + return __invoke(get(), __a0, __a1, __a2); + } + + template <class _A0, class _A1, class _A2> + _LIBCPP_INLINE_VISIBILITY + typename __invoke_return2<type, _A0 const, _A1 const, _A2 const>::type + operator() (_A0 const& __a0, _A1 const& __a1, _A2 const& __a2) const { + return __invoke(get(), __a0, __a1, __a2); + } +#endif // _LIBCPP_HAS_NO_VARIADICS }; template <class _Tp> struct __is_reference_wrapper_impl : public false_type {}; @@ -510,6 +614,7 @@ cref(reference_wrapper<_Tp> __t) _NOEXCEPT return cref(__t.get()); } +#ifndef _LIBCPP_HAS_NO_VARIADICS #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES #ifndef _LIBCPP_HAS_NO_DELETED_FUNCTIONS diff --git a/include/__functional_base_03 b/include/__functional_base_03 index 655027786665..8407dcfa39ca 100644 --- a/include/__functional_base_03 +++ b/include/__functional_base_03 @@ -13,943 +13,166 @@ // manual variadic expansion for <functional> -// __weak_result_type - -template <class _Tp> -struct __derives_from_unary_function -{ -private: - struct __two {char __lx; char __lxx;}; - static __two __test(...); - template <class _Ap, class _Rp> - static unary_function<_Ap, _Rp> - __test(const volatile unary_function<_Ap, _Rp>*); -public: - static const bool value = !is_same<decltype(__test((_Tp*)0)), __two>::value; - typedef decltype(__test((_Tp*)0)) type; -}; - -template <class _Tp> -struct __derives_from_binary_function -{ -private: - struct __two {char __lx; char __lxx;}; - static __two __test(...); - template <class _A1, class _A2, class _Rp> - static binary_function<_A1, _A2, _Rp> - __test(const volatile binary_function<_A1, _A2, _Rp>*); -public: - static const bool value = !is_same<decltype(__test((_Tp*)0)), __two>::value; - typedef decltype(__test((_Tp*)0)) type; -}; - -template <class _Tp, bool = __derives_from_unary_function<_Tp>::value> -struct __maybe_derive_from_unary_function // bool is true - : public __derives_from_unary_function<_Tp>::type -{ -}; - -template <class _Tp> -struct __maybe_derive_from_unary_function<_Tp, false> -{ -}; - -template <class _Tp, bool = __derives_from_binary_function<_Tp>::value> -struct __maybe_derive_from_binary_function // bool is true - : public __derives_from_binary_function<_Tp>::type -{ -}; - -template <class _Tp> -struct __maybe_derive_from_binary_function<_Tp, false> -{ -}; - -template <class _Tp, bool = __has_result_type<_Tp>::value> -struct __weak_result_type_imp // bool is true - : public __maybe_derive_from_unary_function<_Tp>, - public __maybe_derive_from_binary_function<_Tp> -{ - typedef typename _Tp::result_type result_type; -}; - -template <class _Tp> -struct __weak_result_type_imp<_Tp, false> - : public __maybe_derive_from_unary_function<_Tp>, - public __maybe_derive_from_binary_function<_Tp> -{ -}; - -template <class _Tp> -struct __weak_result_type - : public __weak_result_type_imp<typename remove_reference<_Tp>::type> -{ -}; - -// 0 argument case - -template <class _Rp> -struct __weak_result_type<_Rp ()> -{ - typedef _Rp result_type; -}; - -template <class _Rp> -struct __weak_result_type<_Rp (&)()> -{ - typedef _Rp result_type; -}; - -template <class _Rp> -struct __weak_result_type<_Rp (*)()> -{ - typedef _Rp result_type; -}; - -// 1 argument case - -template <class _Rp, class _A1> -struct __weak_result_type<_Rp (_A1)> - : public unary_function<_A1, _Rp> -{ -}; - -template <class _Rp, class _A1> -struct __weak_result_type<_Rp (&)(_A1)> - : public unary_function<_A1, _Rp> -{ -}; - -template <class _Rp, class _A1> -struct __weak_result_type<_Rp (*)(_A1)> - : public unary_function<_A1, _Rp> -{ -}; - -template <class _Rp, class _Cp> -struct __weak_result_type<_Rp (_Cp::*)()> - : public unary_function<_Cp*, _Rp> -{ -}; - -template <class _Rp, class _Cp> -struct __weak_result_type<_Rp (_Cp::*)() const> - : public unary_function<const _Cp*, _Rp> -{ -}; - -template <class _Rp, class _Cp> -struct __weak_result_type<_Rp (_Cp::*)() volatile> - : public unary_function<volatile _Cp*, _Rp> -{ -}; - -template <class _Rp, class _Cp> -struct __weak_result_type<_Rp (_Cp::*)() const volatile> - : public unary_function<const volatile _Cp*, _Rp> -{ -}; - -// 2 argument case - -template <class _Rp, class _A1, class _A2> -struct __weak_result_type<_Rp (_A1, _A2)> - : public binary_function<_A1, _A2, _Rp> -{ -}; - -template <class _Rp, class _A1, class _A2> -struct __weak_result_type<_Rp (*)(_A1, _A2)> - : public binary_function<_A1, _A2, _Rp> -{ -}; - -template <class _Rp, class _A1, class _A2> -struct __weak_result_type<_Rp (&)(_A1, _A2)> - : public binary_function<_A1, _A2, _Rp> -{ -}; - -template <class _Rp, class _Cp, class _A1> -struct __weak_result_type<_Rp (_Cp::*)(_A1)> - : public binary_function<_Cp*, _A1, _Rp> -{ -}; - -template <class _Rp, class _Cp, class _A1> -struct __weak_result_type<_Rp (_Cp::*)(_A1) const> - : public binary_function<const _Cp*, _A1, _Rp> -{ -}; - -template <class _Rp, class _Cp, class _A1> -struct __weak_result_type<_Rp (_Cp::*)(_A1) volatile> - : public binary_function<volatile _Cp*, _A1, _Rp> -{ -}; - -template <class _Rp, class _Cp, class _A1> -struct __weak_result_type<_Rp (_Cp::*)(_A1) const volatile> - : public binary_function<const volatile _Cp*, _A1, _Rp> -{ -}; +// __invoke -// 3 or more arguments +template <class _Ret, class _T1, bool _IsFunc, bool _IsBase> +struct __enable_invoke_imp; -template <class _Rp, class _A1, class _A2, class _A3> -struct __weak_result_type<_Rp (_A1, _A2, _A3)> -{ - typedef _Rp result_type; +template <class _Ret, class _T1> +struct __enable_invoke_imp<_Ret, _T1, true, true> { + typedef _Ret _Bullet1; + typedef _Bullet1 type; }; -template <class _Rp, class _A1, class _A2, class _A3> -struct __weak_result_type<_Rp (&)(_A1, _A2, _A3)> -{ - typedef _Rp result_type; +template <class _Ret, class _T1> +struct __enable_invoke_imp<_Ret, _T1, true, false> { + typedef _Ret _Bullet2; + typedef _Bullet2 type; }; -template <class _Rp, class _A1, class _A2, class _A3> -struct __weak_result_type<_Rp (*)(_A1, _A2, _A3)> -{ - typedef _Rp result_type; +template <class _Ret, class _T1> +struct __enable_invoke_imp<_Ret, _T1, false, true> { + typedef typename add_lvalue_reference< + typename __apply_cv<_T1, _Ret>::type + >::type _Bullet3; + typedef _Bullet3 type; }; -template <class _Rp, class _Cp, class _A1, class _A2> -struct __weak_result_type<_Rp (_Cp::*)(_A1, _A2)> -{ - typedef _Rp result_type; +template <class _Ret, class _T1> +struct __enable_invoke_imp<_Ret, _T1, false, false> { + typedef typename add_lvalue_reference< + typename __apply_cv<decltype(*_VSTD::declval<_T1>()), _Ret>::type + >::type _Bullet4; + typedef _Bullet4 type; }; -template <class _Rp, class _Cp, class _A1, class _A2> -struct __weak_result_type<_Rp (_Cp::*)(_A1, _A2) const> -{ - typedef _Rp result_type; +template <class _Ret, class _T1> +struct __enable_invoke_imp<_Ret, _T1*, false, false> { + typedef typename add_lvalue_reference< + typename __apply_cv<_T1, _Ret>::type + >::type _Bullet4; + typedef _Bullet4 type; }; -template <class _Rp, class _Cp, class _A1, class _A2> -struct __weak_result_type<_Rp (_Cp::*)(_A1, _A2) volatile> +template <class _Fn, class _T1, + class _Traits = __member_pointer_traits<_Fn>, + class _Ret = typename _Traits::_ReturnType, + class _Class = typename _Traits::_ClassType> +struct __enable_invoke : __enable_invoke_imp< + _Ret, _T1, + is_member_function_pointer<_Fn>::value, + is_base_of<_Class, typename remove_reference<_T1>::type>::value> { - typedef _Rp result_type; }; -// __invoke - -// __ref_return0 -// -// template <class _Tp, bool _HasResultType> -// struct ________ref_return0 // _HasResultType is true -// { -// typedef typename _Tp::result_type type; -// }; -// -// template <class _Tp> -// struct ________ref_return0<_Tp, false> -// { -// typedef void type; -// }; -// -// template <class _Tp, bool _IsClass> -// struct ____ref_return0 // _IsClass is true -// : public ________ref_return0<_Tp, __has_result_type<typename remove_cv<_Tp>::type>::value> -// { -// }; -// -// template <class _Tp, bool _HasResultType> -// struct ______ref_return0 // _HasResultType is true -// { -// typedef typename __callable_type<_Tp>::result_type type; -// }; -// -// template <class _Tp> -// struct ______ref_return0<_Tp, false> // pointer to member data -// { -// typedef void type; -// }; -// -// template <class _Tp> -// struct ____ref_return0<_Tp, false> -// : public ______ref_return0<typename remove_cv<_Tp>::type, -// __has_result_type<__callable_type<typename remove_cv<_Tp>::type> >::value> -// { -// }; -// -// template <class _Tp> -// struct __ref_return0 -// : public ____ref_return0<typename remove_reference<_Tp>::type, -// is_class<typename remove_reference<_Tp>::type>::value> -// { -// }; -// -// __ref_return1 -// -// template <class _Tp, bool _IsClass, class _A0> -// struct ____ref_return1 // _IsClass is true -// { -// typedef typename result_of<_Tp(_A0)>::type type; -// }; -// -// template <class _Tp, bool _HasResultType, class _A0> -// struct ______ref_return1 // _HasResultType is true -// { -// typedef typename __callable_type<_Tp>::result_type type; -// }; -// -// template <class _Tp, class _A0, bool> -// struct __ref_return1_member_data1; -// -// template <class _Rp, class _Cp, class _A0> -// struct __ref_return1_member_data1<_Rp _Cp::*, _A0, true> -// { -// typedef typename __apply_cv<_A0, _Rp>::type& type; -// }; -// -// template <class _Rp, class _Cp, class _A0> -// struct __ref_return1_member_data1<_Rp _Cp::*, _A0, false> -// { -// static _A0 __a; -// typedef typename __apply_cv<decltype(*__a), _Rp>::type& type; -// }; -// -// template <class _Tp, class _A0> -// struct __ref_return1_member_data; -// -// template <class _Rp, class _Cp, class _A0> -// struct __ref_return1_member_data<_Rp _Cp::*, _A0> -// : public __ref_return1_member_data1<_Rp _Cp::*, _A0, -// is_same<typename remove_cv<_Cp>::type, -// typename remove_cv<typename remove_reference<_A0>::type>::type>::value> -// { -// }; -// -// template <class _Tp, class _A0> -// struct ______ref_return1<_Tp, false, _A0> // pointer to member data -// : public __ref_return1_member_data<typename remove_cv<_Tp>::type, _A0> -// { -// }; -// -// template <class _Tp, class _A0> -// struct ____ref_return1<_Tp, false, _A0> -// : public ______ref_return1<typename remove_cv<_Tp>::type, -// __has_result_type<__callable_type<typename remove_cv<_Tp>::type> >::value, _A0> -// { -// }; -// -// template <class _Tp, class _A0> -// struct __ref_return1 -// : public ____ref_return1<typename remove_reference<_Tp>::type, -// is_class<typename remove_reference<_Tp>::type>::value, _A0> -// { -// }; -// -// __ref_return2 -// -// template <class _Tp, bool _IsClass, class _A0, class _A1> -// struct ____ref_return2 // _IsClass is true -// { -// typedef typename result_of<_Tp(_A0, _A1)>::type type; -// }; -// -// template <class _Tp, bool _HasResultType, class _A0, class _A1> -// struct ______ref_return2 // _HasResultType is true -// { -// typedef typename __callable_type<_Tp>::result_type type; -// }; -// -// template <class _Tp> -// struct ______ref_return2<_Tp, false, class _A0, class _A1> // pointer to member data -// { -// static_assert(sizeof(_Tp) == 0, "An attempt has been made to `call` a pointer" -// " to member data with too many arguments."); -// }; -// -// template <class _Tp, class _A0, class _A1> -// struct ____ref_return2<_Tp, false, _A0, _A1> -// : public ______ref_return2<typename remove_cv<_Tp>::type, -// __has_result_type<__callable_type<typename remove_cv<_Tp>::type> >::value, _A0, _A1> -// { -// }; -// -// template <class _Tp, class _A0, class _A1> -// struct __ref_return2 -// : public ____ref_return2<typename remove_reference<_Tp>::type, -// is_class<typename remove_reference<_Tp>::type>::value, _A0, _A1> -// { -// }; -// -// __ref_return3 -// -// template <class _Tp, bool _IsClass, class _A0, class _A1, class _A2> -// struct ____ref_return3 // _IsClass is true -// { -// typedef typename result_of<_Tp(_A0, _A1, _A2)>::type type; -// }; -// -// template <class _Tp, bool _HasResultType, class _A0, class _A1, class _A2> -// struct ______ref_return3 // _HasResultType is true -// { -// typedef typename __callable_type<_Tp>::result_type type; -// }; -// -// template <class _Tp> -// struct ______ref_return3<_Tp, false, class _A0, class _A1, class _A2> // pointer to member data -// { -// static_assert(sizeof(_Tp) == 0, "An attempt has been made to `call` a pointer" -// " to member data with too many arguments."); -// }; -// -// template <class _Tp, class _A0, class _A1, class _A2> -// struct ____ref_return3<_Tp, false, _A0, _A1, _A2> -// : public ______ref_return3<typename remove_cv<_Tp>::type, -// __has_result_type<__callable_type<typename remove_cv<_Tp>::type> >::value, _A0, _A1, _A2> -// { -// }; -// -// template <class _Tp, class _A0, class _A1, class _A2> -// struct __ref_return3 -// : public ____ref_return3<typename remove_reference<_Tp>::type, -// is_class<typename remove_reference<_Tp>::type>::value, _A0, _A1, _A2> -// { -// }; +__nat __invoke(__any, ...); // first bullet -template <class _Rp, class _Tp, class _T1> -inline _LIBCPP_INLINE_VISIBILITY -typename enable_if -< - is_base_of<_Tp, typename remove_reference<_T1>::type>::value, - _Rp ->::type -__invoke(_Rp (_Tp::*__f)(), _T1& __t1) -{ - return (__t1.*__f)(); -} - -template <class _Rp, class _Tp, class _T1, class _A0> -inline _LIBCPP_INLINE_VISIBILITY -typename enable_if -< - is_base_of<_Tp, typename remove_reference<_T1>::type>::value, - _Rp ->::type -__invoke(_Rp (_Tp::*__f)(_A0), _T1& __t1, _A0& __a0) -{ - return (__t1.*__f)(__a0); -} - -template <class _Rp, class _Tp, class _T1, class _A0, class _A1> -inline _LIBCPP_INLINE_VISIBILITY -typename enable_if -< - is_base_of<_Tp, typename remove_reference<_T1>::type>::value, - _Rp ->::type -__invoke(_Rp (_Tp::*__f)(_A0, _A1), _T1& __t1, _A0& __a0, _A1& __a1) -{ - return (__t1.*__f)(__a0, __a1); -} - -template <class _Rp, class _Tp, class _T1, class _A0, class _A1, class _A2> -inline _LIBCPP_INLINE_VISIBILITY -typename enable_if -< - is_base_of<_Tp, typename remove_reference<_T1>::type>::value, - _Rp ->::type -__invoke(_Rp (_Tp::*__f)(_A0, _A1, _A2), _T1& __t1, _A0& __a0, _A1& __a1, _A2& __a2) -{ - return (__t1.*__f)(__a0, __a1, __a2); -} - -template <class _Rp, class _Tp, class _T1> -inline _LIBCPP_INLINE_VISIBILITY -typename enable_if -< - is_base_of<_Tp, typename remove_reference<_T1>::type>::value, - _Rp ->::type -__invoke(_Rp (_Tp::*__f)() const, _T1& __t1) -{ - return (__t1.*__f)(); -} - -template <class _Rp, class _Tp, class _T1, class _A0> -inline _LIBCPP_INLINE_VISIBILITY -typename enable_if -< - is_base_of<_Tp, typename remove_reference<_T1>::type>::value, - _Rp ->::type -__invoke(_Rp (_Tp::*__f)(_A0) const, _T1& __t1, _A0& __a0) -{ - return (__t1.*__f)(__a0); -} - -template <class _Rp, class _Tp, class _T1, class _A0, class _A1> -inline _LIBCPP_INLINE_VISIBILITY -typename enable_if -< - is_base_of<_Tp, typename remove_reference<_T1>::type>::value, - _Rp ->::type -__invoke(_Rp (_Tp::*__f)(_A0, _A1) const, _T1& __t1, _A0& __a0, _A1& __a1) -{ - return (__t1.*__f)(__a0, __a1); -} - -template <class _Rp, class _Tp, class _T1, class _A0, class _A1, class _A2> -inline _LIBCPP_INLINE_VISIBILITY -typename enable_if -< - is_base_of<_Tp, typename remove_reference<_T1>::type>::value, - _Rp ->::type -__invoke(_Rp (_Tp::*__f)(_A0, _A1, _A2) const, _T1& __t1, _A0& __a0, _A1& __a1, _A2& __a2) -{ - return (__t1.*__f)(__a0, __a1, __a2); -} - -template <class _Rp, class _Tp, class _T1> -inline _LIBCPP_INLINE_VISIBILITY -typename enable_if -< - is_base_of<_Tp, typename remove_reference<_T1>::type>::value, - _Rp ->::type -__invoke(_Rp (_Tp::*__f)() volatile, _T1& __t1) -{ - return (__t1.*__f)(); -} - -template <class _Rp, class _Tp, class _T1, class _A0> -inline _LIBCPP_INLINE_VISIBILITY -typename enable_if -< - is_base_of<_Tp, typename remove_reference<_T1>::type>::value, - _Rp ->::type -__invoke(_Rp (_Tp::*__f)(_A0) volatile, _T1& __t1, _A0& __a0) -{ - return (__t1.*__f)(__a0); -} - -template <class _Rp, class _Tp, class _T1, class _A0, class _A1> -inline _LIBCPP_INLINE_VISIBILITY -typename enable_if -< - is_base_of<_Tp, typename remove_reference<_T1>::type>::value, - _Rp ->::type -__invoke(_Rp (_Tp::*__f)(_A0, _A1) volatile, _T1& __t1, _A0& __a0, _A1& __a1) -{ - return (__t1.*__f)(__a0, __a1); -} - -template <class _Rp, class _Tp, class _T1, class _A0, class _A1, class _A2> -inline _LIBCPP_INLINE_VISIBILITY -typename enable_if -< - is_base_of<_Tp, typename remove_reference<_T1>::type>::value, - _Rp ->::type -__invoke(_Rp (_Tp::*__f)(_A0, _A1, _A2) volatile, _T1& __t1, _A0& __a0, _A1& __a1, _A2& __a2) -{ - return (__t1.*__f)(__a0, __a1, __a2); -} - -template <class _Rp, class _Tp, class _T1> +template <class _Fn, class _T1> inline _LIBCPP_INLINE_VISIBILITY -typename enable_if -< - is_base_of<_Tp, typename remove_reference<_T1>::type>::value, - _Rp ->::type -__invoke(_Rp (_Tp::*__f)() const volatile, _T1& __t1) -{ +typename __enable_invoke<_Fn, _T1>::_Bullet1 +__invoke(_Fn __f, _T1& __t1) { return (__t1.*__f)(); } -template <class _Rp, class _Tp, class _T1, class _A0> +template <class _Fn, class _T1, class _A0> inline _LIBCPP_INLINE_VISIBILITY -typename enable_if -< - is_base_of<_Tp, typename remove_reference<_T1>::type>::value, - _Rp ->::type -__invoke(_Rp (_Tp::*__f)(_A0) const volatile, _T1& __t1, _A0& __a0) -{ +typename __enable_invoke<_Fn, _T1>::_Bullet1 +__invoke(_Fn __f, _T1& __t1, _A0& __a0) { return (__t1.*__f)(__a0); } -template <class _Rp, class _Tp, class _T1, class _A0, class _A1> +template <class _Fn, class _T1, class _A0, class _A1> inline _LIBCPP_INLINE_VISIBILITY -typename enable_if -< - is_base_of<_Tp, typename remove_reference<_T1>::type>::value, - _Rp ->::type -__invoke(_Rp (_Tp::*__f)(_A0, _A1) const volatile, _T1& __t1, _A0& __a0, _A1& __a1) -{ +typename __enable_invoke<_Fn, _T1>::_Bullet1 +__invoke(_Fn __f, _T1& __t1, _A0& __a0, _A1& __a1) { return (__t1.*__f)(__a0, __a1); } -template <class _Rp, class _Tp, class _T1, class _A0, class _A1, class _A2> +template <class _Fn, class _T1, class _A0, class _A1, class _A2> inline _LIBCPP_INLINE_VISIBILITY -typename enable_if -< - is_base_of<_Tp, typename remove_reference<_T1>::type>::value, - _Rp ->::type -__invoke(_Rp (_Tp::*__f)(_A0, _A1, _A2) const volatile, _T1& __t1, _A0& __a0, _A1& __a1, _A2& __a2) -{ +typename __enable_invoke<_Fn, _T1>::_Bullet1 +__invoke(_Fn __f, _T1& __t1, _A0& __a0, _A1& __a1, _A2& __a2) { return (__t1.*__f)(__a0, __a1, __a2); } -// second bullet - -template <class _Rp, class _Tp, class _T1> -inline _LIBCPP_INLINE_VISIBILITY -typename enable_if -< - !is_base_of<_Tp, typename remove_reference<_T1>::type>::value, - _Rp ->::type -__invoke(_Rp (_Tp::*__f)(), _T1 __t1) -{ - return ((*__t1).*__f)(); -} - -template <class _Rp, class _Tp, class _T1, class _A0> -inline _LIBCPP_INLINE_VISIBILITY -typename enable_if -< - !is_base_of<_Tp, typename remove_reference<_T1>::type>::value, - _Rp ->::type -__invoke(_Rp (_Tp::*__f)(_A0), _T1 __t1, _A0& __a0) -{ - return ((*__t1).*__f)(__a0); -} - -template <class _Rp, class _Tp, class _T1, class _A0, class _A1> -inline _LIBCPP_INLINE_VISIBILITY -typename enable_if -< - !is_base_of<_Tp, typename remove_reference<_T1>::type>::value, - _Rp ->::type -__invoke(_Rp (_Tp::*__f)(_A0, _A1), _T1 __t1, _A0& __a0, _A1& __a1) -{ - return ((*__t1).*__f)(__a0, __a1); -} - -template <class _Rp, class _Tp, class _T1, class _A0, class _A1, class _A2> -inline _LIBCPP_INLINE_VISIBILITY -typename enable_if -< - !is_base_of<_Tp, typename remove_reference<_T1>::type>::value, - _Rp ->::type -__invoke(_Rp (_Tp::*__f)(_A0, _A1, _A2), _T1 __t1, _A0& __a0, _A1& __a1, _A2& __a2) -{ - return ((*__t1).*__f)(__a0, __a1, __a2); -} - -template <class _Rp, class _Tp, class _T1> -inline _LIBCPP_INLINE_VISIBILITY -typename enable_if -< - !is_base_of<_Tp, typename remove_reference<_T1>::type>::value, - _Rp ->::type -__invoke(_Rp (_Tp::*__f)() const, _T1 __t1) -{ - return ((*__t1).*__f)(); -} - -template <class _Rp, class _Tp, class _T1, class _A0> -inline _LIBCPP_INLINE_VISIBILITY -typename enable_if -< - !is_base_of<_Tp, typename remove_reference<_T1>::type>::value, - _Rp ->::type -__invoke(_Rp (_Tp::*__f)(_A0) const, _T1 __t1, _A0& __a0) -{ - return ((*__t1).*__f)(__a0); -} - -template <class _Rp, class _Tp, class _T1, class _A0, class _A1> -inline _LIBCPP_INLINE_VISIBILITY -typename enable_if -< - !is_base_of<_Tp, typename remove_reference<_T1>::type>::value, - _Rp ->::type -__invoke(_Rp (_Tp::*__f)(_A0, _A1) const, _T1 __t1, _A0& __a0, _A1& __a1) -{ - return ((*__t1).*__f)(__a0, __a1); -} - -template <class _Rp, class _Tp, class _T1, class _A0, class _A1, class _A2> -inline _LIBCPP_INLINE_VISIBILITY -typename enable_if -< - !is_base_of<_Tp, typename remove_reference<_T1>::type>::value, - _Rp ->::type -__invoke(_Rp (_Tp::*__f)(_A0, _A1, _A2) const, _T1 __t1, _A0& __a0, _A1& __a1, _A2& __a2) -{ - return ((*__t1).*__f)(__a0, __a1, __a2); -} - -template <class _Rp, class _Tp, class _T1> -inline _LIBCPP_INLINE_VISIBILITY -typename enable_if -< - !is_base_of<_Tp, typename remove_reference<_T1>::type>::value, - _Rp ->::type -__invoke(_Rp (_Tp::*__f)() volatile, _T1 __t1) -{ - return ((*__t1).*__f)(); -} - -template <class _Rp, class _Tp, class _T1, class _A0> -inline _LIBCPP_INLINE_VISIBILITY -typename enable_if -< - !is_base_of<_Tp, typename remove_reference<_T1>::type>::value, - _Rp ->::type -__invoke(_Rp (_Tp::*__f)(_A0) volatile, _T1 __t1, _A0& __a0) -{ - return ((*__t1).*__f)(__a0); -} - -template <class _Rp, class _Tp, class _T1, class _A0, class _A1> -inline _LIBCPP_INLINE_VISIBILITY -typename enable_if -< - !is_base_of<_Tp, typename remove_reference<_T1>::type>::value, - _Rp ->::type -__invoke(_Rp (_Tp::*__f)(_A0, _A1) volatile, _T1 __t1, _A0& __a0, _A1& __a1) -{ - return ((*__t1).*__f)(__a0, __a1); -} - -template <class _Rp, class _Tp, class _T1, class _A0, class _A1, class _A2> -inline _LIBCPP_INLINE_VISIBILITY -typename enable_if -< - !is_base_of<_Tp, typename remove_reference<_T1>::type>::value, - _Rp ->::type -__invoke(_Rp (_Tp::*__f)(_A0, _A1, _A2) volatile, _T1 __t1, _A0& __a0, _A1& __a1, _A2& __a2) -{ - return ((*__t1).*__f)(__a0, __a1, __a2); -} - -template <class _Rp, class _Tp, class _T1> +template <class _Fn, class _T1> inline _LIBCPP_INLINE_VISIBILITY -typename enable_if -< - !is_base_of<_Tp, typename remove_reference<_T1>::type>::value, - _Rp ->::type -__invoke(_Rp (_Tp::*__f)() const volatile, _T1 __t1) -{ +typename __enable_invoke<_Fn, _T1>::_Bullet2 +__invoke(_Fn __f, _T1& __t1) { return ((*__t1).*__f)(); } -template <class _Rp, class _Tp, class _T1, class _A0> +template <class _Fn, class _T1, class _A0> inline _LIBCPP_INLINE_VISIBILITY -typename enable_if -< - !is_base_of<_Tp, typename remove_reference<_T1>::type>::value, - _Rp ->::type -__invoke(_Rp (_Tp::*__f)(_A0) const volatile, _T1 __t1, _A0& __a0) -{ +typename __enable_invoke<_Fn, _T1>::_Bullet2 +__invoke(_Fn __f, _T1& __t1, _A0& __a0) { return ((*__t1).*__f)(__a0); } -template <class _Rp, class _Tp, class _T1, class _A0, class _A1> +template <class _Fn, class _T1, class _A0, class _A1> inline _LIBCPP_INLINE_VISIBILITY -typename enable_if -< - !is_base_of<_Tp, typename remove_reference<_T1>::type>::value, - _Rp ->::type -__invoke(_Rp (_Tp::*__f)(_A0, _A1) const volatile, _T1 __t1, _A0& __a0, _A1& __a1) -{ +typename __enable_invoke<_Fn, _T1>::_Bullet2 +__invoke(_Fn __f, _T1& __t1, _A0& __a0, _A1& __a1) { return ((*__t1).*__f)(__a0, __a1); } -template <class _Rp, class _Tp, class _T1, class _A0, class _A1, class _A2> +template <class _Fn, class _T1, class _A0, class _A1, class _A2> inline _LIBCPP_INLINE_VISIBILITY -typename enable_if -< - !is_base_of<_Tp, typename remove_reference<_T1>::type>::value, - _Rp ->::type -__invoke(_Rp (_Tp::*__f)(_A0, _A1, _A2) const volatile, _T1 __t1, _A0& __a0, _A1& __a1, _A2& __a2) -{ +typename __enable_invoke<_Fn, _T1>::_Bullet2 +__invoke(_Fn __f, _T1& __t1, _A0& __a0, _A1& __a1, _A2& __a2) { return ((*__t1).*__f)(__a0, __a1, __a2); } -// third bullet - -template <class _Rp, class _Tp, class _T1> +template <class _Fn, class _T1> inline _LIBCPP_INLINE_VISIBILITY -typename enable_if -< - is_base_of<_Tp, typename remove_reference<_T1>::type>::value, - typename __apply_cv<_T1, _Rp>::type& ->::type -__invoke(_Rp _Tp::* __f, _T1& __t1) -{ +typename __enable_invoke<_Fn, _T1>::_Bullet3 +__invoke(_Fn __f, _T1& __t1) { return __t1.*__f; } -template <class _Rp, class _Tp> -inline _LIBCPP_INLINE_VISIBILITY -void -__invoke(_Rp _Tp::*) -{ -} - -// template <class _Dp, class _Rp, class _Tp, class _T1> -// inline _LIBCPP_INLINE_VISIBILITY -// typename enable_if -// < -// is_base_of<_Tp, typename remove_reference<_T1>::type>::value, -// typename __ref_return1<_Rp _Tp::*, _T1>::type -// >::type -// __invoke(_Rp _Tp::* __f, _T1& __t1) -// { -// return __t1.*__f; -// } - -// forth bullet - -template <class _T1, class _Rp, bool> -struct __4th_helper -{ -}; - -template <class _T1, class _Rp> -struct __4th_helper<_T1, _Rp, true> -{ - typedef typename __apply_cv<decltype(*_VSTD::declval<_T1>()), _Rp>::type type; -}; - -template <class _Rp, class _Tp, class _T1> +template <class _Fn, class _T1> inline _LIBCPP_INLINE_VISIBILITY -typename __4th_helper<_T1, _Rp, - !is_base_of<_Tp, - typename remove_reference<_T1>::type - >::value - >::type& -__invoke(_Rp _Tp::* __f, _T1& __t1) -{ +typename __enable_invoke<_Fn, _T1>::_Bullet4 +__invoke(_Fn __f, _T1& __t1) { return (*__t1).*__f; } -// template <class _Dp, class _Rp, class _Tp, class _T1> -// inline _LIBCPP_INLINE_VISIBILITY -// typename enable_if -// < -// !is_base_of<_Tp, typename remove_reference<_T1>::type>::value, -// typename __ref_return1<_Rp _Tp::*, _T1>::type -// >::type -// __invoke(_Rp _Tp::* __f, _T1 __t1) -// { -// return (*__t1).*__f; -// } - // fifth bullet template <class _Fp> inline _LIBCPP_INLINE_VISIBILITY -decltype(declval<_Fp>()()) -__invoke(_Fp __f) +decltype(_VSTD::declval<_Fp&>()()) +__invoke(_Fp& __f) { return __f(); } template <class _Fp, class _A0> inline _LIBCPP_INLINE_VISIBILITY -decltype(declval<_Fp>()(declval<_A0&>())) -__invoke(_Fp __f, _A0& __a0) +decltype(_VSTD::declval<_Fp&>()(_VSTD::declval<_A0&>())) +__invoke(_Fp& __f, _A0& __a0) { return __f(__a0); } template <class _Fp, class _A0, class _A1> inline _LIBCPP_INLINE_VISIBILITY -decltype(declval<_Fp>()(declval<_A0&>(), declval<_A1&>())) -__invoke(_Fp __f, _A0& __a0, _A1& __a1) +decltype(_VSTD::declval<_Fp&>()(_VSTD::declval<_A0&>(), _VSTD::declval<_A1&>())) +__invoke(_Fp& __f, _A0& __a0, _A1& __a1) { return __f(__a0, __a1); } template <class _Fp, class _A0, class _A1, class _A2> inline _LIBCPP_INLINE_VISIBILITY -decltype(declval<_Fp>()(declval<_A0&>(), declval<_A1&>(), declval<_A2&>())) -__invoke(_Fp __f, _A0& __a0, _A1& __a1, _A2& __a2) +decltype(_VSTD::declval<_Fp&>()(_VSTD::declval<_A0&>(), _VSTD::declval<_A1&>(), _VSTD::declval<_A2&>())) +__invoke(_Fp& __f, _A0& __a0, _A1& __a1, _A2& __a2) { return __f(__a0, __a1, __a2); } -// template <class _Rp, class _Fp> -// inline _LIBCPP_INLINE_VISIBILITY -// _Rp -// __invoke(_Fp& __f) -// { -// return __f(); -// } -// -// template <class _Rp, class _Fp, class _A0> -// inline _LIBCPP_INLINE_VISIBILITY -// typename enable_if -// < -// !is_member_pointer<_Fp>::value, -// _Rp -// >::type -// __invoke(_Fp& __f, _A0& __a0) -// { -// return __f(__a0); -// } -// -// template <class _Rp, class _Fp, class _A0, class _A1> -// inline _LIBCPP_INLINE_VISIBILITY -// _Rp -// __invoke(_Fp& __f, _A0& __a0, _A1& __a1) -// { -// return __f(__a0, __a1); -// } -// -// template <class _Rp, class _Fp, class _A0, class _A1, class _A2> -// inline _LIBCPP_INLINE_VISIBILITY -// _Rp -// __invoke(_Fp& __f, _A0& __a0, _A1& __a1, _A2& __a2) -// { -// return __f(__a0, __a1, __a2); -// } - -template <class _Tp> -struct __has_type -{ -private: - struct __two {char __lx; char __lxx;}; - template <class _Up> static __two __test(...); - template <class _Up> static char __test(typename _Up::type* = 0); -public: - static const bool value = sizeof(__test<_Tp>(0)) == 1; -}; - template <class _Fp, bool = __has_result_type<__weak_result_type<_Fp> >::value> struct __invoke_return { @@ -959,186 +182,43 @@ struct __invoke_return template <class _Fp> struct __invoke_return<_Fp, false> { - typedef decltype(__invoke(_VSTD::declval<_Fp>())) type; + typedef decltype(__invoke(_VSTD::declval<_Fp&>())) type; }; template <class _Tp, class _A0> struct __invoke_return0 { - typedef decltype(__invoke(_VSTD::declval<_Tp>(), _VSTD::declval<_A0>())) type; + typedef decltype(__invoke(_VSTD::declval<_Tp&>(), _VSTD::declval<_A0&>())) type; }; template <class _Rp, class _Tp, class _A0> struct __invoke_return0<_Rp _Tp::*, _A0> { - typedef typename __apply_cv<_A0, _Rp>::type& type; -}; - -template <class _Rp, class _Tp, class _A0> -struct __invoke_return0<_Rp _Tp::*, _A0*> -{ - typedef typename __apply_cv<_A0, _Rp>::type& type; + typedef typename __enable_invoke<_Rp _Tp::*, _A0>::type type; }; template <class _Tp, class _A0, class _A1> struct __invoke_return1 { - typedef decltype(__invoke(_VSTD::declval<_Tp>(), _VSTD::declval<_A0>(), - _VSTD::declval<_A1>())) type; + typedef decltype(__invoke(_VSTD::declval<_Tp&>(), _VSTD::declval<_A0&>(), + _VSTD::declval<_A1&>())) type; }; -template <class _Tp, class _A0, class _A1, class _A2> -struct __invoke_return2 -{ - typedef decltype(__invoke(_VSTD::declval<_Tp>(), _VSTD::declval<_A0>(), - _VSTD::declval<_A1>(), - _VSTD::declval<_A2>())) type; +template <class _Rp, class _Class, class _A0, class _A1> +struct __invoke_return1<_Rp _Class::*, _A0, _A1> { + typedef typename __enable_invoke<_Rp _Class::*, _A0>::type type; }; -template <class _Ret> -struct __invoke_void_return_wrapper +template <class _Tp, class _A0, class _A1, class _A2> +struct __invoke_return2 { - template <class _Fn> - static _Ret __call(_Fn __f) - { - return __invoke(__f); - } - - template <class _Fn, class _A0> - static _Ret __call(_Fn __f, _A0& __a0) - { - return __invoke(__f, __a0); - } - - template <class _Fn, class _A0, class _A1> - static _Ret __call(_Fn __f, _A0& __a0, _A1& __a1) - { - return __invoke(__f, __a0, __a1); - } - - template <class _Fn, class _A0, class _A1, class _A2> - static _Ret __call(_Fn __f, _A0& __a0, _A1& __a1, _A2& __a2) - { - return __invoke(__f, __a0, __a1, __a2); - } + typedef decltype(__invoke(_VSTD::declval<_Tp&>(), _VSTD::declval<_A0&>(), + _VSTD::declval<_A1&>(), + _VSTD::declval<_A2&>())) type; }; - -template <> -struct __invoke_void_return_wrapper<void> -{ - template <class _Fn> - static void __call(_Fn __f) - { - __invoke(__f); - } - - template <class _Fn, class _A0> - static void __call(_Fn __f, _A0& __a0) - { - __invoke(__f, __a0); - } - - template <class _Fn, class _A0, class _A1> - static void __call(_Fn __f, _A0& __a0, _A1& __a1) - { - __invoke(__f, __a0, __a1); - } - - template <class _Fn, class _A0, class _A1, class _A2> - static void __call(_Fn __f, _A0& __a0, _A1& __a1, _A2& __a2) - { - __invoke(__f, __a0, __a1, __a2); - } +template <class _Ret, class _Class, class _A0, class _A1, class _A2> +struct __invoke_return2<_Ret _Class::*, _A0, _A1, _A2> { + typedef typename __enable_invoke<_Ret _Class::*, _A0>::type type; }; - -template <class _Tp> -class _LIBCPP_TYPE_VIS_ONLY reference_wrapper - : public __weak_result_type<_Tp> -{ -public: - // types - typedef _Tp type; -private: - type* __f_; - -public: - // construct/copy/destroy - _LIBCPP_INLINE_VISIBILITY reference_wrapper(type& __f) : __f_(&__f) {} - - // access - _LIBCPP_INLINE_VISIBILITY operator type& () const {return *__f_;} - _LIBCPP_INLINE_VISIBILITY type& get() const {return *__f_;} - - // invoke - - _LIBCPP_INLINE_VISIBILITY - typename __invoke_return<type&>::type - operator() () const - { - return __invoke(get()); - } - - template <class _A0> - _LIBCPP_INLINE_VISIBILITY - typename __invoke_return0<type&, _A0>::type - operator() (_A0& __a0) const - { - return __invoke<type&, _A0>(get(), __a0); - } - - template <class _A0, class _A1> - _LIBCPP_INLINE_VISIBILITY - typename __invoke_return1<type&, _A0, _A1>::type - operator() (_A0& __a0, _A1& __a1) const - { - return __invoke<type&, _A0, _A1>(get(), __a0, __a1); - } - - template <class _A0, class _A1, class _A2> - _LIBCPP_INLINE_VISIBILITY - typename __invoke_return2<type&, _A0, _A1, _A2>::type - operator() (_A0& __a0, _A1& __a1, _A2& __a2) const - { - return __invoke<type&, _A0, _A1, _A2>(get(), __a0, __a1, __a2); - } -}; - -template <class _Tp> struct __is_reference_wrapper_impl : public false_type {}; -template <class _Tp> struct __is_reference_wrapper_impl<reference_wrapper<_Tp> > : public true_type {}; -template <class _Tp> struct __is_reference_wrapper - : public __is_reference_wrapper_impl<typename remove_cv<_Tp>::type> {}; - -template <class _Tp> -inline _LIBCPP_INLINE_VISIBILITY -reference_wrapper<_Tp> -ref(_Tp& __t) -{ - return reference_wrapper<_Tp>(__t); -} - -template <class _Tp> -inline _LIBCPP_INLINE_VISIBILITY -reference_wrapper<_Tp> -ref(reference_wrapper<_Tp> __t) -{ - return ref(__t.get()); -} - -template <class _Tp> -inline _LIBCPP_INLINE_VISIBILITY -reference_wrapper<const _Tp> -cref(const _Tp& __t) -{ - return reference_wrapper<const _Tp>(__t); -} - -template <class _Tp> -inline _LIBCPP_INLINE_VISIBILITY -reference_wrapper<const _Tp> -cref(reference_wrapper<_Tp> __t) -{ - return cref(__t.get()); -} - #endif // _LIBCPP_FUNCTIONAL_BASE_03 diff --git a/include/__hash_table b/include/__hash_table index f3a20309df71..cfa763ab217a 100644 --- a/include/__hash_table +++ b/include/__hash_table @@ -836,6 +836,7 @@ public: typedef __hash_local_iterator<__node_pointer> local_iterator; typedef __hash_const_local_iterator<__node_pointer> const_local_iterator; + _LIBCPP_INLINE_VISIBILITY __hash_table() _NOEXCEPT_( is_nothrow_default_constructible<__bucket_list>::value && @@ -843,6 +844,7 @@ public: is_nothrow_default_constructible<__node_allocator>::value && is_nothrow_default_constructible<hasher>::value && is_nothrow_default_constructible<key_equal>::value); + _LIBCPP_INLINE_VISIBILITY __hash_table(const hasher& __hf, const key_equal& __eql); __hash_table(const hasher& __hf, const key_equal& __eql, const allocator_type& __a); @@ -863,6 +865,7 @@ public: __hash_table& operator=(const __hash_table& __u); #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + _LIBCPP_INLINE_VISIBILITY __hash_table& operator=(__hash_table&& __u) _NOEXCEPT_( __node_traits::propagate_on_container_move_assignment::value && @@ -934,9 +937,13 @@ public: return __bucket_list_.get_deleter().size(); } + _LIBCPP_INLINE_VISIBILITY iterator begin() _NOEXCEPT; + _LIBCPP_INLINE_VISIBILITY iterator end() _NOEXCEPT; + _LIBCPP_INLINE_VISIBILITY const_iterator begin() const _NOEXCEPT; + _LIBCPP_INLINE_VISIBILITY const_iterator end() const _NOEXCEPT; template <class _Key> @@ -965,6 +972,7 @@ public: __node_holder remove(const_iterator __p) _NOEXCEPT; template <class _Key> + _LIBCPP_INLINE_VISIBILITY size_type __count_unique(const _Key& __k) const; template <class _Key> size_type __count_multi(const _Key& __k) const; @@ -984,15 +992,17 @@ public: __equal_range_multi(const _Key& __k) const; void swap(__hash_table& __u) +#if _LIBCPP_STD_VER <= 11 _NOEXCEPT_( __is_nothrow_swappable<hasher>::value && __is_nothrow_swappable<key_equal>::value -#if _LIBCPP_STD_VER <= 11 && (!allocator_traits<__pointer_allocator>::propagate_on_container_swap::value || __is_nothrow_swappable<__pointer_allocator>::value) && (!__node_traits::propagate_on_container_swap::value || __is_nothrow_swappable<__node_allocator>::value) -#endif ); +#else + _NOEXCEPT_(__is_nothrow_swappable<hasher>::value && __is_nothrow_swappable<key_equal>::value); +#endif _LIBCPP_INLINE_VISIBILITY size_type max_bucket_count() const _NOEXCEPT @@ -1128,11 +1138,12 @@ private: }; template <class _Tp, class _Hash, class _Equal, class _Alloc> -inline _LIBCPP_INLINE_VISIBILITY +inline __hash_table<_Tp, _Hash, _Equal, _Alloc>::__hash_table() _NOEXCEPT_( is_nothrow_default_constructible<__bucket_list>::value && is_nothrow_default_constructible<__first_node>::value && + is_nothrow_default_constructible<__node_allocator>::value && is_nothrow_default_constructible<hasher>::value && is_nothrow_default_constructible<key_equal>::value) : __p2_(0), @@ -1141,7 +1152,7 @@ __hash_table<_Tp, _Hash, _Equal, _Alloc>::__hash_table() } template <class _Tp, class _Hash, class _Equal, class _Alloc> -inline _LIBCPP_INLINE_VISIBILITY +inline __hash_table<_Tp, _Hash, _Equal, _Alloc>::__hash_table(const hasher& __hf, const key_equal& __eql) : __bucket_list_(nullptr, __bucket_list_deleter()), @@ -1201,6 +1212,7 @@ __hash_table<_Tp, _Hash, _Equal, _Alloc>::__hash_table(__hash_table&& __u) _NOEXCEPT_( is_nothrow_move_constructible<__bucket_list>::value && is_nothrow_move_constructible<__first_node>::value && + is_nothrow_move_constructible<__node_allocator>::value && is_nothrow_move_constructible<hasher>::value && is_nothrow_move_constructible<key_equal>::value) : __bucket_list_(_VSTD::move(__u.__bucket_list_)), @@ -1408,7 +1420,7 @@ __hash_table<_Tp, _Hash, _Equal, _Alloc>::__move_assign( } template <class _Tp, class _Hash, class _Equal, class _Alloc> -inline _LIBCPP_INLINE_VISIBILITY +inline __hash_table<_Tp, _Hash, _Equal, _Alloc>& __hash_table<_Tp, _Hash, _Equal, _Alloc>::operator=(__hash_table&& __u) _NOEXCEPT_( @@ -1493,7 +1505,7 @@ __hash_table<_Tp, _Hash, _Equal, _Alloc>::__assign_multi(_InputIterator __first, } template <class _Tp, class _Hash, class _Equal, class _Alloc> -inline _LIBCPP_INLINE_VISIBILITY +inline typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator __hash_table<_Tp, _Hash, _Equal, _Alloc>::begin() _NOEXCEPT { @@ -1505,7 +1517,7 @@ __hash_table<_Tp, _Hash, _Equal, _Alloc>::begin() _NOEXCEPT } template <class _Tp, class _Hash, class _Equal, class _Alloc> -inline _LIBCPP_INLINE_VISIBILITY +inline typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::iterator __hash_table<_Tp, _Hash, _Equal, _Alloc>::end() _NOEXCEPT { @@ -1517,7 +1529,7 @@ __hash_table<_Tp, _Hash, _Equal, _Alloc>::end() _NOEXCEPT } template <class _Tp, class _Hash, class _Equal, class _Alloc> -inline _LIBCPP_INLINE_VISIBILITY +inline typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::const_iterator __hash_table<_Tp, _Hash, _Equal, _Alloc>::begin() const _NOEXCEPT { @@ -1529,7 +1541,7 @@ __hash_table<_Tp, _Hash, _Equal, _Alloc>::begin() const _NOEXCEPT } template <class _Tp, class _Hash, class _Equal, class _Alloc> -inline _LIBCPP_INLINE_VISIBILITY +inline typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::const_iterator __hash_table<_Tp, _Hash, _Equal, _Alloc>::end() const _NOEXCEPT { @@ -2106,7 +2118,7 @@ __hash_table<_Tp, _Hash, _Equal, _Alloc>::__construct_node(const value_type& __v __h.get_deleter().__value_constructed = true; __h->__hash_ = hash_function()(__h->__value_); __h->__next_ = nullptr; - return _VSTD::move(__h); // explicitly moved for C++03 + return _LIBCPP_EXPLICIT_MOVE(__h); // explicitly moved for C++03 } #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES @@ -2122,7 +2134,7 @@ __hash_table<_Tp, _Hash, _Equal, _Alloc>::__construct_node(const value_type& __v __h.get_deleter().__value_constructed = true; __h->__hash_ = __hash; __h->__next_ = nullptr; - return _VSTD::move(__h); // explicitly moved for C++03 + return _LIBCPP_EXPLICIT_MOVE(__h); // explicitly moved for C++03 } template <class _Tp, class _Hash, class _Equal, class _Alloc> @@ -2254,7 +2266,7 @@ __hash_table<_Tp, _Hash, _Equal, _Alloc>::remove(const_iterator __p) _NOEXCEPT template <class _Tp, class _Hash, class _Equal, class _Alloc> template <class _Key> -inline _LIBCPP_INLINE_VISIBILITY +inline typename __hash_table<_Tp, _Hash, _Equal, _Alloc>::size_type __hash_table<_Tp, _Hash, _Equal, _Alloc>::__count_unique(const _Key& __k) const { @@ -2351,15 +2363,17 @@ __hash_table<_Tp, _Hash, _Equal, _Alloc>::__equal_range_multi( template <class _Tp, class _Hash, class _Equal, class _Alloc> void __hash_table<_Tp, _Hash, _Equal, _Alloc>::swap(__hash_table& __u) +#if _LIBCPP_STD_VER <= 11 _NOEXCEPT_( __is_nothrow_swappable<hasher>::value && __is_nothrow_swappable<key_equal>::value -#if _LIBCPP_STD_VER <= 11 && (!allocator_traits<__pointer_allocator>::propagate_on_container_swap::value || __is_nothrow_swappable<__pointer_allocator>::value) && (!__node_traits::propagate_on_container_swap::value || __is_nothrow_swappable<__node_allocator>::value) -#endif ) +#else + _NOEXCEPT_(__is_nothrow_swappable<hasher>::value && __is_nothrow_swappable<key_equal>::value) +#endif { { __node_pointer_pointer __npp = __bucket_list_.release(); diff --git a/include/__locale b/include/__locale index 19895582cac8..7bc701dda6e3 100644 --- a/include/__locale +++ b/include/__locale @@ -37,6 +37,8 @@ #elif (defined(__GLIBC__) || defined(__APPLE__) || defined(__FreeBSD__) \ || defined(__EMSCRIPTEN__) || defined(__IBMCPP__)) # include <xlocale.h> +#elif defined(_LIBCPP_HAS_MUSL_LIBC) +# include <support/musl/xlocale.h> #endif // __GLIBC__ || __APPLE__ || __FreeBSD__ || __sun__ || __EMSCRIPTEN__ || __IBMCPP__ #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) @@ -329,7 +331,7 @@ locale::operator()(const basic_string<_CharT, _Traits, _Allocator>& __x, class _LIBCPP_TYPE_VIS ctype_base { public: -#ifdef __GLIBC__ +#if defined(__GLIBC__) typedef unsigned short mask; static const mask space = _ISspace; static const mask print = _ISprint; @@ -359,7 +361,7 @@ public: typedef __uint32_t mask; # elif defined(__FreeBSD__) typedef unsigned long mask; -# elif defined(__EMSCRIPTEN__) || defined(__NetBSD__) +# elif defined(__EMSCRIPTEN__) || defined(__NetBSD__) typedef unsigned short mask; # endif static const mask space = _CTYPE_S; diff --git a/include/__mutex_base b/include/__mutex_base index d5ece7c1454c..b019b4760d18 100644 --- a/include/__mutex_base +++ b/include/__mutex_base @@ -14,7 +14,9 @@ #include <__config> #include <chrono> #include <system_error> +#ifndef _LIBCPP_HAS_NO_THREADS #include <pthread.h> +#endif #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) #pragma GCC system_header @@ -306,6 +308,7 @@ public: template <class _Rep, class _Period, class _Predicate> bool + _LIBCPP_INLINE_VISIBILITY wait_for(unique_lock<mutex>& __lk, const chrono::duration<_Rep, _Period>& __d, _Predicate __pred); @@ -390,7 +393,7 @@ condition_variable::wait_for(unique_lock<mutex>& __lk, } template <class _Rep, class _Period, class _Predicate> -inline _LIBCPP_INLINE_VISIBILITY +inline bool condition_variable::wait_for(unique_lock<mutex>& __lk, const chrono::duration<_Rep, _Period>& __d, diff --git a/include/__nullptr b/include/__nullptr new file mode 100644 index 000000000000..95415a6325a3 --- /dev/null +++ b/include/__nullptr @@ -0,0 +1,66 @@ +// -*- C++ -*- +//===--------------------------- __nullptr --------------------------------===// +// +// 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_NULLPTR +#define _LIBCPP_NULLPTR + +#include <__config> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +#ifdef _LIBCPP_HAS_NO_NULLPTR + +_LIBCPP_BEGIN_NAMESPACE_STD + +struct _LIBCPP_TYPE_VIS_ONLY nullptr_t +{ + void* __lx; + + struct __nat {int __for_bool_;}; + + _LIBCPP_ALWAYS_INLINE _LIBCPP_CONSTEXPR nullptr_t() : __lx(0) {} + _LIBCPP_ALWAYS_INLINE _LIBCPP_CONSTEXPR nullptr_t(int __nat::*) : __lx(0) {} + + _LIBCPP_ALWAYS_INLINE _LIBCPP_CONSTEXPR operator int __nat::*() const {return 0;} + + template <class _Tp> + _LIBCPP_ALWAYS_INLINE _LIBCPP_CONSTEXPR + operator _Tp* () const {return 0;} + + template <class _Tp, class _Up> + _LIBCPP_ALWAYS_INLINE + operator _Tp _Up::* () const {return 0;} + + friend _LIBCPP_ALWAYS_INLINE _LIBCPP_CONSTEXPR bool operator==(nullptr_t, nullptr_t) {return true;} + friend _LIBCPP_ALWAYS_INLINE _LIBCPP_CONSTEXPR bool operator!=(nullptr_t, nullptr_t) {return false;} + friend _LIBCPP_ALWAYS_INLINE _LIBCPP_CONSTEXPR bool operator<(nullptr_t, nullptr_t) {return false;} + friend _LIBCPP_ALWAYS_INLINE _LIBCPP_CONSTEXPR bool operator<=(nullptr_t, nullptr_t) {return true;} + friend _LIBCPP_ALWAYS_INLINE _LIBCPP_CONSTEXPR bool operator>(nullptr_t, nullptr_t) {return false;} + friend _LIBCPP_ALWAYS_INLINE _LIBCPP_CONSTEXPR bool operator>=(nullptr_t, nullptr_t) {return true;} +}; + +inline _LIBCPP_ALWAYS_INLINE _LIBCPP_CONSTEXPR nullptr_t __get_nullptr_t() {return nullptr_t(0);} + +#define nullptr _VSTD::__get_nullptr_t() + +_LIBCPP_END_NAMESPACE_STD + +#else // _LIBCPP_HAS_NO_NULLPTR + +namespace std +{ + typedef decltype(nullptr) nullptr_t; +} + +#endif // _LIBCPP_HAS_NO_NULLPTR + +#endif // _LIBCPP_NULLPTR diff --git a/include/__split_buffer b/include/__split_buffer index 727b1b6b5674..79d1aa1d7c4a 100644 --- a/include/__split_buffer +++ b/include/__split_buffer @@ -56,9 +56,12 @@ public: _LIBCPP_INLINE_VISIBILITY pointer& __end_cap() _NOEXCEPT {return __end_cap_.first();} _LIBCPP_INLINE_VISIBILITY const pointer& __end_cap() const _NOEXCEPT {return __end_cap_.first();} + _LIBCPP_INLINE_VISIBILITY __split_buffer() _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value); + _LIBCPP_INLINE_VISIBILITY explicit __split_buffer(__alloc_rr& __a); + _LIBCPP_INLINE_VISIBILITY explicit __split_buffer(const __alloc_rr& __a); __split_buffer(size_type __cap, size_type __start, __alloc_rr& __a); ~__split_buffer(); @@ -128,7 +131,9 @@ public: _LIBCPP_INLINE_VISIBILITY void __destruct_at_begin(pointer __new_begin) {__destruct_at_begin(__new_begin, is_trivially_destructible<value_type>());} + _LIBCPP_INLINE_VISIBILITY void __destruct_at_begin(pointer __new_begin, false_type); + _LIBCPP_INLINE_VISIBILITY void __destruct_at_begin(pointer __new_begin, true_type); _LIBCPP_INLINE_VISIBILITY @@ -266,7 +271,7 @@ __split_buffer<_Tp, _Allocator>::__construct_at_end(_ForwardIterator __first, _F } template <class _Tp, class _Allocator> -inline _LIBCPP_INLINE_VISIBILITY +inline void __split_buffer<_Tp, _Allocator>::__destruct_at_begin(pointer __new_begin, false_type) { @@ -275,7 +280,7 @@ __split_buffer<_Tp, _Allocator>::__destruct_at_begin(pointer __new_begin, false_ } template <class _Tp, class _Allocator> -inline _LIBCPP_INLINE_VISIBILITY +inline void __split_buffer<_Tp, _Allocator>::__destruct_at_begin(pointer __new_begin, true_type) { @@ -309,7 +314,7 @@ __split_buffer<_Tp, _Allocator>::__split_buffer(size_type __cap, size_type __sta } template <class _Tp, class _Allocator> -inline _LIBCPP_INLINE_VISIBILITY +inline __split_buffer<_Tp, _Allocator>::__split_buffer() _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value) : __first_(nullptr), __begin_(nullptr), __end_(nullptr), __end_cap_(nullptr) @@ -317,14 +322,14 @@ __split_buffer<_Tp, _Allocator>::__split_buffer() } template <class _Tp, class _Allocator> -inline _LIBCPP_INLINE_VISIBILITY +inline __split_buffer<_Tp, _Allocator>::__split_buffer(__alloc_rr& __a) : __first_(nullptr), __begin_(nullptr), __end_(nullptr), __end_cap_(nullptr, __a) { } template <class _Tp, class _Allocator> -inline _LIBCPP_INLINE_VISIBILITY +inline __split_buffer<_Tp, _Allocator>::__split_buffer(const __alloc_rr& __a) : __first_(nullptr), __begin_(nullptr), __end_(nullptr), __end_cap_(nullptr, __a) { diff --git a/include/__std_stream b/include/__std_stream index 5403adabc343..f867cd23bdd5 100644 --- a/include/__std_stream +++ b/include/__std_stream @@ -276,7 +276,6 @@ __stdoutbuf<_CharT>::overflow(int_type __c) codecvt_base::result __r; char_type* pbase = &__1buf; char_type* pptr = pbase + 1; - char_type* epptr = pptr; do { const char_type* __e; diff --git a/include/__tree b/include/__tree index 574e74baf26b..6391609b3982 100644 --- a/include/__tree +++ b/include/__tree @@ -1118,8 +1118,8 @@ __tree<_Tp, _Compare, _Allocator>::__tree(const value_compare& __comp) template <class _Tp, class _Compare, class _Allocator> __tree<_Tp, _Compare, _Allocator>::__tree(const allocator_type& __a) - : __pair1_(__node_allocator(__a)), - __begin_node_(__node_pointer()), + : __begin_node_(__node_pointer()), + __pair1_(__node_allocator(__a)), __pair3_(0) { __begin_node() = __end_node(); @@ -1128,8 +1128,8 @@ __tree<_Tp, _Compare, _Allocator>::__tree(const allocator_type& __a) template <class _Tp, class _Compare, class _Allocator> __tree<_Tp, _Compare, _Allocator>::__tree(const value_compare& __comp, const allocator_type& __a) - : __pair1_(__node_allocator(__a)), - __begin_node_(__node_pointer()), + : __begin_node_(__node_pointer()), + __pair1_(__node_allocator(__a)), __pair3_(0, __comp) { __begin_node() = __end_node(); @@ -1843,7 +1843,7 @@ __tree<_Tp, _Compare, _Allocator>::__construct_node(const value_type& __v) __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na)); __node_traits::construct(__na, _VSTD::addressof(__h->__value_), __v); __h.get_deleter().__value_constructed = true; - return _VSTD::move(__h); // explicitly moved for C++03 + return _LIBCPP_EXPLICIT_MOVE(__h); // explicitly moved for C++03 } #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES diff --git a/include/__tuple b/include/__tuple index 2837ce708f09..8c31759774de 100644 --- a/include/__tuple +++ b/include/__tuple @@ -86,6 +86,11 @@ template <size_t _Ip, class ..._Tp> _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 typename tuple_element<_Ip, tuple<_Tp...> >::type&& get(tuple<_Tp...>&&) _NOEXCEPT; + +template <size_t _Ip, class ..._Tp> +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 +const typename tuple_element<_Ip, tuple<_Tp...> >::type&& +get(const tuple<_Tp...>&&) _NOEXCEPT; #endif // pair specializations @@ -109,6 +114,11 @@ template <size_t _Ip, class _T1, class _T2> _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 typename tuple_element<_Ip, pair<_T1, _T2> >::type&& get(pair<_T1, _T2>&&) _NOEXCEPT; + +template <size_t _Ip, class _T1, class _T2> +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 +const typename tuple_element<_Ip, pair<_T1, _T2> >::type&& +get(const pair<_T1, _T2>&&) _NOEXCEPT; #endif // array specializations @@ -132,35 +142,15 @@ template <size_t _Ip, class _Tp, size_t _Size> _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 _Tp&& get(array<_Tp, _Size>&&) _NOEXCEPT; + +template <size_t _Ip, class _Tp, size_t _Size> +_LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 +const _Tp&& +get(const array<_Tp, _Size>&&) _NOEXCEPT; #endif #if !defined(_LIBCPP_HAS_NO_VARIADICS) -// __lazy_and - -template <bool _Last, class ..._Preds> -struct __lazy_and_impl; - -template <class ..._Preds> -struct __lazy_and_impl<false, _Preds...> : false_type {}; - -template <> -struct __lazy_and_impl<true> : true_type {}; - -template <class _Pred> -struct __lazy_and_impl<true, _Pred> : integral_constant<bool, _Pred::type::value> {}; - -template <class _Hp, class ..._Tp> -struct __lazy_and_impl<true, _Hp, _Tp...> : __lazy_and_impl<_Hp::type::value, _Tp...> {}; - -template <class _P1, class ..._Pr> -struct __lazy_and : __lazy_and_impl<_P1::type::value, _Pr...> {}; - -// __lazy_not - -template <class _Pred> -struct __lazy_not : integral_constant<bool, !_Pred::type::value> {}; - // __make_tuple_indices template <size_t...> struct __tuple_indices {}; diff --git a/include/algorithm b/include/algorithm index 7b0c53e05a5a..9c051198930d 100644 --- a/include/algorithm +++ b/include/algorithm @@ -851,7 +851,7 @@ for_each(_InputIterator __first, _InputIterator __last, _Function __f) { for (; __first != __last; ++__first) __f(*__first); - return _VSTD::move(__f); // explicitly moved for (emulated) C++03 + return _LIBCPP_EXPLICIT_MOVE(__f); // explicitly moved for (emulated) C++03 } // find @@ -2330,7 +2330,7 @@ __reverse(_BidirectionalIterator __first, _BidirectionalIterator __last, bidirec { if (__first == --__last) break; - swap(*__first, *__last); + _VSTD::iter_swap(__first, __last); ++__first; } } @@ -2342,7 +2342,7 @@ __reverse(_RandomAccessIterator __first, _RandomAccessIterator __last, random_ac { if (__first != __last) for (; __first < --__last; ++__first) - swap(*__first, *__last); + _VSTD::iter_swap(__first, __last); } template <class _BidirectionalIterator> @@ -3037,7 +3037,7 @@ uniform_int_distribution<_IntType>::operator()(_URNG& __g, const param_type& __p if (_Rp == 0) return static_cast<result_type>(_Eng(__g, _Dt)()); size_t __w = _Dt - __clz(_Rp) - 1; - if ((_Rp & (_UIntType(~0) >> (_Dt - __w))) != 0) + if ((_Rp & (std::numeric_limits<_UIntType>::max() >> (_Dt - __w))) != 0) ++__w; _Eng __e(__g, __w); _UIntType __u; diff --git a/include/array b/include/array index 2e02a43ed524..8866eaf6b463 100644 --- a/include/array +++ b/include/array @@ -89,12 +89,13 @@ template <class T, size_t N > void swap(array<T,N>& x, array<T,N>& y) noexcept(noexcept(x.swap(y))); template <class T> class tuple_size; -template <int I, class T> class tuple_element; +template <size_t I, class T> class tuple_element; template <class T, size_t N> struct tuple_size<array<T, N>>; -template <int I, class T, size_t N> struct tuple_element<I, array<T, N>>; -template <int I, class T, size_t N> T& get(array<T, N>&) noexcept; // constexpr in C++14 -template <int I, class T, size_t N> const T& get(const array<T, N>&) noexcept; // constexpr in C++14 -template <int I, class T, size_t N> T&& get(array<T, N>&&) noexcept; // constexpr in C++14 +template <size_t I, class T, size_t N> struct tuple_element<I, array<T, N>>; +template <size_t I, class T, size_t N> T& get(array<T, N>&) noexcept; // constexpr in C++14 +template <size_t I, class T, size_t N> const T& get(const array<T, N>&) noexcept; // constexpr in C++14 +template <size_t I, class T, size_t N> T&& get(array<T, N>&&) noexcept; // constexpr in C++14 +template <size_t I, class T, size_t N> const T&& get(const array<T, N>&&) noexcept; // constexpr in C++14 } // std @@ -324,6 +325,15 @@ get(array<_Tp, _Size>&& __a) _NOEXCEPT return _VSTD::move(__a.__elems_[_Ip]); } +template <size_t _Ip, class _Tp, size_t _Size> +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 +const _Tp&& +get(const array<_Tp, _Size>&& __a) _NOEXCEPT +{ + static_assert(_Ip < _Size, "Index out of bounds in std::get<> (const std::array &&)"); + return _VSTD::move(__a.__elems_[_Ip]); +} + #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES _LIBCPP_END_NAMESPACE_STD diff --git a/include/atomic b/include/atomic index 97a998d33633..abec2a0b565a 100644 --- a/include/atomic +++ b/include/atomic @@ -535,25 +535,35 @@ void atomic_signal_fence(memory_order m) noexcept; #ifdef _LIBCPP_HAS_NO_THREADS #error <atomic> is not supported on this single threaded system -#else // !_LIBCPP_HAS_NO_THREADS +#endif +#if !defined(_LIBCPP_HAS_C_ATOMIC_IMP) && !defined(_LIBCPP_HAS_GCC_ATOMIC_IMP) +#error <atomic> is not implemented +#endif _LIBCPP_BEGIN_NAMESPACE_STD -#if !__has_feature(cxx_atomic) && _GNUC_VER < 407 -#error <atomic> 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; -#if _GNUC_VER >= 407 +#if defined(_LIBCPP_HAS_GCC_ATOMIC_IMP) namespace __gcc_atomic { template <typename _Tp> struct __gcc_atomic_t { - __gcc_atomic_t() _NOEXCEPT {} + +#if _GNUC_VER >= 501 + static_assert(is_trivially_copyable<_Tp>::value, + "std::atomic<Tp> requires that 'Tp' be a trivially copyable type"); +#endif + + _LIBCPP_INLINE_VISIBILITY +#ifndef _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS + __gcc_atomic_t() _NOEXCEPT = default; +#else + __gcc_atomic_t() _NOEXCEPT : __a_value() {} +#endif // _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS _LIBCPP_CONSTEXPR explicit __gcc_atomic_t(_Tp value) _NOEXCEPT : __a_value(value) {} _Tp __a_value; @@ -574,7 +584,7 @@ struct __can_assign { sizeof(__test_atomic_assignable<_Tp, _Td>(1)) == sizeof(char); }; -static inline constexpr int __to_gcc_order(memory_order __order) { +static inline _LIBCPP_CONSTEXPR int __to_gcc_order(memory_order __order) { // Avoid switch statement to make this a constexpr. return __order == memory_order_relaxed ? __ATOMIC_RELAXED: (__order == memory_order_acquire ? __ATOMIC_ACQUIRE: @@ -584,7 +594,7 @@ static inline constexpr int __to_gcc_order(memory_order __order) { __ATOMIC_CONSUME)))); } -static inline constexpr int __to_gcc_failure_order(memory_order __order) { +static inline _LIBCPP_CONSTEXPR int __to_gcc_failure_order(memory_order __order) { // Avoid switch statement to make this a constexpr. return __order == memory_order_relaxed ? __ATOMIC_RELAXED: (__order == memory_order_acquire ? __ATOMIC_ACQUIRE: @@ -805,7 +815,7 @@ static inline _Tp __c11_atomic_fetch_xor(_Atomic(_Tp)* __a, _Tp __pattern, return __atomic_fetch_xor(&__a->__a_value, __pattern, __gcc_atomic::__to_gcc_order(__order)); } -#endif // _GNUC_VER >= 407 +#endif // _LIBCPP_HAS_GCC_ATOMIC_IMP template <class _Tp> inline _LIBCPP_INLINE_VISIBILITY @@ -825,7 +835,7 @@ struct __atomic_base // false _LIBCPP_INLINE_VISIBILITY bool is_lock_free() const volatile _NOEXCEPT { -#if __has_feature(cxx_atomic) +#if defined(_LIBCPP_HAS_C_ATOMIC_IMP) return __c11_atomic_is_lock_free(sizeof(_Tp)); #else return __atomic_is_lock_free(sizeof(_Tp), 0); @@ -1779,8 +1789,6 @@ typedef atomic<uintmax_t> atomic_uintmax_t; #define ATOMIC_FLAG_INIT {false} #define ATOMIC_VAR_INIT(__v) {__v} -// lock-free property - #define ATOMIC_BOOL_LOCK_FREE __GCC_ATOMIC_BOOL_LOCK_FREE #define ATOMIC_CHAR_LOCK_FREE __GCC_ATOMIC_CHAR_LOCK_FREE #define ATOMIC_CHAR16_T_LOCK_FREE __GCC_ATOMIC_CHAR16_T_LOCK_FREE @@ -1792,10 +1800,6 @@ typedef atomic<uintmax_t> atomic_uintmax_t; #define ATOMIC_LLONG_LOCK_FREE __GCC_ATOMIC_LLONG_LOCK_FREE #define ATOMIC_POINTER_LOCK_FREE __GCC_ATOMIC_POINTER_LOCK_FREE -#endif // !__has_feature(cxx_atomic) - _LIBCPP_END_NAMESPACE_STD -#endif // !_LIBCPP_HAS_NO_THREADS - #endif // _LIBCPP_ATOMIC diff --git a/include/bitset b/include/bitset index 8c278cc724f1..87d7afca5a73 100644 --- a/include/bitset +++ b/include/bitset @@ -168,7 +168,9 @@ protected: typedef __bit_iterator<__bitset, false> iterator; typedef __bit_iterator<__bitset, true> const_iterator; + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR __bitset() _NOEXCEPT; + _LIBCPP_INLINE_VISIBILITY explicit _LIBCPP_CONSTEXPR __bitset(unsigned long long __v) _NOEXCEPT; _LIBCPP_INLINE_VISIBILITY reference __make_ref(size_t __pos) _NOEXCEPT @@ -180,8 +182,11 @@ protected: _LIBCPP_INLINE_VISIBILITY const_iterator __make_iter(size_t __pos) const _NOEXCEPT {return const_iterator(__first_ + __pos / __bits_per_word, __pos % __bits_per_word);} + _LIBCPP_INLINE_VISIBILITY void operator&=(const __bitset& __v) _NOEXCEPT; + _LIBCPP_INLINE_VISIBILITY void operator|=(const __bitset& __v) _NOEXCEPT; + _LIBCPP_INLINE_VISIBILITY void operator^=(const __bitset& __v) _NOEXCEPT; void flip() _NOEXCEPT; @@ -192,22 +197,27 @@ protected: bool all() const _NOEXCEPT; bool any() const _NOEXCEPT; + _LIBCPP_INLINE_VISIBILITY size_t __hash_code() const _NOEXCEPT; private: #ifdef _LIBCPP_HAS_NO_CONSTEXPR void __init(unsigned long long __v, false_type) _NOEXCEPT; + _LIBCPP_INLINE_VISIBILITY void __init(unsigned long long __v, true_type) _NOEXCEPT; #endif // _LIBCPP_HAS_NO_CONSTEXPR unsigned long to_ulong(false_type) const; + _LIBCPP_INLINE_VISIBILITY unsigned long to_ulong(true_type) const; unsigned long long to_ullong(false_type) const; + _LIBCPP_INLINE_VISIBILITY unsigned long long to_ullong(true_type) const; + _LIBCPP_INLINE_VISIBILITY unsigned long long to_ullong(true_type, false_type) const; unsigned long long to_ullong(true_type, true_type) const; }; template <size_t _N_words, size_t _Size> -inline _LIBCPP_INLINE_VISIBILITY +inline _LIBCPP_CONSTEXPR __bitset<_N_words, _Size>::__bitset() _NOEXCEPT #ifndef _LIBCPP_HAS_NO_CONSTEXPR @@ -245,7 +255,7 @@ __bitset<_N_words, _Size>::__init(unsigned long long __v, true_type) _NOEXCEPT #endif // _LIBCPP_HAS_NO_CONSTEXPR template <size_t _N_words, size_t _Size> -inline _LIBCPP_INLINE_VISIBILITY +inline _LIBCPP_CONSTEXPR __bitset<_N_words, _Size>::__bitset(unsigned long long __v) _NOEXCEPT #ifndef _LIBCPP_HAS_NO_CONSTEXPR @@ -264,7 +274,7 @@ __bitset<_N_words, _Size>::__bitset(unsigned long long __v) _NOEXCEPT } template <size_t _N_words, size_t _Size> -inline _LIBCPP_INLINE_VISIBILITY +inline void __bitset<_N_words, _Size>::operator&=(const __bitset& __v) _NOEXCEPT { @@ -273,7 +283,7 @@ __bitset<_N_words, _Size>::operator&=(const __bitset& __v) _NOEXCEPT } template <size_t _N_words, size_t _Size> -inline _LIBCPP_INLINE_VISIBILITY +inline void __bitset<_N_words, _Size>::operator|=(const __bitset& __v) _NOEXCEPT { @@ -282,7 +292,7 @@ __bitset<_N_words, _Size>::operator|=(const __bitset& __v) _NOEXCEPT } template <size_t _N_words, size_t _Size> -inline _LIBCPP_INLINE_VISIBILITY +inline void __bitset<_N_words, _Size>::operator^=(const __bitset& __v) _NOEXCEPT { @@ -325,7 +335,7 @@ __bitset<_N_words, _Size>::to_ulong(false_type) const } template <size_t _N_words, size_t _Size> -inline _LIBCPP_INLINE_VISIBILITY +inline unsigned long __bitset<_N_words, _Size>::to_ulong(true_type) const { @@ -348,7 +358,7 @@ __bitset<_N_words, _Size>::to_ullong(false_type) const } template <size_t _N_words, size_t _Size> -inline _LIBCPP_INLINE_VISIBILITY +inline unsigned long long __bitset<_N_words, _Size>::to_ullong(true_type) const { @@ -356,7 +366,7 @@ __bitset<_N_words, _Size>::to_ullong(true_type) const } template <size_t _N_words, size_t _Size> -inline _LIBCPP_INLINE_VISIBILITY +inline unsigned long long __bitset<_N_words, _Size>::to_ullong(true_type, false_type) const { @@ -414,7 +424,7 @@ __bitset<_N_words, _Size>::any() const _NOEXCEPT } template <size_t _N_words, size_t _Size> -inline _LIBCPP_INLINE_VISIBILITY +inline size_t __bitset<_N_words, _Size>::__hash_code() const _NOEXCEPT { @@ -450,7 +460,9 @@ protected: typedef __bit_iterator<__bitset, false> iterator; typedef __bit_iterator<__bitset, true> const_iterator; + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR __bitset() _NOEXCEPT; + _LIBCPP_INLINE_VISIBILITY explicit _LIBCPP_CONSTEXPR __bitset(unsigned long long __v) _NOEXCEPT; _LIBCPP_INLINE_VISIBILITY reference __make_ref(size_t __pos) _NOEXCEPT @@ -462,23 +474,32 @@ protected: _LIBCPP_INLINE_VISIBILITY const_iterator __make_iter(size_t __pos) const _NOEXCEPT {return const_iterator(&__first_ + __pos / __bits_per_word, __pos % __bits_per_word);} + _LIBCPP_INLINE_VISIBILITY void operator&=(const __bitset& __v) _NOEXCEPT; + _LIBCPP_INLINE_VISIBILITY void operator|=(const __bitset& __v) _NOEXCEPT; + _LIBCPP_INLINE_VISIBILITY void operator^=(const __bitset& __v) _NOEXCEPT; + _LIBCPP_INLINE_VISIBILITY void flip() _NOEXCEPT; + _LIBCPP_INLINE_VISIBILITY unsigned long to_ulong() const; + _LIBCPP_INLINE_VISIBILITY unsigned long long to_ullong() const; + _LIBCPP_INLINE_VISIBILITY bool all() const _NOEXCEPT; + _LIBCPP_INLINE_VISIBILITY bool any() const _NOEXCEPT; + _LIBCPP_INLINE_VISIBILITY size_t __hash_code() const _NOEXCEPT; }; template <size_t _Size> -inline _LIBCPP_INLINE_VISIBILITY +inline _LIBCPP_CONSTEXPR __bitset<1, _Size>::__bitset() _NOEXCEPT : __first_(0) @@ -486,7 +507,7 @@ __bitset<1, _Size>::__bitset() _NOEXCEPT } template <size_t _Size> -inline _LIBCPP_INLINE_VISIBILITY +inline _LIBCPP_CONSTEXPR __bitset<1, _Size>::__bitset(unsigned long long __v) _NOEXCEPT : __first_(static_cast<__storage_type>(__v)) @@ -494,7 +515,7 @@ __bitset<1, _Size>::__bitset(unsigned long long __v) _NOEXCEPT } template <size_t _Size> -inline _LIBCPP_INLINE_VISIBILITY +inline void __bitset<1, _Size>::operator&=(const __bitset& __v) _NOEXCEPT { @@ -502,7 +523,7 @@ __bitset<1, _Size>::operator&=(const __bitset& __v) _NOEXCEPT } template <size_t _Size> -inline _LIBCPP_INLINE_VISIBILITY +inline void __bitset<1, _Size>::operator|=(const __bitset& __v) _NOEXCEPT { @@ -510,7 +531,7 @@ __bitset<1, _Size>::operator|=(const __bitset& __v) _NOEXCEPT } template <size_t _Size> -inline _LIBCPP_INLINE_VISIBILITY +inline void __bitset<1, _Size>::operator^=(const __bitset& __v) _NOEXCEPT { @@ -518,7 +539,7 @@ __bitset<1, _Size>::operator^=(const __bitset& __v) _NOEXCEPT } template <size_t _Size> -inline _LIBCPP_INLINE_VISIBILITY +inline void __bitset<1, _Size>::flip() _NOEXCEPT { @@ -528,7 +549,7 @@ __bitset<1, _Size>::flip() _NOEXCEPT } template <size_t _Size> -inline _LIBCPP_INLINE_VISIBILITY +inline unsigned long __bitset<1, _Size>::to_ulong() const { @@ -536,7 +557,7 @@ __bitset<1, _Size>::to_ulong() const } template <size_t _Size> -inline _LIBCPP_INLINE_VISIBILITY +inline unsigned long long __bitset<1, _Size>::to_ullong() const { @@ -544,7 +565,7 @@ __bitset<1, _Size>::to_ullong() const } template <size_t _Size> -inline _LIBCPP_INLINE_VISIBILITY +inline bool __bitset<1, _Size>::all() const _NOEXCEPT { @@ -553,7 +574,7 @@ __bitset<1, _Size>::all() const _NOEXCEPT } template <size_t _Size> -inline _LIBCPP_INLINE_VISIBILITY +inline bool __bitset<1, _Size>::any() const _NOEXCEPT { @@ -562,7 +583,7 @@ __bitset<1, _Size>::any() const _NOEXCEPT } template <size_t _Size> -inline _LIBCPP_INLINE_VISIBILITY +inline size_t __bitset<1, _Size>::__hash_code() const _NOEXCEPT { @@ -593,7 +614,9 @@ protected: typedef __bit_iterator<__bitset, false> iterator; typedef __bit_iterator<__bitset, true> const_iterator; + _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR __bitset() _NOEXCEPT; + _LIBCPP_INLINE_VISIBILITY explicit _LIBCPP_CONSTEXPR __bitset(unsigned long long) _NOEXCEPT; _LIBCPP_INLINE_VISIBILITY reference __make_ref(size_t) _NOEXCEPT @@ -620,13 +643,13 @@ protected: _LIBCPP_INLINE_VISIBILITY size_t __hash_code() const _NOEXCEPT {return 0;} }; -inline _LIBCPP_INLINE_VISIBILITY +inline _LIBCPP_CONSTEXPR __bitset<0, 0>::__bitset() _NOEXCEPT { } -inline _LIBCPP_INLINE_VISIBILITY +inline _LIBCPP_CONSTEXPR __bitset<0, 0>::__bitset(unsigned long long) _NOEXCEPT { @@ -663,16 +686,23 @@ public: _CharT __zero = _CharT('0'), _CharT __one = _CharT('1')); // 23.3.5.2 bitset operations: + _LIBCPP_INLINE_VISIBILITY bitset& operator&=(const bitset& __rhs) _NOEXCEPT; + _LIBCPP_INLINE_VISIBILITY bitset& operator|=(const bitset& __rhs) _NOEXCEPT; + _LIBCPP_INLINE_VISIBILITY bitset& operator^=(const bitset& __rhs) _NOEXCEPT; bitset& operator<<=(size_t __pos) _NOEXCEPT; bitset& operator>>=(size_t __pos) _NOEXCEPT; + _LIBCPP_INLINE_VISIBILITY bitset& set() _NOEXCEPT; bitset& set(size_t __pos, bool __val = true); + _LIBCPP_INLINE_VISIBILITY bitset& reset() _NOEXCEPT; bitset& reset(size_t __pos); + _LIBCPP_INLINE_VISIBILITY bitset operator~() const _NOEXCEPT; + _LIBCPP_INLINE_VISIBILITY bitset& flip() _NOEXCEPT; bitset& flip(size_t __pos); @@ -680,28 +710,40 @@ public: _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR const_reference operator[](size_t __p) const {return base::__make_ref(__p);} _LIBCPP_INLINE_VISIBILITY reference operator[](size_t __p) {return base::__make_ref(__p);} + _LIBCPP_INLINE_VISIBILITY unsigned long to_ulong() const; + _LIBCPP_INLINE_VISIBILITY unsigned long long to_ullong() const; template <class _CharT, class _Traits, class _Allocator> basic_string<_CharT, _Traits, _Allocator> to_string(_CharT __zero = _CharT('0'), _CharT __one = _CharT('1')) const; template <class _CharT, class _Traits> + _LIBCPP_INLINE_VISIBILITY basic_string<_CharT, _Traits, allocator<_CharT> > to_string(_CharT __zero = _CharT('0'), _CharT __one = _CharT('1')) const; template <class _CharT> + _LIBCPP_INLINE_VISIBILITY basic_string<_CharT, char_traits<_CharT>, allocator<_CharT> > to_string(_CharT __zero = _CharT('0'), _CharT __one = _CharT('1')) const; + _LIBCPP_INLINE_VISIBILITY basic_string<char, char_traits<char>, allocator<char> > to_string(char __zero = '0', char __one = '1') const; + _LIBCPP_INLINE_VISIBILITY size_t count() const _NOEXCEPT; _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR size_t size() const _NOEXCEPT {return _Size;} + _LIBCPP_INLINE_VISIBILITY bool operator==(const bitset& __rhs) const _NOEXCEPT; + _LIBCPP_INLINE_VISIBILITY bool operator!=(const bitset& __rhs) const _NOEXCEPT; bool test(size_t __pos) const; + _LIBCPP_INLINE_VISIBILITY bool all() const _NOEXCEPT; + _LIBCPP_INLINE_VISIBILITY bool any() const _NOEXCEPT; _LIBCPP_INLINE_VISIBILITY bool none() const _NOEXCEPT {return !any();} + _LIBCPP_INLINE_VISIBILITY bitset operator<<(size_t __pos) const _NOEXCEPT; + _LIBCPP_INLINE_VISIBILITY bitset operator>>(size_t __pos) const _NOEXCEPT; private: @@ -774,7 +816,7 @@ bitset<_Size>::bitset(const basic_string<_CharT,_Traits,_Allocator>& __str, } template <size_t _Size> -inline _LIBCPP_INLINE_VISIBILITY +inline bitset<_Size>& bitset<_Size>::operator&=(const bitset& __rhs) _NOEXCEPT { @@ -783,7 +825,7 @@ bitset<_Size>::operator&=(const bitset& __rhs) _NOEXCEPT } template <size_t _Size> -inline _LIBCPP_INLINE_VISIBILITY +inline bitset<_Size>& bitset<_Size>::operator|=(const bitset& __rhs) _NOEXCEPT { @@ -792,7 +834,7 @@ bitset<_Size>::operator|=(const bitset& __rhs) _NOEXCEPT } template <size_t _Size> -inline _LIBCPP_INLINE_VISIBILITY +inline bitset<_Size>& bitset<_Size>::operator^=(const bitset& __rhs) _NOEXCEPT { @@ -821,7 +863,7 @@ bitset<_Size>::operator>>=(size_t __pos) _NOEXCEPT } template <size_t _Size> -inline _LIBCPP_INLINE_VISIBILITY +inline bitset<_Size>& bitset<_Size>::set() _NOEXCEPT { @@ -844,7 +886,7 @@ bitset<_Size>::set(size_t __pos, bool __val) } template <size_t _Size> -inline _LIBCPP_INLINE_VISIBILITY +inline bitset<_Size>& bitset<_Size>::reset() _NOEXCEPT { @@ -867,7 +909,7 @@ bitset<_Size>::reset(size_t __pos) } template <size_t _Size> -inline _LIBCPP_INLINE_VISIBILITY +inline bitset<_Size> bitset<_Size>::operator~() const _NOEXCEPT { @@ -877,7 +919,7 @@ bitset<_Size>::operator~() const _NOEXCEPT } template <size_t _Size> -inline _LIBCPP_INLINE_VISIBILITY +inline bitset<_Size>& bitset<_Size>::flip() _NOEXCEPT { @@ -901,7 +943,7 @@ bitset<_Size>::flip(size_t __pos) } template <size_t _Size> -inline _LIBCPP_INLINE_VISIBILITY +inline unsigned long bitset<_Size>::to_ulong() const { @@ -909,7 +951,7 @@ bitset<_Size>::to_ulong() const } template <size_t _Size> -inline _LIBCPP_INLINE_VISIBILITY +inline unsigned long long bitset<_Size>::to_ullong() const { @@ -932,7 +974,7 @@ bitset<_Size>::to_string(_CharT __zero, _CharT __one) const template <size_t _Size> template <class _CharT, class _Traits> -inline _LIBCPP_INLINE_VISIBILITY +inline basic_string<_CharT, _Traits, allocator<_CharT> > bitset<_Size>::to_string(_CharT __zero, _CharT __one) const { @@ -941,7 +983,7 @@ bitset<_Size>::to_string(_CharT __zero, _CharT __one) const template <size_t _Size> template <class _CharT> -inline _LIBCPP_INLINE_VISIBILITY +inline basic_string<_CharT, char_traits<_CharT>, allocator<_CharT> > bitset<_Size>::to_string(_CharT __zero, _CharT __one) const { @@ -949,7 +991,7 @@ bitset<_Size>::to_string(_CharT __zero, _CharT __one) const } template <size_t _Size> -inline _LIBCPP_INLINE_VISIBILITY +inline basic_string<char, char_traits<char>, allocator<char> > bitset<_Size>::to_string(char __zero, char __one) const { @@ -957,7 +999,7 @@ bitset<_Size>::to_string(char __zero, char __one) const } template <size_t _Size> -inline _LIBCPP_INLINE_VISIBILITY +inline size_t bitset<_Size>::count() const _NOEXCEPT { @@ -965,7 +1007,7 @@ bitset<_Size>::count() const _NOEXCEPT } template <size_t _Size> -inline _LIBCPP_INLINE_VISIBILITY +inline bool bitset<_Size>::operator==(const bitset& __rhs) const _NOEXCEPT { @@ -973,7 +1015,7 @@ bitset<_Size>::operator==(const bitset& __rhs) const _NOEXCEPT } template <size_t _Size> -inline _LIBCPP_INLINE_VISIBILITY +inline bool bitset<_Size>::operator!=(const bitset& __rhs) const _NOEXCEPT { @@ -994,7 +1036,7 @@ bitset<_Size>::test(size_t __pos) const } template <size_t _Size> -inline _LIBCPP_INLINE_VISIBILITY +inline bool bitset<_Size>::all() const _NOEXCEPT { @@ -1002,7 +1044,7 @@ bitset<_Size>::all() const _NOEXCEPT } template <size_t _Size> -inline _LIBCPP_INLINE_VISIBILITY +inline bool bitset<_Size>::any() const _NOEXCEPT { @@ -1010,7 +1052,7 @@ bitset<_Size>::any() const _NOEXCEPT } template <size_t _Size> -inline _LIBCPP_INLINE_VISIBILITY +inline bitset<_Size> bitset<_Size>::operator<<(size_t __pos) const _NOEXCEPT { @@ -1020,7 +1062,7 @@ bitset<_Size>::operator<<(size_t __pos) const _NOEXCEPT } template <size_t _Size> -inline _LIBCPP_INLINE_VISIBILITY +inline bitset<_Size> bitset<_Size>::operator>>(size_t __pos) const _NOEXCEPT { diff --git a/include/cctype b/include/cctype index 26c740f7382d..a68c2a06604d 100644 --- a/include/cctype +++ b/include/cctype @@ -37,10 +37,6 @@ int toupper(int c); #include <__config> #include <ctype.h> -#if defined(_LIBCPP_MSVCRT) -#include "support/win32/support.h" -#include "support/win32/locale_win32.h" -#endif // _LIBCPP_MSVCRT #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) #pragma GCC system_header @@ -48,117 +44,20 @@ int toupper(int c); _LIBCPP_BEGIN_NAMESPACE_STD -#ifdef isalnum -inline _LIBCPP_INLINE_VISIBILITY int __libcpp_isalnum(int __c) {return isalnum(__c);} -#undef isalnum -inline _LIBCPP_INLINE_VISIBILITY int isalnum(int __c) {return __libcpp_isalnum(__c);} -#else // isalnum using ::isalnum; -#endif // isalnum - -#ifdef isalpha -inline _LIBCPP_INLINE_VISIBILITY int __libcpp_isalpha(int __c) {return isalpha(__c);} -#undef isalpha -inline _LIBCPP_INLINE_VISIBILITY int isalpha(int __c) {return __libcpp_isalpha(__c);} -#else // isalpha using ::isalpha; -#endif // isalpha - -#ifdef isblank -inline _LIBCPP_INLINE_VISIBILITY int __libcpp_isblank(int __c) {return isblank(__c);} -#undef isblank -inline _LIBCPP_INLINE_VISIBILITY int isblank(int __c) {return __libcpp_isblank(__c);} -#else // isblank using ::isblank; -#endif // isblank - -#ifdef iscntrl -inline _LIBCPP_INLINE_VISIBILITY int __libcpp_iscntrl(int __c) {return iscntrl(__c);} -#undef iscntrl -inline _LIBCPP_INLINE_VISIBILITY int iscntrl(int __c) {return __libcpp_iscntrl(__c);} -#else // iscntrl using ::iscntrl; -#endif // iscntrl - -#ifdef isdigit -inline _LIBCPP_INLINE_VISIBILITY int __libcpp_isdigit(int __c) {return isdigit(__c);} -#undef isdigit -inline _LIBCPP_INLINE_VISIBILITY int isdigit(int __c) {return __libcpp_isdigit(__c);} -#else // isdigit using ::isdigit; -#endif // isdigit - -#ifdef isgraph -inline _LIBCPP_INLINE_VISIBILITY int __libcpp_isgraph(int __c) {return isgraph(__c);} -#undef isgraph -inline _LIBCPP_INLINE_VISIBILITY int isgraph(int __c) {return __libcpp_isgraph(__c);} -#else // isgraph using ::isgraph; -#endif // isgraph - -#ifdef islower -inline _LIBCPP_INLINE_VISIBILITY int __libcpp_islower(int __c) {return islower(__c);} -#undef islower -inline _LIBCPP_INLINE_VISIBILITY int islower(int __c) {return __libcpp_islower(__c);} -#else // islower using ::islower; -#endif // islower - -#ifdef isprint -inline _LIBCPP_INLINE_VISIBILITY int __libcpp_isprint(int __c) {return isprint(__c);} -#undef isprint -inline _LIBCPP_INLINE_VISIBILITY int isprint(int __c) {return __libcpp_isprint(__c);} -#else // isprint using ::isprint; -#endif // isprint - -#ifdef ispunct -inline _LIBCPP_INLINE_VISIBILITY int __libcpp_ispunct(int __c) {return ispunct(__c);} -#undef ispunct -inline _LIBCPP_INLINE_VISIBILITY int ispunct(int __c) {return __libcpp_ispunct(__c);} -#else // ispunct using ::ispunct; -#endif // ispunct - -#ifdef isspace -inline _LIBCPP_INLINE_VISIBILITY int __libcpp_isspace(int __c) {return isspace(__c);} -#undef isspace -inline _LIBCPP_INLINE_VISIBILITY int isspace(int __c) {return __libcpp_isspace(__c);} -#else // isspace using ::isspace; -#endif // isspace - -#ifdef isupper -inline _LIBCPP_INLINE_VISIBILITY int __libcpp_isupper(int __c) {return isupper(__c);} -#undef isupper -inline _LIBCPP_INLINE_VISIBILITY int isupper(int __c) {return __libcpp_isupper(__c);} -#else // isupper using ::isupper; -#endif // isupper - -#ifdef isxdigit -inline _LIBCPP_INLINE_VISIBILITY int __libcpp_isxdigit(int __c) {return isxdigit(__c);} -#undef isxdigit -inline _LIBCPP_INLINE_VISIBILITY int isxdigit(int __c) {return __libcpp_isxdigit(__c);} -#else // isxdigit using ::isxdigit; -#endif // isxdigit - -#ifdef tolower -inline _LIBCPP_INLINE_VISIBILITY int __libcpp_tolower(int __c) {return tolower(__c);} -#undef tolower -inline _LIBCPP_INLINE_VISIBILITY int tolower(int __c) {return __libcpp_tolower(__c);} -#else // tolower using ::tolower; -#endif // tolower - -#ifdef toupper -inline _LIBCPP_INLINE_VISIBILITY int __libcpp_toupper(int __c) {return toupper(__c);} -#undef toupper -inline _LIBCPP_INLINE_VISIBILITY int toupper(int __c) {return __libcpp_toupper(__c);} -#else // toupper using ::toupper; -#endif // toupper _LIBCPP_END_NAMESPACE_STD diff --git a/include/cerrno b/include/cerrno index 9804e4e3dcfe..bab13b8aa861 100644 --- a/include/cerrno +++ b/include/cerrno @@ -30,364 +30,4 @@ Macros: #pragma GCC system_header #endif -#if !defined(EOWNERDEAD) || !defined(ENOTRECOVERABLE) - -#ifdef ELAST - -const int __elast1 = ELAST+1; -const int __elast2 = ELAST+2; - -#else - -const int __elast1 = 104; -const int __elast2 = 105; - -#endif - -#ifdef ENOTRECOVERABLE - -#define EOWNERDEAD __elast1 - -#ifdef ELAST -#undef ELAST -#define ELAST EOWNERDEAD -#endif - -#elif defined(EOWNERDEAD) - -#define ENOTRECOVERABLE __elast1 -#ifdef ELAST -#undef ELAST -#define ELAST ENOTRECOVERABLE -#endif - -#else // defined(EOWNERDEAD) - -#define EOWNERDEAD __elast1 -#define ENOTRECOVERABLE __elast2 -#ifdef ELAST -#undef ELAST -#define ELAST ENOTRECOVERABLE -#endif - -#endif // defined(EOWNERDEAD) - -#endif // !defined(EOWNERDEAD) || !defined(ENOTRECOVERABLE) - -// supply errno values likely to be missing, particularly on Windows - -#ifndef EAFNOSUPPORT -#define EAFNOSUPPORT 9901 -#endif - -#ifndef EADDRINUSE -#define EADDRINUSE 9902 -#endif - -#ifndef EADDRNOTAVAIL -#define EADDRNOTAVAIL 9903 -#endif - -#ifndef EISCONN -#define EISCONN 9904 -#endif - -#ifndef EBADMSG -#define EBADMSG 9905 -#endif - -#ifndef ECONNABORTED -#define ECONNABORTED 9906 -#endif - -#ifndef EALREADY -#define EALREADY 9907 -#endif - -#ifndef ECONNREFUSED -#define ECONNREFUSED 9908 -#endif - -#ifndef ECONNRESET -#define ECONNRESET 9909 -#endif - -#ifndef EDESTADDRREQ -#define EDESTADDRREQ 9910 -#endif - -#ifndef EHOSTUNREACH -#define EHOSTUNREACH 9911 -#endif - -#ifndef EIDRM -#define EIDRM 9912 -#endif - -#ifndef EMSGSIZE -#define EMSGSIZE 9913 -#endif - -#ifndef ENETDOWN -#define ENETDOWN 9914 -#endif - -#ifndef ENETRESET -#define ENETRESET 9915 -#endif - -#ifndef ENETUNREACH -#define ENETUNREACH 9916 -#endif - -#ifndef ENOBUFS -#define ENOBUFS 9917 -#endif - -#ifndef ENOLINK -#define ENOLINK 9918 -#endif - -#ifndef ENODATA -#define ENODATA 9919 -#endif - -#ifndef ENOMSG -#define ENOMSG 9920 -#endif - -#ifndef ENOPROTOOPT -#define ENOPROTOOPT 9921 -#endif - -#ifndef ENOSR -#define ENOSR 9922 -#endif - -#ifndef ENOTSOCK -#define ENOTSOCK 9923 -#endif - -#ifndef ENOSTR -#define ENOSTR 9924 -#endif - -#ifndef ENOTCONN -#define ENOTCONN 9925 -#endif - -#ifndef ENOTSUP -#define ENOTSUP 9926 -#endif - -#ifndef ECANCELED -#define ECANCELED 9927 -#endif - -#ifndef EINPROGRESS -#define EINPROGRESS 9928 -#endif - -#ifndef EOPNOTSUPP -#define EOPNOTSUPP 9929 -#endif - -#ifndef EWOULDBLOCK -#define EWOULDBLOCK 9930 -#endif - -#ifndef EOWNERDEAD -#define EOWNERDEAD 9931 -#endif - -#ifndef EPROTO -#define EPROTO 9932 -#endif - -#ifndef EPROTONOSUPPORT -#define EPROTONOSUPPORT 9933 -#endif - -#ifndef ENOTRECOVERABLE -#define ENOTRECOVERABLE 9934 -#endif - -#ifndef ETIME -#define ETIME 9935 -#endif - -#ifndef ETXTBSY -#define ETXTBSY 9936 -#endif - -#ifndef ETIMEDOUT -#define ETIMEDOUT 9938 -#endif - -#ifndef ELOOP -#define ELOOP 9939 -#endif - -#ifndef EOVERFLOW -#define EOVERFLOW 9940 -#endif - -#ifndef EPROTOTYPE -#define EPROTOTYPE 9941 -#endif - -#ifndef ENOSYS -#define ENOSYS 9942 -#endif - -#ifndef EINVAL -#define EINVAL 9943 -#endif - -#ifndef ERANGE -#define ERANGE 9944 -#endif - -#ifndef EILSEQ -#define EILSEQ 9945 -#endif - -// Windows Mobile doesn't appear to define these: - -#ifndef E2BIG -#define E2BIG 9946 -#endif - -#ifndef EDOM -#define EDOM 9947 -#endif - -#ifndef EFAULT -#define EFAULT 9948 -#endif - -#ifndef EBADF -#define EBADF 9949 -#endif - -#ifndef EPIPE -#define EPIPE 9950 -#endif - -#ifndef EXDEV -#define EXDEV 9951 -#endif - -#ifndef EBUSY -#define EBUSY 9952 -#endif - -#ifndef ENOTEMPTY -#define ENOTEMPTY 9953 -#endif - -#ifndef ENOEXEC -#define ENOEXEC 9954 -#endif - -#ifndef EEXIST -#define EEXIST 9955 -#endif - -#ifndef EFBIG -#define EFBIG 9956 -#endif - -#ifndef ENAMETOOLONG -#define ENAMETOOLONG 9957 -#endif - -#ifndef ENOTTY -#define ENOTTY 9958 -#endif - -#ifndef EINTR -#define EINTR 9959 -#endif - -#ifndef ESPIPE -#define ESPIPE 9960 -#endif - -#ifndef EIO -#define EIO 9961 -#endif - -#ifndef EISDIR -#define EISDIR 9962 -#endif - -#ifndef ECHILD -#define ECHILD 9963 -#endif - -#ifndef ENOLCK -#define ENOLCK 9964 -#endif - -#ifndef ENOSPC -#define ENOSPC 9965 -#endif - -#ifndef ENXIO -#define ENXIO 9966 -#endif - -#ifndef ENODEV -#define ENODEV 9967 -#endif - -#ifndef ENOENT -#define ENOENT 9968 -#endif - -#ifndef ESRCH -#define ESRCH 9969 -#endif - -#ifndef ENOTDIR -#define ENOTDIR 9970 -#endif - -#ifndef ENOMEM -#define ENOMEM 9971 -#endif - -#ifndef EPERM -#define EPERM 9972 -#endif - -#ifndef EACCES -#define EACCES 9973 -#endif - -#ifndef EROFS -#define EROFS 9974 -#endif - -#ifndef EDEADLK -#define EDEADLK 9975 -#endif - -#ifndef EAGAIN -#define EAGAIN 9976 -#endif - -#ifndef ENFILE -#define ENFILE 9977 -#endif - -#ifndef EMFILE -#define EMFILE 9978 -#endif - -#ifndef EMLINK -#define EMLINK 9979 -#endif - #endif // _LIBCPP_CERRNO diff --git a/include/cfenv b/include/cfenv index dd7db37f8e48..4fc630419bde 100644 --- a/include/cfenv +++ b/include/cfenv @@ -1,5 +1,5 @@ // -*- C++ -*- -//===---------------------------- cctype ----------------------------------===// +//===---------------------------- cfenv -----------------------------------===// // // The LLVM Compiler Infrastructure // diff --git a/include/cfloat b/include/cfloat index 5fa56550fa6a..176fa9de3cec 100644 --- a/include/cfloat +++ b/include/cfloat @@ -67,12 +67,4 @@ Macros: #pragma GCC system_header #endif -#ifndef FLT_EVAL_METHOD -#define FLT_EVAL_METHOD __FLT_EVAL_METHOD__ -#endif - -#ifndef DECIMAL_DIG -#define DECIMAL_DIG __DECIMAL_DIG__ -#endif - #endif // _LIBCPP_CFLOAT diff --git a/include/chrono b/include/chrono index 9229234ce55a..68484e982432 100644 --- a/include/chrono +++ b/include/chrono @@ -26,6 +26,9 @@ duration_cast(const duration<Rep, Period>& fd); template <class Rep> struct treat_as_floating_point : is_floating_point<Rep> {}; +template <class Rep> constexpr bool treat_as_floating_point_v + = treat_as_floating_point<Rep>::value; // C++17 + template <class Rep> struct duration_values { @@ -194,6 +197,13 @@ template <class Rep1, class Period1, class Rep2, class Period2> template <class ToDuration, class Rep, class Period> ToDuration duration_cast(const duration<Rep, Period>& d); +template <class ToDuration, class Rep, class Period> + constexpr ToDuration floor(const duration<Rep, Period>& d); // C++17 +template <class ToDuration, class Rep, class Period> + constexpr ToDuration ceil(const duration<Rep, Period>& d); // C++17 +template <class ToDuration, class Rep, class Period> + constexpr ToDuration round(const duration<Rep, Period>& d); // C++17 + // time_point arithmetic (all constexpr in C++14) template <class Clock, class Duration1, class Rep2, class Period2> time_point<Clock, typename common_type<Duration1, duration<Rep2, Period2>>::type> @@ -227,6 +237,20 @@ template <class Clock, class Duration1, class Duration2> template <class ToDuration, class Clock, class Duration> time_point<Clock, ToDuration> time_point_cast(const time_point<Clock, Duration>& t); +template <class ToDuration, class Clock, class Duration> + constexpr time_point<Clock, ToDuration> + floor(const time_point<Clock, Duration>& tp); // C++17 + +template <class ToDuration, class Clock, class Duration> + constexpr time_point<Clock, ToDuration> + ceil(const time_point<Clock, Duration>& tp); // C++17 + +template <class ToDuration, class Clock, class Duration> + constexpr time_point<Clock, ToDuration> + round(const time_point<Clock, Duration>& tp); // C++17 + +template <class Rep, class Period> + constexpr duration<Rep, Period> abs(duration<Rep, Period> d); // C++17 // Clocks class system_clock @@ -392,6 +416,11 @@ duration_cast(const duration<_Rep, _Period>& __fd) template <class _Rep> struct _LIBCPP_TYPE_VIS_ONLY treat_as_floating_point : is_floating_point<_Rep> {}; +#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_VARIABLE_TEMPLATES) +template <class _Rep> _LIBCPP_CONSTEXPR bool treat_as_floating_point_v + = treat_as_floating_point<_Rep>::value; +#endif + template <class _Rep> struct _LIBCPP_TYPE_VIS_ONLY duration_values { @@ -401,6 +430,58 @@ public: _LIBCPP_INLINE_VISIBILITY static _LIBCPP_CONSTEXPR _Rep min() {return numeric_limits<_Rep>::lowest();} }; +#if _LIBCPP_STD_VER > 14 +template <class _ToDuration, class _Rep, class _Period> +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR +typename enable_if +< + __is_duration<_ToDuration>::value, + _ToDuration +>::type +floor(const duration<_Rep, _Period>& __d) +{ + _ToDuration __t = duration_cast<_ToDuration>(__d); + if (__t > __d) + __t = __t - _ToDuration{1}; + return __t; +} + +template <class _ToDuration, class _Rep, class _Period> +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR +typename enable_if +< + __is_duration<_ToDuration>::value, + _ToDuration +>::type +ceil(const duration<_Rep, _Period>& __d) +{ + _ToDuration __t = duration_cast<_ToDuration>(__d); + if (__t < __d) + __t = __t + _ToDuration{1}; + return __t; +} + +template <class _ToDuration, class _Rep, class _Period> +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR +typename enable_if +< + __is_duration<_ToDuration>::value, + _ToDuration +>::type +round(const duration<_Rep, _Period>& __d) +{ + _ToDuration __lower = floor<_ToDuration>(__d); + _ToDuration __upper = __lower + _ToDuration{1}; + auto __lowerDiff = __d - __lower; + auto __upperDiff = __upper - __d; + if (__lowerDiff < __upperDiff) + return __lower; + if (__lowerDiff > __upperDiff) + return __upper; + return __lower.count() & 1 ? __upper : __lower; +} +#endif + // duration template <class _Rep, class _Period> @@ -807,6 +888,56 @@ time_point_cast(const time_point<_Clock, _Duration>& __t) return time_point<_Clock, _ToDuration>(_VSTD::chrono::duration_cast<_ToDuration>(__t.time_since_epoch())); } +#if _LIBCPP_STD_VER > 14 +template <class _ToDuration, class _Clock, class _Duration> +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR +typename enable_if +< + __is_duration<_ToDuration>::value, + time_point<_Clock, _ToDuration> +>::type +floor(const time_point<_Clock, _Duration>& __t) +{ + return time_point<_Clock, _ToDuration>{floor<_ToDuration>(__t.time_since_epoch())}; +} + +template <class _ToDuration, class _Clock, class _Duration> +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR +typename enable_if +< + __is_duration<_ToDuration>::value, + time_point<_Clock, _ToDuration> +>::type +ceil(const time_point<_Clock, _Duration>& __t) +{ + return time_point<_Clock, _ToDuration>{ceil<_ToDuration>(__t.time_since_epoch())}; +} + +template <class _ToDuration, class _Clock, class _Duration> +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR +typename enable_if +< + __is_duration<_ToDuration>::value, + time_point<_Clock, _ToDuration> +>::type +round(const time_point<_Clock, _Duration>& __t) +{ + return time_point<_Clock, _ToDuration>{round<_ToDuration>(__t.time_since_epoch())}; +} + +template <class _Rep, class _Period> +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR +typename enable_if +< + numeric_limits<_Rep>::is_signed, + duration<_Rep, _Period> +>::type +abs(duration<_Rep, _Period> __d) +{ + return __d >= __d.zero() ? __d : -__d; +} +#endif + // time_point == template <class _Clock, class _Duration1, class _Duration2> diff --git a/include/cinttypes b/include/cinttypes index cfd763c98f4a..3f61b0634b17 100644 --- a/include/cinttypes +++ b/include/cinttypes @@ -246,10 +246,7 @@ uintmax_t wcstoumax(const wchar_t* restrict nptr, wchar_t** restrict endptr, int _LIBCPP_BEGIN_NAMESPACE_STD using::imaxdiv_t; - -#undef imaxabs using::imaxabs; -#undef imaxdiv using::imaxdiv; using::strtoimax; using::strtoumax; diff --git a/include/cmath b/include/cmath index 5f9aaedd5afa..ebbde18168ff 100644 --- a/include/cmath +++ b/include/cmath @@ -299,340 +299,11 @@ long double truncl(long double x); #include <__config> #include <math.h> -#include <type_traits> - -#ifdef _LIBCPP_MSVCRT -#include "support/win32/math_win32.h" -#endif #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) #pragma GCC system_header #endif -// signbit - -#ifdef signbit - -template <class _A1> -_LIBCPP_ALWAYS_INLINE -bool -__libcpp_signbit(_A1 __lcpp_x) _NOEXCEPT -{ - return signbit(__lcpp_x); -} - -#undef signbit - -template <class _A1> -inline _LIBCPP_INLINE_VISIBILITY -typename std::enable_if<std::is_arithmetic<_A1>::value, bool>::type -signbit(_A1 __lcpp_x) _NOEXCEPT -{ - return __libcpp_signbit((typename std::__promote<_A1>::type)__lcpp_x); -} - -#endif // signbit - -// fpclassify - -#ifdef fpclassify - -template <class _A1> -_LIBCPP_ALWAYS_INLINE -int -__libcpp_fpclassify(_A1 __lcpp_x) _NOEXCEPT -{ - return fpclassify(__lcpp_x); -} - -#undef fpclassify - -template <class _A1> -inline _LIBCPP_INLINE_VISIBILITY -typename std::enable_if<std::is_arithmetic<_A1>::value, int>::type -fpclassify(_A1 __lcpp_x) _NOEXCEPT -{ - return __libcpp_fpclassify((typename std::__promote<_A1>::type)__lcpp_x); -} - -#endif // fpclassify - -// isfinite - -#ifdef isfinite - -template <class _A1> -_LIBCPP_ALWAYS_INLINE -bool -__libcpp_isfinite(_A1 __lcpp_x) _NOEXCEPT -{ - return isfinite(__lcpp_x); -} - -#undef isfinite - -template <class _A1> -inline _LIBCPP_INLINE_VISIBILITY -typename std::enable_if<std::is_arithmetic<_A1>::value, bool>::type -isfinite(_A1 __lcpp_x) _NOEXCEPT -{ - return __libcpp_isfinite((typename std::__promote<_A1>::type)__lcpp_x); -} - -#endif // isfinite - -// isinf - -#ifdef isinf - -template <class _A1> -_LIBCPP_ALWAYS_INLINE -bool -__libcpp_isinf(_A1 __lcpp_x) _NOEXCEPT -{ - return isinf(__lcpp_x); -} - -#undef isinf - -template <class _A1> -inline _LIBCPP_INLINE_VISIBILITY -typename std::enable_if<std::is_arithmetic<_A1>::value, bool>::type -isinf(_A1 __lcpp_x) _NOEXCEPT -{ - return __libcpp_isinf((typename std::__promote<_A1>::type)__lcpp_x); -} - -#endif // isinf - -// isnan - -#ifdef isnan - -template <class _A1> -_LIBCPP_ALWAYS_INLINE -bool -__libcpp_isnan(_A1 __lcpp_x) _NOEXCEPT -{ - return isnan(__lcpp_x); -} - -#undef isnan - -template <class _A1> -inline _LIBCPP_INLINE_VISIBILITY -typename std::enable_if<std::is_arithmetic<_A1>::value, bool>::type -isnan(_A1 __lcpp_x) _NOEXCEPT -{ - return __libcpp_isnan((typename std::__promote<_A1>::type)__lcpp_x); -} - -#endif // isnan - -// isnormal - -#ifdef isnormal - -template <class _A1> -_LIBCPP_ALWAYS_INLINE -bool -__libcpp_isnormal(_A1 __lcpp_x) _NOEXCEPT -{ - return isnormal(__lcpp_x); -} - -#undef isnormal - -template <class _A1> -inline _LIBCPP_INLINE_VISIBILITY -typename std::enable_if<std::is_arithmetic<_A1>::value, bool>::type -isnormal(_A1 __lcpp_x) _NOEXCEPT -{ - return __libcpp_isnormal((typename std::__promote<_A1>::type)__lcpp_x); -} - -#endif // isnormal - -// isgreater - -#ifdef isgreater - -template <class _A1, class _A2> -_LIBCPP_ALWAYS_INLINE -bool -__libcpp_isgreater(_A1 __lcpp_x, _A2 __lcpp_y) _NOEXCEPT -{ - return isgreater(__lcpp_x, __lcpp_y); -} - -#undef isgreater - -template <class _A1, class _A2> -inline _LIBCPP_INLINE_VISIBILITY -typename std::enable_if -< - std::is_arithmetic<_A1>::value && - std::is_arithmetic<_A2>::value, - bool ->::type -isgreater(_A1 __lcpp_x, _A2 __lcpp_y) _NOEXCEPT -{ - typedef typename std::__promote<_A1, _A2>::type type; - return __libcpp_isgreater((type)__lcpp_x, (type)__lcpp_y); -} - -#endif // isgreater - -// isgreaterequal - -#ifdef isgreaterequal - -template <class _A1, class _A2> -_LIBCPP_ALWAYS_INLINE -bool -__libcpp_isgreaterequal(_A1 __lcpp_x, _A2 __lcpp_y) _NOEXCEPT -{ - return isgreaterequal(__lcpp_x, __lcpp_y); -} - -#undef isgreaterequal - -template <class _A1, class _A2> -inline _LIBCPP_INLINE_VISIBILITY -typename std::enable_if -< - std::is_arithmetic<_A1>::value && - std::is_arithmetic<_A2>::value, - bool ->::type -isgreaterequal(_A1 __lcpp_x, _A2 __lcpp_y) _NOEXCEPT -{ - typedef typename std::__promote<_A1, _A2>::type type; - return __libcpp_isgreaterequal((type)__lcpp_x, (type)__lcpp_y); -} - -#endif // isgreaterequal - -// isless - -#ifdef isless - -template <class _A1, class _A2> -_LIBCPP_ALWAYS_INLINE -bool -__libcpp_isless(_A1 __lcpp_x, _A2 __lcpp_y) _NOEXCEPT -{ - return isless(__lcpp_x, __lcpp_y); -} - -#undef isless - -template <class _A1, class _A2> -inline _LIBCPP_INLINE_VISIBILITY -typename std::enable_if -< - std::is_arithmetic<_A1>::value && - std::is_arithmetic<_A2>::value, - bool ->::type -isless(_A1 __lcpp_x, _A2 __lcpp_y) _NOEXCEPT -{ - typedef typename std::__promote<_A1, _A2>::type type; - return __libcpp_isless((type)__lcpp_x, (type)__lcpp_y); -} - -#endif // isless - -// islessequal - -#ifdef islessequal - -template <class _A1, class _A2> -_LIBCPP_ALWAYS_INLINE -bool -__libcpp_islessequal(_A1 __lcpp_x, _A2 __lcpp_y) _NOEXCEPT -{ - return islessequal(__lcpp_x, __lcpp_y); -} - -#undef islessequal - -template <class _A1, class _A2> -inline _LIBCPP_INLINE_VISIBILITY -typename std::enable_if -< - std::is_arithmetic<_A1>::value && - std::is_arithmetic<_A2>::value, - bool ->::type -islessequal(_A1 __lcpp_x, _A2 __lcpp_y) _NOEXCEPT -{ - typedef typename std::__promote<_A1, _A2>::type type; - return __libcpp_islessequal((type)__lcpp_x, (type)__lcpp_y); -} - -#endif // islessequal - -// islessgreater - -#ifdef islessgreater - -template <class _A1, class _A2> -_LIBCPP_ALWAYS_INLINE -bool -__libcpp_islessgreater(_A1 __lcpp_x, _A2 __lcpp_y) _NOEXCEPT -{ - return islessgreater(__lcpp_x, __lcpp_y); -} - -#undef islessgreater - -template <class _A1, class _A2> -inline _LIBCPP_INLINE_VISIBILITY -typename std::enable_if -< - std::is_arithmetic<_A1>::value && - std::is_arithmetic<_A2>::value, - bool ->::type -islessgreater(_A1 __lcpp_x, _A2 __lcpp_y) _NOEXCEPT -{ - typedef typename std::__promote<_A1, _A2>::type type; - return __libcpp_islessgreater((type)__lcpp_x, (type)__lcpp_y); -} - -#endif // islessgreater - -// isunordered - -#ifdef isunordered - -template <class _A1, class _A2> -_LIBCPP_ALWAYS_INLINE -bool -__libcpp_isunordered(_A1 __lcpp_x, _A2 __lcpp_y) _NOEXCEPT -{ - return isunordered(__lcpp_x, __lcpp_y); -} - -#undef isunordered - -template <class _A1, class _A2> -inline _LIBCPP_INLINE_VISIBILITY -typename std::enable_if -< - std::is_arithmetic<_A1>::value && - std::is_arithmetic<_A2>::value, - bool ->::type -isunordered(_A1 __lcpp_x, _A2 __lcpp_y) _NOEXCEPT -{ - typedef typename std::__promote<_A1, _A2>::type type; - return __libcpp_isunordered((type)__lcpp_x, (type)__lcpp_y); -} - -#endif // isunordered - _LIBCPP_BEGIN_NAMESPACE_STD using ::signbit; @@ -652,794 +323,130 @@ using ::isunordered; using ::float_t; using ::double_t; -// abs - -#if defined(__sun__) +#ifndef _AIX using ::abs; #endif -#if !defined(_AIX) && !defined(__sun__) -inline _LIBCPP_INLINE_VISIBILITY -float -abs(float __lcpp_x) _NOEXCEPT {return fabsf(__lcpp_x);} - -inline _LIBCPP_INLINE_VISIBILITY -double -abs(double __lcpp_x) _NOEXCEPT {return fabs(__lcpp_x);} - -inline _LIBCPP_INLINE_VISIBILITY -long double -abs(long double __lcpp_x) _NOEXCEPT {return fabsl(__lcpp_x);} -#endif // !defined(_AIX) - #ifndef __sun__ - -// acos - using ::acos; using ::acosf; - -#if !(defined(_LIBCPP_MSVCRT) || defined(_AIX)) -inline _LIBCPP_INLINE_VISIBILITY float acos(float __lcpp_x) _NOEXCEPT {return acosf(__lcpp_x);} -inline _LIBCPP_INLINE_VISIBILITY long double acos(long double __lcpp_x) _NOEXCEPT {return acosl(__lcpp_x);} -#endif - -template <class _A1> -inline _LIBCPP_INLINE_VISIBILITY -typename enable_if<is_integral<_A1>::value, double>::type -acos(_A1 __lcpp_x) _NOEXCEPT {return acos((double)__lcpp_x);} - -// asin - using ::asin; using ::asinf; - -#if !(defined(_LIBCPP_MSVCRT) || defined(_AIX)) -inline _LIBCPP_INLINE_VISIBILITY float asin(float __lcpp_x) _NOEXCEPT {return asinf(__lcpp_x);} -inline _LIBCPP_INLINE_VISIBILITY long double asin(long double __lcpp_x) _NOEXCEPT {return asinl(__lcpp_x);} -#endif - -template <class _A1> -inline _LIBCPP_INLINE_VISIBILITY -typename enable_if<is_integral<_A1>::value, double>::type -asin(_A1 __lcpp_x) _NOEXCEPT {return asin((double)__lcpp_x);} - -// atan - using ::atan; using ::atanf; - -#if !(defined(_LIBCPP_MSVCRT) || defined(_AIX)) -inline _LIBCPP_INLINE_VISIBILITY float atan(float __lcpp_x) _NOEXCEPT {return atanf(__lcpp_x);} -inline _LIBCPP_INLINE_VISIBILITY long double atan(long double __lcpp_x) _NOEXCEPT {return atanl(__lcpp_x);} -#endif - -template <class _A1> -inline _LIBCPP_INLINE_VISIBILITY -typename enable_if<is_integral<_A1>::value, double>::type -atan(_A1 __lcpp_x) _NOEXCEPT {return atan((double)__lcpp_x);} - -// atan2 - using ::atan2; using ::atan2f; - -#if !(defined(_LIBCPP_MSVCRT) || defined(_AIX)) -inline _LIBCPP_INLINE_VISIBILITY float atan2(float __lcpp_y, float __lcpp_x) _NOEXCEPT {return atan2f(__lcpp_y, __lcpp_x);} -inline _LIBCPP_INLINE_VISIBILITY long double atan2(long double __lcpp_y, long double __lcpp_x) _NOEXCEPT {return atan2l(__lcpp_y, __lcpp_x);} -#endif - -template <class _A1, class _A2> -inline _LIBCPP_INLINE_VISIBILITY -typename __lazy_enable_if -< - is_arithmetic<_A1>::value && - is_arithmetic<_A2>::value, - __promote<_A1, _A2> ->::type -atan2(_A1 __lcpp_y, _A2 __lcpp_x) _NOEXCEPT -{ - 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)__lcpp_y, (__result_type)__lcpp_x); -} - -// ceil - using ::ceil; using ::ceilf; - -#if !(defined(_LIBCPP_MSVCRT) || defined(_AIX)) -inline _LIBCPP_INLINE_VISIBILITY float ceil(float __lcpp_x) _NOEXCEPT {return ceilf(__lcpp_x);} -inline _LIBCPP_INLINE_VISIBILITY long double ceil(long double __lcpp_x) _NOEXCEPT {return ceill(__lcpp_x);} -#endif - -template <class _A1> -inline _LIBCPP_INLINE_VISIBILITY -typename enable_if<is_integral<_A1>::value, double>::type -ceil(_A1 __lcpp_x) _NOEXCEPT {return ceil((double)__lcpp_x);} - -// cos - using ::cos; using ::cosf; - -#if !(defined(_LIBCPP_MSVCRT) || defined(_AIX)) -inline _LIBCPP_INLINE_VISIBILITY float cos(float __lcpp_x) _NOEXCEPT {return cosf(__lcpp_x);} -inline _LIBCPP_INLINE_VISIBILITY long double cos(long double __lcpp_x) _NOEXCEPT {return cosl(__lcpp_x);} -#endif - -template <class _A1> -inline _LIBCPP_INLINE_VISIBILITY -typename enable_if<is_integral<_A1>::value, double>::type -cos(_A1 __lcpp_x) _NOEXCEPT {return cos((double)__lcpp_x);} - -// cosh - using ::cosh; using ::coshf; - -#if !(defined(_LIBCPP_MSVCRT) || defined(_AIX)) -inline _LIBCPP_INLINE_VISIBILITY float cosh(float __lcpp_x) _NOEXCEPT {return coshf(__lcpp_x);} -inline _LIBCPP_INLINE_VISIBILITY long double cosh(long double __lcpp_x) _NOEXCEPT {return coshl(__lcpp_x);} -#endif - -template <class _A1> -inline _LIBCPP_INLINE_VISIBILITY -typename enable_if<is_integral<_A1>::value, double>::type -cosh(_A1 __lcpp_x) _NOEXCEPT {return cosh((double)__lcpp_x);} - #endif // __sun__ -// exp using ::exp; using ::expf; #ifndef __sun__ - -#if !(defined(_LIBCPP_MSVCRT) || defined(_AIX)) -inline _LIBCPP_INLINE_VISIBILITY float exp(float __lcpp_x) _NOEXCEPT {return expf(__lcpp_x);} -inline _LIBCPP_INLINE_VISIBILITY long double exp(long double __lcpp_x) _NOEXCEPT {return expl(__lcpp_x);} -#endif - - -template <class _A1> -inline _LIBCPP_INLINE_VISIBILITY -typename enable_if<is_integral<_A1>::value, double>::type -exp(_A1 __lcpp_x) _NOEXCEPT {return exp((double)__lcpp_x);} - -// fabs - using ::fabs; using ::fabsf; - -#if !(defined(_LIBCPP_MSVCRT) || defined(_AIX)) -inline _LIBCPP_INLINE_VISIBILITY float fabs(float __lcpp_x) _NOEXCEPT {return fabsf(__lcpp_x);} -inline _LIBCPP_INLINE_VISIBILITY long double fabs(long double __lcpp_x) _NOEXCEPT {return fabsl(__lcpp_x);} -#endif - -template <class _A1> -inline _LIBCPP_INLINE_VISIBILITY -typename enable_if<is_integral<_A1>::value, double>::type -fabs(_A1 __lcpp_x) _NOEXCEPT {return fabs((double)__lcpp_x);} - -// floor - using ::floor; using ::floorf; - -#if !(defined(_LIBCPP_MSVCRT) || defined(_AIX)) -inline _LIBCPP_INLINE_VISIBILITY float floor(float __lcpp_x) _NOEXCEPT {return floorf(__lcpp_x);} -inline _LIBCPP_INLINE_VISIBILITY long double floor(long double __lcpp_x) _NOEXCEPT {return floorl(__lcpp_x);} -#endif - -template <class _A1> -inline _LIBCPP_INLINE_VISIBILITY -typename enable_if<is_integral<_A1>::value, double>::type -floor(_A1 __lcpp_x) _NOEXCEPT {return floor((double)__lcpp_x);} - -// fmod - #endif //__sun__ + using ::fmod; using ::fmodf; -#ifndef __sun__ - -#if !(defined(_LIBCPP_MSVCRT) || defined(_AIX)) -inline _LIBCPP_INLINE_VISIBILITY float fmod(float __lcpp_x, float __lcpp_y) _NOEXCEPT {return fmodf(__lcpp_x, __lcpp_y);} -inline _LIBCPP_INLINE_VISIBILITY long double fmod(long double __lcpp_x, long double __lcpp_y) _NOEXCEPT {return fmodl(__lcpp_x, __lcpp_y);} -#endif - -template <class _A1, class _A2> -inline _LIBCPP_INLINE_VISIBILITY -typename __lazy_enable_if -< - is_arithmetic<_A1>::value && - is_arithmetic<_A2>::value, - __promote<_A1, _A2> ->::type -fmod(_A1 __lcpp_x, _A2 __lcpp_y) _NOEXCEPT -{ - 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)__lcpp_x, (__result_type)__lcpp_y); -} - - -// frexp +#ifndef __sun__ using ::frexp; using ::frexpf; - -#if !(defined(_LIBCPP_MSVCRT) || defined(_AIX)) -inline _LIBCPP_INLINE_VISIBILITY float frexp(float __lcpp_x, int* __lcpp_e) _NOEXCEPT {return frexpf(__lcpp_x, __lcpp_e);} -inline _LIBCPP_INLINE_VISIBILITY long double frexp(long double __lcpp_x, int* __lcpp_e) _NOEXCEPT {return frexpl(__lcpp_x, __lcpp_e);} -#endif - -template <class _A1> -inline _LIBCPP_INLINE_VISIBILITY -typename enable_if<is_integral<_A1>::value, double>::type -frexp(_A1 __lcpp_x, int* __lcpp_e) _NOEXCEPT {return frexp((double)__lcpp_x, __lcpp_e);} - -// ldexp - using ::ldexp; using ::ldexpf; - -#if !(defined(_LIBCPP_MSVCRT) || defined(_AIX)) -inline _LIBCPP_INLINE_VISIBILITY float ldexp(float __lcpp_x, int __lcpp_e) _NOEXCEPT {return ldexpf(__lcpp_x, __lcpp_e);} -inline _LIBCPP_INLINE_VISIBILITY long double ldexp(long double __lcpp_x, int __lcpp_e) _NOEXCEPT {return ldexpl(__lcpp_x, __lcpp_e);} -#endif - -template <class _A1> -inline _LIBCPP_INLINE_VISIBILITY -typename enable_if<is_integral<_A1>::value, double>::type -ldexp(_A1 __lcpp_x, int __lcpp_e) _NOEXCEPT {return ldexp((double)__lcpp_x, __lcpp_e);} - -// log - #endif // __sun__ + using ::log; using ::logf; -#ifndef __sun__ - -#if !(defined(_LIBCPP_MSVCRT) || defined(_AIX)) -inline _LIBCPP_INLINE_VISIBILITY float log(float __lcpp_x) _NOEXCEPT {return logf(__lcpp_x);} -inline _LIBCPP_INLINE_VISIBILITY long double log(long double __lcpp_x) _NOEXCEPT {return logl(__lcpp_x);} -#endif - -template <class _A1> -inline _LIBCPP_INLINE_VISIBILITY -typename enable_if<is_integral<_A1>::value, double>::type -log(_A1 __lcpp_x) _NOEXCEPT {return log((double)__lcpp_x);} - - -// log10 +#ifndef __sun__ using ::log10; using ::log10f; - -#if !(defined(_LIBCPP_MSVCRT) || defined(_AIX)) -inline _LIBCPP_INLINE_VISIBILITY float log10(float __lcpp_x) _NOEXCEPT {return log10f(__lcpp_x);} -inline _LIBCPP_INLINE_VISIBILITY long double log10(long double __lcpp_x) _NOEXCEPT {return log10l(__lcpp_x);} -#endif - -template <class _A1> -inline _LIBCPP_INLINE_VISIBILITY -typename enable_if<is_integral<_A1>::value, double>::type -log10(_A1 __lcpp_x) _NOEXCEPT {return log10((double)__lcpp_x);} - -// modf - using ::modf; using ::modff; - -#if !(defined(_LIBCPP_MSVCRT) || defined(_AIX)) -inline _LIBCPP_INLINE_VISIBILITY float modf(float __lcpp_x, float* __lcpp_y) _NOEXCEPT {return modff(__lcpp_x, __lcpp_y);} -inline _LIBCPP_INLINE_VISIBILITY long double modf(long double __lcpp_x, long double* __lcpp_y) _NOEXCEPT {return modfl(__lcpp_x, __lcpp_y);} -#endif - -// pow - #endif // __sun__ + using ::pow; using ::powf; #ifndef __sun__ - -#if !(defined(_LIBCPP_MSVCRT) || defined(_AIX)) -inline _LIBCPP_INLINE_VISIBILITY float pow(float __lcpp_x, float __lcpp_y) _NOEXCEPT {return powf(__lcpp_x, __lcpp_y);} -inline _LIBCPP_INLINE_VISIBILITY long double pow(long double __lcpp_x, long double __lcpp_y) _NOEXCEPT {return powl(__lcpp_x, __lcpp_y);} -#endif - -template <class _A1, class _A2> -inline _LIBCPP_INLINE_VISIBILITY -typename __lazy_enable_if -< - is_arithmetic<_A1>::value && - is_arithmetic<_A2>::value, - __promote<_A1, _A2> ->::type -pow(_A1 __lcpp_x, _A2 __lcpp_y) _NOEXCEPT -{ - 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)__lcpp_x, (__result_type)__lcpp_y); -} - -// sin - using ::sin; using ::sinf; - -#if !(defined(_LIBCPP_MSVCRT) || defined(_AIX)) -inline _LIBCPP_INLINE_VISIBILITY float sin(float __lcpp_x) _NOEXCEPT {return sinf(__lcpp_x);} -inline _LIBCPP_INLINE_VISIBILITY long double sin(long double __lcpp_x) _NOEXCEPT {return sinl(__lcpp_x);} -#endif - -template <class _A1> -inline _LIBCPP_INLINE_VISIBILITY -typename enable_if<is_integral<_A1>::value, double>::type -sin(_A1 __lcpp_x) _NOEXCEPT {return sin((double)__lcpp_x);} - -// sinh - using ::sinh; using ::sinhf; - -#if !(defined(_LIBCPP_MSVCRT) || defined(_AIX)) -inline _LIBCPP_INLINE_VISIBILITY float sinh(float __lcpp_x) _NOEXCEPT {return sinhf(__lcpp_x);} -inline _LIBCPP_INLINE_VISIBILITY long double sinh(long double __lcpp_x) _NOEXCEPT {return sinhl(__lcpp_x);} -#endif - -template <class _A1> -inline _LIBCPP_INLINE_VISIBILITY -typename enable_if<is_integral<_A1>::value, double>::type -sinh(_A1 __lcpp_x) _NOEXCEPT {return sinh((double)__lcpp_x);} - -// sqrt - #endif // __sun__ + using ::sqrt; using ::sqrtf; - - -#if !(defined(_LIBCPP_MSVCRT) || defined(__sun__) || defined(_AIX)) -inline _LIBCPP_INLINE_VISIBILITY float sqrt(float __lcpp_x) _NOEXCEPT {return sqrtf(__lcpp_x);} -inline _LIBCPP_INLINE_VISIBILITY long double sqrt(long double __lcpp_x) _NOEXCEPT {return sqrtl(__lcpp_x);} -#endif - -template <class _A1> -inline _LIBCPP_INLINE_VISIBILITY -typename enable_if<is_integral<_A1>::value, double>::type -sqrt(_A1 __lcpp_x) _NOEXCEPT {return sqrt((double)__lcpp_x);} - -// tan - using ::tan; using ::tanf; -#ifndef __sun__ - -#if !(defined(_LIBCPP_MSVCRT) || defined(_AIX)) -inline _LIBCPP_INLINE_VISIBILITY float tan(float __lcpp_x) _NOEXCEPT {return tanf(__lcpp_x);} -inline _LIBCPP_INLINE_VISIBILITY long double tan(long double __lcpp_x) _NOEXCEPT {return tanl(__lcpp_x);} -#endif - -template <class _A1> -inline _LIBCPP_INLINE_VISIBILITY -typename enable_if<is_integral<_A1>::value, double>::type -tan(_A1 __lcpp_x) _NOEXCEPT {return tan((double)__lcpp_x);} - -// tanh +#ifndef __sun__ using ::tanh; using ::tanhf; -#if !(defined(_LIBCPP_MSVCRT) || defined(_AIX)) -inline _LIBCPP_INLINE_VISIBILITY float tanh(float __lcpp_x) _NOEXCEPT {return tanhf(__lcpp_x);} -inline _LIBCPP_INLINE_VISIBILITY long double tanh(long double __lcpp_x) _NOEXCEPT {return tanhl(__lcpp_x);} -#endif - -template <class _A1> -inline _LIBCPP_INLINE_VISIBILITY -typename enable_if<is_integral<_A1>::value, double>::type -tanh(_A1 __lcpp_x) _NOEXCEPT {return tanh((double)__lcpp_x);} - -// acosh - #ifndef _LIBCPP_MSVCRT using ::acosh; using ::acoshf; - -inline _LIBCPP_INLINE_VISIBILITY float acosh(float __lcpp_x) _NOEXCEPT {return acoshf(__lcpp_x);} -inline _LIBCPP_INLINE_VISIBILITY long double acosh(long double __lcpp_x) _NOEXCEPT {return acoshl(__lcpp_x);} - -template <class _A1> -inline _LIBCPP_INLINE_VISIBILITY -typename enable_if<is_integral<_A1>::value, double>::type -acosh(_A1 __lcpp_x) _NOEXCEPT {return acosh((double)__lcpp_x);} -#endif - -// asinh - -#ifndef _LIBCPP_MSVCRT using ::asinh; using ::asinhf; - -inline _LIBCPP_INLINE_VISIBILITY float asinh(float __lcpp_x) _NOEXCEPT {return asinhf(__lcpp_x);} -inline _LIBCPP_INLINE_VISIBILITY long double asinh(long double __lcpp_x) _NOEXCEPT {return asinhl(__lcpp_x);} - -template <class _A1> -inline _LIBCPP_INLINE_VISIBILITY -typename enable_if<is_integral<_A1>::value, double>::type -asinh(_A1 __lcpp_x) _NOEXCEPT {return asinh((double)__lcpp_x);} -#endif - -// atanh - -#ifndef _LIBCPP_MSVCRT using ::atanh; using ::atanhf; - -inline _LIBCPP_INLINE_VISIBILITY float atanh(float __lcpp_x) _NOEXCEPT {return atanhf(__lcpp_x);} -inline _LIBCPP_INLINE_VISIBILITY long double atanh(long double __lcpp_x) _NOEXCEPT {return atanhl(__lcpp_x);} - -template <class _A1> -inline _LIBCPP_INLINE_VISIBILITY -typename enable_if<is_integral<_A1>::value, double>::type -atanh(_A1 __lcpp_x) _NOEXCEPT {return atanh((double)__lcpp_x);} -#endif - -// cbrt - -#ifndef _LIBCPP_MSVCRT using ::cbrt; using ::cbrtf; - -inline _LIBCPP_INLINE_VISIBILITY float cbrt(float __lcpp_x) _NOEXCEPT {return cbrtf(__lcpp_x);} -inline _LIBCPP_INLINE_VISIBILITY long double cbrt(long double __lcpp_x) _NOEXCEPT {return cbrtl(__lcpp_x);} - -template <class _A1> -inline _LIBCPP_INLINE_VISIBILITY -typename enable_if<is_integral<_A1>::value, double>::type -cbrt(_A1 __lcpp_x) _NOEXCEPT {return cbrt((double)__lcpp_x);} #endif -// copysign - using ::copysign; using ::copysignf; -#if !defined(_VC_CRT_MAJOR_VERSION) || (_VC_CRT_MAJOR_VERSION < 12) -inline _LIBCPP_INLINE_VISIBILITY float copysign(float __lcpp_x, - float __lcpp_y) _NOEXCEPT { - return copysignf(__lcpp_x, __lcpp_y); -} -inline _LIBCPP_INLINE_VISIBILITY long double -copysign(long double __lcpp_x, long double __lcpp_y) _NOEXCEPT { - return copysignl(__lcpp_x, __lcpp_y); -} -#endif - -template <class _A1, class _A2> -inline _LIBCPP_INLINE_VISIBILITY -typename __lazy_enable_if -< - is_arithmetic<_A1>::value && - is_arithmetic<_A2>::value, - __promote<_A1, _A2> ->::type -copysign(_A1 __lcpp_x, _A2 __lcpp_y) _NOEXCEPT -{ - 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)__lcpp_x, (__result_type)__lcpp_y); -} - #ifndef _LIBCPP_MSVCRT - -// erf - using ::erf; using ::erff; - -inline _LIBCPP_INLINE_VISIBILITY float erf(float __lcpp_x) _NOEXCEPT {return erff(__lcpp_x);} -inline _LIBCPP_INLINE_VISIBILITY long double erf(long double __lcpp_x) _NOEXCEPT {return erfl(__lcpp_x);} - -template <class _A1> -inline _LIBCPP_INLINE_VISIBILITY -typename enable_if<is_integral<_A1>::value, double>::type -erf(_A1 __lcpp_x) _NOEXCEPT {return erf((double)__lcpp_x);} - -// erfc - using ::erfc; using ::erfcf; - -inline _LIBCPP_INLINE_VISIBILITY float erfc(float __lcpp_x) _NOEXCEPT {return erfcf(__lcpp_x);} -inline _LIBCPP_INLINE_VISIBILITY long double erfc(long double __lcpp_x) _NOEXCEPT {return erfcl(__lcpp_x);} - -template <class _A1> -inline _LIBCPP_INLINE_VISIBILITY -typename enable_if<is_integral<_A1>::value, double>::type -erfc(_A1 __lcpp_x) _NOEXCEPT {return erfc((double)__lcpp_x);} - -// exp2 - using ::exp2; using ::exp2f; - -inline _LIBCPP_INLINE_VISIBILITY float exp2(float __lcpp_x) _NOEXCEPT {return exp2f(__lcpp_x);} -inline _LIBCPP_INLINE_VISIBILITY long double exp2(long double __lcpp_x) _NOEXCEPT {return exp2l(__lcpp_x);} - -template <class _A1> -inline _LIBCPP_INLINE_VISIBILITY -typename enable_if<is_integral<_A1>::value, double>::type -exp2(_A1 __lcpp_x) _NOEXCEPT {return exp2((double)__lcpp_x);} - -// expm1 - using ::expm1; using ::expm1f; - -inline _LIBCPP_INLINE_VISIBILITY float expm1(float __lcpp_x) _NOEXCEPT {return expm1f(__lcpp_x);} -inline _LIBCPP_INLINE_VISIBILITY long double expm1(long double __lcpp_x) _NOEXCEPT {return expm1l(__lcpp_x);} - -template <class _A1> -inline _LIBCPP_INLINE_VISIBILITY -typename enable_if<is_integral<_A1>::value, double>::type -expm1(_A1 __lcpp_x) _NOEXCEPT {return expm1((double)__lcpp_x);} - -// fdim - using ::fdim; using ::fdimf; - -inline _LIBCPP_INLINE_VISIBILITY float fdim(float __lcpp_x, float __lcpp_y) _NOEXCEPT {return fdimf(__lcpp_x, __lcpp_y);} -inline _LIBCPP_INLINE_VISIBILITY long double fdim(long double __lcpp_x, long double __lcpp_y) _NOEXCEPT {return fdiml(__lcpp_x, __lcpp_y);} - -template <class _A1, class _A2> -inline _LIBCPP_INLINE_VISIBILITY -typename __lazy_enable_if -< - is_arithmetic<_A1>::value && - is_arithmetic<_A2>::value, - __promote<_A1, _A2> ->::type -fdim(_A1 __lcpp_x, _A2 __lcpp_y) _NOEXCEPT -{ - 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)__lcpp_x, (__result_type)__lcpp_y); -} - -// fma - using ::fmaf; using ::fma; - -inline _LIBCPP_INLINE_VISIBILITY float fma(float __lcpp_x, float __lcpp_y, float __lcpp_z) _NOEXCEPT {return fmaf(__lcpp_x, __lcpp_y, __lcpp_z);} -inline _LIBCPP_INLINE_VISIBILITY long double fma(long double __lcpp_x, long double __lcpp_y, long double __lcpp_z) _NOEXCEPT {return fmal(__lcpp_x, __lcpp_y, __lcpp_z);} - -template <class _A1, class _A2, class _A3> -inline _LIBCPP_INLINE_VISIBILITY -typename __lazy_enable_if -< - is_arithmetic<_A1>::value && - is_arithmetic<_A2>::value && - is_arithmetic<_A3>::value, - __promote<_A1, _A2, _A3> ->::type -fma(_A1 __lcpp_x, _A2 __lcpp_y, _A3 __lcpp_z) _NOEXCEPT -{ - typedef typename __promote<_A1, _A2, _A3>::type __result_type; - static_assert((!(is_same<_A1, __result_type>::value && - is_same<_A2, __result_type>::value && - is_same<_A3, __result_type>::value)), ""); - return fma((__result_type)__lcpp_x, (__result_type)__lcpp_y, (__result_type)__lcpp_z); -} - -// fmax - using ::fmax; using ::fmaxf; - -inline _LIBCPP_INLINE_VISIBILITY float fmax(float __lcpp_x, float __lcpp_y) _NOEXCEPT {return fmaxf(__lcpp_x, __lcpp_y);} -inline _LIBCPP_INLINE_VISIBILITY long double fmax(long double __lcpp_x, long double __lcpp_y) _NOEXCEPT {return fmaxl(__lcpp_x, __lcpp_y);} - -template <class _A1, class _A2> -inline _LIBCPP_INLINE_VISIBILITY -typename __lazy_enable_if -< - is_arithmetic<_A1>::value && - is_arithmetic<_A2>::value, - __promote<_A1, _A2> ->::type -fmax(_A1 __lcpp_x, _A2 __lcpp_y) _NOEXCEPT -{ - 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)__lcpp_x, (__result_type)__lcpp_y); -} - -// fmin - using ::fmin; using ::fminf; - -inline _LIBCPP_INLINE_VISIBILITY float fmin(float __lcpp_x, float __lcpp_y) _NOEXCEPT {return fminf(__lcpp_x, __lcpp_y);} -inline _LIBCPP_INLINE_VISIBILITY long double fmin(long double __lcpp_x, long double __lcpp_y) _NOEXCEPT {return fminl(__lcpp_x, __lcpp_y);} - -template <class _A1, class _A2> -inline _LIBCPP_INLINE_VISIBILITY -typename __lazy_enable_if -< - is_arithmetic<_A1>::value && - is_arithmetic<_A2>::value, - __promote<_A1, _A2> ->::type -fmin(_A1 __lcpp_x, _A2 __lcpp_y) _NOEXCEPT -{ - 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)__lcpp_x, (__result_type)__lcpp_y); -} - -// hypot - using ::hypot; using ::hypotf; - -inline _LIBCPP_INLINE_VISIBILITY float hypot(float __lcpp_x, float __lcpp_y) _NOEXCEPT {return hypotf(__lcpp_x, __lcpp_y);} -inline _LIBCPP_INLINE_VISIBILITY long double hypot(long double __lcpp_x, long double __lcpp_y) _NOEXCEPT {return hypotl(__lcpp_x, __lcpp_y);} - -template <class _A1, class _A2> -inline _LIBCPP_INLINE_VISIBILITY -typename __lazy_enable_if -< - is_arithmetic<_A1>::value && - is_arithmetic<_A2>::value, - __promote<_A1, _A2> ->::type -hypot(_A1 __lcpp_x, _A2 __lcpp_y) _NOEXCEPT -{ - 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)__lcpp_x, (__result_type)__lcpp_y); -} - -// ilogb - using ::ilogb; using ::ilogbf; - -inline _LIBCPP_INLINE_VISIBILITY int ilogb(float __lcpp_x) _NOEXCEPT {return ilogbf(__lcpp_x);} -inline _LIBCPP_INLINE_VISIBILITY int ilogb(long double __lcpp_x) _NOEXCEPT {return ilogbl(__lcpp_x);} - -template <class _A1> -inline _LIBCPP_INLINE_VISIBILITY -typename enable_if<is_integral<_A1>::value, int>::type -ilogb(_A1 __lcpp_x) _NOEXCEPT {return ilogb((double)__lcpp_x);} - -// lgamma - using ::lgamma; using ::lgammaf; - -inline _LIBCPP_INLINE_VISIBILITY float lgamma(float __lcpp_x) _NOEXCEPT {return lgammaf(__lcpp_x);} -inline _LIBCPP_INLINE_VISIBILITY long double lgamma(long double __lcpp_x) _NOEXCEPT {return lgammal(__lcpp_x);} - - -template <class _A1> -inline _LIBCPP_INLINE_VISIBILITY -typename enable_if<is_integral<_A1>::value, double>::type -lgamma(_A1 __lcpp_x) _NOEXCEPT {return lgamma((double)__lcpp_x);} - - -// llrint - using ::llrint; using ::llrintf; - -inline _LIBCPP_INLINE_VISIBILITY long long llrint(float __lcpp_x) _NOEXCEPT {return llrintf(__lcpp_x);} -inline _LIBCPP_INLINE_VISIBILITY long long llrint(long double __lcpp_x) _NOEXCEPT {return llrintl(__lcpp_x);} - -template <class _A1> -inline _LIBCPP_INLINE_VISIBILITY -typename enable_if<is_integral<_A1>::value, long long>::type -llrint(_A1 __lcpp_x) _NOEXCEPT {return llrint((double)__lcpp_x);} - -// llround - using ::llround; using ::llroundf; - -inline _LIBCPP_INLINE_VISIBILITY long long llround(float __lcpp_x) _NOEXCEPT {return llroundf(__lcpp_x);} -inline _LIBCPP_INLINE_VISIBILITY long long llround(long double __lcpp_x) _NOEXCEPT {return llroundl(__lcpp_x);} - -template <class _A1> -inline _LIBCPP_INLINE_VISIBILITY -typename enable_if<is_integral<_A1>::value, long long>::type -llround(_A1 __lcpp_x) _NOEXCEPT {return llround((double)__lcpp_x);} - -// log1p - using ::log1p; using ::log1pf; - -inline _LIBCPP_INLINE_VISIBILITY float log1p(float __lcpp_x) _NOEXCEPT {return log1pf(__lcpp_x);} -inline _LIBCPP_INLINE_VISIBILITY long double log1p(long double __lcpp_x) _NOEXCEPT {return log1pl(__lcpp_x);} - -template <class _A1> -inline _LIBCPP_INLINE_VISIBILITY -typename enable_if<is_integral<_A1>::value, double>::type -log1p(_A1 __lcpp_x) _NOEXCEPT {return log1p((double)__lcpp_x);} - -// log2 - using ::log2; using ::log2f; - -inline _LIBCPP_INLINE_VISIBILITY float log2(float __lcpp_x) _NOEXCEPT {return log2f(__lcpp_x);} -inline _LIBCPP_INLINE_VISIBILITY long double log2(long double __lcpp_x) _NOEXCEPT {return log2l(__lcpp_x);} - -template <class _A1> -inline _LIBCPP_INLINE_VISIBILITY -typename enable_if<is_integral<_A1>::value, double>::type -log2(_A1 __lcpp_x) _NOEXCEPT {return log2((double)__lcpp_x);} - -// logb - using ::logb; using ::logbf; - -inline _LIBCPP_INLINE_VISIBILITY float logb(float __lcpp_x) _NOEXCEPT {return logbf(__lcpp_x);} -inline _LIBCPP_INLINE_VISIBILITY long double logb(long double __lcpp_x) _NOEXCEPT {return logbl(__lcpp_x);} - -template <class _A1> -inline _LIBCPP_INLINE_VISIBILITY -typename enable_if<is_integral<_A1>::value, double>::type -logb(_A1 __lcpp_x) _NOEXCEPT {return logb((double)__lcpp_x);} - -// lrint - using ::lrint; using ::lrintf; - -inline _LIBCPP_INLINE_VISIBILITY long lrint(float __lcpp_x) _NOEXCEPT {return lrintf(__lcpp_x);} -inline _LIBCPP_INLINE_VISIBILITY long lrint(long double __lcpp_x) _NOEXCEPT {return lrintl(__lcpp_x);} - -template <class _A1> -inline _LIBCPP_INLINE_VISIBILITY -typename enable_if<is_integral<_A1>::value, long>::type -lrint(_A1 __lcpp_x) _NOEXCEPT {return lrint((double)__lcpp_x);} - -// lround - using ::lround; using ::lroundf; - -inline _LIBCPP_INLINE_VISIBILITY long lround(float __lcpp_x) _NOEXCEPT {return lroundf(__lcpp_x);} -inline _LIBCPP_INLINE_VISIBILITY long lround(long double __lcpp_x) _NOEXCEPT {return lroundl(__lcpp_x);} - -template <class _A1> -inline _LIBCPP_INLINE_VISIBILITY -typename enable_if<is_integral<_A1>::value, long>::type -lround(_A1 __lcpp_x) _NOEXCEPT {return lround((double)__lcpp_x);} - #endif // _LIBCPP_MSVCRT #endif // __sun__ -// nan - #ifndef _LIBCPP_MSVCRT using ::nan; using ::nanf; @@ -1447,183 +454,28 @@ using ::nanf; #ifndef __sun__ #ifndef _LIBCPP_MSVCRT - -// nearbyint - using ::nearbyint; using ::nearbyintf; - -inline _LIBCPP_INLINE_VISIBILITY float nearbyint(float __lcpp_x) _NOEXCEPT {return nearbyintf(__lcpp_x);} -inline _LIBCPP_INLINE_VISIBILITY long double nearbyint(long double __lcpp_x) _NOEXCEPT {return nearbyintl(__lcpp_x);} - -template <class _A1> -inline _LIBCPP_INLINE_VISIBILITY -typename enable_if<is_integral<_A1>::value, double>::type -nearbyint(_A1 __lcpp_x) _NOEXCEPT {return nearbyint((double)__lcpp_x);} - -// nextafter - using ::nextafter; using ::nextafterf; - -inline _LIBCPP_INLINE_VISIBILITY float nextafter(float __lcpp_x, float __lcpp_y) _NOEXCEPT {return nextafterf(__lcpp_x, __lcpp_y);} -inline _LIBCPP_INLINE_VISIBILITY long double nextafter(long double __lcpp_x, long double __lcpp_y) _NOEXCEPT {return nextafterl(__lcpp_x, __lcpp_y);} - -template <class _A1, class _A2> -inline _LIBCPP_INLINE_VISIBILITY -typename __lazy_enable_if -< - is_arithmetic<_A1>::value && - is_arithmetic<_A2>::value, - __promote<_A1, _A2> ->::type -nextafter(_A1 __lcpp_x, _A2 __lcpp_y) _NOEXCEPT -{ - 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)__lcpp_x, (__result_type)__lcpp_y); -} - -// nexttoward - using ::nexttoward; using ::nexttowardf; - -inline _LIBCPP_INLINE_VISIBILITY float nexttoward(float __lcpp_x, long double __lcpp_y) _NOEXCEPT {return nexttowardf(__lcpp_x, __lcpp_y);} -inline _LIBCPP_INLINE_VISIBILITY long double nexttoward(long double __lcpp_x, long double __lcpp_y) _NOEXCEPT {return nexttowardl(__lcpp_x, __lcpp_y);} - -template <class _A1> -inline _LIBCPP_INLINE_VISIBILITY -typename enable_if<is_integral<_A1>::value, double>::type -nexttoward(_A1 __lcpp_x, long double __lcpp_y) _NOEXCEPT {return nexttoward((double)__lcpp_x, __lcpp_y);} - -// remainder - using ::remainder; using ::remainderf; - -inline _LIBCPP_INLINE_VISIBILITY float remainder(float __lcpp_x, float __lcpp_y) _NOEXCEPT {return remainderf(__lcpp_x, __lcpp_y);} -inline _LIBCPP_INLINE_VISIBILITY long double remainder(long double __lcpp_x, long double __lcpp_y) _NOEXCEPT {return remainderl(__lcpp_x, __lcpp_y);} - -template <class _A1, class _A2> -inline _LIBCPP_INLINE_VISIBILITY -typename __lazy_enable_if -< - is_arithmetic<_A1>::value && - is_arithmetic<_A2>::value, - __promote<_A1, _A2> ->::type -remainder(_A1 __lcpp_x, _A2 __lcpp_y) _NOEXCEPT -{ - 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)__lcpp_x, (__result_type)__lcpp_y); -} - -// remquo - using ::remquo; using ::remquof; - -inline _LIBCPP_INLINE_VISIBILITY float remquo(float __lcpp_x, float __lcpp_y, int* __lcpp_z) _NOEXCEPT {return remquof(__lcpp_x, __lcpp_y, __lcpp_z);} -inline _LIBCPP_INLINE_VISIBILITY long double remquo(long double __lcpp_x, long double __lcpp_y, int* __lcpp_z) _NOEXCEPT {return remquol(__lcpp_x, __lcpp_y, __lcpp_z);} - -template <class _A1, class _A2> -inline _LIBCPP_INLINE_VISIBILITY -typename __lazy_enable_if -< - is_arithmetic<_A1>::value && - is_arithmetic<_A2>::value, - __promote<_A1, _A2> ->::type -remquo(_A1 __lcpp_x, _A2 __lcpp_y, int* __lcpp_z) _NOEXCEPT -{ - 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)__lcpp_x, (__result_type)__lcpp_y, __lcpp_z); -} - -// rint - using ::rint; using ::rintf; - -inline _LIBCPP_INLINE_VISIBILITY float rint(float __lcpp_x) _NOEXCEPT {return rintf(__lcpp_x);} -inline _LIBCPP_INLINE_VISIBILITY long double rint(long double __lcpp_x) _NOEXCEPT {return rintl(__lcpp_x);} - -template <class _A1> -inline _LIBCPP_INLINE_VISIBILITY -typename enable_if<is_integral<_A1>::value, double>::type -rint(_A1 __lcpp_x) _NOEXCEPT {return rint((double)__lcpp_x);} - -// round - using ::round; using ::roundf; - -inline _LIBCPP_INLINE_VISIBILITY float round(float __lcpp_x) _NOEXCEPT {return roundf(__lcpp_x);} -inline _LIBCPP_INLINE_VISIBILITY long double round(long double __lcpp_x) _NOEXCEPT {return roundl(__lcpp_x);} - -template <class _A1> -inline _LIBCPP_INLINE_VISIBILITY -typename enable_if<is_integral<_A1>::value, double>::type -round(_A1 __lcpp_x) _NOEXCEPT {return round((double)__lcpp_x);} - -// scalbln - using ::scalbln; using ::scalblnf; - -inline _LIBCPP_INLINE_VISIBILITY float scalbln(float __lcpp_x, long __lcpp_y) _NOEXCEPT {return scalblnf(__lcpp_x, __lcpp_y);} -inline _LIBCPP_INLINE_VISIBILITY long double scalbln(long double __lcpp_x, long __lcpp_y) _NOEXCEPT {return scalblnl(__lcpp_x, __lcpp_y);} - -template <class _A1> -inline _LIBCPP_INLINE_VISIBILITY -typename enable_if<is_integral<_A1>::value, double>::type -scalbln(_A1 __lcpp_x, long __lcpp_y) _NOEXCEPT {return scalbln((double)__lcpp_x, __lcpp_y);} - -// scalbn - using ::scalbn; using ::scalbnf; - -inline _LIBCPP_INLINE_VISIBILITY float scalbn(float __lcpp_x, int __lcpp_y) _NOEXCEPT {return scalbnf(__lcpp_x, __lcpp_y);} -inline _LIBCPP_INLINE_VISIBILITY long double scalbn(long double __lcpp_x, int __lcpp_y) _NOEXCEPT {return scalbnl(__lcpp_x, __lcpp_y);} - -template <class _A1> -inline _LIBCPP_INLINE_VISIBILITY -typename enable_if<is_integral<_A1>::value, double>::type -scalbn(_A1 __lcpp_x, int __lcpp_y) _NOEXCEPT {return scalbn((double)__lcpp_x, __lcpp_y);} - -// tgamma - using ::tgamma; using ::tgammaf; - -inline _LIBCPP_INLINE_VISIBILITY float tgamma(float __lcpp_x) _NOEXCEPT {return tgammaf(__lcpp_x);} -inline _LIBCPP_INLINE_VISIBILITY long double tgamma(long double __lcpp_x) _NOEXCEPT {return tgammal(__lcpp_x);} - -template <class _A1> -inline _LIBCPP_INLINE_VISIBILITY -typename enable_if<is_integral<_A1>::value, double>::type -tgamma(_A1 __lcpp_x) _NOEXCEPT {return tgamma((double)__lcpp_x);} - -// trunc - using ::trunc; using ::truncf; - -inline _LIBCPP_INLINE_VISIBILITY float trunc(float __lcpp_x) _NOEXCEPT {return truncf(__lcpp_x);} -inline _LIBCPP_INLINE_VISIBILITY long double trunc(long double __lcpp_x) _NOEXCEPT {return truncl(__lcpp_x);} - -template <class _A1> -inline _LIBCPP_INLINE_VISIBILITY -typename enable_if<is_integral<_A1>::value, double>::type -trunc(_A1 __lcpp_x) _NOEXCEPT {return trunc((double)__lcpp_x);} - #endif // !_LIBCPP_MSVCRT using ::acosl; @@ -1647,6 +499,7 @@ using ::sinl; using ::sinhl; using ::sqrtl; using ::tanl; + #ifndef _LIBCPP_MSVCRT using ::tanhl; using ::acoshl; @@ -1654,7 +507,9 @@ using ::asinhl; using ::atanhl; using ::cbrtl; #endif // !_LIBCPP_MSVCRT + using ::copysignl; + #ifndef _LIBCPP_MSVCRT using ::erfl; using ::erfcl; @@ -1692,6 +547,7 @@ using ::truncl; using ::lgamma; using ::lgammaf; #endif // __sun__ + _LIBCPP_END_NAMESPACE_STD #endif // _LIBCPP_CMATH diff --git a/include/complex.h b/include/complex.h index 7003d31a89cd..c2359665add5 100644 --- a/include/complex.h +++ b/include/complex.h @@ -18,6 +18,12 @@ */ +#include <__config> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +#pragma GCC system_header +#endif + #ifdef __cplusplus #include <ccomplex> @@ -28,8 +34,4 @@ #endif // __cplusplus -#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) -#pragma GCC system_header -#endif - #endif // _LIBCPP_COMPLEX_H diff --git a/include/condition_variable b/include/condition_variable index 1af2484abd7b..10e007701672 100644 --- a/include/condition_variable +++ b/include/condition_variable @@ -124,14 +124,18 @@ class _LIBCPP_TYPE_VIS condition_variable_any condition_variable __cv_; shared_ptr<mutex> __mut_; public: + _LIBCPP_INLINE_VISIBILITY condition_variable_any(); + _LIBCPP_INLINE_VISIBILITY void notify_one() _NOEXCEPT; + _LIBCPP_INLINE_VISIBILITY void notify_all() _NOEXCEPT; template <class _Lock> void wait(_Lock& __lock); template <class _Lock, class _Predicate> + _LIBCPP_INLINE_VISIBILITY void wait(_Lock& __lock, _Predicate __pred); template <class _Lock, class _Clock, class _Duration> @@ -141,27 +145,30 @@ public: template <class _Lock, class _Clock, class _Duration, class _Predicate> bool + _LIBCPP_INLINE_VISIBILITY wait_until(_Lock& __lock, const chrono::time_point<_Clock, _Duration>& __t, _Predicate __pred); template <class _Lock, class _Rep, class _Period> cv_status + _LIBCPP_INLINE_VISIBILITY wait_for(_Lock& __lock, const chrono::duration<_Rep, _Period>& __d); template <class _Lock, class _Rep, class _Period, class _Predicate> bool + _LIBCPP_INLINE_VISIBILITY wait_for(_Lock& __lock, const chrono::duration<_Rep, _Period>& __d, _Predicate __pred); }; -inline _LIBCPP_INLINE_VISIBILITY +inline condition_variable_any::condition_variable_any() : __mut_(make_shared<mutex>()) {} -inline _LIBCPP_INLINE_VISIBILITY +inline void condition_variable_any::notify_one() _NOEXCEPT { @@ -169,7 +176,7 @@ condition_variable_any::notify_one() _NOEXCEPT __cv_.notify_one(); } -inline _LIBCPP_INLINE_VISIBILITY +inline void condition_variable_any::notify_all() _NOEXCEPT { @@ -196,7 +203,7 @@ condition_variable_any::wait(_Lock& __lock) } // __mut_.unlock(), __lock.lock() template <class _Lock, class _Predicate> -inline _LIBCPP_INLINE_VISIBILITY +inline void condition_variable_any::wait(_Lock& __lock, _Predicate __pred) { @@ -218,7 +225,7 @@ condition_variable_any::wait_until(_Lock& __lock, } // __mut_.unlock(), __lock.lock() template <class _Lock, class _Clock, class _Duration, class _Predicate> -inline _LIBCPP_INLINE_VISIBILITY +inline bool condition_variable_any::wait_until(_Lock& __lock, const chrono::time_point<_Clock, _Duration>& __t, @@ -231,7 +238,7 @@ condition_variable_any::wait_until(_Lock& __lock, } template <class _Lock, class _Rep, class _Period> -inline _LIBCPP_INLINE_VISIBILITY +inline cv_status condition_variable_any::wait_for(_Lock& __lock, const chrono::duration<_Rep, _Period>& __d) @@ -240,7 +247,7 @@ condition_variable_any::wait_for(_Lock& __lock, } template <class _Lock, class _Rep, class _Period, class _Predicate> -inline _LIBCPP_INLINE_VISIBILITY +inline bool condition_variable_any::wait_for(_Lock& __lock, const chrono::duration<_Rep, _Period>& __d, diff --git a/include/csetjmp b/include/csetjmp index d0b2c078967d..58a9c73ab56f 100644 --- a/include/csetjmp +++ b/include/csetjmp @@ -38,10 +38,6 @@ void longjmp(jmp_buf env, int val); #pragma GCC system_header #endif -#ifndef setjmp -#define setjmp(env) setjmp(env) -#endif - _LIBCPP_BEGIN_NAMESPACE_STD using ::jmp_buf; diff --git a/include/cstddef b/include/cstddef index c3ca64a9c014..edd106c001bc 100644 --- a/include/cstddef +++ b/include/cstddef @@ -35,12 +35,14 @@ Types: #include <__config> -#include <stddef.h> - #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) #pragma GCC system_header #endif +// Don't include our own <stddef.h>; we don't want to declare ::nullptr_t. +#include_next <stddef.h> +#include <__nullptr> + _LIBCPP_BEGIN_NAMESPACE_STD using ::ptrdiff_t; @@ -53,50 +55,6 @@ using ::max_align_t; typedef long double max_align_t; #endif -#ifdef _LIBCPP_HAS_NO_NULLPTR - -struct _LIBCPP_TYPE_VIS_ONLY nullptr_t -{ - void* __lx; - - struct __nat {int __for_bool_;}; - - _LIBCPP_ALWAYS_INLINE _LIBCPP_CONSTEXPR nullptr_t() : __lx(0) {} - _LIBCPP_ALWAYS_INLINE _LIBCPP_CONSTEXPR nullptr_t(int __nat::*) : __lx(0) {} - - _LIBCPP_ALWAYS_INLINE _LIBCPP_CONSTEXPR operator int __nat::*() const {return 0;} - - template <class _Tp> - _LIBCPP_ALWAYS_INLINE _LIBCPP_CONSTEXPR - operator _Tp* () const {return 0;} - - template <class _Tp, class _Up> - _LIBCPP_ALWAYS_INLINE - operator _Tp _Up::* () const {return 0;} - - friend _LIBCPP_ALWAYS_INLINE _LIBCPP_CONSTEXPR bool operator==(nullptr_t, nullptr_t) {return true;} - friend _LIBCPP_ALWAYS_INLINE _LIBCPP_CONSTEXPR bool operator!=(nullptr_t, nullptr_t) {return false;} - friend _LIBCPP_ALWAYS_INLINE _LIBCPP_CONSTEXPR bool operator<(nullptr_t, nullptr_t) {return false;} - friend _LIBCPP_ALWAYS_INLINE _LIBCPP_CONSTEXPR bool operator<=(nullptr_t, nullptr_t) {return true;} - friend _LIBCPP_ALWAYS_INLINE _LIBCPP_CONSTEXPR bool operator>(nullptr_t, nullptr_t) {return false;} - friend _LIBCPP_ALWAYS_INLINE _LIBCPP_CONSTEXPR bool operator>=(nullptr_t, nullptr_t) {return true;} -}; - -inline _LIBCPP_ALWAYS_INLINE _LIBCPP_CONSTEXPR nullptr_t __get_nullptr_t() {return nullptr_t(0);} - -#define nullptr _VSTD::__get_nullptr_t() - -#endif // _LIBCPP_HAS_NO_NULLPTR - _LIBCPP_END_NAMESPACE_STD -#ifndef _LIBCPP_HAS_NO_NULLPTR - -namespace std -{ - typedef decltype(nullptr) nullptr_t; -} - -#endif // _LIBCPP_HAS_NO_NULLPTR - #endif // _LIBCPP_CSTDDEF diff --git a/include/cstdio b/include/cstdio index d8ba6c2ef383..50fdd3457426 100644 --- a/include/cstdio +++ b/include/cstdio @@ -103,41 +103,6 @@ void perror(const char* s); #pragma GCC system_header #endif -// snprintf -#if defined(_LIBCPP_MSVCRT) -#include "support/win32/support.h" -#endif - -#ifdef getc -inline _LIBCPP_INLINE_VISIBILITY int __libcpp_getc(FILE* __stream) {return getc(__stream);} -#undef getc -inline _LIBCPP_INLINE_VISIBILITY int getc(FILE* __stream) {return __libcpp_getc(__stream);} -#endif // getc - -#ifdef putc -inline _LIBCPP_INLINE_VISIBILITY int __libcpp_putc(int __c, FILE* __stream) {return putc(__c, __stream);} -#undef putc -inline _LIBCPP_INLINE_VISIBILITY int putc(int __c, FILE* __stream) {return __libcpp_putc(__c, __stream);} -#endif // putc - -#ifdef clearerr -inline _LIBCPP_INLINE_VISIBILITY void __libcpp_clearerr(FILE* __stream) { return clearerr(__stream); } -#undef clearerr -inline _LIBCPP_INLINE_VISIBILITY void clearerr(FILE* __stream) { return __libcpp_clearerr(__stream); } -#endif // clearerr - -#ifdef feof -inline _LIBCPP_INLINE_VISIBILITY int __libcpp_feof(FILE* __stream) { return feof(__stream); } -#undef feof -inline _LIBCPP_INLINE_VISIBILITY int feof(FILE* __stream) { return __libcpp_feof(__stream); } -#endif // feof - -#ifdef ferror -inline _LIBCPP_INLINE_VISIBILITY int __libcpp_ferror(FILE* __stream) { return ferror(__stream); } -#undef ferror -inline _LIBCPP_INLINE_VISIBILITY int ferror(FILE* __stream) { return __libcpp_ferror(__stream); } -#endif // ferror - _LIBCPP_BEGIN_NAMESPACE_STD using ::FILE; diff --git a/include/cstdlib b/include/cstdlib index 55e15c82192e..10ed231078d8 100644 --- a/include/cstdlib +++ b/include/cstdlib @@ -84,9 +84,6 @@ void *aligned_alloc(size_t alignment, size_t size); // C11 #include <__config> #include <stdlib.h> -#ifdef _LIBCPP_MSVCRT -#include "support/win32/locale_win32.h" -#endif // _LIBCPP_MSVCRT #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) #pragma GCC system_header @@ -131,20 +128,14 @@ using ::getenv; using ::system; using ::bsearch; using ::qsort; -#undef abs using ::abs; -#undef labs using ::labs; #ifndef _LIBCPP_HAS_NO_LONG_LONG -#undef llabs using ::llabs; #endif // _LIBCPP_HAS_NO_LONG_LONG -#undef div using ::div; -#undef ldiv using ::ldiv; #ifndef _LIBCPP_HAS_NO_LONG_LONG -#undef lldiv using ::lldiv; #endif // _LIBCPP_HAS_NO_LONG_LONG #ifndef _LIBCPP_HAS_NO_THREAD_UNSAFE_C_FUNCTIONS @@ -162,19 +153,6 @@ using ::quick_exit; using ::aligned_alloc; #endif -// MSVCRT already has the correct prototype in <stdlib.h> #ifdef __cplusplus -#if !defined(_LIBCPP_MSVCRT) && !defined(__sun__) && !defined(_AIX) -inline _LIBCPP_INLINE_VISIBILITY long abs( long __x) _NOEXCEPT {return labs(__x);} -#ifndef _LIBCPP_HAS_NO_LONG_LONG -inline _LIBCPP_INLINE_VISIBILITY long long abs(long long __x) _NOEXCEPT {return llabs(__x);} -#endif // _LIBCPP_HAS_NO_LONG_LONG - -inline _LIBCPP_INLINE_VISIBILITY ldiv_t div( long __x, long __y) _NOEXCEPT {return ldiv(__x, __y);} -#ifndef _LIBCPP_HAS_NO_LONG_LONG -inline _LIBCPP_INLINE_VISIBILITY lldiv_t div(long long __x, long long __y) _NOEXCEPT {return lldiv(__x, __y);} -#endif // _LIBCPP_HAS_NO_LONG_LONG -#endif // _LIBCPP_MSVCRT - _LIBCPP_END_NAMESPACE_STD #endif // _LIBCPP_CSTDLIB diff --git a/include/ctype.h b/include/ctype.h new file mode 100644 index 000000000000..22d6c49be9e1 --- /dev/null +++ b/include/ctype.h @@ -0,0 +1,69 @@ +// -*- C++ -*- +//===---------------------------- ctype.h ---------------------------------===// +// +// 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_CTYPE_H +#define _LIBCPP_CTYPE_H + +/* + ctype.h synopsis + +int isalnum(int c); +int isalpha(int c); +int isblank(int c); // C99 +int iscntrl(int c); +int isdigit(int c); +int isgraph(int c); +int islower(int c); +int isprint(int c); +int ispunct(int c); +int isspace(int c); +int isupper(int c); +int isxdigit(int c); +int tolower(int c); +int toupper(int c); +*/ + +#include <__config> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +#include_next <ctype.h> + +#ifdef __cplusplus + +#if defined(_LIBCPP_MSVCRT) +// We support including .h headers inside 'extern "C"' contexts, so switch +// back to C++ linkage before including these C++ headers. +extern "C++" { + #include "support/win32/support.h" + #include "support/win32/locale_win32.h" +} +#endif // _LIBCPP_MSVCRT + +#undef isalnum +#undef isalpha +#undef isblank +#undef iscntrl +#undef isdigit +#undef isgraph +#undef islower +#undef isprint +#undef ispunct +#undef isspace +#undef isupper +#undef isxdigit +#undef tolower +#undef toupper + +#endif + +#endif // _LIBCPP_CTYPE_H diff --git a/include/cwchar b/include/cwchar index 797a1777c22f..ef4806db2bde 100644 --- a/include/cwchar +++ b/include/cwchar @@ -106,9 +106,6 @@ size_t wcsrtombs(char* restrict dst, const wchar_t** restrict src, size_t len, #include <__config> #include <cwctype> #include <wchar.h> -#if defined(_LIBCPP_MSVCRT) || defined(__MINGW32__) -#include <support/win32/support.h> // pull in *swprintf defines -#endif // _LIBCPP_MSVCRT #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) #pragma GCC system_header @@ -161,16 +158,13 @@ using ::wcscoll; using ::wcsncmp; using ::wcsxfrm; -#if defined(_WCHAR_H_CPLUSPLUS_98_CONFORMANCE_) - +#ifdef _LIBCPP_WCHAR_H_HAS_CONST_OVERLOADS using ::wcschr; using ::wcspbrk; using ::wcsrchr; using ::wcsstr; using ::wmemchr; - #else - inline _LIBCPP_INLINE_VISIBILITY const wchar_t* wcschr(const wchar_t* __s, wchar_t __c) {return ::wcschr(__s, __c);} inline _LIBCPP_INLINE_VISIBILITY wchar_t* wcschr( wchar_t* __s, wchar_t __c) {return ::wcschr(__s, __c);} @@ -185,7 +179,6 @@ inline _LIBCPP_INLINE_VISIBILITY wchar_t* wcsstr( wchar_t* __s1, cons inline _LIBCPP_INLINE_VISIBILITY const wchar_t* wmemchr(const wchar_t* __s, wchar_t __c, size_t __n) {return ::wmemchr(__s, __c, __n);} inline _LIBCPP_INLINE_VISIBILITY wchar_t* wmemchr( wchar_t* __s, wchar_t __c, size_t __n) {return ::wmemchr(__s, __c, __n);} - #endif using ::wcscspn; diff --git a/include/cwctype b/include/cwctype index 4f89b52db27c..25b2489edf2c 100644 --- a/include/cwctype +++ b/include/cwctype @@ -63,150 +63,24 @@ _LIBCPP_BEGIN_NAMESPACE_STD using ::wint_t; using ::wctrans_t; using ::wctype_t; - -#ifdef iswalnum -inline _LIBCPP_INLINE_VISIBILITY int __libcpp_iswalnum(wint_t __wc) {return iswalnum(__wc);} -#undef iswalnum -inline _LIBCPP_INLINE_VISIBILITY int iswalnum(wint_t __wc) {return __libcpp_iswalnum(__wc);} -#else // iswalnum using ::iswalnum; -#endif - -#ifdef iswalpha -inline _LIBCPP_INLINE_VISIBILITY int __libcpp_iswalpha(wint_t __wc) {return iswalpha(__wc);} -#undef iswalpha -inline _LIBCPP_INLINE_VISIBILITY int iswalpha(wint_t __wc) {return __libcpp_iswalpha(__wc);} -#else // iswalpha using ::iswalpha; -#endif - -#ifdef iswblank -inline _LIBCPP_INLINE_VISIBILITY int __libcpp_iswblank(wint_t __wc) {return iswblank(__wc);} -#undef iswblank -inline _LIBCPP_INLINE_VISIBILITY int iswblank(wint_t __wc) {return __libcpp_iswblank(__wc);} -#else // iswblank using ::iswblank; -#endif - -#ifdef iswcntrl -inline _LIBCPP_INLINE_VISIBILITY int __libcpp_iswcntrl(wint_t __wc) {return iswcntrl(__wc);} -#undef iswcntrl -inline _LIBCPP_INLINE_VISIBILITY int iswcntrl(wint_t __wc) {return __libcpp_iswcntrl(__wc);} -#else // iswcntrl using ::iswcntrl; -#endif - -#ifdef iswdigit -inline _LIBCPP_INLINE_VISIBILITY int __libcpp_iswdigit(wint_t __wc) {return iswdigit(__wc);} -#undef iswdigit -inline _LIBCPP_INLINE_VISIBILITY int iswdigit(wint_t __wc) {return __libcpp_iswdigit(__wc);} -#else // iswdigit using ::iswdigit; -#endif - -#ifdef iswgraph -inline _LIBCPP_INLINE_VISIBILITY int __libcpp_iswgraph(wint_t __wc) {return iswgraph(__wc);} -#undef iswgraph -inline _LIBCPP_INLINE_VISIBILITY int iswgraph(wint_t __wc) {return __libcpp_iswgraph(__wc);} -#else // iswgraph using ::iswgraph; -#endif - -#ifdef iswlower -inline _LIBCPP_INLINE_VISIBILITY int __libcpp_iswlower(wint_t __wc) {return iswlower(__wc);} -#undef iswlower -inline _LIBCPP_INLINE_VISIBILITY int iswlower(wint_t __wc) {return __libcpp_iswlower(__wc);} -#else // iswlower using ::iswlower; -#endif - -#ifdef iswprint -inline _LIBCPP_INLINE_VISIBILITY int __libcpp_iswprint(wint_t __wc) {return iswprint(__wc);} -#undef iswprint -inline _LIBCPP_INLINE_VISIBILITY int iswprint(wint_t __wc) {return __libcpp_iswprint(__wc);} -#else // iswprint using ::iswprint; -#endif - -#ifdef iswpunct -inline _LIBCPP_INLINE_VISIBILITY int __libcpp_iswpunct(wint_t __wc) {return iswpunct(__wc);} -#undef iswpunct -inline _LIBCPP_INLINE_VISIBILITY int iswpunct(wint_t __wc) {return __libcpp_iswpunct(__wc);} -#else // iswpunct using ::iswpunct; -#endif - -#ifdef iswspace -inline _LIBCPP_INLINE_VISIBILITY int __libcpp_iswspace(wint_t __wc) {return iswspace(__wc);} -#undef iswspace -inline _LIBCPP_INLINE_VISIBILITY int iswspace(wint_t __wc) {return __libcpp_iswspace(__wc);} -#else // iswspace using ::iswspace; -#endif - -#ifdef iswupper -inline _LIBCPP_INLINE_VISIBILITY int __libcpp_iswupper(wint_t __wc) {return iswupper(__wc);} -#undef iswupper -inline _LIBCPP_INLINE_VISIBILITY int iswupper(wint_t __wc) {return __libcpp_iswupper(__wc);} -#else // iswupper using ::iswupper; -#endif - -#ifdef iswxdigit -inline _LIBCPP_INLINE_VISIBILITY int __libcpp_iswxdigit(wint_t __wc) {return iswxdigit(__wc);} -#undef iswxdigit -inline _LIBCPP_INLINE_VISIBILITY int iswxdigit(wint_t __wc) {return __libcpp_iswxdigit(__wc);} -#else // iswxdigit using ::iswxdigit; -#endif - -#ifdef iswctype -inline _LIBCPP_INLINE_VISIBILITY int __libcpp_iswctype(wint_t __w, wctype_t __d) {return iswctype(__w, __d);} -#undef iswctype -inline _LIBCPP_INLINE_VISIBILITY int iswctype(wint_t __w, wctype_t __d) {return __libcpp_iswctype(__w, __d);} -#else // iswctype using ::iswctype; -#endif - -#ifdef wctype -inline _LIBCPP_INLINE_VISIBILITY wctype_t __libcpp_wctype(const char* __p) {return wctype(__p);} -#undef wctype -inline _LIBCPP_INLINE_VISIBILITY wctype_t wctype(const char* __p) {return __libcpp_wctype(__p);} -#else // wctype using ::wctype; -#endif - -#ifdef towlower -inline _LIBCPP_INLINE_VISIBILITY wint_t __libcpp_towlower(wint_t __wc) {return towlower(__wc);} -#undef towlower -inline _LIBCPP_INLINE_VISIBILITY wint_t towlower(wint_t __wc) {return __libcpp_towlower(__wc);} -#else // towlower using ::towlower; -#endif - -#ifdef towupper -inline _LIBCPP_INLINE_VISIBILITY wint_t __libcpp_towupper(wint_t __wc) {return towupper(__wc);} -#undef towupper -inline _LIBCPP_INLINE_VISIBILITY wint_t towupper(wint_t __wc) {return __libcpp_towupper(__wc);} -#else // towupper using ::towupper; -#endif - -#ifdef towctrans -inline _LIBCPP_INLINE_VISIBILITY wint_t __libcpp_towctrans(wint_t __wc, wctype_t __d) {return towctrans(__wc, __d);} -#undef towctrans -inline _LIBCPP_INLINE_VISIBILITY wint_t towctrans(wint_t __wc, wctype_t __d) {return __libcpp_towctrans(__wc, __d);} -#else // towctrans using ::towctrans; -#endif - -#ifdef wctrans -inline _LIBCPP_INLINE_VISIBILITY wctrans_t __libcpp_wctrans(const char* __p) {return wctrans(__p);} -#undef wctrans -inline _LIBCPP_INLINE_VISIBILITY wctrans_t wctrans(const char* __p) {return __libcpp_wctrans(__p);} -#else // wctrans using ::wctrans; -#endif _LIBCPP_END_NAMESPACE_STD diff --git a/include/deque b/include/deque index 5e152e425d0b..c6fbd512a1c6 100644 --- a/include/deque +++ b/include/deque @@ -261,8 +261,21 @@ move_backward(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f, __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __l, __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r); +template <class _ValueType, class _DiffType> +struct __deque_block_size { + static const _DiffType value = sizeof(_ValueType) < 256 ? 4096 / sizeof(_ValueType) : 16; +}; + template <class _ValueType, class _Pointer, class _Reference, class _MapPointer, - class _DiffType, _DiffType _BlockSize> + class _DiffType, _DiffType _BS = +#ifdef _LIBCPP_ABI_INCOMPLETE_TYPES_IN_DEQUE +// Keep template parameter to avoid changing all template declarations thoughout +// this file. + 0 +#else + __deque_block_size<_ValueType, _DiffType>::value +#endif + > class _LIBCPP_TYPE_VIS_ONLY __deque_iterator { typedef _MapPointer __map_iterator; @@ -273,7 +286,7 @@ private: __map_iterator __m_iter_; pointer __ptr_; - static const difference_type __block_size = _BlockSize; + static const difference_type __block_size; public: typedef _ValueType value_type; typedef random_access_iterator_tag iterator_category; @@ -287,7 +300,7 @@ public: template <class _Pp, class _Rp, class _MP> _LIBCPP_INLINE_VISIBILITY - __deque_iterator(const __deque_iterator<value_type, _Pp, _Rp, _MP, difference_type, __block_size>& __it, + __deque_iterator(const __deque_iterator<value_type, _Pp, _Rp, _MP, difference_type, _BS>& __it, typename enable_if<is_convertible<_Pp, pointer>::value>::type* = 0) _NOEXCEPT : __m_iter_(__it.__m_iter_), __ptr_(__it.__ptr_) {} @@ -520,6 +533,12 @@ private: __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2> __r); }; +template <class _ValueType, class _Pointer, class _Reference, class _MapPointer, + class _DiffType, _DiffType _BlockSize> +const _DiffType __deque_iterator<_ValueType, _Pointer, _Reference, _MapPointer, + _DiffType, _BlockSize>::__block_size = + __deque_block_size<_ValueType, _DiffType>::value; + // copy template <class _RAIter, @@ -532,10 +551,11 @@ copy(_RAIter __f, { typedef typename __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2>::difference_type difference_type; typedef typename __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2>::pointer pointer; + const difference_type __block_size = __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2>::__block_size; while (__f != __l) { pointer __rb = __r.__ptr_; - pointer __re = *__r.__m_iter_ + _B2; + pointer __re = *__r.__m_iter_ + __block_size; difference_type __bs = __re - __rb; difference_type __n = __l - __f; _RAIter __m = __l; @@ -560,11 +580,12 @@ copy(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f, { typedef typename __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1>::difference_type difference_type; typedef typename __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1>::pointer pointer; + const difference_type __block_size = __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1>::__block_size; difference_type __n = __l - __f; while (__n > 0) { pointer __fb = __f.__ptr_; - pointer __fe = *__f.__m_iter_ + _B1; + pointer __fe = *__f.__m_iter_ + __block_size; difference_type __bs = __fe - __fb; if (__bs > __n) { @@ -587,11 +608,12 @@ copy(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f, { typedef typename __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1>::difference_type difference_type; typedef typename __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1>::pointer pointer; + const difference_type __block_size = __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1>::__block_size; difference_type __n = __l - __f; while (__n > 0) { pointer __fb = __f.__ptr_; - pointer __fe = *__f.__m_iter_ + _B1; + pointer __fe = *__f.__m_iter_ + __block_size; difference_type __bs = __fe - __fb; if (__bs > __n) { @@ -705,10 +727,11 @@ move(_RAIter __f, { typedef typename __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2>::difference_type difference_type; typedef typename __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2>::pointer pointer; + const difference_type __block_size = __deque_iterator<_V2, _P2, _R2, _M2, _D2, _B2>::__block_size; while (__f != __l) { pointer __rb = __r.__ptr_; - pointer __re = *__r.__m_iter_ + _B2; + pointer __re = *__r.__m_iter_ + __block_size; difference_type __bs = __re - __rb; difference_type __n = __l - __f; _RAIter __m = __l; @@ -733,11 +756,12 @@ move(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f, { typedef typename __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1>::difference_type difference_type; typedef typename __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1>::pointer pointer; + const difference_type __block_size = __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1>::__block_size; difference_type __n = __l - __f; while (__n > 0) { pointer __fb = __f.__ptr_; - pointer __fe = *__f.__m_iter_ + _B1; + pointer __fe = *__f.__m_iter_ + __block_size; difference_type __bs = __fe - __fb; if (__bs > __n) { @@ -760,11 +784,12 @@ move(__deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1> __f, { typedef typename __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1>::difference_type difference_type; typedef typename __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1>::pointer pointer; + const difference_type __block_size = __deque_iterator<_V1, _P1, _R1, _M1, _D1, _B1>::__block_size; difference_type __n = __l - __f; while (__n > 0) { pointer __fb = __f.__ptr_; - pointer __fe = *__f.__m_iter_ + _B1; + pointer __fe = *__f.__m_iter_ + __block_size; difference_type __bs = __fe - __fb; if (__bs > __n) { @@ -909,7 +934,7 @@ protected: typedef typename __alloc_traits::pointer pointer; typedef typename __alloc_traits::const_pointer const_pointer; - static const difference_type __block_size = sizeof(value_type) < 256 ? 4096 / sizeof(value_type) : 16; + static const difference_type __block_size; typedef typename __rebind_alloc_helper<__alloc_traits, pointer>::type __pointer_allocator; typedef allocator_traits<__pointer_allocator> __map_traits; @@ -919,9 +944,9 @@ protected: typedef __split_buffer<pointer, __pointer_allocator> __map; typedef __deque_iterator<value_type, pointer, reference, __map_pointer, - difference_type, __block_size> iterator; + difference_type> iterator; typedef __deque_iterator<value_type, const_pointer, const_reference, __map_const_pointer, - difference_type, __block_size> const_iterator; + difference_type> const_iterator; __map __map_; size_type __start_; @@ -939,8 +964,10 @@ protected: _LIBCPP_INLINE_VISIBILITY const allocator_type& __alloc() const _NOEXCEPT {return __size_.second();} + _LIBCPP_INLINE_VISIBILITY __deque_base() _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value); + _LIBCPP_INLINE_VISIBILITY explicit __deque_base(const allocator_type& __a); public: ~__deque_base(); @@ -997,6 +1024,11 @@ private: }; template <class _Tp, class _Allocator> +const typename __deque_base<_Tp, _Allocator>::difference_type + __deque_base<_Tp, _Allocator>::__block_size = + __deque_block_size<value_type, difference_type>::value; + +template <class _Tp, class _Allocator> bool __deque_base<_Tp, _Allocator>::__invariants() const { @@ -1060,13 +1092,13 @@ __deque_base<_Tp, _Allocator>::end() const _NOEXCEPT } template <class _Tp, class _Allocator> -inline _LIBCPP_INLINE_VISIBILITY +inline __deque_base<_Tp, _Allocator>::__deque_base() _NOEXCEPT_(is_nothrow_default_constructible<allocator_type>::value) : __start_(0), __size_(0) {} template <class _Tp, class _Allocator> -inline _LIBCPP_INLINE_VISIBILITY +inline __deque_base<_Tp, _Allocator>::__deque_base(const allocator_type& __a) : __map_(__pointer_allocator(__a)), __start_(0), __size_(0, __a) {} @@ -1164,6 +1196,9 @@ public: typedef _Tp value_type; typedef _Allocator allocator_type; + static_assert((is_same<typename allocator_type::value_type, value_type>::value), + "Allocator::value_type must be same type as value_type"); + typedef __deque_base<value_type, allocator_type> __base; typedef typename __base::__alloc_traits __alloc_traits; @@ -1211,8 +1246,11 @@ public: #endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + _LIBCPP_INLINE_VISIBILITY deque(deque&& __c) _NOEXCEPT_(is_nothrow_move_constructible<__base>::value); + _LIBCPP_INLINE_VISIBILITY deque(deque&& __c, const allocator_type& __a); + _LIBCPP_INLINE_VISIBILITY deque& operator=(deque&& __c) _NOEXCEPT_(__alloc_traits::propagate_on_container_move_assignment::value && is_nothrow_move_assignable<allocator_type>::value); @@ -1231,6 +1269,7 @@ public: void assign(initializer_list<value_type> __il) {assign(__il.begin(), __il.end());} #endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS + _LIBCPP_INLINE_VISIBILITY allocator_type get_allocator() const _NOEXCEPT; // iterators: @@ -1283,13 +1322,21 @@ public: bool empty() const _NOEXCEPT {return __base::size() == 0;} // element access: + _LIBCPP_INLINE_VISIBILITY reference operator[](size_type __i); + _LIBCPP_INLINE_VISIBILITY const_reference operator[](size_type __i) const; + _LIBCPP_INLINE_VISIBILITY reference at(size_type __i); + _LIBCPP_INLINE_VISIBILITY const_reference at(size_type __i) const; + _LIBCPP_INLINE_VISIBILITY reference front(); + _LIBCPP_INLINE_VISIBILITY const_reference front() const; + _LIBCPP_INLINE_VISIBILITY reference back(); + _LIBCPP_INLINE_VISIBILITY const_reference back() const; // 23.2.2.3 modifiers: @@ -1328,6 +1375,7 @@ public: iterator erase(const_iterator __p); iterator erase(const_iterator __f, const_iterator __l); + _LIBCPP_INLINE_VISIBILITY void swap(deque& __c) #if _LIBCPP_STD_VER >= 14 _NOEXCEPT; @@ -1335,6 +1383,7 @@ public: _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value || __is_nothrow_swappable<allocator_type>::value); #endif + _LIBCPP_INLINE_VISIBILITY void clear() _NOEXCEPT; _LIBCPP_INLINE_VISIBILITY @@ -1507,7 +1556,7 @@ deque<_Tp, _Allocator>::operator=(const deque& __c) #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES template <class _Tp, class _Allocator> -inline _LIBCPP_INLINE_VISIBILITY +inline deque<_Tp, _Allocator>::deque(deque&& __c) _NOEXCEPT_(is_nothrow_move_constructible<__base>::value) : __base(_VSTD::move(__c)) @@ -1515,7 +1564,7 @@ deque<_Tp, _Allocator>::deque(deque&& __c) } template <class _Tp, class _Allocator> -inline _LIBCPP_INLINE_VISIBILITY +inline deque<_Tp, _Allocator>::deque(deque&& __c, const allocator_type& __a) : __base(_VSTD::move(__c), __a) { @@ -1527,7 +1576,7 @@ deque<_Tp, _Allocator>::deque(deque&& __c, const allocator_type& __a) } template <class _Tp, class _Allocator> -inline _LIBCPP_INLINE_VISIBILITY +inline deque<_Tp, _Allocator>& deque<_Tp, _Allocator>::operator=(deque&& __c) _NOEXCEPT_(__alloc_traits::propagate_on_container_move_assignment::value && @@ -1611,7 +1660,7 @@ deque<_Tp, _Allocator>::assign(size_type __n, const value_type& __v) } template <class _Tp, class _Allocator> -inline _LIBCPP_INLINE_VISIBILITY +inline _Allocator deque<_Tp, _Allocator>::get_allocator() const _NOEXCEPT { @@ -1670,7 +1719,7 @@ deque<_Tp, _Allocator>::shrink_to_fit() _NOEXCEPT } template <class _Tp, class _Allocator> -inline _LIBCPP_INLINE_VISIBILITY +inline typename deque<_Tp, _Allocator>::reference deque<_Tp, _Allocator>::operator[](size_type __i) { @@ -1679,7 +1728,7 @@ deque<_Tp, _Allocator>::operator[](size_type __i) } template <class _Tp, class _Allocator> -inline _LIBCPP_INLINE_VISIBILITY +inline typename deque<_Tp, _Allocator>::const_reference deque<_Tp, _Allocator>::operator[](size_type __i) const { @@ -1688,7 +1737,7 @@ deque<_Tp, _Allocator>::operator[](size_type __i) const } template <class _Tp, class _Allocator> -inline _LIBCPP_INLINE_VISIBILITY +inline typename deque<_Tp, _Allocator>::reference deque<_Tp, _Allocator>::at(size_type __i) { @@ -1699,7 +1748,7 @@ deque<_Tp, _Allocator>::at(size_type __i) } template <class _Tp, class _Allocator> -inline _LIBCPP_INLINE_VISIBILITY +inline typename deque<_Tp, _Allocator>::const_reference deque<_Tp, _Allocator>::at(size_type __i) const { @@ -1710,7 +1759,7 @@ deque<_Tp, _Allocator>::at(size_type __i) const } template <class _Tp, class _Allocator> -inline _LIBCPP_INLINE_VISIBILITY +inline typename deque<_Tp, _Allocator>::reference deque<_Tp, _Allocator>::front() { @@ -1719,7 +1768,7 @@ deque<_Tp, _Allocator>::front() } template <class _Tp, class _Allocator> -inline _LIBCPP_INLINE_VISIBILITY +inline typename deque<_Tp, _Allocator>::const_reference deque<_Tp, _Allocator>::front() const { @@ -1728,7 +1777,7 @@ deque<_Tp, _Allocator>::front() const } template <class _Tp, class _Allocator> -inline _LIBCPP_INLINE_VISIBILITY +inline typename deque<_Tp, _Allocator>::reference deque<_Tp, _Allocator>::back() { @@ -1737,7 +1786,7 @@ deque<_Tp, _Allocator>::back() } template <class _Tp, class _Allocator> -inline _LIBCPP_INLINE_VISIBILITY +inline typename deque<_Tp, _Allocator>::const_reference deque<_Tp, _Allocator>::back() const { @@ -2029,7 +2078,6 @@ deque<_Tp, _Allocator>::insert(const_iterator __p, size_type __n, const value_ty if (__n > __front_spare()) __add_front_capacity(__n - __front_spare()); // __n <= __front_spare() - size_type __old_n = __n; iterator __old_begin = __base::begin(); iterator __i = __old_begin; if (__n > __pos) @@ -2054,7 +2102,6 @@ deque<_Tp, _Allocator>::insert(const_iterator __p, size_type __n, const value_ty if (__n > __back_capacity) __add_back_capacity(__n - __back_capacity); // __n <= __back_capacity - size_type __old_n = __n; iterator __old_end = __base::end(); iterator __i = __old_end; size_type __de = __base::size() - __pos; @@ -2119,7 +2166,6 @@ deque<_Tp, _Allocator>::insert(const_iterator __p, _BiIter __f, _BiIter __l, if (__n > __front_spare()) __add_front_capacity(__n - __front_spare()); // __n <= __front_spare() - size_type __old_n = __n; iterator __old_begin = __base::begin(); iterator __i = __old_begin; _BiIter __m = __f; @@ -2150,7 +2196,6 @@ deque<_Tp, _Allocator>::insert(const_iterator __p, _BiIter __f, _BiIter __l, if (__n > __back_capacity) __add_back_capacity(__n - __back_capacity); // __n <= __back_capacity - size_type __old_n = __n; iterator __old_end = __base::end(); iterator __i = __old_end; _BiIter __m = __l; @@ -2685,7 +2730,6 @@ template <class _Tp, class _Allocator> typename deque<_Tp, _Allocator>::iterator deque<_Tp, _Allocator>::erase(const_iterator __f) { - difference_type __n = 1; iterator __b = __base::begin(); difference_type __pos = __f - __b; iterator __p = __b + __pos; @@ -2781,7 +2825,7 @@ deque<_Tp, _Allocator>::__erase_to_end(const_iterator __f) } template <class _Tp, class _Allocator> -inline _LIBCPP_INLINE_VISIBILITY +inline void deque<_Tp, _Allocator>::swap(deque& __c) #if _LIBCPP_STD_VER >= 14 @@ -2795,7 +2839,7 @@ deque<_Tp, _Allocator>::swap(deque& __c) } template <class _Tp, class _Allocator> -inline _LIBCPP_INLINE_VISIBILITY +inline void deque<_Tp, _Allocator>::clear() _NOEXCEPT { diff --git a/include/errno.h b/include/errno.h new file mode 100644 index 000000000000..ee6429110cc1 --- /dev/null +++ b/include/errno.h @@ -0,0 +1,398 @@ +// -*- C++ -*- +//===-------------------------- errno.h -----------------------------------===// +// +// 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_ERRNO_H +#define _LIBCPP_ERRNO_H + +/* + errno.h synopsis + +Macros: + + EDOM + EILSEQ // C99 + ERANGE + errno + +*/ + +#include <__config> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +#include_next <errno.h> + +#ifdef __cplusplus + +#if !defined(EOWNERDEAD) || !defined(ENOTRECOVERABLE) + +#ifdef ELAST + +static const int __elast1 = ELAST+1; +static const int __elast2 = ELAST+2; + +#else + +static const int __elast1 = 104; +static const int __elast2 = 105; + +#endif + +#ifdef ENOTRECOVERABLE + +#define EOWNERDEAD __elast1 + +#ifdef ELAST +#undef ELAST +#define ELAST EOWNERDEAD +#endif + +#elif defined(EOWNERDEAD) + +#define ENOTRECOVERABLE __elast1 +#ifdef ELAST +#undef ELAST +#define ELAST ENOTRECOVERABLE +#endif + +#else // defined(EOWNERDEAD) + +#define EOWNERDEAD __elast1 +#define ENOTRECOVERABLE __elast2 +#ifdef ELAST +#undef ELAST +#define ELAST ENOTRECOVERABLE +#endif + +#endif // defined(EOWNERDEAD) + +#endif // !defined(EOWNERDEAD) || !defined(ENOTRECOVERABLE) + +// supply errno values likely to be missing, particularly on Windows + +#ifndef EAFNOSUPPORT +#define EAFNOSUPPORT 9901 +#endif + +#ifndef EADDRINUSE +#define EADDRINUSE 9902 +#endif + +#ifndef EADDRNOTAVAIL +#define EADDRNOTAVAIL 9903 +#endif + +#ifndef EISCONN +#define EISCONN 9904 +#endif + +#ifndef EBADMSG +#define EBADMSG 9905 +#endif + +#ifndef ECONNABORTED +#define ECONNABORTED 9906 +#endif + +#ifndef EALREADY +#define EALREADY 9907 +#endif + +#ifndef ECONNREFUSED +#define ECONNREFUSED 9908 +#endif + +#ifndef ECONNRESET +#define ECONNRESET 9909 +#endif + +#ifndef EDESTADDRREQ +#define EDESTADDRREQ 9910 +#endif + +#ifndef EHOSTUNREACH +#define EHOSTUNREACH 9911 +#endif + +#ifndef EIDRM +#define EIDRM 9912 +#endif + +#ifndef EMSGSIZE +#define EMSGSIZE 9913 +#endif + +#ifndef ENETDOWN +#define ENETDOWN 9914 +#endif + +#ifndef ENETRESET +#define ENETRESET 9915 +#endif + +#ifndef ENETUNREACH +#define ENETUNREACH 9916 +#endif + +#ifndef ENOBUFS +#define ENOBUFS 9917 +#endif + +#ifndef ENOLINK +#define ENOLINK 9918 +#endif + +#ifndef ENODATA +#define ENODATA 9919 +#endif + +#ifndef ENOMSG +#define ENOMSG 9920 +#endif + +#ifndef ENOPROTOOPT +#define ENOPROTOOPT 9921 +#endif + +#ifndef ENOSR +#define ENOSR 9922 +#endif + +#ifndef ENOTSOCK +#define ENOTSOCK 9923 +#endif + +#ifndef ENOSTR +#define ENOSTR 9924 +#endif + +#ifndef ENOTCONN +#define ENOTCONN 9925 +#endif + +#ifndef ENOTSUP +#define ENOTSUP 9926 +#endif + +#ifndef ECANCELED +#define ECANCELED 9927 +#endif + +#ifndef EINPROGRESS +#define EINPROGRESS 9928 +#endif + +#ifndef EOPNOTSUPP +#define EOPNOTSUPP 9929 +#endif + +#ifndef EWOULDBLOCK +#define EWOULDBLOCK 9930 +#endif + +#ifndef EOWNERDEAD +#define EOWNERDEAD 9931 +#endif + +#ifndef EPROTO +#define EPROTO 9932 +#endif + +#ifndef EPROTONOSUPPORT +#define EPROTONOSUPPORT 9933 +#endif + +#ifndef ENOTRECOVERABLE +#define ENOTRECOVERABLE 9934 +#endif + +#ifndef ETIME +#define ETIME 9935 +#endif + +#ifndef ETXTBSY +#define ETXTBSY 9936 +#endif + +#ifndef ETIMEDOUT +#define ETIMEDOUT 9938 +#endif + +#ifndef ELOOP +#define ELOOP 9939 +#endif + +#ifndef EOVERFLOW +#define EOVERFLOW 9940 +#endif + +#ifndef EPROTOTYPE +#define EPROTOTYPE 9941 +#endif + +#ifndef ENOSYS +#define ENOSYS 9942 +#endif + +#ifndef EINVAL +#define EINVAL 9943 +#endif + +#ifndef ERANGE +#define ERANGE 9944 +#endif + +#ifndef EILSEQ +#define EILSEQ 9945 +#endif + +// Windows Mobile doesn't appear to define these: + +#ifndef E2BIG +#define E2BIG 9946 +#endif + +#ifndef EDOM +#define EDOM 9947 +#endif + +#ifndef EFAULT +#define EFAULT 9948 +#endif + +#ifndef EBADF +#define EBADF 9949 +#endif + +#ifndef EPIPE +#define EPIPE 9950 +#endif + +#ifndef EXDEV +#define EXDEV 9951 +#endif + +#ifndef EBUSY +#define EBUSY 9952 +#endif + +#ifndef ENOTEMPTY +#define ENOTEMPTY 9953 +#endif + +#ifndef ENOEXEC +#define ENOEXEC 9954 +#endif + +#ifndef EEXIST +#define EEXIST 9955 +#endif + +#ifndef EFBIG +#define EFBIG 9956 +#endif + +#ifndef ENAMETOOLONG +#define ENAMETOOLONG 9957 +#endif + +#ifndef ENOTTY +#define ENOTTY 9958 +#endif + +#ifndef EINTR +#define EINTR 9959 +#endif + +#ifndef ESPIPE +#define ESPIPE 9960 +#endif + +#ifndef EIO +#define EIO 9961 +#endif + +#ifndef EISDIR +#define EISDIR 9962 +#endif + +#ifndef ECHILD +#define ECHILD 9963 +#endif + +#ifndef ENOLCK +#define ENOLCK 9964 +#endif + +#ifndef ENOSPC +#define ENOSPC 9965 +#endif + +#ifndef ENXIO +#define ENXIO 9966 +#endif + +#ifndef ENODEV +#define ENODEV 9967 +#endif + +#ifndef ENOENT +#define ENOENT 9968 +#endif + +#ifndef ESRCH +#define ESRCH 9969 +#endif + +#ifndef ENOTDIR +#define ENOTDIR 9970 +#endif + +#ifndef ENOMEM +#define ENOMEM 9971 +#endif + +#ifndef EPERM +#define EPERM 9972 +#endif + +#ifndef EACCES +#define EACCES 9973 +#endif + +#ifndef EROFS +#define EROFS 9974 +#endif + +#ifndef EDEADLK +#define EDEADLK 9975 +#endif + +#ifndef EAGAIN +#define EAGAIN 9976 +#endif + +#ifndef ENFILE +#define ENFILE 9977 +#endif + +#ifndef EMFILE +#define EMFILE 9978 +#endif + +#ifndef EMLINK +#define EMLINK 9979 +#endif + +#endif // __cplusplus + +#endif // _LIBCPP_ERRNO_H diff --git a/include/exception b/include/exception index 5a905e7e58d8..686e4ecd0578 100644 --- a/include/exception +++ b/include/exception @@ -235,7 +235,7 @@ rethrow_if_nested(const _Ep& __e, typename enable_if< is_polymorphic<_Ep>::value >::type* = 0) { - const nested_exception* __nep = dynamic_cast<const nested_exception*>(&__e); + const nested_exception* __nep = dynamic_cast<const nested_exception*>(_VSTD::addressof(__e)); if (__nep) __nep->rethrow_nested(); } diff --git a/include/experimental/algorithm b/include/experimental/algorithm index a2e956f281a0..ffaa793b6d4e 100644 --- a/include/experimental/algorithm +++ b/include/experimental/algorithm @@ -50,6 +50,12 @@ SampleIterator sample(PopulationIterator first, PopulationIterator last, _LIBCPP_BEGIN_NAMESPACE_LFTS +template <class _ForwardIterator, class _Searcher> +_LIBCPP_INLINE_VISIBILITY +_ForwardIterator search(_ForwardIterator __f, _ForwardIterator __l, const _Searcher &__s) +{ return __s(__f, __l); } + + template <class _PopulationIterator, class _SampleIterator, class _Distance, class _UniformRandomNumberGenerator> _LIBCPP_INLINE_VISIBILITY diff --git a/include/experimental/any b/include/experimental/any new file mode 100644 index 000000000000..603788484dd5 --- /dev/null +++ b/include/experimental/any @@ -0,0 +1,590 @@ +// -*- C++ -*- +//===------------------------------ any -----------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP_EXPERIMENTAL_ANY +#define _LIBCPP_EXPERIMENTAL_ANY + +/* + experimental/any synopsis + +namespace std { +namespace experimental { +inline namespace fundamentals_v1 { + + class bad_any_cast : public bad_cast + { + public: + virtual const char* what() const noexcept; + }; + + class any + { + public: + + // 6.3.1 any construct/destruct + any() noexcept; + + any(const any& other); + any(any&& other) noexcept; + + template <class ValueType> + any(ValueType&& value); + + ~any(); + + // 6.3.2 any assignments + any& operator=(const any& rhs); + any& operator=(any&& rhs) noexcept; + + template <class ValueType> + any& operator=(ValueType&& rhs); + + // 6.3.3 any modifiers + void clear() noexcept; + void swap(any& rhs) noexcept; + + // 6.3.4 any observers + bool empty() const noexcept; + const type_info& type() const noexcept; + }; + + // 6.4 Non-member functions + void swap(any& x, any& y) noexcept; + + template<class ValueType> + ValueType any_cast(const any& operand); + template<class ValueType> + ValueType any_cast(any& operand); + template<class ValueType> + ValueType any_cast(any&& operand); + + template<class ValueType> + const ValueType* any_cast(const any* operand) noexcept; + template<class ValueType> + ValueType* any_cast(any* operand) noexcept; + +} // namespace fundamentals_v1 +} // namespace experimental +} // namespace std + +*/ + +#include <experimental/__config> +#include <memory> +#include <new> +#include <typeinfo> +#include <type_traits> +#include <cstdlib> +#include <cassert> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCPP_BEGIN_NAMESPACE_LFTS + +class _LIBCPP_EXCEPTION_ABI bad_any_cast : public bad_cast +{ +public: + virtual const char* what() const _NOEXCEPT; +}; + +#if _LIBCPP_STD_VER > 11 // C++ > 11 + +_LIBCPP_NORETURN _LIBCPP_INLINE_VISIBILITY +inline void __throw_bad_any_cast() +{ +#ifndef _LIBCPP_NO_EXCEPTIONS + throw bad_any_cast(); +#else + assert(!"bad_any_cast"); +#endif +} + +// Forward declarations +class any; + +template <class _ValueType> +typename add_pointer<typename add_const<_ValueType>::type>::type +any_cast(any const *) _NOEXCEPT; + +template <class _ValueType> +typename add_pointer<_ValueType>::type +any_cast(any *) _NOEXCEPT; + +namespace __any_imp +{ + typedef typename aligned_storage<3*sizeof(void*), alignment_of<void*>::value>::type + _Buffer; + + template <class _Tp> + struct _IsSmallObject + : public integral_constant<bool + , sizeof(_Tp) <= sizeof(_Buffer) + && alignment_of<_Buffer>::value + % alignment_of<_Tp>::value == 0 + && is_nothrow_move_constructible<_Tp>::value + > + {}; + + enum class _Action + { + _Destroy, + _Copy, + _Move, + _Get, + _TypeInfo + }; + + template <class _Tp> + struct _SmallHandler; + + template <class _Tp> + struct _LargeHandler; + + template <class _Tp> + using _Handler = typename conditional<_IsSmallObject<_Tp>::value + , _SmallHandler<_Tp> + , _LargeHandler<_Tp> + >::type; + template <class _ValueType> + using _EnableIfNotAny = typename + enable_if< + !is_same<typename decay<_ValueType>::type, any>::value + >::type; + +} // namespace __any_imp + +class any +{ +public: + // 6.3.1 any construct/destruct + _LIBCPP_INLINE_VISIBILITY + any() _NOEXCEPT : __h(nullptr) {} + + _LIBCPP_INLINE_VISIBILITY + any(any const & __other) : __h(nullptr) + { + if (__other.__h) __other.__call(_Action::_Copy, this); + } + + _LIBCPP_INLINE_VISIBILITY + any(any && __other) _NOEXCEPT : __h(nullptr) + { + if (__other.__h) __other.__call(_Action::_Move, this); + } + + template < + class _ValueType + , class = __any_imp::_EnableIfNotAny<_ValueType> + > + any(_ValueType && __value); + + _LIBCPP_INLINE_VISIBILITY + ~any() + { + this->clear(); + } + + // 6.3.2 any assignments + _LIBCPP_INLINE_VISIBILITY + any & operator=(any const & __rhs) + { + any(__rhs).swap(*this); + return *this; + } + + _LIBCPP_INLINE_VISIBILITY + any & operator=(any && __rhs) _NOEXCEPT + { + any(_VSTD::move(__rhs)).swap(*this); + return *this; + } + + template < + class _ValueType + , class = __any_imp::_EnableIfNotAny<_ValueType> + > + any & operator=(_ValueType && __rhs); + + // 6.3.3 any modifiers + _LIBCPP_INLINE_VISIBILITY + void clear() _NOEXCEPT + { + if (__h) this->__call(_Action::_Destroy); + } + + void swap(any & __rhs) _NOEXCEPT; + + // 6.3.4 any observers + _LIBCPP_INLINE_VISIBILITY + bool empty() const _NOEXCEPT + { + return __h == nullptr; + } + +#if !defined(_LIBCPP_NO_RTTI) + _LIBCPP_INLINE_VISIBILITY + const type_info & type() const _NOEXCEPT + { + if (__h) { + return *static_cast<type_info const *>(this->__call(_Action::_TypeInfo)); + } else { + return typeid(void); + } + } +#endif + +private: + typedef __any_imp::_Action _Action; + + typedef void* (*_HandleFuncPtr)(_Action, any const *, any *, const type_info *); + + union _Storage + { + void * __ptr; + __any_imp::_Buffer __buf; + }; + + _LIBCPP_ALWAYS_INLINE + void * __call(_Action __a, any * __other = nullptr, + type_info const * __info = nullptr) const + { + return __h(__a, this, __other, __info); + } + + _LIBCPP_ALWAYS_INLINE + void * __call(_Action __a, any * __other = nullptr, + type_info const * __info = nullptr) + { + return __h(__a, this, __other, __info); + } + + template <class> + friend struct __any_imp::_SmallHandler; + template <class> + friend struct __any_imp::_LargeHandler; + + template <class _ValueType> + friend typename add_pointer<typename add_const<_ValueType>::type>::type + any_cast(any const *) _NOEXCEPT; + + template <class _ValueType> + friend typename add_pointer<_ValueType>::type + any_cast(any *) _NOEXCEPT; + + _HandleFuncPtr __h; + _Storage __s; +}; + +namespace __any_imp +{ + + template <class _Tp> + struct _LIBCPP_TYPE_VIS_ONLY _SmallHandler + { + _LIBCPP_INLINE_VISIBILITY + static void* __handle(_Action __act, any const * __this, any * __other, + type_info const * __info) + { + switch (__act) + { + case _Action::_Destroy: + __destroy(const_cast<any &>(*__this)); + return nullptr; + case _Action::_Copy: + __copy(*__this, *__other); + return nullptr; + case _Action::_Move: + __move(const_cast<any &>(*__this), *__other); + return nullptr; + case _Action::_Get: + return __get(const_cast<any &>(*__this), __info); + case _Action::_TypeInfo: + return __type_info(); + } + } + + template <class _Up> + _LIBCPP_INLINE_VISIBILITY + static void __create(any & __dest, _Up && __v) + { + ::new (static_cast<void*>(&__dest.__s.__buf)) _Tp(_VSTD::forward<_Up>(__v)); + __dest.__h = &_SmallHandler::__handle; + } + + private: + _LIBCPP_ALWAYS_INLINE _LIBCPP_INLINE_VISIBILITY + static void __destroy(any & __this) + { + _Tp & __value = *static_cast<_Tp *>(static_cast<void*>(&__this.__s.__buf)); + __value.~_Tp(); + __this.__h = nullptr; + } + + _LIBCPP_ALWAYS_INLINE _LIBCPP_INLINE_VISIBILITY + static void __copy(any const & __this, any & __dest) + { + _SmallHandler::__create(__dest, *static_cast<_Tp const *>( + static_cast<void const *>(&__this.__s.__buf))); + } + + _LIBCPP_ALWAYS_INLINE _LIBCPP_INLINE_VISIBILITY + static void __move(any & __this, any & __dest) + { + _SmallHandler::__create(__dest, _VSTD::move( + *static_cast<_Tp*>(static_cast<void*>(&__this.__s.__buf)))); + __destroy(__this); + } + + _LIBCPP_ALWAYS_INLINE _LIBCPP_INLINE_VISIBILITY + static void* __get(any & __this, type_info const * __info) + { +#if !defined(_LIBCPP_NO_RTTI) + if (typeid(_Tp) == *__info) { + return static_cast<void*>(&__this.__s.__buf); + } + return nullptr; +#else + return static_cast<void*>(&__this.__s.__buf); +#endif + } + + _LIBCPP_ALWAYS_INLINE _LIBCPP_INLINE_VISIBILITY + static void* __type_info() + { +#if !defined(_LIBCPP_NO_RTTI) + return const_cast<void*>(static_cast<void const *>(&typeid(_Tp))); +#else + return nullptr; +#endif + } + }; + + template <class _Tp> + struct _LIBCPP_TYPE_VIS_ONLY _LargeHandler + { + _LIBCPP_INLINE_VISIBILITY + static void* __handle(_Action __act, any const * __this, any * __other, + type_info const * __info) + { + switch (__act) + { + case _Action::_Destroy: + __destroy(const_cast<any &>(*__this)); + return nullptr; + case _Action::_Copy: + __copy(*__this, *__other); + return nullptr; + case _Action::_Move: + __move(const_cast<any &>(*__this), *__other); + return nullptr; + case _Action::_Get: + return __get(const_cast<any &>(*__this), __info); + case _Action::_TypeInfo: + return __type_info(); + } + } + + template <class _Up> + _LIBCPP_INLINE_VISIBILITY + static void __create(any & __dest, _Up && __v) + { + typedef allocator<_Tp> _Alloc; + typedef __allocator_destructor<_Alloc> _Dp; + _Alloc __a; + unique_ptr<_Tp, _Dp> __hold(__a.allocate(1), _Dp(__a, 1)); + ::new ((void*)__hold.get()) _Tp(_VSTD::forward<_Up>(__v)); + __dest.__s.__ptr = __hold.release(); + __dest.__h = &_LargeHandler::__handle; + } + + private: + + _LIBCPP_ALWAYS_INLINE _LIBCPP_INLINE_VISIBILITY + static void __destroy(any & __this) + { + delete static_cast<_Tp*>(__this.__s.__ptr); + __this.__h = nullptr; + } + + _LIBCPP_ALWAYS_INLINE _LIBCPP_INLINE_VISIBILITY + static void __copy(any const & __this, any & __dest) + { + _LargeHandler::__create(__dest, *static_cast<_Tp const *>(__this.__s.__ptr)); + } + + _LIBCPP_ALWAYS_INLINE _LIBCPP_INLINE_VISIBILITY + static void __move(any & __this, any & __dest) + { + __dest.__s.__ptr = __this.__s.__ptr; + __dest.__h = &_LargeHandler::__handle; + __this.__h = nullptr; + } + + _LIBCPP_ALWAYS_INLINE _LIBCPP_INLINE_VISIBILITY + static void* __get(any & __this, type_info const * __info) + { +#if !defined(_LIBCPP_NO_RTTI) + if (typeid(_Tp) == *__info) { + return static_cast<void*>(__this.__s.__ptr); + } + return nullptr; +#else + return static_cast<void*>(__this.__s.__ptr); +#endif + } + + _LIBCPP_ALWAYS_INLINE _LIBCPP_INLINE_VISIBILITY + static void* __type_info() + { +#if !defined(_LIBCPP_NO_RTTI) + return const_cast<void*>(static_cast<void const *>(&typeid(_Tp))); +#else + return nullptr; +#endif + } + }; + +} // namespace __any_imp + + +template <class _ValueType, class> +_LIBCPP_INLINE_VISIBILITY +any::any(_ValueType && __v) : __h(nullptr) +{ + typedef typename decay<_ValueType>::type _Tp; + static_assert(is_copy_constructible<_Tp>::value, + "_ValueType must be CopyConstructible."); + typedef __any_imp::_Handler<_Tp> _HandlerType; + _HandlerType::__create(*this, _VSTD::forward<_ValueType>(__v)); +} + +template <class _ValueType, class> +_LIBCPP_INLINE_VISIBILITY +any & any::operator=(_ValueType && __v) +{ + typedef typename decay<_ValueType>::type _Tp; + static_assert(is_copy_constructible<_Tp>::value, + "_ValueType must be CopyConstructible."); + any(_VSTD::forward<_ValueType>(__v)).swap(*this); + return *this; +} + +inline _LIBCPP_INLINE_VISIBILITY +void any::swap(any & __rhs) _NOEXCEPT +{ + if (__h && __rhs.__h) { + any __tmp; + __rhs.__call(_Action::_Move, &__tmp); + this->__call(_Action::_Move, &__rhs); + __tmp.__call(_Action::_Move, this); + } + else if (__h) { + this->__call(_Action::_Move, &__rhs); + } + else if (__rhs.__h) { + __rhs.__call(_Action::_Move, this); + } +} + +// 6.4 Non-member functions + +inline _LIBCPP_INLINE_VISIBILITY +void swap(any & __lhs, any & __rhs) _NOEXCEPT +{ + __lhs.swap(__rhs); +} + +template <class _ValueType> +_LIBCPP_INLINE_VISIBILITY +_ValueType any_cast(any const & __v) +{ + static_assert( + is_reference<_ValueType>::value + || is_copy_constructible<_ValueType>::value, + "_ValueType is required to be a reference or a CopyConstructible type."); + typedef typename add_const<typename remove_reference<_ValueType>::type>::type + _Tp; + _Tp * __tmp = any_cast<_Tp>(&__v); + if (__tmp == nullptr) + __throw_bad_any_cast(); + return *__tmp; +} + +template <class _ValueType> +_LIBCPP_INLINE_VISIBILITY +_ValueType any_cast(any & __v) +{ + static_assert( + is_reference<_ValueType>::value + || is_copy_constructible<_ValueType>::value, + "_ValueType is required to be a reference or a CopyConstructible type."); + typedef typename remove_reference<_ValueType>::type _Tp; + _Tp * __tmp = any_cast<_Tp>(&__v); + if (__tmp == nullptr) + __throw_bad_any_cast(); + return *__tmp; +} + +template <class _ValueType> +_LIBCPP_INLINE_VISIBILITY +_ValueType any_cast(any && __v) +{ + static_assert( + is_reference<_ValueType>::value + || is_copy_constructible<_ValueType>::value, + "_ValueType is required to be a reference or a CopyConstructible type."); + typedef typename remove_reference<_ValueType>::type _Tp; + _Tp * __tmp = any_cast<_Tp>(&__v); + if (__tmp == nullptr) + __throw_bad_any_cast(); + return *__tmp; +} + +template <class _ValueType> +inline _LIBCPP_INLINE_VISIBILITY +typename add_pointer<typename add_const<_ValueType>::type>::type +any_cast(any const * __any) _NOEXCEPT +{ + static_assert(!is_reference<_ValueType>::value, + "_ValueType may not be a reference."); + return any_cast<_ValueType>(const_cast<any *>(__any)); +} + +template <class _ValueType> +_LIBCPP_INLINE_VISIBILITY +typename add_pointer<_ValueType>::type +any_cast(any * __any) _NOEXCEPT +{ + using __any_imp::_Action; + static_assert(!is_reference<_ValueType>::value, + "_ValueType may not be a reference."); + typedef typename add_pointer<_ValueType>::type _ReturnType; + if (__any && __any->__h) { + + return static_cast<_ReturnType>( + __any->__call(_Action::_Get, nullptr, +#if !defined(_LIBCPP_NO_RTTI) + &typeid(_ValueType) +#else + nullptr +#endif + )); + + } + return nullptr; +} + +#endif // _LIBCPP_STD_VER > 11 + +_LIBCPP_END_NAMESPACE_LFTS + +#endif // _LIBCPP_EXPERIMENTAL_ANY diff --git a/include/experimental/dynarray b/include/experimental/dynarray index a0258628dfa6..f40a6ca188b8 100644 --- a/include/experimental/dynarray +++ b/include/experimental/dynarray @@ -137,7 +137,7 @@ public: private: size_t __size_; value_type * __base_; - _LIBCPP_ALWAYS_INLINE dynarray () noexcept : __base_(nullptr), __size_(0) {} + _LIBCPP_ALWAYS_INLINE dynarray () noexcept : __size_(0), __base_(nullptr) {} static inline _LIBCPP_INLINE_VISIBILITY value_type* __allocate ( size_t count ) { diff --git a/include/experimental/functional b/include/experimental/functional new file mode 100644 index 000000000000..c7a78695b809 --- /dev/null +++ b/include/experimental/functional @@ -0,0 +1,454 @@ +// -*- C++ -*- +//===-------------------------- functional --------------------------------===// +// +// 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_EXPERIMENTAL_FUNCTIONAL +#define _LIBCPP_EXPERIMENTAL_FUNCTIONAL + +/* + experimental/functional synopsis + +#include <algorithm> + +namespace std { +namespace experimental { +inline namespace fundamentals_v1 { + + // See C++14 20.9.9, Function object binders + template <class T> constexpr bool is_bind_expression_v + = is_bind_expression<T>::value; + template <class T> constexpr int is_placeholder_v + = is_placeholder<T>::value; + + // 4.2, Class template function + template<class> class function; // undefined + template<class R, class... ArgTypes> class function<R(ArgTypes...)>; + + template<class R, class... ArgTypes> + void swap(function<R(ArgTypes...)>&, function<R(ArgTypes...)>&); + + template<class R, class... ArgTypes> + bool operator==(const function<R(ArgTypes...)>&, nullptr_t) noexcept; + template<class R, class... ArgTypes> + bool operator==(nullptr_t, const function<R(ArgTypes...)>&) noexcept; + template<class R, class... ArgTypes> + bool operator!=(const function<R(ArgTypes...)>&, nullptr_t) noexcept; + template<class R, class... ArgTypes> + bool operator!=(nullptr_t, const function<R(ArgTypes...)>&) noexcept; + + // 4.3, Searchers + template<class ForwardIterator, class BinaryPredicate = equal_to<>> + class default_searcher; + + template<class RandomAccessIterator, + class Hash = hash<typename iterator_traits<RandomAccessIterator>::value_type>, + class BinaryPredicate = equal_to<>> + class boyer_moore_searcher; + + template<class RandomAccessIterator, + class Hash = hash<typename iterator_traits<RandomAccessIterator>::value_type>, + class BinaryPredicate = equal_to<>> + class boyer_moore_horspool_searcher; + + template<class ForwardIterator, class BinaryPredicate = equal_to<>> + default_searcher<ForwardIterator, BinaryPredicate> + make_default_searcher(ForwardIterator pat_first, ForwardIterator pat_last, + BinaryPredicate pred = BinaryPredicate()); + + template<class RandomAccessIterator, + class Hash = hash<typename iterator_traits<RandomAccessIterator>::value_type>, + class BinaryPredicate = equal_to<>> + boyer_moore_searcher<RandomAccessIterator, Hash, BinaryPredicate> + make_boyer_moore_searcher( + RandomAccessIterator pat_first, RandomAccessIterator pat_last, + Hash hf = Hash(), BinaryPredicate pred = BinaryPredicate()); + + template<class RandomAccessIterator, + class Hash = hash<typename iterator_traits<RandomAccessIterator>::value_type>, + class BinaryPredicate = equal_to<>> + boyer_moore_horspool_searcher<RandomAccessIterator, Hash, BinaryPredicate> + make_boyer_moore_horspool_searcher( + RandomAccessIterator pat_first, RandomAccessIterator pat_last, + Hash hf = Hash(), BinaryPredicate pred = BinaryPredicate()); + + } // namespace fundamentals_v1 + } // namespace experimental + + template<class R, class... ArgTypes, class Alloc> + struct uses_allocator<experimental::function<R(ArgTypes...)>, Alloc>; + +} // namespace std + +*/ + +#include <experimental/__config> +#include <functional> + +#include <algorithm> +#include <type_traits> +#include <vector> +#include <array> +#include <unordered_map> + +#include <__undef_min_max> + +#include <__debug> + +#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) +#pragma GCC system_header +#endif + +_LIBCPP_BEGIN_NAMESPACE_LFTS + +#if _LIBCPP_STD_VER > 11 +// default searcher +template<class _ForwardIterator, class _BinaryPredicate = equal_to<>> +_LIBCPP_TYPE_VIS +class default_searcher { +public: + _LIBCPP_INLINE_VISIBILITY + default_searcher(_ForwardIterator __f, _ForwardIterator __l, + _BinaryPredicate __p = _BinaryPredicate()) + : __first_(__f), __last_(__l), __pred_(__p) {} + + template <typename _ForwardIterator2> + _LIBCPP_INLINE_VISIBILITY + _ForwardIterator2 operator () (_ForwardIterator2 __f, _ForwardIterator2 __l) const + { + return _VSTD::search(__f, __l, __first_, __last_, __pred_); + } + +private: + _ForwardIterator __first_; + _ForwardIterator __last_; + _BinaryPredicate __pred_; + }; + +template<class _ForwardIterator, class _BinaryPredicate = equal_to<>> +_LIBCPP_INLINE_VISIBILITY +default_searcher<_ForwardIterator, _BinaryPredicate> +make_default_searcher( _ForwardIterator __f, _ForwardIterator __l, _BinaryPredicate __p = _BinaryPredicate ()) +{ + return default_searcher<_ForwardIterator, _BinaryPredicate>(__f, __l, __p); +} + +template<class _Key, class _Value, class _Hash, class _BinaryPredicate, bool /*useArray*/> class _BMSkipTable; + +// General case for BM data searching; use a map +template<class _Key, typename _Value, class _Hash, class _BinaryPredicate> +class _BMSkipTable<_Key, _Value, _Hash, _BinaryPredicate, false> { +public: // TODO private: + typedef _Value value_type; + typedef _Key key_type; + + const _Value __default_value_; + std::unordered_map<_Key, _Value, _Hash, _BinaryPredicate> __table; + +public: + _LIBCPP_INLINE_VISIBILITY + _BMSkipTable(std::size_t __sz, _Value __default, _Hash __hf, _BinaryPredicate __pred) + : __default_value_(__default), __table(__sz, __hf, __pred) {} + + _LIBCPP_INLINE_VISIBILITY + void insert(const key_type &__key, value_type __val) + { + __table [__key] = __val; // Would skip_.insert (val) be better here? + } + + _LIBCPP_INLINE_VISIBILITY + value_type operator [](const key_type & __key) const + { + auto __it = __table.find (__key); + return __it == __table.end() ? __default_value_ : __it->second; + } +}; + + +// Special case small numeric values; use an array +template<class _Key, typename _Value, class _Hash, class _BinaryPredicate> +class _BMSkipTable<_Key, _Value, _Hash, _BinaryPredicate, true> { +private: + typedef _Value value_type; + typedef _Key key_type; + + typedef typename std::make_unsigned<key_type>::type unsigned_key_type; + typedef std::array<value_type, _VSTD::numeric_limits<unsigned_key_type>::max()> skip_map; + skip_map __table; + +public: + _LIBCPP_INLINE_VISIBILITY + _BMSkipTable(std::size_t /*__sz*/, _Value __default, _Hash /*__hf*/, _BinaryPredicate /*__pred*/) + { + std::fill_n(__table.begin(), __table.size(), __default); + } + + _LIBCPP_INLINE_VISIBILITY + void insert(key_type __key, value_type __val) + { + __table[static_cast<unsigned_key_type>(__key)] = __val; + } + + _LIBCPP_INLINE_VISIBILITY + value_type operator [](key_type __key) const + { + return __table[static_cast<unsigned_key_ |