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> | |
#include <typeinfo> | |
template <typename BASE, typename ... BASES> | |
struct MultiDerived : BASE, MultiDerived<BASES> ... | |
{ | |
void EveryAction() | |
{ | |
BASE::Action(); |
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 <unsigned int N> | |
struct factorial | |
{ | |
enum { value = N * factorial<N - 1>::value }; | |
}; | |
template <> | |
struct factorial<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> | |
#include <exception> | |
#include <cstdlib> | |
void f() noexcept(false) | |
{ | |
std::cout << "f()" << std::endl; | |
throw('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 <mutex> | |
#include <functional> | |
struct Object | |
{ | |
Object(int n) : n(n) {} | |
void init() { std::call_once(initialized, [this] { std::cout << "init with n=" << n << std::endl; }); } |
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 <mutex> | |
struct Object | |
{ | |
Object(int id) : id(id) | |
{ | |
std::cout << '[' << id << "] constructor" << std::endl; | |
} |
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 <thread> | |
#include <list> | |
struct Object | |
{ | |
void method(int n) {} | |
void operator()(int n) {} | |
}; |
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 <future> | |
#include <thread> | |
std::mutex mu; | |
template <typename T> | |
void print(std::string message, T data) | |
{ | |
std::lock_guard<std::mutex> lg(mu); |
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 <mutex> | |
struct Lock | |
{ | |
Lock(int id) : id(id) {} | |
void lock() { std::cout << "lock() from " << id << std::endl; } | |
bool try_lock() { std::cout << "try_lock() from " << id << std::endl; return true; } | |
void unlock() { std::cout << "unlock() from " << id << std::endl; } | |
int id; |
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> | |
int main(void) | |
{ | |
int a = 1001; | |
long double b = 3.1415926; | |
char c = 'A'; | |
std::string d = "I like C"; | |
std::cout << "a: " << a << std::endl; |
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> | |
struct Object | |
{ | |
Object(int n = 0) : n(n) | |
{ std::cout << '[' << n << ']' << " Object::Object()" << std::endl; } | |
~Object() | |
{ std::cout << '[' << n << ']' << " Object::~Object()" << std::endl; } |