は、私は私のコードは、このように構成されているとし:この場合、テンプレートの特殊化をcppファイルに書き込むことはできますか?
header1.h
template <class T, template<class> class C> struct metafunction { using type = typename C<T>::type; }; inline namespace msn { template <class T> struct implementation; } // uses the *implementation* not defined in the header! template <class T> struct use_case { using type = typename metafunction<T, implementation>::type; };
cpp1.cpp
#include <header1.h> // I'll only need this in this compilation unit, so the // question is: "Is this a good place to define it?" template <> struct implementation<int> { using type = int; }; int main() { using tt = int; // is this point of instantiation OK due to // the existence of a specialization in the same cpp file? using tt = use_case<int>::type; tt var; (void)var; }
私の前提は、私が唯一のよということです私はリンカーの問題に対処する必要はありませんので、cppファイル内の特定の専門分野を使用してください。 これは、cpp2.cpp
ファイル(header1.h
を含む)では使用できず、use_case<int>
を使用するか、ODRに違反するimplementation<int>
を再定義しようとしています。だから、私はこのコードがlinear form(すべてが1つのcppファイルに適合する順序で入れられているバージョン)に類似しているかどうかを尋ねています。
この目的で 'extern'テンプレートを使うことができます。 –
@KerrekSB私はインラインネームスペースで持ち去られました。私がC++ 11を持っていないとすれば、与えられたコードが悪いですか? –
どのような詳細をお探しですか? – Barry