Re: [Boost-users] mpi: sending/receiving different types
-----Original Message----- From: "Riccardo Murri" [riccardo.murri@gmail.com] Date: 09/12/2010 11:58 AM To: boost-users@lists.boost.org Subject: Re: [Boost-users] mpi: sending/receiving different types
Hi Hicham,
<snip>
3. I just thought of using boost::variant<> over all the possible types.
I think this is the way to go; I'm attaching a sample program. Not sure this is exactly what you need, but could be enough to get you started.
Best regards, Riccardo
It's exactly what I was gonna do, thanks very much. The bit I am missing now is my question here: http://lists.boost.org/boost-users/2010/12/64797.php I don't know how to assign the most derived type to the variant at creation in the sender. In your code snippet, you explicitly construct c, then assign it to v. For me, I get given const Base& and I need to store the actual type. This seems to be what some of the boost libraries have to do themselves, but I can't remember which one exactly. I could intrusively add virtual functions to the classes but I don't want that, thanks Riccardo,
Hi Hicham,
On Thu, Dec 9, 2010 at 2:47 PM, Hicham Mouline
The bit I am missing now is my question here:
http://lists.boost.org/boost-users/2010/12/64797.php
I don't know how to assign the most derived type to the variant at creation in the sender. In your code snippet, you explicitly construct c, then assign it to v. For me, I get given const Base& and I need to store the actual type.
If all you have is a `const Base&` then slicing has already happened
and there's no way to get the original type: all you have is a base
instance.
Can't you change your code to pass around
`boost::variant
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On Thursday 09 December 2010, Riccardo Murri wrote:
If all you have is a `const Base&` then slicing has already happened
Why do you say that? Polymorphism can be done with references as well as with pointers. -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.9 (GNU/Linux) iEYEARECAAYFAk0A46QACgkQ5vihyNWuA4UWOwCeJoUaqZS+hbmo+d03Z8/6SDpy 8wgAn3LXL5UcLox/d3gsanmfzXCZIjPB =BssA -----END PGP SIGNATURE-----
On Thu, Dec 9, 2010 at 3:11 PM, Frank Mori Hess
On Thursday 09 December 2010, Riccardo Murri wrote:
If all you have is a `const Base&` then slicing has already happened
Why do you say that? Polymorphism can be done with references as well as with pointers.
Yes, sorry - my original wording is indeed plain wrong... What I meant to say is that there is no way to get information on the "original" type, unless you resort to virtual methods or a discriminating field. Best regards, Riccardo
On Dec 9, 2010, at 3:11 PM, Frank Mori Hess wrote:
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1
On Thursday 09 December 2010, Riccardo Murri wrote:
If all you have is a `const Base&` then slicing has already happened
Why do you say that? Polymorphism can be done with references as well as with pointers.
If you give Boost.Serializatiion a reference to the base type, then how should it convert your base class object to a derived one?
participants (4)
-
Frank Mori Hess
-
Hicham Mouline
-
Matthias Troyer
-
Riccardo Murri