[External] Re: [xsd-users] Template for member created by Code
Synthesis
Markowitz, Hillel [USA]
Markowitz_Hillel at bah.com
Thu Feb 26 17:23:22 EST 2015
Thank you. looking at this, I see that it explicitly has memberA_pushback. I have been able to create templates that will use the generic member as long as the member exists in the base class. However, consider the case in which memberA, memberB, ..., memberL all exist while memberM, ..., memberZ have not yet been implemented. i do not have control of the relevant library but would like to be able to set up a generic template rather than have to write a unique one for each member.
Looking at the enable_if I am not sure what needs to be done to create the appropriate boolean. I have set it up to return a boolean as well instead of a void which has worked so far.
I also have a more complex set of
mainClass::BaseClass baseclass;
mainClass::MemberClassA mymember("baseData);
mymember.setContexts(contextData);
baseclass.memberClassA().push_back(mymember);
However, I would first want to get the simple case solved if possible.
I am also including my outside email in the cc: line so that I can see this and your response at home.
Thank you for answering me.
--
Hillel Eli Markowitz
Booz Allen Hamilton
Markowitz_Hillel at bah.com
Hillel.Markowitz at gmail.com
________________________________________
From: Boris Kolpackov <boris at codesynthesis.com>
Sent: Thursday, February 26, 2015 4:45 AM
To: Markowitz, Hillel [USA]
Cc: xsd-users at codesynthesis.com
Subject: [External] Re: [xsd-users] Template for member created by Code Synthesis
Hi Hillel,
Markowitz, Hillel [USA] <Markowitz_Hillel at bah.com> writes:
> I would like to set up templates to handle certain members that
> will be added in the future. I would like to use the templates
> so that I do not get a compilation file before the updated include
> files and libraries are installed.
>
>
> for example baseclass.myMemberA().push_back(basedata);
Ok, if I understood the above correctly, you are looking for a way
to test at C++-compile-time whether a class has a certain member.
If you are using C++11, this can be easily done with the expression
SFINAE. E.g., something along these lines:
template <typename T>
auto MemberA_push_back (const T* baseclass, const BaseData* basedata)
-> decltype (baseclass->myMemberA().push_back (*basedata))
{
baseclass->myMemberA().push_back (*basedata);
}
template <typename T>
void MemberA_push_back (...) {}
MemberA_push_back (&baseclass, &basedata)
You could also probably use enable_if instead of function return types.
Boris
More information about the xsd-users
mailing list