How is it that this works? Might be doing something wrong here.
def.H
enum some_enum { FAKE = 0, };
template < some_enum T> struct example_trait;
trait_implementation.H
#include "def.H"
template<> struct example_trait<FAKE> {
static constexpr size_t member_var = 3; };
generic_alg.H
#include "def.H"
template < some_enum T, typename TT = example_trait<T> > void
function() { std::cout << TT::member_var << std::endl; }
main.C
I can run this in my main as long as I include the headers in this order
#include trait_implementation.H
#include generic_alg.H
int main() {
function<FAKE>();
return 0;
}
How is it that this compiles? can generic_alg.H compiles with only a forward declared traits class. It can see the traits definition when included in the right order, even though generic_alg.H itself does not include the trait_implementation.H. How is that plausible?
Using an online compiler I can only re-create: https://onlinegdb.com/B1BEUlp7E