valarray_array.tcc revision 97403
197403Sobrien// The template and inlines for the -*- C++ -*- internal _Array helper class.
297403Sobrien
397403Sobrien// Copyright (C) 1997, 1998, 1999 Free Software Foundation, Inc.
497403Sobrien//
597403Sobrien// This file is part of the GNU ISO C++ Library.  This library is free
697403Sobrien// software; you can redistribute it and/or modify it under the
797403Sobrien// terms of the GNU General Public License as published by the
897403Sobrien// Free Software Foundation; either version 2, or (at your option)
997403Sobrien// any later version.
1097403Sobrien
1197403Sobrien// This library is distributed in the hope that it will be useful,
1297403Sobrien// but WITHOUT ANY WARRANTY; without even the implied warranty of
1397403Sobrien// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
1497403Sobrien// GNU General Public License for more details.
1597403Sobrien
1697403Sobrien// You should have received a copy of the GNU General Public License along
1797403Sobrien// with this library; see the file COPYING.  If not, write to the Free
1897403Sobrien// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
1997403Sobrien// USA.
2097403Sobrien
2197403Sobrien// As a special exception, you may use this file as part of a free software
2297403Sobrien// library without restriction.  Specifically, if other files instantiate
2397403Sobrien// templates or use macros or inline functions from this file, or you compile
2497403Sobrien// this file and link it with other files to produce an executable, this
2597403Sobrien// file does not by itself cause the resulting executable to be covered by
2697403Sobrien// the GNU General Public License.  This exception does not however
2797403Sobrien// invalidate any other reasons why the executable file might be covered by
2897403Sobrien// the GNU General Public License.
2997403Sobrien
3097403Sobrien// Written by Gabriel Dos Reis <Gabriel.Dos-Reis@DPTMaths.ENS-Cachan.Fr>
3197403Sobrien
3297403Sobrien#ifndef _CPP_BITS_VALARRAY_ARRAY_TCC 
3397403Sobrien#define _CPP_BITS_VALARRAY_ARRAY_TCC 1
3497403Sobrien
3597403Sobriennamespace std
3697403Sobrien{
3797403Sobrien
3897403Sobrienexport template<typename _Tp>
3997403Sobrienvoid
4097403Sobrien__valarray_fill (_Array<_Tp> __a, size_t __n, _Array<bool> __m, const _Tp& __t)
4197403Sobrien{
4297403Sobrien    _Tp* __p = __a._M_data;
4397403Sobrien    bool* __ok (__m._M_data);
4497403Sobrien    for (size_t __i=0; __i<__n; ++__i, ++__ok, ++__p) {
4597403Sobrien        while (! *__ok) {
4697403Sobrien            ++__ok;
4797403Sobrien            ++__p;
4897403Sobrien        }
4997403Sobrien        *__p = __t;
5097403Sobrien    }
5197403Sobrien}
5297403Sobrien
5397403Sobrienexport template<typename _Tp>
5497403Sobrienvoid
5597403Sobrien__valarray_copy (_Array<_Tp> __a, _Array<bool> __m, _Array<_Tp> __b, size_t __n)
5697403Sobrien{
5797403Sobrien    _Tp* __p (__a._M_data);
5897403Sobrien    bool* __ok (__m._M_data);
5997403Sobrien    for (_Tp* __q=__b._M_data; __q<__b._M_data+__n; ++__q, ++__ok, ++__p) {
6097403Sobrien        while (! *__ok) {
6197403Sobrien            ++__ok;
6297403Sobrien            ++__p;
6397403Sobrien        }
6497403Sobrien        *__q = *__p;
6597403Sobrien    }
6697403Sobrien}
6797403Sobrien
6897403Sobrienexport template<typename _Tp>
6997403Sobrienvoid
7097403Sobrien__valarray_copy (_Array<_Tp> __a, size_t __n, _Array<_Tp> __b, _Array<bool> __m)
7197403Sobrien{
7297403Sobrien    _Tp* __q (__b._M_data);
7397403Sobrien    bool* __ok (__m._M_data);
7497403Sobrien    for (_Tp* __p=__a._M_data; __p<__a._M_data+__n; ++__p, ++__ok, ++__q) {
7597403Sobrien        while (! *__ok) {
7697403Sobrien            ++__ok;
7797403Sobrien            ++__q;
7897403Sobrien        }
7997403Sobrien        *__q = *__p;
8097403Sobrien    }
8197403Sobrien}
8297403Sobrien
8397403Sobrienexport template<typename _Tp, class _Dom>
8497403Sobrienvoid
8597403Sobrien__valarray_copy (const _Expr<_Dom, _Tp>& __e, size_t __n, _Array<_Tp> __a)
8697403Sobrien{
8797403Sobrien    _Tp* __p (__a._M_data);
8897403Sobrien    for (size_t __i=0; __i<__n; ++__i, ++__p) *__p = __e[__i];
8997403Sobrien}
9097403Sobrien
9197403Sobrienexport template<typename _Tp, class _Dom>
9297403Sobrienvoid
9397403Sobrien__valarray_copy (const _Expr<_Dom, _Tp>& __e, size_t __n, 
9497403Sobrien                 _Array<_Tp> __a, size_t __s)
9597403Sobrien{
9697403Sobrien    _Tp* __p (__a._M_data);
9797403Sobrien    for (size_t __i=0; __i<__n; ++__i, __p+=__s) *__p = __e[__i];
9897403Sobrien}
9997403Sobrien
10097403Sobrienexport template<typename _Tp, class _Dom>
10197403Sobrienvoid
10297403Sobrien__valarray_copy (const _Expr<_Dom, _Tp>& __e, size_t __n, 
10397403Sobrien                 _Array<_Tp> __a, _Array<size_t> __i)
10497403Sobrien{
10597403Sobrien    size_t* __j (__i._M_data);
10697403Sobrien    for (size_t __k=0; __k<__n; ++__k, ++__j) __a._M_data[*__j] = __e[__k];
10797403Sobrien}
10897403Sobrien
10997403Sobrienexport template<typename _Tp, class _Dom>
11097403Sobrienvoid
11197403Sobrien__valarray_copy (const _Expr<_Dom, _Tp>& __e, size_t __n, 
11297403Sobrien                 _Array<_Tp> __a, _Array<bool> __m)
11397403Sobrien{
11497403Sobrien    bool* __ok (__m._M_data);
11597403Sobrien    _Tp* __p (__a._M_data);
11697403Sobrien    for (size_t __i=0; __i<__n; ++__i, ++__ok, ++__p) {
11797403Sobrien        while (! *__ok) {
11897403Sobrien            ++__ok;
11997403Sobrien            ++__p;
12097403Sobrien        }
12197403Sobrien        *__p = __e[__i];
12297403Sobrien    }
12397403Sobrien}
12497403Sobrien
12597403Sobrien
12697403Sobrienexport template<typename _Tp, class _Dom>
12797403Sobrienvoid
12897403Sobrien__valarray_copy_construct (const _Expr<_Dom, _Tp>& __e, size_t __n,
12997403Sobrien                           _Array<_Tp> __a)
13097403Sobrien{
13197403Sobrien    _Tp* __p (__a._M_data);
13297403Sobrien    for (size_t __i=0; __i<__n; ++__i, ++__p) new (__p) _Tp(__e[__i]);
13397403Sobrien}
13497403Sobrien
13597403Sobrien
13697403Sobrienexport template<typename _Tp>
13797403Sobrienvoid
13897403Sobrien__valarray_copy_construct (_Array<_Tp> __a, _Array<bool> __m,
13997403Sobrien                           _Array<_Tp> __b, size_t __n)
14097403Sobrien{
14197403Sobrien    _Tp* __p (__a._M_data);
14297403Sobrien    bool* __ok (__m._M_data);
14397403Sobrien    for (_Tp* __q=__b._M_data; __q<__b._M_data+__n; ++__q, ++__ok, ++__p) {
14497403Sobrien        while (! *__ok) {
14597403Sobrien            ++__ok;
14697403Sobrien            ++__p;
14797403Sobrien        }
14897403Sobrien        new (__q) _Tp(*__p);
14997403Sobrien    }
15097403Sobrien}
15197403Sobrien
15297403Sobrien
15397403Sobrien
15497403Sobrien
15597403Sobrien} // std::
15697403Sobrien
15797403Sobrien#endif /* _CPP_BITS_VALARRAY_ARRAY_TCC */
15897403Sobrien
15997403Sobrien// Local Variables:
16097403Sobrien// mode:c++
16197403Sobrien// End:
162