Thanks for using Compiler Explorer
Sponsors
Jakt
C++
Ada
Analysis
Android Java
Android Kotlin
Assembly
C
C3
Carbon
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#
Go
Haskell
HLSL
Hook
Hylo
ispc
Java
Julia
Kotlin
LLVM IR
LLVM MIR
Modula-2
Nim
Objective-C
Objective-C++
OCaml
OpenCL C
Pascal
Pony
Python
Racket
Ruby
Rust
Snowball
Scala
Solidity
Spice
Swift
LLVM TableGen
Toit
TypeScript Native
V
Vala
Visual Basic
WASM
Zig
Javascript
GIMPLE
cpp2_cppfront source #6
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
cppfront trunk
Options
Source code
ranges: namespace == std::ranges; folk_info: @struct type = { uid: u32; name: std::string; position: std::string; } projector_example :() = { folks: std::vector = ( :folk_info = (0, "Ana", "dev"), :folk_info = (1, "Bob", "devops"), :folk_info = (2, "Eve", "ops") ); using namespace std::literals; who:= "Eve"; it:= std::ranges::find(folks, who, folk_info::name&); if it != folks.end() { std::println("Profile:"); std::println(" UID: {}", it*.uid); std::println(" Name: {}", it*.name); std::println(" Position: {}", it*.position); std::println(""); } } main: () = { projector_example(); n1: const int = 3; n2: const int = 5; v: std::array = (4, 1, 3, 2); if ranges::find(v, n1) != v.end() { std::println("v contains: {}", n1); } else { std::println("v does not contain: {}", n1); } if ranges::find(v.begin(), v.end(), n2) != v.end() { std::println("v contains: {}", n2); } else { std::println("v does not contain: {}", n2); } is_even:= :(x: int) x % 2 == 0; (result:= ranges::find_if(v.begin(), v.end(), is_even)) if result != v.end() { std::println("First even element in v: {}", result*); } else { std::println("No even elements in v"); } (result:= ranges::find_if_not(v, is_even)) if result != v.end() { std::println("First odd element in v: {}", result*); } else { std::println("No odd elements in v"); } divides_13:= :(x: int) x % 13 == 0; (result:= ranges::find_if(v, divides_13)) if result != v.end() { std::println("First element divisible by 13 in v: {}", result*); } else { std::println("No elements in v are divisible by 13"); } (result:= ranges::find_if_not(v.begin(), v.end(), divides_13)) if result != v.end() { std::println("First element indivisible by 13 in v: {}", result*); } else { std::println("All elements in v are divisible by 13"); } nums: std::vector = (:std::complex<double> = (4, 2)); it:= ranges::find(nums, std::complex<double>(4, 2)); assert(it == nums.begin()); }
Become a Patron
Sponsor on GitHub
Donate via PayPal
Source on GitHub
Mailing list
Installed libraries
Wiki
Report an issue
How it works
Contact the author
CE on Mastodon
About the author
Statistics
Changelog
Version tree