boost variant question

Hi, I am new to the boost variant and have the following issue. I have, two numeric vector-like structures (say a contiguous and a strided – the actual problem has many more), and would like to create a variant of those two to use interchangeably in my code. Then plan is to have different constructors for different hosted structures and play with deriving-from/containing a variant These structures, being stl-like have iterators. Is there a mechanism to export the iterator that corresponds to the structure hosted in the variant and use it? Would I have along-side a variant of the corresponding iterators – if this is possible at all? Is there a –preferrably elegant, nut necessarily efficient- solution to this? Thank you in advance for your help, Kind Regards, Petros

On 09/23/11 21:49, petros wrote:
Hi, I am new to the boost variant and have the following issue. I have, two numeric vector-like structures (say a contiguous and a strided – the actual problem has many more), and would like to create a variant of those two to use interchangeably in my code. Then plan is to have different constructors for different hosted structures and play with deriving-from/containing a variant These structures, being stl-like have iterators. Is there a mechanism to export the iterator that corresponds to the structure hosted in the variant and use it? Would I have along-side a variant of the corresponding iterators – if this is possible at all? Is there a –preferrably elegant, nut necessarily efficient- solution to this? Thank you in advance for your help, Kind Regards, Petros
Why wouldn't a boost::multi_array, a_multi_array, satisfy your requirements? a_multi_array.data() would return the contiguous vector-like structure, and a_multi_array itself would be the strided vector-like structure.

Hi Larry, Thank you for the response. As I said, this is only an example for the reason I am seeking this functionality. Best Regards, Petros -----Original Message----- From: Larry Evans Sent: Saturday, September 24, 2011 6:03 AM To: boost-users@lists.boost.org Subject: Re: [Boost-users] boost variant question On 09/23/11 21:49, petros wrote:
Hi, I am new to the boost variant and have the following issue. I have, two numeric vector-like structures (say a contiguous and a strided – the actual problem has many more), and would like to create a variant of those two to use interchangeably in my code. Then plan is to have different constructors for different hosted structures and play with deriving-from/containing a variant These structures, being stl-like have iterators. Is there a mechanism to export the iterator that corresponds to the structure hosted in the variant and use it? Would I have along-side a variant of the corresponding iterators – if this is possible at all? Is there a –preferrably elegant, nut necessarily efficient- solution to this? Thank you in advance for your help, Kind Regards, Petros
Why wouldn't a boost::multi_array, a_multi_array, satisfy your requirements? a_multi_array.data() would return the contiguous vector-like structure, and a_multi_array itself would be the strided vector-like structure. _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users

Is there a mechanism to export the iterator that corresponds to the structure hosted in the variant and use it?
Actually, variant has only one (type-safe) observing mechanism - static_visitor. Using static visitor you can make your own custom facilities, including the one you mention.

Hi Igor, Thank you for your response. I am not sure that I understand it though. I have seen examples (wrote a couple myself) where, using the static_visitor, "dictated" the behavior of public member functions of the variant type. But which iterator type to associate with the hosted type would require a variant of iterators to be maintaned along-side. Is this what you mean? If not, is there an example or "sketchy" pseudo code you could point me too. Thank you very much for your help. Kind Regards, Petros -----Original Message----- From: Igor R Sent: Saturday, September 24, 2011 12:48 PM To: boost-users@lists.boost.org Subject: Re: [Boost-users] boost variant question
Is there a mechanism to export the iterator that corresponds to the structure hosted in the variant and use it?
Actually, variant has only one (type-safe) observing mechanism - static_visitor. Using static visitor you can make your own custom facilities, including the one you mention. _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users

I am not sure that I understand it though. I have seen examples (wrote a couple myself) where, using the static_visitor, "dictated" the behavior of public member functions of the variant type. But which iterator type to associate with the hosted type would require a variant of iterators to be maintaned along-side. Is this what you mean? If not, is there an example or "sketchy" pseudo code you could point me too.
Sorry, perhaps I misunderstood you. Lets say you've got the following: variant<container1, container2> var; Do you mean to use it like this: iterator1 it = your_begin(var); do_something(it); If so, you have to know "iterator1" type in compile-time - this is the problem, isn't it? Of course, you can find out it with "try and fail" approach, using get() function template, but this would be ugly and hard to support. That's why typically one moves do_something (i.e. anything that depends on the actual container type) to the visitor itself.

Hi Igor, Thank you very much, Best Regards, Petros -----Original Message----- From: Igor R Sent: Sunday, September 25, 2011 3:05 AM To: boost-users@lists.boost.org Subject: Re: [Boost-users] boost variant question
I am not sure that I understand it though. I have seen examples (wrote a couple myself) where, using the static_visitor, "dictated" the behavior of public member functions of the variant type. But which iterator type to associate with the hosted type would require a variant of iterators to be maintaned along-side. Is this what you mean? If not, is there an example or "sketchy" pseudo code you could point me too.
Sorry, perhaps I misunderstood you. Lets say you've got the following: variant<container1, container2> var; Do you mean to use it like this: iterator1 it = your_begin(var); do_something(it); If so, you have to know "iterator1" type in compile-time - this is the problem, isn't it? Of course, you can find out it with "try and fail" approach, using get() function template, but this would be ugly and hard to support. That's why typically one moves do_something (i.e. anything that depends on the actual container type) to the visitor itself. _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
participants (3)
-
Igor R
-
Larry Evans
-
petros