numeric 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. // <experimental/numeric> -*- C++ -*-
  2. // Copyright (C) 2015-2018 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. */
  23. //
  24. // N4336 Working Draft, C++ Extensions for Library Fundamentals, Version 2
  25. //
  26. #ifndef _GLIBCXX_EXPERIMENTAL_NUMERIC
  27. #define _GLIBCXX_EXPERIMENTAL_NUMERIC 1
  28. #pragma GCC system_header
  29. #if __cplusplus >= 201402L
  30. #include <numeric>
  31. #include <experimental/type_traits>
  32. namespace std _GLIBCXX_VISIBILITY(default)
  33. {
  34. _GLIBCXX_BEGIN_NAMESPACE_VERSION
  35. namespace experimental
  36. {
  37. inline namespace fundamentals_v2
  38. {
  39. #define __cpp_lib_experimental_gcd_lcm 201411
  40. /// Greatest common divisor
  41. template<typename _Mn, typename _Nn>
  42. constexpr common_type_t<_Mn, _Nn>
  43. gcd(_Mn __m, _Nn __n)
  44. {
  45. static_assert(is_integral_v<_Mn>, "gcd arguments are integers");
  46. static_assert(is_integral_v<_Nn>, "gcd arguments are integers");
  47. static_assert(!is_same_v<remove_cv_t<_Mn>, bool>,
  48. "gcd arguments are not bools");
  49. static_assert(!is_same_v<remove_cv_t<_Nn>, bool>,
  50. "gcd arguments are not bools");
  51. return std::__detail::__gcd(__m, __n);
  52. }
  53. /// Least common multiple
  54. template<typename _Mn, typename _Nn>
  55. constexpr common_type_t<_Mn, _Nn>
  56. lcm(_Mn __m, _Nn __n)
  57. {
  58. static_assert(is_integral_v<_Mn>, "lcm arguments are integers");
  59. static_assert(is_integral_v<_Nn>, "lcm arguments are integers");
  60. static_assert(!is_same_v<remove_cv_t<_Mn>, bool>,
  61. "lcm arguments are not bools");
  62. static_assert(!is_same_v<remove_cv_t<_Nn>, bool>,
  63. "lcm arguments are not bools");
  64. return std::__detail::__lcm(__m, __n);
  65. }
  66. } // namespace fundamentals_v2
  67. } // namespace experimental
  68. _GLIBCXX_END_NAMESPACE_VERSION
  69. } // namespace std
  70. #endif // __cplusplus <= 201103L
  71. #endif // _GLIBCXX_EXPERIMENTAL_NUMERIC