0

I'm getting a really big, scary, puzzling error in some code I've been working on lately. Basically, I'm trying to declare a thread and put it inside a std::vector for safe keeping. However, for some reason this gets std::tuple involved, which doesn't like what I'm doing.

How do I fix this?

P.S. I've already looked at this. If the answer's there, I'm not seeing it.

synchronizer.cpp:

#include <sys/socket.h>
#include <vector>
#include <thread>
#include <iostream>

#define PACKET_SIZE 8192

class synchronizer
{
private:
    int sock;
    int* status;
public:
    int start();
    synchronizer(int socket, int* stat);
    ~synchronizer();
    void operator()();
};

synchronizer::synchronizer(int socket, int* stat) : sock(socket), status(stat) {}

void synchronizer::operator()()
{
    this->start();
}

int synchronizer::start()
{
    std::cout << "Starting." << std::endl;

    char buf[PACKET_SIZE];

    if (recv(sock, buf, PACKET_SIZE, 0) == -1)
    {
        perror("Error receiving");
        return -1;
    }
    return 0;
}

synchronizer::~synchronizer()
{
}

The relevant bits of server.cpp, which is the main file:

#include <iostream>
#include <thread>
#include "synchronizer.hpp"

inline int checkin (std::vector<std::thread> *pool, int conn, int *status)
{
    synchronizer syncer = synchronizer(conn, status);
    pool->push_back(std::thread(syncer));
    return 0;
}

int main(void)
{
    std::vector<std::thread> pool = {};
    int status = 0;

    // newfd being a socket file descriptor acquired earlier in the program's logic
    checkin(&pool, newfd, &status);
}

And here's the error (compiling with option -pthread):

In file included from server.cpp:14:
/usr/include/c++/9/thread: In instantiation of ‘static std::thread::_Invoker<std::tuple<typename std::decay<_Tp>::type, typename std::decay<_Args>::type ...> > std::thread::__make_invoker(_Callable&&, _Args&& ...) [with _Callable = synchronizer&; _Args = {}; typename std::decay<_Tp>::type = synchronizer]’:
/usr/include/c++/9/thread:131:22:   required from ‘std::thread::thread(_Callable&&, _Args&& ...) [with _Callable = synchronizer&; _Args = {}; <template-parameter-1-3> = void]’
server.cpp:44:49:   required from here
/usr/include/c++/9/thread:267:4: error: no matching function for call to ‘std::tuple<synchronizer>::tuple(<brace-enclosed initializer list>)’
  267 |  } };
      |    ^
In file included from /usr/include/c++/9/bits/unique_ptr.h:37,
                 from /usr/include/c++/9/memory:80,
                 from /usr/include/c++/9/thread:39,
                 from server.cpp:14:
/usr/include/c++/9/tuple:808:11: note: candidate: ‘template<class _Alloc, class _Dummy, class ... _UElements, typename std::enable_if<((std::tuple<synchronizer>::_TMCT<_UElements ...>::_MoveConstructibleTuple<_UElements ...>() && (! std::tuple<synchronizer>::_TMCT<_UElements ...>::_ImplicitlyMoveConvertibleTuple<_UElements ...>())) && std::tuple<synchronizer>::_TNTC<_Dummy>::_NonNestedTuple<tuple<_Tail ...>&&>()), bool>::type <anonymous> > std::tuple<_Elements>::tuple(std::allocator_arg_t, const _Alloc&, std::tuple<_Args2 ...>&&)’
  808 |  explicit tuple(allocator_arg_t __tag, const _Alloc& __a,
      |           ^~~~~
/usr/include/c++/9/tuple:808:11: note:   template argument deduction/substitution failed:
In file included from server.cpp:14:
/usr/include/c++/9/thread:267:4: note:   candidate expects 3 arguments, 1 provided
  267 |  } };
      |    ^
In file included from /usr/include/c++/9/bits/unique_ptr.h:37,
                 from /usr/include/c++/9/memory:80,
                 from /usr/include/c++/9/thread:39,
                 from server.cpp:14:
/usr/include/c++/9/tuple:793:2: note: candidate: ‘template<class _Alloc, class _Dummy, class ... _UElements, typename std::enable_if<((std::tuple<synchronizer>::_TMCT<_UElements ...>::_MoveConstructibleTuple<_UElements ...>() && std::tuple<synchronizer>::_TMCT<_UElements ...>::_ImplicitlyMoveConvertibleTuple<_UElements ...>()) && std::tuple<synchronizer>::_TNTC<_Dummy>::_NonNestedTuple<tuple<_Tail ...>&&>()), bool>::type <anonymous> > std::tuple<_Elements>::tuple(std::allocator_arg_t, const _Alloc&, std::tuple<_Args2 ...>&&)’
  793 |  tuple(allocator_arg_t __tag, const _Alloc& __a,
      |  ^~~~~
/usr/include/c++/9/tuple:793:2: note:   template argument deduction/substitution failed:
In file included from server.cpp:14:
/usr/include/c++/9/thread:267:4: note:   candidate expects 3 arguments, 1 provided
  267 |  } };
      |    ^
In file included from /usr/include/c++/9/bits/unique_ptr.h:37,
                 from /usr/include/c++/9/memory:80,
                 from /usr/include/c++/9/thread:39,
                 from server.cpp:14:
/usr/include/c++/9/tuple:778:11: note: candidate: ‘template<class _Alloc, class _Dummy, class ... _UElements, typename std::enable_if<((std::tuple<synchronizer>::_TMCT<_UElements ...>::_ConstructibleTuple<_UElements ...>() && (! std::tuple<synchronizer>::_TMCT<_UElements ...>::_ImplicitlyConvertibleTuple<_UElements ...>())) && std::tuple<synchronizer>::_TNTC<_Dummy>::_NonNestedTuple<const tuple<_Tail ...>&>()), bool>::type <anonymous> > std::tuple<_Elements>::tuple(std::allocator_arg_t, const _Alloc&, const std::tuple<_Args2 ...>&)’
  778 |  explicit tuple(allocator_arg_t __tag, const _Alloc& __a,
      |           ^~~~~
/usr/include/c++/9/tuple:778:11: note:   template argument deduction/substitution failed:
In file included from server.cpp:14:
/usr/include/c++/9/thread:267:4: note:   candidate expects 3 arguments, 1 provided
  267 |  } };
      |    ^
In file included from /usr/include/c++/9/bits/unique_ptr.h:37,
                 from /usr/include/c++/9/memory:80,
                 from /usr/include/c++/9/thread:39,
                 from server.cpp:14:
/usr/include/c++/9/tuple:763:2: note: candidate: ‘template<class _Alloc, class _Dummy, class ... _UElements, typename std::enable_if<((std::tuple<synchronizer>::_TMCT<_UElements ...>::_ConstructibleTuple<_UElements ...>() && std::tuple<synchronizer>::_TMCT<_UElements ...>::_ImplicitlyConvertibleTuple<_UElements ...>()) && std::tuple<synchronizer>::_TNTC<_Dummy>::_NonNestedTuple<const tuple<_Tail ...>&>()), bool>::type <anonymous> > std::tuple<_Elements>::tuple(std::allocator_arg_t, const _Alloc&, const std::tuple<_Args2 ...>&)’
  763 |  tuple(allocator_arg_t __tag, const _Alloc& __a,
      |  ^~~~~
/usr/include/c++/9/tuple:763:2: note:   template argument deduction/substitution failed:
In file included from server.cpp:14:
/usr/include/c++/9/thread:267:4: note:   candidate expects 3 arguments, 1 provided
  267 |  } };
      |    ^
In file included from /usr/include/c++/9/bits/unique_ptr.h:37,
                 from /usr/include/c++/9/memory:80,
                 from /usr/include/c++/9/thread:39,
                 from server.cpp:14:
/usr/include/c++/9/tuple:751:2: note: candidate: ‘template<class _Alloc> std::tuple<_Elements>::tuple(std::allocator_arg_t, const _Alloc&, std::tuple<_Elements>&&)’
  751 |  tuple(allocator_arg_t __tag, const _Alloc& __a, tuple&& __in)
      |  ^~~~~
/usr/include/c++/9/tuple:751:2: note:   template argument deduction/substitution failed:
In file included from server.cpp:14:
/usr/include/c++/9/thread:267:4: note:   candidate expects 3 arguments, 1 provided
  267 |  } };
      |    ^
In file included from /usr/include/c++/9/bits/unique_ptr.h:37,
                 from /usr/include/c++/9/memory:80,
                 from /usr/include/c++/9/thread:39,
                 from server.cpp:14:
/usr/include/c++/9/tuple:747:2: note: candidate: ‘template<class _Alloc> std::tuple<_Elements>::tuple(std::allocator_arg_t, const _Alloc&, const std::tuple<_Elements>&)’
  747 |  tuple(allocator_arg_t __tag, const _Alloc& __a, const tuple& __in)
      |  ^~~~~
/usr/include/c++/9/tuple:747:2: note:   template argument deduction/substitution failed:
In file included from server.cpp:14:
/usr/include/c++/9/thread:267:4: note:   candidate expects 3 arguments, 1 provided
  267 |  } };
      |    ^
In file included from /usr/include/c++/9/bits/unique_ptr.h:37,
                 from /usr/include/c++/9/memory:80,
                 from /usr/include/c++/9/thread:39,
                 from server.cpp:14:
/usr/include/c++/9/tuple:741:11: note: candidate: ‘template<class _Alloc, class ... _UElements, typename std::enable_if<(std::tuple<synchronizer>::_TMC<_UElements ...>::_MoveConstructibleTuple<_UElements ...>() && (! std::tuple<synchronizer>::_TMC<_UElements ...>::_ImplicitlyMoveConvertibleTuple<_UElements ...>())), bool>::type <anonymous> > std::tuple<_Elements>::tuple(std::allocator_arg_t, const _Alloc&, _UElements&& ...)’
  741 |  explicit tuple(allocator_arg_t __tag, const _Alloc& __a,
      |           ^~~~~
/usr/include/c++/9/tuple:741:11: note:   template argument deduction/substitution failed:
In file included from server.cpp:14:
/usr/include/c++/9/thread:267:4: note:   candidate expects at least 2 arguments, 1 provided
  267 |  } };
      |    ^
In file included from /usr/include/c++/9/bits/unique_ptr.h:37,
                 from /usr/include/c++/9/memory:80,
                 from /usr/include/c++/9/thread:39,
                 from server.cpp:14:
/usr/include/c++/9/tuple:730:2: note: candidate: ‘template<class _Alloc, class ... _UElements, typename std::enable_if<(std::tuple<synchronizer>::_TMC<_UElements ...>::_MoveConstructibleTuple<_UElements ...>() && std::tuple<synchronizer>::_TMC<_UElements ...>::_ImplicitlyMoveConvertibleTuple<_UElements ...>()), bool>::type <anonymous> > std::tuple<_Elements>::tuple(std::allocator_arg_t, const _Alloc&, _UElements&& ...)’
  730 |  tuple(allocator_arg_t __tag, const _Alloc& __a,
      |  ^~~~~
/usr/include/c++/9/tuple:730:2: note:   template argument deduction/substitution failed:
In file included from server.cpp:14:
/usr/include/c++/9/thread:267:4: note:   candidate expects at least 2 arguments, 1 provided
  267 |  } };
      |    ^
In file included from /usr/include/c++/9/bits/unique_ptr.h:37,
                 from /usr/include/c++/9/memory:80,
                 from /usr/include/c++/9/thread:39,
                 from server.cpp:14:
/usr/include/c++/9/tuple:720:11: note: candidate: ‘template<class _Alloc, class _Dummy, typename std::enable_if<(std::tuple<synchronizer>::_TCC<_Dummy>::_ConstructibleTuple<synchronizer>() && (! std::tuple<synchronizer>::_TCC<_Dummy>::_ImplicitlyConvertibleTuple<synchronizer>())), bool>::type <anonymous> > std::tuple<_Elements>::tuple(std::allocator_arg_t, const _Alloc&, const _Elements& ...)’
  720 |  explicit tuple(allocator_arg_t __tag, const _Alloc& __a,
      |           ^~~~~
/usr/include/c++/9/tuple:720:11: note:   template argument deduction/substitution failed:
In file included from server.cpp:14:
/usr/include/c++/9/thread:267:4: note:   candidate expects 3 arguments, 1 provided
  267 |  } };
      |    ^
In file included from /usr/include/c++/9/bits/unique_ptr.h:37,
                 from /usr/include/c++/9/memory:80,
                 from /usr/include/c++/9/thread:39,
                 from server.cpp:14:
/usr/include/c++/9/tuple:709:2: note: candidate: ‘template<class _Alloc, class _Dummy, typename std::enable_if<(std::tuple<synchronizer>::_TCC<_Dummy>::_ConstructibleTuple<synchronizer>() && std::tuple<synchronizer>::_TCC<_Dummy>::_ImplicitlyConvertibleTuple<synchronizer>()), bool>::type <anonymous> > std::tuple<_Elements>::tuple(std::allocator_arg_t, const _Alloc&, const _Elements& ...)’
  709 |  tuple(allocator_arg_t __tag, const _Alloc& __a,
      |  ^~~~~
/usr/include/c++/9/tuple:709:2: note:   template argument deduction/substitution failed:
In file included from server.cpp:14:
/usr/include/c++/9/thread:267:4: note:   candidate expects 3 arguments, 1 provided
  267 |  } };
      |    ^
In file included from /usr/include/c++/9/bits/unique_ptr.h:37,
                 from /usr/include/c++/9/memory:80,
                 from /usr/include/c++/9/thread:39,
                 from server.cpp:14:
/usr/include/c++/9/tuple:699:2: note: candidate: ‘template<class _Alloc> std::tuple<_Elements>::tuple(std::allocator_arg_t, const _Alloc&)’
  699 |  tuple(allocator_arg_t __tag, const _Alloc& __a)
      |  ^~~~~
/usr/include/c++/9/tuple:699:2: note:   template argument deduction/substitution failed:
In file included from server.cpp:14:
/usr/include/c++/9/thread:267:4: note:   candidate expects 2 arguments, 1 provided
  267 |  } };
      |    ^
In file included from /usr/include/c++/9/bits/unique_ptr.h:37,
                 from /usr/include/c++/9/memory:80,
                 from /usr/include/c++/9/thread:39,
                 from server.cpp:14:
/usr/include/c++/9/tuple:693:28: note: candidate: ‘template<class ... _UElements, class _Dummy, typename std::enable_if<((std::tuple<synchronizer>::_TMCT<_UElements ...>::_MoveConstructibleTuple<_UElements ...>() && (! std::tuple<synchronizer>::_TMCT<_UElements ...>::_ImplicitlyMoveConvertibleTuple<_UElements ...>())) && std::tuple<synchronizer>::_TNTC<_Dummy>::_NonNestedTuple<tuple<_Tps ...>&&>()), bool>::type <anonymous> > constexpr std::tuple<_Elements>::tuple(std::tuple<_Args1 ...>&&)’
  693 |         explicit constexpr tuple(tuple<_UElements...>&& __in)
      |                            ^~~~~
/usr/include/c++/9/tuple:693:28: note:   template argument deduction/substitution failed:
In file included from server.cpp:14:
/usr/include/c++/9/thread:267:4: note:   ‘synchronizer’ is not derived from ‘std::tuple<_Tps ...>’
  267 |  } };
      |    ^
In file included from /usr/include/c++/9/bits/unique_ptr.h:37,
                 from /usr/include/c++/9/memory:80,
                 from /usr/include/c++/9/thread:39,
                 from server.cpp:14:
/usr/include/c++/9/tuple:682:19: note: candidate: ‘template<class ... _UElements, class _Dummy, typename std::enable_if<((std::tuple<synchronizer>::_TMCT<_UElements ...>::_MoveConstructibleTuple<_UElements ...>() && std::tuple<synchronizer>::_TMCT<_UElements ...>::_ImplicitlyMoveConvertibleTuple<_UElements ...>()) && std::tuple<synchronizer>::_TNTC<_Dummy>::_NonNestedTuple<tuple<_Tps ...>&&>()), bool>::type <anonymous> > constexpr std::tuple<_Elements>::tuple(std::tuple<_Args1 ...>&&)’
  682 |         constexpr tuple(tuple<_UElements...>&& __in)
      |                   ^~~~~
/usr/include/c++/9/tuple:682:19: note:   template argument deduction/substitution failed:
In file included from server.cpp:14:
/usr/include/c++/9/thread:267:4: note:   ‘synchronizer’ is not derived from ‘std::tuple<_Tps ...>’
  267 |  } };
      |    ^
In file included from /usr/include/c++/9/bits/unique_ptr.h:37,
                 from /usr/include/c++/9/memory:80,
                 from /usr/include/c++/9/thread:39,
                 from server.cpp:14:
/usr/include/c++/9/tuple:670:28: note: candidate: ‘template<class ... _UElements, class _Dummy, typename std::enable_if<((std::tuple<synchronizer>::_TMCT<_UElements ...>::_ConstructibleTuple<_UElements ...>() && (! std::tuple<synchronizer>::_TMCT<_UElements ...>::_ImplicitlyConvertibleTuple<_UElements ...>())) && std::tuple<synchronizer>::_TNTC<_Dummy>::_NonNestedTuple<const tuple<_Tps ...>&>()), bool>::type <anonymous> > constexpr std::tuple<_Elements>::tuple(const std::tuple<_Args1 ...>&)’
  670 |         explicit constexpr tuple(const tuple<_UElements...>& __in)
      |                            ^~~~~
/usr/include/c++/9/tuple:670:28: note:   template argument deduction/substitution failed:
In file included from server.cpp:14:
/usr/include/c++/9/thread:267:4: note:   ‘synchronizer’ is not derived from ‘const std::tuple<_Tps ...>’
  267 |  } };
      |    ^
In file included from /usr/include/c++/9/bits/unique_ptr.h:37,
                 from /usr/include/c++/9/memory:80,
                 from /usr/include/c++/9/thread:39,
                 from server.cpp:14:
/usr/include/c++/9/tuple:658:19: note: candidate: ‘template<class ... _UElements, class _Dummy, typename std::enable_if<((std::tuple<synchronizer>::_TMCT<_UElements ...>::_ConstructibleTuple<_UElements ...>() && std::tuple<synchronizer>::_TMCT<_UElements ...>::_ImplicitlyConvertibleTuple<_UElements ...>()) && std::tuple<synchronizer>::_TNTC<_Dummy>::_NonNestedTuple<const tuple<_Tps ...>&>()), bool>::type <anonymous> > constexpr std::tuple<_Elements>::tuple(const std::tuple<_Args1 ...>&)’
  658 |         constexpr tuple(const tuple<_UElements...>& __in)
      |                   ^~~~~
/usr/include/c++/9/tuple:658:19: note:   template argument deduction/substitution failed:
In file included from server.cpp:14:
/usr/include/c++/9/thread:267:4: note:   ‘synchronizer’ is not derived from ‘const std::tuple<_Tps ...>’
  267 |  } };
      |    ^
In file included from /usr/include/c++/9/bits/unique_ptr.h:37,
                 from /usr/include/c++/9/memory:80,
                 from /usr/include/c++/9/thread:39,
                 from server.cpp:14:
/usr/include/c++/9/tuple:642:17: note: candidate: ‘constexpr std::tuple<_Elements>::tuple(std::tuple<_Elements>&&) [with _Elements = {synchronizer}]’
  642 |       constexpr tuple(tuple&&) = default;
      |                 ^~~~~
/usr/include/c++/9/tuple:642:23: note:   no known conversion for argument 1 from ‘synchronizer’ to ‘std::tuple<synchronizer>&&’
  642 |       constexpr tuple(tuple&&) = default;
      |                       ^~~~~~~
/usr/include/c++/9/tuple:637:28: note: candidate: ‘template<class ... _UElements, typename std::enable_if<((std::tuple<synchronizer>::_TMC<_UElements ...>::_MoveConstructibleTuple<_UElements ...>() && (! std::tuple<synchronizer>::_TMC<_UElements ...>::_ImplicitlyMoveConvertibleTuple<_UElements ...>())) && (1 >= 1)), bool>::type <anonymous> > constexpr std::tuple<_Elements>::tuple(_UElements&& ...)’
  637 |         explicit constexpr tuple(_UElements&&... __elements)
      |                            ^~~~~
/usr/include/c++/9/tuple:637:28: note:   template argument deduction/substitution failed:
/usr/include/c++/9/tuple:636:21: error: no type named ‘type’ in ‘struct std::enable_if<false, bool>’
  636 |         bool>::type=false>
      |                     ^~~~~
/usr/include/c++/9/tuple:626:19: note: candidate: ‘template<class ... _UElements, typename std::enable_if<((std::tuple<synchronizer>::_TMC<_UElements ...>::_MoveConstructibleTuple<_UElements ...>() && std::tuple<synchronizer>::_TMC<_UElements ...>::_ImplicitlyMoveConvertibleTuple<_UElements ...>()) && (1 >= 1)), bool>::type <anonymous> > constexpr std::tuple<_Elements>::tuple(_UElements&& ...)’
  626 |         constexpr tuple(_UElements&&... __elements)
      |                   ^~~~~
/usr/include/c++/9/tuple:626:19: note:   template argument deduction/substitution failed:
/usr/include/c++/9/tuple:625:21: error: no type named ‘type’ in ‘struct std::enable_if<false, bool>’
  625 |         bool>::type=true>
      |                     ^~~~
/usr/include/c++/9/tuple:599:26: note: candidate: ‘template<class _Dummy, typename std::enable_if<((std::tuple<synchronizer>::_TCC<_Dummy>::_ConstructibleTuple<synchronizer>() && (! std::tuple<synchronizer>::_TCC<_Dummy>::_ImplicitlyConvertibleTuple<synchronizer>())) && (1 >= 1)), bool>::type <anonymous> > constexpr std::tuple<_Elements>::tuple(const _Elements& ...)’
  599 |       explicit constexpr tuple(const _Elements&... __elements)
      |                          ^~~~~
/usr/include/c++/9/tuple:599:26: note:   template argument deduction/substitution failed:
/usr/include/c++/9/tuple:598:28: error: no type named ‘type’ in ‘struct std::enable_if<false, bool>’
  598 |                bool>::type=false>
      |                            ^~~~~
/usr/include/c++/9/tuple:588:19: note: candidate: ‘template<class _Dummy, typename std::enable_if<((std::tuple<synchronizer>::_TCC<_Dummy>::_ConstructibleTuple<synchronizer>() && std::tuple<synchronizer>::_TCC<_Dummy>::_ImplicitlyConvertibleTuple<synchronizer>()) && (1 >= 1)), bool>::type <anonymous> > constexpr std::tuple<_Elements>::tuple(const _Elements& ...)’
  588 |         constexpr tuple(const _Elements&... __elements)
      |                   ^~~~~
/usr/include/c++/9/tuple:588:19: note:   template argument deduction/substitution failed:
/usr/include/c++/9/tuple:587:28: error: no type named ‘type’ in ‘struct std::enable_if<false, bool>’
  587 |                bool>::type=true>
      |                            ^~~~
/usr/include/c++/9/tuple:571:26: note: candidate: ‘template<class _Dummy, typename std::enable_if<(std::tuple<synchronizer>::_TC2<_Dummy>::_DefaultConstructibleTuple() && (! std::tuple<synchronizer>::_TC2<_Dummy>::_ImplicitlyDefaultConstructibleTuple())), bool>::type <anonymous> > constexpr std::tuple<_Elements>::tuple()’
  571 |       explicit constexpr tuple()
      |                          ^~~~~
/usr/include/c++/9/tuple:571:26: note:   template argument deduction/substitution failed:
In file included from server.cpp:14:
/usr/include/c++/9/thread:267:4: note:   candidate expects 0 arguments, 1 provided
  267 |  } };
      |    ^
In file included from /usr/include/c++/9/bits/unique_ptr.h:37,
                 from /usr/include/c++/9/memory:80,
                 from /usr/include/c++/9/thread:39,
                 from server.cpp:14:
/usr/include/c++/9/tuple:561:17: note: candidate: ‘template<class _Dummy, typename std::enable_if<std::tuple<synchronizer>::_TC2<_Dummy>::_ImplicitlyDefaultConstructibleTuple(), bool>::type <anonymous> > constexpr std::tuple<_Elements>::tuple()’
  561 |       constexpr tuple()
      |                 ^~~~~
/usr/include/c++/9/tuple:561:17: note:   template argument deduction/substitution failed:
In file included from server.cpp:14:
/usr/include/c++/9/thread:267:4: note:   candidate expects 0 arguments, 1 provided
  267 |  } };
      |    ^
/usr/include/c++/9/thread:267:4: error: could not convert ‘{<expression error>}’ from ‘<brace-enclosed initializer list>’ to ‘std::thread::_Invoker<std::tuple<synchronizer> >’

0 Answers0