[MPL] what is my base class?

I'm writing a class template, say C<T>, that has essentially different features depending on a classification of type T. So, I implemented Ca and Cb as befitting the two categories, and then make that transparent to the user by making a stub for C that inherits from either of those two, using boost::mpl::if_ to choose between them. However, the constructors have to be brought down manually. To "inherit" them, they need to be forwarded to the base class: C (...args...) : Ca (...args...) {} The problem is, I can't easily name the base class here in the base initialization list. I'm not even sure repeating the if_ metaexpression here would work, since the init list doesn't even like typedefs but wants the literal name of the class. Did I paint myself into a corner? Please help. In one case, it was not a problem to use only a default constructor and call an inherited Initialize function from the body. In the other case, I want to keep my reference member initializers. Thanks, --John TradeStation Group, Inc. is a publicly-traded holding company (NASDAQ GS: TRAD) of three operating subsidiaries, TradeStation Securities, Inc. (Member NYSE, FINRA, SIPC and NFA), TradeStation Technologies, Inc., a trading software and subscription company, and TradeStation Europe Limited, a United Kingdom, FSA-authorized introducing brokerage firm. None of these companies provides trading or investment advice, recommendations or endorsements of any kind. The information transmitted is intended only for the person or entity to which it is addressed and may contain confidential and/or privileged material. Any review, retransmission, dissemination or other use of, or taking of any action in reliance upon, this information by persons or entities other than the intended recipient is prohibited. If you received this in error, please contact the sender and delete the material from any computer.

On Fri, May 21, 2010 at 10:44 AM, John Dlugosz
I'm writing a class template, say C<T>, that has essentially different features depending on a classification of type T. So, I implemented Ca and Cb as befitting the two categories, and then make that transparent to the user by making a stub for C that inherits from either of those two, using boost::mpl::if_ to choose between them.
However, the constructors have to be brought down manually. To "inherit" them, they need to be forwarded to the base class: C (...args...) : Ca (...args...) {}
The problem is, I can't easily name the base class here in the base initialization list. I'm not even sure repeating the if_ metaexpression here would work, since the init list doesn't even like typedefs but wants the literal name of the class.
Did I paint myself into a corner? Please help.
In one case, it was not a problem to use only a default constructor and call an inherited Initialize function from the body. In the other case, I want to keep my reference member initializers.
It helps a lot if you have a minimized source code that demonstrates the problem with comments of what you want done attached to your email?

It helps a lot if you have a minimized source code that demonstrates the problem with comments of what you want done attached to your email?
template <typename T> class C : public boost::mpl::if_ < is_blue<T>, Ca <T>, Cb<T> >::type { public: C (blah& a, xxx b) : Ca (a,b) // >> problem here {} }; I'm writing a class template, say C<T>, that has essentially different features depending on a classification of type T. So, I implemented Ca and Cb as befitting the two categories, and then make that transparent to the user by making a stub for C that inherits from either of those two, using boost::mpl::if_ to choose between them. However, the constructors have to be brought down manually. To "inherit" them, they need to be forwarded to the base class: C (...args...) : Ca (...args...) {} The problem is, I can't easily name the base class here in the base initialization list. I'm not even sure repeating the if_ metaexpression here would work, since the init list doesn't even like typedefs but wants the literal name of the class.
Did I paint myself into a corner? Please help.
--John TradeStation Group, Inc. is a publicly-traded holding company (NASDAQ GS: TRAD) of three operating subsidiaries, TradeStation Securities, Inc. (Member NYSE, FINRA, SIPC and NFA), TradeStation Technologies, Inc., a trading software and subscription company, and TradeStation Europe Limited, a United Kingdom, FSA-authorized introducing brokerage firm. None of these companies provides trading or investment advice, recommendations or endorsements of any kind. The information transmitted is intended only for the person or entity to which it is addressed and may contain confidential and/or privileged material. Any review, retransmission, dissemination or other use of, or taking of any action in reliance upon, this information by persons or entities other than the intended recipient is prohibited. If you received this in error, please contact the sender and delete the material from any computer.

On May 21, 2010, at 12:44 PM, John Dlugosz
The problem is, I can't easily name the base class here in the base initialization list. I'm not even sure repeating the if_ metaexpression here would work, since the init list doesn't even like typedefs but wants the literal name of the class.
Especially when my base class is a template with a number of
parameters, I often do write something like:
class Subclass: BaseClass

Especially when my base class is a template with a number of parameters, I often do write something like:
class Subclass: BaseClass
{ typedef BaseClass super; public: Subclass(whatever): super(whatever), ... {} ... }; Also, this lets an override method forward a call to the base-class method by writing super::method();
What part isn't working for you?
Hmm, I seem to recall that the init list didn't like typedefs. Maybe that is way out of date (for Microsoft compiler), or maybe I was confusing that with the constructor name itself only. That certainly would help, as I can make a typedef for the meta-expression before making the class, and use it for both the base and init list. Thanks; I'll try that again. I see it is explicitly allowed (and clarified) in the n3092 draft standard. --John TradeStation Group, Inc. is a publicly-traded holding company (NASDAQ GS: TRAD) of three operating subsidiaries, TradeStation Securities, Inc. (Member NYSE, FINRA, SIPC and NFA), TradeStation Technologies, Inc., a trading software and subscription company, and TradeStation Europe Limited, a United Kingdom, FSA-authorized introducing brokerage firm. None of these companies provides trading or investment advice, recommendations or endorsements of any kind. The information transmitted is intended only for the person or entity to which it is addressed and may contain confidential and/or privileged material. Any review, retransmission, dissemination or other use of, or taking of any action in reliance upon, this information by persons or entities other than the intended recipient is prohibited. If you received this in error, please contact the sender and delete the material from any computer.

2010/5/22 Nat Goodspeed
Especially when my base class is a template with a number of parameters, I often do write something like:
class Subclass: BaseClass
{ typedef BaseClass super; public: Subclass(whatever): super(whatever), ... {} ... };
If your compiler implements injected names correctly (gcc does not), you can use BaseClass instead of super. namespace some_long_namespace { template <class T> struct Base {}; } struct Derived : some_long_namespace::Base<int> { Derived() : Base() {} }; Roman Perepelitsa.

typedef BaseClass
super;
It turns out that this does work under VS2008.
So I have to give the metafunction expression twice: once for declaring the class's parent, and again immediately after for the typedef. But then all the constructors and others can use the typedef.
In this case, the base uses the same template parameter as the derived, so I could not use a typedef beforehand. I'm pretty sure that VS2010 doesn't support the enhanced typedef features of C++0x, so it will be in there for a while.
What bugs me is that MSVC has a __super keyword, "to deal with injected base class that you don't know the name of" due to its non-standard "attribute" extension. But it doesn't work with the constructor init list, only with qualifications.
--John
From: boost-users-bounces@lists.boost.org [mailto:boost-users-bounces@lists.boost.org] On Behalf Of Roman Perepelitsa
Sent: Tuesday, May 25, 2010 3:43 AM
To: boost-users@lists.boost.org
Subject: Re: [Boost-users] [MPL] what is my base class?
2010/5/22 Nat Goodspeed

2010/5/25 John Dlugosz
typedef BaseClass
super; It turns out that this does work under VS2008.
Have you tried using injected names under VS2008? Like this: template <typename T> struct C : boost::mpl::if_< is_blue<T>, Ca <T>, Cb<T> >::type { C(blah& a, xxx b) : if_(a, b) {} }; Roman Perepelitsa.

Hmm, so if_ itself, with no arguments? That's a good idea. I'll try that.
That might be exactly what I was looking for, if it doesn't choke the compiler. Many thanks.
--John
From: boost-users-bounces@lists.boost.org [mailto:boost-users-bounces@lists.boost.org] On Behalf Of Roman Perepelitsa
Sent: Tuesday, May 25, 2010 11:08 AM
To: boost-users@lists.boost.org
Subject: Re: [Boost-users] [MPL] what is my base class?
2010/5/25 John Dlugosz
typedef BaseClass
super; It turns out that this does work under VS2008. Have you tried using injected names under VS2008? Like this:
template <typename T> struct C : boost::mpl::if_< is_blue<T>, Ca <T>, Cb<T> >::type { C(blah& a, xxx b) : if_(a, b) {} }; Roman Perepelitsa. TradeStation Group, Inc. is a publicly-traded holding company (NASDAQ GS: TRAD) of three operating subsidiaries, TradeStation Securities, Inc. (Member NYSE, FINRA, SIPC and NFA), TradeStation Technologies, Inc., a trading software and subscription company, and TradeStation Europe Limited, a United Kingdom, FSA-authorized introducing brokerage firm. None of these companies provides trading or investment advice, recommendations or endorsements of any kind. The information transmitted is intended only for the person or entity to which it is addressed and may contain confidential and/or privileged material. Any review, retransmission, dissemination or other use of, or taking of any action in reliance upon, this information by persons or entities other than the intended recipient is prohibited. If you received this in error, please contact the sender and delete the material from any computer.
participants (4)
-
John Dlugosz
-
Nat Goodspeed
-
OvermindDL1
-
Roman Perepelitsa