Boost logo

Boost Users :

Subject: Re: [Boost-users] Indirectly 'recursive' type erasure
From: Samuel Christie (schrist_at_[hidden])
Date: 2014-03-13 16:09:57


Thanks again for your help. I was also able to get that example to compile,
which was perfect. Unfortunately, it seems rather fragile. I had copied
most of the pieces over into a split test.hpp/test.cpp, and kept getting
errors. I did eventually resolve the problem by more completely replacing
them with your code directly, but I wasn't able to figure out what was
causing the problem. Of course, that means when I tried to apply it to my
real code, I ended up with the same error:

solution.hpp:36:3: error: template argument 1 is invalid
solution.hpp:36:4: error: expected identifier before '::' token
solution.hpp:36:6: error: typedef name may not be a nested-name-specifier
solution.hpp:36:6: error: expected ';' at end of member declaration
solution.hpp:36:11: error: 'type' does not name a type
solution.hpp:52:3: error: template argument 1 is invalid
solution.hpp:52:4: error: expected identifier before '::' token
solution.hpp:52:6: error: typedef name may not be a nested-name-specifier
solution.hpp:52:6: error: expected ';' at end of member declaration
solution.hpp:52:11: error: 'type' does not name a type

the relevant pieces of code were the following:

31 template<class T>
32 struct get_neighborhood_type {
33 typedef typename mpl::eval_if<is_placeholder<T>,
34 mpl::identity<void>,
35 get_neighborhood_type_impl<T>
36 >::type type;
37 };

and

47 template<class T>
48 struct get_iterator_type {
49 typedef typename mpl::eval_if<is_placeholder<T>,
50 mpl::identity<void>,
51 get_iterator_type_impl<T>
52 >::type type;
53 };

which are pretty much the same as what you sent me, but with the names
changed. Are there any likely causes of these errors that occur to you, so
I can try so fix them in a somewhat intelligent fashion?

Thanks.

-sc

On Tue, Mar 11, 2014 at 6:57 PM, Steven Watanabe <watanabesj_at_[hidden]>wrote:

> 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 mailing list
> Boost-users_at_[hidden]
> http://lists.boost.org/mailman/listinfo.cgi/boost-users
>



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