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
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.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
// apply_multichannel Template Function Implementation in C++ // Developed by Jimmy Hu #include <algorithm> #include <cassert> #include <chrono> #include <cmath> #include <complex> #include <concepts> #include <execution> #include <filesystem> #include <fstream> #include <functional> #include <future> #include <iostream> #include <iterator> #include <numeric> #include <ranges> #include <random> #include <string> #include <type_traits> #include <variant> #include <vector> #include <utility> namespace TinyDIP { struct RGB { std::uint8_t channels[3]; inline RGB operator+(const RGB& input) const { return RGB{ static_cast<std::uint8_t>(input.channels[0] + channels[0]), static_cast<std::uint8_t>(input.channels[1] + channels[1]), static_cast<std::uint8_t>(input.channels[2] + channels[2]) }; } inline RGB operator-(const RGB& input) const { return RGB{ static_cast<std::uint8_t>(channels[0] - input.channels[0]), static_cast<std::uint8_t>(channels[1] - input.channels[1]), static_cast<std::uint8_t>(channels[2] - input.channels[2]) }; } friend std::ostream& operator<<(std::ostream& out, const RGB& _myStruct) { out << '{' << +_myStruct.channels[0] << ", " << +_myStruct.channels[1] << ", " << +_myStruct.channels[2] << '}'; return out; } }; struct RGB_DOUBLE { double channels[3]; inline RGB_DOUBLE operator+(const RGB_DOUBLE& input) const { return RGB_DOUBLE{ input.channels[0] + channels[0], input.channels[1] + channels[1], input.channels[2] + channels[2] }; } inline RGB_DOUBLE operator-(const RGB_DOUBLE& input) const { return RGB_DOUBLE{ channels[0] - input.channels[0], channels[1] - input.channels[1], channels[2] - input.channels[2] }; } friend std::ostream& operator<<(std::ostream& out, const RGB_DOUBLE& _myStruct) { out << '{' << +_myStruct.channels[0] << ", " << +_myStruct.channels[1] << ", " << +_myStruct.channels[2] << '}'; return out; } }; using GrayScale = std::uint8_t; struct HSV { double channels[3]; // Range: 0 <= H < 360, 0 <= S <= 1, 0 <= V <= 255 inline HSV operator+(const HSV& input) const { return HSV{ input.channels[0] + channels[0], input.channels[1] + channels[1], input.channels[2] + channels[2] }; } inline HSV operator-(const HSV& input) const { return HSV{ channels[0] - input.channels[0], channels[1] - input.channels[1], channels[2] - input.channels[2] }; } friend std::ostream& operator<<(std::ostream& out, const HSV& _myStruct) { out << '{' << +_myStruct.channels[0] << ", " << +_myStruct.channels[1] << ", " << +_myStruct.channels[2] << '}'; return out; } }; // MultiChannel struct implementation template<class ElementT, std::size_t channel_count = 3> struct MultiChannel { std::array<ElementT, channel_count> channels; inline MultiChannel operator+(const MultiChannel& input) const { std::array<ElementT, channel_count> channels_output; for(std::size_t i = 0; i < channels.size(); ++i) { channels_output[i] = channels[i] + input.channels[i]; } return MultiChannel{channels_output}; } inline MultiChannel operator-(const MultiChannel& input) const { std::array<ElementT, channel_count> channels_output; for(std::size_t i = 0; i < channels.size(); ++i) { channels_output[i] = channels[i] - input.channels[i]; } return MultiChannel{channels_output}; } friend std::ostream& operator<<(std::ostream& out, const MultiChannel& _myStruct) { out << '{'; for(std::size_t i = 0; i < channel_count; ++i) { out << +_myStruct.channels[i] << ", "; } out << '}'; return out; } }; struct BMPIMAGE { std::filesystem::path FILENAME; unsigned int XSIZE; unsigned int YSIZE; std::uint8_t FILLINGBYTE; std::uint8_t* IMAGE_DATA; }; // Reference: https://stackoverflow.com/a/48458312/6667035 template <typename> struct is_tuple : std::false_type {}; template <typename ...T> struct is_tuple<std::tuple<T...>> : std::true_type {}; // is_MultiChannel struct implementation template <typename> struct is_MultiChannel : std::false_type {}; template <std::size_t N, typename T> struct is_MultiChannel<MultiChannel<T, N>> : std::true_type {}; template <typename, typename> struct check_tuple_element_type {}; template <typename TargetType, typename ...ElementT> struct check_tuple_element_type<TargetType, std::tuple<ElementT...>> : std::bool_constant<(std::is_same_v<ElementT, TargetType> || ...)> { }; template<typename T> concept image_element_standard_floating_point_type = std::same_as<double, T> or std::same_as<float, T> or std::same_as<long double, T> ; // Reference: https://stackoverflow.com/a/64287611/6667035 template <typename T> struct is_complex : std::false_type {}; template <typename T> struct is_complex<std::complex<T>> : std::true_type {}; // Reference: https://stackoverflow.com/a/58067611/6667035 template <typename T> concept arithmetic = std::is_arithmetic_v<T> or is_complex<T>::value; // recursive_print template function implementation template<typename T> constexpr void recursive_print(const T& input, const std::size_t level = 0) { std::cout << std::string(level, ' ') << input << '\n'; } template<std::ranges::input_range Range> constexpr void recursive_print(const Range& input, const std::size_t level = 0) { std::cout << std::string(level, ' ') << "Level " << level << ":" << std::endl; std::ranges::for_each(input, [level](auto&& element) { recursive_print(element, level + 1); }); } template <typename ElementT> class Image { public: Image() = default; template<std::same_as<std::size_t>... Sizes> Image(Sizes... sizes): size{sizes...}, image_data((1 * ... * sizes)) {} template<std::same_as<int>... Sizes> Image(Sizes... sizes) { size.reserve(sizeof...(sizes)); (size.emplace_back(sizes), ...); image_data.resize( std::reduce( std::ranges::cbegin(size), std::ranges::cend(size), std::size_t{1}, std::multiplies<>() ) ); } Image(const std::vector<std::size_t>& sizes) { if (sizes.empty()) { throw std::runtime_error("Image size vector is empty!"); } size = std::move(sizes); image_data.resize( std::reduce( std::ranges::cbegin(sizes), std::ranges::cend(sizes), std::size_t{1}, std::multiplies<>() )); } template<std::ranges::input_range Range, std::same_as<std::size_t>... Sizes> Image(const Range& input, Sizes... sizes): size{sizes...}, image_data(begin(input), end(input)) { if (image_data.size() != (1 * ... * sizes)) { throw std::runtime_error("Image data input and the given size are mismatched!"); } } template<std::same_as<std::size_t>... Sizes> Image(std::vector<ElementT>&& input, Sizes... sizes): size{sizes...}, image_data(begin(input), end(input)) { if (input.empty()) { throw std::runtime_error("Input vector is empty!"); } if (image_data.size() != (1 * ... * sizes)) { throw std::runtime_error("Image data input and the given size are mismatched!"); } } Image(const std::vector<ElementT>& input, const std::vector<std::size_t>& sizes) { if (input.empty()) { throw std::runtime_error("Input vector is empty!"); } size = std::move(sizes); image_data = std::move(input); auto count = std::reduce(std::ranges::cbegin(sizes), std::ranges::cend(sizes), 1, std::multiplies()); if (image_data.size() != count) { throw std::runtime_error("Image data input and the given size are mismatched!"); } } Image(const std::vector<ElementT>& input, std::size_t newWidth, std::size_t newHeight) { if (input.empty()) { throw std::runtime_error("Input vector is empty!"); } size.reserve(2); size.emplace_back(newWidth); size.emplace_back(newHeight); if (input.size() != newWidth * newHeight) { throw std::runtime_error("Image data input and the given size are mismatched!"); } image_data = std::move(input); // Reference: https://stackoverflow.com/a/51706522/6667035 } Image(const std::vector<std::vector<ElementT>>& input) { if (input.empty()) { throw std::runtime_error("Input vector is empty!"); } size.reserve(2); size.emplace_back(input[0].size()); size.emplace_back(input.size()); for (auto& rows : input) { image_data.insert(image_data.end(), std::ranges::begin(rows), std::ranges::end(rows)); // flatten } return; } // at template function implementation template<typename... Args> constexpr ElementT& at(const Args... indexInput) { return const_cast<ElementT&>(static_cast<const Image &>(*this).at(indexInput...)); } // at template function implementation // Reference: https://codereview.stackexchange.com/a/288736/231235 template<typename... Args> constexpr ElementT const& at(const Args... indexInput) const { checkBoundary(indexInput...); constexpr std::size_t n = sizeof...(Args); if(n != size.size()) { throw std::runtime_error("Dimensionality mismatched!"); } std::size_t i = 0; std::size_t stride = 1; std::size_t position = 0; auto update_position = [&](auto index) { position += index * stride; stride *= size[i++]; }; (update_position(indexInput), ...); return image_data[position]; } // at_without_boundary_check template function implementation template<typename... Args> constexpr ElementT& at_without_boundary_check(const Args... indexInput) { return const_cast<ElementT&>(static_cast<const Image &>(*this).at_without_boundary_check(indexInput...)); } template<typename... Args> constexpr ElementT const& at_without_boundary_check(const Args... indexInput) const { std::size_t i = 0; std::size_t stride = 1; std::size_t position = 0; auto update_position = [&](auto index) { position += index * stride; stride *= size[i++]; }; (update_position(indexInput), ...); return image_data[position]; } // get function implementation constexpr ElementT get(std::size_t index) const noexcept { return image_data[index]; } // set function implementation constexpr ElementT& set(const std::size_t index) noexcept { return image_data[index]; } // set template function implementation template<class TupleT> requires(is_tuple<TupleT>::value and check_tuple_element_type<std::size_t, TupleT>::value) constexpr bool set(const TupleT location, const ElementT draw_value) { if (checkBoundaryTuple(location)) { image_data[tuple_location_to_index(location)] = draw_value; return true; } return false; } // cast template function implementation template<typename TargetT> constexpr Image<TargetT> cast() { std::vector<TargetT> output_data; output_data.resize(image_data.size()); std::transform( std::ranges::cbegin(image_data), std::ranges::cend(image_data), std::ranges::begin(output_data), [](auto& input){ return static_cast<TargetT>(input); } ); Image<TargetT> output(output_data, size); return output; } constexpr std::size_t count() const noexcept { return std::reduce(std::ranges::cbegin(size), std::ranges::cend(size), 1, std::multiplies()); } constexpr std::size_t getDimensionality() const noexcept { return size.size(); } constexpr std::size_t getWidth() const noexcept { return size[0]; } constexpr std::size_t getHeight() const noexcept { return size[1]; } // getSize function implementation constexpr auto getSize() const noexcept { return size; } // getSize function implementation constexpr auto getSize(std::size_t index) const noexcept { return size[index]; } // getStride function implementation constexpr std::size_t getStride(std::size_t index) const noexcept { if(index == 0) { return std::size_t{1}; } std::size_t output = std::size_t{1}; for(std::size_t i = 0; i < index; ++i) { output *= size[i]; } return output; } std::vector<ElementT> const& getImageData() const noexcept { return image_data; } // expose the internal data // print function implementation void print(std::string separator = "\t", std::ostream& os = std::cout) const { if constexpr (is_MultiChannel<ElementT>::value) { if (size.size() == 1) { for (std::size_t x = 0; x < size[0]; ++x) { os << at(x) << separator; } os << "\n"; } else if (size.size() == 2) { for (std::size_t y = 0; y < size[1]; ++y) { for (std::size_t x = 0; x < size[0]; ++x) { os << at(x, y) << separator; } os << "\n"; } os << "\n"; } else if (size.size() == 3) { for (std::size_t z = 0; z < size[2]; ++z) { for (std::size_t y = 0; y < size[1]; ++y) { for (std::size_t x = 0; x < size[0]; ++x) { os << at(x, y, z) << separator; } os << "\n"; } os << "\n"; } os << "\n"; } else if (size.size() == 4) { for (std::size_t a = 0; a < size[3]; ++a) { os << "group = " << a << "\n"; for (std::size_t z = 0; z < size[2]; ++z) { for (std::size_t y = 0; y < size[1]; ++y) { for (std::size_t x = 0; x < size[0]; ++x) { os << at(x, y, z, a) << separator; } os << "\n"; } os << "\n"; } os << "\n"; } os << "\n"; } } else { if (size.size() == 1) { for (std::size_t x = 0; x < size[0]; ++x) { // Ref: https://isocpp.org/wiki/faq/input-output#print-char-or-ptr-as-number os << +at(x) << separator; } os << "\n"; } else if (size.size() == 2) { for (std::size_t y = 0; y < size[1]; ++y) { for (std::size_t x = 0; x < size[0]; ++x) { // Ref: https://isocpp.org/wiki/faq/input-output#print-char-or-ptr-as-number os << +at(x, y) << separator; } os << "\n"; } os << "\n"; } else if (size.size() == 3) { for (std::size_t z = 0; z < size[2]; ++z) { for (std::size_t y = 0; y < size[1]; ++y) { for (std::size_t x = 0; x < size[0]; ++x) { // Ref: https://isocpp.org/wiki/faq/input-output#print-char-or-ptr-as-number os << +at(x, y, z) << separator; } os << "\n"; } os << "\n"; } os << "\n"; } else if (size.size() == 4) { for (std::size_t a = 0; a < size[3]; ++a) { os << "group = " << a << "\n"; for (std::size_t z = 0; z < size[2]; ++z) { for (std::size_t y = 0; y < size[1]; ++y) { for (std::size_t x = 0; x < size[0]; ++x) { // Ref: https://isocpp.org/wiki/faq/input-output#print-char-or-ptr-as-number os << +at(x, y, z, a) << separator; } os << "\n"; } os << "\n"; } os << "\n"; } os << "\n"; } } } // Enable this function if ElementT = RGB or RGB_DOUBLE or HSV void print(std::string separator = "\t", std::ostream& os = std::cout) const requires(std::same_as<ElementT, RGB> or std::same_as<ElementT, RGB_DOUBLE> or std::same_as<ElementT, HSV> or is_MultiChannel<ElementT>::value) { if (size.size() == 1) { for (std::size_t x = 0; x < size[0]; ++x) { os << "( "; for (std::size_t channel_index = 0; channel_index < 3; ++channel_index) { // Ref: https://isocpp.org/wiki/faq/input-output#print-char-or-ptr-as-number os << +at(x).channels[channel_index] << separator; } os << ")" << separator; } os << "\n"; } else if (size.size() == 2) { for (std::size_t y = 0; y < size[1]; ++y) { for (std::size_t x = 0; x < size[0]; ++x) { os << "( "; for (std::size_t channel_index = 0; channel_index < 3; ++channel_index) { // Ref: https://isocpp.org/wiki/faq/input-output#print-char-or-ptr-as-number os << +at(x, y).channels[channel_index] << separator; } os << ")" << separator; } os << "\n"; } os << "\n"; } return; } Image<ElementT>& setAllValue(const ElementT input) { std::fill(std::ranges::begin(image_data), std::ranges::end(image_data), input); return *this; } friend std::ostream& operator<<(std::ostream& os, const Image<ElementT>& rhs) { const std::string separator = "\t"; rhs.print(separator, os); return os; } Image<ElementT>& operator+=(const Image<ElementT>& rhs) { check_size_same(rhs, *this); std::transform(std::ranges::cbegin(image_data), std::ranges::cend(image_data), std::ranges::cbegin(rhs.image_data), std::ranges::begin(image_data), std::plus<>{}); return *this; } Image<ElementT>& operator-=(const Image<ElementT>& rhs) { check_size_same(rhs, *this); std::transform(std::ranges::cbegin(image_data), std::ranges::cend(image_data), std::ranges::cbegin(rhs.image_data), std::ranges::begin(image_data), std::minus<>{}); return *this; } Image<ElementT>& operator*=(const Image<ElementT>& rhs) { check_size_same(rhs, *this); std::transform(std::ranges::cbegin(image_data), std::ranges::cend(image_data), std::ranges::cbegin(rhs.image_data), std::ranges::begin(image_data), std::multiplies<>{}); return *this; } Image<ElementT>& operator/=(const Image<ElementT>& rhs) { check_size_same(rhs, *this); std::transform(std::ranges::cbegin(image_data), std::ranges::cend(image_data), std::ranges::cbegin(rhs.image_data), std::ranges::begin(image_data), std::divides<>{}); return *this; } friend bool operator==(Image<ElementT> const&, Image<ElementT> const&) = default; friend bool operator!=(Image<ElementT> const&, Image<ElementT> const&) = default; friend Image<ElementT> operator+(Image<ElementT> input1, const Image<ElementT>& input2) { return input1 += input2; } friend Image<ElementT> operator-(Image<ElementT> input1, const Image<ElementT>& input2) { return input1 -= input2; } friend Image<ElementT> operator*(Image<ElementT> input1, ElementT input2) { return multiplies(input1, input2); } friend Image<ElementT> operator*(ElementT input1, Image<ElementT> input2) { return multiplies(input2, input1); } #ifdef USE_BOOST_SERIALIZATION void Save(std::string filename) { const std::string filename_with_extension = filename + ".dat"; // Reference: https://stackoverflow.com/questions/523872/how-do-you-serialize-an-object-in-c std::ofstream ofs(filename_with_extension, std::ios::binary); boost::archive::binary_oarchive ArchiveOut(ofs); // write class instance to archive ArchiveOut << *this; // archive and stream closed when destructors are called ofs.close(); } #endif private: std::vector<std::size_t> size; std::vector<ElementT> image_data; template<typename... Args> void checkBoundary(const Args... indexInput) const { constexpr std::size_t n = sizeof...(Args); if(n != size.size()) { throw std::runtime_error("Dimensionality mismatched!"); } std::size_t parameter_pack_index = 0; auto function = [&](auto index) { if (index >= size[parameter_pack_index]) throw std::out_of_range("Given index out of range!"); parameter_pack_index = parameter_pack_index + 1; }; (function(indexInput), ...); } // checkBoundaryTuple template function implementation template<class TupleT> requires(TinyDIP::is_tuple<TupleT>::value) constexpr bool checkBoundaryTuple(const TupleT location) { constexpr std::size_t n = std::tuple_size<TupleT>{}; if(n != size.size()) { throw std::runtime_error("Dimensionality mismatched!"); } std::size_t parameter_pack_index = 0; auto function = [&](auto index) { if (std::cmp_greater_equal(index, size[parameter_pack_index])) return false; parameter_pack_index = parameter_pack_index + 1; return true; }; return std::apply([&](auto&&... args) { return ((function(args))&& ...);}, location); } // tuple_location_to_index template function implementation template<class TupleT> requires(TinyDIP::is_tuple<TupleT>::value) constexpr std::size_t tuple_location_to_index(TupleT location) { std::size_t i = 0; std::size_t stride = 1; std::size_t position = 0; auto update_position = [&](auto index) { position += index * stride; stride *= size[i++]; }; std::apply([&](auto&&... args) {((update_position(args)), ...);}, location); return position; } #ifdef USE_BOOST_SERIALIZATION friend class boost::serialization::access; template<class Archive> void serialize(Archive& ar, const unsigned int version) { ar& size; ar& image_data; } #endif }; template<typename T, typename ElementT> concept is_Image = std::is_same_v<T, Image<ElementT>>; // zeros template function implementation template<typename ElementT, std::same_as<std::size_t>... Sizes> constexpr static auto zeros(Sizes... sizes) { auto output = Image<ElementT>(sizes...); return output; } // ones template function implementation template<typename ElementT, std::same_as<std::size_t>... Sizes> constexpr static auto ones(Sizes... sizes) { auto output = zeros<ElementT>(sizes...); output.setAllValue(1); return output; } // rand template function implementation template<image_element_standard_floating_point_type ElementT = double, typename Urbg, std::same_as<std::size_t>... Sizes> requires std::uniform_random_bit_generator<std::remove_reference_t<Urbg>> constexpr static auto rand(Urbg&& urbg, Sizes... sizes) { if constexpr (sizeof...(Sizes) == 1) { return rand(std::forward<Urbg>(urbg), sizes..., sizes...); } else { std::vector<ElementT> image_data((... * sizes)); // Reference: https://stackoverflow.com/a/23143753/6667035 // Reference: https://codereview.stackexchange.com/a/294739/231235 auto dist = std::uniform_real_distribution<ElementT>{}; std::ranges::generate(image_data, [&dist, &urbg]() { return dist(urbg); }); return Image<ElementT>{std::move(image_data), sizes...}; } } // rand template function implementation template<image_element_standard_floating_point_type ElementT = double, std::same_as<std::size_t>... Size> inline auto rand(Size... size) { return rand<ElementT>(std::mt19937{std::random_device{}()}, size...); } // rand template function implementation template<image_element_standard_floating_point_type ElementT = double, typename Urbg> requires std::uniform_random_bit_generator<std::remove_reference_t<Urbg>> constexpr auto rand(Urbg&& urbg) -> ElementT { auto dist = std::uniform_real_distribution<ElementT>{}; return dist(urbg); } // rand template function implementation template<image_element_standard_floating_point_type ElementT = double> inline auto rand() { return rand<ElementT>(std::mt19937{std::random_device{}()}); } template<typename ElementT> constexpr void check_width_same(const Image<ElementT>& x, const Image<ElementT>& y) { if (!is_width_same(x, y)) throw std::runtime_error("Width mismatched!"); } template<typename ElementT> constexpr void check_height_same(const Image<ElementT>& x, const Image<ElementT>& y) { if (!is_height_same(x, y)) throw std::runtime_error("Height mismatched!"); } // check_size_same template function implementation template<typename ElementT> constexpr void check_size_same(const Image<ElementT>& x, const Image<ElementT>& y) { if(x.getSize() != y.getSize()) throw std::runtime_error("Size mismatched!"); } // Multichannel Concept Implementation template<typename T> concept Multichannel = requires(T a) { { a.channels }; // or whatever is best to check for multiple channels }; // apply_multichannel Template Function Implementation template<std::size_t channel_count = 3, class ElementT, class Lambda, typename... Args> [[nodiscard]] constexpr static auto apply_multichannel(const MultiChannel<ElementT, channel_count>& input, Lambda f, Args... args) { MultiChannel<decltype(std::invoke(f, input.channels[0], args...)), channel_count> output; std::transform(std::ranges::cbegin(input.channels), std::ranges::cend(input.channels), std::ranges::begin(output.channels), [&](auto&& input) { return std::invoke(f, input, args...); }); return output; } // apply_multichannel Template Function Implementation (the version with execution policy) template<std::size_t channel_count = 3, class ExecutionPolicy, class ElementT, class Lambda, typename... Args> requires (std::is_execution_policy_v<std::remove_cvref_t<ExecutionPolicy>>) [[nodiscard]] constexpr static auto apply_multichannel(ExecutionPolicy&& execution_policy, const MultiChannel<ElementT, channel_count>& input, Lambda f, Args... args) { MultiChannel<decltype(std::invoke(f, input.channels[0], args...)), channel_count> output; std::transform(execution_policy, std::ranges::cbegin(input.channels), std::ranges::cend(input.channels), std::ranges::begin(output.channels), [&](auto&& input) { return std::invoke(f, input, args...); }); return output; } // apply_multichannel Template Function Implementation template<std::size_t channel_count = 3, class T, class Lambda, typename... Args> requires((std::same_as<T, RGB>) || (std::same_as<T, RGB_DOUBLE>) || (std::same_as<T, HSV>)) [[nodiscard]] constexpr static auto apply_multichannel(const T& input, Lambda f, Args... args) { MultiChannel<decltype(std::invoke(f, input.channels[0], args...)), channel_count> output; std::transform(std::ranges::cbegin(input.channels), std::ranges::cend(input.channels), std::ranges::begin(output.channels), [&](auto&& input) { return std::invoke(f, input, args...); }); return output; } // apply_multichannel Template Function Implementation (the version with execution policy) template<std::size_t channel_count = 3, class ExecutionPolicy, class T, class Lambda, typename... Args> requires (std::is_execution_policy_v<std::remove_cvref_t<ExecutionPolicy>>)&& ((std::same_as<T, RGB>) || (std::same_as<T, RGB_DOUBLE>) || (std::same_as<T, HSV>)) [[nodiscard]] constexpr static auto apply_multichannel(ExecutionPolicy&& execution_policy, const T& input, Lambda f, Args... args) { MultiChannel<decltype(std::invoke(f, input.channels[0], args...)), channel_count> output; std::transform(execution_policy, std::ranges::cbegin(input.channels), std::ranges::cend(input.channels), std::ranges::begin(output.channels), [&](auto&& input) { return std::invoke(f, input, args...); }); return output; } // abs Template Function Implementation template<typename T> [[nodiscard]] constexpr static auto abs(const T& input) { if constexpr (Multichannel<T>) { return apply_multichannel(input, [&](auto&& _input) {return std::abs(_input); }); } else { return std::abs(input); } } // abs Template Function Implementation (the version with execution policy) template<class ExecutionPolicy, typename T> requires (std::is_execution_policy_v<std::remove_cvref_t<ExecutionPolicy>>) [[nodiscard]] constexpr static auto abs(ExecutionPolicy&& execution_policy, const T& input) { if constexpr (Multichannel<T>) { return apply_multichannel(execution_policy, input, [&](auto&& _input) {return std::abs(_input); }); } else { return std::abs(input); } } // pow Template Function Implementation template<typename T, typename ExpT = double> [[nodiscard]] constexpr static auto pow(const T& input, const ExpT exp) { if constexpr (Multichannel<T>) { return apply_multichannel(input, [&](auto&& _input, auto&& input_exp) {return std::pow(_input, input_exp); }, exp); } else { return std::pow(input); } } // pow Template Function Implementation (the version with execution policy) template<class ExecutionPolicy, typename T, typename ExpT = double> requires (std::is_execution_policy_v<std::remove_cvref_t<ExecutionPolicy>>) [[nodiscard]] constexpr static auto pow(ExecutionPolicy&& execution_policy, const T& input, const ExpT exp) { if constexpr (Multichannel<T>) { return apply_multichannel(execution_policy, input, [&](auto&& _input, auto&& input_exp) {return std::pow(_input, input_exp); }, exp); } else { return std::pow(input); } } // sqrt Template Function Implementation template<typename T> [[nodiscard]] constexpr static auto sqrt(const T& input) { if constexpr (Multichannel<T>) { return apply_multichannel(input, [&](auto&& _input) {return std::sqrt(_input); }); } else { return std::sqrt(input); } } // sqrt Template Function Implementation (the version with execution policy) template<class ExecutionPolicy, typename T> requires (std::is_execution_policy_v<std::remove_cvref_t<ExecutionPolicy>>) [[nodiscard]] constexpr static auto sqrt(ExecutionPolicy&& execution_policy, const T& input) { if constexpr (Multichannel<T>) { return apply_multichannel(execution_policy, input, [&](auto&& _input) {return std::sqrt(_input); }); } else { return std::sqrt(input); } } // cbrt Template Function Implementation template<typename T> [[nodiscard]] constexpr static auto cbrt(const T& input) { if constexpr (Multichannel<T>) { return apply_multichannel(input, [&](auto&& _input) {return std::cbrt(_input); }); } else { return std::cbrt(input); } } // cbrt Template Function Implementation (the version with execution policy) template<class ExecutionPolicy, typename T> requires (std::is_execution_policy_v<std::remove_cvref_t<ExecutionPolicy>>) [[nodiscard]] constexpr static auto cbrt(ExecutionPolicy&& execution_policy, const T& input) { if constexpr (Multichannel<T>) { return apply_multichannel(execution_policy, input, [&](auto&& _input) {return std::cbrt(_input); }); } else { return std::cbrt(input); } } // sin Template Function Implementation template<typename T> [[nodiscard]] constexpr static auto sin(const T& input) { if constexpr (Multichannel<T>) { return apply_multichannel(input, [&](auto&& _input) {return std::sin(_input); }); } else { return std::sin(input); } } // sin Template Function Implementation (the version with execution policy) template<class ExecutionPolicy, typename T> requires (std::is_execution_policy_v<std::remove_cvref_t<ExecutionPolicy>>) [[nodiscard]] constexpr static auto sin(ExecutionPolicy&& execution_policy, const T& input) { if constexpr (Multichannel<T>) { return apply_multichannel(execution_policy, input, [&](auto&& _input) {return std::sin(_input); }); } else { return std::sin(input); } } // cos Template Function Implementation template<typename T> [[nodiscard]] constexpr static auto cos(const T& input) { if constexpr (Multichannel<T>) { return apply_multichannel(input, [&](auto&& _input) {return std::cos(_input); }); } else { return std::cos(input); } } // cos Template Function Implementation (the version with execution policy) template<class ExecutionPolicy, typename T> requires (std::is_execution_policy_v<std::remove_cvref_t<ExecutionPolicy>>) [[nodiscard]] constexpr static auto cos(ExecutionPolicy&& execution_policy, const T& input) { if constexpr (Multichannel<T>) { return apply_multichannel(execution_policy, input, [&](auto&& _input) {return std::cos(_input); }); } else { return std::cos(input); } } // tan Template Function Implementation template<typename T> [[nodiscard]] constexpr static auto tan(const T& input) { if constexpr (Multichannel<T>) { return apply_multichannel(input, [&](auto&& _input) {return std::tan(_input); }); } else { return std::tan(input); } } // tan Template Function Implementation (the version with execution policy) template<class ExecutionPolicy, typename T> requires (std::is_execution_policy_v<std::remove_cvref_t<ExecutionPolicy>>) [[nodiscard]] constexpr static auto tan(ExecutionPolicy&& execution_policy, const T& input) { if constexpr (Multichannel<T>) { return apply_multichannel(execution_policy, input, [&](auto&& _input) {return std::tan(_input); }); } else { return std::tan(input); } } // cot Template Function Implementation template<typename T> [[nodiscard]] constexpr static auto cot(const T& input) { if constexpr (Multichannel<T>) { return apply_multichannel(input, [&](auto&& _input) {return 1 / std::tan(_input); }); } else { return 1 / std::tan(input); } } // cot Template Function Implementation (the version with execution policy) template<class ExecutionPolicy, typename T> requires (std::is_execution_policy_v<std::remove_cvref_t<ExecutionPolicy>>) [[nodiscard]] constexpr static auto cot(ExecutionPolicy&& execution_policy, const T& input) { if constexpr (Multichannel<T>) { return apply_multichannel(execution_policy, input, [&](auto&& _input) {return 1 / std::tan(_input); }); } else { return 1 / std::tan(input); } } // sec Template Function Implementation template<typename T> [[nodiscard]] constexpr static auto sec(const T& input) { if constexpr (Multichannel<T>) { return apply_multichannel(input, [&](auto&& _input) {return 1 / std::cos(_input); }); } else { return 1 / std::cos(input); } } // sec Template Function Implementation (the version with execution policy) template<class ExecutionPolicy, typename T> requires (std::is_execution_policy_v<std::remove_cvref_t<ExecutionPolicy>>) [[nodiscard]] constexpr static auto sec(ExecutionPolicy&& execution_policy, const T& input) { if constexpr (Multichannel<T>) { return apply_multichannel(execution_policy, input, [&](auto&& _input) {return 1 / std::cos(_input); }); } else { return 1 / std::cos(input); } } // csc Template Function Implementation template<typename T> [[nodiscard]] constexpr static auto csc(const T& input) { if constexpr (Multichannel<T>) { return apply_multichannel(input, [&](auto&& _input) {return 1 / std::sin(_input); }); } else { return 1 / std::sin(input); } } // csc Template Function Implementation (the version with execution policy) template<class ExecutionPolicy, typename T> requires (std::is_execution_policy_v<std::remove_cvref_t<ExecutionPolicy>>) [[nodiscard]] constexpr static auto csc(ExecutionPolicy&& execution_policy, const T& input) { if constexpr (Multichannel<T>) { return apply_multichannel(execution_policy, input, [&](auto&& _input) {return 1 / std::sin(_input); }); } else { return 1 / std::sin(input); } } // asin Template Function Implementation template<typename T> [[nodiscard]] constexpr static auto asin(const T& input) { if constexpr (Multichannel<T>) { return apply_multichannel(input, [&](auto&& _input) {return std::asin(_input); }); } else { return std::asin(input); } } // asin Template Function Implementation (the version with execution policy) template<class ExecutionPolicy, typename T> requires (std::is_execution_policy_v<std::remove_cvref_t<ExecutionPolicy>>) [[nodiscard]] constexpr static auto asin(ExecutionPolicy&& execution_policy, const T& input) { if constexpr (Multichannel<T>) { return apply_multichannel(execution_policy, input, [&](auto&& _input) {return std::asin(_input); }); } else { return std::asin(input); } } // acos Template Function Implementation template<typename T> [[nodiscard]] constexpr static auto acos(const T& input) { if constexpr (Multichannel<T>) { return apply_multichannel(input, [&](auto&& _input) {return std::acos(_input); }); } else { return std::acos(input); } } // acos Template Function Implementation (the version with execution policy) template<class ExecutionPolicy, typename T> requires (std::is_execution_policy_v<std::remove_cvref_t<ExecutionPolicy>>) [[nodiscard]] constexpr static auto acos(ExecutionPolicy&& execution_policy, const T& input) { if constexpr (Multichannel<T>) { return apply_multichannel(execution_policy, input, [&](auto&& _input) {return std::acos(_input); }); } else { return std::acos(input); } } // atan Template Function Implementation template<typename T> [[nodiscard]] constexpr static auto atan(const T& input) { if constexpr (Multichannel<T>) { return apply_multichannel(input, [&](auto&& _input) {return std::atan(_input); }); } else { return std::atan(input); } } // atan Template Function Implementation (the version with execution policy) template<class ExecutionPolicy, typename T> requires (std::is_execution_policy_v<std::remove_cvref_t<ExecutionPolicy>>) [[nodiscard]] constexpr static auto atan(ExecutionPolicy&& execution_policy, const T& input) { if constexpr (Multichannel<T>) { return apply_multichannel(execution_policy, input, [&](auto&& _input) {return std::atan(_input); }); } else { return std::atan(input); } } // sinh Template Function Implementation template<typename T> [[nodiscard]] constexpr static auto sinh(const T& input) { if constexpr (Multichannel<T>) { return apply_multichannel(input, [&](auto&& _input) {return std::sinh(_input); }); } else { return std::sinh(input); } } // sinh Template Function Implementation (the version with execution policy) template<class ExecutionPolicy, typename T> requires (std::is_execution_policy_v<std::remove_cvref_t<ExecutionPolicy>>) [[nodiscard]] constexpr static auto sinh(ExecutionPolicy&& execution_policy, const T& input) { if constexpr (Multichannel<T>) { return apply_multichannel(execution_policy, input, [&](auto&& _input) {return std::sinh(_input); }); } else { return std::sinh(input); } } // cosh Template Function Implementation template<typename T> [[nodiscard]] constexpr static auto cosh(const T& input) { if constexpr (Multichannel<T>) { return apply_multichannel(input, [&](auto&& _input) {return std::cosh(_input); }); } else { return std::cosh(input); } } // cosh Template Function Implementation (the version with execution policy) template<class ExecutionPolicy, typename T> requires (std::is_execution_policy_v<std::remove_cvref_t<ExecutionPolicy>>) [[nodiscard]] constexpr static auto cosh(ExecutionPolicy&& execution_policy, const T& input) { if constexpr (Multichannel<T>) { return apply_multichannel(execution_policy, input, [&](auto&& _input) {return std::cosh(_input); }); } else { return std::cosh(input); } } // tanh Template Function Implementation template<typename T> [[nodiscard]] constexpr static auto tanh(const T& input) { if constexpr (Multichannel<T>) { return apply_multichannel(input, [&](auto&& _input) {return std::tanh(_input); }); } else { return std::tanh(input); } } // tanh Template Function Implementation (the version with execution policy) template<class ExecutionPolicy, typename T> requires (std::is_execution_policy_v<std::remove_cvref_t<ExecutionPolicy>>) [[nodiscard]] constexpr static auto tanh(ExecutionPolicy&& execution_policy, const T& input) { if constexpr (Multichannel<T>) { return apply_multichannel(execution_policy, input, [&](auto&& _input) {return std::tanh(_input); }); } else { return std::tanh(input); } } // asinh Template Function Implementation template<typename T> [[nodiscard]] constexpr static auto asinh(const T& input) { if constexpr (Multichannel<T>) { return apply_multichannel(input, [&](auto&& _input) {return std::asinh(_input); }); } else { return std::asinh(input); } } // asinh Template Function Implementation (the version with execution policy) template<class ExecutionPolicy, typename T> requires (std::is_execution_policy_v<std::remove_cvref_t<ExecutionPolicy>>) [[nodiscard]] constexpr static auto asinh(ExecutionPolicy&& execution_policy, const T& input) { if constexpr (Multichannel<T>) { return apply_multichannel(execution_policy, input, [&](auto&& _input) {return std::asinh(_input); }); } else { return std::asinh(input); } } // acosh Template Function Implementation template<typename T> [[nodiscard]] constexpr static auto acosh(const T& input) { if constexpr (Multichannel<T>) { return apply_multichannel(input, [&](auto&& _input) {return std::acosh(_input); }); } else { return std::acosh(input); } } // acosh Template Function Implementation (the version with execution policy) template<class ExecutionPolicy, typename T> requires (std::is_execution_policy_v<std::remove_cvref_t<ExecutionPolicy>>) [[nodiscard]] constexpr static auto acosh(ExecutionPolicy&& execution_policy, const T& input) { if constexpr (Multichannel<T>) { return apply_multichannel(execution_policy, input, [&](auto&& _input) {return std::acosh(_input); }); } else { return std::acosh(input); } } // atanh Template Function Implementation template<typename T> [[nodiscard]] constexpr static auto atanh(const T& input) { if constexpr (Multichannel<T>) { return apply_multichannel(input, [&](auto&& _input) {return std::atanh(_input); }); } else { return std::atanh(input); } } // atanh Template Function Implementation (the version with execution policy) template<class ExecutionPolicy, typename T> requires (std::is_execution_policy_v<std::remove_cvref_t<ExecutionPolicy>>) [[nodiscard]] constexpr static auto atanh(ExecutionPolicy&& execution_policy, const T& input) { if constexpr (Multichannel<T>) { return apply_multichannel(execution_policy, input, [&](auto&& _input) {return std::atanh(_input); }); } else { return std::atanh(input); } } // erf Template Function Implementation template<typename T> [[nodiscard]] constexpr static auto erf(const T& input) { if constexpr (Multichannel<T>) { return apply_multichannel(input, [&](auto&& _input) {return std::erf(_input); }); } else { return std::erf(input); } } // erf Template Function Implementation (the version with execution policy) template<class ExecutionPolicy, typename T> requires (std::is_execution_policy_v<std::remove_cvref_t<ExecutionPolicy>>) [[nodiscard]] constexpr static auto erf(ExecutionPolicy&& execution_policy, const T& input) { if constexpr (Multichannel<T>) { return apply_multichannel(execution_policy, input, [&](auto&& _input) {return std::erf(_input); }); } else { return std::erf(input); } } // erfc Template Function Implementation template<typename T> [[nodiscard]] constexpr static auto erfc(const T& input) { if constexpr (Multichannel<T>) { return apply_multichannel(input, [&](auto&& _input) {return std::erfc(_input); }); } else { return std::erfc(input); } } // erfc Template Function Implementation (the version with execution policy) template<class ExecutionPolicy, typename T> requires (std::is_execution_policy_v<std::remove_cvref_t<ExecutionPolicy>>) [[nodiscard]] constexpr static auto erfc(ExecutionPolicy&& execution_policy, const T& input) { if constexpr (Multichannel<T>) { return apply_multichannel(execution_policy, input, [&](auto&& _input) {return std::erfc(_input); }); } else { return std::erfc(input); } } // lgamma Template Function Implementation template<typename T> [[nodiscard]] constexpr static auto lgamma(const T& input) { if constexpr (Multichannel<T>) { return apply_multichannel(input, [&](auto&& _input) {return std::lgamma(_input); }); } else { return std::lgamma(input); } } // lgamma Template Function Implementation (the version with execution policy) template<class ExecutionPolicy, typename T> requires (std::is_execution_policy_v<std::remove_cvref_t<ExecutionPolicy>>) [[nodiscard]] constexpr static auto lgamma(ExecutionPolicy&& execution_policy, const T& input) { if constexpr (Multichannel<T>) { return apply_multichannel(execution_policy, input, [&](auto&& _input) {return std::lgamma(_input); }); } else { return std::lgamma(input); } } // tgamma Template Function Implementation template<typename T> [[nodiscard]] constexpr static auto tgamma(const T& input) { if constexpr (Multichannel<T>) { return apply_multichannel(input, [&](auto&& _input) {return std::tgamma(_input); }); } else { return std::tgamma(input); } } // tgamma Template Function Implementation (the version with execution policy) template<class ExecutionPolicy, typename T> requires (std::is_execution_policy_v<std::remove_cvref_t<ExecutionPolicy>>) [[nodiscard]] constexpr static auto tgamma(ExecutionPolicy&& execution_policy, const T& input) { if constexpr (Multichannel<T>) { return apply_multichannel(execution_policy, input, [&](auto&& _input) {return std::tgamma(_input); }); } else { return std::tgamma(input); } } // ceil Template Function Implementation template<typename T> [[nodiscard]] constexpr static auto ceil(const T& input) { if constexpr (Multichannel<T>) { return apply_multichannel(input, [&](auto&& _input) {return std::ceil(_input); }); } else { return std::ceil(input); } } // ceil Template Function Implementation (the version with execution policy) template<class ExecutionPolicy, typename T> requires (std::is_execution_policy_v<std::remove_cvref_t<ExecutionPolicy>>) [[nodiscard]] constexpr static auto ceil(ExecutionPolicy&& execution_policy, const T& input) { if constexpr (Multichannel<T>) { return apply_multichannel(execution_policy, input, [&](auto&& _input) {return std::ceil(_input); }); } else { return std::ceil(input); } } // floor Template Function Implementation template<typename T> [[nodiscard]] constexpr static auto floor(const T& input) { if constexpr (Multichannel<T>) { return apply_multichannel(input, [&](auto&& _input) {return std::floor(_input); }); } else { return std::floor(input); } } // floor Template Function Implementation (the version with execution policy) template<class ExecutionPolicy, typename T> requires (std::is_execution_policy_v<std::remove_cvref_t<ExecutionPolicy>>) [[nodiscard]] constexpr static auto floor(ExecutionPolicy&& execution_policy, const T& input) { if constexpr (Multichannel<T>) { return apply_multichannel(execution_policy, input, [&](auto&& _input) {return std::floor(_input); }); } else { return std::floor(input); } } // trunc Template Function Implementation template<typename T> [[nodiscard]] constexpr static auto trunc(const T& input) { if constexpr (Multichannel<T>) { return apply_multichannel(input, [&](auto&& _input) {return std::trunc(_input); }); } else { return std::trunc(input); } } // trunc Template Function Implementation (the version with execution policy) template<class ExecutionPolicy, typename T> requires (std::is_execution_policy_v<std::remove_cvref_t<ExecutionPolicy>>) [[nodiscard]] constexpr static auto trunc(ExecutionPolicy&& execution_policy, const T& input) { if constexpr (Multichannel<T>) { return apply_multichannel(execution_policy, input, [&](auto&& _input) {return std::trunc(_input); }); } else { return std::trunc(input); } } // nearbyint Template Function Implementation template<typename T> [[nodiscard]] constexpr static auto nearbyint(const T& input) { if constexpr (Multichannel<T>) { return apply_multichannel(input, [&](auto&& _input) {return std::nearbyint(_input); }); } else { return std::nearbyint(input); } } // nearbyint Template Function Implementation (the version with execution policy) template<class ExecutionPolicy, typename T> requires (std::is_execution_policy_v<std::remove_cvref_t<ExecutionPolicy>>) [[nodiscard]] constexpr static auto nearbyint(ExecutionPolicy&& execution_policy, const T& input) { if constexpr (Multichannel<T>) { return apply_multichannel(execution_policy, input, [&](auto&& _input) {return std::nearbyint(_input); }); } else { return std::nearbyint(input); } } // rint Template Function Implementation template<typename T> [[nodiscard]] constexpr static auto rint(const T& input) { if constexpr (Multichannel<T>) { return apply_multichannel(input, [&](auto&& _input) {return std::rint(_input); }); } else { return std::rint(input); } } // rint Template Function Implementation (the version with execution policy) template<class ExecutionPolicy, typename T> requires (std::is_execution_policy_v<std::remove_cvref_t<ExecutionPolicy>>) [[nodiscard]] constexpr static auto rint(ExecutionPolicy&& execution_policy, const T& input) { if constexpr (Multichannel<T>) { return apply_multichannel(execution_policy, input, [&](auto&& _input) {return std::rint(_input); }); } else { return std::rint(input); } } // ilogb Template Function Implementation template<typename T> [[nodiscard]] constexpr static auto ilogb(const T& input) { if constexpr (Multichannel<T>) { return apply_multichannel(input, [&](auto&& _input) {return std::ilogb(_input); }); } else { return std::ilogb(input); } } // ilogb Template Function Implementation (the version with execution policy) template<class ExecutionPolicy, typename T> requires (std::is_execution_policy_v<std::remove_cvref_t<ExecutionPolicy>>) [[nodiscard]] constexpr static auto ilogb(ExecutionPolicy&& execution_policy, const T& input) { if constexpr (Multichannel<T>) { return apply_multichannel(execution_policy, input, [&](auto&& _input) {return std::ilogb(_input); }); } else { return std::ilogb(input); } } // logb Template Function Implementation template<typename T> [[nodiscard]] constexpr static auto logb(const T& input) { if constexpr (Multichannel<T>) { return apply_multichannel(input, [&](auto&& _input) {return std::logb(_input); }); } else { return std::logb(input); } } // logb Template Function Implementation (the version with execution policy) template<class ExecutionPolicy, typename T> requires (std::is_execution_policy_v<std::remove_cvref_t<ExecutionPolicy>>) [[nodiscard]] constexpr static auto logb(ExecutionPolicy&& execution_policy, const T& input) { if constexpr (Multichannel<T>) { return apply_multichannel(execution_policy, input, [&](auto&& _input) {return std::logb(_input); }); } else { return std::logb(input); } } // fpclassify Template Function Implementation template<typename T> [[nodiscard]] constexpr static auto fpclassify(const T& input) { if constexpr (Multichannel<T>) { return apply_multichannel(input, [&](auto&& _input) {return std::fpclassify(_input); }); } else { return std::fpclassify(input); } } // fpclassify Template Function Implementation (the version with execution policy) template<class ExecutionPolicy, typename T> requires (std::is_execution_policy_v<std::remove_cvref_t<ExecutionPolicy>>) [[nodiscard]] constexpr static auto fpclassify(ExecutionPolicy&& execution_policy, const T& input) { if constexpr (Multichannel<T>) { return apply_multichannel(execution_policy, input, [&](auto&& _input) {return std::fpclassify(_input); }); } else { return std::fpclassify(input); } } // isfinite Template Function Implementation template<typename T> [[nodiscard]] constexpr static auto isfinite(const T& input) { if constexpr (Multichannel<T>) { return apply_multichannel(input, [&](auto&& _input) {return std::isfinite(_input); }); } else { return std::isfinite(input); } } // isfinite Template Function Implementation (the version with execution policy) template<class ExecutionPolicy, typename T> requires (std::is_execution_policy_v<std::remove_cvref_t<ExecutionPolicy>>) [[nodiscard]] constexpr static auto isfinite(ExecutionPolicy&& execution_policy, const T& input) { if constexpr (Multichannel<T>) { return apply_multichannel(execution_policy, input, [&](auto&& _input) {return std::isfinite(_input); }); } else { return std::isfinite(input); } } // isinf Template Function Implementation template<typename T> [[nodiscard]] constexpr static auto isinf(const T& input) { if constexpr (Multichannel<T>) { return apply_multichannel(input, [&](auto&& _input) {return std::isinf(_input); }); } else { return std::isinf(input); } } // isinf Template Function Implementation (the version with execution policy) template<class ExecutionPolicy, typename T> requires (std::is_execution_policy_v<std::remove_cvref_t<ExecutionPolicy>>) [[nodiscard]] constexpr static auto isinf(ExecutionPolicy&& execution_policy, const T& input) { if constexpr (Multichannel<T>) { return apply_multichannel(execution_policy, input, [&](auto&& _input) {return std::isinf(_input); }); } else { return std::isinf(input); } } // isnan Template Function Implementation template<typename T> [[nodiscard]] constexpr static auto isnan(const T& input) { if constexpr (Multichannel<T>) { return apply_multichannel(input, [&](auto&& _input) {return std::isnan(_input); }); } else { return std::isnan(input); } } // isnan Template Function Implementation (the version with execution policy) template<class ExecutionPolicy, typename T> requires (std::is_execution_policy_v<std::remove_cvref_t<ExecutionPolicy>>) [[nodiscard]] constexpr static auto isnan(ExecutionPolicy&& execution_policy, const T& input) { if constexpr (Multichannel<T>) { return apply_multichannel(execution_policy, input, [&](auto&& _input) {return std::isnan(_input); }); } else { return std::isnan(input); } } // isnormal Template Function Implementation template<typename T> [[nodiscard]] constexpr static auto isnormal(const T& input) { if constexpr (Multichannel<T>) { return apply_multichannel(input, [&](auto&& _input) {return std::isnormal(_input); }); } else { return std::isnormal(input); } } // isnormal Template Function Implementation (the version with execution policy) template<class ExecutionPolicy, typename T> requires (std::is_execution_policy_v<std::remove_cvref_t<ExecutionPolicy>>) [[nodiscard]] constexpr static auto isnormal(ExecutionPolicy&& execution_policy, const T& input) { if constexpr (Multichannel<T>) { return apply_multichannel(execution_policy, input, [&](auto&& _input) {return std::isnormal(_input); }); } else { return std::isnormal(input); } } // signbit Template Function Implementation template<typename T> [[nodiscard]] constexpr static auto signbit(const T& input) { if constexpr (Multichannel<T>) { return apply_multichannel(input, [&](auto&& _input) {return std::signbit(_input); }); } else { return std::signbit(input); } } // signbit Template Function Implementation (the version with execution policy) template<class ExecutionPolicy, typename T> requires (std::is_execution_policy_v<std::remove_cvref_t<ExecutionPolicy>>) [[nodiscard]] constexpr static auto signbit(ExecutionPolicy&& execution_policy, const T& input) { if constexpr (Multichannel<T>) { return apply_multichannel(execution_policy, input, [&](auto&& _input) {return std::signbit(_input); }); } else { return std::signbit(input); } } // exp Template Function Implementation template<typename T> [[nodiscard]] constexpr static auto exp(const T& input) { if constexpr (Multichannel<T>) { return apply_multichannel(input, [&](auto&& _input) {return std::exp(_input); }); } else { return std::exp(input); } } // exp Template Function Implementation (the version with execution policy) template<class ExecutionPolicy, typename T> requires (std::is_execution_policy_v<std::remove_cvref_t<ExecutionPolicy>>) [[nodiscard]] constexpr static auto exp(ExecutionPolicy&& execution_policy, const T& input) { if constexpr (Multichannel<T>) { return apply_multichannel(execution_policy, input, [&](auto&& _input) {return std::exp(_input); }); } else { return std::exp(input); } } // exp2 Template Function Implementation template<typename T> [[nodiscard]] constexpr static auto exp2(const T& input) { if constexpr (Multichannel<T>) { return apply_multichannel(input, [&](auto&& _input) {return std::exp2(_input); }); } else { return std::exp2(input); } } // exp2 Template Function Implementation (the version with execution policy) template<class ExecutionPolicy, typename T> requires (std::is_execution_policy_v<std::remove_cvref_t<ExecutionPolicy>>) [[nodiscard]] constexpr static auto exp2(ExecutionPolicy&& execution_policy, const T& input) { if constexpr (Multichannel<T>) { return apply_multichannel(execution_policy, input, [&](auto&& _input) {return std::exp2(_input); }); } else { return std::exp2(input); } } // expm1 Template Function Implementation template<typename T> [[nodiscard]] constexpr static auto expm1(const T& input) { if constexpr (Multichannel<T>) { return apply_multichannel(input, [&](auto&& _input) {return std::expm1(_input); }); } else { return std::expm1(input); } } // expm1 Template Function Implementation (the version with execution policy) template<class ExecutionPolicy, typename T> requires (std::is_execution_policy_v<std::remove_cvref_t<ExecutionPolicy>>) [[nodiscard]] constexpr static auto expm1(ExecutionPolicy&& execution_policy, const T& input) { if constexpr (Multichannel<T>) { return apply_multichannel(execution_policy, input, [&](auto&& _input) {return std::expm1(_input); }); } else { return std::expm1(input); } } // log Template Function Implementation template<typename T> [[nodiscard]] constexpr static auto log(const T& input) { if constexpr (Multichannel<T>) { return apply_multichannel(input, [&](auto&& _input) {return std::log(_input); }); } else { return std::log(input); } } // log Template Function Implementation (the version with execution policy) template<class ExecutionPolicy, typename T> requires (std::is_execution_policy_v<std::remove_cvref_t<ExecutionPolicy>>) [[nodiscard]] constexpr static auto log(ExecutionPolicy&& execution_policy, const T& input) { if constexpr (Multichannel<T>) { return apply_multichannel(execution_policy, input, [&](auto&& _input) {return std::log(_input); }); } else { return std::log(input); } } // log10 Template Function Implementation template<typename T> [[nodiscard]] constexpr static auto log10(const T& input) { if constexpr (Multichannel<T>) { return apply_multichannel(input, [&](auto&& _input) {return std::log10(_input); }); } else { return std::log10(input); } } // log10 Template Function Implementation (the version with execution policy) template<class ExecutionPolicy, typename T> requires (std::is_execution_policy_v<std::remove_cvref_t<ExecutionPolicy>>) [[nodiscard]] constexpr static auto log10(ExecutionPolicy&& execution_policy, const T& input) { if constexpr (Multichannel<T>) { return apply_multichannel(execution_policy, input, [&](auto&& _input) {return std::log10(_input); }); } else { return std::log10(input); } } // log1p Template Function Implementation template<typename T> [[nodiscard]] constexpr static auto log1p(const T& input) { if constexpr (Multichannel<T>) { return apply_multichannel(input, [&](auto&& _input) {return std::log1p(_input); }); } else { return std::log1p(input); } } // log1p Template Function Implementation (the version with execution policy) template<class ExecutionPolicy, typename T> requires (std::is_execution_policy_v<std::remove_cvref_t<ExecutionPolicy>>) [[nodiscard]] constexpr static auto log1p(ExecutionPolicy&& execution_policy, const T& input) { if constexpr (Multichannel<T>) { return apply_multichannel(execution_policy, input, [&](auto&& _input) {return std::log1p(_input); }); } else { return std::log1p(input); } } // log2 Template Function Implementation template<typename T> [[nodiscard]] constexpr static auto log2(const T& input) { if constexpr (Multichannel<T>) { return apply_multichannel(input, [&](auto&& _input) {return std::log2(_input); }); } else { return std::log2(input); } } // log2 Template Function Implementation (the version with execution policy) template<class ExecutionPolicy, typename T> requires (std::is_execution_policy_v<std::remove_cvref_t<ExecutionPolicy>>) [[nodiscard]] constexpr static auto log2(ExecutionPolicy&& execution_policy, const T& input) { if constexpr (Multichannel<T>) { return apply_multichannel(execution_policy, input, [&](auto&& _input) {return std::log2(_input); }); } else { return std::log2(input); } } // two_input_map_reduce Template Function Implementation template< class ExecutionPolicy, std::ranges::input_range Input1, std::ranges::input_range Input2, class T, class BinaryOp1 = std::minus<T>, class BinaryOp2 = std::plus<T> > requires(std::is_execution_policy_v<std::remove_cvref_t<ExecutionPolicy>>) constexpr auto two_input_map_reduce( ExecutionPolicy execution_policy, const Input1& input1, const Input2& input2, const T init = {}, const BinaryOp1& binop1 = std::minus<T>(), const BinaryOp2& binop2 = std::plus<T>()) { if (input1.size() != input2.size()) { throw std::runtime_error("Size mismatched!"); } auto transformed = std::views::zip(input1, input2) | std::views::transform([&](auto input) { return std::invoke(binop1, std::get<0>(input), std::get<1>(input)); }); return std::reduce( execution_policy, transformed.begin(), transformed.end(), init, binop2 ); } // euclidean_distance Template Function Implementation template< arithmetic OutputT = double, class ExPo, arithmetic ElementT1 = double, arithmetic ElementT2 = double > requires(std::is_execution_policy_v<std::remove_cvref_t<ExPo>>) constexpr static auto euclidean_distance( ExPo execution_policy, const Image<ElementT1>& input1, const Image<ElementT2>& input2, const OutputT output = 0.0 ) { if (input1.getSize() != input2.getSize()) { throw std::runtime_error("Size mismatched!"); } return std::sqrt(two_input_map_reduce(execution_policy, input1.getImageData(), input2.getImageData(), OutputT{}, [&](auto&& element1, auto&& element2) { return std::pow(element1 - element2, 2.0); })); } // euclidean_distance Template Function Implementation template< arithmetic OutputT = double, arithmetic ElementT1 = double, arithmetic ElementT2 = double > constexpr static auto euclidean_distance( const Image<ElementT1>& input1, const Image<ElementT2>& input2, const OutputT output = 0.0 ) { return euclidean_distance(std::execution::seq, input1, input2, output); } // euclidean_distance Template Function Implementation for multiple channel image template< class ExPo, class ElementT1, class ElementT2 > requires((std::same_as<ElementT1, RGB>) || (std::same_as<ElementT1, RGB_DOUBLE>) || (std::same_as<ElementT1, HSV>)) and ((std::same_as<ElementT2, RGB>) || (std::same_as<ElementT2, RGB_DOUBLE>) || (std::same_as<ElementT2, HSV>)) and (std::is_execution_policy_v<std::remove_cvref_t<ExPo>>) constexpr static auto euclidean_distance( ExPo execution_policy, const Image<ElementT1>& input1, const Image<ElementT2>& input2 ) { return sqrt(execution_policy, two_input_map_reduce(execution_policy, input1.getImageData(), input2.getImageData(), MultiChannel<double>{}, [&](auto&& element1, auto&& element2) { return pow(execution_policy, element1 - element2, 2.0); })); } // euclidean_distance Template Function Implementation for multiple channel image template< class ExPo, class ElementT1, class ElementT2, std::size_t Size > constexpr static auto euclidean_distance( ExPo execution_policy, const Image<MultiChannel<ElementT1, Size>>& input1, const Image<MultiChannel<ElementT2, Size>>& input2 ) { return sqrt(execution_policy, two_input_map_reduce(execution_policy, input1.getImageData(), input2.getImageData(), MultiChannel<double, Size>{}, [&](auto&& element1, auto&& element2) { return pow(execution_policy, element1 - element2, 2.0); })); } // euclidean_distance Template Function Implementation for multiple channel image template< class ElementT1, class ElementT2 > requires((std::same_as<ElementT1, RGB>) || (std::same_as<ElementT1, RGB_DOUBLE>) || (std::same_as<ElementT1, HSV>) || (is_MultiChannel<ElementT1>::value)) and ((std::same_as<ElementT2, RGB>) || (std::same_as<ElementT2, RGB_DOUBLE>) || (std::same_as<ElementT2, HSV>) || (is_MultiChannel<ElementT2>::value)) constexpr static auto euclidean_distance( const Image<ElementT1>& input1, const Image<ElementT2>& input2 ) { return euclidean_distance(std::execution::seq, input1, input2); } // hypot Template Function Implementation template<typename... Args> constexpr auto hypot(Args... args) { return std::sqrt((std::pow(args, 2.0) + ...)); } // Copy from https://stackoverflow.com/a/41171552 template<class TupType, std::size_t... I> void print_tuple(const TupType& _tup, std::index_sequence<I...>) { std::cout << "("; (..., (std::cout << (I == 0? "" : ", ") << std::get<I>(_tup))); std::cout << ")\n"; } template<class... T> void print_tuple(const std::tuple<T...>& _tup) { print_tuple(_tup, std::make_index_sequence<sizeof...(T)>()); } } void euclidean_distanceRGBTest( const std::size_t sizex = 3, const std::size_t sizey = 2 ) { TinyDIP::Image<TinyDIP::RGB> image1(sizex, sizey); image1.setAllValue(TinyDIP::RGB{1, 2, 3}); image1.print(" "); TinyDIP::Image<TinyDIP::RGB> image2(sizex, sizey); image2.print(" "); std::cout << "euclidean_distance of image1 and image2: " << TinyDIP::euclidean_distance(image1, image2) << '\n'; return; } int main() { auto start = std::chrono::system_clock::now(); euclidean_distanceRGBTest(); auto end = std::chrono::system_clock::now(); std::chrono::duration<double> elapsed_seconds = end - start; std::time_t end_time = std::chrono::system_clock::to_time_t(end); if (elapsed_seconds.count() != 1) { std::cout << "Computation finished at " << std::ctime(&end_time) << "elapsed time: " << elapsed_seconds.count() << " seconds.\n"; } else { std::cout << "Computation finished at " << std::ctime(&end_time) << "elapsed time: " << elapsed_seconds.count() << " second.\n"; } return EXIT_SUCCESS; }
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