Skip to content

Operators +=, -=, /=, *= for Parameter's#130

Open
pdigiglio wants to merge 1 commit intoyap:masterfrom
pdigiglio:par_op
Open

Operators +=, -=, /=, *= for Parameter's#130
pdigiglio wants to merge 1 commit intoyap:masterfrom
pdigiglio:par_op

Conversation

@pdigiglio
Copy link
Contributor

No description provided.

template <typename P,
typename enable = typename std::enable_if<std::is_base_of<Parameter<typename P::parameter_type>, P>::value>::type>
inline P& operator/=(P& par, typename P::parameter_type a)
{ return (par *= (1. / a)); }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should be either P::parameter_type(1) / a or, better,

par.setValue(par.value() / a);
return par;

template <typename P,
typename enable = typename std::enable_if<std::is_base_of<Parameter<typename P::parameter_type>, P>::value>::type>
inline P& operator-=(P& par, typename P::parameter_type a)
{ return (par += -a); }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

par.setValue(par.value() - a);
return par;

(does not rely on there being unary minus available for type.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants