Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
[project-description] Fix extraction of the ns-3 version.
[simgrid.git] / include / xbt / range.hpp
1 /* Copyright (c) 2016-2022. 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 #include <algorithm>
11
12 namespace simgrid {
13 namespace xbt {
14
15 /** Describes a contiguous inclusive-exclusive [a,b) range of values */
16 template<class T> class Range {
17   T begin_;
18   T end_;
19 public:
20   Range()               : begin_(), end_() {}
21   Range(T begin, T end) : begin_(std::move(begin)), end_(std::move(end)) {}
22   explicit Range(T value) : begin_(value), end_(value + 1) {}
23   T& begin()             { return begin_; }
24   T& end()               { return end_; }
25   const T& begin() const { return begin_; }
26   const T& end() const   { return end_; }
27   bool empty() const     { return begin_ >= end_; }
28   bool contain(T const& x) const { return begin_ <= x && end_ > x; }
29 };
30
31 }
32 }
33
34 #endif