1

使用 gnu 编译器,我得到了多个错误

error: too few template-parameter-lists

这让我很困惑,因为英特尔编译器似乎在没有警告的情况下处理了以下代码段:

// Template to retrieve traits of any MPI object
template <class T>
struct mpi_type_traits {
   typedef T element_type;
   typedef T* element_addr_type;
   static inline MPI_Datatype get_type(T&& val);
   static inline size_t get_size(T& val);
   static inline void* get_addr(T& val);
};

// Specialization of mpi_type_traits for primitive types
#define PRIMITIVE(Type, MpiType) \
        template<> \
        inline MPI_Datatype mpi_type_traits<Type>::get_type(Type&&) { return MpiType; } \
        inline size_t mpi_type_traits<Type>::get_size(Type&) { return 1; } \
        inline void* mpi_type_traits<Type>::get_addr(Type& val) { return &val; }
  PRIMITIVE(char, MPI::CHAR);
  PRIMITIVE(wchar_t, MPI::WCHAR);
  PRIMITIVE(short, MPI::SHORT);
  PRIMITIVE(int, MPI::INT);
  PRIMITIVE(long, MPI::LONG);
  PRIMITIVE(signed char, MPI::SIGNED_CHAR);
  PRIMITIVE(unsigned char, MPI::UNSIGNED_CHAR);
  PRIMITIVE(unsigned short, MPI::UNSIGNED_SHORT);
  PRIMITIVE(unsigned int, MPI::UNSIGNED);
  PRIMITIVE(unsigned long, MPI::UNSIGNED_LONG);
  PRIMITIVE(unsigned long long, MPI::UNSIGNED_LONG_LONG);
  PRIMITIVE(bool, MPI::BOOL);
  PRIMITIVE(std::complex<float>, MPI::COMPLEX);
  PRIMITIVE(std::complex<double>, MPI::DOUBLE_COMPLEX);
  PRIMITIVE(std::complex<long double>, MPI::LONG_DOUBLE_COMPLEX);

#undef PRIMITIVE

通过阅读,这与类型名称规范有关,但我无法确定它需要放置在哪里。很明显,错误来自每个 PRIMITIVE。

4

1 回答 1

2

好的,想通了。需要将 template<> 放在每个定义的内联之前。

...
#define PRIMITIVE(Type, MpiType) \
    template<> \
    inline MPI_Datatype mpi_type_traits<Type>::get_type(Type&&) { return MpiType; } \
    template<> \
    inline size_t mpi_type_traits<Type>::get_size(Type&) { return 1; } \
    template<> \
    inline void* mpi_type_traits<Type>::get_addr(Type& val) { return &val; }
  PRIMITIVE(char, MPI::CHAR);
...
于 2013-11-03T17:55:51.687 回答