Having a template:

struct SomeStruct(int size)
{

}

Is there any language trait returning the value of size template parameter for the template instantiation SomeStruct!10?

In fact, I'm interested in an eponymous template to test if some type is a template inttantation for SomeStruct(int size).

template isSomeStruct(T)
{
  enum isSomeStruct = ?
}

template getStructSize(T) if (isSomeStruct!T)
{
  enum getStructSize = ?
}


I know that I can do something like this:

struct SomeStruct(int size)
{
   enum internalSize = size;
}

template isSomeStruct(T)
{
  enum isSomeStruct = is (typeof(T.internalSize): int);
}

template getStructSize(T) if (isSomeStruct!T)
{
  enum getStructSize = T.internalSize;
}

but I wonder that if it's not another simple and safe way. This approach is not safe because there is a risk to have SomeOtherStruct(int size) defined with similar semantics.

Thanks.

Reply via email to