/**************************************************************************
 *
 * equal.cpp - Example program for comparing two ranges for equivalence.
 *
 * $Id: equal.cpp 550991 2007-06-26 23:58:07Z sebor $
 *
 ***************************************************************************
 *
 * Licensed to the Apache Software  Foundation (ASF) under one or more
 * contributor  license agreements.  See  the NOTICE  file distributed
 * with  this  work  for  additional information  regarding  copyright
 * ownership.   The ASF  licenses this  file to  you under  the Apache
 * License, Version  2.0 (the  "License"); you may  not use  this file
 * except in  compliance with the License.   You may obtain  a copy of
 * the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the  License is distributed on an  "AS IS" BASIS,
 * WITHOUT  WARRANTIES OR CONDITIONS  OF ANY  KIND, either  express or
 * implied.   See  the License  for  the  specific language  governing
 * permissions and limitations under the License.
 *
 * Copyright 1994-2006 Rogue Wave Software.
 * 
 **************************************************************************/

#include <algorithm>    // for equal
#include <functional>   // for equal_to
#include <ios>          // for boolalpha
#include <iostream>     // for cout, endl
#include <iterator>     // for ostream_iterator
#include <vector>       // for vector

#include <examples.h>


int main ()
{
    // Typedef for convenience.
    typedef std::vector<int, std::allocator<int> > Vector;

    typedef std::ostream_iterator <Vector::value_type,
                                   char,
                                   std::char_traits<char> > os_iter;

    const Vector::value_type a1[] = { 1, 2, 3, 4 };
    const Vector::value_type a2[] = { 1, 2, 4, 3 };

    // Set up two vectors.
    const Vector v1 (a1, a1 + sizeof a1 / sizeof *a1);
    const Vector v2 (a2, a2 + sizeof a2 / sizeof *a2);

    // Check for equality.
    bool same = std::equal (v1.begin (), v1.end (), v2.begin ());

    same = same && std::equal (v1.begin (), v1.end (), v2.begin (), 
                               std::equal_to<Vector::value_type>());

    // Output the sequences.
    std::cout << "{ ";
    std::copy (v1.begin (), v1.end (), os_iter (std::cout, " "));

    std::cout << "} == { ";
    std::copy (v2.begin (), v2.end (), os_iter (std::cout, " "));

    // Output the result.
    std::cout << "} --> " << std::boolalpha << same << std::endl;

    return 0;
}
