diff --git a/src/algorithm b/src/algorithm index 52403494..af04f972 100644 --- a/src/algorithm +++ b/src/algorithm @@ -364,17 +364,6 @@ namespace std{ return result; } - template< class InputIterator, class Size, class OutputIterator > - OutputIterator copy_n( InputIterator first, Size count, OutputIterator result ) { - if (count > 0) { - *result++ = *first; - for (Size i = 1; i < count; ++i) { - *result++ = *++first; - } - } - return result; - } - template _UCXXEXPORT BidirectionalIterator2 copy_backward(BidirectionalIterator1 first, BidirectionalIterator1 last, @@ -394,16 +383,6 @@ namespace std{ b = temp; } - template _UCXXEXPORT - void - iter_swap(ForwardIterator1 a, ForwardIterator2 b) - { - typename iterator_traits::value_type temp(*a); - *a = *b; - *b = temp; - } - - template _UCXXEXPORT ForwardIterator2 swap_ranges(ForwardIterator1 first1, ForwardIterator1 last1, ForwardIterator2 first2) @@ -417,6 +396,16 @@ namespace std{ } + template _UCXXEXPORT + void + iter_swap(ForwardIterator1 a, ForwardIterator2 b) + { + typename iterator_traits::value_type temp(*a); + *a = *b; + *b = temp; + } + + template _UCXXEXPORT OutputIterator transform(InputIterator first, InputIterator last, diff --git a/src/associative_base b/src/associative_base index 27ae0ef9..be8b27f6 100644 --- a/src/associative_base +++ b/src/associative_base @@ -200,8 +200,7 @@ public: } void erase(iterator first, iterator last){ while(first != last){ - backing.erase(first.base_iterator()); - ++first; + first = backing.erase(first.base_iterator()); } } diff --git a/src/basic_definitions b/src/basic_definitions index d4b6cd51..9936563e 100644 --- a/src/basic_definitions +++ b/src/basic_definitions @@ -39,6 +39,28 @@ #define __UCLIBCXX_NORETURN #endif +#ifdef __GCC__ +# ifndef _UCXX_NOTHROW +# ifndef __cplusplus +# define _UCXX_NOTHROW __attribute__((__nothrow__)) +# endif +# endif +#endif +#ifdef __cplusplus +# if __cplusplus >= 201103L +# define _UCXX_NOEXCEPT noexcept +# define _UCXX_USE_NOEXCEPT noexcept +# define _UCXX_THROW(_EXCEPTION) +# else +# define _UCXX_NOEXCEPT +# define _UCXX_USE_NOEXCEPT throw() +# define _UCXX_THROW(_EXCEPTION) throw(_EXCEPTION) +# endif +# ifndef _UCXX_NOTHROW +# define _UCXX_NOTHROW _UCXX_USE_NOEXCEPT +# endif +#endif + #ifdef __UCLIBCXX_HAS_TLS__ #define __UCLIBCXX_TLS __thread #else diff --git a/src/char_traits b/src/char_traits index 36eae361..1d33f394 100644 --- a/src/char_traits +++ b/src/char_traits @@ -52,7 +52,7 @@ namespace std{ static char_type to_char_type(const int_type & i); inline static int_type to_int_type(const char_type & c){ - return (short int)(unsigned char)c; + return static_cast(static_cast(c)); } inline static bool eq_int_type(const int_type & a, const int_type & b){ @@ -71,7 +71,7 @@ namespace std{ } inline static char_type* move(char_type* s1, const char_type* s2, size_t n){ - return (char*) memmove(s1, s2, n); + return static_cast(memmove(s1, s2, n)); } inline static char_type* copy(char_type* s1, const char_type* s2, size_t n){ @@ -82,7 +82,7 @@ namespace std{ } inline static char_type* assign(char_type* s, size_t n, char_type a){ - return (char *)memset(s, a, n); + return static_cast(memset(s, a, n)); } inline static int compare(const char_type* s1, const char_type* s2, size_t n){ diff --git a/src/cstdio b/src/cstdio index 8f4df276..0a424580 100644 --- a/src/cstdio +++ b/src/cstdio @@ -21,6 +21,15 @@ #ifndef __HEADER_CSTDIO #define __HEADER_CSTDIO 1 +#undef clearerr +#undef feof +#undef ferror +#undef fgetc +#undef fputc +#undef getc +#undef getchar +#undef putc +#undef putchar namespace std{ using ::FILE; @@ -48,6 +57,7 @@ namespace std{ using ::getc; using ::getchar; #if __cplusplus <= 201103L + // LWG 2249 using ::gets; #endif using ::perror; @@ -64,7 +74,9 @@ namespace std{ using ::sprintf; using ::sscanf; using ::tmpfile; +#ifdef _GLIBCXX_USE_TMPNAM using ::tmpnam; +#endif using ::ungetc; using ::vfprintf; using ::vprintf; diff --git a/src/del_op.cpp b/src/del_op.cpp index e6b584fc..588743da 100644 --- a/src/del_op.cpp +++ b/src/del_op.cpp @@ -24,7 +24,7 @@ #include #include -_UCXXEXPORT void operator delete(void* ptr) throw(){ +_UCXXEXPORT void operator delete(void* ptr) _UCXX_USE_NOEXCEPT{ free(ptr); } diff --git a/src/del_opnt.cpp b/src/del_opnt.cpp index 96cb03ba..48259129 100644 --- a/src/del_opnt.cpp +++ b/src/del_opnt.cpp @@ -22,7 +22,7 @@ #include #ifndef NO_NOTHROW -_UCXXEXPORT void operator delete(void* ptr, const std::nothrow_t& ) throw() { +_UCXXEXPORT void operator delete(void* ptr, const std::nothrow_t& ) _UCXX_USE_NOEXCEPT { free(ptr); } #endif diff --git a/src/del_ops.cpp b/src/del_ops.cpp index e292b037..b914fc59 100644 --- a/src/del_ops.cpp +++ b/src/del_ops.cpp @@ -22,6 +22,6 @@ #include #include -_UCXXEXPORT void operator delete(void* ptr, std::size_t) throw(){ +_UCXXEXPORT void operator delete(void* ptr, std::size_t) _UCXX_USE_NOEXCEPT{ ::operator delete (ptr); } diff --git a/src/del_opv.cpp b/src/del_opv.cpp index 1690f88a..a24c72d1 100644 --- a/src/del_opv.cpp +++ b/src/del_opv.cpp @@ -24,7 +24,7 @@ #include #include -_UCXXEXPORT void operator delete[](void * ptr) throw(){ +_UCXXEXPORT void operator delete[](void * ptr) _UCXX_USE_NOEXCEPT{ free(ptr); } diff --git a/src/del_opvnt.cpp b/src/del_opvnt.cpp index f2a2a361..71b7631b 100644 --- a/src/del_opvnt.cpp +++ b/src/del_opvnt.cpp @@ -22,7 +22,7 @@ #include #ifndef NO_NOTHROW -_UCXXEXPORT void operator delete[](void* ptr, const std::nothrow_t& ) throw(){ +_UCXXEXPORT void operator delete[](void* ptr, const std::nothrow_t& ) _UCXX_USE_NOEXCEPT{ free(ptr); } #endif diff --git a/src/del_opvs.cpp b/src/del_opvs.cpp index 1c92d1f1..53ab7cc9 100644 --- a/src/del_opvs.cpp +++ b/src/del_opvs.cpp @@ -22,6 +22,6 @@ #include #include -_UCXXEXPORT void operator delete[](void * ptr, std::size_t) throw(){ +_UCXXEXPORT void operator delete[](void * ptr, std::size_t) _UCXX_USE_NOEXCEPT{ ::operator delete[] (ptr); } diff --git a/src/eh_alloc.cpp b/src/eh_alloc.cpp index cdf28e09..270ef10b 100644 --- a/src/eh_alloc.cpp +++ b/src/eh_alloc.cpp @@ -27,7 +27,7 @@ namespace __cxxabiv1 { -extern "C" void * __cxa_allocate_exception(std::size_t thrown_size) throw(){ +extern "C" void * __cxa_allocate_exception(std::size_t thrown_size) _UCXX_USE_NOEXCEPT{ void *e; // The sizeof crap is required by Itanium ABI because we need to // provide space for accounting information which is implementation @@ -40,12 +40,12 @@ extern "C" void * __cxa_allocate_exception(std::size_t thrown_size) throw(){ return (void *)((unsigned char *)e + sizeof(__cxa_refcounted_exception)); } -extern "C" void __cxa_free_exception(void *vptr) throw(){ +extern "C" void __cxa_free_exception(void *vptr) _UCXX_USE_NOEXCEPT{ free( (char *)(vptr) - sizeof(__cxa_refcounted_exception) ); } -extern "C" __cxa_dependent_exception * __cxa_allocate_dependent_exception() throw(){ +extern "C" __cxa_dependent_exception * __cxa_allocate_dependent_exception() _UCXX_USE_NOEXCEPT{ __cxa_dependent_exception *retval; // The sizeof crap is required by Itanium ABI because we need to // provide space for accounting information which is implementation @@ -58,7 +58,7 @@ extern "C" __cxa_dependent_exception * __cxa_allocate_dependent_exception() thro return retval; } -extern "C" void __cxa_free_dependent_exception(__cxa_dependent_exception *vptr) throw(){ +extern "C" void __cxa_free_dependent_exception(__cxa_dependent_exception *vptr) _UCXX_USE_NOEXCEPT{ free( (char *)(vptr) ); } diff --git a/src/eh_globals.cpp b/src/eh_globals.cpp index 38d4583e..99154331 100644 --- a/src/eh_globals.cpp +++ b/src/eh_globals.cpp @@ -31,11 +31,11 @@ namespace __cxxabiv1{ static __UCLIBCXX_TLS __cxa_eh_globals eh_globals; -extern "C" __cxa_eh_globals* __cxa_get_globals() throw(){ +extern "C" __cxa_eh_globals* __cxa_get_globals() _UCXX_USE_NOEXCEPT{ return &eh_globals; } -extern "C" __cxa_eh_globals* __cxa_get_globals_fast() throw(){ +extern "C" __cxa_eh_globals* __cxa_get_globals_fast() _UCXX_USE_NOEXCEPT{ return &eh_globals; } diff --git a/src/exception b/src/exception index bdf393e6..0cccc9cb 100644 --- a/src/exception +++ b/src/exception @@ -54,11 +54,11 @@ namespace std class exception { public: - exception() throw() { } - virtual ~exception() throw(); + exception() _UCXX_NOTHROW { } + virtual ~exception() _UCXX_NOTHROW; /** Returns a C-style character string describing the general cause * of the current error. */ - virtual const char* what() const throw(); + virtual const char* what() const _UCXX_NOTHROW; }; /** If an %exception is thrown which is not listed in a function's @@ -66,10 +66,10 @@ namespace std class bad_exception : public exception { public: - bad_exception() throw() { } + bad_exception() _UCXX_USE_NOEXCEPT { } // This declaration is not useless: // http://gcc.gnu.org/onlinedocs/gcc-3.0.2/gcc_6.html#SEC118 - virtual ~bad_exception() throw(); + virtual ~bad_exception() _UCXX_USE_NOEXCEPT; }; /// If you write a replacement %terminate handler, it must be of this type. @@ -78,13 +78,13 @@ namespace std typedef void (*unexpected_handler) (); /// Takes a new handler function as an argument, returns the old function. - terminate_handler set_terminate(terminate_handler) throw(); + terminate_handler set_terminate(terminate_handler) _UCXX_USE_NOEXCEPT; /** The runtime will call this function if %exception handling must be * abandoned for any reason. */ void terminate() __UCLIBCXX_NORETURN; /// Takes a new handler function as an argument, returns the old function. - unexpected_handler set_unexpected(unexpected_handler) throw(); + unexpected_handler set_unexpected(unexpected_handler) _UCXX_USE_NOEXCEPT; /** The runtime will call this function if an %exception is thrown which * violates the function's %exception specification. */ void unexpected() __UCLIBCXX_NORETURN; @@ -99,7 +99,7 @@ namespace std * 2: "When @c uncaught_exception() is true, throwing an %exception can * result in a call of @c terminate() (15.5.1)." */ - bool uncaught_exception() throw(); + bool uncaught_exception() _UCXX_USE_NOEXCEPT; } // namespace std namespace __gnu_cxx diff --git a/src/exception.cpp b/src/exception.cpp index 82021ddb..5f4e8962 100644 --- a/src/exception.cpp +++ b/src/exception.cpp @@ -33,15 +33,15 @@ namespace std{ //We are providing our own versions to be sneaky - _UCXXEXPORT exception::~exception() throw(){ + _UCXXEXPORT exception::~exception() _UCXX_USE_NOEXCEPT{ //Empty function } - _UCXXEXPORT const char* exception::what() const throw(){ + _UCXXEXPORT const char* exception::what() const _UCXX_USE_NOEXCEPT{ return __std_exception_what_value; } - _UCXXEXPORT bad_exception::~bad_exception() throw(){ + _UCXXEXPORT bad_exception::~bad_exception() _UCXX_USE_NOEXCEPT{ } diff --git a/src/functional b/src/functional index b7932e2c..ae9ed4b8 100644 --- a/src/functional +++ b/src/functional @@ -137,25 +137,25 @@ namespace std{ }; template struct _UCXXEXPORT greater : binary_function{ - bool operator()(const T& x, const T& y) const{ + bool operator()(const T& x, const T& y) const _UCXX_NOTHROW { return (x > y); } }; template struct _UCXXEXPORT less : binary_function{ - bool operator()(const T& x, const T& y) const{ + bool operator()(const T& x, const T& y) const _UCXX_NOTHROW { return (x < y); } }; template struct _UCXXEXPORT greater_equal : binary_function{ - bool operator()(const T& x, const T& y) const{ + bool operator()(const T& x, const T& y) const _UCXX_NOTHROW { return (x >= y); } }; template struct _UCXXEXPORT less_equal : binary_function{ - bool operator()(const T& x, const T& y) const{ + bool operator()(const T& x, const T& y) const _UCXX_NOTHROW { return (x <= y); } }; diff --git a/src/initializer_list b/src/initializer_list deleted file mode 100644 index 05a4e841..00000000 --- a/src/initializer_list +++ /dev/null @@ -1,60 +0,0 @@ -/* Copyright (C) 2016 Michael Matera - - This file is part of the uClibc++ Library. - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - -*/ - - -#ifndef __STD_HEADER_INITIALIZER_LIST -#define __STD_HEADER_INITIALIZER_LIST - -#pragma GCC visibility push(default) - -namespace std { - -template -class initializer_list { - -private: - const T* array; - size_t len; - - // Initialize from a { ... } construct - initializer_list(const T *a, size_t l): array(a), len(l) { } - -public: - - // default constructor - initializer_list() : array(NULL), len(0) {} - - size_t size() const { - return len; - } - - const T *begin() { - return array; - } - - const T *end() { - return array + len; - } - -}; - -} - -#endif diff --git a/src/ios b/src/ios index 63dc4edb..ac6566a5 100644 --- a/src/ios +++ b/src/ios @@ -40,7 +40,7 @@ namespace std{ public: explicit failure(const std::string&) { } explicit failure() { } - virtual const char* what() const throw() { + virtual const char* what() const _UCXX_USE_NOEXCEPT { return "std::ios_base failure exception"; } }; @@ -139,13 +139,15 @@ namespace std{ // long& iword(int index); // void*& pword(int index); - _UCXXEXPORT ~ios_base() { } - enum event { erase_event, imbue_event, copyfmt_event }; typedef void (*event_callback)(event, ios_base&, int index); // void register_callback(event_call_back fn, int index); + virtual _UCXXEXPORT ~ios_base() { + /* would run erase_event callbacks here */ + } + //We are going to wrap stdio so we don't need implementation of the following: inline static bool sync_with_stdio(bool = true) { return true; } @@ -340,7 +342,8 @@ namespace std{ throw_mask = except; } - explicit _UCXXEXPORT basic_ios(basic_streambuf* sb) : fill_char(' '), mtied(0), mstreambuf(0){ + explicit _UCXXEXPORT basic_ios(basic_streambuf* sb) + : fill_char(' '), mtied(0), mstreambuf(0), throw_mask(0) { init(sb); } diff --git a/src/istream b/src/istream index a6fe3dee..2083eefd 100644 --- a/src/istream +++ b/src/istream @@ -345,7 +345,8 @@ namespace std{ { bool ok; public: - explicit _UCXXEXPORT sentry(basic_istream& os, bool noskipws = false){ + explicit _UCXXEXPORT sentry(basic_istream& os, bool noskipws = false) + : ok(false){ if(os.good() !=0){ //Prepare for output } @@ -451,24 +452,24 @@ namespace std{ #ifdef __UCLIBCXX_HAS_FLOATS__ template _UCXXEXPORT basic_istream& - basic_istream::operator>>(float& n) + basic_istream::operator>>(float& f) { sentry(*this); - __istream_readin::readin(*this, n); + __istream_readin::readin(*this, f); return *this; } template _UCXXEXPORT basic_istream& - basic_istream::operator>>(double& n) + basic_istream::operator>>(double& f) { sentry(*this); - __istream_readin::readin(*this, n); + __istream_readin::readin(*this, f); return *this; } template _UCXXEXPORT basic_istream& - basic_istream::operator>>(long double& n) + basic_istream::operator>>(long double& f) { sentry(*this); - __istream_readin::readin(*this, n); + __istream_readin::readin(*this, f); return *this; } #endif diff --git a/src/iterator b/src/iterator index d38fa1c4..3348d85f 100644 --- a/src/iterator +++ b/src/iterator @@ -145,10 +145,10 @@ namespace std{ charT operator*() { return val; } }; - istreambuf_iterator() throw() : sbuf(0) { } - istreambuf_iterator(istream_type& s) throw() : sbuf(s.rdbuf()) { } - istreambuf_iterator(streambuf_type* s) throw() : sbuf(s) { } - istreambuf_iterator(const proxy& p) throw() : sbuf(&p.buf) { } + istreambuf_iterator() _UCXX_USE_NOEXCEPT : sbuf(0) { } + istreambuf_iterator(istream_type& s) _UCXX_USE_NOEXCEPT : sbuf(s.rdbuf()) { } + istreambuf_iterator(streambuf_type* s) _UCXX_USE_NOEXCEPT : sbuf(s) { } + istreambuf_iterator(const proxy& p) _UCXX_USE_NOEXCEPT : sbuf(&p.buf) { } charT operator*() const{ return sbuf->sgetc(); @@ -157,14 +157,14 @@ namespace std{ sbuf->sbumpc(); return *this; } - proxy operator++(int){ + istreambuf_iterator operator++(int){ istreambuf_iterator tmp = *this; sbuf->sbumpc(); return(tmp); } bool equal(const istreambuf_iterator& b) const{ - return sbuf == b.sbuf || is_eof() && b.is_eof(); + return sbuf == b.sbuf || (is_eof() && b.is_eof()); } private: streambuf_type* sbuf; @@ -196,8 +196,8 @@ namespace std{ typedef basic_streambuf streambuf_type; typedef basic_ostream ostream_type; public: - ostreambuf_iterator(ostream_type& s) throw() : sbuf(s.rdbuf()), f(false) { } - ostreambuf_iterator(streambuf_type* s) throw() : sbuf(s), f(false) { } + ostreambuf_iterator(ostream_type& s) _UCXX_USE_NOEXCEPT : sbuf(s.rdbuf()), f(false) { } + ostreambuf_iterator(streambuf_type* s) _UCXX_USE_NOEXCEPT : sbuf(s), f(false) { } ostreambuf_iterator& operator=(charT c){ if(failed() == false){ if(sbuf->sputc(c) == traits::eof()){ @@ -211,7 +211,7 @@ namespace std{ } ostreambuf_iterator& operator++() { return *this; } ostreambuf_iterator operator++(int) { return *this; } - bool failed() const throw(){ + bool failed() const _UCXX_USE_NOEXCEPT{ return f; } @@ -220,12 +220,6 @@ namespace std{ bool f; }; - template< class C > - auto begin( C& c ) -> decltype(c.begin()) { return c.begin(); } - - template< class C > - auto end( C& c ) -> decltype(c.end()) { return c.end(); } - } #pragma GCC visibility pop diff --git a/src/iterator_base b/src/iterator_base index 1cae5896..e112a7f3 100644 --- a/src/iterator_base +++ b/src/iterator_base @@ -139,7 +139,7 @@ namespace std{ public: typedef Iterator iterator_type; - reverse_iterator() : current(){}; + reverse_iterator() : current(){} explicit reverse_iterator(Iterator x) : current(x) { } template reverse_iterator(const reverse_iterator &x) : current(x.base()){} @@ -225,7 +225,7 @@ namespace std{ Container& container; public: typedef Container container_type; - explicit back_insert_iterator(Container& x):container(x) {}; + explicit back_insert_iterator(Container& x):container(x) {} back_insert_iterator& operator=(const typename Container::value_type& value){ container.push_back(value); return *this; diff --git a/src/list b/src/list index 04afa2da..1ef00fbd 100644 --- a/src/list +++ b/src/list @@ -20,7 +20,6 @@ #include #include #include -#include #ifndef __STD_HEADER_LIST #define __STD_HEADER_LIST 1 @@ -75,16 +74,6 @@ namespace std{ } return *this; } - - list& operator=(const std::initializer_list& x){ - clear(); - auto i = x.begin(); - while(i != x.end()){ - push_back(*i); - ++i; - } - return *this; - } template void assign(InputIterator first, InputIterator last); template void assign(Size n, const U& u = U()); @@ -615,8 +604,8 @@ namespace std{ //Insert at begining special case if(position == begin()){ - - i.link_struct()->previous->next = i.link_struct()->next; + if (i.link_struct()->previous != 0) + i.link_struct()->previous->next = i.link_struct()->next; i.link_struct()->next->previous = i.link_struct()->previous; i.link_struct()->previous = 0; diff --git a/src/locale b/src/locale index 96e6bc94..ed4dfa36 100644 --- a/src/locale +++ b/src/locale @@ -42,21 +42,21 @@ namespace std{ all = collate | ctype | monetary | numeric | time | messages; // construct/copy/destroy: - locale() throw(){ + locale() _UCXX_USE_NOEXCEPT{ return; } - locale(const locale& other) throw(){ + locale(const locale& other) _UCXX_USE_NOEXCEPT{ (void)other; return; } - locale(const char *) throw(){ + locale(const char *) _UCXX_USE_NOEXCEPT{ return; } - ~locale() throw(){ + ~locale() _UCXX_USE_NOEXCEPT{ return; } - const locale& operator=(const locale&) throw(){ + const locale& operator=(const locale&) _UCXX_USE_NOEXCEPT{ return *this; } std::string name() const { return "C"; } diff --git a/src/map b/src/map index 44be7108..038191af 100644 --- a/src/map +++ b/src/map @@ -22,7 +22,6 @@ #include #include #include -#include #ifndef __STD_HEADER_MAP @@ -110,10 +109,6 @@ public: const Compare& comp = Compare(), const Allocator& al = Allocator()) : base(first, last, comp, al, v_t_k) { } - map(initializer_list> in, const Compare& comp = Compare(), - const Allocator& al = Allocator()) - : base(in.begin(), in.end(), comp, al, v_t_k) { } - map(const map& x) : base(x) { } ~map() { } diff --git a/src/memory b/src/memory index 2a7ce8c1..37ac637e 100644 --- a/src/memory +++ b/src/memory @@ -57,23 +57,23 @@ public: pointer address(reference r) const { return &r; } const_pointer address(const_reference r) const { return &r; } - allocator() throw(){} - template allocator(const allocator& ) throw(); - ~allocator() throw(){} + allocator() _UCXX_USE_NOEXCEPT{} + template allocator(const allocator& ) _UCXX_USE_NOEXCEPT; + ~allocator() _UCXX_USE_NOEXCEPT{} //Space for n Ts pointer allocate(size_type n, typename allocator::const_pointer = 0){ - return (T*)(::operator new( n * sizeof(T) )); + return static_cast(::operator new( n * sizeof(T) )); } void deallocate(pointer p, size_type){ ::operator delete(p); } //Use placement new to engage the constructor - void construct(pointer p, const T& val) { new((void*)p) T(val); } - void destroy(pointer p){ ((T*)p)->~T(); } //Call destructor + void construct(pointer p, const T& val) { new(static_cast(p)) T(val); } + void destroy(pointer p){ (static_cast(p))->~T(); } //Call destructor - size_type max_size() const throw(); + size_type max_size() const _UCXX_USE_NOEXCEPT; template struct rebind { typedef allocator other; }; }; @@ -128,13 +128,13 @@ public: typedef T element_type; - explicit auto_ptr(T* p =0) throw() : object(p){ } - auto_ptr(auto_ptr& p) throw() : object(p.release()){ } - auto_ptr(auto_ptr_ref r) throw() : object(r.p){ + explicit auto_ptr(T* p =0) _UCXX_USE_NOEXCEPT : object(p){ } + auto_ptr(auto_ptr& p) _UCXX_USE_NOEXCEPT : object(p.release()){ } + auto_ptr(auto_ptr_ref r) _UCXX_USE_NOEXCEPT : object(r.p){ r.p = 0; } - template auto_ptr(auto_ptr& p) throw() : object(p.release()){ } - auto_ptr& operator=(auto_ptr& p) throw(){ + template auto_ptr(auto_ptr& p) _UCXX_USE_NOEXCEPT : object(p.release()){ } + auto_ptr& operator=(auto_ptr& p) _UCXX_USE_NOEXCEPT{ if(&p == this){ return *this; } @@ -142,7 +142,7 @@ public: object = p.release(); return *this; } - template auto_ptr& operator=(auto_ptr& p) throw(){ + template auto_ptr& operator=(auto_ptr& p) _UCXX_USE_NOEXCEPT{ if(&p == this){ return *this; } @@ -154,33 +154,33 @@ public: delete object; } - T& operator*() const throw(){ + T& operator*() const _UCXX_USE_NOEXCEPT{ return *object; } - T* operator->() const throw(){ + T* operator->() const _UCXX_USE_NOEXCEPT{ return object; } - T* get() const throw(){ + T* get() const _UCXX_USE_NOEXCEPT{ return object; } - T* release() throw(){ + T* release() _UCXX_USE_NOEXCEPT{ T * temp(object); object = 0; return temp; } - void reset(T * p=0) throw(){ + void reset(T * p=0) _UCXX_USE_NOEXCEPT{ if(p != object){ delete object; object = p; } } - template operator auto_ptr_ref() throw(){ + template operator auto_ptr_ref() _UCXX_USE_NOEXCEPT{ auto_ptr_ref retval; retval.p = object; object = 0; return retval; } - template operator auto_ptr() throw(){ + template operator auto_ptr() _UCXX_USE_NOEXCEPT{ auto_ptr retval(object); object = 0; return retval; diff --git a/src/new b/src/new index 12b52a48..1dc33a47 100644 --- a/src/new +++ b/src/new @@ -33,43 +33,36 @@ namespace std{ extern const nothrow_t nothrow; typedef void (*new_handler)(); - _UCXXEXPORT new_handler set_new_handler(new_handler new_p) throw(); + _UCXXEXPORT new_handler set_new_handler(new_handler new_p) _UCXX_USE_NOEXCEPT; } -#if (__cplusplus < 201703L) - _UCXXEXPORT void* operator new(std::size_t numBytes) throw(std::bad_alloc); -#else - _UCXXEXPORT void* operator new(std::size_t numBytes) noexcept(false); -#endif -_UCXXEXPORT void operator delete(void* ptr) throw(); -#if __cpp_sized_deallocation -_UCXXEXPORT void operator delete(void* ptr, std::size_t) throw(); -#endif -#if (__cplusplus < 201703L) - _UCXXEXPORT void* operator new[](std::size_t numBytes) throw(std::bad_alloc); -#else - _UCXXEXPORT void* operator new[](std::size_t numBytes) noexcept(false); +_UCXXEXPORT void* operator new(std::size_t numBytes) _UCXX_THROW(std::bad_alloc); +_UCXXEXPORT void operator delete(void* ptr) _UCXX_USE_NOEXCEPT; +#ifdef __cpp_sized_deallocation +_UCXXEXPORT void operator delete(void* ptr, std::size_t) _UCXX_USE_NOEXCEPT; #endif -_UCXXEXPORT void operator delete[](void * ptr) throw(); -#if __cpp_sized_deallocation -_UCXXEXPORT void operator delete[](void * ptr, std::size_t) throw(); + +_UCXXEXPORT void* operator new[](std::size_t numBytes) _UCXX_THROW(std::bad_alloc); +_UCXXEXPORT void operator delete[](void * ptr) _UCXX_USE_NOEXCEPT; +#ifdef __cpp_sized_deallocation +_UCXXEXPORT void operator delete[](void * ptr, std::size_t) _UCXX_USE_NOEXCEPT; #endif #ifndef NO_NOTHROW -_UCXXEXPORT void* operator new(std::size_t numBytes, const std::nothrow_t& ) throw(); -_UCXXEXPORT void operator delete(void* ptr, const std::nothrow_t& ) throw(); +_UCXXEXPORT void* operator new(std::size_t numBytes, const std::nothrow_t& ) _UCXX_USE_NOEXCEPT; +_UCXXEXPORT void operator delete(void* ptr, const std::nothrow_t& ) _UCXX_USE_NOEXCEPT; -_UCXXEXPORT void* operator new[](std::size_t numBytes, const std::nothrow_t& ) throw(); -_UCXXEXPORT void operator delete[](void* ptr, const std::nothrow_t& ) throw(); +_UCXXEXPORT void* operator new[](std::size_t numBytes, const std::nothrow_t& ) _UCXX_USE_NOEXCEPT; +_UCXXEXPORT void operator delete[](void* ptr, const std::nothrow_t& ) _UCXX_USE_NOEXCEPT; #endif /* Placement operators */ -inline void* operator new(std::size_t, void* ptr) throw() {return ptr; } -inline void operator delete(void* , void *) throw() { } - -inline void* operator new[](std::size_t, void *p) throw() { return p; } -inline void operator delete[](void* , void *) throw() {} +inline void* operator new(std::size_t, void* ptr) _UCXX_USE_NOEXCEPT {return ptr; } +inline void operator delete(void* , void *) _UCXX_USE_NOEXCEPT { } + +inline void* operator new[](std::size_t, void *p) _UCXX_USE_NOEXCEPT { return p; } +inline void operator delete[](void* , void *) _UCXX_USE_NOEXCEPT {} #pragma GCC visibility pop diff --git a/src/new_handler.cpp b/src/new_handler.cpp index 1d85ee3f..a6efb9cb 100644 --- a/src/new_handler.cpp +++ b/src/new_handler.cpp @@ -24,7 +24,7 @@ const std::nothrow_t std::nothrow = { }; //Name selected to be compatable with g++ code std::new_handler __new_handler; -_UCXXEXPORT std::new_handler std::set_new_handler(std::new_handler new_p) throw(){ +_UCXXEXPORT std::new_handler std::set_new_handler(std::new_handler new_p) _UCXX_USE_NOEXCEPT{ std::new_handler retval = __new_handler; __new_handler = new_p; return retval; diff --git a/src/new_op.cpp b/src/new_op.cpp index 355087e5..5232b1ec 100644 --- a/src/new_op.cpp +++ b/src/new_op.cpp @@ -24,7 +24,8 @@ #include #include -_UCXXEXPORT void* operator new(std::size_t numBytes) throw(std::bad_alloc){ +_UCXXEXPORT void* operator new(std::size_t numBytes) _UCXX_THROW(std::bad_alloc) +{ //C++ stardard 5.3.4.8 requires that a valid pointer be returned for //a call to new(0). Thus: if(numBytes == 0){ diff --git a/src/new_opnt.cpp b/src/new_opnt.cpp index cffce610..c37903e0 100644 --- a/src/new_opnt.cpp +++ b/src/new_opnt.cpp @@ -22,7 +22,7 @@ #include #ifndef NO_NOTHROW -_UCXXEXPORT void* operator new(std::size_t numBytes, const std::nothrow_t& ) throw(){ +_UCXXEXPORT void* operator new(std::size_t numBytes, const std::nothrow_t& ) _UCXX_USE_NOEXCEPT{ return malloc(numBytes); } #endif diff --git a/src/new_opv.cpp b/src/new_opv.cpp index b5318255..89a6a2aa 100644 --- a/src/new_opv.cpp +++ b/src/new_opv.cpp @@ -24,7 +24,7 @@ #include #include -_UCXXEXPORT void* operator new[](std::size_t numBytes) throw(std::bad_alloc){ +_UCXXEXPORT void* operator new[](std::size_t numBytes)_UCXX_THROW(std::bad_alloc){ //C++ stardard 5.3.4.8 requires that a valid pointer be returned for //a call to new(0). Thus: if(numBytes == 0){ diff --git a/src/new_opvnt.cpp b/src/new_opvnt.cpp index 3ea592af..4874a7f6 100644 --- a/src/new_opvnt.cpp +++ b/src/new_opvnt.cpp @@ -22,7 +22,7 @@ #include #ifndef NO_NOTHROW -_UCXXEXPORT void* operator new[](std::size_t numBytes, const std::nothrow_t& ) throw(){ +_UCXXEXPORT void* operator new[](std::size_t numBytes, const std::nothrow_t& ) _UCXX_USE_NOEXCEPT{ return malloc(numBytes); } #endif diff --git a/src/ostream_helpers b/src/ostream_helpers index 813f573b..5b5fffd3 100644 --- a/src/ostream_helpers +++ b/src/ostream_helpers @@ -146,7 +146,7 @@ int arduinoPrintFloat(double number, uint8_t digits, char *buffer, size_t buffer } }; -#ifndef __STRICT_ANSI__ +#if !defined(__STRICT_ANSI__) || (__cplusplus >= 201103L) template class _UCXXEXPORT __ostream_printout{ public: @@ -241,7 +241,7 @@ int arduinoPrintFloat(double number, uint8_t digits, char *buffer, size_t buffer }; -#endif //__STRICT_ANSI__ +#endif // !defined(__STRICT_ANSI__) || (__cplusplus >= 201103L) // FIXME: Improve printing of doubles and floats. @@ -298,6 +298,7 @@ int arduinoPrintFloat(double number, uint8_t digits, char *buffer, size_t buffer if(stream.flags() & ios_base::unitbuf){ stream.flush(); } + } }; @@ -370,7 +371,7 @@ int arduinoPrintFloat(double number, uint8_t digits, char *buffer, size_t buffer } }; -#ifndef __STRICT_ANSI__ +#if !defined(__STRICT_ANSI__) || (__cplusplus >= 201103L) template class _UCXXEXPORT __ostream_printout{ public: @@ -441,7 +442,7 @@ int arduinoPrintFloat(double number, uint8_t digits, char *buffer, size_t buffer }; -#endif //__STRICT_ANSI__ +#endif // !defined(__STRICT_ANSI__) || (__cplusplus >= 201103L) template class _UCXXEXPORT __ostream_printout{ public: diff --git a/src/stack b/src/stack index d4861b3a..ea697f18 100644 --- a/src/stack +++ b/src/stack @@ -34,7 +34,7 @@ namespace std{ typedef typename Container::size_type size_type; typedef Container container_type; - explicit stack(const Container& a = Container()) : c(a) { }; + explicit stack(const Container& a = Container()) : c(a) { } bool empty() const { return c.empty(); } size_type size() const { return c.size(); } value_type& top() { return c.back(); } diff --git a/src/stdexcept b/src/stdexcept index 7557f24c..76c38706 100644 --- a/src/stdexcept +++ b/src/stdexcept @@ -37,11 +37,11 @@ class _UCXXEXPORT logic_error : public exception { protected: string mstring; public: - logic_error() throw(); + logic_error() _UCXX_USE_NOEXCEPT; logic_error(const string& what_arg); - virtual ~logic_error() throw() {} - virtual const char * what() const throw(); + virtual ~logic_error() _UCXX_USE_NOEXCEPT {} + virtual const char * what() const _UCXX_USE_NOEXCEPT; }; @@ -49,28 +49,28 @@ class _UCXXEXPORT domain_error : public logic_error { public: domain_error() : logic_error() {} domain_error(const string& what_arg) : logic_error(what_arg) {} - virtual ~domain_error() throw() {} + virtual ~domain_error() _UCXX_USE_NOEXCEPT {} }; class _UCXXEXPORT invalid_argument : public logic_error { public: invalid_argument() : logic_error(){} invalid_argument(const string& what_arg) : logic_error(what_arg){} - virtual ~invalid_argument() throw() {} + virtual ~invalid_argument() _UCXX_USE_NOEXCEPT {} }; class _UCXXEXPORT length_error : public logic_error { public: length_error() : logic_error(){} length_error(const string& what_arg) : logic_error(what_arg){} - virtual ~length_error() throw() {} + virtual ~length_error() _UCXX_USE_NOEXCEPT {} }; class _UCXXEXPORT out_of_range : public logic_error{ public: out_of_range(); out_of_range(const string & what_arg); - virtual ~out_of_range() throw() {} + virtual ~out_of_range() _UCXX_USE_NOEXCEPT {} }; @@ -81,15 +81,15 @@ public: runtime_error(); runtime_error(const string& what_arg); - virtual ~runtime_error() throw() {} - virtual const char * what() const throw(); + virtual ~runtime_error() _UCXX_USE_NOEXCEPT {} + virtual const char * what() const _UCXX_USE_NOEXCEPT; }; class _UCXXEXPORT range_error : public runtime_error{ public: range_error() : runtime_error(){} range_error(const string& what_arg) : runtime_error(what_arg) {} - virtual ~range_error() throw(){ } + virtual ~range_error() _UCXX_USE_NOEXCEPT{ } }; @@ -97,14 +97,14 @@ class _UCXXEXPORT overflow_error : public runtime_error{ public: overflow_error() : runtime_error(){} overflow_error(const string& what_arg) : runtime_error(what_arg) {} - virtual ~overflow_error() throw(){} + virtual ~overflow_error() _UCXX_USE_NOEXCEPT{} }; class _UCXXEXPORT underflow_error : public runtime_error{ public: underflow_error() : runtime_error(){} underflow_error(const string& what_arg) : runtime_error(what_arg) {} - virtual ~underflow_error() throw(){} + virtual ~underflow_error() _UCXX_USE_NOEXCEPT{} }; diff --git a/src/stdexcept.cpp b/src/stdexcept.cpp index 90dccc7a..b812b6f7 100644 --- a/src/stdexcept.cpp +++ b/src/stdexcept.cpp @@ -24,7 +24,7 @@ namespace std{ - _UCXXEXPORT logic_error::logic_error() throw() : mstring(){ + _UCXXEXPORT logic_error::logic_error() _UCXX_USE_NOEXCEPT : mstring(){ } @@ -32,7 +32,7 @@ namespace std{ } - _UCXXEXPORT const char * logic_error::what() const throw(){ + _UCXXEXPORT const char * logic_error::what() const _UCXX_USE_NOEXCEPT{ return mstring.c_str(); } @@ -53,7 +53,7 @@ namespace std{ } - _UCXXEXPORT const char * runtime_error::what() const throw(){ + _UCXXEXPORT const char * runtime_error::what() const _UCXX_USE_NOEXCEPT{ return mstring.c_str(); } diff --git a/src/string b/src/string index d22f0515..8cfa8b0d 100644 --- a/src/string +++ b/src/string @@ -70,7 +70,7 @@ public: typedef typename vector::reverse_iterator reverse_iterator; typedef typename vector::const_reverse_iterator const_reverse_iterator; - static const size_type npos = (size_type)-1; + static const size_type npos = static_cast(-1); explicit _UCXXEXPORT basic_string(const A& al = A()) : vector(al){ return; } @@ -84,7 +84,7 @@ public: } if (*s > 0){ resize(n); - Tr::copy(vector::data_, s, vector::elements); + Tr::copy(vector::data, s, vector::elements); } } @@ -112,7 +112,7 @@ public: if(s!=0){ size_type len = Tr::length(s); resize(len); - Tr::copy( vector::data_, s, len); + Tr::copy( vector::data, s, len); } return *this; } @@ -145,7 +145,7 @@ public: _UCXXEXPORT basic_string& append(const basic_string& str){ size_t temp = vector::elements; resize(vector::elements + str.elements); - Tr::copy( vector::data_ + temp, str.vector::data_, str.elements); + Tr::copy( vector::data + temp, str.vector::data, str.elements); return *this; } @@ -164,14 +164,14 @@ public: } size_t temp = vector::elements; resize(vector::elements + rlen); - Tr::copy( vector::data_ + temp, str.vector::data_ + pos, rlen); + Tr::copy( vector::data + temp, str.vector::data + pos, rlen); return *this; } _UCXXEXPORT basic_string& append(const Ch* s, size_type n){ size_t temp = vector::elements; resize(vector::elements + n); - Tr::copy( vector::data_ + temp, s, n); + Tr::copy( vector::data + temp, s, n); return *this; } @@ -179,7 +179,7 @@ public: size_type strLen = Tr::length(s); size_t temp = vector::elements; resize(vector::elements + strLen); - Tr::copy( vector::data_ + temp, s, strLen); + Tr::copy( vector::data + temp, s, strLen); return *this; } @@ -260,8 +260,8 @@ public: } size_type temp = vector::elements; resize(vector::elements + n); - Tr::move(vector::data_ + pos + n, vector::data_ + pos, temp - pos); - Tr::copy(vector::data_ + pos, s, n); + Tr::move(vector::data + pos + n, vector::data + pos, temp - pos); + Tr::copy(vector::data + pos, s, n); return *this; } @@ -406,12 +406,12 @@ public: _UCXXEXPORT const Ch* c_str() const{ const_cast *>(this)->reserve(vector::elements+1); - vector::data_[vector::elements] = 0; //Add 0 at the end - return vector::data_; + vector::data[vector::elements] = 0; //Add 0 at the end + return vector::data; } _UCXXEXPORT const Ch* data() const{ - return vector::data_; + return vector::data; } _UCXXEXPORT allocator_type get_allocator() const{ return vector::a; @@ -579,7 +579,7 @@ public: if(rlen > str.elements){ rlen = str.elements; } - int retval = Tr::compare(vector::data_, str.vector::data_, rlen); + int retval = Tr::compare(vector::data, str.vector::data, rlen); if(retval == 0){ if(vector::elements < str.elements){ retval = -1; @@ -623,7 +623,7 @@ public: if(rlen > vector::elements){ rlen=vector::elements; } - int retval = Tr::compare(vector::data_, s, rlen); + int retval = Tr::compare(vector::data, s, rlen); if(retval==0){ if(vector::elements < slen){ retval = -1; @@ -687,7 +687,7 @@ template _UCXXEXPORT basic_string:: rlen = n; } resize(rlen); - Tr::copy(vector::data_, str.vector::data_ + pos, vector::elements); + Tr::copy(vector::data, str.vector::data + pos, vector::elements); } template _UCXXEXPORT basic_string& @@ -698,7 +698,7 @@ template _UCXXEXPORT basic_string& } vector::clear(); resize(str.elements); - Tr::copy( vector::data_, str.vector::data_, str.elements); + Tr::copy( vector::data, str.vector::data, str.elements); return *this; } @@ -729,7 +729,7 @@ template if(rlen > n){ rlen = n; } - return basic_string(vector::data_ + pos,rlen); + return basic_string(vector::data + pos,rlen); } diff --git a/src/typeinfo b/src/typeinfo index 88a2639b..7863af27 100644 --- a/src/typeinfo +++ b/src/typeinfo @@ -135,20 +135,20 @@ namespace std class bad_cast : public exception { public: - bad_cast() throw() { } + bad_cast() _UCXX_USE_NOEXCEPT { } // This declaration is not useless: // http://gcc.gnu.org/onlinedocs/gcc-3.0.2/gcc_6.html#SEC118 - virtual ~bad_cast() throw(); + virtual ~bad_cast() _UCXX_USE_NOEXCEPT; }; /** If you use a NULL pointer in a @c typeid expression, this is thrown. */ class bad_typeid : public exception { public: - bad_typeid () throw() { } + bad_typeid () _UCXX_USE_NOEXCEPT { } // This declaration is not useless: // http://gcc.gnu.org/onlinedocs/gcc-3.0.2/gcc_6.html#SEC118 - virtual ~bad_typeid() throw(); + virtual ~bad_typeid() _UCXX_USE_NOEXCEPT; }; } // namespace std diff --git a/src/typeinfo.cpp b/src/typeinfo.cpp index b8ea3019..c9f9d23f 100644 --- a/src/typeinfo.cpp +++ b/src/typeinfo.cpp @@ -21,11 +21,11 @@ namespace std{ - _UCXXEXPORT bad_cast::~bad_cast() throw(){ + _UCXXEXPORT bad_cast::~bad_cast() _UCXX_USE_NOEXCEPT{ } - _UCXXEXPORT bad_typeid::~bad_typeid() throw(){ + _UCXXEXPORT bad_typeid::~bad_typeid() _UCXX_USE_NOEXCEPT{ } diff --git a/src/unwind-cxx.h b/src/unwind-cxx.h index e0013435..999aba36 100644 --- a/src/unwind-cxx.h +++ b/src/unwind-cxx.h @@ -140,18 +140,18 @@ struct __cxa_eh_globals // either of the following functions. The "fast" version assumes at least // one prior call of __cxa_get_globals has been made from the current // thread, so no initialization is necessary. -extern "C" __cxa_eh_globals *__cxa_get_globals () throw(); -extern "C" __cxa_eh_globals *__cxa_get_globals_fast () throw(); +extern "C" __cxa_eh_globals *__cxa_get_globals () _UCXX_USE_NOEXCEPT; +extern "C" __cxa_eh_globals *__cxa_get_globals_fast () _UCXX_USE_NOEXCEPT; // Allocate memory for the primary exception plus the thrown object. -extern "C" void *__cxa_allocate_exception(std::size_t thrown_size) throw(); +extern "C" void *__cxa_allocate_exception(std::size_t thrown_size) _UCXX_USE_NOEXCEPT; // Allocate memory for dependent exception. -extern "C" __cxa_dependent_exception *__cxa_allocate_dependent_exception() throw(); +extern "C" __cxa_dependent_exception *__cxa_allocate_dependent_exception() _UCXX_USE_NOEXCEPT; // Free the space allocated for the primary exception. -extern "C" void __cxa_free_exception(void *thrown_exception) throw(); +extern "C" void __cxa_free_exception(void *thrown_exception) _UCXX_USE_NOEXCEPT; // Free the space allocated for the dependent exception. -extern "C" void __cxa_free_dependent_exception(__cxa_dependent_exception *dependent_exception) throw(); +extern "C" void __cxa_free_dependent_exception(__cxa_dependent_exception *dependent_exception) _UCXX_USE_NOEXCEPT; // Throw the exception. extern "C" void __cxa_throw (void *thrown_exception, @@ -160,7 +160,7 @@ extern "C" void __cxa_throw (void *thrown_exception, __attribute__((noreturn)); // Used to implement exception handlers. -extern "C" void *__cxa_begin_catch (void *) throw(); +extern "C" void *__cxa_begin_catch (void *) _UCXX_USE_NOEXCEPT; extern "C" void __cxa_end_catch (); extern "C" void __cxa_rethrow () __attribute__((noreturn)); @@ -177,7 +177,7 @@ extern "C" void __cxa_call_unexpected (void *) __attribute__((noreturn)); // Invokes given handler, dying appropriately if the user handler was // so inconsiderate as to return. -extern void __terminate(std::terminate_handler) throw () __attribute__((noreturn)); +extern void __terminate(std::terminate_handler) _UCXX_USE_NOEXCEPT __attribute__((noreturn)); extern void __unexpected(std::unexpected_handler) __attribute__((noreturn)); // The current installed user handlers. diff --git a/src/vector b/src/vector index f8cb4107..3cf64ed6 100644 --- a/src/vector +++ b/src/vector @@ -24,7 +24,7 @@ #include #include #include -#include + #ifndef __STD_HEADER_VECTOR #define __STD_HEADER_VECTOR @@ -59,26 +59,26 @@ namespace std{ typedef std::reverse_iterator reverse_iterator; typedef std::reverse_iterator const_reverse_iterator; - explicit _UCXXEXPORT vector(const Allocator& al= Allocator()): data_(0), //defaultValue(T()), + explicit _UCXXEXPORT vector(const Allocator& al= Allocator()): data(0), //defaultValue(T()), data_size(__UCLIBCXX_STL_BUFFER_SIZE__), elements(0), a(al) { - data_ = a.allocate(data_size); + data = a.allocate(data_size); } explicit _UCXXEXPORT vector(size_type n, const T& value = T(), const Allocator& al= Allocator()) : - data_(0), data_size(0), elements(0), a(al) + data(0), data_size(0), elements(0), a(al) { data_size = n + __UCLIBCXX_STL_BUFFER_SIZE__; - data_ = a.allocate(data_size); + data = a.allocate(data_size); resize(n, value); } template _UCXXEXPORT vector(InputIterator first, InputIterator last, const Allocator& al = Allocator()): - data_(0), data_size(__UCLIBCXX_STL_BUFFER_SIZE__), elements(0), a(al) + data(0), data_size(__UCLIBCXX_STL_BUFFER_SIZE__), elements(0), a(al) { - data_ = a.allocate(data_size); + data = a.allocate(data_size); assign(first, last); } @@ -87,23 +87,13 @@ namespace std{ elements = x.elements; data_size = elements + __UCLIBCXX_STL_BUFFER_SIZE__; - data_ = a.allocate(data_size); + data = a.allocate(data_size); for(size_type i = 0; i < elements; i++){ - a.construct(data_+i, x.data_[i]); + a.construct(data+i, x.data[i]); } } - _UCXXEXPORT vector(initializer_list in, const Allocator & al=Allocator()) : - a(al) - { - data_size = in.size() + __UCLIBCXX_STL_BUFFER_SIZE__; - elements = in.size(); - data_ = a.allocate(data_size); - for(size_type i = 0; i < elements; i++) - a.construct(data_+i, *(in.begin()+i)); - } - _UCXXEXPORT ~vector(); //Below _UCXXEXPORT vector& operator=(const vector& x){ @@ -121,13 +111,13 @@ namespace std{ minElements = x.elements; } for(size_t i = 0; i < minElements; ++i){ - data_[i] = x.data_[i]; + data[i] = x.data[i]; } //If we need to add new elements if(elements < x.elements){ for(size_t i = elements; i< x.elements; ++i){ - a.construct(data_+i, x.data_[i]); + a.construct(data+i, x.data[i]); ++elements; } } @@ -149,29 +139,24 @@ namespace std{ resize(n, u); } - _UCXXEXPORT void assign(initializer_list in){ - clear(); - insert(begin(), in.begin(), in.end()); - } - inline allocator_type get_allocator() const{ return a; } inline iterator begin(){ - return data_; + return data; } inline const_iterator begin() const{ - return data_; + return data; } inline iterator end(){ - return (data_ + elements); + return (data + elements); } inline const_iterator end() const{ - return (data_ + elements); + return (data + elements); } inline reverse_iterator rbegin(){ @@ -195,7 +180,7 @@ namespace std{ } _UCXXEXPORT size_type max_size() const{ - return ((size_type)(-1)) / sizeof(T); + return static_cast(-1) / sizeof(T); } void downsize(size_type sz); @@ -209,48 +194,44 @@ namespace std{ return (size() == 0); } - inline T* data() noexcept { return data_; } - - inline const T* data() const noexcept { return data_; } - void reserve(size_type n); inline reference operator[](size_type n){ - return data_[n]; + return data[n]; } inline const_reference operator[](size_type n) const{ - return data_[n]; + return data[n]; } _UCXXEXPORT const_reference at(size_type n) const{ if(n >= elements){ __throw_out_of_range("Invalid subscript"); } - return data_[n]; + return data[n]; } _UCXXEXPORT reference at(size_type n){ if(n >= elements){ __throw_out_of_range("Invalid subscript"); } - return data_[n]; + return data[n]; } inline reference front(){ - return data_[0]; + return data[0]; } inline const_reference front() const{ - return data_[0]; + return data[0]; } inline reference back(){ - return data_[ size() - 1]; + return data[ size() - 1]; } inline const_reference back() const{ - return data_[ size() - 1 ]; + return data[ size() - 1 ]; } inline void push_back(const T& x){ @@ -262,24 +243,24 @@ namespace std{ } _UCXXEXPORT iterator insert(iterator position, const T& x = T()){ - size_type index = position - data_; + size_type index = position - data; resize(size() + 1, x); for(size_type i = elements - 1; i > index; --i){ - data_[i] = data_[i-1]; + data[i] = data[i-1]; } - data_[index] = x; - return (data_ + index); + data[index] = x; + return (data + index); } _UCXXEXPORT void _insert_fill(iterator position, size_type n, const T & x){ - size_type index = position - data_; + size_type index = position - data; resize(size() + n, x); for(size_type i = elements -1; (i > (index+n-1)); --i){ - data_[i] = data_[i-n]; + data[i] = data[i-n]; } for(size_type i = 0; i < n; i++){ - data_[i + index] = x; + data[i + index] = x; } } @@ -317,22 +298,22 @@ namespace std{ } _UCXXEXPORT iterator erase(iterator position){ - size_type index = position - data_; + size_type index = position - data; for(size_type i = index; i < (elements - 1); ++i){ - data_[i] = data_[i+1]; + data[i] = data[i+1]; } downsize(size() - 1); - return (data_ + index); + return (data + index); } _UCXXEXPORT iterator erase(iterator first, iterator last){ - size_type index = first - data_; + size_type index = first - data; size_type width = last - first; for(size_type i = index; i < (elements - width) ;++i){ - data_[i] = data_[i+width]; + data[i] = data[i+width]; } downsize(size() - width); - return (data_ + index); + return (data + index); } _UCXXEXPORT void swap(vector& v){ @@ -343,9 +324,9 @@ namespace std{ size_type temp; //Swap pointers first - ptr = data_; - data_ = v.data_; - v.data_ = ptr; + ptr = data; + data = v.data; + v.data = ptr; //Swap element counts temp = elements; @@ -363,7 +344,7 @@ namespace std{ } protected: - T* data_; + T* data; size_type data_size; size_type elements; Allocator a; @@ -375,22 +356,22 @@ namespace std{ template _UCXXEXPORT vector::~vector(){ for(size_t i = 0; i < elements; ++i){ - a.destroy(data_ + i); + a.destroy(data + i); } - a.deallocate(data_, data_size); + a.deallocate(data, data_size); } template _UCXXEXPORT void vector::reserve(size_type n){ if(n > data_size){ //We never shrink... - T * temp_ptr = data_; + T * temp_ptr = data; size_type temp_size = data_size; data_size = n; - data_ = a.allocate(data_size); + data = a.allocate(data_size); for(size_type i = 0; i _UCXXEXPORT void vector::downsize(size_type sz){ if(sz < elements){ //Actually are downsizing for(size_t i = sz; i< elements; ++i){ - a.destroy(data_+i); + a.destroy(data+i); } elements = sz; }