// Copyright (c) 2008 Max-Planck-Institute Saarbruecken (Germany). // All rights reserved. // // This file is part of CGAL (www.cgal.org) // // $URL: https://github.com/CGAL/cgal/blob/v5.1/Polynomial/include/CGAL/Exponent_vector.h $ // $Id: Exponent_vector.h 0779373 2020-03-26T13:31:46+01:00 Sébastien Loriot // SPDX-License-Identifier: LGPL-3.0-or-later OR LicenseRef-Commercial // // // Author(s) : Michael Hemmer // // ============================================================================ #ifndef CGAL_EXPONENT_VECTOR_H #define CGAL_EXPONENT_VECTOR_H #include #include #include #include #include #include #include #include #include namespace CGAL { class Exponent_vector : public boost::less_than_comparable1< Exponent_vector >, public boost::equality_comparable1< Exponent_vector > { std::vector v; public: typedef Exponent_vector Self; Exponent_vector(){}; Exponent_vector(int e0): v(1) { v[0]=e0; }; Exponent_vector(int e0, int e1): v(2) { v[0]=e0; v[1]=e1; }; Exponent_vector(int e0, int e1, int e2): v(3) { v[0]=e0; v[1]=e1; v[2]=e2; }; Exponent_vector(int e0, int e1, int e2, int e3): v(4) { v[0]=e0; v[1]=e1; v[2]=e2; v[3]=e3; }; Exponent_vector(const std::vector& v_): v(v_){}; template Exponent_vector(InputIterator begin , InputIterator end) :v(begin,end){ typedef typename std::iterator_traits::value_type value_type; CGAL_USE_TYPE(value_type); CGAL_static_assertion(( ::boost::is_same::value)); } // mirror vector functions typedef std::vector::value_type value_type; typedef std::vector::pointer pointer; typedef std::vector::const_pointer const_pointer; typedef std::vector::reference reference; typedef std::vector::const_reference const_reference; typedef std::vector::size_type size_type; typedef std::vector::difference_type difference_type; typedef std::vector::iterator iterator; typedef std::vector::const_iterator const_iterator; typedef std::vector::reverse_iterator reverse_iterator; typedef std::vector::const_reverse_iterator const_reverse_iterator; iterator begin(){return v.begin();} iterator end(){return v.end();} const_iterator begin() const {return v.begin();} const_iterator end() const {return v.end();} reverse_iterator rbegin() {return v.rbegin();} reverse_iterator rend(){return v.rend();} const_reverse_iterator rbegin() const {return v.rbegin();} const_reverse_iterator rend() const {return v.rend();} size_type size() const {return v.size();} size_type max_size() const {return v.max_size();} size_type capacity() const {return v.capacity();} bool empty() const {return v.empty();} reference operator[](size_type n) { return v[n]; } const_reference operator[](size_type n) const {return v[n];} // vector& operator=(const vector&) void reserve(size_t s){v.reserve(s);} reference front(){return v.front();} const_reference front() const {return v.front();} reference back() {return v.back();} const_reference back() const {return v.back();} void push_back(const int& x) { v.push_back(x);} void pop_back() {v.pop_back();} void swap(Self& ev) {v.swap(ev.v);} iterator insert(iterator pos, const int& x){return v.insert(pos,x);} template void insert(iterator pos,InputIterator f, InputIterator l){ v.insert(pos,f,l); } void insert(iterator pos, size_type n, const int& x){ v.insert(pos,n,x); } iterator erase(iterator pos){return v.erase(pos);} iterator erase(iterator first, iterator last){return v.erase(first,last);} void clear(){v.clear();} void resize(size_type n, int t = 0){v.resize(n,t);} bool operator==(const Self& ev) const { return v == ev.v; } // this is the actual change bool operator<( const Exponent_vector& ev ) const { return std::lexicographical_compare ( this->rbegin(), this->rend(), ev.rbegin(), ev.rend()); } void output_benchmark( std::ostream& os ) const { os << "( "; for( unsigned i = 0; i < size(); ++i ) { if( i != 0 ) os << ", "; os << v.at(i); } os << " )"; } }; inline bool is_valid(const Exponent_vector& ev) { Exponent_vector::const_iterator it; for(it = ev.begin(); it != ev.end();it++){ if (CGAL::is_negative(*it)) return false; } return true; } inline std::ostream& operator << (std::ostream& os, const Exponent_vector& ev) { Exponent_vector::const_iterator it; os << "(" ; for(it = ev.begin(); it != ev.end();it++){ if (it == ev.begin()) { os << *it ; } else{ os <<"," << *it ; } } os << ")" ; return os; } } //namespace CGAL namespace std{ template <> inline void swap(CGAL::Exponent_vector& ev1, CGAL::Exponent_vector& ev2) CGAL_NOEXCEPT(std::is_nothrow_move_constructible::value && std::is_nothrow_move_assignable::value) { ev1.swap(ev2); } } #endif // CGAL_EXPONENT_VECTOR_H