# define _GLIBCXX_BEGIN_NAMESPACE_TR1 namespace tr1 { # define _GLIBCXX_END_NAMESPACE_TR1 } # define _GLIBCXX_TR1 tr1:: # include # undef _GLIBCXX_TR1 # undef _GLIBCXX_END_NAMESPACE_TR1 # undef _GLIBCXX_BEGIN_NAMESPACE_TR1 # undef _GLIBCXX_INCLUDE_AS_TR1 #endif #endif // _GLIBCXX_TR1_FUNCTIONAL // Special functions -*- C++ -*- // Copyright (C) 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 tr1/modified_bessel_func.tcc * This is an internal header file, included by other library headers. * You should not attempt to use it directly. */ // // ISO C++ 14882 TR1: 5.2 Special functions // // Written by Edward Smith-Rowland. // // References: // (1) Handbook of Mathematical Functions, // Ed. Milton Abramowitz and Irene A. Stegun, // Dover Publications, // Section 9, pp. 355-434, Section 10 pp. 435-478 // (2) The Gnu Scientific Library, http://www.gnu.org/software/gsl // (3) Numerical Recipes in C, by W. H. Press, S. A. Teukolsky, // W. T. Vetterling, B. P. Flannery, Cambridge University Press (1992), // 2nd ed, pp. 246-249. #ifndef _GLIBCXX_TR1_MODIFIED_BESSEL_FUNC_TCC #define _GLIBCXX_TR1_MODIFIED_BESSEL_FUNC_TCC 1 #include "special_function_util.h" namespace std { namespace tr1 { // [5.2] Special functions // Implementation-space details. namespace __detail { /** * @brief Compute the modified Bessel functions @f$ I_\nu(x) @f$ and * @f$ K_\nu(x) @f$ and their first derivatives * @f$ I'_\nu(x) @f$ and @f$ K'_\nu(x) @f$ respectively. * These four functions are computed together for numerical * stability. * * @param __nu The order of the Bessel functions. * @param __x The argument of the Bessel functions. * @param __Inu The output regular modified Bessel function. * @param __Knu The output irregular modified Bessel function. * @param __Ipnu The output derivative of the regular * modified Bessel function. * @param __Kpnu The output derivative of the irregular * modified Bessel function. */ template void __bessel_ik(const _Tp __nu, const _Tp __x, _Tp & __Inu, _Tp & __Knu, _Tp & __Ipnu, _Tp & __Kpnu) { if (__x == _Tp(0)) { if (__nu == _Tp(0)) { __Inu = _Tp(1); __Ipnu = _Tp(0); } else if (__nu == _Tp(1)) { __Inu = _Tp(0); __Ipnu = _Tp(0.5L); } else { __Inu = _Tp(0); __Ipnu = _Tp(0); } __Knu = std::numeric_limits<_Tp>::infinity(); __Kpnu = -std::numeric_limits<_Tp>::infinity(); return; } const _Tp __eps = std::numeric_limits<_Tp>::epsilon(); const _Tp __fp_min = _Tp(10) * std::numeric_limits<_Tp>::epsilon(); const int __max_iter = 15000; const _Tp __x_min = _Tp(2); const int __nl = static_cast(__nu + _Tp(0.5L)); const _Tp __mu = __nu - __nl; const _Tp __mu2 = __mu * __mu; const _Tp __xi = _Tp(1) / __x; const _Tp __xi2 = _Tp(2) * __xi; _Tp __h = __nu * __xi; if ( __h < __fp_min ) __h = __fp_min; _Tp __b = __xi2 * __nu; _Tp __d = _Tp(0); _Tp __c = __h; int __i; for ( __i = 1; __i <= __max_iter; ++__i ) { __b += __xi2; __d = _Tp(1) / (__b + __d); __c = __b + _Tp(1) / __c; const _Tp __del = __c * __d; __h *= __del; if (std::abs(__del - _Tp(1)) < __eps) break; } if (__i > __max_iter) std::__throw_runtime_error(__N("Argument x too large " "in __bessel_jn; " "try asymptotic expansion.")); _Tp __Inul = __fp_min; _Tp __Ipnul = __h * __Inul; _Tp __Inul1 = __Inul; _Tp __Ipnu1 = __Ipnul; _Tp __fact = __nu * __xi; for (int __l = __nl; __l >= 1; --__l) { const _Tp __Inutemp = __fact * __Inul + __Ipnul; __fact -= __xi; __Ipnul = __fact * __Inutemp + __Inul; __Inul = __Inutemp; } _Tp __f = __Ipnul / __Inul; _Tp __Kmu, __Knu1; if (__x < __x_min) { const _Tp __x2 = __x / _Tp(2); const _Tp __pimu = __numeric_constants<_Tp>::__pi() * __mu; const _Tp __fact = (std::abs(__pimu) < __eps ? _Tp(1) : __pimu / std::sin(__pimu)); _Tp __d = -std::log(__x2); _Tp __e = __mu * __d; const _Tp __fact2 = (std::abs(__e) < __eps ? _Tp(1) : std::sinh(__e) / __e); _Tp __gam1, __gam2, __gampl, __gammi; __gamma_temme(__mu, __gam1, __gam2, __gampl, __gammi); _Tp __ff = __fact * (__gam1 * std::cosh(__e) + __gam2 * __fact2 * __d); _Tp __sum = __ff; __e = std::exp(__e); _Tp __p = __e / (_Tp(2) * __gampl); _Tp __q = _Tp(1) / (_Tp(2) * __e * __gammi); _Tp __c = _Tp(1); __d = __x2 * __x2; _Tp __sum1 = __p; int __i; for (__i = 1; __i <= __max_iter; ++__i) { __ff = (__i * __ff + __p + __q) / (__i * __i - __mu2); __c *= __d / __i; __p /= __i - __mu; __q /= __i + __mu; const _Tp __del = __c * __ff; __sum += __del; const _Tp __del1 = __c * (__p - __i * __ff); __sum1 += __del1; if (std::abs(__del) < __eps * std::abs(__sum)) break; } if (__i > __max_iter) std::__throw_runtime_error(__N("Bessel k series failed to converge " "in __bessel_jn.")); __Kmu = __sum; __Knu1 = __sum1 * __xi2; } else { _Tp __b = _Tp(2) * (_Tp(1) + __x); _Tp __d = _Tp(1) / __b; _Tp __delh = __d; _Tp __h = __delh; _Tp __q1 = _Tp(0); _Tp __q2 = _Tp(1); _Tp __a1 = _Tp(0.25L) - __mu2; _Tp __q = __c = __a1; _Tp __a = -__a1; _Tp __s = _Tp(1) + __q * __delh; int __i; for (__i = 2; __i <= __max_iter; ++__i) { __a -= 2 * (__i - 1); __c = -__a * __c / __i; const _Tp __qnew = (__q1 - __b * __q2) / __a; __q1 = __q2; __q2 = __qnew; __q += __c * __qnew; __b += _Tp(2); __d = _Tp(1) / (__b + __a * __d); __delh = (__b * __d - _Tp(1)) * __delh; __h += __delh; const _Tp __dels = __q * __delh; __s += __dels; if ( std::abs(__dels / __s) < __eps ) break; } if (__i > __max_iter) std::__throw_runtime_error(__N("Steed's method failed " "in __bessel_jn.")); __h = __a1 * __h; __Kmu = std::sqrt(__numeric_constants<_Tp>::__pi() / (_Tp(2) * __x)) * std::exp(-__x) / __s; __Knu1 = __Kmu * (__mu + __x + _Tp(0.5L) - __h) * __xi; } _Tp __Kpmu = __mu * __xi * __Kmu - __Knu1; _Tp __Inumu = __xi / (__f * __Kmu - __Kpmu); __Inu = __Inumu * __Inul1 / __Inul; __Ipnu = __Inumu * __Ipnu1 / __Inul; for ( __i = 1; __i <= __nl; ++__i ) { const _Tp __Knutemp = (__mu + __i) * __xi2 * __Knu1 + __Kmu; __Kmu = __Knu1; __Knu1 = __Knutemp; } __Knu = __Kmu; __Kpnu = __nu * __xi * __Kmu - __Knu1; return; } /** * @brief Return the regular modified Bessel function of order * \f$ \nu \f$: \f$ I_{\nu}(x) \f$. * * The regular modified cylindrical Bessel function is: * @f[ * I_{\nu}(x) = \sum_{k=0}^{\infty} * \frac{(x/2)^{\nu + 2k}}{k!\Gamma(\nu+k+1)} * @f] * * @param __nu The order of the regular modified Bessel function. * @param __x The argument of the regular modified Bessel function. * @return The output regular modified Bessel function. */ template _Tp __cyl_bessel_i(const _Tp __nu, const _Tp __x) { if (__nu < _Tp(0) || __x < _Tp(0)) std::__throw_domain_error(__N("Bad argument " "in __cyl_bessel_i.")); else if (__isnan(__nu) || __isnan(__x)) return std::numeric_limits<_Tp>::quiet_NaN(); else if (__x * __x < _Tp(10) * (__nu + _Tp(1))) return __cyl_bessel_ij_series(__nu, __x, +_Tp(1), 200); else { _Tp __I_nu, __K_nu, __Ip_nu, __Kp_nu; __bessel_ik(__nu, __x, __I_nu, __K_nu, __Ip_nu, __Kp_nu); return __I_nu; } } /** * @brief Return the irregular modified Bessel function * \f$ K_{\nu}(x) \f$ of order \f$ \nu \f$. * * The irregular modified Bessel function is defined by: * @f[ * K_{\nu}(x) = \frac{\pi}{2} * \frac{I_{-\nu}(x) - I_{\nu}(x)}{\sin \nu\pi} * @f] * where for integral \f$ \nu = n \f$ a limit is taken: * \f$ lim_{\nu \to n} \f$. * * @param __nu The order of the irregular modified Bessel function. * @param __x The argument of the irregular modified Bessel function. * @return The output irregular modified Bessel function. */ template _Tp __cyl_bessel_k(const _Tp __nu, const _Tp __x) { if (__nu < _Tp(0) || __x < _Tp(0)) std::__throw_domain_error(__N("Bad argument " "in __cyl_bessel_k.")); else if (__isnan(__nu) || __isnan(__x)) return std::numeric_limits<_Tp>::quiet_NaN(); else { _Tp __I_nu, __K_nu, __Ip_nu, __Kp_nu; __bessel_ik(__nu, __x, __I_nu, __K_nu, __Ip_nu, __Kp_nu); return __K_nu; } } /** * @brief Compute the spherical modified Bessel functions * @f$ i_n(x) @f$ and @f$ k_n(x) @f$ and their first * derivatives @f$ i'_n(x) @f$ and @f$ k'_n(x) @f$ * respectively. * * @param __n The order of the modified spherical Bessel function. * @param __x The argument of the modified spherical Bessel function. * @param __i_n The output regular modified spherical Bessel function. * @param __k_n The output irregular modified spherical * Bessel function. * @param __ip_n The output derivative of the regular modified * spherical Bessel function. * @param __kp_n The output derivative of the irregular modified * spherical Bessel function. */ template void __sph_bessel_ik(const unsigned int __n, const _Tp __x, Î-Ï-Ð-Ñ- _Tp & __i_n, _Tp & __k_n, _Tp & __ip_n, _Tp & __kp_n) { const _Tp __nu = _Tp(__n) + _Tp(0.5L); _Tp __I_nu, __Ip_nu, __K_nu, __Kp_nu; __bessel_ik(__nu, __x, __I_nu, __K_nu, __Ip_nu, __Kp_nu); const _Tp __factor = __numeric_constants<_Tp>::__sqrtpio2() / std::sqrt(__x); __i_n = __factor * __I_nu; __k_n = __factor * __K_nu; __ip_n = __factor * __Ip_nu - __i_n / (_Tp(2) * __x); __kp_n = __factor * __Kp_nu - __k_n / (_Tp(2) * __x); return; } /** * @brief Compute the Airy functions * @f$ Ai(x) @f$ and @f$ Bi(x) @f$ and their first * derivatives @f$ Ai'(x) @f$ and @f$ Bi(x) @f$ * respectively. * * @param __n The order of the Airy functions. * @param __x The argument of the Airy functions. * @param __i_n The output Airy function. * @param __k_n The output Airy function. * @param __ip_n The output derivative of the Airy function. * @param __kp_n The output derivative of the Airy function. */ template void __airy(const _Tp __x, _Tp & __Ai, _Tp & __Bi, _Tp & __Aip, _Tp & __Bip) { const _Tp __absx = std::abs(__x); const _Tp __rootx = std::sqrt(__absx); const _Tp __z = _Tp(2) * __absx * __rootx / _Tp(3); if (__isnan(__x)) return std::numeric_limits<_Tp>::quiet_NaN(); else if (__x > _Tp(0)) { _Tp __I_nu, __Ip_nu, __K_nu, __Kp_nu; __bessel_ik(_Tp(1) / _Tp(3), __z, __I_nu, __K_nu, __Ip_nu, __Kp_nu); __Ai = __rootx * __K_nu / (__numeric_constants<_Tp>::__sqrt3() * __numeric_constants<_Tp>::__pi()); __Bi = __rootx * (__K_nu / __numeric_constants<_Tp>::__pi() + _Tp(2) * __I_nu / __numeric_constants<_Tp>::__sqrt3()); __bessel_ik(_Tp(2) / _Tp(3), __z, __I_nu, __K_nu, __Ip_nu, __Kp_nu); __Aip = -__x * __K_nu / (__numeric_constants<_Tp>::__sqrt3() * __numeric_constants<_Tp>::__pi()); __Bip = __x * (__K_nu / __numeric_constants<_Tp>::__pi() + _Tp(2) * __I_nu / __numeric_constants<_Tp>::__sqrt3()); } else if (__x < _Tp(0)) { _Tp __J_nu, __Jp_nu, __N_nu, __Np_nu; __bessel_jn(_Tp(1) / _Tp(3), __z, __J_nu, __N_nu, __Jp_nu, __Np_nu); __Ai = __rootx * (__J_nu - __N_nu / __numeric_constants<_Tp>::__sqrt3()) / _Tp(2); __Bi = -__rootx * (__N_nu + __J_nu / __numeric_constants<_Tp>::__sqrt3()) / _Tp(2); __bessel_jn(_Tp(2) / _Tp(3), __z, __J_nu, __N_nu, __Jp_nu, __Np_nu); __Aip = __absx * (__N_nu / __numeric_constants<_Tp>::__sqrt3() + __J_nu) / _Tp(2); __Bip = __absx * (__J_nu / __numeric_constants<_Tp>::__sqrt3() - __N_nu) / _Tp(2); } else { // Reference: // Abramowitz & Stegun, page 446 section 10.4.4 on Airy functions. // The number is Ai(0) = 3^{-2/3}/\Gamma(2/3). __Ai = _Tp(0.35502805388781723926L); __Bi = __Ai * __numeric_constants<_Tp>::__sqrt3(); // Reference: // Abramowitz & Stegun, page 446 section 10.4.5 on Airy functions. // The number is Ai'(0) = -3^{-1/3}/\Gamma(1/3). __Aip = -_Tp(0.25881940379280679840L); __Bip = -__Aip * __numeric_constants<_Tp>::__sqrt3(); } return; } } // namespace std::tr1::__detail } } #endif // _GLIBCXX_TR1_MODIFIED_BESSEL_FUNC_TCC // Special functions -*- C++ -*- // Copyright (C) 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 tr1/bessel_function.tcc * This is an internal header file, included by other library headers. * You should not attempt to use it directly. */ // // ISO C++ 14882 TR1: 5.2 Special functions // // Written by Edward Smith-Rowland. // // References: // (1) Handbook of Mathematical Functions, // ed. Milton Abramowitz and Irene A. Stegun, // Dover Publications, // Section 9, pp. 355-434, Section 10 pp. 435-478 // (2) The Gnu Scientific Library, http://www.gnu.org/software/gsl // (3) Numerical Recipes in C, by W. H. Press, S. A. Teukolsky, // W. T. Vetterling, B. P. Flannery, Cambridge University Press (1992), // 2nd ed, pp. 240-245 #ifndef _GLIBCXX_TR1_BESSEL_FUNCTION_TCC #define _GLIBCXX_TR1_BESSEL_FUNCTION_TCC 1 #include "special_function_util.h" namespace std { namespace tr1 { // [5.2] Special functions // Implementation-space details. namespace __detail { /** * @brief Compute the gamma functions required by the Temme series * expansions of @f$ N_\nu(x) @f$ and @f$ K_\nu(x) @f$. * @f[ * \Gamma_1 = \frac{1}{2\mu} * [\frac{1}{\Gamma(1 - \mu)} - \frac{1}{\Gamma(1 + \mu)}] * @f] * and * @f[ * \Gamma_2 = \frac{1}{2} * [\frac{1}{\Gamma(1 - \mu)} + \frac{1}{\Gamma(1 + \mu)}] * @f] * where @f$ -1/2 <= \mu <= 1/2 @f$ is @f$ \mu = \nu - N @f$ and @f$ N @f$. * is the nearest integer to @f$ \nu @f$. * The values of \f$ \Gamma(1 + \mu) \f$ and \f$ \Gamma(1 - \mu) \f$ * are returned as well. * * The accuracy requirements on this are exquisite. * * @param __mu The input parameter of the gamma functions. * @param __gam1 The output function \f$ \Gamma_1(\mu) \f$ * @param __gam2 The output function \f$ \Gamma_2(\mu) \f$ * @param __gampl The output function \f$ \Gamma(1 + \mu) \f$ * @param __gammi The output function \f$ \Gamma(1 - \mu) \f$ */ template void __gamma_temme(const _Tp __mu, _Tp & __gam1, _Tp & __gam2, _Tp & __gampl, _Tp & __gammi) { #if _GLIBCXX_USE_C99_MATH_TR1 __gampl = _Tp(1) / std::tr1::tgamma(_Tp(1) + __mu); __gammi = _Tp(1) / std::tr1::tgamma(_Tp(1) - __mu); #else __gampl = _Tp(1) / __gamma(_Tp(1) + __mu); __gammi = _Tp(1) / __gamma(_Tp(1) - __mu); #endif if (std::abs(__mu) < std::numeric_limits<_Tp>::epsilon()) __gam1 = -_Tp(__numeric_constants<_Tp>::__gamma_e()); else __gam1 = (__gammi - __gampl) / (_Tp(2) * __mu); __gam2 = (__gammi + __gampl) / (_Tp(2)); return; } /** * @brief Compute the Bessel @f$ J_\nu(x) @f$ and Neumann * @f$ N_\nu(x) @f$ functions and their first derivatives * @f$ J'_\nu(x) @f$ and @f$ N'_\nu(x) @f$ respectively. * These four functions are computed together for numerical * stability. * * @param __nu The order of the Bessel functions. * @param __x The argument of the Bessel functions. * @param __Jnu The output Bessel function of the first kind. * @param __Nnu The output Neumann function (Bessel function of the second kind). * @param __Jpnu The output derivative of the Bessel function of the first kind. * @param __Npnu The output derivative of the Neumann function. */ template void __bessel_jn(const _Tp __nu, const _Tp __x, _Tp & __Jnu, _Tp & __Nnu, _Tp & __Jpnu, _Tp & __Npnu) { if (__x == _Tp(0)) { if (__nu == _Tp(0)) { __Jnu = _Tp(1); __Jpnu = _Tp(0); } else if (__nu == _Tp(1)) { __Jnu = _Tp(0); __Jpnu = _Tp(0.5L); } else { __Jnu = _Tp(0); __Jpnu = _Tp(0); } __Nnu = -std::numeric_limits<_Tp>::infinity(); __Npnu = std::numeric_limits<_Tp>::infinity(); return; } const _Tp __eps = std::numeric_limits<_Tp>::epsilon(); // When the multiplier is N i.e. // fp_min = N * min() // Then J_0 and N_0 tank at x = 8 * N (J_0 = 0 and N_0 = nan)! //const _Tp __fp_min = _Tp(20) * std::numeric_limits<_Tp>::min(); const _Tp __fp_min = std::sqrt(std::numeric_limits<_Tp>::min()); const int __max_iter = 15000; const _Tp __x_min = _Tp(2); const int __nl = (__x < __x_min ? static_cast(__nu + _Tp(0.5L)) : std::max(0, static_cast(__nu - __x + _Tp(1.5L)))); const _Tp __mu = __nu - __nl; const _Tp __mu2 = __mu * __mu; const _Tp __xi = _Tp(1) / __x; const _Tp __xi2 = _Tp(2) * __xi; _Tp __w = __xi2 / __numeric_constants<_Tp>::__pi(); int __isign = 1; _Tp __h = __nu * __xi; if (__h < __fp_min) __h = __fp_min; _Tp __b = __xi2 * __nu; _Tp __d = _Tp(0); _Tp __c = __h; int __i; for (__i = 1; __i <= __max_iter; ++__i) { __b += __xi2; __d = __b - __d; if (std::abs(__d) < __fp_min) __d = __fp_min; __c = __b - _Tp(1) / __c; if (std::abs(__c) < __fp_min) __c = __fp_min; __d = _Tp(1) / __d; const _Tp __del = __c * __d; __h *= __del; if (__d < _Tp(0)) __isign = -__isign; if (std::abs(__del - _Tp(1)) < __eps) break; } if (__i > __max_iter) std::__throw_runtime_error(__N("Argument x too large in __bessel_jn; " "try asymptotic expansion.")); _Tp __Jnul = __isign * __fp_min; _Tp __Jpnul = __h * __Jnul; _Tp __Jnul1 = __Jnul; _Tp __Jpnu1 = __Jpnul; _Tp __fact = __nu * __xi; for ( int __l = __nl; __l >= 1; --__l ) { const _Tp __Jnutemp = __fact * __Jnul + __Jpnul; __fact -= __xi; __Jpnul = __fact * __Jnutemp - __Jnul; __Jnul = __Jnutemp; } if (__Jnul == _Tp(0)) __Jnul = __eps; _Tp __f= __Jpnul / __Jnul; _Tp __Nmu, __Nnu1, __Npmu, __Jmu; if (__x < __x_min) { const _Tp __x2 = __x / _Tp(2); const _Tp __pimu = __numeric_constants<_Tp>::__pi() * __mu; _Tp __fact = (std::abs(__pimu) < __eps ? _Tp(1) : __pimu / std::sin(__pimu)); _Tp __d = -std::log(__x2); _Tp __e = __mu * __d; _Tp __fact2 = (std::abs(__e) < __eps ? _Tp(1) : std::sinh(__e) / __e); _Tp __gam1, __gam2, __gampl, __gammi; __gamma_temme(__mu, __gam1, __gam2, __gampl, __gammi); _Tp __ff = (_Tp(2) / __numeric_constants<_Tp>::__pi()) * __fact * (__gam1 * std::cosh(__e) + __gam2 * __fact2 * __d); __e = std::exp(__e); _Tp __p = __e / (__numeric_constants<_Tp>::__pi() * __gampl); _Tp __q = _Tp(1) / (__e * __numeric_constants<_Tp>::__pi() * __gammi); const _Tp __pimu2 = __pimu / _Tp(2); _Tp __fact3 = (std::abs(__pimu2) < __eps ? _Tp(1) : std::sin(__pimu2) / __pimu2 ); _Tp __r = __numeric_constants<_Tp>::__pi() * __pimu2 * __fact3 * __fact3; _Tp __c = _Tp(1); __d = -__x2 * __x2; _Tp __sum = __ff + __r * __q; _Tp __sum1 = __p; for (__i = 1; __i <= __max_iter; ++__i) { __ff = (__i * __ff + __p + __q) / (__i * __i - __mu2); __c *= __d / _Tp(__i); __p /= _Tp(__i) - __mu; __q /= _Tp(__i) + __mu; const _Tp __del = __c * (__ff + __r * __q); __sum += __del; const _Tp __del1 = __c * __p - __i * __del; __sum1 += __del1; if ( std::abs(__del) < __eps * (_Tp(1) + std::abs(__sum)) ) break; } if ( __i > __max_iter ) std::__throw_runtime_error(__N("Bessel y series failed to converge " "in __bessel_jn.")); __Nmu = -__sum; __Nnu1 = -__sum1 * __xi2; __Npmu = __mu * __xi * __Nmu - __Nnu1; __Jmu = __w / (__Npmu - __f * __Nmu); } else { _Tp __a = _Tp(0.25L) - __mu2; _Tp __q = _Tp(1); _Tp __p = -__xi / _Tp(2); _Tp __br = _Tp(2) * __x; _Tp __bi = _Tp(2); _Tp __fact = __a * __xi / (__p * __p + __q * __q); _Tp __cr = __br + __q * __fact; _Tp __ci = __bi + __p * __fact; _Tp __den = __br * __br + __bi * __bi; _Tp __dr = __br / __den; _Tp __di = -__bi / __den; _Tp __dlr = __cr * __dr - __ci * __di; _Tp __dli = __cr * __di + __ci * __dr; _Tp __temp = __p * __dlr - __q * __dli; __q = __p * __dli + __q * __dlr; __p = __temp; int __i; for (__i = 2; __i <= __max_iter; ++__i) { __a += _Tp(2 * (__i - 1)); __bi += _Tp(2); __dr = __a * __dr + __br; __di = __a * __di + __bi; if (std::abs(__dr) + std::abs(__di) < __fp_min) __dr = __fp_min; __fact = __a / (__cr * __cr + __ci * __ci); __cr = __br + __cr * __fact; __ci = __bi - __ci * __fact; if (std::abs(__cr) + std::abs(__ci) < __fp_min) __cr = __fp_min; __den = __dr * __dr + __di * __di; __dr /= __den; __di /= -__den; __dlr = __cr * __dr - __ci * __di; __dli = __cr * __di + __ci * __dr; __temp = __p * __dlr - __q * __dli; __q = __p * __dli + __q * __dlr; __p = __temp; if (std::abs(__dlr - _Tp(1)) + std::abs(__dli) < __eps) break; } if (__i > __max_iter) std::__throw_runtime_error(__N("Lentz's method failed " "in __bessel_jn.")); const _Tp __gam = (__p - __f) / __q; __Jmu = std::sqrt(__w / ((__p - __f) * __gam + __q)); #if _GLIBCXX_USE_C99_MATH_TR1 __Jmu = std::tr1::copysign(__Jmu, __Jnul); #else if (__Jmu * __Jnul < _Tp(0)) __Jmu = -__Jmu; #endif __Nmu = __gam * __Jmu; __Npmu = (__p + __q / __gam) * __Nmu; __Nnu1 = __mu * __xi * __Nmu - __Npmu; } __fact = __Jmu / __Jnul; __Jnu = __fact * __Jnul1; __Jpnu = __fact * __Jpnu1; for (__i ß-à-á-â-ã-ä-å-æ-ç-è-= 1; __i <= __nl; ++__i) { const _Tp __Nnutemp = (__mu + __i) * __xi2 * __Nnu1 - __Nmu; __Nmu = __Nnu1; __Nnu1 = __Nnutemp; } __Nnu = __Nmu; __Npnu = __nu * __xi * __Nmu - __Nnu1; return; } /** * @brief This routine computes the asymptotic cylindrical Bessel * and Neumann functions of order nu: \f$ J_{\nu} \f$, * \f$ N_{\nu} \f$. * * References: * (1) Handbook of Mathematical Functions, * ed. Milton Abramowitz and Irene A. Stegun, * Dover Publications, * Section 9 p. 364, Equations 9.2.5-9.2.10 * * @param __nu The order of the Bessel functions. * @param __x The argument of the Bessel functions. * @param __Jnu The output Bessel function of the first kind. * @param __Nnu The output Neumann function (Bessel function of the second kind). */ template void __cyl_bessel_jn_asymp(const _Tp __nu, const _Tp __x, _Tp & __Jnu, _Tp & __Nnu) { const _Tp __coef = std::sqrt(_Tp(2) / (__numeric_constants<_Tp>::__pi() * __x)); const _Tp __mu = _Tp(4) * __nu * __nu; const _Tp __mum1 = __mu - _Tp(1); const _Tp __mum9 = __mu - _Tp(9); const _Tp __mum25 = __mu - _Tp(25); const _Tp __mum49 = __mu - _Tp(49); const _Tp __xx = _Tp(64) * __x * __x; const _Tp __P = _Tp(1) - __mum1 * __mum9 / (_Tp(2) * __xx) * (_Tp(1) - __mum25 * __mum49 / (_Tp(12) * __xx)); const _Tp __Q = __mum1 / (_Tp(8) * __x) * (_Tp(1) - __mum9 * __mum25 / (_Tp(6) * __xx)); const _Tp __chi = __x - (__nu + _Tp(0.5L)) * __numeric_constants<_Tp>::__pi_2(); const _Tp __c = std::cos(__chi); const _Tp __s = std::sin(__chi); __Jnu = __coef * (__c * __P - __s * __Q); __Nnu = __coef * (__s * __P + __c * __Q); return; } /** * @brief This routine returns the cylindrical Bessel functions * of order \f$ \nu \f$: \f$ J_{\nu} \f$ or \f$ I_{\nu} \f$ * by series expansion. * * The modified cylindrical Bessel function is: * @f[ * Z_{\nu}(x) = \sum_{k=0}^{\infty} * \frac{\sigma^k (x/2)^{\nu + 2k}}{k!\Gamma(\nu+k+1)} * @f] * where \f$ \sigma = +1 \f$ or\f$ -1 \f$ for * \f$ Z = I \f$ or \f$ J \f$ respectively. * * See Abramowitz & Stegun, 9.1.10 * Abramowitz & Stegun, 9.6.7 * (1) Handbook of Mathematical Functions, * ed. Milton Abramowitz and Irene A. Stegun, * Dover Publications, * Equation 9.1.10 p. 360 and Equation 9.6.10 p. 375 * * @param __nu The order of the Bessel function. * @param __x The argument of the Bessel function. * @param __sgn The sign of the alternate terms * -1 for the Bessel function of the first kind. * +1 for the modified Bessel function of the first kind. * @return The output Bessel function. */ template _Tp __cyl_bessel_ij_series(const _Tp __nu, const _Tp __x, const _Tp __sgn, const unsigned int __max_iter) { const _Tp __x2 = __x / _Tp(2); _Tp __fact = __nu * std::log(__x2); #if _GLIBCXX_USE_C99_MATH_TR1 __fact -= std::tr1::lgamma(__nu + _Tp(1)); #else __fact -= __log_gamma(__nu + _Tp(1)); #endif __fact = std::exp(__fact); const _Tp __xx4 = __sgn * __x2 * __x2; _Tp __Jn = _Tp(1); _Tp __term = _Tp(1); for (unsigned int __i = 1; __i < __max_iter; ++__i) { __term *= __xx4 / (_Tp(__i) * (__nu + _Tp(__i))); __Jn += __term; if (std::abs(__term / __Jn) < std::numeric_limits<_Tp>::epsilon()) break; } return __fact * __Jn; } /** * @brief Return the Bessel function of order \f$ \nu \f$: * \f$ J_{\nu}(x) \f$. * * The cylindrical Bessel function is: * @f[ * J_{\nu}(x) = \sum_{k=0}^{\infty} * \frac{(-1)^k (x/2)^{\nu + 2k}}{k!\Gamma(\nu+k+1)} * @f] * * @param __nu The order of the Bessel function. * @param __x The argument of the Bessel function. * @return The output Bessel function. */ template _Tp __cyl_bessel_j(const _Tp __nu, const _Tp __x) { if (__nu < _Tp(0) || __x < _Tp(0)) std::__throw_domain_error(__N("Bad argument " "in __cyl_bessel_j.")); else if (__isnan(__nu) || __isnan(__x)) return std::numeric_limits<_Tp>::quiet_NaN(); else if (__x * __x < _Tp(10) * (__nu + _Tp(1))) return __cyl_bessel_ij_series(__nu, __x, -_Tp(1), 200); else if (__x > _Tp(1000)) { _Tp __J_nu, __N_nu; __cyl_bessel_jn_asymp(__nu, __x, __J_nu, __N_nu); return __J_nu; } else { _Tp __J_nu, __N_nu, __Jp_nu, __Np_nu; __bessel_jn(__nu, __x, __J_nu, __N_nu, __Jp_nu, __Np_nu); return __J_nu; } } /** * @brief Return the Neumann function of order \f$ \nu \f$: * \f$ N_{\nu}(x) \f$. * * The Neumann function is defined by: * @f[ * N_{\nu}(x) = \frac{J_{\nu}(x) \cos \nu\pi - J_{-\nu}(x)} * {\sin \nu\pi} * @f] * where for integral \f$ \nu = n \f$ a limit is taken: * \f$ lim_{\nu \to n} \f$. * * @param __nu The order of the Neumann function. * @param __x The argument of the Neumann function. * @return The output Neumann function. */ template _Tp __cyl_neumann_n(const _Tp __nu, const _Tp __x) { if (__nu < _Tp(0) || __x < _Tp(0)) std::__throw_domain_error(__N("Bad argument " "in __cyl_neumann_n.")); else if (__isnan(__nu) || __isnan(__x)) return std::numeric_limits<_Tp>::quiet_NaN(); else if (__x > _Tp(1000)) { _Tp __J_nu, __N_nu; __cyl_bessel_jn_asymp(__nu, __x, __J_nu, __N_nu); return __N_nu; } else { _Tp __J_nu, __N_nu, __Jp_nu, __Np_nu; __bessel_jn(__nu, __x, __J_nu, __N_nu, __Jp_nu, __Np_nu); return __N_nu; } } /** * @brief Compute the spherical Bessel @f$ j_n(x) @f$ * and Neumann @f$ n_n(x) @f$ functions and their first * derivatives @f$ j'_n(x) @f$ and @f$ n'_n(x) @f$ * respectively. * * @param __n The order of the spherical Bessel function. * @param __x The argument of the spherical Bessel function. * @param __j_n The output spherical Bessel function. * @param __n_n The output spherical Neumann function. * @param __jp_n The output derivative of the spherical Bessel function. * @param __np_n The output derivative of the spherical Neumann function. */ template void __sph_bessel_jn(const unsigned int __n, const _Tp __x, _Tp & __j_n, _Tp & __n_n, _Tp & __jp_n, _Tp & __np_n) { const _Tp __nu = _Tp(__n) + _Tp(0.5L); _Tp __J_nu, __N_nu, __Jp_nu, __Np_nu; __bessel_jn(__nu, __x, __J_nu, __N_nu, __Jp_nu, __Np_nu); const _Tp __factor = __numeric_constants<_Tp>::__sqrtpio2() / std::sqrt(__x); __j_n = __factor * __J_nu; __n_n = __factor * __N_nu; __jp_n = __factor * __Jp_nu - __j_n / (_Tp(2) * __x); __np_n = __factor * __Np_nu - __n_n / (_Tp(2) * __x); return; } /** * @brief Return the spherical Bessel function * @f$ j_n(x) @f$ of order n. * * The spherical Bessel function is defined by: * @f[ * j_n(x) = \left( \frac{\pi}{2x} \right) ^{1/2} J_{n+1/2}(x) * @f] * * @param __n The order of the spherical Bessel function. * @param __x The argument of the spherical Bessel function. * @return The output spherical Bessel function. */ template _Tp __sph_bessel(const unsigned int __n, const _Tp __x) { if (__x < _Tp(0)) std::__throw_domain_error(__N("Bad argument " "in __sph_bessel.")); else if (__isnan(__x)) return std::numeric_limits<_Tp>::quiet_NaN(); else if (__x == _Tp(0)) { if (__n == 0) return _Tp(1); else return _Tp(0); } else { _Tp __j_n, __n_n, __jp_n, __np_n; __sph_bessel_jn(__n, __x, __j_n, __n_n, __jp_n, __np_n); return __j_n; } } /** * @brief Return the spherical Neumann function * @f$ n_n(x) @f$. * * The spherical Neumann function is defined by: * @f[ * n_n(x) = \left( \frac{\pi}{2x} \right) ^{1/2} N_{n+1/2}(x) * @f] * * @param __n The order of the spherical Neumann function. * @param __x The argument of the spherical Neumann function. * @return The output spherical Neumann function. */ template _Tp __sph_neumann(const unsigned int __n, const _Tp __x) { if (__x < _Tp(0)) std::__throw_domain_error(__N("Bad argument " "in __sph_neumann.")); else if (__isnan(__x)) return std::numeric_limits<_Tp>::quiet_NaN(); else if (__x == _Tp(0)) return -std::numeric_limits<_Tp>::infinity(); else { _Tp __j_n, __n_n, __jp_n, __np_n; __sph_bessel_jn(__n, __x, __j_n, __n_n, __jp_n, __np_n); return __n_n; } } } // namespace std::tr1::__detail } } #endif // _GLIBCXX_TR1_BESSEL_FUNCTION_TCC // -*- C++ -*- // Copyright (C) 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/tuple * This is a Standard C++ Library header. */ #ifndef _GLIBCXX_CXX0X_TUPLE #define _GLIBCXX_CXX0X_TUPLE 1 #pragma GCC system_header #ifndef __GXX_EXPERIMENTAL_CXX0X__ # include #endif #include namespace std { // Adds a const reference to a non-reference type. template struct __add_c_ref { typedef const _Tp& type; }; template struct __add_c_ref<_Tp&> { typedef _Tp& type; }; // Adds a reference to a non-reference type. template struct __add_ref { typedef _Tp& type; }; template struct __add_ref<_Tp&> { typedef _Tp& type; }; template struct _Head_base; template struct _Head_base<_Idx, _Head, true> : public _Head { _Head_base() : _Head() { } _Head_base(const _Head& __h) : _Head(__h) { } template _Head_base(_UHead&& __h) : _Head(std::forward<_UHead>(__h)) { } _Head& _M_head() { return *this; } const _Head& _M_head() const { return *this; } }; template struct _Head_base<_Idx, _Head, false> { _Head_base() : _M_head_impl() { } _Head_base(const _Head& __h) : _M_head_impl(__h) { } template _Head_base(_UHead&& __h) : _M_head_impl(std::forward<_UHead>(__h)) { } _Head& _M_head() { return _M_head_impl; } const _Head& _M_head() const { return _M_head_impl; } _Head _M_head_impl; }; /** * Contains the actual implementation of the @c tuple template, stored * as a recursive inheritance hierarchy from the first element (most * derived class) to the last (least derived class). The @c Idx * parameter gives the 0-based index of the element stored at this * point in the hierarchy; we use it to implement a constant-time * get() operation. */ template struct _Tuple_impl; /** * Zero-element tuple implementation. This is the basis case for the * inheritance recursion. */ template struct _Tuple_impl<_Idx> { }; /** * Recursive tuple implementation. Here we store the @c Head element * and derive from a @c Tuple_impl containing the remaining elements * (which contains the @c Tail). */ template struct _Tuple_impl<_Idx, _Head, _Tail...> : public _Tuple_impl<_Idx + 1, _Tail...>, private _Head_base<_Idx, _Head, std::is_empty<_Head>::value> { typedef _Tuple_impl<_Idx + 1, _Tail...> _Inherited; typedef _Head_base<_Idx, _Head, std::is_empty<_Head>::value> _Base; _Head& _M_head() { return _Base::_M_head(); } const _Head& _M_head() const { return _Base::_M_head(); } _Inherited& _M_tail() { return *this; } const _Inherited& _M_tail() const { return *this; } _Tuple_impl() : _Inherited(), _Base() { } explicit _Tuple_impl(const _Head& __head, const _Tail&... __tail) : _Inherited(__tail...), _Base(__head) { } template explicit _Tuple_impl(_UHead&& __head, _UTail&&... __tail) : _Inherited(std::forward<_UTail>(__tail)...), _Base(std::forward<_UHead>(__head)) { } _Tuple_impl(const _Tuple_impl& __in) : _Inherited(__in._M_tail()), _Base(__in._M_head()) { } _Tuple_impl(_Tuple_impl&& __in) : _Inherited(std::move<_Inherited&&>(__in._M_tail())), _Base(std::forward<_Head>(__in._M_head())) { } template _Tuple_impl(const _Tuple_impl<_Idx, _UElements...>& __in) : _Inherited(__in._M_tail()), _Base(__in._M_head()) { } template _Tuple_impl(_Tuple_impl<_Idx, _UElements...>&& __in) : _Inherited(std::move:: _Inherited&&>(__in._M_tail())), _Base(std::forward:: _Base>(__in._M_head())) { } _Tuple_impl& operator=(const _Tuple_impl& __in) { _M_head() = __in._M_head(); _M_tail() = __in._M_tail(); return *this; } _Tuple_impl& operator=(_Tuple_impl&& __in) { _M_head() = std::move(__in._M_head()); _M_tail() = std::move(__in._M_tail()); return *this; } template _Tuple_impl& operator=(const _Tuple_impl<_Idx, _UElements...>& __in) { _M_head() = __in._M_head(); _M_tail() = __in._M_tail(); return *this; } template _Tuple_impl& operator=(_Tuple_impl<_Idx, _UElements...>&& __in) { _M_head() = std::move(__in._M_head()); _M_tail() = std::move(__in._M_tail()); return *this; } }; /// tuple template class tuple : public _Tuple_impl<0, _Elements...> { typedef _Tuple_impl<0, _Elements...> _Inherited; public: tuple() : _Inherited() { } explicit tuple(const _Elements&... __elements) : _Inherited(__elements...) { } template explicit tuple(_UElements&&... __elements) : _Inherited(std::forward<_UElements>(__elements)...) { } tuple(const tuple& __in) : _Inherited(static_cast(__in)) { } tuple(tuple&& __in) : _Inherited(std::move<_Inherited>(__in)) { } template tuple(const tuple<_UElements...>& __in) : _Inherited(static_cast&>(__in)) { } template tuple(tuple<_UElements...>&& __in) : _Inherited(std::move<_Tuple_impl<0, _UElements...> >(__in)) { } // XXX http://gcc.gnu.org/ml/libstdc++/2008-02/msg00047.html template tuple(tuple<_UElements...>& __in) : _Inherited(static_cast&>(__in)) { } tuple& operator=(const tuple& __in) { static_cast<_Inherited&>(*this) = __in; return *this; } tuple& operator=(tuple&& __in) { static_cast<_Inherited&>(*this) = std::move(__in); return *this; } template tuple& operator=(const tuple<_UElements...>& __in) { static_cast<_Inherited&>(*this) = __in; return *this; } template tuple& operator=(tuple<_UElements...>&& __in) { static_cast<_Inherited&>(*this) = std::move(__in); return *this; } }; template<> class tuple<> { }; /// tuple (2-element), with construction and assignment from a pair. template class tuple<_T1, _T2> : public _Tuple_impl<0, _T1, _T2> { typedef _Tuple_impl<0, _T1, _T2> _Inherited; public: tuple() : _Inherited() { } explicit tuple(const _T1& __a1, const _T2& __a2) : _Inherited(__a1, __a2) { } template explicit tuple(_U1&& __a1, _U2&& __a2) : _Inherited(std::forward<_U1>(__a1), std::forward<_U2>(__a2)) { } tuple(const tuple& __in) : _Inherited(static_cast(__in)) { } tuple(tuple&& __in) : _Inherited(std::move<_Inherited>(__in)) { } template tuple(const tuple<_U1, _U2>& __in) : _Inherited(static_cast&>(__in)) { } template tuple(tuple<_U1, _U2>&& __in) : _Inherited(std::move<_Tuple_impl<0, _U1, _U2> >(__in)) { } template tuple(const pair<_U1, _U2>& __in) : _Inherited(__in.first, __in.second) { } template tuple(pair<_U1, _U2>&& __in) : _Inherited(std::move(__in.first), std::move(__in.second)) { } tuple& operator=(const tuple& __in) { static_cast<_Inherited&>(*this) = __in; return *this; } tuple& operator=(tuple&& __in) { static_cast<_Inherited&>(*this) = std::move(__in); return *this; } template tuple& operator=(const tuple<_U1, _U2>& __in) { static_cast<_Inherited&>(*this) = __in; return *this; } template tuple& operator=(tuple<_U1, _U2>&& __in) { static_cast<_Inherited&>(*this) = std::move(__in); return *this; } template tuple& operator=(const pair<_U1, _U2>& __in) { this->_M_head() = __in.first; this->_M_tail()._M_head() = __in.second; return *this; } template tuple& operator=(pair<_U1, _U2>&& __in) { this->_M_head() = std::move(__in.first); this->_M_tail()._M_head() = std::move(__in.second); return *this; } }; /// Gives the type of the ith element of a given tuple type. template struct tuple_element; /** * Recursive case for tuple_element: strip off the first element in * the tuple and retrieve the (i-1)th element of the remaining tuple. */ template struct tuple_element<__i, tuple<_Head, _Tail...> > : tuple_element<__i - 1, tuple<_Tail...> > { }; /** * Basis case for tuple_element: The first element is the one we're seeking. */ template struct tuple_element<0, tuple<_Head, _Tail...> > { typedef _Head type; }; /// Finds the size of a given tuple type. template struct tuple_size; /// class tuple_size template struct tuple_size > { static const int value = sizeof...(_Elements); }; template const int tuple_size >::value; template inline typename __add_ref<_Head>::type __get_helper(_Tuple_impl<__i, _Head, _Tail...>& __t) { return __t._M_head(); } template inline typename __add_c_ref<_Head>::type __get_helper(const _Tuple_impl<__i, _Head, _Tail...>& __t) { return __t._M_head(); } // Return a reference (const reference) to the ith element of a tuple. // Any const or non-const ref elements are returned with their original type. template inline typename __add_ref< typename tuple_element<__i, tuple<_Elements.ö-÷-ø-ù-ú-û-ü-ý-..> >::type >::type get(tuple<_Elements...>& __t) { return __get_helper<__i>(__t); } template inline typename __add_c_ref< typename tuple_element<__i, tuple<_Elements...> >::type >::type get(const tuple<_Elements...>& __t) { return __get_helper<__i>(__t); } // This class helps construct the various comparison operations on tuples template struct __tuple_compare; template struct __tuple_compare<0, __i, __j, _Tp, _Up> { static bool __eq(const _Tp& __t, const _Up& __u) { return (get<__i>(__t) == get<__i>(__u) && __tuple_compare<0, __i+1, __j, _Tp, _Up>::__eq(__t, __u)); } static bool __less(const _Tp& __t, const _Up& __u) { return ((get<__i>(__t) < get<__i>(__u)) || !(get<__i>(__u) < get<__i>(__t)) && __tuple_compare<0, __i+1, __j, _Tp, _Up>::__less(__t, __u)); } }; template struct __tuple_compare<0, __i, __i, _Tp, _Up> { static bool __eq(const _Tp&, const _Up&) { return true; } static bool __less(const _Tp&, const _Up&) { return false; } }; template bool operator==(const tuple<_TElements...>& __t, const tuple<_UElements...>& __u) { typedef tuple<_TElements...> _Tp; typedef tuple<_UElements...> _Up; return (__tuple_compare::value - tuple_size<_Up>::value, 0, tuple_size<_Tp>::value, _Tp, _Up>::__eq(__t, __u)); } template bool operator<(const tuple<_TElements...>& __t, const tuple<_UElements...>& __u) { typedef tuple<_TElements...> _Tp; typedef tuple<_UElements...> _Up; return (__tuple_compare::value - tuple_size<_Up>::value, 0, tuple_size<_Tp>::value, _Tp, _Up>::__less(__t, __u)); } template inline bool operator!=(const tuple<_TElements...>& __t, const tuple<_UElements...>& __u) { return !(__t == __u); } template inline bool operator>(const tuple<_TElements...>& __t, const tuple<_UElements...>& __u) { return __u < __t; } template inline bool operator<=(const tuple<_TElements...>& __t, const tuple<_UElements...>& __u) { return !(__u < __t); } template inline bool operator>=(const tuple<_TElements...>& __t, const tuple<_UElements...>& __u) { return !(__t < __u); } // NB: DR 705. template inline tuple::__type...> make_tuple(_Elements&&... __args) { typedef tuple::__type...> __result_type; return __result_type(std::forward<_Elements>(__args)...); } template struct __index_holder { }; template struct __index_holder_impl; template struct __index_holder_impl<__i, __index_holder<_Indexes...>, _IdxHolder, _Elements...> { typedef typename __index_holder_impl<__i + 1, __index_holder<_Indexes..., __i>, _Elements...>::type type; }; template struct __index_holder_impl<__i, __index_holder<_Indexes...> > { typedef __index_holder<_Indexes...> type; }; template struct __make_index_holder : __index_holder_impl<0, __index_holder<>, _Elements...> { }; template inline tuple<_TElements..., _UElements...> __tuple_cat_helper(const tuple<_TElements...>& __t, const __index_holder<_TIdx...>&, const tuple<_UElements...>& __u, const __index_holder<_UIdx...>&) { return tuple<_TElements..., _UElements...>(get<_TIdx>(__t)..., get<_UIdx>(__u)...); } template inline tuple<_TElements..., _UElements...> __tuple_cat_helper(tuple<_TElements...>&& __t, const __index_holder<_TIdx...>&, const tuple<_UElements...>& __u, const __index_holder<_UIdx...>&) { return tuple<_TElements..., _UElements...> (std::move(get<_TIdx>(__t))..., get<_UIdx>(__u)...); } template inline tuple<_TElements..., _UElements...> __tuple_cat_helper(const tuple<_TElements...>& __t, const __index_holder<_TIdx...>&, tuple<_UElements...>&& __u, const __index_holder<_UIdx...>&) { return tuple<_TElements..., _UElements...> (get<_TIdx>(__t)..., std::move(get<_UIdx>(__u))...); } template inline tuple<_TElements..., _UElements...> __tuple_cat_helper(tuple<_TElements...>&& __t, const __index_holder<_TIdx...>&, tuple<_UElements...>&& __u, const __index_holder<_UIdx...>&) { return tuple<_TElements..., _UElements...> (std::move(get<_TIdx>(__t))..., std::move(get<_UIdx>(__u))...); } template inline tuple<_TElements..., _UElements...> tuple_cat(const tuple<_TElements...>& __t, const tuple<_UElements...>& __u) { return __tuple_cat_helper(__t, typename __make_index_holder<_TElements...>::type(), __u, typename __make_index_holder<_UElements...>::type()); } template inline tuple<_TElements..., _UElements...> tuple_cat(tuple<_TElements...>&& __t, const tuple<_UElements...>& __u) { return __tuple_cat_helper(std::move(__t), typename __make_index_holder<_TElements...>::type(), __u, typename __make_index_holder<_UElements...>::type()); } template inline tuple<_TElements..., _UElements...> tuple_cat(const tuple<_TElements...>& __t, tuple<_UElements...>&& __u) { return __tuple_cat_helper(__t, typename __make_index_holder<_TElements...>::type(), std::move(__u), typename __make_index_holder<_UElements...>::type()); } template inline tuple<_TElements..., _UElements...> tuple_cat(tuple<_TElements...>&& __t, tuple<_UElements...>&& __u) { return __tuple_cat_helper(std::move(__t), typename __make_index_holder<_TElements...>::type(), std::move(__u), typename __make_index_holder<_UElements...>::type()); } template inline tuple<_Elements&...> tie(_Elements&... __args) { return tuple<_Elements&...>(__args...); } // A class (and instance) which can be used in 'tie' when an element // of a tuple is not required struct _Swallow_assign { template _Swallow_assign& operator=(const _Tp&) { return *this; } }; // TODO: Put this in some kind of shared file. namespace { _Swallow_assign ignore; }; // anonymous namespace } #endif // _GLIBCXX_CXX0X_TUPLE // Standard iostream objects -*- C++ -*- // Copyright (C) 1997, 1998, 1999, 2001, 2002, 2005, 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 iostream * This is a Standard C++ Library header. */ // // ISO C++ 14882: 27.3 Standard iostream objects // #ifndef _GLIBCXX_IOSTREAM #define _GLIBCXX_IOSTREAM 1 #pragma GCC system_header #include #include #include _GLIBCXX_BEGIN_NAMESPACE(std) /** * @name Standard Stream Objects * * The <iostream> header declares the eight standard stream * objects. For other declarations, see * http://gcc.gnu.org/onlinedocs/libstdc++/manual/bk01pt11ch24.html * and the @link s27_2_iosfwd I/O for