type traits for vector types

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

type traits for vector types

Jochen Wilhelmy
Hi!

I'd like to find out info about vectors at compile time.

For example I have these vector traits:
template <typename T>
struct VectorTraits {
    enum {
        VECTOR = 0
    };
};

template <>
struct VectorTraits<float __attribute__((ext_vector_type(2)))> {
    enum {
        VECTOR = 2
    };
};

template <>
struct VectorTraits<float> {
    enum {
        VECTOR = 1
    };
};


This fails with the following error:
error: redefinition of
      'VectorTraits<float>'
 struct VectorTraits<float>
        ^~~~~~~~~~~~~~~~~~~

It seems clang can not specialize by vector type. But when I omit the
vector specialization
the result for a vector type (i.e. VectorTraits<float2>::VECTOR) is 0.
The vector type does not count as its basic type at instantiation time.
Therefore this is a bug.

-Jochen

_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: type traits for vector types

Douglas Gregor

On May 11, 2010, at 4:42 PM, Jochen Wilhelmy wrote:

> Hi!
>
> I'd like to find out info about vectors at compile time.
>
> For example I have these vector traits:
> template <typename T>
> struct VectorTraits {
>    enum {
>        VECTOR = 0
>    };
> };
>
> template <>
> struct VectorTraits<float __attribute__((ext_vector_type(2)))> {
>    enum {
>        VECTOR = 2
>    };
> };
>
> template <>
> struct VectorTraits<float> {
>    enum {
>        VECTOR = 1
>    };
> };
>
>
> This fails with the following error:
> error: redefinition of
>      'VectorTraits<float>'
> struct VectorTraits<float>
>        ^~~~~~~~~~~~~~~~~~~

> It seems clang can not specialize by vector type. But when I omit the
> vector specialization
> the result for a vector type (i.e. VectorTraits<float2>::VECTOR) is 0.
> The vector type does not count as its basic type at instantiation time.
> Therefore this is a bug.

The template argument deduction and checking rules have no understanding of vector types (or extended vector types). You'll need to extend that for templates and vector types to work well together.

  - Doug
_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev