gsoap calc++ example ended up with error - gsoap

I am trying to build calc++ after looking into tutorial given here https://www.genivia.com/examples/calc++/index.html but end up with error as shown below.
Here are the steps i followed
wsdl2h -o calc.h http://www.genivia.com/calc.wsdl [This created the
header file and i am not sure what to do file "typemap.dat" file so
i proceed with second step]
soapcpp2 -j -r -CL calc.h [This generates the required files and i downloaded the calcclient.cpp , copied the stdsoap2.h and stdsoap2.cpp in the same folder]
g++ -o calcclient calcclient.cpp stdsoap2.cpp soapC.cpp soapcalcProxy.cpp [This step ends with the error shown below]
Can anybody help me regarding this, i am totally new to gsoap and trying to build something with it so i decided to start with gsoap example but getting this big error. I am doing this in Ubuntu and following the exact steps which is given in the tutorial.Please check error below
calcclient.cpp: In function ‘int main(int, char**)’:
calcclient.cpp:58:29: error: no matching function for call to ‘calcProxy::add(double&, double&, double*)’
calc.add(a, b, &result);
^
In file included from calcclient.cpp:41:0:
soapcalcProxy.h:74:21: note: candidate: virtual int calcProxy::add(double, double, double&)
virtual int add(double a, double b, double &result)
^
soapcalcProxy.h:74:21: note: no known conversion for argument 3 from ‘double*’ to ‘double&’
soapcalcProxy.h:76:21: note: candidate: virtual int calcProxy::add(const char*, const char*, double, double, double&)
virtual int add(const char *soap_endpoint, const char *soap_action, double a, double b, double &result);
^
soapcalcProxy.h:76:21: note: candidate expects 5 arguments, 3 provided
calcclient.cpp:61:29: error: no matching function for call to ‘calcProxy::sub(double&, double&, double*)’
calc.sub(a, b, &result);
^
In file included from calcclient.cpp:41:0:
soapcalcProxy.h:78:21: note: candidate: virtual int calcProxy::sub(double, double, double&)
virtual int sub(double a, double b, double &result)
^
soapcalcProxy.h:78:21: note: no known conversion for argument 3 from ‘double*’ to ‘double&’
soapcalcProxy.h:80:21: note: candidate: virtual int calcProxy::sub(const char*, const char*, double, double, double&)
virtual int sub(const char *soap_endpoint, const char *soap_action, double a, double b, double &result);
^
soapcalcProxy.h:80:21: note: candidate expects 5 arguments, 3 provided
calcclient.cpp:64:29: error: no matching function for call to ‘calcProxy::mul(double&, double&, double*)’
calc.mul(a, b, &result);
^
In file included from calcclient.cpp:41:0:
soapcalcProxy.h:82:21: note: candidate: virtual int calcProxy::mul(double, double, double&)
virtual int mul(double a, double b, double &result)
^
soapcalcProxy.h:82:21: note: no known conversion for argument 3 from ‘double*’ to ‘double&’
soapcalcProxy.h:84:21: note: candidate: virtual int calcProxy::mul(const char*, const char*, double, double, double&)
virtual int mul(const char *soap_endpoint, const char *soap_action, double a, double b, double &result);
^
soapcalcProxy.h:84:21: note: candidate expects 5 arguments, 3 provided
calcclient.cpp:67:29: error: no matching function for call to ‘calcProxy::div(double&, double&, double*)’
calc.div(a, b, &result);
^
In file included from calcclient.cpp:41:0:
soapcalcProxy.h:86:21: note: candidate: virtual int calcProxy::div(double, double, double&)
virtual int div(double a, double b, double &result)
^
soapcalcProxy.h:86:21: note: no known conversion for argument 3 from ‘double*’ to ‘double&’
soapcalcProxy.h:88:21: note: candidate: virtual int calcProxy::div(const char*, const char*, double, double, double&)
virtual int div(const char *soap_endpoint, const char *soap_action, double a, double b, double &result);
^
soapcalcProxy.h:88:21: note: candidate expects 5 arguments, 3 provided
calcclient.cpp:70:29: error: no matching function for call to ‘calcProxy::pow(double&, double&, double*)’
calc.pow(a, b, &result);
^
In file included from calcclient.cpp:41:0:
soapcalcProxy.h:90:21: note: candidate: virtual int calcProxy::pow(double, double, double&)
virtual int pow(double a, double b, double &result)
^
soapcalcProxy.h:90:21: note: no known conversion for argument 3 from ‘double*’ to ‘double&’
soapcalcProxy.h:92:21: note: candidate: virtual int calcProxy::pow(const char*, const char*, double, double, double&)
virtual int pow(const char *soap_endpoint, const char *soap_action, double a, double b, double &result);
^
soapcalcProxy.h:92:21: note: candidate expects 5 arguments, 3 provided

Perhaps you are passing one or more arguments as a pointer. The correct proxy call should look like this:
#include "soapcalcProxy.h"
#include "calc.nsmap"
double a, b, result;
calcProxy calc("http://server.com/path");
a = 1.23;
b = 4.56;
int err = calc.add(a, b, result);

Related

Error in constexpr' expansion of 'shader.base::BasicStringPiece<char>::remove_prefix(6)'

constexpr base::StringPiece StripLambda(base::StringPiece shader) {
// Must contain at least "[]() {}".
DCHECK_EQ(shader.substr(0, 6), "[]() {");
DCHECK_EQ(shader.back(), '}');
shader.remove_prefix(6);
shader.remove_suffix(1);
return shader;
}
chromium94/src/components/viz/service/display/shader.cc:29:23: in 'constexpr' expansion of 'shader.base::BasicStringPiece::remove_prefix(6)'
chromium94/src/base/check_op.h:157:41: error: 'constexpr logging::CheckOpResult logging::CheckLEImpl(T, U, const char*) [with T = unsigned int; U = unsigned int; typename std::enable_if<(std::is_fundamental<_Tp>::value && std::is_fundamental::value), int>::type = 0]' called in a constant expression
chromium94/src/base/check_op.h:184:38: error: call to non-'constexpr' function 'logging::CheckOpResult::CheckOpResult(const char*, char*, char*)'
chromium94/src/base/check_op.h:157:41: error: 'constexpr logging::CheckOpResult logging::CheckLEImpl(T, U, const char*) [with T = unsigned int; U = unsigned int; typename std::enable_if<(std::is_fundamental<_Tp>::value && std::is_fundamental::value), int>::type = 0]' called in a constant expression
Can anyone help with work around solution?
Can anyone help with work around solution?

Arrays declared globally gives out of scope error in functions

I have these arrays declared globally
char str1[] = "6541254939322816220209974565477289648317";
char str2[] = "3142522751761601737419090933147067701840";
int str1_size = strlen(str1);
int str2_size = strlen(str2);
int lcs[str1_size][str2_size];
int arrows[str1_size][str2_size];
But when I access this inside a function, it gives
lcs was not declared in this scope
also
array bound is not an integer constant before ‘]’ token
int lcs[str1_size][str2_size];
What am I doing wrong here ?
First of all
int a[dim];
where dim isn't a compile-time know constant (constexpr by example) isn't C++ standard; maybe it's possible with some extension with some compiler but isn't C++ standard.
So, in your case
int lcs[str1_size][str2_size];
int arrows[str1_size][str2_size];
where str1_size and str2_size are normal (not constexpr, not const initialized with literals) variables, is an error.
If you could redefine str1_size and str2_size as follows
constexpt int str1_size = strlen(str1);
constexpr int str2_size = strlen(str2);
the lcs and arrows definition could works.
Unfortunately (1) str1 and str2 aren't constexpr and (2) std::strlen() isn't constexpr.
But if declare str1/str2 constexpr and write a constexpr alternative to std::strlen...
#include <iostream>
constexpr std::size_t lenStr (char const * str)
{
std::size_t ret{};
while ( *(str++) )
++ret;
return ret;
}
constexpr char str1[] = "6541254939322816220209974565477289648317";
constexpr char str2[] = "3142522751761601737419090933147067701840";
constexpr auto str1_size = lenStr(str1);
constexpr auto str2_size = lenStr(str2);
int lcs[str1_size][str2_size];
int arrows[str1_size][str2_size];
int main ()
{
}
Unfortunately the preceding code require C++14 (in C++11 it's impossible write so complex constexpr functions).
In C++11 you should write lenStr() in a recursive way
constexpr std::size_t lenStr (char const * str, std::size_t ret = 0u)
{ return *str ? lenStr(++str, ++ret) : ret; }

How to get *any* example of boost::mpl::map working?

Here is my sample code. Can someone please help me with it?
#include <string>
#include <utility> //Not strictly necessary (gets imported implicitely anyway)
#include <boost/mpl/map.hpp>
#include <boost/mpl/size.hpp>
#include <boost/type_traits/is_same.hpp>
typedef boost::mpl::map<
std::pair<int,unsigned>
, std::pair<char,unsigned char>
> m;
int main()
{
std::pair<int,unsigned> b(10,10); //this works
int a = boost::mpl::size<m>::value; //this doesn't
}
The error message:
In file included from /home/adam/spack/opt/spack/linux-ubuntu16.04-x86_64/gcc-5.4.0/boost-1.67.0-xcr4z3warx5tptvihmi5biqrq7hpgw7j/include/boost/mpl/map/aux_/include_preprocessed.hpp:47:0,
from /home/adam/spack/opt/spack/linux-ubuntu16.04-x86_64/gcc-5.4.0/boost-1.67.0-xcr4z3warx5tptvihmi5biqrq7hpgw7j/include/boost/mpl/map/map10.hpp:28,
from /home/adam/spack/opt/spack/linux-ubuntu16.04-x86_64/gcc-5.4.0/boost-1.67.0-xcr4z3warx5tptvihmi5biqrq7hpgw7j/include/boost/mpl/map/map20.hpp:19,
from /home/adam/spack/opt/spack/linux-ubuntu16.04-x86_64/gcc-5.4.0/boost-1.67.0-xcr4z3warx5tptvihmi5biqrq7hpgw7j/include/boost/mpl/map.hpp:36,
from /home/adam/c++/tests/simple_test/test2.cpp:3:
/home/adam/spack/opt/spack/linux-ubuntu16.04-x86_64/gcc-5.4.0/boost-1.67.0-xcr4z3warx5tptvihmi5biqrq7hpgw7j/include/boost/mpl/map/aux_/preprocessed/typeof_based/map10.hpp: In instantiation of ‘struct boost::mpl::map2<std::pair<int, unsigned int>, std::pair<char, unsigned char> >’:
/home/adam/spack/opt/spack/linux-ubuntu16.04-x86_64/gcc-5.4.0/boost-1.67.0-xcr4z3warx5tptvihmi5biqrq7hpgw7j/include/boost/mpl/aux_/preprocessed/gcc/map.hpp:51:8: required from ‘struct boost::mpl::map<std::pair<int, unsigned int>, std::pair<char, unsigned char> >’
/home/adam/spack/opt/spack/linux-ubuntu16.04-x86_64/gcc-5.4.0/boost-1.67.0-xcr4z3warx5tptvihmi5biqrq7hpgw7j/include/boost/mpl/aux_/has_tag.hpp:20:1: required by substitution of ‘template<class U> static char (& boost::mpl::aux::has_tag<boost::mpl::map<std::pair<int, unsigned int>, std::pair<char, unsigned char> >, mpl_::bool_<false> >::gcc_3_2_wknd::test<U>(const volatile boost::mpl::aux::type_wrapper<T>*, boost::mpl::aux::type_wrapper<typename U::tag>*))[2] [with U = boost::mpl::map<std::pair<int, unsigned int>, std::pair<char, unsigned char> >]’
/home/adam/spack/opt/spack/linux-ubuntu16.04-x86_64/gcc-5.4.0/boost-1.67.0-xcr4z3warx5tptvihmi5biqrq7hpgw7j/include/boost/mpl/aux_/has_tag.hpp:20:1: required from ‘const bool boost::mpl::aux::has_tag<boost::mpl::map<std::pair<int, unsigned int>, std::pair<char, unsigned char> >, mpl_::bool_<false> >::value’
/home/adam/spack/opt/spack/linux-ubuntu16.04-x86_64/gcc-5.4.0/boost-1.67.0-xcr4z3warx5tptvihmi5biqrq7hpgw7j/include/boost/mpl/aux_/has_tag.hpp:20:1: required from ‘struct boost::mpl::aux::has_tag<boost::mpl::map<std::pair<int, unsigned int>, std::pair<char, unsigned char> >, mpl_::bool_<false> >’
/home/adam/spack/opt/spack/linux-ubuntu16.04-x86_64/gcc-5.4.0/boost-1.67.0-xcr4z3warx5tptvihmi5biqrq7hpgw7j/include/boost/mpl/sequence_tag.hpp:110:8: required from ‘struct boost::mpl::sequence_tag<boost::mpl::map<std::pair<int, unsigned int>, std::pair<char, unsigned char> > >’
/home/adam/spack/opt/spack/linux-ubuntu16.04-x86_64/gcc-5.4.0/boost-1.67.0-xcr4z3warx5tptvihmi5biqrq7hpgw7j/include/boost/mpl/size.hpp:29:8: required from ‘struct boost::mpl::size<boost::mpl::map<std::pair<int, unsigned int>, std::pair<char, unsigned char> > >’
/home/adam/c++/tests/simple_test/test2.cpp:15:29: required from here
/home/adam/spack/opt/spack/linux-ubuntu16.04-x86_64/gcc-5.4.0/boost-1.67.0-xcr4z3warx5tptvihmi5biqrq7hpgw7j/include/boost/mpl/map/aux_/preprocessed/typeof_based/map10.hpp:31:8: error: no type named ‘first’ in ‘struct std::pair<char, unsigned char>’
struct map2
^~~~
In file included from /home/adam/c++/tests/simple_test/test2.cpp:4:0:
/home/adam/spack/opt/spack/linux-ubuntu16.04-x86_64/gcc-5.4.0/boost-1.67.0-xcr4z3warx5tptvihmi5biqrq7hpgw7j/include/boost/mpl/size.hpp: In instantiation of ‘struct boost::mpl::size<boost::mpl::map<std::pair<int, unsigned int>, std::pair<char, unsigned char> > >’:
/home/adam/c++/tests/simple_test/test2.cpp:15:29: required from here
/home/adam/spack/opt/spack/linux-ubuntu16.04-x86_64/gcc-5.4.0/boost-1.67.0-xcr4z3warx5tptvihmi5biqrq7hpgw7j/include/boost/mpl/size.hpp:29:8: error: no class template named ‘apply’ in ‘struct boost::mpl::size_impl<boost::mpl::non_sequence_tag>’
struct size
^~~~
/home/adam/c++/tests/simple_test/test2.cpp: In function ‘int main()’:
/home/adam/c++/tests/simple_test/test2.cpp:15:31: error: ‘value’ is not a member of ‘boost::mpl::size<boost::mpl::map<std::pair<int, unsigned int>, std::pair<char, unsigned char> > >’
int a = boost::mpl::size<m>::value; //this doesn't
^~~~~
/home/adam/c++/tests/simple_test/test2.cpp:15:6: warning: unused variable ‘a’ [-Wunused-variable]
int a = boost::mpl::size<m>::value; //this doesn't
^
CMakeFiles/libsimple_test.dir/build.make:62: recipe for target 'CMakeFiles/libsimple_test.dir/test2.cpp.o' failed
make[2]: *** [CMakeFiles/libsimple_test.dir/test2.cpp.o] Error 1
CMakeFiles/Makefile2:142: recipe for target 'CMakeFiles/libsimple_test.dir/all' failed
make[1]: *** [CMakeFiles/libsimple_test.dir/all] Error 2
Makefile:83: recipe for target 'all' failed
make: *** [all] Error 2
I use C++11 on GCC 7.3.0 and libboost 1.67.0 on Ubuntu 16.04 64bit.
By chance I found a solution: Don't use the standard std::pair, but rather use the re-invented boost::mpl::pair. After simple replacing std::pair into boost::mpl::pair the sample code compiles and runs properly... which leads to another question.

std::get on std::tuple results in variadic args reducing to nothing with incomplete type error

The following code produces a huge list of compiler errors:
/// Uses template recursion to bind all args
template<std::size_t N, typename... Args> class Binder
{
public:
Binder(Sqlite3StatementBase &s, std::tuple<Args...> &tup)
{
Binder<N - 1, Args...> b(s, tup);
s.bind(N + 1, std::get<N, Args...>(tup)); // Line 182
}
};
/// Specialization of Binder to end recursion at 0
template<typename... Args> class Binder<0, Args...>
{
public:
Binder(Sqlite3StatementBase &s, std::tuple<Args...> &tup)
{
s.bind(1, std::get<0, Args...>(tup));
}
};
The first batch of errors consists of:
In file included from /usr/include/c++/6/bits/unique_ptr.h:37:0,
from /usr/include/c++/6/condition_variable:43,
from /home/tony/htpc/Dev/logi/src/db/logi-db.h:22,
from /home/tony/htpc/Dev/logi/src/db/logi-sqlite.h:26,
from /home/tony/htpc/Dev/logi/src/db/logi-sqlite.cpp:24:
/usr/include/c++/6/tuple: In instantiation of ‘class std::tuple_element<1ul, std::tuple<unsigned int> >’:
/usr/include/c++/6/tuple:1228:12: recursively required from ‘class std::tuple_element<2ul, std::tuple<unsigned int, unsigned int> >’
/usr/include/c++/6/tuple:1228:12: required from ‘class std::tuple_element<3ul, std::tuple<unsigned int, unsigned int, unsigned int> >’
/usr/include/c++/6/utility:106:69: required by substitution of ‘template<long unsigned int __i, class _Tp> using __tuple_element_t = typename std::tuple_element::type [with long unsigned int __i = 3ul; _Tp = std::tuple<unsigned int, unsigned int, unsigned int>]’
/usr/include/c++/6/tuple:1270:5: required by substitution of ‘template<long unsigned int __i, class ... _Elements> constexpr std::__tuple_element_t<__i, std::tuple<_Elements ...> >&& std::get(std::tuple<_Elements ...>&&) [with long unsigned int __i = 3ul; _Elements = {unsigned int, unsigned int, unsigned int}]’
/home/tony/htpc/Dev/logi/src/db/logi-sqlite.h:182:47: required from ‘logi::Sqlite3Database::Binder<N, Args>::Binder(logi::Sqlite3Database::Sqlite3StatementBase&, std::tuple<_Elements ...>&) [with long unsigned int N = 3ul; Args = {unsigned int, unsigned int, unsigned int}]’
/home/tony/htpc/Dev/logi/src/db/logi-sqlite.h:238:71: required from ‘void logi::Sqlite3Database::Sqlite3Statement<Args>::prepare_row(logi::Sqlite3Database::Sqlite3Statement<Args>::Tup&) [with Args = {unsigned int, unsigned int, unsigned int}; logi::Sqlite3Database::Sqlite3Statement<Args>::Tup = std::tuple<unsigned int, unsigned int, unsigned int>]’
/home/tony/htpc/Dev/logi/src/db/logi-sqlite.h:231:28: required from ‘void logi::Sqlite3Database::Sqlite3Statement<Args>::execute(typename logi::Sqlite3Database::Sqlite3Statement<Args>::Parent::ArgsVector&) [with Args = {unsigned int, unsigned int, unsigned int}; typename logi::Sqlite3Database::Sqlite3Statement<Args>::Parent::ArgsVector = std::vector<std::tuple<unsigned int, unsigned int, unsigned int>, std::allocator<std::tuple<unsigned int, unsigned int, unsigned int> > >]’
/home/tony/htpc/Dev/logi/src/db/logi-sqlite.cpp:354:1: required from here
/usr/include/c++/6/tuple:1228:12: error: invalid use of incomplete type ‘class std::tuple_element<0ul, std::tuple<> >’
So it seems as if the std::get call is causing other parts of the system libraries (not directly related to std::get or std::tuple) to recursively reduce Args... to nothing, and this is happening independently of my recursion of the numerical template parameter N. Is there something I can fix in my code without fundamentally changing my approach, or is it just not possible to use std::get in a context where the tuple's template parameters are variadic?
Given an implementation of the C++14 make_index_sequence function (and its associated types), you can do what you want easily enough:
template<size_t ...indices, typename ...Args>
void binder_helper(Sqlite3StatementBase &s, std::integer_sequence<size_t, indices...>, std::tuple<Args...> &tup)
{
auto dump = {(s.bind(indices, std::get<indices>(tup)), 0)...};
}
template<typename ...Args>
void binder(Sqlite3StatementBase &s, std::tuple<Args...> &tup)
{
binder_helper(s, std::make_index_sequence<sizeof...(Args)>(), tup);
}
With C++17's fold expressions, the oddball stuff in binder_helper can be reduced to something much more reasonable:
template<size_t ...indices, typename ...Args>
void binder_helper(Sqlite3StatementBase &s, std::integer_sequence<size_t, indices...>, std::tuple<Args...> &tup)
{
(s.bind(indices, std::get<indices>(tup)), ...);
}
Note that in the latter case, the standard does not guarantee thatt the calls to s.bind will be executed in order. In the former case, because the expressions are wrapped in a braced-init-list, you're guaranteed in-order evaluation.

unordered_map with IP address as a key

I am trying to build a list of linked list in my application. The list will contains unique IP addresses,and for each IP addres I have a list of applications. I am trying to build it using unordered_map to take Boost::boost::asio::ip::address as a the key and std::list as value:
#include <boost/unordered/unordered_map.hpp>
#include <iostream>
#include <list>
using namespace boost::asio::ip;
using namespace std;
typedef int ApplicationID;
typedef address IPAddress;
typedef list <ApplicationID> APP_LIST;
typedef boost::unordered::unordered_map <IPAddress, APP_LIST> USER_MAP;
USER_MAP user_map;
Later I try to get the list associated with an IP address as following:
APP_LIST *list = &user_map[ip];
But I get errors in the compilation, so could you please specify what's the problem?
Is it possible to use Boost:IPaddress as a key function?
Another question is it possible to use char[some_size] as a key value?
Error Output:
In file included from /boost/functional/hash/hash.hpp:535:0,
from /boost/functional/hash.hpp:6,
from /boost/unordered/unordered_map.hpp:21,
from ipc_module.cpp:18:
/boost/functional/hash/extensions.hpp: In member function ‘std::size_t boost::hash<T>::operator()(const T&) const [with T = boost::asio::ip::address, std::size_t = long unsigned int]’:
/boost/unordered/detail/unique.hpp:331:55: instantiated from ‘boost::unordered::detail::table_impl<Types>::value_type& boost::unordered::detail::table_impl<Types>::operator[](const key_type&) [with Types = boost::unordered::detail::map<std::allocator<std::pair<const boost::asio::ip::address, std::list<int> > >, boost::asio::ip::address, std::list<int>, boost::hash<boost::asio::ip::address>, std::equal_to<boost::asio::ip::address> >, boost::unordered::detail::table_impl<Types>::value_type = std::pair<const boost::asio::ip::address, std::list<int> >, boost::unordered::detail::table_impl<Types>::key_type = boost::asio::ip::address]’
/boost/unordered/unordered_map.hpp:1192:26: instantiated from ‘boost::unordered::unordered_map<K, T, H, P, A>::mapped_type& boost::unordered::unordered_map<K, T, H, P, A>::operator[](const key_type&) [with K = boost::asio::ip::address, T = std::list<int>, H = boost::hash<boost::asio::ip::address>, P = std::equal_to<boost::asio::ip::address>, A = std::allocator<std::pair<const boost::asio::ip::address, std::list<int> > >, boost::unordered::unordered_map<K, T, H, P, A>::mapped_type = std::list<int>, boost::unordered::unordered_map<K, T, H, P, A>::key_type = boost::asio::ip::address]’
ipc_module.cpp:175:40: instantiated from here
/boost/functional/hash/extensions.hpp:176:34: error: no matching function for call to ‘hash_value(const boost::asio::ip::address&)’
/boost/functional/hash/extensions.hpp:176:34: note: candidates are:
/boost/smart_ptr/shared_ptr.hpp:708:33: note: template<class T> std::size_t boost::hash_value(const boost::shared_ptr<T>&)
/boost/functional/hash/hash.hpp:144:24: note: std::size_t boost::hash_value(bool)
/boost/functional/hash/hash.hpp:144:24: note: no known conversion for argument 1 from ‘const boost::asio::ip::address’ to ‘bool’
/boost/functional/hash/hash.hpp:149:24: note: std::size_t boost::hash_value(char)
/boost/functional/hash/hash.hpp:149:24: note: no known conversion for argument 1 from ‘const boost::asio::ip::address’ to ‘char’
/boost/functional/hash/hash.hpp:154:24: note: std::size_t boost::hash_value(unsigned char)
/boost/functional/hash/hash.hpp:154:24: note: no known conversion for argument 1 from ‘const boost::asio::ip::address’ to ‘unsigned char’
/boost/functional/hash/hash.hpp:159:24: note: std::size_t boost::hash_value(signed char)
/boost/functional/hash/hash.hpp:159:24: note: no known conversion for argument 1 from ‘const boost::asio::ip::address’ to ‘signed char’
/boost/functional/hash/hash.hpp:164:24: note: std::size_t boost::hash_value(short int)
/boost/functional/hash/hash.hpp:164:24: note: no known conversion for argument 1 from ‘const boost::asio::ip::address’ to ‘short int’
/boost/functional/hash/hash.hpp:169:24: note: std::size_t boost::hash_value(short unsigned int)
/boost/functional/hash/hash.hpp:169:24: note: no known conversion for argument 1 from ‘const boost::asio::ip::address’ to ‘short unsigned int’
/boost/functional/hash/hash.hpp:174:24: note: std::size_t boost::hash_value(int)
/boost/functional/hash/hash.hpp:174:24: note: no known conversion for argument 1 from ‘const boost::asio::ip::address’ to ‘int’
/boost/functional/hash/hash.hpp:179:24: note: std::size_t boost::hash_value(unsigned int)
/boost/functional/hash/hash.hpp:179:24: note: no known conversion for argument 1 from ‘const boost::asio::ip::address’ to ‘unsigned int’
/boost/functional/hash/hash.hpp:184:24: note: std::size_t boost::hash_value(long int)
/boost/functional/hash/hash.hpp:184:24: note: no known conversion for argument 1 from ‘const boost::asio::ip::address’ to ‘long int’
/boost/functional/hash/hash.hpp:189:24: note: std::size_t boost::hash_value(long unsigned int)
/boost/functional/hash/hash.hpp:189:24: note: no known conversion for argument 1 from ‘const boost::asio::ip::address’ to ‘long unsigned int’
/boost/functional/hash/hash.hpp:195:24: note: std::size_t boost::hash_value(wchar_t)
/boost/functional/hash/hash.hpp:195:24: note: no known conversion for argument 1 from ‘const boost::asio::ip::address’ to ‘wchar_t’
/boost/functional/hash/hash.hpp:202:24: note: std::size_t boost::hash_value(boost::long_long_type)
/boost/functional/hash/hash.hpp:202:24: note: no known conversion for argument 1 from ‘const boost::asio::ip::address’ to ‘boost::long_long_type {aka long long int}’
/boost/functional/hash/hash.hpp:207:24: note: std::size_t boost::hash_value(boost::ulong_long_type)
/boost/functional/hash/hash.hpp:207:24: note: no known conversion for argument 1 from ‘const boost::asio::ip::address’ to ‘boost::ulong_long_type {aka long long unsigned int}’
/boost/functional/hash/hash.hpp:215:36: note: template<class T> std::size_t boost::hash_value(T* const&)
/boost/functional/hash/hash.hpp:308:24: note: template<class T, unsigned int N> std::size_t boost::hash_value(const T (&)[N])
/boost/functional/hash/hash.hpp:314:24: note: template<class T, unsigned int N> std::size_t boost::hash_value(T (&)[N])
/boost/functional/hash/hash.hpp:327:24: note: std::size_t boost::hash_value(float)
/boost/functional/hash/hash.hpp:327:24: note: no known conversion for argument 1 from ‘const boost::asio::ip::address’ to ‘float’
/boost/functional/hash/hash.hpp:332:24: note: std::size_t boost::hash_value(double)
/boost/functional/hash/hash.hpp:332:24: note: no known conversion for argument 1 from ‘const boost::asio::ip::address’ to ‘double’
/boost/functional/hash/hash.hpp:337:24: note: std::size_t boost::hash_value(long double)
/boost/functional/hash/hash.hpp:337:24: note: no known conversion for argument 1 from ‘const boost::asio::ip::address’ to ‘long double’
/boost/functional/hash/hash.hpp:321:24: note: template<class Ch, class A> std::size_t boost::hash_value(const std::basic_string<Ch, std::char_traits<_CharT>, A>&)
/boost/functional/hash/hash.hpp:343:24: note: std::size_t boost::hash_value(std::type_index)
/boost/functional/hash/hash.hpp:343:24: note: no known conversion for argument 1 from ‘const boost::asio::ip::address’ to ‘std::type_index’
/boost/functional/hash/extensions.hpp:54:17: note: template<class A, class B> std::size_t boost::hash_value(const std::pair<_T1, _T2>&)
/boost/functional/hash/extensions.hpp:63:17: note: template<class T, class A> std::size_t boost::hash_value(const std::vector<_Tp, _Alloc>&)
/boost/functional/hash/extensions.hpp:69:17: note: template<class T, class A> std::size_t boost::hash_value(const std::list<_Tp, _Alloc>&)
/boost/functional/hash/extensions.hpp:75:17: note: template<class T, class A> std::size_t boost::hash_value(const std::deque<_Tp, _Alloc>&)
/boost/functional/hash/extensions.hpp:81:17: note: template<class K, class C, class A> std::size_t boost::hash_value(const std::set<_Key, _Compare, _Alloc>&)
/boost/functional/hash/extensions.hpp:87:17: note: template<class K, class C, class A> std::size_t boost::hash_value(const std::multiset<_Key, _Compare, _Alloc>&)
/boost/functional/hash/extensions.hpp:93:17: note: template<class K, class T, class C, class A> std::size_t boost::hash_value(const std::map<_Key, _Tp, _Compare, _Alloc>&)
/boost/functional/hash/extensions.hpp:99:17: note: template<class K, class T, class C, class A> std::size_t boost::hash_value(const std::multimap<_Key, _Tp, _Compare, _Alloc>&)
/boost/functional/hash/extensions.hpp:105:17: note: template<class T> std::size_t boost::hash_value(const std::complex<_Tp>&)
/boost/functional/hash/extensions.hpp:177:9: warning: control reaches end of non-void function [-Wreturn-type]
/boost/asio/error.hpp: At global scope:
/boost/asio/error.hpp:244:45: warning: ‘boost::asio::error::system_category’ defined but not used [-Wunused-variable]
/boost/asio/error.hpp:246:45: warning: ‘boost::asio::error::netdb_category’ defined but not used [-Wunused-variable]
/boost/asio/error.hpp:248:45: warning: ‘boost::asio::error::addrinfo_category’ defined but not used [-Wunused-variable]
/boost/asio/error.hpp:250:45: warning: ‘boost::asio::error::misc_category’ defined but not used [-Wunused-variable]
Here's what I came up with after a brief inspection of the class interface for ip::address.
I would like to note that it's pretty wasteful to use. Especially if you happen to know that all addresses are ipv4, e.g. I'd prefer to key by ulong then.
namespace boost
{
template <>
struct hash<IPAddress>
{
size_t operator()(IPAddress const& v) const {
if (v.is_v4())
return v.to_v4().to_ulong();
if (v.is_v6())
{
auto const& range = v.to_v6().to_bytes();
return hash_range(range.begin(), range.end());
}
if (v.is_unspecified())
{
// guaranteed to be random: chosen by fair dice roll
return static_cast<size_t>(0x4751301174351161ul);
}
return hash_value(v.to_string());
}
};
}
See it Live on Coliru:
#include <boost/asio.hpp>
#include <boost/unordered/unordered_map.hpp>
#include <iostream>
#include <list>
typedef int ApplicationID;
typedef boost::asio::ip::address IPAddress;
typedef std::list<ApplicationID> APP_LIST;
typedef boost::unordered::unordered_map<IPAddress, APP_LIST> USER_MAP;
namespace boost
{
template <>
struct hash<IPAddress>
{
size_t operator()(IPAddress const& v) const {
if (v.is_v4())
return v.to_v4().to_ulong();
if (v.is_v6())
{
auto const& range = v.to_v6().to_bytes();
return hash_range(range.begin(), range.end());
}
if (v.is_unspecified())
return 0x4751301174351161ul;
return hash_value(v.to_string());
}
};
}
int main()
{
USER_MAP map;
map.insert({ {}, {} });
}
This is an old question, but I recently came across the same issue while writing a game in c++17.
This is how I solved it:
struct endpoint_hash
{
std::size_t operator()(boost::asio::ip::udp::endpoint const& ep) const noexcept
{
auto accum = std::size_t(0);
auto combine = [&accum](auto&& arg) {
boost::hash_combine(accum, arg);
};
combine(ep.port());
if (auto&& addr = ep.address(); addr.is_v4())
{
combine(addr.to_v4().to_ulong());
}
else
{
combine(addr.to_v6().to_bytes());
}
combine(ep.port());
return accum;
}
};
std::unordered_map<boost::asio::ip::udp::endpoint, std::shared_ptr<game_client>, endpoint_hash> cache_;
It will work if you write a hash function for IPaddress.

Resources