From: Wolfgang Bangerth Date: Thu, 20 Aug 2015 17:42:45 +0000 (-0500) Subject: Clean up a piece of rather awkward code. X-Git-Tag: v8.4.0-rc2~573^2 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3ceed4d7f18a30488e8f469a5db53073e7bd112d;p=dealii.git Clean up a piece of rather awkward code. In particular, avoid initializing const members in the initializer list of the class, then const-casting them and initializing them again. --- diff --git a/source/fe/fe.cc b/source/fe/fe.cc index fd00738656..6401b85777 100644 --- a/source/fe/fe.cc +++ b/source/fe/fe.cc @@ -152,10 +152,10 @@ FiniteElement::InternalDataBase::clear_first_cell () template -FiniteElement::FiniteElement ( - const FiniteElementData &fe_data, - const std::vector &r_i_a_f, - const std::vector &nonzero_c) +FiniteElement:: +FiniteElement (const FiniteElementData &fe_data, + const std::vector &r_i_a_f, + const std::vector &nonzero_c) : FiniteElementData (fe_data), adjust_quad_dof_index_for_face_orientation_table (dim == 3 ? @@ -167,40 +167,21 @@ FiniteElement::FiniteElement ( face_system_to_base_table(this->dofs_per_face), component_to_base_table (this->components, std::make_pair(std::make_pair(0U, 0U), 0U)), - restriction_is_additive_flags(r_i_a_f), - nonzero_components (nonzero_c) -{ - // Special handling of vectors of - // length one: in this case, we - // assume that all entries were - // supposed to be equal. - -//TODO: Do the following in a better way by expanding these arrays in the member initializer section above - // Normally, we should be careful - // with const_cast, but since this - // is the constructor and we do it - // here only, we are fine. - unsigned int ndofs = this->dofs_per_cell; - if (restriction_is_additive_flags.size() == 1 && ndofs > 1) - { - std::vector &aux - = const_cast&> (restriction_is_additive_flags); - aux.resize(ndofs, restriction_is_additive_flags[0]); - } - if (nonzero_components.size() == 1 && ndofs > 1) - { - std::vector &aux - = const_cast&> (nonzero_components); - aux.resize(ndofs, nonzero_components[0]); - } - - // These used to be initialized in - // the constructor, but here we - // have the possibly corrected - // nonzero_components vector. - const_cast&> - (n_nonzero_components_table) = compute_n_nonzero_components(nonzero_components); + // Special handling of vectors of length one: in this case, we + // assume that all entries were supposed to be equal + restriction_is_additive_flags(r_i_a_f.size() == 1 + ? + std::vector (fe_data.dofs_per_cell, r_i_a_f[0]) + : + r_i_a_f), + nonzero_components (nonzero_c.size() == 1 + ? + std::vector (fe_data.dofs_per_cell, nonzero_c[0]) + : + nonzero_c), + n_nonzero_components_table (compute_n_nonzero_components(nonzero_components)) +{ this->set_primitivity(std::find_if (n_nonzero_components_table.begin(), n_nonzero_components_table.end(), std::bind2nd(std::not_equal_to(), @@ -223,7 +204,7 @@ FiniteElement::FiniteElement ( ExcInternalError()); Assert (n_nonzero_components_table[i] <= this->n_components(), ExcInternalError()); - }; + } // initialize some tables in the default way, i.e. if there is only one // (vector-)component; if the element is not primitive, leave these tables