Index: libcxx/include/istream =================================================================== --- libcxx/include/istream +++ libcxx/include/istream @@ -358,381 +358,162 @@ { } -template +template +_LIBCPP_INLINE_VISIBILITY basic_istream<_CharT, _Traits>& -basic_istream<_CharT, _Traits>::operator>>(unsigned short& __n) -{ +__input_arithmetic(basic_istream<_CharT, _Traits>& __is, _Tp& __n) { #ifndef _LIBCPP_NO_EXCEPTIONS try { #endif // _LIBCPP_NO_EXCEPTIONS - sentry __s(*this); + typename basic_istream<_CharT, _Traits>::sentry __s(__is); if (__s) { - typedef istreambuf_iterator _Ip; - typedef num_get _Fp; + typedef istreambuf_iterator<_CharT, _Traits> _Ip; + typedef num_get<_CharT, _Ip> _Fp; ios_base::iostate __err = ios_base::goodbit; - use_facet<_Fp>(this->getloc()).get(_Ip(*this), _Ip(), *this, __err, __n); - this->setstate(__err); + use_facet<_Fp>(__is.getloc()).get(_Ip(__is), _Ip(), __is, __err, __n); + __is.setstate(__err); } #ifndef _LIBCPP_NO_EXCEPTIONS } catch (...) { - this->__set_badbit_and_consider_rethrow(); + __is.__set_badbit_and_consider_rethrow(); } #endif // _LIBCPP_NO_EXCEPTIONS - return *this; + return __is; +} + +template +basic_istream<_CharT, _Traits>& +basic_istream<_CharT, _Traits>::operator>>(unsigned short& __n) +{ + return _VSTD::__input_arithmetic(*this, __n); } template basic_istream<_CharT, _Traits>& basic_istream<_CharT, _Traits>::operator>>(unsigned int& __n) { -#ifndef _LIBCPP_NO_EXCEPTIONS - try - { -#endif // _LIBCPP_NO_EXCEPTIONS - sentry __s(*this); - if (__s) - { - typedef istreambuf_iterator _Ip; - typedef num_get _Fp; - ios_base::iostate __err = ios_base::goodbit; - use_facet<_Fp>(this->getloc()).get(_Ip(*this), _Ip(), *this, __err, __n); - this->setstate(__err); - } -#ifndef _LIBCPP_NO_EXCEPTIONS - } - catch (...) - { - this->__set_badbit_and_consider_rethrow(); - } -#endif // _LIBCPP_NO_EXCEPTIONS - return *this; + return _VSTD::__input_arithmetic(*this, __n); } template basic_istream<_CharT, _Traits>& basic_istream<_CharT, _Traits>::operator>>(long& __n) { -#ifndef _LIBCPP_NO_EXCEPTIONS - try - { -#endif // _LIBCPP_NO_EXCEPTIONS - sentry __s(*this); - if (__s) - { - typedef istreambuf_iterator _Ip; - typedef num_get _Fp; - ios_base::iostate __err = ios_base::goodbit; - use_facet<_Fp>(this->getloc()).get(_Ip(*this), _Ip(), *this, __err, __n); - this->setstate(__err); - } -#ifndef _LIBCPP_NO_EXCEPTIONS - } - catch (...) - { - this->__set_badbit_and_consider_rethrow(); - } -#endif // _LIBCPP_NO_EXCEPTIONS - return *this; + return _VSTD::__input_arithmetic(*this, __n); } template basic_istream<_CharT, _Traits>& basic_istream<_CharT, _Traits>::operator>>(unsigned long& __n) { -#ifndef _LIBCPP_NO_EXCEPTIONS - try - { -#endif // _LIBCPP_NO_EXCEPTIONS - sentry __s(*this); - if (__s) - { - typedef istreambuf_iterator _Ip; - typedef num_get _Fp; - ios_base::iostate __err = ios_base::goodbit; - use_facet<_Fp>(this->getloc()).get(_Ip(*this), _Ip(), *this, __err, __n); - this->setstate(__err); - } -#ifndef _LIBCPP_NO_EXCEPTIONS - } - catch (...) - { - this->__set_badbit_and_consider_rethrow(); - } -#endif // _LIBCPP_NO_EXCEPTIONS - return *this; + return _VSTD::__input_arithmetic(*this, __n); } template basic_istream<_CharT, _Traits>& basic_istream<_CharT, _Traits>::operator>>(long long& __n) { -#ifndef _LIBCPP_NO_EXCEPTIONS - try - { -#endif // _LIBCPP_NO_EXCEPTIONS - sentry __s(*this); - if (__s) - { - typedef istreambuf_iterator _Ip; - typedef num_get _Fp; - ios_base::iostate __err = ios_base::goodbit; - use_facet<_Fp>(this->getloc()).get(_Ip(*this), _Ip(), *this, __err, __n); - this->setstate(__err); - } -#ifndef _LIBCPP_NO_EXCEPTIONS - } - catch (...) - { - this->__set_badbit_and_consider_rethrow(); - } -#endif // _LIBCPP_NO_EXCEPTIONS - return *this; + return _VSTD::__input_arithmetic(*this, __n); } template basic_istream<_CharT, _Traits>& basic_istream<_CharT, _Traits>::operator>>(unsigned long long& __n) { -#ifndef _LIBCPP_NO_EXCEPTIONS - try - { -#endif // _LIBCPP_NO_EXCEPTIONS - sentry __s(*this); - if (__s) - { - typedef istreambuf_iterator _Ip; - typedef num_get _Fp; - ios_base::iostate __err = ios_base::goodbit; - use_facet<_Fp>(this->getloc()).get(_Ip(*this), _Ip(), *this, __err, __n); - this->setstate(__err); - } -#ifndef _LIBCPP_NO_EXCEPTIONS - } - catch (...) - { - this->__set_badbit_and_consider_rethrow(); - } -#endif // _LIBCPP_NO_EXCEPTIONS - return *this; + return _VSTD::__input_arithmetic(*this, __n); } template basic_istream<_CharT, _Traits>& basic_istream<_CharT, _Traits>::operator>>(float& __n) { -#ifndef _LIBCPP_NO_EXCEPTIONS - try - { -#endif // _LIBCPP_NO_EXCEPTIONS - sentry __s(*this); - if (__s) - { - typedef istreambuf_iterator _Ip; - typedef num_get _Fp; - ios_base::iostate __err = ios_base::goodbit; - use_facet<_Fp>(this->getloc()).get(_Ip(*this), _Ip(), *this, __err, __n); - this->setstate(__err); - } -#ifndef _LIBCPP_NO_EXCEPTIONS - } - catch (...) - { - this->__set_badbit_and_consider_rethrow(); - } -#endif // _LIBCPP_NO_EXCEPTIONS - return *this; + return _VSTD::__input_arithmetic(*this, __n); } template basic_istream<_CharT, _Traits>& basic_istream<_CharT, _Traits>::operator>>(double& __n) { -#ifndef _LIBCPP_NO_EXCEPTIONS - try - { -#endif // _LIBCPP_NO_EXCEPTIONS - sentry __s(*this); - if (__s) - { - typedef istreambuf_iterator _Ip; - typedef num_get _Fp; - ios_base::iostate __err = ios_base::goodbit; - use_facet<_Fp>(this->getloc()).get(_Ip(*this), _Ip(), *this, __err, __n); - this->setstate(__err); - } -#ifndef _LIBCPP_NO_EXCEPTIONS - } - catch (...) - { - this->__set_badbit_and_consider_rethrow(); - } -#endif // _LIBCPP_NO_EXCEPTIONS - return *this; + return _VSTD::__input_arithmetic(*this, __n); } template basic_istream<_CharT, _Traits>& basic_istream<_CharT, _Traits>::operator>>(long double& __n) { -#ifndef _LIBCPP_NO_EXCEPTIONS - try - { -#endif // _LIBCPP_NO_EXCEPTIONS - sentry __s(*this); - if (__s) - { - typedef istreambuf_iterator _Ip; - typedef num_get _Fp; - ios_base::iostate __err = ios_base::goodbit; - use_facet<_Fp>(this->getloc()).get(_Ip(*this), _Ip(), *this, __err, __n); - this->setstate(__err); - } -#ifndef _LIBCPP_NO_EXCEPTIONS - } - catch (...) - { - this->__set_badbit_and_consider_rethrow(); - } -#endif // _LIBCPP_NO_EXCEPTIONS - return *this; + return _VSTD::__input_arithmetic(*this, __n); } template basic_istream<_CharT, _Traits>& basic_istream<_CharT, _Traits>::operator>>(bool& __n) { -#ifndef _LIBCPP_NO_EXCEPTIONS - try - { -#endif // _LIBCPP_NO_EXCEPTIONS - sentry __s(*this); - if (__s) - { - typedef istreambuf_iterator _Ip; - typedef num_get _Fp; - ios_base::iostate __err = ios_base::goodbit; - use_facet<_Fp>(this->getloc()).get(_Ip(*this), _Ip(), *this, __err, __n); - this->setstate(__err); - } -#ifndef _LIBCPP_NO_EXCEPTIONS - } - catch (...) - { - this->__set_badbit_and_consider_rethrow(); - } -#endif // _LIBCPP_NO_EXCEPTIONS - return *this; + return _VSTD::__input_arithmetic(*this, __n); } template basic_istream<_CharT, _Traits>& basic_istream<_CharT, _Traits>::operator>>(void*& __n) { -#ifndef _LIBCPP_NO_EXCEPTIONS - try - { -#endif // _LIBCPP_NO_EXCEPTIONS - sentry __s(*this); - if (__s) - { - typedef istreambuf_iterator _Ip; - typedef num_get _Fp; - ios_base::iostate __err = ios_base::goodbit; - use_facet<_Fp>(this->getloc()).get(_Ip(*this), _Ip(), *this, __err, __n); - this->setstate(__err); - } -#ifndef _LIBCPP_NO_EXCEPTIONS - } - catch (...) - { - this->__set_badbit_and_consider_rethrow(); - } -#endif // _LIBCPP_NO_EXCEPTIONS - return *this; + return _VSTD::__input_arithmetic(*this, __n); } -template +template +_LIBCPP_INLINE_VISIBILITY basic_istream<_CharT, _Traits>& -basic_istream<_CharT, _Traits>::operator>>(short& __n) -{ +__input_arithmetic_with_numeric_limits(basic_istream<_CharT, _Traits>& __is, _Tp& __n) { #ifndef _LIBCPP_NO_EXCEPTIONS try { #endif // _LIBCPP_NO_EXCEPTIONS - sentry __s(*this); + typename basic_istream<_CharT, _Traits>::sentry __s(__is); if (__s) { - typedef istreambuf_iterator _Ip; - typedef num_get _Fp; + typedef istreambuf_iterator<_CharT, _Traits> _Ip; + typedef num_get<_CharT, _Ip> _Fp; ios_base::iostate __err = ios_base::goodbit; long __temp; - use_facet<_Fp>(this->getloc()).get(_Ip(*this), _Ip(), *this, __err, __temp); - if (__temp < numeric_limits::min()) + use_facet<_Fp>(__is.getloc()).get(_Ip(__is), _Ip(), __is, __err, __temp); + if (__temp < numeric_limits<_Tp>::min()) { __err |= ios_base::failbit; - __n = numeric_limits::min(); + __n = numeric_limits<_Tp>::min(); } - else if (__temp > numeric_limits::max()) + else if (__temp > numeric_limits<_Tp>::max()) { __err |= ios_base::failbit; - __n = numeric_limits::max(); + __n = numeric_limits<_Tp>::max(); } else - __n = static_cast(__temp); - this->setstate(__err); + __n = static_cast<_Tp>(__temp); + __is.setstate(__err); } #ifndef _LIBCPP_NO_EXCEPTIONS } catch (...) { - this->__set_badbit_and_consider_rethrow(); + __is.__set_badbit_and_consider_rethrow(); } #endif // _LIBCPP_NO_EXCEPTIONS - return *this; + return __is; +} + +template +basic_istream<_CharT, _Traits>& +basic_istream<_CharT, _Traits>::operator>>(short& __n) +{ + return _VSTD::__input_arithmetic_with_numeric_limits(*this, __n); } template basic_istream<_CharT, _Traits>& basic_istream<_CharT, _Traits>::operator>>(int& __n) { -#ifndef _LIBCPP_NO_EXCEPTIONS - try - { -#endif // _LIBCPP_NO_EXCEPTIONS - sentry __s(*this); - if (__s) - { - typedef istreambuf_iterator _Ip; - typedef num_get _Fp; - ios_base::iostate __err = ios_base::goodbit; - long __temp; - use_facet<_Fp>(this->getloc()).get(_Ip(*this), _Ip(), *this, __err, __temp); - if (__temp < numeric_limits::min()) - { - __err |= ios_base::failbit; - __n = numeric_limits::min(); - } - else if (__temp > numeric_limits::max()) - { - __err |= ios_base::failbit; - __n = numeric_limits::max(); - } - else - __n = static_cast(__temp); - this->setstate(__err); - } -#ifndef _LIBCPP_NO_EXCEPTIONS - } - catch (...) - { - this->__set_badbit_and_consider_rethrow(); - } -#endif // _LIBCPP_NO_EXCEPTIONS - return *this; + return _VSTD::__input_arithmetic_with_numeric_limits(*this, __n); } template