Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Define XBT_ATTRIB_DEPRECATED_v326.
[simgrid.git] / include / xbt / range.hpp
1 /* Copyright (c) 2016-2019. The SimGrid Team.
2  * All rights reserved.                                                     */
3
4 /* This program is free software; you can redistribute it and/or modify it
5  * under the terms of the license (GNU LGPL) which comes with this package. */
6
7 #ifndef SIMGRID_XBT_RANGE_HPP
8 #define SIMGRID_XBT_RANGE_HPP
9
10 namespace simgrid {
11 namespace xbt {
12
13 /** Describes a contiguous inclusive-exclusive [a,b) range of values */
14 template<class T> class Range {
15   T begin_;
16   T end_;
17 public:
18   Range()               : begin_(), end_() {}
19   Range(T begin, T end) : begin_(std::move(begin)), end_(std::move(end)) {}
20   explicit Range(T value) : begin_(value), end_(value + 1) {}
21   T& begin()             { return begin_; }
22   T& end()               { return end_; }
23   const T& begin() const { return begin_; }
24   const T& end() const   { return end_; }
25   bool empty() const     { return begin_ >= end_; }
26   bool contain(T const& x) const { return begin_ <= x && end_ > x; }
27 };
28
29 }
30 }
31
32 #endif