私はすべての算術型のためのstd ::ベクトルを含めるためにハッシュを専門にしようとしているのベクトルのクラスの専門が、それは私が私のように近くに従うことをしようとしたいくつかのエラー特定type_trait
./includes/helpers.hpp:14:22: error: default template argument in a class template partial specialization
typename = std::enable_if_t<std::is_arithmetic<dtype>::value> >
^
./includes/helpers.hpp:16:8: error: class template partial specialization contains a template parameter that cannot be deduced; this partial specialization will never be used [-Wunusable-partial-specialization]
struct hash<std::vector<dtype> >
^~~~~~~~~~~~~~~~~~~~~~~~~
を投げています異なるenable_if_tガイドを使用することができます。しかし、それは動作していないようだ、私は間違って何ですか?
enable_if_tを使用せずに動作するようです。しかし、その後これは、これまでの私のコードで、このハッシュを使用しないでくださいベクトル
との重複の可能性が存在することになる(以上、「完全」であることをeditted)
#include <iostream>
#include <type_traits>
#include <vector>
namespace std {
template <typename dtype,
typename = std::enable_if_t< std::is_arithmetic<dtype>::value> >
struct hash<std::vector<dtype> > {
size_t operator()(const std::vector<dtype> &input)
{
//perform hash
}
};
}
using namespace std;
int main()
{
const vector<int> i{1,2,3,4};
cout << hash<vector<int>>()(i) << endl;
return 0;
}
無名のテンプレート引数のデフォルト値として、このような 'enable_if_t'のアプリケーションがあったことはありませんでした。あなたが言及したガイドへのリンクを提供できますか? – Omni
@オムニそれは本当にガイドではありませんが、私はちょうど2つの異なる情報源を使って、うまくいくと思っています。 「名前のないテンプレートのデフォルト値」については、http://en.cppreference.com/w/cpp/types/enable_ifが正しく動作するはずです(5番までスクロールしてください)。 – Michael
[最小限で完全であり、検証可能な例](http://stackoverflow.com/help/mcve)を投稿してください。 –