Skip to content

Instantly share code, notes, and snippets.

View dschwen's full-sized avatar

Daniel Schwen dschwen

View GitHub Profile
@dschwen
dschwen / gist:6cb72490293433e2b958
Last active August 29, 2015 14:06
Y U no compile?!!
#include <iostream>
class C {
public:
class B;
class A {
public:
friend A operator+(const B & l, const B & r);
void hello() { std::cout << "hello!"; }
@dschwen
dschwen / gist:2e79eb8c2911b57de8fe
Created September 23, 2014 16:37
This compiles (double friend)
#include <iostream>
class C {
public:
class B;
class A {
public:
friend A operator+(const B & l, const B & r);
void hello() { std::cout << "hello!"; }
@dschwen
dschwen / gist:a6bf02c1d51c0c5cac79
Created September 23, 2014 19:27
A true power operator in C++
#include <iostream>
#include <cmath>
class Exponent;
class Number {
public:
Number(double v) : value(v) {}
double getVal() const { return value; }
#include <iostream>
// Get the hilbert index for a point along a 2D Hilbert curve.
// Daniel Schwen, 2014
//
// -------
// |01|10|
// -------
// |00|11|
// -------
### Keybase proof
I hereby claim:
* I am dschwen on github.
* I am dschwen (https://keybase.io/dschwen) on keybase.
* I have a public key whose fingerprint is 9071 892B E0EC FB07 D778 5ACB 4D73 4E12 9611 8FE0
To claim this, I am signing this object:
@dschwen
dschwen / gist:537915784f12bf8d7f67
Last active August 29, 2015 14:22
Copy constructor shenanigans
#include <iostream>
class Base {
public:
Base() {}
Base(const Base & a) {
std::cout << "In Base\n";
}
};
FirstName LastName Address1 Phone Zip Email
Dalton Skinner P.O. Box 374, 9689 Magna. Road (458) 555-0362 84125 id@Sed.org
Kirk Kidd Ap #692-3484 Phasellus Road (697) 555-6989 65844 vitae@convallisincursus.edu
Cleo Riddle P.O. Box 841, 4429 Aliquam St. (690) 555-6058 59233 arcu@nisi.org
Olga Navarro Ap #809-3508 Libero. Road (870) 555-9331 39969 rutrum.non.hendrerit@tinciduntDonec.ca
Olivia Snider P.O. Box 475, 4800 Tortor Av. (644) 555-3957 50733 sem.elit.pharetra@gravida.edu
Mira George 7043 Ligula. Av. (496) 555-6952 62383 nisi.nibh@magnaetipsum.com
Andrew Landry Ap #392-2775 Ornare Avenue (668) 555-1476 53839 Aliquam@ullamcorpernisl.edu
Colton Meyer Ap #439-2430 Nec, Street (166) 555-6210 36615 neque@inlobortis.com
Shellie Buck Ap #676-8128 Pharetra. Street (142) 555-1728 76648 dapibus@et.co.uk

Introduction

[\int_0^1 x_i]

#include <iostream>
#include <iomanip>
#include <sstream>
#include <string>
#include <cstdlib>
#include <cmath>
typedef double Real;
int main()
#include <iostream>
#include <vector>
template <typename T>
class ref_wrapper
{
public:
ref_wrapper() = delete;
ref_wrapper(T & obj) { ptr = &obj; }
ref_wrapper(const ref_wrapper<T> & ref) { ptr = ref.ptr; }