|
You are here |
rust.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 MyPair { int a; int b; }; void CopyPair(const std::vector<std::pair<int, int>>& a, std::vector<std::pair<int, int>>& b) { std::copy(a.begin(), a.end(), b.begin()); } void SmartCopyPair(const std::vector<MyPair>& a, std::vector<MyPair>& b) { std::copy(a.begin(), a.end(), b.begin()); } | |
| | | | |
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 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) { first = other.first; second = other.second; return *this; } }; int main() { int x = 10; MyPair<int&, int> a(x, 5); MyPair<int&, int> b(x, 10); b = a; } | |
| | | | |
nishtahir.com
|
|
| | | One of the most interesting features of WebAssembly is its memory model. Despite providing a system that allows for direct access and control of raw bytes, it does this in a way that offers more safety than one would typically expect out of low-level environments like C/C++. WASM memory | ||