Skip to content

Instantly share code, notes, and snippets.

View peteb's full-sized avatar

Peter Backman peteb

View GitHub Profile
@peteb
peteb / gist:964164
Created May 10, 2011 09:28
C++ templates for vector classes (vec3, color4, float2, etc)
#include <iostream>
#include <ctime>
#include <iterator>
// old stuff
template<typename DataType, int NumComponents, typename Derived>
struct composite_base {
typedef DataType value_type;
static const int num_components = NumComponents;
@peteb
peteb / ostream_cast_iterator.cpp
Created November 16, 2010 13:00
An iterator that casts the input data to another type. Note: std::transform should probably be used in most cases
#include <iostream>
#include <map>
#include <sstream>
#include <string>
#include <iterator>
template <class T, class C, class charT=char, class traits=std::char_traits<charT> >
class ostream_cast_iterator :
public std::iterator<std::output_iterator_tag, void, void, void, void>
{
@peteb
peteb / filter.cpp
Created November 9, 2010 16:03
Implements a simple filter function in C++
#include <vector>
#include <iostream>
#include <functional>
#include <iterator>
template <class Functor>
class Not
{
public:
Not(Functor & f) : func(f) {}