Board index » delphi » class template partial specialization ERROR ?

class template partial specialization ERROR ?

hi everyone,

Try the following code, i don't know why it fails to compile(it can pass the
gcc compiler)?

template <typename T>      // traits class
struct MemFuncTraits {};

template <typename R, typename O>   // partial specialization
struct MemFuncTraits<R (O::*)()> {  // for zero-parameter
 typedef R ReturnType;     // non-const member
 typedef O ObjectType;     // functions

Quote
};

However, the follow code will compile:

template <typename T>      // traits class
struct MemFuncTraits {};

template <typename R, typename O>   // partial specialization
struct MemFuncTraits<R& (O::*)()> {  // for zero-parameter
 typedef R ReturnType;     // non-const member
 typedef O ObjectType;     // functions

Quote
};

Thanks in any tips,

b...@sina.com

 

Re:class template partial specialization ERROR ?


What is the error it generates?
Maybe the problem is that you instantiate it with member function, that
returns R&, not R.
By the way which is the compiler you use? BC++5.5?

Boris

Quote
"bugn" <b...@sina.com> wrote in message news:3a81b4f0_2@dnews...
> hi everyone,

> Try the following code, i don't know why it fails to compile(it can pass
the
> gcc compiler)?

> template <typename T>      // traits class
> struct MemFuncTraits {};

> template <typename R, typename O>   // partial specialization
> struct MemFuncTraits<R (O::*)()> {  // for zero-parameter
>  typedef R ReturnType;     // non-const member
>  typedef O ObjectType;     // functions
> };

> However, the follow code will compile:

> template <typename T>      // traits class
> struct MemFuncTraits {};

> template <typename R, typename O>   // partial specialization
> struct MemFuncTraits<R& (O::*)()> {  // for zero-parameter
>  typedef R ReturnType;     // non-const member
>  typedef O ObjectType;     // functions
> };

> Thanks in any tips,

> b...@sina.com

Re:class template partial specialization ERROR ?


Quote
bugn wrote:

> hi everyone,

> Try the following code, i don't know why it fails to compile(it can pass
> the gcc compiler)?

What compiler are you using?

In fact it's not relevant to your question because even the latest C++
Builder versions still have problems wrt non-type template parameters. But
if you use C++ Builder (I guess you do because your code looks very
"modern"), please ask in the appropriate .cppbuilder newsgroup (in this
case, it would be .language).

Re:class template partial specialization ERROR ?


Quote
Thomas Maeder" <mae...@glue.ch> wrote in message

news:3A831DC1.D3A5C75D@glue.ch...

Quote
> bugn wrote:

> > hi everyone,

> > Try the following code, i don't know why it fails to compile(it can pass
> > the gcc compiler)?

> What compiler are you using?

BCC5.5.1(with sp2)

Quote

> In fact it's not relevant to your question because even the latest C++
> Builder versions still have problems wrt non-type template parameters. But
> if you use C++ Builder (I guess you do because your code looks very
> "modern"), please ask in the appropriate .cppbuilder newsgroup (in this
> case, it would be .language).

Borland claimed its BCC support the latest ISO/IEC 14882 standards.
Therefor I consider if this is only a minor bug for BCC since an alternate
compiler such as MSVC does not support partial specialization at all where
as GCC2.95 fully supports it.

Re:class template partial specialization ERROR ?


Quote
bugn wrote:

> BCC5.5.1(with sp2)

Then this is the wrong newsgroup. Please follow-up in .cppbuilder.language
(if at all).

Quote
> Borland claimed its BCC support the latest ISO/IEC 14882 standards.
> Therefor I consider if this is only a minor bug for BCC since an
> alternate compiler such as MSVC does not support partial specialization
> at all where as GCC2.95 fully supports it.

Where it is "minor" is in the eye of the beholder (I personally don't think
it is and have filed it), but in general, you're right.

Other Threads