From: David Wells Date: Sat, 12 Jan 2019 01:24:28 +0000 (-0500) Subject: Use emplace_back over an in-place destructor/new. X-Git-Tag: v9.1.0-rc1~444^2 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f25b912f40524342152f235fe65bfdc7ca39e15b;p=dealii.git Use emplace_back over an in-place destructor/new. --- diff --git a/source/fe/fe_values.cc b/source/fe/fe_values.cc index 8f17342c52..0f682e841d 100644 --- a/source/fe/fe_values.cc +++ b/source/fe/fe_values.cc @@ -2642,75 +2642,40 @@ namespace internal { const FiniteElement &fe = fe_values.get_fe(); - // create the views objects: Allocate a bunch of default-constructed ones - // then destroy them again and do in-place construction of those we - // actually want to use. const unsigned int n_scalars = fe.n_components(); - scalars.resize(n_scalars); + scalars.reserve(n_scalars); for (unsigned int component = 0; component < n_scalars; ++component) - { - // Use an alias here to work around an issue with gcc-4.1: - using ScalarView = dealii::FEValuesViews::Scalar; - scalars[component].ScalarView::~ScalarView(); - - new (&scalars[component]) - dealii::FEValuesViews::Scalar(fe_values, component); - } + scalars.emplace_back(fe_values, component); // compute number of vectors that we can fit into this finite element. // note that this is based on the dimensionality 'dim' of the manifold, // not 'spacedim' of the output vector const unsigned int n_vectors = (fe.n_components() >= spacedim ? fe.n_components() - spacedim + 1 : 0); - vectors.resize(n_vectors); + vectors.reserve(n_vectors); for (unsigned int component = 0; component < n_vectors; ++component) - { - // Use an alias here to work around an issue with gcc-4.1: - using VectorView = dealii::FEValuesViews::Vector; - vectors[component].VectorView::~VectorView(); - - new (&vectors[component]) - dealii::FEValuesViews::Vector(fe_values, component); - } + vectors.emplace_back(fe_values, component); // compute number of symmetric tensors in the same way as above const unsigned int n_symmetric_second_order_tensors = (fe.n_components() >= (dim * dim + dim) / 2 ? fe.n_components() - (dim * dim + dim) / 2 + 1 : 0); - symmetric_second_order_tensors.resize(n_symmetric_second_order_tensors); + symmetric_second_order_tensors.reserve(n_symmetric_second_order_tensors); for (unsigned int component = 0; component < n_symmetric_second_order_tensors; ++component) - { - // Use an alias here to work around an issue with gcc-4.1: - using SymmetricTensorView = - dealii::FEValuesViews::SymmetricTensor<2, dim, spacedim>; - symmetric_second_order_tensors[component] - .SymmetricTensorView::~SymmetricTensorView(); - - new (&symmetric_second_order_tensors[component]) - dealii::FEValuesViews::SymmetricTensor<2, dim, spacedim>(fe_values, - component); - } + symmetric_second_order_tensors.emplace_back(fe_values, component); // compute number of symmetric tensors in the same way as above const unsigned int n_second_order_tensors = (fe.n_components() >= dim * dim ? fe.n_components() - dim * dim + 1 : 0); - second_order_tensors.resize(n_second_order_tensors); + second_order_tensors.reserve(n_second_order_tensors); for (unsigned int component = 0; component < n_second_order_tensors; ++component) - { - // Use an alias here to work around an issue with gcc-4.1: - using TensorView = dealii::FEValuesViews::Tensor<2, dim, spacedim>; - second_order_tensors[component].TensorView::~TensorView(); - - new (&second_order_tensors[component]) - dealii::FEValuesViews::Tensor<2, dim, spacedim>(fe_values, - component); - } + second_order_tensors.emplace_back(fe_values, component); } } // namespace FEValuesViews } // namespace internal