#pragma once #include "tl/detail/prologue.h" #include "tl/type_traits.h" #include #include #include namespace tl { namespace detail { ////////////////////////////////////////////////////////////////////////// // associative containers (ordered & unordered) [maps, unordered_maps, multimaps, unordered_multimaps ...] template void append(std::true_type, DstContainer& dst, const SrcContainer& src) noexcept { dst.insert(std::begin(src), std::end(src)); } ////////////////////////////////////////////////////////////////////////// // sequence containers [vector, dequeue, forward_list, list, ...] template void append(std::false_type, DstContainer& dst, const SrcContainer& src) noexcept { dst.insert(std::end(dst), std::begin(src), std::end(src)); } ////////////////////////////////////////////////////////////////////////// // Obs: std::forward_list don't support fast traversal to the end // thus going to std::prev(std::end(dst)) must be done manually // Cost: O(N) template void append(std::false_type, std::forward_list& dst, const SrcContainer& src) noexcept { auto before_end = dst.before_begin(); for (auto& _ : dst) ++before_end; dst.insert_after(before_end, std::begin(src), std::end(src)); } ////////////////////////////////////////////////////////////////////////// } // namespace detail ////////////////////////////////////////////////////////////////////////// template void append(DstContainer& dst, const SrcContainer& src) noexcept { detail::append(tl::is_associative_container{}, dst, src); } ////////////////////////////////////////////////////////////////////////// }