Skip to content

Commit

Permalink
Make empty Variable initialization constexpr
Browse files Browse the repository at this point in the history
  • Loading branch information
calcmogul committed Jan 17, 2025
1 parent 9537d65 commit b309ebd
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions include/sleipnir/autodiff/Variable.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,24 @@ class SLEIPNIR_DLLEXPORT Variable {
Variable() = default;

/**
* Constructs a Variable from a double.
* Constructs an empty Variable.
*/
explicit constexpr Variable(std::nullptr_t) : expr{nullptr} {}

/**
* Constructs a Variable from a floating point type.
*
* @param value The value of the Variable.
*/
Variable(std::floating_point auto value) // NOLINT
: expr{detail::MakeExpressionPtr<detail::ConstExpression>(value)} {}

/**
* Constructs a Variable from an integral type.
*
* @param value The value of the Variable.
*/
Variable(double value) // NOLINT
Variable(std::integral auto value) // NOLINT
: expr{detail::MakeExpressionPtr<detail::ConstExpression>(value)} {}

/**
Expand All @@ -55,7 +68,8 @@ class SLEIPNIR_DLLEXPORT Variable {
*
* @param expr The autodiff variable.
*/
explicit Variable(detail::ExpressionPtr&& expr) : expr{std::move(expr)} {}
explicit constexpr Variable(detail::ExpressionPtr&& expr)
: expr{std::move(expr)} {}

/**
* Assignment operator for double.
Expand Down

0 comments on commit b309ebd

Please sign in to comment.