Imported Upstream version 4.8.1
[platform/upstream/gcc48.git] / libstdc++-v3 / include / bits / stl_algobase.h
index 5cee10a..a90881f 100644 (file)
@@ -1,7 +1,6 @@
 // Core algorithmic facilities -*- C++ -*-
 
-// Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010,
-// 2011 Free Software Foundation, Inc.
+// Copyright (C) 2001-2013 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
@@ -74,6 +73,7 @@ namespace std _GLIBCXX_VISIBILITY(default)
 {
 _GLIBCXX_BEGIN_NAMESPACE_VERSION
 
+#if __cplusplus < 201103L
   // See http://gcc.gnu.org/ml/libstdc++/2004-08/msg00167.html: in a
   // nutshell, we are partially implementing the resolution of DR 187,
   // when it's safe, i.e., the value_types are equal.
@@ -102,6 +102,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
           swap(*__a, *__b);
         }
     };
+#endif
 
   /**
    *  @brief Swaps the contents of two iterators.
@@ -117,16 +118,18 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
     inline void
     iter_swap(_ForwardIterator1 __a, _ForwardIterator2 __b)
     {
-      typedef typename iterator_traits<_ForwardIterator1>::value_type
-       _ValueType1;
-      typedef typename iterator_traits<_ForwardIterator2>::value_type
-       _ValueType2;
-
       // concept requirements
       __glibcxx_function_requires(_Mutable_ForwardIteratorConcept<
                                  _ForwardIterator1>)
       __glibcxx_function_requires(_Mutable_ForwardIteratorConcept<
                                  _ForwardIterator2>)
+
+#if __cplusplus < 201103L
+      typedef typename iterator_traits<_ForwardIterator1>::value_type
+       _ValueType1;
+      typedef typename iterator_traits<_ForwardIterator2>::value_type
+       _ValueType2;
+
       __glibcxx_function_requires(_ConvertibleConcept<_ValueType1,
                                  _ValueType2>)
       __glibcxx_function_requires(_ConvertibleConcept<_ValueType2,
@@ -140,6 +143,9 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
        && __are_same<_ValueType1&, _ReferenceType1>::__value
        && __are_same<_ValueType2&, _ReferenceType2>::__value>::
        iter_swap(__a, __b);
+#else
+      swap(*__a, *__b);
+#endif
     }
 
   /**
@@ -301,7 +307,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
        }
     };
 
-#ifdef __GXX_EXPERIMENTAL_CXX0X__
+#if __cplusplus >= 201103L
   template<typename _Category>
     struct __copy_move<true, false, _Category>
     {
@@ -334,7 +340,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
        }
     };
 
-#ifdef __GXX_EXPERIMENTAL_CXX0X__
+#if __cplusplus >= 201103L
   template<>
     struct __copy_move<true, false, random_access_iterator_tag>
     {
@@ -454,7 +460,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
               __result));
     }
 
-#ifdef __GXX_EXPERIMENTAL_CXX0X__
+#if __cplusplus >= 201103L
   /**
    *  @brief Moves the range [first,last) into result.
    *  @ingroup mutating_algorithms
@@ -504,7 +510,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
        }
     };
 
-#ifdef __GXX_EXPERIMENTAL_CXX0X__
+#if __cplusplus >= 201103L
   template<typename _Category>
     struct __copy_move_backward<true, false, _Category>
     {
@@ -533,7 +539,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
        }
     };
 
-#ifdef __GXX_EXPERIMENTAL_CXX0X__
+#if __cplusplus >= 201103L
   template<>
     struct __copy_move_backward<true, false, random_access_iterator_tag>
     {
@@ -625,7 +631,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
               __result));
     }
 
-#ifdef __GXX_EXPERIMENTAL_CXX0X__
+#if __cplusplus >= 201103L
   /**
    *  @brief Moves the range [first,last) into result.
    *  @ingroup mutating_algorithms
@@ -937,8 +943,10 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
     lower_bound(_ForwardIterator __first, _ForwardIterator __last,
                const _Tp& __val)
     {
+#ifdef _GLIBCXX_CONCEPT_CHECKS
       typedef typename iterator_traits<_ForwardIterator>::value_type
        _ValueType;
+#endif
       typedef typename iterator_traits<_ForwardIterator>::difference_type
        _DistanceType;
 
@@ -968,37 +976,27 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 
   /// This is a helper function for the sort routines and for random.tcc.
   //  Precondition: __n > 0.
-  template<typename _Size>
-    inline _Size
-    __lg(_Size __n)
-    {
-      _Size __k;
-      for (__k = 0; __n != 0; __n >>= 1)
-       ++__k;
-      return __k - 1;
-    }
-
-  inline int
+  inline _GLIBCXX_CONSTEXPR int
   __lg(int __n)
   { return sizeof(int) * __CHAR_BIT__  - 1 - __builtin_clz(__n); }
 
-  inline unsigned
+  inline _GLIBCXX_CONSTEXPR unsigned
   __lg(unsigned __n)
   { return sizeof(int) * __CHAR_BIT__  - 1 - __builtin_clz(__n); }
 
-  inline long
+  inline _GLIBCXX_CONSTEXPR long
   __lg(long __n)
   { return sizeof(long) * __CHAR_BIT__ - 1 - __builtin_clzl(__n); }
 
-  inline unsigned long
+  inline _GLIBCXX_CONSTEXPR unsigned long
   __lg(unsigned long __n)
   { return sizeof(long) * __CHAR_BIT__ - 1 - __builtin_clzl(__n); }
 
-  inline long long
+  inline _GLIBCXX_CONSTEXPR long long
   __lg(long long __n)
   { return sizeof(long long) * __CHAR_BIT__ - 1 - __builtin_clzll(__n); }
 
-  inline unsigned long long
+  inline _GLIBCXX_CONSTEXPR unsigned long long
   __lg(unsigned long long __n)
   { return sizeof(long long) * __CHAR_BIT__ - 1 - __builtin_clzll(__n); }
 
@@ -1086,9 +1084,11 @@ _GLIBCXX_BEGIN_NAMESPACE_ALGO
     lexicographical_compare(_II1 __first1, _II1 __last1,
                            _II2 __first2, _II2 __last2)
     {
+#ifdef _GLIBCXX_CONCEPT_CHECKS
       // concept requirements
       typedef typename iterator_traits<_II1>::value_type _ValueType1;
       typedef typename iterator_traits<_II2>::value_type _ValueType2;
+#endif
       __glibcxx_function_requires(_InputIteratorConcept<_II1>)
       __glibcxx_function_requires(_InputIteratorConcept<_II2>)
       __glibcxx_function_requires(_LessThanOpConcept<_ValueType1, _ValueType2>)