Thanks for using Compiler Explorer
Sponsors
Jakt
C++
Ada
Algol68
Analysis
Android Java
Android Kotlin
Assembly
C
C3
Carbon
C with Coccinelle
C++ with Coccinelle
C++ (Circle)
CIRCT
Clean
CMake
CMakeScript
COBOL
C++ for OpenCL
MLIR
Cppx
Cppx-Blue
Cppx-Gold
Cpp2-cppfront
Crystal
C#
CUDA C++
D
Dart
Elixir
Erlang
Fortran
F#
GLSL
Go
Haskell
HLSL
Hook
Hylo
IL
ispc
Java
Julia
Kotlin
LLVM IR
LLVM MIR
Modula-2
Mojo
Nim
Numba
Nix
Objective-C
Objective-C++
OCaml
Odin
OpenCL C
Pascal
Pony
PTX
Python
Racket
Raku
Ruby
Rust
Sail
Snowball
Scala
Slang
Solidity
Spice
SPIR-V
Swift
LLVM TableGen
Toit
Triton
TypeScript Native
V
Vala
Visual Basic
Vyper
WASM
Zig
Javascript
GIMPLE
Ygen
sway
c++ source #1
Output
Compile to binary object
Link to binary
Execute the code
Intel asm syntax
Demangle identifiers
Verbose demangling
Filters
Unused labels
Library functions
Directives
Comments
Horizontal whitespace
Debug intrinsics
Compiler
6502-c++ 11.1.0
ARM GCC 10.2.0
ARM GCC 10.3.0
ARM GCC 10.4.0
ARM GCC 10.5.0
ARM GCC 11.1.0
ARM GCC 11.2.0
ARM GCC 11.3.0
ARM GCC 11.4.0
ARM GCC 12.1.0
ARM GCC 12.2.0
ARM GCC 12.3.0
ARM GCC 12.4.0
ARM GCC 12.5.0
ARM GCC 13.1.0
ARM GCC 13.2.0
ARM GCC 13.2.0 (unknown-eabi)
ARM GCC 13.3.0
ARM GCC 13.3.0 (unknown-eabi)
ARM GCC 13.4.0
ARM GCC 13.4.0 (unknown-eabi)
ARM GCC 14.1.0
ARM GCC 14.1.0 (unknown-eabi)
ARM GCC 14.2.0
ARM GCC 14.2.0 (unknown-eabi)
ARM GCC 14.3.0
ARM GCC 14.3.0 (unknown-eabi)
ARM GCC 15.1.0
ARM GCC 15.1.0 (unknown-eabi)
ARM GCC 15.2.0
ARM GCC 15.2.0 (unknown-eabi)
ARM GCC 4.5.4
ARM GCC 4.6.4
ARM GCC 5.4
ARM GCC 6.3.0
ARM GCC 6.4.0
ARM GCC 7.3.0
ARM GCC 7.5.0
ARM GCC 8.2.0
ARM GCC 8.5.0
ARM GCC 9.3.0
ARM GCC 9.4.0
ARM GCC 9.5.0
ARM GCC trunk
ARM gcc 10.2.1 (none)
ARM gcc 10.3.1 (2021.07 none)
ARM gcc 10.3.1 (2021.10 none)
ARM gcc 11.2.1 (none)
ARM gcc 5.4.1 (none)
ARM gcc 7.2.1 (none)
ARM gcc 8.2 (WinCE)
ARM gcc 8.3.1 (none)
ARM gcc 9.2.1 (none)
ARM msvc v19.0 (ex-WINE)
ARM msvc v19.10 (ex-WINE)
ARM msvc v19.14 (ex-WINE)
ARM64 Morello gcc 10.1 Alpha 2
ARM64 gcc 10.2
ARM64 gcc 10.3
ARM64 gcc 10.4
ARM64 gcc 10.5.0
ARM64 gcc 11.1
ARM64 gcc 11.2
ARM64 gcc 11.3
ARM64 gcc 11.4.0
ARM64 gcc 12.1
ARM64 gcc 12.2.0
ARM64 gcc 12.3.0
ARM64 gcc 12.4.0
ARM64 gcc 12.5.0
ARM64 gcc 13.1.0
ARM64 gcc 13.2.0
ARM64 gcc 13.3.0
ARM64 gcc 13.4.0
ARM64 gcc 14.1.0
ARM64 gcc 14.2.0
ARM64 gcc 14.3.0
ARM64 gcc 15.1.0
ARM64 gcc 15.2.0
ARM64 gcc 4.9.4
ARM64 gcc 5.4
ARM64 gcc 5.5.0
ARM64 gcc 6.3
ARM64 gcc 6.4
ARM64 gcc 7.3
ARM64 gcc 7.5
ARM64 gcc 8.2
ARM64 gcc 8.5
ARM64 gcc 9.3
ARM64 gcc 9.4
ARM64 gcc 9.5
ARM64 gcc trunk
ARM64 msvc v19.14 (ex-WINE)
AVR gcc 10.3.0
AVR gcc 11.1.0
AVR gcc 12.1.0
AVR gcc 12.2.0
AVR gcc 12.3.0
AVR gcc 12.4.0
AVR gcc 12.5.0
AVR gcc 13.1.0
AVR gcc 13.2.0
AVR gcc 13.3.0
AVR gcc 13.4.0
AVR gcc 14.1.0
AVR gcc 14.2.0
AVR gcc 14.3.0
AVR gcc 15.1.0
AVR gcc 15.2.0
AVR gcc 4.5.4
AVR gcc 4.6.4
AVR gcc 5.4.0
AVR gcc 9.2.0
AVR gcc 9.3.0
Arduino Mega (1.8.9)
Arduino Uno (1.8.9)
BPF clang (trunk)
BPF clang 13.0.0
BPF clang 14.0.0
BPF clang 15.0.0
BPF clang 16.0.0
BPF clang 17.0.1
BPF clang 18.1.0
BPF clang 19.1.0
BPF clang 20.1.0
BPF clang 21.1.0
EDG (experimental reflection)
EDG 6.5
EDG 6.5 (GNU mode gcc 13)
EDG 6.6
EDG 6.6 (GNU mode gcc 13)
EDG 6.7
EDG 6.7 (GNU mode gcc 14)
FRC 2019
FRC 2020
FRC 2023
HPPA gcc 14.2.0
HPPA gcc 14.3.0
HPPA gcc 15.1.0
HPPA gcc 15.2.0
KVX ACB 4.1.0 (GCC 7.5.0)
KVX ACB 4.1.0-cd1 (GCC 7.5.0)
KVX ACB 4.10.0 (GCC 10.3.1)
KVX ACB 4.11.1 (GCC 10.3.1)
KVX ACB 4.12.0 (GCC 11.3.0)
KVX ACB 4.2.0 (GCC 7.5.0)
KVX ACB 4.3.0 (GCC 7.5.0)
KVX ACB 4.4.0 (GCC 7.5.0)
KVX ACB 4.6.0 (GCC 9.4.1)
KVX ACB 4.8.0 (GCC 9.4.1)
KVX ACB 4.9.0 (GCC 9.4.1)
KVX ACB 5.0.0 (GCC 12.2.1)
KVX ACB 5.2.0 (GCC 13.2.1)
LoongArch64 clang (trunk)
LoongArch64 clang 17.0.1
LoongArch64 clang 18.1.0
LoongArch64 clang 19.1.0
LoongArch64 clang 20.1.0
LoongArch64 clang 21.1.0
M68K gcc 13.1.0
M68K gcc 13.2.0
M68K gcc 13.3.0
M68K gcc 13.4.0
M68K gcc 14.1.0
M68K gcc 14.2.0
M68K gcc 14.3.0
M68K gcc 15.1.0
M68K gcc 15.2.0
M68k clang (trunk)
MRISC32 gcc (trunk)
MSP430 gcc 4.5.3
MSP430 gcc 5.3.0
MSP430 gcc 6.2.1
MinGW clang 14.0.3
MinGW clang 14.0.6
MinGW clang 15.0.7
MinGW clang 16.0.0
MinGW clang 16.0.2
MinGW gcc 11.3.0
MinGW gcc 12.1.0
MinGW gcc 12.2.0
MinGW gcc 13.1.0
RISC-V (32-bits) gcc (trunk)
RISC-V (32-bits) gcc 10.2.0
RISC-V (32-bits) gcc 10.3.0
RISC-V (32-bits) gcc 11.2.0
RISC-V (32-bits) gcc 11.3.0
RISC-V (32-bits) gcc 11.4.0
RISC-V (32-bits) gcc 12.1.0
RISC-V (32-bits) gcc 12.2.0
RISC-V (32-bits) gcc 12.3.0
RISC-V (32-bits) gcc 12.4.0
RISC-V (32-bits) gcc 12.5.0
RISC-V (32-bits) gcc 13.1.0
RISC-V (32-bits) gcc 13.2.0
RISC-V (32-bits) gcc 13.3.0
RISC-V (32-bits) gcc 13.4.0
RISC-V (32-bits) gcc 14.1.0
RISC-V (32-bits) gcc 14.2.0
RISC-V (32-bits) gcc 14.3.0
RISC-V (32-bits) gcc 15.1.0
RISC-V (32-bits) gcc 15.2.0
RISC-V (32-bits) gcc 8.2.0
RISC-V (32-bits) gcc 8.5.0
RISC-V (32-bits) gcc 9.4.0
RISC-V (64-bits) gcc (trunk)
RISC-V (64-bits) gcc 10.2.0
RISC-V (64-bits) gcc 10.3.0
RISC-V (64-bits) gcc 11.2.0
RISC-V (64-bits) gcc 11.3.0
RISC-V (64-bits) gcc 11.4.0
RISC-V (64-bits) gcc 12.1.0
RISC-V (64-bits) gcc 12.2.0
RISC-V (64-bits) gcc 12.3.0
RISC-V (64-bits) gcc 12.4.0
RISC-V (64-bits) gcc 12.5.0
RISC-V (64-bits) gcc 13.1.0
RISC-V (64-bits) gcc 13.2.0
RISC-V (64-bits) gcc 13.3.0
RISC-V (64-bits) gcc 13.4.0
RISC-V (64-bits) gcc 14.1.0
RISC-V (64-bits) gcc 14.2.0
RISC-V (64-bits) gcc 14.3.0
RISC-V (64-bits) gcc 15.1.0
RISC-V (64-bits) gcc 15.2.0
RISC-V (64-bits) gcc 8.2.0
RISC-V (64-bits) gcc 8.5.0
RISC-V (64-bits) gcc 9.4.0
RISC-V rv32gc clang (trunk)
RISC-V rv32gc clang 10.0.0
RISC-V rv32gc clang 10.0.1
RISC-V rv32gc clang 11.0.0
RISC-V rv32gc clang 11.0.1
RISC-V rv32gc clang 12.0.0
RISC-V rv32gc clang 12.0.1
RISC-V rv32gc clang 13.0.0
RISC-V rv32gc clang 13.0.1
RISC-V rv32gc clang 14.0.0
RISC-V rv32gc clang 15.0.0
RISC-V rv32gc clang 16.0.0
RISC-V rv32gc clang 17.0.1
RISC-V rv32gc clang 18.1.0
RISC-V rv32gc clang 19.1.0
RISC-V rv32gc clang 20.1.0
RISC-V rv32gc clang 21.1.0
RISC-V rv32gc clang 9.0.0
RISC-V rv32gc clang 9.0.1
RISC-V rv64gc clang (trunk)
RISC-V rv64gc clang 10.0.0
RISC-V rv64gc clang 10.0.1
RISC-V rv64gc clang 11.0.0
RISC-V rv64gc clang 11.0.1
RISC-V rv64gc clang 12.0.0
RISC-V rv64gc clang 12.0.1
RISC-V rv64gc clang 13.0.0
RISC-V rv64gc clang 13.0.1
RISC-V rv64gc clang 14.0.0
RISC-V rv64gc clang 15.0.0
RISC-V rv64gc clang 16.0.0
RISC-V rv64gc clang 17.0.1
RISC-V rv64gc clang 18.1.0
RISC-V rv64gc clang 19.1.0
RISC-V rv64gc clang 20.1.0
RISC-V rv64gc clang 21.1.0
RISC-V rv64gc clang 9.0.0
RISC-V rv64gc clang 9.0.1
Raspbian Buster
Raspbian Stretch
SPARC LEON gcc 12.2.0
SPARC LEON gcc 12.3.0
SPARC LEON gcc 12.4.0
SPARC LEON gcc 12.5.0
SPARC LEON gcc 13.1.0
SPARC LEON gcc 13.2.0
SPARC LEON gcc 13.3.0
SPARC LEON gcc 13.4.0
SPARC LEON gcc 14.1.0
SPARC LEON gcc 14.2.0
SPARC LEON gcc 14.3.0
SPARC LEON gcc 15.1.0
SPARC LEON gcc 15.2.0
SPARC gcc 12.2.0
SPARC gcc 12.3.0
SPARC gcc 12.4.0
SPARC gcc 12.5.0
SPARC gcc 13.1.0
SPARC gcc 13.2.0
SPARC gcc 13.3.0
SPARC gcc 13.4.0
SPARC gcc 14.1.0
SPARC gcc 14.2.0
SPARC gcc 14.3.0
SPARC gcc 15.1.0
SPARC gcc 15.2.0
SPARC64 gcc 12.2.0
SPARC64 gcc 12.3.0
SPARC64 gcc 12.4.0
SPARC64 gcc 12.5.0
SPARC64 gcc 13.1.0
SPARC64 gcc 13.2.0
SPARC64 gcc 13.3.0
SPARC64 gcc 13.4.0
SPARC64 gcc 14.1.0
SPARC64 gcc 14.2.0
SPARC64 gcc 14.3.0
SPARC64 gcc 15.1.0
SPARC64 gcc 15.2.0
TI C6x gcc 12.2.0
TI C6x gcc 12.3.0
TI C6x gcc 12.4.0
TI C6x gcc 12.5.0
TI C6x gcc 13.1.0
TI C6x gcc 13.2.0
TI C6x gcc 13.3.0
TI C6x gcc 13.4.0
TI C6x gcc 14.1.0
TI C6x gcc 14.2.0
TI C6x gcc 14.3.0
TI C6x gcc 15.1.0
TI C6x gcc 15.2.0
TI CL430 21.6.1
Tricore gcc 11.3.0 (EEESlab)
VAX gcc NetBSDELF 10.4.0
VAX gcc NetBSDELF 10.5.0 (Nov 15 03:50:22 2023)
VAX gcc NetBSDELF 12.4.0 (Apr 16 05:27 2025)
WebAssembly clang (trunk)
Xtensa ESP32 gcc 11.2.0 (2022r1)
Xtensa ESP32 gcc 12.2.0 (20230208)
Xtensa ESP32 gcc 14.2.0 (20241119)
Xtensa ESP32 gcc 8.2.0 (2019r2)
Xtensa ESP32 gcc 8.2.0 (2020r1)
Xtensa ESP32 gcc 8.2.0 (2020r2)
Xtensa ESP32 gcc 8.4.0 (2020r3)
Xtensa ESP32 gcc 8.4.0 (2021r1)
Xtensa ESP32 gcc 8.4.0 (2021r2)
Xtensa ESP32-S2 gcc 11.2.0 (2022r1)
Xtensa ESP32-S2 gcc 12.2.0 (20230208)
Xtensa ESP32-S2 gcc 14.2.0 (20241119)
Xtensa ESP32-S2 gcc 8.2.0 (2019r2)
Xtensa ESP32-S2 gcc 8.2.0 (2020r1)
Xtensa ESP32-S2 gcc 8.2.0 (2020r2)
Xtensa ESP32-S2 gcc 8.4.0 (2020r3)
Xtensa ESP32-S2 gcc 8.4.0 (2021r1)
Xtensa ESP32-S2 gcc 8.4.0 (2021r2)
Xtensa ESP32-S3 gcc 11.2.0 (2022r1)
Xtensa ESP32-S3 gcc 12.2.0 (20230208)
Xtensa ESP32-S3 gcc 14.2.0 (20241119)
Xtensa ESP32-S3 gcc 8.4.0 (2020r3)
Xtensa ESP32-S3 gcc 8.4.0 (2021r1)
Xtensa ESP32-S3 gcc 8.4.0 (2021r2)
arm64 msvc v19.20 VS16.0
arm64 msvc v19.21 VS16.1
arm64 msvc v19.22 VS16.2
arm64 msvc v19.23 VS16.3
arm64 msvc v19.24 VS16.4
arm64 msvc v19.25 VS16.5
arm64 msvc v19.27 VS16.7
arm64 msvc v19.28 VS16.8
arm64 msvc v19.28 VS16.9
arm64 msvc v19.29 VS16.10
arm64 msvc v19.29 VS16.11
arm64 msvc v19.30 VS17.0
arm64 msvc v19.31 VS17.1
arm64 msvc v19.32 VS17.2
arm64 msvc v19.33 VS17.3
arm64 msvc v19.34 VS17.4
arm64 msvc v19.35 VS17.5
arm64 msvc v19.36 VS17.6
arm64 msvc v19.37 VS17.7
arm64 msvc v19.38 VS17.8
arm64 msvc v19.39 VS17.9
arm64 msvc v19.40 VS17.10
arm64 msvc v19.41 VS17.11
arm64 msvc v19.42 VS17.12
arm64 msvc v19.43 VS17.13
arm64 msvc v19.latest
armv7-a clang (trunk)
armv7-a clang 10.0.0
armv7-a clang 10.0.1
armv7-a clang 11.0.0
armv7-a clang 11.0.1
armv7-a clang 12.0.0
armv7-a clang 12.0.1
armv7-a clang 13.0.0
armv7-a clang 13.0.1
armv7-a clang 14.0.0
armv7-a clang 15.0.0
armv7-a clang 16.0.0
armv7-a clang 17.0.1
armv7-a clang 18.1.0
armv7-a clang 19.1.0
armv7-a clang 20.1.0
armv7-a clang 21.1.0
armv7-a clang 9.0.0
armv7-a clang 9.0.1
armv8-a clang (all architectural features, trunk)
armv8-a clang (trunk)
armv8-a clang 10.0.0
armv8-a clang 10.0.1
armv8-a clang 11.0.0
armv8-a clang 11.0.1
armv8-a clang 12.0.0
armv8-a clang 13.0.0
armv8-a clang 14.0.0
armv8-a clang 15.0.0
armv8-a clang 16.0.0
armv8-a clang 17.0.1
armv8-a clang 18.1.0
armv8-a clang 19.1.0
armv8-a clang 20.1.0
armv8-a clang 21.1.0
armv8-a clang 9.0.0
armv8-a clang 9.0.1
clad trunk (clang 21.1.0)
clad v1.10 (clang 20.1.0)
clad v1.8 (clang 18.1.0)
clad v1.9 (clang 19.1.0)
clad v2.00 (clang 20.1.0)
clang-cl 18.1.0
ellcc 0.1.33
ellcc 0.1.34
ellcc 2017-07-16
ez80-clang 15.0.0
ez80-clang 15.0.7
hexagon-clang 16.0.5
llvm-mos atari2600-3e
llvm-mos atari2600-4k
llvm-mos atari2600-common
llvm-mos atari5200-supercart
llvm-mos atari8-cart-megacart
llvm-mos atari8-cart-std
llvm-mos atari8-cart-xegs
llvm-mos atari8-common
llvm-mos atari8-dos
llvm-mos c128
llvm-mos c64
llvm-mos commodore
llvm-mos cpm65
llvm-mos cx16
llvm-mos dodo
llvm-mos eater
llvm-mos mega65
llvm-mos nes
llvm-mos nes-action53
llvm-mos nes-cnrom
llvm-mos nes-gtrom
llvm-mos nes-mmc1
llvm-mos nes-mmc3
llvm-mos nes-nrom
llvm-mos nes-unrom
llvm-mos nes-unrom-512
llvm-mos osi-c1p
llvm-mos pce
llvm-mos pce-cd
llvm-mos pce-common
llvm-mos pet
llvm-mos rp6502
llvm-mos rpc8e
llvm-mos supervision
llvm-mos vic20
loongarch64 gcc 12.2.0
loongarch64 gcc 12.3.0
loongarch64 gcc 12.4.0
loongarch64 gcc 12.5.0
loongarch64 gcc 13.1.0
loongarch64 gcc 13.2.0
loongarch64 gcc 13.3.0
loongarch64 gcc 13.4.0
loongarch64 gcc 14.1.0
loongarch64 gcc 14.2.0
loongarch64 gcc 14.3.0
loongarch64 gcc 15.1.0
loongarch64 gcc 15.2.0
mips clang 13.0.0
mips clang 14.0.0
mips clang 15.0.0
mips clang 16.0.0
mips clang 17.0.1
mips clang 18.1.0
mips clang 19.1.0
mips clang 20.1.0
mips clang 21.1.0
mips gcc 11.2.0
mips gcc 12.1.0
mips gcc 12.2.0
mips gcc 12.3.0
mips gcc 12.4.0
mips gcc 12.5.0
mips gcc 13.1.0
mips gcc 13.2.0
mips gcc 13.3.0
mips gcc 13.4.0
mips gcc 14.1.0
mips gcc 14.2.0
mips gcc 14.3.0
mips gcc 15.1.0
mips gcc 15.2.0
mips gcc 4.9.4
mips gcc 5.4
mips gcc 5.5.0
mips gcc 9.3.0 (codescape)
mips gcc 9.5.0
mips64 (el) gcc 12.1.0
mips64 (el) gcc 12.2.0
mips64 (el) gcc 12.3.0
mips64 (el) gcc 12.4.0
mips64 (el) gcc 12.5.0
mips64 (el) gcc 13.1.0
mips64 (el) gcc 13.2.0
mips64 (el) gcc 13.3.0
mips64 (el) gcc 13.4.0
mips64 (el) gcc 14.1.0
mips64 (el) gcc 14.2.0
mips64 (el) gcc 14.3.0
mips64 (el) gcc 15.1.0
mips64 (el) gcc 15.2.0
mips64 (el) gcc 4.9.4
mips64 (el) gcc 5.4.0
mips64 (el) gcc 5.5.0
mips64 (el) gcc 9.5.0
mips64 clang 13.0.0
mips64 clang 14.0.0
mips64 clang 15.0.0
mips64 clang 16.0.0
mips64 clang 17.0.1
mips64 clang 18.1.0
mips64 clang 19.1.0
mips64 clang 20.1.0
mips64 clang 21.1.0
mips64 gcc 11.2.0
mips64 gcc 12.1.0
mips64 gcc 12.2.0
mips64 gcc 12.3.0
mips64 gcc 12.4.0
mips64 gcc 12.5.0
mips64 gcc 13.1.0
mips64 gcc 13.2.0
mips64 gcc 13.3.0
mips64 gcc 13.4.0
mips64 gcc 14.1.0
mips64 gcc 14.2.0
mips64 gcc 14.3.0
mips64 gcc 15.1.0
mips64 gcc 15.2.0
mips64 gcc 4.9.4
mips64 gcc 5.4.0
mips64 gcc 5.5.0
mips64 gcc 9.5.0
mips64el clang 13.0.0
mips64el clang 14.0.0
mips64el clang 15.0.0
mips64el clang 16.0.0
mips64el clang 17.0.1
mips64el clang 18.1.0
mips64el clang 19.1.0
mips64el clang 20.1.0
mips64el clang 21.1.0
mipsel clang 13.0.0
mipsel clang 14.0.0
mipsel clang 15.0.0
mipsel clang 16.0.0
mipsel clang 17.0.1
mipsel clang 18.1.0
mipsel clang 19.1.0
mipsel clang 20.1.0
mipsel clang 21.1.0
mipsel gcc 12.1.0
mipsel gcc 12.2.0
mipsel gcc 12.3.0
mipsel gcc 12.4.0
mipsel gcc 12.5.0
mipsel gcc 13.1.0
mipsel gcc 13.2.0
mipsel gcc 13.3.0
mipsel gcc 13.4.0
mipsel gcc 14.1.0
mipsel gcc 14.2.0
mipsel gcc 14.3.0
mipsel gcc 15.1.0
mipsel gcc 15.2.0
mipsel gcc 4.9.4
mipsel gcc 5.4.0
mipsel gcc 5.5.0
mipsel gcc 9.5.0
nanoMIPS gcc 6.3.0 (mtk)
power gcc 11.2.0
power gcc 12.1.0
power gcc 12.2.0
power gcc 12.3.0
power gcc 12.4.0
power gcc 12.5.0
power gcc 13.1.0
power gcc 13.2.0
power gcc 13.3.0
power gcc 13.4.0
power gcc 14.1.0
power gcc 14.2.0
power gcc 14.3.0
power gcc 15.1.0
power gcc 15.2.0
power gcc 4.8.5
power64 AT12.0 (gcc8)
power64 AT13.0 (gcc9)
power64 gcc 11.2.0
power64 gcc 12.1.0
power64 gcc 12.2.0
power64 gcc 12.3.0
power64 gcc 12.4.0
power64 gcc 12.5.0
power64 gcc 13.1.0
power64 gcc 13.2.0
power64 gcc 13.3.0
power64 gcc 13.4.0
power64 gcc 14.1.0
power64 gcc 14.2.0
power64 gcc 14.3.0
power64 gcc 15.1.0
power64 gcc 15.2.0
power64 gcc trunk
power64le AT12.0 (gcc8)
power64le AT13.0 (gcc9)
power64le clang (trunk)
power64le gcc 11.2.0
power64le gcc 12.1.0
power64le gcc 12.2.0
power64le gcc 12.3.0
power64le gcc 12.4.0
power64le gcc 12.5.0
power64le gcc 13.1.0
power64le gcc 13.2.0
power64le gcc 13.3.0
power64le gcc 13.4.0
power64le gcc 14.1.0
power64le gcc 14.2.0
power64le gcc 14.3.0
power64le gcc 15.1.0
power64le gcc 15.2.0
power64le gcc 6.3.0
power64le gcc trunk
powerpc64 clang (trunk)
qnx 8.0.0
s390x gcc 11.2.0
s390x gcc 12.1.0
s390x gcc 12.2.0
s390x gcc 12.3.0
s390x gcc 12.4.0
s390x gcc 12.5.0
s390x gcc 13.1.0
s390x gcc 13.2.0
s390x gcc 13.3.0
s390x gcc 13.4.0
s390x gcc 14.1.0
s390x gcc 14.2.0
s390x gcc 14.3.0
s390x gcc 15.1.0
s390x gcc 15.2.0
sh gcc 12.2.0
sh gcc 12.3.0
sh gcc 12.4.0
sh gcc 12.5.0
sh gcc 13.1.0
sh gcc 13.2.0
sh gcc 13.3.0
sh gcc 13.4.0
sh gcc 14.1.0
sh gcc 14.2.0
sh gcc 14.3.0
sh gcc 15.1.0
sh gcc 15.2.0
sh gcc 4.9.4
sh gcc 9.5.0
vast (trunk)
x64 msvc v19.0 (ex-WINE)
x64 msvc v19.10 (ex-WINE)
x64 msvc v19.14 (ex-WINE)
x64 msvc v19.20 VS16.0
x64 msvc v19.21 VS16.1
x64 msvc v19.22 VS16.2
x64 msvc v19.23 VS16.3
x64 msvc v19.24 VS16.4
x64 msvc v19.25 VS16.5
x64 msvc v19.27 VS16.7
x64 msvc v19.28 VS16.8
x64 msvc v19.28 VS16.9
x64 msvc v19.29 VS16.10
x64 msvc v19.29 VS16.11
x64 msvc v19.30 VS17.0
x64 msvc v19.31 VS17.1
x64 msvc v19.32 VS17.2
x64 msvc v19.33 VS17.3
x64 msvc v19.34 VS17.4
x64 msvc v19.35 VS17.5
x64 msvc v19.36 VS17.6
x64 msvc v19.37 VS17.7
x64 msvc v19.38 VS17.8
x64 msvc v19.39 VS17.9
x64 msvc v19.40 VS17.10
x64 msvc v19.41 VS17.11
x64 msvc v19.42 VS17.12
x64 msvc v19.43 VS17.13
x64 msvc v19.latest
x86 djgpp 4.9.4
x86 djgpp 5.5.0
x86 djgpp 6.4.0
x86 djgpp 7.2.0
x86 msvc v19.0 (ex-WINE)
x86 msvc v19.10 (ex-WINE)
x86 msvc v19.14 (ex-WINE)
x86 msvc v19.20 VS16.0
x86 msvc v19.21 VS16.1
x86 msvc v19.22 VS16.2
x86 msvc v19.23 VS16.3
x86 msvc v19.24 VS16.4
x86 msvc v19.25 VS16.5
x86 msvc v19.27 VS16.7
x86 msvc v19.28 VS16.8
x86 msvc v19.28 VS16.9
x86 msvc v19.29 VS16.10
x86 msvc v19.29 VS16.11
x86 msvc v19.30 VS17.0
x86 msvc v19.31 VS17.1
x86 msvc v19.32 VS17.2
x86 msvc v19.33 VS17.3
x86 msvc v19.34 VS17.4
x86 msvc v19.35 VS17.5
x86 msvc v19.36 VS17.6
x86 msvc v19.37 VS17.7
x86 msvc v19.38 VS17.8
x86 msvc v19.39 VS17.9
x86 msvc v19.40 VS17.10
x86 msvc v19.41 VS17.11
x86 msvc v19.42 VS17.12
x86 msvc v19.43 VS17.13
x86 msvc v19.latest
x86 nvc++ 22.11
x86 nvc++ 22.7
x86 nvc++ 22.9
x86 nvc++ 23.1
x86 nvc++ 23.11
x86 nvc++ 23.3
x86 nvc++ 23.5
x86 nvc++ 23.7
x86 nvc++ 23.9
x86 nvc++ 24.1
x86 nvc++ 24.11
x86 nvc++ 24.3
x86 nvc++ 24.5
x86 nvc++ 24.7
x86 nvc++ 24.9
x86 nvc++ 25.1
x86 nvc++ 25.3
x86 nvc++ 25.5
x86 nvc++ 25.7
x86-64 Zapcc 190308
x86-64 clang (-fimplicit-constexpr)
x86-64 clang (Chris Bazley N3089)
x86-64 clang (EricWF contracts)
x86-64 clang (amd-staging)
x86-64 clang (assertions trunk)
x86-64 clang (clangir)
x86-64 clang (experimental -Wlifetime)
x86-64 clang (experimental P1061)
x86-64 clang (experimental P1144)
x86-64 clang (experimental P1221)
x86-64 clang (experimental P2998)
x86-64 clang (experimental P3068)
x86-64 clang (experimental P3309)
x86-64 clang (experimental P3367)
x86-64 clang (experimental P3372)
x86-64 clang (experimental P3385)
x86-64 clang (experimental P3776)
x86-64 clang (experimental metaprogramming - P2632)
x86-64 clang (old concepts branch)
x86-64 clang (p1974)
x86-64 clang (pattern matching - P2688)
x86-64 clang (reflection - C++26)
x86-64 clang (reflection - TS)
x86-64 clang (resugar)
x86-64 clang (string interpolation - P3412)
x86-64 clang (thephd.dev)
x86-64 clang (trunk)
x86-64 clang (variadic friends - P2893)
x86-64 clang (widberg)
x86-64 clang 10.0.0
x86-64 clang 10.0.0 (assertions)
x86-64 clang 10.0.1
x86-64 clang 11.0.0
x86-64 clang 11.0.0 (assertions)
x86-64 clang 11.0.1
x86-64 clang 12.0.0
x86-64 clang 12.0.0 (assertions)
x86-64 clang 12.0.1
x86-64 clang 13.0.0
x86-64 clang 13.0.0 (assertions)
x86-64 clang 13.0.1
x86-64 clang 14.0.0
x86-64 clang 14.0.0 (assertions)
x86-64 clang 15.0.0
x86-64 clang 15.0.0 (assertions)
x86-64 clang 16.0.0
x86-64 clang 16.0.0 (assertions)
x86-64 clang 17.0.1
x86-64 clang 17.0.1 (assertions)
x86-64 clang 18.1.0
x86-64 clang 18.1.0 (assertions)
x86-64 clang 19.1.0
x86-64 clang 19.1.0 (assertions)
x86-64 clang 2.6.0 (assertions)
x86-64 clang 2.7.0 (assertions)
x86-64 clang 2.8.0 (assertions)
x86-64 clang 2.9.0 (assertions)
x86-64 clang 20.1.0
x86-64 clang 20.1.0 (assertions)
x86-64 clang 21.1.0
x86-64 clang 21.1.0 (assertions)
x86-64 clang 3.0.0
x86-64 clang 3.0.0 (assertions)
x86-64 clang 3.1
x86-64 clang 3.1 (assertions)
x86-64 clang 3.2
x86-64 clang 3.2 (assertions)
x86-64 clang 3.3
x86-64 clang 3.3 (assertions)
x86-64 clang 3.4 (assertions)
x86-64 clang 3.4.1
x86-64 clang 3.5
x86-64 clang 3.5 (assertions)
x86-64 clang 3.5.1
x86-64 clang 3.5.2
x86-64 clang 3.6
x86-64 clang 3.6 (assertions)
x86-64 clang 3.7
x86-64 clang 3.7 (assertions)
x86-64 clang 3.7.1
x86-64 clang 3.8
x86-64 clang 3.8 (assertions)
x86-64 clang 3.8.1
x86-64 clang 3.9.0
x86-64 clang 3.9.0 (assertions)
x86-64 clang 3.9.1
x86-64 clang 4.0.0
x86-64 clang 4.0.0 (assertions)
x86-64 clang 4.0.1
x86-64 clang 5.0.0
x86-64 clang 5.0.0 (assertions)
x86-64 clang 5.0.1
x86-64 clang 5.0.2
x86-64 clang 6.0.0
x86-64 clang 6.0.0 (assertions)
x86-64 clang 6.0.1
x86-64 clang 7.0.0
x86-64 clang 7.0.0 (assertions)
x86-64 clang 7.0.1
x86-64 clang 7.1.0
x86-64 clang 8.0.0
x86-64 clang 8.0.0 (assertions)
x86-64 clang 8.0.1
x86-64 clang 9.0.0
x86-64 clang 9.0.0 (assertions)
x86-64 clang 9.0.1
x86-64 clang rocm-4.5.2
x86-64 clang rocm-5.0.2
x86-64 clang rocm-5.1.3
x86-64 clang rocm-5.2.3
x86-64 clang rocm-5.3.3
x86-64 clang rocm-5.7.0
x86-64 clang rocm-6.0.2
x86-64 clang rocm-6.1.2
x86-64 clang rocm-6.2.4
x86-64 clang rocm-6.3.3
x86-64 clang rocm-6.4.0
x86-64 gcc (P2034 lambdas)
x86-64 gcc (contract labels)
x86-64 gcc (contracts natural syntax)
x86-64 gcc (contracts)
x86-64 gcc (coroutines)
x86-64 gcc (modules)
x86-64 gcc (trunk)
x86-64 gcc 10.1
x86-64 gcc 10.2
x86-64 gcc 10.3
x86-64 gcc 10.3 (assertions)
x86-64 gcc 10.4
x86-64 gcc 10.4 (assertions)
x86-64 gcc 10.5
x86-64 gcc 10.5 (assertions)
x86-64 gcc 11.1
x86-64 gcc 11.1 (assertions)
x86-64 gcc 11.2
x86-64 gcc 11.2 (assertions)
x86-64 gcc 11.3
x86-64 gcc 11.3 (assertions)
x86-64 gcc 11.4
x86-64 gcc 11.4 (assertions)
x86-64 gcc 12.1
x86-64 gcc 12.1 (assertions)
x86-64 gcc 12.2
x86-64 gcc 12.2 (assertions)
x86-64 gcc 12.3
x86-64 gcc 12.3 (assertions)
x86-64 gcc 12.4
x86-64 gcc 12.4 (assertions)
x86-64 gcc 12.5
x86-64 gcc 12.5 (assertions)
x86-64 gcc 13.1
x86-64 gcc 13.1 (assertions)
x86-64 gcc 13.2
x86-64 gcc 13.2 (assertions)
x86-64 gcc 13.3
x86-64 gcc 13.3 (assertions)
x86-64 gcc 13.4
x86-64 gcc 13.4 (assertions)
x86-64 gcc 14.1
x86-64 gcc 14.1 (assertions)
x86-64 gcc 14.2
x86-64 gcc 14.2 (assertions)
x86-64 gcc 14.3
x86-64 gcc 14.3 (assertions)
x86-64 gcc 15.1
x86-64 gcc 15.1 (assertions)
x86-64 gcc 15.2
x86-64 gcc 15.2 (assertions)
x86-64 gcc 3.4.6
x86-64 gcc 4.0.4
x86-64 gcc 4.1.2
x86-64 gcc 4.4.7
x86-64 gcc 4.5.3
x86-64 gcc 4.6.4
x86-64 gcc 4.7.1
x86-64 gcc 4.7.2
x86-64 gcc 4.7.3
x86-64 gcc 4.7.4
x86-64 gcc 4.8.1
x86-64 gcc 4.8.2
x86-64 gcc 4.8.3
x86-64 gcc 4.8.4
x86-64 gcc 4.8.5
x86-64 gcc 4.9.0
x86-64 gcc 4.9.1
x86-64 gcc 4.9.2
x86-64 gcc 4.9.3
x86-64 gcc 4.9.4
x86-64 gcc 5.1
x86-64 gcc 5.2
x86-64 gcc 5.3
x86-64 gcc 5.4
x86-64 gcc 5.5
x86-64 gcc 6.1
x86-64 gcc 6.2
x86-64 gcc 6.3
x86-64 gcc 6.4
x86-64 gcc 6.5
x86-64 gcc 7.1
x86-64 gcc 7.2
x86-64 gcc 7.3
x86-64 gcc 7.4
x86-64 gcc 7.5
x86-64 gcc 8.1
x86-64 gcc 8.2
x86-64 gcc 8.3
x86-64 gcc 8.4
x86-64 gcc 8.5
x86-64 gcc 9.1
x86-64 gcc 9.2
x86-64 gcc 9.3
x86-64 gcc 9.4
x86-64 gcc 9.5
x86-64 icc 13.0.1
x86-64 icc 16.0.3
x86-64 icc 17.0.0
x86-64 icc 18.0.0
x86-64 icc 19.0.0
x86-64 icc 19.0.1
x86-64 icc 2021.1.2
x86-64 icc 2021.10.0
x86-64 icc 2021.2.0
x86-64 icc 2021.3.0
x86-64 icc 2021.4.0
x86-64 icc 2021.5.0
x86-64 icc 2021.6.0
x86-64 icc 2021.7.0
x86-64 icc 2021.7.1
x86-64 icc 2021.8.0
x86-64 icc 2021.9.0
x86-64 icx 2021.1.2
x86-64 icx 2021.2.0
x86-64 icx 2021.3.0
x86-64 icx 2021.4.0
x86-64 icx 2022.0.0
x86-64 icx 2022.1.0
x86-64 icx 2022.2.0
x86-64 icx 2022.2.1
x86-64 icx 2023.0.0
x86-64 icx 2023.1.0
x86-64 icx 2023.2.1
x86-64 icx 2024.0.0
x86-64 icx 2024.1.0
x86-64 icx 2024.2.0
x86-64 icx 2024.2.1
x86-64 icx 2025.0.0
x86-64 icx 2025.0.1
x86-64 icx 2025.0.3
x86-64 icx 2025.0.4
x86-64 icx 2025.1.0
x86-64 icx 2025.1.1
x86-64 icx 2025.2.0
x86-64 icx 2025.2.1
x86-64 icx 2025.2.1
z180-clang 15.0.0
z180-clang 15.0.7
z80-clang 15.0.0
z80-clang 15.0.7
zig c++ 0.10.0
zig c++ 0.11.0
zig c++ 0.12.0
zig c++ 0.12.1
zig c++ 0.13.0
zig c++ 0.14.0
zig c++ 0.14.1
zig c++ 0.15.1
zig c++ 0.6.0
zig c++ 0.7.0
zig c++ 0.7.1
zig c++ 0.8.0
zig c++ 0.9.0
zig c++ trunk
Options
Source code
//===----------------------------------------------------------------------===// // // Under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// // Copyright (c) Hui Xie, S. Levent Yilmaz #ifndef LIBCPP_RANGE_CONCAT_UTILS_HPP #define LIBCPP_RANGE_CONCAT_UTILS_HPP #include <functional> #include <utility> #include <tuple> #include <type_traits> namespace std::ranges::concat_detail { namespace tuple_or_pair_test { template <typename T, typename U> auto test() -> std::pair<T, U>; template <typename... Ts> requires(sizeof...(Ts) != 2) auto test() -> std::tuple<Ts...>; } // namespace tuple_or_pair_test // exposition only utilities from zip_view (zip_view is not implemented yet in libc++) // http://eel.is/c++draft/ranges#range.zip.view (perhaps we can reuse in the spec) // this paper proposed it to be moved out of zip_view // http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2021/p2374r3.html template <typename... Ts> using tuple_or_pair = decltype(tuple_or_pair_test::test<Ts...>()); template <typename F, typename Tuple> constexpr auto tuple_transform(F&& f, Tuple&& tuple) { return apply( [&]<class... Ts>(Ts && ... elements) { return tuple_or_pair<invoke_result_t<F&, Ts>...>( invoke(f, std::forward<Ts>(elements))...); }, std::forward<Tuple>(tuple)); } } // namespace std::ranges::concat_detail // Exposition only utilities, normalize cross-compiler: #ifdef _MSC_VER namespace std::ranges { template <bool C, typename T> using __maybe_const = _Maybe_const<C, T>; template <typename T> concept __has_arrow = _Has_arrow<T>; template <typename T> concept __simple_view = _Simple_view<T>; } // namespace std::ranges #endif #if defined(__GNUC__) && !defined(_LIBCPP_VERSION) namespace std::ranges { template <bool C, typename T> using __maybe_const = __detail::__maybe_const_t<C, T>; template <typename T> concept __has_arrow = __detail::__has_arrow<T>; template <typename T> concept __simple_view = __detail::__simple_view<T>; } // namespace std::ranges #endif #if defined(_LIBCPP_VERSION) namespace std::ranges { template <typename T> concept __has_arrow = std::__has_arrow<T>; } #endif #endif //===----------------------------------------------------------------------===// // // Under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// // Copyright (c) Hui Xie, S. Levent Yilmaz #ifndef LIBCPP__RANGE_CONCAT_HPP #define LIBCPP__RANGE_CONCAT_HPP #include <array> #include <cassert> #include <concepts> #include <functional> #include <numeric> #include <ranges> #include <tuple> #include <variant> // #include "utils.hpp" namespace std::ranges { namespace xo { // exposition only things (and persevering face) template <bool Const, class... Views> concept all_random_access = (random_access_range<__maybe_const<Const, Views>> && ...); template <bool Const, class... Views> concept all_bidirectional = (bidirectional_range<__maybe_const<Const, Views>> && ...); template <bool Const, class... Views> concept all_forward = (forward_range<__maybe_const<Const, Views>> && ...); inline namespace not_to_spec { template <class... Rs> using concat_reference_t = common_reference_t<range_reference_t<Rs>...>; template <class... Rs> using concat_rvalue_reference_t = common_reference_t<range_rvalue_reference_t<Rs>...>; template <class... Rs> using concat_value_t = common_type_t<range_value_t<Rs>...>; // clang-format off template <class Ref, class RRef, class It> concept concat_indirectly_readable_impl = requires (const It it){ { *it } -> convertible_to<Ref>; { ranges::iter_move(it) } -> convertible_to<RRef>; }; template <class... Rs> concept concat_indirectly_readable = common_reference_with<concat_reference_t<Rs...> &&, concat_value_t<Rs...>&>&& common_reference_with<concat_reference_t<Rs...>&&, concat_rvalue_reference_t<Rs...>&&>&& common_reference_with<concat_rvalue_reference_t<Rs...>&&, concat_value_t<Rs...> const&> && (concat_indirectly_readable_impl<concat_reference_t<Rs...>, concat_rvalue_reference_t<Rs...>, iterator_t<Rs>> && ...); // clang-format on } // namespace not_to_spec // clang-format off template <class... Rs> concept concatable = requires { typename concat_reference_t<Rs...>; typename concat_value_t<Rs...>; typename concat_rvalue_reference_t<Rs...>; } && concat_indirectly_readable<Rs...>; // clang-format on static_assert(true); // clang-format badness inline namespace not_to_spec { template <class... T> using back = tuple_element_t<sizeof...(T) - 1, tuple<T...>>; template <bool... b, size_t... I> consteval bool all_but_last_impl(std::index_sequence<I...>) { return ((I == sizeof...(I) - 1 || b) && ...); } template <bool... b> constexpr bool all_but_last = all_but_last_impl<b...>(make_index_sequence<sizeof...(b)>{}); template <bool... b, size_t... I> consteval bool all_but_first_impl(std::index_sequence<I...>) { return ((I == 0 || b) && ...); } template <bool... b> constexpr bool all_but_first = all_but_first_impl<b...>(make_index_sequence<sizeof...(b)>{}); } // namespace not_to_spec template <bool Const, class... Views> concept concat_is_random_access = (all_random_access<Const, Views> && ...) && (all_but_last<common_range<__maybe_const<Const, Views>>...>); template <bool Const, class... Views> concept concat_bidirectional = all_but_last<common_range<__maybe_const<Const, Views>>...> && all_bidirectional<Const, Views...>; static_assert(true); // clang-format badness inline namespace not_to_spec { // it is not defined in the standard and we can't refer to it. template <typename T> concept has_member_arrow = requires(T it) { it.operator->(); }; // iterator_traits<It>::pointer when present gives the result of arrow, or // presumably the result of arrow is convertible to that. // when iterator_traits<It>::pointer is not present for not-a-C++17-iterators, // we should get the pointer type from the arrow expression: template <__has_arrow It> decltype(auto) get_arrow_result(It&& it) { if constexpr (has_member_arrow<It>) { return static_cast<It&&>(it).operator->(); } else { return static_cast<It&&>(it); } } template <typename It> void get_arrow_result(It&&); template <class It> struct PointerTrait { using type = decltype(get_arrow_result(declval<It>())); }; template <class It> requires requires { typename iterator_traits<remove_reference_t<It>>::pointer; } struct PointerTrait<It> { using type = typename iterator_traits<remove_reference_t<It>>::pointer; }; template <class R> using range_pointer_t = typename PointerTrait<iterator_t<R>>::type; template <class... Views> using concat_pointer = common_type<range_pointer_t<Views>...>; // using concat_pointer = common_type<typename // iterator_traits<iterator_t<Views>>::pointer...>; // ^^ hard fails for not-a-c17iterator } // namespace not_to_spec template <class... Views> using concat_pointer_t = typename concat_pointer<Views...>::type; // clang-format off template <class... Views> concept concat_has_arrow = (__has_arrow<iterator_t<Views>> && ...) && requires { typename concat_pointer_t<Views...>; } && (convertible_to<const range_pointer_t<Views>&, concat_pointer_t<Views...>> && ...) ; // clang-format on inline namespace not_to_spec { template <bool Const, class... Ts> consteval auto iterator_concept_test() { if constexpr (concat_is_random_access<Const, Ts...>) { return random_access_iterator_tag{}; } else if constexpr (concat_bidirectional<Const, Ts...>) { return bidirectional_iterator_tag{}; } else if constexpr ((forward_range<__maybe_const<Const, Ts>> && ...)) { return forward_iterator_tag{}; } else { return input_iterator_tag{}; } } // calls f(integral_constant<idx>{}) for a runtime idx in [0,N) template <size_t N, typename Var, typename F> constexpr auto visit_i_impl(size_t idx, Var&& v, F&& f) { assert(idx < N); if constexpr (N > 1) { return idx == N - 1 ? invoke(static_cast<F&&>(f), integral_constant<size_t, N - 1>{}, std::get<N - 1>(static_cast<Var&&>(v))) : visit_i_impl<N - 1>(idx, static_cast<Var&&>(v), static_cast<F&&>(f)); } else { return invoke(static_cast<F&&>(f), integral_constant<size_t, 0>{}, std::get<0>(static_cast<Var&&>(v))); } } // calls f(integral_constant<idx>{}, get<idx>(v)) for idx == v.index(). template <typename Var, typename F> constexpr auto visit_i(Var&& v, F&& f) { return visit_i_impl<variant_size_v<remove_reference_t<Var>>>( v.index(), static_cast<Var&&>(v), static_cast<F&&>(f)); } template <typename tag, typename View> concept has_tag = derived_from<tag, typename iterator_traits<iterator_t<View>>::iterator_category>; template <bool Const, class... Views> consteval auto iter_cat_test() { using reference = common_reference_t<range_reference_t<__maybe_const<Const, Views>>...>; if constexpr (!is_reference_v<reference>) { return input_iterator_tag{}; } else if constexpr ((has_tag<random_access_iterator_tag, __maybe_const<Const, Views>> && ...) && concat_is_random_access<Const, Views...>) { return random_access_iterator_tag{}; } else if constexpr ((has_tag<bidirectional_iterator_tag, __maybe_const<Const, Views>> && ...) && concat_bidirectional<Const, Views...>) { return bidirectional_iterator_tag{}; } else if constexpr ((has_tag<forward_iterator_tag, __maybe_const<Const, Views>> && ...)) { return forward_iterator_tag{}; } else { return input_iterator_tag{}; } } struct empty_ {}; template <bool Const, class... Views> struct iter_cat_base { using iterator_category = decltype(iter_cat_test<Const, Views...>()); }; template <bool, class...> consteval auto iter_cat_base_sel() -> empty_; template <bool Const, class... Views> consteval auto iter_cat_base_sel() -> iter_cat_base<Const, Views...> requires((forward_range<__maybe_const<Const, Views>> && ...)); template <bool Const, class... Views> using iter_cat_base_t = decltype(iter_cat_base_sel<Const, Views...>()); } // namespace not_to_spec } // namespace xo // clang-format off // [TODO] constrain less and allow just a `view`? (i.e. including output_range in the mix - need an example) template <input_range... Views> requires (view<Views>&&...) && (sizeof...(Views) > 0) && xo::concatable<Views...> class concat_view : public view_interface<concat_view<Views...>> { // clang-format on tuple<Views...> views_; // exposition only template <bool Const> class iterator : public xo::iter_cat_base_t<Const, Views...> { public: using value_type = xo::concat_value_t<__maybe_const<Const, Views>...>; using difference_type = common_type_t<range_difference_t<__maybe_const<Const, Views>>...>; using iterator_concept = decltype(xo::iterator_concept_test<Const, Views...>()); private: using ParentView = __maybe_const<Const, concat_view>; using BaseIt = variant<iterator_t<__maybe_const<Const, Views>>...>; ParentView* parent_ = nullptr; BaseIt it_; friend class iterator<!Const>; friend class concat_view; template <std::size_t N> constexpr void satisfy() { if constexpr (N < (sizeof...(Views) - 1)) { if (get<N>(it_) == ranges::end(get<N>(parent_->views_))) { it_.template emplace<N + 1>( ranges::begin(get<N + 1>(parent_->views_))); satisfy<N + 1>(); } } } template <std::size_t N> constexpr void prev() { if constexpr (N == 0) { --get<0>(it_); } else { if (get<N>(it_) == ranges::begin(get<N>(parent_->views_))) { it_.template emplace<N - 1>( ranges::end(get<N - 1>(parent_->views_))); prev<N - 1>(); } else { --get<N>(it_); } } } template <std::size_t N> constexpr void advance_fwd(difference_type current_offset, difference_type steps) { using underlying_diff_type = std::iter_difference_t<std::variant_alternative_t<N, BaseIt>>; if constexpr (N == sizeof...(Views) - 1) { get<N>(it_) += static_cast<underlying_diff_type>(steps); } else { static_assert( std::ranges::common_range<decltype(get<N>(parent_->views_))>); auto n_size = ranges::distance(get<N>(parent_->views_)); if (current_offset + steps < n_size) { get<N>(it_) += static_cast<underlying_diff_type>(steps); } else { it_.template emplace<N + 1>( ranges::begin(get<N + 1>(parent_->views_))); advance_fwd<N + 1>( 0, current_offset + steps - n_size); } } } template <std::size_t N> constexpr void advance_bwd(difference_type current_offset, difference_type steps) { using underlying_diff_type = std::iter_difference_t<std::variant_alternative_t<N, BaseIt>>; if constexpr (N == 0) { get<N>(it_) -= static_cast<underlying_diff_type>(steps); } else { if (current_offset >= steps) { get<N>(it_) -= static_cast<underlying_diff_type>(steps); } else { static_assert( std::ranges::common_range<decltype(get<N - 1>(parent_->views_))>); auto prev_size = ranges::distance(get<N - 1>(parent_->views_)); it_.template emplace<N - 1>(ranges::end(get<N - 1>(parent_->views_))); advance_bwd<N - 1>(prev_size, steps - current_offset); } } } decltype(auto) get_parent_views() const { return (parent_->views_); } template <class... Args> explicit constexpr iterator(ParentView* parent, Args&&... args) requires constructible_from<BaseIt, Args&&...> : parent_{parent}, it_{static_cast<Args&&>(args)...} {} public: iterator() = default; constexpr iterator(iterator<!Const> i) requires Const && (convertible_to<iterator_t<Views>, iterator_t<const Views>>&&...) // [TODO] noexcept specs? : parent_{i.parent_}, it_{xo::visit_i(std::move(i.it_), [](auto I, auto&& it){ return BaseIt(in_place_index<I>, std::move(it)); })} {} constexpr decltype(auto) operator*() const { using reference = xo::concat_reference_t<__maybe_const<Const, Views>...>; return visit([](auto&& it) -> reference { return *it; }, it_); } constexpr auto operator->() const requires xo::concat_has_arrow<__maybe_const<Const, Views>...> { return visit( [](auto const& it) -> xo::concat_pointer_t<__maybe_const<Const, Views>...> { using It = remove_reference_t<decltype(it)>; if constexpr (xo::has_member_arrow<It>) { return it.operator->(); } else { static_assert(is_pointer_v<It>); return it; } }, it_); } constexpr iterator& operator++() { xo::visit_i(it_, [this](auto I, auto&& it) { ++it; this->satisfy<I>(); }); return *this; } constexpr void operator++(int) { ++*this; } constexpr iterator operator++(int) requires( forward_range<__maybe_const<Const, Views>>&&...) { auto tmp = *this; ++*this; return tmp; } constexpr iterator& operator--() requires xo::concat_bidirectional<Const, Views...> { xo::visit_i(it_, [this](auto I, auto&&) { this->prev<I>(); }); return *this; } constexpr iterator operator--( int) requires xo::concat_bidirectional<Const, Views...> { auto tmp = *this; --*this; return tmp; } constexpr iterator& operator+=(difference_type n) // requires xo::concat_is_random_access<Const, Views...> { if (n > 0) { xo::visit_i(it_, [this, n](auto I, auto&& it) { this->advance_fwd<I>(it - ranges::begin(get<I>(parent_->views_)), n); }); } else if (n < 0) { xo::visit_i(it_, [this, n](auto I, auto&& it) { this->advance_bwd<I>(it - ranges::begin(get<I>(parent_->views_)), -n); }); } return *this; } constexpr iterator& operator-=(difference_type n) // requires xo::concat_is_random_access<Const, Views...> { *this += -n; return *this; } constexpr decltype(auto) operator[](difference_type n) const // requires xo::concat_is_random_access<Const, Views...> { return *((*this) + n); } friend constexpr bool operator==(const iterator& it1, const iterator& it2) requires( equality_comparable<iterator_t<__maybe_const<Const, Views>>>&&...) { return it1.it_ == it2.it_; } friend constexpr bool operator==(const iterator& it, const default_sentinel_t&) { constexpr auto LastIdx = sizeof...(Views) - 1; return it.it_.index() == LastIdx && get<LastIdx>(it.it_) == ranges::end(get<LastIdx>(it.get_parent_views())); } friend constexpr bool operator<(const iterator& x, const iterator& y) requires( random_access_range<__maybe_const<Const, Views>>&&...) { return x.it_ < y.it_; } friend constexpr bool operator>(const iterator& x, const iterator& y) requires( random_access_range<__maybe_const<Const, Views>>&&...) { return y < x; } friend constexpr bool operator<=(const iterator& x, const iterator& y) requires( random_access_range<__maybe_const<Const, Views>>&&...) { return !(y < x); } friend constexpr bool operator>=(const iterator& x, const iterator& y) requires( random_access_range<__maybe_const<Const, Views>>&&...) { return !(x < y); } friend constexpr auto operator<=>(const iterator& x, const iterator& y) requires( (random_access_range<__maybe_const<Const, Views>> && three_way_comparable<iterator_t<__maybe_const<Const, Views>>>)&&...) { return x.it_ <=> y.it_; } friend constexpr iterator operator+(const iterator& it, difference_type n) requires xo::concat_is_random_access<Const, Views...> { auto temp = it; temp += n; return temp; } friend constexpr iterator operator+(difference_type n, const iterator& it) requires xo::concat_is_random_access<Const, Views...> { return it + n; } friend constexpr iterator operator-(const iterator& it, difference_type n) requires xo::concat_is_random_access<Const, Views...> { auto temp = it; temp -= n; return temp; } friend constexpr difference_type operator-(const iterator& x, const iterator& y) requires xo::concat_is_random_access<Const, Views...> { auto ix = x.it_.index(); auto iy = y.it_.index(); if (ix > iy) { // distance(y, yend) + size(ranges_in_between)... + distance(xbegin, x) const auto all_sizes = std::apply( [&](const auto&... views) { const auto getSize = [](const auto& view) { if constexpr (ranges::common_range<decay_t<decltype(view)>>) { return ranges::distance(view); } else { return 0; // only the last range can be non common, and its // value is not used } }; return std::array{ static_cast<difference_type>(getSize(views))...}; }, x.get_parent_views()); auto in_between = std::accumulate(all_sizes.data() + iy + 1, all_sizes.data() + ix, difference_type(0)); auto y_to_end = xo::visit_i(y.it_, [&](auto I, auto&& it) { return ranges::distance(it, ranges::end(get<I>(y.get_parent_views()))); }); auto begin_to_x = xo::visit_i(x.it_, [&](auto I, auto&& it) { return it - ranges::begin(get<I>(x.get_parent_views())); }); return y_to_end + in_between + begin_to_x; } else if (ix < iy) { return -(y - x); } else { return xo::visit_i(x.it_, [&](auto I, auto&&) { return get<I>(x.it_) - get<I>(y.it_); }); } } friend constexpr difference_type operator-(const iterator& it, default_sentinel_t) requires (sized_sentinel_for<sentinel_t<__maybe_const<Const, Views>>, iterator_t<__maybe_const<Const, Views>>> && ...) && (xo::all_but_first<sized_range<__maybe_const<Const, Views>>...>) { const auto idx = it.it_.index(); const auto all_sizes = std::apply( [&](const auto&... views) { return std::array{ static_cast<difference_type>(ranges::distance(views))...}; }, it.get_parent_views()); auto to_the_end = std::accumulate(all_sizes.begin() + idx + 1, all_sizes.end(), difference_type(0)); auto i_to_idx_end = xo::visit_i(it.it_, [&](auto I, auto&& i) { return ranges::distance(i, ranges::end(get<I>(it.get_parent_views()))); }); return -(i_to_idx_end + to_the_end); } friend constexpr difference_type operator-(default_sentinel_t, const iterator& it) requires (sized_sentinel_for<sentinel_t<__maybe_const<Const, Views>>, iterator_t<__maybe_const<Const, Views>>> && ...) && (xo::all_but_first<sized_range<__maybe_const<Const, Views>>...>) { return -(it - default_sentinel); } friend constexpr decltype(auto) iter_move(iterator const& ii) noexcept( ((std::is_nothrow_invocable_v< decltype(ranges::iter_move), const iterator_t<__maybe_const<Const, Views>>&> && std::is_nothrow_convertible_v< range_rvalue_reference_t<__maybe_const<Const, Views>>, xo::concat_rvalue_reference_t<__maybe_const<Const, Views>...>>)&&...)) { return std::visit( [](auto const& i) -> xo::concat_rvalue_reference_t< __maybe_const<Const, Views>...> { // return ranges::iter_move(i); }, ii.it_); } friend constexpr void iter_swap(const iterator& x, const iterator& y) requires swappable_with<iter_reference_t<iterator>, iter_reference_t<iterator>> && (...&& indirectly_swappable<iterator_t<__maybe_const<Const, Views>>>) // todo: noexcept? { std::visit( [&](const auto& it1, const auto& it2) { if constexpr (std::is_same_v<decltype(it1), decltype(it2)>) { ranges::iter_swap(it1, it2); } else { ranges::swap(*x, *y); } }, x.it_, y.it_); } }; public: constexpr concat_view() = default; constexpr explicit concat_view(Views... views) : views_{static_cast<Views&&>(views)...} {} constexpr iterator<false> begin() requires(!(__simple_view<Views> && ...)) // { iterator<false> it(this, in_place_index<0u>, ranges::begin(get<0>(views_))); it.template satisfy<0>(); return it; } constexpr iterator<true> begin() const requires((range<const Views> && ...) && xo::concatable<const Views...>) // { iterator<true> it(this, in_place_index<0u>, ranges::begin(get<0>(views_))); it.template satisfy<0>(); return it; } constexpr auto end() requires(!(__simple_view<Views> && ...)) { using LastView = xo::back<Views...>; if constexpr (common_range<LastView>) { constexpr auto N = sizeof...(Views); return iterator<false>(this, in_place_index<N - 1>, ranges::end(get<N - 1>(views_))); } else { return default_sentinel; } } constexpr auto end() const requires((range<const Views>&&...) && xo::concatable<const Views...>) { using LastView = xo::back<const Views...>; if constexpr (common_range<LastView>) { constexpr auto N = sizeof...(Views); return iterator<true>(this, in_place_index<N - 1>, ranges::end(get<N - 1>(views_))); } else { return default_sentinel; } } constexpr auto size() requires(sized_range<Views>&&...) { return apply( [](auto... sizes) { using CT = make_unsigned_t<common_type_t<decltype(sizes)...>>; return (CT(sizes) + ...); }, concat_detail::tuple_transform(ranges::size, views_)); } constexpr auto size() const requires(sized_range<const Views>&&...) { return apply( [](auto... sizes) { using CT = make_unsigned_t<common_type_t<decltype(sizes)...>>; return (CT{0} + ... + CT{sizes}); }, concat_detail::tuple_transform(ranges::size, views_)); } }; template <class... R> concat_view(R&&...) -> concat_view<views::all_t<R>...>; // cpo: namespace views { namespace xo { class concat_fn { public: constexpr void operator()() const = delete; template <viewable_range V> constexpr auto operator()(V&& v) const noexcept(noexcept(std::views::all(static_cast<V&&>(v)))) { return std::views::all(static_cast<V&&>(v)); } template <input_range... V> requires(sizeof...(V) > 1) && ranges::xo::concatable<all_t<V&&>...> && (viewable_range<V> && ...) // constexpr auto operator()(V&&... v) const { // noexcept(noexcept(concat_view{static_cast<V&&>(v)...})) { return concat_view{static_cast<V&&>(v)...}; } }; } // namespace xo inline constexpr xo::concat_fn concat; } // namespace views } // namespace std::ranges #endif namespace std::ranges::views { // HACK HACK using namespace xo; } #include <algorithm> #include <ranges> int main() { static constexpr auto con = {'c', 'o', 'n'}; static constexpr char cat[]{'c', 'a', 't', '\0'}; static constexpr auto concat{std::views::concat(con, cat)}; // overload (2) static_assert(std::ranges::equal(concat, "concat")); } /* https://en.cppreference.com/w/cpp/ranges/concat_view/concat_view#Example :) |output= */
Become a Patron
Sponsor on GitHub
Donate via PayPal
Compiler Explorer Shop
Source on GitHub
Mailing list
Installed libraries
Wiki
Report an issue
How it works
Contact the author
CE on Mastodon
CE on Bluesky
Statistics
Changelog
Version tree