Topic: A reference about References to references :o)
Author: dwalker07@snet.net.invalid (Daryle Walker)
Date: Sun, 10 Sep 2000 16:13:26 GMT Raw View
Jean-Daniel Nicolet <jdn@llinkvest.ch> wrote:
> template <typename T>
> struct DoubleRefSuppressor
> {
> typedef T Type;
> };
>
> template<typename T>
> struct DoubleRefSuppressor<T&>
> {
> typedef T Type; // Use partial specialization to suppress the
> unneeded ref
> };
Wouldn't something like
//===
template <typename T>
struct DoubleRefSuppressor<T&>
{
typedef typename DoubleRefSuppressor<T>::Type Type
};
//===
be a bit more safer? I was thinking this would help in protection for
triple references. I just realized that this would get rid of single
references too. Maybe we could use
//===
template <typename T>
struct remove_reference
{
typedef T base_type;
};
template <typename T>
struct remove_reference<T&>
{
typedef typename remove_reference<T>::base_type base_type;
};
template <typename T>
struct add_reference
{
typedef typename remove_reference<T>::base_type &reference_type;
// maybe add another entry for constant references
};
//===
--
Daryle Walker
Mac, Internet, and Video Game Junkie
dwalker07 AT snet DOT net
---
[ 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: Gabriel Dos Reis <dosreis@cmla.ens-cachan.fr>
Date: 2000/08/25 Raw View
David R Tribble <david@tribble.com> writes:
[...]
| ... If a reference type 'T&&' should be simplified
Doesn't this get parsed as 'T &&' ? ;-)
--
Gabriel Dos Reis, dosreis@cmla.ens-cachan.fr
---
[ 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: wmm@fastdial.net
Date: 2000/08/25 Raw View
In article <flk8d7h8bp.fsf@riz.cmla.ens-cachan.fr>,
Gabriel Dos Reis <dosreis@cmla.ens-cachan.fr> wrote:
> David R Tribble <david@tribble.com> writes:
>
> [...]
>
> | ... If a reference type 'T&&' should be simplified
>
> Doesn't this get parsed as 'T &&' ? ;-)
I see the smiley, but just in case anyone else might not know,
the proposal before the Committee is to apply this transformation
only to types created via typedef or template parameter --
writing "T & &" would be an error, just as it is today. (This
is analogous to the treatment of cv-qualifiers: you can apply
a "const" specifier to an already-const type via a typedef
or template parameter, but "const const int" is an error.)
--
William M. Miller, wmm@fastdial.net
Vignette Corporation (www.vignette.com)
Sent via Deja.com http://www.deja.com/
Before you buy.
---
[ 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: Francis Glassborow <francis@robinton.demon.co.uk>
Date: 2000/08/26 Raw View
In article <flk8d7h8bp.fsf@riz.cmla.ens-cachan.fr>, Gabriel Dos Reis
<dosreis@cmla.ens-cachan.fr> writes
>| ... If a reference type 'T&&' should be simplified
>
>Doesn't this get parsed as 'T &&' ? ;-)
It would if we were using macros, but templates work differently.
>
Francis Glassborow Association of C & C++ Users
64 Southfield Rd
Oxford OX4 1PA +44(0)1865 246490
All opinions are mine and do not represent those of any organisation
---
[ 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: "Jean-Daniel Nicolet" <jdn@llinkvest.ch>
Date: 2000/08/28 Raw View
I personally don't find it a good idea to introduce such conversion rules
directly in the language. It's a kind of implicit conversion that can only
add complexity to the language, and possibly also new ambiguities. We
already have the automatic conversion of a pointer to function to the
function itself and this implies additional rules for the compiler.
Moreover, it is really simple with modern compilers to simulate the T&& to
T& conversion with a helper template using partial specialization to
distinguish between a reference and a simple type:
template <typename T>
struct DoubleRefSuppressor
{
typedef T Type;
};
template<typename T>
struct DoubleRefSuppressor<T&>
{
typedef T Type; // Use partial specialization to suppress the
unneeded ref
};
template<typename T>
struct Ref
{
typedef typename DoubleRefSuppressor<T>::Type& Type; // Note the ref
here!
};
// here the binder2nd as an example of use
template<typename Pred, typename T>
binder2nd<Pred> bind2nd(const Pred& pr, const Ref<T>::Type y);
The Ref<T> template builds a T& avoiding the T&& pitfall.
If I remember the argumentation to avoid introducing the inherited keyword
into the language (a simple construct can emulate it), I believe we have
exactly the same situation here: no need for a new language construct. Just
make good use of the existing!
By the way, there are aleady STL-like libraries around using exactly that
trick.
Jean-Daniel Nicolet
Software Consultant
Geneva
Switzerland
---
[ 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: Gabriel Dos Reis <gdr@merlin.codesourcery.com>
Date: 2000/08/28 Raw View
Francis Glassborow <francis@robinton.demon.co.uk> writes:
| In article <flk8d7h8bp.fsf@riz.cmla.ens-cachan.fr>, Gabriel Dos Reis
| <dosreis@cmla.ens-cachan.fr> writes
| >| ... If a reference type 'T&&' should be simplified
| >
| >Doesn't this get parsed as 'T &&' ? ;-)
|
| It would if we were using macros, but templates work differently.
Indeed.
As noted by William Miller, I wasn't taking my question seriously.
I was merely trying (apparently with no much success :-) to point out
that no just because `U&' would be simplied to a reference type,
for a reference type `U', that would `T&&' would be a reference type.
--
Gabriel Dos Reis, gdr@codesourcery.com
CodeSourcery, LLC http://www.codesourcery.com
http://www.codesourcery.com/gcc-compile.shtml
---
[ 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: "Balog Pal (mh)" <pasa@lib.hu>
Date: 2000/08/28 Raw View
>I see the smiley, but just in case anyone else might not know,
>the proposal before the Committee is to apply this transformation
>only to types created via typedef or template parameter --
>writing "T & &" would be an error, just as it is today. (This
>is analogous to the treatment of cv-qualifiers: you can apply
>a "const" specifier to an already-const type via a typedef
>or template parameter, but "const const int" is an error.)
And what is the rationale (to both)? To undermine any attempts to use a
#define macro?
Paul
---
[ 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: comeau@panix.com (Greg Comeau)
Date: 2000/08/29 Raw View
In article <39aa8fc6@andromeda.datanet.hu>, Balog Pal (mh) <pasa@lib.hu> wrote:
>>I see the smiley, but just in case anyone else might not know,
>>the proposal before the Committee is to apply this transformation
>>only to types created via typedef or template parameter --
>>writing "T & &" would be an error, just as it is today. (This
>>is analogous to the treatment of cv-qualifiers: you can apply
>>a "const" specifier to an already-const type via a typedef
>>or template parameter, but "const const int" is an error.)
>
>
>And what is the rationale (to both)? To undermine any attempts to use a
>#define macro?
I don't recall #define being given much consideration here.
Just that if you _explicitly_ say it twice in a decl, you probably
did not want to. However, with typedef, or template parameters,
they may have distinct "requirements" (from an interface
perspective) and so it would be a shame to reject something
say that needs to be const because it it's already const.
IOWs, the way to look at this is type building, and that if
it doesn't have it (const or ref) make it so, not that it's
makeing it so again in the case where it already has it
(so there really is no const const's or &&'s).
- Greg
--
Comeau Computing / Comeau C/C++ ("so close" 4.2.44 betas starting)
TRY Comeau C++ ONLINE at http://www.comeaucomputing.com/tryitout
Email: comeau@comeaucomputing.com / WEB: http://www.comeaucomputing.com
---
[ 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: "Andrei Alexandrescu" <andrewalex@hotmail.com>
Date: 2000/08/21 Raw View
On Bjarne Stroustrup's book errata
http://www.research.att.com/~bs/3rd_issues.html, one can read:
*pg 522: It is not possible to have a reference to a reference so the
calls to bind2nd() appears to be nonconforming. The committee has
resolved this issue by deeming T&& equivalent to T&.
I didn't find this change on
http://anubis.dkuug.dk/jtc1/sc22/wg21/docs/lwg-active.html, nor in the
closed issue list. Can someone give me more details? Thanks.
Andrei
---
[ 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: wmm@fastdial.net
Date: 2000/08/22 Raw View
In article <sq1ekdl587v79@news.supernews.com>,
"Andrei Alexandrescu" <andrewalex@hotmail.com> wrote:
> On Bjarne Stroustrup's book errata
> http://www.research.att.com/~bs/3rd_issues.html, one can read:
>
> *pg 522: It is not possible to have a reference to a reference so the
> calls to bind2nd() appears to be nonconforming. The committee has
> resolved this issue by deeming T&& equivalent to T&.
>
> I didn't find this change on
> http://anubis.dkuug.dk/jtc1/sc22/wg21/docs/lwg-active.html, nor in the
> closed issue list. Can someone give me more details? Thanks.
It's core issue 106. Bjarne was a little early in saying that
the Committee "has resolved this issue." There has been
general informal agreement with this one-line summary of the
desired resolution, but the exact form of the change is still
under discussion. At the last meeting the core language working
group accepted the proposed wording shown in the issues list,
but the entire committee has not yet voted on it. (And it's a
good thing, too -- Lisa Lippincott has pointed out that the
proposed wording does not handle cv-qualification correctly,
so there's still some work to do before we can change the
Standard to reflect the desired outcome.)
--
William M. Miller, wmm@fastdial.net
Vignette Corporation (www.vignette.com)
Sent via Deja.com http://www.deja.com/
Before you buy.
---
[ 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: "Andrei Alexandrescu" <andrewalex@hotmail.com>
Date: 2000/08/22 Raw View
<wmm@fastdial.net> wrote in message
news:8nsj3m$r6a$1@nnrp1.deja.com...
I wrote when I was younger, so much younger that todaaay-yeah-yeah:
> > I didn't find this change on
> > http://anubis.dkuug.dk/jtc1/sc22/wg21/docs/lwg-active.html, nor in
the
> > closed issue list. Can someone give me more details? Thanks.
>
> It's core issue 106.
Thanks. Can you please, please provide me with a link? From what I
saw, issue 106 is "Numeric library private members are implementation
defined." I have to admit I'm not sure whether I'm looking in the
right place.
Andrei
---
[ 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: Marc Girod <girod@stybba.ntc.nokia.com>
Date: 2000/08/23 Raw View
>>>>> "AA" == Andrei Alexandrescu <andrewalex@hotmail.com> writes:
>> > http://anubis.dkuug.dk/jtc1/sc22/wg21/docs/lwg-active.html
Er... This is the "C++ Standard Library Active Issues List"
>> It's core issue 106.
AA> Thanks. Can you please, please provide me with a link? From what I
AA> saw, issue 106 is "Numeric library private members are implementation
AA> defined." I have to admit I'm not sure whether I'm looking in the
AA> right place.
You have look at the "C++ Standard Core Language Issues List":
http://anubis.dkuug.dk/jtc1/sc22/wg21/docs/cwg_active.html
There it is.
--
Marc Girod P.O. Box 320 Voice: +358-9-511 23746
Nokia Networks 00045 NOKIA Group Mobile: +358-40-569 7954
Hiomo 5/1 Finland Fax: +358-9-511 23580
---
[ 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: David R Tribble <david@tribble.com>
Date: 2000/08/23 Raw View
wmm@fastdial.net wrote:
> It's core issue 106. Bjarne was a little early in saying that
> the Committee "has resolved this issue." There has been
> general informal agreement with this one-line summary of the
> desired resolution, but the exact form of the change is still
> under discussion. At the last meeting the core language working
> group accepted the proposed wording shown in the issues list,
> but the entire committee has not yet voted on it. (And it's a
> good thing, too -- Lisa Lippincott has pointed out that the
> proposed wording does not handle cv-qualification correctly,
> so there's still some work to do before we can change the
> Standard to reflect the desired outcome.)
That's a good point. If a reference type 'T&&' should be simplified
to type 'T&', what type would a non-const reference to a const
reference type be, e.g., '(const T&)&' ? Would it retain the
constness, e.g., become 'const T&' ?
--
David R. Tribble, mailto:david@tribble.com, http://david.tribble.com
---
[ 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 ]