Tensor Comprehensions
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
utils-inl.h
Go to the documentation of this file.
1 
16 #pragma once
17 #include <algorithm>
18 #include <iterator>
19 #include <type_traits>
20 #include <vector>
21 
22 namespace tc {
23 namespace autotune {
24 
25 namespace detail {
26 template <typename Vector>
27 void mergeVectorsImpl(Vector&) {}
28 
29 template <typename Vector, typename... Vectors>
30 void mergeVectorsImpl(Vector& sink, Vector&& v, Vectors&&... vs) {
31  mergeVectorsImpl(sink, std::forward<Vectors>(vs)...);
32 
33  if (std::is_rvalue_reference<decltype(v)>::value) {
34  sink.reserve(sink.size() + v.size());
35  std::move(v.begin(), v.end(), std::back_inserter(sink));
36  } else {
37  sink.insert(sink.end(), v.begin(), v.end());
38  }
39 }
40 
41 } // namespace detail
42 
43 template <typename Vector, typename... Vectors>
44 Vector mergeVectors(Vector&& v, Vectors&&... vs) {
45  Vector merged;
47  merged, std::forward<Vector>(v), std::forward<Vectors>(vs)...);
48  std::sort(merged.begin(), merged.end());
49  merged.erase(std::unique(merged.begin(), merged.end()), merged.end());
50  return merged;
51 }
52 
53 } // namespace autotune
54 } // namespace tc
void mergeVectorsImpl(Vector &)
Definition: utils-inl.h:27
Vector mergeVectors(Vector &&v, Vectors &&...vs)
Definition: utils-inl.h:44