みなさんこんにちは!C++:テンプレート:部分的な特殊化:すべてのテンプレートを印刷
次のコードを持つ:
template<typename T, typename OutStream = std::ostream>
struct print
{
OutStream &operator()(T const &toPrint, OutStream &outStream = std::cout) const
{
outStream << toPrint;
return outStream;
}
};
template<typename T, typename Index = unsigned int, typename CharType = char, typename OutStream = std::ostream>
struct print<T *, Index>
{
print(CharType delimiter = ' '): delimiter_(delimiter) {}
OutStream &operator()(T const *toPrint, Index startIndex, Index finishIndex, OutStream &outStream = std::cout) const
{
for (Index i(startIndex) ; i < finishIndex ; ++i)
outStream << toPrint[i] << delimiter_;
return outStream;
}
protected:
CharType delimiter_;
};
コンパイラ:MSVCPP10
コンパイラの出力:
1>main.cpp(31): error C2764: 'CharType' : template parameter not used or deducible in partial specialization 'print<T*,Index>'
1>main.cpp(31): error C2764: 'OutStream' : template parameter not used or deducible in partial specialization 'print<T*,Index>'
1>main.cpp(31): error C2756: 'print<T*,Index>' : default arguments not allowed on a partial specialization
私はこだわっています。私は部分的な専門化を完了するのに役立ちます。
ありがとうございます!
私は([プリティプリンタライブラリ]であなたは興味があります。http: //stackoverflow.com/questions/4850473/pretty-print-c-stl-containers)? –
*特殊な*ケースでは、何かを専門にすることができます。あなたの 'T *、Index'フォームは"もっと特別な "ものではなく、まったく異なっています。 –
@KerrekSBありがとう、あなたが提案したプロジェクトは非常に面白いです! – DaddyM