I have many classes exposing an inner type named Binding
. For instance, one of them could be:
struct Message
{
struct Binding
{
};
};
I invoke a function apply
like this:
apply< Message >([](Message::Binding& x)
{
// setup binding fields
});
for I wrote
template <class TMessage, class TBindingExpression>
void apply(const TBindingExpression& expr)
{
typedef typename TMessage::Binding BindingType;
BindingType binding;
expr(binding);
apply(MessageUtil::typeId< TMessage >(), binding);
}
Since Message
is a bit redundant in the way I invoke apply
, I would like to make the compiler deduce Message
so I can write
apply([](Message::Binding x)
{
//...
});
So far, I am stuck here:
template <class TBindingExpression>
void apply(const TBindingExpression& expr)
{
// I get the type of the argument which is Message::Binding in this example
typedef typename std::tuple_element
<
0,
FunctionTraits< TBindingExpression >::ArgumentTypes
>
::type BindingType;
// so I can invoke my expression
BindingType binding;
expr(binding);
// But now I need the type of the outer class, i.e. Message
typedef typename MessageTypeFromBinding< BindingType >::Type MessageType;
apply(MessageUtil::typeId< MessageType >(), binding);
}
Is there a way to write/achieve MessageTypeFromBinding
?
Obviously, that's pure curiosity and cosmetic concerns.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…