Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

more fixups for foreach. We need to be able to have deduction guide … #173

Merged
merged 1 commit into from
Dec 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion include/wxUI/ForEach.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,13 @@ struct ForEach {
Function createFunction;
};

// initializer_list is like a string_view, we want a copy. So deduce as vector so we have a copy
template <std::ranges::input_range Range, typename Function>
ForEach(Range&&, Function&&) -> ForEach<Range, Function>;

template <std::ranges::input_range Range, typename Function>
ForEach(wxSizerFlags const& flags, Range&&, Function&&) -> ForEach<Range, Function>;

// initializer_list is like a string_view, we want a copy. So deduce as vector so we have a copy
template <typename Function, typename T>
ForEach(std::initializer_list<T>, Function&&) -> ForEach<std::vector<T>, Function>;

Expand Down
189 changes: 189 additions & 0 deletions tests/wxUI_ForEachTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,69 @@ TEST_CASE("ForEach")
});
uut3.createAndAdd(&frame, &sizer, wxSizerFlags {});
}
SECTION("ForEach.Flags.lvalue.Vector.T")
{
auto data = std::vector { "A", "B", "C" };
auto builder = [](auto name) {
return wxUI::Button { name };
};
{
wxFrame frame { nullptr, wxID_ANY, "" };
auto sizer = wxBoxSizer(wxHORIZONTAL);
auto uut = wxUI::ForEach {
wxSizerFlags {},
data,
[](auto name) {
return wxUI::Button { name };
}
};
uut.createAndAdd(&frame, &sizer, wxSizerFlags {});
auto uut2 = wxUI::VForEach(
wxSizerFlags {},
data,
[](auto name) {
return wxUI::Button { name };
});
uut2.createAndAdd(&frame, &sizer, wxSizerFlags {});
auto uut3 = wxUI::HForEach(
wxSizerFlags {},
data,
[](auto name) {
return wxUI::Button { name };
});
uut3.createAndAdd(&frame, &sizer, wxSizerFlags {});
}
{
wxFrame frame { nullptr, wxID_ANY, "" };
auto sizer = wxBoxSizer(wxHORIZONTAL);
auto uut = wxUI::ForEach {
wxSizerFlags {},
std::vector { "A", "B", "C" },
builder
};
uut.createAndAdd(&frame, &sizer, wxSizerFlags {});
auto uut2 = wxUI::VForEach(
wxSizerFlags {},
std::vector { "A", "B", "C" },
builder);
uut2.createAndAdd(&frame, &sizer, wxSizerFlags {});
auto uut3 = wxUI::HForEach(
wxSizerFlags {},
std::vector { "A", "B", "C" },
builder);
uut3.createAndAdd(&frame, &sizer, wxSizerFlags {});
}
{
wxFrame frame { nullptr, wxID_ANY, "" };
auto sizer = wxBoxSizer(wxHORIZONTAL);
auto uut = wxUI::ForEach { wxSizerFlags {}, data, builder };
uut.createAndAdd(&frame, &sizer, wxSizerFlags {});
auto uut2 = wxUI::VForEach(wxSizerFlags {}, data, builder);
uut2.createAndAdd(&frame, &sizer, wxSizerFlags {});
auto uut3 = wxUI::HForEach(wxSizerFlags {}, data, builder);
uut3.createAndAdd(&frame, &sizer, wxSizerFlags {});
}
}
SECTION("ForEach.Flags.Vector.Tuple")
{
wxFrame frame { nullptr, wxID_ANY, "" };
Expand Down Expand Up @@ -527,6 +590,69 @@ TEST_CASE("ForEach")
});
uut3.createAndAdd(&frame, &sizer, wxSizerFlags {});
}
SECTION("ForEach.Flags.lvalue.Range.T")
{
auto data = std::vector { "A", "B", "C" } | std::views::filter([](auto str) { return str[0] == 'A'; });
auto builder = [](auto name) {
return wxUI::Button { name };
};
{
wxFrame frame { nullptr, wxID_ANY, "" };
auto sizer = wxBoxSizer(wxHORIZONTAL);
auto uut = wxUI::ForEach {
wxSizerFlags {},
data,
[](auto name) {
return wxUI::Button { name };
}
};
uut.createAndAdd(&frame, &sizer, wxSizerFlags {});
auto uut2 = wxUI::VForEach(
wxSizerFlags {},
data,
[](auto name) {
return wxUI::Button { name };
});
uut2.createAndAdd(&frame, &sizer, wxSizerFlags {});
auto uut3 = wxUI::HForEach(
wxSizerFlags {},
data,
[](auto name) {
return wxUI::Button { name };
});
uut3.createAndAdd(&frame, &sizer, wxSizerFlags {});
}
{
wxFrame frame { nullptr, wxID_ANY, "" };
auto sizer = wxBoxSizer(wxHORIZONTAL);
auto uut = wxUI::ForEach {
wxSizerFlags {},
std::vector { "A", "B", "C" },
builder
};
uut.createAndAdd(&frame, &sizer, wxSizerFlags {});
auto uut2 = wxUI::VForEach(
wxSizerFlags {},
std::vector { "A", "B", "C" },
builder);
uut2.createAndAdd(&frame, &sizer, wxSizerFlags {});
auto uut3 = wxUI::HForEach(
wxSizerFlags {},
std::vector { "A", "B", "C" },
builder);
uut3.createAndAdd(&frame, &sizer, wxSizerFlags {});
}
{
wxFrame frame { nullptr, wxID_ANY, "" };
auto sizer = wxBoxSizer(wxHORIZONTAL);
auto uut = wxUI::ForEach { wxSizerFlags {}, data, builder };
uut.createAndAdd(&frame, &sizer, wxSizerFlags {});
auto uut2 = wxUI::VForEach(wxSizerFlags {}, data, builder);
uut2.createAndAdd(&frame, &sizer, wxSizerFlags {});
auto uut3 = wxUI::HForEach(wxSizerFlags {}, data, builder);
uut3.createAndAdd(&frame, &sizer, wxSizerFlags {});
}
}
SECTION("ForEach.Flags.Range.Tuple")
{
wxFrame frame { nullptr, wxID_ANY, "" };
Expand Down Expand Up @@ -608,6 +734,69 @@ TEST_CASE("ForEach")
});
uut3.createAndAdd(&frame, &sizer, wxSizerFlags {});
}
SECTION("ForEach.Flags.lvalue.InitializerList.T")
{
auto data = { "A", "B", "C" };
auto builder = [](auto name) {
return wxUI::Button { name };
};
{
wxFrame frame { nullptr, wxID_ANY, "" };
auto sizer = wxBoxSizer(wxHORIZONTAL);
auto uut = wxUI::ForEach {
wxSizerFlags {},
data,
[](auto name) {
return wxUI::Button { name };
}
};
uut.createAndAdd(&frame, &sizer, wxSizerFlags {});
auto uut2 = wxUI::VForEach(
wxSizerFlags {},
data,
[](auto name) {
return wxUI::Button { name };
});
uut2.createAndAdd(&frame, &sizer, wxSizerFlags {});
auto uut3 = wxUI::HForEach(
wxSizerFlags {},
data,
[](auto name) {
return wxUI::Button { name };
});
uut3.createAndAdd(&frame, &sizer, wxSizerFlags {});
}
{
wxFrame frame { nullptr, wxID_ANY, "" };
auto sizer = wxBoxSizer(wxHORIZONTAL);
auto uut = wxUI::ForEach {
wxSizerFlags {},
std::vector { "A", "B", "C" },
builder
};
uut.createAndAdd(&frame, &sizer, wxSizerFlags {});
auto uut2 = wxUI::VForEach(
wxSizerFlags {},
std::vector { "A", "B", "C" },
builder);
uut2.createAndAdd(&frame, &sizer, wxSizerFlags {});
auto uut3 = wxUI::HForEach(
wxSizerFlags {},
std::vector { "A", "B", "C" },
builder);
uut3.createAndAdd(&frame, &sizer, wxSizerFlags {});
}
{
wxFrame frame { nullptr, wxID_ANY, "" };
auto sizer = wxBoxSizer(wxHORIZONTAL);
auto uut = wxUI::ForEach { wxSizerFlags {}, data, builder };
uut.createAndAdd(&frame, &sizer, wxSizerFlags {});
auto uut2 = wxUI::VForEach(wxSizerFlags {}, data, builder);
uut2.createAndAdd(&frame, &sizer, wxSizerFlags {});
auto uut3 = wxUI::HForEach(wxSizerFlags {}, data, builder);
uut3.createAndAdd(&frame, &sizer, wxSizerFlags {});
}
}
SECTION("ForEach.Flags.InitializerList.Tuple")
{
wxFrame frame { nullptr, wxID_ANY, "" };
Expand Down