Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Re: some experiments with type names

22 views
Skip to first unread message
Message has been deleted

Paavo Helde

unread,
May 2, 2015, 2:47:36 PM5/2/15
to
r...@zedat.fu-berlin.de (Stefan Ram) wrote in news:type-name-20150502181607
@ram.dialup.fu-berlin.de:
> Do you know a type from the standard library that actually
> /is/ a class? (not a template or a typedef)
> (I really am looking for such a class to use it in my tutorial.)

I feel sorry for your students who need to waste their time to learning
useless garbage like unnecessary leading :: and unnecessary 'class' and
'typename' usage.

> Exercise: (I have not done this myself and don't know if
> it's possible).

Feeling even more sorry ...

Öö Tiib

unread,
May 2, 2015, 3:49:15 PM5/2/15
to
On Saturday, 2 May 2015 19:28:26 UTC+3, Stefan Ram wrote:
> You can declare a variable thus
>
> int i;
>
> , although »int« is a type name, the compiler did not accept
>
> typename int i;
>
> , but it did accept
>
> typename ::std::string s;
>
> , however, it did not accept
>
> class ::std::string s;
>
> because ::std::string is typedef, it is not a class, but it
> would accept
>
> class a_class a;
>
> if »a_class« is a proper class.

It is well-formed also when 'a_class' is 'struct', but several
compilers will warn about it.

> Do you know a type from the standard library that actually
> /is/ a class? (not a template or a typedef)

Lets be curious and check what typedef the 'std::string' is? It is
required to be (in 'std' namespace):

typedef basic_string<char> string;

So lets see further what is the mysterious 'basic_string'? It is
required to be such a thing:

template < class charT
, class traits = char_traits<charT>
, class Alloc = allocator<charT>
>
class basic_string;

Wow, a 'class' template. So we may type:

class std::basic_string<char> s1;

Since further research about 'std::char_traits' and 'std::allocator'
shows that these are class templates as well we may type:

class ::std::basic_string<char, class ::std::char_traits<char>,
class ::std::allocator<char> > s2;

and that declaration must be equal with:

std::string s2;

However ... don't you have something more basic to teach your
students about software development? The allocators and character
traits are rather advanced topic. One may work for years in C++
shop and not care about those.

0 new messages