numeric 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. // <experimental/numeric> -*- C++ -*-
  2. // Copyright (C) 2015-2020 Free Software Foundation, Inc.
  3. //
  4. // This file is part of the GNU ISO C++ Library. This library is free
  5. // software; you can redistribute it and/or modify it under the
  6. // terms of the GNU General Public License as published by the
  7. // Free Software Foundation; either version 3, or (at your option)
  8. // any later version.
  9. // This library is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU General Public License for more details.
  13. // Under Section 7 of GPL version 3, you are granted additional
  14. // permissions described in the GCC Runtime Library Exception, version
  15. // 3.1, as published by the Free Software Foundation.
  16. // You should have received a copy of the GNU General Public License and
  17. // a copy of the GCC Runtime Library Exception along with this program;
  18. // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
  19. // <http://www.gnu.org/licenses/>.
  20. /** @file experimental/numeric
  21. * This is a TS C++ Library header.
  22. * @ingroup libfund-ts
  23. */
  24. //
  25. // N4336 Working Draft, C++ Extensions for Library Fundamentals, Version 2
  26. //
  27. #ifndef _GLIBCXX_EXPERIMENTAL_NUMERIC
  28. #define _GLIBCXX_EXPERIMENTAL_NUMERIC 1
  29. #pragma GCC system_header
  30. #if __cplusplus >= 201402L
  31. #include <numeric>
  32. #include <experimental/type_traits>
  33. namespace std _GLIBCXX_VISIBILITY(default)
  34. {
  35. _GLIBCXX_BEGIN_NAMESPACE_VERSION
  36. namespace experimental
  37. {
  38. inline namespace fundamentals_v2
  39. {
  40. #define __cpp_lib_experimental_gcd_lcm 201411
  41. /// Greatest common divisor
  42. template<typename _Mn, typename _Nn>
  43. constexpr common_type_t<_Mn, _Nn>
  44. gcd(_Mn __m, _Nn __n)
  45. {
  46. static_assert(is_integral_v<_Mn>, "gcd arguments are integers");
  47. static_assert(is_integral_v<_Nn>, "gcd arguments are integers");
  48. static_assert(!is_same_v<remove_cv_t<_Mn>, bool>,
  49. "gcd arguments are not bools");
  50. static_assert(!is_same_v<remove_cv_t<_Nn>, bool>,
  51. "gcd arguments are not bools");
  52. return std::__detail::__gcd(__m, __n);
  53. }
  54. /// Least common multiple
  55. template<typename _Mn, typename _Nn>
  56. constexpr common_type_t<_Mn, _Nn>
  57. lcm(_Mn __m, _Nn __n)
  58. {
  59. static_assert(is_integral_v<_Mn>, "lcm arguments are integers");
  60. static_assert(is_integral_v<_Nn>, "lcm arguments are integers");
  61. static_assert(!is_same_v<remove_cv_t<_Mn>, bool>,
  62. "lcm arguments are not bools");
  63. static_assert(!is_same_v<remove_cv_t<_Nn>, bool>,
  64. "lcm arguments are not bools");
  65. return std::__detail::__lcm(__m, __n);
  66. }
  67. } // namespace fundamentals_v2
  68. } // namespace experimental
  69. _GLIBCXX_END_NAMESPACE_VERSION
  70. } // namespace std
  71. #endif // __cplusplus <= 201103L
  72. #endif // _GLIBCXX_EXPERIMENTAL_NUMERIC