Vcsn  2.0
Be Rational
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
raise.hh
Go to the documentation of this file.
1 #ifndef VCSN_MISC_RAISE_HH
2 # define VCSN_MISC_RAISE_HH
3 
4 # include <stdexcept>
5 # include <sstream>
6 # include <utility>
7 
8 # include <vcsn/misc/attributes.hh>
9 
10 namespace vcsn
11 {
12  namespace detail
13  {
17  struct pass
18  {
19  template<typename ...T> pass(T...) {}
20  };
21  }
22 
24  template <typename... Args>
25  ATTRIBUTE_NORETURN
26  inline void raise(Args&&... args)
27  {
28  std::ostringstream o;
29  using swallow = int[];
30  (void) swallow
31  {
32  (o << args, 0)...
33  };
34  throw std::runtime_error{o.str()};
35  }
36 
38  template <typename... Args>
39  inline void require(bool b, Args&&... args)
40  {
41  if (!b)
42  raise(std::forward<Args>(args)...);
43  }
44 };
45 
46 #endif // !VCSN_MISC_RAISE_HH
Ignore its arguments.
Definition: raise.hh:17
Provide a variadic mul on top of a binary mul(), and one().
Definition: fwd.hh:36
void require(bool b, Args &&...args)
If b is not verified, raise an error with args as message.
Definition: raise.hh:39