+ size_t iPrev = 0;
+ sortedPos.insert( std::make_pair( theListToSort.size(), sortedPos.size() ));
+ for ( const auto & pos_order : sortedPos )
+ {
+ const size_t& posInList = pos_order.first;
+ const size_t& order = pos_order.second;
+ if ( order < sortedPos.size() - 1 )
+ orderedSM[ order ] = theListToSort[ posInList ];
+
+ if ( iPrev < posInList )
+ orderedSM.insert( orderedSM.end(),
+ theListToSort.begin() + iPrev,
+ theListToSort.begin() + posInList );
+ iPrev = posInList + 1;
+ }
+
+ theListToSort.swap( orderedSM );
+
+ return true;