From ad2f823056b874cc992e45bfa07c2b652c0e2f0e Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Sat, 5 May 2018 02:12:48 -0700 Subject: [PATCH] ircd::m::room: Add head::has() existential test. --- include/ircd/m/room.h | 1 + ircd/m/room.cc | 15 +++++++++++++++ 2 files changed, 16 insertions(+) diff --git a/include/ircd/m/room.h b/include/ircd/m/room.h index 0a5277dbf..30286cc4c 100644 --- a/include/ircd/m/room.h +++ b/include/ircd/m/room.h @@ -360,6 +360,7 @@ struct ircd::m::room::head bool for_each(const closure_bool &) const; void for_each(const closure &) const; + bool has(const event::id &) const; size_t count() const; head(const m::room &room) diff --git a/ircd/m/room.cc b/ircd/m/room.cc index 95cfb7102..6ecc5d5f7 100644 --- a/ircd/m/room.cc +++ b/ircd/m/room.cc @@ -1510,6 +1510,21 @@ const return ret; } +bool +ircd::m::room::head::has(const event::id &event_id) +const +{ + bool ret{false}; + for_each(closure_bool{[&ret, &event_id] + (const event::idx &event_idx, const event::id &event_id_) + { + ret = event_id_ == event_id; + return !ret; // for_each protocol: false to break + }}); + + return ret; +} + void ircd::m::room::head::for_each(const closure &closure) const