Topic: Using declarations and member templates


Author: Valentin Bonnard <Bonnard.V@wanadoo.fr>
Date: 1999/09/09
Raw View
Martin von Loewis wrote:

> smeyers@aristeia.com (Scott Meyers) writes:

> >   A using-declaration shall not name a template-id.

> > So here's my question: is my code legal?  More formally, does the usi=
ng
> > declaration in SP<T> above name a template-id?
>=20
> Yes, your code is legal. 14.2, [temp.names]/1, says
>=20
>    template=ADid:
>                template=ADname < template=ADargument=ADlist-opt >

Applying this resonning to the example of this rule, I get=20
that they aren't template-id either, so they are valid.

But the comment in the examples says: ill-formed.

Either your resonning or the example is wrong.

--=20

Valentin Bonnard
---
[ 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: 1999/09/09
Raw View
In article <MPG.123f3aa3ee0ac1c49896ca@news.teleport.com>,
  smeyers@aristeia.com (Scott Meyers) wrote:
>
> In the October DDJ, I have an article discussing how to implement
> operator->* for smart pointers.  At one point I propose declaring a
bunch
> of operator->* templates in a base class template,
>
>   template <typename T>     // base class for smart pointers wishing
>   class SmartPtrBase {      // to support operator->*
>   public:
>
>     // various member templates for operator->*, e.g.:
>     template <typename U>
>     ComplicatedReturnType operator->*(UglyParamType);
>
>     ...                    // other stuff we don't care about here
>   };
>
> I then suggest having smart pointer class templates privately inherit
from
> this base:
>
>   template <typename T>
>   class SP: private SmartPtrBase<T> {
>   public:
>      using SmartPtrBase<T>::operator->*;  // make the privately
inherited
>                                           // operator->* templates
public
>
>     ...
>   };
>
> My concern is 7.3.3/5 of the standard, which states:
>
>   A using-declaration shall not name a template-id.
>
> It goes on to give a couple of examples, each of which involves
reference
> to a specialization of a member template.  My example above doesn't
involve
> specialization, so I'm wondering if it might sneak through as
legitimate,
> standard C++.
>
> So here's my question: is my code legal?  More formally, does the
using
> declaration in SP<T> above name a template-id?  It seems like it does,
but
> since the examples in the standard don't show this particular form,
I'm
> hoping to get lucky.  If not, I'm once again in the position of
finding a
> bug in something I wrote after it's been finalized but before it has
> appeared, sigh.

No need to worry, it's fine.  The reason for the rule in 7.3.3p5 is
to prevent importing only some specializations of a template, which
would be essentially the same as importing only some signatures of an
overloaded member function -- it isn't allowed, you have to get the
entire overload set.

In this case, you are naming the template itself, not a specialization,
so there is no problem.  (The qualification isn't "named" in the using-
declaration; that phraseology applies to the declared entity, cf
7.3.3p1, "A using-declaration introduces a name...").
--
William M. Miller, wmm@fastdial.net
Software Emancipation Technology (www.setech.com)


Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.
---
[ 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: smeyers@aristeia.com (Scott Meyers)
Date: 1999/09/08
Raw View
In the October DDJ, I have an article discussing how to implement
operator->* for smart pointers.  At one point I propose declaring a bunch
of operator->* templates in a base class template,

  template <typename T>     // base class for smart pointers wishing
  class SmartPtrBase {      // to support operator->*
  public:

    // various member templates for operator->*, e.g.:
    template <typename U>
    ComplicatedReturnType operator->*(UglyParamType);

    ...                    // other stuff we don't care about here
  };

I then suggest having smart pointer class templates privately inherit from
this base:

  template <typename T>
  class SP: private SmartPtrBase<T> {
  public:
     using SmartPtrBase<T>::operator->*;  // make the privately inherited
                                          // operator->* templates public

    ...
  };

My concern is 7.3.3/5 of the standard, which states:

  A using-declaration shall not name a template-id.

It goes on to give a couple of examples, each of which involves reference
to a specialization of a member template.  My example above doesn't involve
specialization, so I'm wondering if it might sneak through as legitimate,
standard C++.

So here's my question: is my code legal?  More formally, does the using
declaration in SP<T> above name a template-id?  It seems like it does, but
since the examples in the standard don't show this particular form, I'm
hoping to get lucky.  If not, I'm once again in the position of finding a
bug in something I wrote after it's been finalized but before it has
appeared, sigh.

Thanks,

Scott

--
Scott Meyers, Ph.D.                  smeyers@aristeia.com
Software Development Consultant      http://www.aristeia.com/
Visit http://meyerscd.awl.com/ to demo the Effective C++ CD


[ 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              ]