Vcsn  2.3
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 {
16 
26  class to
27  {
28  public:
35  to(int min_, int max_)
36  : min{min_}
37  , max{max_}
38  {
39  if (max == -2)
40  max = min_;
41  if (min == -1)
42  min = 0;
43  require(0 <= min
44  && -1 <= max
45  && (max == -1 || min <= max),
46  "invalid exponents: ", min, ", ", max);
47  }
48 
49  to(int min_)
50  : to{min_, -2}
51  {}
52 
53  to(unsigned min_)
54  : to{int(min_)}
55  {}
56 
58  bool finite() const
59  {
60  return max != -1;
61  }
62 
64  bool single() const
65  {
66  return min == max;
67  }
68 
69  int min;
70  int max;
71  };
72 
73  inline std::ostream& operator<<(std::ostream& o, const to& t)
74  {
75  return o << '{' << t.min << ", " << t.max << '}';
76  }
77 }
to(int min_)
Definition: to.hh:49
int max
Definition: to.hh:70
to(unsigned min_)
Definition: to.hh:53
to(int min_, int max_)
Build a exponent range.
Definition: to.hh:35
std::ostream & operator<<(std::ostream &os, direction d)
Pretty-printing.
Definition: direction.cc:19
bool finite() const
Whether the max exponent is finte.
Definition: to.hh:58
void require(Bool b, Args &&...args)
If b is not verified, raise an error with args as message.
Definition: raise.hh:91
Definition: a-star.hh:8
int min
Definition: to.hh:69
An exponent, or range of exponents.
Definition: to.hh:26
bool single() const
Whether features a single exponent.
Definition: to.hh:64