]> git.ipfire.org Git - thirdparty/gcc.git/blame - libstdc++-v3/src/c++98/valarray.cc
Update copyright years.
[thirdparty/gcc.git] / libstdc++-v3 / src / c++98 / valarray.cc
CommitLineData
d53d7f6e
PE
1// Explicit instantiation file.
2
83ffe9cd 3// Copyright (C) 2001-2023 Free Software Foundation, Inc.
d53d7f6e
PE
4//
5// This file is part of the GNU ISO C++ Library. This library is free
6// software; you can redistribute it and/or modify it under the
7// terms of the GNU General Public License as published by the
748086b7 8// Free Software Foundation; either version 3, or (at your option)
d53d7f6e
PE
9// any later version.
10
11// This library is distributed in the hope that it will be useful,
12// but WITHOUT ANY WARRANTY; without even the implied warranty of
13// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14// GNU General Public License for more details.
15
748086b7
JJ
16// Under Section 7 of GPL version 3, you are granted additional
17// permissions described in the GCC Runtime Library Exception, version
18// 3.1, as published by the Free Software Foundation.
19
20// You should have received a copy of the GNU General Public License and
21// a copy of the GCC Runtime Library Exception along with this program;
22// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
23// <http://www.gnu.org/licenses/>.
d53d7f6e
PE
24
25//
26// ISO C++ 14882:
27//
28
54c1bf78 29#include <valarray>
b2dad0e3 30
12ffa228
BK
31namespace std _GLIBCXX_VISIBILITY(default)
32{
33_GLIBCXX_BEGIN_NAMESPACE_VERSION
3cbc7af0 34
eafa1afa 35 // Some explicit instantiations.
8db47d74
GDR
36 template void
37 __valarray_fill(size_t* __restrict__, size_t, const size_t&);
f92ab29f 38
8db47d74
GDR
39 template void
40 __valarray_copy(const size_t* __restrict__, size_t, size_t* __restrict__);
f92ab29f 41
8db47d74
GDR
42 template valarray<size_t>::valarray(size_t);
43 template valarray<size_t>::valarray(const valarray<size_t>&);
44 template valarray<size_t>::~valarray();
45 template size_t valarray<size_t>::size() const;
46 template size_t& valarray<size_t>::operator[](size_t);
b2dad0e3 47
fab2c75b
JW
48 // Compute the product of all elements in the non-empty range [__f, __l)
49 template<typename _Tp>
50 inline _Tp
51 __valarray_product(const _Tp* __f, const _Tp* __l)
52 {
53 _Tp __r = *__f++;
54 while (__f != __l)
55 __r = __r * *__f++;
56 return __r;
57 }
58
8db47d74
GDR
59 inline size_t
60 __valarray_product(const valarray<size_t>& __a)
61 {
fab2c75b 62 return __valarray_product(&__a[0], &__a[0] + __a.size());
8db47d74 63 }
f92ab29f 64
8db47d74
GDR
65 // Map a gslice, described by its multidimensional LENGTHS
66 // and corresponding STRIDES, to a linear array of INDEXES
67 // for the purpose of indexing a flat, one-dimensional array
68 // representation of a gslice_array.
69 void
70 __gslice_to_index(size_t __o, const valarray<size_t>& __l,
71 const valarray<size_t>& __s, valarray<size_t>& __i)
72 {
ee5ca789 73 // There are as many dimensions as there are strides.
682b9664 74 const size_t __n = __l.size();
b2dad0e3 75
682b9664
PC
76 // Holds current multi-index as we go through the gslice for the
77 // purpose of computing its linear-image.
78 valarray<size_t> __t(__l);
b2dad0e3 79
8db47d74
GDR
80 // Note that this should match the product of all numbers appearing
81 // in __l which describes the multidimensional sizes of the
682b9664 82 // generalized slice.
8db47d74 83 const size_t __z = __i.size();
682b9664 84
8db47d74
GDR
85 for (size_t __j = 0; __j < __z; ++__j)
86 {
682b9664
PC
87 // Compute the linear-index image of (t_0, ... t_{n-1}).
88 __i[__j] = __o;
8db47d74 89
682b9664
PC
90 --__t[__n - 1];
91 __o += __s[__n - 1];
b2dad0e3 92
8db47d74 93 // Process the next multi-index. The loop ought to be
682b9664
PC
94 // backward since we're making a lexicographical visit.
95 for (size_t __k2 = __n - 1; __k2 && !__t[__k2]; --__k2)
8db47d74 96 {
682b9664
PC
97 __o -= __s[__k2] * __l[__k2];
98 __t[__k2] = __l[__k2];
99
100 --__t[__k2 - 1];
101 __o += __s[__k2 - 1];
8db47d74
GDR
102 }
103 }
104 }
f92ab29f 105
8db47d74
GDR
106 gslice::_Indexer::_Indexer(size_t __o, const valarray<size_t>& __l,
107 const valarray<size_t>& __s)
82cb2574
PC
108 : _M_count(1), _M_start(__o), _M_size(__l), _M_stride(__s),
109 _M_index(__l.size() == 0 ? 0 : __valarray_product(__l))
f92ab29f 110 { __gslice_to_index(__o, __l, __s, _M_index); }
3cbc7af0 111
12ffa228
BK
112_GLIBCXX_END_NAMESPACE_VERSION
113} // namespace