source: trunk/test/iterator_test.cc @ 881

Last change on this file since 881 was 881, checked in by Peter, 16 years ago

merged constIterator into Iterator and added an extra template parameter. There are problems with conversion from iterator to const_iterator

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 2.0 KB
Line 
1// $Id: iterator_test.cc 881 2007-09-22 20:22:36Z peter $
2
3/*
4  Copyright (C) 2007 Peter Johansson
5
6  This file is part of the yat library, http://trac.thep.lu.se/trac/yat
7
8  The yat library is free software; you can redistribute it and/or
9  modify it under the terms of the GNU General Public License as
10  published by the Free Software Foundation; either version 2 of the
11  License, or (at your option) any later version.
12
13  The yat library is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  General Public License for more details.
17
18  You should have received a copy of the GNU General Public License
19  along with this program; if not, write to the Free Software
20  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
21  02111-1307, USA.
22*/
23
24#include "yat/classifier/DataLookup1D.h"
25
26#include "yat/utility/constIterator.h"
27#include "yat/utility/Iterator.h"
28#include "yat/utility/vector.h"
29
30#include <algorithm>
31#include <fstream>
32
33using namespace theplu::yat;
34
35int main(const int argc,const char* argv[])
36{ 
37  std::ostream* message;
38  if (argc>1 && argv[1]==std::string("-v"))
39    message = &std::cerr;
40  else {
41    message = new std::ofstream("/dev/null");
42    if (argc>1)
43      std::cout << "iterator_test -v : for printing extra "  << "information\n";
44  }
45  *message << "testing iterator" << std::endl;
46  bool ok = true;
47
48  utility::vector vec(12);
49  classifier::DataLookup1D lookup(vec);
50  utility::vector::iterator begin=vec.begin();
51  // test iterator to const_iterator conversion
52  utility::vector::const_iterator ci = vec.begin();
53  ci = begin;
54  //if (begin!=ci)
55  //ok = false;
56
57  utility::vector::iterator end=vec.end();
58  std::sort(begin, end);
59  classifier::DataLookup1D::const_iterator lbegin=lookup.begin();
60  classifier::DataLookup1D::const_iterator lend=lookup.end();
61 
62  std::copy(lbegin, lend, begin);
63  std::copy(begin, end, begin);
64  std::sort(begin, end);
65
66  if (!ok)
67    *message << "iterator test failed" << std::endl;
68
69  return (ok ? 0 : -1);
70}
Note: See TracBrowser for help on using the repository browser.