Function Moar with C++23 – MUC++ 2023 © Björn Fahller @
[email protected] 125/208
Network interfaces
class ipif
{
public:
using state_type = enum { off, on };
void set_state(state_type);
state_type state() const { return state_; }
ip_address address() const { return addr_; }
netmask mask() const { return mask_; }
ip_address gateway() const { return gw_; }
private:
ip_address addr_;
netmask mask_;
ip_address gw_;
state_type state_;
};
auto compose = [](F1&& f1, F2&& f2) {
return [f1 = std::forward(f1), f2 = std::forward(f2)]
(Ts&& ... ts) -> decltype(auto) {
return f1(f2(std::forward(ts)...));
};
};
auto with_address = [](auto addr, netmask mask = {255,255,255,255}) {
return compose(ip_matches(addr, mask), get_address);
};
auto it = std::ranges::find_if(interfaces,
compose(ip_matches({192,168,0,1},
get_address)));
with_address({192,168,0,1}));
But what if I want to
search with more
than one criteria, e.g.
address and state?