Skip to content

Commit

Permalink
Merge pull request #20 from scipopt/issue-19-narrowing-constant-linea…
Browse files Browse the repository at this point in the history
…r-expressions

Allow the construction of constant linear expressions without narrowing warnings
  • Loading branch information
hedtke authored Nov 22, 2023
2 parents 004fac8 + 4baa55e commit 066d898
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
8 changes: 7 additions & 1 deletion include/scippp/lin_expr.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,15 @@ class LinExpr {
* Creates a linear expression with no variables.
* @since 1.0.0
* @remark This is on purpose not an explicit c'tor to allow expressions like x <= 1.
* @tparam Arithmetic type that will be casted to \c double.
* @warning \c Arithmetic is casted to \c double without creating a narrowing warning!
* @param constant Constant term to set.
*/
LinExpr(double constant);
template <typename Arithmetic, std::enable_if_t<std::is_arithmetic_v<Arithmetic>, bool> = true>
LinExpr(Arithmetic constant)
: m_constant { static_cast<double>(constant) }
{
}
/**
* Creates a linear expression with zero as constant the given variable with coefficient one.
* @since 1.0.0
Expand Down
5 changes: 0 additions & 5 deletions source/lin_expr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,6 @@

namespace scippp {

LinExpr::LinExpr(double constant)
: m_constant { constant }
{
}

LinExpr::LinExpr(const Var& var)
: m_vars { var }
, m_coeffs(1, 1)
Expand Down

0 comments on commit 066d898

Please sign in to comment.