]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Replace boost::optional by std_cxx17::optional 8594/head
authorDaniel Arndt <arndtd@ornl.gov>
Sat, 17 Aug 2019 16:31:54 +0000 (12:31 -0400)
committerDaniel Arndt <arndtd@ornl.gov>
Sun, 18 Aug 2019 02:17:38 +0000 (22:17 -0400)
doc/news/changes/incompatibilities/20190817DanielArndt [new file with mode: 0644]
include/deal.II/base/std_cxx17/optional.h [new file with mode: 0644]
include/deal.II/grid/grid_tools.h
include/deal.II/numerics/fe_field_function.h
include/deal.II/numerics/fe_field_function.templates.h
include/deal.II/optimization/line_minimization.h
source/dofs/dof_handler_policy.cc
tests/distributed_grids/grid_tools_exchange_cell_data_04.cc

diff --git a/doc/news/changes/incompatibilities/20190817DanielArndt b/doc/news/changes/incompatibilities/20190817DanielArndt
new file mode 100644 (file)
index 0000000..30b743b
--- /dev/null
@@ -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.
+<br>
+(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 (file)
index 0000000..52001f9
--- /dev/null
@@ -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 <deal.II/base/config.h>
+
+#ifdef __cpp_lib_optional
+#  include <optional>
+#else
+#  include <boost/optional.hpp>
+#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
index 095cbb28a71b3ab29b73ba913718f15f2bfd0f33..efb5c414ef38ec0a4e442a4747cce23fc0acfa40 100644 (file)
@@ -21,6 +21,7 @@
 
 #  include <deal.II/base/bounding_box.h>
 #  include <deal.II/base/geometry_info.h>
+#  include <deal.II/base/std_cxx17/optional.h>
 
 #  include <deal.II/boost_adaptors/bounding_box.h>
 
@@ -44,7 +45,6 @@
 #  include <boost/archive/binary_oarchive.hpp>
 #  include <boost/geometry/index/detail/serialization.hpp>
 #  include <boost/geometry/index/rtree.hpp>
-#  include <boost/optional.hpp>
 #  include <boost/serialization/array.hpp>
 #  include <boost/serialization/vector.hpp>
 
@@ -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
-   *   <code>boost::optional@<DataType@></code> to indicate that nothing has
+   *   <code>std_cxx17::optional@<DataType@></code> 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<unsigned int>`. The former converts automatically
-   * to the latter, implying that data will always be transported to the
-   * other processor.
+   * not a `std_cxx17::optional<unsigned int>`. 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<boost::optional<DataType>(
+    const std::function<std_cxx17::optional<DataType>(
       const typename MeshType::active_cell_iterator &)> &pack,
     const std::function<void(const typename MeshType::active_cell_iterator &,
                              const DataType &)> &        unpack);
@@ -3787,7 +3787,7 @@ namespace GridTools
   void
   exchange_cell_data_to_ghosts(
     const MeshType &                                     mesh,
-    const std::function<boost::optional<DataType>(
+    const std::function<std_cxx17::optional<DataType>(
       const typename MeshType::active_cell_iterator &)> &pack,
     const std::function<void(const typename MeshType::active_cell_iterator &,
                              const DataType &)> &        unpack)
@@ -3850,7 +3850,7 @@ namespace GridTools
                                                               cell->index(),
                                                               &mesh);
 
-              const boost::optional<DataType> data = pack(mesh_it);
+              const std_cxx17::optional<DataType> 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);
                     }
                 }
             }
index 22efd14feecf703469ec5e6c2494778ee3a5a60f..f6fb6ddb639b36e81547c0d0259e877a930cdd02 100644 (file)
@@ -18,6 +18,7 @@
 
 #include <deal.II/base/function.h>
 #include <deal.II/base/point.h>
+#include <deal.II/base/std_cxx17/optional.h>
 #include <deal.II/base/tensor.h>
 #include <deal.II/base/thread_local_storage.h>
 
@@ -30,8 +31,6 @@
 
 #include <deal.II/lac/vector.h>
 
-#include <boost/optional.hpp>
-
 
 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<Point<dim>>
+    std_cxx17::optional<Point<dim>>
     get_reference_coordinates(
       const typename DoFHandlerType::active_cell_iterator &cell,
       const Point<dim> &                                   point) const;
index 0f3b8f614e40d13d19bc9a328f4db0875d5dd19f..8845310e7cd531eca54746f84edf5dda427be519 100644 (file)
@@ -79,7 +79,7 @@ namespace Functions
     if (cell == dh->end())
       cell = dh->begin_active();
 
-    boost::optional<Point<dim>> qp = get_reference_coordinates(cell, p);
+    std_cxx17::optional<Point<dim>> qp = get_reference_coordinates(cell, p);
     if (!qp)
       {
         const std::pair<typename dealii::internal::
@@ -100,7 +100,7 @@ namespace Functions
                 VectorTools::ExcPointNotAvailableHere());
 
     // Now we can find out about the point
-    Quadrature<dim> quad(qp.get());
+    Quadrature<dim> quad = *qp;
     FEValues<dim>   fe_v(mapping, cell->get_fe(), quad, update_values);
     fe_v.reinit(cell);
     std::vector<Vector<typename VectorType::value_type>> vvalues(
@@ -138,7 +138,7 @@ namespace Functions
     if (cell == dh->end())
       cell = dh->begin_active();
 
-    boost::optional<Point<dim>> qp = get_reference_coordinates(cell, p);
+    std_cxx17::optional<Point<dim>> qp = get_reference_coordinates(cell, p);
     if (!qp)
       {
         const std::pair<typename dealii::internal::
@@ -159,7 +159,7 @@ namespace Functions
     cell_hint.get() = cell;
 
     // Now we can find out about the point
-    Quadrature<dim> quad(qp.get());
+    Quadrature<dim> quad = *qp;
     FEValues<dim>   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<Point<dim>> qp = get_reference_coordinates(cell, p);
+    std_cxx17::optional<Point<dim>> qp = get_reference_coordinates(cell, p);
     if (!qp)
       {
         const std::pair<typename dealii::internal::
@@ -232,7 +232,7 @@ namespace Functions
     cell_hint.get() = cell;
 
     // Now we can find out about the point
-    Quadrature<dim> quad(qp.get());
+    Quadrature<dim> quad = *qp;
     FEValues<dim>   fe_v(mapping, cell->get_fe(), quad, update_hessians);
     fe_v.reinit(cell);
     std::vector<Vector<typename VectorType::value_type>> vvalues(
@@ -531,7 +531,7 @@ namespace Functions
 
 
   template <int dim, typename DoFHandlerType, typename VectorType>
-  boost::optional<Point<dim>>
+  std_cxx17::optional<Point<dim>>
   FEFieldFunction<dim, DoFHandlerType, VectorType>::get_reference_coordinates(
     const typename DoFHandlerType::active_cell_iterator &cell,
     const Point<dim> &                                   point) const
@@ -542,14 +542,14 @@ namespace Functions
         if (GeometryInfo<dim>::is_inside_unit_cell(qp))
           return qp;
         else
-          return boost::optional<Point<dim>>();
+          return std_cxx17::optional<Point<dim>>();
       }
     catch (const typename Mapping<dim>::ExcTransformationFailed &)
       {
         // transformation failed, so
         // assume the point is
         // outside
-        return boost::optional<Point<dim>>();
+        return std_cxx17::optional<Point<dim>>();
       }
   }
 
index 4c451cb76b1b752d52ea907e82a8abe17170e48e..97678acda01ac9d4c135d04f87ee91bacdcf8dc7 100644 (file)
 #include <deal.II/base/exceptions.h>
 #include <deal.II/base/logstream.h>
 #include <deal.II/base/numbers.h>
+#include <deal.II/base/std_cxx17/optional.h>
 #include <deal.II/base/utilities.h>
 
 #include <deal.II/numerics/history.h>
 
-#include <boost/optional.hpp>
-
 #include <errno.h>
 #include <sys/stat.h>
 
@@ -50,7 +49,7 @@ namespace LineMinimization
    * not have a solution for given parameters.
    */
   template <typename NumberType>
-  boost::optional<NumberType>
+  std_cxx17::optional<NumberType>
   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 <typename NumberType>
-  boost::optional<NumberType>
+  std_cxx17::optional<NumberType>
   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 <typename NumberType>
-  boost::optional<NumberType>
+  std_cxx17::optional<NumberType>
   cubic_fit_three_points(const NumberType x_low,
                          const NumberType f_low,
                          const NumberType g_low,
@@ -353,7 +352,7 @@ namespace LineMinimization
 
 
   template <typename NumberType>
-  boost::optional<NumberType>
+  std_cxx17::optional<NumberType>
   quadratic_fit(const NumberType x1,
                 const NumberType f1,
                 const NumberType g1,
@@ -371,7 +370,7 @@ namespace LineMinimization
 
 
   template <typename NumberType>
-  boost::optional<NumberType>
+  std_cxx17::optional<NumberType>
   cubic_fit(const NumberType x1,
             const NumberType f1,
             const NumberType g1,
@@ -398,7 +397,7 @@ namespace LineMinimization
 
 
   template <typename NumberType>
-  boost::optional<NumberType>
+  std_cxx17::optional<NumberType>
   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<NumberType> res = cubic_fit(x1, f1, g1, x2, f2, g2);
+    std_cxx17::optional<NumberType> 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<NumberType> res =
+    std_cxx17::optional<NumberType> res =
       x_rec.size() > 0 ?
         cubic_fit_three_points(x1, f1, g1, x2, f2, x_rec[0], f_rec[0]) :
         boost::none;
index 08b99293b537016ee44d1a1841b98a4a9a0ae3c5..efae49610a5dcbd62699518dd58d6b853478da3c 100644 (file)
@@ -4836,7 +4836,7 @@ namespace internal
           // from elsewhere
           auto pack =
             [](const typename DoFHandlerType::active_cell_iterator &cell)
-            -> boost::optional<std::vector<types::global_dof_index>> {
+            -> std_cxx17::optional<std::vector<types::global_dof_index>> {
             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<std::vector<types::global_dof_index>>();
+                return std_cxx17::optional<
+                  std::vector<types::global_dof_index>>();
               }
           };
 
index 8a86eca7ad23520f22cb705c4bfa47e0db2265e7..8d82b236b58327d251bebe4fc29e283e1ca0ebf3 100644 (file)
@@ -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 <deal.II/base/logstream.h>
@@ -54,7 +54,7 @@ test()
   GridTools::
     exchange_cell_data_to_ghosts<DT, parallel::distributed::Triangulation<dim>>(
       tria,
-      [&](const cell_iterator &cell) -> boost::optional<DT> {
+      [&](const cell_iterator &cell) -> std_cxx17::optional<DT> {
         ++counter;
         if (counter % 2 == 0)
           {
@@ -66,7 +66,7 @@ test()
         else
           {
             deallog << "skipping " << cell->id() << ' ' << counter << std::endl;
-            return boost::optional<DT>();
+            return std_cxx17::optional<DT>();
           }
       },
       [&](const cell_iterator &cell, const DT &data) {

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.