Boost logo

Boost Users :

Subject: Re: [Boost-users] Indirectly 'recursive' type erasure
From: Steven Watanabe (watanabesj_at_[hidden])
Date: 2014-03-11 18:57:48


AMDG

On 03/11/2014 01:42 PM, Samuel Christie wrote:
>
> I'm not sure how to do the get_collection_type deduction in such a way that
> it works for more than one type of collection. I.e., both a vector<T> and a
> Collection as defined above.
>

You can either use a nested typedef (like T::iterator)
or you can use decltype(boost::declval<T>().collection()).

> I also tried to do a test with the slightly more basic vector<Test>
> collection type. I got close, but I eventually had issues with the !=
> required by the foreach loop pattern.
>

That shouldn't have been a problem, since
equality_comparable defines both == and !=.

> Here's a paste of most of the test code: pastebin.com/GiQwQTcq
>
> Hopefully what I'm having trouble with makes sense to you; if not, maybe
> just providing a few more examples of the pieces required to make a
> for(auto i : t.collection()) work based on the above class declaration
> would be helpful. I feel like either I'm getting close, or I'm trying to do
> something I shouldn't be.
>

You're really close. I've gotten your example
working. See attached. (I also cleaned it up
a bit by using BOOST_TYPE_ERASURE_MEMBER/FREE).
Tested with MSVC 12 and GCC 4.7.

In Christ,
Steven Watanabe




Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net