// The template and inlines for the -*- C++ -*- valarray class.
-// Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2004, 2005, 2006, 2007
+// 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)
_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
/// 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);
*/
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>&);
return _M_data[__i];
}
+ // @} group numeric_arrays
+
_GLIBCXX_END_NAMESPACE
#include <bits/valarray_after.h>
_GLIBCXX_BEGIN_NAMESPACE(std)
+ /**
+ * @addtogroup numeric_arrays
+ * @{
+ */
+
template<typename _Tp>
inline
valarray<_Tp>::valarray() : _M_size(0), _M_data(0) {}
(__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)
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)
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>
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>
{ \
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)
#undef _DEFINE_BINARY_OPERATOR
+ // @} group numeric_arrays
+
_GLIBCXX_END_NAMESPACE
#endif /* _GLIBCXX_VALARRAY */