Skip to content

Instantly share code, notes, and snippets.

View odeblic's full-sized avatar

Olivier de BLIC odeblic

View GitHub Profile
@odeblic
odeblic / access.cpp
Last active July 27, 2017 11:31
Legal member access violation with polymorphism
#include <iostream>
class Base
{
public:
virtual void action() { std::cout << "Base::action()\n"; }
};
class Derived : public Base
{
@odeblic
odeblic / if_scope.cpp
Last active July 27, 2017 11:32
Scope of variable within an if statement
#include <iostream>
int main()
{
int cond = 1;
if (int var = cond)
{
std::cout << "if: var=" << var << "\n";
}
@odeblic
odeblic / types.cpp
Last active July 27, 2017 11:34
Study of primitive built-in types
#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;
@odeblic
odeblic / variadic_templates.cpp
Last active July 27, 2017 11:25
Simple example using variadic templates
#include <string>
#include <iostream>
#include <typeinfo>
template <typename T>
void f(T t)
{
std::cout << typeid(t).name() << ":" << t << std::endl;
}
@odeblic
odeblic / shared_mutex.cpp
Last active July 27, 2017 11:34
Shared mutex discovery
#include <mutex>
#include <shared_mutex>
#include <iostream>
template <typename M>
void test(M& mutex)
{
bool exclusive = false;
bool shared = false;