From 09080cf911cae5c7faaf8573e82c899903e7b9fc Mon Sep 17 00:00:00 2001 From: Dmitri Naumov <github@naumov.de> Date: Tue, 9 Mar 2021 23:05:24 +0100 Subject: [PATCH] Use std::optional specific functions and helpers. boost::none -> std::nullopt boost::make_optional -> std::make_optional boost::optional<T>::get() -> std::optional<T>::value() --- Applications/FileIO/AsciiRasterInterface.cpp | 4 ++-- BaseLib/Algorithm.h | 2 +- BaseLib/ConfigTree-impl.h | 12 ++++++------ BaseLib/ConfigTree.cpp | 2 +- GeoLib/SurfaceGrid.cpp | 2 +- MaterialLib/PorousMedium/PorousMediaProperties.cpp | 2 +- MaterialLib/SolidModels/MFront/MFront.cpp | 2 +- MeshLib/IO/MPI_IO/PropertyVectorMetaData.h | 12 ++++++------ ParameterLib/FunctionParameter.h | 2 +- ParameterLib/GroupBasedParameter.h | 2 +- ParameterLib/Parameter.h | 2 +- ParameterLib/SpatialPosition.h | 8 ++++---- .../NeumannBoundaryConditionLocalAssembler.h | 2 +- .../RobinBoundaryConditionLocalAssembler.h | 2 +- .../PorousMediaProperties.cpp | 2 +- ProcessLib/RichardsMechanics/RichardsMechanicsFEM.h | 2 +- ProcessLib/SmallDeformation/SmallDeformationFEM.h | 2 +- ProcessLib/SourceTerms/VolumetricSourceTermFEM.h | 2 +- .../ThermalTwoPhaseFlowWithPPLocalAssembler-impl.h | 2 +- ProcessLib/ThermoMechanics/ThermoMechanicsFEM.h | 2 +- .../ThermoRichardsMechanicsFEM.h | 2 +- .../TwoPhaseFlowWithPrhoLocalAssembler-impl.h | 2 +- Tests/MaterialLib/MFront.cpp | 6 +++--- Tests/MeshLib/ConvertToLinearMesh.cpp | 8 ++++---- Tests/NumLib/TestODEInt.cpp | 2 +- 25 files changed, 44 insertions(+), 44 deletions(-) diff --git a/Applications/FileIO/AsciiRasterInterface.cpp b/Applications/FileIO/AsciiRasterInterface.cpp index 2c54be6a105..107c417c90f 100644 --- a/Applications/FileIO/AsciiRasterInterface.cpp +++ b/Applications/FileIO/AsciiRasterInterface.cpp @@ -286,7 +286,7 @@ std::optional<std::vector<GeoLib::Raster const*>> readRasters( { if (!allRastersExist(raster_paths)) { - return boost::none; + return std::nullopt; } std::vector<GeoLib::Raster const*> rasters; @@ -295,6 +295,6 @@ std::optional<std::vector<GeoLib::Raster const*>> readRasters( std::back_inserter(rasters), [](auto const& path) { return FileIO::AsciiRasterInterface::readRaster(path); }); - return boost::make_optional(rasters); + return std::make_optional(rasters); } } // end namespace FileIO diff --git a/BaseLib/Algorithm.h b/BaseLib/Algorithm.h index b7ebba8c49e..edfb6046759 100644 --- a/BaseLib/Algorithm.h +++ b/BaseLib/Algorithm.h @@ -278,7 +278,7 @@ std::optional<typename Container::value_type> findFirstNotEqualElement( [&element](typename Container::value_type const& e) { return e == element; }); - return it == container.end() ? boost::none : boost::make_optional(*it); + return it == container.end() ? std::nullopt : std::make_optional(*it); } /// Returns the index of first element in container or, if the element is not diff --git a/BaseLib/ConfigTree-impl.h b/BaseLib/ConfigTree-impl.h index 54f4e610efd..3b7191313ae 100644 --- a/BaseLib/ConfigTree-impl.h +++ b/BaseLib/ConfigTree-impl.h @@ -79,7 +79,7 @@ std::optional<T> ConfigTree::getConfigParameterOptionalImpl( return p->getValue<T>(); } - return boost::none; + return std::nullopt; } template <typename T> @@ -103,13 +103,13 @@ std::optional<std::vector<T>> ConfigTree::getConfigParameterOptionalImpl( "' not convertible to a vector of the desired type." " Could not convert token no. " + std::to_string(result.size() + 1) + "."); - return boost::none; + return std::nullopt; } - return boost::make_optional(result); + return std::make_optional(result); } - return boost::none; + return std::nullopt; } template<typename T> @@ -225,7 +225,7 @@ std::optional<T> ConfigTree::getConfigAttributeOptional( if (auto a = attrs->get_child_optional(attr)) { ++ct.count; // count only if attribute has been found if (auto v = a->get_value_optional<T>()) { - return v; + return std::make_optional(*v); } error("Value for XML attribute '" + attr + "' `" + shortString(a->data()) + @@ -233,7 +233,7 @@ std::optional<T> ConfigTree::getConfigAttributeOptional( } } - return boost::none; + return std::nullopt; } template<typename T> diff --git a/BaseLib/ConfigTree.cpp b/BaseLib/ConfigTree.cpp index dda172e81cb..e99c2770991 100644 --- a/BaseLib/ConfigTree.cpp +++ b/BaseLib/ConfigTree.cpp @@ -165,7 +165,7 @@ std::optional<ConfigTree> ConfigTree::getConfigSubtreeOptional( return ConfigTree(*subtree, *this, root); } markVisited(root, Attr::TAG, true); - return boost::none; + return std::nullopt; } Range<ConfigTree::SubtreeIterator> diff --git a/GeoLib/SurfaceGrid.cpp b/GeoLib/SurfaceGrid.cpp index 253283426b8..c48462e6616 100644 --- a/GeoLib/SurfaceGrid.cpp +++ b/GeoLib/SurfaceGrid.cpp @@ -209,7 +209,7 @@ bool SurfaceGrid::isPointInSurface(MathLib::Point3d const& pnt, if (!optional_c) { return false; } - std::array<std::size_t,3> c(optional_c.get()); + std::array<std::size_t, 3> c(optional_c.value()); std::size_t const grid_cell_idx(c[0]+c[1]*_n_steps[0]+c[2]*_n_steps[0]*_n_steps[1]); std::vector<Triangle const*> const& triangles(_triangles_in_grid_box[grid_cell_idx]); diff --git a/MaterialLib/PorousMedium/PorousMediaProperties.cpp b/MaterialLib/PorousMedium/PorousMediaProperties.cpp index 798abf5214c..a9a47d702dd 100644 --- a/MaterialLib/PorousMedium/PorousMediaProperties.cpp +++ b/MaterialLib/PorousMedium/PorousMediaProperties.cpp @@ -17,7 +17,7 @@ namespace PorousMedium int PorousMediaProperties::getMaterialID( ParameterLib::SpatialPosition const& pos) const { - return _material_ids ? (*_material_ids)[pos.getElementID().get()] : 0; + return _material_ids ? (*_material_ids)[pos.getElementID().value()] : 0; } MaterialLib::PorousMedium::Porosity const& PorousMediaProperties::getPorosity( diff --git a/MaterialLib/SolidModels/MFront/MFront.cpp b/MaterialLib/SolidModels/MFront/MFront.cpp index f5fb7f716e9..4476181ef2f 100644 --- a/MaterialLib/SolidModels/MFront/MFront.cpp +++ b/MaterialLib/SolidModels/MFront/MFront.cpp @@ -179,7 +179,7 @@ MFront<DisplacementDim>::MFront( getEquivalentPlasticStrainOffset(_behaviour)), _material_properties(std::move(material_properties)), _local_coordinate_system( - local_coordinate_system ? &local_coordinate_system.get() : nullptr) + local_coordinate_system ? &local_coordinate_system.value() : nullptr) { auto const hypothesis = behaviour.hypothesis; diff --git a/MeshLib/IO/MPI_IO/PropertyVectorMetaData.h b/MeshLib/IO/MPI_IO/PropertyVectorMetaData.h index 4e2f9d2a0b3..d7e03d431e0 100644 --- a/MeshLib/IO/MPI_IO/PropertyVectorMetaData.h +++ b/MeshLib/IO/MPI_IO/PropertyVectorMetaData.h @@ -92,24 +92,24 @@ inline std::optional<PropertyVectorMetaData> readPropertyVectorMetaData( char *dummy = new char[s]; if (!is.read(dummy, s)) { - return boost::none; + return std::nullopt; } pvmd.property_name = std::string(dummy, s); delete [] dummy; if(!is.read(reinterpret_cast<char*>(&pvmd.is_int_type), sizeof(bool))) - return boost::none; + return std::nullopt; if(!is.read(reinterpret_cast<char*>(&pvmd.is_data_type_signed), sizeof(bool))) - return boost::none; + return std::nullopt; if(!is.read(reinterpret_cast<char*>(&pvmd.data_type_size_in_bytes), sizeof(unsigned long))) - return boost::none; + return std::nullopt; if(!is.read(reinterpret_cast<char*>(&pvmd.number_of_components), sizeof(unsigned long))) - return boost::none; + return std::nullopt; if(!is.read(reinterpret_cast<char*>(&pvmd.number_of_tuples), sizeof(unsigned long))) - return boost::none; + return std::nullopt; return std::optional<PropertyVectorMetaData>(pvmd); } diff --git a/ParameterLib/FunctionParameter.h b/ParameterLib/FunctionParameter.h index 377d6c71a16..69d1e0c9428 100644 --- a/ParameterLib/FunctionParameter.h +++ b/ParameterLib/FunctionParameter.h @@ -120,7 +120,7 @@ struct FunctionParameter final : public Parameter<T> "FunctionParameter: The spatial position has to be set by " "coordinates."); } - auto const coords = pos.getCoordinates().get(); + auto const coords = pos.getCoordinates().value(); x = coords[0]; y = coords[1]; z = coords[2]; diff --git a/ParameterLib/GroupBasedParameter.h b/ParameterLib/GroupBasedParameter.h index f18a1d820c5..627293178c0 100644 --- a/ParameterLib/GroupBasedParameter.h +++ b/ParameterLib/GroupBasedParameter.h @@ -63,7 +63,7 @@ struct GroupBasedParameter final : public Parameter<T> { auto const item_id = getMeshItemID(pos, type<MeshItemType>()); assert(item_id); - int const index = _property_index[item_id.get()]; + int const index = _property_index[item_id.value()]; auto const& values = _vec_values[index]; if (values.empty()) { diff --git a/ParameterLib/Parameter.h b/ParameterLib/Parameter.h index 337e6087a0a..197db43c68f 100644 --- a/ParameterLib/Parameter.h +++ b/ParameterLib/Parameter.h @@ -174,7 +174,7 @@ struct Parameter : public ParameterBase for (int i = 0; i < n_nodes; ++i) { x_position.setAll( - nodes[i]->getID(), element.getID(), boost::none, *nodes[i]); + nodes[i]->getID(), element.getID(), std::nullopt, *nodes[i]); auto const& values = this->operator()(t, x_position); auto const row_values = Eigen::Map<Eigen::Matrix<T, Eigen::Dynamic, 1> const>( diff --git a/ParameterLib/SpatialPosition.h b/ParameterLib/SpatialPosition.h index 75e8080c0d6..da2709ecc08 100644 --- a/ParameterLib/SpatialPosition.h +++ b/ParameterLib/SpatialPosition.h @@ -89,10 +89,10 @@ public: void clear() { - _node_id = boost::none; - _element_id = boost::none; - _integration_point = boost::none; - _coordinates = boost::none; + _node_id = std::nullopt; + _element_id = std::nullopt; + _integration_point = std::nullopt; + _coordinates = std::nullopt; } private: diff --git a/ProcessLib/BoundaryCondition/NeumannBoundaryConditionLocalAssembler.h b/ProcessLib/BoundaryCondition/NeumannBoundaryConditionLocalAssembler.h index 990c1361cdb..11bf2f6e97f 100644 --- a/ProcessLib/BoundaryCondition/NeumannBoundaryConditionLocalAssembler.h +++ b/ProcessLib/BoundaryCondition/NeumannBoundaryConditionLocalAssembler.h @@ -76,7 +76,7 @@ public: auto const& w = ip_data.weight; ParameterLib::SpatialPosition const position{ - boost::none, Base::_element.getID(), ip, + std::nullopt, Base::_element.getID(), ip, MathLib::Point3d( NumLib::interpolateCoordinates<ShapeFunction, ShapeMatricesType>( diff --git a/ProcessLib/BoundaryCondition/RobinBoundaryConditionLocalAssembler.h b/ProcessLib/BoundaryCondition/RobinBoundaryConditionLocalAssembler.h index dae3ed423ee..3698b84db5e 100644 --- a/ProcessLib/BoundaryCondition/RobinBoundaryConditionLocalAssembler.h +++ b/ProcessLib/BoundaryCondition/RobinBoundaryConditionLocalAssembler.h @@ -73,7 +73,7 @@ public: auto const& w = ip_data.weight; ParameterLib::SpatialPosition const position{ - boost::none, Base::_element.getID(), ip, + std::nullopt, Base::_element.getID(), ip, MathLib::Point3d( NumLib::interpolateCoordinates<ShapeFunction, ShapeMatricesType>( diff --git a/ProcessLib/RichardsComponentTransport/PorousMediaProperties.cpp b/ProcessLib/RichardsComponentTransport/PorousMediaProperties.cpp index b6aec9ba1b9..c8f8f0cfafe 100644 --- a/ProcessLib/RichardsComponentTransport/PorousMediaProperties.cpp +++ b/ProcessLib/RichardsComponentTransport/PorousMediaProperties.cpp @@ -17,7 +17,7 @@ namespace RichardsComponentTransport int PorousMediaProperties::getMaterialID( ParameterLib::SpatialPosition const& pos) const { - int const element_id = pos.getElementID().get(); + int const element_id = pos.getElementID().value(); return _material_ids[element_id]; } diff --git a/ProcessLib/RichardsMechanics/RichardsMechanicsFEM.h b/ProcessLib/RichardsMechanics/RichardsMechanicsFEM.h index 1f43d85ee21..5d9c3b56e4e 100644 --- a/ProcessLib/RichardsMechanics/RichardsMechanicsFEM.h +++ b/ProcessLib/RichardsMechanics/RichardsMechanicsFEM.h @@ -130,7 +130,7 @@ public: if (_process_data.initial_stress != nullptr) { ParameterLib::SpatialPosition const x_position{ - boost::none, _element.getID(), ip, + std::nullopt, _element.getID(), ip, MathLib::Point3d(NumLib::interpolateCoordinates< ShapeFunctionDisplacement, ShapeMatricesTypeDisplacement>( diff --git a/ProcessLib/SmallDeformation/SmallDeformationFEM.h b/ProcessLib/SmallDeformation/SmallDeformationFEM.h index 4b254b2f70d..5ac7d11edc9 100644 --- a/ProcessLib/SmallDeformation/SmallDeformationFEM.h +++ b/ProcessLib/SmallDeformation/SmallDeformationFEM.h @@ -207,7 +207,7 @@ public: if (_process_data.initial_stress != nullptr) { ParameterLib::SpatialPosition const x_position{ - boost::none, _element.getID(), ip, + std::nullopt, _element.getID(), ip, MathLib::Point3d( NumLib::interpolateCoordinates<ShapeFunction, ShapeMatricesType>( diff --git a/ProcessLib/SourceTerms/VolumetricSourceTermFEM.h b/ProcessLib/SourceTerms/VolumetricSourceTermFEM.h index 724dbd5fde8..8f750e3bc13 100644 --- a/ProcessLib/SourceTerms/VolumetricSourceTermFEM.h +++ b/ProcessLib/SourceTerms/VolumetricSourceTermFEM.h @@ -92,7 +92,7 @@ public: auto const& w = _ip_data[ip].integration_weight; ParameterLib::SpatialPosition const pos{ - boost::none, _element.getID(), ip, + std::nullopt, _element.getID(), ip, MathLib::Point3d( NumLib::interpolateCoordinates<ShapeFunction, ShapeMatricesType>(_element, diff --git a/ProcessLib/ThermalTwoPhaseFlowWithPP/ThermalTwoPhaseFlowWithPPLocalAssembler-impl.h b/ProcessLib/ThermalTwoPhaseFlowWithPP/ThermalTwoPhaseFlowWithPPLocalAssembler-impl.h index f15da09d7fd..f2660af759c 100644 --- a/ProcessLib/ThermalTwoPhaseFlowWithPP/ThermalTwoPhaseFlowWithPPLocalAssembler-impl.h +++ b/ProcessLib/ThermalTwoPhaseFlowWithPP/ThermalTwoPhaseFlowWithPPLocalAssembler-impl.h @@ -143,7 +143,7 @@ void ThermalTwoPhaseFlowWithPPLocalAssembler< auto const& two_phase_material_model = _process_data.material->getTwoPhaseMaterialModel(); const int material_id = - two_phase_material_model.getMaterialID(pos.getElementID().get()); + two_phase_material_model.getMaterialID(pos.getElementID().value()); auto const num_nodes = ShapeFunction::NPOINTS; auto const pg_nodal_values = diff --git a/ProcessLib/ThermoMechanics/ThermoMechanicsFEM.h b/ProcessLib/ThermoMechanics/ThermoMechanicsFEM.h index f677c9f17a2..1520ffc7a83 100644 --- a/ProcessLib/ThermoMechanics/ThermoMechanicsFEM.h +++ b/ProcessLib/ThermoMechanics/ThermoMechanicsFEM.h @@ -208,7 +208,7 @@ public: if (_process_data.initial_stress != nullptr) { ParameterLib::SpatialPosition const x_position{ - boost::none, _element.getID(), ip, + std::nullopt, _element.getID(), ip, MathLib::Point3d( NumLib::interpolateCoordinates<ShapeFunction, ShapeMatricesType>( diff --git a/ProcessLib/ThermoRichardsMechanics/ThermoRichardsMechanicsFEM.h b/ProcessLib/ThermoRichardsMechanics/ThermoRichardsMechanicsFEM.h index 258424a9703..3ae5241ab53 100644 --- a/ProcessLib/ThermoRichardsMechanics/ThermoRichardsMechanicsFEM.h +++ b/ProcessLib/ThermoRichardsMechanics/ThermoRichardsMechanicsFEM.h @@ -117,7 +117,7 @@ public: if (process_data_.initial_stress != nullptr) { ParameterLib::SpatialPosition const x_position{ - boost::none, element_.getID(), ip, + std::nullopt, element_.getID(), ip, MathLib::Point3d(NumLib::interpolateCoordinates< ShapeFunctionDisplacement, ShapeMatricesTypeDisplacement>( diff --git a/ProcessLib/TwoPhaseFlowWithPrho/TwoPhaseFlowWithPrhoLocalAssembler-impl.h b/ProcessLib/TwoPhaseFlowWithPrho/TwoPhaseFlowWithPrhoLocalAssembler-impl.h index 8b5af543336..5f04e95f03a 100644 --- a/ProcessLib/TwoPhaseFlowWithPrho/TwoPhaseFlowWithPrhoLocalAssembler-impl.h +++ b/ProcessLib/TwoPhaseFlowWithPrho/TwoPhaseFlowWithPrhoLocalAssembler-impl.h @@ -82,7 +82,7 @@ void TwoPhaseFlowWithPrhoLocalAssembler< ParameterLib::SpatialPosition pos; pos.setElementID(_element.getID()); const int material_id = - _process_data._material->getMaterialID(pos.getElementID().get()); + _process_data._material->getMaterialID(pos.getElementID().value()); const Eigen::MatrixXd& perm = _process_data._material->getPermeability( material_id, t, pos, _element.getDimension()); diff --git a/Tests/MaterialLib/MFront.cpp b/Tests/MaterialLib/MFront.cpp index 20b322d14ab..7edd62e5cb4 100644 --- a/Tests/MaterialLib/MFront.cpp +++ b/Tests/MaterialLib/MFront.cpp @@ -56,7 +56,7 @@ struct StandardElasticityBrickBehaviour &young_modulus, &poisson_ratio}; auto result = std::make_unique<MFront::MFront<Dim>>( - std::move(behaviour), std::move(parameters), boost::none); + std::move(behaviour), std::move(parameters), std::nullopt); return result; } }; @@ -77,7 +77,7 @@ struct ElasticBehaviour &young_modulus, &poisson_ratio}; auto result = std::make_unique<MFront::MFront<Dim>>( - std::move(behaviour), std::move(parameters), boost::none); + std::move(behaviour), std::move(parameters), std::nullopt); return result; } }; @@ -110,7 +110,7 @@ struct MohrCoulombAbboSloanBehaviour &tension_cut_off_parameter}; auto result = std::make_unique<MFront::MFront<Dim>>( - std::move(behaviour), std::move(parameters), boost::none); + std::move(behaviour), std::move(parameters), std::nullopt); return result; } }; diff --git a/Tests/MeshLib/ConvertToLinearMesh.cpp b/Tests/MeshLib/ConvertToLinearMesh.cpp index 1eee0f70742..0ecfc479a38 100644 --- a/Tests/MeshLib/ConvertToLinearMesh.cpp +++ b/Tests/MeshLib/ConvertToLinearMesh.cpp @@ -214,7 +214,7 @@ TEST_F(ConvertToLinearMesh, GeneratedHexMeshRandomizedNodes) { auto const result = inversePermutationIdentityTest(permutation, inverse_permutation); - ASSERT_TRUE(result == boost::none) + ASSERT_TRUE(result == std::nullopt) << "Quadratic mesh nodes permutation test failed: " << *result; } @@ -253,7 +253,7 @@ TEST_F(ConvertToLinearMesh, GeneratedHexMeshRandomizedNodes) auto const& element_b = *permuted_nodes_quadratic_mesh.getElement(i); auto const elements_are_equal = equal(element_a, element_b); - ASSERT_TRUE(elements_are_equal == boost::none) + ASSERT_TRUE(elements_are_equal == std::nullopt) << *elements_are_equal << " For the element " << i << "."; } } @@ -285,7 +285,7 @@ TEST_F(ConvertToLinearMesh, GeneratedHexMeshRandomizedNodes) auto const& element_a = *linear_mesh->getElement(i); auto const& element_b = *converted_mesh->getElement(i); auto const elements_are_equal = equal(element_a, element_b); - ASSERT_TRUE(elements_are_equal == boost::none) + ASSERT_TRUE(elements_are_equal == std::nullopt) << *elements_are_equal << " For the element " << i << "."; } } @@ -320,7 +320,7 @@ TEST_F(ConvertToLinearMesh, GeneratedHexMeshBackToLinear) auto const& converted_mesh_element = *converted_mesh->getElement(i); auto const elements_are_equal = equal(linear_mesh_element, converted_mesh_element); - ASSERT_TRUE(elements_are_equal == boost::none) + ASSERT_TRUE(elements_are_equal == std::nullopt) << *elements_are_equal << " For the element " << i << "."; } } diff --git a/Tests/NumLib/TestODEInt.cpp b/Tests/NumLib/TestODEInt.cpp index 47358596b3b..5a1cd51bba5 100644 --- a/Tests/NumLib/TestODEInt.cpp +++ b/Tests/NumLib/TestODEInt.cpp @@ -76,7 +76,7 @@ public: auto linear_solver = createLinearSolver(); auto conv_crit = std::make_unique<NumLib::ConvergenceCriterionDeltaX>( - _tol, boost::none, MathLib::VecNormType::NORM2); + _tol, std::nullopt, MathLib::VecNormType::NORM2); auto nonlinear_solver = std::make_unique<NLSolver>(*linear_solver, _maxiter); -- GitLab