diff --git a/algorithm b/algorithm index 7c830ed..58bb496 100644 --- a/algorithm +++ b/algorithm @@ -17,7 +17,7 @@ #include #include -#include +#include #include #ifndef __STD_HEADER_ALGORITHM @@ -120,14 +120,14 @@ namespace std{ } ++temp2; } - + } return last1; } template _UCXXEXPORT ForwardIterator1 - find_first_of(ForwardIterator1 first1, ForwardIterator1 last1, + find_first_of(ForwardIterator1 first1, ForwardIterator1 last1, ForwardIterator2 first2, ForwardIterator2 last2, BinaryPredicate pred) { @@ -139,7 +139,7 @@ namespace std{ } ++temp2; } - + } return last1; } @@ -204,7 +204,7 @@ namespace std{ } template _UCXXEXPORT - pair + pair mismatch(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2) { while(first1 != last1){ @@ -274,7 +274,7 @@ namespace std{ ForwardIterator2 first2, ForwardIterator2 last2) { equal_to::value_type> c; - return search(first1, last1, first2, last2, c); + return search(first1, last1, first2, last2, c); } @@ -322,7 +322,7 @@ namespace std{ } ++first; } - return first; + return first; } @@ -346,7 +346,7 @@ namespace std{ } ++first; } - return first; + return first; } @@ -810,7 +810,7 @@ namespace std{ } } - //Rotate the element back to the begining + //Rotate the element back to the beginning tempb = tempe; while(tempb != first){ iter_swap(tempb, tempb-1 ); @@ -830,12 +830,6 @@ namespace std{ sort(first, last, c ); } - template _UCXXEXPORT - void sort(RandomAccessIterator first, RandomAccessIterator last, Compare comp) - { - stable_sort(first, last, comp); - } - template _UCXXEXPORT void stable_sort(RandomAccessIterator first, RandomAccessIterator last) { @@ -861,6 +855,12 @@ namespace std{ } } + template _UCXXEXPORT + void sort(RandomAccessIterator first, RandomAccessIterator last, Compare comp) + { + stable_sort(first, last, comp); + } + template _UCXXEXPORT void partial_sort(RandomAccessIterator first, RandomAccessIterator middle, RandomAccessIterator last) { @@ -965,7 +965,7 @@ namespace std{ return last; } - //Now begin the actual search for the begining + //Now begin the actual search for the beginning while( distance(first, last) > 1 ){ //Find middle middle = first; @@ -976,7 +976,7 @@ namespace std{ first = middle; } } - + if( !comp(*first, value) ){ return first; } @@ -1024,7 +1024,7 @@ namespace std{ first = middle; } } - + if( comp(value, *first) ){ return first; } @@ -1084,10 +1084,10 @@ namespace std{ if( !comp(*first, value) && !comp(value, *first) ){ return true; - } + } if( !comp(*last, value) && !comp(value, *last) ){ return true; - } + } return false; } @@ -1301,7 +1301,7 @@ namespace std{ while( first2 != last2 && !comp( *temp, *first2) ){ ++first2; } - + }else{ //They are identical - skip //Elliminate duplicates InputIterator1 temp = first1; @@ -1356,7 +1356,7 @@ namespace std{ while( first2 != last2 && !comp( *temp, *first2) ){ ++first2; } - + }else{ //They are identical - skip //Elliminate duplicates InputIterator1 temp = first1; @@ -1428,7 +1428,7 @@ namespace std{ middle = end; } - //Now all we do is swap the elements up to the begining + //Now all we do is swap the elements up to the beginning --last; while(last > middle){ @@ -1630,7 +1630,7 @@ namespace std{ return false; } } - + } @@ -1640,7 +1640,7 @@ namespace std{ less::value_type> c; return prev_permutation(first, last, c); } - + template _UCXXEXPORT bool prev_permutation(BidirectionalIterator first, BidirectionalIterator last, Compare comp) { diff --git a/associative_base b/associative_base index 7616243..061ac1f 100644 --- a/associative_base +++ b/associative_base @@ -19,7 +19,7 @@ #include -#include +#include #include #include #include @@ -39,7 +39,7 @@ namespace std{ * considerations about how to address multiple entries with the same key. * The goal is that the tree/storage code should be here, and managing * single or multiple counts will be left to subclasses. - * Yes, inheritence for the purpose of code sharing is usually a bad idea. + * Yes, inheritance for the purpose of code sharing is usually a bad idea. * However, since our goal is to reduce the total amount of code written * and the overall binary size, this seems to be the best approach possible. */ @@ -161,7 +161,7 @@ public: } return retval; } - const_iterator find(const key_type& x) const{ + const_iterator find(const key_type& x) const{ const_iterator retval = lower_bound(x); if(retval == end()){ return retval; @@ -171,7 +171,7 @@ public: } return retval; } - size_type count(const key_type& x) const{ + size_type count(const key_type& x) const{ size_type retval(0); const_iterator first = lower_bound(x); while(first != end() && !c(x, value_to_key(*first))){ @@ -188,7 +188,7 @@ public: void erase(iterator pos){ backing.erase(pos.base_iterator()); } - size_type erase(const key_type& x){ + size_type erase(const key_type& x){ size_type count(0); iterator start = lower_bound(x); iterator end = upper_bound(x); @@ -198,7 +198,7 @@ public: } return count; } - void erase(iterator first, iterator last){ + void erase(iterator first, iterator last){ while(first != last){ backing.erase(first.base_iterator()); ++first; @@ -604,7 +604,7 @@ public: } iterator insert(const value_type& x){ - iterator location = lower_bound(value_to_key(x)); + iterator location = lower_bound(this->value_to_key(x)); if(location == begin()){ backing.push_front(x); diff --git a/bitset b/bitset index 24b63cb..50d5404 100644 --- a/bitset +++ b/bitset @@ -210,7 +210,7 @@ namespace std{ return *this; } bitset& reset(){ - for(size_t i = 0; i <= num_bytes; ++i){ + for(size_t i = 0; i < num_bytes; ++i){ data[i] = 0; } return *this; @@ -226,7 +226,7 @@ namespace std{ } bitset& flip(){ - for(size_t i = 0; i <= num_bytes; ++i){ + for(size_t i = 0; i < num_bytes; ++i){ data[i] = ~data[i]; } return *this; diff --git a/cmath b/cmath index 1f476ab..556987e 100644 --- a/cmath +++ b/cmath @@ -22,8 +22,153 @@ #ifndef __STD_HEADER_CMATH #define __STD_HEADER_CMATH 1 -namespace std{ -#if ! defined(__AVR__) +# undef abs +# undef acos +# undef asin +# undef atan +# undef atan2 +# undef ceil +# undef cos +# undef cosh +# undef exp +# undef fabs +# undef floor +# undef fmod +# undef frexp +# undef ldexp +# undef log +# undef log10 +# undef modf +# undef pow +# undef sin +# undef sinh +# undef sqrt +# undef tan +# undef tanh + +// Workaround for older (at least pre-1.8.0) versions of avr-libc's copy +// of math.h - on that platform doubles and floats are interchangeable. +# if defined(__AVR__) && __SIZEOF_FLOAT__ == __SIZEOF_DOUBLE__ +# ifndef fabsf +# define fabsf fabs +# define WORKAROUND_fabs +# endif + +# ifndef acosf +# define acosf acos +# define WORKAROUND_acos +# endif + +# ifndef asinf +# define asinf asin +# define WORKAROUND_asin +# endif + +# ifndef atanf +# define atanf atan +# define WORKAROUND_atan +# endif + +# ifndef atan2f +# define atan2f atan2 +# define WORKAROUND_atan2 +# endif + +# ifndef ceilf +# define ceilf ceil +# define WORKAROUND_ceil +# endif + +# ifndef cosf +# define cosf cos +# define WORKAROUND_cos +# endif + +# ifndef coshf +# define coshf cosh +# define WORKAROUND_cosh +# endif + +# ifndef expf +# define expf exp +# define WORKAROUND_exp +# endif + +# ifndef fabsf +# define fabsf fabs +# define WORKAROUND_fabs +# endif + +# ifndef floorf +# define floorf floor +# define WORKAROUND_floor +# endif + +# ifndef fmodf +# define fmodf fmod +# define WORKAROUND_fmod +# endif + +# ifndef frexpf +# define frexpf frexp +# define WORKAROUND_frexp +# endif + +# ifndef ldexpf +# define ldexpf ldexp +# define WORKAROUND_ldexp +# endif + +# ifndef logf +# define logf log +# define WORKAROUND_log +# endif + +# ifndef log10f +# define log10f log10 +# define WORKAROUND_log10 +# endif + +# ifndef modff +# define WORKAROUND_modf +# endif + +# ifndef powf +# define powf pow +# define WORKAROUND_pow +# endif + +# ifndef sinf +# define sinf sin +# define WORKAROUND_sin +# endif + +# ifndef sinhf +# define sinhf sinh +# define WORKAROUND_sinh +# endif + +# ifndef sqrtf +# define sqrtf sqrt +# define WORKAROUND_sqrt +# endif + +# ifndef tanf +# define tanf tan +# define WORKAROUND_tan +# endif + +# ifndef tanhf +# define tanhf tanh +# define WORKAROUND_tanh +# endif + +# endif // AVR workaround + + + +namespace std { + using ::acos; using ::asin; using ::atan; @@ -47,161 +192,288 @@ namespace std{ using ::tan; using ::tanh; +# ifndef __CORRECT_ISO_CPP_MATH_H_PROTO inline float abs (float x){ - return fabsf(x); + return ::fabsf(x); } inline float acos (float x){ - return acosf(x); + return ::acosf(x); } inline float asin (float x){ - return asinf(x); + return ::asinf(x); } inline float atan (float x){ - return atanf(x); + return ::atanf(x); } inline float atan2(float y, float x){ - return atan2f(y, x); + return ::atan2f(y, x); } inline float ceil (float x){ - return ceilf(x); + return ::ceilf(x); } inline float cos (float x){ - return cosf(x); + return ::cosf(x); } inline float cosh (float x){ - return coshf(x); + return ::coshf(x); } inline float exp (float x){ - return expf(x); + return ::expf(x); } inline float fabs (float x){ - return fabsf(x); + return ::fabsf(x); } inline float floor(float x){ - return floorf(x); + return ::floorf(x); } inline float fmod (float x, float y){ - return fmodf(x, y); + return ::fmodf(x, y); } inline float frexp(float x, int* exp){ - return frexpf(x, exp); + return ::frexpf(x, exp); } inline float ldexp(float x, int exp){ - return ldexpf(x, exp); + return ::ldexpf(x, exp); } inline float log (float x){ - return logf(x); + return ::logf(x); } inline float log10(float x){ - return log10f(x); + return ::log10f(x); } inline float modf (float x, float* inptr){ - return modff(x, inptr); +# ifdef WORKAROUND_modf + double intpart; + float ret = static_cast(::modf(static_cast(x), & intpart)); + *inptr = static_cast(intpart); + return ret; +# else + return ::modff(x, inptr); +# endif } inline float pow (float x, float y){ - return powf(x, y); + return ::powf(x, y); } +# if 1 // DR 550 removed this inline float pow (float x, int y){ - return pow((double)x, (double)y); + return ::pow((double)x, (double)y); } +# endif inline float sin (float x){ - return sinf(x); + return ::sinf(x); } inline float sinh (float x){ - return sinhf(x); + return ::sinhf(x); } inline float sqrt (float x){ - return sqrtf(x); + return ::sqrtf(x); } inline float tan (float x){ - return tanf(x); + return ::tanf(x); } inline float tanh (float x){ - return tanhf(x); + return ::tanhf(x); } inline double abs(double x){ - return fabs(x); + return ::fabs(x); } inline double pow(double x, int y){ - return pow((double)x, (double)y); + return ::pow((double)x, (double)y); } -#ifdef __UCLIBCXX_HAS_LONG_DOUBLE__ +# ifdef __UCLIBCXX_HAS_LONG_DOUBLE__ inline long double abs (long double x){ - return fabsl(x); + return ::fabsl(x); } inline long double acos (long double x){ - return acosl(x); + return ::acosl(x); } inline long double asin (long double x){ - return asinl(x); + return ::asinl(x); } inline long double atan (long double x){ - return atanl(x); + return ::atanl(x); } inline long double atan2(long double y, long double x){ - return atan2l(y, x); + return ::atan2l(y, x); } inline long double ceil (long double x){ - return ceill(x); + return ::ceill(x); } inline long double cos (long double x){ - return cosl(x); + return ::cosl(x); } inline long double cosh (long double x){ - return coshl(x); + return ::coshl(x); } inline long double exp (long double x){ - return expl(x); + return ::expl(x); } inline long double fabs (long double x){ - return fabsl(x); + return ::fabsl(x); } inline long double floor(long double x){ - return floorl(x); + return ::floorl(x); } inline long double frexp(long double x, int* exp){ - return frexpl(x, exp); + return ::frexpl(x, exp); } inline long double fmod (long double x, long double y){ - return fmodl(x, y); + return ::fmodl(x, y); } inline long double ldexp(long double x, int y){ - return ldexpl(x, y); + return ::ldexpl(x, y); } inline long double log (long double x){ - return logl(x); + return ::logl(x); } inline long double log10(long double x){ - return log10l(x); + return ::log10l(x); } inline long double modf (long double x, long double* iptr){ - return modfl(x, iptr); + return ::modfl(x, iptr); } inline long double pow (long double x, long double y){ - return powl(x, y); + return ::powl(x, y); } inline long double pow (long double x, int y){ - return powl(x, (long double)y ); + return ::powl(x, (long double)y ); } inline long double sin (long double x){ - return sinl(x); + return ::sinl(x); } inline long double sinh (long double x){ - return sinhl(x); + return ::sinhl(x); } inline long double sqrt (long double x){ - return sqrtl(x); + return ::sqrtl(x); } inline long double tan (long double x){ - return tanl(x); + return ::tanl(x); } inline long double tanh (long double x){ - return tanhl(x); + return ::tanhl(x); } -#endif // __UCLIBCXX_HAS_LONG_DOUBLE__ -#endif // ! defined(__AVR__) +# endif // __UCLIBCXX_HAS_LONG_DOUBLE__ +# endif // __CORRECT_ISO_CPP_MATH_H_PROTO } +// Undo AVR workaround, if applied + +# ifdef WORKAROUND_fabs +# undef fabsf +# undef WORKAROUND_fabs +# endif + +# ifdef WORKAROUND_acos +# undef acosf +# undef WORKAROUND_acos +# endif + +# ifdef WORKAROUND_asin +# undef asinf +# undef WORKAROUND_asin +# endif + +# ifdef WORKAROUND_atan +# undef atanf +# undef WORKAROUND_atan +# endif + +# ifdef WORKAROUND_atan2 +# undef atan2f +# undef WORKAROUND_atan2 +# endif + +# ifdef WORKAROUND_ceil +# undef ceilf +# undef WORKAROUND_ceil +# endif + +# ifdef WORKAROUND_cos +# undef cosf +# undef WORKAROUND_cos +# endif + +# ifdef WORKAROUND_cosh +# undef coshf +# undef WORKAROUND_cosh +# endif + +# ifdef WORKAROUND_exp +# undef expf +# undef WORKAROUND_exp +# endif + +# ifdef WORKAROUND_fabs +# undef fabsf +# undef WORKAROUND_fabs +# endif + +# ifdef WORKAROUND_floor +# undef floorf +# undef WORKAROUND_floor +# endif + +# ifdef WORKAROUND_fmod +# undef fmodf +# undef WORKAROUND_fmod +# endif + +# ifdef WORKAROUND_frexp +# undef frexpf +# undef WORKAROUND_frexp +# endif + +# ifdef WORKAROUND_ldexp +# undef ldexpf +# undef WORKAROUND_ldexp +# endif + +# ifdef WORKAROUND_log +# undef logf +# undef WORKAROUND_log +# endif + +# ifdef WORKAROUND_log10 +# undef log10f +# undef WORKAROUND_log10 +# endif + +# ifdef WORKAROUND_modf +# undef modff +# undef WORKAROUND_modf +# endif + +# ifdef WORKAROUND_pow +# undef powf +# undef WORKAROUND_pow +# endif + +# ifdef WORKAROUND_sin +# undef sinf +# undef WORKAROUND_sin +# endif + +# ifdef WORKAROUND_sinh +# undef sinhf +# undef WORKAROUND_sinh +# endif + +# ifdef WORKAROUND_sqrt +# undef sqrtf +# undef WORKAROUND_sqrt +# endif + +# ifdef WORKAROUND_tan +# undef tanf +# undef WORKAROUND_tan +# endif + +# ifdef WORKAROUND_tanh +# undef tanhf +# undef WORKAROUND_tanh +# endif + #endif //__STD_HEADER_CMATH diff --git a/cstdlib b/cstdlib index fc2f50f..e2834e0 100644 --- a/cstdlib +++ b/cstdlib @@ -30,7 +30,14 @@ namespace std{ using ::system; #endif // ! defined(__AVR__) using ::abort; +#if defined(abs) +# undef abs + inline int abs(int v) { + return __builtin_abs(v); + } +#else using ::abs; +#endif using ::atol; using ::atof; using ::atoi; diff --git a/exception b/exception index 87cb103..bdf393e 100644 --- a/exception +++ b/exception @@ -9,12 +9,12 @@ // it under the terms of the GNU General Public License as published by // the Free Software Foundation; either version 2, or (at your option) // any later version. -// +// // GNU CC 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 General Public License for more details. -// +// // You should have received a copy of the GNU General Public License // along with GNU CC; see the file COPYING. If not, write to // the Free Software Foundation, 59 Temple Place - Suite 330, @@ -41,7 +41,7 @@ extern "C++" { -namespace std +namespace std { /** * @brief Base class for all library exceptions. @@ -51,7 +51,7 @@ namespace std * your own %exception classes, or use a different hierarchy, or to * throw non-class data (e.g., fundamental types). */ - class exception + class exception { public: exception() throw() { } @@ -63,7 +63,7 @@ namespace std /** If an %exception is thrown which is not listed in a function's * %exception specification, one of these may be thrown. */ - class bad_exception : public exception + class bad_exception : public exception { public: bad_exception() throw() { } @@ -114,7 +114,7 @@ namespace __gnu_cxx */ void __verbose_terminate_handler (); } // namespace __gnu_cxx - + } // extern "C++" #endif diff --git a/fstream b/fstream index 2e2f2a8..4345e81 100644 --- a/fstream +++ b/fstream @@ -29,6 +29,8 @@ #include #include +#ifndef __AVR__ // AVR-LibC has no concept of a file. + #include #include #include @@ -72,9 +74,9 @@ namespace std{ pbuffer = new char_type[__UCLIBCXX_IOSTREAM_BUFSIZE__]; gbuffer = new char_type[__UCLIBCXX_IOSTREAM_BUFSIZE__]; - setp(pbuffer, pbuffer + __UCLIBCXX_IOSTREAM_BUFSIZE__); + this->setp(pbuffer, pbuffer + __UCLIBCXX_IOSTREAM_BUFSIZE__); //Position get buffer so that there is no data available - setg(gbuffer, gbuffer + __UCLIBCXX_IOSTREAM_BUFSIZE__, + this->setg(gbuffer, gbuffer + __UCLIBCXX_IOSTREAM_BUFSIZE__, gbuffer + __UCLIBCXX_IOSTREAM_BUFSIZE__); } @@ -221,7 +223,7 @@ namespace std{ if(basic_streambuf::eback() == basic_streambuf::gptr()){ //Buffer is full return traits::to_int_type(*basic_streambuf::gptr()); } - //Shift entire buffer back to the begining + //Shift entire buffer back to the beginning size_t offset = basic_streambuf::gptr() - basic_streambuf::eback(); size_t amountData = basic_streambuf::egptr() - basic_streambuf::gptr(); @@ -647,7 +649,6 @@ template <> _UCXXEXPORT basic_filebuf >::int_type }; -#if 0 #ifdef __UCLIBCXX_EXPAND_FSTREAM_CHAR__ #ifndef __UCLIBCXX_COMPILE_FSTREAM__ @@ -663,16 +664,15 @@ template <> _UCXXEXPORT basic_filebuf >::int_type #endif // __UCLIBCXX_EXPAND_CONSTRUCTORS_DESTRUCTORS__ -#endif - #endif #endif - - } #pragma GCC visibility pop + +#endif // __AVR__ + #endif diff --git a/fstream.cpp b/fstream.cpp index 61a8540..af93d93 100644 --- a/fstream.cpp +++ b/fstream.cpp @@ -175,4 +175,4 @@ template <> _UCXXEXPORT basic_filebuf >::int_type } -#endif // not ARDUINO +#endif // not __AVR__ diff --git a/functional b/functional index 8a9dd3b..b7932e2 100644 --- a/functional +++ b/functional @@ -60,7 +60,7 @@ namespace std{ template class pointer_to_unary_function; template pointer_to_unary_function ptr_fun(Result (*)(Arg)); template class pointer_to_binary_function; - template + template pointer_to_binary_function ptr_fun(Result (*)(Arg1,Arg2)); template class mem_fun_t; @@ -165,7 +165,7 @@ namespace std{ return (x && y); } }; - + template struct _UCXXEXPORT logical_or : binary_function { bool operator()(const T& x, const T& y) const{ return (x || y); @@ -218,7 +218,7 @@ namespace std{ template class _UCXXEXPORT binder1st - : public unary_function { protected: @@ -231,7 +231,7 @@ namespace std{ } }; - + template _UCXXEXPORT binder1st bind1st(const Operation& op, const T& x){ return binder1st(op, typename Operation::first_argument_type(x)); } @@ -251,15 +251,15 @@ namespace std{ } }; - - template _UCXXEXPORT + + template _UCXXEXPORT binder2nd bind2nd(const Operation& op, const T& x) { return binder2nd(op, typename Operation::second_argument_type(x)); } - - template class _UCXXEXPORT + + template class _UCXXEXPORT pointer_to_unary_function : public unary_function { protected: @@ -271,13 +271,13 @@ namespace std{ } }; - + template _UCXXEXPORT pointer_to_unary_function ptr_fun(Result (*f)(Arg)){ return pointer_to_unary_function(f); } - - template class _UCXXEXPORT + + template class _UCXXEXPORT pointer_to_binary_function : public binary_function { protected: @@ -289,13 +289,13 @@ namespace std{ } }; - template _UCXXEXPORT + template _UCXXEXPORT pointer_to_binary_function ptr_fun(Result (*f)(Arg1, Arg2)) { return pointer_to_binary_function(f); } - + template class _UCXXEXPORT mem_fun_t : public unary_function { @@ -361,11 +361,11 @@ namespace std{ { public: explicit mem_fun_ref_t(S (T::*p)()) : mf(p) { } - S operator()(T& p) { return (p.*mf)(); } + S operator()(T& p) { return (p.*mf)(); } private: S (T::*mf)(); }; - + template class _UCXXEXPORT mem_fun1_ref_t : public binary_function { @@ -405,13 +405,13 @@ public: } }; -template _UCXXEXPORT +template _UCXXEXPORT inline unary_compose compose1(const Op1& fn1, const Op2& fn2){ return unary_compose(fn1, fn2); } -template class _UCXXEXPORT binary_compose : +template class _UCXXEXPORT binary_compose : public std::unary_function { protected: diff --git a/ios b/ios index 44ec166..63dc4ed 100644 --- a/ios +++ b/ios @@ -38,7 +38,7 @@ namespace std{ #ifdef __UCLIBCXX_EXCEPTION_SUPPORT__ class failure : public exception { public: - explicit failure(const std::string& msg) { } + explicit failure(const std::string&) { } explicit failure() { } virtual const char* what() const throw() { return "std::ios_base failure exception"; @@ -150,7 +150,7 @@ namespace std{ inline static bool sync_with_stdio(bool = true) { return true; } protected: - _UCXXEXPORT ios_base() : mLocale(), mformat(dec | skipws ), mstate(goodbit), + _UCXXEXPORT ios_base() : mLocale(), mformat(dec | skipws ), mstate(goodbit), mmode(), mdir(), mprecision(6), mwidth(0) #ifdef __UCLIBCXX_SUPPORT_CDIR__ ,mInit() @@ -355,7 +355,7 @@ namespace std{ _UCXXEXPORT basic_ostream* tie(basic_ostream* tiestr){ basic_ostream* retval= mtied; mtied = tiestr; - return retval; + return retval; } _UCXXEXPORT basic_streambuf* rdbuf() const{ return mstreambuf; @@ -398,7 +398,7 @@ namespace std{ #ifdef __UCLIBCXX_EXPAND_IOS_CHAR__ #ifndef __UCLIBCXX_COMPILE_IOS__ - + template <> _UCXXEXPORT void basic_ios >::clear(iostate state); template <> _UCXXEXPORT void basic_ios >::setstate(iostate state); @@ -432,14 +432,14 @@ namespace std{ #endif //__UCLIBCXX_HAS_WCHAR__ - template + template inline typename basic_ios::char_type basic_ios::widen(char c) const { return c; } - template <> + template <> inline basic_ios >::char_type basic_ios >::widen(char c) const { @@ -448,7 +448,7 @@ namespace std{ #ifdef __UCLIBCXX_HAS_WCHAR__ - template <> + template <> inline basic_ios >::char_type basic_ios >::widen(char c) const { @@ -473,7 +473,7 @@ namespace std{ return st == rhs.st; } _UCXXEXPORT bool operator!=(const fpos &rhs){ - return st == rhs.st; + return st != rhs.st; } _UCXXEXPORT fpos & operator+(const streamoff & o){ st += o; @@ -487,7 +487,6 @@ namespace std{ return st - rhs.st; } - private: stateT st; }; diff --git a/ios.cpp b/ios.cpp index 247bb98..d4312c0 100644 --- a/ios.cpp +++ b/ios.cpp @@ -61,8 +61,6 @@ namespace std{ _UCXXEXPORT wfilebuf _wclog_filebuf; #endif - - //Then create streams #ifdef __UCLIBCXX_SUPPORT_COUT__ _UCXXEXPORT ostream cout(&_cout_filebuf); @@ -106,7 +104,7 @@ namespace std{ _UCXXEXPORT ios_base::Init::Init(){ if(init_cnt == 0){ //Need to construct cout et al -#ifndef ARDUINO +#ifndef __AVR__ #ifdef __UCLIBCXX_SUPPORT_COUT__ _cout_filebuf.fp = stdout; @@ -151,7 +149,7 @@ namespace std{ wcin.tie(&wcout); #endif -#endif // not Arduino +#endif // not __AVR__ #endif // not CDIR } diff --git a/istream b/istream index caeda5d..d67f48f 100644 --- a/istream +++ b/istream @@ -42,23 +42,23 @@ namespace std{ virtual public basic_ios { public: - + typedef charT char_type; typedef typename traits::int_type int_type; typedef typename traits::pos_type pos_type; typedef typename traits::off_type off_type; typedef basic_streambuf streambuf_type; typedef traits traits_type; - + explicit basic_istream(basic_streambuf* sb) : basic_ios(sb), count_last_ufmt_input(0) { basic_ios::init(sb); } virtual ~basic_istream() { } - + class sentry; - + basic_istream& operator>>(basic_istream& (*pf)(basic_istream&)); basic_istream& operator>>(basic_ios& (*pf)(basic_ios&)); basic_istream& operator>>(ios_base& (*pf)(ios_base&)); @@ -77,18 +77,18 @@ namespace std{ basic_istream& operator>>(double& f); basic_istream& operator>>(long double& f); #endif - + _UCXXEXPORT streamsize gcount() const{ return count_last_ufmt_input; } - + _UCXXEXPORT int_type get(); //below - _UCXXEXPORT basic_istream& get(char_type& c); //Below - + _UCXXEXPORT basic_istream& get(char_type& c); //Below + _UCXXEXPORT basic_istream& get(char_type* s, streamsize n){ return get(s, n, basic_ios::widen('\n')); } - + _UCXXEXPORT basic_istream& get(char_type* s, streamsize n, char_type delim){ sentry(*this, true); streamsize i = 0; @@ -117,11 +117,11 @@ namespace std{ count_last_ufmt_input = i; return *this; } - + _UCXXEXPORT basic_istream& get(basic_streambuf& sb){ return get(sb, basic_ios::widen('\n')); } - + _UCXXEXPORT basic_istream& get(basic_streambuf& sb, char_type delim){ sentry(*this, true); streamsize i = 0; @@ -150,13 +150,13 @@ namespace std{ } ++i; basic_ios::mstreambuf->sbumpc(); - } + } } - + _UCXXEXPORT basic_istream& getline(char_type* s, streamsize n){ return getline(s, n, basic_ios::widen('\n')); } - + _UCXXEXPORT basic_istream& getline(char_type* s, streamsize n, char_type delim){ sentry(*this, true); streamsize i = 0; @@ -186,7 +186,7 @@ namespace std{ s[n-1] = traits::eos(); return *this; } - + _UCXXEXPORT basic_istream& ignore (streamsize n = 1, int_type delim = traits::eof()){ sentry(*this, true); streamsize i; @@ -204,7 +204,7 @@ namespace std{ } return *this; } - + _UCXXEXPORT int_type peek(){ if(basic_ios::good() == false){ return traits::eof(); @@ -216,7 +216,7 @@ namespace std{ return basic_ios::mstreambuf->sgetc(); } } - + _UCXXEXPORT basic_istream& read (char_type* s, streamsize n){ sentry(*this, true); streamsize i; @@ -236,7 +236,7 @@ namespace std{ count_last_ufmt_input = n; return *this; } - + _UCXXEXPORT streamsize readsome(char_type* s, streamsize n){ sentry(*this, true); if(!basic_ios::good()){ @@ -244,20 +244,20 @@ namespace std{ basic_ios::setstate(ios_base::failbit); return 0; } - + if( basic_ios::mstreambuf->in_avail() == -1){ count_last_ufmt_input=0; basic_ios::setstate(ios_base::eofbit); return 0; } - + if(n > basic_ios::mstreambuf->in_avail() ){ n = basic_ios::mstreambuf->in_avail(); } - + streamsize i; int_type c; - + for(i=0;i::mstreambuf->sgetc(); basic_ios::mstreambuf->sbumpc(); @@ -266,7 +266,7 @@ namespace std{ count_last_ufmt_input = n; return n; } - + _UCXXEXPORT basic_istream& putback(char_type c){ sentry(*this, true); if(!basic_ios::good()){ @@ -283,7 +283,7 @@ namespace std{ } return *this; } - + _UCXXEXPORT basic_istream& unget(){ sentry(*this, true); if(!basic_ios::good()){ @@ -299,7 +299,7 @@ namespace std{ } return *this; } - + _UCXXEXPORT int sync(){ sentry(*this, true); if(basic_ios::mstreambuf == 0){ @@ -311,35 +311,35 @@ namespace std{ } return 0; } - + _UCXXEXPORT pos_type tellg(){ if(basic_ios::fail() !=false){ return pos_type(-1); } return basic_ios::mstreambuf->pubseekoff(0, ios_base::cur, ios_base::in); } - + _UCXXEXPORT basic_istream& seekg(pos_type pos){ if(basic_ios::fail() !=true){ - basic_ios::mstreambuf->pubseekpos(pos); + basic_ios::mstreambuf->pubseekpos(pos); } - return *this; + return *this; } - + _UCXXEXPORT basic_istream& seekg(off_type off, ios_base::seekdir dir){ if(basic_ios::fail() !=true){ basic_ios::mstreambuf->pubseekoff(off, dir); } return *this; } - + protected: _UCXXEXPORT basic_istream(const basic_istream &): basic_ios() { } _UCXXEXPORT basic_istream & operator=(const basic_istream &){ return *this; } streamsize count_last_ufmt_input; }; - + template > class _UCXXEXPORT basic_istream::sentry { bool ok; public: @@ -362,7 +362,7 @@ namespace std{ return ok; } }; - + //Template implementations of basic_istream functions which may be partially specialized //For code reduction @@ -395,9 +395,9 @@ namespace std{ } return *this; } - - template _UCXXEXPORT basic_istream& + + template _UCXXEXPORT basic_istream& basic_istream::operator>>(bool& n) { sentry(*this); @@ -405,7 +405,7 @@ namespace std{ return *this; } - template _UCXXEXPORT basic_istream& + template _UCXXEXPORT basic_istream& basic_istream::operator>>(short& n) { sentry(*this); @@ -413,7 +413,7 @@ namespace std{ return *this; } - template _UCXXEXPORT basic_istream& + template _UCXXEXPORT basic_istream& basic_istream::operator>>(unsigned short& n) { sentry(*this); @@ -439,7 +439,7 @@ namespace std{ return *this; } - template _UCXXEXPORT basic_istream& + template _UCXXEXPORT basic_istream& basic_istream::operator>>(unsigned long int& n) { sentry(*this); @@ -448,21 +448,21 @@ namespace std{ } #ifdef __UCLIBCXX_HAS_FLOATS__ - template _UCXXEXPORT basic_istream& + template _UCXXEXPORT basic_istream& basic_istream::operator>>(float& n) { sentry(*this); __istream_readin::readin(*this, n); return *this; } - template _UCXXEXPORT basic_istream& + template _UCXXEXPORT basic_istream& basic_istream::operator>>(double& n) { sentry(*this); __istream_readin::readin(*this, n); return *this; } - template _UCXXEXPORT basic_istream& + template _UCXXEXPORT basic_istream& basic_istream::operator>>(long double& n) { sentry(*this); @@ -470,7 +470,7 @@ namespace std{ return *this; } #endif - template _UCXXEXPORT basic_istream& + template _UCXXEXPORT basic_istream& basic_istream::operator>>(void *& n) { sentry(*this); @@ -538,7 +538,7 @@ namespace std{ return is; } - template _UCXXEXPORT basic_istream& + template _UCXXEXPORT basic_istream& basic_istream::operator>>(basic_istream& (*pf)(basic_istream&)) { sentry(*this); @@ -546,7 +546,7 @@ namespace std{ return *this; } - template _UCXXEXPORT basic_istream& + template _UCXXEXPORT basic_istream& basic_istream::operator>>(basic_ios& (*pf)(basic_ios&)) { sentry(*this); @@ -590,8 +590,6 @@ namespace std{ #endif #endif - - } diff --git a/istream_helpers b/istream_helpers index a61cc27..67ee3c8 100644 --- a/istream_helpers +++ b/istream_helpers @@ -42,7 +42,7 @@ namespace std{ * require different scanf functions */ - template _UCXXEXPORT + template _UCXXEXPORT basic_string _readToken(basic_istream& stream) { basic_string temp; @@ -62,7 +62,7 @@ namespace std{ return temp; } - template _UCXXEXPORT + template _UCXXEXPORT basic_string _readTokenDecimal(basic_istream& stream) { basic_string temp; @@ -103,12 +103,38 @@ namespace std{ public: inline static void readin(basic_istream& stream, bool & var) { + /* 22.4.2.1.2.4 */ basic_string temp; temp = _readToken( stream); - if(temp == "true" || temp == "True" || temp == "TRUE" || temp == "1"){ - var = true; - }else{ - var = false; + if (stream.flags() & ios_base::boolalpha) { + if (temp == "true") // truename() + var = true; + else { + var = false; + if (temp != "false") // falsename() + stream.setstate(ios_base::failbit); + } + } else { + long int i = 0; + int ret; + if (stream.flags() & ios_base::dec) { + ret = sscanf(temp.c_str(), "%ld", &i ); + } else { + if (stream.flags() & ios_base::oct) { + ret = sscanf(temp.c_str(), "%lo", (unsigned long int *)(&i)); + } else if (stream.flags() & ios_base::hex) { + if (stream.flags() & ios_base::uppercase) { + ret = sscanf(temp.c_str(), "%lX", (unsigned long int *)(&i)); + } else { + ret = sscanf(temp.c_str(), "%lx", (unsigned long int *)(&i)); + } + } else { + ret = sscanf(temp.c_str(), "%li", &i); + } + } + if (ret != 1 || i >> 1) + stream.setstate(ios_base::failbit); + var = ret == 1 && bool(i); } } }; @@ -135,7 +161,6 @@ namespace std{ } }else{ sscanf(temp.c_str(), "%hi", &var); - } } } @@ -215,7 +240,7 @@ namespace std{ }else{ sscanf(temp.c_str(), "%i", (int *)(&var) ); } - } + } } }; @@ -343,8 +368,7 @@ namespace std{ while ( !traits::eq_int_type((c = is.rdbuf()->sgetc()), eof) && isspace(c) - ) - { + ) { is.rdbuf()->sbumpc(); } if(traits::eq_int_type(c, eof)){ diff --git a/iterator b/iterator index c0ba25e..b3d81b2 100644 --- a/iterator +++ b/iterator @@ -34,19 +34,19 @@ namespace std{ // subclause _lib.stream.iterators_, stream iterators: template , class Distance = ptrdiff_t> class istream_iterator; - template bool + template bool operator==(const istream_iterator& x, const istream_iterator& y); - template bool + template bool operator!=(const istream_iterator& x, const istream_iterator& y); template > class ostream_iterator; template > class istreambuf_iterator; - template bool + template bool operator==(const istreambuf_iterator& a, const istreambuf_iterator& b); - template bool + template bool operator!=(const istreambuf_iterator& a, const istreambuf_iterator& b); template > class ostreambuf_iterator; - + template < class T, class charT, class traits, class Distance > class _UCXXEXPORT istream_iterator : public iterator { @@ -85,14 +85,14 @@ namespace std{ T value; }; - template _UCXXEXPORT + template _UCXXEXPORT bool operator==(const istream_iterator& x, const istream_iterator& y) { return x.m_equal(y); } - template _UCXXEXPORT + template _UCXXEXPORT bool operator!=(const istream_iterator& x, const istream_iterator& y) { @@ -126,7 +126,7 @@ namespace std{ const char* delim; }; - template class _UCXXEXPORT istreambuf_iterator : + template class _UCXXEXPORT istreambuf_iterator : public iterator { public: @@ -139,7 +139,7 @@ namespace std{ class _UCXXEXPORT proxy{ charT val; basic_streambuf * buf; - + proxy(charT v, basic_streambuf * b) : val(v), buf(b) { } public: charT operator*() { return val; } @@ -180,7 +180,7 @@ namespace std{ return a.equal(b); } - template bool _UCXXEXPORT + template bool _UCXXEXPORT operator!=(const istreambuf_iterator& a, const istreambuf_iterator& b) { diff --git a/iterator_base b/iterator_base index af59bbc..c5dccc5 100644 --- a/iterator_base +++ b/iterator_base @@ -43,7 +43,7 @@ namespace std{ } } - template _UCXXEXPORT typename iterator_traits::difference_type + template _UCXXEXPORT typename iterator_traits::difference_type distance(InputIterator first, InputIterator last) { typename iterator_traits::difference_type d = 0; @@ -63,7 +63,7 @@ namespace std{ template bool operator<=(const reverse_iterator& x, const reverse_iterator& y); template typename reverse_iterator::difference_type operator-( const reverse_iterator& x, const reverse_iterator& y); - template reverse_iterator + template reverse_iterator operator+( typename reverse_iterator::difference_type n, const reverse_iterator& x); template class back_insert_iterator; template back_insert_iterator back_inserter(Container& x); @@ -72,7 +72,7 @@ namespace std{ template class insert_iterator; template insert_iterator inserter(Container& x, Iterator i); - + //Actual Template definitions template struct _UCXXEXPORT iterator_traits { @@ -92,7 +92,7 @@ namespace std{ typedef random_access_iterator_tag iterator_category; }; - //Specialization recomended by standard + //Specialization recommended by standard /* template struct _UCXXEXPORT iterator_traits { typedef long difference_type; typedef T value_type; @@ -115,7 +115,7 @@ namespace std{ };*/ - template + template struct _UCXXEXPORT iterator { typedef T value_type; @@ -143,7 +143,7 @@ namespace std{ explicit reverse_iterator(Iterator x) : current(x) { } template reverse_iterator(const reverse_iterator &x) : current(x.base()){} - Iterator base() const { return current; } // explicit + Iterator base() const { return current; } // explicit typename iterator_traits::reference operator*() const { Iterator tmp = current; return *--tmp; } typename iterator_traits::pointer operator->() const { return &(operator*()); } @@ -218,7 +218,7 @@ namespace std{ return reverse_iterator (x.base() - n); } - template class _UCXXEXPORT back_insert_iterator : + template class _UCXXEXPORT back_insert_iterator : public iterator { protected: @@ -285,7 +285,7 @@ namespace std{ ++iter; return *this; } - insert_iterator& operator*() { return *this; } + insert_iterator& operator*() { return *this; } insert_iterator& operator++() { return *this; } insert_iterator operator++(int) { return *this; } }; diff --git a/limits b/limits index ca9bff4..7a62b0f 100644 --- a/limits +++ b/limits @@ -26,6 +26,9 @@ #pragma GCC visibility push(default) +#undef min +#undef max + namespace std{ enum float_round_style{ @@ -110,38 +113,38 @@ public: // General -- meaningful for all specializations. static const bool is_specialized = false; - static T min(); - static T max(); - static const int radix; - static const int digits; - static const int digits10; - static const bool is_signed; - static const bool is_integer; - static const bool is_exact; - static const bool traps; - static const bool is_modulo; - static const bool is_bounded; + static T min() { return T(); } + static T max() { return T(); } + static const int radix = 0; + static const int digits = 0; + static const int digits10 = 0; + static const bool is_signed = false; + static const bool is_integer = false; + static const bool is_exact = false; + static const bool traps = false; + static const bool is_modulo = false; + static const bool is_bounded = false; // Floating point specific. - static T epsilon(); - static T round_error(); - static const int min_exponent10; - static const int max_exponent10; - static const int min_exponent; - - static const int max_exponent; - static const bool has_infinity; - static const bool has_quiet_NaN; - static const bool has_signaling_NaN; - static const bool is_iec559; - static const bool has_denorm; - static const bool tinyness_before; - static const float_round_style round_style; - static T denorm_min(); - static T infinity(); - static T quiet_NaN(); - static T signaling_NaN(); + static T epsilon() { return T(); } + static T round_error() { return T(); } + static const int min_exponent10 = 0; + static const int max_exponent10 = 0; + static const int min_exponent = 0; + + static const int max_exponent = 0; + static const bool has_infinity = false; + static const bool has_quiet_NaN = false; + static const bool has_signaling_NaN = false; + static const bool is_iec559 = false; + static const bool has_denorm = false; + static const bool tinyness_before = false; + static const float_round_style round_style = round_toward_zero; + static T denorm_min() { return T(); } + static T infinity() { return T(); } + static T quiet_NaN() { return T(); } + static T signaling_NaN() { return T(); } }; template <> class numeric_limits { @@ -614,6 +617,54 @@ public: static T signaling_NaN(); }; +#ifndef __SUPPORT_SNAN__ +# define __SUPPORT_SNAN__ 0 +#endif + +#ifdef __UCLIBCXX_HAS_FLOATS__ +template <> class numeric_limits { +public: + typedef float numeric_type; + + static const bool is_specialized = true; + static numeric_type min () { return __FLT_MIN__; } + static numeric_type max () { return __FLT_MAX__; } + static const int radix = __FLT_RADIX__; + static const int digits = __FLT_MANT_DIG__; + static const int digits10 = __FLT_DIG__; + static const bool is_signed = true; + static const bool is_integer = false; + static const bool is_exact = false; + static const bool traps = false; // this is a guess + static const bool is_modulo = false; + static const bool is_bounded = true; + + // Floating point specific. + + static numeric_type epsilon () { return __FLT_EPSILON__; } + static numeric_type round_error () { return 0.5; } + static const int min_exponent10 = __FLT_MIN_10_EXP__; + static const int max_exponent10 = __FLT_MAX_10_EXP__; + static const int min_exponent = __FLT_MIN_EXP__; + static const int max_exponent = __FLT_MAX_EXP__; + static const bool has_infinity = __FLT_HAS_INFINITY__; + static const bool has_quiet_NaN = __FLT_HAS_QUIET_NAN__; + static const bool has_signaling_NaN = __SUPPORT_SNAN__; + static const bool has_denorm = __FLT_HAS_DENORM__; + + static const bool is_iec559 = false; //I don't know, so until I can find out, I'm saying no + static const bool tinyness_before = false; // more questions + static const float_round_style round_style = round_to_nearest; // more questions + static numeric_type denorm_min () { return __FLT_DENORM_MIN__; } + static numeric_type infinity () { return __builtin_inff(); } //This is a gcc builtin... + static numeric_type quiet_NaN () { return __builtin_nanf(""); } //This is a gcc builtin... +#if __SUPPORT_SNAN__ + static numeric_type signaling_NaN () { return __builtin_nansf(""); } //This is a gcc builtin... +#else + static numeric_type signaling_NaN () { return 0; } //How do I properly get this? +#endif +}; + template <> class numeric_limits { public: typedef double numeric_type; @@ -635,27 +686,88 @@ public: static numeric_type epsilon () { return __DBL_EPSILON__; } static numeric_type round_error () { return 0.5; } - static const int min_exponent10 = -1; //How do I properly get this? - static const int max_exponent10 = -1; //How do I properly get this? - static const int min_exponent = -1; //How do I properly get this? - static const int max_exponent = -1; //How do I properly get this? - static const bool has_infinity = false; //I don't know, so until I can find out, I'm saying no - static const bool has_quiet_NaN = false; //I don't know, so until I can find out, I'm saying no - static const bool has_signaling_NaN = false; //I don't know, so until I can find out, I'm saying no - static const bool has_denorm = false; //I don't know, so until I can find out, I'm saying no + static const int min_exponent10 = __DBL_MIN_10_EXP__; + static const int max_exponent10 = __DBL_MAX_10_EXP__; + static const int min_exponent = __DBL_MIN_EXP__; + static const int max_exponent = __DBL_MAX_EXP__; + static const bool has_infinity = __DBL_HAS_INFINITY__; + static const bool has_quiet_NaN = __DBL_HAS_QUIET_NAN__; + static const bool has_signaling_NaN = __SUPPORT_SNAN__; + static const bool has_denorm = __DBL_HAS_DENORM__; static const bool is_iec559 = false; //I don't know, so until I can find out, I'm saying no static const bool tinyness_before = false; // more questions static const float_round_style round_style = round_to_nearest; // more questions - static numeric_type denorm_min () { return -1; } //How do I properly get this? - static numeric_type infinity () { return -1; } //How do I properly get this? - static numeric_type quiet_NaN () { return -1; } //How do I properly get this? - static numeric_type signaling_NaN () { return -1; } //How do I properly get this? + static numeric_type denorm_min () { return __DBL_DENORM_MIN__; } + static numeric_type infinity () { return __builtin_inf(); } //This is a gcc builtin... + static numeric_type quiet_NaN () { return __builtin_nan(""); } //This is a gcc builtin... +#if __SUPPORT_SNAN__ + static numeric_type signaling_NaN () { return __builtin_nans(""); } //This is a gcc builtin... +#else + static numeric_type signaling_NaN () { return 0; } //How do I properly get this? +#endif }; +#endif // __UCLIBCXX_HAS_FLOATS__ + +#ifdef __UCLIBCXX_HAS_LONG_DOUBLE__ +template <> class numeric_limits { +public: + typedef long double numeric_type; + + static const bool is_specialized = true; + static numeric_type min () { return __LDBL_MIN__; } + static numeric_type max () { return __LDBL_MAX__; } + static const int radix = __FLT_RADIX__; + static const int digits = __LDBL_MANT_DIG__; + static const int digits10 = __LDBL_DIG__; + static const bool is_signed = true; + static const bool is_integer = false; + static const bool is_exact = false; + static const bool traps = false; // this is a guess + static const bool is_modulo = false; + static const bool is_bounded = true; + // Floating point specific. + static numeric_type epsilon () { return __LDBL_EPSILON__; } + static numeric_type round_error () { return 0.5; } + static const int min_exponent10 = __LDBL_MIN_10_EXP__; + static const int max_exponent10 = __LDBL_MAX_10_EXP__; + static const int min_exponent = __LDBL_MIN_EXP__; + static const int max_exponent = __LDBL_MAX_EXP__; + static const bool has_infinity = __LDBL_HAS_INFINITY__; + static const bool has_quiet_NaN = __LDBL_HAS_QUIET_NAN__; + static const bool has_signaling_NaN = __SUPPORT_SNAN__; + static const bool has_denorm = __LDBL_HAS_DENORM__; + static const bool is_iec559 = false; //I don't know, so until I can find out, I'm saying no + static const bool tinyness_before = false; // more questions + static const float_round_style round_style = round_to_nearest; // more questions + static numeric_type denorm_min () { return __LDBL_DENORM_MIN__; } + static numeric_type infinity () { return __builtin_infl (); } //This is a gcc builtin... + static numeric_type quiet_NaN () { return __builtin_nanl (""); } //This is a gcc builtin... +#if __SUPPORT_SNAN__ + static numeric_type signaling_NaN () { return __builtin_nansl (""); } //This is a gcc builtin... +#else + static numeric_type signaling_NaN () { return 0; } //How do I properly get this? +#endif +}; +#endif // __UCLIBCXX_HAS_LONG_DOUBLE__ + +template class numeric_limits : public numeric_limits { + public: + typedef const T numeric_type; +}; + +template class numeric_limits : public numeric_limits { + public: + typedef volatile T numeric_type; +}; +template class numeric_limits : public numeric_limits { + public: + typedef const volatile T numeric_type; +}; } diff --git a/list b/list index aa0905e..3d01faa 100644 --- a/list +++ b/list @@ -57,7 +57,7 @@ namespace std{ explicit list(const Allocator& = Allocator()); explicit list(size_type n, const T& value = T(), const Allocator& = Allocator()); - template list(InputIterator first, InputIterator last, + template list(InputIterator first, InputIterator last, const Allocator& al= Allocator()); list(const list& x); ~list(); @@ -150,10 +150,10 @@ namespace std{ //List iterator template class _UCXXEXPORT list::iter_list : public std::iterator< - bidirectional_iterator_tag, - T, - typename Allocator::difference_type, - typename Allocator::pointer, + bidirectional_iterator_tag, + T, + typename Allocator::difference_type, + typename Allocator::pointer, typename Allocator::reference > { @@ -200,7 +200,7 @@ namespace std{ iter_list temp(current); current = current->next; return temp; - } + } iter_list & operator--(){ current = current->previous; return *this; @@ -299,20 +299,20 @@ namespace std{ y->val = v; } - template typename list::iterator + template typename list::iterator list::begin() { return iterator(list_start); } - + template typename list::const_iterator list::begin() const { return const_iterator(list_start); } - + template typename list::iterator list::end() { @@ -452,7 +452,7 @@ namespace std{ } - template typename list::iterator + template typename list::iterator list::insert(iterator position, const T& x) { node * temp = new node(x); @@ -560,7 +560,7 @@ namespace std{ x.elements = 0; - //Chaining to the begining + //Chaining to the beginning if(position == begin()){ x.list_end->previous->next = list_start; list_start->previous = x.list_end->previous; @@ -576,34 +576,33 @@ namespace std{ //Link everything we need x.list_start->previous = position.link_struct()->previous; position.link_struct()->previous->next = x.list_start; - + position.link_struct()->previous = x.list_end->previous; x.list_end->previous->next = position.link_struct(); //Clean up the other list - + x.list_start = x.list_end; x.list_end->previous=0; } template - void list::splice(iterator position, list& x, iterator i) + void list::splice(iterator position, list& x, iterator i) { //Invalid conditions if( x.elements == 0 || i == position || position.link_struct() == i.link_struct()->next ){ return; } - - //Do we need to adjust the begining pointer? + //Do we need to adjust the beginning pointer? if(i == x.begin()){ x.list_start = x.list_start->next; x.list_start->previous = 0; } - //Insert at begining special case + //Insert at beginning special case if(position == begin()){ i.link_struct()->previous->next = i.link_struct()->next; @@ -627,7 +626,7 @@ namespace std{ i.link_struct()->next->previous = 0; x.list_start = i.link_struct()->next; } - + i.link_struct()->previous = position.link_struct()->previous; position.link_struct()->previous->next = i.link_struct(); @@ -706,7 +705,7 @@ namespace std{ merge(x, c); } - template template + template template void list::merge(list& x, Compare comp) { iterator source = x.begin(); @@ -785,7 +784,7 @@ namespace std{ node * following; node * temp; - //Need to move the list_end element to the begining + //Need to move the list_end element to the beginning temp = list_end; list_end = temp->previous; diff --git a/locale b/locale index f6d08dc..96e6bc9 100644 --- a/locale +++ b/locale @@ -44,7 +44,7 @@ namespace std{ // construct/copy/destroy: locale() throw(){ return; - } + } locale(const locale& other) throw(){ (void)other; return; diff --git a/map b/map index 54891ff..8b7332b 100644 --- a/map +++ b/map @@ -19,7 +19,7 @@ #include -#include +#include #include #include #include diff --git a/memory b/memory index ecf8103..2a7ce8c 100644 --- a/memory +++ b/memory @@ -21,7 +21,7 @@ #include #include #include -#include +#include #include #ifndef HEADER_STD_MEMORY diff --git a/new_handler.cpp b/new_handler.cpp index 1d85ee3..b535c0d 100644 --- a/new_handler.cpp +++ b/new_handler.cpp @@ -21,7 +21,7 @@ const std::nothrow_t std::nothrow = { }; -//Name selected to be compatable with g++ code +//Name selected to be compatible with g++ code std::new_handler __new_handler; _UCXXEXPORT std::new_handler std::set_new_handler(std::new_handler new_p) throw(){ diff --git a/ostream b/ostream index 3491180..4434cdd 100644 --- a/ostream +++ b/ostream @@ -252,6 +252,7 @@ namespace std { } return *this; } + template _UCXXEXPORT basic_ostream& basic_ostream::operator<<(basic_streambuf* sb) { diff --git a/ostream_helpers b/ostream_helpers index 75693af..0c763a0 100644 --- a/ostream_helpers +++ b/ostream_helpers @@ -238,24 +238,25 @@ namespace std{ #endif //__STRICT_ANSI__ - +#if defined( __UCLIBCXX_HAS_FLOATS__ ) +# if defined( __AVR__ ) template class _UCXXEXPORT __ostream_printout{ public: static void printout(basic_ostream& stream, const float f) { char buffer[32]; int length; - + //length = snprintf(buffer, 32, "%*.*f",static_cast(stream.width()),static_cast(stream.precision()), f); length = strlen(dtostrf(f, static_cast(stream.width()), static_cast(stream.precision()), buffer)); - + stream.printout(buffer, length); if(stream.flags() & ios_base::unitbuf){ stream.flush(); } } }; - +# endif template class _UCXXEXPORT __ostream_printout{ public: static void printout(basic_ostream& stream, const double f) @@ -264,30 +265,30 @@ namespace std{ int length; if(stream.flags() & ios_base::scientific){ if(stream.flags() & ios_base::uppercase){ -#if defined( __AVR__ ) +# if defined( __AVR__ ) length = strlen(dtostre(f, buffer, static_cast(stream.precision()), 0x04 )); -#else +# else length = snprintf(buffer, 32, "%*.*E", static_cast(stream.width()),static_cast(stream.precision()), f); -#endif +# endif }else{ -#if defined( __AVR__ ) +# if defined( __AVR__ ) length = strlen(dtostre(f, buffer, static_cast(stream.precision()), 0)); -#else +# else length = snprintf(buffer, 32, "%*.*e", static_cast(stream.width()),static_cast(stream.precision()), f); -#endif +# endif } } else if(stream.flags() & ios_base::fixed){ -#if defined( __AVR__ ) +# if defined( __AVR__ ) length = strlen(dtostrf(f, static_cast(stream.width()), static_cast(stream.precision()), buffer)); -#else +# else length = snprintf(buffer, 32, "%*.*f",static_cast(stream.width()),static_cast(stream.precision()), f); -#endif +# endif } else { -#if defined( __AVR__ ) +# if defined( __AVR__ ) length = strlen(dtostrf(f, static_cast(stream.width()), static_cast(stream.precision()), buffer)); -#else +# else length = snprintf(buffer, 32, "%*.*g",static_cast(stream.width()),static_cast(stream.precision()), f); -#endif +# endif } stream.printout(buffer, length); if(stream.flags() & ios_base::unitbuf){ @@ -296,6 +297,9 @@ namespace std{ } }; +#endif // __UCLIBCXX_HAS_FLOATS__ + +#if defined( __UCLIBCXX_HAS_LONG_DOUBLE__ ) template class _UCXXEXPORT __ostream_printout{ public: static void printout(basic_ostream& stream, const long double f) @@ -320,6 +324,7 @@ namespace std{ } }; +#endif // __UCLIBCXX_HAS_LONG_DOUBLE__ #ifdef __UCLIBCXX_HAS_WCHAR__ template class _UCXXEXPORT __ostream_printout{ @@ -390,7 +395,7 @@ namespace std{ } }; -#ifndef __STRICT_ANSI__ +# ifndef __STRICT_ANSI__ template class _UCXXEXPORT __ostream_printout{ public: @@ -461,8 +466,9 @@ namespace std{ }; -#endif //__STRICT_ANSI__ +# endif //__STRICT_ANSI__ +# if defined( __UCLIBCXX_HAS_FLOATS__ ) template class _UCXXEXPORT __ostream_printout{ public: static void printout(basic_ostream& stream, const double f) @@ -486,7 +492,9 @@ namespace std{ } } }; +# endif // __UCLIBCXX_HAS_FLOATS__ +# if defined( __UCLIBCXX_HAS_LONG_DOUBLE__ ) template class _UCXXEXPORT __ostream_printout{ public: static void printout(basic_ostream& stream, const long double f) @@ -510,6 +518,7 @@ namespace std{ } } }; +# endif // __UCLIBCXX_HAS_LONG_DOUBLE__ #endif //__UCLIBCXX_HAS_WCHAR__ diff --git a/set b/set index 721e70b..f376e47 100644 --- a/set +++ b/set @@ -19,7 +19,7 @@ #include -#include +#include #include #include #include @@ -185,11 +185,11 @@ protected: /* Non-member functions. These are at the end because they are not associated with any - particular class. These will be implemented as I figure out exactly what all of + particular class. These will be implemented as I figure out exactly what all of them are supposed to do, and I have time. */ - template _UCXXEXPORT bool operator< + template _UCXXEXPORT bool operator< (const set& x, const set& y) { typename set::const_iterator first1 = x.begin(); @@ -207,7 +207,7 @@ protected: ++first1; ++first2; } - return first1==last1 && first2 != last2; + return first1==last1 && first2 != last2; } template _UCXXEXPORT bool operator> @@ -228,7 +228,7 @@ protected: ++first1; ++first2; } - return first1!=last1 && first2 == last2; + return first1!=last1 && first2 == last2; } template _UCXXEXPORT bool operator>= @@ -249,7 +249,7 @@ protected: ++first1; ++first2; } - return first1!=last1; + return first1!=last1; } template _UCXXEXPORT bool operator<= @@ -270,7 +270,7 @@ protected: ++first1; ++first2; } - return first2!=last2; + return first2!=last2; } template _UCXXEXPORT void swap (set& x, set& y) @@ -288,7 +288,7 @@ protected: return false; } - template _UCXXEXPORT bool operator< + template _UCXXEXPORT bool operator< (const multiset& x, const multiset& y) { typename multiset::const_iterator first1 = x.begin(); @@ -306,7 +306,7 @@ protected: ++first1; ++first2; } - return first1==last1 && first2 != last2; + return first1==last1 && first2 != last2; } template _UCXXEXPORT bool operator!= @@ -324,10 +324,10 @@ protected: ++first1; ++first2; } - return first1!=last1 || first2 != last2; + return first1!=last1 || first2 != last2; } - template _UCXXEXPORT bool operator> + template _UCXXEXPORT bool operator> (const multiset& x, const multiset& y) { typename multiset::const_iterator first1 = x.begin(); @@ -345,7 +345,7 @@ protected: ++first1; ++first2; } - return first1!=last1 && first2 == last2; + return first1!=last1 && first2 == last2; } template _UCXXEXPORT bool operator>= @@ -366,9 +366,9 @@ protected: ++first1; ++first2; } - return first1!=last1; + return first1!=last1; } - + template _UCXXEXPORT bool operator<= (const multiset& x, const multiset& y) { @@ -387,7 +387,7 @@ protected: ++first1; ++first2; } - return first2!=last2; + return first2!=last2; } template _UCXXEXPORT void swap @@ -404,4 +404,3 @@ protected: #endif - diff --git a/string b/string index 3ad2467..35b9a46 100644 --- a/string +++ b/string @@ -89,7 +89,7 @@ public: } _UCXXEXPORT basic_string(const Ch* s, const A& al = A()); //Below - + _UCXXEXPORT basic_string(size_type n, Ch c, const A& al = A()) : vector(n, c, al) { @@ -98,7 +98,7 @@ public: template _UCXXEXPORT basic_string(InputIterator begin, InputIterator end, const A& a = A()) :vector(begin, end) { - + } _UCXXEXPORT ~basic_string() { @@ -167,7 +167,7 @@ public: 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); @@ -368,7 +368,7 @@ public: _UCXXEXPORT basic_string& replace(size_type pos, size_type n1, const Ch* s, size_type n2){ return replace(pos,n1,basic_string(s,n2)); - + } inline _UCXXEXPORT basic_string& replace(size_type pos, size_type n1, const Ch* s){ @@ -456,7 +456,7 @@ public: _UCXXEXPORT size_type find_first_of(const basic_string& str, size_type pos = 0) const{ for(size_type i = pos; i < length(); ++i){ for(size_type j = 0; j < str.length() ; ++j){ - if( Tr::eq(str[j], operator[](i)) ){ + if( Tr::eq(str[j], this->operator[](i)) ){ return i; } } @@ -472,7 +472,7 @@ public: } _UCXXEXPORT size_type find_first_of(Ch c, size_type pos = 0) const{ for(size_type i = pos; i< length(); ++i){ - if( Tr::eq(operator[](i), c) ){ + if( Tr::eq(this->operator[](i), c) ){ return i; } } @@ -485,7 +485,7 @@ public: } for(size_type i = pos; i >0 ; --i){ for(size_type j = 0 ; j < str.length(); ++j){ - if( Tr::eq(operator[](i-1), str[j]) ){ + if( Tr::eq(this->operator[](i-1), str[j]) ){ return i-1; } } @@ -503,7 +503,7 @@ public: pos = length(); } for(size_type i = pos; i >0 ; --i){ - if( Tr::eq(operator[](i-1), c) ){ + if( Tr::eq(this->operator[](i-1), c) ){ return i-1; } } @@ -514,15 +514,15 @@ public: bool foundCharacter; for(size_type i = pos; i < length(); ++i){ foundCharacter = false; - for(size_type j = 0; j < str.length() ; ++j){ - if( Tr::eq(str[j], operator[](i)) ){ + for(size_type j = 0; j < str.length() ; ++j){ + if( Tr::eq(str[j], this->operator[](i)) ){ foundCharacter = true; - } - } + } + } if(foundCharacter == false){ return i; } - } + } return npos; } @@ -534,7 +534,7 @@ public: } _UCXXEXPORT size_type find_first_not_of(Ch c, size_type pos = 0) const{ for(size_type i = pos; i < length() ; ++i){ - if(operator[](i) != c){ + if(this->operator[](i) != c){ return i; } } @@ -545,8 +545,8 @@ public: if(xpos > pos){ xpos = pos; } - - while(xpos != npos && npos != str.find_first_of(at(xpos))){ + + while(xpos != npos && npos != str.find_first_of(this->at(xpos))){ --xpos; } @@ -564,7 +564,7 @@ public: if(xpos > pos){ xpos = pos; } - while(xpos != npos && Tr::eq(at(xpos), c)){ + while(xpos != npos && Tr::eq(this->at(xpos), c)){ --xpos; } return xpos; @@ -675,7 +675,7 @@ template _UCXXEXPORT basic_string::basic_str } template _UCXXEXPORT basic_string:: - basic_string(const basic_string& str, size_type pos, size_type n, const A& al) + basic_string(const basic_string& str, size_type pos, size_type n, const A& al) : vector(al) { if(pos>str.size()){ @@ -692,7 +692,7 @@ template _UCXXEXPORT basic_string:: template _UCXXEXPORT basic_string& basic_string::operator=(const basic_string & str) { - if(&str == this){ //Check if we are doing a=a + if(&str == this){ //Check if we are doing a=a return *this; } vector::clear(); @@ -790,7 +790,7 @@ template //typedef basic_string string; -template _UCXXEXPORT basic_string +template _UCXXEXPORT basic_string operator+(const basic_string& lhs, const basic_string& rhs) { basic_string temp(lhs); @@ -831,7 +831,7 @@ template _UCXXEXPORT basic_string _UCXXEXPORT bool +template _UCXXEXPORT bool operator==(const basic_string& lhs, const basic_string& rhs) { if(lhs.compare(rhs) == 0){ @@ -840,7 +840,7 @@ template _UCXXEXPORT bool return false; } -template _UCXXEXPORT bool +template _UCXXEXPORT bool operator==(const charT* lhs, const basic_string& rhs) { if(rhs.compare(lhs) == 0){ @@ -849,7 +849,7 @@ template _UCXXEXPORT bool return false; } -template _UCXXEXPORT bool +template _UCXXEXPORT bool operator==(const basic_string& lhs, const charT* rhs) { if(lhs.compare(rhs)==0){ @@ -858,7 +858,7 @@ template _UCXXEXPORT bool return false; } -template _UCXXEXPORT bool +template _UCXXEXPORT bool operator!=(const basic_string& lhs, const basic_string& rhs) { if(lhs.compare(rhs) !=0){ @@ -867,21 +867,21 @@ template _UCXXEXPORT bool return false; } -template _UCXXEXPORT bool +template _UCXXEXPORT bool operator!=(const charT* lhs, const basic_string& rhs) { basic_string temp(lhs); return (temp != rhs); } -template _UCXXEXPORT bool +template _UCXXEXPORT bool operator!=(const basic_string& lhs, const charT* rhs) { basic_string temp(rhs); return (lhs != temp); } -template _UCXXEXPORT bool +template _UCXXEXPORT bool operator< (const basic_string& lhs, const basic_string& rhs) { if(lhs.compare(rhs) < 0){ @@ -890,7 +890,7 @@ template _UCXXEXPORT bool return false; } -template _UCXXEXPORT bool +template _UCXXEXPORT bool operator< (const basic_string& lhs, const charT* rhs) { basic_string temp(rhs); @@ -900,7 +900,7 @@ template _UCXXEXPORT bool return false; } -template _UCXXEXPORT bool +template _UCXXEXPORT bool operator< (const charT* lhs, const basic_string& rhs) { basic_string temp(lhs); @@ -911,7 +911,7 @@ template _UCXXEXPORT bool } -template _UCXXEXPORT bool +template _UCXXEXPORT bool operator> (const basic_string& lhs, const basic_string& rhs) { if(lhs.compare(rhs) > 0){ @@ -920,7 +920,7 @@ template _UCXXEXPORT bool return false; } -template _UCXXEXPORT bool +template _UCXXEXPORT bool operator> (const basic_string& lhs, const charT* rhs) { basic_string temp(rhs); @@ -930,7 +930,7 @@ template _UCXXEXPORT bool return false; } -template _UCXXEXPORT bool +template _UCXXEXPORT bool operator> (const charT* lhs, const basic_string& rhs) { basic_string temp(lhs); @@ -940,7 +940,7 @@ template _UCXXEXPORT bool return false; } -template _UCXXEXPORT bool +template _UCXXEXPORT bool operator<=(const basic_string& lhs, const basic_string& rhs) { if(lhs.compare(rhs) <=0){ @@ -949,7 +949,7 @@ template _UCXXEXPORT bool return false; } -template _UCXXEXPORT bool +template _UCXXEXPORT bool operator<=(const basic_string& lhs, const charT* rhs) { basic_string temp(rhs); @@ -959,7 +959,7 @@ template _UCXXEXPORT bool return false; } -template _UCXXEXPORT bool +template _UCXXEXPORT bool operator<=(const charT* lhs, const basic_string& rhs) { basic_string temp(lhs); @@ -969,7 +969,7 @@ template _UCXXEXPORT bool return false; } -template _UCXXEXPORT bool +template _UCXXEXPORT bool operator>=(const basic_string& lhs, const basic_string& rhs) { if(lhs.compare(rhs) >=0){ @@ -978,7 +978,7 @@ template _UCXXEXPORT bool return false; } -template _UCXXEXPORT bool +template _UCXXEXPORT bool operator>=(const basic_string& lhs, const charT* rhs) { basic_string temp(rhs); @@ -988,7 +988,7 @@ template _UCXXEXPORT bool return false; } -template _UCXXEXPORT bool +template _UCXXEXPORT bool operator>=(const charT* lhs, const basic_string& rhs) { basic_string temp(lhs); @@ -998,7 +998,7 @@ template _UCXXEXPORT bool return false; } -template _UCXXEXPORT void +template _UCXXEXPORT void swap(basic_string& lhs, basic_string& rhs) { lhs.swap(rhs); diff --git a/support b/support index ed0c7ca..210e901 100644 --- a/support +++ b/support @@ -57,9 +57,9 @@ static const _Unwind_Action _UA_HANDLER_FRAME = 4; static const _Unwind_Action _UA_FORCE_UNWIND = 8; const _Unwind_Exception_Class __uclibcxx_exception_class = (((((((( - _Unwind_Exception_Class) 'u' << 8 | (_Unwind_Exception_Class) 'l') << 8 + _Unwind_Exception_Class) 'u' << 8 | (_Unwind_Exception_Class) 'l') << 8 | (_Unwind_Exception_Class) 'i') << 8 | (_Unwind_Exception_Class) 'b') << 8 - | (_Unwind_Exception_Class) 'C')<< 8 | (_Unwind_Exception_Class) '+') << 8 + | (_Unwind_Exception_Class) 'C')<< 8 | (_Unwind_Exception_Class) '+') << 8 | (_Unwind_Exception_Class) '+') << 8 | (_Unwind_Exception_Class) '\0'); @@ -93,14 +93,14 @@ struct _Unwind_Context; _Unwind_Reason_Code _Unwind_RaiseException ( struct _Unwind_Exception *exception_object ); -//_Unwind_ForcedUnwind +//_Unwind_ForcedUnwind typedef _Unwind_Reason_Code (*_Unwind_Stop_Fn) (int version, _Unwind_Action actions, _Unwind_Exception_Class exceptionClass, - struct _Unwind_Exception *exceptionObject, + struct _Unwind_Exception *exceptionObject, struct _Unwind_Context *context, void *stop_parameter ); -_Unwind_Reason_Code _Unwind_ForcedUnwind ( +_Unwind_Reason_Code _Unwind_ForcedUnwind ( struct _Unwind_Exception *exception_object, _Unwind_Stop_Fn stop, void *stop_parameter ); @@ -124,18 +124,18 @@ _Unwind_Reason_Code (*__personality_routine) struct _Unwind_Context *context); //Unwinder state information -/*The following part is the Level II ABI which is required for compatability*/ +/*The following part is the Level II ABI which is required for compatibility*/ //This might be the only stuff that *I* need to implement -struct __cxa_exception { +struct __cxa_exception { std::type_info *exceptionType; //Type of thrown exception - void (*exceptionDestructor) (void *); //Pointer to the destructor + void (*exceptionDestructor) (void *); //Pointer to the destructor unexpected_handler unexpectedHandler; //Unexpected handler to use terminate_handler terminateHandler; //Terminate handle to use __cxa_exception *nextException; //per thread linked list int handlerCount; //How many handlers have caught this - int handlerSwitchValue; + int handlerSwitchValue; const char *actionRecord; const char *languageSpecificData; void *catchTemp; @@ -155,13 +155,11 @@ extern "C" __cxa_eh_globals *__cxa_get_globals_fast(void); //Same as above, assu extern "C" void *__cxa_allocate_exception(size_t thrown_size); //Allocate space for exception plus header extern "C" void __cxa_free_exception(void *thrown_exception); //Free space allocated from the above -extern "C" void __cxa_throw (void *thrown_exception, //This is the actual throw call -// std::type_info *tinfo, //Type of object - void * tinfo, //Type of object +extern "C" void __cxa_throw (void *thrown_exception, //This is the actual throw call +// std::type_info *tinfo, //Type of object + void * tinfo, //Type of object void (*dest) (void *) ); //Pointer to destructor destroy object #endif - - diff --git a/system_configuration.h b/system_configuration.h index 62e519b..20718a9 100644 --- a/system_configuration.h +++ b/system_configuration.h @@ -6,12 +6,13 @@ */ #define __UCLIBCXX_MAJOR__ 0 #define __UCLIBCXX_MINOR__ 2 -#define __UCLIBCXX_SUBLEVEL__ 3 +#define __UCLIBCXX_SUBLEVEL__ 5-git /* * Target Features and Options */ -#define __UCLIBCXX_HAS_FLOATS__ +#define __UCLIBCXX_HAS_FLOATS__ 1 +#undef __UCLIBCXX_HAS_LONG_DOUBLE__ #undef __UCLIBCXX_HAS_TLS__ #define __WARNINGS__ "-Wall" #define __BUILD_EXTRA_LIBRARIES__ "" @@ -24,8 +25,11 @@ #define __UCLIBCXX_IOSTREAM_BUFSIZE__ 32 #undef __UCLIBCXX_HAS_LFS__ #undef __UCLIBCXX_SUPPORT_CDIR__ -#define __UCLIBCXX_SUPPORT_COUT__ -#define __UCLIBCXX_SUPPORT_CERR__ +#define __UCLIBCXX_SUPPORT_CIN__ 1 +#define __UCLIBCXX_SUPPORT_COUT__ 1 +#define __UCLIBCXX_SUPPORT_CERR__ 1 +#undef __UCLIBCXX_SUPPORT_CLOG__ + /* * STL and Code Expansion */ diff --git a/unwind-cxx.h b/unwind-cxx.h index 4a8961a..b773259 100644 --- a/unwind-cxx.h +++ b/unwind-cxx.h @@ -173,6 +173,7 @@ extern std::unexpected_handler __unexpected_handler; // This is the exception class we report -- "GNUCC++\0". const _Unwind_Exception_Class __gxx_exception_class +#ifndef __ARM_EABI_UNWINDER__ = ((((((((_Unwind_Exception_Class) 'G' << 8 | (_Unwind_Exception_Class) 'N') << 8 | (_Unwind_Exception_Class) 'U') @@ -181,6 +182,9 @@ const _Unwind_Exception_Class __gxx_exception_class << 8 | (_Unwind_Exception_Class) '+') << 8 | (_Unwind_Exception_Class) '+') << 8 | (_Unwind_Exception_Class) '\0'); +#else += "GNUCC++"; +#endif // GNU C++ personality routine, Version 0. extern "C" _Unwind_Reason_Code __gxx_personality_v0 diff --git a/utility.h b/utility similarity index 100% rename from utility.h rename to utility diff --git a/utility.cpp b/utility.cpp index 42e0daa..b2f8995 100644 --- a/utility.cpp +++ b/utility.cpp @@ -18,7 +18,7 @@ */ -#include +#include namespace std{ diff --git a/valarray b/valarray index 983d458..9b3e191 100644 --- a/valarray +++ b/valarray @@ -113,7 +113,12 @@ namespace std{ } valarray& operator=(const valarray& v){ - for(size_t i =0; i< length; ++i){ + if (length != v.length) { // DR 630 + delete [] data; + length = v.length; + data = new T[length]; + } + for (size_t i = 0; i < length; ++i) { data[i] = v.data[i]; } return *this; @@ -134,7 +139,7 @@ namespace std{ valarray& operator=(const mask_array&); valarray& operator=(const indirect_array&); - T operator[](size_t t) const{ + const T& operator[](size_t t) const{ return data[t]; } T& operator[](size_t t){ @@ -184,10 +189,10 @@ namespace std{ } return retval; } - valarray operator!() const{ - valarray retval(length); - for(size_t i = 0; i< length ; ++i){ - retval.data[i] = !data[i]; + valarray operator!() const{ + valarray retval(length); + for (size_t i = 0; i < length ; ++i){ + retval[i] = !data[i]; } return retval; } @@ -235,7 +240,7 @@ namespace std{ } valarray& operator|= (const T& t){ for(size_t i=0;i shift (int n) const{ valarray retval(length); - for(size_t i = 0; i < length ; ++i){ - if(i + n > 0 && i + n < length){ - retval.data[i] = data[i + n]; - } + if (n < 0) { + if (-size_t(n) > length) + n = -int(length); + } else { + if (size_t(n) > length) + n = int(length); + } + for (size_t i = 0; i < length ; ++i) { + if ((n + i) < length) + retval.data[i] = data[n + i]; } return retval; } valarray cshift(int n) const{ valarray retval(length); - for(size_t i = 0; i < length ; ++i){ - retval.data[i] = data[ (i + n) % length ]; + if (length == 0) + return retval; + if (n < 0) { + if (-size_t(n) > length) + n = -int(-size_t(n) % length); + n = length + n; + } else { + if (size_t(n) > length) + n = int(size_t(n) % length); + } + for (size_t i = 0; i < length ; ++i){ + retval.data[i] = data[(n + i) % length]; } return retval; } @@ -471,6 +492,7 @@ namespace std{ slice_array& operator=(const slice_array& sa){ array = sa.array; s = sa.s; + return *this; } private: @@ -486,7 +508,7 @@ namespace std{ valarray str; public: - gslice() : sta(0) { } + gslice() : sta(0), siz(), str() { } // DR 543 gslice(size_t s, const valarray& l, const valarray& d) : sta(s), siz(l), str(d) { } @@ -598,7 +620,7 @@ namespace std{ } template valarray operator- (const valarray& lhs, const T& rhs){ valarray retval(lhs); - retval-= rhs; + retval -= rhs; return retval; } template valarray operator- (const T& lhs, const valarray& rhs){ @@ -802,7 +824,7 @@ namespace std{ } return retval; } - template valarray operator> (const T& rhs, const valarray& lhs){ + template valarray operator> (const T& lhs, const valarray& rhs){ valarray retval(rhs.size()); for(size_t i = 0; i rhs[i]; @@ -873,122 +895,141 @@ namespace std{ for(size_t i = 0; i < retval.size(); ++i){ retval[i] = abs(x[i]); } + return retval; } template valarray acos (const valarray& x){ valarray retval(x.size()); for(size_t i = 0; i < retval.size(); ++i){ retval[i] = acos(x[i]); } + return retval; } template valarray asin (const valarray& x){ valarray retval(x.size()); for(size_t i = 0; i < retval.size(); ++i){ retval[i] = asin(x[i]); } + return retval; } template valarray atan (const valarray& x){ valarray retval(x.size()); for(size_t i = 0; i < retval.size(); ++i){ retval[i] = atan(x[i]); } + return retval; } template valarray atan2(const valarray& y, const valarray& x){ valarray retval(y.size()); for(size_t i = 0; i < retval.size(); ++i){ retval[i] = atan2(y[i], x[i]); } + return retval; } template valarray atan2(const valarray& y, const T& x){ valarray retval(y.size()); for(size_t i = 0; i < retval.size(); ++i){ retval[i] = atan2(y[i], x); } + return retval; } template valarray atan2(const T& y, const valarray& x){ valarray retval(x.size()); for(size_t i = 0; i < retval.size(); ++i){ - retval[i] = abs(y, x[i]); + retval[i] = atan2(y, x[i]); } + return retval; } template valarray cos (const valarray& x){ valarray retval(x.size()); for(size_t i = 0; i < retval.size(); ++i){ retval[i] = cos(x[i]); } + return retval; } template valarray cosh (const valarray& x){ valarray retval(x.size()); for(size_t i = 0; i < retval.size(); ++i){ retval[i] = cosh(x[i]); } + return retval; } template valarray exp (const valarray& x){ valarray retval(x.size()); for(size_t i = 0; i < retval.size(); ++i){ retval[i] = exp(x[i]); } + return retval; } template valarray log (const valarray& x){ valarray retval(x.size()); for(size_t i = 0; i < retval.size(); ++i){ retval[i] = log(x[i]); } + return retval; } template valarray log10(const valarray& x){ valarray retval(x.size()); for(size_t i = 0; i < retval.size(); ++i){ retval[i] = log10(x[i]); } + return retval; } - template valarray pow (const valarray& x, const valarray& y){ + template valarray pow (const valarray& x, const valarray& y){ valarray retval(x.size()); for(size_t i = 0; i < retval.size(); ++i){ retval[i] = pow(x[i], y[i]); } + return retval; } template valarray pow (const valarray& x, const T& y){ valarray retval(x.size()); for(size_t i = 0; i < retval.size(); ++i){ retval[i] = pow(x[i], y); } + return retval; } template valarray pow (const T& x, const valarray& y){ - valarray retval(x.size()); + valarray retval(y.size()); for(size_t i = 0; i < retval.size(); ++i){ retval[i] = pow(x, y[i]); } + return retval; } template valarray sin (const valarray& x){ valarray retval(x.size()); for(size_t i = 0; i < retval.size(); ++i){ retval[i] = sin(x[i]); } + return retval; } template valarray sinh (const valarray& x){ valarray retval(x.size()); for(size_t i = 0; i < retval.size(); ++i){ retval[i] = sinh(x[i]); } + return retval; } template valarray sqrt (const valarray& x){ valarray retval(x.size()); for(size_t i = 0; i < retval.size(); ++i){ retval[i] = sqrt(x[i]); } + return retval; } template valarray tan (const valarray& x){ valarray retval(x.size()); for(size_t i = 0; i < retval.size(); ++i){ retval[i] = tan(x[i]); } + return retval; } template valarray tanh (const valarray& x){ valarray retval(x.size()); for(size_t i = 0; i < retval.size(); ++i){ retval[i] = tanh(x[i]); } - } - + return retval; + } } #pragma GCC visibility pop diff --git a/vector b/vector index 5a3c592..2e17cbe 100644 --- a/vector +++ b/vector @@ -59,13 +59,13 @@ 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); } - explicit _UCXXEXPORT vector(size_type n, const T& value = T(), const Allocator& al= Allocator()) : + explicit _UCXXEXPORT vector(size_type n, const T& value = T(), const Allocator& al= Allocator()) : data(0), data_size(0), elements(0), a(al) { data_size = n + __UCLIBCXX_STL_BUFFER_SIZE__; @@ -74,7 +74,7 @@ namespace std{ resize(n, value); } - template _UCXXEXPORT + template _UCXXEXPORT vector(InputIterator first, InputIterator last, const Allocator& al = Allocator()): data(0), data_size(__UCLIBCXX_STL_BUFFER_SIZE__), elements(0), a(al) { @@ -91,7 +91,7 @@ namespace std{ for(size_type i = 0; i < elements; i++){ a.construct(data+i, x.data[i]); - } + } } #if __cplusplus >= 201103L _UCXXEXPORT vector(initializer_list x,const Allocator& al= Allocator()): @@ -276,7 +276,7 @@ namespace std{ } } - template _UCXXEXPORT + template _UCXXEXPORT void _insert_from_iterator(iterator position, InputIterator first, InputIterator last) { T temp; @@ -375,7 +375,7 @@ namespace std{ template _UCXXEXPORT void vector::reserve(size_type n){ - if(n > data_size){ //We never shrink... + if(n > data_size){ //We never shrink... T * temp_ptr = data; size_type temp_size = data_size; @@ -491,7 +491,7 @@ namespace std{ operator< (const vector& x, const vector& y) { less::iterator >::value_type> c; - return lexicographical_compare(x.begin(), x.end(), y.begin(), y.end(), c); + return lexicographical_compare(x.begin(), x.end(), y.begin(), y.end(), c); } template _UCXXEXPORT bool operator!=(const vector& x, const vector& y) @@ -502,19 +502,19 @@ namespace std{ operator> (const vector& x, const vector& y) { greater::iterator >::value_type> c; - return lexicographical_compare(x.begin(), x.end(), y.begin(), y.end(), c); + return lexicographical_compare(x.begin(), x.end(), y.begin(), y.end(), c); } template _UCXXEXPORT bool operator>=(const vector& x, const vector& y) { greater_equal::iterator >::value_type> c; - return lexicographical_compare(x.begin(), x.end(), y.begin(), y.end(), c); + return lexicographical_compare(x.begin(), x.end(), y.begin(), y.end(), c); } template _UCXXEXPORT bool operator<=(const vector& x, const vector& y) { less_equal::iterator >::value_type> c; - return lexicographical_compare(x.begin(), x.end(), y.begin(), y.end(), c); + return lexicographical_compare(x.begin(), x.end(), y.begin(), y.end(), c); } template _UCXXEXPORT void swap(vector& x, vector& y){