/explore
|
You are here |
zig.godbolt.org | ||
| | | | |
gcc.godbolt.org
// By value because it fits in the register. int extract(const std::pair<int, int> p) { return p.second; } int extract(const std::tuple<int, int> p) { return std::get<1>(p); } std::pair<int, int> make_pair(int a, int b) { return {a, b}; } std::tuple<int, int> make_tuple(int a, int b) { return {a, b}; } |
|
| | | | | ||
| | | | |
gcc.godbolt.org
struct RC { size_t s; size_t w; }; void init_zero(RC& rc) { rc.s = 0; rc.w = 0; } void init_one(RC& rc) { rc.s = 1; rc.w = 1; } void dealloc(); void dec_zero_exact(std::atomic<size_t>& c) { if (0 == c.fetch_sub(1, std::memory_order_acq_rel)) { dealloc(); } } void dec_zero_less(std::atomic<size_t>& c) { using ssize_t = std::make_signed_t<size_t>; if (0 >= static_cast<ssize_t>(c.fetch_sub(1, std::memory_order_acq_rel))) { dealloc(); } } void dec_one(std::atomic<size_t>& c) { if (1 == c.fetch_sub(1, std::memory_order_acq_rel)) { dealloc(); } } |
|
| | | | | ||
| | | | |
gcc.godbolt.org
template<class T1, class T2> struct MyPair { T1 first; T2 second; static constexpr bool has_references = std::is_reference_v<T1> || std::is_reference_v<T2>; MyPair(const MyPair& other) = default; MyPair(const T1& x, const T2& y) : first(x), second(y) {} MyPair& operator=(const MyPair&) requires(!has_references) = default; MyPair& operator=(const MyPair& other) requires(has_references) { this->~MyPair(); return * new (this) MyPair(other); } }; int main() { int x = 10; int y = 1; MyPair<int&, int> a(x, 5); MyPair<int&, int> b(y, 10); b = a; return b.first; // 10 } |
|
| | | | | ||
| | | | |
thume.ca
[AI summary] This blog post by Tristan Hume details his experience writing a compiler for a course project using Rust. He discusses various aspects of the project including the use of Rust's powerful enums and pattern matching, handling variable and type resolution, reference counting with Rc, code generation for x86 assembly, and the use of usercorn to run Linux binaries on macOS. The post also reflects on the challenges and benefits of using Rust for such a project, comparing it with other languages and design decisions. |
|
| | | |||