source: src/Helpers/Range.hpp@ 9c643e

Last change on this file since 9c643e was 9c643e, checked in by Frederik Heber <heber@…>, 14 years ago

FIX: Range was missing iosfwd inclusion after operator<< added.

  • Property mode set to 100644
File size: 1.7 KB
RevLine 
[a80f419]1/*
2 * Range.hpp
3 *
4 * Created on: Jul 22, 2010
5 * Author: crueger
6 */
7
8#ifndef RANGE_HPP_
9#define RANGE_HPP_
[70672e3]10
11// include config.h
12#ifdef HAVE_CONFIG_H
13#include <config.h>
14#endif
15
[9c643e]16#include <iosfwd>
17
[a80f419]18template <class T>
19struct range {
20 range(const T&,const T&);
21 bool isInRange(const T&) const;
22 bool isBefore(const T&) const;
23 bool isBeyond(const T&) const;
24
25 T first;
26 T last;
27};
28
29template <class T>
30inline range<T>::range(const T &_first,const T &_last) :
31first(_first),last(_last)
32{}
33
34template <class T>
35inline bool range<T>::isInRange(const T &value) const{
36 return first <= value && value < last;
37}
38
39template <class T>
40inline bool range<T>::isBefore(const T &value) const{
41 return value < first;
42}
43
44template <class T>
45inline bool range<T>::isBeyond(const T &value) const{
46 return last <= value;
47}
48
49template <class T>
50inline range<T> makeRange(const T&first, const T&last){
51 return range<T>(first,last);
52}
53
54template <class T>
55inline bool operator<(const range <T> &x, const range<T> &y){
56 return (x.first!=y.first)?x.first<y.first:x.last<y.last;
57}
58
59template <class T>
60inline bool operator==(const range<T> &x,const range<T> &y){
61 return x.first==y.first && x.last==y.last;
62}
63
64template <class T>
65inline bool operator!= (const range<T>& x, const range<T>& y) { return !(x==y); }
66template <class T>
67inline bool operator> (const range<T>& x, const range<T>& y) { return y<x; }
68template <class T>
69inline bool operator<=(const range<T>& x, const range<T>& y) { return !(y<x); }
70template <class T>
71inline bool operator>= (const range<T>& x, const range<T>& y) { return !(x<y); }
[6b898c]72template <class T>
73std::ostream &operator<< (std::ostream &ost, const range<T>& y)
74{
75 ost << "[" << y.first << ";" << y.last << "]";
76 return ost;
77}
[a80f419]78
79#endif /* RANGE_HPP_ */
Note: See TracBrowser for help on using the repository browser.