fix bug #3552:

replace std::swap with own code
Merge pull request #2349 from jet47:fix-bug-3552