mercredi 30 décembre 2020

no matching function for call to std::get with const tuple ref as argument

I've been trying to make a generic function in order to build a query in SQL. In order to do that, I went and used tuple with variadic template, in order to make the query more generic. This is the code (This is not a final code so understand some of the code is pseudo-code):

#include <tuple>

template<std::size_t I>
struct Visit_Tup_Impl
{
  template<typename ...T>
  static const std::string& visit_tup (const std::tuple<T...>& values, int comp)
  {
    if (I == comp)
    {
      std::get<I, std::tuple<T...> > (values);
      return EMPTY_STRING;
    }
    else
    {
      return Visit_Tup_Impl<I-1>::visit_tup (values, comp);
    }
  }
};

template<>
template<>
const std::string&
Visit_Tup_Impl<0>::visit_tup (const std::tuple<>& values, int comp)
{
  assert (0 && "Should not happen");
  return EMPTY_STRING;
}

template <typename ...T>
std::string
create_coupled_query (const std::vector<std::string>& keys,
                      const std::vector<std::tuple<T...> >& values)
{
  std::ostringstream local;
  local << "(";

  auto iter = values.begin ();
  auto iter_end = values.end ();
  for (; iter != iter_end; ++iter)
  {
    local << "(";
    int i = 1;
    do
    {
      local << keys [i] << "=" << to_sql_string (Visit_Tup_Impl<(sizeof...(T) - 1)>::visit_tup (*iter, i));
      ++i;
      if (i < keys.size ())
        local << " AND ";
    }
    while (i < keys.size ());

    local << ")";
    if (iter + 1 != iter_end)
      local << " OR ";
  }

  local << ")";

  return local.str ();
}

This is the line that wouldn't compile:

std::get<I, std::tuple<T...> > (values);

I Get This compilation error:

no matching function for call to ‘get(const std::tuple<ACE_Time_Value, ACE_Time_Value, std::basic_string<char, std::char_traits, std::allocator > >&)’

Also, it gives me suggestions for std::get candidates (under utility.h):

template<long unsigned int _Int, class _Tp1, class _Tp2> constexpr typename std::tuple_element<_Int, std::pair<_Tp1, _Tp2> >::type& std::get(std::pair<_Tp1, _Tp2>&)

and some more, which are not relevant for me.

Ur help compiling this please

Aucun commentaire:

Enregistrer un commentaire