-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
IPM: assemble_primal_dual_direction() was simplified using expression…
…s. Symbolic class UnaryNegation was added
- Loading branch information
Showing
4 changed files
with
52 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// Copyright (c) 2018-2024 Charlie Vanaret | ||
// Licensed under the MIT license. See LICENSE file in the project directory for details. | ||
|
||
#ifndef UNO_UNARYNEGATION_H | ||
#define UNO_UNARYNEGATION_H | ||
|
||
// stores the expression -expression symbolically | ||
// limited to types that possess value_type | ||
// https://stackoverflow.com/questions/11055923/stdenable-if-parameter-vs-template-parameter | ||
template <typename Expression> | ||
class UnaryNegation { | ||
public: | ||
using value_type = typename std::remove_reference_t<Expression>::value_type; | ||
|
||
explicit UnaryNegation(Expression&& expression): expression(std::forward<Expression>(expression)) { } | ||
|
||
[[nodiscard]] constexpr size_t size() const { return this->expression.size(); } | ||
[[nodiscard]] typename UnaryNegation::value_type operator[](size_t index) const { return -this->expression[index]; } | ||
|
||
protected: | ||
Expression expression; | ||
}; | ||
|
||
// free function | ||
template <typename Expression> | ||
inline UnaryNegation<Expression> operator-(Expression&& expression) { | ||
return UnaryNegation<Expression>(std::forward<Expression>(expression)); | ||
} | ||
|
||
#endif // UNO_UNARYNEGATION_H |