This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <memory> | |
struct Base | |
{ | |
~Base() | |
{ | |
std::cout << "~Base()" << std::endl; | |
} | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Original work: https://gist.github.com/odeblic/fa54037bf4d764a5dc02735cb4bd79f3 | |
* Inspired from: https://youtu.be/ZiNGWHg5Z-o | |
* | |
* Compile | |
* | |
* $ g++ -Wall -Wextra smart_dtor.cpp | |
* | |
* Run | |
* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** zero-dependency allocation-free mapping enum values to names */ | |
namespace enumnames { | |
typedef const char* (*name)(); | |
bool match(const char*, const char*) noexcept; /* to be provided by the user */ | |
template<typename T, T K, name V> | |
struct tuple { | |
typedef T key_t; | |
static constexpr T key = K; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <type_traits> | |
namespace detail { | |
// No need to give up constexpr for std::forward | |
template <class T> | |
constexpr T && forward(typename std::remove_reference<T>::type & t) noexcept { | |
return static_cast<T &&>(t); | |
} |
NewerOlder