19 #ifndef _POLYNOMIAL_IMPL_IPP_
20 #define _POLYNOMIAL_IMPL_IPP_
22 #include "../include/Polynomial.hpp"
31 template <
typename FieldT>
33 :m_coefs{in_list},m_size{in_list.size()}
40 template <
typename FieldT>
41 template <
typename InputIt>
44 for(
auto it=first; it != last; ++it) {
45 m_coefs.push_back(*it);
53 template <
typename FieldT>
61 template <
typename FieldT>
62 template <
typename convertibleToFieldT>
64 :m_coefs{
static_cast<FieldT
>(v)},
m_size{1}
72 template<
typename FieldT>
81 template <
typename FieldT>
85 throw std::out_of_range(
"");
87 return *(std::next(
m_coefs.begin(),i));
93 template <
typename FieldT>
97 return const_cast<FieldT&
>((
static_cast<Polynomial<FieldT> const*
>(
this)->
operator[](i)));
104 template <
typename FieldT>
108 std::cout<<
"=(&)"<<std::endl;
120 template <
typename FieldT>
125 std::cout<<
"=(&&)"<<std::endl;
142 template <
typename FieldT>
146 std::cout<<
"+=(&) "<<std::endl;
154 auto s_it = smaller_polynomial.
m_coefs.begin();
155 auto b_it = copy_for_swap.
m_coefs.begin();
156 for( ;s_it != smaller_polynomial.
m_coefs.end();) {
162 copy_for_swap.
trim();
164 swap(*
this,copy_for_swap);
169 template <
typename FieldT>
173 std::cout<<
"+=(&&) "<<std::endl;
179 auto s_it = smaller_polynomial.
m_coefs.begin();
180 auto b_it = bigger_polynomial.
m_coefs.begin();
181 for( ;s_it != smaller_polynomial.
m_coefs.end();) {
187 bigger_polynomial.
trim();
189 swap(*
this,bigger_polynomial);
196 template <
typename FieldT>
200 std::cout<<
"-=(&) "<<std::endl;
207 template <
typename FieldT>
211 std::cout<<
"-=(&&) "<<std::endl;
214 return (*
this+=-std::move(p2));
219 template <
typename FieldT>
223 std::cout<<
"this+(value) "<<std::endl;
226 return std::move(p2);
230 template <
typename FieldT>
238 template <
typename FieldT>
242 std::cout<<
"this-(value) "<<std::endl;
246 return std::move(temp);
251 template <
typename FieldT>
257 template <
typename FieldT>
260 for(
typename std::list<FieldT>::reverse_iterator r_it =
m_coefs.rbegin(); r_it !=
m_coefs.rend(); ) {
263 if ( *r_it == 0 &&
size() >1) {
264 typename std::list<FieldT>::reverse_iterator to_delete_it = r_it;
266 m_coefs.erase(--to_delete_it.base());
275 template <
typename FieldT>
284 #endif// _POLYNOMIAL_IPP_
void appendTerm(FieldT coeff)
Append new terms by pushing back coefficients.
std::list< FieldT > m_coefs
Polynomial()
The default constructor to make the class default constructible.
Polynomial operator+(const Polynomial &p2)
operator
friend Polynomial operator-(Polynomial const &rhs)
The unary (-) operator.
const FieldT & operator[](size_t i) const
Operator to fetch coefficients. Checks range.
friend void swap(Polynomial &lhs, Polynomial &rhs) noexcept
A non-template friend swap to aid in the implementation of copy-and-swap.
const Polynomial & operator+=(Polynomial const &p2)
The += operator for polynomials.
void trim()
Use to maintain the invariant 1.
Polynomial & minus()
Flip the sign of all coefs.
Contains the definition for the abstract base class which will be used by different multiplication al...
const Polynomial & operator-=(Polynomial const &p2)
The -= operator for polynomials.
Polynomial const & operator=(const Polynomial &rhs)
The assignemnt operator.