アルゴリズム設計のブラッシュアップと C++11 の学習を同時に行っているときに、次のようなヒープ ソートの実装を思い付きました。
template <typename It, typename Comp> void heapSort(It begin, It end, Comp compFunc, std::random_access_iterator_tag) { std::make_heap(begin, end, compFunc); std::sort_heap(begin, end, compFunc); } template <typename It, typename Comp, typename IterCat> void heapSort(It begin, It end, Comp compFunc, IterCat) { typedef typename It::value_type value_type; std::vector<value_type> randomAccessContainer; randomAccessContainer.reserve(std::distance(begin, end)); std::move(begin, end, std::back_inserter(randomAccessContainer)); heapSort(std::begin(randomAccessContainer), std::end(randomAccessContainer), compFunc, std::random_access_iterator_tag()); std::move(std::begin(randomAccessContainer), std::end(randomAccessContainer), begin); }
[begin, end)
最初に から新しいコンテナに移動し、次にそのコンテナから に戻るのは標準的な C++[begin, end)
ですか?