33 #ifndef _GLIBCXX_VALARRAY
34 #define _GLIBCXX_VALARRAY 1
36 #pragma GCC system_header
44 namespace std _GLIBCXX_VISIBILITY(default)
46 _GLIBCXX_BEGIN_NAMESPACE_VERSION
48 template<
class _Clos,
typename _Tp>
51 template<
typename _Tp1,
typename _Tp2>
54 template<
class _Oper,
template<
class,
class>
class _Meta,
class _Dom>
58 template<
class,
class>
class _Meta1,
59 template<
class,
class>
class _Meta2,
60 class _Dom1,
class _Dom2>
63 template<
template<
class,
class>
class _Meta,
class _Dom>
66 template<
template<
class,
class>
class _Meta,
class _Dom>
69 template<
template<
class,
class>
class _Meta,
class _Dom>
72 template<
template<
class,
class>
class _Meta,
class _Dom>
75 template<
template<
class,
class>
class _Meta,
class _Dom>
86 _GLIBCXX_END_NAMESPACE_VERSION
92 namespace std _GLIBCXX_VISIBILITY(default)
94 _GLIBCXX_BEGIN_NAMESPACE_VERSION
121 typedef typename __fun<_Op, _Tp>::result_type __rt;
122 typedef _Expr<_UnClos<_Op, _ValArray, _Tp>, __rt> _Rt;
125 typedef _Tp value_type;
138 valarray(
const _Tp* __restrict__,
size_t);
153 valarray(
const indirect_array<_Tp>&);
155 #ifdef __GXX_EXPERIMENTAL_CXX0X__
161 valarray(
const _Expr<_Dom, _Tp>& __e);
174 valarray<_Tp>&
operator=(
const valarray<_Tp>&);
193 valarray<_Tp>&
operator=(
const slice_array<_Tp>&);
203 valarray<_Tp>&
operator=(
const gslice_array<_Tp>&);
213 valarray<_Tp>&
operator=(
const mask_array<_Tp>&);
223 valarray<_Tp>&
operator=(
const indirect_array<_Tp>&);
225 #ifdef __GXX_EXPERIMENTAL_CXX0X__
237 template<
class _Dom> valarray<_Tp>&
264 _Expr<_SClos<_ValArray, _Tp>, _Tp>
operator[](slice)
const;
287 _Expr<_GClos<_ValArray, _Tp>, _Tp>
operator[](
const gslice&)
const;
313 valarray<_Tp>
operator[](
const valarray<bool>&)
const;
327 mask_array<_Tp>
operator[](
const valarray<bool>&);
340 _Expr<_IClos<_ValArray, _Tp>, _Tp>
355 indirect_array<_Tp>
operator[](
const valarray<size_t>&);
359 typename _UnaryOp<__unary_plus>::_Rt
operator+()
const;
362 typename _UnaryOp<__negate>::_Rt
operator-()
const;
365 typename _UnaryOp<__bitwise_not>::_Rt
operator~()
const;
368 typename _UnaryOp<__logical_not>::_Rt
operator!()
const;
402 valarray<_Tp>&
operator*=(
const valarray<_Tp>&);
405 valarray<_Tp>&
operator/=(
const valarray<_Tp>&);
408 valarray<_Tp>&
operator%=(
const valarray<_Tp>&);
411 valarray<_Tp>&
operator+=(
const valarray<_Tp>&);
414 valarray<_Tp>&
operator-=(
const valarray<_Tp>&);
417 valarray<_Tp>&
operator^=(
const valarray<_Tp>&);
420 valarray<_Tp>&
operator|=(
const valarray<_Tp>&);
423 valarray<_Tp>&
operator&=(
const valarray<_Tp>&);
426 valarray<_Tp>& operator<<=(const valarray<_Tp>&);
432 valarray<_Tp>&
operator*=(
const _Expr<_Dom, _Tp>&);
434 valarray<_Tp>&
operator/=(
const _Expr<_Dom, _Tp>&);
436 valarray<_Tp>&
operator%=(
const _Expr<_Dom, _Tp>&);
438 valarray<_Tp>&
operator+=(
const _Expr<_Dom, _Tp>&);
440 valarray<_Tp>&
operator-=(
const _Expr<_Dom, _Tp>&);
442 valarray<_Tp>&
operator^=(
const _Expr<_Dom, _Tp>&);
444 valarray<_Tp>&
operator|=(
const _Expr<_Dom, _Tp>&);
446 valarray<_Tp>&
operator&=(
const _Expr<_Dom, _Tp>&);
448 valarray<_Tp>& operator<<=(const _Expr<_Dom, _Tp>&);
450 valarray<_Tp>&
operator>>=(
const _Expr<_Dom, _Tp>&);
485 valarray<_Tp>
shift (
int)
const;
502 valarray<_Tp>
cshift(
int)
const;
514 _Expr<_ValFunClos<_ValArray, _Tp>, _Tp>
apply(_Tp func(_Tp))
const;
526 _Expr<_RefFunClos<_ValArray, _Tp>, _Tp>
apply(_Tp func(
const _Tp&))
const;
537 void resize(
size_t __size, _Tp __c = _Tp());
541 _Tp* __restrict__ _M_data;
543 friend class _Array<_Tp>;
546 template<
typename _Tp>
550 __glibcxx_requires_subscript(__i);
554 template<
typename _Tp>
558 __glibcxx_requires_subscript(__i);
564 _GLIBCXX_END_NAMESPACE_VERSION
574 namespace std _GLIBCXX_VISIBILITY(default)
576 _GLIBCXX_BEGIN_NAMESPACE_VERSION
583 template<
typename _Tp>
587 template<
typename _Tp>
590 : _M_size(__n), _M_data(__valarray_get_storage<_Tp>(__n))
591 { std::__valarray_default_construct(_M_data, _M_data + __n); }
593 template<
typename _Tp>
596 : _M_size(__n), _M_data(__valarray_get_storage<_Tp>(__n))
597 { std::__valarray_fill_construct(_M_data, _M_data + __n, __t); }
599 template<
typename _Tp>
602 : _M_size(__n), _M_data(__valarray_get_storage<_Tp>(__n))
604 _GLIBCXX_DEBUG_ASSERT(__p != 0 || __n == 0);
605 std::__valarray_copy_construct(__p, __p + __n, _M_data);
608 template<
typename _Tp>
611 : _M_size(__v._M_size), _M_data(__valarray_get_storage<_Tp>(__v._M_size))
612 { std::__valarray_copy_construct(__v._M_data, __v._M_data + _M_size,
615 template<
typename _Tp>
618 : _M_size(__sa._M_sz), _M_data(__valarray_get_storage<_Tp>(__sa._M_sz))
620 std::__valarray_copy_construct
621 (__sa._M_array, __sa._M_sz, __sa._M_stride, _Array<_Tp>(_M_data));
624 template<
typename _Tp>
627 : _M_size(__ga._M_index.
size()),
628 _M_data(__valarray_get_storage<_Tp>(_M_size))
630 std::__valarray_copy_construct
631 (__ga._M_array, _Array<size_t>(__ga._M_index),
632 _Array<_Tp>(_M_data), _M_size);
635 template<
typename _Tp>
638 : _M_size(__ma._M_sz), _M_data(__valarray_get_storage<_Tp>(__ma._M_sz))
640 std::__valarray_copy_construct
641 (__ma._M_array, __ma._M_mask, _Array<_Tp>(_M_data), _M_size);
644 template<
typename _Tp>
647 : _M_size(__ia._M_sz), _M_data(__valarray_get_storage<_Tp>(__ia._M_sz))
649 std::__valarray_copy_construct
650 (__ia._M_array, __ia._M_index, _Array<_Tp>(_M_data), _M_size);
653 #ifdef __GXX_EXPERIMENTAL_CXX0X__
654 template<
typename _Tp>
657 : _M_size(__l.
size()), _M_data(__valarray_get_storage<_Tp>(__l.
size()))
658 { std::__valarray_copy_construct (__l.begin(), __l.end(), _M_data); }
661 template<
typename _Tp>
template<
class _Dom>
664 : _M_size(__e.
size()), _M_data(__valarray_get_storage<_Tp>(_M_size))
665 { std::__valarray_copy_construct(__e, _M_size, _Array<_Tp>(_M_data)); }
667 template<
typename _Tp>
669 valarray<_Tp>::~valarray()
671 std::__valarray_destroy_elements(_M_data, _M_data + _M_size);
672 std::__valarray_release_memory(_M_data);
675 template<
typename _Tp>
676 inline valarray<_Tp>&
681 if (_M_size == __v._M_size)
682 std::__valarray_copy(__v._M_data, _M_size, _M_data);
687 std::__valarray_destroy_elements(_M_data, _M_data + _M_size);
688 std::__valarray_release_memory(_M_data);
690 _M_size = __v._M_size;
691 _M_data = __valarray_get_storage<_Tp>(_M_size);
692 std::__valarray_copy_construct(__v._M_data, __v._M_data + _M_size,
698 #ifdef __GXX_EXPERIMENTAL_CXX0X__
699 template<
typename _Tp>
705 if (_M_size == __l.size())
706 std::__valarray_copy(__l.begin(), __l.size(), _M_data);
711 std::__valarray_destroy_elements(_M_data, _M_data + _M_size);
712 std::__valarray_release_memory(_M_data);
714 _M_size = __l.size();
715 _M_data = __valarray_get_storage<_Tp>(_M_size);
716 std::__valarray_copy_construct(__l.begin(), __l.begin() + _M_size,
723 template<
typename _Tp>
727 std::__valarray_fill(_M_data, _M_size, __t);
731 template<
typename _Tp>
735 _GLIBCXX_DEBUG_ASSERT(_M_size == __sa._M_sz);
736 std::__valarray_copy(__sa._M_array, __sa._M_sz,
737 __sa._M_stride, _Array<_Tp>(_M_data));
741 template<
typename _Tp>
745 _GLIBCXX_DEBUG_ASSERT(_M_size == __ga._M_index.
size());
746 std::__valarray_copy(__ga._M_array, _Array<size_t>(__ga._M_index),
747 _Array<_Tp>(_M_data), _M_size);
751 template<
typename _Tp>
755 _GLIBCXX_DEBUG_ASSERT(_M_size == __ma._M_sz);
756 std::__valarray_copy(__ma._M_array, __ma._M_mask,
757 _Array<_Tp>(_M_data), _M_size);
761 template<
typename _Tp>
765 _GLIBCXX_DEBUG_ASSERT(_M_size == __ia._M_sz);
766 std::__valarray_copy(__ia._M_array, __ia._M_index,
767 _Array<_Tp>(_M_data), _M_size);
771 template<
typename _Tp>
template<
class _Dom>
775 _GLIBCXX_DEBUG_ASSERT(_M_size == __e.size());
776 std::__valarray_copy(__e, _M_size, _Array<_Tp>(_M_data));
780 template<
typename _Tp>
781 inline _Expr<_SClos<_ValArray,_Tp>, _Tp>
784 typedef _SClos<_ValArray,_Tp> _Closure;
785 return _Expr<_Closure, _Tp>(_Closure (_Array<_Tp>(_M_data), __s));
788 template<
typename _Tp>
793 template<
typename _Tp>
794 inline _Expr<_GClos<_ValArray,_Tp>, _Tp>
797 typedef _GClos<_ValArray,_Tp> _Closure;
798 return _Expr<_Closure, _Tp>
799 (_Closure(_Array<_Tp>(_M_data), __gs._M_index->_M_index));
802 template<
typename _Tp>
807 (_Array<_Tp>(_M_data), __gs._M_index->_M_index);
810 template<
typename _Tp>
815 size_t __e = __m.
size();
816 for (
size_t __i=0; __i<__e; ++__i)
819 _Array<bool> (__m)));
822 template<
typename _Tp>
827 size_t __e = __m.
size();
828 for (
size_t __i=0; __i<__e; ++__i)
833 template<
typename _Tp>
834 inline _Expr<_IClos<_ValArray,_Tp>, _Tp>
837 typedef _IClos<_ValArray,_Tp> _Closure;
838 return _Expr<_Closure, _Tp>(_Closure(*
this, __i));
841 template<
typename _Tp>
846 _Array<size_t>(__i));
858 _GLIBCXX_DEBUG_ASSERT(_M_size > 0);
859 return std::__valarray_sum(_M_data, _M_data + _M_size);
871 _Tp* __restrict__ __tmp_M_data =
872 std::__valarray_get_storage<_Tp>(_M_size);
875 std::__valarray_copy_construct(_M_data,
876 _M_data + _M_size, __tmp_M_data);
879 if (
size_t(__n) > _M_size)
882 std::__valarray_copy_construct(_M_data + __n,
883 _M_data + _M_size, __tmp_M_data);
884 std::__valarray_default_construct(__tmp_M_data + _M_size - __n,
885 __tmp_M_data + _M_size);
889 if (-
size_t(__n) > _M_size)
892 std::__valarray_copy_construct(_M_data, _M_data + _M_size + __n,
894 std::__valarray_default_construct(__tmp_M_data,
898 __ret._M_size = _M_size;
899 __ret._M_data = __tmp_M_data;
912 _Tp* __restrict__ __tmp_M_data =
913 std::__valarray_get_storage<_Tp>(_M_size);
916 std::__valarray_copy_construct(_M_data,
917 _M_data + _M_size, __tmp_M_data);
920 if (
size_t(__n) > _M_size)
921 __n = int(__n % _M_size);
923 std::__valarray_copy_construct(_M_data, _M_data + __n,
924 __tmp_M_data + _M_size - __n);
925 std::__valarray_copy_construct(_M_data + __n, _M_data + _M_size,
930 if (-
size_t(__n) > _M_size)
931 __n = -int(-
size_t(__n) % _M_size);
933 std::__valarray_copy_construct(_M_data + _M_size + __n,
934 _M_data + _M_size, __tmp_M_data);
935 std::__valarray_copy_construct(_M_data, _M_data + _M_size + __n,
939 __ret._M_size = _M_size;
940 __ret._M_data = __tmp_M_data;
951 std::__valarray_destroy_elements(_M_data, _M_data + _M_size);
954 std::__valarray_release_memory(_M_data);
956 _M_data = __valarray_get_storage<_Tp>(__n);
958 std::__valarray_fill_construct(_M_data, _M_data + __n, __c);
961 template<
typename _Tp>
965 _GLIBCXX_DEBUG_ASSERT(_M_size > 0);
969 template<
typename _Tp>
973 _GLIBCXX_DEBUG_ASSERT(_M_size > 0);
978 inline _Expr<_ValFunClos<_ValArray, _Tp>, _Tp>
981 typedef _ValFunClos<_ValArray, _Tp> _Closure;
982 return _Expr<_Closure, _Tp>(_Closure(*
this, func));
986 inline _Expr<_RefFunClos<_ValArray, _Tp>, _Tp>
989 typedef _RefFunClos<_ValArray, _Tp> _Closure;
990 return _Expr<_Closure, _Tp>(_Closure(*
this, func));
993 #define _DEFINE_VALARRAY_UNARY_OPERATOR(_Op, _Name) \
994 template<typename _Tp> \
995 inline typename valarray<_Tp>::template _UnaryOp<_Name>::_Rt \
996 valarray<_Tp>::operator _Op() const \
998 typedef _UnClos<_Name, _ValArray, _Tp> _Closure; \
999 typedef typename __fun<_Name, _Tp>::result_type _Rt; \
1000 return _Expr<_Closure, _Rt>(_Closure(*this)); \
1003 _DEFINE_VALARRAY_UNARY_OPERATOR(+, __unary_plus)
1004 _DEFINE_VALARRAY_UNARY_OPERATOR(-, __negate)
1005 _DEFINE_VALARRAY_UNARY_OPERATOR(~, __bitwise_not)
1006 _DEFINE_VALARRAY_UNARY_OPERATOR (!, __logical_not)
1008 #undef _DEFINE_VALARRAY_UNARY_OPERATOR
1010 #define _DEFINE_VALARRAY_AUGMENTED_ASSIGNMENT(_Op, _Name) \
1011 template<class _Tp> \
1012 inline valarray<_Tp>& \
1013 valarray<_Tp>::operator _Op##=(const _Tp &__t) \
1015 _Array_augmented_##_Name(_Array<_Tp>(_M_data), _M_size, __t); \
1019 template<class _Tp> \
1020 inline valarray<_Tp>& \
1021 valarray<_Tp>::operator _Op##=(const valarray<_Tp> &__v) \
1023 _GLIBCXX_DEBUG_ASSERT(_M_size == __v._M_size); \
1024 _Array_augmented_##_Name(_Array<_Tp>(_M_data), _M_size, \
1025 _Array<_Tp>(__v._M_data)); \
1029 _DEFINE_VALARRAY_AUGMENTED_ASSIGNMENT(+, __plus)
1030 _DEFINE_VALARRAY_AUGMENTED_ASSIGNMENT(-, __minus)
1031 _DEFINE_VALARRAY_AUGMENTED_ASSIGNMENT(*, __multiplies)
1032 _DEFINE_VALARRAY_AUGMENTED_ASSIGNMENT(/, __divides)
1033 _DEFINE_VALARRAY_AUGMENTED_ASSIGNMENT(%, __modulus)
1034 _DEFINE_VALARRAY_AUGMENTED_ASSIGNMENT(^, __bitwise_xor)
1035 _DEFINE_VALARRAY_AUGMENTED_ASSIGNMENT(&, __bitwise_and)
1036 _DEFINE_VALARRAY_AUGMENTED_ASSIGNMENT(|, __bitwise_or)
1037 _DEFINE_VALARRAY_AUGMENTED_ASSIGNMENT(<<, __shift_left)
1038 _DEFINE_VALARRAY_AUGMENTED_ASSIGNMENT(>>, __shift_right)
1040 #undef _DEFINE_VALARRAY_AUGMENTED_ASSIGNMENT
1042 #define _DEFINE_VALARRAY_EXPR_AUGMENTED_ASSIGNMENT(_Op, _Name) \
1043 template<class _Tp> template<class _Dom> \
1044 inline valarray<_Tp>& \
1045 valarray<_Tp>::operator _Op##=(const _Expr<_Dom, _Tp>& __e) \
1047 _Array_augmented_##_Name(_Array<_Tp>(_M_data), __e, _M_size); \
1051 _DEFINE_VALARRAY_EXPR_AUGMENTED_ASSIGNMENT(+, __plus)
1052 _DEFINE_VALARRAY_EXPR_AUGMENTED_ASSIGNMENT(-, __minus)
1053 _DEFINE_VALARRAY_EXPR_AUGMENTED_ASSIGNMENT(*, __multiplies)
1054 _DEFINE_VALARRAY_EXPR_AUGMENTED_ASSIGNMENT(/, __divides)
1055 _DEFINE_VALARRAY_EXPR_AUGMENTED_ASSIGNMENT(%, __modulus)
1056 _DEFINE_VALARRAY_EXPR_AUGMENTED_ASSIGNMENT(^, __bitwise_xor)
1057 _DEFINE_VALARRAY_EXPR_AUGMENTED_ASSIGNMENT(&, __bitwise_and)
1058 _DEFINE_VALARRAY_EXPR_AUGMENTED_ASSIGNMENT(|, __bitwise_or)
1059 _DEFINE_VALARRAY_EXPR_AUGMENTED_ASSIGNMENT(<<, __shift_left)
1060 _DEFINE_VALARRAY_EXPR_AUGMENTED_ASSIGNMENT(>>, __shift_right)
1062 #undef _DEFINE_VALARRAY_EXPR_AUGMENTED_ASSIGNMENT
1065 #define _DEFINE_BINARY_OPERATOR(_Op, _Name) \
1066 template<typename _Tp> \
1067 inline _Expr<_BinClos<_Name, _ValArray, _ValArray, _Tp, _Tp>, \
1068 typename __fun<_Name, _Tp>::result_type> \
1069 operator _Op(const valarray<_Tp>& __v, const valarray<_Tp>& __w) \
1071 _GLIBCXX_DEBUG_ASSERT(__v.size() == __w.size()); \
1072 typedef _BinClos<_Name, _ValArray, _ValArray, _Tp, _Tp> _Closure; \
1073 typedef typename __fun<_Name, _Tp>::result_type _Rt; \
1074 return _Expr<_Closure, _Rt>(_Closure(__v, __w)); \
1077 template<typename _Tp> \
1078 inline _Expr<_BinClos<_Name, _ValArray,_Constant, _Tp, _Tp>, \
1079 typename __fun<_Name, _Tp>::result_type> \
1080 operator _Op(const valarray<_Tp>& __v, const _Tp& __t) \
1082 typedef _BinClos<_Name, _ValArray, _Constant, _Tp, _Tp> _Closure; \
1083 typedef typename __fun<_Name, _Tp>::result_type _Rt; \
1084 return _Expr<_Closure, _Rt>(_Closure(__v, __t)); \
1087 template<typename _Tp> \
1088 inline _Expr<_BinClos<_Name, _Constant, _ValArray, _Tp, _Tp>, \
1089 typename __fun<_Name, _Tp>::result_type> \
1090 operator _Op(const _Tp& __t, const valarray<_Tp>& __v) \
1092 typedef _BinClos<_Name, _Constant, _ValArray, _Tp, _Tp> _Closure; \
1093 typedef typename __fun<_Name, _Tp>::result_type _Rt; \
1094 return _Expr<_Closure, _Rt>(_Closure(__t, __v)); \
1097 _DEFINE_BINARY_OPERATOR(+, __plus)
1098 _DEFINE_BINARY_OPERATOR(-, __minus)
1099 _DEFINE_BINARY_OPERATOR(*, __multiplies)
1100 _DEFINE_BINARY_OPERATOR(/, __divides)
1101 _DEFINE_BINARY_OPERATOR(%, __modulus)
1102 _DEFINE_BINARY_OPERATOR(^, __bitwise_xor)
1103 _DEFINE_BINARY_OPERATOR(&, __bitwise_and)
1104 _DEFINE_BINARY_OPERATOR(|, __bitwise_or)
1105 _DEFINE_BINARY_OPERATOR(<<, __shift_left)
1106 _DEFINE_BINARY_OPERATOR(>>, __shift_right)
1107 _DEFINE_BINARY_OPERATOR(&&, __logical_and)
1108 _DEFINE_BINARY_OPERATOR(||, __logical_or)
1109 _DEFINE_BINARY_OPERATOR(==, __equal_to)
1110 _DEFINE_BINARY_OPERATOR(!=, __not_equal_to)
1111 _DEFINE_BINARY_OPERATOR(<, __less)
1112 _DEFINE_BINARY_OPERATOR(>, __greater)
1113 _DEFINE_BINARY_OPERATOR(<=, __less_equal)
1114 _DEFINE_BINARY_OPERATOR(>=, __greater_equal)
1116 #undef _DEFINE_BINARY_OPERATOR
1118 #ifdef __GXX_EXPERIMENTAL_CXX0X__
1127 {
return std::__addressof(__va[0]); }
1137 {
return std::__addressof(__va[0]); }
1147 {
return std::__addressof(__va[0]) + __va.
size(); }
1157 {
return std::__addressof(__va[0]) + __va.
size(); }
1158 #endif // __GXX_EXPERIMENTAL_CXX0X__
1162 _GLIBCXX_END_NAMESPACE_VERSION