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
Clojure
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
Helion
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
Yul (Solidity IR)
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
MinGW gcc 14.3.0
MinGW gcc 15.2.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.44 VS17.14
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)
clad v2.1 (clang 21.1.0)
clad v2.2 (clang 21.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.44 VS17.14
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 g++ 1.27
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.44 VS17.14
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 nvc++ 25.9
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 P2561)
x86-64 clang (experimental P2998)
x86-64 clang (experimental P3068)
x86-64 clang (experimental P3309)
x86-64 clang (experimental P3334)
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 clang rocm-7.0.1
x86-64 gcc (C++26 contracts + GNU extensions)
x86-64 gcc (C++26 contracts)
x86-64 gcc (C++26 reflection)
x86-64 gcc (P2034 lambdas)
x86-64 gcc (Thomas Healy)
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.3.0
x86-64 icx 2025.3.1
x86-64 icx 2025.3.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.15.2
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
#include <cassert> #include <new> #include <type_traits> #include <typeinfo> #include <utility> namespace std { typedef long unsigned int size_t; typedef long int ptrdiff_t; typedef decltype(nullptr) nullptr_t; } namespace std { inline namespace __cxx11 __attribute__((__abi_tag__ ("cxx11"))) { } } namespace __gnu_cxx { inline namespace __cxx11 __attribute__((__abi_tag__ ("cxx11"))) { } } static_assert(201703L >= 201402L, "__cplusplus >= 201402L"); #include <cstddef> namespace folly { constexpr bool kHasUnalignedAccess = true; } namespace folly { constexpr bool kIsArchArm = 0 == 1; constexpr bool kIsArchAmd64 = 1 == 1; constexpr bool kIsArchAArch64 = 0 == 1; constexpr bool kIsArchPPC64 = 0 == 1; } namespace folly { constexpr bool kIsLibrarySanitizeAddress = false; constexpr bool kIsSanitizeAddress = false; constexpr bool kIsSanitizeThread = false; constexpr bool kIsSanitize = false; } namespace folly { constexpr auto kIsDebug = true; } namespace folly { constexpr auto kHasExceptions = true; } namespace folly { constexpr auto kIsLittleEndian = 1234 == 1234; constexpr auto kIsBigEndian = !kIsLittleEndian; } namespace folly { constexpr bool const kHasRtti = 1; } namespace folly { constexpr auto kIsObjC = false; constexpr auto kIsMobile = false; constexpr auto kIsLinux = true; constexpr auto kIsWindows = false; constexpr auto kIsGlibcxx = true; constexpr auto kGlibcxxVer = 0; constexpr auto kIsLibcpp = false; constexpr auto kIsLibstdcpp = true; constexpr auto kMscVer = 0; constexpr auto kGnuc = 4; constexpr auto kIsClang = true; constexpr auto kMicrosoftAbiVer = 0; constexpr auto kCpplibVer = 0; } #include <functional> #include <limits> #include <memory> #include <tuple> #include <type_traits> namespace folly { template <typename...> struct tag_t {}; template <typename... T> inline constexpr tag_t<T...> tag; template <bool B> using bool_constant = std::integral_constant<bool, B>; template <std::size_t I> using index_constant = std::integral_constant<std::size_t, I>; namespace detail { template <template <typename...> class, typename> struct is_instantiation_of : std::false_type {}; template <template <typename...> class C, typename... T> struct is_instantiation_of<C, C<T...>> : std::true_type {}; template <template <typename...> class C, typename T> constexpr bool is_instantiation_of_v = is_instantiation_of<C, T>::value; } namespace detail { template <bool, typename T> struct is_constexpr_default_constructible_; template <typename T> struct is_constexpr_default_constructible_<false, T> { using type = std::false_type; }; template <typename T> struct is_constexpr_default_constructible_<true, T> { static constexpr int take(T) { return 0; } template <int = take(T{})> static std::true_type sfinae(int); static std::false_type sfinae(...); using type = decltype(sfinae(0)); }; } template <typename T> struct is_constexpr_default_constructible : detail::is_constexpr_default_constructible_< std::is_default_constructible<T>::value, T>::type {}; template <typename T> inline constexpr bool is_constexpr_default_constructible_v = is_constexpr_default_constructible<T>::value; template <typename T> using _t = typename T::type; template <typename T> struct remove_cvref { using type = typename std::remove_cv<typename std::remove_reference<T>::type>::type; }; template <typename T> using remove_cvref_t = typename remove_cvref<T>::type; namespace detail { template <typename Src> struct like_ { template <typename Dst> using apply = Dst; }; template <typename Src> struct like_<Src const> { template <typename Dst> using apply = Dst const; }; template <typename Src> struct like_<Src volatile> { template <typename Dst> using apply = Dst volatile; }; template <typename Src> struct like_<Src const volatile> { template <typename Dst> using apply = Dst const volatile; }; template <typename Src> struct like_<Src&> { template <typename Dst> using apply = typename like_<Src>::template apply<Dst>&; }; template <typename Src> struct like_<Src&&> { template <typename Dst> using apply = typename like_<Src>::template apply<Dst>&&; }; } template <typename Src, typename Dst> using like_t = typename detail::like_<Src>::template apply<remove_cvref_t<Dst>>; template <typename Src, typename Dst> struct like { using type = like_t<Src, Dst>; }; namespace traits_detail { template <class T, class...> struct type_t_ { using type = T; }; } template <class T, class... Ts> using type_t = typename traits_detail::type_t_<T, Ts...>::type; template <class... Ts> using void_t = type_t<void, Ts...>; template <typename T> using aligned_storage_for_t = typename std::aligned_storage<sizeof(T), alignof(T)>::type; template <class T> struct is_trivially_copyable : bool_constant<__is_trivially_copyable(T)> {}; template <class T> inline constexpr bool is_trivially_copyable_v = is_trivially_copyable<T>::value; namespace traits_detail { template <typename TTheClass_> struct has_IsRelocatable__folly_traits_impl__ { template <typename UTheClass_> static constexpr bool test(typename UTheClass_::IsRelocatable*) { return true; } template <typename> static constexpr bool test(...) { return false; } }; template <typename TTheClass_> using has_IsRelocatable = typename std::conditional< has_IsRelocatable__folly_traits_impl__<TTheClass_>::template test<TTheClass_>( nullptr), std::true_type, std::false_type>::type; template <class T> struct IsRelocatable_is_true : std::is_same<typename T::IsRelocatable, std::true_type> {}; template <class T> struct has_true_IsRelocatable : std::conditional< has_IsRelocatable<T>::value, IsRelocatable_is_true<T>, std::false_type>::type {}; template <typename TTheClass_> struct has_IsZeroInitializable__folly_traits_impl__ { template <typename UTheClass_> static constexpr bool test(typename UTheClass_::IsZeroInitializable*) { return true; } template <typename> static constexpr bool test(...) { return false; } }; template <typename TTheClass_> using has_IsZeroInitializable = typename std::conditional< has_IsZeroInitializable__folly_traits_impl__<TTheClass_>::template test<TTheClass_>( nullptr), std::true_type, std::false_type>::type; template <class T> struct IsZeroInitializable_is_true : std::is_same<typename T::IsZeroInitializable, std::true_type> {}; template <class T> struct has_true_IsZeroInitializable : std::conditional< has_IsZeroInitializable<T>::value, IsZeroInitializable_is_true<T>, std::false_type>::type {}; } struct Ignore { Ignore() = default; template <class T> constexpr Ignore(const T&) {} template <class T> const Ignore& operator=(T const&) const { return *this; } }; template <class...> using Ignored = Ignore; namespace traits_detail_IsEqualityComparable { Ignore operator==(Ignore, Ignore); template <class T, class U = T> struct IsEqualityComparable : std::is_convertible< decltype(std::declval<T>() == std::declval<U>()), bool> {}; } using traits_detail_IsEqualityComparable:: IsEqualityComparable; namespace traits_detail_IsLessThanComparable { Ignore operator<(Ignore, Ignore); template <class T, class U = T> struct IsLessThanComparable : std::is_convertible< decltype(std::declval<T>() < std::declval<U>()), bool> {}; } using traits_detail_IsLessThanComparable:: IsLessThanComparable; namespace traits_detail_IsNothrowSwappable { using std::swap; template <class T> struct IsNothrowSwappable : bool_constant<std::is_nothrow_move_constructible<T>::value&& noexcept( swap(std::declval<T&>(), std::declval<T&>()))> {}; } using traits_detail_IsNothrowSwappable::IsNothrowSwappable; template <class T> struct IsRelocatable : std::conditional< traits_detail::has_IsRelocatable<T>::value, traits_detail::has_true_IsRelocatable<T>, is_trivially_copyable<T>>::type {}; template <class T> struct IsZeroInitializable : std::conditional< traits_detail::has_IsZeroInitializable<T>::value, traits_detail::has_true_IsZeroInitializable<T>, bool_constant<!std::is_class<T>::value>>::type {}; namespace detail { template <bool> struct conditional_; template <> struct conditional_<false> { template <typename, typename T> using apply = T; }; template <> struct conditional_<true> { template <typename T, typename> using apply = T; }; } template <bool V, typename T, typename F> using conditional_t = typename detail::conditional_<V>::template apply<T, F>; template <typename...> struct Conjunction : std::true_type {}; template <typename T> struct Conjunction<T> : T {}; template <typename T, typename... TList> struct Conjunction<T, TList...> : std::conditional<T::value, Conjunction<TList...>, T>::type {}; template <typename...> struct Disjunction : std::false_type {}; template <typename T> struct Disjunction<T> : T {}; template <typename T, typename... TList> struct Disjunction<T, TList...> : std::conditional<T::value, T, Disjunction<TList...>>::type {}; template <typename T> struct Negation : bool_constant<!T::value> {}; template <bool... Bs> struct Bools { using valid_type = bool; static constexpr std::size_t size() { return sizeof...(Bs); } }; template <class... Ts> struct StrictConjunction : std::is_same<Bools<Ts::value...>, Bools<(Ts::value || true)...>> {}; template <class... Ts> struct StrictDisjunction : Negation< std::is_same<Bools<Ts::value...>, Bools<(Ts::value && false)...>>> {}; namespace detail { template <typename, typename> struct is_transparent_ : std::false_type {}; template <typename T> struct is_transparent_<void_t<typename T::is_transparent>, T> : std::true_type { }; } template <typename T> struct is_transparent : detail::is_transparent_<void, T> {}; } namespace folly { template <class T, class U> struct IsRelocatable<std::pair<T, U>> : bool_constant<IsRelocatable<T>::value && IsRelocatable<U>::value> {}; template <typename T, typename... Ts> using IsOneOf = StrictDisjunction<std::is_same<T, Ts>...>; template <typename T> constexpr bool is_negative(T x) { return std::is_signed<T>::value && x < T(0); } template <typename T> constexpr bool is_non_positive(T x) { return !x || folly::is_negative(x); } template <typename T> constexpr bool is_positive(T x) { return !is_non_positive(x); } template <typename T> constexpr bool is_non_negative(T x) { return !x || is_positive(x); } namespace detail { #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wsign-compare" template <typename RHS, RHS rhs, typename LHS> bool less_than_impl(LHS const lhs) { return (!std::is_signed<RHS>::value && is_negative(lhs)) ? true : (!std::is_signed<LHS>::value && is_negative(rhs)) ? false : rhs > std::numeric_limits<LHS>::max() ? true : rhs <= std::numeric_limits<LHS>::min() ? false : lhs < rhs; } template <typename RHS, RHS rhs, typename LHS> bool greater_than_impl(LHS const lhs) { return (!std::is_signed<RHS>::value && is_negative(lhs)) ? false : (!std::is_signed<LHS>::value && is_negative(rhs)) ? true : rhs > std::numeric_limits<LHS>::max() ? false : rhs < std::numeric_limits<LHS>::min() ? true : lhs > rhs; } #pragma GCC diagnostic pop } template <typename RHS, RHS rhs, typename LHS> bool less_than(LHS const lhs) { return detail:: less_than_impl<RHS, rhs, typename std::remove_reference<LHS>::type>(lhs); } template <typename RHS, RHS rhs, typename LHS> bool greater_than(LHS const lhs) { return detail:: greater_than_impl<RHS, rhs, typename std::remove_reference<LHS>::type>( lhs); } } namespace folly { template <class T1, class T2> struct IsRelocatable<std::unique_ptr<T1, T2> > : std::true_type {}; } namespace folly { template <class T1> struct IsRelocatable<std::shared_ptr<T1> > : std::true_type {}; } namespace std { template <> struct is_arithmetic<__int128> : ::std::true_type {}; template <> struct is_arithmetic<unsigned __int128> : ::std::true_type {}; template <> struct is_integral<__int128> : ::std::true_type {}; template <> struct is_integral<unsigned __int128> : ::std::true_type {}; template <> struct make_unsigned<__int128> { typedef unsigned __int128 type; }; template <> struct make_signed<__int128> { typedef __int128 type; }; template <> struct make_unsigned<unsigned __int128> { typedef unsigned __int128 type; }; template <> struct make_signed<unsigned __int128> { typedef __int128 type; }; template <> struct is_signed<__int128> : ::std::true_type {}; template <> struct is_unsigned<unsigned __int128> : ::std::true_type {}; } namespace folly { template <typename Container> const Container& order_preserving_reinsertion_view(const Container& container) { return container; } } #include <cstddef> #include <utility> #include <cstdint> #include <limits> #include <type_traits> #include <utility> namespace folly { template <typename T> constexpr typename std::decay<T>::type copy(T&& value) noexcept( noexcept(typename std::decay<T>::type(std::forward<T>(value)))) { return std::forward<T>(value); } template <class T> constexpr T const& as_const(T& t) noexcept { return t; } template <class T> void as_const(T const&&) = delete; template <typename Src, typename Dst> constexpr like_t<Src, Dst>&& forward_like(Dst&& dst) noexcept { return static_cast<like_t<Src, Dst>&&>(std::forward<Dst>(dst)); } struct in_place_tag {}; template <class> struct in_place_type_tag {}; template <std::size_t> struct in_place_index_tag {}; using in_place_t = in_place_tag (&)(in_place_tag); template <class T> using in_place_type_t = in_place_type_tag<T> (&)(in_place_type_tag<T>); template <std::size_t I> using in_place_index_t = in_place_index_tag<I> (&)(in_place_index_tag<I>); inline in_place_tag in_place(in_place_tag = {}) { return {}; } template <class T> inline in_place_type_tag<T> in_place_type(in_place_type_tag<T> = {}) { return {}; } template <std::size_t I> inline in_place_index_tag<I> in_place_index(in_place_index_tag<I> = {}) { return {}; } struct initlist_construct_t {}; constexpr initlist_construct_t initlist_construct{}; struct sorted_unique_t {}; constexpr sorted_unique_t sorted_unique; struct sorted_equivalent_t {}; constexpr sorted_equivalent_t sorted_equivalent; template <typename T> struct transparent : T { using is_transparent = void; using T::T; }; struct Identity { template <class T> constexpr T&& operator()(T&& x) const noexcept { return static_cast<T&&>(x); } }; namespace moveonly_ { class MoveOnly { protected: constexpr MoveOnly() = default; ~MoveOnly() = default; MoveOnly(MoveOnly&&) = default; MoveOnly& operator=(MoveOnly&&) = default; MoveOnly(const MoveOnly&) = delete; MoveOnly& operator=(const MoveOnly&) = delete; }; } using MoveOnly = moveonly_::MoveOnly; template <typename T> constexpr auto to_signed(T const& t) -> typename std::make_signed<T>::type { using S = typename std::make_signed<T>::type; constexpr auto m = static_cast<T>(std::numeric_limits<S>::max()); return m < t ? -static_cast<S>(~t) + S{-1} : static_cast<S>(t); } template <typename T> constexpr auto to_unsigned(T const& t) -> typename std::make_unsigned<T>::type { using U = typename std::make_unsigned<T>::type; return static_cast<U>(t); } template <typename Src> class to_narrow_convertible { public: static_assert(std::is_integral<Src>::value, "not an integer"); explicit constexpr to_narrow_convertible(Src const& value) noexcept : value_(value) {} explicit to_narrow_convertible(to_narrow_convertible const&) = default; explicit to_narrow_convertible(to_narrow_convertible&&) = default; to_narrow_convertible& operator=(to_narrow_convertible const&) = default; to_narrow_convertible& operator=(to_narrow_convertible&&) = default; template < typename Dst, std::enable_if_t< std::is_integral<Dst>::value && std::is_signed<Dst>::value == std::is_signed<Src>::value, int> = 0> constexpr operator Dst() const noexcept { #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wconversion" return value_; #pragma GCC diagnostic pop } private: Src value_; }; template <typename Src> constexpr auto to_narrow(Src const& src) -> to_narrow_convertible<Src> { return to_narrow_convertible<Src>{src}; } template <class E> constexpr std::underlying_type_t<E> to_underlying(E e) noexcept { static_assert(std::is_enum<E>::value, "not an enum type"); return static_cast<std::underlying_type_t<E>>(e); } } namespace folly { namespace detail { template <bool B> using Bool = bool_constant<B>; using True = std::true_type; using False = std::false_type; template <class Fn, class... Ts> using MetaApply = typename Fn::template apply<Ts...>; template <class... Ts> struct TypeList { using type = TypeList; static constexpr std::size_t size() noexcept { return sizeof...(Ts); } template <class Fn> using apply = MetaApply<Fn, Ts...>; }; template <class T> struct Type { using type = T; template <class...> using apply = T; }; struct Empty {}; namespace impl { template <bool B> struct If_ { template <class T, class U> using apply = T; }; template <> struct If_<false> { template <class T, class U> using apply = U; }; } template <bool If_, class Then, class Else> using If = MetaApply<impl::If_<If_>, Then, Else>; template <template <class...> class C, class... Ts> class MetaDefer { template <template <class...> class D, class = D<Ts...>> static char (&try_(int))[1]; template <template <class...> class D, class = void> static char (&try_(long))[2]; struct Result { using type = C<Ts...>; }; public: template <class... Us> using apply = _t<If<sizeof(try_<C>(0)) - 1 || sizeof...(Us), Empty, Result>>; }; template <class P, class Q> struct MetaCompose { template <class... Ts> using apply = MetaApply<P, MetaApply<Q, Ts...>>; }; struct MetaIdentity { template <class T> using apply = T; }; template <template <class...> class C> struct MetaQuote { template <class... Ts> using apply = MetaApply<MetaDefer<C, Ts...>>; }; template <> struct MetaQuote<TypeList> { template <class... Ts> using apply = TypeList<Ts...>; }; template <template <class...> class C> using MetaQuoteTrait = MetaCompose<MetaQuote<_t>, MetaQuote<C>>; template <class Fn, class... Ts> struct MetaBindFront { template <class... Us> using apply = MetaApply<Fn, Ts..., Us...>; }; template <class Fn, class... Ts> struct MetaBindBack { template <class... Us> using apply = MetaApply<Fn, Us..., Ts...>; }; template <class Fn> using MetaCurry = MetaCompose<Fn, MetaQuote<TypeList>>; template <class Fn> using MetaUncurry = MetaBindBack<MetaQuote<MetaApply>, Fn>; template <class List, class... Ts> using TypePushBack = MetaApply<List, MetaBindBack<MetaQuote<TypeList>, Ts...>>; template <class List, class... Ts> using TypePushFront = MetaApply<List, MetaBindFront<MetaQuote<TypeList>, Ts...>>; template <class Fn, class List> using MetaUnpack = MetaApply<List, Fn>; namespace impl { template <class Fn> struct TypeTransform_ { template <class... Ts> using apply = TypeList<MetaApply<Fn, Ts>...>; }; } template <class List, class Fn> using TypeTransform = MetaApply<List, impl::TypeTransform_<Fn>>; template <class Fn> struct MetaFlip { template <class A, class B> using apply = MetaApply<Fn, B, A>; }; namespace impl { template <class Fn> struct FoldR_ { template <class... Ts> struct Lambda : MetaIdentity {}; template <class A, class... Ts> struct Lambda<A, Ts...> { template <class State> using apply = MetaApply<Fn, A, MetaApply<Lambda<Ts...>, State>>; }; template <class A, class B, class C, class D, class... Ts> struct Lambda<A, B, C, D, Ts...> { template <class State> using apply = MetaApply< Fn, A, MetaApply< Fn, B, MetaApply< Fn, C, MetaApply<Fn, D, MetaApply<Lambda<Ts...>, State>>>>>; }; template <class... Ts> using apply = Lambda<Ts...>; }; } template <class List, class State, class Fn> using TypeFold = MetaApply<MetaApply<List, impl::FoldR_<Fn>>, State>; namespace impl { template <class Fn> struct FoldL_ { template <class... Ts> struct Lambda : MetaIdentity {}; template <class A, class... Ts> struct Lambda<A, Ts...> { template <class State> using apply = MetaApply<Lambda<Ts...>, MetaApply<Fn, State, A>>; }; template <class A, class B, class C, class D, class... Ts> struct Lambda<A, B, C, D, Ts...> { template <class State> using apply = MetaApply< Lambda<Ts...>, MetaApply< Fn, MetaApply<Fn, MetaApply<Fn, MetaApply<Fn, State, A>, B>, C>, D>>; }; template <class... Ts> using apply = Lambda<Ts...>; }; } template <class List, class State, class Fn> using TypeReverseFold = MetaApply<MetaApply<List, impl::FoldL_<Fn>>, State>; namespace impl { template <class List> struct Inherit_; template <class... Ts> struct Inherit_<TypeList<Ts...>> : Ts... { using type = Inherit_; }; } template <class List> using Inherit = impl::Inherit_<List>; namespace impl { template <class T, class... Set> using In_ = Bool<__is_base_of(Type<T>, Inherit<TypeList<Type<Set>...>>)>; template <class T> struct InsertFront_ { template <class... Set> using apply = If<In_<T, Set...>::value, TypeList<Set...>, TypeList<T, Set...>>; }; struct Unique_ { template <class T, class List> using apply = MetaApply<List, impl::InsertFront_<T>>; }; } template <class List> using TypeUnique = TypeFold<List, TypeList<>, impl::Unique_>; template <class List> using TypeReverseUnique = TypeReverseFold<List, TypeList<>, MetaFlip<impl::Unique_>>; namespace impl { template <class T> struct AsTypeList_ {}; template <template <class...> class T, class... Ts> struct AsTypeList_<T<Ts...>> { using type = TypeList<Ts...>; }; template <class T, T... Is> struct AsTypeList_<std::integer_sequence<T, Is...>> { using type = TypeList<std::integral_constant<T, Is>...>; }; } template <class T> using AsTypeList = _t<impl::AsTypeList_<T>>; namespace impl { struct Join_ { template <class Fn> struct Lambda { template <class... Ts> using apply = MetaBindBack<Fn, Ts...>; }; template <class List, class Fn> using apply = MetaApply<List, Lambda<Fn>>; }; } template <class List> using TypeJoin = MetaApply<TypeFold<List, MetaQuote<TypeList>, impl::Join_>>; template <class... Ts> using TypeConcat = TypeJoin<TypeList<Ts...>>; } } namespace folly { inline __attribute__((__always_inline__)) void assume(bool cond); [[noreturn]] inline __attribute__((__always_inline__)) void assume_unreachable(); } #include <cstdlib> namespace folly { namespace detail { extern void assume_check(bool cond); } inline __attribute__((__always_inline__)) void assume(bool cond) { if (kIsDebug) { detail::assume_check(cond); } else { __builtin_assume(cond); } } [[noreturn]] inline __attribute__((__always_inline__)) void assume_unreachable() { assume(false); __builtin_unreachable(); } } #include <exception> #include <typeinfo> namespace folly { struct __attribute__((__visibility__("default"))) BadPolyAccess : std::exception { BadPolyAccess() = default; char const* what() const noexcept override { return "BadPolyAccess"; } }; struct __attribute__((__visibility__("default"))) BadPolyCast : std::bad_cast { BadPolyCast() = default; char const* what() const noexcept override { return "BadPolyCast"; } }; } #include <functional> #include <new> #include <tuple> #include <type_traits> #include <typeinfo> #include <utility> #include <functional> #include <type_traits> #include <boost/preprocessor/control/expr_iif.hpp> #include <boost/preprocessor/facilities/is_empty_variadic.hpp> #include <boost/preprocessor/list/for_each.hpp> #include <boost/preprocessor/logical/not.hpp> #include <boost/preprocessor/tuple/to_list.hpp> namespace folly { template <typename F, typename... Args> inline __attribute__((__always_inline__)) __attribute__((__visibility__("hidden"))) constexpr auto invoke(F&& f, Args&&... args) noexcept( noexcept(static_cast<F&&>(f)(static_cast<Args&&>(args)...))) -> decltype(static_cast<F&&>(f)(static_cast<Args&&>(args)...)) { return static_cast<F&&>(f)(static_cast<Args&&>(args)...); } template <typename M, typename C, typename... Args> inline __attribute__((__always_inline__)) __attribute__((__visibility__("hidden"))) constexpr auto invoke(M(C::*d), Args&&... args) -> decltype(std::mem_fn(d)(static_cast<Args&&>(args)...)) { return std::mem_fn(d)(static_cast<Args&&>(args)...); } } namespace folly { namespace invoke_detail { template <typename F, typename... Args> using invoke_result_ = decltype(invoke(std::declval<F>(), std::declval<Args>()...)); template <typename F, typename... Args> struct invoke_nothrow_ : bool_constant<noexcept( invoke(std::declval<F>(), std::declval<Args>()...))> {}; template <typename Void, typename F, typename... Args> struct invoke_result {}; template <typename F, typename... Args> struct invoke_result<void_t<invoke_result_<F, Args...>>, F, Args...> { using type = invoke_result_<F, Args...>; }; template <typename Void, typename F, typename... Args> struct is_invocable : std::false_type {}; template <typename F, typename... Args> struct is_invocable<void_t<invoke_result_<F, Args...>>, F, Args...> : std::true_type {}; template <typename Void, typename R, typename F, typename... Args> struct is_invocable_r : std::false_type {}; template <typename R, typename F, typename... Args> struct is_invocable_r<void_t<invoke_result_<F, Args...>>, R, F, Args...> : std::is_convertible<invoke_result_<F, Args...>, R> {}; template <typename Void, typename F, typename... Args> struct is_nothrow_invocable : std::false_type {}; template <typename F, typename... Args> struct is_nothrow_invocable<void_t<invoke_result_<F, Args...>>, F, Args...> : invoke_nothrow_<F, Args...> {}; template <typename Void, typename R, typename F, typename... Args> struct is_nothrow_invocable_r : std::false_type {}; template <typename R, typename F, typename... Args> struct is_nothrow_invocable_r<void_t<invoke_result_<F, Args...>>, R, F, Args...> : StrictConjunction< std::is_convertible<invoke_result_<F, Args...>, R>, invoke_nothrow_<F, Args...>> {}; } template <typename F, typename... Args> struct invoke_result : invoke_detail::invoke_result<void, F, Args...> {}; template <typename F, typename... Args> using invoke_result_t = typename invoke_result<F, Args...>::type; template <typename F, typename... Args> struct is_invocable : invoke_detail::is_invocable<void, F, Args...> {}; template <typename F, typename... Args> inline constexpr bool is_invocable_v = is_invocable<F, Args...>::value; template <typename R, typename F, typename... Args> struct is_invocable_r : invoke_detail::is_invocable_r<void, R, F, Args...> {}; template <typename R, typename F, typename... Args> inline constexpr bool is_invocable_r_v = is_invocable_r<R, F, Args...>::value; template <typename F, typename... Args> struct is_nothrow_invocable : invoke_detail::is_nothrow_invocable<void, F, Args...> {}; template <typename F, typename... Args> inline constexpr bool is_nothrow_invocable_v = is_nothrow_invocable<F, Args...>::value; template <typename R, typename F, typename... Args> struct is_nothrow_invocable_r : invoke_detail::is_nothrow_invocable_r<void, R, F, Args...> {}; template <typename R, typename F, typename... Args> inline constexpr bool is_nothrow_invocable_r_v = is_nothrow_invocable_r<R, F, Args...>::value; } namespace folly { namespace detail { struct invoke_private_overload; template <bool, typename Invoke> struct invoke_traits_base_ {}; template <typename Invoke> struct invoke_traits_base_<false, Invoke> {}; template <typename Invoke> struct invoke_traits_base_<true, Invoke> { inline static constexpr Invoke invoke{}; }; template <typename Invoke> using invoke_traits_base = invoke_traits_base_<is_constexpr_default_constructible_v<Invoke>, Invoke>; } template <typename Invoke> struct invoke_traits : detail::invoke_traits_base<Invoke> { public: using invoke_type = Invoke; template <typename... Args> struct invoke_result : folly::invoke_result<Invoke, Args...> {}; template <typename... Args> using invoke_result_t = folly::invoke_result_t<Invoke, Args...>; template <typename... Args> struct is_invocable : folly::is_invocable<Invoke, Args...> {}; template <typename... Args> inline static constexpr bool is_invocable_v = is_invocable<Args...>::value; template <typename R, typename... Args> struct is_invocable_r : folly::is_invocable_r<R, Invoke, Args...> {}; template <typename R, typename... Args> inline static constexpr bool is_invocable_r_v = is_invocable_r<R, Args...>::value; template <typename... Args> struct is_nothrow_invocable : folly::is_nothrow_invocable<Invoke, Args...> {}; template <typename... Args> inline static constexpr bool is_nothrow_invocable_v = is_nothrow_invocable<Args...>::value; template <typename R, typename... Args> struct is_nothrow_invocable_r : folly::is_nothrow_invocable_r<R, Invoke, Args...> {}; template <typename R, typename... Args> inline static constexpr bool is_nothrow_invocable_r_v = is_nothrow_invocable_r<R, Args...>::value; }; } #include <exception> #include <type_traits> #include <utility> namespace folly { template <typename Ex> [[noreturn]] __attribute__((__noinline__)) __attribute__((__cold__)) void throw_exception(Ex&& ex) { throw static_cast<Ex&&>(ex); } template <typename Ex> [[noreturn]] __attribute__((__noinline__)) __attribute__((__cold__)) void terminate_with(Ex&& ex) noexcept { throw_exception(static_cast<Ex&&>(ex)); } namespace detail { template <typename T> inline __attribute__((__always_inline__)) __attribute__((__visibility__("hidden"))) T&& to_exception_arg_(T&& t) { return static_cast<T&&>(t); } template <std::size_t N> inline __attribute__((__always_inline__)) __attribute__((__visibility__("hidden"))) char const* to_exception_arg_( char const (&array)[N]) { return static_cast<char const*>(array); } template <typename Ex, typename... Args> [[noreturn]] __attribute__((__noinline__)) __attribute__((__cold__)) void throw_exception_(Args&&... args) { throw_exception(Ex(static_cast<Args&&>(args)...)); } template <typename Ex, typename... Args> [[noreturn]] __attribute__((__noinline__)) __attribute__((__cold__)) void terminate_with_( Args&&... args) noexcept { throw_exception(Ex(static_cast<Args&&>(args)...)); } } template <typename Ex, typename... Args> [[noreturn]] inline __attribute__((__always_inline__)) __attribute__((__visibility__("hidden"))) void throw_exception(Args&&... args) { detail::throw_exception_<Ex>( detail::to_exception_arg_(static_cast<Args&&>(args))...); } template <typename Ex, typename... Args> [[noreturn]] inline __attribute__((__always_inline__)) __attribute__((__visibility__("hidden"))) void terminate_with(Args&&... args) noexcept { detail::terminate_with_<Ex>( detail::to_exception_arg_(static_cast<Args&&>(args))...); } template <typename F, typename... A> __attribute__((__noinline__)) __attribute__((__cold__)) auto invoke_cold(F&& f, A&&... a) -> decltype(static_cast<F&&>(f)(static_cast<A&&>(a)...)) { return static_cast<F&&>(f)(static_cast<A&&>(a)...); } template <typename F, typename... A> [[noreturn]] __attribute__((__noinline__)) __attribute__((__cold__)) void invoke_noreturn_cold( F&& f, A&&... a) { static_cast<F&&>(f)(static_cast<A&&>(a)...); std::terminate(); } template <typename E, typename Try, typename Catch, typename... CatchA> inline __attribute__((__always_inline__)) __attribute__((__visibility__("hidden"))) auto catch_exception(Try&& t, Catch&& c, CatchA&&... a) -> typename std::common_type< decltype(static_cast<Try&&>(t)()), decltype(static_cast<Catch&&>( c)(std::declval<E>(), static_cast<CatchA&&>(a)...))>::type { try { return static_cast<Try&&>(t)(); } catch (E e) { return invoke_cold(static_cast<Catch&&>(c), e, static_cast<CatchA&&>(a)...); } } template <typename Try, typename Catch, typename... CatchA> inline __attribute__((__always_inline__)) __attribute__((__visibility__("hidden"))) auto catch_exception(Try&& t, Catch&& c, CatchA&&... a) -> typename std::common_type< decltype(static_cast<Try&&>(t)()), decltype(static_cast<Catch&&>(c)(static_cast<CatchA&&>(a)...))>::type { try { return static_cast<Try&&>(t)(); } catch (...) { return invoke_cold(static_cast<Catch&&>(c), static_cast<CatchA&&>(a)...); } } } namespace folly { template <typename T> struct StaticConst { static constexpr T value{}; }; template <typename T> constexpr T StaticConst<T>::value; } namespace folly { namespace detail { template <class I> struct PolyRoot; using RRef_ = MetaQuoteTrait<std::add_rvalue_reference>; using LRef_ = MetaQuoteTrait<std::add_lvalue_reference>; template <typename T> struct XRef_ : Type<MetaQuoteTrait<Type>> {}; template <typename T> using XRef = _t<XRef_<T>>; template <typename T> struct XRef_<T&&> : Type<MetaCompose<RRef_, XRef<T>>> {}; template <typename T> struct XRef_<T&> : Type<MetaCompose<LRef_, XRef<T>>> {}; template <typename T> struct XRef_<T const> : Type<MetaQuoteTrait<std::add_const>> {}; template <class A, class B> using AddCvrefOf = MetaApply<XRef<B>, A>; } template <class I> struct Poly; template <class T, class I> detail::AddCvrefOf<T, I>& poly_cast(detail::PolyRoot<I>&); template <class T, class I> detail::AddCvrefOf<T, I> const& poly_cast(detail::PolyRoot<I> const&); template <auto...> struct PolyMembers; namespace detail { template <class T, template <class...> class U> struct IsInstanceOf : std::false_type {}; template <class... Ts, template <class...> class U> struct IsInstanceOf<U<Ts...>, U> : std::true_type {}; template <class Then> decltype(auto) if_constexpr(std::true_type, Then then) { return then(Identity{}); } template <class Then> void if_constexpr(std::false_type, Then) {} template <class Then, class Else> decltype(auto) if_constexpr(std::true_type, Then then, Else) { return then(Identity{}); } template <class Then, class Else> decltype(auto) if_constexpr(std::false_type, Then, Else else_) { return else_(Identity{}); } enum class Op : short { eNuke, eMove, eCopy, eType, eAddr, eRefr }; enum class RefType : std::uintptr_t { eRvalue, eLvalue, eConstLvalue }; struct Data; template <class I> struct PolyVal; template <class I> struct PolyRef; struct PolyAccess; template <class T> using IsPoly = IsInstanceOf<remove_cvref_t<T>, Poly>; template <class I, class T> using MembersOf = typename I::template Members<remove_cvref_t<T>>; template <class I, class T> using InterfaceOf = typename I::template Interface<T>; template <auto M> using MemberType = decltype(M); template <auto M> inline constexpr MemberType<M> memberValue() noexcept { return M; } struct PolyBase {}; template <class I, class = void> struct SubsumptionsOf_ { using type = TypeList<>; }; template <class I> using InclusiveSubsumptionsOf = TypePushFront<_t<SubsumptionsOf_<I>>, I>; template <class I> struct SubsumptionsOf_<I, void_t<typename I::Subsumptions>> { using type = TypeJoin<TypeTransform< typename I::Subsumptions, MetaQuote<InclusiveSubsumptionsOf>>>; }; template <class I> using SubsumptionsOf = TypeReverseUnique<_t<SubsumptionsOf_<I>>>; struct Bottom { template <class T> [[noreturn]] operator T &&() const { std::terminate(); } }; using ArchetypeNode = MetaQuote<InterfaceOf>; template <class I> struct ArchetypeRoot; template <class I> using Archetype = TypeFold<InclusiveSubsumptionsOf<I>, ArchetypeRoot<I>, ArchetypeNode>; struct ArchetypeBase : Bottom { ArchetypeBase() = default; template <class T> ArchetypeBase(T&&); template <std::size_t, class... As> [[noreturn]] Bottom _polyCall_(As&&...) const { std::terminate(); } friend bool operator==(ArchetypeBase const&, ArchetypeBase const&); friend bool operator!=(ArchetypeBase const&, ArchetypeBase const&); friend bool operator<(ArchetypeBase const&, ArchetypeBase const&); friend bool operator<=(ArchetypeBase const&, ArchetypeBase const&); friend bool operator>(ArchetypeBase const&, ArchetypeBase const&); friend bool operator>=(ArchetypeBase const&, ArchetypeBase const&); friend Bottom operator++(ArchetypeBase const&); friend Bottom operator++(ArchetypeBase const&, int); friend Bottom operator--(ArchetypeBase const&); friend Bottom operator--(ArchetypeBase const&, int); friend Bottom operator+(ArchetypeBase const&, ArchetypeBase const&); friend Bottom operator+=(ArchetypeBase const&, ArchetypeBase const&); friend Bottom operator-(ArchetypeBase const&, ArchetypeBase const&); friend Bottom operator-=(ArchetypeBase const&, ArchetypeBase const&); friend Bottom operator*(ArchetypeBase const&, ArchetypeBase const&); friend Bottom operator*=(ArchetypeBase const&, ArchetypeBase const&); friend Bottom operator/(ArchetypeBase const&, ArchetypeBase const&); friend Bottom operator/=(ArchetypeBase const&, ArchetypeBase const&); friend Bottom operator%(ArchetypeBase const&, ArchetypeBase const&); friend Bottom operator%=(ArchetypeBase const&, ArchetypeBase const&); friend Bottom operator<<(ArchetypeBase const&, ArchetypeBase const&); friend Bottom operator<<=(ArchetypeBase const&, ArchetypeBase const&); friend Bottom operator>>(ArchetypeBase const&, ArchetypeBase const&); friend Bottom operator>>=(ArchetypeBase const&, ArchetypeBase const&); }; template <class I> struct ArchetypeRoot : ArchetypeBase { template <class Node, class Tfx> using _polySelf_ = Archetype<AddCvrefOf<MetaApply<Tfx, I>, Node>>; using _polyInterface_ = I; }; struct Data { Data() = default; Data(Data const&) {} Data& operator=(Data const&) { return *this; } union { void* pobj_ = nullptr; std::aligned_storage_t<sizeof(double[2])> buff_; }; }; template <class U, class I> using Arg = If<std::is_same<remove_cvref_t<U>, Archetype<I>>::value, Poly<AddCvrefOf<I, U const&>>, U>; template <class U, class I> using Ret = If<std::is_same<remove_cvref_t<U>, Archetype<I>>::value, AddCvrefOf<Poly<I>, U>, U>; template <class Member, class I> struct SignatureOf_; template <class R, class C, class... As, class I> struct SignatureOf_<R (C::*)(As...), I> { using type = Ret<R, I> (*)(Data&, Arg<As, I>...); }; template <class R, class C, class... As, class I> struct SignatureOf_<R (C::*)(As...) const, I> { using type = Ret<R, I> (*)(Data const&, Arg<As, I>...); }; template <class R, class C, class... As, class I> struct SignatureOf_<R (C::*)(As...) noexcept, I> { using type = std::add_pointer_t<Ret<R, I>(Data&, Arg<As, I>...) noexcept>; }; template <class R, class C, class... As, class I> struct SignatureOf_<R (C::*)(As...) const noexcept, I> { using type = std::add_pointer_t<Ret<R, I>(Data const&, Arg<As, I>...) noexcept>; }; template <class R, class This, class... As, class I> struct SignatureOf_<R (*)(This&, As...), I> { using type = Ret<R, I> (*)(Data&, Arg<As, I>...); }; template <class R, class This, class... As, class I> struct SignatureOf_<R (*)(This const&, As...), I> { using type = Ret<R, I> (*)(Data const&, Arg<As, I>...); }; template <auto Arch, class I> using SignatureOf = _t<SignatureOf_<MemberType<Arch>, I>>; template <auto User, class I, class Sig = SignatureOf<User, I>> struct ArgTypes_; template <auto User, class I, class Ret, class Data, class... Args> struct ArgTypes_<User, I, Ret (*)(Data, Args...)> { using type = TypeList<Args...>; }; template <auto User, class I, class Ret, class Data, class... Args> struct ArgTypes_<User, I, Ret (*)(Data, Args...) noexcept> { using type = TypeList<Args...>; }; template <auto User, class I> using ArgTypes = _t<ArgTypes_<User, I>>; template <class R, class... Args> using FnPtr = R (*)(Args...); struct ThrowThunk { template <class R, class... Args> constexpr operator FnPtr<R, Args...>() const noexcept { struct _ { static R call(Args...) { throw_exception<BadPolyAccess>(); } }; return &_::call; } }; inline constexpr ThrowThunk throw_() noexcept { return ThrowThunk{}; } template <class T> inline constexpr bool inSitu() noexcept { return !std::is_reference<T>::value && sizeof(std::decay_t<T>) <= sizeof(Data) && std::is_nothrow_move_constructible<std::decay_t<T>>::value; } template <class T> T& get(Data& d) noexcept { if (inSitu<T>()) { return *(std::add_pointer_t<T>)static_cast<void*>(&d.buff_); } else { return *static_cast<std::add_pointer_t<T>>(d.pobj_); } } template <class T> T const& get(Data const& d) noexcept { if (inSitu<T>()) { return *(std::add_pointer_t<T const>)static_cast<void const*>(&d.buff_); } else { return *static_cast<std::add_pointer_t<T const>>(d.pobj_); } } enum class State : short { eEmpty, eInSitu, eOnHeap }; template <class T> struct IsPolyRef : std::false_type {}; template <class T> struct IsPolyRef<Poly<T&>> : std::true_type {}; template <class Arg, class U> decltype(auto) convert(U&& u) { return detail::if_constexpr( StrictConjunction< IsPolyRef<remove_cvref_t<U>>, Negation<std::is_convertible<U, Arg>>>(), [&](auto id) -> decltype(auto) { return poly_cast<remove_cvref_t<Arg>>(id(u).get()); }, [&](auto id) -> U&& { return static_cast<U&&>(id(u)); }); } template <class Fun> struct IsConstMember : std::false_type {}; template <class R, class C, class... As> struct IsConstMember<R (C::*)(As...) const> : std::true_type {}; template <class R, class C, class... As> struct IsConstMember<R (*)(C const&, As...)> : std::true_type {}; template <class R, class C, class... As> struct IsConstMember<R (C::*)(As...) const noexcept> : std::true_type {}; template <class R, class C, class... As> struct IsConstMember<R (*)(C const&, As...) noexcept> : std::true_type {}; template < class T, auto User, class I, class = ArgTypes<User, I>, class = Bool<true>> struct ThunkFn { template <class R, class D, class... As> constexpr operator FnPtr<R, D&, As...>() const noexcept { return nullptr; } }; template <class T, auto User, class I, class... Args> struct ThunkFn< T, User, I, TypeList<Args...>, Bool< !std::is_const<std::remove_reference_t<T>>::value || IsConstMember<MemberType<User>>::value>> { template <class R, class D, class... As> constexpr operator FnPtr<R, D&, As...>() const noexcept { struct _ { static R call(D& d, As... as) { return folly::invoke( memberValue<User>(), get<T>(d), convert<Args>(static_cast<As&&>(as))...); } }; return &_::call; } }; template < class I, class = MembersOf<I, Archetype<I>>, class = SubsumptionsOf<I>> struct VTable; template <class T, auto User, class I> inline constexpr ThunkFn<T, User, I> thunk() noexcept { return ThunkFn<T, User, I>{}; } template <class I> constexpr VTable<I> const* vtable() noexcept { return &StaticConst<VTable<I>>::value; } template <class I, class T> struct VTableFor : VTable<I> { constexpr VTableFor() noexcept : VTable<I>{Type<T>{}} {} }; template <class I, class T> constexpr VTable<I> const* vtableFor() noexcept { return &StaticConst<VTableFor<I, T>>::value; } template <class I, class T> constexpr void* vtableForRef(RefType ref) { switch (ref) { case RefType::eRvalue: return const_cast<VTable<I>*>(vtableFor<I, T&&>()); case RefType::eLvalue: return const_cast<VTable<I>*>(vtableFor<I, T&>()); case RefType::eConstLvalue: return const_cast<VTable<I>*>(vtableFor<I, T const&>()); } return nullptr; } template < class I, class T, std::enable_if_t<std::is_reference<T>::value, int> = 0> void* execOnHeap(Op op, Data* from, void* to) { switch (op) { case Op::eNuke: break; case Op::eMove: case Op::eCopy: static_cast<Data*>(to)->pobj_ = from->pobj_; break; case Op::eType: return const_cast<void*>(static_cast<void const*>(&typeid(T))); case Op::eAddr: if (*static_cast<std::type_info const*>(to) == typeid(T)) { return from->pobj_; } throw_exception<BadPolyCast>(); case Op::eRefr: return vtableForRef<I, remove_cvref_t<T>>( static_cast<RefType>(reinterpret_cast<std::uintptr_t>(to))); } return nullptr; } template < class I, class T, std::enable_if_t<Negation<std::is_reference<T>>::value, int> = 0> void* execOnHeap(Op op, Data* from, void* to) { switch (op) { case Op::eNuke: delete &get<T>(*from); break; case Op::eMove: static_cast<Data*>(to)->pobj_ = std::exchange(from->pobj_, nullptr); break; case Op::eCopy: detail::if_constexpr(std::is_copy_constructible<T>(), [&](auto id) { static_cast<Data*>(to)->pobj_ = new T(id(get<T>(*from))); }); break; case Op::eType: return const_cast<void*>(static_cast<void const*>(&typeid(T))); case Op::eAddr: if (*static_cast<std::type_info const*>(to) == typeid(T)) { return from->pobj_; } throw_exception<BadPolyCast>(); case Op::eRefr: return vtableForRef<I, remove_cvref_t<T>>( static_cast<RefType>(reinterpret_cast<std::uintptr_t>(to))); } return nullptr; } template <class I, class T> void* execInSitu(Op op, Data* from, void* to) { switch (op) { case Op::eNuke: get<T>(*from).~T(); break; case Op::eMove: ::new (static_cast<void*>(&static_cast<Data*>(to)->buff_)) T(std::move(get<T>(*from))); get<T>(*from).~T(); break; case Op::eCopy: detail::if_constexpr(std::is_copy_constructible<T>(), [&](auto id) { ::new (static_cast<void*>(&static_cast<Data*>(to)->buff_)) T(id(get<T>(*from))); }); break; case Op::eType: return const_cast<void*>(static_cast<void const*>(&typeid(T))); case Op::eAddr: if (*static_cast<std::type_info const*>(to) == typeid(T)) { return &from->buff_; } throw_exception<BadPolyCast>(); case Op::eRefr: return vtableForRef<I, remove_cvref_t<T>>( static_cast<RefType>(reinterpret_cast<std::uintptr_t>(to))); } return nullptr; } inline void* noopExec(Op op, Data*, void*) { if (op == Op::eAddr) throw_exception<BadPolyAccess>(); return const_cast<void*>(static_cast<void const*>(&typeid(void))); } template <class I> struct BasePtr { VTable<I> const* vptr_; }; template <class I, class T> constexpr void* (*getOpsImpl(std::true_type) noexcept)(Op, Data*, void*) { return &execInSitu<I, T>; } template <class I, class T> constexpr void* (*getOpsImpl(std::false_type) noexcept)(Op, Data*, void*) { return &execOnHeap<I, T>; } template <class I, class T> constexpr void* (*getOps() noexcept)(Op, Data*, void*) { return getOpsImpl<I, T>(std::integral_constant<bool, inSitu<T>()>{}); } template <class I, auto... Arch, class... S> struct VTable<I, PolyMembers<Arch...>, TypeList<S...>> : BasePtr<S>..., std::tuple<SignatureOf<Arch, I>...> { private: template <class T, auto... User> constexpr VTable(Type<T>, PolyMembers<User...>) noexcept : BasePtr<S>{vtableFor<S, T>()}..., std::tuple<SignatureOf<Arch, I>...>{thunk<T, User, I>()...}, state_{inSitu<T>() ? State::eInSitu : State::eOnHeap}, ops_{getOps<I, T>()} {} public: constexpr VTable() noexcept : BasePtr<S>{vtable<S>()}..., std::tuple<SignatureOf<Arch, I>...>{ static_cast<SignatureOf<Arch, I>>(throw_())...}, state_{State::eEmpty}, ops_{&noopExec} {} template <class T> explicit constexpr VTable(Type<T>) noexcept : VTable{Type<T>{}, MembersOf<I, T>{}} {} State state_; void* (*ops_)(Op, Data*, void*); }; template <class I> constexpr VTable<I> const& select(VTable<_t<Type<I>>> const& vtbl) noexcept { return vtbl; } template <class I> constexpr VTable<I> const& select(BasePtr<_t<Type<I>>> const& base) noexcept { return *base.vptr_; } struct PolyAccess { template <std::size_t N, typename This, typename... As> static auto call(This&& _this, As&&... args) -> decltype(static_cast<This&&>(_this).template _polyCall_<N>( static_cast<As&&>(args)...)) { static_assert( !IsInstanceOf<std::decay_t<This>, Poly>::value, "When passing a Poly<> object to call(), you must explicitly " "say which Interface to dispatch to, as in " "call<0, MyInterface>(self, args...)"); return static_cast<This&&>(_this).template _polyCall_<N>( static_cast<As&&>(args)...); } template <class Poly> using Iface = typename remove_cvref_t<Poly>::_polyInterface_; template <class Node, class Tfx = MetaIdentity> static typename remove_cvref_t<Node>::template _polySelf_<Node, Tfx> self_(); template <class T, class Poly, class I = Iface<Poly>> static decltype(auto) cast(Poly&& _this) { using Ret = AddCvrefOf<AddCvrefOf<T, I>, Poly&&>; return static_cast<Ret>( *static_cast<std::add_pointer_t<Ret>>(_this.vptr_->ops_( Op::eAddr, const_cast<Data*>(static_cast<Data const*>(&_this)), const_cast<void*>(static_cast<void const*>(&typeid(T)))))); } template <class Poly> static decltype(auto) root(Poly&& _this) noexcept { return static_cast<Poly&&>(_this)._polyRoot_(); } template <class I> static std::type_info const& type(PolyRoot<I> const& _this) noexcept { return *static_cast<std::type_info const*>( _this.vptr_->ops_(Op::eType, nullptr, nullptr)); } template <class I> static VTable<remove_cvref_t<I>> const* vtable( PolyRoot<I> const& _this) noexcept { return _this.vptr_; } template <class I> static Data* data(PolyRoot<I>& _this) noexcept { return &_this; } template <class I> static Data const* data(PolyRoot<I> const& _this) noexcept { return &_this; } template <class I> static Poly<I&&> move(PolyRoot<I&> const& _this) noexcept { return Poly<I&&>{_this, Type<I&>{}}; } template <class I> static Poly<I const&> move(PolyRoot<I const&> const& _this) noexcept { return Poly<I const&>{_this, Type<I const&>{}}; } }; template <class I, class Tail> struct PolyNode : Tail { private: friend PolyAccess; using Tail::Tail; template <std::size_t K, typename... As> decltype(auto) _polyCall_(As&&... as) { return std::get<K>(select<I>(*PolyAccess::vtable(*this)))( *PolyAccess::data(*this), static_cast<As&&>(as)...); } template <std::size_t K, typename... As> decltype(auto) _polyCall_(As&&... as) const { return std::get<K>(select<I>(*PolyAccess::vtable(*this)))( *PolyAccess::data(*this), static_cast<As&&>(as)...); } }; struct MakePolyNode { template <class I, class State> using apply = InterfaceOf<I, PolyNode<I, State>>; }; template <class I> struct PolyRoot : private PolyBase, private Data { friend PolyAccess; friend Poly<I>; friend PolyVal<I>; friend PolyRef<I>; template <class Node, class Tfx> using _polySelf_ = Poly<AddCvrefOf<MetaApply<Tfx, I>, Node>>; using _polyInterface_ = I; private: PolyRoot& _polyRoot_() noexcept { return *this; } PolyRoot const& _polyRoot_() const noexcept { return *this; } VTable<std::decay_t<I>> const* vptr_ = vtable<std::decay_t<I>>(); }; template <class I> using PolyImpl = TypeFold< InclusiveSubsumptionsOf<remove_cvref_t<I>>, PolyRoot<I>, MakePolyNode>; template <class Fun> struct Sig { template <class T> constexpr Fun T::*operator()(Fun T::*t) const volatile noexcept { return t; } template <class F, class T> constexpr F T::*operator()(F T::*t) const volatile noexcept { return t; } }; template <class R> struct Sig<R()> : Sig<R() const> { using Fun = R(); using Sig<R() const>::operator(); template <class T> constexpr Fun T::*operator()(Fun T::*t) const noexcept { return t; } }; template <class R, class... As> struct SigImpl : Sig<R(As...) const> { using Fun = R(As...); using Sig<R(As...) const>::operator(); template <class T> constexpr Fun T::*operator()(Fun T::*t) const noexcept { return t; } constexpr Fun* operator()(Fun* t) const noexcept { return t; } template <class F> constexpr F* operator()(F* t) const noexcept { return t; } }; template <class R, class... As> struct Sig<R(As...)> : SigImpl<R, As...> {}; template <class R, class A, class... As> struct Sig<R(A&, As...)> : SigImpl<R, A&, As...> { using CCFun = R(A const&, As...); using SigImpl<R, A&, As...>::operator(); constexpr CCFun* operator()(CCFun* t) const volatile noexcept { return t; } }; template <class T, class I, class = void> struct ModelsInterface2_ : std::false_type {}; template <class T, class I> struct ModelsInterface2_< T, I, void_t< std::enable_if_t< std::is_constructible<AddCvrefOf<std::decay_t<T>, I>, T>::value>, MembersOf<std::decay_t<I>, std::decay_t<T>>>> : std::true_type {}; template <class T, class I, class = void> struct ModelsInterface_ : std::false_type {}; template <class T, class I> struct ModelsInterface_< T, I, std::enable_if_t< Negation<std::is_base_of<PolyBase, std::decay_t<T>>>::value>> : ModelsInterface2_<T, I> {}; template <class T, class I> struct ModelsInterface : ModelsInterface_<T, I> {}; template <class I1, class I2> struct ValueCompatible : std::is_base_of<I1, I2> {}; template <class I1> struct ValueCompatible<I1, I1> : std::false_type {}; template <class I1, class I2, class I2Ref> struct ReferenceCompatible : std::is_constructible<I1, I2Ref> {}; template <class I1, class I2Ref> struct ReferenceCompatible<I1, I1, I2Ref> : std::false_type {}; } } namespace folly { template <class I> struct Poly; template <class Node, class Tfx, class Access> struct PolySelf_ { using type = decltype(Access::template self_<Node, Tfx>()); }; template < class Node, class Tfx = detail::MetaIdentity, class Access = detail::PolyAccess> using PolySelf = _t<PolySelf_<Node, Tfx, Access>>; using PolyDecay = detail::MetaQuote<std::decay_t>; template <auto... Ps> struct PolyMembers {}; template <class... I> struct PolyExtends : virtual I... { using Subsumptions = detail::TypeList<I...>; template <class Base> struct Interface : Base { Interface() = default; using Base::Base; }; template <class...> using Members = PolyMembers<>; }; template <std::size_t N, typename This, typename... As> auto poly_call(This&& _this, As&&... as) -> decltype(detail::PolyAccess::call<N>( static_cast<This&&>(_this), static_cast<As&&>(as)...)) { return detail::PolyAccess::call<N>( static_cast<This&&>(_this), static_cast<As&&>(as)...); } template <std::size_t N, class I, class Tail, typename... As> decltype(auto) poly_call(detail::PolyNode<I, Tail>&& _this, As&&... as) { using This = detail::InterfaceOf<I, detail::PolyNode<I, Tail>>; return detail::PolyAccess::call<N>( static_cast<This&&>(_this), static_cast<As&&>(as)...); } template <std::size_t N, class I, class Tail, typename... As> decltype(auto) poly_call(detail::PolyNode<I, Tail>& _this, As&&... as) { using This = detail::InterfaceOf<I, detail::PolyNode<I, Tail>>; return detail::PolyAccess::call<N>( static_cast<This&>(_this), static_cast<As&&>(as)...); } template <std::size_t N, class I, class Tail, typename... As> decltype(auto) poly_call(detail::PolyNode<I, Tail> const& _this, As&&... as) { using This = detail::InterfaceOf<I, detail::PolyNode<I, Tail>>; return detail::PolyAccess::call<N>( static_cast<This const&>(_this), static_cast<As&&>(as)...); } template < std::size_t N, class I, class Poly, typename... As, std::enable_if_t<detail::IsPoly<Poly>::value, int> = 0> auto poly_call(Poly&& _this, As&&... as) -> decltype(poly_call<N, I>( static_cast<Poly&&>(_this).get(), static_cast<As&&>(as)...)) { return poly_call<N, I>( static_cast<Poly&&>(_this).get(), static_cast<As&&>(as)...); } template <std::size_t N, class I, typename... As> [[noreturn]] detail::Bottom poly_call(detail::ArchetypeBase const&, As&&...) { assume_unreachable(); } template <class T, class I> detail::AddCvrefOf<T, I>&& poly_cast(detail::PolyRoot<I>&& that) { return detail::PolyAccess::cast<T>(std::move(that)); } template <class T, class I> detail::AddCvrefOf<T, I>& poly_cast(detail::PolyRoot<I>& that) { return detail::PolyAccess::cast<T>(that); } template <class T, class I> detail::AddCvrefOf<T, I> const& poly_cast(detail::PolyRoot<I> const& that) { return detail::PolyAccess::cast<T>(that); } template <class T, class I> [[noreturn]] detail::AddCvrefOf<T, I>&& poly_cast(detail::ArchetypeRoot<I>&&) { assume_unreachable(); } template <class T, class I> [[noreturn]] detail::AddCvrefOf<T, I>& poly_cast(detail::ArchetypeRoot<I>&) { assume_unreachable(); } template <class T, class I> [[noreturn]] detail::AddCvrefOf<T, I> const& poly_cast( detail::ArchetypeRoot<I> const&) { assume_unreachable(); } template < class T, class Poly, std::enable_if_t<detail::IsPoly<Poly>::value, int> = 0> constexpr auto poly_cast(Poly&& that) -> decltype(poly_cast<T>(std::declval<Poly>().get())) { return poly_cast<T>(static_cast<Poly&&>(that).get()); } template <class I> std::type_info const& poly_type(detail::PolyRoot<I> const& that) noexcept { return detail::PolyAccess::type(that); } [[noreturn]] inline std::type_info const& poly_type( detail::ArchetypeBase const&) noexcept { assume_unreachable(); } template <class Poly, std::enable_if_t<detail::IsPoly<Poly>::value, int> = 0> constexpr auto poly_type(Poly const& that) noexcept -> decltype(poly_type(that.get())) { return poly_type(that.get()); } template <class I> bool poly_empty(detail::PolyRoot<I> const& that) noexcept { return detail::State::eEmpty == detail::PolyAccess::vtable(that)->state_; } template <class I> constexpr bool poly_empty(detail::PolyRoot<I&&> const&) noexcept { return false; } template <class I> constexpr bool poly_empty(detail::PolyRoot<I&> const&) noexcept { return false; } template <class I> constexpr bool poly_empty(Poly<I&&> const&) noexcept { return false; } template <class I> constexpr bool poly_empty(Poly<I&> const&) noexcept { return false; } [[noreturn]] inline bool poly_empty(detail::ArchetypeBase const&) noexcept { assume_unreachable(); } template < class I, std::enable_if_t<Negation<std::is_reference<I>>::value, int> = 0> constexpr Poly<I>&& poly_move(detail::PolyRoot<I>& that) noexcept { return static_cast<Poly<I>&&>(static_cast<Poly<I>&>(that)); } template <class I, std::enable_if_t<Negation<std::is_const<I>>::value, int> = 0> Poly<I&&> poly_move(detail::PolyRoot<I&> const& that) noexcept { return detail::PolyAccess::move(that); } template <class I> Poly<I const&> poly_move(detail::PolyRoot<I const&> const& that) noexcept { return detail::PolyAccess::move(that); } [[noreturn]] inline detail::ArchetypeBase poly_move( detail::ArchetypeBase const&) noexcept { assume_unreachable(); } template <class Poly, std::enable_if_t<detail::IsPoly<Poly>::value, int> = 0> constexpr auto poly_move(Poly& that) noexcept -> decltype(poly_move(that.get())) { return poly_move(that.get()); } namespace detail { template <class I> struct PolyVal : PolyImpl<I> { private: friend PolyAccess; struct NoneSuch {}; using Copyable = std::is_copy_constructible<PolyImpl<I>>; using PolyOrNonesuch = If<Copyable::value, PolyVal, NoneSuch>; using PolyRoot<I>::vptr_; PolyRoot<I>& _polyRoot_() noexcept { return *this; } PolyRoot<I> const& _polyRoot_() const noexcept { return *this; } Data* _data_() noexcept { return PolyAccess::data(*this); } Data const* _data_() const noexcept { return PolyAccess::data(*this); } public: PolyVal() = default; PolyVal(PolyVal&& that) noexcept; PolyVal(PolyOrNonesuch const& that); ~PolyVal(); using PolyImpl<I>::PolyImpl; Poly<I>& operator=(PolyVal that) noexcept; template <class T, std::enable_if_t<ModelsInterface<T, I>::value, int> = 0> PolyVal(T&& t); template <class I2, std::enable_if_t<ValueCompatible<I, I2>::value, int> = 0> PolyVal(Poly<I2> that); template <class T, std::enable_if_t<ModelsInterface<T, I>::value, int> = 0> Poly<I>& operator=(T&& t); template <class I2, std::enable_if_t<ValueCompatible<I, I2>::value, int> = 0> Poly<I>& operator=(Poly<I2> that); void swap(Poly<I>& that) noexcept; }; template <class I> struct PolyRef : private PolyImpl<I> { private: friend PolyAccess; AddCvrefOf<PolyRoot<I>, I>& _polyRoot_() const noexcept; Data* _data_() noexcept { return PolyAccess::data(*this); } Data const* _data_() const noexcept { return PolyAccess::data(*this); } static constexpr RefType refType() noexcept; protected: template <class That, class I2> PolyRef(That&& that, Type<I2>); public: PolyRef(PolyRef const& that) noexcept; Poly<I>& operator=(PolyRef const& that) noexcept; template <class T, std::enable_if_t<ModelsInterface<T, I>::value, int> = 0> PolyRef(T&& t) noexcept; template < class I2, std::enable_if_t<ReferenceCompatible<I, I2, I2&&>::value, int> = 0> PolyRef(Poly<I2>&& that) noexcept( std::is_reference<I2>::value); template < class I2, std::enable_if_t<ReferenceCompatible<I, I2, I2&>::value, int> = 0> PolyRef(Poly<I2>& that) noexcept(std::is_reference<I2>::value) : PolyRef{that, Type<I2>{}} {} template < class I2, std::enable_if_t<ReferenceCompatible<I, I2, I2 const&>::value, int> = 0> PolyRef(Poly<I2> const& that) noexcept( std::is_reference<I2>::value) : PolyRef{that, Type<I2>{}} {} template <class T, std::enable_if_t<ModelsInterface<T, I>::value, int> = 0> Poly<I>& operator=(T&& t) noexcept; template < class I2, std::enable_if_t<ReferenceCompatible<I, I2, I2&&>::value, int> = 0> Poly<I>& operator=(Poly<I2>&& that) noexcept(std::is_reference<I2>::value); template < class I2, std::enable_if_t<ReferenceCompatible<I, I2, I2&>::value, int> = 0> Poly<I>& operator=(Poly<I2>& that) noexcept(std::is_reference<I2>::value); template < class I2, std::enable_if_t<ReferenceCompatible<I, I2, I2 const&>::value, int> = 0> Poly<I>& operator=(Poly<I2> const& that) noexcept( std::is_reference<I2>::value); void swap(Poly<I>& that) noexcept; AddCvrefOf<PolyImpl<I>, I>& get() const noexcept; AddCvrefOf<PolyImpl<I>, I>& operator*() const noexcept { return get(); } auto operator-> () const noexcept { return &get(); } }; template <class I> using PolyValOrRef = If<std::is_reference<I>::value, PolyRef<I>, PolyVal<I>>; } template <class I> struct Poly final : detail::PolyValOrRef<I> { friend detail::PolyAccess; Poly() = default; using detail::PolyValOrRef<I>::PolyValOrRef; using detail::PolyValOrRef<I>::operator=; }; template <class I> void swap(Poly<I>& left, Poly<I>& right) noexcept { left.swap(right); } template <class Sig> inline constexpr detail::Sig<Sig> const sig = {}; } namespace folly { namespace detail { template <class I> inline PolyVal<I>::PolyVal(PolyVal&& that) noexcept { that.vptr_->ops_(Op::eMove, &that, static_cast<Data*>(this)); vptr_ = std::exchange(that.vptr_, vtable<I>()); } template <class I> inline PolyVal<I>::PolyVal(PolyOrNonesuch const& that) { that.vptr_->ops_( Op::eCopy, const_cast<Data*>(that._data_()), PolyAccess::data(*this)); vptr_ = that.vptr_; } template <class I> inline PolyVal<I>::~PolyVal() { vptr_->ops_(Op::eNuke, this, nullptr); } template <class I> inline Poly<I>& PolyVal<I>::operator=(PolyVal that) noexcept { vptr_->ops_(Op::eNuke, _data_(), nullptr); that.vptr_->ops_(Op::eMove, that._data_(), _data_()); vptr_ = std::exchange(that.vptr_, vtable<I>()); return static_cast<Poly<I>&>(*this); } template <class I> template <class T, std::enable_if_t<ModelsInterface<T, I>::value, int>> inline PolyVal<I>::PolyVal(T&& t) { using U = std::decay_t<T>; static_assert( std::is_copy_constructible<U>::value || !Copyable::value, "This Poly<> requires copyability, and the source object is not " "copyable"); assert(typeid(t) == typeid(std::decay_t<T>) || !"Dynamic and static exception types don't match. Object would " "be sliced when storing in Poly."); if (inSitu<U>()) { auto const buff = static_cast<void*>(&_data_()->buff_); ::new (buff) U(static_cast<T&&>(t)); } else { _data_()->pobj_ = new U(static_cast<T&&>(t)); } vptr_ = vtableFor<I, U>(); } template <class I> template <class I2, std::enable_if_t<ValueCompatible<I, I2>::value, int>> inline PolyVal<I>::PolyVal(Poly<I2> that) { static_assert( !Copyable::value || std::is_copy_constructible<Poly<I2>>::value, "This Poly<> requires copyability, and the source object is not " "copyable"); auto* that_vptr = PolyAccess::vtable(that); if (that_vptr->state_ != State::eEmpty) { that_vptr->ops_(Op::eMove, PolyAccess::data(that), _data_()); vptr_ = &select<I>(*std::exchange(that_vptr, vtable<std::decay_t<I2>>())); } } template <class I> template <class T, std::enable_if_t<ModelsInterface<T, I>::value, int>> inline Poly<I>& PolyVal<I>::operator=(T&& t) { *this = PolyVal(static_cast<T&&>(t)); return static_cast<Poly<I>&>(*this); } template <class I> template <class I2, std::enable_if_t<ValueCompatible<I, I2>::value, int>> inline Poly<I>& PolyVal<I>::operator=(Poly<I2> that) { *this = PolyVal(std::move(that)); return static_cast<Poly<I>&>(*this); } template <class I> inline void PolyVal<I>::swap(Poly<I>& that) noexcept { switch (vptr_->state_) { case State::eEmpty: *this = std::move(that); break; case State::eOnHeap: if (State::eOnHeap == that.vptr_->state_) { std::swap(_data_()->pobj_, that._data_()->pobj_); std::swap(vptr_, that.vptr_); return; } [[fallthrough]]; case State::eInSitu: std::swap( *this, static_cast<PolyVal<I>&>(that)); } } template <class I> inline AddCvrefOf<PolyRoot<I>, I>& PolyRef<I>::_polyRoot_() const noexcept { return const_cast<AddCvrefOf<PolyRoot<I>, I>&>( static_cast<PolyRoot<I> const&>(*this)); } template <class I> constexpr RefType PolyRef<I>::refType() noexcept { using J = std::remove_reference_t<I>; return std::is_rvalue_reference<I>::value ? RefType::eRvalue : std::is_const<J>::value ? RefType::eConstLvalue : RefType::eLvalue; } template <class I> template <class That, class I2> inline PolyRef<I>::PolyRef(That&& that, Type<I2>) { auto* that_vptr = PolyAccess::vtable(PolyAccess::root(that)); detail::State const that_state = that_vptr->state_; if (that_state == State::eEmpty) { throw BadPolyAccess(); } auto* that_data = PolyAccess::data(PolyAccess::root(that)); _data_()->pobj_ = that_state == State::eInSitu ? const_cast<void*>(static_cast<void const*>(&that_data->buff_)) : that_data->pobj_; this->vptr_ = &select<std::decay_t<I>>( *static_cast<VTable<std::decay_t<I2>> const*>(that_vptr->ops_( Op::eRefr, nullptr, reinterpret_cast<void*>(refType())))); } template <class I> inline PolyRef<I>::PolyRef(PolyRef const& that) noexcept { _data_()->pobj_ = that._data_()->pobj_; this->vptr_ = that.vptr_; } template <class I> inline Poly<I>& PolyRef<I>::operator=(PolyRef const& that) noexcept { _data_()->pobj_ = that._data_()->pobj_; this->vptr_ = that.vptr_; return static_cast<Poly<I>&>(*this); } template <class I> template <class T, std::enable_if_t<ModelsInterface<T, I>::value, int>> inline PolyRef<I>::PolyRef(T&& t) noexcept { _data_()->pobj_ = const_cast<void*>(static_cast<void const*>(std::addressof(t))); this->vptr_ = vtableFor<std::decay_t<I>, AddCvrefOf<std::decay_t<T>, I>>(); } template <class I> template < class I2, std::enable_if_t<ReferenceCompatible<I, I2, I2&&>::value, int>> inline PolyRef<I>::PolyRef(Poly<I2>&& that) noexcept( std::is_reference<I2>::value) : PolyRef{that, Type<I2>{}} { static_assert( Disjunction<std::is_reference<I2>, std::is_rvalue_reference<I>>::value, "Attempting to construct a Poly that is a reference to a temporary. " "This is probably a mistake."); } template <class I> template <class T, std::enable_if_t<ModelsInterface<T, I>::value, int>> inline Poly<I>& PolyRef<I>::operator=(T&& t) noexcept { *this = PolyRef(static_cast<T&&>(t)); return static_cast<Poly<I>&>(*this); } template <class I> template < class I2, std::enable_if_t<ReferenceCompatible<I, I2, I2&&>::value, int>> inline Poly<I>& PolyRef<I>::operator=(Poly<I2>&& that) noexcept( std::is_reference<I2>::value) { *this = PolyRef(std::move(that)); return static_cast<Poly<I>&>(*this); } template <class I> template < class I2, std::enable_if_t<ReferenceCompatible<I, I2, I2&>::value, int>> inline Poly<I>& PolyRef<I>::operator=(Poly<I2>& that) noexcept( std::is_reference<I2>::value) { *this = PolyRef(that); return static_cast<Poly<I>&>(*this); } template <class I> template < class I2, std::enable_if_t<ReferenceCompatible<I, I2, I2 const&>::value, int>> inline Poly<I>& PolyRef<I>::operator=(Poly<I2> const& that) noexcept( std::is_reference<I2>::value) { *this = PolyRef(that); return static_cast<Poly<I>&>(*this); } template <class I> inline void PolyRef<I>::swap(Poly<I>& that) noexcept { std::swap(_data_()->pobj_, that._data_()->pobj_); std::swap(this->vptr_, that.vptr_); } template <class I> inline AddCvrefOf<PolyImpl<I>, I>& PolyRef<I>::get() const noexcept { return const_cast<AddCvrefOf<PolyImpl<I>, I>&>( static_cast<PolyImpl<I> const&>(*this)); } } } // The example begins here #if USE_FAKE_STREAMS #define ostream OSTREAM namespace std { struct ostream; template<typename T> ostream &operator<<(ostream &, const T &); ostream *coutP; ostream &cout = *coutP; } #else #include <iostream> #endif struct IDrawable { // Define the interface of something that can be drawn: template <class Base> struct Interface : Base { void draw(std::ostream& out) const { folly::poly_call<0>(*this, out);} }; // Define how concrete types can fulfill that interface (in C++17): template <class T> using Members = folly::PolyMembers<&T::draw>; }; // Define an object that can hold anything that can be drawn: using drawable = folly::Poly<IDrawable>; struct Square { void draw(std::ostream& out) const { out << "Square\n"; } }; struct Circle { void draw(std::ostream& out) const { out << "Circle\n"; } }; void f(drawable const& d) { d.draw(std::cout); } int main() { f(Square{}); // prints Square f(Circle{}); // prints Circle }
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