Topic: typedef::typedef


Author: "Vlad Harchev" <vladhar@imimail.ssau.ru>
Date: 1998/11/25
Raw View
Siemel Naran wrote ...
>
>Is the following program correct?
>
>----------------------------------
>
>#include <iostream> // LINE1
>
>template <int N> struct vec
>{
>     void f() const
>     {
>          std::cout << N << ' ' << this << '\n';
>     }
>};
>
>template <int N> struct X { typedef vec<N> result_type; result_type
result; };
>template <int N> struct Y { typedef X<N> thing_type; thing_type thing; };
>
>template <int N>
>void f(const typename Y<N>::thing_type::result_type& x) // LINE15
>//void f(const vec<N>& x) // LINE16
>{
>     x.f();
>}
>
>int main()
>{
>     Y<3> y;
>     f(y.thing.result); // LINE24
>}
>
>----------------------------------
>
>Egcs gives the following error message
>
>e.cc: In function `int main()':
>e.cc:24: no matching function for call to `f (vec<3> &)'
>
>
>However, if I comment out LINE15 and uncomment LINE16, then the
>program compiles.  But isn't
>   vec<N>
>the same as
>   Y<N>::thing_type::result_type

   In general, there can exist explicit or partial (here the same as
explicit) specialization of Y<N> in which typedef thing_type can denote
something other than X<N>, so there can exist 2 approaches:
 compiler sees that there is no explicit specializations of Y<N>, so it
deduces that in all specializations of Y<N> thing_type will be X<N> (it
should interpret the template body in some wise way) or reject the request
like egcs did. Imagine that the CC pretend to be wise and selected the 1st
way: but what if there exist several explicit specializations of Y<N> in
each of which thing_type::result_type is vec<N> - ie compiler should chose
from several N's of these specializations? I think that 1st way is
unacceptable to be proposed behaviour because of difficulties of
implementation and logical inconsistenses. From tha point of view  egcs
behaves correctly.

 - Vlad
---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]





Author: sbnaran@fermi.ceg.uiuc.edu (Siemel Naran)
Date: 1998/11/18
Raw View

Is the following program correct?

----------------------------------

#include <iostream> // LINE1

template <int N> struct vec
{
     void f() const
     {
          std::cout << N << ' ' << this << '\n';
     }
};

template <int N> struct X { typedef vec<N> result_type; result_type result; };
template <int N> struct Y { typedef X<N> thing_type; thing_type thing; };

template <int N>
void f(const typename Y<N>::thing_type::result_type& x) // LINE15
//void f(const vec<N>& x) // LINE16
{
     x.f();
}

int main()
{
     Y<3> y;
     f(y.thing.result); // LINE24
}

----------------------------------

Egcs gives the following error message

e.cc: In function `int main()':
e.cc:24: no matching function for call to `f (vec<3> &)'


However, if I comment out LINE15 and uncomment LINE16, then the
program compiles.  But isn't
   vec<N>
the same as
   Y<N>::thing_type::result_type



--
----------------------------------
Siemel B. Naran (sbnaran@uiuc.edu)
----------------------------------


[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]