From: Daniel Arndt Date: Sat, 17 Aug 2019 16:31:54 +0000 (-0400) Subject: Replace boost::optional by std_cxx17::optional X-Git-Tag: v9.2.0-rc1~1224^2 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F8594%2Fhead;p=dealii.git Replace boost::optional by std_cxx17::optional --- diff --git a/doc/news/changes/incompatibilities/20190817DanielArndt b/doc/news/changes/incompatibilities/20190817DanielArndt new file mode 100644 index 0000000000..30b743be5a --- /dev/null +++ b/doc/news/changes/incompatibilities/20190817DanielArndt @@ -0,0 +1,4 @@ +Replaced: boost::optional was replaced by std_cxx17::optional that wraps the +former and std::optional depending on compiler support for C++17. +
+(Daniel Arndt, 2019/08/17) diff --git a/include/deal.II/base/std_cxx17/optional.h b/include/deal.II/base/std_cxx17/optional.h new file mode 100644 index 0000000000..52001f9fbc --- /dev/null +++ b/include/deal.II/base/std_cxx17/optional.h @@ -0,0 +1,37 @@ +// --------------------------------------------------------------------- +// +// Copyright (C) 2019 by the deal.II authors +// +// This file is part of the deal.II library. +// +// The deal.II library is free software; you can use it, redistribute +// it, and/or modify it under the terms of the GNU Lesser General +// Public License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// The full text of the license can be found in the file LICENSE.md at +// the top level directory of deal.II. +// +// --------------------------------------------------------------------- +#ifndef dealii_cxx17_optional_h +#define dealii_cxx17_optional_h + +#include + +#ifdef __cpp_lib_optional +# include +#else +# include +#endif + +DEAL_II_NAMESPACE_OPEN +namespace std_cxx17 +{ +#ifdef __cpp_lib_optional + using std::optional; +#else + using boost::optional; +#endif +} // namespace std_cxx17 +DEAL_II_NAMESPACE_CLOSE + +#endif // dealii_cxx17_optional_h diff --git a/include/deal.II/grid/grid_tools.h b/include/deal.II/grid/grid_tools.h index 095cbb28a7..efb5c414ef 100644 --- a/include/deal.II/grid/grid_tools.h +++ b/include/deal.II/grid/grid_tools.h @@ -21,6 +21,7 @@ # include # include +# include # include @@ -44,7 +45,6 @@ # include # include # include -# include # include # include @@ -2742,12 +2742,12 @@ namespace GridTools * every ghost cell as it was given by @p pack on the owning processor. * Whether you do or do not receive information to @p unpack on a given * ghost cell depends on whether the @p pack function decided that - * something needs to be sent. It does so using the boost::optional - * mechanism: if the boost::optional return object of the @p pack + * something needs to be sent. It does so using the std_cxx17::optional + * mechanism: if the std_cxx17::optional return object of the @p pack * function is empty, then this implies that no data has to be sent for * the locally owned cell it was called on. In that case, @p unpack will * also not be called on the ghost cell that corresponds to it on the - * receiving side. On the other hand, if the boost::optional object is + * receiving side. On the other hand, if the std_cxx17::optional object is * not empty, then the data stored within it will be sent to the received * and the @p unpack function called with it. * @@ -2765,11 +2765,11 @@ namespace GridTools * that is a ghost cell somewhere else. As mentioned above, the function * may return a regular data object of type @p DataType to indicate * that data should be sent, or an empty - * boost::optional@ to indicate that nothing has + * std_cxx17::optional@ to indicate that nothing has * to be sent for this cell. * @param unpack The function that will be called for each ghost cell * for which data was sent, i.e., for which the @p pack function - * on the sending side returned a non-empty boost::optional object. + * on the sending side returned a non-empty std_cxx17::optional object. * The @p unpack function is then called with the data sent by the * processor that owns that cell. * @@ -2804,9 +2804,9 @@ namespace GridTools * @endcode * * You will notice that the @p pack lambda function returns an `unsigned int`, - * not a `boost::optional`. The former converts automatically - * to the latter, implying that data will always be transported to the - * other processor. + * not a `std_cxx17::optional`. The former converts + * automatically to the latter, implying that data will always be transported + * to the other processor. * * (In reality, the @p unpack function needs to be a bit more * complicated because it is not allowed to call @@ -2820,7 +2820,7 @@ namespace GridTools void exchange_cell_data_to_ghosts( const MeshType & mesh, - const std::function( + const std::function( const typename MeshType::active_cell_iterator &)> &pack, const std::function & unpack); @@ -3787,7 +3787,7 @@ namespace GridTools void exchange_cell_data_to_ghosts( const MeshType & mesh, - const std::function( + const std::function( const typename MeshType::active_cell_iterator &)> &pack, const std::function & unpack) @@ -3850,7 +3850,7 @@ namespace GridTools cell->index(), &mesh); - const boost::optional data = pack(mesh_it); + const std_cxx17::optional data = pack(mesh_it); if (data) { @@ -3867,7 +3867,7 @@ namespace GridTools .first; p->second.cell_ids.emplace_back(cellid); - p->second.data.emplace_back(data.get()); + p->second.data.emplace_back(*data); } } } diff --git a/include/deal.II/numerics/fe_field_function.h b/include/deal.II/numerics/fe_field_function.h index 22efd14fee..f6fb6ddb63 100644 --- a/include/deal.II/numerics/fe_field_function.h +++ b/include/deal.II/numerics/fe_field_function.h @@ -18,6 +18,7 @@ #include #include +#include #include #include @@ -30,8 +31,6 @@ #include -#include - DEAL_II_NAMESPACE_OPEN @@ -473,9 +472,9 @@ namespace Functions /** * Given a cell, return the reference coordinates of the given point * within this cell if it indeed lies within the cell. Otherwise return an - * uninitialized boost::optional object. + * uninitialized std_cxx17::optional object. */ - boost::optional> + std_cxx17::optional> get_reference_coordinates( const typename DoFHandlerType::active_cell_iterator &cell, const Point & point) const; diff --git a/include/deal.II/numerics/fe_field_function.templates.h b/include/deal.II/numerics/fe_field_function.templates.h index 0f3b8f614e..8845310e7c 100644 --- a/include/deal.II/numerics/fe_field_function.templates.h +++ b/include/deal.II/numerics/fe_field_function.templates.h @@ -79,7 +79,7 @@ namespace Functions if (cell == dh->end()) cell = dh->begin_active(); - boost::optional> qp = get_reference_coordinates(cell, p); + std_cxx17::optional> qp = get_reference_coordinates(cell, p); if (!qp) { const std::pair quad(qp.get()); + Quadrature quad = *qp; FEValues fe_v(mapping, cell->get_fe(), quad, update_values); fe_v.reinit(cell); std::vector> vvalues( @@ -138,7 +138,7 @@ namespace Functions if (cell == dh->end()) cell = dh->begin_active(); - boost::optional> qp = get_reference_coordinates(cell, p); + std_cxx17::optional> qp = get_reference_coordinates(cell, p); if (!qp) { const std::pair quad(qp.get()); + Quadrature quad = *qp; FEValues fe_v(mapping, cell->get_fe(), quad, update_gradients); fe_v.reinit(cell); @@ -211,7 +211,7 @@ namespace Functions if (cell == dh->end()) cell = dh->begin_active(); - boost::optional> qp = get_reference_coordinates(cell, p); + std_cxx17::optional> qp = get_reference_coordinates(cell, p); if (!qp) { const std::pair quad(qp.get()); + Quadrature quad = *qp; FEValues fe_v(mapping, cell->get_fe(), quad, update_hessians); fe_v.reinit(cell); std::vector> vvalues( @@ -531,7 +531,7 @@ namespace Functions template - boost::optional> + std_cxx17::optional> FEFieldFunction::get_reference_coordinates( const typename DoFHandlerType::active_cell_iterator &cell, const Point & point) const @@ -542,14 +542,14 @@ namespace Functions if (GeometryInfo::is_inside_unit_cell(qp)) return qp; else - return boost::optional>(); + return std_cxx17::optional>(); } catch (const typename Mapping::ExcTransformationFailed &) { // transformation failed, so // assume the point is // outside - return boost::optional>(); + return std_cxx17::optional>(); } } diff --git a/include/deal.II/optimization/line_minimization.h b/include/deal.II/optimization/line_minimization.h index 4c451cb76b..97678acda0 100644 --- a/include/deal.II/optimization/line_minimization.h +++ b/include/deal.II/optimization/line_minimization.h @@ -21,12 +21,11 @@ #include #include #include +#include #include #include -#include - #include #include @@ -50,7 +49,7 @@ namespace LineMinimization * not have a solution for given parameters. */ template - boost::optional + std_cxx17::optional quadratic_fit(const NumberType x_low, const NumberType f_low, const NumberType g_low, @@ -67,7 +66,7 @@ namespace LineMinimization * The return type is optional as the real-valued solution might not exist. */ template - boost::optional + std_cxx17::optional cubic_fit(const NumberType x_low, const NumberType f_low, const NumberType g_low, @@ -83,7 +82,7 @@ namespace LineMinimization * The return type is optional as the real-valued solution might not exist. */ template - boost::optional + std_cxx17::optional cubic_fit_three_points(const NumberType x_low, const NumberType f_low, const NumberType g_low, @@ -353,7 +352,7 @@ namespace LineMinimization template - boost::optional + std_cxx17::optional quadratic_fit(const NumberType x1, const NumberType f1, const NumberType g1, @@ -371,7 +370,7 @@ namespace LineMinimization template - boost::optional + std_cxx17::optional cubic_fit(const NumberType x1, const NumberType f1, const NumberType g1, @@ -398,7 +397,7 @@ namespace LineMinimization template - boost::optional + std_cxx17::optional cubic_fit_three_points(const NumberType x1, const NumberType f1, const NumberType g1, @@ -461,7 +460,7 @@ namespace LineMinimization // https://github.com/scipy/scipy/blob/v1.0.0/scipy/optimize/linesearch.py#L555-L563 // First try cubic interpolation - boost::optional res = cubic_fit(x1, f1, g1, x2, f2, g2); + std_cxx17::optional res = cubic_fit(x1, f1, g1, x2, f2, g2); if (res && *res >= bounds.first && *res <= bounds.second) return *res; @@ -497,7 +496,7 @@ namespace LineMinimization // https://github.com/scipy/scipy/blob/v1.0.0/scipy/optimize/linesearch.py#L555-L563 // First try cubic interpolation after first iteration - boost::optional res = + std_cxx17::optional res = x_rec.size() > 0 ? cubic_fit_three_points(x1, f1, g1, x2, f2, x_rec[0], f_rec[0]) : boost::none; diff --git a/source/dofs/dof_handler_policy.cc b/source/dofs/dof_handler_policy.cc index 08b99293b5..efae49610a 100644 --- a/source/dofs/dof_handler_policy.cc +++ b/source/dofs/dof_handler_policy.cc @@ -4836,7 +4836,7 @@ namespace internal // from elsewhere auto pack = [](const typename DoFHandlerType::active_cell_iterator &cell) - -> boost::optional> { + -> std_cxx17::optional> { Assert(cell->is_locally_owned(), ExcInternalError()); // first see whether we need to do anything at all on this cell. @@ -4887,7 +4887,8 @@ namespace internal local_dof_indices.end()); Assert(is_complete, ExcInternalError()); # endif - return boost::optional>(); + return std_cxx17::optional< + std::vector>(); } }; diff --git a/tests/distributed_grids/grid_tools_exchange_cell_data_04.cc b/tests/distributed_grids/grid_tools_exchange_cell_data_04.cc index 8a86eca7ad..8d82b236b5 100644 --- a/tests/distributed_grids/grid_tools_exchange_cell_data_04.cc +++ b/tests/distributed_grids/grid_tools_exchange_cell_data_04.cc @@ -17,7 +17,7 @@ // test GridTools::exchange_cell_data_to_ghosts // // this test works just like the _01 test, but it skips those cells -// where we have an odd 'counter' value via the boost::optional +// where we have an odd 'counter' value via the std_cxx17::optional // framework #include @@ -54,7 +54,7 @@ test() GridTools:: exchange_cell_data_to_ghosts>( tria, - [&](const cell_iterator &cell) -> boost::optional
{ + [&](const cell_iterator &cell) -> std_cxx17::optional
{ ++counter; if (counter % 2 == 0) { @@ -66,7 +66,7 @@ test() else { deallog << "skipping " << cell->id() << ' ' << counter << std::endl; - return boost::optional
(); + return std_cxx17::optional
(); } }, [&](const cell_iterator &cell, const DT &data) {