Skip to content

Instantly share code, notes, and snippets.

#include <iostream>
template<class T>
struct BX
{
T t;
};
template<class T>
struct B {
@aruslan
aruslan / gist:1648002
Created January 20, 2012 15:58
Code I see almost everywhere -- is it from somewhere in 3DSMAX SDK?
Modifier* FindPhysiqueModifier(AXNode* nodePtr)
{
// Get object from node. Abort if no object.
Object* ObjectPtr =((INode*)nodePtr)->GetObjectRef();
//DebugBox("* Find Physiqye Modifier");
if (!ObjectPtr) return NULL;
// Is derived object ?
// Вырезка из набора простых boundary test cases парсера C++ комментариев
// 2003-2005 (ц) Руслан "aruslan" Абдикеев
// Константы
std::cout << "C1. This is /* not a comment */\n";
std::cout << "C2. This is // not a comment\n";
std::cout << "C3. This is \" /* not a comment as well*/ \"\n";
std::cout << "C4. This is \" // not a comment as well \"\n";
std::cout << "C5. Let's print some random numbers: " << '/*' << '*/' << '\n';
std::cout << "C6. Let's print a random number: " << '//' << '\n';
@aruslan
aruslan / gist:1760882
Created February 7, 2012 17:34
Demonstration of the "Abdikeev's binary search padding effect"
// Demonstration of the "Abdikeev's binary search padding effect":
// increasing the binary search performance by +30%
#include <algorithm>
#include <vector>
#include <iostream>
#include <assert.h>
#include <stdlib.h>
#include <time.h>
template<typename T>
@aruslan
aruslan / bs-padded.cpp
Created February 7, 2012 21:53
Binary search with padding, or how to get +30% in performance
// Demonstration of the "Abdikeev's binary search padding effect":
// increasing the binary search performance by +30%
#include <algorithm>
#include <vector>
#include <iostream>
#include <cassert>
#include <cstdlib>
#include <ctime>
@aruslan
aruslan / gist:1777049
Created February 9, 2012 03:32
MSVC template-as-text-substitution round 4...
#include <stdio.h> // Any parser should survive the standard i/o
struct t0 { typedef int a; };
struct t1 : virtual t0
{
static const int a = 42;
int result(int b) const { return (a)-(b); }
};
struct t2 : virtual t0
{
-- | The 'permutations' function returns the list of all permutations of the argument.
--
-- > permutations "abc" == ["abc","bac","cba","bca","cab","acb"]
permutations :: [a] -> [[a]]
permutations xs0 = xs0 : perms xs0 []
where
perms [] _ = []
perms (t:ts) is = foldr interleave (perms ts (t:is)) (permutations is)
where interleave xs r = let (_,zs) = interleave' id xs r in zs
interleave' _ [] r = (ts, r)
/* Function to print permutations of string
This function takes three parameters:
1. String
2. Starting index of the string
3. Ending index of the string. */
void permute(char *a, int i, int n)
{
int j;
if (i == n)
printf("%s\n", a);
@aruslan
aruslan / gist:1792938
Created February 10, 2012 21:15
Generate all unique permutations?
#include <vector>
#include <algorithm>
#include <iostream>
#include <ostream>
#include <iterator>
template<typename T>
void print(const std::vector<T>& v)
{
std::copy(v.begin(), v.end(), std::ostream_iterator<T>(std::cout));
@aruslan
aruslan / gist:1820939
Created February 13, 2012 22:17
Explicit constructors all over the place
struct foo
{
explicit foo(int a) {}
explicit foo(const foo&) {}
};
int main()
{
foo a(42);
foo b = a; // breaks because the copy constructor is explicit