Topic: Lifting nested types out of class - scope


Author: aon.912719634@aon.at (Nicolas Pavlidis)
Date: Tue, 10 Apr 2007 20:01:48 GMT
Raw View
jam wrote:
> On Apr 9, 8:30 pm, aon.912719...@aon.at (Nicolas Pavlidis) wrote:
>> Greg Herlihy wrote:
>>> On Apr 9, 9:17 am, Nicolas Pavlidis <aon.912719...@aon.at> wrote:
>>>> Is there any proposal for doning the following:
>>>> class Outer
>>>> {
>>>> public:
>>>>   typdef SomeType<Foo> FooType;
>>>> };
>>>> using Outer::FooType;
>>> I doubt it - after all, making C++'s name-lookup rules even more
>>> complicated is probably not on anyone's wishlist for the next C++
>>> Standard (at least I fervently hope that to be the case).
>> Ok, that's clear.
>>
>>>> There are sometimes conditions such a construct whoulb be very useful,
>>>> as "templated typedefs", which found their way into C++0x.
>>> Wouldn't a typedef work just as well:
>>>     typedef Outer::FooType FooType;
>> That's clear, this is the approach I use, only from the code - readers
>> point of view, it would be a bit cleaner with using as to introduce a
>> new typedef, IMHO.
>>
>>> and this approach has the advantage of already being legal in C++..
>> Yes, clear :-).
>>
>>>> Maybe someone can tell me the reason, why such a statement is illegal be
>>>> now.
>>> Because Outer is the name of a class and not the name of a namespace.
>> Where exactly is the difference between a class and a namespace, from
>> the lookup sinds point of view?
>>
>> It is for example legal, to lift a protected method of a base - class
>> into public scope of a deriving class via using.
>>
> You just wrote methods(member functions).Since it is neither possible
> nor readable to use 'typedef' for them,we had needed another keyword
> for changing the scope without imposing the unnessesary over head of
> redifinition of a member function.

That wasn't my point :-) It's clear that /using/ was used for expressing
such things.

I always saw these feature as lifting something into another scope, here
from protected to public scope.


>> Maybe I mix the woring things together, but such a thing is as hasr to
>> lookup as if is lift out a nested name via using.
>>
> I am affraid you do a little bit.

I think too.

>> I'm not that well versed what it means to implement these lookup - rules
>> from the compilerside, maybe you can tell me whats the difference in
>> this case, between lifting out a "name" from a class and lifiting out a
>> "name" from a namespace.
>
> They exist in different layers of compile;I mean using/namespace are
> relatiely newer keywords and it would really result in
> incomprehensible  code to use 'typedef' for namespace aliases since
> they were not types.But theoretically class is avariation of namespace
> that obeys access rules.

Yes :-). But in meantime I see another problem with my approach, that
can be a big problem for lookup, right these access - rules that makes
classes classes. If /using/ could do this, what I wnat it to do, it had
to worry about acces-rules, for which it was not invented.

>> And yes typedef works well, but a using would be more readable I think.
>>
>
> I do not agree.'typedef' means that we are going to define a type
> aliase.Therefore I believe that typedef is more readable since it
> provides us with more info about the code.

That's the point in this case, we do not introduce a new type, we just
want to use a nested type without explicit scopeing the holding class,
in my point of view this:

class Test
{
public:
  typedef std::vector<std::string> StringVect;
};

introduces a "new" type, but

typedef Test::StringVect StringVect

does not introduce a new type, that's why I think using woud be better
here, but now I understand that there are some problems to let /using/
cope with such a situation.

Thanks && Best regards,
Nicolas

>
> ---
> [ 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://www.comeaucomputing.com/csc/faq.html                      ]
>

---
[ 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://www.comeaucomputing.com/csc/faq.html                      ]





Author: "jam" <farid.mehrabi@gmail.com>
Date: Wed, 11 Apr 2007 15:43:43 CST
Raw View
On Apr 10, 11:01 pm, aon.912719...@aon.at (Nicolas Pavlidis) wrote:
> jam wrote:
> > On Apr 9, 8:30 pm, aon.912719...@aon.at (Nicolas Pavlidis) wrote:
> >> Greg Herlihy wrote:
> >>> On Apr 9, 9:17 am, Nicolas Pavlidis <aon.912719...@aon.at> wrote:
> >>>> Is there any proposal for doning the following:
> >>>> class Outer
> >>>> {
> >>>> public:
> >>>>   typdef SomeType<Foo> FooType;
> >>>> };
> >>>> using Outer::FooType;
> >>> I doubt it - after all, making C++'s name-lookup rules even more
> >>> complicated is probably not on anyone's wishlist for the next C++
> >>> Standard (at least I fervently hope that to be the case).
> >> Ok, that's clear.
>
> >>>> There are sometimes conditions such a construct whoulb be very useful,
> >>>> as "templated typedefs", which found their way into C++0x.
> >>> Wouldn't a typedef work just as well:
> >>>     typedef Outer::FooType FooType;
> >> That's clear, this is the approach I use, only from the code - readers
> >> point of view, it would be a bit cleaner with using as to introduce a
> >> new typedef, IMHO.
>
> >>> and this approach has the advantage of already being legal in C++..
> >> Yes, clear :-).
>
> >>>> Maybe someone can tell me the reason, why such a statement is illegal be
> >>>> now.
> >>> Because Outer is the name of a class and not the name of a namespace.
> >> Where exactly is the difference between a class and a namespace, from
> >> the lookup sinds point of view?
>
> >> It is for example legal, to lift a protected method of a base - class
> >> into public scope of a deriving class via using.
>
> > You just wrote methods(member functions).Since it is neither possible
> > nor readable to use 'typedef' for them,we had needed another keyword
> > for changing the scope without imposing the unnessesary over head of
> > redifinition of a member function.
>
> That wasn't my point :-) It's clear that /using/ was used for expressing
> such things.
>
> I always saw these feature as lifting something into another scope, here
> from protected to public scope.
>
> >> Maybe I mix the woring things together, but such a thing is as hasr to
> >> lookup as if is lift out a nested name via using.
>
> > I am affraid you do a little bit.
>
> I think too.
>
> >> I'm not that well versed what it means to implement these lookup - rules
> >> from the compilerside, maybe you can tell me whats the difference in
> >> this case, between lifting out a "name" from a class and lifiting out a
> >> "name" from a namespace.
>
> > They exist in different layers of compile;I mean using/namespace are
> > relatiely newer keywords and it would really result in
> > incomprehensible  code to use 'typedef' for namespace aliases since
> > they were not types.But theoretically class is avariation of namespace
> > that obeys access rules.
>
> Yes :-). But in meantime I see another problem with my approach, that
> can be a big problem for lookup, right these access - rules that makes
> classes classes. If /using/ could do this, what I wnat it to do, it had
> to worry about acces-rules, for which it was not invented.
>
> >> And yes typedef works well, but a using would be more readable I think.
>
> > I do not agree.'typedef' means that we are going to define a type
> > aliase.Therefore I believe that typedef is more readable since it
> > provides us with more info about the code.
>
> That's the point in this case, we do not introduce a new type, we just
> want to use a nested type without explicit scopeing the holding class,
> in my point of view this:
>
> class Test
> {
> public:
>   typedef std::vector<std::string> StringVect;
>
> };
>
> introduces a "new" type, but
>

No.It just gives a new short name to a predefined type.
> typedef Test::StringVect StringVect
>
> does not introduce a new type, that's why I think using woud be better
> here, but now I understand that there are some problems to let /using/
> cope with such a situation.
>
This is also giving a new short name to a predefined type.'typedef' is
older a keyword -inhherited from C -than 'namespace/using'  which
where declared later compared to templates who were declared long
after OOP and C++.It could handle your purpose without much difficulty
and there was no major need to change this behavior .It looks to be a
matter of taste.

---
[ 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://www.comeaucomputing.com/csc/faq.html                      ]





Author: Nicolas Pavlidis <aon.912719634@aon.at>
Date: Mon, 9 Apr 2007 10:17:24 CST
Raw View
Hi!

Is there any proposal for doning the following:

class Outer
{
public:
  typdef SomeType<Foo> FooType;
};

using Outer::FooType;

There are sometimes conditions such a construct whoulb be very useful,
as "templated typedefs", which found their way into C++0x.

Maybe someone can tell me the reason, why such a statement is illegal be
now.

Thanks && Kind regrads,
Nicolas

---
[ 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://www.comeaucomputing.com/csc/faq.html                      ]





Author: "Greg Herlihy" <greghe@pacbell.net>
Date: Mon, 9 Apr 2007 11:38:46 CST
Raw View
On Apr 9, 9:17 am, Nicolas Pavlidis <aon.912719...@aon.at> wrote:
> Is there any proposal for doning the following:
>
> class Outer
> {
> public:
>   typdef SomeType<Foo> FooType;
>
> };
>
> using Outer::FooType;

I doubt it - after all, making C++'s name-lookup rules even more
complicated is probably not on anyone's wishlist for the next C++
Standard (at least I fervently hope that to be the case).

> There are sometimes conditions such a construct whoulb be very useful,
> as "templated typedefs", which found their way into C++0x.

Wouldn't a typedef work just as well:

    typedef Outer::FooType FooType;

and this approach has the advantage of already being legal in C++..

> Maybe someone can tell me the reason, why such a statement is illegal be
> now.

Because Outer is the name of a class and not the name of a namespace.

Greg


---
[ 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://www.comeaucomputing.com/csc/faq.html                      ]





Author: aon.912719634@aon.at (Nicolas Pavlidis)
Date: Mon, 9 Apr 2007 17:30:20 GMT
Raw View
Greg Herlihy wrote:
> On Apr 9, 9:17 am, Nicolas Pavlidis <aon.912719...@aon.at> wrote:
>> Is there any proposal for doning the following:
>>
>> class Outer
>> {
>> public:
>>   typdef SomeType<Foo> FooType;
>>
>> };
>>
>> using Outer::FooType;
>
> I doubt it - after all, making C++'s name-lookup rules even more
> complicated is probably not on anyone's wishlist for the next C++
> Standard (at least I fervently hope that to be the case).

Ok, that's clear.

>> There are sometimes conditions such a construct whoulb be very useful,
>> as "templated typedefs", which found their way into C++0x.
>
> Wouldn't a typedef work just as well:
>
>     typedef Outer::FooType FooType;

That's clear, this is the approach I use, only from the code - readers
point of view, it would be a bit cleaner with using as to introduce a
new typedef, IMHO.

> and this approach has the advantage of already being legal in C++..

Yes, clear :-).

>> Maybe someone can tell me the reason, why such a statement is illegal be
>> now.
>
> Because Outer is the name of a class and not the name of a namespace.

Where exactly is the difference between a class and a namespace, from
the lookup sinds point of view?

It is for example legal, to lift a protected method of a base - class
into public scope of a deriving class via using.

Maybe I mix the woring things together, but such a thing is as hasr to
lookup as if is lift out a nested name via using.

I'm not that well versed what it means to implement these lookup - rules
from the compilerside, maybe you can tell me whats the difference in
this case, between lifting out a "name" from a class and lifiting out a
"name" from a namespace.

And yes typedef works well, but a using would be more readable I think.

Best regards,
Nicolas

---
[ 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://www.comeaucomputing.com/csc/faq.html                      ]





Author: "jam" <farid.mehrabi@gmail.com>
Date: Tue, 10 Apr 2007 12:40:59 CST
Raw View
On Apr 9, 8:30 pm, aon.912719...@aon.at (Nicolas Pavlidis) wrote:
> Greg Herlihy wrote:
> > On Apr 9, 9:17 am, Nicolas Pavlidis <aon.912719...@aon.at> wrote:
> >> Is there any proposal for doning the following:
>
> >> class Outer
> >> {
> >> public:
> >>   typdef SomeType<Foo> FooType;
>
> >> };
>
> >> using Outer::FooType;
>
> > I doubt it - after all, making C++'s name-lookup rules even more
> > complicated is probably not on anyone's wishlist for the next C++
> > Standard (at least I fervently hope that to be the case).
>
> Ok, that's clear.
>
> >> There are sometimes conditions such a construct whoulb be very useful,
> >> as "templated typedefs", which found their way into C++0x.
>
> > Wouldn't a typedef work just as well:
>
> >     typedef Outer::FooType FooType;
>
> That's clear, this is the approach I use, only from the code - readers
> point of view, it would be a bit cleaner with using as to introduce a
> new typedef, IMHO.
>
> > and this approach has the advantage of already being legal in C++..
>
> Yes, clear :-).
>
> >> Maybe someone can tell me the reason, why such a statement is illegal be
> >> now.
>
> > Because Outer is the name of a class and not the name of a namespace.
>
> Where exactly is the difference between a class and a namespace, from
> the lookup sinds point of view?
>
> It is for example legal, to lift a protected method of a base - class
> into public scope of a deriving class via using.
>
You just wrote methods(member functions).Since it is neither possible
nor readable to use 'typedef' for them,we had needed another keyword
for changing the scope without imposing the unnessesary over head of
redifinition of a member function.

> Maybe I mix the woring things together, but such a thing is as hasr to
> lookup as if is lift out a nested name via using.
>
I am affraid you do a little bit.

> I'm not that well versed what it means to implement these lookup - rules
> from the compilerside, maybe you can tell me whats the difference in
> this case, between lifting out a "name" from a class and lifiting out a
> "name" from a namespace.

They exist in different layers of compile;I mean using/namespace are
relatiely newer keywords and it would really result in
incomprehensible  code to use 'typedef' for namespace aliases since
they were not types.But theoretically class is avariation of namespace
that obeys access rules.

>
> And yes typedef works well, but a using would be more readable I think.
>

I do not agree.'typedef' means that we are going to define a type
aliase.Therefore I believe that typedef is more readable since it
provides us with more info about the code.


---
[ 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://www.comeaucomputing.com/csc/faq.html                      ]