Listing 4: Definition of class Gear.

template <class C, class T, class B>
class Gear : public Integrator<C,T>
{
    private:
        bool (*approx_equal)(const C&, const C&);
        const unsigned int order, maxiter;
        unsigned int curr_order;
        std::deque<C> past_state;
        C xnext, xtemp, dxdt;

        // Gear formulas
        typedef void (Gear<C,T,B>::*xnext_functions)(void);
        xnext_functions calc_xnext[4];
        void Gear1xnext(void);
        void Gear2xnext(void);
        void Gear3xnext(void);
        void Gear4xnext(void);

    public:
        Gear(const unsigned int, const C &, const T, const T,
             const unsigned int,
             void (*)(const C&, const T, C&),
             bool (*)(const C&, const C&));
        void step(void);
        void set_step_size(T);
};

template <class C, class T, class B>
Gear<C,T,B>::Gear(const unsigned int Gear_order, const C &x0,
                  const T t0, const T h_init, 
                  const unsigned int maxiterations,
                  void (*dxdt_calc)(const C&, const T, C&),
                  bool (*almost)(const C&, const C&))
    :Integrator<C,T>(x0, t0, h_init, dxdt_calc),
     order(Gear_order), maxiter(maxiterations), xnext(x0),
     xtemp(x0), dxdt(x0)
{
    approx_equal = almost;
    curr_order = 1;
    calc_xnext[0] = &Gear<C,T,B>::Gear1xnext;
    calc_xnext[1] = &Gear<C,T,B>::Gear2xnext;
    calc_xnext[2] = &Gear<C,T,B>::Gear3xnext;
    calc_xnext[3] = &Gear<C,T,B>::Gear4xnext;
}