A typedef template parameter as the base class for the template class

I have a template
template<class T>           //1
class A : public LT         //2
{
public:
  typedef list<T> LT;       //3
};

This is a simplified version of a I'm writing class, the 1 template parameter is more than one, the 3 LT is a very complex type definitions, a typedef consists of a series of typedef finally got (with T)
If I like the above to write, compile time will be reported to LT is not defined. But I can't put 3 into the outside of class, because the LT associated with the T template parameter. I can think of right now is LT honestly according to no typedef prior written.
Do not know if you have no good way, retain the above this simple definition, also can let the compiler through?

Started by Derrick at February 05, 2016 - 7:01 PM

This is a problem I encountered in the preparation of ATL project, define a class ATL projects in the following excerpt:
template<class IChl, class Ctl, class ChlSmp, class SnsSmp, class Sns>
class IChunnelImp : public IChl, public ISensorsCollImpl
{
public:
	typedef typename list<CAdapt<CComObjectPtr<Sns>>> SensorContainer;
	typedef typename CComEnumOnSTL<IEnumVARIANT, &IID_IEnumVARIANT, VARIANT, 
					_CopyVariantFromAdaptComObjectPtr<Sns>, 
					SensorContainer>
			CComEnumVariantOnListOfSensors;
	typedef typename ICollectionOnSTLImpl<
					IDispatchImpl<IChunnel, &IID_IChunnel, &LIBID_TroikaLib, /*wMajor =*/ 1, /*wMinor =*/ 0>,
					SensorContainer,
					ISensor*, 
					_CopyItfFromAdaptComObjectPtr<ISensor, Sns>,
					CComEnumVariantOnListOfSensors>
			ISensorsCollImpl;
//...
};

This is a collection of implementation, we can see that ISensorsCollImpl is composed of 3 typedef finally get, and he is the base class for IChunnelImp, its structure is simplified example of the same.

Posted by Derrick at February 11, 2016 - 7:13 PM

Template alias C++11 can solve your problem.

temple<typename T >
using ...

Posted by Crystal at February 15, 2016 - 8:11 PM

Sadly, this is in the VS2005, if there is no alias.?

Posted by Derrick at February 28, 2016 - 9:02 PM

template<class T>
class LTT
{
public:
  typedef list<T> type;
};


template<class T>           //1
class A : public typename LTT<T>::type         //2
{
};

Posted by Shirley at March 10, 2016 - 9:05 PM

Don't be lazy.

Posted by Lori at March 25, 2016 - 9:56 PM

According to Saleayas method, can achieve the effect I want, thank you.

Posted by Derrick at March 26, 2016 - 10:33 PM

Ha ha, programmers like lazy.

Posted by Derrick at March 31, 2016 - 11:28 PM

type traits. +1

Posted by Linda at April 01, 2016 - 11:37 PM

Is traits

Posted by Derrick at April 15, 2016 - 12:14 AM

Methods 4 floor is not recommended, in the absence of template alias C++03, traditionally as the four floor for a class to replace typedef, the problem is this class is redundant, it becomes a useless substitute for some is not only necessary grammatical convenience. For this reason, C++11 is proposed to replace the template name.

You know VS2005, don't use VS2010 or VS2012 will be a very difficult thing.? ?

Posted by Crystal at April 27, 2016 - 1:02 AM

Your experience, understand the change the compiler the look on PM's face
When PM, a lot of people are no longer continue to study technology.
As long as the old method also can be used, don't change it is not for improvement

Posted by Noah at May 02, 2016 - 1:29 AM

Try it, although not very good-looking, but to avoid being a #10 problem, and does not need c++11.
template<class T, typename LT = std::list<T>>
class A : public LT
{
};

Posted by Gregary at May 16, 2016 - 1:43 AM

I seem to remember that VS 2012 does not support template aliases.
At that time, I tested the C++11 support.
It is not support template alias and parametric template.

But VS 2013 perfect support.

Posted by Shirley at May 26, 2016 - 1:57 AM

A lot of development is more team development,
In a team, there is a people do not want to randomly change the compiler.

So, a team for the compiler is very troublesome.

Posted by Shirley at May 30, 2016 - 2:34 AM

Really hateful, 2010 and 2012 were not provide template alias, 2013 RTM began to support, g++ would have. Always don't like Microsoft C/C++ compiler, but most of the time, had to use them, but.

Posted by Crystal at June 06, 2016 - 3:27 AM

You this is with the four floor is the same (call forwarding for the element function), benefit is less to write a type, but the essence of the same.

MPL is often used to simplify the code element function forwarding.

Posted by Crystal at June 19, 2016 - 4:17 AM

This is not certain, change characteristics of information project is frequent, a compiler option is the configuration management, at the same time in the risk control need to be considered and proposed remedies.

Posted by Crystal at November 17, 2016 - 4:56 PM

Not perfect
At present the test results, similar to that still does not support:
template <typename _Ty > using MyPtr = _Ty *; //Neither the structure nor the function, but the legal

Posted by Jane at November 26, 2016 - 5:32 PM

I think you just don't want the same thing two times.
The way you say using, I don't understand how to avoid repeated typing, and without introducing redundant name, or you show code?

Posted by Gregary at December 11, 2016 - 6:13 PM

never mind, I think I got it.

Posted by Gregary at December 22, 2016 - 6:20 PM

This is not a few times, after all, is the copy paste can do, so a few words and no province who will give benefits.
The key is to maintain the problem. If a definition of words long and complex. When the future changes may occur without modification conditions. After all, then look at the code may not remember the code should be and another is together, may also just a single expression.
There is no better way, at present I have not found, who has the method that can say.
template<class T, typename LT = std::list<T>>
class A : public LT
This method is really not good. Because it does not meet the mandatory binding constraints LZ

Posted by Jane at January 06, 2017 - 6:33 PM

Agree with you before half theory.
As you said the default template parameters "does not meet the binding constraints that mandatory" LZ, I don't understand.
What is called the "mandatory binding constraints"?
LT is already common in class scope inside, also there needs to duplicate code, so that "look at the code may not remember the code should be and another is together."?
The only problem is LT need to use outside of class, it may result in duplicate, and then lead to maintenance problems.
Solutions can be used with traits or similar techniques, such as the class type is defined, then all other things by the class name qualified access.
You can also use the using and traits, but the essence is the same.
Anyway, I haven't seen using have what great fundamental advantage, in addition to the more modern and more clean.

Posted by Gregary at January 11, 2017 - 6:34 PM

Using and the four floor of the method is not the same (even the essence is not the same), in fact, four floor, the method also can not be said to be traits, it is similar to traits, but God does not like, the purpose of the traits is non intrusive extension, but the method four, obviously and this has nothing to do, but it. The output with a first-order meta function only, just like a chair, missing a leg, the wood is used up, so the temporary use of brick pad, it can also make do with one day, but the brick is always the bricks, it can never replace the chair legs, as long as the use of bricks, this chair is not complete.

The template name is such a chair leg, four floor is such a brick. Cannot typedef template is the language facilities design omission, especially template-id often looks like chicken, the template designer didn't think to give it an alias, C++11 now finally put the chair legs to fill up.

Posted by Crystal at January 13, 2017 - 6:48 PM