From 96a37da03d820e66c0378c336fe02a513bec224f Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Wed, 29 May 2019 22:34:39 +0200 Subject: [PATCH] config/Block: add method With() --- src/config/Block.hxx | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/config/Block.hxx b/src/config/Block.hxx index 0a038c838..b052bb7eb 100644 --- a/src/config/Block.hxx +++ b/src/config/Block.hxx @@ -59,6 +59,19 @@ struct BlockParam { */ [[noreturn]] void ThrowWithNested() const; + + /** + * Invoke a function with the configured value; if the + * function throws, call ThrowWithNested(). + */ + template + auto With(F &&f) const { + try { + return f(value.c_str()); + } catch (...) { + ThrowWithNested(); + } + } }; struct ConfigBlock {