Ne.app NeANT
The Ne.app NeANT User module of the NeANT distribution.
valarray.cc
Go to the documentation of this file.
1
31
32
33template <class _TypeT>
34valarray<_TypeT> valarray<_TypeT>::shift (int __n) const
35{
36 if (0 == __n)
37 return *this;
38
39 const _RWSTD_SIZE_T __size = size ();
40
41 if (__size <= (_RWSTD_SIZE_T)(__n < 0 ? -__n : __n))
42 return valarray (__size);
43
44 // use copy- rather than direct-initialization to work around
45 // a gcc 3.2 bug
46 _RW::__rw_array<_TypeT> __tmp =
47 _RW::__rw_array<_TypeT>(_TypeT (), __size);
48
49 // 26.3.2.7, p5 - negative n shifts right, positive left
50 if (__n < 0)
51 copy (_C_array.begin (), _C_array.end () + __n, __tmp.begin () - __n);
52 else
53 copy (_C_array.begin () + __n, _C_array.end (), __tmp.begin ());
54
55 return valarray (__tmp);
56}
57
58
59template <class _TypeT>
60valarray<_TypeT> valarray<_TypeT>::cshift (int __n) const
61{
62 const _RWSTD_SIZE_T __size = size ();
63
64 // compute non-negative modulus - the sign of (a % b) is
65 // implementation-defined if either argument is negative (5.6, p4)
66 _RWSTD_PTRDIFF_T __mod = __size ? __n % (_RWSTD_PTRDIFF_T)__size : 0;
67 _RWSTD_SIZE_T __rem = __mod < 0 ? -__mod : __mod;
68
69 if (0 == __rem)
70 return *this;
71
72 // use copy- rather than direct-initialization to work around
73 // a gcc 3.2 bug
74 _RW::__rw_array<_TypeT> __tmp =
75 _RW::__rw_array<_TypeT>(_TypeT (), __size);
76
77 // 26.3.2.7, p7 - negative n rotates right, positive left
78 rotate_copy (_C_array.begin (),
79 __n < 0 ? _C_array.end () - __rem : _C_array.begin () + __rem,
80 _C_array.end (), __tmp.begin ());
81
82 return valarray (__tmp);
83}
84
85
86} // namespace std
#define _RWSTD_NAMESPACE(name)
Definition _defs.h:567
Definition json.h:5363