cpp-httplib icon indicating copy to clipboard operation
cpp-httplib copied to clipboard

Creating vector of clients

Open jmbouffa opened this issue 4 years ago • 2 comments

Hello, what is the easiest way to create one sslclient per thread in a boost::thread_pool?

I am trying to create a vector of httplib::SSLClient but I get errors like:

error:` no matching function for call to ‘httplib::SSLClient::SSLClient()’

with vector<httplib::SSLClient> clientDataVector(4)

or

error: static assertion failed: result type must be constructible from value type of input range 137 | static_assert(is_constructible<_ValueType2, decltype(*__first)>::value,

with vector<httplib::SSLClient> clientDataVector { httplib::SSLClient("host.com"), httplib::SSLClient("host.com"), httplib::SSLClient("host.com"), httplib::SSLClient("host.com") };

jmbouffa avatar Nov 29 '22 15:11 jmbouffa

@jmbouffa, thanks for the feedback, but there is no easy clean way since the default and copy constructors are intentionally removed from SSLClient. If you want to put SSL Client instances into a vector with the initializer, you have to do it with std::shared_ptr unfortunately. But the vector will be std::vector<std::shared_ptr<httplib::SSLClient>>, and it doesn't look beautiful...

This is actually not a question for cpp-httplib, but a general C++ question to make a vector of a class which doesn't have the default and copy constructor. I think you can find answers in stackoverflow.

Hope it helps!

yhirose avatar Nov 29 '22 16:11 yhirose

Ah, I see. I suspected as much, but I wasn't sure. Thanks for the clarification!

jmbouffa avatar Nov 30 '22 00:11 jmbouffa