Skip to content

OpenToonz - An open-source full-featured 2D animation creation software

C

Remove boost::bind

otakuto3bf77288b575
diff --git a/toonz/sources/tnztools/levelselection.cpp b/toonz/sources/tnztools/levelselection.cpp
index bfa0d427e..688d1dae7 100644
--- a/toonz/sources/tnztools/levelselection.cpp
+++ b/toonz/sources/tnztools/levelselection.cpp
@@ -14,7 +14,6 @@
// Boost includes
#include <boost/iterator/counting_iterator.hpp>
-#include <boost/bind.hpp>
//*******************************************************************************
// Local namespace stuff
@@ -108,7 +107,7 @@ void getBoundaries(TVectorImage &vi, std::vector<int> &strokes) {
std::copy_if(boost::make_counting_iterator(0u),
boost::make_counting_iterator(vi.getStrokeCount()),
std::back_inserter(strokes),
- boost::bind(locals::isBoundary, sData, _1));
+ [&](UINT e) { return locals::isBoundary(sData, e); });
}
} // namespace
diff --git a/toonz/sources/tnztools/vectorselectiontool.cpp b/toonz/sources/tnztools/vectorselectiontool.cpp
index 2a73d1eb5..be77085df 100644
--- a/toonz/sources/tnztools/vectorselectiontool.cpp
+++ b/toonz/sources/tnztools/vectorselectiontool.cpp
@@ -24,9 +24,6 @@
// TnzCore includes
#include "drawutil.h"
-// boost includes
-#include <boost/bind.hpp>
-
using namespace ToolUtils;
using namespace DragSelectionTool;
@@ -652,7 +649,7 @@ void DragSelectionTool::VectorDeformTool::transformWholeLevel() {
// Remove unwanted fids
fids.erase(std::remove_if(
fids.begin(), fids.end(),
- boost::bind(::currentOrNotSelected, boost::cref(*tool), _1)),
+ [tool](const TFrameId &fid) { return currentOrNotSelected(*tool, fid); }),
fids.end());
TUndoManager::manager()->beginBlock();
@@ -701,9 +698,9 @@ void DragSelectionTool::VectorDeformTool::transformWholeLevel() {
// Finally, notify changed frames
std::for_each(fids.begin(), fids.end(),
- boost::bind( // NOTE: current frame is not here - it should be,
- &TTool::notifyImageChanged, m_tool,
- _1)); // but it's currently unnecessary, in fact...
+ // NOTE: current frame is not here - it should be,
+ // but it's currently unnecessary, in fact...
+ [this](const TFrameId &fid) { m_tool->notifyImageChanged(fid); });
// notifyImageChanged(fid) must be invoked OUTSIDE of the loop - since it
// seems to imply notifyImageChanged()
@@ -973,12 +970,12 @@ void DragSelectionTool::VectorChangeThicknessTool::setStrokesThickness(
const std::set<int> &selectedStrokeIdxs = strokeSelection->getSelection();
std::for_each(selectedStrokeIdxs.begin(), selectedStrokeIdxs.end(),
- boost::bind(locals::setThickness, boost::cref(data), _1));
+ [&data](int s) { locals::setThickness(data, s); });
} else {
std::vector<int> strokeIdxs = getSelectedStrokes(vi, levelSelection);
std::for_each(strokeIdxs.begin(), strokeIdxs.end(),
- boost::bind(locals::setThickness, boost::cref(data), _1));
+ [&data](int s) { locals::setThickness(data, s); });
}
}
@@ -1027,12 +1024,12 @@ void DragSelectionTool::VectorChangeThicknessTool::changeImageThickness(
const std::set<int> &selectedStrokeIdxs = strokeSelection->getSelection();
std::for_each(selectedStrokeIdxs.begin(), selectedStrokeIdxs.end(),
- boost::bind(locals::changeThickness, boost::ref(data), _1));
+ [&data](int s) { locals::changeThickness(data, s); });
} else {
std::vector<int> strokeIdxs = getSelectedStrokes(vi, levelSelection);
std::for_each(strokeIdxs.begin(), strokeIdxs.end(),
- boost::bind(locals::changeThickness, boost::ref(data), _1));
+ [&data](int s) { locals::changeThickness(data, s); });
}
}
@@ -1058,8 +1055,7 @@ void DragSelectionTool::VectorChangeThicknessTool::addUndo() {
// Remove unwanted frames
fids.erase(std::remove_if(fids.begin(), fids.end(),
- boost::bind(::currentOrNotSelected,
- boost::cref(*vtool), _1)),
+ [vtool](const TFrameId &fid) { return currentOrNotSelected(*vtool, fid); }),
fids.end());
TUndoManager::manager()->beginBlock();
@@ -1095,9 +1091,7 @@ void DragSelectionTool::VectorChangeThicknessTool::addUndo() {
// Finally, notify changed frames
std::for_each(fids.begin(), fids.end(),
- boost::bind( // NOTE: current frame is not here - it was
- &TTool::notifyImageChanged, m_tool,
- _1)); // aldready notified
+ [this](const TFrameId &fid) { m_tool->notifyImageChanged(fid); });
} else
TUndoManager::manager()->add(m_undo.release()); // Outside any undo block
}
@@ -1283,7 +1277,7 @@ void VectorSelectionTool::setNewFreeDeformer() {
fids.erase(std::remove_if(
fids.begin(), fids.end(),
- boost::bind(::currentOrNotSelected, boost::cref(*this), _1)),
+ [this](const TFrameId &fid) { return currentOrNotSelected(*this, fid); }),
fids.end());
std::vector<TFrameId>::iterator ft, fEnd = fids.end();
diff --git a/toonz/sources/toonz/filebrowser.cpp b/toonz/sources/toonz/filebrowser.cpp
index 1565d696c..c3c40770b 100644
--- a/toonz/sources/toonz/filebrowser.cpp
+++ b/toonz/sources/toonz/filebrowser.cpp
@@ -80,7 +80,6 @@
#include "tcg/boost/permuted_range.h"
// boost includes
-#include <boost/bind.hpp>
#include <boost/iterator/counting_iterator.hpp>
#include <boost/range/adaptor/filtered.hpp>
#include <boost/range/adaptor/transformed.hpp>
@@ -435,7 +434,7 @@ void FileBrowser::sortByDataModel(DataType dataType, bool isDiscendent) {
std::stable_sort(
new2OldIdx.begin(), new2OldIdx.end(),
- boost::bind(locals::itemLess, _1, _2, boost::ref(*this), dataType));
+ [this, dataType](int x, int y) { return locals::itemLess(x, y, *this, dataType); });
// Use the renumbering table to permutate elements
std::vector<Item>(
@@ -453,15 +452,13 @@ void FileBrowser::sortByDataModel(DataType dataType, bool isDiscendent) {
boost::make_counting_iterator(int(m_items.size())));
std::sort(old2NewIdx.begin(), old2NewIdx.end(),
- boost::bind(locals::indexLess, _1, _2, boost::ref(new2OldIdx)));
+ [&new2OldIdx](int aIdx, int bIdx){ return locals::indexLess(aIdx, bIdx, new2OldIdx); });
std::vector<int> newSelectedIndices;
tcg::substitute(
newSelectedIndices,
tcg::permuted_range(old2NewIdx, fs->getSelectedIndices() |
- ba::filtered(boost::bind(
- std::less<int>(), _1,
- int(old2NewIdx.size())))));
+ ba::filtered([&old2NewIdx](int x){ return x < old2NewIdx.size(); })));
fs->select(!newSelectedIndices.empty() ? &newSelectedIndices.front() : 0,
int(newSelectedIndices.size()));
@@ -486,8 +483,8 @@ void FileBrowser::sortByDataModel(DataType dataType, bool isDiscendent) {
tcg::substitute(
newSelectedIndices,
fs->getSelectedIndices() |
- ba::filtered(boost::bind(std::less<int>(), _1, iCount)) |
- ba::transformed(boost::bind(locals::complement, _1, lastIdx)));
+ ba::filtered([iCount](int x){ return x < iCount; }) |
+ ba::transformed([lastIdx](int x){ return locals::complement(x, lastIdx); }));
fs->select(!newSelectedIndices.empty() ? &newSelectedIndices.front() : 0,
int(newSelectedIndices.size()));
diff --git a/toonz/sources/toonz/loadfoldercommand.cpp b/toonz/sources/toonz/loadfoldercommand.cpp
index 47fb11d07..05d9301b5 100644
--- a/toonz/sources/toonz/loadfoldercommand.cpp
+++ b/toonz/sources/toonz/loadfoldercommand.cpp
@@ -35,8 +35,6 @@
#include <boost/operators.hpp>
#include <boost/range.hpp>
-#include <boost/bind.hpp>
-
#include <boost/iterator/transform_iterator.hpp>
#include <boost/range/algorithm/for_each.hpp>
@@ -239,9 +237,7 @@ struct buildResources_locals {
const MergeData *mdt,
*mdEnd = mergeTable + boost::size(mergeTable) - 1; // Last item is fake
- mdt = std::find_if(mergeTable, mdEnd,
- boost::bind(exactMatch<MergeData>, _1,
- boost::cref(rt->first.first.m_relFp)));
+ mdt = std::find_if(mergeTable, mdEnd, [&rt](const MergeData& mergeData){ return exactMatch(mergeData, rt->first.first.m_relFp); });
if (mdt != mdEnd) {
// Lookup every possible resource component to merge
@@ -306,8 +302,7 @@ void buildResources(std::vector<Resource> &resources, const TFilePath &rootPath,
const FormatData *fdt,
*fdEnd = l_formatDatas + boost::size(l_formatDatas);
fdt = std::find_if(
- l_formatDatas, fdEnd,
- boost::bind(exactMatch<FormatData>, _1, boost::cref(relPath)));
+ l_formatDatas, fdEnd, [&relPath](const FormatData &formatData){ return exactMatch(formatData, relPath); });
if (fdt != fdEnd) {
relPath = fdt->m_resourcePathFunc(relPath);
@@ -402,8 +397,7 @@ struct import_Locals {
// Perform resource copy
std::for_each(rsrc.m_components.begin(), rsrc.m_components.end(),
- boost::bind(copy, boost::cref(srcDir), boost::cref(dstDir),
- _1, overwrite));
+ [&srcDir, &dstDir, &overwrite](const Resource::Component &comp){ copy(srcDir, dstDir, comp, overwrite); });
} catch (const TException &e) {
DVGui::error(QString::fromStdWString(e.getMessage()));
} catch (...) {
@@ -492,7 +486,7 @@ QString OverwriteDialog::acceptResolution(void *obj_, int resolution,
static bool existsResource(const TFilePath &dstDir, const Resource &rsrc) {
return std::any_of(rsrc.m_components.begin(), rsrc.m_components.end(),
- boost::bind(existsComponent, boost::cref(dstDir), _1));
+ [&dstDir](const Resource::Component &comp){ return existsComponent(dstDir, comp); });
}
}; // locals
@@ -547,7 +541,7 @@ int IoCmd::loadResourceFolders(LoadResourceArguments &args,
{
if (std::any_of(
args.resourceDatas.begin(), args.resourceDatas.end(),
- boost::bind(locals::isExternPath, boost::cref(*scene), _1))) {
+ [scene](const LRArgs::ResourceData &rd){ return locals::isExternPath(*scene, rd); })) {
// Ask for data import in this case
int resolutionButton = DVGui::MsgBox(
QObject::tr("Selected folders don't belong to the current project.\n"
@@ -570,11 +564,8 @@ int IoCmd::loadResourceFolders(LoadResourceArguments &args,
// Select resources to be loaded
std::vector<Resource> resources;
- boost::for_each(
- args.resourceDatas |
- boost::adaptors::transformed(boost::bind<const TFilePath &>(
- &LRArgs::ResourceData::m_path, _1)),
- boost::bind(::buildResources, boost::ref(resources), _1, TFilePath()));
+ boost::for_each(args.resourceDatas,
+ [&resources](const LRArgs::ResourceData &resourceData){ buildResources(resources, resourceData.m_path, TFilePath()); });
// Import them if required
if (import) ::import(*scene, resources, *sb);
diff --git a/toonz/sources/toonz/scenebrowser.cpp b/toonz/sources/toonz/scenebrowser.cpp
index f79eaf2e7..a44a51995 100644
--- a/toonz/sources/toonz/scenebrowser.cpp
+++ b/toonz/sources/toonz/scenebrowser.cpp
@@ -81,7 +81,6 @@
#include "tcg/boost/permuted_range.h"
// boost includes
-#include <boost/bind.hpp>
#include <boost/iterator/counting_iterator.hpp>
#include <boost/range/adaptor/filtered.hpp>
#include <boost/range/adaptor/transformed.hpp>
@@ -419,7 +418,7 @@ void SceneBrowser::sortByDataModel(DataType dataType, bool isDiscendent) {
std::stable_sort(
new2OldIdx.begin(), new2OldIdx.end(),
- boost::bind(locals::itemLess, _1, _2, boost::ref(*this), dataType));
+ [this, dataType](int x, int y){ return locals::itemLess(x, y, *this, dataType); });
// Use the renumbering table to permutate elements
std::vector<Item>(
@@ -437,15 +436,13 @@ void SceneBrowser::sortByDataModel(DataType dataType, bool isDiscendent) {
boost::make_counting_iterator(int(m_items.size())));
std::sort(old2NewIdx.begin(), old2NewIdx.end(),
- boost::bind(locals::indexLess, _1, _2, boost::ref(new2OldIdx)));
+ [&new2OldIdx](int x, int y){ return locals::indexLess(x, y, new2OldIdx); });
std::vector<int> newSelectedIndices;
tcg::substitute(
newSelectedIndices,
tcg::permuted_range(old2NewIdx, fs->getSelectedIndices() |
- ba::filtered(boost::bind(
- std::less<int>(), _1,
- int(old2NewIdx.size())))));
+ ba::filtered([&old2NewIdx](int x){ return x < old2NewIdx.size(); })));
fs->select(!newSelectedIndices.empty() ? &newSelectedIndices.front() : 0,
int(newSelectedIndices.size()));
@@ -470,8 +467,8 @@ void SceneBrowser::sortByDataModel(DataType dataType, bool isDiscendent) {
tcg::substitute(
newSelectedIndices,
fs->getSelectedIndices() |
- ba::filtered(boost::bind(std::less<int>(), _1, iCount)) |
- ba::transformed(boost::bind(locals::complement, _1, lastIdx)));
+ ba::filtered([iCount](int x){ return x < iCount; }) |
+ ba::transformed([lastIdx](int x){ return locals::complement(x, lastIdx); }));
fs->select(!newSelectedIndices.empty() ? &newSelectedIndices.front() : 0,
int(newSelectedIndices.size()));
diff --git a/toonz/sources/toonz/selectionutils.cpp b/toonz/sources/toonz/selectionutils.cpp
index 39b611eca..7be8f3059 100644
--- a/toonz/sources/toonz/selectionutils.cpp
+++ b/toonz/sources/toonz/selectionutils.cpp
@@ -24,7 +24,6 @@
#include "tcg/boost/range_utility.h"
// Boost includes
-#include <boost/bind.hpp>
#include <boost/range/counting_range.hpp>
#include <boost/range/adaptor/transformed.hpp>
@@ -63,8 +62,7 @@ void getSelectedFrames<TXshSimpleLevel>(
if (!sl) continue;
tcg::substitute(frames[sl], boost::counting_range(0, sl->getFrameCount()) |
- boost::adaptors::transformed(boost::bind(
- &TXshSimpleLevel::getFrameId, sl, _1)));
+ boost::adaptors::transformed([&sl](int index){ return sl->getFrameId(index); }));
}
}
diff --git a/toonz/sources/toonz/xsheetcmd.cpp b/toonz/sources/toonz/xsheetcmd.cpp
index 54108c50b..458767b9b 100644
--- a/toonz/sources/toonz/xsheetcmd.cpp
+++ b/toonz/sources/toonz/xsheetcmd.cpp
@@ -71,8 +71,6 @@
#include "tcg/boost/range_utility.h"
// boost includes
-#include <boost/bind.hpp>
-#include <boost/bind/make_adaptable.hpp>
#include <boost/range/adaptor/filtered.hpp>
#include <boost/range/adaptor/transformed.hpp>
@@ -431,8 +429,7 @@ public:
: GlobalKeyframeUndo(frame) {
tcg::substitute(
m_columns,
- columns | ba::filtered(std::not1(boost::make_adaptable<bool, int>(
- boost::bind(isKeyframe, frame, _1)))));
+ columns | ba::filtered([frame](int c){ return !isKeyframe(frame, c); }));
}
void redo() const override {
@@ -506,11 +503,10 @@ public:
}; // locals
tcg::substitute(m_columns,
- columns | ba::filtered(boost::bind(isKeyframe, frame, _1)));
+ columns | ba::filtered([frame](int c){ return isKeyframe(frame, c); }));
tcg::substitute(m_keyframes,
- m_columns | ba::transformed(boost::bind(locals::getKeyframe,
- frame, _1)));
+ m_columns | ba::transformed([frame](int c){ return locals::getKeyframe(frame, c); }));
}
void redo() const override {
diff --git a/toonz/sources/toonzlib/palettecmd.cpp b/toonz/sources/toonzlib/palettecmd.cpp
index 19d8db440..0b117a49f 100644
--- a/toonz/sources/toonzlib/palettecmd.cpp
+++ b/toonz/sources/toonzlib/palettecmd.cpp
@@ -39,7 +39,6 @@
#include "tcg/boost/range_utility.h"
// boost includes
-#include <boost/bind.hpp>
#include <boost/range/counting_range.hpp>
#include <boost/range/adaptor/transformed.hpp>
#include <boost/range/adaptor/filtered.hpp>
@@ -583,8 +582,7 @@ void PaletteCmd::eraseStyles(const std::set<TXshSimpleLevel *> &levels,
tcg::substitute(
levelImages.second,
boost::counting_range(0, levelImages.first->getFrameCount()) |
- boost::adaptors::transformed(boost::bind(
- cloneImage, boost::cref(*levelImages.first), _1)));
+ boost::adaptors::transformed([&levelImages](int f){ return cloneImage(*levelImages.first, f); }));
}
static void restoreImage(const TXshSimpleLevelP &level, int f,
diff --git a/toonz/sources/toonzlib/preferences.cpp b/toonz/sources/toonzlib/preferences.cpp
index fd28142f7..7210e9166 100644
--- a/toonz/sources/toonzlib/preferences.cpp
+++ b/toonz/sources/toonzlib/preferences.cpp
@@ -27,9 +27,6 @@
#include <QColor>
#include <QTextStream>
-// boost includes
-#include <boost/bind.hpp>
-
//**********************************************************************************
// Local namespace stuff
//**********************************************************************************
@@ -1106,7 +1103,7 @@ int Preferences::levelFormatsCount() const {
int Preferences::matchLevelFormat(const TFilePath &fp) const {
LevelFormatVector::const_iterator lft =
std::find_if(m_levelFormats.begin(), m_levelFormats.end(),
- boost::bind(&LevelFormat::matches, _1, boost::cref(fp)));
+ [&fp](const LevelFormat &format) { return format.matches(fp); });
return (lft != m_levelFormats.end()) ? lft - m_levelFormats.begin() : -1;
}