From 0b0baf34467e82293c33ed04e966155e3bcc544f Mon Sep 17 00:00:00 2001 From: gatecat Date: Mon, 27 Sep 2021 19:18:22 +0100 Subject: [PATCH] idstring: Add 'in' function Signed-off-by: gatecat --- common/idstring.h | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/common/idstring.h b/common/idstring.h index 28f5456d..019e0a2a 100644 --- a/common/idstring.h +++ b/common/idstring.h @@ -58,6 +58,16 @@ struct IdString bool empty() const { return index == 0; } unsigned int hash() const { return index; } + + template bool in(Args... args) const + { + // Credit: https://articles.emptycrate.com/2016/05/14/folds_in_cpp11_ish.html + bool result = false; + (void)std::initializer_list{(result = result || in(args), 0)...}; + return result; + } + + bool in(const IdString &rhs) const { return *this == rhs; } }; NEXTPNR_NAMESPACE_END