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 <string> | |
#include <iostream> | |
#include <typeinfo> | |
template <typename T> | |
void f(T t) | |
{ | |
std::cout << typeid(t).name() << ":" << t << 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 <typeinfo> | |
#define PRINT_EXPR(T) do { std::cout << "parameter: " << #T << "\t\t\t\ttype: " << typeid(T).name() << std::endl; } while(false); | |
#define PRINT_TYPE(T) do { T val; std::cout << "parameter: " << #T << "\t\t\t\ttype: " << typeid(val).name() << std::endl; } while(false); | |
template <typename T> | |
void print(T t) | |
{ | |
std::cout << "type: " << typeid(T).name() << " value: " << t << 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> | |
int main() | |
{ | |
int cond = 1; | |
if (int var = cond) | |
{ | |
std::cout << "if: var=" << var << "\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> | |
class Base | |
{ | |
public: | |
virtual void action() { std::cout << "Base::action()\n"; } | |
}; | |
class Derived : public Base | |
{ |
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; } |
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> | |
#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> | |
#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 <thread> | |
#include <list> | |
struct Object | |
{ | |
void method(int n) {} | |
void operator()(int n) {} | |
}; |
OlderNewer