--- /dev/null
+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)
--- /dev/null
+// ---------------------------------------------------------------------
+//
+// 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
# 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>
# 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>
* 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.
*
* 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.
*
* @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
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);
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)
cell->index(),
&mesh);
- const boost::optional<DataType> data = pack(mesh_it);
+ const std_cxx17::optional<DataType> data = pack(mesh_it);
if (data)
{
.first;
p->second.cell_ids.emplace_back(cellid);
- p->second.data.emplace_back(data.get());
+ p->second.data.emplace_back(*data);
}
}
}
#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>
#include <deal.II/lac/vector.h>
-#include <boost/optional.hpp>
-
DEAL_II_NAMESPACE_OPEN
/**
* 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;
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::
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(
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::
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);
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::
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(
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
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>>();
}
}
#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>
* 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,
* 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,
* 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,
template <typename NumberType>
- boost::optional<NumberType>
+ std_cxx17::optional<NumberType>
quadratic_fit(const NumberType x1,
const NumberType f1,
const NumberType g1,
template <typename NumberType>
- boost::optional<NumberType>
+ std_cxx17::optional<NumberType>
cubic_fit(const NumberType x1,
const NumberType f1,
const NumberType g1,
template <typename NumberType>
- boost::optional<NumberType>
+ std_cxx17::optional<NumberType>
cubic_fit_three_points(const NumberType x1,
const NumberType f1,
const NumberType g1,
// 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;
// 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;
// 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.
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>>();
}
};
// 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>
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)
{
else
{
deallog << "skipping " << cell->id() << ' ' << counter << std::endl;
- return boost::optional<DT>();
+ return std_cxx17::optional<DT>();
}
},
[&](const cell_iterator &cell, const DT &data) {