OSDN Git Service

Licensing changes to GPLv3 resp. GPLv3 with GCC Runtime Exception.
[pf3gnuchains/gcc-fork.git] / libstdc++-v3 / include / std / valarray
index 95f2701..79d3a16 100644 (file)
@@ -1,12 +1,13 @@
 // The template and inlines for the -*- C++ -*- valarray class.
 
-// Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2004, 2005, 2006
+// Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
+// 2006, 2007, 2009
 // 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
 // terms of the GNU General Public License as published by the
-// Free Software Foundation; either version 2, or (at your option)
+// Free Software Foundation; either version 3, or (at your option)
 // any later version.
 
 // This library is distributed in the hope that it will be useful,
 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 // GNU General Public License for more details.
 
-// 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, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
-// USA.
+// Under Section 7 of GPL version 3, you are granted additional
+// permissions described in the GCC Runtime Library Exception, version
+// 3.1, as published by the Free Software Foundation.
 
-// As a special exception, you may use this file as part of a free software
-// library without restriction.  Specifically, if other files instantiate
-// templates or use macros or inline functions from this file, or you compile
-// this file and link it with other files to produce an executable, this
-// file does not by itself cause the resulting executable to be covered by
-// the GNU General Public License.  This exception does not however
-// invalidate any other reasons why the executable file might be covered by
-// the GNU General Public License.
+// You should have received a copy of the GNU General Public License and
+// a copy of the GCC Runtime Library Exception along with this program;
+// see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
+// <http://www.gnu.org/licenses/>.
 
 /** @file valarray
  *  This is a Standard C++ Library header. 
 #include <bits/c++config.h>
 #include <cstddef>
 #include <cmath>
-#include <cstdlib>
-#include <numeric>
 #include <algorithm>
 #include <debug/debug.h>
+#include <initializer_list>
 
 _GLIBCXX_BEGIN_NAMESPACE(std)
 
@@ -95,6 +90,14 @@ _GLIBCXX_END_NAMESPACE
 _GLIBCXX_BEGIN_NAMESPACE(std)
 
   /**
+   * @defgroup numeric_arrays Numeric Arrays
+   * @ingroup numerics
+   *
+   * Classes and functions for representing and manipulating arrays of elements.
+   * @{
+   */
+
+  /**
    *  @brief  Smart array designed to support numeric processing.
    *
    *  A valarray is an array that provides constraints intended to allow for
@@ -145,6 +148,11 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
       ///  Construct an array with the same size and values in @a ia.
       valarray(const indirect_array<_Tp>&);
 
+#ifdef __GXX_EXPERIMENTAL_CXX0X__
+      ///  Construct an array with an initializer_list of values.
+      valarray(initializer_list<_Tp>);
+#endif
+
       template<class _Dom>
        valarray(const _Expr<_Dom, _Tp>& __e);
 
@@ -210,6 +218,18 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
        */
       valarray<_Tp>& operator=(const indirect_array<_Tp>&);
 
+#ifdef __GXX_EXPERIMENTAL_CXX0X__
+      /**
+       *  @brief  Assign elements to an initializer_list.
+       *
+       *  Assign elements of array to values in @a l.  Results are undefined
+       *  if @a l does not have the same size as this array.
+       *
+       *  @param  l  initializer_list to get values from.
+       */
+      valarray& operator=(initializer_list<_Tp>);
+#endif
+
       template<class _Dom> valarray<_Tp>&
        operator= (const _Expr<_Dom, _Tp>&);
 
@@ -535,6 +555,8 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
       return _M_data[__i];
     }
 
+  // @} group numeric_arrays
+
 _GLIBCXX_END_NAMESPACE
 
 #include <bits/valarray_after.h>
@@ -546,6 +568,11 @@ _GLIBCXX_END_NAMESPACE
 
 _GLIBCXX_BEGIN_NAMESPACE(std)
 
+  /**
+   * @addtogroup numeric_arrays
+   * @{
+   */
+
   template<typename _Tp>
     inline
     valarray<_Tp>::valarray() : _M_size(0), _M_data(0) {}
@@ -616,6 +643,14 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
        (__ia._M_array, __ia._M_index, _Array<_Tp>(_M_data), _M_size);
     }
 
+#ifdef __GXX_EXPERIMENTAL_CXX0X__
+  template<typename _Tp>
+    inline
+    valarray<_Tp>::valarray(initializer_list<_Tp> __l)
+      : _M_size(__l.size()), _M_data(__valarray_get_storage<_Tp>(__l.size()))
+    { std::__valarray_copy_construct (__l.begin(), __l.end(), _M_data); }
+#endif
+
   template<typename _Tp> template<class _Dom>
     inline
     valarray<_Tp>::valarray(const _Expr<_Dom, _Tp>& __e)
@@ -639,6 +674,16 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
       return *this;
     }
 
+#ifdef __GXX_EXPERIMENTAL_CXX0X__
+  template<typename _Tp>
+    inline valarray<_Tp>&
+    valarray<_Tp>::operator=(initializer_list<_Tp> __l)
+    {
+      _GLIBCXX_DEBUG_ASSERT(_M_size == __l.size());
+      std::__valarray_copy(__l.begin(), __l.size(), _M_data);
+    }
+#endif
+
   template<typename _Tp>
     inline valarray<_Tp>&
     valarray<_Tp>::operator=(const _Tp& __t)
@@ -782,27 +827,31 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
      inline valarray<_Tp>
      valarray<_Tp>::shift(int __n) const
      {
-       if (_M_size == 0 || __n == 0)
-        return *this;
-     
        valarray<_Tp> __ret;
+
+       if (_M_size == 0)
+        return __ret;
+
        _Tp* __restrict__ __tmp_M_data =
         std::__valarray_get_storage<_Tp>(_M_size);
 
-       if (__n > 0)      // shift left
+       if (__n == 0)
+        std::__valarray_copy_construct(_M_data,
+                                       _M_data + _M_size, __tmp_M_data);
+       else if (__n > 0)      // shift left
         {
           if (size_t(__n) > _M_size)
-            __n = _M_size;
+            __n = int(_M_size);
 
           std::__valarray_copy_construct(_M_data + __n,
                                          _M_data + _M_size, __tmp_M_data);
           std::__valarray_default_construct(__tmp_M_data + _M_size - __n,
                                             __tmp_M_data + _M_size);
         }
-       else              // shift right
+       else                   // shift right
         {
-          if (size_t(-__n) > _M_size)
-            __n = -_M_size;
+          if (-size_t(__n) > _M_size)
+            __n = -int(_M_size);
 
           std::__valarray_copy_construct(_M_data, _M_data + _M_size + __n,
                                          __tmp_M_data - __n);
@@ -819,27 +868,31 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
      inline valarray<_Tp>
      valarray<_Tp>::cshift(int __n) const
      {
-       if (_M_size == 0 || __n == 0)
-        return *this;
-
        valarray<_Tp> __ret;
+
+       if (_M_size == 0)
+        return __ret;
+
        _Tp* __restrict__ __tmp_M_data =
         std::__valarray_get_storage<_Tp>(_M_size);
-       
-       if (__n > 0)      // cshift left
+
+       if (__n == 0)
+        std::__valarray_copy_construct(_M_data,
+                                       _M_data + _M_size, __tmp_M_data);
+       else if (__n > 0)      // cshift left
         {
           if (size_t(__n) > _M_size)
-            __n = __n % _M_size;
+            __n = int(__n % _M_size);
 
           std::__valarray_copy_construct(_M_data, _M_data + __n,
                                          __tmp_M_data + _M_size - __n);
           std::__valarray_copy_construct(_M_data + __n, _M_data + _M_size,
                                          __tmp_M_data);
         }
-       else              // cshift right
+       else                   // cshift right
         {
-          if (size_t(-__n) > _M_size)
-            __n = -(-__n % _M_size);
+          if (-size_t(__n) > _M_size)
+            __n = -int(-size_t(__n) % _M_size);
 
           std::__valarray_copy_construct(_M_data + _M_size + __n,
                                          _M_data + _M_size, __tmp_M_data);
@@ -874,7 +927,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
     valarray<_Tp>::min() const
     {
       _GLIBCXX_DEBUG_ASSERT(_M_size > 0);
-      return *std::min_element(_M_data, _M_data+_M_size);
+      return *std::min_element(_M_data, _M_data + _M_size);
     }
 
   template<typename _Tp>
@@ -882,7 +935,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
     valarray<_Tp>::max() const
     {
       _GLIBCXX_DEBUG_ASSERT(_M_size > 0);
-      return *std::max_element(_M_data, _M_data+_M_size);
+      return *std::max_element(_M_data, _M_data + _M_size);
     }
   
   template<class _Tp>
@@ -1002,7 +1055,7 @@ _DEFINE_VALARRAY_EXPR_AUGMENTED_ASSIGNMENT(>>, __shift_right)
     {                                                                  \
       typedef _BinClos<_Name, _Constant, _ValArray, _Tp, _Tp> _Closure; \
       typedef typename __fun<_Name, _Tp>::result_type _Rt;              \
-      return _Expr<_Closure, _Tp>(_Closure(__t, __v));                 \
+      return _Expr<_Closure, _Rt>(_Closure(__t, __v));                 \
     }
 
 _DEFINE_BINARY_OPERATOR(+, __plus)
@@ -1026,6 +1079,8 @@ _DEFINE_BINARY_OPERATOR(>=, __greater_equal)
 
 #undef _DEFINE_BINARY_OPERATOR
 
+  // @} group numeric_arrays
+
 _GLIBCXX_END_NAMESPACE
 
 #endif /* _GLIBCXX_VALARRAY */