This file contains hidden or 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 <type_traits> | |
template <typename T, typename = typename std::is_enum<T>::type> | |
struct safe_underlying_type { using type = T; }; | |
template <typename T> | |
struct safe_underlying_type<T, std::true_type> { using type = std::underlying_type_t<T>; }; | |
template <typename T> |
This file contains hidden or 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> | |
#include <iostream> | |
template <typename T, typename = typename std::is_enum<T>::type> | |
struct safe_underlying_type { using type = T; }; | |
template <typename T> | |
struct safe_underlying_type<T, std::true_type> { using type = std::underlying_type_t<T>; }; | |
template <typename T> |
This file contains hidden or 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> | |
// impl ---------- | |
template <typename T> | |
struct accessor { | |
static typename T::type value; | |
}; | |
template <typename T> |
This file contains hidden or 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 <sstream> | |
#ifdef __GNUG__ | |
#include <cstdlib> | |
#include <memory> | |
#include <cxxabi.h> | |
std::string demangle(const char *name) { |
This file contains hidden or 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> | |
// impl ---------- | |
#if (__cplusplus > 201402L) | |
using std::bool_constant; | |
using std::negation; | |
using std::conjunction; | |
using std::disjunction; |
This file contains hidden or 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> | |
template <typename T, typename U> | |
constexpr inline T &force_cast(U &u) { return (*reinterpret_cast<T *>(&u)); } | |
template <typename T, typename U> | |
constexpr inline const T &force_cast(const U &u) { return (*reinterpret_cast<const T *>(&u)); } | |
struct foo { int value = 123; }; |
This file contains hidden or 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 <functional> | |
#include <memory> | |
// impl ---------- | |
struct state { | |
using pointer = std::shared_ptr<state>; | |
virtual pointer operator()() = 0; | |
}; |
This file contains hidden or 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> | |
// impl ---------- | |
template <auto V> | |
struct auto_constant { | |
static constexpr auto value = V; | |
using value_type = decltype(value); | |
using type = auto_constant; |
This file contains hidden or 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 <functional> | |
#include <type_traits> | |
// impl ---------- | |
template <typename T, typename F = decltype(+std::declval<T>())> | |
class fn { | |
public: | |
using type = std::remove_pointer_t<F>; |
This file contains hidden or 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> | |
class foo { | |
public: | |
foo() { std::cout << __func__ << std::endl; } | |
~foo() { std::cout << __func__ << std::endl; } | |
}; | |
class bar : public foo { |