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 <type_traits> | |
using namespace std; | |
class NullType; | |
template<size_t, template<class> class...> struct nth_type { | |
template<class V> using type = NullType; | |
}; |
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 <cstdlib> | |
class const_str { | |
const char* str; | |
size_t len; | |
public: | |
template<size_t N> constexpr const_str(const char (&str)[N]) : str{str}, len{N - 1} {} | |
constexpr size_t size() const { return len; } | |
}; |
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
#ifndef any_h | |
#define any_h | |
namespace utility { | |
class any { | |
struct impl_base { | |
virtual impl_base* clone() const = 0; | |
virtual ~impl_base() = default; | |
}; |
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 <typeinfo> | |
#include <cstdint> | |
struct bit_field { | |
uint32_t a : 6; | |
}; | |
struct helper { | |
union { |
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> | |
namespace ex { | |
template<class T> void foo(T) { std::cout << "primary template\n"; } | |
} | |
template<> void ex::foo<int>(int) { std::cout << "specialization outside of namespace\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> | |
int main() { | |
unsigned a = 1; | |
float b = 2.0f; | |
auto c = -a * b; | |
std::cout << c << 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
#include <iostream> | |
struct null_ptr_t { | |
constexpr null_ptr_t() {} | |
template<typename T> operator T*() const { return nullptr; } | |
}; | |
constexpr null_ptr_t null_ptr; |
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
template<class T1, class T2> struct some_template { | |
using true_ = char(&)[1]; | |
using false_ = char(&)[2]; | |
struct host { | |
operator T1*() const; | |
operator T2*(); | |
}; | |
template<typename 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> | |
int main() { | |
auto a = int{}; | |
const auto b = sizeof(++a) == sizeof(int); | |
std::cout << a << ' ' << b << '\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> | |
int foo(int& a) { return ++a; } | |
int main() { | |
auto a = int{}; | |
const auto b = sizeof(foo(a)) == sizeof(int); | |
std::cout << a << ' ' << b << '\n'; | |
} |