From: Timo Heister Date: Fri, 20 Oct 2017 21:01:47 +0000 (-0400) Subject: pass std::function by const reference X-Git-Tag: v9.0.0-rc1~919^2 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c77d4ff74f7c6728745b3b291c937aeb3bbfc2dd;p=dealii.git pass std::function by const reference I think a std::function should be passed by const reference, unless we are planning on storing a copy (then by value and move). --- diff --git a/include/deal.II/base/thread_management.h b/include/deal.II/base/thread_management.h index 263b8b3bf9..0db3bbbc99 100644 --- a/include/deal.II/base/thread_management.h +++ b/include/deal.II/base/thread_management.h @@ -893,7 +893,7 @@ namespace Threads * The function that runs on the thread. */ static - void thread_entry_point (const std::function function, + void thread_entry_point (const std::function &function, std::shared_ptr > ret_val) { // call the function in question. since an exception that is diff --git a/include/deal.II/base/time_stepping.h b/include/deal.II/base/time_stepping.h index 73657368ad..781b8b58a6 100644 --- a/include/deal.II/base/time_stepping.h +++ b/include/deal.II/base/time_stepping.h @@ -165,8 +165,8 @@ namespace TimeStepping * evolve_one_time_step returns the time at the end of the time step. */ virtual double evolve_one_time_step - (std::function f, - std::function id_minus_tau_J_inverse, + (const std::function &f, + const std::function &id_minus_tau_J_inverse, double t, double delta_t, VectorType &y) = 0; @@ -234,8 +234,8 @@ namespace TimeStepping * end of the time step. */ double evolve_one_time_step - (std::function f, - std::function id_minus_tau_J_inverse, + (const std::function &f, + const std::function &id_minus_tau_J_inverse, double t, double delta_t, VectorType &y); @@ -248,7 +248,7 @@ namespace TimeStepping * step. */ double evolve_one_time_step - (std::function f, + (const std::function &f, double t, double delta_t, VectorType &y); @@ -276,7 +276,7 @@ namespace TimeStepping * Compute the different stages needed. */ void compute_stages - (std::function f, + (const std::function &f, const double t, const double delta_t, const VectorType &y, @@ -333,11 +333,11 @@ namespace TimeStepping * returns the time at the end of the time step. */ double evolve_one_time_step - (std::function f, - std::function id_minus_tau_J_inverse, - double t, - double delta_t, - VectorType &y); + (const std::function &f, + const std::function &id_minus_tau_J_inverse, + double t, + double delta_t, + VectorType &y); /** * Set the maximum number of iterations and the tolerance used by the @@ -374,30 +374,30 @@ namespace TimeStepping * Compute the different stages needed. */ void compute_stages - (std::function f, - std::function id_minus_tau_J_inverse, - double t, - double delta_t, - VectorType &y, + (const std::function &f, + const std::function &id_minus_tau_J_inverse, + double t, + double delta_t, + VectorType &y, std::vector &f_stages); /** * Newton solver used for the implicit stages. */ - void newton_solve(std::function get_residual, - std::function id_minus_tau_J_inverse, - VectorType &y); + void newton_solve(const std::function &get_residual, + const std::function &id_minus_tau_J_inverse, + VectorType &y); /** * Compute the residual needed by the Newton solver. */ - void compute_residual(std::function f, - double t, - double delta_t, - const VectorType &new_y, - const VectorType &y, - VectorType &tendency, - VectorType &residual) const; + void compute_residual(const std::function &f, + double t, + double delta_t, + const VectorType &new_y, + const VectorType &y, + VectorType &tendency, + VectorType &residual) const; /** * When using SDIRK, there is no need to compute the linear combination of @@ -483,8 +483,8 @@ namespace TimeStepping * at the end of the time step. */ double evolve_one_time_step - (std::function f, - std::function id_minus_tau_J_inverse, + (const std::function &f, + const std::function &id_minus_tau_J_inverse, double t, double delta_t, VectorType &y); @@ -497,7 +497,7 @@ namespace TimeStepping * step. */ double evolve_one_time_step - (std::function f, + (const std::function &f, double t, double delta_t, VectorType &y); @@ -536,7 +536,7 @@ namespace TimeStepping /** * Compute the different stages needed. */ - void compute_stages(std::function f, + void compute_stages(const std::function &f, const double t, const double delta_t, const VectorType &y, diff --git a/include/deal.II/base/time_stepping.templates.h b/include/deal.II/base/time_stepping.templates.h index 8d1538025a..c3f0cfd4bd 100644 --- a/include/deal.II/base/time_stepping.templates.h +++ b/include/deal.II/base/time_stepping.templates.h @@ -138,8 +138,8 @@ namespace TimeStepping template double ExplicitRungeKutta::evolve_one_time_step - (std::function f, - std::function /*id_minus_tau_J_inverse*/, + (const std::function &f, + const std::function &/*id_minus_tau_J_inverse*/, double t, double delta_t, VectorType &y) @@ -151,7 +151,7 @@ namespace TimeStepping template double ExplicitRungeKutta::evolve_one_time_step - (std::function f, + (const std::function &f, double t, double delta_t, VectorType &y) @@ -179,7 +179,7 @@ namespace TimeStepping template void ExplicitRungeKutta::compute_stages - (std::function f, + (const std::function &f, const double t, const double delta_t, const VectorType &y, @@ -281,8 +281,8 @@ namespace TimeStepping template double ImplicitRungeKutta::evolve_one_time_step - (std::function f, - std::function id_minus_tau_J_inverse, + (const std::function &f, + const std::function &id_minus_tau_J_inverse, double t, double delta_t, VectorType &y) @@ -324,8 +324,8 @@ namespace TimeStepping template void ImplicitRungeKutta::compute_stages( - std::function f, - std::function id_minus_tau_J_inverse, + const std::function &f, + const std::function &id_minus_tau_J_inverse, double t, double delta_t, VectorType &y, @@ -351,8 +351,8 @@ namespace TimeStepping template void ImplicitRungeKutta::newton_solve( - std::function get_residual, - std::function id_minus_tau_J_inverse, + const std::function &get_residual, + const std::function &id_minus_tau_J_inverse, VectorType &y) { VectorType residual(y); @@ -377,7 +377,7 @@ namespace TimeStepping template void ImplicitRungeKutta::compute_residual - (std::function f, + (const std::function &f, double t, double delta_t, const VectorType &old_y, @@ -675,8 +675,8 @@ namespace TimeStepping template double EmbeddedExplicitRungeKutta::evolve_one_time_step( - std::function f, - std::function /*id_minus_tau_J_inverse*/, + const std::function &f, + const std::function &/*id_minus_tau_J_inverse*/, double t, double delta_t, VectorType &y) @@ -688,7 +688,7 @@ namespace TimeStepping template double EmbeddedExplicitRungeKutta::evolve_one_time_step( - std::function f, + const std::function &f, double t, double delta_t, VectorType &y) { bool done = false; @@ -804,7 +804,7 @@ namespace TimeStepping template void EmbeddedExplicitRungeKutta::compute_stages( - std::function f, + const std::function &f, const double t, const double delta_t, const VectorType &y, diff --git a/include/deal.II/distributed/grid_tools.h b/include/deal.II/distributed/grid_tools.h index 5e3a0203e3..5c48895bf3 100644 --- a/include/deal.II/distributed/grid_tools.h +++ b/include/deal.II/distributed/grid_tools.h @@ -128,8 +128,8 @@ namespace parallel template void exchange_cell_data_to_ghosts (const MeshType &mesh, - std::function (const typename MeshType::active_cell_iterator &)> pack, - std::function unpack); + const std::function (const typename MeshType::active_cell_iterator &)> &pack, + const std::function &unpack); } @@ -260,8 +260,8 @@ namespace parallel template void exchange_cell_data_to_ghosts (const MeshType &mesh, - std::function (const typename MeshType::active_cell_iterator &)> pack, - std::function unpack) + const std::function (const typename MeshType::active_cell_iterator &)> &pack, + const std::function &unpack) { #ifndef DEAL_II_WITH_MPI (void)mesh; diff --git a/include/deal.II/numerics/vector_tools.h b/include/deal.II/numerics/vector_tools.h index 84036616a1..2fa2ba5250 100644 --- a/include/deal.II/numerics/vector_tools.h +++ b/include/deal.II/numerics/vector_tools.h @@ -897,7 +897,7 @@ namespace VectorTools const DoFHandler &dof, const ConstraintMatrix &constraints, const Quadrature &quadrature, - const std::function< typename VectorType::value_type (const typename DoFHandler::active_cell_iterator &, const unsigned int)> func, + const std::function< typename VectorType::value_type (const typename DoFHandler::active_cell_iterator &, const unsigned int)> &func, VectorType &vec_result); /** @@ -924,7 +924,7 @@ namespace VectorTools void project (std::shared_ptr > data, const ConstraintMatrix &constraints, const unsigned int n_q_points_1d, - const std::function< VectorizedArray (const unsigned int, const unsigned int)> func, + const std::function< VectorizedArray (const unsigned int, const unsigned int)> &func, VectorType &vec_result); /** @@ -933,7 +933,7 @@ namespace VectorTools template void project (std::shared_ptr > data, const ConstraintMatrix &constraints, - const std::function< VectorizedArray (const unsigned int, const unsigned int)> func, + const std::function< VectorizedArray (const unsigned int, const unsigned int)> &func, VectorType &vec_result); /** diff --git a/include/deal.II/numerics/vector_tools.templates.h b/include/deal.II/numerics/vector_tools.templates.h index 9332a367e4..7db3343eeb 100644 --- a/include/deal.II/numerics/vector_tools.templates.h +++ b/include/deal.II/numerics/vector_tools.templates.h @@ -1262,7 +1262,7 @@ namespace VectorTools const DoFHandler &dof, const ConstraintMatrix &constraints, const Quadrature &quadrature, - const std::function< typename VectorType::value_type (const typename DoFHandler::active_cell_iterator &, const unsigned int)> func, + const std::function< typename VectorType::value_type (const typename DoFHandler::active_cell_iterator &, const unsigned int)> &func, VectorType &vec_result) { typedef typename VectorType::value_type Number; @@ -1360,7 +1360,7 @@ namespace VectorTools template void project_parallel (std::shared_ptr > matrix_free, const ConstraintMatrix &constraints, - const std::function< VectorizedArray (const unsigned int, const unsigned int)> func, + const std::function< VectorizedArray (const unsigned int, const unsigned int)> &func, VectorType &vec_result) { const DoFHandler &dof = matrix_free->get_dof_handler(); @@ -1438,7 +1438,7 @@ namespace VectorTools const DoFHandler &dof, const ConstraintMatrix &constraints, const Quadrature &quadrature, - const std::function< typename VectorType::value_type (const typename DoFHandler::active_cell_iterator &, const unsigned int)> func, + const std::function< typename VectorType::value_type (const typename DoFHandler::active_cell_iterator &, const unsigned int)> &func, VectorType &vec_result) { switch (dof.get_fe().degree) @@ -1463,7 +1463,7 @@ namespace VectorTools void project (std::shared_ptr > matrix_free, const ConstraintMatrix &constraints, const unsigned int n_q_points_1d, - const std::function< VectorizedArray (const unsigned int, const unsigned int)> func, + const std::function< VectorizedArray (const unsigned int, const unsigned int)> &func, VectorType &vec_result) { (void) n_q_points_1d; @@ -1493,7 +1493,7 @@ namespace VectorTools template void project (std::shared_ptr > matrix_free, const ConstraintMatrix &constraints, - const std::function< VectorizedArray (const unsigned int, const unsigned int)> func, + const std::function< VectorizedArray (const unsigned int, const unsigned int)> &func, VectorType &vec_result) { project (matrix_free, diff --git a/source/numerics/vector_tools_project_qp.inst.in b/source/numerics/vector_tools_project_qp.inst.in index 966e05d837..4f51630a74 100644 --- a/source/numerics/vector_tools_project_qp.inst.in +++ b/source/numerics/vector_tools_project_qp.inst.in @@ -23,7 +23,7 @@ for (VEC: REAL_NONBLOCK_VECTORS; deal_II_dimension : DIMENSIONS) const DoFHandler &, const ConstraintMatrix &, const Quadrature &, - const std::function::active_cell_iterator &, const unsigned int)>, + const std::function::active_cell_iterator &, const unsigned int)> &, VEC &); \} diff --git a/source/numerics/vector_tools_project_qpmf.inst.in b/source/numerics/vector_tools_project_qpmf.inst.in index 234a485a7d..3b9c0968c6 100644 --- a/source/numerics/vector_tools_project_qpmf.inst.in +++ b/source/numerics/vector_tools_project_qpmf.inst.in @@ -23,7 +23,7 @@ for (VEC: REAL_NONBLOCK_VECTORS; deal_II_dimension : DIMENSIONS) void project( std::shared_ptr > matrix_free, const ConstraintMatrix &constraints, - const std::function< VectorizedArray (const unsigned int, const unsigned int)>, + const std::function< VectorizedArray (const unsigned int, const unsigned int)> &, VEC &); template @@ -31,7 +31,7 @@ for (VEC: REAL_NONBLOCK_VECTORS; deal_II_dimension : DIMENSIONS) std::shared_ptr > matrix_free, const ConstraintMatrix &constraints, const unsigned int, - const std::function< VectorizedArray (const unsigned int, const unsigned int)>, + const std::function< VectorizedArray (const unsigned int, const unsigned int)> &, VEC &); \}