#include <iostream>
template<typename T>
const T unit{ 1 };
template<typename T>
struct data
{
typename T::value_type val;
};
struct decimal_def
{
using value_type = int;
static const value_type unit_val() {
return 10;
}
};
template<typename T>
const data<T> unit<data<T>> { T::unit_val() };
auto decimal_data_unit = unit<data<decimal_def>>;
int main(){
std::cout << decimal_data_unit.val << std::endl;
return 0;
}
exoect: 10
gcc: 10
msvc: 0
I think the reason of the difference between gcc and msvc is that compilers optimize unit_val() differently.