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 A | |
{ | |
virtual void do_something() {} | |
virtual void do_something2() { std::cerr << "In A\n"; } | |
}; | |
struct B : public A | |
{ |
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
// Assume we need 32-byte alignment for AVX instructions | |
#define ALIGN 32 | |
void *aligned_malloc(int size) | |
{ | |
// We require whatever user asked for PLUS space for a pointer | |
// PLUS space to align pointer as per alignment requirement | |
void *mem = malloc(size + sizeof(void*) + (ALIGN - 1)); | |
// Location that we will return to user |
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
>>> isinstance(True, int) | |
True | |
>>> isinstance(True, float) | |
False | |
>>> isinstance(3, int) | |
True | |
>>> isinstance([1,2,3], list) | |
True | |
>>> isinstance("aa", str) | |
True |
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
>>> from collections import namedtuple | |
>>> d = {"name": "joe", "age": 20} | |
>>> d | |
{'age': 20, 'name': 'joe'} | |
>>> d_named = namedtuple("Employee", d.keys())(*d.values()) | |
>>> d_named | |
Employee(name='joe', age=20) | |
>>> d_named.name | |
'joe' |
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
// Example that shows difference between pointer-to-pointer | |
// and reference-to-pointer. | |
#include <cstdio> | |
void func_ptr(int **x) | |
{ | |
*x = new int; | |
**x = 100; | |
} |
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
// Example to show why base class destructor should be virtual. | |
// | |
// If ~A is not virtual below, you will notice that B's destructor | |
// is not called and B's Foo object is not freed. Memory leak! | |
// | |
// Change ~A to virtual and Foo is freed at end of scope correctly. | |
#include <iostream> | |
#include <memory> | |
using namespace std; |
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> | |
// Virtual method declarations | |
struct A | |
{ | |
virtual void Foo() const; | |
}; | |
struct B : public A |
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
# Doxyfile 1.8.6 | |
# This file describes the settings to be used by the documentation system | |
# doxygen (www.doxygen.org) for a project. | |
# | |
# All text after a double hash (##) is considered a comment and is placed in | |
# front of the TAG it is preceding. | |
# | |
# All text after a single hash (#) is considered a comment and will be ignored. | |
# The format is: |
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
# Comments and blank lines are allowed. | |
RCS | |
.+,v | |
CVS | |
\.\#.+ # CVS conflict files / emacs lock files | |
\.cvsignore | |
\.svn |
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 <stack> | |
#include <unordered_set> | |
#include <vector> | |
class Point | |
{ | |
public: | |
int x; | |
int y; |