Awali
Another Weighted Automata library
raise.hh
Go to the documentation of this file.
1 // This file is part of Awali.
2 // Copyright 2016-2022 Sylvain Lombardy, Victor Marsault, Jacques Sakarovitch
3 //
4 // Awali is a free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
13 //
14 // You should have received a copy of the GNU General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
16 
17 #ifndef AWALI_MISC_RAISE_HH
18 # define AWALI_MISC_RAISE_HH
19 
20 # include <stdexcept>
21 # include <sstream>
22 # include <utility>
23 
25 
26 namespace awali { namespace sttc {
27 
28  namespace internal
29  {
33  struct pass
34  {
35  template<typename ...T> pass(T...) {}
36  };
37  }
38 
40  template <typename... Args>
41  ATTRIBUTE_NORETURN
42  inline void raise(Args&&... args)
43  {
44  std::ostringstream o;
45  using swallow = int[];
46  (void) swallow
47  {
48  (o << args, 0)...
49  };
50  throw std::runtime_error{o.str()};
51  }
52 
54  template <typename... Args>
55  inline void require(bool b, Args&&... args)
56  {
57  if (!b)
58  raise(std::forward<Args>(args)...);
59  }
60 
61 
62 }}//end of ns awali::stc
63 
64 #endif // !AWALI_MISC_RAISE_HH
The Boolean semring.
Definition: b.hh:38
void require(bool b, Args &&... args)
If b is not verified, raise an error with args as message.
Definition: raise.hh:55
Main namespace of Awali.
Definition: ato.hh:22
Ignore its arguments.
Definition: raise.hh:34
pass(T...)
Definition: raise.hh:35