From 3733bc57b798adb030ad83354ef40d20f0b07389 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Wed, 10 Jul 2024 16:35:40 +0200 Subject: [PATCH] config/{Block,Data,Param}: add concept checks to With() --- src/config/Block.hxx | 8 +++----- src/config/Data.hxx | 10 ++++------ src/config/Param.hxx | 8 +++----- 3 files changed, 10 insertions(+), 16 deletions(-) diff --git a/src/config/Block.hxx b/src/config/Block.hxx index 57f16b5f6..5dc0bb588 100644 --- a/src/config/Block.hxx +++ b/src/config/Block.hxx @@ -1,9 +1,9 @@ // SPDX-License-Identifier: GPL-2.0-or-later // Copyright The Music Player Daemon Project -#ifndef MPD_CONFIG_BLOCK_HXX -#define MPD_CONFIG_BLOCK_HXX +#pragma once +#include #include #include @@ -45,7 +45,7 @@ struct BlockParam { * Invoke a function with the configured value; if the * function throws, call ThrowWithNested(). */ - template + template F> auto With(F &&f) const { try { return f(value.c_str()); @@ -130,5 +130,3 @@ struct ConfigBlock { [[noreturn]] void ThrowWithNested() const; }; - -#endif diff --git a/src/config/Data.hxx b/src/config/Data.hxx index 3a8fdf8ab..7718d71f1 100644 --- a/src/config/Data.hxx +++ b/src/config/Data.hxx @@ -1,8 +1,7 @@ // SPDX-License-Identifier: GPL-2.0-or-later // Copyright The Music Player Daemon Project -#ifndef MPD_CONFIG_DATA_HXX -#define MPD_CONFIG_DATA_HXX +#pragma once #include "Option.hxx" #include "Param.hxx" @@ -10,6 +9,7 @@ #include #include +#include #include class AllocatedPath; @@ -36,7 +36,7 @@ struct ConfigData { return list.empty() ? nullptr : &list.front(); } - template + template F> auto With(ConfigOption option, F &&f) const { const auto *param = GetParam(option); return param != nullptr @@ -113,7 +113,7 @@ struct ConfigData { * Exceptions thrown by the function will be nested in one * that specifies the location of the block. */ - template + template F> void WithEach(ConfigBlockOption option, F &&f) const { for (const auto &block : GetBlockList(option)) { block.SetUsed(); @@ -126,5 +126,3 @@ struct ConfigData { } } }; - -#endif diff --git a/src/config/Param.hxx b/src/config/Param.hxx index 8ac98df34..4b69d4be3 100644 --- a/src/config/Param.hxx +++ b/src/config/Param.hxx @@ -1,9 +1,9 @@ // SPDX-License-Identifier: GPL-2.0-or-later // Copyright The Music Player Daemon Project -#ifndef MPD_CONFIG_PARAM_HXX -#define MPD_CONFIG_PARAM_HXX +#pragma once +#include #include class AllocatedPath; @@ -53,7 +53,7 @@ struct ConfigParam { * Invoke a function with the configured value; if the * function throws, call ThrowWithNested(). */ - template + template F> auto With(F &&f) const { try { return f(value.c_str()); @@ -62,5 +62,3 @@ struct ConfigParam { } } }; - -#endif