Skip to content

Instantly share code, notes, and snippets.

@stevenRush
Created February 24, 2014 08:11
Show Gist options
  • Save stevenRush/9183712 to your computer and use it in GitHub Desktop.
Save stevenRush/9183712 to your computer and use it in GitHub Desktop.
Simple strategy pattern example with templates
template<class ADVANCE_STRATEGY>
class base_iterator : ADVANCE_STRATEGY
{
private:
int * pointer;
public:
base_iterator & operator++()
{
advance(pointer);
}
};
class straight_strategy
{
void advance(int *& pointer)
{
++pointer;
}
};
class reverse_strategy
{
void advance(int *& pointer)
{
--pointer;
}
};
typedef base_iterator<straight_strategy> iterator;
typedef base_iterator<reverse_strategy> reverse_iterator;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment