Topic: Using declarations and template-ids


Author: "Greg Herlihy" <greghe@pacbell.net>
Date: Fri, 12 Jan 2007 11:32:19 CST
Raw View
The Standard states:

    "A using-declaration shall not name a template-id."
    [namespace.udecl/5]

and provides two examples of ill-formed using declarations:

    using A::f<double>; // ill-formed
    using A::X<int>; // ill-formed

In these examples, the template-id is the entity being named. But does
a template-id that appears as a specifier for another type of name -
"name" the template-id as well? For example:

    template <class T>
    class base
    {
    public:
        struct param_type {  };
    };

    template <class T>
    class test : public base<T>
    {
    public:
       using typename base<T>::param_type;  // legal?
    };

Is the using declaration for param_type legal because it "names"
param_type, or is it illegal because it "names" base<T> as well? C++
compilers seem to be divided on this question.

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: a.l_e.x_AT.s_u.n_c.h_o.D@T_c.o_m (Alex Howlett)
Date: Fri, 12 Jan 2007 20:22:09 GMT
Raw View
Greg Herlihy formulated on Friday :
> The Standard states:
>
>     "A using-declaration shall not name a template-id."
>     [namespace.udecl/5]
>
> and provides two examples of ill-formed using declarations:
>
>     using A::f<double>; // ill-formed
>     using A::X<int>; // ill-formed
>
> In these examples, the template-id is the entity being named. But does
> a template-id that appears as a specifier for another type of name -
> "name" the template-id as well? For example:
>
>     template <class T>
>     class base
>     {
>     public:
>         struct param_type {  };
>     };
>
>     template <class T>
>     class test : public base<T>
>     {
>     public:
>        using typename base<T>::param_type;  // legal?
>     };
>
> Is the using declaration for param_type legal because it "names"
> param_type, or is it illegal because it "names" base<T> as well? C++
> compilers seem to be divided on this question.
>
> Greg
>

It sounds like it should be legal because the using-declaration isn't
naming a template-id.  It's naming a type.  The fact that the
nested-name-specifier happens to be a template-id shouldn't really
matter.  At least that's my take.

If your example (using type names) doesn't work and you need it to
work, you could always do this instead:

template<class T>
class test: public base<T>
{
public:
    typedef typename base<T>::param_type param_type;
};

I think that would give essentially the same result.

---
[ 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: cbarron413@adelphia.net (Carl Barron)
Date: Tue, 16 Jan 2007 17:14:35 GMT
Raw View
In article <1168591256.198701.194810@s34g2000cwa.googlegroups.com>,
Greg Herlihy <greghe@pacbell.net> wrote:

> The Standard states:
>
>     "A using-declaration shall not name a template-id."
>     [namespace.udecl/5]
>
> and provides two examples of ill-formed using declarations:
>
>     using A::f<double>; // ill-formed
>     using A::X<int>; // ill-formed
>
This is legal:
namespace A
{
   template <class T>
   void f(const T &);
}

using A::f;

void test()
{
   f((int)0);
   f((double)0);
}

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