I'm writing some code for automatic function argument type deduction using a tuple. I'm then iterating over it to narrow down and check each argument separately. I spent a cozy evening tinkering with getting by-value, const value and const references to work, until I discovered that some functions need to return more than one result. This is where I need to identify non-const lvalue references, which a tuple has difficulty in handling.
As far as I can tell most problems out and about on the web focus on creating fairly simple stand-alone tuples that only contain lvalue references using std::tie. In particular, this stackexchange thread outlines how that can be accomplished.
Problem is, I have a packed array of types, which may or may not contain one or more lvalue references interleaved with other types. forward_as_tuple is suggested here and there, but I'm unsure how to use it.
Here's there relevant code:
// split the return type from the argument list
template<typename R, typename... Args>
struct signature<R(Args...)>
{
using return_type = R;
using argument_type = std::tuple<Args...>; // 1
};
template<typename FUNCSIG>
editor::nodetype_t& CreateNodeType(
IN const char* category)
{
// instantiate the argument list tuple. No need to post any further code as this
// is where things fail to compile
signature<FUNCSIG>::argument_type arglist; // 2
}
// the below snippet outlines how CreateNodeType() is called:
#define DEFINE_MTL_NODE(function, category, ...) \
auto& nodeType = CreateNodeType<decltype(function)>(category);
// a sample function for completeness. I'm intentionally not using the return value here.
void Lerp(
IN const math::vec3& ColorIn1,
IN const math::vec3& ColorIn2,
IN float Alpha,
OUT math::vec3& ColorOut) { .. }
void main()
{
DEFINE_MTL_NODE(Lerp, "Color");
}
Either the line marked with 1 or 2 needs to be something else, but apparently my C++ level is not high enough to figure out what. PS - to further complicate things, I'm stuck on C++11 for now.
Ideas?