libstdc++
|
00001 // The template and inlines for the -*- C++ -*- gslice_array class. 00002 00003 // Copyright (C) 1997-2019 Free Software Foundation, Inc. 00004 // 00005 // This file is part of the GNU ISO C++ Library. This library is free 00006 // software; you can redistribute it and/or modify it under the 00007 // terms of the GNU General Public License as published by the 00008 // Free Software Foundation; either version 3, or (at your option) 00009 // any later version. 00010 00011 // This library is distributed in the hope that it will be useful, 00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 // GNU General Public License for more details. 00015 00016 // Under Section 7 of GPL version 3, you are granted additional 00017 // permissions described in the GCC Runtime Library Exception, version 00018 // 3.1, as published by the Free Software Foundation. 00019 00020 // You should have received a copy of the GNU General Public License and 00021 // a copy of the GCC Runtime Library Exception along with this program; 00022 // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see 00023 // <http://www.gnu.org/licenses/>. 00024 00025 /** @file bits/gslice_array.h 00026 * This is an internal header file, included by other library headers. 00027 * Do not attempt to use it directly. @headername{valarray} 00028 */ 00029 00030 // Written by Gabriel Dos Reis <Gabriel.Dos-Reis@DPTMaths.ENS-Cachan.Fr> 00031 00032 #ifndef _GSLICE_ARRAY_H 00033 #define _GSLICE_ARRAY_H 1 00034 00035 #pragma GCC system_header 00036 00037 namespace std _GLIBCXX_VISIBILITY(default) 00038 { 00039 _GLIBCXX_BEGIN_NAMESPACE_VERSION 00040 00041 /** 00042 * @addtogroup numeric_arrays 00043 * @{ 00044 */ 00045 00046 /** 00047 * @brief Reference to multi-dimensional subset of an array. 00048 * 00049 * A gslice_array is a reference to the actual elements of an array 00050 * specified by a gslice. The way to get a gslice_array is to call 00051 * operator[](gslice) on a valarray. The returned gslice_array then 00052 * permits carrying operations out on the referenced subset of elements in 00053 * the original valarray. For example, operator+=(valarray) will add 00054 * values to the subset of elements in the underlying valarray this 00055 * gslice_array refers to. 00056 * 00057 * @param Tp Element type. 00058 */ 00059 template<typename _Tp> 00060 class gslice_array 00061 { 00062 public: 00063 typedef _Tp value_type; 00064 00065 // _GLIBCXX_RESOLVE_LIB_DEFECTS 00066 // 253. valarray helper functions are almost entirely useless 00067 00068 /// Copy constructor. Both slices refer to the same underlying array. 00069 gslice_array(const gslice_array&); 00070 00071 /// Assignment operator. Assigns slice elements to corresponding 00072 /// elements of @a a. 00073 gslice_array& operator=(const gslice_array&); 00074 00075 /// Assign slice elements to corresponding elements of @a v. 00076 void operator=(const valarray<_Tp>&) const; 00077 /// Multiply slice elements by corresponding elements of @a v. 00078 void operator*=(const valarray<_Tp>&) const; 00079 /// Divide slice elements by corresponding elements of @a v. 00080 void operator/=(const valarray<_Tp>&) const; 00081 /// Modulo slice elements by corresponding elements of @a v. 00082 void operator%=(const valarray<_Tp>&) const; 00083 /// Add corresponding elements of @a v to slice elements. 00084 void operator+=(const valarray<_Tp>&) const; 00085 /// Subtract corresponding elements of @a v from slice elements. 00086 void operator-=(const valarray<_Tp>&) const; 00087 /// Logical xor slice elements with corresponding elements of @a v. 00088 void operator^=(const valarray<_Tp>&) const; 00089 /// Logical and slice elements with corresponding elements of @a v. 00090 void operator&=(const valarray<_Tp>&) const; 00091 /// Logical or slice elements with corresponding elements of @a v. 00092 void operator|=(const valarray<_Tp>&) const; 00093 /// Left shift slice elements by corresponding elements of @a v. 00094 void operator<<=(const valarray<_Tp>&) const; 00095 /// Right shift slice elements by corresponding elements of @a v. 00096 void operator>>=(const valarray<_Tp>&) const; 00097 /// Assign all slice elements to @a t. 00098 void operator=(const _Tp&) const; 00099 00100 template<class _Dom> 00101 void operator=(const _Expr<_Dom, _Tp>&) const; 00102 template<class _Dom> 00103 void operator*=(const _Expr<_Dom, _Tp>&) const; 00104 template<class _Dom> 00105 void operator/=(const _Expr<_Dom, _Tp>&) const; 00106 template<class _Dom> 00107 void operator%=(const _Expr<_Dom, _Tp>&) const; 00108 template<class _Dom> 00109 void operator+=(const _Expr<_Dom, _Tp>&) const; 00110 template<class _Dom> 00111 void operator-=(const _Expr<_Dom, _Tp>&) const; 00112 template<class _Dom> 00113 void operator^=(const _Expr<_Dom, _Tp>&) const; 00114 template<class _Dom> 00115 void operator&=(const _Expr<_Dom, _Tp>&) const; 00116 template<class _Dom> 00117 void operator|=(const _Expr<_Dom, _Tp>&) const; 00118 template<class _Dom> 00119 void operator<<=(const _Expr<_Dom, _Tp>&) const; 00120 template<class _Dom> 00121 void operator>>=(const _Expr<_Dom, _Tp>&) const; 00122 00123 private: 00124 _Array<_Tp> _M_array; 00125 const valarray<size_t>& _M_index; 00126 00127 friend class valarray<_Tp>; 00128 00129 gslice_array(_Array<_Tp>, const valarray<size_t>&); 00130 00131 #if __cplusplus < 201103L 00132 // not implemented 00133 gslice_array(); 00134 #else 00135 public: 00136 gslice_array() = delete; 00137 #endif 00138 }; 00139 00140 template<typename _Tp> 00141 inline 00142 gslice_array<_Tp>::gslice_array(_Array<_Tp> __a, 00143 const valarray<size_t>& __i) 00144 : _M_array(__a), _M_index(__i) {} 00145 00146 template<typename _Tp> 00147 inline 00148 gslice_array<_Tp>::gslice_array(const gslice_array<_Tp>& __a) 00149 : _M_array(__a._M_array), _M_index(__a._M_index) {} 00150 00151 template<typename _Tp> 00152 inline gslice_array<_Tp>& 00153 gslice_array<_Tp>::operator=(const gslice_array<_Tp>& __a) 00154 { 00155 std::__valarray_copy(_Array<_Tp>(__a._M_array), 00156 _Array<size_t>(__a._M_index), _M_index.size(), 00157 _M_array, _Array<size_t>(_M_index)); 00158 return *this; 00159 } 00160 00161 template<typename _Tp> 00162 inline void 00163 gslice_array<_Tp>::operator=(const _Tp& __t) const 00164 { 00165 std::__valarray_fill(_M_array, _Array<size_t>(_M_index), 00166 _M_index.size(), __t); 00167 } 00168 00169 template<typename _Tp> 00170 inline void 00171 gslice_array<_Tp>::operator=(const valarray<_Tp>& __v) const 00172 { 00173 std::__valarray_copy(_Array<_Tp>(__v), __v.size(), 00174 _M_array, _Array<size_t>(_M_index)); 00175 } 00176 00177 template<typename _Tp> 00178 template<class _Dom> 00179 inline void 00180 gslice_array<_Tp>::operator=(const _Expr<_Dom, _Tp>& __e) const 00181 { 00182 std::__valarray_copy (__e, _M_index.size(), _M_array, 00183 _Array<size_t>(_M_index)); 00184 } 00185 00186 #undef _DEFINE_VALARRAY_OPERATOR 00187 #define _DEFINE_VALARRAY_OPERATOR(_Op, _Name) \ 00188 template<typename _Tp> \ 00189 inline void \ 00190 gslice_array<_Tp>::operator _Op##=(const valarray<_Tp>& __v) const \ 00191 { \ 00192 _Array_augmented_##_Name(_M_array, _Array<size_t>(_M_index), \ 00193 _Array<_Tp>(__v), __v.size()); \ 00194 } \ 00195 \ 00196 template<typename _Tp> \ 00197 template<class _Dom> \ 00198 inline void \ 00199 gslice_array<_Tp>::operator _Op##= (const _Expr<_Dom, _Tp>& __e) const\ 00200 { \ 00201 _Array_augmented_##_Name(_M_array, _Array<size_t>(_M_index), __e,\ 00202 _M_index.size()); \ 00203 } 00204 00205 _DEFINE_VALARRAY_OPERATOR(*, __multiplies) 00206 _DEFINE_VALARRAY_OPERATOR(/, __divides) 00207 _DEFINE_VALARRAY_OPERATOR(%, __modulus) 00208 _DEFINE_VALARRAY_OPERATOR(+, __plus) 00209 _DEFINE_VALARRAY_OPERATOR(-, __minus) 00210 _DEFINE_VALARRAY_OPERATOR(^, __bitwise_xor) 00211 _DEFINE_VALARRAY_OPERATOR(&, __bitwise_and) 00212 _DEFINE_VALARRAY_OPERATOR(|, __bitwise_or) 00213 _DEFINE_VALARRAY_OPERATOR(<<, __shift_left) 00214 _DEFINE_VALARRAY_OPERATOR(>>, __shift_right) 00215 00216 #undef _DEFINE_VALARRAY_OPERATOR 00217 00218 // @} group numeric_arrays 00219 00220 _GLIBCXX_END_NAMESPACE_VERSION 00221 } // namespace 00222 00223 #endif /* _GSLICE_ARRAY_H */