jeudi 3 novembre 2016

Template Metaprogramming Errors [duplicate]

This question already has an answer here:

I am trying to play with some TMP techniques, following Simple C++11 Metaprogramming, I cooked up my own sample

#include <cstdlib>
#include "magma.h"

struct None{};

template<typename Type>
struct select_type_impl{
    typedef typename None type;
};

template<>
struct select_type_impl<double>{
    typedef typename magmaDouble_ptr type;
};

template<typename Type>
using select_type_ = select_type_impl<Type>::type;

template<typename Type>
class GMatrix {
public:
    select_type_<Type> data;
    size_t nRow;
    size_t nCol;
    GMatrix(const size_t _nRow, const size_t _nCol):nRow(_nRow), nCol(_nCol){
        magma_dmalloc(data,nRow*nCol);
    }
    ~GMatrix(){
        magma_free(data);
    }
};

Unfortunately, there are a lot of errors generated by the compiler (nvcc with icpc backends), here are they

    /home/user/Desktop/NSPCAGPU/src/GMatrix.cu(12): error: a class or namespace qualified name is required (This refers to the line typedef typename None type;)


/home/user/Desktop/NSPCAGPU/src/GMatrix.cu(17): error: a class or namespace qualified name is required (This refers to the line typedef typename magmaDouble_ptr type;)

/home/user/Desktop/NSPCAGPU/src/GMatrix.cu(21): error: nontype "select_type_impl<Type>::type [with Type=Type]" is not a type name (This refers to the line select_type_<Type> data;)

I have checked several other answers (e.g. template error: nontype “.. [with T=T] is not a type name”) but I still do not understand how to change the code. Any help or explanation is welcome

Aucun commentaire:

Enregistrer un commentaire