Boost logo

Boost Users :

Subject: Re: [Boost-users] challange to MPL gurus
From: Larry Evans (cppljevans_at_[hidden])
Date: 2011-12-13 00:30:02


On 12/12/11 22:49, Robert Ramey wrote:
> Jeremiah Willcock wrote:
>> On Mon, 12 Dec 2011, Larry Evans wrote:
>>
>>> On 12/12/11 17:04, Larry Evans wrote:
>>>> On 12/12/11 16:39, Jeremiah Willcock wrote:
>>> [snip]
>>>> Looking at your code, it seems you solved the problem by removing
>>>> the nested specialization of is_end, with a specialization in file
>>>> scope of check_unless_end. I've a vague memory of hearing some
>>>> similar solution elsewhere. Is there some reason why
>>>> specializations cannot occur within the class?
>>>>
>>>> -regards,
>>>> Larry
>>>
>>> The reason is explained in this thread:
>>>
>>> http://groups.google.com/group/comp.lang.c++.moderated/browse_frm/thread/c040d6d750bf5c08/26bc1ce0b89b5979?#26bc1ce0b89b5979
>>
>> I don't see anything in that thread that talks about why member
>> templates can't be specialized in-class. I don't see a good reason
>> for that limitation; how is a class member specialization different
>> from one in a namespace other than that there can be template
>> parameters on the class itself?
>>
>> -- Jeremiah Willcock
>
> First of all I want to thank everyone who contributed to this thread. I
> carefully read
> every single message and the links. I was really lost.
>
> I was really bothered with the idea that the template specialization would
> work
> outside the class but not in it - as you were. The links didn't seem on
> point on
> this subject. I took my original solution and moved the specializations
> outside
> the class. This failed because the I wasn't defined so I added it do the
> template
> arguments. Then a few syntax corrections and it started to work - OK,
> problem solved - but now I was left with this really annoying feature whose
> behavior changed when the specialization was moved out side the class. So
> I moved it back in - and voila - worked as expected. Here is my solution:
>
>
> template<typename I>
> struct ForwardIterator {
> template<typename I, typename B>
> struct is_end {};
>
> template<typename I2>
> struct is_end<I2, false_> {
> typedef typename deref<I2>::type t1;
> typedef typename next<I2>::type t2;
> BOOST_CONCEPT_ASSERT(( ForwardIterator<t2> ));
> };
>
> typedef typename is_end<
> I,
> typename boost::is_same<
> boost::mpl::l_iter<boost::mpl::l_end>,
> I
> >
> > type;
> typedef typename boost::mpl::print<
> I
> >::type t1;
>
> BOOST_MPL_ASSERT((
> is_convertible<
> typename I::category,
> forward_iterator_tag
> >
> ));
> };
>
> Basically, I just had to avoid depending on the "outter" template parameter.
> This had bothered
> me before but I wasn't aware of the right syntax to avoid it. I had to use
> the specialization syntax above rather than the template<> syntax I was
> familiar with. So
> I guess that resolves the problem.
>
> Again, thanks for everyone who contributed - really would never have found
> it by myself.
>
> Robert Ramey
Hi Robert,

I couldn't get this code to compile with gcc-4.7-20111008. Before any
revision, got:

ramey_iter_concept_check.cpp:22:14: error: declaration of 'class I'
ramey_iter_concept_check.cpp:20:10: error: shadows template parm 'class I'
ramey_iter_concept_check.cpp:32:22: error: expected nested-name-specifier
ramey_iter_concept_check.cpp:38:7: error: invalid declarator before 'type'

After eliminating the showing I, as shown in the attached, I got:

/home/evansl/download/gcc/4.7-20111008/install/bin/g++ -c -Wall
-Wstrict-overflow -ftemplate-depth-300 -O0 -g3 -fno-inline -std=gnu++0x
-I/home/evansl/prog_dev/boost-svn/ro/trunk/sandbox/ro/numeric_bindings
-I/home/evansl/prog_dev/boost-svn/ro/trunk/sandbox/rw/non_variadic_templates
-I/home/evansl/prog_dev/boost-svn/ro/trunk -DTEMPLATE_DEPTH=300
ramey_iter_concept_check.cpp -MMD -o
build/gcc4_7n/boost-svn/ro/trunk/sandbox/rw/variadic_templates/libs/mpl/example/ramey_iter_concept_check.o

ramey_iter_concept_check.cpp:31:22: error: expected nested-name-specifier
ramey_iter_concept_check.cpp:37:7: error: invalid declarator before 'type'
make: ***
[build/gcc4_7n/boost-svn/ro/trunk/sandbox/rw/variadic_templates/libs/mpl/example/ramey_iter_concept_check.o]
Error 1

I guess you're using MS or an earlier gcc.

-regards,
Larry




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