]> git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/src/c++98/valarray.cc
Update copyright years.
[thirdparty/gcc.git] / libstdc++-v3 / src / c++98 / valarray.cc
1 // Explicit instantiation file.
2
3 // Copyright (C) 2001-2019 Free Software Foundation, Inc.
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
8 // Free Software Foundation; either version 3, or (at your option)
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
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/>.
24
25 //
26 // ISO C++ 14882:
27 //
28
29 #include <valarray>
30
31 namespace std _GLIBCXX_VISIBILITY(default)
32 {
33 _GLIBCXX_BEGIN_NAMESPACE_VERSION
34
35 // Some explicit instantiations.
36 template void
37 __valarray_fill(size_t* __restrict__, size_t, const size_t&);
38
39 template void
40 __valarray_copy(const size_t* __restrict__, size_t, size_t* __restrict__);
41
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);
47
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
59 inline size_t
60 __valarray_product(const valarray<size_t>& __a)
61 {
62 return __valarray_product(&__a[0], &__a[0] + __a.size());
63 }
64
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 {
73 // There are as many dimensions as there are strides.
74 const size_t __n = __l.size();
75
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);
79
80 // Note that this should match the product of all numbers appearing
81 // in __l which describes the multidimensional sizes of the
82 // generalized slice.
83 const size_t __z = __i.size();
84
85 for (size_t __j = 0; __j < __z; ++__j)
86 {
87 // Compute the linear-index image of (t_0, ... t_{n-1}).
88 __i[__j] = __o;
89
90 --__t[__n - 1];
91 __o += __s[__n - 1];
92
93 // Process the next multi-index. The loop ought to be
94 // backward since we're making a lexicographical visit.
95 for (size_t __k2 = __n - 1; __k2 && !__t[__k2]; --__k2)
96 {
97 __o -= __s[__k2] * __l[__k2];
98 __t[__k2] = __l[__k2];
99
100 --__t[__k2 - 1];
101 __o += __s[__k2 - 1];
102 }
103 }
104 }
105
106 gslice::_Indexer::_Indexer(size_t __o, const valarray<size_t>& __l,
107 const valarray<size_t>& __s)
108 : _M_count(1), _M_start(__o), _M_size(__l), _M_stride(__s),
109 _M_index(__l.size() == 0 ? 0 : __valarray_product(__l))
110 { __gslice_to_index(__o, __l, __s, _M_index); }
111
112 _GLIBCXX_END_NAMESPACE_VERSION
113 } // namespace