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 <utility> | |
struct any_type | |
{ | |
template <class T> | |
constexpr operator T(); // non explicit | |
}; | |
namespace detail | |
{ |
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 <utility> | |
#include <cstddef> | |
#include <stdexcept> | |
#include <ctime> | |
struct test_t { }; | |
namespace detail | |
{ | |
template <size_t I> |
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
#pragma once | |
#include <type_traits> | |
#include <tuple> | |
#include <memory> | |
template <std::size_t N, class... Types> | |
struct packed_tuple; | |
// is_packed_tuple | |
template <class T> |
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
namespace detail | |
{ | |
template <class T> | |
struct flag | |
{ | |
struct dummy { | |
constexpr dummy() {} | |
#pragma GCC diagnostic push | |
#pragma GCC diagnostic ignored "-Wnon-template-friend" |
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 <ctime> | |
#include <utility> | |
template <class T, class F, T... I> | |
bool to_const(T value, F&& fn, std::integer_sequence<T, I...>) { | |
return ( | |
(value == I && (fn(std::integral_constant<T, I>{}), true)) | |
|| ... // or continue | |
); |
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> | |
template <class T, class = std::enable_if_t<std::is_integral<T>::value>> | |
using integral_t = T; | |
// the usage | |
template <class T> | |
void f(integral_t<T> a) {} | |
int main() |
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> | |
struct printer | |
{ | |
template <class T> | |
constexpr void operator()(const T& t) const { | |
std::cout << t << '\n'; | |
} | |
}; |
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 <functional> | |
#include <any> | |
struct any_type : std::any | |
{ | |
using std::any::any; | |
template <class T> operator T() const { | |
return std::any_cast<T>(*this); | |
} |
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
#pragma once | |
#include <utility> | |
template <class T, std::size_t... I> | |
inline const char* type_name(std::index_sequence<I...>) { | |
static constexpr char name[] = { __PRETTY_FUNCTION__[I + 60]..., 0 }; | |
return name; | |
} | |
template <class T> |
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 <string_view> | |
template <class T> | |
constexpr std::string_view type_name(const T&) | |
{ | |
std::string_view sv = __PRETTY_FUNCTION__; | |
sv.remove_prefix(sv.find('=') + 2); | |
return { sv.data(), sv.find(';') }; |
NewerOlder