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
TypeScript Native
V
Vala
Visual Basic
Vyper
WASM
Zig
Javascript
GIMPLE
Ygen
sway
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
quantity: @struct <Number: type> type = { number: Number; } // from: (forward q: quantity) = _ = q; // Translate the above to: namespace cpp2 { template <template <typename...> class C, typename T> consteval auto is() -> bool { if constexpr (requires(T t) { []<typename... Ts>(C<Ts...> const&) { }(t); }) { return true; } return false; } } from: (forward q) requires cpp2::is<quantity, CPP2_TYPEOF(q)>() = _ = q; // from: (forward q: quantity<float>) = _ = q; // Translate the above to: namespace cpp2 { template <typename T, typename U> consteval auto is() -> bool { return std::is_same_v<T, U>; } } func: (forward q) requires cpp2::is<quantity<float>, CPP2_TYPEOF(q)>() = _ = q; main: () = { q: quantity<i32> = (); q.from(); quantity<float>().func(); // q.func(); // 0.from(); _ = q; }
cmake source #2
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
Options
Source code
cmake_minimum_required(VERSION ${CMAKE_VERSION}) project(test LANGUAGES CXX) include("CompilerExplorerSetup.cmake") # add_library(greet STATIC) # jegp_cpp2_target_sources(greet PUBLIC FILE_SET CXX_MODULES FILES "greet.cpp2" "hello.cpp2") # add_library(title STATIC) # jegp_cpp2_target_sources(title PUBLIC FILE_SET CXX_MODULES FILES "title.cpp2") # target_link_libraries(title PRIVATE greet) add_executable(main) jegp_cpp2_target_sources(main PRIVATE "main.cpp2") # target_link_libraries(main PRIVATE title) target_include_directories( main PUBLIC # mp-units # "/opt/compiler-explorer/libs/mp-units/trunk/src/core/include;/opt/compiler-explorer/libs/mp-units/trunk/src/core-fmt/include;/opt/compiler-explorer/libs/mp-units/trunk/src/core-io/include;/opt/compiler-explorer/libs/mp-units/trunk/src/systems/isq/include;/opt/compiler-explorer/libs/mp-units/trunk/src/systems/isq-iec80000/include;/opt/compiler-explorer/libs/mp-units/trunk/src/systems/isq-natural/include;/opt/compiler-explorer/libs/mp-units/trunk/src/systems/si/include;/opt/compiler-explorer/libs/mp-units/trunk/src/systems/si-cgs/include;/opt/compiler-explorer/libs/mp-units/trunk/src/systems/si-fps/include;/opt/compiler-explorer/libs/mp-units/trunk/src/systems/si-iau/include;/opt/compiler-explorer/libs/mp-units/trunk/src/systems/si-imperial/include;/opt/compiler-explorer/libs/mp-units/trunk/src/systems/si-international/include;/opt/compiler-explorer/libs/mp-units/trunk/src/systems/si-typographic/include;/opt/compiler-explorer/libs/mp-units/trunk/src/systems/si-us/include;/opt/compiler-explorer/libs/fmt/8.1.1/include;/opt/compiler-explorer/libs/gsl-lite/include" )
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