Vcsn  2.4
Be Rational
to.hh
Go to the documentation of this file.
1 #pragma once
2 
3 #include <vcsn/misc/raise.hh>
4 
5 namespace vcsn
6 {
25  class to
26  {
27  public:
34  to(int min_, int max_)
35  : min{min_}
36  , max{max_}
37  {
38  if (max == -2)
39  max = min_;
40  if (min == -1)
41  min = 0;
42  require(0 <= min
43  && -1 <= max
44  && (max == -1 || min <= max),
45  "invalid exponents: ", min, ", ", max);
46  }
47 
48  to(int min_)
49  : to{min_, -2}
50  {}
51 
52  to(unsigned min_)
53  : to{int(min_)}
54  {}
55 
57  bool finite() const
58  {
59  return max != -1;
60  }
61 
63  bool single() const
64  {
65  return min == max;
66  }
67 
68  int min;
69  int max;
70  };
71 
72  inline std::ostream& operator<<(std::ostream& o, const to& t)
73  {
74  return o << '{' << t.min << ", " << t.max << '}';
75  }
76 }
to(unsigned min_)
Definition: to.hh:52
bool single() const
Whether features a single exponent.
Definition: to.hh:63
int max
Definition: to.hh:69
void require(Bool b, Args &&...args)
If b is not verified, raise an error with args as message.
Definition: raise.hh:91
std::ostream & operator<<(std::ostream &os, direction d)
Pretty-printing.
Definition: direction.cc:19
Definition: a-star.hh:8
to(int min_, int max_)
Build a exponent range.
Definition: to.hh:34
bool finite() const
Whether the max exponent is finte.
Definition: to.hh:57
to(int min_)
Definition: to.hh:48
int min
Definition: to.hh:68
An exponent, or range of exponents.
Definition: to.hh:25