.appveyor.yml .github/workflows/main.yml .gitignore .lgtm.yml .readthedocs.requirements.txt .readthedocs.yml .travis.yml CMakeLists.txt LICENSE NOTICE.txt README.md binder/environment.yml cmake_files/gcemConfig.cmake.in contributors.txt docs/Doxyfile docs/Makefile docs/environment.yml docs/make.bat docs/source/_static/main_stylesheet.css docs/source/api/algorithms.rst docs/source/api/basic_functions.rst docs/source/api/hyperbolic_functions.rst docs/source/api/math_index.rst docs/source/api/special_functions.rst docs/source/api/trigonometric_functions.rst docs/source/conf.py docs/source/examples.rst docs/source/index.rst include/gcem.hpp include/gcem_incl/abs.hpp include/gcem_incl/acos.hpp include/gcem_incl/acosh.hpp include/gcem_incl/asin.hpp include/gcem_incl/asinh.hpp include/gcem_incl/atan.hpp include/gcem_incl/atan2.hpp include/gcem_incl/atanh.hpp include/gcem_incl/beta.hpp include/gcem_incl/binomial_coef.hpp include/gcem_incl/ceil.hpp include/gcem_incl/copysign.hpp include/gcem_incl/cos.hpp include/gcem_incl/cosh.hpp include/gcem_incl/erf.hpp include/gcem_incl/erf_inv.hpp include/gcem_incl/exp.hpp include/gcem_incl/expm1.hpp include/gcem_incl/factorial.hpp include/gcem_incl/find_exponent.hpp include/gcem_incl/find_fraction.hpp include/gcem_incl/find_whole.hpp include/gcem_incl/floor.hpp include/gcem_incl/fmod.hpp include/gcem_incl/gcd.hpp include/gcem_incl/gcem_options.hpp include/gcem_incl/incomplete_beta.hpp include/gcem_incl/incomplete_beta_inv.hpp include/gcem_incl/incomplete_gamma.hpp include/gcem_incl/incomplete_gamma_inv.hpp include/gcem_incl/inv_sqrt.hpp include/gcem_incl/is_even.hpp include/gcem_incl/is_finite.hpp include/gcem_incl/is_inf.hpp include/gcem_incl/is_nan.hpp include/gcem_incl/is_odd.hpp include/gcem_incl/lbeta.hpp include/gcem_incl/lcm.hpp include/gcem_incl/lgamma.hpp include/gcem_incl/lmgamma.hpp include/gcem_incl/log.hpp include/gcem_incl/log10.hpp include/gcem_incl/log1p.hpp include/gcem_incl/log2.hpp include/gcem_incl/log_binomial_coef.hpp include/gcem_incl/mantissa.hpp include/gcem_incl/max.hpp include/gcem_incl/min.hpp include/gcem_incl/neg_zero.hpp include/gcem_incl/pow.hpp include/gcem_incl/pow_integral.hpp include/gcem_incl/quadrature/gauss_legendre_30.hpp include/gcem_incl/quadrature/gauss_legendre_50.hpp include/gcem_incl/round.hpp include/gcem_incl/sgn.hpp include/gcem_incl/signbit.hpp include/gcem_incl/sin.hpp include/gcem_incl/sinh.hpp include/gcem_incl/sqrt.hpp include/gcem_incl/tan.hpp include/gcem_incl/tanh.hpp include/gcem_incl/tgamma.hpp include/gcem_incl/trunc.hpp notebooks/gcem.ipynb tests/CMakeLists.txt tests/Makefile tests/abs.cpp tests/acos.cpp tests/acosh.cpp tests/asin.cpp tests/asinh.cpp tests/atan.cpp tests/atan2.cpp tests/atanh.cpp tests/binomial_coef.cpp tests/copysign.cpp tests/cos.cpp tests/cosh.cpp tests/cov_check tests/erf.cpp tests/erf_inv.cpp tests/exp.cpp tests/expm1.cpp tests/factorial.cpp tests/fmod.cpp tests/gcd.cpp tests/gcem_tests.hpp tests/incomplete_beta.cpp tests/incomplete_beta_inv.cpp tests/incomplete_gamma.cpp tests/incomplete_gamma_inv.cpp tests/inv_sqrt.cpp tests/is_odd.cpp tests/lcm.cpp tests/lgamma.cpp tests/log.cpp tests/log10.cpp tests/log1p.cpp tests/log2.cpp tests/log_binomial_coef.cpp tests/other.cpp tests/pow.cpp tests/rounding.cpp tests/run_tests tests/signbit.cpp tests/sin.cpp tests/sinh.cpp tests/sqrt.cpp tests/tan.cpp tests/tanh.cpp tests/tgamma.cpp <<<<<< network # path=tests/abs.cpp.gcov -: 0:Source:abs.cpp -: 0:Graph:./abs.gcno -: 0:Data:./abs.gcda -: 0:Runs:1 -: 1:/*################################################################################ -: 2: ## -: 3: ## Copyright (C) 2016-2022 Keith O'Hara -: 4: ## -: 5: ## This file is part of the GCE-Math C++ library. -: 6: ## -: 7: ## Licensed under the Apache License, Version 2.0 (the "License"); -: 8: ## you may not use this file except in compliance with the License. -: 9: ## You may obtain a copy of the License at -: 10: ## -: 11: ## http://www.apache.org/licenses/LICENSE-2.0 -: 12: ## -: 13: ## Unless required by applicable law or agreed to in writing, software -: 14: ## distributed under the License is distributed on an "AS IS" BASIS, -: 15: ## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -: 16: ## See the License for the specific language governing permissions and -: 17: ## limitations under the License. -: 18: ## -: 19: ################################################################################*/ -: 20: -: 21:#define TEST_PRINT_PRECISION_1 6 -: 22:#define TEST_PRINT_PRECISION_2 18 -: 23: -: 24:#include "gcem_tests.hpp" -: 25: 1: 26:int main() -: 27:{ 1: 28: print_begin("abs"); -: 29: -: 30: // -: 31: 2*: 32: GCEM_TEST_COMPARE_VALS(gcem::abs,std::abs, 0.0); 2*: 33: GCEM_TEST_COMPARE_VALS(gcem::abs,std::abs,-0.0); 2*: 34: GCEM_TEST_COMPARE_VALS(gcem::abs,std::abs, 1.0); 2*: 35: GCEM_TEST_COMPARE_VALS(gcem::abs,std::abs,-1.0); 2*: 36: GCEM_TEST_COMPARE_VALS(gcem::abs,std::abs, 0); 2*: 37: GCEM_TEST_COMPARE_VALS(gcem::abs,std::abs, 1); 2*: 38: GCEM_TEST_COMPARE_VALS(gcem::abs,std::abs,-1); -: 39: 2*: 40: GCEM_TEST_COMPARE_VALS(gcem::abs,std::abs, INT64_MIN); 2*: 41: GCEM_TEST_COMPARE_VALS(gcem::abs,std::abs, INT64_MAX); -: 42: 2*: 43: GCEM_TEST_COMPARE_VALS(gcem::abs,std::abs, TEST_NAN); 2*: 44: GCEM_TEST_COMPARE_VALS(gcem::abs,std::abs, TEST_NEGINF); 2*: 45: GCEM_TEST_COMPARE_VALS(gcem::abs,std::abs, TEST_POSINF); -: 46: -: 47: // -: 48: 1: 49: print_final("abs"); -: 50: 1: 51: return 0; -: 52:} <<<<<< EOF # path=tests/abs.hpp.gcov -: 0:Source:../include/gcem_incl/abs.hpp -: 0:Graph:log.gcno -: 0:Data:log.gcda -: 0:Runs:2 -: 1:/*################################################################################ -: 2: ## -: 3: ## Copyright (C) 2016-2022 Keith O'Hara -: 4: ## -: 5: ## This file is part of the GCE-Math C++ library. -: 6: ## -: 7: ## Licensed under the Apache License, Version 2.0 (the "License"); -: 8: ## you may not use this file except in compliance with the License. -: 9: ## You may obtain a copy of the License at -: 10: ## -: 11: ## http://www.apache.org/licenses/LICENSE-2.0 -: 12: ## -: 13: ## Unless required by applicable law or agreed to in writing, software -: 14: ## distributed under the License is distributed on an "AS IS" BASIS, -: 15: ## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -: 16: ## See the License for the specific language governing permissions and -: 17: ## limitations under the License. -: 18: ## -: 19: ################################################################################*/ -: 20: -: 21:#ifndef _gcem_abs_HPP -: 22:#define _gcem_abs_HPP -: 23: -: 24:/** -: 25: * Compile-time absolute value function -: 26: * -: 27: * @param x a real-valued input. -: 28: * @return the absolute value of \c x, \f$ |x| \f$. -: 29: */ -: 30: -: 31:template -: 32:constexpr -: 33:T 2: 34:abs(const T x) -: 35:noexcept -: 36:{ -: 37: return( // deal with signed-zeros 4*: 38: x == T(0) ? \ -: 39: T(0) : -: 40: // else 2*: 41: x < T(0) ? \ 2: 42: - x : x ); -: 43:} -: 44: -: 45:#endif <<<<<< EOF # path=tests/acos.cpp.gcov -: 0:Source:acos.cpp -: 0:Graph:./acos.gcno -: 0:Data:./acos.gcda -: 0:Runs:1 -: 1:/*################################################################################ -: 2: ## -: 3: ## Copyright (C) 2016-2022 Keith O'Hara -: 4: ## -: 5: ## This file is part of the GCE-Math C++ library. -: 6: ## -: 7: ## Licensed under the Apache License, Version 2.0 (the "License"); -: 8: ## you may not use this file except in compliance with the License. -: 9: ## You may obtain a copy of the License at -: 10: ## -: 11: ## http://www.apache.org/licenses/LICENSE-2.0 -: 12: ## -: 13: ## Unless required by applicable law or agreed to in writing, software -: 14: ## distributed under the License is distributed on an "AS IS" BASIS, -: 15: ## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -: 16: ## See the License for the specific language governing permissions and -: 17: ## limitations under the License. -: 18: ## -: 19: ################################################################################*/ -: 20: -: 21:#define TEST_PRINT_PRECISION_1 6 -: 22:#define TEST_PRINT_PRECISION_2 18 -: 23: -: 24:#include "gcem_tests.hpp" -: 25: 1: 26:int main() -: 27:{ 1: 28: print_begin("acos"); -: 29: -: 30: // -: 31: 2*: 32: GCEM_TEST_COMPARE_VALS(gcem::acos,std::acos, 0.0L); 2*: 33: GCEM_TEST_COMPARE_VALS(gcem::acos,std::acos, 0.001L); 2*: 34: GCEM_TEST_COMPARE_VALS(gcem::acos,std::acos, 0.5L); 2*: 35: GCEM_TEST_COMPARE_VALS(gcem::acos,std::acos,-0.5L); 2*: 36: GCEM_TEST_COMPARE_VALS(gcem::acos,std::acos, 0.7568025L); 2*: 37: GCEM_TEST_COMPARE_VALS(gcem::acos,std::acos, 1.0L); 2*: 38: GCEM_TEST_COMPARE_VALS(gcem::acos,std::acos, 5.0L); -: 39: 2*: 40: GCEM_TEST_COMPARE_VALS(gcem::acos,std::acos, TEST_NAN); -: 41: -: 42: // -: 43: 1: 44: print_final("acos"); -: 45: 1: 46: return 0; -: 47:} <<<<<< EOF # path=tests/acosh.cpp.gcov -: 0:Source:acosh.cpp -: 0:Graph:./acosh.gcno -: 0:Data:./acosh.gcda -: 0:Runs:1 -: 1:/*################################################################################ -: 2: ## -: 3: ## Copyright (C) 2016-2022 Keith O'Hara -: 4: ## -: 5: ## This file is part of the GCE-Math C++ library. -: 6: ## -: 7: ## Licensed under the Apache License, Version 2.0 (the "License"); -: 8: ## you may not use this file except in compliance with the License. -: 9: ## You may obtain a copy of the License at -: 10: ## -: 11: ## http://www.apache.org/licenses/LICENSE-2.0 -: 12: ## -: 13: ## Unless required by applicable law or agreed to in writing, software -: 14: ## distributed under the License is distributed on an "AS IS" BASIS, -: 15: ## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -: 16: ## See the License for the specific language governing permissions and -: 17: ## limitations under the License. -: 18: ## -: 19: ################################################################################*/ -: 20: -: 21:#define TEST_PRINT_PRECISION_1 3 -: 22:#define TEST_PRINT_PRECISION_2 18 -: 23: -: 24:#include "gcem_tests.hpp" -: 25: 1: 26:int main() -: 27:{ 1: 28: print_begin("acosh"); -: 29: -: 30: // -: 31: 2*: 32: GCEM_TEST_COMPARE_VALS(gcem::acosh,std::acosh,1.001L); 2*: 33: GCEM_TEST_COMPARE_VALS(gcem::acosh,std::acosh,1.5L); 2*: 34: GCEM_TEST_COMPARE_VALS(gcem::acosh,std::acosh,11.1L); 2*: 35: GCEM_TEST_COMPARE_VALS(gcem::acosh,std::acosh,50.0L); 2*: 36: GCEM_TEST_COMPARE_VALS(gcem::acosh,std::acosh,0.5L); -: 37: 2*: 38: GCEM_TEST_COMPARE_VALS(gcem::acosh,std::acosh,TEST_NAN); -: 39: -: 40: // -: 41: 1: 42: print_final("acosh"); -: 43: 1: 44: return 0; -: 45:} <<<<<< EOF # path=tests/alloc_traits.h.gcov -: 0:Source:/usr/include/c++/9/ext/alloc_traits.h -: 0:Graph:log.gcno -: 0:Data:log.gcda -: 0:Runs:2 -: 1:// Allocator traits -*- C++ -*- -: 2: -: 3:// Copyright (C) 2011-2019 Free Software Foundation, Inc. -: 4:// -: 5:// This file is part of the GNU ISO C++ Library. This library is free -: 6:// software; you can redistribute it and/or modify it under the -: 7:// terms of the GNU General Public License as published by the -: 8:// Free Software Foundation; either version 3, or (at your option) -: 9:// any later version. -: 10: -: 11:// This library is distributed in the hope that it will be useful, -: 12:// but WITHOUT ANY WARRANTY; without even the implied warranty of -: 13:// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -: 14:// GNU General Public License for more details. -: 15: -: 16:// Under Section 7 of GPL version 3, you are granted additional -: 17:// permissions described in the GCC Runtime Library Exception, version -: 18:// 3.1, as published by the Free Software Foundation. -: 19: -: 20:// You should have received a copy of the GNU General Public License and -: 21:// a copy of the GCC Runtime Library Exception along with this program; -: 22:// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see -: 23:// . -: 24: -: 25:/** @file ext/alloc_traits.h -: 26: * This file is a GNU extension to the Standard C++ Library. -: 27: */ -: 28: -: 29:#ifndef _EXT_ALLOC_TRAITS_H -: 30:#define _EXT_ALLOC_TRAITS_H 1 -: 31: -: 32:#pragma GCC system_header -: 33: -: 34:#if __cplusplus >= 201103L -: 35:# include -: 36:# include -: 37:#else -: 38:# include // for __alloc_swap -: 39:#endif -: 40: -: 41:namespace __gnu_cxx _GLIBCXX_VISIBILITY(default) -: 42:{ -: 43:_GLIBCXX_BEGIN_NAMESPACE_VERSION -: 44: -: 45:/** -: 46: * @brief Uniform interface to C++98 and C++11 allocators. -: 47: * @ingroup allocators -: 48:*/ -: 49:template -: 50: struct __alloc_traits -: 51:#if __cplusplus >= 201103L -: 52: : std::allocator_traits<_Alloc> -: 53:#endif -: 54: { -: 55: typedef _Alloc allocator_type; -: 56:#if __cplusplus >= 201103L -: 57: typedef std::allocator_traits<_Alloc> _Base_type; -: 58: typedef typename _Base_type::value_type value_type; -: 59: typedef typename _Base_type::pointer pointer; -: 60: typedef typename _Base_type::const_pointer const_pointer; -: 61: typedef typename _Base_type::size_type size_type; -: 62: typedef typename _Base_type::difference_type difference_type; -: 63: // C++11 allocators do not define reference or const_reference -: 64: typedef value_type& reference; -: 65: typedef const value_type& const_reference; -: 66: using _Base_type::allocate; -: 67: using _Base_type::deallocate; -: 68: using _Base_type::construct; -: 69: using _Base_type::destroy; -: 70: using _Base_type::max_size; -: 71: -: 72: private: -: 73: template -: 74: using __is_custom_pointer -: 75: = std::__and_, -: 76: std::__not_>>; -: 77: -: 78: public: -: 79: // overload construct for non-standard pointer types -: 80: template -: 81: static typename std::enable_if<__is_custom_pointer<_Ptr>::value>::type -: 82: construct(_Alloc& __a, _Ptr __p, _Args&&... __args) -: 83: noexcept(noexcept(_Base_type::construct(__a, std::__to_address(__p), -: 84: std::forward<_Args>(__args)...))) -: 85: { -: 86: _Base_type::construct(__a, std::__to_address(__p), -: 87: std::forward<_Args>(__args)...); -: 88: } -: 89: -: 90: // overload destroy for non-standard pointer types -: 91: template -: 92: static typename std::enable_if<__is_custom_pointer<_Ptr>::value>::type -: 93: destroy(_Alloc& __a, _Ptr __p) -: 94: noexcept(noexcept(_Base_type::destroy(__a, std::__to_address(__p)))) -: 95: { _Base_type::destroy(__a, std::__to_address(__p)); } -: 96: #####: 97: static _Alloc _S_select_on_copy(const _Alloc& __a) #####: 98: { return _Base_type::select_on_container_copy_construction(__a); } -: 99: -: 100: static void _S_on_swap(_Alloc& __a, _Alloc& __b) -: 101: { std::__alloc_on_swap(__a, __b); } -: 102: -: 103: static constexpr bool _S_propagate_on_copy_assign() -: 104: { return _Base_type::propagate_on_container_copy_assignment::value; } -: 105: -: 106: static constexpr bool _S_propagate_on_move_assign() -: 107: { return _Base_type::propagate_on_container_move_assignment::value; } -: 108: -: 109: static constexpr bool _S_propagate_on_swap() -: 110: { return _Base_type::propagate_on_container_swap::value; } -: 111: -: 112: static constexpr bool _S_always_equal() -: 113: { return _Base_type::is_always_equal::value; } -: 114: -: 115: static constexpr bool _S_nothrow_move() -: 116: { return _S_propagate_on_move_assign() || _S_always_equal(); } -: 117: -: 118: template -: 119: struct rebind -: 120: { typedef typename _Base_type::template rebind_alloc<_Tp> other; }; -: 121:#else -: 122: -: 123: typedef typename _Alloc::pointer pointer; -: 124: typedef typename _Alloc::const_pointer const_pointer; -: 125: typedef typename _Alloc::value_type value_type; -: 126: typedef typename _Alloc::reference reference; -: 127: typedef typename _Alloc::const_reference const_reference; -: 128: typedef typename _Alloc::size_type size_type; -: 129: typedef typename _Alloc::difference_type difference_type; -: 130: -: 131: _GLIBCXX_NODISCARD static pointer -: 132: allocate(_Alloc& __a, size_type __n) -: 133: { return __a.allocate(__n); } -: 134: -: 135: static void deallocate(_Alloc& __a, pointer __p, size_type __n) -: 136: { __a.deallocate(__p, __n); } -: 137: -: 138: template -: 139: static void construct(_Alloc& __a, pointer __p, const _Tp& __arg) -: 140: { __a.construct(__p, __arg); } -: 141: -: 142: static void destroy(_Alloc& __a, pointer __p) -: 143: { __a.destroy(__p); } -: 144: -: 145: static size_type max_size(const _Alloc& __a) -: 146: { return __a.max_size(); } -: 147: -: 148: static const _Alloc& _S_select_on_copy(const _Alloc& __a) { return __a; } -: 149: -: 150: static void _S_on_swap(_Alloc& __a, _Alloc& __b) -: 151: { -: 152: // _GLIBCXX_RESOLVE_LIB_DEFECTS -: 153: // 431. Swapping containers with unequal allocators. -: 154: std::__alloc_swap<_Alloc>::_S_do_it(__a, __b); -: 155: } -: 156: -: 157: template -: 158: struct rebind -: 159: { typedef typename _Alloc::template rebind<_Tp>::other other; }; -: 160:#endif -: 161: }; -: 162: -: 163:_GLIBCXX_END_NAMESPACE_VERSION -: 164:} // namespace __gnu_cxx -: 165: -: 166:#endif <<<<<< EOF # path=tests/asin.cpp.gcov -: 0:Source:asin.cpp -: 0:Graph:./asin.gcno -: 0:Data:./asin.gcda -: 0:Runs:1 -: 1:/*################################################################################ -: 2: ## -: 3: ## Copyright (C) 2016-2022 Keith O'Hara -: 4: ## -: 5: ## This file is part of the GCE-Math C++ library. -: 6: ## -: 7: ## Licensed under the Apache License, Version 2.0 (the "License"); -: 8: ## you may not use this file except in compliance with the License. -: 9: ## You may obtain a copy of the License at -: 10: ## -: 11: ## http://www.apache.org/licenses/LICENSE-2.0 -: 12: ## -: 13: ## Unless required by applicable law or agreed to in writing, software -: 14: ## distributed under the License is distributed on an "AS IS" BASIS, -: 15: ## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -: 16: ## See the License for the specific language governing permissions and -: 17: ## limitations under the License. -: 18: ## -: 19: ################################################################################*/ -: 20: -: 21:#define TEST_PRINT_PRECISION_1 6 -: 22:#define TEST_PRINT_PRECISION_2 18 -: 23: -: 24:#include "gcem_tests.hpp" -: 25: 1: 26:int main() -: 27:{ 1: 28: print_begin("asin"); -: 29: -: 30: // -: 31: 2*: 32: GCEM_TEST_COMPARE_VALS(gcem::asin,std::asin,0.0L); 2*: 33: GCEM_TEST_COMPARE_VALS(gcem::asin,std::asin,0.001L); 2*: 34: GCEM_TEST_COMPARE_VALS(gcem::asin,std::asin,0.5L); 2*: 35: GCEM_TEST_COMPARE_VALS(gcem::asin,std::asin,-0.5L); 2*: 36: GCEM_TEST_COMPARE_VALS(gcem::asin,std::asin,0.7568025L); 2*: 37: GCEM_TEST_COMPARE_VALS(gcem::asin,std::asin,1.0L); 2*: 38: GCEM_TEST_COMPARE_VALS(gcem::asin,std::asin,5.0L); -: 39: 2*: 40: GCEM_TEST_COMPARE_VALS(gcem::asin,std::asin,TEST_NAN); -: 41: -: 42: // -: 43: 1: 44: print_final("asin"); -: 45: 1: 46: return 0; -: 47:} <<<<<< EOF # path=tests/asinh.cpp.gcov -: 0:Source:asinh.cpp -: 0:Graph:./asinh.gcno -: 0:Data:./asinh.gcda -: 0:Runs:1 -: 1:/*################################################################################ -: 2: ## -: 3: ## Copyright (C) 2016-2022 Keith O'Hara -: 4: ## -: 5: ## This file is part of the GCE-Math C++ library. -: 6: ## -: 7: ## Licensed under the Apache License, Version 2.0 (the "License"); -: 8: ## you may not use this file except in compliance with the License. -: 9: ## You may obtain a copy of the License at -: 10: ## -: 11: ## http://www.apache.org/licenses/LICENSE-2.0 -: 12: ## -: 13: ## Unless required by applicable law or agreed to in writing, software -: 14: ## distributed under the License is distributed on an "AS IS" BASIS, -: 15: ## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -: 16: ## See the License for the specific language governing permissions and -: 17: ## limitations under the License. -: 18: ## -: 19: ################################################################################*/ -: 20: -: 21:#define TEST_PRINT_PRECISION_1 3 -: 22:#define TEST_PRINT_PRECISION_2 18 -: 23: -: 24:#include "gcem_tests.hpp" -: 25: 1: 26:int main() -: 27:{ 1: 28: print_begin("asinh"); -: 29: -: 30: // -: 31: 2*: 32: GCEM_TEST_COMPARE_VALS(gcem::asinh,std::asinh,0.0L); 2*: 33: GCEM_TEST_COMPARE_VALS(gcem::asinh,std::asinh,0.001L); 2*: 34: GCEM_TEST_COMPARE_VALS(gcem::asinh,std::asinh,1.001L); 2*: 35: GCEM_TEST_COMPARE_VALS(gcem::asinh,std::asinh,1.5L); 2*: 36: GCEM_TEST_COMPARE_VALS(gcem::asinh,std::asinh,11.1L); 2*: 37: GCEM_TEST_COMPARE_VALS(gcem::asinh,std::asinh,50.0L); 2*: 38: GCEM_TEST_COMPARE_VALS(gcem::asinh,std::asinh,-1.5L); -: 39: 2*: 40: GCEM_TEST_COMPARE_VALS(gcem::asinh,std::asinh,TEST_NAN); -: 41: -: 42: // -: 43: 1: 44: print_final("asinh"); -: 45: 1: 46: return 0; -: 47:} <<<<<< EOF # path=tests/atan.cpp.gcov -: 0:Source:atan.cpp -: 0:Graph:./atan.gcno -: 0:Data:./atan.gcda -: 0:Runs:1 -: 1:/*################################################################################ -: 2: ## -: 3: ## Copyright (C) 2016-2022 Keith O'Hara -: 4: ## -: 5: ## This file is part of the GCE-Math C++ library. -: 6: ## -: 7: ## Licensed under the Apache License, Version 2.0 (the "License"); -: 8: ## you may not use this file except in compliance with the License. -: 9: ## You may obtain a copy of the License at -: 10: ## -: 11: ## http://www.apache.org/licenses/LICENSE-2.0 -: 12: ## -: 13: ## Unless required by applicable law or agreed to in writing, software -: 14: ## distributed under the License is distributed on an "AS IS" BASIS, -: 15: ## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -: 16: ## See the License for the specific language governing permissions and -: 17: ## limitations under the License. -: 18: ## -: 19: ################################################################################*/ -: 20: -: 21:#define TEST_PRINT_PRECISION_1 6 -: 22:#define TEST_PRINT_PRECISION_2 18 -: 23: -: 24:#include "gcem_tests.hpp" -: 25: 1: 26:int main() -: 27:{ 1: 28: print_begin("atan"); -: 29: -: 30: // -: 31: 2*: 32: GCEM_TEST_COMPARE_VALS(gcem::atan,std::atan,0.0L); 2*: 33: GCEM_TEST_COMPARE_VALS(gcem::atan,std::atan,0.001L); 2*: 34: GCEM_TEST_COMPARE_VALS(gcem::atan,std::atan,0.49L); 2*: 35: GCEM_TEST_COMPARE_VALS(gcem::atan,std::atan,-0.5L); 2*: 36: GCEM_TEST_COMPARE_VALS(gcem::atan,std::atan,-1.5L); 2*: 37: GCEM_TEST_COMPARE_VALS(gcem::atan,std::atan,0.7568025L); 2*: 38: GCEM_TEST_COMPARE_VALS(gcem::atan,std::atan,0.99L); 2*: 39: GCEM_TEST_COMPARE_VALS(gcem::atan,std::atan,1.49L); 2*: 40: GCEM_TEST_COMPARE_VALS(gcem::atan,std::atan,1.99L); -: 41: 2*: 42: GCEM_TEST_COMPARE_VALS(gcem::atan,std::atan,2.49L); 2*: 43: GCEM_TEST_COMPARE_VALS(gcem::atan,std::atan,2.51L); 2*: 44: GCEM_TEST_COMPARE_VALS(gcem::atan,std::atan,3.99L); 2*: 45: GCEM_TEST_COMPARE_VALS(gcem::atan,std::atan,7.0L); 2*: 46: GCEM_TEST_COMPARE_VALS(gcem::atan,std::atan,11.0L); 2*: 47: GCEM_TEST_COMPARE_VALS(gcem::atan,std::atan,25.0L); -: 48: 2*: 49: GCEM_TEST_COMPARE_VALS(gcem::atan,std::atan,101.0L); 2*: 50: GCEM_TEST_COMPARE_VALS(gcem::atan,std::atan,900.0L); 2*: 51: GCEM_TEST_COMPARE_VALS(gcem::atan,std::atan,1001.0L); -: 52: 2*: 53: GCEM_TEST_COMPARE_VALS(gcem::atan,std::atan,TEST_NAN); -: 54: -: 55: // -: 56: 1: 57: print_final("atan"); -: 58: 1: 59: return 0; -: 60:} <<<<<< EOF # path=tests/atan2.cpp.gcov -: 0:Source:atan2.cpp -: 0:Graph:./atan2.gcno -: 0:Data:./atan2.gcda -: 0:Runs:1 -: 1:/*################################################################################ -: 2: ## -: 3: ## Copyright (C) 2016-2022 Keith O'Hara -: 4: ## -: 5: ## This file is part of the GCE-Math C++ library. -: 6: ## -: 7: ## Licensed under the Apache License, Version 2.0 (the "License"); -: 8: ## you may not use this file except in compliance with the License. -: 9: ## You may obtain a copy of the License at -: 10: ## -: 11: ## http://www.apache.org/licenses/LICENSE-2.0 -: 12: ## -: 13: ## Unless required by applicable law or agreed to in writing, software -: 14: ## distributed under the License is distributed on an "AS IS" BASIS, -: 15: ## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -: 16: ## See the License for the specific language governing permissions and -: 17: ## limitations under the License. -: 18: ## -: 19: ################################################################################*/ -: 20: -: 21:#define TEST_PRINT_PRECISION_1 6 -: 22:#define TEST_PRINT_PRECISION_2 18 -: 23: -: 24:#include "gcem_tests.hpp" -: 25: 1: 26:int main() -: 27:{ 1: 28: print_begin("atan2"); -: 29: -: 30: // -: 31: 2*: 32: GCEM_TEST_COMPARE_VALS(gcem::atan2,std::atan2, 0.0L, 0.0L); 2*: 33: GCEM_TEST_COMPARE_VALS(gcem::atan2,std::atan2, -0.0L, 0.0L); 2*: 34: GCEM_TEST_COMPARE_VALS(gcem::atan2,std::atan2, 0.0L, -0.0L); 2*: 35: GCEM_TEST_COMPARE_VALS(gcem::atan2,std::atan2, -0.0L, -0.0L); -: 36: 2*: 37: GCEM_TEST_COMPARE_VALS(gcem::atan2,std::atan2, 0.2L, 0.0L); 2*: 38: GCEM_TEST_COMPARE_VALS(gcem::atan2,std::atan2, -0.2L, 0.0L); 2*: 39: GCEM_TEST_COMPARE_VALS(gcem::atan2,std::atan2, 0.001L, 0.001L); 2*: 40: GCEM_TEST_COMPARE_VALS(gcem::atan2,std::atan2, 0.49L, 0.49L); -: 41: 2*: 42: GCEM_TEST_COMPARE_VALS(gcem::atan2,std::atan2, -0.5L, -0.5L); 2*: 43: GCEM_TEST_COMPARE_VALS(gcem::atan2,std::atan2, 0.5L, -0.5L); 2*: 44: GCEM_TEST_COMPARE_VALS(gcem::atan2,std::atan2, -0.5L, 0.5L); -: 45: 2*: 46: GCEM_TEST_COMPARE_VALS(gcem::atan2,std::atan2, 9.6L, 8.4L); 2*: 47: GCEM_TEST_COMPARE_VALS(gcem::atan2,std::atan2, 1.0L, 0.0L); 2*: 48: GCEM_TEST_COMPARE_VALS(gcem::atan2,std::atan2, 0.0L, 1.0L); 2*: 49: GCEM_TEST_COMPARE_VALS(gcem::atan2,std::atan2, -1.0L, 0.0L); 2*: 50: GCEM_TEST_COMPARE_VALS(gcem::atan2,std::atan2, 0.0L, -1.0L); 2*: 51: GCEM_TEST_COMPARE_VALS(gcem::atan2,std::atan2, 1.0L, 3.0L); 2*: 52: GCEM_TEST_COMPARE_VALS(gcem::atan2,std::atan2, -5.0L, 2.5L); 2*: 53: GCEM_TEST_COMPARE_VALS(gcem::atan2,std::atan2, -1000.0L, -0.001L); 2*: 54: GCEM_TEST_COMPARE_VALS(gcem::atan2,std::atan2, 0.1337L, -123456.0L); -: 55: -: 56: // -: 57: 2*: 58: GCEM_TEST_COMPARE_VALS(gcem::atan2,std::atan2, TEST_NAN, 1.0L); 2*: 59: GCEM_TEST_COMPARE_VALS(gcem::atan2,std::atan2, 1.0L, TEST_NAN); 2*: 60: GCEM_TEST_COMPARE_VALS(gcem::atan2,std::atan2, TEST_NAN, TEST_NAN); -: 61: -: 62: // -: 63: 1: 64: print_final("atan2"); -: 65: 1: 66: return 0; -: 67:} <<<<<< EOF # path=tests/atanh.cpp.gcov -: 0:Source:atanh.cpp -: 0:Graph:./atanh.gcno -: 0:Data:./atanh.gcda -: 0:Runs:1 -: 1:/*################################################################################ -: 2: ## -: 3: ## Copyright (C) 2016-2022 Keith O'Hara -: 4: ## -: 5: ## This file is part of the GCE-Math C++ library. -: 6: ## -: 7: ## Licensed under the Apache License, Version 2.0 (the "License"); -: 8: ## you may not use this file except in compliance with the License. -: 9: ## You may obtain a copy of the License at -: 10: ## -: 11: ## http://www.apache.org/licenses/LICENSE-2.0 -: 12: ## -: 13: ## Unless required by applicable law or agreed to in writing, software -: 14: ## distributed under the License is distributed on an "AS IS" BASIS, -: 15: ## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -: 16: ## See the License for the specific language governing permissions and -: 17: ## limitations under the License. -: 18: ## -: 19: ################################################################################*/ -: 20: -: 21:#define TEST_PRINT_PRECISION_1 3 -: 22:#define TEST_PRINT_PRECISION_2 18 -: 23: -: 24:#include "gcem_tests.hpp" -: 25: 1: 26:int main() -: 27:{ 1: 28: print_begin("atanh"); -: 29: -: 30: // -: 31: 2*: 32: GCEM_TEST_COMPARE_VALS(gcem::atanh,std::atanh,-0.99L); 2*: 33: GCEM_TEST_COMPARE_VALS(gcem::atanh,std::atanh,0.0L); 2*: 34: GCEM_TEST_COMPARE_VALS(gcem::atanh,std::atanh,0.001L); 2*: 35: GCEM_TEST_COMPARE_VALS(gcem::atanh,std::atanh,1.0L); 2*: 36: GCEM_TEST_COMPARE_VALS(gcem::atanh,std::atanh,-1.0L); 2*: 37: GCEM_TEST_COMPARE_VALS(gcem::atanh,std::atanh,1.1L); -: 38: 2*: 39: GCEM_TEST_COMPARE_VALS(gcem::atanh,std::atanh,TEST_NAN); -: 40: -: 41: // -: 42: 1: 43: print_final("atanh"); -: 44: 1: 45: return 0; -: 46:} <<<<<< EOF # path=tests/basic_string.h.gcov -: 0:Source:/usr/include/c++/9/bits/basic_string.h -: 0:Graph:log.gcno -: 0:Data:log.gcda -: 0:Runs:2 -: 1:// Components for manipulating sequences of characters -*- C++ -*- -: 2: -: 3:// Copyright (C) 1997-2019 Free Software Foundation, Inc. -: 4:// -: 5:// This file is part of the GNU ISO C++ Library. This library is free -: 6:// software; you can redistribute it and/or modify it under the -: 7:// terms of the GNU General Public License as published by the -: 8:// Free Software Foundation; either version 3, or (at your option) -: 9:// any later version. -: 10: -: 11:// This library is distributed in the hope that it will be useful, -: 12:// but WITHOUT ANY WARRANTY; without even the implied warranty of -: 13:// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -: 14:// GNU General Public License for more details. -: 15: -: 16:// Under Section 7 of GPL version 3, you are granted additional -: 17:// permissions described in the GCC Runtime Library Exception, version -: 18:// 3.1, as published by the Free Software Foundation. -: 19: -: 20:// You should have received a copy of the GNU General Public License and -: 21:// a copy of the GCC Runtime Library Exception along with this program; -: 22:// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see -: 23:// . -: 24: -: 25:/** @file bits/basic_string.h -: 26: * This is an internal header file, included by other library headers. -: 27: * Do not attempt to use it directly. @headername{string} -: 28: */ -: 29: -: 30:// -: 31:// ISO C++ 14882: 21 Strings library -: 32:// -: 33: -: 34:#ifndef _BASIC_STRING_H -: 35:#define _BASIC_STRING_H 1 -: 36: -: 37:#pragma GCC system_header -: 38: -: 39:#include -: 40:#include -: 41:#include -: 42: -: 43:#if __cplusplus >= 201103L -: 44:#include -: 45:#endif -: 46: -: 47:#if __cplusplus >= 201703L -: 48:# include -: 49:#endif -: 50: -: 51:namespace std _GLIBCXX_VISIBILITY(default) -: 52:{ -: 53:_GLIBCXX_BEGIN_NAMESPACE_VERSION -: 54: -: 55:#if __cplusplus >= 201703L -: 56:// Support P0426R1 changes to char_traits in C++17. -: 57:# define __cpp_lib_constexpr_string 201611L -: 58:#endif -: 59: -: 60:#if _GLIBCXX_USE_CXX11_ABI -: 61:_GLIBCXX_BEGIN_NAMESPACE_CXX11 -: 62: /** -: 63: * @class basic_string basic_string.h -: 64: * @brief Managing sequences of characters and character-like objects. -: 65: * -: 66: * @ingroup strings -: 67: * @ingroup sequences -: 68: * -: 69: * @tparam _CharT Type of character -: 70: * @tparam _Traits Traits for character type, defaults to -: 71: * char_traits<_CharT>. -: 72: * @tparam _Alloc Allocator type, defaults to allocator<_CharT>. -: 73: * -: 74: * Meets the requirements of a container, a -: 75: * reversible container, and a -: 76: * sequence. Of the -: 77: * optional sequence requirements, only -: 78: * @c push_back, @c at, and @c %array access are supported. -: 79: */ -: 80: template -: 81: class basic_string -: 82: { -: 83: typedef typename __gnu_cxx::__alloc_traits<_Alloc>::template -: 84: rebind<_CharT>::other _Char_alloc_type; -: 85: typedef __gnu_cxx::__alloc_traits<_Char_alloc_type> _Alloc_traits; -: 86: -: 87: // Types: -: 88: public: -: 89: typedef _Traits traits_type; -: 90: typedef typename _Traits::char_type value_type; -: 91: typedef _Char_alloc_type allocator_type; -: 92: typedef typename _Alloc_traits::size_type size_type; -: 93: typedef typename _Alloc_traits::difference_type difference_type; -: 94: typedef typename _Alloc_traits::reference reference; -: 95: typedef typename _Alloc_traits::const_reference const_reference; -: 96: typedef typename _Alloc_traits::pointer pointer; -: 97: typedef typename _Alloc_traits::const_pointer const_pointer; -: 98: typedef __gnu_cxx::__normal_iterator iterator; -: 99: typedef __gnu_cxx::__normal_iterator -: 100: const_iterator; -: 101: typedef std::reverse_iterator const_reverse_iterator; -: 102: typedef std::reverse_iterator reverse_iterator; -: 103: -: 104: /// Value returned by various member functions when they fail. -: 105: static const size_type npos = static_cast(-1); -: 106: -: 107: protected: -: 108: // type used for positions in insert, erase etc. -: 109:#if __cplusplus < 201103L -: 110: typedef iterator __const_iterator; -: 111:#else -: 112: typedef const_iterator __const_iterator; -: 113:#endif -: 114: -: 115: private: -: 116:#if __cplusplus >= 201703L -: 117: // A helper type for avoiding boiler-plate. -: 118: typedef basic_string_view<_CharT, _Traits> __sv_type; -: 119: -: 120: template -: 121: using _If_sv = enable_if_t< -: 122: __and_, -: 123: __not_>, -: 124: __not_>>::value, -: 125: _Res>; -: 126: -: 127: // Allows an implicit conversion to __sv_type. -: 128: static __sv_type -: 129: _S_to_string_view(__sv_type __svt) noexcept -: 130: { return __svt; } -: 131: -: 132: // Wraps a string_view by explicit conversion and thus -: 133: // allows to add an internal constructor that does not -: 134: // participate in overload resolution when a string_view -: 135: // is provided. -: 136: struct __sv_wrapper -: 137: { -: 138: explicit __sv_wrapper(__sv_type __sv) noexcept : _M_sv(__sv) { } -: 139: __sv_type _M_sv; -: 140: }; -: 141: -: 142: /** -: 143: * @brief Only internally used: Construct string from a string view -: 144: * wrapper. -: 145: * @param __svw string view wrapper. -: 146: * @param __a Allocator to use. -: 147: */ -: 148: explicit -: 149: basic_string(__sv_wrapper __svw, const _Alloc& __a) -: 150: : basic_string(__svw._M_sv.data(), __svw._M_sv.size(), __a) { } -: 151:#endif -: 152: -: 153: // Use empty-base optimization: http://www.cantrip.org/emptyopt.html -: 154: struct _Alloc_hider : allocator_type // TODO check __is_final -: 155: { -: 156:#if __cplusplus < 201103L -: 157: _Alloc_hider(pointer __dat, const _Alloc& __a = _Alloc()) -: 158: : allocator_type(__a), _M_p(__dat) { } -: 159:#else -: 160: _Alloc_hider(pointer __dat, const _Alloc& __a) -: 161: : allocator_type(__a), _M_p(__dat) { } -: 162: -: 163: _Alloc_hider(pointer __dat, _Alloc&& __a = _Alloc()) -: 164: : allocator_type(std::move(__a)), _M_p(__dat) { } -: 165:#endif -: 166: -: 167: pointer _M_p; // The actual data. -: 168: }; -: 169: -: 170: _Alloc_hider _M_dataplus; -: 171: size_type _M_string_length; -: 172: -: 173: enum { _S_local_capacity = 15 / sizeof(_CharT) }; -: 174: -: 175: union -: 176: { -: 177: _CharT _M_local_buf[_S_local_capacity + 1]; -: 178: size_type _M_allocated_capacity; -: 179: }; -: 180: -: 181: void -: 182: _M_data(pointer __p) -: 183: { _M_dataplus._M_p = __p; } -: 184: -: 185: void -: 186: _M_length(size_type __length) -: 187: { _M_string_length = __length; } -: 188: -: 189: pointer -: 190: _M_data() const -: 191: { return _M_dataplus._M_p; } -: 192: -: 193: pointer -: 194: _M_local_data() -: 195: { -: 196:#if __cplusplus >= 201103L -: 197: return std::pointer_traits::pointer_to(*_M_local_buf); -: 198:#else -: 199: return pointer(_M_local_buf); -: 200:#endif -: 201: } -: 202: -: 203: const_pointer -: 204: _M_local_data() const -: 205: { -: 206:#if __cplusplus >= 201103L -: 207: return std::pointer_traits::pointer_to(*_M_local_buf); -: 208:#else -: 209: return const_pointer(_M_local_buf); -: 210:#endif -: 211: } -: 212: -: 213: void -: 214: _M_capacity(size_type __capacity) -: 215: { _M_allocated_capacity = __capacity; } -: 216: -: 217: void -: 218: _M_set_length(size_type __n) -: 219: { -: 220: _M_length(__n); -: 221: traits_type::assign(_M_data()[__n], _CharT()); -: 222: } -: 223: -: 224: bool -: 225: _M_is_local() const -: 226: { return _M_data() == _M_local_data(); } -: 227: -: 228: // Create & Destroy -: 229: pointer -: 230: _M_create(size_type&, size_type); -: 231: -: 232: void -: 233: _M_dispose() -: 234: { -: 235: if (!_M_is_local()) -: 236: _M_destroy(_M_allocated_capacity); -: 237: } -: 238: -: 239: void -: 240: _M_destroy(size_type __size) throw() -: 241: { _Alloc_traits::deallocate(_M_get_allocator(), _M_data(), __size + 1); } -: 242: -: 243: // _M_construct_aux is used to implement the 21.3.1 para 15 which -: 244: // requires special behaviour if _InIterator is an integral type -: 245: template -: 246: void #####: 247: _M_construct_aux(_InIterator __beg, _InIterator __end, -: 248: std::__false_type) -: 249: { -: 250: typedef typename iterator_traits<_InIterator>::iterator_category _Tag; #####: 251: _M_construct(__beg, __end, _Tag()); #####: 252: } ------------------ _ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE16_M_construct_auxIPcEEvT_S7_St12__false_type: #####: 247: _M_construct_aux(_InIterator __beg, _InIterator __end, -: 248: std::__false_type) -: 249: { -: 250: typedef typename iterator_traits<_InIterator>::iterator_category _Tag; #####: 251: _M_construct(__beg, __end, _Tag()); #####: 252: } ------------------ _ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE16_M_construct_auxIPKcEEvT_S8_St12__false_type: #####: 247: _M_construct_aux(_InIterator __beg, _InIterator __end, -: 248: std::__false_type) -: 249: { -: 250: typedef typename iterator_traits<_InIterator>::iterator_category _Tag; #####: 251: _M_construct(__beg, __end, _Tag()); #####: 252: } ------------------ -: 253: -: 254: // _GLIBCXX_RESOLVE_LIB_DEFECTS -: 255: // 438. Ambiguity in the "do the right thing" clause -: 256: template -: 257: void -: 258: _M_construct_aux(_Integer __beg, _Integer __end, std::__true_type) -: 259: { _M_construct_aux_2(static_cast(__beg), __end); } -: 260: -: 261: void -: 262: _M_construct_aux_2(size_type __req, _CharT __c) -: 263: { _M_construct(__req, __c); } -: 264: -: 265: template -: 266: void #####: 267: _M_construct(_InIterator __beg, _InIterator __end) -: 268: { -: 269: typedef typename std::__is_integer<_InIterator>::__type _Integral; #####: 270: _M_construct_aux(__beg, __end, _Integral()); #####: 271: } ------------------ _ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE12_M_constructIPcEEvT_S7_: #####: 267: _M_construct(_InIterator __beg, _InIterator __end) -: 268: { -: 269: typedef typename std::__is_integer<_InIterator>::__type _Integral; #####: 270: _M_construct_aux(__beg, __end, _Integral()); #####: 271: } ------------------ _ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE12_M_constructIPKcEEvT_S8_: #####: 267: _M_construct(_InIterator __beg, _InIterator __end) -: 268: { -: 269: typedef typename std::__is_integer<_InIterator>::__type _Integral; #####: 270: _M_construct_aux(__beg, __end, _Integral()); #####: 271: } ------------------ -: 272: -: 273: // For Input Iterators, used in istreambuf_iterators, etc. -: 274: template -: 275: void -: 276: _M_construct(_InIterator __beg, _InIterator __end, -: 277: std::input_iterator_tag); -: 278: -: 279: // For forward_iterators up to random_access_iterators, used for -: 280: // string::iterator, _CharT*, etc. -: 281: template -: 282: void -: 283: _M_construct(_FwdIterator __beg, _FwdIterator __end, -: 284: std::forward_iterator_tag); -: 285: -: 286: void -: 287: _M_construct(size_type __req, _CharT __c); -: 288: -: 289: allocator_type& -: 290: _M_get_allocator() -: 291: { return _M_dataplus; } -: 292: -: 293: const allocator_type& -: 294: _M_get_allocator() const -: 295: { return _M_dataplus; } -: 296: -: 297: private: -: 298: -: 299:#ifdef _GLIBCXX_DISAMBIGUATE_REPLACE_INST -: 300: // The explicit instantiations in misc-inst.cc require this due to -: 301: // https://gcc.gnu.org/bugzilla/show_bug.cgi?id=64063 -: 302: template::__value -: 304: && !__are_same<_Tp, const _CharT*>::__value -: 305: && !__are_same<_Tp, iterator>::__value -: 306: && !__are_same<_Tp, const_iterator>::__value> -: 307: struct __enable_if_not_native_iterator -: 308: { typedef basic_string& __type; }; -: 309: template -: 310: struct __enable_if_not_native_iterator<_Tp, false> { }; -: 311:#endif -: 312: -: 313: size_type -: 314: _M_check(size_type __pos, const char* __s) const -: 315: { -: 316: if (__pos > this->size()) -: 317: __throw_out_of_range_fmt(__N("%s: __pos (which is %zu) > " -: 318: "this->size() (which is %zu)"), -: 319: __s, __pos, this->size()); -: 320: return __pos; -: 321: } -: 322: -: 323: void -: 324: _M_check_length(size_type __n1, size_type __n2, const char* __s) const -: 325: { -: 326: if (this->max_size() - (this->size() - __n1) < __n2) -: 327: __throw_length_error(__N(__s)); -: 328: } -: 329: -: 330: -: 331: // NB: _M_limit doesn't check for a bad __pos value. -: 332: size_type -: 333: _M_limit(size_type __pos, size_type __off) const _GLIBCXX_NOEXCEPT -: 334: { -: 335: const bool __testoff = __off < this->size() - __pos; -: 336: return __testoff ? __off : this->size() - __pos; -: 337: } -: 338: -: 339: // True if _Rep and source do not overlap. -: 340: bool -: 341: _M_disjunct(const _CharT* __s) const _GLIBCXX_NOEXCEPT -: 342: { -: 343: return (less()(__s, _M_data()) -: 344: || less()(_M_data() + this->size(), __s)); -: 345: } -: 346: -: 347: // When __n = 1 way faster than the general multichar -: 348: // traits_type::copy/move/assign. -: 349: static void -: 350: _S_copy(_CharT* __d, const _CharT* __s, size_type __n) -: 351: { -: 352: if (__n == 1) -: 353: traits_type::assign(*__d, *__s); -: 354: else -: 355: traits_type::copy(__d, __s, __n); -: 356: } -: 357: -: 358: static void -: 359: _S_move(_CharT* __d, const _CharT* __s, size_type __n) -: 360: { -: 361: if (__n == 1) -: 362: traits_type::assign(*__d, *__s); -: 363: else -: 364: traits_type::move(__d, __s, __n); -: 365: } -: 366: -: 367: static void -: 368: _S_assign(_CharT* __d, size_type __n, _CharT __c) -: 369: { -: 370: if (__n == 1) -: 371: traits_type::assign(*__d, __c); -: 372: else -: 373: traits_type::assign(__d, __n, __c); -: 374: } -: 375: -: 376: // _S_copy_chars is a separate template to permit specialization -: 377: // to optimize for the common case of pointers as iterators. -: 378: template -: 379: static void -: 380: _S_copy_chars(_CharT* __p, _Iterator __k1, _Iterator __k2) -: 381: { -: 382: for (; __k1 != __k2; ++__k1, (void)++__p) -: 383: traits_type::assign(*__p, *__k1); // These types are off. -: 384: } -: 385: -: 386: static void -: 387: _S_copy_chars(_CharT* __p, iterator __k1, iterator __k2) _GLIBCXX_NOEXCEPT -: 388: { _S_copy_chars(__p, __k1.base(), __k2.base()); } -: 389: -: 390: static void -: 391: _S_copy_chars(_CharT* __p, const_iterator __k1, const_iterator __k2) -: 392: _GLIBCXX_NOEXCEPT -: 393: { _S_copy_chars(__p, __k1.base(), __k2.base()); } -: 394: -: 395: static void -: 396: _S_copy_chars(_CharT* __p, _CharT* __k1, _CharT* __k2) _GLIBCXX_NOEXCEPT -: 397: { _S_copy(__p, __k1, __k2 - __k1); } -: 398: -: 399: static void -: 400: _S_copy_chars(_CharT* __p, const _CharT* __k1, const _CharT* __k2) -: 401: _GLIBCXX_NOEXCEPT -: 402: { _S_copy(__p, __k1, __k2 - __k1); } -: 403: -: 404: static int -: 405: _S_compare(size_type __n1, size_type __n2) _GLIBCXX_NOEXCEPT -: 406: { -: 407: const difference_type __d = difference_type(__n1 - __n2); -: 408: -: 409: if (__d > __gnu_cxx::__numeric_traits::__max) -: 410: return __gnu_cxx::__numeric_traits::__max; -: 411: else if (__d < __gnu_cxx::__numeric_traits::__min) -: 412: return __gnu_cxx::__numeric_traits::__min; -: 413: else -: 414: return int(__d); -: 415: } -: 416: -: 417: void -: 418: _M_assign(const basic_string&); -: 419: -: 420: void -: 421: _M_mutate(size_type __pos, size_type __len1, const _CharT* __s, -: 422: size_type __len2); -: 423: -: 424: void -: 425: _M_erase(size_type __pos, size_type __n); -: 426: -: 427: public: -: 428: // Construct/copy/destroy: -: 429: // NB: We overload ctors in some cases instead of using default -: 430: // arguments, per 17.4.4.4 para. 2 item 2. -: 431: -: 432: /** -: 433: * @brief Default constructor creates an empty string. -: 434: */ -: 435: basic_string() -: 436: _GLIBCXX_NOEXCEPT_IF(is_nothrow_default_constructible<_Alloc>::value) -: 437: : _M_dataplus(_M_local_data()) -: 438: { _M_set_length(0); } -: 439: -: 440: /** -: 441: * @brief Construct an empty string using allocator @a a. -: 442: */ -: 443: explicit -: 444: basic_string(const _Alloc& __a) _GLIBCXX_NOEXCEPT -: 445: : _M_dataplus(_M_local_data(), __a) -: 446: { _M_set_length(0); } -: 447: -: 448: /** -: 449: * @brief Construct string with copy of value of @a __str. -: 450: * @param __str Source string. -: 451: */ -: 452: basic_string(const basic_string& __str) -: 453: : _M_dataplus(_M_local_data(), -: 454: _Alloc_traits::_S_select_on_copy(__str._M_get_allocator())) -: 455: { _M_construct(__str._M_data(), __str._M_data() + __str.length()); } -: 456: -: 457: // _GLIBCXX_RESOLVE_LIB_DEFECTS -: 458: // 2583. no way to supply an allocator for basic_string(str, pos) -: 459: /** -: 460: * @brief Construct string as copy of a substring. -: 461: * @param __str Source string. -: 462: * @param __pos Index of first character to copy from. -: 463: * @param __a Allocator to use. -: 464: */ -: 465: basic_string(const basic_string& __str, size_type __pos, -: 466: const _Alloc& __a = _Alloc()) -: 467: : _M_dataplus(_M_local_data(), __a) -: 468: { -: 469: const _CharT* __start = __str._M_data() -: 470: + __str._M_check(__pos, "basic_string::basic_string"); -: 471: _M_construct(__start, __start + __str._M_limit(__pos, npos)); -: 472: } -: 473: -: 474: /** -: 475: * @brief Construct string as copy of a substring. -: 476: * @param __str Source string. -: 477: * @param __pos Index of first character to copy from. -: 478: * @param __n Number of characters to copy. -: 479: */ -: 480: basic_string(const basic_string& __str, size_type __pos, -: 481: size_type __n) -: 482: : _M_dataplus(_M_local_data()) -: 483: { -: 484: const _CharT* __start = __str._M_data() -: 485: + __str._M_check(__pos, "basic_string::basic_string"); -: 486: _M_construct(__start, __start + __str._M_limit(__pos, __n)); -: 487: } -: 488: -: 489: /** -: 490: * @brief Construct string as copy of a substring. -: 491: * @param __str Source string. -: 492: * @param __pos Index of first character to copy from. -: 493: * @param __n Number of characters to copy. -: 494: * @param __a Allocator to use. -: 495: */ -: 496: basic_string(const basic_string& __str, size_type __pos, -: 497: size_type __n, const _Alloc& __a) -: 498: : _M_dataplus(_M_local_data(), __a) -: 499: { -: 500: const _CharT* __start -: 501: = __str._M_data() + __str._M_check(__pos, "string::string"); -: 502: _M_construct(__start, __start + __str._M_limit(__pos, __n)); -: 503: } -: 504: -: 505: /** -: 506: * @brief Construct string initialized by a character %array. -: 507: * @param __s Source character %array. -: 508: * @param __n Number of characters to copy. -: 509: * @param __a Allocator to use (default is default allocator). -: 510: * -: 511: * NB: @a __s must have at least @a __n characters, '\\0' -: 512: * has no special meaning. -: 513: */ -: 514: basic_string(const _CharT* __s, size_type __n, -: 515: const _Alloc& __a = _Alloc()) -: 516: : _M_dataplus(_M_local_data(), __a) -: 517: { _M_construct(__s, __s + __n); } -: 518: -: 519: /** -: 520: * @brief Construct string as copy of a C string. -: 521: * @param __s Source C string. -: 522: * @param __a Allocator to use (default is default allocator). -: 523: */ -: 524:#if __cpp_deduction_guides && ! defined _GLIBCXX_DEFINING_STRING_INSTANTIATIONS -: 525: // _GLIBCXX_RESOLVE_LIB_DEFECTS -: 526: // 3076. basic_string CTAD ambiguity -: 527: template> -: 528:#endif -: 529: basic_string(const _CharT* __s, const _Alloc& __a = _Alloc()) -: 530: : _M_dataplus(_M_local_data(), __a) -: 531: { _M_construct(__s, __s ? __s + traits_type::length(__s) : __s+npos); } -: 532: -: 533: /** -: 534: * @brief Construct string as multiple characters. -: 535: * @param __n Number of characters. -: 536: * @param __c Character to use. -: 537: * @param __a Allocator to use (default is default allocator). -: 538: */ -: 539:#if __cpp_deduction_guides && ! defined _GLIBCXX_DEFINING_STRING_INSTANTIATIONS -: 540: // _GLIBCXX_RESOLVE_LIB_DEFECTS -: 541: // 3076. basic_string CTAD ambiguity -: 542: template> -: 543:#endif -: 544: basic_string(size_type __n, _CharT __c, const _Alloc& __a = _Alloc()) -: 545: : _M_dataplus(_M_local_data(), __a) -: 546: { _M_construct(__n, __c); } -: 547: -: 548:#if __cplusplus >= 201103L -: 549: /** -: 550: * @brief Move construct string. -: 551: * @param __str Source string. -: 552: * -: 553: * The newly-created string contains the exact contents of @a __str. -: 554: * @a __str is a valid, but unspecified string. -: 555: **/ -: 556: basic_string(basic_string&& __str) noexcept -: 557: : _M_dataplus(_M_local_data(), std::move(__str._M_get_allocator())) -: 558: { -: 559: if (__str._M_is_local()) -: 560: { -: 561: traits_type::copy(_M_local_buf, __str._M_local_buf, -: 562: _S_local_capacity + 1); -: 563: } -: 564: else -: 565: { -: 566: _M_data(__str._M_data()); -: 567: _M_capacity(__str._M_allocated_capacity); -: 568: } -: 569: -: 570: // Must use _M_length() here not _M_set_length() because -: 571: // basic_stringbuf relies on writing into unallocated capacity so -: 572: // we mess up the contents if we put a '\0' in the string. -: 573: _M_length(__str.length()); -: 574: __str._M_data(__str._M_local_data()); -: 575: __str._M_set_length(0); -: 576: } -: 577: -: 578: /** -: 579: * @brief Construct string from an initializer %list. -: 580: * @param __l std::initializer_list of characters. -: 581: * @param __a Allocator to use (default is default allocator). -: 582: */ -: 583: basic_string(initializer_list<_CharT> __l, const _Alloc& __a = _Alloc()) -: 584: : _M_dataplus(_M_local_data(), __a) -: 585: { _M_construct(__l.begin(), __l.end()); } -: 586: -: 587: basic_string(const basic_string& __str, const _Alloc& __a) -: 588: : _M_dataplus(_M_local_data(), __a) -: 589: { _M_construct(__str.begin(), __str.end()); } -: 590: -: 591: basic_string(basic_string&& __str, const _Alloc& __a) -: 592: noexcept(_Alloc_traits::_S_always_equal()) -: 593: : _M_dataplus(_M_local_data(), __a) -: 594: { -: 595: if (__str._M_is_local()) -: 596: { -: 597: traits_type::copy(_M_local_buf, __str._M_local_buf, -: 598: _S_local_capacity + 1); -: 599: _M_length(__str.length()); -: 600: __str._M_set_length(0); -: 601: } -: 602: else if (_Alloc_traits::_S_always_equal() -: 603: || __str.get_allocator() == __a) -: 604: { -: 605: _M_data(__str._M_data()); -: 606: _M_length(__str.length()); -: 607: _M_capacity(__str._M_allocated_capacity); -: 608: __str._M_data(__str._M_local_buf); -: 609: __str._M_set_length(0); -: 610: } -: 611: else -: 612: _M_construct(__str.begin(), __str.end()); -: 613: } -: 614: -: 615:#endif // C++11 -: 616: -: 617: /** -: 618: * @brief Construct string as copy of a range. -: 619: * @param __beg Start of range. -: 620: * @param __end End of range. -: 621: * @param __a Allocator to use (default is default allocator). -: 622: */ -: 623:#if __cplusplus >= 201103L -: 624: template> -: 626:#else -: 627: template -: 628:#endif -: 629: basic_string(_InputIterator __beg, _InputIterator __end, -: 630: const _Alloc& __a = _Alloc()) -: 631: : _M_dataplus(_M_local_data(), __a) -: 632: { _M_construct(__beg, __end); } -: 633: -: 634:#if __cplusplus >= 201703L -: 635: /** -: 636: * @brief Construct string from a substring of a string_view. -: 637: * @param __t Source object convertible to string view. -: 638: * @param __pos The index of the first character to copy from __t. -: 639: * @param __n The number of characters to copy from __t. -: 640: * @param __a Allocator to use. -: 641: */ -: 642: template> -: 643: basic_string(const _Tp& __t, size_type __pos, size_type __n, -: 644: const _Alloc& __a = _Alloc()) -: 645: : basic_string(_S_to_string_view(__t).substr(__pos, __n), __a) { } -: 646: -: 647: /** -: 648: * @brief Construct string from a string_view. -: 649: * @param __t Source object convertible to string view. -: 650: * @param __a Allocator to use (default is default allocator). -: 651: */ -: 652: template> -: 653: explicit -: 654: basic_string(const _Tp& __t, const _Alloc& __a = _Alloc()) -: 655: : basic_string(__sv_wrapper(_S_to_string_view(__t)), __a) { } -: 656:#endif // C++17 -: 657: -: 658: /** -: 659: * @brief Destroy the string instance. -: 660: */ -: 661: ~basic_string() -: 662: { _M_dispose(); } -: 663: -: 664: /** -: 665: * @brief Assign the value of @a str to this string. -: 666: * @param __str Source string. -: 667: */ -: 668: basic_string& -: 669: operator=(const basic_string& __str) -: 670: { -: 671:#if __cplusplus >= 201103L -: 672: if (_Alloc_traits::_S_propagate_on_copy_assign()) -: 673: { -: 674: if (!_Alloc_traits::_S_always_equal() && !_M_is_local() -: 675: && _M_get_allocator() != __str._M_get_allocator()) -: 676: { -: 677: // Propagating allocator cannot free existing storage so must -: 678: // deallocate it before replacing current allocator. -: 679: if (__str.size() <= _S_local_capacity) -: 680: { -: 681: _M_destroy(_M_allocated_capacity); -: 682: _M_data(_M_local_data()); -: 683: _M_set_length(0); -: 684: } -: 685: else -: 686: { -: 687: const auto __len = __str.size(); -: 688: auto __alloc = __str._M_get_allocator(); -: 689: // If this allocation throws there are no effects: -: 690: auto __ptr = _Alloc_traits::allocate(__alloc, __len + 1); -: 691: _M_destroy(_M_allocated_capacity); -: 692: _M_data(__ptr); -: 693: _M_capacity(__len); -: 694: _M_set_length(__len); -: 695: } -: 696: } -: 697: std::__alloc_on_copy(_M_get_allocator(), __str._M_get_allocator()); -: 698: } -: 699:#endif -: 700: return this->assign(__str); -: 701: } -: 702: -: 703: /** -: 704: * @brief Copy contents of @a s into this string. -: 705: * @param __s Source null-terminated string. -: 706: */ -: 707: basic_string& -: 708: operator=(const _CharT* __s) -: 709: { return this->assign(__s); } -: 710: -: 711: /** -: 712: * @brief Set value to string of length 1. -: 713: * @param __c Source character. -: 714: * -: 715: * Assigning to a character makes this string length 1 and -: 716: * (*this)[0] == @a c. -: 717: */ -: 718: basic_string& -: 719: operator=(_CharT __c) -: 720: { -: 721: this->assign(1, __c); -: 722: return *this; -: 723: } -: 724: -: 725:#if __cplusplus >= 201103L -: 726: /** -: 727: * @brief Move assign the value of @a str to this string. -: 728: * @param __str Source string. -: 729: * -: 730: * The contents of @a str are moved into this string (without copying). -: 731: * @a str is a valid, but unspecified string. -: 732: **/ -: 733: // _GLIBCXX_RESOLVE_LIB_DEFECTS -: 734: // 2063. Contradictory requirements for string move assignment -: 735: basic_string& -: 736: operator=(basic_string&& __str) -: 737: noexcept(_Alloc_traits::_S_nothrow_move()) -: 738: { -: 739: if (!_M_is_local() && _Alloc_traits::_S_propagate_on_move_assign() -: 740: && !_Alloc_traits::_S_always_equal() -: 741: && _M_get_allocator() != __str._M_get_allocator()) -: 742: { -: 743: // Destroy existing storage before replacing allocator. -: 744: _M_destroy(_M_allocated_capacity); -: 745: _M_data(_M_local_data()); -: 746: _M_set_length(0); -: 747: } -: 748: // Replace allocator if POCMA is true. -: 749: std::__alloc_on_move(_M_get_allocator(), __str._M_get_allocator()); -: 750: -: 751: if (__str._M_is_local()) -: 752: { -: 753: // We've always got room for a short string, just copy it. -: 754: if (__str.size()) -: 755: this->_S_copy(_M_data(), __str._M_data(), __str.size()); -: 756: _M_set_length(__str.size()); -: 757: } -: 758: else if (_Alloc_traits::_S_propagate_on_move_assign() -: 759: || _Alloc_traits::_S_always_equal() -: 760: || _M_get_allocator() == __str._M_get_allocator()) -: 761: { -: 762: // Just move the allocated pointer, our allocator can free it. -: 763: pointer __data = nullptr; -: 764: size_type __capacity; -: 765: if (!_M_is_local()) -: 766: { -: 767: if (_Alloc_traits::_S_always_equal()) -: 768: { -: 769: // __str can reuse our existing storage. -: 770: __data = _M_data(); -: 771: __capacity = _M_allocated_capacity; -: 772: } -: 773: else // __str can't use it, so free it. -: 774: _M_destroy(_M_allocated_capacity); -: 775: } -: 776: -: 777: _M_data(__str._M_data()); -: 778: _M_length(__str.length()); -: 779: _M_capacity(__str._M_allocated_capacity); -: 780: if (__data) -: 781: { -: 782: __str._M_data(__data); -: 783: __str._M_capacity(__capacity); -: 784: } -: 785: else -: 786: __str._M_data(__str._M_local_buf); -: 787: } -: 788: else // Need to do a deep copy -: 789: assign(__str); -: 790: __str.clear(); -: 791: return *this; -: 792: } -: 793: -: 794: /** -: 795: * @brief Set value to string constructed from initializer %list. -: 796: * @param __l std::initializer_list. -: 797: */ -: 798: basic_string& -: 799: operator=(initializer_list<_CharT> __l) -: 800: { -: 801: this->assign(__l.begin(), __l.size()); -: 802: return *this; -: 803: } -: 804:#endif // C++11 -: 805: -: 806:#if __cplusplus >= 201703L -: 807: /** -: 808: * @brief Set value to string constructed from a string_view. -: 809: * @param __svt An object convertible to string_view. -: 810: */ -: 811: template -: 812: _If_sv<_Tp, basic_string&> -: 813: operator=(const _Tp& __svt) -: 814: { return this->assign(__svt); } -: 815: -: 816: /** -: 817: * @brief Convert to a string_view. -: 818: * @return A string_view. -: 819: */ -: 820: operator __sv_type() const noexcept -: 821: { return __sv_type(data(), size()); } -: 822:#endif // C++17 -: 823: -: 824: // Iterators: -: 825: /** -: 826: * Returns a read/write iterator that points to the first character in -: 827: * the %string. -: 828: */ -: 829: iterator -: 830: begin() _GLIBCXX_NOEXCEPT -: 831: { return iterator(_M_data()); } -: 832: -: 833: /** -: 834: * Returns a read-only (constant) iterator that points to the first -: 835: * character in the %string. -: 836: */ -: 837: const_iterator -: 838: begin() const _GLIBCXX_NOEXCEPT -: 839: { return const_iterator(_M_data()); } -: 840: -: 841: /** -: 842: * Returns a read/write iterator that points one past the last -: 843: * character in the %string. -: 844: */ -: 845: iterator -: 846: end() _GLIBCXX_NOEXCEPT -: 847: { return iterator(_M_data() + this->size()); } -: 848: -: 849: /** -: 850: * Returns a read-only (constant) iterator that points one past the -: 851: * last character in the %string. -: 852: */ -: 853: const_iterator -: 854: end() const _GLIBCXX_NOEXCEPT -: 855: { return const_iterator(_M_data() + this->size()); } -: 856: -: 857: /** -: 858: * Returns a read/write reverse iterator that points to the last -: 859: * character in the %string. Iteration is done in reverse element -: 860: * order. -: 861: */ -: 862: reverse_iterator -: 863: rbegin() _GLIBCXX_NOEXCEPT -: 864: { return reverse_iterator(this->end()); } -: 865: -: 866: /** -: 867: * Returns a read-only (constant) reverse iterator that points -: 868: * to the last character in the %string. Iteration is done in -: 869: * reverse element order. -: 870: */ -: 871: const_reverse_iterator -: 872: rbegin() const _GLIBCXX_NOEXCEPT -: 873: { return const_reverse_iterator(this->end()); } -: 874: -: 875: /** -: 876: * Returns a read/write reverse iterator that points to one before the -: 877: * first character in the %string. Iteration is done in reverse -: 878: * element order. -: 879: */ -: 880: reverse_iterator -: 881: rend() _GLIBCXX_NOEXCEPT -: 882: { return reverse_iterator(this->begin()); } -: 883: -: 884: /** -: 885: * Returns a read-only (constant) reverse iterator that points -: 886: * to one before the first character in the %string. Iteration -: 887: * is done in reverse element order. -: 888: */ -: 889: const_reverse_iterator -: 890: rend() const _GLIBCXX_NOEXCEPT -: 891: { return const_reverse_iterator(this->begin()); } -: 892: -: 893:#if __cplusplus >= 201103L -: 894: /** -: 895: * Returns a read-only (constant) iterator that points to the first -: 896: * character in the %string. -: 897: */ -: 898: const_iterator -: 899: cbegin() const noexcept -: 900: { return const_iterator(this->_M_data()); } -: 901: -: 902: /** -: 903: * Returns a read-only (constant) iterator that points one past the -: 904: * last character in the %string. -: 905: */ -: 906: const_iterator -: 907: cend() const noexcept -: 908: { return const_iterator(this->_M_data() + this->size()); } -: 909: -: 910: /** -: 911: * Returns a read-only (constant) reverse iterator that points -: 912: * to the last character in the %string. Iteration is done in -: 913: * reverse element order. -: 914: */ -: 915: const_reverse_iterator -: 916: crbegin() const noexcept -: 917: { return const_reverse_iterator(this->end()); } -: 918: -: 919: /** -: 920: * Returns a read-only (constant) reverse iterator that points -: 921: * to one before the first character in the %string. Iteration -: 922: * is done in reverse element order. -: 923: */ -: 924: const_reverse_iterator -: 925: crend() const noexcept -: 926: { return const_reverse_iterator(this->begin()); } -: 927:#endif -: 928: -: 929: public: -: 930: // Capacity: -: 931: /// Returns the number of characters in the string, not including any -: 932: /// null-termination. -: 933: size_type -: 934: size() const _GLIBCXX_NOEXCEPT -: 935: { return _M_string_length; } -: 936: -: 937: /// Returns the number of characters in the string, not including any -: 938: /// null-termination. -: 939: size_type -: 940: length() const _GLIBCXX_NOEXCEPT -: 941: { return _M_string_length; } -: 942: -: 943: /// Returns the size() of the largest possible %string. -: 944: size_type -: 945: max_size() const _GLIBCXX_NOEXCEPT -: 946: { return (_Alloc_traits::max_size(_M_get_allocator()) - 1) / 2; } -: 947: -: 948: /** -: 949: * @brief Resizes the %string to the specified number of characters. -: 950: * @param __n Number of characters the %string should contain. -: 951: * @param __c Character to fill any new elements. -: 952: * -: 953: * This function will %resize the %string to the specified -: 954: * number of characters. If the number is smaller than the -: 955: * %string's current size the %string is truncated, otherwise -: 956: * the %string is extended and new elements are %set to @a __c. -: 957: */ -: 958: void -: 959: resize(size_type __n, _CharT __c); -: 960: -: 961: /** -: 962: * @brief Resizes the %string to the specified number of characters. -: 963: * @param __n Number of characters the %string should contain. -: 964: * -: 965: * This function will resize the %string to the specified length. If -: 966: * the new size is smaller than the %string's current size the %string -: 967: * is truncated, otherwise the %string is extended and new characters -: 968: * are default-constructed. For basic types such as char, this means -: 969: * setting them to 0. -: 970: */ -: 971: void -: 972: resize(size_type __n) -: 973: { this->resize(__n, _CharT()); } -: 974: -: 975:#if __cplusplus >= 201103L -: 976: /// A non-binding request to reduce capacity() to size(). -: 977: void -: 978: shrink_to_fit() noexcept -: 979: { -: 980:#if __cpp_exceptions -: 981: if (capacity() > size()) -: 982: { -: 983: try -: 984: { reserve(0); } -: 985: catch(...) -: 986: { } -: 987: } -: 988:#endif -: 989: } -: 990:#endif -: 991: -: 992: /** -: 993: * Returns the total number of characters that the %string can hold -: 994: * before needing to allocate more memory. -: 995: */ -: 996: size_type -: 997: capacity() const _GLIBCXX_NOEXCEPT -: 998: { -: 999: return _M_is_local() ? size_type(_S_local_capacity) -: 1000: : _M_allocated_capacity; -: 1001: } -: 1002: -: 1003: /** -: 1004: * @brief Attempt to preallocate enough memory for specified number of -: 1005: * characters. -: 1006: * @param __res_arg Number of characters required. -: 1007: * @throw std::length_error If @a __res_arg exceeds @c max_size(). -: 1008: * -: 1009: * This function attempts to reserve enough memory for the -: 1010: * %string to hold the specified number of characters. If the -: 1011: * number requested is more than max_size(), length_error is -: 1012: * thrown. -: 1013: * -: 1014: * The advantage of this function is that if optimal code is a -: 1015: * necessity and the user can determine the string length that will be -: 1016: * required, the user can reserve the memory in %advance, and thus -: 1017: * prevent a possible reallocation of memory and copying of %string -: 1018: * data. -: 1019: */ -: 1020: void -: 1021: reserve(size_type __res_arg = 0); -: 1022: -: 1023: /** -: 1024: * Erases the string, making it empty. -: 1025: */ -: 1026: void -: 1027: clear() _GLIBCXX_NOEXCEPT -: 1028: { _M_set_length(0); } -: 1029: -: 1030: /** -: 1031: * Returns true if the %string is empty. Equivalent to -: 1032: * *this == "". -: 1033: */ -: 1034: _GLIBCXX_NODISCARD bool -: 1035: empty() const _GLIBCXX_NOEXCEPT -: 1036: { return this->size() == 0; } -: 1037: -: 1038: // Element access: -: 1039: /** -: 1040: * @brief Subscript access to the data contained in the %string. -: 1041: * @param __pos The index of the character to access. -: 1042: * @return Read-only (constant) reference to the character. -: 1043: * -: 1044: * This operator allows for easy, array-style, data access. -: 1045: * Note that data access with this operator is unchecked and -: 1046: * out_of_range lookups are not defined. (For checked lookups -: 1047: * see at().) -: 1048: */ -: 1049: const_reference -: 1050: operator[] (size_type __pos) const _GLIBCXX_NOEXCEPT -: 1051: { -: 1052: __glibcxx_assert(__pos <= size()); -: 1053: return _M_data()[__pos]; -: 1054: } -: 1055: -: 1056: /** -: 1057: * @brief Subscript access to the data contained in the %string. -: 1058: * @param __pos The index of the character to access. -: 1059: * @return Read/write reference to the character. -: 1060: * -: 1061: * This operator allows for easy, array-style, data access. -: 1062: * Note that data access with this operator is unchecked and -: 1063: * out_of_range lookups are not defined. (For checked lookups -: 1064: * see at().) -: 1065: */ -: 1066: reference -: 1067: operator[](size_type __pos) -: 1068: { -: 1069: // Allow pos == size() both in C++98 mode, as v3 extension, -: 1070: // and in C++11 mode. -: 1071: __glibcxx_assert(__pos <= size()); -: 1072: // In pedantic mode be strict in C++98 mode. -: 1073: _GLIBCXX_DEBUG_PEDASSERT(__cplusplus >= 201103L || __pos < size()); -: 1074: return _M_data()[__pos]; -: 1075: } -: 1076: -: 1077: /** -: 1078: * @brief Provides access to the data contained in the %string. -: 1079: * @param __n The index of the character to access. -: 1080: * @return Read-only (const) reference to the character. -: 1081: * @throw std::out_of_range If @a n is an invalid index. -: 1082: * -: 1083: * This function provides for safer data access. The parameter is -: 1084: * first checked that it is in the range of the string. The function -: 1085: * throws out_of_range if the check fails. -: 1086: */ -: 1087: const_reference -: 1088: at(size_type __n) const -: 1089: { -: 1090: if (__n >= this->size()) -: 1091: __throw_out_of_range_fmt(__N("basic_string::at: __n " -: 1092: "(which is %zu) >= this->size() " -: 1093: "(which is %zu)"), -: 1094: __n, this->size()); -: 1095: return _M_data()[__n]; -: 1096: } -: 1097: -: 1098: /** -: 1099: * @brief Provides access to the data contained in the %string. -: 1100: * @param __n The index of the character to access. -: 1101: * @return Read/write reference to the character. -: 1102: * @throw std::out_of_range If @a n is an invalid index. -: 1103: * -: 1104: * This function provides for safer data access. The parameter is -: 1105: * first checked that it is in the range of the string. The function -: 1106: * throws out_of_range if the check fails. -: 1107: */ -: 1108: reference -: 1109: at(size_type __n) -: 1110: { -: 1111: if (__n >= size()) -: 1112: __throw_out_of_range_fmt(__N("basic_string::at: __n " -: 1113: "(which is %zu) >= this->size() " -: 1114: "(which is %zu)"), -: 1115: __n, this->size()); -: 1116: return _M_data()[__n]; -: 1117: } -: 1118: -: 1119:#if __cplusplus >= 201103L -: 1120: /** -: 1121: * Returns a read/write reference to the data at the first -: 1122: * element of the %string. -: 1123: */ -: 1124: reference -: 1125: front() noexcept -: 1126: { -: 1127: __glibcxx_assert(!empty()); -: 1128: return operator[](0); -: 1129: } -: 1130: -: 1131: /** -: 1132: * Returns a read-only (constant) reference to the data at the first -: 1133: * element of the %string. -: 1134: */ -: 1135: const_reference -: 1136: front() const noexcept -: 1137: { -: 1138: __glibcxx_assert(!empty()); -: 1139: return operator[](0); -: 1140: } -: 1141: -: 1142: /** -: 1143: * Returns a read/write reference to the data at the last -: 1144: * element of the %string. -: 1145: */ -: 1146: reference -: 1147: back() noexcept -: 1148: { -: 1149: __glibcxx_assert(!empty()); -: 1150: return operator[](this->size() - 1); -: 1151: } -: 1152: -: 1153: /** -: 1154: * Returns a read-only (constant) reference to the data at the -: 1155: * last element of the %string. -: 1156: */ -: 1157: const_reference -: 1158: back() const noexcept -: 1159: { -: 1160: __glibcxx_assert(!empty()); -: 1161: return operator[](this->size() - 1); -: 1162: } -: 1163:#endif -: 1164: -: 1165: // Modifiers: -: 1166: /** -: 1167: * @brief Append a string to this string. -: 1168: * @param __str The string to append. -: 1169: * @return Reference to this string. -: 1170: */ -: 1171: basic_string& -: 1172: operator+=(const basic_string& __str) -: 1173: { return this->append(__str); } -: 1174: -: 1175: /** -: 1176: * @brief Append a C string. -: 1177: * @param __s The C string to append. -: 1178: * @return Reference to this string. -: 1179: */ -: 1180: basic_string& -: 1181: operator+=(const _CharT* __s) -: 1182: { return this->append(__s); } -: 1183: -: 1184: /** -: 1185: * @brief Append a character. -: 1186: * @param __c The character to append. -: 1187: * @return Reference to this string. -: 1188: */ -: 1189: basic_string& -: 1190: operator+=(_CharT __c) -: 1191: { -: 1192: this->push_back(__c); -: 1193: return *this; -: 1194: } -: 1195: -: 1196:#if __cplusplus >= 201103L -: 1197: /** -: 1198: * @brief Append an initializer_list of characters. -: 1199: * @param __l The initializer_list of characters to be appended. -: 1200: * @return Reference to this string. -: 1201: */ -: 1202: basic_string& -: 1203: operator+=(initializer_list<_CharT> __l) -: 1204: { return this->append(__l.begin(), __l.size()); } -: 1205:#endif // C++11 -: 1206: -: 1207:#if __cplusplus >= 201703L -: 1208: /** -: 1209: * @brief Append a string_view. -: 1210: * @param __svt An object convertible to string_view to be appended. -: 1211: * @return Reference to this string. -: 1212: */ -: 1213: template -: 1214: _If_sv<_Tp, basic_string&> -: 1215: operator+=(const _Tp& __svt) -: 1216: { return this->append(__svt); } -: 1217:#endif // C++17 -: 1218: -: 1219: /** -: 1220: * @brief Append a string to this string. -: 1221: * @param __str The string to append. -: 1222: * @return Reference to this string. -: 1223: */ -: 1224: basic_string& -: 1225: append(const basic_string& __str) -: 1226: { return _M_append(__str._M_data(), __str.size()); } -: 1227: -: 1228: /** -: 1229: * @brief Append a substring. -: 1230: * @param __str The string to append. -: 1231: * @param __pos Index of the first character of str to append. -: 1232: * @param __n The number of characters to append. -: 1233: * @return Reference to this string. -: 1234: * @throw std::out_of_range if @a __pos is not a valid index. -: 1235: * -: 1236: * This function appends @a __n characters from @a __str -: 1237: * starting at @a __pos to this string. If @a __n is is larger -: 1238: * than the number of available characters in @a __str, the -: 1239: * remainder of @a __str is appended. -: 1240: */ -: 1241: basic_string& -: 1242: append(const basic_string& __str, size_type __pos, size_type __n = npos) -: 1243: { return _M_append(__str._M_data() -: 1244: + __str._M_check(__pos, "basic_string::append"), -: 1245: __str._M_limit(__pos, __n)); } -: 1246: -: 1247: /** -: 1248: * @brief Append a C substring. -: 1249: * @param __s The C string to append. -: 1250: * @param __n The number of characters to append. -: 1251: * @return Reference to this string. -: 1252: */ -: 1253: basic_string& -: 1254: append(const _CharT* __s, size_type __n) -: 1255: { -: 1256: __glibcxx_requires_string_len(__s, __n); -: 1257: _M_check_length(size_type(0), __n, "basic_string::append"); -: 1258: return _M_append(__s, __n); -: 1259: } -: 1260: -: 1261: /** -: 1262: * @brief Append a C string. -: 1263: * @param __s The C string to append. -: 1264: * @return Reference to this string. -: 1265: */ -: 1266: basic_string& -: 1267: append(const _CharT* __s) -: 1268: { -: 1269: __glibcxx_requires_string(__s); -: 1270: const size_type __n = traits_type::length(__s); -: 1271: _M_check_length(size_type(0), __n, "basic_string::append"); -: 1272: return _M_append(__s, __n); -: 1273: } -: 1274: -: 1275: /** -: 1276: * @brief Append multiple characters. -: 1277: * @param __n The number of characters to append. -: 1278: * @param __c The character to use. -: 1279: * @return Reference to this string. -: 1280: * -: 1281: * Appends __n copies of __c to this string. -: 1282: */ -: 1283: basic_string& -: 1284: append(size_type __n, _CharT __c) -: 1285: { return _M_replace_aux(this->size(), size_type(0), __n, __c); } -: 1286: -: 1287:#if __cplusplus >= 201103L -: 1288: /** -: 1289: * @brief Append an initializer_list of characters. -: 1290: * @param __l The initializer_list of characters to append. -: 1291: * @return Reference to this string. -: 1292: */ -: 1293: basic_string& -: 1294: append(initializer_list<_CharT> __l) -: 1295: { return this->append(__l.begin(), __l.size()); } -: 1296:#endif // C++11 -: 1297: -: 1298: /** -: 1299: * @brief Append a range of characters. -: 1300: * @param __first Iterator referencing the first character to append. -: 1301: * @param __last Iterator marking the end of the range. -: 1302: * @return Reference to this string. -: 1303: * -: 1304: * Appends characters in the range [__first,__last) to this string. -: 1305: */ -: 1306:#if __cplusplus >= 201103L -: 1307: template> -: 1309:#else -: 1310: template -: 1311:#endif -: 1312: basic_string& -: 1313: append(_InputIterator __first, _InputIterator __last) -: 1314: { return this->replace(end(), end(), __first, __last); } -: 1315: -: 1316:#if __cplusplus >= 201703L -: 1317: /** -: 1318: * @brief Append a string_view. -: 1319: * @param __svt An object convertible to string_view to be appended. -: 1320: * @return Reference to this string. -: 1321: */ -: 1322: template -: 1323: _If_sv<_Tp, basic_string&> -: 1324: append(const _Tp& __svt) -: 1325: { -: 1326: __sv_type __sv = __svt; -: 1327: return this->append(__sv.data(), __sv.size()); -: 1328: } -: 1329: -: 1330: /** -: 1331: * @brief Append a range of characters from a string_view. -: 1332: * @param __svt An object convertible to string_view to be appended from. -: 1333: * @param __pos The position in the string_view to append from. -: 1334: * @param __n The number of characters to append from the string_view. -: 1335: * @return Reference to this string. -: 1336: */ -: 1337: template -: 1338: _If_sv<_Tp, basic_string&> -: 1339: append(const _Tp& __svt, size_type __pos, size_type __n = npos) -: 1340: { -: 1341: __sv_type __sv = __svt; -: 1342: return _M_append(__sv.data() -: 1343: + std::__sv_check(__sv.size(), __pos, "basic_string::append"), -: 1344: std::__sv_limit(__sv.size(), __pos, __n)); -: 1345: } -: 1346:#endif // C++17 -: 1347: -: 1348: /** -: 1349: * @brief Append a single character. -: 1350: * @param __c Character to append. -: 1351: */ -: 1352: void -: 1353: push_back(_CharT __c) -: 1354: { -: 1355: const size_type __size = this->size(); -: 1356: if (__size + 1 > this->capacity()) -: 1357: this->_M_mutate(__size, size_type(0), 0, size_type(1)); -: 1358: traits_type::assign(this->_M_data()[__size], __c); -: 1359: this->_M_set_length(__size + 1); -: 1360: } -: 1361: -: 1362: /** -: 1363: * @brief Set value to contents of another string. -: 1364: * @param __str Source string to use. -: 1365: * @return Reference to this string. -: 1366: */ -: 1367: basic_string& -: 1368: assign(const basic_string& __str) -: 1369: { -: 1370: this->_M_assign(__str); -: 1371: return *this; -: 1372: } -: 1373: -: 1374:#if __cplusplus >= 201103L -: 1375: /** -: 1376: * @brief Set value to contents of another string. -: 1377: * @param __str Source string to use. -: 1378: * @return Reference to this string. -: 1379: * -: 1380: * This function sets this string to the exact contents of @a __str. -: 1381: * @a __str is a valid, but unspecified string. -: 1382: */ -: 1383: basic_string& -: 1384: assign(basic_string&& __str) -: 1385: noexcept(_Alloc_traits::_S_nothrow_move()) -: 1386: { -: 1387: // _GLIBCXX_RESOLVE_LIB_DEFECTS -: 1388: // 2063. Contradictory requirements for string move assignment -: 1389: return *this = std::move(__str); -: 1390: } -: 1391:#endif // C++11 -: 1392: -: 1393: /** -: 1394: * @brief Set value to a substring of a string. -: 1395: * @param __str The string to use. -: 1396: * @param __pos Index of the first character of str. -: 1397: * @param __n Number of characters to use. -: 1398: * @return Reference to this string. -: 1399: * @throw std::out_of_range if @a pos is not a valid index. -: 1400: * -: 1401: * This function sets this string to the substring of @a __str -: 1402: * consisting of @a __n characters at @a __pos. If @a __n is -: 1403: * is larger than the number of available characters in @a -: 1404: * __str, the remainder of @a __str is used. -: 1405: */ -: 1406: basic_string& -: 1407: assign(const basic_string& __str, size_type __pos, size_type __n = npos) -: 1408: { return _M_replace(size_type(0), this->size(), __str._M_data() -: 1409: + __str._M_check(__pos, "basic_string::assign"), -: 1410: __str._M_limit(__pos, __n)); } -: 1411: -: 1412: /** -: 1413: * @brief Set value to a C substring. -: 1414: * @param __s The C string to use. -: 1415: * @param __n Number of characters to use. -: 1416: * @return Reference to this string. -: 1417: * -: 1418: * This function sets the value of this string to the first @a __n -: 1419: * characters of @a __s. If @a __n is is larger than the number of -: 1420: * available characters in @a __s, the remainder of @a __s is used. -: 1421: */ -: 1422: basic_string& -: 1423: assign(const _CharT* __s, size_type __n) -: 1424: { -: 1425: __glibcxx_requires_string_len(__s, __n); -: 1426: return _M_replace(size_type(0), this->size(), __s, __n); -: 1427: } -: 1428: -: 1429: /** -: 1430: * @brief Set value to contents of a C string. -: 1431: * @param __s The C string to use. -: 1432: * @return Reference to this string. -: 1433: * -: 1434: * This function sets the value of this string to the value of @a __s. -: 1435: * The data is copied, so there is no dependence on @a __s once the -: 1436: * function returns. -: 1437: */ -: 1438: basic_string& -: 1439: assign(const _CharT* __s) -: 1440: { -: 1441: __glibcxx_requires_string(__s); -: 1442: return _M_replace(size_type(0), this->size(), __s, -: 1443: traits_type::length(__s)); -: 1444: } -: 1445: -: 1446: /** -: 1447: * @brief Set value to multiple characters. -: 1448: * @param __n Length of the resulting string. -: 1449: * @param __c The character to use. -: 1450: * @return Reference to this string. -: 1451: * -: 1452: * This function sets the value of this string to @a __n copies of -: 1453: * character @a __c. -: 1454: */ -: 1455: basic_string& -: 1456: assign(size_type __n, _CharT __c) -: 1457: { return _M_replace_aux(size_type(0), this->size(), __n, __c); } -: 1458: -: 1459: /** -: 1460: * @brief Set value to a range of characters. -: 1461: * @param __first Iterator referencing the first character to append. -: 1462: * @param __last Iterator marking the end of the range. -: 1463: * @return Reference to this string. -: 1464: * -: 1465: * Sets value of string to characters in the range [__first,__last). -: 1466: */ -: 1467:#if __cplusplus >= 201103L -: 1468: template> -: 1470:#else -: 1471: template -: 1472:#endif -: 1473: basic_string& -: 1474: assign(_InputIterator __first, _InputIterator __last) -: 1475: { return this->replace(begin(), end(), __first, __last); } -: 1476: -: 1477:#if __cplusplus >= 201103L -: 1478: /** -: 1479: * @brief Set value to an initializer_list of characters. -: 1480: * @param __l The initializer_list of characters to assign. -: 1481: * @return Reference to this string. -: 1482: */ -: 1483: basic_string& -: 1484: assign(initializer_list<_CharT> __l) -: 1485: { return this->assign(__l.begin(), __l.size()); } -: 1486:#endif // C++11 -: 1487: -: 1488:#if __cplusplus >= 201703L -: 1489: /** -: 1490: * @brief Set value from a string_view. -: 1491: * @param __svt The source object convertible to string_view. -: 1492: * @return Reference to this string. -: 1493: */ -: 1494: template -: 1495: _If_sv<_Tp, basic_string&> -: 1496: assign(const _Tp& __svt) -: 1497: { -: 1498: __sv_type __sv = __svt; -: 1499: return this->assign(__sv.data(), __sv.size()); -: 1500: } -: 1501: -: 1502: /** -: 1503: * @brief Set value from a range of characters in a string_view. -: 1504: * @param __svt The source object convertible to string_view. -: 1505: * @param __pos The position in the string_view to assign from. -: 1506: * @param __n The number of characters to assign. -: 1507: * @return Reference to this string. -: 1508: */ -: 1509: template -: 1510: _If_sv<_Tp, basic_string&> -: 1511: assign(const _Tp& __svt, size_type __pos, size_type __n = npos) -: 1512: { -: 1513: __sv_type __sv = __svt; -: 1514: return _M_replace(size_type(0), this->size(), -: 1515: __sv.data() -: 1516: + std::__sv_check(__sv.size(), __pos, "basic_string::assign"), -: 1517: std::__sv_limit(__sv.size(), __pos, __n)); -: 1518: } -: 1519:#endif // C++17 -: 1520: -: 1521:#if __cplusplus >= 201103L -: 1522: /** -: 1523: * @brief Insert multiple characters. -: 1524: * @param __p Const_iterator referencing location in string to -: 1525: * insert at. -: 1526: * @param __n Number of characters to insert -: 1527: * @param __c The character to insert. -: 1528: * @return Iterator referencing the first inserted char. -: 1529: * @throw std::length_error If new length exceeds @c max_size(). -: 1530: * -: 1531: * Inserts @a __n copies of character @a __c starting at the -: 1532: * position referenced by iterator @a __p. If adding -: 1533: * characters causes the length to exceed max_size(), -: 1534: * length_error is thrown. The value of the string doesn't -: 1535: * change if an error is thrown. -: 1536: */ -: 1537: iterator -: 1538: insert(const_iterator __p, size_type __n, _CharT __c) -: 1539: { -: 1540: _GLIBCXX_DEBUG_PEDASSERT(__p >= begin() && __p <= end()); -: 1541: const size_type __pos = __p - begin(); -: 1542: this->replace(__p, __p, __n, __c); -: 1543: return iterator(this->_M_data() + __pos); -: 1544: } -: 1545:#else -: 1546: /** -: 1547: * @brief Insert multiple characters. -: 1548: * @param __p Iterator referencing location in string to insert at. -: 1549: * @param __n Number of characters to insert -: 1550: * @param __c The character to insert. -: 1551: * @throw std::length_error If new length exceeds @c max_size(). -: 1552: * -: 1553: * Inserts @a __n copies of character @a __c starting at the -: 1554: * position referenced by iterator @a __p. If adding -: 1555: * characters causes the length to exceed max_size(), -: 1556: * length_error is thrown. The value of the string doesn't -: 1557: * change if an error is thrown. -: 1558: */ -: 1559: void -: 1560: insert(iterator __p, size_type __n, _CharT __c) -: 1561: { this->replace(__p, __p, __n, __c); } -: 1562:#endif -: 1563: -: 1564:#if __cplusplus >= 201103L -: 1565: /** -: 1566: * @brief Insert a range of characters. -: 1567: * @param __p Const_iterator referencing location in string to -: 1568: * insert at. -: 1569: * @param __beg Start of range. -: 1570: * @param __end End of range. -: 1571: * @return Iterator referencing the first inserted char. -: 1572: * @throw std::length_error If new length exceeds @c max_size(). -: 1573: * -: 1574: * Inserts characters in range [beg,end). If adding characters -: 1575: * causes the length to exceed max_size(), length_error is -: 1576: * thrown. The value of the string doesn't change if an error -: 1577: * is thrown. -: 1578: */ -: 1579: template> -: 1581: iterator -: 1582: insert(const_iterator __p, _InputIterator __beg, _InputIterator __end) -: 1583: { -: 1584: _GLIBCXX_DEBUG_PEDASSERT(__p >= begin() && __p <= end()); -: 1585: const size_type __pos = __p - begin(); -: 1586: this->replace(__p, __p, __beg, __end); -: 1587: return iterator(this->_M_data() + __pos); -: 1588: } -: 1589:#else -: 1590: /** -: 1591: * @brief Insert a range of characters. -: 1592: * @param __p Iterator referencing location in string to insert at. -: 1593: * @param __beg Start of range. -: 1594: * @param __end End of range. -: 1595: * @throw std::length_error If new length exceeds @c max_size(). -: 1596: * -: 1597: * Inserts characters in range [__beg,__end). If adding -: 1598: * characters causes the length to exceed max_size(), -: 1599: * length_error is thrown. The value of the string doesn't -: 1600: * change if an error is thrown. -: 1601: */ -: 1602: template -: 1603: void -: 1604: insert(iterator __p, _InputIterator __beg, _InputIterator __end) -: 1605: { this->replace(__p, __p, __beg, __end); } -: 1606:#endif -: 1607: -: 1608:#if __cplusplus >= 201103L -: 1609: /** -: 1610: * @brief Insert an initializer_list of characters. -: 1611: * @param __p Iterator referencing location in string to insert at. -: 1612: * @param __l The initializer_list of characters to insert. -: 1613: * @throw std::length_error If new length exceeds @c max_size(). -: 1614: */ -: 1615: iterator -: 1616: insert(const_iterator __p, initializer_list<_CharT> __l) -: 1617: { return this->insert(__p, __l.begin(), __l.end()); } -: 1618: -: 1619:#ifdef _GLIBCXX_DEFINING_STRING_INSTANTIATIONS -: 1620: // See PR libstdc++/83328 -: 1621: void -: 1622: insert(iterator __p, initializer_list<_CharT> __l) -: 1623: { -: 1624: _GLIBCXX_DEBUG_PEDASSERT(__p >= begin() && __p <= end()); -: 1625: this->insert(__p - begin(), __l.begin(), __l.size()); -: 1626: } -: 1627:#endif -: 1628:#endif // C++11 -: 1629: -: 1630: /** -: 1631: * @brief Insert value of a string. -: 1632: * @param __pos1 Iterator referencing location in string to insert at. -: 1633: * @param __str The string to insert. -: 1634: * @return Reference to this string. -: 1635: * @throw std::length_error If new length exceeds @c max_size(). -: 1636: * -: 1637: * Inserts value of @a __str starting at @a __pos1. If adding -: 1638: * characters causes the length to exceed max_size(), -: 1639: * length_error is thrown. The value of the string doesn't -: 1640: * change if an error is thrown. -: 1641: */ -: 1642: basic_string& -: 1643: insert(size_type __pos1, const basic_string& __str) -: 1644: { return this->replace(__pos1, size_type(0), -: 1645: __str._M_data(), __str.size()); } -: 1646: -: 1647: /** -: 1648: * @brief Insert a substring. -: 1649: * @param __pos1 Iterator referencing location in string to insert at. -: 1650: * @param __str The string to insert. -: 1651: * @param __pos2 Start of characters in str to insert. -: 1652: * @param __n Number of characters to insert. -: 1653: * @return Reference to this string. -: 1654: * @throw std::length_error If new length exceeds @c max_size(). -: 1655: * @throw std::out_of_range If @a pos1 > size() or -: 1656: * @a __pos2 > @a str.size(). -: 1657: * -: 1658: * Starting at @a pos1, insert @a __n character of @a __str -: 1659: * beginning with @a __pos2. If adding characters causes the -: 1660: * length to exceed max_size(), length_error is thrown. If @a -: 1661: * __pos1 is beyond the end of this string or @a __pos2 is -: 1662: * beyond the end of @a __str, out_of_range is thrown. The -: 1663: * value of the string doesn't change if an error is thrown. -: 1664: */ -: 1665: basic_string& -: 1666: insert(size_type __pos1, const basic_string& __str, -: 1667: size_type __pos2, size_type __n = npos) -: 1668: { return this->replace(__pos1, size_type(0), __str._M_data() -: 1669: + __str._M_check(__pos2, "basic_string::insert"), -: 1670: __str._M_limit(__pos2, __n)); } -: 1671: -: 1672: /** -: 1673: * @brief Insert a C substring. -: 1674: * @param __pos Iterator referencing location in string to insert at. -: 1675: * @param __s The C string to insert. -: 1676: * @param __n The number of characters to insert. -: 1677: * @return Reference to this string. -: 1678: * @throw std::length_error If new length exceeds @c max_size(). -: 1679: * @throw std::out_of_range If @a __pos is beyond the end of this -: 1680: * string. -: 1681: * -: 1682: * Inserts the first @a __n characters of @a __s starting at @a -: 1683: * __pos. If adding characters causes the length to exceed -: 1684: * max_size(), length_error is thrown. If @a __pos is beyond -: 1685: * end(), out_of_range is thrown. The value of the string -: 1686: * doesn't change if an error is thrown. -: 1687: */ -: 1688: basic_string& -: 1689: insert(size_type __pos, const _CharT* __s, size_type __n) -: 1690: { return this->replace(__pos, size_type(0), __s, __n); } -: 1691: -: 1692: /** -: 1693: * @brief Insert a C string. -: 1694: * @param __pos Iterator referencing location in string to insert at. -: 1695: * @param __s The C string to insert. -: 1696: * @return Reference to this string. -: 1697: * @throw std::length_error If new length exceeds @c max_size(). -: 1698: * @throw std::out_of_range If @a pos is beyond the end of this -: 1699: * string. -: 1700: * -: 1701: * Inserts the first @a n characters of @a __s starting at @a __pos. If -: 1702: * adding characters causes the length to exceed max_size(), -: 1703: * length_error is thrown. If @a __pos is beyond end(), out_of_range is -: 1704: * thrown. The value of the string doesn't change if an error is -: 1705: * thrown. -: 1706: */ -: 1707: basic_string& -: 1708: insert(size_type __pos, const _CharT* __s) -: 1709: { -: 1710: __glibcxx_requires_string(__s); -: 1711: return this->replace(__pos, size_type(0), __s, -: 1712: traits_type::length(__s)); -: 1713: } -: 1714: -: 1715: /** -: 1716: * @brief Insert multiple characters. -: 1717: * @param __pos Index in string to insert at. -: 1718: * @param __n Number of characters to insert -: 1719: * @param __c The character to insert. -: 1720: * @return Reference to this string. -: 1721: * @throw std::length_error If new length exceeds @c max_size(). -: 1722: * @throw std::out_of_range If @a __pos is beyond the end of this -: 1723: * string. -: 1724: * -: 1725: * Inserts @a __n copies of character @a __c starting at index -: 1726: * @a __pos. If adding characters causes the length to exceed -: 1727: * max_size(), length_error is thrown. If @a __pos > length(), -: 1728: * out_of_range is thrown. The value of the string doesn't -: 1729: * change if an error is thrown. -: 1730: */ -: 1731: basic_string& -: 1732: insert(size_type __pos, size_type __n, _CharT __c) -: 1733: { return _M_replace_aux(_M_check(__pos, "basic_string::insert"), -: 1734: size_type(0), __n, __c); } -: 1735: -: 1736: /** -: 1737: * @brief Insert one character. -: 1738: * @param __p Iterator referencing position in string to insert at. -: 1739: * @param __c The character to insert. -: 1740: * @return Iterator referencing newly inserted char. -: 1741: * @throw std::length_error If new length exceeds @c max_size(). -: 1742: * -: 1743: * Inserts character @a __c at position referenced by @a __p. -: 1744: * If adding character causes the length to exceed max_size(), -: 1745: * length_error is thrown. If @a __p is beyond end of string, -: 1746: * out_of_range is thrown. The value of the string doesn't -: 1747: * change if an error is thrown. -: 1748: */ -: 1749: iterator -: 1750: insert(__const_iterator __p, _CharT __c) -: 1751: { -: 1752: _GLIBCXX_DEBUG_PEDASSERT(__p >= begin() && __p <= end()); -: 1753: const size_type __pos = __p - begin(); -: 1754: _M_replace_aux(__pos, size_type(0), size_type(1), __c); -: 1755: return iterator(_M_data() + __pos); -: 1756: } -: 1757: -: 1758:#if __cplusplus >= 201703L -: 1759: /** -: 1760: * @brief Insert a string_view. -: 1761: * @param __pos Iterator referencing position in string to insert at. -: 1762: * @param __svt The object convertible to string_view to insert. -: 1763: * @return Reference to this string. -: 1764: */ -: 1765: template -: 1766: _If_sv<_Tp, basic_string&> -: 1767: insert(size_type __pos, const _Tp& __svt) -: 1768: { -: 1769: __sv_type __sv = __svt; -: 1770: return this->insert(__pos, __sv.data(), __sv.size()); -: 1771: } -: 1772: -: 1773: /** -: 1774: * @brief Insert a string_view. -: 1775: * @param __pos Iterator referencing position in string to insert at. -: 1776: * @param __svt The object convertible to string_view to insert from. -: 1777: * @param __pos Iterator referencing position in string_view to insert -: 1778: * from. -: 1779: * @param __n The number of characters to insert. -: 1780: * @return Reference to this string. -: 1781: */ -: 1782: template -: 1783: _If_sv<_Tp, basic_string&> -: 1784: insert(size_type __pos1, const _Tp& __svt, -: 1785: size_type __pos2, size_type __n = npos) -: 1786: { -: 1787: __sv_type __sv = __svt; -: 1788: return this->replace(__pos1, size_type(0), -: 1789: __sv.data() -: 1790: + std::__sv_check(__sv.size(), __pos2, "basic_string::insert"), -: 1791: std::__sv_limit(__sv.size(), __pos2, __n)); -: 1792: } -: 1793:#endif // C++17 -: 1794: -: 1795: /** -: 1796: * @brief Remove characters. -: 1797: * @param __pos Index of first character to remove (default 0). -: 1798: * @param __n Number of characters to remove (default remainder). -: 1799: * @return Reference to this string. -: 1800: * @throw std::out_of_range If @a pos is beyond the end of this -: 1801: * string. -: 1802: * -: 1803: * Removes @a __n characters from this string starting at @a -: 1804: * __pos. The length of the string is reduced by @a __n. If -: 1805: * there are < @a __n characters to remove, the remainder of -: 1806: * the string is truncated. If @a __p is beyond end of string, -: 1807: * out_of_range is thrown. The value of the string doesn't -: 1808: * change if an error is thrown. -: 1809: */ -: 1810: basic_string& -: 1811: erase(size_type __pos = 0, size_type __n = npos) -: 1812: { -: 1813: _M_check(__pos, "basic_string::erase"); -: 1814: if (__n == npos) -: 1815: this->_M_set_length(__pos); -: 1816: else if (__n != 0) -: 1817: this->_M_erase(__pos, _M_limit(__pos, __n)); -: 1818: return *this; -: 1819: } -: 1820: -: 1821: /** -: 1822: * @brief Remove one character. -: 1823: * @param __position Iterator referencing the character to remove. -: 1824: * @return iterator referencing same location after removal. -: 1825: * -: 1826: * Removes the character at @a __position from this string. The value -: 1827: * of the string doesn't change if an error is thrown. -: 1828: */ -: 1829: iterator -: 1830: erase(__const_iterator __position) -: 1831: { -: 1832: _GLIBCXX_DEBUG_PEDASSERT(__position >= begin() -: 1833: && __position < end()); -: 1834: const size_type __pos = __position - begin(); -: 1835: this->_M_erase(__pos, size_type(1)); -: 1836: return iterator(_M_data() + __pos); -: 1837: } -: 1838: -: 1839: /** -: 1840: * @brief Remove a range of characters. -: 1841: * @param __first Iterator referencing the first character to remove. -: 1842: * @param __last Iterator referencing the end of the range. -: 1843: * @return Iterator referencing location of first after removal. -: 1844: * -: 1845: * Removes the characters in the range [first,last) from this string. -: 1846: * The value of the string doesn't change if an error is thrown. -: 1847: */ -: 1848: iterator -: 1849: erase(__const_iterator __first, __const_iterator __last) -: 1850: { -: 1851: _GLIBCXX_DEBUG_PEDASSERT(__first >= begin() && __first <= __last -: 1852: && __last <= end()); -: 1853: const size_type __pos = __first - begin(); -: 1854: if (__last == end()) -: 1855: this->_M_set_length(__pos); -: 1856: else -: 1857: this->_M_erase(__pos, __last - __first); -: 1858: return iterator(this->_M_data() + __pos); -: 1859: } -: 1860: -: 1861:#if __cplusplus >= 201103L -: 1862: /** -: 1863: * @brief Remove the last character. -: 1864: * -: 1865: * The string must be non-empty. -: 1866: */ -: 1867: void -: 1868: pop_back() noexcept -: 1869: { -: 1870: __glibcxx_assert(!empty()); -: 1871: _M_erase(size() - 1, 1); -: 1872: } -: 1873:#endif // C++11 -: 1874: -: 1875: /** -: 1876: * @brief Replace characters with value from another string. -: 1877: * @param __pos Index of first character to replace. -: 1878: * @param __n Number of characters to be replaced. -: 1879: * @param __str String to insert. -: 1880: * @return Reference to this string. -: 1881: * @throw std::out_of_range If @a pos is beyond the end of this -: 1882: * string. -: 1883: * @throw std::length_error If new length exceeds @c max_size(). -: 1884: * -: 1885: * Removes the characters in the range [__pos,__pos+__n) from -: 1886: * this string. In place, the value of @a __str is inserted. -: 1887: * If @a __pos is beyond end of string, out_of_range is thrown. -: 1888: * If the length of the result exceeds max_size(), length_error -: 1889: * is thrown. The value of the string doesn't change if an -: 1890: * error is thrown. -: 1891: */ -: 1892: basic_string& -: 1893: replace(size_type __pos, size_type __n, const basic_string& __str) -: 1894: { return this->replace(__pos, __n, __str._M_data(), __str.size()); } -: 1895: -: 1896: /** -: 1897: * @brief Replace characters with value from another string. -: 1898: * @param __pos1 Index of first character to replace. -: 1899: * @param __n1 Number of characters to be replaced. -: 1900: * @param __str String to insert. -: 1901: * @param __pos2 Index of first character of str to use. -: 1902: * @param __n2 Number of characters from str to use. -: 1903: * @return Reference to this string. -: 1904: * @throw std::out_of_range If @a __pos1 > size() or @a __pos2 > -: 1905: * __str.size(). -: 1906: * @throw std::length_error If new length exceeds @c max_size(). -: 1907: * -: 1908: * Removes the characters in the range [__pos1,__pos1 + n) from this -: 1909: * string. In place, the value of @a __str is inserted. If @a __pos is -: 1910: * beyond end of string, out_of_range is thrown. If the length of the -: 1911: * result exceeds max_size(), length_error is thrown. The value of the -: 1912: * string doesn't change if an error is thrown. -: 1913: */ -: 1914: basic_string& -: 1915: replace(size_type __pos1, size_type __n1, const basic_string& __str, -: 1916: size_type __pos2, size_type __n2 = npos) -: 1917: { return this->replace(__pos1, __n1, __str._M_data() -: 1918: + __str._M_check(__pos2, "basic_string::replace"), -: 1919: __str._M_limit(__pos2, __n2)); } -: 1920: -: 1921: /** -: 1922: * @brief Replace characters with value of a C substring. -: 1923: * @param __pos Index of first character to replace. -: 1924: * @param __n1 Number of characters to be replaced. -: 1925: * @param __s C string to insert. -: 1926: * @param __n2 Number of characters from @a s to use. -: 1927: * @return Reference to this string. -: 1928: * @throw std::out_of_range If @a pos1 > size(). -: 1929: * @throw std::length_error If new length exceeds @c max_size(). -: 1930: * -: 1931: * Removes the characters in the range [__pos,__pos + __n1) -: 1932: * from this string. In place, the first @a __n2 characters of -: 1933: * @a __s are inserted, or all of @a __s if @a __n2 is too large. If -: 1934: * @a __pos is beyond end of string, out_of_range is thrown. If -: 1935: * the length of result exceeds max_size(), length_error is -: 1936: * thrown. The value of the string doesn't change if an error -: 1937: * is thrown. -: 1938: */ -: 1939: basic_string& -: 1940: replace(size_type __pos, size_type __n1, const _CharT* __s, -: 1941: size_type __n2) -: 1942: { -: 1943: __glibcxx_requires_string_len(__s, __n2); -: 1944: return _M_replace(_M_check(__pos, "basic_string::replace"), -: 1945: _M_limit(__pos, __n1), __s, __n2); -: 1946: } -: 1947: -: 1948: /** -: 1949: * @brief Replace characters with value of a C string. -: 1950: * @param __pos Index of first character to replace. -: 1951: * @param __n1 Number of characters to be replaced. -: 1952: * @param __s C string to insert. -: 1953: * @return Reference to this string. -: 1954: * @throw std::out_of_range If @a pos > size(). -: 1955: * @throw std::length_error If new length exceeds @c max_size(). -: 1956: * -: 1957: * Removes the characters in the range [__pos,__pos + __n1) -: 1958: * from this string. In place, the characters of @a __s are -: 1959: * inserted. If @a __pos is beyond end of string, out_of_range -: 1960: * is thrown. If the length of result exceeds max_size(), -: 1961: * length_error is thrown. The value of the string doesn't -: 1962: * change if an error is thrown. -: 1963: */ -: 1964: basic_string& -: 1965: replace(size_type __pos, size_type __n1, const _CharT* __s) -: 1966: { -: 1967: __glibcxx_requires_string(__s); -: 1968: return this->replace(__pos, __n1, __s, traits_type::length(__s)); -: 1969: } -: 1970: -: 1971: /** -: 1972: * @brief Replace characters with multiple characters. -: 1973: * @param __pos Index of first character to replace. -: 1974: * @param __n1 Number of characters to be replaced. -: 1975: * @param __n2 Number of characters to insert. -: 1976: * @param __c Character to insert. -: 1977: * @return Reference to this string. -: 1978: * @throw std::out_of_range If @a __pos > size(). -: 1979: * @throw std::length_error If new length exceeds @c max_size(). -: 1980: * -: 1981: * Removes the characters in the range [pos,pos + n1) from this -: 1982: * string. In place, @a __n2 copies of @a __c are inserted. -: 1983: * If @a __pos is beyond end of string, out_of_range is thrown. -: 1984: * If the length of result exceeds max_size(), length_error is -: 1985: * thrown. The value of the string doesn't change if an error -: 1986: * is thrown. -: 1987: */ -: 1988: basic_string& -: 1989: replace(size_type __pos, size_type __n1, size_type __n2, _CharT __c) -: 1990: { return _M_replace_aux(_M_check(__pos, "basic_string::replace"), -: 1991: _M_limit(__pos, __n1), __n2, __c); } -: 1992: -: 1993: /** -: 1994: * @brief Replace range of characters with string. -: 1995: * @param __i1 Iterator referencing start of range to replace. -: 1996: * @param __i2 Iterator referencing end of range to replace. -: 1997: * @param __str String value to insert. -: 1998: * @return Reference to this string. -: 1999: * @throw std::length_error If new length exceeds @c max_size(). -: 2000: * -: 2001: * Removes the characters in the range [__i1,__i2). In place, -: 2002: * the value of @a __str is inserted. If the length of result -: 2003: * exceeds max_size(), length_error is thrown. The value of -: 2004: * the string doesn't change if an error is thrown. -: 2005: */ -: 2006: basic_string& -: 2007: replace(__const_iterator __i1, __const_iterator __i2, -: 2008: const basic_string& __str) -: 2009: { return this->replace(__i1, __i2, __str._M_data(), __str.size()); } -: 2010: -: 2011: /** -: 2012: * @brief Replace range of characters with C substring. -: 2013: * @param __i1 Iterator referencing start of range to replace. -: 2014: * @param __i2 Iterator referencing end of range to replace. -: 2015: * @param __s C string value to insert. -: 2016: * @param __n Number of characters from s to insert. -: 2017: * @return Reference to this string. -: 2018: * @throw std::length_error If new length exceeds @c max_size(). -: 2019: * -: 2020: * Removes the characters in the range [__i1,__i2). In place, -: 2021: * the first @a __n characters of @a __s are inserted. If the -: 2022: * length of result exceeds max_size(), length_error is thrown. -: 2023: * The value of the string doesn't change if an error is -: 2024: * thrown. -: 2025: */ -: 2026: basic_string& -: 2027: replace(__const_iterator __i1, __const_iterator __i2, -: 2028: const _CharT* __s, size_type __n) -: 2029: { -: 2030: _GLIBCXX_DEBUG_PEDASSERT(begin() <= __i1 && __i1 <= __i2 -: 2031: && __i2 <= end()); -: 2032: return this->replace(__i1 - begin(), __i2 - __i1, __s, __n); -: 2033: } -: 2034: -: 2035: /** -: 2036: * @brief Replace range of characters with C string. -: 2037: * @param __i1 Iterator referencing start of range to replace. -: 2038: * @param __i2 Iterator referencing end of range to replace. -: 2039: * @param __s C string value to insert. -: 2040: * @return Reference to this string. -: 2041: * @throw std::length_error If new length exceeds @c max_size(). -: 2042: * -: 2043: * Removes the characters in the range [__i1,__i2). In place, -: 2044: * the characters of @a __s are inserted. If the length of -: 2045: * result exceeds max_size(), length_error is thrown. The -: 2046: * value of the string doesn't change if an error is thrown. -: 2047: */ -: 2048: basic_string& -: 2049: replace(__const_iterator __i1, __const_iterator __i2, const _CharT* __s) -: 2050: { -: 2051: __glibcxx_requires_string(__s); -: 2052: return this->replace(__i1, __i2, __s, traits_type::length(__s)); -: 2053: } -: 2054: -: 2055: /** -: 2056: * @brief Replace range of characters with multiple characters -: 2057: * @param __i1 Iterator referencing start of range to replace. -: 2058: * @param __i2 Iterator referencing end of range to replace. -: 2059: * @param __n Number of characters to insert. -: 2060: * @param __c Character to insert. -: 2061: * @return Reference to this string. -: 2062: * @throw std::length_error If new length exceeds @c max_size(). -: 2063: * -: 2064: * Removes the characters in the range [__i1,__i2). In place, -: 2065: * @a __n copies of @a __c are inserted. If the length of -: 2066: * result exceeds max_size(), length_error is thrown. The -: 2067: * value of the string doesn't change if an error is thrown. -: 2068: */ -: 2069: basic_string& -: 2070: replace(__const_iterator __i1, __const_iterator __i2, size_type __n, -: 2071: _CharT __c) -: 2072: { -: 2073: _GLIBCXX_DEBUG_PEDASSERT(begin() <= __i1 && __i1 <= __i2 -: 2074: && __i2 <= end()); -: 2075: return _M_replace_aux(__i1 - begin(), __i2 - __i1, __n, __c); -: 2076: } -: 2077: -: 2078: /** -: 2079: * @brief Replace range of characters with range. -: 2080: * @param __i1 Iterator referencing start of range to replace. -: 2081: * @param __i2 Iterator referencing end of range to replace. -: 2082: * @param __k1 Iterator referencing start of range to insert. -: 2083: * @param __k2 Iterator referencing end of range to insert. -: 2084: * @return Reference to this string. -: 2085: * @throw std::length_error If new length exceeds @c max_size(). -: 2086: * -: 2087: * Removes the characters in the range [__i1,__i2). In place, -: 2088: * characters in the range [__k1,__k2) are inserted. If the -: 2089: * length of result exceeds max_size(), length_error is thrown. -: 2090: * The value of the string doesn't change if an error is -: 2091: * thrown. -: 2092: */ -: 2093:#if __cplusplus >= 201103L -: 2094: template> -: 2096: basic_string& -: 2097: replace(const_iterator __i1, const_iterator __i2, -: 2098: _InputIterator __k1, _InputIterator __k2) -: 2099: { -: 2100: _GLIBCXX_DEBUG_PEDASSERT(begin() <= __i1 && __i1 <= __i2 -: 2101: && __i2 <= end()); -: 2102: __glibcxx_requires_valid_range(__k1, __k2); -: 2103: return this->_M_replace_dispatch(__i1, __i2, __k1, __k2, -: 2104: std::__false_type()); -: 2105: } -: 2106:#else -: 2107: template -: 2108:#ifdef _GLIBCXX_DISAMBIGUATE_REPLACE_INST -: 2109: typename __enable_if_not_native_iterator<_InputIterator>::__type -: 2110:#else -: 2111: basic_string& -: 2112:#endif -: 2113: replace(iterator __i1, iterator __i2, -: 2114: _InputIterator __k1, _InputIterator __k2) -: 2115: { -: 2116: _GLIBCXX_DEBUG_PEDASSERT(begin() <= __i1 && __i1 <= __i2 -: 2117: && __i2 <= end()); -: 2118: __glibcxx_requires_valid_range(__k1, __k2); -: 2119: typedef typename std::__is_integer<_InputIterator>::__type _Integral; -: 2120: return _M_replace_dispatch(__i1, __i2, __k1, __k2, _Integral()); -: 2121: } -: 2122:#endif -: 2123: -: 2124: // Specializations for the common case of pointer and iterator: -: 2125: // useful to avoid the overhead of temporary buffering in _M_replace. -: 2126: basic_string& -: 2127: replace(__const_iterator __i1, __const_iterator __i2, -: 2128: _CharT* __k1, _CharT* __k2) -: 2129: { -: 2130: _GLIBCXX_DEBUG_PEDASSERT(begin() <= __i1 && __i1 <= __i2 -: 2131: && __i2 <= end()); -: 2132: __glibcxx_requires_valid_range(__k1, __k2); -: 2133: return this->replace(__i1 - begin(), __i2 - __i1, -: 2134: __k1, __k2 - __k1); -: 2135: } -: 2136: -: 2137: basic_string& -: 2138: replace(__const_iterator __i1, __const_iterator __i2, -: 2139: const _CharT* __k1, const _CharT* __k2) -: 2140: { -: 2141: _GLIBCXX_DEBUG_PEDASSERT(begin() <= __i1 && __i1 <= __i2 -: 2142: && __i2 <= end()); -: 2143: __glibcxx_requires_valid_range(__k1, __k2); -: 2144: return this->replace(__i1 - begin(), __i2 - __i1, -: 2145: __k1, __k2 - __k1); -: 2146: } -: 2147: -: 2148: basic_string& -: 2149: replace(__const_iterator __i1, __const_iterator __i2, -: 2150: iterator __k1, iterator __k2) -: 2151: { -: 2152: _GLIBCXX_DEBUG_PEDASSERT(begin() <= __i1 && __i1 <= __i2 -: 2153: && __i2 <= end()); -: 2154: __glibcxx_requires_valid_range(__k1, __k2); -: 2155: return this->replace(__i1 - begin(), __i2 - __i1, -: 2156: __k1.base(), __k2 - __k1); -: 2157: } -: 2158: -: 2159: basic_string& -: 2160: replace(__const_iterator __i1, __const_iterator __i2, -: 2161: const_iterator __k1, const_iterator __k2) -: 2162: { -: 2163: _GLIBCXX_DEBUG_PEDASSERT(begin() <= __i1 && __i1 <= __i2 -: 2164: && __i2 <= end()); -: 2165: __glibcxx_requires_valid_range(__k1, __k2); -: 2166: return this->replace(__i1 - begin(), __i2 - __i1, -: 2167: __k1.base(), __k2 - __k1); -: 2168: } -: 2169: -: 2170:#if __cplusplus >= 201103L -: 2171: /** -: 2172: * @brief Replace range of characters with initializer_list. -: 2173: * @param __i1 Iterator referencing start of range to replace. -: 2174: * @param __i2 Iterator referencing end of range to replace. -: 2175: * @param __l The initializer_list of characters to insert. -: 2176: * @return Reference to this string. -: 2177: * @throw std::length_error If new length exceeds @c max_size(). -: 2178: * -: 2179: * Removes the characters in the range [__i1,__i2). In place, -: 2180: * characters in the range [__k1,__k2) are inserted. If the -: 2181: * length of result exceeds max_size(), length_error is thrown. -: 2182: * The value of the string doesn't change if an error is -: 2183: * thrown. -: 2184: */ -: 2185: basic_string& replace(const_iterator __i1, const_iterator __i2, -: 2186: initializer_list<_CharT> __l) -: 2187: { return this->replace(__i1, __i2, __l.begin(), __l.size()); } -: 2188:#endif // C++11 -: 2189: -: 2190:#if __cplusplus >= 201703L -: 2191: /** -: 2192: * @brief Replace range of characters with string_view. -: 2193: * @param __pos The position to replace at. -: 2194: * @param __n The number of characters to replace. -: 2195: * @param __svt The object convertible to string_view to insert. -: 2196: * @return Reference to this string. -: 2197: */ -: 2198: template -: 2199: _If_sv<_Tp, basic_string&> -: 2200: replace(size_type __pos, size_type __n, const _Tp& __svt) -: 2201: { -: 2202: __sv_type __sv = __svt; -: 2203: return this->replace(__pos, __n, __sv.data(), __sv.size()); -: 2204: } -: 2205: -: 2206: /** -: 2207: * @brief Replace range of characters with string_view. -: 2208: * @param __pos1 The position to replace at. -: 2209: * @param __n1 The number of characters to replace. -: 2210: * @param __svt The object convertible to string_view to insert from. -: 2211: * @param __pos2 The position in the string_view to insert from. -: 2212: * @param __n2 The number of characters to insert. -: 2213: * @return Reference to this string. -: 2214: */ -: 2215: template -: 2216: _If_sv<_Tp, basic_string&> -: 2217: replace(size_type __pos1, size_type __n1, const _Tp& __svt, -: 2218: size_type __pos2, size_type __n2 = npos) -: 2219: { -: 2220: __sv_type __sv = __svt; -: 2221: return this->replace(__pos1, __n1, -: 2222: __sv.data() -: 2223: + std::__sv_check(__sv.size(), __pos2, "basic_string::replace"), -: 2224: std::__sv_limit(__sv.size(), __pos2, __n2)); -: 2225: } -: 2226: -: 2227: /** -: 2228: * @brief Replace range of characters with string_view. -: 2229: * @param __i1 An iterator referencing the start position -: 2230: to replace at. -: 2231: * @param __i2 An iterator referencing the end position -: 2232: for the replace. -: 2233: * @param __svt The object convertible to string_view to insert from. -: 2234: * @return Reference to this string. -: 2235: */ -: 2236: template -: 2237: _If_sv<_Tp, basic_string&> -: 2238: replace(const_iterator __i1, const_iterator __i2, const _Tp& __svt) -: 2239: { -: 2240: __sv_type __sv = __svt; -: 2241: return this->replace(__i1 - begin(), __i2 - __i1, __sv); -: 2242: } -: 2243:#endif // C++17 -: 2244: -: 2245: private: -: 2246: template -: 2247: basic_string& -: 2248: _M_replace_dispatch(const_iterator __i1, const_iterator __i2, -: 2249: _Integer __n, _Integer __val, __true_type) -: 2250: { return _M_replace_aux(__i1 - begin(), __i2 - __i1, __n, __val); } -: 2251: -: 2252: template -: 2253: basic_string& -: 2254: _M_replace_dispatch(const_iterator __i1, const_iterator __i2, -: 2255: _InputIterator __k1, _InputIterator __k2, -: 2256: __false_type); -: 2257: -: 2258: basic_string& -: 2259: _M_replace_aux(size_type __pos1, size_type __n1, size_type __n2, -: 2260: _CharT __c); -: 2261: -: 2262: basic_string& -: 2263: _M_replace(size_type __pos, size_type __len1, const _CharT* __s, -: 2264: const size_type __len2); -: 2265: -: 2266: basic_string& -: 2267: _M_append(const _CharT* __s, size_type __n); -: 2268: -: 2269: public: -: 2270: -: 2271: /** -: 2272: * @brief Copy substring into C string. -: 2273: * @param __s C string to copy value into. -: 2274: * @param __n Number of characters to copy. -: 2275: * @param __pos Index of first character to copy. -: 2276: * @return Number of characters actually copied -: 2277: * @throw std::out_of_range If __pos > size(). -: 2278: * -: 2279: * Copies up to @a __n characters starting at @a __pos into the -: 2280: * C string @a __s. If @a __pos is %greater than size(), -: 2281: * out_of_range is thrown. -: 2282: */ -: 2283: size_type -: 2284: copy(_CharT* __s, size_type __n, size_type __pos = 0) const; -: 2285: -: 2286: /** -: 2287: * @brief Swap contents with another string. -: 2288: * @param __s String to swap with. -: 2289: * -: 2290: * Exchanges the contents of this string with that of @a __s in constant -: 2291: * time. -: 2292: */ -: 2293: void -: 2294: swap(basic_string& __s) _GLIBCXX_NOEXCEPT; -: 2295: -: 2296: // String operations: -: 2297: /** -: 2298: * @brief Return const pointer to null-terminated contents. -: 2299: * -: 2300: * This is a handle to internal data. Do not modify or dire things may -: 2301: * happen. -: 2302: */ -: 2303: const _CharT* -: 2304: c_str() const _GLIBCXX_NOEXCEPT -: 2305: { return _M_data(); } -: 2306: -: 2307: /** -: 2308: * @brief Return const pointer to contents. -: 2309: * -: 2310: * This is a pointer to internal data. It is undefined to modify -: 2311: * the contents through the returned pointer. To get a pointer that -: 2312: * allows modifying the contents use @c &str[0] instead, -: 2313: * (or in C++17 the non-const @c str.data() overload). -: 2314: */ -: 2315: const _CharT* -: 2316: data() const _GLIBCXX_NOEXCEPT -: 2317: { return _M_data(); } -: 2318: -: 2319:#if __cplusplus >= 201703L -: 2320: /** -: 2321: * @brief Return non-const pointer to contents. -: 2322: * -: 2323: * This is a pointer to the character sequence held by the string. -: 2324: * Modifying the characters in the sequence is allowed. -: 2325: */ -: 2326: _CharT* -: 2327: data() noexcept -: 2328: { return _M_data(); } -: 2329:#endif -: 2330: -: 2331: /** -: 2332: * @brief Return copy of allocator used to construct this string. -: 2333: */ -: 2334: allocator_type -: 2335: get_allocator() const _GLIBCXX_NOEXCEPT -: 2336: { return _M_get_allocator(); } -: 2337: -: 2338: /** -: 2339: * @brief Find position of a C substring. -: 2340: * @param __s C string to locate. -: 2341: * @param __pos Index of character to search from. -: 2342: * @param __n Number of characters from @a s to search for. -: 2343: * @return Index of start of first occurrence. -: 2344: * -: 2345: * Starting from @a __pos, searches forward for the first @a -: 2346: * __n characters in @a __s within this string. If found, -: 2347: * returns the index where it begins. If not found, returns -: 2348: * npos. -: 2349: */ -: 2350: size_type -: 2351: find(const _CharT* __s, size_type __pos, size_type __n) const -: 2352: _GLIBCXX_NOEXCEPT; -: 2353: -: 2354: /** -: 2355: * @brief Find position of a string. -: 2356: * @param __str String to locate. -: 2357: * @param __pos Index of character to search from (default 0). -: 2358: * @return Index of start of first occurrence. -: 2359: * -: 2360: * Starting from @a __pos, searches forward for value of @a __str within -: 2361: * this string. If found, returns the index where it begins. If not -: 2362: * found, returns npos. -: 2363: */ -: 2364: size_type -: 2365: find(const basic_string& __str, size_type __pos = 0) const -: 2366: _GLIBCXX_NOEXCEPT -: 2367: { return this->find(__str.data(), __pos, __str.size()); } -: 2368: -: 2369:#if __cplusplus >= 201703L -: 2370: /** -: 2371: * @brief Find position of a string_view. -: 2372: * @param __svt The object convertible to string_view to locate. -: 2373: * @param __pos Index of character to search from (default 0). -: 2374: * @return Index of start of first occurrence. -: 2375: */ -: 2376: template -: 2377: _If_sv<_Tp, size_type> -: 2378: find(const _Tp& __svt, size_type __pos = 0) const -: 2379: noexcept(is_same<_Tp, __sv_type>::value) -: 2380: { -: 2381: __sv_type __sv = __svt; -: 2382: return this->find(__sv.data(), __pos, __sv.size()); -: 2383: } -: 2384:#endif // C++17 -: 2385: -: 2386: /** -: 2387: * @brief Find position of a C string. -: 2388: * @param __s C string to locate. -: 2389: * @param __pos Index of character to search from (default 0). -: 2390: * @return Index of start of first occurrence. -: 2391: * -: 2392: * Starting from @a __pos, searches forward for the value of @a -: 2393: * __s within this string. If found, returns the index where -: 2394: * it begins. If not found, returns npos. -: 2395: */ -: 2396: size_type -: 2397: find(const _CharT* __s, size_type __pos = 0) const _GLIBCXX_NOEXCEPT -: 2398: { -: 2399: __glibcxx_requires_string(__s); -: 2400: return this->find(__s, __pos, traits_type::length(__s)); -: 2401: } -: 2402: -: 2403: /** -: 2404: * @brief Find position of a character. -: 2405: * @param __c Character to locate. -: 2406: * @param __pos Index of character to search from (default 0). -: 2407: * @return Index of first occurrence. -: 2408: * -: 2409: * Starting from @a __pos, searches forward for @a __c within -: 2410: * this string. If found, returns the index where it was -: 2411: * found. If not found, returns npos. -: 2412: */ -: 2413: size_type -: 2414: find(_CharT __c, size_type __pos = 0) const _GLIBCXX_NOEXCEPT; -: 2415: -: 2416: /** -: 2417: * @brief Find last position of a string. -: 2418: * @param __str String to locate. -: 2419: * @param __pos Index of character to search back from (default end). -: 2420: * @return Index of start of last occurrence. -: 2421: * -: 2422: * Starting from @a __pos, searches backward for value of @a -: 2423: * __str within this string. If found, returns the index where -: 2424: * it begins. If not found, returns npos. -: 2425: */ -: 2426: size_type -: 2427: rfind(const basic_string& __str, size_type __pos = npos) const -: 2428: _GLIBCXX_NOEXCEPT -: 2429: { return this->rfind(__str.data(), __pos, __str.size()); } -: 2430: -: 2431:#if __cplusplus >= 201703L -: 2432: /** -: 2433: * @brief Find last position of a string_view. -: 2434: * @param __svt The object convertible to string_view to locate. -: 2435: * @param __pos Index of character to search back from (default end). -: 2436: * @return Index of start of last occurrence. -: 2437: */ -: 2438: template -: 2439: _If_sv<_Tp, size_type> -: 2440: rfind(const _Tp& __svt, size_type __pos = npos) const -: 2441: noexcept(is_same<_Tp, __sv_type>::value) -: 2442: { -: 2443: __sv_type __sv = __svt; -: 2444: return this->rfind(__sv.data(), __pos, __sv.size()); -: 2445: } -: 2446:#endif // C++17 -: 2447: -: 2448: /** -: 2449: * @brief Find last position of a C substring. -: 2450: * @param __s C string to locate. -: 2451: * @param __pos Index of character to search back from. -: 2452: * @param __n Number of characters from s to search for. -: 2453: * @return Index of start of last occurrence. -: 2454: * -: 2455: * Starting from @a __pos, searches backward for the first @a -: 2456: * __n characters in @a __s within this string. If found, -: 2457: * returns the index where it begins. If not found, returns -: 2458: * npos. -: 2459: */ -: 2460: size_type -: 2461: rfind(const _CharT* __s, size_type __pos, size_type __n) const -: 2462: _GLIBCXX_NOEXCEPT; -: 2463: -: 2464: /** -: 2465: * @brief Find last position of a C string. -: 2466: * @param __s C string to locate. -: 2467: * @param __pos Index of character to start search at (default end). -: 2468: * @return Index of start of last occurrence. -: 2469: * -: 2470: * Starting from @a __pos, searches backward for the value of -: 2471: * @a __s within this string. If found, returns the index -: 2472: * where it begins. If not found, returns npos. -: 2473: */ -: 2474: size_type -: 2475: rfind(const _CharT* __s, size_type __pos = npos) const -: 2476: { -: 2477: __glibcxx_requires_string(__s); -: 2478: return this->rfind(__s, __pos, traits_type::length(__s)); -: 2479: } -: 2480: -: 2481: /** -: 2482: * @brief Find last position of a character. -: 2483: * @param __c Character to locate. -: 2484: * @param __pos Index of character to search back from (default end). -: 2485: * @return Index of last occurrence. -: 2486: * -: 2487: * Starting from @a __pos, searches backward for @a __c within -: 2488: * this string. If found, returns the index where it was -: 2489: * found. If not found, returns npos. -: 2490: */ -: 2491: size_type -: 2492: rfind(_CharT __c, size_type __pos = npos) const _GLIBCXX_NOEXCEPT; -: 2493: -: 2494: /** -: 2495: * @brief Find position of a character of string. -: 2496: * @param __str String containing characters to locate. -: 2497: * @param __pos Index of character to search from (default 0). -: 2498: * @return Index of first occurrence. -: 2499: * -: 2500: * Starting from @a __pos, searches forward for one of the -: 2501: * characters of @a __str within this string. If found, -: 2502: * returns the index where it was found. If not found, returns -: 2503: * npos. -: 2504: */ -: 2505: size_type -: 2506: find_first_of(const basic_string& __str, size_type __pos = 0) const -: 2507: _GLIBCXX_NOEXCEPT -: 2508: { return this->find_first_of(__str.data(), __pos, __str.size()); } -: 2509: -: 2510:#if __cplusplus >= 201703L -: 2511: /** -: 2512: * @brief Find position of a character of a string_view. -: 2513: * @param __svt An object convertible to string_view containing -: 2514: * characters to locate. -: 2515: * @param __pos Index of character to search from (default 0). -: 2516: * @return Index of first occurrence. -: 2517: */ -: 2518: template -: 2519: _If_sv<_Tp, size_type> -: 2520: find_first_of(const _Tp& __svt, size_type __pos = 0) const -: 2521: noexcept(is_same<_Tp, __sv_type>::value) -: 2522: { -: 2523: __sv_type __sv = __svt; -: 2524: return this->find_first_of(__sv.data(), __pos, __sv.size()); -: 2525: } -: 2526:#endif // C++17 -: 2527: -: 2528: /** -: 2529: * @brief Find position of a character of C substring. -: 2530: * @param __s String containing characters to locate. -: 2531: * @param __pos Index of character to search from. -: 2532: * @param __n Number of characters from s to search for. -: 2533: * @return Index of first occurrence. -: 2534: * -: 2535: * Starting from @a __pos, searches forward for one of the -: 2536: * first @a __n characters of @a __s within this string. If -: 2537: * found, returns the index where it was found. If not found, -: 2538: * returns npos. -: 2539: */ -: 2540: size_type -: 2541: find_first_of(const _CharT* __s, size_type __pos, size_type __n) const -: 2542: _GLIBCXX_NOEXCEPT; -: 2543: -: 2544: /** -: 2545: * @brief Find position of a character of C string. -: 2546: * @param __s String containing characters to locate. -: 2547: * @param __pos Index of character to search from (default 0). -: 2548: * @return Index of first occurrence. -: 2549: * -: 2550: * Starting from @a __pos, searches forward for one of the -: 2551: * characters of @a __s within this string. If found, returns -: 2552: * the index where it was found. If not found, returns npos. -: 2553: */ -: 2554: size_type -: 2555: find_first_of(const _CharT* __s, size_type __pos = 0) const -: 2556: _GLIBCXX_NOEXCEPT -: 2557: { -: 2558: __glibcxx_requires_string(__s); -: 2559: return this->find_first_of(__s, __pos, traits_type::length(__s)); -: 2560: } -: 2561: -: 2562: /** -: 2563: * @brief Find position of a character. -: 2564: * @param __c Character to locate. -: 2565: * @param __pos Index of character to search from (default 0). -: 2566: * @return Index of first occurrence. -: 2567: * -: 2568: * Starting from @a __pos, searches forward for the character -: 2569: * @a __c within this string. If found, returns the index -: 2570: * where it was found. If not found, returns npos. -: 2571: * -: 2572: * Note: equivalent to find(__c, __pos). -: 2573: */ -: 2574: size_type -: 2575: find_first_of(_CharT __c, size_type __pos = 0) const _GLIBCXX_NOEXCEPT -: 2576: { return this->find(__c, __pos); } -: 2577: -: 2578: /** -: 2579: * @brief Find last position of a character of string. -: 2580: * @param __str String containing characters to locate. -: 2581: * @param __pos Index of character to search back from (default end). -: 2582: * @return Index of last occurrence. -: 2583: * -: 2584: * Starting from @a __pos, searches backward for one of the -: 2585: * characters of @a __str within this string. If found, -: 2586: * returns the index where it was found. If not found, returns -: 2587: * npos. -: 2588: */ -: 2589: size_type -: 2590: find_last_of(const basic_string& __str, size_type __pos = npos) const -: 2591: _GLIBCXX_NOEXCEPT -: 2592: { return this->find_last_of(__str.data(), __pos, __str.size()); } -: 2593: -: 2594:#if __cplusplus >= 201703L -: 2595: /** -: 2596: * @brief Find last position of a character of string. -: 2597: * @param __svt An object convertible to string_view containing -: 2598: * characters to locate. -: 2599: * @param __pos Index of character to search back from (default end). -: 2600: * @return Index of last occurrence. -: 2601: */ -: 2602: template -: 2603: _If_sv<_Tp, size_type> -: 2604: find_last_of(const _Tp& __svt, size_type __pos = npos) const -: 2605: noexcept(is_same<_Tp, __sv_type>::value) -: 2606: { -: 2607: __sv_type __sv = __svt; -: 2608: return this->find_last_of(__sv.data(), __pos, __sv.size()); -: 2609: } -: 2610:#endif // C++17 -: 2611: -: 2612: /** -: 2613: * @brief Find last position of a character of C substring. -: 2614: * @param __s C string containing characters to locate. -: 2615: * @param __pos Index of character to search back from. -: 2616: * @param __n Number of characters from s to search for. -: 2617: * @return Index of last occurrence. -: 2618: * -: 2619: * Starting from @a __pos, searches backward for one of the -: 2620: * first @a __n characters of @a __s within this string. If -: 2621: * found, returns the index where it was found. If not found, -: 2622: * returns npos. -: 2623: */ -: 2624: size_type -: 2625: find_last_of(const _CharT* __s, size_type __pos, size_type __n) const -: 2626: _GLIBCXX_NOEXCEPT; -: 2627: -: 2628: /** -: 2629: * @brief Find last position of a character of C string. -: 2630: * @param __s C string containing characters to locate. -: 2631: * @param __pos Index of character to search back from (default end). -: 2632: * @return Index of last occurrence. -: 2633: * -: 2634: * Starting from @a __pos, searches backward for one of the -: 2635: * characters of @a __s within this string. If found, returns -: 2636: * the index where it was found. If not found, returns npos. -: 2637: */ -: 2638: size_type -: 2639: find_last_of(const _CharT* __s, size_type __pos = npos) const -: 2640: _GLIBCXX_NOEXCEPT -: 2641: { -: 2642: __glibcxx_requires_string(__s); -: 2643: return this->find_last_of(__s, __pos, traits_type::length(__s)); -: 2644: } -: 2645: -: 2646: /** -: 2647: * @brief Find last position of a character. -: 2648: * @param __c Character to locate. -: 2649: * @param __pos Index of character to search back from (default end). -: 2650: * @return Index of last occurrence. -: 2651: * -: 2652: * Starting from @a __pos, searches backward for @a __c within -: 2653: * this string. If found, returns the index where it was -: 2654: * found. If not found, returns npos. -: 2655: * -: 2656: * Note: equivalent to rfind(__c, __pos). -: 2657: */ -: 2658: size_type -: 2659: find_last_of(_CharT __c, size_type __pos = npos) const _GLIBCXX_NOEXCEPT -: 2660: { return this->rfind(__c, __pos); } -: 2661: -: 2662: /** -: 2663: * @brief Find position of a character not in string. -: 2664: * @param __str String containing characters to avoid. -: 2665: * @param __pos Index of character to search from (default 0). -: 2666: * @return Index of first occurrence. -: 2667: * -: 2668: * Starting from @a __pos, searches forward for a character not contained -: 2669: * in @a __str within this string. If found, returns the index where it -: 2670: * was found. If not found, returns npos. -: 2671: */ -: 2672: size_type -: 2673: find_first_not_of(const basic_string& __str, size_type __pos = 0) const -: 2674: _GLIBCXX_NOEXCEPT -: 2675: { return this->find_first_not_of(__str.data(), __pos, __str.size()); } -: 2676: -: 2677:#if __cplusplus >= 201703L -: 2678: /** -: 2679: * @brief Find position of a character not in a string_view. -: 2680: * @param __svt A object convertible to string_view containing -: 2681: * characters to avoid. -: 2682: * @param __pos Index of character to search from (default 0). -: 2683: * @return Index of first occurrence. -: 2684: */ -: 2685: template -: 2686: _If_sv<_Tp, size_type> -: 2687: find_first_not_of(const _Tp& __svt, size_type __pos = 0) const -: 2688: noexcept(is_same<_Tp, __sv_type>::value) -: 2689: { -: 2690: __sv_type __sv = __svt; -: 2691: return this->find_first_not_of(__sv.data(), __pos, __sv.size()); -: 2692: } -: 2693:#endif // C++17 -: 2694: -: 2695: /** -: 2696: * @brief Find position of a character not in C substring. -: 2697: * @param __s C string containing characters to avoid. -: 2698: * @param __pos Index of character to search from. -: 2699: * @param __n Number of characters from __s to consider. -: 2700: * @return Index of first occurrence. -: 2701: * -: 2702: * Starting from @a __pos, searches forward for a character not -: 2703: * contained in the first @a __n characters of @a __s within -: 2704: * this string. If found, returns the index where it was -: 2705: * found. If not found, returns npos. -: 2706: */ -: 2707: size_type -: 2708: find_first_not_of(const _CharT* __s, size_type __pos, -: 2709: size_type __n) const _GLIBCXX_NOEXCEPT; -: 2710: -: 2711: /** -: 2712: * @brief Find position of a character not in C string. -: 2713: * @param __s C string containing characters to avoid. -: 2714: * @param __pos Index of character to search from (default 0). -: 2715: * @return Index of first occurrence. -: 2716: * -: 2717: * Starting from @a __pos, searches forward for a character not -: 2718: * contained in @a __s within this string. If found, returns -: 2719: * the index where it was found. If not found, returns npos. -: 2720: */ -: 2721: size_type -: 2722: find_first_not_of(const _CharT* __s, size_type __pos = 0) const -: 2723: _GLIBCXX_NOEXCEPT -: 2724: { -: 2725: __glibcxx_requires_string(__s); -: 2726: return this->find_first_not_of(__s, __pos, traits_type::length(__s)); -: 2727: } -: 2728: -: 2729: /** -: 2730: * @brief Find position of a different character. -: 2731: * @param __c Character to avoid. -: 2732: * @param __pos Index of character to search from (default 0). -: 2733: * @return Index of first occurrence. -: 2734: * -: 2735: * Starting from @a __pos, searches forward for a character -: 2736: * other than @a __c within this string. If found, returns the -: 2737: * index where it was found. If not found, returns npos. -: 2738: */ -: 2739: size_type -: 2740: find_first_not_of(_CharT __c, size_type __pos = 0) const -: 2741: _GLIBCXX_NOEXCEPT; -: 2742: -: 2743: /** -: 2744: * @brief Find last position of a character not in string. -: 2745: * @param __str String containing characters to avoid. -: 2746: * @param __pos Index of character to search back from (default end). -: 2747: * @return Index of last occurrence. -: 2748: * -: 2749: * Starting from @a __pos, searches backward for a character -: 2750: * not contained in @a __str within this string. If found, -: 2751: * returns the index where it was found. If not found, returns -: 2752: * npos. -: 2753: */ -: 2754: size_type -: 2755: find_last_not_of(const basic_string& __str, size_type __pos = npos) const -: 2756: _GLIBCXX_NOEXCEPT -: 2757: { return this->find_last_not_of(__str.data(), __pos, __str.size()); } -: 2758: -: 2759:#if __cplusplus >= 201703L -: 2760: /** -: 2761: * @brief Find last position of a character not in a string_view. -: 2762: * @param __svt An object convertible to string_view containing -: 2763: * characters to avoid. -: 2764: * @param __pos Index of character to search back from (default end). -: 2765: * @return Index of last occurrence. -: 2766: */ -: 2767: template -: 2768: _If_sv<_Tp, size_type> -: 2769: find_last_not_of(const _Tp& __svt, size_type __pos = npos) const -: 2770: noexcept(is_same<_Tp, __sv_type>::value) -: 2771: { -: 2772: __sv_type __sv = __svt; -: 2773: return this->find_last_not_of(__sv.data(), __pos, __sv.size()); -: 2774: } -: 2775:#endif // C++17 -: 2776: -: 2777: /** -: 2778: * @brief Find last position of a character not in C substring. -: 2779: * @param __s C string containing characters to avoid. -: 2780: * @param __pos Index of character to search back from. -: 2781: * @param __n Number of characters from s to consider. -: 2782: * @return Index of last occurrence. -: 2783: * -: 2784: * Starting from @a __pos, searches backward for a character not -: 2785: * contained in the first @a __n characters of @a __s within this string. -: 2786: * If found, returns the index where it was found. If not found, -: 2787: * returns npos. -: 2788: */ -: 2789: size_type -: 2790: find_last_not_of(const _CharT* __s, size_type __pos, -: 2791: size_type __n) const _GLIBCXX_NOEXCEPT; -: 2792: /** -: 2793: * @brief Find last position of a character not in C string. -: 2794: * @param __s C string containing characters to avoid. -: 2795: * @param __pos Index of character to search back from (default end). -: 2796: * @return Index of last occurrence. -: 2797: * -: 2798: * Starting from @a __pos, searches backward for a character -: 2799: * not contained in @a __s within this string. If found, -: 2800: * returns the index where it was found. If not found, returns -: 2801: * npos. -: 2802: */ -: 2803: size_type -: 2804: find_last_not_of(const _CharT* __s, size_type __pos = npos) const -: 2805: _GLIBCXX_NOEXCEPT -: 2806: { -: 2807: __glibcxx_requires_string(__s); -: 2808: return this->find_last_not_of(__s, __pos, traits_type::length(__s)); -: 2809: } -: 2810: -: 2811: /** -: 2812: * @brief Find last position of a different character. -: 2813: * @param __c Character to avoid. -: 2814: * @param __pos Index of character to search back from (default end). -: 2815: * @return Index of last occurrence. -: 2816: * -: 2817: * Starting from @a __pos, searches backward for a character other than -: 2818: * @a __c within this string. If found, returns the index where it was -: 2819: * found. If not found, returns npos. -: 2820: */ -: 2821: size_type -: 2822: find_last_not_of(_CharT __c, size_type __pos = npos) const -: 2823: _GLIBCXX_NOEXCEPT; -: 2824: -: 2825: /** -: 2826: * @brief Get a substring. -: 2827: * @param __pos Index of first character (default 0). -: 2828: * @param __n Number of characters in substring (default remainder). -: 2829: * @return The new string. -: 2830: * @throw std::out_of_range If __pos > size(). -: 2831: * -: 2832: * Construct and return a new string using the @a __n -: 2833: * characters starting at @a __pos. If the string is too -: 2834: * short, use the remainder of the characters. If @a __pos is -: 2835: * beyond the end of the string, out_of_range is thrown. -: 2836: */ -: 2837: basic_string -: 2838: substr(size_type __pos = 0, size_type __n = npos) const -: 2839: { return basic_string(*this, -: 2840: _M_check(__pos, "basic_string::substr"), __n); } -: 2841: -: 2842: /** -: 2843: * @brief Compare to a string. -: 2844: * @param __str String to compare against. -: 2845: * @return Integer < 0, 0, or > 0. -: 2846: * -: 2847: * Returns an integer < 0 if this string is ordered before @a -: 2848: * __str, 0 if their values are equivalent, or > 0 if this -: 2849: * string is ordered after @a __str. Determines the effective -: 2850: * length rlen of the strings to compare as the smallest of -: 2851: * size() and str.size(). The function then compares the two -: 2852: * strings by calling traits::compare(data(), str.data(),rlen). -: 2853: * If the result of the comparison is nonzero returns it, -: 2854: * otherwise the shorter one is ordered first. -: 2855: */ -: 2856: int -: 2857: compare(const basic_string& __str) const -: 2858: { -: 2859: const size_type __size = this->size(); -: 2860: const size_type __osize = __str.size(); -: 2861: const size_type __len = std::min(__size, __osize); -: 2862: -: 2863: int __r = traits_type::compare(_M_data(), __str.data(), __len); -: 2864: if (!__r) -: 2865: __r = _S_compare(__size, __osize); -: 2866: return __r; -: 2867: } -: 2868: -: 2869:#if __cplusplus >= 201703L -: 2870: /** -: 2871: * @brief Compare to a string_view. -: 2872: * @param __svt An object convertible to string_view to compare against. -: 2873: * @return Integer < 0, 0, or > 0. -: 2874: */ -: 2875: template -: 2876: _If_sv<_Tp, int> -: 2877: compare(const _Tp& __svt) const -: 2878: noexcept(is_same<_Tp, __sv_type>::value) -: 2879: { -: 2880: __sv_type __sv = __svt; -: 2881: const size_type __size = this->size(); -: 2882: const size_type __osize = __sv.size(); -: 2883: const size_type __len = std::min(__size, __osize); -: 2884: -: 2885: int __r = traits_type::compare(_M_data(), __sv.data(), __len); -: 2886: if (!__r) -: 2887: __r = _S_compare(__size, __osize); -: 2888: return __r; -: 2889: } -: 2890: -: 2891: /** -: 2892: * @brief Compare to a string_view. -: 2893: * @param __pos A position in the string to start comparing from. -: 2894: * @param __n The number of characters to compare. -: 2895: * @param __svt An object convertible to string_view to compare -: 2896: * against. -: 2897: * @return Integer < 0, 0, or > 0. -: 2898: */ -: 2899: template -: 2900: _If_sv<_Tp, int> -: 2901: compare(size_type __pos, size_type __n, const _Tp& __svt) const -: 2902: noexcept(is_same<_Tp, __sv_type>::value) -: 2903: { -: 2904: __sv_type __sv = __svt; -: 2905: return __sv_type(*this).substr(__pos, __n).compare(__sv); -: 2906: } -: 2907: -: 2908: /** -: 2909: * @brief Compare to a string_view. -: 2910: * @param __pos1 A position in the string to start comparing from. -: 2911: * @param __n1 The number of characters to compare. -: 2912: * @param __svt An object convertible to string_view to compare -: 2913: * against. -: 2914: * @param __pos2 A position in the string_view to start comparing from. -: 2915: * @param __n2 The number of characters to compare. -: 2916: * @return Integer < 0, 0, or > 0. -: 2917: */ -: 2918: template -: 2919: _If_sv<_Tp, int> -: 2920: compare(size_type __pos1, size_type __n1, const _Tp& __svt, -: 2921: size_type __pos2, size_type __n2 = npos) const -: 2922: noexcept(is_same<_Tp, __sv_type>::value) -: 2923: { -: 2924: __sv_type __sv = __svt; -: 2925: return __sv_type(*this) -: 2926: .substr(__pos1, __n1).compare(__sv.substr(__pos2, __n2)); -: 2927: } -: 2928:#endif // C++17 -: 2929: -: 2930: /** -: 2931: * @brief Compare substring to a string. -: 2932: * @param __pos Index of first character of substring. -: 2933: * @param __n Number of characters in substring. -: 2934: * @param __str String to compare against. -: 2935: * @return Integer < 0, 0, or > 0. -: 2936: * -: 2937: * Form the substring of this string from the @a __n characters -: 2938: * starting at @a __pos. Returns an integer < 0 if the -: 2939: * substring is ordered before @a __str, 0 if their values are -: 2940: * equivalent, or > 0 if the substring is ordered after @a -: 2941: * __str. Determines the effective length rlen of the strings -: 2942: * to compare as the smallest of the length of the substring -: 2943: * and @a __str.size(). The function then compares the two -: 2944: * strings by calling -: 2945: * traits::compare(substring.data(),str.data(),rlen). If the -: 2946: * result of the comparison is nonzero returns it, otherwise -: 2947: * the shorter one is ordered first. -: 2948: */ -: 2949: int -: 2950: compare(size_type __pos, size_type __n, const basic_string& __str) const; -: 2951: -: 2952: /** -: 2953: * @brief Compare substring to a substring. -: 2954: * @param __pos1 Index of first character of substring. -: 2955: * @param __n1 Number of characters in substring. -: 2956: * @param __str String to compare against. -: 2957: * @param __pos2 Index of first character of substring of str. -: 2958: * @param __n2 Number of characters in substring of str. -: 2959: * @return Integer < 0, 0, or > 0. -: 2960: * -: 2961: * Form the substring of this string from the @a __n1 -: 2962: * characters starting at @a __pos1. Form the substring of @a -: 2963: * __str from the @a __n2 characters starting at @a __pos2. -: 2964: * Returns an integer < 0 if this substring is ordered before -: 2965: * the substring of @a __str, 0 if their values are equivalent, -: 2966: * or > 0 if this substring is ordered after the substring of -: 2967: * @a __str. Determines the effective length rlen of the -: 2968: * strings to compare as the smallest of the lengths of the -: 2969: * substrings. The function then compares the two strings by -: 2970: * calling -: 2971: * traits::compare(substring.data(),str.substr(pos2,n2).data(),rlen). -: 2972: * If the result of the comparison is nonzero returns it, -: 2973: * otherwise the shorter one is ordered first. -: 2974: */ -: 2975: int -: 2976: compare(size_type __pos1, size_type __n1, const basic_string& __str, -: 2977: size_type __pos2, size_type __n2 = npos) const; -: 2978: -: 2979: /** -: 2980: * @brief Compare to a C string. -: 2981: * @param __s C string to compare against. -: 2982: * @return Integer < 0, 0, or > 0. -: 2983: * -: 2984: * Returns an integer < 0 if this string is ordered before @a __s, 0 if -: 2985: * their values are equivalent, or > 0 if this string is ordered after -: 2986: * @a __s. Determines the effective length rlen of the strings to -: 2987: * compare as the smallest of size() and the length of a string -: 2988: * constructed from @a __s. The function then compares the two strings -: 2989: * by calling traits::compare(data(),s,rlen). If the result of the -: 2990: * comparison is nonzero returns it, otherwise the shorter one is -: 2991: * ordered first. -: 2992: */ -: 2993: int -: 2994: compare(const _CharT* __s) const _GLIBCXX_NOEXCEPT; -: 2995: -: 2996: // _GLIBCXX_RESOLVE_LIB_DEFECTS -: 2997: // 5 String::compare specification questionable -: 2998: /** -: 2999: * @brief Compare substring to a C string. -: 3000: * @param __pos Index of first character of substring. -: 3001: * @param __n1 Number of characters in substring. -: 3002: * @param __s C string to compare against. -: 3003: * @return Integer < 0, 0, or > 0. -: 3004: * -: 3005: * Form the substring of this string from the @a __n1 -: 3006: * characters starting at @a pos. Returns an integer < 0 if -: 3007: * the substring is ordered before @a __s, 0 if their values -: 3008: * are equivalent, or > 0 if the substring is ordered after @a -: 3009: * __s. Determines the effective length rlen of the strings to -: 3010: * compare as the smallest of the length of the substring and -: 3011: * the length of a string constructed from @a __s. The -: 3012: * function then compares the two string by calling -: 3013: * traits::compare(substring.data(),__s,rlen). If the result of -: 3014: * the comparison is nonzero returns it, otherwise the shorter -: 3015: * one is ordered first. -: 3016: */ -: 3017: int -: 3018: compare(size_type __pos, size_type __n1, const _CharT* __s) const; -: 3019: -: 3020: /** -: 3021: * @brief Compare substring against a character %array. -: 3022: * @param __pos Index of first character of substring. -: 3023: * @param __n1 Number of characters in substring. -: 3024: * @param __s character %array to compare against. -: 3025: * @param __n2 Number of characters of s. -: 3026: * @return Integer < 0, 0, or > 0. -: 3027: * -: 3028: * Form the substring of this string from the @a __n1 -: 3029: * characters starting at @a __pos. Form a string from the -: 3030: * first @a __n2 characters of @a __s. Returns an integer < 0 -: 3031: * if this substring is ordered before the string from @a __s, -: 3032: * 0 if their values are equivalent, or > 0 if this substring -: 3033: * is ordered after the string from @a __s. Determines the -: 3034: * effective length rlen of the strings to compare as the -: 3035: * smallest of the length of the substring and @a __n2. The -: 3036: * function then compares the two strings by calling -: 3037: * traits::compare(substring.data(),s,rlen). If the result of -: 3038: * the comparison is nonzero returns it, otherwise the shorter -: 3039: * one is ordered first. -: 3040: * -: 3041: * NB: s must have at least n2 characters, '\\0' has -: 3042: * no special meaning. -: 3043: */ -: 3044: int -: 3045: compare(size_type __pos, size_type __n1, const _CharT* __s, -: 3046: size_type __n2) const; -: 3047: -: 3048:#if __cplusplus > 201703L -: 3049: bool -: 3050: starts_with(basic_string_view<_CharT, _Traits> __x) const noexcept -: 3051: { return __sv_type(this->data(), this->size()).starts_with(__x); } -: 3052: -: 3053: bool -: 3054: starts_with(_CharT __x) const noexcept -: 3055: { return __sv_type(this->data(), this->size()).starts_with(__x); } -: 3056: -: 3057: bool -: 3058: starts_with(const _CharT* __x) const noexcept -: 3059: { return __sv_type(this->data(), this->size()).starts_with(__x); } -: 3060: -: 3061: bool -: 3062: ends_with(basic_string_view<_CharT, _Traits> __x) const noexcept -: 3063: { return __sv_type(this->data(), this->size()).ends_with(__x); } -: 3064: -: 3065: bool -: 3066: ends_with(_CharT __x) const noexcept -: 3067: { return __sv_type(this->data(), this->size()).ends_with(__x); } -: 3068: -: 3069: bool -: 3070: ends_with(const _CharT* __x) const noexcept -: 3071: { return __sv_type(this->data(), this->size()).ends_with(__x); } -: 3072:#endif // C++20 -: 3073: -: 3074: // Allow basic_stringbuf::__xfer_bufptrs to call _M_length: -: 3075: template friend class basic_stringbuf; -: 3076: }; -: 3077:_GLIBCXX_END_NAMESPACE_CXX11 -: 3078:#else // !_GLIBCXX_USE_CXX11_ABI -: 3079: // Reference-counted COW string implentation -: 3080: -: 3081: /** -: 3082: * @class basic_string basic_string.h -: 3083: * @brief Managing sequences of characters and character-like objects. -: 3084: * -: 3085: * @ingroup strings -: 3086: * @ingroup sequences -: 3087: * -: 3088: * @tparam _CharT Type of character -: 3089: * @tparam _Traits Traits for character type, defaults to -: 3090: * char_traits<_CharT>. -: 3091: * @tparam _Alloc Allocator type, defaults to allocator<_CharT>. -: 3092: * -: 3093: * Meets the requirements of a container, a -: 3094: * reversible container, and a -: 3095: * sequence. Of the -: 3096: * optional sequence requirements, only -: 3097: * @c push_back, @c at, and @c %array access are supported. -: 3098: * -: 3099: * @doctodo -: 3100: * -: 3101: * -: 3102: * Documentation? What's that? -: 3103: * Nathan Myers . -: 3104: * -: 3105: * A string looks like this: -: 3106: * -: 3107: * @code -: 3108: * [_Rep] -: 3109: * _M_length -: 3110: * [basic_string] _M_capacity -: 3111: * _M_dataplus _M_refcount -: 3112: * _M_p ----------------> unnamed array of char_type -: 3113: * @endcode -: 3114: * -: 3115: * Where the _M_p points to the first character in the string, and -: 3116: * you cast it to a pointer-to-_Rep and subtract 1 to get a -: 3117: * pointer to the header. -: 3118: * -: 3119: * This approach has the enormous advantage that a string object -: 3120: * requires only one allocation. All the ugliness is confined -: 3121: * within a single %pair of inline functions, which each compile to -: 3122: * a single @a add instruction: _Rep::_M_data(), and -: 3123: * string::_M_rep(); and the allocation function which gets a -: 3124: * block of raw bytes and with room enough and constructs a _Rep -: 3125: * object at the front. -: 3126: * -: 3127: * The reason you want _M_data pointing to the character %array and -: 3128: * not the _Rep is so that the debugger can see the string -: 3129: * contents. (Probably we should add a non-inline member to get -: 3130: * the _Rep for the debugger to use, so users can check the actual -: 3131: * string length.) -: 3132: * -: 3133: * Note that the _Rep object is a POD so that you can have a -: 3134: * static empty string _Rep object already @a constructed before -: 3135: * static constructors have run. The reference-count encoding is -: 3136: * chosen so that a 0 indicates one reference, so you never try to -: 3137: * destroy the empty-string _Rep object. -: 3138: * -: 3139: * All but the last paragraph is considered pretty conventional -: 3140: * for a C++ string implementation. -: 3141: */ -: 3142: // 21.3 Template class basic_string -: 3143: template -: 3144: class basic_string -: 3145: { -: 3146: typedef typename _Alloc::template rebind<_CharT>::other _CharT_alloc_type; -: 3147: -: 3148: // Types: -: 3149: public: -: 3150: typedef _Traits traits_type; -: 3151: typedef typename _Traits::char_type value_type; -: 3152: typedef _Alloc allocator_type; -: 3153: typedef typename _CharT_alloc_type::size_type size_type; -: 3154: typedef typename _CharT_alloc_type::difference_type difference_type; -: 3155:#if __cplusplus < 201103L -: 3156: typedef typename _CharT_alloc_type::reference reference; -: 3157: typedef typename _CharT_alloc_type::const_reference const_reference; -: 3158:#else -: 3159: typedef value_type& reference; -: 3160: typedef const value_type& const_reference; -: 3161:#endif -: 3162: typedef typename _CharT_alloc_type::pointer pointer; -: 3163: typedef typename _CharT_alloc_type::const_pointer const_pointer; -: 3164: typedef __gnu_cxx::__normal_iterator iterator; -: 3165: typedef __gnu_cxx::__normal_iterator -: 3166: const_iterator; -: 3167: typedef std::reverse_iterator const_reverse_iterator; -: 3168: typedef std::reverse_iterator reverse_iterator; -: 3169: -: 3170: protected: -: 3171: // type used for positions in insert, erase etc. -: 3172: typedef iterator __const_iterator; -: 3173: -: 3174: private: -: 3175: // _Rep: string representation -: 3176: // Invariants: -: 3177: // 1. String really contains _M_length + 1 characters: due to 21.3.4 -: 3178: // must be kept null-terminated. -: 3179: // 2. _M_capacity >= _M_length -: 3180: // Allocated memory is always (_M_capacity + 1) * sizeof(_CharT). -: 3181: // 3. _M_refcount has three states: -: 3182: // -1: leaked, one reference, no ref-copies allowed, non-const. -: 3183: // 0: one reference, non-const. -: 3184: // n>0: n + 1 references, operations require a lock, const. -: 3185: // 4. All fields==0 is an empty string, given the extra storage -: 3186: // beyond-the-end for a null terminator; thus, the shared -: 3187: // empty string representation needs no constructor. -: 3188: -: 3189: struct _Rep_base -: 3190: { -: 3191: size_type _M_length; -: 3192: size_type _M_capacity; -: 3193: _Atomic_word _M_refcount; -: 3194: }; -: 3195: -: 3196: struct _Rep : _Rep_base -: 3197: { -: 3198: // Types: -: 3199: typedef typename _Alloc::template rebind::other _Raw_bytes_alloc; -: 3200: -: 3201: // (Public) Data members: -: 3202: -: 3203: // The maximum number of individual char_type elements of an -: 3204: // individual string is determined by _S_max_size. This is the -: 3205: // value that will be returned by max_size(). (Whereas npos -: 3206: // is the maximum number of bytes the allocator can allocate.) -: 3207: // If one was to divvy up the theoretical largest size string, -: 3208: // with a terminating character and m _CharT elements, it'd -: 3209: // look like this: -: 3210: // npos = sizeof(_Rep) + (m * sizeof(_CharT)) + sizeof(_CharT) -: 3211: // Solving for m: -: 3212: // m = ((npos - sizeof(_Rep))/sizeof(CharT)) - 1 -: 3213: // In addition, this implementation quarters this amount. -: 3214: static const size_type _S_max_size; -: 3215: static const _CharT _S_terminal; -: 3216: -: 3217: // The following storage is init'd to 0 by the linker, resulting -: 3218: // (carefully) in an empty string with one reference. -: 3219: static size_type _S_empty_rep_storage[]; -: 3220: -: 3221: static _Rep& -: 3222: _S_empty_rep() _GLIBCXX_NOEXCEPT -: 3223: { -: 3224: // NB: Mild hack to avoid strict-aliasing warnings. Note that -: 3225: // _S_empty_rep_storage is never modified and the punning should -: 3226: // be reasonably safe in this case. -: 3227: void* __p = reinterpret_cast(&_S_empty_rep_storage); -: 3228: return *reinterpret_cast<_Rep*>(__p); -: 3229: } -: 3230: -: 3231: bool -: 3232: _M_is_leaked() const _GLIBCXX_NOEXCEPT -: 3233: { -: 3234:#if defined(__GTHREADS) -: 3235: // _M_refcount is mutated concurrently by _M_refcopy/_M_dispose, -: 3236: // so we need to use an atomic load. However, _M_is_leaked -: 3237: // predicate does not change concurrently (i.e. the string is either -: 3238: // leaked or not), so a relaxed load is enough. -: 3239: return __atomic_load_n(&this->_M_refcount, __ATOMIC_RELAXED) < 0; -: 3240:#else -: 3241: return this->_M_refcount < 0; -: 3242:#endif -: 3243: } -: 3244: -: 3245: bool -: 3246: _M_is_shared() const _GLIBCXX_NOEXCEPT -: 3247: { -: 3248:#if defined(__GTHREADS) -: 3249: // _M_refcount is mutated concurrently by _M_refcopy/_M_dispose, -: 3250: // so we need to use an atomic load. Another thread can drop last -: 3251: // but one reference concurrently with this check, so we need this -: 3252: // load to be acquire to synchronize with release fetch_and_add in -: 3253: // _M_dispose. -: 3254: return __atomic_load_n(&this->_M_refcount, __ATOMIC_ACQUIRE) > 0; -: 3255:#else -: 3256: return this->_M_refcount > 0; -: 3257:#endif -: 3258: } -: 3259: -: 3260: void -: 3261: _M_set_leaked() _GLIBCXX_NOEXCEPT -: 3262: { this->_M_refcount = -1; } -: 3263: -: 3264: void -: 3265: _M_set_sharable() _GLIBCXX_NOEXCEPT -: 3266: { this->_M_refcount = 0; } -: 3267: -: 3268: void -: 3269: _M_set_length_and_sharable(size_type __n) _GLIBCXX_NOEXCEPT -: 3270: { -: 3271:#if _GLIBCXX_FULLY_DYNAMIC_STRING == 0 -: 3272: if (__builtin_expect(this != &_S_empty_rep(), false)) -: 3273:#endif -: 3274: { -: 3275: this->_M_set_sharable(); // One reference. -: 3276: this->_M_length = __n; -: 3277: traits_type::assign(this->_M_refdata()[__n], _S_terminal); -: 3278: // grrr. (per 21.3.4) -: 3279: // You cannot leave those LWG people alone for a second. -: 3280: } -: 3281: } -: 3282: -: 3283: _CharT* -: 3284: _M_refdata() throw() -: 3285: { return reinterpret_cast<_CharT*>(this + 1); } -: 3286: -: 3287: _CharT* -: 3288: _M_grab(const _Alloc& __alloc1, const _Alloc& __alloc2) -: 3289: { -: 3290: return (!_M_is_leaked() && __alloc1 == __alloc2) -: 3291: ? _M_refcopy() : _M_clone(__alloc1); -: 3292: } -: 3293: -: 3294: // Create & Destroy -: 3295: static _Rep* -: 3296: _S_create(size_type, size_type, const _Alloc&); -: 3297: -: 3298: void -: 3299: _M_dispose(const _Alloc& __a) _GLIBCXX_NOEXCEPT -: 3300: { -: 3301:#if _GLIBCXX_FULLY_DYNAMIC_STRING == 0 -: 3302: if (__builtin_expect(this != &_S_empty_rep(), false)) -: 3303:#endif -: 3304: { -: 3305: // Be race-detector-friendly. For more info see bits/c++config. -: 3306: _GLIBCXX_SYNCHRONIZATION_HAPPENS_BEFORE(&this->_M_refcount); -: 3307: // Decrement of _M_refcount is acq_rel, because: -: 3308: // - all but last decrements need to release to synchronize with -: 3309: // the last decrement that will delete the object. -: 3310: // - the last decrement needs to acquire to synchronize with -: 3311: // all the previous decrements. -: 3312: // - last but one decrement needs to release to synchronize with -: 3313: // the acquire load in _M_is_shared that will conclude that -: 3314: // the object is not shared anymore. -: 3315: if (__gnu_cxx::__exchange_and_add_dispatch(&this->_M_refcount, -: 3316: -1) <= 0) -: 3317: { -: 3318: _GLIBCXX_SYNCHRONIZATION_HAPPENS_AFTER(&this->_M_refcount); -: 3319: _M_destroy(__a); -: 3320: } -: 3321: } -: 3322: } // XXX MT -: 3323: -: 3324: void -: 3325: _M_destroy(const _Alloc&) throw(); -: 3326: -: 3327: _CharT* -: 3328: _M_refcopy() throw() -: 3329: { -: 3330:#if _GLIBCXX_FULLY_DYNAMIC_STRING == 0 -: 3331: if (__builtin_expect(this != &_S_empty_rep(), false)) -: 3332:#endif -: 3333: __gnu_cxx::__atomic_add_dispatch(&this->_M_refcount, 1); -: 3334: return _M_refdata(); -: 3335: } // XXX MT -: 3336: -: 3337: _CharT* -: 3338: _M_clone(const _Alloc&, size_type __res = 0); -: 3339: }; -: 3340: -: 3341: // Use empty-base optimization: http://www.cantrip.org/emptyopt.html -: 3342: struct _Alloc_hider : _Alloc -: 3343: { -: 3344: _Alloc_hider(_CharT* __dat, const _Alloc& __a) _GLIBCXX_NOEXCEPT -: 3345: : _Alloc(__a), _M_p(__dat) { } -: 3346: -: 3347: _CharT* _M_p; // The actual data. -: 3348: }; -: 3349: -: 3350: public: -: 3351: // Data Members (public): -: 3352: // NB: This is an unsigned type, and thus represents the maximum -: 3353: // size that the allocator can hold. -: 3354: /// Value returned by various member functions when they fail. -: 3355: static const size_type npos = static_cast(-1); -: 3356: -: 3357: private: -: 3358: // Data Members (private): -: 3359: mutable _Alloc_hider _M_dataplus; -: 3360: -: 3361: _CharT* -: 3362: _M_data() const _GLIBCXX_NOEXCEPT -: 3363: { return _M_dataplus._M_p; } -: 3364: -: 3365: _CharT* -: 3366: _M_data(_CharT* __p) _GLIBCXX_NOEXCEPT -: 3367: { return (_M_dataplus._M_p = __p); } -: 3368: -: 3369: _Rep* -: 3370: _M_rep() const _GLIBCXX_NOEXCEPT -: 3371: { return &((reinterpret_cast<_Rep*> (_M_data()))[-1]); } -: 3372: -: 3373: // For the internal use we have functions similar to `begin'/`end' -: 3374: // but they do not call _M_leak. -: 3375: iterator -: 3376: _M_ibegin() const _GLIBCXX_NOEXCEPT -: 3377: { return iterator(_M_data()); } -: 3378: -: 3379: iterator -: 3380: _M_iend() const _GLIBCXX_NOEXCEPT -: 3381: { return iterator(_M_data() + this->size()); } -: 3382: -: 3383: void -: 3384: _M_leak() // for use in begin() & non-const op[] -: 3385: { -: 3386: if (!_M_rep()->_M_is_leaked()) -: 3387: _M_leak_hard(); -: 3388: } -: 3389: -: 3390: size_type -: 3391: _M_check(size_type __pos, const char* __s) const -: 3392: { -: 3393: if (__pos > this->size()) -: 3394: __throw_out_of_range_fmt(__N("%s: __pos (which is %zu) > " -: 3395: "this->size() (which is %zu)"), -: 3396: __s, __pos, this->size()); -: 3397: return __pos; -: 3398: } -: 3399: -: 3400: void -: 3401: _M_check_length(size_type __n1, size_type __n2, const char* __s) const -: 3402: { -: 3403: if (this->max_size() - (this->size() - __n1) < __n2) -: 3404: __throw_length_error(__N(__s)); -: 3405: } -: 3406: -: 3407: // NB: _M_limit doesn't check for a bad __pos value. -: 3408: size_type -: 3409: _M_limit(size_type __pos, size_type __off) const _GLIBCXX_NOEXCEPT -: 3410: { -: 3411: const bool __testoff = __off < this->size() - __pos; -: 3412: return __testoff ? __off : this->size() - __pos; -: 3413: } -: 3414: -: 3415: // True if _Rep and source do not overlap. -: 3416: bool -: 3417: _M_disjunct(const _CharT* __s) const _GLIBCXX_NOEXCEPT -: 3418: { -: 3419: return (less()(__s, _M_data()) -: 3420: || less()(_M_data() + this->size(), __s)); -: 3421: } -: 3422: -: 3423: // When __n = 1 way faster than the general multichar -: 3424: // traits_type::copy/move/assign. -: 3425: static void -: 3426: _M_copy(_CharT* __d, const _CharT* __s, size_type __n) _GLIBCXX_NOEXCEPT -: 3427: { -: 3428: if (__n == 1) -: 3429: traits_type::assign(*__d, *__s); -: 3430: else -: 3431: traits_type::copy(__d, __s, __n); -: 3432: } -: 3433: -: 3434: static void -: 3435: _M_move(_CharT* __d, const _CharT* __s, size_type __n) _GLIBCXX_NOEXCEPT -: 3436: { -: 3437: if (__n == 1) -: 3438: traits_type::assign(*__d, *__s); -: 3439: else -: 3440: traits_type::move(__d, __s, __n); -: 3441: } -: 3442: -: 3443: static void -: 3444: _M_assign(_CharT* __d, size_type __n, _CharT __c) _GLIBCXX_NOEXCEPT -: 3445: { -: 3446: if (__n == 1) -: 3447: traits_type::assign(*__d, __c); -: 3448: else -: 3449: traits_type::assign(__d, __n, __c); -: 3450: } -: 3451: -: 3452: // _S_copy_chars is a separate template to permit specialization -: 3453: // to optimize for the common case of pointers as iterators. -: 3454: template -: 3455: static void -: 3456: _S_copy_chars(_CharT* __p, _Iterator __k1, _Iterator __k2) -: 3457: { -: 3458: for (; __k1 != __k2; ++__k1, (void)++__p) -: 3459: traits_type::assign(*__p, *__k1); // These types are off. -: 3460: } -: 3461: -: 3462: static void -: 3463: _S_copy_chars(_CharT* __p, iterator __k1, iterator __k2) _GLIBCXX_NOEXCEPT -: 3464: { _S_copy_chars(__p, __k1.base(), __k2.base()); } -: 3465: -: 3466: static void -: 3467: _S_copy_chars(_CharT* __p, const_iterator __k1, const_iterator __k2) -: 3468: _GLIBCXX_NOEXCEPT -: 3469: { _S_copy_chars(__p, __k1.base(), __k2.base()); } -: 3470: -: 3471: static void -: 3472: _S_copy_chars(_CharT* __p, _CharT* __k1, _CharT* __k2) _GLIBCXX_NOEXCEPT -: 3473: { _M_copy(__p, __k1, __k2 - __k1); } -: 3474: -: 3475: static void -: 3476: _S_copy_chars(_CharT* __p, const _CharT* __k1, const _CharT* __k2) -: 3477: _GLIBCXX_NOEXCEPT -: 3478: { _M_copy(__p, __k1, __k2 - __k1); } -: 3479: -: 3480: static int -: 3481: _S_compare(size_type __n1, size_type __n2) _GLIBCXX_NOEXCEPT -: 3482: { -: 3483: const difference_type __d = difference_type(__n1 - __n2); -: 3484: -: 3485: if (__d > __gnu_cxx::__numeric_traits::__max) -: 3486: return __gnu_cxx::__numeric_traits::__max; -: 3487: else if (__d < __gnu_cxx::__numeric_traits::__min) -: 3488: return __gnu_cxx::__numeric_traits::__min; -: 3489: else -: 3490: return int(__d); -: 3491: } -: 3492: -: 3493: void -: 3494: _M_mutate(size_type __pos, size_type __len1, size_type __len2); -: 3495: -: 3496: void -: 3497: _M_leak_hard(); -: 3498: -: 3499: static _Rep& -: 3500: _S_empty_rep() _GLIBCXX_NOEXCEPT -: 3501: { return _Rep::_S_empty_rep(); } -: 3502: -: 3503:#if __cplusplus >= 201703L -: 3504: // A helper type for avoiding boiler-plate. -: 3505: typedef basic_string_view<_CharT, _Traits> __sv_type; -: 3506: -: 3507: template -: 3508: using _If_sv = enable_if_t< -: 3509: __and_, -: 3510: __not_>, -: 3511: __not_>>::value, -: 3512: _Res>; -: 3513: -: 3514: // Allows an implicit conversion to __sv_type. -: 3515: static __sv_type -: 3516: _S_to_string_view(__sv_type __svt) noexcept -: 3517: { return __svt; } -: 3518: -: 3519: // Wraps a string_view by explicit conversion and thus -: 3520: // allows to add an internal constructor that does not -: 3521: // participate in overload resolution when a string_view -: 3522: // is provided. -: 3523: struct __sv_wrapper -: 3524: { -: 3525: explicit __sv_wrapper(__sv_type __sv) noexcept : _M_sv(__sv) { } -: 3526: __sv_type _M_sv; -: 3527: }; -: 3528: -: 3529: /** -: 3530: * @brief Only internally used: Construct string from a string view -: 3531: * wrapper. -: 3532: * @param __svw string view wrapper. -: 3533: * @param __a Allocator to use. -: 3534: */ -: 3535: explicit -: 3536: basic_string(__sv_wrapper __svw, const _Alloc& __a) -: 3537: : basic_string(__svw._M_sv.data(), __svw._M_sv.size(), __a) { } -: 3538:#endif -: 3539: -: 3540: public: -: 3541: // Construct/copy/destroy: -: 3542: // NB: We overload ctors in some cases instead of using default -: 3543: // arguments, per 17.4.4.4 para. 2 item 2. -: 3544: -: 3545: /** -: 3546: * @brief Default constructor creates an empty string. -: 3547: */ -: 3548: basic_string() -: 3549:#if _GLIBCXX_FULLY_DYNAMIC_STRING == 0 -: 3550: _GLIBCXX_NOEXCEPT -: 3551: : _M_dataplus(_S_empty_rep()._M_refdata(), _Alloc()) -: 3552:#else -: 3553: : _M_dataplus(_S_construct(size_type(), _CharT(), _Alloc()), _Alloc()) -: 3554:#endif -: 3555: { } -: 3556: -: 3557: /** -: 3558: * @brief Construct an empty string using allocator @a a. -: 3559: */ -: 3560: explicit -: 3561: basic_string(const _Alloc& __a); -: 3562: -: 3563: // NB: per LWG issue 42, semantics different from IS: -: 3564: /** -: 3565: * @brief Construct string with copy of value of @a str. -: 3566: * @param __str Source string. -: 3567: */ -: 3568: basic_string(const basic_string& __str); -: 3569: -: 3570: // _GLIBCXX_RESOLVE_LIB_DEFECTS -: 3571: // 2583. no way to supply an allocator for basic_string(str, pos) -: 3572: /** -: 3573: * @brief Construct string as copy of a substring. -: 3574: * @param __str Source string. -: 3575: * @param __pos Index of first character to copy from. -: 3576: * @param __a Allocator to use. -: 3577: */ -: 3578: basic_string(const basic_string& __str, size_type __pos, -: 3579: const _Alloc& __a = _Alloc()); -: 3580: -: 3581: /** -: 3582: * @brief Construct string as copy of a substring. -: 3583: * @param __str Source string. -: 3584: * @param __pos Index of first character to copy from. -: 3585: * @param __n Number of characters to copy. -: 3586: */ -: 3587: basic_string(const basic_string& __str, size_type __pos, -: 3588: size_type __n); -: 3589: /** -: 3590: * @brief Construct string as copy of a substring. -: 3591: * @param __str Source string. -: 3592: * @param __pos Index of first character to copy from. -: 3593: * @param __n Number of characters to copy. -: 3594: * @param __a Allocator to use. -: 3595: */ -: 3596: basic_string(const basic_string& __str, size_type __pos, -: 3597: size_type __n, const _Alloc& __a); -: 3598: -: 3599: /** -: 3600: * @brief Construct string initialized by a character %array. -: 3601: * @param __s Source character %array. -: 3602: * @param __n Number of characters to copy. -: 3603: * @param __a Allocator to use (default is default allocator). -: 3604: * -: 3605: * NB: @a __s must have at least @a __n characters, '\\0' -: 3606: * has no special meaning. -: 3607: */ -: 3608: basic_string(const _CharT* __s, size_type __n, -: 3609: const _Alloc& __a = _Alloc()); -: 3610: /** -: 3611: * @brief Construct string as copy of a C string. -: 3612: * @param __s Source C string. -: 3613: * @param __a Allocator to use (default is default allocator). -: 3614: */ -: 3615: basic_string(const _CharT* __s, const _Alloc& __a = _Alloc()); -: 3616: /** -: 3617: * @brief Construct string as multiple characters. -: 3618: * @param __n Number of characters. -: 3619: * @param __c Character to use. -: 3620: * @param __a Allocator to use (default is default allocator). -: 3621: */ -: 3622: basic_string(size_type __n, _CharT __c, const _Alloc& __a = _Alloc()); -: 3623: -: 3624:#if __cplusplus >= 201103L -: 3625: /** -: 3626: * @brief Move construct string. -: 3627: * @param __str Source string. -: 3628: * -: 3629: * The newly-created string contains the exact contents of @a __str. -: 3630: * @a __str is a valid, but unspecified string. -: 3631: **/ -: 3632: basic_string(basic_string&& __str) -: 3633:#if _GLIBCXX_FULLY_DYNAMIC_STRING == 0 -: 3634: noexcept // FIXME C++11: should always be noexcept. -: 3635:#endif -: 3636: : _M_dataplus(std::move(__str._M_dataplus)) -: 3637: { -: 3638:#if _GLIBCXX_FULLY_DYNAMIC_STRING == 0 -: 3639: __str._M_data(_S_empty_rep()._M_refdata()); -: 3640:#else -: 3641: __str._M_data(_S_construct(size_type(), _CharT(), get_allocator())); -: 3642:#endif -: 3643: } -: 3644: -: 3645: /** -: 3646: * @brief Construct string from an initializer %list. -: 3647: * @param __l std::initializer_list of characters. -: 3648: * @param __a Allocator to use (default is default allocator). -: 3649: */ -: 3650: basic_string(initializer_list<_CharT> __l, const _Alloc& __a = _Alloc()); -: 3651: -: 3652: basic_string(const basic_string& __str, const _Alloc& __a) -: 3653: : _M_dataplus(__str._M_rep()->_M_grab(__a, __str.get_allocator()), __a) -: 3654: { } -: 3655: -: 3656: basic_string(basic_string&& __str, const _Alloc& __a) -: 3657: : _M_dataplus(__str._M_data(), __a) -: 3658: { -: 3659: if (__a == __str.get_allocator()) -: 3660: { -: 3661:#if _GLIBCXX_FULLY_DYNAMIC_STRING == 0 -: 3662: __str._M_data(_S_empty_rep()._M_refdata()); -: 3663:#else -: 3664: __str._M_data(_S_construct(size_type(), _CharT(), __a)); -: 3665:#endif -: 3666: } -: 3667: else -: 3668: _M_dataplus._M_p = _S_construct(__str.begin(), __str.end(), __a); -: 3669: } -: 3670:#endif // C++11 -: 3671: -: 3672: /** -: 3673: * @brief Construct string as copy of a range. -: 3674: * @param __beg Start of range. -: 3675: * @param __end End of range. -: 3676: * @param __a Allocator to use (default is default allocator). -: 3677: */ -: 3678: template -: 3679: basic_string(_InputIterator __beg, _InputIterator __end, -: 3680: const _Alloc& __a = _Alloc()); -: 3681: -: 3682:#if __cplusplus >= 201703L -: 3683: /** -: 3684: * @brief Construct string from a substring of a string_view. -: 3685: * @param __t Source object convertible to string view. -: 3686: * @param __pos The index of the first character to copy from __t. -: 3687: * @param __n The number of characters to copy from __t. -: 3688: * @param __a Allocator to use. -: 3689: */ -: 3690: template> -: 3691: basic_string(const _Tp& __t, size_type __pos, size_type __n, -: 3692: const _Alloc& __a = _Alloc()) -: 3693: : basic_string(_S_to_string_view(__t).substr(__pos, __n), __a) { } -: 3694: -: 3695: /** -: 3696: * @brief Construct string from a string_view. -: 3697: * @param __t Source object convertible to string view. -: 3698: * @param __a Allocator to use (default is default allocator). -: 3699: */ -: 3700: template> -: 3701: explicit -: 3702: basic_string(const _Tp& __t, const _Alloc& __a = _Alloc()) -: 3703: : basic_string(__sv_wrapper(_S_to_string_view(__t)), __a) { } -: 3704:#endif // C++17 -: 3705: -: 3706: /** -: 3707: * @brief Destroy the string instance. -: 3708: */ -: 3709: ~basic_string() _GLIBCXX_NOEXCEPT -: 3710: { _M_rep()->_M_dispose(this->get_allocator()); } -: 3711: -: 3712: /** -: 3713: * @brief Assign the value of @a str to this string. -: 3714: * @param __str Source string. -: 3715: */ -: 3716: basic_string& -: 3717: operator=(const basic_string& __str) -: 3718: { return this->assign(__str); } -: 3719: -: 3720: /** -: 3721: * @brief Copy contents of @a s into this string. -: 3722: * @param __s Source null-terminated string. -: 3723: */ -: 3724: basic_string& -: 3725: operator=(const _CharT* __s) -: 3726: { return this->assign(__s); } -: 3727: -: 3728: /** -: 3729: * @brief Set value to string of length 1. -: 3730: * @param __c Source character. -: 3731: * -: 3732: * Assigning to a character makes this string length 1 and -: 3733: * (*this)[0] == @a c. -: 3734: */ -: 3735: basic_string& -: 3736: operator=(_CharT __c) -: 3737: { -: 3738: this->assign(1, __c); -: 3739: return *this; -: 3740: } -: 3741: -: 3742:#if __cplusplus >= 201103L -: 3743: /** -: 3744: * @brief Move assign the value of @a str to this string. -: 3745: * @param __str Source string. -: 3746: * -: 3747: * The contents of @a str are moved into this string (without copying). -: 3748: * @a str is a valid, but unspecified string. -: 3749: **/ -: 3750: basic_string& -: 3751: operator=(basic_string&& __str) -: 3752: _GLIBCXX_NOEXCEPT_IF(allocator_traits<_Alloc>::is_always_equal::value) -: 3753: { -: 3754: // NB: DR 1204. -: 3755: this->swap(__str); -: 3756: return *this; -: 3757: } -: 3758: -: 3759: /** -: 3760: * @brief Set value to string constructed from initializer %list. -: 3761: * @param __l std::initializer_list. -: 3762: */ -: 3763: basic_string& -: 3764: operator=(initializer_list<_CharT> __l) -: 3765: { -: 3766: this->assign(__l.begin(), __l.size()); -: 3767: return *this; -: 3768: } -: 3769:#endif // C++11 -: 3770: -: 3771:#if __cplusplus >= 201703L -: 3772: /** -: 3773: * @brief Set value to string constructed from a string_view. -: 3774: * @param __svt An object convertible to string_view. -: 3775: */ -: 3776: template -: 3777: _If_sv<_Tp, basic_string&> -: 3778: operator=(const _Tp& __svt) -: 3779: { return this->assign(__svt); } -: 3780: -: 3781: /** -: 3782: * @brief Convert to a string_view. -: 3783: * @return A string_view. -: 3784: */ -: 3785: operator __sv_type() const noexcept -: 3786: { return __sv_type(data(), size()); } -: 3787:#endif // C++17 -: 3788: -: 3789: // Iterators: -: 3790: /** -: 3791: * Returns a read/write iterator that points to the first character in -: 3792: * the %string. Unshares the string. -: 3793: */ -: 3794: iterator -: 3795: begin() // FIXME C++11: should be noexcept. -: 3796: { -: 3797: _M_leak(); -: 3798: return iterator(_M_data()); -: 3799: } -: 3800: -: 3801: /** -: 3802: * Returns a read-only (constant) iterator that points to the first -: 3803: * character in the %string. -: 3804: */ -: 3805: const_iterator -: 3806: begin() const _GLIBCXX_NOEXCEPT -: 3807: { return const_iterator(_M_data()); } -: 3808: -: 3809: /** -: 3810: * Returns a read/write iterator that points one past the last -: 3811: * character in the %string. Unshares the string. -: 3812: */ -: 3813: iterator -: 3814: end() // FIXME C++11: should be noexcept. -: 3815: { -: 3816: _M_leak(); -: 3817: return iterator(_M_data() + this->size()); -: 3818: } -: 3819: -: 3820: /** -: 3821: * Returns a read-only (constant) iterator that points one past the -: 3822: * last character in the %string. -: 3823: */ -: 3824: const_iterator -: 3825: end() const _GLIBCXX_NOEXCEPT -: 3826: { return const_iterator(_M_data() + this->size()); } -: 3827: -: 3828: /** -: 3829: * Returns a read/write reverse iterator that points to the last -: 3830: * character in the %string. Iteration is done in reverse element -: 3831: * order. Unshares the string. -: 3832: */ -: 3833: reverse_iterator -: 3834: rbegin() // FIXME C++11: should be noexcept. -: 3835: { return reverse_iterator(this->end()); } -: 3836: -: 3837: /** -: 3838: * Returns a read-only (constant) reverse iterator that points -: 3839: * to the last character in the %string. Iteration is done in -: 3840: * reverse element order. -: 3841: */ -: 3842: const_reverse_iterator -: 3843: rbegin() const _GLIBCXX_NOEXCEPT -: 3844: { return const_reverse_iterator(this->end()); } -: 3845: -: 3846: /** -: 3847: * Returns a read/write reverse iterator that points to one before the -: 3848: * first character in the %string. Iteration is done in reverse -: 3849: * element order. Unshares the string. -: 3850: */ -: 3851: reverse_iterator -: 3852: rend() // FIXME C++11: should be noexcept. -: 3853: { return reverse_iterator(this->begin()); } -: 3854: -: 3855: /** -: 3856: * Returns a read-only (constant) reverse iterator that points -: 3857: * to one before the first character in the %string. Iteration -: 3858: * is done in reverse element order. -: 3859: */ -: 3860: const_reverse_iterator -: 3861: rend() const _GLIBCXX_NOEXCEPT -: 3862: { return const_reverse_iterator(this->begin()); } -: 3863: -: 3864:#if __cplusplus >= 201103L -: 3865: /** -: 3866: * Returns a read-only (constant) iterator that points to the first -: 3867: * character in the %string. -: 3868: */ -: 3869: const_iterator -: 3870: cbegin() const noexcept -: 3871: { return const_iterator(this->_M_data()); } -: 3872: -: 3873: /** -: 3874: * Returns a read-only (constant) iterator that points one past the -: 3875: * last character in the %string. -: 3876: */ -: 3877: const_iterator -: 3878: cend() const noexcept -: 3879: { return const_iterator(this->_M_data() + this->size()); } -: 3880: -: 3881: /** -: 3882: * Returns a read-only (constant) reverse iterator that points -: 3883: * to the last character in the %string. Iteration is done in -: 3884: * reverse element order. -: 3885: */ -: 3886: const_reverse_iterator -: 3887: crbegin() const noexcept -: 3888: { return const_reverse_iterator(this->end()); } -: 3889: -: 3890: /** -: 3891: * Returns a read-only (constant) reverse iterator that points -: 3892: * to one before the first character in the %string. Iteration -: 3893: * is done in reverse element order. -: 3894: */ -: 3895: const_reverse_iterator -: 3896: crend() const noexcept -: 3897: { return const_reverse_iterator(this->begin()); } -: 3898:#endif -: 3899: -: 3900: public: -: 3901: // Capacity: -: 3902: /// Returns the number of characters in the string, not including any -: 3903: /// null-termination. -: 3904: size_type -: 3905: size() const _GLIBCXX_NOEXCEPT -: 3906: { return _M_rep()->_M_length; } -: 3907: -: 3908: /// Returns the number of characters in the string, not including any -: 3909: /// null-termination. -: 3910: size_type -: 3911: length() const _GLIBCXX_NOEXCEPT -: 3912: { return _M_rep()->_M_length; } -: 3913: -: 3914: /// Returns the size() of the largest possible %string. -: 3915: size_type -: 3916: max_size() const _GLIBCXX_NOEXCEPT -: 3917: { return _Rep::_S_max_size; } -: 3918: -: 3919: /** -: 3920: * @brief Resizes the %string to the specified number of characters. -: 3921: * @param __n Number of characters the %string should contain. -: 3922: * @param __c Character to fill any new elements. -: 3923: * -: 3924: * This function will %resize the %string to the specified -: 3925: * number of characters. If the number is smaller than the -: 3926: * %string's current size the %string is truncated, otherwise -: 3927: * the %string is extended and new elements are %set to @a __c. -: 3928: */ -: 3929: void -: 3930: resize(size_type __n, _CharT __c); -: 3931: -: 3932: /** -: 3933: * @brief Resizes the %string to the specified number of characters. -: 3934: * @param __n Number of characters the %string should contain. -: 3935: * -: 3936: * This function will resize the %string to the specified length. If -: 3937: * the new size is smaller than the %string's current size the %string -: 3938: * is truncated, otherwise the %string is extended and new characters -: 3939: * are default-constructed. For basic types such as char, this means -: 3940: * setting them to 0. -: 3941: */ -: 3942: void -: 3943: resize(size_type __n) -: 3944: { this->resize(__n, _CharT()); } -: 3945: -: 3946:#if __cplusplus >= 201103L -: 3947: /// A non-binding request to reduce capacity() to size(). -: 3948: void -: 3949: shrink_to_fit() _GLIBCXX_NOEXCEPT -: 3950: { -: 3951:#if __cpp_exceptions -: 3952: if (capacity() > size()) -: 3953: { -: 3954: try -: 3955: { reserve(0); } -: 3956: catch(...) -: 3957: { } -: 3958: } -: 3959:#endif -: 3960: } -: 3961:#endif -: 3962: -: 3963: /** -: 3964: * Returns the total number of characters that the %string can hold -: 3965: * before needing to allocate more memory. -: 3966: */ -: 3967: size_type -: 3968: capacity() const _GLIBCXX_NOEXCEPT -: 3969: { return _M_rep()->_M_capacity; } -: 3970: -: 3971: /** -: 3972: * @brief Attempt to preallocate enough memory for specified number of -: 3973: * characters. -: 3974: * @param __res_arg Number of characters required. -: 3975: * @throw std::length_error If @a __res_arg exceeds @c max_size(). -: 3976: * -: 3977: * This function attempts to reserve enough memory for the -: 3978: * %string to hold the specified number of characters. If the -: 3979: * number requested is more than max_size(), length_error is -: 3980: * thrown. -: 3981: * -: 3982: * The advantage of this function is that if optimal code is a -: 3983: * necessity and the user can determine the string length that will be -: 3984: * required, the user can reserve the memory in %advance, and thus -: 3985: * prevent a possible reallocation of memory and copying of %string -: 3986: * data. -: 3987: */ -: 3988: void -: 3989: reserve(size_type __res_arg = 0); -: 3990: -: 3991: /** -: 3992: * Erases the string, making it empty. -: 3993: */ -: 3994:#if _GLIBCXX_FULLY_DYNAMIC_STRING == 0 -: 3995: void -: 3996: clear() _GLIBCXX_NOEXCEPT -: 3997: { -: 3998: if (_M_rep()->_M_is_shared()) -: 3999: { -: 4000: _M_rep()->_M_dispose(this->get_allocator()); -: 4001: _M_data(_S_empty_rep()._M_refdata()); -: 4002: } -: 4003: else -: 4004: _M_rep()->_M_set_length_and_sharable(0); -: 4005: } -: 4006:#else -: 4007: // PR 56166: this should not throw. -: 4008: void -: 4009: clear() -: 4010: { _M_mutate(0, this->size(), 0); } -: 4011:#endif -: 4012: -: 4013: /** -: 4014: * Returns true if the %string is empty. Equivalent to -: 4015: * *this == "". -: 4016: */ -: 4017: _GLIBCXX_NODISCARD bool -: 4018: empty() const _GLIBCXX_NOEXCEPT -: 4019: { return this->size() == 0; } -: 4020: -: 4021: // Element access: -: 4022: /** -: 4023: * @brief Subscript access to the data contained in the %string. -: 4024: * @param __pos The index of the character to access. -: 4025: * @return Read-only (constant) reference to the character. -: 4026: * -: 4027: * This operator allows for easy, array-style, data access. -: 4028: * Note that data access with this operator is unchecked and -: 4029: * out_of_range lookups are not defined. (For checked lookups -: 4030: * see at().) -: 4031: */ -: 4032: const_reference -: 4033: operator[] (size_type __pos) const _GLIBCXX_NOEXCEPT -: 4034: { -: 4035: __glibcxx_assert(__pos <= size()); -: 4036: return _M_data()[__pos]; -: 4037: } -: 4038: -: 4039: /** -: 4040: * @brief Subscript access to the data contained in the %string. -: 4041: * @param __pos The index of the character to access. -: 4042: * @return Read/write reference to the character. -: 4043: * -: 4044: * This operator allows for easy, array-style, data access. -: 4045: * Note that data access with this operator is unchecked and -: 4046: * out_of_range lookups are not defined. (For checked lookups -: 4047: * see at().) Unshares the string. -: 4048: */ -: 4049: reference -: 4050: operator[](size_type __pos) -: 4051: { -: 4052: // Allow pos == size() both in C++98 mode, as v3 extension, -: 4053: // and in C++11 mode. -: 4054: __glibcxx_assert(__pos <= size()); -: 4055: // In pedantic mode be strict in C++98 mode. -: 4056: _GLIBCXX_DEBUG_PEDASSERT(__cplusplus >= 201103L || __pos < size()); -: 4057: _M_leak(); -: 4058: return _M_data()[__pos]; -: 4059: } -: 4060: -: 4061: /** -: 4062: * @brief Provides access to the data contained in the %string. -: 4063: * @param __n The index of the character to access. -: 4064: * @return Read-only (const) reference to the character. -: 4065: * @throw std::out_of_range If @a n is an invalid index. -: 4066: * -: 4067: * This function provides for safer data access. The parameter is -: 4068: * first checked that it is in the range of the string. The function -: 4069: * throws out_of_range if the check fails. -: 4070: */ -: 4071: const_reference -: 4072: at(size_type __n) const -: 4073: { -: 4074: if (__n >= this->size()) -: 4075: __throw_out_of_range_fmt(__N("basic_string::at: __n " -: 4076: "(which is %zu) >= this->size() " -: 4077: "(which is %zu)"), -: 4078: __n, this->size()); -: 4079: return _M_data()[__n]; -: 4080: } -: 4081: -: 4082: /** -: 4083: * @brief Provides access to the data contained in the %string. -: 4084: * @param __n The index of the character to access. -: 4085: * @return Read/write reference to the character. -: 4086: * @throw std::out_of_range If @a n is an invalid index. -: 4087: * -: 4088: * This function provides for safer data access. The parameter is -: 4089: * first checked that it is in the range of the string. The function -: 4090: * throws out_of_range if the check fails. Success results in -: 4091: * unsharing the string. -: 4092: */ -: 4093: reference -: 4094: at(size_type __n) -: 4095: { -: 4096: if (__n >= size()) -: 4097: __throw_out_of_range_fmt(__N("basic_string::at: __n " -: 4098: "(which is %zu) >= this->size() " -: 4099: "(which is %zu)"), -: 4100: __n, this->size()); -: 4101: _M_leak(); -: 4102: return _M_data()[__n]; -: 4103: } -: 4104: -: 4105:#if __cplusplus >= 201103L -: 4106: /** -: 4107: * Returns a read/write reference to the data at the first -: 4108: * element of the %string. -: 4109: */ -: 4110: reference -: 4111: front() -: 4112: { -: 4113: __glibcxx_assert(!empty()); -: 4114: return operator[](0); -: 4115: } -: 4116: -: 4117: /** -: 4118: * Returns a read-only (constant) reference to the data at the first -: 4119: * element of the %string. -: 4120: */ -: 4121: const_reference -: 4122: front() const noexcept -: 4123: { -: 4124: __glibcxx_assert(!empty()); -: 4125: return operator[](0); -: 4126: } -: 4127: -: 4128: /** -: 4129: * Returns a read/write reference to the data at the last -: 4130: * element of the %string. -: 4131: */ -: 4132: reference -: 4133: back() -: 4134: { -: 4135: __glibcxx_assert(!empty()); -: 4136: return operator[](this->size() - 1); -: 4137: } -: 4138: -: 4139: /** -: 4140: * Returns a read-only (constant) reference to the data at the -: 4141: * last element of the %string. -: 4142: */ -: 4143: const_reference -: 4144: back() const noexcept -: 4145: { -: 4146: __glibcxx_assert(!empty()); -: 4147: return operator[](this->size() - 1); -: 4148: } -: 4149:#endif -: 4150: -: 4151: // Modifiers: -: 4152: /** -: 4153: * @brief Append a string to this string. -: 4154: * @param __str The string to append. -: 4155: * @return Reference to this string. -: 4156: */ -: 4157: basic_string& -: 4158: operator+=(const basic_string& __str) -: 4159: { return this->append(__str); } -: 4160: -: 4161: /** -: 4162: * @brief Append a C string. -: 4163: * @param __s The C string to append. -: 4164: * @return Reference to this string. -: 4165: */ -: 4166: basic_string& -: 4167: operator+=(const _CharT* __s) -: 4168: { return this->append(__s); } -: 4169: -: 4170: /** -: 4171: * @brief Append a character. -: 4172: * @param __c The character to append. -: 4173: * @return Reference to this string. -: 4174: */ -: 4175: basic_string& -: 4176: operator+=(_CharT __c) -: 4177: { -: 4178: this->push_back(__c); -: 4179: return *this; -: 4180: } -: 4181: -: 4182:#if __cplusplus >= 201103L -: 4183: /** -: 4184: * @brief Append an initializer_list of characters. -: 4185: * @param __l The initializer_list of characters to be appended. -: 4186: * @return Reference to this string. -: 4187: */ -: 4188: basic_string& -: 4189: operator+=(initializer_list<_CharT> __l) -: 4190: { return this->append(__l.begin(), __l.size()); } -: 4191:#endif // C++11 -: 4192: -: 4193:#if __cplusplus >= 201703L -: 4194: /** -: 4195: * @brief Append a string_view. -: 4196: * @param __svt The object convertible to string_view to be appended. -: 4197: * @return Reference to this string. -: 4198: */ -: 4199: template -: 4200: _If_sv<_Tp, basic_string&> -: 4201: operator+=(const _Tp& __svt) -: 4202: { return this->append(__svt); } -: 4203:#endif // C++17 -: 4204: -: 4205: /** -: 4206: * @brief Append a string to this string. -: 4207: * @param __str The string to append. -: 4208: * @return Reference to this string. -: 4209: */ -: 4210: basic_string& -: 4211: append(const basic_string& __str); -: 4212: -: 4213: /** -: 4214: * @brief Append a substring. -: 4215: * @param __str The string to append. -: 4216: * @param __pos Index of the first character of str to append. -: 4217: * @param __n The number of characters to append. -: 4218: * @return Reference to this string. -: 4219: * @throw std::out_of_range if @a __pos is not a valid index. -: 4220: * -: 4221: * This function appends @a __n characters from @a __str -: 4222: * starting at @a __pos to this string. If @a __n is is larger -: 4223: * than the number of available characters in @a __str, the -: 4224: * remainder of @a __str is appended. -: 4225: */ -: 4226: basic_string& -: 4227: append(const basic_string& __str, size_type __pos, size_type __n = npos); -: 4228: -: 4229: /** -: 4230: * @brief Append a C substring. -: 4231: * @param __s The C string to append. -: 4232: * @param __n The number of characters to append. -: 4233: * @return Reference to this string. -: 4234: */ -: 4235: basic_string& -: 4236: append(const _CharT* __s, size_type __n); -: 4237: -: 4238: /** -: 4239: * @brief Append a C string. -: 4240: * @param __s The C string to append. -: 4241: * @return Reference to this string. -: 4242: */ -: 4243: basic_string& -: 4244: append(const _CharT* __s) -: 4245: { -: 4246: __glibcxx_requires_string(__s); -: 4247: return this->append(__s, traits_type::length(__s)); -: 4248: } -: 4249: -: 4250: /** -: 4251: * @brief Append multiple characters. -: 4252: * @param __n The number of characters to append. -: 4253: * @param __c The character to use. -: 4254: * @return Reference to this string. -: 4255: * -: 4256: * Appends __n copies of __c to this string. -: 4257: */ -: 4258: basic_string& -: 4259: append(size_type __n, _CharT __c); -: 4260: -: 4261:#if __cplusplus >= 201103L -: 4262: /** -: 4263: * @brief Append an initializer_list of characters. -: 4264: * @param __l The initializer_list of characters to append. -: 4265: * @return Reference to this string. -: 4266: */ -: 4267: basic_string& -: 4268: append(initializer_list<_CharT> __l) -: 4269: { return this->append(__l.begin(), __l.size()); } -: 4270:#endif // C++11 -: 4271: -: 4272: /** -: 4273: * @brief Append a range of characters. -: 4274: * @param __first Iterator referencing the first character to append. -: 4275: * @param __last Iterator marking the end of the range. -: 4276: * @return Reference to this string. -: 4277: * -: 4278: * Appends characters in the range [__first,__last) to this string. -: 4279: */ -: 4280: template -: 4281: basic_string& -: 4282: append(_InputIterator __first, _InputIterator __last) -: 4283: { return this->replace(_M_iend(), _M_iend(), __first, __last); } -: 4284: -: 4285:#if __cplusplus >= 201703L -: 4286: /** -: 4287: * @brief Append a string_view. -: 4288: * @param __svt The object convertible to string_view to be appended. -: 4289: * @return Reference to this string. -: 4290: */ -: 4291: template -: 4292: _If_sv<_Tp, basic_string&> -: 4293: append(const _Tp& __svt) -: 4294: { -: 4295: __sv_type __sv = __svt; -: 4296: return this->append(__sv.data(), __sv.size()); -: 4297: } -: 4298: -: 4299: /** -: 4300: * @brief Append a range of characters from a string_view. -: 4301: * @param __svt The object convertible to string_view to be appended -: 4302: * from. -: 4303: * @param __pos The position in the string_view to append from. -: 4304: * @param __n The number of characters to append from the string_view. -: 4305: * @return Reference to this string. -: 4306: */ -: 4307: template -: 4308: _If_sv<_Tp, basic_string&> -: 4309: append(const _Tp& __svt, size_type __pos, size_type __n = npos) -: 4310: { -: 4311: __sv_type __sv = __svt; -: 4312: return append(__sv.data() -: 4313: + std::__sv_check(__sv.size(), __pos, "basic_string::append"), -: 4314: std::__sv_limit(__sv.size(), __pos, __n)); -: 4315: } -: 4316:#endif // C++17 -: 4317: -: 4318: /** -: 4319: * @brief Append a single character. -: 4320: * @param __c Character to append. -: 4321: */ -: 4322: void -: 4323: push_back(_CharT __c) -: 4324: { -: 4325: const size_type __len = 1 + this->size(); -: 4326: if (__len > this->capacity() || _M_rep()->_M_is_shared()) -: 4327: this->reserve(__len); -: 4328: traits_type::assign(_M_data()[this->size()], __c); -: 4329: _M_rep()->_M_set_length_and_sharable(__len); -: 4330: } -: 4331: -: 4332: /** -: 4333: * @brief Set value to contents of another string. -: 4334: * @param __str Source string to use. -: 4335: * @return Reference to this string. -: 4336: */ -: 4337: basic_string& -: 4338: assign(const basic_string& __str); -: 4339: -: 4340:#if __cplusplus >= 201103L -: 4341: /** -: 4342: * @brief Set value to contents of another string. -: 4343: * @param __str Source string to use. -: 4344: * @return Reference to this string. -: 4345: * -: 4346: * This function sets this string to the exact contents of @a __str. -: 4347: * @a __str is a valid, but unspecified string. -: 4348: */ -: 4349: basic_string& -: 4350: assign(basic_string&& __str) -: 4351: noexcept(allocator_traits<_Alloc>::is_always_equal::value) -: 4352: { -: 4353: this->swap(__str); -: 4354: return *this; -: 4355: } -: 4356:#endif // C++11 -: 4357: -: 4358: /** -: 4359: * @brief Set value to a substring of a string. -: 4360: * @param __str The string to use. -: 4361: * @param __pos Index of the first character of str. -: 4362: * @param __n Number of characters to use. -: 4363: * @return Reference to this string. -: 4364: * @throw std::out_of_range if @a pos is not a valid index. -: 4365: * -: 4366: * This function sets this string to the substring of @a __str -: 4367: * consisting of @a __n characters at @a __pos. If @a __n is -: 4368: * is larger than the number of available characters in @a -: 4369: * __str, the remainder of @a __str is used. -: 4370: */ -: 4371: basic_string& -: 4372: assign(const basic_string& __str, size_type __pos, size_type __n = npos) -: 4373: { return this->assign(__str._M_data() -: 4374: + __str._M_check(__pos, "basic_string::assign"), -: 4375: __str._M_limit(__pos, __n)); } -: 4376: -: 4377: /** -: 4378: * @brief Set value to a C substring. -: 4379: * @param __s The C string to use. -: 4380: * @param __n Number of characters to use. -: 4381: * @return Reference to this string. -: 4382: * -: 4383: * This function sets the value of this string to the first @a __n -: 4384: * characters of @a __s. If @a __n is is larger than the number of -: 4385: * available characters in @a __s, the remainder of @a __s is used. -: 4386: */ -: 4387: basic_string& -: 4388: assign(const _CharT* __s, size_type __n); -: 4389: -: 4390: /** -: 4391: * @brief Set value to contents of a C string. -: 4392: * @param __s The C string to use. -: 4393: * @return Reference to this string. -: 4394: * -: 4395: * This function sets the value of this string to the value of @a __s. -: 4396: * The data is copied, so there is no dependence on @a __s once the -: 4397: * function returns. -: 4398: */ -: 4399: basic_string& -: 4400: assign(const _CharT* __s) -: 4401: { -: 4402: __glibcxx_requires_string(__s); -: 4403: return this->assign(__s, traits_type::length(__s)); -: 4404: } -: 4405: -: 4406: /** -: 4407: * @brief Set value to multiple characters. -: 4408: * @param __n Length of the resulting string. -: 4409: * @param __c The character to use. -: 4410: * @return Reference to this string. -: 4411: * -: 4412: * This function sets the value of this string to @a __n copies of -: 4413: * character @a __c. -: 4414: */ -: 4415: basic_string& -: 4416: assign(size_type __n, _CharT __c) -: 4417: { return _M_replace_aux(size_type(0), this->size(), __n, __c); } -: 4418: -: 4419: /** -: 4420: * @brief Set value to a range of characters. -: 4421: * @param __first Iterator referencing the first character to append. -: 4422: * @param __last Iterator marking the end of the range. -: 4423: * @return Reference to this string. -: 4424: * -: 4425: * Sets value of string to characters in the range [__first,__last). -: 4426: */ -: 4427: template -: 4428: basic_string& -: 4429: assign(_InputIterator __first, _InputIterator __last) -: 4430: { return this->replace(_M_ibegin(), _M_iend(), __first, __last); } -: 4431: -: 4432:#if __cplusplus >= 201103L -: 4433: /** -: 4434: * @brief Set value to an initializer_list of characters. -: 4435: * @param __l The initializer_list of characters to assign. -: 4436: * @return Reference to this string. -: 4437: */ -: 4438: basic_string& -: 4439: assign(initializer_list<_CharT> __l) -: 4440: { return this->assign(__l.begin(), __l.size()); } -: 4441:#endif // C++11 -: 4442: -: 4443:#if __cplusplus >= 201703L -: 4444: /** -: 4445: * @brief Set value from a string_view. -: 4446: * @param __svt The source object convertible to string_view. -: 4447: * @return Reference to this string. -: 4448: */ -: 4449: template -: 4450: _If_sv<_Tp, basic_string&> -: 4451: assign(const _Tp& __svt) -: 4452: { -: 4453: __sv_type __sv = __svt; -: 4454: return this->assign(__sv.data(), __sv.size()); -: 4455: } -: 4456: -: 4457: /** -: 4458: * @brief Set value from a range of characters in a string_view. -: 4459: * @param __svt The source object convertible to string_view. -: 4460: * @param __pos The position in the string_view to assign from. -: 4461: * @param __n The number of characters to assign. -: 4462: * @return Reference to this string. -: 4463: */ -: 4464: template -: 4465: _If_sv<_Tp, basic_string&> -: 4466: assign(const _Tp& __svt, size_type __pos, size_type __n = npos) -: 4467: { -: 4468: __sv_type __sv = __svt; -: 4469: return assign(__sv.data() -: 4470: + std::__sv_check(__sv.size(), __pos, "basic_string::assign"), -: 4471: std::__sv_limit(__sv.size(), __pos, __n)); -: 4472: } -: 4473:#endif // C++17 -: 4474: -: 4475: /** -: 4476: * @brief Insert multiple characters. -: 4477: * @param __p Iterator referencing location in string to insert at. -: 4478: * @param __n Number of characters to insert -: 4479: * @param __c The character to insert. -: 4480: * @throw std::length_error If new length exceeds @c max_size(). -: 4481: * -: 4482: * Inserts @a __n copies of character @a __c starting at the -: 4483: * position referenced by iterator @a __p. If adding -: 4484: * characters causes the length to exceed max_size(), -: 4485: * length_error is thrown. The value of the string doesn't -: 4486: * change if an error is thrown. -: 4487: */ -: 4488: void -: 4489: insert(iterator __p, size_type __n, _CharT __c) -: 4490: { this->replace(__p, __p, __n, __c); } -: 4491: -: 4492: /** -: 4493: * @brief Insert a range of characters. -: 4494: * @param __p Iterator referencing location in string to insert at. -: 4495: * @param __beg Start of range. -: 4496: * @param __end End of range. -: 4497: * @throw std::length_error If new length exceeds @c max_size(). -: 4498: * -: 4499: * Inserts characters in range [__beg,__end). If adding -: 4500: * characters causes the length to exceed max_size(), -: 4501: * length_error is thrown. The value of the string doesn't -: 4502: * change if an error is thrown. -: 4503: */ -: 4504: template -: 4505: void -: 4506: insert(iterator __p, _InputIterator __beg, _InputIterator __end) -: 4507: { this->replace(__p, __p, __beg, __end); } -: 4508: -: 4509:#if __cplusplus >= 201103L -: 4510: /** -: 4511: * @brief Insert an initializer_list of characters. -: 4512: * @param __p Iterator referencing location in string to insert at. -: 4513: * @param __l The initializer_list of characters to insert. -: 4514: * @throw std::length_error If new length exceeds @c max_size(). -: 4515: */ -: 4516: void -: 4517: insert(iterator __p, initializer_list<_CharT> __l) -: 4518: { -: 4519: _GLIBCXX_DEBUG_PEDASSERT(__p >= _M_ibegin() && __p <= _M_iend()); -: 4520: this->insert(__p - _M_ibegin(), __l.begin(), __l.size()); -: 4521: } -: 4522:#endif // C++11 -: 4523: -: 4524: /** -: 4525: * @brief Insert value of a string. -: 4526: * @param __pos1 Iterator referencing location in string to insert at. -: 4527: * @param __str The string to insert. -: 4528: * @return Reference to this string. -: 4529: * @throw std::length_error If new length exceeds @c max_size(). -: 4530: * -: 4531: * Inserts value of @a __str starting at @a __pos1. If adding -: 4532: * characters causes the length to exceed max_size(), -: 4533: * length_error is thrown. The value of the string doesn't -: 4534: * change if an error is thrown. -: 4535: */ -: 4536: basic_string& -: 4537: insert(size_type __pos1, const basic_string& __str) -: 4538: { return this->insert(__pos1, __str, size_type(0), __str.size()); } -: 4539: -: 4540: /** -: 4541: * @brief Insert a substring. -: 4542: * @param __pos1 Iterator referencing location in string to insert at. -: 4543: * @param __str The string to insert. -: 4544: * @param __pos2 Start of characters in str to insert. -: 4545: * @param __n Number of characters to insert. -: 4546: * @return Reference to this string. -: 4547: * @throw std::length_error If new length exceeds @c max_size(). -: 4548: * @throw std::out_of_range If @a pos1 > size() or -: 4549: * @a __pos2 > @a str.size(). -: 4550: * -: 4551: * Starting at @a pos1, insert @a __n character of @a __str -: 4552: * beginning with @a __pos2. If adding characters causes the -: 4553: * length to exceed max_size(), length_error is thrown. If @a -: 4554: * __pos1 is beyond the end of this string or @a __pos2 is -: 4555: * beyond the end of @a __str, out_of_range is thrown. The -: 4556: * value of the string doesn't change if an error is thrown. -: 4557: */ -: 4558: basic_string& -: 4559: insert(size_type __pos1, const basic_string& __str, -: 4560: size_type __pos2, size_type __n = npos) -: 4561: { return this->insert(__pos1, __str._M_data() -: 4562: + __str._M_check(__pos2, "basic_string::insert"), -: 4563: __str._M_limit(__pos2, __n)); } -: 4564: -: 4565: /** -: 4566: * @brief Insert a C substring. -: 4567: * @param __pos Iterator referencing location in string to insert at. -: 4568: * @param __s The C string to insert. -: 4569: * @param __n The number of characters to insert. -: 4570: * @return Reference to this string. -: 4571: * @throw std::length_error If new length exceeds @c max_size(). -: 4572: * @throw std::out_of_range If @a __pos is beyond the end of this -: 4573: * string. -: 4574: * -: 4575: * Inserts the first @a __n characters of @a __s starting at @a -: 4576: * __pos. If adding characters causes the length to exceed -: 4577: * max_size(), length_error is thrown. If @a __pos is beyond -: 4578: * end(), out_of_range is thrown. The value of the string -: 4579: * doesn't change if an error is thrown. -: 4580: */ -: 4581: basic_string& -: 4582: insert(size_type __pos, const _CharT* __s, size_type __n); -: 4583: -: 4584: /** -: 4585: * @brief Insert a C string. -: 4586: * @param __pos Iterator referencing location in string to insert at. -: 4587: * @param __s The C string to insert. -: 4588: * @return Reference to this string. -: 4589: * @throw std::length_error If new length exceeds @c max_size(). -: 4590: * @throw std::out_of_range If @a pos is beyond the end of this -: 4591: * string. -: 4592: * -: 4593: * Inserts the first @a n characters of @a __s starting at @a __pos. If -: 4594: * adding characters causes the length to exceed max_size(), -: 4595: * length_error is thrown. If @a __pos is beyond end(), out_of_range is -: 4596: * thrown. The value of the string doesn't change if an error is -: 4597: * thrown. -: 4598: */ -: 4599: basic_string& -: 4600: insert(size_type __pos, const _CharT* __s) -: 4601: { -: 4602: __glibcxx_requires_string(__s); -: 4603: return this->insert(__pos, __s, traits_type::length(__s)); -: 4604: } -: 4605: -: 4606: /** -: 4607: * @brief Insert multiple characters. -: 4608: * @param __pos Index in string to insert at. -: 4609: * @param __n Number of characters to insert -: 4610: * @param __c The character to insert. -: 4611: * @return Reference to this string. -: 4612: * @throw std::length_error If new length exceeds @c max_size(). -: 4613: * @throw std::out_of_range If @a __pos is beyond the end of this -: 4614: * string. -: 4615: * -: 4616: * Inserts @a __n copies of character @a __c starting at index -: 4617: * @a __pos. If adding characters causes the length to exceed -: 4618: * max_size(), length_error is thrown. If @a __pos > length(), -: 4619: * out_of_range is thrown. The value of the string doesn't -: 4620: * change if an error is thrown. -: 4621: */ -: 4622: basic_string& -: 4623: insert(size_type __pos, size_type __n, _CharT __c) -: 4624: { return _M_replace_aux(_M_check(__pos, "basic_string::insert"), -: 4625: size_type(0), __n, __c); } -: 4626: -: 4627: /** -: 4628: * @brief Insert one character. -: 4629: * @param __p Iterator referencing position in string to insert at. -: 4630: * @param __c The character to insert. -: 4631: * @return Iterator referencing newly inserted char. -: 4632: * @throw std::length_error If new length exceeds @c max_size(). -: 4633: * -: 4634: * Inserts character @a __c at position referenced by @a __p. -: 4635: * If adding character causes the length to exceed max_size(), -: 4636: * length_error is thrown. If @a __p is beyond end of string, -: 4637: * out_of_range is thrown. The value of the string doesn't -: 4638: * change if an error is thrown. -: 4639: */ -: 4640: iterator -: 4641: insert(iterator __p, _CharT __c) -: 4642: { -: 4643: _GLIBCXX_DEBUG_PEDASSERT(__p >= _M_ibegin() && __p <= _M_iend()); -: 4644: const size_type __pos = __p - _M_ibegin(); -: 4645: _M_replace_aux(__pos, size_type(0), size_type(1), __c); -: 4646: _M_rep()->_M_set_leaked(); -: 4647: return iterator(_M_data() + __pos); -: 4648: } -: 4649: -: 4650:#if __cplusplus >= 201703L -: 4651: /** -: 4652: * @brief Insert a string_view. -: 4653: * @param __pos Iterator referencing position in string to insert at. -: 4654: * @param __svt The object convertible to string_view to insert. -: 4655: * @return Reference to this string. -: 4656: */ -: 4657: template -: 4658: _If_sv<_Tp, basic_string&> -: 4659: insert(size_type __pos, const _Tp& __svt) -: 4660: { -: 4661: __sv_type __sv = __svt; -: 4662: return this->insert(__pos, __sv.data(), __sv.size()); -: 4663: } -: 4664: -: 4665: /** -: 4666: * @brief Insert a string_view. -: 4667: * @param __pos1 Position in string to insert at. -: 4668: * @param __svt The object convertible to string_view to insert from. -: 4669: * @param __pos2 Position in string_view to insert from. -: 4670: * @param __n The number of characters to insert. -: 4671: * @return Reference to this string. -: 4672: */ -: 4673: template -: 4674: _If_sv<_Tp, basic_string&> -: 4675: insert(size_type __pos1, const _Tp& __svt, -: 4676: size_type __pos2, size_type __n = npos) -: 4677: { -: 4678: __sv_type __sv = __svt; -: 4679: return this->replace(__pos1, size_type(0), __sv.data() -: 4680: + std::__sv_check(__sv.size(), __pos2, "basic_string::insert"), -: 4681: std::__sv_limit(__sv.size(), __pos2, __n)); -: 4682: } -: 4683:#endif // C++17 -: 4684: -: 4685: /** -: 4686: * @brief Remove characters. -: 4687: * @param __pos Index of first character to remove (default 0). -: 4688: * @param __n Number of characters to remove (default remainder). -: 4689: * @return Reference to this string. -: 4690: * @throw std::out_of_range If @a pos is beyond the end of this -: 4691: * string. -: 4692: * -: 4693: * Removes @a __n characters from this string starting at @a -: 4694: * __pos. The length of the string is reduced by @a __n. If -: 4695: * there are < @a __n characters to remove, the remainder of -: 4696: * the string is truncated. If @a __p is beyond end of string, -: 4697: * out_of_range is thrown. The value of the string doesn't -: 4698: * change if an error is thrown. -: 4699: */ -: 4700: basic_string& -: 4701: erase(size_type __pos = 0, size_type __n = npos) -: 4702: { -: 4703: _M_mutate(_M_check(__pos, "basic_string::erase"), -: 4704: _M_limit(__pos, __n), size_type(0)); -: 4705: return *this; -: 4706: } -: 4707: -: 4708: /** -: 4709: * @brief Remove one character. -: 4710: * @param __position Iterator referencing the character to remove. -: 4711: * @return iterator referencing same location after removal. -: 4712: * -: 4713: * Removes the character at @a __position from this string. The value -: 4714: * of the string doesn't change if an error is thrown. -: 4715: */ -: 4716: iterator -: 4717: erase(iterator __position) -: 4718: { -: 4719: _GLIBCXX_DEBUG_PEDASSERT(__position >= _M_ibegin() -: 4720: && __position < _M_iend()); -: 4721: const size_type __pos = __position - _M_ibegin(); -: 4722: _M_mutate(__pos, size_type(1), size_type(0)); -: 4723: _M_rep()->_M_set_leaked(); -: 4724: return iterator(_M_data() + __pos); -: 4725: } -: 4726: -: 4727: /** -: 4728: * @brief Remove a range of characters. -: 4729: * @param __first Iterator referencing the first character to remove. -: 4730: * @param __last Iterator referencing the end of the range. -: 4731: * @return Iterator referencing location of first after removal. -: 4732: * -: 4733: * Removes the characters in the range [first,last) from this string. -: 4734: * The value of the string doesn't change if an error is thrown. -: 4735: */ -: 4736: iterator -: 4737: erase(iterator __first, iterator __last); -: 4738: -: 4739:#if __cplusplus >= 201103L -: 4740: /** -: 4741: * @brief Remove the last character. -: 4742: * -: 4743: * The string must be non-empty. -: 4744: */ -: 4745: void -: 4746: pop_back() // FIXME C++11: should be noexcept. -: 4747: { -: 4748: __glibcxx_assert(!empty()); -: 4749: erase(size() - 1, 1); -: 4750: } -: 4751:#endif // C++11 -: 4752: -: 4753: /** -: 4754: * @brief Replace characters with value from another string. -: 4755: * @param __pos Index of first character to replace. -: 4756: * @param __n Number of characters to be replaced. -: 4757: * @param __str String to insert. -: 4758: * @return Reference to this string. -: 4759: * @throw std::out_of_range If @a pos is beyond the end of this -: 4760: * string. -: 4761: * @throw std::length_error If new length exceeds @c max_size(). -: 4762: * -: 4763: * Removes the characters in the range [__pos,__pos+__n) from -: 4764: * this string. In place, the value of @a __str is inserted. -: 4765: * If @a __pos is beyond end of string, out_of_range is thrown. -: 4766: * If the length of the result exceeds max_size(), length_error -: 4767: * is thrown. The value of the string doesn't change if an -: 4768: * error is thrown. -: 4769: */ -: 4770: basic_string& -: 4771: replace(size_type __pos, size_type __n, const basic_string& __str) -: 4772: { return this->replace(__pos, __n, __str._M_data(), __str.size()); } -: 4773: -: 4774: /** -: 4775: * @brief Replace characters with value from another string. -: 4776: * @param __pos1 Index of first character to replace. -: 4777: * @param __n1 Number of characters to be replaced. -: 4778: * @param __str String to insert. -: 4779: * @param __pos2 Index of first character of str to use. -: 4780: * @param __n2 Number of characters from str to use. -: 4781: * @return Reference to this string. -: 4782: * @throw std::out_of_range If @a __pos1 > size() or @a __pos2 > -: 4783: * __str.size(). -: 4784: * @throw std::length_error If new length exceeds @c max_size(). -: 4785: * -: 4786: * Removes the characters in the range [__pos1,__pos1 + n) from this -: 4787: * string. In place, the value of @a __str is inserted. If @a __pos is -: 4788: * beyond end of string, out_of_range is thrown. If the length of the -: 4789: * result exceeds max_size(), length_error is thrown. The value of the -: 4790: * string doesn't change if an error is thrown. -: 4791: */ -: 4792: basic_string& -: 4793: replace(size_type __pos1, size_type __n1, const basic_string& __str, -: 4794: size_type __pos2, size_type __n2 = npos) -: 4795: { return this->replace(__pos1, __n1, __str._M_data() -: 4796: + __str._M_check(__pos2, "basic_string::replace"), -: 4797: __str._M_limit(__pos2, __n2)); } -: 4798: -: 4799: /** -: 4800: * @brief Replace characters with value of a C substring. -: 4801: * @param __pos Index of first character to replace. -: 4802: * @param __n1 Number of characters to be replaced. -: 4803: * @param __s C string to insert. -: 4804: * @param __n2 Number of characters from @a s to use. -: 4805: * @return Reference to this string. -: 4806: * @throw std::out_of_range If @a pos1 > size(). -: 4807: * @throw std::length_error If new length exceeds @c max_size(). -: 4808: * -: 4809: * Removes the characters in the range [__pos,__pos + __n1) -: 4810: * from this string. In place, the first @a __n2 characters of -: 4811: * @a __s are inserted, or all of @a __s if @a __n2 is too large. If -: 4812: * @a __pos is beyond end of string, out_of_range is thrown. If -: 4813: * the length of result exceeds max_size(), length_error is -: 4814: * thrown. The value of the string doesn't change if an error -: 4815: * is thrown. -: 4816: */ -: 4817: basic_string& -: 4818: replace(size_type __pos, size_type __n1, const _CharT* __s, -: 4819: size_type __n2); -: 4820: -: 4821: /** -: 4822: * @brief Replace characters with value of a C string. -: 4823: * @param __pos Index of first character to replace. -: 4824: * @param __n1 Number of characters to be replaced. -: 4825: * @param __s C string to insert. -: 4826: * @return Reference to this string. -: 4827: * @throw std::out_of_range If @a pos > size(). -: 4828: * @throw std::length_error If new length exceeds @c max_size(). -: 4829: * -: 4830: * Removes the characters in the range [__pos,__pos + __n1) -: 4831: * from this string. In place, the characters of @a __s are -: 4832: * inserted. If @a __pos is beyond end of string, out_of_range -: 4833: * is thrown. If the length of result exceeds max_size(), -: 4834: * length_error is thrown. The value of the string doesn't -: 4835: * change if an error is thrown. -: 4836: */ -: 4837: basic_string& -: 4838: replace(size_type __pos, size_type __n1, const _CharT* __s) -: 4839: { -: 4840: __glibcxx_requires_string(__s); -: 4841: return this->replace(__pos, __n1, __s, traits_type::length(__s)); -: 4842: } -: 4843: -: 4844: /** -: 4845: * @brief Replace characters with multiple characters. -: 4846: * @param __pos Index of first character to replace. -: 4847: * @param __n1 Number of characters to be replaced. -: 4848: * @param __n2 Number of characters to insert. -: 4849: * @param __c Character to insert. -: 4850: * @return Reference to this string. -: 4851: * @throw std::out_of_range If @a __pos > size(). -: 4852: * @throw std::length_error If new length exceeds @c max_size(). -: 4853: * -: 4854: * Removes the characters in the range [pos,pos + n1) from this -: 4855: * string. In place, @a __n2 copies of @a __c are inserted. -: 4856: * If @a __pos is beyond end of string, out_of_range is thrown. -: 4857: * If the length of result exceeds max_size(), length_error is -: 4858: * thrown. The value of the string doesn't change if an error -: 4859: * is thrown. -: 4860: */ -: 4861: basic_string& -: 4862: replace(size_type __pos, size_type __n1, size_type __n2, _CharT __c) -: 4863: { return _M_replace_aux(_M_check(__pos, "basic_string::replace"), -: 4864: _M_limit(__pos, __n1), __n2, __c); } -: 4865: -: 4866: /** -: 4867: * @brief Replace range of characters with string. -: 4868: * @param __i1 Iterator referencing start of range to replace. -: 4869: * @param __i2 Iterator referencing end of range to replace. -: 4870: * @param __str String value to insert. -: 4871: * @return Reference to this string. -: 4872: * @throw std::length_error If new length exceeds @c max_size(). -: 4873: * -: 4874: * Removes the characters in the range [__i1,__i2). In place, -: 4875: * the value of @a __str is inserted. If the length of result -: 4876: * exceeds max_size(), length_error is thrown. The value of -: 4877: * the string doesn't change if an error is thrown. -: 4878: */ -: 4879: basic_string& -: 4880: replace(iterator __i1, iterator __i2, const basic_string& __str) -: 4881: { return this->replace(__i1, __i2, __str._M_data(), __str.size()); } -: 4882: -: 4883: /** -: 4884: * @brief Replace range of characters with C substring. -: 4885: * @param __i1 Iterator referencing start of range to replace. -: 4886: * @param __i2 Iterator referencing end of range to replace. -: 4887: * @param __s C string value to insert. -: 4888: * @param __n Number of characters from s to insert. -: 4889: * @return Reference to this string. -: 4890: * @throw std::length_error If new length exceeds @c max_size(). -: 4891: * -: 4892: * Removes the characters in the range [__i1,__i2). In place, -: 4893: * the first @a __n characters of @a __s are inserted. If the -: 4894: * length of result exceeds max_size(), length_error is thrown. -: 4895: * The value of the string doesn't change if an error is -: 4896: * thrown. -: 4897: */ -: 4898: basic_string& -: 4899: replace(iterator __i1, iterator __i2, const _CharT* __s, size_type __n) -: 4900: { -: 4901: _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2 -: 4902: && __i2 <= _M_iend()); -: 4903: return this->replace(__i1 - _M_ibegin(), __i2 - __i1, __s, __n); -: 4904: } -: 4905: -: 4906: /** -: 4907: * @brief Replace range of characters with C string. -: 4908: * @param __i1 Iterator referencing start of range to replace. -: 4909: * @param __i2 Iterator referencing end of range to replace. -: 4910: * @param __s C string value to insert. -: 4911: * @return Reference to this string. -: 4912: * @throw std::length_error If new length exceeds @c max_size(). -: 4913: * -: 4914: * Removes the characters in the range [__i1,__i2). In place, -: 4915: * the characters of @a __s are inserted. If the length of -: 4916: * result exceeds max_size(), length_error is thrown. The -: 4917: * value of the string doesn't change if an error is thrown. -: 4918: */ -: 4919: basic_string& -: 4920: replace(iterator __i1, iterator __i2, const _CharT* __s) -: 4921: { -: 4922: __glibcxx_requires_string(__s); -: 4923: return this->replace(__i1, __i2, __s, traits_type::length(__s)); -: 4924: } -: 4925: -: 4926: /** -: 4927: * @brief Replace range of characters with multiple characters -: 4928: * @param __i1 Iterator referencing start of range to replace. -: 4929: * @param __i2 Iterator referencing end of range to replace. -: 4930: * @param __n Number of characters to insert. -: 4931: * @param __c Character to insert. -: 4932: * @return Reference to this string. -: 4933: * @throw std::length_error If new length exceeds @c max_size(). -: 4934: * -: 4935: * Removes the characters in the range [__i1,__i2). In place, -: 4936: * @a __n copies of @a __c are inserted. If the length of -: 4937: * result exceeds max_size(), length_error is thrown. The -: 4938: * value of the string doesn't change if an error is thrown. -: 4939: */ -: 4940: basic_string& -: 4941: replace(iterator __i1, iterator __i2, size_type __n, _CharT __c) -: 4942: { -: 4943: _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2 -: 4944: && __i2 <= _M_iend()); -: 4945: return _M_replace_aux(__i1 - _M_ibegin(), __i2 - __i1, __n, __c); -: 4946: } -: 4947: -: 4948: /** -: 4949: * @brief Replace range of characters with range. -: 4950: * @param __i1 Iterator referencing start of range to replace. -: 4951: * @param __i2 Iterator referencing end of range to replace. -: 4952: * @param __k1 Iterator referencing start of range to insert. -: 4953: * @param __k2 Iterator referencing end of range to insert. -: 4954: * @return Reference to this string. -: 4955: * @throw std::length_error If new length exceeds @c max_size(). -: 4956: * -: 4957: * Removes the characters in the range [__i1,__i2). In place, -: 4958: * characters in the range [__k1,__k2) are inserted. If the -: 4959: * length of result exceeds max_size(), length_error is thrown. -: 4960: * The value of the string doesn't change if an error is -: 4961: * thrown. -: 4962: */ -: 4963: template -: 4964: basic_string& -: 4965: replace(iterator __i1, iterator __i2, -: 4966: _InputIterator __k1, _InputIterator __k2) -: 4967: { -: 4968: _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2 -: 4969: && __i2 <= _M_iend()); -: 4970: __glibcxx_requires_valid_range(__k1, __k2); -: 4971: typedef typename std::__is_integer<_InputIterator>::__type _Integral; -: 4972: return _M_replace_dispatch(__i1, __i2, __k1, __k2, _Integral()); -: 4973: } -: 4974: -: 4975: // Specializations for the common case of pointer and iterator: -: 4976: // useful to avoid the overhead of temporary buffering in _M_replace. -: 4977: basic_string& -: 4978: replace(iterator __i1, iterator __i2, _CharT* __k1, _CharT* __k2) -: 4979: { -: 4980: _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2 -: 4981: && __i2 <= _M_iend()); -: 4982: __glibcxx_requires_valid_range(__k1, __k2); -: 4983: return this->replace(__i1 - _M_ibegin(), __i2 - __i1, -: 4984: __k1, __k2 - __k1); -: 4985: } -: 4986: -: 4987: basic_string& -: 4988: replace(iterator __i1, iterator __i2, -: 4989: const _CharT* __k1, const _CharT* __k2) -: 4990: { -: 4991: _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2 -: 4992: && __i2 <= _M_iend()); -: 4993: __glibcxx_requires_valid_range(__k1, __k2); -: 4994: return this->replace(__i1 - _M_ibegin(), __i2 - __i1, -: 4995: __k1, __k2 - __k1); -: 4996: } -: 4997: -: 4998: basic_string& -: 4999: replace(iterator __i1, iterator __i2, iterator __k1, iterator __k2) -: 5000: { -: 5001: _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2 -: 5002: && __i2 <= _M_iend()); -: 5003: __glibcxx_requires_valid_range(__k1, __k2); -: 5004: return this->replace(__i1 - _M_ibegin(), __i2 - __i1, -: 5005: __k1.base(), __k2 - __k1); -: 5006: } -: 5007: -: 5008: basic_string& -: 5009: replace(iterator __i1, iterator __i2, -: 5010: const_iterator __k1, const_iterator __k2) -: 5011: { -: 5012: _GLIBCXX_DEBUG_PEDASSERT(_M_ibegin() <= __i1 && __i1 <= __i2 -: 5013: && __i2 <= _M_iend()); -: 5014: __glibcxx_requires_valid_range(__k1, __k2); -: 5015: return this->replace(__i1 - _M_ibegin(), __i2 - __i1, -: 5016: __k1.base(), __k2 - __k1); -: 5017: } -: 5018: -: 5019:#if __cplusplus >= 201103L -: 5020: /** -: 5021: * @brief Replace range of characters with initializer_list. -: 5022: * @param __i1 Iterator referencing start of range to replace. -: 5023: * @param __i2 Iterator referencing end of range to replace. -: 5024: * @param __l The initializer_list of characters to insert. -: 5025: * @return Reference to this string. -: 5026: * @throw std::length_error If new length exceeds @c max_size(). -: 5027: * -: 5028: * Removes the characters in the range [__i1,__i2). In place, -: 5029: * characters in the range [__k1,__k2) are inserted. If the -: 5030: * length of result exceeds max_size(), length_error is thrown. -: 5031: * The value of the string doesn't change if an error is -: 5032: * thrown. -: 5033: */ -: 5034: basic_string& replace(iterator __i1, iterator __i2, -: 5035: initializer_list<_CharT> __l) -: 5036: { return this->replace(__i1, __i2, __l.begin(), __l.end()); } -: 5037:#endif // C++11 -: 5038: -: 5039:#if __cplusplus >= 201703L -: 5040: /** -: 5041: * @brief Replace range of characters with string_view. -: 5042: * @param __pos The position to replace at. -: 5043: * @param __n The number of characters to replace. -: 5044: * @param __svt The object convertible to string_view to insert. -: 5045: * @return Reference to this string. -: 5046: */ -: 5047: template -: 5048: _If_sv<_Tp, basic_string&> -: 5049: replace(size_type __pos, size_type __n, const _Tp& __svt) -: 5050: { -: 5051: __sv_type __sv = __svt; -: 5052: return this->replace(__pos, __n, __sv.data(), __sv.size()); -: 5053: } -: 5054: -: 5055: /** -: 5056: * @brief Replace range of characters with string_view. -: 5057: * @param __pos1 The position to replace at. -: 5058: * @param __n1 The number of characters to replace. -: 5059: * @param __svt The object convertible to string_view to insert from. -: 5060: * @param __pos2 The position in the string_view to insert from. -: 5061: * @param __n2 The number of characters to insert. -: 5062: * @return Reference to this string. -: 5063: */ -: 5064: template -: 5065: _If_sv<_Tp, basic_string&> -: 5066: replace(size_type __pos1, size_type __n1, const _Tp& __svt, -: 5067: size_type __pos2, size_type __n2 = npos) -: 5068: { -: 5069: __sv_type __sv = __svt; -: 5070: return this->replace(__pos1, __n1, -: 5071: __sv.data() -: 5072: + std::__sv_check(__sv.size(), __pos2, "basic_string::replace"), -: 5073: std::__sv_limit(__sv.size(), __pos2, __n2)); -: 5074: } -: 5075: -: 5076: /** -: 5077: * @brief Replace range of characters with string_view. -: 5078: * @param __i1 An iterator referencing the start position -: 5079: to replace at. -: 5080: * @param __i2 An iterator referencing the end position -: 5081: for the replace. -: 5082: * @param __svt The object convertible to string_view to insert from. -: 5083: * @return Reference to this string. -: 5084: */ -: 5085: template -: 5086: _If_sv<_Tp, basic_string&> -: 5087: replace(const_iterator __i1, const_iterator __i2, const _Tp& __svt) -: 5088: { -: 5089: __sv_type __sv = __svt; -: 5090: return this->replace(__i1 - begin(), __i2 - __i1, __sv); -: 5091: } -: 5092:#endif // C++17 -: 5093: -: 5094: private: -: 5095: template -: 5096: basic_string& -: 5097: _M_replace_dispatch(iterator __i1, iterator __i2, _Integer __n, -: 5098: _Integer __val, __true_type) -: 5099: { return _M_replace_aux(__i1 - _M_ibegin(), __i2 - __i1, __n, __val); } -: 5100: -: 5101: template -: 5102: basic_string& -: 5103: _M_replace_dispatch(iterator __i1, iterator __i2, _InputIterator __k1, -: 5104: _InputIterator __k2, __false_type); -: 5105: -: 5106: basic_string& -: 5107: _M_replace_aux(size_type __pos1, size_type __n1, size_type __n2, -: 5108: _CharT __c); -: 5109: -: 5110: basic_string& -: 5111: _M_replace_safe(size_type __pos1, size_type __n1, const _CharT* __s, -: 5112: size_type __n2); -: 5113: -: 5114: // _S_construct_aux is used to implement the 21.3.1 para 15 which -: 5115: // requires special behaviour if _InIter is an integral type -: 5116: template -: 5117: static _CharT* -: 5118: _S_construct_aux(_InIterator __beg, _InIterator __end, -: 5119: const _Alloc& __a, __false_type) -: 5120: { -: 5121: typedef typename iterator_traits<_InIterator>::iterator_category _Tag; -: 5122: return _S_construct(__beg, __end, __a, _Tag()); -: 5123: } -: 5124: -: 5125: // _GLIBCXX_RESOLVE_LIB_DEFECTS -: 5126: // 438. Ambiguity in the "do the right thing" clause -: 5127: template -: 5128: static _CharT* -: 5129: _S_construct_aux(_Integer __beg, _Integer __end, -: 5130: const _Alloc& __a, __true_type) -: 5131: { return _S_construct_aux_2(static_cast(__beg), -: 5132: __end, __a); } -: 5133: -: 5134: static _CharT* -: 5135: _S_construct_aux_2(size_type __req, _CharT __c, const _Alloc& __a) -: 5136: { return _S_construct(__req, __c, __a); } -: 5137: -: 5138: template -: 5139: static _CharT* -: 5140: _S_construct(_InIterator __beg, _InIterator __end, const _Alloc& __a) -: 5141: { -: 5142: typedef typename std::__is_integer<_InIterator>::__type _Integral; -: 5143: return _S_construct_aux(__beg, __end, __a, _Integral()); -: 5144: } -: 5145: -: 5146: // For Input Iterators, used in istreambuf_iterators, etc. -: 5147: template -: 5148: static _CharT* -: 5149: _S_construct(_InIterator __beg, _InIterator __end, const _Alloc& __a, -: 5150: input_iterator_tag); -: 5151: -: 5152: // For forward_iterators up to random_access_iterators, used for -: 5153: // string::iterator, _CharT*, etc. -: 5154: template -: 5155: static _CharT* -: 5156: _S_construct(_FwdIterator __beg, _FwdIterator __end, const _Alloc& __a, -: 5157: forward_iterator_tag); -: 5158: -: 5159: static _CharT* -: 5160: _S_construct(size_type __req, _CharT __c, const _Alloc& __a); -: 5161: -: 5162: public: -: 5163: -: 5164: /** -: 5165: * @brief Copy substring into C string. -: 5166: * @param __s C string to copy value into. -: 5167: * @param __n Number of characters to copy. -: 5168: * @param __pos Index of first character to copy. -: 5169: * @return Number of characters actually copied -: 5170: * @throw std::out_of_range If __pos > size(). -: 5171: * -: 5172: * Copies up to @a __n characters starting at @a __pos into the -: 5173: * C string @a __s. If @a __pos is %greater than size(), -: 5174: * out_of_range is thrown. -: 5175: */ -: 5176: size_type -: 5177: copy(_CharT* __s, size_type __n, size_type __pos = 0) const; -: 5178: -: 5179: /** -: 5180: * @brief Swap contents with another string. -: 5181: * @param __s String to swap with. -: 5182: * -: 5183: * Exchanges the contents of this string with that of @a __s in constant -: 5184: * time. -: 5185: */ -: 5186: void -: 5187: swap(basic_string& __s) -: 5188: _GLIBCXX_NOEXCEPT_IF(allocator_traits<_Alloc>::is_always_equal::value); -: 5189: -: 5190: // String operations: -: 5191: /** -: 5192: * @brief Return const pointer to null-terminated contents. -: 5193: * -: 5194: * This is a handle to internal data. Do not modify or dire things may -: 5195: * happen. -: 5196: */ -: 5197: const _CharT* -: 5198: c_str() const _GLIBCXX_NOEXCEPT -: 5199: { return _M_data(); } -: 5200: -: 5201: /** -: 5202: * @brief Return const pointer to contents. -: 5203: * -: 5204: * This is a pointer to internal data. It is undefined to modify -: 5205: * the contents through the returned pointer. To get a pointer that -: 5206: * allows modifying the contents use @c &str[0] instead, -: 5207: * (or in C++17 the non-const @c str.data() overload). -: 5208: */ -: 5209: const _CharT* -: 5210: data() const _GLIBCXX_NOEXCEPT -: 5211: { return _M_data(); } -: 5212: -: 5213:#if __cplusplus >= 201703L -: 5214: /** -: 5215: * @brief Return non-const pointer to contents. -: 5216: * -: 5217: * This is a pointer to the character sequence held by the string. -: 5218: * Modifying the characters in the sequence is allowed. -: 5219: */ -: 5220: _CharT* -: 5221: data() noexcept -: 5222: { -: 5223: _M_leak(); -: 5224: return _M_data(); -: 5225: } -: 5226:#endif -: 5227: -: 5228: /** -: 5229: * @brief Return copy of allocator used to construct this string. -: 5230: */ -: 5231: allocator_type -: 5232: get_allocator() const _GLIBCXX_NOEXCEPT -: 5233: { return _M_dataplus; } -: 5234: -: 5235: /** -: 5236: * @brief Find position of a C substring. -: 5237: * @param __s C string to locate. -: 5238: * @param __pos Index of character to search from. -: 5239: * @param __n Number of characters from @a s to search for. -: 5240: * @return Index of start of first occurrence. -: 5241: * -: 5242: * Starting from @a __pos, searches forward for the first @a -: 5243: * __n characters in @a __s within this string. If found, -: 5244: * returns the index where it begins. If not found, returns -: 5245: * npos. -: 5246: */ -: 5247: size_type -: 5248: find(const _CharT* __s, size_type __pos, size_type __n) const -: 5249: _GLIBCXX_NOEXCEPT; -: 5250: -: 5251: /** -: 5252: * @brief Find position of a string. -: 5253: * @param __str String to locate. -: 5254: * @param __pos Index of character to search from (default 0). -: 5255: * @return Index of start of first occurrence. -: 5256: * -: 5257: * Starting from @a __pos, searches forward for value of @a __str within -: 5258: * this string. If found, returns the index where it begins. If not -: 5259: * found, returns npos. -: 5260: */ -: 5261: size_type -: 5262: find(const basic_string& __str, size_type __pos = 0) const -: 5263: _GLIBCXX_NOEXCEPT -: 5264: { return this->find(__str.data(), __pos, __str.size()); } -: 5265: -: 5266: /** -: 5267: * @brief Find position of a C string. -: 5268: * @param __s C string to locate. -: 5269: * @param __pos Index of character to search from (default 0). -: 5270: * @return Index of start of first occurrence. -: 5271: * -: 5272: * Starting from @a __pos, searches forward for the value of @a -: 5273: * __s within this string. If found, returns the index where -: 5274: * it begins. If not found, returns npos. -: 5275: */ -: 5276: size_type -: 5277: find(const _CharT* __s, size_type __pos = 0) const _GLIBCXX_NOEXCEPT -: 5278: { -: 5279: __glibcxx_requires_string(__s); -: 5280: return this->find(__s, __pos, traits_type::length(__s)); -: 5281: } -: 5282: -: 5283: /** -: 5284: * @brief Find position of a character. -: 5285: * @param __c Character to locate. -: 5286: * @param __pos Index of character to search from (default 0). -: 5287: * @return Index of first occurrence. -: 5288: * -: 5289: * Starting from @a __pos, searches forward for @a __c within -: 5290: * this string. If found, returns the index where it was -: 5291: * found. If not found, returns npos. -: 5292: */ -: 5293: size_type -: 5294: find(_CharT __c, size_type __pos = 0) const _GLIBCXX_NOEXCEPT; -: 5295: -: 5296:#if __cplusplus >= 201703L -: 5297: /** -: 5298: * @brief Find position of a string_view. -: 5299: * @param __svt The object convertible to string_view to locate. -: 5300: * @param __pos Index of character to search from (default 0). -: 5301: * @return Index of start of first occurrence. -: 5302: */ -: 5303: template -: 5304: _If_sv<_Tp, size_type> -: 5305: find(const _Tp& __svt, size_type __pos = 0) const -: 5306: noexcept(is_same<_Tp, __sv_type>::value) -: 5307: { -: 5308: __sv_type __sv = __svt; -: 5309: return this->find(__sv.data(), __pos, __sv.size()); -: 5310: } -: 5311:#endif // C++17 -: 5312: -: 5313: /** -: 5314: * @brief Find last position of a string. -: 5315: * @param __str String to locate. -: 5316: * @param __pos Index of character to search back from (default end). -: 5317: * @return Index of start of last occurrence. -: 5318: * -: 5319: * Starting from @a __pos, searches backward for value of @a -: 5320: * __str within this string. If found, returns the index where -: 5321: * it begins. If not found, returns npos. -: 5322: */ -: 5323: size_type -: 5324: rfind(const basic_string& __str, size_type __pos = npos) const -: 5325: _GLIBCXX_NOEXCEPT -: 5326: { return this->rfind(__str.data(), __pos, __str.size()); } -: 5327: -: 5328: /** -: 5329: * @brief Find last position of a C substring. -: 5330: * @param __s C string to locate. -: 5331: * @param __pos Index of character to search back from. -: 5332: * @param __n Number of characters from s to search for. -: 5333: * @return Index of start of last occurrence. -: 5334: * -: 5335: * Starting from @a __pos, searches backward for the first @a -: 5336: * __n characters in @a __s within this string. If found, -: 5337: * returns the index where it begins. If not found, returns -: 5338: * npos. -: 5339: */ -: 5340: size_type -: 5341: rfind(const _CharT* __s, size_type __pos, size_type __n) const -: 5342: _GLIBCXX_NOEXCEPT; -: 5343: -: 5344: /** -: 5345: * @brief Find last position of a C string. -: 5346: * @param __s C string to locate. -: 5347: * @param __pos Index of character to start search at (default end). -: 5348: * @return Index of start of last occurrence. -: 5349: * -: 5350: * Starting from @a __pos, searches backward for the value of -: 5351: * @a __s within this string. If found, returns the index -: 5352: * where it begins. If not found, returns npos. -: 5353: */ -: 5354: size_type -: 5355: rfind(const _CharT* __s, size_type __pos = npos) const _GLIBCXX_NOEXCEPT -: 5356: { -: 5357: __glibcxx_requires_string(__s); -: 5358: return this->rfind(__s, __pos, traits_type::length(__s)); -: 5359: } -: 5360: -: 5361: /** -: 5362: * @brief Find last position of a character. -: 5363: * @param __c Character to locate. -: 5364: * @param __pos Index of character to search back from (default end). -: 5365: * @return Index of last occurrence. -: 5366: * -: 5367: * Starting from @a __pos, searches backward for @a __c within -: 5368: * this string. If found, returns the index where it was -: 5369: * found. If not found, returns npos. -: 5370: */ -: 5371: size_type -: 5372: rfind(_CharT __c, size_type __pos = npos) const _GLIBCXX_NOEXCEPT; -: 5373: -: 5374:#if __cplusplus >= 201703L -: 5375: /** -: 5376: * @brief Find last position of a string_view. -: 5377: * @param __svt The object convertible to string_view to locate. -: 5378: * @param __pos Index of character to search back from (default end). -: 5379: * @return Index of start of last occurrence. -: 5380: */ -: 5381: template -: 5382: _If_sv<_Tp, size_type> -: 5383: rfind(const _Tp& __svt, size_type __pos = npos) const -: 5384: noexcept(is_same<_Tp, __sv_type>::value) -: 5385: { -: 5386: __sv_type __sv = __svt; -: 5387: return this->rfind(__sv.data(), __pos, __sv.size()); -: 5388: } -: 5389:#endif // C++17 -: 5390: -: 5391: /** -: 5392: * @brief Find position of a character of string. -: 5393: * @param __str String containing characters to locate. -: 5394: * @param __pos Index of character to search from (default 0). -: 5395: * @return Index of first occurrence. -: 5396: * -: 5397: * Starting from @a __pos, searches forward for one of the -: 5398: * characters of @a __str within this string. If found, -: 5399: * returns the index where it was found. If not found, returns -: 5400: * npos. -: 5401: */ -: 5402: size_type -: 5403: find_first_of(const basic_string& __str, size_type __pos = 0) const -: 5404: _GLIBCXX_NOEXCEPT -: 5405: { return this->find_first_of(__str.data(), __pos, __str.size()); } -: 5406: -: 5407: /** -: 5408: * @brief Find position of a character of C substring. -: 5409: * @param __s String containing characters to locate. -: 5410: * @param __pos Index of character to search from. -: 5411: * @param __n Number of characters from s to search for. -: 5412: * @return Index of first occurrence. -: 5413: * -: 5414: * Starting from @a __pos, searches forward for one of the -: 5415: * first @a __n characters of @a __s within this string. If -: 5416: * found, returns the index where it was found. If not found, -: 5417: * returns npos. -: 5418: */ -: 5419: size_type -: 5420: find_first_of(const _CharT* __s, size_type __pos, size_type __n) const -: 5421: _GLIBCXX_NOEXCEPT; -: 5422: -: 5423: /** -: 5424: * @brief Find position of a character of C string. -: 5425: * @param __s String containing characters to locate. -: 5426: * @param __pos Index of character to search from (default 0). -: 5427: * @return Index of first occurrence. -: 5428: * -: 5429: * Starting from @a __pos, searches forward for one of the -: 5430: * characters of @a __s within this string. If found, returns -: 5431: * the index where it was found. If not found, returns npos. -: 5432: */ -: 5433: size_type -: 5434: find_first_of(const _CharT* __s, size_type __pos = 0) const -: 5435: _GLIBCXX_NOEXCEPT -: 5436: { -: 5437: __glibcxx_requires_string(__s); -: 5438: return this->find_first_of(__s, __pos, traits_type::length(__s)); -: 5439: } -: 5440: -: 5441: /** -: 5442: * @brief Find position of a character. -: 5443: * @param __c Character to locate. -: 5444: * @param __pos Index of character to search from (default 0). -: 5445: * @return Index of first occurrence. -: 5446: * -: 5447: * Starting from @a __pos, searches forward for the character -: 5448: * @a __c within this string. If found, returns the index -: 5449: * where it was found. If not found, returns npos. -: 5450: * -: 5451: * Note: equivalent to find(__c, __pos). -: 5452: */ -: 5453: size_type -: 5454: find_first_of(_CharT __c, size_type __pos = 0) const _GLIBCXX_NOEXCEPT -: 5455: { return this->find(__c, __pos); } -: 5456: -: 5457:#if __cplusplus >= 201703L -: 5458: /** -: 5459: * @brief Find position of a character of a string_view. -: 5460: * @param __svt An object convertible to string_view containing -: 5461: * characters to locate. -: 5462: * @param __pos Index of character to search from (default 0). -: 5463: * @return Index of first occurrence. -: 5464: */ -: 5465: template -: 5466: _If_sv<_Tp, size_type> -: 5467: find_first_of(const _Tp& __svt, size_type __pos = 0) const -: 5468: noexcept(is_same<_Tp, __sv_type>::value) -: 5469: { -: 5470: __sv_type __sv = __svt; -: 5471: return this->find_first_of(__sv.data(), __pos, __sv.size()); -: 5472: } -: 5473:#endif // C++17 -: 5474: -: 5475: /** -: 5476: * @brief Find last position of a character of string. -: 5477: * @param __str String containing characters to locate. -: 5478: * @param __pos Index of character to search back from (default end). -: 5479: * @return Index of last occurrence. -: 5480: * -: 5481: * Starting from @a __pos, searches backward for one of the -: 5482: * characters of @a __str within this string. If found, -: 5483: * returns the index where it was found. If not found, returns -: 5484: * npos. -: 5485: */ -: 5486: size_type -: 5487: find_last_of(const basic_string& __str, size_type __pos = npos) const -: 5488: _GLIBCXX_NOEXCEPT -: 5489: { return this->find_last_of(__str.data(), __pos, __str.size()); } -: 5490: -: 5491: /** -: 5492: * @brief Find last position of a character of C substring. -: 5493: * @param __s C string containing characters to locate. -: 5494: * @param __pos Index of character to search back from. -: 5495: * @param __n Number of characters from s to search for. -: 5496: * @return Index of last occurrence. -: 5497: * -: 5498: * Starting from @a __pos, searches backward for one of the -: 5499: * first @a __n characters of @a __s within this string. If -: 5500: * found, returns the index where it was found. If not found, -: 5501: * returns npos. -: 5502: */ -: 5503: size_type -: 5504: find_last_of(const _CharT* __s, size_type __pos, size_type __n) const -: 5505: _GLIBCXX_NOEXCEPT; -: 5506: -: 5507: /** -: 5508: * @brief Find last position of a character of C string. -: 5509: * @param __s C string containing characters to locate. -: 5510: * @param __pos Index of character to search back from (default end). -: 5511: * @return Index of last occurrence. -: 5512: * -: 5513: * Starting from @a __pos, searches backward for one of the -: 5514: * characters of @a __s within this string. If found, returns -: 5515: * the index where it was found. If not found, returns npos. -: 5516: */ -: 5517: size_type -: 5518: find_last_of(const _CharT* __s, size_type __pos = npos) const -: 5519: _GLIBCXX_NOEXCEPT -: 5520: { -: 5521: __glibcxx_requires_string(__s); -: 5522: return this->find_last_of(__s, __pos, traits_type::length(__s)); -: 5523: } -: 5524: -: 5525: /** -: 5526: * @brief Find last position of a character. -: 5527: * @param __c Character to locate. -: 5528: * @param __pos Index of character to search back from (default end). -: 5529: * @return Index of last occurrence. -: 5530: * -: 5531: * Starting from @a __pos, searches backward for @a __c within -: 5532: * this string. If found, returns the index where it was -: 5533: * found. If not found, returns npos. -: 5534: * -: 5535: * Note: equivalent to rfind(__c, __pos). -: 5536: */ -: 5537: size_type -: 5538: find_last_of(_CharT __c, size_type __pos = npos) const _GLIBCXX_NOEXCEPT -: 5539: { return this->rfind(__c, __pos); } -: 5540: -: 5541:#if __cplusplus >= 201703L -: 5542: /** -: 5543: * @brief Find last position of a character of string. -: 5544: * @param __svt An object convertible to string_view containing -: 5545: * characters to locate. -: 5546: * @param __pos Index of character to search back from (default end). -: 5547: * @return Index of last occurrence. -: 5548: */ -: 5549: template -: 5550: _If_sv<_Tp, size_type> -: 5551: find_last_of(const _Tp& __svt, size_type __pos = npos) const -: 5552: noexcept(is_same<_Tp, __sv_type>::value) -: 5553: { -: 5554: __sv_type __sv = __svt; -: 5555: return this->find_last_of(__sv.data(), __pos, __sv.size()); -: 5556: } -: 5557:#endif // C++17 -: 5558: -: 5559: /** -: 5560: * @brief Find position of a character not in string. -: 5561: * @param __str String containing characters to avoid. -: 5562: * @param __pos Index of character to search from (default 0). -: 5563: * @return Index of first occurrence. -: 5564: * -: 5565: * Starting from @a __pos, searches forward for a character not contained -: 5566: * in @a __str within this string. If found, returns the index where it -: 5567: * was found. If not found, returns npos. -: 5568: */ -: 5569: size_type -: 5570: find_first_not_of(const basic_string& __str, size_type __pos = 0) const -: 5571: _GLIBCXX_NOEXCEPT -: 5572: { return this->find_first_not_of(__str.data(), __pos, __str.size()); } -: 5573: -: 5574: /** -: 5575: * @brief Find position of a character not in C substring. -: 5576: * @param __s C string containing characters to avoid. -: 5577: * @param __pos Index of character to search from. -: 5578: * @param __n Number of characters from __s to consider. -: 5579: * @return Index of first occurrence. -: 5580: * -: 5581: * Starting from @a __pos, searches forward for a character not -: 5582: * contained in the first @a __n characters of @a __s within -: 5583: * this string. If found, returns the index where it was -: 5584: * found. If not found, returns npos. -: 5585: */ -: 5586: size_type -: 5587: find_first_not_of(const _CharT* __s, size_type __pos, -: 5588: size_type __n) const _GLIBCXX_NOEXCEPT; -: 5589: -: 5590: /** -: 5591: * @brief Find position of a character not in C string. -: 5592: * @param __s C string containing characters to avoid. -: 5593: * @param __pos Index of character to search from (default 0). -: 5594: * @return Index of first occurrence. -: 5595: * -: 5596: * Starting from @a __pos, searches forward for a character not -: 5597: * contained in @a __s within this string. If found, returns -: 5598: * the index where it was found. If not found, returns npos. -: 5599: */ -: 5600: size_type -: 5601: find_first_not_of(const _CharT* __s, size_type __pos = 0) const -: 5602: _GLIBCXX_NOEXCEPT -: 5603: { -: 5604: __glibcxx_requires_string(__s); -: 5605: return this->find_first_not_of(__s, __pos, traits_type::length(__s)); -: 5606: } -: 5607: -: 5608: /** -: 5609: * @brief Find position of a different character. -: 5610: * @param __c Character to avoid. -: 5611: * @param __pos Index of character to search from (default 0). -: 5612: * @return Index of first occurrence. -: 5613: * -: 5614: * Starting from @a __pos, searches forward for a character -: 5615: * other than @a __c within this string. If found, returns the -: 5616: * index where it was found. If not found, returns npos. -: 5617: */ -: 5618: size_type -: 5619: find_first_not_of(_CharT __c, size_type __pos = 0) const -: 5620: _GLIBCXX_NOEXCEPT; -: 5621: -: 5622:#if __cplusplus >= 201703L -: 5623: /** -: 5624: * @brief Find position of a character not in a string_view. -: 5625: * @param __svt An object convertible to string_view containing -: 5626: * characters to avoid. -: 5627: * @param __pos Index of character to search from (default 0). -: 5628: * @return Index of first occurrence. -: 5629: */ -: 5630: template -: 5631: _If_sv<_Tp, size_type> -: 5632: find_first_not_of(const _Tp& __svt, size_type __pos = 0) const -: 5633: noexcept(is_same<_Tp, __sv_type>::value) -: 5634: { -: 5635: __sv_type __sv = __svt; -: 5636: return this->find_first_not_of(__sv.data(), __pos, __sv.size()); -: 5637: } -: 5638:#endif // C++17 -: 5639: -: 5640: /** -: 5641: * @brief Find last position of a character not in string. -: 5642: * @param __str String containing characters to avoid. -: 5643: * @param __pos Index of character to search back from (default end). -: 5644: * @return Index of last occurrence. -: 5645: * -: 5646: * Starting from @a __pos, searches backward for a character -: 5647: * not contained in @a __str within this string. If found, -: 5648: * returns the index where it was found. If not found, returns -: 5649: * npos. -: 5650: */ -: 5651: size_type -: 5652: find_last_not_of(const basic_string& __str, size_type __pos = npos) const -: 5653: _GLIBCXX_NOEXCEPT -: 5654: { return this->find_last_not_of(__str.data(), __pos, __str.size()); } -: 5655: -: 5656: /** -: 5657: * @brief Find last position of a character not in C substring. -: 5658: * @param __s C string containing characters to avoid. -: 5659: * @param __pos Index of character to search back from. -: 5660: * @param __n Number of characters from s to consider. -: 5661: * @return Index of last occurrence. -: 5662: * -: 5663: * Starting from @a __pos, searches backward for a character not -: 5664: * contained in the first @a __n characters of @a __s within this string. -: 5665: * If found, returns the index where it was found. If not found, -: 5666: * returns npos. -: 5667: */ -: 5668: size_type -: 5669: find_last_not_of(const _CharT* __s, size_type __pos, -: 5670: size_type __n) const _GLIBCXX_NOEXCEPT; -: 5671: /** -: 5672: * @brief Find last position of a character not in C string. -: 5673: * @param __s C string containing characters to avoid. -: 5674: * @param __pos Index of character to search back from (default end). -: 5675: * @return Index of last occurrence. -: 5676: * -: 5677: * Starting from @a __pos, searches backward for a character -: 5678: * not contained in @a __s within this string. If found, -: 5679: * returns the index where it was found. If not found, returns -: 5680: * npos. -: 5681: */ -: 5682: size_type -: 5683: find_last_not_of(const _CharT* __s, size_type __pos = npos) const -: 5684: _GLIBCXX_NOEXCEPT -: 5685: { -: 5686: __glibcxx_requires_string(__s); -: 5687: return this->find_last_not_of(__s, __pos, traits_type::length(__s)); -: 5688: } -: 5689: -: 5690: /** -: 5691: * @brief Find last position of a different character. -: 5692: * @param __c Character to avoid. -: 5693: * @param __pos Index of character to search back from (default end). -: 5694: * @return Index of last occurrence. -: 5695: * -: 5696: * Starting from @a __pos, searches backward for a character other than -: 5697: * @a __c within this string. If found, returns the index where it was -: 5698: * found. If not found, returns npos. -: 5699: */ -: 5700: size_type -: 5701: find_last_not_of(_CharT __c, size_type __pos = npos) const -: 5702: _GLIBCXX_NOEXCEPT; -: 5703: -: 5704:#if __cplusplus >= 201703L -: 5705: /** -: 5706: * @brief Find last position of a character not in a string_view. -: 5707: * @param __svt An object convertible to string_view containing -: 5708: * characters to avoid. -: 5709: * @param __pos Index of character to search back from (default end). -: 5710: * @return Index of last occurrence. -: 5711: */ -: 5712: template -: 5713: _If_sv<_Tp, size_type> -: 5714: find_last_not_of(const _Tp& __svt, size_type __pos = npos) const -: 5715: noexcept(is_same<_Tp, __sv_type>::value) -: 5716: { -: 5717: __sv_type __sv = __svt; -: 5718: return this->find_last_not_of(__sv.data(), __pos, __sv.size()); -: 5719: } -: 5720:#endif // C++17 -: 5721: -: 5722: /** -: 5723: * @brief Get a substring. -: 5724: * @param __pos Index of first character (default 0). -: 5725: * @param __n Number of characters in substring (default remainder). -: 5726: * @return The new string. -: 5727: * @throw std::out_of_range If __pos > size(). -: 5728: * -: 5729: * Construct and return a new string using the @a __n -: 5730: * characters starting at @a __pos. If the string is too -: 5731: * short, use the remainder of the characters. If @a __pos is -: 5732: * beyond the end of the string, out_of_range is thrown. -: 5733: */ -: 5734: basic_string -: 5735: substr(size_type __pos = 0, size_type __n = npos) const -: 5736: { return basic_string(*this, -: 5737: _M_check(__pos, "basic_string::substr"), __n); } -: 5738: -: 5739: /** -: 5740: * @brief Compare to a string. -: 5741: * @param __str String to compare against. -: 5742: * @return Integer < 0, 0, or > 0. -: 5743: * -: 5744: * Returns an integer < 0 if this string is ordered before @a -: 5745: * __str, 0 if their values are equivalent, or > 0 if this -: 5746: * string is ordered after @a __str. Determines the effective -: 5747: * length rlen of the strings to compare as the smallest of -: 5748: * size() and str.size(). The function then compares the two -: 5749: * strings by calling traits::compare(data(), str.data(),rlen). -: 5750: * If the result of the comparison is nonzero returns it, -: 5751: * otherwise the shorter one is ordered first. -: 5752: */ -: 5753: int -: 5754: compare(const basic_string& __str) const -: 5755: { -: 5756: const size_type __size = this->size(); -: 5757: const size_type __osize = __str.size(); -: 5758: const size_type __len = std::min(__size, __osize); -: 5759: -: 5760: int __r = traits_type::compare(_M_data(), __str.data(), __len); -: 5761: if (!__r) -: 5762: __r = _S_compare(__size, __osize); -: 5763: return __r; -: 5764: } -: 5765: -: 5766:#if __cplusplus >= 201703L -: 5767: /** -: 5768: * @brief Compare to a string_view. -: 5769: * @param __svt An object convertible to string_view to compare against. -: 5770: * @return Integer < 0, 0, or > 0. -: 5771: */ -: 5772: template -: 5773: _If_sv<_Tp, int> -: 5774: compare(const _Tp& __svt) const -: 5775: noexcept(is_same<_Tp, __sv_type>::value) -: 5776: { -: 5777: __sv_type __sv = __svt; -: 5778: const size_type __size = this->size(); -: 5779: const size_type __osize = __sv.size(); -: 5780: const size_type __len = std::min(__size, __osize); -: 5781: -: 5782: int __r = traits_type::compare(_M_data(), __sv.data(), __len); -: 5783: if (!__r) -: 5784: __r = _S_compare(__size, __osize); -: 5785: return __r; -: 5786: } -: 5787: -: 5788: /** -: 5789: * @brief Compare to a string_view. -: 5790: * @param __pos A position in the string to start comparing from. -: 5791: * @param __n The number of characters to compare. -: 5792: * @param __svt An object convertible to string_view to compare -: 5793: * against. -: 5794: * @return Integer < 0, 0, or > 0. -: 5795: */ -: 5796: template -: 5797: _If_sv<_Tp, int> -: 5798: compare(size_type __pos, size_type __n, const _Tp& __svt) const -: 5799: noexcept(is_same<_Tp, __sv_type>::value) -: 5800: { -: 5801: __sv_type __sv = __svt; -: 5802: return __sv_type(*this).substr(__pos, __n).compare(__sv); -: 5803: } -: 5804: -: 5805: /** -: 5806: * @brief Compare to a string_view. -: 5807: * @param __pos1 A position in the string to start comparing from. -: 5808: * @param __n1 The number of characters to compare. -: 5809: * @param __svt An object convertible to string_view to compare -: 5810: * against. -: 5811: * @param __pos2 A position in the string_view to start comparing from. -: 5812: * @param __n2 The number of characters to compare. -: 5813: * @return Integer < 0, 0, or > 0. -: 5814: */ -: 5815: template -: 5816: _If_sv<_Tp, int> -: 5817: compare(size_type __pos1, size_type __n1, const _Tp& __svt, -: 5818: size_type __pos2, size_type __n2 = npos) const -: 5819: noexcept(is_same<_Tp, __sv_type>::value) -: 5820: { -: 5821: __sv_type __sv = __svt; -: 5822: return __sv_type(*this) -: 5823: .substr(__pos1, __n1).compare(__sv.substr(__pos2, __n2)); -: 5824: } -: 5825:#endif // C++17 -: 5826: -: 5827: /** -: 5828: * @brief Compare substring to a string. -: 5829: * @param __pos Index of first character of substring. -: 5830: * @param __n Number of characters in substring. -: 5831: * @param __str String to compare against. -: 5832: * @return Integer < 0, 0, or > 0. -: 5833: * -: 5834: * Form the substring of this string from the @a __n characters -: 5835: * starting at @a __pos. Returns an integer < 0 if the -: 5836: * substring is ordered before @a __str, 0 if their values are -: 5837: * equivalent, or > 0 if the substring is ordered after @a -: 5838: * __str. Determines the effective length rlen of the strings -: 5839: * to compare as the smallest of the length of the substring -: 5840: * and @a __str.size(). The function then compares the two -: 5841: * strings by calling -: 5842: * traits::compare(substring.data(),str.data(),rlen). If the -: 5843: * result of the comparison is nonzero returns it, otherwise -: 5844: * the shorter one is ordered first. -: 5845: */ -: 5846: int -: 5847: compare(size_type __pos, size_type __n, const basic_string& __str) const; -: 5848: -: 5849: /** -: 5850: * @brief Compare substring to a substring. -: 5851: * @param __pos1 Index of first character of substring. -: 5852: * @param __n1 Number of characters in substring. -: 5853: * @param __str String to compare against. -: 5854: * @param __pos2 Index of first character of substring of str. -: 5855: * @param __n2 Number of characters in substring of str. -: 5856: * @return Integer < 0, 0, or > 0. -: 5857: * -: 5858: * Form the substring of this string from the @a __n1 -: 5859: * characters starting at @a __pos1. Form the substring of @a -: 5860: * __str from the @a __n2 characters starting at @a __pos2. -: 5861: * Returns an integer < 0 if this substring is ordered before -: 5862: * the substring of @a __str, 0 if their values are equivalent, -: 5863: * or > 0 if this substring is ordered after the substring of -: 5864: * @a __str. Determines the effective length rlen of the -: 5865: * strings to compare as the smallest of the lengths of the -: 5866: * substrings. The function then compares the two strings by -: 5867: * calling -: 5868: * traits::compare(substring.data(),str.substr(pos2,n2).data(),rlen). -: 5869: * If the result of the comparison is nonzero returns it, -: 5870: * otherwise the shorter one is ordered first. -: 5871: */ -: 5872: int -: 5873: compare(size_type __pos1, size_type __n1, const basic_string& __str, -: 5874: size_type __pos2, size_type __n2 = npos) const; -: 5875: -: 5876: /** -: 5877: * @brief Compare to a C string. -: 5878: * @param __s C string to compare against. -: 5879: * @return Integer < 0, 0, or > 0. -: 5880: * -: 5881: * Returns an integer < 0 if this string is ordered before @a __s, 0 if -: 5882: * their values are equivalent, or > 0 if this string is ordered after -: 5883: * @a __s. Determines the effective length rlen of the strings to -: 5884: * compare as the smallest of size() and the length of a string -: 5885: * constructed from @a __s. The function then compares the two strings -: 5886: * by calling traits::compare(data(),s,rlen). If the result of the -: 5887: * comparison is nonzero returns it, otherwise the shorter one is -: 5888: * ordered first. -: 5889: */ -: 5890: int -: 5891: compare(const _CharT* __s) const _GLIBCXX_NOEXCEPT; -: 5892: -: 5893: // _GLIBCXX_RESOLVE_LIB_DEFECTS -: 5894: // 5 String::compare specification questionable -: 5895: /** -: 5896: * @brief Compare substring to a C string. -: 5897: * @param __pos Index of first character of substring. -: 5898: * @param __n1 Number of characters in substring. -: 5899: * @param __s C string to compare against. -: 5900: * @return Integer < 0, 0, or > 0. -: 5901: * -: 5902: * Form the substring of this string from the @a __n1 -: 5903: * characters starting at @a pos. Returns an integer < 0 if -: 5904: * the substring is ordered before @a __s, 0 if their values -: 5905: * are equivalent, or > 0 if the substring is ordered after @a -: 5906: * __s. Determines the effective length rlen of the strings to -: 5907: * compare as the smallest of the length of the substring and -: 5908: * the length of a string constructed from @a __s. The -: 5909: * function then compares the two string by calling -: 5910: * traits::compare(substring.data(),__s,rlen). If the result of -: 5911: * the comparison is nonzero returns it, otherwise the shorter -: 5912: * one is ordered first. -: 5913: */ -: 5914: int -: 5915: compare(size_type __pos, size_type __n1, const _CharT* __s) const; -: 5916: -: 5917: /** -: 5918: * @brief Compare substring against a character %array. -: 5919: * @param __pos Index of first character of substring. -: 5920: * @param __n1 Number of characters in substring. -: 5921: * @param __s character %array to compare against. -: 5922: * @param __n2 Number of characters of s. -: 5923: * @return Integer < 0, 0, or > 0. -: 5924: * -: 5925: * Form the substring of this string from the @a __n1 -: 5926: * characters starting at @a __pos. Form a string from the -: 5927: * first @a __n2 characters of @a __s. Returns an integer < 0 -: 5928: * if this substring is ordered before the string from @a __s, -: 5929: * 0 if their values are equivalent, or > 0 if this substring -: 5930: * is ordered after the string from @a __s. Determines the -: 5931: * effective length rlen of the strings to compare as the -: 5932: * smallest of the length of the substring and @a __n2. The -: 5933: * function then compares the two strings by calling -: 5934: * traits::compare(substring.data(),s,rlen). If the result of -: 5935: * the comparison is nonzero returns it, otherwise the shorter -: 5936: * one is ordered first. -: 5937: * -: 5938: * NB: s must have at least n2 characters, '\\0' has -: 5939: * no special meaning. -: 5940: */ -: 5941: int -: 5942: compare(size_type __pos, size_type __n1, const _CharT* __s, -: 5943: size_type __n2) const; -: 5944: -: 5945:#if __cplusplus > 201703L -: 5946: bool -: 5947: starts_with(basic_string_view<_CharT, _Traits> __x) const noexcept -: 5948: { return __sv_type(this->data(), this->size()).starts_with(__x); } -: 5949: -: 5950: bool -: 5951: starts_with(_CharT __x) const noexcept -: 5952: { return __sv_type(this->data(), this->size()).starts_with(__x); } -: 5953: -: 5954: bool -: 5955: starts_with(const _CharT* __x) const noexcept -: 5956: { return __sv_type(this->data(), this->size()).starts_with(__x); } -: 5957: -: 5958: bool -: 5959: ends_with(basic_string_view<_CharT, _Traits> __x) const noexcept -: 5960: { return __sv_type(this->data(), this->size()).ends_with(__x); } -: 5961: -: 5962: bool -: 5963: ends_with(_CharT __x) const noexcept -: 5964: { return __sv_type(this->data(), this->size()).ends_with(__x); } -: 5965: -: 5966: bool -: 5967: ends_with(const _CharT* __x) const noexcept -: 5968: { return __sv_type(this->data(), this->size()).ends_with(__x); } -: 5969:#endif // C++20 -: 5970: -: 5971:# ifdef _GLIBCXX_TM_TS_INTERNAL -: 5972: friend void -: 5973: ::_txnal_cow_string_C1_for_exceptions(void* that, const char* s, -: 5974: void* exc); -: 5975: friend const char* -: 5976: ::_txnal_cow_string_c_str(const void *that); -: 5977: friend void -: 5978: ::_txnal_cow_string_D1(void *that); -: 5979: friend void -: 5980: ::_txnal_cow_string_D1_commit(void *that); -: 5981:# endif -: 5982: }; -: 5983:#endif // !_GLIBCXX_USE_CXX11_ABI -: 5984: -: 5985:#if __cpp_deduction_guides >= 201606 -: 5986:_GLIBCXX_BEGIN_NAMESPACE_CXX11 -: 5987: template::value_type, -: 5989: typename _Allocator = allocator<_CharT>, -: 5990: typename = _RequireInputIter<_InputIterator>, -: 5991: typename = _RequireAllocator<_Allocator>> -: 5992: basic_string(_InputIterator, _InputIterator, _Allocator = _Allocator()) -: 5993: -> basic_string<_CharT, char_traits<_CharT>, _Allocator>; -: 5994: -: 5995: // _GLIBCXX_RESOLVE_LIB_DEFECTS -: 5996: // 3075. basic_string needs deduction guides from basic_string_view -: 5997: template, -: 5999: typename = _RequireAllocator<_Allocator>> -: 6000: basic_string(basic_string_view<_CharT, _Traits>, const _Allocator& = _Allocator()) -: 6001: -> basic_string<_CharT, _Traits, _Allocator>; -: 6002: -: 6003: template, -: 6005: typename = _RequireAllocator<_Allocator>> -: 6006: basic_string(basic_string_view<_CharT, _Traits>, -: 6007: typename basic_string<_CharT, _Traits, _Allocator>::size_type, -: 6008: typename basic_string<_CharT, _Traits, _Allocator>::size_type, -: 6009: const _Allocator& = _Allocator()) -: 6010: -> basic_string<_CharT, _Traits, _Allocator>; -: 6011:_GLIBCXX_END_NAMESPACE_CXX11 -: 6012:#endif -: 6013: -: 6014: // operator+ -: 6015: /** -: 6016: * @brief Concatenate two strings. -: 6017: * @param __lhs First string. -: 6018: * @param __rhs Last string. -: 6019: * @return New string with value of @a __lhs followed by @a __rhs. -: 6020: */ -: 6021: template -: 6022: basic_string<_CharT, _Traits, _Alloc> -: 6023: operator+(const basic_string<_CharT, _Traits, _Alloc>& __lhs, -: 6024: const basic_string<_CharT, _Traits, _Alloc>& __rhs) -: 6025: { -: 6026: basic_string<_CharT, _Traits, _Alloc> __str(__lhs); -: 6027: __str.append(__rhs); -: 6028: return __str; -: 6029: } -: 6030: -: 6031: /** -: 6032: * @brief Concatenate C string and string. -: 6033: * @param __lhs First string. -: 6034: * @param __rhs Last string. -: 6035: * @return New string with value of @a __lhs followed by @a __rhs. -: 6036: */ -: 6037: template -: 6038: basic_string<_CharT,_Traits,_Alloc> -: 6039: operator+(const _CharT* __lhs, -: 6040: const basic_string<_CharT,_Traits,_Alloc>& __rhs); -: 6041: -: 6042: /** -: 6043: * @brief Concatenate character and string. -: 6044: * @param __lhs First string. -: 6045: * @param __rhs Last string. -: 6046: * @return New string with @a __lhs followed by @a __rhs. -: 6047: */ -: 6048: template -: 6049: basic_string<_CharT,_Traits,_Alloc> -: 6050: operator+(_CharT __lhs, const basic_string<_CharT,_Traits,_Alloc>& __rhs); -: 6051: -: 6052: /** -: 6053: * @brief Concatenate string and C string. -: 6054: * @param __lhs First string. -: 6055: * @param __rhs Last string. -: 6056: * @return New string with @a __lhs followed by @a __rhs. -: 6057: */ -: 6058: template -: 6059: inline basic_string<_CharT, _Traits, _Alloc> -: 6060: operator+(const basic_string<_CharT, _Traits, _Alloc>& __lhs, -: 6061: const _CharT* __rhs) -: 6062: { -: 6063: basic_string<_CharT, _Traits, _Alloc> __str(__lhs); -: 6064: __str.append(__rhs); -: 6065: return __str; -: 6066: } -: 6067: -: 6068: /** -: 6069: * @brief Concatenate string and character. -: 6070: * @param __lhs First string. -: 6071: * @param __rhs Last string. -: 6072: * @return New string with @a __lhs followed by @a __rhs. -: 6073: */ -: 6074: template -: 6075: inline basic_string<_CharT, _Traits, _Alloc> -: 6076: operator+(const basic_string<_CharT, _Traits, _Alloc>& __lhs, _CharT __rhs) -: 6077: { -: 6078: typedef basic_string<_CharT, _Traits, _Alloc> __string_type; -: 6079: typedef typename __string_type::size_type __size_type; -: 6080: __string_type __str(__lhs); -: 6081: __str.append(__size_type(1), __rhs); -: 6082: return __str; -: 6083: } -: 6084: -: 6085:#if __cplusplus >= 201103L -: 6086: template -: 6087: inline basic_string<_CharT, _Traits, _Alloc> -: 6088: operator+(basic_string<_CharT, _Traits, _Alloc>&& __lhs, -: 6089: const basic_string<_CharT, _Traits, _Alloc>& __rhs) -: 6090: { return std::move(__lhs.append(__rhs)); } -: 6091: -: 6092: template -: 6093: inline basic_string<_CharT, _Traits, _Alloc> -: 6094: operator+(const basic_string<_CharT, _Traits, _Alloc>& __lhs, -: 6095: basic_string<_CharT, _Traits, _Alloc>&& __rhs) -: 6096: { return std::move(__rhs.insert(0, __lhs)); } -: 6097: -: 6098: template -: 6099: inline basic_string<_CharT, _Traits, _Alloc> -: 6100: operator+(basic_string<_CharT, _Traits, _Alloc>&& __lhs, -: 6101: basic_string<_CharT, _Traits, _Alloc>&& __rhs) -: 6102: { -: 6103: const auto __size = __lhs.size() + __rhs.size(); -: 6104: const bool __cond = (__size > __lhs.capacity() -: 6105: && __size <= __rhs.capacity()); -: 6106: return __cond ? std::move(__rhs.insert(0, __lhs)) -: 6107: : std::move(__lhs.append(__rhs)); -: 6108: } -: 6109: -: 6110: template -: 6111: inline basic_string<_CharT, _Traits, _Alloc> -: 6112: operator+(const _CharT* __lhs, -: 6113: basic_string<_CharT, _Traits, _Alloc>&& __rhs) -: 6114: { return std::move(__rhs.insert(0, __lhs)); } -: 6115: -: 6116: template -: 6117: inline basic_string<_CharT, _Traits, _Alloc> -: 6118: operator+(_CharT __lhs, -: 6119: basic_string<_CharT, _Traits, _Alloc>&& __rhs) -: 6120: { return std::move(__rhs.insert(0, 1, __lhs)); } -: 6121: -: 6122: template -: 6123: inline basic_string<_CharT, _Traits, _Alloc> -: 6124: operator+(basic_string<_CharT, _Traits, _Alloc>&& __lhs, -: 6125: const _CharT* __rhs) -: 6126: { return std::move(__lhs.append(__rhs)); } -: 6127: -: 6128: template -: 6129: inline basic_string<_CharT, _Traits, _Alloc> -: 6130: operator+(basic_string<_CharT, _Traits, _Alloc>&& __lhs, -: 6131: _CharT __rhs) -: 6132: { return std::move(__lhs.append(1, __rhs)); } -: 6133:#endif -: 6134: -: 6135: // operator == -: 6136: /** -: 6137: * @brief Test equivalence of two strings. -: 6138: * @param __lhs First string. -: 6139: * @param __rhs Second string. -: 6140: * @return True if @a __lhs.compare(@a __rhs) == 0. False otherwise. -: 6141: */ -: 6142: template -: 6143: inline bool -: 6144: operator==(const basic_string<_CharT, _Traits, _Alloc>& __lhs, -: 6145: const basic_string<_CharT, _Traits, _Alloc>& __rhs) -: 6146: _GLIBCXX_NOEXCEPT -: 6147: { return __lhs.compare(__rhs) == 0; } -: 6148: -: 6149: template -: 6150: inline -: 6151: typename __gnu_cxx::__enable_if<__is_char<_CharT>::__value, bool>::__type -: 6152: operator==(const basic_string<_CharT>& __lhs, -: 6153: const basic_string<_CharT>& __rhs) _GLIBCXX_NOEXCEPT -: 6154: { return (__lhs.size() == __rhs.size() -: 6155: && !std::char_traits<_CharT>::compare(__lhs.data(), __rhs.data(), -: 6156: __lhs.size())); } -: 6157: -: 6158: /** -: 6159: * @brief Test equivalence of C string and string. -: 6160: * @param __lhs C string. -: 6161: * @param __rhs String. -: 6162: * @return True if @a __rhs.compare(@a __lhs) == 0. False otherwise. -: 6163: */ -: 6164: template -: 6165: inline bool -: 6166: operator==(const _CharT* __lhs, -: 6167: const basic_string<_CharT, _Traits, _Alloc>& __rhs) -: 6168: { return __rhs.compare(__lhs) == 0; } -: 6169: -: 6170: /** -: 6171: * @brief Test equivalence of string and C string. -: 6172: * @param __lhs String. -: 6173: * @param __rhs C string. -: 6174: * @return True if @a __lhs.compare(@a __rhs) == 0. False otherwise. -: 6175: */ -: 6176: template -: 6177: inline bool -: 6178: operator==(const basic_string<_CharT, _Traits, _Alloc>& __lhs, -: 6179: const _CharT* __rhs) -: 6180: { return __lhs.compare(__rhs) == 0; } -: 6181: -: 6182: // operator != -: 6183: /** -: 6184: * @brief Test difference of two strings. -: 6185: * @param __lhs First string. -: 6186: * @param __rhs Second string. -: 6187: * @return True if @a __lhs.compare(@a __rhs) != 0. False otherwise. -: 6188: */ -: 6189: template -: 6190: inline bool -: 6191: operator!=(const basic_string<_CharT, _Traits, _Alloc>& __lhs, -: 6192: const basic_string<_CharT, _Traits, _Alloc>& __rhs) -: 6193: _GLIBCXX_NOEXCEPT -: 6194: { return !(__lhs == __rhs); } -: 6195: -: 6196: /** -: 6197: * @brief Test difference of C string and string. -: 6198: * @param __lhs C string. -: 6199: * @param __rhs String. -: 6200: * @return True if @a __rhs.compare(@a __lhs) != 0. False otherwise. -: 6201: */ -: 6202: template -: 6203: inline bool -: 6204: operator!=(const _CharT* __lhs, -: 6205: const basic_string<_CharT, _Traits, _Alloc>& __rhs) -: 6206: { return !(__lhs == __rhs); } -: 6207: -: 6208: /** -: 6209: * @brief Test difference of string and C string. -: 6210: * @param __lhs String. -: 6211: * @param __rhs C string. -: 6212: * @return True if @a __lhs.compare(@a __rhs) != 0. False otherwise. -: 6213: */ -: 6214: template -: 6215: inline bool -: 6216: operator!=(const basic_string<_CharT, _Traits, _Alloc>& __lhs, -: 6217: const _CharT* __rhs) -: 6218: { return !(__lhs == __rhs); } -: 6219: -: 6220: // operator < -: 6221: /** -: 6222: * @brief Test if string precedes string. -: 6223: * @param __lhs First string. -: 6224: * @param __rhs Second string. -: 6225: * @return True if @a __lhs precedes @a __rhs. False otherwise. -: 6226: */ -: 6227: template -: 6228: inline bool -: 6229: operator<(const basic_string<_CharT, _Traits, _Alloc>& __lhs, -: 6230: const basic_string<_CharT, _Traits, _Alloc>& __rhs) -: 6231: _GLIBCXX_NOEXCEPT -: 6232: { return __lhs.compare(__rhs) < 0; } -: 6233: -: 6234: /** -: 6235: * @brief Test if string precedes C string. -: 6236: * @param __lhs String. -: 6237: * @param __rhs C string. -: 6238: * @return True if @a __lhs precedes @a __rhs. False otherwise. -: 6239: */ -: 6240: template -: 6241: inline bool -: 6242: operator<(const basic_string<_CharT, _Traits, _Alloc>& __lhs, -: 6243: const _CharT* __rhs) -: 6244: { return __lhs.compare(__rhs) < 0; } -: 6245: -: 6246: /** -: 6247: * @brief Test if C string precedes string. -: 6248: * @param __lhs C string. -: 6249: * @param __rhs String. -: 6250: * @return True if @a __lhs precedes @a __rhs. False otherwise. -: 6251: */ -: 6252: template -: 6253: inline bool -: 6254: operator<(const _CharT* __lhs, -: 6255: const basic_string<_CharT, _Traits, _Alloc>& __rhs) -: 6256: { return __rhs.compare(__lhs) > 0; } -: 6257: -: 6258: // operator > -: 6259: /** -: 6260: * @brief Test if string follows string. -: 6261: * @param __lhs First string. -: 6262: * @param __rhs Second string. -: 6263: * @return True if @a __lhs follows @a __rhs. False otherwise. -: 6264: */ -: 6265: template -: 6266: inline bool -: 6267: operator>(const basic_string<_CharT, _Traits, _Alloc>& __lhs, -: 6268: const basic_string<_CharT, _Traits, _Alloc>& __rhs) -: 6269: _GLIBCXX_NOEXCEPT -: 6270: { return __lhs.compare(__rhs) > 0; } -: 6271: -: 6272: /** -: 6273: * @brief Test if string follows C string. -: 6274: * @param __lhs String. -: 6275: * @param __rhs C string. -: 6276: * @return True if @a __lhs follows @a __rhs. False otherwise. -: 6277: */ -: 6278: template -: 6279: inline bool -: 6280: operator>(const basic_string<_CharT, _Traits, _Alloc>& __lhs, -: 6281: const _CharT* __rhs) -: 6282: { return __lhs.compare(__rhs) > 0; } -: 6283: -: 6284: /** -: 6285: * @brief Test if C string follows string. -: 6286: * @param __lhs C string. -: 6287: * @param __rhs String. -: 6288: * @return True if @a __lhs follows @a __rhs. False otherwise. -: 6289: */ -: 6290: template -: 6291: inline bool -: 6292: operator>(const _CharT* __lhs, -: 6293: const basic_string<_CharT, _Traits, _Alloc>& __rhs) -: 6294: { return __rhs.compare(__lhs) < 0; } -: 6295: -: 6296: // operator <= -: 6297: /** -: 6298: * @brief Test if string doesn't follow string. -: 6299: * @param __lhs First string. -: 6300: * @param __rhs Second string. -: 6301: * @return True if @a __lhs doesn't follow @a __rhs. False otherwise. -: 6302: */ -: 6303: template -: 6304: inline bool -: 6305: operator<=(const basic_string<_CharT, _Traits, _Alloc>& __lhs, -: 6306: const basic_string<_CharT, _Traits, _Alloc>& __rhs) -: 6307: _GLIBCXX_NOEXCEPT -: 6308: { return __lhs.compare(__rhs) <= 0; } -: 6309: -: 6310: /** -: 6311: * @brief Test if string doesn't follow C string. -: 6312: * @param __lhs String. -: 6313: * @param __rhs C string. -: 6314: * @return True if @a __lhs doesn't follow @a __rhs. False otherwise. -: 6315: */ -: 6316: template -: 6317: inline bool -: 6318: operator<=(const basic_string<_CharT, _Traits, _Alloc>& __lhs, -: 6319: const _CharT* __rhs) -: 6320: { return __lhs.compare(__rhs) <= 0; } -: 6321: -: 6322: /** -: 6323: * @brief Test if C string doesn't follow string. -: 6324: * @param __lhs C string. -: 6325: * @param __rhs String. -: 6326: * @return True if @a __lhs doesn't follow @a __rhs. False otherwise. -: 6327: */ -: 6328: template -: 6329: inline bool -: 6330: operator<=(const _CharT* __lhs, -: 6331: const basic_string<_CharT, _Traits, _Alloc>& __rhs) -: 6332: { return __rhs.compare(__lhs) >= 0; } -: 6333: -: 6334: // operator >= -: 6335: /** -: 6336: * @brief Test if string doesn't precede string. -: 6337: * @param __lhs First string. -: 6338: * @param __rhs Second string. -: 6339: * @return True if @a __lhs doesn't precede @a __rhs. False otherwise. -: 6340: */ -: 6341: template -: 6342: inline bool -: 6343: operator>=(const basic_string<_CharT, _Traits, _Alloc>& __lhs, -: 6344: const basic_string<_CharT, _Traits, _Alloc>& __rhs) -: 6345: _GLIBCXX_NOEXCEPT -: 6346: { return __lhs.compare(__rhs) >= 0; } -: 6347: -: 6348: /** -: 6349: * @brief Test if string doesn't precede C string. -: 6350: * @param __lhs String. -: 6351: * @param __rhs C string. -: 6352: * @return True if @a __lhs doesn't precede @a __rhs. False otherwise. -: 6353: */ -: 6354: template -: 6355: inline bool -: 6356: operator>=(const basic_string<_CharT, _Traits, _Alloc>& __lhs, -: 6357: const _CharT* __rhs) -: 6358: { return __lhs.compare(__rhs) >= 0; } -: 6359: -: 6360: /** -: 6361: * @brief Test if C string doesn't precede string. -: 6362: * @param __lhs C string. -: 6363: * @param __rhs String. -: 6364: * @return True if @a __lhs doesn't precede @a __rhs. False otherwise. -: 6365: */ -: 6366: template -: 6367: inline bool -: 6368: operator>=(const _CharT* __lhs, -: 6369: const basic_string<_CharT, _Traits, _Alloc>& __rhs) -: 6370: { return __rhs.compare(__lhs) <= 0; } -: 6371: -: 6372: /** -: 6373: * @brief Swap contents of two strings. -: 6374: * @param __lhs First string. -: 6375: * @param __rhs Second string. -: 6376: * -: 6377: * Exchanges the contents of @a __lhs and @a __rhs in constant time. -: 6378: */ -: 6379: template -: 6380: inline void -: 6381: swap(basic_string<_CharT, _Traits, _Alloc>& __lhs, -: 6382: basic_string<_CharT, _Traits, _Alloc>& __rhs) -: 6383: _GLIBCXX_NOEXCEPT_IF(noexcept(__lhs.swap(__rhs))) -: 6384: { __lhs.swap(__rhs); } -: 6385: -: 6386: -: 6387: /** -: 6388: * @brief Read stream into a string. -: 6389: * @param __is Input stream. -: 6390: * @param __str Buffer to store into. -: 6391: * @return Reference to the input stream. -: 6392: * -: 6393: * Stores characters from @a __is into @a __str until whitespace is -: 6394: * found, the end of the stream is encountered, or str.max_size() -: 6395: * is reached. If is.width() is non-zero, that is the limit on the -: 6396: * number of characters stored into @a __str. Any previous -: 6397: * contents of @a __str are erased. -: 6398: */ -: 6399: template -: 6400: basic_istream<_CharT, _Traits>& -: 6401: operator>>(basic_istream<_CharT, _Traits>& __is, -: 6402: basic_string<_CharT, _Traits, _Alloc>& __str); -: 6403: -: 6404: template<> -: 6405: basic_istream& -: 6406: operator>>(basic_istream& __is, basic_string& __str); -: 6407: -: 6408: /** -: 6409: * @brief Write string to a stream. -: 6410: * @param __os Output stream. -: 6411: * @param __str String to write out. -: 6412: * @return Reference to the output stream. -: 6413: * -: 6414: * Output characters of @a __str into os following the same rules as for -: 6415: * writing a C string. -: 6416: */ -: 6417: template -: 6418: inline basic_ostream<_CharT, _Traits>& -: 6419: operator<<(basic_ostream<_CharT, _Traits>& __os, -: 6420: const basic_string<_CharT, _Traits, _Alloc>& __str) -: 6421: { -: 6422: // _GLIBCXX_RESOLVE_LIB_DEFECTS -: 6423: // 586. string inserter not a formatted function -: 6424: return __ostream_insert(__os, __str.data(), __str.size()); -: 6425: } -: 6426: -: 6427: /** -: 6428: * @brief Read a line from stream into a string. -: 6429: * @param __is Input stream. -: 6430: * @param __str Buffer to store into. -: 6431: * @param __delim Character marking end of line. -: 6432: * @return Reference to the input stream. -: 6433: * -: 6434: * Stores characters from @a __is into @a __str until @a __delim is -: 6435: * found, the end of the stream is encountered, or str.max_size() -: 6436: * is reached. Any previous contents of @a __str are erased. If -: 6437: * @a __delim is encountered, it is extracted but not stored into -: 6438: * @a __str. -: 6439: */ -: 6440: template -: 6441: basic_istream<_CharT, _Traits>& -: 6442: getline(basic_istream<_CharT, _Traits>& __is, -: 6443: basic_string<_CharT, _Traits, _Alloc>& __str, _CharT __delim); -: 6444: -: 6445: /** -: 6446: * @brief Read a line from stream into a string. -: 6447: * @param __is Input stream. -: 6448: * @param __str Buffer to store into. -: 6449: * @return Reference to the input stream. -: 6450: * -: 6451: * Stores characters from is into @a __str until '\n' is -: 6452: * found, the end of the stream is encountered, or str.max_size() -: 6453: * is reached. Any previous contents of @a __str are erased. If -: 6454: * end of line is encountered, it is extracted but not stored into -: 6455: * @a __str. -: 6456: */ -: 6457: template -: 6458: inline basic_istream<_CharT, _Traits>& -: 6459: getline(basic_istream<_CharT, _Traits>& __is, -: 6460: basic_string<_CharT, _Traits, _Alloc>& __str) -: 6461: { return std::getline(__is, __str, __is.widen('\n')); } -: 6462: -: 6463:#if __cplusplus >= 201103L -: 6464: /// Read a line from an rvalue stream into a string. -: 6465: template -: 6466: inline basic_istream<_CharT, _Traits>& -: 6467: getline(basic_istream<_CharT, _Traits>&& __is, -: 6468: basic_string<_CharT, _Traits, _Alloc>& __str, _CharT __delim) -: 6469: { return std::getline(__is, __str, __delim); } -: 6470: -: 6471: /// Read a line from an rvalue stream into a string. -: 6472: template -: 6473: inline basic_istream<_CharT, _Traits>& -: 6474: getline(basic_istream<_CharT, _Traits>&& __is, -: 6475: basic_string<_CharT, _Traits, _Alloc>& __str) -: 6476: { return std::getline(__is, __str); } -: 6477:#endif -: 6478: -: 6479: template<> -: 6480: basic_istream& -: 6481: getline(basic_istream& __in, basic_string& __str, -: 6482: char __delim); -: 6483: -: 6484:#ifdef _GLIBCXX_USE_WCHAR_T -: 6485: template<> -: 6486: basic_istream& -: 6487: getline(basic_istream& __in, basic_string& __str, -: 6488: wchar_t __delim); -: 6489:#endif -: 6490: -: 6491:_GLIBCXX_END_NAMESPACE_VERSION -: 6492:} // namespace -: 6493: -: 6494:#if __cplusplus >= 201103L -: 6495: -: 6496:#include -: 6497: -: 6498:namespace std _GLIBCXX_VISIBILITY(default) -: 6499:{ -: 6500:_GLIBCXX_BEGIN_NAMESPACE_VERSION -: 6501:_GLIBCXX_BEGIN_NAMESPACE_CXX11 -: 6502: -: 6503:#if _GLIBCXX_USE_C99_STDLIB -: 6504: // 21.4 Numeric Conversions [string.conversions]. -: 6505: inline int -: 6506: stoi(const string& __str, size_t* __idx = 0, int __base = 10) -: 6507: { return __gnu_cxx::__stoa(&std::strtol, "stoi", __str.c_str(), -: 6508: __idx, __base); } -: 6509: -: 6510: inline long -: 6511: stol(const string& __str, size_t* __idx = 0, int __base = 10) -: 6512: { return __gnu_cxx::__stoa(&std::strtol, "stol", __str.c_str(), -: 6513: __idx, __base); } -: 6514: -: 6515: inline unsigned long -: 6516: stoul(const string& __str, size_t* __idx = 0, int __base = 10) -: 6517: { return __gnu_cxx::__stoa(&std::strtoul, "stoul", __str.c_str(), -: 6518: __idx, __base); } -: 6519: -: 6520: inline long long -: 6521: stoll(const string& __str, size_t* __idx = 0, int __base = 10) -: 6522: { return __gnu_cxx::__stoa(&std::strtoll, "stoll", __str.c_str(), -: 6523: __idx, __base); } -: 6524: -: 6525: inline unsigned long long -: 6526: stoull(const string& __str, size_t* __idx = 0, int __base = 10) -: 6527: { return __gnu_cxx::__stoa(&std::strtoull, "stoull", __str.c_str(), -: 6528: __idx, __base); } -: 6529: -: 6530: // NB: strtof vs strtod. -: 6531: inline float -: 6532: stof(const string& __str, size_t* __idx = 0) -: 6533: { return __gnu_cxx::__stoa(&std::strtof, "stof", __str.c_str(), __idx); } -: 6534: -: 6535: inline double -: 6536: stod(const string& __str, size_t* __idx = 0) -: 6537: { return __gnu_cxx::__stoa(&std::strtod, "stod", __str.c_str(), __idx); } -: 6538: -: 6539: inline long double -: 6540: stold(const string& __str, size_t* __idx = 0) -: 6541: { return __gnu_cxx::__stoa(&std::strtold, "stold", __str.c_str(), __idx); } -: 6542:#endif // _GLIBCXX_USE_C99_STDLIB -: 6543: -: 6544:#if _GLIBCXX_USE_C99_STDIO -: 6545: // NB: (v)snprintf vs sprintf. -: 6546: -: 6547: // DR 1261. -: 6548: inline string -: 6549: to_string(int __val) -: 6550: { return __gnu_cxx::__to_xstring(&std::vsnprintf, 4 * sizeof(int), -: 6551: "%d", __val); } -: 6552: -: 6553: inline string -: 6554: to_string(unsigned __val) -: 6555: { return __gnu_cxx::__to_xstring(&std::vsnprintf, -: 6556: 4 * sizeof(unsigned), -: 6557: "%u", __val); } -: 6558: -: 6559: inline string -: 6560: to_string(long __val) -: 6561: { return __gnu_cxx::__to_xstring(&std::vsnprintf, 4 * sizeof(long), -: 6562: "%ld", __val); } -: 6563: -: 6564: inline string -: 6565: to_string(unsigned long __val) -: 6566: { return __gnu_cxx::__to_xstring(&std::vsnprintf, -: 6567: 4 * sizeof(unsigned long), -: 6568: "%lu", __val); } -: 6569: -: 6570: inline string -: 6571: to_string(long long __val) -: 6572: { return __gnu_cxx::__to_xstring(&std::vsnprintf, -: 6573: 4 * sizeof(long long), -: 6574: "%lld", __val); } -: 6575: -: 6576: inline string -: 6577: to_string(unsigned long long __val) -: 6578: { return __gnu_cxx::__to_xstring(&std::vsnprintf, -: 6579: 4 * sizeof(unsigned long long), -: 6580: "%llu", __val); } -: 6581: -: 6582: inline string -: 6583: to_string(float __val) -: 6584: { -: 6585: const int __n = -: 6586: __gnu_cxx::__numeric_traits::__max_exponent10 + 20; -: 6587: return __gnu_cxx::__to_xstring(&std::vsnprintf, __n, -: 6588: "%f", __val); -: 6589: } -: 6590: -: 6591: inline string -: 6592: to_string(double __val) -: 6593: { -: 6594: const int __n = -: 6595: __gnu_cxx::__numeric_traits::__max_exponent10 + 20; -: 6596: return __gnu_cxx::__to_xstring(&std::vsnprintf, __n, -: 6597: "%f", __val); -: 6598: } -: 6599: -: 6600: inline string -: 6601: to_string(long double __val) -: 6602: { -: 6603: const int __n = -: 6604: __gnu_cxx::__numeric_traits::__max_exponent10 + 20; -: 6605: return __gnu_cxx::__to_xstring(&std::vsnprintf, __n, -: 6606: "%Lf", __val); -: 6607: } -: 6608:#endif // _GLIBCXX_USE_C99_STDIO -: 6609: -: 6610:#if defined(_GLIBCXX_USE_WCHAR_T) && _GLIBCXX_USE_C99_WCHAR -: 6611: inline int -: 6612: stoi(const wstring& __str, size_t* __idx = 0, int __base = 10) -: 6613: { return __gnu_cxx::__stoa(&std::wcstol, "stoi", __str.c_str(), -: 6614: __idx, __base); } -: 6615: -: 6616: inline long -: 6617: stol(const wstring& __str, size_t* __idx = 0, int __base = 10) -: 6618: { return __gnu_cxx::__stoa(&std::wcstol, "stol", __str.c_str(), -: 6619: __idx, __base); } -: 6620: -: 6621: inline unsigned long -: 6622: stoul(const wstring& __str, size_t* __idx = 0, int __base = 10) -: 6623: { return __gnu_cxx::__stoa(&std::wcstoul, "stoul", __str.c_str(), -: 6624: __idx, __base); } -: 6625: -: 6626: inline long long -: 6627: stoll(const wstring& __str, size_t* __idx = 0, int __base = 10) -: 6628: { return __gnu_cxx::__stoa(&std::wcstoll, "stoll", __str.c_str(), -: 6629: __idx, __base); } -: 6630: -: 6631: inline unsigned long long -: 6632: stoull(const wstring& __str, size_t* __idx = 0, int __base = 10) -: 6633: { return __gnu_cxx::__stoa(&std::wcstoull, "stoull", __str.c_str(), -: 6634: __idx, __base); } -: 6635: -: 6636: // NB: wcstof vs wcstod. -: 6637: inline float -: 6638: stof(const wstring& __str, size_t* __idx = 0) -: 6639: { return __gnu_cxx::__stoa(&std::wcstof, "stof", __str.c_str(), __idx); } -: 6640: -: 6641: inline double -: 6642: stod(const wstring& __str, size_t* __idx = 0) -: 6643: { return __gnu_cxx::__stoa(&std::wcstod, "stod", __str.c_str(), __idx); } -: 6644: -: 6645: inline long double -: 6646: stold(const wstring& __str, size_t* __idx = 0) -: 6647: { return __gnu_cxx::__stoa(&std::wcstold, "stold", __str.c_str(), __idx); } -: 6648: -: 6649:#ifndef _GLIBCXX_HAVE_BROKEN_VSWPRINTF -: 6650: // DR 1261. -: 6651: inline wstring -: 6652: to_wstring(int __val) -: 6653: { return __gnu_cxx::__to_xstring(&std::vswprintf, 4 * sizeof(int), -: 6654: L"%d", __val); } -: 6655: -: 6656: inline wstring -: 6657: to_wstring(unsigned __val) -: 6658: { return __gnu_cxx::__to_xstring(&std::vswprintf, -: 6659: 4 * sizeof(unsigned), -: 6660: L"%u", __val); } -: 6661: -: 6662: inline wstring -: 6663: to_wstring(long __val) -: 6664: { return __gnu_cxx::__to_xstring(&std::vswprintf, 4 * sizeof(long), -: 6665: L"%ld", __val); } -: 6666: -: 6667: inline wstring -: 6668: to_wstring(unsigned long __val) -: 6669: { return __gnu_cxx::__to_xstring(&std::vswprintf, -: 6670: 4 * sizeof(unsigned long), -: 6671: L"%lu", __val); } -: 6672: -: 6673: inline wstring -: 6674: to_wstring(long long __val) -: 6675: { return __gnu_cxx::__to_xstring(&std::vswprintf, -: 6676: 4 * sizeof(long long), -: 6677: L"%lld", __val); } -: 6678: -: 6679: inline wstring -: 6680: to_wstring(unsigned long long __val) -: 6681: { return __gnu_cxx::__to_xstring(&std::vswprintf, -: 6682: 4 * sizeof(unsigned long long), -: 6683: L"%llu", __val); } -: 6684: -: 6685: inline wstring -: 6686: to_wstring(float __val) -: 6687: { -: 6688: const int __n = -: 6689: __gnu_cxx::__numeric_traits::__max_exponent10 + 20; -: 6690: return __gnu_cxx::__to_xstring(&std::vswprintf, __n, -: 6691: L"%f", __val); -: 6692: } -: 6693: -: 6694: inline wstring -: 6695: to_wstring(double __val) -: 6696: { -: 6697: const int __n = -: 6698: __gnu_cxx::__numeric_traits::__max_exponent10 + 20; -: 6699: return __gnu_cxx::__to_xstring(&std::vswprintf, __n, -: 6700: L"%f", __val); -: 6701: } -: 6702: -: 6703: inline wstring -: 6704: to_wstring(long double __val) -: 6705: { -: 6706: const int __n = -: 6707: __gnu_cxx::__numeric_traits::__max_exponent10 + 20; -: 6708: return __gnu_cxx::__to_xstring(&std::vswprintf, __n, -: 6709: L"%Lf", __val); -: 6710: } -: 6711:#endif // _GLIBCXX_HAVE_BROKEN_VSWPRINTF -: 6712:#endif // _GLIBCXX_USE_WCHAR_T && _GLIBCXX_USE_C99_WCHAR -: 6713: -: 6714:_GLIBCXX_END_NAMESPACE_CXX11 -: 6715:_GLIBCXX_END_NAMESPACE_VERSION -: 6716:} // namespace -: 6717: -: 6718:#endif /* C++11 */ -: 6719: -: 6720:#if __cplusplus >= 201103L -: 6721: -: 6722:#include -: 6723: -: 6724:namespace std _GLIBCXX_VISIBILITY(default) -: 6725:{ -: 6726:_GLIBCXX_BEGIN_NAMESPACE_VERSION -: 6727: -: 6728: // DR 1182. -: 6729: -: 6730:#ifndef _GLIBCXX_COMPATIBILITY_CXX0X -: 6731: /// std::hash specialization for string. -: 6732: template<> -: 6733: struct hash -: 6734: : public __hash_base -: 6735: { -: 6736: size_t -: 6737: operator()(const string& __s) const noexcept -: 6738: { return std::_Hash_impl::hash(__s.data(), __s.length()); } -: 6739: }; -: 6740: -: 6741: template<> -: 6742: struct __is_fast_hash> : std::false_type -: 6743: { }; -: 6744: -: 6745:#ifdef _GLIBCXX_USE_WCHAR_T -: 6746: /// std::hash specialization for wstring. -: 6747: template<> -: 6748: struct hash -: 6749: : public __hash_base -: 6750: { -: 6751: size_t -: 6752: operator()(const wstring& __s) const noexcept -: 6753: { return std::_Hash_impl::hash(__s.data(), -: 6754: __s.length() * sizeof(wchar_t)); } -: 6755: }; -: 6756: -: 6757: template<> -: 6758: struct __is_fast_hash> : std::false_type -: 6759: { }; -: 6760:#endif -: 6761:#endif /* _GLIBCXX_COMPATIBILITY_CXX0X */ -: 6762: -: 6763:#ifdef _GLIBCXX_USE_CHAR8_T -: 6764: /// std::hash specialization for u8string. -: 6765: template<> -: 6766: struct hash -: 6767: : public __hash_base -: 6768: { -: 6769: size_t -: 6770: operator()(const u8string& __s) const noexcept -: 6771: { return std::_Hash_impl::hash(__s.data(), -: 6772: __s.length() * sizeof(char8_t)); } -: 6773: }; -: 6774: -: 6775: template<> -: 6776: struct __is_fast_hash> : std::false_type -: 6777: { }; -: 6778:#endif -: 6779: -: 6780: /// std::hash specialization for u16string. -: 6781: template<> -: 6782: struct hash -: 6783: : public __hash_base -: 6784: { -: 6785: size_t -: 6786: operator()(const u16string& __s) const noexcept -: 6787: { return std::_Hash_impl::hash(__s.data(), -: 6788: __s.length() * sizeof(char16_t)); } -: 6789: }; -: 6790: -: 6791: template<> -: 6792: struct __is_fast_hash> : std::false_type -: 6793: { }; -: 6794: -: 6795: /// std::hash specialization for u32string. -: 6796: template<> -: 6797: struct hash -: 6798: : public __hash_base -: 6799: { -: 6800: size_t -: 6801: operator()(const u32string& __s) const noexcept -: 6802: { return std::_Hash_impl::hash(__s.data(), -: 6803: __s.length() * sizeof(char32_t)); } -: 6804: }; -: 6805: -: 6806: template<> -: 6807: struct __is_fast_hash> : std::false_type -: 6808: { }; -: 6809: -: 6810:#if __cplusplus >= 201402L -: 6811: -: 6812:#define __cpp_lib_string_udls 201304 -: 6813: -: 6814: inline namespace literals -: 6815: { -: 6816: inline namespace string_literals -: 6817: { -: 6818:#pragma GCC diagnostic push -: 6819:#pragma GCC diagnostic ignored "-Wliteral-suffix" -: 6820: _GLIBCXX_DEFAULT_ABI_TAG -: 6821: inline basic_string -: 6822: operator""s(const char* __str, size_t __len) -: 6823: { return basic_string{__str, __len}; } -: 6824: -: 6825:#ifdef _GLIBCXX_USE_WCHAR_T -: 6826: _GLIBCXX_DEFAULT_ABI_TAG -: 6827: inline basic_string -: 6828: operator""s(const wchar_t* __str, size_t __len) -: 6829: { return basic_string{__str, __len}; } -: 6830:#endif -: 6831: -: 6832:#ifdef _GLIBCXX_USE_CHAR8_T -: 6833: _GLIBCXX_DEFAULT_ABI_TAG -: 6834: inline basic_string -: 6835: operator""s(const char8_t* __str, size_t __len) -: 6836: { return basic_string{__str, __len}; } -: 6837:#endif -: 6838: -: 6839: _GLIBCXX_DEFAULT_ABI_TAG -: 6840: inline basic_string -: 6841: operator""s(const char16_t* __str, size_t __len) -: 6842: { return basic_string{__str, __len}; } -: 6843: -: 6844: _GLIBCXX_DEFAULT_ABI_TAG -: 6845: inline basic_string -: 6846: operator""s(const char32_t* __str, size_t __len) -: 6847: { return basic_string{__str, __len}; } -: 6848: -: 6849:#pragma GCC diagnostic pop -: 6850: } // inline namespace string_literals -: 6851: } // inline namespace literals -: 6852: -: 6853:#if __cplusplus >= 201703L -: 6854: namespace __detail::__variant -: 6855: { -: 6856: template struct _Never_valueless_alt; // see -: 6857: -: 6858: // Provide the strong exception-safety guarantee when emplacing a -: 6859: // basic_string into a variant, but only if moving the string cannot throw. -: 6860: template -: 6861: struct _Never_valueless_alt> -: 6862: : __and_< -: 6863: is_nothrow_move_constructible>, -: 6864: is_nothrow_move_assignable> -: 6865: >::type -: 6866: { }; -: 6867: } // namespace __detail::__variant -: 6868:#endif // C++17 -: 6869:#endif // C++14 -: 6870: -: 6871:_GLIBCXX_END_NAMESPACE_VERSION -: 6872:} // namespace std -: 6873: -: 6874:#endif // C++11 -: 6875: -: 6876:#endif /* _BASIC_STRING_H */ <<<<<< EOF # path=tests/basic_string.tcc.gcov -: 0:Source:/usr/include/c++/9/bits/basic_string.tcc -: 0:Graph:log.gcno -: 0:Data:log.gcda -: 0:Runs:2 -: 1:// Components for manipulating sequences of characters -*- C++ -*- -: 2: -: 3:// Copyright (C) 1997-2019 Free Software Foundation, Inc. -: 4:// -: 5:// This file is part of the GNU ISO C++ Library. This library is free -: 6:// software; you can redistribute it and/or modify it under the -: 7:// terms of the GNU General Public License as published by the -: 8:// Free Software Foundation; either version 3, or (at your option) -: 9:// any later version. -: 10: -: 11:// This library is distributed in the hope that it will be useful, -: 12:// but WITHOUT ANY WARRANTY; without even the implied warranty of -: 13:// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -: 14:// GNU General Public License for more details. -: 15: -: 16:// Under Section 7 of GPL version 3, you are granted additional -: 17:// permissions described in the GCC Runtime Library Exception, version -: 18:// 3.1, as published by the Free Software Foundation. -: 19: -: 20:// You should have received a copy of the GNU General Public License and -: 21:// a copy of the GCC Runtime Library Exception along with this program; -: 22:// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see -: 23:// . -: 24: -: 25:/** @file bits/basic_string.tcc -: 26: * This is an internal header file, included by other library headers. -: 27: * Do not attempt to use it directly. @headername{string} -: 28: */ -: 29: -: 30:// -: 31:// ISO C++ 14882: 21 Strings library -: 32:// -: 33: -: 34:// Written by Jason Merrill based upon the specification by Takanori Adachi -: 35:// in ANSI X3J16/94-0013R2. Rewritten by Nathan Myers to ISO-14882. -: 36:// Non-reference-counted implementation written by Paolo Carlini and -: 37:// updated by Jonathan Wakely for ISO-14882-2011. -: 38: -: 39:#ifndef _BASIC_STRING_TCC -: 40:#define _BASIC_STRING_TCC 1 -: 41: -: 42:#pragma GCC system_header -: 43: -: 44:#include -: 45: -: 46:namespace std _GLIBCXX_VISIBILITY(default) -: 47:{ -: 48:_GLIBCXX_BEGIN_NAMESPACE_VERSION -: 49: -: 50:#if _GLIBCXX_USE_CXX11_ABI -: 51: -: 52: template -: 53: const typename basic_string<_CharT, _Traits, _Alloc>::size_type -: 54: basic_string<_CharT, _Traits, _Alloc>::npos; -: 55: -: 56: template -: 57: void -: 58: basic_string<_CharT, _Traits, _Alloc>:: -: 59: swap(basic_string& __s) _GLIBCXX_NOEXCEPT -: 60: { -: 61: if (this == &__s) -: 62: return; -: 63: -: 64: _Alloc_traits::_S_on_swap(_M_get_allocator(), __s._M_get_allocator()); -: 65: -: 66: if (_M_is_local()) -: 67: if (__s._M_is_local()) -: 68: { -: 69: if (length() && __s.length()) -: 70: { -: 71: _CharT __tmp_data[_S_local_capacity + 1]; -: 72: traits_type::copy(__tmp_data, __s._M_local_buf, -: 73: _S_local_capacity + 1); -: 74: traits_type::copy(__s._M_local_buf, _M_local_buf, -: 75: _S_local_capacity + 1); -: 76: traits_type::copy(_M_local_buf, __tmp_data, -: 77: _S_local_capacity + 1); -: 78: } -: 79: else if (__s.length()) -: 80: { -: 81: traits_type::copy(_M_local_buf, __s._M_local_buf, -: 82: _S_local_capacity + 1); -: 83: _M_length(__s.length()); -: 84: __s._M_set_length(0); -: 85: return; -: 86: } -: 87: else if (length()) -: 88: { -: 89: traits_type::copy(__s._M_local_buf, _M_local_buf, -: 90: _S_local_capacity + 1); -: 91: __s._M_length(length()); -: 92: _M_set_length(0); -: 93: return; -: 94: } -: 95: } -: 96: else -: 97: { -: 98: const size_type __tmp_capacity = __s._M_allocated_capacity; -: 99: traits_type::copy(__s._M_local_buf, _M_local_buf, -: 100: _S_local_capacity + 1); -: 101: _M_data(__s._M_data()); -: 102: __s._M_data(__s._M_local_buf); -: 103: _M_capacity(__tmp_capacity); -: 104: } -: 105: else -: 106: { -: 107: const size_type __tmp_capacity = _M_allocated_capacity; -: 108: if (__s._M_is_local()) -: 109: { -: 110: traits_type::copy(_M_local_buf, __s._M_local_buf, -: 111: _S_local_capacity + 1); -: 112: __s._M_data(_M_data()); -: 113: _M_data(_M_local_buf); -: 114: } -: 115: else -: 116: { -: 117: pointer __tmp_ptr = _M_data(); -: 118: _M_data(__s._M_data()); -: 119: __s._M_data(__tmp_ptr); -: 120: _M_capacity(__s._M_allocated_capacity); -: 121: } -: 122: __s._M_capacity(__tmp_capacity); -: 123: } -: 124: -: 125: const size_type __tmp_length = length(); -: 126: _M_length(__s.length()); -: 127: __s._M_length(__tmp_length); -: 128: } -: 129: -: 130: template -: 131: typename basic_string<_CharT, _Traits, _Alloc>::pointer -: 132: basic_string<_CharT, _Traits, _Alloc>:: -: 133: _M_create(size_type& __capacity, size_type __old_capacity) -: 134: { -: 135: // _GLIBCXX_RESOLVE_LIB_DEFECTS -: 136: // 83. String::npos vs. string::max_size() -: 137: if (__capacity > max_size()) -: 138: std::__throw_length_error(__N("basic_string::_M_create")); -: 139: -: 140: // The below implements an exponential growth policy, necessary to -: 141: // meet amortized linear time requirements of the library: see -: 142: // http://gcc.gnu.org/ml/libstdc++/2001-07/msg00085.html. -: 143: if (__capacity > __old_capacity && __capacity < 2 * __old_capacity) -: 144: { -: 145: __capacity = 2 * __old_capacity; -: 146: // Never allocate a string bigger than max_size. -: 147: if (__capacity > max_size()) -: 148: __capacity = max_size(); -: 149: } -: 150: -: 151: // NB: Need an array of char_type[__capacity], plus a terminating -: 152: // null char_type() element. -: 153: return _Alloc_traits::allocate(_M_get_allocator(), __capacity + 1); -: 154: } -: 155: -: 156: // NB: This is the special case for Input Iterators, used in -: 157: // istreambuf_iterators, etc. -: 158: // Input Iterators have a cost structure very different from -: 159: // pointers, calling for a different coding style. -: 160: template -: 161: template -: 162: void -: 163: basic_string<_CharT, _Traits, _Alloc>:: -: 164: _M_construct(_InIterator __beg, _InIterator __end, -: 165: std::input_iterator_tag) -: 166: { -: 167: size_type __len = 0; -: 168: size_type __capacity = size_type(_S_local_capacity); -: 169: -: 170: while (__beg != __end && __len < __capacity) -: 171: { -: 172: _M_data()[__len++] = *__beg; -: 173: ++__beg; -: 174: } -: 175: -: 176: __try -: 177: { -: 178: while (__beg != __end) -: 179: { -: 180: if (__len == __capacity) -: 181: { -: 182: // Allocate more space. -: 183: __capacity = __len + 1; -: 184: pointer __another = _M_create(__capacity, __len); -: 185: this->_S_copy(__another, _M_data(), __len); -: 186: _M_dispose(); -: 187: _M_data(__another); -: 188: _M_capacity(__capacity); -: 189: } -: 190: _M_data()[__len++] = *__beg; -: 191: ++__beg; -: 192: } -: 193: } -: 194: __catch(...) -: 195: { -: 196: _M_dispose(); -: 197: __throw_exception_again; -: 198: } -: 199: -: 200: _M_set_length(__len); -: 201: } -: 202: -: 203: template -: 204: template -: 205: void #####: 206: basic_string<_CharT, _Traits, _Alloc>:: -: 207: _M_construct(_InIterator __beg, _InIterator __end, -: 208: std::forward_iterator_tag) -: 209: { -: 210: // NB: Not required, but considered best practice. #####: 211: if (__gnu_cxx::__is_null_pointer(__beg) && __beg != __end) #####: 212: std::__throw_logic_error(__N("basic_string::" -: 213: "_M_construct null not valid")); -: 214: #####: 215: size_type __dnew = static_cast(std::distance(__beg, __end)); -: 216: #####: 217: if (__dnew > size_type(_S_local_capacity)) -: 218: { #####: 219: _M_data(_M_create(__dnew, size_type(0))); #####: 220: _M_capacity(__dnew); -: 221: } -: 222: -: 223: // Check for out_of_range and length_error exceptions. -: 224: __try #####: 225: { this->_S_copy_chars(_M_data(), __beg, __end); } =====: 226: __catch(...) -: 227: { =====: 228: _M_dispose(); =====: 229: __throw_exception_again; -: 230: } -: 231: #####: 232: _M_set_length(__dnew); #####: 233: } ------------------ _ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE12_M_constructIPcEEvT_S7_St20forward_iterator_tag: #####: 206: basic_string<_CharT, _Traits, _Alloc>:: -: 207: _M_construct(_InIterator __beg, _InIterator __end, -: 208: std::forward_iterator_tag) -: 209: { -: 210: // NB: Not required, but considered best practice. #####: 211: if (__gnu_cxx::__is_null_pointer(__beg) && __beg != __end) #####: 212: std::__throw_logic_error(__N("basic_string::" -: 213: "_M_construct null not valid")); -: 214: #####: 215: size_type __dnew = static_cast(std::distance(__beg, __end)); -: 216: #####: 217: if (__dnew > size_type(_S_local_capacity)) -: 218: { #####: 219: _M_data(_M_create(__dnew, size_type(0))); #####: 220: _M_capacity(__dnew); -: 221: } -: 222: -: 223: // Check for out_of_range and length_error exceptions. -: 224: __try #####: 225: { this->_S_copy_chars(_M_data(), __beg, __end); } =====: 226: __catch(...) -: 227: { =====: 228: _M_dispose(); =====: 229: __throw_exception_again; -: 230: } -: 231: #####: 232: _M_set_length(__dnew); #####: 233: } ------------------ _ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE12_M_constructIPKcEEvT_S8_St20forward_iterator_tag: #####: 206: basic_string<_CharT, _Traits, _Alloc>:: -: 207: _M_construct(_InIterator __beg, _InIterator __end, -: 208: std::forward_iterator_tag) -: 209: { -: 210: // NB: Not required, but considered best practice. #####: 211: if (__gnu_cxx::__is_null_pointer(__beg) && __beg != __end) #####: 212: std::__throw_logic_error(__N("basic_string::" -: 213: "_M_construct null not valid")); -: 214: #####: 215: size_type __dnew = static_cast(std::distance(__beg, __end)); -: 216: #####: 217: if (__dnew > size_type(_S_local_capacity)) -: 218: { #####: 219: _M_data(_M_create(__dnew, size_type(0))); #####: 220: _M_capacity(__dnew); -: 221: } -: 222: -: 223: // Check for out_of_range and length_error exceptions. -: 224: __try #####: 225: { this->_S_copy_chars(_M_data(), __beg, __end); } =====: 226: __catch(...) -: 227: { =====: 228: _M_dispose(); =====: 229: __throw_exception_again; -: 230: } -: 231: #####: 232: _M_set_length(__dnew); #####: 233: } ------------------ -: 234: -: 235: template -: 236: void -: 237: basic_string<_CharT, _Traits, _Alloc>:: -: 238: _M_construct(size_type __n, _CharT __c) -: 239: { -: 240: if (__n > size_type(_S_local_capacity)) -: 241: { -: 242: _M_data(_M_create(__n, size_type(0))); -: 243: _M_capacity(__n); -: 244: } -: 245: -: 246: if (__n) -: 247: this->_S_assign(_M_data(), __n, __c); -: 248: -: 249: _M_set_length(__n); -: 250: } -: 251: -: 252: template -: 253: void -: 254: basic_string<_CharT, _Traits, _Alloc>:: -: 255: _M_assign(const basic_string& __str) -: 256: { -: 257: if (this != &__str) -: 258: { -: 259: const size_type __rsize = __str.length(); -: 260: const size_type __capacity = capacity(); -: 261: -: 262: if (__rsize > __capacity) -: 263: { -: 264: size_type __new_capacity = __rsize; -: 265: pointer __tmp = _M_create(__new_capacity, __capacity); -: 266: _M_dispose(); -: 267: _M_data(__tmp); -: 268: _M_capacity(__new_capacity); -: 269: } -: 270: -: 271: if (__rsize) -: 272: this->_S_copy(_M_data(), __str._M_data(), __rsize); -: 273: -: 274: _M_set_length(__rsize); -: 275: } -: 276: } -: 277: -: 278: template -: 279: void -: 280: basic_string<_CharT, _Traits, _Alloc>:: -: 281: reserve(size_type __res) -: 282: { -: 283: // Make sure we don't shrink below the current size. -: 284: if (__res < length()) -: 285: __res = length(); -: 286: -: 287: const size_type __capacity = capacity(); -: 288: if (__res != __capacity) -: 289: { -: 290: if (__res > __capacity -: 291: || __res > size_type(_S_local_capacity)) -: 292: { -: 293: pointer __tmp = _M_create(__res, __capacity); -: 294: this->_S_copy(__tmp, _M_data(), length() + 1); -: 295: _M_dispose(); -: 296: _M_data(__tmp); -: 297: _M_capacity(__res); -: 298: } -: 299: else if (!_M_is_local()) -: 300: { -: 301: this->_S_copy(_M_local_data(), _M_data(), length() + 1); -: 302: _M_destroy(__capacity); -: 303: _M_data(_M_local_data()); -: 304: } -: 305: } -: 306: } -: 307: -: 308: template -: 309: void -: 310: basic_string<_CharT, _Traits, _Alloc>:: -: 311: _M_mutate(size_type __pos, size_type __len1, const _CharT* __s, -: 312: size_type __len2) -: 313: { -: 314: const size_type __how_much = length() - __pos - __len1; -: 315: -: 316: size_type __new_capacity = length() + __len2 - __len1; -: 317: pointer __r = _M_create(__new_capacity, capacity()); -: 318: -: 319: if (__pos) -: 320: this->_S_copy(__r, _M_data(), __pos); -: 321: if (__s && __len2) -: 322: this->_S_copy(__r + __pos, __s, __len2); -: 323: if (__how_much) -: 324: this->_S_copy(__r + __pos + __len2, -: 325: _M_data() + __pos + __len1, __how_much); -: 326: -: 327: _M_dispose(); -: 328: _M_data(__r); -: 329: _M_capacity(__new_capacity); -: 330: } -: 331: -: 332: template -: 333: void -: 334: basic_string<_CharT, _Traits, _Alloc>:: -: 335: _M_erase(size_type __pos, size_type __n) -: 336: { -: 337: const size_type __how_much = length() - __pos - __n; -: 338: -: 339: if (__how_much && __n) -: 340: this->_S_move(_M_data() + __pos, _M_data() + __pos + __n, __how_much); -: 341: -: 342: _M_set_length(length() - __n); -: 343: } -: 344: -: 345: template -: 346: void -: 347: basic_string<_CharT, _Traits, _Alloc>:: -: 348: resize(size_type __n, _CharT __c) -: 349: { -: 350: const size_type __size = this->size(); -: 351: if (__size < __n) -: 352: this->append(__n - __size, __c); -: 353: else if (__n < __size) -: 354: this->_M_set_length(__n); -: 355: } -: 356: -: 357: template -: 358: basic_string<_CharT, _Traits, _Alloc>& -: 359: basic_string<_CharT, _Traits, _Alloc>:: -: 360: _M_append(const _CharT* __s, size_type __n) -: 361: { -: 362: const size_type __len = __n + this->size(); -: 363: -: 364: if (__len <= this->capacity()) -: 365: { -: 366: if (__n) -: 367: this->_S_copy(this->_M_data() + this->size(), __s, __n); -: 368: } -: 369: else -: 370: this->_M_mutate(this->size(), size_type(0), __s, __n); -: 371: -: 372: this->_M_set_length(__len); -: 373: return *this; -: 374: } -: 375: -: 376: template -: 377: template -: 378: basic_string<_CharT, _Traits, _Alloc>& -: 379: basic_string<_CharT, _Traits, _Alloc>:: -: 380: _M_replace_dispatch(const_iterator __i1, const_iterator __i2, -: 381: _InputIterator __k1, _InputIterator __k2, -: 382: std::__false_type) -: 383: { -: 384: const basic_string __s(__k1, __k2); -: 385: const size_type __n1 = __i2 - __i1; -: 386: return _M_replace(__i1 - begin(), __n1, __s._M_data(), -: 387: __s.size()); -: 388: } -: 389: -: 390: template -: 391: basic_string<_CharT, _Traits, _Alloc>& -: 392: basic_string<_CharT, _Traits, _Alloc>:: -: 393: _M_replace_aux(size_type __pos1, size_type __n1, size_type __n2, -: 394: _CharT __c) -: 395: { -: 396: _M_check_length(__n1, __n2, "basic_string::_M_replace_aux"); -: 397: -: 398: const size_type __old_size = this->size(); -: 399: const size_type __new_size = __old_size + __n2 - __n1; -: 400: -: 401: if (__new_size <= this->capacity()) -: 402: { -: 403: pointer __p = this->_M_data() + __pos1; -: 404: -: 405: const size_type __how_much = __old_size - __pos1 - __n1; -: 406: if (__how_much && __n1 != __n2) -: 407: this->_S_move(__p + __n2, __p + __n1, __how_much); -: 408: } -: 409: else -: 410: this->_M_mutate(__pos1, __n1, 0, __n2); -: 411: -: 412: if (__n2) -: 413: this->_S_assign(this->_M_data() + __pos1, __n2, __c); -: 414: -: 415: this->_M_set_length(__new_size); -: 416: return *this; -: 417: } -: 418: -: 419: template -: 420: basic_string<_CharT, _Traits, _Alloc>& -: 421: basic_string<_CharT, _Traits, _Alloc>:: -: 422: _M_replace(size_type __pos, size_type __len1, const _CharT* __s, -: 423: const size_type __len2) -: 424: { -: 425: _M_check_length(__len1, __len2, "basic_string::_M_replace"); -: 426: -: 427: const size_type __old_size = this->size(); -: 428: const size_type __new_size = __old_size + __len2 - __len1; -: 429: -: 430: if (__new_size <= this->capacity()) -: 431: { -: 432: pointer __p = this->_M_data() + __pos; -: 433: -: 434: const size_type __how_much = __old_size - __pos - __len1; -: 435: if (_M_disjunct(__s)) -: 436: { -: 437: if (__how_much && __len1 != __len2) -: 438: this->_S_move(__p + __len2, __p + __len1, __how_much); -: 439: if (__len2) -: 440: this->_S_copy(__p, __s, __len2); -: 441: } -: 442: else -: 443: { -: 444: // Work in-place. -: 445: if (__len2 && __len2 <= __len1) -: 446: this->_S_move(__p, __s, __len2); -: 447: if (__how_much && __len1 != __len2) -: 448: this->_S_move(__p + __len2, __p + __len1, __how_much); -: 449: if (__len2 > __len1) -: 450: { -: 451: if (__s + __len2 <= __p + __len1) -: 452: this->_S_move(__p, __s, __len2); -: 453: else if (__s >= __p + __len1) -: 454: this->_S_copy(__p, __s + __len2 - __len1, __len2); -: 455: else -: 456: { -: 457: const size_type __nleft = (__p + __len1) - __s; -: 458: this->_S_move(__p, __s, __nleft); -: 459: this->_S_copy(__p + __nleft, __p + __len2, -: 460: __len2 - __nleft); -: 461: } -: 462: } -: 463: } -: 464: } -: 465: else -: 466: this->_M_mutate(__pos, __len1, __s, __len2); -: 467: -: 468: this->_M_set_length(__new_size); -: 469: return *this; -: 470: } -: 471: -: 472: template -: 473: typename basic_string<_CharT, _Traits, _Alloc>::size_type -: 474: basic_string<_CharT, _Traits, _Alloc>:: -: 475: copy(_CharT* __s, size_type __n, size_type __pos) const -: 476: { -: 477: _M_check(__pos, "basic_string::copy"); -: 478: __n = _M_limit(__pos, __n); -: 479: __glibcxx_requires_string_len(__s, __n); -: 480: if (__n) -: 481: _S_copy(__s, _M_data() + __pos, __n); -: 482: // 21.3.5.7 par 3: do not append null. (good.) -: 483: return __n; -: 484: } -: 485: -: 486:#else // !_GLIBCXX_USE_CXX11_ABI -: 487: -: 488: template -: 489: const typename basic_string<_CharT, _Traits, _Alloc>::size_type -: 490: basic_string<_CharT, _Traits, _Alloc>:: -: 491: _Rep::_S_max_size = (((npos - sizeof(_Rep_base))/sizeof(_CharT)) - 1) / 4; -: 492: -: 493: template -: 494: const _CharT -: 495: basic_string<_CharT, _Traits, _Alloc>:: -: 496: _Rep::_S_terminal = _CharT(); -: 497: -: 498: template -: 499: const typename basic_string<_CharT, _Traits, _Alloc>::size_type -: 500: basic_string<_CharT, _Traits, _Alloc>::npos; -: 501: -: 502: // Linker sets _S_empty_rep_storage to all 0s (one reference, empty string) -: 503: // at static init time (before static ctors are run). -: 504: template -: 505: typename basic_string<_CharT, _Traits, _Alloc>::size_type -: 506: basic_string<_CharT, _Traits, _Alloc>::_Rep::_S_empty_rep_storage[ -: 507: (sizeof(_Rep_base) + sizeof(_CharT) + sizeof(size_type) - 1) / -: 508: sizeof(size_type)]; -: 509: -: 510: // NB: This is the special case for Input Iterators, used in -: 511: // istreambuf_iterators, etc. -: 512: // Input Iterators have a cost structure very different from -: 513: // pointers, calling for a different coding style. -: 514: template -: 515: template -: 516: _CharT* -: 517: basic_string<_CharT, _Traits, _Alloc>:: -: 518: _S_construct(_InIterator __beg, _InIterator __end, const _Alloc& __a, -: 519: input_iterator_tag) -: 520: { -: 521:#if _GLIBCXX_FULLY_DYNAMIC_STRING == 0 -: 522: if (__beg == __end && __a == _Alloc()) -: 523: return _S_empty_rep()._M_refdata(); -: 524:#endif -: 525: // Avoid reallocation for common case. -: 526: _CharT __buf[128]; -: 527: size_type __len = 0; -: 528: while (__beg != __end && __len < sizeof(__buf) / sizeof(_CharT)) -: 529: { -: 530: __buf[__len++] = *__beg; -: 531: ++__beg; -: 532: } -: 533: _Rep* __r = _Rep::_S_create(__len, size_type(0), __a); -: 534: _M_copy(__r->_M_refdata(), __buf, __len); -: 535: __try -: 536: { -: 537: while (__beg != __end) -: 538: { -: 539: if (__len == __r->_M_capacity) -: 540: { -: 541: // Allocate more space. -: 542: _Rep* __another = _Rep::_S_create(__len + 1, __len, __a); -: 543: _M_copy(__another->_M_refdata(), __r->_M_refdata(), __len); -: 544: __r->_M_destroy(__a); -: 545: __r = __another; -: 546: } -: 547: __r->_M_refdata()[__len++] = *__beg; -: 548: ++__beg; -: 549: } -: 550: } -: 551: __catch(...) -: 552: { -: 553: __r->_M_destroy(__a); -: 554: __throw_exception_again; -: 555: } -: 556: __r->_M_set_length_and_sharable(__len); -: 557: return __r->_M_refdata(); -: 558: } -: 559: -: 560: template -: 561: template -: 562: _CharT* -: 563: basic_string<_CharT, _Traits, _Alloc>:: -: 564: _S_construct(_InIterator __beg, _InIterator __end, const _Alloc& __a, -: 565: forward_iterator_tag) -: 566: { -: 567:#if _GLIBCXX_FULLY_DYNAMIC_STRING == 0 -: 568: if (__beg == __end && __a == _Alloc()) -: 569: return _S_empty_rep()._M_refdata(); -: 570:#endif -: 571: // NB: Not required, but considered best practice. -: 572: if (__gnu_cxx::__is_null_pointer(__beg) && __beg != __end) -: 573: __throw_logic_error(__N("basic_string::_S_construct null not valid")); -: 574: -: 575: const size_type __dnew = static_cast(std::distance(__beg, -: 576: __end)); -: 577: // Check for out_of_range and length_error exceptions. -: 578: _Rep* __r = _Rep::_S_create(__dnew, size_type(0), __a); -: 579: __try -: 580: { _S_copy_chars(__r->_M_refdata(), __beg, __end); } -: 581: __catch(...) -: 582: { -: 583: __r->_M_destroy(__a); -: 584: __throw_exception_again; -: 585: } -: 586: __r->_M_set_length_and_sharable(__dnew); -: 587: return __r->_M_refdata(); -: 588: } -: 589: -: 590: template -: 591: _CharT* -: 592: basic_string<_CharT, _Traits, _Alloc>:: -: 593: _S_construct(size_type __n, _CharT __c, const _Alloc& __a) -: 594: { -: 595:#if _GLIBCXX_FULLY_DYNAMIC_STRING == 0 -: 596: if (__n == 0 && __a == _Alloc()) -: 597: return _S_empty_rep()._M_refdata(); -: 598:#endif -: 599: // Check for out_of_range and length_error exceptions. -: 600: _Rep* __r = _Rep::_S_create(__n, size_type(0), __a); -: 601: if (__n) -: 602: _M_assign(__r->_M_refdata(), __n, __c); -: 603: -: 604: __r->_M_set_length_and_sharable(__n); -: 605: return __r->_M_refdata(); -: 606: } -: 607: -: 608: template -: 609: basic_string<_CharT, _Traits, _Alloc>:: -: 610: basic_string(const basic_string& __str) -: 611: : _M_dataplus(__str._M_rep()->_M_grab(_Alloc(__str.get_allocator()), -: 612: __str.get_allocator()), -: 613: __str.get_allocator()) -: 614: { } -: 615: -: 616: template -: 617: basic_string<_CharT, _Traits, _Alloc>:: -: 618: basic_string(const _Alloc& __a) -: 619: : _M_dataplus(_S_construct(size_type(), _CharT(), __a), __a) -: 620: { } -: 621: -: 622: template -: 623: basic_string<_CharT, _Traits, _Alloc>:: -: 624: basic_string(const basic_string& __str, size_type __pos, const _Alloc& __a) -: 625: : _M_dataplus(_S_construct(__str._M_data() -: 626: + __str._M_check(__pos, -: 627: "basic_string::basic_string"), -: 628: __str._M_data() + __str._M_limit(__pos, npos) -: 629: + __pos, __a), __a) -: 630: { } -: 631: -: 632: template -: 633: basic_string<_CharT, _Traits, _Alloc>:: -: 634: basic_string(const basic_string& __str, size_type __pos, size_type __n) -: 635: : _M_dataplus(_S_construct(__str._M_data() -: 636: + __str._M_check(__pos, -: 637: "basic_string::basic_string"), -: 638: __str._M_data() + __str._M_limit(__pos, __n) -: 639: + __pos, _Alloc()), _Alloc()) -: 640: { } -: 641: -: 642: template -: 643: basic_string<_CharT, _Traits, _Alloc>:: -: 644: basic_string(const basic_string& __str, size_type __pos, -: 645: size_type __n, const _Alloc& __a) -: 646: : _M_dataplus(_S_construct(__str._M_data() -: 647: + __str._M_check(__pos, -: 648: "basic_string::basic_string"), -: 649: __str._M_data() + __str._M_limit(__pos, __n) -: 650: + __pos, __a), __a) -: 651: { } -: 652: -: 653: // TBD: DPG annotate -: 654: template -: 655: basic_string<_CharT, _Traits, _Alloc>:: -: 656: basic_string(const _CharT* __s, size_type __n, const _Alloc& __a) -: 657: : _M_dataplus(_S_construct(__s, __s + __n, __a), __a) -: 658: { } -: 659: -: 660: // TBD: DPG annotate -: 661: template -: 662: basic_string<_CharT, _Traits, _Alloc>:: -: 663: basic_string(const _CharT* __s, const _Alloc& __a) -: 664: : _M_dataplus(_S_construct(__s, __s ? __s + traits_type::length(__s) : -: 665: __s + npos, __a), __a) -: 666: { } -: 667: -: 668: template -: 669: basic_string<_CharT, _Traits, _Alloc>:: -: 670: basic_string(size_type __n, _CharT __c, const _Alloc& __a) -: 671: : _M_dataplus(_S_construct(__n, __c, __a), __a) -: 672: { } -: 673: -: 674: // TBD: DPG annotate -: 675: template -: 676: template -: 677: basic_string<_CharT, _Traits, _Alloc>:: -: 678: basic_string(_InputIterator __beg, _InputIterator __end, const _Alloc& __a) -: 679: : _M_dataplus(_S_construct(__beg, __end, __a), __a) -: 680: { } -: 681: -: 682:#if __cplusplus >= 201103L -: 683: template -: 684: basic_string<_CharT, _Traits, _Alloc>:: -: 685: basic_string(initializer_list<_CharT> __l, const _Alloc& __a) -: 686: : _M_dataplus(_S_construct(__l.begin(), __l.end(), __a), __a) -: 687: { } -: 688:#endif -: 689: -: 690: template -: 691: basic_string<_CharT, _Traits, _Alloc>& -: 692: basic_string<_CharT, _Traits, _Alloc>:: -: 693: assign(const basic_string& __str) -: 694: { -: 695: if (_M_rep() != __str._M_rep()) -: 696: { -: 697: // XXX MT -: 698: const allocator_type __a = this->get_allocator(); -: 699: _CharT* __tmp = __str._M_rep()->_M_grab(__a, __str.get_allocator()); -: 700: _M_rep()->_M_dispose(__a); -: 701: _M_data(__tmp); -: 702: } -: 703: return *this; -: 704: } -: 705: -: 706: template -: 707: basic_string<_CharT, _Traits, _Alloc>& -: 708: basic_string<_CharT, _Traits, _Alloc>:: -: 709: assign(const _CharT* __s, size_type __n) -: 710: { -: 711: __glibcxx_requires_string_len(__s, __n); -: 712: _M_check_length(this->size(), __n, "basic_string::assign"); -: 713: if (_M_disjunct(__s) || _M_rep()->_M_is_shared()) -: 714: return _M_replace_safe(size_type(0), this->size(), __s, __n); -: 715: else -: 716: { -: 717: // Work in-place. -: 718: const size_type __pos = __s - _M_data(); -: 719: if (__pos >= __n) -: 720: _M_copy(_M_data(), __s, __n); -: 721: else if (__pos) -: 722: _M_move(_M_data(), __s, __n); -: 723: _M_rep()->_M_set_length_and_sharable(__n); -: 724: return *this; -: 725: } -: 726: } -: 727: -: 728: template -: 729: basic_string<_CharT, _Traits, _Alloc>& -: 730: basic_string<_CharT, _Traits, _Alloc>:: -: 731: append(size_type __n, _CharT __c) -: 732: { -: 733: if (__n) -: 734: { -: 735: _M_check_length(size_type(0), __n, "basic_string::append"); -: 736: const size_type __len = __n + this->size(); -: 737: if (__len > this->capacity() || _M_rep()->_M_is_shared()) -: 738: this->reserve(__len); -: 739: _M_assign(_M_data() + this->size(), __n, __c); -: 740: _M_rep()->_M_set_length_and_sharable(__len); -: 741: } -: 742: return *this; -: 743: } -: 744: -: 745: template -: 746: basic_string<_CharT, _Traits, _Alloc>& -: 747: basic_string<_CharT, _Traits, _Alloc>:: -: 748: append(const _CharT* __s, size_type __n) -: 749: { -: 750: __glibcxx_requires_string_len(__s, __n); -: 751: if (__n) -: 752: { -: 753: _M_check_length(size_type(0), __n, "basic_string::append"); -: 754: const size_type __len = __n + this->size(); -: 755: if (__len > this->capacity() || _M_rep()->_M_is_shared()) -: 756: { -: 757: if (_M_disjunct(__s)) -: 758: this->reserve(__len); -: 759: else -: 760: { -: 761: const size_type __off = __s - _M_data(); -: 762: this->reserve(__len); -: 763: __s = _M_data() + __off; -: 764: } -: 765: } -: 766: _M_copy(_M_data() + this->size(), __s, __n); -: 767: _M_rep()->_M_set_length_and_sharable(__len); -: 768: } -: 769: return *this; -: 770: } -: 771: -: 772: template -: 773: basic_string<_CharT, _Traits, _Alloc>& -: 774: basic_string<_CharT, _Traits, _Alloc>:: -: 775: append(const basic_string& __str) -: 776: { -: 777: const size_type __size = __str.size(); -: 778: if (__size) -: 779: { -: 780: const size_type __len = __size + this->size(); -: 781: if (__len > this->capacity() || _M_rep()->_M_is_shared()) -: 782: this->reserve(__len); -: 783: _M_copy(_M_data() + this->size(), __str._M_data(), __size); -: 784: _M_rep()->_M_set_length_and_sharable(__len); -: 785: } -: 786: return *this; -: 787: } -: 788: -: 789: template -: 790: basic_string<_CharT, _Traits, _Alloc>& -: 791: basic_string<_CharT, _Traits, _Alloc>:: -: 792: append(const basic_string& __str, size_type __pos, size_type __n) -: 793: { -: 794: __str._M_check(__pos, "basic_string::append"); -: 795: __n = __str._M_limit(__pos, __n); -: 796: if (__n) -: 797: { -: 798: const size_type __len = __n + this->size(); -: 799: if (__len > this->capacity() || _M_rep()->_M_is_shared()) -: 800: this->reserve(__len); -: 801: _M_copy(_M_data() + this->size(), __str._M_data() + __pos, __n); -: 802: _M_rep()->_M_set_length_and_sharable(__len); -: 803: } -: 804: return *this; -: 805: } -: 806: -: 807: template -: 808: basic_string<_CharT, _Traits, _Alloc>& -: 809: basic_string<_CharT, _Traits, _Alloc>:: -: 810: insert(size_type __pos, const _CharT* __s, size_type __n) -: 811: { -: 812: __glibcxx_requires_string_len(__s, __n); -: 813: _M_check(__pos, "basic_string::insert"); -: 814: _M_check_length(size_type(0), __n, "basic_string::insert"); -: 815: if (_M_disjunct(__s) || _M_rep()->_M_is_shared()) -: 816: return _M_replace_safe(__pos, size_type(0), __s, __n); -: 817: else -: 818: { -: 819: // Work in-place. -: 820: const size_type __off = __s - _M_data(); -: 821: _M_mutate(__pos, 0, __n); -: 822: __s = _M_data() + __off; -: 823: _CharT* __p = _M_data() + __pos; -: 824: if (__s + __n <= __p) -: 825: _M_copy(__p, __s, __n); -: 826: else if (__s >= __p) -: 827: _M_copy(__p, __s + __n, __n); -: 828: else -: 829: { -: 830: const size_type __nleft = __p - __s; -: 831: _M_copy(__p, __s, __nleft); -: 832: _M_copy(__p + __nleft, __p + __n, __n - __nleft); -: 833: } -: 834: return *this; -: 835: } -: 836: } -: 837: -: 838: template -: 839: typename basic_string<_CharT, _Traits, _Alloc>::iterator -: 840: basic_string<_CharT, _Traits, _Alloc>:: -: 841: erase(iterator __first, iterator __last) -: 842: { -: 843: _GLIBCXX_DEBUG_PEDASSERT(__first >= _M_ibegin() && __first <= __last -: 844: && __last <= _M_iend()); -: 845: -: 846: // NB: This isn't just an optimization (bail out early when -: 847: // there is nothing to do, really), it's also a correctness -: 848: // issue vs MT, see libstdc++/40518. -: 849: const size_type __size = __last - __first; -: 850: if (__size) -: 851: { -: 852: const size_type __pos = __first - _M_ibegin(); -: 853: _M_mutate(__pos, __size, size_type(0)); -: 854: _M_rep()->_M_set_leaked(); -: 855: return iterator(_M_data() + __pos); -: 856: } -: 857: else -: 858: return __first; -: 859: } -: 860: -: 861: template -: 862: basic_string<_CharT, _Traits, _Alloc>& -: 863: basic_string<_CharT, _Traits, _Alloc>:: -: 864: replace(size_type __pos, size_type __n1, const _CharT* __s, -: 865: size_type __n2) -: 866: { -: 867: __glibcxx_requires_string_len(__s, __n2); -: 868: _M_check(__pos, "basic_string::replace"); -: 869: __n1 = _M_limit(__pos, __n1); -: 870: _M_check_length(__n1, __n2, "basic_string::replace"); -: 871: bool __left; -: 872: if (_M_disjunct(__s) || _M_rep()->_M_is_shared()) -: 873: return _M_replace_safe(__pos, __n1, __s, __n2); -: 874: else if ((__left = __s + __n2 <= _M_data() + __pos) -: 875: || _M_data() + __pos + __n1 <= __s) -: 876: { -: 877: // Work in-place: non-overlapping case. -: 878: size_type __off = __s - _M_data(); -: 879: __left ? __off : (__off += __n2 - __n1); -: 880: _M_mutate(__pos, __n1, __n2); -: 881: _M_copy(_M_data() + __pos, _M_data() + __off, __n2); -: 882: return *this; -: 883: } -: 884: else -: 885: { -: 886: // Todo: overlapping case. -: 887: const basic_string __tmp(__s, __n2); -: 888: return _M_replace_safe(__pos, __n1, __tmp._M_data(), __n2); -: 889: } -: 890: } -: 891: -: 892: template -: 893: void -: 894: basic_string<_CharT, _Traits, _Alloc>::_Rep:: -: 895: _M_destroy(const _Alloc& __a) throw () -: 896: { -: 897: const size_type __size = sizeof(_Rep_base) + -: 898: (this->_M_capacity + 1) * sizeof(_CharT); -: 899: _Raw_bytes_alloc(__a).deallocate(reinterpret_cast(this), __size); -: 900: } -: 901: -: 902: template -: 903: void -: 904: basic_string<_CharT, _Traits, _Alloc>:: -: 905: _M_leak_hard() -: 906: { -: 907:#if _GLIBCXX_FULLY_DYNAMIC_STRING == 0 -: 908: if (_M_rep() == &_S_empty_rep()) -: 909: return; -: 910:#endif -: 911: if (_M_rep()->_M_is_shared()) -: 912: _M_mutate(0, 0, 0); -: 913: _M_rep()->_M_set_leaked(); -: 914: } -: 915: -: 916: template -: 917: void -: 918: basic_string<_CharT, _Traits, _Alloc>:: -: 919: _M_mutate(size_type __pos, size_type __len1, size_type __len2) -: 920: { -: 921: const size_type __old_size = this->size(); -: 922: const size_type __new_size = __old_size + __len2 - __len1; -: 923: const size_type __how_much = __old_size - __pos - __len1; -: 924: -: 925: if (__new_size > this->capacity() || _M_rep()->_M_is_shared()) -: 926: { -: 927: // Must reallocate. -: 928: const allocator_type __a = get_allocator(); -: 929: _Rep* __r = _Rep::_S_create(__new_size, this->capacity(), __a); -: 930: -: 931: if (__pos) -: 932: _M_copy(__r->_M_refdata(), _M_data(), __pos); -: 933: if (__how_much) -: 934: _M_copy(__r->_M_refdata() + __pos + __len2, -: 935: _M_data() + __pos + __len1, __how_much); -: 936: -: 937: _M_rep()->_M_dispose(__a); -: 938: _M_data(__r->_M_refdata()); -: 939: } -: 940: else if (__how_much && __len1 != __len2) -: 941: { -: 942: // Work in-place. -: 943: _M_move(_M_data() + __pos + __len2, -: 944: _M_data() + __pos + __len1, __how_much); -: 945: } -: 946: _M_rep()->_M_set_length_and_sharable(__new_size); -: 947: } -: 948: -: 949: template -: 950: void -: 951: basic_string<_CharT, _Traits, _Alloc>:: -: 952: reserve(size_type __res) -: 953: { -: 954: if (__res != this->capacity() || _M_rep()->_M_is_shared()) -: 955: { -: 956: // Make sure we don't shrink below the current size -: 957: if (__res < this->size()) -: 958: __res = this->size(); -: 959: const allocator_type __a = get_allocator(); -: 960: _CharT* __tmp = _M_rep()->_M_clone(__a, __res - this->size()); -: 961: _M_rep()->_M_dispose(__a); -: 962: _M_data(__tmp); -: 963: } -: 964: } -: 965: -: 966: template -: 967: void -: 968: basic_string<_CharT, _Traits, _Alloc>:: -: 969: swap(basic_string& __s) -: 970: _GLIBCXX_NOEXCEPT_IF(allocator_traits<_Alloc>::is_always_equal::value) -: 971: { -: 972: if (_M_rep()->_M_is_leaked()) -: 973: _M_rep()->_M_set_sharable(); -: 974: if (__s._M_rep()->_M_is_leaked()) -: 975: __s._M_rep()->_M_set_sharable(); -: 976: if (this->get_allocator() == __s.get_allocator()) -: 977: { -: 978: _CharT* __tmp = _M_data(); -: 979: _M_data(__s._M_data()); -: 980: __s._M_data(__tmp); -: 981: } -: 982: // The code below can usually be optimized away. -: 983: else -: 984: { -: 985: const basic_string __tmp1(_M_ibegin(), _M_iend(), -: 986: __s.get_allocator()); -: 987: const basic_string __tmp2(__s._M_ibegin(), __s._M_iend(), -: 988: this->get_allocator()); -: 989: *this = __tmp2; -: 990: __s = __tmp1; -: 991: } -: 992: } -: 993: -: 994: template -: 995: typename basic_string<_CharT, _Traits, _Alloc>::_Rep* -: 996: basic_string<_CharT, _Traits, _Alloc>::_Rep:: -: 997: _S_create(size_type __capacity, size_type __old_capacity, -: 998: const _Alloc& __alloc) -: 999: { -: 1000: // _GLIBCXX_RESOLVE_LIB_DEFECTS -: 1001: // 83. String::npos vs. string::max_size() -: 1002: if (__capacity > _S_max_size) -: 1003: __throw_length_error(__N("basic_string::_S_create")); -: 1004: -: 1005: // The standard places no restriction on allocating more memory -: 1006: // than is strictly needed within this layer at the moment or as -: 1007: // requested by an explicit application call to reserve(). -: 1008: -: 1009: // Many malloc implementations perform quite poorly when an -: 1010: // application attempts to allocate memory in a stepwise fashion -: 1011: // growing each allocation size by only 1 char. Additionally, -: 1012: // it makes little sense to allocate less linear memory than the -: 1013: // natural blocking size of the malloc implementation. -: 1014: // Unfortunately, we would need a somewhat low-level calculation -: 1015: // with tuned parameters to get this perfect for any particular -: 1016: // malloc implementation. Fortunately, generalizations about -: 1017: // common features seen among implementations seems to suffice. -: 1018: -: 1019: // __pagesize need not match the actual VM page size for good -: 1020: // results in practice, thus we pick a common value on the low -: 1021: // side. __malloc_header_size is an estimate of the amount of -: 1022: // overhead per memory allocation (in practice seen N * sizeof -: 1023: // (void*) where N is 0, 2 or 4). According to folklore, -: 1024: // picking this value on the high side is better than -: 1025: // low-balling it (especially when this algorithm is used with -: 1026: // malloc implementations that allocate memory blocks rounded up -: 1027: // to a size which is a power of 2). -: 1028: const size_type __pagesize = 4096; -: 1029: const size_type __malloc_header_size = 4 * sizeof(void*); -: 1030: -: 1031: // The below implements an exponential growth policy, necessary to -: 1032: // meet amortized linear time requirements of the library: see -: 1033: // http://gcc.gnu.org/ml/libstdc++/2001-07/msg00085.html. -: 1034: // It's active for allocations requiring an amount of memory above -: 1035: // system pagesize. This is consistent with the requirements of the -: 1036: // standard: http://gcc.gnu.org/ml/libstdc++/2001-07/msg00130.html -: 1037: if (__capacity > __old_capacity && __capacity < 2 * __old_capacity) -: 1038: __capacity = 2 * __old_capacity; -: 1039: -: 1040: // NB: Need an array of char_type[__capacity], plus a terminating -: 1041: // null char_type() element, plus enough for the _Rep data structure. -: 1042: // Whew. Seemingly so needy, yet so elemental. -: 1043: size_type __size = (__capacity + 1) * sizeof(_CharT) + sizeof(_Rep); -: 1044: -: 1045: const size_type __adj_size = __size + __malloc_header_size; -: 1046: if (__adj_size > __pagesize && __capacity > __old_capacity) -: 1047: { -: 1048: const size_type __extra = __pagesize - __adj_size % __pagesize; -: 1049: __capacity += __extra / sizeof(_CharT); -: 1050: // Never allocate a string bigger than _S_max_size. -: 1051: if (__capacity > _S_max_size) -: 1052: __capacity = _S_max_size; -: 1053: __size = (__capacity + 1) * sizeof(_CharT) + sizeof(_Rep); -: 1054: } -: 1055: -: 1056: // NB: Might throw, but no worries about a leak, mate: _Rep() -: 1057: // does not throw. -: 1058: void* __place = _Raw_bytes_alloc(__alloc).allocate(__size); -: 1059: _Rep *__p = new (__place) _Rep; -: 1060: __p->_M_capacity = __capacity; -: 1061: // ABI compatibility - 3.4.x set in _S_create both -: 1062: // _M_refcount and _M_length. All callers of _S_create -: 1063: // in basic_string.tcc then set just _M_length. -: 1064: // In 4.0.x and later both _M_refcount and _M_length -: 1065: // are initialized in the callers, unfortunately we can -: 1066: // have 3.4.x compiled code with _S_create callers inlined -: 1067: // calling 4.0.x+ _S_create. -: 1068: __p->_M_set_sharable(); -: 1069: return __p; -: 1070: } -: 1071: -: 1072: template -: 1073: _CharT* -: 1074: basic_string<_CharT, _Traits, _Alloc>::_Rep:: -: 1075: _M_clone(const _Alloc& __alloc, size_type __res) -: 1076: { -: 1077: // Requested capacity of the clone. -: 1078: const size_type __requested_cap = this->_M_length + __res; -: 1079: _Rep* __r = _Rep::_S_create(__requested_cap, this->_M_capacity, -: 1080: __alloc); -: 1081: if (this->_M_length) -: 1082: _M_copy(__r->_M_refdata(), _M_refdata(), this->_M_length); -: 1083: -: 1084: __r->_M_set_length_and_sharable(this->_M_length); -: 1085: return __r->_M_refdata(); -: 1086: } -: 1087: -: 1088: template -: 1089: void -: 1090: basic_string<_CharT, _Traits, _Alloc>:: -: 1091: resize(size_type __n, _CharT __c) -: 1092: { -: 1093: const size_type __size = this->size(); -: 1094: _M_check_length(__size, __n, "basic_string::resize"); -: 1095: if (__size < __n) -: 1096: this->append(__n - __size, __c); -: 1097: else if (__n < __size) -: 1098: this->erase(__n); -: 1099: // else nothing (in particular, avoid calling _M_mutate() unnecessarily.) -: 1100: } -: 1101: -: 1102: template -: 1103: template -: 1104: basic_string<_CharT, _Traits, _Alloc>& -: 1105: basic_string<_CharT, _Traits, _Alloc>:: -: 1106: _M_replace_dispatch(iterator __i1, iterator __i2, _InputIterator __k1, -: 1107: _InputIterator __k2, __false_type) -: 1108: { -: 1109: const basic_string __s(__k1, __k2); -: 1110: const size_type __n1 = __i2 - __i1; -: 1111: _M_check_length(__n1, __s.size(), "basic_string::_M_replace_dispatch"); -: 1112: return _M_replace_safe(__i1 - _M_ibegin(), __n1, __s._M_data(), -: 1113: __s.size()); -: 1114: } -: 1115: -: 1116: template -: 1117: basic_string<_CharT, _Traits, _Alloc>& -: 1118: basic_string<_CharT, _Traits, _Alloc>:: -: 1119: _M_replace_aux(size_type __pos1, size_type __n1, size_type __n2, -: 1120: _CharT __c) -: 1121: { -: 1122: _M_check_length(__n1, __n2, "basic_string::_M_replace_aux"); -: 1123: _M_mutate(__pos1, __n1, __n2); -: 1124: if (__n2) -: 1125: _M_assign(_M_data() + __pos1, __n2, __c); -: 1126: return *this; -: 1127: } -: 1128: -: 1129: template -: 1130: basic_string<_CharT, _Traits, _Alloc>& -: 1131: basic_string<_CharT, _Traits, _Alloc>:: -: 1132: _M_replace_safe(size_type __pos1, size_type __n1, const _CharT* __s, -: 1133: size_type __n2) -: 1134: { -: 1135: _M_mutate(__pos1, __n1, __n2); -: 1136: if (__n2) -: 1137: _M_copy(_M_data() + __pos1, __s, __n2); -: 1138: return *this; -: 1139: } -: 1140: -: 1141: template -: 1142: typename basic_string<_CharT, _Traits, _Alloc>::size_type -: 1143: basic_string<_CharT, _Traits, _Alloc>:: -: 1144: copy(_CharT* __s, size_type __n, size_type __pos) const -: 1145: { -: 1146: _M_check(__pos, "basic_string::copy"); -: 1147: __n = _M_limit(__pos, __n); -: 1148: __glibcxx_requires_string_len(__s, __n); -: 1149: if (__n) -: 1150: _M_copy(__s, _M_data() + __pos, __n); -: 1151: // 21.3.5.7 par 3: do not append null. (good.) -: 1152: return __n; -: 1153: } -: 1154:#endif // !_GLIBCXX_USE_CXX11_ABI -: 1155: -: 1156: template -: 1157: basic_string<_CharT, _Traits, _Alloc> -: 1158: operator+(const _CharT* __lhs, -: 1159: const basic_string<_CharT, _Traits, _Alloc>& __rhs) -: 1160: { -: 1161: __glibcxx_requires_string(__lhs); -: 1162: typedef basic_string<_CharT, _Traits, _Alloc> __string_type; -: 1163: typedef typename __string_type::size_type __size_type; -: 1164: const __size_type __len = _Traits::length(__lhs); -: 1165: __string_type __str; -: 1166: __str.reserve(__len + __rhs.size()); -: 1167: __str.append(__lhs, __len); -: 1168: __str.append(__rhs); -: 1169: return __str; -: 1170: } -: 1171: -: 1172: template -: 1173: basic_string<_CharT, _Traits, _Alloc> -: 1174: operator+(_CharT __lhs, const basic_string<_CharT, _Traits, _Alloc>& __rhs) -: 1175: { -: 1176: typedef basic_string<_CharT, _Traits, _Alloc> __string_type; -: 1177: typedef typename __string_type::size_type __size_type; -: 1178: __string_type __str; -: 1179: const __size_type __len = __rhs.size(); -: 1180: __str.reserve(__len + 1); -: 1181: __str.append(__size_type(1), __lhs); -: 1182: __str.append(__rhs); -: 1183: return __str; -: 1184: } -: 1185: -: 1186: template -: 1187: typename basic_string<_CharT, _Traits, _Alloc>::size_type -: 1188: basic_string<_CharT, _Traits, _Alloc>:: -: 1189: find(const _CharT* __s, size_type __pos, size_type __n) const -: 1190: _GLIBCXX_NOEXCEPT -: 1191: { -: 1192: __glibcxx_requires_string_len(__s, __n); -: 1193: const size_type __size = this->size(); -: 1194: -: 1195: if (__n == 0) -: 1196: return __pos <= __size ? __pos : npos; -: 1197: if (__pos >= __size) -: 1198: return npos; -: 1199: -: 1200: const _CharT __elem0 = __s[0]; -: 1201: const _CharT* const __data = data(); -: 1202: const _CharT* __first = __data + __pos; -: 1203: const _CharT* const __last = __data + __size; -: 1204: size_type __len = __size - __pos; -: 1205: -: 1206: while (__len >= __n) -: 1207: { -: 1208: // Find the first occurrence of __elem0: -: 1209: __first = traits_type::find(__first, __len - __n + 1, __elem0); -: 1210: if (!__first) -: 1211: return npos; -: 1212: // Compare the full strings from the first occurrence of __elem0. -: 1213: // We already know that __first[0] == __s[0] but compare them again -: 1214: // anyway because __s is probably aligned, which helps memcmp. -: 1215: if (traits_type::compare(__first, __s, __n) == 0) -: 1216: return __first - __data; -: 1217: __len = __last - ++__first; -: 1218: } -: 1219: return npos; -: 1220: } -: 1221: -: 1222: template -: 1223: typename basic_string<_CharT, _Traits, _Alloc>::size_type -: 1224: basic_string<_CharT, _Traits, _Alloc>:: -: 1225: find(_CharT __c, size_type __pos) const _GLIBCXX_NOEXCEPT -: 1226: { -: 1227: size_type __ret = npos; -: 1228: const size_type __size = this->size(); -: 1229: if (__pos < __size) -: 1230: { -: 1231: const _CharT* __data = _M_data(); -: 1232: const size_type __n = __size - __pos; -: 1233: const _CharT* __p = traits_type::find(__data + __pos, __n, __c); -: 1234: if (__p) -: 1235: __ret = __p - __data; -: 1236: } -: 1237: return __ret; -: 1238: } -: 1239: -: 1240: template -: 1241: typename basic_string<_CharT, _Traits, _Alloc>::size_type -: 1242: basic_string<_CharT, _Traits, _Alloc>:: -: 1243: rfind(const _CharT* __s, size_type __pos, size_type __n) const -: 1244: _GLIBCXX_NOEXCEPT -: 1245: { -: 1246: __glibcxx_requires_string_len(__s, __n); -: 1247: const size_type __size = this->size(); -: 1248: if (__n <= __size) -: 1249: { -: 1250: __pos = std::min(size_type(__size - __n), __pos); -: 1251: const _CharT* __data = _M_data(); -: 1252: do -: 1253: { -: 1254: if (traits_type::compare(__data + __pos, __s, __n) == 0) -: 1255: return __pos; -: 1256: } -: 1257: while (__pos-- > 0); -: 1258: } -: 1259: return npos; -: 1260: } -: 1261: -: 1262: template -: 1263: typename basic_string<_CharT, _Traits, _Alloc>::size_type -: 1264: basic_string<_CharT, _Traits, _Alloc>:: -: 1265: rfind(_CharT __c, size_type __pos) const _GLIBCXX_NOEXCEPT -: 1266: { -: 1267: size_type __size = this->size(); -: 1268: if (__size) -: 1269: { -: 1270: if (--__size > __pos) -: 1271: __size = __pos; -: 1272: for (++__size; __size-- > 0; ) -: 1273: if (traits_type::eq(_M_data()[__size], __c)) -: 1274: return __size; -: 1275: } -: 1276: return npos; -: 1277: } -: 1278: -: 1279: template -: 1280: typename basic_string<_CharT, _Traits, _Alloc>::size_type -: 1281: basic_string<_CharT, _Traits, _Alloc>:: -: 1282: find_first_of(const _CharT* __s, size_type __pos, size_type __n) const -: 1283: _GLIBCXX_NOEXCEPT -: 1284: { -: 1285: __glibcxx_requires_string_len(__s, __n); -: 1286: for (; __n && __pos < this->size(); ++__pos) -: 1287: { -: 1288: const _CharT* __p = traits_type::find(__s, __n, _M_data()[__pos]); -: 1289: if (__p) -: 1290: return __pos; -: 1291: } -: 1292: return npos; -: 1293: } -: 1294: -: 1295: template -: 1296: typename basic_string<_CharT, _Traits, _Alloc>::size_type -: 1297: basic_string<_CharT, _Traits, _Alloc>:: -: 1298: find_last_of(const _CharT* __s, size_type __pos, size_type __n) const -: 1299: _GLIBCXX_NOEXCEPT -: 1300: { -: 1301: __glibcxx_requires_string_len(__s, __n); -: 1302: size_type __size = this->size(); -: 1303: if (__size && __n) -: 1304: { -: 1305: if (--__size > __pos) -: 1306: __size = __pos; -: 1307: do -: 1308: { -: 1309: if (traits_type::find(__s, __n, _M_data()[__size])) -: 1310: return __size; -: 1311: } -: 1312: while (__size-- != 0); -: 1313: } -: 1314: return npos; -: 1315: } -: 1316: -: 1317: template -: 1318: typename basic_string<_CharT, _Traits, _Alloc>::size_type -: 1319: basic_string<_CharT, _Traits, _Alloc>:: -: 1320: find_first_not_of(const _CharT* __s, size_type __pos, size_type __n) const -: 1321: _GLIBCXX_NOEXCEPT -: 1322: { -: 1323: __glibcxx_requires_string_len(__s, __n); -: 1324: for (; __pos < this->size(); ++__pos) -: 1325: if (!traits_type::find(__s, __n, _M_data()[__pos])) -: 1326: return __pos; -: 1327: return npos; -: 1328: } -: 1329: -: 1330: template -: 1331: typename basic_string<_CharT, _Traits, _Alloc>::size_type -: 1332: basic_string<_CharT, _Traits, _Alloc>:: -: 1333: find_first_not_of(_CharT __c, size_type __pos) const _GLIBCXX_NOEXCEPT -: 1334: { -: 1335: for (; __pos < this->size(); ++__pos) -: 1336: if (!traits_type::eq(_M_data()[__pos], __c)) -: 1337: return __pos; -: 1338: return npos; -: 1339: } -: 1340: -: 1341: template -: 1342: typename basic_string<_CharT, _Traits, _Alloc>::size_type -: 1343: basic_string<_CharT, _Traits, _Alloc>:: -: 1344: find_last_not_of(const _CharT* __s, size_type __pos, size_type __n) const -: 1345: _GLIBCXX_NOEXCEPT -: 1346: { -: 1347: __glibcxx_requires_string_len(__s, __n); -: 1348: size_type __size = this->size(); -: 1349: if (__size) -: 1350: { -: 1351: if (--__size > __pos) -: 1352: __size = __pos; -: 1353: do -: 1354: { -: 1355: if (!traits_type::find(__s, __n, _M_data()[__size])) -: 1356: return __size; -: 1357: } -: 1358: while (__size--); -: 1359: } -: 1360: return npos; -: 1361: } -: 1362: -: 1363: template -: 1364: typename basic_string<_CharT, _Traits, _Alloc>::size_type -: 1365: basic_string<_CharT, _Traits, _Alloc>:: -: 1366: find_last_not_of(_CharT __c, size_type __pos) const _GLIBCXX_NOEXCEPT -: 1367: { -: 1368: size_type __size = this->size(); -: 1369: if (__size) -: 1370: { -: 1371: if (--__size > __pos) -: 1372: __size = __pos; -: 1373: do -: 1374: { -: 1375: if (!traits_type::eq(_M_data()[__size], __c)) -: 1376: return __size; -: 1377: } -: 1378: while (__size--); -: 1379: } -: 1380: return npos; -: 1381: } -: 1382: -: 1383: template -: 1384: int -: 1385: basic_string<_CharT, _Traits, _Alloc>:: -: 1386: compare(size_type __pos, size_type __n, const basic_string& __str) const -: 1387: { -: 1388: _M_check(__pos, "basic_string::compare"); -: 1389: __n = _M_limit(__pos, __n); -: 1390: const size_type __osize = __str.size(); -: 1391: const size_type __len = std::min(__n, __osize); -: 1392: int __r = traits_type::compare(_M_data() + __pos, __str.data(), __len); -: 1393: if (!__r) -: 1394: __r = _S_compare(__n, __osize); -: 1395: return __r; -: 1396: } -: 1397: -: 1398: template -: 1399: int -: 1400: basic_string<_CharT, _Traits, _Alloc>:: -: 1401: compare(size_type __pos1, size_type __n1, const basic_string& __str, -: 1402: size_type __pos2, size_type __n2) const -: 1403: { -: 1404: _M_check(__pos1, "basic_string::compare"); -: 1405: __str._M_check(__pos2, "basic_string::compare"); -: 1406: __n1 = _M_limit(__pos1, __n1); -: 1407: __n2 = __str._M_limit(__pos2, __n2); -: 1408: const size_type __len = std::min(__n1, __n2); -: 1409: int __r = traits_type::compare(_M_data() + __pos1, -: 1410: __str.data() + __pos2, __len); -: 1411: if (!__r) -: 1412: __r = _S_compare(__n1, __n2); -: 1413: return __r; -: 1414: } -: 1415: -: 1416: template -: 1417: int -: 1418: basic_string<_CharT, _Traits, _Alloc>:: -: 1419: compare(const _CharT* __s) const _GLIBCXX_NOEXCEPT -: 1420: { -: 1421: __glibcxx_requires_string(__s); -: 1422: const size_type __size = this->size(); -: 1423: const size_type __osize = traits_type::length(__s); -: 1424: const size_type __len = std::min(__size, __osize); -: 1425: int __r = traits_type::compare(_M_data(), __s, __len); -: 1426: if (!__r) -: 1427: __r = _S_compare(__size, __osize); -: 1428: return __r; -: 1429: } -: 1430: -: 1431: template -: 1432: int -: 1433: basic_string <_CharT, _Traits, _Alloc>:: -: 1434: compare(size_type __pos, size_type __n1, const _CharT* __s) const -: 1435: { -: 1436: __glibcxx_requires_string(__s); -: 1437: _M_check(__pos, "basic_string::compare"); -: 1438: __n1 = _M_limit(__pos, __n1); -: 1439: const size_type __osize = traits_type::length(__s); -: 1440: const size_type __len = std::min(__n1, __osize); -: 1441: int __r = traits_type::compare(_M_data() + __pos, __s, __len); -: 1442: if (!__r) -: 1443: __r = _S_compare(__n1, __osize); -: 1444: return __r; -: 1445: } -: 1446: -: 1447: template -: 1448: int -: 1449: basic_string <_CharT, _Traits, _Alloc>:: -: 1450: compare(size_type __pos, size_type __n1, const _CharT* __s, -: 1451: size_type __n2) const -: 1452: { -: 1453: __glibcxx_requires_string_len(__s, __n2); -: 1454: _M_check(__pos, "basic_string::compare"); -: 1455: __n1 = _M_limit(__pos, __n1); -: 1456: const size_type __len = std::min(__n1, __n2); -: 1457: int __r = traits_type::compare(_M_data() + __pos, __s, __len); -: 1458: if (!__r) -: 1459: __r = _S_compare(__n1, __n2); -: 1460: return __r; -: 1461: } -: 1462: -: 1463: // 21.3.7.9 basic_string::getline and operators -: 1464: template -: 1465: basic_istream<_CharT, _Traits>& -: 1466: operator>>(basic_istream<_CharT, _Traits>& __in, -: 1467: basic_string<_CharT, _Traits, _Alloc>& __str) -: 1468: { -: 1469: typedef basic_istream<_CharT, _Traits> __istream_type; -: 1470: typedef basic_string<_CharT, _Traits, _Alloc> __string_type; -: 1471: typedef typename __istream_type::ios_base __ios_base; -: 1472: typedef typename __istream_type::int_type __int_type; -: 1473: typedef typename __string_type::size_type __size_type; -: 1474: typedef ctype<_CharT> __ctype_type; -: 1475: typedef typename __ctype_type::ctype_base __ctype_base; -: 1476: -: 1477: __size_type __extracted = 0; -: 1478: typename __ios_base::iostate __err = __ios_base::goodbit; -: 1479: typename __istream_type::sentry __cerb(__in, false); -: 1480: if (__cerb) -: 1481: { -: 1482: __try -: 1483: { -: 1484: // Avoid reallocation for common case. -: 1485: __str.erase(); -: 1486: _CharT __buf[128]; -: 1487: __size_type __len = 0; -: 1488: const streamsize __w = __in.width(); -: 1489: const __size_type __n = __w > 0 ? static_cast<__size_type>(__w) -: 1490: : __str.max_size(); -: 1491: const __ctype_type& __ct = use_facet<__ctype_type>(__in.getloc()); -: 1492: const __int_type __eof = _Traits::eof(); -: 1493: __int_type __c = __in.rdbuf()->sgetc(); -: 1494: -: 1495: while (__extracted < __n -: 1496: && !_Traits::eq_int_type(__c, __eof) -: 1497: && !__ct.is(__ctype_base::space, -: 1498: _Traits::to_char_type(__c))) -: 1499: { -: 1500: if (__len == sizeof(__buf) / sizeof(_CharT)) -: 1501: { -: 1502: __str.append(__buf, sizeof(__buf) / sizeof(_CharT)); -: 1503: __len = 0; -: 1504: } -: 1505: __buf[__len++] = _Traits::to_char_type(__c); -: 1506: ++__extracted; -: 1507: __c = __in.rdbuf()->snextc(); -: 1508: } -: 1509: __str.append(__buf, __len); -: 1510: -: 1511: if (_Traits::eq_int_type(__c, __eof)) -: 1512: __err |= __ios_base::eofbit; -: 1513: __in.width(0); -: 1514: } -: 1515: __catch(__cxxabiv1::__forced_unwind&) -: 1516: { -: 1517: __in._M_setstate(__ios_base::badbit); -: 1518: __throw_exception_again; -: 1519: } -: 1520: __catch(...) -: 1521: { -: 1522: // _GLIBCXX_RESOLVE_LIB_DEFECTS -: 1523: // 91. Description of operator>> and getline() for string<> -: 1524: // might cause endless loop -: 1525: __in._M_setstate(__ios_base::badbit); -: 1526: } -: 1527: } -: 1528: // 211. operator>>(istream&, string&) doesn't set failbit -: 1529: if (!__extracted) -: 1530: __err |= __ios_base::failbit; -: 1531: if (__err) -: 1532: __in.setstate(__err); -: 1533: return __in; -: 1534: } -: 1535: -: 1536: template -: 1537: basic_istream<_CharT, _Traits>& -: 1538: getline(basic_istream<_CharT, _Traits>& __in, -: 1539: basic_string<_CharT, _Traits, _Alloc>& __str, _CharT __delim) -: 1540: { -: 1541: typedef basic_istream<_CharT, _Traits> __istream_type; -: 1542: typedef basic_string<_CharT, _Traits, _Alloc> __string_type; -: 1543: typedef typename __istream_type::ios_base __ios_base; -: 1544: typedef typename __istream_type::int_type __int_type; -: 1545: typedef typename __string_type::size_type __size_type; -: 1546: -: 1547: __size_type __extracted = 0; -: 1548: const __size_type __n = __str.max_size(); -: 1549: typename __ios_base::iostate __err = __ios_base::goodbit; -: 1550: typename __istream_type::sentry __cerb(__in, true); -: 1551: if (__cerb) -: 1552: { -: 1553: __try -: 1554: { -: 1555: __str.erase(); -: 1556: const __int_type __idelim = _Traits::to_int_type(__delim); -: 1557: const __int_type __eof = _Traits::eof(); -: 1558: __int_type __c = __in.rdbuf()->sgetc(); -: 1559: -: 1560: while (__extracted < __n -: 1561: && !_Traits::eq_int_type(__c, __eof) -: 1562: && !_Traits::eq_int_type(__c, __idelim)) -: 1563: { -: 1564: __str += _Traits::to_char_type(__c); -: 1565: ++__extracted; -: 1566: __c = __in.rdbuf()->snextc(); -: 1567: } -: 1568: -: 1569: if (_Traits::eq_int_type(__c, __eof)) -: 1570: __err |= __ios_base::eofbit; -: 1571: else if (_Traits::eq_int_type(__c, __idelim)) -: 1572: { -: 1573: ++__extracted; -: 1574: __in.rdbuf()->sbumpc(); -: 1575: } -: 1576: else -: 1577: __err |= __ios_base::failbit; -: 1578: } -: 1579: __catch(__cxxabiv1::__forced_unwind&) -: 1580: { -: 1581: __in._M_setstate(__ios_base::badbit); -: 1582: __throw_exception_again; -: 1583: } -: 1584: __catch(...) -: 1585: { -: 1586: // _GLIBCXX_RESOLVE_LIB_DEFECTS -: 1587: // 91. Description of operator>> and getline() for string<> -: 1588: // might cause endless loop -: 1589: __in._M_setstate(__ios_base::badbit); -: 1590: } -: 1591: } -: 1592: if (!__extracted) -: 1593: __err |= __ios_base::failbit; -: 1594: if (__err) -: 1595: __in.setstate(__err); -: 1596: return __in; -: 1597: } -: 1598: -: 1599: // Inhibit implicit instantiations for required instantiations, -: 1600: // which are defined via explicit instantiations elsewhere. -: 1601:#if _GLIBCXX_EXTERN_TEMPLATE -: 1602: // The explicit instantiation definitions in src/c++11/string-inst.cc and -: 1603: // src/c++17/string-inst.cc only instantiate the members required for C++17 -: 1604: // and earlier standards (so not C++20's starts_with and ends_with). -: 1605: // Suppress the explicit instantiation declarations for C++20, so C++20 -: 1606: // code will implicitly instantiate std::string and std::wstring as needed. -: 1607:# if __cplusplus <= 201703L && _GLIBCXX_EXTERN_TEMPLATE > 0 -: 1608: extern template class basic_string; -: 1609:# elif ! _GLIBCXX_USE_CXX11_ABI -: 1610: // Still need to prevent implicit instantiation of the COW empty rep, -: 1611: // to ensure the definition in libstdc++.so is unique (PR 86138). -: 1612: extern template basic_string::size_type -: 1613: basic_string::_Rep::_S_empty_rep_storage[]; -: 1614:# endif -: 1615: -: 1616: extern template -: 1617: basic_istream& -: 1618: operator>>(basic_istream&, string&); -: 1619: extern template -: 1620: basic_ostream& -: 1621: operator<<(basic_ostream&, const string&); -: 1622: extern template -: 1623: basic_istream& -: 1624: getline(basic_istream&, string&, char); -: 1625: extern template -: 1626: basic_istream& -: 1627: getline(basic_istream&, string&); -: 1628: -: 1629:#ifdef _GLIBCXX_USE_WCHAR_T -: 1630:# if __cplusplus <= 201703L && _GLIBCXX_EXTERN_TEMPLATE > 0 -: 1631: extern template class basic_string; -: 1632:# elif ! _GLIBCXX_USE_CXX11_ABI -: 1633: extern template basic_string::size_type -: 1634: basic_string::_Rep::_S_empty_rep_storage[]; -: 1635:# endif -: 1636: -: 1637: extern template -: 1638: basic_istream& -: 1639: operator>>(basic_istream&, wstring&); -: 1640: extern template -: 1641: basic_ostream& -: 1642: operator<<(basic_ostream&, const wstring&); -: 1643: extern template -: 1644: basic_istream& -: 1645: getline(basic_istream&, wstring&, wchar_t); -: 1646: extern template -: 1647: basic_istream& -: 1648: getline(basic_istream&, wstring&); -: 1649:#endif // _GLIBCXX_USE_WCHAR_T -: 1650:#endif // _GLIBCXX_EXTERN_TEMPLATE -: 1651: -: 1652:_GLIBCXX_END_NAMESPACE_VERSION -: 1653:} // namespace std -: 1654: -: 1655:#endif <<<<<< EOF # path=tests/binomial_coef.cpp.gcov -: 0:Source:binomial_coef.cpp -: 0:Graph:./binomial_coef.gcno -: 0:Data:./binomial_coef.gcda -: 0:Runs:1 -: 1:/*################################################################################ -: 2: ## -: 3: ## Copyright (C) 2016-2022 Keith O'Hara -: 4: ## -: 5: ## This file is part of the GCE-Math C++ library. -: 6: ## -: 7: ## Licensed under the Apache License, Version 2.0 (the "License"); -: 8: ## you may not use this file except in compliance with the License. -: 9: ## You may obtain a copy of the License at -: 10: ## -: 11: ## http://www.apache.org/licenses/LICENSE-2.0 -: 12: ## -: 13: ## Unless required by applicable law or agreed to in writing, software -: 14: ## distributed under the License is distributed on an "AS IS" BASIS, -: 15: ## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -: 16: ## See the License for the specific language governing permissions and -: 17: ## limitations under the License. -: 18: ## -: 19: ################################################################################*/ -: 20: -: 21:#include "gcem_tests.hpp" -: 22: 1: 23:int main() -: 24:{ 1: 25: print_begin("binomial_coef"); -: 26: -: 27: // -: 28: 2*: 29: GCEM_TEST_EXPECTED_VAL(gcem::binomial_coef, 1, 0, 0); 2*: 30: GCEM_TEST_EXPECTED_VAL(gcem::binomial_coef, 0, 0, 1); 2*: 31: GCEM_TEST_EXPECTED_VAL(gcem::binomial_coef, 1, 1, 0); 2*: 32: GCEM_TEST_EXPECTED_VAL(gcem::binomial_coef, 1, 1, 1); 2*: 33: GCEM_TEST_EXPECTED_VAL(gcem::binomial_coef, 10, 5, 2); 2*: 34: GCEM_TEST_EXPECTED_VAL(gcem::binomial_coef, 45, 10, 8); 2*: 35: GCEM_TEST_EXPECTED_VAL(gcem::binomial_coef, 10, 10, 9); 2*: 36: GCEM_TEST_EXPECTED_VAL(gcem::binomial_coef, 1, 10, 10); -: 37: -: 38: // -: 39: -: 40: // GCEM_TEST_EXPECTED_VAL(gcem::binomial_coef, TEST_NAN, TEST_NAN, 1.0L); -: 41: // GCEM_TEST_EXPECTED_VAL(gcem::binomial_coef, TEST_NAN, 1.0L, TEST_NAN); -: 42: // GCEM_TEST_EXPECTED_VAL(gcem::binomial_coef, TEST_NAN, TEST_NAN, TEST_NAN); -: 43: -: 44: // -: 45: 1: 46: print_final("binomial_coef"); -: 47: 1: 48: return 0; -: 49:} <<<<<< EOF # path=tests/char_traits.h.gcov -: 0:Source:/usr/include/c++/9/bits/char_traits.h -: 0:Graph:log.gcno -: 0:Data:log.gcda -: 0:Runs:2 -: 1:// Character Traits for use by standard string and iostream -*- C++ -*- -: 2: -: 3:// Copyright (C) 1997-2019 Free Software Foundation, Inc. -: 4:// -: 5:// This file is part of the GNU ISO C++ Library. This library is free -: 6:// software; you can redistribute it and/or modify it under the -: 7:// terms of the GNU General Public License as published by the -: 8:// Free Software Foundation; either version 3, or (at your option) -: 9:// any later version. -: 10: -: 11:// This library is distributed in the hope that it will be useful, -: 12:// but WITHOUT ANY WARRANTY; without even the implied warranty of -: 13:// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -: 14:// GNU General Public License for more details. -: 15: -: 16:// Under Section 7 of GPL version 3, you are granted additional -: 17:// permissions described in the GCC Runtime Library Exception, version -: 18:// 3.1, as published by the Free Software Foundation. -: 19: -: 20:// You should have received a copy of the GNU General Public License and -: 21:// a copy of the GCC Runtime Library Exception along with this program; -: 22:// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see -: 23:// . -: 24: -: 25:/** @file bits/char_traits.h -: 26: * This is an internal header file, included by other library headers. -: 27: * Do not attempt to use it directly. @headername{string} -: 28: */ -: 29: -: 30:// -: 31:// ISO C++ 14882: 21 Strings library -: 32:// -: 33: -: 34:#ifndef _CHAR_TRAITS_H -: 35:#define _CHAR_TRAITS_H 1 -: 36: -: 37:#pragma GCC system_header -: 38: -: 39:#include // std::copy, std::fill_n -: 40:#include // For streampos -: 41:#include // For WEOF, wmemmove, wmemset, etc. -: 42: -: 43:#ifndef _GLIBCXX_ALWAYS_INLINE -: 44:# define _GLIBCXX_ALWAYS_INLINE inline __attribute__((__always_inline__)) -: 45:#endif -: 46: -: 47:namespace __gnu_cxx _GLIBCXX_VISIBILITY(default) -: 48:{ -: 49:_GLIBCXX_BEGIN_NAMESPACE_VERSION -: 50: -: 51: /** -: 52: * @brief Mapping from character type to associated types. -: 53: * -: 54: * @note This is an implementation class for the generic version -: 55: * of char_traits. It defines int_type, off_type, pos_type, and -: 56: * state_type. By default these are unsigned long, streamoff, -: 57: * streampos, and mbstate_t. Users who need a different set of -: 58: * types, but who don't need to change the definitions of any function -: 59: * defined in char_traits, can specialize __gnu_cxx::_Char_types -: 60: * while leaving __gnu_cxx::char_traits alone. */ -: 61: template -: 62: struct _Char_types -: 63: { -: 64: typedef unsigned long int_type; -: 65: typedef std::streampos pos_type; -: 66: typedef std::streamoff off_type; -: 67: typedef std::mbstate_t state_type; -: 68: }; -: 69: -: 70: -: 71: /** -: 72: * @brief Base class used to implement std::char_traits. -: 73: * -: 74: * @note For any given actual character type, this definition is -: 75: * probably wrong. (Most of the member functions are likely to be -: 76: * right, but the int_type and state_type typedefs, and the eof() -: 77: * member function, are likely to be wrong.) The reason this class -: 78: * exists is so users can specialize it. Classes in namespace std -: 79: * may not be specialized for fundamental types, but classes in -: 80: * namespace __gnu_cxx may be. -: 81: * -: 82: * See https://gcc.gnu.org/onlinedocs/libstdc++/manual/strings.html#strings.string.character_types -: 83: * for advice on how to make use of this class for @a unusual character -: 84: * types. Also, check out include/ext/pod_char_traits.h. -: 85: */ -: 86: template -: 87: struct char_traits -: 88: { -: 89: typedef _CharT char_type; -: 90: typedef typename _Char_types<_CharT>::int_type int_type; -: 91: typedef typename _Char_types<_CharT>::pos_type pos_type; -: 92: typedef typename _Char_types<_CharT>::off_type off_type; -: 93: typedef typename _Char_types<_CharT>::state_type state_type; -: 94: -: 95: static _GLIBCXX14_CONSTEXPR void -: 96: assign(char_type& __c1, const char_type& __c2) -: 97: { __c1 = __c2; } -: 98: -: 99: static _GLIBCXX_CONSTEXPR bool -: 100: eq(const char_type& __c1, const char_type& __c2) -: 101: { return __c1 == __c2; } -: 102: -: 103: static _GLIBCXX_CONSTEXPR bool -: 104: lt(const char_type& __c1, const char_type& __c2) -: 105: { return __c1 < __c2; } -: 106: -: 107: static _GLIBCXX14_CONSTEXPR int -: 108: compare(const char_type* __s1, const char_type* __s2, std::size_t __n); -: 109: -: 110: static _GLIBCXX14_CONSTEXPR std::size_t -: 111: length(const char_type* __s); -: 112: -: 113: static _GLIBCXX14_CONSTEXPR const char_type* -: 114: find(const char_type* __s, std::size_t __n, const char_type& __a); -: 115: -: 116: static char_type* -: 117: move(char_type* __s1, const char_type* __s2, std::size_t __n); -: 118: -: 119: static char_type* -: 120: copy(char_type* __s1, const char_type* __s2, std::size_t __n); -: 121: -: 122: static char_type* -: 123: assign(char_type* __s, std::size_t __n, char_type __a); -: 124: -: 125: static _GLIBCXX_CONSTEXPR char_type -: 126: to_char_type(const int_type& __c) -: 127: { return static_cast(__c); } -: 128: -: 129: static _GLIBCXX_CONSTEXPR int_type -: 130: to_int_type(const char_type& __c) -: 131: { return static_cast(__c); } -: 132: -: 133: static _GLIBCXX_CONSTEXPR bool -: 134: eq_int_type(const int_type& __c1, const int_type& __c2) -: 135: { return __c1 == __c2; } -: 136: -: 137: static _GLIBCXX_CONSTEXPR int_type -: 138: eof() -: 139: { return static_cast(_GLIBCXX_STDIO_EOF); } -: 140: -: 141: static _GLIBCXX_CONSTEXPR int_type -: 142: not_eof(const int_type& __c) -: 143: { return !eq_int_type(__c, eof()) ? __c : to_int_type(char_type()); } -: 144: }; -: 145: -: 146: template -: 147: _GLIBCXX14_CONSTEXPR int -: 148: char_traits<_CharT>:: -: 149: compare(const char_type* __s1, const char_type* __s2, std::size_t __n) -: 150: { -: 151: for (std::size_t __i = 0; __i < __n; ++__i) -: 152: if (lt(__s1[__i], __s2[__i])) -: 153: return -1; -: 154: else if (lt(__s2[__i], __s1[__i])) -: 155: return 1; -: 156: return 0; -: 157: } -: 158: -: 159: template -: 160: _GLIBCXX14_CONSTEXPR std::size_t -: 161: char_traits<_CharT>:: -: 162: length(const char_type* __p) -: 163: { -: 164: std::size_t __i = 0; -: 165: while (!eq(__p[__i], char_type())) -: 166: ++__i; -: 167: return __i; -: 168: } -: 169: -: 170: template -: 171: _GLIBCXX14_CONSTEXPR const typename char_traits<_CharT>::char_type* -: 172: char_traits<_CharT>:: -: 173: find(const char_type* __s, std::size_t __n, const char_type& __a) -: 174: { -: 175: for (std::size_t __i = 0; __i < __n; ++__i) -: 176: if (eq(__s[__i], __a)) -: 177: return __s + __i; -: 178: return 0; -: 179: } -: 180: -: 181: template -: 182: typename char_traits<_CharT>::char_type* -: 183: char_traits<_CharT>:: -: 184: move(char_type* __s1, const char_type* __s2, std::size_t __n) -: 185: { -: 186: if (__n == 0) -: 187: return __s1; -: 188: return static_cast<_CharT*>(__builtin_memmove(__s1, __s2, -: 189: __n * sizeof(char_type))); -: 190: } -: 191: -: 192: template -: 193: typename char_traits<_CharT>::char_type* -: 194: char_traits<_CharT>:: -: 195: copy(char_type* __s1, const char_type* __s2, std::size_t __n) -: 196: { -: 197: // NB: Inline std::copy so no recursive dependencies. -: 198: std::copy(__s2, __s2 + __n, __s1); -: 199: return __s1; -: 200: } -: 201: -: 202: template -: 203: typename char_traits<_CharT>::char_type* -: 204: char_traits<_CharT>:: -: 205: assign(char_type* __s, std::size_t __n, char_type __a) -: 206: { -: 207: // NB: Inline std::fill_n so no recursive dependencies. -: 208: std::fill_n(__s, __n, __a); -: 209: return __s; -: 210: } -: 211: -: 212:_GLIBCXX_END_NAMESPACE_VERSION -: 213:} // namespace -: 214: -: 215:namespace std _GLIBCXX_VISIBILITY(default) -: 216:{ -: 217:_GLIBCXX_BEGIN_NAMESPACE_VERSION -: 218: -: 219:#if __cplusplus >= 201703L -: 220:#define __cpp_lib_constexpr_char_traits 201611 -: 221: -: 222: /** -: 223: * @brief Determine whether the characters of a NULL-terminated -: 224: * string are known at compile time. -: 225: * @param __s The string. -: 226: * -: 227: * Assumes that _CharT is a built-in character type. -: 228: */ -: 229: template -: 230: static _GLIBCXX_ALWAYS_INLINE constexpr bool -: 231: __constant_string_p(const _CharT* __s) -: 232: { -: 233:#ifdef _GLIBCXX_HAVE_BUILTIN_IS_CONSTANT_EVALUATED -: 234: (void) __s; -: 235: // In constexpr contexts all strings should be constant. -: 236: return __builtin_is_constant_evaluated(); -: 237:#else -: 238: while (__builtin_constant_p(*__s) && *__s) -: 239: __s++; -: 240: return __builtin_constant_p(*__s); -: 241:#endif -: 242: } -: 243: -: 244: /** -: 245: * @brief Determine whether the characters of a character array are -: 246: * known at compile time. -: 247: * @param __a The character array. -: 248: * @param __n Number of characters. -: 249: * -: 250: * Assumes that _CharT is a built-in character type. -: 251: */ -: 252: template -: 253: static _GLIBCXX_ALWAYS_INLINE constexpr bool -: 254: __constant_char_array_p(const _CharT* __a, size_t __n) -: 255: { -: 256:#ifdef _GLIBCXX_HAVE_BUILTIN_IS_CONSTANT_EVALUATED -: 257: (void) __a; -: 258: (void) __n; -: 259: // In constexpr contexts all character arrays should be constant. -: 260: return __builtin_is_constant_evaluated(); -: 261:#else -: 262: size_t __i = 0; -: 263: while (__i < __n && __builtin_constant_p(__a[__i])) -: 264: __i++; -: 265: return __i == __n; -: 266:#endif -: 267: } -: 268:#endif -: 269: -: 270: // 21.1 -: 271: /** -: 272: * @brief Basis for explicit traits specializations. -: 273: * -: 274: * @note For any given actual character type, this definition is -: 275: * probably wrong. Since this is just a thin wrapper around -: 276: * __gnu_cxx::char_traits, it is possible to achieve a more -: 277: * appropriate definition by specializing __gnu_cxx::char_traits. -: 278: * -: 279: * See https://gcc.gnu.org/onlinedocs/libstdc++/manual/strings.html#strings.string.character_types -: 280: * for advice on how to make use of this class for @a unusual character -: 281: * types. Also, check out include/ext/pod_char_traits.h. -: 282: */ -: 283: template -: 284: struct char_traits : public __gnu_cxx::char_traits<_CharT> -: 285: { }; -: 286: -: 287: -: 288: /// 21.1.3.1 char_traits specializations -: 289: template<> -: 290: struct char_traits -: 291: { -: 292: typedef char char_type; -: 293: typedef int int_type; -: 294: typedef streampos pos_type; -: 295: typedef streamoff off_type; -: 296: typedef mbstate_t state_type; -: 297: -: 298: static _GLIBCXX17_CONSTEXPR void -: 299: assign(char_type& __c1, const char_type& __c2) _GLIBCXX_NOEXCEPT -: 300: { __c1 = __c2; } -: 301: -: 302: static _GLIBCXX_CONSTEXPR bool -: 303: eq(const char_type& __c1, const char_type& __c2) _GLIBCXX_NOEXCEPT -: 304: { return __c1 == __c2; } -: 305: -: 306: static _GLIBCXX_CONSTEXPR bool -: 307: lt(const char_type& __c1, const char_type& __c2) _GLIBCXX_NOEXCEPT -: 308: { -: 309: // LWG 467. -: 310: return (static_cast(__c1) -: 311: < static_cast(__c2)); -: 312: } -: 313: -: 314: static _GLIBCXX17_CONSTEXPR int -: 315: compare(const char_type* __s1, const char_type* __s2, size_t __n) -: 316: { -: 317: if (__n == 0) -: 318: return 0; -: 319:#if __cplusplus >= 201703L -: 320: if (__builtin_constant_p(__n) -: 321: && __constant_char_array_p(__s1, __n) -: 322: && __constant_char_array_p(__s2, __n)) -: 323: { -: 324: for (size_t __i = 0; __i < __n; ++__i) -: 325: if (lt(__s1[__i], __s2[__i])) -: 326: return -1; -: 327: else if (lt(__s2[__i], __s1[__i])) -: 328: return 1; -: 329: return 0; -: 330: } -: 331:#endif -: 332: return __builtin_memcmp(__s1, __s2, __n); -: 333: } -: 334: -: 335: static _GLIBCXX17_CONSTEXPR size_t #####: 336: length(const char_type* __s) -: 337: { -: 338:#if __cplusplus >= 201703L -: 339: if (__constant_string_p(__s)) -: 340: return __gnu_cxx::char_traits::length(__s); -: 341:#endif #####: 342: return __builtin_strlen(__s); -: 343: } -: 344: -: 345: static _GLIBCXX17_CONSTEXPR const char_type* -: 346: find(const char_type* __s, size_t __n, const char_type& __a) -: 347: { -: 348: if (__n == 0) -: 349: return 0; -: 350:#if __cplusplus >= 201703L -: 351: if (__builtin_constant_p(__n) -: 352: && __builtin_constant_p(__a) -: 353: && __constant_char_array_p(__s, __n)) -: 354: return __gnu_cxx::char_traits::find(__s, __n, __a); -: 355:#endif -: 356: return static_cast(__builtin_memchr(__s, __a, __n)); -: 357: } -: 358: -: 359: static char_type* -: 360: move(char_type* __s1, const char_type* __s2, size_t __n) -: 361: { -: 362: if (__n == 0) -: 363: return __s1; -: 364: return static_cast(__builtin_memmove(__s1, __s2, __n)); -: 365: } -: 366: -: 367: static char_type* -: 368: copy(char_type* __s1, const char_type* __s2, size_t __n) -: 369: { -: 370: if (__n == 0) -: 371: return __s1; -: 372: return static_cast(__builtin_memcpy(__s1, __s2, __n)); -: 373: } -: 374: -: 375: static char_type* -: 376: assign(char_type* __s, size_t __n, char_type __a) -: 377: { -: 378: if (__n == 0) -: 379: return __s; -: 380: return static_cast(__builtin_memset(__s, __a, __n)); -: 381: } -: 382: -: 383: static _GLIBCXX_CONSTEXPR char_type -: 384: to_char_type(const int_type& __c) _GLIBCXX_NOEXCEPT -: 385: { return static_cast(__c); } -: 386: -: 387: // To keep both the byte 0xff and the eof symbol 0xffffffff -: 388: // from ending up as 0xffffffff. -: 389: static _GLIBCXX_CONSTEXPR int_type -: 390: to_int_type(const char_type& __c) _GLIBCXX_NOEXCEPT -: 391: { return static_cast(static_cast(__c)); } -: 392: -: 393: static _GLIBCXX_CONSTEXPR bool -: 394: eq_int_type(const int_type& __c1, const int_type& __c2) _GLIBCXX_NOEXCEPT -: 395: { return __c1 == __c2; } -: 396: -: 397: static _GLIBCXX_CONSTEXPR int_type -: 398: eof() _GLIBCXX_NOEXCEPT -: 399: { return static_cast(_GLIBCXX_STDIO_EOF); } -: 400: -: 401: static _GLIBCXX_CONSTEXPR int_type -: 402: not_eof(const int_type& __c) _GLIBCXX_NOEXCEPT -: 403: { return (__c == eof()) ? 0 : __c; } -: 404: }; -: 405: -: 406: -: 407:#ifdef _GLIBCXX_USE_WCHAR_T -: 408: /// 21.1.3.2 char_traits specializations -: 409: template<> -: 410: struct char_traits -: 411: { -: 412: typedef wchar_t char_type; -: 413: typedef wint_t int_type; -: 414: typedef streamoff off_type; -: 415: typedef wstreampos pos_type; -: 416: typedef mbstate_t state_type; -: 417: -: 418: static _GLIBCXX17_CONSTEXPR void -: 419: assign(char_type& __c1, const char_type& __c2) _GLIBCXX_NOEXCEPT -: 420: { __c1 = __c2; } -: 421: -: 422: static _GLIBCXX_CONSTEXPR bool -: 423: eq(const char_type& __c1, const char_type& __c2) _GLIBCXX_NOEXCEPT -: 424: { return __c1 == __c2; } -: 425: -: 426: static _GLIBCXX_CONSTEXPR bool -: 427: lt(const char_type& __c1, const char_type& __c2) _GLIBCXX_NOEXCEPT -: 428: { return __c1 < __c2; } -: 429: -: 430: static _GLIBCXX17_CONSTEXPR int -: 431: compare(const char_type* __s1, const char_type* __s2, size_t __n) -: 432: { -: 433: if (__n == 0) -: 434: return 0; -: 435:#if __cplusplus >= 201703L -: 436: if (__builtin_constant_p(__n) -: 437: && __constant_char_array_p(__s1, __n) -: 438: && __constant_char_array_p(__s2, __n)) -: 439: return __gnu_cxx::char_traits::compare(__s1, __s2, __n); -: 440:#endif -: 441: return wmemcmp(__s1, __s2, __n); -: 442: } -: 443: -: 444: static _GLIBCXX17_CONSTEXPR size_t -: 445: length(const char_type* __s) -: 446: { -: 447:#if __cplusplus >= 201703L -: 448: if (__constant_string_p(__s)) -: 449: return __gnu_cxx::char_traits::length(__s); -: 450:#endif -: 451: return wcslen(__s); -: 452: } -: 453: -: 454: static _GLIBCXX17_CONSTEXPR const char_type* -: 455: find(const char_type* __s, size_t __n, const char_type& __a) -: 456: { -: 457: if (__n == 0) -: 458: return 0; -: 459:#if __cplusplus >= 201703L -: 460: if (__builtin_constant_p(__n) -: 461: && __builtin_constant_p(__a) -: 462: && __constant_char_array_p(__s, __n)) -: 463: return __gnu_cxx::char_traits::find(__s, __n, __a); -: 464:#endif -: 465: return wmemchr(__s, __a, __n); -: 466: } -: 467: -: 468: static char_type* -: 469: move(char_type* __s1, const char_type* __s2, size_t __n) -: 470: { -: 471: if (__n == 0) -: 472: return __s1; -: 473: return wmemmove(__s1, __s2, __n); -: 474: } -: 475: -: 476: static char_type* -: 477: copy(char_type* __s1, const char_type* __s2, size_t __n) -: 478: { -: 479: if (__n == 0) -: 480: return __s1; -: 481: return wmemcpy(__s1, __s2, __n); -: 482: } -: 483: -: 484: static char_type* -: 485: assign(char_type* __s, size_t __n, char_type __a) -: 486: { -: 487: if (__n == 0) -: 488: return __s; -: 489: return wmemset(__s, __a, __n); -: 490: } -: 491: -: 492: static _GLIBCXX_CONSTEXPR char_type -: 493: to_char_type(const int_type& __c) _GLIBCXX_NOEXCEPT -: 494: { return char_type(__c); } -: 495: -: 496: static _GLIBCXX_CONSTEXPR int_type -: 497: to_int_type(const char_type& __c) _GLIBCXX_NOEXCEPT -: 498: { return int_type(__c); } -: 499: -: 500: static _GLIBCXX_CONSTEXPR bool -: 501: eq_int_type(const int_type& __c1, const int_type& __c2) _GLIBCXX_NOEXCEPT -: 502: { return __c1 == __c2; } -: 503: -: 504: static _GLIBCXX_CONSTEXPR int_type -: 505: eof() _GLIBCXX_NOEXCEPT -: 506: { return static_cast(WEOF); } -: 507: -: 508: static _GLIBCXX_CONSTEXPR int_type -: 509: not_eof(const int_type& __c) _GLIBCXX_NOEXCEPT -: 510: { return eq_int_type(__c, eof()) ? 0 : __c; } -: 511: }; -: 512:#endif //_GLIBCXX_USE_WCHAR_T -: 513: -: 514:#ifdef _GLIBCXX_USE_CHAR8_T -: 515: template<> -: 516: struct char_traits -: 517: { -: 518: typedef char8_t char_type; -: 519: typedef unsigned int int_type; -: 520: typedef u8streampos pos_type; -: 521: typedef streamoff off_type; -: 522: typedef mbstate_t state_type; -: 523: -: 524: static _GLIBCXX17_CONSTEXPR void -: 525: assign(char_type& __c1, const char_type& __c2) _GLIBCXX_NOEXCEPT -: 526: { __c1 = __c2; } -: 527: -: 528: static _GLIBCXX_CONSTEXPR bool -: 529: eq(const char_type& __c1, const char_type& __c2) _GLIBCXX_NOEXCEPT -: 530: { return __c1 == __c2; } -: 531: -: 532: static _GLIBCXX_CONSTEXPR bool -: 533: lt(const char_type& __c1, const char_type& __c2) _GLIBCXX_NOEXCEPT -: 534: { return __c1 < __c2; } -: 535: -: 536: static _GLIBCXX17_CONSTEXPR int -: 537: compare(const char_type* __s1, const char_type* __s2, size_t __n) -: 538: { -: 539: if (__n == 0) -: 540: return 0; -: 541:#if __cplusplus > 201402 -: 542: if (__builtin_constant_p(__n) -: 543: && __constant_char_array_p(__s1, __n) -: 544: && __constant_char_array_p(__s2, __n)) -: 545: return __gnu_cxx::char_traits::compare(__s1, __s2, __n); -: 546:#endif -: 547: return __builtin_memcmp(__s1, __s2, __n); -: 548: } -: 549: -: 550: static _GLIBCXX17_CONSTEXPR size_t -: 551: length(const char_type* __s) -: 552: { -: 553:#if __cplusplus > 201402 -: 554: if (__constant_string_p(__s)) -: 555: return __gnu_cxx::char_traits::length(__s); -: 556:#endif -: 557: size_t __i = 0; -: 558: while (!eq(__s[__i], char_type())) -: 559: ++__i; -: 560: return __i; -: 561: } -: 562: -: 563: static _GLIBCXX17_CONSTEXPR const char_type* -: 564: find(const char_type* __s, size_t __n, const char_type& __a) -: 565: { -: 566: if (__n == 0) -: 567: return 0; -: 568:#if __cplusplus > 201402 -: 569: if (__builtin_constant_p(__n) -: 570: && __builtin_constant_p(__a) -: 571: && __constant_char_array_p(__s, __n)) -: 572: return __gnu_cxx::char_traits::find(__s, __n, __a); -: 573:#endif -: 574: return static_cast(__builtin_memchr(__s, __a, __n)); -: 575: } -: 576: -: 577: static char_type* -: 578: move(char_type* __s1, const char_type* __s2, size_t __n) -: 579: { -: 580: if (__n == 0) -: 581: return __s1; -: 582: return static_cast(__builtin_memmove(__s1, __s2, __n)); -: 583: } -: 584: -: 585: static char_type* -: 586: copy(char_type* __s1, const char_type* __s2, size_t __n) -: 587: { -: 588: if (__n == 0) -: 589: return __s1; -: 590: return static_cast(__builtin_memcpy(__s1, __s2, __n)); -: 591: } -: 592: -: 593: static char_type* -: 594: assign(char_type* __s, size_t __n, char_type __a) -: 595: { -: 596: if (__n == 0) -: 597: return __s; -: 598: return static_cast(__builtin_memset(__s, __a, __n)); -: 599: } -: 600: -: 601: static _GLIBCXX_CONSTEXPR char_type -: 602: to_char_type(const int_type& __c) _GLIBCXX_NOEXCEPT -: 603: { return char_type(__c); } -: 604: -: 605: static _GLIBCXX_CONSTEXPR int_type -: 606: to_int_type(const char_type& __c) _GLIBCXX_NOEXCEPT -: 607: { return int_type(__c); } -: 608: -: 609: static _GLIBCXX_CONSTEXPR bool -: 610: eq_int_type(const int_type& __c1, const int_type& __c2) _GLIBCXX_NOEXCEPT -: 611: { return __c1 == __c2; } -: 612: -: 613: static _GLIBCXX_CONSTEXPR int_type -: 614: eof() _GLIBCXX_NOEXCEPT -: 615: { return static_cast(-1); } -: 616: -: 617: static _GLIBCXX_CONSTEXPR int_type -: 618: not_eof(const int_type& __c) _GLIBCXX_NOEXCEPT -: 619: { return eq_int_type(__c, eof()) ? 0 : __c; } -: 620: }; -: 621:#endif //_GLIBCXX_USE_CHAR8_T -: 622: -: 623:_GLIBCXX_END_NAMESPACE_VERSION -: 624:} // namespace -: 625: -: 626:#if __cplusplus >= 201103L -: 627: -: 628:#include -: 629: -: 630:namespace std _GLIBCXX_VISIBILITY(default) -: 631:{ -: 632:_GLIBCXX_BEGIN_NAMESPACE_VERSION -: 633: -: 634: template<> -: 635: struct char_traits -: 636: { -: 637: typedef char16_t char_type; -: 638:#ifdef _GLIBCXX_USE_C99_STDINT_TR1 -: 639: typedef uint_least16_t int_type; -: 640:#elif defined __UINT_LEAST16_TYPE__ -: 641: typedef __UINT_LEAST16_TYPE__ int_type; -: 642:#else -: 643: typedef make_unsigned::type int_type; -: 644:#endif -: 645: typedef streamoff off_type; -: 646: typedef u16streampos pos_type; -: 647: typedef mbstate_t state_type; -: 648: -: 649: static _GLIBCXX17_CONSTEXPR void -: 650: assign(char_type& __c1, const char_type& __c2) noexcept -: 651: { __c1 = __c2; } -: 652: -: 653: static constexpr bool -: 654: eq(const char_type& __c1, const char_type& __c2) noexcept -: 655: { return __c1 == __c2; } -: 656: -: 657: static constexpr bool -: 658: lt(const char_type& __c1, const char_type& __c2) noexcept -: 659: { return __c1 < __c2; } -: 660: -: 661: static _GLIBCXX17_CONSTEXPR int -: 662: compare(const char_type* __s1, const char_type* __s2, size_t __n) -: 663: { -: 664: for (size_t __i = 0; __i < __n; ++__i) -: 665: if (lt(__s1[__i], __s2[__i])) -: 666: return -1; -: 667: else if (lt(__s2[__i], __s1[__i])) -: 668: return 1; -: 669: return 0; -: 670: } -: 671: -: 672: static _GLIBCXX17_CONSTEXPR size_t -: 673: length(const char_type* __s) -: 674: { -: 675: size_t __i = 0; -: 676: while (!eq(__s[__i], char_type())) -: 677: ++__i; -: 678: return __i; -: 679: } -: 680: -: 681: static _GLIBCXX17_CONSTEXPR const char_type* -: 682: find(const char_type* __s, size_t __n, const char_type& __a) -: 683: { -: 684: for (size_t __i = 0; __i < __n; ++__i) -: 685: if (eq(__s[__i], __a)) -: 686: return __s + __i; -: 687: return 0; -: 688: } -: 689: -: 690: static char_type* -: 691: move(char_type* __s1, const char_type* __s2, size_t __n) -: 692: { -: 693: if (__n == 0) -: 694: return __s1; -: 695: return (static_cast -: 696: (__builtin_memmove(__s1, __s2, __n * sizeof(char_type)))); -: 697: } -: 698: -: 699: static char_type* -: 700: copy(char_type* __s1, const char_type* __s2, size_t __n) -: 701: { -: 702: if (__n == 0) -: 703: return __s1; -: 704: return (static_cast -: 705: (__builtin_memcpy(__s1, __s2, __n * sizeof(char_type)))); -: 706: } -: 707: -: 708: static char_type* -: 709: assign(char_type* __s, size_t __n, char_type __a) -: 710: { -: 711: for (size_t __i = 0; __i < __n; ++__i) -: 712: assign(__s[__i], __a); -: 713: return __s; -: 714: } -: 715: -: 716: static constexpr char_type -: 717: to_char_type(const int_type& __c) noexcept -: 718: { return char_type(__c); } -: 719: -: 720: static constexpr int_type -: 721: to_int_type(const char_type& __c) noexcept -: 722: { return __c == eof() ? int_type(0xfffd) : int_type(__c); } -: 723: -: 724: static constexpr bool -: 725: eq_int_type(const int_type& __c1, const int_type& __c2) noexcept -: 726: { return __c1 == __c2; } -: 727: -: 728: static constexpr int_type -: 729: eof() noexcept -: 730: { return static_cast(-1); } -: 731: -: 732: static constexpr int_type -: 733: not_eof(const int_type& __c) noexcept -: 734: { return eq_int_type(__c, eof()) ? 0 : __c; } -: 735: }; -: 736: -: 737: template<> -: 738: struct char_traits -: 739: { -: 740: typedef char32_t char_type; -: 741:#ifdef _GLIBCXX_USE_C99_STDINT_TR1 -: 742: typedef uint_least32_t int_type; -: 743:#elif defined __UINT_LEAST32_TYPE__ -: 744: typedef __UINT_LEAST32_TYPE__ int_type; -: 745:#else -: 746: typedef make_unsigned::type int_type; -: 747:#endif -: 748: typedef streamoff off_type; -: 749: typedef u32streampos pos_type; -: 750: typedef mbstate_t state_type; -: 751: -: 752: static _GLIBCXX17_CONSTEXPR void -: 753: assign(char_type& __c1, const char_type& __c2) noexcept -: 754: { __c1 = __c2; } -: 755: -: 756: static constexpr bool -: 757: eq(const char_type& __c1, const char_type& __c2) noexcept -: 758: { return __c1 == __c2; } -: 759: -: 760: static constexpr bool -: 761: lt(const char_type& __c1, const char_type& __c2) noexcept -: 762: { return __c1 < __c2; } -: 763: -: 764: static _GLIBCXX17_CONSTEXPR int -: 765: compare(const char_type* __s1, const char_type* __s2, size_t __n) -: 766: { -: 767: for (size_t __i = 0; __i < __n; ++__i) -: 768: if (lt(__s1[__i], __s2[__i])) -: 769: return -1; -: 770: else if (lt(__s2[__i], __s1[__i])) -: 771: return 1; -: 772: return 0; -: 773: } -: 774: -: 775: static _GLIBCXX17_CONSTEXPR size_t -: 776: length(const char_type* __s) -: 777: { -: 778: size_t __i = 0; -: 779: while (!eq(__s[__i], char_type())) -: 780: ++__i; -: 781: return __i; -: 782: } -: 783: -: 784: static _GLIBCXX17_CONSTEXPR const char_type* -: 785: find(const char_type* __s, size_t __n, const char_type& __a) -: 786: { -: 787: for (size_t __i = 0; __i < __n; ++__i) -: 788: if (eq(__s[__i], __a)) -: 789: return __s + __i; -: 790: return 0; -: 791: } -: 792: -: 793: static char_type* -: 794: move(char_type* __s1, const char_type* __s2, size_t __n) -: 795: { -: 796: if (__n == 0) -: 797: return __s1; -: 798: return (static_cast -: 799: (__builtin_memmove(__s1, __s2, __n * sizeof(char_type)))); -: 800: } -: 801: -: 802: static char_type* -: 803: copy(char_type* __s1, const char_type* __s2, size_t __n) -: 804: { -: 805: if (__n == 0) -: 806: return __s1; -: 807: return (static_cast -: 808: (__builtin_memcpy(__s1, __s2, __n * sizeof(char_type)))); -: 809: } -: 810: -: 811: static char_type* -: 812: assign(char_type* __s, size_t __n, char_type __a) -: 813: { -: 814: for (size_t __i = 0; __i < __n; ++__i) -: 815: assign(__s[__i], __a); -: 816: return __s; -: 817: } -: 818: -: 819: static constexpr char_type -: 820: to_char_type(const int_type& __c) noexcept -: 821: { return char_type(__c); } -: 822: -: 823: static constexpr int_type -: 824: to_int_type(const char_type& __c) noexcept -: 825: { return int_type(__c); } -: 826: -: 827: static constexpr bool -: 828: eq_int_type(const int_type& __c1, const int_type& __c2) noexcept -: 829: { return __c1 == __c2; } -: 830: -: 831: static constexpr int_type -: 832: eof() noexcept -: 833: { return static_cast(-1); } -: 834: -: 835: static constexpr int_type -: 836: not_eof(const int_type& __c) noexcept -: 837: { return eq_int_type(__c, eof()) ? 0 : __c; } -: 838: }; -: 839: -: 840:_GLIBCXX_END_NAMESPACE_VERSION -: 841:} // namespace -: 842: -: 843:#endif // C++11 -: 844: -: 845:#endif // _CHAR_TRAITS_H <<<<<< EOF # path=tests/cmath.gcov -: 0:Source:/usr/include/c++/9/cmath -: 0:Graph:log.gcno -: 0:Data:log.gcda -: 0:Runs:2 -: 1:// -*- C++ -*- C forwarding header. -: 2: -: 3:// Copyright (C) 1997-2019 Free Software Foundation, Inc. -: 4:// -: 5:// This file is part of the GNU ISO C++ Library. This library is free -: 6:// software; you can redistribute it and/or modify it under the -: 7:// terms of the GNU General Public License as published by the -: 8:// Free Software Foundation; either version 3, or (at your option) -: 9:// any later version. -: 10: -: 11:// This library is distributed in the hope that it will be useful, -: 12:// but WITHOUT ANY WARRANTY; without even the implied warranty of -: 13:// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -: 14:// GNU General Public License for more details. -: 15: -: 16:// Under Section 7 of GPL version 3, you are granted additional -: 17:// permissions described in the GCC Runtime Library Exception, version -: 18:// 3.1, as published by the Free Software Foundation. -: 19: -: 20:// You should have received a copy of the GNU General Public License and -: 21:// a copy of the GCC Runtime Library Exception along with this program; -: 22:// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see -: 23:// . -: 24: -: 25:/** @file include/cmath -: 26: * This is a Standard C++ Library file. You should @c \#include this file -: 27: * in your programs, rather than any of the @a *.h implementation files. -: 28: * -: 29: * This is the C++ version of the Standard C Library header @c math.h, -: 30: * and its contents are (mostly) the same as that header, but are all -: 31: * contained in the namespace @c std (except for names which are defined -: 32: * as macros in C). -: 33: */ -: 34: -: 35:// -: 36:// ISO C++ 14882: 26.5 C library -: 37:// -: 38: -: 39:#pragma GCC system_header -: 40: -: 41:#include -: 42:#include -: 43:#include -: 44:#define _GLIBCXX_INCLUDE_NEXT_C_HEADERS -: 45:#include_next -: 46:#undef _GLIBCXX_INCLUDE_NEXT_C_HEADERS -: 47:#include -: 48: -: 49:#ifndef _GLIBCXX_CMATH -: 50:#define _GLIBCXX_CMATH 1 -: 51: -: 52:// Get rid of those macros defined in in lieu of real functions. -: 53:#undef div -: 54:#undef acos -: 55:#undef asin -: 56:#undef atan -: 57:#undef atan2 -: 58:#undef ceil -: 59:#undef cos -: 60:#undef cosh -: 61:#undef exp -: 62:#undef fabs -: 63:#undef floor -: 64:#undef fmod -: 65:#undef frexp -: 66:#undef ldexp -: 67:#undef log -: 68:#undef log10 -: 69:#undef modf -: 70:#undef pow -: 71:#undef sin -: 72:#undef sinh -: 73:#undef sqrt -: 74:#undef tan -: 75:#undef tanh -: 76: -: 77:extern "C++" -: 78:{ -: 79:namespace std _GLIBCXX_VISIBILITY(default) -: 80:{ -: 81:_GLIBCXX_BEGIN_NAMESPACE_VERSION -: 82: -: 83: using ::acos; -: 84: -: 85:#ifndef __CORRECT_ISO_CPP_MATH_H_PROTO -: 86: inline _GLIBCXX_CONSTEXPR float -: 87: acos(float __x) -: 88: { return __builtin_acosf(__x); } -: 89: -: 90: inline _GLIBCXX_CONSTEXPR long double -: 91: acos(long double __x) -: 92: { return __builtin_acosl(__x); } -: 93:#endif -: 94: -: 95: template -: 96: inline _GLIBCXX_CONSTEXPR -: 97: typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value, -: 98: double>::__type -: 99: acos(_Tp __x) -: 100: { return __builtin_acos(__x); } -: 101: -: 102: using ::asin; -: 103: -: 104:#ifndef __CORRECT_ISO_CPP_MATH_H_PROTO -: 105: inline _GLIBCXX_CONSTEXPR float -: 106: asin(float __x) -: 107: { return __builtin_asinf(__x); } -: 108: -: 109: inline _GLIBCXX_CONSTEXPR long double -: 110: asin(long double __x) -: 111: { return __builtin_asinl(__x); } -: 112:#endif -: 113: -: 114: template -: 115: inline _GLIBCXX_CONSTEXPR -: 116: typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value, -: 117: double>::__type -: 118: asin(_Tp __x) -: 119: { return __builtin_asin(__x); } -: 120: -: 121: using ::atan; -: 122: -: 123:#ifndef __CORRECT_ISO_CPP_MATH_H_PROTO -: 124: inline _GLIBCXX_CONSTEXPR float -: 125: atan(float __x) -: 126: { return __builtin_atanf(__x); } -: 127: -: 128: inline _GLIBCXX_CONSTEXPR long double -: 129: atan(long double __x) -: 130: { return __builtin_atanl(__x); } -: 131:#endif -: 132: -: 133: template -: 134: inline _GLIBCXX_CONSTEXPR -: 135: typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value, -: 136: double>::__type -: 137: atan(_Tp __x) -: 138: { return __builtin_atan(__x); } -: 139: -: 140: using ::atan2; -: 141: -: 142:#ifndef __CORRECT_ISO_CPP_MATH_H_PROTO -: 143: inline _GLIBCXX_CONSTEXPR float -: 144: atan2(float __y, float __x) -: 145: { return __builtin_atan2f(__y, __x); } -: 146: -: 147: inline _GLIBCXX_CONSTEXPR long double -: 148: atan2(long double __y, long double __x) -: 149: { return __builtin_atan2l(__y, __x); } -: 150:#endif -: 151: -: 152: template -: 153: inline _GLIBCXX_CONSTEXPR -: 154: typename __gnu_cxx::__promote_2<_Tp, _Up>::__type -: 155: atan2(_Tp __y, _Up __x) -: 156: { -: 157: typedef typename __gnu_cxx::__promote_2<_Tp, _Up>::__type __type; -: 158: return atan2(__type(__y), __type(__x)); -: 159: } -: 160: -: 161: using ::ceil; -: 162: -: 163:#ifndef __CORRECT_ISO_CPP_MATH_H_PROTO -: 164: inline _GLIBCXX_CONSTEXPR float -: 165: ceil(float __x) -: 166: { return __builtin_ceilf(__x); } -: 167: -: 168: inline _GLIBCXX_CONSTEXPR long double -: 169: ceil(long double __x) -: 170: { return __builtin_ceill(__x); } -: 171:#endif -: 172: -: 173: template -: 174: inline _GLIBCXX_CONSTEXPR -: 175: typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value, -: 176: double>::__type -: 177: ceil(_Tp __x) -: 178: { return __builtin_ceil(__x); } -: 179: -: 180: using ::cos; -: 181: -: 182:#ifndef __CORRECT_ISO_CPP_MATH_H_PROTO -: 183: inline _GLIBCXX_CONSTEXPR float -: 184: cos(float __x) -: 185: { return __builtin_cosf(__x); } -: 186: -: 187: inline _GLIBCXX_CONSTEXPR long double -: 188: cos(long double __x) -: 189: { return __builtin_cosl(__x); } -: 190:#endif -: 191: -: 192: template -: 193: inline _GLIBCXX_CONSTEXPR -: 194: typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value, -: 195: double>::__type -: 196: cos(_Tp __x) -: 197: { return __builtin_cos(__x); } -: 198: -: 199: using ::cosh; -: 200: -: 201:#ifndef __CORRECT_ISO_CPP_MATH_H_PROTO -: 202: inline _GLIBCXX_CONSTEXPR float -: 203: cosh(float __x) -: 204: { return __builtin_coshf(__x); } -: 205: -: 206: inline _GLIBCXX_CONSTEXPR long double -: 207: cosh(long double __x) -: 208: { return __builtin_coshl(__x); } -: 209:#endif -: 210: -: 211: template -: 212: inline _GLIBCXX_CONSTEXPR -: 213: typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value, -: 214: double>::__type -: 215: cosh(_Tp __x) -: 216: { return __builtin_cosh(__x); } -: 217: -: 218: using ::exp; -: 219: -: 220:#ifndef __CORRECT_ISO_CPP_MATH_H_PROTO -: 221: inline _GLIBCXX_CONSTEXPR float -: 222: exp(float __x) -: 223: { return __builtin_expf(__x); } -: 224: -: 225: inline _GLIBCXX_CONSTEXPR long double -: 226: exp(long double __x) -: 227: { return __builtin_expl(__x); } -: 228:#endif -: 229: -: 230: template -: 231: inline _GLIBCXX_CONSTEXPR -: 232: typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value, -: 233: double>::__type -: 234: exp(_Tp __x) -: 235: { return __builtin_exp(__x); } -: 236: -: 237: using ::fabs; -: 238: -: 239:#ifndef __CORRECT_ISO_CPP_MATH_H_PROTO -: 240: inline _GLIBCXX_CONSTEXPR float -: 241: fabs(float __x) -: 242: { return __builtin_fabsf(__x); } -: 243: -: 244: inline _GLIBCXX_CONSTEXPR long double -: 245: fabs(long double __x) -: 246: { return __builtin_fabsl(__x); } -: 247:#endif -: 248: -: 249: template -: 250: inline _GLIBCXX_CONSTEXPR -: 251: typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value, -: 252: double>::__type -: 253: fabs(_Tp __x) -: 254: { return __builtin_fabs(__x); } -: 255: -: 256: using ::floor; -: 257: -: 258:#ifndef __CORRECT_ISO_CPP_MATH_H_PROTO -: 259: inline _GLIBCXX_CONSTEXPR float -: 260: floor(float __x) -: 261: { return __builtin_floorf(__x); } -: 262: -: 263: inline _GLIBCXX_CONSTEXPR long double -: 264: floor(long double __x) -: 265: { return __builtin_floorl(__x); } -: 266:#endif -: 267: -: 268: template -: 269: inline _GLIBCXX_CONSTEXPR -: 270: typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value, -: 271: double>::__type -: 272: floor(_Tp __x) -: 273: { return __builtin_floor(__x); } -: 274: -: 275: using ::fmod; -: 276: -: 277:#ifndef __CORRECT_ISO_CPP_MATH_H_PROTO -: 278: inline _GLIBCXX_CONSTEXPR float -: 279: fmod(float __x, float __y) -: 280: { return __builtin_fmodf(__x, __y); } -: 281: -: 282: inline _GLIBCXX_CONSTEXPR long double -: 283: fmod(long double __x, long double __y) -: 284: { return __builtin_fmodl(__x, __y); } -: 285:#endif -: 286: -: 287: template -: 288: inline _GLIBCXX_CONSTEXPR -: 289: typename __gnu_cxx::__promote_2<_Tp, _Up>::__type -: 290: fmod(_Tp __x, _Up __y) -: 291: { -: 292: typedef typename __gnu_cxx::__promote_2<_Tp, _Up>::__type __type; -: 293: return fmod(__type(__x), __type(__y)); -: 294: } -: 295: -: 296: using ::frexp; -: 297: -: 298:#ifndef __CORRECT_ISO_CPP_MATH_H_PROTO -: 299: inline float -: 300: frexp(float __x, int* __exp) -: 301: { return __builtin_frexpf(__x, __exp); } -: 302: -: 303: inline long double -: 304: frexp(long double __x, int* __exp) -: 305: { return __builtin_frexpl(__x, __exp); } -: 306:#endif -: 307: -: 308: template -: 309: inline _GLIBCXX_CONSTEXPR -: 310: typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value, -: 311: double>::__type -: 312: frexp(_Tp __x, int* __exp) -: 313: { return __builtin_frexp(__x, __exp); } -: 314: -: 315: using ::ldexp; -: 316: -: 317:#ifndef __CORRECT_ISO_CPP_MATH_H_PROTO -: 318: inline _GLIBCXX_CONSTEXPR float -: 319: ldexp(float __x, int __exp) -: 320: { return __builtin_ldexpf(__x, __exp); } -: 321: -: 322: inline _GLIBCXX_CONSTEXPR long double -: 323: ldexp(long double __x, int __exp) -: 324: { return __builtin_ldexpl(__x, __exp); } -: 325:#endif -: 326: -: 327: template -: 328: inline _GLIBCXX_CONSTEXPR -: 329: typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value, -: 330: double>::__type -: 331: ldexp(_Tp __x, int __exp) -: 332: { return __builtin_ldexp(__x, __exp); } -: 333: -: 334: using ::log; -: 335: -: 336:#ifndef __CORRECT_ISO_CPP_MATH_H_PROTO -: 337: inline _GLIBCXX_CONSTEXPR float -: 338: log(float __x) -: 339: { return __builtin_logf(__x); } -: 340: -: 341: inline _GLIBCXX_CONSTEXPR long double 10: 342: log(long double __x) 10: 343: { return __builtin_logl(__x); } -: 344:#endif -: 345: -: 346: template -: 347: inline _GLIBCXX_CONSTEXPR -: 348: typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value, -: 349: double>::__type -: 350: log(_Tp __x) -: 351: { return __builtin_log(__x); } -: 352: -: 353: using ::log10; -: 354: -: 355:#ifndef __CORRECT_ISO_CPP_MATH_H_PROTO -: 356: inline _GLIBCXX_CONSTEXPR float -: 357: log10(float __x) -: 358: { return __builtin_log10f(__x); } -: 359: -: 360: inline _GLIBCXX_CONSTEXPR long double -: 361: log10(long double __x) -: 362: { return __builtin_log10l(__x); } -: 363:#endif -: 364: -: 365: template -: 366: inline _GLIBCXX_CONSTEXPR -: 367: typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value, -: 368: double>::__type -: 369: log10(_Tp __x) -: 370: { return __builtin_log10(__x); } -: 371: -: 372: using ::modf; -: 373: -: 374:#ifndef __CORRECT_ISO_CPP_MATH_H_PROTO -: 375: inline float -: 376: modf(float __x, float* __iptr) -: 377: { return __builtin_modff(__x, __iptr); } -: 378: -: 379: inline long double -: 380: modf(long double __x, long double* __iptr) -: 381: { return __builtin_modfl(__x, __iptr); } -: 382:#endif -: 383: -: 384: using ::pow; -: 385: -: 386:#ifndef __CORRECT_ISO_CPP_MATH_H_PROTO -: 387: inline _GLIBCXX_CONSTEXPR float -: 388: pow(float __x, float __y) -: 389: { return __builtin_powf(__x, __y); } -: 390: -: 391: inline _GLIBCXX_CONSTEXPR long double -: 392: pow(long double __x, long double __y) -: 393: { return __builtin_powl(__x, __y); } -: 394: -: 395:#if __cplusplus < 201103L -: 396: // _GLIBCXX_RESOLVE_LIB_DEFECTS -: 397: // DR 550. What should the return type of pow(float,int) be? -: 398: inline double -: 399: pow(double __x, int __i) -: 400: { return __builtin_powi(__x, __i); } -: 401: -: 402: inline float -: 403: pow(float __x, int __n) -: 404: { return __builtin_powif(__x, __n); } -: 405: -: 406: inline long double -: 407: pow(long double __x, int __n) -: 408: { return __builtin_powil(__x, __n); } -: 409:#endif -: 410:#endif -: 411: -: 412: template -: 413: inline _GLIBCXX_CONSTEXPR -: 414: typename __gnu_cxx::__promote_2<_Tp, _Up>::__type -: 415: pow(_Tp __x, _Up __y) -: 416: { -: 417: typedef typename __gnu_cxx::__promote_2<_Tp, _Up>::__type __type; -: 418: return pow(__type(__x), __type(__y)); -: 419: } -: 420: -: 421: using ::sin; -: 422: -: 423:#ifndef __CORRECT_ISO_CPP_MATH_H_PROTO -: 424: inline _GLIBCXX_CONSTEXPR float -: 425: sin(float __x) -: 426: { return __builtin_sinf(__x); } -: 427: -: 428: inline _GLIBCXX_CONSTEXPR long double -: 429: sin(long double __x) -: 430: { return __builtin_sinl(__x); } -: 431:#endif -: 432: -: 433: template -: 434: inline _GLIBCXX_CONSTEXPR -: 435: typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value, -: 436: double>::__type -: 437: sin(_Tp __x) -: 438: { return __builtin_sin(__x); } -: 439: -: 440: using ::sinh; -: 441: -: 442:#ifndef __CORRECT_ISO_CPP_MATH_H_PROTO -: 443: inline _GLIBCXX_CONSTEXPR float -: 444: sinh(float __x) -: 445: { return __builtin_sinhf(__x); } -: 446: -: 447: inline _GLIBCXX_CONSTEXPR long double -: 448: sinh(long double __x) -: 449: { return __builtin_sinhl(__x); } -: 450:#endif -: 451: -: 452: template -: 453: inline _GLIBCXX_CONSTEXPR -: 454: typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value, -: 455: double>::__type -: 456: sinh(_Tp __x) -: 457: { return __builtin_sinh(__x); } -: 458: -: 459: using ::sqrt; -: 460: -: 461:#ifndef __CORRECT_ISO_CPP_MATH_H_PROTO -: 462: inline _GLIBCXX_CONSTEXPR float -: 463: sqrt(float __x) -: 464: { return __builtin_sqrtf(__x); } -: 465: -: 466: inline _GLIBCXX_CONSTEXPR long double -: 467: sqrt(long double __x) -: 468: { return __builtin_sqrtl(__x); } -: 469:#endif -: 470: -: 471: template -: 472: inline _GLIBCXX_CONSTEXPR -: 473: typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value, -: 474: double>::__type -: 475: sqrt(_Tp __x) -: 476: { return __builtin_sqrt(__x); } -: 477: -: 478: using ::tan; -: 479: -: 480:#ifndef __CORRECT_ISO_CPP_MATH_H_PROTO -: 481: inline _GLIBCXX_CONSTEXPR float -: 482: tan(float __x) -: 483: { return __builtin_tanf(__x); } -: 484: -: 485: inline _GLIBCXX_CONSTEXPR long double -: 486: tan(long double __x) -: 487: { return __builtin_tanl(__x); } -: 488:#endif -: 489: -: 490: template -: 491: inline _GLIBCXX_CONSTEXPR -: 492: typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value, -: 493: double>::__type -: 494: tan(_Tp __x) -: 495: { return __builtin_tan(__x); } -: 496: -: 497: using ::tanh; -: 498: -: 499:#ifndef __CORRECT_ISO_CPP_MATH_H_PROTO -: 500: inline _GLIBCXX_CONSTEXPR float -: 501: tanh(float __x) -: 502: { return __builtin_tanhf(__x); } -: 503: -: 504: inline _GLIBCXX_CONSTEXPR long double -: 505: tanh(long double __x) -: 506: { return __builtin_tanhl(__x); } -: 507:#endif -: 508: -: 509: template -: 510: inline _GLIBCXX_CONSTEXPR -: 511: typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value, -: 512: double>::__type -: 513: tanh(_Tp __x) -: 514: { return __builtin_tanh(__x); } -: 515: -: 516:#if _GLIBCXX_USE_C99_MATH -: 517:#if !_GLIBCXX_USE_C99_FP_MACROS_DYNAMIC -: 518: -: 519:// These are possible macros imported from C99-land. -: 520:#undef fpclassify -: 521:#undef isfinite -: 522:#undef isinf -: 523:#undef isnan -: 524:#undef isnormal -: 525:#undef signbit -: 526:#undef isgreater -: 527:#undef isgreaterequal -: 528:#undef isless -: 529:#undef islessequal -: 530:#undef islessgreater -: 531:#undef isunordered -: 532: -: 533:#if __cplusplus >= 201103L -: 534: -: 535:#ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO_FP -: 536: constexpr int -: 537: fpclassify(float __x) -: 538: { return __builtin_fpclassify(FP_NAN, FP_INFINITE, FP_NORMAL, -: 539: FP_SUBNORMAL, FP_ZERO, __x); } -: 540: -: 541: constexpr int -: 542: fpclassify(double __x) -: 543: { return __builtin_fpclassify(FP_NAN, FP_INFINITE, FP_NORMAL, -: 544: FP_SUBNORMAL, FP_ZERO, __x); } -: 545: -: 546: constexpr int -: 547: fpclassify(long double __x) -: 548: { return __builtin_fpclassify(FP_NAN, FP_INFINITE, FP_NORMAL, -: 549: FP_SUBNORMAL, FP_ZERO, __x); } -: 550:#endif -: 551: -: 552:#ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO_INT -: 553: template -: 554: constexpr typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value, -: 555: int>::__type -: 556: fpclassify(_Tp __x) -: 557: { return __x != 0 ? FP_NORMAL : FP_ZERO; } -: 558:#endif -: 559: -: 560:#ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO_FP -: 561: constexpr bool -: 562: isfinite(float __x) -: 563: { return __builtin_isfinite(__x); } -: 564: -: 565: constexpr bool -: 566: isfinite(double __x) -: 567: { return __builtin_isfinite(__x); } -: 568: -: 569: constexpr bool -: 570: isfinite(long double __x) -: 571: { return __builtin_isfinite(__x); } -: 572:#endif -: 573: -: 574:#ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO_INT -: 575: template -: 576: constexpr typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value, -: 577: bool>::__type -: 578: isfinite(_Tp __x) -: 579: { return true; } -: 580:#endif -: 581: -: 582:#ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO_FP -: 583: constexpr bool -: 584: isinf(float __x) -: 585: { return __builtin_isinf(__x); } -: 586: -: 587:#if _GLIBCXX_HAVE_OBSOLETE_ISINF \ -: 588: && !_GLIBCXX_NO_OBSOLETE_ISINF_ISNAN_DYNAMIC -: 589: using ::isinf; -: 590:#else -: 591: constexpr bool -: 592: isinf(double __x) -: 593: { return __builtin_isinf(__x); } -: 594:#endif -: 595: -: 596: constexpr bool 18: 597: isinf(long double __x) 18: 598: { return __builtin_isinf(__x); } -: 599:#endif -: 600: -: 601:#ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO_INT -: 602: template -: 603: constexpr typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value, -: 604: bool>::__type -: 605: isinf(_Tp __x) -: 606: { return false; } -: 607:#endif -: 608: -: 609:#ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO_FP -: 610: constexpr bool -: 611: isnan(float __x) -: 612: { return __builtin_isnan(__x); } -: 613: -: 614:#if _GLIBCXX_HAVE_OBSOLETE_ISNAN \ -: 615: && !_GLIBCXX_NO_OBSOLETE_ISINF_ISNAN_DYNAMIC -: 616: using ::isnan; -: 617:#else -: 618: constexpr bool -: 619: isnan(double __x) -: 620: { return __builtin_isnan(__x); } -: 621:#endif -: 622: -: 623: constexpr bool 72: 624: isnan(long double __x) 72: 625: { return __builtin_isnan(__x); } -: 626:#endif -: 627: -: 628:#ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO_INT -: 629: template -: 630: constexpr typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value, -: 631: bool>::__type -: 632: isnan(_Tp __x) -: 633: { return false; } -: 634:#endif -: 635: -: 636:#ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO_FP -: 637: constexpr bool -: 638: isnormal(float __x) -: 639: { return __builtin_isnormal(__x); } -: 640: -: 641: constexpr bool -: 642: isnormal(double __x) -: 643: { return __builtin_isnormal(__x); } -: 644: -: 645: constexpr bool -: 646: isnormal(long double __x) -: 647: { return __builtin_isnormal(__x); } -: 648:#endif -: 649: -: 650:#ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO_INT -: 651: template -: 652: constexpr typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value, -: 653: bool>::__type -: 654: isnormal(_Tp __x) -: 655: { return __x != 0 ? true : false; } -: 656:#endif -: 657: -: 658:#ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO_FP -: 659: // Note: middle-end/36757 is fixed, __builtin_signbit is type-generic. -: 660: constexpr bool -: 661: signbit(float __x) -: 662: { return __builtin_signbit(__x); } -: 663: -: 664: constexpr bool -: 665: signbit(double __x) -: 666: { return __builtin_signbit(__x); } -: 667: -: 668: constexpr bool -: 669: signbit(long double __x) -: 670: { return __builtin_signbit(__x); } -: 671:#endif -: 672: -: 673:#ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO_INT -: 674: template -: 675: constexpr typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value, -: 676: bool>::__type -: 677: signbit(_Tp __x) -: 678: { return __x < 0 ? true : false; } -: 679:#endif -: 680: -: 681:#ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO_FP -: 682: constexpr bool -: 683: isgreater(float __x, float __y) -: 684: { return __builtin_isgreater(__x, __y); } -: 685: -: 686: constexpr bool -: 687: isgreater(double __x, double __y) -: 688: { return __builtin_isgreater(__x, __y); } -: 689: -: 690: constexpr bool -: 691: isgreater(long double __x, long double __y) -: 692: { return __builtin_isgreater(__x, __y); } -: 693:#endif -: 694: -: 695:#ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO_INT -: 696: template -: 697: constexpr typename -: 698: __gnu_cxx::__enable_if<(__is_arithmetic<_Tp>::__value -: 699: && __is_arithmetic<_Up>::__value), bool>::__type -: 700: isgreater(_Tp __x, _Up __y) -: 701: { -: 702: typedef typename __gnu_cxx::__promote_2<_Tp, _Up>::__type __type; -: 703: return __builtin_isgreater(__type(__x), __type(__y)); -: 704: } -: 705:#endif -: 706: -: 707:#ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO_FP -: 708: constexpr bool -: 709: isgreaterequal(float __x, float __y) -: 710: { return __builtin_isgreaterequal(__x, __y); } -: 711: -: 712: constexpr bool -: 713: isgreaterequal(double __x, double __y) -: 714: { return __builtin_isgreaterequal(__x, __y); } -: 715: -: 716: constexpr bool -: 717: isgreaterequal(long double __x, long double __y) -: 718: { return __builtin_isgreaterequal(__x, __y); } -: 719:#endif -: 720: -: 721:#ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO_INT -: 722: template -: 723: constexpr typename -: 724: __gnu_cxx::__enable_if<(__is_arithmetic<_Tp>::__value -: 725: && __is_arithmetic<_Up>::__value), bool>::__type -: 726: isgreaterequal(_Tp __x, _Up __y) -: 727: { -: 728: typedef typename __gnu_cxx::__promote_2<_Tp, _Up>::__type __type; -: 729: return __builtin_isgreaterequal(__type(__x), __type(__y)); -: 730: } -: 731:#endif -: 732: -: 733:#ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO_FP -: 734: constexpr bool -: 735: isless(float __x, float __y) -: 736: { return __builtin_isless(__x, __y); } -: 737: -: 738: constexpr bool -: 739: isless(double __x, double __y) -: 740: { return __builtin_isless(__x, __y); } -: 741: -: 742: constexpr bool -: 743: isless(long double __x, long double __y) -: 744: { return __builtin_isless(__x, __y); } -: 745:#endif -: 746: -: 747:#ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO_INT -: 748: template -: 749: constexpr typename -: 750: __gnu_cxx::__enable_if<(__is_arithmetic<_Tp>::__value -: 751: && __is_arithmetic<_Up>::__value), bool>::__type -: 752: isless(_Tp __x, _Up __y) -: 753: { -: 754: typedef typename __gnu_cxx::__promote_2<_Tp, _Up>::__type __type; -: 755: return __builtin_isless(__type(__x), __type(__y)); -: 756: } -: 757:#endif -: 758: -: 759:#ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO_FP -: 760: constexpr bool -: 761: islessequal(float __x, float __y) -: 762: { return __builtin_islessequal(__x, __y); } -: 763: -: 764: constexpr bool -: 765: islessequal(double __x, double __y) -: 766: { return __builtin_islessequal(__x, __y); } -: 767: -: 768: constexpr bool -: 769: islessequal(long double __x, long double __y) -: 770: { return __builtin_islessequal(__x, __y); } -: 771:#endif -: 772: -: 773:#ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO_INT -: 774: template -: 775: constexpr typename -: 776: __gnu_cxx::__enable_if<(__is_arithmetic<_Tp>::__value -: 777: && __is_arithmetic<_Up>::__value), bool>::__type -: 778: islessequal(_Tp __x, _Up __y) -: 779: { -: 780: typedef typename __gnu_cxx::__promote_2<_Tp, _Up>::__type __type; -: 781: return __builtin_islessequal(__type(__x), __type(__y)); -: 782: } -: 783:#endif -: 784: -: 785:#ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO_FP -: 786: constexpr bool -: 787: islessgreater(float __x, float __y) -: 788: { return __builtin_islessgreater(__x, __y); } -: 789: -: 790: constexpr bool -: 791: islessgreater(double __x, double __y) -: 792: { return __builtin_islessgreater(__x, __y); } -: 793: -: 794: constexpr bool -: 795: islessgreater(long double __x, long double __y) -: 796: { return __builtin_islessgreater(__x, __y); } -: 797:#endif -: 798: -: 799:#ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO_INT -: 800: template -: 801: constexpr typename -: 802: __gnu_cxx::__enable_if<(__is_arithmetic<_Tp>::__value -: 803: && __is_arithmetic<_Up>::__value), bool>::__type -: 804: islessgreater(_Tp __x, _Up __y) -: 805: { -: 806: typedef typename __gnu_cxx::__promote_2<_Tp, _Up>::__type __type; -: 807: return __builtin_islessgreater(__type(__x), __type(__y)); -: 808: } -: 809:#endif -: 810: -: 811:#ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO_FP -: 812: constexpr bool -: 813: isunordered(float __x, float __y) -: 814: { return __builtin_isunordered(__x, __y); } -: 815: -: 816: constexpr bool -: 817: isunordered(double __x, double __y) -: 818: { return __builtin_isunordered(__x, __y); } -: 819: -: 820: constexpr bool -: 821: isunordered(long double __x, long double __y) -: 822: { return __builtin_isunordered(__x, __y); } -: 823:#endif -: 824: -: 825:#ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO_INT -: 826: template -: 827: constexpr typename -: 828: __gnu_cxx::__enable_if<(__is_arithmetic<_Tp>::__value -: 829: && __is_arithmetic<_Up>::__value), bool>::__type -: 830: isunordered(_Tp __x, _Up __y) -: 831: { -: 832: typedef typename __gnu_cxx::__promote_2<_Tp, _Up>::__type __type; -: 833: return __builtin_isunordered(__type(__x), __type(__y)); -: 834: } -: 835:#endif -: 836: -: 837:#else -: 838: -: 839: template -: 840: inline typename __gnu_cxx::__enable_if<__is_arithmetic<_Tp>::__value, -: 841: int>::__type -: 842: fpclassify(_Tp __f) -: 843: { -: 844: typedef typename __gnu_cxx::__promote<_Tp>::__type __type; -: 845: return __builtin_fpclassify(FP_NAN, FP_INFINITE, FP_NORMAL, -: 846: FP_SUBNORMAL, FP_ZERO, __type(__f)); -: 847: } -: 848: -: 849: template -: 850: inline typename __gnu_cxx::__enable_if<__is_arithmetic<_Tp>::__value, -: 851: int>::__type -: 852: isfinite(_Tp __f) -: 853: { -: 854: typedef typename __gnu_cxx::__promote<_Tp>::__type __type; -: 855: return __builtin_isfinite(__type(__f)); -: 856: } -: 857: -: 858: template -: 859: inline typename __gnu_cxx::__enable_if<__is_arithmetic<_Tp>::__value, -: 860: int>::__type -: 861: isinf(_Tp __f) -: 862: { -: 863: typedef typename __gnu_cxx::__promote<_Tp>::__type __type; -: 864: return __builtin_isinf(__type(__f)); -: 865: } -: 866: -: 867: template -: 868: inline typename __gnu_cxx::__enable_if<__is_arithmetic<_Tp>::__value, -: 869: int>::__type -: 870: isnan(_Tp __f) -: 871: { -: 872: typedef typename __gnu_cxx::__promote<_Tp>::__type __type; -: 873: return __builtin_isnan(__type(__f)); -: 874: } -: 875: -: 876: template -: 877: inline typename __gnu_cxx::__enable_if<__is_arithmetic<_Tp>::__value, -: 878: int>::__type -: 879: isnormal(_Tp __f) -: 880: { -: 881: typedef typename __gnu_cxx::__promote<_Tp>::__type __type; -: 882: return __builtin_isnormal(__type(__f)); -: 883: } -: 884: -: 885: template -: 886: inline typename __gnu_cxx::__enable_if<__is_arithmetic<_Tp>::__value, -: 887: int>::__type -: 888: signbit(_Tp __f) -: 889: { -: 890: typedef typename __gnu_cxx::__promote<_Tp>::__type __type; -: 891: return __builtin_signbit(__type(__f)); -: 892: } -: 893: -: 894: template -: 895: inline typename __gnu_cxx::__enable_if<__is_arithmetic<_Tp>::__value, -: 896: int>::__type -: 897: isgreater(_Tp __f1, _Tp __f2) -: 898: { -: 899: typedef typename __gnu_cxx::__promote<_Tp>::__type __type; -: 900: return __builtin_isgreater(__type(__f1), __type(__f2)); -: 901: } -: 902: -: 903: template -: 904: inline typename __gnu_cxx::__enable_if<__is_arithmetic<_Tp>::__value, -: 905: int>::__type -: 906: isgreaterequal(_Tp __f1, _Tp __f2) -: 907: { -: 908: typedef typename __gnu_cxx::__promote<_Tp>::__type __type; -: 909: return __builtin_isgreaterequal(__type(__f1), __type(__f2)); -: 910: } -: 911: -: 912: template -: 913: inline typename __gnu_cxx::__enable_if<__is_arithmetic<_Tp>::__value, -: 914: int>::__type -: 915: isless(_Tp __f1, _Tp __f2) -: 916: { -: 917: typedef typename __gnu_cxx::__promote<_Tp>::__type __type; -: 918: return __builtin_isless(__type(__f1), __type(__f2)); -: 919: } -: 920: -: 921: template -: 922: inline typename __gnu_cxx::__enable_if<__is_arithmetic<_Tp>::__value, -: 923: int>::__type -: 924: islessequal(_Tp __f1, _Tp __f2) -: 925: { -: 926: typedef typename __gnu_cxx::__promote<_Tp>::__type __type; -: 927: return __builtin_islessequal(__type(__f1), __type(__f2)); -: 928: } -: 929: -: 930: template -: 931: inline typename __gnu_cxx::__enable_if<__is_arithmetic<_Tp>::__value, -: 932: int>::__type -: 933: islessgreater(_Tp __f1, _Tp __f2) -: 934: { -: 935: typedef typename __gnu_cxx::__promote<_Tp>::__type __type; -: 936: return __builtin_islessgreater(__type(__f1), __type(__f2)); -: 937: } -: 938: -: 939: template -: 940: inline typename __gnu_cxx::__enable_if<__is_arithmetic<_Tp>::__value, -: 941: int>::__type -: 942: isunordered(_Tp __f1, _Tp __f2) -: 943: { -: 944: typedef typename __gnu_cxx::__promote<_Tp>::__type __type; -: 945: return __builtin_isunordered(__type(__f1), __type(__f2)); -: 946: } -: 947: -: 948:#endif // C++11 -: 949:#endif /* _GLIBCXX_USE_C99_FP_MACROS_DYNAMIC */ -: 950:#endif /* _GLIBCXX_USE_C99_MATH */ -: 951: -: 952:#if __cplusplus >= 201103L -: 953: -: 954:#ifdef _GLIBCXX_USE_C99_MATH_TR1 -: 955: -: 956:#undef acosh -: 957:#undef acoshf -: 958:#undef acoshl -: 959:#undef asinh -: 960:#undef asinhf -: 961:#undef asinhl -: 962:#undef atanh -: 963:#undef atanhf -: 964:#undef atanhl -: 965:#undef cbrt -: 966:#undef cbrtf -: 967:#undef cbrtl -: 968:#undef copysign -: 969:#undef copysignf -: 970:#undef copysignl -: 971:#undef erf -: 972:#undef erff -: 973:#undef erfl -: 974:#undef erfc -: 975:#undef erfcf -: 976:#undef erfcl -: 977:#undef exp2 -: 978:#undef exp2f -: 979:#undef exp2l -: 980:#undef expm1 -: 981:#undef expm1f -: 982:#undef expm1l -: 983:#undef fdim -: 984:#undef fdimf -: 985:#undef fdiml -: 986:#undef fma -: 987:#undef fmaf -: 988:#undef fmal -: 989:#undef fmax -: 990:#undef fmaxf -: 991:#undef fmaxl -: 992:#undef fmin -: 993:#undef fminf -: 994:#undef fminl -: 995:#undef hypot -: 996:#undef hypotf -: 997:#undef hypotl -: 998:#undef ilogb -: 999:#undef ilogbf -: 1000:#undef ilogbl -: 1001:#undef lgamma -: 1002:#undef lgammaf -: 1003:#undef lgammal -: 1004:#ifndef _GLIBCXX_NO_C99_ROUNDING_FUNCS -: 1005:#undef llrint -: 1006:#undef llrintf -: 1007:#undef llrintl -: 1008:#undef llround -: 1009:#undef llroundf -: 1010:#undef llroundl -: 1011:#endif -: 1012:#undef log1p -: 1013:#undef log1pf -: 1014:#undef log1pl -: 1015:#undef log2 -: 1016:#undef log2f -: 1017:#undef log2l -: 1018:#undef logb -: 1019:#undef logbf -: 1020:#undef logbl -: 1021:#undef lrint -: 1022:#undef lrintf -: 1023:#undef lrintl -: 1024:#undef lround -: 1025:#undef lroundf -: 1026:#undef lroundl -: 1027:#undef nan -: 1028:#undef nanf -: 1029:#undef nanl -: 1030:#undef nearbyint -: 1031:#undef nearbyintf -: 1032:#undef nearbyintl -: 1033:#undef nextafter -: 1034:#undef nextafterf -: 1035:#undef nextafterl -: 1036:#undef nexttoward -: 1037:#undef nexttowardf -: 1038:#undef nexttowardl -: 1039:#undef remainder -: 1040:#undef remainderf -: 1041:#undef remainderl -: 1042:#undef remquo -: 1043:#undef remquof -: 1044:#undef remquol -: 1045:#undef rint -: 1046:#undef rintf -: 1047:#undef rintl -: 1048:#undef round -: 1049:#undef roundf -: 1050:#undef roundl -: 1051:#undef scalbln -: 1052:#undef scalblnf -: 1053:#undef scalblnl -: 1054:#undef scalbn -: 1055:#undef scalbnf -: 1056:#undef scalbnl -: 1057:#undef tgamma -: 1058:#undef tgammaf -: 1059:#undef tgammal -: 1060:#undef trunc -: 1061:#undef truncf -: 1062:#undef truncl -: 1063: -: 1064: // types -: 1065: using ::double_t; -: 1066: using ::float_t; -: 1067: -: 1068: // functions -: 1069: using ::acosh; -: 1070: using ::acoshf; -: 1071: using ::acoshl; -: 1072: -: 1073: using ::asinh; -: 1074: using ::asinhf; -: 1075: using ::asinhl; -: 1076: -: 1077: using ::atanh; -: 1078: using ::atanhf; -: 1079: using ::atanhl; -: 1080: -: 1081: using ::cbrt; -: 1082: using ::cbrtf; -: 1083: using ::cbrtl; -: 1084: -: 1085: using ::copysign; -: 1086: using ::copysignf; -: 1087: using ::copysignl; -: 1088: -: 1089: using ::erf; -: 1090: using ::erff; -: 1091: using ::erfl; -: 1092: -: 1093: using ::erfc; -: 1094: using ::erfcf; -: 1095: using ::erfcl; -: 1096: -: 1097: using ::exp2; -: 1098: using ::exp2f; -: 1099: using ::exp2l; -: 1100: -: 1101: using ::expm1; -: 1102: using ::expm1f; -: 1103: using ::expm1l; -: 1104: -: 1105: using ::fdim; -: 1106: using ::fdimf; -: 1107: using ::fdiml; -: 1108: -: 1109: using ::fma; -: 1110: using ::fmaf; -: 1111: using ::fmal; -: 1112: -: 1113: using ::fmax; -: 1114: using ::fmaxf; -: 1115: using ::fmaxl; -: 1116: -: 1117: using ::fmin; -: 1118: using ::fminf; -: 1119: using ::fminl; -: 1120: -: 1121: using ::hypot; -: 1122: using ::hypotf; -: 1123: using ::hypotl; -: 1124: -: 1125: using ::ilogb; -: 1126: using ::ilogbf; -: 1127: using ::ilogbl; -: 1128: -: 1129: using ::lgamma; -: 1130: using ::lgammaf; -: 1131: using ::lgammal; -: 1132: -: 1133:#ifndef _GLIBCXX_NO_C99_ROUNDING_FUNCS -: 1134: using ::llrint; -: 1135: using ::llrintf; -: 1136: using ::llrintl; -: 1137: -: 1138: using ::llround; -: 1139: using ::llroundf; -: 1140: using ::llroundl; -: 1141:#endif -: 1142: -: 1143: using ::log1p; -: 1144: using ::log1pf; -: 1145: using ::log1pl; -: 1146: -: 1147: using ::log2; -: 1148: using ::log2f; -: 1149: using ::log2l; -: 1150: -: 1151: using ::logb; -: 1152: using ::logbf; -: 1153: using ::logbl; -: 1154: -: 1155: using ::lrint; -: 1156: using ::lrintf; -: 1157: using ::lrintl; -: 1158: -: 1159: using ::lround; -: 1160: using ::lroundf; -: 1161: using ::lroundl; -: 1162: -: 1163: using ::nan; -: 1164: using ::nanf; -: 1165: using ::nanl; -: 1166: -: 1167: using ::nearbyint; -: 1168: using ::nearbyintf; -: 1169: using ::nearbyintl; -: 1170: -: 1171: using ::nextafter; -: 1172: using ::nextafterf; -: 1173: using ::nextafterl; -: 1174: -: 1175: using ::nexttoward; -: 1176: using ::nexttowardf; -: 1177: using ::nexttowardl; -: 1178: -: 1179: using ::remainder; -: 1180: using ::remainderf; -: 1181: using ::remainderl; -: 1182: -: 1183: using ::remquo; -: 1184: using ::remquof; -: 1185: using ::remquol; -: 1186: -: 1187: using ::rint; -: 1188: using ::rintf; -: 1189: using ::rintl; -: 1190: -: 1191: using ::round; -: 1192: using ::roundf; -: 1193: using ::roundl; -: 1194: -: 1195: using ::scalbln; -: 1196: using ::scalblnf; -: 1197: using ::scalblnl; -: 1198: -: 1199: using ::scalbn; -: 1200: using ::scalbnf; -: 1201: using ::scalbnl; -: 1202: -: 1203: using ::tgamma; -: 1204: using ::tgammaf; -: 1205: using ::tgammal; -: 1206: -: 1207: using ::trunc; -: 1208: using ::truncf; -: 1209: using ::truncl; -: 1210: -: 1211: /// Additional overloads. -: 1212:#ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO_FP -: 1213: constexpr float -: 1214: acosh(float __x) -: 1215: { return __builtin_acoshf(__x); } -: 1216: -: 1217: constexpr long double -: 1218: acosh(long double __x) -: 1219: { return __builtin_acoshl(__x); } -: 1220:#endif -: 1221: -: 1222:#ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO_INT -: 1223: template -: 1224: constexpr typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value, -: 1225: double>::__type -: 1226: acosh(_Tp __x) -: 1227: { return __builtin_acosh(__x); } -: 1228:#endif -: 1229: -: 1230:#ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO_FP -: 1231: constexpr float -: 1232: asinh(float __x) -: 1233: { return __builtin_asinhf(__x); } -: 1234: -: 1235: constexpr long double -: 1236: asinh(long double __x) -: 1237: { return __builtin_asinhl(__x); } -: 1238:#endif -: 1239: -: 1240:#ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO_INT -: 1241: template -: 1242: constexpr typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value, -: 1243: double>::__type -: 1244: asinh(_Tp __x) -: 1245: { return __builtin_asinh(__x); } -: 1246:#endif -: 1247: -: 1248:#ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO_FP -: 1249: constexpr float -: 1250: atanh(float __x) -: 1251: { return __builtin_atanhf(__x); } -: 1252: -: 1253: constexpr long double -: 1254: atanh(long double __x) -: 1255: { return __builtin_atanhl(__x); } -: 1256:#endif -: 1257: -: 1258:#ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO_INT -: 1259: template -: 1260: constexpr typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value, -: 1261: double>::__type -: 1262: atanh(_Tp __x) -: 1263: { return __builtin_atanh(__x); } -: 1264:#endif -: 1265: -: 1266:#ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO_FP -: 1267: constexpr float -: 1268: cbrt(float __x) -: 1269: { return __builtin_cbrtf(__x); } -: 1270: -: 1271: constexpr long double -: 1272: cbrt(long double __x) -: 1273: { return __builtin_cbrtl(__x); } -: 1274:#endif -: 1275: -: 1276:#ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO_INT -: 1277: template -: 1278: constexpr typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value, -: 1279: double>::__type -: 1280: cbrt(_Tp __x) -: 1281: { return __builtin_cbrt(__x); } -: 1282:#endif -: 1283: -: 1284:#ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO_FP -: 1285: constexpr float -: 1286: copysign(float __x, float __y) -: 1287: { return __builtin_copysignf(__x, __y); } -: 1288: -: 1289: constexpr long double -: 1290: copysign(long double __x, long double __y) -: 1291: { return __builtin_copysignl(__x, __y); } -: 1292:#endif -: 1293: -: 1294:#ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO_INT -: 1295: template -: 1296: constexpr typename __gnu_cxx::__promote_2<_Tp, _Up>::__type -: 1297: copysign(_Tp __x, _Up __y) -: 1298: { -: 1299: typedef typename __gnu_cxx::__promote_2<_Tp, _Up>::__type __type; -: 1300: return copysign(__type(__x), __type(__y)); -: 1301: } -: 1302:#endif -: 1303: -: 1304:#ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO_FP -: 1305: constexpr float -: 1306: erf(float __x) -: 1307: { return __builtin_erff(__x); } -: 1308: -: 1309: constexpr long double -: 1310: erf(long double __x) -: 1311: { return __builtin_erfl(__x); } -: 1312:#endif -: 1313: -: 1314:#ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO_INT -: 1315: template -: 1316: constexpr typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value, -: 1317: double>::__type -: 1318: erf(_Tp __x) -: 1319: { return __builtin_erf(__x); } -: 1320:#endif -: 1321: -: 1322:#ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO_FP -: 1323: constexpr float -: 1324: erfc(float __x) -: 1325: { return __builtin_erfcf(__x); } -: 1326: -: 1327: constexpr long double -: 1328: erfc(long double __x) -: 1329: { return __builtin_erfcl(__x); } -: 1330:#endif -: 1331: -: 1332:#ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO_INT -: 1333: template -: 1334: constexpr typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value, -: 1335: double>::__type -: 1336: erfc(_Tp __x) -: 1337: { return __builtin_erfc(__x); } -: 1338:#endif -: 1339: -: 1340:#ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO_FP -: 1341: constexpr float -: 1342: exp2(float __x) -: 1343: { return __builtin_exp2f(__x); } -: 1344: -: 1345: constexpr long double -: 1346: exp2(long double __x) -: 1347: { return __builtin_exp2l(__x); } -: 1348:#endif -: 1349: -: 1350:#ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO_INT -: 1351: template -: 1352: constexpr typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value, -: 1353: double>::__type -: 1354: exp2(_Tp __x) -: 1355: { return __builtin_exp2(__x); } -: 1356:#endif -: 1357: -: 1358:#ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO_FP -: 1359: constexpr float -: 1360: expm1(float __x) -: 1361: { return __builtin_expm1f(__x); } -: 1362: -: 1363: constexpr long double -: 1364: expm1(long double __x) -: 1365: { return __builtin_expm1l(__x); } -: 1366:#endif -: 1367: -: 1368:#ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO_INT -: 1369: template -: 1370: constexpr typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value, -: 1371: double>::__type -: 1372: expm1(_Tp __x) -: 1373: { return __builtin_expm1(__x); } -: 1374:#endif -: 1375: -: 1376:#ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO_FP -: 1377: constexpr float -: 1378: fdim(float __x, float __y) -: 1379: { return __builtin_fdimf(__x, __y); } -: 1380: -: 1381: constexpr long double -: 1382: fdim(long double __x, long double __y) -: 1383: { return __builtin_fdiml(__x, __y); } -: 1384:#endif -: 1385: -: 1386:#ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO_INT -: 1387: template -: 1388: constexpr typename __gnu_cxx::__promote_2<_Tp, _Up>::__type -: 1389: fdim(_Tp __x, _Up __y) -: 1390: { -: 1391: typedef typename __gnu_cxx::__promote_2<_Tp, _Up>::__type __type; -: 1392: return fdim(__type(__x), __type(__y)); -: 1393: } -: 1394:#endif -: 1395: -: 1396:#ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO_FP -: 1397: constexpr float -: 1398: fma(float __x, float __y, float __z) -: 1399: { return __builtin_fmaf(__x, __y, __z); } -: 1400: -: 1401: constexpr long double -: 1402: fma(long double __x, long double __y, long double __z) -: 1403: { return __builtin_fmal(__x, __y, __z); } -: 1404:#endif -: 1405: -: 1406:#ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO_INT -: 1407: template -: 1408: constexpr typename __gnu_cxx::__promote_3<_Tp, _Up, _Vp>::__type -: 1409: fma(_Tp __x, _Up __y, _Vp __z) -: 1410: { -: 1411: typedef typename __gnu_cxx::__promote_3<_Tp, _Up, _Vp>::__type __type; -: 1412: return fma(__type(__x), __type(__y), __type(__z)); -: 1413: } -: 1414:#endif -: 1415: -: 1416:#ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO_FP -: 1417: constexpr float -: 1418: fmax(float __x, float __y) -: 1419: { return __builtin_fmaxf(__x, __y); } -: 1420: -: 1421: constexpr long double -: 1422: fmax(long double __x, long double __y) -: 1423: { return __builtin_fmaxl(__x, __y); } -: 1424:#endif -: 1425: -: 1426:#ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO_INT -: 1427: template -: 1428: constexpr typename __gnu_cxx::__promote_2<_Tp, _Up>::__type -: 1429: fmax(_Tp __x, _Up __y) -: 1430: { -: 1431: typedef typename __gnu_cxx::__promote_2<_Tp, _Up>::__type __type; -: 1432: return fmax(__type(__x), __type(__y)); -: 1433: } -: 1434:#endif -: 1435: -: 1436:#ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO_FP -: 1437: constexpr float -: 1438: fmin(float __x, float __y) -: 1439: { return __builtin_fminf(__x, __y); } -: 1440: -: 1441: constexpr long double -: 1442: fmin(long double __x, long double __y) -: 1443: { return __builtin_fminl(__x, __y); } -: 1444:#endif -: 1445: -: 1446:#ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO_INT -: 1447: template -: 1448: constexpr typename __gnu_cxx::__promote_2<_Tp, _Up>::__type -: 1449: fmin(_Tp __x, _Up __y) -: 1450: { -: 1451: typedef typename __gnu_cxx::__promote_2<_Tp, _Up>::__type __type; -: 1452: return fmin(__type(__x), __type(__y)); -: 1453: } -: 1454:#endif -: 1455: -: 1456:#ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO_FP -: 1457: constexpr float -: 1458: hypot(float __x, float __y) -: 1459: { return __builtin_hypotf(__x, __y); } -: 1460: -: 1461: constexpr long double -: 1462: hypot(long double __x, long double __y) -: 1463: { return __builtin_hypotl(__x, __y); } -: 1464:#endif -: 1465: -: 1466:#ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO_INT -: 1467: template -: 1468: constexpr typename __gnu_cxx::__promote_2<_Tp, _Up>::__type -: 1469: hypot(_Tp __x, _Up __y) -: 1470: { -: 1471: typedef typename __gnu_cxx::__promote_2<_Tp, _Up>::__type __type; -: 1472: return hypot(__type(__x), __type(__y)); -: 1473: } -: 1474:#endif -: 1475: -: 1476:#ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO_FP -: 1477: constexpr int -: 1478: ilogb(float __x) -: 1479: { return __builtin_ilogbf(__x); } -: 1480: -: 1481: constexpr int -: 1482: ilogb(long double __x) -: 1483: { return __builtin_ilogbl(__x); } -: 1484:#endif -: 1485: -: 1486:#ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO_INT -: 1487: template -: 1488: constexpr -: 1489: typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value, -: 1490: int>::__type -: 1491: ilogb(_Tp __x) -: 1492: { return __builtin_ilogb(__x); } -: 1493:#endif -: 1494: -: 1495:#ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO_FP -: 1496: constexpr float -: 1497: lgamma(float __x) -: 1498: { return __builtin_lgammaf(__x); } -: 1499: -: 1500: constexpr long double -: 1501: lgamma(long double __x) -: 1502: { return __builtin_lgammal(__x); } -: 1503:#endif -: 1504: -: 1505:#ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO_INT -: 1506: template -: 1507: constexpr typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value, -: 1508: double>::__type -: 1509: lgamma(_Tp __x) -: 1510: { return __builtin_lgamma(__x); } -: 1511:#endif -: 1512: -: 1513:#ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO_FP -: 1514: constexpr long long -: 1515: llrint(float __x) -: 1516: { return __builtin_llrintf(__x); } -: 1517: -: 1518: constexpr long long -: 1519: llrint(long double __x) -: 1520: { return __builtin_llrintl(__x); } -: 1521:#endif -: 1522: -: 1523:#ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO_INT -: 1524: template -: 1525: constexpr typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value, -: 1526: long long>::__type -: 1527: llrint(_Tp __x) -: 1528: { return __builtin_llrint(__x); } -: 1529:#endif -: 1530: -: 1531:#ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO_FP -: 1532: constexpr long long -: 1533: llround(float __x) -: 1534: { return __builtin_llroundf(__x); } -: 1535: -: 1536: constexpr long long -: 1537: llround(long double __x) -: 1538: { return __builtin_llroundl(__x); } -: 1539:#endif -: 1540: -: 1541:#ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO_INT -: 1542: template -: 1543: constexpr typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value, -: 1544: long long>::__type -: 1545: llround(_Tp __x) -: 1546: { return __builtin_llround(__x); } -: 1547:#endif -: 1548: -: 1549:#ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO_FP -: 1550: constexpr float -: 1551: log1p(float __x) -: 1552: { return __builtin_log1pf(__x); } -: 1553: -: 1554: constexpr long double -: 1555: log1p(long double __x) -: 1556: { return __builtin_log1pl(__x); } -: 1557:#endif -: 1558: -: 1559:#ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO_INT -: 1560: template -: 1561: constexpr typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value, -: 1562: double>::__type -: 1563: log1p(_Tp __x) -: 1564: { return __builtin_log1p(__x); } -: 1565:#endif -: 1566: -: 1567:#ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO_FP -: 1568: // DR 568. -: 1569: constexpr float -: 1570: log2(float __x) -: 1571: { return __builtin_log2f(__x); } -: 1572: -: 1573: constexpr long double -: 1574: log2(long double __x) -: 1575: { return __builtin_log2l(__x); } -: 1576:#endif -: 1577: -: 1578:#ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO_INT -: 1579: template -: 1580: constexpr typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value, -: 1581: double>::__type -: 1582: log2(_Tp __x) -: 1583: { return __builtin_log2(__x); } -: 1584:#endif -: 1585: -: 1586:#ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO_FP -: 1587: constexpr float -: 1588: logb(float __x) -: 1589: { return __builtin_logbf(__x); } -: 1590: -: 1591: constexpr long double -: 1592: logb(long double __x) -: 1593: { return __builtin_logbl(__x); } -: 1594:#endif -: 1595: -: 1596:#ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO_INT -: 1597: template -: 1598: constexpr typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value, -: 1599: double>::__type -: 1600: logb(_Tp __x) -: 1601: { return __builtin_logb(__x); } -: 1602:#endif -: 1603: -: 1604:#ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO_FP -: 1605: constexpr long -: 1606: lrint(float __x) -: 1607: { return __builtin_lrintf(__x); } -: 1608: -: 1609: constexpr long -: 1610: lrint(long double __x) -: 1611: { return __builtin_lrintl(__x); } -: 1612:#endif -: 1613: -: 1614:#ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO_INT -: 1615: template -: 1616: constexpr typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value, -: 1617: long>::__type -: 1618: lrint(_Tp __x) -: 1619: { return __builtin_lrint(__x); } -: 1620:#endif -: 1621: -: 1622:#ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO_FP -: 1623: constexpr long -: 1624: lround(float __x) -: 1625: { return __builtin_lroundf(__x); } -: 1626: -: 1627: constexpr long -: 1628: lround(long double __x) -: 1629: { return __builtin_lroundl(__x); } -: 1630:#endif -: 1631: -: 1632:#ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO_INT -: 1633: template -: 1634: constexpr typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value, -: 1635: long>::__type -: 1636: lround(_Tp __x) -: 1637: { return __builtin_lround(__x); } -: 1638:#endif -: 1639: -: 1640:#ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO_FP -: 1641: constexpr float -: 1642: nearbyint(float __x) -: 1643: { return __builtin_nearbyintf(__x); } -: 1644: -: 1645: constexpr long double -: 1646: nearbyint(long double __x) -: 1647: { return __builtin_nearbyintl(__x); } -: 1648:#endif -: 1649: -: 1650:#ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO_INT -: 1651: template -: 1652: constexpr typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value, -: 1653: double>::__type -: 1654: nearbyint(_Tp __x) -: 1655: { return __builtin_nearbyint(__x); } -: 1656:#endif -: 1657: -: 1658:#ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO_FP -: 1659: constexpr float -: 1660: nextafter(float __x, float __y) -: 1661: { return __builtin_nextafterf(__x, __y); } -: 1662: -: 1663: constexpr long double -: 1664: nextafter(long double __x, long double __y) -: 1665: { return __builtin_nextafterl(__x, __y); } -: 1666:#endif -: 1667: -: 1668:#ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO_INT -: 1669: template -: 1670: constexpr typename __gnu_cxx::__promote_2<_Tp, _Up>::__type -: 1671: nextafter(_Tp __x, _Up __y) -: 1672: { -: 1673: typedef typename __gnu_cxx::__promote_2<_Tp, _Up>::__type __type; -: 1674: return nextafter(__type(__x), __type(__y)); -: 1675: } -: 1676:#endif -: 1677: -: 1678:#ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO_FP -: 1679: constexpr float -: 1680: nexttoward(float __x, long double __y) -: 1681: { return __builtin_nexttowardf(__x, __y); } -: 1682: -: 1683: constexpr long double -: 1684: nexttoward(long double __x, long double __y) -: 1685: { return __builtin_nexttowardl(__x, __y); } -: 1686:#endif -: 1687: -: 1688:#ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO_INT -: 1689: template -: 1690: constexpr typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value, -: 1691: double>::__type -: 1692: nexttoward(_Tp __x, long double __y) -: 1693: { return __builtin_nexttoward(__x, __y); } -: 1694:#endif -: 1695: -: 1696:#ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO_FP -: 1697: constexpr float -: 1698: remainder(float __x, float __y) -: 1699: { return __builtin_remainderf(__x, __y); } -: 1700: -: 1701: constexpr long double -: 1702: remainder(long double __x, long double __y) -: 1703: { return __builtin_remainderl(__x, __y); } -: 1704:#endif -: 1705: -: 1706:#ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO_INT -: 1707: template -: 1708: constexpr typename __gnu_cxx::__promote_2<_Tp, _Up>::__type -: 1709: remainder(_Tp __x, _Up __y) -: 1710: { -: 1711: typedef typename __gnu_cxx::__promote_2<_Tp, _Up>::__type __type; -: 1712: return remainder(__type(__x), __type(__y)); -: 1713: } -: 1714:#endif -: 1715: -: 1716:#ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO_FP -: 1717: inline float -: 1718: remquo(float __x, float __y, int* __pquo) -: 1719: { return __builtin_remquof(__x, __y, __pquo); } -: 1720: -: 1721: inline long double -: 1722: remquo(long double __x, long double __y, int* __pquo) -: 1723: { return __builtin_remquol(__x, __y, __pquo); } -: 1724:#endif -: 1725: -: 1726:#ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO_INT -: 1727: template -: 1728: inline typename __gnu_cxx::__promote_2<_Tp, _Up>::__type -: 1729: remquo(_Tp __x, _Up __y, int* __pquo) -: 1730: { -: 1731: typedef typename __gnu_cxx::__promote_2<_Tp, _Up>::__type __type; -: 1732: return remquo(__type(__x), __type(__y), __pquo); -: 1733: } -: 1734:#endif -: 1735: -: 1736:#ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO_FP -: 1737: constexpr float -: 1738: rint(float __x) -: 1739: { return __builtin_rintf(__x); } -: 1740: -: 1741: constexpr long double -: 1742: rint(long double __x) -: 1743: { return __builtin_rintl(__x); } -: 1744:#endif -: 1745: -: 1746:#ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO_INT -: 1747: template -: 1748: constexpr typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value, -: 1749: double>::__type -: 1750: rint(_Tp __x) -: 1751: { return __builtin_rint(__x); } -: 1752:#endif -: 1753: -: 1754:#ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO_FP -: 1755: constexpr float -: 1756: round(float __x) -: 1757: { return __builtin_roundf(__x); } -: 1758: -: 1759: constexpr long double -: 1760: round(long double __x) -: 1761: { return __builtin_roundl(__x); } -: 1762:#endif -: 1763: -: 1764:#ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO_INT -: 1765: template -: 1766: constexpr typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value, -: 1767: double>::__type -: 1768: round(_Tp __x) -: 1769: { return __builtin_round(__x); } -: 1770:#endif -: 1771: -: 1772:#ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO_FP -: 1773: constexpr float -: 1774: scalbln(float __x, long __ex) -: 1775: { return __builtin_scalblnf(__x, __ex); } -: 1776: -: 1777: constexpr long double -: 1778: scalbln(long double __x, long __ex) -: 1779: { return __builtin_scalblnl(__x, __ex); } -: 1780:#endif -: 1781: -: 1782:#ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO_INT -: 1783: template -: 1784: constexpr typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value, -: 1785: double>::__type -: 1786: scalbln(_Tp __x, long __ex) -: 1787: { return __builtin_scalbln(__x, __ex); } -: 1788:#endif -: 1789: -: 1790:#ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO_FP -: 1791: constexpr float -: 1792: scalbn(float __x, int __ex) -: 1793: { return __builtin_scalbnf(__x, __ex); } -: 1794: -: 1795: constexpr long double -: 1796: scalbn(long double __x, int __ex) -: 1797: { return __builtin_scalbnl(__x, __ex); } -: 1798:#endif -: 1799: -: 1800:#ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO_INT -: 1801: template -: 1802: constexpr typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value, -: 1803: double>::__type -: 1804: scalbn(_Tp __x, int __ex) -: 1805: { return __builtin_scalbn(__x, __ex); } -: 1806:#endif -: 1807: -: 1808:#ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO_FP -: 1809: constexpr float -: 1810: tgamma(float __x) -: 1811: { return __builtin_tgammaf(__x); } -: 1812: -: 1813: constexpr long double -: 1814: tgamma(long double __x) -: 1815: { return __builtin_tgammal(__x); } -: 1816:#endif -: 1817: -: 1818:#ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO_INT -: 1819: template -: 1820: constexpr typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value, -: 1821: double>::__type -: 1822: tgamma(_Tp __x) -: 1823: { return __builtin_tgamma(__x); } -: 1824:#endif -: 1825: -: 1826:#ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO_FP -: 1827: constexpr float -: 1828: trunc(float __x) -: 1829: { return __builtin_truncf(__x); } -: 1830: -: 1831: constexpr long double -: 1832: trunc(long double __x) -: 1833: { return __builtin_truncl(__x); } -: 1834:#endif -: 1835: -: 1836:#ifndef __CORRECT_ISO_CPP11_MATH_H_PROTO_INT -: 1837: template -: 1838: constexpr typename __gnu_cxx::__enable_if<__is_integer<_Tp>::__value, -: 1839: double>::__type -: 1840: trunc(_Tp __x) -: 1841: { return __builtin_trunc(__x); } -: 1842:#endif -: 1843: -: 1844:#endif // _GLIBCXX_USE_C99_MATH_TR1 -: 1845:#endif // C++11 -: 1846: -: 1847:#if __cplusplus > 201402L -: 1848: -: 1849: // [c.math.hypot3], three-dimensional hypotenuse -: 1850:#define __cpp_lib_hypot 201603 -: 1851: -: 1852: template -: 1853: inline _Tp -: 1854: __hypot3(_Tp __x, _Tp __y, _Tp __z) -: 1855: { -: 1856: __x = std::abs(__x); -: 1857: __y = std::abs(__y); -: 1858: __z = std::abs(__z); -: 1859: if (_Tp __a = __x < __y ? __y < __z ? __z : __y : __x < __z ? __z : __x) -: 1860: return __a * std::sqrt((__x / __a) * (__x / __a) -: 1861: + (__y / __a) * (__y / __a) -: 1862: + (__z / __a) * (__z / __a)); -: 1863: else -: 1864: return {}; -: 1865: } -: 1866: -: 1867: inline float -: 1868: hypot(float __x, float __y, float __z) -: 1869: { return std::__hypot3(__x, __y, __z); } -: 1870: -: 1871: inline double -: 1872: hypot(double __x, double __y, double __z) -: 1873: { return std::__hypot3(__x, __y, __z); } -: 1874: -: 1875: inline long double -: 1876: hypot(long double __x, long double __y, long double __z) -: 1877: { return std::__hypot3(__x, __y, __z); } -: 1878: -: 1879: template -: 1880: typename __gnu_cxx::__promote_3<_Tp, _Up, _Vp>::__type -: 1881: hypot(_Tp __x, _Up __y, _Vp __z) -: 1882: { -: 1883: using __type = typename __gnu_cxx::__promote_3<_Tp, _Up, _Vp>::__type; -: 1884: return std::__hypot3<__type>(__x, __y, __z); -: 1885: } -: 1886:#endif // C++17 -: 1887: -: 1888:#if __cplusplus > 201703L -: 1889: // linear interpolation -: 1890:# define __cpp_lib_interpolate 201902L -: 1891: -: 1892: template -: 1893: constexpr _Fp -: 1894: __lerp(_Fp __a, _Fp __b, _Fp __t) noexcept -: 1895: { -: 1896: if (__a <= 0 && __b >= 0 || __a >= 0 && __b <= 0) -: 1897: return __t * __b + (1 - __t) * __a; -: 1898: -: 1899: if (__t == 1) -: 1900: return __b; // exact -: 1901: -: 1902: // Exact at __t=0, monotonic except near __t=1, -: 1903: // bounded, determinate, and consistent: -: 1904: const _Fp __x = __a + __t * (__b - __a); -: 1905: return __t > 1 == __b > __a -: 1906: ? (__b < __x ? __x : __b) -: 1907: : (__b > __x ? __x : __b); // monotonic near __t=1 -: 1908: } -: 1909: -: 1910: constexpr float -: 1911: lerp(float __a, float __b, float __t) noexcept -: 1912: { return std::__lerp(__a, __b, __t); } -: 1913: -: 1914: constexpr double -: 1915: lerp(double __a, double __b, double __t) noexcept -: 1916: { return std::__lerp(__a, __b, __t); } -: 1917: -: 1918: constexpr long double -: 1919: lerp(long double __a, long double __b, long double __t) noexcept -: 1920: { return std::__lerp(__a, __b, __t); } -: 1921:#endif // C++20 -: 1922: -: 1923:_GLIBCXX_END_NAMESPACE_VERSION -: 1924:} // namespace -: 1925: -: 1926:#if _GLIBCXX_USE_STD_SPEC_FUNCS -: 1927:# include -: 1928:#endif -: 1929: -: 1930:} // extern "C++" -: 1931: -: 1932:#endif <<<<<< EOF # path=tests/copysign.cpp.gcov -: 0:Source:copysign.cpp -: 0:Graph:./copysign.gcno -: 0:Data:./copysign.gcda -: 0:Runs:1 -: 1:/*################################################################################ -: 2: ## -: 3: ## Copyright (C) 2016-2022 Keith O'Hara -: 4: ## -: 5: ## This file is part of the GCE-Math C++ library. -: 6: ## -: 7: ## Licensed under the Apache License, Version 2.0 (the "License"); -: 8: ## you may not use this file except in compliance with the License. -: 9: ## You may obtain a copy of the License at -: 10: ## -: 11: ## http://www.apache.org/licenses/LICENSE-2.0 -: 12: ## -: 13: ## Unless required by applicable law or agreed to in writing, software -: 14: ## distributed under the License is distributed on an "AS IS" BASIS, -: 15: ## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -: 16: ## See the License for the specific language governing permissions and -: 17: ## limitations under the License. -: 18: ## -: 19: ################################################################################*/ -: 20: -: 21:#define TEST_PRINT_PRECISION_1 2 -: 22:#define TEST_PRINT_PRECISION_2 2 -: 23: -: 24:#include "gcem_tests.hpp" -: 25: 1: 26:int main() -: 27:{ 1: 28: print_begin("copysign"); -: 29: -: 30: // -: 31: 2*: 32: GCEM_TEST_COMPARE_VALS(gcem::copysign,std::copysign, 1.0, 1.0); 2*: 33: GCEM_TEST_COMPARE_VALS(gcem::copysign,std::copysign, -1.0, 1.0); 2*: 34: GCEM_TEST_COMPARE_VALS(gcem::copysign,std::copysign, 1.0, -1.0); 2*: 35: GCEM_TEST_COMPARE_VALS(gcem::copysign,std::copysign, -1.0, -1.0); -: 36: 2*: 37: GCEM_TEST_COMPARE_VALS(gcem::copysign,std::copysign, 1.0, 0.0); 2*: 38: GCEM_TEST_COMPARE_VALS(gcem::copysign,std::copysign, -1.0, 0.0); 2*: 39: GCEM_TEST_COMPARE_VALS(gcem::copysign,std::copysign, 1.0, -0.0); 2*: 40: GCEM_TEST_COMPARE_VALS(gcem::copysign,std::copysign, -1.0, -0.0); -: 41: 2*: 42: GCEM_TEST_COMPARE_VALS(gcem::copysign,std::copysign, 0.0, 0.0); 2*: 43: GCEM_TEST_COMPARE_VALS(gcem::copysign,std::copysign, -0.0, 0.0); 2*: 44: GCEM_TEST_COMPARE_VALS(gcem::copysign,std::copysign, 0.0, -0.0); 2*: 45: GCEM_TEST_COMPARE_VALS(gcem::copysign,std::copysign, -0.0, -0.0); -: 46: 2*: 47: GCEM_TEST_COMPARE_VALS(gcem::copysign,std::copysign, TEST_POSINF, TEST_POSINF); 2*: 48: GCEM_TEST_COMPARE_VALS(gcem::copysign,std::copysign, TEST_NEGINF, TEST_POSINF); 2*: 49: GCEM_TEST_COMPARE_VALS(gcem::copysign,std::copysign, TEST_POSINF, TEST_NEGINF); 2*: 50: GCEM_TEST_COMPARE_VALS(gcem::copysign,std::copysign, TEST_NEGINF, TEST_NEGINF); -: 51: 2*: 52: GCEM_TEST_COMPARE_VALS(gcem::copysign,std::copysign, TEST_NAN, TEST_NAN); -: 53: -: 54: // -: 55: 1: 56: print_final("copysign"); -: 57: 1: 58: return 0; -: 59:} <<<<<< EOF # path=tests/cos.cpp.gcov -: 0:Source:cos.cpp -: 0:Graph:./cos.gcno -: 0:Data:./cos.gcda -: 0:Runs:1 -: 1:/*################################################################################ -: 2: ## -: 3: ## Copyright (C) 2016-2022 Keith O'Hara -: 4: ## -: 5: ## This file is part of the GCE-Math C++ library. -: 6: ## -: 7: ## Licensed under the Apache License, Version 2.0 (the "License"); -: 8: ## you may not use this file except in compliance with the License. -: 9: ## You may obtain a copy of the License at -: 10: ## -: 11: ## http://www.apache.org/licenses/LICENSE-2.0 -: 12: ## -: 13: ## Unless required by applicable law or agreed to in writing, software -: 14: ## distributed under the License is distributed on an "AS IS" BASIS, -: 15: ## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -: 16: ## See the License for the specific language governing permissions and -: 17: ## limitations under the License. -: 18: ## -: 19: ################################################################################*/ -: 20: -: 21:#define TEST_PRINT_PRECISION_1 3 -: 22:#define TEST_PRINT_PRECISION_2 18 -: 23: -: 24:#include "gcem_tests.hpp" -: 25: 1: 26:int main() -: 27:{ 1: 28: print_begin("cos"); -: 29: -: 30: // -: 31: 2*: 32: GCEM_TEST_COMPARE_VALS(gcem::cos,std::cos,-1.5L); 2*: 33: GCEM_TEST_COMPARE_VALS(gcem::cos,std::cos,0.0L); 2*: 34: GCEM_TEST_COMPARE_VALS(gcem::cos,std::cos,0.001L); 2*: 35: GCEM_TEST_COMPARE_VALS(gcem::cos,std::cos,1.001L); 2*: 36: GCEM_TEST_COMPARE_VALS(gcem::cos,std::cos,1.5L); 2*: 37: GCEM_TEST_COMPARE_VALS(gcem::cos,std::cos,11.1L); 2*: 38: GCEM_TEST_COMPARE_VALS(gcem::cos,std::cos,50.0L); 2*: 39: GCEM_TEST_COMPARE_VALS(gcem::cos,std::cos,150.0L); -: 40: 2*: 41: GCEM_TEST_COMPARE_VALS(gcem::cos,std::cos,TEST_NAN); -: 42: -: 43: // -: 44: 1: 45: print_final("cos"); -: 46: 1: 47: return 0; -: 48:} <<<<<< EOF # path=tests/cosh.cpp.gcov -: 0:Source:cosh.cpp -: 0:Graph:./cosh.gcno -: 0:Data:./cosh.gcda -: 0:Runs:1 -: 1:/*################################################################################ -: 2: ## -: 3: ## Copyright (C) 2016-2022 Keith O'Hara -: 4: ## -: 5: ## This file is part of the GCE-Math C++ library. -: 6: ## -: 7: ## Licensed under the Apache License, Version 2.0 (the "License"); -: 8: ## you may not use this file except in compliance with the License. -: 9: ## You may obtain a copy of the License at -: 10: ## -: 11: ## http://www.apache.org/licenses/LICENSE-2.0 -: 12: ## -: 13: ## Unless required by applicable law or agreed to in writing, software -: 14: ## distributed under the License is distributed on an "AS IS" BASIS, -: 15: ## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -: 16: ## See the License for the specific language governing permissions and -: 17: ## limitations under the License. -: 18: ## -: 19: ################################################################################*/ -: 20: -: 21:#define TEST_PRINT_PRECISION_1 6 -: 22:#define TEST_PRINT_PRECISION_2 18 -: 23: -: 24:#include "gcem_tests.hpp" -: 25: 1: 26:int main() -: 27:{ 1: 28: print_begin("cosh"); -: 29: -: 30: // -: 31: 2*: 32: GCEM_TEST_COMPARE_VALS(gcem::cosh,std::cosh,0.0L); 2*: 33: GCEM_TEST_COMPARE_VALS(gcem::cosh,std::cosh,0.001L); 2*: 34: GCEM_TEST_COMPARE_VALS(gcem::cosh,std::cosh,0.5L); 2*: 35: GCEM_TEST_COMPARE_VALS(gcem::cosh,std::cosh,-0.5L); 2*: 36: GCEM_TEST_COMPARE_VALS(gcem::cosh,std::cosh,0.7568025L); 2*: 37: GCEM_TEST_COMPARE_VALS(gcem::cosh,std::cosh,1.0L); 2*: 38: GCEM_TEST_COMPARE_VALS(gcem::cosh,std::cosh,5.0L); -: 39: 2*: 40: GCEM_TEST_COMPARE_VALS(gcem::cosh,std::cosh,TEST_NAN); -: 41: -: 42: // -: 43: 1: 44: print_final("cosh"); -: 45: 1: 46: return 0; -: 47:} <<<<<< EOF # path=tests/erf.cpp.gcov -: 0:Source:erf.cpp -: 0:Graph:./erf.gcno -: 0:Data:./erf.gcda -: 0:Runs:1 -: 1:/*################################################################################ -: 2: ## -: 3: ## Copyright (C) 2016-2022 Keith O'Hara -: 4: ## -: 5: ## This file is part of the GCE-Math C++ library. -: 6: ## -: 7: ## Licensed under the Apache License, Version 2.0 (the "License"); -: 8: ## you may not use this file except in compliance with the License. -: 9: ## You may obtain a copy of the License at -: 10: ## -: 11: ## http://www.apache.org/licenses/LICENSE-2.0 -: 12: ## -: 13: ## Unless required by applicable law or agreed to in writing, software -: 14: ## distributed under the License is distributed on an "AS IS" BASIS, -: 15: ## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -: 16: ## See the License for the specific language governing permissions and -: 17: ## limitations under the License. -: 18: ## -: 19: ################################################################################*/ -: 20: -: 21:#define TEST_ERR_TOL 1e-12 -: 22: -: 23:#define TEST_PRINT_PRECISION_1 3 -: 24:#define TEST_PRINT_PRECISION_2 10 -: 25: -: 26:#include "gcem_tests.hpp" -: 27: 1: 28:int main() -: 29:{ 1: 30: print_begin("erf"); -: 31: -: 32: // -: 33: 2*: 34: GCEM_TEST_COMPARE_VALS(gcem::erf, std::erf, -3.0L); 2*: 35: GCEM_TEST_COMPARE_VALS(gcem::erf, std::erf, -2.5L); 2*: 36: GCEM_TEST_COMPARE_VALS(gcem::erf, std::erf, -2.11L); 2*: 37: GCEM_TEST_COMPARE_VALS(gcem::erf, std::erf, -2.099L); 2*: 38: GCEM_TEST_COMPARE_VALS(gcem::erf, std::erf, -2.0L); 2*: 39: GCEM_TEST_COMPARE_VALS(gcem::erf, std::erf, -1.3L); 2*: 40: GCEM_TEST_COMPARE_VALS(gcem::erf, std::erf, 0.0L); 2*: 41: GCEM_TEST_COMPARE_VALS(gcem::erf, std::erf, 1.3L); 2*: 42: GCEM_TEST_COMPARE_VALS(gcem::erf, std::erf, 2.0L); 2*: 43: GCEM_TEST_COMPARE_VALS(gcem::erf, std::erf, 2.099L); 2*: 44: GCEM_TEST_COMPARE_VALS(gcem::erf, std::erf, 2.11L); 2*: 45: GCEM_TEST_COMPARE_VALS(gcem::erf, std::erf, 2.5L); 2*: 46: GCEM_TEST_COMPARE_VALS(gcem::erf, std::erf, 3.0L); -: 47: -: 48: // -: 49: 2*: 50: GCEM_TEST_COMPARE_VALS(gcem::erf, std::erf, TEST_NAN); 2*: 51: GCEM_TEST_COMPARE_VALS(gcem::erf, std::erf, TEST_POSINF); 2*: 52: GCEM_TEST_COMPARE_VALS(gcem::erf, std::erf, TEST_NEGINF); -: 53: -: 54: // -: 55: 1: 56: print_final("erf"); -: 57: 1: 58: return 0; -: 59:} <<<<<< EOF # path=tests/erf_inv.cpp.gcov -: 0:Source:erf_inv.cpp -: 0:Graph:./erf_inv.gcno -: 0:Data:./erf_inv.gcda -: 0:Runs:1 -: 1:/*################################################################################ -: 2: ## -: 3: ## Copyright (C) 2016-2022 Keith O'Hara -: 4: ## -: 5: ## This file is part of the GCE-Math C++ library. -: 6: ## -: 7: ## Licensed under the Apache License, Version 2.0 (the "License"); -: 8: ## you may not use this file except in compliance with the License. -: 9: ## You may obtain a copy of the License at -: 10: ## -: 11: ## http://www.apache.org/licenses/LICENSE-2.0 -: 12: ## -: 13: ## Unless required by applicable law or agreed to in writing, software -: 14: ## distributed under the License is distributed on an "AS IS" BASIS, -: 15: ## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -: 16: ## See the License for the specific language governing permissions and -: 17: ## limitations under the License. -: 18: ## -: 19: ################################################################################*/ -: 20: -: 21:#define TEST_ERR_TOL 1e-12 -: 22: -: 23:#define TEST_PRINT_PRECISION_1 6 -: 24:#define TEST_PRINT_PRECISION_2 18 -: 25: -: 26:#include "gcem_tests.hpp" -: 27: 1: 28:int main() -: 29:{ 1: 30: print_begin("erf_inv"); -: 31: -: 32: // -: 33: 2*: 34: GCEM_TEST_EXPECTED_VAL(gcem::erf_inv, -3.0L, -0.999977909503001415L); 2*: 35: GCEM_TEST_EXPECTED_VAL(gcem::erf_inv, -2.5L, -0.999593047982555041L); 2*: 36: GCEM_TEST_EXPECTED_VAL(gcem::erf_inv, -2.11L, -0.997154845031177802L); 2*: 37: GCEM_TEST_EXPECTED_VAL(gcem::erf_inv, -2.05L, -0.996258096044456873L); 2*: 38: GCEM_TEST_EXPECTED_VAL(gcem::erf_inv, -1.3L, -0.934007944940652437L); 2*: 39: GCEM_TEST_EXPECTED_VAL(gcem::erf_inv, 0.0L, 0.0L); 2*: 40: GCEM_TEST_EXPECTED_VAL(gcem::erf_inv, 1.3L, 0.934007944940652437L); 2*: 41: GCEM_TEST_EXPECTED_VAL(gcem::erf_inv, 2.05L, 0.996258096044456873L); 2*: 42: GCEM_TEST_EXPECTED_VAL(gcem::erf_inv, 2.11L, 0.997154845031177802L); 2*: 43: GCEM_TEST_EXPECTED_VAL(gcem::erf_inv, 2.5L, 0.999593047982555041L); 2*: 44: GCEM_TEST_EXPECTED_VAL(gcem::erf_inv, 3.0L, 0.999977909503001415L); -: 45: -: 46: // -: 47: 2*: 48: GCEM_TEST_EXPECTED_VAL(gcem::erf_inv, TEST_NAN, TEST_NAN); 2*: 49: GCEM_TEST_EXPECTED_VAL(gcem::erf_inv, TEST_NAN, -1.1); 2*: 50: GCEM_TEST_EXPECTED_VAL(gcem::erf_inv, TEST_NAN, 1.1); -: 51: 2*: 52: GCEM_TEST_EXPECTED_VAL(gcem::erf_inv, TEST_POSINF, 1); 2*: 53: GCEM_TEST_EXPECTED_VAL(gcem::erf_inv, TEST_NEGINF, -1); -: 54: -: 55: // -: 56: 1: 57: print_final("erf_inv"); -: 58: 1: 59: return 0; -: 60:} <<<<<< EOF # path=tests/exp.cpp.gcov -: 0:Source:exp.cpp -: 0:Graph:exp.gcno -: 0:Data:exp.gcda -: 0:Runs:2 -: 1:/*################################################################################ -: 2: ## -: 3: ## Copyright (C) 2016-2022 Keith O'Hara -: 4: ## -: 5: ## This file is part of the GCE-Math C++ library. -: 6: ## -: 7: ## Licensed under the Apache License, Version 2.0 (the "License"); -: 8: ## you may not use this file except in compliance with the License. -: 9: ## You may obtain a copy of the License at -: 10: ## -: 11: ## http://www.apache.org/licenses/LICENSE-2.0 -: 12: ## -: 13: ## Unless required by applicable law or agreed to in writing, software -: 14: ## distributed under the License is distributed on an "AS IS" BASIS, -: 15: ## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -: 16: ## See the License for the specific language governing permissions and -: 17: ## limitations under the License. -: 18: ## -: 19: ################################################################################*/ -: 20: -: 21:#define TEST_PRINT_PRECISION_1 5 -: 22:#define TEST_PRINT_PRECISION_2 18 -: 23: -: 24:#include "gcem_tests.hpp" -: 25: 2: 26:int main() -: 27:{ 2: 28: print_begin("exp"); -: 29: -: 30: // -: 31: 4*: 32: GCEM_TEST_COMPARE_VALS(gcem::exp,std::exp, -40.0L); 4*: 33: GCEM_TEST_COMPARE_VALS(gcem::exp,std::exp, -4.0L); 4*: 34: GCEM_TEST_COMPARE_VALS(gcem::exp,std::exp, 0.0001L); 4*: 35: GCEM_TEST_COMPARE_VALS(gcem::exp,std::exp, 1.0L); 4*: 36: GCEM_TEST_COMPARE_VALS(gcem::exp,std::exp, 1.75L); 4*: 37: GCEM_TEST_COMPARE_VALS(gcem::exp,std::exp, 1.9991L); 4*: 38: GCEM_TEST_COMPARE_VALS(gcem::exp,std::exp, 2.1L); 4*: 39: GCEM_TEST_COMPARE_VALS(gcem::exp,std::exp, 4.0L); -: 40: 4*: 41: GCEM_TEST_COMPARE_VALS(gcem::exp,std::exp, -std::numeric_limits::infinity()); 4*: 42: GCEM_TEST_COMPARE_VALS(gcem::exp,std::exp, std::numeric_limits::infinity()); 4*: 43: GCEM_TEST_COMPARE_VALS(gcem::exp,std::exp, std::numeric_limits::quiet_NaN()); -: 44: -: 45: // -: 46: 2: 47: print_final("exp"); -: 48: 2: 49: return 0; -: 50:} <<<<<< EOF # path=tests/exp.hpp.gcov -: 0:Source:../include/gcem_incl/exp.hpp -: 0:Graph:./incomplete_gamma_inv.gcno -: 0:Data:./incomplete_gamma_inv.gcda -: 0:Runs:1 -: 1:/*################################################################################ -: 2: ## -: 3: ## Copyright (C) 2016-2022 Keith O'Hara -: 4: ## -: 5: ## This file is part of the GCE-Math C++ library. -: 6: ## -: 7: ## Licensed under the Apache License, Version 2.0 (the "License"); -: 8: ## you may not use this file except in compliance with the License. -: 9: ## You may obtain a copy of the License at -: 10: ## -: 11: ## http://www.apache.org/licenses/LICENSE-2.0 -: 12: ## -: 13: ## Unless required by applicable law or agreed to in writing, software -: 14: ## distributed under the License is distributed on an "AS IS" BASIS, -: 15: ## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -: 16: ## See the License for the specific language governing permissions and -: 17: ## limitations under the License. -: 18: ## -: 19: ################################################################################*/ -: 20: -: 21:/* -: 22: * compile-time exponential function -: 23: */ -: 24: -: 25:#ifndef _gcem_exp_HPP -: 26:#define _gcem_exp_HPP -: 27: -: 28:namespace internal -: 29:{ -: 30: -: 31:template -: 32:constexpr -: 33:T 734400: 34:exp_cf_recur(const T x, const int depth) -: 35:noexcept -: 36:{ 1439424: 37: return( depth < GCEM_EXP_MAX_ITER_SMALL ? \ -: 38: // if 705024: 39: depth == 1 ? \ 29376: 40: T(1) - x/exp_cf_recur(x,depth+1) : 675648: 41: T(1) + x/T(depth - 1) - x/depth/exp_cf_recur(x,depth+1) : -: 42: // else 734400: 43: T(1) ); -: 44:} -: 45: -: 46:template -: 47:constexpr -: 48:T 29376: 49:exp_cf(const T x) -: 50:noexcept -: 51:{ 29376: 52: return( T(1)/exp_cf_recur(x,1) ); -: 53:} -: 54: -: 55:template -: 56:constexpr -: 57:T 29376: 58:exp_split(const T x) -: 59:noexcept -: 60:{ 29376: 61: return( static_cast(pow_integral(GCEM_E,find_whole(x))) * exp_cf(find_fraction(x)) ); -: 62:} -: 63: -: 64:template -: 65:constexpr -: 66:T 29376: 67:exp_check(const T x) -: 68:noexcept -: 69:{ 58752: 70: return( is_nan(x) ? \ #####: 71: GCLIM::quiet_NaN() : -: 72: // 58752*: 73: is_neginf(x) ? \ -: 74: T(0) : -: 75: // 58752*: 76: GCLIM::min() > abs(x) ? \ -: 77: T(1) : -: 78: // 58752: 79: is_posinf(x) ? \ #####: 80: GCLIM::infinity() : -: 81: // 29376: 82: abs(x) < T(2) ? \ #####: 83: exp_cf(x) : \ 58752: 84: exp_split(x) ); -: 85:} -: 86: -: 87:} -: 88: -: 89:/** -: 90: * Compile-time exponential function -: 91: * -: 92: * @param x a real-valued input. -: 93: * @return \f$ \exp(x) \f$ using \f[ \exp(x) = \dfrac{1}{1-\dfrac{x}{1+x-\dfrac{\frac{1}{2}x}{1 + \frac{1}{2}x - \dfrac{\frac{1}{3}x}{1 + \frac{1}{3}x - \ddots}}}} \f] -: 94: * The continued fraction argument is split into two parts: \f$ x = n + r \f$, where \f$ n \f$ is an integer and \f$ r \in [-0.5,0.5] \f$. -: 95: */ -: 96: -: 97:template -: 98:constexpr -: 99:return_t 29376: 100:exp(const T x) -: 101:noexcept -: 102:{ 29376: 103: return internal::exp_check( static_cast>(x) ); -: 104:} -: 105: -: 106:#endif <<<<<< EOF # path=tests/expm1.cpp.gcov -: 0:Source:expm1.cpp -: 0:Graph:./expm1.gcno -: 0:Data:./expm1.gcda -: 0:Runs:1 -: 1:/*################################################################################ -: 2: ## -: 3: ## Copyright (C) 2016-2022 Keith O'Hara -: 4: ## -: 5: ## This file is part of the GCE-Math C++ library. -: 6: ## -: 7: ## Licensed under the Apache License, Version 2.0 (the "License"); -: 8: ## you may not use this file except in compliance with the License. -: 9: ## You may obtain a copy of the License at -: 10: ## -: 11: ## http://www.apache.org/licenses/LICENSE-2.0 -: 12: ## -: 13: ## Unless required by applicable law or agreed to in writing, software -: 14: ## distributed under the License is distributed on an "AS IS" BASIS, -: 15: ## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -: 16: ## See the License for the specific language governing permissions and -: 17: ## limitations under the License. -: 18: ## -: 19: ################################################################################*/ -: 20: -: 21:#define TEST_PRINT_PRECISION_1 5 -: 22:#define TEST_PRINT_PRECISION_2 18 -: 23: -: 24:#include "gcem_tests.hpp" -: 25: 1: 26:int main() -: 27:{ 1: 28: print_begin("expm1"); -: 29: -: 30: // -: 31: 2*: 32: GCEM_TEST_COMPARE_VALS(gcem::expm1,std::expm1,1.0L); 2*: 33: GCEM_TEST_COMPARE_VALS(gcem::expm1,std::expm1,0.0L); 2*: 34: GCEM_TEST_COMPARE_VALS(gcem::expm1,std::expm1,1e-04L); 2*: 35: GCEM_TEST_COMPARE_VALS(gcem::expm1,std::expm1,-1e-04L); 2*: 36: GCEM_TEST_COMPARE_VALS(gcem::expm1,std::expm1,1e-05L); 2*: 37: GCEM_TEST_COMPARE_VALS(gcem::expm1,std::expm1,1e-06L); 2*: 38: GCEM_TEST_COMPARE_VALS(gcem::expm1,std::expm1,1e-22L); -: 39: 2*: 40: GCEM_TEST_COMPARE_VALS(gcem::expm1,std::expm1, -std::numeric_limits::infinity()); 2*: 41: GCEM_TEST_COMPARE_VALS(gcem::expm1,std::expm1, std::numeric_limits::infinity()); 2*: 42: GCEM_TEST_COMPARE_VALS(gcem::expm1,std::expm1, std::numeric_limits::quiet_NaN()); -: 43: -: 44: // -: 45: 1: 46: print_final("expm1"); -: 47: 1: 48: return 0; -: 49:} <<<<<< EOF # path=tests/factorial.cpp.gcov -: 0:Source:factorial.cpp -: 0:Graph:./factorial.gcno -: 0:Data:./factorial.gcda -: 0:Runs:1 -: 1:/*################################################################################ -: 2: ## -: 3: ## Copyright (C) 2016-2022 Keith O'Hara -: 4: ## -: 5: ## This file is part of the GCE-Math C++ library. -: 6: ## -: 7: ## Licensed under the Apache License, Version 2.0 (the "License"); -: 8: ## you may not use this file except in compliance with the License. -: 9: ## You may obtain a copy of the License at -: 10: ## -: 11: ## http://www.apache.org/licenses/LICENSE-2.0 -: 12: ## -: 13: ## Unless required by applicable law or agreed to in writing, software -: 14: ## distributed under the License is distributed on an "AS IS" BASIS, -: 15: ## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -: 16: ## See the License for the specific language governing permissions and -: 17: ## limitations under the License. -: 18: ## -: 19: ################################################################################*/ -: 20: -: 21:#define TEST_ERR_TOL 1e-02 -: 22:#define TEST_PRINT_PRECISION_1 6 -: 23:#define TEST_PRINT_PRECISION_2 18 -: 24: -: 25:#include "gcem_tests.hpp" -: 26: 1: 27:int main() -: 28:{ 1: 29: print_begin("factorial"); -: 30: 12: 31: std::function std_fn = [] (long double x) -> long double { return std::tgamma(x+1); }; -: 32: -: 33: // -: 34: -: 35: // using long doubles -> tgamma 2*: 36: GCEM_TEST_COMPARE_VALS(gcem::factorial,std_fn, 3.1L); 2*: 37: GCEM_TEST_COMPARE_VALS(gcem::factorial,std_fn, 7.0L); 2*: 38: GCEM_TEST_COMPARE_VALS(gcem::factorial,std_fn, 10.0L); 2*: 39: GCEM_TEST_COMPARE_VALS(gcem::factorial,std_fn, 12.0L); 2*: 40: GCEM_TEST_COMPARE_VALS(gcem::factorial,std_fn, 14.0L); 2*: 41: GCEM_TEST_COMPARE_VALS(gcem::factorial,std_fn, 15.0L); -: 42: -: 43: // using long ints 2*: 44: GCEM_TEST_COMPARE_VALS(gcem::factorial,std_fn, 5L); 2*: 45: GCEM_TEST_COMPARE_VALS(gcem::factorial,std_fn, 9L); 2*: 46: GCEM_TEST_COMPARE_VALS(gcem::factorial,std_fn, 11L); -: 47:#ifndef _WIN32 2*: 48: GCEM_TEST_COMPARE_VALS(gcem::factorial,std_fn, 13L); 2*: 49: GCEM_TEST_COMPARE_VALS(gcem::factorial,std_fn, 16L); -: 50:#endif -: 51: -: 52: // -: 53: 1: 54: print_final("factorial"); -: 55: 1: 56: return 0; -: 57:} <<<<<< EOF # path=tests/find_exponent.hpp.gcov -: 0:Source:../include/gcem_incl/find_exponent.hpp -: 0:Graph:log.gcno -: 0:Data:log.gcda -: 0:Runs:2 -: 1:/*################################################################################ -: 2: ## -: 3: ## Copyright (C) 2016-2022 Keith O'Hara -: 4: ## -: 5: ## This file is part of the GCE-Math C++ library. -: 6: ## -: 7: ## Licensed under the Apache License, Version 2.0 (the "License"); -: 8: ## you may not use this file except in compliance with the License. -: 9: ## You may obtain a copy of the License at -: 10: ## -: 11: ## http://www.apache.org/licenses/LICENSE-2.0 -: 12: ## -: 13: ## Unless required by applicable law or agreed to in writing, software -: 14: ## distributed under the License is distributed on an "AS IS" BASIS, -: 15: ## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -: 16: ## See the License for the specific language governing permissions and -: 17: ## limitations under the License. -: 18: ## -: 19: ################################################################################*/ -: 20: -: 21:/* -: 22: * compile-time find_exponent function -: 23: */ -: 24: -: 25:#ifndef _gcem_find_exponent_HPP -: 26:#define _gcem_find_exponent_HPP -: 27: -: 28:namespace internal -: 29:{ -: 30: -: 31:template -: 32:constexpr -: 33:llint_t 9866: 34:find_exponent(const T x, const llint_t exponent) -: 35:noexcept -: 36:{ 9868: 37: return( x < T(1) ? \ 9864: 38: find_exponent(x*T(10),exponent - llint_t(1)) : 2: 39: x > T(10) ? \ #####: 40: find_exponent(x/T(10),exponent + llint_t(1)) : -: 41: // else 9866: 42: exponent ); -: 43:} -: 44: -: 45:} -: 46: -: 47:#endif <<<<<< EOF # path=tests/find_fraction.hpp.gcov -: 0:Source:../include/gcem_incl/find_fraction.hpp -: 0:Graph:./incomplete_gamma_inv.gcno -: 0:Data:./incomplete_gamma_inv.gcda -: 0:Runs:1 -: 1:/*################################################################################ -: 2: ## -: 3: ## Copyright (C) 2016-2022 Keith O'Hara -: 4: ## -: 5: ## This file is part of the GCE-Math C++ library. -: 6: ## -: 7: ## Licensed under the Apache License, Version 2.0 (the "License"); -: 8: ## you may not use this file except in compliance with the License. -: 9: ## You may obtain a copy of the License at -: 10: ## -: 11: ## http://www.apache.org/licenses/LICENSE-2.0 -: 12: ## -: 13: ## Unless required by applicable law or agreed to in writing, software -: 14: ## distributed under the License is distributed on an "AS IS" BASIS, -: 15: ## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -: 16: ## See the License for the specific language governing permissions and -: 17: ## limitations under the License. -: 18: ## -: 19: ################################################################################*/ -: 20: -: 21:/* -: 22: * find the fraction part of x = n + r, where -0.5 <= r <= 0.5 -: 23: */ -: 24: -: 25:#ifndef _gcem_find_fraction_HPP -: 26:#define _gcem_find_fraction_HPP -: 27: -: 28:namespace internal -: 29:{ -: 30: -: 31:template -: 32:constexpr -: 33:T 29376: 34:find_fraction(const T x) -: 35:noexcept -: 36:{ 42226: 37: return( abs(x - internal::floor_check(x)) >= T(0.5) ? \ -: 38: // if 16526: 39: x - internal::floor_check(x) - sgn(x) : -: 40: //else 42226: 41: x - internal::floor_check(x) ); -: 42:} -: 43: -: 44:} -: 45: -: 46:#endif <<<<<< EOF # path=tests/find_whole.hpp.gcov -: 0:Source:../include/gcem_incl/find_whole.hpp -: 0:Graph:./incomplete_gamma_inv.gcno -: 0:Data:./incomplete_gamma_inv.gcda -: 0:Runs:1 -: 1:/*################################################################################ -: 2: ## -: 3: ## Copyright (C) 2016-2022 Keith O'Hara -: 4: ## -: 5: ## This file is part of the GCE-Math C++ library. -: 6: ## -: 7: ## Licensed under the Apache License, Version 2.0 (the "License"); -: 8: ## you may not use this file except in compliance with the License. -: 9: ## You may obtain a copy of the License at -: 10: ## -: 11: ## http://www.apache.org/licenses/LICENSE-2.0 -: 12: ## -: 13: ## Unless required by applicable law or agreed to in writing, software -: 14: ## distributed under the License is distributed on an "AS IS" BASIS, -: 15: ## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -: 16: ## See the License for the specific language governing permissions and -: 17: ## limitations under the License. -: 18: ## -: 19: ################################################################################*/ -: 20: -: 21:/* -: 22: * find the whole number part of x = n + r, where -0.5 <= r <= 0.5 -: 23: */ -: 24: -: 25:#ifndef _gcem_find_whole_HPP -: 26:#define _gcem_find_whole_HPP -: 27: -: 28:namespace internal -: 29:{ -: 30: -: 31:template -: 32:constexpr -: 33:llint_t 29376: 34:find_whole(const T x) -: 35:noexcept -: 36:{ 42226: 37: return( abs(x - internal::floor_check(x)) >= T(0.5) ? \ -: 38: // if 16526: 39: static_cast(internal::floor_check(x) + sgn(x)) : -: 40: // else 42226: 41: static_cast(internal::floor_check(x)) ); -: 42:} -: 43: -: 44:} -: 45: -: 46:#endif <<<<<< EOF # path=tests/floor.hpp.gcov -: 0:Source:../include/gcem_incl/floor.hpp -: 0:Graph:./incomplete_gamma_inv.gcno -: 0:Data:./incomplete_gamma_inv.gcda -: 0:Runs:1 -: 1:/*################################################################################ -: 2: ## -: 3: ## Copyright (C) 2016-2022 Keith O'Hara -: 4: ## -: 5: ## This file is part of the GCE-Math C++ library. -: 6: ## -: 7: ## Licensed under the Apache License, Version 2.0 (the "License"); -: 8: ## you may not use this file except in compliance with the License. -: 9: ## You may obtain a copy of the License at -: 10: ## -: 11: ## http://www.apache.org/licenses/LICENSE-2.0 -: 12: ## -: 13: ## Unless required by applicable law or agreed to in writing, software -: 14: ## distributed under the License is distributed on an "AS IS" BASIS, -: 15: ## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -: 16: ## See the License for the specific language governing permissions and -: 17: ## limitations under the License. -: 18: ## -: 19: ################################################################################*/ -: 20: -: 21:#ifndef _gcem_floor_HPP -: 22:#define _gcem_floor_HPP -: 23: -: 24:namespace internal -: 25:{ -: 26: -: 27:template -: 28:constexpr -: 29:int 117504: 30:floor_resid(const T x, const T x_whole) -: 31:noexcept -: 32:{ 117504*: 33: return( (x < T(0)) && (x < x_whole) ); -: 34:} -: 35: -: 36:template -: 37:constexpr -: 38:T 117504: 39:floor_int(const T x, const T x_whole) -: 40:noexcept -: 41:{ 117504: 42: return( x_whole - static_cast(floor_resid(x,x_whole)) ); -: 43:} -: 44: -: 45:template -: 46:constexpr -: 47:T -: 48:floor_check_internal(const T x) -: 49:noexcept -: 50:{ -: 51: return x; -: 52:} -: 53: -: 54:template<> -: 55:constexpr -: 56:float -: 57:floor_check_internal(const float x) -: 58:noexcept -: 59:{ -: 60: return( abs(x) >= 8388608.f ? \ -: 61: // if -: 62: x : \ -: 63: // else -: 64: floor_int(x, float(static_cast(x))) ); -: 65:} -: 66: -: 67:template<> -: 68:constexpr -: 69:double -: 70:floor_check_internal(const double x) -: 71:noexcept -: 72:{ -: 73: return( abs(x) >= 4503599627370496. ? \ -: 74: // if -: 75: x : \ -: 76: // else -: 77: floor_int(x, double(static_cast(x))) ); -: 78:} -: 79: -: 80:template<> -: 81:constexpr -: 82:long double 117504: 83:floor_check_internal(const long double x) -: 84:noexcept -: 85:{ 117504*: 86: return( abs(x) >= 9223372036854775808.l ? \ -: 87: // if -: 88: x : \ -: 89: // else 117504: 90: floor_int(x, ((long double)static_cast(abs(x))) * sgn(x)) ); -: 91:} -: 92: -: 93:template -: 94:constexpr -: 95:T 117504: 96:floor_check(const T x) -: 97:noexcept -: 98:{ -: 99: return( // NaN check 235008: 100: is_nan(x) ? \ #####: 101: GCLIM::quiet_NaN() : -: 102: // +/- infinite 235008*: 103: !is_finite(x) ? \ -: 104: x : -: 105: // signed-zero cases 117504*: 106: GCLIM::min() > abs(x) ? \ -: 107: x : -: 108: // else 235008: 109: floor_check_internal(x) ); -: 110:} -: 111: -: 112:} -: 113: -: 114:/** -: 115: * Compile-time floor function -: 116: * -: 117: * @param x a real-valued input. -: 118: * @return computes the floor-value of the input. -: 119: */ -: 120: -: 121:template -: 122:constexpr -: 123:return_t -: 124:floor(const T x) -: 125:noexcept -: 126:{ -: 127: return internal::floor_check( static_cast>(x) ); -: 128:} -: 129: -: 130:#endif <<<<<< EOF # path=tests/fmod.cpp.gcov -: 0:Source:fmod.cpp -: 0:Graph:./fmod.gcno -: 0:Data:./fmod.gcda -: 0:Runs:1 -: 1:/*################################################################################ -: 2: ## -: 3: ## Copyright (C) 2016-2022 Keith O'Hara -: 4: ## -: 5: ## This file is part of the GCE-Math C++ library. -: 6: ## -: 7: ## Licensed under the Apache License, Version 2.0 (the "License"); -: 8: ## you may not use this file except in compliance with the License. -: 9: ## You may obtain a copy of the License at -: 10: ## -: 11: ## http://www.apache.org/licenses/LICENSE-2.0 -: 12: ## -: 13: ## Unless required by applicable law or agreed to in writing, software -: 14: ## distributed under the License is distributed on an "AS IS" BASIS, -: 15: ## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -: 16: ## See the License for the specific language governing permissions and -: 17: ## limitations under the License. -: 18: ## -: 19: ################################################################################*/ -: 20: -: 21:#define TEST_PRINT_PRECISION_1 2 -: 22:#define TEST_PRINT_PRECISION_2 2 -: 23: -: 24:#include "gcem_tests.hpp" -: 25: 1: 26:int main() -: 27:{ 1: 28: print_begin("fmod"); -: 29: -: 30: // -: 31: 2*: 32: GCEM_TEST_COMPARE_VALS(gcem::fmod,std::fmod, 0.0, 0.0); 2*: 33: GCEM_TEST_COMPARE_VALS(gcem::fmod,std::fmod, -0.0, 0.0); 2*: 34: GCEM_TEST_COMPARE_VALS(gcem::fmod,std::fmod, 0.0, -0.0); 2*: 35: GCEM_TEST_COMPARE_VALS(gcem::fmod,std::fmod, 5.3, 2.0); 2*: 36: GCEM_TEST_COMPARE_VALS(gcem::fmod,std::fmod, -5.3, 2.0); 2*: 37: GCEM_TEST_COMPARE_VALS(gcem::fmod,std::fmod, 5.3, -2.0); 2*: 38: GCEM_TEST_COMPARE_VALS(gcem::fmod,std::fmod, -5.3, -2.0); 2*: 39: GCEM_TEST_COMPARE_VALS(gcem::fmod,std::fmod, 18.5, 4.2); 2*: 40: GCEM_TEST_COMPARE_VALS(gcem::fmod,std::fmod, -18.5, 4.2); 2*: 41: GCEM_TEST_COMPARE_VALS(gcem::fmod,std::fmod, 18.5, -4.2); 2*: 42: GCEM_TEST_COMPARE_VALS(gcem::fmod,std::fmod, -18.5, -4.2); -: 43: 2*: 44: GCEM_TEST_COMPARE_VALS(gcem::fmod,std::fmod, -std::numeric_limits::infinity(), 0.0); 2*: 45: GCEM_TEST_COMPARE_VALS(gcem::fmod,std::fmod, -std::numeric_limits::infinity(), -1.0); 2*: 46: GCEM_TEST_COMPARE_VALS(gcem::fmod,std::fmod, -std::numeric_limits::infinity(), 1.0); 2*: 47: GCEM_TEST_COMPARE_VALS(gcem::fmod,std::fmod, -std::numeric_limits::infinity(), std::numeric_limits::infinity()); 2*: 48: GCEM_TEST_COMPARE_VALS(gcem::fmod,std::fmod, -std::numeric_limits::infinity(), -std::numeric_limits::infinity()); 2*: 49: GCEM_TEST_COMPARE_VALS(gcem::fmod,std::fmod, -std::numeric_limits::infinity(), std::numeric_limits::quiet_NaN()); -: 50: 2*: 51: GCEM_TEST_COMPARE_VALS(gcem::fmod,std::fmod, std::numeric_limits::infinity(), 0.0); 2*: 52: GCEM_TEST_COMPARE_VALS(gcem::fmod,std::fmod, std::numeric_limits::infinity(), -1.0); 2*: 53: GCEM_TEST_COMPARE_VALS(gcem::fmod,std::fmod, std::numeric_limits::infinity(), 1.0); 2*: 54: GCEM_TEST_COMPARE_VALS(gcem::fmod,std::fmod, std::numeric_limits::infinity(), std::numeric_limits::infinity()); 2*: 55: GCEM_TEST_COMPARE_VALS(gcem::fmod,std::fmod, std::numeric_limits::infinity(), -std::numeric_limits::infinity()); 2*: 56: GCEM_TEST_COMPARE_VALS(gcem::fmod,std::fmod, std::numeric_limits::infinity(), std::numeric_limits::quiet_NaN()); -: 57: 2*: 58: GCEM_TEST_COMPARE_VALS(gcem::fmod,std::fmod, std::numeric_limits::quiet_NaN(), 0.0); 2*: 59: GCEM_TEST_COMPARE_VALS(gcem::fmod,std::fmod, std::numeric_limits::quiet_NaN(), -1.0); 2*: 60: GCEM_TEST_COMPARE_VALS(gcem::fmod,std::fmod, std::numeric_limits::quiet_NaN(), 1.0); 2*: 61: GCEM_TEST_COMPARE_VALS(gcem::fmod,std::fmod, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity()); 2*: 62: GCEM_TEST_COMPARE_VALS(gcem::fmod,std::fmod, std::numeric_limits::quiet_NaN(), -std::numeric_limits::infinity()); 2*: 63: GCEM_TEST_COMPARE_VALS(gcem::fmod,std::fmod, std::numeric_limits::quiet_NaN(), std::numeric_limits::quiet_NaN()); -: 64: -: 65: // -: 66: 1: 67: print_final("fmod"); -: 68: 1: 69: return 0; -: 70:} <<<<<< EOF # path=tests/fmod.hpp.gcov -: 0:Source:../include/gcem_incl/fmod.hpp -: 0:Graph:./fmod.gcno -: 0:Data:./fmod.gcda -: 0:Runs:1 -: 1:/*################################################################################ -: 2: ## -: 3: ## Copyright (C) 2016-2022 Keith O'Hara -: 4: ## -: 5: ## This file is part of the GCE-Math C++ library. -: 6: ## -: 7: ## Licensed under the Apache License, Version 2.0 (the "License"); -: 8: ## you may not use this file except in compliance with the License. -: 9: ## You may obtain a copy of the License at -: 10: ## -: 11: ## http://www.apache.org/licenses/LICENSE-2.0 -: 12: ## -: 13: ## Unless required by applicable law or agreed to in writing, software -: 14: ## distributed under the License is distributed on an "AS IS" BASIS, -: 15: ## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -: 16: ## See the License for the specific language governing permissions and -: 17: ## limitations under the License. -: 18: ## -: 19: ################################################################################*/ -: 20: -: 21:#ifndef _gcem_fmod_HPP -: 22:#define _gcem_fmod_HPP -: 23: -: 24:namespace internal -: 25:{ -: 26: -: 27:template -: 28:constexpr -: 29:T 3: 30:fmod_check(const T x, const T y) -: 31:noexcept -: 32:{ -: 33: return( // NaN check 6: 34: any_nan(x, y) ? \ #####: 35: GCLIM::quiet_NaN() : -: 36: // +/- infinite 3: 37: !all_finite(x, y) ? \ #####: 38: GCLIM::quiet_NaN() : -: 39: // else 6: 40: x - trunc(x/y)*y ); -: 41:} -: 42: -: 43:template> -: 44:constexpr -: 45:TC 3: 46:fmod_type_check(const T1 x, const T2 y) -: 47:noexcept -: 48:{ 3: 49: return fmod_check(static_cast(x),static_cast(y)); -: 50:} -: 51: -: 52:} -: 53: -: 54:/** -: 55: * Compile-time remainder of division function -: 56: * @param x a real-valued input. -: 57: * @param y a real-valued input. -: 58: * @return computes the floating-point remainder of \f$ x / y \f$ (rounded towards zero) using \f[ \text{fmod}(x,y) = x - \text{trunc}(x/y) \times y \f] -: 59: */ -: 60: -: 61:template -: 62:constexpr -: 63:common_return_t 3: 64:fmod(const T1 x, const T2 y) -: 65:noexcept -: 66:{ 3: 67: return internal::fmod_type_check(x,y); -: 68:} -: 69: -: 70:#endif <<<<<< EOF # path=tests/gcd.cpp.gcov -: 0:Source:gcd.cpp -: 0:Graph:./gcd.gcno -: 0:Data:./gcd.gcda -: 0:Runs:1 -: 1:/*################################################################################ -: 2: ## -: 3: ## Copyright (C) 2016-2022 Keith O'Hara -: 4: ## -: 5: ## This file is part of the GCE-Math C++ library. -: 6: ## -: 7: ## Licensed under the Apache License, Version 2.0 (the "License"); -: 8: ## you may not use this file except in compliance with the License. -: 9: ## You may obtain a copy of the License at -: 10: ## -: 11: ## http://www.apache.org/licenses/LICENSE-2.0 -: 12: ## -: 13: ## Unless required by applicable law or agreed to in writing, software -: 14: ## distributed under the License is distributed on an "AS IS" BASIS, -: 15: ## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -: 16: ## See the License for the specific language governing permissions and -: 17: ## limitations under the License. -: 18: ## -: 19: ################################################################################*/ -: 20: -: 21:#define TEST_VAL_TYPES int -: 22: -: 23:#include "gcem_tests.hpp" -: 24: 1: 25:int main() -: 26:{ 1: 27: print_begin("gcd"); -: 28: -: 29: // -: 30: 2*: 31: GCEM_TEST_EXPECTED_VAL(gcem::gcd,6,12,18); 2*: 32: GCEM_TEST_EXPECTED_VAL(gcem::gcd,2,-4,14); 2*: 33: GCEM_TEST_EXPECTED_VAL(gcem::gcd,14,42,56); -: 34: -: 35: // -: 36: 1: 37: print_final("gcd"); -: 38: 1: 39: return 0; -: 40:} <<<<<< EOF # path=tests/gcem_tests.hpp.gcov -: 0:Source:gcem_tests.hpp -: 0:Graph:log.gcno -: 0:Data:log.gcda -: 0:Runs:2 -: 1:/*################################################################################ -: 2: ## -: 3: ## Copyright (C) 2016-2022 Keith O'Hara -: 4: ## -: 5: ## This file is part of the GCE-Math C++ library. -: 6: ## -: 7: ## Licensed under the Apache License, Version 2.0 (the "License"); -: 8: ## you may not use this file except in compliance with the License. -: 9: ## You may obtain a copy of the License at -: 10: ## -: 11: ## http://www.apache.org/licenses/LICENSE-2.0 -: 12: ## -: 13: ## Unless required by applicable law or agreed to in writing, software -: 14: ## distributed under the License is distributed on an "AS IS" BASIS, -: 15: ## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -: 16: ## See the License for the specific language governing permissions and -: 17: ## limitations under the License. -: 18: ## -: 19: ################################################################################*/ -: 20: -: 21:#include -: 22:#include -: 23:#include -: 24:#include -: 25:#include -: 26:#include -: 27: -: 28:#include "gcem.hpp" -: 29: -: 30:// -: 31:// tolerance -: 32: -: 33:int GCEM_TEST_NUMBER = 0; -: 34: -: 35:#ifndef TEST_VAL_TYPES -: 36: #define TEST_VAL_TYPES long double -: 37: #define TEST_VAL_TYPES_V 1 -: 38:#endif -: 39: -: 40:#ifndef TEST_ERR_TOL -: 41:#ifdef _WIN32 -: 42: #define TEST_ERR_TOL 1e-10 -: 43:#else -: 44: #define TEST_ERR_TOL 1e-14 -: 45:#endif -: 46:#endif -: 47: -: 48:#ifdef TEST_VAL_TYPES_V -: 49:#define PRINT_ERR(err_val) \ -: 50:{ \ -: 51: printf(" error value = %LE.", err_val); \ -: 52:} -: 53:#else -: 54:#define PRINT_ERR(err_val) \ -: 55:{ \ -: 56: printf(" error value = %d.", err_val); \ -: 57:} -: 58:#endif -: 59: -: 60:#ifdef TEST_VAL_TYPES_V -: 61: #define VAL_IS_INF(val) std::isinf(static_cast(val)) -: 62: #define VAL_IS_NAN(val) std::isnan(static_cast(val)) -: 63:#else -: 64: #define VAL_IS_INF(val) false -: 65: #define VAL_IS_NAN(val) false -: 66:#endif -: 67: -: 68:#ifndef TEST_NAN -: 69: #define TEST_NAN gcem::GCLIM::quiet_NaN() -: 70:#endif -: 71: -: 72:#ifndef TEST_POSINF -: 73: #define TEST_POSINF gcem::GCLIM::infinity() -: 74:#endif -: 75: -: 76:#ifndef TEST_NEGINF -: 77: #define TEST_NEGINF -gcem::GCLIM::infinity() -: 78:#endif -: 79: -: 80:// -: 81: -: 82:#ifndef TEST_PRINT_LEVEL -: 83: #define TEST_PRINT_LEVEL 3 -: 84:#endif -: 85: -: 86:#ifndef TEST_PRINT_PRECISION_1 -: 87: #define TEST_PRINT_PRECISION_1 2 -: 88:#endif -: 89: -: 90:#ifndef TEST_PRINT_PRECISION_2 -: 91: #define TEST_PRINT_PRECISION_2 5 -: 92:#endif -: 93: -: 94:#ifndef GCEM_UNUSED_PAR -: 95: #define GCEM_UNUSED_PAR(x) (void)(x) -: 96:#endif -: 97: -: 98:// -: 99:// printing pass -: 100: -: 101:#ifndef TRAVIS_CLANG_CXX -: 102: -: 103:#define TEST_PASS_PRINT_FINISH \ -: 104: if (print_level > 1 && !VAL_IS_NAN(err_val)) { \ -: 105: std::cout << std::setprecision(3) << std::scientific \ -: 106: << " - error value = " << err_val << "\n"; \ -: 107: } \ -: 108: \ -: 109: std::cout << std::defaultfloat; \ -: 110: std::cout << std::endl; \ -: 111: -: 112:#else -: 113: -: 114:#define TEST_PASS_PRINT_FINISH \ -: 115: if (print_level > 1 && !VAL_IS_NAN(err_val)) { \ -: 116: std::cout << " - error value = " << err_val << "\n"; \ -: 117: } \ -: 118: \ -: 119: std::cout << std::endl; \ -: 120: -: 121:#endif -: 122: -: 123:// -: 124: -: 125:template -: 126:inline -: 127:void 24: 128:print_test_pass(std::string fn_name, const int print_level, -: 129: int print_precision_1, int print_precision_2, -: 130: const T1 f_val, const T2 err_val, -: 131: const T3 par_1) -: 132:{ 24: 133: std::cout << "[\033[32mOK\033[0m] "; -: 134: std::cout << std::setiosflags(std::ios::fixed) -: 135: << std::setprecision(print_precision_1) << fn_name 24: 136: << "(" << par_1 << ") = " 24: 137: << std::setprecision(print_precision_2) << f_val << "\n"; -: 138: 24: 139: TEST_PASS_PRINT_FINISH 24: 140:} -: 141: -: 142:template -: 143:inline -: 144:void -: 145:print_test_pass(std::string fn_name, const int print_level, -: 146: int print_precision_1, int print_precision_2, -: 147: const T1 f_val, const T2 err_val, -: 148: const T3 par_1, const T4 par_2) -: 149:{ -: 150: std::cout << "[\033[32mOK\033[0m] "; -: 151: std::cout << std::setiosflags(std::ios::fixed) -: 152: << std::setprecision(print_precision_1) << fn_name -: 153: << "(" << par_1 << "," << par_2 << ") = " -: 154: << std::setprecision(print_precision_2) << f_val << "\n"; -: 155: -: 156: TEST_PASS_PRINT_FINISH -: 157:} -: 158: -: 159:template -: 160:inline -: 161:void -: 162:print_test_pass(std::string fn_name, const int print_level, -: 163: int print_precision_1, int print_precision_2, -: 164: const T1 f_val, const T2 err_val, -: 165: const T3 par_1, const T4 par_2, const T5 par_3) -: 166:{ -: 167: std::cout << "[\033[32mOK\033[0m] "; -: 168: std::cout << std::setiosflags(std::ios::fixed) -: 169: << std::setprecision(print_precision_1) << fn_name -: 170: << "(" << par_1 << "," << par_2 << "," << par_3 << ") = " -: 171: << std::setprecision(print_precision_2) << f_val << "\n"; -: 172: -: 173: TEST_PASS_PRINT_FINISH -: 174:} -: 175: -: 176:// -: 177:// printing fail -: 178: -: 179:template -: 180:inline -: 181:void #####: 182:print_test_fail(std::string fn_name, int test_number, const int print_level, -: 183: int print_precision_1, int print_precision_2, -: 184: const T1 f_val, const T2 expected_val, -: 185: const T3 par_1) -: 186:{ -: 187: GCEM_UNUSED_PAR(print_level); -: 188: GCEM_UNUSED_PAR(print_precision_1); -: 189: GCEM_UNUSED_PAR(print_precision_2); -: 190: #####: 191: std::cerr << "\033[31m Test failed!\033[0m\n"; #####: 192: std::cerr << " - Test number: " << test_number << "\n"; -: 193: std::cerr << " - Function Call: " << fn_name #####: 194: << "(" << par_1 << ");\n"; #####: 195: std::cerr << " - Expected value: " << expected_val << "\n"; #####: 196: std::cerr << " - Actual value: " << f_val << "\n"; #####: 197: std::cerr << std::endl; -: 198: #####: 199: throw std::runtime_error("test fail"); -: 200:} -: 201: -: 202:template -: 203:inline -: 204:void -: 205:print_test_fail(std::string fn_name, int test_number, const int print_level, -: 206: int print_precision_1, int print_precision_2, -: 207: const T1 f_val, const T2 expected_val, -: 208: const T3 par_1, const T4 par_2) -: 209:{ -: 210: GCEM_UNUSED_PAR(print_level); -: 211: GCEM_UNUSED_PAR(print_precision_1); -: 212: GCEM_UNUSED_PAR(print_precision_2); -: 213: -: 214: std::cerr << "\033[31m Test failed!\033[0m\n"; -: 215: std::cerr << " - Test number: " << test_number << "\n"; -: 216: std::cerr << " - Function Call: " << fn_name -: 217: << "(" << par_1 << "," << par_2 << ");\n"; -: 218: std::cerr << " - Expected value: " << expected_val << "\n"; -: 219: std::cerr << " - Actual value: " << f_val << "\n"; -: 220: std::cerr << std::endl; -: 221: -: 222: throw std::runtime_error("test fail"); -: 223:} -: 224: -: 225:template -: 226:inline -: 227:void -: 228:print_test_fail(std::string fn_name, int test_number, const int print_level, -: 229: int print_precision_1, int print_precision_2, -: 230: const T1 f_val, const T2 expected_val, -: 231: const T3 par_1, const T4 par_2, const T5 par_3) -: 232:{ -: 233: GCEM_UNUSED_PAR(print_level); -: 234: GCEM_UNUSED_PAR(print_precision_1); -: 235: GCEM_UNUSED_PAR(print_precision_2); -: 236: -: 237: std::cerr << "\033[31m Test failed!\033[0m\n"; -: 238: std::cerr << " - Test number: " << test_number << "\n"; -: 239: std::cerr << " - Function Call: " << fn_name -: 240: << "(" << par_1 << "," << par_2 << "," << par_3 << ");\n"; -: 241: std::cerr << " - Expected value: " << expected_val << "\n"; -: 242: std::cerr << " - Actual value: " << f_val << "\n"; -: 243: std::cerr << std::endl; -: 244: -: 245: throw std::runtime_error("test fail"); -: 246:} -: 247: -: 248:// -: 249:// macros -: 250: -: 251:#define GCEM_TEST_EXPECTED_VAL(gcem_fn, expected_val, ...) \ -: 252:{ \ -: 253: ++GCEM_TEST_NUMBER; \ -: 254: std::string fn_name = #gcem_fn; \ -: 255: \ -: 256: auto f_val = gcem_fn(__VA_ARGS__); \ -: 257: \ -: 258: auto err_val = std::abs(f_val - expected_val) / (1 + std::abs(expected_val)); \ -: 259: \ -: 260: bool test_success = false; \ -: 261: \ -: 262: if (VAL_IS_NAN(expected_val) && VAL_IS_NAN(f_val)) { \ -: 263: test_success = true; \ -: 264: } else if(!VAL_IS_NAN(f_val) && VAL_IS_INF(f_val) && f_val == expected_val) { \ -: 265: test_success = true; \ -: 266: } else if(err_val < TEST_ERR_TOL) { \ -: 267: test_success = true; \ -: 268: } else { \ -: 269: print_test_fail(fn_name,GCEM_TEST_NUMBER,TEST_PRINT_LEVEL, \ -: 270: TEST_PRINT_PRECISION_1,TEST_PRINT_PRECISION_2, \ -: 271: f_val,expected_val,__VA_ARGS__); \ -: 272: } \ -: 273: \ -: 274: if (test_success && TEST_PRINT_LEVEL > 0) \ -: 275: { \ -: 276: print_test_pass(fn_name,TEST_PRINT_LEVEL, \ -: 277: TEST_PRINT_PRECISION_1,TEST_PRINT_PRECISION_2, \ -: 278: f_val,err_val,__VA_ARGS__); \ -: 279: } \ -: 280:} -: 281: -: 282:#define GCEM_TEST_COMPARE_VALS(gcem_fn, std_fn, ...) \ -: 283:{ \ -: 284: ++GCEM_TEST_NUMBER; \ -: 285: \ -: 286: std::string fn_name = #gcem_fn; \ -: 287: \ -: 288: auto gcem_fn_val = gcem_fn(__VA_ARGS__); \ -: 289: auto std_fn_val = std_fn(__VA_ARGS__); \ -: 290: \ -: 291: auto err_val = std::abs(gcem_fn_val - std_fn_val) / (1 + std::abs(std_fn_val)); \ -: 292: \ -: 293: bool test_success = false; \ -: 294: \ -: 295: if (VAL_IS_NAN(gcem_fn_val) && VAL_IS_NAN(std_fn_val)) { \ -: 296: test_success = true; \ -: 297: } else if(!VAL_IS_NAN(gcem_fn_val) && VAL_IS_INF(gcem_fn_val) && gcem_fn_val == std_fn_val) { \ -: 298: test_success = true; \ -: 299: } else if(err_val < TEST_ERR_TOL) { \ -: 300: test_success = true; \ -: 301: } else { \ -: 302: print_test_fail(fn_name,GCEM_TEST_NUMBER,TEST_PRINT_LEVEL, \ -: 303: TEST_PRINT_PRECISION_1,TEST_PRINT_PRECISION_2, \ -: 304: gcem_fn_val,std_fn_val,__VA_ARGS__); \ -: 305: } \ -: 306: \ -: 307: if (test_success && TEST_PRINT_LEVEL > 0) \ -: 308: { \ -: 309: print_test_pass(fn_name,TEST_PRINT_LEVEL, \ -: 310: TEST_PRINT_PRECISION_1,TEST_PRINT_PRECISION_2, \ -: 311: gcem_fn_val,err_val,__VA_ARGS__); \ -: 312: } \ -: 313:} -: 314: -: 315:// -: 316:// begin and end print -: 317: -: 318:inline -: 319:void 6: 320:finish_print_line(int k) -: 321:{ 334: 322: for (int i=0; i < 80 - k; ++i) { 328: 323: printf(" "); -: 324: } 6: 325: printf("#"); 6: 326:} -: 327: -: 328:inline -: 329:void 2: 330:print_begin(std::string fn_name) -: 331:{ -: 332: // GCEM_UNUSED_PAR(fn_name); -: 333: if (TEST_PRINT_LEVEL > 0) { -: 334: std::cout << 2: 335: "\n################################################################################\n"; -: 336: std::cout << 2: 337: "\n\033[36m~~~~ Begin tests for: " << fn_name << "\033[0m\n"; 2: 338: std::cout << std::endl; -: 339: } 2: 340:} -: 341: -: 342:inline -: 343:void 2: 344:print_final(std::string fn_name) -: 345:{ 2: 346: std::cout.precision(1); -: 347: -: 348: std::cout << -: 349: "################################################################################\n" << 2: 350: "# TESTS SUMMARY #\n"; -: 351: -: 352: // -: 353: -: 354: std::cout << 2: 355: "# - Test suite: " << fn_name; 2: 356: finish_print_line(14 + int(fn_name.length()) + 4); 2: 357: std::cout << std::endl; -: 358: -: 359: // -: 360: -: 361: std::cout << 2: 362: "# - Number of tests: " << GCEM_TEST_NUMBER; 2*: 363: finish_print_line(20 + (GCEM_TEST_NUMBER > 9 ? 1 : 0) + 4); 2: 364: std::cout << std::endl; -: 365: -: 366: // -: 367: -: 368: std::cout << 2: 369: "# - Error tolerance: " << std::scientific << TEST_ERR_TOL; 2: 370: finish_print_line(30); 2: 371: std::cout << std::endl; -: 372: -: 373: // -: 374: -: 375: std::cout << -: 376: "# [\033[32mPASS\033[0m] #\n" << 2: 377: "################################################################################\n"; -: 378: // -: 379: 2: 380: std::cout << std::endl; 2: 381:} <<<<<< EOF # path=tests/incomplete_beta.cpp.gcov -: 0:Source:incomplete_beta.cpp -: 0:Graph:./incomplete_beta.gcno -: 0:Data:./incomplete_beta.gcda -: 0:Runs:1 -: 1:/*################################################################################ -: 2: ## -: 3: ## Copyright (C) 2016-2022 Keith O'Hara -: 4: ## -: 5: ## This file is part of the GCE-Math C++ library. -: 6: ## -: 7: ## Licensed under the Apache License, Version 2.0 (the "License"); -: 8: ## you may not use this file except in compliance with the License. -: 9: ## You may obtain a copy of the License at -: 10: ## -: 11: ## http://www.apache.org/licenses/LICENSE-2.0 -: 12: ## -: 13: ## Unless required by applicable law or agreed to in writing, software -: 14: ## distributed under the License is distributed on an "AS IS" BASIS, -: 15: ## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -: 16: ## See the License for the specific language governing permissions and -: 17: ## limitations under the License. -: 18: ## -: 19: ################################################################################*/ -: 20: -: 21:#define TEST_PRINT_PRECISION_1 3 -: 22:#define TEST_PRINT_PRECISION_2 18 -: 23: -: 24:#include "gcem_tests.hpp" -: 25: 1: 26:int main() -: 27:{ 1: 28: print_begin("incomplete_beta"); -: 29: -: 30: // -: 31: 2*: 32: GCEM_TEST_EXPECTED_VAL(gcem::incomplete_beta, 0.11464699677582491921L, 0.9L, 0.9L, 0.1L); 2*: 33: GCEM_TEST_EXPECTED_VAL(gcem::incomplete_beta, 0.78492840804657726395L, 0.9L, 0.9L, 0.8L); -: 34: 2*: 35: GCEM_TEST_EXPECTED_VAL(gcem::incomplete_beta, 0.80000000000000004441L, 1.0L, 1.0L, 0.8L); 2*: 36: GCEM_TEST_EXPECTED_VAL(gcem::incomplete_beta, 0.89600000000000001865L, 2.0L, 2.0L, 0.8L); 2*: 37: GCEM_TEST_EXPECTED_VAL(gcem::incomplete_beta, 0.81920000000000003926L, 3.0L, 2.0L, 0.8L); -: 38: 2*: 39: GCEM_TEST_EXPECTED_VAL(gcem::incomplete_beta, 0.97279999999999999805L, 2.0L, 3.0L, 0.8L); 2*: 40: GCEM_TEST_EXPECTED_VAL(gcem::incomplete_beta, 3.9970000000000084279e-09L, 3.0L, 2.0L, 0.001L); 2*: 41: GCEM_TEST_EXPECTED_VAL(gcem::incomplete_beta, 0.35200000000000003508L, 2.0L, 2.0L, 0.4L); -: 42: 2*: 43: GCEM_TEST_EXPECTED_VAL(gcem::incomplete_beta, TEST_NAN, TEST_NAN, TEST_NAN, TEST_NAN); 2*: 44: GCEM_TEST_EXPECTED_VAL(gcem::incomplete_beta, TEST_NAN, TEST_NAN, 2.0L, 0.8L); 2*: 45: GCEM_TEST_EXPECTED_VAL(gcem::incomplete_beta, TEST_NAN, 2.0L, TEST_NAN, 0.8L); 2*: 46: GCEM_TEST_EXPECTED_VAL(gcem::incomplete_beta, TEST_NAN, 2.0L, 2.0L, TEST_NAN); -: 47: -: 48: // -: 49: 1: 50: print_final("incomplete_beta"); -: 51: 1: 52: return 0; -: 53:} <<<<<< EOF # path=tests/incomplete_beta_inv.cpp.gcov -: 0:Source:incomplete_beta_inv.cpp -: 0:Graph:./incomplete_beta_inv.gcno -: 0:Data:./incomplete_beta_inv.gcda -: 0:Runs:1 -: 1:/*################################################################################ -: 2: ## -: 3: ## Copyright (C) 2016-2022 Keith O'Hara -: 4: ## -: 5: ## This file is part of the GCE-Math C++ library. -: 6: ## -: 7: ## Licensed under the Apache License, Version 2.0 (the "License"); -: 8: ## you may not use this file except in compliance with the License. -: 9: ## You may obtain a copy of the License at -: 10: ## -: 11: ## http://www.apache.org/licenses/LICENSE-2.0 -: 12: ## -: 13: ## Unless required by applicable law or agreed to in writing, software -: 14: ## distributed under the License is distributed on an "AS IS" BASIS, -: 15: ## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -: 16: ## See the License for the specific language governing permissions and -: 17: ## limitations under the License. -: 18: ## -: 19: ################################################################################*/ -: 20: -: 21:#define TEST_PRINT_PRECISION_1 3 -: 22:#define TEST_PRINT_PRECISION_2 18 -: 23: -: 24:#include "gcem_tests.hpp" -: 25: 1: 26:int main() -: 27:{ 1: 28: print_begin("incomplete_beta_inv"); -: 29: -: 30: // -: 31: 2*: 32: GCEM_TEST_EXPECTED_VAL(gcem::incomplete_beta_inv, 0.085977260425697907276L, 0.9L, 0.9L, 0.1L); 2*: 33: GCEM_TEST_EXPECTED_VAL(gcem::incomplete_beta_inv, 0.81533908558467627081L, 0.9L, 0.9L, 0.8L); -: 34: 2*: 35: GCEM_TEST_EXPECTED_VAL(gcem::incomplete_beta_inv, 0.80000000000000004441L, 1.0L, 1.0L, 0.8L); 2*: 36: GCEM_TEST_EXPECTED_VAL(gcem::incomplete_beta_inv, 0.71285927458325959449L, 2.0L, 2.0L, 0.8L); 2*: 37: GCEM_TEST_EXPECTED_VAL(gcem::incomplete_beta_inv, 0.78768287172204876079L, 3.0L, 2.0L, 0.8L); -: 38: 2*: 39: GCEM_TEST_EXPECTED_VAL(gcem::incomplete_beta_inv, 0.58245357452433332845L, 2.0L, 3.0L, 0.8L); 2*: 40: GCEM_TEST_EXPECTED_VAL(gcem::incomplete_beta_inv, 0.064038139102833388505L, 3.0L, 2.0L, 0.001L); 2*: 41: GCEM_TEST_EXPECTED_VAL(gcem::incomplete_beta_inv, 0.43293107714773171324L, 2.0L, 2.0L, 0.4L); -: 42: -: 43: // -: 44: 2*: 45: GCEM_TEST_EXPECTED_VAL(gcem::incomplete_beta_inv, TEST_NAN, TEST_NAN, 3.0L, 0.8L); 2*: 46: GCEM_TEST_EXPECTED_VAL(gcem::incomplete_beta_inv, TEST_NAN, 3.0L, TEST_NAN, 0.8L); 2*: 47: GCEM_TEST_EXPECTED_VAL(gcem::incomplete_beta_inv, TEST_NAN, 3.0L, 3.0L, TEST_NAN); -: 48: -: 49: // -: 50: 1: 51: print_final("incomplete_beta_inv"); -: 52: 1: 53: return 0; -: 54:} <<<<<< EOF # path=tests/incomplete_gamma.cpp.gcov -: 0:Source:incomplete_gamma.cpp -: 0:Graph:./incomplete_gamma.gcno -: 0:Data:./incomplete_gamma.gcda -: 0:Runs:1 -: 1:/*################################################################################ -: 2: ## -: 3: ## Copyright (C) 2016-2022 Keith O'Hara -: 4: ## -: 5: ## This file is part of the GCE-Math C++ library. -: 6: ## -: 7: ## Licensed under the Apache License, Version 2.0 (the "License"); -: 8: ## you may not use this file except in compliance with the License. -: 9: ## You may obtain a copy of the License at -: 10: ## -: 11: ## http://www.apache.org/licenses/LICENSE-2.0 -: 12: ## -: 13: ## Unless required by applicable law or agreed to in writing, software -: 14: ## distributed under the License is distributed on an "AS IS" BASIS, -: 15: ## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -: 16: ## See the License for the specific language governing permissions and -: 17: ## limitations under the License. -: 18: ## -: 19: ################################################################################*/ -: 20: -: 21:#define TEST_ERR_TOL 1e-12 -: 22: -: 23:#define TEST_PRINT_PRECISION_1 3 -: 24:#define TEST_PRINT_PRECISION_2 18 -: 25: -: 26:#include "gcem_tests.hpp" -: 27: 1: 28:int main() -: 29:{ 1: 30: print_begin("incomplete_gamma"); -: 31: -: 32: // -: 33: 2*: 34: GCEM_TEST_EXPECTED_VAL(gcem::incomplete_gamma, 0.26424111765711527644L, 2.0L, 1.0L); 2*: 35: GCEM_TEST_EXPECTED_VAL(gcem::incomplete_gamma, 0.42759329552912134220L, 1.5L, 1.0L); -: 36: 2*: 37: GCEM_TEST_EXPECTED_VAL(gcem::incomplete_gamma, 0.80085172652854419439L, 2.0L, 3.0L); 2*: 38: GCEM_TEST_EXPECTED_VAL(gcem::incomplete_gamma, 0.95957231800548714595L, 2.0L, 5.0L); 2*: 39: GCEM_TEST_EXPECTED_VAL(gcem::incomplete_gamma, 0.99876590195913317327L, 2.0L, 9.0L); -: 40: 2*: 41: GCEM_TEST_EXPECTED_VAL(gcem::incomplete_gamma, 1.0L, 0.0L, 9.0L); 2*: 42: GCEM_TEST_EXPECTED_VAL(gcem::incomplete_gamma, 0.0L, 2.0L, 0.0L); 2*: 43: GCEM_TEST_EXPECTED_VAL(gcem::incomplete_gamma, 0.0L, 0.0L, 0.0L); -: 44: 2*: 45: GCEM_TEST_EXPECTED_VAL(gcem::incomplete_gamma, 0.47974821959920432857L, 11.5L, 11.0L); 2*: 46: GCEM_TEST_EXPECTED_VAL(gcem::incomplete_gamma, 0.75410627202774938027L, 15.5L, 18.0L); 2*: 47: GCEM_TEST_EXPECTED_VAL(gcem::incomplete_gamma, 0.43775501395596266851L, 19.0L, 18.0L); 2*: 48: GCEM_TEST_EXPECTED_VAL(gcem::incomplete_gamma, 0.43939261060849132967L, 20.0L, 19.0L); -: 49: 2*: 50: GCEM_TEST_EXPECTED_VAL(gcem::incomplete_gamma, 0.58504236243630125536L, 38.0L, 39.0L); 2*: 51: GCEM_TEST_EXPECTED_VAL(gcem::incomplete_gamma, 0.46422093592347296598L, 56.0L, 55.0L); 2*: 52: GCEM_TEST_EXPECTED_VAL(gcem::incomplete_gamma, 0.55342727426212001696L, 98.0L, 99.0L); -: 53: 2*: 54: GCEM_TEST_EXPECTED_VAL(gcem::incomplete_gamma, 0.47356929040257916830L, 102.0L, 101.0L); 2*: 55: GCEM_TEST_EXPECTED_VAL(gcem::incomplete_gamma, 0.48457398488934400049L, 298.0L, 297.0L); 2*: 56: GCEM_TEST_EXPECTED_VAL(gcem::incomplete_gamma, 0.48467673854389853316L, 302.0L, 301.0L); 2*: 57: GCEM_TEST_EXPECTED_VAL(gcem::incomplete_gamma, 0.48807306199561317772L, 498.0L, 497.0L); 2*: 58: GCEM_TEST_EXPECTED_VAL(gcem::incomplete_gamma, 0.48812074555706047585L, 502.0L, 501.0L); 2*: 59: GCEM_TEST_EXPECTED_VAL(gcem::incomplete_gamma, 0.51881664512582725823L, 798.0L, 799.0L); 2*: 60: GCEM_TEST_EXPECTED_VAL(gcem::incomplete_gamma, 0.49059834200005758564L, 801.0L, 800.0L); 2*: 61: GCEM_TEST_EXPECTED_VAL(gcem::incomplete_gamma, 0.52943655952003709775L, 997.0L, 999.0L); 2*: 62: GCEM_TEST_EXPECTED_VAL(gcem::incomplete_gamma, 0.45389544705967349580L, 1005.0L, 1001.0L); -: 63: 2*: 64: GCEM_TEST_EXPECTED_VAL(gcem::incomplete_gamma, 0.99947774194996708008L, 3.0L, 12.0L); 2*: 65: GCEM_TEST_EXPECTED_VAL(gcem::incomplete_gamma, 0.99914335878922466705L, 5.0L, 15.0L); 2*: 66: GCEM_TEST_EXPECTED_VAL(gcem::incomplete_gamma, 0.99998305525606989708L, 5.0L, 20.0L); 2*: 67: GCEM_TEST_EXPECTED_VAL(gcem::incomplete_gamma, 0.99999973309165746116L, 5.0L, 25.0L); 2*: 68: GCEM_TEST_EXPECTED_VAL(gcem::incomplete_gamma, 0.99999999995566213329L, 5.0L, 35.0L); 2*: 69: GCEM_TEST_EXPECTED_VAL(gcem::incomplete_gamma, 1.0L , 5.0L, 50.0L); 2*: 70: GCEM_TEST_EXPECTED_VAL(gcem::incomplete_gamma, 1.0L , 5.0L, 500.0L); 2*: 71: GCEM_TEST_EXPECTED_VAL(gcem::incomplete_gamma, 0.99791274095086501816L, 9.0L, 20.0L); 2*: 72: GCEM_TEST_EXPECTED_VAL(gcem::incomplete_gamma, 0.99999999914307291515L, 9.0L, 40.0L); -: 73: 2*: 74: GCEM_TEST_EXPECTED_VAL(gcem::incomplete_gamma, 0.88153558847098478779L, 11.0L, 15.0L); 2*: 75: GCEM_TEST_EXPECTED_VAL(gcem::incomplete_gamma, 0.98918828117334733907L, 11.0L, 20.0L); 2*: 76: GCEM_TEST_EXPECTED_VAL(gcem::incomplete_gamma, 0.99941353837024693441L, 11.0L, 25.0L); 2*: 77: GCEM_TEST_EXPECTED_VAL(gcem::incomplete_gamma, 0.99999933855955824846L, 11.0L, 35.0L); 2*: 78: GCEM_TEST_EXPECTED_VAL(gcem::incomplete_gamma, 0.99999999999354982627L, 11.0L, 50.0L); 2*: 79: GCEM_TEST_EXPECTED_VAL(gcem::incomplete_gamma, 1.0L , 11.0L, 500.0L); -: 80: -: 81: // -: 82: 2*: 83: GCEM_TEST_EXPECTED_VAL(gcem::incomplete_gamma, TEST_NAN, -0.1, 0.0); -: 84: 2*: 85: GCEM_TEST_EXPECTED_VAL(gcem::incomplete_gamma, TEST_NAN, TEST_NAN, TEST_NAN); 2*: 86: GCEM_TEST_EXPECTED_VAL(gcem::incomplete_gamma, TEST_NAN, TEST_NAN, 3.0L); 2*: 87: GCEM_TEST_EXPECTED_VAL(gcem::incomplete_gamma, TEST_NAN, 2.0L, TEST_NAN); -: 88: -: 89: // -: 90: 1: 91: print_final("incomplete_gamma"); -: 92: 1: 93: return 0; -: 94:} <<<<<< EOF # path=tests/incomplete_gamma.hpp.gcov -: 0:Source:../include/gcem_incl/incomplete_gamma.hpp -: 0:Graph:./incomplete_gamma_inv.gcno -: 0:Data:./incomplete_gamma_inv.gcda -: 0:Runs:1 -: 1:/*################################################################################ -: 2: ## -: 3: ## Copyright (C) 2016-2022 Keith O'Hara -: 4: ## -: 5: ## This file is part of the GCE-Math C++ library. -: 6: ## -: 7: ## Licensed under the Apache License, Version 2.0 (the "License"); -: 8: ## you may not use this file except in compliance with the License. -: 9: ## You may obtain a copy of the License at -: 10: ## -: 11: ## http://www.apache.org/licenses/LICENSE-2.0 -: 12: ## -: 13: ## Unless required by applicable law or agreed to in writing, software -: 14: ## distributed under the License is distributed on an "AS IS" BASIS, -: 15: ## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -: 16: ## See the License for the specific language governing permissions and -: 17: ## limitations under the License. -: 18: ## -: 19: ################################################################################*/ -: 20: -: 21:/* -: 22: * compile-time (regularized) incomplete gamma function -: 23: */ -: 24: -: 25:#ifndef _gcem_incomplete_gamma_HPP -: 26:#define _gcem_incomplete_gamma_HPP -: 27: -: 28:namespace internal -: 29:{ -: 30: -: 31:// 50 point Gauss-Legendre quadrature -: 32: -: 33:template -: 34:constexpr -: 35:T 28800: 36:incomplete_gamma_quad_inp_vals(const T lb, const T ub, const int counter) -: 37:noexcept -: 38:{ 28800: 39: return (ub-lb) * gauss_legendre_50_points[counter] / T(2) + (ub + lb) / T(2); -: 40:} -: 41: -: 42:template -: 43:constexpr -: 44:T 28800: 45:incomplete_gamma_quad_weight_vals(const T lb, const T ub, const int counter) -: 46:noexcept -: 47:{ 28800: 48: return (ub-lb) * gauss_legendre_50_weights[counter] / T(2); -: 49:} -: 50: -: 51:template -: 52:constexpr -: 53:T 28800: 54:incomplete_gamma_quad_fn(const T x, const T a, const T lg_term) -: 55:noexcept -: 56:{ 28800: 57: return exp( -x + (a-T(1))*log(x) - lg_term ); -: 58:} -: 59: -: 60:template -: 61:constexpr -: 62:T 28800: 63:incomplete_gamma_quad_recur(const T lb, const T ub, const T a, const T lg_term, const int counter) -: 64:noexcept -: 65:{ 57600: 66: return( counter < 49 ? \ -: 67: // if 28224: 68: incomplete_gamma_quad_fn(incomplete_gamma_quad_inp_vals(lb,ub,counter),a,lg_term) \ 28224: 69: * incomplete_gamma_quad_weight_vals(lb,ub,counter) \ 28224: 70: + incomplete_gamma_quad_recur(lb,ub,a,lg_term,counter+1) : -: 71: // else 576: 72: incomplete_gamma_quad_fn(incomplete_gamma_quad_inp_vals(lb,ub,counter),a,lg_term) \ 29376: 73: * incomplete_gamma_quad_weight_vals(lb,ub,counter) ); -: 74:} -: 75: -: 76:template -: 77:constexpr -: 78:T 576: 79:incomplete_gamma_quad_lb(const T a, const T z) -: 80:noexcept -: 81:{ 1116: 82: return( a > T(1000) ? max(T(0),min(z,a) - 11*sqrt(a)) : // break integration into ranges 1008: 83: a > T(800) ? max(T(0),min(z,a) - 11*sqrt(a)) : 864: 84: a > T(500) ? max(T(0),min(z,a) - 10*sqrt(a)) : 720: 85: a > T(300) ? max(T(0),min(z,a) - 10*sqrt(a)) : 576: 86: a > T(100) ? max(T(0),min(z,a) - 9*sqrt(a)) : 468: 87: a > T(90) ? max(T(0),min(z,a) - 9*sqrt(a)) : 432*: 88: a > T(70) ? max(T(0),min(z,a) - 8*sqrt(a)) : 396: 89: a > T(50) ? max(T(0),min(z,a) - 7*sqrt(a)) : 360*: 90: a > T(40) ? max(T(0),min(z,a) - 6*sqrt(a)) : 180: 91: a > T(30) ? max(T(0),min(z,a) - 5*sqrt(a)) : -: 92: // else 720: 93: max(T(0),min(z,a)-4*sqrt(a)) ); -: 94:} -: 95: -: 96:template -: 97:constexpr -: 98:T 576: 99:incomplete_gamma_quad_ub(const T a, const T z) -: 100:noexcept -: 101:{ 1116: 102: return( a > T(1000) ? min(z, a + 10*sqrt(a)) : 1008: 103: a > T(800) ? min(z, a + 10*sqrt(a)) : 864: 104: a > T(500) ? min(z, a + 9*sqrt(a)) : 720: 105: a > T(300) ? min(z, a + 9*sqrt(a)) : 576: 106: a > T(100) ? min(z, a + 8*sqrt(a)) : 468: 107: a > T(90) ? min(z, a + 8*sqrt(a)) : 432*: 108: a > T(70) ? min(z, a + 7*sqrt(a)) : 216: 109: a > T(50) ? min(z, a + 6*sqrt(a)) : -: 110: // else 756: 111: min(z, a + 5*sqrt(a)) ); -: 112:} -: 113: -: 114:template -: 115:constexpr -: 116:T 576: 117:incomplete_gamma_quad(const T a, const T z) -: 118:noexcept -: 119:{ 576: 120: return incomplete_gamma_quad_recur(incomplete_gamma_quad_lb(a,z), incomplete_gamma_quad_ub(a,z), a,lgamma(a),0); -: 121:} -: 122: -: 123:// reverse cf expansion -: 124:// see: https://functions.wolfram.com/GammaBetaErf/Gamma2/10/0003/ -: 125: -: 126:template -: 127:constexpr -: 128:T #####: 129:incomplete_gamma_cf_2_recur(const T a, const T z, const int depth) -: 130:noexcept -: 131:{ #####: 132: return( depth < 100 ? \ -: 133: // if #####: 134: (1 + (depth-1)*2 - a + z) + depth*(a - depth)/incomplete_gamma_cf_2_recur(a,z,depth+1) : -: 135: // else #####: 136: (1 + (depth-1)*2 - a + z) ); -: 137:} -: 138: -: 139:template -: 140:constexpr -: 141:T #####: 142:incomplete_gamma_cf_2(const T a, const T z) -: 143:noexcept -: 144:{ // lower (regularized) incomplete gamma function #####: 145: return( T(1.0) - exp(a*log(z) - z - lgamma(a)) / incomplete_gamma_cf_2_recur(a,z,1) ); -: 146:} -: 147: -: 148:// cf expansion -: 149:// see: http://functions.wolfram.com/GammaBetaErf/Gamma2/10/0009/ -: 150: -: 151:template -: 152:constexpr -: 153:T #####: 154:incomplete_gamma_cf_1_coef(const T a, const T z, const int depth) -: 155:noexcept -: 156:{ #####: 157: return( is_odd(depth) ? - (a - 1 + T(depth+1)/T(2)) * z : T(depth)/T(2) * z ); -: 158:} -: 159: -: 160:template -: 161:constexpr -: 162:T #####: 163:incomplete_gamma_cf_1_recur(const T a, const T z, const int depth) -: 164:noexcept -: 165:{ #####: 166: return( depth < GCEM_INCML_GAMMA_MAX_ITER ? \ -: 167: // if #####: 168: (a + depth - 1) + incomplete_gamma_cf_1_coef(a,z,depth)/incomplete_gamma_cf_1_recur(a,z,depth+1) : -: 169: // else #####: 170: (a + depth - 1) ); -: 171:} -: 172: -: 173:template -: 174:constexpr -: 175:T #####: 176:incomplete_gamma_cf_1(const T a, const T z) -: 177:noexcept -: 178:{ // lower (regularized) incomplete gamma function #####: 179: return( exp(a*log(z) - z - lgamma(a)) / incomplete_gamma_cf_1_recur(a,z,1) ); -: 180:} -: 181: -: 182:// -: 183: -: 184:template -: 185:constexpr -: 186:T 576: 187:incomplete_gamma_check(const T a, const T z) -: 188:noexcept -: 189:{ -: 190: return( // NaN check 1152: 191: any_nan(a, z) ? \ #####: 192: GCLIM::quiet_NaN() : -: 193: // 1152: 194: a < T(0) ? \ #####: 195: GCLIM::quiet_NaN() : -: 196: // 1152*: 197: GCLIM::min() > z ? \ -: 198: T(0) : -: 199: // 1152*: 200: GCLIM::min() > a ? \ -: 201: T(1) : -: 202: // cf or quadrature 1152*: 203: (a < T(10)) && (z - a < T(10)) ? #####: 204: incomplete_gamma_cf_1(a,z) : 576: 205: (a < T(10)) || (z/a > T(3)) ? #####: 206: incomplete_gamma_cf_2(a,z) : -: 207: // else 1152: 208: incomplete_gamma_quad(a,z) ); -: 209:} -: 210: -: 211:template> -: 212:constexpr -: 213:TC 576: 214:incomplete_gamma_type_check(const T1 a, const T2 p) -: 215:noexcept -: 216:{ 576: 217: return incomplete_gamma_check(static_cast(a), 576: 218: static_cast(p)); -: 219:} -: 220: -: 221:} -: 222: -: 223:/** -: 224: * Compile-time regularized lower incomplete gamma function -: 225: * -: 226: * @param a a real-valued, non-negative input. -: 227: * @param x a real-valued, non-negative input. -: 228: * -: 229: * @return the regularized lower incomplete gamma function evaluated at (\c a, \c x), -: 230: * \f[ \frac{\gamma(a,x)}{\Gamma(a)} = \frac{1}{\Gamma(a)} \int_0^x t^{a-1} \exp(-t) dt \f] -: 231: * When \c a is not too large, the value is computed using the continued fraction representation of the upper incomplete gamma function, \f$ \Gamma(a,x) \f$, using -: 232: * \f[ \Gamma(a,x) = \Gamma(a) - \dfrac{x^a\exp(-x)}{a - \dfrac{ax}{a + 1 + \dfrac{x}{a + 2 - \dfrac{(a+1)x}{a + 3 + \dfrac{2x}{a + 4 - \ddots}}}}} \f] -: 233: * where \f$ \gamma(a,x) \f$ and \f$ \Gamma(a,x) \f$ are connected via -: 234: * \f[ \frac{\gamma(a,x)}{\Gamma(a)} + \frac{\Gamma(a,x)}{\Gamma(a)} = 1 \f] -: 235: * When \f$ a > 10 \f$, a 50-point Gauss-Legendre quadrature scheme is employed. -: 236: */ -: 237: -: 238:template -: 239:constexpr -: 240:common_return_t 576: 241:incomplete_gamma(const T1 a, const T2 x) -: 242:noexcept -: 243:{ 576: 244: return internal::incomplete_gamma_type_check(a,x); -: 245:} -: 246: -: 247:#endif <<<<<< EOF # path=tests/incomplete_gamma_inv.cpp.gcov -: 0:Source:incomplete_gamma_inv.cpp -: 0:Graph:./incomplete_gamma_inv.gcno -: 0:Data:./incomplete_gamma_inv.gcda -: 0:Runs:1 -: 1:/*################################################################################ -: 2: ## -: 3: ## Copyright (C) 2016-2022 Keith O'Hara -: 4: ## -: 5: ## This file is part of the GCE-Math C++ library. -: 6: ## -: 7: ## Licensed under the Apache License, Version 2.0 (the "License"); -: 8: ## you may not use this file except in compliance with the License. -: 9: ## You may obtain a copy of the License at -: 10: ## -: 11: ## http://www.apache.org/licenses/LICENSE-2.0 -: 12: ## -: 13: ## Unless required by applicable law or agreed to in writing, software -: 14: ## distributed under the License is distributed on an "AS IS" BASIS, -: 15: ## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -: 16: ## See the License for the specific language governing permissions and -: 17: ## limitations under the License. -: 18: ## -: 19: ################################################################################*/ -: 20: -: 21:#ifndef _WIN32 -: 22: #define TEST_ERR_TOL 1e-12 -: 23:#endif -: 24: -: 25:#define TEST_PRINT_PRECISION_1 3 -: 26:#define TEST_PRINT_PRECISION_2 18 -: 27: -: 28:#include "gcem_tests.hpp" -: 29: 1: 30:int main() -: 31:{ 1: 32: print_begin("incomplete_gamma_inv"); -: 33: -: 34: // -: 35: 2*: 36: GCEM_TEST_EXPECTED_VAL(gcem::incomplete_gamma_inv, 1.0L, 2.0L, 0.26424111765711527644L); 2*: 37: GCEM_TEST_EXPECTED_VAL(gcem::incomplete_gamma_inv, 1.0L, 1.5L, 0.42759329552912134220L); -: 38: 2*: 39: GCEM_TEST_EXPECTED_VAL(gcem::incomplete_gamma_inv, 3.0L, 2.0L, 0.80085172652854419439L); 2*: 40: GCEM_TEST_EXPECTED_VAL(gcem::incomplete_gamma_inv, 5.0L, 2.0L, 0.95957231800548714595L); 2*: 41: GCEM_TEST_EXPECTED_VAL(gcem::incomplete_gamma_inv, 9.0L, 2.0L, 0.99876590195913317327L); -: 42: 2*: 43: GCEM_TEST_EXPECTED_VAL(gcem::incomplete_gamma_inv, TEST_POSINF, 0.0L, 1.0L); 2*: 44: GCEM_TEST_EXPECTED_VAL(gcem::incomplete_gamma_inv, 0.0L, 2.0L, 0.0L); 2*: 45: GCEM_TEST_EXPECTED_VAL(gcem::incomplete_gamma_inv, 0.0L, 0.0L, 0.0L); -: 46: 2*: 47: GCEM_TEST_EXPECTED_VAL(gcem::incomplete_gamma_inv, 11.0L, 11.5L, 0.47974821959920432857L); 2*: 48: GCEM_TEST_EXPECTED_VAL(gcem::incomplete_gamma_inv, 18.0L, 15.5L, 0.75410627202774938027L); 2*: 49: GCEM_TEST_EXPECTED_VAL(gcem::incomplete_gamma_inv, 18.0L, 19.0L, 0.43775501395596266851L); 2*: 50: GCEM_TEST_EXPECTED_VAL(gcem::incomplete_gamma_inv, 19.0L, 20.0L, 0.43939261060849132967L); -: 51: 2*: 52: GCEM_TEST_EXPECTED_VAL(gcem::incomplete_gamma_inv, 39.0L, 38.0L, 0.58504236243630125536L); 2*: 53: GCEM_TEST_EXPECTED_VAL(gcem::incomplete_gamma_inv, 55.0L, 56.0L, 0.46422093592347296598L); 2*: 54: GCEM_TEST_EXPECTED_VAL(gcem::incomplete_gamma_inv, 99.0L, 98.0L, 0.55342727426212001696L); -: 55: 2*: 56: GCEM_TEST_EXPECTED_VAL(gcem::incomplete_gamma_inv, 101.0L, 102.0L, 0.47356929040257916830L); 2*: 57: GCEM_TEST_EXPECTED_VAL(gcem::incomplete_gamma_inv, 297.0L, 298.0L, 0.48457398488934400049L); 2*: 58: GCEM_TEST_EXPECTED_VAL(gcem::incomplete_gamma_inv, 301.0L, 302.0L, 0.48467673854389853316L); 2*: 59: GCEM_TEST_EXPECTED_VAL(gcem::incomplete_gamma_inv, 497.0L, 498.0L, 0.48807306199561317772L); 2*: 60: GCEM_TEST_EXPECTED_VAL(gcem::incomplete_gamma_inv, 501.0L, 502.0L, 0.48812074555706047585L); 2*: 61: GCEM_TEST_EXPECTED_VAL(gcem::incomplete_gamma_inv, 799.0L, 798.0L, 0.51881664512582725823L); 2*: 62: GCEM_TEST_EXPECTED_VAL(gcem::incomplete_gamma_inv, 800.0L, 801.0L, 0.49059834200005758564L); 2*: 63: GCEM_TEST_EXPECTED_VAL(gcem::incomplete_gamma_inv, 999.0L, 997.0L, 0.52943655952003709775L); 2*: 64: GCEM_TEST_EXPECTED_VAL(gcem::incomplete_gamma_inv, 1001.0L, 1005.0L, 0.45389544705967349580L); -: 65: -: 66: // -: 67: 2*: 68: GCEM_TEST_EXPECTED_VAL(gcem::incomplete_gamma_inv, TEST_NAN, TEST_NAN, TEST_NAN); 2*: 69: GCEM_TEST_EXPECTED_VAL(gcem::incomplete_gamma_inv, TEST_NAN, TEST_NAN, 0.5L); 2*: 70: GCEM_TEST_EXPECTED_VAL(gcem::incomplete_gamma_inv, TEST_NAN, 2.0L, TEST_NAN); -: 71: -: 72: // -: 73: 1: 74: print_final("incomplete_gamma_inv"); -: 75: 1: 76: return 0; -: 77:} <<<<<< EOF # path=tests/incomplete_gamma_inv.hpp.gcov -: 0:Source:../include/gcem_incl/incomplete_gamma_inv.hpp -: 0:Graph:./incomplete_gamma_inv.gcno -: 0:Data:./incomplete_gamma_inv.gcda -: 0:Runs:1 -: 1:/*################################################################################ -: 2: ## -: 3: ## Copyright (C) 2016-2022 Keith O'Hara -: 4: ## -: 5: ## This file is part of the GCE-Math C++ library. -: 6: ## -: 7: ## Licensed under the Apache License, Version 2.0 (the "License"); -: 8: ## you may not use this file except in compliance with the License. -: 9: ## You may obtain a copy of the License at -: 10: ## -: 11: ## http://www.apache.org/licenses/LICENSE-2.0 -: 12: ## -: 13: ## Unless required by applicable law or agreed to in writing, software -: 14: ## distributed under the License is distributed on an "AS IS" BASIS, -: 15: ## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -: 16: ## See the License for the specific language governing permissions and -: 17: ## limitations under the License. -: 18: ## -: 19: ################################################################################*/ -: 20: -: 21:/* -: 22: * inverse of the incomplete gamma function -: 23: */ -: 24: -: 25:#ifndef _gcem_incomplete_gamma_inv_HPP -: 26:#define _gcem_incomplete_gamma_inv_HPP -: 27: -: 28:namespace internal -: 29:{ -: 30: -: 31:template -: 32:constexpr T incomplete_gamma_inv_decision(const T value, const T a, const T p, const T direc, const T lg_val, const int iter_count) noexcept; -: 33: -: 34:// -: 35:// initial value for Halley -: 36: -: 37:template -: 38:constexpr -: 39:T 16: 40:incomplete_gamma_inv_t_val_1(const T p) -: 41:noexcept -: 42:{ // a > 1.0 16: 43: return( p > T(0.5) ? sqrt(-2*log(T(1) - p)) : sqrt(-2*log(p)) ); -: 44:} -: 45: -: 46:template -: 47:constexpr -: 48:T #####: 49:incomplete_gamma_inv_t_val_2(const T a) -: 50:noexcept -: 51:{ // a <= 1.0 #####: 52: return( T(1) - T(0.253) * a - T(0.12) * a*a ); -: 53:} -: 54: -: 55:// -: 56: -: 57:template -: 58:constexpr -: 59:T 16: 60:incomplete_gamma_inv_initial_val_1_int_begin(const T t_val) -: 61:noexcept -: 62:{ // internal for a > 1.0 16: 63: return( t_val - (T(2.515517L) + T(0.802853L)*t_val + T(0.010328L)*t_val*t_val) \ 16: 64: / (T(1) + T(1.432788L)*t_val + T(0.189269L)*t_val*t_val + T(0.001308L)*t_val*t_val*t_val) ); -: 65:} -: 66: -: 67:template -: 68:constexpr -: 69:T 16: 70:incomplete_gamma_inv_initial_val_1_int_end(const T value_inp, const T a) -: 71:noexcept -: 72:{ // internal for a > 1.0 16: 73: return max( T(1E-04), a*pow(T(1) - T(1)/(9*a) - value_inp/(3*sqrt(a)), 3) ); -: 74:} -: 75: -: 76:template -: 77:constexpr -: 78:T 16: 79:incomplete_gamma_inv_initial_val_1(const T a, const T t_val, const T sgn_term) -: 80:noexcept -: 81:{ // a > 1.0 16: 82: return incomplete_gamma_inv_initial_val_1_int_end(sgn_term*incomplete_gamma_inv_initial_val_1_int_begin(t_val), a); -: 83:} -: 84: -: 85:template -: 86:constexpr -: 87:T #####: 88:incomplete_gamma_inv_initial_val_2(const T a, const T p, const T t_val) -: 89:noexcept -: 90:{ // a <= 1.0 #####: 91: return( p < t_val ? \ -: 92: // if #####: 93: pow(p/t_val,T(1)/a) : -: 94: // else #####: 95: T(1) - log(T(1) - (p - t_val)/(T(1) - t_val)) ); -: 96:} -: 97: -: 98:// initial value -: 99: -: 100:template -: 101:constexpr -: 102:T 16: 103:incomplete_gamma_inv_initial_val(const T a, const T p) -: 104:noexcept -: 105:{ 16: 106: return( a > T(1) ? \ -: 107: // if 16: 108: incomplete_gamma_inv_initial_val_1(a, -: 109: incomplete_gamma_inv_t_val_1(p), -: 110: p > T(0.5) ? T(-1) : T(1)) : -: 111: // else #####: 112: incomplete_gamma_inv_initial_val_2(a,p, 16: 113: incomplete_gamma_inv_t_val_2(a))); -: 114:} -: 115: -: 116:// -: 117:// Halley recursion -: 118: -: 119:template -: 120:constexpr -: 121:T 576: 122:incomplete_gamma_inv_err_val(const T value, const T a, const T p) -: 123:noexcept -: 124:{ // err_val = f(x) 576: 125: return( incomplete_gamma(a,value) - p ); -: 126:} -: 127: -: 128:template -: 129:constexpr -: 130:T 576: 131:incomplete_gamma_inv_deriv_1(const T value, const T a, const T lg_val) -: 132:noexcept -: 133:{ // derivative of the incomplete gamma function w.r.t. x 576: 134: return( exp( - value + (a - T(1))*log(value) - lg_val ) ); -: 135:} -: 136: -: 137:template -: 138:constexpr -: 139:T 576: 140:incomplete_gamma_inv_deriv_2(const T value, const T a, const T deriv_1) -: 141:noexcept -: 142:{ // second derivative of the incomplete gamma function w.r.t. x 576: 143: return( deriv_1*((a - T(1))/value - T(1)) ); -: 144:} -: 145: -: 146:template -: 147:constexpr -: 148:T 576: 149:incomplete_gamma_inv_ratio_val_1(const T value, const T a, const T p, const T deriv_1) -: 150:noexcept -: 151:{ 576: 152: return( incomplete_gamma_inv_err_val(value,a,p) / deriv_1 ); -: 153:} -: 154: -: 155:template -: 156:constexpr -: 157:T 576: 158:incomplete_gamma_inv_ratio_val_2(const T value, const T a, const T deriv_1) -: 159:noexcept -: 160:{ 576: 161: return( incomplete_gamma_inv_deriv_2(value,a,deriv_1) / deriv_1 ); -: 162:} -: 163: -: 164:template -: 165:constexpr -: 166:T 576: 167:incomplete_gamma_inv_halley(const T ratio_val_1, const T ratio_val_2) -: 168:noexcept -: 169:{ 576: 170: return( ratio_val_1 / max( T(0.8), min( T(1.2), T(1) - T(0.5)*ratio_val_1*ratio_val_2 ) ) ); -: 171:} -: 172: -: 173:template -: 174:constexpr -: 175:T 576: 176:incomplete_gamma_inv_recur(const T value, const T a, const T p, const T deriv_1, const T lg_val, const int iter_count) -: 177:noexcept -: 178:{ 576: 179: return incomplete_gamma_inv_decision(value, a, p, -: 180: incomplete_gamma_inv_halley(incomplete_gamma_inv_ratio_val_1(value,a,p,deriv_1), -: 181: incomplete_gamma_inv_ratio_val_2(value,a,deriv_1)), 576: 182: lg_val, iter_count); -: 183:} -: 184: -: 185:template -: 186:constexpr -: 187:T 576: 188:incomplete_gamma_inv_decision(const T value, const T a, const T p, const T direc, const T lg_val, const int iter_count) -: 189:noexcept -: 190:{ -: 191: // return( abs(direc) > GCEM_INCML_GAMMA_INV_TOL ? incomplete_gamma_inv_recur(value - direc, a, p, incomplete_gamma_inv_deriv_1(value,a,lg_val), lg_val) : value - direc ); 576: 192: return( iter_count <= GCEM_INCML_GAMMA_INV_MAX_ITER ? \ -: 193: // if 560: 194: incomplete_gamma_inv_recur(value-direc,a,p, -: 195: incomplete_gamma_inv_deriv_1(value,a,lg_val), -: 196: lg_val,iter_count+1) : -: 197: // else 576: 198: value - direc ); -: 199:} -: 200: -: 201:template -: 202:constexpr -: 203:T 16: 204:incomplete_gamma_inv_begin(const T initial_val, const T a, const T p, const T lg_val) -: 205:noexcept -: 206:{ 16: 207: return incomplete_gamma_inv_recur(initial_val,a,p, 16: 208: incomplete_gamma_inv_deriv_1(initial_val,a,lg_val), lg_val,1); -: 209:} -: 210: -: 211:template -: 212:constexpr -: 213:T 16: 214:incomplete_gamma_inv_check(const T a, const T p) -: 215:noexcept -: 216:{ -: 217: return( // NaN check 32: 218: any_nan(a, p) ? \ #####: 219: GCLIM::quiet_NaN() : -: 220: // 32*: 221: GCLIM::min() > p ? \ -: 222: T(0) : 32: 223: p > T(1) ? \ #####: 224: GCLIM::quiet_NaN() : 32: 225: GCLIM::min() > abs(T(1) - p) ? \ #####: 226: GCLIM::infinity() : -: 227: // 16*: 228: GCLIM::min() > a ? \ -: 229: T(0) : -: 230: // else 32: 231: incomplete_gamma_inv_begin(incomplete_gamma_inv_initial_val(a,p),a,p,lgamma(a)) ); -: 232:} -: 233: -: 234:template> -: 235:constexpr -: 236:TC 16: 237:incomplete_gamma_inv_type_check(const T1 a, const T2 p) -: 238:noexcept -: 239:{ 16: 240: return incomplete_gamma_inv_check(static_cast(a), 16: 241: static_cast(p)); -: 242:} -: 243: -: 244:} -: 245: -: 246:/** -: 247: * Compile-time inverse incomplete gamma function -: 248: * -: 249: * @param a a real-valued, non-negative input. -: 250: * @param p a real-valued input with values in the unit-interval. -: 251: * -: 252: * @return Computes the inverse incomplete gamma function, a value \f$ x \f$ such that -: 253: * \f[ f(x) := \frac{\gamma(a,x)}{\Gamma(a)} - p \f] -: 254: * equal to zero, for a given \c p. -: 255: * GCE-Math finds this root using Halley's method: -: 256: * \f[ x_{n+1} = x_n - \frac{f(x_n)/f'(x_n)}{1 - 0.5 \frac{f(x_n)}{f'(x_n)} \frac{f''(x_n)}{f'(x_n)} } \f] -: 257: * where -: 258: * \f[ \frac{\partial}{\partial x} \left(\frac{\gamma(a,x)}{\Gamma(a)}\right) = \frac{1}{\Gamma(a)} x^{a-1} \exp(-x) \f] -: 259: * \f[ \frac{\partial^2}{\partial x^2} \left(\frac{\gamma(a,x)}{\Gamma(a)}\right) = \frac{1}{\Gamma(a)} x^{a-1} \exp(-x) \left( \frac{a-1}{x} - 1 \right) \f] -: 260: */ -: 261: -: 262:template -: 263:constexpr -: 264:common_return_t 16: 265:incomplete_gamma_inv(const T1 a, const T2 p) -: 266:noexcept -: 267:{ 16: 268: return internal::incomplete_gamma_inv_type_check(a,p); -: 269:} -: 270: -: 271:#endif <<<<<< EOF # path=tests/inv_sqrt.cpp.gcov -: 0:Source:inv_sqrt.cpp -: 0:Graph:./inv_sqrt.gcno -: 0:Data:./inv_sqrt.gcda -: 0:Runs:1 -: 1:/*################################################################################ -: 2: ## -: 3: ## Copyright (C) 2016-2022 Keith O'Hara -: 4: ## -: 5: ## This file is part of the GCE-Math C++ library. -: 6: ## -: 7: ## Licensed under the Apache License, Version 2.0 (the "License"); -: 8: ## you may not use this file except in compliance with the License. -: 9: ## You may obtain a copy of the License at -: 10: ## -: 11: ## http://www.apache.org/licenses/LICENSE-2.0 -: 12: ## -: 13: ## Unless required by applicable law or agreed to in writing, software -: 14: ## distributed under the License is distributed on an "AS IS" BASIS, -: 15: ## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -: 16: ## See the License for the specific language governing permissions and -: 17: ## limitations under the License. -: 18: ## -: 19: ################################################################################*/ -: 20: -: 21:#define TEST_PRINT_PRECISION_1 6 -: 22:#define TEST_PRINT_PRECISION_2 18 -: 23: -: 24:#include "gcem_tests.hpp" -: 25: -: 26:template -: 27:constexpr -: 28:T 5: 29:std_test_fn(const T x) -: 30:{ 5: 31: return T(1) / std::sqrt(x); -: 32:} -: 33: 1: 34:int main() -: 35:{ 1: 36: print_begin("sqrt"); -: 37: -: 38: // -: 39: 2*: 40: GCEM_TEST_COMPARE_VALS(gcem::inv_sqrt, std_test_fn, 0.5L); 2*: 41: GCEM_TEST_COMPARE_VALS(gcem::inv_sqrt, std_test_fn, 0.00199900000000000208L); 2*: 42: GCEM_TEST_COMPARE_VALS(gcem::inv_sqrt, std_test_fn, 1.5L); 2*: 43: GCEM_TEST_COMPARE_VALS(gcem::inv_sqrt, std_test_fn, 2.0L); 2*: 44: GCEM_TEST_COMPARE_VALS(gcem::inv_sqrt, std_test_fn, 41.5L); 2*: 45: GCEM_TEST_COMPARE_VALS(gcem::inv_sqrt, std_test_fn, 0.0L); 2*: 46: GCEM_TEST_COMPARE_VALS(gcem::inv_sqrt, std_test_fn, -1.0L); -: 47: 2*: 48: GCEM_TEST_COMPARE_VALS(gcem::inv_sqrt, std_test_fn, -std::numeric_limits::infinity()); 2*: 49: GCEM_TEST_COMPARE_VALS(gcem::inv_sqrt, std_test_fn, std::numeric_limits::infinity()); 2*: 50: GCEM_TEST_COMPARE_VALS(gcem::inv_sqrt, std_test_fn, std::numeric_limits::quiet_NaN()); -: 51: -: 52: // -: 53: 1: 54: print_final("sqrt"); -: 55: 1: 56: return 0; -: 57:} <<<<<< EOF # path=tests/iomanip.gcov -: 0:Source:/usr/include/c++/9/iomanip -: 0:Graph:log.gcno -: 0:Data:log.gcda -: 0:Runs:2 -: 1:// Standard stream manipulators -*- C++ -*- -: 2: -: 3:// Copyright (C) 1997-2019 Free Software Foundation, Inc. -: 4:// -: 5:// This file is part of the GNU ISO C++ Library. This library is free -: 6:// software; you can redistribute it and/or modify it under the -: 7:// terms of the GNU General Public License as published by the -: 8:// Free Software Foundation; either version 3, or (at your option) -: 9:// any later version. -: 10: -: 11:// This library is distributed in the hope that it will be useful, -: 12:// but WITHOUT ANY WARRANTY; without even the implied warranty of -: 13:// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -: 14:// GNU General Public License for more details. -: 15: -: 16:// Under Section 7 of GPL version 3, you are granted additional -: 17:// permissions described in the GCC Runtime Library Exception, version -: 18:// 3.1, as published by the Free Software Foundation. -: 19: -: 20:// You should have received a copy of the GNU General Public License and -: 21:// a copy of the GCC Runtime Library Exception along with this program; -: 22:// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see -: 23:// . -: 24: -: 25:/** @file include/iomanip -: 26: * This is a Standard C++ Library header. -: 27: */ -: 28: -: 29:// -: 30:// ISO C++ 14882: 27.6.3 Standard manipulators -: 31:// -: 32: -: 33:#ifndef _GLIBCXX_IOMANIP -: 34:#define _GLIBCXX_IOMANIP 1 -: 35: -: 36:#pragma GCC system_header -: 37: -: 38:#include -: 39:#include -: 40:#include -: 41: -: 42:#if __cplusplus >= 201103L -: 43:#include -: 44:#if __cplusplus > 201103L -: 45:#include -: 46:#endif -: 47:#endif -: 48: -: 49:namespace std _GLIBCXX_VISIBILITY(default) -: 50:{ -: 51:_GLIBCXX_BEGIN_NAMESPACE_VERSION -: 52: -: 53: // [27.6.3] standard manipulators -: 54: // Also see DR 183. -: 55: -: 56: struct _Resetiosflags { ios_base::fmtflags _M_mask; }; -: 57: -: 58: /** -: 59: * @brief Manipulator for @c setf. -: 60: * @param __mask A format flags mask. -: 61: * -: 62: * Sent to a stream object, this manipulator resets the specified flags, -: 63: * via @e stream.setf(0,__mask). -: 64: */ -: 65: inline _Resetiosflags -: 66: resetiosflags(ios_base::fmtflags __mask) -: 67: { return { __mask }; } -: 68: -: 69: template -: 70: inline basic_istream<_CharT, _Traits>& -: 71: operator>>(basic_istream<_CharT, _Traits>& __is, _Resetiosflags __f) -: 72: { -: 73: __is.setf(ios_base::fmtflags(0), __f._M_mask); -: 74: return __is; -: 75: } -: 76: -: 77: template -: 78: inline basic_ostream<_CharT, _Traits>& -: 79: operator<<(basic_ostream<_CharT, _Traits>& __os, _Resetiosflags __f) -: 80: { -: 81: __os.setf(ios_base::fmtflags(0), __f._M_mask); -: 82: return __os; -: 83: } -: 84: -: 85: -: 86: struct _Setiosflags { ios_base::fmtflags _M_mask; }; -: 87: -: 88: /** -: 89: * @brief Manipulator for @c setf. -: 90: * @param __mask A format flags mask. -: 91: * -: 92: * Sent to a stream object, this manipulator sets the format flags -: 93: * to @a __mask. -: 94: */ -: 95: inline _Setiosflags 24: 96: setiosflags(ios_base::fmtflags __mask) 24: 97: { return { __mask }; } -: 98: -: 99: template -: 100: inline basic_istream<_CharT, _Traits>& -: 101: operator>>(basic_istream<_CharT, _Traits>& __is, _Setiosflags __f) -: 102: { -: 103: __is.setf(__f._M_mask); -: 104: return __is; -: 105: } -: 106: -: 107: template -: 108: inline basic_ostream<_CharT, _Traits>& -: 109: operator<<(basic_ostream<_CharT, _Traits>& __os, _Setiosflags __f) -: 110: { -: 111: __os.setf(__f._M_mask); -: 112: return __os; -: 113: } -: 114: -: 115: -: 116: struct _Setbase { int _M_base; }; -: 117: -: 118: /** -: 119: * @brief Manipulator for @c setf. -: 120: * @param __base A numeric base. -: 121: * -: 122: * Sent to a stream object, this manipulator changes the -: 123: * @c ios_base::basefield flags to @c oct, @c dec, or @c hex when @a base -: 124: * is 8, 10, or 16, accordingly, and to 0 if @a __base is any other value. -: 125: */ -: 126: inline _Setbase -: 127: setbase(int __base) -: 128: { return { __base }; } -: 129: -: 130: template -: 131: inline basic_istream<_CharT, _Traits>& -: 132: operator>>(basic_istream<_CharT, _Traits>& __is, _Setbase __f) -: 133: { -: 134: __is.setf(__f._M_base == 8 ? ios_base::oct : -: 135: __f._M_base == 10 ? ios_base::dec : -: 136: __f._M_base == 16 ? ios_base::hex : -: 137: ios_base::fmtflags(0), ios_base::basefield); -: 138: return __is; -: 139: } -: 140: -: 141: template -: 142: inline basic_ostream<_CharT, _Traits>& -: 143: operator<<(basic_ostream<_CharT, _Traits>& __os, _Setbase __f) -: 144: { -: 145: __os.setf(__f._M_base == 8 ? ios_base::oct : -: 146: __f._M_base == 10 ? ios_base::dec : -: 147: __f._M_base == 16 ? ios_base::hex : -: 148: ios_base::fmtflags(0), ios_base::basefield); -: 149: return __os; -: 150: } -: 151: -: 152: -: 153: template -: 154: struct _Setfill { _CharT _M_c; }; -: 155: -: 156: /** -: 157: * @brief Manipulator for @c fill. -: 158: * @param __c The new fill character. -: 159: * -: 160: * Sent to a stream object, this manipulator calls @c fill(__c) for that -: 161: * object. -: 162: */ -: 163: template -: 164: inline _Setfill<_CharT> -: 165: setfill(_CharT __c) -: 166: { return { __c }; } -: 167: -: 168: template -: 169: inline basic_istream<_CharT, _Traits>& -: 170: operator>>(basic_istream<_CharT, _Traits>& __is, _Setfill<_CharT> __f) -: 171: { -: 172: __is.fill(__f._M_c); -: 173: return __is; -: 174: } -: 175: -: 176: template -: 177: inline basic_ostream<_CharT, _Traits>& -: 178: operator<<(basic_ostream<_CharT, _Traits>& __os, _Setfill<_CharT> __f) -: 179: { -: 180: __os.fill(__f._M_c); -: 181: return __os; -: 182: } -: 183: -: 184: -: 185: struct _Setprecision { int _M_n; }; -: 186: -: 187: /** -: 188: * @brief Manipulator for @c precision. -: 189: * @param __n The new precision. -: 190: * -: 191: * Sent to a stream object, this manipulator calls @c precision(__n) for -: 192: * that object. -: 193: */ -: 194: inline _Setprecision 62: 195: setprecision(int __n) 62: 196: { return { __n }; } -: 197: -: 198: template -: 199: inline basic_istream<_CharT, _Traits>& -: 200: operator>>(basic_istream<_CharT, _Traits>& __is, _Setprecision __f) -: 201: { -: 202: __is.precision(__f._M_n); -: 203: return __is; -: 204: } -: 205: -: 206: template -: 207: inline basic_ostream<_CharT, _Traits>& -: 208: operator<<(basic_ostream<_CharT, _Traits>& __os, _Setprecision __f) -: 209: { -: 210: __os.precision(__f._M_n); -: 211: return __os; -: 212: } -: 213: -: 214: -: 215: struct _Setw { int _M_n; }; -: 216: -: 217: /** -: 218: * @brief Manipulator for @c width. -: 219: * @param __n The new width. -: 220: * -: 221: * Sent to a stream object, this manipulator calls @c width(__n) for -: 222: * that object. -: 223: */ -: 224: inline _Setw -: 225: setw(int __n) -: 226: { return { __n }; } -: 227: -: 228: template -: 229: inline basic_istream<_CharT, _Traits>& -: 230: operator>>(basic_istream<_CharT, _Traits>& __is, _Setw __f) -: 231: { -: 232: __is.width(__f._M_n); -: 233: return __is; -: 234: } -: 235: -: 236: template -: 237: inline basic_ostream<_CharT, _Traits>& -: 238: operator<<(basic_ostream<_CharT, _Traits>& __os, _Setw __f) -: 239: { -: 240: __os.width(__f._M_n); -: 241: return __os; -: 242: } -: 243: -: 244:#if __cplusplus >= 201103L -: 245: -: 246: template -: 247: struct _Get_money { _MoneyT& _M_mon; bool _M_intl; }; -: 248: -: 249: /** -: 250: * @brief Extended manipulator for extracting money. -: 251: * @param __mon Either long double or a specialization of @c basic_string. -: 252: * @param __intl A bool indicating whether international format -: 253: * is to be used. -: 254: * -: 255: * Sent to a stream object, this manipulator extracts @a __mon. -: 256: */ -: 257: template -: 258: inline _Get_money<_MoneyT> -: 259: get_money(_MoneyT& __mon, bool __intl = false) -: 260: { return { __mon, __intl }; } -: 261: -: 262: template -: 263: basic_istream<_CharT, _Traits>& -: 264: operator>>(basic_istream<_CharT, _Traits>& __is, _Get_money<_MoneyT> __f) -: 265: { -: 266: typename basic_istream<_CharT, _Traits>::sentry __cerb(__is, false); -: 267: if (__cerb) -: 268: { -: 269: ios_base::iostate __err = ios_base::goodbit; -: 270: __try -: 271: { -: 272: typedef istreambuf_iterator<_CharT, _Traits> _Iter; -: 273: typedef money_get<_CharT, _Iter> _MoneyGet; -: 274: -: 275: const _MoneyGet& __mg = use_facet<_MoneyGet>(__is.getloc()); -: 276: __mg.get(_Iter(__is.rdbuf()), _Iter(), __f._M_intl, -: 277: __is, __err, __f._M_mon); -: 278: } -: 279: __catch(__cxxabiv1::__forced_unwind&) -: 280: { -: 281: __is._M_setstate(ios_base::badbit); -: 282: __throw_exception_again; -: 283: } -: 284: __catch(...) -: 285: { __is._M_setstate(ios_base::badbit); } -: 286: if (__err) -: 287: __is.setstate(__err); -: 288: } -: 289: return __is; -: 290: } -: 291: -: 292: -: 293: template -: 294: struct _Put_money { const _MoneyT& _M_mon; bool _M_intl; }; -: 295: -: 296: /** -: 297: * @brief Extended manipulator for inserting money. -: 298: * @param __mon Either long double or a specialization of @c basic_string. -: 299: * @param __intl A bool indicating whether international format -: 300: * is to be used. -: 301: * -: 302: * Sent to a stream object, this manipulator inserts @a __mon. -: 303: */ -: 304: template -: 305: inline _Put_money<_MoneyT> -: 306: put_money(const _MoneyT& __mon, bool __intl = false) -: 307: { return { __mon, __intl }; } -: 308: -: 309: template -: 310: basic_ostream<_CharT, _Traits>& -: 311: operator<<(basic_ostream<_CharT, _Traits>& __os, _Put_money<_MoneyT> __f) -: 312: { -: 313: typename basic_ostream<_CharT, _Traits>::sentry __cerb(__os); -: 314: if (__cerb) -: 315: { -: 316: ios_base::iostate __err = ios_base::goodbit; -: 317: __try -: 318: { -: 319: typedef ostreambuf_iterator<_CharT, _Traits> _Iter; -: 320: typedef money_put<_CharT, _Iter> _MoneyPut; -: 321: -: 322: const _MoneyPut& __mp = use_facet<_MoneyPut>(__os.getloc()); -: 323: if (__mp.put(_Iter(__os.rdbuf()), __f._M_intl, __os, -: 324: __os.fill(), __f._M_mon).failed()) -: 325: __err |= ios_base::badbit; -: 326: } -: 327: __catch(__cxxabiv1::__forced_unwind&) -: 328: { -: 329: __os._M_setstate(ios_base::badbit); -: 330: __throw_exception_again; -: 331: } -: 332: __catch(...) -: 333: { __os._M_setstate(ios_base::badbit); } -: 334: if (__err) -: 335: __os.setstate(__err); -: 336: } -: 337: return __os; -: 338: } -: 339: -: 340: template -: 341: struct _Put_time -: 342: { -: 343: const std::tm* _M_tmb; -: 344: const _CharT* _M_fmt; -: 345: }; -: 346: -: 347: /** -: 348: * @brief Extended manipulator for formatting time. -: 349: * -: 350: * This manipulator uses time_put::put to format time. -: 351: * [ext.manip] -: 352: * -: 353: * @param __tmb struct tm time data to format. -: 354: * @param __fmt format string. -: 355: */ -: 356: template -: 357: inline _Put_time<_CharT> -: 358: put_time(const std::tm* __tmb, const _CharT* __fmt) -: 359: { return { __tmb, __fmt }; } -: 360: -: 361: template -: 362: basic_ostream<_CharT, _Traits>& -: 363: operator<<(basic_ostream<_CharT, _Traits>& __os, _Put_time<_CharT> __f) -: 364: { -: 365: typename basic_ostream<_CharT, _Traits>::sentry __cerb(__os); -: 366: if (__cerb) -: 367: { -: 368: ios_base::iostate __err = ios_base::goodbit; -: 369: __try -: 370: { -: 371: typedef ostreambuf_iterator<_CharT, _Traits> _Iter; -: 372: typedef time_put<_CharT, _Iter> _TimePut; -: 373: -: 374: const _CharT* const __fmt_end = __f._M_fmt + -: 375: _Traits::length(__f._M_fmt); -: 376: -: 377: const _TimePut& __mp = use_facet<_TimePut>(__os.getloc()); -: 378: if (__mp.put(_Iter(__os.rdbuf()), __os, __os.fill(), -: 379: __f._M_tmb, __f._M_fmt, __fmt_end).failed()) -: 380: __err |= ios_base::badbit; -: 381: } -: 382: __catch(__cxxabiv1::__forced_unwind&) -: 383: { -: 384: __os._M_setstate(ios_base::badbit); -: 385: __throw_exception_again; -: 386: } -: 387: __catch(...) -: 388: { __os._M_setstate(ios_base::badbit); } -: 389: if (__err) -: 390: __os.setstate(__err); -: 391: } -: 392: return __os; -: 393: } -: 394: -: 395: template -: 396: struct _Get_time -: 397: { -: 398: std::tm* _M_tmb; -: 399: const _CharT* _M_fmt; -: 400: }; -: 401: -: 402: /** -: 403: * @brief Extended manipulator for extracting time. -: 404: * -: 405: * This manipulator uses time_get::get to extract time. -: 406: * [ext.manip] -: 407: * -: 408: * @param __tmb struct to extract the time data to. -: 409: * @param __fmt format string. -: 410: */ -: 411: template -: 412: inline _Get_time<_CharT> -: 413: get_time(std::tm* __tmb, const _CharT* __fmt) -: 414: { return { __tmb, __fmt }; } -: 415: -: 416: template -: 417: basic_istream<_CharT, _Traits>& -: 418: operator>>(basic_istream<_CharT, _Traits>& __is, _Get_time<_CharT> __f) -: 419: { -: 420: typename basic_istream<_CharT, _Traits>::sentry __cerb(__is, false); -: 421: if (__cerb) -: 422: { -: 423: ios_base::iostate __err = ios_base::goodbit; -: 424: __try -: 425: { -: 426: typedef istreambuf_iterator<_CharT, _Traits> _Iter; -: 427: typedef time_get<_CharT, _Iter> _TimeGet; -: 428: -: 429: const _CharT* const __fmt_end = __f._M_fmt + -: 430: _Traits::length(__f._M_fmt); -: 431: -: 432: const _TimeGet& __mg = use_facet<_TimeGet>(__is.getloc()); -: 433: __mg.get(_Iter(__is.rdbuf()), _Iter(), __is, -: 434: __err, __f._M_tmb, __f._M_fmt, __fmt_end); -: 435: } -: 436: __catch(__cxxabiv1::__forced_unwind&) -: 437: { -: 438: __is._M_setstate(ios_base::badbit); -: 439: __throw_exception_again; -: 440: } -: 441: __catch(...) -: 442: { __is._M_setstate(ios_base::badbit); } -: 443: if (__err) -: 444: __is.setstate(__err); -: 445: } -: 446: return __is; -: 447: } -: 448: -: 449:#if __cplusplus >= 201402L -: 450: -: 451:#define __cpp_lib_quoted_string_io 201304 -: 452: -: 453: /** -: 454: * @brief Manipulator for quoted strings. -: 455: * @param __string String to quote. -: 456: * @param __delim Character to quote string with. -: 457: * @param __escape Escape character to escape itself or quote character. -: 458: */ -: 459: template -: 460: inline auto -: 461: quoted(const _CharT* __string, -: 462: _CharT __delim = _CharT('"'), _CharT __escape = _CharT('\\')) -: 463: { -: 464: return __detail::_Quoted_string(__string, __delim, -: 465: __escape); -: 466: } -: 467: -: 468: template -: 469: inline auto -: 470: quoted(const basic_string<_CharT, _Traits, _Alloc>& __string, -: 471: _CharT __delim = _CharT('"'), _CharT __escape = _CharT('\\')) -: 472: { -: 473: return __detail::_Quoted_string< -: 474: const basic_string<_CharT, _Traits, _Alloc>&, _CharT>( -: 475: __string, __delim, __escape); -: 476: } -: 477: -: 478: template -: 479: inline auto -: 480: quoted(basic_string<_CharT, _Traits, _Alloc>& __string, -: 481: _CharT __delim = _CharT('"'), _CharT __escape = _CharT('\\')) -: 482: { -: 483: return __detail::_Quoted_string< -: 484: basic_string<_CharT, _Traits, _Alloc>&, _CharT>( -: 485: __string, __delim, __escape); -: 486: } -: 487: -: 488:#if __cplusplus >= 201703L -: 489: // _GLIBCXX_RESOLVE_LIB_DEFECTS -: 490: // 2785. quoted should work with basic_string_view -: 491: template -: 492: inline auto -: 493: quoted(basic_string_view<_CharT, _Traits> __sv, -: 494: _CharT __delim = _CharT('"'), _CharT __escape = _CharT('\\')) -: 495: { -: 496: return __detail::_Quoted_string< -: 497: basic_string_view<_CharT, _Traits>, _CharT>(__sv, __delim, __escape); -: 498: } -: 499:#endif // C++17 -: 500:#endif // C++14 -: 501: -: 502:#endif // __cplusplus >= 201103L -: 503: -: 504: // Inhibit implicit instantiations for required instantiations, -: 505: // which are defined via explicit instantiations elsewhere. -: 506: // NB: This syntax is a GNU extension. -: 507:#if _GLIBCXX_EXTERN_TEMPLATE -: 508: extern template ostream& operator<<(ostream&, _Setfill); -: 509: extern template ostream& operator<<(ostream&, _Setiosflags); -: 510: extern template ostream& operator<<(ostream&, _Resetiosflags); -: 511: extern template ostream& operator<<(ostream&, _Setbase); -: 512: extern template ostream& operator<<(ostream&, _Setprecision); -: 513: extern template ostream& operator<<(ostream&, _Setw); -: 514: extern template istream& operator>>(istream&, _Setfill); -: 515: extern template istream& operator>>(istream&, _Setiosflags); -: 516: extern template istream& operator>>(istream&, _Resetiosflags); -: 517: extern template istream& operator>>(istream&, _Setbase); -: 518: extern template istream& operator>>(istream&, _Setprecision); -: 519: extern template istream& operator>>(istream&, _Setw); -: 520: -: 521:#ifdef _GLIBCXX_USE_WCHAR_T -: 522: extern template wostream& operator<<(wostream&, _Setfill); -: 523: extern template wostream& operator<<(wostream&, _Setiosflags); -: 524: extern template wostream& operator<<(wostream&, _Resetiosflags); -: 525: extern template wostream& operator<<(wostream&, _Setbase); -: 526: extern template wostream& operator<<(wostream&, _Setprecision); -: 527: extern template wostream& operator<<(wostream&, _Setw); -: 528: extern template wistream& operator>>(wistream&, _Setfill); -: 529: extern template wistream& operator>>(wistream&, _Setiosflags); -: 530: extern template wistream& operator>>(wistream&, _Resetiosflags); -: 531: extern template wistream& operator>>(wistream&, _Setbase); -: 532: extern template wistream& operator>>(wistream&, _Setprecision); -: 533: extern template wistream& operator>>(wistream&, _Setw); -: 534:#endif -: 535:#endif -: 536: -: 537:_GLIBCXX_END_NAMESPACE_VERSION -: 538:} // namespace -: 539: -: 540:#endif /* _GLIBCXX_IOMANIP */ <<<<<< EOF # path=tests/ios_base.h.gcov -: 0:Source:/usr/include/c++/9/bits/ios_base.h -: 0:Graph:log.gcno -: 0:Data:log.gcda -: 0:Runs:2 -: 1:// Iostreams base classes -*- C++ -*- -: 2: -: 3:// Copyright (C) 1997-2019 Free Software Foundation, Inc. -: 4:// -: 5:// This file is part of the GNU ISO C++ Library. This library is free -: 6:// software; you can redistribute it and/or modify it under the -: 7:// terms of the GNU General Public License as published by the -: 8:// Free Software Foundation; either version 3, or (at your option) -: 9:// any later version. -: 10: -: 11:// This library is distributed in the hope that it will be useful, -: 12:// but WITHOUT ANY WARRANTY; without even the implied warranty of -: 13:// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -: 14:// GNU General Public License for more details. -: 15: -: 16:// Under Section 7 of GPL version 3, you are granted additional -: 17:// permissions described in the GCC Runtime Library Exception, version -: 18:// 3.1, as published by the Free Software Foundation. -: 19: -: 20:// You should have received a copy of the GNU General Public License and -: 21:// a copy of the GCC Runtime Library Exception along with this program; -: 22:// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see -: 23:// . -: 24: -: 25:/** @file bits/ios_base.h -: 26: * This is an internal header file, included by other library headers. -: 27: * Do not attempt to use it directly. @headername{ios} -: 28: */ -: 29: -: 30:// -: 31:// ISO C++ 14882: 27.4 Iostreams base classes -: 32:// -: 33: -: 34:#ifndef _IOS_BASE_H -: 35:#define _IOS_BASE_H 1 -: 36: -: 37:#pragma GCC system_header -: 38: -: 39:#include -: 40:#include -: 41:#include -: 42: -: 43:#if __cplusplus < 201103L -: 44:# include -: 45:#else -: 46:# include -: 47:#endif -: 48: -: 49:namespace std _GLIBCXX_VISIBILITY(default) -: 50:{ -: 51:_GLIBCXX_BEGIN_NAMESPACE_VERSION -: 52: -: 53: // The following definitions of bitmask types are enums, not ints, -: 54: // as permitted (but not required) in the standard, in order to provide -: 55: // better type safety in iostream calls. A side effect is that in C++98 -: 56: // expressions involving them are not compile-time constants. -: 57: enum _Ios_Fmtflags -: 58: { -: 59: _S_boolalpha = 1L << 0, -: 60: _S_dec = 1L << 1, -: 61: _S_fixed = 1L << 2, -: 62: _S_hex = 1L << 3, -: 63: _S_internal = 1L << 4, -: 64: _S_left = 1L << 5, -: 65: _S_oct = 1L << 6, -: 66: _S_right = 1L << 7, -: 67: _S_scientific = 1L << 8, -: 68: _S_showbase = 1L << 9, -: 69: _S_showpoint = 1L << 10, -: 70: _S_showpos = 1L << 11, -: 71: _S_skipws = 1L << 12, -: 72: _S_unitbuf = 1L << 13, -: 73: _S_uppercase = 1L << 14, -: 74: _S_adjustfield = _S_left | _S_right | _S_internal, -: 75: _S_basefield = _S_dec | _S_oct | _S_hex, -: 76: _S_floatfield = _S_scientific | _S_fixed, -: 77: _S_ios_fmtflags_end = 1L << 16, -: 78: _S_ios_fmtflags_max = __INT_MAX__, -: 79: _S_ios_fmtflags_min = ~__INT_MAX__ -: 80: }; -: 81: -: 82: inline _GLIBCXX_CONSTEXPR _Ios_Fmtflags 56: 83: operator&(_Ios_Fmtflags __a, _Ios_Fmtflags __b) 56: 84: { return _Ios_Fmtflags(static_cast(__a) & static_cast(__b)); } -: 85: -: 86: inline _GLIBCXX_CONSTEXPR _Ios_Fmtflags 16: 87: operator|(_Ios_Fmtflags __a, _Ios_Fmtflags __b) 16: 88: { return _Ios_Fmtflags(static_cast(__a) | static_cast(__b)); } -: 89: -: 90: inline _GLIBCXX_CONSTEXPR _Ios_Fmtflags -: 91: operator^(_Ios_Fmtflags __a, _Ios_Fmtflags __b) -: 92: { return _Ios_Fmtflags(static_cast(__a) ^ static_cast(__b)); } -: 93: -: 94: inline _GLIBCXX_CONSTEXPR _Ios_Fmtflags 40: 95: operator~(_Ios_Fmtflags __a) 40: 96: { return _Ios_Fmtflags(~static_cast(__a)); } -: 97: -: 98: inline const _Ios_Fmtflags& 16: 99: operator|=(_Ios_Fmtflags& __a, _Ios_Fmtflags __b) 16: 100: { return __a = __a | __b; } -: 101: -: 102: inline const _Ios_Fmtflags& 40: 103: operator&=(_Ios_Fmtflags& __a, _Ios_Fmtflags __b) 40: 104: { return __a = __a & __b; } -: 105: -: 106: inline const _Ios_Fmtflags& -: 107: operator^=(_Ios_Fmtflags& __a, _Ios_Fmtflags __b) -: 108: { return __a = __a ^ __b; } -: 109: -: 110: -: 111: enum _Ios_Openmode -: 112: { -: 113: _S_app = 1L << 0, -: 114: _S_ate = 1L << 1, -: 115: _S_bin = 1L << 2, -: 116: _S_in = 1L << 3, -: 117: _S_out = 1L << 4, -: 118: _S_trunc = 1L << 5, -: 119: _S_ios_openmode_end = 1L << 16, -: 120: _S_ios_openmode_max = __INT_MAX__, -: 121: _S_ios_openmode_min = ~__INT_MAX__ -: 122: }; -: 123: -: 124: inline _GLIBCXX_CONSTEXPR _Ios_Openmode -: 125: operator&(_Ios_Openmode __a, _Ios_Openmode __b) -: 126: { return _Ios_Openmode(static_cast(__a) & static_cast(__b)); } -: 127: -: 128: inline _GLIBCXX_CONSTEXPR _Ios_Openmode -: 129: operator|(_Ios_Openmode __a, _Ios_Openmode __b) -: 130: { return _Ios_Openmode(static_cast(__a) | static_cast(__b)); } -: 131: -: 132: inline _GLIBCXX_CONSTEXPR _Ios_Openmode -: 133: operator^(_Ios_Openmode __a, _Ios_Openmode __b) -: 134: { return _Ios_Openmode(static_cast(__a) ^ static_cast(__b)); } -: 135: -: 136: inline _GLIBCXX_CONSTEXPR _Ios_Openmode -: 137: operator~(_Ios_Openmode __a) -: 138: { return _Ios_Openmode(~static_cast(__a)); } -: 139: -: 140: inline const _Ios_Openmode& -: 141: operator|=(_Ios_Openmode& __a, _Ios_Openmode __b) -: 142: { return __a = __a | __b; } -: 143: -: 144: inline const _Ios_Openmode& -: 145: operator&=(_Ios_Openmode& __a, _Ios_Openmode __b) -: 146: { return __a = __a & __b; } -: 147: -: 148: inline const _Ios_Openmode& -: 149: operator^=(_Ios_Openmode& __a, _Ios_Openmode __b) -: 150: { return __a = __a ^ __b; } -: 151: -: 152: -: 153: enum _Ios_Iostate -: 154: { -: 155: _S_goodbit = 0, -: 156: _S_badbit = 1L << 0, -: 157: _S_eofbit = 1L << 1, -: 158: _S_failbit = 1L << 2, -: 159: _S_ios_iostate_end = 1L << 16, -: 160: _S_ios_iostate_max = __INT_MAX__, -: 161: _S_ios_iostate_min = ~__INT_MAX__ -: 162: }; -: 163: -: 164: inline _GLIBCXX_CONSTEXPR _Ios_Iostate -: 165: operator&(_Ios_Iostate __a, _Ios_Iostate __b) -: 166: { return _Ios_Iostate(static_cast(__a) & static_cast(__b)); } -: 167: -: 168: inline _GLIBCXX_CONSTEXPR _Ios_Iostate -: 169: operator|(_Ios_Iostate __a, _Ios_Iostate __b) -: 170: { return _Ios_Iostate(static_cast(__a) | static_cast(__b)); } -: 171: -: 172: inline _GLIBCXX_CONSTEXPR _Ios_Iostate -: 173: operator^(_Ios_Iostate __a, _Ios_Iostate __b) -: 174: { return _Ios_Iostate(static_cast(__a) ^ static_cast(__b)); } -: 175: -: 176: inline _GLIBCXX_CONSTEXPR _Ios_Iostate -: 177: operator~(_Ios_Iostate __a) -: 178: { return _Ios_Iostate(~static_cast(__a)); } -: 179: -: 180: inline const _Ios_Iostate& -: 181: operator|=(_Ios_Iostate& __a, _Ios_Iostate __b) -: 182: { return __a = __a | __b; } -: 183: -: 184: inline const _Ios_Iostate& -: 185: operator&=(_Ios_Iostate& __a, _Ios_Iostate __b) -: 186: { return __a = __a & __b; } -: 187: -: 188: inline const _Ios_Iostate& -: 189: operator^=(_Ios_Iostate& __a, _Ios_Iostate __b) -: 190: { return __a = __a ^ __b; } -: 191: -: 192: -: 193: enum _Ios_Seekdir -: 194: { -: 195: _S_beg = 0, -: 196: _S_cur = _GLIBCXX_STDIO_SEEK_CUR, -: 197: _S_end = _GLIBCXX_STDIO_SEEK_END, -: 198: _S_ios_seekdir_end = 1L << 16 -: 199: }; -: 200: -: 201:#if __cplusplus >= 201103L -: 202: /// I/O error code -: 203: enum class io_errc { stream = 1 }; -: 204: -: 205: template <> struct is_error_code_enum : public true_type { }; -: 206: -: 207: const error_category& iostream_category() noexcept; -: 208: -: 209: inline error_code -: 210: make_error_code(io_errc __e) noexcept -: 211: { return error_code(static_cast(__e), iostream_category()); } -: 212: -: 213: inline error_condition -: 214: make_error_condition(io_errc __e) noexcept -: 215: { return error_condition(static_cast(__e), iostream_category()); } -: 216:#endif -: 217: -: 218: // 27.4.2 Class ios_base -: 219: /** -: 220: * @brief The base of the I/O class hierarchy. -: 221: * @ingroup io -: 222: * -: 223: * This class defines everything that can be defined about I/O that does -: 224: * not depend on the type of characters being input or output. Most -: 225: * people will only see @c ios_base when they need to specify the full -: 226: * name of the various I/O flags (e.g., the openmodes). -: 227: */ -: 228: class ios_base -: 229: { -: 230:#if _GLIBCXX_USE_CXX11_ABI -: 231:#if __cplusplus < 201103L -: 232: // Type that is layout-compatible with std::system_error -: 233: struct system_error : std::runtime_error -: 234: { -: 235: // Type that is layout-compatible with std::error_code -: 236: struct error_code -: 237: { -: 238: error_code() { } -: 239: private: -: 240: int _M_value; -: 241: const void* _M_cat; -: 242: } _M_code; -: 243: }; -: 244:#endif -: 245:#endif -: 246: public: -: 247: -: 248: /** -: 249: * @brief These are thrown to indicate problems with io. -: 250: * @ingroup exceptions -: 251: * -: 252: * 27.4.2.1.1 Class ios_base::failure -: 253: */ -: 254:#if _GLIBCXX_USE_CXX11_ABI -: 255: class _GLIBCXX_ABI_TAG_CXX11 failure : public system_error -: 256: { -: 257: public: -: 258: explicit -: 259: failure(const string& __str); -: 260: -: 261:#if __cplusplus >= 201103L -: 262: explicit -: 263: failure(const string&, const error_code&); -: 264: -: 265: explicit -: 266: failure(const char*, const error_code& = io_errc::stream); -: 267:#endif -: 268: -: 269: virtual -: 270: ~failure() throw(); -: 271: -: 272: virtual const char* -: 273: what() const throw(); -: 274: }; -: 275:#else -: 276: class failure : public exception -: 277: { -: 278: public: -: 279: // _GLIBCXX_RESOLVE_LIB_DEFECTS -: 280: // 48. Use of non-existent exception constructor -: 281: explicit -: 282: failure(const string& __str) throw(); -: 283: -: 284: // This declaration is not useless: -: 285: // http://gcc.gnu.org/onlinedocs/gcc-4.3.2/gcc/Vague-Linkage.html -: 286: virtual -: 287: ~failure() throw(); -: 288: -: 289: virtual const char* -: 290: what() const throw(); -: 291: -: 292: private: -: 293: string _M_msg; -: 294: }; -: 295:#endif -: 296: -: 297: // 27.4.2.1.2 Type ios_base::fmtflags -: 298: /** -: 299: * @brief This is a bitmask type. -: 300: * -: 301: * @c @a _Ios_Fmtflags is implementation-defined, but it is valid to -: 302: * perform bitwise operations on these values and expect the Right -: 303: * Thing to happen. Defined objects of type fmtflags are: -: 304: * - boolalpha -: 305: * - dec -: 306: * - fixed -: 307: * - hex -: 308: * - internal -: 309: * - left -: 310: * - oct -: 311: * - right -: 312: * - scientific -: 313: * - showbase -: 314: * - showpoint -: 315: * - showpos -: 316: * - skipws -: 317: * - unitbuf -: 318: * - uppercase -: 319: * - adjustfield -: 320: * - basefield -: 321: * - floatfield -: 322: */ -: 323: typedef _Ios_Fmtflags fmtflags; -: 324: -: 325: /// Insert/extract @c bool in alphabetic rather than numeric format. -: 326: static const fmtflags boolalpha = _S_boolalpha; -: 327: -: 328: /// Converts integer input or generates integer output in decimal base. -: 329: static const fmtflags dec = _S_dec; -: 330: -: 331: /// Generate floating-point output in fixed-point notation. -: 332: static const fmtflags fixed = _S_fixed; -: 333: -: 334: /// Converts integer input or generates integer output in hexadecimal base. -: 335: static const fmtflags hex = _S_hex; -: 336: -: 337: /// Adds fill characters at a designated internal point in certain -: 338: /// generated output, or identical to @c right if no such point is -: 339: /// designated. -: 340: static const fmtflags internal = _S_internal; -: 341: -: 342: /// Adds fill characters on the right (final positions) of certain -: 343: /// generated output. (I.e., the thing you print is flush left.) -: 344: static const fmtflags left = _S_left; -: 345: -: 346: /// Converts integer input or generates integer output in octal base. -: 347: static const fmtflags oct = _S_oct; -: 348: -: 349: /// Adds fill characters on the left (initial positions) of certain -: 350: /// generated output. (I.e., the thing you print is flush right.) -: 351: static const fmtflags right = _S_right; -: 352: -: 353: /// Generates floating-point output in scientific notation. -: 354: static const fmtflags scientific = _S_scientific; -: 355: -: 356: /// Generates a prefix indicating the numeric base of generated integer -: 357: /// output. -: 358: static const fmtflags showbase = _S_showbase; -: 359: -: 360: /// Generates a decimal-point character unconditionally in generated -: 361: /// floating-point output. -: 362: static const fmtflags showpoint = _S_showpoint; -: 363: -: 364: /// Generates a + sign in non-negative generated numeric output. -: 365: static const fmtflags showpos = _S_showpos; -: 366: -: 367: /// Skips leading white space before certain input operations. -: 368: static const fmtflags skipws = _S_skipws; -: 369: -: 370: /// Flushes output after each output operation. -: 371: static const fmtflags unitbuf = _S_unitbuf; -: 372: -: 373: /// Replaces certain lowercase letters with their uppercase equivalents -: 374: /// in generated output. -: 375: static const fmtflags uppercase = _S_uppercase; -: 376: -: 377: /// A mask of left|right|internal. Useful for the 2-arg form of @c setf. -: 378: static const fmtflags adjustfield = _S_adjustfield; -: 379: -: 380: /// A mask of dec|oct|hex. Useful for the 2-arg form of @c setf. -: 381: static const fmtflags basefield = _S_basefield; -: 382: -: 383: /// A mask of scientific|fixed. Useful for the 2-arg form of @c setf. -: 384: static const fmtflags floatfield = _S_floatfield; -: 385: -: 386: // 27.4.2.1.3 Type ios_base::iostate -: 387: /** -: 388: * @brief This is a bitmask type. -: 389: * -: 390: * @c @a _Ios_Iostate is implementation-defined, but it is valid to -: 391: * perform bitwise operations on these values and expect the Right -: 392: * Thing to happen. Defined objects of type iostate are: -: 393: * - badbit -: 394: * - eofbit -: 395: * - failbit -: 396: * - goodbit -: 397: */ -: 398: typedef _Ios_Iostate iostate; -: 399: -: 400: /// Indicates a loss of integrity in an input or output sequence (such -: 401: /// as an irrecoverable read error from a file). -: 402: static const iostate badbit = _S_badbit; -: 403: -: 404: /// Indicates that an input operation reached the end of an input sequence. -: 405: static const iostate eofbit = _S_eofbit; -: 406: -: 407: /// Indicates that an input operation failed to read the expected -: 408: /// characters, or that an output operation failed to generate the -: 409: /// desired characters. -: 410: static const iostate failbit = _S_failbit; -: 411: -: 412: /// Indicates all is well. -: 413: static const iostate goodbit = _S_goodbit; -: 414: -: 415: // 27.4.2.1.4 Type ios_base::openmode -: 416: /** -: 417: * @brief This is a bitmask type. -: 418: * -: 419: * @c @a _Ios_Openmode is implementation-defined, but it is valid to -: 420: * perform bitwise operations on these values and expect the Right -: 421: * Thing to happen. Defined objects of type openmode are: -: 422: * - app -: 423: * - ate -: 424: * - binary -: 425: * - in -: 426: * - out -: 427: * - trunc -: 428: */ -: 429: typedef _Ios_Openmode openmode; -: 430: -: 431: /// Seek to end before each write. -: 432: static const openmode app = _S_app; -: 433: -: 434: /// Open and seek to end immediately after opening. -: 435: static const openmode ate = _S_ate; -: 436: -: 437: /// Perform input and output in binary mode (as opposed to text mode). -: 438: /// This is probably not what you think it is; see -: 439: /// https://gcc.gnu.org/onlinedocs/libstdc++/manual/fstreams.html#std.io.filestreams.binary -: 440: static const openmode binary = _S_bin; -: 441: -: 442: /// Open for input. Default for @c ifstream and fstream. -: 443: static const openmode in = _S_in; -: 444: -: 445: /// Open for output. Default for @c ofstream and fstream. -: 446: static const openmode out = _S_out; -: 447: -: 448: /// Truncate an existing stream when opening. Default for @c ofstream. -: 449: static const openmode trunc = _S_trunc; -: 450: -: 451: // 27.4.2.1.5 Type ios_base::seekdir -: 452: /** -: 453: * @brief This is an enumerated type. -: 454: * -: 455: * @c @a _Ios_Seekdir is implementation-defined. Defined values -: 456: * of type seekdir are: -: 457: * - beg -: 458: * - cur, equivalent to @c SEEK_CUR in the C standard library. -: 459: * - end, equivalent to @c SEEK_END in the C standard library. -: 460: */ -: 461: typedef _Ios_Seekdir seekdir; -: 462: -: 463: /// Request a seek relative to the beginning of the stream. -: 464: static const seekdir beg = _S_beg; -: 465: -: 466: /// Request a seek relative to the current position within the sequence. -: 467: static const seekdir cur = _S_cur; -: 468: -: 469: /// Request a seek relative to the current end of the sequence. -: 470: static const seekdir end = _S_end; -: 471: -: 472:#if __cplusplus <= 201402L -: 473: // Annex D.6 (removed in C++17) -: 474: typedef int io_state -: 475: _GLIBCXX_DEPRECATED_SUGGEST("std::iostate"); -: 476: typedef int open_mode -: 477: _GLIBCXX_DEPRECATED_SUGGEST("std::openmode"); -: 478: typedef int seek_dir -: 479: _GLIBCXX_DEPRECATED_SUGGEST("std::seekdir"); -: 480: -: 481: typedef std::streampos streampos -: 482: _GLIBCXX_DEPRECATED_SUGGEST("std::streampos"); -: 483: typedef std::streamoff streamoff -: 484: _GLIBCXX_DEPRECATED_SUGGEST("std::streamoff"); -: 485:#endif -: 486: -: 487: // Callbacks; -: 488: /** -: 489: * @brief The set of events that may be passed to an event callback. -: 490: * -: 491: * erase_event is used during ~ios() and copyfmt(). imbue_event is used -: 492: * during imbue(). copyfmt_event is used during copyfmt(). -: 493: */ -: 494: enum event -: 495: { -: 496: erase_event, -: 497: imbue_event, -: 498: copyfmt_event -: 499: }; -: 500: -: 501: /** -: 502: * @brief The type of an event callback function. -: 503: * @param __e One of the members of the event enum. -: 504: * @param __b Reference to the ios_base object. -: 505: * @param __i The integer provided when the callback was registered. -: 506: * -: 507: * Event callbacks are user defined functions that get called during -: 508: * several ios_base and basic_ios functions, specifically imbue(), -: 509: * copyfmt(), and ~ios(). -: 510: */ -: 511: typedef void (*event_callback) (event __e, ios_base& __b, int __i); -: 512: -: 513: /** -: 514: * @brief Add the callback __fn with parameter __index. -: 515: * @param __fn The function to add. -: 516: * @param __index The integer to pass to the function when invoked. -: 517: * -: 518: * Registers a function as an event callback with an integer parameter to -: 519: * be passed to the function when invoked. Multiple copies of the -: 520: * function are allowed. If there are multiple callbacks, they are -: 521: * invoked in the order they were registered. -: 522: */ -: 523: void -: 524: register_callback(event_callback __fn, int __index); -: 525: -: 526: protected: -: 527: streamsize _M_precision; -: 528: streamsize _M_width; -: 529: fmtflags _M_flags; -: 530: iostate _M_exception; -: 531: iostate _M_streambuf_state; -: 532: -: 533: // 27.4.2.6 Members for callbacks -: 534: // 27.4.2.6 ios_base callbacks -: 535: struct _Callback_list -: 536: { -: 537: // Data Members -: 538: _Callback_list* _M_next; -: 539: ios_base::event_callback _M_fn; -: 540: int _M_index; -: 541: _Atomic_word _M_refcount; // 0 means one reference. -: 542: -: 543: _Callback_list(ios_base::event_callback __fn, int __index, -: 544: _Callback_list* __cb) -: 545: : _M_next(__cb), _M_fn(__fn), _M_index(__index), _M_refcount(0) { } -: 546: -: 547: void -: 548: _M_add_reference() { __gnu_cxx::__atomic_add_dispatch(&_M_refcount, 1); } -: 549: -: 550: // 0 => OK to delete. -: 551: int -: 552: _M_remove_reference() -: 553: { -: 554: // Be race-detector-friendly. For more info see bits/c++config. -: 555: _GLIBCXX_SYNCHRONIZATION_HAPPENS_BEFORE(&_M_refcount); -: 556: int __res = __gnu_cxx::__exchange_and_add_dispatch(&_M_refcount, -1); -: 557: if (__res == 0) -: 558: { -: 559: _GLIBCXX_SYNCHRONIZATION_HAPPENS_AFTER(&_M_refcount); -: 560: } -: 561: return __res; -: 562: } -: 563: }; -: 564: -: 565: _Callback_list* _M_callbacks; -: 566: -: 567: void -: 568: _M_call_callbacks(event __ev) throw(); -: 569: -: 570: void -: 571: _M_dispose_callbacks(void) throw(); -: 572: -: 573: // 27.4.2.5 Members for iword/pword storage -: 574: struct _Words -: 575: { -: 576: void* _M_pword; -: 577: long _M_iword; -: 578: _Words() : _M_pword(0), _M_iword(0) { } -: 579: }; -: 580: -: 581: // Only for failed iword/pword calls. -: 582: _Words _M_word_zero; -: 583: -: 584: // Guaranteed storage. -: 585: // The first 5 iword and pword slots are reserved for internal use. -: 586: enum { _S_local_word_size = 8 }; -: 587: _Words _M_local_word[_S_local_word_size]; -: 588: -: 589: // Allocated storage. -: 590: int _M_word_size; -: 591: _Words* _M_word; -: 592: -: 593: _Words& -: 594: _M_grow_words(int __index, bool __iword); -: 595: -: 596: // Members for locale and locale caching. -: 597: locale _M_ios_locale; -: 598: -: 599: void -: 600: _M_init() throw(); -: 601: -: 602: public: -: 603: -: 604: // 27.4.2.1.6 Class ios_base::Init -: 605: // Used to initialize standard streams. In theory, g++ could use -: 606: // -finit-priority to order this stuff correctly without going -: 607: // through these machinations. -: 608: class Init -: 609: { -: 610: friend class ios_base; -: 611: public: -: 612: Init(); -: 613: ~Init(); -: 614: -: 615:#if __cplusplus >= 201103L -: 616: Init(const Init&) = default; -: 617: Init& operator=(const Init&) = default; -: 618:#endif -: 619: -: 620: private: -: 621: static _Atomic_word _S_refcount; -: 622: static bool _S_synced_with_stdio; -: 623: }; -: 624: -: 625: // [27.4.2.2] fmtflags state functions -: 626: /** -: 627: * @brief Access to format flags. -: 628: * @return The format control flags for both input and output. -: 629: */ -: 630: fmtflags -: 631: flags() const -: 632: { return _M_flags; } -: 633: -: 634: /** -: 635: * @brief Setting new format flags all at once. -: 636: * @param __fmtfl The new flags to set. -: 637: * @return The previous format control flags. -: 638: * -: 639: * This function overwrites all the format flags with @a __fmtfl. -: 640: */ -: 641: fmtflags -: 642: flags(fmtflags __fmtfl) -: 643: { -: 644: fmtflags __old = _M_flags; -: 645: _M_flags = __fmtfl; -: 646: return __old; -: 647: } -: 648: -: 649: /** -: 650: * @brief Setting new format flags. -: 651: * @param __fmtfl Additional flags to set. -: 652: * @return The previous format control flags. -: 653: * -: 654: * This function sets additional flags in format control. Flags that -: 655: * were previously set remain set. -: 656: */ -: 657: fmtflags -: 658: setf(fmtflags __fmtfl) -: 659: { -: 660: fmtflags __old = _M_flags; -: 661: _M_flags |= __fmtfl; -: 662: return __old; -: 663: } -: 664: -: 665: /** -: 666: * @brief Setting new format flags. -: 667: * @param __fmtfl Additional flags to set. -: 668: * @param __mask The flags mask for @a fmtfl. -: 669: * @return The previous format control flags. -: 670: * -: 671: * This function clears @a mask in the format flags, then sets -: 672: * @a fmtfl @c & @a mask. An example mask is @c ios_base::adjustfield. -: 673: */ -: 674: fmtflags 16: 675: setf(fmtflags __fmtfl, fmtflags __mask) -: 676: { 16: 677: fmtflags __old = _M_flags; 16: 678: _M_flags &= ~__mask; 16: 679: _M_flags |= (__fmtfl & __mask); 16: 680: return __old; -: 681: } -: 682: -: 683: /** -: 684: * @brief Clearing format flags. -: 685: * @param __mask The flags to unset. -: 686: * -: 687: * This function clears @a __mask in the format flags. -: 688: */ -: 689: void 24: 690: unsetf(fmtflags __mask) 24: 691: { _M_flags &= ~__mask; } -: 692: -: 693: /** -: 694: * @brief Flags access. -: 695: * @return The precision to generate on certain output operations. -: 696: * -: 697: * Be careful if you try to give a definition of @a precision here; see -: 698: * DR 189. -: 699: */ -: 700: streamsize -: 701: precision() const -: 702: { return _M_precision; } -: 703: -: 704: /** -: 705: * @brief Changing flags. -: 706: * @param __prec The new precision value. -: 707: * @return The previous value of precision(). -: 708: */ -: 709: streamsize 2: 710: precision(streamsize __prec) -: 711: { 2: 712: streamsize __old = _M_precision; 2: 713: _M_precision = __prec; 2: 714: return __old; -: 715: } -: 716: -: 717: /** -: 718: * @brief Flags access. -: 719: * @return The minimum field width to generate on output operations. -: 720: * -: 721: * Minimum field width refers to the number of characters. -: 722: */ -: 723: streamsize -: 724: width() const -: 725: { return _M_width; } -: 726: -: 727: /** -: 728: * @brief Changing flags. -: 729: * @param __wide The new width value. -: 730: * @return The previous value of width(). -: 731: */ -: 732: streamsize -: 733: width(streamsize __wide) -: 734: { -: 735: streamsize __old = _M_width; -: 736: _M_width = __wide; -: 737: return __old; -: 738: } -: 739: -: 740: // [27.4.2.4] ios_base static members -: 741: /** -: 742: * @brief Interaction with the standard C I/O objects. -: 743: * @param __sync Whether to synchronize or not. -: 744: * @return True if the standard streams were previously synchronized. -: 745: * -: 746: * The synchronization referred to is @e only that between the standard -: 747: * C facilities (e.g., stdout) and the standard C++ objects (e.g., -: 748: * cout). User-declared streams are unaffected. See -: 749: * https://gcc.gnu.org/onlinedocs/libstdc++/manual/fstreams.html#std.io.filestreams.binary -: 750: */ -: 751: static bool -: 752: sync_with_stdio(bool __sync = true); -: 753: -: 754: // [27.4.2.3] ios_base locale functions -: 755: /** -: 756: * @brief Setting a new locale. -: 757: * @param __loc The new locale. -: 758: * @return The previous locale. -: 759: * -: 760: * Sets the new locale for this stream, and then invokes each callback -: 761: * with imbue_event. -: 762: */ -: 763: locale -: 764: imbue(const locale& __loc) throw(); -: 765: -: 766: /** -: 767: * @brief Locale access -: 768: * @return A copy of the current locale. -: 769: * -: 770: * If @c imbue(loc) has previously been called, then this function -: 771: * returns @c loc. Otherwise, it returns a copy of @c std::locale(), -: 772: * the global C++ locale. -: 773: */ -: 774: locale -: 775: getloc() const -: 776: { return _M_ios_locale; } -: 777: -: 778: /** -: 779: * @brief Locale access -: 780: * @return A reference to the current locale. -: 781: * -: 782: * Like getloc above, but returns a reference instead of -: 783: * generating a copy. -: 784: */ -: 785: const locale& -: 786: _M_getloc() const -: 787: { return _M_ios_locale; } -: 788: -: 789: // [27.4.2.5] ios_base storage functions -: 790: /** -: 791: * @brief Access to unique indices. -: 792: * @return An integer different from all previous calls. -: 793: * -: 794: * This function returns a unique integer every time it is called. It -: 795: * can be used for any purpose, but is primarily intended to be a unique -: 796: * index for the iword and pword functions. The expectation is that an -: 797: * application calls xalloc in order to obtain an index in the iword and -: 798: * pword arrays that can be used without fear of conflict. -: 799: * -: 800: * The implementation maintains a static variable that is incremented and -: 801: * returned on each invocation. xalloc is guaranteed to return an index -: 802: * that is safe to use in the iword and pword arrays. -: 803: */ -: 804: static int -: 805: xalloc() throw(); -: 806: -: 807: /** -: 808: * @brief Access to integer array. -: 809: * @param __ix Index into the array. -: 810: * @return A reference to an integer associated with the index. -: 811: * -: 812: * The iword function provides access to an array of integers that can be -: 813: * used for any purpose. The array grows as required to hold the -: 814: * supplied index. All integers in the array are initialized to 0. -: 815: * -: 816: * The implementation reserves several indices. You should use xalloc to -: 817: * obtain an index that is safe to use. Also note that since the array -: 818: * can grow dynamically, it is not safe to hold onto the reference. -: 819: */ -: 820: long& -: 821: iword(int __ix) -: 822: { -: 823: _Words& __word = ((unsigned)__ix < (unsigned)_M_word_size) -: 824: ? _M_word[__ix] : _M_grow_words(__ix, true); -: 825: return __word._M_iword; -: 826: } -: 827: -: 828: /** -: 829: * @brief Access to void pointer array. -: 830: * @param __ix Index into the array. -: 831: * @return A reference to a void* associated with the index. -: 832: * -: 833: * The pword function provides access to an array of pointers that can be -: 834: * used for any purpose. The array grows as required to hold the -: 835: * supplied index. All pointers in the array are initialized to 0. -: 836: * -: 837: * The implementation reserves several indices. You should use xalloc to -: 838: * obtain an index that is safe to use. Also note that since the array -: 839: * can grow dynamically, it is not safe to hold onto the reference. -: 840: */ -: 841: void*& -: 842: pword(int __ix) -: 843: { -: 844: _Words& __word = ((unsigned)__ix < (unsigned)_M_word_size) -: 845: ? _M_word[__ix] : _M_grow_words(__ix, false); -: 846: return __word._M_pword; -: 847: } -: 848: -: 849: // Destructor -: 850: /** -: 851: * Invokes each callback with erase_event. Destroys local storage. -: 852: * -: 853: * Note that the ios_base object for the standard streams never gets -: 854: * destroyed. As a result, any callbacks registered with the standard -: 855: * streams will not get invoked with erase_event (unless copyfmt is -: 856: * used). -: 857: */ -: 858: virtual ~ios_base(); -: 859: -: 860: protected: -: 861: ios_base() throw (); -: 862: -: 863:#if __cplusplus < 201103L -: 864: // _GLIBCXX_RESOLVE_LIB_DEFECTS -: 865: // 50. Copy constructor and assignment operator of ios_base -: 866: private: -: 867: ios_base(const ios_base&); -: 868: -: 869: ios_base& -: 870: operator=(const ios_base&); -: 871:#else -: 872: public: -: 873: ios_base(const ios_base&) = delete; -: 874: -: 875: ios_base& -: 876: operator=(const ios_base&) = delete; -: 877: -: 878: protected: -: 879: void -: 880: _M_move(ios_base&) noexcept; -: 881: -: 882: void -: 883: _M_swap(ios_base& __rhs) noexcept; -: 884:#endif -: 885: }; -: 886: -: 887: // [27.4.5.1] fmtflags manipulators -: 888: /// Calls base.setf(ios_base::boolalpha). -: 889: inline ios_base& -: 890: boolalpha(ios_base& __base) -: 891: { -: 892: __base.setf(ios_base::boolalpha); -: 893: return __base; -: 894: } -: 895: -: 896: /// Calls base.unsetf(ios_base::boolalpha). -: 897: inline ios_base& -: 898: noboolalpha(ios_base& __base) -: 899: { -: 900: __base.unsetf(ios_base::boolalpha); -: 901: return __base; -: 902: } -: 903: -: 904: /// Calls base.setf(ios_base::showbase). -: 905: inline ios_base& -: 906: showbase(ios_base& __base) -: 907: { -: 908: __base.setf(ios_base::showbase); -: 909: return __base; -: 910: } -: 911: -: 912: /// Calls base.unsetf(ios_base::showbase). -: 913: inline ios_base& -: 914: noshowbase(ios_base& __base) -: 915: { -: 916: __base.unsetf(ios_base::showbase); -: 917: return __base; -: 918: } -: 919: -: 920: /// Calls base.setf(ios_base::showpoint). -: 921: inline ios_base& -: 922: showpoint(ios_base& __base) -: 923: { -: 924: __base.setf(ios_base::showpoint); -: 925: return __base; -: 926: } -: 927: -: 928: /// Calls base.unsetf(ios_base::showpoint). -: 929: inline ios_base& -: 930: noshowpoint(ios_base& __base) -: 931: { -: 932: __base.unsetf(ios_base::showpoint); -: 933: return __base; -: 934: } -: 935: -: 936: /// Calls base.setf(ios_base::showpos). -: 937: inline ios_base& -: 938: showpos(ios_base& __base) -: 939: { -: 940: __base.setf(ios_base::showpos); -: 941: return __base; -: 942: } -: 943: -: 944: /// Calls base.unsetf(ios_base::showpos). -: 945: inline ios_base& -: 946: noshowpos(ios_base& __base) -: 947: { -: 948: __base.unsetf(ios_base::showpos); -: 949: return __base; -: 950: } -: 951: -: 952: /// Calls base.setf(ios_base::skipws). -: 953: inline ios_base& -: 954: skipws(ios_base& __base) -: 955: { -: 956: __base.setf(ios_base::skipws); -: 957: return __base; -: 958: } -: 959: -: 960: /// Calls base.unsetf(ios_base::skipws). -: 961: inline ios_base& -: 962: noskipws(ios_base& __base) -: 963: { -: 964: __base.unsetf(ios_base::skipws); -: 965: return __base; -: 966: } -: 967: -: 968: /// Calls base.setf(ios_base::uppercase). -: 969: inline ios_base& -: 970: uppercase(ios_base& __base) -: 971: { -: 972: __base.setf(ios_base::uppercase); -: 973: return __base; -: 974: } -: 975: -: 976: /// Calls base.unsetf(ios_base::uppercase). -: 977: inline ios_base& -: 978: nouppercase(ios_base& __base) -: 979: { -: 980: __base.unsetf(ios_base::uppercase); -: 981: return __base; -: 982: } -: 983: -: 984: /// Calls base.setf(ios_base::unitbuf). -: 985: inline ios_base& -: 986: unitbuf(ios_base& __base) -: 987: { -: 988: __base.setf(ios_base::unitbuf); -: 989: return __base; -: 990: } -: 991: -: 992: /// Calls base.unsetf(ios_base::unitbuf). -: 993: inline ios_base& -: 994: nounitbuf(ios_base& __base) -: 995: { -: 996: __base.unsetf(ios_base::unitbuf); -: 997: return __base; -: 998: } -: 999: -: 1000: // [27.4.5.2] adjustfield manipulators -: 1001: /// Calls base.setf(ios_base::internal, ios_base::adjustfield). -: 1002: inline ios_base& -: 1003: internal(ios_base& __base) -: 1004: { -: 1005: __base.setf(ios_base::internal, ios_base::adjustfield); -: 1006: return __base; -: 1007: } -: 1008: -: 1009: /// Calls base.setf(ios_base::left, ios_base::adjustfield). -: 1010: inline ios_base& -: 1011: left(ios_base& __base) -: 1012: { -: 1013: __base.setf(ios_base::left, ios_base::adjustfield); -: 1014: return __base; -: 1015: } -: 1016: -: 1017: /// Calls base.setf(ios_base::right, ios_base::adjustfield). -: 1018: inline ios_base& -: 1019: right(ios_base& __base) -: 1020: { -: 1021: __base.setf(ios_base::right, ios_base::adjustfield); -: 1022: return __base; -: 1023: } -: 1024: -: 1025: // [27.4.5.3] basefield manipulators -: 1026: /// Calls base.setf(ios_base::dec, ios_base::basefield). -: 1027: inline ios_base& -: 1028: dec(ios_base& __base) -: 1029: { -: 1030: __base.setf(ios_base::dec, ios_base::basefield); -: 1031: return __base; -: 1032: } -: 1033: -: 1034: /// Calls base.setf(ios_base::hex, ios_base::basefield). -: 1035: inline ios_base& -: 1036: hex(ios_base& __base) -: 1037: { -: 1038: __base.setf(ios_base::hex, ios_base::basefield); -: 1039: return __base; -: 1040: } -: 1041: -: 1042: /// Calls base.setf(ios_base::oct, ios_base::basefield). -: 1043: inline ios_base& -: 1044: oct(ios_base& __base) -: 1045: { -: 1046: __base.setf(ios_base::oct, ios_base::basefield); -: 1047: return __base; -: 1048: } -: 1049: -: 1050: // [27.4.5.4] floatfield manipulators -: 1051: /// Calls base.setf(ios_base::fixed, ios_base::floatfield). -: 1052: inline ios_base& -: 1053: fixed(ios_base& __base) -: 1054: { -: 1055: __base.setf(ios_base::fixed, ios_base::floatfield); -: 1056: return __base; -: 1057: } -: 1058: -: 1059: /// Calls base.setf(ios_base::scientific, ios_base::floatfield). -: 1060: inline ios_base& 16: 1061: scientific(ios_base& __base) -: 1062: { 16: 1063: __base.setf(ios_base::scientific, ios_base::floatfield); 16: 1064: return __base; -: 1065: } -: 1066: -: 1067:#if __cplusplus >= 201103L -: 1068: // New C++11 floatfield manipulators -: 1069: -: 1070: /// Calls -: 1071: /// base.setf(ios_base::fixed|ios_base::scientific, ios_base::floatfield) -: 1072: inline ios_base& -: 1073: hexfloat(ios_base& __base) -: 1074: { -: 1075: __base.setf(ios_base::fixed | ios_base::scientific, ios_base::floatfield); -: 1076: return __base; -: 1077: } -: 1078: -: 1079: /// Calls @c base.unsetf(ios_base::floatfield) -: 1080: inline ios_base& 24: 1081: defaultfloat(ios_base& __base) -: 1082: { 24: 1083: __base.unsetf(ios_base::floatfield); 24: 1084: return __base; -: 1085: } -: 1086:#endif -: 1087: -: 1088:_GLIBCXX_END_NAMESPACE_VERSION -: 1089:} // namespace -: 1090: -: 1091:#endif /* _IOS_BASE_H */ <<<<<< EOF # path=tests/is_even.hpp.gcov -: 0:Source:../include/gcem_incl/is_even.hpp -: 0:Graph:./is_odd.gcno -: 0:Data:./is_odd.gcda -: 0:Runs:1 -: 1:/*################################################################################ -: 2: ## -: 3: ## Copyright (C) 2016-2022 Keith O'Hara -: 4: ## -: 5: ## This file is part of the GCE-Math C++ library. -: 6: ## -: 7: ## Licensed under the Apache License, Version 2.0 (the "License"); -: 8: ## you may not use this file except in compliance with the License. -: 9: ## You may obtain a copy of the License at -: 10: ## -: 11: ## http://www.apache.org/licenses/LICENSE-2.0 -: 12: ## -: 13: ## Unless required by applicable law or agreed to in writing, software -: 14: ## distributed under the License is distributed on an "AS IS" BASIS, -: 15: ## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -: 16: ## See the License for the specific language governing permissions and -: 17: ## limitations under the License. -: 18: ## -: 19: ################################################################################*/ -: 20: -: 21:/* -: 22: * compile-time check if integer is even -: 23: */ -: 24: -: 25:#ifndef _gcem_is_even_HPP -: 26:#define _gcem_is_even_HPP -: 27: -: 28:namespace internal -: 29:{ -: 30: -: 31:constexpr -: 32:bool 2: 33:is_even(const llint_t x) -: 34:noexcept -: 35:{ 2: 36: return !is_odd(x); -: 37:} -: 38: -: 39:} -: 40: -: 41:#endif <<<<<< EOF # path=tests/is_finite.hpp.gcov -: 0:Source:../include/gcem_incl/is_finite.hpp -: 0:Graph:./incomplete_gamma_inv.gcno -: 0:Data:./incomplete_gamma_inv.gcda -: 0:Runs:1 -: 1:/*################################################################################ -: 2: ## -: 3: ## Copyright (C) 2016-2022 Keith O'Hara -: 4: ## -: 5: ## This file is part of the GCE-Math C++ library. -: 6: ## -: 7: ## Licensed under the Apache License, Version 2.0 (the "License"); -: 8: ## you may not use this file except in compliance with the License. -: 9: ## You may obtain a copy of the License at -: 10: ## -: 11: ## http://www.apache.org/licenses/LICENSE-2.0 -: 12: ## -: 13: ## Unless required by applicable law or agreed to in writing, software -: 14: ## distributed under the License is distributed on an "AS IS" BASIS, -: 15: ## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -: 16: ## See the License for the specific language governing permissions and -: 17: ## limitations under the License. -: 18: ## -: 19: ################################################################################*/ -: 20: -: 21:/* -: 22: * compile-time check if a float is not NaN-valued or +/-Inf -: 23: */ -: 24: -: 25:#ifndef _gcem_is_finite_HPP -: 26:#define _gcem_is_finite_HPP -: 27: -: 28:namespace internal -: 29:{ -: 30: -: 31:template -: 32:constexpr -: 33:bool 117504: 34:is_finite(const T x) -: 35:noexcept -: 36:{ 117504*: 37: return (!is_nan(x)) && (!is_inf(x)); -: 38:} -: 39: -: 40:template -: 41:constexpr -: 42:bool -: 43:any_finite(const T1 x, const T2 y) -: 44:noexcept -: 45:{ -: 46: return( is_finite(x) || is_finite(y) ); -: 47:} -: 48: -: 49:template -: 50:constexpr -: 51:bool -: 52:all_finite(const T1 x, const T2 y) -: 53:noexcept -: 54:{ -: 55: return( is_finite(x) && is_finite(y) ); -: 56:} -: 57: -: 58:template -: 59:constexpr -: 60:bool -: 61:any_finite(const T1 x, const T2 y, const T3 z) -: 62:noexcept -: 63:{ -: 64: return( is_finite(x) || is_finite(y) || is_finite(z) ); -: 65:} -: 66: -: 67:template -: 68:constexpr -: 69:bool -: 70:all_finite(const T1 x, const T2 y, const T3 z) -: 71:noexcept -: 72:{ -: 73: return( is_finite(x) && is_finite(y) && is_finite(z) ); -: 74:} -: 75: -: 76:} -: 77: -: 78:#endif <<<<<< EOF # path=tests/is_inf.hpp.gcov -: 0:Source:../include/gcem_incl/is_inf.hpp -: 0:Graph:./incomplete_gamma_inv.gcno -: 0:Data:./incomplete_gamma_inv.gcda -: 0:Runs:1 -: 1:/*################################################################################ -: 2: ## -: 3: ## Copyright (C) 2016-2022 Keith O'Hara -: 4: ## -: 5: ## This file is part of the GCE-Math C++ library. -: 6: ## -: 7: ## Licensed under the Apache License, Version 2.0 (the "License"); -: 8: ## you may not use this file except in compliance with the License. -: 9: ## You may obtain a copy of the License at -: 10: ## -: 11: ## http://www.apache.org/licenses/LICENSE-2.0 -: 12: ## -: 13: ## Unless required by applicable law or agreed to in writing, software -: 14: ## distributed under the License is distributed on an "AS IS" BASIS, -: 15: ## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -: 16: ## See the License for the specific language governing permissions and -: 17: ## limitations under the License. -: 18: ## -: 19: ################################################################################*/ -: 20: -: 21:/* -: 22: * compile-time check if a float is +/-Inf -: 23: */ -: 24: -: 25:#ifndef _gcem_is_inf_HPP -: 26:#define _gcem_is_inf_HPP -: 27: -: 28:namespace internal -: 29:{ -: 30: -: 31:template -: 32:constexpr -: 33:bool 146880: 34:is_neginf(const T x) -: 35:noexcept -: 36:{ 146880: 37: return x == - GCLIM::infinity(); -: 38:} -: 39: -: 40:template -: 41:constexpr -: 42:bool -: 43:any_neginf(const T1 x, const T2 y) -: 44:noexcept -: 45:{ -: 46: return( is_neginf(x) || is_neginf(y) ); -: 47:} -: 48: -: 49:template -: 50:constexpr -: 51:bool -: 52:all_neginf(const T1 x, const T2 y) -: 53:noexcept -: 54:{ -: 55: return( is_neginf(x) && is_neginf(y) ); -: 56:} -: 57: -: 58:template -: 59:constexpr -: 60:bool -: 61:any_neginf(const T1 x, const T2 y, const T3 z) -: 62:noexcept -: 63:{ -: 64: return( is_neginf(x) || is_neginf(y) || is_neginf(z) ); -: 65:} -: 66: -: 67:template -: 68:constexpr -: 69:bool -: 70:all_neginf(const T1 x, const T2 y, const T3 z) -: 71:noexcept -: 72:{ -: 73: return( is_neginf(x) && is_neginf(y) && is_neginf(z) ); -: 74:} -: 75: -: 76:// -: 77: -: 78:template -: 79:constexpr -: 80:bool 151568: 81:is_posinf(const T x) -: 82:noexcept -: 83:{ 151568: 84: return x == GCLIM::infinity(); -: 85:} -: 86: -: 87:template -: 88:constexpr -: 89:bool -: 90:any_posinf(const T1 x, const T2 y) -: 91:noexcept -: 92:{ -: 93: return( is_posinf(x) || is_posinf(y) ); -: 94:} -: 95: -: 96:template -: 97:constexpr -: 98:bool -: 99:all_posinf(const T1 x, const T2 y) -: 100:noexcept -: 101:{ -: 102: return( is_posinf(x) && is_posinf(y) ); -: 103:} -: 104: -: 105:template -: 106:constexpr -: 107:bool -: 108:any_posinf(const T1 x, const T2 y, const T3 z) -: 109:noexcept -: 110:{ -: 111: return( is_posinf(x) || is_posinf(y) || is_posinf(z) ); -: 112:} -: 113: -: 114:template -: 115:constexpr -: 116:bool -: 117:all_posinf(const T1 x, const T2 y, const T3 z) -: 118:noexcept -: 119:{ -: 120: return( is_posinf(x) && is_posinf(y) && is_posinf(z) ); -: 121:} -: 122: -: 123:// -: 124: -: 125:template -: 126:constexpr -: 127:bool 117504: 128:is_inf(const T x) -: 129:noexcept -: 130:{ 117504*: 131: return( is_neginf(x) || is_posinf(x) ); -: 132:} -: 133: -: 134:template -: 135:constexpr -: 136:bool -: 137:any_inf(const T1 x, const T2 y) -: 138:noexcept -: 139:{ -: 140: return( is_inf(x) || is_inf(y) ); -: 141:} -: 142: -: 143:template -: 144:constexpr -: 145:bool -: 146:all_inf(const T1 x, const T2 y) -: 147:noexcept -: 148:{ -: 149: return( is_inf(x) && is_inf(y) ); -: 150:} -: 151: -: 152:template -: 153:constexpr -: 154:bool -: 155:any_inf(const T1 x, const T2 y, const T3 z) -: 156:noexcept -: 157:{ -: 158: return( is_inf(x) || is_inf(y) || is_inf(z) ); -: 159:} -: 160: -: 161:template -: 162:constexpr -: 163:bool -: 164:all_inf(const T1 x, const T2 y, const T3 z) -: 165:noexcept -: 166:{ -: 167: return( is_inf(x) && is_inf(y) && is_inf(z) ); -: 168:} -: 169: -: 170:} -: 171: -: 172:#endif <<<<<< EOF # path=tests/is_nan.hpp.gcov -: 0:Source:../include/gcem_incl/is_nan.hpp -: 0:Graph:log.gcno -: 0:Data:log.gcda -: 0:Runs:2 -: 1:/*################################################################################ -: 2: ## -: 3: ## Copyright (C) 2016-2022 Keith O'Hara -: 4: ## -: 5: ## This file is part of the GCE-Math C++ library. -: 6: ## -: 7: ## Licensed under the Apache License, Version 2.0 (the "License"); -: 8: ## you may not use this file except in compliance with the License. -: 9: ## You may obtain a copy of the License at -: 10: ## -: 11: ## http://www.apache.org/licenses/LICENSE-2.0 -: 12: ## -: 13: ## Unless required by applicable law or agreed to in writing, software -: 14: ## distributed under the License is distributed on an "AS IS" BASIS, -: 15: ## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -: 16: ## See the License for the specific language governing permissions and -: 17: ## limitations under the License. -: 18: ## -: 19: ################################################################################*/ -: 20: -: 21:/* -: 22: * compile-time check if a float is NaN-valued -: 23: */ -: 24: -: 25:#ifndef _gcem_is_nan_HPP -: 26:#define _gcem_is_nan_HPP -: 27: -: 28:namespace internal -: 29:{ -: 30: -: 31:// future: consider using __builtin_isnan(__x) -: 32: -: 33:template -: 34:constexpr -: 35:bool 2: 36:is_nan(const T x) -: 37:noexcept -: 38:{ 2: 39: return x != x; -: 40:} -: 41: -: 42:template -: 43:constexpr -: 44:bool -: 45:any_nan(const T1 x, const T2 y) -: 46:noexcept -: 47:{ -: 48: return( is_nan(x) || is_nan(y) ); -: 49:} -: 50: -: 51:template -: 52:constexpr -: 53:bool -: 54:all_nan(const T1 x, const T2 y) -: 55:noexcept -: 56:{ -: 57: return( is_nan(x) && is_nan(y) ); -: 58:} -: 59: -: 60:template -: 61:constexpr -: 62:bool -: 63:any_nan(const T1 x, const T2 y, const T3 z) -: 64:noexcept -: 65:{ -: 66: return( is_nan(x) || is_nan(y) || is_nan(z) ); -: 67:} -: 68: -: 69:template -: 70:constexpr -: 71:bool -: 72:all_nan(const T1 x, const T2 y, const T3 z) -: 73:noexcept -: 74:{ -: 75: return( is_nan(x) && is_nan(y) && is_nan(z) ); -: 76:} -: 77: -: 78:} -: 79: -: 80:#endif <<<<<< EOF # path=tests/is_odd.cpp.gcov -: 0:Source:is_odd.cpp -: 0:Graph:./is_odd.gcno -: 0:Data:./is_odd.gcda -: 0:Runs:1 -: 1:/*################################################################################ -: 2: ## -: 3: ## Copyright (C) 2016-2022 Keith O'Hara -: 4: ## -: 5: ## This file is part of the GCE-Math C++ library. -: 6: ## -: 7: ## Licensed under the Apache License, Version 2.0 (the "License"); -: 8: ## you may not use this file except in compliance with the License. -: 9: ## You may obtain a copy of the License at -: 10: ## -: 11: ## http://www.apache.org/licenses/LICENSE-2.0 -: 12: ## -: 13: ## Unless required by applicable law or agreed to in writing, software -: 14: ## distributed under the License is distributed on an "AS IS" BASIS, -: 15: ## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -: 16: ## See the License for the specific language governing permissions and -: 17: ## limitations under the License. -: 18: ## -: 19: ################################################################################*/ -: 20: -: 21:#include "gcem_tests.hpp" -: 22: 1: 23:int main() -: 24:{ 1: 25: std::cout << "\n*** begin is_odd test ***\n" << std::endl; -: 26: -: 27: // -: 28: 1: 29: int run_val = 0; -: 30: 1: 31: run_val += gcem::internal::is_odd(1); 1: 32: run_val += gcem::internal::is_odd(3); 1: 33: run_val += gcem::internal::is_odd(-5); 1: 34: run_val += gcem::internal::is_even(10UL); 1: 35: run_val += gcem::internal::is_odd(-400009L); 1: 36: run_val += gcem::internal::is_even(100000000L); -: 37: 1: 38: if (run_val == 6) 1: 39: std::cout << "\033[32m All OK.\033[0m" << std::endl; -: 40: else #####: 41: throw std::runtime_error("test fail"); -: 42: -: 43: // -: 44: 1: 45: std::cout << "\n*** end is_odd test ***\n" << std::endl; -: 46: 1: 47: return 0; -: 48:} <<<<<< EOF # path=tests/is_odd.hpp.gcov -: 0:Source:../include/gcem_incl/is_odd.hpp -: 0:Graph:./is_odd.gcno -: 0:Data:./is_odd.gcda -: 0:Runs:1 -: 1:/*################################################################################ -: 2: ## -: 3: ## Copyright (C) 2016-2022 Keith O'Hara -: 4: ## -: 5: ## This file is part of the GCE-Math C++ library. -: 6: ## -: 7: ## Licensed under the Apache License, Version 2.0 (the "License"); -: 8: ## you may not use this file except in compliance with the License. -: 9: ## You may obtain a copy of the License at -: 10: ## -: 11: ## http://www.apache.org/licenses/LICENSE-2.0 -: 12: ## -: 13: ## Unless required by applicable law or agreed to in writing, software -: 14: ## distributed under the License is distributed on an "AS IS" BASIS, -: 15: ## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -: 16: ## See the License for the specific language governing permissions and -: 17: ## limitations under the License. -: 18: ## -: 19: ################################################################################*/ -: 20: -: 21:/* -: 22: * compile-time check if integer is odd -: 23: */ -: 24: -: 25:#ifndef _gcem_is_odd_HPP -: 26:#define _gcem_is_odd_HPP -: 27: -: 28:namespace internal -: 29:{ -: 30: -: 31:constexpr -: 32:bool 6: 33:is_odd(const llint_t x) -: 34:noexcept -: 35:{ -: 36: // return( x % llint_t(2) == llint_t(0) ? false : true ); 6: 37: return (x & 1U) != 0; -: 38:} -: 39: -: 40:} -: 41: -: 42:#endif <<<<<< EOF # path=tests/lcm.cpp.gcov -: 0:Source:lcm.cpp -: 0:Graph:./lcm.gcno -: 0:Data:./lcm.gcda -: 0:Runs:1 -: 1:/*################################################################################ -: 2: ## -: 3: ## Copyright (C) 2016-2022 Keith O'Hara -: 4: ## -: 5: ## This file is part of the GCE-Math C++ library. -: 6: ## -: 7: ## Licensed under the Apache License, Version 2.0 (the "License"); -: 8: ## you may not use this file except in compliance with the License. -: 9: ## You may obtain a copy of the License at -: 10: ## -: 11: ## http://www.apache.org/licenses/LICENSE-2.0 -: 12: ## -: 13: ## Unless required by applicable law or agreed to in writing, software -: 14: ## distributed under the License is distributed on an "AS IS" BASIS, -: 15: ## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -: 16: ## See the License for the specific language governing permissions and -: 17: ## limitations under the License. -: 18: ## -: 19: ################################################################################*/ -: 20: -: 21:#define TEST_VAL_TYPES int -: 22: -: 23:#include "gcem_tests.hpp" -: 24: 1: 25:int main() -: 26:{ 1: 27: print_begin("lcm"); -: 28: -: 29: // -: 30: 2*: 31: GCEM_TEST_EXPECTED_VAL(gcem::lcm,12,3,4); 2*: 32: GCEM_TEST_EXPECTED_VAL(gcem::lcm,60,12,15); 2*: 33: GCEM_TEST_EXPECTED_VAL(gcem::lcm,1377,17,81); -: 34: -: 35: // -: 36: 1: 37: print_final("lcm"); -: 38: 1: 39: return 0; -: 40:} <<<<<< EOF # path=tests/lgamma.cpp.gcov -: 0:Source:lgamma.cpp -: 0:Graph:./lgamma.gcno -: 0:Data:./lgamma.gcda -: 0:Runs:1 -: 1:/*################################################################################ -: 2: ## -: 3: ## Copyright (C) 2016-2022 Keith O'Hara -: 4: ## -: 5: ## This file is part of the GCE-Math C++ library. -: 6: ## -: 7: ## Licensed under the Apache License, Version 2.0 (the "License"); -: 8: ## you may not use this file except in compliance with the License. -: 9: ## You may obtain a copy of the License at -: 10: ## -: 11: ## http://www.apache.org/licenses/LICENSE-2.0 -: 12: ## -: 13: ## Unless required by applicable law or agreed to in writing, software -: 14: ## distributed under the License is distributed on an "AS IS" BASIS, -: 15: ## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -: 16: ## See the License for the specific language governing permissions and -: 17: ## limitations under the License. -: 18: ## -: 19: ################################################################################*/ -: 20: -: 21:#define TEST_PRINT_PRECISION_1 2 -: 22:#define TEST_PRINT_PRECISION_2 18 -: 23: -: 24:#include "gcem_tests.hpp" -: 25: 1: 26:int main() -: 27:{ 1: 28: print_begin("lgamma"); -: 29: -: 30: // -: 31: 2*: 32: GCEM_TEST_COMPARE_VALS(gcem::lgamma,std::lgamma, 1.5L); 2*: 33: GCEM_TEST_COMPARE_VALS(gcem::lgamma,std::lgamma, 0.7L); 2*: 34: GCEM_TEST_COMPARE_VALS(gcem::lgamma,std::lgamma, 1.0L); 2*: 35: GCEM_TEST_COMPARE_VALS(gcem::lgamma,std::lgamma, 0.0L); 2*: 36: GCEM_TEST_COMPARE_VALS(gcem::lgamma,std::lgamma, -1.0L); -: 37: 2*: 38: GCEM_TEST_COMPARE_VALS(gcem::lgamma,std::lgamma, TEST_NAN); -: 39: -: 40: // -: 41: 1: 42: print_final("lgamma"); -: 43: 1: 44: return 0; -: 45:} <<<<<< EOF # path=tests/lgamma.hpp.gcov -: 0:Source:../include/gcem_incl/lgamma.hpp -: 0:Graph:./incomplete_gamma_inv.gcno -: 0:Data:./incomplete_gamma_inv.gcda -: 0:Runs:1 -: 1:/*################################################################################ -: 2: ## -: 3: ## Copyright (C) 2016-2022 Keith O'Hara -: 4: ## -: 5: ## This file is part of the GCE-Math C++ library. -: 6: ## -: 7: ## Licensed under the Apache License, Version 2.0 (the "License"); -: 8: ## you may not use this file except in compliance with the License. -: 9: ## You may obtain a copy of the License at -: 10: ## -: 11: ## http://www.apache.org/licenses/LICENSE-2.0 -: 12: ## -: 13: ## Unless required by applicable law or agreed to in writing, software -: 14: ## distributed under the License is distributed on an "AS IS" BASIS, -: 15: ## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -: 16: ## See the License for the specific language governing permissions and -: 17: ## limitations under the License. -: 18: ## -: 19: ################################################################################*/ -: 20: -: 21:/* -: 22: * compile-time log-gamma function -: 23: * -: 24: * for coefficient values, see: -: 25: * http://my.fit.edu/~gabdo/gamma.txt -: 26: */ -: 27: -: 28:#ifndef _gcem_lgamma_HPP -: 29:#define _gcem_lgamma_HPP -: 30: -: 31:namespace internal -: 32:{ -: 33: -: 34:// P. Godfrey's coefficients: -: 35:// -: 36:// 0.99999999999999709182 -: 37:// 57.156235665862923517 -: 38:// -59.597960355475491248 -: 39:// 14.136097974741747174 -: 40:// -0.49191381609762019978 -: 41:// .33994649984811888699e-4 -: 42:// .46523628927048575665e-4 -: 43:// -.98374475304879564677e-4 -: 44:// .15808870322491248884e-3 -: 45:// -.21026444172410488319e-3 -: 46:// .21743961811521264320e-3 -: 47:// -.16431810653676389022e-3 -: 48:// .84418223983852743293e-4 -: 49:// -.26190838401581408670e-4 -: 50:// .36899182659531622704e-5 -: 51: -: 52:constexpr -: 53:long double 592: 54:lgamma_coef_term(const long double x) -: 55:noexcept -: 56:{ 592: 57: return( 0.99999999999999709182L + 57.156235665862923517L / (x+1) \ 592: 58: - 59.597960355475491248L / (x+2) + 14.136097974741747174L / (x+3) \ 592: 59: - 0.49191381609762019978L / (x+4) + .33994649984811888699e-4L / (x+5) \ 592: 60: + .46523628927048575665e-4L / (x+6) - .98374475304879564677e-4L / (x+7) \ 592: 61: + .15808870322491248884e-3L / (x+8) - .21026444172410488319e-3L / (x+9) \ 592: 62: + .21743961811521264320e-3L / (x+10) - .16431810653676389022e-3L / (x+11) \ 592: 63: + .84418223983852743293e-4L / (x+12) - .26190838401581408670e-4L / (x+13) \ 592: 64: + .36899182659531622704e-5L / (x+14) ); -: 65:} -: 66: -: 67:template -: 68:constexpr -: 69:T 592: 70:lgamma_term_2(const T x) -: 71:noexcept -: 72:{ // 592: 73: return( T(GCEM_LOG_SQRT_2PI) + log(T(lgamma_coef_term(x))) ); -: 74:} -: 75: -: 76:template -: 77:constexpr -: 78:T 592: 79:lgamma_term_1(const T x) -: 80:noexcept -: 81:{ // note: 607/128 + 0.5 = 5.2421875 592: 82: return( (x + T(0.5))*log(x + T(5.2421875L)) - (x + T(5.2421875L)) ); -: 83:} -: 84: -: 85:template -: 86:constexpr -: 87:T 592: 88:lgamma_begin(const T x) -: 89:noexcept -: 90:{ // returns lngamma(x+1) 592: 91: return( lgamma_term_1(x) + lgamma_term_2(x) ); -: 92:} -: 93: -: 94:template -: 95:constexpr -: 96:T 592: 97:lgamma_check(const T x) -: 98:noexcept -: 99:{ -: 100: return( // NaN check 1184: 101: is_nan(x) ? \ #####: 102: GCLIM::quiet_NaN() : -: 103: // indistinguishable from one or <= zero 1184*: 104: GCLIM::min() > abs(x - T(1)) ? \ -: 105: T(0) : 592: 106: GCLIM::min() > x ? \ #####: 107: GCLIM::infinity() : -: 108: // else 1184: 109: lgamma_begin(x - T(1)) ); -: 110:} -: 111: -: 112:} -: 113: -: 114:/** -: 115: * Compile-time log-gamma function -: 116: * -: 117: * @param x a real-valued input. -: 118: * @return computes the log-gamma function -: 119: * \f[ \ln \Gamma(x) = \ln \int_0^\infty y^{x-1} \exp(-y) dy \f] -: 120: * using a polynomial form: -: 121: * \f[ \Gamma(x+1) \approx (x+g+0.5)^{x+0.5} \exp(-x-g-0.5) \sqrt{2 \pi} \left[ c_0 + \frac{c_1}{x+1} + \frac{c_2}{x+2} + \cdots + \frac{c_n}{x+n} \right] \f] -: 122: * where the value \f$ g \f$ and the coefficients \f$ (c_0, c_1, \ldots, c_n) \f$ -: 123: * are taken from Paul Godfrey, whose note can be found here: http://my.fit.edu/~gabdo/gamma.txt -: 124: */ -: 125: -: 126:template -: 127:constexpr -: 128:return_t 592: 129:lgamma(const T x) -: 130:noexcept -: 131:{ 592: 132: return internal::lgamma_check( static_cast>(x) ); -: 133:} -: 134: -: 135:#endif <<<<<< EOF # path=tests/limits.gcov -: 0:Source:/usr/include/c++/9/limits -: 0:Graph:log.gcno -: 0:Data:log.gcda -: 0:Runs:2 -: 1:// The template and inlines for the numeric_limits classes. -*- C++ -*- -: 2: -: 3:// Copyright (C) 1999-2019 Free Software Foundation, Inc. -: 4:// -: 5:// This file is part of the GNU ISO C++ Library. This library is free -: 6:// software; you can redistribute it and/or modify it under the -: 7:// terms of the GNU General Public License as published by the -: 8:// Free Software Foundation; either version 3, or (at your option) -: 9:// any later version. -: 10: -: 11:// This library is distributed in the hope that it will be useful, -: 12:// but WITHOUT ANY WARRANTY; without even the implied warranty of -: 13:// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -: 14:// GNU General Public License for more details. -: 15: -: 16:// Under Section 7 of GPL version 3, you are granted additional -: 17:// permissions described in the GCC Runtime Library Exception, version -: 18:// 3.1, as published by the Free Software Foundation. -: 19: -: 20:// You should have received a copy of the GNU General Public License and -: 21:// a copy of the GCC Runtime Library Exception along with this program; -: 22:// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see -: 23:// . -: 24: -: 25:/** @file include/limits -: 26: * This is a Standard C++ Library header. -: 27: */ -: 28: -: 29:// Note: this is not a conforming implementation. -: 30:// Written by Gabriel Dos Reis -: 31: -: 32:// -: 33:// ISO 14882:1998 -: 34:// 18.2.1 -: 35:// -: 36: -: 37:#ifndef _GLIBCXX_NUMERIC_LIMITS -: 38:#define _GLIBCXX_NUMERIC_LIMITS 1 -: 39: -: 40:#pragma GCC system_header -: 41: -: 42:#include -: 43: -: 44:// -: 45:// The numeric_limits<> traits document implementation-defined aspects -: 46:// of fundamental arithmetic data types (integers and floating points). -: 47:// From Standard C++ point of view, there are 14 such types: -: 48:// * integers -: 49:// bool (1) -: 50:// char, signed char, unsigned char, wchar_t (4) -: 51:// short, unsigned short (2) -: 52:// int, unsigned (2) -: 53:// long, unsigned long (2) -: 54:// -: 55:// * floating points -: 56:// float (1) -: 57:// double (1) -: 58:// long double (1) -: 59:// -: 60:// GNU C++ understands (where supported by the host C-library) -: 61:// * integer -: 62:// long long, unsigned long long (2) -: 63:// -: 64:// which brings us to 16 fundamental arithmetic data types in GNU C++. -: 65:// -: 66:// -: 67:// Since a numeric_limits<> is a bit tricky to get right, we rely on -: 68:// an interface composed of macros which should be defined in config/os -: 69:// or config/cpu when they differ from the generic (read arbitrary) -: 70:// definitions given here. -: 71:// -: 72: -: 73:// These values can be overridden in the target configuration file. -: 74:// The default values are appropriate for many 32-bit targets. -: 75: -: 76:// GCC only intrinsically supports modulo integral types. The only remaining -: 77:// integral exceptional values is division by zero. Only targets that do not -: 78:// signal division by zero in some "hard to ignore" way should use false. -: 79:#ifndef __glibcxx_integral_traps -: 80:# define __glibcxx_integral_traps true -: 81:#endif -: 82: -: 83:// float -: 84:// -: 85: -: 86:// Default values. Should be overridden in configuration files if necessary. -: 87: -: 88:#ifndef __glibcxx_float_has_denorm_loss -: 89:# define __glibcxx_float_has_denorm_loss false -: 90:#endif -: 91:#ifndef __glibcxx_float_traps -: 92:# define __glibcxx_float_traps false -: 93:#endif -: 94:#ifndef __glibcxx_float_tinyness_before -: 95:# define __glibcxx_float_tinyness_before false -: 96:#endif -: 97: -: 98:// double -: 99: -: 100:// Default values. Should be overridden in configuration files if necessary. -: 101: -: 102:#ifndef __glibcxx_double_has_denorm_loss -: 103:# define __glibcxx_double_has_denorm_loss false -: 104:#endif -: 105:#ifndef __glibcxx_double_traps -: 106:# define __glibcxx_double_traps false -: 107:#endif -: 108:#ifndef __glibcxx_double_tinyness_before -: 109:# define __glibcxx_double_tinyness_before false -: 110:#endif -: 111: -: 112:// long double -: 113: -: 114:// Default values. Should be overridden in configuration files if necessary. -: 115: -: 116:#ifndef __glibcxx_long_double_has_denorm_loss -: 117:# define __glibcxx_long_double_has_denorm_loss false -: 118:#endif -: 119:#ifndef __glibcxx_long_double_traps -: 120:# define __glibcxx_long_double_traps false -: 121:#endif -: 122:#ifndef __glibcxx_long_double_tinyness_before -: 123:# define __glibcxx_long_double_tinyness_before false -: 124:#endif -: 125: -: 126:// You should not need to define any macros below this point. -: 127: -: 128:#define __glibcxx_signed_b(T,B) ((T)(-1) < 0) -: 129: -: 130:#define __glibcxx_min_b(T,B) \ -: 131: (__glibcxx_signed_b (T,B) ? -__glibcxx_max_b (T,B) - 1 : (T)0) -: 132: -: 133:#define __glibcxx_max_b(T,B) \ -: 134: (__glibcxx_signed_b (T,B) ? \ -: 135: (((((T)1 << (__glibcxx_digits_b (T,B) - 1)) - 1) << 1) + 1) : ~(T)0) -: 136: -: 137:#define __glibcxx_digits_b(T,B) \ -: 138: (B - __glibcxx_signed_b (T,B)) -: 139: -: 140:// The fraction 643/2136 approximates log10(2) to 7 significant digits. -: 141:#define __glibcxx_digits10_b(T,B) \ -: 142: (__glibcxx_digits_b (T,B) * 643L / 2136) -: 143: -: 144:#define __glibcxx_signed(T) \ -: 145: __glibcxx_signed_b (T, sizeof(T) * __CHAR_BIT__) -: 146:#define __glibcxx_min(T) \ -: 147: __glibcxx_min_b (T, sizeof(T) * __CHAR_BIT__) -: 148:#define __glibcxx_max(T) \ -: 149: __glibcxx_max_b (T, sizeof(T) * __CHAR_BIT__) -: 150:#define __glibcxx_digits(T) \ -: 151: __glibcxx_digits_b (T, sizeof(T) * __CHAR_BIT__) -: 152:#define __glibcxx_digits10(T) \ -: 153: __glibcxx_digits10_b (T, sizeof(T) * __CHAR_BIT__) -: 154: -: 155:#define __glibcxx_max_digits10(T) \ -: 156: (2 + (T) * 643L / 2136) -: 157: -: 158:namespace std _GLIBCXX_VISIBILITY(default) -: 159:{ -: 160:_GLIBCXX_BEGIN_NAMESPACE_VERSION -: 161: -: 162: /** -: 163: * @brief Describes the rounding style for floating-point types. -: 164: * -: 165: * This is used in the std::numeric_limits class. -: 166: */ -: 167: enum float_round_style -: 168: { -: 169: round_indeterminate = -1, /// Intermediate. -: 170: round_toward_zero = 0, /// To zero. -: 171: round_to_nearest = 1, /// To the nearest representable value. -: 172: round_toward_infinity = 2, /// To infinity. -: 173: round_toward_neg_infinity = 3 /// To negative infinity. -: 174: }; -: 175: -: 176: /** -: 177: * @brief Describes the denormalization for floating-point types. -: 178: * -: 179: * These values represent the presence or absence of a variable number -: 180: * of exponent bits. This type is used in the std::numeric_limits class. -: 181: */ -: 182: enum float_denorm_style -: 183: { -: 184: /// Indeterminate at compile time whether denormalized values are allowed. -: 185: denorm_indeterminate = -1, -: 186: /// The type does not allow denormalized values. -: 187: denorm_absent = 0, -: 188: /// The type allows denormalized values. -: 189: denorm_present = 1 -: 190: }; -: 191: -: 192: /** -: 193: * @brief Part of std::numeric_limits. -: 194: * -: 195: * The @c static @c const members are usable as integral constant -: 196: * expressions. -: 197: * -: 198: * @note This is a separate class for purposes of efficiency; you -: 199: * should only access these members as part of an instantiation -: 200: * of the std::numeric_limits class. -: 201: */ -: 202: struct __numeric_limits_base -: 203: { -: 204: /** This will be true for all fundamental types (which have -: 205: specializations), and false for everything else. */ -: 206: static _GLIBCXX_USE_CONSTEXPR bool is_specialized = false; -: 207: -: 208: /** The number of @c radix digits that be represented without change: for -: 209: integer types, the number of non-sign bits in the mantissa; for -: 210: floating types, the number of @c radix digits in the mantissa. */ -: 211: static _GLIBCXX_USE_CONSTEXPR int digits = 0; -: 212: -: 213: /** The number of base 10 digits that can be represented without change. */ -: 214: static _GLIBCXX_USE_CONSTEXPR int digits10 = 0; -: 215: -: 216:#if __cplusplus >= 201103L -: 217: /** The number of base 10 digits required to ensure that values which -: 218: differ are always differentiated. */ -: 219: static constexpr int max_digits10 = 0; -: 220:#endif -: 221: -: 222: /** True if the type is signed. */ -: 223: static _GLIBCXX_USE_CONSTEXPR bool is_signed = false; -: 224: -: 225: /** True if the type is integer. */ -: 226: static _GLIBCXX_USE_CONSTEXPR bool is_integer = false; -: 227: -: 228: /** True if the type uses an exact representation. All integer types are -: 229: exact, but not all exact types are integer. For example, rational and -: 230: fixed-exponent representations are exact but not integer. */ -: 231: static _GLIBCXX_USE_CONSTEXPR bool is_exact = false; -: 232: -: 233: /** For integer types, specifies the base of the representation. For -: 234: floating types, specifies the base of the exponent representation. */ -: 235: static _GLIBCXX_USE_CONSTEXPR int radix = 0; -: 236: -: 237: /** The minimum negative integer such that @c radix raised to the power of -: 238: (one less than that integer) is a normalized floating point number. */ -: 239: static _GLIBCXX_USE_CONSTEXPR int min_exponent = 0; -: 240: -: 241: /** The minimum negative integer such that 10 raised to that power is in -: 242: the range of normalized floating point numbers. */ -: 243: static _GLIBCXX_USE_CONSTEXPR int min_exponent10 = 0; -: 244: -: 245: /** The maximum positive integer such that @c radix raised to the power of -: 246: (one less than that integer) is a representable finite floating point -: 247: number. */ -: 248: static _GLIBCXX_USE_CONSTEXPR int max_exponent = 0; -: 249: -: 250: /** The maximum positive integer such that 10 raised to that power is in -: 251: the range of representable finite floating point numbers. */ -: 252: static _GLIBCXX_USE_CONSTEXPR int max_exponent10 = 0; -: 253: -: 254: /** True if the type has a representation for positive infinity. */ -: 255: static _GLIBCXX_USE_CONSTEXPR bool has_infinity = false; -: 256: -: 257: /** True if the type has a representation for a quiet (non-signaling) -: 258: Not a Number. */ -: 259: static _GLIBCXX_USE_CONSTEXPR bool has_quiet_NaN = false; -: 260: -: 261: /** True if the type has a representation for a signaling -: 262: Not a Number. */ -: 263: static _GLIBCXX_USE_CONSTEXPR bool has_signaling_NaN = false; -: 264: -: 265: /** See std::float_denorm_style for more information. */ -: 266: static _GLIBCXX_USE_CONSTEXPR float_denorm_style has_denorm = denorm_absent; -: 267: -: 268: /** True if loss of accuracy is detected as a denormalization loss, -: 269: rather than as an inexact result. */ -: 270: static _GLIBCXX_USE_CONSTEXPR bool has_denorm_loss = false; -: 271: -: 272: /** True if-and-only-if the type adheres to the IEC 559 standard, also -: 273: known as IEEE 754. (Only makes sense for floating point types.) */ -: 274: static _GLIBCXX_USE_CONSTEXPR bool is_iec559 = false; -: 275: -: 276: /** True if the set of values representable by the type is -: 277: finite. All built-in types are bounded, this member would be -: 278: false for arbitrary precision types. */ -: 279: static _GLIBCXX_USE_CONSTEXPR bool is_bounded = false; -: 280: -: 281: /** True if the type is @e modulo. A type is modulo if, for any -: 282: operation involving +, -, or * on values of that type whose -: 283: result would fall outside the range [min(),max()], the value -: 284: returned differs from the true value by an integer multiple of -: 285: max() - min() + 1. On most machines, this is false for floating -: 286: types, true for unsigned integers, and true for signed integers. -: 287: See PR22200 about signed integers. */ -: 288: static _GLIBCXX_USE_CONSTEXPR bool is_modulo = false; -: 289: -: 290: /** True if trapping is implemented for this type. */ -: 291: static _GLIBCXX_USE_CONSTEXPR bool traps = false; -: 292: -: 293: /** True if tininess is detected before rounding. (see IEC 559) */ -: 294: static _GLIBCXX_USE_CONSTEXPR bool tinyness_before = false; -: 295: -: 296: /** See std::float_round_style for more information. This is only -: 297: meaningful for floating types; integer types will all be -: 298: round_toward_zero. */ -: 299: static _GLIBCXX_USE_CONSTEXPR float_round_style round_style = -: 300: round_toward_zero; -: 301: }; -: 302: -: 303: /** -: 304: * @brief Properties of fundamental types. -: 305: * -: 306: * This class allows a program to obtain information about the -: 307: * representation of a fundamental type on a given platform. For -: 308: * non-fundamental types, the functions will return 0 and the data -: 309: * members will all be @c false. -: 310: */ -: 311: template -: 312: struct numeric_limits : public __numeric_limits_base -: 313: { -: 314: /** The minimum finite value, or for floating types with -: 315: denormalization, the minimum positive normalized value. */ -: 316: static _GLIBCXX_CONSTEXPR _Tp -: 317: min() _GLIBCXX_USE_NOEXCEPT { return _Tp(); } -: 318: -: 319: /** The maximum finite value. */ -: 320: static _GLIBCXX_CONSTEXPR _Tp -: 321: max() _GLIBCXX_USE_NOEXCEPT { return _Tp(); } -: 322: -: 323:#if __cplusplus >= 201103L -: 324: /** A finite value x such that there is no other finite value y -: 325: * where y < x. */ -: 326: static constexpr _Tp -: 327: lowest() noexcept { return _Tp(); } -: 328:#endif -: 329: -: 330: /** The @e machine @e epsilon: the difference between 1 and the least -: 331: value greater than 1 that is representable. */ -: 332: static _GLIBCXX_CONSTEXPR _Tp -: 333: epsilon() _GLIBCXX_USE_NOEXCEPT { return _Tp(); } -: 334: -: 335: /** The maximum rounding error measurement (see LIA-1). */ -: 336: static _GLIBCXX_CONSTEXPR _Tp -: 337: round_error() _GLIBCXX_USE_NOEXCEPT { return _Tp(); } -: 338: -: 339: /** The representation of positive infinity, if @c has_infinity. */ -: 340: static _GLIBCXX_CONSTEXPR _Tp -: 341: infinity() _GLIBCXX_USE_NOEXCEPT { return _Tp(); } -: 342: -: 343: /** The representation of a quiet Not a Number, -: 344: if @c has_quiet_NaN. */ -: 345: static _GLIBCXX_CONSTEXPR _Tp -: 346: quiet_NaN() _GLIBCXX_USE_NOEXCEPT { return _Tp(); } -: 347: -: 348: /** The representation of a signaling Not a Number, if -: 349: @c has_signaling_NaN. */ -: 350: static _GLIBCXX_CONSTEXPR _Tp -: 351: signaling_NaN() _GLIBCXX_USE_NOEXCEPT { return _Tp(); } -: 352: -: 353: /** The minimum positive denormalized value. For types where -: 354: @c has_denorm is false, this is the minimum positive normalized -: 355: value. */ -: 356: static _GLIBCXX_CONSTEXPR _Tp -: 357: denorm_min() _GLIBCXX_USE_NOEXCEPT { return _Tp(); } -: 358: }; -: 359: -: 360: // _GLIBCXX_RESOLVE_LIB_DEFECTS -: 361: // 559. numeric_limits -: 362: -: 363: template -: 364: struct numeric_limits -: 365: : public numeric_limits<_Tp> { }; -: 366: -: 367: template -: 368: struct numeric_limits -: 369: : public numeric_limits<_Tp> { }; -: 370: -: 371: template -: 372: struct numeric_limits -: 373: : public numeric_limits<_Tp> { }; -: 374: -: 375: // Now there follow 16 explicit specializations. Yes, 16. Make sure -: 376: // you get the count right. (18 in C++11 mode, with char16_t and char32_t.) -: 377: // (+1 if char8_t is enabled.) -: 378: -: 379: // _GLIBCXX_RESOLVE_LIB_DEFECTS -: 380: // 184. numeric_limits wording problems -: 381: -: 382: /// numeric_limits specialization. -: 383: template<> -: 384: struct numeric_limits -: 385: { -: 386: static _GLIBCXX_USE_CONSTEXPR bool is_specialized = true; -: 387: -: 388: static _GLIBCXX_CONSTEXPR bool -: 389: min() _GLIBCXX_USE_NOEXCEPT { return false; } -: 390: -: 391: static _GLIBCXX_CONSTEXPR bool -: 392: max() _GLIBCXX_USE_NOEXCEPT { return true; } -: 393: -: 394:#if __cplusplus >= 201103L -: 395: static constexpr bool -: 396: lowest() noexcept { return min(); } -: 397:#endif -: 398: static _GLIBCXX_USE_CONSTEXPR int digits = 1; -: 399: static _GLIBCXX_USE_CONSTEXPR int digits10 = 0; -: 400:#if __cplusplus >= 201103L -: 401: static constexpr int max_digits10 = 0; -: 402:#endif -: 403: static _GLIBCXX_USE_CONSTEXPR bool is_signed = false; -: 404: static _GLIBCXX_USE_CONSTEXPR bool is_integer = true; -: 405: static _GLIBCXX_USE_CONSTEXPR bool is_exact = true; -: 406: static _GLIBCXX_USE_CONSTEXPR int radix = 2; -: 407: -: 408: static _GLIBCXX_CONSTEXPR bool -: 409: epsilon() _GLIBCXX_USE_NOEXCEPT { return false; } -: 410: -: 411: static _GLIBCXX_CONSTEXPR bool -: 412: round_error() _GLIBCXX_USE_NOEXCEPT { return false; } -: 413: -: 414: static _GLIBCXX_USE_CONSTEXPR int min_exponent = 0; -: 415: static _GLIBCXX_USE_CONSTEXPR int min_exponent10 = 0; -: 416: static _GLIBCXX_USE_CONSTEXPR int max_exponent = 0; -: 417: static _GLIBCXX_USE_CONSTEXPR int max_exponent10 = 0; -: 418: -: 419: static _GLIBCXX_USE_CONSTEXPR bool has_infinity = false; -: 420: static _GLIBCXX_USE_CONSTEXPR bool has_quiet_NaN = false; -: 421: static _GLIBCXX_USE_CONSTEXPR bool has_signaling_NaN = false; -: 422: static _GLIBCXX_USE_CONSTEXPR float_denorm_style has_denorm -: 423: = denorm_absent; -: 424: static _GLIBCXX_USE_CONSTEXPR bool has_denorm_loss = false; -: 425: -: 426: static _GLIBCXX_CONSTEXPR bool -: 427: infinity() _GLIBCXX_USE_NOEXCEPT { return false; } -: 428: -: 429: static _GLIBCXX_CONSTEXPR bool -: 430: quiet_NaN() _GLIBCXX_USE_NOEXCEPT { return false; } -: 431: -: 432: static _GLIBCXX_CONSTEXPR bool -: 433: signaling_NaN() _GLIBCXX_USE_NOEXCEPT { return false; } -: 434: -: 435: static _GLIBCXX_CONSTEXPR bool -: 436: denorm_min() _GLIBCXX_USE_NOEXCEPT { return false; } -: 437: -: 438: static _GLIBCXX_USE_CONSTEXPR bool is_iec559 = false; -: 439: static _GLIBCXX_USE_CONSTEXPR bool is_bounded = true; -: 440: static _GLIBCXX_USE_CONSTEXPR bool is_modulo = false; -: 441: -: 442: // It is not clear what it means for a boolean type to trap. -: 443: // This is a DR on the LWG issue list. Here, I use integer -: 444: // promotion semantics. -: 445: static _GLIBCXX_USE_CONSTEXPR bool traps = __glibcxx_integral_traps; -: 446: static _GLIBCXX_USE_CONSTEXPR bool tinyness_before = false; -: 447: static _GLIBCXX_USE_CONSTEXPR float_round_style round_style -: 448: = round_toward_zero; -: 449: }; -: 450: -: 451: /// numeric_limits specialization. -: 452: template<> -: 453: struct numeric_limits -: 454: { -: 455: static _GLIBCXX_USE_CONSTEXPR bool is_specialized = true; -: 456: -: 457: static _GLIBCXX_CONSTEXPR char -: 458: min() _GLIBCXX_USE_NOEXCEPT { return __glibcxx_min(char); } -: 459: -: 460: static _GLIBCXX_CONSTEXPR char -: 461: max() _GLIBCXX_USE_NOEXCEPT { return __glibcxx_max(char); } -: 462: -: 463:#if __cplusplus >= 201103L -: 464: static constexpr char -: 465: lowest() noexcept { return min(); } -: 466:#endif -: 467: -: 468: static _GLIBCXX_USE_CONSTEXPR int digits = __glibcxx_digits (char); -: 469: static _GLIBCXX_USE_CONSTEXPR int digits10 = __glibcxx_digits10 (char); -: 470:#if __cplusplus >= 201103L -: 471: static constexpr int max_digits10 = 0; -: 472:#endif -: 473: static _GLIBCXX_USE_CONSTEXPR bool is_signed = __glibcxx_signed (char); -: 474: static _GLIBCXX_USE_CONSTEXPR bool is_integer = true; -: 475: static _GLIBCXX_USE_CONSTEXPR bool is_exact = true; -: 476: static _GLIBCXX_USE_CONSTEXPR int radix = 2; -: 477: -: 478: static _GLIBCXX_CONSTEXPR char -: 479: epsilon() _GLIBCXX_USE_NOEXCEPT { return 0; } -: 480: -: 481: static _GLIBCXX_CONSTEXPR char -: 482: round_error() _GLIBCXX_USE_NOEXCEPT { return 0; } -: 483: -: 484: static _GLIBCXX_USE_CONSTEXPR int min_exponent = 0; -: 485: static _GLIBCXX_USE_CONSTEXPR int min_exponent10 = 0; -: 486: static _GLIBCXX_USE_CONSTEXPR int max_exponent = 0; -: 487: static _GLIBCXX_USE_CONSTEXPR int max_exponent10 = 0; -: 488: -: 489: static _GLIBCXX_USE_CONSTEXPR bool has_infinity = false; -: 490: static _GLIBCXX_USE_CONSTEXPR bool has_quiet_NaN = false; -: 491: static _GLIBCXX_USE_CONSTEXPR bool has_signaling_NaN = false; -: 492: static _GLIBCXX_USE_CONSTEXPR float_denorm_style has_denorm -: 493: = denorm_absent; -: 494: static _GLIBCXX_USE_CONSTEXPR bool has_denorm_loss = false; -: 495: -: 496: static _GLIBCXX_CONSTEXPR -: 497: char infinity() _GLIBCXX_USE_NOEXCEPT { return char(); } -: 498: -: 499: static _GLIBCXX_CONSTEXPR char -: 500: quiet_NaN() _GLIBCXX_USE_NOEXCEPT { return char(); } -: 501: -: 502: static _GLIBCXX_CONSTEXPR char -: 503: signaling_NaN() _GLIBCXX_USE_NOEXCEPT { return char(); } -: 504: -: 505: static _GLIBCXX_CONSTEXPR char -: 506: denorm_min() _GLIBCXX_USE_NOEXCEPT { return static_cast(0); } -: 507: -: 508: static _GLIBCXX_USE_CONSTEXPR bool is_iec559 = false; -: 509: static _GLIBCXX_USE_CONSTEXPR bool is_bounded = true; -: 510: static _GLIBCXX_USE_CONSTEXPR bool is_modulo = !is_signed; -: 511: -: 512: static _GLIBCXX_USE_CONSTEXPR bool traps = __glibcxx_integral_traps; -: 513: static _GLIBCXX_USE_CONSTEXPR bool tinyness_before = false; -: 514: static _GLIBCXX_USE_CONSTEXPR float_round_style round_style -: 515: = round_toward_zero; -: 516: }; -: 517: -: 518: /// numeric_limits specialization. -: 519: template<> -: 520: struct numeric_limits -: 521: { -: 522: static _GLIBCXX_USE_CONSTEXPR bool is_specialized = true; -: 523: -: 524: static _GLIBCXX_CONSTEXPR signed char -: 525: min() _GLIBCXX_USE_NOEXCEPT { return -__SCHAR_MAX__ - 1; } -: 526: -: 527: static _GLIBCXX_CONSTEXPR signed char -: 528: max() _GLIBCXX_USE_NOEXCEPT { return __SCHAR_MAX__; } -: 529: -: 530:#if __cplusplus >= 201103L -: 531: static constexpr signed char -: 532: lowest() noexcept { return min(); } -: 533:#endif -: 534: -: 535: static _GLIBCXX_USE_CONSTEXPR int digits = __glibcxx_digits (signed char); -: 536: static _GLIBCXX_USE_CONSTEXPR int digits10 -: 537: = __glibcxx_digits10 (signed char); -: 538:#if __cplusplus >= 201103L -: 539: static constexpr int max_digits10 = 0; -: 540:#endif -: 541: static _GLIBCXX_USE_CONSTEXPR bool is_signed = true; -: 542: static _GLIBCXX_USE_CONSTEXPR bool is_integer = true; -: 543: static _GLIBCXX_USE_CONSTEXPR bool is_exact = true; -: 544: static _GLIBCXX_USE_CONSTEXPR int radix = 2; -: 545: -: 546: static _GLIBCXX_CONSTEXPR signed char -: 547: epsilon() _GLIBCXX_USE_NOEXCEPT { return 0; } -: 548: -: 549: static _GLIBCXX_CONSTEXPR signed char -: 550: round_error() _GLIBCXX_USE_NOEXCEPT { return 0; } -: 551: -: 552: static _GLIBCXX_USE_CONSTEXPR int min_exponent = 0; -: 553: static _GLIBCXX_USE_CONSTEXPR int min_exponent10 = 0; -: 554: static _GLIBCXX_USE_CONSTEXPR int max_exponent = 0; -: 555: static _GLIBCXX_USE_CONSTEXPR int max_exponent10 = 0; -: 556: -: 557: static _GLIBCXX_USE_CONSTEXPR bool has_infinity = false; -: 558: static _GLIBCXX_USE_CONSTEXPR bool has_quiet_NaN = false; -: 559: static _GLIBCXX_USE_CONSTEXPR bool has_signaling_NaN = false; -: 560: static _GLIBCXX_USE_CONSTEXPR float_denorm_style has_denorm -: 561: = denorm_absent; -: 562: static _GLIBCXX_USE_CONSTEXPR bool has_denorm_loss = false; -: 563: -: 564: static _GLIBCXX_CONSTEXPR signed char -: 565: infinity() _GLIBCXX_USE_NOEXCEPT { return static_cast(0); } -: 566: -: 567: static _GLIBCXX_CONSTEXPR signed char -: 568: quiet_NaN() _GLIBCXX_USE_NOEXCEPT { return static_cast(0); } -: 569: -: 570: static _GLIBCXX_CONSTEXPR signed char -: 571: signaling_NaN() _GLIBCXX_USE_NOEXCEPT -: 572: { return static_cast(0); } -: 573: -: 574: static _GLIBCXX_CONSTEXPR signed char -: 575: denorm_min() _GLIBCXX_USE_NOEXCEPT -: 576: { return static_cast(0); } -: 577: -: 578: static _GLIBCXX_USE_CONSTEXPR bool is_iec559 = false; -: 579: static _GLIBCXX_USE_CONSTEXPR bool is_bounded = true; -: 580: static _GLIBCXX_USE_CONSTEXPR bool is_modulo = false; -: 581: -: 582: static _GLIBCXX_USE_CONSTEXPR bool traps = __glibcxx_integral_traps; -: 583: static _GLIBCXX_USE_CONSTEXPR bool tinyness_before = false; -: 584: static _GLIBCXX_USE_CONSTEXPR float_round_style round_style -: 585: = round_toward_zero; -: 586: }; -: 587: -: 588: /// numeric_limits specialization. -: 589: template<> -: 590: struct numeric_limits -: 591: { -: 592: static _GLIBCXX_USE_CONSTEXPR bool is_specialized = true; -: 593: -: 594: static _GLIBCXX_CONSTEXPR unsigned char -: 595: min() _GLIBCXX_USE_NOEXCEPT { return 0; } -: 596: -: 597: static _GLIBCXX_CONSTEXPR unsigned char -: 598: max() _GLIBCXX_USE_NOEXCEPT { return __SCHAR_MAX__ * 2U + 1; } -: 599: -: 600:#if __cplusplus >= 201103L -: 601: static constexpr unsigned char -: 602: lowest() noexcept { return min(); } -: 603:#endif -: 604: -: 605: static _GLIBCXX_USE_CONSTEXPR int digits -: 606: = __glibcxx_digits (unsigned char); -: 607: static _GLIBCXX_USE_CONSTEXPR int digits10 -: 608: = __glibcxx_digits10 (unsigned char); -: 609:#if __cplusplus >= 201103L -: 610: static constexpr int max_digits10 = 0; -: 611:#endif -: 612: static _GLIBCXX_USE_CONSTEXPR bool is_signed = false; -: 613: static _GLIBCXX_USE_CONSTEXPR bool is_integer = true; -: 614: static _GLIBCXX_USE_CONSTEXPR bool is_exact = true; -: 615: static _GLIBCXX_USE_CONSTEXPR int radix = 2; -: 616: -: 617: static _GLIBCXX_CONSTEXPR unsigned char -: 618: epsilon() _GLIBCXX_USE_NOEXCEPT { return 0; } -: 619: -: 620: static _GLIBCXX_CONSTEXPR unsigned char -: 621: round_error() _GLIBCXX_USE_NOEXCEPT { return 0; } -: 622: -: 623: static _GLIBCXX_USE_CONSTEXPR int min_exponent = 0; -: 624: static _GLIBCXX_USE_CONSTEXPR int min_exponent10 = 0; -: 625: static _GLIBCXX_USE_CONSTEXPR int max_exponent = 0; -: 626: static _GLIBCXX_USE_CONSTEXPR int max_exponent10 = 0; -: 627: -: 628: static _GLIBCXX_USE_CONSTEXPR bool has_infinity = false; -: 629: static _GLIBCXX_USE_CONSTEXPR bool has_quiet_NaN = false; -: 630: static _GLIBCXX_USE_CONSTEXPR bool has_signaling_NaN = false; -: 631: static _GLIBCXX_USE_CONSTEXPR float_denorm_style has_denorm -: 632: = denorm_absent; -: 633: static _GLIBCXX_USE_CONSTEXPR bool has_denorm_loss = false; -: 634: -: 635: static _GLIBCXX_CONSTEXPR unsigned char -: 636: infinity() _GLIBCXX_USE_NOEXCEPT -: 637: { return static_cast(0); } -: 638: -: 639: static _GLIBCXX_CONSTEXPR unsigned char -: 640: quiet_NaN() _GLIBCXX_USE_NOEXCEPT -: 641: { return static_cast(0); } -: 642: -: 643: static _GLIBCXX_CONSTEXPR unsigned char -: 644: signaling_NaN() _GLIBCXX_USE_NOEXCEPT -: 645: { return static_cast(0); } -: 646: -: 647: static _GLIBCXX_CONSTEXPR unsigned char -: 648: denorm_min() _GLIBCXX_USE_NOEXCEPT -: 649: { return static_cast(0); } -: 650: -: 651: static _GLIBCXX_USE_CONSTEXPR bool is_iec559 = false; -: 652: static _GLIBCXX_USE_CONSTEXPR bool is_bounded = true; -: 653: static _GLIBCXX_USE_CONSTEXPR bool is_modulo = true; -: 654: -: 655: static _GLIBCXX_USE_CONSTEXPR bool traps = __glibcxx_integral_traps; -: 656: static _GLIBCXX_USE_CONSTEXPR bool tinyness_before = false; -: 657: static _GLIBCXX_USE_CONSTEXPR float_round_style round_style -: 658: = round_toward_zero; -: 659: }; -: 660: -: 661: /// numeric_limits specialization. -: 662: template<> -: 663: struct numeric_limits -: 664: { -: 665: static _GLIBCXX_USE_CONSTEXPR bool is_specialized = true; -: 666: -: 667: static _GLIBCXX_CONSTEXPR wchar_t -: 668: min() _GLIBCXX_USE_NOEXCEPT { return __glibcxx_min (wchar_t); } -: 669: -: 670: static _GLIBCXX_CONSTEXPR wchar_t -: 671: max() _GLIBCXX_USE_NOEXCEPT { return __glibcxx_max (wchar_t); } -: 672: -: 673:#if __cplusplus >= 201103L -: 674: static constexpr wchar_t -: 675: lowest() noexcept { return min(); } -: 676:#endif -: 677: -: 678: static _GLIBCXX_USE_CONSTEXPR int digits = __glibcxx_digits (wchar_t); -: 679: static _GLIBCXX_USE_CONSTEXPR int digits10 -: 680: = __glibcxx_digits10 (wchar_t); -: 681:#if __cplusplus >= 201103L -: 682: static constexpr int max_digits10 = 0; -: 683:#endif -: 684: static _GLIBCXX_USE_CONSTEXPR bool is_signed = __glibcxx_signed (wchar_t); -: 685: static _GLIBCXX_USE_CONSTEXPR bool is_integer = true; -: 686: static _GLIBCXX_USE_CONSTEXPR bool is_exact = true; -: 687: static _GLIBCXX_USE_CONSTEXPR int radix = 2; -: 688: -: 689: static _GLIBCXX_CONSTEXPR wchar_t -: 690: epsilon() _GLIBCXX_USE_NOEXCEPT { return 0; } -: 691: -: 692: static _GLIBCXX_CONSTEXPR wchar_t -: 693: round_error() _GLIBCXX_USE_NOEXCEPT { return 0; } -: 694: -: 695: static _GLIBCXX_USE_CONSTEXPR int min_exponent = 0; -: 696: static _GLIBCXX_USE_CONSTEXPR int min_exponent10 = 0; -: 697: static _GLIBCXX_USE_CONSTEXPR int max_exponent = 0; -: 698: static _GLIBCXX_USE_CONSTEXPR int max_exponent10 = 0; -: 699: -: 700: static _GLIBCXX_USE_CONSTEXPR bool has_infinity = false; -: 701: static _GLIBCXX_USE_CONSTEXPR bool has_quiet_NaN = false; -: 702: static _GLIBCXX_USE_CONSTEXPR bool has_signaling_NaN = false; -: 703: static _GLIBCXX_USE_CONSTEXPR float_denorm_style has_denorm -: 704: = denorm_absent; -: 705: static _GLIBCXX_USE_CONSTEXPR bool has_denorm_loss = false; -: 706: -: 707: static _GLIBCXX_CONSTEXPR wchar_t -: 708: infinity() _GLIBCXX_USE_NOEXCEPT { return wchar_t(); } -: 709: -: 710: static _GLIBCXX_CONSTEXPR wchar_t -: 711: quiet_NaN() _GLIBCXX_USE_NOEXCEPT { return wchar_t(); } -: 712: -: 713: static _GLIBCXX_CONSTEXPR wchar_t -: 714: signaling_NaN() _GLIBCXX_USE_NOEXCEPT { return wchar_t(); } -: 715: -: 716: static _GLIBCXX_CONSTEXPR wchar_t -: 717: denorm_min() _GLIBCXX_USE_NOEXCEPT { return wchar_t(); } -: 718: -: 719: static _GLIBCXX_USE_CONSTEXPR bool is_iec559 = false; -: 720: static _GLIBCXX_USE_CONSTEXPR bool is_bounded = true; -: 721: static _GLIBCXX_USE_CONSTEXPR bool is_modulo = !is_signed; -: 722: -: 723: static _GLIBCXX_USE_CONSTEXPR bool traps = __glibcxx_integral_traps; -: 724: static _GLIBCXX_USE_CONSTEXPR bool tinyness_before = false; -: 725: static _GLIBCXX_USE_CONSTEXPR float_round_style round_style -: 726: = round_toward_zero; -: 727: }; -: 728: -: 729:#if _GLIBCXX_USE_CHAR8_T -: 730: /// numeric_limits specialization. -: 731: template<> -: 732: struct numeric_limits -: 733: { -: 734: static _GLIBCXX_USE_CONSTEXPR bool is_specialized = true; -: 735: -: 736: static _GLIBCXX_CONSTEXPR char8_t -: 737: min() _GLIBCXX_USE_NOEXCEPT { return __glibcxx_min (char8_t); } -: 738: -: 739: static _GLIBCXX_CONSTEXPR char8_t -: 740: max() _GLIBCXX_USE_NOEXCEPT { return __glibcxx_max (char8_t); } -: 741: -: 742: static _GLIBCXX_CONSTEXPR char8_t -: 743: lowest() _GLIBCXX_USE_NOEXCEPT { return min(); } -: 744: -: 745: static _GLIBCXX_USE_CONSTEXPR int digits = __glibcxx_digits (char8_t); -: 746: static _GLIBCXX_USE_CONSTEXPR int digits10 = __glibcxx_digits10 (char8_t); -: 747: static _GLIBCXX_USE_CONSTEXPR int max_digits10 = 0; -: 748: static _GLIBCXX_USE_CONSTEXPR bool is_signed = __glibcxx_signed (char8_t); -: 749: static _GLIBCXX_USE_CONSTEXPR bool is_integer = true; -: 750: static _GLIBCXX_USE_CONSTEXPR bool is_exact = true; -: 751: static _GLIBCXX_USE_CONSTEXPR int radix = 2; -: 752: -: 753: static _GLIBCXX_CONSTEXPR char8_t -: 754: epsilon() _GLIBCXX_USE_NOEXCEPT { return 0; } -: 755: -: 756: static _GLIBCXX_CONSTEXPR char8_t -: 757: round_error() _GLIBCXX_USE_NOEXCEPT { return 0; } -: 758: -: 759: static _GLIBCXX_USE_CONSTEXPR int min_exponent = 0; -: 760: static _GLIBCXX_USE_CONSTEXPR int min_exponent10 = 0; -: 761: static _GLIBCXX_USE_CONSTEXPR int max_exponent = 0; -: 762: static _GLIBCXX_USE_CONSTEXPR int max_exponent10 = 0; -: 763: -: 764: static _GLIBCXX_USE_CONSTEXPR bool has_infinity = false; -: 765: static _GLIBCXX_USE_CONSTEXPR bool has_quiet_NaN = false; -: 766: static _GLIBCXX_USE_CONSTEXPR bool has_signaling_NaN = false; -: 767: static _GLIBCXX_USE_CONSTEXPR float_denorm_style has_denorm -: 768: = denorm_absent; -: 769: static _GLIBCXX_USE_CONSTEXPR bool has_denorm_loss = false; -: 770: -: 771: static _GLIBCXX_CONSTEXPR char8_t -: 772: infinity() _GLIBCXX_USE_NOEXCEPT { return char8_t(); } -: 773: -: 774: static _GLIBCXX_CONSTEXPR char8_t -: 775: quiet_NaN() _GLIBCXX_USE_NOEXCEPT { return char8_t(); } -: 776: -: 777: static _GLIBCXX_CONSTEXPR char8_t -: 778: signaling_NaN() _GLIBCXX_USE_NOEXCEPT { return char8_t(); } -: 779: -: 780: static _GLIBCXX_CONSTEXPR char8_t -: 781: denorm_min() _GLIBCXX_USE_NOEXCEPT { return char8_t(); } -: 782: -: 783: static _GLIBCXX_USE_CONSTEXPR bool is_iec559 = false; -: 784: static _GLIBCXX_USE_CONSTEXPR bool is_bounded = true; -: 785: static _GLIBCXX_USE_CONSTEXPR bool is_modulo = !is_signed; -: 786: -: 787: static _GLIBCXX_USE_CONSTEXPR bool traps = __glibcxx_integral_traps; -: 788: static _GLIBCXX_USE_CONSTEXPR bool tinyness_before = false; -: 789: static _GLIBCXX_USE_CONSTEXPR float_round_style round_style -: 790: = round_toward_zero; -: 791: }; -: 792:#endif -: 793: -: 794:#if __cplusplus >= 201103L -: 795: /// numeric_limits specialization. -: 796: template<> -: 797: struct numeric_limits -: 798: { -: 799: static constexpr bool is_specialized = true; -: 800: -: 801: static constexpr char16_t -: 802: min() noexcept { return __glibcxx_min (char16_t); } -: 803: -: 804: static constexpr char16_t -: 805: max() noexcept { return __glibcxx_max (char16_t); } -: 806: -: 807: static constexpr char16_t -: 808: lowest() noexcept { return min(); } -: 809: -: 810: static constexpr int digits = __glibcxx_digits (char16_t); -: 811: static constexpr int digits10 = __glibcxx_digits10 (char16_t); -: 812: static constexpr int max_digits10 = 0; -: 813: static constexpr bool is_signed = __glibcxx_signed (char16_t); -: 814: static constexpr bool is_integer = true; -: 815: static constexpr bool is_exact = true; -: 816: static constexpr int radix = 2; -: 817: -: 818: static constexpr char16_t -: 819: epsilon() noexcept { return 0; } -: 820: -: 821: static constexpr char16_t -: 822: round_error() noexcept { return 0; } -: 823: -: 824: static constexpr int min_exponent = 0; -: 825: static constexpr int min_exponent10 = 0; -: 826: static constexpr int max_exponent = 0; -: 827: static constexpr int max_exponent10 = 0; -: 828: -: 829: static constexpr bool has_infinity = false; -: 830: static constexpr bool has_quiet_NaN = false; -: 831: static constexpr bool has_signaling_NaN = false; -: 832: static constexpr float_denorm_style has_denorm = denorm_absent; -: 833: static constexpr bool has_denorm_loss = false; -: 834: -: 835: static constexpr char16_t -: 836: infinity() noexcept { return char16_t(); } -: 837: -: 838: static constexpr char16_t -: 839: quiet_NaN() noexcept { return char16_t(); } -: 840: -: 841: static constexpr char16_t -: 842: signaling_NaN() noexcept { return char16_t(); } -: 843: -: 844: static constexpr char16_t -: 845: denorm_min() noexcept { return char16_t(); } -: 846: -: 847: static constexpr bool is_iec559 = false; -: 848: static constexpr bool is_bounded = true; -: 849: static constexpr bool is_modulo = !is_signed; -: 850: -: 851: static constexpr bool traps = __glibcxx_integral_traps; -: 852: static constexpr bool tinyness_before = false; -: 853: static constexpr float_round_style round_style = round_toward_zero; -: 854: }; -: 855: -: 856: /// numeric_limits specialization. -: 857: template<> -: 858: struct numeric_limits -: 859: { -: 860: static constexpr bool is_specialized = true; -: 861: -: 862: static constexpr char32_t -: 863: min() noexcept { return __glibcxx_min (char32_t); } -: 864: -: 865: static constexpr char32_t -: 866: max() noexcept { return __glibcxx_max (char32_t); } -: 867: -: 868: static constexpr char32_t -: 869: lowest() noexcept { return min(); } -: 870: -: 871: static constexpr int digits = __glibcxx_digits (char32_t); -: 872: static constexpr int digits10 = __glibcxx_digits10 (char32_t); -: 873: static constexpr int max_digits10 = 0; -: 874: static constexpr bool is_signed = __glibcxx_signed (char32_t); -: 875: static constexpr bool is_integer = true; -: 876: static constexpr bool is_exact = true; -: 877: static constexpr int radix = 2; -: 878: -: 879: static constexpr char32_t -: 880: epsilon() noexcept { return 0; } -: 881: -: 882: static constexpr char32_t -: 883: round_error() noexcept { return 0; } -: 884: -: 885: static constexpr int min_exponent = 0; -: 886: static constexpr int min_exponent10 = 0; -: 887: static constexpr int max_exponent = 0; -: 888: static constexpr int max_exponent10 = 0; -: 889: -: 890: static constexpr bool has_infinity = false; -: 891: static constexpr bool has_quiet_NaN = false; -: 892: static constexpr bool has_signaling_NaN = false; -: 893: static constexpr float_denorm_style has_denorm = denorm_absent; -: 894: static constexpr bool has_denorm_loss = false; -: 895: -: 896: static constexpr char32_t -: 897: infinity() noexcept { return char32_t(); } -: 898: -: 899: static constexpr char32_t -: 900: quiet_NaN() noexcept { return char32_t(); } -: 901: -: 902: static constexpr char32_t -: 903: signaling_NaN() noexcept { return char32_t(); } -: 904: -: 905: static constexpr char32_t -: 906: denorm_min() noexcept { return char32_t(); } -: 907: -: 908: static constexpr bool is_iec559 = false; -: 909: static constexpr bool is_bounded = true; -: 910: static constexpr bool is_modulo = !is_signed; -: 911: -: 912: static constexpr bool traps = __glibcxx_integral_traps; -: 913: static constexpr bool tinyness_before = false; -: 914: static constexpr float_round_style round_style = round_toward_zero; -: 915: }; -: 916:#endif -: 917: -: 918: /// numeric_limits specialization. -: 919: template<> -: 920: struct numeric_limits -: 921: { -: 922: static _GLIBCXX_USE_CONSTEXPR bool is_specialized = true; -: 923: -: 924: static _GLIBCXX_CONSTEXPR short -: 925: min() _GLIBCXX_USE_NOEXCEPT { return -__SHRT_MAX__ - 1; } -: 926: -: 927: static _GLIBCXX_CONSTEXPR short -: 928: max() _GLIBCXX_USE_NOEXCEPT { return __SHRT_MAX__; } -: 929: -: 930:#if __cplusplus >= 201103L -: 931: static constexpr short -: 932: lowest() noexcept { return min(); } -: 933:#endif -: 934: -: 935: static _GLIBCXX_USE_CONSTEXPR int digits = __glibcxx_digits (short); -: 936: static _GLIBCXX_USE_CONSTEXPR int digits10 = __glibcxx_digits10 (short); -: 937:#if __cplusplus >= 201103L -: 938: static constexpr int max_digits10 = 0; -: 939:#endif -: 940: static _GLIBCXX_USE_CONSTEXPR bool is_signed = true; -: 941: static _GLIBCXX_USE_CONSTEXPR bool is_integer = true; -: 942: static _GLIBCXX_USE_CONSTEXPR bool is_exact = true; -: 943: static _GLIBCXX_USE_CONSTEXPR int radix = 2; -: 944: -: 945: static _GLIBCXX_CONSTEXPR short -: 946: epsilon() _GLIBCXX_USE_NOEXCEPT { return 0; } -: 947: -: 948: static _GLIBCXX_CONSTEXPR short -: 949: round_error() _GLIBCXX_USE_NOEXCEPT { return 0; } -: 950: -: 951: static _GLIBCXX_USE_CONSTEXPR int min_exponent = 0; -: 952: static _GLIBCXX_USE_CONSTEXPR int min_exponent10 = 0; -: 953: static _GLIBCXX_USE_CONSTEXPR int max_exponent = 0; -: 954: static _GLIBCXX_USE_CONSTEXPR int max_exponent10 = 0; -: 955: -: 956: static _GLIBCXX_USE_CONSTEXPR bool has_infinity = false; -: 957: static _GLIBCXX_USE_CONSTEXPR bool has_quiet_NaN = false; -: 958: static _GLIBCXX_USE_CONSTEXPR bool has_signaling_NaN = false; -: 959: static _GLIBCXX_USE_CONSTEXPR float_denorm_style has_denorm -: 960: = denorm_absent; -: 961: static _GLIBCXX_USE_CONSTEXPR bool has_denorm_loss = false; -: 962: -: 963: static _GLIBCXX_CONSTEXPR short -: 964: infinity() _GLIBCXX_USE_NOEXCEPT { return short(); } -: 965: -: 966: static _GLIBCXX_CONSTEXPR short -: 967: quiet_NaN() _GLIBCXX_USE_NOEXCEPT { return short(); } -: 968: -: 969: static _GLIBCXX_CONSTEXPR short -: 970: signaling_NaN() _GLIBCXX_USE_NOEXCEPT { return short(); } -: 971: -: 972: static _GLIBCXX_CONSTEXPR short -: 973: denorm_min() _GLIBCXX_USE_NOEXCEPT { return short(); } -: 974: -: 975: static _GLIBCXX_USE_CONSTEXPR bool is_iec559 = false; -: 976: static _GLIBCXX_USE_CONSTEXPR bool is_bounded = true; -: 977: static _GLIBCXX_USE_CONSTEXPR bool is_modulo = false; -: 978: -: 979: static _GLIBCXX_USE_CONSTEXPR bool traps = __glibcxx_integral_traps; -: 980: static _GLIBCXX_USE_CONSTEXPR bool tinyness_before = false; -: 981: static _GLIBCXX_USE_CONSTEXPR float_round_style round_style -: 982: = round_toward_zero; -: 983: }; -: 984: -: 985: /// numeric_limits specialization. -: 986: template<> -: 987: struct numeric_limits -: 988: { -: 989: static _GLIBCXX_USE_CONSTEXPR bool is_specialized = true; -: 990: -: 991: static _GLIBCXX_CONSTEXPR unsigned short -: 992: min() _GLIBCXX_USE_NOEXCEPT { return 0; } -: 993: -: 994: static _GLIBCXX_CONSTEXPR unsigned short -: 995: max() _GLIBCXX_USE_NOEXCEPT { return __SHRT_MAX__ * 2U + 1; } -: 996: -: 997:#if __cplusplus >= 201103L -: 998: static constexpr unsigned short -: 999: lowest() noexcept { return min(); } -: 1000:#endif -: 1001: -: 1002: static _GLIBCXX_USE_CONSTEXPR int digits -: 1003: = __glibcxx_digits (unsigned short); -: 1004: static _GLIBCXX_USE_CONSTEXPR int digits10 -: 1005: = __glibcxx_digits10 (unsigned short); -: 1006:#if __cplusplus >= 201103L -: 1007: static constexpr int max_digits10 = 0; -: 1008:#endif -: 1009: static _GLIBCXX_USE_CONSTEXPR bool is_signed = false; -: 1010: static _GLIBCXX_USE_CONSTEXPR bool is_integer = true; -: 1011: static _GLIBCXX_USE_CONSTEXPR bool is_exact = true; -: 1012: static _GLIBCXX_USE_CONSTEXPR int radix = 2; -: 1013: -: 1014: static _GLIBCXX_CONSTEXPR unsigned short -: 1015: epsilon() _GLIBCXX_USE_NOEXCEPT { return 0; } -: 1016: -: 1017: static _GLIBCXX_CONSTEXPR unsigned short -: 1018: round_error() _GLIBCXX_USE_NOEXCEPT { return 0; } -: 1019: -: 1020: static _GLIBCXX_USE_CONSTEXPR int min_exponent = 0; -: 1021: static _GLIBCXX_USE_CONSTEXPR int min_exponent10 = 0; -: 1022: static _GLIBCXX_USE_CONSTEXPR int max_exponent = 0; -: 1023: static _GLIBCXX_USE_CONSTEXPR int max_exponent10 = 0; -: 1024: -: 1025: static _GLIBCXX_USE_CONSTEXPR bool has_infinity = false; -: 1026: static _GLIBCXX_USE_CONSTEXPR bool has_quiet_NaN = false; -: 1027: static _GLIBCXX_USE_CONSTEXPR bool has_signaling_NaN = false; -: 1028: static _GLIBCXX_USE_CONSTEXPR float_denorm_style has_denorm -: 1029: = denorm_absent; -: 1030: static _GLIBCXX_USE_CONSTEXPR bool has_denorm_loss = false; -: 1031: -: 1032: static _GLIBCXX_CONSTEXPR unsigned short -: 1033: infinity() _GLIBCXX_USE_NOEXCEPT -: 1034: { return static_cast(0); } -: 1035: -: 1036: static _GLIBCXX_CONSTEXPR unsigned short -: 1037: quiet_NaN() _GLIBCXX_USE_NOEXCEPT -: 1038: { return static_cast(0); } -: 1039: -: 1040: static _GLIBCXX_CONSTEXPR unsigned short -: 1041: signaling_NaN() _GLIBCXX_USE_NOEXCEPT -: 1042: { return static_cast(0); } -: 1043: -: 1044: static _GLIBCXX_CONSTEXPR unsigned short -: 1045: denorm_min() _GLIBCXX_USE_NOEXCEPT -: 1046: { return static_cast(0); } -: 1047: -: 1048: static _GLIBCXX_USE_CONSTEXPR bool is_iec559 = false; -: 1049: static _GLIBCXX_USE_CONSTEXPR bool is_bounded = true; -: 1050: static _GLIBCXX_USE_CONSTEXPR bool is_modulo = true; -: 1051: -: 1052: static _GLIBCXX_USE_CONSTEXPR bool traps = __glibcxx_integral_traps; -: 1053: static _GLIBCXX_USE_CONSTEXPR bool tinyness_before = false; -: 1054: static _GLIBCXX_USE_CONSTEXPR float_round_style round_style -: 1055: = round_toward_zero; -: 1056: }; -: 1057: -: 1058: /// numeric_limits specialization. -: 1059: template<> -: 1060: struct numeric_limits -: 1061: { -: 1062: static _GLIBCXX_USE_CONSTEXPR bool is_specialized = true; -: 1063: -: 1064: static _GLIBCXX_CONSTEXPR int -: 1065: min() _GLIBCXX_USE_NOEXCEPT { return -__INT_MAX__ - 1; } -: 1066: -: 1067: static _GLIBCXX_CONSTEXPR int -: 1068: max() _GLIBCXX_USE_NOEXCEPT { return __INT_MAX__; } -: 1069: -: 1070:#if __cplusplus >= 201103L -: 1071: static constexpr int -: 1072: lowest() noexcept { return min(); } -: 1073:#endif -: 1074: -: 1075: static _GLIBCXX_USE_CONSTEXPR int digits = __glibcxx_digits (int); -: 1076: static _GLIBCXX_USE_CONSTEXPR int digits10 = __glibcxx_digits10 (int); -: 1077:#if __cplusplus >= 201103L -: 1078: static constexpr int max_digits10 = 0; -: 1079:#endif -: 1080: static _GLIBCXX_USE_CONSTEXPR bool is_signed = true; -: 1081: static _GLIBCXX_USE_CONSTEXPR bool is_integer = true; -: 1082: static _GLIBCXX_USE_CONSTEXPR bool is_exact = true; -: 1083: static _GLIBCXX_USE_CONSTEXPR int radix = 2; -: 1084: -: 1085: static _GLIBCXX_CONSTEXPR int -: 1086: epsilon() _GLIBCXX_USE_NOEXCEPT { return 0; } -: 1087: -: 1088: static _GLIBCXX_CONSTEXPR int -: 1089: round_error() _GLIBCXX_USE_NOEXCEPT { return 0; } -: 1090: -: 1091: static _GLIBCXX_USE_CONSTEXPR int min_exponent = 0; -: 1092: static _GLIBCXX_USE_CONSTEXPR int min_exponent10 = 0; -: 1093: static _GLIBCXX_USE_CONSTEXPR int max_exponent = 0; -: 1094: static _GLIBCXX_USE_CONSTEXPR int max_exponent10 = 0; -: 1095: -: 1096: static _GLIBCXX_USE_CONSTEXPR bool has_infinity = false; -: 1097: static _GLIBCXX_USE_CONSTEXPR bool has_quiet_NaN = false; -: 1098: static _GLIBCXX_USE_CONSTEXPR bool has_signaling_NaN = false; -: 1099: static _GLIBCXX_USE_CONSTEXPR float_denorm_style has_denorm -: 1100: = denorm_absent; -: 1101: static _GLIBCXX_USE_CONSTEXPR bool has_denorm_loss = false; -: 1102: -: 1103: static _GLIBCXX_CONSTEXPR int -: 1104: infinity() _GLIBCXX_USE_NOEXCEPT { return static_cast(0); } -: 1105: -: 1106: static _GLIBCXX_CONSTEXPR int -: 1107: quiet_NaN() _GLIBCXX_USE_NOEXCEPT { return static_cast(0); } -: 1108: -: 1109: static _GLIBCXX_CONSTEXPR int -: 1110: signaling_NaN() _GLIBCXX_USE_NOEXCEPT { return static_cast(0); } -: 1111: -: 1112: static _GLIBCXX_CONSTEXPR int -: 1113: denorm_min() _GLIBCXX_USE_NOEXCEPT { return static_cast(0); } -: 1114: -: 1115: static _GLIBCXX_USE_CONSTEXPR bool is_iec559 = false; -: 1116: static _GLIBCXX_USE_CONSTEXPR bool is_bounded = true; -: 1117: static _GLIBCXX_USE_CONSTEXPR bool is_modulo = false; -: 1118: -: 1119: static _GLIBCXX_USE_CONSTEXPR bool traps = __glibcxx_integral_traps; -: 1120: static _GLIBCXX_USE_CONSTEXPR bool tinyness_before = false; -: 1121: static _GLIBCXX_USE_CONSTEXPR float_round_style round_style -: 1122: = round_toward_zero; -: 1123: }; -: 1124: -: 1125: /// numeric_limits specialization. -: 1126: template<> -: 1127: struct numeric_limits -: 1128: { -: 1129: static _GLIBCXX_USE_CONSTEXPR bool is_specialized = true; -: 1130: -: 1131: static _GLIBCXX_CONSTEXPR unsigned int -: 1132: min() _GLIBCXX_USE_NOEXCEPT { return 0; } -: 1133: -: 1134: static _GLIBCXX_CONSTEXPR unsigned int -: 1135: max() _GLIBCXX_USE_NOEXCEPT { return __INT_MAX__ * 2U + 1; } -: 1136: -: 1137:#if __cplusplus >= 201103L -: 1138: static constexpr unsigned int -: 1139: lowest() noexcept { return min(); } -: 1140:#endif -: 1141: -: 1142: static _GLIBCXX_USE_CONSTEXPR int digits -: 1143: = __glibcxx_digits (unsigned int); -: 1144: static _GLIBCXX_USE_CONSTEXPR int digits10 -: 1145: = __glibcxx_digits10 (unsigned int); -: 1146:#if __cplusplus >= 201103L -: 1147: static constexpr int max_digits10 = 0; -: 1148:#endif -: 1149: static _GLIBCXX_USE_CONSTEXPR bool is_signed = false; -: 1150: static _GLIBCXX_USE_CONSTEXPR bool is_integer = true; -: 1151: static _GLIBCXX_USE_CONSTEXPR bool is_exact = true; -: 1152: static _GLIBCXX_USE_CONSTEXPR int radix = 2; -: 1153: -: 1154: static _GLIBCXX_CONSTEXPR unsigned int -: 1155: epsilon() _GLIBCXX_USE_NOEXCEPT { return 0; } -: 1156: -: 1157: static _GLIBCXX_CONSTEXPR unsigned int -: 1158: round_error() _GLIBCXX_USE_NOEXCEPT { return 0; } -: 1159: -: 1160: static _GLIBCXX_USE_CONSTEXPR int min_exponent = 0; -: 1161: static _GLIBCXX_USE_CONSTEXPR int min_exponent10 = 0; -: 1162: static _GLIBCXX_USE_CONSTEXPR int max_exponent = 0; -: 1163: static _GLIBCXX_USE_CONSTEXPR int max_exponent10 = 0; -: 1164: -: 1165: static _GLIBCXX_USE_CONSTEXPR bool has_infinity = false; -: 1166: static _GLIBCXX_USE_CONSTEXPR bool has_quiet_NaN = false; -: 1167: static _GLIBCXX_USE_CONSTEXPR bool has_signaling_NaN = false; -: 1168: static _GLIBCXX_USE_CONSTEXPR float_denorm_style has_denorm -: 1169: = denorm_absent; -: 1170: static _GLIBCXX_USE_CONSTEXPR bool has_denorm_loss = false; -: 1171: -: 1172: static _GLIBCXX_CONSTEXPR unsigned int -: 1173: infinity() _GLIBCXX_USE_NOEXCEPT { return static_cast(0); } -: 1174: -: 1175: static _GLIBCXX_CONSTEXPR unsigned int -: 1176: quiet_NaN() _GLIBCXX_USE_NOEXCEPT -: 1177: { return static_cast(0); } -: 1178: -: 1179: static _GLIBCXX_CONSTEXPR unsigned int -: 1180: signaling_NaN() _GLIBCXX_USE_NOEXCEPT -: 1181: { return static_cast(0); } -: 1182: -: 1183: static _GLIBCXX_CONSTEXPR unsigned int -: 1184: denorm_min() _GLIBCXX_USE_NOEXCEPT -: 1185: { return static_cast(0); } -: 1186: -: 1187: static _GLIBCXX_USE_CONSTEXPR bool is_iec559 = false; -: 1188: static _GLIBCXX_USE_CONSTEXPR bool is_bounded = true; -: 1189: static _GLIBCXX_USE_CONSTEXPR bool is_modulo = true; -: 1190: -: 1191: static _GLIBCXX_USE_CONSTEXPR bool traps = __glibcxx_integral_traps; -: 1192: static _GLIBCXX_USE_CONSTEXPR bool tinyness_before = false; -: 1193: static _GLIBCXX_USE_CONSTEXPR float_round_style round_style -: 1194: = round_toward_zero; -: 1195: }; -: 1196: -: 1197: /// numeric_limits specialization. -: 1198: template<> -: 1199: struct numeric_limits -: 1200: { -: 1201: static _GLIBCXX_USE_CONSTEXPR bool is_specialized = true; -: 1202: -: 1203: static _GLIBCXX_CONSTEXPR long -: 1204: min() _GLIBCXX_USE_NOEXCEPT { return -__LONG_MAX__ - 1; } -: 1205: -: 1206: static _GLIBCXX_CONSTEXPR long -: 1207: max() _GLIBCXX_USE_NOEXCEPT { return __LONG_MAX__; } -: 1208: -: 1209:#if __cplusplus >= 201103L -: 1210: static constexpr long -: 1211: lowest() noexcept { return min(); } -: 1212:#endif -: 1213: -: 1214: static _GLIBCXX_USE_CONSTEXPR int digits = __glibcxx_digits (long); -: 1215: static _GLIBCXX_USE_CONSTEXPR int digits10 = __glibcxx_digits10 (long); -: 1216:#if __cplusplus >= 201103L -: 1217: static constexpr int max_digits10 = 0; -: 1218:#endif -: 1219: static _GLIBCXX_USE_CONSTEXPR bool is_signed = true; -: 1220: static _GLIBCXX_USE_CONSTEXPR bool is_integer = true; -: 1221: static _GLIBCXX_USE_CONSTEXPR bool is_exact = true; -: 1222: static _GLIBCXX_USE_CONSTEXPR int radix = 2; -: 1223: -: 1224: static _GLIBCXX_CONSTEXPR long -: 1225: epsilon() _GLIBCXX_USE_NOEXCEPT { return 0; } -: 1226: -: 1227: static _GLIBCXX_CONSTEXPR long -: 1228: round_error() _GLIBCXX_USE_NOEXCEPT { return 0; } -: 1229: -: 1230: static _GLIBCXX_USE_CONSTEXPR int min_exponent = 0; -: 1231: static _GLIBCXX_USE_CONSTEXPR int min_exponent10 = 0; -: 1232: static _GLIBCXX_USE_CONSTEXPR int max_exponent = 0; -: 1233: static _GLIBCXX_USE_CONSTEXPR int max_exponent10 = 0; -: 1234: -: 1235: static _GLIBCXX_USE_CONSTEXPR bool has_infinity = false; -: 1236: static _GLIBCXX_USE_CONSTEXPR bool has_quiet_NaN = false; -: 1237: static _GLIBCXX_USE_CONSTEXPR bool has_signaling_NaN = false; -: 1238: static _GLIBCXX_USE_CONSTEXPR float_denorm_style has_denorm -: 1239: = denorm_absent; -: 1240: static _GLIBCXX_USE_CONSTEXPR bool has_denorm_loss = false; -: 1241: -: 1242: static _GLIBCXX_CONSTEXPR long -: 1243: infinity() _GLIBCXX_USE_NOEXCEPT { return static_cast(0); } -: 1244: -: 1245: static _GLIBCXX_CONSTEXPR long -: 1246: quiet_NaN() _GLIBCXX_USE_NOEXCEPT { return static_cast(0); } -: 1247: -: 1248: static _GLIBCXX_CONSTEXPR long -: 1249: signaling_NaN() _GLIBCXX_USE_NOEXCEPT { return static_cast(0); } -: 1250: -: 1251: static _GLIBCXX_CONSTEXPR long -: 1252: denorm_min() _GLIBCXX_USE_NOEXCEPT { return static_cast(0); } -: 1253: -: 1254: static _GLIBCXX_USE_CONSTEXPR bool is_iec559 = false; -: 1255: static _GLIBCXX_USE_CONSTEXPR bool is_bounded = true; -: 1256: static _GLIBCXX_USE_CONSTEXPR bool is_modulo = false; -: 1257: -: 1258: static _GLIBCXX_USE_CONSTEXPR bool traps = __glibcxx_integral_traps; -: 1259: static _GLIBCXX_USE_CONSTEXPR bool tinyness_before = false; -: 1260: static _GLIBCXX_USE_CONSTEXPR float_round_style round_style -: 1261: = round_toward_zero; -: 1262: }; -: 1263: -: 1264: /// numeric_limits specialization. -: 1265: template<> -: 1266: struct numeric_limits -: 1267: { -: 1268: static _GLIBCXX_USE_CONSTEXPR bool is_specialized = true; -: 1269: -: 1270: static _GLIBCXX_CONSTEXPR unsigned long -: 1271: min() _GLIBCXX_USE_NOEXCEPT { return 0; } -: 1272: -: 1273: static _GLIBCXX_CONSTEXPR unsigned long -: 1274: max() _GLIBCXX_USE_NOEXCEPT { return __LONG_MAX__ * 2UL + 1; } -: 1275: -: 1276:#if __cplusplus >= 201103L -: 1277: static constexpr unsigned long -: 1278: lowest() noexcept { return min(); } -: 1279:#endif -: 1280: -: 1281: static _GLIBCXX_USE_CONSTEXPR int digits -: 1282: = __glibcxx_digits (unsigned long); -: 1283: static _GLIBCXX_USE_CONSTEXPR int digits10 -: 1284: = __glibcxx_digits10 (unsigned long); -: 1285:#if __cplusplus >= 201103L -: 1286: static constexpr int max_digits10 = 0; -: 1287:#endif -: 1288: static _GLIBCXX_USE_CONSTEXPR bool is_signed = false; -: 1289: static _GLIBCXX_USE_CONSTEXPR bool is_integer = true; -: 1290: static _GLIBCXX_USE_CONSTEXPR bool is_exact = true; -: 1291: static _GLIBCXX_USE_CONSTEXPR int radix = 2; -: 1292: -: 1293: static _GLIBCXX_CONSTEXPR unsigned long -: 1294: epsilon() _GLIBCXX_USE_NOEXCEPT { return 0; } -: 1295: -: 1296: static _GLIBCXX_CONSTEXPR unsigned long -: 1297: round_error() _GLIBCXX_USE_NOEXCEPT { return 0; } -: 1298: -: 1299: static _GLIBCXX_USE_CONSTEXPR int min_exponent = 0; -: 1300: static _GLIBCXX_USE_CONSTEXPR int min_exponent10 = 0; -: 1301: static _GLIBCXX_USE_CONSTEXPR int max_exponent = 0; -: 1302: static _GLIBCXX_USE_CONSTEXPR int max_exponent10 = 0; -: 1303: -: 1304: static _GLIBCXX_USE_CONSTEXPR bool has_infinity = false; -: 1305: static _GLIBCXX_USE_CONSTEXPR bool has_quiet_NaN = false; -: 1306: static _GLIBCXX_USE_CONSTEXPR bool has_signaling_NaN = false; -: 1307: static _GLIBCXX_USE_CONSTEXPR float_denorm_style has_denorm -: 1308: = denorm_absent; -: 1309: static _GLIBCXX_USE_CONSTEXPR bool has_denorm_loss = false; -: 1310: -: 1311: static _GLIBCXX_CONSTEXPR unsigned long -: 1312: infinity() _GLIBCXX_USE_NOEXCEPT -: 1313: { return static_cast(0); } -: 1314: -: 1315: static _GLIBCXX_CONSTEXPR unsigned long -: 1316: quiet_NaN() _GLIBCXX_USE_NOEXCEPT -: 1317: { return static_cast(0); } -: 1318: -: 1319: static _GLIBCXX_CONSTEXPR unsigned long -: 1320: signaling_NaN() _GLIBCXX_USE_NOEXCEPT -: 1321: { return static_cast(0); } -: 1322: -: 1323: static _GLIBCXX_CONSTEXPR unsigned long -: 1324: denorm_min() _GLIBCXX_USE_NOEXCEPT -: 1325: { return static_cast(0); } -: 1326: -: 1327: static _GLIBCXX_USE_CONSTEXPR bool is_iec559 = false; -: 1328: static _GLIBCXX_USE_CONSTEXPR bool is_bounded = true; -: 1329: static _GLIBCXX_USE_CONSTEXPR bool is_modulo = true; -: 1330: -: 1331: static _GLIBCXX_USE_CONSTEXPR bool traps = __glibcxx_integral_traps; -: 1332: static _GLIBCXX_USE_CONSTEXPR bool tinyness_before = false; -: 1333: static _GLIBCXX_USE_CONSTEXPR float_round_style round_style -: 1334: = round_toward_zero; -: 1335: }; -: 1336: -: 1337: /// numeric_limits specialization. -: 1338: template<> -: 1339: struct numeric_limits -: 1340: { -: 1341: static _GLIBCXX_USE_CONSTEXPR bool is_specialized = true; -: 1342: -: 1343: static _GLIBCXX_CONSTEXPR long long -: 1344: min() _GLIBCXX_USE_NOEXCEPT { return -__LONG_LONG_MAX__ - 1; } -: 1345: -: 1346: static _GLIBCXX_CONSTEXPR long long -: 1347: max() _GLIBCXX_USE_NOEXCEPT { return __LONG_LONG_MAX__; } -: 1348: -: 1349:#if __cplusplus >= 201103L -: 1350: static constexpr long long -: 1351: lowest() noexcept { return min(); } -: 1352:#endif -: 1353: -: 1354: static _GLIBCXX_USE_CONSTEXPR int digits -: 1355: = __glibcxx_digits (long long); -: 1356: static _GLIBCXX_USE_CONSTEXPR int digits10 -: 1357: = __glibcxx_digits10 (long long); -: 1358:#if __cplusplus >= 201103L -: 1359: static constexpr int max_digits10 = 0; -: 1360:#endif -: 1361: static _GLIBCXX_USE_CONSTEXPR bool is_signed = true; -: 1362: static _GLIBCXX_USE_CONSTEXPR bool is_integer = true; -: 1363: static _GLIBCXX_USE_CONSTEXPR bool is_exact = true; -: 1364: static _GLIBCXX_USE_CONSTEXPR int radix = 2; -: 1365: -: 1366: static _GLIBCXX_CONSTEXPR long long -: 1367: epsilon() _GLIBCXX_USE_NOEXCEPT { return 0; } -: 1368: -: 1369: static _GLIBCXX_CONSTEXPR long long -: 1370: round_error() _GLIBCXX_USE_NOEXCEPT { return 0; } -: 1371: -: 1372: static _GLIBCXX_USE_CONSTEXPR int min_exponent = 0; -: 1373: static _GLIBCXX_USE_CONSTEXPR int min_exponent10 = 0; -: 1374: static _GLIBCXX_USE_CONSTEXPR int max_exponent = 0; -: 1375: static _GLIBCXX_USE_CONSTEXPR int max_exponent10 = 0; -: 1376: -: 1377: static _GLIBCXX_USE_CONSTEXPR bool has_infinity = false; -: 1378: static _GLIBCXX_USE_CONSTEXPR bool has_quiet_NaN = false; -: 1379: static _GLIBCXX_USE_CONSTEXPR bool has_signaling_NaN = false; -: 1380: static _GLIBCXX_USE_CONSTEXPR float_denorm_style has_denorm -: 1381: = denorm_absent; -: 1382: static _GLIBCXX_USE_CONSTEXPR bool has_denorm_loss = false; -: 1383: -: 1384: static _GLIBCXX_CONSTEXPR long long -: 1385: infinity() _GLIBCXX_USE_NOEXCEPT { return static_cast(0); } -: 1386: -: 1387: static _GLIBCXX_CONSTEXPR long long -: 1388: quiet_NaN() _GLIBCXX_USE_NOEXCEPT { return static_cast(0); } -: 1389: -: 1390: static _GLIBCXX_CONSTEXPR long long -: 1391: signaling_NaN() _GLIBCXX_USE_NOEXCEPT -: 1392: { return static_cast(0); } -: 1393: -: 1394: static _GLIBCXX_CONSTEXPR long long -: 1395: denorm_min() _GLIBCXX_USE_NOEXCEPT { return static_cast(0); } -: 1396: -: 1397: static _GLIBCXX_USE_CONSTEXPR bool is_iec559 = false; -: 1398: static _GLIBCXX_USE_CONSTEXPR bool is_bounded = true; -: 1399: static _GLIBCXX_USE_CONSTEXPR bool is_modulo = false; -: 1400: -: 1401: static _GLIBCXX_USE_CONSTEXPR bool traps = __glibcxx_integral_traps; -: 1402: static _GLIBCXX_USE_CONSTEXPR bool tinyness_before = false; -: 1403: static _GLIBCXX_USE_CONSTEXPR float_round_style round_style -: 1404: = round_toward_zero; -: 1405: }; -: 1406: -: 1407: /// numeric_limits specialization. -: 1408: template<> -: 1409: struct numeric_limits -: 1410: { -: 1411: static _GLIBCXX_USE_CONSTEXPR bool is_specialized = true; -: 1412: -: 1413: static _GLIBCXX_CONSTEXPR unsigned long long -: 1414: min() _GLIBCXX_USE_NOEXCEPT { return 0; } -: 1415: -: 1416: static _GLIBCXX_CONSTEXPR unsigned long long -: 1417: max() _GLIBCXX_USE_NOEXCEPT { return __LONG_LONG_MAX__ * 2ULL + 1; } -: 1418: -: 1419:#if __cplusplus >= 201103L -: 1420: static constexpr unsigned long long -: 1421: lowest() noexcept { return min(); } -: 1422:#endif -: 1423: -: 1424: static _GLIBCXX_USE_CONSTEXPR int digits -: 1425: = __glibcxx_digits (unsigned long long); -: 1426: static _GLIBCXX_USE_CONSTEXPR int digits10 -: 1427: = __glibcxx_digits10 (unsigned long long); -: 1428:#if __cplusplus >= 201103L -: 1429: static constexpr int max_digits10 = 0; -: 1430:#endif -: 1431: static _GLIBCXX_USE_CONSTEXPR bool is_signed = false; -: 1432: static _GLIBCXX_USE_CONSTEXPR bool is_integer = true; -: 1433: static _GLIBCXX_USE_CONSTEXPR bool is_exact = true; -: 1434: static _GLIBCXX_USE_CONSTEXPR int radix = 2; -: 1435: -: 1436: static _GLIBCXX_CONSTEXPR unsigned long long -: 1437: epsilon() _GLIBCXX_USE_NOEXCEPT { return 0; } -: 1438: -: 1439: static _GLIBCXX_CONSTEXPR unsigned long long -: 1440: round_error() _GLIBCXX_USE_NOEXCEPT { return 0; } -: 1441: -: 1442: static _GLIBCXX_USE_CONSTEXPR int min_exponent = 0; -: 1443: static _GLIBCXX_USE_CONSTEXPR int min_exponent10 = 0; -: 1444: static _GLIBCXX_USE_CONSTEXPR int max_exponent = 0; -: 1445: static _GLIBCXX_USE_CONSTEXPR int max_exponent10 = 0; -: 1446: -: 1447: static _GLIBCXX_USE_CONSTEXPR bool has_infinity = false; -: 1448: static _GLIBCXX_USE_CONSTEXPR bool has_quiet_NaN = false; -: 1449: static _GLIBCXX_USE_CONSTEXPR bool has_signaling_NaN = false; -: 1450: static _GLIBCXX_USE_CONSTEXPR float_denorm_style has_denorm -: 1451: = denorm_absent; -: 1452: static _GLIBCXX_USE_CONSTEXPR bool has_denorm_loss = false; -: 1453: -: 1454: static _GLIBCXX_CONSTEXPR unsigned long long -: 1455: infinity() _GLIBCXX_USE_NOEXCEPT -: 1456: { return static_cast(0); } -: 1457: -: 1458: static _GLIBCXX_CONSTEXPR unsigned long long -: 1459: quiet_NaN() _GLIBCXX_USE_NOEXCEPT -: 1460: { return static_cast(0); } -: 1461: -: 1462: static _GLIBCXX_CONSTEXPR unsigned long long -: 1463: signaling_NaN() _GLIBCXX_USE_NOEXCEPT -: 1464: { return static_cast(0); } -: 1465: -: 1466: static _GLIBCXX_CONSTEXPR unsigned long long -: 1467: denorm_min() _GLIBCXX_USE_NOEXCEPT -: 1468: { return static_cast(0); } -: 1469: -: 1470: static _GLIBCXX_USE_CONSTEXPR bool is_iec559 = false; -: 1471: static _GLIBCXX_USE_CONSTEXPR bool is_bounded = true; -: 1472: static _GLIBCXX_USE_CONSTEXPR bool is_modulo = true; -: 1473: -: 1474: static _GLIBCXX_USE_CONSTEXPR bool traps = __glibcxx_integral_traps; -: 1475: static _GLIBCXX_USE_CONSTEXPR bool tinyness_before = false; -: 1476: static _GLIBCXX_USE_CONSTEXPR float_round_style round_style -: 1477: = round_toward_zero; -: 1478: }; -: 1479: -: 1480:#if !defined(__STRICT_ANSI__) -: 1481: -: 1482:#define __INT_N(TYPE, BITSIZE, EXT, UEXT) \ -: 1483: template<> \ -: 1484: struct numeric_limits \ -: 1485: { \ -: 1486: static _GLIBCXX_USE_CONSTEXPR bool is_specialized = true; \ -: 1487: \ -: 1488: static _GLIBCXX_CONSTEXPR TYPE \ -: 1489: min() _GLIBCXX_USE_NOEXCEPT { return __glibcxx_min_b (TYPE, BITSIZE); } \ -: 1490: \ -: 1491: static _GLIBCXX_CONSTEXPR TYPE \ -: 1492: max() _GLIBCXX_USE_NOEXCEPT { return __glibcxx_max_b (TYPE, BITSIZE); } \ -: 1493: \ -: 1494: static _GLIBCXX_USE_CONSTEXPR int digits \ -: 1495: = BITSIZE - 1; \ -: 1496: static _GLIBCXX_USE_CONSTEXPR int digits10 \ -: 1497: = (BITSIZE - 1) * 643L / 2136; \ -: 1498: \ -: 1499: static _GLIBCXX_USE_CONSTEXPR bool is_signed = true; \ -: 1500: static _GLIBCXX_USE_CONSTEXPR bool is_integer = true; \ -: 1501: static _GLIBCXX_USE_CONSTEXPR bool is_exact = true; \ -: 1502: static _GLIBCXX_USE_CONSTEXPR int radix = 2; \ -: 1503: \ -: 1504: static _GLIBCXX_CONSTEXPR TYPE \ -: 1505: epsilon() _GLIBCXX_USE_NOEXCEPT { return 0; } \ -: 1506: \ -: 1507: static _GLIBCXX_CONSTEXPR TYPE \ -: 1508: round_error() _GLIBCXX_USE_NOEXCEPT { return 0; } \ -: 1509: \ -: 1510: EXT \ -: 1511: \ -: 1512: static _GLIBCXX_USE_CONSTEXPR int min_exponent = 0; \ -: 1513: static _GLIBCXX_USE_CONSTEXPR int min_exponent10 = 0; \ -: 1514: static _GLIBCXX_USE_CONSTEXPR int max_exponent = 0; \ -: 1515: static _GLIBCXX_USE_CONSTEXPR int max_exponent10 = 0; \ -: 1516: \ -: 1517: static _GLIBCXX_USE_CONSTEXPR bool has_infinity = false; \ -: 1518: static _GLIBCXX_USE_CONSTEXPR bool has_quiet_NaN = false; \ -: 1519: static _GLIBCXX_USE_CONSTEXPR bool has_signaling_NaN = false; \ -: 1520: static _GLIBCXX_USE_CONSTEXPR float_denorm_style has_denorm \ -: 1521: = denorm_absent; \ -: 1522: static _GLIBCXX_USE_CONSTEXPR bool has_denorm_loss = false; \ -: 1523: \ -: 1524: static _GLIBCXX_CONSTEXPR TYPE \ -: 1525: infinity() _GLIBCXX_USE_NOEXCEPT \ -: 1526: { return static_cast(0); } \ -: 1527: \ -: 1528: static _GLIBCXX_CONSTEXPR TYPE \ -: 1529: quiet_NaN() _GLIBCXX_USE_NOEXCEPT \ -: 1530: { return static_cast(0); } \ -: 1531: \ -: 1532: static _GLIBCXX_CONSTEXPR TYPE \ -: 1533: signaling_NaN() _GLIBCXX_USE_NOEXCEPT \ -: 1534: { return static_cast(0); } \ -: 1535: \ -: 1536: static _GLIBCXX_CONSTEXPR TYPE \ -: 1537: denorm_min() _GLIBCXX_USE_NOEXCEPT \ -: 1538: { return static_cast(0); } \ -: 1539: \ -: 1540: static _GLIBCXX_USE_CONSTEXPR bool is_iec559 = false; \ -: 1541: static _GLIBCXX_USE_CONSTEXPR bool is_bounded = true; \ -: 1542: static _GLIBCXX_USE_CONSTEXPR bool is_modulo = false; \ -: 1543: \ -: 1544: static _GLIBCXX_USE_CONSTEXPR bool traps \ -: 1545: = __glibcxx_integral_traps; \ -: 1546: static _GLIBCXX_USE_CONSTEXPR bool tinyness_before = false; \ -: 1547: static _GLIBCXX_USE_CONSTEXPR float_round_style round_style \ -: 1548: = round_toward_zero; \ -: 1549: }; \ -: 1550: \ -: 1551: template<> \ -: 1552: struct numeric_limits \ -: 1553: { \ -: 1554: static _GLIBCXX_USE_CONSTEXPR bool is_specialized = true; \ -: 1555: \ -: 1556: static _GLIBCXX_CONSTEXPR unsigned TYPE \ -: 1557: min() _GLIBCXX_USE_NOEXCEPT { return 0; } \ -: 1558: \ -: 1559: static _GLIBCXX_CONSTEXPR unsigned TYPE \ -: 1560: max() _GLIBCXX_USE_NOEXCEPT \ -: 1561: { return __glibcxx_max_b (unsigned TYPE, BITSIZE); } \ -: 1562: \ -: 1563: UEXT \ -: 1564: \ -: 1565: static _GLIBCXX_USE_CONSTEXPR int digits \ -: 1566: = BITSIZE; \ -: 1567: static _GLIBCXX_USE_CONSTEXPR int digits10 \ -: 1568: = BITSIZE * 643L / 2136; \ -: 1569: static _GLIBCXX_USE_CONSTEXPR bool is_signed = false; \ -: 1570: static _GLIBCXX_USE_CONSTEXPR bool is_integer = true; \ -: 1571: static _GLIBCXX_USE_CONSTEXPR bool is_exact = true; \ -: 1572: static _GLIBCXX_USE_CONSTEXPR int radix = 2; \ -: 1573: \ -: 1574: static _GLIBCXX_CONSTEXPR unsigned TYPE \ -: 1575: epsilon() _GLIBCXX_USE_NOEXCEPT { return 0; } \ -: 1576: \ -: 1577: static _GLIBCXX_CONSTEXPR unsigned TYPE \ -: 1578: round_error() _GLIBCXX_USE_NOEXCEPT { return 0; } \ -: 1579: \ -: 1580: static _GLIBCXX_USE_CONSTEXPR int min_exponent = 0; \ -: 1581: static _GLIBCXX_USE_CONSTEXPR int min_exponent10 = 0; \ -: 1582: static _GLIBCXX_USE_CONSTEXPR int max_exponent = 0; \ -: 1583: static _GLIBCXX_USE_CONSTEXPR int max_exponent10 = 0; \ -: 1584: \ -: 1585: static _GLIBCXX_USE_CONSTEXPR bool has_infinity = false; \ -: 1586: static _GLIBCXX_USE_CONSTEXPR bool has_quiet_NaN = false; \ -: 1587: static _GLIBCXX_USE_CONSTEXPR bool has_signaling_NaN = false; \ -: 1588: static _GLIBCXX_USE_CONSTEXPR float_denorm_style has_denorm \ -: 1589: = denorm_absent; \ -: 1590: static _GLIBCXX_USE_CONSTEXPR bool has_denorm_loss = false; \ -: 1591: \ -: 1592: static _GLIBCXX_CONSTEXPR unsigned TYPE \ -: 1593: infinity() _GLIBCXX_USE_NOEXCEPT \ -: 1594: { return static_cast(0); } \ -: 1595: \ -: 1596: static _GLIBCXX_CONSTEXPR unsigned TYPE \ -: 1597: quiet_NaN() _GLIBCXX_USE_NOEXCEPT \ -: 1598: { return static_cast(0); } \ -: 1599: \ -: 1600: static _GLIBCXX_CONSTEXPR unsigned TYPE \ -: 1601: signaling_NaN() _GLIBCXX_USE_NOEXCEPT \ -: 1602: { return static_cast(0); } \ -: 1603: \ -: 1604: static _GLIBCXX_CONSTEXPR unsigned TYPE \ -: 1605: denorm_min() _GLIBCXX_USE_NOEXCEPT \ -: 1606: { return static_cast(0); } \ -: 1607: \ -: 1608: static _GLIBCXX_USE_CONSTEXPR bool is_iec559 = false; \ -: 1609: static _GLIBCXX_USE_CONSTEXPR bool is_bounded = true; \ -: 1610: static _GLIBCXX_USE_CONSTEXPR bool is_modulo = true; \ -: 1611: \ -: 1612: static _GLIBCXX_USE_CONSTEXPR bool traps = __glibcxx_integral_traps; \ -: 1613: static _GLIBCXX_USE_CONSTEXPR bool tinyness_before = false; \ -: 1614: static _GLIBCXX_USE_CONSTEXPR float_round_style round_style \ -: 1615: = round_toward_zero; \ -: 1616: }; -: 1617: -: 1618:#if __cplusplus >= 201103L -: 1619: -: 1620:#define __INT_N_201103(TYPE) \ -: 1621: static constexpr TYPE \ -: 1622: lowest() noexcept { return min(); } \ -: 1623: static constexpr int max_digits10 = 0; -: 1624: -: 1625:#define __INT_N_U201103(TYPE) \ -: 1626: static constexpr unsigned TYPE \ -: 1627: lowest() noexcept { return min(); } \ -: 1628: static constexpr int max_digits10 = 0; -: 1629: -: 1630:#else -: 1631:#define __INT_N_201103(TYPE) -: 1632:#define __INT_N_U201103(TYPE) -: 1633:#endif -: 1634: -: 1635:#ifdef __GLIBCXX_TYPE_INT_N_0 -: 1636: __INT_N(__GLIBCXX_TYPE_INT_N_0, __GLIBCXX_BITSIZE_INT_N_0, -: 1637: __INT_N_201103 (__GLIBCXX_TYPE_INT_N_0), __INT_N_U201103 (__GLIBCXX_TYPE_INT_N_0)) -: 1638:#endif -: 1639:#ifdef __GLIBCXX_TYPE_INT_N_1 -: 1640: __INT_N (__GLIBCXX_TYPE_INT_N_1, __GLIBCXX_BITSIZE_INT_N_1, -: 1641: __INT_N_201103 (__GLIBCXX_TYPE_INT_N_1), __INT_N_U201103 (__GLIBCXX_TYPE_INT_N_1)) -: 1642:#endif -: 1643:#ifdef __GLIBCXX_TYPE_INT_N_2 -: 1644: __INT_N (__GLIBCXX_TYPE_INT_N_2, __GLIBCXX_BITSIZE_INT_N_2, -: 1645: __INT_N_201103 (__GLIBCXX_TYPE_INT_N_2), __INT_N_U201103 (__GLIBCXX_TYPE_INT_N_2)) -: 1646:#endif -: 1647:#ifdef __GLIBCXX_TYPE_INT_N_3 -: 1648: __INT_N (__GLIBCXX_TYPE_INT_N_3, __GLIBCXX_BITSIZE_INT_N_3, -: 1649: __INT_N_201103 (__GLIBCXX_TYPE_INT_N_3), __INT_N_U201103 (__GLIBCXX_TYPE_INT_N_3)) -: 1650:#endif -: 1651: -: 1652:#undef __INT_N -: 1653:#undef __INT_N_201103 -: 1654:#undef __INT_N_U201103 -: 1655: -: 1656:#endif -: 1657: -: 1658: /// numeric_limits specialization. -: 1659: template<> -: 1660: struct numeric_limits -: 1661: { -: 1662: static _GLIBCXX_USE_CONSTEXPR bool is_specialized = true; -: 1663: -: 1664: static _GLIBCXX_CONSTEXPR float -: 1665: min() _GLIBCXX_USE_NOEXCEPT { return __FLT_MIN__; } -: 1666: -: 1667: static _GLIBCXX_CONSTEXPR float -: 1668: max() _GLIBCXX_USE_NOEXCEPT { return __FLT_MAX__; } -: 1669: -: 1670:#if __cplusplus >= 201103L -: 1671: static constexpr float -: 1672: lowest() noexcept { return -__FLT_MAX__; } -: 1673:#endif -: 1674: -: 1675: static _GLIBCXX_USE_CONSTEXPR int digits = __FLT_MANT_DIG__; -: 1676: static _GLIBCXX_USE_CONSTEXPR int digits10 = __FLT_DIG__; -: 1677:#if __cplusplus >= 201103L -: 1678: static constexpr int max_digits10 -: 1679: = __glibcxx_max_digits10 (__FLT_MANT_DIG__); -: 1680:#endif -: 1681: static _GLIBCXX_USE_CONSTEXPR bool is_signed = true; -: 1682: static _GLIBCXX_USE_CONSTEXPR bool is_integer = false; -: 1683: static _GLIBCXX_USE_CONSTEXPR bool is_exact = false; -: 1684: static _GLIBCXX_USE_CONSTEXPR int radix = __FLT_RADIX__; -: 1685: -: 1686: static _GLIBCXX_CONSTEXPR float -: 1687: epsilon() _GLIBCXX_USE_NOEXCEPT { return __FLT_EPSILON__; } -: 1688: -: 1689: static _GLIBCXX_CONSTEXPR float -: 1690: round_error() _GLIBCXX_USE_NOEXCEPT { return 0.5F; } -: 1691: -: 1692: static _GLIBCXX_USE_CONSTEXPR int min_exponent = __FLT_MIN_EXP__; -: 1693: static _GLIBCXX_USE_CONSTEXPR int min_exponent10 = __FLT_MIN_10_EXP__; -: 1694: static _GLIBCXX_USE_CONSTEXPR int max_exponent = __FLT_MAX_EXP__; -: 1695: static _GLIBCXX_USE_CONSTEXPR int max_exponent10 = __FLT_MAX_10_EXP__; -: 1696: -: 1697: static _GLIBCXX_USE_CONSTEXPR bool has_infinity = __FLT_HAS_INFINITY__; -: 1698: static _GLIBCXX_USE_CONSTEXPR bool has_quiet_NaN = __FLT_HAS_QUIET_NAN__; -: 1699: static _GLIBCXX_USE_CONSTEXPR bool has_signaling_NaN = has_quiet_NaN; -: 1700: static _GLIBCXX_USE_CONSTEXPR float_denorm_style has_denorm -: 1701: = bool(__FLT_HAS_DENORM__) ? denorm_present : denorm_absent; -: 1702: static _GLIBCXX_USE_CONSTEXPR bool has_denorm_loss -: 1703: = __glibcxx_float_has_denorm_loss; -: 1704: -: 1705: static _GLIBCXX_CONSTEXPR float -: 1706: infinity() _GLIBCXX_USE_NOEXCEPT { return __builtin_huge_valf(); } -: 1707: -: 1708: static _GLIBCXX_CONSTEXPR float -: 1709: quiet_NaN() _GLIBCXX_USE_NOEXCEPT { return __builtin_nanf(""); } -: 1710: -: 1711: static _GLIBCXX_CONSTEXPR float -: 1712: signaling_NaN() _GLIBCXX_USE_NOEXCEPT { return __builtin_nansf(""); } -: 1713: -: 1714: static _GLIBCXX_CONSTEXPR float -: 1715: denorm_min() _GLIBCXX_USE_NOEXCEPT { return __FLT_DENORM_MIN__; } -: 1716: -: 1717: static _GLIBCXX_USE_CONSTEXPR bool is_iec559 -: 1718: = has_infinity && has_quiet_NaN && has_denorm == denorm_present; -: 1719: static _GLIBCXX_USE_CONSTEXPR bool is_bounded = true; -: 1720: static _GLIBCXX_USE_CONSTEXPR bool is_modulo = false; -: 1721: -: 1722: static _GLIBCXX_USE_CONSTEXPR bool traps = __glibcxx_float_traps; -: 1723: static _GLIBCXX_USE_CONSTEXPR bool tinyness_before -: 1724: = __glibcxx_float_tinyness_before; -: 1725: static _GLIBCXX_USE_CONSTEXPR float_round_style round_style -: 1726: = round_to_nearest; -: 1727: }; -: 1728: -: 1729:#undef __glibcxx_float_has_denorm_loss -: 1730:#undef __glibcxx_float_traps -: 1731:#undef __glibcxx_float_tinyness_before -: 1732: -: 1733: /// numeric_limits specialization. -: 1734: template<> -: 1735: struct numeric_limits -: 1736: { -: 1737: static _GLIBCXX_USE_CONSTEXPR bool is_specialized = true; -: 1738: -: 1739: static _GLIBCXX_CONSTEXPR double -: 1740: min() _GLIBCXX_USE_NOEXCEPT { return __DBL_MIN__; } -: 1741: -: 1742: static _GLIBCXX_CONSTEXPR double -: 1743: max() _GLIBCXX_USE_NOEXCEPT { return __DBL_MAX__; } -: 1744: -: 1745:#if __cplusplus >= 201103L -: 1746: static constexpr double -: 1747: lowest() noexcept { return -__DBL_MAX__; } -: 1748:#endif -: 1749: -: 1750: static _GLIBCXX_USE_CONSTEXPR int digits = __DBL_MANT_DIG__; -: 1751: static _GLIBCXX_USE_CONSTEXPR int digits10 = __DBL_DIG__; -: 1752:#if __cplusplus >= 201103L -: 1753: static constexpr int max_digits10 -: 1754: = __glibcxx_max_digits10 (__DBL_MANT_DIG__); -: 1755:#endif -: 1756: static _GLIBCXX_USE_CONSTEXPR bool is_signed = true; -: 1757: static _GLIBCXX_USE_CONSTEXPR bool is_integer = false; -: 1758: static _GLIBCXX_USE_CONSTEXPR bool is_exact = false; -: 1759: static _GLIBCXX_USE_CONSTEXPR int radix = __FLT_RADIX__; -: 1760: -: 1761: static _GLIBCXX_CONSTEXPR double -: 1762: epsilon() _GLIBCXX_USE_NOEXCEPT { return __DBL_EPSILON__; } -: 1763: -: 1764: static _GLIBCXX_CONSTEXPR double -: 1765: round_error() _GLIBCXX_USE_NOEXCEPT { return 0.5; } -: 1766: -: 1767: static _GLIBCXX_USE_CONSTEXPR int min_exponent = __DBL_MIN_EXP__; -: 1768: static _GLIBCXX_USE_CONSTEXPR int min_exponent10 = __DBL_MIN_10_EXP__; -: 1769: static _GLIBCXX_USE_CONSTEXPR int max_exponent = __DBL_MAX_EXP__; -: 1770: static _GLIBCXX_USE_CONSTEXPR int max_exponent10 = __DBL_MAX_10_EXP__; -: 1771: -: 1772: static _GLIBCXX_USE_CONSTEXPR bool has_infinity = __DBL_HAS_INFINITY__; -: 1773: static _GLIBCXX_USE_CONSTEXPR bool has_quiet_NaN = __DBL_HAS_QUIET_NAN__; -: 1774: static _GLIBCXX_USE_CONSTEXPR bool has_signaling_NaN = has_quiet_NaN; -: 1775: static _GLIBCXX_USE_CONSTEXPR float_denorm_style has_denorm -: 1776: = bool(__DBL_HAS_DENORM__) ? denorm_present : denorm_absent; -: 1777: static _GLIBCXX_USE_CONSTEXPR bool has_denorm_loss -: 1778: = __glibcxx_double_has_denorm_loss; -: 1779: -: 1780: static _GLIBCXX_CONSTEXPR double -: 1781: infinity() _GLIBCXX_USE_NOEXCEPT { return __builtin_huge_val(); } -: 1782: -: 1783: static _GLIBCXX_CONSTEXPR double -: 1784: quiet_NaN() _GLIBCXX_USE_NOEXCEPT { return __builtin_nan(""); } -: 1785: -: 1786: static _GLIBCXX_CONSTEXPR double -: 1787: signaling_NaN() _GLIBCXX_USE_NOEXCEPT { return __builtin_nans(""); } -: 1788: -: 1789: static _GLIBCXX_CONSTEXPR double -: 1790: denorm_min() _GLIBCXX_USE_NOEXCEPT { return __DBL_DENORM_MIN__; } -: 1791: -: 1792: static _GLIBCXX_USE_CONSTEXPR bool is_iec559 -: 1793: = has_infinity && has_quiet_NaN && has_denorm == denorm_present; -: 1794: static _GLIBCXX_USE_CONSTEXPR bool is_bounded = true; -: 1795: static _GLIBCXX_USE_CONSTEXPR bool is_modulo = false; -: 1796: -: 1797: static _GLIBCXX_USE_CONSTEXPR bool traps = __glibcxx_double_traps; -: 1798: static _GLIBCXX_USE_CONSTEXPR bool tinyness_before -: 1799: = __glibcxx_double_tinyness_before; -: 1800: static _GLIBCXX_USE_CONSTEXPR float_round_style round_style -: 1801: = round_to_nearest; -: 1802: }; -: 1803: -: 1804:#undef __glibcxx_double_has_denorm_loss -: 1805:#undef __glibcxx_double_traps -: 1806:#undef __glibcxx_double_tinyness_before -: 1807: -: 1808: /// numeric_limits specialization. -: 1809: template<> -: 1810: struct numeric_limits -: 1811: { -: 1812: static _GLIBCXX_USE_CONSTEXPR bool is_specialized = true; -: 1813: -: 1814: static _GLIBCXX_CONSTEXPR long double 8: 1815: min() _GLIBCXX_USE_NOEXCEPT { return __LDBL_MIN__; } -: 1816: -: 1817: static _GLIBCXX_CONSTEXPR long double -: 1818: max() _GLIBCXX_USE_NOEXCEPT { return __LDBL_MAX__; } -: 1819: -: 1820:#if __cplusplus >= 201103L -: 1821: static constexpr long double -: 1822: lowest() noexcept { return -__LDBL_MAX__; } -: 1823:#endif -: 1824: -: 1825: static _GLIBCXX_USE_CONSTEXPR int digits = __LDBL_MANT_DIG__; -: 1826: static _GLIBCXX_USE_CONSTEXPR int digits10 = __LDBL_DIG__; -: 1827:#if __cplusplus >= 201103L -: 1828: static _GLIBCXX_USE_CONSTEXPR int max_digits10 -: 1829: = __glibcxx_max_digits10 (__LDBL_MANT_DIG__); -: 1830:#endif -: 1831: static _GLIBCXX_USE_CONSTEXPR bool is_signed = true; -: 1832: static _GLIBCXX_USE_CONSTEXPR bool is_integer = false; -: 1833: static _GLIBCXX_USE_CONSTEXPR bool is_exact = false; -: 1834: static _GLIBCXX_USE_CONSTEXPR int radix = __FLT_RADIX__; -: 1835: -: 1836: static _GLIBCXX_CONSTEXPR long double -: 1837: epsilon() _GLIBCXX_USE_NOEXCEPT { return __LDBL_EPSILON__; } -: 1838: -: 1839: static _GLIBCXX_CONSTEXPR long double -: 1840: round_error() _GLIBCXX_USE_NOEXCEPT { return 0.5L; } -: 1841: -: 1842: static _GLIBCXX_USE_CONSTEXPR int min_exponent = __LDBL_MIN_EXP__; -: 1843: static _GLIBCXX_USE_CONSTEXPR int min_exponent10 = __LDBL_MIN_10_EXP__; -: 1844: static _GLIBCXX_USE_CONSTEXPR int max_exponent = __LDBL_MAX_EXP__; -: 1845: static _GLIBCXX_USE_CONSTEXPR int max_exponent10 = __LDBL_MAX_10_EXP__; -: 1846: -: 1847: static _GLIBCXX_USE_CONSTEXPR bool has_infinity = __LDBL_HAS_INFINITY__; -: 1848: static _GLIBCXX_USE_CONSTEXPR bool has_quiet_NaN = __LDBL_HAS_QUIET_NAN__; -: 1849: static _GLIBCXX_USE_CONSTEXPR bool has_signaling_NaN = has_quiet_NaN; -: 1850: static _GLIBCXX_USE_CONSTEXPR float_denorm_style has_denorm -: 1851: = bool(__LDBL_HAS_DENORM__) ? denorm_present : denorm_absent; -: 1852: static _GLIBCXX_USE_CONSTEXPR bool has_denorm_loss -: 1853: = __glibcxx_long_double_has_denorm_loss; -: 1854: -: 1855: static _GLIBCXX_CONSTEXPR long double 10: 1856: infinity() _GLIBCXX_USE_NOEXCEPT { return __builtin_huge_vall(); } -: 1857: -: 1858: static _GLIBCXX_CONSTEXPR long double 4: 1859: quiet_NaN() _GLIBCXX_USE_NOEXCEPT { return __builtin_nanl(""); } -: 1860: -: 1861: static _GLIBCXX_CONSTEXPR long double -: 1862: signaling_NaN() _GLIBCXX_USE_NOEXCEPT { return __builtin_nansl(""); } -: 1863: -: 1864: static _GLIBCXX_CONSTEXPR long double -: 1865: denorm_min() _GLIBCXX_USE_NOEXCEPT { return __LDBL_DENORM_MIN__; } -: 1866: -: 1867: static _GLIBCXX_USE_CONSTEXPR bool is_iec559 -: 1868: = has_infinity && has_quiet_NaN && has_denorm == denorm_present; -: 1869: static _GLIBCXX_USE_CONSTEXPR bool is_bounded = true; -: 1870: static _GLIBCXX_USE_CONSTEXPR bool is_modulo = false; -: 1871: -: 1872: static _GLIBCXX_USE_CONSTEXPR bool traps = __glibcxx_long_double_traps; -: 1873: static _GLIBCXX_USE_CONSTEXPR bool tinyness_before = -: 1874: __glibcxx_long_double_tinyness_before; -: 1875: static _GLIBCXX_USE_CONSTEXPR float_round_style round_style = -: 1876: round_to_nearest; -: 1877: }; -: 1878: -: 1879:#undef __glibcxx_long_double_has_denorm_loss -: 1880:#undef __glibcxx_long_double_traps -: 1881:#undef __glibcxx_long_double_tinyness_before -: 1882: -: 1883:_GLIBCXX_END_NAMESPACE_VERSION -: 1884:} // namespace -: 1885: -: 1886:#undef __glibcxx_signed -: 1887:#undef __glibcxx_min -: 1888:#undef __glibcxx_max -: 1889:#undef __glibcxx_digits -: 1890:#undef __glibcxx_digits10 -: 1891:#undef __glibcxx_max_digits10 -: 1892: -: 1893:#endif // _GLIBCXX_NUMERIC_LIMITS <<<<<< EOF # path=tests/log.cpp.gcov -: 0:Source:log.cpp -: 0:Graph:log.gcno -: 0:Data:log.gcda -: 0:Runs:2 -: 1:/*################################################################################ -: 2: ## -: 3: ## Copyright (C) 2016-2022 Keith O'Hara -: 4: ## -: 5: ## This file is part of the GCE-Math C++ library. -: 6: ## -: 7: ## Licensed under the Apache License, Version 2.0 (the "License"); -: 8: ## you may not use this file except in compliance with the License. -: 9: ## You may obtain a copy of the License at -: 10: ## -: 11: ## http://www.apache.org/licenses/LICENSE-2.0 -: 12: ## -: 13: ## Unless required by applicable law or agreed to in writing, software -: 14: ## distributed under the License is distributed on an "AS IS" BASIS, -: 15: ## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -: 16: ## See the License for the specific language governing permissions and -: 17: ## limitations under the License. -: 18: ## -: 19: ################################################################################*/ -: 20: -: 21:// g++-mp-7 -O3 -Wall -std=c++11 -fconstexpr-depth=20 -fconstexpr-steps=1271242 -I./../include log.cpp -o log.test -framework Accelerate -: 22: -: 23:#define TEST_PRINT_PRECISION_1 6 -: 24:#define TEST_PRINT_PRECISION_2 18 -: 25: -: 26:#include "gcem_tests.hpp" -: 27: 2: 28:int main() -: 29:{ 2: 30: print_begin("log"); -: 31: -: 32: // -: 33: 4*: 34: GCEM_TEST_COMPARE_VALS(gcem::log,std::log, 0.5L); 4*: 35: GCEM_TEST_COMPARE_VALS(gcem::log,std::log, 0.00199900000000000208L); 4*: 36: GCEM_TEST_COMPARE_VALS(gcem::log,std::log, 1.0L); 4*: 37: GCEM_TEST_COMPARE_VALS(gcem::log,std::log, 1.5L); 4*: 38: GCEM_TEST_COMPARE_VALS(gcem::log,std::log, 41.5L); 4*: 39: GCEM_TEST_COMPARE_VALS(gcem::log,std::log, 0.0L); 4*: 40: GCEM_TEST_COMPARE_VALS(gcem::log,std::log, -1.0L); 4*: 41: GCEM_TEST_COMPARE_VALS(gcem::log,std::log, 1e-500L); 4*: 42: GCEM_TEST_COMPARE_VALS(gcem::log,std::log, std::numeric_limits::min()); -: 43: 4*: 44: GCEM_TEST_COMPARE_VALS(gcem::log,std::log, -std::numeric_limits::infinity()); 4*: 45: GCEM_TEST_COMPARE_VALS(gcem::log,std::log, std::numeric_limits::infinity()); 4*: 46: GCEM_TEST_COMPARE_VALS(gcem::log,std::log, std::numeric_limits::quiet_NaN()); -: 47: -: 48: // -: 49: 2: 50: print_final("log"); -: 51: 2: 52: return 0; -: 53:} <<<<<< EOF # path=tests/log.hpp.gcov -: 0:Source:../include/gcem_incl/log.hpp -: 0:Graph:log.gcno -: 0:Data:log.gcda -: 0:Runs:2 -: 1:/*################################################################################ -: 2: ## -: 3: ## Copyright (C) 2016-2022 Keith O'Hara -: 4: ## -: 5: ## This file is part of the GCE-Math C++ library. -: 6: ## -: 7: ## Licensed under the Apache License, Version 2.0 (the "License"); -: 8: ## you may not use this file except in compliance with the License. -: 9: ## You may obtain a copy of the License at -: 10: ## -: 11: ## http://www.apache.org/licenses/LICENSE-2.0 -: 12: ## -: 13: ## Unless required by applicable law or agreed to in writing, software -: 14: ## distributed under the License is distributed on an "AS IS" BASIS, -: 15: ## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -: 16: ## See the License for the specific language governing permissions and -: 17: ## limitations under the License. -: 18: ## -: 19: ################################################################################*/ -: 20: -: 21:/* -: 22: * compile-time natural logarithm function -: 23: */ -: 24: -: 25:#ifndef _gcem_log_HPP -: 26:#define _gcem_log_HPP -: 27: -: 28:namespace internal -: 29:{ -: 30: -: 31:// continued fraction seems to be a better approximation for small x -: 32:// see http://functions.wolfram.com/ElementaryFunctions/Log/10/0005/ -: 33: -: 34:template -: 35:constexpr -: 36:T 50: 37:log_cf_main(const T xx, const int depth) -: 38:noexcept -: 39:{ 50: 40: return( depth < GCEM_LOG_MAX_ITER_SMALL ? \ -: 41: // if 48: 42: T(2*depth - 1) - T(depth*depth)*xx/log_cf_main(xx,depth+1) : -: 43: // else 50: 44: T(2*depth - 1) ); -: 45:} -: 46: -: 47:template -: 48:constexpr -: 49:T 2: 50:log_cf_begin(const T x) -: 51:noexcept -: 52:{ 2: 53: return( T(2)*x/log_cf_main(x*x,1) ); -: 54:} -: 55: -: 56:template -: 57:constexpr -: 58:T 2: 59:log_main(const T x) -: 60:noexcept -: 61:{ 2: 62: return( log_cf_begin((x - T(1))/(x + T(1))) ); -: 63:} -: 64: -: 65:constexpr -: 66:long double 2: 67:log_mantissa_integer(const int x) -: 68:noexcept -: 69:{ 4*: 70: return( x == 2 ? 0.6931471805599453094172321214581765680755L : 2*: 71: x == 3 ? 1.0986122886681096913952452369225257046475L : #####: 72: x == 4 ? 1.3862943611198906188344642429163531361510L : #####: 73: x == 5 ? 1.6094379124341003746007593332261876395256L : #####: 74: x == 6 ? 1.7917594692280550008124773583807022727230L : #####: 75: x == 7 ? 1.9459101490553133051053527434431797296371L : #####: 76: x == 8 ? 2.0794415416798359282516963643745297042265L : #####: 77: x == 9 ? 2.1972245773362193827904904738450514092950L : #####: 78: x == 10 ? 2.3025850929940456840179914546843642076011L : 2: 79: 0.0L ); -: 80:} -: 81: -: 82:template -: 83:constexpr -: 84:T 2: 85:log_mantissa(const T x) -: 86:noexcept -: 87:{ // divide by the integer part of x, which will be in [1,10], then adjust using tables 2: 88: return( log_main(x/T(static_cast(x))) + T(log_mantissa_integer(static_cast(x))) ); -: 89:} -: 90: -: 91:template -: 92:constexpr -: 93:T 2: 94:log_breakup(const T x) -: 95:noexcept -: 96:{ // x = a*b, where b = 10^c 2: 97: return( log_mantissa(mantissa(x)) + T(GCEM_LOG_10)*T(find_exponent(x,0)) ); -: 98:} -: 99: -: 100:template -: 101:constexpr -: 102:T 2: 103:log_check(const T x) -: 104:noexcept -: 105:{ 4: 106: return( is_nan(x) ? \ #####: 107: GCLIM::quiet_NaN() : -: 108: // x < 0 4: 109: x < T(0) ? \ #####: 110: GCLIM::quiet_NaN() : -: 111: // x ~= 0 4*: 112: GCLIM::min() > x ? \ #####: 113: - GCLIM::infinity() : -: 114: // indistinguishable from 1 4*: 115: GCLIM::min() > abs(x - T(1)) ? \ -: 116: T(0) : -: 117: // 4: 118: x == GCLIM::infinity() ? \ #####: 119: GCLIM::infinity() : -: 120: // else 2*: 121: (x < T(0.5) || x > T(1.5)) ? -: 122: // if 2: 123: log_breakup(x) : -: 124: // else 2*: 125: log_main(x) ); -: 126:} -: 127: -: 128:template -: 129:constexpr -: 130:return_t 2: 131:log_integral_check(const T x) -: 132:noexcept -: 133:{ 2: 134: return( std::is_integral::value ? \ -: 135: x == T(0) ? \ -: 136: - GCLIM>::infinity() : -: 137: x > T(1) ? \ -: 138: log_check( static_cast>(x) ) : -: 139: static_cast>(0) : 2: 140: log_check( static_cast>(x) ) ); -: 141:} -: 142: -: 143:} -: 144: -: 145:/** -: 146: * Compile-time natural logarithm function -: 147: * -: 148: * @param x a real-valued input. -: 149: * @return \f$ \log_e(x) \f$ using \f[ \log\left(\frac{1+x}{1-x}\right) = \dfrac{2x}{1-\dfrac{x^2}{3-\dfrac{4x^2}{5 - \dfrac{9x^3}{7 - \ddots}}}}, \ \ x \in [-1,1] \f] -: 150: * The continued fraction argument is split into two parts: \f$ x = a \times 10^c \f$, where \f$ c \f$ is an integer. -: 151: */ -: 152: -: 153:template -: 154:constexpr -: 155:return_t 2: 156:log(const T x) -: 157:noexcept -: 158:{ 2: 159: return internal::log_integral_check( x ); -: 160:} -: 161: -: 162:#endif <<<<<< EOF # path=tests/log10.cpp.gcov -: 0:Source:log10.cpp -: 0:Graph:./log10.gcno -: 0:Data:./log10.gcda -: 0:Runs:1 -: 1:/*################################################################################ -: 2: ## -: 3: ## Copyright (C) 2016-2022 Keith O'Hara -: 4: ## -: 5: ## This file is part of the GCE-Math C++ library. -: 6: ## -: 7: ## Licensed under the Apache License, Version 2.0 (the "License"); -: 8: ## you may not use this file except in compliance with the License. -: 9: ## You may obtain a copy of the License at -: 10: ## -: 11: ## http://www.apache.org/licenses/LICENSE-2.0 -: 12: ## -: 13: ## Unless required by applicable law or agreed to in writing, software -: 14: ## distributed under the License is distributed on an "AS IS" BASIS, -: 15: ## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -: 16: ## See the License for the specific language governing permissions and -: 17: ## limitations under the License. -: 18: ## -: 19: ################################################################################*/ -: 20: -: 21:#define TEST_PRINT_PRECISION_1 6 -: 22:#define TEST_PRINT_PRECISION_2 18 -: 23: -: 24:#include "gcem_tests.hpp" -: 25: 1: 26:int main() -: 27:{ 1: 28: print_begin("log10"); -: 29: -: 30: // -: 31: 2*: 32: GCEM_TEST_COMPARE_VALS(gcem::log10, std::log10, 0.5L); 2*: 33: GCEM_TEST_COMPARE_VALS(gcem::log10, std::log10, 0.00199900000000000208L); 2*: 34: GCEM_TEST_COMPARE_VALS(gcem::log10, std::log10, 1.5L); 2*: 35: GCEM_TEST_COMPARE_VALS(gcem::log10, std::log10, 41.5L); 2*: 36: GCEM_TEST_COMPARE_VALS(gcem::log10, std::log10, 0.0L); 2*: 37: GCEM_TEST_COMPARE_VALS(gcem::log10, std::log10, -1.0L); 2*: 38: GCEM_TEST_COMPARE_VALS(gcem::log10, std::log10, 1e-500L); 2*: 39: GCEM_TEST_COMPARE_VALS(gcem::log10, std::log10, std::numeric_limits::min()); -: 40: 2*: 41: GCEM_TEST_COMPARE_VALS(gcem::log10, std::log10, -std::numeric_limits::infinity()); 2*: 42: GCEM_TEST_COMPARE_VALS(gcem::log10, std::log10, std::numeric_limits::infinity()); 2*: 43: GCEM_TEST_COMPARE_VALS(gcem::log10, std::log10, std::numeric_limits::quiet_NaN()); -: 44: -: 45: // -: 46: 1: 47: print_final("log10"); -: 48: 1: 49: return 0; -: 50:} <<<<<< EOF # path=tests/log10.hpp.gcov -: 0:Source:../include/gcem_incl/log10.hpp -: 0:Graph:./log10.gcno -: 0:Data:./log10.gcda -: 0:Runs:1 -: 1:/*################################################################################ -: 2: ## -: 3: ## Copyright (C) 2016-2022 Keith O'Hara -: 4: ## -: 5: ## This file is part of the GCE-Math C++ library. -: 6: ## -: 7: ## Licensed under the Apache License, Version 2.0 (the "License"); -: 8: ## you may not use this file except in compliance with the License. -: 9: ## You may obtain a copy of the License at -: 10: ## -: 11: ## http://www.apache.org/licenses/LICENSE-2.0 -: 12: ## -: 13: ## Unless required by applicable law or agreed to in writing, software -: 14: ## distributed under the License is distributed on an "AS IS" BASIS, -: 15: ## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -: 16: ## See the License for the specific language governing permissions and -: 17: ## limitations under the License. -: 18: ## -: 19: ################################################################################*/ -: 20: -: 21:/* -: 22: * compile-time common logarithm function -: 23: */ -: 24: -: 25:#ifndef _gcem_log10_HPP -: 26:#define _gcem_log10_HPP -: 27: -: 28:namespace internal -: 29:{ -: 30: -: 31:template -: 32:constexpr -: 33:return_t 1: 34:log10_check(const T x) -: 35:noexcept -: 36:{ -: 37: // log_10(x) = ln(x) / ln(10) 1: 38: return return_t(log(x) / GCEM_LOG_10); -: 39:} -: 40: -: 41:} -: 42: -: 43:/** -: 44: * Compile-time common logarithm function -: 45: * -: 46: * @param x a real-valued input. -: 47: * @return \f$ \log_{10}(x) \f$ using \f[ \log_{10}(x) = \frac{\log_e(x)}{\log_e(10)} \f] -: 48: */ -: 49: -: 50:template -: 51:constexpr -: 52:return_t 1: 53:log10(const T x) -: 54:noexcept -: 55:{ 1: 56: return internal::log10_check( x ); -: 57:} -: 58: -: 59:#endif <<<<<< EOF # path=tests/log1p.cpp.gcov -: 0:Source:log1p.cpp -: 0:Graph:./log1p.gcno -: 0:Data:./log1p.gcda -: 0:Runs:1 -: 1:/*################################################################################ -: 2: ## -: 3: ## Copyright (C) 2016-2022 Keith O'Hara -: 4: ## -: 5: ## This file is part of the GCE-Math C++ library. -: 6: ## -: 7: ## Licensed under the Apache License, Version 2.0 (the "License"); -: 8: ## you may not use this file except in compliance with the License. -: 9: ## You may obtain a copy of the License at -: 10: ## -: 11: ## http://www.apache.org/licenses/LICENSE-2.0 -: 12: ## -: 13: ## Unless required by applicable law or agreed to in writing, software -: 14: ## distributed under the License is distributed on an "AS IS" BASIS, -: 15: ## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -: 16: ## See the License for the specific language governing permissions and -: 17: ## limitations under the License. -: 18: ## -: 19: ################################################################################*/ -: 20: -: 21:#define TEST_PRINT_PRECISION_1 5 -: 22:#define TEST_PRINT_PRECISION_2 18 -: 23: -: 24:#include "gcem_tests.hpp" -: 25: 1: 26:int main() -: 27:{ 1: 28: print_begin("log1p"); -: 29: -: 30: // -: 31: 2*: 32: GCEM_TEST_COMPARE_VALS(gcem::log1p,std::log1p,1.0L); 2*: 33: GCEM_TEST_COMPARE_VALS(gcem::log1p,std::log1p,0.0L); 2*: 34: GCEM_TEST_COMPARE_VALS(gcem::log1p,std::log1p,1e-04L); 2*: 35: GCEM_TEST_COMPARE_VALS(gcem::log1p,std::log1p,-1e-04L); 2*: 36: GCEM_TEST_COMPARE_VALS(gcem::log1p,std::log1p,1e-05L); 2*: 37: GCEM_TEST_COMPARE_VALS(gcem::log1p,std::log1p,1e-06L); 2*: 38: GCEM_TEST_COMPARE_VALS(gcem::log1p,std::log1p,1e-22L); -: 39: 2*: 40: GCEM_TEST_COMPARE_VALS(gcem::log1p,std::log1p, -std::numeric_limits::infinity()); 2*: 41: GCEM_TEST_COMPARE_VALS(gcem::log1p,std::log1p, std::numeric_limits::infinity()); 2*: 42: GCEM_TEST_COMPARE_VALS(gcem::log1p,std::log1p, std::numeric_limits::quiet_NaN()); -: 43: -: 44: // -: 45: 1: 46: print_final("log1p"); -: 47: 1: 48: return 0; -: 49:} <<<<<< EOF # path=tests/log2.cpp.gcov -: 0:Source:log2.cpp -: 0:Graph:./log2.gcno -: 0:Data:./log2.gcda -: 0:Runs:1 -: 1:/*################################################################################ -: 2: ## -: 3: ## Copyright (C) 2016-2022 Keith O'Hara -: 4: ## -: 5: ## This file is part of the GCE-Math C++ library. -: 6: ## -: 7: ## Licensed under the Apache License, Version 2.0 (the "License"); -: 8: ## you may not use this file except in compliance with the License. -: 9: ## You may obtain a copy of the License at -: 10: ## -: 11: ## http://www.apache.org/licenses/LICENSE-2.0 -: 12: ## -: 13: ## Unless required by applicable law or agreed to in writing, software -: 14: ## distributed under the License is distributed on an "AS IS" BASIS, -: 15: ## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -: 16: ## See the License for the specific language governing permissions and -: 17: ## limitations under the License. -: 18: ## -: 19: ################################################################################*/ -: 20: -: 21:#define TEST_PRINT_PRECISION_1 6 -: 22:#define TEST_PRINT_PRECISION_2 18 -: 23: -: 24:#include "gcem_tests.hpp" -: 25: 1: 26:int main() -: 27:{ 1: 28: print_begin("log2"); -: 29: -: 30: // -: 31: 2*: 32: GCEM_TEST_COMPARE_VALS(gcem::log2, std::log2, 0.5L); 2*: 33: GCEM_TEST_COMPARE_VALS(gcem::log2, std::log2, 0.00199900000000000208L); 2*: 34: GCEM_TEST_COMPARE_VALS(gcem::log2, std::log2, 1.5L); 2*: 35: GCEM_TEST_COMPARE_VALS(gcem::log2, std::log2, 41.5L); 2*: 36: GCEM_TEST_COMPARE_VALS(gcem::log2, std::log2, 0.0L); 2*: 37: GCEM_TEST_COMPARE_VALS(gcem::log2, std::log2, -1.0L); 2*: 38: GCEM_TEST_COMPARE_VALS(gcem::log2,std::log2, 1e-500L); 2*: 39: GCEM_TEST_COMPARE_VALS(gcem::log2,std::log2, std::numeric_limits::min()); -: 40: 2*: 41: GCEM_TEST_COMPARE_VALS(gcem::log2, std::log2, -std::numeric_limits::infinity()); 2*: 42: GCEM_TEST_COMPARE_VALS(gcem::log2, std::log2, std::numeric_limits::infinity()); 2*: 43: GCEM_TEST_COMPARE_VALS(gcem::log2, std::log2, std::numeric_limits::quiet_NaN()); -: 44: -: 45: // -: 46: 1: 47: print_final("log2"); -: 48: 1: 49: return 0; -: 50:} <<<<<< EOF # path=tests/log2.hpp.gcov -: 0:Source:../include/gcem_incl/log2.hpp -: 0:Graph:./log2.gcno -: 0:Data:./log2.gcda -: 0:Runs:1 -: 1:/*################################################################################ -: 2: ## -: 3: ## Copyright (C) 2016-2022 Keith O'Hara -: 4: ## -: 5: ## This file is part of the GCE-Math C++ library. -: 6: ## -: 7: ## Licensed under the Apache License, Version 2.0 (the "License"); -: 8: ## you may not use this file except in compliance with the License. -: 9: ## You may obtain a copy of the License at -: 10: ## -: 11: ## http://www.apache.org/licenses/LICENSE-2.0 -: 12: ## -: 13: ## Unless required by applicable law or agreed to in writing, software -: 14: ## distributed under the License is distributed on an "AS IS" BASIS, -: 15: ## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -: 16: ## See the License for the specific language governing permissions and -: 17: ## limitations under the License. -: 18: ## -: 19: ################################################################################*/ -: 20: -: 21:/* -: 22: * compile-time binary logarithm function -: 23: */ -: 24: -: 25:#ifndef _gcem_log2_HPP -: 26:#define _gcem_log2_HPP -: 27: -: 28:namespace internal -: 29:{ -: 30: -: 31:template -: 32:constexpr -: 33:return_t 1: 34:log2_check(const T x) -: 35:noexcept -: 36:{ -: 37: // log_2(x) = ln(x) / ln(2) 1: 38: return return_t(log(x) / GCEM_LOG_2); -: 39:} -: 40: -: 41:} -: 42: -: 43:/** -: 44: * Compile-time binary logarithm function -: 45: * -: 46: * @param x a real-valued input. -: 47: * @return \f$ \log_2(x) \f$ using \f[ \log_{2}(x) = \frac{\log_e(x)}{\log_e(2)} \f] -: 48: */ -: 49: -: 50:template -: 51:constexpr -: 52:return_t 1: 53:log2(const T x) -: 54:noexcept -: 55:{ 1: 56: return internal::log2_check( x ); -: 57:} -: 58: -: 59:#endif <<<<<< EOF # path=tests/log_binomial_coef.cpp.gcov -: 0:Source:log_binomial_coef.cpp -: 0:Graph:./log_binomial_coef.gcno -: 0:Data:./log_binomial_coef.gcda -: 0:Runs:1 -: 1:/*################################################################################ -: 2: ## -: 3: ## Copyright (C) 2016-2022 Keith O'Hara -: 4: ## -: 5: ## This file is part of the GCE-Math C++ library. -: 6: ## -: 7: ## Licensed under the Apache License, Version 2.0 (the "License"); -: 8: ## you may not use this file except in compliance with the License. -: 9: ## You may obtain a copy of the License at -: 10: ## -: 11: ## http://www.apache.org/licenses/LICENSE-2.0 -: 12: ## -: 13: ## Unless required by applicable law or agreed to in writing, software -: 14: ## distributed under the License is distributed on an "AS IS" BASIS, -: 15: ## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -: 16: ## See the License for the specific language governing permissions and -: 17: ## limitations under the License. -: 18: ## -: 19: ################################################################################*/ -: 20: -: 21:#include "gcem_tests.hpp" -: 22: 1: 23:int main() -: 24:{ 1: 25: print_begin("log_binomial_coef"); -: 26: -: 27: // -: 28: 2*: 29: GCEM_TEST_EXPECTED_VAL(gcem::log_binomial_coef, 0, 0, 0); 2*: 30: GCEM_TEST_EXPECTED_VAL(gcem::log_binomial_coef, TEST_NEGINF, 0, 1); 2*: 31: GCEM_TEST_EXPECTED_VAL(gcem::log_binomial_coef, 0, 1, 0); 2*: 32: GCEM_TEST_EXPECTED_VAL(gcem::log_binomial_coef, 0, 1, 1); 2*: 33: GCEM_TEST_EXPECTED_VAL(gcem::log_binomial_coef, std::log(10.0L), 5, 2); 2*: 34: GCEM_TEST_EXPECTED_VAL(gcem::log_binomial_coef, std::log(45.0L), 10, 8); 2*: 35: GCEM_TEST_EXPECTED_VAL(gcem::log_binomial_coef, std::log(10.0L), 10, 9); 2*: 36: GCEM_TEST_EXPECTED_VAL(gcem::log_binomial_coef, 0, 10, 10); -: 37: -: 38: // -: 39: 1: 40: print_final("log_binomial_coef"); -: 41: 1: 42: return 0; -: 43:} <<<<<< EOF # path=tests/mantissa.hpp.gcov -: 0:Source:../include/gcem_incl/mantissa.hpp -: 0:Graph:log.gcno -: 0:Data:log.gcda -: 0:Runs:2 -: 1:/*################################################################################ -: 2: ## -: 3: ## Copyright (C) 2016-2022 Keith O'Hara -: 4: ## -: 5: ## This file is part of the GCE-Math C++ library. -: 6: ## -: 7: ## Licensed under the Apache License, Version 2.0 (the "License"); -: 8: ## you may not use this file except in compliance with the License. -: 9: ## You may obtain a copy of the License at -: 10: ## -: 11: ## http://www.apache.org/licenses/LICENSE-2.0 -: 12: ## -: 13: ## Unless required by applicable law or agreed to in writing, software -: 14: ## distributed under the License is distributed on an "AS IS" BASIS, -: 15: ## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -: 16: ## See the License for the specific language governing permissions and -: 17: ## limitations under the License. -: 18: ## -: 19: ################################################################################*/ -: 20: -: 21:/* -: 22: * compile-time mantissa function -: 23: */ -: 24: -: 25:#ifndef _gcem_mantissa_HPP -: 26:#define _gcem_mantissa_HPP -: 27: -: 28:namespace internal -: 29:{ -: 30: -: 31:template -: 32:constexpr -: 33:T 9866: 34:mantissa(const T x) -: 35:noexcept -: 36:{ 9868: 37: return( x < T(1) ? \ 9864: 38: mantissa(x*T(10)) : 2: 39: x > T(10) ? \ #####: 40: mantissa(x/T(10)) : -: 41: // else 9866: 42: x ); -: 43:} -: 44: -: 45:} -: 46: -: 47:#endif <<<<<< EOF # path=tests/max.hpp.gcov -: 0:Source:../include/gcem_incl/max.hpp -: 0:Graph:./incomplete_gamma_inv.gcno -: 0:Data:./incomplete_gamma_inv.gcda -: 0:Runs:1 -: 1:/*################################################################################ -: 2: ## -: 3: ## Copyright (C) 2016-2022 Keith O'Hara -: 4: ## -: 5: ## This file is part of the GCE-Math C++ library. -: 6: ## -: 7: ## Licensed under the Apache License, Version 2.0 (the "License"); -: 8: ## you may not use this file except in compliance with the License. -: 9: ## You may obtain a copy of the License at -: 10: ## -: 11: ## http://www.apache.org/licenses/LICENSE-2.0 -: 12: ## -: 13: ## Unless required by applicable law or agreed to in writing, software -: 14: ## distributed under the License is distributed on an "AS IS" BASIS, -: 15: ## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -: 16: ## See the License for the specific language governing permissions and -: 17: ## limitations under the License. -: 18: ## -: 19: ################################################################################*/ -: 20: -: 21:#ifndef _gcem_max_HPP -: 22:#define _gcem_max_HPP -: 23: -: 24:/** -: 25: * Compile-time pairwise maximum function -: 26: * -: 27: * @param x a real-valued input. -: 28: * @param y a real-valued input. -: 29: * @return Computes the maximum between \c x and \c y, where \c x and \c y have the same type (e.g., \c int, \c double, etc.) -: 30: */ -: 31: -: 32:template -: 33:constexpr -: 34:common_t 1168: 35:max(const T1 x, const T2 y) -: 36:noexcept -: 37:{ 1168: 38: return( y < x ? x : y ); -: 39:} -: 40: -: 41:#endif <<<<<< EOF # path=tests/min.hpp.gcov -: 0:Source:../include/gcem_incl/min.hpp -: 0:Graph:./incomplete_gamma_inv.gcno -: 0:Data:./incomplete_gamma_inv.gcda -: 0:Runs:1 -: 1:/*################################################################################ -: 2: ## -: 3: ## Copyright (C) 2016-2022 Keith O'Hara -: 4: ## -: 5: ## This file is part of the GCE-Math C++ library. -: 6: ## -: 7: ## Licensed under the Apache License, Version 2.0 (the "License"); -: 8: ## you may not use this file except in compliance with the License. -: 9: ## You may obtain a copy of the License at -: 10: ## -: 11: ## http://www.apache.org/licenses/LICENSE-2.0 -: 12: ## -: 13: ## Unless required by applicable law or agreed to in writing, software -: 14: ## distributed under the License is distributed on an "AS IS" BASIS, -: 15: ## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -: 16: ## See the License for the specific language governing permissions and -: 17: ## limitations under the License. -: 18: ## -: 19: ################################################################################*/ -: 20: -: 21:#ifndef _gcem_min_HPP -: 22:#define _gcem_min_HPP -: 23: -: 24:/** -: 25: * Compile-time pairwise minimum function -: 26: * -: 27: * @param x a real-valued input. -: 28: * @param y a real-valued input. -: 29: * @return Computes the minimum between \c x and \c y, where \c x and \c y have the same type (e.g., \c int, \c double, etc.) -: 30: */ -: 31: -: 32:template -: 33:constexpr -: 34:common_t 1728: 35:min(const T1 x, const T2 y) -: 36:noexcept -: 37:{ 1728: 38: return( y > x ? x : y ); -: 39:} -: 40: -: 41:#endif <<<<<< EOF # path=tests/move.h.gcov -: 0:Source:/usr/include/c++/9/bits/move.h -: 0:Graph:log.gcno -: 0:Data:log.gcda -: 0:Runs:2 -: 1:// Move, forward and identity for C++11 + swap -*- C++ -*- -: 2: -: 3:// Copyright (C) 2007-2019 Free Software Foundation, Inc. -: 4:// -: 5:// This file is part of the GNU ISO C++ Library. This library is free -: 6:// software; you can redistribute it and/or modify it under the -: 7:// terms of the GNU General Public License as published by the -: 8:// Free Software Foundation; either version 3, or (at your option) -: 9:// any later version. -: 10: -: 11:// This library is distributed in the hope that it will be useful, -: 12:// but WITHOUT ANY WARRANTY; without even the implied warranty of -: 13:// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -: 14:// GNU General Public License for more details. -: 15: -: 16:// Under Section 7 of GPL version 3, you are granted additional -: 17:// permissions described in the GCC Runtime Library Exception, version -: 18:// 3.1, as published by the Free Software Foundation. -: 19: -: 20:// You should have received a copy of the GNU General Public License and -: 21:// a copy of the GCC Runtime Library Exception along with this program; -: 22:// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see -: 23:// . -: 24: -: 25:/** @file bits/move.h -: 26: * This is an internal header file, included by other library headers. -: 27: * Do not attempt to use it directly. @headername{utility} -: 28: */ -: 29: -: 30:#ifndef _MOVE_H -: 31:#define _MOVE_H 1 -: 32: -: 33:#include -: 34:#include -: 35: -: 36:namespace std _GLIBCXX_VISIBILITY(default) -: 37:{ -: 38:_GLIBCXX_BEGIN_NAMESPACE_VERSION -: 39: -: 40: // Used, in C++03 mode too, by allocators, etc. -: 41: /** -: 42: * @brief Same as C++11 std::addressof -: 43: * @ingroup utilities -: 44: */ -: 45: template -: 46: inline _GLIBCXX_CONSTEXPR _Tp* -: 47: __addressof(_Tp& __r) _GLIBCXX_NOEXCEPT -: 48: { return __builtin_addressof(__r); } -: 49: -: 50:#if __cplusplus >= 201103L -: 51: -: 52:_GLIBCXX_END_NAMESPACE_VERSION -: 53:} // namespace -: 54: -: 55:#include // Brings in std::declval too. -: 56: -: 57:namespace std _GLIBCXX_VISIBILITY(default) -: 58:{ -: 59:_GLIBCXX_BEGIN_NAMESPACE_VERSION -: 60: -: 61: /** -: 62: * @addtogroup utilities -: 63: * @{ -: 64: */ -: 65: -: 66: /** -: 67: * @brief Forward an lvalue. -: 68: * @return The parameter cast to the specified type. -: 69: * -: 70: * This function is used to implement "perfect forwarding". -: 71: */ -: 72: template -: 73: constexpr _Tp&& -: 74: forward(typename std::remove_reference<_Tp>::type& __t) noexcept -: 75: { return static_cast<_Tp&&>(__t); } -: 76: -: 77: /** -: 78: * @brief Forward an rvalue. -: 79: * @return The parameter cast to the specified type. -: 80: * -: 81: * This function is used to implement "perfect forwarding". -: 82: */ -: 83: template -: 84: constexpr _Tp&& -: 85: forward(typename std::remove_reference<_Tp>::type&& __t) noexcept -: 86: { -: 87: static_assert(!std::is_lvalue_reference<_Tp>::value, "template argument" -: 88: " substituting _Tp is an lvalue reference type"); -: 89: return static_cast<_Tp&&>(__t); -: 90: } -: 91: -: 92: /** -: 93: * @brief Convert a value to an rvalue. -: 94: * @param __t A thing of arbitrary type. -: 95: * @return The parameter cast to an rvalue-reference to allow moving it. -: 96: */ -: 97: template -: 98: constexpr typename std::remove_reference<_Tp>::type&& #####: 99: move(_Tp&& __t) noexcept #####: 100: { return static_cast::type&&>(__t); } -: 101: -: 102: -: 103: template -: 104: struct __move_if_noexcept_cond -: 105: : public __and_<__not_>, -: 106: is_copy_constructible<_Tp>>::type { }; -: 107: -: 108: /** -: 109: * @brief Conditionally convert a value to an rvalue. -: 110: * @param __x A thing of arbitrary type. -: 111: * @return The parameter, possibly cast to an rvalue-reference. -: 112: * -: 113: * Same as std::move unless the type's move constructor could throw and the -: 114: * type is copyable, in which case an lvalue-reference is returned instead. -: 115: */ -: 116: template -: 117: constexpr typename -: 118: conditional<__move_if_noexcept_cond<_Tp>::value, const _Tp&, _Tp&&>::type -: 119: move_if_noexcept(_Tp& __x) noexcept -: 120: { return std::move(__x); } -: 121: -: 122: // declval, from type_traits. -: 123: -: 124:#if __cplusplus > 201402L -: 125: // _GLIBCXX_RESOLVE_LIB_DEFECTS -: 126: // 2296. std::addressof should be constexpr -: 127:# define __cpp_lib_addressof_constexpr 201603 -: 128:#endif -: 129: /** -: 130: * @brief Returns the actual address of the object or function -: 131: * referenced by r, even in the presence of an overloaded -: 132: * operator&. -: 133: * @param __r Reference to an object or function. -: 134: * @return The actual address. -: 135: */ -: 136: template -: 137: inline _GLIBCXX17_CONSTEXPR _Tp* -: 138: addressof(_Tp& __r) noexcept -: 139: { return std::__addressof(__r); } -: 140: -: 141: // _GLIBCXX_RESOLVE_LIB_DEFECTS -: 142: // 2598. addressof works on temporaries -: 143: template -: 144: const _Tp* addressof(const _Tp&&) = delete; -: 145: -: 146: // C++11 version of std::exchange for internal use. -: 147: template -: 148: inline _Tp -: 149: __exchange(_Tp& __obj, _Up&& __new_val) -: 150: { -: 151: _Tp __old_val = std::move(__obj); -: 152: __obj = std::forward<_Up>(__new_val); -: 153: return __old_val; -: 154: } -: 155: -: 156: /// @} group utilities -: 157: -: 158:#define _GLIBCXX_MOVE(__val) std::move(__val) -: 159:#define _GLIBCXX_FORWARD(_Tp, __val) std::forward<_Tp>(__val) -: 160:#else -: 161:#define _GLIBCXX_MOVE(__val) (__val) -: 162:#define _GLIBCXX_FORWARD(_Tp, __val) (__val) -: 163:#endif -: 164: -: 165: /** -: 166: * @addtogroup utilities -: 167: * @{ -: 168: */ -: 169: -: 170: /** -: 171: * @brief Swaps two values. -: 172: * @param __a A thing of arbitrary type. -: 173: * @param __b Another thing of arbitrary type. -: 174: * @return Nothing. -: 175: */ -: 176: template -: 177: inline -: 178:#if __cplusplus >= 201103L -: 179: typename enable_if<__and_<__not_<__is_tuple_like<_Tp>>, -: 180: is_move_constructible<_Tp>, -: 181: is_move_assignable<_Tp>>::value>::type -: 182: swap(_Tp& __a, _Tp& __b) -: 183: noexcept(__and_, -: 184: is_nothrow_move_assignable<_Tp>>::value) -: 185:#else -: 186: void -: 187: swap(_Tp& __a, _Tp& __b) -: 188:#endif -: 189: { -: 190: // concept requirements -: 191: __glibcxx_function_requires(_SGIAssignableConcept<_Tp>) -: 192: -: 193: _Tp __tmp = _GLIBCXX_MOVE(__a); -: 194: __a = _GLIBCXX_MOVE(__b); -: 195: __b = _GLIBCXX_MOVE(__tmp); -: 196: } -: 197: -: 198: // _GLIBCXX_RESOLVE_LIB_DEFECTS -: 199: // DR 809. std::swap should be overloaded for array types. -: 200: /// Swap the contents of two arrays. -: 201: template -: 202: inline -: 203:#if __cplusplus >= 201103L -: 204: typename enable_if<__is_swappable<_Tp>::value>::type -: 205: swap(_Tp (&__a)[_Nm], _Tp (&__b)[_Nm]) -: 206: noexcept(__is_nothrow_swappable<_Tp>::value) -: 207:#else -: 208: void -: 209: swap(_Tp (&__a)[_Nm], _Tp (&__b)[_Nm]) -: 210:#endif -: 211: { -: 212: for (size_t __n = 0; __n < _Nm; ++__n) -: 213: swap(__a[__n], __b[__n]); -: 214: } -: 215: -: 216: /// @} group utilities -: 217:_GLIBCXX_END_NAMESPACE_VERSION -: 218:} // namespace -: 219: -: 220:#endif /* _MOVE_H */ <<<<<< EOF # path=tests/new.gcov -: 0:Source:/usr/include/c++/9/new -: 0:Graph:./factorial.gcno -: 0:Data:./factorial.gcda -: 0:Runs:1 -: 1:// The -*- C++ -*- dynamic memory management header. -: 2: -: 3:// Copyright (C) 1994-2019 Free Software Foundation, Inc. -: 4: -: 5:// This file is part of GCC. -: 6:// -: 7:// GCC is free software; you can redistribute it and/or modify -: 8:// it under the terms of the GNU General Public License as published by -: 9:// the Free Software Foundation; either version 3, or (at your option) -: 10:// any later version. -: 11:// -: 12:// GCC is distributed in the hope that it will be useful, -: 13:// but WITHOUT ANY WARRANTY; without even the implied warranty of -: 14:// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -: 15:// GNU General Public License for more details. -: 16:// -: 17:// Under Section 7 of GPL version 3, you are granted additional -: 18:// permissions described in the GCC Runtime Library Exception, version -: 19:// 3.1, as published by the Free Software Foundation. -: 20: -: 21:// You should have received a copy of the GNU General Public License and -: 22:// a copy of the GCC Runtime Library Exception along with this program; -: 23:// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see -: 24:// . -: 25: -: 26:/** @file new -: 27: * This is a Standard C++ Library header. -: 28: * -: 29: * The header @c new defines several functions to manage dynamic memory and -: 30: * handling memory allocation errors; see -: 31: * http://gcc.gnu.org/onlinedocs/libstdc++/18_support/howto.html#4 for more. -: 32: */ -: 33: -: 34:#ifndef _NEW -: 35:#define _NEW -: 36: -: 37:#pragma GCC system_header -: 38: -: 39:#include -: 40:#include -: 41: -: 42:#pragma GCC visibility push(default) -: 43: -: 44:extern "C++" { -: 45: -: 46:namespace std -: 47:{ -: 48: /** -: 49: * @brief Exception possibly thrown by @c new. -: 50: * @ingroup exceptions -: 51: * -: 52: * @c bad_alloc (or classes derived from it) is used to report allocation -: 53: * errors from the throwing forms of @c new. */ -: 54: class bad_alloc : public exception -: 55: { -: 56: public: -: 57: bad_alloc() throw() { } -: 58: -: 59:#if __cplusplus >= 201103L -: 60: bad_alloc(const bad_alloc&) = default; -: 61: bad_alloc& operator=(const bad_alloc&) = default; -: 62:#endif -: 63: -: 64: // This declaration is not useless: -: 65: // http://gcc.gnu.org/onlinedocs/gcc-3.0.2/gcc_6.html#SEC118 -: 66: virtual ~bad_alloc() throw(); -: 67: -: 68: // See comment in eh_exception.cc. -: 69: virtual const char* what() const throw(); -: 70: }; -: 71: -: 72:#if __cplusplus >= 201103L -: 73: class bad_array_new_length : public bad_alloc -: 74: { -: 75: public: -: 76: bad_array_new_length() throw() { } -: 77: -: 78: // This declaration is not useless: -: 79: // http://gcc.gnu.org/onlinedocs/gcc-3.0.2/gcc_6.html#SEC118 -: 80: virtual ~bad_array_new_length() throw(); -: 81: -: 82: // See comment in eh_exception.cc. -: 83: virtual const char* what() const throw(); -: 84: }; -: 85:#endif -: 86: -: 87:#if __cpp_aligned_new -: 88: enum class align_val_t: size_t {}; -: 89:#endif -: 90: -: 91: struct nothrow_t -: 92: { -: 93:#if __cplusplus >= 201103L -: 94: explicit nothrow_t() = default; -: 95:#endif -: 96: }; -: 97: -: 98: extern const nothrow_t nothrow; -: 99: -: 100: /** If you write your own error handler to be called by @c new, it must -: 101: * be of this type. */ -: 102: typedef void (*new_handler)(); -: 103: -: 104: /// Takes a replacement handler as the argument, returns the -: 105: /// previous handler. -: 106: new_handler set_new_handler(new_handler) throw(); -: 107: -: 108:#if __cplusplus >= 201103L -: 109: /// Return the current new handler. -: 110: new_handler get_new_handler() noexcept; -: 111:#endif -: 112:} // namespace std -: 113: -: 114://@{ -: 115:/** These are replaceable signatures: -: 116: * - normal single new and delete (no arguments, throw @c bad_alloc on error) -: 117: * - normal array new and delete (same) -: 118: * - @c nothrow single new and delete (take a @c nothrow argument, return -: 119: * @c NULL on error) -: 120: * - @c nothrow array new and delete (same) -: 121: * -: 122: * Placement new and delete signatures (take a memory address argument, -: 123: * does nothing) may not be replaced by a user's program. -: 124:*/ -: 125:_GLIBCXX_NODISCARD void* operator new(std::size_t) _GLIBCXX_THROW (std::bad_alloc) -: 126: __attribute__((__externally_visible__)); -: 127:_GLIBCXX_NODISCARD void* operator new[](std::size_t) _GLIBCXX_THROW (std::bad_alloc) -: 128: __attribute__((__externally_visible__)); -: 129:void operator delete(void*) _GLIBCXX_USE_NOEXCEPT -: 130: __attribute__((__externally_visible__)); -: 131:void operator delete[](void*) _GLIBCXX_USE_NOEXCEPT -: 132: __attribute__((__externally_visible__)); -: 133:#if __cpp_sized_deallocation -: 134:void operator delete(void*, std::size_t) _GLIBCXX_USE_NOEXCEPT -: 135: __attribute__((__externally_visible__)); -: 136:void operator delete[](void*, std::size_t) _GLIBCXX_USE_NOEXCEPT -: 137: __attribute__((__externally_visible__)); -: 138:#endif -: 139:_GLIBCXX_NODISCARD void* operator new(std::size_t, const std::nothrow_t&) _GLIBCXX_USE_NOEXCEPT -: 140: __attribute__((__externally_visible__, __malloc__)); -: 141:_GLIBCXX_NODISCARD void* operator new[](std::size_t, const std::nothrow_t&) _GLIBCXX_USE_NOEXCEPT -: 142: __attribute__((__externally_visible__, __malloc__)); -: 143:void operator delete(void*, const std::nothrow_t&) _GLIBCXX_USE_NOEXCEPT -: 144: __attribute__((__externally_visible__)); -: 145:void operator delete[](void*, const std::nothrow_t&) _GLIBCXX_USE_NOEXCEPT -: 146: __attribute__((__externally_visible__)); -: 147:#if __cpp_aligned_new -: 148:_GLIBCXX_NODISCARD void* operator new(std::size_t, std::align_val_t) -: 149: __attribute__((__externally_visible__)); -: 150:_GLIBCXX_NODISCARD void* operator new(std::size_t, std::align_val_t, const std::nothrow_t&) -: 151: _GLIBCXX_USE_NOEXCEPT __attribute__((__externally_visible__, __malloc__)); -: 152:void operator delete(void*, std::align_val_t) -: 153: _GLIBCXX_USE_NOEXCEPT __attribute__((__externally_visible__)); -: 154:void operator delete(void*, std::align_val_t, const std::nothrow_t&) -: 155: _GLIBCXX_USE_NOEXCEPT __attribute__((__externally_visible__)); -: 156:_GLIBCXX_NODISCARD void* operator new[](std::size_t, std::align_val_t) -: 157: __attribute__((__externally_visible__)); -: 158:_GLIBCXX_NODISCARD void* operator new[](std::size_t, std::align_val_t, const std::nothrow_t&) -: 159: _GLIBCXX_USE_NOEXCEPT __attribute__((__externally_visible__, __malloc__)); -: 160:void operator delete[](void*, std::align_val_t) -: 161: _GLIBCXX_USE_NOEXCEPT __attribute__((__externally_visible__)); -: 162:void operator delete[](void*, std::align_val_t, const std::nothrow_t&) -: 163: _GLIBCXX_USE_NOEXCEPT __attribute__((__externally_visible__)); -: 164:#if __cpp_sized_deallocation -: 165:void operator delete(void*, std::size_t, std::align_val_t) -: 166: _GLIBCXX_USE_NOEXCEPT __attribute__((__externally_visible__)); -: 167:void operator delete[](void*, std::size_t, std::align_val_t) -: 168: _GLIBCXX_USE_NOEXCEPT __attribute__((__externally_visible__)); -: 169:#endif // __cpp_sized_deallocation -: 170:#endif // __cpp_aligned_new -: 171: -: 172:// Default placement versions of operator new. 1: 173:_GLIBCXX_NODISCARD inline void* operator new(std::size_t, void* __p) _GLIBCXX_USE_NOEXCEPT 1: 174:{ return __p; } -: 175:_GLIBCXX_NODISCARD inline void* operator new[](std::size_t, void* __p) _GLIBCXX_USE_NOEXCEPT -: 176:{ return __p; } -: 177: -: 178:// Default placement versions of operator delete. -: 179:inline void operator delete (void*, void*) _GLIBCXX_USE_NOEXCEPT { } -: 180:inline void operator delete[](void*, void*) _GLIBCXX_USE_NOEXCEPT { } -: 181://@} -: 182:} // extern "C++" -: 183: -: 184:#if __cplusplus >= 201703L -: 185:#ifdef _GLIBCXX_HAVE_BUILTIN_LAUNDER -: 186:namespace std -: 187:{ -: 188:#define __cpp_lib_launder 201606 -: 189: /// Pointer optimization barrier [ptr.launder] -: 190: template -: 191: [[nodiscard]] constexpr _Tp* -: 192: launder(_Tp* __p) noexcept -: 193: { return __builtin_launder(__p); } -: 194: -: 195: // The program is ill-formed if T is a function type or -: 196: // (possibly cv-qualified) void. -: 197: -: 198: template -: 199: void launder(_Ret (*)(_Args...) _GLIBCXX_NOEXCEPT_QUAL) = delete; -: 200: template -: 201: void launder(_Ret (*)(_Args......) _GLIBCXX_NOEXCEPT_QUAL) = delete; -: 202: -: 203: void launder(void*) = delete; -: 204: void launder(const void*) = delete; -: 205: void launder(volatile void*) = delete; -: 206: void launder(const volatile void*) = delete; -: 207:} -: 208:#endif // _GLIBCXX_HAVE_BUILTIN_LAUNDER -: 209:#endif // C++17 -: 210: -: 211:#if __cplusplus > 201703L -: 212:namespace std -: 213:{ -: 214: struct destroying_delete_t -: 215: { -: 216: explicit destroying_delete_t() = default; -: 217: }; -: 218: inline constexpr destroying_delete_t destroying_delete{}; -: 219:} -: 220:// Only define the feature test macro if the compiler supports the feature: -: 221:#if __cpp_impl_destroying_delete -: 222:# define __cpp_lib_destroying_delete 201806L -: 223:#endif -: 224:#endif // C++20 -: 225: -: 226:#pragma GCC visibility pop -: 227: -: 228:#endif <<<<<< EOF # path=tests/new_allocator.h.gcov -: 0:Source:/usr/include/c++/9/ext/new_allocator.h -: 0:Graph:log.gcno -: 0:Data:log.gcda -: 0:Runs:2 -: 1:// Allocator that wraps operator new -*- C++ -*- -: 2: -: 3:// Copyright (C) 2001-2019 Free Software Foundation, Inc. -: 4:// -: 5:// This file is part of the GNU ISO C++ Library. This library is free -: 6:// software; you can redistribute it and/or modify it under the -: 7:// terms of the GNU General Public License as published by the -: 8:// Free Software Foundation; either version 3, or (at your option) -: 9:// any later version. -: 10: -: 11:// This library is distributed in the hope that it will be useful, -: 12:// but WITHOUT ANY WARRANTY; without even the implied warranty of -: 13:// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -: 14:// GNU General Public License for more details. -: 15: -: 16:// Under Section 7 of GPL version 3, you are granted additional -: 17:// permissions described in the GCC Runtime Library Exception, version -: 18:// 3.1, as published by the Free Software Foundation. -: 19: -: 20:// You should have received a copy of the GNU General Public License and -: 21:// a copy of the GCC Runtime Library Exception along with this program; -: 22:// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see -: 23:// . -: 24: -: 25:/** @file ext/new_allocator.h -: 26: * This file is a GNU extension to the Standard C++ Library. -: 27: */ -: 28: -: 29:#ifndef _NEW_ALLOCATOR_H -: 30:#define _NEW_ALLOCATOR_H 1 -: 31: -: 32:#include -: 33:#include -: 34:#include -: 35:#include -: 36:#if __cplusplus >= 201103L -: 37:#include -: 38:#endif -: 39: -: 40:namespace __gnu_cxx _GLIBCXX_VISIBILITY(default) -: 41:{ -: 42:_GLIBCXX_BEGIN_NAMESPACE_VERSION -: 43: -: 44: using std::size_t; -: 45: using std::ptrdiff_t; -: 46: -: 47: /** -: 48: * @brief An allocator that uses global new, as per [20.4]. -: 49: * @ingroup allocators -: 50: * -: 51: * This is precisely the allocator defined in the C++ Standard. -: 52: * - all allocation calls operator new -: 53: * - all deallocation calls operator delete -: 54: * -: 55: * @tparam _Tp Type of allocated object. -: 56: */ -: 57: template -: 58: class new_allocator -: 59: { -: 60: public: -: 61: typedef size_t size_type; -: 62: typedef ptrdiff_t difference_type; -: 63: typedef _Tp* pointer; -: 64: typedef const _Tp* const_pointer; -: 65: typedef _Tp& reference; -: 66: typedef const _Tp& const_reference; -: 67: typedef _Tp value_type; -: 68: -: 69: template -: 70: struct rebind -: 71: { typedef new_allocator<_Tp1> other; }; -: 72: -: 73:#if __cplusplus >= 201103L -: 74: // _GLIBCXX_RESOLVE_LIB_DEFECTS -: 75: // 2103. propagate_on_container_move_assignment -: 76: typedef std::true_type propagate_on_container_move_assignment; -: 77:#endif -: 78: -: 79: _GLIBCXX20_CONSTEXPR #####: 80: new_allocator() _GLIBCXX_USE_NOEXCEPT { } -: 81: -: 82: _GLIBCXX20_CONSTEXPR #####: 83: new_allocator(const new_allocator&) _GLIBCXX_USE_NOEXCEPT { } -: 84: -: 85: template -: 86: _GLIBCXX20_CONSTEXPR -: 87: new_allocator(const new_allocator<_Tp1>&) _GLIBCXX_USE_NOEXCEPT { } -: 88: #####: 89: ~new_allocator() _GLIBCXX_USE_NOEXCEPT { } -: 90: -: 91: pointer -: 92: address(reference __x) const _GLIBCXX_NOEXCEPT -: 93: { return std::__addressof(__x); } -: 94: -: 95: const_pointer -: 96: address(const_reference __x) const _GLIBCXX_NOEXCEPT -: 97: { return std::__addressof(__x); } -: 98: -: 99: // NB: __n is permitted to be 0. The C++ standard says nothing -: 100: // about what the return value is when __n == 0. -: 101: _GLIBCXX_NODISCARD pointer -: 102: allocate(size_type __n, const void* = static_cast(0)) -: 103: { -: 104: if (__n > this->max_size()) -: 105: std::__throw_bad_alloc(); -: 106: -: 107:#if __cpp_aligned_new -: 108: if (alignof(_Tp) > __STDCPP_DEFAULT_NEW_ALIGNMENT__) -: 109: { -: 110: std::align_val_t __al = std::align_val_t(alignof(_Tp)); -: 111: return static_cast<_Tp*>(::operator new(__n * sizeof(_Tp), __al)); -: 112: } -: 113:#endif -: 114: return static_cast<_Tp*>(::operator new(__n * sizeof(_Tp))); -: 115: } -: 116: -: 117: // __p is not permitted to be a null pointer. -: 118: void -: 119: deallocate(pointer __p, size_type) -: 120: { -: 121:#if __cpp_aligned_new -: 122: if (alignof(_Tp) > __STDCPP_DEFAULT_NEW_ALIGNMENT__) -: 123: { -: 124: ::operator delete(__p, std::align_val_t(alignof(_Tp))); -: 125: return; -: 126: } -: 127:#endif -: 128: ::operator delete(__p); -: 129: } -: 130: -: 131: size_type -: 132: max_size() const _GLIBCXX_USE_NOEXCEPT -: 133: { -: 134:#if __PTRDIFF_MAX__ < __SIZE_MAX__ -: 135: return size_t(__PTRDIFF_MAX__) / sizeof(_Tp); -: 136:#else -: 137: return size_t(-1) / sizeof(_Tp); -: 138:#endif -: 139: } -: 140: -: 141:#if __cplusplus >= 201103L -: 142: template -: 143: void -: 144: construct(_Up* __p, _Args&&... __args) -: 145: noexcept(std::is_nothrow_constructible<_Up, _Args...>::value) -: 146: { ::new((void *)__p) _Up(std::forward<_Args>(__args)...); } -: 147: -: 148: template -: 149: void -: 150: destroy(_Up* __p) -: 151: noexcept(std::is_nothrow_destructible<_Up>::value) -: 152: { __p->~_Up(); } -: 153:#else -: 154: // _GLIBCXX_RESOLVE_LIB_DEFECTS -: 155: // 402. wrong new expression in [some_] allocator::construct -: 156: void -: 157: construct(pointer __p, const _Tp& __val) -: 158: { ::new((void *)__p) _Tp(__val); } -: 159: -: 160: void -: 161: destroy(pointer __p) { __p->~_Tp(); } -: 162:#endif -: 163: -: 164: template -: 165: friend bool -: 166: operator==(const new_allocator&, const new_allocator<_Up>&) -: 167: _GLIBCXX_NOTHROW -: 168: { return true; } -: 169: -: 170: template -: 171: friend bool -: 172: operator!=(const new_allocator&, const new_allocator<_Up>&) -: 173: _GLIBCXX_NOTHROW -: 174: { return false; } -: 175: }; -: 176: -: 177:_GLIBCXX_END_NAMESPACE_VERSION -: 178:} // namespace -: 179: -: 180:#endif <<<<<< EOF # path=tests/other.cpp.gcov -: 0:Source:other.cpp -: 0:Graph:./other.gcno -: 0:Data:./other.gcda -: 0:Runs:1 -: 1:/*################################################################################ -: 2: ## -: 3: ## Copyright (C) 2016-2022 Keith O'Hara -: 4: ## -: 5: ## This file is part of the GCE-Math C++ library. -: 6: ## -: 7: ## Licensed under the Apache License, Version 2.0 (the "License"); -: 8: ## you may not use this file except in compliance with the License. -: 9: ## You may obtain a copy of the License at -: 10: ## -: 11: ## http://www.apache.org/licenses/LICENSE-2.0 -: 12: ## -: 13: ## Unless required by applicable law or agreed to in writing, software -: 14: ## distributed under the License is distributed on an "AS IS" BASIS, -: 15: ## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -: 16: ## See the License for the specific language governing permissions and -: 17: ## limitations under the License. -: 18: ## -: 19: ################################################################################*/ -: 20: -: 21:#include "gcem_tests.hpp" -: 22: -: 23:// test misc functions -: 24: 1: 25:int main() -: 26:{ -: 27: 2*: 28: GCEM_TEST_EXPECTED_VAL(gcem::sgn, 1, 1.5); 2*: 29: GCEM_TEST_EXPECTED_VAL(gcem::sgn, -1, -1.5); -: 30: 2*: 31: GCEM_TEST_EXPECTED_VAL(gcem::internal::find_fraction, -0.5, 1.5); 2*: 32: GCEM_TEST_EXPECTED_VAL(gcem::internal::find_fraction, 1.5, -1.5); -: 33: 2*: 34: GCEM_TEST_EXPECTED_VAL(gcem::internal::find_whole, 1, 1.5); 2*: 35: GCEM_TEST_EXPECTED_VAL(gcem::internal::find_whole, -3, -1.5); -: 36: 2*: 37: GCEM_TEST_EXPECTED_VAL(gcem::internal::neg_zero, 0, 0.0); 2*: 38: GCEM_TEST_EXPECTED_VAL(gcem::internal::neg_zero, 1, -0.0); -: 39: 1: 40: return 0; -: 41:} <<<<<< EOF # path=tests/pow.cpp.gcov -: 0:Source:pow.cpp -: 0:Graph:pow.gcno -: 0:Data:pow.gcda -: 0:Runs:2 -: 1:/*################################################################################ -: 2: ## -: 3: ## Copyright (C) 2016-2022 Keith O'Hara -: 4: ## -: 5: ## This file is part of the GCE-Math C++ library. -: 6: ## -: 7: ## Licensed under the Apache License, Version 2.0 (the "License"); -: 8: ## you may not use this file except in compliance with the License. -: 9: ## You may obtain a copy of the License at -: 10: ## -: 11: ## http://www.apache.org/licenses/LICENSE-2.0 -: 12: ## -: 13: ## Unless required by applicable law or agreed to in writing, software -: 14: ## distributed under the License is distributed on an "AS IS" BASIS, -: 15: ## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -: 16: ## See the License for the specific language governing permissions and -: 17: ## limitations under the License. -: 18: ## -: 19: ################################################################################*/ -: 20: -: 21:#define TEST_PRINT_PRECISION_1 5 -: 22:#define TEST_PRINT_PRECISION_2 18 -: 23: -: 24:#include "gcem_tests.hpp" -: 25: 2: 26:int main() -: 27:{ 2: 28: print_begin("pow"); -: 29: -: 30: // -: 31: 4*: 32: GCEM_TEST_COMPARE_VALS(gcem::pow,std::pow, 0.199900000000000208L, 3.5L); 4*: 33: GCEM_TEST_COMPARE_VALS(gcem::pow,std::pow, 0.5L, 2.0L); 4*: 34: GCEM_TEST_COMPARE_VALS(gcem::pow,std::pow, 1.5L, 0.99L); 4*: 35: GCEM_TEST_COMPARE_VALS(gcem::pow,std::pow, 2.0L, 1.0L); 4*: 36: GCEM_TEST_COMPARE_VALS(gcem::pow,std::pow, 41.5L, 7.0L); -: 37: -: 38: // int versions 4*: 39: GCEM_TEST_COMPARE_VALS(gcem::pow,std::pow, 0.5L, 2L); 4*: 40: GCEM_TEST_COMPARE_VALS(gcem::pow,std::pow, 41.5L, 7L); -: 41: 4*: 42: GCEM_TEST_COMPARE_VALS(gcem::pow,std::pow, std::numeric_limits::quiet_NaN(), 2); 4*: 43: GCEM_TEST_COMPARE_VALS(gcem::pow,std::pow, 2, std::numeric_limits::quiet_NaN()); -: 44: 4*: 45: GCEM_TEST_COMPARE_VALS(gcem::pow,std::pow, std::numeric_limits::infinity(), 2); 4*: 46: GCEM_TEST_COMPARE_VALS(gcem::pow,std::pow, std::numeric_limits::infinity(), - 2); 4*: 47: GCEM_TEST_COMPARE_VALS(gcem::pow,std::pow, std::numeric_limits::infinity(), 0); -: 48: -: 49: // -: 50: 2: 51: print_final("pow"); -: 52: 2: 53: return 0; -: 54:} <<<<<< EOF # path=tests/pow.hpp.gcov -: 0:Source:../include/gcem_incl/pow.hpp -: 0:Graph:./incomplete_gamma_inv.gcno -: 0:Data:./incomplete_gamma_inv.gcda -: 0:Runs:1 -: 1:/*################################################################################ -: 2: ## -: 3: ## Copyright (C) 2016-2022 Keith O'Hara -: 4: ## -: 5: ## This file is part of the GCE-Math C++ library. -: 6: ## -: 7: ## Licensed under the Apache License, Version 2.0 (the "License"); -: 8: ## you may not use this file except in compliance with the License. -: 9: ## You may obtain a copy of the License at -: 10: ## -: 11: ## http://www.apache.org/licenses/LICENSE-2.0 -: 12: ## -: 13: ## Unless required by applicable law or agreed to in writing, software -: 14: ## distributed under the License is distributed on an "AS IS" BASIS, -: 15: ## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -: 16: ## See the License for the specific language governing permissions and -: 17: ## limitations under the License. -: 18: ## -: 19: ################################################################################*/ -: 20: -: 21:/* -: 22: * compile-time power function -: 23: */ -: 24: -: 25:#ifndef _gcem_pow_HPP -: 26:#define _gcem_pow_HPP -: 27: -: 28:namespace internal -: 29:{ -: 30: -: 31:template -: 32:constexpr -: 33:T #####: 34:pow_dbl(const T base, const T exp_term) -: 35:noexcept -: 36:{ #####: 37: return exp(exp_term*log(base)); -: 38:} -: 39: -: 40:template, -: 41: typename std::enable_if::value>::type* = nullptr> -: 42:constexpr -: 43:TC #####: 44:pow_check(const T1 base, const T2 exp_term) -: 45:noexcept -: 46:{ #####: 47: return( base < T1(0) ? \ #####: 48: GCLIM::quiet_NaN() : -: 49: // #####: 50: pow_dbl(static_cast(base),static_cast(exp_term)) ); -: 51:} -: 52: -: 53:template, -: 54: typename std::enable_if::value>::type* = nullptr> -: 55:constexpr -: 56:TC 16: 57:pow_check(const T1 base, const T2 exp_term) -: 58:noexcept -: 59:{ 16: 60: return pow_integral(base,exp_term); -: 61:} -: 62: -: 63:} -: 64: -: 65:/** -: 66: * Compile-time power function -: 67: * -: 68: * @param base a real-valued input. -: 69: * @param exp_term a real-valued input. -: 70: * @return Computes \c base raised to the power \c exp_term. In the case where \c exp_term is integral-valued, recursion by squaring is used, otherwise \f$ \text{base}^{\text{exp\_term}} = e^{\text{exp\_term} \log(\text{base})} \f$ -: 71: */ -: 72: -: 73:template -: 74:constexpr -: 75:common_t 16*: 76:pow(const T1 base, const T2 exp_term) -: 77:noexcept -: 78:{ 16*: 79: return internal::pow_check(base,exp_term); -: 80:} -: 81: -: 82:#endif <<<<<< EOF # path=tests/pow_integral.hpp.gcov -: 0:Source:../include/gcem_incl/pow_integral.hpp -: 0:Graph:./incomplete_gamma_inv.gcno -: 0:Data:./incomplete_gamma_inv.gcda -: 0:Runs:1 -: 1:/*################################################################################ -: 2: ## -: 3: ## Copyright (C) 2016-2022 Keith O'Hara -: 4: ## -: 5: ## This file is part of the GCE-Math C++ library. -: 6: ## -: 7: ## Licensed under the Apache License, Version 2.0 (the "License"); -: 8: ## you may not use this file except in compliance with the License. -: 9: ## You may obtain a copy of the License at -: 10: ## -: 11: ## http://www.apache.org/licenses/LICENSE-2.0 -: 12: ## -: 13: ## Unless required by applicable law or agreed to in writing, software -: 14: ## distributed under the License is distributed on an "AS IS" BASIS, -: 15: ## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -: 16: ## See the License for the specific language governing permissions and -: 17: ## limitations under the License. -: 18: ## -: 19: ################################################################################*/ -: 20: -: 21:/* -: 22: * compile-time power function -: 23: */ -: 24: -: 25:#ifndef _gcem_pow_integral_HPP -: 26:#define _gcem_pow_integral_HPP -: 27: -: 28:namespace internal -: 29:{ -: 30: -: 31:template -: 32:constexpr T1 pow_integral_compute(const T1 base, const T2 exp_term) noexcept; -: 33: -: 34:// integral-valued powers using method described in -: 35:// https://en.wikipedia.org/wiki/Exponentiation_by_squaring -: 36: -: 37:template -: 38:constexpr -: 39:T1 127368*: 40:pow_integral_compute_recur(const T1 base, const T1 val, const T2 exp_term) -: 41:noexcept -: 42:{ 254736*: 43: return( exp_term > T2(1) ? \ 99792*: 44: (is_odd(exp_term) ? \ 42772*: 45: pow_integral_compute_recur(base*base,val*base,exp_term/2) : 57020*: 46: pow_integral_compute_recur(base*base,val,exp_term/2)) : 154944*: 47: (exp_term == T2(1) ? val*base : val) ); -: 48:} ------------------ _ZN4gcem8internal26pow_integral_compute_recurIeiEET_S2_S2_T0_: #####: 40:pow_integral_compute_recur(const T1 base, const T1 val, const T2 exp_term) -: 41:noexcept -: 42:{ #####: 43: return( exp_term > T2(1) ? \ #####: 44: (is_odd(exp_term) ? \ #####: 45: pow_integral_compute_recur(base*base,val*base,exp_term/2) : #####: 46: pow_integral_compute_recur(base*base,val,exp_term/2)) : #####: 47: (exp_term == T2(1) ? val*base : val) ); -: 48:} ------------------ _ZN4gcem8internal26pow_integral_compute_recurIexEET_S2_S2_T0_: 127368: 40:pow_integral_compute_recur(const T1 base, const T1 val, const T2 exp_term) -: 41:noexcept -: 42:{ 254736: 43: return( exp_term > T2(1) ? \ 99792: 44: (is_odd(exp_term) ? \ 42772: 45: pow_integral_compute_recur(base*base,val*base,exp_term/2) : 57020: 46: pow_integral_compute_recur(base*base,val,exp_term/2)) : 154944*: 47: (exp_term == T2(1) ? val*base : val) ); -: 48:} ------------------ -: 49: -: 50:template::value>::type* = nullptr> -: 51:constexpr -: 52:T1 56952*: 53:pow_integral_sgn_check(const T1 base, const T2 exp_term) -: 54:noexcept -: 55:{ 86328*: 56: return( exp_term < T2(0) ? \ -: 57: // 29376*: 58: T1(1) / pow_integral_compute(base, - exp_term) : -: 59: // 56952*: 60: pow_integral_compute_recur(base,T1(1),exp_term) ); -: 61:} ------------------ _ZN4gcem8internal22pow_integral_sgn_checkIeiLPv0EEET_S3_T0_: #####: 53:pow_integral_sgn_check(const T1 base, const T2 exp_term) -: 54:noexcept -: 55:{ #####: 56: return( exp_term < T2(0) ? \ -: 57: // #####: 58: T1(1) / pow_integral_compute(base, - exp_term) : -: 59: // #####: 60: pow_integral_compute_recur(base,T1(1),exp_term) ); -: 61:} ------------------ _ZN4gcem8internal22pow_integral_sgn_checkIexLPv0EEET_S3_T0_: 56952: 53:pow_integral_sgn_check(const T1 base, const T2 exp_term) -: 54:noexcept -: 55:{ 86328: 56: return( exp_term < T2(0) ? \ -: 57: // 29376: 58: T1(1) / pow_integral_compute(base, - exp_term) : -: 59: // 56952: 60: pow_integral_compute_recur(base,T1(1),exp_term) ); -: 61:} ------------------ -: 62: -: 63:template::value>::type* = nullptr> -: 64:constexpr -: 65:T1 -: 66:pow_integral_sgn_check(const T1 base, const T2 exp_term) -: 67:noexcept -: 68:{ -: 69: return( pow_integral_compute_recur(base,T1(1),exp_term) ); -: 70:} -: 71: -: 72:template -: 73:constexpr -: 74:T1 58768: 75:pow_integral_compute(const T1 base, const T2 exp_term) -: 76:noexcept -: 77:{ 115720*: 78: return( exp_term == T2(3) ? \ 1816: 79: base*base*base : 113904*: 80: exp_term == T2(2) ? \ -: 81: base*base : 113904*: 82: exp_term == T2(1) ? \ -: 83: base : 113904*: 84: exp_term == T2(0) ? \ -: 85: T1(1) : -: 86: // check for overflow 113904*: 87: exp_term == GCLIM::min() ? \ -: 88: T1(0) : 56952*: 89: exp_term == GCLIM::max() ? \ #####: 90: GCLIM::infinity() : -: 91: // else 115720*: 92: pow_integral_sgn_check(base,exp_term) ); -: 93:} ------------------ _ZN4gcem8internal20pow_integral_computeIexEET_S2_T0_: 58752: 75:pow_integral_compute(const T1 base, const T2 exp_term) -: 76:noexcept -: 77:{ 115704: 78: return( exp_term == T2(3) ? \ 1800: 79: base*base*base : 113904*: 80: exp_term == T2(2) ? \ -: 81: base*base : 113904*: 82: exp_term == T2(1) ? \ -: 83: base : 113904*: 84: exp_term == T2(0) ? \ -: 85: T1(1) : -: 86: // check for overflow 113904*: 87: exp_term == GCLIM::min() ? \ -: 88: T1(0) : 56952: 89: exp_term == GCLIM::max() ? \ #####: 90: GCLIM::infinity() : -: 91: // else 115704: 92: pow_integral_sgn_check(base,exp_term) ); -: 93:} ------------------ _ZN4gcem8internal20pow_integral_computeIeiEET_S2_T0_: 16: 75:pow_integral_compute(const T1 base, const T2 exp_term) -: 76:noexcept -: 77:{ 16*: 78: return( exp_term == T2(3) ? \ 16: 79: base*base*base : #####: 80: exp_term == T2(2) ? \ -: 81: base*base : #####: 82: exp_term == T2(1) ? \ -: 83: base : #####: 84: exp_term == T2(0) ? \ -: 85: T1(1) : -: 86: // check for overflow #####: 87: exp_term == GCLIM::min() ? \ -: 88: T1(0) : #####: 89: exp_term == GCLIM::max() ? \ #####: 90: GCLIM::infinity() : -: 91: // else 16*: 92: pow_integral_sgn_check(base,exp_term) ); -: 93:} ------------------ -: 94: -: 95:template::value>::type* = nullptr> -: 96:constexpr -: 97:T1 29392: 98:pow_integral_type_check(const T1 base, const T2 exp_term) -: 99:noexcept -: 100:{ 29392: 101: return pow_integral_compute(base,exp_term); -: 102:} ------------------ _ZN4gcem8internal23pow_integral_type_checkIexLPv0EEET_S3_T0_: 29376: 98:pow_integral_type_check(const T1 base, const T2 exp_term) -: 99:noexcept -: 100:{ 29376: 101: return pow_integral_compute(base,exp_term); -: 102:} ------------------ _ZN4gcem8internal23pow_integral_type_checkIeiLPv0EEET_S3_T0_: 16: 98:pow_integral_type_check(const T1 base, const T2 exp_term) -: 99:noexcept -: 100:{ 16: 101: return pow_integral_compute(base,exp_term); -: 102:} ------------------ -: 103: -: 104:template::value>::type* = nullptr> -: 105:constexpr -: 106:T1 -: 107:pow_integral_type_check(const T1 base, const T2 exp_term) -: 108:noexcept -: 109:{ -: 110: // return GCLIM>::quiet_NaN(); -: 111: return pow_integral_compute(base,static_cast(exp_term)); -: 112:} -: 113: -: 114:// -: 115:// main function -: 116: -: 117:template -: 118:constexpr -: 119:T1 29392: 120:pow_integral(const T1 base, const T2 exp_term) -: 121:noexcept -: 122:{ 29392: 123: return internal::pow_integral_type_check(base,exp_term); -: 124:} -: 125: -: 126:} -: 127: -: 128:#endif <<<<<< EOF # path=tests/rounding.cpp.gcov -: 0:Source:rounding.cpp -: 0:Graph:./rounding.gcno -: 0:Data:./rounding.gcda -: 0:Runs:1 -: 1:/*################################################################################ -: 2: ## -: 3: ## Copyright (C) 2016-2022 Keith O'Hara -: 4: ## -: 5: ## This file is part of the GCE-Math C++ library. -: 6: ## -: 7: ## Licensed under the Apache License, Version 2.0 (the "License"); -: 8: ## you may not use this file except in compliance with the License. -: 9: ## You may obtain a copy of the License at -: 10: ## -: 11: ## http://www.apache.org/licenses/LICENSE-2.0 -: 12: ## -: 13: ## Unless required by applicable law or agreed to in writing, software -: 14: ## distributed under the License is distributed on an "AS IS" BASIS, -: 15: ## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -: 16: ## See the License for the specific language governing permissions and -: 17: ## limitations under the License. -: 18: ## -: 19: ################################################################################*/ -: 20: -: 21:#define TEST_PRINT_PRECISION_1 2 -: 22:#define TEST_PRINT_PRECISION_2 2 -: 23: -: 24:#include "gcem_tests.hpp" -: 25: 1: 26:int main() -: 27:{ 1: 28: print_begin("rounding"); -: 29: -: 30: // -: 31: 2*: 32: GCEM_TEST_COMPARE_VALS(gcem::floor,std::floor, 0.0); 2*: 33: GCEM_TEST_COMPARE_VALS(gcem::floor,std::floor, -0.0); 2*: 34: GCEM_TEST_COMPARE_VALS(gcem::floor,std::floor, 4.2); 2*: 35: GCEM_TEST_COMPARE_VALS(gcem::floor,std::floor, 4.5); 2*: 36: GCEM_TEST_COMPARE_VALS(gcem::floor,std::floor, 4.7); 2*: 37: GCEM_TEST_COMPARE_VALS(gcem::floor,std::floor, 5.0); 2*: 38: GCEM_TEST_COMPARE_VALS(gcem::floor,std::floor, -4.2); 2*: 39: GCEM_TEST_COMPARE_VALS(gcem::floor,std::floor, -4.7); 2*: 40: GCEM_TEST_COMPARE_VALS(gcem::floor,std::floor, -5.0); 2*: 41: GCEM_TEST_COMPARE_VALS(gcem::floor,std::floor, 42e32); 2*: 42: GCEM_TEST_COMPARE_VALS(gcem::floor,std::floor, -42e32); -: 43: 2*: 44: GCEM_TEST_COMPARE_VALS(gcem::floor,std::floor, std::numeric_limits::max()); 2*: 45: GCEM_TEST_COMPARE_VALS(gcem::floor,std::floor, -std::numeric_limits::infinity()); 2*: 46: GCEM_TEST_COMPARE_VALS(gcem::floor,std::floor, std::numeric_limits::infinity()); 2*: 47: GCEM_TEST_COMPARE_VALS(gcem::floor,std::floor, std::numeric_limits::quiet_NaN()); -: 48: -: 49: // -: 50: 2*: 51: GCEM_TEST_COMPARE_VALS(gcem::ceil,std::ceil, 0.0); 2*: 52: GCEM_TEST_COMPARE_VALS(gcem::ceil,std::ceil, -0.0); 2*: 53: GCEM_TEST_COMPARE_VALS(gcem::ceil,std::ceil, 4.2); 2*: 54: GCEM_TEST_COMPARE_VALS(gcem::ceil,std::ceil, 4.5); 2*: 55: GCEM_TEST_COMPARE_VALS(gcem::ceil,std::ceil, 4.7); 2*: 56: GCEM_TEST_COMPARE_VALS(gcem::ceil,std::ceil, 5.0); 2*: 57: GCEM_TEST_COMPARE_VALS(gcem::ceil,std::ceil, -4.2); 2*: 58: GCEM_TEST_COMPARE_VALS(gcem::ceil,std::ceil, -4.7); 2*: 59: GCEM_TEST_COMPARE_VALS(gcem::ceil,std::ceil, -5.0); 2*: 60: GCEM_TEST_COMPARE_VALS(gcem::ceil,std::ceil, 42e32); 2*: 61: GCEM_TEST_COMPARE_VALS(gcem::ceil,std::ceil, -42e32); -: 62: 2*: 63: GCEM_TEST_COMPARE_VALS(gcem::ceil,std::ceil, std::numeric_limits::max()); 2*: 64: GCEM_TEST_COMPARE_VALS(gcem::ceil,std::ceil, -std::numeric_limits::infinity()); 2*: 65: GCEM_TEST_COMPARE_VALS(gcem::ceil,std::ceil, std::numeric_limits::infinity()); 2*: 66: GCEM_TEST_COMPARE_VALS(gcem::ceil,std::ceil, std::numeric_limits::quiet_NaN()); -: 67: -: 68: // -: 69: 2*: 70: GCEM_TEST_COMPARE_VALS(gcem::trunc,std::trunc, 0.0); 2*: 71: GCEM_TEST_COMPARE_VALS(gcem::trunc,std::trunc, -0.0); 2*: 72: GCEM_TEST_COMPARE_VALS(gcem::trunc,std::trunc, 4.2); 2*: 73: GCEM_TEST_COMPARE_VALS(gcem::trunc,std::trunc, 4.5); 2*: 74: GCEM_TEST_COMPARE_VALS(gcem::trunc,std::trunc, 4.7); 2*: 75: GCEM_TEST_COMPARE_VALS(gcem::trunc,std::trunc, 5.0); 2*: 76: GCEM_TEST_COMPARE_VALS(gcem::trunc,std::trunc, -4.2); 2*: 77: GCEM_TEST_COMPARE_VALS(gcem::trunc,std::trunc, -4.7); 2*: 78: GCEM_TEST_COMPARE_VALS(gcem::trunc,std::trunc, -5.0); 2*: 79: GCEM_TEST_COMPARE_VALS(gcem::trunc,std::trunc, 42e32); 2*: 80: GCEM_TEST_COMPARE_VALS(gcem::trunc,std::trunc, -42e32); -: 81: 2*: 82: GCEM_TEST_COMPARE_VALS(gcem::trunc,std::trunc, std::numeric_limits::max()); 2*: 83: GCEM_TEST_COMPARE_VALS(gcem::trunc,std::trunc, -std::numeric_limits::infinity()); 2*: 84: GCEM_TEST_COMPARE_VALS(gcem::trunc,std::trunc, std::numeric_limits::infinity()); 2*: 85: GCEM_TEST_COMPARE_VALS(gcem::trunc,std::trunc, std::numeric_limits::quiet_NaN()); -: 86: -: 87: // -: 88: 2*: 89: GCEM_TEST_COMPARE_VALS(gcem::round,std::round, 0.0); 2*: 90: GCEM_TEST_COMPARE_VALS(gcem::round,std::round, -0.0); 2*: 91: GCEM_TEST_COMPARE_VALS(gcem::round,std::round, 4.2); 2*: 92: GCEM_TEST_COMPARE_VALS(gcem::round,std::round, 4.5); 2*: 93: GCEM_TEST_COMPARE_VALS(gcem::round,std::round, 4.7); 2*: 94: GCEM_TEST_COMPARE_VALS(gcem::round,std::round, 5.0); 2*: 95: GCEM_TEST_COMPARE_VALS(gcem::round,std::round, -4.2); 2*: 96: GCEM_TEST_COMPARE_VALS(gcem::round,std::round, -4.5); 2*: 97: GCEM_TEST_COMPARE_VALS(gcem::round,std::round, -4.7); 2*: 98: GCEM_TEST_COMPARE_VALS(gcem::round,std::round, -5.0); 2*: 99: GCEM_TEST_COMPARE_VALS(gcem::round,std::round, 42e32); 2*: 100: GCEM_TEST_COMPARE_VALS(gcem::round,std::round, -42e32); -: 101: 2*: 102: GCEM_TEST_COMPARE_VALS(gcem::round,std::round, std::numeric_limits::max()); 2*: 103: GCEM_TEST_COMPARE_VALS(gcem::round,std::round, -std::numeric_limits::infinity()); 2*: 104: GCEM_TEST_COMPARE_VALS(gcem::round,std::round, std::numeric_limits::infinity()); 2*: 105: GCEM_TEST_COMPARE_VALS(gcem::round,std::round, std::numeric_limits::quiet_NaN()); -: 106: -: 107: // -: 108: 1: 109: print_final("rounding"); -: 110: 1: 111: return 0; -: 112:} <<<<<< EOF # path=tests/sgn.hpp.gcov -: 0:Source:../include/gcem_incl/sgn.hpp -: 0:Graph:./incomplete_gamma_inv.gcno -: 0:Data:./incomplete_gamma_inv.gcda -: 0:Runs:1 -: 1:/*################################################################################ -: 2: ## -: 3: ## Copyright (C) 2016-2022 Keith O'Hara -: 4: ## -: 5: ## This file is part of the GCE-Math C++ library. -: 6: ## -: 7: ## Licensed under the Apache License, Version 2.0 (the "License"); -: 8: ## you may not use this file except in compliance with the License. -: 9: ## You may obtain a copy of the License at -: 10: ## -: 11: ## http://www.apache.org/licenses/LICENSE-2.0 -: 12: ## -: 13: ## Unless required by applicable law or agreed to in writing, software -: 14: ## distributed under the License is distributed on an "AS IS" BASIS, -: 15: ## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -: 16: ## See the License for the specific language governing permissions and -: 17: ## limitations under the License. -: 18: ## -: 19: ################################################################################*/ -: 20: -: 21:#ifndef _gcem_sgn_HPP -: 22:#define _gcem_sgn_HPP -: 23: -: 24:/** -: 25: * Compile-time sign function -: 26: * -: 27: * @param x a real-valued input -: 28: * @return a value \f$ y \f$ such that \f[ y = \begin{cases} 1 \ &\text{ if } x > 0 \\ 0 \ &\text{ if } x = 0 \\ -1 \ &\text{ if } x < 0 \end{cases} \f] -: 29: */ -: 30: -: 31:template -: 32:constexpr -: 33:int 150556: 34:sgn(const T x) -: 35:noexcept -: 36:{ -: 37: return( // positive 301112*: 38: x > T(0) ? 1 : -: 39: // negative 150556*: 40: x < T(0) ? -1 : -: 41: // else 150556: 42: 0 ); -: 43:} -: 44: -: 45:#endif <<<<<< EOF # path=tests/signbit.cpp.gcov -: 0:Source:signbit.cpp -: 0:Graph:./signbit.gcno -: 0:Data:./signbit.gcda -: 0:Runs:1 -: 1:/*################################################################################ -: 2: ## -: 3: ## Copyright (C) 2016-2022 Keith O'Hara -: 4: ## -: 5: ## This file is part of the GCE-Math C++ library. -: 6: ## -: 7: ## Licensed under the Apache License, Version 2.0 (the "License"); -: 8: ## you may not use this file except in compliance with the License. -: 9: ## You may obtain a copy of the License at -: 10: ## -: 11: ## http://www.apache.org/licenses/LICENSE-2.0 -: 12: ## -: 13: ## Unless required by applicable law or agreed to in writing, software -: 14: ## distributed under the License is distributed on an "AS IS" BASIS, -: 15: ## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -: 16: ## See the License for the specific language governing permissions and -: 17: ## limitations under the License. -: 18: ## -: 19: ################################################################################*/ -: 20: -: 21:#define TEST_PRINT_PRECISION_1 2 -: 22:#define TEST_PRINT_PRECISION_2 2 -: 23: -: 24:#include "gcem_tests.hpp" -: 25: -: 26:template -: 27:constexpr -: 28:int -: 29:std_test_fn(const T x) -: 30:{ -: 31: return static_cast(std::signbit(x)); -: 32:} -: 33: 1: 34:int main() -: 35:{ 1: 36: print_begin("signbit"); -: 37: -: 38: // -: 39: 2*: 40: GCEM_TEST_COMPARE_VALS(gcem::signbit,std_test_fn, 1.0); 2*: 41: GCEM_TEST_COMPARE_VALS(gcem::signbit,std_test_fn, -1.0); -: 42: 2*: 43: GCEM_TEST_COMPARE_VALS(gcem::signbit,std_test_fn, 0.0); 2*: 44: GCEM_TEST_COMPARE_VALS(gcem::signbit,std_test_fn, -0.0); -: 45: 2*: 46: GCEM_TEST_COMPARE_VALS(gcem::signbit,std_test_fn, TEST_POSINF); 2*: 47: GCEM_TEST_COMPARE_VALS(gcem::signbit,std_test_fn, TEST_NEGINF); 2*: 48: GCEM_TEST_COMPARE_VALS(gcem::signbit,std_test_fn, TEST_NAN); -: 49: -: 50: // -: 51: 1: 52: print_final("signbit"); -: 53: 1: 54: return 0; -: 55:} <<<<<< EOF # path=tests/sin.cpp.gcov -: 0:Source:sin.cpp -: 0:Graph:./sin.gcno -: 0:Data:./sin.gcda -: 0:Runs:1 -: 1:/*################################################################################ -: 2: ## -: 3: ## Copyright (C) 2016-2022 Keith O'Hara -: 4: ## -: 5: ## This file is part of the GCE-Math C++ library. -: 6: ## -: 7: ## Licensed under the Apache License, Version 2.0 (the "License"); -: 8: ## you may not use this file except in compliance with the License. -: 9: ## You may obtain a copy of the License at -: 10: ## -: 11: ## http://www.apache.org/licenses/LICENSE-2.0 -: 12: ## -: 13: ## Unless required by applicable law or agreed to in writing, software -: 14: ## distributed under the License is distributed on an "AS IS" BASIS, -: 15: ## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -: 16: ## See the License for the specific language governing permissions and -: 17: ## limitations under the License. -: 18: ## -: 19: ################################################################################*/ -: 20: -: 21:#define TEST_PRINT_PRECISION_1 3 -: 22:#define TEST_PRINT_PRECISION_2 18 -: 23: -: 24:#include "gcem_tests.hpp" -: 25: 1: 26:int main() -: 27:{ 1: 28: print_begin("sin"); -: 29: -: 30: // -: 31: 2*: 32: GCEM_TEST_COMPARE_VALS(gcem::sin,std::sin,-1.5L); 2*: 33: GCEM_TEST_COMPARE_VALS(gcem::sin,std::sin,0.0L); 2*: 34: GCEM_TEST_COMPARE_VALS(gcem::sin,std::sin,0.001L); 2*: 35: GCEM_TEST_COMPARE_VALS(gcem::sin,std::sin,1.001L); 2*: 36: GCEM_TEST_COMPARE_VALS(gcem::sin,std::sin,1.5L); 2*: 37: GCEM_TEST_COMPARE_VALS(gcem::sin,std::sin,11.1L); 2*: 38: GCEM_TEST_COMPARE_VALS(gcem::sin,std::sin,50.0L); 2*: 39: GCEM_TEST_COMPARE_VALS(gcem::sin,std::sin,150.0L); -: 40: 2*: 41: GCEM_TEST_COMPARE_VALS(gcem::sin,std::sin,TEST_NAN); -: 42: -: 43: // -: 44: 1: 45: print_final("sin"); -: 46: 1: 47: return 0; -: 48:} <<<<<< EOF # path=tests/sinh.cpp.gcov -: 0:Source:sinh.cpp -: 0:Graph:./sinh.gcno -: 0:Data:./sinh.gcda -: 0:Runs:1 -: 1:/*################################################################################ -: 2: ## -: 3: ## Copyright (C) 2016-2022 Keith O'Hara -: 4: ## -: 5: ## This file is part of the GCE-Math C++ library. -: 6: ## -: 7: ## Licensed under the Apache License, Version 2.0 (the "License"); -: 8: ## you may not use this file except in compliance with the License. -: 9: ## You may obtain a copy of the License at -: 10: ## -: 11: ## http://www.apache.org/licenses/LICENSE-2.0 -: 12: ## -: 13: ## Unless required by applicable law or agreed to in writing, software -: 14: ## distributed under the License is distributed on an "AS IS" BASIS, -: 15: ## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -: 16: ## See the License for the specific language governing permissions and -: 17: ## limitations under the License. -: 18: ## -: 19: ################################################################################*/ -: 20: -: 21:#define TEST_PRINT_PRECISION_1 6 -: 22:#define TEST_PRINT_PRECISION_2 18 -: 23: -: 24:#include "gcem_tests.hpp" -: 25: 1: 26:int main() -: 27:{ 1: 28: print_begin("sinh"); -: 29: -: 30: // -: 31: 2*: 32: GCEM_TEST_COMPARE_VALS(gcem::sinh,std::sinh,0.0L); 2*: 33: GCEM_TEST_COMPARE_VALS(gcem::sinh,std::sinh,0.001L); 2*: 34: GCEM_TEST_COMPARE_VALS(gcem::sinh,std::sinh,0.5L); 2*: 35: GCEM_TEST_COMPARE_VALS(gcem::sinh,std::sinh,-0.5L); 2*: 36: GCEM_TEST_COMPARE_VALS(gcem::sinh,std::sinh,0.7568025L); 2*: 37: GCEM_TEST_COMPARE_VALS(gcem::sinh,std::sinh,1.0L); 2*: 38: GCEM_TEST_COMPARE_VALS(gcem::sinh,std::sinh,5.0L); -: 39: 2*: 40: GCEM_TEST_COMPARE_VALS(gcem::sinh,std::sinh,TEST_NAN); -: 41: -: 42: // -: 43: 1: 44: print_final("sinh"); -: 45: 1: 46: return 0; -: 47:} <<<<<< EOF # path=tests/sqrt.cpp.gcov -: 0:Source:sqrt.cpp -: 0:Graph:./sqrt.gcno -: 0:Data:./sqrt.gcda -: 0:Runs:1 -: 1:/*################################################################################ -: 2: ## -: 3: ## Copyright (C) 2016-2022 Keith O'Hara -: 4: ## -: 5: ## This file is part of the GCE-Math C++ library. -: 6: ## -: 7: ## Licensed under the Apache License, Version 2.0 (the "License"); -: 8: ## you may not use this file except in compliance with the License. -: 9: ## You may obtain a copy of the License at -: 10: ## -: 11: ## http://www.apache.org/licenses/LICENSE-2.0 -: 12: ## -: 13: ## Unless required by applicable law or agreed to in writing, software -: 14: ## distributed under the License is distributed on an "AS IS" BASIS, -: 15: ## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -: 16: ## See the License for the specific language governing permissions and -: 17: ## limitations under the License. -: 18: ## -: 19: ################################################################################*/ -: 20: -: 21:// g++-mp-7 -O3 -Wall -std=c++11 -fconstexpr-depth=20 -fconstexpr-steps=1271242 -I./../include sqrt.cpp -o sqrt.test -framework Accelerate -: 22: -: 23:#define TEST_PRINT_PRECISION_1 6 -: 24:#define TEST_PRINT_PRECISION_2 18 -: 25: -: 26:#include "gcem_tests.hpp" -: 27: 1: 28:int main() -: 29:{ 1: 30: print_begin("sqrt"); -: 31: -: 32: // -: 33: 2*: 34: GCEM_TEST_COMPARE_VALS(gcem::sqrt,std::sqrt, 0.5L); 2*: 35: GCEM_TEST_COMPARE_VALS(gcem::sqrt,std::sqrt, 0.00199900000000000208L); 2*: 36: GCEM_TEST_COMPARE_VALS(gcem::sqrt,std::sqrt, 1.5L); 2*: 37: GCEM_TEST_COMPARE_VALS(gcem::sqrt,std::sqrt, 2.0L); 2*: 38: GCEM_TEST_COMPARE_VALS(gcem::sqrt,std::sqrt, 41.5L); 2*: 39: GCEM_TEST_COMPARE_VALS(gcem::sqrt,std::sqrt, 0.0L); 2*: 40: GCEM_TEST_COMPARE_VALS(gcem::sqrt,std::sqrt, -1.0L); -: 41: 2*: 42: GCEM_TEST_COMPARE_VALS(gcem::sqrt,std::sqrt, -std::numeric_limits::infinity()); 2*: 43: GCEM_TEST_COMPARE_VALS(gcem::sqrt,std::sqrt, std::numeric_limits::infinity()); 2*: 44: GCEM_TEST_COMPARE_VALS(gcem::sqrt,std::sqrt, std::numeric_limits::quiet_NaN()); -: 45: -: 46: // -: 47: 1: 48: print_final("sqrt"); -: 49: 1: 50: return 0; -: 51:} <<<<<< EOF # path=tests/sqrt.hpp.gcov -: 0:Source:../include/gcem_incl/sqrt.hpp -: 0:Graph:./incomplete_gamma_inv.gcno -: 0:Data:./incomplete_gamma_inv.gcda -: 0:Runs:1 -: 1:/*################################################################################ -: 2: ## -: 3: ## Copyright (C) 2016-2022 Keith O'Hara -: 4: ## -: 5: ## This file is part of the GCE-Math C++ library. -: 6: ## -: 7: ## Licensed under the Apache License, Version 2.0 (the "License"); -: 8: ## you may not use this file except in compliance with the License. -: 9: ## You may obtain a copy of the License at -: 10: ## -: 11: ## http://www.apache.org/licenses/LICENSE-2.0 -: 12: ## -: 13: ## Unless required by applicable law or agreed to in writing, software -: 14: ## distributed under the License is distributed on an "AS IS" BASIS, -: 15: ## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -: 16: ## See the License for the specific language governing permissions and -: 17: ## limitations under the License. -: 18: ## -: 19: ################################################################################*/ -: 20: -: 21:/* -: 22: * compile-time square-root function -: 23: */ -: 24: -: 25:#ifndef _gcem_sqrt_HPP -: 26:#define _gcem_sqrt_HPP -: 27: -: 28:namespace internal -: 29:{ -: 30: -: 31:template -: 32:constexpr -: 33:T 42237: 34:sqrt_recur(const T x, const T xn, const int count) -: 35:noexcept -: 36:{ 83659: 37: return( abs(xn - x/xn) / (T(1) + xn) < GCLIM::min() ? \ -: 38: // if -: 39: xn : 41422: 40: count < GCEM_SQRT_MAX_ITER ? \ -: 41: // else 41053: 42: sqrt_recur(x, T(0.5)*(xn + x/xn), count+1) : 42237: 43: xn ); -: 44:} -: 45: -: 46:template -: 47:constexpr -: 48:T 4688: 49:sqrt_check(const T x, const T m_val) -: 50:noexcept -: 51:{ 9376: 52: return( is_nan(x) ? \ #####: 53: GCLIM::quiet_NaN() : -: 54: // 9376: 55: x < T(0) ? \ #####: 56: GCLIM::quiet_NaN() : -: 57: // 9376*: 58: is_posinf(x) ? \ -: 59: x : -: 60: // indistinguishable from zero or one 9376*: 61: GCLIM::min() > abs(x) ? \ -: 62: T(0) : 9376*: 63: GCLIM::min() > abs(T(1) - x) ? \ -: 64: x : -: 65: // else 5872: 66: x > T(4) ? \ 3504: 67: sqrt_check(x/T(4), T(2)*m_val) : 5872: 68: m_val * sqrt_recur(x, x/T(2), 0) ); -: 69:} -: 70: -: 71:} -: 72: -: 73: -: 74:/** -: 75: * Compile-time square-root function -: 76: * -: 77: * @param x a real-valued input. -: 78: * @return Computes \f$ \sqrt{x} \f$ using a Newton-Raphson approach. -: 79: */ -: 80: -: 81:template -: 82:constexpr -: 83:return_t 1184: 84:sqrt(const T x) -: 85:noexcept -: 86:{ 1184: 87: return internal::sqrt_check( static_cast>(x), return_t(1) ); -: 88:} -: 89: -: 90:#endif <<<<<< EOF # path=tests/std_abs.h.gcov -: 0:Source:/usr/include/c++/9/bits/std_abs.h -: 0:Graph:log.gcno -: 0:Data:log.gcda -: 0:Runs:2 -: 1:// -*- C++ -*- C library enhancements header. -: 2: -: 3:// Copyright (C) 2016-2019 Free Software Foundation, Inc. -: 4:// -: 5:// This file is part of the GNU ISO C++ Library. This library is free -: 6:// software; you can redistribute it and/or modify it under the -: 7:// terms of the GNU General Public License as published by the -: 8:// Free Software Foundation; either version 3, or (at your option) -: 9:// any later version. -: 10: -: 11:// This library is distributed in the hope that it will be useful, -: 12:// but WITHOUT ANY WARRANTY; without even the implied warranty of -: 13:// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -: 14:// GNU General Public License for more details. -: 15: -: 16:// Under Section 7 of GPL version 3, you are granted additional -: 17:// permissions described in the GCC Runtime Library Exception, version -: 18:// 3.1, as published by the Free Software Foundation. -: 19: -: 20:// You should have received a copy of the GNU General Public License and -: 21:// a copy of the GCC Runtime Library Exception along with this program; -: 22:// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see -: 23:// . -: 24: -: 25:/** @file include/bits/std_abs.h -: 26: * This is an internal header file, included by other library headers. -: 27: * Do not attempt to use it directly. @headername{cmath, cstdlib} -: 28: */ -: 29: -: 30:#ifndef _GLIBCXX_BITS_STD_ABS_H -: 31:#define _GLIBCXX_BITS_STD_ABS_H -: 32: -: 33:#pragma GCC system_header -: 34: -: 35:#include -: 36: -: 37:#define _GLIBCXX_INCLUDE_NEXT_C_HEADERS -: 38:#include_next -: 39:#ifdef __CORRECT_ISO_CPP_MATH_H_PROTO -: 40:# include_next -: 41:#endif -: 42:#undef _GLIBCXX_INCLUDE_NEXT_C_HEADERS -: 43: -: 44:#undef abs -: 45: -: 46:extern "C++" -: 47:{ -: 48:namespace std _GLIBCXX_VISIBILITY(default) -: 49:{ -: 50:_GLIBCXX_BEGIN_NAMESPACE_VERSION -: 51: -: 52: using ::abs; -: 53: -: 54:#ifndef __CORRECT_ISO_CPP_STDLIB_H_PROTO -: 55: inline long -: 56: abs(long __i) { return __builtin_labs(__i); } -: 57:#endif -: 58: -: 59:#ifdef _GLIBCXX_USE_LONG_LONG -: 60: inline long long -: 61: abs(long long __x) { return __builtin_llabs (__x); } -: 62:#endif -: 63: -: 64:// _GLIBCXX_RESOLVE_LIB_DEFECTS -: 65:// 2192. Validity and return type of std::abs(0u) is unclear -: 66:// 2294. should declare abs(double) -: 67:// 2735. std::abs(short), std::abs(signed char) and others should return int -: 68: -: 69:#ifndef __CORRECT_ISO_CPP_MATH_H_PROTO -: 70: inline _GLIBCXX_CONSTEXPR double -: 71: abs(double __x) -: 72: { return __builtin_fabs(__x); } -: 73: -: 74: inline _GLIBCXX_CONSTEXPR float -: 75: abs(float __x) -: 76: { return __builtin_fabsf(__x); } -: 77: -: 78: inline _GLIBCXX_CONSTEXPR long double 48: 79: abs(long double __x) 48: 80: { return __builtin_fabsl(__x); } -: 81:#endif -: 82: -: 83:#if defined(__GLIBCXX_TYPE_INT_N_0) -: 84: inline _GLIBCXX_CONSTEXPR __GLIBCXX_TYPE_INT_N_0 -: 85: abs(__GLIBCXX_TYPE_INT_N_0 __x) { return __x >= 0 ? __x : -__x; } -: 86:#endif -: 87:#if defined(__GLIBCXX_TYPE_INT_N_1) -: 88: inline _GLIBCXX_CONSTEXPR __GLIBCXX_TYPE_INT_N_1 -: 89: abs(__GLIBCXX_TYPE_INT_N_1 __x) { return __x >= 0 ? __x : -__x; } -: 90:#endif -: 91:#if defined(__GLIBCXX_TYPE_INT_N_2) -: 92: inline _GLIBCXX_CONSTEXPR __GLIBCXX_TYPE_INT_N_2 -: 93: abs(__GLIBCXX_TYPE_INT_N_2 __x) { return __x >= 0 ? __x : -__x; } -: 94:#endif -: 95:#if defined(__GLIBCXX_TYPE_INT_N_3) -: 96: inline _GLIBCXX_CONSTEXPR __GLIBCXX_TYPE_INT_N_3 -: 97: abs(__GLIBCXX_TYPE_INT_N_3 __x) { return __x >= 0 ? __x : -__x; } -: 98:#endif -: 99: -: 100:#if !defined(__STRICT_ANSI__) && defined(_GLIBCXX_USE_FLOAT128) && !defined(__CUDACC__) -: 101: inline _GLIBCXX_CONSTEXPR -: 102: __float128 -: 103: abs(__float128 __x) -: 104: { return __x < 0 ? -__x : __x; } -: 105:#endif -: 106: -: 107:_GLIBCXX_END_NAMESPACE_VERSION -: 108:} // namespace -: 109:} // extern "C"++" -: 110: -: 111:#endif // _GLIBCXX_BITS_STD_ABS_H <<<<<< EOF # path=tests/std_function.h.gcov -: 0:Source:/usr/include/c++/9/bits/std_function.h -: 0:Graph:./factorial.gcno -: 0:Data:./factorial.gcda -: 0:Runs:1 -: 1:// Implementation of std::function -*- C++ -*- -: 2: -: 3:// Copyright (C) 2004-2019 Free Software Foundation, Inc. -: 4:// -: 5:// This file is part of the GNU ISO C++ Library. This library is free -: 6:// software; you can redistribute it and/or modify it under the -: 7:// terms of the GNU General Public License as published by the -: 8:// Free Software Foundation; either version 3, or (at your option) -: 9:// any later version. -: 10: -: 11:// This library is distributed in the hope that it will be useful, -: 12:// but WITHOUT ANY WARRANTY; without even the implied warranty of -: 13:// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -: 14:// GNU General Public License for more details. -: 15: -: 16:// Under Section 7 of GPL version 3, you are granted additional -: 17:// permissions described in the GCC Runtime Library Exception, version -: 18:// 3.1, as published by the Free Software Foundation. -: 19: -: 20:// You should have received a copy of the GNU General Public License and -: 21:// a copy of the GCC Runtime Library Exception along with this program; -: 22:// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see -: 23:// . -: 24: -: 25:/** @file include/bits/std_function.h -: 26: * This is an internal header file, included by other library headers. -: 27: * Do not attempt to use it directly. @headername{functional} -: 28: */ -: 29: -: 30:#ifndef _GLIBCXX_STD_FUNCTION_H -: 31:#define _GLIBCXX_STD_FUNCTION_H 1 -: 32: -: 33:#pragma GCC system_header -: 34: -: 35:#if __cplusplus < 201103L -: 36:# include -: 37:#else -: 38: -: 39:#if __cpp_rtti -: 40:# include -: 41:#endif -: 42:#include -: 43:#include -: 44:#include -: 45:#include -: 46: -: 47:namespace std _GLIBCXX_VISIBILITY(default) -: 48:{ -: 49:_GLIBCXX_BEGIN_NAMESPACE_VERSION -: 50: -: 51: /** -: 52: * @brief Exception class thrown when class template function's -: 53: * operator() is called with an empty target. -: 54: * @ingroup exceptions -: 55: */ -: 56: class bad_function_call : public std::exception -: 57: { -: 58: public: -: 59: virtual ~bad_function_call() noexcept; -: 60: -: 61: const char* what() const noexcept; -: 62: }; -: 63: -: 64: /** -: 65: * Trait identifying "location-invariant" types, meaning that the -: 66: * address of the object (or any of its members) will not escape. -: 67: * Trivially copyable types are location-invariant and users can -: 68: * specialize this trait for other types. -: 69: */ -: 70: template -: 71: struct __is_location_invariant -: 72: : is_trivially_copyable<_Tp>::type -: 73: { }; -: 74: -: 75: class _Undefined_class; -: 76: -: 77: union _Nocopy_types -: 78: { -: 79: void* _M_object; -: 80: const void* _M_const_object; -: 81: void (*_M_function_pointer)(); -: 82: void (_Undefined_class::*_M_member_pointer)(); -: 83: }; -: 84: -: 85: union [[gnu::may_alias]] _Any_data -: 86: { 2: 87: void* _M_access() { return &_M_pod_data[0]; } 11: 88: const void* _M_access() const { return &_M_pod_data[0]; } -: 89: -: 90: template -: 91: _Tp& 1*: 92: _M_access() 1*: 93: { return *static_cast<_Tp*>(_M_access()); } ------------------ _ZNSt9_Any_data9_M_accessIZ4mainEUleE_EERT_v: 1: 92: _M_access() 1: 93: { return *static_cast<_Tp*>(_M_access()); } ------------------ _ZNSt9_Any_data9_M_accessIPZ4mainEUleE_EERT_v: #####: 92: _M_access() #####: 93: { return *static_cast<_Tp*>(_M_access()); } ------------------ _ZNSt9_Any_data9_M_accessIPKSt9type_infoEERT_v: #####: 92: _M_access() #####: 93: { return *static_cast<_Tp*>(_M_access()); } ------------------ -: 94: -: 95: template -: 96: const _Tp& 11: 97: _M_access() const 11: 98: { return *static_cast(_M_access()); } -: 99: -: 100: _Nocopy_types _M_unused; -: 101: char _M_pod_data[sizeof(_Nocopy_types)]; -: 102: }; -: 103: -: 104: enum _Manager_operation -: 105: { -: 106: __get_type_info, -: 107: __get_functor_ptr, -: 108: __clone_functor, -: 109: __destroy_functor -: 110: }; -: 111: -: 112: // Simple type wrapper that helps avoid annoying const problems -: 113: // when casting between void pointers and pointers-to-pointers. -: 114: template -: 115: struct _Simple_type_wrapper -: 116: { -: 117: _Simple_type_wrapper(_Tp __value) : __value(__value) { } -: 118: -: 119: _Tp __value; -: 120: }; -: 121: -: 122: template -: 123: struct __is_location_invariant<_Simple_type_wrapper<_Tp> > -: 124: : __is_location_invariant<_Tp> -: 125: { }; -: 126: -: 127: template -: 128: class function; -: 129: -: 130: /// Base class of all polymorphic function object wrappers. -: 131: class _Function_base -: 132: { -: 133: public: -: 134: static const size_t _M_max_size = sizeof(_Nocopy_types); -: 135: static const size_t _M_max_align = __alignof__(_Nocopy_types); -: 136: -: 137: template -: 138: class _Base_manager -: 139: { -: 140: protected: -: 141: static const bool __stored_locally = -: 142: (__is_location_invariant<_Functor>::value -: 143: && sizeof(_Functor) <= _M_max_size -: 144: && __alignof__(_Functor) <= _M_max_align -: 145: && (_M_max_align % __alignof__(_Functor) == 0)); -: 146: -: 147: typedef integral_constant _Local_storage; -: 148: -: 149: // Retrieve a pointer to the function object -: 150: static _Functor* 11: 151: _M_get_pointer(const _Any_data& __source) -: 152: { -: 153: if _GLIBCXX17_CONSTEXPR (__stored_locally) -: 154: { 11: 155: const _Functor& __f = __source._M_access<_Functor>(); 11: 156: return const_cast<_Functor*>(std::__addressof(__f)); -: 157: } -: 158: else // have stored a pointer -: 159: return __source._M_access<_Functor*>(); -: 160: } -: 161: -: 162: // Clone a location-invariant function object that fits within -: 163: // an _Any_data structure. -: 164: static void #####: 165: _M_clone(_Any_data& __dest, const _Any_data& __source, true_type) -: 166: { #####: 167: ::new (__dest._M_access()) _Functor(__source._M_access<_Functor>()); #####: 168: } -: 169: -: 170: // Clone a function object that is not location-invariant or -: 171: // that cannot fit into an _Any_data structure. -: 172: static void -: 173: _M_clone(_Any_data& __dest, const _Any_data& __source, false_type) -: 174: { -: 175: __dest._M_access<_Functor*>() = -: 176: new _Functor(*__source._M_access()); -: 177: } -: 178: -: 179: // Destroying a location-invariant object may still require -: 180: // destruction. -: 181: static void 1: 182: _M_destroy(_Any_data& __victim, true_type) -: 183: { 1: 184: __victim._M_access<_Functor>().~_Functor(); 1: 185: } -: 186: -: 187: // Destroying an object located on the heap. -: 188: static void -: 189: _M_destroy(_Any_data& __victim, false_type) -: 190: { -: 191: delete __victim._M_access<_Functor*>(); -: 192: } -: 193: -: 194: public: -: 195: static bool 1: 196: _M_manager(_Any_data& __dest, const _Any_data& __source, -: 197: _Manager_operation __op) -: 198: { 1: 199: switch (__op) -: 200: { -: 201:#if __cpp_rtti #####: 202: case __get_type_info: #####: 203: __dest._M_access() = &typeid(_Functor); #####: 204: break; -: 205:#endif #####: 206: case __get_functor_ptr: #####: 207: __dest._M_access<_Functor*>() = _M_get_pointer(__source); #####: 208: break; -: 209: #####: 210: case __clone_functor: #####: 211: _M_clone(__dest, __source, _Local_storage()); #####: 212: break; -: 213: 1: 214: case __destroy_functor: 1: 215: _M_destroy(__dest, _Local_storage()); 1: 216: break; -: 217: } 1: 218: return false; -: 219: } -: 220: -: 221: static void 1: 222: _M_init_functor(_Any_data& __functor, _Functor&& __f) 1: 223: { _M_init_functor(__functor, std::move(__f), _Local_storage()); } -: 224: -: 225: template -: 226: static bool -: 227: _M_not_empty_function(const function<_Signature>& __f) -: 228: { return static_cast(__f); } -: 229: -: 230: template -: 231: static bool -: 232: _M_not_empty_function(_Tp* __fp) -: 233: { return __fp != nullptr; } -: 234: -: 235: template -: 236: static bool -: 237: _M_not_empty_function(_Tp _Class::* __mp) -: 238: { return __mp != nullptr; } -: 239: -: 240: template -: 241: static bool 1: 242: _M_not_empty_function(const _Tp&) 1: 243: { return true; } -: 244: -: 245: private: -: 246: static void 1: 247: _M_init_functor(_Any_data& __functor, _Functor&& __f, true_type) 1: 248: { ::new (__functor._M_access()) _Functor(std::move(__f)); } -: 249: -: 250: static void -: 251: _M_init_functor(_Any_data& __functor, _Functor&& __f, false_type) -: 252: { __functor._M_access<_Functor*>() = new _Functor(std::move(__f)); } -: 253: }; -: 254: 1: 255: _Function_base() : _M_manager(nullptr) { } -: 256: 1: 257: ~_Function_base() 1: 258: { 1: 259: if (_M_manager) 1: 260: _M_manager(_M_functor, _M_functor, __destroy_functor); 1: 261: } -: 262: 11: 263: bool _M_empty() const { return !_M_manager; } -: 264: -: 265: typedef bool (*_Manager_type)(_Any_data&, const _Any_data&, -: 266: _Manager_operation); -: 267: -: 268: _Any_data _M_functor; -: 269: _Manager_type _M_manager; -: 270: }; -: 271: -: 272: template -: 273: class _Function_handler; -: 274: -: 275: template -: 276: class _Function_handler<_Res(_ArgTypes...), _Functor> -: 277: : public _Function_base::_Base_manager<_Functor> -: 278: { -: 279: typedef _Function_base::_Base_manager<_Functor> _Base; -: 280: -: 281: public: -: 282: static _Res 11: 283: _M_invoke(const _Any_data& __functor, _ArgTypes&&... __args) -: 284: { 22: 285: return (*_Base::_M_get_pointer(__functor))( 22: 286: std::forward<_ArgTypes>(__args)...); -: 287: } -: 288: }; -: 289: -: 290: template -: 291: class _Function_handler -: 292: : public _Function_base::_Base_manager<_Functor> -: 293: { -: 294: typedef _Function_base::_Base_manager<_Functor> _Base; -: 295: -: 296: public: -: 297: static void -: 298: _M_invoke(const _Any_data& __functor, _ArgTypes&&... __args) -: 299: { -: 300: (*_Base::_M_get_pointer(__functor))( -: 301: std::forward<_ArgTypes>(__args)...); -: 302: } -: 303: }; -: 304: -: 305: template -: 307: class _Function_handler<_Res(_ArgTypes...), _Member _Class::*> -: 308: : public _Function_handler -: 309: { -: 310: typedef _Function_handler -: 311: _Base; -: 312: -: 313: public: -: 314: static _Res -: 315: _M_invoke(const _Any_data& __functor, _ArgTypes&&... __args) -: 316: { -: 317: return std::__invoke(_Base::_M_get_pointer(__functor)->__value, -: 318: std::forward<_ArgTypes>(__args)...); -: 319: } -: 320: }; -: 321: -: 322: template -: 323: class _Function_handler -: 324: : public _Function_base::_Base_manager< -: 325: _Simple_type_wrapper< _Member _Class::* > > -: 326: { -: 327: typedef _Member _Class::* _Functor; -: 328: typedef _Simple_type_wrapper<_Functor> _Wrapper; -: 329: typedef _Function_base::_Base_manager<_Wrapper> _Base; -: 330: -: 331: public: -: 332: static bool -: 333: _M_manager(_Any_data& __dest, const _Any_data& __source, -: 334: _Manager_operation __op) -: 335: { -: 336: switch (__op) -: 337: { -: 338:#if __cpp_rtti -: 339: case __get_type_info: -: 340: __dest._M_access() = &typeid(_Functor); -: 341: break; -: 342:#endif -: 343: case __get_functor_ptr: -: 344: __dest._M_access<_Functor*>() = -: 345: &_Base::_M_get_pointer(__source)->__value; -: 346: break; -: 347: -: 348: default: -: 349: _Base::_M_manager(__dest, __source, __op); -: 350: } -: 351: return false; -: 352: } -: 353: -: 354: static void -: 355: _M_invoke(const _Any_data& __functor, _ArgTypes&&... __args) -: 356: { -: 357: std::__invoke(_Base::_M_get_pointer(__functor)->__value, -: 358: std::forward<_ArgTypes>(__args)...); -: 359: } -: 360: }; -: 361: -: 362: /** -: 363: * @brief Primary class template for std::function. -: 364: * @ingroup functors -: 365: * -: 366: * Polymorphic function wrapper. -: 367: */ -: 368: template -: 369: class function<_Res(_ArgTypes...)> -: 370: : public _Maybe_unary_or_binary_function<_Res, _ArgTypes...>, -: 371: private _Function_base -: 372: { -: 373: template> -: 375: struct _Callable -: 376: : __is_invocable_impl<_Res2, _Res>::type -: 377: { }; -: 378: -: 379: // Used so the return type convertibility checks aren't done when -: 380: // performing overload resolution for copy construction/assignment. -: 381: template -: 382: struct _Callable : false_type { }; -: 383: -: 384: template -: 385: using _Requires = typename enable_if<_Cond::value, _Tp>::type; -: 386: -: 387: public: -: 388: typedef _Res result_type; -: 389: -: 390: // [3.7.2.1] construct/copy/destroy -: 391: -: 392: /** -: 393: * @brief Default construct creates an empty function call wrapper. -: 394: * @post @c !(bool)*this -: 395: */ -: 396: function() noexcept -: 397: : _Function_base() { } -: 398: -: 399: /** -: 400: * @brief Creates an empty function call wrapper. -: 401: * @post @c !(bool)*this -: 402: */ -: 403: function(nullptr_t) noexcept -: 404: : _Function_base() { } -: 405: -: 406: /** -: 407: * @brief %Function copy constructor. -: 408: * @param __x A %function object with identical call signature. -: 409: * @post @c bool(*this) == bool(__x) -: 410: * -: 411: * The newly-created %function contains a copy of the target of @a -: 412: * __x (if it has one). -: 413: */ -: 414: function(const function& __x); -: 415: -: 416: /** -: 417: * @brief %Function move constructor. -: 418: * @param __x A %function object rvalue with identical call signature. -: 419: * -: 420: * The newly-created %function contains the target of @a __x -: 421: * (if it has one). -: 422: */ -: 423: function(function&& __x) noexcept : _Function_base() -: 424: { -: 425: __x.swap(*this); -: 426: } -: 427: -: 428: /** -: 429: * @brief Builds a %function that targets a copy of the incoming -: 430: * function object. -: 431: * @param __f A %function object that is callable with parameters of -: 432: * type @c T1, @c T2, ..., @c TN and returns a value convertible -: 433: * to @c Res. -: 434: * -: 435: * The newly-created %function object will target a copy of -: 436: * @a __f. If @a __f is @c reference_wrapper, then this function -: 437: * object will contain a reference to the function object @c -: 438: * __f.get(). If @a __f is a NULL function pointer or NULL -: 439: * pointer-to-member, the newly-created object will be empty. -: 440: * -: 441: * If @a __f is a non-NULL function pointer or an object of type @c -: 442: * reference_wrapper, this function will not throw. -: 443: */ -: 444: template>, void>, -: 446: typename = _Requires<_Callable<_Functor>, void>> -: 447: function(_Functor); -: 448: -: 449: /** -: 450: * @brief %Function assignment operator. -: 451: * @param __x A %function with identical call signature. -: 452: * @post @c (bool)*this == (bool)x -: 453: * @returns @c *this -: 454: * -: 455: * The target of @a __x is copied to @c *this. If @a __x has no -: 456: * target, then @c *this will be empty. -: 457: * -: 458: * If @a __x targets a function pointer or a reference to a function -: 459: * object, then this operation will not throw an %exception. -: 460: */ -: 461: function& -: 462: operator=(const function& __x) -: 463: { -: 464: function(__x).swap(*this); -: 465: return *this; -: 466: } -: 467: -: 468: /** -: 469: * @brief %Function move-assignment operator. -: 470: * @param __x A %function rvalue with identical call signature. -: 471: * @returns @c *this -: 472: * -: 473: * The target of @a __x is moved to @c *this. If @a __x has no -: 474: * target, then @c *this will be empty. -: 475: * -: 476: * If @a __x targets a function pointer or a reference to a function -: 477: * object, then this operation will not throw an %exception. -: 478: */ -: 479: function& -: 480: operator=(function&& __x) noexcept -: 481: { -: 482: function(std::move(__x)).swap(*this); -: 483: return *this; -: 484: } -: 485: -: 486: /** -: 487: * @brief %Function assignment to zero. -: 488: * @post @c !(bool)*this -: 489: * @returns @c *this -: 490: * -: 491: * The target of @c *this is deallocated, leaving it empty. -: 492: */ -: 493: function& -: 494: operator=(nullptr_t) noexcept -: 495: { -: 496: if (_M_manager) -: 497: { -: 498: _M_manager(_M_functor, _M_functor, __destroy_functor); -: 499: _M_manager = nullptr; -: 500: _M_invoker = nullptr; -: 501: } -: 502: return *this; -: 503: } -: 504: -: 505: /** -: 506: * @brief %Function assignment to a new target. -: 507: * @param __f A %function object that is callable with parameters of -: 508: * type @c T1, @c T2, ..., @c TN and returns a value convertible -: 509: * to @c Res. -: 510: * @return @c *this -: 511: * -: 512: * This %function object wrapper will target a copy of @a -: 513: * __f. If @a __f is @c reference_wrapper, then this function -: 514: * object will contain a reference to the function object @c -: 515: * __f.get(). If @a __f is a NULL function pointer or NULL -: 516: * pointer-to-member, @c this object will be empty. -: 517: * -: 518: * If @a __f is a non-NULL function pointer or an object of type @c -: 519: * reference_wrapper, this function will not throw. -: 520: */ -: 521: template -: 522: _Requires<_Callable::type>, function&> -: 523: operator=(_Functor&& __f) -: 524: { -: 525: function(std::forward<_Functor>(__f)).swap(*this); -: 526: return *this; -: 527: } -: 528: -: 529: /// @overload -: 530: template -: 531: function& -: 532: operator=(reference_wrapper<_Functor> __f) noexcept -: 533: { -: 534: function(__f).swap(*this); -: 535: return *this; -: 536: } -: 537: -: 538: // [3.7.2.2] function modifiers -: 539: -: 540: /** -: 541: * @brief Swap the targets of two %function objects. -: 542: * @param __x A %function with identical call signature. -: 543: * -: 544: * Swap the targets of @c this function object and @a __f. This -: 545: * function will not throw an %exception. -: 546: */ -: 547: void swap(function& __x) noexcept -: 548: { -: 549: std::swap(_M_functor, __x._M_functor); -: 550: std::swap(_M_manager, __x._M_manager); -: 551: std::swap(_M_invoker, __x._M_invoker); -: 552: } -: 553: -: 554: // [3.7.2.3] function capacity -: 555: -: 556: /** -: 557: * @brief Determine if the %function wrapper has a target. -: 558: * -: 559: * @return @c true when this %function object contains a target, -: 560: * or @c false when it is empty. -: 561: * -: 562: * This function will not throw an %exception. -: 563: */ -: 564: explicit operator bool() const noexcept -: 565: { return !_M_empty(); } -: 566: -: 567: // [3.7.2.4] function invocation -: 568: -: 569: /** -: 570: * @brief Invokes the function targeted by @c *this. -: 571: * @returns the result of the target. -: 572: * @throws bad_function_call when @c !(bool)*this -: 573: * -: 574: * The function call operator invokes the target function object -: 575: * stored by @c this. -: 576: */ -: 577: _Res operator()(_ArgTypes... __args) const; -: 578: -: 579:#if __cpp_rtti -: 580: // [3.7.2.5] function target access -: 581: /** -: 582: * @brief Determine the type of the target of this function object -: 583: * wrapper. -: 584: * -: 585: * @returns the type identifier of the target function object, or -: 586: * @c typeid(void) if @c !(bool)*this. -: 587: * -: 588: * This function will not throw an %exception. -: 589: */ -: 590: const type_info& target_type() const noexcept; -: 591: -: 592: /** -: 593: * @brief Access the stored target function object. -: 594: * -: 595: * @return Returns a pointer to the stored target function object, -: 596: * if @c typeid(_Functor).equals(target_type()); otherwise, a NULL -: 597: * pointer. -: 598: * -: 599: * This function does not throw exceptions. -: 600: * -: 601: * @{ -: 602: */ -: 603: template _Functor* target() noexcept; -: 604: -: 605: template const _Functor* target() const noexcept; -: 606: /// @} -: 607:#endif -: 608: -: 609: private: -: 610: using _Invoker_type = _Res (*)(const _Any_data&, _ArgTypes&&...); -: 611: _Invoker_type _M_invoker; -: 612: }; -: 613: -: 614:#if __cpp_deduction_guides >= 201606 -: 615: template -: 616: struct __function_guide_helper -: 617: { }; -: 618: -: 619: template -: 620: struct __function_guide_helper< -: 621: _Res (_Tp::*) (_Args...) noexcept(_Nx) -: 622: > -: 623: { using type = _Res(_Args...); }; -: 624: -: 625: template -: 626: struct __function_guide_helper< -: 627: _Res (_Tp::*) (_Args...) & noexcept(_Nx) -: 628: > -: 629: { using type = _Res(_Args...); }; -: 630: -: 631: template -: 632: struct __function_guide_helper< -: 633: _Res (_Tp::*) (_Args...) const noexcept(_Nx) -: 634: > -: 635: { using type = _Res(_Args...); }; -: 636: -: 637: template -: 638: struct __function_guide_helper< -: 639: _Res (_Tp::*) (_Args...) const & noexcept(_Nx) -: 640: > -: 641: { using type = _Res(_Args...); }; -: 642: -: 643: template -: 644: function(_Res(*)(_ArgTypes...)) -> function<_Res(_ArgTypes...)>; -: 645: -: 646: template::type> -: 648: function(_Functor) -> function<_Signature>; -: 649:#endif -: 650: -: 651: // Out-of-line member definitions. -: 652: template -: 653: function<_Res(_ArgTypes...)>:: -: 654: function(const function& __x) -: 655: : _Function_base() -: 656: { -: 657: if (static_cast(__x)) -: 658: { -: 659: __x._M_manager(_M_functor, __x._M_functor, __clone_functor); -: 660: _M_invoker = __x._M_invoker; -: 661: _M_manager = __x._M_manager; -: 662: } -: 663: } -: 664: -: 665: template -: 666: template 1: 667: function<_Res(_ArgTypes...)>:: -: 668: function(_Functor __f) 1: 669: : _Function_base() -: 670: { -: 671: typedef _Function_handler<_Res(_ArgTypes...), _Functor> _My_handler; -: 672: 1: 673: if (_My_handler::_M_not_empty_function(__f)) -: 674: { 1: 675: _My_handler::_M_init_functor(_M_functor, std::move(__f)); 1: 676: _M_invoker = &_My_handler::_M_invoke; 1: 677: _M_manager = &_My_handler::_M_manager; -: 678: } 1: 679: } -: 680: -: 681: template -: 682: _Res 11: 683: function<_Res(_ArgTypes...)>:: -: 684: operator()(_ArgTypes... __args) const -: 685: { 11: 686: if (_M_empty()) #####: 687: __throw_bad_function_call(); 11: 688: return _M_invoker(_M_functor, std::forward<_ArgTypes>(__args)...); -: 689: } -: 690: -: 691:#if __cpp_rtti -: 692: template -: 693: const type_info& -: 694: function<_Res(_ArgTypes...)>:: -: 695: target_type() const noexcept -: 696: { -: 697: if (_M_manager) -: 698: { -: 699: _Any_data __typeinfo_result; -: 700: _M_manager(__typeinfo_result, _M_functor, __get_type_info); -: 701: return *__typeinfo_result._M_access(); -: 702: } -: 703: else -: 704: return typeid(void); -: 705: } -: 706: -: 707: template -: 708: template -: 709: _Functor* -: 710: function<_Res(_ArgTypes...)>:: -: 711: target() noexcept -: 712: { -: 713: const function* __const_this = this; -: 714: const _Functor* __func = __const_this->template target<_Functor>(); -: 715: return const_cast<_Functor*>(__func); -: 716: } -: 717: -: 718: template -: 719: template -: 720: const _Functor* -: 721: function<_Res(_ArgTypes...)>:: -: 722: target() const noexcept -: 723: { -: 724: if (typeid(_Functor) == target_type() && _M_manager) -: 725: { -: 726: _Any_data __ptr; -: 727: _M_manager(__ptr, _M_functor, __get_functor_ptr); -: 728: return __ptr._M_access(); -: 729: } -: 730: else -: 731: return nullptr; -: 732: } -: 733:#endif -: 734: -: 735: // [20.7.15.2.6] null pointer comparisons -: 736: -: 737: /** -: 738: * @brief Compares a polymorphic function object wrapper against 0 -: 739: * (the NULL pointer). -: 740: * @returns @c true if the wrapper has no target, @c false otherwise -: 741: * -: 742: * This function will not throw an %exception. -: 743: */ -: 744: template -: 745: inline bool -: 746: operator==(const function<_Res(_Args...)>& __f, nullptr_t) noexcept -: 747: { return !static_cast(__f); } -: 748: -: 749: /// @overload -: 750: template -: 751: inline bool -: 752: operator==(nullptr_t, const function<_Res(_Args...)>& __f) noexcept -: 753: { return !static_cast(__f); } -: 754: -: 755: /** -: 756: * @brief Compares a polymorphic function object wrapper against 0 -: 757: * (the NULL pointer). -: 758: * @returns @c false if the wrapper has no target, @c true otherwise -: 759: * -: 760: * This function will not throw an %exception. -: 761: */ -: 762: template -: 763: inline bool -: 764: operator!=(const function<_Res(_Args...)>& __f, nullptr_t) noexcept -: 765: { return static_cast(__f); } -: 766: -: 767: /// @overload -: 768: template -: 769: inline bool -: 770: operator!=(nullptr_t, const function<_Res(_Args...)>& __f) noexcept -: 771: { return static_cast(__f); } -: 772: -: 773: -: 774: // [20.7.15.2.7] specialized algorithms -: 775: -: 776: /** -: 777: * @brief Swap the targets of two polymorphic function object wrappers. -: 778: * -: 779: * This function will not throw an %exception. -: 780: */ -: 781: // _GLIBCXX_RESOLVE_LIB_DEFECTS -: 782: // 2062. Effect contradictions w/o no-throw guarantee of std::function swaps -: 783: template -: 784: inline void -: 785: swap(function<_Res(_Args...)>& __x, function<_Res(_Args...)>& __y) noexcept -: 786: { __x.swap(__y); } -: 787: -: 788:#if __cplusplus >= 201703L -: 789: namespace __detail::__variant -: 790: { -: 791: template struct _Never_valueless_alt; // see -: 792: -: 793: // Provide the strong exception-safety guarantee when emplacing a -: 794: // function into a variant. -: 795: template -: 796: struct _Never_valueless_alt> -: 797: : std::true_type -: 798: { }; -: 799: } // namespace __detail::__variant -: 800:#endif // C++17 -: 801: -: 802:_GLIBCXX_END_NAMESPACE_VERSION -: 803:} // namespace std -: 804: -: 805:#endif // C++11 -: 806:#endif // _GLIBCXX_STD_FUNCTION_H <<<<<< EOF # path=tests/stl_iterator_base_funcs.h.gcov -: 0:Source:/usr/include/c++/9/bits/stl_iterator_base_funcs.h -: 0:Graph:log.gcno -: 0:Data:log.gcda -: 0:Runs:2 -: 1:// Functions used by iterators -*- C++ -*- -: 2: -: 3:// Copyright (C) 2001-2019 Free Software Foundation, Inc. -: 4:// -: 5:// This file is part of the GNU ISO C++ Library. This library is free -: 6:// software; you can redistribute it and/or modify it under the -: 7:// terms of the GNU General Public License as published by the -: 8:// Free Software Foundation; either version 3, or (at your option) -: 9:// any later version. -: 10: -: 11:// This library is distributed in the hope that it will be useful, -: 12:// but WITHOUT ANY WARRANTY; without even the implied warranty of -: 13:// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -: 14:// GNU General Public License for more details. -: 15: -: 16:// Under Section 7 of GPL version 3, you are granted additional -: 17:// permissions described in the GCC Runtime Library Exception, version -: 18:// 3.1, as published by the Free Software Foundation. -: 19: -: 20:// You should have received a copy of the GNU General Public License and -: 21:// a copy of the GCC Runtime Library Exception along with this program; -: 22:// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see -: 23:// . -: 24: -: 25:/* -: 26: * -: 27: * Copyright (c) 1994 -: 28: * Hewlett-Packard Company -: 29: * -: 30: * Permission to use, copy, modify, distribute and sell this software -: 31: * and its documentation for any purpose is hereby granted without fee, -: 32: * provided that the above copyright notice appear in all copies and -: 33: * that both that copyright notice and this permission notice appear -: 34: * in supporting documentation. Hewlett-Packard Company makes no -: 35: * representations about the suitability of this software for any -: 36: * purpose. It is provided "as is" without express or implied warranty. -: 37: * -: 38: * -: 39: * Copyright (c) 1996-1998 -: 40: * Silicon Graphics Computer Systems, Inc. -: 41: * -: 42: * Permission to use, copy, modify, distribute and sell this software -: 43: * and its documentation for any purpose is hereby granted without fee, -: 44: * provided that the above copyright notice appear in all copies and -: 45: * that both that copyright notice and this permission notice appear -: 46: * in supporting documentation. Silicon Graphics makes no -: 47: * representations about the suitability of this software for any -: 48: * purpose. It is provided "as is" without express or implied warranty. -: 49: */ -: 50: -: 51:/** @file bits/stl_iterator_base_funcs.h -: 52: * This is an internal header file, included by other library headers. -: 53: * Do not attempt to use it directly. @headername{iterator} -: 54: * -: 55: * This file contains all of the general iterator-related utility -: 56: * functions, such as distance() and advance(). -: 57: */ -: 58: -: 59:#ifndef _STL_ITERATOR_BASE_FUNCS_H -: 60:#define _STL_ITERATOR_BASE_FUNCS_H 1 -: 61: -: 62:#pragma GCC system_header -: 63: -: 64:#include -: 65:#include -: 66: -: 67:namespace std _GLIBCXX_VISIBILITY(default) -: 68:{ -: 69:_GLIBCXX_BEGIN_NAMESPACE_VERSION -: 70: -: 71:_GLIBCXX_BEGIN_NAMESPACE_CONTAINER -: 72: // Forward declaration for the overloads of __distance. -: 73: template struct _List_iterator; -: 74: template struct _List_const_iterator; -: 75:_GLIBCXX_END_NAMESPACE_CONTAINER -: 76: -: 77: template -: 78: inline _GLIBCXX14_CONSTEXPR -: 79: typename iterator_traits<_InputIterator>::difference_type -: 80: __distance(_InputIterator __first, _InputIterator __last, -: 81: input_iterator_tag) -: 82: { -: 83: // concept requirements -: 84: __glibcxx_function_requires(_InputIteratorConcept<_InputIterator>) -: 85: -: 86: typename iterator_traits<_InputIterator>::difference_type __n = 0; -: 87: while (__first != __last) -: 88: { -: 89: ++__first; -: 90: ++__n; -: 91: } -: 92: return __n; -: 93: } -: 94: -: 95: template -: 96: inline _GLIBCXX14_CONSTEXPR -: 97: typename iterator_traits<_RandomAccessIterator>::difference_type #####: 98: __distance(_RandomAccessIterator __first, _RandomAccessIterator __last, -: 99: random_access_iterator_tag) -: 100: { -: 101: // concept requirements -: 102: __glibcxx_function_requires(_RandomAccessIteratorConcept< -: 103: _RandomAccessIterator>) #####: 104: return __last - __first; -: 105: } ------------------ _ZSt10__distanceIPcENSt15iterator_traitsIT_E15difference_typeES2_S2_St26random_access_iterator_tag: #####: 98: __distance(_RandomAccessIterator __first, _RandomAccessIterator __last, -: 99: random_access_iterator_tag) -: 100: { -: 101: // concept requirements -: 102: __glibcxx_function_requires(_RandomAccessIteratorConcept< -: 103: _RandomAccessIterator>) #####: 104: return __last - __first; -: 105: } ------------------ _ZSt10__distanceIPKcENSt15iterator_traitsIT_E15difference_typeES3_S3_St26random_access_iterator_tag: #####: 98: __distance(_RandomAccessIterator __first, _RandomAccessIterator __last, -: 99: random_access_iterator_tag) -: 100: { -: 101: // concept requirements -: 102: __glibcxx_function_requires(_RandomAccessIteratorConcept< -: 103: _RandomAccessIterator>) #####: 104: return __last - __first; -: 105: } ------------------ -: 106: -: 107:#if _GLIBCXX_USE_CXX11_ABI -: 108: // Forward declaration because of the qualified call in distance. -: 109: template -: 110: ptrdiff_t -: 111: __distance(_GLIBCXX_STD_C::_List_iterator<_Tp>, -: 112: _GLIBCXX_STD_C::_List_iterator<_Tp>, -: 113: input_iterator_tag); -: 114: -: 115: template -: 116: ptrdiff_t -: 117: __distance(_GLIBCXX_STD_C::_List_const_iterator<_Tp>, -: 118: _GLIBCXX_STD_C::_List_const_iterator<_Tp>, -: 119: input_iterator_tag); -: 120:#endif -: 121: -: 122: /** -: 123: * @brief A generalization of pointer arithmetic. -: 124: * @param __first An input iterator. -: 125: * @param __last An input iterator. -: 126: * @return The distance between them. -: 127: * -: 128: * Returns @c n such that __first + n == __last. This requires -: 129: * that @p __last must be reachable from @p __first. Note that @c -: 130: * n may be negative. -: 131: * -: 132: * For random access iterators, this uses their @c + and @c - operations -: 133: * and are constant time. For other %iterator classes they are linear time. -: 134: */ -: 135: template -: 136: inline _GLIBCXX17_CONSTEXPR -: 137: typename iterator_traits<_InputIterator>::difference_type #####: 138: distance(_InputIterator __first, _InputIterator __last) -: 139: { -: 140: // concept requirements -- taken care of in __distance #####: 141: return std::__distance(__first, __last, #####: 142: std::__iterator_category(__first)); -: 143: } -: 144: -: 145: template -: 146: inline _GLIBCXX14_CONSTEXPR void -: 147: __advance(_InputIterator& __i, _Distance __n, input_iterator_tag) -: 148: { -: 149: // concept requirements -: 150: __glibcxx_function_requires(_InputIteratorConcept<_InputIterator>) -: 151: __glibcxx_assert(__n >= 0); -: 152: while (__n--) -: 153: ++__i; -: 154: } -: 155: -: 156: template -: 157: inline _GLIBCXX14_CONSTEXPR void -: 158: __advance(_BidirectionalIterator& __i, _Distance __n, -: 159: bidirectional_iterator_tag) -: 160: { -: 161: // concept requirements -: 162: __glibcxx_function_requires(_BidirectionalIteratorConcept< -: 163: _BidirectionalIterator>) -: 164: if (__n > 0) -: 165: while (__n--) -: 166: ++__i; -: 167: else -: 168: while (__n++) -: 169: --__i; -: 170: } -: 171: -: 172: template -: 173: inline _GLIBCXX14_CONSTEXPR void -: 174: __advance(_RandomAccessIterator& __i, _Distance __n, -: 175: random_access_iterator_tag) -: 176: { -: 177: // concept requirements -: 178: __glibcxx_function_requires(_RandomAccessIteratorConcept< -: 179: _RandomAccessIterator>) -: 180: if (__builtin_constant_p(__n) && __n == 1) -: 181: ++__i; -: 182: else if (__builtin_constant_p(__n) && __n == -1) -: 183: --__i; -: 184: else -: 185: __i += __n; -: 186: } -: 187: -: 188: /** -: 189: * @brief A generalization of pointer arithmetic. -: 190: * @param __i An input iterator. -: 191: * @param __n The @a delta by which to change @p __i. -: 192: * @return Nothing. -: 193: * -: 194: * This increments @p i by @p n. For bidirectional and random access -: 195: * iterators, @p __n may be negative, in which case @p __i is decremented. -: 196: * -: 197: * For random access iterators, this uses their @c + and @c - operations -: 198: * and are constant time. For other %iterator classes they are linear time. -: 199: */ -: 200: template -: 201: inline _GLIBCXX17_CONSTEXPR void -: 202: advance(_InputIterator& __i, _Distance __n) -: 203: { -: 204: // concept requirements -- taken care of in __advance -: 205: typename iterator_traits<_InputIterator>::difference_type __d = __n; -: 206: std::__advance(__i, __d, std::__iterator_category(__i)); -: 207: } -: 208: -: 209:#if __cplusplus >= 201103L -: 210: -: 211: template -: 212: inline _GLIBCXX17_CONSTEXPR _InputIterator -: 213: next(_InputIterator __x, typename -: 214: iterator_traits<_InputIterator>::difference_type __n = 1) -: 215: { -: 216: // concept requirements -: 217: __glibcxx_function_requires(_InputIteratorConcept<_InputIterator>) -: 218: std::advance(__x, __n); -: 219: return __x; -: 220: } -: 221: -: 222: template -: 223: inline _GLIBCXX17_CONSTEXPR _BidirectionalIterator -: 224: prev(_BidirectionalIterator __x, typename -: 225: iterator_traits<_BidirectionalIterator>::difference_type __n = 1) -: 226: { -: 227: // concept requirements -: 228: __glibcxx_function_requires(_BidirectionalIteratorConcept< -: 229: _BidirectionalIterator>) -: 230: std::advance(__x, -__n); -: 231: return __x; -: 232: } -: 233: -: 234:#endif // C++11 -: 235: -: 236:_GLIBCXX_END_NAMESPACE_VERSION -: 237:} // namespace -: 238: -: 239:#endif /* _STL_ITERATOR_BASE_FUNCS_H */ <<<<<< EOF # path=tests/stl_iterator_base_types.h.gcov -: 0:Source:/usr/include/c++/9/bits/stl_iterator_base_types.h -: 0:Graph:log.gcno -: 0:Data:log.gcda -: 0:Runs:2 -: 1:// Types used in iterator implementation -*- C++ -*- -: 2: -: 3:// Copyright (C) 2001-2019 Free Software Foundation, Inc. -: 4:// -: 5:// This file is part of the GNU ISO C++ Library. This library is free -: 6:// software; you can redistribute it and/or modify it under the -: 7:// terms of the GNU General Public License as published by the -: 8:// Free Software Foundation; either version 3, or (at your option) -: 9:// any later version. -: 10: -: 11:// This library is distributed in the hope that it will be useful, -: 12:// but WITHOUT ANY WARRANTY; without even the implied warranty of -: 13:// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -: 14:// GNU General Public License for more details. -: 15: -: 16:// Under Section 7 of GPL version 3, you are granted additional -: 17:// permissions described in the GCC Runtime Library Exception, version -: 18:// 3.1, as published by the Free Software Foundation. -: 19: -: 20:// You should have received a copy of the GNU General Public License and -: 21:// a copy of the GCC Runtime Library Exception along with this program; -: 22:// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see -: 23:// . -: 24: -: 25:/* -: 26: * -: 27: * Copyright (c) 1994 -: 28: * Hewlett-Packard Company -: 29: * -: 30: * Permission to use, copy, modify, distribute and sell this software -: 31: * and its documentation for any purpose is hereby granted without fee, -: 32: * provided that the above copyright notice appear in all copies and -: 33: * that both that copyright notice and this permission notice appear -: 34: * in supporting documentation. Hewlett-Packard Company makes no -: 35: * representations about the suitability of this software for any -: 36: * purpose. It is provided "as is" without express or implied warranty. -: 37: * -: 38: * -: 39: * Copyright (c) 1996-1998 -: 40: * Silicon Graphics Computer Systems, Inc. -: 41: * -: 42: * Permission to use, copy, modify, distribute and sell this software -: 43: * and its documentation for any purpose is hereby granted without fee, -: 44: * provided that the above copyright notice appear in all copies and -: 45: * that both that copyright notice and this permission notice appear -: 46: * in supporting documentation. Silicon Graphics makes no -: 47: * representations about the suitability of this software for any -: 48: * purpose. It is provided "as is" without express or implied warranty. -: 49: */ -: 50: -: 51:/** @file bits/stl_iterator_base_types.h -: 52: * This is an internal header file, included by other library headers. -: 53: * Do not attempt to use it directly. @headername{iterator} -: 54: * -: 55: * This file contains all of the general iterator-related utility types, -: 56: * such as iterator_traits and struct iterator. -: 57: */ -: 58: -: 59:#ifndef _STL_ITERATOR_BASE_TYPES_H -: 60:#define _STL_ITERATOR_BASE_TYPES_H 1 -: 61: -: 62:#pragma GCC system_header -: 63: -: 64:#include -: 65: -: 66:#if __cplusplus >= 201103L -: 67:# include // For __void_t, is_convertible -: 68:#endif -: 69: -: 70:namespace std _GLIBCXX_VISIBILITY(default) -: 71:{ -: 72:_GLIBCXX_BEGIN_NAMESPACE_VERSION -: 73: -: 74: /** -: 75: * @defgroup iterators Iterators -: 76: * Abstractions for uniform iterating through various underlying types. -: 77: */ -: 78: ///@{ -: 79: -: 80: /** -: 81: * @defgroup iterator_tags Iterator Tags -: 82: * These are empty types, used to distinguish different iterators. The -: 83: * distinction is not made by what they contain, but simply by what they -: 84: * are. Different underlying algorithms can then be used based on the -: 85: * different operations supported by different iterator types. -: 86: */ -: 87: ///@{ -: 88: /// Marking input iterators. -: 89: struct input_iterator_tag { }; -: 90: -: 91: /// Marking output iterators. -: 92: struct output_iterator_tag { }; -: 93: -: 94: /// Forward iterators support a superset of input iterator operations. -: 95: struct forward_iterator_tag : public input_iterator_tag { }; -: 96: -: 97: /// Bidirectional iterators support a superset of forward iterator -: 98: /// operations. -: 99: struct bidirectional_iterator_tag : public forward_iterator_tag { }; -: 100: -: 101: /// Random-access iterators support a superset of bidirectional -: 102: /// iterator operations. -: 103: struct random_access_iterator_tag : public bidirectional_iterator_tag { }; -: 104: ///@} -: 105: -: 106: /** -: 107: * @brief Common %iterator class. -: 108: * -: 109: * This class does nothing but define nested typedefs. %Iterator classes -: 110: * can inherit from this class to save some work. The typedefs are then -: 111: * used in specializations and overloading. -: 112: * -: 113: * In particular, there are no default implementations of requirements -: 114: * such as @c operator++ and the like. (How could there be?) -: 115: */ -: 116: template -: 118: struct iterator -: 119: { -: 120: /// One of the @link iterator_tags tag types@endlink. -: 121: typedef _Category iterator_category; -: 122: /// The type "pointed to" by the iterator. -: 123: typedef _Tp value_type; -: 124: /// Distance between iterators is represented as this type. -: 125: typedef _Distance difference_type; -: 126: /// This type represents a pointer-to-value_type. -: 127: typedef _Pointer pointer; -: 128: /// This type represents a reference-to-value_type. -: 129: typedef _Reference reference; -: 130: }; -: 131: -: 132: /** -: 133: * @brief Traits class for iterators. -: 134: * -: 135: * This class does nothing but define nested typedefs. The general -: 136: * version simply @a forwards the nested typedefs from the Iterator -: 137: * argument. Specialized versions for pointers and pointers-to-const -: 138: * provide tighter, more correct semantics. -: 139: */ -: 140:#if __cplusplus >= 201103L -: 141: // _GLIBCXX_RESOLVE_LIB_DEFECTS -: 142: // 2408. SFINAE-friendly common_type/iterator_traits is missing in C++14 -: 143: template> -: 144: struct __iterator_traits { }; -: 145: -: 146: template -: 147: struct __iterator_traits<_Iterator, -: 148: __void_t> -: 153: { -: 154: typedef typename _Iterator::iterator_category iterator_category; -: 155: typedef typename _Iterator::value_type value_type; -: 156: typedef typename _Iterator::difference_type difference_type; -: 157: typedef typename _Iterator::pointer pointer; -: 158: typedef typename _Iterator::reference reference; -: 159: }; -: 160: -: 161: template -: 162: struct iterator_traits -: 163: : public __iterator_traits<_Iterator> { }; -: 164:#else -: 165: template -: 166: struct iterator_traits -: 167: { -: 168: typedef typename _Iterator::iterator_category iterator_category; -: 169: typedef typename _Iterator::value_type value_type; -: 170: typedef typename _Iterator::difference_type difference_type; -: 171: typedef typename _Iterator::pointer pointer; -: 172: typedef typename _Iterator::reference reference; -: 173: }; -: 174:#endif -: 175: -: 176: /// Partial specialization for pointer types. -: 177: template -: 178: struct iterator_traits<_Tp*> -: 179: { -: 180: typedef random_access_iterator_tag iterator_category; -: 181: typedef _Tp value_type; -: 182: typedef ptrdiff_t difference_type; -: 183: typedef _Tp* pointer; -: 184: typedef _Tp& reference; -: 185: }; -: 186: -: 187: /// Partial specialization for const pointer types. -: 188: template -: 189: struct iterator_traits -: 190: { -: 191: typedef random_access_iterator_tag iterator_category; -: 192: typedef _Tp value_type; -: 193: typedef ptrdiff_t difference_type; -: 194: typedef const _Tp* pointer; -: 195: typedef const _Tp& reference; -: 196: }; -: 197: -: 198: /** -: 199: * This function is not a part of the C++ standard but is syntactic -: 200: * sugar for internal library use only. -: 201: */ -: 202: template -: 203: inline _GLIBCXX_CONSTEXPR -: 204: typename iterator_traits<_Iter>::iterator_category #####: 205: __iterator_category(const _Iter&) #####: 206: { return typename iterator_traits<_Iter>::iterator_category(); } ------------------ _ZSt19__iterator_categoryIPcENSt15iterator_traitsIT_E17iterator_categoryERKS2_: #####: 205: __iterator_category(const _Iter&) #####: 206: { return typename iterator_traits<_Iter>::iterator_category(); } ------------------ _ZSt19__iterator_categoryIPKcENSt15iterator_traitsIT_E17iterator_categoryERKS3_: #####: 205: __iterator_category(const _Iter&) #####: 206: { return typename iterator_traits<_Iter>::iterator_category(); } ------------------ -: 207: -: 208: ///@} -: 209: -: 210:#if __cplusplus < 201103L -: 211: // If _Iterator has a base returns it otherwise _Iterator is returned -: 212: // untouched -: 213: template -: 214: struct _Iter_base -: 215: { -: 216: typedef _Iterator iterator_type; -: 217: static iterator_type _S_base(_Iterator __it) -: 218: { return __it; } -: 219: }; -: 220: -: 221: template -: 222: struct _Iter_base<_Iterator, true> -: 223: { -: 224: typedef typename _Iterator::iterator_type iterator_type; -: 225: static iterator_type _S_base(_Iterator __it) -: 226: { return __it.base(); } -: 227: }; -: 228:#endif -: 229: -: 230:#if __cplusplus >= 201103L -: 231: template -: 232: using _RequireInputIter = typename -: 233: enable_if::iterator_category, -: 235: input_iterator_tag>::value>::type; -: 236:#endif -: 237: -: 238:_GLIBCXX_END_NAMESPACE_VERSION -: 239:} // namespace -: 240: -: 241:#endif /* _STL_ITERATOR_BASE_TYPES_H */ -: 242: <<<<<< EOF # path=tests/tan.cpp.gcov -: 0:Source:tan.cpp -: 0:Graph:./tan.gcno -: 0:Data:./tan.gcda -: 0:Runs:1 -: 1:/*################################################################################ -: 2: ## -: 3: ## Copyright (C) 2016-2022 Keith O'Hara -: 4: ## -: 5: ## This file is part of the GCE-Math C++ library. -: 6: ## -: 7: ## Licensed under the Apache License, Version 2.0 (the "License"); -: 8: ## you may not use this file except in compliance with the License. -: 9: ## You may obtain a copy of the License at -: 10: ## -: 11: ## http://www.apache.org/licenses/LICENSE-2.0 -: 12: ## -: 13: ## Unless required by applicable law or agreed to in writing, software -: 14: ## distributed under the License is distributed on an "AS IS" BASIS, -: 15: ## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -: 16: ## See the License for the specific language governing permissions and -: 17: ## limitations under the License. -: 18: ## -: 19: ################################################################################*/ -: 20: -: 21:#define TEST_PRINT_PRECISION_1 3 -: 22:#define TEST_PRINT_PRECISION_2 18 -: 23: -: 24:#include "gcem_tests.hpp" -: 25: 1: 26:int main() -: 27:{ 1: 28: print_begin("tan"); -: 29: -: 30: // -: 31: -: 32: // static constexpr long double lrgval = std::numeric_limits::max()*100.0L; -: 33: 2*: 34: GCEM_TEST_COMPARE_VALS(gcem::tan,std::tan, 0.0L); 2*: 35: GCEM_TEST_COMPARE_VALS(gcem::tan,std::tan, 0.001L); 2*: 36: GCEM_TEST_COMPARE_VALS(gcem::tan,std::tan, 1.001L); 2*: 37: GCEM_TEST_COMPARE_VALS(gcem::tan,std::tan, 1.5L); 2*: 38: GCEM_TEST_COMPARE_VALS(gcem::tan,std::tan, 11.1L); 2*: 39: GCEM_TEST_COMPARE_VALS(gcem::tan,std::tan, 50.0L); 2*: 40: GCEM_TEST_COMPARE_VALS(gcem::tan,std::tan, -1.5L); -: 41: // GCEM_TEST_COMPARE_VALS(gcem::tan,std::tan, lrgval); -: 42: 2*: 43: GCEM_TEST_COMPARE_VALS(gcem::tan,std::tan, TEST_NAN); -: 44: -: 45: // -: 46: 1: 47: print_final("tan"); -: 48: 1: 49: return 0; -: 50:} <<<<<< EOF # path=tests/tanh.cpp.gcov -: 0:Source:tanh.cpp -: 0:Graph:./tanh.gcno -: 0:Data:./tanh.gcda -: 0:Runs:1 -: 1:/*################################################################################ -: 2: ## -: 3: ## Copyright (C) 2016-2022 Keith O'Hara -: 4: ## -: 5: ## This file is part of the GCE-Math C++ library. -: 6: ## -: 7: ## Licensed under the Apache License, Version 2.0 (the "License"); -: 8: ## you may not use this file except in compliance with the License. -: 9: ## You may obtain a copy of the License at -: 10: ## -: 11: ## http://www.apache.org/licenses/LICENSE-2.0 -: 12: ## -: 13: ## Unless required by applicable law or agreed to in writing, software -: 14: ## distributed under the License is distributed on an "AS IS" BASIS, -: 15: ## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -: 16: ## See the License for the specific language governing permissions and -: 17: ## limitations under the License. -: 18: ## -: 19: ################################################################################*/ -: 20: -: 21:#define TEST_PRINT_PRECISION_1 6 -: 22:#define TEST_PRINT_PRECISION_2 18 -: 23: -: 24:#include "gcem_tests.hpp" -: 25: 1: 26:int main() -: 27:{ 1: 28: print_begin("tanh"); -: 29: -: 30: // -: 31: 2*: 32: GCEM_TEST_COMPARE_VALS(gcem::tanh,std::tanh, 0.0L); 2*: 33: GCEM_TEST_COMPARE_VALS(gcem::tanh,std::tanh, 0.001L); 2*: 34: GCEM_TEST_COMPARE_VALS(gcem::tanh,std::tanh, 0.5L); 2*: 35: GCEM_TEST_COMPARE_VALS(gcem::tanh,std::tanh, -0.5L); 2*: 36: GCEM_TEST_COMPARE_VALS(gcem::tanh,std::tanh, 0.7568025L); 2*: 37: GCEM_TEST_COMPARE_VALS(gcem::tanh,std::tanh, 1.0L); 2*: 38: GCEM_TEST_COMPARE_VALS(gcem::tanh,std::tanh, 5.0L); -: 39: 2*: 40: GCEM_TEST_COMPARE_VALS(gcem::tanh,std::tanh, TEST_NAN); -: 41: -: 42: // -: 43: 1: 44: print_final("tanh"); -: 45: 1: 46: return 0; -: 47:} <<<<<< EOF # path=tests/tgamma.cpp.gcov -: 0:Source:tgamma.cpp -: 0:Graph:./tgamma.gcno -: 0:Data:./tgamma.gcda -: 0:Runs:1 -: 1:/*################################################################################ -: 2: ## -: 3: ## Copyright (C) 2016-2022 Keith O'Hara -: 4: ## -: 5: ## This file is part of the GCE-Math C++ library. -: 6: ## -: 7: ## Licensed under the Apache License, Version 2.0 (the "License"); -: 8: ## you may not use this file except in compliance with the License. -: 9: ## You may obtain a copy of the License at -: 10: ## -: 11: ## http://www.apache.org/licenses/LICENSE-2.0 -: 12: ## -: 13: ## Unless required by applicable law or agreed to in writing, software -: 14: ## distributed under the License is distributed on an "AS IS" BASIS, -: 15: ## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -: 16: ## See the License for the specific language governing permissions and -: 17: ## limitations under the License. -: 18: ## -: 19: ################################################################################*/ -: 20: -: 21:#define TEST_PRINT_PRECISION_1 3 -: 22:#define TEST_PRINT_PRECISION_2 18 -: 23: -: 24:#include "gcem_tests.hpp" -: 25: 1: 26:int main() -: 27:{ 1: 28: print_begin("tgamma"); -: 29: -: 30: // -: 31: 2*: 32: GCEM_TEST_COMPARE_VALS(gcem::tgamma,std::tgamma, 1.5L); 2*: 33: GCEM_TEST_COMPARE_VALS(gcem::tgamma,std::tgamma, 2.7L); 2*: 34: GCEM_TEST_COMPARE_VALS(gcem::tgamma,std::tgamma, 3.0L); 2*: 35: GCEM_TEST_COMPARE_VALS(gcem::tgamma,std::tgamma, 4.0L); 2*: 36: GCEM_TEST_COMPARE_VALS(gcem::tgamma,std::tgamma, 5.0L); -: 37: 2*: 38: GCEM_TEST_COMPARE_VALS(gcem::tgamma,std::tgamma, TEST_NAN); 2*: 39: GCEM_TEST_COMPARE_VALS(gcem::tgamma,std::tgamma, 1.0); -: 40: 2*: 41: GCEM_TEST_COMPARE_VALS(gcem::tgamma,std::tgamma, 0.9); 2*: 42: GCEM_TEST_COMPARE_VALS(gcem::tgamma,std::tgamma, 0.1); 2*: 43: GCEM_TEST_COMPARE_VALS(gcem::tgamma,std::tgamma, 0.001); 2*: 44: GCEM_TEST_COMPARE_VALS(gcem::tgamma,std::tgamma, 0.0); -: 45: 2*: 46: GCEM_TEST_COMPARE_VALS(gcem::tgamma,std::tgamma, -0.1); 2*: 47: GCEM_TEST_COMPARE_VALS(gcem::tgamma,std::tgamma, -1); 2*: 48: GCEM_TEST_COMPARE_VALS(gcem::tgamma,std::tgamma, -1.1); 2*: 49: GCEM_TEST_COMPARE_VALS(gcem::tgamma,std::tgamma, -2); 2*: 50: GCEM_TEST_COMPARE_VALS(gcem::tgamma,std::tgamma, -3); 2*: 51: GCEM_TEST_COMPARE_VALS(gcem::tgamma,std::tgamma, -4); -: 52: -: 53: // -: 54: 1: 55: print_final("tgamma"); -: 56: 1: 57: return 0; -: 58:} <<<<<< EOF # path=tests/trunc.hpp.gcov -: 0:Source:../include/gcem_incl/trunc.hpp -: 0:Graph:./fmod.gcno -: 0:Data:./fmod.gcda -: 0:Runs:1 -: 1:/*################################################################################ -: 2: ## -: 3: ## Copyright (C) 2016-2022 Keith O'Hara -: 4: ## -: 5: ## This file is part of the GCE-Math C++ library. -: 6: ## -: 7: ## Licensed under the Apache License, Version 2.0 (the "License"); -: 8: ## you may not use this file except in compliance with the License. -: 9: ## You may obtain a copy of the License at -: 10: ## -: 11: ## http://www.apache.org/licenses/LICENSE-2.0 -: 12: ## -: 13: ## Unless required by applicable law or agreed to in writing, software -: 14: ## distributed under the License is distributed on an "AS IS" BASIS, -: 15: ## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -: 16: ## See the License for the specific language governing permissions and -: 17: ## limitations under the License. -: 18: ## -: 19: ################################################################################*/ -: 20: -: 21:#ifndef _gcem_trunc_HPP -: 22:#define _gcem_trunc_HPP -: 23: -: 24:namespace internal -: 25:{ -: 26: -: 27:template -: 28:constexpr -: 29:T #####: 30:trunc_int(const T x) -: 31:noexcept -: 32:{ #####: 33: return( T(static_cast(x)) ); -: 34:} -: 35: -: 36:template -: 37:constexpr -: 38:T -: 39:trunc_check_internal(const T x) -: 40:noexcept -: 41:{ -: 42: return x; -: 43:} -: 44: -: 45:template<> -: 46:constexpr -: 47:float -: 48:trunc_check_internal(const float x) -: 49:noexcept -: 50:{ -: 51: return( abs(x) >= 8388608.f ? \ -: 52: // if -: 53: x : \ -: 54: // else -: 55: trunc_int(x) ); -: 56:} -: 57: -: 58:template<> -: 59:constexpr -: 60:double #####: 61:trunc_check_internal(const double x) -: 62:noexcept -: 63:{ #####: 64: return( abs(x) >= 4503599627370496. ? \ -: 65: // if -: 66: x : \ -: 67: // else #####: 68: trunc_int(x) ); -: 69:} -: 70: -: 71:template<> -: 72:constexpr -: 73:long double -: 74:trunc_check_internal(const long double x) -: 75:noexcept -: 76:{ -: 77: return( abs(x) >= 9223372036854775808.l ? \ -: 78: // if -: 79: x : \ -: 80: // else -: 81: ((long double)static_cast(abs(x))) * sgn(x) ); -: 82:} -: 83: -: 84:template -: 85:constexpr -: 86:T 3: 87:trunc_check(const T x) -: 88:noexcept -: 89:{ -: 90: return( // NaN check 3*: 91: is_nan(x) ? \ 3: 92: GCLIM::quiet_NaN() : -: 93: // +/- infinite #####: 94: !is_finite(x) ? \ -: 95: x : -: 96: // signed-zero cases #####: 97: GCLIM::min() > abs(x) ? \ -: 98: x : -: 99: // else 3*: 100: trunc_check_internal(x) ); -: 101:} -: 102: -: 103:} -: 104: -: 105:/** -: 106: * Compile-time trunc function -: 107: * -: 108: * @param x a real-valued input. -: 109: * @return computes the trunc-value of the input, essentially returning the integer part of the input. -: 110: */ -: 111: -: 112:template -: 113:constexpr -: 114:return_t 3: 115:trunc(const T x) -: 116:noexcept -: 117:{ 3: 118: return internal::trunc_check( static_cast>(x) ); -: 119:} -: 120: -: 121:#endif <<<<<< EOF # path=tests/type_traits.h.gcov -: 0:Source:/usr/include/c++/9/ext/type_traits.h -: 0:Graph:log.gcno -: 0:Data:log.gcda -: 0:Runs:2 -: 1:// -*- C++ -*- -: 2: -: 3:// Copyright (C) 2005-2019 Free Software Foundation, Inc. -: 4:// -: 5:// This file is part of the GNU ISO C++ Library. This library is free -: 6:// software; you can redistribute it and/or modify it under the terms -: 7:// of the GNU General Public License as published by the Free Software -: 8:// Foundation; either version 3, or (at your option) any later -: 9:// version. -: 10: -: 11:// This library is distributed in the hope that it will be useful, but -: 12:// WITHOUT ANY WARRANTY; without even the implied warranty of -: 13:// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -: 14:// General Public License for more details. -: 15: -: 16:// Under Section 7 of GPL version 3, you are granted additional -: 17:// permissions described in the GCC Runtime Library Exception, version -: 18:// 3.1, as published by the Free Software Foundation. -: 19: -: 20:// You should have received a copy of the GNU General Public License and -: 21:// a copy of the GCC Runtime Library Exception along with this program; -: 22:// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see -: 23:// . -: 24: -: 25:/** @file ext/type_traits.h -: 26: * This file is a GNU extension to the Standard C++ Library. -: 27: */ -: 28: -: 29:#ifndef _EXT_TYPE_TRAITS -: 30:#define _EXT_TYPE_TRAITS 1 -: 31: -: 32:#pragma GCC system_header -: 33: -: 34:#include -: 35:#include -: 36: -: 37:extern "C++" { -: 38: -: 39:namespace __gnu_cxx _GLIBCXX_VISIBILITY(default) -: 40:{ -: 41:_GLIBCXX_BEGIN_NAMESPACE_VERSION -: 42: -: 43: // Define a nested type if some predicate holds. -: 44: template -: 45: struct __enable_if -: 46: { }; -: 47: -: 48: template -: 49: struct __enable_if -: 50: { typedef _Tp __type; }; -: 51: -: 52: -: 53: // Conditional expression for types. If true, first, if false, second. -: 54: template -: 55: struct __conditional_type -: 56: { typedef _Iftrue __type; }; -: 57: -: 58: template -: 59: struct __conditional_type -: 60: { typedef _Iffalse __type; }; -: 61: -: 62: -: 63: // Given an integral builtin type, return the corresponding unsigned type. -: 64: template -: 65: struct __add_unsigned -: 66: { -: 67: private: -: 68: typedef __enable_if::__value, _Tp> __if_type; -: 69: -: 70: public: -: 71: typedef typename __if_type::__type __type; -: 72: }; -: 73: -: 74: template<> -: 75: struct __add_unsigned -: 76: { typedef unsigned char __type; }; -: 77: -: 78: template<> -: 79: struct __add_unsigned -: 80: { typedef unsigned char __type; }; -: 81: -: 82: template<> -: 83: struct __add_unsigned -: 84: { typedef unsigned short __type; }; -: 85: -: 86: template<> -: 87: struct __add_unsigned -: 88: { typedef unsigned int __type; }; -: 89: -: 90: template<> -: 91: struct __add_unsigned -: 92: { typedef unsigned long __type; }; -: 93: -: 94: template<> -: 95: struct __add_unsigned -: 96: { typedef unsigned long long __type; }; -: 97: -: 98: // Declare but don't define. -: 99: template<> -: 100: struct __add_unsigned; -: 101: -: 102: template<> -: 103: struct __add_unsigned; -: 104: -: 105: -: 106: // Given an integral builtin type, return the corresponding signed type. -: 107: template -: 108: struct __remove_unsigned -: 109: { -: 110: private: -: 111: typedef __enable_if::__value, _Tp> __if_type; -: 112: -: 113: public: -: 114: typedef typename __if_type::__type __type; -: 115: }; -: 116: -: 117: template<> -: 118: struct __remove_unsigned -: 119: { typedef signed char __type; }; -: 120: -: 121: template<> -: 122: struct __remove_unsigned -: 123: { typedef signed char __type; }; -: 124: -: 125: template<> -: 126: struct __remove_unsigned -: 127: { typedef short __type; }; -: 128: -: 129: template<> -: 130: struct __remove_unsigned -: 131: { typedef int __type; }; -: 132: -: 133: template<> -: 134: struct __remove_unsigned -: 135: { typedef long __type; }; -: 136: -: 137: template<> -: 138: struct __remove_unsigned -: 139: { typedef long long __type; }; -: 140: -: 141: // Declare but don't define. -: 142: template<> -: 143: struct __remove_unsigned; -: 144: -: 145: template<> -: 146: struct __remove_unsigned; -: 147: -: 148: -: 149: // For use in string and vstring. -: 150: template -: 151: inline bool #####: 152: __is_null_pointer(_Type* __ptr) #####: 153: { return __ptr == 0; } ------------------ _ZN9__gnu_cxx17__is_null_pointerIcEEbPT_: #####: 152: __is_null_pointer(_Type* __ptr) #####: 153: { return __ptr == 0; } ------------------ _ZN9__gnu_cxx17__is_null_pointerIKcEEbPT_: #####: 152: __is_null_pointer(_Type* __ptr) #####: 153: { return __ptr == 0; } ------------------ -: 154: -: 155: template -: 156: inline bool -: 157: __is_null_pointer(_Type) -: 158: { return false; } -: 159: -: 160:#if __cplusplus >= 201103L -: 161: inline bool -: 162: __is_null_pointer(std::nullptr_t) -: 163: { return true; } -: 164:#endif -: 165: -: 166: // For complex and cmath -: 167: template::__value> -: 168: struct __promote -: 169: { typedef double __type; }; -: 170: -: 171: // No nested __type member for non-integer non-floating point types, -: 172: // allows this type to be used for SFINAE to constrain overloads in -: 173: // and to only the intended types. -: 174: template -: 175: struct __promote<_Tp, false> -: 176: { }; -: 177: -: 178: template<> -: 179: struct __promote -: 180: { typedef long double __type; }; -: 181: -: 182: template<> -: 183: struct __promote -: 184: { typedef double __type; }; -: 185: -: 186: template<> -: 187: struct __promote -: 188: { typedef float __type; }; -: 189: -: 190: template::__type, -: 192: typename _Up2 = typename __promote<_Up>::__type> -: 193: struct __promote_2 -: 194: { -: 195: typedef __typeof__(_Tp2() + _Up2()) __type; -: 196: }; -: 197: -: 198: template::__type, -: 200: typename _Up2 = typename __promote<_Up>::__type, -: 201: typename _Vp2 = typename __promote<_Vp>::__type> -: 202: struct __promote_3 -: 203: { -: 204: typedef __typeof__(_Tp2() + _Up2() + _Vp2()) __type; -: 205: }; -: 206: -: 207: template::__type, -: 209: typename _Up2 = typename __promote<_Up>::__type, -: 210: typename _Vp2 = typename __promote<_Vp>::__type, -: 211: typename _Wp2 = typename __promote<_Wp>::__type> -: 212: struct __promote_4 -: 213: { -: 214: typedef __typeof__(_Tp2() + _Up2() + _Vp2() + _Wp2()) __type; -: 215: }; -: 216: -: 217:_GLIBCXX_END_NAMESPACE_VERSION -: 218:} // namespace -: 219:} // extern "C++" -: 220: -: 221:#endif <<<<<< EOF