diff --git a/src/CommandLine.cxx b/src/CommandLine.cxx index 981572d40..393269fcb 100644 --- a/src/CommandLine.cxx +++ b/src/CommandLine.cxx @@ -180,8 +180,9 @@ static void version() #ifdef ENABLE_ENCODER "\n" "Encoder plugins:\n"); - encoder_plugins_for_each(plugin) - fmt::print(" {}", plugin->name); + for (const auto &plugin : GetAllEncoderPlugins()) { + fmt::print(" {}", plugin.name); + } fmt::print("\n" #endif diff --git a/src/encoder/EncoderList.cxx b/src/encoder/EncoderList.cxx index f4db535d0..39083f448 100644 --- a/src/encoder/EncoderList.cxx +++ b/src/encoder/EncoderList.cxx @@ -46,9 +46,10 @@ constinit const EncoderPlugin *const encoder_plugins[] = { const EncoderPlugin * encoder_plugin_get(const char *name) { - encoder_plugins_for_each(plugin) - if (strcmp(plugin->name, name) == 0) - return plugin; + for (const auto &plugin : GetAllEncoderPlugins()) { + if (strcmp(plugin.name, name) == 0) + return &plugin; + } return nullptr; } diff --git a/src/encoder/EncoderList.hxx b/src/encoder/EncoderList.hxx index e7b381419..e5c2fe77a 100644 --- a/src/encoder/EncoderList.hxx +++ b/src/encoder/EncoderList.hxx @@ -1,18 +1,20 @@ // SPDX-License-Identifier: GPL-2.0-or-later // Copyright The Music Player Daemon Project -#ifndef MPD_ENCODER_LIST_HXX -#define MPD_ENCODER_LIST_HXX +#pragma once + +#include "util/DereferenceIterator.hxx" +#include "util/TerminatedArray.hxx" struct EncoderPlugin; extern const EncoderPlugin *const encoder_plugins[]; -#define encoder_plugins_for_each(plugin) \ - for (const EncoderPlugin *plugin, \ - *const*encoder_plugin_iterator = &encoder_plugins[0]; \ - (plugin = *encoder_plugin_iterator) != nullptr; \ - ++encoder_plugin_iterator) +static inline auto +GetAllEncoderPlugins() noexcept +{ + return DereferenceContainerAdapter{TerminatedArray{encoder_plugins}}; +} /** * Looks up an encoder plugin by its name. @@ -23,5 +25,3 @@ extern const EncoderPlugin *const encoder_plugins[]; */ const EncoderPlugin * encoder_plugin_get(const char *name); - -#endif