Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- struct Bar{
- private{
- field other:shared_ptr[Bar];
- field key_1:i32;
- field key_2:i32;
- }
- function new(addr:i32):Bar{
- let seed = random();
- return Bar{key_1 = addr ^ seed, key_2 = seed};
- }
- function set_other(self:ref Bar, other:shared_ptr[Bar]){
- self->other = other;
- }
- function copy(target:out Bar, source:ref Bar){
- let seed = random();
- target->key_1 = seed;
- if ( not source->other.empty() ){
- let other = source->other.get(); //ref Bar
- print(other->key_1 ^ other->key_2); // prints some garbage
- }
- target->key_2 = source->key_1 ^ source->key_2 ^ seed;
- }
- };
- function foo(){
- var a:shared_ptr[Bar] = shared_ptr::new(Bar::new(1));
- var b:shared_ptr[Bar] = shared_ptr::new(Bar::new(2));
- // copies
- external_call(a, b);
- *a = *b;
- }
- // compiler does not see the source code for this function
- function external_call(a b:shared_ptr[Bar]){
- b->set_other(a);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement