Listing 3: The alternative class
//  Copyright (c) 2001, Joel de Guzman and Dan Nuffer
//  Permission is granted to use this code without restriction as
//  long as this copyright notice appears in all source files.

template <typename A, typename B>
struct alternative
    : public binary<A, B>
    , public parser<alternative<A, B> >
{
    alternative(A const& a, B const& b)
    : binary<A, B>(a, b) {}

    template <typename IteratorT>
    match
    parse(IteratorT& first,  IteratorT const& last) const
    {
        if (match hit = this->left().parse(first, last))
            return hit;
        return this->right().parse(first, last);
    }
};