valarray.cpp revision 262801
11590Srgrimes//===------------------------ valarray.cpp --------------------------------===//
21590Srgrimes//
31590Srgrimes//                     The LLVM Compiler Infrastructure
41590Srgrimes//
51590Srgrimes// This file is dual licensed under the MIT and the University of Illinois Open
61590Srgrimes// Source Licenses. See LICENSE.TXT for details.
71590Srgrimes//
81590Srgrimes//===----------------------------------------------------------------------===//
91590Srgrimes
101590Srgrimes#define _LIBCPP_EXTERN_TEMPLATE(...) extern template __VA_ARGS__;
111590Srgrimes
121590Srgrimes#include "valarray"
131590Srgrimes
141590Srgrimes_LIBCPP_BEGIN_NAMESPACE_STD
151590Srgrimes
161590Srgrimestemplate valarray<size_t>::valarray(size_t);
171590Srgrimestemplate valarray<size_t>::~valarray();
181590Srgrimestemplate void valarray<size_t>::resize(size_t, size_t);
191590Srgrimes
201590Srgrimesvoid
211590Srgrimesgslice::__init(size_t __start)
221590Srgrimes{
231590Srgrimes    valarray<size_t> __indices(__size_.size());
241590Srgrimes    size_t __k = __size_.size() != 0;
251590Srgrimes    for (size_t __i = 0; __i < __size_.size(); ++__i)
261590Srgrimes        __k *= __size_[__i];
271590Srgrimes    __1d_.resize(__k);
281590Srgrimes    if (__1d_.size())
291590Srgrimes    {
3087715Smarkm        __k = 0;
3187715Smarkm        __1d_[__k] = __start;
3287715Smarkm        while (true)
3387715Smarkm        {
3487715Smarkm            size_t __i = __indices.size() - 1;
3587715Smarkm            while (true)
3687715Smarkm            {
3787715Smarkm                if (++__indices[__i] < __size_[__i])
381590Srgrimes                {
3987715Smarkm                    ++__k;
401590Srgrimes                    __1d_[__k] = __1d_[__k-1] + __stride_[__i];
411590Srgrimes                    for (size_t __j = __i + 1; __j != __indices.size(); ++__j)
4228149Scharnier                        __1d_[__k] -= __stride_[__j] * (__size_[__j] - 1);
431590Srgrimes                    break;
441590Srgrimes                }
4570118Srwatson                else
4674671Stmm                {
471590Srgrimes                    if (__i == 0)
4828149Scharnier                        return;
4977205Stmm                    __indices[__i--] = 0;
5014953Sache                }
511590Srgrimes            }
52200462Sdelphij        }
531590Srgrimes    }
541590Srgrimes}
5540060Sobrien
5640060Sobrien_LIBCPP_END_NAMESPACE_STD
5787715Smarkm