Shawn Shie wrote:
Hello!
When reading source code of loki,i have some problems as below:
//HierarchyGenerators.h
namespace Private
{
...
template <>
struct GenScatterImpl<TL::Private::NoneList_ID>
{
template <class AtomicType, class MetaFunctionWrapper>
struct In
{
typedef typename
ApplyInnerType<MetaFunctionWrapper, AtomicType>::type type;
typedef type LeftBase;
typedef EmptyType RightBase;
};
};
...
}
...
template <class T, class Unit>
class GenScatterHierarchy : public Private::GenScatterImpl
<
IS_TYPELIST(T)::type_id
::template In<T, Unit>::type
{
public:
...
typedef typename Private::GenScatterImpl
~~~~~~~~(1)
<
IS_TYPELIST(T)::type_id
::template In<T, Unit>::RightBase RightBase;
~~~~~~~~ ...(2)
};
Problems:
1).Why must a "typename" in place (1)?
I ever wrote some codes with no "typename"s,
but they could be compiled exactly and worked with no error.
When must "typename" be used??
Because the standard says so.
The requirement stems from a problem in parsing because the grammer is
ambiguous so the standard just requires it to be so.
2).What's the effect of the word "template"??
There are no error without the "template" as i tried.
So, are there any semantic differences between the two--with or without
"template" ?
The use of 'template' is optional here however certain compilers (gcc)
may not recognize a template name correctly. Hence you may choose to
the template name<...> syntax to be compatible with earlier buggy versions.
see: http://gcc.gnu.org/bugzilla/show_bug.cgi?id=795
.