The following code works fine:
#include <type_traits>
template <typename> class AddLayer;
template <template <typename> class TLayer>
struct LayerInputPortSet
{
using type = int;
};
template <>
struct LayerInputPortSet<AddLayer>
{
using type = float;
};
using type = typename LayerInputPortSet<AddLayer>::type;
static_assert(std::is_same_v<type, float>);
But with the following modification:
#include <type_traits>
template <typename> class AddLayer;
template <template <typename> class TLayer>
struct LayerInputPortSet
{
using type = int;
};
template <>
struct LayerInputPortSet<AddLayer>
{
using type = float;
};
template <template<typename> class TLayer>
struct Sublayer
{
template <typename TInputs>
using LayerType = TLayer<TInputs>;
};
using type = typename LayerInputPortSet<Sublayer<AddLayer>::template LayerType>::type;
static_assert(std::is_same_v<type, float>);
As I understand, since "A type alias declaration introduces a name which can be used as a synonym for the type denoted by type-id", therefore Sublayer<AddLayer>::template LayerType
is an alias of AddLayer
, so type
should be float
based on the template specialization.
This code works on GCC, but it cannot be compiled on clang 6, clang 7, clang 8, and VS 2019. In fact, if I change the last line as:
static_assert(std::is_same_v<type, int>);
The code could be compiled on clang 6, clang 7, clang 8, and VS 2019.
I don't know which compiler's behavior is correct: GCC or Clang/VS ?
Thanks a lot!