OGLplus  (0.59.0) a C++ wrapper for rendering APIs

one_of.hpp
Go to the documentation of this file.
1 
9 #ifndef EAGINE_VALID_IF_ONE_OF_HPP
10 #define EAGINE_VALID_IF_ONE_OF_HPP
11 
12 #include "decl.hpp"
13 
14 namespace eagine {
15 
16 // one of
17 template <typename T, T... C>
18 struct valid_if_one_of_policy {
19  auto operator()(const T& value) const noexcept {
20  const T choices[] = {C...};
21  for(const T& choice : choices) {
22  if(value == choice) {
23  return true;
24  }
25  }
26  return false;
27  }
28 
29  struct do_log {
30  template <typename X, typename = disable_if_same_t<X, do_log>>
31  constexpr do_log(X&&) noexcept {}
32 
33  template <typename Log>
34  void operator()(Log& log, const T& v) const {
35  log << "Value " << v << ", "
36  << "other than one of the values [";
37 
38  const T choices[] = {C...};
39  bool first = true;
40  for(const T& choice : choices) {
41  log << (first ? "" : ", ") << choice;
42  first = false;
43  }
44  log << "] is invalid";
45  }
46  };
47 };
48 
49 template <typename T, T... C>
50 using valid_if_one_of = valid_if<T, valid_if_one_of_policy<T, C...>>;
51 
52 } // namespace eagine
53 
54 #endif // EAGINE_VALID_IF_ONE_OF_HPP
Common code is placed in this namespace.
Definition: eagine.hpp:21

Copyright © 2015-2021 Matúš Chochlík.
<chochlik -at -gmail.com>
Documentation generated on Tue Apr 13 2021 by Doxygen (version 1.8.17).