@@ -47,6 +47,20 @@ thread_local!(
4747pub fn add_to_total_8 ( mut x : i32 ) {
4848 total_7. with ( |rc| * rc. borrow_mut ( ) += x) ;
4949}
50+ pub fn pair_sum_9 ( p : ( Value < i32 > , Value < i32 > ) ) -> i32 {
51+ let p: Value < ( Value < i32 > , Value < i32 > ) > = Rc :: new ( RefCell :: new ( p) ) ;
52+ return ( ( * ( * p. borrow ( ) ) . 0 . borrow ( ) ) + ( * ( * p. borrow ( ) ) . 1 . borrow ( ) ) ) ;
53+ }
54+ pub fn string_size_10 ( mut s : Vec < i8 > ) -> usize {
55+ return ( s. len ( ) - 1 ) ;
56+ }
57+ pub fn vector_sum_11 ( mut v : Vec < i32 > ) -> i32 {
58+ return ( v[ 0_usize ] + v[ 1_usize ] ) ;
59+ }
60+ pub fn is_less_12 ( o : std:: cmp:: Ordering ) -> bool {
61+ let o: Value < std:: cmp:: Ordering > = Rc :: new ( RefCell :: new ( o) ) ;
62+ return ( { ( * o. borrow ( ) ) } ) == std:: cmp:: Ordering :: Less ;
63+ }
5064pub fn main ( ) {
5165 __cpp2rust_init_globals ( ) ;
5266 std:: process:: exit ( main_0 ( ) ) ;
@@ -82,6 +96,28 @@ fn main_0() -> i32 {
8296 ( { handler. call ( 2 ) } ) ;
8397 ( { handler. call ( 3 ) } ) ;
8498 assert ! ( ( total_7. with( |rc| * rc. borrow( ) ) == 5 ) ) ;
99+ let mut pf: FnPtr < fn ( ( Value < i32 > , Value < i32 > ) ) -> i32 > =
100+ FnPtr :: < fn ( ( Value < i32 > , Value < i32 > ) ) -> i32 > :: new ( pair_sum_9) ;
101+ assert ! ( ( ( { pf. call( ( Rc :: new( RefCell :: new( 1 ) ) , Rc :: new( RefCell :: new( 2 ) ) ) , ) } ) == 3 ) ) ;
102+ let mut sf: FnPtr < fn ( Vec < i8 > ) -> usize > = FnPtr :: < fn ( Vec < i8 > ) -> usize > :: new ( string_size_10) ;
103+ assert ! (
104+ ( ( {
105+ sf. call( {
106+ let mut __bytes = Ptr :: <i8 >:: from_string_literal( b"abc" ) . to_c_bytes( ) ;
107+ __bytes. push( 0 ) ;
108+ __bytes
109+ } )
110+ } ) == 3_usize )
111+ ) ;
112+ let mut vf: FnPtr < fn ( Vec < i32 > ) -> i32 > = FnPtr :: < fn ( Vec < i32 > ) -> i32 > :: new ( vector_sum_11) ;
113+ assert ! ( ( ( { vf. call( Vec :: from( [ 1 , 2 , ] ) , ) } ) == 3 ) ) ;
114+ let mut of: FnPtr < fn ( std:: cmp:: Ordering ) -> bool > =
115+ FnPtr :: < fn ( std:: cmp:: Ordering ) -> bool > :: new ( is_less_12) ;
116+ assert ! ( ( { of. call( std:: cmp:: Ord :: cmp( & ( 1 ) , & ( 2 ) ) , ) } ) ) ;
117+ assert ! ( !( { of. call( std:: cmp:: Ord :: cmp( & ( 2 ) , & ( 1 ) ) , ) } ) ) ;
118+ let o: Value < std:: cmp:: Ordering > = Rc :: new ( RefCell :: new ( std:: cmp:: Ord :: cmp ( & ( 1 ) , & ( 2 ) ) ) ) ;
119+ let mut op: Ptr < std:: cmp:: Ordering > = ( o. as_pointer ( ) ) ;
120+ assert ! ( ( { ( * op. upgrade( ) . deref( ) ) } ) == std:: cmp:: Ordering :: Less ) ;
85121 return 0 ;
86122}
87123pub fn __cpp2rust_init_globals ( ) {
0 commit comments