_pback_cur_save = this->gptr(); _M_pback_end_save = this->egptr(); this->setg(&_M_pback, &_M_pback, &_M_pback + 1); _M_pback_init = true; } } /** * Deactivates pback buffer contents, and restores normal buffer. * Assumptions: * The pback buffer has only moved forward. */ void _M_destroy_pback() throw() { if (_M_pback_init) { // Length _M_in_cur moved in the pback buffer. _M_pback_cur_save += this->gptr() != this->eback(); this->setg(_M_buf, _M_pback_cur_save, _M_pback_end_save); _M_pback_init = false; } } public: // Constructors/destructor: /** * @brief Does not open any files. * * The default constructor initializes the parent class using its * own default ctor. */ basic_filebuf(); /** * @brief The destructor closes the file first. */ virtual ~basic_filebuf() { this->close(); } // Members: /** * @brief Returns true if the external file is open. */ bool is_open() const throw() { return _M_file.is_open(); } /** * @brief Opens an external file. * @param s The name of the file. * @param mode The open mode flags. * @return @c this on success, NULL on failure * * If a file is already open, this function immediately fails. * Otherwise it tries to open the file named @a s using the flags * given in @a mode. * * Table 92, adapted here, gives the relation between openmode * combinations and the equivalent fopen() flags. * (NB: lines app, in|out|app, in|app, binary|app, binary|in|out|app, * and binary|in|app per DR 596) * +---------------------------------------------------------+ * | ios_base Flag combination stdio equivalent | * |binary in out trunc app | * +---------------------------------------------------------+ * | + "w" | * | + + "a" | * | + "a" | * | + + "w" | * | + "r" | * | + + "r+" | * | + + + "w+" | * | + + + "a+" | * | + + "a+" | * +---------------------------------------------------------+ * | + + "wb" | * | + + + "ab" | * | + + "ab" | * | + + + "wb" | * | + + "rb" | * | + + + "r+b" | * | + + + + "w+b" | * | + + + + "a+b" | * | + + + "a+b" | * +---------------------------------------------------------+ */ __filebuf_type* open(const char* __s, ios_base::openmode __mode); /** * @brief Closes the currently associated file. * @return @c this on success, NULL on failure * * If no file is currently open, this function immediately fails. * * If a "put buffer area" exists, @c overflow(eof) is called to flush * all the characters. The file is then closed. * * If any operations fail, this function also fails. */ __filebuf_type* close(); protected: void _M_allocate_internal_buffer(); void _M_destroy_internal_buffer() throw(); // [27.8.1.4] overridden virtual functions virtual streamsize showmanyc(); // Stroustrup, 1998, p. 628 // underflow() and uflow() functions are called to get the next // character from the real input source when the buffer is empty. // Buffered input uses underflow() virtual int_type underflow(); virtual int_type pbackfail(int_type __c = _Traits::eof()); // Stroustrup, 1998, p 648 // The overflow() function is called to transfer characters to the // real output destination when the buffer is full. A call to // overflow(c) outputs the contents of the buffer plus the // character c. // 27.5.2.4.5 // Consume some sequence of the characters in the pending sequence. virtual int_type overflow(int_type __c = _Traits::eof()); // Convert internal byte sequence to external, char-based // sequence via codecvt. bool _M_convert_to_external(char_type*, streamsize); /** * @brief Manipulates the buffer. * @param s Pointer to a buffer area. * @param n Size of @a s. * @return @c this * * If no file has been opened, and both @a s and @a n are zero, then * the stream becomes unbuffered. Otherwise, @c s is used as a * buffer; see * http://gcc.gnu.org/onlinedocs/libstdc++/manual/bk01pt11ch25s02.html * for more. */ virtual __streambuf_type* setbuf(char_type* __s, streamsize __n); virtual pos_type seekoff(off_type __off, ios_base::seekdir __way, ios_base::openmode __mode = ios_base::in | ios_base::out); virtual pos_type seekpos(pos_type __pos, ios_base::openmode __mode = ios_base::in | ios_base::out); // Common code for seekoff and seekpos pos_type _M_seek(off_type __off, ios_base::seekdir __way, __state_type __state); virtual int sync(); virÇ%È%É%Ê%Ë%Ì%Í%Î%Ï%Ð%Ñ%Ò%Ó%tual void imbue(const locale& __loc); virtual streamsize xsgetn(char_type* __s, streamsize __n); virtual streamsize xsputn(const char_type* __s, streamsize __n); // Flushes output buffer, then writes unshift sequence. bool _M_terminate_output(); /** * This function sets the pointers of the internal buffer, both get * and put areas. Typically: * * __off == egptr() - eback() upon underflow/uflow ('read' mode); * __off == 0 upon overflow ('write' mode); * __off == -1 upon open, setbuf, seekoff/pos ('uncommitted' mode). * * NB: epptr() - pbase() == _M_buf_size - 1, since _M_buf_size * reflects the actual allocated memory and the last cell is reserved * for the overflow char of a full put area. */ void _M_set_buffer(streamsize __off) { const bool __testin = _M_mode & ios_base::in; const bool __testout = _M_mode & ios_base::out; if (__testin && __off > 0) this->setg(_M_buf, _M_buf, _M_buf + __off); else this->setg(_M_buf, _M_buf, _M_buf); if (__testout && __off == 0 && _M_buf_size > 1 ) this->setp(_M_buf, _M_buf + _M_buf_size - 1); else this->setp(NULL, NULL); } }; // [27.8.1.5] Template class basic_ifstream /** * @brief Controlling input for files. * * This class supports reading from named files, using the inherited * functions from std::basic_istream. To control the associated * sequence, an instance of std::basic_filebuf is used, which this page * refers to as @c sb. */ template class basic_ifstream : public basic_istream<_CharT, _Traits> { public: // Types: typedef _CharT char_type; typedef _Traits traits_type; typedef typename traits_type::int_type int_type; typedef typename traits_type::pos_type pos_type; typedef typename traits_type::off_type off_type; // Non-standard types: typedef basic_filebuf __filebuf_type; typedef basic_istream __istream_type; private: __filebuf_type _M_filebuf; public: // Constructors/Destructors: /** * @brief Default constructor. * * Initializes @c sb using its default constructor, and passes * @c &sb to the base class initializer. Does not open any files * (you haven't given it a filename to open). */ basic_ifstream() : __istream_type(), _M_filebuf() { this->init(&_M_filebuf); } /** * @brief Create an input file stream. * @param s Null terminated string specifying the filename. * @param mode Open file in specified mode (see std::ios_base). * * @c ios_base::in is automatically included in @a mode. * * Tip: When using std::string to hold the filename, you must use * .c_str() before passing it to this constructor. */ explicit basic_ifstream(const char* __s, ios_base::openmode __mode = ios_base::in) : __istream_type(), _M_filebuf() { this->init(&_M_filebuf); this->open(__s, __mode); } /** * @brief The destructor does nothing. * * The file is closed by the filebuf object, not the formatting * stream. */ ~basic_ifstream() { } // Members: /** * @brief Accessing the underlying buffer. * @return The current basic_filebuf buffer. * * This hides both signatures of std::basic_ios::rdbuf(). */ __filebuf_type* rdbuf() const { return const_cast<__filebuf_type*>(&_M_filebuf); } /** * @brief Wrapper to test for an open file. * @return @c rdbuf()->is_open() */ bool is_open() { return _M_filebuf.is_open(); } // _GLIBCXX_RESOLVE_LIB_DEFECTS // 365. Lack of const-qualification in clause 27 bool is_open() const { return _M_filebuf.is_open(); } /** * @brief Opens an external file. * @param s The name of the file. * @param mode The open mode flags. * * Calls @c std::basic_filebuf::open(s,mode|in). If that function * fails, @c failbit is set in the stream's error state. * * Tip: When using std::string to hold the filename, you must use * .c_str() before passing it to this constructor. */ void open(const char* __s, ios_base::openmode __mode = ios_base::in) { if (!_M_filebuf.open(__s, __mode | ios_base::in)) this->setstate(ios_base::failbit); else // _GLIBCXX_RESOLVE_LIB_DEFECTS // 409. Closing an fstream should clear error state this->clear(); } /** * @brief Close the file. * * Calls @c std::basic_filebuf::close(). If that function * fails, @c failbit is set in the stream's error state. */ void close() { if (!_M_filebuf.close()) this->setstate(ios_base::failbit); } }; // [27.8.1.8] Template class basic_ofstream /** * @brief Controlling output for files. * * This class supports reading from named files, using the inherited * functions from std::basic_ostream. To control the associated * sequence, an instance of std::basic_filebuf is used, which this page * refers to as @c sb. */ template class basic_ofstream : public basic_ostream<_CharT,_Traits> { public: // Types: typedef _CharT char_type; typedef _Traits traits_type; typedef typename traits_type::int_type int_type; typedef typename traits_type::pos_type pos_type; typedef typename traits_type::off_type off_type; // Non-standard types: typedef basic_filebuf __filebuf_type; typedef basic_ostream __ostream_type; private: __filebuf_type _M_filebuf; public: // Constructors: /** * @brief Default constructor. * * Initializes @c sb using its default constructor, and passes * @c &sb to the base class initializer. Does not open any files * (you haven't given it a filename to open). */ basic_ofstream(): __ostream_type(), _M_filebuf() { this->init(&_M_filebuf); } /** * @brief Create an output file stream. * @param s Null terminated string specifying the filename. * @param mode Open file in specified mode (see std::ios_base). * * @c ios_base::out|ios_base::trunc is automatically included in * @a mode. * * Tip: When using std::string to hold the filename, you must use * .c_str() before passing it to this constructor. */ explicit basic_ofstream(const char* __s, ios_base::openmode __mode = ios_base::out|ios_base::trunc) : __ostream_type(), _M_filebuf() { this->init(&_M_filebuf); this->open(__s, __mode); } /** * @brief The destructor does nothing. * * The file is closed by the filebuf object, not the formatting * stream. */ ~basic_ofstream() { } // Members: /** * @brief Accessing the underlying buffer. * @return The current basic_filebuf buffer. * * This hides both signatures of std::basic_ios::rdbuf(). */ __filebuf_type* rdbuf() const { return const_cast<__filebuf_type*>(&_M_filebuf); } /** * @brief Wrapper to test for an open file. * @return @c rdbuf()->is_open() */ bool is_open() { return _M_filebuf.is_open(); } // _GLIBCXX_RESOLVE_LIB_DEFECTS // 365. Lack of const-qualification in clause 27 bool is_open() const { return _M_filebuf.is_open(); } /** * @brief Opens an external file. * @param s The name of the file. * @param mode The open mode flags. * * Calls @c std::basic_filebuf::open(s,mode|out|trunc). If that * function fails, @c failbit is set in the stream's error state. * * Tip: When using std::string to hold the filename, you must use * .c_str() before passing it to this constructor. */ void open(const char* __s, ios_base::openmode __mode = ios_base::out | ios_base::trunc) { if (!_M_filebuf.open(__s, __mode | ios_base::out)) this->setstate(ios_base::failbit); else // _GLIBCXX_RESOLVE_LIB_DEFECTS // 409. Closing an fstream should clear error state this->clear(); } /** * @brief Close the file. * * Calls @c std::basic_filebuf::close(). If that function * fails, @c failbit is set in the stream's error state. */ void close() { if (!_M_filebuf.close()) this->setstate(ios_base::failbit); } }; // [27.8.1.11] Template class basic_fstream /** * @brief Controlling input and output for files. * * This class supports reading from and writing to named files, using * the inherited functions from std::basic_iostream. To control the * associated sequence, an instance of std::basic_filebuf is used, which * this page refers to as @c sb. */ template class basic_fstream : public basic_iostream<_CharT, _Traits> { public: // Types: typedef _CharT char_type; typedef _Traits traits_type; typedef typename traits_type::int_type int_type; typedef typename traits_type::pos_type pos_type; typedef typename traits_type::off_type off_type; // Non-standard types: typedef basic_filebuf __filebuf_type; typedef basic_ios __ios_type; typedef basic_iostream __iostream_type; private: __filebuf_type _M_filebuf; public: // Constructors/destructor: /** * @brief Default constructor. * * Initializes @c sb using its default constructor, and passes * @c &sb to the base class initializer. Does not open any files * (you haven't given it a filename to open). */ basic_fstream() : __iostream_type(), _M_filebuf() { this->init(&_M_filebuf); } /** * @brief Create an input/output file stream. * @param s Null terminated string specifying the filename. * @param mode Open file in specified mode (see std::ios_base). * * Tip: When using std::string to hold the filename, you must use * .c_str() before passing it to this constructor. */ explicit basic_fstream(const char* __s, ios_base::openmode __mode = ios_base::in | ios_base::out) : __iostream_type(NULL), _M_filebuf() { this->init(&_M_filebuf); this->open(__s, __mode); } /** * @brief The destructor does nothing. * * The file is closed by the filebuf object, not the formatting * stream. */ ~basic_fstream() { } // Members: /** * @brief Accessing the underlying buffer. * @return The current basic_filebuf buffer. * * This hides both signatures of std::basic_ios::rdbuf(). */ __filebuf_type* rdbuf() const { return const_cast<__filebuf_type*>(&_M_filebuf); } /** * @brief Wrapper to test for an open file. * @return @c rdbuf()->is_open() */ bool is_open() { return _M_filebuf.is_open(); } // _GLIBCXX_RESOLVE_LIB_DEFECTS // 365. Lack of const-qualification in clause 27 bool is_open() const { return _M_filebuf.is_open(); } /** * @brief Opens an external file. * @param s The name of the file. * @param mode The open mode flags. * * Calls @c std::basic_filebuf::open(s,mode). If that * function fails, @c failbit is set in the stream's error state. * * Tip: When using std::string to hold the filename, you must use * .c_str() before passing it to this constructor. */ void open(const char* __s, ios_base::openmode __mode = ios_base::in | ios_base::out) { if (!_M_filebuf.open(__s, __mode)) this->setstate(ios_base::failbit); else // _GLIBCXX_RESOLVE_LIB_DEFECTS // 409. Closing an fstream should clear error state this->clear(); } /** * @brief Close the file. * * Calls @c std::basic_filebuf::close(). If that function * fails, @c failbit is set in the stream's error state. */ void close() { if (!_M_filebuf.close()) this->setstate(ios_base::failbit); } }; _GLIBCXX_END_NAMESPACE #ifndef _GLIBCXX_EXPORT_TEMPLATE # include #endif #endif /* _GLIBCXX_FSTREAM */ // -*- C++ -*- // Copyright (C) 2007 Free Software Foundation, Inc. // // This file is part of the GNU ISO C++ Library. This library is free // software; you can redistribute it and/or modify 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. // 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 General Public License for more details. // You should have received a copy of the GNU General Public License // along with this library; see the file COPYING. If not, write to // the Free Software Foundation, 51 Franklin Street, Fifth Floor, // Boston, MA 02110-1301, USA. // As a special exception, you may use this file as part of a free software // library without restriction. Specifically, if other files instantiate // templates or use macros or inline functions from this file, or you compile // this file and link it with other files to produce an executable, this // file does not by itself cause the resulting executable to be covered by // the GNU General Public License. This exception does not however // invalidate any other reasons why the executable file might be covered by // the GNU General Public License. /** @file include/array * This is a Standard C++ Library header. */ #ifndef _GLIBCXX_CXX0X_ARRAY #define _GLIBCXX_CXX0X_ARRAY 1 #pragma GCC system_header #ifndef __GXX_EXPERIMENTAL_CXX0X__ # include #endif #if defined(_GLIBCXX_INCLUDE_AS_TR1) # error C++0x header cannot be included from TR1 header #endif #include #if defined(_GLIBCXX_INCLUDE_AS_CXX0X) # include #else # define _GLIBCXX_INCLUDE_AS_CXX0X # define _GLIBCXX_BEGIN_NAMESPACE_TR1 # define _GLIBCXX_END_NAMESPACE_TR1 # define _GLIBCXX_TR1 # include # undef _GLIBCXX_TR1 # undef _GLIBCXX_END_NAMESPACE_TR1 # undef _GLIBCXX_BEGIN_NAMESPACE_TR1 # undef _GLIBCXX_INCLUDE_AS_CXX0X #endif #endif // _GLIBCXX_CXX0X_ARRAY // -*- C++ -*- // Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007 // Free Software Foundation, Inc. // // This file is part of the GNU ISO C++ Library. This library is free // software; you can redistribute it and/or modify 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. // 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 General Public License for more details. // You should have received a copy of the GNU General Public License // along with this library; see the file COPYING. If not, write to // the Free Software Foundation, 51 Franklin Street, Fifth Floor, // Boston, MA 02110-1301, USA. // As a special exception, you may use this file as part of a free software // library without restriction. Specifically, if other files instantiate // templates or use macros or inline functions from this file, or you compile // this file and link it with other files to produce an executable, this // file does not by itself cause the resulting executable to be covered by // the GNU General Public License. This exception does not however // invalidate any other reasons why the executable file might be covered by // the GNU General Public License. /* * * Copyright (c) 1994 * Hewlett-Packard Company * * Permission to use, copy, modify, distribute and sell this software * and its documentation for any purpose is hereby granted without fee, * provided that the above copyright notice appear in all copies and * that both that copyright notice and this permission notice appear * in supporting documentation. Hewlett-Packard Company makes no * representations about the suitability of this software for any * purpose. It is provided "as is" without express or implied warranty. * * * Copyright (c) 1996,1997 * Silicon Graphics Computer Systems, Inc. * * Permission to use, copy, modify, distribute and sell this software * and its documentation for any purpose is hereby granted without fee, * provided that the above copyright notice appear in all copies and * that both that copyright notice and this permission notice appear * in supporting documentation. Silicon Graphics makes no * representations about the suitability of this software for any * purpose. It is provided "as is" without express or implied warranty. */ /** @file include/utility * This is a Standard C++ Library header. */ #ifndef _GLIBCXX_UTILITY #define _GLIBCXX_UTILITY 1 #pragma GCC system_header #include #include #include #ifdef __GXX_EXPERIMENTAL_CXX0X__ # if defined(_GLIBCXX_INCLUDE_AS_TR1) # error C++0x header cannot be included from TR1 header # endif # if defined(_GLIBCXX_INCLUDE_AS_CXX0X) # include # else # define _GLIBCXX_INCLUDE_AS_CXX0X # define _GLIBCXX_BEGIN_NAMESPACE_TR1 # define _GLIBCXX_END_NAMESPACE_TR1 # define _GLIBCXX_TR1 # include # undef _GLIBCXX_TR1 # undef _GLIBCXX_END_NAMESPACE_TR1 # undef _GLIBCXX_BEGIN_NAMESPACE_TR1 # undef _GLIBCXX_INCLUDE_AS_CXX0X # endif # include #endif #endif /* _GLIBCXX_UTILITY */ // cxxabi.h subset for inclusion by other library headers -*- C++ -*- // Copyright (C) 2007 Free Software Foundation, Inc. // // This file is part of GCC. // // GCC is free software; you can redistribute it and/or modify // 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. // // GCC 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 GCC; see the file COPYING. If not, write to // the Free Software Foundation, 51 Franklin Street, Fifth Floor, // Boston, MA 02110-1301, USA. // As a special exception, you may use this file as part of a free software // library without restriction. Specifically, if other files instantiate // templates or use macros or inline functions from this file, or you compile // this file and link it with other files to produce an executable, this // file does not by itself cause the resulting executable to be covered by // the GNU General Public License. This exception does not however // invalidate any other reasons why the executable file might be covered by // the GNU General Public License. #ifndef _CXXABI_FORCED_H #define _CXXABI_FORCED_H 1 #pragma GCC visibility push(default) #ifdef __cplusplus namespace __cxxabiv1 { // A magic placeholder class that can be caught by reference // to recognize forced unwinding. class __forced_unwind { virtual ~__forced_unwind() throw(); virtual void __pure_dummy() = 0; // prevent catch by value }; } #endif // __cplusplus #pragma GCC visibility pop #endif // __CXXABI_FORCED_H // -*- C++ -*- forwarding header. // Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, // 2006, 2007, 2008 // Free Software Foundation, Inc. // // This file is part of the GNU ISO C++ Library. This library is free // software; you can redistribute it and/or modify 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. // 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 General Public License for more details. // You should have received a copy of the GNU General Public License // along with this library; see the file COPYING. If not, write to // the Free Software Foundation, 51 Franklin Street, Fifth Floor, // Boston, MA 02110-1301, USA. // As a special exception, you may use this file as part of a free software // library without restriction. Specifically, if other files instantiate // templates or use macros or inline functions from this file, or you compile // this file and link it with other files to produce an executable, this // file does not by itself cause the resulting executable to be covered by // the GNU General Public License. This exception does not however // invalidate any other reasons why the executable file might be covered by // the GNU General Public License. /** @file include/cfloat * This is a Standard C++ Library file. You should @c #include this file * in your programs, rather than any of the "*.h" implementation files. * * This is the C++ version of the Standard C Library header @c float.h, * and its contents are (mostly) the same as that header, but are all * contained in the namespace @c std (except for names which are defined * as macros in C). */ // // ISO C++ 14882: 18.2.2 Implementation properties: C library // #pragma GCC system_header #include #ifndef _GLIBCXX_CFLOAT #define _GLIBCXX_CFLOAT 1 #ifdef __GXX_EXPERIMENTAL_CXX0X__ # if defined(_GLIBCXX_INCLUDE_AS_TR1) # error C++0x header cannot be included from TR1 header # endif # ifndef DECIMAL_DIG # define DECIMAL_DIG __DECIMAL_DIG__ # endif # ifndef FLT_EVAL_METHOD # define FLT_EVAL_METHOD __FLT_EVAL_METHOD__ # endif #endif #endif // The template and inlines for the numeric_limits classes. -*- C++ -*- // Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008 // Free Software Foundation, Inc. // // This file is part of the GNU ISO C++ Library. This library is free // software; you can redistribute it and/or modify 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. // 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 General Public License for more details. // You should have received a copy of the GNU General Public License // along with this library; see the file COPYING. If not, write to // the Free Software Foundation, 51 Franklin Street, Fifth Floor, // Boston, MA 02110-1301, USA. // As a special exception, you may use this file as part of a free software // library without restriction. Specifically, if other files instantiate // templates or use macros or inline functions from this file, or you compile // this file and link it with other files to produce an executable, this // file does not by itself cause the resulting executable to be covered by // the GNU General Public License. This exception does not however // invalidate any other reasons why the executable file might be covered by // the GNU General Public License. /** @file limits * This is a Standard C++ Library header. */ // Note: this is not a conforming implementation. // Written by Gabriel Dos Reis // // ISO 14882:1998 // 18.2.1 // #ifndef _GLIBCXX_NUMERIC_LIMITS #define _GLIBCXX_NUMERIC_LIMITS 1 #pragma GCC system_header #include // // The numeric_limits<> traits document implementation-defined aspects // of fundamental arithmetic data types (integers and floating points). // From Standard C++ point of view, there are 13 such types: // * integers // bool (1) // char, signed char, unsigned char (3) // short, unsigned short (2) // int, unsigned (2) // long, unsigned long (2) // // * floating points // float (1) // double (1) // long double (1) // // GNU C++ understands (where supported by the host C-library) // * integer // long long, unsigned long long (2) // // which brings us to 15 fundamental arithmetic data types in GNU C++. // // // Since a numeric_limits<> is a bit tricky to get right, we rely on // an interface composed of macros which should be defined in config/os // or config/cpu when they differ from the generic (read arbitrary) // definitions given here. // // These values can be overridden in the target configuration file. // The default values are appropriate for many 32-bit targets. // GCC only intrinsically supports modulo integral types. The only remaining // integral exceptional values is division by zero. Only targets that do not // signal division by zero in some "hard to ignore" way should use false. #ifndef __glibcxx_integral_traps # define __glibcxx_integral_traps true #endif // float // // Default values. Should be overridden in configuration files if necessary. #ifndef __glibcxx_float_has_denorm_loss # define __glibcxx_float_has_denorm_loss false #endif #ifndef __glibcxx_float_traps # define __glibcxx_float_traps false #endif #ifndef __glibcxx_float_tinyness_before # define __glibcxx_float_tinyness_before false #endif // double // Default values. Should be overridden in configuration files if necessary. #ifndef __glibcxx_double_has_denorm_loss # define __glibcxx_double_has_denorm_loss false #endif #ifndef __glibcxx_double_traps # define __glibcxx_double_traps false #endif #ifndef __glibcxx_double_tinyness_before # define __glibcxx_double_tinyness_before false #endif // long double // Default values. Should be overridden in configuration files if necessary. #ifndef __glibcxx_long_double_has_denorm_loss # define __glibcxx_long_double_has_denorm_loss false #endif #ifndef __glibcxx_long_double_traps # define __glibcxx_long_double_traps false #endif #ifndef __glibcxx_long_double_tinyness_before # define __glibcxx_long_double_tinyness_before false #endif // You should not need to define any macros below this point. #define __glibcxx_signed(T) ((T)(-1) < 0) #define __glibcxx_min(T) \ (__glibcxx_signed (T) ? (T)1 << __glibcxx_digits (T) : (T)0) #define __glibcxx_max(T) \ (__glibcxx_signed (T) ? \ (((((T)1 << (__glibcxx_digits (T) - 1)) - 1) << 1) + 1) : ~(T)0) #define __glibcxx_digits(T) \ (sizeof(T) * __CHAR_BIT__ - __glibcxx_signed (T)) // The fraction 643/2136 approximates log10(2) to 7 significant digits. #define __glibcxx_digits10(T) \ (__glibcxx_digits (T) * 643 / 2136) _GLIBCXX_BEGIN_NAMESPACE(std) /** * @brief Describes the rounding style for floating-point types. * * This is used in the std::numeric_limits class. */ enum float_round_style { round_indeterminate = -1, ///< Self-explanatory. round_toward_zero = 0, ///< Self-explanatory. round_to_nearest = 1, ///< To the nearest representable value. round_toward_infinity = 2, ///< Self-explanatory. round_toward_neg_infinity = 3 ///< Self-explanatory. }; /** * @brief Describes the denormalization for floating-point types. * * These values represent the presence or absence of a variable number * of exponent bits. This type is used in the std::numeric_limits class. */ enum float_denorm_style { /// Indeterminate at compile time whether denormalized values are allowed. denorm_indeterminate = -1, /// The type does not allow denormalized values. denorm_absent = 0, /// The type allows denormalized values. denorm_present = 1 }; /** * @brief Part of std::numeric_limits. * * The @c static @c const members are usable as integral constant * expressions. * * @note This is a separate class for purposes of efficiency; you * should only access these members as part of an instantiation * of the std::numeric_limits class. */ struct __numeric_limits_base { /** This will be true for all fundamental types (which have specializations), and false for everything else. */ static const bool is_specialized = false; /** The number of @c radix digits that be represented without change: for integer types, the number of non-sign bits in the mantissa; for floating types, the number of @c radix digits in the mantissa. */ static const int digits = 0; /** The number of base 10 digits that can be represented without change. */ static const int digits10 = 0; /** True if the type is signed. */ static const bool is_signed = false; /** True if the type is integer. * Is this supposed to be "if the type is integral"? */ static const bool is_integer = false; /** True if the type uses an exact representation. "All integer types are exact, but not all exact types are integer. For example, rational and fixed-exponent representations are exact but not integer." [18.2.1.2]/15 */ static const bool is_exact = false; /** For integer types, specifies the base of the representation. For floating types, specifies the base of the exponent representation. */ static const int radix = 0; /** The minimum negative integer such that @c radix raised to the power of (one less than that integer) is a normalized floating point number. */ static const int min_exponent = 0; /** The minimum negative integer such that 10 raised to that power is in the range of normalized floating point numbers. */ static const int min_exponent10 = 0; /** The maximum positive integer such that @c radix raised to the power of (one less than that integer) is a representable finite floating point number. */ static const int max_exponent = 0; /** The maximum positive integer such that 10 raised to that power is in the range of representable finite floating point numbers. */ static const int max_exponent10 = 0; /** True if the type has a representation for positive infinity. */ static const bool has_infinity = false; /** True if the type has a representation for a quiet (non-signaling) "Not a Number." */ static const bool has_quiet_NaN = false; /** True if the type has a representation for a signaling "Not a Number." */ static const bool has_signaling_NaN = false; /** See std::float_denorm_style for more information. */ static const float_denorm_style has_denorm = denorm_absent; /** "True if loss of accuracy is detected as a denormalization loss, rather than as an inexact result." [18.2.1.2]/42 */ static const bool has_denorm_loss = false; /** True if-and-only-if the type adheres to the IEC 559 standard, also known as IEEE 754. (Only makes sense for floating point types.) */ static const bool is_iec559 = false; /** "True if the set of values representable by the type is finite. All built-in types are bounded, this member would be false for arbitrary precision types." [18.2.1.2]/54 */ static const bool is_bounded = false; /** True if the type is @e modulo, that is, if it is possible to add two positive numbers and have a result that wraps around to a third number that is less. Typically false for floating types, true for unsigned integers, and true for signed integers. */ static const bool is_modulo = false; /** True if trapping is implemented for this type. */ static const bool traps = false; /** True if tininess is detected before rounding. (see IEC 559) */ static const bool tinyness_before = false; /** See std::float_round_style for more information. This is only meaningful for floating types; integer types will all be round_toward_zero. */ static const float_round_style round_style = round_toward_zero; }; /** * @brief Properties of fundamental types. * * This class allows a program to obtain information about the * representation of a fundamental type on a given platform. For * non-fundamental types, the functions will return 0 and the data * members will all be @c false. * * _GLIBCXX_RESOLVE_LIB_DEFECTS: DRs 201 and 184 (hi Gaby!) are * noted, but not incorporated in this documented (yet). */ template struct numeric_limits : public __numeric_limits_base { /** The minimum finite value, or for floating types with denormalization, the minimum positive normalized value. */ static _Tp min() throw() { return static_cast<_Tp>(0); } /** The maximum finite value. */ static _Tp max() throw() { return static_cast<_Tp>(0); } /** The @e machine @e epsilon: the difference between 1 and the least value greater than 1 that is representable. */ static _Tp epsilon() throw() { return static_cast<_Tp>(0); } /** The maximum rounding error measurement (see LIA-1). */ static _Tp round_error() throw() { return static_cast<_Tp>(0); } /** The representation of positive infinity, if @c has_infinity. */ static _Tp infinity() throw() { return static_cast<_Tp>(0); } /** The representation of a quiet "Not a Number," if @c has_quiet_NaN. */ static _Tp quiet_NaN() throw() { return static_cast<_Tp>(0); } /** The representation of a signaling "Not a Number," if @c has_signaling_NaN. */ static _Tp signaling_NaN() throw() { return static_cast<_Tp>(0); } /** The minimum positive denormalized value. For types where @c has_denorm is false, this is the minimum positive normalized value. */ static _Tp denorm_min() throw() { return static_cast<_Tp>(0); } }; // Now there follow 15 explicit specializations. Yes, 15. Make sure // you get the count right. /// numeric_limití%î%ï%ð%ñ%ò%ó%ô%õ%ö%÷%ø%ù%ú%û%ü%ý%þ%ÿ%&&&&&&&&& & &s specialization. template<> struct numeric_limits { static const bool is_specialized = true; static bool min() throw() { return false; } static bool max() throw() { return true; } static const int digits = 1; static const int digits10 = 0; static const bool is_signed = false; static const bool is_integer = true; static const bool is_exact = true; static const int radix = 2; static bool epsilon() throw() { return false; } static bool round_error() throw() { return false; } static const int min_exponent = 0; static const int min_exponent10 = 0; static const int max_exponent = 0; static const int max_exponent10 = 0; static const bool has_infinity = false; static const bool has_quiet_NaN = false; static const bool has_signaling_NaN = false; static const float_denorm_style has_denorm = denorm_absent; static const bool has_denorm_loss = false; static bool infinity() throw() { return false; } static bool quiet_NaN() throw() { return false; } static bool signaling_NaN() throw() { return false; } static bool denorm_min() throw() { return false; } static const bool is_iec559 = false; static const bool is_bounded = true; static const bool is_modulo = false; // It is not clear what it means for a boolean type to trap. // This is a DR on the LWG issue list. Here, I use integer // promotion semantics. static const bool traps = __glibcxx_integral_traps; static const bool tinyness_before = false; static const float_round_style round_style = round_toward_zero; }; /// numeric_limits specialization. template<> struct numeric_limits { static const bool is_specialized = true; static char min() throw() { return __glibcxx_min(char); } static char max() throw() { return __glibcxx_max(char); } static const int digits = __glibcxx_digits (char); static const int digits10 = __glibcxx_digits10 (char); static const bool is_signed = __glibcxx_signed (char); static const bool is_integer = true; static const bool is_exact = true; static const int radix = 2; static char epsilon() throw() { return 0; } static char round_error() throw() { return 0; } static const int min_exponent = 0; static const int min_exponent10 = 0; static const int max_exponent = 0; static const int max_exponent10 = 0; static const bool has_infinity = false; static const bool has_quiet_NaN = false; static const bool has_signaling_NaN = false; static const float_denorm_style has_denorm = denorm_absent; static const bool has_denorm_loss = false; static char infinity() throw() { return char(); } static char quiet_NaN() throw() { return char(); } static char signaling_NaN() throw() { return char(); } static char denorm_min() throw() { return static_cast(0); } static const bool is_iec559 = false; static const bool is_bounded = true; static const bool is_modulo = true; static const bool traps = __glibcxx_integral_traps; static const bool tinyness_before = false; static const float_round_style round_style = round_toward_zero; }; /// numeric_limits specialization. template<> struct numeric_limits { static const bool is_specialized = true; static signed char min() throw() { return -__SCHAR_MAX__ - 1; } static signed char max() throw() { return __SCHAR_MAX__; } static const int digits = __glibcxx_digits (signed char); static const int digits10 = __glibcxx_digits10 (signed char); static const bool is_signed = true; static const bool is_integer = true; static const bool is_exact = true; static const int radix = 2; static signed char epsilon() throw() { return 0; } static signed char round_error() throw() { return 0; } static const int min_exponent = 0; static const int min_exponent10 = 0; static const int max_exponent = 0; static const int max_exponent10 = 0; static const bool has_infinity = false; static const bool has_quiet_NaN = false; static const bool has_signaling_NaN = false; static const float_denorm_style has_denorm = denorm_absent; static const bool has_denorm_loss = false; static signed char infinity() throw() { return static_cast(0); } static signed char quiet_NaN() throw() { return static_cast(0); } static signed char signaling_NaN() throw() { return static_cast(0); } static signed char denorm_min() throw() { return static_cast(0); } static const bool is_iec559 = false; static const bool is_bounded = true; static const bool is_modulo = true; static const bool traps = __glibcxx_integral_traps; static const bool tinyness_before = false; static const float_round_style round_style = round_toward_zero; }; /// numeric_limits specialization. template<> struct numeric_limits { static const bool is_specialized = true; static unsigned char min() throw() { return 0; } static unsigned char max() throw() { return __SCHAR_MAX__ * 2U + 1; } static const int digits = __glibcxx_digits (unsigned char); static const int digits10 = __glibcxx_digits10 (unsigned char); static const bool is_signed = false; static const bool is_integer = true; static const bool is_exact = true; static const int radix = 2; static unsigned char epsilon() throw() { return 0; } static unsigned char round_error() throw() { return 0; } static const int min_exponent = 0; static const int min_exponent10 = 0; static const int max_exponent = 0; static const int max_exponent10 = 0; static const bool has_infinity = false; static const bool has_quiet_NaN = false; static const bool has_signaling_NaN = false; static const float_denorm_style has_denorm = denorm_absent; static const bool has_denorm_loss = false; static unsigned char infinity() throw() { return static_cast(0); } static unsigned char quiet_NaN() throw() { return static_cast(0); } static unsigned char signaling_NaN() throw() { return static_cast(0); } static unsigned char denorm_min() throw() { return static_cast(0); } static const bool is_iec559 = false; static const bool is_bounded = true; static const bool is_modulo = true; static const bool traps = __glibcxx_integral_traps; static const bool tinyness_before = false; static const float_round_style round_style = round_toward_zero; }; /// numeric_limits specialization. template<> struct numeric_limits { static const bool is_specialized = true; static wchar_t min() throw() { return __glibcxx_min (wchar_t); } static wchar_t max() throw() { return __glibcxx_max (wchar_t); } static const int digits = __glibcxx_digits (wchar_t); static const int digits10 = __glibcxx_digits10 (wchar_t); static const bool is_signed = __glibcxx_signed (wchar_t); static const bool is_integer = true; static const bool is_exact = true; static const int radix = 2; static wchar_t epsilon() throw() { return 0; } static wchar_t round_error() throw() { return 0; } static const int min_exponent = 0; static const int min_exponent10 = 0; static const int max_exponent = 0; static const int max_exponent10 = 0; static const bool has_infinity = false; static const bool has_quiet_NaN = false; static const bool has_signaling_NaN = false; static const float_denorm_style has_denorm = denorm_absent; static const bool has_denorm_loss = false; static wchar_t infinity() throw() { return wchar_t(); } static wchar_t quiet_NaN() throw() { return wchar_t(); } static wchar_t signaling_NaN() throw() { return wchar_t(); } static wchar_t denorm_min() throw() { return wchar_t(); } static const bool is_iec559 = false; static const bool is_bounded = true; static const bool is_modulo = true; static const bool traps = __glibcxx_integral_traps; static const bool tinyness_before = false; static const float_round_style round_style = round_toward_zero; }; /// numeric_limits specialization. template<> struct numeric_limits { static const bool is_specialized = true; static short min() throw() { return -__SHRT_MAX__ - 1; } static short max() throw() { return __SHRT_MAX__; } static const int digits = __glibcxx_digits (short); static const int digits10 = __glibcxx_digits10 (short); static const bool is_signed = true; static const bool is_integer = true; static const bool is_exact = true; static const int radix = 2; static short epsilon() throw() { return 0; } static short round_error() throw() { return 0; } static const int min_exponent = 0; static const int min_exponent10 = 0; static const int max_exponent = 0; static const int max_exponent10 = 0; static const bool has_infinity = false; static const bool has_quiet_NaN = false; static const bool has_signaling_NaN = false; static const float_denorm_style has_denorm = denorm_absent; static const bool has_denorm_loss = false; static short infinity() throw() { return short(); } static short quiet_NaN() throw() { return short(); } static short signaling_NaN() throw() { return short(); } static short denorm_min() throw() { return short(); } static const bool is_iec559 = false; static const bool is_bounded = true; static const bool is_modulo = true; static const bool traps = __glibcxx_integral_traps; static const bool tinyness_before = false; static const float_round_style round_style = round_toward_zero; }; /// numeric_limits specialization. template<> struct numeric_limits { static const bool is_specialized = true; static unsigned short min() throw() { return 0; } static unsigned short max() throw() { return __SHRT_MAX__ * 2U + 1; } static const int digits = __glibcxx_digits (unsigned short); static const int digits10 = __glibcxx_digits10 (unsigned short); static const bool is_signed = false; static const bool is_integer = true; static const bool is_exact = true; static const int radix = 2; static unsigned short epsilon() throw() { return 0; } static unsigned short round_error() throw() { return 0; } static const int min_exponent = 0; static const int min_exponent10 = 0; static const int max_exponent = 0; static const int max_exponent10 = 0; static const bool has_infinity = false; static const bool has_quiet_NaN = false; static const bool has_signaling_NaN = false; static const float_denorm_style has_denorm = denorm_absent; static const bool has_denorm_loss = false; static unsigned short infinity() throw() { return static_cast(0); } static unsigned short quiet_NaN() throw() { return static_cast(0); } static unsigned short signaling_NaN() throw() { return static_cast(0); } static unsigned short denorm_min() throw() { return static_cast(0); } static const bool is_iec559 = false; static const bool is_bounded = true; static const bool is_modulo = true; static const bool traps = __glibcxx_integral_traps; static const bool tinyness_before = false; static const float_round_style round_style = round_toward_zero; }; /// numeric_limits specialization. template<> struct numeric_limits { static const bool is_specialized = true; static int min() throw() { return -__INT_MAX__ - 1; } static int max() throw() { return __INT_MAX__; } static const int digits = __glibcxx_digits (int); static const int digits10 = __glibcxx_digits10 (int); static const bool is_signed = true; static const bool is_integer = true; static const bool is_exact = true; static const int radix = 2; static int epsilon() throw() { return 0; } static int round_error() throw() { return 0; } static const int min_exponent = 0; static const int min_exponent10 = 0; static const int max_exponent = 0; static const int max_exponent10 = 0; static const bool has_infinity = false; static const bool has_quiet_NaN = false; static const bool has_signaling_NaN = false; static const float_denorm_style has_denorm = denorm_absent; static const bool has_denorm_loss = false; static int infinity() throw() { return static_cast(0); } static int quiet_NaN() throw() { return static_cast(0); } static int signaling_NaN() throw() { return static_cast(0); } static int denorm_min() throw() { return static_cast(0); } static const bool is_iec559 = false; static const bool is_bounded = true; static const bool is_modulo = true; static const bool traps = __glibcxx_integral_traps; static const bool tinyness_before = false; static const float_round_style round_style = round_toward_zero; }; /// numeric_limits specialization. template<> struct numeric_limits { static const bool is_specialized = true; static unsigned int min() throw() { return 0; } static unsigned int max() throw() { return __INT_MAX__ * 2U + 1; } static const int digits = __glibcxx_digits (unsigned int); static const int digits10 = __glibcxx_digits10 (unsigned int); static const bool is_signed = false; static const bool is_integer = true; static const bool is_exact = true; static const int radix = 2; static unsigned int epsilon() throw() { return 0; } static unsigned int round_error() throw() { return 0; } static const int min_exponent = 0; static const int min_exponent10 = 0; static const int max_exponent = 0; static const int max_exponent10 = 0; static const bool has_infinity = false; static const bool has_quiet_NaN = false; static const bool has_signaling_NaN = false; static const float_denorm_style has_denorm = denorm_absent; static const bool has_denorm_loss = false; static unsigned int infinity() throw() { return static_cast(0); } static unsigned int quiet_NaN() throw() { return static_cast(0); } static unsigned int signaling_NaN() throw() { return static_cast(0); } static unsigned int denorm_min() throw() { return static_cast(0); } static const bool is_iec559 = false; static const bool is_bounded = true; static const bool is_modulo = true; static const bool traps = __glibcxx_integral_traps; static const bool tinyness_before = false; static const float_round_style round_style = round_toward_zero; }; /// numeric_limits specialization. template<> struct numeric_limits { static const bool is_specialized = true; static long min() throw() { return -__LONG_MAX__ - 1; } static long max() throw() { return __LONG_MAX__; } static const int digits = __glibcxx_digits (long); static const int digits10 = __glibcxx_digits10 (long); static const bool is_signed = true; static const bool is_integer = true; static const bool is_exact = true; static const int radix = 2; static long epsilon() throw() { return 0; } static long round_error() throw() { return 0; } static const int min_exponent = 0; static const int min_exponent10 = 0; static const int max_exponent = 0; static const int max_exponent10 = 0; static const bool has_infinity = false; static const bool has_quiet_NaN = false; static const bool has_signaling_NaN = false; static const float_denorm_style has_denorm = denorm_absent; static const bool has_denorm_loss = false; static long infinity() throw() { return static_cast(0); } static long quiet_NaN() throw() { return static_cast(0); } static long signaling_NaN() throw() { return static_cast(0); } static long denorm_min() throw() { return static_cast(0); } static const bool is_iec559 = false; static const bool is_bounded = true; static const bool is_modulo = true; static const bool traps = __glibcxx_integral_traps; static const bool tinyness_before = false; static const float_round_style round_style = round_toward_zero; }; /// numeric_limits specialization. template<> struct numeric_limits { static const bool is_specialized = true; static unsigned long min() throw() { return 0; } static unsigned long max() throw() { return __LONG_MAX__ * 2UL + 1; } static const int digits = __glibcxx_digits (unsigned long); static const int digits10 = __glibcxx_digits10 (unsigned long); static const bool is_signed = false; static const bool is_integer = true; static const bool is_exact = true; static const int radix = 2; static unsigned long epsilon() throw() { return 0; } static unsigned long round_error() throw() { return 0; } static const int min_exponent = 0; static const int min_exponent10 = 0; static const int max_exponent = 0; static const int max_exponent10 = 0; static const bool has_infinity = false; static const bool has_quiet_NaN = false; static const bool has_signaling_NaN = false; static const float_denorm_style has_denorm = denorm_absent; static const bool has_denorm_loss = false; static unsigned long infinity() throw() { return static_cast(0); } static unsigned long quiet_NaN() throw() { return static_cast(0); } static unsigned long signaling_NaN() throw() { return static_cast(0); } static unsigned long denorm_min() throw() { return static_cast(0); } static const bool is_iec559 = false; static const bool is_bounded = true; static const bool is_modulo = true; static