mardi 27 octobre 2015

template for generating functions to call a function with argument from a runtime stack

my questions are in the following code:

template <class _type>
_type translateArgument (std::string);

template <class _type>
std::string translateResult (_type result);

template <class _function_type, _function_type _function, class _result_type, class... _arguments_type>
struct Function
{
    typedef std::tuple<_arguments_type...> arguments_type;

    static void call(std::stack<std::string> stack)
    {
        auto value1 = translateArgument<std::tuple_element<0, arguments_type>::type>(stack.top());
        stack.pop();

        auto value2 = translateArgument<std::tuple_element<1, arguments_type>::type>(stack.top());
        stack.pop();

        ...
    }
};

1.first question :

how to generate code from value1 to valueN, where N is the sizeof...(_arguments_type)

2.second question :

if _result_type is void, add code to the end of Function::call

_function(value1, value2, ...);

otherwise, add code to the end of Function::call

stack.push(preocessResult<_result_type>(_function(valu1, value2, ...)));

Aucun commentaire:

Enregistrer un commentaire