Say I have my code structured this way:
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; }
My precondition is that I'll only use the specific specialization(s) inside the cpp file(s) so I won't have to deal with linker problems. I know this won't work for a cpp2.cpp
file including header1.h
and trying to just use use_case<int>
or redefining an implementation<int>
that violates the ODR. So what I'm asking is whether this code is analogous to its linear form (a version where everything is put into a single cpp file with a conforming order) that (apparently) compiles fine.