[SOLVED]return parameter pack, working without tuple

Hi.

I’m trying to do a sketch that can return a parameter pack. I found a reference here: tuple-to-parameter-pack

I modify it to be even more generic and can return any type of object to a void function pointer.

That said, now I’m testing with arduino DUE and this board support tuple. But the arduino uno do not.

So, base on this article:
variadic-template-data-structures
I decide to use my own micro-tuple data-structure that will be supported by UNO. The structure work by itself.

Here the code so far:

#include <tuple>

template<size_t idx, typename T>
struct microTupleGetHelper;

template<typename ... T>
struct microTuple
{
};

template<int ...> struct seq {};

template<int N, int ...S> struct gens : gens<N - 1, N - 1, S...> { };

template<int ...S> struct gens<0, S...>{ typedef seq<S...> type; };



template<typename T, typename ... Rest>
struct microTuple<T, Rest ...>
{
    microTuple(const T& first, const Rest& ... rest)
        : first(first)
        , rest(rest...)
    {}
    
    T first;
    microTuple<Rest ... > rest;
    
    template<size_t idx>
    auto get() ->  decltype(microTupleGetHelper<idx, microTuple<T,Rest...>>::get(*this))
    {
        return microTupleGetHelper<idx, microTuple<T,Rest...>>::get(*this);
    }
};

template<typename T, typename ... Rest>
struct microTupleGetHelper<0, microTuple<T, Rest ... >>
{
    static T get(microTuple<T, Rest...>& data)
    {
        return data.first;
    }
};

template<size_t idx, typename T, typename ... Rest>
struct microTupleGetHelper<idx, microTuple<T, Rest ... >>
{
    static auto get(microTuple<T, Rest...>& data) ->  decltype(microTupleGetHelper<idx-1, microTuple<Rest ...>>::get(data.rest))
    {
        return microTupleGetHelper<idx-1, microTuple<Rest ...>>::get(data.rest);
    }
};



template <typename ...Args>
struct paramsPack
{
    //std::tuple<Args...> params;
    microTuple<Args...> params;

    void (*func)(Args...);

/*    template<int ...S>
    auto callFunc(seq<S...>) -> decltype(this->func(std::get<S>(this->params) ...))
    {
        return func(std::get<S>(params) ...);
    }*/

    template<int ...S>
    auto callFunc(seq<S...>) -> decltype(this->func(this->params.get<S>() ...))
    {
     return func(params.get<S>() ...)
    }

    auto delayed_dispatch() -> decltype(this->callFunc(typename gens<sizeof...(Args)>::type()))
    {
        return this->callFunc(typename gens<sizeof...(Args)>::type()); // Item #1
    }

};

Here, the old tuple version is muted for reference.

the error come in auto callFunc(…), it stand:

microTuple:72:73: error: expected primary-expression before ')' token

     auto callFunc(seq<S...>) -> decltype(this->func(this->params.get<S>() ...))

                                                                         ^

The reference to the object in the structure is accessible with obj.get() syntax usually, I don’t know was it is not here…

I’m stuck there.

Regards. Nitrof

I think your question is too complex for us to provide useful answer. I can only see 1 or 2 frequencers that can provide the solution.

You would have better luck posting it somewhere else.

:o Ho… I never though I will get to that point one day… lol.

I could ask on stack overflow, but there there’s a good chance they told me to use tuple instead. You don’t think ? They are not confine to the arduino environment…

I will try it anyway, maybe the will have a clue…

thanks.

Regards.

Nitrof

From Stack overflow:
The type of params is dependent on the template parameters, so the compiler has no way of knowing whether .get is a template or not when parsing it. You need to tell the compiler explicitly that it is a template:

    template<int ...S>
    auto callFunc(seq<S...>) -> decltype(this->func(this->params.template get<S>() ...))
    {
     return func(params.template get<S>() ...);
    }