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

in_list.hpp
Go to the documentation of this file.
1 
9 #ifndef EAGINE_VALID_IF_IN_LIST_HPP
10 #define EAGINE_VALID_IF_IN_LIST_HPP
11 
12 #include "decl.hpp"
13 
14 namespace eagine {
15 
18 template <typename T, typename Range>
20  Range _choices = {};
21 
22  valid_if_in_list_policy(const Range& choices)
23  : _choices(choices) {}
24 
26  auto operator()(const T& value) const noexcept -> bool {
27  for(const T& choice : _choices) {
28  if(are_equal(value, choice)) {
29  return true;
30  }
31  }
32  return false;
33  }
34 
35  struct do_log {
36  Range _choices;
37 
38  inline do_log(const valid_if_in_list_policy<T, Range>& p) noexcept
39  : _choices(p._choices) {}
40 
41  template <typename Log>
42  void operator()(Log& log, const T& v) const {
43  log << "Value '" << v << "', "
44  << "other than one of the values [";
45 
46  bool first = true;
47  for(const T& choice : _choices) {
48  log << (first ? "" : ", ") << "'" << choice << "'";
49  first = false;
50  }
51  log << "] is invalid";
52  }
53  };
54 };
55 
58 template <typename T, typename Range>
60 
61 } // namespace eagine
62 
63 #endif // EAGINE_VALID_IF_IN_LIST_HPP
Common code is placed in this namespace.
Definition: eagine.hpp:21
Primary template for conditionally valid values.
Definition: decl.hpp:49
auto operator()(const T &value) const noexcept -> bool
Indicates value validity, true if value is one of the specified choices.
Definition: in_list.hpp:26
Policy for values valid if contained in object of Range type.
Definition: in_list.hpp:19

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