From 6a859215f84f4591fc9a0ae8b5804f9ab3ce0ab5 Mon Sep 17 00:00:00 2001 From: Ray Speth Date: Wed, 14 Nov 2018 15:22:23 -0500 Subject: [PATCH] Replace timesConstant with C++11 lambda --- include/cantera/base/utilities.h | 10 ++++++++-- src/thermo/Phase.cpp | 2 +- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/include/cantera/base/utilities.h b/include/cantera/base/utilities.h index a7486e540..32329315b 100644 --- a/include/cantera/base/utilities.h +++ b/include/cantera/base/utilities.h @@ -29,6 +29,8 @@ namespace Cantera /*! * The form of this operator is designed for use by std::transform. * @see @ref scale(). + * + * @deprecated To be removed after Cantera 2.5. Replaceable with C++11 lambda. */ template struct timesConstant : public std::unary_function { //! Constructor @@ -36,7 +38,10 @@ template struct timesConstant : public std::unary_function { * @param c Constant of templated type T that will be stored internally * within the object and used in the multiplication operation */ - timesConstant(T c) : m_c(c) {} + timesConstant(T c) : m_c(c) { + warn_deprecated("class timesConstant", + "To be removed after Cantera 2.5. Replaceable with C++11 lambda."); + } //! Parenthesis operator returning a double /*! @@ -130,7 +135,8 @@ template inline void scale(InputIter begin, InputIter end, OutputIter out, S scale_factor) { - std::transform(begin, end, out, timesConstant(scale_factor)); + std::transform(begin, end, out, + [scale_factor](double x) { return x * scale_factor; }); } //! Multiply each entry in x by the corresponding entry in y. diff --git a/src/thermo/Phase.cpp b/src/thermo/Phase.cpp index ae5ee0ef1..73cbe9818 100644 --- a/src/thermo/Phase.cpp +++ b/src/thermo/Phase.cpp @@ -283,7 +283,7 @@ void Phase::setMoleFractions(const doublereal* const x) void Phase::setMoleFractions_NoNorm(const doublereal* const x) { m_mmw = dot(x, x + m_kk, m_molwts.begin()); - transform(x, x + m_kk, m_ym.begin(), timesConstant(1.0/m_mmw)); + scale(x, x + m_kk, m_ym.begin(), 1.0/m_mmw); transform(m_ym.begin(), m_ym.begin() + m_kk, m_molwts.begin(), m_y.begin(), multiplies()); compositionChanged();