From 1ee169b5a1905c4dcb6839b6bc343e4c76e0698c Mon Sep 17 00:00:00 2001
From: Danilo Piparo <danilo.piparo@cern.ch>
Date: Fri, 29 Mar 2019 13:50:45 +0100
Subject: [PATCH] [RVec] Add `Concatenate` helper to "merge" two RVec instances

---
 math/vecops/inc/ROOT/RVec.hxx | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)

diff --git a/math/vecops/inc/ROOT/RVec.hxx b/math/vecops/inc/ROOT/RVec.hxx
index 04ea8348a1f..073b4dff2bf 100644
--- a/math/vecops/inc/ROOT/RVec.hxx
+++ b/math/vecops/inc/ROOT/RVec.hxx
@@ -1408,6 +1408,29 @@ RVec<T> Where(const RVec<int> &c, T v1, T v2)
    return r;
 }
 
+/// Return the concatenation of two RVecs.
+///
+/// Example code, at the ROOT prompt:
+/// ~~~{.cpp}
+/// using namespace ROOT::VecOps;
+/// RVec<float> rvf {0.f, 1.f, 2.f};
+/// RVec<int> rvi {7, 8, 9};
+/// Concatenate(rvf, rvi);
+/// // (ROOT::VecOps::RVec<float>) { 2.0000000, 4.0000000, 4.0000000 }
+/// ~~~
+template <typename T0, typename T1, typename Common_t = typename std::common_type<T0, T1>::type>
+RVec<Common_t> Concatenate(const RVec<T0> &v0, const RVec<T1> &v1)
+{
+   RVec<Common_t> res;
+   res.reserve(v0.size() + v1.size());
+   auto &resAsVect = res.AsVector();
+   auto &v0AsVect = v0.AsVector();
+   auto &v1AsVect = v1.AsVector();
+   resAsVect.insert(resAsVect.begin(), v0AsVect.begin(), v0AsVect.end());
+   resAsVect.insert(resAsVect.end(), v1AsVect.begin(), v1AsVect.end());
+   return res;
+}
+
 ////////////////////////////////////////////////////////////////////////////////
 /// Print a RVec at the prompt:
 template <class T>
-- 
GitLab