@@ -8,6 +8,7 @@ use num::Zero;
8
8
9
9
use libc:: c_int;
10
10
use num:: Complex ;
11
+ use std:: mem;
11
12
use std:: ops:: Neg ;
12
13
use std:: ops:: { Add , BitAnd , BitOr , BitXor , Div , Mul , Not , Rem , Shl , Shr , Sub } ;
13
14
@@ -854,6 +855,49 @@ arith_func!(BitAnd, bitand, bitand);
854
855
arith_func ! ( BitOr , bitor, bitor) ;
855
856
arith_func ! ( BitXor , bitxor, bitxor) ;
856
857
858
+ macro_rules! bitshift_scalar_func {
859
+ ( $rust_type: ty, $trait_name: ident, $op_name: ident) => {
860
+ impl <T > $trait_name<$rust_type> for Array <T >
861
+ where
862
+ T : HasAfEnum + ImplicitPromote <$rust_type>,
863
+ $rust_type: HasAfEnum + ImplicitPromote <T >,
864
+ <T as ImplicitPromote <$rust_type>>:: Output : HasAfEnum ,
865
+ {
866
+ type Output = Array <<T as ImplicitPromote <$rust_type>>:: Output >;
867
+
868
+ fn $op_name( self , rhs: $rust_type) -> Self :: Output {
869
+ let op2 = constant( rhs, self . dims( ) ) ;
870
+ self . $op_name( op2)
871
+ }
872
+ }
873
+ impl <' f, T > $trait_name<$rust_type> for & ' f Array <T >
874
+ where
875
+ T : HasAfEnum + ImplicitPromote <$rust_type>,
876
+ $rust_type: HasAfEnum + ImplicitPromote <T >,
877
+ <T as ImplicitPromote <$rust_type>>:: Output : HasAfEnum ,
878
+ {
879
+ type Output = Array <<T as ImplicitPromote <$rust_type>>:: Output >;
880
+
881
+ fn $op_name( self , rhs: $rust_type) -> Self :: Output {
882
+ let op2 = constant( rhs, self . dims( ) ) ;
883
+ self . $op_name( op2)
884
+ }
885
+ }
886
+ } ;
887
+ }
888
+
889
+ macro_rules! shift_spec {
890
+ ( $trait_name: ident, $op_name: ident) => {
891
+ bitshift_scalar_func!( u64 , $trait_name, $op_name) ;
892
+ bitshift_scalar_func!( u32 , $trait_name, $op_name) ;
893
+ bitshift_scalar_func!( u16 , $trait_name, $op_name) ;
894
+ bitshift_scalar_func!( u8 , $trait_name, $op_name) ;
895
+ } ;
896
+ }
897
+
898
+ shift_spec ! ( Shl , shl) ;
899
+ shift_spec ! ( Shr , shr) ;
900
+
857
901
#[ cfg( op_assign) ]
858
902
mod op_assign {
859
903
@@ -871,7 +915,6 @@ mod op_assign {
871
915
<A as ImplicitPromote <B >>:: Output : HasAfEnum ,
872
916
<B as ImplicitPromote <A >>:: Output : HasAfEnum ,
873
917
{
874
- #[ allow( unused_variables) ]
875
918
fn $fn_name( & mut self , rhs: Array <B >) {
876
919
let tmp_seq = Seq :: <f32 >:: default ( ) ;
877
920
let mut idxrs = Indexer :: default ( ) ;
@@ -893,6 +936,35 @@ mod op_assign {
893
936
arith_assign_func ! ( ShlAssign , shl_assign, shiftl) ;
894
937
arith_assign_func ! ( ShrAssign , shr_assign, shiftr) ;
895
938
939
+ macro_rules! shift_assign_func {
940
+ ( $rust_type: ty, $trait_name: ident, $op_name: ident, $func: ident) => {
941
+ impl <T > $trait_name<$rust_type> for Array <T >
942
+ where
943
+ $rust_type: HasAfEnum + ImplicitPromote <T >,
944
+ T : HasAfEnum
945
+ + ImplicitPromote <$rust_type>
946
+ + ImplicitPromote <$rust_type, Output = T >,
947
+ {
948
+ fn $op_name( & mut self , rhs: $rust_type) {
949
+ let mut temp = $func( self , & rhs, false ) ;
950
+ mem:: swap( self , & mut temp) ;
951
+ }
952
+ }
953
+ } ;
954
+ }
955
+
956
+ macro_rules! shift_assign_spec {
957
+ ( $trait_name: ident, $op_name: ident, $func: ident) => {
958
+ shift_assign_func!( u64 , $trait_name, $op_name, $func) ;
959
+ shift_assign_func!( u32 , $trait_name, $op_name, $func) ;
960
+ shift_assign_func!( u16 , $trait_name, $op_name, $func) ;
961
+ shift_assign_func!( u8 , $trait_name, $op_name, $func) ;
962
+ } ;
963
+ }
964
+
965
+ shift_assign_spec ! ( ShlAssign , shl_assign, shiftl) ;
966
+ shift_assign_spec ! ( ShrAssign , shr_assign, shiftr) ;
967
+
896
968
macro_rules! bit_assign_func {
897
969
( $op_name: ident, $fn_name: ident, $func: ident) => {
898
970
impl <A , B > $op_name<Array <B >> for Array <A >
@@ -902,7 +974,6 @@ mod op_assign {
902
974
<A as ImplicitPromote <B >>:: Output : HasAfEnum ,
903
975
<B as ImplicitPromote <A >>:: Output : HasAfEnum ,
904
976
{
905
- #[ allow( unused_variables) ]
906
977
fn $fn_name( & mut self , rhs: Array <B >) {
907
978
let tmp_seq = Seq :: <f32 >:: default ( ) ;
908
979
let mut idxrs = Indexer :: default ( ) ;
0 commit comments