Use lambdas in a few places

This commit is contained in:
Thomas Goyne 2012-11-12 19:36:25 -08:00
parent dbbb73651d
commit b6b68b789d
5 changed files with 10 additions and 19 deletions

View File

@ -181,8 +181,8 @@ void DialogAutomation::UpdateDisplay()
template<class Container> template<class Container>
static bool has_file(Container const& c, wxFileName const& fn) static bool has_file(Container const& c, wxFileName const& fn)
{ {
return find_if(c.begin(), c.end(), return any_of(c.begin(), c.end(),
std::bind(&wxFileName::SameAs, fn, std::bind(&Automation4::Script::GetFilename, _1), wxPATH_NATIVE)) != c.end(); [&](const Automation4::Script *s) { return fn.SameAs(s->GetFilename()); });
} }
void DialogAutomation::OnAdd(wxCommandEvent &) void DialogAutomation::OnAdd(wxCommandEvent &)

View File

@ -702,10 +702,6 @@ void DialogStyleManager::UpdateButtons() {
CurrentSort->Enable(itemsCurr > 1); CurrentSort->Enable(itemsCurr > 1);
} }
static bool cmp_style_name(const AssStyle *lft, const AssStyle *rgt) {
return lft->name < rgt->name;
}
template<class Cont> template<class Cont>
static void do_move(Cont& styls, int type, int& first, int& last, bool storage) { static void do_move(Cont& styls, int type, int& first, int& last, bool storage) {
typename Cont::iterator begin = styls.begin(); typename Cont::iterator begin = styls.begin();
@ -744,7 +740,9 @@ static void do_move(Cont& styls, int type, int& first, int& last, bool storage)
if (res == wxNO) return; if (res == wxNO) return;
} }
sort(styls.begin(), styls.end(), cmp_style_name); sort(styls.begin(), styls.end(), [](const AssStyle *lft, const AssStyle *rgt) {
return lft->name < rgt->name;
});
first = 0; first = 0;
last = 0; last = 0;

View File

@ -307,8 +307,8 @@ std::vector<AssDialogue*> DialogTimingProcessor::SortDialogues() {
if (onlySelection->IsChecked()) { if (onlySelection->IsChecked()) {
SubtitleSelection sel = c->selectionController->GetSelectedSet(); SubtitleSelection sel = c->selectionController->GetSelectedSet();
remove_copy_if(sel.begin(), sel.end(), back_inserter(sorted), copy_if(sel.begin(), sel.end(), back_inserter(sorted),
bind(bad_line, &styles, _1)); [&](AssDialogue *d) { return !d->Comment && styles.count(d->Style); });
} }
else { else {
transform(c->ass->Line.begin(), c->ass->Line.end(), back_inserter(sorted), cast<AssDialogue*>()); transform(c->ass->Line.begin(), c->ass->Line.end(), back_inserter(sorted), cast<AssDialogue*>());

View File

@ -152,12 +152,8 @@ void VisualToolDrag::OnFrameChanged() {
} }
} }
template<class T> static bool cmp_line(T const& lft, T const& rgt) {
return lft->line == rgt->line;
}
template<class C, class T> static bool line_not_present(C const& set, T const& it) { template<class C, class T> static bool line_not_present(C const& set, T const& it) {
return find_if(set.begin(), set.end(), bind(cmp_line<T>, it, std::placeholders::_1)) == set.end(); return std::none_of(set.begin(), set.end(), [&](T const& cmp) { return cmp->line == it->line; });
} }
void VisualToolDrag::OnSelectedSetChanged(const SubtitleSelection &added, const SubtitleSelection &removed) { void VisualToolDrag::OnSelectedSetChanged(const SubtitleSelection &added, const SubtitleSelection &removed) {

View File

@ -94,10 +94,6 @@ void VisualToolVectorClip::SetMode(int new_mode) {
mode = new_mode; mode = new_mode;
} }
static bool is_move(SplineCurve const& c) {
return c.type == SplineCurve::POINT;
}
void VisualToolVectorClip::Draw() { void VisualToolVectorClip::Draw() {
if (!active_line) return; if (!active_line) return;
if (spline.empty()) return; if (spline.empty()) return;
@ -145,7 +141,8 @@ void VisualToolVectorClip::Draw() {
// Draw preview of inserted line // Draw preview of inserted line
if (mode == 1 || mode == 2) { if (mode == 1 || mode == 2) {
if (spline.size() && mouse_pos) { if (spline.size() && mouse_pos) {
Spline::reverse_iterator c0 = std::find_if(spline.rbegin(), spline.rend(), is_move); auto c0 = std::find_if(spline.rbegin(), spline.rend(),
[](SplineCurve const& s) { return s.type == SplineCurve::POINT; });
SplineCurve *c1 = &spline.back(); SplineCurve *c1 = &spline.back();
gl.DrawDashedLine(mouse_pos, c0->p1, 6); gl.DrawDashedLine(mouse_pos, c0->p1, 6);
gl.DrawDashedLine(mouse_pos, c1->EndPoint(), 6); gl.DrawDashedLine(mouse_pos, c1->EndPoint(), 6);