//Purpose: // Test code based on: /* From: Antony Polukhin Newsgroups: gmane.comp.lib.boost.devel Subject: Re: [variant] Please vote for behavior Date: Wed, 30 Jan 2013 14:58:10 +0400 */ // #include #include enum type_enum { type_scalar , type_ptr }; struct object_top { virtual ~object_top() { std::cout<<"~base()\n"; } virtual type_enum type_get()const =0; }; struct object_scalar : public object_top { type_enum type_get()const { return type_scalar; } }; union my_union; struct object_ptr : public object_top { type_enum type_get()const { return type_ptr; } my_union*my_ptr; object_ptr(my_union*a_ptr) : my_ptr(a_ptr) {} }; union my_union { object_ptr p_; object_scalar s_; my_union() : s_(object_scalar()) {} my_union(my_union*a_p) : p_(a_p) {} }; std::ostream& operator<< ( std::ostream& sout , my_union const* u_ptr ) { object_ptr const*op=&(u_ptr->p_); object_top const*top=op; unsigned i=0; type_enum te=top->type_get(); sout<<"\n"; char const*const indent=" "; sout<my_ptr; op=&(u_ptr->p_); top=op; te=top->type_get(); sout< vec_us(0); std::cout<<"vec_us.size()="<