David Blume's GitList
Repositories
testcode.git
Code
Commits
Branches
Tags
Search
Tree:
e120db9
Branches
Tags
c++11
main
start
testcode.git
product
lifetime.cpp
Add SeparateDefinitionBlocks to .clang-format
dblume
commited
e120db9
at 2025-01-21 13:07:32
lifetime.cpp
Blame
History
Raw
#include "lifetime.h" #include <cstdio> #include <array> // From C++ Weekly with Jason Turner // https://www.youtube.com/watch?v=6SaUwqw4ueE // // Test with: // ls -1 lifetime* | entr sh -c 'g++ -Wall -std=c++17 lifetime.cpp && valgrind -q --leak-check=yes --show-leak-kinds=all ./a.out' Lifetime::Lifetime() { std::puts("Lifetime() // default ctor"); } Lifetime::~Lifetime() { std::puts("~Lifetime() // destructor"); } Lifetime::Lifetime(const Lifetime &) { std::puts("Lifetime(const Lifetime &) // copy ctor"); } Lifetime::Lifetime(Lifetime &&) { std::puts("Lifetime(Lifetime &&) // move ctor"); } Lifetime &Lifetime::operator=(Lifetime &&) { std::puts("operator=(const Lifetime &&) // move assign"); return *this; } Lifetime &Lifetime::operator=(const Lifetime &) { std::puts("operator=(const Lifetime &) // copy assign"); return *this; } /* int main() { #if 0 Lifetime l1; Lifetime l2; std::array<Lifetime, 2> a{l1, l2}; #elif 1 Lifetime l1; Lifetime l2; std::array<Lifetime, 2> a{std::move(l1), std::move(l2)}; #else auto make_lifetime = [](const int value) { // Benefits from return value optimization Lifetime l; l.data_ = value; return l; }; std::array<Lifetime, 2> a{make_lifetime(42), make_lifetime(43)}; #endif } */