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
OpenCL C
Pascal
Pony
Python
Racket
Ruby
Rust
Snowball
Scala
Solidity
Spice
SPIR-V
Swift
LLVM TableGen
Toit
TypeScript Native
V
Vala
Visual Basic
WASM
Zig
Javascript
GIMPLE
Ygen
circle 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
Build 128
Build 129
Build 131
Latest
Options
Source code
#feature on safety template<typename Key, typename Value> class Map { public: // Lifetime elision rules constrain the return by self. auto get1(self^, const Key^ key) safe -> Value^; // Use explicit parameterizations for alternate constraints. auto get2/(a)(self^/a, const Key^/a key) safe -> Value^/a; }; int main() safe { Map<float, long> map { }; // Bind the key reference to a materialized temporary. // The temporary expires at the end of this statement. long^ value1 = mut map.get1(3.14f); // We can still access value, because it's not constrained on the // key argument. *value1 = 1001; // The call to get2 constrains the returned reference to the lifetime // of the key temporary. long^ value2 = mut map.get2(1.6186f); // This is ill-formed, because get2's key argument is out of scope. *value2 = 1002; }
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