From a902dba9f7d2318e7a7cdc27821a367b968d49e0 Mon Sep 17 00:00:00 2001 From: Lei Qiao Date: Mon, 20 Apr 2015 14:16:44 -0500 Subject: [PATCH] simplify accessing to Vector element. --- examples/step-33/step-33.cc | 23 ++++------------------- 1 file changed, 4 insertions(+), 19 deletions(-) diff --git a/examples/step-33/step-33.cc b/examples/step-33/step-33.cc index bbe74f4719..991cb80db0 100644 --- a/examples/step-33/step-33.cc +++ b/examples/step-33/step-33.cc @@ -172,20 +172,6 @@ namespace Step33 // = \frac{|\rho \mathbf v|^2}{2\rho}$ (note that the independent // variables contain the momentum components $\rho v_i$, not the // velocities $v_i$). - // - // There is one slight problem: We will need to call the following - // functions with input arguments of type - // std::vector@ and - // Vector@. The problem is that the former has an - // access operator operator[] whereas the latter, for - // historical reasons, has operator(). We wouldn't be able to - // write the function in a generic way if we were to use one or the other - // of these. Fortunately, we can use the following trick: instead of - // writing v[i] or v(i), we can use - // *(v.begin() + i), i.e. we generate an iterator that points - // to the ith element, and then dereference it. This works - // for both kinds of vectors -- not the prettiest solution, but one that - // works. template static typename InputVector::value_type @@ -193,9 +179,9 @@ namespace Step33 { typename InputVector::value_type kinetic_energy = 0; for (unsigned int d=0; d