libstdc++
|
00001 // <experimental/numeric> -*- C++ -*- 00002 00003 // Copyright (C) 2015-2019 Free Software Foundation, Inc. 00004 // 00005 // This file is part of the GNU ISO C++ Library. This library is free 00006 // software; you can redistribute it and/or modify it under the 00007 // terms of the GNU General Public License as published by the 00008 // Free Software Foundation; either version 3, or (at your option) 00009 // any later version. 00010 00011 // This library is distributed in the hope that it will be useful, 00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 // GNU General Public License for more details. 00015 00016 // Under Section 7 of GPL version 3, you are granted additional 00017 // permissions described in the GCC Runtime Library Exception, version 00018 // 3.1, as published by the Free Software Foundation. 00019 00020 // You should have received a copy of the GNU General Public License and 00021 // a copy of the GCC Runtime Library Exception along with this program; 00022 // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see 00023 // <http://www.gnu.org/licenses/>. 00024 00025 /** @file experimental/numeric 00026 * This is a TS C++ Library header. 00027 */ 00028 00029 // 00030 // N4336 Working Draft, C++ Extensions for Library Fundamentals, Version 2 00031 // 00032 00033 #ifndef _GLIBCXX_EXPERIMENTAL_NUMERIC 00034 #define _GLIBCXX_EXPERIMENTAL_NUMERIC 1 00035 00036 #pragma GCC system_header 00037 00038 #if __cplusplus >= 201402L 00039 00040 #include <numeric> 00041 #include <experimental/type_traits> 00042 00043 namespace std _GLIBCXX_VISIBILITY(default) 00044 { 00045 _GLIBCXX_BEGIN_NAMESPACE_VERSION 00046 00047 namespace experimental 00048 { 00049 inline namespace fundamentals_v2 00050 { 00051 #define __cpp_lib_experimental_gcd_lcm 201411 00052 00053 /// Greatest common divisor 00054 template<typename _Mn, typename _Nn> 00055 constexpr common_type_t<_Mn, _Nn> 00056 gcd(_Mn __m, _Nn __n) 00057 { 00058 static_assert(is_integral_v<_Mn>, "gcd arguments are integers"); 00059 static_assert(is_integral_v<_Nn>, "gcd arguments are integers"); 00060 static_assert(!is_same_v<remove_cv_t<_Mn>, bool>, 00061 "gcd arguments are not bools"); 00062 static_assert(!is_same_v<remove_cv_t<_Nn>, bool>, 00063 "gcd arguments are not bools"); 00064 return std::__detail::__gcd(__m, __n); 00065 } 00066 00067 /// Least common multiple 00068 template<typename _Mn, typename _Nn> 00069 constexpr common_type_t<_Mn, _Nn> 00070 lcm(_Mn __m, _Nn __n) 00071 { 00072 static_assert(is_integral_v<_Mn>, "lcm arguments are integers"); 00073 static_assert(is_integral_v<_Nn>, "lcm arguments are integers"); 00074 static_assert(!is_same_v<remove_cv_t<_Mn>, bool>, 00075 "lcm arguments are not bools"); 00076 static_assert(!is_same_v<remove_cv_t<_Nn>, bool>, 00077 "lcm arguments are not bools"); 00078 return std::__detail::__lcm(__m, __n); 00079 } 00080 } // namespace fundamentals_v2 00081 } // namespace experimental 00082 00083 _GLIBCXX_END_NAMESPACE_VERSION 00084 } // namespace std 00085 00086 #endif // __cplusplus <= 201103L 00087 00088 #endif // _GLIBCXX_EXPERIMENTAL_NUMERIC