Topic: Template typedefs: who's right?
Author: kuehl@horn.informatik.uni-konstanz.de (Dietmar Kuehl)
Date: 1998/01/11 Raw View
Hi,
Brock (peabody@npcinternational.com) wrote:
: Martin Connell wrote in message <691djn$dhl$1@plug.news.pipex.net>...
: >Dietmar,
: <<<snip
: >mind on this? In my opinion it would be wonderful if we could have template
: >typedefs having wanted to use them on many many occasions.
I know for sure that there is no such thing as a template typedef in
the FDIS (Final Draft International Standard). That is, he, or at least
the standardization committee haven't change their minds on this
subject.
: I think I also saw templatized namespaces mentioned in Stroustrup's 3ed.
: What's the word on them?
I'm not that sure on this topic but I doubt that there are templatized
in the standard.
--
<mailto:dietmar.kuehl@claas-solutions.de>
<http://www.informatik.uni-konstanz.de/~kuehl/>
I am a realistic optimist - that's why I appear to be slightly pessimistic
[ 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 ]
[ FAQ: http://reality.sgi.com/employees/austern_mti/std-c++/faq.html ]
[ Policy: http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
[ Comments? mailto:std-c++-request@ncar.ucar.edu ]
Author: Martin Connell <martinc@topology-com.UCAR.EDU>
Date: 1998/01/08 Raw View
Dietmar,
I was interested to see you bring up the syntax:
> template <class T> typedef basic_string<T, my_traits<T> > basic_mystring;
This is something I have tried to do myself only to find eventually a
specific note in Stroustrup's "The C++ Programming Language" 2nd edition
where he says he considered providing template typedefs but decided against
it. Do you know if this is still the case or has he or others changed their
mind on this? In my opinion it would be wonderful if we could have template
typedefs having wanted to use them on many many occasions.
Best wishes
Martin Connell
---
[ 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 ]
[ FAQ: http://reality.sgi.com/employees/austern_mti/std-c++/faq.html ]
[ Policy: http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
[ Comments? mailto:std-c++-request@ncar.ucar.edu ]
Author: "Brock" <peabody@npcinternational.com>
Date: 1998/01/10 Raw View
Martin Connell wrote in message <691djn$dhl$1@plug.news.pipex.net>...
>Dietmar,
<<<snip
>mind on this? In my opinion it would be wonderful if we could have template
>typedefs having wanted to use them on many many occasions.
I think I also saw templatized namespaces mentioned in Stroustrup's 3ed.
What's the word on them?
Brock
---
[ 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 ]
[ FAQ: http://reality.sgi.com/employees/austern_mti/std-c++/faq.html ]
[ Policy: http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
[ Comments? mailto:std-c++-request@ncar.ucar.edu ]
Author: Ross Smith <alien@netlink.co.nz>
Date: 1998/01/05 Raw View
Calling all language lawyers...
I've been trying to write a template-based implementation of integers
with specified sizes. I'll put the code at the end of this message.
Basically, Bits<N>::Integer should be a typedef for the smallest integer
type with at least N bits. The code here works fine with Symantec C++
7.5, but EGCS 1.0 (Win32 port) gives me this:
main.cpp:6: warning: ANSI C++ forbids typedef which does not specify
a type
main.cpp:6: cannot declare member 'Bits<(N + 1)>::Integer' within
'Bits<N>'
main.cpp:6: parse error before ';'
I was surprised to get this because EGCS is a much more up to date
compiler in most respects, and I'd expect it to handle anything the
ancient Symantec compiler could.
Which compiler is right? Is my code legal?
Here's the code:
#include <iostream.h>
#include <limits.h>
template <unsigned N> class Bits {
public:
typedef Bits<N + 1>::Integer Integer; // <-- EGCS errors here
};
class Bits<CHAR_BIT> {
public:
typedef signed char Exact;
};
#if USHRT_MAX > UCHAR_MAX
class Bits<CHAR_BIT * sizeof(short)> {
public:
typedef short Integer;
};
#endif
#if UINT_MAX > USHRT_MAX
class Bits<CHAR_BIT * sizeof(int)> {
public:
typedef int Integer;
};
#endif
#if ULONG_MAX > UINT_MAX
class Bits<CHAR_BIT * sizeof(long)> {
public:
typedef long Integer;
};
#endif
int main() {
cout << sizeof(Bits<20>::Integer) << endl;
return 0;
}
--
Ross Smith (Wellington, New Zealand) ...... <mailto:alien@netlink.co.nz>
"While I'd like to claim that it was a bitter and satirical
attack upon the mindless brutalities of war, it was really
just plain bloody violent..." -- Alan Moore
---
[ comp.std.c++ is moderated. To submit articles: Try just posting with your
newsreader. If that fails, use mailto:std-c++@ncar.ucar.edu
comp.std.c++ FAQ: http://reality.sgi.com/austern/std-c++/faq.html
Moderation policy: http://reality.sgi.com/austern/std-c++/policy.html
Comments? mailto:std-c++-request@ncar.ucar.edu
]
Author: kuehl@horn.informatik.uni-konstanz.de (Dietmar Kuehl)
Date: 1998/01/05 Raw View
Hi,
Ross Smith (alien@netlink.co.nz) wrote:
: main.cpp:6: warning: ANSI C++ forbids typedef which does not specify
: a type
Note, that the compiler is not complaining about a "template typedef".
This would look something like this:
template <class T> typedef basic_string<T, my_traits<T> > basic_mystring;
Instead, it complains about the attempt to make something a typedef
which is actually not a type! The problem here is that 'Bits<N +
1>::Integer' is a dependent name (it, obviously, depends on one of the
template arguments). Such dependent names are NOT considered to be a
type unless qualified to be a type using the 'typename' keyword. Thus,
egcs is correct in complaining about your code. It should look like
this:
template <unsigned N> class Bits {
public:
typedef typename Bits<N + 1>::Integer Integer;
// ^^^^^^^^ note this
};
: Which compiler is right? Is my code legal?
egcs. Your code is illegal.
--
<mailto:dietmar.kuehl@claas-solutions.de>
<http://www.informatik.uni-konstanz.de/~kuehl/>
I am a realistic optimist - that's why I appear to be slightly pessimistic
---
[ comp.std.c++ is moderated. To submit articles: Try just posting with your
newsreader. If that fails, use mailto:std-c++@ncar.ucar.edu
comp.std.c++ FAQ: http://reality.sgi.com/austern/std-c++/faq.html
Moderation policy: http://reality.sgi.com/austern/std-c++/policy.html
Comments? mailto:std-c++-request@ncar.ucar.edu
]