Skip to content
Snippets Groups Projects
Commit 1ee169b5 authored by Danilo Piparo's avatar Danilo Piparo
Browse files

[RVec] Add `Concatenate` helper to "merge" two RVec instances

parent 342f495c
No related branches found
No related tags found
No related merge requests found
...@@ -1408,6 +1408,29 @@ RVec<T> Where(const RVec<int> &c, T v1, T v2) ...@@ -1408,6 +1408,29 @@ RVec<T> Where(const RVec<int> &c, T v1, T v2)
return r; 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: /// Print a RVec at the prompt:
template <class T> template <class T>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment