diff options
Diffstat (limited to 'contrib/libstdc++/include/ext/numeric')
-rw-r--r-- | contrib/libstdc++/include/ext/numeric | 45 |
1 files changed, 24 insertions, 21 deletions
diff --git a/contrib/libstdc++/include/ext/numeric b/contrib/libstdc++/include/ext/numeric index 40edf07..290d032 100644 --- a/contrib/libstdc++/include/ext/numeric +++ b/contrib/libstdc++/include/ext/numeric @@ -1,6 +1,6 @@ // Numeric extensions -*- C++ -*- -// Copyright (C) 2002 Free Software Foundation, Inc. +// Copyright (C) 2002, 2004, 2005 Free Software Foundation, Inc. // // This file is part of the GNU ISO C++ Library. This library is free // software; you can redistribute it and/or modify it under the @@ -15,7 +15,7 @@ // You should have received a copy of the GNU General Public License along // with this library; see the file COPYING. If not, write to the Free -// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, +// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, // USA. // As a special exception, you may use this file as part of a free software @@ -55,8 +55,7 @@ /** @file ext/numeric * This file is a GNU extension to the Standard C++ Library (possibly - * containing extensions from the HP/SGI STL subset). You should only - * include this header if you are using GCC 3 or later. + * containing extensions from the HP/SGI STL subset). */ #ifndef _EXT_NUMERIC @@ -69,8 +68,8 @@ #include <ext/functional> // For identity_element -namespace __gnu_cxx -{ +_GLIBCXX_BEGIN_NAMESPACE(__gnu_cxx) + // Returns __x ** __n, where __n >= 0. _Note that "multiplication" // is required to be associative, but not necessarily commutative. template<typename _Tp, typename _Integer, typename _MonoidOperation> @@ -79,22 +78,25 @@ namespace __gnu_cxx { if (__n == 0) return identity_element(__monoid_op); - else { - while ((__n & 1) == 0) { + else + { + while ((__n & 1) == 0) + { + __n >>= 1; + __x = __monoid_op(__x, __x); + } + + _Tp __result = __x; __n >>= 1; - __x = __monoid_op(__x, __x); + while (__n != 0) + { + __x = __monoid_op(__x, __x); + if ((__n & 1) != 0) + __result = __monoid_op(__result, __x); + __n >>= 1; + } + return __result; } - - _Tp __result = __x; - __n >>= 1; - while (__n != 0) { - __x = __monoid_op(__x, __x); - if ((__n & 1) != 0) - __result = __monoid_op(__result, __x); - __n >>= 1; - } - return __result; - } } template<typename _Tp, typename _Integer> @@ -142,7 +144,8 @@ namespace __gnu_cxx while (__first != __last) *__first++ = __value++; } -} // namespace __gnu_cxx + +_GLIBCXX_END_NAMESPACE #endif |