libstdc++
|
00001 // <experimental/numeric> -*- C++ -*- 00002 00003 // Copyright (C) 2015-2017 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 <= 201103L 00039 # include <bits/c++14_warning.h> 00040 #else 00041 00042 #include <numeric> 00043 #include <experimental/type_traits> 00044 00045 namespace std _GLIBCXX_VISIBILITY(default) 00046 { 00047 namespace experimental 00048 { 00049 inline namespace fundamentals_v2 00050 { 00051 _GLIBCXX_BEGIN_NAMESPACE_VERSION 00052 00053 #define __cpp_lib_experimental_gcd_lcm 201411 00054 00055 /// Greatest common divisor 00056 template<typename _Mn, typename _Nn> 00057 constexpr common_type_t<_Mn, _Nn> 00058 gcd(_Mn __m, _Nn __n) 00059 { 00060 static_assert(is_integral<_Mn>::value, "gcd arguments are integers"); 00061 static_assert(is_integral<_Nn>::value, "gcd arguments are integers"); 00062 static_assert(!is_same<_Mn, bool>::value, "gcd arguments are not bools"); 00063 static_assert(!is_same<_Nn, bool>::value, "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<_Mn>::value, "lcm arguments are integers"); 00073 static_assert(is_integral<_Nn>::value, "lcm arguments are integers"); 00074 static_assert(!is_same<_Mn, bool>::value, "lcm arguments are not bools"); 00075 static_assert(!is_same<_Nn, bool>::value, "lcm arguments are not bools"); 00076 return std::__detail::__lcm(__m, __n); 00077 } 00078 00079 _GLIBCXX_END_NAMESPACE_VERSION 00080 } // namespace fundamentals_v2 00081 } // namespace experimental 00082 } // namespace std 00083 00084 #endif // __cplusplus <= 201103L 00085 00086 #endif // _GLIBCXX_EXPERIMENTAL_NUMERIC