MCPcopy Create free account
hub / github.com/davisking/dlib / call_if_valid

Function call_if_valid

dlib/metaprogramming.h:65–81  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

63
64 template <typename Funct, typename... Args>
65 bool call_if_valid(Funct&& f, Args&&... args)
66 /*!
67 ensures
68 - if f(std::forward<Args>(args)...) is a valid expression then we evaluate it and return
69 true. Otherwise we do nothing and return false.
70 !*/
71 {
72 return switch_(bools(is_invocable<Funct, Args...>{}),
73 [&](true_t, auto _) {
74 _(std::forward<Funct>(f))(std::forward<Args>(args)...);
75 return true;
76 },
77 [](auto...) {
78 return false;
79 }
80 );
81 }
82
83// ----------------------------------------------------------------------------------------
84

Callers 7

test_call_if_validFunction · 0.85
visitMethod · 0.85
visitMethod · 0.85
visitMethod · 0.85
do_visitMethod · 0.85
operator()Method · 0.85
do_visitMethod · 0.85

Calls 3

switch_Function · 0.85
_Function · 0.85
boolsFunction · 0.70

Tested by 1

test_call_if_validFunction · 0.68