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#
GLSL
Go
Haskell
HLSL
Hook
Hylo
IL
ispc
Java
Julia
Kotlin
LLVM IR
LLVM MIR
Modula-2
Nim
Objective-C
Objective-C++
OCaml
Odin
OpenCL C
Pascal
Pony
Python
Racket
Ruby
Rust
Snowball
Scala
Slang
Solidity
Spice
SPIR-V
Swift
LLVM TableGen
Toit
TypeScript Native
V
Vala
Visual Basic
Vyper
WASM
Zig
Javascript
GIMPLE
Ygen
cpp2_cppfront 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
cppfront trunk
Options
Source code
print_ordinals: (ordinals: std::vector<unsigned>) = { std::cout << "ordinals: "; for ordinals do (ord: unsigned) { std::cout << std::setw(3) << ord << ' '; } std::cout << '\n'; } to_uppercase: (c: char) -> char = { return unsafe_narrow<char>(std::toupper(c)); } to_uppercase_inplace: (inout c: char) = { c = to_uppercase(c); } unary_transform_example: (inout hello: std::string, copy world: std::string) = { // Transform string to uppercase in-place std::transform(hello.cbegin(), hello.cend(), hello.begin(), to_uppercase); std::cout << "hello = " << std::quoted(hello) << '\n'; // for_each version std::for_each(world.begin(), world.end(), to_uppercase_inplace); std::cout << "world = " << std::quoted(world) << '\n'; } binary_transform_example: (move ordinals: std::vector<unsigned>) = { // Transform numbers to doubled values print_ordinals(ordinals); std::transform(ordinals.cbegin(), ordinals.cend(), ordinals.cbegin(), ordinals.begin(), std::plus<>()); print_ordinals(ordinals); } main: () = { hello: std::string = ("hello"); unary_transform_example(hello, "world"); ordinals: std::vector<unsigned> = (); std::copy(hello.cbegin(), hello.cend(), std::back_inserter(ordinals)); binary_transform_example(move ordinals); }
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
CE on Bluesky
About the author
Statistics
Changelog
Version tree