2000-03-09 03:36:48 +00:00
|
|
|
// -*- C++ -*-
|
2002-05-30 02:24:33 +00:00
|
|
|
/**
|
|
|
|
* \file lyxalgo.h
|
2002-09-25 10:03:41 +00:00
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
* Licence details can be found in the file COPYING.
|
2002-05-30 02:24:33 +00:00
|
|
|
*
|
2008-11-14 15:58:50 +00:00
|
|
|
* \author Lars Gullik Bjønnes
|
2002-09-25 10:03:41 +00:00
|
|
|
*
|
2003-08-23 00:17:00 +00:00
|
|
|
* Full author contact details are available in file CREDITS.
|
2002-05-30 02:24:33 +00:00
|
|
|
*
|
2002-09-25 10:03:41 +00:00
|
|
|
* A variety of useful templates.
|
2002-05-30 02:24:33 +00:00
|
|
|
*/
|
|
|
|
|
2000-03-09 03:36:48 +00:00
|
|
|
#ifndef LYX_ALGO_H
|
|
|
|
#define LYX_ALGO_H
|
|
|
|
|
2001-04-17 14:22:53 +00:00
|
|
|
namespace lyx {
|
|
|
|
|
2000-03-09 03:36:48 +00:00
|
|
|
|
|
|
|
/// Returns true if the sequence first,last is sorted, false if not.
|
|
|
|
template <class For>
|
|
|
|
bool sorted(For first, For last)
|
|
|
|
{
|
|
|
|
if (first == last) return true;
|
|
|
|
For tmp = first;
|
|
|
|
while (++tmp != last) {
|
2000-03-09 23:58:55 +00:00
|
|
|
if (*tmp < *first++) return false;
|
2000-03-09 03:36:48 +00:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2001-04-17 14:22:53 +00:00
|
|
|
|
2000-03-09 03:36:48 +00:00
|
|
|
/// Cmp is the same Cmp as you would pass to std::sort.
|
|
|
|
template <class For, class Cmp>
|
|
|
|
bool sorted(For first, For last, Cmp cmp)
|
|
|
|
{
|
|
|
|
if (first == last) return true;
|
|
|
|
For tmp = first;
|
|
|
|
while (++tmp != last) {
|
|
|
|
if (cmp(*tmp, *first++)) return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2001-04-17 14:22:53 +00:00
|
|
|
|
2002-01-14 13:04:06 +00:00
|
|
|
} // namespace lyx
|
|
|
|
|
2002-05-30 02:24:33 +00:00
|
|
|
#endif // LYX_ALGO_H
|