Skip to content

Instantly share code, notes, and snippets.

View mumreg's full-sized avatar

mumreg mumreg

View GitHub Profile
@mumreg
mumreg / tuple_to_strings.cpp
Last active April 20, 2016 21:20
Strings formating approach
#include <iostream>
#include <cstddef>
#include <tuple>
#include <utility>
#include <sstream>
#include <vector>
template <typename Tuple, typename F, std::size_t ...Indices>
void for_each_impl(Tuple&& tuple, F&& f, std::index_sequence<Indices...>) {
using swallow = int[];
@mumreg
mumreg / visitor_first.cpp
Last active April 21, 2016 16:52
First approach of template visitor
#include <iostream>
class BaseVisitor
{
public:
virtual ~BaseVisitor() {}
};
template <class T, typename R = void>
class Visitor {
@mumreg
mumreg / visitor_second.cpp
Last active April 21, 2016 13:57
Second approach of visitor template
#include <iostream>
class Derived0;
class Derived1;
template <typename R, typename ...Args>
class IVisitor
{
public:
virtual R visit(Derived0*, Args...) = 0;
@mumreg
mumreg / test3dscene.cpp
Created May 16, 2016 10:26
Little snippet of how to create sandwich scene with 2D-3D-2D layers in cocos2d-x
#include "Test3dScene.h"
#include "2d/CCActionInterval.h"
#include "2d/CCCamera.h"
#include "2d/CCSprite.h"
#include "3d/CCAnimate3D.h"
#include "3d/CCAnimation3D.h"
#include "3d/CCSprite3D.h"
#include "base/CCDirector.h"
#include "base/ccTypes.h"
#include "math/CCGeometry.h"
@mumreg
mumreg / ptr_fun2.cpp
Last active August 19, 2016 12:23
Fun with pointers #2
#include <iostream>
int main(int argc, const char * argv[]) {
int *a = nullptr;
int b = 10;
auto foo = [&b](int *&a) { a = &b; };
foo(a);
std::cout << *a << std::endl;
return 0;
}
#include <iostream>
class A {
public:
A(int i) : a(i) {}
int a;
int& GetA() { return a; }
};
int main(int argc, const char * argv[]) {
#include <iostream>
int main(int argc, const char * argv[]) {
int n = 0;
std::cout << "Enter n:";
std::cin >> n;
int n1 = 0, n2 = 1, sum = 1;
while (sum < n)
{