Re: Enum within function, is this standard?
From: Ivan Vecerina (please_use_web_form_at_ivan.vecerina.com)
Date: 11/14/03
- Next message: Allen: "will the pointer survive?"
- Previous message: Ivan Vecerina: "Re: Newbie char* question"
- In reply to: Rob Williscroft: "Re: Enum within function, is this standard?"
- Next in thread: Rob Williscroft: "Re: Enum within function, is this standard?"
- Reply: Rob Williscroft: "Re: Enum within function, is this standard?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Fri, 14 Nov 2003 06:00:03 +0100
"Rob Williscroft" <rtw@freenet.REMOVE.co.uk> wrote in message
news:Xns9432CE4F14022ukcoREMOVEfreenetrtw@195.129.110.204...
> Domenico Andreoli wrote in news:86Qsb.112809$vO5.4389182
> @twister1.libero.it:
> > so the following breaks? why?
> >
> > template <typename T>
> > struct A
> > {
> > T t;
> > };
> >
> > void f()
> > {
> > enum B { zero, one };
> > A<B> t;
> > }
> >
> >
>
> The name B doesn't have external linkage. If you consider adding:
Exact.
> IOW templates base there external-linkage on the external-linkage
> of there arguments.
Which from a typical implementation's perspective means that
the name of the parameter type is mangled into (used as part of)
the name of template instanciation.
> This is how the standard was/is writen. It could have been otherwise,
> but would the benefits outway the cost (for implementers this is
> man-hour's of programming, for us it's more waiting for fully
> conforming compiler's).
Maybe, but this is debatable. Since the compiler has support for
anonymous namespaces, it knows how to generate unique names
already.
Many find this limitation is especially annoying when writing
functors and predicates:
void sortByAge(std::vector<Item>& items)
{
struct AgeCompare {
bool operator()(Item const& a, Item const&b)
{ return a.age<b.age; }
};
std::sort(items.begin(),items.end(),AgeCompare()); //error
}
Because AgeCompare has no external linkage, it has to be
moved out of the function. Ugly.
I'm pretty sure that dropping this limitation has been proposed
for the next C++ standard...
Regards,
Ivan
-- http://ivan.vecerina.com
- Next message: Allen: "will the pointer survive?"
- Previous message: Ivan Vecerina: "Re: Newbie char* question"
- In reply to: Rob Williscroft: "Re: Enum within function, is this standard?"
- Next in thread: Rob Williscroft: "Re: Enum within function, is this standard?"
- Reply: Rob Williscroft: "Re: Enum within function, is this standard?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|