Add and use SPL::swap().
authorCarl Hetherington <cth@carlh.net>
Thu, 1 Dec 2022 10:52:33 +0000 (11:52 +0100)
committerCarl Hetherington <cth@carlh.net>
Thu, 1 Dec 2022 10:52:45 +0000 (11:52 +0100)
src/lib/spl.h
src/tools/dcpomatic_playlist.cc

index 49eb93df236f7ab709080e41678e54b8a66db54a..d7c746d1e39d1121bdbfdd3886682d4d05aa7d1e 100644 (file)
@@ -26,6 +26,8 @@
 #include "spl_entry.h"
 #include <dcp/util.h>
 #include <boost/signals2.hpp>
 #include "spl_entry.h"
 #include <dcp/util.h>
 #include <boost/signals2.hpp>
+#include <algorithm>
+
 
 class ContentStore;
 
 
 class ContentStore;
 
@@ -63,6 +65,8 @@ public:
 
        SPLEntry const & operator[] (std::size_t index) const {
                return _spl[index];
 
        SPLEntry const & operator[] (std::size_t index) const {
                return _spl[index];
+       void swap(size_t a, size_t b) {
+               std::iter_swap(_spl.begin() + a, _spl.begin() + b);
        }
 
        void read (boost::filesystem::path path, ContentStore* store);
        }
 
        void read (boost::filesystem::path path, ContentStore* store);
index 9eada8b3820968807aea9297d772c342545d4328..5a8ee91267a9cb27aa65dbc42f828a36fe6257fd 100644 (file)
@@ -402,9 +402,7 @@ private:
 
                DCPOMATIC_ASSERT (_playlist);
 
 
                DCPOMATIC_ASSERT (_playlist);
 
-               auto tmp = (*_playlist)[s];
-               (*_playlist)[s] = (*_playlist)[s-1];
-               (*_playlist)[s-1] = tmp;
+               _playlist->swap(s, s - 1);
 
                set_item (s - 1, (*_playlist)[s-1]);
                set_item (s, (*_playlist)[s]);
 
                set_item (s - 1, (*_playlist)[s-1]);
                set_item (s, (*_playlist)[s]);
@@ -419,9 +417,7 @@ private:
 
                DCPOMATIC_ASSERT (_playlist);
 
 
                DCPOMATIC_ASSERT (_playlist);
 
-               auto tmp = (*_playlist)[s];
-               (*_playlist)[s] = (*_playlist)[s+1];
-               (*_playlist)[s+1] = tmp;
+               _playlist->swap(s, s + 1);
 
                set_item (s + 1, (*_playlist)[s+1]);
                set_item (s, (*_playlist)[s]);
 
                set_item (s + 1, (*_playlist)[s+1]);
                set_item (s, (*_playlist)[s]);