From 004142f85a4c01e11e501ebb440bbf5583710cf3 Mon Sep 17 00:00:00 2001 From: trotFunky Date: Tue, 14 May 2019 12:43:53 +0200 Subject: [PATCH] Better decltype for Polynomial::add return type --- snippets/Polynomial.tpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/snippets/Polynomial.tpp b/snippets/Polynomial.tpp index 96f06df..04a2dd9 100644 --- a/snippets/Polynomial.tpp +++ b/snippets/Polynomial.tpp @@ -35,7 +35,7 @@ public: bool equals(const Polynomial&) const; template - auto add(const Polynomial& operand) const -> Polynomial(0) + operand[0])>; + auto add(const Polynomial& operand) const -> Polynomial; template friend std::ostream& operator<<(std::ostream&, const Polynomial&); @@ -62,6 +62,7 @@ private: template Polynomial::Polynomial() { + // Not bad, but could be better with C++20. Not that useful either static_assert(std::is_arithmetic::value,"Polynomial must be of an arithmetic type!"); factors = {0}; } @@ -197,7 +198,7 @@ bool Polynomial::equals(const Polynomial& operand) const template template -auto Polynomial::add(const Polynomial& operand) const -> Polynomial(0) + operand[0])> +auto Polynomial::add(const Polynomial& operand) const -> Polynomial { bool isLargest = true; @@ -212,7 +213,7 @@ auto Polynomial::add(const Polynomial& operand) const -> Polynomial(0)+operand[0])> resultPolynomial = {}; + std::vector resultPolynomial = {}; resultPolynomial.reserve(largestSize); for(int i = 0;i::add(const Polynomial& operand) const -> Polynomial(0)+operand[0])>(resultPolynomial); + return Polynomial(resultPolynomial); } ////////////////////