Optymalny sposób dostępu do elementu std :: tuple w czasie wykonywania według indeksu

Mam funkcjęat zaprojektowany do uzyskiwania dostępu do elementu std :: tuple według indeksu określonego w czasie wykonywania

template<std::size_t _Index = 0, typename _Tuple, typename _Function>
inline typename std::enable_if<_Index == std::tuple_size<_Tuple>::value, void>::type
for_each(_Tuple &, _Function)
{}

template<std::size_t _Index = 0, typename _Tuple, typename _Function>
inline typename std::enable_if < _Index < std::tuple_size<_Tuple>::value, void>::type
    for_each(_Tuple &t, _Function f)
{
    f(std::get<_Index>(t));
    for_each<_Index + 1, _Tuple, _Function>(t, f);
}

namespace detail { namespace at {

template < typename _Function >
struct helper
{
    inline helper(size_t index_, _Function f_) : index(index_), f(f_), count(0) {}

    template < typename _Arg >
    void operator()(_Arg &arg_) const
    {
        if(index == count++)
            f(arg_);
    }

    const size_t index;
    mutable size_t count;
    _Function f;
};

}} // end of namespace detail

template < typename _Tuple, typename _Function >
void at(_Tuple &t, size_t index_, _Function f)
{
    if(std::tuple_size<_Tuple> ::value <= index_)
        throw std::out_of_range("");

    for_each(t, detail::at::helper<_Function>(index_, f));
}

Ma liniową złożoność. Jak uzyskać złożoność O (1)?

questionAnswers(1)

yourAnswerToTheQuestion