⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 std_valarray.h

📁 gcc-you can use this code to learn something about gcc, and inquire further into linux,
💻 H
📖 第 1 页 / 共 2 页
字号:
// The template and inlines for the -*- C++ -*- valarray class.// Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002// 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)// any later version.// This library is distributed in the hope that it will be useful,// but WITHOUT ANY WARRANTY; without even the implied warranty of// 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, 59 Temple Place - Suite 330, Boston, MA 02111-1307,// USA.// 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.// Written by Gabriel Dos Reis <Gabriel.Dos-Reis@DPTMaths.ENS-Cachan.Fr>/** @file valarray *  This is a Standard C++ Library header.  You should @c #include this header *  in your programs, rather than any of the "st[dl]_*.h" implementation files. */#ifndef _CPP_VALARRAY#define _CPP_VALARRAY 1#pragma GCC system_header#include <bits/c++config.h>#include <cstddef>#include <cmath>#include <cstdlib>#include <numeric>#include <algorithm>namespace std{  template<class _Clos, typename _Tp>     class _Expr;  template<typename _Tp1, typename _Tp2>     class _ValArray;      template<class _Oper, template<class, class> class _Meta, class _Dom>    struct _UnClos;  template<class _Oper,        template<class, class> class _Meta1,        template<class, class> class _Meta2,        class _Dom1, class _Dom2>     class _BinClos;  template<template<class, class> class _Meta, class _Dom>     class _SClos;  template<template<class, class> class _Meta, class _Dom>     class _GClos;      template<template<class, class> class _Meta, class _Dom>     class _IClos;      template<template<class, class> class _Meta, class _Dom>     class _ValFunClos;    template<template<class, class> class _Meta, class _Dom>     class _RefFunClos;  template<class _Tp> class valarray;   // An array of type _Tp  class slice;                          // BLAS-like slice out of an array  template<class _Tp> class slice_array;  class gslice;                         // generalized slice out of an array  template<class _Tp> class gslice_array;  template<class _Tp> class mask_array;     // masked array  template<class _Tp> class indirect_array; // indirected array} // namespace std#include <bits/valarray_array.h>#include <bits/valarray_meta.h>  namespace std{  template<class _Tp>     class valarray    {      template<class _Op>	struct _UnaryOp 	{	  typedef typename __fun<_Op, _Tp>::result_type __rt;	  typedef _Expr<_UnClos<_Op, _ValArray, _Tp>, __rt> _Rt;	};    public:      typedef _Tp value_type;      	// _lib.valarray.cons_ construct/destroy:      valarray();      explicit valarray(size_t);      valarray(const _Tp&, size_t);      valarray(const _Tp* __restrict__, size_t);      valarray(const valarray&);      valarray(const slice_array<_Tp>&);      valarray(const gslice_array<_Tp>&);      valarray(const mask_array<_Tp>&);      valarray(const indirect_array<_Tp>&);      template<class _Dom>	valarray(const _Expr<_Dom,_Tp>& __e);      ~valarray();      // _lib.valarray.assign_ assignment:      valarray<_Tp>& operator=(const valarray<_Tp>&);      valarray<_Tp>& operator=(const _Tp&);      valarray<_Tp>& operator=(const slice_array<_Tp>&);      valarray<_Tp>& operator=(const gslice_array<_Tp>&);      valarray<_Tp>& operator=(const mask_array<_Tp>&);      valarray<_Tp>& operator=(const indirect_array<_Tp>&);      template<class _Dom> valarray<_Tp>&	operator= (const _Expr<_Dom,_Tp>&);      // _lib.valarray.access_ element access:      // XXX: LWG to be resolved.      const _Tp&                 operator[](size_t) const;      _Tp&                operator[](size_t);		      // _lib.valarray.sub_ subset operations:      _Expr<_SClos<_ValArray,_Tp>, _Tp> operator[](slice) const;      slice_array<_Tp>    operator[](slice);      _Expr<_GClos<_ValArray,_Tp>, _Tp> operator[](const gslice&) const;      gslice_array<_Tp>   operator[](const gslice&);      valarray<_Tp>     	 operator[](const valarray<bool>&) const;      mask_array<_Tp>     operator[](const valarray<bool>&);      _Expr<_IClos<_ValArray, _Tp>, _Tp>        operator[](const valarray<size_t>&) const;      indirect_array<_Tp> operator[](const valarray<size_t>&);      // _lib.valarray.unary_ unary operators:      typename _UnaryOp<__unary_plus>::_Rt  operator+() const;      typename _UnaryOp<__negate>::_Rt      operator-() const;      typename _UnaryOp<__bitwise_not>::_Rt operator~() const;      typename _UnaryOp<__logical_not>::_Rt operator!() const;      // _lib.valarray.cassign_ computed assignment:      valarray<_Tp>& operator*=(const _Tp&);      valarray<_Tp>& operator/=(const _Tp&);      valarray<_Tp>& operator%=(const _Tp&);      valarray<_Tp>& operator+=(const _Tp&);      valarray<_Tp>& operator-=(const _Tp&);      valarray<_Tp>& operator^=(const _Tp&);      valarray<_Tp>& operator&=(const _Tp&);      valarray<_Tp>& operator|=(const _Tp&);      valarray<_Tp>& operator<<=(const _Tp&);      valarray<_Tp>& operator>>=(const _Tp&);      valarray<_Tp>& operator*=(const valarray<_Tp>&);      valarray<_Tp>& operator/=(const valarray<_Tp>&);      valarray<_Tp>& operator%=(const valarray<_Tp>&);      valarray<_Tp>& operator+=(const valarray<_Tp>&);      valarray<_Tp>& operator-=(const valarray<_Tp>&);      valarray<_Tp>& operator^=(const valarray<_Tp>&);      valarray<_Tp>& operator|=(const valarray<_Tp>&);      valarray<_Tp>& operator&=(const valarray<_Tp>&);      valarray<_Tp>& operator<<=(const valarray<_Tp>&);      valarray<_Tp>& operator>>=(const valarray<_Tp>&);      template<class _Dom>	valarray<_Tp>& operator*=(const _Expr<_Dom,_Tp>&);      template<class _Dom>	valarray<_Tp>& operator/=(const _Expr<_Dom,_Tp>&);      template<class _Dom>	valarray<_Tp>& operator%=(const _Expr<_Dom,_Tp>&);      template<class _Dom>	valarray<_Tp>& operator+=(const _Expr<_Dom,_Tp>&);      template<class _Dom>	valarray<_Tp>& operator-=(const _Expr<_Dom,_Tp>&);      template<class _Dom>	valarray<_Tp>& operator^=(const _Expr<_Dom,_Tp>&);      template<class _Dom>	valarray<_Tp>& operator|=(const _Expr<_Dom,_Tp>&);      template<class _Dom>	valarray<_Tp>& operator&=(const _Expr<_Dom,_Tp>&);      template<class _Dom>      valarray<_Tp>& operator<<=(const _Expr<_Dom,_Tp>&);      template<class _Dom>	valarray<_Tp>& operator>>=(const _Expr<_Dom,_Tp>&);      // _lib.valarray.members_ member functions:      size_t size() const;      _Tp    sum() const;	      _Tp    min() const;	      _Tp    max() const;	  //           // FIXME: Extension  //       _Tp    product () const;      valarray<_Tp> shift (int) const;      valarray<_Tp> cshift(int) const;      _Expr<_ValFunClos<_ValArray,_Tp>,_Tp> apply(_Tp func(_Tp)) const;      _Expr<_RefFunClos<_ValArray,_Tp>,_Tp> apply(_Tp func(const _Tp&)) const;      void resize(size_t __size, _Tp __c = _Tp());    private:      size_t _M_size;      _Tp* __restrict__ _M_data;            friend class _Array<_Tp>;    };    template<typename _Tp>    inline const _Tp&    valarray<_Tp>::operator[](size_t __i) const    { return _M_data[__i]; }  template<typename _Tp>    inline _Tp&    valarray<_Tp>::operator[](size_t __i)    { return _M_data[__i]; }} // std::      #include <bits/slice_array.h>#include <bits/gslice.h>#include <bits/gslice_array.h>#include <bits/mask_array.h>#include <bits/indirect_array.h>namespace std{  template<typename _Tp>    inline    valarray<_Tp>::valarray() : _M_size(0), _M_data(0) {}  template<typename _Tp>    inline     valarray<_Tp>::valarray(size_t __n) 	: _M_size(__n), _M_data(__valarray_get_storage<_Tp>(__n))    { __valarray_default_construct(_M_data, _M_data + __n); }  template<typename _Tp>    inline    valarray<_Tp>::valarray(const _Tp& __t, size_t __n)      : _M_size(__n), _M_data(__valarray_get_storage<_Tp>(__n))    { __valarray_fill_construct(_M_data, _M_data + __n, __t); }  template<typename _Tp>    inline    valarray<_Tp>::valarray(const _Tp* __restrict__ __p, size_t __n)      : _M_size(__n), _M_data(__valarray_get_storage<_Tp>(__n))    { __valarray_copy_construct(__p, __p + __n, _M_data); }  template<typename _Tp>    inline    valarray<_Tp>::valarray(const valarray<_Tp>& __v)      : _M_size(__v._M_size), _M_data(__valarray_get_storage<_Tp>(__v._M_size))    { __valarray_copy_construct(__v._M_data, __v._M_data + _M_size, _M_data); }  template<typename _Tp>    inline    valarray<_Tp>::valarray(const slice_array<_Tp>& __sa)      : _M_size(__sa._M_sz), _M_data(__valarray_get_storage<_Tp>(__sa._M_sz))    {      __valarray_copy	(__sa._M_array, __sa._M_sz, __sa._M_stride, _Array<_Tp>(_M_data));    }  template<typename _Tp>    inline    valarray<_Tp>::valarray(const gslice_array<_Tp>& __ga)      : _M_size(__ga._M_index.size()),	_M_data(__valarray_get_storage<_Tp>(_M_size))    {      __valarray_copy	(__ga._M_array, _Array<size_t>(__ga._M_index),	 _Array<_Tp>(_M_data), _M_size);    }  template<typename _Tp>    inline    valarray<_Tp>::valarray(const mask_array<_Tp>& __ma)      : _M_size(__ma._M_sz), _M_data(__valarray_get_storage<_Tp>(__ma._M_sz))    {      __valarray_copy	(__ma._M_array, __ma._M_mask, _Array<_Tp>(_M_data), _M_size);    }  template<typename _Tp>    inline    valarray<_Tp>::valarray(const indirect_array<_Tp>& __ia)      : _M_size(__ia._M_sz), _M_data(__valarray_get_storage<_Tp>(__ia._M_sz))    {      __valarray_copy	(__ia._M_array, __ia._M_index, _Array<_Tp>(_M_data), _M_size);    }  template<typename _Tp> template<class _Dom>    inline    valarray<_Tp>::valarray(const _Expr<_Dom, _Tp>& __e)      : _M_size(__e.size()), _M_data(__valarray_get_storage<_Tp>(_M_size))    { __valarray_copy(__e, _M_size, _Array<_Tp>(_M_data)); }  template<typename _Tp>    inline    valarray<_Tp>::~valarray()    {      __valarray_destroy_elements(_M_data, _M_data + _M_size);      __valarray_release_memory(_M_data);    }  template<typename _Tp>    inline valarray<_Tp>&    valarray<_Tp>::operator=(const valarray<_Tp>& __v)    {      __valarray_copy(__v._M_data, _M_size, _M_data);      return *this;    }  template<typename _Tp>    inline valarray<_Tp>&    valarray<_Tp>::operator=(const _Tp& __t)    {      __valarray_fill(_M_data, _M_size, __t);      return *this;    }  template<typename _Tp>    inline valarray<_Tp>&    valarray<_Tp>::operator=(const slice_array<_Tp>& __sa)    {      __valarray_copy(__sa._M_array, __sa._M_sz,		      __sa._M_stride, _Array<_Tp>(_M_data));      return *this;    }  template<typename _Tp>    inline valarray<_Tp>&    valarray<_Tp>::operator=(const gslice_array<_Tp>& __ga)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -