Boost logo

Boost :

From: Peder Holt (peder.holt_at_[hidden])
Date: 2004-12-09 02:25:26


On Wed, 8 Dec 2004 16:15:47 -0500, Arkadiy Vertleyb
<vertleyb_at_[hidden]> wrote:
> "Peder Holt" <peder.holt_at_[hidden]> wrote
>
> > Then again, the following compiles with VC7.1, so maybe there is hope
> > after all :)
>
> Wow...
>
> The reason it compiles is that you are using "class" where I used
> "typename". The following does not work:
>

Correct. I first tried with typename.

> template<typename A0>
> void deduce_container(*typename* std::_Tree<A0>::iterator)
> {
> std::cout << "map" << "\n";
> }
>
> I don't think this is a legal standard usage, though... Probably a
> Microsoft - specific "feature"... Any comments from language experts?
> Should the following work according to the Standard?
>

I tried a modified version with comeau online compiler, and it did not compile.
I like the syntax, though. There is a difference between nested
classes and typedefs, and this is a nice way to show the difference
explicitly in the source :)

I have written a simple test in order to discover if other compilers support it:

template<typename T>
struct outer {
   class nested{};
};

template<typename T>
void deduce(class outer<T>::nested)
{}

int main() {
   outer<int>::nested a;
   deduce(a);
   return 0;
}

Successfully compiles on VC6.5 and VC7.1
Fails to compile on Comeau C/C++ 4.3.3

I propose to define the macro
BOOST_HAS_TEMPLATE_NESTED_CLASS_DEDUCTION for the VC compilers (and
possibly other compilers supporting this)
and supplying
BOOST_TYPEOF_REGISTER_TEMPLATE_NESTED if the above is set.

Peder

> >
> > #pragma warning (disable:4786)
> > #include <map>
> > #include <list>
> > #include <iostream>
> >
> > template<typename A0,typename A1>
> > void deduce_container(class std::list<A0,A1>::iterator)
> > {
> > std::cout << "list" << "\n";
> > }
> >
> >
> > template<typename A0>
> > void deduce_container(class std::_Tree<A0>::iterator)
> > {
> > std::cout << "map" << "\n";
> > }
> >
> > int main() {
> > std::map<int,double>::iterator a;
> > std::list<int*>::iterator b;
> > deduce_container(a);
> > deduce_container(b);
> > return 0;
> > }
>
> Arkadiy
>
> _______________________________________________
> Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
>


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk