Marco Bubke
|
95d40394da
|
Utils: Add C++ 20 converter function to_array
That can be quite useful to create arrays:
struct MyReallySpecialType
{
std::string_view name;
std::string_view expression;
};
std::string_view getExressionCArray(std::string_view name)
{
static constexpr MyReallySpecialType list[] = {
{"Left", "true"},
{"Center", "execute(%1)"},
{"Right", "false"}};
auto found =std::find_if(
std::begin(list),
std::end(list),
[&] (const auto &entry) { return entry.name == name; });
if (found != std::end(list))
return found->expression;
return {};
}
std::string_view getExressionStdArray(std::string_view name)
{
static constexpr auto list = Utils::to_array<MyReallySpecialType>({
{"Left", "true"},
{"Center", "execute(%1)"},
{"Right", "false"}});
auto found = std::find_if(
std::begin(list),
std::end(list),
[&] (const auto &entry) { return entry.name == name; });
if (found != std::end(list))
return found->expression;
return {};
}
Change-Id: Ifc737edb72d7a5f63b26203a5f22bfde19b5c2bc
Reviewed-by: Qt CI Patch Build Bot <ci_patchbuild_bot@qt.io>
Reviewed-by: Tim Jenssen <tim.jenssen@qt.io>
|
2023-10-04 10:27:28 +00:00 |
|