diff --git a/toonz/sources/common/tmeshimage/tmeshimage.cpp b/toonz/sources/common/tmeshimage/tmeshimage.cpp index e82e830..129f393 100644 --- a/toonz/sources/common/tmeshimage/tmeshimage.cpp +++ b/toonz/sources/common/tmeshimage/tmeshimage.cpp @@ -5,7 +5,6 @@ // tcg includes #include "tcg/tcg_misc.h" -#include "tcg/tcg_iterator_ops.h" #define INCLUDE_HPP #include "tmeshimage.h" @@ -24,10 +23,6 @@ typedef tcg::TriMesh> TriMesh_base; DEFINE_CLASS_CODE(TTextureMesh, 120) PERSIST_IDENTIFIER(TTextureMesh, "mesh") -static TTextureMeshP cloneMesh_(const TTextureMeshP &other) { - return TTextureMeshP(new TTextureMesh(*other)); -} - static void static_check() { /* input iterator */ static_assert( @@ -56,35 +51,6 @@ static void static_check() { TTextureMeshP>::iterator>::reference>::value == true, "akan"); - - /* converted iterator */ - std::vector vec; - auto it = vec.end(); - auto c = tcg::make_cast_it(it, cloneMesh_); - - static_assert( - std::is_same::iterator_category, - std::random_access_iterator_tag>::value == true, - "random"); - - static_assert( - std::is_base_of< - std::input_iterator_tag, - std::iterator_traits::iterator_category>::value == true, - "input"); - - static_assert( - std::is_base_of< - std::forward_iterator_tag, - std::iterator_traits::iterator_category>::value == true, - "forward"); - - // TTextureMeshP p(std::iterator_traits< decltype(c) >::reference); - static_assert( - std::is_constructible< - TTextureMeshP, std::iterator_traits::reference>::value == - true, - "akan"); } //----------------------------------------------------------------------- @@ -310,11 +276,11 @@ public: Imp() : m_dpiX(), m_dpiY() {} - Imp(const Imp &other) - : m_meshes(tcg::make_cast_it(other.m_meshes.begin(), cloneMesh), - tcg::make_cast_it(other.m_meshes.end(), cloneMesh)) - , m_dpiX(other.m_dpiX) - , m_dpiY(other.m_dpiY) {} + Imp(const Imp &other) : m_dpiX(other.m_dpiX), m_dpiY(other.m_dpiY) { + for (auto const &e : other.m_meshes) { + m_meshes.push_back(cloneMesh(e)); + } + } private: static TTextureMeshP cloneMesh(const TTextureMeshP &other) { diff --git a/toonz/sources/include/tcg/iterator_ops.h b/toonz/sources/include/tcg/iterator_ops.h index d93edf8..df1bcce 100644 --- a/toonz/sources/include/tcg/iterator_ops.h +++ b/toonz/sources/include/tcg/iterator_ops.h @@ -26,159 +26,6 @@ struct iterator_traits : public std::iterator_traits { typedef ptr inheritable_iterator_type; }; -//**************************************************************************** -// Derived Iterator definition -//**************************************************************************** - -template ::iterator_category> -struct derived_iterator - : public tcg::iterator_traits::inheritable_iterator_type { - typedef typename tcg::iterator_traits::inheritable_iterator_type - base_iterator; - -public: - derived_iterator() : base_iterator() {} - derived_iterator(const base_iterator &it) : base_iterator(it) {} - - Der &operator++() { - base_iterator::operator++(); - return static_cast(*this); - } - Der operator++(int) { - return Der(base_iterator::operator++(0), static_cast(*this)); - } -}; - -template -struct derived_iterator - : public derived_iterator { - typedef typename tcg::iterator_traits::inheritable_iterator_type - base_iterator; - -public: - derived_iterator() : _iter() {} - derived_iterator(const base_iterator &it) : _iter(it) {} - - Der &operator--() { - base_iterator::operator--(); - return static_cast(*this); - } - Der operator--(int) { - return Der(base_iterator::operator--(0), static_cast(*this)); - } - -private: - typedef derived_iterator _iter; -}; - -template -struct derived_iterator - : public derived_iterator { - typedef typename tcg::iterator_traits::inheritable_iterator_type - base_iterator; - typedef typename base_iterator::difference_type difference_type; - -public: - derived_iterator() : _iter() {} - derived_iterator(const base_iterator &it) : _iter(it) {} - - Der operator+(difference_type d) const { - return Der(static_cast(*this) + d, - static_cast(*this)); - } - Der &operator+=(difference_type d) { - static_cast(*this) += d; - return static_cast(*this); - } - - Der operator-(difference_type d) const { - return Der(static_cast(*this) - d, - static_cast(*this)); - } - Der &operator-=(difference_type d) { - static_cast(*this) -= d; - return static_cast(*this); - } - - difference_type operator-(const Der &other) const { - return static_cast(*this) - - static_cast(other); - } - -private: - typedef derived_iterator _iter; -}; - -//**************************************************************************** -// Cast Iterator definition -//**************************************************************************** - -/*! - A cast iterator is a utility iterator wrapper that can be used to access - an iterator's data through a supplied functor intermediary, proving to be - especially useful when converting data from a container to another with - minimal effort. -*/ - -template ::ret_type>::referenced_type, - typename Ref = typename choose_if_match< - typename function_traits::ret_type &, - typename traits::reference_type>::type, - typename Ptr = typename choose_if_match< - Ref, void, typename traits::pointer_type>::type> -class cast_iterator - : public derived_iterator> { - typedef derived_iterator iterator; - typedef typename iterator::base_iterator base_iterator; - typedef Func function; - typedef typename function_traits::ret_type ret_type; - -public: - typedef Ref reference; - typedef Ptr pointer; - typedef Val value_type; - -public: - cast_iterator() : iterator(), m_func() {} - cast_iterator(const Func &func) : iterator(), m_func(func) {} - - cast_iterator(const base_iterator &it) : iterator(it), m_func() {} - cast_iterator(const base_iterator &it, const Func &func) - : iterator(it), m_func(func) {} - - cast_iterator(const base_iterator &it, const cast_iterator &other) - : iterator(it), m_func(other.m_func) {} - - ret_type operator*() { return m_func(iterator::operator*()); } - pointer operator->() { return ptr(0); } - -private: - Func m_func; - -private: - template - pointer ptr(T, - typename tcg::enable_if::value, - T>::type = 0) const { - return &operator*(); - } - - void ptr(char) const {} -}; - -//========================================================================== - -// Utility maker function - -template -inline cast_iterator make_cast_it(const It &it, Func func) { - return cast_iterator(it, func); -} - //*********************************************************************** // Step Iterator class //*********************************************************************** diff --git a/toonz/sources/tnzext/plasticskeleton.cpp b/toonz/sources/tnzext/plasticskeleton.cpp index 682dd0d..198b95f 100644 --- a/toonz/sources/tnzext/plasticskeleton.cpp +++ b/toonz/sources/tnzext/plasticskeleton.cpp @@ -13,7 +13,6 @@ #include "tcg/tcg_misc.h" #include "tcg/tcg_pool.h" #include "tcg/tcg_function_types.h" -#include "tcg/tcg_iterator_ops.h" #include "ext/plasticskeleton.h" @@ -573,16 +572,9 @@ int PlasticSkeleton::closestEdge(const TPointD &pos, double *dist) const { //------------------------------------------------------------------------------- std::vector PlasticSkeleton::verticesToHandles() const { - // Someway, PlasticHandle's EXPLICIT unary constructors are not enough - // to disambiguate the direct construction of a vector of PlasticHandles - // from m_vertices, at least with *gcc*. I guess it could be a compiler bug. - - // So, we'll convert them using an explicit casting iterator... - - typedef tcg::function < PlasticHandle (PlasticSkeletonVertex::*)() const, - &PlasticSkeletonVertex::operator PlasticHandle> Func; - - return std::vector( - tcg::make_cast_it(m_vertices.begin(), Func()), - tcg::make_cast_it(m_vertices.end(), Func())); + std::vector v; + for (auto const &e : m_vertices) { + v.push_back(e); + } + return v; } diff --git a/toonz/sources/tnztools/plastictool_build.cpp b/toonz/sources/tnztools/plastictool_build.cpp index f1a569d..a4a2094 100644 --- a/toonz/sources/tnztools/plastictool_build.cpp +++ b/toonz/sources/tnztools/plastictool_build.cpp @@ -15,7 +15,6 @@ // tcg includes #include "tcg/tcg_point_ops.h" #include "tcg/tcg_function_types.h" -#include "tcg/tcg_iterator_ops.h" #include "plastictool.h" @@ -562,12 +561,6 @@ void PlasticTool::leftButtonDown_build(const TPointD &pos, // Start move vertex operation if (!m_svSel.isEmpty()) { - struct locals { - static TPointD vertexPos(const PlasticSkeleton &skel, int v) { - return skel.vertex(v).P(); - } - }; - const PlasticSkeletonP &skel = skeleton(); assert(skel); @@ -575,11 +568,11 @@ void PlasticTool::leftButtonDown_build(const TPointD &pos, if (m_svSel.hasSingleObject()) m_pressedPos = skel->vertex(m_svSel).P(); // Store original vertex positions - m_pressedVxsPos = std::vector( - tcg::make_cast_it(m_svSel.objects().begin(), - tcg::bind1st(&locals::vertexPos, *skel)), - tcg::make_cast_it(m_svSel.objects().end(), - tcg::bind1st(&locals::vertexPos, *skel))); + std::vector v; + for (auto const &e : m_svSel.objects()) { + v.push_back(skel->vertex(e).P()); + } + m_pressedVxsPos = std::move(v); } invalidate(); diff --git a/toonz/sources/tnztools/plastictool_meshedit.cpp b/toonz/sources/tnztools/plastictool_meshedit.cpp index 22deeb1..d4da3c4 100644 --- a/toonz/sources/tnztools/plastictool_meshedit.cpp +++ b/toonz/sources/tnztools/plastictool_meshedit.cpp @@ -11,7 +11,6 @@ // tcg includes #include "tcg/tcg_macros.h" #include "tcg/tcg_point_ops.h" -#include "tcg/tcg_iterator_ops.h" #include "tcg/tcg_function_types.h" // boost includes @@ -1052,11 +1051,6 @@ void PlasticTool::leftButtonDown_mesh(const TPointD &pos, } else m_this->setMeshSelection(sel, MeshSelection()); } - - static TPointD vertexPos(const TMeshImage &mi, const MeshIndex &meshIdx) { - return mi.meshes()[meshIdx.m_meshIdx]->vertex(meshIdx.m_idx).P(); - } - } locals = {this}; // Track mouse position @@ -1068,11 +1062,11 @@ void PlasticTool::leftButtonDown_mesh(const TPointD &pos, // Store original vertex positions if (!m_mvSel.isEmpty()) { - m_pressedVxsPos = std::vector( - tcg::make_cast_it(m_mvSel.objects().begin(), - tcg::bind1st(&Locals::vertexPos, *m_mi)), - tcg::make_cast_it(m_mvSel.objects().end(), - tcg::bind1st(&Locals::vertexPos, *m_mi))); + std::vector v; + for (auto const &e : m_mvSel.objects()) { + v.push_back(m_mi->meshes()[e.m_meshIdx]->vertex(e.m_idx).P()); + } + m_pressedVxsPos = std::move(v); } // Redraw selections diff --git a/toonz/sources/toonz/adjustthicknesspopup.cpp b/toonz/sources/toonz/adjustthicknesspopup.cpp index 46e5554..75af9cb 100644 --- a/toonz/sources/toonz/adjustthicknesspopup.cpp +++ b/toonz/sources/toonz/adjustthicknesspopup.cpp @@ -48,7 +48,6 @@ // tcg includes #include "tcg/tcg_numeric_ops.h" #include "tcg/tcg_function_types.h" -#include "tcg/tcg_iterator_ops.h" // boost includes #include @@ -298,10 +297,6 @@ AdjustThicknessPopup::SelectionData::SelectionData(const TSelection *sel) struct Locals { SelectionData *m_this; - typedef tcg::function - Fid2Index; - void resetIfInvalid() // Resets to empty if thickness adjustment is { // not applicable: if (!m_this->m_sl) // 1. The level is not a VECTOR level @@ -349,11 +344,11 @@ AdjustThicknessPopup::SelectionData::SelectionData(const TSelection *sel) const std::set &fids = selection.getSelectedFids(); - m_this->m_frameIdxs = std::set( - tcg::make_cast_it(fids.begin(), - tcg::bind1st(Fid2Index(), *m_this->m_sl)), - tcg::make_cast_it(fids.end(), - tcg::bind1st(Fid2Index(), *m_this->m_sl))); + std::set s; + for (auto const &e : fids) { + s.insert(m_this->m_sl->fid2index(e)); + } + m_this->m_frameIdxs = std::move(s); resetIfInvalid(); } @@ -484,11 +479,11 @@ AdjustThicknessPopup::SelectionData::SelectionData(const TSelection *sel) const std::set &fids = TTool::getSelectedFrames(); - m_this->m_frameIdxs = std::set( - tcg::make_cast_it(fids.begin(), - tcg::bind1st(Fid2Index(), *m_this->m_sl)), - tcg::make_cast_it(fids.end(), - tcg::bind1st(Fid2Index(), *m_this->m_sl))); + std::set s; + for (auto const &e : fids) { + s.insert(m_this->m_sl->fid2index(e)); + } + m_this->m_frameIdxs = std::move(s); break; } } diff --git a/toonz/sources/toonzlib/fxcommand.cpp b/toonz/sources/toonzlib/fxcommand.cpp index 0ea8a78..e21e9ae 100644 --- a/toonz/sources/toonzlib/fxcommand.cpp +++ b/toonz/sources/toonzlib/fxcommand.cpp @@ -36,7 +36,6 @@ #include "tcg/tcg_macros.h" #include "tcg/tcg_base.h" #include "tcg/tcg_function_types.h" -#include "tcg/tcg_iterator_ops.h" #include @@ -2366,12 +2365,10 @@ static void deleteColumns(const std::list &columns, // columns directly, and then their (updated) column index. TXsheet *xsh = xshHandle->getXsheet(); - typedef tcg::function - getColumn_fun; - tcg::binder1st getCol(getColumn_fun(), *xsh); - - std::vector cols(tcg::make_cast_it(columns.begin(), getCol), - tcg::make_cast_it(columns.end(), getCol)); + std::vector cols; + for (auto const &c : columns) { + cols.push_back(xsh->getColumn(c)); + } size_t c, cCount = cols.size(); for (c = 0; c != cCount; ++c) { @@ -3107,20 +3104,6 @@ private: //====================================================== void UndoDisconnectFxs::initialize() { - struct locals { - static QPair originalPos(const QPair &pair) { - return QPair(pair.first, - pair.first->getAttributes()->getDagNodePos()); - } - - static bool contains(const std::list &fxs, TFx *fx) { - tcg::function getPointer_fun; - - return (std::count(tcg::make_cast_it(fxs.begin(), getPointer_fun), - tcg::make_cast_it(fxs.end(), getPointer_fun), fx) > 0); - } - }; - TXsheet *xsh = m_xshHandle->getXsheet(); FxDag *fxDag = xsh->getFxDag(); @@ -3132,13 +3115,15 @@ void UndoDisconnectFxs::initialize() { if (m_fxs.empty()) return; // Build fxs data - tcg::binder1st &, TFx *)> contains_fun( - &locals::contains, m_fxs); + auto const contains = [this](TFx const *fx) -> bool { + return std::count_if(this->m_fxs.begin(), this->m_fxs.end(), + [fx](TFxP &f) { return f.getPointer() == fx; }) > 0; + }; - m_leftFx = FxCommandUndo::leftmostConnectedFx(m_fxs.front().getPointer(), - contains_fun); - m_rightFx = FxCommandUndo::rightmostConnectedFx(m_fxs.front().getPointer(), - contains_fun); + m_leftFx = + FxCommandUndo::leftmostConnectedFx(m_fxs.front().getPointer(), contains); + m_rightFx = + FxCommandUndo::rightmostConnectedFx(m_fxs.front().getPointer(), contains); // Store sensible original data for the undo m_undoLinksIn = FxCommandUndo::inputLinks(xsh, m_leftFx); @@ -3150,10 +3135,12 @@ void UndoDisconnectFxs::initialize() { m_undoTerminalLinks.push_back(TFxCommand::Link(lt->m_inputFx.getPointer(), fxDag->getXsheetFx(), -1)); - std::vector>( - tcg::make_cast_it(m_undoDagPos.begin(), &locals::originalPos), - tcg::make_cast_it(m_undoDagPos.end(), &locals::originalPos)) - .swap(m_redoDagPos); + std::vector> v; + for (auto const &e : m_undoDagPos) { + v.emplace_back(e.first, e.first->getAttributes()->getDagNodePos()); + } + m_redoDagPos = std::move(v); + m_redoDagPos.shrink_to_fit(); } //------------------------------------------------------