From 7f3b2173d5e8ec80c043e20c02713a5e3c75ac16 Mon Sep 17 00:00:00 2001 From: Otto Date: Mon, 18 Oct 2021 09:24:25 +0200 Subject: [PATCH] Make addS() more versatile and use modern C++ (enable_if_t). Use new args pdnsutil to get primary vs primaries correct. --- pdns/misc.hh | 19 +++++++++++-------- pdns/pdnsutil.cc | 2 +- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/pdns/misc.hh b/pdns/misc.hh index 193074d8df..aad2340fb9 100644 --- a/pdns/misc.hh +++ b/pdns/misc.hh @@ -591,18 +591,21 @@ T valueOrEmpty(const P val) { // I'm not very OCD, but I appreciate loglines like "processing 1 delta", "processing 2 deltas" :-) -template -const char* addS(Integer siz, typename std::enable_if::value>::type*P=0) +template ::value, bool> = true> +const char* addS(Integer siz, const char* singular = "", const char *plural = "s") { - if(!siz || siz > 1) - return "s"; - else return ""; + if (siz == 1) { + return singular; + } + return plural; } -template -const char* addS(const C& c, typename std::enable_if::value>::type*P=0) +template ::value, bool> = true> +const char* addS(const C& c, const char* singular = "", const char *plural = "s") { - return addS(c.size()); + return addS(c.size(), singular, plural); } template diff --git a/pdns/pdnsutil.cc b/pdns/pdnsutil.cc index a92b19e861..8da10873ca 100644 --- a/pdns/pdnsutil.cc +++ b/pdns/pdnsutil.cc @@ -1844,7 +1844,7 @@ static bool showZone(DNSSECKeeper& dk, const DNSName& zone, bool exportDS = fals } } else if(di.kind == DomainInfo::Slave) { - cout << "Primary" << addS(di.masters) << ": "; + cout << "Primar" << addS(di.masters, "y", "ies") << ": "; for(const auto& m : di.masters) cout<