Unnamed: 0
int64
0
0
repo_id
stringlengths
5
186
file_path
stringlengths
15
223
content
stringlengths
1
32.8M
0
repos/zimalloc
repos/zimalloc/test/multi-threaded-loop.zig
var zigpa = ZiAllocator(.{}){}; pub fn main() !void { defer zigpa.deinit(); const max_spawn_count = 128 * 5; var threads: [max_spawn_count]std.Thread = undefined; const concurrency_limit = try std.Thread.getCpuCount(); const spawn_count = 5 * concurrency_limit; var semaphore = std.Thread.Semaphore{}; var wg = std.Thread.WaitGroup{}; var init_count = std.atomic.Value(usize).init(spawn_count); for (threads[0..spawn_count], 0..) |*thread, i| { thread.* = try std.Thread.spawn(.{}, run, .{ i, &wg, &semaphore, &init_count }); } while (init_count.load(.acquire) != 0) { std.atomic.spinLoopHint(); } std.log.debug("starting loops", .{}); { semaphore.mutex.lock(); defer semaphore.mutex.unlock(); semaphore.permits = concurrency_limit; semaphore.cond.broadcast(); } wg.wait(); std.log.debug("joining threads", .{}); for (threads[0..spawn_count]) |thread| { thread.join(); } } threadlocal var thread_index: ?usize = null; fn run(index: usize, wg: *std.Thread.WaitGroup, semaphore: *std.Thread.Semaphore, init: *std.atomic.Value(usize)) !void { wg.start(); defer wg.finish(); defer zigpa.deinitCurrentThreadHeap(); thread_index = index; std.log.debug("starting thread", .{}); const allocator = zigpa.allocator(); _ = init.fetchSub(1, .release); for (1..5) |i| { semaphore.wait(); defer semaphore.post(); std.log.debug("running iteration {d}", .{i}); var buf: [50000]*[256]u8 = undefined; // pointers to 12 MiB of data for (&buf) |*ptr| { const b = try allocator.create([256]u8); b.* = [1]u8{1} ** 256; ptr.* = b; } for (buf) |ptr| { allocator.destroy(ptr); } std.log.debug("finished iteration {d}", .{i}); } } pub const std_options: std.Options = .{ .logFn = logFn, }; fn logFn( comptime message_level: std.log.Level, comptime scope: @TypeOf(.enum_literal), comptime format: []const u8, args: anytype, ) void { if (comptime !std.log.logEnabled(message_level, scope)) return; const level_txt = comptime message_level.asText(); const prefix1 = "[Thread {?d}-{d}] "; const prefix2 = if (scope == .default) ": " else "(" ++ @tagName(scope) ++ "): "; const stderr = std.io.getStdErr().writer(); std.debug.lockStdErr(); defer std.debug.unlockStdErr(); nosuspend stderr.print( prefix1 ++ level_txt ++ prefix2 ++ format ++ "\n", .{ thread_index, std.Thread.getCurrentId() } ++ args, ) catch return; } const std = @import("std"); const build_options = @import("build_options"); const ZiAllocator = @import("zimalloc").Allocator;
0
repos
repos/range-v3/Version.cmake
# To update the range-v3 version, from a working directory that is clean except for an # updated doc/release_notes.md file, update the version numbers below. This makefile will # generate a new version.hpp, *AMEND THE MOST RECENT COMMIT*, and git-tag the commit. set(RANGE_V3_MAJOR 0) set(RANGE_V3_MINOR 12) set(RANGE_V3_PATCHLEVEL 0)
0
repos
repos/range-v3/CREDITS.md
Acknowledgements ---------------- In range-v3, I have integrated many ideas that come from other people. I would be remiss to not mention them. Many others helped either directly or indirectly in a variety of ways. In no particular order... | Contributor | Contribution | |-----------------------------|------| | Jeremy Siek | Container algorithms (in Boost pre-history), Boost.Iterators | | Thorston Ottoson | Boost.Range v1 | | Neil Groves | Boost.Range v2 | | David Abrahams, Thomas Witt | Boost.Iterators, Sentinels | | Sean Parent | ASL, Projections, View / Range distinction, much Generic Program wisdom besides | | Dietmar Kühl | Array Traits, Property Map | | Andrew Sutton | C++ Concepts "Lite", Origin Libraries, Palo Alto Report | | Doug Gregor | C++0x Concepts | | Casey Carter | Co-author and Editor, Ranges TS; major code contributions | | Gonzalo Brito Gadeschi | Many ideas, bug reports, and code contributions | | Alexander Stepanov | STL, Generic Programming, Iterators, Elements of Programming, etc. | | Bjarne Stroustrup | A tireless effort to add proper support for Generic Programming to C++, early support for my Ranges proposal | | Herb Sutter | Early support for my Ranges proposal | | The Standard C++ Foundation | A generous grant supporting my Ranges work | An Abreviated History -------------------- **Range v1** I came to Boost in the early 2000's. By that time, Boost already had a Range library (Thorston Ottoson's). At this time, Boost.Range was little more that the `begin` and `end` free functions, and range-based overloads of the STL algorithms that dispatched to the iterator-based overloads in namespace `std`. Boost also already had the Iterators library by David Abrahams and Jeremy Siek. This library had iterator adaptors like `filter_iterator` and `transform_iterator`. **Range v2** It seemed natural to me that the Range library and the adaptors from the Iterators library should be combined. I wrote the `filter` and `transform` range adaptors, commandeered the pipe operator (`|`) from bash for chaining, and put a rough library together called Range_ex in the Boost File Vault (which would later become the Boost Sandbox). I saw problems with my design and never finished it. A few years later, Neil Groves picked up some of the ideas in my Range\_ex, polished them a great deal, published his own Range\_ex library, and submitted it to Boost. It became Boost.Range v2. At the time of writing (March, 2017), it is the version still shipping with Boost. **Range v3** In 2013, I published a blog post called ["Out Parameters, Move Semantics, and Stateful Algorithms"](http://ericniebler.com/2013/10/13/out-parameters-vs-move-semantics/) that turned my mind to ranges once again. Following that, it became clear to me that the Boost.Range library, designed for C++98, needed a facelift for the post-C++11 world. I began what I believed at the time would be a quick hack to bring Boost.Range into the modern world. I called it "Range v3", thinking it would become the third major version of the Boost.Range library. Subsequent posts detailed the evolution of my thinking as range-v3 took shape. **Standardization** Around this time, some big thinkers in the C++ community were working to resurrect the effort to add Concepts to C++. They published a paper ([N3351](http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2012/n3351.pdf)) that would become known as the **"Palo Alto Report"** which detailed the necessary and sufficient language and library support for a concept-checked version of the Standard Template Library. The authors of the paper included Alexander Stepanov, Bjarne Stroustrup, Sean Parent, Andrew Sutton, and more. Andrew Sutton began working in earnest to realize the core language changes, an effort that became known as "Concepts Lite". It became the Concepts TS and ultimately C++20's `concept` language feature. I realized early on that Concepts Lite, or something like it, would become part of Standard C++. Recognizing that C++ would need a concept-ified Standard Library to go with the language feature, I began evolving range-v3 in that direction, eventually submitting ["Ranges for the Standard Library, Revision 1"](http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2014/n4128.html) to the C++ Standardization Committee, together with Andrew Sutton and Sean Parent. The Committee approved the direction in late 2014, and so it goes... As of today (2022-06), C++20 has shipped with modest ranges support in the `std::ranges` namespace, with *much* more to come in C++23 and beyond. Stay tuned.
0
repos
repos/range-v3/install_libcxx.sh
#!/usr/bin/env bash TRUNK_VERSION="9.0.0" set -e # The pattern of clang --version is: clang version X.Y.Z (sometimes, see below). COMPILER_VERSION_OUTPUT="$($CXX --version)" arr=(${COMPILER_VERSION_OUTPUT// / }) COMPILER="${arr[0]}" VERSION="${arr[2]}" case $COMPILER in "clang") # Some Ubuntu clang builds are advertised as "just clang", but the # Version still follows the pattern: 3.6.2-svn240577-1~exp1 # echo "Compiler is clang :)" arr2=(${VERSION//-/ }) VERSION="${arr2[0]}" ;; "Ubuntu") # Ubuntu renames _some_ (not all) of its clang compilers, the pattern of # clang --version is then: # Ubuntu clang version 3.6.2-svn240577-1~exp1 COMPILER="${arr[1]}" VERSION="${arr[3]}" arr2=(${VERSION//-/ }) VERSION="${arr2[0]}" ;; *) echo "case did not match: compiler: ${COMPILER}" exit 1 ;; esac if [ ${COMPILER} != "clang" ]; then echo "Error: trying to install libc++ for a compiler that is not clang: ${COMPILER}" exit 1 fi if [ -z ${VERSION+x} ]; then echo "Malformed libc++ version - I give up." exit 4 fi if [ ${VERSION} == $TRUNK_VERSION ]; then echo "Fetching libc++ and libc++abi tip-of-trunk..." # Checkout LLVM sources git clone --depth=1 https://github.com/llvm-mirror/llvm.git llvm-source git clone --depth=1 https://github.com/llvm-mirror/libcxx.git llvm-source/projects/libcxx git clone --depth=1 https://github.com/llvm-mirror/libcxxabi.git llvm-source/projects/libcxxabi else echo "Fetching libc++/libc++abi version: ${VERSION} ..." MAJOR=$(echo ${VERSION} | cut -d '.' -f 1) if [[ ${MAJOR} -lt 14 ]]; then URL_ROOT="https://releases.llvm.org/${VERSION}" else URL_ROOT="https://github.com/llvm/llvm-project/releases/download/llvmorg-${VERSION}" fi echo "From url ${URL_ROOT} ..." LLVM_URL="${URL_ROOT}/llvm-${VERSION}.src.tar.xz" LIBCXX_URL="${URL_ROOT}/libcxx-${VERSION}.src.tar.xz" LIBCXXABI_URL="${URL_ROOT}/libcxxabi-${VERSION}.src.tar.xz" curl -LO $LLVM_URL curl -LO $LIBCXX_URL curl -LO $LIBCXXABI_URL mkdir llvm-source mkdir llvm-source/projects mkdir llvm-source/projects/libcxx mkdir llvm-source/projects/libcxxabi tar -xf llvm-${VERSION}.src.tar.xz -C llvm-source --strip-components=1 tar -xf libcxx-${VERSION}.src.tar.xz -C llvm-source/projects/libcxx --strip-components=1 tar -xf libcxxabi-${VERSION}.src.tar.xz -C llvm-source/projects/libcxxabi --strip-components=1 fi TARGET=`pwd`/llvm mkdir "${TARGET}" mkdir llvm-build cd llvm-build # - libc++ versions < 4.x do not have the install-cxxabi and install-cxx targets # - only ASAN is enabled for clang/libc++ versions < 4.x if [[ $VERSION == *"3."* ]]; then cmake -DCMAKE_C_COMPILER=${CC} -DCMAKE_CXX_COMPILER=${CXX} \ -DCMAKE_BUILD_TYPE=RelWithDebInfo -DCMAKE_INSTALL_PREFIX="${TARGET}" \ ../llvm-source if [[ $SANITIZER == "Address;Undefined" ]]; then ASAN_FLAGS="-fsanitize=address" cmake -DCMAKE_CXX_FLAGS="${ASAN_FLAGS}" -DCMAKE_EXE_LINKER_FLAGS="${ASAN_FLAGS}" ../llvm-source fi make cxx -j2 VERBOSE=1 mkdir "${TARGET}/lib" mkdir "${TARGET}/include" cp -r lib/* "${TARGET}/lib" cp -r include/c++ "${TARGET}/include" else cmake -DCMAKE_C_COMPILER=${CC} -DCMAKE_CXX_COMPILER=${CXX} \ -DCMAKE_BUILD_TYPE=RelWithDebInfo -DCMAKE_INSTALL_PREFIX="${TARGET}" \ -DLIBCXX_ABI_UNSTABLE=ON \ -DLLVM_USE_SANITIZER=${SANITIZER} \ ../llvm-source make cxx -j2 VERBOSE=1 make install-cxxabi install-cxx fi exit 0
0
repos
repos/range-v3/CMakeLists.txt
# Copyright Eric Niebler 2014 # Copyright Gonzalo Brito Gadeschi 2014, 2017 # Copyright Louis Dionne 2015 # Copyright Casey Carter 2016 # Distributed under the Boost Software License, Version 1.0. # (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) cmake_minimum_required(VERSION 3.6) get_directory_property(is_subproject PARENT_DIRECTORY) if(NOT is_subproject) set(is_standalone YES) else() set(is_standalone NO) endif() project(Range-v3 CXX) list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake") set(CMAKE_EXPORT_COMPILE_COMMANDS ON) # Export compilation data-base set_property(GLOBAL PROPERTY USE_FOLDERS ON) include(ranges_options) include(ranges_env) include(ranges_flags) add_library(range-v3-meta INTERFACE) add_library(range-v3::meta ALIAS range-v3-meta) target_include_directories(range-v3-meta INTERFACE $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include/>) target_include_directories(range-v3-meta SYSTEM INTERFACE $<INSTALL_INTERFACE:$<INSTALL_PREFIX>/include>) target_compile_options(range-v3-meta INTERFACE $<$<COMPILE_LANG_AND_ID:CXX,MSVC>:/permissive-> $<$<COMPILE_LANG_AND_ID:CUDA,MSVC>:-Xcompiler=/permissive->) add_library(range-v3-concepts INTERFACE) add_library(range-v3::concepts ALIAS range-v3-concepts) target_include_directories(range-v3-concepts INTERFACE $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include/>) target_include_directories(range-v3-concepts SYSTEM INTERFACE $<INSTALL_INTERFACE:$<INSTALL_PREFIX>/include>) target_compile_options(range-v3-concepts INTERFACE $<$<COMPILE_LANG_AND_ID:CXX,MSVC>:/permissive-> $<$<COMPILE_LANG_AND_ID:CUDA,MSVC>:-Xcompiler=/permissive->) target_link_libraries(range-v3-concepts INTERFACE range-v3::meta) add_library(range-v3 INTERFACE) add_library(range-v3::range-v3 ALIAS range-v3) target_include_directories(range-v3 INTERFACE $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include/>) target_include_directories(range-v3 SYSTEM INTERFACE $<INSTALL_INTERFACE:$<INSTALL_PREFIX>/include>) target_compile_options(range-v3 INTERFACE $<$<COMPILE_LANG_AND_ID:CXX,MSVC>:/permissive-> $<$<COMPILE_LANG_AND_ID:CUDA,MSVC>:-Xcompiler=/permissive->) target_link_libraries(range-v3 INTERFACE range-v3::concepts range-v3::meta) function(rv3_add_test TESTNAME EXENAME FIRSTSOURCE) add_executable(range.v3.${EXENAME} ${FIRSTSOURCE} ${ARGN}) target_link_libraries(range.v3.${EXENAME} range-v3) add_test(range.v3.${TESTNAME} range.v3.${EXENAME}) endfunction(rv3_add_test) if(RANGE_V3_DOCS) add_subdirectory(doc) endif() if(RANGE_V3_TESTS) include(CTest) add_subdirectory(test) endif() if(RANGE_V3_EXAMPLES) add_subdirectory(example) endif() if(RANGE_V3_PERF) include(gtest) include(gbenchmark) add_subdirectory(perf) endif() # Add header files as sources to fix MSVS 2017 not finding source during debugging file(GLOB_RECURSE RANGE_V3_PUBLIC_HEADERS_ABSOLUTE "${CMAKE_CURRENT_SOURCE_DIR}/include/*.hpp") add_custom_target(range.v3.headers SOURCES ${RANGE_V3_PUBLIC_HEADERS_ABSOLUTE}) set_target_properties(range.v3.headers PROPERTIES FOLDER "header") # Test all headers if(RANGE_V3_HEADER_CHECKS) include(TestHeaders) file(GLOB_RECURSE RANGE_V3_PUBLIC_HEADERS RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}/include" "${CMAKE_CURRENT_SOURCE_DIR}/include/*.hpp") # These headers are not meant to be included directly: list(REMOVE_ITEM RANGE_V3_PUBLIC_HEADERS std/detail/associated_types.hpp) list(REMOVE_ITEM RANGE_V3_PUBLIC_HEADERS range/v3/detail/epilogue.hpp) # Deprecated headers if(CMAKE_CXX_COMPILER_ID STREQUAL GNU) foreach(header ${RANGE_V3_PUBLIC_HEADERS}) file(STRINGS "${CMAKE_CURRENT_SOURCE_DIR}/include/${header}" is_deprecated LIMIT_COUNT 1 REGEX ".*RANGES_DEPRECATED_HEADER.*") if(is_deprecated) list(APPEND RANGE_V3_DEPRECATED_PUBLIC_HEADERS "${header}") endif() endforeach() endif() if(NOT RANGE_V3_COROUTINE_FLAGS) # Can't test this header if we can't even compile it list(APPEND RANGE_V3_DEPRECATED_PUBLIC_HEADERS range/v3/experimental/utility/generator.hpp) endif() add_header_test(test.range.v3.headers EXCLUDE ${RANGE_V3_DEPRECATED_PUBLIC_HEADERS} HEADERS ${RANGE_V3_PUBLIC_HEADERS}) target_link_libraries(test.range.v3.headers PRIVATE range-v3) endif() # Grab the range-v3 version numbers: include(${CMAKE_CURRENT_SOURCE_DIR}/Version.cmake) set(RANGE_V3_VERSION ${RANGE_V3_MAJOR}.${RANGE_V3_MINOR}.${RANGE_V3_PATCHLEVEL}) # Try to build a new version.hpp configure_file(version.hpp.in include/range/v3/version.hpp @ONLY) file(STRINGS ${CMAKE_CURRENT_BINARY_DIR}/include/range/v3/version.hpp RANGE_V3_OLD_VERSION_HPP) file(STRINGS ${CMAKE_CURRENT_SOURCE_DIR}/include/range/v3/version.hpp RANGE_V3_NEW_VERSION_HPP) # If the new version.hpp is materially different from the one in the source # directory, update it, commit, and tag. if(NOT RANGE_V3_NEW_VERSION_HPP STREQUAL RANGE_V3_OLD_VERSION_HPP) # Check that doc/release_notes.md and Version.cmake are the only changed file: execute_process( COMMAND ${GIT_EXECUTABLE} -C "${CMAKE_CURRENT_SOURCE_DIR}" status --porcelain -uno OUTPUT_VARIABLE RANGE_V3_GIT_STATUS OUTPUT_STRIP_TRAILING_WHITESPACE ) string(REPLACE "\n" ";" RANGE_V3_GIT_STATUS ${RANGE_V3_GIT_STATUS}) if (NOT "x${RANGE_V3_GIT_STATUS}" STREQUAL "x M Version.cmake; M doc/release_notes.md") message(FATAL_ERROR "Cannot update version.hpp: range-v3 source directory has a dirty status") endif() file( COPY ${CMAKE_CURRENT_BINARY_DIR}/include/range/v3/version.hpp DESTINATION ${CMAKE_CURRENT_SOURCE_DIR}/include/range/v3 ) execute_process( COMMAND ${GIT_EXECUTABLE} -C "${CMAKE_CURRENT_SOURCE_DIR}" add -u ) execute_process( COMMAND ${GIT_EXECUTABLE} -C "${CMAKE_CURRENT_SOURCE_DIR}" commit -m "${RANGE_V3_VERSION}" ) execute_process( COMMAND ${GIT_EXECUTABLE} -C "${CMAKE_CURRENT_SOURCE_DIR}" tag -f -a "${RANGE_V3_VERSION}" -m "${RANGE_V3_VERSION}" ) find_program(CONAN_EXECUTABLE NAMES conan conan.exe) if (NOT "x${CONAN_EXECUTABLE}" STREQUAL "xCONAN_EXECUTABLE-NOTFOUND") message(STATUS "Exporting conanfile for new version") execute_process( COMMAND ${CONAN_EXECUTABLE} create . range-v3/${RANGE_V3_VERSION}@ericniebler/stable WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}" ) endif() message(STATUS "Version updated to ${RANGE_V3_VERSION}. Don't forget to:") message(STATUS " git push origin <feature-branch>") message(STATUS "and (after that is merged to master) then:") message(STATUS " conan remote add range-v3 https://api.bintray.com/conan/range-v3/range-v3") message(STATUS " conan create ${CMAKE_CURRENT_SOURCE_DIR} range-v3/${RANGE_V3_VERSION}@ericniebler/stable") message(STATUS " conan upload --all range-v3/${RANGE_V3_VERSION}@ericniebler/stable -r=range-v3") endif() if (RANGE_V3_INSTALL) include(CMakePackageConfigHelpers) # write_basic_package_version_file(...) gained ARCH_INDEPENDENT in CMake 3.14. # For CMake 3.6, this workaround makes the version file ARCH_INDEPENDENT # by making CMAKE_SIZEOF_VOID_P empty. set(OLD_CMAKE_SIZEOF_VOID_P ${CMAKE_SIZEOF_VOID_P}) set(CMAKE_SIZEOF_VOID_P "") write_basic_package_version_file( ${CMAKE_CURRENT_BINARY_DIR}/range-v3-config-version.cmake VERSION ${RANGE_V3_VERSION} COMPATIBILITY ExactVersion ) set(CMAKE_SIZEOF_VOID_P ${OLD_CMAKE_SIZEOF_VOID_P}) include(GNUInstallDirs) install(TARGETS range-v3-concepts range-v3-meta range-v3 EXPORT range-v3-targets DESTINATION ${CMAKE_INSTALL_LIBDIR}) install(EXPORT range-v3-targets FILE range-v3-targets.cmake DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/range-v3) install(FILES ${CMAKE_CURRENT_BINARY_DIR}/range-v3-config-version.cmake cmake/range-v3-config.cmake DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/range-v3) install(DIRECTORY include/ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} FILES_MATCHING PATTERN "*") export(EXPORT range-v3-targets FILE range-v3-config.cmake) endif()
0
repos
repos/range-v3/LICENSE.txt
======================================================== Boost Software License - Version 1.0 - August 17th, 2003 ======================================================== Permission is hereby granted, free of charge, to any person or organization obtaining a copy of the software and accompanying documentation covered by this license (the "Software") to use, reproduce, display, distribute, execute, and transmit the Software, and to prepare derivative works of the Software, and to permit third-parties to whom the Software is furnished to do so, all subject to the following: The copyright notices in the Software and this entire statement, including the above license grant, this restriction and the following disclaimer, must be included in all copies of the Software, in whole or in part, and all derivative works of the Software, unless such copies or derivative works are solely in the form of machine-executable object code generated by a source language processor. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ============================================================================== libc++ License ============================================================================== The libc++ library is dual licensed under both the University of Illinois "BSD-Like" license and the MIT license. As a user of this code you may choose to use it under either license. As a contributor, you agree to allow your code to be used under both. Full text of the relevant licenses is included below. ============================================================================== University of Illinois/NCSA Open Source License Copyright (c) 2009-2014 by the contributors listed in CREDITS.TXT http://llvm.org/svn/llvm-project/libcxx/trunk/CREDITS.TXT All rights reserved. Developed by: LLVM Team University of Illinois at Urbana-Champaign http://llvm.org Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal with the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimers. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimers in the documentation and/or other materials provided with the distribution. * Neither the names of the LLVM Team, University of Illinois at Urbana-Champaign, nor the names of its contributors may be used to endorse or promote products derived from this Software without specific prior written permission. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS WITH THE SOFTWARE. ============================================================================== Copyright (c) 2009-2014 by the contributors listed in CREDITS.TXT http://llvm.org/svn/llvm-project/libcxx/trunk/CREDITS.TXT Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ============================================================================== Stepanov and McJones, "Elements of Programming" license ============================================================================== // Copyright (c) 2009 Alexander Stepanov and Paul McJones // // Permission to use, copy, modify, distribute and sell this software // and its documentation for any purpose is hereby granted without // fee, provided that the above copyright notice appear in all copies // and that both that copyright notice and this permission notice // appear in supporting documentation. The authors make no // representations about the suitability of this software for any // purpose. It is provided "as is" without express or implied // warranty. // // Algorithms from // Elements of Programming // by Alexander Stepanov and Paul McJones // Addison-Wesley Professional, 2009 ============================================================================== SGI C++ Standard Template Library license ============================================================================== // Copyright (c) 1994 // Hewlett-Packard Company // // Permission to use, copy, modify, distribute and sell this software // and its documentation for any purpose is hereby granted without fee, // provided that the above copyright notice appear in all copies and // that both that copyright notice and this permission notice appear // in supporting documentation. Hewlett-Packard Company makes no // representations about the suitability of this software for any // purpose. It is provided "as is" without express or implied warranty. // // Copyright (c) 1996 // Silicon Graphics Computer Systems, Inc. // // Permission to use, copy, modify, distribute and sell this software // and its documentation for any purpose is hereby granted without fee, // provided that the above copyright notice appear in all copies and // that both that copyright notice and this permission notice appear // in supporting documentation. Silicon Graphics makes no // representations about the suitability of this software for any // purpose. It is provided "as is" without express or implied warranty. //
0
repos
repos/range-v3/README.md
range-v3 ======== Range library for C++14/17/20. This code was the basis of [a formal proposal](https://ericniebler.github.io/std/wg21/D4128.html) to add range support to the C++ standard library. That proposal evolved through a Technical Specification, and finally into [P0896R4 "The One Ranges Proposal"](https://wg21.link/p0896r4) which was merged into the C++20 working drafts in November 2018. About: ------ Ranges are an extension of the Standard Template Library that makes its iterators and algorithms more powerful by making them _composable_. Unlike other range-like solutions which seek to do away with iterators, in range-v3 ranges are an abstraction layer _on top_ of iterators. Range-v3 is built on three pillars: Views, Actions, and Algorithms. The algorithms are the same as those with which you are already familiar in the STL, except that in range-v3 all the algorithms have overloads that take ranges in addition to the overloads that take iterators. Views are composable adaptations of ranges where the adaptation happens lazily as the view is iterated. And an action is an eager application of an algorithm to a container that mutates the container in-place and returns it for further processing. Views and actions use the pipe syntax (e.g., `rng | adapt1 | adapt2 | ...`) so your code is terse and readable from left to right. Documentation: -------------- Check out the (woefully incomplete) documentation [here](https://ericniebler.github.io/range-v3/). Other resources (mind the dates, the library probably has changed since then): - Usage: - Talk: [CppCon 2015: Eric Niebler "Ranges for the Standard Library"](https://www.youtube.com/watch?v=mFUXNMfaciE), 2015. - [A slice of Python in C++](http://ericniebler.com/2014/12/07/a-slice-of-python-in-c/), 07.12.2014. - Actions (back then called [Container Algorithms](http://ericniebler.com/2014/11/23/container-algorithms/)), 23.11.2014. - [Range comprehensions](http://ericniebler.com/2014/04/27/range-comprehensions/), 27.04.2014. - [Input iterators vs input ranges](http://ericniebler.com/2013/11/07/input-iterators-vs-input-ranges/), 07.11.2013. - Design / Implementation: - Rationale behind range-v3: [N4128: Ranges for the standard library Revision 1](http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2014/n4128.html), 2014. - Ranges TS: [N4560: C++ Extensions for Ranges](http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2015/n4560.pdf), 2015. - Implementation of customization points in range-v3: - [N4381: Suggested Design for Customization Points](http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2015/n4381.html), 2015. - [P0386: Inline variables](http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2016/p0386r0.pdf), 2016. - [Customization Point Design in C++11 and Beyond](http://ericniebler.com/2014/10/21/customization-point-design-in-c11-and-beyond/), 2014. - Proxy iterators in range-v3: - [D0022: Proxy Iterators for the Ranges Extensions](https://ericniebler.github.io/std/wg21/D0022.html). - [To Be or Not to Be (an Iterator)](http://ericniebler.com/2015/01/28/to-be-or-not-to-be-an-iterator/), 2015. - [Iterators++: Part1](http://ericniebler.com/2015/02/03/iterators-plus-plus-part-1/), 2015. - [Iterators++: Part2](http://ericniebler.com/2015/02/13/iterators-plus-plus-part-2/), 2015. - [Iterators++: Part3](http://ericniebler.com/2015/03/03/iterators-plus-plus-part-3/), 2015. - Metaprogramming utilities: - See the [meta documentation](https://ericniebler.github.io/meta/index.html), the library has changed significantly since the [2014 blog post](http://ericniebler.com/2014/11/13/tiny-metaprogramming-library/). - Concept emulation layer: [Concept checking in C++11](http://ericniebler.com/2013/11/23/concept-checking-in-c11/), 2013. - [C++Now 2014: Eric Niebler "C++11 Library Design"](https://www.youtube.com/watch?v=zgOF4NrQllo), 2014. License: -------- Most of the source code in this project are mine, and those are under the Boost Software License. Parts are taken from Alex Stepanov's Elements of Programming, Howard Hinnant's libc++, and from the SGI STL. Please see the attached LICENSE file and the CREDITS file for the licensing and acknowledgments. Supported Compilers ------------------- The code is known to work on the following compilers: - clang 5.0 (or later) - GCC 6.5 (or later) - Clang/LLVM 6 (or later) on Windows (older versions may work - we haven't tested.) - Visual Studio 2019 (or later) on Windows, with some caveats due to range-v3's strict conformance requirements: - range-v3 needs `/permissive-` and either `/std:c++latest`, `/std:c++20`, or `/std:c++17` **Development Status:** This code is fairly stable, well-tested, and suitable for casual use, although currently lacking documentation. _In general_, no promise is made about support or long-term stability. This code *will* evolve without regard to backwards compatibility. A notable exception is anything found within the `ranges::cpp20` namespace. Those components will change rarely or (preferably) never at all. **Build status** - on GitHub Actions: [![GitHub Actions Status](https://github.com/ericniebler/range-v3/workflows/range-v3%20CI/badge.svg?branch=master)](https://github.com/ericniebler/range-v3/actions) Building range-v3 - Using vcpkg ------------------------------- You can download and install range-v3 using the [vcpkg](https://github.com/Microsoft/vcpkg) dependency manager: ```sh git clone https://github.com/Microsoft/vcpkg.git cd vcpkg ./bootstrap-vcpkg.sh ./vcpkg integrate install ./vcpkg install range-v3 ``` The range-v3 port in vcpkg is kept up to date by Microsoft team members and community contributors. If the version is out of date, please [create an issue or pull request](https://github.com/Microsoft/vcpkg) on the vcpkg repository. Building range-v3 - Using Conan ------------------------------- You can download and install range-v3 using the [Conan](https://github.com/conan-io/conan) dependency manager. Setup your CMakeLists.txt (see [Conan documentation](https://docs.conan.io/en/latest/integrations/build_system.html) on how to use MSBuild, Meson and others): ```cmake project(myproject CXX) add_executable(${PROJECT_NAME} main.cpp) include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake) # Include Conan-generated file conan_basic_setup(TARGETS) # Introduce Conan-generated targets target_link_libraries(${PROJECT_NAME} CONAN_PKG::range-v3) ``` Create `conanfile.txt` in your source dir: ```sh [requires] range-v3/0.12.0 [generators] cmake ``` Install and run `conan`, then build your project as always: ```sh pip install conan mkdir build cd build conan install ../ --build=missing cmake ../ cmake --build . ``` Building range-v3 - Using `build2` ---------------------------------- You can use [`build2`](https://build2.org), a dependency manager and build-system combined, to use `range-v3` (or work on it): Currently this package is available in these package repositories: - **https://cppget.org/range-v3/** for released and published versions. - [**The git repository with the sources of the `build2` package of `range-v3`**](https://github.com/build2-packaging/range-v3.git) for unreleased or custom revisions of `range-v3`, or for working on it with `build2`. ### Usage: - `build2` package name: `range-v3` - Library target name : `lib{range-v3}` - [Detailed use cases and instructions in this document](https://github.com/build2-packaging/range-v3/blob/master/NOTES-build2.md). For example, to make your `build2` project depend on `range-v3`: - Add one of the repositories to your configurations, or in your `repositories.manifest`, if not already there; for example: ``` : role: prerequisite location: https://pkg.cppget.org/1/alpha # v0.11.0 is there. ``` - Add this package as a dependency to your `manifest` file (example for `v0.11.x`): ``` depends: range-v3 ~0.11.0 ``` - Import the target and use it as a prerequisite to your own target using `range-v3` in the appropriate `buildfile`: ```py import range_v3 = range-v3%lib{range-v3} lib{mylib} : cxx{**} ... $range_v3 ``` Then just build your project as usual (with `b` or `bdep update`), `build2` will figure out the rest. For `build2` newcomers or to get more details and use cases, you can read [this document](https://github.com/build2-packaging/range-v3/blob/master/NOTES-build2.md) and the [`build2` toolchain introduction](https://build2.org/build2-toolchain/doc/build2-toolchain-intro.xhtml). Say Thanks! ----------- I do this work because I love it and because I love C++ and want it to be as excellent as I know it can be. If you like my work and are looking for a way to say thank you, you can leave a supportive comment on [my blog](http://ericniebler.com). Or you could leave me some kudos on my Open Hub range-v3 contribution page. Just click the **Give Kudos** button [here](https://www.openhub.net/p/range-v3/contributors/3053743222308608).
0
repos
repos/range-v3/build.zig.zon
.{ .name = "range-v3", .version = "0.13.0", .paths = .{ "include", "build.zig", "build.zig;zon", "test", "example", "README.md", "LICENSE.txt", }, }
0
repos
repos/range-v3/build.zig
//! Zi version 0.13 or higher const std = @import("std"); // Although this function looks imperative, note that its job is to // declaratively construct a build graph that will be executed by an external // runner. pub fn build(b: *std.Build) void { // Standard target options allows the person running `zig build` to choose // what target to build for. Here we do not override the defaults, which // means any target is allowed, and the default is native. Other options // for restricting supported target set are available. const target = b.standardTargetOptions(.{}); // Standard optimization options allow the person running `zig build` to select // between Debug, ReleaseSafe, ReleaseFast, and ReleaseSmall. Here we do not // set a preferred release mode, allowing the user to decide how to optimize. const optimize = b.standardOptimizeOption(.{}); // Options const tests = b.option(bool, "tests", "Build tests [default: false]") orelse false; const librange = b.addStaticLibrary(.{ .name = "range-v3", .target = target, .optimize = optimize, }); librange.addIncludePath(b.path("include")); librange.installHeadersDirectory(b.path("include"), "", .{ .exclude_extensions = &.{"modulemap"}, }); const empty_cpp = b.addWriteFile("empty.cpp", "// bypass for zig build"); librange.addCSourceFiles(.{ .root = empty_cpp.getDirectory(), .files = &.{"empty.cpp"}, }); b.installArtifact(librange); if (tests) { inline for (&.{ "example/hello.cpp", "example/comprehensions.cpp", "example/count_if.cpp", "example/sort_unique.cpp", "example/for_each_assoc.cpp", "example/any_all_none_of.cpp", "example/view/transform.cpp", "example/view/filter.cpp", "perf/sort_patterns.cpp", "perf/counted_insertion_sort.cpp", "test/functional/bind_back.cpp", "test/bug474.cpp", "test/bug566.cpp", "test/bug1322.cpp", "test/bug1335.cpp", "test/bug1633.cpp", "test/bug1729.cpp", "test/multiple2.cpp", "test/constexpr_core.cpp", "test/config.cpp", "test/algorithm/binary_search.cpp", "test/algorithm/adjacent_remove_if.cpp", "test/algorithm/adjacent_find.cpp", "test/algorithm/generate_n.cpp", "test/algorithm/shuffle.cpp", "test/algorithm/swap_ranges.cpp", "test/algorithm/sort_n_with_buffer.cpp", "test/algorithm/unique.cpp", "test/range/conversion.cpp", "test/algorithm/make_heap.cpp", "test/algorithm/mismatch.cpp", "test/algorithm/sort_heap.cpp", "test/algorithm/stable_partition.cpp", "test/algorithm/next_permutation.cpp", "test/range/operations.cpp", "test/algorithm/set_union1.cpp", "test/algorithm/move_backward.cpp", "test/experimental/view/shared.cpp", "test/algorithm/set_union2.cpp", "test/algorithm/set_union3.cpp", "test/algorithm/set_union4.cpp", "test/algorithm/set_union5.cpp", "test/algorithm/set_union6.cpp", "test/algorithm/unstable_remove_if.cpp", "test/algorithm/nth_element.cpp", "test/algorithm/lexicographical_compare.cpp", // "test/experimental/utility/generator.cpp", // experimental::range }) |example| { buildTest(b, .{ .lib = librange, .path = example, }); } } } fn buildTest(b: *std.Build, info: BuildInfo) void { const test_exe = b.addExecutable(.{ .name = info.filename(), .optimize = info.lib.root_module.optimize.?, .target = info.lib.root_module.resolved_target.?, }); for (info.lib.root_module.include_dirs.items) |include_dir| { test_exe.root_module.include_dirs.append(b.allocator, include_dir) catch unreachable; } test_exe.addIncludePath(b.path("test")); test_exe.addCSourceFile(.{ .file = b.path(info.path), .flags = cxxFlags, }); if (test_exe.rootModuleTarget().abi == .msvc) test_exe.linkLibC() else test_exe.linkLibCpp(); b.installArtifact(test_exe); const run_cmd = b.addRunArtifact(test_exe); run_cmd.step.dependOn(b.getInstallStep()); if (b.args) |args| { run_cmd.addArgs(args); } const run_step = b.step( b.fmt("{s}", .{info.filename()}), b.fmt("Run the {s} test", .{info.filename()}), ); run_step.dependOn(&run_cmd.step); } const cxxFlags = &.{ // "-std=c++20", "-Wall", "-Wextra", "-Wpedantic", }; const BuildInfo = struct { lib: *std.Build.Step.Compile, path: []const u8, fn filename(self: BuildInfo) []const u8 { var split = std.mem.splitSequence(u8, std.fs.path.basename(self.path), "."); return split.first(); } };
0
repos
repos/range-v3/version.hpp.in
/// \file // Range v3 library // // Copyright Eric Niebler 2017-present // // Use, modification and distribution is subject to the // Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) // // Project home: https://github.com/ericniebler/range-v3 // #ifndef RANGES_V3_VERSION_HPP #define RANGES_V3_VERSION_HPP #define RANGE_V3_MAJOR @RANGE_V3_MAJOR@ #define RANGE_V3_MINOR @RANGE_V3_MINOR@ #define RANGE_V3_PATCHLEVEL @RANGE_V3_PATCHLEVEL@ #define RANGE_V3_VERSION \ (RANGE_V3_MAJOR * 10000 + RANGE_V3_MINOR * 100 + RANGE_V3_PATCHLEVEL) #endif
0
repos
repos/range-v3/conanfile.py
# Range v3 library # # Copyright Luis Martinez de Bartolome Izquierdo 2016 # # Use, modification and distribution is subject to the # Boost Software License, Version 1.0. (See accompanying # file LICENSE_1_0.txt or copy at # http://www.boost.org/LICENSE_1_0.txt) # # Project home: https://github.com/ericniebler/range-v3 # from conans import ConanFile, CMake class Rangev3Conan(ConanFile): name = "range-v3" version = "0.12.0" license = "Boost Software License - Version 1.0 - August 17th, 2003" url = "https://github.com/ericniebler/range-v3" description = """Experimental range library for C++14/17/20""" # No settings/options are necessary, this is header only exports_sources = "include*", "LICENSE.txt", "CMakeLists.txt", "cmake/*", "Version.cmake", "version.hpp.in" no_copy_source = True def package(self): cmake = CMake(self) cmake.definitions["RANGE_V3_TESTS"] = "OFF" cmake.definitions["RANGE_V3_EXAMPLES"] = "OFF" cmake.definitions["RANGE_V3_PERF"] = "OFF" cmake.definitions["RANGE_V3_DOCS"] = "OFF" cmake.definitions["RANGE_V3_HEADER_CHECKS"] = "OFF" cmake.configure() cmake.install() self.copy("LICENSE.txt", dst="licenses", ignore_case=True, keep_path=False)
0
repos
repos/range-v3/TODO.md
* Add contiguous iterator utilities. How about `is_contiguous_iterator` and `as_contiguous_range`: ``` CPP_template(typename I, typename S)( requires RandomAccessIterator<I> && SizedSentinel<S, I> && is_contiguous_iterator<I>()) subrange<std::add_pointer_t<iter_reference_t<I>>> as_contiguous_range(I begin, S end) { if(begin == end) return {nullptr, nullptr}; else return {addressof(*begin), addressof(*begin) + (end - begin)}; } ``` * Longer-term goals: - Make `inplace_merge` work with forward iterators - Make the sorting algorithms work with forward iterators * Maybe iterators are not necessarily countable. Is there a relation between the ability to be able to subtract two iterators to find the distance, and with the existence of a DistanceType associated type? Think of: - counted iterators (subtractable regardless of traversal category) - repeat_view iterators (*not* subtractable but could be random access otherwise) - infinite ranges (only countable with an infinite precision integer which we lack)
0
repos/range-v3
repos/range-v3/include/module.modulemap
/// \file // Range v3 library // // Copyright Gonzalo Brito Gadeschi 2017. // // Use, modification and distribution is subject to the // Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) // // Project home: https://github.com/ericniebler/range-v3 // module concepts { umbrella "concepts" export * } module meta { umbrella "meta" export * } module range_v3 { umbrella "range" export * exclude header "range/v3/algorithm/tagspec.hpp" exclude header "range/v3/at.hpp" exclude header "range/v3/back.hpp" exclude header "range/v3/begin_end.hpp" exclude header "range/v3/data.hpp" exclude header "range/v3/distance.hpp" exclude header "range/v3/empty.hpp" exclude header "range/v3/front.hpp" exclude header "range/v3/getlines.hpp" exclude header "range/v3/index.hpp" exclude header "range/v3/istream_range.hpp" exclude header "range/v3/iterator_range.hpp" exclude header "range/v3/range_access.hpp" exclude header "range/v3/range_concepts.hpp" exclude header "range/v3/range_traits.hpp" exclude header "range/v3/size.hpp" exclude header "range/v3/span.hpp" exclude header "range/v3/to_container.hpp" exclude header "range/v3/utility/associated_types.hpp" exclude header "range/v3/utility/basic_iterator.hpp" exclude header "range/v3/utility/common_iterator.hpp" exclude header "range/v3/utility/concepts.hpp" exclude header "range/v3/utility/counted_iterator.hpp" exclude header "range/v3/utility/dangling.hpp" exclude header "range/v3/utility/functional.hpp" exclude header "range/v3/utility/infinity.hpp" exclude header "range/v3/utility/invoke.hpp" exclude header "range/v3/utility/iterator_concepts.hpp" exclude header "range/v3/utility/iterator_traits.hpp" exclude header "range/v3/utility/iterator.hpp" exclude header "range/v3/utility/nullptr_v.hpp" exclude header "range/v3/utility/unreachable.hpp" exclude header "range/v3/view_adaptor.hpp" exclude header "range/v3/view_facade.hpp" exclude header "range/v3/view_interface.hpp" exclude header "range/v3/view/bounded.hpp" }
0
repos/range-v3/include
repos/range-v3/include/concepts/type_traits.hpp
/// \file // Concepts library // // Copyright Eric Niebler 2013-present // // Use, modification and distribution is subject to the // Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) // // Project home: https://github.com/ericniebler/range-v3 #ifndef CPP_TYPE_TRAITS_HPP #define CPP_TYPE_TRAITS_HPP #include <tuple> #include <utility> #include <type_traits> #include <meta/meta.hpp> namespace concepts { template<typename T> using remove_cvref_t = typename std::remove_cv< typename std::remove_reference<T>::type>::type; /// \cond namespace detail { template<typename From, typename To> using is_convertible = std::is_convertible<meta::_t<std::add_rvalue_reference<From>>, To>; template<bool> struct if_else_ { template<typename, typename U> using invoke = U; }; template<> struct if_else_<true> { template<typename T, typename> using invoke = T; }; template<bool B, typename T, typename U> using if_else_t = meta::invoke<if_else_<B>, T, U>; template<bool> struct if_ {}; template<> struct if_<true> { template<typename T> using invoke = T; }; template<bool B, typename T = void> using if_t = meta::invoke<if_<B>, T>; template<typename From, typename To> struct _copy_cv_ { using type = To; }; template<typename From, typename To> struct _copy_cv_<From const, To> { using type = To const; }; template<typename From, typename To> struct _copy_cv_<From volatile, To> { using type = To volatile; }; template<typename From, typename To> struct _copy_cv_<From const volatile, To> { using type = To const volatile; }; template<typename From, typename To> using _copy_cv = meta::_t<_copy_cv_<From, To>>; //////////////////////////////////////////////////////////////////////////////////////// template<typename T, typename U, typename = void> struct _builtin_common; template<typename T, typename U> using _builtin_common_t = meta::_t<_builtin_common<T, U>>; template<typename T, typename U> using _cond_res = decltype(true ? std::declval<T>() : std::declval<U>()); template<typename T, typename U, typename R = _builtin_common_t<T &, U &>> using _rref_res = if_else_t<std::is_reference<R>::value, meta::_t<std::remove_reference<R>> &&, R>; template<typename T, typename U> using _lref_res = _cond_res<_copy_cv<T, U> &, _copy_cv<U, T> &>; template<typename T> struct as_cref_ { using type = T const &; }; template<typename T> struct as_cref_<T &> { using type = T const &; }; template<typename T> struct as_cref_<T &&> { using type = T const &; }; template<> struct as_cref_<void> { using type = void; }; template<> struct as_cref_<void const> { using type = void const; }; template<typename T> using as_cref_t = typename as_cref_<T>::type; template<typename T> using decay_t = typename std::decay<T>::type; #if !defined(__GNUC__) || defined(__clang__) template<typename T, typename U, typename = void> struct _builtin_common_3 {}; template<typename T, typename U> struct _builtin_common_3<T, U, meta::void_<_cond_res<as_cref_t<T>, as_cref_t<U>>>> : std::decay<_cond_res<as_cref_t<T>, as_cref_t<U>>> {}; template<typename T, typename U, typename = void> struct _builtin_common_2 : _builtin_common_3<T, U> {}; template<typename T, typename U> struct _builtin_common_2<T, U, meta::void_<_cond_res<T, U>>> : std::decay<_cond_res<T, U>> {}; template<typename T, typename U, typename /* = void */> struct _builtin_common : _builtin_common_2<T, U> {}; template<typename T, typename U> struct _builtin_common<T &&, U &&, if_t< is_convertible<T &&, _rref_res<T, U>>::value && is_convertible<U &&, _rref_res<T, U>>::value>> { using type = _rref_res<T, U>; }; template<typename T, typename U> struct _builtin_common<T &, U &> : meta::defer<_lref_res, T, U> {}; template<typename T, typename U> struct _builtin_common<T &, U &&, if_t< is_convertible<U &&, _builtin_common_t<T &, U const &>>::value>> : _builtin_common<T &, U const &> {}; template<typename T, typename U> struct _builtin_common<T &&, U &> : _builtin_common<U &, T &&> {}; #else template<typename T, typename U, typename = void> struct _builtin_common_3 {}; template<typename T, typename U> struct _builtin_common_3<T, U, meta::void_<_cond_res<as_cref_t<T>, as_cref_t<U>>>> : std::decay<_cond_res<as_cref_t<T>, as_cref_t<U>>> {}; template<typename T, typename U, typename = void> struct _builtin_common_2 : _builtin_common_3<T, U> {}; template<typename T, typename U> struct _builtin_common_2<T, U, meta::void_<_cond_res<T, U>>> : std::decay<_cond_res<T, U>> {}; template<typename T, typename U, typename /* = void */> struct _builtin_common : _builtin_common_2<T, U> {}; template<typename T, typename U, typename = void> struct _builtin_common_rr : _builtin_common_2<T &&, U &&> {}; template<typename T, typename U> struct _builtin_common_rr<T, U, if_t< is_convertible<T &&, _rref_res<T, U>>::value && is_convertible<U &&, _rref_res<T, U>>::value>> { using type = _rref_res<T, U>; }; template<typename T, typename U> struct _builtin_common<T &&, U &&> : _builtin_common_rr<T, U> {}; template<typename T, typename U> struct _builtin_common<T &, U &> : meta::defer<_lref_res, T, U> {}; template<typename T, typename U, typename = void> struct _builtin_common_lr : _builtin_common_2<T &, T &&> {}; template<typename T, typename U> struct _builtin_common_lr<T, U, if_t< is_convertible<U &&, _builtin_common_t<T &, U const &>>::value>> : _builtin_common<T &, U const &> {}; template<typename T, typename U> struct _builtin_common<T &, U &&> : _builtin_common_lr<T, U> {}; template<typename T, typename U> struct _builtin_common<T &&, U &> : _builtin_common<U &, T &&> {}; #endif } /// \endcond /// \addtogroup group-utility Utility /// @{ /// /// Users should specialize this to hook the \c common_with concept /// until \c std gets a SFINAE-friendly \c std::common_type and there's /// some sane way to deal with cv and ref qualifiers. template<typename ...Ts> struct common_type {}; template<typename T> struct common_type<T> : std::decay<T> {}; template<typename T, typename U> struct common_type<T, U> : detail::if_else_t< (META_IS_SAME(detail::decay_t<T>, T) && META_IS_SAME(detail::decay_t<U>, U) ), meta::defer<detail::_builtin_common_t, T, U>, common_type<detail::decay_t<T>, detail::decay_t<U>>> {}; template<typename... Ts> using common_type_t = typename common_type<Ts...>::type; template<typename T, typename U, typename... Vs> struct common_type<T, U, Vs...> : meta::lazy::fold<meta::list<U, Vs...>, T, meta::quote<common_type_t>> {}; /// @} /// \addtogroup group-utility Utility /// @{ /// /// Users can specialize this to hook the \c common_reference_with concept. /// \sa `common_reference` template< typename T, typename U, template<typename> class TQual, template<typename> class UQual> struct basic_common_reference {}; /// \cond namespace detail { using _rref = meta::quote_trait<std::add_rvalue_reference>; using _lref = meta::quote_trait<std::add_lvalue_reference>; template<typename> struct _xref { template<typename T> using invoke = T; }; template<typename T> struct _xref<T &&> { template<typename U> using invoke = meta::_t<std::add_rvalue_reference<meta::invoke<_xref<T>, U>>>; }; template<typename T> struct _xref<T &> { template<typename U> using invoke = meta::_t<std::add_lvalue_reference<meta::invoke<_xref<T>, U>>>; }; template<typename T> struct _xref<T const> { template<typename U> using invoke = U const; }; template<typename T> struct _xref<T volatile> { template<typename U> using invoke = U volatile; }; template<typename T> struct _xref<T const volatile> { template<typename U> using invoke = U const volatile; }; template<typename T, typename U> using _basic_common_reference = basic_common_reference< remove_cvref_t<T>, remove_cvref_t<U>, _xref<T>::template invoke, _xref<U>::template invoke>; template<typename T, typename U, typename = void> struct _common_reference2 : if_else_t< meta::is_trait<_basic_common_reference<T, U>>::value, _basic_common_reference<T, U>, common_type<T, U>> {}; template<typename T, typename U> struct _common_reference2<T, U, if_t<std::is_reference<_builtin_common_t<T, U>>::value>> : _builtin_common<T, U> {}; } /// \endcond /// Users can specialize this to hook the \c common_reference_with concept. /// \sa `basic_common_reference` template<typename ...Ts> struct common_reference {}; template<typename T> struct common_reference<T> { using type = T; }; template<typename T, typename U> struct common_reference<T, U> : detail::_common_reference2<T, U> {}; template<typename... Ts> using common_reference_t = typename common_reference<Ts...>::type; template<typename T, typename U, typename... Vs> struct common_reference<T, U, Vs...> : meta::lazy::fold<meta::list<U, Vs...>, T, meta::quote<common_reference_t>> {}; /// @} } // namespace concepts #endif
0
repos/range-v3/include
repos/range-v3/include/concepts/concepts.hpp
/// \file // CPP, the Concepts PreProcessor library // // Copyright Eric Niebler 2018-present // Copyright (c) 2018-present, Facebook, Inc. // Copyright (c) 2020-present, Google LLC. // // Use, modification and distribution is subject to the // Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) // // This source code is licensed under the MIT license found in the // LICENSE file in the root directory of this source tree. // // Project home: https://github.com/ericniebler/range-v3 // #ifndef CPP_CONCEPTS_HPP #define CPP_CONCEPTS_HPP // clang-format off #include <initializer_list> #include <utility> #include <type_traits> #include <concepts/swap.hpp> #include <concepts/type_traits.hpp> // Disable buggy clang compatibility warning about "requires" and "concept" being // C++20 keywords. // https://bugs.llvm.org/show_bug.cgi?id=43708 #if defined(__clang__) && __cplusplus <= 201703L #define CPP_PP_IGNORE_CXX2A_COMPAT_BEGIN \ CPP_DIAGNOSTIC_PUSH \ CPP_DIAGNOSTIC_IGNORE_CPP2A_COMPAT #define CPP_PP_IGNORE_CXX2A_COMPAT_END \ CPP_DIAGNOSTIC_POP #else #define CPP_PP_IGNORE_CXX2A_COMPAT_BEGIN #define CPP_PP_IGNORE_CXX2A_COMPAT_END #endif #if defined(_MSC_VER) && !defined(__clang__) #define CPP_WORKAROUND_MSVC_779763 // FATAL_UNREACHABLE calling constexpr function via template parameter #define CPP_WORKAROUND_MSVC_784772 // Failure to invoke *explicit* bool conversion in a constant expression #endif #if !defined(CPP_CXX_CONCEPTS) #ifdef CPP_DOXYGEN_INVOKED #define CPP_CXX_CONCEPTS 201800L #elif defined(__cpp_concepts) && __cpp_concepts > 0 // gcc-6 concepts are too buggy to use #if !defined(__GNUC__) || defined(__clang__) || __GNUC__ >= 7 #define CPP_CXX_CONCEPTS __cpp_concepts #else #define CPP_CXX_CONCEPTS 0L #endif #else #define CPP_CXX_CONCEPTS 0L #endif #endif #define CPP_PP_CAT_(X, ...) X ## __VA_ARGS__ #define CPP_PP_CAT(X, ...) CPP_PP_CAT_(X, __VA_ARGS__) #define CPP_PP_EVAL_(X, ARGS) X ARGS #define CPP_PP_EVAL(X, ...) CPP_PP_EVAL_(X, (__VA_ARGS__)) #define CPP_PP_EVAL2_(X, ARGS) X ARGS #define CPP_PP_EVAL2(X, ...) CPP_PP_EVAL2_(X, (__VA_ARGS__)) #define CPP_PP_EXPAND(...) __VA_ARGS__ #define CPP_PP_EAT(...) #define CPP_PP_FIRST(LIST) CPP_PP_FIRST_ LIST #define CPP_PP_FIRST_(...) __VA_ARGS__ CPP_PP_EAT #define CPP_PP_SECOND(LIST) CPP_PP_SECOND_ LIST #define CPP_PP_SECOND_(...) CPP_PP_EXPAND #define CPP_PP_CHECK(...) CPP_PP_EXPAND(CPP_PP_CHECK_N(__VA_ARGS__, 0,)) #define CPP_PP_CHECK_N(x, n, ...) n #define CPP_PP_PROBE(x) x, 1, #define CPP_PP_PROBE_N(x, n) x, n, #define CPP_PP_IS_PAREN(x) CPP_PP_CHECK(CPP_PP_IS_PAREN_PROBE x) #define CPP_PP_IS_PAREN_PROBE(...) CPP_PP_PROBE(~) // CPP_CXX_VA_OPT #ifndef CPP_CXX_VA_OPT #if __cplusplus > 201703L #define CPP_CXX_VA_OPT_(...) CPP_PP_CHECK(__VA_OPT__(,) 1) #define CPP_CXX_VA_OPT CPP_CXX_VA_OPT_(~) #else #define CPP_CXX_VA_OPT 0 #endif #endif // CPP_CXX_VA_OPT // The final CPP_PP_EXPAND here is to avoid // https://stackoverflow.com/questions/5134523/msvc-doesnt-expand-va-args-correctly #define CPP_PP_COUNT(...) \ CPP_PP_EXPAND(CPP_PP_COUNT_(__VA_ARGS__, \ 50, 49, 48, 47, 46, 45, 44, 43, 42, 41, \ 40, 39, 38, 37, 36, 35, 34, 33, 32, 31, \ 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, \ 20, 19, 18, 17, 16, 15, 14, 13, 12, 11, \ 10, 9, 8, 7, 6, 5, 4, 3, 2, 1,)) #define CPP_PP_COUNT_( \ _01, _02, _03, _04, _05, _06, _07, _08, _09, _10, \ _11, _12, _13, _14, _15, _16, _17, _18, _19, _20, \ _21, _22, _23, _24, _25, _26, _27, _28, _29, _30, \ _31, _32, _33, _34, _35, _36, _37, _38, _39, _40, \ _41, _42, _43, _44, _45, _46, _47, _48, _49, _50, N, ...) \ N #define CPP_PP_IIF(BIT) CPP_PP_CAT_(CPP_PP_IIF_, BIT) #define CPP_PP_IIF_0(TRUE, ...) __VA_ARGS__ #define CPP_PP_IIF_1(TRUE, ...) TRUE #define CPP_PP_LPAREN ( #define CPP_PP_RPAREN ) #define CPP_PP_NOT(BIT) CPP_PP_CAT_(CPP_PP_NOT_, BIT) #define CPP_PP_NOT_0 1 #define CPP_PP_NOT_1 0 #define CPP_PP_EMPTY() #define CPP_PP_COMMA() , #define CPP_PP_LBRACE() { #define CPP_PP_RBRACE() } #define CPP_PP_COMMA_IIF(X) \ CPP_PP_IIF(X)(CPP_PP_EMPTY, CPP_PP_COMMA)() #define CPP_PP_FOR_EACH(M, ...) \ CPP_PP_FOR_EACH_N(CPP_PP_COUNT(__VA_ARGS__), M, __VA_ARGS__) #define CPP_PP_FOR_EACH_N(N, M, ...) \ CPP_PP_CAT(CPP_PP_FOR_EACH_, N)(M, __VA_ARGS__) #define CPP_PP_FOR_EACH_1(M, _1) \ M(_1) #define CPP_PP_FOR_EACH_2(M, _1, _2) \ M(_1), M(_2) #define CPP_PP_FOR_EACH_3(M, _1, _2, _3) \ M(_1), M(_2), M(_3) #define CPP_PP_FOR_EACH_4(M, _1, _2, _3, _4) \ M(_1), M(_2), M(_3), M(_4) #define CPP_PP_FOR_EACH_5(M, _1, _2, _3, _4, _5) \ M(_1), M(_2), M(_3), M(_4), M(_5) #define CPP_PP_FOR_EACH_6(M, _1, _2, _3, _4, _5, _6) \ M(_1), M(_2), M(_3), M(_4), M(_5), M(_6) #define CPP_PP_FOR_EACH_7(M, _1, _2, _3, _4, _5, _6, _7) \ M(_1), M(_2), M(_3), M(_4), M(_5), M(_6), M(_7) #define CPP_PP_FOR_EACH_8(M, _1, _2, _3, _4, _5, _6, _7, _8) \ M(_1), M(_2), M(_3), M(_4), M(_5), M(_6), M(_7), M(_8) #define CPP_PP_PROBE_EMPTY_PROBE_CPP_PP_PROBE_EMPTY \ CPP_PP_PROBE(~) #define CPP_PP_PROBE_EMPTY() #define CPP_PP_IS_NOT_EMPTY(...) \ CPP_PP_EVAL( \ CPP_PP_CHECK, \ CPP_PP_CAT( \ CPP_PP_PROBE_EMPTY_PROBE_, \ CPP_PP_PROBE_EMPTY __VA_ARGS__ ())) #if defined(_MSC_VER) && !defined(__clang__) && (__cplusplus <= 201703L) #define CPP_BOOL(...) ::meta::bool_<__VA_ARGS__>::value #define CPP_TRUE_FN \ !::concepts::detail::instance_< \ decltype(CPP_true_fn(::concepts::detail::xNil{}))> #define CPP_NOT(...) (!CPP_BOOL(__VA_ARGS__)) #else #define CPP_BOOL(...) __VA_ARGS__ #define CPP_TRUE_FN CPP_true_fn(::concepts::detail::xNil{}) #define CPP_NOT(...) (!(__VA_ARGS__)) #endif #define CPP_assert(...) \ static_assert(static_cast<bool>(__VA_ARGS__), \ "Concept assertion failed : " #__VA_ARGS__) #define CPP_assert_msg static_assert #if CPP_CXX_CONCEPTS || defined(CPP_DOXYGEN_INVOKED) #define CPP_concept META_CONCEPT #define CPP_and && #else #define CPP_concept CPP_INLINE_VAR constexpr bool #define CPP_and CPP_and_sfinae #endif //////////////////////////////////////////////////////////////////////////////// // CPP_template // Usage: // CPP_template(typename A, typename B) // (requires Concept1<A> CPP_and Concept2<B>) // void foo(A a, B b) // {} #if CPP_CXX_CONCEPTS #if defined(CPP_DOXYGEN_INVOKED) #define CPP_template(...) template<__VA_ARGS__> CPP_TEMPLATE_EXPAND_ #define CPP_TEMPLATE_EXPAND_(X,Y) X Y #else #define CPP_template(...) template<__VA_ARGS__ CPP_TEMPLATE_AUX_ #endif #define CPP_template_def CPP_template #define CPP_member #define CPP_ctor(TYPE) TYPE CPP_CTOR_IMPL_1_ #if defined(__GNUC__) && !defined(__clang__) && __GNUC__ < 10 #define CPP_auto_member template<typename...> #else #define CPP_auto_member #endif /// INTERNAL ONLY #define CPP_CTOR_IMPL_1_(...) (__VA_ARGS__) CPP_PP_EXPAND /// INTERNAL ONLY #define CPP_TEMPLATE_AUX_(...) \ > CPP_PP_CAT( \ CPP_TEMPLATE_AUX_, \ CPP_TEMPLATE_AUX_WHICH_(__VA_ARGS__,))(__VA_ARGS__) /// INTERNAL ONLY #define CPP_TEMPLATE_AUX_WHICH_(FIRST, ...) \ CPP_PP_EVAL( \ CPP_PP_CHECK, \ CPP_PP_CAT(CPP_TEMPLATE_PROBE_CONCEPT_, FIRST)) /// INTERNAL ONLY #define CPP_TEMPLATE_PROBE_CONCEPT_concept \ CPP_PP_PROBE(~) // A template with a requires clause /// INTERNAL ONLY #define CPP_TEMPLATE_AUX_0(...) __VA_ARGS__ // A concept definition /// INTERNAL ONLY #define CPP_TEMPLATE_AUX_1(DECL, ...) \ CPP_concept CPP_CONCEPT_NAME_(DECL) = __VA_ARGS__ #if defined(CPP_DOXYGEN_INVOKED) #define CPP_concept_ref(NAME, ...) \ NAME<__VA_ARGS__> #else #define CPP_concept_ref(NAME, ...) \ CPP_PP_CAT(NAME, concept_)<__VA_ARGS__> #endif #else // ^^^^ with concepts / without concepts vvvv #define CPP_template CPP_template_sfinae #define CPP_template_def CPP_template_def_sfinae #define CPP_member CPP_member_sfinae #define CPP_auto_member CPP_member_sfinae #define CPP_ctor CPP_ctor_sfinae #define CPP_concept_ref(NAME, ...) \ (1u == sizeof(CPP_PP_CAT(NAME, concept_)( \ (::concepts::detail::tag<__VA_ARGS__>*)nullptr))) /// INTERNAL ONLY #define CPP_TEMPLATE_AUX_ CPP_TEMPLATE_SFINAE_AUX_ #endif #define CPP_template_sfinae(...) \ CPP_PP_IGNORE_CXX2A_COMPAT_BEGIN \ template<__VA_ARGS__ CPP_TEMPLATE_SFINAE_AUX_ /// INTERNAL ONLY #define CPP_TEMPLATE_SFINAE_PROBE_CONCEPT_concept \ CPP_PP_PROBE(~) /// INTERNAL ONLY #define CPP_TEMPLATE_SFINAE_AUX_WHICH_(FIRST, ...) \ CPP_PP_EVAL( \ CPP_PP_CHECK, \ CPP_PP_CAT(CPP_TEMPLATE_SFINAE_PROBE_CONCEPT_, FIRST)) /// INTERNAL ONLY #define CPP_TEMPLATE_SFINAE_AUX_(...) \ CPP_PP_CAT( \ CPP_TEMPLATE_SFINAE_AUX_, \ CPP_TEMPLATE_SFINAE_AUX_WHICH_(__VA_ARGS__,))(__VA_ARGS__) // A template with a requires clause /// INTERNAL ONLY #define CPP_TEMPLATE_SFINAE_AUX_0(...) , \ bool CPP_true = true, \ std::enable_if_t< \ CPP_PP_CAT(CPP_TEMPLATE_SFINAE_AUX_3_, __VA_ARGS__) && \ CPP_BOOL(CPP_true), \ int> = 0> \ CPP_PP_IGNORE_CXX2A_COMPAT_END // A concept definition /// INTERNAL ONLY #define CPP_TEMPLATE_SFINAE_AUX_1(DECL, ...) , \ bool CPP_true = true, \ std::enable_if_t<__VA_ARGS__ && CPP_BOOL(CPP_true), int> = 0> \ auto CPP_CONCEPT_NAME_(DECL)( \ ::concepts::detail::tag<CPP_CONCEPT_PARAMS_(DECL)>*) \ -> char(&)[1]; \ auto CPP_CONCEPT_NAME_(DECL)(...) -> char(&)[2] \ CPP_PP_IGNORE_CXX2A_COMPAT_END /// INTERNAL ONLY #define CPP_CONCEPT_NAME_(DECL) \ CPP_PP_EVAL( \ CPP_PP_CAT, \ CPP_PP_EVAL(CPP_PP_FIRST, CPP_EAT_CONCEPT_(DECL)), concept_) /// INTERNAL ONLY #define CPP_CONCEPT_PARAMS_(DECL) \ CPP_PP_EVAL(CPP_PP_SECOND, CPP_EAT_CONCEPT_(DECL)) /// INTERNAL ONLY #define CPP_EAT_CONCEPT_(DECL) \ CPP_PP_CAT(CPP_EAT_CONCEPT_, DECL) /// INTERNAL ONLY #define CPP_EAT_CONCEPT_concept /// INTERNAL ONLY #define CPP_and_sfinae \ && CPP_BOOL(CPP_true), int> = 0, std::enable_if_t< /// INTERNAL ONLY #define CPP_template_def_sfinae(...) \ template<__VA_ARGS__ CPP_TEMPLATE_DEF_SFINAE_AUX_ /// INTERNAL ONLY #define CPP_TEMPLATE_DEF_SFINAE_AUX_(...) , \ bool CPP_true, \ std::enable_if_t< \ CPP_PP_CAT(CPP_TEMPLATE_SFINAE_AUX_3_, __VA_ARGS__) && \ CPP_BOOL(CPP_true), \ int>> /// INTERNAL ONLY #define CPP_and_sfinae_def \ && CPP_BOOL(CPP_true), int>, std::enable_if_t< /// INTERNAL ONLY #define CPP_TEMPLATE_SFINAE_AUX_3_requires /// INTERNAL ONLY #define CPP_member_sfinae \ CPP_broken_friend_member /// INTERNAL ONLY #define CPP_ctor_sfinae(TYPE) \ CPP_PP_IGNORE_CXX2A_COMPAT_BEGIN \ TYPE CPP_CTOR_SFINAE_IMPL_1_ /// INTERNAL ONLY #define CPP_CTOR_SFINAE_IMPL_1_(...) \ (__VA_ARGS__ \ CPP_PP_COMMA_IIF( \ CPP_PP_NOT(CPP_PP_IS_NOT_EMPTY(__VA_ARGS__))) \ CPP_CTOR_SFINAE_REQUIRES /// INTERNAL ONLY #define CPP_CTOR_SFINAE_PROBE_NOEXCEPT_noexcept \ CPP_PP_PROBE(~) /// INTERNAL ONLY #define CPP_CTOR_SFINAE_MAKE_PROBE(FIRST,...) \ CPP_PP_CAT(CPP_CTOR_SFINAE_PROBE_NOEXCEPT_, FIRST) /// INTERNAL ONLY #define CPP_CTOR_SFINAE_REQUIRES(...) \ CPP_PP_CAT( \ CPP_CTOR_SFINAE_REQUIRES_, \ CPP_PP_EVAL( \ CPP_PP_CHECK, \ CPP_CTOR_SFINAE_MAKE_PROBE(__VA_ARGS__,)))(__VA_ARGS__) // No noexcept-clause: /// INTERNAL ONLY #define CPP_CTOR_SFINAE_REQUIRES_0(...) \ std::enable_if_t< \ CPP_PP_CAT(CPP_TEMPLATE_SFINAE_AUX_3_, __VA_ARGS__) && CPP_TRUE_FN, \ ::concepts::detail::KnightsWhoSayNil \ > = {}) \ CPP_PP_IGNORE_CXX2A_COMPAT_END // Yes noexcept-clause: /// INTERNAL ONLY #define CPP_CTOR_SFINAE_REQUIRES_1(...) \ std::enable_if_t< \ CPP_PP_EVAL(CPP_PP_CAT, \ CPP_TEMPLATE_SFINAE_AUX_3_, \ CPP_PP_CAT(CPP_CTOR_SFINAE_EAT_NOEXCEPT_, __VA_ARGS__)) && CPP_TRUE_FN,\ ::concepts::detail::KnightsWhoSayNil \ > = {}) \ CPP_PP_EXPAND(CPP_PP_CAT(CPP_CTOR_SFINAE_SHOW_NOEXCEPT_, __VA_ARGS__))) /// INTERNAL ONLY #define CPP_CTOR_SFINAE_EAT_NOEXCEPT_noexcept(...) /// INTERNAL ONLY #define CPP_CTOR_SFINAE_SHOW_NOEXCEPT_noexcept(...) \ noexcept(__VA_ARGS__) \ CPP_PP_IGNORE_CXX2A_COMPAT_END \ CPP_PP_EAT CPP_PP_LPAREN #ifdef CPP_DOXYGEN_INVOKED /// INTERNAL ONLY #define CPP_broken_friend_ret(...) \ __VA_ARGS__ CPP_PP_EXPAND #else // ^^^ CPP_DOXYGEN_INVOKED / not CPP_DOXYGEN_INVOKED vvv #define CPP_broken_friend_ret(...) \ ::concepts::return_t< \ __VA_ARGS__, \ std::enable_if_t<CPP_BROKEN_FRIEND_RETURN_TYPE_AUX_ /// INTERNAL ONLY #define CPP_BROKEN_FRIEND_RETURN_TYPE_AUX_(...) \ CPP_BROKEN_FRIEND_RETURN_TYPE_AUX_3_(CPP_PP_CAT( \ CPP_TEMPLATE_AUX_2_, __VA_ARGS__)) /// INTERNAL ONLY #define CPP_TEMPLATE_AUX_2_requires /// INTERNAL ONLY #define CPP_BROKEN_FRIEND_RETURN_TYPE_AUX_3_(...) \ (__VA_ARGS__ && CPP_TRUE_FN)>> #ifdef CPP_WORKAROUND_MSVC_779763 /// INTERNAL ONLY #define CPP_broken_friend_member \ template<::concepts::detail::CPP_true_t const &CPP_true_fn = \ ::concepts::detail::CPP_true_fn_> #else // ^^^ workaround / no workaround vvv /// INTERNAL ONLY #define CPP_broken_friend_member \ template<bool (&CPP_true_fn)(::concepts::detail::xNil) = \ ::concepts::detail::CPP_true_fn> #endif // CPP_WORKAROUND_MSVC_779763 #endif #if CPP_CXX_CONCEPTS #if defined(CPP_DOXYGEN_INVOKED) #define CPP_requires(NAME, REQS) \ concept NAME = \ CPP_PP_CAT(CPP_REQUIRES_, REQS) #define CPP_requires_ref(NAME, ...) \ NAME<__VA_ARGS__> #else #define CPP_requires(NAME, REQS) \ CPP_concept CPP_PP_CAT(NAME, requires_) = \ CPP_PP_CAT(CPP_REQUIRES_, REQS) #define CPP_requires_ref(NAME, ...) \ CPP_PP_CAT(NAME, requires_)<__VA_ARGS__> #endif /// INTERNAL ONLY #define CPP_REQUIRES_requires(...) \ requires(__VA_ARGS__) CPP_REQUIRES_AUX_ /// INTERNAL ONLY #define CPP_REQUIRES_AUX_(...) \ { __VA_ARGS__; } #else #define CPP_requires(NAME, REQS) \ auto CPP_PP_CAT(NAME, requires_test_) \ CPP_REQUIRES_AUX_(NAME, CPP_REQUIRES_ ## REQS) #define CPP_requires_ref(NAME, ...) \ (1u == sizeof(CPP_PP_CAT(NAME, requires_)( \ (::concepts::detail::tag<__VA_ARGS__>*)nullptr))) /// INTERNAL ONLY #define CPP_REQUIRES_requires(...) \ (__VA_ARGS__) -> decltype CPP_REQUIRES_RETURN_ /// INTERNAL ONLY #define CPP_REQUIRES_RETURN_(...) (__VA_ARGS__, void()) {} /// INTERNAL ONLY #define CPP_REQUIRES_AUX_(NAME, ...) \ __VA_ARGS__ \ template<typename... As> \ auto CPP_PP_CAT(NAME, requires_)( \ ::concepts::detail::tag<As...> *, \ decltype(&CPP_PP_CAT(NAME, requires_test_)<As...>) = nullptr) \ -> char(&)[1]; \ auto CPP_PP_CAT(NAME, requires_)(...) -> char(&)[2] #endif #if CPP_CXX_CONCEPTS #define CPP_ret(...) \ __VA_ARGS__ CPP_PP_EXPAND #else #define CPP_ret \ CPP_broken_friend_ret #endif //////////////////////////////////////////////////////////////////////////////// // CPP_fun #if CPP_CXX_CONCEPTS /// INTERNAL ONLY #define CPP_FUN_IMPL_1_(...) \ (__VA_ARGS__) \ CPP_PP_EXPAND #define CPP_fun(X) X CPP_FUN_IMPL_1_ #else /// INTERNAL ONLY #define CPP_FUN_IMPL_1_(...) \ (__VA_ARGS__ \ CPP_PP_COMMA_IIF( \ CPP_PP_NOT(CPP_PP_IS_NOT_EMPTY(__VA_ARGS__))) \ CPP_FUN_IMPL_REQUIRES /// INTERNAL ONLY #define CPP_FUN_IMPL_REQUIRES(...) \ CPP_PP_EVAL2_( \ CPP_FUN_IMPL_SELECT_CONST_, \ (__VA_ARGS__,) \ )(__VA_ARGS__) /// INTERNAL ONLY #define CPP_FUN_IMPL_SELECT_CONST_(MAYBE_CONST, ...) \ CPP_PP_CAT(CPP_FUN_IMPL_SELECT_CONST_, \ CPP_PP_EVAL(CPP_PP_CHECK, CPP_PP_CAT( \ CPP_PP_PROBE_CONST_PROBE_, MAYBE_CONST))) /// INTERNAL ONLY #define CPP_PP_PROBE_CONST_PROBE_const CPP_PP_PROBE(~) /// INTERNAL ONLY #define CPP_FUN_IMPL_SELECT_CONST_1(...) \ CPP_PP_EVAL( \ CPP_FUN_IMPL_SELECT_CONST_NOEXCEPT_, \ CPP_PP_CAT(CPP_FUN_IMPL_EAT_CONST_, __VA_ARGS__),)( \ CPP_PP_CAT(CPP_FUN_IMPL_EAT_CONST_, __VA_ARGS__)) /// INTERNAL ONLY #define CPP_FUN_IMPL_SELECT_CONST_NOEXCEPT_(MAYBE_NOEXCEPT, ...) \ CPP_PP_CAT(CPP_FUN_IMPL_SELECT_CONST_NOEXCEPT_, \ CPP_PP_EVAL2(CPP_PP_CHECK, CPP_PP_CAT( \ CPP_PP_PROBE_NOEXCEPT_PROBE_, MAYBE_NOEXCEPT))) /// INTERNAL ONLY #define CPP_PP_PROBE_NOEXCEPT_PROBE_noexcept CPP_PP_PROBE(~) /// INTERNAL ONLY #define CPP_FUN_IMPL_SELECT_CONST_NOEXCEPT_0(...) \ std::enable_if_t< \ CPP_PP_EVAL( \ CPP_PP_CAT, \ CPP_FUN_IMPL_EAT_REQUIRES_, \ __VA_ARGS__) && CPP_TRUE_FN, \ ::concepts::detail::KnightsWhoSayNil \ > = {}) const \ CPP_PP_IGNORE_CXX2A_COMPAT_END /// INTERNAL ONLY #define CPP_FUN_IMPL_SELECT_CONST_NOEXCEPT_1(...) \ std::enable_if_t< \ CPP_PP_EVAL( \ CPP_PP_CAT, \ CPP_FUN_IMPL_EAT_REQUIRES_, \ CPP_PP_CAT(CPP_FUN_IMPL_EAT_NOEXCEPT_, __VA_ARGS__)) && CPP_TRUE_FN,\ ::concepts::detail::KnightsWhoSayNil \ > = {}) const \ CPP_PP_EXPAND(CPP_PP_CAT(CPP_FUN_IMPL_SHOW_NOEXCEPT_, __VA_ARGS__))) /// INTERNAL ONLY #define CPP_FUN_IMPL_EAT_NOEXCEPT_noexcept(...) /// INTERNAL ONLY #define CPP_FUN_IMPL_SHOW_NOEXCEPT_noexcept(...) \ noexcept(__VA_ARGS__) CPP_PP_IGNORE_CXX2A_COMPAT_END \ CPP_PP_EAT CPP_PP_LPAREN /// INTERNAL ONLY #define CPP_FUN_IMPL_SELECT_CONST_0(...) \ CPP_PP_EVAL_( \ CPP_FUN_IMPL_SELECT_NONCONST_NOEXCEPT_, \ (__VA_ARGS__,) \ )(__VA_ARGS__) /// INTERNAL ONLY #define CPP_FUN_IMPL_SELECT_NONCONST_NOEXCEPT_(MAYBE_NOEXCEPT, ...) \ CPP_PP_CAT(CPP_FUN_IMPL_SELECT_NONCONST_NOEXCEPT_, \ CPP_PP_EVAL2(CPP_PP_CHECK, CPP_PP_CAT( \ CPP_PP_PROBE_NOEXCEPT_PROBE_, MAYBE_NOEXCEPT))) /// INTERNAL ONLY #define CPP_FUN_IMPL_SELECT_NONCONST_NOEXCEPT_0(...) \ std::enable_if_t< \ CPP_PP_CAT(CPP_FUN_IMPL_EAT_REQUIRES_, __VA_ARGS__) && CPP_TRUE_FN, \ ::concepts::detail::KnightsWhoSayNil \ > = {}) \ CPP_PP_IGNORE_CXX2A_COMPAT_END /// INTERNAL ONLY #define CPP_FUN_IMPL_SELECT_NONCONST_NOEXCEPT_1(...) \ std::enable_if_t< \ CPP_PP_EVAL( \ CPP_PP_CAT, \ CPP_FUN_IMPL_EAT_REQUIRES_, \ CPP_PP_CAT(CPP_FUN_IMPL_EAT_NOEXCEPT_, __VA_ARGS__) \ ) && CPP_TRUE_FN, \ ::concepts::detail::KnightsWhoSayNil \ > = {}) \ CPP_PP_EXPAND(CPP_PP_CAT(CPP_FUN_IMPL_SHOW_NOEXCEPT_, __VA_ARGS__))) /// INTERNAL ONLY #define CPP_FUN_IMPL_EAT_CONST_const /// INTERNAL ONLY #define CPP_FUN_IMPL_EAT_REQUIRES_requires //////////////////////////////////////////////////////////////////////////////// // CPP_fun // Usage: // template <typename A, typename B> // void CPP_fun(foo)(A a, B b)([const]opt [noexcept(true)]opt // requires Concept1<A> && Concept2<B>) // {} // // Note: This macro cannot be used when the last function argument is a // parameter pack. #define CPP_fun(X) CPP_PP_IGNORE_CXX2A_COMPAT_BEGIN X CPP_FUN_IMPL_1_ #endif //////////////////////////////////////////////////////////////////////////////// // CPP_auto_fun // Usage: // template <typename A, typename B> // auto CPP_auto_fun(foo)(A a, B b)([const]opt [noexcept(cond)]opt)opt // ( // return a + b // ) #define CPP_auto_fun(X) X CPP_AUTO_FUN_IMPL_ /// INTERNAL ONLY #define CPP_AUTO_FUN_IMPL_(...) (__VA_ARGS__) CPP_AUTO_FUN_RETURNS_ /// INTERNAL ONLY #define CPP_AUTO_FUN_RETURNS_(...) \ CPP_PP_EVAL2_( \ CPP_AUTO_FUN_SELECT_RETURNS_, \ (__VA_ARGS__,) \ )(__VA_ARGS__) /// INTERNAL ONLY #define CPP_AUTO_FUN_SELECT_RETURNS_(MAYBE_CONST, ...) \ CPP_PP_CAT(CPP_AUTO_FUN_RETURNS_CONST_, \ CPP_PP_EVAL(CPP_PP_CHECK, CPP_PP_CAT( \ CPP_PP_PROBE_CONST_MUTABLE_PROBE_, MAYBE_CONST))) /// INTERNAL ONLY #define CPP_PP_PROBE_CONST_MUTABLE_PROBE_const CPP_PP_PROBE_N(~, 1) /// INTERNAL ONLY #define CPP_PP_PROBE_CONST_MUTABLE_PROBE_mutable CPP_PP_PROBE_N(~, 2) /// INTERNAL ONLY #define CPP_PP_EAT_MUTABLE_mutable /// INTERNAL ONLY #define CPP_AUTO_FUN_RETURNS_CONST_2(...) \ CPP_PP_CAT(CPP_PP_EAT_MUTABLE_, __VA_ARGS__) CPP_AUTO_FUN_RETURNS_CONST_0 /// INTERNAL ONLY #define CPP_AUTO_FUN_RETURNS_CONST_1(...) \ __VA_ARGS__ CPP_AUTO_FUN_RETURNS_CONST_0 /// INTERNAL ONLY #define CPP_AUTO_FUN_RETURNS_CONST_0(...) \ CPP_PP_EVAL(CPP_AUTO_FUN_DECLTYPE_NOEXCEPT_, \ CPP_PP_CAT(CPP_AUTO_FUN_RETURNS_, __VA_ARGS__)) /// INTERNAL ONLY #define CPP_AUTO_FUN_RETURNS_return #ifdef __cpp_guaranteed_copy_elision /// INTERNAL ONLY #define CPP_AUTO_FUN_DECLTYPE_NOEXCEPT_(...) \ noexcept(noexcept(__VA_ARGS__)) -> decltype(__VA_ARGS__) \ { return (__VA_ARGS__); } #else /// INTERNAL ONLY #define CPP_AUTO_FUN_DECLTYPE_NOEXCEPT_(...) \ noexcept(noexcept(decltype(__VA_ARGS__)(__VA_ARGS__))) -> \ decltype(__VA_ARGS__) \ { return (__VA_ARGS__); } #endif #if defined(CPP_DOXYGEN_INVOKED) #define concept(NAME) concept NAME CPP_CONCEPT_EQUALS_ #define CPP_CONCEPT_EQUALS_(...) = #endif namespace concepts { template<bool B> using bool_ = std::integral_constant<bool, B>; #if defined(__cpp_fold_expressions) && __cpp_fold_expressions >= 201603 template<bool...Bs> CPP_INLINE_VAR constexpr bool and_v = (Bs &&...); template<bool...Bs> CPP_INLINE_VAR constexpr bool or_v = (Bs ||...); #else namespace detail { template<bool...> struct bools; } // namespace detail template<bool...Bs> CPP_INLINE_VAR constexpr bool and_v = META_IS_SAME(detail::bools<Bs..., true>, detail::bools<true, Bs...>); template<bool...Bs> CPP_INLINE_VAR constexpr bool or_v = !META_IS_SAME(detail::bools<Bs..., false>, detail::bools<false, Bs...>); #endif template<typename> struct return_t_ { template<typename T> using invoke = T; }; template<typename T, typename EnableIf> using return_t = meta::invoke<return_t_<EnableIf>, T>; /// \cond namespace detail { struct ignore { template<class... Args> constexpr ignore(Args&&...) noexcept {} }; template<class> constexpr bool true_() { return true; } template<typename...> struct tag; template<typename T> CPP_INLINE_VAR constexpr T instance_ = T{}; template<typename> constexpr bool requires_() { return true; } struct KnightsWhoSayNil {}; #ifdef CPP_WORKAROUND_MSVC_779763 enum class xNil {}; struct CPP_true_t { constexpr bool operator()(KnightsWhoSayNil) const noexcept { return true; } constexpr bool operator()(xNil) const noexcept { return true; } }; CPP_INLINE_VAR constexpr CPP_true_t CPP_true_fn_ {}; constexpr bool CPP_true_fn(xNil) { return true; } #else using xNil = KnightsWhoSayNil; #endif constexpr bool CPP_true_fn(KnightsWhoSayNil) { return true; } } // namespace detail /// \endcond #if defined(__clang__) || defined(_MSC_VER) || defined(__NVCOMPILER) template<bool B> std::enable_if_t<B> requires_() {} #else template<bool B> CPP_INLINE_VAR constexpr std::enable_if_t<B, int> requires_ = 0; #endif inline namespace defs { //////////////////////////////////////////////////////////////////////// // Utility concepts //////////////////////////////////////////////////////////////////////// /// \concept is_true /// \brief The \c is_true concept template<bool B> CPP_concept is_true = B; /// \concept type /// \brief The \c type concept template<typename... Args> CPP_concept type = true; /// \concept satisfies /// \brief The \c satisfies concept template<class T, template<typename...> class Trait, typename... Args> CPP_concept satisfies = static_cast<bool>(Trait<T, Args...>::type::value); //////////////////////////////////////////////////////////////////////// // Core language concepts //////////////////////////////////////////////////////////////////////// /// \concept same_as /// \brief The \c same_as concept template<typename A, typename B> CPP_concept same_as = META_IS_SAME(A, B) && META_IS_SAME(B, A); /// \cond /// \concept not_same_as_ /// \brief The \c not_same_as_ concept template<typename A, typename B> CPP_concept not_same_as_ = (!same_as<remove_cvref_t<A>, remove_cvref_t<B>>); /// \endcond // Workaround bug in the Standard Library: // From cannot be an incomplete class type despite that // is_convertible<X, Y> should be equivalent to is_convertible<X&&, Y> // in such a case. /// \concept implicitly_convertible_to /// \brief The \c implicitly_convertible_to concept template<typename From, typename To> CPP_concept implicitly_convertible_to = std::is_convertible<std::add_rvalue_reference_t<From>, To>::value; /// \concept explicitly_convertible_to_ /// \brief The \c explicitly_convertible_to_ concept template<typename From, typename To> CPP_requires(explicitly_convertible_to_, requires(From(*from)()) // ( static_cast<To>(from()) )); /// \concept explicitly_convertible_to /// \brief The \c explicitly_convertible_to concept template<typename From, typename To> CPP_concept explicitly_convertible_to = CPP_requires_ref(concepts::explicitly_convertible_to_, From, To); /// \concept convertible_to /// \brief The \c convertible_to concept template<typename From, typename To> CPP_concept convertible_to = implicitly_convertible_to<From, To> && explicitly_convertible_to<From, To>; /// \concept derived_from_ /// \brief The \c derived_from_ concept CPP_template(typename T, typename U)( concept (derived_from_)(T, U), convertible_to<T const volatile *, U const volatile *> ); /// \concept derived_from /// \brief The \c derived_from concept template<typename T, typename U> CPP_concept derived_from = META_IS_BASE_OF(U, T) && CPP_concept_ref(concepts::derived_from_, T, U); /// \concept common_reference_with_ /// \brief The \c common_reference_with_ concept CPP_template(typename T, typename U)( concept (common_reference_with_)(T, U), same_as<common_reference_t<T, U>, common_reference_t<U, T>> CPP_and convertible_to<T, common_reference_t<T, U>> CPP_and convertible_to<U, common_reference_t<T, U>> ); /// \concept common_reference_with /// \brief The \c common_reference_with concept template<typename T, typename U> CPP_concept common_reference_with = CPP_concept_ref(concepts::common_reference_with_, T, U); /// \concept common_with_ /// \brief The \c common_with_ concept CPP_template(typename T, typename U)( concept (common_with_)(T, U), same_as<common_type_t<T, U>, common_type_t<U, T>> CPP_and convertible_to<T, common_type_t<T, U>> CPP_and convertible_to<U, common_type_t<T, U>> CPP_and common_reference_with< std::add_lvalue_reference_t<T const>, std::add_lvalue_reference_t<U const>> CPP_and common_reference_with< std::add_lvalue_reference_t<common_type_t<T, U>>, common_reference_t< std::add_lvalue_reference_t<T const>, std::add_lvalue_reference_t<U const>>> ); /// \concept common_with /// \brief The \c common_with concept template<typename T, typename U> CPP_concept common_with = CPP_concept_ref(concepts::common_with_, T, U); /// \concept integral /// \brief The \c integral concept template<typename T> CPP_concept integral = std::is_integral<T>::value; /// \concept signed_integral /// \brief The \c signed_integral concept template<typename T> CPP_concept signed_integral = integral<T> && std::is_signed<T>::value; /// \concept unsigned_integral /// \brief The \c unsigned_integral concept template<typename T> CPP_concept unsigned_integral = integral<T> && !signed_integral<T>; /// \concept assignable_from_ /// \brief The \c assignable_from_ concept template<typename T, typename U> CPP_requires(assignable_from_, requires(T t, U && u) // ( t = (U &&) u, requires_<same_as<T, decltype(t = (U &&) u)>> )); /// \concept assignable_from /// \brief The \c assignable_from concept template<typename T, typename U> CPP_concept assignable_from = std::is_lvalue_reference<T>::value && common_reference_with<detail::as_cref_t<T>, detail::as_cref_t<U>> && CPP_requires_ref(defs::assignable_from_, T, U); /// \concept swappable_ /// \brief The \c swappable_ concept template<typename T> CPP_requires(swappable_, requires(T & t, T & u) // ( concepts::swap(t, u) )); /// \concept swappable /// \brief The \c swappable concept template<typename T> CPP_concept swappable = CPP_requires_ref(defs::swappable_, T); /// \concept swappable_with_ /// \brief The \c swappable_with_ concept template<typename T, typename U> CPP_requires(swappable_with_, requires(T && t, U && u) // ( concepts::swap((T &&) t, (T &&) t), concepts::swap((U &&) u, (U &&) u), concepts::swap((U &&) u, (T &&) t), concepts::swap((T &&) t, (U &&) u) )); /// \concept swappable_with /// \brief The \c swappable_with concept template<typename T, typename U> CPP_concept swappable_with = common_reference_with<detail::as_cref_t<T>, detail::as_cref_t<U>> && CPP_requires_ref(defs::swappable_with_, T, U); } // inline namespace defs namespace detail { /// \concept boolean_testable_impl_ /// \brief The \c boolean_testable_impl_ concept template<typename T> CPP_concept boolean_testable_impl_ = convertible_to<T, bool>; /// \concept boolean_testable_frag_ /// \brief The \c boolean_testable_frag_ concept template<typename T> CPP_requires(boolean_testable_frag_, requires(T && t) // ( !(T&&) t, concepts::requires_<boolean_testable_impl_<decltype(!(T&&) t)>> )); /// \concept boolean_testable_ /// \brief The \c boolean_testable_ concept template<typename T> CPP_concept boolean_testable_ = CPP_requires_ref(boolean_testable_frag_, T) && boolean_testable_impl_<T>; CPP_DIAGNOSTIC_PUSH CPP_DIAGNOSTIC_IGNORE_FLOAT_EQUAL /// \concept weakly_equality_comparable_with_frag_ /// \brief The \c weakly_equality_comparable_with_frag_ concept template<typename T, typename U> CPP_requires(weakly_equality_comparable_with_frag_, requires(detail::as_cref_t<T> t, detail::as_cref_t<U> u) // ( concepts::requires_<boolean_testable_<decltype(t == u)>>, concepts::requires_<boolean_testable_<decltype(t != u)>>, concepts::requires_<boolean_testable_<decltype(u == t)>>, concepts::requires_<boolean_testable_<decltype(u != t)>> )); /// \concept weakly_equality_comparable_with_ /// \brief The \c weakly_equality_comparable_with_ concept template<typename T, typename U> CPP_concept weakly_equality_comparable_with_ = CPP_requires_ref(weakly_equality_comparable_with_frag_, T, U); /// \concept partially_ordered_with_frag_ /// \brief The \c partially_ordered_with_frag_ concept template<typename T, typename U> CPP_requires(partially_ordered_with_frag_, requires(detail::as_cref_t<T>& t, detail::as_cref_t<U>& u) // ( concepts::requires_<boolean_testable_<decltype(t < u)>>, concepts::requires_<boolean_testable_<decltype(t > u)>>, concepts::requires_<boolean_testable_<decltype(t <= u)>>, concepts::requires_<boolean_testable_<decltype(t >= u)>>, concepts::requires_<boolean_testable_<decltype(u < t)>>, concepts::requires_<boolean_testable_<decltype(u > t)>>, concepts::requires_<boolean_testable_<decltype(u <= t)>>, concepts::requires_<boolean_testable_<decltype(u >= t)>> )); /// \concept partially_ordered_with_ /// \brief The \c partially_ordered_with_ concept template<typename T, typename U> CPP_concept partially_ordered_with_ = CPP_requires_ref(partially_ordered_with_frag_, T, U); CPP_DIAGNOSTIC_POP } // namespace detail inline namespace defs { //////////////////////////////////////////////////////////////////////// // Comparison concepts //////////////////////////////////////////////////////////////////////// /// \concept equality_comparable /// \brief The \c equality_comparable concept template<typename T> CPP_concept equality_comparable = detail::weakly_equality_comparable_with_<T, T>; /// \concept equality_comparable_with_ /// \brief The \c equality_comparable_with_ concept CPP_template(typename T, typename U)( concept (equality_comparable_with_)(T, U), equality_comparable< common_reference_t<detail::as_cref_t<T>, detail::as_cref_t<U>>> ); /// \concept equality_comparable_with /// \brief The \c equality_comparable_with concept template<typename T, typename U> CPP_concept equality_comparable_with = equality_comparable<T> && equality_comparable<U> && detail::weakly_equality_comparable_with_<T, U> && common_reference_with<detail::as_cref_t<T>, detail::as_cref_t<U>> && CPP_concept_ref(concepts::equality_comparable_with_, T, U); /// \concept totally_ordered /// \brief The \c totally_ordered concept template<typename T> CPP_concept totally_ordered = equality_comparable<T> && detail::partially_ordered_with_<T, T>; /// \concept totally_ordered_with_ /// \brief The \c totally_ordered_with_ concept CPP_template(typename T, typename U)( concept (totally_ordered_with_)(T, U), totally_ordered< common_reference_t< detail::as_cref_t<T>, detail::as_cref_t<U>>> CPP_and detail::partially_ordered_with_<T, U>); /// \concept totally_ordered_with /// \brief The \c totally_ordered_with concept template<typename T, typename U> CPP_concept totally_ordered_with = totally_ordered<T> && totally_ordered<U> && equality_comparable_with<T, U> && CPP_concept_ref(concepts::totally_ordered_with_, T, U); //////////////////////////////////////////////////////////////////////// // Object concepts //////////////////////////////////////////////////////////////////////// /// \concept destructible /// \brief The \c destructible concept template<typename T> CPP_concept destructible = std::is_nothrow_destructible<T>::value; /// \concept constructible_from /// \brief The \c constructible_from concept template<typename T, typename... Args> CPP_concept constructible_from = destructible<T> && META_IS_CONSTRUCTIBLE(T, Args...); /// \concept default_constructible /// \brief The \c default_constructible concept template<typename T> CPP_concept default_constructible = constructible_from<T>; /// \concept move_constructible /// \brief The \c move_constructible concept template<typename T> CPP_concept move_constructible = constructible_from<T, T> && convertible_to<T, T>; /// \concept copy_constructible_ /// \brief The \c copy_constructible_ concept CPP_template(typename T)( concept (copy_constructible_)(T), constructible_from<T, T &> && constructible_from<T, T const &> && constructible_from<T, T const> && convertible_to<T &, T> && convertible_to<T const &, T> && convertible_to<T const, T>); /// \concept copy_constructible /// \brief The \c copy_constructible concept template<typename T> CPP_concept copy_constructible = move_constructible<T> && CPP_concept_ref(concepts::copy_constructible_, T); /// \concept move_assignable_ /// \brief The \c move_assignable_ concept CPP_template(typename T)( concept (move_assignable_)(T), assignable_from<T &, T> ); /// \concept movable /// \brief The \c movable concept template<typename T> CPP_concept movable = std::is_object<T>::value && move_constructible<T> && CPP_concept_ref(concepts::move_assignable_, T) && swappable<T>; /// \concept copy_assignable_ /// \brief The \c copy_assignable_ concept CPP_template(typename T)( concept (copy_assignable_)(T), assignable_from<T &, T const &> ); /// \concept copyable /// \brief The \c copyable concept template<typename T> CPP_concept copyable = copy_constructible<T> && movable<T> && CPP_concept_ref(concepts::copy_assignable_, T); /// \concept semiregular /// \brief The \c semiregular concept template<typename T> CPP_concept semiregular = copyable<T> && default_constructible<T>; // Axiom: copies are independent. See Fundamentals of Generic // Programming http://www.stepanovpapers.com/DeSt98.pdf /// \concept regular /// \brief The \c regular concept template<typename T> CPP_concept regular = semiregular<T> && equality_comparable<T>; } // inline namespace defs } // namespace concepts #endif // RANGES_V3_UTILITY_CONCEPTS_HPP
0
repos/range-v3/include
repos/range-v3/include/concepts/compare.hpp
/// \file // CPP, the Concepts PreProcessor library // // Copyright Eric Niebler 2018-present // Copyright (c) 2020-present, Google LLC. // // Use, modification and distribution is subject to the // Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) // // This source code is licensed under the MIT license found in the // LICENSE file in the root directory of this source tree. // // Project home: https://github.com/ericniebler/range-v3 // #ifndef CPP_COMPARE_HPP #define CPP_COMPARE_HPP #if __cplusplus > 201703L && __has_include(<compare>) && \ defined(__cpp_concepts) && defined(__cpp_impl_three_way_comparison) #include <compare> #include <concepts/concepts.hpp> #include <range/v3/compare.hpp> // clang-format off namespace concepts { // Note: concepts in this file can use C++20 concepts, since operator<=> isn't available in // compilers that don't support core concepts. namespace detail { template<typename T, typename Cat> concept compares_as = same_as<ranges::common_comparison_category_t<T, Cat>, Cat>; } // namespace detail inline namespace defs { template<typename T, typename Cat = std::partial_ordering> concept three_way_comparable = detail::weakly_equality_comparable_with_<T, T> && detail::partially_ordered_with_<T ,T> && requires(detail::as_cref_t<T>& a, detail::as_cref_t<T>& b) { { a <=> b } -> detail::compares_as<Cat>; }; template<typename T, typename U, typename Cat = std::partial_ordering> concept three_way_comparable_with = three_way_comparable<T, Cat> && three_way_comparable<U, Cat> && common_reference_with<detail::as_cref_t<T>&, detail::as_cref_t<U>&> && three_way_comparable<common_reference_t<detail::as_cref_t<T>&, detail::as_cref_t<U>&>> && detail::partially_ordered_with_<T, U> && requires(detail::as_cref_t<T>& t, detail::as_cref_t<U>& u) { { t <=> u } -> detail::compares_as<Cat>; { u <=> t } -> detail::compares_as<Cat>; }; } // inline namespace defs } // namespace concepts // clang-format on #endif // __cplusplus #endif // CPP_COMPARE_HPP
0
repos/range-v3/include
repos/range-v3/include/concepts/swap.hpp
/// \file // Concepts library // // Copyright Eric Niebler 2013-present // // Use, modification and distribution is subject to the // Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) // // Project home: https://github.com/ericniebler/range-v3 #ifndef CPP_SWAP_HPP #define CPP_SWAP_HPP #include <tuple> #include <utility> #include <type_traits> #include <meta/meta.hpp> // Note: constexpr implies inline, to retain the same visibility // C++14 constexpr functions are inline in C++11 #if (defined(__cpp_constexpr) && __cpp_constexpr >= 201304L) ||\ (!defined(__cpp_constexpr) && __cplusplus >= 201402L) #define CPP_CXX14_CONSTEXPR constexpr #else #define CPP_CXX14_CONSTEXPR inline #endif #ifndef CPP_CXX_INLINE_VARIABLES #ifdef __cpp_inline_variables // TODO: fix this if SD-6 picks another name #define CPP_CXX_INLINE_VARIABLES __cpp_inline_variables // TODO: remove once clang defines __cpp_inline_variables (or equivalent) #elif defined(__clang__) && \ (__clang_major__ > 3 || __clang_major__ == 3 && __clang_minor__ == 9) && \ __cplusplus > 201402L #define CPP_CXX_INLINE_VARIABLES 201606L #else #define CPP_CXX_INLINE_VARIABLES __cplusplus #endif // __cpp_inline_variables #endif // CPP_CXX_INLINE_VARIABLES #if defined(_MSC_VER) && !defined(__clang__) #if _MSC_VER < 1926 #define CPP_WORKAROUND_MSVC_895622 // Error when phase 1 name binding finds only deleted function #endif // _MSC_VER < 1926 #endif // MSVC #if CPP_CXX_INLINE_VARIABLES < 201606L #define CPP_INLINE_VAR #define CPP_INLINE_VARIABLE(type, name) \ inline namespace \ { \ constexpr auto &name = ::concepts::detail::static_const<type>::value; \ } \ /**/ #else // CPP_CXX_INLINE_VARIABLES >= 201606L #define CPP_INLINE_VAR inline #define CPP_INLINE_VARIABLE(type, name) \ inline constexpr type name{}; \ /**/ #endif // CPP_CXX_INLINE_VARIABLES #if CPP_CXX_INLINE_VARIABLES < 201606L #define CPP_DEFINE_CPO(type, name) \ inline namespace \ { \ constexpr auto &name = ::concepts::detail::static_const<type>::value; \ } \ /**/ #else // CPP_CXX_INLINE_VARIABLES >= 201606L #define CPP_DEFINE_CPO(type, name) \ inline namespace _ \ { \ inline constexpr type name{}; \ } \ /**/ #endif // CPP_CXX_INLINE_VARIABLES #if defined(_MSC_VER) && !defined(__clang__) #define CPP_DIAGNOSTIC_PUSH __pragma(warning(push)) #define CPP_DIAGNOSTIC_POP __pragma(warning(pop)) #define CPP_DIAGNOSTIC_IGNORE_INIT_LIST_LIFETIME #define CPP_DIAGNOSTIC_IGNORE_FLOAT_EQUAL #define CPP_DIAGNOSTIC_IGNORE_CPP2A_COMPAT #else // ^^^ defined(_MSC_VER) ^^^ / vvv !defined(_MSC_VER) vvv #if defined(__GNUC__) || defined(__clang__) #define CPP_PRAGMA(X) _Pragma(#X) #define CPP_DIAGNOSTIC_PUSH CPP_PRAGMA(GCC diagnostic push) #define CPP_DIAGNOSTIC_POP CPP_PRAGMA(GCC diagnostic pop) #define CPP_DIAGNOSTIC_IGNORE_PRAGMAS \ CPP_PRAGMA(GCC diagnostic ignored "-Wpragmas") #define CPP_DIAGNOSTIC_IGNORE(X) \ CPP_DIAGNOSTIC_IGNORE_PRAGMAS \ CPP_PRAGMA(GCC diagnostic ignored "-Wunknown-pragmas") \ CPP_PRAGMA(GCC diagnostic ignored X) #define CPP_DIAGNOSTIC_IGNORE_INIT_LIST_LIFETIME \ CPP_DIAGNOSTIC_IGNORE("-Wunknown-warning-option") \ CPP_DIAGNOSTIC_IGNORE("-Winit-list-lifetime") #define CPP_DIAGNOSTIC_IGNORE_FLOAT_EQUAL CPP_DIAGNOSTIC_IGNORE("-Wfloat-equal") #define CPP_DIAGNOSTIC_IGNORE_CPP2A_COMPAT CPP_DIAGNOSTIC_IGNORE("-Wc++2a-compat") #else #define CPP_DIAGNOSTIC_PUSH #define CPP_DIAGNOSTIC_POP #define CPP_DIAGNOSTIC_IGNORE_INIT_LIST_LIFETIME #define CPP_DIAGNOSTIC_IGNORE_FLOAT_EQUAL #define CPP_DIAGNOSTIC_IGNORE_CPP2A_COMPAT #endif #endif // MSVC/Generic configuration switch namespace concepts { /// \cond namespace detail { template<typename T> CPP_INLINE_VAR constexpr bool is_movable_v = std::is_object<T>::value && std::is_move_constructible<T>::value && std::is_move_assignable<T>::value; template<typename T> struct static_const { static constexpr T const value {}; }; template<typename T> constexpr T const static_const<T>::value; } /// \endcond template<typename T> struct is_swappable; template<typename T> struct is_nothrow_swappable; template<typename T, typename U> struct is_swappable_with; template<typename T, typename U> struct is_nothrow_swappable_with; template<typename T, typename U = T> CPP_CXX14_CONSTEXPR meta::if_c< std::is_move_constructible<T>::value && std::is_assignable<T &, U>::value, T> exchange(T &t, U &&u) noexcept( std::is_nothrow_move_constructible<T>::value && std::is_nothrow_assignable<T &, U>::value) { T tmp((T &&) t); t = (U &&) u; CPP_DIAGNOSTIC_IGNORE_INIT_LIST_LIFETIME return tmp; } /// \cond namespace adl_swap_detail { struct nope {}; // Intentionally create an ambiguity with std::swap, which is // (possibly) unconstrained. template<typename T> nope swap(T &, T &) = delete; template<typename T, std::size_t N> nope swap(T (&)[N], T (&)[N]) = delete; #ifdef CPP_WORKAROUND_MSVC_895622 nope swap(); #endif template<typename T, typename U> decltype(swap(std::declval<T>(), std::declval<U>())) try_adl_swap_(int); template<typename T, typename U> nope try_adl_swap_(long); template<typename T, typename U = T> CPP_INLINE_VAR constexpr bool is_adl_swappable_v = !META_IS_SAME(decltype(adl_swap_detail::try_adl_swap_<T, U>(42)), nope); struct swap_fn { // Dispatch to user-defined swap found via ADL: template<typename T, typename U> CPP_CXX14_CONSTEXPR meta::if_c<is_adl_swappable_v<T, U>> operator()(T &&t, U &&u) const noexcept(noexcept(swap((T &&) t, (U &&) u))) { swap((T &&) t, (U &&) u); } // For intrinsically swappable (i.e., movable) types for which // a swap overload cannot be found via ADL, swap by moving. template<typename T> CPP_CXX14_CONSTEXPR meta::if_c< !is_adl_swappable_v<T &> && detail::is_movable_v<T>> operator()(T &a, T &b) const noexcept(noexcept(b = concepts::exchange(a, (T &&) b))) { b = concepts::exchange(a, (T &&) b); } // For arrays of intrinsically swappable (i.e., movable) types // for which a swap overload cannot be found via ADL, swap array // elements by moving. template<typename T, typename U, std::size_t N> CPP_CXX14_CONSTEXPR meta::if_c< !is_adl_swappable_v<T (&)[N], U (&)[N]> && is_swappable_with<T &, U &>::value> operator()(T (&t)[N], U (&u)[N]) const noexcept(is_nothrow_swappable_with<T &, U &>::value) { for(std::size_t i = 0; i < N; ++i) (*this)(t[i], u[i]); } // For rvalue pairs and tuples of swappable types, swap the // members. This permits code like: // ranges::swap(std::tie(a,b,c), std::tie(d,e,f)); template<typename F0, typename S0, typename F1, typename S1> CPP_CXX14_CONSTEXPR meta::if_c<is_swappable_with<F0, F1>::value && is_swappable_with<S0, S1>::value> operator()(std::pair<F0, S0> &&left, std::pair<F1, S1> &&right) const noexcept( is_nothrow_swappable_with<F0, F1>::value && is_nothrow_swappable_with<S0, S1>::value) { swap_fn()(static_cast<std::pair<F0, S0> &&>(left).first, static_cast<std::pair<F1, S1> &&>(right).first); swap_fn()(static_cast<std::pair<F0, S0> &&>(left).second, static_cast<std::pair<F1, S1> &&>(right).second); } template<typename ...Ts, typename ...Us> CPP_CXX14_CONSTEXPR meta::if_c<meta::and_c<is_swappable_with<Ts, Us>::value...>::value> operator()(std::tuple<Ts...> &&left, std::tuple<Us...> &&right) const noexcept(meta::and_c<is_nothrow_swappable_with<Ts, Us>::value...>::value) { swap_fn::impl( static_cast<std::tuple<Ts...> &&>(left), static_cast<std::tuple<Us...> &&>(right), meta::make_index_sequence<sizeof...(Ts)>{}); } private: template<typename... Ts> static constexpr int ignore_unused(Ts &&...) { return 0; } template<typename T, typename U, std::size_t ...Is> CPP_CXX14_CONSTEXPR static void impl(T &&left, U &&right, meta::index_sequence<Is...>) { (void) swap_fn::ignore_unused( (swap_fn()(std::get<Is>(static_cast<T &&>(left)), std::get<Is>(static_cast<U &&>(right))), 42)...); } }; template<typename T, typename U, typename = void> struct is_swappable_with_ : std::false_type {}; template<typename T, typename U> struct is_swappable_with_<T, U, meta::void_< decltype(swap_fn()(std::declval<T>(), std::declval<U>())), decltype(swap_fn()(std::declval<U>(), std::declval<T>()))>> : std::true_type {}; template<typename T, typename U> struct is_nothrow_swappable_with_ : meta::bool_<noexcept(swap_fn()(std::declval<T>(), std::declval<U>())) && noexcept(swap_fn()(std::declval<U>(), std::declval<T>()))> {}; // Q: Should std::reference_wrapper be considered a proxy wrt swapping rvalues? // A: No. Its operator= is currently defined to reseat the references, so // std::swap(ra, rb) already means something when ra and rb are (lvalue) // reference_wrappers. That reseats the reference wrappers but leaves the // referents unmodified. Treating rvalue reference_wrappers differently would // be confusing. // Q: Then why is it OK to "re"-define swap for pairs and tuples of references? // A: Because as defined above, swapping an rvalue tuple of references has the same // semantics as swapping an lvalue tuple of references. Rather than reseat the // references, assignment happens *through* the references. // Q: But I have an iterator whose operator* returns an rvalue // std::reference_wrapper<T>. How do I make it model indirectly_swappable? // A: With an overload of iter_swap. } /// \endcond /// \ingroup group-utility template<typename T, typename U> struct is_swappable_with : adl_swap_detail::is_swappable_with_<T, U> {}; /// \ingroup group-utility template<typename T, typename U> struct is_nothrow_swappable_with : meta::and_< is_swappable_with<T, U>, adl_swap_detail::is_nothrow_swappable_with_<T, U>> {}; /// \ingroup group-utility template<typename T> struct is_swappable : is_swappable_with<T &, T &> {}; /// \ingroup group-utility template<typename T> struct is_nothrow_swappable : is_nothrow_swappable_with<T &, T &> {}; /// \ingroup group-utility /// \relates adl_swap_detail::swap_fn CPP_DEFINE_CPO(adl_swap_detail::swap_fn, swap) } #endif
0
repos/range-v3/include/range
repos/range-v3/include/range/v3/span.hpp
// Range v3 library // // Copyright Casey Carter 2016-2017 // // Use, modification and distribution is subject to the // Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) // // Project home: https://github.com/ericniebler/range-v3 // #ifndef RANGES_V3_SPAN_HPP #define RANGES_V3_SPAN_HPP #include <range/v3/detail/config.hpp> RANGES_DEPRECATED_HEADER( "This header is deprecated. Please #include <range/v3/view/span.hpp> instead.") #include <range/v3/view/span.hpp> #endif // RANGES_V3_SPAN_HPP
0
repos/range-v3/include/range
repos/range-v3/include/range/v3/iterator_range.hpp
/// \file // Range v3 library // // Copyright Eric Niebler 2013-present // // Use, modification and distribution is subject to the // Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) // // Project home: https://github.com/ericniebler/range-v3 // #ifndef RANGES_V3_ITERATOR_RANGE_HPP #define RANGES_V3_ITERATOR_RANGE_HPP #include <type_traits> #include <utility> #include <meta/meta.hpp> #include <concepts/concepts.hpp> #include <range/v3/range_fwd.hpp> #include <range/v3/iterator/concepts.hpp> #include <range/v3/iterator/operations.hpp> #include <range/v3/iterator/unreachable_sentinel.hpp> #include <range/v3/utility/static_const.hpp> #include <range/v3/view/interface.hpp> RANGES_DEPRECATED_HEADER( "This header is deprecated. Please switch to subrange in " "<range/v3/view/subrange.hpp>.") #include <range/v3/detail/prologue.hpp> namespace ranges { /// \addtogroup group-views /// @{ template<typename I, typename S> RANGES_INLINE_VAR constexpr bool enable_borrowed_range<iterator_range<I, S>> = true; template<typename I, typename S> RANGES_INLINE_VAR constexpr bool enable_borrowed_range<sized_iterator_range<I, S>> = true; template<typename I, typename S /*= I*/> struct RANGES_EMPTY_BASES iterator_range : view_interface<iterator_range<I, S>, same_as<S, unreachable_sentinel_t> ? infinite : unknown> , compressed_pair<I, S> { private: template<typename, typename> friend struct iterator_range; template<typename, typename> friend struct sized_iterator_range; compressed_pair<I, S> & base() noexcept { return *this; } compressed_pair<I, S> const & base() const noexcept { return *this; } using compressed_pair<I, S>::first; using compressed_pair<I, S>::second; public: using iterator = I; using sentinel = S; /// \cond using const_iterator = I; // Mostly to avoid spurious errors in Boost.Range /// \endcond constexpr I & begin() & { return this->first(); } constexpr I const & begin() const & { return this->first(); } constexpr S & end() & { return this->second(); } constexpr S const & end() const & { return this->second(); } iterator_range() = default; constexpr iterator_range(I first, S last) : compressed_pair<I, S>{detail::move(first), detail::move(last)} {} template(typename X, typename Y)( requires constructible_from<I, X> AND constructible_from<S, Y>) constexpr iterator_range(iterator_range<X, Y> rng) : compressed_pair<I, S>{detail::move(rng.begin()), detail::move(rng.end())} {} template(typename X, typename Y)( requires constructible_from<I, X> AND constructible_from<S, Y>) constexpr explicit iterator_range(std::pair<X, Y> rng) : compressed_pair<I, S>{detail::move(rng.first), detail::move(rng.second)} {} template(typename X, typename Y)( requires assignable_from<I &, X> AND assignable_from<S &, Y>) iterator_range & operator=(iterator_range<X, Y> rng) { base().first() = std::move(rng.base()).first(); base().second() = std::move(rng.base()).second(); return *this; } template(typename X, typename Y)( requires convertible_to<I, X> AND convertible_to<S, Y>) constexpr operator std::pair<X, Y>() const { return {base().first(), base().second()}; } constexpr bool empty() const { return base().first() == base().second(); } }; // Like iterator_range, but with a known size. The first and second members // are private to prevent inadvertent violations of the class invariant. // // Class invariant: // distance(begin(), end()) == size() // template<typename I, typename S /* = I */> struct sized_iterator_range : view_interface<sized_iterator_range<I, S>, finite> { using size_type = detail::iter_size_t<I>; using iterator = I; using sentinel = S; #ifndef RANGES_DOXYGEN_INVOKED using const_iterator = I; // Mostly to avoid spurious errors in Boost.Range #endif private: template<typename X, typename Y> friend struct sized_iterator_range; iterator_range<I, S> rng_; size_type size_; public: sized_iterator_range() = default; RANGES_NDEBUG_CONSTEXPR sized_iterator_range(I first, S last, size_type size) : rng_{detail::move(first), detail::move(last)} , size_(size) { #ifndef NDEBUG RANGES_ASSERT(!(bool)forward_iterator<I> || static_cast<size_type>(ranges::distance(rng_)) == size_); #endif } template(typename X, typename Y)( requires constructible_from<I, X> AND constructible_from<S, Y>) RANGES_NDEBUG_CONSTEXPR sized_iterator_range(std::pair<X, Y> rng, size_type size) : sized_iterator_range{detail::move(rng).first, detail::move(rng).second, size} {} template(typename X, typename Y)( requires constructible_from<I, X> AND constructible_from<S, Y>) RANGES_NDEBUG_CONSTEXPR sized_iterator_range(iterator_range<X, Y> rng, size_type size) : sized_iterator_range{detail::move(rng).first(), detail::move(rng).second, size} {} template(typename X, typename Y)( requires constructible_from<I, X> AND constructible_from<S, Y>) RANGES_NDEBUG_CONSTEXPR sized_iterator_range(sized_iterator_range<X, Y> rng) : sized_iterator_range{detail::move(rng).rng_.first(), detail::move(rng).rng_.second, rng.size_} {} template(typename X, typename Y)( requires assignable_from<I &, X> AND assignable_from<S &, Y>) sized_iterator_range & operator=(sized_iterator_range<X, Y> rng) { rng_ = detail::move(rng).rng_; size_ = rng.size_; return *this; } I begin() const { return rng_.begin(); } S end() const { return rng_.end(); } size_type size() const noexcept { return size_; } template(typename X, typename Y)( requires convertible_to<I, X> AND convertible_to<S, Y>) constexpr operator std::pair<X, Y>() const { return rng_; } template(typename X, typename Y)( requires convertible_to<I, X> AND convertible_to<S, Y>) constexpr operator iterator_range<X, Y>() const { return rng_; } constexpr operator iterator_range<I, S> const &() const & noexcept { return rng_; } // clang-format off /// Tuple-like access for `sized_iterator_range` template(std::size_t N)( requires (N < 2)) // friend constexpr auto CPP_auto_fun(get)(sized_iterator_range const &p) ( // return ranges::get<N>(p.rng_) return ranges::get<N>(p.*&sized_iterator_range::rng_) // makes clang happy ) // clang-format on /// \overload template(std::size_t N)( requires (N == 2)) // friend constexpr size_type get(sized_iterator_range const & p) noexcept { return p.size(); } }; struct make_iterator_range_fn { /// \return `{first, last}` template(typename I, typename S)( requires sentinel_for<S, I>) constexpr iterator_range<I, S> operator()(I first, S last) const { return {detail::move(first), detail::move(last)}; } /// \return `{first, last, size}` template(typename I, typename S)( requires sentinel_for<S, I>) constexpr sized_iterator_range<I, S> // operator()(I first, S last, detail::iter_size_t<I> sz) const { return {detail::move(first), detail::move(last), sz}; } }; /// \sa `make_iterator_range_fn` RANGES_INLINE_VARIABLE(make_iterator_range_fn, make_iterator_range) // TODO add specialization of range_cardinality for when we can determine the range is // infinite /// @} } // namespace ranges // The standard is inconsistent about whether these are classes or structs RANGES_DIAGNOSTIC_PUSH RANGES_DIAGNOSTIC_IGNORE_MISMATCHED_TAGS /// \cond namespace std { template<typename I, typename S> struct tuple_size<::ranges::iterator_range<I, S>> : std::integral_constant<size_t, 2> {}; template<typename I, typename S> struct tuple_element<0, ::ranges::iterator_range<I, S>> { using type = I; }; template<typename I, typename S> struct tuple_element<1, ::ranges::iterator_range<I, S>> { using type = S; }; template<typename I, typename S> struct tuple_size<::ranges::sized_iterator_range<I, S>> : std::integral_constant<size_t, 3> {}; template<typename I, typename S> struct tuple_element<0, ::ranges::sized_iterator_range<I, S>> { using type = I; }; template<typename I, typename S> struct tuple_element<1, ::ranges::sized_iterator_range<I, S>> { using type = S; }; template<typename I, typename S> struct tuple_element<2, ::ranges::sized_iterator_range<I, S>> { using type = typename ::ranges::sized_iterator_range<I, S>::size_type; }; } // namespace std /// \endcond RANGES_DIAGNOSTIC_POP #include <range/v3/detail/epilogue.hpp> #endif
0
repos/range-v3/include/range
repos/range-v3/include/range/v3/at.hpp
// Range v3 library // // Copyright Eric Niebler 2014-present // Copyright Gonzalo Brito Gadeschi 2017 // // Use, modification and distribution is subject to the // Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) // // Project home: https://github.com/ericniebler/range-v3 // #ifndef RANGES_V3_AT_HPP #define RANGES_V3_AT_HPP #include <range/v3/detail/config.hpp> RANGES_DEPRECATED_HEADER( "This header is deprecated. Please #include <range/v3/range/operations.hpp> instead.") #include <range/v3/range/operations.hpp> #endif
0
repos/range-v3/include/range
repos/range-v3/include/range/v3/distance.hpp
// Range v3 library // // Copyright Eric Niebler 2014-present // Copyright Michel Morin 2014 // // Use, modification and distribution is subject to the // Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) // // Project home: https://github.com/ericniebler/range-v3 // #ifndef RANGES_V3_DISTANCE_HPP #define RANGES_V3_DISTANCE_HPP #include <range/v3/detail/config.hpp> RANGES_DEPRECATED_HEADER( "This header is deprecated. Please #include <range/v3/iterator/operations.hpp> " "instead.") #include <range/v3/iterator/operations.hpp> #endif
0
repos/range-v3/include/range
repos/range-v3/include/range/v3/range_concepts.hpp
// Range v3 library // // Copyright Eric Niebler 2013-present // // Use, modification and distribution is subject to the // Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) // // Project home: https://github.com/ericniebler/range-v3 // #ifndef RANGES_V3_DEPRECATED_RANGE_CONCEPTS_HPP #define RANGES_V3_DEPRECATED_RANGE_CONCEPTS_HPP #include <range/v3/detail/config.hpp> RANGES_DEPRECATED_HEADER( "This header is deprecated. Please #include <range/v3/range/concepts.hpp> instead.") #include <range/v3/range/concepts.hpp> #endif
0
repos/range-v3/include/range
repos/range-v3/include/range/v3/data.hpp
// Range v3 library // // Copyright Casey Carter 2016 // // Use, modification and distribution is subject to the // Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) // // Project home: https://github.com/ericniebler/range-v3 // #ifndef RANGES_V3_DATA_HPP #define RANGES_V3_DATA_HPP #include <range/v3/detail/config.hpp> RANGES_DEPRECATED_HEADER( "This header is deprecated. Please #include <range/v3/range/primitives.hpp> instead.") #include <range/v3/range/primitives.hpp> #endif // RANGES_V3_DATA_HPP
0
repos/range-v3/include/range
repos/range-v3/include/range/v3/view_adaptor.hpp
// Range v3 library // // Copyright Eric Niebler 2014-present // // Use, modification and distribution is subject to the // Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) // // Project home: https://github.com/ericniebler/range-v3 // #ifndef RANGES_V3_OLD_VIEW_ADAPTOR_HPP #define RANGES_V3_OLD_VIEW_ADAPTOR_HPP #include <range/v3/detail/config.hpp> RANGES_DEPRECATED_HEADER( "This header is deprecated. Please #include <range/v3/view/adaptor.hpp> instead.") #include <range/v3/view/adaptor.hpp> #endif
0
repos/range-v3/include/range
repos/range-v3/include/range/v3/view_interface.hpp
// Range v3 library // // Copyright Eric Niebler 2014-present // // Use, modification and distribution is subject to the // Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) // // Project home: https://github.com/ericniebler/range-v3 // #ifndef RANGES_V3_OLD_VIEW_INTERFACE_HPP #define RANGES_V3_OLD_VIEW_INTERFACE_HPP #include <range/v3/detail/config.hpp> RANGES_DEPRECATED_HEADER( "This header is deprecated. Please #include <range/v3/view/interface.hpp> instead.") #include <range/v3/view/interface.hpp> #endif
0
repos/range-v3/include/range
repos/range-v3/include/range/v3/range_for.hpp
/// \file // Range v3 library // // Copyright Eric Niebler 2014-present // // Use, modification and distribution is subject to the // Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) // // Project home: https://github.com/ericniebler/range-v3 // #ifndef RANGES_V3_RANGE_FOR_HPP #define RANGES_V3_RANGE_FOR_HPP #include <range/v3/range_fwd.hpp> #include <range/v3/range/access.hpp> #if RANGES_CXX_RANGE_BASED_FOR < RANGES_CXX_RANGE_BASED_FOR_17 /// A range-based for macro, basically a hack until the built-in range-for can handle /// Ranges that have a different type for begin and end. \ingroup range-core #define RANGES_FOR(VAR_DECL, ...) \ if(bool CPP_PP_CAT(_range_v3_done, __LINE__) = false) {} \ else \ for(auto && CPP_PP_CAT(_range_v3_rng, __LINE__) = (__VA_ARGS__); \ !CPP_PP_CAT(_range_v3_done, __LINE__);) \ for(auto CPP_PP_CAT(_range_v3_begin, __LINE__) = \ ranges::begin(CPP_PP_CAT(_range_v3_rng, __LINE__)); \ !CPP_PP_CAT(_range_v3_done, __LINE__); \ CPP_PP_CAT(_range_v3_done, __LINE__) = true) \ for(auto CPP_PP_CAT(_range_v3_end, __LINE__) = \ ranges::end(CPP_PP_CAT(_range_v3_rng, __LINE__)); \ !CPP_PP_CAT(_range_v3_done, __LINE__) && \ CPP_PP_CAT(_range_v3_begin, __LINE__) != \ CPP_PP_CAT(_range_v3_end, __LINE__); \ ++CPP_PP_CAT(_range_v3_begin, __LINE__)) \ if(!(CPP_PP_CAT(_range_v3_done, __LINE__) = true)) {} \ else \ for(VAR_DECL = *CPP_PP_CAT(_range_v3_begin, __LINE__); \ CPP_PP_CAT(_range_v3_done, __LINE__); \ CPP_PP_CAT(_range_v3_done, __LINE__) = false) \ /**/ #else #define RANGES_FOR(VAR_DECL, ...) for(VAR_DECL : (__VA_ARGS__)) #endif #endif
0
repos/range-v3/include/range
repos/range-v3/include/range/v3/begin_end.hpp
// Range v3 library // // Copyright Eric Niebler 2013-present // // Use, modification and distribution is subject to the // Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) // // Project home: https://github.com/ericniebler/range-v3 // #ifndef RANGES_V3_BEGIN_END_HPP #define RANGES_V3_BEGIN_END_HPP #include <range/v3/detail/config.hpp> RANGES_DEPRECATED_HEADER( "This header is deprecated. Please #include <range/v3/range/access.hpp> instead.") #include <range/v3/range/access.hpp> #endif
0
repos/range-v3/include/range
repos/range-v3/include/range/v3/to_container.hpp
// Range v3 library // // Copyright Eric Niebler 2013-present // // Use, modification and distribution is subject to the // Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) // // Project home: https://github.com/ericniebler/range-v3 // #ifndef RANGES_V3_TO_CONTAINER_HPP #define RANGES_V3_TO_CONTAINER_HPP #include <range/v3/detail/config.hpp> RANGES_DEPRECATED_HEADER( "This header is deprecated. Please #include <range/v3/range/conversion.hpp> instead.") #include <range/v3/range/conversion.hpp> #endif
0
repos/range-v3/include/range
repos/range-v3/include/range/v3/getlines.hpp
// Range v3 library // // Copyright Eric Niebler 2013-present // // Use, modification and distribution is subject to the // Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) // // Project home: https://github.com/ericniebler/range-v3 // #ifndef RANGES_V3_GETLINES_HPP #define RANGES_V3_GETLINES_HPP #include <range/v3/detail/config.hpp> RANGES_DEPRECATED_HEADER( "This header is deprecated. Please #include <range/v3/view/getlines.hpp> instead.") #include <range/v3/view/getlines.hpp> #endif
0
repos/range-v3/include/range
repos/range-v3/include/range/v3/iterator.hpp
/// \file // Range v3 library // // Copyright Eric Niebler 2019-present // // Use, modification and distribution is subject to the // Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) // // Project home: https://github.com/ericniebler/range-v3 // #ifndef RANGES_V3_ITERATOR_HPP #define RANGES_V3_ITERATOR_HPP #include <range/v3/iterator/access.hpp> #include <range/v3/iterator/basic_iterator.hpp> #include <range/v3/iterator/common_iterator.hpp> #include <range/v3/iterator/concepts.hpp> #include <range/v3/iterator/counted_iterator.hpp> #include <range/v3/iterator/default_sentinel.hpp> #include <range/v3/iterator/diffmax_t.hpp> #include <range/v3/iterator/insert_iterators.hpp> #include <range/v3/iterator/move_iterators.hpp> #include <range/v3/iterator/operations.hpp> #include <range/v3/iterator/reverse_iterator.hpp> #include <range/v3/iterator/stream_iterators.hpp> #include <range/v3/iterator/traits.hpp> #include <range/v3/iterator/unreachable_sentinel.hpp> #endif
0
repos/range-v3/include/range
repos/range-v3/include/range/v3/core.hpp
/// \file // Range v3 library // // Copyright Eric Niebler 2013-present // // Use, modification and distribution is subject to the // Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) // // Project home: https://github.com/ericniebler/range-v3 // #ifndef RANGES_V3_CORE_HPP #define RANGES_V3_CORE_HPP #include <range/v3/iterator/common_iterator.hpp> #include <range/v3/iterator/operations.hpp> #include <range/v3/range/access.hpp> #include <range/v3/range/concepts.hpp> #include <range/v3/range/conversion.hpp> #include <range/v3/range/operations.hpp> #include <range/v3/range/primitives.hpp> #include <range/v3/range/traits.hpp> #include <range/v3/range_for.hpp> #include <range/v3/view/adaptor.hpp> #include <range/v3/view/facade.hpp> #include <range/v3/view/getlines.hpp> #include <range/v3/view/interface.hpp> #include <range/v3/view/istream.hpp> #include <range/v3/view/subrange.hpp> #endif
0
repos/range-v3/include/range
repos/range-v3/include/range/v3/all.hpp
/// \file // Range v3 library // // Copyright Eric Niebler 2013,2014. // // Use, modification and distribution is subject to the // Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) // // Project home: https://github.com/ericniebler/range-v3 // #ifndef RANGES_V3_ALL_HPP #define RANGES_V3_ALL_HPP #include <range/v3/action.hpp> #include <range/v3/algorithm.hpp> #include <range/v3/core.hpp> #include <range/v3/functional.hpp> #include <range/v3/iterator.hpp> #include <range/v3/numeric.hpp> #include <range/v3/range.hpp> #include <range/v3/utility.hpp> #include <range/v3/view.hpp> #endif
0
repos/range-v3/include/range
repos/range-v3/include/range/v3/functional.hpp
/// \file // Range v3 library // // Copyright Eric Niebler 2019-present // // Use, modification and distribution is subject to the // Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) // // Project home: https://github.com/ericniebler/range-v3 // #ifndef RANGES_V3_FUNCTIONAL_HPP #define RANGES_V3_FUNCTIONAL_HPP #include <range/v3/functional/arithmetic.hpp> #include <range/v3/functional/bind.hpp> #include <range/v3/functional/bind_back.hpp> #include <range/v3/functional/comparisons.hpp> #include <range/v3/functional/compose.hpp> #include <range/v3/functional/concepts.hpp> #include <range/v3/functional/identity.hpp> #include <range/v3/functional/indirect.hpp> #include <range/v3/functional/invoke.hpp> #include <range/v3/functional/not_fn.hpp> #include <range/v3/functional/on.hpp> #include <range/v3/functional/overload.hpp> #include <range/v3/functional/pipeable.hpp> #include <range/v3/functional/reference_wrapper.hpp> #endif
0
repos/range-v3/include/range
repos/range-v3/include/range/v3/view.hpp
/// \file // Range v3 library // // Copyright Eric Niebler 2013-present // // Use, modification and distribution is subject to the // Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) // // Project home: https://github.com/ericniebler/range-v3 // #ifndef RANGES_V3_VIEW_HPP #define RANGES_V3_VIEW_HPP #include <range/v3/view/adaptor.hpp> #include <range/v3/view/addressof.hpp> #include <range/v3/view/adjacent_filter.hpp> #include <range/v3/view/adjacent_remove_if.hpp> #include <range/v3/view/all.hpp> #include <range/v3/view/any_view.hpp> #include <range/v3/view/c_str.hpp> #include <range/v3/view/cache1.hpp> #include <range/v3/view/cartesian_product.hpp> #include <range/v3/view/chunk.hpp> #include <range/v3/view/chunk_by.hpp> #include <range/v3/view/common.hpp> #include <range/v3/view/concat.hpp> #include <range/v3/view/const.hpp> #include <range/v3/view/counted.hpp> #include <range/v3/view/cycle.hpp> #include <range/v3/view/delimit.hpp> #include <range/v3/view/drop.hpp> #include <range/v3/view/drop_exactly.hpp> #include <range/v3/view/drop_last.hpp> #include <range/v3/view/drop_while.hpp> #include <range/v3/view/empty.hpp> #include <range/v3/view/enumerate.hpp> #include <range/v3/view/exclusive_scan.hpp> #include <range/v3/view/facade.hpp> #include <range/v3/view/filter.hpp> #include <range/v3/view/for_each.hpp> #include <range/v3/view/generate.hpp> #include <range/v3/view/generate_n.hpp> #include <range/v3/view/getlines.hpp> #include <range/v3/view/group_by.hpp> #include <range/v3/view/indices.hpp> #include <range/v3/view/indirect.hpp> #include <range/v3/view/intersperse.hpp> #include <range/v3/view/iota.hpp> #include <range/v3/view/istream.hpp> #include <range/v3/view/join.hpp> #include <range/v3/view/linear_distribute.hpp> #include <range/v3/view/map.hpp> #include <range/v3/view/move.hpp> #include <range/v3/view/partial_sum.hpp> #include <range/v3/view/ref.hpp> #include <range/v3/view/remove.hpp> #include <range/v3/view/remove_if.hpp> #include <range/v3/view/repeat.hpp> #include <range/v3/view/repeat_n.hpp> #include <range/v3/view/replace.hpp> #include <range/v3/view/replace_if.hpp> #include <range/v3/view/reverse.hpp> #include <range/v3/view/sample.hpp> #include <range/v3/view/set_algorithm.hpp> #include <range/v3/view/single.hpp> #include <range/v3/view/slice.hpp> #include <range/v3/view/sliding.hpp> #include <range/v3/view/span.hpp> #include <range/v3/view/split.hpp> #include <range/v3/view/split_when.hpp> #include <range/v3/view/stride.hpp> #include <range/v3/view/subrange.hpp> #include <range/v3/view/tail.hpp> #include <range/v3/view/take.hpp> #include <range/v3/view/take_exactly.hpp> #include <range/v3/view/take_last.hpp> #include <range/v3/view/take_while.hpp> #include <range/v3/view/tokenize.hpp> #include <range/v3/view/transform.hpp> #include <range/v3/view/trim.hpp> #include <range/v3/view/unbounded.hpp> #include <range/v3/view/unique.hpp> #include <range/v3/view/view.hpp> #include <range/v3/view/zip.hpp> #include <range/v3/view/zip_with.hpp> #endif
0
repos/range-v3/include/range
repos/range-v3/include/range/v3/compare.hpp
/// \file // CPP, the Concepts PreProcessor library // // Copyright Eric Niebler 2018-present // Copyright (c) 2020-present, Google LLC. // // Use, modification and distribution is subject to the // Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) // // This source code is licensed under the MIT license found in the // LICENSE file in the root directory of this source tree. // // Project home: https://github.com/ericniebler/range-v3 // #ifndef RANGES_V3_COMPARE_HPP #define RANGES_V3_COMPARE_HPP #if __cplusplus > 201703L && __has_include(<compare>) && \ defined(__cpp_concepts) && defined(__cpp_impl_three_way_comparison) #include <compare> #include <type_traits> namespace ranges { template<typename... Ts> struct common_comparison_category { using type = void; }; template<typename... Ts> requires ((std::is_same_v<Ts, std::partial_ordering> || std::is_same_v<Ts, std::weak_ordering> || std::is_same_v<Ts, std::strong_ordering>) && ...) struct common_comparison_category<Ts...> : std::common_type<Ts...> {}; template<typename... Ts> using common_comparison_category_t = typename common_comparison_category<Ts...>::type; } // namespace ranges #endif // __cplusplus #endif // RANGES_V3_COMPARE_HPP
0
repos/range-v3/include/range
repos/range-v3/include/range/v3/empty.hpp
// Range v3 library // // Copyright Eric Niebler 2014-present // // Use, modification and distribution is subject to the // Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) // // Project home: https://github.com/ericniebler/range-v3 // #ifndef RANGES_V3_EMPTY_HPP #define RANGES_V3_EMPTY_HPP #include <range/v3/detail/config.hpp> RANGES_DEPRECATED_HEADER( "This header is deprecated. Please #include <range/v3/range/primitives.hpp> instead.") #include <range/v3/range/primitives.hpp> #endif
0
repos/range-v3/include/range
repos/range-v3/include/range/v3/version.hpp
/// \file // Range v3 library // // Copyright Eric Niebler 2017-present // // Use, modification and distribution is subject to the // Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) // // Project home: https://github.com/ericniebler/range-v3 // #ifndef RANGES_V3_VERSION_HPP #define RANGES_V3_VERSION_HPP #define RANGE_V3_MAJOR 0 #define RANGE_V3_MINOR 12 #define RANGE_V3_PATCHLEVEL 0 #define RANGE_V3_VERSION \ (RANGE_V3_MAJOR * 10000 + RANGE_V3_MINOR * 100 + RANGE_V3_PATCHLEVEL) #endif
0
repos/range-v3/include/range
repos/range-v3/include/range/v3/numeric.hpp
/////////////////////////////////////////////////////////////////////////////// /// \file numeric.hpp /// Contains range-based versions of the numeric algorithms // // Copyright Eric Niebler 2014-present // // Distributed under the Boost Software License, Version 1.0. (See // accompanying file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) #ifndef RANGES_V3_NUMERIC_HPP #define RANGES_V3_NUMERIC_HPP #include <range/v3/numeric/accumulate.hpp> #include <range/v3/numeric/adjacent_difference.hpp> #include <range/v3/numeric/inner_product.hpp> #include <range/v3/numeric/iota.hpp> #include <range/v3/numeric/partial_sum.hpp> #endif
0
repos/range-v3/include/range
repos/range-v3/include/range/v3/istream_range.hpp
// Range v3 library // // Copyright Eric Niebler 2013-present // // Use, modification and distribution is subject to the // Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) // // Project home: https://github.com/ericniebler/range-v3 // #ifndef RANGES_V3_ISTREAM_RANGE_HPP #define RANGES_V3_ISTREAM_RANGE_HPP #include <range/v3/detail/config.hpp> RANGES_DEPRECATED_HEADER( "This header is deprecated. Please #include <range/v3/view/istream.hpp> instead.") #include <range/v3/view/istream.hpp> #endif
0
repos/range-v3/include/range
repos/range-v3/include/range/v3/algorithm.hpp
/// \file // Range v3 library // // Copyright Eric Niebler 2013-present // // Use, modification and distribution is subject to the // Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) // // Project home: https://github.com/ericniebler/range-v3 // #ifndef RANGES_V3_ALGORITHM_HPP #define RANGES_V3_ALGORITHM_HPP #include <range/v3/algorithm/adjacent_find.hpp> #include <range/v3/algorithm/adjacent_remove_if.hpp> #include <range/v3/algorithm/all_of.hpp> #include <range/v3/algorithm/any_of.hpp> #include <range/v3/algorithm/binary_search.hpp> #include <range/v3/algorithm/contains.hpp> #include <range/v3/algorithm/contains_subrange.hpp> #include <range/v3/algorithm/copy.hpp> #include <range/v3/algorithm/copy_backward.hpp> #include <range/v3/algorithm/copy_if.hpp> #include <range/v3/algorithm/copy_n.hpp> #include <range/v3/algorithm/count.hpp> #include <range/v3/algorithm/count_if.hpp> #include <range/v3/algorithm/ends_with.hpp> #include <range/v3/algorithm/equal.hpp> #include <range/v3/algorithm/equal_range.hpp> #include <range/v3/algorithm/fill.hpp> #include <range/v3/algorithm/fill_n.hpp> #include <range/v3/algorithm/find.hpp> #include <range/v3/algorithm/find_end.hpp> #include <range/v3/algorithm/find_first_of.hpp> #include <range/v3/algorithm/find_if.hpp> #include <range/v3/algorithm/find_if_not.hpp> #include <range/v3/algorithm/fold.hpp> #include <range/v3/algorithm/for_each.hpp> #include <range/v3/algorithm/for_each_n.hpp> #include <range/v3/algorithm/generate.hpp> #include <range/v3/algorithm/generate_n.hpp> #include <range/v3/algorithm/heap_algorithm.hpp> #include <range/v3/algorithm/inplace_merge.hpp> #include <range/v3/algorithm/is_partitioned.hpp> #include <range/v3/algorithm/is_sorted.hpp> #include <range/v3/algorithm/is_sorted_until.hpp> #include <range/v3/algorithm/lexicographical_compare.hpp> #include <range/v3/algorithm/lower_bound.hpp> #include <range/v3/algorithm/max.hpp> #include <range/v3/algorithm/max_element.hpp> #include <range/v3/algorithm/merge.hpp> #include <range/v3/algorithm/min.hpp> #include <range/v3/algorithm/min_element.hpp> #include <range/v3/algorithm/minmax.hpp> #include <range/v3/algorithm/minmax_element.hpp> #include <range/v3/algorithm/mismatch.hpp> #include <range/v3/algorithm/move.hpp> #include <range/v3/algorithm/move_backward.hpp> #include <range/v3/algorithm/none_of.hpp> #include <range/v3/algorithm/nth_element.hpp> #include <range/v3/algorithm/partial_sort.hpp> #include <range/v3/algorithm/partial_sort_copy.hpp> #include <range/v3/algorithm/partition.hpp> #include <range/v3/algorithm/partition_copy.hpp> #include <range/v3/algorithm/partition_point.hpp> #include <range/v3/algorithm/permutation.hpp> #include <range/v3/algorithm/remove.hpp> #include <range/v3/algorithm/remove_copy.hpp> #include <range/v3/algorithm/remove_copy_if.hpp> #include <range/v3/algorithm/remove_if.hpp> #include <range/v3/algorithm/replace.hpp> #include <range/v3/algorithm/replace_copy.hpp> #include <range/v3/algorithm/replace_copy_if.hpp> #include <range/v3/algorithm/replace_if.hpp> #include <range/v3/algorithm/reverse.hpp> #include <range/v3/algorithm/reverse_copy.hpp> #include <range/v3/algorithm/rotate.hpp> #include <range/v3/algorithm/rotate_copy.hpp> #include <range/v3/algorithm/sample.hpp> #include <range/v3/algorithm/search.hpp> #include <range/v3/algorithm/search_n.hpp> #include <range/v3/algorithm/set_algorithm.hpp> #include <range/v3/algorithm/shuffle.hpp> #include <range/v3/algorithm/sort.hpp> #include <range/v3/algorithm/stable_partition.hpp> #include <range/v3/algorithm/stable_sort.hpp> #include <range/v3/algorithm/starts_with.hpp> #include <range/v3/algorithm/swap_ranges.hpp> #include <range/v3/algorithm/transform.hpp> #include <range/v3/algorithm/unique.hpp> #include <range/v3/algorithm/unique_copy.hpp> #include <range/v3/algorithm/unstable_remove_if.hpp> #include <range/v3/algorithm/upper_bound.hpp> #include <range/v3/detail/config.hpp> // BUGBUG #include <range/v3/algorithm/aux_/equal_range_n.hpp> #include <range/v3/algorithm/aux_/lower_bound_n.hpp> #include <range/v3/algorithm/aux_/merge_n.hpp> #include <range/v3/algorithm/aux_/merge_n_with_buffer.hpp> #include <range/v3/algorithm/aux_/sort_n_with_buffer.hpp> #include <range/v3/algorithm/aux_/upper_bound_n.hpp> #endif
0
repos/range-v3/include/range
repos/range-v3/include/range/v3/front.hpp
// Range v3 library // // Copyright Eric Niebler 2014-present // // Use, modification and distribution is subject to the // Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) // // Project home: https://github.com/ericniebler/range-v3 // #ifndef RANGES_V3_FRONT_HPP #define RANGES_V3_FRONT_HPP #include <range/v3/detail/config.hpp> RANGES_DEPRECATED_HEADER( "This header is deprecated. Please #include <range/v3/range/operations.hpp> instead.") #include <range/v3/range/operations.hpp> #endif
0
repos/range-v3/include/range
repos/range-v3/include/range/v3/view_facade.hpp
// Range v3 library // // Copyright Eric Niebler 2014-present // // Use, modification and distribution is subject to the // Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) // // Project home: https://github.com/ericniebler/range-v3 // #ifndef RANGES_V3_OLD_VIEW_FACADE_HPP #define RANGES_V3_OLD_VIEW_FACADE_HPP #include <range/v3/detail/config.hpp> RANGES_DEPRECATED_HEADER( "This header is deprecated. Please #include <range/v3/view/facade.hpp> instead.") #include <range/v3/view/facade.hpp> #endif
0
repos/range-v3/include/range
repos/range-v3/include/range/v3/range_fwd.hpp
/// \file // Range v3 library // // Copyright Eric Niebler 2013-present // // Use, modification and distribution is subject to the // Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) // // Project home: https://github.com/ericniebler/range-v3 // #ifndef RANGES_V3_RANGE_FWD_HPP #define RANGES_V3_RANGE_FWD_HPP #include <type_traits> #include <utility> #include <meta/meta.hpp> #include <concepts/concepts.hpp> #include <concepts/compare.hpp> #include <range/v3/detail/config.hpp> #include <range/v3/utility/static_const.hpp> #include <range/v3/version.hpp> /// \defgroup group-iterator Iterator /// Iterator functionality /// \defgroup group-iterator-concepts Iterator Concepts /// \ingroup group-iterator /// Iterator concepts /// \defgroup group-range Range /// Core range functionality /// \defgroup group-range-concepts Range Concepts /// \ingroup group-range /// Range concepts /// \defgroup group-algorithms Algorithms /// Iterator- and range-based algorithms, like the standard algorithms /// \defgroup group-views Views /// Lazy, non-owning, non-mutating, composable range views /// \defgroup group-actions Actions /// Eager, mutating, composable algorithms /// \defgroup group-utility Utility /// Utility classes /// \defgroup group-functional Functional /// Function and function object utilities /// \defgroup group-numerics Numerics /// Numeric utilities #include <range/v3/detail/prologue.hpp> RANGES_DIAGNOSTIC_PUSH RANGES_DIAGNOSTIC_IGNORE_CXX17_COMPAT namespace ranges { /// \cond namespace views { } namespace actions { } // GCC either fails to accept an attribute on a namespace, or else // it ignores the deprecation attribute. Frustrating. #if(RANGES_CXX_VER < RANGES_CXX_STD_17 || defined(__GNUC__) && !defined(__clang__)) inline namespace v3 { using namespace ranges; } namespace view = views; namespace action = actions; #else inline namespace RANGES_DEPRECATED( "The name ranges::v3 namespace is deprecated. " "Please discontinue using it.") v3 { using namespace ranges; } namespace RANGES_DEPRECATED( "The ranges::view namespace has been renamed to ranges::views. " "(Sorry!)") view { using namespace views; } namespace RANGES_DEPRECATED( "The ranges::action namespace has been renamed to ranges::actions. " "(Sorry!)") action { using namespace actions; } #endif namespace _end_ { struct fn; } using end_fn = _end_::fn; namespace _size_ { struct fn; } template<typename> struct result_of; template<typename Sig> using result_of_t RANGES_DEPRECATED( "ranges::result_of_t is deprecated. " "Please use ranges::invoke_result_t") = meta::_t<result_of<Sig>>; /// \endcond template<typename...> struct variant; struct dangling; struct make_pipeable_fn; struct pipeable_base; template<typename First, typename Second> struct composed; template<typename... Fns> struct overloaded; namespace actions { template<typename ActionFn> struct action_closure; } namespace views { template<typename ViewFn> struct view_closure; } struct advance_fn; struct advance_to_fn; struct advance_bounded_fn; struct next_fn; struct prev_fn; struct distance_fn; struct iter_size_fn; template<typename T> struct indirectly_readable_traits; template<typename T> using readable_traits RANGES_DEPRECATED("Please use ranges::indirectly_readable_traits") = indirectly_readable_traits<T>; template<typename T> struct incrementable_traits; struct view_base {}; /// \cond namespace detail { template<typename T> struct difference_type_; template<typename T> struct value_type_; } // namespace detail template<typename T> using difference_type RANGES_DEPRECATED( "ranges::difference_type<T>::type is deprecated. Use " "ranges::incrementable_traits<T>::difference_type instead.") = detail::difference_type_<T>; template<typename T> using value_type RANGES_DEPRECATED( "ranges::value_type<T>::type is deprecated. Use " "ranges::indirectly_readable_traits<T>::value_type instead.") = detail::value_type_<T>; template<typename T> struct size_type; /// \endcond /// \cond namespace detail { struct ignore_t { ignore_t() = default; template<typename T> constexpr ignore_t(T &&) noexcept {} template<typename T> constexpr ignore_t const & operator=(T &&) const noexcept { return *this; } }; struct value_init { template<typename T> operator T() const { return T{}; } }; struct make_compressed_pair_fn; template<typename T> constexpr meta::_t<std::remove_reference<T>> && move(T && t) noexcept { return static_cast<meta::_t<std::remove_reference<T>> &&>(t); } struct as_const_fn { template<typename T> constexpr T const & operator()(T & t) const noexcept { return t; } template<typename T> constexpr T const && operator()(T && t) const noexcept { return (T &&) t; } }; RANGES_INLINE_VARIABLE(as_const_fn, as_const) template<typename T> using as_const_t = decltype(as_const(std::declval<T>())); template<typename T> using decay_t = meta::_t<std::decay<T>>; template<typename T, typename R = meta::_t<std::remove_reference<T>>> using as_ref_t = meta::_t<std::add_lvalue_reference<meta::_t<std::remove_const<R>>>>; template<typename T, typename R = meta::_t<std::remove_reference<T>>> using as_cref_t = meta::_t<std::add_lvalue_reference<R const>>; struct get_first; struct get_second; template<typename Val1, typename Val2> struct replacer_fn; template<typename Pred, typename Val> struct replacer_if_fn; template<typename I> struct move_into_cursor; template<typename Int> struct from_end_; template<typename... Ts> constexpr int ignore_unused(Ts &&...) { return 42; } template<int I> struct priority_tag : priority_tag<I - 1> {}; template<> struct priority_tag<0> {}; #if defined(__clang__) && !defined(_LIBCPP_VERSION) template<typename T, typename... Args> RANGES_INLINE_VAR constexpr bool is_trivially_constructible_v = __is_trivially_constructible(T, Args...); template<typename T> RANGES_INLINE_VAR constexpr bool is_trivially_default_constructible_v = is_trivially_constructible_v<T>; template<typename T> RANGES_INLINE_VAR constexpr bool is_trivially_copy_constructible_v = is_trivially_constructible_v<T, T const &>; template<typename T> RANGES_INLINE_VAR constexpr bool is_trivially_move_constructible_v = is_trivially_constructible_v<T, T>; template<typename T> RANGES_INLINE_VAR constexpr bool is_trivially_copyable_v = __is_trivially_copyable(T); template<typename T, typename U> RANGES_INLINE_VAR constexpr bool is_trivially_assignable_v = __is_trivially_assignable(T, U); template<typename T> RANGES_INLINE_VAR constexpr bool is_trivially_copy_assignable_v = is_trivially_assignable_v<T &, T const &>; template<typename T> RANGES_INLINE_VAR constexpr bool is_trivially_move_assignable_v = is_trivially_assignable_v<T &, T>; template<typename T, typename... Args> struct is_trivially_constructible : meta::bool_<is_trivially_constructible_v<T, Args...>> {}; template<typename T> struct is_trivially_default_constructible : meta::bool_<is_trivially_default_constructible_v<T>> {}; template<typename T> struct is_trivially_copy_constructible : meta::bool_<is_trivially_copy_constructible_v<T>> {}; template<typename T> struct is_trivially_move_constructible : meta::bool_<is_trivially_move_constructible_v<T>> {}; template<typename T> struct is_trivially_copyable : meta::bool_<is_trivially_copyable_v<T>> {}; template<typename T, typename U> struct is_trivially_assignable : meta::bool_<is_trivially_assignable_v<T, U>> {}; template<typename T> struct is_trivially_copy_assignable : meta::bool_<is_trivially_copy_assignable_v<T>> {}; template<typename T> struct is_trivially_move_assignable : meta::bool_<is_trivially_move_assignable_v<T>> {}; #else using std::is_trivially_constructible; using std::is_trivially_default_constructible; using std::is_trivially_copy_assignable; using std::is_trivially_copy_constructible; using std::is_trivially_copyable; using std::is_trivially_assignable; using std::is_trivially_move_assignable; using std::is_trivially_move_constructible; #if META_CXX_TRAIT_VARIABLE_TEMPLATES using std::is_trivially_constructible_v; using std::is_trivially_default_constructible_v; using std::is_trivially_copy_assignable_v; using std::is_trivially_copy_constructible_v; using std::is_trivially_copyable_v; using std::is_trivially_assignable_v; using std::is_trivially_move_assignable_v; using std::is_trivially_move_constructible_v; #else template<typename T, typename... Args> RANGES_INLINE_VAR constexpr bool is_trivially_constructible_v = is_trivially_constructible<T, Args...>::value; template<typename T> RANGES_INLINE_VAR constexpr bool is_trivially_default_constructible_v = is_trivially_default_constructible<T>::value; template<typename T> RANGES_INLINE_VAR constexpr bool is_trivially_copy_constructible_v = is_trivially_copy_constructible<T>::value; template<typename T> RANGES_INLINE_VAR constexpr bool is_trivially_move_constructible_v = is_trivially_move_constructible<T>::value; template<typename T> RANGES_INLINE_VAR constexpr bool is_trivially_copyable_v = is_trivially_copyable<T>::value; template<typename T, typename U> RANGES_INLINE_VAR constexpr bool is_trivially_assignable_v = is_trivially_assignable<T, U>::value; template<typename T> RANGES_INLINE_VAR constexpr bool is_trivially_copy_assignable_v = is_trivially_copy_assignable<T>::value; template<typename T> RANGES_INLINE_VAR constexpr bool is_trivially_move_assignable_v = is_trivially_move_assignable<T>::value; #endif #endif template<typename T> RANGES_INLINE_VAR constexpr bool is_trivial_v = is_trivially_copyable_v<T> && is_trivially_default_constructible_v<T>; template<typename T> struct is_trivial : meta::bool_<is_trivial_v<T>> {}; #if RANGES_CXX_LIB_IS_FINAL > 0 #if defined(__clang__) && !defined(_LIBCPP_VERSION) template<typename T> RANGES_INLINE_VAR constexpr bool is_final_v = __is_final(T); template<typename T> struct is_final : meta::bool_<is_final_v<T>> {}; #else using std::is_final; #if META_CXX_TRAIT_VARIABLE_TEMPLATES using std::is_final_v; #else template<typename T> RANGES_INLINE_VAR constexpr bool is_final_v = is_final<T>::value; #endif #endif #else template<typename T> RANGES_INLINE_VAR constexpr bool is_final_v = false; template<typename T> using is_final = std::false_type; #endif // Work around libc++'s buggy std::is_function // Function types here: template<typename T> char (&is_function_impl_(priority_tag<0>))[1]; // Array types here: template<typename T, typename = decltype((*(T *)0)[0])> char (&is_function_impl_(priority_tag<1>))[2]; // Anything that can be returned from a function here (including // void and reference types): template<typename T, typename = T (*)()> char (&is_function_impl_(priority_tag<2>))[3]; // Classes and unions (including abstract types) here: template<typename T, typename = int T::*> char (&is_function_impl_(priority_tag<3>))[4]; template<typename T> RANGES_INLINE_VAR constexpr bool is_function_v = sizeof(detail::is_function_impl_<T>(priority_tag<3>{})) == 1; template<typename T> struct remove_rvalue_reference { using type = T; }; template<typename T> struct remove_rvalue_reference<T &&> { using type = T; }; template<typename T> using remove_rvalue_reference_t = meta::_t<remove_rvalue_reference<T>>; // Workaround bug in the Standard Library: // From cannot be an incomplete class type despite that // is_convertible<X, Y> should be equivalent to is_convertible<X&&, Y> // in such a case. template<typename From, typename To> using is_convertible = std::is_convertible<meta::_t<std::add_rvalue_reference<From>>, To>; } // namespace detail /// \endcond struct begin_tag {}; struct end_tag {}; struct copy_tag {}; struct move_tag {}; template<typename T> using uncvref_t = meta::_t<std::remove_cv<meta::_t<std::remove_reference<T>>>>; struct not_equal_to; struct equal_to; struct less; #if __cplusplus > 201703L && __has_include(<compare>) && \ defined(__cpp_concepts) && defined(__cpp_impl_three_way_comparison) struct compare_three_way; #endif // __cplusplus struct identity; template<typename Pred> struct logical_negate; enum cardinality : std::ptrdiff_t { infinite = -3, unknown = -2, finite = -1 }; template<typename Rng, typename Void = void> struct range_cardinality; template<typename Rng> using is_finite = meta::bool_<range_cardinality<Rng>::value >= finite>; template<typename Rng> using is_infinite = meta::bool_<range_cardinality<Rng>::value == infinite>; template<typename S, typename I> RANGES_INLINE_VAR constexpr bool disable_sized_sentinel = false; template<typename R> RANGES_INLINE_VAR constexpr bool enable_borrowed_range = false; namespace detail { template<typename R> RANGES_DEPRECATED("Please use ranges::enable_borrowed_range instead.") RANGES_INLINE_VAR constexpr bool enable_safe_range = enable_borrowed_range<R>; } // namespace detail using detail::enable_safe_range; template<typename Cur> struct basic_mixin; template<typename Cur> struct RANGES_EMPTY_BASES basic_iterator; template<cardinality> struct basic_view : view_base {}; template<typename Derived, cardinality C = finite> struct view_facade; template<typename Derived, typename BaseRng, cardinality C = range_cardinality<BaseRng>::value> struct view_adaptor; template<typename I, typename S> struct common_iterator; /// \cond namespace detail { template<typename I> struct cpp17_iterator_cursor; template<typename I> using cpp17_iterator = basic_iterator<cpp17_iterator_cursor<I>>; } // namespace detail /// \endcond template<typename First, typename Second> struct compressed_pair; template<typename T> struct bind_element; template<typename T> using bind_element_t = meta::_t<bind_element<T>>; template<typename Derived, cardinality = finite> struct view_interface; template<typename T> struct istream_view; template<typename I, typename S = I> struct RANGES_EMPTY_BASES iterator_range; template<typename I, typename S = I> struct sized_iterator_range; template<typename T> struct reference_wrapper; // Views // template<typename Rng, typename Pred> struct RANGES_EMPTY_BASES adjacent_filter_view; namespace views { struct adjacent_filter_fn; } template<typename Rng, typename Pred> struct RANGES_EMPTY_BASES adjacent_remove_if_view; namespace views { struct adjacent_remove_if_fn; } namespace views { struct all_fn; } template<typename Rng, typename Fun> struct chunk_by_view; namespace views { struct chunk_by_fn; } template<typename Rng> struct const_view; namespace views { struct const_fn; } template<typename I> struct counted_view; namespace views { struct counted_fn; } struct default_sentinel_t; template<typename I> struct move_iterator; template<typename I> using move_into_iterator = basic_iterator<detail::move_into_cursor<I>>; template<typename Rng, bool = (bool)is_infinite<Rng>()> struct RANGES_EMPTY_BASES cycled_view; namespace views { struct cycle_fn; } /// \cond namespace detail { template<typename I> struct reverse_cursor; } /// \endcond template<typename I> using reverse_iterator = basic_iterator<detail::reverse_cursor<I>>; template<typename T> struct empty_view; namespace views { struct empty_fn; } template<typename Rng, typename Fun> struct group_by_view; namespace views { struct group_by_fn; } template<typename Rng> struct indirect_view; namespace views { struct indirect_fn; } struct unreachable_sentinel_t; template<typename From, typename To = unreachable_sentinel_t> struct iota_view; template<typename From, typename To = From> struct closed_iota_view; namespace views { struct iota_fn; struct closed_iota_fn; } // namespace views template<typename Rng> struct join_view; template<typename Rng, typename ValRng> struct join_with_view; namespace views { struct join_fn; } template<typename... Rngs> struct concat_view; namespace views { struct concat_fn; } template<typename Rng, typename Fun> struct partial_sum_view; namespace views { struct partial_sum_fn; } template<typename Rng> struct move_view; namespace views { struct move_fn; } template<typename Rng> struct ref_view; namespace views { struct ref_fn; } template<typename Val> struct repeat_view; namespace views { struct repeat_fn; } template<typename Rng> struct RANGES_EMPTY_BASES reverse_view; namespace views { struct reverse_fn; } template<typename Rng> struct slice_view; namespace views { struct slice_fn; } // template<typename Rng, typename Fun> // struct split_view; // namespace views // { // struct split_fn; // } template<typename Rng> struct single_view; namespace views { struct single_fn; } template<typename Rng> struct stride_view; namespace views { struct stride_fn; } template<typename Rng> struct take_view; namespace views { struct take_fn; } /// \cond namespace detail { template<typename Rng> struct is_random_access_common_; template<typename Rng, bool IsRandomAccessCommon = is_random_access_common_<Rng>::value> struct take_exactly_view_; } // namespace detail /// \endcond template<typename Rng> using take_exactly_view = detail::take_exactly_view_<Rng>; namespace views { struct take_exactly_fn; } template<typename Rng, typename Pred> struct iter_take_while_view; template<typename Rng, typename Pred> struct take_while_view; namespace views { struct iter_take_while_fn; struct take_while_fn; } // namespace views template<typename Rng, typename Regex, typename SubMatchRange> struct tokenize_view; namespace views { struct tokenize_fn; } template<typename Rng, typename Fun> struct iter_transform_view; template<typename Rng, typename Fun> struct transform_view; namespace views { struct transform_fn; } template<typename Rng, typename Val1, typename Val2> using replace_view = iter_transform_view<Rng, detail::replacer_fn<Val1, Val2>>; template<typename Rng, typename Pred, typename Val> using replace_if_view = iter_transform_view<Rng, detail::replacer_if_fn<Pred, Val>>; namespace views { struct replace_fn; struct replace_if_fn; } // namespace views template<typename Rng, typename Pred> struct trim_view; namespace views { struct trim_fn; } template<typename I> struct unbounded_view; namespace views { struct unbounded_fn; } template<typename Rng> using unique_view = adjacent_filter_view<Rng, logical_negate<equal_to>>; namespace views { struct unique_fn; } template<typename Rng> using keys_range_view = transform_view<Rng, detail::get_first>; template<typename Rng> using values_view = transform_view<Rng, detail::get_second>; namespace views { struct keys_fn; struct values_fn; } // namespace views template<typename Fun, typename... Rngs> struct iter_zip_with_view; template<typename Fun, typename... Rngs> struct zip_with_view; template<typename... Rngs> struct zip_view; namespace views { struct iter_zip_with_fn; struct zip_with_fn; struct zip_fn; } // namespace views } // namespace ranges /// \cond namespace ranges { namespace concepts = ::concepts; using namespace ::concepts::defs; using ::concepts::and_v; } // namespace ranges /// \endcond RANGES_DIAGNOSTIC_POP #include <range/v3/detail/epilogue.hpp> #endif
0
repos/range-v3/include/range
repos/range-v3/include/range/v3/index.hpp
// Range v3 library // // Copyright Eric Niebler 2014-present // Copyright Gonzalo Brito Gadeschi 2017 // // Use, modification and distribution is subject to the // Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) // // Project home: https://github.com/ericniebler/range-v3 // #ifndef RANGES_V3_INDEX_HPP #define RANGES_V3_INDEX_HPP #include <range/v3/detail/config.hpp> RANGES_DEPRECATED_HEADER( "This header is deprecated. Please #include <range/v3/range/operations.hpp> instead.") #include <range/v3/range/operations.hpp> #endif // RANGES_V3_INDEX_HPP
0
repos/range-v3/include/range
repos/range-v3/include/range/v3/utility.hpp
/// \file // Range v3 library // // Copyright Eric Niebler 2019-present // // Use, modification and distribution is subject to the // Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) // // Project home: https://github.com/ericniebler/range-v3 // #ifndef RANGES_V3_UTILITY_HPP #define RANGES_V3_UTILITY_HPP #include <range/v3/utility/any.hpp> #include <range/v3/utility/box.hpp> #include <range/v3/utility/common_tuple.hpp> #include <range/v3/utility/common_type.hpp> #include <range/v3/utility/compressed_pair.hpp> #include <range/v3/utility/copy.hpp> #include <range/v3/utility/get.hpp> #include <range/v3/utility/in_place.hpp> #include <range/v3/utility/memory.hpp> #include <range/v3/utility/move.hpp> #include <range/v3/utility/optional.hpp> #include <range/v3/utility/polymorphic_cast.hpp> #include <range/v3/utility/random.hpp> #include <range/v3/utility/scope_exit.hpp> #include <range/v3/utility/semiregular_box.hpp> #include <range/v3/utility/static_const.hpp> #include <range/v3/utility/swap.hpp> #include <range/v3/utility/tuple_algorithm.hpp> #include <range/v3/utility/variant.hpp> #endif
0
repos/range-v3/include/range
repos/range-v3/include/range/v3/size.hpp
// Range v3 library // // Copyright Eric Niebler 2014-present // // Use, modification and distribution is subject to the // Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) // // Project home: https://github.com/ericniebler/range-v3 // #ifndef RANGES_V3_SIZE_HPP #define RANGES_V3_SIZE_HPP #include <range/v3/detail/config.hpp> RANGES_DEPRECATED_HEADER( "This header is deprecated. Please #include <range/v3/range/primitives.hpp> instead.") #include <range/v3/range/primitives.hpp> #endif
0
repos/range-v3/include/range
repos/range-v3/include/range/v3/range_traits.hpp
// Range v3 library // // Copyright Eric Niebler 2013-present // // Use, modification and distribution is subject to the // Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) // // Project home: https://github.com/ericniebler/range-v3 // #ifndef RANGES_V3_OLD_RANGE_TRAITS_HPP #define RANGES_V3_OLD_RANGE_TRAITS_HPP #include <range/v3/detail/config.hpp> RANGES_DEPRECATED_HEADER( "This header is deprecated. Please #include <range/v3/range/traits.hpp> instead.") #include <range/v3/range/traits.hpp> #endif
0
repos/range-v3/include/range
repos/range-v3/include/range/v3/action.hpp
/// \file // Range v3 library // // Copyright Eric Niebler 2014-present // // Use, modification and distribution is subject to the // Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) // // Project home: https://github.com/ericniebler/range-v3 // #ifndef RANGES_V3_ACTION_HPP #define RANGES_V3_ACTION_HPP #include <range/v3/action/action.hpp> #include <range/v3/action/adjacent_remove_if.hpp> #include <range/v3/action/concepts.hpp> #include <range/v3/action/drop.hpp> #include <range/v3/action/drop_while.hpp> #include <range/v3/action/erase.hpp> #include <range/v3/action/insert.hpp> #include <range/v3/action/join.hpp> #include <range/v3/action/push_back.hpp> #include <range/v3/action/push_front.hpp> #include <range/v3/action/remove.hpp> #include <range/v3/action/remove_if.hpp> #include <range/v3/action/reverse.hpp> #include <range/v3/action/shuffle.hpp> #include <range/v3/action/slice.hpp> #include <range/v3/action/sort.hpp> #include <range/v3/action/split.hpp> #include <range/v3/action/split_when.hpp> #include <range/v3/action/stable_sort.hpp> #include <range/v3/action/stride.hpp> #include <range/v3/action/take.hpp> #include <range/v3/action/take_while.hpp> #include <range/v3/action/transform.hpp> #include <range/v3/action/unique.hpp> #include <range/v3/action/unstable_remove_if.hpp> #endif
0
repos/range-v3/include/range
repos/range-v3/include/range/v3/range_access.hpp
// Range v3 library // // Copyright Eric Niebler 2014-present // Copyright Casey Carter 2016 // // Use, modification and distribution is subject to the // Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) // // Project home: https://github.com/ericniebler/range-v3 // #ifndef RANGES_V3_OLD_RANGE_ACCESS_HPP #define RANGES_V3_OLD_RANGE_ACCESS_HPP #include <range/v3/detail/config.hpp> RANGES_DEPRECATED_HEADER( "This header is deprecated. Please #include <range/v3/range/operations.hpp> instead.") #include <range/v3/range/operations.hpp> #endif
0
repos/range-v3/include/range
repos/range-v3/include/range/v3/back.hpp
// Range v3 library // // Copyright Eric Niebler 2014-present // // Use, modification and distribution is subject to the // Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) // // Project home: https://github.com/ericniebler/range-v3 // #ifndef RANGES_V3_BACK_HPP #define RANGES_V3_BACK_HPP #include <range/v3/detail/config.hpp> RANGES_DEPRECATED_HEADER( "This header is deprecated. Please #include <range/v3/range/operations.hpp> instead.") #include <range/v3/range/operations.hpp> #endif
0
repos/range-v3/include/range
repos/range-v3/include/range/v3/range.hpp
/// \file // Range v3 library // // Copyright Eric Niebler 2019-present // // Use, modification and distribution is subject to the // Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) // // Project home: https://github.com/ericniebler/range-v3 // #ifndef RANGES_V3_RANGE_HPP #define RANGES_V3_RANGE_HPP #include <range/v3/range/access.hpp> #include <range/v3/range/concepts.hpp> #include <range/v3/range/conversion.hpp> #include <range/v3/range/dangling.hpp> #include <range/v3/range/operations.hpp> #include <range/v3/range/primitives.hpp> #include <range/v3/range/traits.hpp> #endif
0
repos/range-v3/include/range/v3
repos/range-v3/include/range/v3/numeric/partial_sum.hpp
/// \file // Range v3 library // // Copyright Eric Niebler 2013-present // Copyright Gonzalo Brito Gadeschi 2014 // // Use, modification and distribution is subject to the // Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) // // Project home: https://github.com/ericniebler/range-v3 // #ifndef RANGES_V3_NUMERIC_PARTIAL_SUM_HPP #define RANGES_V3_NUMERIC_PARTIAL_SUM_HPP #include <meta/meta.hpp> #include <range/v3/algorithm/result_types.hpp> #include <range/v3/functional/arithmetic.hpp> #include <range/v3/functional/compose.hpp> #include <range/v3/functional/identity.hpp> #include <range/v3/functional/invoke.hpp> #include <range/v3/iterator/concepts.hpp> #include <range/v3/iterator/traits.hpp> #include <range/v3/iterator/unreachable_sentinel.hpp> #include <range/v3/range/access.hpp> #include <range/v3/range/concepts.hpp> #include <range/v3/range/dangling.hpp> #include <range/v3/range/traits.hpp> #include <range/v3/utility/static_const.hpp> #include <range/v3/detail/prologue.hpp> namespace ranges { /// \addtogroup group-numerics /// @{ /// \cond namespace detail { // Only needed for type-checking purposes: struct as_lvalue_fn { template<typename T> constexpr T & operator()(T && t) const noexcept { return t; } }; template<typename I> using as_value_type_t = composed<as_lvalue_fn, coerce<iter_value_t<I>>>; } // namespace detail /// \endcond // axiom: BOp is associative over values of I. // clang-format off /// \concept indirect_semigroup_ /// \brief The \c indirect_semigroup_ concept template(typename I, typename BOp)( concept (indirect_semigroup_)(I, BOp), copyable<iter_value_t<I>> AND indirectly_regular_binary_invocable_< composed<coerce<iter_value_t<I>>, BOp>, iter_value_t<I>*, I> ); /// \concept indirect_semigroup /// \brief The \c indirect_semigroup concept template<typename I, typename BOp> CPP_concept indirect_semigroup = indirectly_readable<I> && CPP_concept_ref(ranges::indirect_semigroup_, I, BOp); /// \concept partial_sum_constraints_ /// \brief The \c partial_sum_constraints_ concept template(typename I, typename O, typename BOp, typename P)( concept (partial_sum_constraints_)(I, O, BOp, P), indirect_semigroup< projected<projected<I, detail::as_value_type_t<I>>, P>, BOp> AND output_iterator< O, iter_value_t< projected<projected<I, detail::as_value_type_t<I>>, P>> const &> ); /// \concept partial_sum_constraints /// \brief The \c partial_sum_constraints concept template<typename I, typename O, typename BOp = plus, typename P = identity> CPP_concept partial_sum_constraints = input_iterator<I> && CPP_concept_ref(ranges::partial_sum_constraints_, I, O, BOp, P); // clang-format on template<typename I, typename O> using partial_sum_result = detail::in_out_result<I, O>; struct partial_sum_fn { template(typename I, typename S1, typename O, typename S2, typename BOp = plus, typename P = identity)( requires sentinel_for<S1, I> AND sentinel_for<S2, O> AND partial_sum_constraints<I, O, BOp, P>) partial_sum_result<I, O> operator()(I first, S1 last, O result, S2 end_result, BOp bop = BOp{}, P proj = P{}) const { using X = projected<projected<I, detail::as_value_type_t<I>>, P>; coerce<iter_value_t<I>> val_i; coerce<iter_value_t<X>> val_x; if(first != last && result != end_result) { auto && cur1 = val_i(*first); iter_value_t<X> t(invoke(proj, cur1)); *result = t; for(++first, ++result; first != last && result != end_result; ++first, ++result) { auto && cur2 = val_i(*first); t = val_x(invoke(bop, t, invoke(proj, cur2))); *result = t; } } return {first, result}; } template(typename I, typename S, typename O, typename BOp = plus, typename P = identity)( requires sentinel_for<S, I> AND partial_sum_constraints<I, O, BOp, P>) partial_sum_result<I, O> // operator()(I first, S last, O result, BOp bop = BOp{}, P proj = P{}) const { return (*this)(std::move(first), std::move(last), std::move(result), unreachable, std::move(bop), std::move(proj)); } template(typename Rng, typename ORef, typename BOp = plus, typename P = identity, typename I = iterator_t<Rng>, typename O = uncvref_t<ORef>)( requires range<Rng> AND partial_sum_constraints<I, O, BOp, P>) partial_sum_result<borrowed_iterator_t<Rng>, O> // operator()(Rng && rng, ORef && result, BOp bop = BOp{}, P proj = P{}) const { return (*this)(begin(rng), end(rng), static_cast<ORef &&>(result), std::move(bop), std::move(proj)); } template(typename Rng, typename ORng, typename BOp = plus, typename P = identity, typename I = iterator_t<Rng>, typename O = iterator_t<ORng>)( requires range<Rng> AND range<ORng> AND partial_sum_constraints<I, O, BOp, P>) partial_sum_result<borrowed_iterator_t<Rng>, borrowed_iterator_t<ORng>> // operator()(Rng && rng, ORng && result, BOp bop = BOp{}, P proj = P{}) const { return (*this)(begin(rng), end(rng), begin(result), end(result), std::move(bop), std::move(proj)); } }; RANGES_INLINE_VARIABLE(partial_sum_fn, partial_sum) /// @} } // namespace ranges #include <range/v3/detail/epilogue.hpp> #endif
0
repos/range-v3/include/range/v3
repos/range-v3/include/range/v3/numeric/adjacent_difference.hpp
/// \file // Range v3 library // // Copyright Eric Niebler 2004 // Copyright Gonzalo Brito Gadeschi 2014 // // Use, modification and distribution is subject to the // Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) // // Project home: https://github.com/ericniebler/range-v3 // // Implementation based on the code in libc++ // http://http://libcxx.llvm.org/ #ifndef RANGES_V3_NUMERIC_ADJACENT_DIFFERENCE_HPP #define RANGES_V3_NUMERIC_ADJACENT_DIFFERENCE_HPP #include <meta/meta.hpp> #include <range/v3/algorithm/result_types.hpp> #include <range/v3/functional/arithmetic.hpp> #include <range/v3/functional/identity.hpp> #include <range/v3/functional/invoke.hpp> #include <range/v3/iterator/concepts.hpp> #include <range/v3/iterator/traits.hpp> #include <range/v3/iterator/unreachable_sentinel.hpp> #include <range/v3/range/access.hpp> #include <range/v3/range/concepts.hpp> #include <range/v3/range/dangling.hpp> #include <range/v3/range/traits.hpp> #include <range/v3/utility/static_const.hpp> #include <range/v3/detail/prologue.hpp> namespace ranges { /// \addtogroup group-numerics /// @{ // clang-format off /// \concept differenceable_ /// \brief The \c differenceable_ concept template(typename I, typename O, typename BOp, typename P)( concept (differenceable_)(I, O, BOp, P), invocable<P&, iter_value_t<I>> AND copy_constructible<uncvref_t<invoke_result_t<P&, iter_value_t<I>>>> AND movable<uncvref_t<invoke_result_t<P&, iter_value_t<I>>>> AND output_iterator<O, invoke_result_t<P&, iter_value_t<I>>> AND invocable< BOp&, invoke_result_t< P&, iter_value_t<I>>, invoke_result_t<P&, iter_value_t<I>>> AND output_iterator< O, invoke_result_t< BOp&, invoke_result_t<P&, iter_value_t<I>>, invoke_result_t<P&, iter_value_t<I>>>>); /// \concept differenceable /// \brief The \c differenceable concept template<typename I, typename O, typename BOp = minus, typename P = identity> CPP_concept differenceable = input_iterator<I> && CPP_concept_ref(ranges::differenceable_, I, O, BOp, P); // clang-format on template<typename I, typename O> using adjacent_difference_result = detail::in_out_result<I, O>; struct adjacent_difference_fn { template(typename I, typename S, typename O, typename S2, typename BOp = minus, typename P = identity)( requires sentinel_for<S, I> AND sentinel_for<S2, O> AND differenceable<I, O, BOp, P>) adjacent_difference_result<I, O> operator()(I first, S last, O result, S2 end_result, BOp bop = BOp{}, P proj = P{}) const { // BUGBUG think about the use of coerce here. using V = iter_value_t<I>; using X = invoke_result_t<P &, V>; coerce<V> v; coerce<X> x; if(first != last && result != end_result) { auto t1(x(invoke(proj, v(*first)))); *result = t1; for(++first, ++result; first != last && result != end_result; ++first, ++result) { auto t2(x(invoke(proj, v(*first)))); *result = invoke(bop, t2, t1); t1 = std::move(t2); } } return {first, result}; } template(typename I, typename S, typename O, typename BOp = minus, typename P = identity)( requires sentinel_for<S, I> AND differenceable<I, O, BOp, P>) adjacent_difference_result<I, O> // operator()(I first, S last, O result, BOp bop = BOp{}, P proj = P{}) const { return (*this)(std::move(first), std::move(last), std::move(result), unreachable, std::move(bop), std::move(proj)); } template(typename Rng, typename ORef, typename BOp = minus, typename P = identity, typename I = iterator_t<Rng>, typename O = uncvref_t<ORef>)( requires range<Rng> AND differenceable<I, O, BOp, P>) adjacent_difference_result<borrowed_iterator_t<Rng>, O> // operator()(Rng && rng, ORef && result, BOp bop = BOp{}, P proj = P{}) const { return (*this)(begin(rng), end(rng), static_cast<ORef &&>(result), std::move(bop), std::move(proj)); } template(typename Rng, typename ORng, typename BOp = minus, typename P = identity, typename I = iterator_t<Rng>, typename O = iterator_t<ORng>)( requires range<Rng> AND range<ORng> AND differenceable<I, O, BOp, P>) adjacent_difference_result<borrowed_iterator_t<Rng>, borrowed_iterator_t<ORng>> operator()(Rng && rng, ORng && result, BOp bop = BOp{}, P proj = P{}) const { return (*this)(begin(rng), end(rng), begin(result), end(result), std::move(bop), std::move(proj)); } }; RANGES_INLINE_VARIABLE(adjacent_difference_fn, adjacent_difference) /// @} } // namespace ranges #include <range/v3/detail/epilogue.hpp> #endif
0
repos/range-v3/include/range/v3
repos/range-v3/include/range/v3/numeric/inner_product.hpp
/// \file // Range v3 library // // Copyright Eric Niebler 2013-present // Copyright Gonzalo Brito Gadeschi 2014 // // Use, modification and distribution is subject to the // Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) // // Project home: https://github.com/ericniebler/range-v3 // #ifndef RANGES_V3_NUMERIC_INNER_PRODUCT_HPP #define RANGES_V3_NUMERIC_INNER_PRODUCT_HPP #include <meta/meta.hpp> #include <range/v3/functional/arithmetic.hpp> #include <range/v3/functional/concepts.hpp> #include <range/v3/functional/identity.hpp> #include <range/v3/functional/invoke.hpp> #include <range/v3/iterator/concepts.hpp> #include <range/v3/iterator/traits.hpp> #include <range/v3/iterator/unreachable_sentinel.hpp> #include <range/v3/range/access.hpp> #include <range/v3/range/concepts.hpp> #include <range/v3/range/traits.hpp> #include <range/v3/utility/static_const.hpp> #include <range/v3/detail/prologue.hpp> namespace ranges { /// \addtogroup group-numerics /// @{ // clang-format off /// \concept inner_product_constraints_ /// \brief The \c inner_product_constraints_ concept template(typename I1, typename I2, typename T, typename BOp1, typename BOp2, typename P1, typename P2)( concept (inner_product_constraints_)(I1, I2, T, BOp1, BOp2, P1, P2), invocable<P1&, iter_value_t<I1>> AND invocable<P2&, iter_value_t<I2>> AND invocable< BOp2&, invoke_result_t<P1&, iter_value_t<I1>>, invoke_result_t<P2&, iter_value_t<I2>>> AND invocable< BOp1&, T, invoke_result_t< BOp2&, invoke_result_t<P1&, iter_value_t<I1>>, invoke_result_t<P2&, iter_value_t<I2>>>> AND assignable_from< T&, invoke_result_t< BOp1&, T, invoke_result_t< BOp2&, invoke_result_t<P1&, iter_value_t<I1>>, invoke_result_t<P2&, iter_value_t<I2>>>>> ); /// \concept inner_product_constraints /// \brief The \c inner_product_constraints concept template<typename I1, typename I2, typename T, typename BOp1 = plus, typename BOp2 = multiplies, typename P1 = identity, typename P2 = identity> CPP_concept inner_product_constraints = input_iterator<I1> && input_iterator<I2> && CPP_concept_ref(ranges::inner_product_constraints_, I1, I2, T, BOp1, BOp2, P1, P2); // clang-format on struct inner_product_fn { template(typename I1, typename S1, typename I2, typename S2, typename T, typename BOp1 = plus, typename BOp2 = multiplies, typename P1 = identity, typename P2 = identity)( requires sentinel_for<S1, I1> AND sentinel_for<S2, I2> AND inner_product_constraints<I1, I2, T, BOp1, BOp2, P1, P2>) T operator()(I1 begin1, S1 end1, I2 begin2, S2 end2, T init, BOp1 bop1 = BOp1{}, BOp2 bop2 = BOp2{}, P1 proj1 = P1{}, P2 proj2 = P2{}) const { for(; begin1 != end1 && begin2 != end2; ++begin1, ++begin2) init = invoke(bop1, init, invoke(bop2, invoke(proj1, *begin1), invoke(proj2, *begin2))); return init; } template(typename I1, typename S1, typename I2, typename T, typename BOp1 = plus, typename BOp2 = multiplies, typename P1 = identity, typename P2 = identity)( requires sentinel_for<S1, I1> AND inner_product_constraints<I1, I2, T, BOp1, BOp2, P1, P2>) T operator()(I1 begin1, S1 end1, I2 begin2, T init, BOp1 bop1 = BOp1{}, BOp2 bop2 = BOp2{}, P1 proj1 = P1{}, P2 proj2 = P2{}) const { return (*this)(std::move(begin1), std::move(end1), std::move(begin2), unreachable, std::move(init), std::move(bop1), std::move(bop2), std::move(proj1), std::move(proj2)); } template(typename Rng1, typename I2Ref, typename T, typename BOp1 = plus, typename BOp2 = multiplies, typename P1 = identity, typename P2 = identity, typename I1 = iterator_t<Rng1>, typename I2 = uncvref_t<I2Ref>)( requires range<Rng1> AND inner_product_constraints<I1, I2, T, BOp1, BOp2, P1, P2>) T operator()(Rng1 && rng1, I2Ref && begin2, T init, BOp1 bop1 = BOp1{}, BOp2 bop2 = BOp2{}, P1 proj1 = P1{}, P2 proj2 = P2{}) const { return (*this)(begin(rng1), end(rng1), static_cast<I2Ref &&>(begin2), std::move(init), std::move(bop1), std::move(bop2), std::move(proj1), std::move(proj2)); } template(typename Rng1, typename Rng2, typename T, typename BOp1 = plus, typename BOp2 = multiplies, typename P1 = identity, typename P2 = identity, typename I1 = iterator_t<Rng1>, typename I2 = iterator_t<Rng2>)( requires range<Rng1> AND range<Rng2> AND inner_product_constraints<I1, I2, T, BOp1, BOp2, P1, P2>) T operator()(Rng1 && rng1, Rng2 && rng2, T init, BOp1 bop1 = BOp1{}, BOp2 bop2 = BOp2{}, P1 proj1 = P1{}, P2 proj2 = P2{}) const { return (*this)(begin(rng1), end(rng1), begin(rng2), end(rng2), std::move(init), std::move(bop1), std::move(bop2), std::move(proj1), std::move(proj2)); } }; RANGES_INLINE_VARIABLE(inner_product_fn, inner_product) /// @} } // namespace ranges #include <range/v3/detail/epilogue.hpp> #endif
0
repos/range-v3/include/range/v3
repos/range-v3/include/range/v3/numeric/iota.hpp
/// \file // Range v3 library // // Copyright Eric Niebler 2013-present // // Use, modification and distribution is subject to the // Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) // // Project home: https://github.com/ericniebler/range-v3 // #ifndef RANGES_V3_NUMERIC_IOTA_HPP #define RANGES_V3_NUMERIC_IOTA_HPP #include <range/v3/iterator/concepts.hpp> #include <range/v3/range/access.hpp> #include <range/v3/range/concepts.hpp> #include <range/v3/range/dangling.hpp> #include <range/v3/range/traits.hpp> #include <range/v3/utility/static_const.hpp> #include <range/v3/detail/prologue.hpp> namespace ranges { /// \addtogroup group-numerics /// @{ struct iota_fn { template(typename O, typename S, typename T)( requires output_iterator<O, T const &> AND sentinel_for<S, O> AND weakly_incrementable<T>) O operator()(O first, S last, T val) const { for(; first != last; ++first, ++val) *first = detail::as_const(val); return first; } template(typename Rng, typename T)( requires output_range<Rng, T const &> AND weakly_incrementable<T>) borrowed_iterator_t<Rng> operator()(Rng && rng, T val) const // { return (*this)(begin(rng), end(rng), detail::move(val)); } }; RANGES_INLINE_VARIABLE(iota_fn, iota) /// @} } // namespace ranges #include <range/v3/detail/epilogue.hpp> #endif
0
repos/range-v3/include/range/v3
repos/range-v3/include/range/v3/numeric/accumulate.hpp
/// \file // Range v3 library // // Copyright Eric Niebler 2013-present // // Use, modification and distribution is subject to the // Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) // // Project home: https://github.com/ericniebler/range-v3 // #ifndef RANGES_V3_NUMERIC_ACCUMULATE_HPP #define RANGES_V3_NUMERIC_ACCUMULATE_HPP #include <meta/meta.hpp> #include <range/v3/functional/arithmetic.hpp> #include <range/v3/functional/identity.hpp> #include <range/v3/functional/invoke.hpp> #include <range/v3/iterator/concepts.hpp> #include <range/v3/iterator/traits.hpp> #include <range/v3/range/access.hpp> #include <range/v3/range/concepts.hpp> #include <range/v3/range/traits.hpp> #include <range/v3/utility/static_const.hpp> #include <range/v3/detail/prologue.hpp> namespace ranges { /// \addtogroup group-numerics /// @{ struct accumulate_fn { template(typename I, typename S, typename T, typename Op = plus, typename P = identity)( requires sentinel_for<S, I> AND input_iterator<I> AND indirectly_binary_invocable_<Op, T *, projected<I, P>> AND assignable_from<T &, indirect_result_t<Op &, T *, projected<I, P>>>) T operator()(I first, S last, T init, Op op = Op{}, P proj = P{}) const { for(; first != last; ++first) init = invoke(op, init, invoke(proj, *first)); return init; } template(typename Rng, typename T, typename Op = plus, typename P = identity)( requires input_range<Rng> AND indirectly_binary_invocable_<Op, T *, projected<iterator_t<Rng>, P>> AND assignable_from< T &, indirect_result_t<Op &, T *, projected<iterator_t<Rng>, P>>>) T operator()(Rng && rng, T init, Op op = Op{}, P proj = P{}) const { return (*this)( begin(rng), end(rng), std::move(init), std::move(op), std::move(proj)); } }; RANGES_INLINE_VARIABLE(accumulate_fn, accumulate) /// @} } // namespace ranges #include <range/v3/detail/epilogue.hpp> #endif
0
repos/range-v3/include/range/v3
repos/range-v3/include/range/v3/range/traits.hpp
/// \file // Range v3 library // // Copyright Eric Niebler 2013-present // // Use, modification and distribution is subject to the // Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) // // Project home: https://github.com/ericniebler/range-v3 // #ifndef RANGES_V3_RANGE_TRAITS_HPP #define RANGES_V3_RANGE_TRAITS_HPP #include <array> #include <iterator> #include <type_traits> #include <utility> #include <meta/meta.hpp> #include <range/v3/range_fwd.hpp> #include <range/v3/range/access.hpp> #include <range/v3/range/primitives.hpp> #include <range/v3/detail/prologue.hpp> namespace ranges { /// \cond namespace detail { template<typename I, typename S> using common_iterator_impl_t = enable_if_t<(bool)(input_or_output_iterator<I> && sentinel_for<S, I>), common_iterator<I, S>>; } /// \endcond /// \addtogroup group-range /// @{ template<typename I, typename S> using common_iterator_t = meta::conditional_t<std::is_same<I, S>::value, I, detail::common_iterator_impl_t<I, S>>; /// \cond namespace detail { template<typename I, typename S> using cpp17_iterator_t = meta::conditional_t<std::is_integral<iter_difference_t<I>>::value, common_iterator_t<I, S>, cpp17_iterator<common_iterator_t<I, S>>>; } /// \endcond // Aliases (SFINAE-able) template<typename Rng> using range_difference_t = iter_difference_t<iterator_t<Rng>>; template<typename Rng> using range_value_t = iter_value_t<iterator_t<Rng>>; template<typename Rng> using range_reference_t = iter_reference_t<iterator_t<Rng>>; template<typename Rng> using range_rvalue_reference_t = iter_rvalue_reference_t<iterator_t<Rng>>; template<typename Rng> using range_common_reference_t = iter_common_reference_t<iterator_t<Rng>>; template<typename Rng> using range_size_t = decltype(ranges::size(std::declval<Rng &>())); /// \cond template<typename Rng> using range_difference_type_t RANGES_DEPRECATED( "range_difference_type_t is deprecated. Use the range_difference_t instead.") = iter_difference_t<iterator_t<Rng>>; template<typename Rng> using range_value_type_t RANGES_DEPRECATED( "range_value_type_t is deprecated. Use the range_value_t instead.") = iter_value_t<iterator_t<Rng>>; template<typename Rng> using range_category_t RANGES_DEPRECATED( "range_category_t is deprecated. Use the range concepts instead.") = meta::_t<detail::iterator_category<iterator_t<Rng>>>; template<typename Rng> using range_size_type_t RANGES_DEPRECATED( "range_size_type_t is deprecated. Use range_size_t instead.") = detail::iter_size_t<iterator_t<Rng>>; /// \endcond template<typename Rng> using range_common_iterator_t = common_iterator_t<iterator_t<Rng>, sentinel_t<Rng>>; /// \cond namespace detail { template<typename Rng> using range_cpp17_iterator_t = cpp17_iterator_t<iterator_t<Rng>, sentinel_t<Rng>>; std::integral_constant<cardinality, finite> test_cardinality(void *); template<cardinality Card> std::integral_constant<cardinality, Card> test_cardinality(basic_view<Card> *); template<typename T, std::size_t N> std::integral_constant<cardinality, static_cast<cardinality>(N)> test_cardinality( T (*)[N]); template<typename T, std::size_t N> std::integral_constant<cardinality, static_cast<cardinality>(N)> test_cardinality( std::array<T, N> *); } // namespace detail /// \endcond // User customization point for specifying the cardinality of ranges: template<typename Rng, typename Void /*= void*/> struct range_cardinality : meta::conditional_t<RANGES_IS_SAME(Rng, uncvref_t<Rng>), decltype(detail::test_cardinality( static_cast<uncvref_t<Rng> *>(nullptr))), range_cardinality<uncvref_t<Rng>>> {}; /// @} namespace cpp20 { using ranges::range_difference_t; using ranges::range_reference_t; using ranges::range_rvalue_reference_t; using ranges::range_value_t; } // namespace cpp20 } // namespace ranges #include <range/v3/detail/epilogue.hpp> #endif
0
repos/range-v3/include/range/v3
repos/range-v3/include/range/v3/range/access.hpp
/// \file // Range v3 library // // Copyright Eric Niebler 2013-present // // Use, modification and distribution is subject to the // Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) // // Project home: https://github.com/ericniebler/range-v3 // #ifndef RANGES_V3_RANGE_ACCESS_HPP #define RANGES_V3_RANGE_ACCESS_HPP #include <range/v3/detail/config.hpp> #include <functional> // for reference_wrapper (whose use with begin/end is deprecated) #include <initializer_list> #include <iterator> #include <limits> #include <utility> #ifdef __has_include #if __has_include(<span>) && !defined(RANGES_WORKAROUND_MSVC_UNUSABLE_SPAN) #include <span> #endif #if __has_include(<string_view>) #include <string_view> #endif #endif #include <range/v3/range_fwd.hpp> #include <range/v3/iterator/concepts.hpp> #include <range/v3/iterator/reverse_iterator.hpp> #include <range/v3/iterator/traits.hpp> #include <range/v3/utility/static_const.hpp> #include <range/v3/detail/prologue.hpp> namespace ranges { #if defined(__cpp_lib_string_view) && __cpp_lib_string_view >= 201603L template<class CharT, class Traits> RANGES_INLINE_VAR constexpr bool enable_borrowed_range<std::basic_string_view<CharT, Traits>> = true; #endif // libstdc++'s <span> header only defines std::span when concepts // are also enabled. https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97869 #if defined(__cpp_lib_span) && __cpp_lib_span >= 202002L && \ (!defined(__GLIBCXX__) || defined(__cpp_lib_concepts)) template<class T, std::size_t N> RANGES_INLINE_VAR constexpr bool enable_borrowed_range<std::span<T, N>> = true; #endif namespace detail { template<typename T> RANGES_INLINE_VAR constexpr bool _borrowed_range = enable_borrowed_range<uncvref_t<T>>; template<typename T> RANGES_INLINE_VAR constexpr bool _borrowed_range<T &> = true; template<typename T> T _decay_copy(T) noexcept; } // namespace detail /// \cond namespace _begin_ { // Poison pill for std::begin. (See the detailed discussion at // https://github.com/ericniebler/stl2/issues/139) template<typename T> void begin(T &&) = delete; #ifdef RANGES_WORKAROUND_MSVC_895622 void begin(); #endif template<typename T> void begin(std::initializer_list<T>) = delete; template(typename I)( requires input_or_output_iterator<I>) void is_iterator(I); // clang-format off /// \concept has_member_begin_ /// \brief The \c has_member_begin_ concept template<typename T> CPP_requires(has_member_begin_, requires(T & t) // ( _begin_::is_iterator(t.begin()) )); /// \concept has_member_begin /// \brief The \c has_member_begin concept template<typename T> CPP_concept has_member_begin = CPP_requires_ref(_begin_::has_member_begin_, T); /// \concept has_non_member_begin_ /// \brief The \c has_non_member_begin_ concept template<typename T> CPP_requires(has_non_member_begin_, requires(T & t) // ( _begin_::is_iterator(begin(t)) )); /// \concept has_non_member_begin /// \brief The \c has_non_member_begin concept template<typename T> CPP_concept has_non_member_begin = CPP_requires_ref(_begin_::has_non_member_begin_, T); // clang-format on struct fn { private: struct _member_result_ { template<typename R> using invoke = decltype(detail::_decay_copy(declval(R &).begin())); }; struct _non_member_result_ { template<typename R> using invoke = decltype(detail::_decay_copy(begin(declval(R &)))); }; template<typename R> using _result_t = meta::invoke< meta::conditional_t< has_member_begin<R>, _member_result_, _non_member_result_>, R>; public: template<typename R, std::size_t N> void operator()(R(&&)[N]) const = delete; template<typename R, std::size_t N> constexpr R * operator()(R (&array)[N]) const noexcept { return array; } template(typename R)( requires detail::_borrowed_range<R> AND has_member_begin<R>) constexpr _result_t<R> operator()(R && r) const // noexcept(noexcept(r.begin())) { return r.begin(); } template(typename R)( requires detail::_borrowed_range<R> AND (!has_member_begin<R>) AND has_non_member_begin<R>) constexpr _result_t<R> operator()(R && r) const // noexcept(noexcept(begin(r))) { return begin(r); } }; template<typename R> using _t = decltype(fn{}(declval(R &&))); } // namespace _begin_ /// \endcond /// \ingroup group-range /// \param r /// \return \c r, if \c r is an array. Otherwise, `r.begin()` if that expression is /// well-formed and returns an input_or_output_iterator. Otherwise, `begin(r)` if /// that expression returns an input_or_output_iterator. RANGES_DEFINE_CPO(_begin_::fn, begin) /// \cond namespace _end_ { // Poison pill for std::end. (See the detailed discussion at // https://github.com/ericniebler/stl2/issues/139) template<typename T> void end(T &&) = delete; #ifdef RANGES_WORKAROUND_MSVC_895622 void end(); #endif template<typename T> void end(std::initializer_list<T>) = delete; template(typename I, typename S)( requires sentinel_for<S, I>) void _is_sentinel(S, I); // clang-format off /// \concept has_member_end_ /// \brief The \c has_member_end_ concept template<typename T> CPP_requires(has_member_end_, requires(T & t) // ( _end_::_is_sentinel(t.end(), ranges::begin(t)) )); /// \concept has_member_end /// \brief The \c has_member_end concept template<typename T> CPP_concept has_member_end = CPP_requires_ref(_end_::has_member_end_, T); /// \concept has_non_member_end_ /// \brief The \c has_non_member_end_ concept template<typename T> CPP_requires(has_non_member_end_, requires(T & t) // ( _end_::_is_sentinel(end(t), ranges::begin(t)) )); /// \concept has_non_member_end /// \brief The \c has_non_member_end concept template<typename T> CPP_concept has_non_member_end = CPP_requires_ref(_end_::has_non_member_end_, T); // clang-format on struct fn { private: struct _member_result_ { template<typename R> using invoke = decltype(detail::_decay_copy(declval(R &).end())); }; struct _non_member_result_ { template<typename R> using invoke = decltype(detail::_decay_copy(end(declval(R &)))); }; template<typename R> using _result_t = meta::invoke< meta::conditional_t< has_member_end<R>, _member_result_, _non_member_result_>, R>; template<typename Int> using iter_diff_t = meta::_t<meta::conditional_t<std::is_integral<Int>::value, std::make_signed<Int>, // meta::id<Int>>>; public: template<typename R, std::size_t N> void operator()(R(&&)[N]) const = delete; template<typename R, std::size_t N> constexpr R * operator()(R (&array)[N]) const noexcept { return array + N; } template(typename R)( requires detail::_borrowed_range<R> AND has_member_end<R>) constexpr _result_t<R> operator()(R && r) const // noexcept(noexcept(r.end())) { return r.end(); } template(typename R)( requires detail::_borrowed_range<R> AND (!has_member_end<R>) AND has_non_member_end<R>) constexpr _result_t<R> operator()(R && r) const // noexcept(noexcept(end(r))) { return end(r); } template(typename Int)( requires detail::integer_like_<Int>) auto operator-(Int dist) const -> detail::from_end_<iter_diff_t<Int>> { using SInt = iter_diff_t<Int>; RANGES_EXPECT(0 <= dist); RANGES_EXPECT(dist <= static_cast<Int>((std::numeric_limits<SInt>::max)())); return detail::from_end_<SInt>{-static_cast<SInt>(dist)}; } }; template<typename R> using _t = decltype(fn{}(declval(R &&))); } // namespace _end_ /// \endcond /// \ingroup group-range /// \param r /// \return \c r+size(r), if \c r is an array. Otherwise, `r.end()` if that expression /// is /// well-formed and returns an input_or_output_iterator. Otherwise, `end(r)` if that /// expression returns an input_or_output_iterator. RANGES_DEFINE_CPO(_end_::fn, end) /// \cond namespace _cbegin_ { struct fn { template<typename T, std::size_t N> void operator()(T(&&)[N]) const = delete; template<typename R> constexpr _begin_::_t<detail::as_const_t<R>> operator()(R && r) const noexcept(noexcept(ranges::begin(detail::as_const(r)))) { return ranges::begin(detail::as_const(r)); } }; } // namespace _cbegin_ /// \endcond /// \ingroup group-range /// \param r /// \return The result of calling `ranges::begin` with a const-qualified /// reference to r. RANGES_INLINE_VARIABLE(_cbegin_::fn, cbegin) /// \cond namespace _cend_ { struct fn { template<typename T, std::size_t N> void operator()(T(&&)[N]) const = delete; template<typename R> constexpr _end_::_t<detail::as_const_t<R>> operator()(R && r) const noexcept(noexcept(ranges::end(detail::as_const(r)))) { return ranges::end(detail::as_const(r)); } }; } // namespace _cend_ /// \endcond /// \ingroup group-range /// \param r /// \return The result of calling `ranges::end` with a const-qualified /// reference to r. RANGES_INLINE_VARIABLE(_cend_::fn, cend) /// \cond namespace _rbegin_ { template<typename R> void rbegin(R &&) = delete; // Non-standard, to keep unqualified rbegin(r) from finding std::rbegin // and returning a std::reverse_iterator. template<typename T> void rbegin(std::initializer_list<T>) = delete; template<typename T, std::size_t N> void rbegin(T (&)[N]) = delete; // clang-format off /// \concept has_member_rbegin_ /// \brief The \c has_member_rbegin_ concept template<typename T> CPP_requires(has_member_rbegin_, requires(T & t) // ( _begin_::is_iterator(t.rbegin()) )); /// \concept has_member_rbegin /// \brief The \c has_member_rbegin concept template<typename T> CPP_concept has_member_rbegin = CPP_requires_ref(_rbegin_::has_member_rbegin_, T); /// \concept has_non_member_rbegin_ /// \brief The \c has_non_member_rbegin_ concept template<typename T> CPP_requires(has_non_member_rbegin_, requires(T & t) // ( _begin_::is_iterator(rbegin(t)) )); /// \concept has_non_member_rbegin /// \brief The \c has_non_member_rbegin concept template<typename T> CPP_concept has_non_member_rbegin = CPP_requires_ref(_rbegin_::has_non_member_rbegin_, T); template<typename I> void _same_type(I, I); /// \concept can_reverse_end_ /// \brief The \c can_reverse_end_ concept template<typename T> CPP_requires(can_reverse_end_, requires(T & t) // ( // make_reverse_iterator is constrained with // bidirectional_iterator. ranges::make_reverse_iterator(ranges::end(t)), _rbegin_::_same_type(ranges::begin(t), ranges::end(t)) )); /// \concept can_reverse_end /// \brief The \c can_reverse_end concept template<typename T> CPP_concept can_reverse_end = CPP_requires_ref(_rbegin_::can_reverse_end_, T); // clang-format on struct fn { private: struct _member_result_ { template<typename R> using invoke = decltype(detail::_decay_copy(declval(R &).rbegin())); }; struct _non_member_result_ { template<typename R> using invoke = decltype(detail::_decay_copy(rbegin(declval(R &)))); }; struct _reverse_result_ { template<typename R> using invoke = decltype(ranges::make_reverse_iterator(ranges::end(declval(R &)))); }; struct _other_result_ { template<typename R> using invoke = meta::invoke< meta::conditional_t< has_non_member_rbegin<R>, _non_member_result_, _reverse_result_>, R>; }; template<typename R> using _result_t = meta::invoke< meta::conditional_t< has_member_rbegin<R>, _member_result_, _other_result_>, R>; public: template(typename R)( requires detail::_borrowed_range<R> AND has_member_rbegin<R>) constexpr auto operator()(R && r) const // noexcept(noexcept(r.rbegin())) // { return r.rbegin(); } template(typename R)( requires detail::_borrowed_range<R> AND (!has_member_rbegin<R>) AND has_non_member_rbegin<R>) constexpr auto operator()(R && r) const // noexcept(noexcept(rbegin(r))) // { return rbegin(r); } template(typename R)( requires detail::_borrowed_range<R> AND (!has_member_rbegin<R>) AND (!has_non_member_rbegin<R>) AND can_reverse_end<R>) constexpr auto operator()(R && r) const // noexcept(noexcept(ranges::make_reverse_iterator(ranges::end(r)))) { return ranges::make_reverse_iterator(ranges::end(r)); } }; template<typename R> using _t = decltype(fn{}(declval(R &&))); } // namespace _rbegin_ /// \endcond /// \ingroup group-range /// \param r /// \return `make_reverse_iterator(r + ranges::size(r))` if r is an array. Otherwise, /// `r.rbegin()` if that expression is well-formed and returns an /// input_or_output_iterator. Otherwise, `make_reverse_iterator(ranges::end(r))` if /// `ranges::begin(r)` and `ranges::end(r)` are both well-formed and have the same /// type that satisfies `bidirectional_iterator`. RANGES_DEFINE_CPO(_rbegin_::fn, rbegin) /// \cond namespace _rend_ { template<typename R> void rend(R &&) = delete; // Non-standard, to keep unqualified rend(r) from finding std::rend // and returning a std::reverse_iterator. template<typename T> void rend(std::initializer_list<T>) = delete; template<typename T, std::size_t N> void rend(T (&)[N]) = delete; // clang-format off /// \concept has_member_rend_ /// \brief The \c has_member_rend_ concept template<typename T> CPP_requires(has_member_rend_, requires(T & t) // ( _end_::_is_sentinel(t.rend(), ranges::rbegin(t)) )); /// \concept has_member_rend /// \brief The \c has_member_rend concept template<typename T> CPP_concept has_member_rend = CPP_requires_ref(_rend_::has_member_rend_, T); /// \concept has_non_member_rend_ /// \brief The \c has_non_member_rend_ concept template<typename T> CPP_requires(has_non_member_rend_, requires(T & t) // ( _end_::_is_sentinel(rend(t), ranges::rbegin(t)) )); /// \concept has_non_member_rend /// \brief The \c has_non_member_rend concept template<typename T> CPP_concept has_non_member_rend = CPP_requires_ref(_rend_::has_non_member_rend_, T); /// \concept can_reverse_begin_ /// \brief The \c can_reverse_begin_ concept template<typename T> CPP_requires(can_reverse_begin_, requires(T & t) // ( // make_reverse_iterator is constrained with // bidirectional_iterator. ranges::make_reverse_iterator(ranges::begin(t)), _rbegin_::_same_type(ranges::begin(t), ranges::end(t)) )); /// \concept can_reverse_begin /// \brief The \c can_reverse_begin concept template<typename T> CPP_concept can_reverse_begin = CPP_requires_ref(_rend_::can_reverse_begin_, T); // clang-format on struct fn { private: struct _member_result_ { template<typename R> using invoke = decltype(detail::_decay_copy(declval(R &).rend())); }; struct _non_member_result_ { template<typename R> using invoke = decltype(detail::_decay_copy(rend(declval(R &)))); }; struct _reverse_result_ { template<typename R> using invoke = decltype(ranges::make_reverse_iterator(ranges::begin(declval(R &)))); }; struct _other_result_ { template<typename R> using invoke = meta::invoke< meta::conditional_t< has_non_member_rend<R>, _non_member_result_, _reverse_result_>, R>; }; template<typename R> using _result_t = meta::invoke< meta::conditional_t< has_member_rend<R>, _member_result_, _other_result_>, R>; public: template(typename R)( requires detail::_borrowed_range<R> AND has_member_rend<R>) constexpr auto operator()(R && r) const // noexcept(noexcept(r.rend())) // { return r.rend(); } template(typename R)( requires detail::_borrowed_range<R> AND (!has_member_rend<R>) AND has_non_member_rend<R>) constexpr auto operator()(R && r) const // noexcept(noexcept(rend(r))) // { return rend(r); } template(typename R)( requires detail::_borrowed_range<R> AND (!has_member_rend<R>) AND (!has_non_member_rend<R>) AND can_reverse_begin<R>) constexpr auto operator()(R && r) const // noexcept(noexcept(ranges::make_reverse_iterator(ranges::begin(r)))) { return ranges::make_reverse_iterator(ranges::begin(r)); } }; template<typename R> using _t = decltype(fn{}(declval(R &&))); } // namespace _rend_ /// \endcond /// \ingroup group-range /// \param r /// \return `make_reverse_iterator(r)` if `r` is an array. Otherwise, /// `r.rend()` if that expression is well-formed and returns a type that /// satisfies `sentinel_for<S, I>` where `I` is the type of `ranges::rbegin(r)`. /// Otherwise, `make_reverse_iterator(ranges::begin(r))` if `ranges::begin(r)` /// and `ranges::end(r)` are both well-formed and have the same type that /// satisfies `bidirectional_iterator`. RANGES_DEFINE_CPO(_rend_::fn, rend) /// \cond namespace _crbegin_ { struct fn { template<typename T, std::size_t N> void operator()(T(&&)[N]) const = delete; template<typename R> constexpr _rbegin_::_t<detail::as_const_t<R>> operator()(R && r) const noexcept(noexcept(ranges::rbegin(detail::as_const(r)))) { return ranges::rbegin(detail::as_const(r)); } }; } // namespace _crbegin_ /// \endcond /// \ingroup group-range /// \param r /// \return The result of calling `ranges::rbegin` with a const-qualified /// reference to r. RANGES_INLINE_VARIABLE(_crbegin_::fn, crbegin) /// \cond namespace _crend_ { struct fn { template<typename T, std::size_t N> void operator()(T(&&)[N]) const = delete; template<typename R> constexpr _rend_::_t<detail::as_const_t<R>> operator()(R && r) const noexcept(noexcept(ranges::rend(detail::as_const(r)))) { return ranges::rend(detail::as_const(r)); } }; } // namespace _crend_ /// \endcond /// \ingroup group-range /// \param r /// \return The result of calling `ranges::rend` with a const-qualified /// reference to r. RANGES_INLINE_VARIABLE(_crend_::fn, crend) template<typename Rng> using iterator_t = decltype(begin(declval(Rng &))); template<typename Rng> using sentinel_t = decltype(end(declval(Rng &))); namespace cpp20 { using ranges::begin; using ranges::cbegin; using ranges::cend; using ranges::crbegin; using ranges::crend; using ranges::end; using ranges::rbegin; using ranges::rend; using ranges::iterator_t; using ranges::sentinel_t; using ranges::enable_borrowed_range; } // namespace cpp20 } // namespace ranges #include <range/v3/detail/epilogue.hpp> #endif
0
repos/range-v3/include/range/v3
repos/range-v3/include/range/v3/range/concepts.hpp
/// \file // Range v3 library // // Copyright Eric Niebler 2013-present // // Use, modification and distribution is subject to the // Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) // // Project home: https://github.com/ericniebler/range-v3 // #ifndef RANGES_V3_RANGE_CONCEPTS_HPP #define RANGES_V3_RANGE_CONCEPTS_HPP #include <range/v3/detail/config.hpp> #include <initializer_list> #include <type_traits> #include <utility> #ifdef __has_include #if __has_include(<span>) && !defined(RANGES_WORKAROUND_MSVC_UNUSABLE_SPAN) #include <span> #endif #if __has_include(<string_view>) #include <string_view> #endif #endif #include <meta/meta.hpp> #include <concepts/concepts.hpp> #include <range/v3/range_fwd.hpp> #include <range/v3/functional/comparisons.hpp> #include <range/v3/iterator/concepts.hpp> #include <range/v3/iterator/traits.hpp> #include <range/v3/range/access.hpp> #include <range/v3/range/primitives.hpp> #include <range/v3/range/traits.hpp> #include <range/v3/detail/prologue.hpp> namespace ranges { /// \addtogroup group-range-concepts /// @{ // // Range concepts below // // clang-format off /// \concept _range_ /// \brief The \c _range_ concept template<typename T> CPP_requires(_range_, requires(T & t) // ( ranges::begin(t), // not necessarily equality-preserving ranges::end(t) )); /// \concept range /// \brief The \c range concept template<typename T> CPP_concept range = CPP_requires_ref(ranges::_range_, T); /// \concept borrowed_range /// \brief The \c borrowed_range concept template<typename T> CPP_concept borrowed_range = range<T> && detail::_borrowed_range<T>; template <typename R> RANGES_DEPRECATED("Please use ranges::borrowed_range instead.") RANGES_INLINE_VAR constexpr bool safe_range = borrowed_range<R>; /// \concept output_range_ /// \brief The \c output_range_ concept template(typename T, typename V)( concept (output_range_)(T, V), output_iterator<iterator_t<T>, V> ); /// \concept output_range /// \brief The \c output_range concept template<typename T, typename V> CPP_concept output_range = range<T> && CPP_concept_ref(ranges::output_range_, T, V); /// \concept input_range_ /// \brief The \c input_range_ concept template(typename T)( concept (input_range_)(T), input_iterator<iterator_t<T>> ); /// \concept input_range /// \brief The \c input_range concept template<typename T> CPP_concept input_range = range<T> && CPP_concept_ref(ranges::input_range_, T); /// \concept forward_range_ /// \brief The \c forward_range_ concept template(typename T)( concept (forward_range_)(T), forward_iterator<iterator_t<T>> ); /// \concept forward_range /// \brief The \c forward_range concept template<typename T> CPP_concept forward_range = input_range<T> && CPP_concept_ref(ranges::forward_range_, T); /// \concept bidirectional_range_ /// \brief The \c bidirectional_range_ concept template(typename T)( concept (bidirectional_range_)(T), bidirectional_iterator<iterator_t<T>> ); /// \concept bidirectional_range /// \brief The \c bidirectional_range concept template<typename T> CPP_concept bidirectional_range = forward_range<T> && CPP_concept_ref(ranges::bidirectional_range_, T); /// \concept random_access_range_ /// \brief The \c random_access_range_ concept template(typename T)( concept (random_access_range_)(T), random_access_iterator<iterator_t<T>> ); /// \concept random_access_range /// \brief The \c random_access_range concept template<typename T> CPP_concept random_access_range = bidirectional_range<T> && CPP_concept_ref(ranges::random_access_range_, T); // clang-format on /// \cond namespace detail { template<typename Rng> using data_t = decltype(ranges::data(std::declval<Rng &>())); template<typename Rng> using element_t = meta::_t<std::remove_pointer<data_t<Rng>>>; } // namespace detail /// \endcond // clang-format off /// \concept contiguous_range_ /// \brief The \c contiguous_range_ concept template(typename T)( concept (contiguous_range_)(T), contiguous_iterator<iterator_t<T>> AND same_as<detail::data_t<T>, std::add_pointer_t<iter_reference_t<iterator_t<T>>>> ); /// \concept contiguous_range /// \brief The \c contiguous_range concept template<typename T> CPP_concept contiguous_range = random_access_range<T> && CPP_concept_ref(ranges::contiguous_range_, T); /// \concept common_range_ /// \brief The \c common_range_ concept template(typename T)( concept (common_range_)(T), same_as<iterator_t<T>, sentinel_t<T>> ); /// \concept common_range /// \brief The \c common_range concept template<typename T> CPP_concept common_range = range<T> && CPP_concept_ref(ranges::common_range_, T); /// \cond /// \concept bounded_range /// \brief The \c bounded_range concept template<typename T> CPP_concept bounded_range = common_range<T>; /// \endcond /// \concept sized_range_ /// \brief The \c sized_range_ concept template<typename T> CPP_requires(sized_range_, requires(T & t) // ( ranges::size(t) )); /// \concept sized_range_ /// \brief The \c sized_range_ concept template(typename T)( concept (sized_range_)(T), detail::integer_like_<range_size_t<T>>); /// \concept sized_range /// \brief The \c sized_range concept template<typename T> CPP_concept sized_range = range<T> && !disable_sized_range<uncvref_t<T>> && CPP_requires_ref(ranges::sized_range_, T) && CPP_concept_ref(ranges::sized_range_, T); // clang-format on /// \cond namespace ext { template<typename T> struct enable_view : std::is_base_of<view_base, T> {}; } // namespace detail /// \endcond // Specialize this if the default is wrong. template<typename T> RANGES_INLINE_VAR constexpr bool enable_view = ext::enable_view<T>::value; #if defined(__cpp_lib_string_view) && __cpp_lib_string_view >= 201603L template<typename Char, typename Traits> RANGES_INLINE_VAR constexpr bool enable_view<std::basic_string_view<Char, Traits>> = true; #endif // libstdc++'s <span> header only defines std::span when concepts // are also enabled. https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97869 #if defined(__cpp_lib_span) && __cpp_lib_span >= 202002L && \ (!defined(__GLIBCXX__) || defined(__cpp_lib_concepts)) template<typename T, std::size_t N> RANGES_INLINE_VAR constexpr bool enable_view<std::span<T, N>> = true; #endif // // View concepts below // // clang-format off /// \concept view_ /// \brief The \c view_ concept template<typename T> CPP_concept view_ = range<T> && copyable<T> && enable_view<T>; /// \concept viewable_range /// \brief The \c viewable_range concept template<typename T> CPP_concept viewable_range = range<T> && (borrowed_range<T> || view_<uncvref_t<T>>); // clang-format on ////////////////////////////////////////////////////////////////////////////////////// // range_tag struct range_tag {}; struct input_range_tag : range_tag {}; struct forward_range_tag : input_range_tag {}; struct bidirectional_range_tag : forward_range_tag {}; struct random_access_range_tag : bidirectional_range_tag {}; struct contiguous_range_tag : random_access_range_tag {}; template<typename Rng> using range_tag_of = // std::enable_if_t< // range<Rng>, // meta::conditional_t< // contiguous_range<Rng>, // contiguous_range_tag, // meta::conditional_t< // random_access_range<Rng>, // random_access_range_tag, // meta::conditional_t< // bidirectional_range<Rng>, // bidirectional_range_tag, // meta::conditional_t< // forward_range<Rng>, // forward_range_tag, // meta::conditional_t< // input_range<Rng>, // input_range_tag, // range_tag>>>>>>; ////////////////////////////////////////////////////////////////////////////////////// // common_range_tag_of struct common_range_tag : range_tag {}; template<typename Rng> using common_range_tag_of = // std::enable_if_t< // range<Rng>, // meta::conditional_t<common_range<Rng>, common_range_tag, range_tag>>; ////////////////////////////////////////////////////////////////////////////////////// // sized_range_concept struct sized_range_tag : range_tag {}; template<typename Rng> using sized_range_tag_of = // std::enable_if_t< // range<Rng>, // meta::conditional_t<sized_range<Rng>, sized_range_tag, range_tag>>; /// \cond namespace view_detail_ { // clang-format off /// \concept view /// \brief The \c view concept template<typename T> CPP_concept view = ranges::view_<T>; // clang-format on } // namespace view_detail_ /// \endcond namespace cpp20 { using ranges::borrowed_range; using ranges::bidirectional_range; using ranges::common_range; using ranges::contiguous_range; using ranges::enable_view; using ranges::forward_range; using ranges::input_range; using ranges::output_range; using ranges::random_access_range; using ranges::range; using ranges::sized_range; using ranges::viewable_range; using ranges::view_detail_::view; using ranges::view_base; } // namespace cpp20 /// @} } // namespace ranges #include <range/v3/detail/epilogue.hpp> #endif
0
repos/range-v3/include/range/v3
repos/range-v3/include/range/v3/range/conversion.hpp
/// \file // Range v3 library // // Copyright Eric Niebler 2013-present // // Use, modification and distribution is subject to the // Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) // // Project home: https://github.com/ericniebler/range-v3 // #ifndef RANGES_V3_RANGE_CONVERSION_HPP #define RANGES_V3_RANGE_CONVERSION_HPP #include <vector> #include <meta/meta.hpp> #include <range/v3/range_fwd.hpp> #include <range/v3/action/concepts.hpp> #include <range/v3/functional/pipeable.hpp> #include <range/v3/iterator/common_iterator.hpp> #include <range/v3/range/concepts.hpp> #include <range/v3/range/traits.hpp> #include <range/v3/utility/static_const.hpp> #include <range/v3/detail/prologue.hpp> namespace ranges { /// \cond namespace detail { struct to_container { template<typename MetaFn> struct fn; template<typename MetaFn, typename Fn> struct closure; template<typename MetaFn, typename Rng> using container_t = meta::invoke<MetaFn, Rng>; template<typename Rng, typename MetaFn> friend auto operator|(Rng && rng, closure<MetaFn, fn<MetaFn>> (*)(to_container)) -> CPP_broken_friend_ret(container_t<MetaFn, Rng>)( requires invocable<fn<MetaFn>, Rng>) { return fn<MetaFn>{}(static_cast<Rng &&>(rng)); } template<typename MetaFn, typename Pipeable> friend auto operator|(closure<MetaFn, fn<MetaFn>> (*)(to_container), Pipeable pipe) -> CPP_broken_friend_ret( closure<MetaFn, composed<Pipeable, fn<MetaFn>>>)( requires (is_pipeable_v<Pipeable>)) { return closure<MetaFn, composed<Pipeable, fn<MetaFn>>>{ compose(static_cast<Pipeable &&>(pipe), fn<MetaFn>{})}; } }; // A simple, light-weight transform iterator that applies ranges::to // to each element in the range. Used by ranges::to to convert a range // of ranges into a container of containers. template<typename Rng, typename Cont> struct to_container_iterator { private: using I = range_cpp17_iterator_t<Rng>; using ValueType = range_value_t<Cont>; I it_; public: using difference_type = typename std::iterator_traits<I>::difference_type; using value_type = ValueType; using reference = ValueType; using pointer = typename std::iterator_traits<I>::pointer; using iterator_category = typename std::iterator_traits<I>::iterator_category; to_container_iterator() = default; template<typename OtherIt> to_container_iterator(OtherIt it) : it_(std::move(it)) {} friend bool operator==(to_container_iterator const & a, to_container_iterator const & b) { return a.it_ == b.it_; } friend bool operator!=(to_container_iterator const & a, to_container_iterator const & b) { return !(a == b); } reference operator*() const { return to_container::fn<meta::id<ValueType>>{}(*it_); } to_container_iterator & operator++() { ++it_; return *this; } to_container_iterator operator++(int) { auto tmp = *this; ++it_; return tmp; } CPP_member auto operator--() // -> CPP_ret(to_container_iterator &)( requires derived_from<iterator_category, std::bidirectional_iterator_tag>) { --it_; return *this; } CPP_member auto operator--(int) // -> CPP_ret(to_container_iterator &)( requires derived_from<iterator_category, std::bidirectional_iterator_tag>) { auto tmp = *this; ++it_; return tmp; } CPP_member auto operator+=(difference_type n) // -> CPP_ret(to_container_iterator &)( requires derived_from<iterator_category, std::random_access_iterator_tag>) { it_ += n; return *this; } CPP_member auto operator-=(difference_type n) // -> CPP_ret(to_container_iterator &)( requires derived_from<iterator_category, std::random_access_iterator_tag>) { it_ -= n; return *this; } CPP_broken_friend_member friend auto operator+(to_container_iterator i, difference_type n) // -> CPP_broken_friend_ret(to_container_iterator)( requires derived_from<iterator_category, std::random_access_iterator_tag>) { return i += n; } CPP_broken_friend_member friend auto operator-(to_container_iterator i, difference_type n) // -> CPP_broken_friend_ret(to_container_iterator)( requires derived_from<iterator_category, std::random_access_iterator_tag>) { return i -= n; } CPP_broken_friend_member friend auto operator-(difference_type n, to_container_iterator i) // -> CPP_broken_friend_ret(to_container_iterator)( requires derived_from<iterator_category, std::random_access_iterator_tag>) { return i -= n; } CPP_broken_friend_member friend auto operator-(to_container_iterator const & i, to_container_iterator const & j) // -> CPP_broken_friend_ret(difference_type)( requires derived_from<iterator_category, std::random_access_iterator_tag>) { return i.it_ - j.it_; } CPP_member auto operator[](difference_type n) const // -> CPP_ret(reference)( requires derived_from<iterator_category, std::random_access_iterator_tag>) { return *(*this + n); } }; template<typename Rng, typename Cont> using to_container_iterator_t = enable_if_t<(bool)range<Rng>, to_container_iterator<Rng, Cont>>; // clang-format off /// \concept range_and_not_view_ /// \brief The \c range_and_not_view_ concept template(typename Rng)( concept (range_and_not_view_)(Rng), range<Rng> AND (!view_<Rng>)); /// \concept range_and_not_view /// \brief The \c range_and_not_view concept template<typename Rng> CPP_concept range_and_not_view = CPP_concept_ref(range_and_not_view_, Rng); /// \concept convertible_to_cont_impl_ /// \brief The \c convertible_to_cont_impl_ concept template(typename Rng, typename Cont)( concept (convertible_to_cont_impl_)(Rng, Cont), constructible_from<range_value_t<Cont>, range_reference_t<Rng>> AND constructible_from< Cont, range_cpp17_iterator_t<Rng>, range_cpp17_iterator_t<Rng>> ); /// \concept convertible_to_cont /// \brief The \c convertible_to_cont concept template<typename Rng, typename Cont> CPP_concept convertible_to_cont = // range_and_not_view<Cont> && // move_constructible<Cont> && // CPP_concept_ref(detail::convertible_to_cont_impl_, Rng, Cont); /// \concept convertible_to_cont_cont_impl_ /// \brief The \c convertible_to_cont_cont_impl_ concept template(typename Rng, typename Cont)( concept (convertible_to_cont_cont_impl_)(Rng, Cont), range_and_not_view<range_value_t<Cont>> AND // Test that each element of the input range can be ranges::to<> // to the output container. invocable< to_container::fn<meta::id<range_value_t<Cont>>>, range_reference_t<Rng>> AND constructible_from< Cont, to_container_iterator_t<Rng, Cont>, to_container_iterator_t<Rng, Cont>> ); /// \concept convertible_to_cont_cont /// \brief The \c convertible_to_cont_cont concept template<typename Rng, typename Cont> CPP_concept convertible_to_cont_cont = // range<Cont> && // (!view_<Cont>) && // move_constructible<Cont> && // CPP_concept_ref(detail::convertible_to_cont_cont_impl_, Rng, Cont); /// \concept to_container_reserve /// \brief The \c to_container_reserve concept template<typename C, typename I, typename R> CPP_concept to_container_reserve = // reservable_with_assign<C, I> && // sized_range<R>; template<typename MetaFn, typename Rng> using container_t = meta::invoke<MetaFn, Rng>; // clang-format on struct RANGES_STRUCT_WITH_ADL_BARRIER(to_container_closure_base) { // clang-format off template(typename Rng, typename MetaFn, typename Fn)( requires input_range<Rng> AND convertible_to_cont<Rng, container_t<MetaFn, Rng>>) friend constexpr auto operator|(Rng && rng, to_container::closure<MetaFn, Fn> fn) { return static_cast<Fn &&>(fn)(static_cast<Rng &&>(rng)); } template(typename Rng, typename MetaFn, typename Fn)( requires input_range<Rng> AND (!convertible_to_cont<Rng, container_t<MetaFn, Rng>>) AND convertible_to_cont_cont<Rng, container_t<MetaFn, Rng>>) friend constexpr auto operator|(Rng && rng, to_container::closure<MetaFn, Fn> fn) { return static_cast<Fn &&>(fn)(static_cast<Rng &&>(rng)); } template<typename MetaFn, typename Fn, typename Pipeable> friend constexpr auto operator|(to_container::closure<MetaFn, Fn> sh, Pipeable pipe) -> CPP_broken_friend_ret( to_container::closure<MetaFn, composed<Pipeable, Fn>>)( requires is_pipeable_v<Pipeable>) { return to_container::closure<MetaFn, composed<Pipeable, Fn>>{ compose(static_cast<Pipeable &&>(pipe), static_cast<Fn &&>(sh))}; } }; template<typename MetaFn, typename Fn> struct to_container::closure : to_container_closure_base , Fn { closure() = default; constexpr explicit closure(Fn fn) : Fn(static_cast<Fn &&>(fn)) {} }; template<typename MetaFn> struct to_container::fn { private: template<typename Cont, typename I, typename Rng> static Cont impl(Rng && rng, std::false_type) { return Cont(I{ranges::begin(rng)}, I{ranges::end(rng)}); } template<typename Cont, typename I, typename Rng> static auto impl(Rng && rng, std::true_type) { Cont c; auto const rng_size = ranges::size(rng); using size_type = decltype(c.max_size()); using C = common_type_t<range_size_t<Rng>, size_type>; RANGES_EXPECT(static_cast<C>(rng_size) <= static_cast<C>(c.max_size())); c.reserve(static_cast<size_type>(rng_size)); c.assign(I{ranges::begin(rng)}, I{ranges::end(rng)}); return c; } public: template(typename Rng)( requires input_range<Rng> AND convertible_to_cont<Rng, container_t<MetaFn, Rng>>) container_t<MetaFn, Rng> operator()(Rng && rng) const { static_assert(!is_infinite<Rng>::value, "Attempt to convert an infinite range to a container."); using cont_t = container_t<MetaFn, Rng>; using iter_t = range_cpp17_iterator_t<Rng>; using use_reserve_t = meta::bool_<(bool)to_container_reserve<cont_t, iter_t, Rng>>; return impl<cont_t, iter_t>(static_cast<Rng &&>(rng), use_reserve_t{}); } template(typename Rng)( requires input_range<Rng> AND (!convertible_to_cont<Rng, container_t<MetaFn, Rng>>) AND convertible_to_cont_cont<Rng, container_t<MetaFn, Rng>>) container_t<MetaFn, Rng> operator()(Rng && rng) const { static_assert(!is_infinite<Rng>::value, "Attempt to convert an infinite range to a container."); using cont_t = container_t<MetaFn, Rng>; using iter_t = to_container_iterator<Rng, cont_t>; using use_reserve_t = meta::bool_<(bool)to_container_reserve<cont_t, iter_t, Rng>>; return impl<cont_t, iter_t>(static_cast<Rng &&>(rng), use_reserve_t{}); } }; template<typename MetaFn, typename Fn> using to_container_closure = to_container::closure<MetaFn, Fn>; template<typename MetaFn> using to_container_fn = to_container_closure<MetaFn, to_container::fn<MetaFn>>; template<template<typename...> class ContT> struct from_range { #if RANGES_CXX_DEDUCTION_GUIDES >= RANGES_CXX_DEDUCTION_GUIDES_17 // Attempt to use a deduction guide first... template<typename Rng> static auto from_rng_(int) // -> decltype(ContT(range_cpp17_iterator_t<Rng>{}, range_cpp17_iterator_t<Rng>{})); // No deduction guide. Fallback to instantiating with the // iterator's value type. template<typename Rng> static auto from_rng_(long) // -> meta::invoke<meta::quote<ContT>, range_value_t<Rng>>; template<typename Rng> using invoke = decltype(from_range::from_rng_<Rng>(0)); #else template<typename Rng> using invoke = meta::invoke<meta::quote<ContT>, range_value_t<Rng>>; #endif }; } // namespace detail /// \endcond /// \addtogroup group-range /// @{ /// \ingroup group-range RANGES_INLINE_VARIABLE(detail::to_container_fn<detail::from_range<std::vector>>, to_vector) /// \cond namespace _to_ { /// \endcond /// \brief For initializing a container of the specified type with the elements of /// an Range template<template<typename...> class ContT> auto to(RANGES_HIDDEN_DETAIL(detail::to_container = {})) -> detail::to_container_fn<detail::from_range<ContT>> { return {}; } /// \overload template(template<typename...> class ContT, typename Rng, typename C = meta::invoke<detail::from_range<ContT>, Rng>)( requires range<Rng> AND detail::convertible_to_cont<Rng, C>) auto to(Rng && rng) -> C { return detail::to_container_fn<detail::from_range<ContT>>{}( static_cast<Rng &&>(rng)); } /// \overload template<typename Cont> auto to(RANGES_HIDDEN_DETAIL(detail::to_container = {})) -> detail::to_container_fn<meta::id<Cont>> { return {}; } /// \overload template(typename Cont, typename Rng)( requires range<Rng> AND detail::convertible_to_cont<Rng, Cont>) auto to(Rng && rng) -> Cont { return detail::to_container_fn<meta::id<Cont>>{}(static_cast<Rng &&>(rng)); } /// \overload template(typename Cont, typename Rng)( requires input_range<Rng> AND (!detail::convertible_to_cont<Rng, Cont>) AND detail::convertible_to_cont_cont<Rng, Cont>) auto to(Rng && rng) -> Cont { return detail::to_container_fn<meta::id<Cont>>{}(static_cast<Rng &&>(rng)); } /// \cond // Slightly odd initializer_list overloads, undocumented for now. template(template<typename...> class ContT, typename T)( requires detail::convertible_to_cont<std::initializer_list<T>, ContT<T>>) auto to(std::initializer_list<T> il) -> ContT<T> { return detail::to_container_fn<detail::from_range<ContT>>{}(il); } template(typename Cont, typename T)( requires detail::convertible_to_cont<std::initializer_list<T>, Cont>) auto to(std::initializer_list<T> il) -> Cont { return detail::to_container_fn<meta::id<Cont>>{}(il); } /// \endcond /// \cond } // namespace _to_ using namespace _to_; /// \endcond /// @} //////////////////////////////////////////////////////////////////////////// /// \cond namespace _to_ { // The old name "ranges::to_" is now deprecated: template<template<typename...> class ContT> RANGES_DEPRECATED("Please use ranges::to (no underscore) instead.") detail::to_container_fn<detail::from_range<ContT>> to_(detail::to_container = {}) { return {}; } template(template<typename...> class ContT, typename Rng)( requires range<Rng> AND detail::convertible_to_cont<Rng, ContT<range_value_t<Rng>>>) RANGES_DEPRECATED("Please use ranges::to (no underscore) instead.") ContT<range_value_t<Rng>> to_(Rng && rng) { return static_cast<Rng &&>(rng) | ranges::to_<ContT>(); } template(template<typename...> class ContT, typename T)( requires detail::convertible_to_cont<std::initializer_list<T>, ContT<T>>) RANGES_DEPRECATED("Please use ranges::to (no underscore) instead.") ContT<T> to_(std::initializer_list<T> il) { return il | ranges::to_<ContT>(); } template<typename Cont> RANGES_DEPRECATED("Please use ranges::to (no underscore) instead.") detail::to_container_fn<meta::id<Cont>> to_(detail::to_container = {}) { return {}; } template(typename Cont, typename Rng)( requires range<Rng> AND detail::convertible_to_cont<Rng, Cont>) RANGES_DEPRECATED("Please use ranges::to (no underscore) instead.") Cont to_(Rng && rng) { return static_cast<Rng &&>(rng) | ranges::to_<Cont>(); } template(typename Cont, typename T)( requires detail::convertible_to_cont<std::initializer_list<T>, Cont>) RANGES_DEPRECATED("Please use ranges::to (no underscore) instead.") Cont to_(std::initializer_list<T> list) { return list | ranges::to_<Cont>(); } } // namespace _to_ /// \endcond template<typename MetaFn, typename Fn> RANGES_INLINE_VAR constexpr bool is_pipeable_v<detail::to_container_closure<MetaFn, Fn>> = true; } // namespace ranges #include <range/v3/detail/epilogue.hpp> #endif
0
repos/range-v3/include/range/v3
repos/range-v3/include/range/v3/range/operations.hpp
/// \file // Range v3 library // // Copyright Eric Niebler 2014-present // Copyright Gonzalo Brito Gadeschi 2017 // // Use, modification and distribution is subject to the // Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) // // Project home: https://github.com/ericniebler/range-v3 // #ifndef RANGES_V3_RANGE_OPERATIONS_HPP #define RANGES_V3_RANGE_OPERATIONS_HPP #include <stdexcept> #include <range/v3/range_fwd.hpp> #include <range/v3/iterator/operations.hpp> #include <range/v3/range/access.hpp> #include <range/v3/range/concepts.hpp> #include <range/v3/range/traits.hpp> #include <range/v3/utility/static_const.hpp> #include <range/v3/detail/prologue.hpp> namespace ranges { /// Checked indexed range access. /// /// \ingroup group-range struct at_fn { /// \return `begin(rng)[n]` template(typename Rng)( requires random_access_range<Rng> AND sized_range<Rng> AND borrowed_range<Rng>) constexpr range_reference_t<Rng> // operator()(Rng && rng, range_difference_t<Rng> n) const { // Workaround https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67371 in GCC 5 check_throw(rng, n); return ranges::begin(rng)[n]; } private: template<typename Rng> static constexpr void check_throw(Rng && rng, range_difference_t<Rng> n) { (n < 0 || n >= ranges::distance(rng)) ? throw std::out_of_range("ranges::at") : void(0); } }; /// Checked indexed range access. /// /// \ingroup group-range /// \sa `at_fn` RANGES_INLINE_VARIABLE(at_fn, at) /// Unchecked indexed range access. /// /// \ingroup group-range struct index_fn { /// \return `begin(rng)[n]` template(typename Rng, typename Int)( requires random_access_range<Rng> AND integral<Int> AND borrowed_range<Rng>) constexpr range_reference_t<Rng> operator()(Rng && rng, Int n) const // { using D = range_difference_t<Rng>; RANGES_EXPECT(0 <= static_cast<D>(n)); RANGES_EXPECT(!(bool)sized_range<Rng> || static_cast<D>(n) < ranges::distance(rng)); return ranges::begin(rng)[static_cast<D>(n)]; } }; /// Unchecked indexed range access. /// /// \ingroup group-range /// \sa `index_fn` RANGES_INLINE_VARIABLE(index_fn, index) /// \ingroup group-range struct back_fn { /// \return `*prev(end(rng))` template(typename Rng)( requires common_range<Rng> AND bidirectional_range<Rng> AND borrowed_range<Rng>) constexpr range_reference_t<Rng> operator()(Rng && rng) const { return *prev(end(rng)); } }; /// \ingroup group-range /// \sa `back_fn` RANGES_INLINE_VARIABLE(back_fn, back) /// \ingroup group-range struct front_fn { /// \return `*begin(rng)` template(typename Rng)( requires forward_range<Rng> AND borrowed_range<Rng>) constexpr range_reference_t<Rng> operator()(Rng && rng) const { return *begin(rng); } }; /// \ingroup group-range /// \sa `front_fn` RANGES_INLINE_VARIABLE(front_fn, front) } // namespace ranges #include <range/v3/detail/epilogue.hpp> #endif
0
repos/range-v3/include/range/v3
repos/range-v3/include/range/v3/range/dangling.hpp
/// \file // Range v3 library // // Copyright Eric Niebler 2013-present // // Use, modification and distribution is subject to the // Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) // // Project home: https://github.com/ericniebler/range-v3 // #ifndef RANGES_V3_RANGE_DANGLING_HPP #define RANGES_V3_RANGE_DANGLING_HPP #include <utility> #include <concepts/concepts.hpp> #include <range/v3/range_fwd.hpp> #include <range/v3/range/access.hpp> #include <range/v3/range/concepts.hpp> #include <range/v3/utility/static_const.hpp> #include <range/v3/detail/prologue.hpp> namespace ranges { /// \ingroup group-range /// A placeholder for an iterator or a sentinel into a range that may /// no longer be valid. struct dangling { dangling() = default; /// Implicit converting constructor; ignores argument template(typename T)( requires not_same_as_<T, dangling>) constexpr dangling(T &&) {} }; /// \cond namespace detail { template(class R, class U)( requires range<R>) using maybe_dangling_ = // meta::conditional_t<detail::_borrowed_range<R>, U, dangling>; } /// \endcond template<typename Rng> using borrowed_iterator_t = detail::maybe_dangling_<Rng, iterator_t<Rng>>; template<typename Rng> using safe_iterator_t RANGES_DEPRECATED( "Please use ranges::borrowed_iterator_t instead.") = borrowed_iterator_t<Rng>; /// \cond struct _sanitize_fn { template<typename T> constexpr T && operator()(T && t) const noexcept { return static_cast<T &&>(t); } }; using sanitize_fn RANGES_DEPRECATED( "The sanitize function is unneeded and deprecated.") = _sanitize_fn; namespace { RANGES_DEPRECATED("The sanitize function is unneeded and deprecated.") constexpr auto & sanitize = static_const<_sanitize_fn>::value; } // namespace /// \endcond namespace cpp20 { using ranges::dangling; using ranges::borrowed_iterator_t; template<typename Rng> using safe_iterator_t RANGES_DEPRECATED( "Please use ranges::borrowed_iterator_t instead.") = borrowed_iterator_t<Rng>; } // namespace cpp20 } // namespace ranges #include <range/v3/detail/epilogue.hpp> #endif
0
repos/range-v3/include/range/v3
repos/range-v3/include/range/v3/range/primitives.hpp
/// \file // Range v3 library // // Copyright Eric Niebler 2014-present // // Use, modification and distribution is subject to the // Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) // // Project home: https://github.com/ericniebler/range-v3 // #ifndef RANGES_V3_RANGE_PRIMITIVES_HPP #define RANGES_V3_RANGE_PRIMITIVES_HPP #include <concepts/concepts.hpp> #include <range/v3/range_fwd.hpp> #include <range/v3/iterator/concepts.hpp> #include <range/v3/range/access.hpp> #include <range/v3/utility/addressof.hpp> #include <range/v3/utility/static_const.hpp> #include <range/v3/detail/prologue.hpp> namespace ranges { /// \addtogroup group-range // Specialize this if the default is wrong. template<typename T> RANGES_INLINE_VAR constexpr bool disable_sized_range = false; /// \cond namespace _size_ { template<typename T> void size(T &&) = delete; #ifdef RANGES_WORKAROUND_MSVC_895622 void size(); #endif // clang-format off /// \concept has_member_size_ /// \brief The \c has_member_size_ concept template<typename T> CPP_requires(has_member_size_, requires(T && t) // ( ((T &&) t).size() )); /// \concept has_member_size /// \brief The \c has_member_size concept template<typename T> CPP_concept has_member_size = CPP_requires_ref(_size_::has_member_size_, T); /// \concept has_non_member_size_ /// \brief The \c has_non_member_size_ concept template<typename T> CPP_requires(has_non_member_size_, requires(T && t) // ( size((T &&) t) )); /// \concept has_non_member_size /// \brief The \c has_non_member_size concept template<typename T> CPP_concept has_non_member_size = CPP_requires_ref(_size_::has_non_member_size_, T); // clang-format on struct fn { private: struct _member_result_ { template<typename R> using invoke = decltype(+(declval(R &).size())); }; struct _non_member_result_ { template<typename R> using invoke = decltype(+(size(declval(R &)))); }; struct _distance_result_ { template<typename R> using invoke = detail::iter_size_t<_begin_::_t<R>>; }; struct _other_result_ { template<typename R> using invoke = meta::invoke< meta::conditional_t< has_non_member_size<R>, _non_member_result_, _distance_result_>, R>; }; template<typename R> using _result_t = meta::invoke< meta::conditional_t< has_member_size<R>, _member_result_, _other_result_>, R>; public: template<typename R, std::size_t N> constexpr std::size_t operator()(R (&)[N], int) const noexcept { return N; } template<typename R, std::size_t N> constexpr std::size_t operator()(R(&&)[N]) const noexcept { return N; } // Prefer member if it returns integral. template(typename R)( requires (!disable_sized_range<uncvref_t<R>>) AND has_member_size<R> AND detail::integer_like_<_result_t<R>>) constexpr _result_t<R> operator()(R && r) const noexcept(noexcept(((R &&) r).size())) { return ((R &&) r).size(); } // Use ADL if it returns integral. template(typename R)( requires (!disable_sized_range<uncvref_t<R>>) AND (!has_member_size<R>) AND has_non_member_size<R> AND detail::integer_like_<_result_t<R>>) constexpr _result_t<R> operator()(R && r) const noexcept(noexcept(size((R &&) r))) { return size((R &&) r); } template(typename R)( requires (!has_member_size<R> || disable_sized_range<uncvref_t<R>>) AND (!has_non_member_size<R> || disable_sized_range<uncvref_t<R>>) AND forward_iterator<_begin_::_t<R>> AND sized_sentinel_for<_end_::_t<R>, _begin_::_t<R>>) constexpr _result_t<R> operator()(R && r) const noexcept(noexcept(ranges::end((R &&) r) - ranges::begin((R &&) r))) { using size_type = detail::iter_size_t<_begin_::_t<R>>; return static_cast<size_type>(ranges::end((R &&) r) - ranges::begin((R &&) r)); } }; } // namespace _size_ /// \endcond /// \ingroup group-range /// \return For a given expression `E` of type `T`, `ranges::size(E)` is equivalent /// to: /// * `+extent_v<T>` if `T` is an array type. /// * Otherwise, `+E.size()` if it is a valid expression and its type `I` models /// `integral` and `disable_sized_range<std::remove_cvref_t<T>>` is false. /// * Otherwise, `+size(E)` if it is a valid expression and its type `I` models /// `integral` with overload resolution performed in a context that includes the /// declaration: /// \code /// template<class T> void size(T&&) = delete; /// \endcode /// and does not include a declaration of `ranges::size`, and /// `disable_sized_range<std::remove_cvref_t<T>>` is false. /// * Otherwise, `static_cast<U>(ranges::end(E) - ranges::begin(E))` where `U` is /// `std::make_unsigned_t<iter_difference_t<iterator_t<T>>>` if /// `iter_difference_t<iterator_t<T>>` satisfies `integral` and /// `iter_difference_t<iterator_t<T>>` otherwise; except that `E` is /// evaluated once, if it is a valid expression and the types `I` and `S` of /// `ranges::begin(E)` and `ranges::end(E)` model `sized_sentinel_for<S, I>` and /// `forward_iterator<I>`. /// * Otherwise, `ranges::size(E)` is ill-formed. RANGES_DEFINE_CPO(_size_::fn, size) // Customization point data /// \cond namespace _data_ { // clang-format off /// \concept has_member_data_ /// \brief The \c has_member_data_ concept template<typename T> CPP_requires(has_member_data_, requires(T & t) // ( t.data() )); /// \concept has_member_data /// \brief The \c has_member_data concept template<typename T> CPP_concept has_member_data = CPP_requires_ref(_data_::has_member_data_, T); // clang-format on struct fn { private: struct _member_data_ { template<typename R> using invoke = decltype(+(declval(R &&).data())); }; struct _pointer_iterator_ { template<typename R> using invoke = _begin_::_t<R>; }; struct _contiguous_iterator_ { template<typename R> using invoke = decltype(detail::addressof(*declval(_begin_::_t<R> &&))); }; struct _other_result_ { template<typename R> using invoke = meta::invoke< meta::conditional_t< std::is_pointer<_begin_::_t<R>>::value, _pointer_iterator_, _contiguous_iterator_>, R>; }; template<typename R> using _result_t = meta::invoke< meta::conditional_t< has_member_data<R>, _member_data_, _other_result_>, R>; public: template(typename R)( requires has_member_data<R &> AND std::is_pointer<_result_t<R &>>::value) constexpr _result_t<R &> operator()(R & r) const // noexcept(noexcept(r.data())) { return r.data(); } template(typename R)( requires (!has_member_data<R &>) AND std::is_pointer<_begin_::_t<R>>::value) constexpr _result_t<R> operator()(R && r) const // noexcept(noexcept(ranges::begin((R &&) r))) { return ranges::begin((R &&) r); } template(typename R)( requires (!has_member_data<R &>) AND (!std::is_pointer<_begin_::_t<R>>::value) AND contiguous_iterator<_begin_::_t<R>>) constexpr _result_t<R> operator()(R && r) const // noexcept(noexcept( ranges::begin((R &&) r) == ranges::end((R &&) r) ? nullptr : detail::addressof(*ranges::begin((R &&) r)))) { return ranges::begin((R &&) r) == ranges::end((R &&) r) ? nullptr : detail::addressof(*ranges::begin((R &&) r)); } #if RANGES_CXX_STD <= RANGES_CXX_STD_14 template<typename charT, typename Traits, typename Alloc> constexpr charT * operator()( std::basic_string<charT, Traits, Alloc> & s) const noexcept { // string doesn't have non-const data before C++17 return const_cast<charT *>(detail::as_const(s).data()); } #endif }; template<typename R> using _t = decltype(fn{}(declval(R &&))); } // namespace _data_ /// \endcond RANGES_INLINE_VARIABLE(_data_::fn, data) /// \cond namespace _cdata_ { struct fn { template<typename R> constexpr _data_::_t<R const &> operator()(R const & r) const noexcept(noexcept(ranges::data(r))) { return ranges::data(r); } template<typename R> constexpr _data_::_t<R const> operator()(R const && r) const noexcept(noexcept(ranges::data((R const &&)r))) { return ranges::data((R const &&)r); } }; } // namespace _cdata_ /// \endcond /// \ingroup group-range /// \param r /// \return The result of calling `ranges::data` with a const-qualified /// (lvalue or rvalue) reference to `r`. RANGES_INLINE_VARIABLE(_cdata_::fn, cdata) /// \cond namespace _empty_ { // clang-format off /// \concept has_member_empty_ /// \brief The \c has_member_empty_ concept template<typename T> CPP_requires(has_member_empty_, requires(T && t) // ( bool(((T &&) t).empty()) )); /// \concept has_member_empty /// \brief The \c has_member_empty concept template<typename T> CPP_concept has_member_empty = CPP_requires_ref(_empty_::has_member_empty_, T); /// \concept has_size_ /// \brief The \c has_size_ concept template<typename T> CPP_requires(has_size_, requires(T && t) // ( ranges::size((T &&) t) )); /// \concept has_size /// \brief The \c has_size concept template<typename T> CPP_concept has_size = CPP_requires_ref(_empty_::has_size_, T); // clang-format on struct fn { // Prefer member if it is valid. template(typename R)( requires has_member_empty<R>) constexpr bool operator()(R && r) const noexcept(noexcept(bool(((R &&) r).empty()))) { return bool(((R &&) r).empty()); } // Fall back to size == 0. template(typename R)( requires (!has_member_empty<R>) AND has_size<R>) constexpr bool operator()(R && r) const noexcept(noexcept(bool(ranges::size((R &&) r) == 0))) { return bool(ranges::size((R &&) r) == 0); } // Fall further back to begin == end. template(typename R)( requires (!has_member_empty<R>) AND (!has_size<R>) AND forward_iterator<_begin_::_t<R>>) constexpr bool operator()(R && r) const noexcept(noexcept(bool(ranges::begin((R &&) r) == ranges::end((R &&) r)))) { return bool(ranges::begin((R &&) r) == ranges::end((R &&) r)); } }; } // namespace _empty_ /// \endcond /// \ingroup group-range /// \return true if and only if range contains no elements. RANGES_INLINE_VARIABLE(_empty_::fn, empty) namespace cpp20 { // Specialize this is namespace ranges:: using ranges::cdata; using ranges::data; using ranges::disable_sized_range; using ranges::empty; using ranges::size; } // namespace cpp20 } // namespace ranges #include <range/v3/detail/epilogue.hpp> #endif
0
repos/range-v3/include/range/v3
repos/range-v3/include/range/v3/utility/random.hpp
/// \file // Range v3 library // // Copyright Casey Carter 2016 // // Use, modification and distribution is subject to the // Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) // // Project home: https://github.com/ericniebler/range-v3 // /* * Random-Number Utilities (randutil) * Addresses common issues with C++11 random number generation. * Makes good seeding easier, and makes using RNGs easy while retaining * all the power. * * The MIT License (MIT) * * Copyright (c) 2015 Melissa E. O'Neill * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ #ifndef RANGES_V3_UTILITY_RANDOM_HPP #define RANGES_V3_UTILITY_RANDOM_HPP #include <array> #include <cstddef> #include <cstdint> #include <initializer_list> #include <new> #include <random> #include <meta/meta.hpp> #include <concepts/concepts.hpp> #include <range/v3/range_fwd.hpp> #include <range/v3/algorithm/copy.hpp> #include <range/v3/algorithm/generate.hpp> #include <range/v3/functional/invoke.hpp> #include <range/v3/functional/reference_wrapper.hpp> #include <range/v3/iterator/concepts.hpp> #if !RANGES_CXX_THREAD_LOCAL #include <mutex> #endif #include <range/v3/detail/prologue.hpp> RANGES_DIAGNOSTIC_PUSH RANGES_DIAGNOSTIC_IGNORE_CXX17_COMPAT namespace ranges { /// \addtogroup group-numerics /// @{ // clang-format off /// \concept uniform_random_bit_generator_ /// \brief The \c uniform_random_bit_generator_ concept template<typename Gen> CPP_requires(uniform_random_bit_generator_, requires() // ( Gen::min(), Gen::max() )); /// \concept uniform_random_bit_generator_ /// \brief The \c uniform_random_bit_generator_ concept template(typename Gen)( concept (uniform_random_bit_generator_)(Gen), unsigned_integral<invoke_result_t<Gen &>> AND same_as<invoke_result_t<Gen &>, decltype(Gen::min())> AND same_as<invoke_result_t<Gen &>, decltype(Gen::max())>); /// \concept uniform_random_bit_generator /// \brief The \c uniform_random_bit_generator concept template<typename Gen> CPP_concept uniform_random_bit_generator = invocable<Gen &> && CPP_requires_ref(ranges::uniform_random_bit_generator_, Gen) && CPP_concept_ref(ranges::uniform_random_bit_generator_, Gen); // clang-format on /// @} /// \cond namespace detail { namespace randutils { inline std::array<std::uint32_t, 8> get_entropy() { std::array<std::uint32_t, 8> seeds; // Hopefully high-quality entropy from random_device. #if defined(__GLIBCXX__) && defined(RANGES_WORKAROUND_VALGRIND_RDRAND) std::random_device rd{"/dev/urandom"}; #else std::random_device rd; #endif std::uniform_int_distribution<std::uint32_t> dist{}; ranges::generate(seeds, [&] { return dist(rd); }); return seeds; } template(typename I)( requires unsigned_integral<I>) constexpr I fast_exp(I x, I power, I result = I{1}) { return power == I{0} ? result : randutils::fast_exp( x * x, power >> 1, result * (power & I{1} ? x : 1)); } ////////////////////////////////////////////////////////////////////////////// // // seed_seq_fe // ////////////////////////////////////////////////////////////////////////////// /* * seed_seq_fe implements a fixed-entropy seed sequence; it conforms to all * the requirements of a Seed Sequence concept. * * seed_seq_fe<N> implements a seed sequence which seeds based on a store of * N * 32 bits of entropy. Typically, it would be initialized with N or more * integers. * * seed_seq_fe128 and seed_seq_fe256 are provided as convenience typedefs for * 128- and 256-bit entropy stores respectively. These variants outperform * std::seed_seq, while being better mixing the bits it is provided as * entropy. In almost all common use cases, they serve as better drop-in * replacements for seed_seq. * * Technical details * * Assuming it constructed with M seed integers as input, it exhibits the * following properties * * * Diffusion/Avalanche: A single-bit change in any of the M inputs has a * 50% chance of flipping every bit in the bitstream produced by generate. * Initializing the N-word entropy store with M words requires O(N * M) * time precisely because of the avalanche requirements. Once constructed, * calls to generate are linear in the number of words generated. * * * Bias freedom/Bijection: If M == N, the state of the entropy store is a * bijection from the M inputs (i.e., no states occur twice, none are * omitted). If M > N the number of times each state can occur is the same * (each state occurs 2**(32*(M-N)) times, where ** is the power function). * If M < N, some states cannot occur (bias) but no state occurs more * than once (it's impossible to avoid bias if M < N; ideally N should not * be chosen so that it is more than M). * * Likewise, the generate function has similar properties (with the entropy * store as the input data). If more outputs are requested than there is * entropy, some outputs cannot occur. For example, the Mersenne Twister * will request 624 outputs, to initialize its 19937-bit state, which is * much larger than a 128-bit or 256-bit entropy pool. But in practice, * limiting the Mersenne Twister to 2**128 possible initializations gives * us enough initializations to give a unique initialization to trillions * of computers for billions of years. If you really have 624 words of * *real* high-quality entropy you want to use, you probably don't need * an entropy mixer like this class at all. But if you *really* want to, * nothing is stopping you from creating a randutils::seed_seq_fe<624>. * * * As a consequence of the above properties, if all parts of the provided * seed data are kept constant except one, and the remaining part is varied * through K different states, K different output sequences will be * produced. * * * Also, because the amount of entropy stored is fixed, this class never * performs dynamic allocation and is free of the possibility of generating * an exception. * * Ideas used to implement this code include hashing, a simple PCG generator * based on an MCG base with an XorShift output function and permutation * functions on tuples. * * More detail at * http://www.pcg-random.org/posts/developing-a-seed_seq-alternative.html */ template<std::size_t count, typename IntRep = std::uint32_t> struct seed_seq_fe { public: CPP_assert(unsigned_integral<IntRep>); typedef IntRep result_type; private: static constexpr std::size_t mix_rounds = 1 + (count <= 2); static constexpr std::uint32_t INIT_A = 0x43b0d7e5; static constexpr std::uint32_t MULT_A = 0x931e8875; static constexpr std::uint32_t INIT_B = 0x8b51f9dd; static constexpr std::uint32_t MULT_B = 0x58f38ded; static constexpr std::uint32_t MIX_MULT_L = 0xca01f9dd; static constexpr std::uint32_t MIX_MULT_R = 0x4973f715; static constexpr std::uint32_t XSHIFT = sizeof(IntRep) * 8 / 2; std::array<IntRep, count> mixer_; template(typename I, typename S)( requires input_iterator<I> AND sentinel_for<S, I> AND convertible_to<iter_reference_t<I>, IntRep>) void mix_entropy(I first, S last) { auto hash_const = INIT_A; auto hash = [&](IntRep value) RANGES_INTENDED_MODULAR_ARITHMETIC { value ^= hash_const; hash_const *= MULT_A; value *= hash_const; value ^= value >> XSHIFT; return value; }; auto mix = [](IntRep x, IntRep y) RANGES_INTENDED_MODULAR_ARITHMETIC { IntRep result = MIX_MULT_L * x - MIX_MULT_R * y; result ^= result >> XSHIFT; return result; }; for(auto & elem : mixer_) { if(first != last) { elem = hash(static_cast<IntRep>(*first)); ++first; } else elem = hash(IntRep{0}); } for(auto & src : mixer_) for(auto & dest : mixer_) if(&src != &dest) dest = mix(dest, hash(src)); for(; first != last; ++first) for(auto & dest : mixer_) dest = mix(dest, hash(static_cast<IntRep>(*first))); } public: seed_seq_fe(const seed_seq_fe &) = delete; void operator=(const seed_seq_fe &) = delete; template(typename T)( requires convertible_to<T const &, IntRep>) seed_seq_fe(std::initializer_list<T> init) { seed(init.begin(), init.end()); } template(typename I, typename S)( requires input_iterator<I> AND sentinel_for<S, I> AND convertible_to<iter_reference_t<I>, IntRep>) seed_seq_fe(I first, S last) { seed(first, last); } // generating functions template(typename I, typename S)( requires random_access_iterator<I> AND sentinel_for<S, I>) RANGES_INTENDED_MODULAR_ARITHMETIC // void generate(I first, S const last) const { auto src_begin = mixer_.begin(); auto src_end = mixer_.end(); auto src = src_begin; auto hash_const = INIT_B; for(; first != last; ++first) { auto dataval = *src; if(++src == src_end) src = src_begin; dataval ^= hash_const; hash_const *= MULT_B; dataval *= hash_const; dataval ^= dataval >> XSHIFT; *first = dataval; } } constexpr std::size_t size() const { return count; } template(typename O)( requires weakly_incrementable<O> AND indirectly_copyable<decltype(mixer_.begin()), O>) RANGES_INTENDED_MODULAR_ARITHMETIC void param(O dest) const { constexpr IntRep INV_A = randutils::fast_exp(MULT_A, IntRep(-1)); constexpr IntRep MIX_INV_L = randutils::fast_exp(MIX_MULT_L, IntRep(-1)); auto mixer_copy = mixer_; for(std::size_t round = 0; round < mix_rounds; ++round) { // Advance to the final value. We'll backtrack from that. auto hash_const = INIT_A * randutils::fast_exp(MULT_A, IntRep(count * count)); for(auto src = mixer_copy.rbegin(); src != mixer_copy.rend(); ++src) for(auto rdest = mixer_copy.rbegin(); rdest != mixer_copy.rend(); ++rdest) if(src != rdest) { IntRep revhashed = *src; auto mult_const = hash_const; hash_const *= INV_A; revhashed ^= hash_const; revhashed *= mult_const; revhashed ^= revhashed >> XSHIFT; IntRep unmixed = *rdest; unmixed ^= unmixed >> XSHIFT; unmixed += MIX_MULT_R * revhashed; unmixed *= MIX_INV_L; *rdest = unmixed; } for(auto i = mixer_copy.rbegin(); i != mixer_copy.rend(); ++i) { IntRep unhashed = *i; unhashed ^= unhashed >> XSHIFT; unhashed *= randutils::fast_exp(hash_const, IntRep(-1)); hash_const *= INV_A; unhashed ^= hash_const; *i = unhashed; } } ranges::copy(mixer_copy, dest); } template(typename I, typename S)( requires input_iterator<I> AND sentinel_for<S, I> AND convertible_to<iter_reference_t<I>, IntRep>) void seed(I first, S last) { mix_entropy(first, last); // For very small sizes, we do some additional mixing. For normal // sizes, this loop never performs any iterations. for(std::size_t i = 1; i < mix_rounds; ++i) stir(); } seed_seq_fe & stir() { mix_entropy(mixer_.begin(), mixer_.end()); return *this; } }; using seed_seq_fe128 = seed_seq_fe<4, std::uint32_t>; using seed_seq_fe256 = seed_seq_fe<8, std::uint32_t>; ////////////////////////////////////////////////////////////////////////////// // // auto_seeded // ////////////////////////////////////////////////////////////////////////////// /* * randutils::auto_seeded * * Extends a seed sequence class with a nondeterministic default * constructor. Uses a variety of local sources of entropy to portably * initialize any seed sequence to a good default state. * * In normal use, it's accessed via one of the following type aliases, which * use seed_seq_fe128 and seed_seq_fe256 above. * * randutils::auto_seed_128 * randutils::auto_seed_256 * * It's discussed in detail at * http://www.pcg-random.org/posts/simple-portable-cpp-seed-entropy.html * and its motivation (why you can't just use std::random_device) here * http://www.pcg-random.org/posts/cpps-random_device.html */ template<typename SeedSeq> struct auto_seeded : public SeedSeq { auto_seeded() : auto_seeded(randutils::get_entropy()) {} template<std::size_t N> auto_seeded(std::array<std::uint32_t, N> const & seeds) : SeedSeq(seeds.begin(), seeds.end()) {} using SeedSeq::SeedSeq; const SeedSeq & base() const { return *this; } SeedSeq & base() { return *this; } }; using auto_seed_128 = auto_seeded<seed_seq_fe128>; using auto_seed_256 = auto_seeded<seed_seq_fe256>; } // namespace randutils using default_URNG = meta::if_c<(sizeof(void *) >= sizeof(long long)), std::mt19937_64, std::mt19937>; #if !RANGES_CXX_THREAD_LOCAL template<typename URNG> class sync_URNG : private URNG { mutable std::mutex mtx_; public: using URNG::URNG; sync_URNG() = default; using typename URNG::result_type; result_type operator()() { std::lock_guard<std::mutex> guard{mtx_}; return static_cast<URNG &>(*this)(); } using URNG::max; using URNG::min; }; using default_random_engine = sync_URNG<default_URNG>; #else using default_random_engine = default_URNG; #endif template<typename T = void> default_random_engine & get_random_engine() { using Seeder = meta::if_c<(sizeof(default_URNG) > 16), randutils::auto_seed_256, randutils::auto_seed_128>; #if RANGES_CXX_THREAD_LOCAL >= RANGES_CXX_THREAD_LOCAL_11 static thread_local default_random_engine engine{Seeder{}.base()}; #elif RANGES_CXX_THREAD_LOCAL static __thread bool initialized = false; static __thread meta::_t<std::aligned_storage<sizeof(default_random_engine), alignof(default_random_engine)>> storage; if(!initialized) { ::new(static_cast<void *>(&storage)) default_random_engine{Seeder{}.base()}; initialized = true; } auto & engine = reinterpret_cast<default_random_engine &>(storage); #else static default_random_engine engine{Seeder{}.base()}; #endif // RANGES_CXX_THREAD_LOCAL return engine; } } // namespace detail /// \endcond } // namespace ranges RANGES_DIAGNOSTIC_POP #include <range/v3/detail/epilogue.hpp> #endif
0
repos/range-v3/include/range/v3
repos/range-v3/include/range/v3/utility/semiregular_box.hpp
/// \file // Range v3 library // // Copyright Eric Niebler 2013-present // // Use, modification and distribution is subject to the // Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) // // Project home: https://github.com/ericniebler/range-v3 // #ifndef RANGES_V3_UTILITY_SEMIREGULAR_BOX_HPP #define RANGES_V3_UTILITY_SEMIREGULAR_BOX_HPP #include <type_traits> #include <utility> #include <meta/meta.hpp> #include <concepts/concepts.hpp> #include <range/v3/range_fwd.hpp> #include <range/v3/functional/concepts.hpp> #include <range/v3/functional/invoke.hpp> #include <range/v3/functional/reference_wrapper.hpp> #include <range/v3/utility/get.hpp> #include <range/v3/utility/in_place.hpp> #include <range/v3/detail/prologue.hpp> namespace ranges { /// \cond template<typename T> struct semiregular_box; namespace detail { struct semiregular_get { // clang-format off template<typename T> friend auto CPP_auto_fun(get)(meta::id_t<semiregular_box<T>> &t) ( return t.get() ) template<typename T> friend auto CPP_auto_fun(get)(meta::id_t<semiregular_box<T>> const &t) ( return t.get() ) template<typename T> friend auto CPP_auto_fun(get)(meta::id_t<semiregular_box<T>> &&t) ( return detail::move(t).get() ) // clang-format on }; } // namespace detail /// \endcond /// \addtogroup group-utility /// @{ template<typename T> struct semiregular_box : private detail::semiregular_get { private: struct tag {}; template<typename... Args> void construct_from(Args &&... args) { new((void *)std::addressof(data_)) T(static_cast<Args &&>(args)...); engaged_ = true; } void move_assign(T && t, std::true_type) { data_ = detail::move(t); } void move_assign(T && t, std::false_type) { reset(); construct_from(detail::move(t)); } void copy_assign(T const & t, std::true_type) { data_ = t; } void copy_assign(T && t, std::false_type) { reset(); construct_from(t); } constexpr semiregular_box(tag, std::false_type) noexcept {} constexpr semiregular_box(tag, std::true_type) noexcept( std::is_nothrow_default_constructible<T>::value) : data_{} , engaged_(true) {} void reset() { if(engaged_) { data_.~T(); engaged_ = false; } } union { char ch_{}; T data_; }; bool engaged_{false}; public: constexpr semiregular_box() noexcept( std::is_nothrow_default_constructible<T>::value || !std::is_default_constructible<T>::value) : semiregular_box(tag{}, std::is_default_constructible<T>{}) {} semiregular_box(semiregular_box && that) noexcept( std::is_nothrow_move_constructible<T>::value) { if(that.engaged_) this->construct_from(detail::move(that.data_)); } semiregular_box(semiregular_box const & that) noexcept( std::is_nothrow_copy_constructible<T>::value) { if(that.engaged_) this->construct_from(that.data_); } #if defined(__cpp_conditional_explicit) && 0 < __cpp_conditional_explicit template(typename U)( requires (!same_as<uncvref_t<U>, semiregular_box>) AND constructible_from<T, U>) explicit(!convertible_to<U, T>) constexpr semiregular_box(U && u) noexcept(std::is_nothrow_constructible<T, U>::value) : semiregular_box(in_place, static_cast<U &&>(u)) {} #else template(typename U)( requires (!same_as<uncvref_t<U>, semiregular_box>) AND constructible_from<T, U> AND (!convertible_to<U, T>)) // constexpr explicit semiregular_box(U && u) noexcept(std::is_nothrow_constructible<T, U>::value) : semiregular_box(in_place, static_cast<U &&>(u)) {} template(typename U)( requires (!same_as<uncvref_t<U>, semiregular_box>) AND constructible_from<T, U> AND convertible_to<U, T>) constexpr semiregular_box(U && u) noexcept(std::is_nothrow_constructible<T, U>::value) : semiregular_box(in_place, static_cast<U &&>(u)) {} #endif template(typename... Args)( requires constructible_from<T, Args...>) constexpr semiregular_box(in_place_t, Args &&... args) // noexcept(std::is_nothrow_constructible<T, Args...>::value) : data_(static_cast<Args &&>(args)...) , engaged_(true) {} ~semiregular_box() { reset(); } semiregular_box & operator=(semiregular_box && that) noexcept( std::is_nothrow_move_constructible<T>::value && (!std::is_move_assignable<T>::value || std::is_nothrow_move_assignable<T>::value)) { if(engaged_ && that.engaged_) this->move_assign(detail::move(that.data_), std::is_move_assignable<T>()); else if(that.engaged_) this->construct_from(detail::move(that.data_)); else if(engaged_) this->reset(); return *this; } semiregular_box & operator=(semiregular_box const & that) noexcept( std::is_nothrow_copy_constructible<T>::value && (!std::is_copy_assignable<T>::value || std::is_nothrow_copy_assignable<T>::value)) { if(engaged_ && that.engaged_) this->copy_assign(that.data_, std::is_copy_assignable<T>()); else if(that.engaged_) this->construct_from(that.data_); else if(engaged_) this->reset(); return *this; } constexpr T & get() & noexcept { return RANGES_ENSURE(engaged_), data_; } constexpr T const & get() const & noexcept { return RANGES_ENSURE(engaged_), data_; } constexpr T && get() && noexcept { return RANGES_ENSURE(engaged_), detail::move(data_); } T const && get() const && = delete; constexpr operator T &() & noexcept { return get(); } constexpr operator T const &() const & noexcept { return get(); } constexpr operator T &&() && noexcept { return detail::move(get()); } operator T const &&() const && = delete; // clang-format off template(typename... Args)( requires invocable<T &, Args...>) constexpr decltype(auto) operator()(Args &&... args) & noexcept(is_nothrow_invocable_v<T &, Args...>) { return invoke(data_, static_cast<Args &&>(args)...); } template(typename... Args)( requires invocable<T const &, Args...>) constexpr decltype(auto) operator()(Args &&... args) const & noexcept(is_nothrow_invocable_v<T const &, Args...>) { return invoke(data_, static_cast<Args &&>(args)...); } template(typename... Args)( requires invocable<T, Args...>) constexpr decltype(auto) operator()(Args &&... args) && noexcept(is_nothrow_invocable_v<T, Args...>) { return invoke(static_cast<T &&>(data_), static_cast<Args &&>(args)...); } template<typename... Args> void operator()(Args &&...) const && = delete; // clang-format on }; template<typename T> struct semiregular_box<T &> : private ranges::reference_wrapper<T &> , private detail::semiregular_get { semiregular_box() = default; template(typename Arg)( requires constructible_from<ranges::reference_wrapper<T &>, Arg &>) semiregular_box(in_place_t, Arg & arg) noexcept // : ranges::reference_wrapper<T &>(arg) {} using ranges::reference_wrapper<T &>::get; using ranges::reference_wrapper<T &>::operator T &; using ranges::reference_wrapper<T &>::operator(); #if defined(_MSC_VER) template(typename U)( requires (!same_as<uncvref_t<U>, semiregular_box>) AND constructible_from<ranges::reference_wrapper<T &>, U>) constexpr semiregular_box(U && u) noexcept( std::is_nothrow_constructible<ranges::reference_wrapper<T &>, U>::value) : ranges::reference_wrapper<T &>{static_cast<U &&>(u)} {} #else using ranges::reference_wrapper<T &>::reference_wrapper; #endif }; template<typename T> struct semiregular_box<T &&> : private ranges::reference_wrapper<T &&> , private detail::semiregular_get { semiregular_box() = default; template(typename Arg)( requires constructible_from<ranges::reference_wrapper<T &&>, Arg>) semiregular_box(in_place_t, Arg && arg) noexcept // : ranges::reference_wrapper<T &&>(static_cast<Arg &&>(arg)) {} using ranges::reference_wrapper<T &&>::get; using ranges::reference_wrapper<T &&>::operator T &&; using ranges::reference_wrapper<T &&>::operator(); #if defined(_MSC_VER) template(typename U)( requires (!same_as<uncvref_t<U>, semiregular_box>) AND constructible_from<ranges::reference_wrapper<T &&>, U>) constexpr semiregular_box(U && u) noexcept( std::is_nothrow_constructible<ranges::reference_wrapper<T &&>, U>::value) : ranges::reference_wrapper<T &&>{static_cast<U &&>(u)} {} #else using ranges::reference_wrapper<T &&>::reference_wrapper; #endif }; template<typename T> using semiregular_box_t = meta::if_c<(bool)semiregular<T>, T, semiregular_box<T>>; template<typename T, bool IsConst = false> using semiregular_box_ref_or_val_t = meta::if_c< (bool)semiregular<T>, meta::if_c<IsConst || std::is_empty<T>::value, T, reference_wrapper<T>>, reference_wrapper< meta::if_c<IsConst, semiregular_box<T> const, semiregular_box<T>>>>; /// @} /// \cond template<typename T> using semiregular_t RANGES_DEPRECATED("Please use semiregular_box_t instead.") = semiregular_box_t<T>; template<typename T, bool IsConst = false> using semiregular_ref_or_val_t RANGES_DEPRECATED( "Please use semiregular_box_ref_or_val_t instead.") = semiregular_box_ref_or_val_t<T, IsConst>; /// \endcond } // namespace ranges #include <range/v3/detail/epilogue.hpp> #endif
0
repos/range-v3/include/range/v3
repos/range-v3/include/range/v3/utility/any.hpp
/// \file // Range v3 library // // Copyright Eric Niebler 2015-present // // Use, modification and distribution is subject to the // Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) // // Project home: https://github.com/ericniebler/range-v3 // #ifndef RANGES_V3_UTILITY_ANY_HPP #define RANGES_V3_UTILITY_ANY_HPP #include <memory> #include <type_traits> #include <typeinfo> #include <meta/meta.hpp> #include <concepts/concepts.hpp> #include <range/v3/range_fwd.hpp> #include <range/v3/utility/swap.hpp> #include <range/v3/detail/prologue.hpp> RANGES_DIAGNOSTIC_PUSH RANGES_DIAGNOSTIC_IGNORE_DEPRECATED_DECLARATIONS namespace ranges { struct bad_any_cast : std::bad_cast { virtual const char * what() const noexcept override { return "bad any_cast"; } }; struct RANGES_DEPRECATED( "ranges::any will be going away in the not-too-distant future. " "We suggest you use std::any or boost::any instead (or simply steal " "this header and maintain it yourself).") any; template<typename T> meta::if_c<std::is_reference<T>() || copyable<T>, T> any_cast(any &); template<typename T> meta::if_c<std::is_reference<T>() || copyable<T>, T> any_cast(any const &); template<typename T> meta::if_c<std::is_reference<T>() || copyable<T>, T> any_cast(any &&); template<typename T> T * any_cast(any *) noexcept; template<typename T> T const * any_cast(any const *) noexcept; namespace _any_ { struct _base {}; struct interface { virtual ~interface() {} virtual interface * clone() const = 0; virtual std::type_info const & type() const noexcept = 0; }; template<typename T> struct impl final : interface { private: T obj; public: impl() = default; impl(T o) : obj(std::move(o)) {} T & get() { return obj; } T const & get() const { return obj; } impl * clone() const override { return new impl{obj}; } std::type_info const & type() const noexcept override { return typeid(T); } }; } // namespace _any_ struct any #if RANGES_BROKEN_CPO_LOOKUP : private _any_::_base #endif { private: template<typename T> friend meta::if_c<std::is_reference<T>() || (bool)copyable<T>, T> any_cast(any &); template<typename T> friend meta::if_c<std::is_reference<T>() || (bool)copyable<T>, T> any_cast( any const &); template<typename T> friend meta::if_c<std::is_reference<T>() || (bool)copyable<T>, T> any_cast( any &&); template<typename T> friend T * any_cast(any *) noexcept; template<typename T> friend T const * any_cast(any const *) noexcept; std::unique_ptr<_any_::interface> ptr_; public: any() noexcept = default; template(typename TRef, typename T = detail::decay_t<TRef>)( requires (!same_as<T, any>) AND copyable<T>) // any(TRef && t) : ptr_(new _any_::impl<T>(static_cast<TRef &&>(t))) {} any(any &&) noexcept = default; any(any const & that) : ptr_{that.ptr_ ? that.ptr_->clone() : nullptr} {} any & operator=(any &&) noexcept = default; any & operator=(any const & that) { ptr_.reset(that.ptr_ ? that.ptr_->clone() : nullptr); return *this; } template(typename TRef, typename T = detail::decay_t<TRef>)( requires (!same_as<T, any>) AND copyable<T>) // any & operator=(TRef && t) { any{static_cast<TRef &&>(t)}.swap(*this); return *this; } void clear() noexcept { ptr_.reset(); } bool empty() const noexcept { return !ptr_; } std::type_info const & type() const noexcept { return ptr_ ? ptr_->type() : typeid(void); } void swap(any & that) noexcept { ptr_.swap(that.ptr_); } #if !RANGES_BROKEN_CPO_LOOKUP friend void swap(any & x, any & y) noexcept { x.swap(y); } #endif }; #if RANGES_BROKEN_CPO_LOOKUP namespace _any_ { inline void swap(any & x, any & y) noexcept { x.swap(y); } } // namespace _any_ #endif /// \throw bad_any_cast template<typename T> meta::if_c<std::is_reference<T>() || copyable<T>, T> any_cast(any & x) { if(x.type() != typeid(detail::decay_t<T>)) throw bad_any_cast{}; return static_cast<_any_::impl<detail::decay_t<T>> *>(x.ptr_.get())->get(); } /// \overload template<typename T> meta::if_c<std::is_reference<T>() || copyable<T>, T> any_cast(any const & x) { if(x.type() != typeid(detail::decay_t<T>)) throw bad_any_cast{}; return static_cast<_any_::impl<detail::decay_t<T>> const *>(x.ptr_.get())->get(); } /// \overload template<typename T> meta::if_c<std::is_reference<T>() || copyable<T>, T> any_cast(any && x) { if(x.type() != typeid(detail::decay_t<T>)) throw bad_any_cast{}; return static_cast<_any_::impl<detail::decay_t<T>> *>(x.ptr_.get())->get(); } /// \overload template<typename T> T * any_cast(any * p) noexcept { if(p && p->ptr_) if(_any_::impl<T> * q = dynamic_cast<_any_::impl<T> *>(p->ptr_.get())) return &q->get(); return nullptr; } /// \overload template<typename T> T const * any_cast(any const * p) noexcept { if(p && p->ptr_) if(_any_::impl<T> const * q = dynamic_cast<_any_::impl<T> const *>(p->ptr_.get())) return &q->get(); return nullptr; } } // namespace ranges RANGES_DIAGNOSTIC_POP #include <range/v3/detail/epilogue.hpp> #endif
0
repos/range-v3/include/range/v3
repos/range-v3/include/range/v3/utility/memory.hpp
/// \file // Range v3 library // // Copyright Eric Niebler 2014-present // // Use, modification and distribution is subject to the // Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) // // Project home: https://github.com/ericniebler/range-v3 // //===-------------------------- algorithm ---------------------------------===// // // The LLVM Compiler Infrastructure // // This file is dual licensed under the MIT and the University of Illinois Open // Source Licenses. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// #ifndef RANGES_V3_UTILITY_MEMORY_HPP #define RANGES_V3_UTILITY_MEMORY_HPP #include <cstdint> #include <memory> #include <type_traits> #include <utility> #include <meta/meta.hpp> #include <range/v3/detail/config.hpp> #include <range/v3/iterator/concepts.hpp> #include <range/v3/iterator/traits.hpp> #include <range/v3/utility/polymorphic_cast.hpp> #include <range/v3/detail/prologue.hpp> namespace ranges { /// \cond namespace detail { template<typename T> std::pair<T *, std::ptrdiff_t> get_temporary_buffer_impl(std::size_t n) noexcept { if(n > PTRDIFF_MAX / sizeof(T)) n = PTRDIFF_MAX / sizeof(T); void * ptr = nullptr; for(; ptr == nullptr && n > 0; n /= 2) { #if RANGES_CXX_ALIGNED_NEW < RANGES_CXX_ALIGNED_NEW_17 static_assert(alignof(T) <= alignof(std::max_align_t), "Sorry: over-aligned types are supported only with C++17."); #else // RANGES_CXX_ALIGNED_NEW if(RANGES_CONSTEXPR_IF(alignof(T) > __STDCPP_DEFAULT_NEW_ALIGNMENT__)) ptr = ::operator new( sizeof(T) * n, std::align_val_t{alignof(T)}, std::nothrow); else #endif // RANGES_CXX_ALIGNED_NEW ptr = ::operator new(sizeof(T) * n, std::nothrow); } return {static_cast<T *>(ptr), static_cast<std::ptrdiff_t>(n)}; } template<typename T, typename D> std::pair<T *, std::ptrdiff_t> get_temporary_buffer(D count) noexcept { RANGES_EXPECT(count >= 0); return detail::get_temporary_buffer_impl<T>(static_cast<std::size_t>(count)); } struct return_temporary_buffer { template<typename T> void operator()(T * p) const { #if RANGES_CXX_ALIGNED_NEW < RANGES_CXX_ALIGNED_NEW_17 static_assert(alignof(T) <= alignof(std::max_align_t), "Sorry: over-aligned types are supported only with C++17."); #else // RANGES_CXX_ALIGNED_NEW if(RANGES_CONSTEXPR_IF(alignof(T) > __STDCPP_DEFAULT_NEW_ALIGNMENT__)) ::operator delete(p, std::align_val_t{alignof(T)}); else #endif // RANGES_CXX_ALIGNED_NEW ::operator delete(p); } }; template(typename T, typename... Args)( requires (!std::is_array<T>::value)) // std::unique_ptr<T> make_unique(Args &&... args) { return std::unique_ptr<T>{new T(static_cast<Args &&>(args)...)}; } } // namespace detail /// \endcond /// \addtogroup group-utility /// @{ template<typename O, typename Val> struct raw_storage_iterator { private: CPP_assert(output_iterator<O, Val>); CPP_assert(std::is_lvalue_reference<iter_reference_t<O>>()); O out_; public: using difference_type = iter_difference_t<O>; raw_storage_iterator() = default; explicit raw_storage_iterator(O out) : out_(std::move(out)) {} raw_storage_iterator & operator*() noexcept { return *this; } CPP_member auto operator=(Val const & val) // -> CPP_ret(raw_storage_iterator &)( requires copy_constructible<Val>) { ::new((void *)std::addressof(*out_)) Val(val); return *this; } CPP_member auto operator=(Val && val) // -> CPP_ret(raw_storage_iterator &)( requires move_constructible<Val>) { ::new((void *)std::addressof(*out_)) Val(std::move(val)); return *this; } raw_storage_iterator & operator++() { ++out_; return *this; } CPP_member auto operator++(int) // -> CPP_ret(void)( requires (!forward_iterator<O>)) { ++out_; } CPP_member auto operator++(int) // -> CPP_ret(raw_storage_iterator)( requires forward_iterator<O>) { auto tmp = *this; ++out_; return tmp; } O base() const { return out_; } }; template<typename I> struct iterator_wrapper { private: CPP_assert(input_or_output_iterator<I>); mutable I * i_ = nullptr; public: using difference_type = iter_difference_t<I>; iterator_wrapper() = default; iterator_wrapper(iterator_wrapper const & that) : i_(that.i_) { that.i_ = nullptr; } iterator_wrapper & operator=(iterator_wrapper const & that) { i_ = that.i_; that.i_ = nullptr; return *this; } iterator_wrapper(I & i) : i_(std::addressof(i)) {} // clang-format off auto CPP_auto_fun(operator*)()(const) ( return **i_ ) // clang-format on iterator_wrapper & operator++() { ++*i_; return *this; } void operator++(int) { ++*i_; } I base() const { return *i_; } }; template(typename I)( requires input_or_output_iterator<I>) iterator_wrapper<I> iter_ref(I & i) { return i; } template<typename I> struct indirectly_readable_traits<iterator_wrapper<I>> : meta::if_c<(bool)input_iterator<I>, indirectly_readable_traits<I>, meta::nil_> {}; template<typename Val> struct raw_buffer { private: Val * begin_; raw_storage_iterator<Val *, Val> rsi_; public: explicit raw_buffer(Val * first) : begin_(first) , rsi_(first) {} raw_buffer(raw_buffer &&) = default; raw_buffer(raw_buffer const &) = delete; ~raw_buffer() { for(; begin_ != rsi_.base(); ++begin_) begin_->~Val(); } iterator_wrapper<raw_storage_iterator<Val *, Val>> begin() { return ranges::iter_ref(rsi_); } }; template<typename Val> raw_buffer<Val> make_raw_buffer(Val * val) { return raw_buffer<Val>(val); } /// @} } // namespace ranges #include <range/v3/detail/epilogue.hpp> #endif
0
repos/range-v3/include/range/v3
repos/range-v3/include/range/v3/utility/infinity.hpp
// Range v3 library // // Copyright Eric Niebler 2014-present // // Use, modification and distribution is subject to the // Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) // // Project home: https://github.com/ericniebler/range-v3 // #ifndef RANGES_V3_UTILITY_INFINITY_HPP #define RANGES_V3_UTILITY_INFINITY_HPP #include <concepts/concepts.hpp> #include <range/v3/range_fwd.hpp> RANGES_DEPRECATED_HEADER( "This header is deprecated and will be removed from a future version of range-v3.") #include <range/v3/detail/prologue.hpp> namespace ranges { /// \cond struct infinity { friend constexpr bool operator==(infinity, infinity) { return true; } friend constexpr bool operator!=(infinity, infinity) { return false; } template<typename Integer> friend constexpr auto operator==(Integer, infinity) noexcept -> CPP_broken_friend_ret(bool)( requires integral<Integer>) { return false; } template<typename Integer> friend constexpr auto operator==(infinity, Integer) noexcept -> CPP_broken_friend_ret(bool)( requires integral<Integer>) { return false; } template<typename Integer> friend constexpr auto operator!=(Integer, infinity) noexcept -> CPP_broken_friend_ret(bool)( requires integral<Integer>) { return true; } template<typename Integer> friend constexpr auto operator!=(infinity, Integer) noexcept -> CPP_broken_friend_ret(bool)( requires integral<Integer>) { return true; } }; /// \endcond } // namespace ranges #include <range/v3/detail/epilogue.hpp> #endif
0
repos/range-v3/include/range/v3
repos/range-v3/include/range/v3/utility/common_iterator.hpp
// Range v3 library // // Copyright Eric Niebler 2014-present // Copyright Casey Carter 2016 // // Use, modification and distribution is subject to the // Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) // // Project home: https://github.com/ericniebler/range-v3 // #ifndef RANGES_V3_UTILITY_COMMON_ITERATOR_HPP #define RANGES_V3_UTILITY_COMMON_ITERATOR_HPP #include <range/v3/detail/config.hpp> RANGES_DEPRECATED_HEADER( "This header is deprecated. Please #include <range/v3/iterator/common_iterator.hpp> " "instead.") #include <range/v3/iterator/common_iterator.hpp> #endif
0
repos/range-v3/include/range/v3
repos/range-v3/include/range/v3/utility/move.hpp
/// \file // Range v3 library // // Copyright Eric Niebler 2013-present // // Use, modification and distribution is subject to the // Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) // // Project home: https://github.com/ericniebler/range-v3 // #ifndef RANGES_V3_UTILITY_MOVE_HPP #define RANGES_V3_UTILITY_MOVE_HPP #include <type_traits> #include <meta/meta.hpp> #include <range/v3/range_fwd.hpp> #include <range/v3/utility/static_const.hpp> #include <range/v3/detail/prologue.hpp> namespace ranges { namespace aux { /// \ingroup group-utility struct move_fn : move_tag { template<typename T> constexpr meta::_t<std::remove_reference<T>> && operator()(T && t) const // noexcept { return static_cast<meta::_t<std::remove_reference<T>> &&>(t); } /// \ingroup group-utility /// \sa `move_fn` template<typename T> friend constexpr decltype(auto) operator|(T && t, move_fn move) noexcept { return move(t); } }; /// \ingroup group-utility /// \sa `move_fn` RANGES_INLINE_VARIABLE(move_fn, move) /// \ingroup group-utility /// \sa `move_fn` template<typename R> using move_t = meta::if_c<std::is_reference<R>::value, meta::_t<std::remove_reference<R>> &&, detail::decay_t<R>>; } // namespace aux } // namespace ranges #include <range/v3/detail/epilogue.hpp> #endif
0
repos/range-v3/include/range/v3
repos/range-v3/include/range/v3/utility/optional.hpp
/// \file // Range v3 library // // Copyright Casey Carter 2017 // // Use, modification and distribution is subject to the // Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) // // Project home: https://github.com/ericniebler/range-v3 // #ifndef RANGES_V3_UTILITY_OPTIONAL_HPP #define RANGES_V3_UTILITY_OPTIONAL_HPP #include <exception> #include <initializer_list> #include <memory> #include <new> #include <concepts/concepts.hpp> #include <range/v3/detail/config.hpp> #include <range/v3/utility/addressof.hpp> #include <range/v3/utility/in_place.hpp> #include <range/v3/utility/static_const.hpp> #include <range/v3/utility/swap.hpp> #include <range/v3/detail/prologue.hpp> namespace ranges { template<typename> struct optional; struct bad_optional_access : std::exception { virtual const char * what() const noexcept override { return "bad optional access"; } }; struct nullopt_t { struct tag {}; constexpr explicit nullopt_t(tag) noexcept {} }; #if RANGES_CXX_INLINE_VARIABLES >= RANGES_CXX_INLINE_VARIABLES_17 inline constexpr nullopt_t nullopt{nullopt_t::tag{}}; #else /// \cond namespace detail { template<typename> struct nullopt_holder { static constexpr nullopt_t nullopt{nullopt_t::tag{}}; }; template<typename T> constexpr nullopt_t nullopt_holder<T>::nullopt; } // namespace detail /// \endcond namespace { constexpr auto & nullopt = detail::nullopt_holder<void>::nullopt; } #endif /// \cond namespace detail { template<typename = void> [[noreturn]] bool throw_bad_optional_access() { throw bad_optional_access{}; } namespace optional_adl { template<typename T, bool = std::is_trivially_destructible<T>::value> struct optional_storage { union { char dummy_; meta::_t<std::remove_cv<T>> data_; }; bool engaged_; constexpr optional_storage() noexcept : optional_storage( tag{}, meta::bool_<detail::is_trivially_default_constructible_v<T> && detail::is_trivially_copyable_v<T>>{}) {} template(typename... Args)( requires constructible_from<T, Args...>) constexpr explicit optional_storage(in_place_t, Args &&... args) // noexcept(std::is_nothrow_constructible<T, Args...>::value) : data_(static_cast<Args &&>(args)...) , engaged_{true} {} constexpr void reset() noexcept { engaged_ = false; } private: struct tag {}; constexpr optional_storage(tag, std::false_type) noexcept : dummy_{} , engaged_{false} {} constexpr optional_storage(tag, std::true_type) noexcept : data_{} , engaged_{false} {} }; template<typename T> struct optional_storage<T, false> { union { char dummy_; meta::_t<std::remove_cv<T>> data_; }; bool engaged_; ~optional_storage() { reset(); } constexpr optional_storage() noexcept : dummy_{} , engaged_{false} {} template(typename... Args)( requires constructible_from<T, Args...>) constexpr explicit optional_storage(in_place_t, Args &&... args) // noexcept(std::is_nothrow_constructible<T, Args...>::value) : data_(static_cast<Args &&>(args)...) , engaged_{true} {} optional_storage(optional_storage const &) = default; optional_storage(optional_storage &&) = default; optional_storage & operator=(optional_storage const &) = default; optional_storage & operator=(optional_storage &&) = default; void reset() noexcept { if(engaged_) { data_.~T(); engaged_ = false; } } }; template<typename T> struct optional_base : private optional_storage<T> { using optional_storage<T>::optional_storage; using optional_storage<T>::reset; constexpr bool has_value() const noexcept { return engaged_; } constexpr T & operator*() & noexcept { return RANGES_EXPECT(engaged_), data_; } constexpr T const & operator*() const & noexcept { return RANGES_EXPECT(engaged_), data_; } constexpr T && operator*() && noexcept { return RANGES_EXPECT(engaged_), detail::move(data_); } constexpr T const && operator*() const && noexcept { return RANGES_EXPECT(engaged_), detail::move(data_); } constexpr T * operator->() noexcept { return RANGES_EXPECT(engaged_), detail::addressof(data_); } constexpr T const * operator->() const noexcept { return RANGES_EXPECT(engaged_), detail::addressof(data_); } CPP_member constexpr auto swap(optional_base & that) // noexcept(std::is_nothrow_move_constructible<T>::value && is_nothrow_swappable<T>::value) // -> CPP_ret(void)( requires move_constructible<T> && swappable<T>) { constexpr bool can_swap_trivially = !::concepts::adl_swap_detail::is_adl_swappable_v<T> && detail::is_trivially_move_constructible_v<T> && detail::is_trivially_move_assignable_v<T>; swap_(meta::bool_<can_swap_trivially>{}, that); } protected: template(typename... Args)( requires constructible_from<T, Args...>) T & construct_from(Args &&... args) noexcept(std::is_nothrow_constructible<T, Args...>::value) { RANGES_EXPECT(!engaged_); auto const address = static_cast<void *>(std::addressof(data_)); ::new(address) T(static_cast<Args &&>(args)...); engaged_ = true; return data_; } template(typename I)( requires constructible_from<T, decltype(*std::declval<const I &>())>) T & construct_from_deref(const I & it) { RANGES_EXPECT(!engaged_); auto const address = static_cast<void *>(std::addressof(data_)); ::new(address) T(*it); engaged_ = true; return data_; } template<typename U> constexpr void assign_from(U && that) noexcept( std::is_nothrow_constructible<T, decltype(*static_cast<U &&>(that))>:: value && std::is_nothrow_assignable< T &, decltype(*static_cast<U &&>(that))>::value) { if(!that.has_value()) reset(); else if(engaged_) data_ = *static_cast<U &&>(that); else { auto const address = static_cast<void *>(detail::addressof(data_)); ::new(address) T(*static_cast<U &&>(that)); engaged_ = true; } } private: constexpr void swap_(std::true_type, optional_base & that) noexcept { ranges::swap(static_cast<optional_storage<T> &>(*this), static_cast<optional_storage<T> &>(that)); } constexpr void swap_(std::false_type, optional_base & that) noexcept( std::is_nothrow_move_constructible<T>::value && is_nothrow_swappable<T>::value) { if(that.engaged_ == engaged_) { if(engaged_) ranges::swap(data_, that.data_); } else { auto & src = engaged_ ? *this : that; auto & dst = engaged_ ? that : *this; dst.construct_from(detail::move(src.data_)); src.reset(); } } using optional_storage<T>::engaged_; using optional_storage<T>::data_; }; template<typename T> struct optional_base<T &> { optional_base() = default; template(typename Arg)( requires constructible_from<T &, Arg>) constexpr explicit optional_base(in_place_t, Arg && arg) noexcept // : ptr_(detail::addressof(arg)) {} constexpr bool has_value() const noexcept { return ptr_; } constexpr T & operator*() const noexcept { return RANGES_EXPECT(ptr_), *ptr_; } constexpr T * operator->() const noexcept { return RANGES_EXPECT(ptr_), ptr_; } constexpr void reset() noexcept { ptr_ = nullptr; } CPP_member constexpr auto swap(optional_base & that) // noexcept(is_nothrow_swappable<T>::value) // -> CPP_ret(void)( requires swappable<T>) { if(ptr_ && that.ptr_) ranges::swap(*ptr_, *that.ptr_); else ranges::swap(ptr_, that.ptr_); } protected: template(typename U)( requires convertible_to<U &, T &>) constexpr T & construct_from(U && ref) noexcept { RANGES_EXPECT(!ptr_); ptr_ = detail::addressof(ref); return *ptr_; } template<typename U> constexpr void assign_from(U && that) { if(ptr_ && that.ptr_) *ptr_ = *that.ptr_; else ptr_ = that.ptr_; } private: T * ptr_ = nullptr; }; template<typename T> struct optional_copy : optional_base<T> { optional_copy() = default; optional_copy(optional_copy const & that) noexcept( std::is_nothrow_copy_constructible<T>::value) { if(that.has_value()) this->construct_from(*that); } optional_copy(optional_copy &&) = default; optional_copy & operator=(optional_copy const &) = default; optional_copy & operator=(optional_copy &&) = default; using optional_base<T>::optional_base; }; template<typename T> using copy_construct_layer = meta::if_c<std::is_copy_constructible<T>::value && !detail::is_trivially_copy_constructible_v<T>, optional_copy<T>, optional_base<T>>; template<typename T> struct optional_move : copy_construct_layer<T> { optional_move() = default; optional_move(optional_move const &) = default; optional_move(optional_move && that) noexcept( std::is_nothrow_move_constructible<T>::value) { if(that.has_value()) this->construct_from(std::move(*that)); } optional_move & operator=(optional_move const &) = default; optional_move & operator=(optional_move &&) = default; using copy_construct_layer<T>::copy_construct_layer; }; template<typename T> using move_construct_layer = meta::if_c<std::is_move_constructible<T>::value && !detail::is_trivially_move_constructible_v<T>, optional_move<T>, copy_construct_layer<T>>; template<typename T> struct optional_copy_assign : move_construct_layer<T> { optional_copy_assign() = default; optional_copy_assign(optional_copy_assign const &) = default; optional_copy_assign(optional_copy_assign &&) = default; optional_copy_assign & operator=(optional_copy_assign const & that) // noexcept(std::is_nothrow_copy_constructible<T>::value && std::is_nothrow_copy_assignable<T>::value) { this->assign_from(that); return *this; } optional_copy_assign & operator=(optional_copy_assign &&) = default; using move_construct_layer<T>::move_construct_layer; }; template<typename T> struct deleted_copy_assign : move_construct_layer<T> { deleted_copy_assign() = default; deleted_copy_assign(deleted_copy_assign const &) = default; deleted_copy_assign(deleted_copy_assign &&) = default; deleted_copy_assign & operator=(deleted_copy_assign const &) = delete; deleted_copy_assign & operator=(deleted_copy_assign &&) = default; using move_construct_layer<T>::move_construct_layer; }; template<typename T> using copy_assign_layer = meta::if_c< std::is_copy_constructible<T>::value && std::is_copy_assignable<T>::value, meta::if_c<std::is_reference<T>::value || !(detail::is_trivially_copy_constructible_v<T> && detail::is_trivially_copy_assignable_v<T>), optional_copy_assign<T>, move_construct_layer<T>>, deleted_copy_assign<T>>; template<typename T> struct optional_move_assign : copy_assign_layer<T> { optional_move_assign() = default; optional_move_assign(optional_move_assign const &) = default; optional_move_assign(optional_move_assign &&) = default; optional_move_assign & operator=(optional_move_assign const &) = default; optional_move_assign & operator=(optional_move_assign && that) noexcept( std::is_nothrow_move_constructible<T>::value && std::is_nothrow_move_assignable<T>::value) { this->assign_from(std::move(that)); return *this; } using copy_assign_layer<T>::copy_assign_layer; }; template<typename T> struct deleted_move_assign : copy_assign_layer<T> { deleted_move_assign() = default; deleted_move_assign(deleted_move_assign const &) = default; deleted_move_assign(deleted_move_assign &&) = default; deleted_move_assign & operator=(deleted_move_assign const &) = default; deleted_move_assign & operator=(deleted_move_assign &&) = delete; using copy_assign_layer<T>::copy_assign_layer; }; template<typename T> using move_assign_layer = meta::if_c< std::is_move_constructible<T>::value && std::is_move_assignable<T>::value, meta::if_c<std::is_reference<T>::value || !(detail::is_trivially_move_constructible_v<T> && detail::is_trivially_move_assignable_v<T>), optional_move_assign<T>, copy_assign_layer<T>>, deleted_move_assign<T>>; } // namespace optional_adl } // namespace detail /// \endcond // clang-format off /// \concept optional_should_convert /// \brief The \c optional_should_convert concept template<typename U, typename T> CPP_concept optional_should_convert = !( constructible_from<T, optional<U> & > || constructible_from<T, optional<U> && > || constructible_from<T, optional<U> const & > || constructible_from<T, optional<U> const &&> || convertible_to<optional<U> &, T> || convertible_to<optional<U> &&, T> || convertible_to<optional<U> const &, T> || convertible_to<optional<U> const &&, T> ); /// \concept optional_should_convert_assign /// \brief The \c optional_should_convert_assign concept template<typename U, typename T> CPP_concept optional_should_convert_assign = optional_should_convert<U, T> && !(assignable_from<T &, optional<U> &> || assignable_from<T &, optional<U> &&> || assignable_from<T &, optional<U> const &> || assignable_from<T &, optional<U> const &&>); // clang-format on template<typename T> struct optional : detail::optional_adl::move_assign_layer<T> { private: using base_t = detail::optional_adl::move_assign_layer<T>; public: CPP_assert(destructible<T>); static_assert(std::is_object<T>::value || std::is_lvalue_reference<T>::value, ""); static_assert((bool)!same_as<nullopt_t, uncvref_t<T>>, ""); static_assert((bool)!same_as<in_place_t, uncvref_t<T>>, ""); using value_type = meta::_t<std::remove_cv<T>>; constexpr optional() noexcept {} constexpr optional(nullopt_t) noexcept : optional{} {} optional(optional const &) = default; optional(optional &&) = default; using base_t::base_t; template(typename E, typename... Args)( requires constructible_from<T, std::initializer_list<E> &, Args...>) constexpr explicit optional(in_place_t, std::initializer_list<E> il, Args &&... args) // noexcept(std::is_nothrow_constructible<T, std::initializer_list<E> &, Args...>::value) : base_t(in_place, il, static_cast<Args &&>(args)...) {} #if defined(__cpp_conditional_explicit) && __cpp_conditional_explicit > 0 template(typename U = T)( requires (!same_as<detail::decay_t<U>, in_place_t>) AND (!same_as<detail::decay_t<U>, optional>) AND constructible_from<T, U>) constexpr explicit(!convertible_to<U, T>) optional(U && v) : base_t(in_place, static_cast<U &&>(v)) {} template(typename U)( requires optional_should_convert<U, T> AND constructible_from<T, U const &>) explicit(!convertible_to<U const &, T>) optional(optional<U> const & that) { if(that.has_value()) base_t::construct_from(*that); } #else template(typename U = T)( requires (!same_as<detail::decay_t<U>, in_place_t>) AND (!same_as<detail::decay_t<U>, optional>) AND constructible_from<T, U> AND convertible_to<U, T>) constexpr optional(U && v) : base_t(in_place, static_cast<U &&>(v)) {} template(typename U = T)( requires (!same_as<detail::decay_t<U>, in_place_t>) AND (!same_as<detail::decay_t<U>, optional>) AND constructible_from<T, U> AND (!convertible_to<U, T>)) constexpr explicit optional(U && v) : base_t(in_place, static_cast<U &&>(v)) {} template(typename U)( requires optional_should_convert<U, T> AND constructible_from<T, U const &> AND convertible_to<U const &, T>) optional(optional<U> const & that) { if(that.has_value()) base_t::construct_from(*that); } template(typename U)( requires optional_should_convert<U, T> AND constructible_from<T, U const &> AND (!convertible_to<U const &, T>)) explicit optional(optional<U> const & that) { if(that.has_value()) base_t::construct_from(*that); } #endif template(typename U)( requires optional_should_convert<U, T> AND constructible_from<T, U> AND convertible_to<U, T>) optional(optional<U> && that) { if(that.has_value()) base_t::construct_from(detail::move(*that)); } template(typename U)( requires optional_should_convert<U, T> AND constructible_from<T, U> AND (!convertible_to<U, T>)) // explicit optional(optional<U> && that) { if(that.has_value()) base_t::construct_from(detail::move(*that)); } constexpr optional & operator=(nullopt_t) noexcept { reset(); return *this; } optional & operator=(optional const &) = default; optional & operator=(optional &&) = default; template(typename U = T)( requires (!same_as<optional, detail::decay_t<U>>) AND (!(satisfies<T, std::is_scalar> && same_as<T, detail::decay_t<U>>)) AND constructible_from<T, U> AND assignable_from<T &, U>) constexpr optional & operator=(U && u) noexcept( std::is_nothrow_constructible<T, U>::value && std::is_nothrow_assignable<T &, U>::value) { if(has_value()) **this = static_cast<U &&>(u); else base_t::construct_from(static_cast<U &&>(u)); return *this; } template(typename U)( requires optional_should_convert_assign<U, T> AND constructible_from<T, const U &> AND assignable_from<T &, const U &>) constexpr optional & operator=(optional<U> const & that) { base_t::assign_from(that); return *this; } template(typename U)( requires optional_should_convert_assign<U, T> AND constructible_from<T, U> AND assignable_from<T &, U>) constexpr optional & operator=(optional<U> && that) { base_t::assign_from(std::move(that)); return *this; } template(typename I)( requires constructible_from<T, decltype(*std::declval<const I &>())>) T & emplace_deref(const I & it) { reset(); return base_t::construct_from_deref(it); } template(typename... Args)( requires constructible_from<T, Args...>) T & emplace(Args &&... args) noexcept( std::is_nothrow_constructible<T, Args...>::value) { reset(); return base_t::construct_from(static_cast<Args &&>(args)...); } template(typename E, typename... Args)( requires constructible_from<T, std::initializer_list<E> &, Args...>) T & emplace(std::initializer_list<E> il, Args &&... args) noexcept( std::is_nothrow_constructible<T, std::initializer_list<E> &, Args...>::value) { reset(); return base_t::construct_from(il, static_cast<Args &&>(args)...); } using base_t::swap; using base_t::operator->; using base_t::operator*; constexpr explicit operator bool() const noexcept { return has_value(); } using base_t::has_value; constexpr T const & value() const & { return (has_value() || detail::throw_bad_optional_access()), **this; } constexpr T & value() & { return (has_value() || detail::throw_bad_optional_access()), **this; } constexpr T const && value() const && { return (has_value() || detail::throw_bad_optional_access()), detail::move(**this); } constexpr T && value() && { return (has_value() || detail::throw_bad_optional_access()), detail::move(**this); } template(typename U)( requires copy_constructible<T> AND convertible_to<U, T>) constexpr T value_or(U && u) const & { return has_value() ? **this : static_cast<T>((U &&) u); } template(typename U)( requires move_constructible<T> AND convertible_to<U, T>) constexpr T value_or(U && u) && { return has_value() ? detail::move(**this) : static_cast<T>((U &&) u); } using base_t::reset; }; /// \cond namespace detail { namespace optional_adl { constexpr bool convert_bool(bool b) noexcept { return b; } // Relational operators [optional.relops] template<typename T, typename U> constexpr auto operator==(optional<T> const & x, optional<U> const & y) // noexcept(noexcept(convert_bool(*x == *y))) -> decltype(convert_bool(*x == *y)) { return x.has_value() == y.has_value() && (!x || convert_bool(*x == *y)); } template<typename T, typename U> constexpr auto operator!=(optional<T> const & x, optional<U> const & y) // noexcept(noexcept(convert_bool(*x != *y))) -> decltype(convert_bool(*x != *y)) { return x.has_value() != y.has_value() || (x && convert_bool(*x != *y)); } template<typename T, typename U> constexpr auto operator<(optional<T> const & x, optional<U> const & y) // noexcept(noexcept(convert_bool(*x < *y))) -> decltype(convert_bool(*x < *y)) { return y && (!x || convert_bool(*x < *y)); } template<typename T, typename U> constexpr auto operator>(optional<T> const & x, optional<U> const & y) // noexcept(noexcept(convert_bool(*x > *y))) -> decltype(convert_bool(*x > *y)) { return x && (!y || convert_bool(*x > *y)); } template<typename T, typename U> constexpr auto operator<=(optional<T> const & x, optional<U> const & y) // noexcept(noexcept(convert_bool(*x <= *y))) -> decltype(convert_bool(*x <= *y)) { return !x || (y && convert_bool(*x <= *y)); } template<typename T, typename U> constexpr auto operator>=(optional<T> const & x, optional<U> const & y) // noexcept(noexcept(convert_bool(*x >= *y))) -> decltype(convert_bool(*x >= *y)) { return !y || (x && convert_bool(*x >= *y)); } // Comparisons with nullopt [optional.nullops] template<typename T> constexpr bool operator==(optional<T> const & x, nullopt_t) noexcept { return !x; } template<typename T> constexpr bool operator==(nullopt_t, optional<T> const & x) noexcept { return !x; } template<typename T> constexpr bool operator!=(optional<T> const & x, nullopt_t) noexcept { return !!x; } template<typename T> constexpr bool operator!=(nullopt_t, optional<T> const & x) noexcept { return !!x; } template<typename T> constexpr bool operator<(optional<T> const &, nullopt_t) noexcept { return false; } template<typename T> constexpr bool operator<(nullopt_t, optional<T> const & x) noexcept { return !!x; } template<typename T> constexpr bool operator>(optional<T> const & x, nullopt_t) noexcept { return !!x; } template<typename T> constexpr bool operator>(nullopt_t, optional<T> const &) noexcept { return false; } template<typename T> constexpr bool operator<=(optional<T> const & x, nullopt_t) noexcept { return !x; } template<typename T> constexpr bool operator<=(nullopt_t, optional<T> const &) noexcept { return true; } template<typename T> constexpr bool operator>=(optional<T> const &, nullopt_t) noexcept { return true; } template<typename T> constexpr bool operator>=(nullopt_t, optional<T> const & x) noexcept { return !x; } // Comparisons with T [optional.comp_with_t] template<typename T, typename U> constexpr auto operator==(optional<T> const & x, U const & y) // noexcept(noexcept(convert_bool(*x == y))) // -> decltype(convert_bool(*x == y)) { return x && convert_bool(*x == y); } template<typename T, typename U> constexpr auto operator==(T const & x, optional<U> const & y) // noexcept(noexcept(convert_bool(x == *y))) // -> decltype(convert_bool(x == *y)) { return y && convert_bool(x == *y); } template<typename T, typename U> constexpr auto operator!=(optional<T> const & x, U const & y) // noexcept(noexcept(convert_bool(*x != y))) // -> decltype(convert_bool(*x != y)) { return !x || convert_bool(*x != y); } template<typename T, typename U> constexpr auto operator!=(T const & x, optional<U> const & y) // noexcept(noexcept(convert_bool(x != *y))) // -> decltype(convert_bool(x != *y)) { return !y || convert_bool(x != *y); } template<typename T, typename U> constexpr auto operator<(optional<T> const & x, U const & y) // noexcept(noexcept(convert_bool(*x < y))) // -> decltype(convert_bool(*x < y)) { return !x || convert_bool(*x < y); } template<typename T, typename U> constexpr auto operator<(T const & x, optional<U> const & y) // noexcept(noexcept(convert_bool(x < *y))) // -> decltype(convert_bool(x < *y)) { return y && convert_bool(x < *y); } template<typename T, typename U> constexpr auto operator>(optional<T> const & x, U const & y) // noexcept(noexcept(convert_bool(*x > y))) -> decltype(convert_bool(*x > y)) { return x && convert_bool(*x > y); } template<typename T, typename U> constexpr auto operator>(T const & x, optional<U> const & y) // noexcept(noexcept(convert_bool(x > *y))) // -> decltype(convert_bool(x > *y)) { return !y || convert_bool(x > *y); } template<typename T, typename U> constexpr auto operator<=(optional<T> const & x, U const & y) // noexcept(noexcept(convert_bool(*x <= y))) // -> decltype(convert_bool(*x <= y)) { return !x || convert_bool(*x <= y); } template<typename T, typename U> constexpr auto operator<=(T const & x, optional<U> const & y) // noexcept(noexcept(convert_bool(x <= *y))) // -> decltype(convert_bool(x <= *y)) { return y && convert_bool(x <= *y); } template<typename T, typename U> constexpr auto operator>=(optional<T> const & x, U const & y) // noexcept(noexcept(convert_bool(*x >= y))) // -> decltype(convert_bool(*x >= y)) { return x && convert_bool(*x >= y); } template<typename T, typename U> constexpr auto operator>=(T const & x, optional<U> const & y) // noexcept(noexcept(convert_bool(x >= *y))) // -> decltype(convert_bool(x >= *y)) { return !y || convert_bool(x >= *y); } // clang-format off template<typename T> auto CPP_auto_fun(swap)(optional<T> &x, optional<T> &y) ( return x.swap(y) ) // clang-format on } // namespace optional_adl } // namespace detail /// \endcond // clang-format off template<typename T> constexpr auto CPP_auto_fun(make_optional)(T &&t) ( return optional<detail::decay_t<T>>{static_cast<T &&>(t)} ) template<typename T, typename... Args> constexpr auto CPP_auto_fun(make_optional)(Args &&... args) ( return optional<T>{in_place, static_cast<Args &&>(args)...} ) template<typename T, typename U, typename... Args> constexpr auto CPP_auto_fun(make_optional)(std::initializer_list<U> il, Args &&... args) ( return optional<T>{in_place, il, static_cast<Args &&>(args)...} ) // clang-format on /// \cond namespace detail { template<typename T, typename Tag = void, bool Enable = true> struct non_propagating_cache : optional<T> { non_propagating_cache() = default; constexpr non_propagating_cache(nullopt_t) noexcept {} constexpr non_propagating_cache(non_propagating_cache const &) noexcept : optional<T>{} {} constexpr non_propagating_cache(non_propagating_cache && that) noexcept : optional<T>{} { that.optional<T>::reset(); } constexpr non_propagating_cache & operator=( non_propagating_cache const &) noexcept { optional<T>::reset(); return *this; } constexpr non_propagating_cache & operator=( non_propagating_cache && that) noexcept { that.optional<T>::reset(); optional<T>::reset(); return *this; } using optional<T>::operator=; template<class I> constexpr T & emplace_deref(const I & i) { return optional<T>::emplace(*i); } }; template<typename T, typename Tag> struct non_propagating_cache<T, Tag, false> {}; } // namespace detail /// \endcond } // namespace ranges #include <range/v3/detail/epilogue.hpp> #endif
0
repos/range-v3/include/range/v3
repos/range-v3/include/range/v3/utility/unreachable.hpp
// Range v3 library // // Copyright Eric Niebler 2014-present // // Use, modification and distribution is subject to the // Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) // // Project home: https://github.com/ericniebler/range-v3 // #ifndef RANGES_V3_UTILITY_UNREACHABLE_HPP #define RANGES_V3_UTILITY_UNREACHABLE_HPP #include <range/v3/detail/config.hpp> RANGES_DEPRECATED_HEADER( "This header is deprecated. Please #include " "<range/v3/iterator/unreachable_sentinel.hpp> instead.") #include <range/v3/iterator/unreachable_sentinel.hpp> #endif
0
repos/range-v3/include/range/v3
repos/range-v3/include/range/v3/utility/in_place.hpp
/// \file // Range v3 library // // Copyright Eric Niebler 2013-present // // Use, modification and distribution is subject to the // Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) // // Project home: https://github.com/ericniebler/range-v3 // #ifndef RANGES_V3_UTILITY_IN_PLACE_HPP #define RANGES_V3_UTILITY_IN_PLACE_HPP #include <range/v3/range_fwd.hpp> #include <range/v3/utility/static_const.hpp> #include <range/v3/detail/prologue.hpp> namespace ranges { /// \ingroup group-utility struct in_place_t {}; RANGES_INLINE_VARIABLE(in_place_t, in_place) } // namespace ranges #include <range/v3/detail/epilogue.hpp> #endif
0
repos/range-v3/include/range/v3
repos/range-v3/include/range/v3/utility/tuple_algorithm.hpp
/// \file // Range v3 library // // Copyright Eric Niebler 2013-present // // Use, modification and distribution is subject to the // Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) // // Project home: https://github.com/ericniebler/range-v3 // #ifndef RANGES_V3_UTILITY_TUPLE_ALGORITHM_HPP #define RANGES_V3_UTILITY_TUPLE_ALGORITHM_HPP #include <initializer_list> #include <tuple> #include <type_traits> #include <utility> #include <meta/meta.hpp> #include <range/v3/range_fwd.hpp> #include <range/v3/detail/adl_get.hpp> #include <range/v3/functional/invoke.hpp> #include <range/v3/utility/static_const.hpp> #include <range/v3/detail/prologue.hpp> namespace ranges { /// \addtogroup group-utility /// @{ template<typename Tup> using tuple_indices_t = meta::make_index_sequence< std::tuple_size<typename std::remove_reference<Tup>::type>::value>; struct tuple_apply_fn { // clang-format off private: template<typename Fun, typename Tup, std::size_t... Is> static constexpr auto // CPP_auto_fun(impl)(Fun &&fun, Tup &&tup, meta::index_sequence<Is...>) ( return invoke(static_cast<Fun &&>(fun), detail::adl_get<Is>(static_cast<Tup &&>(tup))...) ) public: template<typename Fun, typename Tup> constexpr auto CPP_auto_fun(operator())(Fun &&fun, Tup &&tup)(const) ( return tuple_apply_fn::impl(static_cast<Fun &&>(fun), static_cast<Tup &&>(tup), tuple_indices_t<Tup>{}) ) // clang-format on }; /// \ingroup group-utility /// \sa `tuple_apply_fn` RANGES_INLINE_VARIABLE(tuple_apply_fn, tuple_apply) struct tuple_transform_fn { // clang-format off private: template<typename Tup, typename Fun, std::size_t... Is> static constexpr auto // CPP_auto_fun(impl1)(Tup &&tup, Fun &fun, meta::index_sequence<Is...>) ( return std::tuple< decltype(fun(detail::adl_get<Is>(static_cast<Tup &&>(tup))))...>{ fun(detail::adl_get<Is>(static_cast<Tup &&>( tup)))...} ) template<typename Tup0, typename Tup1, typename Fun, std::size_t... Is> static constexpr auto CPP_auto_fun(impl2)(Tup0 &&tup0, Tup1 &&tup1, Fun &fun, meta::index_sequence<Is...>) ( return std::tuple< decltype(fun(detail::adl_get<Is>(static_cast<Tup0 &&>(tup0)), detail::adl_get<Is>(static_cast<Tup1 &&>(tup1))))...>{ fun(detail::adl_get<Is>(static_cast<Tup0 &&>(tup0)), detail::adl_get<Is>(static_cast<Tup1 &&>(tup1)))...} ) public: template<typename Tup, typename Fun> constexpr auto CPP_auto_fun(operator())(Tup &&tup, Fun fun)(const) ( return tuple_transform_fn::impl1( static_cast<Tup &&>(tup), fun, tuple_indices_t<Tup>{}) ) template<typename Tup0, typename Tup1, typename Fun> constexpr auto CPP_auto_fun(operator())(Tup0 &&tup0, Tup1 &&tup1, Fun fun)(const) ( return tuple_transform_fn::impl2(static_cast<Tup0 &&>(tup0), static_cast<Tup1 &&>(tup1), fun, tuple_indices_t<Tup0>{}) ) // clang-format on }; /// \ingroup group-utility /// \sa `tuple_transform_fn` RANGES_INLINE_VARIABLE(tuple_transform_fn, tuple_transform) struct tuple_foldl_fn { private: template<typename Tup, typename Val, typename Fun> static constexpr Val impl(Tup &&, Val val, Fun &) { return val; } // clang-format off template<std::size_t I0, std::size_t... Is, typename Tup, typename Val, typename Fun, typename Impl = tuple_foldl_fn> static constexpr auto CPP_auto_fun(impl)(Tup &&tup, Val val, Fun &fun) ( return Impl::template impl<Is...>( static_cast<Tup &&>(tup), fun(std::move(val), detail::adl_get<I0>(static_cast<Tup &&>(tup))), fun) ) template<typename Tup, typename Val, typename Fun, std::size_t... Is> static constexpr auto CPP_auto_fun(impl2)(Tup &&tup, Val val, Fun &fun, meta::index_sequence<Is...>) ( return tuple_foldl_fn::impl<Is...>(static_cast<Tup &&>(tup), std::move(val), fun) ) public: template<typename Tup, typename Val, typename Fun> constexpr auto CPP_auto_fun(operator())(Tup &&tup, Val val, Fun fun)(const) ( return tuple_foldl_fn::impl2(static_cast<Tup &&>(tup), std::move(val), fun, tuple_indices_t<Tup>{}) ) // clang-format on }; /// \ingroup group-utility /// \sa `tuple_foldl_fn` RANGES_INLINE_VARIABLE(tuple_foldl_fn, tuple_foldl) struct tuple_for_each_fn { private: template<typename Tup, typename Fun, std::size_t... Is> static constexpr void impl(Tup && tup, Fun & fun, meta::index_sequence<Is...>) { (void)std::initializer_list<int>{ ((void)fun(detail::adl_get<Is>(static_cast<Tup &&>(tup))), 42)...}; } public: template<typename Tup, typename Fun> constexpr Fun operator()(Tup && tup, Fun fun) const { return tuple_for_each_fn::impl( static_cast<Tup &&>(tup), fun, tuple_indices_t<Tup>{}), fun; } }; /// \ingroup group-utility /// \sa `tuple_for_each_fn` RANGES_INLINE_VARIABLE(tuple_for_each_fn, tuple_for_each) struct make_tuple_fn { // clang-format off template<typename... Ts> constexpr auto CPP_auto_fun(operator())(Ts &&... ts)(const) ( return std::make_tuple(static_cast<Ts &&>(ts)...) ) // clang-format on }; /// \ingroup group-utility /// \sa `make_tuple_fn` RANGES_INLINE_VARIABLE(make_tuple_fn, make_tuple) /// @} } // namespace ranges #include <range/v3/detail/epilogue.hpp> #endif
0
repos/range-v3/include/range/v3
repos/range-v3/include/range/v3/utility/common_tuple.hpp
/// \file // Range v3 library // // Copyright Eric Niebler 2013-present // // Use, modification and distribution is subject to the // Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) // // Project home: https://github.com/ericniebler/range-v3 // #ifndef RANGES_V3_UTILITY_COMMON_TUPLE_HPP #define RANGES_V3_UTILITY_COMMON_TUPLE_HPP #include <utility> #include <meta/meta.hpp> #include <concepts/concepts.hpp> #include <range/v3/range_fwd.hpp> #include <range/v3/detail/adl_get.hpp> #include <range/v3/functional/bind.hpp> #include <range/v3/functional/reference_wrapper.hpp> #include <range/v3/utility/common_type.hpp> #include <range/v3/utility/tuple_algorithm.hpp> #include <range/v3/detail/prologue.hpp> namespace ranges { /// \cond namespace detail { template<typename... Us, typename Tup, std::size_t... Is> std::tuple<Us...> to_std_tuple(Tup && tup, meta::index_sequence<Is...>) { return std::tuple<Us...>{adl_get<Is>(static_cast<Tup &&>(tup))...}; } #ifdef RANGES_WORKAROUND_MSVC_786312 template<std::size_t, typename...> struct args_; template<typename, typename> inline constexpr bool argstructible = false; template<std::size_t N, typename... Ts, typename... Us> inline constexpr bool argstructible<args_<N, Ts...>, args_<N, Us...>> = (META_IS_CONSTRUCTIBLE(Ts, Us) && ...); template<typename, typename> inline constexpr bool argsignable = false; template<std::size_t N, typename... Ts, typename... Us> inline constexpr bool argsignable<args_<N, Ts...>, args_<N, Us...>> = (std::is_assignable_v<Ts &, Us> && ...); #endif // RANGES_WORKAROUND_MSVC_786312 template<std::size_t N, typename... Ts> struct args_ { template<typename... Us> args_(args_<N, Us...>, meta::if_c< #ifdef RANGES_WORKAROUND_MSVC_786312 argstructible<args_, args_<N, Us...>> #else // ^^^ workaround / no workaround vvv meta::and_c<META_IS_CONSTRUCTIBLE(Ts, Us)...>::value #endif // RANGES_WORKAROUND_MSVC_786312 > * = nullptr) {} template<typename... Us> meta::if_c< #ifdef RANGES_WORKAROUND_MSVC_786312 argsignable<args_, args_<N, Us...>>, #else // ^^^ workaround / no workaround vvv meta::and_c<std::is_assignable<Ts &, Us>::value...>::value, #endif // RANGES_WORKAROUND_MSVC_786312 args_ &> operator=(args_<N, Us...>) { return *this; } }; template<typename... Ts> using args = args_<sizeof...(Ts), Ts...>; template<typename... Ts> using rargs = args_<sizeof...(Ts), Ts &...>; } // namespace detail /// \endcond template<typename... Ts> struct common_tuple : _tuple_wrapper_::forward_tuple_interface<std::tuple<Ts...>> { private: template<typename That, std::size_t... Is> common_tuple(That && that, meta::index_sequence<Is...>) : common_tuple::forward_tuple_interface{ detail::adl_get<Is>(static_cast<That &&>(that))...} {} struct element_assign_ { template<typename T, typename U> int operator()(T & t, U && u) const { t = static_cast<U &&>(u); return 0; } }; public: // Construction CPP_member CPP_ctor(common_tuple)()( // noexcept( // meta::and_c<std::is_nothrow_default_constructible<Ts>::value...>::value) requires default_constructible<std::tuple<Ts...>>) : common_tuple::forward_tuple_interface{} {} template(typename... Us)( requires constructible_from<detail::args<Ts...>, detail::args<Us...>>) explicit common_tuple(Us &&... us) // noexcept(meta::and_c<std::is_nothrow_constructible<Ts, Us>::value...>::value) : common_tuple::forward_tuple_interface{static_cast<Us &&>(us)...} {} template(typename... Us)( requires constructible_from<detail::args<Ts...>, detail::rargs<Us...>>) common_tuple(std::tuple<Us...> & that) // noexcept( meta::and_c<std::is_nothrow_constructible<Ts, Us &>::value...>::value) // : common_tuple(that, meta::make_index_sequence<sizeof...(Ts)>{}) {} template(typename... Us)( requires constructible_from<detail::args<Ts...>, detail::rargs<Us const...>>) common_tuple(std::tuple<Us...> const & that) // noexcept(meta::and_c< std::is_nothrow_constructible<Ts, Us const &>::value...>::value) // : common_tuple(that, meta::make_index_sequence<sizeof...(Ts)>{}) {} template(typename... Us)( requires constructible_from<detail::args<Ts...>, detail::args<Us...>>) common_tuple(std::tuple<Us...> && that) // noexcept( meta::and_c<std::is_nothrow_constructible<Ts, Us>::value...>::value) // : common_tuple(std::move(that), meta::make_index_sequence<sizeof...(Ts)>{}) {} template(typename... Us)( requires constructible_from<detail::args<Ts...>, detail::rargs<Us...>>) common_tuple(common_tuple<Us...> & that) // noexcept( meta::and_c<std::is_nothrow_constructible<Ts, Us &>::value...>::value) // : common_tuple(that, meta::make_index_sequence<sizeof...(Ts)>{}) {} template(typename... Us)( requires constructible_from<detail::args<Ts...>, detail::rargs<Us const...>>) common_tuple(common_tuple<Us...> const & that) // noexcept(meta::and_c< std::is_nothrow_constructible<Ts, Us const &>::value...>::value) // : common_tuple(that, meta::make_index_sequence<sizeof...(Ts)>{}) {} template(typename... Us)( requires constructible_from<detail::args<Ts...>, detail::args<Us...>>) common_tuple(common_tuple<Us...> && that) // noexcept( meta::and_c<std::is_nothrow_constructible<Ts, Us>::value...>::value) // : common_tuple(std::move(that), meta::make_index_sequence<sizeof...(Ts)>{}) {} std::tuple<Ts...> & base() noexcept { return *this; } std::tuple<Ts...> const & base() const noexcept { return *this; } // Assignment template(typename... Us)( requires std::is_assignable<detail::args<Ts...> &, detail::rargs<Us...>>::value) // common_tuple & operator=(std::tuple<Us...> & that) noexcept( meta::and_c<std::is_nothrow_assignable<Ts &, Us &>::value...>::value) { (void)tuple_transform(base(), that, element_assign_{}); return *this; } template(typename... Us)( requires std::is_assignable<detail::args<Ts...> &, detail::rargs<Us const...>>::value) // common_tuple & operator=(std::tuple<Us...> const & that) noexcept( meta::and_c<std::is_nothrow_assignable<Ts &, Us const &>::value...>::value) { (void)tuple_transform(base(), that, element_assign_{}); return *this; } template(typename... Us)( requires std::is_assignable<detail::args<Ts...> &, detail::args<Us...>>::value) // common_tuple & operator=(std::tuple<Us...> && that) noexcept( meta::and_c<std::is_nothrow_assignable<Ts &, Us>::value...>::value) { (void)tuple_transform(base(), std::move(that), element_assign_{}); return *this; } template(typename... Us)( requires std::is_assignable<detail::args<Ts const...> &, detail::rargs<Us...>>::value) common_tuple const & operator=(std::tuple<Us...> & that) const noexcept( meta::and_c<std::is_nothrow_assignable<Ts const &, Us &>::value...>::value) { (void)tuple_transform(base(), that, element_assign_{}); return *this; } template(typename... Us)( requires std::is_assignable<detail::args<Ts const...> &, detail::rargs<Us const...>>::value) common_tuple const & operator=(std::tuple<Us...> const & that) const noexcept(meta::and_c< std::is_nothrow_assignable<Ts const &, Us const &>::value...>::value) { (void)tuple_transform(base(), that, element_assign_{}); return *this; } template(typename... Us)( requires std::is_assignable<detail::args<Ts const...> &, detail::args<Us...>>::value) common_tuple const & operator=(std::tuple<Us...> && that) const noexcept( meta::and_c<std::is_nothrow_assignable<Ts const &, Us &&>::value...>::value) { (void)tuple_transform(base(), std::move(that), element_assign_{}); return *this; } // Conversion template(typename... Us)( requires constructible_from<detail::args<Us...>, detail::rargs<Ts...>>) operator std::tuple<Us...>() & noexcept( meta::and_c<std::is_nothrow_constructible<Us, Ts &>::value...>::value) { return detail::to_std_tuple<Us...>( *this, meta::make_index_sequence<sizeof...(Ts)>{}); } template(typename... Us)( requires constructible_from<detail::args<Us...>, detail::rargs<Ts const...>>) operator std::tuple<Us...>() const & noexcept( meta::and_c<std::is_nothrow_constructible<Us, Ts const &>::value...>::value) { return detail::to_std_tuple<Us...>( *this, meta::make_index_sequence<sizeof...(Ts)>{}); } template(typename... Us)( requires constructible_from<detail::args<Us...>, detail::args<Ts...>>) operator std::tuple<Us...>() && noexcept(meta::and_c<std::is_nothrow_constructible<Us, Ts>::value...>::value) { return detail::to_std_tuple<Us...>( std::move(*this), meta::make_index_sequence<sizeof...(Ts)>{}); } }; // Logical operators #define LOGICAL_OP(OP, CONCEPT) \ template(typename... Ts, typename... Us)( \ requires and_v<CONCEPT<Ts, Us>...>) \ bool operator OP(common_tuple<Ts...> const & a, common_tuple<Us...> const & b) \ { \ return a.base() OP b.base(); \ } \ template(typename... Ts, typename... Us)( \ requires and_v<CONCEPT<Ts, Us>...>) \ bool operator OP(std::tuple<Ts...> const & a, common_tuple<Us...> const & b) \ { \ return a OP b.base(); \ } \ template(typename... Ts, typename... Us)( \ requires and_v<CONCEPT<Ts, Us>...>) \ bool operator OP(common_tuple<Ts...> const & a, std::tuple<Us...> const & b) \ { \ return a.base() OP b; \ } \ /**/ LOGICAL_OP(==, equality_comparable_with) LOGICAL_OP(!=, equality_comparable_with) LOGICAL_OP(<, totally_ordered_with) LOGICAL_OP(<=, totally_ordered_with) LOGICAL_OP(>, totally_ordered_with) LOGICAL_OP(>=, totally_ordered_with) #undef LOGICAL_OP struct make_common_tuple_fn { template<typename... Args> common_tuple<bind_element_t<Args>...> operator()(Args &&... args) const noexcept( meta::and_c<std::is_nothrow_constructible< bind_element_t<Args>, unwrap_reference_t<Args>>::value...>::value) { return common_tuple<bind_element_t<Args>...>{ unwrap_reference(static_cast<Args &&>(args))...}; } }; /// \ingroup group-utility /// \sa `make_common_tuple_fn` RANGES_INLINE_VARIABLE(make_common_tuple_fn, make_common_tuple) template<typename F, typename S> struct common_pair : std::pair<F, S> { private: std::pair<F, S> const & base() const noexcept { return *this; } public: // Construction CPP_member CPP_ctor(common_pair)()( // noexcept(std::is_nothrow_default_constructible<F>::value && // std::is_nothrow_default_constructible<S>::value) // requires default_constructible<F> && default_constructible<S>) : std::pair<F, S>{} {} template(typename F2, typename S2)( requires constructible_from<F, F2> AND constructible_from<S, S2>) common_pair(F2 && f2, S2 && s2) // noexcept(std::is_nothrow_constructible<F, F2>::value && std::is_nothrow_constructible<S, S2>::value) // : std::pair<F, S>{static_cast<F2 &&>(f2), static_cast<S2 &&>(s2)} {} template(typename F2, typename S2)( requires constructible_from<F, F2 &> AND constructible_from<S, S2 &>) common_pair(std::pair<F2, S2> & that) // noexcept(std::is_nothrow_constructible<F, F2 &>::value && std::is_nothrow_constructible<S, S2 &>::value) // : std::pair<F, S>{that.first, that.second} {} template(typename F2, typename S2)( requires constructible_from<F, F2 const &> AND constructible_from<S, S2 const &>) common_pair(std::pair<F2, S2> const & that) // noexcept(std::is_nothrow_constructible<F, F2 const &>::value && std::is_nothrow_constructible<S, S2 const &>::value) // : std::pair<F, S>{that.first, that.second} {} template(typename F2, typename S2)( requires constructible_from<F, F2> AND constructible_from<S, S2>) common_pair(std::pair<F2, S2> && that) // noexcept(std::is_nothrow_constructible<F, F2>::value && std::is_nothrow_constructible<S, S2>::value) // : std::pair<F, S>{std::forward<F2>(that.first), std::forward<S2>(that.second)} {} // Conversion template(typename F2, typename S2)( requires constructible_from<F2, F &> AND constructible_from<S2, S &>) operator std::pair<F2, S2>() & // noexcept(std::is_nothrow_constructible<F2, F &>::value && std::is_nothrow_constructible<S2, S &>::value) { return {this->first, this->second}; } template(typename F2, typename S2)( requires constructible_from<F2, F const &> AND constructible_from<S2, S const &>) operator std::pair<F2, S2>() const & // noexcept(std::is_nothrow_constructible<F2, F const &>::value && std::is_nothrow_constructible<S2, S const &>::value) { return {this->first, this->second}; } template(typename F2, typename S2)( requires constructible_from<F2, F> AND constructible_from<S2, S>) operator std::pair<F2, S2>() && noexcept(std::is_nothrow_constructible<F2, F>::value && std::is_nothrow_constructible<S2, S>::value) { return {std::forward<F>(this->first), std::forward<S>(this->second)}; } // Assignment template(typename F2, typename S2)( requires assignable_from<F &, F2 &> AND assignable_from<S &, S2 &>) common_pair & operator=(std::pair<F2, S2> & that) // noexcept(std::is_nothrow_assignable<F &, F2 &>::value && std::is_nothrow_assignable<S &, S2 &>::value) { this->first = that.first; this->second = that.second; return *this; } template(typename F2, typename S2)( requires assignable_from<F &, F2 const &> AND assignable_from<S &, S2 const &>) common_pair & operator=(std::pair<F2, S2> const & that) // noexcept(std::is_nothrow_assignable<F &, F2 const &>::value && std::is_nothrow_assignable<S &, S2 const &>::value) { this->first = that.first; this->second = that.second; return *this; } template(typename F2, typename S2)( requires assignable_from<F &, F2> AND assignable_from<S &, S2>) common_pair & operator=(std::pair<F2, S2> && that) // noexcept(std::is_nothrow_assignable<F &, F2>::value && std::is_nothrow_assignable<S &, S2>::value) { this->first = static_cast<F2 &&>(that.first); this->second = static_cast<S2 &&>(that.second); return *this; } template(typename F2, typename S2)( requires assignable_from<F const &, F2 &> AND assignable_from<S const &, S2 &>) common_pair const & operator=(std::pair<F2, S2> & that) const // noexcept(std::is_nothrow_assignable<F const &, F2 &>::value && std::is_nothrow_assignable<S const &, S2 &>::value) { this->first = that.first; this->second = that.second; return *this; } template(typename F2, typename S2)( requires assignable_from<F const &, F2 const &> AND assignable_from<S const &, S2 const &>) common_pair const & operator=(std::pair<F2, S2> const & that) const // noexcept(std::is_nothrow_assignable<F const &, F2 const &>::value && std::is_nothrow_assignable<S const &, S2 const &>::value) { this->first = that.first; this->second = that.second; return *this; } template(typename F2, typename S2)( requires assignable_from<F const &, F2> AND assignable_from<S const &, S2>) common_pair const & operator=(std::pair<F2, S2> && that) const // noexcept(std::is_nothrow_assignable<F const &, F2 &&>::value && std::is_nothrow_assignable<S const &, S2 &&>::value) { this->first = static_cast<F2 &&>(that.first); this->second = static_cast<S2 &&>(that.second); return *this; } }; // Logical operators template(typename F1, typename S1, typename F2, typename S2)( requires equality_comparable_with<F1, F2> AND equality_comparable_with<S1, S2>) bool operator==(common_pair<F1, S1> const & a, common_pair<F2, S2> const & b) { return a.first == b.first && a.second == b.second; } template(typename F1, typename S1, typename F2, typename S2)( requires equality_comparable_with<F1, F2> AND equality_comparable_with<S1, S2>) bool operator==(common_pair<F1, S1> const & a, std::pair<F2, S2> const & b) { return a.first == b.first && a.second == b.second; } template(typename F1, typename S1, typename F2, typename S2)( requires equality_comparable_with<F1, F2> AND equality_comparable_with<S1, S2>) bool operator==(std::pair<F1, S1> const & a, common_pair<F2, S2> const & b) { return a.first == b.first && a.second == b.second; } template(typename F1, typename S1, typename F2, typename S2)( requires totally_ordered_with<F1, F2> AND totally_ordered_with<S1, S2>) bool operator<(common_pair<F1, S1> const & a, common_pair<F2, S2> const & b) { return a.first < b.first || (!(b.first < a.first) && a.second < b.second); } template(typename F1, typename S1, typename F2, typename S2)( requires totally_ordered_with<F1, F2> AND totally_ordered_with<S1, S2>) bool operator<(std::pair<F1, S1> const & a, common_pair<F2, S2> const & b) { return a.first < b.first || (!(b.first < a.first) && a.second < b.second); } template(typename F1, typename S1, typename F2, typename S2)( requires totally_ordered_with<F1, F2> AND totally_ordered_with<S1, S2>) bool operator<(common_pair<F1, S1> const & a, std::pair<F2, S2> const & b) { return a.first < b.first || (!(b.first < a.first) && a.second < b.second); } #define LOGICAL_OP(OP, CONCEPT, RET) \ template(typename F1, typename S1, typename F2, typename S2)( \ requires CONCEPT<F1, F2> AND CONCEPT<S1, S2>) \ bool operator OP(common_pair<F1, S1> const & a, common_pair<F2, S2> const & b) \ { \ return RET; \ } \ template(typename F1, typename S1, typename F2, typename S2)( \ requires CONCEPT<F1, F2> AND CONCEPT<S1, S2>) \ bool operator OP(std::pair<F1, S1> const & a, common_pair<F2, S2> const & b) \ { \ return RET; \ } \ template(typename F1, typename S1, typename F2, typename S2)( \ requires CONCEPT<F1, F2> AND CONCEPT<S1, S2>) \ bool operator OP(common_pair<F1, S1> const & a, std::pair<F2, S2> const & b) \ { \ return RET; \ } \ /**/ LOGICAL_OP(!=, equality_comparable_with, !(a == b)) LOGICAL_OP(<=, totally_ordered_with, !(b < a)) LOGICAL_OP(>, totally_ordered_with, (b < a)) LOGICAL_OP(>=, totally_ordered_with, !(a < b)) #undef LOGICAL_OP struct make_common_pair_fn { template<typename First, typename Second, typename F = bind_element_t<First>, typename S = bind_element_t<Second>> common_pair<F, S> operator()(First && f, Second && s) const // noexcept(std::is_nothrow_constructible<F, unwrap_reference_t<First>>::value && std::is_nothrow_constructible<F, unwrap_reference_t<Second>>::value) { return {unwrap_reference(static_cast<First &&>(f)), unwrap_reference(static_cast<Second &&>(s))}; } }; /// \ingroup group-utility /// \sa `make_common_pair_fn` RANGES_INLINE_VARIABLE(make_common_pair_fn, make_common_pair) /// \cond namespace detail { template<typename, typename, typename, typename = void> struct common_type_tuple_like {}; template<template<typename...> class T0, typename... Ts, template<typename...> class T1, typename... Us, typename TupleLike> struct common_type_tuple_like<T0<Ts...>, T1<Us...>, TupleLike, meta::if_c<sizeof...(Ts) == sizeof...(Us)>> : meta::lazy::let< meta::lazy::invoke<TupleLike, meta::lazy::_t<common_type<Ts, Us>>...>> {}; template<typename, typename, typename, typename = void> struct common_ref_tuple_like {}; template<template<typename...> class T0, typename... Ts, template<typename...> class T1, typename... Us, typename TupleLike> struct common_ref_tuple_like<T0<Ts...>, T1<Us...>, TupleLike, meta::if_c<sizeof...(Ts) == sizeof...(Us)>> : meta::lazy::let<meta::lazy::invoke< TupleLike, meta::lazy::_t<common_reference<Ts, Us>>...>> {}; } // namespace detail /// \endcond } // namespace ranges /// \cond namespace concepts { // common_type for pairs template<typename F1, typename S1, typename F2, typename S2> struct common_type<std::pair<F1, S1>, ranges::common_pair<F2, S2>> : ranges::detail::common_type_tuple_like< std::pair<F1, S1>, ranges::common_pair<F2, S2>, meta::quote<ranges::common_pair>> {}; template<typename F1, typename S1, typename F2, typename S2> struct common_type<ranges::common_pair<F1, S1>, std::pair<F2, S2>> : ranges::detail::common_type_tuple_like< ranges::common_pair<F1, S1>, std::pair<F2, S2>, meta::quote<ranges::common_pair>> {}; template<typename F1, typename S1, typename F2, typename S2> struct common_type<ranges::common_pair<F1, S1>, ranges::common_pair<F2, S2>> : ranges::detail::common_type_tuple_like<ranges::common_pair<F1, S1>, ranges::common_pair<F2, S2>, meta::quote<ranges::common_pair>> {}; // common_type for tuples template<typename... Ts, typename... Us> struct common_type<ranges::common_tuple<Ts...>, std::tuple<Us...>> : ranges::detail::common_type_tuple_like< ranges::common_tuple<Ts...>, std::tuple<Us...>, meta::quote<ranges::common_tuple>> {}; template<typename... Ts, typename... Us> struct common_type<std::tuple<Ts...>, ranges::common_tuple<Us...>> : ranges::detail::common_type_tuple_like< std::tuple<Ts...>, ranges::common_tuple<Us...>, meta::quote<ranges::common_tuple>> {}; template<typename... Ts, typename... Us> struct common_type<ranges::common_tuple<Ts...>, ranges::common_tuple<Us...>> : ranges::detail::common_type_tuple_like<ranges::common_tuple<Ts...>, ranges::common_tuple<Us...>, meta::quote<ranges::common_tuple>> {}; // common reference for pairs template<typename F1, typename S1, typename F2, typename S2, template<typename> class Qual1, template<typename> class Qual2> struct basic_common_reference<ranges::common_pair<F1, S1>, std::pair<F2, S2>, Qual1, Qual2> : ranges::detail::common_ref_tuple_like< ranges::common_pair<Qual1<F1>, Qual1<S1>>, std::pair<Qual2<F2>, Qual2<S2>>, meta::quote<ranges::common_pair>> {}; template<typename F1, typename S1, typename F2, typename S2, template<typename> class Qual1, template<typename> class Qual2> struct basic_common_reference<std::pair<F1, S1>, ranges::common_pair<F2, S2>, Qual1, Qual2> : ranges::detail::common_ref_tuple_like< std::pair<Qual1<F1>, Qual1<S1>>, ranges::common_pair<Qual2<F2>, Qual2<S2>>, meta::quote<ranges::common_pair>> {}; template<typename F1, typename S1, typename F2, typename S2, template<typename> class Qual1, template<typename> class Qual2> struct basic_common_reference<ranges::common_pair<F1, S1>, ranges::common_pair<F2, S2>, Qual1, Qual2> : ranges::detail::common_ref_tuple_like<ranges::common_pair<Qual1<F1>, Qual1<S1>>, ranges::common_pair<Qual2<F2>, Qual2<S2>>, meta::quote<ranges::common_pair>> {}; // common reference for tuples template<typename... Ts, typename... Us, template<typename> class Qual1, template<typename> class Qual2> struct basic_common_reference<ranges::common_tuple<Ts...>, std::tuple<Us...>, Qual1, Qual2> : ranges::detail::common_ref_tuple_like< ranges::common_tuple<Qual1<Ts>...>, std::tuple<Qual2<Us>...>, meta::quote<ranges::common_tuple>> {}; template<typename... Ts, typename... Us, template<typename> class Qual1, template<typename> class Qual2> struct basic_common_reference<std::tuple<Ts...>, ranges::common_tuple<Us...>, Qual1, Qual2> : ranges::detail::common_ref_tuple_like< std::tuple<Qual1<Ts>...>, ranges::common_tuple<Qual2<Us>...>, meta::quote<ranges::common_tuple>> {}; template<typename... Ts, typename... Us, template<typename> class Qual1, template<typename> class Qual2> struct basic_common_reference<ranges::common_tuple<Ts...>, ranges::common_tuple<Us...>, Qual1, Qual2> : ranges::detail::common_ref_tuple_like<ranges::common_tuple<Qual1<Ts>...>, ranges::common_tuple<Qual2<Us>...>, meta::quote<ranges::common_tuple>> {}; } // namespace concepts /// \endcond RANGES_DIAGNOSTIC_PUSH RANGES_DIAGNOSTIC_IGNORE_MISMATCHED_TAGS RANGES_BEGIN_NAMESPACE_STD template<typename First, typename Second> struct tuple_size<::ranges::common_pair<First, Second>> : std::integral_constant<size_t, 2> {}; template<typename First, typename Second> struct tuple_element<0, ::ranges::common_pair<First, Second>> { using type = First; }; template<typename First, typename Second> struct tuple_element<1, ::ranges::common_pair<First, Second>> { using type = Second; }; template<typename... Ts> struct tuple_size<::ranges::common_tuple<Ts...>> : std::integral_constant<size_t, sizeof...(Ts)> {}; template<size_t N, typename... Ts> struct tuple_element<N, ::ranges::common_tuple<Ts...>> : tuple_element<N, tuple<Ts...>> {}; #if RANGES_CXX_VER > RANGES_CXX_STD_17 RANGES_BEGIN_NAMESPACE_VERSION template<typename...> struct common_type; // common_type for pairs template<typename F1, typename S1, typename F2, typename S2> struct common_type<std::pair<F1, S1>, ::ranges::common_pair<F2, S2>> : ::ranges::detail::common_type_tuple_like< std::pair<F1, S1>, ::ranges::common_pair<F2, S2>, ::meta::quote<::ranges::common_pair>> {}; template<typename F1, typename S1, typename F2, typename S2> struct common_type<::ranges::common_pair<F1, S1>, std::pair<F2, S2>> : ::ranges::detail::common_type_tuple_like< ::ranges::common_pair<F1, S1>, std::pair<F2, S2>, ::meta::quote<::ranges::common_pair>> {}; template<typename F1, typename S1, typename F2, typename S2> struct common_type<::ranges::common_pair<F1, S1>, ::ranges::common_pair<F2, S2>> : ::ranges::detail::common_type_tuple_like<::ranges::common_pair<F1, S1>, ::ranges::common_pair<F2, S2>, ::meta::quote<::ranges::common_pair>> {}; // common_type for tuples template<typename... Ts, typename... Us> struct common_type<::ranges::common_tuple<Ts...>, std::tuple<Us...>> : ::ranges::detail::common_type_tuple_like< ::ranges::common_tuple<Ts...>, std::tuple<Us...>, ::meta::quote<::ranges::common_tuple>> {}; template<typename... Ts, typename... Us> struct common_type<std::tuple<Ts...>, ::ranges::common_tuple<Us...>> : ::ranges::detail::common_type_tuple_like< std::tuple<Ts...>, ::ranges::common_tuple<Us...>, ::meta::quote<::ranges::common_tuple>> {}; template<typename... Ts, typename... Us> struct common_type<::ranges::common_tuple<Ts...>, ::ranges::common_tuple<Us...>> : ::ranges::detail::common_type_tuple_like<::ranges::common_tuple<Ts...>, ::ranges::common_tuple<Us...>, ::meta::quote<::ranges::common_tuple>> {}; template<typename, typename, template<typename> class, template<typename> class> struct basic_common_reference; // common reference for pairs template<typename F1, typename S1, typename F2, typename S2, template<typename> class Qual1, template<typename> class Qual2> struct basic_common_reference<::ranges::common_pair<F1, S1>, std::pair<F2, S2>, Qual1, Qual2> : ::ranges::detail::common_ref_tuple_like< ::ranges::common_pair<Qual1<F1>, Qual1<S1>>, std::pair<Qual2<F2>, Qual2<S2>>, ::meta::quote<::ranges::common_pair>> {}; template<typename F1, typename S1, typename F2, typename S2, template<typename> class Qual1, template<typename> class Qual2> struct basic_common_reference<std::pair<F1, S1>, ::ranges::common_pair<F2, S2>, Qual1, Qual2> : ::ranges::detail::common_ref_tuple_like< std::pair<Qual1<F1>, Qual1<S1>>, ::ranges::common_pair<Qual2<F2>, Qual2<S2>>, ::meta::quote<::ranges::common_pair>> {}; template<typename F1, typename S1, typename F2, typename S2, template<typename> class Qual1, template<typename> class Qual2> struct basic_common_reference<::ranges::common_pair<F1, S1>, ::ranges::common_pair<F2, S2>, Qual1, Qual2> : ::ranges::detail::common_ref_tuple_like<::ranges::common_pair<Qual1<F1>, Qual1<S1>>, ::ranges::common_pair<Qual2<F2>, Qual2<S2>>, ::meta::quote<::ranges::common_pair>> {}; // common reference for tuples template<typename... Ts, typename... Us, template<typename> class Qual1, template<typename> class Qual2> struct basic_common_reference<::ranges::common_tuple<Ts...>, std::tuple<Us...>, Qual1, Qual2> : ::ranges::detail::common_ref_tuple_like< ::ranges::common_tuple<Qual1<Ts>...>, std::tuple<Qual2<Us>...>, ::meta::quote<::ranges::common_tuple>> {}; template<typename... Ts, typename... Us, template<typename> class Qual1, template<typename> class Qual2> struct basic_common_reference<std::tuple<Ts...>, ::ranges::common_tuple<Us...>, Qual1, Qual2> : ::ranges::detail::common_ref_tuple_like< std::tuple<Qual1<Ts>...>, ::ranges::common_tuple<Qual2<Us>...>, ::meta::quote<::ranges::common_tuple>> {}; template<typename... Ts, typename... Us, template<typename> class Qual1, template<typename> class Qual2> struct basic_common_reference<::ranges::common_tuple<Ts...>, ::ranges::common_tuple<Us...>, Qual1, Qual2> : ::ranges::detail::common_ref_tuple_like<::ranges::common_tuple<Qual1<Ts>...>, ::ranges::common_tuple<Qual2<Us>...>, ::meta::quote<::ranges::common_tuple>> {}; RANGES_END_NAMESPACE_VERSION #endif // RANGES_CXX_VER > RANGES_CXX_STD_17 RANGES_END_NAMESPACE_STD RANGES_DIAGNOSTIC_POP #include <range/v3/detail/epilogue.hpp> #endif
0
repos/range-v3/include/range/v3
repos/range-v3/include/range/v3/utility/scope_exit.hpp
/// \file // Range v3 library // // Copyright Eric Niebler 2017-present // // Use, modification and distribution is subject to the // Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) // // Project home: https://github.com/ericniebler/range-v3 // #ifndef RANGES_V3_UTILITY_SCOPE_EXIT_HPP #define RANGES_V3_UTILITY_SCOPE_EXIT_HPP #include <functional> #include <type_traits> #include <utility> #include <meta/meta.hpp> #include <range/v3/detail/prologue.hpp> namespace ranges { template<typename Fun> struct scope_exit { private: using nothrow_move_t = std::is_nothrow_move_constructible<Fun>; using nothrow_copy_t = std::is_nothrow_copy_constructible<Fun>; Fun fun_; bool dismissed_{false}; using ref_t = decltype(std::ref(std::declval<Fun const &>())); using guard = scope_exit<ref_t>; scope_exit(Fun const & fun, guard && g) : fun_(fun) { g.dismiss(); } scope_exit(Fun const & fun, std::false_type) : scope_exit(fun, guard{std::ref(fun)}) {} scope_exit(Fun const & fun, std::true_type) noexcept : fun_(fun) {} scope_exit(Fun && fun, std::true_type) noexcept : fun_(std::move(fun)) {} public: explicit scope_exit(Fun const & fun) noexcept( noexcept(scope_exit(fun, nothrow_copy_t{}))) : scope_exit(fun, nothrow_copy_t{}) {} explicit scope_exit(Fun && fun) noexcept(noexcept(scope_exit(std::move(fun), nothrow_move_t{}))) : scope_exit(std::move(fun), nothrow_move_t{}) {} scope_exit(scope_exit const &) = delete; scope_exit(scope_exit && that) noexcept( std::is_nothrow_move_constructible<Fun>::value) : scope_exit(std::move((that.dismiss(), that)).fun_) {} ~scope_exit() { if(!dismissed_) fun_(); } void dismiss() noexcept { dismissed_ = true; } }; template<typename Fun, typename ScopeExit = scope_exit<meta::_t<std::decay<Fun>>>> ScopeExit make_scope_exit(Fun && fun) noexcept( noexcept(ScopeExit(ScopeExit((Fun &&) fun)))) { return ScopeExit((Fun &&) fun); } } // namespace ranges #include <range/v3/detail/epilogue.hpp> #endif
0
repos/range-v3/include/range/v3
repos/range-v3/include/range/v3/utility/concepts.hpp
// Range v3 library // // Copyright Eric Niebler 2013-present // // Use, modification and distribution is subject to the // Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) // // Project home: https://github.com/ericniebler/range-v3 // #ifndef RANGES_V3_UTILITY_CONCEPTS_HPP #define RANGES_V3_UTILITY_CONCEPTS_HPP #include <range/v3/detail/config.hpp> RANGES_DEPRECATED_HEADER( "This header is deprecated. Please #include <concepts/concepts.hpp> instead.") #include <concepts/concepts.hpp> #include <range/v3/range_fwd.hpp> #include <range/v3/utility/common_type.hpp> #include <range/v3/utility/swap.hpp> #endif
0
repos/range-v3/include/range/v3
repos/range-v3/include/range/v3/utility/iterator.hpp
// Range v3 library // // Copyright Eric Niebler 2013-present // // Use, modification and distribution is subject to the // Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) // // Project home: https://github.com/ericniebler/range-v3 // #ifndef RANGES_V3_UTILITY_ITERATOR_HPP #define RANGES_V3_UTILITY_ITERATOR_HPP #include <range/v3/detail/config.hpp> RANGES_DEPRECATED_HEADER( R"(This header is deprecated. Please include one of the following depending on your need: <range/v3/iterator/operations.hpp>, <range/v3/iterator/insert_iterators.hpp>, <range/v3/iterator/move_iterators.hpp>, <range/v3/iterator/reverse_iterator.hpp>, <range/v3/iterator/stream_iterators.hpp>)") #include <range/v3/iterator/insert_iterators.hpp> #include <range/v3/iterator/move_iterators.hpp> #include <range/v3/iterator/operations.hpp> #include <range/v3/iterator/reverse_iterator.hpp> #include <range/v3/iterator/stream_iterators.hpp> #endif
0
repos/range-v3/include/range/v3
repos/range-v3/include/range/v3/utility/compressed_pair.hpp
/// \file // Range v3 library // // Copyright Eric Niebler 2013-present // Copyright Casey Carter 2016 // // Use, modification and distribution is subject to the // Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) // // Project home: https://github.com/ericniebler/range-v3 // #ifndef RANGES_V3_UTILITY_COMPRESSED_PAIR_HPP #define RANGES_V3_UTILITY_COMPRESSED_PAIR_HPP #include <type_traits> #include <utility> #include <meta/meta.hpp> #include <concepts/concepts.hpp> #include <range/v3/range_fwd.hpp> #include <range/v3/utility/box.hpp> #include <range/v3/utility/static_const.hpp> #include <range/v3/detail/prologue.hpp> namespace ranges { /// \cond namespace compressed_tuple_detail { // tagging individual elements with the complete type list disambiguates // base classes when composing compressed_tuples recursively. template<typename T, std::size_t I, typename... Ts> using storage = box<T, meta::list<meta::size_t<I>, Ts...>>; template<typename List, typename Indices> struct compressed_tuple_; template<typename... Ts, std::size_t... Is> struct RANGES_EMPTY_BASES compressed_tuple_<meta::list<Ts...>, meta::index_sequence<Is...>> : storage<Ts, Is, Ts...>... { static_assert(same_as<meta::index_sequence<Is...>, meta::make_index_sequence<sizeof...(Is)>>, "What madness is this?!?"); compressed_tuple_() = default; template<typename... Args, meta::if_<meta::and_c<META_IS_CONSTRUCTIBLE(Ts, Args)...>, int> = 0> constexpr compressed_tuple_(Args &&... args) noexcept( meta::strict_and<std::is_nothrow_constructible<storage<Ts, Is, Ts...>, Args>...>::value) : storage<Ts, Is, Ts...>{static_cast<Args &&>(args)}... {} template< typename... Us, meta::if_<meta::and_c<META_IS_CONSTRUCTIBLE(Us, Ts const &)...>, int> = 0> constexpr operator std::tuple<Us...>() const noexcept( meta::strict_and<std::is_nothrow_constructible<Us, Ts const &>...>::value) { return std::tuple<Us...>{get<Is>(*this)...}; } template<std::size_t I, typename T = meta::at_c<meta::list<Ts...>, I>> friend constexpr T & get(compressed_tuple_ & tuple) noexcept { return static_cast<storage<T, I, Ts...> &>(tuple).get(); } template<std::size_t I, typename T = meta::at_c<meta::list<Ts...>, I>> friend constexpr T const & get(compressed_tuple_ const & tuple) noexcept { return static_cast<storage<T, I, Ts...> const &>(tuple).get(); } template<std::size_t I, typename T = meta::at_c<meta::list<Ts...>, I>> friend constexpr T && get(compressed_tuple_ && tuple) noexcept { return static_cast<storage<T, I, Ts...> &&>(tuple).get(); } template<std::size_t I, typename T = meta::at_c<meta::list<Ts...>, I>> friend constexpr T const && get(compressed_tuple_ const && tuple) noexcept { return static_cast<storage<T, I, Ts...> const &&>(tuple).get(); } }; template<typename... Ts> using compressed_tuple RANGES_DEPRECATED( "ranges::compressed_tuple is deprecated.") = compressed_tuple_<meta::list<Ts...>, meta::make_index_sequence<sizeof...(Ts)>>; } // namespace compressed_tuple_detail /// \endcond using compressed_tuple_detail::compressed_tuple; struct make_compressed_tuple_fn { // clang-format off template<typename... Args> constexpr auto CPP_auto_fun(operator())(Args &&... args) (const) ( return compressed_tuple<bind_element_t<Args>...>{ static_cast<Args &&>(args)...} ) // clang-format on }; /// \ingroup group-utility /// \sa `make_compressed_tuple_fn` RANGES_INLINE_VARIABLE(make_compressed_tuple_fn, make_compressed_tuple) template<typename First, typename Second> struct RANGES_EMPTY_BASES compressed_pair : box<First, meta::size_t<0>> , box<Second, meta::size_t<1>> { using first_type = First; using second_type = Second; compressed_pair() = default; template(typename U, typename V)( requires constructible_from<First, U> AND constructible_from<Second, V>) constexpr compressed_pair(U && u, V && v) // noexcept(noexcept(First((U &&) u)) && noexcept(Second((V &&) v))) : box<First, meta::size_t<0>>{(U &&) u} , box<Second, meta::size_t<1>>{(V &&) v} {} constexpr First & first() & { return this->box<First, meta::size_t<0>>::get(); } constexpr First const & first() const & { return this->box<First, meta::size_t<0>>::get(); } constexpr First && first() && { return static_cast<First &&>(this->box<First, meta::size_t<0>>::get()); } constexpr Second & second() & { return this->box<Second, meta::size_t<1>>::get(); } constexpr Second const & second() const & { return this->box<Second, meta::size_t<1>>::get(); } constexpr Second && second() && { return static_cast<Second &&>(this->box<Second, meta::size_t<1>>::get()); } template(typename F, typename S)( requires convertible_to<First const &, F> AND convertible_to<Second const &, S>) constexpr operator std::pair<F, S>() const { return std::pair<F, S>{first(), second()}; } }; struct make_compressed_pair_fn { // clang-format off template<typename First, typename Second> constexpr auto CPP_auto_fun(operator())(First &&f, Second &&s) (const) ( return compressed_pair<bind_element_t<First>, bind_element_t<Second>>{ static_cast<First &&>(f), static_cast<Second &&>(s) } ) // clang-format on }; /// \ingroup group-utility /// \sa `make_compressed_pair_fn` RANGES_INLINE_VARIABLE(make_compressed_pair_fn, make_compressed_pair) } // namespace ranges RANGES_DIAGNOSTIC_PUSH RANGES_DIAGNOSTIC_IGNORE_MISMATCHED_TAGS namespace std { template<typename... Ts, size_t... Is> struct tuple_size<::ranges::compressed_tuple_detail::compressed_tuple_< ::meta::list<Ts...>, ::meta::index_sequence<Is...>>> : integral_constant<size_t, sizeof...(Ts)> {}; template<size_t I, typename... Ts, size_t... Is> struct tuple_element<I, ::ranges::compressed_tuple_detail::compressed_tuple_< ::meta::list<Ts...>, ::meta::index_sequence<Is...>>> { using type = ::meta::at_c<::meta::list<Ts...>, I>; }; template<typename First, typename Second> struct tuple_size<::ranges::compressed_pair<First, Second>> : integral_constant<size_t, 2> {}; template<typename First, typename Second> struct tuple_element<0, ::ranges::compressed_pair<First, Second>> { using type = First; }; template<typename First, typename Second> struct tuple_element<1, ::ranges::compressed_pair<First, Second>> { using type = Second; }; } // namespace std RANGES_DIAGNOSTIC_POP #include <range/v3/detail/epilogue.hpp> #endif
0
repos/range-v3/include/range/v3
repos/range-v3/include/range/v3/utility/basic_iterator.hpp
// Range v3 library // // Copyright Eric Niebler 2014-present // Copyright Casey Carter 2016 // // Use, modification and distribution is subject to the // Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) // // Project home: https://github.com/ericniebler/range-v3 // #ifndef RANGES_V3_UTILITY_BASIC_ITERATOR_HPP #define RANGES_V3_UTILITY_BASIC_ITERATOR_HPP #include <range/v3/detail/config.hpp> RANGES_DEPRECATED_HEADER( "This header is deprecated. Please #include <range/v3/iterator/basic_iterator.hpp> " "instead.") #include <range/v3/iterator/basic_iterator.hpp> #endif
0
repos/range-v3/include/range/v3
repos/range-v3/include/range/v3/utility/semiregular.hpp
/// \file // Range v3 library // // Copyright Eric Niebler 2013-present // // Use, modification and distribution is subject to the // Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) // // Project home: https://github.com/ericniebler/range-v3 // #ifndef RANGES_V3_UTILITY_SEMIREGULAR_HPP #define RANGES_V3_UTILITY_SEMIREGULAR_HPP #include <range/v3/detail/config.hpp> RANGES_DEPRECATED_HEADER( "This header is deprecated. Please #include <range/v3/utility/semiregular_box.hpp> " "instead.") #include <range/v3/utility/semiregular_box.hpp> #endif
0
repos/range-v3/include/range/v3
repos/range-v3/include/range/v3/utility/box.hpp
/// \file // Range v3 library // // Copyright Eric Niebler 2013-present // Copyright Casey Carter 2016 // // Use, modification and distribution is subject to the // Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) // // Project home: https://github.com/ericniebler/range-v3 // #ifndef RANGES_V3_UTILITY_BOX_HPP #define RANGES_V3_UTILITY_BOX_HPP #include <cstdlib> #include <type_traits> #include <utility> #include <meta/meta.hpp> #include <concepts/concepts.hpp> #include <range/v3/range_fwd.hpp> #include <range/v3/utility/get.hpp> #include <range/v3/detail/prologue.hpp> RANGES_DIAGNOSTIC_PUSH RANGES_DIAGNOSTIC_IGNORE_DEPRECATED_DECLARATIONS namespace ranges { /// \addtogroup group-utility Utility /// @{ /// /// \cond template<typename T> struct RANGES_DEPRECATED("The ranges::mutable_ class template is deprecated") mutable_ { mutable T value; CPP_member constexpr CPP_ctor(mutable_)()( requires std::is_default_constructible<T>::value) : value{} {} constexpr explicit mutable_(T const & t) : value(t) {} constexpr explicit mutable_(T && t) : value(detail::move(t)) {} mutable_ const & operator=(T const & t) const { value = t; return *this; } mutable_ const & operator=(T && t) const { value = detail::move(t); return *this; } constexpr operator T &() const & { return value; } }; template<typename T, T v> struct RANGES_DEPRECATED("The ranges::constant class template is deprecated") constant { constant() = default; constexpr explicit constant(T const &) {} constant & operator=(T const &) { return *this; } constant const & operator=(T const &) const { return *this; } constexpr operator T() const { return v; } constexpr T exchange(T const &) const { return v; } }; /// \endcond /// \cond namespace detail { // "box" has three different implementations that store a T differently: enum class box_compress { none, // Nothing special: get() returns a reference to a T member subobject ebo, // Apply Empty Base Optimization: get() returns a reference to a T base // subobject coalesce // Coalesce all Ts into one T: get() returns a reference to a static // T singleton }; // Per N4582, lambda closures are *not*: // - aggregates ([expr.prim.lambda]/4) // - default constructible_from ([expr.prim.lambda]/p21) // - copy assignable ([expr.prim.lambda]/p21) template<typename Fn> using could_be_lambda = meta::bool_<!std::is_default_constructible<Fn>::value && !std::is_copy_assignable<Fn>::value>; template<typename> constexpr box_compress box_compression_(...) { return box_compress::none; } template<typename T, typename = meta::if_<meta::strict_and< std::is_empty<T>, meta::bool_<!detail::is_final_v<T>> #if defined(__GNUC__) && !defined(__clang__) && __GNUC__ == 6 && __GNUC_MINOR__ < 2 // GCC 6.0 & 6.1 find empty lambdas' implicit conversion // to function pointer when doing overload resolution // for function calls. That causes hard errors. // https://gcc.gnu.org/bugzilla/show_bug.cgi?id=71117 , meta::not_<could_be_lambda<T>> #endif >>> constexpr box_compress box_compression_(long) { return box_compress::ebo; } #ifndef RANGES_WORKAROUND_MSVC_249830 // MSVC pukes passing non-constant-expression objects to constexpr // functions, so do not coalesce. template<typename T, typename = meta::if_<meta::strict_and<std::is_empty<T>, detail::is_trivial<T>>>> constexpr box_compress box_compression_(int) { return box_compress::coalesce; } #endif template<typename T> constexpr box_compress box_compression() { return box_compression_<T>(0); } } // namespace detail /// \endcond template<typename Element, typename Tag = void, detail::box_compress = detail::box_compression<Element>()> class box { Element value; public: CPP_member constexpr CPP_ctor(box)()( // noexcept(std::is_nothrow_default_constructible<Element>::value) // requires std::is_default_constructible<Element>::value) : value{} {} #if defined(__cpp_conditional_explicit) && __cpp_conditional_explicit > 0 template(typename E)( requires (!same_as<box, detail::decay_t<E>>) AND constructible_from<Element, E>) constexpr explicit(!convertible_to<E, Element>) box(E && e) noexcept(std::is_nothrow_constructible<Element, E>::value) // : value(static_cast<E &&>(e)) {} #else template(typename E)( requires (!same_as<box, detail::decay_t<E>>) AND constructible_from<Element, E> AND convertible_to<E, Element>) constexpr box(E && e) noexcept(std::is_nothrow_constructible<Element, E>::value) : value(static_cast<E &&>(e)) {} template(typename E)( requires (!same_as<box, detail::decay_t<E>>) AND constructible_from<Element, E> AND (!convertible_to<E, Element>)) constexpr explicit box(E && e) noexcept(std::is_nothrow_constructible<Element, E>::value) // : value(static_cast<E &&>(e)) {} #endif constexpr Element & get() & noexcept { return value; } constexpr Element const & get() const & noexcept { return value; } constexpr Element && get() && noexcept { return detail::move(value); } constexpr Element const && get() const && noexcept { return detail::move(value); } }; template<typename Element, typename Tag> class box<Element, Tag, detail::box_compress::ebo> : Element { public: CPP_member constexpr CPP_ctor(box)()( // noexcept(std::is_nothrow_default_constructible<Element>::value) // requires std::is_default_constructible<Element>::value) : Element{} {} #if defined(__cpp_conditional_explicit) && __cpp_conditional_explicit > 0 template(typename E)( requires (!same_as<box, detail::decay_t<E>>) AND constructible_from<Element, E>) constexpr explicit(!convertible_to<E, Element>) box(E && e) noexcept(std::is_nothrow_constructible<Element, E>::value) // : Element(static_cast<E &&>(e)) {} #else template(typename E)( requires (!same_as<box, detail::decay_t<E>>) AND constructible_from<Element, E> AND convertible_to<E, Element>) constexpr box(E && e) noexcept(std::is_nothrow_constructible<Element, E>::value) // : Element(static_cast<E &&>(e)) {} template(typename E)( requires (!same_as<box, detail::decay_t<E>>) AND constructible_from<Element, E> AND (!convertible_to<E, Element>)) constexpr explicit box(E && e) noexcept(std::is_nothrow_constructible<Element, E>::value) // : Element(static_cast<E &&>(e)) {} #endif constexpr Element & get() & noexcept { return *this; } constexpr Element const & get() const & noexcept { return *this; } constexpr Element && get() && noexcept { return detail::move(*this); } constexpr Element const && get() const && noexcept { return detail::move(*this); } }; template<typename Element, typename Tag> class box<Element, Tag, detail::box_compress::coalesce> { static Element value; public: constexpr box() noexcept = default; #if defined(__cpp_conditional_explicit) && __cpp_conditional_explicit > 0 template(typename E)( requires (!same_as<box, detail::decay_t<E>>) AND constructible_from<Element, E>) constexpr explicit(!convertible_to<E, Element>) box(E &&) noexcept {} #else template(typename E)( requires (!same_as<box, detail::decay_t<E>>) AND constructible_from<Element, E> AND convertible_to<E, Element>) constexpr box(E &&) noexcept {} template(typename E)( requires (!same_as<box, detail::decay_t<E>>) AND constructible_from<Element, E> AND (!convertible_to<E, Element>)) constexpr explicit box(E &&) noexcept {} #endif constexpr Element & get() & noexcept { return value; } constexpr Element const & get() const & noexcept { return value; } constexpr Element && get() && noexcept { return detail::move(value); } constexpr Element const && get() const && noexcept { return detail::move(value); } }; template<typename Element, typename Tag> Element box<Element, Tag, detail::box_compress::coalesce>::value{}; /// \cond namespace _get_ { /// \endcond // Get by tag type template<typename Tag, typename Element, detail::box_compress BC> constexpr Element & get(box<Element, Tag, BC> & b) noexcept { return b.get(); } template<typename Tag, typename Element, detail::box_compress BC> constexpr Element const & get(box<Element, Tag, BC> const & b) noexcept { return b.get(); } template<typename Tag, typename Element, detail::box_compress BC> constexpr Element && get(box<Element, Tag, BC> && b) noexcept { return detail::move(b).get(); } // Get by index template<std::size_t I, typename Element, detail::box_compress BC> constexpr Element & get(box<Element, meta::size_t<I>, BC> & b) noexcept { return b.get(); } template<std::size_t I, typename Element, detail::box_compress BC> constexpr Element const & get( box<Element, meta::size_t<I>, BC> const & b) noexcept { return b.get(); } template<std::size_t I, typename Element, detail::box_compress BC> constexpr Element && get(box<Element, meta::size_t<I>, BC> && b) noexcept { return detail::move(b).get(); } /// \cond } // namespace _get_ /// \endcond /// @} } // namespace ranges RANGES_DIAGNOSTIC_POP #include <range/v3/detail/epilogue.hpp> #endif
0
repos/range-v3/include/range/v3
repos/range-v3/include/range/v3/utility/functional.hpp
// Range v3 library // // Copyright Eric Niebler 2013-present // Copyright Casey Carter 2016 // // Use, modification and distribution is subject to the // Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) // // Project home: https://github.com/ericniebler/range-v3 // #ifndef RANGES_V3_UTILITY_FUNCTIONAL_HPP #define RANGES_V3_UTILITY_FUNCTIONAL_HPP #include <range/v3/detail/config.hpp> RANGES_DEPRECATED_HEADER( "This header has been deprecated. Please find what you are looking for in the " "range/v3/functional/ directory.") #include <range/v3/detail/with_braced_init_args.hpp> #include <range/v3/functional/arithmetic.hpp> #include <range/v3/functional/bind.hpp> #include <range/v3/functional/bind_back.hpp> #include <range/v3/functional/comparisons.hpp> #include <range/v3/functional/compose.hpp> #include <range/v3/functional/concepts.hpp> #include <range/v3/functional/identity.hpp> #include <range/v3/functional/indirect.hpp> #include <range/v3/functional/invoke.hpp> #include <range/v3/functional/not_fn.hpp> #include <range/v3/functional/on.hpp> #include <range/v3/functional/overload.hpp> #include <range/v3/functional/pipeable.hpp> #include <range/v3/functional/reference_wrapper.hpp> namespace ranges { using detail::with_braced_init_args; } // namespace ranges #endif
0
repos/range-v3/include/range/v3
repos/range-v3/include/range/v3/utility/get.hpp
/// \file // Range v3 library // // Copyright Eric Niebler 2013-present // // Use, modification and distribution is subject to the // Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) // // Project home: https://github.com/ericniebler/range-v3 // #ifndef RANGES_V3_UTILITY_GET_HPP #define RANGES_V3_UTILITY_GET_HPP #include <meta/meta.hpp> #include <concepts/concepts.hpp> #include <range/v3/detail/adl_get.hpp> #include <range/v3/detail/prologue.hpp> namespace ranges { /// \addtogroup group-utility Utility /// @{ /// /// \cond namespace _get_ { /// \endcond // clang-format off template<std::size_t I, typename TupleLike> constexpr auto CPP_auto_fun(get)(TupleLike &&t) ( return detail::adl_get<I>(static_cast<TupleLike &&>(t)) ) template<typename T, typename TupleLike> constexpr auto CPP_auto_fun(get)(TupleLike &&t) ( return detail::adl_get<T>(static_cast<TupleLike &&>(t)) ) // clang-format on template<typename T> T & get(meta::id_t<T> & value) noexcept { return value; } template<typename T> T const & get(meta::id_t<T> const & value) noexcept { return value; } template<typename T> T && get(meta::id_t<T> && value) noexcept { return static_cast<T &&>(value); } /// \cond } // namespace _get_ using namespace _get_; /// \endcond /// @} } // namespace ranges #include <range/v3/detail/epilogue.hpp> #endif
0
repos/range-v3/include/range/v3
repos/range-v3/include/range/v3/utility/iterator_traits.hpp
// Range v3 library // // Copyright Eric Niebler 2013-present // // Use, modification and distribution is subject to the // Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) // // Project home: https://github.com/ericniebler/range-v3 // #ifndef RANGES_V3_UTILITY_ITERATOR_TRAITS_HPP #define RANGES_V3_UTILITY_ITERATOR_TRAITS_HPP #include <range/v3/detail/config.hpp> RANGES_DEPRECATED_HEADER( "This header is deprecated. Please #include <range/v3/iterator/traits.hpp> instead.") #include <range/v3/iterator/traits.hpp> #endif // RANGES_V3_UTILITY_ITERATOR_TRAITS_HPP
0
repos/range-v3/include/range/v3
repos/range-v3/include/range/v3/utility/counted_iterator.hpp
// Range v3 library // // Copyright Eric Niebler 2014-present // // Use, modification and distribution is subject to the // Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) // // Project home: https://github.com/ericniebler/range-v3 // #ifndef RANGES_V3_UTILITY_COUNTED_ITERATOR_HPP #define RANGES_V3_UTILITY_COUNTED_ITERATOR_HPP #include <range/v3/detail/config.hpp> RANGES_DEPRECATED_HEADER( "This header is deprecated. Please #include <range/v3/iterator/counted_iterator.hpp> " "instead.") #include <range/v3/iterator/counted_iterator.hpp> #endif
0
repos/range-v3/include/range/v3
repos/range-v3/include/range/v3/utility/common_type.hpp
/// \file // Range v3 library // // Copyright Eric Niebler 2013-present // // Use, modification and distribution is subject to the // Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) // // Project home: https://github.com/ericniebler/range-v3 // #ifndef RANGES_V3_UTILITY_COMMON_TYPE_HPP #define RANGES_V3_UTILITY_COMMON_TYPE_HPP #include <tuple> #include <utility> #include <meta/meta.hpp> #include <concepts/type_traits.hpp> #include <range/v3/range_fwd.hpp> #include <range/v3/detail/prologue.hpp> // Sadly, this is necessary because of: // - std::common_type is !SFINAE-friendly, and // - The specification of std::common_type makes it impossibly // difficult to specialize on user-defined types without spamming // out a bajillion copies to handle all combinations of cv and ref // qualifiers. namespace ranges { template<typename... Ts> using common_type = concepts::common_type<Ts...>; template<typename... Ts> using common_type_t = concepts::common_type_t<Ts...>; template<typename... Ts> using common_reference = concepts::common_reference<Ts...>; template<typename... Ts> using common_reference_t = concepts::common_reference_t<Ts...>; /// \cond template<typename F, typename S> struct common_pair; template<typename... Ts> struct common_tuple; /// \endcond } // namespace ranges /// \cond // Specializations for pair and tuple namespace concepts { // common_type for std::pairs template<typename F1, typename S1, typename F2, typename S2> struct common_type<std::pair<F1, S1>, ::ranges::common_pair<F2, S2>>; template<typename F1, typename S1, typename F2, typename S2> struct common_type<::ranges::common_pair<F1, S1>, std::pair<F2, S2>>; template<typename F1, typename S1, typename F2, typename S2> struct common_type<::ranges::common_pair<F1, S1>, ::ranges::common_pair<F2, S2>>; // common_type for std::tuples template<typename... Ts, typename... Us> struct common_type<::ranges::common_tuple<Ts...>, std::tuple<Us...>>; template<typename... Ts, typename... Us> struct common_type<std::tuple<Ts...>, ::ranges::common_tuple<Us...>>; template<typename... Ts, typename... Us> struct common_type<::ranges::common_tuple<Ts...>, ::ranges::common_tuple<Us...>>; // A common reference for std::pairs template<typename F1, typename S1, typename F2, typename S2, template<typename> class Qual1, template<typename> class Qual2> struct basic_common_reference<::ranges::common_pair<F1, S1>, std::pair<F2, S2>, Qual1, Qual2>; template<typename F1, typename S1, typename F2, typename S2, template<typename> class Qual1, template<typename> class Qual2> struct basic_common_reference<std::pair<F1, S1>, ::ranges::common_pair<F2, S2>, Qual1, Qual2>; template<typename F1, typename S1, typename F2, typename S2, template<typename> class Qual1, template<typename> class Qual2> struct basic_common_reference<::ranges::common_pair<F1, S1>, ::ranges::common_pair<F2, S2>, Qual1, Qual2>; // A common reference for std::tuples template<typename... Ts, typename... Us, template<typename> class Qual1, template<typename> class Qual2> struct basic_common_reference<::ranges::common_tuple<Ts...>, std::tuple<Us...>, Qual1, Qual2>; template<typename... Ts, typename... Us, template<typename> class Qual1, template<typename> class Qual2> struct basic_common_reference<std::tuple<Ts...>, ::ranges::common_tuple<Us...>, Qual1, Qual2>; template<typename... Ts, typename... Us, template<typename> class Qual1, template<typename> class Qual2> struct basic_common_reference<::ranges::common_tuple<Ts...>, ::ranges::common_tuple<Us...>, Qual1, Qual2>; } // namespace concepts #if RANGES_CXX_VER > RANGES_CXX_STD_17 RANGES_DIAGNOSTIC_PUSH RANGES_DIAGNOSTIC_IGNORE_MISMATCHED_TAGS RANGES_BEGIN_NAMESPACE_STD RANGES_BEGIN_NAMESPACE_VERSION template<typename...> struct common_type; // common_type for std::pairs template<typename F1, typename S1, typename F2, typename S2> struct common_type<std::pair<F1, S1>, ::ranges::common_pair<F2, S2>>; template<typename F1, typename S1, typename F2, typename S2> struct common_type<::ranges::common_pair<F1, S1>, std::pair<F2, S2>>; template<typename F1, typename S1, typename F2, typename S2> struct common_type<::ranges::common_pair<F1, S1>, ::ranges::common_pair<F2, S2>>; // common_type for std::tuples template<typename... Ts, typename... Us> struct common_type<::ranges::common_tuple<Ts...>, std::tuple<Us...>>; template<typename... Ts, typename... Us> struct common_type<std::tuple<Ts...>, ::ranges::common_tuple<Us...>>; template<typename... Ts, typename... Us> struct common_type<::ranges::common_tuple<Ts...>, ::ranges::common_tuple<Us...>>; template<typename, typename, template<typename> class, template<typename> class> struct basic_common_reference; // A common reference for std::pairs template<typename F1, typename S1, typename F2, typename S2, template<typename> class Qual1, template<typename> class Qual2> struct basic_common_reference<::ranges::common_pair<F1, S1>, std::pair<F2, S2>, Qual1, Qual2>; template<typename F1, typename S1, typename F2, typename S2, template<typename> class Qual1, template<typename> class Qual2> struct basic_common_reference<std::pair<F1, S1>, ::ranges::common_pair<F2, S2>, Qual1, Qual2>; template<typename F1, typename S1, typename F2, typename S2, template<typename> class Qual1, template<typename> class Qual2> struct basic_common_reference<::ranges::common_pair<F1, S1>, ::ranges::common_pair<F2, S2>, Qual1, Qual2>; // A common reference for std::tuples template<typename... Ts, typename... Us, template<typename> class Qual1, template<typename> class Qual2> struct basic_common_reference<::ranges::common_tuple<Ts...>, std::tuple<Us...>, Qual1, Qual2>; template<typename... Ts, typename... Us, template<typename> class Qual1, template<typename> class Qual2> struct basic_common_reference<std::tuple<Ts...>, ::ranges::common_tuple<Us...>, Qual1, Qual2>; template<typename... Ts, typename... Us, template<typename> class Qual1, template<typename> class Qual2> struct basic_common_reference<::ranges::common_tuple<Ts...>, ::ranges::common_tuple<Us...>, Qual1, Qual2>; RANGES_END_NAMESPACE_VERSION RANGES_END_NAMESPACE_STD RANGES_DIAGNOSTIC_POP #endif // RANGES_CXX_VER > RANGES_CXX_STD_17 /// \endcond #include <range/v3/detail/epilogue.hpp> #endif
0
repos/range-v3/include/range/v3
repos/range-v3/include/range/v3/utility/invoke.hpp
// Range v3 library // // Copyright Eric Niebler 2013-present // Copyright Casey Carter 2016 // // Use, modification and distribution is subject to the // Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) // // Project home: https://github.com/ericniebler/range-v3 // #ifndef RANGES_V3_UTILITY_INVOKE_HPP #define RANGES_V3_UTILITY_INVOKE_HPP #include <range/v3/detail/config.hpp> RANGES_DEPRECATED_HEADER( "This file has been deprecated. Please #include <range/v3/functional/invoke.hpp> " "instead.") #include <range/v3/functional/invoke.hpp> #endif
0
repos/range-v3/include/range/v3
repos/range-v3/include/range/v3/utility/tagged_tuple.hpp
/// \file // Range v3 library // // Copyright Eric Niebler 2013-present // // Use, modification and distribution is subject to the // Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) // // Project home: https://github.com/ericniebler/range-v3 #ifndef RANGES_V3_UTILITY_TAGGED_TUPLE_HPP #define RANGES_V3_UTILITY_TAGGED_TUPLE_HPP #include <tuple> #include <range/v3/range_fwd.hpp> #include <range/v3/utility/tagged_pair.hpp> #include <range/v3/detail/prologue.hpp> RANGES_DIAGNOSTIC_PUSH RANGES_DIAGNOSTIC_IGNORE_DEPRECATED_DECLARATIONS namespace ranges { template<typename... Ts> using tagged_tuple RANGES_DEPRECATED("ranges::tagged_tuple is deprecated.") = tagged<std::tuple<detail::tag_elem<Ts>...>, detail::tag_spec<Ts>...>; template<typename... Tags, typename... Ts> RANGES_DEPRECATED("ranges::make_tagged_tuple is deprecated.") constexpr tagged_tuple<Tags(bind_element_t<Ts>)...> make_tagged_tuple(Ts &&... ts) { return tagged_tuple<Tags(bind_element_t<Ts>)...>{static_cast<Ts &&>(ts)...}; } } // namespace ranges RANGES_DIAGNOSTIC_POP #include <range/v3/detail/epilogue.hpp> #endif
0
repos/range-v3/include/range/v3
repos/range-v3/include/range/v3/utility/tagged_pair.hpp
/// \file // Range v3 library // // Copyright Eric Niebler 2013-present // Copyright Casey Carter 2016 // // Use, modification and distribution is subject to the // Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) // // Project home: https://github.com/ericniebler/range-v3 #ifndef RANGES_V3_UTILITY_TAGGED_PAIR_HPP #define RANGES_V3_UTILITY_TAGGED_PAIR_HPP #include <utility> #include <meta/meta.hpp> #include <concepts/concepts.hpp> #include <range/v3/range_fwd.hpp> #include <range/v3/detail/adl_get.hpp> #include <range/v3/utility/swap.hpp> #include <range/v3/detail/prologue.hpp> RANGES_DIAGNOSTIC_PUSH RANGES_DIAGNOSTIC_IGNORE_DEPRECATED_DECLARATIONS namespace ranges { /// \cond namespace detail { template<typename T> using tag_spec = meta::front<meta::as_list<T>>; template<typename T> using tag_elem = meta::back<meta::as_list<T>>; template<typename Base, std::size_t, typename...> struct tagged_chain { using type = _tuple_wrapper_::forward_tuple_interface<Base>; }; template<typename Base, std::size_t I, typename First, typename... Rest> struct tagged_chain<Base, I, First, Rest...> { using type = typename First::template getter< Base, I, meta::_t<tagged_chain<Base, I + 1, Rest...>>>; }; } // namespace detail #if RANGES_BROKEN_CPO_LOOKUP namespace _tagged_ { struct adl_hook_ {}; } // namespace _tagged_ #endif /// \endcond template<typename Base, typename... Tags> class RANGES_EMPTY_BASES RANGES_DEPRECATED( "Class template tagged is deprecated.") tagged : public meta::_t<detail::tagged_chain<Base, 0, Tags...>> #if RANGES_BROKEN_CPO_LOOKUP , private _tagged_::adl_hook_ #endif { CPP_assert(same_as<Base, uncvref_t<Base>>); using base_t = meta::_t<detail::tagged_chain<Base, 0, Tags...>>; template<typename Other> struct can_convert : meta::bool_<!RANGES_IS_SAME(Other, Base) && detail::is_convertible<Other, Base>::value> {}; public: tagged() = default; using base_t::base_t; template(typename Other)( requires can_convert<Other>::value) // constexpr tagged(tagged<Other, Tags...> && that) // noexcept(std::is_nothrow_constructible<Base, Other>::value) : base_t(static_cast<Other &&>(that)) {} template(typename Other)( requires can_convert<Other>::value) // constexpr tagged(tagged<Other, Tags...> const & that) // noexcept(std::is_nothrow_constructible<Base, Other const &>::value) : base_t(static_cast<Other const &>(that)) {} template(typename Other)( requires can_convert<Other>::value) // constexpr tagged & operator=(tagged<Other, Tags...> && that) // noexcept( noexcept(std::declval<Base &>() = static_cast<Other &&>(that))) { static_cast<Base &>(*this) = static_cast<Other &&>(that); return *this; } template(typename Other)( requires can_convert<Other>::value) // constexpr tagged & operator=(tagged<Other, Tags...> const & that) // noexcept( noexcept(std::declval<Base &>() = static_cast<Other const &>(that))) { static_cast<Base &>(*this) = static_cast<Other const &>(that); return *this; } template(typename U)( requires (!same_as<tagged, detail::decay_t<U>>) AND satisfies<Base &, std::is_assignable, U>) constexpr tagged & operator=(U && u) // noexcept(noexcept(std::declval<Base &>() = static_cast<U &&>(u))) { static_cast<Base &>(*this) = static_cast<U &&>(u); return *this; } template(typename B = Base)( requires is_swappable<B>::value) // constexpr void swap(tagged & that) noexcept(is_nothrow_swappable<B>::value) { ranges::swap(static_cast<Base &>(*this), static_cast<Base &>(that)); } #if !RANGES_BROKEN_CPO_LOOKUP template<typename B = Base> friend constexpr auto swap(tagged & x, tagged & y) // noexcept(is_nothrow_swappable<B>::value) -> CPP_broken_friend_ret(void)( requires is_swappable<B>::value) { x.swap(y); } #endif }; #if RANGES_BROKEN_CPO_LOOKUP namespace _tagged_ { template(typename Base, typename... Tags)( requires is_swappable<Base>::value) // constexpr void swap(tagged<Base, Tags...> & x, tagged<Base, Tags...> & y) // noexcept(is_nothrow_swappable<Base>::value) { x.swap(y); } } // namespace _tagged_ #endif template<typename F, typename S> using tagged_pair RANGES_DEPRECATED("ranges::tagged_pair is deprecated.") = tagged<std::pair<detail::tag_elem<F>, detail::tag_elem<S>>, detail::tag_spec<F>, detail::tag_spec<S>>; template<typename Tag1, typename Tag2, typename T1, typename T2, typename R = tagged_pair<Tag1(bind_element_t<T1>), Tag2(bind_element_t<T2>)>> RANGES_DEPRECATED("ranges::make_tagged_pair is deprecated.") constexpr R make_tagged_pair(T1 && t1, T2 && t2) noexcept( std::is_nothrow_constructible<R, T1, T2>::value) { return {static_cast<T1 &&>(t1), static_cast<T2 &&>(t2)}; } } // namespace ranges #define RANGES_DEFINE_TAG_SPECIFIER(NAME) \ namespace tag \ { \ struct NAME \ { \ template<typename Untagged, std::size_t I, typename Next> \ class getter : public Next \ { \ protected: \ ~getter() = default; \ \ public: \ getter() = default; \ getter(getter &&) = default; \ getter(getter const &) = default; \ using Next::Next; \ getter & operator=(getter &&) = default; \ getter & operator=(getter const &) = default; \ constexpr meta::_t<std::tuple_element<I, Untagged>> & NAME() & \ noexcept(noexcept(detail::adl_get<I>(std::declval<Untagged &>()))) \ { \ return detail::adl_get<I>(static_cast<Untagged &>(*this)); \ } \ constexpr meta::_t<std::tuple_element<I, Untagged>> && NAME() && \ noexcept(noexcept(detail::adl_get<I>(std::declval<Untagged>()))) \ { \ return detail::adl_get<I>(static_cast<Untagged &&>(*this)); \ } \ constexpr meta::_t<std::tuple_element<I, Untagged>> const & NAME() \ const & noexcept( \ noexcept(detail::adl_get<I>(std::declval<Untagged const &>()))) \ { \ return detail::adl_get<I>(static_cast<Untagged const &>(*this)); \ } \ }; \ }; \ } \ /**/ RANGES_DIAGNOSTIC_IGNORE_MISMATCHED_TAGS namespace std { template<typename Untagged, typename... Tags> struct tuple_size<::ranges::tagged<Untagged, Tags...>> : tuple_size<Untagged> {}; template<size_t N, typename Untagged, typename... Tags> struct tuple_element<N, ::ranges::tagged<Untagged, Tags...>> : tuple_element<N, Untagged> {}; } // namespace std RANGES_DIAGNOSTIC_POP #include <range/v3/detail/epilogue.hpp> #endif
0
repos/range-v3/include/range/v3
repos/range-v3/include/range/v3/utility/swap.hpp
/// \file // Range v3 library // // Copyright Eric Niebler 2013-present // // Use, modification and distribution is subject to the // Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) // // Project home: https://github.com/ericniebler/range-v3 // // The implementation of swap (see below) has been adapted from libc++ // (http://libcxx.llvm.org). #ifndef RANGES_V3_UTILITY_SWAP_HPP #define RANGES_V3_UTILITY_SWAP_HPP #include <concepts/swap.hpp> #include <range/v3/range_fwd.hpp> #include <range/v3/utility/static_const.hpp> #include <range/v3/detail/prologue.hpp> namespace ranges { template<typename T> using is_swappable = concepts::is_swappable<T>; template<typename T> using is_nothrow_swappable = concepts::is_nothrow_swappable<T>; template<typename T, typename U> using is_swappable_with = concepts::is_swappable_with<T, U>; template<typename T, typename U> using is_nothrow_swappable_with = concepts::is_nothrow_swappable_with<T, U>; using concepts::exchange; /// \ingroup group-utility /// \relates concepts::adl_swap_detail::swap_fn RANGES_DEFINE_CPO(uncvref_t<decltype(concepts::swap)>, swap) namespace cpp20 { using ranges::swap; } } // namespace ranges #include <range/v3/detail/epilogue.hpp> #endif
0
repos/range-v3/include/range/v3
repos/range-v3/include/range/v3/utility/variant.hpp
/// \file // Range v3 library // // Copyright Eric Niebler 2014-present // // Use, modification and distribution is subject to the // Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) // // Project home: https://github.com/ericniebler/range-v3 // #ifndef RANGES_V3_UTILITY_VARIANT_HPP #define RANGES_V3_UTILITY_VARIANT_HPP #include <range/v3/algorithm/copy.hpp> #include <range/v3/algorithm/move.hpp> #include <range/v3/detail/variant.hpp> #include <range/v3/iterator/move_iterators.hpp> #include <range/v3/iterator/operations.hpp> #include <range/v3/range/access.hpp> #include <range/v3/range/concepts.hpp> #include <range/v3/range/primitives.hpp> #include <range/v3/detail/prologue.hpp> namespace ranges { /// \cond namespace detail { template<typename T, std::size_t N, typename Index> struct indexed_datum<T[N], Index> { private: union { char c; T data_[N]; }; void fill_default_(T * p, std::true_type) { for(; p != ranges::end(data_); ++p) ::new((void *)p) T{}; } void fill_default_(T * p, std::false_type) { RANGES_EXPECT(p == ranges::end(data_)); } public: CPP_member constexpr CPP_ctor(indexed_datum)(meta::nil_ = {})( requires default_constructible<T>) : data_{} {} CPP_member CPP_ctor(indexed_datum)(indexed_datum && that)( requires move_constructible<T>) { std::uninitialized_copy_n(make_move_iterator(that.data_), N, data_); } CPP_member CPP_ctor(indexed_datum)(indexed_datum const & that)( requires copy_constructible<T>) { std::uninitialized_copy_n(that.data_, N, data_); } // \pre Requires distance(first, last) <= N // \pre Requires default_constructible<T> || distance(first, last) == N template(typename I, typename S)( requires sentinel_for<S, I> AND input_iterator<I> AND constructible_from<T, iter_reference_t<I>>) indexed_datum(I first, S last) { T * p = detail::uninitialized_copy(first, last, data_); this->fill_default_(p, meta::bool_<default_constructible<T>>{}); } // \pre Requires distance(r) <= N // \pre Requires default_constructible<T> || distance(r) == N template(typename R)( requires input_range<R> AND constructible_from<T, range_reference_t<R>>) explicit indexed_datum(R && r) : indexed_datum{ranges::begin(r), ranges::end(r)} {} CPP_member auto operator=(indexed_datum && that) // -> CPP_ret(indexed_datum &)( requires assignable_from<T &, T>) { ranges::move(that.data_, data_); return *this; } CPP_member auto operator=(indexed_datum const & that) // -> CPP_ret(indexed_datum &)( requires assignable_from<T &, T const &>) { ranges::copy(that.data_, data_); return *this; } // \pre Requires ranges::distance(r) <= N template(typename R)( requires input_range<R> AND assignable_from<T &, range_reference_t<R>>) indexed_datum & operator=(R && r) { ranges::copy(r, data_); return *this; } constexpr auto ref() { return indexed_element<T(&)[N], Index::value>{data_}; } constexpr auto ref() const { return indexed_element<T const(&)[N], Index::value>{data_}; } constexpr T (&get() noexcept)[N] { return data_; } constexpr T const (&get() const noexcept)[N] { return data_; } }; } // namespace detail /// \endcond } // namespace ranges #include <range/v3/detail/epilogue.hpp> #endif
0
repos/range-v3/include/range/v3
repos/range-v3/include/range/v3/utility/static_const.hpp
// Range v3 library // // Copyright Eric Niebler 2013-present // // Use, modification and distribution is subject to the // Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) // // Project home: https://github.com/ericniebler/range-v3 // #ifndef RANGES_V3_UTILITY_STATIC_CONST_HPP #define RANGES_V3_UTILITY_STATIC_CONST_HPP namespace ranges { /// \ingroup group-utility template<typename T> struct static_const { static constexpr T value{}; }; /// \ingroup group-utility /// \sa `static_const` template<typename T> constexpr T static_const<T>::value; } // namespace ranges #endif
0
repos/range-v3/include/range/v3
repos/range-v3/include/range/v3/utility/copy.hpp
/// \file // Range v3 library // // Copyright Eric Niebler 2013-present // // Use, modification and distribution is subject to the // Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) // // Project home: https://github.com/ericniebler/range-v3 // #ifndef RANGES_V3_UTILITY_COPY_HPP #define RANGES_V3_UTILITY_COPY_HPP #include <concepts/concepts.hpp> #include <range/v3/range_fwd.hpp> #include <range/v3/utility/static_const.hpp> #include <range/v3/detail/prologue.hpp> namespace ranges { /// \addtogroup group-utility /// @{ namespace aux { struct copy_fn : copy_tag { template(typename T)( requires constructible_from<detail::decay_t<T>, T>) constexpr auto operator()(T && t) const -> detail::decay_t<T> { return static_cast<T &&>(t); } /// \ingroup group-utility /// \sa `copy_fn` template<typename T> friend constexpr auto operator|(T && t, copy_fn) -> CPP_broken_friend_ret(detail::decay_t<T>)( requires constructible_from<detail::decay_t<T>, T>) { return static_cast<T &&>(t); } }; /// \ingroup group-utility /// \sa `copy_fn` RANGES_INLINE_VARIABLE(copy_fn, copy) } // namespace aux /// @} } // namespace ranges #include <range/v3/detail/epilogue.hpp> #endif
0
repos/range-v3/include/range/v3
repos/range-v3/include/range/v3/utility/addressof.hpp
// Range v3 library // // Copyright Eric Niebler 2013-present // // Use, modification and distribution is subject to the // Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) // // Project home: https://github.com/ericniebler/range-v3 // #ifndef RANGES_V3_UTILITY_ADDRESSOF_HPP #define RANGES_V3_UTILITY_ADDRESSOF_HPP #include <memory> #include <type_traits> #include <concepts/concepts.hpp> #include <range/v3/range_fwd.hpp> #include <range/v3/detail/config.hpp> #include <range/v3/detail/prologue.hpp> namespace ranges { /// \cond namespace detail { #ifdef __cpp_lib_addressof_constexpr using std::addressof; #else namespace check_addressof { inline ignore_t operator&(ignore_t) { return {}; } template<typename T> auto addressof(T & t) { return &t; } } // namespace check_addressof template<typename T> constexpr bool has_bad_addressof() { return !std::is_scalar<T>::value && !RANGES_IS_SAME(decltype(check_addressof::addressof(*(T *)nullptr)), ignore_t); } template(typename T)( requires(has_bad_addressof<T>())) T * addressof(T & arg) noexcept { return std::addressof(arg); } template(typename T)( requires (!has_bad_addressof<T>())) constexpr T * addressof(T & arg) noexcept { return &arg; } template<typename T> T const * addressof(T const &&) = delete; #endif } // namespace detail /// \endcond } // namespace ranges #include <range/v3/detail/epilogue.hpp> #endif
0
repos/range-v3/include/range/v3
repos/range-v3/include/range/v3/utility/iterator_concepts.hpp
// Range v3 library // // Copyright Eric Niebler 2013-present // // Use, modification and distribution is subject to the // Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) // // Project home: https://github.com/ericniebler/range-v3 // #ifndef RANGES_V3_UTILITY_ITERATOR_CONCEPTS_HPP #define RANGES_V3_UTILITY_ITERATOR_CONCEPTS_HPP #include <range/v3/detail/config.hpp> RANGES_DEPRECATED_HEADER( "This header is deprecated. Please #include <range/v3/iterator/concepts.hpp> " "instead.") #include <range/v3/iterator/concepts.hpp> #endif // RANGES_V3_UTILITY_ITERATOR_CONCEPTS_HPP
0
repos/range-v3/include/range/v3
repos/range-v3/include/range/v3/utility/associated_types.hpp
// Range v3 library // // Copyright Eric Niebler 2013-2014, 2016 // Copyright Casey Carter 2016 // // Use, modification and distribution is subject to the // Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) // // Project home: https://github.com/ericniebler/range-v3 // #ifndef RANGES_V3_UTILITY_ASSOCIATED_TYPES_HPP #define RANGES_V3_UTILITY_ASSOCIATED_TYPES_HPP #include <range/v3/detail/config.hpp> RANGES_DEPRECATED_HEADER( "This header is deprecated. Please #include <range/v3/iterator/traits.hpp> instead.") #include <range/v3/iterator/traits.hpp> #endif
0
repos/range-v3/include/range/v3
repos/range-v3/include/range/v3/utility/nullptr_v.hpp
// Range v3 library // // Copyright Eric Niebler 2013,2014. // // Use, modification and distribution is subject to the // Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) // // Project home: https://github.com/ericniebler/range-v3 // #ifndef RANGES_V3_UTILITY_NULLPTR_V_HPP #define RANGES_V3_UTILITY_NULLPTR_V_HPP #include <range/v3/detail/config.hpp> RANGES_DEPRECATED_HEADER( "This header is deprecated and will be removed from a future version of range-v3.") #include <range/v3/detail/prologue.hpp> namespace ranges { /// \ingroup group-utility template<typename T> constexpr T * _nullptr_v() { return nullptr; } #if RANGES_CXX_VARIABLE_TEMPLATES /// \ingroup group-utility template<typename T> constexpr T * nullptr_v = nullptr; #endif } // namespace ranges #include <range/v3/detail/epilogue.hpp> #endif
0
repos/range-v3/include/range/v3
repos/range-v3/include/range/v3/utility/polymorphic_cast.hpp
// (C) Copyright Kevlin Henney and Dave Abrahams 1999. // Distributed under the Boost // Software License, Version 1.0. (See accompanying file // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) #ifndef RANGES_V3_UTILITY_POLYMORPHIC_CAST_HPP #define RANGES_V3_UTILITY_POLYMORPHIC_CAST_HPP #include <memory> #include <type_traits> #include <meta/meta.hpp> #include <range/v3/detail/config.hpp> #include <range/v3/detail/prologue.hpp> namespace ranges { template<typename Target, typename Source> auto polymorphic_downcast(Source * x) noexcept -> meta::if_<std::is_pointer<Target>, decltype((static_cast<Target>(x), dynamic_cast<Target>(x)))> { auto result = static_cast<Target>(x); RANGES_ASSERT(dynamic_cast<Target>(x) == result); return result; } template<typename Target, typename Source> auto polymorphic_downcast(Source && x) noexcept -> meta::if_<std::is_reference<Target>, decltype((static_cast<Target>(std::declval<Source>()), dynamic_cast<Target>(std::declval<Source>())))> { auto && result = static_cast<Target>(static_cast<Source &&>(x)); #ifndef NDEBUG auto && dresult = dynamic_cast<Target>(static_cast<Source &&>(x)); RANGES_ASSERT(std::addressof(dresult) == std::addressof(result)); #endif return static_cast<Target>(result); } } // namespace ranges #include <range/v3/detail/epilogue.hpp> #endif // RANGES_V3_UTILITY_POLYMORPHIC_CAST_HPP
0
repos/range-v3/include/range/v3
repos/range-v3/include/range/v3/utility/dangling.hpp
// Range v3 library // // Copyright Eric Niebler 2013-present // // Use, modification and distribution is subject to the // Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) // // Project home: https://github.com/ericniebler/range-v3 // #ifndef RANGES_V3_UTILITY_DANGLING_HPP #define RANGES_V3_UTILITY_DANGLING_HPP #include <range/v3/detail/config.hpp> RANGES_DEPRECATED_HEADER( "This header is deprecated. Please #include <range/v3/range/dangling.hpp> instead.") #include <range/v3/range/dangling.hpp> #endif