[External] Re: [xsd-users] Template for member created by Code
Synthesis
Markowitz, Hillel [USA]
Markowitz_Hillel at bah.com
Fri Feb 27 12:52:25 EST 2015
I got the smaller case working however, I have another case that is built in the form
::maindata::Subdata mydata(indata);
// processing to add other information to mydata
base.subData().push_back(mydata);
However, it fails when I set up the template as
template<classB, typename D>
auto pushSubData(D indata, b &base, AttrType attrData)
-> decltype(base.subData(), bool())
{
doPush<::maindata::Subdata>(mydata, base.subData(), attrData); // This breaks the compiler
return true;
}
However, when I change it to
doPush(mydata, base.subData(), attrData); // This breaks the compiler
It does compile successfully. What am I doing wrong in the specification. Shouldn't the template skip this segment when subData() is not a member of base?
Would this be a valid way of trying it?
maindata.subData.push_back(myData);
auto newData = maindata.subData().back();
newData.attributes = attrData;
--
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